# Lecture 1. How does a computer do mathematics?

**Date and room:** see [Harmonogram](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/book/harmonogram.html) (in Polish).

```{admonition} Lecture materials
:class: tip
* [Slides (reveal.js)](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/slides_w01.html) — the `S` key opens the speaker notes, `Esc` the slide overview.
* [Interactive applets](https://bnaskrecki.faculty.wmi.amu.edu.pl/math-comp/en/applets/index.html) — including *One example, three worlds*, *Anatomy of a floating-point number*, and *Expression tree*.
* [Peano Lab](https://bnaskrecki.faculty.wmi.amu.edu.pl/peano-lab/) — a small, readable “Lean for Peano arithmetic” that runs in the browser.
* Every chapter of this book is a Jupyter notebook: use the download icon (at the top of the page) to get the `.ipynb` file and run it in VS Code.
```

```{rubric} What this lecture is about
```

A computer can “do mathematics” in three fundamentally different ways, and the whole course will
move between them:

| | Numerics | Symbolic computation (CAS) | Formal proof |
|---|---|---|---|
| objects | machine numbers (e.g., `float`) | exact expressions: $\tfrac{1}{3}$, $\sqrt{2}$, $x^2+1$ | theorems and proofs |
| result | an approximation | a transformed expression | a proof checked by the kernel |
| guarantee | rounding error, often unknown | trust in the implementation of the algorithms | trust in a small kernel |
| tools | Python, C, NumPy | SymPy, SageMath, Mathematica, Maple | Peano Lab, Lean, Rocq, Isabelle |

In this first meeting we get to know our working tools and, in outline, how each of
the three “worlds” works. Our running example is the formula
$1 + 2 + \dots + n = \tfrac{n(n+1)}{2}$: we will check it numerically (as with a calculator),
symbolically (a CAS produces the formula — but that is only a *pseudo-proof*), and formally
(a proof by induction in Heyting arithmetic, checked by the Peano Lab kernel; the language of this
theory has no summation symbol, so in it we prove that $n(n+1)/2$ is a natural number, and we prove the
formula itself in Lean).

```{rubric} Outline
```

1. {doc}`w01_1_srodowisko` — VS Code, Python, Jupyter, SymPy, SageMath; how to set up your computer for the labs.
2. {doc}`w01_2_python_matematyka` — Python as a mathematician’s language: numbers, types, lists, functions, loops.
3. {doc}`w01_3_jak_dziala_cas` — expression trees, canonical forms, the zero problem (Richardson’s theorem), branches and assumptions, the algorithms “under the hood.”
4. {doc}`w01_4_obliczenie_sprawdzenie_dowod` — what it means to *compute*, to *verify*, and to *prove*: floating-point arithmetic, patterns that break, the Schwartz–Zippel randomized test, Peano Lab and Lean.

On the slides, section 3 and the Rump example, interval arithmetic and the pyramid of trust from
section 4 belong to {doc}`Lecture 2 <w02>`.

```{rubric} After this lecture you will be able to
```

* run a Jupyter notebook in VS Code with your own Python environment and SymPy installed;
* explain how a numerical result, a symbolic result, and a formal proof differ — and what guarantee each of them gives;
* give an example in which a numerical computation leads to a wrong conclusion;
* describe how a CAS represents an expression (as a tree) and why “simplify” cannot always succeed;
* read a short proof by induction in Peano Lab and say what exactly the kernel checks.

```{rubric} Before the labs
```

Install VS Code, Python (version 3.12 or newer), and the packages `sympy numpy matplotlib ipykernel` following
the section {doc}`w01_1_srodowisko`. Problem sets: {doc}`../laboratoria/lab01_srodowisko_python`
and {doc}`../laboratoria/lab02_sympy_sage`.
