Ramanujan & Python

B

barnesc

A bit of fun:

Ramanujan, an Indian mathematician, was once visited in the hospital
by G. H. Hardy, a prominant English mathematician. Hardy remarked
that he had taken taxi number 1729, and Ramanujan quickly replied
that 1729 is remarkable, as it is the smallest integer that can be
represented in two ways by the sum of two cubes: 1729 = 1**3 + 12**3
= 9**3 + 10**3 [1].

Spectacular, no?

The inspired reader checks this with a quick Python program:
L = range(1,21)
sums = [x**3+y**3 for x in L for y in L]
histo = [sums.count(i) for i in range(max(sums)+1)]
histo.index(4)
1729

Explanation:
20**3 is 8000, so our search extends only up to 8000.
sums contains x**3+y**3 values for each x in L for each y in L.
(note that 1**3 + 12**3 and 12**3 and 1**3 are counted twice in sums).
histo counts how many times each value appears in sums.

The point is that Python is great for mathematical experiments.

This particular program is inefficient on the histo= line, so if you
want to try other cases (such as smallest integer that can be
represented in two ways by the sum of two fourths), you'll need to
optimize.

[1]. http://scienceworld.wolfram.com/biography/Ramanujan.html

This document is in the public domain.

- Connelly
 
I

Istvan Albert

Spectacular, no?

Not really.

I'm might sound a bit of off topic here I but I consider both of
these as 'cheapo' tricks that only sound good on paper (and to
reporters): 'Look Ma the man can compute the sum of two cubes
in a flash'

1**3 is 1, all he needed to know is that 12**3 is 1728
Similarly knowing that 10**3 is 1000 is trivial, all he
needed to know is that 9**3 is 729.

Just as with squared values whenever one works with cubes
they will tune very quickly in and start recognize the first
20 or so by heart in a matter of minutes...

Istvan.
 
P

Paul Rubin

Istvan Albert said:
1**3 is 1, all he needed to know is that 12**3 is 1728
Similarly knowing that 10**3 is 1000 is trivial, all he
needed to know is that 9**3 is 729.

Just as with squared values whenever one works with cubes
they will tune very quickly in and start recognize the first
20 or so by heart in a matter of minutes...

There's another part to the question. Is there a smaller number than
1729, that's also the sum of two cubes in two distinct ways? Ramanujan
could answer that second question immediately. Can you?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top