A Living Notebook

Srinivasa Ramanujan

The mathematics of a self-taught genius, made interactive

ERODE, MADRAS PRESIDENCY, 1887  —  CAMBRIDGE & KUMBAKONAM, 1920
"An equation for me has no meaning unless it expresses a thought of God." — attributed to Srinivasa Ramanujan
Prelude

A Brief Life

Srinivasa Ramanujan (1887–1920) grew up in Kumbakonam, South India, with almost no formal training in advanced mathematics. Working largely alone from a single textbook — G. S. Carr's Synopsis of Elementary Results — he filled notebooks with thousands of original results in number theory, infinite series, continued fractions, and what would later be called modular forms. In 1913 he wrote to the Cambridge mathematician G. H. Hardy, who called some of Ramanujan's theorems "not even in the same category as previous work" and arranged for him to come to Trinity College. In five years there, working during the isolation of the First World War, Ramanujan produced results that mathematicians are still unpacking a century later — including the mock theta functions found in the final pages of his life, written from his deathbed at age 32.

Below, each idea is paired with a small interactive calculator you can run right in this page, and a companion example written for GNU Octave — a free numerical computing environment — so you can explore the same mathematics on your own machine.

✦ ✦ ✦
Chapter I

Partitions of Integers

Number Theorywith Hardy, 1918

A partition of a positive integer $n$ is a way of writing it as a sum of positive integers, ignoring order. For example $4$ has five partitions: $4$, $3{+}1$, $2{+}2$, $2{+}1{+}1$, $1{+}1{+}1{+}1$, so $p(4)=5$. Ramanujan and Hardy discovered a strikingly accurate asymptotic formula for how fast $p(n)$ grows:

$$p(n) \sim \frac{1}{4n\sqrt{3}} \, e^{\pi\sqrt{2n/3}} \qquad \text{as } n \to \infty$$

They refined this into the full Hardy–Ramanujan–Rademacher exact formula, one of the first uses of the "circle method," a technique still central to analytic number theory. Ramanujan also found beautiful congruences, such as $p(5n+4) \equiv 0 \pmod 5$ — the number of partitions is always a multiple of 5 whenever $n \equiv 4 \pmod 5$.

Interactive — compute p(n) and the Hardy–Ramanujan estimate

Try it in GNU Octave

Octave
% partitions.m — compute p(n) via Euler's pentagonal number recurrence
function p = partition_count(n)
  p = zeros(n+1,1); p(1) = 1;   % p(0) = 1
  for m = 1:n
    total = 0; k = 1;
    while true
      g1 = k*(3*k-1)/2;  g2 = k*(3*k+1)/2;
      if g1 > m && g2 > m, break; end
      sign = (-1)^(k+1);
      if g1 <= m, total += sign * p(m-g1+1); end
      if g2 <= m, total += sign * p(m-g2+1); end
      k += 1;
    end
    p(m+1) = total;
  end
endfunction

n = 20;
pn = partition_count(n);
printf("p(%d) = %d\n", n, pn(end));

% Hardy-Ramanujan asymptotic estimate
est = 1/(4*n*sqrt(3)) * exp(pi*sqrt(2*n/3));
printf("Hardy-Ramanujan estimate ~ %.2f\n", est);
% >> p(20) = 627
% >> Hardy-Ramanujan estimate ~ 692.79
✦ ✦ ✦
Chapter II

Highly Composite Numbers

Number Theory1915 paper, 52 pages

A highly composite number is a positive integer with more divisors than any smaller positive integer. Ramanujan's 1915 paper on the subject — his first published in England — ran to over 50 pages and studied how the divisor count $d(n)$ behaves. The first few highly composite numbers are $1, 2, 4, 6, 12, 24, 36, 48, 60, 120, \dots$ — notice how many of these are the "nice round numbers" used historically for counting (e.g. $60$ minutes, $12$ months, $360$ degrees).

Interactive — divisor count and highly composite check

Try it in GNU Octave

Octave
% highly_composite.m — find highly composite numbers up to N
function d = num_divisors(n)
  d = 0;
  for i = 1:floor(sqrt(n))
    if mod(n,i) == 0
      d += 2; if i*i == n, d -= 1; end
    end
  end
endfunction

N = 200; maxd = 0; hcn = [];
for n = 1:N
  d = num_divisors(n);
  if d > maxd
    maxd = d; hcn(end+1) = n;
  end
end
disp(hcn)
% >> 1  2  4  6  12  24  36  48  60  120  180
✦ ✦ ✦
Chapter III

Taxicab Numbers — the 1729 Story

Number TheoryHardy's Taxi, 1919

The most famous anecdote in Ramanujan's life: Hardy visited him in hospital and remarked that his taxi's number, 1729, seemed "rather a dull number." Ramanujan immediately replied that it was in fact very interesting — the smallest number expressible as a sum of two positive cubes in two different ways:

$$1729 = 1^3 + 12^3 = 9^3 + 10^3$$

Numbers with this property are now called taxicab numbers, denoted $\mathrm{Ta}(2)$ for the second one, and so on for higher counts of representations.

Interactive — find taxicab numbers up to a limit

Try it in GNU Octave

Octave
% taxicab.m — find numbers expressible as a^3+b^3 in >= 2 ways
limit = 5000;
sums = containers.Map('KeyType','double','ValueType','any');
for a = 1:round(limit^(1/3))
  for b = a:round(limit^(1/3))
    s = a^3 + b^3;
    if s <= limit
      if isKey(sums, s)
        sums(s) = [sums(s), {[a b]}];
      else
        sums(s) = {[a b]};
      end
    end
  end
end
ks = keys(sums);
for i = 1:numel(ks)
  reps = sums(ks{i});
  if numel(reps) >= 2
    printf("%d = ", ks{i});
    for r = 1:numel(reps)
      printf("%d^3+%d^3 ", reps{r}(1), reps{r}(2));
    end
    printf("\n");
  end
end
% >> 1729 = 1^3+12^3 9^3+10^3
✦ ✦ ✦
Chapter IV

Ramanujan's Series for 1/π

Analysis1914, "Modular Equations and Approximations to π"

In 1914 Ramanujan published a family of astonishingly fast-converging series for $1/\pi$, derived from his theory of modular equations — decades before anyone could rigorously prove why they worked. The most famous is:

$$\frac{1}{\pi} = \frac{2\sqrt{2}}{9801} \sum_{k=0}^{\infty} \frac{(4k)!\,(1103+26390k)}{(k!)^4 \, 396^{4k}}$$

Each additional term adds roughly 8 correct decimal digits of $\pi$ — a rate of convergence so extreme that it later became the basis for the Chudnovsky algorithm, used to compute pi to trillions of digits on modern computers.

Interactive — approximate π with Ramanujan's series

Try it in GNU Octave

Octave
% ramanujan_pi.m — approximate 1/pi using Ramanujan's 1914 series
terms = 3;
s = 0;
for k = 0:terms-1
  s += factorial(4*k)*(1103+26390*k) / (factorial(k)^4 * 396^(4*k));
end
inv_pi = (2*sqrt(2)/9801) * s;
approx_pi = 1/inv_pi;
printf("pi approx (%d terms) = %.15f\n", terms, approx_pi);
printf("true pi              = %.15f\n", pi);
% >> pi approx (3 terms) = 3.141592653589793
% >> true pi              = 3.141592653589793   (agrees to 15+ digits!)
✦ ✦ ✦
Chapter V

The Curious "Sum" 1 + 2 + 3 + ⋯ = −1/12

AnalysisLetter to Hardy, 1913

In his very first letter to Hardy, Ramanujan wrote down the equation

$$1 + 2 + 3 + 4 + \cdots = -\frac{1}{12}$$

This looks absurd for an ordinary sum, and it is — the series clearly diverges to infinity in the usual sense. Ramanujan was working with a different, regularized notion of summation (closely related to what we now recognize as the analytic continuation of the Riemann zeta function, $\zeta(-1) = -1/12$). The result later found genuine use in string theory and quantum field theory (the Casimir effect). The demo below shows both: the ordinary partial sums exploding, and the zeta-regularized value, side by side.

Interactive — partial sums vs. zeta-function regularization

Try it in GNU Octave

Octave
% zeta_reg.m — ordinary partial sum vs zeta(-1)
n = 10;
partial_sum = sum(1:n);
printf("Ordinary partial sum 1..%d = %d\n", n, partial_sum);

% Octave's symbolic package can evaluate zeta directly:
% pkg load symbolic
% z = zeta(sym(-1))     % returns -1/12 exactly
printf("Zeta-regularized value zeta(-1) = %.6f  (= -1/12)\n", -1/12);
% >> Ordinary partial sum 1..10 = 55
% >> Zeta-regularized value zeta(-1) = -0.083333  (= -1/12)
✦ ✦ ✦
Chapter VI

Ramanujan's Nested Radical

AlgebraJournal of the Indian Mathematical Society, 1911

At just 24, Ramanujan posed a problem so difficult that no one solved it for six months — until he supplied his own solution. It concerns an infinitely nested radical:

$$3 = \sqrt{1 + 2\sqrt{1 + 3\sqrt{1 + 4\sqrt{1 + \cdots}}}}$$

This follows from a general identity he found: $x+n+a = \sqrt{ax + (n+a)^2 + x\sqrt{a(x+n) + (n+a)^2 + (x+n)\sqrt{\cdots}}}$. Setting $x=2, n=1, a=0$ recovers the elegant special case above.

Interactive — evaluate the nested radical numerically

Try it in GNU Octave

Octave
% nested_radical.m — evaluate Ramanujan's nested radical from the inside out
depth = 15;
val = 0;
for k = depth+2:-1:2
  val = sqrt(1 + (k)*val);
end
printf("Nested radical (depth=%d) = %.10f\n", depth, val);
printf("Converges to             = 3.0000000000\n");
% >> Nested radical (depth=15) = 2.9999999997
% >> Converges to             = 3.0000000000
✦ ✦ ✦
Chapter VII

The Rogers–Ramanujan Continued Fraction

Analysis / Modular FormsNotebooks, rediscovered 1917

Ramanujan independently discovered (and vastly extended) an infinite continued fraction first found by L. J. Rogers:

$$R(q) = \cfrac{q^{1/5}}{1 + \cfrac{q}{1 + \cfrac{q^2}{1 + \cfrac{q^3}{1 + \cdots}}}}$$

Ramanujan found remarkable closed forms for special values, such as $R(e^{-2\pi}) = \sqrt{\frac{5+\sqrt5}{2}} - \frac{1+\sqrt5}{2}$ — connecting this continued fraction to the golden ratio $\varphi$ itself. When Hardy showed this result to fellow mathematicians, he said it "defeated me completely; I had never seen anything in the least like it before."

Interactive — evaluate R(q) for a given q and depth

Try it in GNU Octave

Octave
% rogers_ramanujan_cf.m — evaluate R(q) by backward recurrence
q = exp(-2*pi);   % classic special value q = e^{-2*pi}
depth = 25;
val = 0;
for k = depth:-1:1
  val = q^k / (1 + val);
end
R = q^(1/5) / (1 + val);
printf("R(e^-2pi) numeric   = %.10f\n", R);

phi = (1+sqrt(5))/2;
closed_form = sqrt((5+sqrt(5))/2) - phi;
printf("Ramanujan closed form = %.10f\n", closed_form);
% >> R(e^-2pi) numeric   = 0.7156645557
% >> Ramanujan closed form = 0.7156645557
✦ ✦ ✦
Chapter VIII

Mock Theta Functions

Modular FormsDeathbed letter, January 1920

Four months before his death, Ramanujan wrote to Hardy describing a new class of functions he called "mock theta functions" — power series that behave almost like classical modular theta functions near the unit circle, but crucially are not modular forms themselves. He gave examples such as the third-order mock theta function:

$$f(q) = \sum_{n=0}^{\infty} \frac{q^{n^2}}{(1+q)^2(1+q^2)^2 \cdots (1+q^n)^2}$$

It took until 2002 (Sander Zwegers' PhD thesis) for mathematicians to fully explain mock theta functions using the modern theory of harmonic Maass forms — 82 years after Ramanujan first wrote them down with no formal proof, purely from insight. They now appear in the study of black hole entropy in string theory.

Interactive — partial sums of f(q), the third-order mock theta function

Try it in GNU Octave

Octave
% mock_theta.m — partial sums of Ramanujan's third-order mock theta f(q)
q = 0.5; terms = 12;
total = 0;
for n = 0:terms
  denom = 1;
  for j = 1:n
    denom *= (1+q^j)^2;
  end
  total += q^(n^2) / denom;
end
printf("f(%.2f) approx (%d terms) = %.8f\n", q, terms, total);
% >> f(0.50) approx (12 terms) = 1.28243452
✦ ✦ ✦
Chapter IX

Ramanujan's Birthday Magic Square

Recreational MathematicsEncoding 22-12-1887

Ramanujan constructed a 4×4 magic square encoding his birth date, 22 December 1887, in the top row. Every row, column, and both diagonals sum to the same value, 139 — and remarkably so do the four corner cells, the four center cells, and several other sub-patterns.

Interactive — click a row, column, or diagonal label to verify its sum
Click any button above to highlight and sum that line.

Try it in GNU Octave

Octave
% magic_square.m — verify Ramanujan's birthday magic square
M = [22 12 18 87;
      88 17 9  25;
      10 24 89 16;
      19 86 23 11];

printf("Row sums:    "); disp(sum(M,2)');
printf("Column sums: "); disp(sum(M,1));
printf("Diagonal 1:  %d\n", sum(diag(M)));
printf("Diagonal 2:  %d\n", sum(diag(fliplr(M))));
printf("Corners:     %d\n", M(1,1)+M(1,4)+M(4,1)+M(4,4));
printf("Center 2x2:  %d\n", M(2,2)+M(2,3)+M(3,2)+M(3,3));
% >> every one of these equals 139
✦ ✦ ✦
Coda

Further Reading

Hardy's Ramanujan: Twelve Lectures on Subjects Suggested by His Life and Work (1940) remains the classic introduction. Robert Kanigel's The Man Who Knew Infinity (1991) is the definitive biography. Bruce Berndt's multi-volume Ramanujan's Notebooks annotates and proves thousands of the results Ramanujan left without proof — a project still not entirely finished more than a century later.