# Maths

Formulas are written in LaTeX, between dollars: `$…$` in the line, `$$…$$` on a line of their own (or in a ` ```math ` block, as on GitHub). Copy a formula: you get its LaTeX back.

## In the line

Einstein's $E = mc^2$, Pythagoras' $a^2 + b^2 = c^2$, Euler's identity $e^{i\pi} + 1 = 0$, the golden ratio $\varphi = \frac{1+\sqrt{5}}{2}$, and a sum $\sum_{k=1}^{n} k = \frac{n(n+1)}{2}$ sit in the text, on its baseline. So do sets like $\mathbb{N} \subset \mathbb{Z} \subset \mathbb{Q} \subset \mathbb{R} \subset \mathbb{C}$, limits like $\lim_{x \to 0} \frac{\sin x}{x} = 1$, and Greek: $\alpha, \beta, \gamma, \delta, \varepsilon, \theta, \lambda, \mu, \pi, \sigma, \omega, \Gamma, \Delta, \Sigma, \Omega$.

A long formula wraps like text, after a $=$ or a $+$ as TeX does: narrow the window to see $P(x) = a_0 + a_1 x + a_2 x^2 + a_3 x^3 + a_4 x^4 + a_5 x^5 + a_6 x^6 + a_7 x^7 + a_8 x^8 + a_9 x^9 + a_{10} x^{10} + a_{11} x^{11} + a_{12} x^{12}$ break over several lines.

Dollars that aren't maths stay dollars: it costs $5, or $ 10 with a space.

## Algebra

The quadratic formula:

$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$

The binomial theorem:

$$(x + y)^n = \sum_{k=0}^{n} \binom{n}{k} x^{n-k} y^k$$

A derivation, aligned on its equals signs:

```math
\begin{aligned}
(a + b)^3 &= (a + b)(a + b)^2 \\
          &= (a + b)(a^2 + 2ab + b^2) \\
          &= a^3 + 3a^2 b + 3ab^2 + b^3
\end{aligned}
```

## Calculus

The fundamental theorem of calculus, and Taylor's series:

$$\int_a^b f'(x)\,dx = f(b) - f(a) \qquad f(x) = \sum_{n=0}^{\infty} \frac{f^{(n)}(a)}{n!}(x - a)^n$$

The Gaussian integral, and Stirling's formula:

$$\int_{-\infty}^{+\infty} e^{-x^2}\,dx = \sqrt{\pi} \qquad n! \sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^n$$

The Fourier transform:

$$\hat{f}(\xi) = \int_{-\infty}^{\infty} f(x)\, e^{-2\pi i x \xi}\,dx$$

Cauchy's integral formula:

$$f(a) = \frac{1}{2\pi i} \oint_\gamma \frac{f(z)}{z - a}\,dz$$

## Linear algebra

$$A = \begin{pmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \vdots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \end{pmatrix} \qquad \det\begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc$$

A rotation, and a system of equations:

$$R_\theta = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix} \qquad \left\{ \begin{array}{rcl} 2x + 3y & = & 7 \\ x - y & = & 1 \end{array} \right.$$

Eigenvalues: $A\mathbf{v} = \lambda\mathbf{v}$, so $\det(A - \lambda I) = 0$.

## Physics

Maxwell's equations:

```math
\begin{aligned}
\nabla \cdot \mathbf{E} &= \frac{\rho}{\varepsilon_0} & \nabla \cdot \mathbf{B} &= 0 \\
\nabla \times \mathbf{E} &= -\frac{\partial \mathbf{B}}{\partial t} & \nabla \times \mathbf{B} &= \mu_0 \mathbf{J} + \mu_0 \varepsilon_0 \frac{\partial \mathbf{E}}{\partial t}
\end{aligned}
```

Schrödinger's equation:

$$i\hbar \frac{\partial}{\partial t} \Psi(\mathbf{r}, t) = \left[ -\frac{\hbar^2}{2m} \nabla^2 + V(\mathbf{r}, t) \right] \Psi(\mathbf{r}, t)$$

Einstein's field equations:

$$R_{\mu\nu} - \frac{1}{2} R\, g_{\mu\nu} + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu}$$

Navier–Stokes:

$$\rho \left( \frac{\partial \mathbf{u}}{\partial t} + (\mathbf{u} \cdot \nabla)\mathbf{u} \right) = -\nabla p + \mu \nabla^2 \mathbf{u} + \mathbf{f}$$

## Probability and statistics

Bayes' theorem, and the normal distribution:

$$P(A \mid B) = \frac{P(B \mid A)\,P(A)}{P(B)} \qquad f(x) = \frac{1}{\sigma\sqrt{2\pi}} \exp\left( -\frac{(x - \mu)^2}{2\sigma^2} \right)$$

Expectation and variance: $\mathbb{E}[X] = \sum_i x_i\, p_i$ and $\operatorname{Var}(X) = \mathbb{E}\big[(X - \mathbb{E}[X])^2\big]$.

## Machine learning

Softmax, and attention as in transformers:

$$\operatorname{softmax}(\mathbf{z})_i = \frac{e^{z_i}}{\sum_{j=1}^{K} e^{z_j}} \qquad \operatorname{Attention}(Q, K, V) = \operatorname{softmax}\!\left( \frac{QK^\top}{\sqrt{d_k}} \right) V$$

Gradient descent, and the cross-entropy loss:

$$\theta_{t+1} = \theta_t - \eta\, \nabla_\theta \mathcal{L}(\theta_t) \qquad \mathcal{L} = -\frac{1}{N} \sum_{i=1}^{N} \sum_{c=1}^{C} y_{i,c} \log \hat{y}_{i,c}$$

## Number theory

Euler's product for the zeta function, and Ramanujan's series for $1/\pi$:

$$\zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s} = \prod_{p \text{ prime}} \frac{1}{1 - p^{-s}} \qquad \frac{1}{\pi} = \frac{2\sqrt{2}}{9801} \sum_{k=0}^{\infty} \frac{(4k)!\,(1103 + 26390k)}{(k!)^4\, 396^{4k}}$$

A continued fraction for the golden ratio:

$$\varphi = 1 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \cfrac{1}{1 + \cdots}}}}$$

Fermat's little theorem: if $p$ is prime and $p \nmid a$, then $a^{p-1} \equiv 1 \pmod{p}$.

## Functions by cases

$$|x| = \begin{cases} x & \text{if } x \ge 0 \\ -x & \text{if } x < 0 \end{cases} \qquad \operatorname{sgn}(x) = \begin{cases} -1 & x < 0 \\ \phantom{-}0 & x = 0 \\ \phantom{-}1 & x > 0 \end{cases}$$

## Sets and logic

$$\forall \varepsilon > 0,\ \exists \delta > 0 : |x - a| < \delta \implies |f(x) - f(a)| < \varepsilon$$

$$A \cup B = \{ x \mid x \in A \lor x \in B \} \qquad \overline{A \cap B} = \overline{A} \cup \overline{B} \qquad \emptyset \subseteq A \subseteq \mathcal{P}(A)$$

## Big operators and braces

$$\underbrace{1 + 2 + \cdots + 100}_{100 \text{ terms}} = \overbrace{\frac{100 \cdot 101}{2}}^{\text{Gauss, aged 9}} = 5050$$

$$\bigcup_{i=1}^{\infty} A_i \qquad \bigoplus_{k} V_k \qquad \iiint_V \nabla \cdot \mathbf{F}\,dV = \oiint_{\partial V} \mathbf{F} \cdot d\mathbf{S} \qquad \sum_{\substack{0 \le i \le m \\ 0 < j < n}} P(i, j)$$

## Arrows, accents and decorations

$$A \xrightarrow{\ f\ } B \xrightarrow[\text{onto}]{\ g\ } C \qquad x \mapsto x^2 \qquad \vec{v},\ \hat{\imath},\ \dot{x},\ \ddot{x},\ \tilde{n},\ \bar{z},\ \widehat{ABC},\ \overrightarrow{PQ}$$

$$\boxed{E = mc^2} \qquad \cancel{x^2} + y \qquad {\color{red} a} + {\color{blue} b} = \textcolor{green}{c} \qquad \sqrt[3]{8} = 2 \qquad \sqrt{1 + \sqrt{1 + \sqrt{1 + x}}}$$

## Tall and nested

$$\left( \frac{\partial^2 f}{\partial x^2} + \frac{\partial^2 f}{\partial y^2} \right) \left[ \sum_{i=1}^{n} \left( \frac{x_i - \bar{x}}{\sigma} \right)^2 \right] \left\| \frac{\mathbf{v}}{\|\mathbf{v}\|} \right\| = \left. \frac{d}{dx} \right|_{x=0}$$

$$\frac{1}{\displaystyle 1 + \frac{1}{\displaystyle 1 + \frac{1}{\displaystyle 1 + \frac{1}{x}}}} \qquad 2^{2^{2^{2}}} \qquad e^{-\frac{x^2}{2\sigma^2}} \qquad x_{i_{j_k}}$$

## Chemistry

Written as chemists type it, with `\ce{…}` and `\pu{…}` (mhchem, as KaTeX has it): water is $\ce{H2O}$, sulfate $\ce{SO4^2-}$, a hydrate $\ce{CuSO4*5H2O}$, an isotope $\ce{^{227}_{90}Th+}$.

$$\ce{CO2 + C -> 2 CO} \qquad \ce{SO4^2- + Ba^2+ -> BaSO4 v} \qquad \ce{3H2 + N2 <=>[Fe][500 °C] 2NH3}$$

$$\ce{Hg^2+ ->[I-] HgI2 ->[I-] [Hg^{II}I4]^2-} \qquad \Delta H = \pu{-92.4 kJ//mol}$$

See also: [Pocket heat](pocket-heat.md) · [Drawings](svg.md) · [Dowwwn](/homepage.md)
