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.
Partitions of Integers
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:
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$.
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
Highly Composite Numbers
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).
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
Taxicab Numbers — the 1729 Story
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:
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.
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
Ramanujan's Series for 1/π
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:
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.
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!)
The Curious "Sum" 1 + 2 + 3 + ⋯ = −1/12
In his very first letter to Hardy, Ramanujan wrote down the equation
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.
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)
Ramanujan's Nested Radical
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:
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.
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
The Rogers–Ramanujan Continued Fraction
Ramanujan independently discovered (and vastly extended) an infinite continued fraction first found by L. J. Rogers:
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."
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
Mock Theta Functions
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:
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.
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
Ramanujan's Birthday Magic Square
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.
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
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.