Taxicab Numbers

I got a little distracted halfway through my number theory homework so I decided to write a post. At least the topic is pertinent to number theory, right?

I first came across taxicab numbers a few years ago while jumping between Wikipedia math articles. Last summer, I was watching the play “Proof” (which was amazing by the way, if you’re ever in New York while its playing then I recommend you watch it) with a friend of mine and the main character mentioned that “1729” is a special number. As soon as I heard that, I felt a memory trying to make its way out from the back of my brain. After a few seconds I finally remembered where I’d seen it and I started excitedly whispering to my friend, frantically trying to explain why the number was special (she still makes fun of how worked-up I got).

For those that are unfamiliar, 1729 is known as the Hardy-Ramanujan number after this anecdote:

“I remember once going to see him when he was ill at Putney. I had ridden in taxi cab number 1729 and remarked that the number seemed to me rather a dull one, and that I hoped it was not an unfavorable omen. “No,” he replied, “it is a very interesting number; it is the smallest number expressible as the sum of two cubes in two different ways.” - G.H. Hardy Source

How does this related to taxicab numbers? In mathematics, the nth taxicab number is the smallest number that can be written as the sum of two positive cube numbers in “n” unique ways.

Unfortunately I must get back to this problem set, so I just quickly threw together a program in R to test whether a number can be expressed as the sum of two positive cube numbers in 2 different ways. The script doesn’t test whether such a number is the smallest so it is not a true taxicab check in that regard. Perhaps I’ll update this later to be a true taxicab check or even write a program to generate taxicab numbers (this seems like a difficult and fun problem).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
is.taxi2 <- function(x) {
 ans <- numeric()
  for (i in 1:ceiling(x^(1/3))) {
   for (j in 1:ceiling(x^(1/3))) {
     if (i^3 + j^3 == x) {
     ans[i] <- i
     ans[j] <- j
     }
   }
 }
 ans <- na.omit(ans)
 ans <- as.numeric(ans)
 if (length(ans) == 4) {
   print("Yes")
 }
 else {
     print("No")
   }
 }

Some examples (the function runs very fast):

1
2
3
4
5
6
7
8
> is.taxi2(708)
[1] "No"
> is.taxi2(58)
[1] "No"
> is.taxi2(1456)
[1] "No"
> is.taxi2(1729)
[1] "Yes"