1. Home
  2. Explore
  3. Mathematics
  4. Leibniz Formula for Pi

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Leibniz Formula for Pi

Leibniz-Madhava Formula and Sums of Squares

The Leibniz-Madhava Series

The formula for π4\frac{\pi}{4}4π​ as an alternating series of odd reciprocals is:

π4=1−13+15−17+19−111+⋯\frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \frac{1}{11} + \cdots4π​=1−31​+51​−71​+91​−111​+⋯

This series is named after Gottfried Wilhelm Leibniz (17th century), but was first discovered by the Indian mathematician Madhava of Sangamagrama in the 14th century, over 200 years earlier. It is therefore often called the Leibniz–Madhava series.

The series is surprising because π\piπ is fundamentally a circle constant (ratio of circumference to diameter), yet the series only involves odd numbers with no obvious connection to circles. However, the series can be derived from the area formula of a circle, revealing a hidden circle.

Good and Bad Odd Numbers

In the sequence of odd numbers 1,3,5,7,9,11,13,15,…1, 3, 5, 7, 9, 11, 13, 15, \dots1,3,5,7,9,11,13,15,…, classify them into two types:

  • Good odd numbers: those of the form 4k+14k+14k+1 (i.e., 1,5,9,13,17,…1, 5, 9, 13, 17, \dots1,5,9,13,17,…). When divided by 4, they leave remainder 1.

  • Bad odd numbers: those of the form 4k+34k+34k+3 (i.e., 3,7,11,15,19,…3, 7, 11, 15, 19, \dots3,7,11,15,19,…). When divided by 4, they leave remainder 3.

The positive terms in the Leibniz–Madhava series have denominators that are good odd numbers (1,5,9,…1, 5, 9, \dots1,5,9,…), and the negative terms have denominators that are bad odd numbers (3,7,11,…3, 7, 11, \dots3,7,11,…). This classification is central to the connection with sums of squares.

Counting Lattice Points in a Circle

Consider the integer lattice in the plane: all points (x,y)(x,y)(x,y) with integer coordinates. Draw a circle of radius rrr centered at the origin. Let N(r)N(r)N(r) be the number of lattice points inside or on the circle. Because each lattice point can be thought of as the center of a unit square, N(r)N(r)N(r) approximates the area of the circle, which is πr2\pi r^2πr2. As r→∞r \to \inftyr→∞, the approximation becomes exact:

lim⁡r→∞N(r)r2=π\lim_{r \to \infty} \frac{N(r)}{r^2} = \pilimr→∞​r2N(r)​=π

For example, with r=7r = 7r=7, N(7)=149N(7) = 149N(7)=149, so π≈149/49≈3.0408\pi \approx 149/49 \approx 3.0408π≈149/49≈3.0408, a rough approximation. With r=1000r=1000r=1000, π\piπ is approximated to 3.14153.14153.1415. In the limit, equality holds.

Counting Lattice Points by Representing Integers as Sums of Two Squares

A lattice point (x,y)(x,y)(x,y) lies inside the circle of radius rrr if and only if x2+y2≤r2x^2 + y^2 \le r^2x2+y2≤r2. Since xxx and yyy are integers, the value x2+y2x^2 + y^2x2+y2 is an integer between 000 and r2r^2r2 (inclusive). Therefore, N(r)N(r)N(r) can be counted by:

  1. List all integers nnn from 000 to r2r^2r2.

  2. For each nnn, count the number of ways to write nnn as x2+y2x^2 + y^2x2+y2 with integers x,yx, yx,y (including negative integers and zero).

  3. Sum all those counts.

Because of the symmetry of the lattice (positive/negative signs, swapping xxx and yyy), the number of ways for a positive integer nnn is always a multiple of 444, except for n=0n=0n=0 (which has exactly 1 way: 02+020^2+0^202+02). For example:

  • 000: 1 way (the origin)

  • 111: 4 ways ((±1,0)(\pm1,0)(±1,0) and (0,±1)(0,\pm1)(0,±1))

  • 222: 4 ways ((±1,±1)(\pm1,\pm1)(±1,±1))

  • 333: 0 ways

  • 444: 4 ways ((±2,0)(\pm2,0)(±2,0) and (0,±2)(0,\pm2)(0,±2))

  • 555: 8 ways ((±2,±1)(\pm2,\pm1)(±2,±1) and (±1,±2)(\pm1,\pm2)(±1,±2))

Thus, N(r)=1+4×(total number of representations of 1 to r2)N(r) = 1 + 4 \times (\text{total number of representations of } 1 \text{ to } r^2)N(r)=1+4×(total number of representations of 1 to r2), but the representation count for each nnn is not simply the number of representations; it's the sum of representation counts over nnn. This is where the good/bad factor theorem simplifies the counting.

Fermat's Christmas Theorem (Prime Case)

Fermat's Christmas Theorem: A prime number ppp can be expressed as a sum of two integer squares if and only if ppp is a good prime (i.e., p=2p = 2p=2 or p≡1mod  4p \equiv 1 \mod 4p≡1mod4). Bad primes (p≡3mod  4p \equiv 3 \mod 4p≡3mod4) cannot be written as a sum of two squares.

Despite the name, the theorem was first stated by Albert Girard in 1625, 15 years before Fermat's letter to Mersenne on Christmas Day 1640. The first published proof was given by Euler.

This theorem is the prime case of a more general result about all integers.

Jacobi's Two-Square Theorem (General Case)

Jacobi's two-square theorem: Let nnn be a positive integer. The number of ways to write nnn as a sum of two integer squares (counting order and signs) is 4(d1(n)−d3(n))4(d_1(n) - d_3(n))4(d1​(n)−d3​(n)), where d1(n)d_1(n)d1​(n) is the number of divisors of nnn that are congruent to 1mod  41 \mod 41mod4 (good odd divisors), and d3(n)d_3(n)d3​(n) is the number of divisors of nnn that are congruent to 3mod  43 \mod 43mod4 (bad odd divisors). That is:

\text{# representations} = 4 \times (\text{# good odd divisors} - \text{# bad odd divisors})

For example, n=18n = 18n=18: the odd divisors of 18 are 1,3,91, 3, 91,3,9. Good divisors: 111 and 999 (both ≡1mod  4\equiv 1 \mod 4≡1mod4). Bad divisor: 333 (≡3mod  4\equiv 3 \mod 4≡3mod4). So 2−1=12 - 1 = 12−1=1, times 444 gives 444 ways. Indeed, 18=32+32=(−3)2+32=32+(−3)2=(−3)2+(−3)218 = 3^2 + 3^2 = (-3)^2 + 3^2 = 3^2 + (-3)^2 = (-3)^2 + (-3)^218=32+32=(−3)2+32=32+(−3)2=(−3)2+(−3)2, counting order? Actually careful: the representation 32+323^2+3^232+32 is counted 4 times due to signs of each number (two numbers can each be ±3\pm 3±3), that's 4 ways. So the theorem holds.

This theorem is named after Carl Gustav Jacob Jacobi.

Deriving the Leibniz-Madhava Series from Circle Area

To derive the series, combine the lattice-point counting with Jacobi's theorem.

Let rrr be a positive integer radius. Count N(r)N(r)N(r) by summing over all nnn from 000 to r2r^2r2:

N(r)=1+∑n=1r24(#good odd divisors of n−#bad odd divisors of n)N(r) = 1 + \sum_{n=1}^{r^2} 4\big( \#\text{good odd divisors of } n - \#\text{bad odd divisors of } n \big)N(r)=1+∑n=1r2​4(#good odd divisors of n−#bad odd divisors of n)

The number 111 accounts for the origin (n=0n=0n=0).

Now, change the summation order: instead of summing over nnn (columns), sum over each odd divisor (rows). For each odd number ddd, count how many nnn in 1,…,r21,\dots,r^21,…,r2 have ddd as a divisor. For a fixed odd ddd, the multiples of ddd up to r2r^2r2 are d,2d,3d,…,⌊r2/d⌋⋅dd, 2d, 3d, \dots, \lfloor r^2/d \rfloor \cdot dd,2d,3d,…,⌊r2/d⌋⋅d. So each good odd divisor ggg contributes +1+1+1 for each multiple; each bad odd divisor bbb contributes −1-1−1 for each multiple.

Thus, the total difference (good - bad) summed over nnn equals:

∑g odd, g≡1mod4⌊r2g⌋  −∑b odd, b≡3mod4⌊r2b⌋\sum_{\substack{g \text{ odd, } g \equiv 1 \!\!\!\mod 4}} \left\lfloor \frac{r^2}{g} \right\rfloor \; - \sum_{\substack{b \text{ odd, } b \equiv 3 \!\!\!\mod 4}} \left\lfloor \frac{r^2}{b} \right\rfloor∑g odd, g≡1mod4​​⌊gr2​⌋−∑b odd, b≡3mod4​​⌊br2​⌋

Now group the odd numbers in order: 1,3,5,7,9,11,…1, 3, 5, 7, 9, 11, \dots1,3,5,7,9,11,…. The sign alternates: 111 is good (positive), 333 is bad (negative), 555 is good (positive), 777 is bad (negative), etc. So we can write:

∑k=0∞(−1)k⌊r22k+1⌋\sum_{k=0}^{\infty} (-1)^k \left\lfloor \frac{r^2}{2k+1} \right\rfloor∑k=0∞​(−1)k⌊2k+1r2​⌋

But careful: the sum includes only odd numbers up to r2r^2r2? Actually as kkk increases, the integer part becomes zero for 2k+1>r22k+1 > r^22k+1>r2, so the sum is finite.

Therefore:

N(r)=1+4∑k=0∞(−1)k⌊r22k+1⌋N(r) = 1 + 4 \sum_{k=0}^{\infty} (-1)^k \left\lfloor \frac{r^2}{2k+1} \right\rfloorN(r)=1+4∑k=0∞​(−1)k⌊2k+1r2​⌋

Now recall the limit:

π=lim⁡r→∞N(r)r2\pi = \lim_{r\to\infty} \frac{N(r)}{r^2}π=limr→∞​r2N(r)​

Divide both sides by r2r^2r2:

π=lim⁡r→∞1r2+4lim⁡r→∞∑k=0∞(−1)k⌊r2/(2k+1)⌋r2\pi = \lim_{r\to\infty} \frac{1}{r^2} + 4 \lim_{r\to\infty} \sum_{k=0}^{\infty} (-1)^k \frac{\lfloor r^2/(2k+1) \rfloor}{r^2}π=limr→∞​r21​+4limr→∞​∑k=0∞​(−1)kr2⌊r2/(2k+1)⌋​

The term 1/r2→01/r^2 \to 01/r2→0. For each fixed kkk, ⌊r2/(2k+1)⌋/r2→1/(2k+1)\lfloor r^2/(2k+1) \rfloor / r^2 \to 1/(2k+1)⌊r2/(2k+1)⌋/r2→1/(2k+1) as r→∞r\to\inftyr→∞ (since the floor difference disappears). Interchanging limit and sum (justified by dominated convergence or careful estimation), we obtain:

π=4∑k=0∞(−1)k12k+1\pi = 4 \sum_{k=0}^{\infty} (-1)^k \frac{1}{2k+1}π=4∑k=0∞​(−1)k2k+11​

Dividing both sides by 444 yields the Leibniz-Madhava series:

π4=1−13+15−17+19−⋯\frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \cdots4π​=1−31​+51​−71​+91​−⋯

Thus, the series arises directly from the formula for the area of a circle, using the lattice point count and the sum-of-squares divisor theorem.

The Easy Half: Why Bad Numbers Cannot Be Sums of Two Squares

Fermat's Christmas theorem has an easy half: no integer of the form 4k+34k+34k+3 (bad odd numbers) can be expressed as a sum of two integer squares. This is proved by considering residues modulo 444.

Every integer is congruent to 0,1,2,0, 1, 2,0,1,2, or 333 modulo 444. When we square an integer:

  • If n≡0mod  4n \equiv 0 \mod 4n≡0mod4, then n2≡0mod  4n^2 \equiv 0 \mod 4n2≡0mod4.

  • If n≡1mod  4n \equiv 1 \mod 4n≡1mod4, then n2≡1mod  4n^2 \equiv 1 \mod 4n2≡1mod4. (Since (4m+1)2=16m2+8m+1≡1(4m+1)^2 = 16m^2 + 8m + 1 \equiv 1(4m+1)2=16m2+8m+1≡1)

  • If n≡2mod  4n \equiv 2 \mod 4n≡2mod4, then n2≡0mod  4n^2 \equiv 0 \mod 4n2≡0mod4. ((4m+2)2=16m2+16m+4≡0(4m+2)^2 = 16m^2 + 16m + 4 \equiv 0(4m+2)2=16m2+16m+4≡0)

  • If n≡3mod  4n \equiv 3 \mod 4n≡3mod4, then n2≡1mod  4n^2 \equiv 1 \mod 4n2≡1mod4. ((4m+3)2=16m2+24m+9≡1(4m+3)^2 = 16m^2 + 24m + 9 \equiv 1(4m+3)2=16m2+24m+9≡1)

So a square is always 000 or 111 modulo 444. The sum of two squares can therefore be:

  • 0+0≡00+0 \equiv 00+0≡0

  • 0+1≡10+1 \equiv 10+1≡1

  • 1+0≡11+0 \equiv 11+0≡1

  • 1+1≡21+1 \equiv 21+1≡2

Thus, the sum of two squares can never be 333 modulo 444. Therefore no integer of the form 4k+34k+34k+3 can be written as a sum of two integer squares. This proves that all bad odd numbers (and indeed any 4k+34k+34k+3 integer, even if not prime) are not sums of two squares.

The converse (that good primes can be written as sums of two squares) is harder and requires deeper number theory.

The Product Identity: Connecting Primes to All Integers

An ancient identity, known to the Greeks, is the key to extending the prime case to composites:

(a2+b2)(c2+d2)=(ac−bd)2+(ad+bc)2(a^2 + b^2)(c^2 + d^2) = (ac - bd)^2 + (ad + bc)^2(a2+b2)(c2+d2)=(ac−bd)2+(ad+bc)2

This shows that if two numbers are each sums of two squares, their product is also a sum of two squares. Since every positive integer is a product of primes, if we know which primes are sums of two squares, we can determine representation for any integer. Jacobi's theorem counts the number of representations using the divisor function.

This identity, together with Fermat's theorem, is the foundation of the general theory of sums of squares.

Summary

The Leibniz-Madhava series for π/4\pi/4π/4 is more than a mysterious pattern; it emerges naturally from the geometry of counting integer lattice points in a circle. The counting is simplified by Jacobi's two-square theorem, which expresses the number of representations as a difference of divisor counts. Fermat's Christmas theorem classifies primes as sum-of-two-squares representable or not, based on their residue modulo 444. The series derivation elegantly links π\piπ, the area of a circle, to the alternating sum of reciprocals of odd numbers, revealing the hidden circle within the series.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent