@slide(layout=chapter-slide)

@number
8

@title
Typesetting mathematics

@slide(layout=content-and-preview)

@title
Formula environments 🧮

@content
``` {.lang-tex .hljs}
$2 \sqrt{\frac{\pi^2}{3} \cdot c_2}$
```

Mathematical formulas are only accepted in the so-called **math mode.**
In-line formulas must therefor be guarded by two dollar signs.
We can also use the `equation` block environment:

``` {.lang-tex .hljs}
\begin{equation}
  2 \sqrt{\frac{\pi^2}{3} \cdot c_2}
\end{equation}
```

Packages: `amsmath`, `amsthm`, `amssymb`, `mathtools`

@preview
![](svg/chapter-09/simple-maths-crop.svg)

@slide(layout=content-only)

@title
Examples

@content
<table>
  <tr>
    <th>source code</th>
    <th>result</th>
  </tr>
  <tr class="fragment">
    <td>`\sum_{i=1}^{n}x^2`</td>
    <td>$\sum_{i=1}^{n} x^2$</td>
  </tr>
  <tr class="fragment">
    <td>`12 \leq 4 x^2 + 13`</td>
    <td>$12 \leq 4 x^2 + 13$</td>
  </tr>
  <tr class="fragment">
    <td>`{n \choose k}`</td>
    <td>${n \choose k}$</td>
  </tr>
</table>


@slide(layout=content-and-preview)

@title
Aligning a group of equations

@content
The `align` environment permits us to align equations at certain positions like the ‘&hairsp;=&hairsp;’ character.

``` {.lang-tex .hljs}
\begin{align}
  13 \cdot (4a - 3)^2 &= 13 … \\
      &= 208a^2 - 312a + 117
\end{align}
```

* ++ The equations will be aligned with respect to the ampersands (‘`&`’).
* ++ We can mark a new line using ‘`\\`’.
* ++ `align` and `equation` will not be numbered if we add an asterisk after their names (e.&thinsp;g. `\begin{align*}` and `\end{align*}`).

@preview
![](svg/chapter-09/alignment-crop.svg)


@slide(layout=task-without-number)

@task-number
8a

@title
Typesetting mathematics

@content
Code up the following formulas in the file `exercises/maths/math-formulas.tex`.

| Meaning | Result |
|---------|--------|
| Gravitational acceleration | $9,81\,\frac{m}{s^2}$  |
| Formula to solve quadratic equations | $x_{1,2} = - \frac{p}{2} \pm \sqrt{\left(\frac{p}{2}\right)^2 - q}$ |
| Another formula to solve quadratic equations | $x_{1,2} = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$ |
| Catalan numbers | $C_n = \frac{1}{n+1} {2n \choose n} = \frac{(2n)!}{(n+1)!n!}$ |


@slide(layout=task-without-number)

@task-number
8b

@title
Typesetting mathematics

@content
Code up the following formulas in the file `exercises/maths/math-formulas.tex`.

| Meaning | Result |
|---------|--------|
| Definition of factorial | $n! = \prod_{i=1}^{n} i$ |
| Set of all odd natural numbers | $\{ x \mid x \in \mathbb{N}, \text{odd}(x) \}$ |
| Elimination $\neg\exists x$ | $\neg\exists x . p(x) \Leftrightarrow \forall x . \neg p(x)$ |



@slide(layout=extra-content-only)

@title
More examples

@content
<table>
  <tr>
    <th>source code</th>
    <th>result</th>
  </tr>
  <tr>
    <td>`(x)`, `[x]`, `\lbrace x \rbrace`, `\lvert x \rvert`</td>
    <td>$(x), [x], \lbrace x\rbrace, \lvert x\rvert$</td>
  </tr>
  <tr>
    <td>`\exists`, `\forall`, `\in`, <br />`\notin`, `\infty`</td>
    <td>$\exists,\forall,\in,\notin,\infty$</td>
  </tr>
  <tr>
    <td>`\alpha`, `\beta`, `\Gamma`, <br />`\Delta`, `\varepsilon`, `\pi`</td>
    <td>$\alpha, \beta, \Gamma, \Delta, \varepsilon, \pi$</td>
  </tr>
  <tr>
    <td>`\rightarrow`, `\leftarrow`, `\Rightarrow`, `\Leftarrow`, `\Leftrightarrow`</td>
    <td>$\rightarrow, \leftarrow, \Rightarrow, \Leftarrow, \Leftrightarrow$</td>
  </tr>
  <tr>
    <td>`(A \cup B) \cap C`</td>
    <td>$(A \cup B) \cap C$</td>
  </tr>
  <tr>
    <td>`(A \lor B) \land C`</td>
    <td>$(A \lor B) \land C$</td>
  </tr>
  <tr>
    <td>`(A \cdot B) \times C`</td>
    <td>$(A \cdot B) \times C$</td>
  </tr>
</table>

@slide(layout=extra-content-only)

@title
Height-adapting braces

@content
<table>
  <tr>
    <th>source code</th>
    <th>result</th>
  </tr>
  <tr>
    <td>`\left( \frac{1}{2} \right)`</td>
    <td>$\left( \frac{1}{2} \right)$</td>
  </tr>
  <tr>
    <td>`\left[ \frac{1}{2} \right]`</td>
    <td>$\left[ \frac{1}{2} \right]$</td>
  </tr>
  <tr>
    <td>`\left\lbrace \frac{1}{2} \right\rbrace`</td>
    <td>$\left\lbrace \frac{1}{2} \right\rbrace$</td>
  </tr>
</table>


``` {.lang-tex .hljs}
$4 \cdot \left( \frac{1}{2} % …
```

<p style="text-align: center;">$4 \cdot \left(\frac{1}{2} +\frac{3}{ 12 \cdot \left( 2 + \frac{1}{86 \cdot \left(\frac{1}{2} + 24 \right)} \right)} \right)$</p>


@slide(layout=extra-content-and-preview)

@title
Depicting boundaries

@content
The bounds of an integral can be enforced to appear above and below the integral symbol using the `\limits` command.
This is the standard behaviour for sums, products and limits.

``` {.lang-tex .hljs}
\sum_{i=1}^{n^2}(x+2)
\prod_{j=1}^{100}(3 \cdot x)
\lim_{x \rightarrow \infty}(14x^3 - 12)
\int\limits_{-12}^{4}(14x^3 - 12)
```

<p data-category="Caution!">Don't use `\limits` inline.</p>


@preview
![](svg/chapter-09/limits-crop.svg)


@slide(layout=extra-content-only)

@title
Set-builder notation

@content
In certain situations, it is more adequate to use textual predicates or long function names within the set builder notation.

This is where `\text{}` comes into play.

<p style="text-align: center;">$\left\lbrace x \mid frequency(x) \geq 20\right\rbrace$</p>
<p style="text-align: center;">$\left\lbrace x \mid \text{frequency}(x) \geq 20\right\rbrace$</p>

``` {.lang-tex .hljs .fragment}
$\left\lbrace x \mid \text{frequency} …
```