# Ramanujan's cubes

Share on:

This post illustrates the working of Ramanujan's generating functions for solving Euler's diophantine equation $$a^3+b^3=c^3+d^3$$ as described by Andrews and Berndt in "Ramanujan's Lost Notebook, Part IV", pp 199 - 205 (Section 8.5). The text is available from Springer.

Ramanujan's result is that if

$f_1(x) = \frac{1+53x+9x^2}{1-82x-82x^2+x^3} = a_0+a_1x+a_2x^2+a_3x^3+\cdots = \alpha_0+\frac{\alpha_1}{x}+\frac{\alpha_2}{x^2}+\frac{\alpha_3}{x^3}+\cdots$

$f_2(x) = \frac{2-26x-12x^2}{1-82x-82x^2+x^3} = b_0+b_1x+b_2x^2+b_3x^3+\cdots = \beta_0+\frac{\beta_1}{x}+\frac{\beta_2}{x^2}+\frac{\beta_3}{x^3}+\cdots$

$f_3(x) = \frac{2+8x-10x^2}{1-82x-82x^2+x^3} = c_0+c_1x+c_2x^2+c_3x^3+\cdots = \gamma_0+\frac{\gamma_1}{x}+\frac{\gamma_2}{x^2}+\frac{\gamma_3}{x^3}+\cdots$

then for every value of $$n$$ we have:

$$a_n^3+b_n^3=c_n^3+(-1)^3$$

and

$$\alpha_n^3+\beta_n^3=\gamma_n^3-(-1)^3$$

thus providing infinite sequences of solutions to Euler's equations. The values $$\alpha_1,\beta_1,\gamma_1$$ are $$9, -12, -10$$ giving rise to

$$(9)^3+(-12)^3=(-10)^3-(-1)^3$$

which can be rewritten as

$$9^3+10^3=12^2+1^3$$.

Andrews and Berndt comment that:

This is another of those many results of Ramanujan for which one wonders, “How did he ever think of this?”

And we all know the story from Hardy about Ramanujan's comment about the number 1729.

1import sympy as sy
2sy.init_printing(num_columns=120)
3
4x,a,b,c = sy.var('x,a,b,c')
5n = sy.Symbol('n', positive=True, integer=True)


Start by entering the three rational functions.

1g = 1-82*x-82*x**2+x**3
2f1 = (1+53*x+9*x**2)/g
3f2 = (2-26*x-12*x**2)/g
4f3 = (2+8*x-10*x**2)/g
5
6display(f1)
7display(f2)
8display(f3)


$\frac{9x^2+53x+1}{x^3-82x^2-82x+1}$

$\frac{-12x^2-26x+2}{x^3-82x^2-82x+1}$

$\frac{-10x^2+8x+2}{x^3-82x^2-82x+1}$

 1fp1 = f1.apart(x,full=True).doit()
2fp2 = f2.apart(x,full=True).doit()
3fp3 = f3.apart(x,full=True).doit()
4fs1 = [z.simplify() for z in fp1.args]
5fs2 = [z.simplify() for z in fp2.args]
6fs3 = [z.simplify() for z in fp3.args]
7
8display(fs1)
9display(fs2)
10display(fs3)


$\left[ -\frac{43}{85x+85}, \frac{8(101+11\sqrt{85})}{85(2x-83-9\sqrt{85})}, \frac{8(101-11\sqrt{85})}{85(2x-83+9\sqrt{85})}\right]$

$\left[ -\frac{16}{85x+85}, \frac{28(-37-4\sqrt{85})}{85(2x-83-9\sqrt{85})}, \frac{28(-37+4\sqrt{85})}{85(2x-83+9\sqrt{85})}\right]$

$\left[ -\frac{16}{85x+85}, \frac{6(-139-15\sqrt{85})}{85(2x-83-9\sqrt{85})}, \frac{6(-139+15\sqrt{85})}{85(2x-83+9\sqrt{85})}\right]$

Note that the denominators of each fraction is the same (as we'd expect).

Now we use the fact that

$\frac{a}{bx+c}$

has the infinite series expansion

$\frac{a}{c}\left(1- \frac{b}{c}x+\left(\frac{b}{c}\right)^2x^2-\left(\frac{b}{c}\right)^3x^3+\cdots\right)$

This means that the coefficient of $$x^n$$ is

$\frac{a}{c}\left(-\frac{b}{c}\right)^n$

Beacuse of the denominators, the values of $$b$$ and $$c$$ are always the same. We start by considering fs1, which consists of the partial fraction sums of f1.

1a1_s = [sy.numer(z) for z in fs1]
2b1_s = [sy.denom(z).coeff(x) for z in fs1]
3c1_s = [sy.denom(z).coeff(x,0) for z in fs1]
4
5ac1_s = [sy.simplify(s/t) for s,t in zip(a1_s,c1_s)]
6bc1_s = [sy.simplify(s/t) for s,t in zip(b1_s,c1_s)]
7
8display(ac1_s)
9display(bc1_s)


$\left[-\frac{43}{85},\frac{64}{85}-\frac{8\sqrt{85}}{85}, \frac{64}{85}+\frac{8\sqrt{85}}{85}\right]$

$\left[1, -\frac{83}{2}+\frac{9\sqrt{85}}{2}, -\frac{83}{2}-\frac{9\sqrt{85}}{2}\right]$

Now we can determine the coefficient of $$x^n$$ in the power series expansion of $$f_1(x)$$:

1a_n = sum(s*(-t)**n for s,t in zip(ac1_s,bc1_s))
2display(a_n)


$-\frac{43(-1)^n}{85} + \left(\frac{64}{85}-\frac{8\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(\frac{64}{85}+\frac{8\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

And repeat all of the above for $$f_2(x)$$ and its partial fractions fs2.

1a2_s = [sy.numer(z) for z in fs2]
2b2_s = [sy.denom(z).coeff(x) for z in fs2]
3c2_s = [sy.denom(z).coeff(x,0) for z in fs2]
4
5ac2_s = [sy.simplify(s/t) for s,t in zip(a2_s,c2_s)]
6bc2_s = [sy.simplify(s/t) for s,t in zip(b2_s,c2_s)]
7
8b_n = sum(s*(-t)**n for s,t in zip(ac2_s,bc2_s))
9display(b_n)


$-\frac{16(-1)^n}{85} + \left(\frac{77}{85}-\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(\frac{77}{85}+\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

Continuing for $$f_3(x)$$:

1a3_s = [sy.numer(z) for z in fs3]
2b3_s = [sy.denom(z).coeff(x) for z in fs3]
3c3_s = [sy.denom(z).coeff(x,0) for z in fs3]
4
5ac3_s = [sy.simplify(s/t) for s,t in zip(a3_s,c3_s)]
6bc3_s = [sy.simplify(s/t) for s,t in zip(b3_s,c3_s)]
7
8c_n = sum(s*(-t)**n for s,t in zip(ac3_s,bc3_s))
9display(c_n)


$-\frac{16(-1)^n}{85} + \left(\frac{93}{85}-\frac{9\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(\frac{93}{85}+\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

In order to see their similarities and differences, we now show them together:

1display(a_n)
2display(b_n)
3display(c_n)


$-\frac{43(-1)^n}{85} + \left(\frac{64}{85}-\frac{8\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(\frac{64}{85}+\frac{8\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

$-\frac{16(-1)^n}{85} + \left(\frac{77}{85}-\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(\frac{77}{85}+\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

$-\frac{16(-1)^n}{85} + \left(\frac{93}{85}-\frac{9\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(\frac{93}{85}+\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

The first few coefficients can be checked against a Taylor series expansion:

1s1 = f1.series(n=6)
2display([s1.coeff(x,k) for k in range(6)])
3a_s = [a_n.subs(n,k).simplify() for k in range(6)]
4display(a_s)


1s2 = f2.series(n=6)
2display([s2.coeff(x,k) for k in range(6)])
3b_s = [b_n.subs(n,k).simplify() for k in range(6)]
4display(b_s)


1s3 = f3.series(n=6)
2display([s3.coeff(x,k) for k in range(6)])
3c_s = [c_n.subs(n,k).simplify() for k in range(6)]
4display(c_s)


Now, if everything has behaved properly, we should now have

$a^3 + b^3 = c^3 + (-1)^3$

and we can check the first few values:

1[s**3+t**3-u**3 for s,t,u in zip(a_s,b_s,c_s)]


$[1,\quad -1,\quad 1,\quad -1,\quad 1,\quad -1]$

And now for the general result:

1sy.powsimp(sy.expand(a_n**3 + b_n**3 - c_n**3),combine='all',force=True).factor()


$(-1)^n$

Woo hoo!

Now for the other expansions, in negative powers of $$x$$; in other words based on the the functions $$f_k(1/x)$$. We'll rename these functions: $$g_k(x) = f_k(1/x)$$. After that it's pretty much a carbon copy of the preceding computations.

1g1 = f1.subs(x,1/x).simplify()
2g2 = f2.subs(x,1/x).simplify()
3g3 = f3.subs(x,1/x).simplify()
4
5display(g1)
6display(g2)
7display(g3)


$\frac{x(x^2+53x+9)}{x^3-82x^2-82x+1}$

$\frac{2x(x^2 - 13x - 6)}{x^3 - 82x^2 - 82x + 1}$

$\frac{2x(x^2 + 4x - 5)}{x^3 - 82x^2 - 82x + 1}$

 1gp1 = g1.apart(x,full=True).doit()
2gp2 = g2.apart(x,full=True).doit()
3gp3 = g3.apart(x,full=True).doit()
4gs1 = [z.simplify() for z in gp1.args]
5gs2 = [z.simplify() for z in gp2.args]
6gs3 = [z.simplify() for z in gp3.args]
7
8display(gs1)
9display(gs2)
10display(gs3)


$\left[1, \frac{43}{85x+85}, \frac{8(1429+155\sqrt{85})}{85(2x-83-9\sqrt{85})}, \frac{8(1429-155\sqrt{85})}{85(2x-83+9\sqrt{85})}\right]$

$\left[2, -\frac{16}{85x+85}, \frac{14(839+91\sqrt{85})}{85(2x-83-9\sqrt{85})}, \frac{14(8397-91\sqrt{85})}{85(2x-83+9\sqrt{85})}\right]$

$\left[2, \frac{16}{85x+85}, \frac{12(1217+132\sqrt{85})}{85(2x-83-9\sqrt{85})}, \frac{12(1217-132\sqrt{85})}{85(2x-83+9\sqrt{85})}\right]$

For ease of writing in Python, we'll use d, e and f instead of $$\alpha$$, $$\beta$$ and $$\gamma$$.

1d1_s = [sy.numer(z) for z in gs1]
2e1_s = [sy.denom(z).coeff(x) for z in gs1]
3f1_s = [sy.denom(z).coeff(x,0) for z in gs1]
4
5df1_s = [sy.simplify(s/t) for s,t in zip(d1_s,f1_s)]
6ef1_s = [sy.simplify(s/t) for s,t in zip(e1_s,f1_s)]
7
8d_n = sum(s*(-t)**n for s,t in zip(df1_s,ef1_s))

1d2_s = [sy.numer(z) for z in gs2]
2e2_s = [sy.denom(z).coeff(x) for z in gs2]
3f2_s = [sy.denom(z).coeff(x,0) for z in gs2]
4
5df2_s = [sy.simplify(s/t) for s,t in zip(d2_s,f2_s)]
6ef2_s = [sy.simplify(s/t) for s,t in zip(e2_s,f2_s)]
7
8e_n = sum(s*(-t)**n for s,t in zip(df2_s,ef2_s))

1d3_s = [sy.numer(z) for z in gs3]
2e3_s = [sy.denom(z).coeff(x) for z in gs3]
3f3_s = [sy.denom(z).coeff(x,0) for z in gs3]
4
5df3_s = [sy.simplify(s/t) for s,t in zip(d3_s,f3_s)]
6ef3_s = [sy.simplify(s/t) for s,t in zip(e3_s,f3_s)]
7
8f_n = sum(s*(-t)**n for s,t in zip(df3_s,ef3_s))

1display(d_n)
2display(e_n)
3display(f_n)


$-\frac{43(-1)^n}{85} + \left(-\frac{64}{85}-\frac{8\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(-\frac{64}{85}+\frac{8\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

$-\frac{16(-1)^n}{85} + \left(-\frac{77}{85}-\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(-\frac{77}{85}+\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

$-\frac{16(-1)^n}{85} + \left(-\frac{93}{85}-\frac{9\sqrt{85}}{85}\right) \left(\frac{83}{2}-\frac{9\sqrt{85}}{2}\right)^n + \left(-\frac{93}{85}+\frac{7\sqrt{85}}{85}\right) \left(\frac{83}{2}+\frac{9\sqrt{85}}{2}\right)^n$

As before, a quick check:

1ds = [d_n.subs(n,k).simplify() for k in range(6)]
2es = [e_n.subs(n,k).simplify() for k in range(6)]
3fs = [f_n.subs(n,k).simplify() for k in range(6)]
4display(ds)
5display(es)
6display(fs)


\begin{align*} &[-1, 9, 791, 65601, 5444135, 451797561]\\\ &\\\ &[-2, -12, -1010, -83802, -6954572, -577145658]\\\ &\\\ &[-2, -10, -812, -67402, -5593538, -464196268] \end{align*}

1[s**3+t**3-v**3 for s,t,v in zip(ds,es,fs)]


$[-1,\quad 1,\quad -1,\quad 1,\quad -1,\quad 1]$

And finally, confirming the general result:

1sy.powsimp(sy.expand(d_n**3 + e_n**3 - f_n**3),combine='all',force=True).factor()


$-(-1)^n$

Again, woo hoo!