← Back to Blog

Taxicab Numbers, Sixty Years On

Adnan Mahmud

In 1963, Christopher Hooley proved that the number of positive integers up to x expressible as a sum of two positive cubes in more than one way grows like x2/3, up to logarithmic corrections. The proof is a delicate application of sieve methods that occupies eight pages of the Mathematische Zeitschrift. The theorem is a statement about how rare taxicab numbers become as one moves along the integers, and it is, in the way of good analytic number theory, both elementary in what it asserts and substantial in how it is established.

This blog is a working exercise in verifying that theorem empirically with a modern laptop. It takes roughly twenty seconds of single-machine compute to reproduce Hooley's asymptotic to visible accuracy across nine orders of magnitude. The exercise is not new mathematics; it is not even close to research. What it is, and what I think is worth writing down, is a small illustration of a shift that has happened quietly across computational number theory: for a class of classical questions, the balance between analytic difficulty and computational difficulty has inverted since the theorem was first proved. This blog walks through what that means concretely for the taxicab problem, produces the figures, and ends with a brief and honest account of where the exercise stops paying off and what would be required to push past that boundary.

1. Ramanujan's cab and the theorem it hides

The number 1729 is famous for a specific reason. G. H. Hardy visited Srinivasa Ramanujan in hospital and, casting around for conversation, mentioned that the number of his taxi was 1729, which struck him as a rather dull number. Ramanujan replied that it was not dull at all; it was the smallest number expressible as the sum of two positive cubes in two different ways. The story appears in Hardy's obituary of Ramanujan [1] and has been retold enough times that 1729 is now called the Hardy–Ramanujan number, and the general phenomenon it exemplifies has borrowed the taxi.

The two decompositions in question are 1729 = 1³ + 12³ = 9³ + 10³. What makes this remarkable is that it happens at all. Most integers cannot be written as a sum of two positive cubes even once; most of those that can, can be written that way in only one way; and the integers for which two distinct such decompositions exist are, empirically, sparse. Silverman's expository article [2] is the standard entry point into the modern view of this phenomenon.

The geometry is worth pausing on because it reframes the question. The equation x³ + y³ = N defines a smooth curve in the plane. In the first quadrant, that curve is a compact arc running from (0, N1/3) to (N1/3, 0), and it is symmetric across the line y = x. Asking whether N has any representation as a sum of two positive cubes is the same as asking whether this arc passes through any point of the integer lattice above the diagonal. Asking whether N has two representations is asking whether the arc passes through two such points. Ramanujan's answer to Hardy is thus a geometric coincidence about the curve x³ + y³ = 1729: it happens to catch two lattice points in its first-quadrant arc rather than one.

Side-by-side comparison of a typical single-representation cubic curve and the 1729 curve.

Figure 1: Two cubic curves of similar size. On the left, x³ + y³ = 1027 catches a single lattice point above the diagonal (its mirror is shown for symmetry). On the right, x³ + y³ = 1729 catches two. Nothing in the shape of the curve distinguishes them; the difference is a lattice-counting accident.

Once the phenomenon is put this way, the natural question becomes quantitative. If catching two lattice points is a coincidence, how often does it occur? Hooley answered this in 1963.

2. What Hooley proved

Let ν(x) denote the number of positive integers nx such that n is expressible as a sum of two positive integer cubes in at least two essentially distinct ways, where two decompositions n = a³ + b³ = c³ + d³ are essentially distinct if the unordered pairs {a, b} and {c, d} are different. Hooley [3] proved

ν(x) = O(x2/3 log log x / (log x)1/2)

as x → ∞. The leading behaviour is x2/3, tempered by a slowly-varying logarithmic factor. The theorem thus makes the sparsity of taxicab numbers precise: they are almost non-existent in the sense that they occupy a set of density zero, but they occupy that density in a controlled way. Since the count of all integers up to x that can be written as a sum of two positive cubes even once is itself of order x2/3, Hooley's estimate has the immediate corollary that representation as a sum of two positive cubes is "almost always essentially unique" [3, 4], in the sense that the density of those that admit more than one representation, relative to those that admit any representation, vanishes.

The proof is a sieve argument. It goes through the correspondence between representations of n as a sum of two cubes and integer points on the associated cubic curve, works with the arithmetic of the ring ℤ[ω] where ω is a primitive cube root of unity, and bounds the number of lattice points on a family of algebraic curves using techniques descended from the analytic number theory of the 1950s and 1960s. In 1980, Hooley [5] improved the exponent from 2/3 to 5/9 + ε using Deligne's resolution of the Riemann hypothesis for varieties over finite fields inside the large sieve; that improvement is a genuine tour de force and is not what this blog is concerned with. What matters here is the original 1963 bound, because that is what the empirical data will make visible.

3. Reproducing the picture in twenty seconds

To see Hooley's theorem in a plot, one needs to enumerate every representation of every nNmax as a sum of two positive cubes, group these representations by n, count how many n receive at least two, and plot the cumulative count as a function of x. The enumeration is straightforward. Iterate over a from 1 to the largest integer with 2a³ ≤ Nmax, and for each a, iterate over b from a to the largest integer with a³ + b³ ≤ Nmax; each such pair contributes one row (N = a³ + b³, a, b) to a table. The requirement ab handles the fact that (a, b) and (b, a) represent the same decomposition. Once the table is built, a group-by on N immediately produces the count of representations per n.

The total work is O(Nmax2/3) because the double loop runs over precisely the lattice points in a region of that size. On my machine, at Nmax = 10⁹, the enumeration produces 441,521 representations in roughly 1.6 seconds across four processes, and the subsequent group-by and summary take under a second. Distributing to more cores would trim this further; the bottleneck at this scale is process spawn overhead rather than computation. Extending to Nmax = 10¹⁰ or 10¹¹ is a matter of patience rather than algorithmic difficulty. All code and artefacts are in the repository accompanying this blog [6].

The distribution of representation counts at Nmax = 10⁹ tells a stark story. Of the 438,413 integers below 10⁹ with any representation as a sum of two positive cubes, 438,405 have exactly one; 1,546 have exactly two; and eight have exactly three. Each step up the ladder costs roughly two orders of magnitude in count. Ta(3) = 87,539,319 is the smallest with three representations; Ta(4) is 6,963,472,309,248 [7], so no integers with four representations appear below 10⁹.

Left: bar chart of counts of integers with k representations for k=1,2,3. Right: cumulative growth on log-log axes with x^(2/3) reference.

Figure 2: Left panel: distribution of representation counts for integers below 10⁹, on a log y-axis. Right panel: cumulative counts on log-log axes, with a straight-line reference of slope 2/3 (dashed). The upper line counts integers nx with at least one representation as a sum of two positive cubes; the lower line counts those with at least two. Both lines run parallel to the reference slope, confirming Hooley's theorem visually across roughly nine orders of magnitude in x. The finite curvature above the reference at large x is the log log x / (log x)1/2 correction from the theorem, still visible at this scale.

The right panel is the substantive one. Both cumulative-count lines are, to eye, straight over most of the plot with slope 2/3, which is exactly Hooley's prediction. The line for at-least-one-representation is displaced upward from the line for at-least-two-representations by roughly two and a half log units, reflecting the fact that the two counts have the same leading exponent but different constants of proportionality. The straight-line fit is not perfect; both lines curve gently above the reference at large x. This is not a failure of the theorem but the visible signature of the (log log x) / (log x)1/2 factor that Hooley's estimate keeps around; that factor grows very slowly with x but grows nonetheless, and at x = 10⁹ it is still noticeable. Were we able to push the sweep further, the curvature would persist rather than close, in agreement with the theorem.

What this constitutes, in the sense one has to be careful about, is not proof of anything. Hooley proved a theorem; the plot only shows that on the range where I can compute, the data does not disagree with what the theorem predicts. But the alignment is precise enough that it does something a good picture is supposed to do: it makes the theorem visible.

4. Where the obstructions come from

A second phenomenon that is worth putting into a figure concerns not how rare taxicab numbers are but why certain integers cannot be sums of two cubes at all. This is a modular constraint and it is a good deal older than Hooley's theorem, but it is of the same flavour: an analytic fact about the integers whose empirical shape is best appreciated visually.

Consider the cubes mod 9. Any integer a is congruent to one of 0, 1, 2, ..., 8 mod 9, and cubing these gives 0, 1, 8, 0, 1, 8, 0, 1, 8. So a³ mod 9 is always in {0, 1, 8}, regardless of a. The sum of two such residues, mod 9, is therefore in the set

{0+0, 0+1, 0+8, 1+1, 1+8, 8+8} mod 9 = {0, 1, 8, 2, 0, 7} = {0, 1, 2, 7, 8}.

The residues 3, 4, 5, and 6 mod 9 are unachievable. Any integer congruent to one of these mod 9 is not expressible as a sum of two integer cubes even once, let alone in multiple ways. This is a hard obstruction, not a statistical one: it rules out four ninths of the integers, roughly 44%, before any question of density or distribution enters. The analogous analysis mod 7 gives cubes in {0, 1, 6}, sums in {0, 1, 2, 5, 6}, and unachievable residues {3, 4}, ruling out a further 2/7 of the integers not already ruled out mod 9.

Bar charts showing how many (i,j) pairs produce each residue mod 7 (left) and mod 9 (right); forbidden residues marked with a red cross.

Figure 3: Frequencies of residues arising as i³ + j³ mod m, for m = 7 (left) and m = 9 (right). The bar height at residue r is the number of pairs (i, j) with 0 ≤ i, j < m such that i³ + j³ ≡ r mod m. Residues that no pair produces are marked with a red cross below the axis: {3, 4} mod 7 and {3, 4, 5, 6} mod 9. These integers are excluded a priori from being sums of two cubes.

The reason to draw the figure at all is that the phenomenon is easier to appreciate as a picture than as a paragraph of arithmetic. The mod-9 panel especially, with its four missing bars, communicates the strength of the constraint immediately. The same modular obstruction reappears throughout related problems; for the sums-of-three-cubes question, for instance, the fact that a cube is at most one away from a multiple of nine implies that sums of three cubes must be within three of a multiple of nine, so integers congruent to 4 or 5 mod 9 cannot be sums of three cubes at all [8]. This is the reason that the 42 problem — the last integer below 100 for which a sums-of-three-cubes representation was unknown — did not involve 4 or 5 mod 9 numbers, and it is the reason Booker and Sutherland's celebrated 2019 computation targeted 42 and 33 specifically [9]. The modular structure sets what is even possible; the analytic and computational work happens within it.

5. What computation can and cannot do here

The exercise this blog describes is not novel mathematics. Hooley's theorem is sixty years old; the modular obstructions are older still; the taxicab numbers are catalogued in the OEIS [7] and their computation is a standard undergraduate programming exercise. What the exercise does show, and what I think is genuinely worth noting, is that a specific ratio has flipped since Hooley wrote his paper. In 1963, the analytic argument was demanding and the empirical verification impossible; today, the argument is unchanged and the empirical verification is a lunchtime project.

It would be easy to overstate what this means. It does not mean that theory has been made redundant by computation. The plot in Figure 2 is legible only because Hooley's theorem tells one what to look for; a straight line on log-log axes with slope 2/3 is unremarkable in isolation. It also does not mean that everything worth knowing about taxicab numbers has been settled. Ta(6) is currently only conjectured, not proven, to be 24,153,319,581,254,312,065,344 [7]; the seventh Ta(k) is not known even conjecturally with certainty; and the deeper structural questions about how representation counts distribute over integers, and how they connect to the arithmetic of the associated elliptic curves, remain active research territory. Whenever cubes appear one has an elliptic curve nearby, and every equation x³ + y³ = N defines (up to birational equivalence) an elliptic curve whose Mordell–Weil rank governs how many representations N can have as a sum of two rational cubes. That connection is where the taxicab story stops being a lattice-point counting exercise and starts being a serious problem in arithmetic geometry. It is also where the computation stops being twenty seconds on a laptop.

For the classical range of N we can enumerate directly, verification is essentially free. For the elliptic-curve rank of x³ + y³ = N at a specific N, one still needs a two-descent implementation, which in practice means SageMath, PARI/GP, or Magma. The interesting research questions live on that side of the boundary. A reasonable amount of computational infrastructure separates one side from the other, which is the small piece of context that motivates the coda.

6. Code and data

All computations, figures, and intermediate data artefacts described in this blog are in a public repository [6]. The repository is structured as a small Python package (src/taxicab/) with a clean separation between the enumeration and search logic, the sign-regime and family classification, and the visualisation modules; a set of thin scripts (scripts/) that produce the specific artefacts shown here; a tested code base (tests/) with pytest, ruff, and mypy configured; and a set of intermediate parquet files (data/processed/) capturing the enumeration output at Nmax = 10⁹, small enough to redistribute without pain.

Reproducing Figures 1 through 3 from a fresh clone requires a conda environment (environment.yml is provided), running the sweep script once (scripts/compute_taxicab.py --regime positive --n-max 1000000000), and then invoking the three render scripts (render_generic_vs_taxicab.py, render_distribution.py, render_residues.py). Total wall time on a modern laptop is under a minute, dominated by figure rendering rather than the numerical sweep. The environment file uses conda-forge exclusively rather than mixing channels; nothing in the pipeline requires administrator rights.

A brief note on style. The figures in this post are rendered in a dark-mode variant of the project's publication style; a light-mode variant is also provided in the repository (use_publication_style vs use_dark_publication_style in viz/style.py) for anyone wanting to reuse the figures in a document with a white background.

7. What happened when I tried to go further

The natural next step in this exercise would have been to compute the Mordell–Weil rank of the elliptic curve associated to each multi-representation N in the sweep, and to look for correlations between representation count and rank. This is a genuinely interesting question. Curves with more integer points tend, empirically, to have higher rank; taxicab numbers are precisely the N whose associated curves have more integer points; whether the rank distribution of these curves differs from that of a random N-family in any structured way is the sort of question that could be worked out at small scale and is not entirely settled at any scale.

I did not get past setup. The rank of an elliptic curve is computed in modern practice by SageMath, which is available on Linux and macOS through several package managers but which does not have a working native Windows installation. The conda-forge sage package on Windows is missing its C-library dependencies (cddlib, cypari2), and the pip-installable Python bindings to PARI/GP need PARI itself as a system library, which is also not straightforwardly available on Windows without administrator rights. The three usable routes are Windows Subsystem for Linux (requires administrator rights to enable), a virtual machine (same), or running the computations on a remote Linux server. On the university-issued laptop this project was carried out on, none of these was available.

It is possible to invoke PARI/GP as a subprocess through its Windows binary distribution, which does install without administrator rights, and to compute ranks that way. This is what I would do if I were to continue. It is more friction than import sage, and the interface layer is not free, but it is not unreasonable. I stopped short of setting this up because at that point the exercise had ceased to be about taxicab numbers and had become about the accessibility of scientific software on locked-down systems, and while that is a real question, it is not the question this blog set out to answer.

The observation is a small one and perhaps not surprising. Modern computational mathematics increasingly assumes Linux, or at least a system on which arbitrary compilation is possible. For a serious user this is not a hard constraint; for anyone using a machine they do not fully own — which is a large fraction of students and a nontrivial fraction of researchers — the boundary between the classical range where enumeration is trivial and the modern range where structural computation begins can be surprisingly hard to cross. This does not diminish what the classical range has to teach. It does mean that the twenty-second verification described here is, for that user, likely to be near the practical edge of what can be done without external infrastructure.

8. Coda

The taxicab problem sits in a fortunate spot: a question elementary enough to state in one sentence, deep enough that a serious theorem is required to answer even the sparsity question, and accessible enough that the theorem can now be seen. Hooley's argument in 1963 could not have been checked with the technology of 1963; it did not have to be, because the argument was correct. But there is something satisfying about producing a picture that would have taken decades of hand computation to draw sixty years ago, and using it to appreciate an argument that was carried through by other means. This is not a demonstration of the power of modern computation, exactly, and it is not a demonstration of the redundancy of anything. It is just a small illustration of what these tools now allow one to see, in a corner of number theory where the seeing is particularly clear.

References

[1] G. H. Hardy, "Obituary notice: S. Ramanujan," Proc. London Math. Soc., s2-19, 1921, doi: 10.1112/plms/s2-19.1.1-s.

[2] J. H. Silverman, "Taxicabs and sums of two cubes," Amer. Math. Monthly, vol. 100, no. 4, pp. 331–340, Apr. 1993, doi: 10.2307/2324954.

[3] C. Hooley, "On the representations of a number as the sum of two cubes," Math. Z., vol. 82, pp. 259–266, 1963, doi: 10.1007/BF01111426.

[4] J. Brüdern and R. C. Vaughan, "A Montgomery–Hooley theorem for sums of two cubes," European J. Math., 2021, doi: 10.1007/s40879-021-00495-4.

[5] C. Hooley, "On the numbers that are representable as the sum of two cubes," J. Reine Angew. Math., vol. 314, pp. 146–173, 1980, doi: 10.1515/crll.1980.314.146.

[6] A. Mahmud, "taxicab-viz," GitHub repository, 2026. [Online]. Available: https://github.com/Adnan1729/taxicab-viz

[7] N. J. A. Sloane and OEIS Foundation, "A011541: Taxicab numbers," The On-Line Encyclopedia of Integer Sequences. [Online]. Available: https://oeis.org/A011541

[8] R. K. Guy, Unsolved Problems in Number Theory, 3rd ed. New York, NY: Springer-Verlag, 2004, section D5.

[9] A. R. Booker and A. V. Sutherland, "On a question of Mordell," Proc. Nat. Acad. Sci., vol. 118, no. 11, e2022377118, Mar. 2021, doi: 10.1073/pnas.2022377118.