# Preliminaries

The proof of Richardson's theorem combines three areas of mathematics that appear in our course
only marginally: **computability theory**, **number theory** (Diophantine equations) and — in the
integration part — **differential algebra**. This chapter collects all the definitions
and theorems needed. Facts marked as *external* are taken without proof (with a reference to the
source); apart from the standard theorems of analysis in §4, everything else is proved in this book.

Conventions: $\mathbb N=\{0,1,2,\dots\}$ (zero belongs to $\mathbb N$), and for a vector
$\boldsymbol\eta=(\eta_1,\dots,\eta_d)\in\mathbb R^d$ we write
$\lVert\boldsymbol\eta\rVert_\infty=\max_j|\eta_j|$ (the maximum norm).

## 1. Algorithms and decidability

```{admonition} Definition 1.1 (algorithm — informally)
:class: note
An **algorithm** is a finite, unambiguous recipe that processes finite input data (a string
over a finite alphabet) step by step and — if it halts — returns a finite result.
There is no bound on time or memory, but every step is mechanical.
```

To talk about what an algorithm *cannot* do, we need a precise model.

```{admonition} Definition 1.2 (Turing machine)
:class: note
A **Turing machine** is a quintuple $(S, \Sigma, \delta, s_0, F)$: a finite set of states $S$ with
an initial state $s_0\in S$ and a set of final states $F\subseteq S$, a finite tape alphabet $\Sigma$
(with a blank symbol), and a transition function
$\delta\colon S\times\Sigma\to S\times\Sigma\times\{\leftarrow,\rightarrow\}$.
The machine works on an infinite tape with a head: at each step it reads a symbol, writes
a new one, moves the head and changes its state. The computation on a given input may **halt**
(reach a final state) or run forever.
```

```{admonition} The Church–Turing thesis
:class: tip
Every algorithm in the informal sense can be implemented by a Turing machine (equivalently: by a
Python program with unlimited memory, in the lambda calculus, by recursive functions…). This is
not a mathematical theorem but a thesis about the adequacy of the definition — so far no
“reasonable” model of computation has refuted it. Thanks to it, in proofs we may write
“there is an algorithm” instead of constructing a Turing machine.
```

```{admonition} Definition 1.3 (decision problem, decidable set)
:class: note
A **decision problem** is a set $W$ of finite strings (e.g., codes of natural numbers or of
expressions). The problem $W$ is **decidable** (the set $W$ is *recursive*) if there is an
algorithm that, for *every* string $w$, halts and correctly answers whether $w\in W$.
Otherwise $W$ is **undecidable**.
```

```{admonition} Definition 1.4 (semi-decidable set)
:class: note
A set $W$ is **semi-decidable** (*computably enumerable*, *recursively enumerable*)
if there is an algorithm that halts exactly on the elements of $W$ (on the remaining
strings it runs forever). Equivalently: there is an algorithm that lists all the
elements of $W$ one after another.
```

```{admonition} Theorem 1.5 (Post)
:class: important
A set $W$ is decidable if and only if both $W$ and its complement
$\overline W$ are semi-decidable.
```

**Proof.** If $W$ is decidable, the same algorithm (forced to loop forever on the answer “no”,
respectively “yes”) semi-decides $W$ and $\overline W$. Conversely: for a given $w$
we run both semi-decision procedures alternately, step by step. Exactly one
of them halts, since $w$ belongs to exactly one of $W,\overline W$; then we know the
answer. $\blacksquare$

The most important example of an undecidable problem concerns programs themselves.

```{admonition} Theorem 1.6 (Turing, 1936: the halting problem)
:class: important
The set $H=\{(e,w): \text{the program with code } e \text{ halts on input } w\}$ is
semi-decidable but undecidable.
```

**Proof.** Semi-decidability: we simulate the program $e$ on $w$ and halt when it
halts. Now suppose that some algorithm $\mathsf{STOP}(e,w)$ decides $H$.
Construct a program $D$ that on input $e$ does the following:
if $\mathsf{STOP}(e,e)$ answers “yes”, it enters an infinite loop; if “no”, it
halts. Let $d$ be the code of the program $D$. Does $D$ halt on input $d$?
If so, then $\mathsf{STOP}(d,d)$ = “yes”, so $D$ loops forever — a contradiction. If not,
then $\mathsf{STOP}(d,d)$ = “no”, so $D$ halts — a contradiction. $\blacksquare$

Post's theorem implies that the **complement** of the halting problem is not even semi-decidable.

Undecidability is transferred to other problems by means of *reductions*.

```{admonition} Definition 1.7 (many-one reduction)
:class: note
A problem $V$ **reduces** to a problem $W$ (we write $V\le_m W$) if there is a computable
function $r$ (an algorithm transforming strings into strings) such that

$$
w\in V \iff r(w)\in W \qquad\text{for every string } w.
$$

```

```{admonition} Proposition 1.8
:class: important
If $V\le_m W$ and $V$ is undecidable, then $W$ is undecidable. Moreover,
$W$ is decidable if and only if $\overline W$ is decidable, so
a reduction $V\le_m\overline W$ also proves that $W$ is undecidable.
```

**Proof.** An algorithm deciding $W$, composed with $r$, would decide $V$. For the complement
it suffices to swap the answers “yes” and “no”. $\blacksquare$

```{admonition} Important: what a reduction does and what it need not do
:class: warning
The function $r$ must be **computable** — in our proof it will be a transformation of *strings*
(expression trees). The justification that $w\in V\iff r(w)\in W$, on the other hand, may be arbitrarily
non-effective: it may use continuity, the intermediate value theorem, the existence of points
that we cannot compute. The algorithm does not have to find these points.
```

## 2. Diophantine equations and Hilbert's tenth problem

```{admonition} Definition 2.1 (Diophantine equation, Diophantine set)
:class: note
A **Diophantine equation** is an equation $p(x_1,\dots,x_n)=0$, where $p\in\mathbb Z[x_1,\dots,x_n]$,
for which we seek integer solutions (here: in $\mathbb N$). A set $D\subseteq\mathbb N$
is **Diophantine** if there is a polynomial $p(y,x_1,\dots,x_n)$ with integer
coefficients such that

$$
y\in D \iff \exists\,x_1,\dots,x_n\in\mathbb N\quad p(y,x_1,\dots,x_n)=0 .
$$

```

For example, the set of composite numbers is Diophantine: $y\in D\iff\exists a,b\ \ y=(a+2)(b+2)$.

**Hilbert's tenth problem** (1900) asked for an algorithm that decides, for an arbitrary
Diophantine equation, whether it has a solution in integers. The answer is
negative, and the road to it led through equations with exponentiation.

```{admonition} Definition 2.2 (exponential Diophantine equation)
:class: note
An **exponential Diophantine equation** is an equation $E_1=E_2$ in which $E_1,E_2$ are built
from variables and natural-number constants by addition, multiplication and exponentiation $a^b$
(also with a variable exponent). Sets defined by such equations (as in Definition 2.1)
are called **exponential Diophantine**.
```

```{admonition} Theorem 2.3 (Davis, Putnam, Robinson, 1961; external)
:class: important
Every semi-decidable set $W\subseteq\mathbb N$ is exponential Diophantine. In particular,
there is no algorithm deciding the solvability of exponential Diophantine equations.
```

```{admonition} Theorem 2.4 (Matiyasevich, 1970; DPRM; external)
:class: important
Every semi-decidable set $W\subseteq\mathbb N$ is Diophantine. In particular,
Hilbert's tenth problem is unsolvable.
```

Matiyasevich showed that the relation $c=a^b$ is itself Diophantine. The key was finding
a Diophantine relation of exponential growth — Matiyasevich used Fibonacci numbers
($v=F_{2u}$); modern expositions usually use the Pell equation. Hence Theorem 2.4 follows
from 2.3. It is even known that nine
unknowns suffice (Matiyasevich; see J. P. Jones, 1982).

```{admonition} Corollary 2.5 (a fixed undecidable polynomial)
:class: important
There exist $n\ge 1$ and a polynomial $p(y,x_1,\dots,x_n)$ with integer coefficients such that the set

$$
U=\{\,a\in\mathbb N:\ \exists\,\mathbf m\in\mathbb N^n\ \ p(a,\mathbf m)=0\,\}
$$

is undecidable.
```

**Proof.** The set $\{e: \text{program } e \text{ halts on input } e\}$ is
semi-decidable (by simulation) but undecidable (the proof of Theorem 1.6 shows exactly this).
Theorem 2.4 gives a Diophantine definition of it. $\blacksquare$

Important: the polynomial $p$ is **a single, fixed one**. Only the parameter $a$ varies. Richardson
(1968), before Matiyasevich's result, used the analogous corollary of Theorem 2.3 in a form
in which exponentiation occurs only as $2^{x_i}$ — see
{doc}`r2_dowod`, §1, and {doc}`r3_dodatki`, Appendix A.

## 3. Expressions, functions, languages

An algorithm is not given a “function”, only a **finite description** of it.

```{admonition} Definition 3.1 (expression language, expression tree)
:class: note
An **expression language** is specified by a grammar: a set of symbols for constants, variables and operations.
For example

$$
A \;::=\; q \mid \pi \mid \log 2 \mid x_1 \mid \dots \mid x_d \mid (A+A) \mid (A-A) \mid (A\cdot A) \mid \exp(A) \mid \sin(A),
\qquad q\in\mathbb Q .
$$

Every expression is a finite **tree**: constants and variables at the leaves, operations at the nodes
(see the section {doc}`../wyklady/w01_3_jak_dziala_cas`). Trees are finite strings, so they
can serve as input to an algorithm.
```

```{admonition} Definition 3.2 (the classes $\mathcal A_d$ and $\mathcal B_d$)
:class: note
$\mathcal A_d$ — the expressions of the above grammar in the variables $x_1,\dots,x_d$
(the *analytic core*); each defines a function $\mathbb R^d\to\mathbb R$ that is defined everywhere.
$\mathcal B_d$ — the same, with the additional operation $A\mapsto|A|$.
Substituting expressions for variables is an operation on trees, so both classes are **effectively
closed under composition**.
```

Different expressions may denote the same function: $\sin^2x+\sin^2(x+\pi/2)-1$ and $0$ are different
trees but the same function (since $\sin(x+\pi/2)=\cos x$). The questions we study concern
**functions**, while the inputs are **trees**. Undecidability lives in the space between the two.

```{admonition} Definition 3.3 (partial functions and equality with domains)
:class: note
A **partial** function $f$ has a domain $\operatorname{dom} f\subseteq\mathbb R$. For a sum,
difference and product, the domain is the intersection of the domains, and
$\operatorname{dom}(f\circ g)=\{x\in\operatorname{dom}g:\ g(x)\in\operatorname{dom}f\}$.
We write $f\equiv g$ when $\operatorname{dom}f=\operatorname{dom}g$ and $f=g$ on this domain.
In particular, $f\equiv 0$ means that $f$ is defined **everywhere** and equal to zero everywhere.
```

## 4. Tools from analysis

```{admonition} Definition 4.1 (real analytic function)
:class: note
A function $f\colon\mathbb R^d\to\mathbb R$ is **analytic** if in a neighborhood of every point
it is the sum of a convergent power series. Constants, coordinates, $\exp$ and $\sin$ are analytic,
and sums, products and compositions of analytic functions are analytic. Hence **every expression
in $\mathcal A_d$ defines an analytic function**. Expressions in $\mathcal B_d$ define continuous
functions, but not always differentiable ones (e.g., $|x|$ at zero).
```

```{admonition} Theorem 4.2 (identity theorem)
:class: important
If a function analytic on an interval $I\subseteq\mathbb R$ vanishes on some nonempty
open interval $J\subseteq I$, then it vanishes on all of $I$.
```

Functions involving the absolute value lack this property: $|x|-x$ vanishes on $[0,\infty)$ but not on $\mathbb R$.
This is precisely why the absolute value is needed in the identity part.

```{admonition} Theorem 4.3 (Darboux — intermediate value theorem)
:class: important
If $\varphi$ is continuous on $[\alpha,\beta]$ and $c$ lies between $\varphi(\alpha)$ and
$\varphi(\beta)$, then $\varphi(\tau)=c$ for some $\tau\in[\alpha,\beta]$.
```

```{admonition} Theorem 4.4 (mean value theorem; integral version)
:class: important
If $\varphi\colon[\alpha,\beta]\to\mathbb R$ is differentiable, then
$|\varphi(\beta)-\varphi(\alpha)|\le(\beta-\alpha)\sup_{[\alpha,\beta]}|\varphi'|$.
For $Q\colon\mathbb R^n\to\mathbb R$ of class $C^1$ and the segment $\gamma(t)=\mathbf x+t(\mathbf m-\mathbf x)$:

$$
Q(\mathbf m)-Q(\mathbf x)=\int_0^1\frac{d}{dt}Q(\gamma(t))\,dt
=\int_0^1\sum_{i=1}^n (m_i-x_i)\,\frac{\partial Q}{\partial x_i}(\gamma(t))\,dt .
$$

```

```{admonition} Definition 4.5 (density)
:class: note
A set $D\subseteq\mathbb R^n$ is **dense** if it meets every nonempty open set;
equivalently: for every $\mathbf a\in\mathbb R^n$ and $\varepsilon>0$ there is
$\mathbf d\in D$ with $\lVert\mathbf d-\mathbf a\rVert_\infty<\varepsilon$.
```

```{admonition} Fact 4.6 (strict inequalities are robust)
:class: important
If $H\colon\mathbb R^n\to\mathbb R$ is continuous and $H(\mathbf u_0)<c$, then $H<c$ on some
neighborhood of $\mathbf u_0$. For the non-strict inequality $H(\mathbf u_0)\le c$ the analogous conclusion need not hold.
```

This small observation is the crux of the whole proof: a dense curve need not pass through any
particular point, but it enters every neighborhood — so it suffices to have a **strict** inequality
with some room to spare.

```{admonition} Definition 4.7 (infimum versus minimum)
:class: note
$\inf_{t}G(t)=0$ means that $G\ge0$ and the values of $G$ come arbitrarily close to zero; it does not mean that $G$
takes the value $0$ somewhere (e.g., $G(t)=\frac{1}{1+t^2}$ has infimum $0$ on $\mathbb R$,
which is not attained).
```

## 5. Differential algebra (only for the integration part)

```{admonition} Definition 5.1 (differential field)
:class: note
A **differential field** is a field $K$ with a **derivation** $D\colon K\to K$: an additive
map satisfying the Leibniz rule $D(uv)=(Du)v+u(Dv)$. The **constants** are the elements $c$
with $Dc=0$. Example: $\mathbb C(x)$ (rational functions) with $D=\frac{d}{dx}$; its constants are $\mathbb C$.
```

```{admonition} Definition 5.2 (elementary extension)
:class: note
An extension $K\subseteq L$ is **elementary** if $L=K(\theta_1,\dots,\theta_s)$, where
each $\theta_j$ is, over $K(\theta_1,\dots,\theta_{j-1})$, either
(i) algebraic, or (ii) **exponential**: $D\theta_j/\theta_j=Db$ (i.e., “$\theta_j=e^b$”),
or (iii) **logarithmic**: $D\theta_j=Db/b$ (i.e., “$\theta_j=\log b$”), for some $b$
in the preceding field. An **elementary function** is an element of such an extension of $\mathbb C(x)$.
Trigonometric functions are elementary, since $\sin z=(e^{iz}-e^{-iz})/(2i)$.
```

```{admonition} Theorem 5.3 (Liouville; Rosenlicht's form; external)
:class: important
Let $K$ be a differential field of characteristic $0$ with field of constants $\mathbb C$, and let
$a\in K$ have an antiderivative in some elementary extension of $K$ with the same constants.
Then there exist $v\in K$, nonzero $u_1,\dots,u_s\in K$ and constants $c_1,\dots,c_s\in\mathbb C$ such that

$$
a = Dv+\sum_{j=1}^{s}c_j\,\frac{Du_j}{u_j}.
$$

```

In other words: if the integral is elementary, it has the form “a function in $K$ plus a combination
of logarithms of functions in $K$”. From this theorem we will derive in {doc}`r3_dodatki` that
$e^{x^2}$ has no elementary antiderivative on any interval.

```{admonition} Where to find proofs of the external facts
:class: seealso
* Theorem 1.6 and reductions: M. Sipser, *Introduction to the Theory of Computation*, Chapters 3–5.
* Theorems 2.3–2.4: M. Davis, *Hilbert's Tenth Problem is Unsolvable*, Amer. Math. Monthly
  80 (1973) — an accessible, complete exposition (Chauvenet and Steele Prizes);
  Yu. Matiyasevich, *Hilbert's Tenth Problem*, MIT Press 1993.
* Theorem 5.3: M. Rosenlicht, Pacific J. Math. 24 (1968); B. Conrad, *Impossibility
  theorems for elementary integration* (notes, Thm. 4.1).
```
