Pi, Primes, and Complex Numbers
Deriving Leibniz's Formula for Pi via Lattice Points and Gaussian Integers
The Grand Goal: A Formula for Pi
The Leibniz formula for pi is an alternating infinite sum:
This formula is surprising because it connects π, the ratio of a circle's circumference to its diameter, with a series involving only odd integers. Whenever π appears in mathematics, a circle is always hiding somewhere — often very subtly. The goal is to uncover that hidden circle by counting lattice points inside a large circle and expressing that count in two different ways. One way gives π, the other leads to the alternating sum. The key insight behind the simplicity of the final series is a regularity in the way primes behave when placed inside the complex numbers, specifically in the Gaussian integers.
Counting Lattice Points in a Circle
Lattice Points and Area
A lattice point is a point (a,b) in the plane where both a and b are integers — the intersections of grid lines. Consider a circle centered at the origin with radius R. The number of lattice points inside the circle is approximately equal to the area of the circle, πR2, because each lattice point corresponds roughly to one unit of area. For example, a circle of radius 10 has area about 100π, and the actual count of lattice points is close to that number. As R grows large, the percentage error between πR2 and the exact count becomes tiny.
Counting by Rings (Radii)
To find a second expression for \pi R^2\), consider all possible distances from the origin. For a lattice point(a,b),itsdistancefromtheoriginis\sqrt{a^2 + b^2}.Sincea^2 + b^2$ is always an integer (the sum of two squares), only circles whose radii are square roots of integers are relevant:
Radius 0: the single origin point.
Radius 1: hits 4 points (±1,0),(0,±1).
Radius 2: hits 4 points (±1,±1).
Radius 3: no lattice points (3 cannot be written as sum of two squares).
Radius 4: hits 4 points (±2,0),(0,±2).
Radius 5: hits 8 points (±2,±1),(±1,±2).
The number of lattice points on each ring seems chaotic, but it is deeply tied to the prime factorization of the integer n=a2+b2. This chaos is a sign that interesting number theory is at work.
Gaussian Integers: A New Perspective
Complex Numbers as Coordinates
Instead of viewing a lattice point as the pair (a,b), view it as the complex number a+bi. The distance squared from the origin is a2+b2, which can be written as the product:
where a−bi is the complex conjugate of a+bi. Geometrically, multiplying a+bi by its conjugate rotates the point back to the positive real axis and scales by its magnitude squared.
The set of all complex numbers a+bi with a,b∈Z is called the Gaussian integers, denoted Z[i]. They form a number system analogous to ordinary integers, but living in the complex plane.
Factorization in the Gaussian Integers
Just as ordinary integers factor uniquely into primes (up to signs), Gaussian integers factor uniquely into Gaussian primes — but with some twists. The units (numbers that divide 1) are ±1 and ±i, so a factorization can be altered by multiplying any factor by a unit.
For example, the ordinary prime number 5 can be factored in Gaussian integers:
Both 2+i and 2−i are Gaussian primes (cannot be factored further into smaller Gaussian integers). The factorization is "almost unique": the only variations come from multiplying factors by ±1 or ±i.
Prime Numbers Modulo 4 and Factoring
The Crucial Pattern
The behavior of an ordinary prime number inside the Gaussian integers depends entirely on its remainder when divided by 4.
Primes p≡1(mod4) (e.g., 5, 13, 17, 29, ...) can always be factored into two distinct conjugate Gaussian primes: p=(a+bi)(a−bi) for some integers a,b. This corresponds to the fact that the ring of radius p always hits lattice points — exactly 8 of them (counting the four unit rotations of each Gaussian integer).
Primes p≡3(mod4) (e.g., 3, 7, 11, 19, ...) cannot be factored in the Gaussian integers. They remain prime even in this larger system. Hence, the ring of radius p hits no lattice points at all.
The prime 2 is special. It factors as 2=(1+i)(1−i). However, these two factors are rotations of each other: multiplying one by i gives the other. This will affect the counting.
This regularity — that a prime's remainder mod 4 determines whether it splits — is the fundamental pattern we exploit.
Counting Lattice Points via Factorization (Recipe)
The Basic Recipe
To count how many lattice points lie on the circle of radius n (i.e., how many Gaussian integers z satisfy z⋅z=n), follow this recipe for a given integer n:
Factor n into ordinary primes, then further factor those primes into Gaussian primes where possible.
Organize the Gaussian primes into two columns, placing each prime and its complex conjugate in opposite columns. (This ensures the products of the two columns are conjugates.)
Multiply the left column to get a Gaussian integer z. Then z⋅z=n.
Multiply by units (1,i,−1,−i) to account for all rotations.
The number of distinct z produced equals the number of lattice points on that circle.
Examples
n=25=52: Since 5=(2+i)(2−i), we have two copies of each conjugate pair. The possible distributions of the two 2+i factors between the left and right columns yields three distinct outputs (up to units): 3+4i, 5, 3−4i. Multiplying each by the four units gives 3×4=12 lattice points — exactly what is observed on the circle of radius 25.
n=125=53: There are four ways to distribute the three 2+i factors (0,1,2,3 in left column). Times 4 units gives 4×4=16 lattice points — matches observation.
n=3×125=375: The prime 3 does not split. It cannot be placed in one column only, because that would break the conjugate pairing. No Gaussian integer exists with norm 375 — zero lattice points.
n=32×125: Now 3 appears with even exponent. Place one 3 in each column (3 is its own conjugate) — this adds no new choices. The count remains 4×4=16.
General Rules
For a prime p≡1(mod4) appearing with exponent e, the number of choices contributed is e+1 (you can put 0, 1, ..., e of its split factors in the left column).
For a prime p≡3(mod4) with exponent e:
If e is even, exactly 1 way to balance the columns.
If e is odd, 0 ways (impossible).
The prime 2, with exponent e, always contributes exactly 1 because swapping its factors just duplicates the unit rotation step.
Finally, multiply by 4 for the unit rotations.
The Chi Function (χ)
Definition
Define a function χ on the natural numbers as follows:
This produces a cyclic pattern: 1,0,−1,0,1,0,−1,0,….
Multiplicative Property
χ is multiplicative: for any integers m,n,
For example, χ(3)⋅χ(5)=(−1)(1)=−1, and χ(15)=−1. This property is crucial.
Expressing the Count Using χ
The number of lattice points on the circle of radius n can be rewritten as:
where r2(n) denotes the number of Gaussian integers with norm n (including zero? We exclude zero). How does this formula emerge?
For each prime power pe:
If p≡1(mod4), χ(pk)=1 for all k, so ∑k=0eχ(pk)=e+1, matching the e+1 choices.
If p≡3(mod4), χ(pk)=(−1)k. Then ∑k=0e(−1)k=1 if e is even (since the sum oscillates and cancels in pairs), and 0 if e is odd. This exactly captures the allowed/disallowed cases.
For p=2, χ(2k)=0 for k≥1, so ∑k=0eχ(2k)=1, reflecting that 2 contributes nothing extra.
Because χ is multiplicative, the sum over all divisors of n of χ(d) equals the product over prime powers of these sums. The factor of 4 accounts for the unit rotations.
Example: n=45=32×5. Then
Thus r2(45)=4×2=8. Indeed, 45 can be expressed as a sum of two squares in two ways (up to sign/order): 45=62+32=32+62 (which are the same set of points) and also 45=02+452? Wait, 45 is not a perfect square, but 45=9+36=32+62, giving 8 lattice points: (±3,±6) and (±6,±3).
From Lattice Count to Pi
Total Lattice Points Inside a Large Circle
Consider a large circle of radius R. The total number of lattice points inside (excluding the origin for convenience, as it contributes negligibly as R→∞) can be expressed in two ways:
Area estimate: Count≈πR2.
Exact count via rings: For each integer n from 1 up to R2, the number of lattice points at distance n is r2(n). So
Reorganizing by Divisors
Now we sum in a different order. Instead of fixing n, fix a divisor d. For how many n in 1,…,R2 is d a divisor? Approximately R2/d times (it may not be exact, but the error becomes negligible as R→∞). Then
Because χ(d)=0 for even d, only odd d contribute. For odd d, χ(d)=1 if d≡1(mod4), and χ(d)=−1 if d≡3(mod4). Therefore the sum becomes:
Equating the Two Estimates
As R grows, the approximation from area becomes exact in the limit, and the approximation from divisor sum also becomes exact (the fractional parts wash out). So
Cancel R2 (which is arbitrary) and we obtain the Leibniz formula:
Summary and Significance
The journey reveals several deep connections:
The circle hides in the lattice point counting problem. The alternating sum emerges naturally when reorganizing sums over divisors.
The prime number regularity — that primes ≡1(mod4) split in the Gaussian integers while primes ≡3(mod4) remain prime — is the engine that makes the chi function multiplicative and yields the simple series.
This path illustrates the intersection of algebraic number theory (Gaussian integers, unique factorization in extensions) and analytic number theory (L-functions like ∑χ(n)/ns). The series we derived is essentially the value of Dirichlet's L-function L(1,χ).
The proof presented here is not the shortest (that would be a direct calculus expansion of arctanx), but it reveals the hidden structural reasons why the formula is true — a satisfying explanation rather than mere manipulation.

Ask anything
We've read this whole study set, so questions about it get the best answers.