Skip to content

Commit 15f809b

Browse files
committed
Math fixes: spaces in inline math, deprecated commands (non-environment forms of cases, pmatrix, et al)
1 parent dc5f8c6 commit 15f809b

File tree

9 files changed

+41
-41
lines changed

9 files changed

+41
-41
lines changed

src/algebra/euclid-algorithm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The algorithm was first described in Euclid's "Elements" (circa 300 BC), but it
1818

1919
The algorithm is extremely simple:
2020

21-
$$gcd(a, b) = \cases{a,&if $b = 0$\cr gcd(b, a\mod b),&otherwise}$$
21+
$$gcd(a, b) = \begin{cases}a,&if $b = 0$\cr gcd(b, a\mod b),&otherwise\end{cases}$$
2222

2323
## Implementation
2424

@@ -76,7 +76,7 @@ $$
7676
So, recalling that $d \mid b$, we obtain the system:
7777
7878
$$
79-
\cases{d \mid b,\cr d \mid (a \mod b)\cr}
79+
\begin{cases}d \mid b,\cr d \mid (a \mod b)\cr\end{cases}
8080
$$
8181
8282
Now we use the fact that for any three numbers $p$, $q$, $r$, if $p\mid q$ and $p\mid r$ then $p\mid gcd(q, r)$, In our case, we get:

src/algebra/extended-euclid-algorithm.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ $$ g = b \cdot x_1 + a \cdot \left( y_1 - \left\lfloor \frac{b}{a} \right\rfloor
3232

3333
We found the values of $x$ and $y$:
3434

35-
$$ \cases{
35+
$$ \begin{cases}
3636
x = y_1 - \left\lfloor \frac{b}{a} \right\rfloor \cdot x_1 \cr
3737
y = x_1
38-
} $$
38+
\end{cases} $$
3939

4040
## Implementation
4141

src/algebra/fft.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ If there isn't a match, then at least a character is different, which leads that
581581
### String matching with wildcards
582582
583583
This is an extension of the previous problem.
584-
This time we allow that the pattern contains the wildcard character $ * $, which can match every possible letter.
584+
This time we allow that the pattern contains the wildcard character $*$, which can match every possible letter.
585585
E.g. the pattern $a*c$ appears in the text $abccaacc$ at exactly three positions, at index $0$, index $4$ and index $5$.
586586
587587
We create the exact same polynomials, except that we set $b_i = 0$ if $P[m-i-1] = *$.

src/algebra/fibonacci-numbers.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ As these two formulas would require very high accuracy when working with fractio
8989

9090
It is easy to prove the following relation:
9191

92-
$$\pmatrix{F_{n-1} & F_{n} \cr} = \pmatrix{F_{n-2} & F_{n-1} \cr} \cdot \pmatrix{0 & 1 \cr 1 & 1 \cr}$$
92+
$$\begin{pmatrix}F_{n-1} & F_{n} \cr\end{pmatrix} = \begin{pmatrix}F_{n-2} & F_{n-1} \cr\end{pmatrix} \cdot \begin{pmatrix}0 & 1 \cr 1 & 1 \cr\end{pmatrix}$$
9393

94-
Denoting $P \equiv \pmatrix{0 & 1 \cr 1 & 1 \cr}$, we have:
94+
Denoting $P \equiv \begin{pmatrix}0 & 1 \cr 1 & 1 \cr\end{pmatrix}$, we have:
9595

96-
$$\pmatrix{F_n & F_{n+1} \cr} = \pmatrix{F_0 & F_1 \cr} \cdot P^n$$
96+
$$\begin{pmatrix}F_n & F_{n+1} \cr\end{pmatrix} = \begin{pmatrix}F_0 & F_1 \cr\end{pmatrix} \cdot P^n$$
9797

9898
Thus, in order to find $F_n$, we must raise the matrix $P$ to $n$. This can be done in $O(\log n)$ (see [Binary exponentiation](./algebra/binary-exp.html)).
9999

src/algebra/primitive-root.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ Furthermore, the number of primitive roots modulo $n$, if there are any, is equa
3232

3333
A naive algorithm is to consider all numbers in range $[1, n-1]$. And then check if each one is a primitive root, by calculating all its power to see if they are all different. This algorithm has complexity $O(g . n)$, which would be too slow. In this section, we propose a faster algorithm using several well-known theorems.
3434

35-
From previous section, we know that if the smallest number $k$ for which $g^k \equiv 1 \pmod n$ is $ \phi (n)$, then $g$ is a primitive root. Since for any number $a$ relative prime to $n$, we know from Euler's theorem that $a ^ { \phi (n) } \equiv 1 \pmod n$, then to check if $g$ is primitive root, it is enough to check that for all $d$ less than $ \phi (n)$, $g^d \not \equiv 1 \pmod n$. However, this algorithm is still too slow.
35+
From previous section, we know that if the smallest number $k$ for which $g^k \equiv 1 \pmod n$ is $\phi (n)$, then $g$ is a primitive root. Since for any number $a$ relative prime to $n$, we know from Euler's theorem that $a ^ { \phi (n) } \equiv 1 \pmod n$, then to check if $g$ is primitive root, it is enough to check that for all $d$ less than $\phi (n)$, $g^d \not \equiv 1 \pmod n$. However, this algorithm is still too slow.
3636

37-
From Lagrange's theorem, we know that the index of any number modulo $n$ must be a divisor of $ \phi (n)$. Thus, it is sufficient to verify for all proper divisor $d \, | \, \phi (n)$ that $g^d \not \equiv 1 \pmod n$. This is already a much faster algorithm, but we can still do better.
37+
From Lagrange's theorem, we know that the index of any number modulo $n$ must be a divisor of $\phi (n)$. Thus, it is sufficient to verify for all proper divisor $d \, | \, \phi (n)$ that $g^d \not \equiv 1 \pmod n$. This is already a much faster algorithm, but we can still do better.
3838

39-
Factorize $ \phi (n) = p_1 ^ {a_1} ... p_s ^ {a_s}$. We prove that in the previous algorithm, it is sufficient to consider only the values of $d$ which has the form $ \frac { \phi (n) } {p_j}$. Indeed, let $d$ be any proper divisor of $ \phi (n) $. Then, obviously, there exists such $j$ that $d \, | \, \frac { \phi (n) } {p_j}$, i.e. $d . k = \frac { \phi (n) } {p_j}$. However, if $g^d \equiv 1 \pmod n$, we would get:
39+
Factorize $\phi (n) = p_1 ^ {a_1} ... p_s ^ {a_s}$. We prove that in the previous algorithm, it is sufficient to consider only the values of $d$ which has the form $\frac { \phi (n) } {p_j}$. Indeed, let $d$ be any proper divisor of $\phi (n)$. Then, obviously, there exists such $j$ that $d \, | \, \frac { \phi (n) } {p_j}$, i.e. $d . k = \frac { \phi (n) } {p_j}$. However, if $g^d \equiv 1 \pmod n$, we would get:
4040

4141
$g ^ { \frac { \phi (n)} {p_j} } \equiv g ^ {d . k} \equiv (g^d) ^k \equiv 1^k \equiv 1 \pmod n$.
4242

@@ -56,7 +56,7 @@ Shoup (1990, 1992) proved, assuming the [generalized Riemann hypothesis](http://
5656

5757
## Implementation
5858

59-
The following code assumes that the modulo `p` is a prime number. To make it works for any value of `p`, we must add calculation of $\phi (p) $.
59+
The following code assumes that the modulo `p` is a prime number. To make it works for any value of `p`, we must add calculation of $\phi (p)$.
6060

6161
```cpp
6262
int powmod (int a, int b, int p) {

src/algebra/sieve-of-eratosthenes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Now, let's evaluate this sum using the integral of a same function over $k$ from
3939
4040
$$\sum_{k = 2}^{\frac n {\ln n}} \frac 1 {k \ln k} \approx \int_2^{\frac n {\ln n}} \frac 1 {k \ln k} dk.$$
4141
42-
The antiderivative for the integrand is $ \ln \ln k$. Using a substitution and removing terms of lower order, we'll get the result:
42+
The antiderivative for the integrand is $\ln \ln k$. Using a substitution and removing terms of lower order, we'll get the result:
4343
4444
$$\int_2^{\frac n {\ln n}} \frac 1 {k \ln k} dk = \ln \ln \frac n {\ln n} - \ln \ln 2 = \ln(\ln n - \ln \ln n) - \ln \ln 2 \approx \ln \ln n.$$
4545

src/combinatorics/inclusion-exclusion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ $$3^n - (3 \cdot 2^n - 3 \cdot 1 + 0)$$
135135

136136
Consider the following equation:
137137
$$x_1 + x_2 + x_3 + x_4 + x_5 + x_6 = 20$$
138-
where $ 0 \le x_i \le 8 (i = 1,2,\ldots 6)$.
138+
where $0 \le x_i \le 8 (i = 1,2,\ldots 6)$.
139139

140140
Task: count the number of solutions to the equation.
141141

src/geometry/lines-intersection.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ You are given two lines, described as coefficients $A_1, B_1, C_1$ and $A_2, B_2
88

99
If two lines are not parallel, they intersect. To find their intersection point, we need to solve the following system of linear equations:
1010

11-
$$ \cases{ A_1 x + B_1 y + C_1 = 0, \cr
12-
A_2 x + B_2 y + C_2 = 0. } $$
11+
$$ \begin{cases} A_1 x + B_1 y + C_1 = 0, \cr
12+
A_2 x + B_2 y + C_2 = 0. \end{cases} $$
1313

1414
Using Cramer's rule, we immediately find the solution for the system, which will give us the required intersection point of the lines:
1515

16-
$$ x = - \frac{ \left|\matrix{C_1&B_1 \cr C_2&B_2}\right| }{ \left|\matrix{A_1&B_1 \cr A_2&B_2}\right| } = - \frac{ C_1 B_2 - C_2 B_1 }{ A_1 B_2 - A_2 B_1 }, $$
17-
$$ y = - \frac{ \left|\matrix{A_1&C_1 \cr A_2&C_2}\right| }{ \left|\matrix{A_1&B_1 \cr A_2&B_2}\right| } = - \frac{ A_1 C_2 - A_2 C_1 }{ A_1 B_2 - A_2 B_1 }. $$
16+
$$ x = - \frac{ \begin{vmatrix}C_1&B_1 \cr C_2&B_2\end{vmatrix} }{ \begin{vmatrix}A_1&B_1 \cr A_2&B_2\end{vmatrix} } = - \frac{ C_1 B_2 - C_2 B_1 }{ A_1 B_2 - A_2 B_1 }, $$
17+
$$ y = - \frac{ \begin{vmatrix}A_1&C_1 \cr A_2&C_2\end{vmatrix} }{ \begin{vmatrix}A_1&B_1 \cr A_2&B_2\end{vmatrix} } = - \frac{ A_1 C_2 - A_2 C_1 }{ A_1 B_2 - A_2 B_1 }. $$
1818

1919
If the denominator equals $0$, i.e.
2020

21-
$$ \left|\matrix{A_1&B_1 \cr A_2&B_2}\right| = A_1 B_2 - A_2 B_1 = 0 $$
21+
$$ \begin{vmatrix}A_1&B_1 \cr A_2&B_2\end{vmatrix} = A_1 B_2 - A_2 B_1 = 0 $$
2222

2323
then either the system has no solutions (the lines are parallel and distinct) or there are infinitely many solutions (the lines overlap). If we need to distinguish these two cases, we have to check if coefficients $C$ are proportional with the same ratio as the coefficients $A$ and $B$. To do that we only have calculate the following determinants, and if they both equal $0$, the lines overlap:
2424

25-
$$ \left|\matrix{ A_1 & C_1 \cr A_2 & C_2 }\right|, \left|\matrix{ B_1 & C_1 \cr B_2 & C_2 }\right| $$
25+
$$ \begin{vmatrix} A_1 & C_1 \cr A_2 & C_2 \end{vmatrix}, \begin{vmatrix} B_1 & C_1 \cr B_2 & C_2 \end{vmatrix} $$
2626

2727
## Implementation
2828

src/string/suffix-array.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ A **suffix array** will contain integers that represent the **starting indexes**
99

1010
As an example look at the string $s = abaab$.
1111
All suffixes are as follows
12-
$$\begin{align}
13-
0. ~&~ abaab \\\\
14-
1. ~&~ baab \\\\
15-
2. ~&~ aab \\\\
16-
3. ~&~ ab \\\\
17-
4. ~&~ b
18-
\end{align}$$
12+
$$\begin{array}{ll}
13+
0. & abaab \\\\
14+
1. & baab \\\\
15+
2. & aab \\\\
16+
3. & ab \\\\
17+
4. & b
18+
\end{array}$$
1919

2020
After sorting these strings:
21-
$$\begin{align}
22-
2. ~&~ aab \\\\
23-
3. ~&~ ab \\\\
24-
0. ~&~ abaab \\\\
25-
4. ~&~ b \\\\
26-
1. ~&~ baab
27-
\end{align}$$
21+
$$\begin{array}{ll}
22+
2. & aab \\\\
23+
3. & ab \\\\
24+
0. & abaab \\\\
25+
4. & b \\\\
26+
1. & baab
27+
\end{array}$$
2828

2929
Therefore the suffix array for $s$ will be $(2,~ 3,~ 0,~ 4,~ 1)$.
3030

@@ -46,13 +46,13 @@ it is enough to append an arbitrary character to the end of the string which is
4646
It is common to use the symbol $\\$$.
4747
Then the order of the sorted cyclic shifts is equivalent to the order of the sorted suffixes, as demonstrated here with the string $dabbb$.
4848

49-
$$\begin{align}
50-
1. ~~ abbb$d ~&~ abbb \\\\
51-
4. ~~ b$dabb ~&~ b \\\\
52-
3. ~~ bb$dab ~&~ bb \\\\
53-
2. ~~ bbb$da ~&~ bbb \\\\
54-
0. ~~ dabbb$ ~&~ dabbb
55-
\end{align}$$
49+
$$\begin{array}{lll}
50+
1. & abbb\\$d & abbb \\\\
51+
4. & b\\$dabb & b \\\\
52+
3. & bb\\$dab & bb \\\\
53+
2. & bbb\\$da & bbb \\\\
54+
0. & dabbb\\$ & dabbb
55+
\end{array}$$
5656

5757
Since we are going to sort cyclic shifts, we will consider **cyclic substrings**.
5858
We will use the notation $s[i \dots j]$ for the substring of $s$ even if $i > j$.

0 commit comments

Comments
 (0)