# Appendices: powers of two and the integral of $e^{x^2}$

Two supplements to the complete proof. Appendix A explains why in the arithmetic input
(Theorem 1.1 in {doc}`r2_dowod`) powers with base $2$ suffice — hence the constant $\log 2$ in
Richardson's language. Appendix B proves that $e^{x^2}$ is a **local obstruction** to
integration in the language with absolute value (Definition 8.1 in {doc}`r2_dowod`), which completes the proof of part (C).

## A. Powers of two suffice

The Davis–Putnam–Robinson theorem (Theorem 2.3 in {doc}`r1_pojecia`) allows
exponentiation $a^b$ with an arbitrary base. We show that the relation $c=a^b$ can be expressed by
equations in which exponentiation occurs only as $2^{(\cdot)}$.

```{admonition} Lemma A.1
:class: important
For positive integers $a,b,c$ let $k=ab+a+1$ and $M=2^k-a$. Then

$$
c=a^b\iff\exists\,q,s\in\mathbb N:\quad 2^{kb}=c+q\,(2^k-a)\quad\text{and}\quad c+s+1=2^k-a .
$$

```

**Proof.** First, the estimates. Since $a\le2^a$, we have $a^b\le2^{ab}$. Moreover,

$$
M-2^{ab}=2^{ab+a+1}-a-2^{ab}=2^{ab}\bigl(2^{a+1}-1\bigr)-a>0 ,
$$

so $0<a^b\le2^{ab}<M$. Since $2^k\equiv a\pmod M$, we get
$2^{kb}=(2^k)^b\equiv a^b\pmod M$.

“⇐”: the second equation says that $0<c<M$ (since $s\ge0$ and $c\ge1$), and the first that $c\equiv2^{kb}\equiv a^b\pmod M$.
Two numbers in the interval $(0,M)$ that are congruent modulo $M$ are equal, so $c=a^b$.
“⇒”: if $c=a^b$, then $2^{kb}-c$ is a multiple of $M$ (nonnegative, since $2^{kb}\ge2^{ab}\ge a^b$),
which gives $q\in\mathbb N$, and $s=M-c-1\ge0$. $\blacksquare$

To make the exponents **variables**, we introduce new unknowns $k$ and $\ell$ with the equations
$k-ab-a-1=0$ and $\ell-kb=0$; then only $2^k$ and $2^\ell$ occur. Any exponential
expression can be broken down, by naming intermediate results as new variables, into a finite system of
equations of this type, and the system $E_1=\dots=E_r=0$ is replaced by the single equation $\sum_jE_j^2=0$.
Positive variables are written as $x+1$ with $x\in\mathbb N$, using $2^{x+1}=2\cdot2^x$. The cases $b=0$ (then $c=1$) and $a=0<b$ (then $c=0$) are added as disjuncts, since $E=0\lor E'=0\iff EE'=0$.
We obtain a polynomial with integer coefficients in the variables $x_i$ and the powers $2^{x_i}$ —
exactly the form of Theorem 1.1 in {doc}`r2_dowod`.

## B. $e^{x^2}$ has no elementary antiderivative — not even locally

The concepts needed (differential field, elementary extension, Liouville's theorem) are
in {doc}`r1_pojecia`, §5. We work with **germs** of meromorphic functions at a real point
(complex values are allowed): a germ is a function defined on some
neighborhood, where functions that agree after shrinking the neighborhood are identified. A germ with zero
derivative is a complex constant, so fields of such germs containing $\mathbb C$ have field of
constants exactly $\mathbb C$ — the hypothesis of Liouville's theorem is satisfied.

### B.1. Transcendence of $e^{x^2}$

```{admonition} Lemma B.1
:class: important
The function $t=e^{x^2}$ is transcendental over $\mathbb C(x)$.
```

**Proof.** If not, then after clearing denominators we would have
$\sum_{j=0}^mp_j(x)e^{jx^2}=0$ with $p_j\in\mathbb C[x]$, $p_m\ne0$, $m\ge1$, on some neighborhood,
and by the identity theorem on the whole real line. Dividing by $p_m(x)e^{mx^2}$ for large
$x>0$, we get $1+\sum_{j<m}\frac{p_j(x)}{p_m(x)}e^{-(m-j)x^2}=0$. Each term of the sum
tends to zero (a rational function grows at most like a power of $x$, while $e^{-(m-j)x^2}$ decays
faster than any reciprocal of a power), which gives the contradiction $1=0$. $\blacksquare$

Hence $K=\mathbb C(x,t)$ is the field of rational functions in the variable $t$ with coefficients in
$\mathbb C(x)$, with the derivation

$$
D=\frac{\partial}{\partial x}+2xt\,\frac{\partial}{\partial t},\qquad Dx=1,\quad Dt=2xt .
$$

### B.2. A rational equation forced by Liouville's theorem

```{admonition} Proposition B.2
:class: important
If $e^{x^2}$ has an elementary antiderivative on some nonempty open interval,
then there is a rational function $r\in\mathbb C(x)$ satisfying

$$
r'(x)+2x\,r(x)=1. \tag{B.1}
$$

Conversely, such an $r$ would give the antiderivative $r(x)e^{x^2}$.
```

**Proof.** An elementary tower containing the antiderivative can be built over $K$
(we adjoin its generators after $t$; the types of the extensions are preserved), with the same field of constants
$\mathbb C$. Liouville's theorem (Theorem 5.3 in {doc}`r1_pojecia`) for $a=t$ gives

$$
t=Dv+\sum_{j=1}^sc_j\frac{Du_j}{u_j},\qquad v\in\mathbb C(x,t),\ u_j\in\mathbb C(x,t)^\times . \tag{B.2}
$$

We compare formal Laurent expansions at the point $t=\infty$, i.e., series
$\sum_{k\le m}a_k(x)t^k$ with $a_k\in\mathbb C(x)$ (every rational function of $t$ has
a unique such expansion). The derivation acts term by term:

$$
D\bigl(a(x)t^k\bigr)=\bigl(a'(x)+2kx\,a(x)\bigr)t^k ,
$$

so differentiating a series with only negative powers produces no nonnegative powers.

*Logarithmic derivatives produce no positive powers of $t$.* We write every nonzero $u\in\mathbb C(x,t)$
as $u=a(x)t^m(1+w)$, $a\ne0$, $m\in\mathbb Z$, with $w$ a series in negative powers.
Then

$$
\frac{Du}{u}=\frac{a'}{a}+2mx+\frac{Dw}{1+w},
$$

and the last term contains only negative powers of $t$.

*The coefficient of $t^1$.* Let $r(x)$ be the coefficient of $t^1$ in the expansion of $v$
(zero if there is none). The coefficient of $t^1$ in $Dv$ is $r'+2xr$; the logarithmic derivatives
contribute $0$; on the left-hand side of (B.2) it is $1$. This gives (B.1). Conversely,
$\frac{d}{dx}\bigl(re^{x^2}\bigr)=(r'+2xr)e^{x^2}$. $\blacksquare$

```{admonition} Lemma B.3
:class: important
Equation (B.1) has no solution $r\in\mathbb C(x)$.
```

**Proof.** Suppose that $r$ has a pole of order $m\ge1$ at $\alpha\in\mathbb C$, with leading term
$c(x-\alpha)^{-m}$, $c\ne0$. Then $r'$ has leading term $-mc(x-\alpha)^{-m-1}$, while $2xr$ has
a pole of order at most $m$, so it cannot cancel it: $r'+2xr$ would have a pole, whereas the right-hand side
of (B.1) is $1$. Hence $r$ is a polynomial. The zero polynomial does not satisfy (B.1); if $r$ has degree
$d\ge0$ and leading coefficient $c\ne0$, then $r'+2xr$ has degree $d+1\ge1$ (the term $2cx^{d+1}$),
so it is not the constant $1$. $\blacksquare$

### B.3. The absolute value does not help

```{admonition} Lemma B.4 (local removal of absolute values)
:class: important
Let $f$ be given by an expression in $\mathcal B_1$. For every nonempty open interval
$I$ there is a nonempty open interval $J\subseteq I$ on which $f$ equals some
expression in $\mathcal A_1$ (without absolute value); in particular, $f$ is elementary and analytic on $J$.
```

**Proof.** Induction on the expression tree, for an arbitrary input interval. Constants and $x$
need no change. For a binary operation, we apply the induction hypothesis to one
argument on $I$, then to the other on the resulting subinterval; on the smaller interval both
replacements hold simultaneously. For $\exp$ and $\sin$, we apply it to the argument. For $|B|$: on some
$J_0\subseteq I$ we have $B=B_0$ with $B_0\in\mathcal A_1$, analytic. If $B_0\equiv0$ on $J_0$,
we replace $|B|$ by $0$. Otherwise we pick a point with $B_0\ne0$ and (by continuity)
a neighborhood $J\subseteq J_0$ on which the sign is constant; we replace $|B|$ by $B_0$ or $-B_0$. $\blacksquare$

This proof is **existential**: it gives no algorithm for determining which subexpressions vanish
identically — and it need not, since the lemma serves only to show that $e^{x^2}$ is an obstruction; the reduction algorithm does not use it.

```{admonition} Corollary B.5 ($e^{x^2}$ is a local obstruction)
:class: important
No function given by an expression in $\mathcal B_1$ has derivative equal to $e^{x^2}$ on any nonempty
open interval. Hence $\Delta(x)=e^{x^2}$ satisfies the hypothesis of Theorem 8.3 in {doc}`r2_dowod`.
```

**Proof.** If $H'=e^{x^2}$ on $I$, then by Lemma B.4, on some $J\subseteq I$ we have $H=H_0$
with $H_0\in\mathcal A_1$, so $H_0'=e^{x^2}$ on $J$, and the germ of $H_0$ is elementary
($\sin z=(e^{iz}-e^{-iz})/(2i)$). This contradicts Proposition B.2 and Lemma B.3. $\blacksquare$

```{admonition} The same method in a language with square roots
:class: note
In Richardson's example the language contains the real square root (then
$|x|=\sqrt{x^2}$). Lemma B.4 carries over: if an expression is defined on an interval, then
the radicand is nonnegative there and either vanishes identically, or on a smaller interval
is positive and the square root is an analytic branch, algebraic over the preceding field.
```

An antiderivative in the ordinary sense does of course exist: $\int_0^xe^{s^2}\,ds$ is smooth on
the whole real line (it is $\tfrac{\sqrt\pi}{2}\operatorname{erfi}x$). The obstruction concerns
the **form** of the antiderivative, not its existence. SymPy behaves in accordance with this theory:

```python
import sympy as sp
x = sp.symbols('x')
sp.integrate(sp.exp(x**2), x)        # sqrt(pi)*erfi(x)/2 — funkcja specjalna, nie elementarna
```
