# The unreasonable deepness of number theory

One of the weirdest things in mathematics is how completely unrelated fields tend to connect with one another.  
A particularly interesting case is the play between number theory (the study of natural numbers $\mathbb{N}=\{0,1,2\dots\}$) and complex analysis (the study of functions on $\mathbb{C}=\{a+bi:a,b\in \mathbb{R}\}$). One is discrete and uses modular arithmetic and combinatorics; one is continuous and uses integrals and epsilon-delta proofs. And yet, many papers in modern number theory use complex analysis. Even if not directly, basically all of them rely on some result with a complex analytic flavor.

What's going on?

This post gives an example of a fundamental result in number theory that uses complex analysis, and tries to explain where that usage is coming from. My writing is semi-technical, I'm not trying to formalize everything, but mostly doing this as an exercise to clear out my own confusion (and hopefully to convince others of why this mathematical connection is valuable).

Technical details in the proof follow [Ang Li’s notes](https://math.uchicago.edu/~may/REU2012/REUPapers/LiAng.pdf); exposition, intuition and possible mistakes are mine.

I Dirichlet's Theorem
=====================

We know that [there are infinitely many prime numbers](https://en.wikipedia.org/wiki/Euclid's_theorem) since around 300 BC. Over 2000 years later, Dirichlet proved that there are infinitely many primes even if we restrict ourselves to an arithmetic progression of the form $a,a+q,a+2q,\dots$, as long as $a,q$ have no common factors.

I'll focus on a concrete example: **there are infinitely many prime numbers ending in the digit 7, that is, primes of the form **$p=10n+7$**.**

This statement can be understood by a curious 7-year-old: she could learn about prime numbers, then write out examples of them - her own age, 17, 37, ... and then be told that, although such numbers ending in 7 become harder and harder to find, they will always be there, beyond whatever limits we imagine.

If the statement is so easy to phrase, why does it require complex analysis?  
Do we really need to use a number defined as the square root of -1, as well as computing infinite sums and integrals, just to handle primes ending in 7?  
You might say that this is necessary because we're working with an "infinite" object, and that necessarily requires tools from analysis. But that's not dissipating the mystery. Here's a simpler statement:

> There is a natural number $N>10^{10^{100}}$ such that $10N+7$ is prime.

This statement has a finite "elementary" proof. In fact, I can guide you on how to construct one: start with $N=10^{10^{100}}+1$ and keep adding 1 until you get that $10N+7$ is prime (as verified by [your favorite primality test](https://en.wikipedia.org/wiki/AKS_primality_test)). This search will stop at some point when we get to a definite prime. Done.

This template of a proof clearly isn't enough; how do we know for sure that it will stop? we can't actually run the search, because just writing out $N$ requires more space than there are atoms in the known universe.

And yet, we know for sure that this algorithm will stop with a definite prime. And we got this knowledge from properties of $\log(z)$ and $i=\sqrt{-1}$. But why?

II Euler's proof for infinitude of primes
=========================================

First we'll prove the easier result: that there are infinitely many primes, without restricting their last digit.

Euler came up with an interesting proof, that shows something stronger than that: the sum $\sum_p \frac{1}{p}$, made by summing over all primes $p$, diverges to infinity.

This implies the infinitude of primes, because in order for a sum of finite terms to have an infinite value, it must have infinitely many terms. It's also a nice trick to turn a "combinatorial" problem (about the amount of prime numbers) to an "analytic" problem (about the divergence of a certain sum).  
How would we go about proving something like that?  
Well, we have one classic example of a divergent infinite sum - the harmonic series:

$$
\sum_{n\ge 1} \frac{1}{n} = \infty.
$$

We want some way to express this sum in terms of prime numbers. 

Primes are the building blocks of the natural numbers: each number can be written as a unique product of prime numbers. So it makes sense to write this sum in terms of products involving prime numbers.

Let's first sum over natural numbers whose only prime factors are 2 and 3. We'll denote this set by $N_{2,3}:=\{2^a3^b |a,b\ge 0\}.$ We have:

$$
\sum_{n\in N_{2,3}} \frac{1}{n}= \sum_{a,b\ge 0} \frac{1}{2^a 3^b}.
$$

We can use the distributive law, to write this as the product of two distinct sums:

$$
\sum_{n\in N_{2,3}} \frac{1}{n}= \left(\sum_{a\ge 0} \frac{1}{2^a}\right) \cdot \left(\sum_{b\ge 0} \frac{1}{3^b}\right).
$$

Each sum on the right-hand side is an infinite geometric series. We know that $\sum_{m\ge 0} r^m = \frac{1}{1-r}$ whenever the sum converges. So we have a simple closed formula:

$$
\sum_{n\in N_{2,3}} \frac{1}{n}= \left( \frac{1}{1-1/2}\right)\cdot \left( \frac{1}{1-1/3} \right).
$$

This is when summing over numbers whose only prime factors are 2 and 3. If we add 5 as a prime factor, by summing over $N_{2,3,5}:=\{2^a3^b5^c |a,b,c\ge 0\}$, we get:

$$
\sum_{n\in N_{2,3,5}} \frac{1}{n}= \sum_{a,b,c\ge 0}\frac{1}{2^a 3^b 5^c}
$$

$$
= \left(1+\frac{1}{2}+\frac{1}{2^2}+\cdots\right)\cdot \left(1+\frac{1}{3}+\frac{1}{3^2}+\cdots\right) \cdot \left(1+\frac{1}{5}+\frac{1}{5^2}+\cdots\right)
$$

$$
=\left( \frac{1}{1-1/2}\right)\cdot \left( \frac{1}{1-1/3} \right) \cdot \left( \frac{1}{1-1/5} \right).
$$

And we carry on, each time adding a new prime factor to our set. This makes the left-hand side sum over more natural numbers, while the right-hand side gets more factors.

Since all natural numbers are products of *some* prime numbers, in the limit we get the identity:

$$
\sum_{n\ge 1}\frac{1}{n} = \prod_p \left(\frac{1}{1-1/p}\right) \qquad (*)
$$

where $p$ ranges over all prime numbers. This is the key identity for our purposes.[^0j1kh28fdhvr]

On itself, $(*)$ is already enough to show the infinitude of primes; the LHS is infinite, while the RHS is a product of terms, one term for each prime number. This only makes sense if the product has infinitely many terms.

But still, we want to show that $\sum_p \frac{1}{p}$ diverges, which is a stronger requirement. We wish to use $(*)$, but it involves **products** over prime numbers, not **sums** over prime numbers.

Which mathematical machinery can we use to turn products into sums?

![A mathematician getting hit in the head by a tree log](https://39669.cdn.cke-cs.com/rQvD3VnunXZu34m86e5f/images/117b679255a6f9312a18e634248c707c0a45e0b7d3072f08.png)

Oh, right; the natural logarithm satisfies $\log(xy)=\log(x)+\log(y)$. This holds for infinite products/sums as well:

$$
\log \left (\prod_p \left(\frac{1}{1-1/p}\right)\right) = \sum_p \log\left(\frac{1}{1-1/p}\right)
$$

$$
\implies \log\left( \sum_{n\ge 1}\frac{1}{n} \right) =\sum_p \log\left(\frac{1}{1-1/p}\right). \qquad(**)
$$

The function $\log(\frac{1}{1-x})$ has a nice Taylor expansion: $\log(\frac{1}{1-x})=x+\frac{x^2}{2}+\frac{x^3}{3}+\cdots$. We only care about asymptotic behavior, so for small $x$, we can approximate $\log(\frac{1}{1-x})\approx x$.[^1pbpg136z11]

Substituting that into $(**)$, we get:

$$
\log\left( \sum_{n\ge 1}\frac{1}{n} \right) \approx \sum_p \frac{1}{p}. \qquad (\star)
$$

Since the left term diverges, the right term also diverges, so $\sum_p \frac{1}{p}=\infty$. Done.

III Trying the same for Dirichlet
=================================

This was a cool trick; we proved a purely number-theoretic result using tools from analysis, like taking the Taylor series of a logarithm.

Can we do the same thing for proving the infinitude of primes of the form $10n+7$?

Let $\delta_7(n)$ denote the function that returns 1 whenever $n\equiv 7 \mod 10$, and 0 otherwise. We want to show that infinitely many primes satisfy $\delta_7(p)=1$. Dirichlet actually shows the stronger claim, that $\sum_p \frac{\delta_7(p)}{p}=\infty$ (remember that $p$ ranges over prime numbers while $n$ ranges over all natural numbers). How do we do that?

We can try a similar technique to Euler's proof. The analogue of identity $(*)$ would be:

$$
\sum_{n\ge 1}\frac{\delta_7(n)}{n} = \prod_p \left(1+\frac{\delta_7(p)}{p}+\frac{\delta_7(p)^2}{p^2}+\cdots\right)= \prod_p \left(\frac{1}{1-\delta_7(p)/p}\right).
$$

Unfortunately, this doesn't hold. The second equality is still valid, but the first one fails, because $\delta_7$ is not a *multiplicative* function; we have $\frac{1}{ab}=\frac{1}{a}\cdot \frac{1}{b}$ but we don't have $\delta_7(ab)=\delta_7(a)\cdot \delta_7(b)$. (Concretely, $\delta_7(3)=\delta_7(9)=0$ but $\delta_7(3\cdot 9)=1$.)

But this identity *does* hold whenever we replace $\delta_7$ with a multiplicative function $\chi$, one that satisfies $\chi(ab)=\chi(a)\chi(b)$ for all natural numbers $a,b$. That is, we have for such $\chi$:

$$
\sum_{n\ge 1}\frac{\chi(n)}{n} = \prod_p \left(\frac{1}{1-\chi(p)/p}\right).
$$

Euler's original proof used this identity for the constant function $\chi(n)=1$.

How do we use this property for analyzing $\delta_7$?

The main idea is to write $\delta_7$ as a linear combination of multiplicative functions. If we analyze each $\chi$ separately, combining them gives us insight to the resulting function.

Well, $\delta_7(n)$ is a periodic function on the integers of period 10. It's a signal, or a heart beat. It beats with the value 1 every 10 integers, and is flat elsewhere.

We already have a technique to write a general periodic signal as a sum of well-behaved components - a Fourier sum:

![undefined](https://upload.wikimedia.org/wikipedia/commons/e/e8/Periodic_identity_function.gif)

Partial Fourier approximations of the sawtooth wave. Credit: [Wikipedia](https://commons.wikimedia.org/wiki/File:Periodic_identity_function.gif)

Fourier series and Fourier transforms are examples of a [much more general concept](https://en.wikipedia.org/wiki/Pontryagin_duality). I won't get into the details here, but if you have a group $G$ satisfying some properties, then you can write every (suitably regular) function $f:G\to \mathbb{C}$ as a combination of multiplicative functions $\chi:G\to \mathbb{C}^\times$. Fourier transforms act on $G=\mathbb{R}$, Fourier sums act on the circle group $G=\mathbb{R}/\mathbb{Z}$, while our example acts on the group $G=(\mathbb{Z}/10\mathbb{Z})^*$ of invertible elements modulo 10. (Don't worry if you are not familiar with groups.)

The main point is that, given a function $f:\mathbb{N}\to \mathbb{R}$ with period 10, we can always[^meufn0m8cyd] write it as a linear combination of multiplicative functions $\chi:\mathbb{N}\to \mathbb{C}$ of the same period. These multiplicative components are called *characters*.  

Allowing $\chi$ to range over complex numbers is necessary; just using real-valued functions isn't enough. This is similar to how Fourier sums require both a cosine and a sine component, where considering only real-valued components only gives us the cosine part. This is the reason why complex numbers are fundamental to our proof - we need roots of unity $\omega =e^{2\pi i/k}$ in order to have a rich choice of characters (the real numbers only have $+1,-1$ as possible character values).

Finding all characters modulo 10 is rather easy. Here they are:

|     | ** 1** | ** 3** | **7** | **9** |
| --- | --- | --- | --- | --- |
| $\\chi_0$ | 1   | 1   | 1   | 1   |
| $\\chi_1$ | 1   | +i  | -i  | -1  |
| $\\chi_2$ | 1   | -i  | +i  | -1  |
| $\\chi_3$ | 1   | -1  | -1  | 1   |

There are 4 such characters in total: $\chi_0,\chi_1,\chi_2,\chi_3$. Since they are 10-periodic, it's enough to write out their values on the set $\{0,1,\dots,9\}$. Also, $\chi(n)=0$ whenever $n$ and 10 have a common divisor, so we can throw out all multiples of 2 and 5; we're left with just 4 values $n=1,3,7,9$ that $\chi$ has a non-zero value on. These values are described in the table above.

One can check that all characters defined above are multiplicative: $\chi(ab)=\chi(a)\chi(b)$. (This is when working modulo 10, so for example, $3\cdot 9 \equiv 7$.)

Finally, we can see that the following identity holds (one can check it explicitly for $n=1,3,7,9$):

$$
\delta_7(n)=\frac{1}{4}\left(\chi_0(n)+i\chi_1(n)-i\chi_2(n)-\chi_3(n)\right).
$$

Going back, we wanted to show that $\sum_p \frac{\delta_7(p)}{p}$ diverges. We'll write it as a sum of these 4 components:

$$
\sum_p \frac{\delta_7(p)}{p} = \frac{1}{4}\left(\sum_p \frac{\chi_0(p)}{p} + i\sum_p \frac{\chi_1(p)}{p} -i\sum_p \frac{\chi_2(p)}{p} - \sum_p \frac{\chi_3(p)}{p} \right). \qquad (\dagger)
$$

We know that the first term diverges: $\sum_p \frac{\chi_0(p)}{p}=\infty$. This is because all primes besides $p=2,5$ satisfy $\chi_0(p)=1$; this is almost equivalent to $\sum_p \frac{1}{p}$, which was already proven to diverge.

What about the three other components?

They involve sums of the form $\sum_p \frac{\chi(p)}{p}$, where $\chi$ is a non-trivial character; it's not always equal to 1, and we may have $\chi(n)=-1,+i,-i$ as well.

Looking again into the table above, we see that besides $\chi_0$, all other rows sum to 0. That is, $\chi$ sums to 0 when summing over all integers modulo 10:

$$
\sum_{n=0}^9 \chi(n)=0.
$$

Fourier series have a similar phenomenon; there is the "constant" component $\cos(0x)=1$, but all other components $\cos(nx),\sin(nx)$ for $n\ge1$ create a periodic "wave" that cancels out:

$$
\int_0^{2\pi} \cos(nx) dx = \int_0^{2\pi}  \sin(nx) dx = 0.
$$

This is not a coincidence because nothing is ever a coincidence.

Since $\chi(p)$ has a cancelling-out behavior, we might expect that unlike for $\chi_0$, $\sum_p \frac{\chi(p)}{p}$ remains bounded; this is like how $\int_1^\infty \frac{\sin(x)}{x}dx<\infty$ even though $\int_1^\infty \frac{1}{x}dx=\infty$. This does turn out to be the case. 

After proving that, we look back in $(\dagger)$: The right-hand side is a sum of 4 components. The first one is infinite, while the other three are bounded. Intuitively (this can be formalized), divergent sum + bounded sum = divergent sum. Thus, the entire expression is divergent. Since the left-hand side is a sum over all primes $p\equiv 7 \mod 10$ (these are the only primes with $\delta_7(p)\neq 0$), the number of such elements must be infinite. Done.

IV Wrapping up (or: getting started)
====================================

Of course, we're not really done. We have to prove that $\sum_p \frac{\chi(p)}{p}$ is bounded whenever $\chi$ is a non-trivial character modulo 10.

A first step would be to revisit formula $(\star)$, that relates sums over all natural numbers to sums over all prime numbers. The same reasoning as above, while using the fact that$$ $\chi$ is multiplicative, gives us:[^xc6wdl7g65f]

$$
\log\left( \sum_{n\ge 1}\frac{\chi(n)}{n} \right) = \log \left (\prod_p \left(\frac{1}{1-\chi(p)/p}\right)\right) \approx \sum_p \frac{\chi(p)}{p}.
$$

This means that to show that $\sum_p \frac{\chi(p)}{p}$ is bounded, it's enough to show that the infinite series $L(\chi):= \sum_{n\ge 1}\frac{\chi(n)}{n}$ converges to a non-zero number. (If $L(\chi)=0$ then $\log(L(\chi))$ diverges, breaking our argument.)

Showing that $$$\sum_{n\ge 1}\frac{\chi(n)}{n}$ converges to a finite number turns out to be pretty easy; we use [summation by parts](https://en.wikipedia.org/wiki/Summation_by_parts), a discrete analogue of integration by parts, the same technique which shows that $\int_1^\infty \frac{\sin(x)}{x}dx$ converges.

So, the only thing keeping us from showing that there are infinitely many prime numbers ending with 7, is the following claim:

> $L(\chi) := \sum_{n\ge 1}\frac{\chi(n)}{n}$  satisfies $L(\chi)\neq 0$ whenever $\chi$ is a non-trivial character modulo 10.

There are three sums to check: $$$L(\chi_1),L(\chi_2),L(\chi_3)$ (for $\chi$ as defined in the table above). Each one of them can be calculated explicitly to a high-enough degree of accuracy, showing that the final sum escapes 0. So, by doing additional finite calculation, we are *truly* done.

The next step is to prove the *general* form of Dirichlet's theorem: if $a,q$ are coprime, then $a+nq$ contains infinitely many prime numbers. Our proof only worked for $q=10$.

The same techniques work for other $q$, but this time, we can't calculate $L(\chi)$ explicitly; there are infinitely many characters to check. 

In the general case proving $L(\chi)\neq 0$ is very hard - in fact, this is the main difficulty of the proof!

This is a typical phenomenon in analytic number theory: given some problem involving prime numbers, there is a standard way to encode it in the language of complex numbers (typically using the Riemann zeta function or other character sums like $L(\chi)$), and the hard part is to show that some analytic bound holds.

V Looking ahead
===============

After studying enough number theory, proofs like the one above start feeling more intuitive to me. I already know how the arguments take place, what's the role of each component, how they play with each other and what are the main difficulties. 

At some point, I was even able to give my own new observations and prove them using similar techniques.

Unfortunately, after all that, I notice that I am still confused. 

There are fundamental rules of the universe that I don't yet understand. And for some reason, one of them seems to spell out: "*thou shall use complex-valued analysis to study the behavior of prime numbers"*. 

This is not always the case; some well-known statements in number theory which were proven with complex-analytic methods were later proved by other means. In fact, [Dirichlet's theorem is one of them](https://www.jstor.org/stable/1969454)! But I am still not satisfied, because:

*   Many results still weren't proved with elementary methods. Good luck showing that $N=10^{10^{100}}+1$ can be written as a sum of three prime numbers without using complex analysis! This refers to *Goldbach's weak conjecture*, which was proven [in 2013](https://arxiv.org/abs/1312.7748) with quite the intricate analysis, and we're not anywhere close to finding a simpler solution.
*   Often these "elementary" proofs are more technical and less clear than their complex-analytic versions. This suggests that looking in the complex numbers is the "right" thing to do; it is a better map for our territory.

This is far from being the only mystery in mathematics. When going deep enough into some field, we see more and more surprising connections. [Homotopy type theory](https://en.wikipedia.org/wiki/Homotopy_type_theory) is one of them; [Monstrous moonshine](https://en.wikipedia.org/wiki/Monstrous_moonshine) is another. I chose to introduce a specific connection I'm more familiar with. If anyone has insights into these other connections, please share them here. 

Maybe studying more math will resolve my confusion. But until then, I remain awestruck by the unreasonable deepness of number theory.

[^0j1kh28fdhvr]: Since the sum \(\sum_{n\ge 1}1/n\) diverges, doing algebraic manipulations on this series is tricky; this can often result in nonsense results like \(1+2+3+4+\cdots = -1/12\). The formal proof involves the series \(\sum_{n\ge 1}1/n^s\) instead, for \(s>1\), and studying the asymptotic behavior as \(s\to 1^+\). I ignore this (important) detail here. 

[^1pbpg136z11]: Formally, we say that \(\log(1/(1-x))=x+O(x^2)\). Instead of saying things are approximately equal, we show an explicit bound on the error term, and note that the total error \(\sum_p p^{-2}\) is finite. 

[^meufn0m8cyd]: Assuming \(f(n)=0\) whenever \(n\) and 10 have a common divisor. 

[^xc6wdl7g65f]: Defining \(\log(z)\) over complex numbers is non-trivial, as \(\log\) is a multi-branch function. Li's notes (link above) show how to settle this over the required domain.