Skip to content

Commit

Permalink
Use markdown-it and katex (#1438)
Browse files Browse the repository at this point in the history
This addresses #845 

Previously we used 'marked' and 'mathjax' in the playground, but
'markdown-it' and 'katex' in VS Code - the latter being what VS Code
uses for its Markdown and LaTeX rendering in file previews, Jupyter
notebooks, etc. This converts the playground, and the kata content
generation, to use markdown-it and katex, and removes 'marked' and
'mathjax' from the repo.

Note that KaTeX is more strict that MathJax that the LaTeX is well
formed. This is probably a _good thing_ while we're authoring content. I
did need to clean up quite a bit of LaTeX in testing this, and there's
probably quite a bit more elsewhere to go over. (In general our LaTeX is
often in poor shape. We might want to look into any 'linting' options
for it). Feel free to skip the .md files and focus on the code
initially.

I also significantly revamped how we render markdown in a Preact
components. This has led to much cleaner code, and deleting a lot of
useRef and useEffect and dangerouslySetInnerHtml code, and the need to
re-typeset content. (Esp. see kata.tsx and docs.tsx).

---------

Co-authored-by: Mariia Mykhailova <mamykhai@microsoft.com>
  • Loading branch information
billti and tcNickolas authored May 3, 2024
1 parent 25bc315 commit 6725ad5
Show file tree
Hide file tree
Showing 102 changed files with 1,084 additions and 855 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $$ re^{i \theta} = r \cos \theta + i r \sin \theta $$

For two complex numbers to be equal, their real and imaginary parts have to be equal. This gives us the following system of equations:

$$ \begin{cases} a = r \cos \theta \\\\ b = r \sin \theta \end{cases} $$
$$ \begin{cases} a = r \cos \theta \\ b = r \sin \theta \end{cases} $$

To calculate $\theta$, we can divide the second equation by the first one to get

Expand Down
2 changes: 1 addition & 1 deletion katas/content/complex_arithmetic/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ $$i+i=2i$$

$$i-i=0$$

$$-1 \\cdot i=-i$$
$$-1 \cdot i=-i$$

$$(-i)^{2} = -1$$

Expand Down
31 changes: 28 additions & 3 deletions katas/content/complex_arithmetic/powers_of_i/solution.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,34 @@ For an even exponent $n$ that is not divisible by 4 you'll have $i^n = i^2 = -1.

Here is the complete pattern that arises when raising $i$ to non-negative powers. Note that it is periodic with period $4$.

|Power of $i$ | $i^0$ | $i^1$ | $i^2$ | $i^3$ | $i^4$ | $i^5$ | $i^6$ | $i^7$ | $i^8$ | $\dots$ |
|----|----|----|----|----|----|----|----|----|----|----|
|Result | $1$ | $i$ | $-1$ | $-i$ | $1$ | $i$ | $-1$ | $-i$ | $1$ | $\dots$ |
<table>
<tr>
<th>Power of $i$</th>
<th> $i^0$ </th>
<th> $i^1$ </th>
<th> $i^2$ </th>
<th> $i^3$ </th>
<th> $i^4$ </th>
<th> $i^5$ </th>
<th> $i^6$ </th>
<th> $i^7$ </th>
<th> $i^8$ </th>
<th> $\dots$ </th>
</tr>
<tr>
<td>Result</td>
<td> $1$ </td>
<td> $i$ </td>
<td> $-1$ </td>
<td> $-i$ </td>
<td> $1$ </td>
<td> $i$ </td>
<td> $-1$ </td>
<td> $-i$ </td>
<td> $1$ </td>
<td> $\dots$ </td>
</tr>
</table>

> `%` is the Q# modulo operator which returns the remainder of a division. For example, `7%2` gives $1$, because $1$ is the remainder of dividing $7$ by $2$.
> We can use this operator to determine if the exponent $n$ is divisible by $4$.
Expand Down
2 changes: 1 addition & 1 deletion katas/content/deutsch_algo/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This kata introduces you to Deutsch algorithm - the single-qubit variant of Deut
"title": "The Problem"
})

You are given a classical function that takes one bit as an input and returns one bit: $f(x): \\{0, 1\\} \to \\{0, 1\\}$. You are guaranteed that the function $f$ is
You are given a classical function that takes one bit as an input and returns one bit: $f(x): \{0, 1\} \to \{0, 1\}$. You are guaranteed that the function $f$ is

- either *constant* (returns the same value for all inputs)
- or *variable* (returns different values for different inputs).
Expand Down
4 changes: 2 additions & 2 deletions katas/content/deutsch_jozsa/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ This kata introduces you to Deutsch-Jozsa algorithm - one of the most famous alg
"title": "The Problem"
})

You are given a classical function that takes an $N$-bit string as an input and returns one bit: $f(x): \\{0, 1\\}^N \to \\{0, 1\\}$. You are guaranteed that the function $f$ is
You are given a classical function that takes an $N$-bit string as an input and returns one bit: $f(x): \{0, 1\}^N \to \{0, 1\}$. You are guaranteed that the function $f$ is

- either *constant* (returns the same value for all inputs)
- or *balanced* (returns value $0$ for half of the inputs and $1$ for the other half of the inputs).
Expand Down Expand Up @@ -235,7 +235,7 @@ The last demo in this kata shows you how to combine the oracles you've seen so f
})

To wrap up our discussion in this kata, let's take a look at a problem solved using a similar approach - the Bernstein-Vazirani algorithm.
In this problem, you are also given an oracle implementing an $N$-bit function $f(x): \\{0, 1\\}^N \to \\{0, 1\\}$.
In this problem, you are also given an oracle implementing an $N$-bit function $f(x): \{0, 1\}^N \to \{0, 1\}$.
However, this time the function is guaranteed to be a *scalar product function*, that is, there exists an $N$-bit string $s$
that allows the following representation ($\cdot$ is bitwise inner product of integers modulo $2$):

Expand Down
6 changes: 1 addition & 5 deletions katas/content/getting_started/media/Coding.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion katas/content/linear_algebra/addition/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

**Goal:** Return the sum of the following two matrices:

$$\begin{bmatrix} 1 & 2 \\\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\\ 7 & 8 \end{bmatrix}$$
$$\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix}$$

> In this and the next few tasks, the matrices are represented as Q# `Double[][]` type, two-dimensional arrays of floating-point numbers. Make sure the constants you use in the return array are floating-point rather than integers.
4 changes: 2 additions & 2 deletions katas/content/linear_algebra/addition/solution.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Following the definition, the sum of two matrices is a matrix of element-wise sums of matrix elements:

$$\begin{bmatrix} 1 & 2 \\\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\\ 7 & 8 \end{bmatrix} = $$
$$= \begin{bmatrix} 1 + 5 & 2 + 6 \\\ 3 + 7 & 4 + 8 \end{bmatrix} = \begin{bmatrix} 6 & 8 \\\ 10 & 12 \end{bmatrix}$$
$$\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} + \begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix} = $$
$$= \begin{bmatrix} 1 + 5 & 2 + 6 \\ 3 + 7 & 4 + 8 \end{bmatrix} = \begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix}$$

@[solution]({"id": "linear_algebra__addition_solution", "codePath": "Solution.qs"})
2 changes: 1 addition & 1 deletion katas/content/linear_algebra/adjoint/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

**Goal:** Return the adjoint of the following matrix:

$$\begin{bmatrix} 1 + 5i & 2 \\\ 3 - 6i & 4i \end{bmatrix}$$
$$\begin{bmatrix} 1 + 5i & 2 \\ 3 - 6i & 4i \end{bmatrix}$$
2 changes: 1 addition & 1 deletion katas/content/linear_algebra/conjugate/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

**Goal:** Return the conjugate of the following matrix:

$$\begin{bmatrix} 1 + 5i & 2 \\\ 3 - 6i & 4i \end{bmatrix}$$
$$\begin{bmatrix} 1 + 5i & 2 \\ 3 - 6i & 4i \end{bmatrix}$$

> In this and the next few tasks, the matrices are represented as Q# `Complex[][]` type, two-dimensional arrays of complex numbers. If you need a refresher on how to work with this data type, check out Complex Arithmetic kata.
Loading

0 comments on commit 6725ad5

Please sign in to comment.