New Video: The Recamán Sequence

The Recamán sequence, or more properly Recamán’s sequence, is one of the more unusual sequences to make the rounds in the internet math community. The way it works is that the first term in the sequence is 1. Then, for each term, you either add or subtract the number of that term from the previous one. There are two rules to this.

First, the numbers have be greater than 0. So for the 2nd term is 1+2=3. The 3rd term is 3+3=6. But the 4th term is 6-4=2. Second, if you subtract, the resulting number may not have appeared in the sequence before. You can include repeats when you add (otherwise, you’d get stuck), but not when you subtract. So the next term is 2+5=7. But then, you can’t subtract 7-6=1 because that there’s already a 1 in the sequence. Instead, you have to add 7+6=13.

This sequence was featured in a video by the YouTube channel Numberphile in 2018, which gave an interesting visualization of the sequence by connecting each term to the next one on the number line with a semicircle, which gave an interesting swirly pattern like the one below:

https://upload.wikimedia.org/wikipedia/en/d/da/Reacam%C3%A1nSequenceDrawing.png
Credit: (CC) by Lugalde (Wikipedia)

Every time the circles cross the mid-line, where the number line would be, is the next term in the sequence: 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43… Notice that the numbers often bounce back and forth, the circles expanding by one unit with each revolution as long as they have room.

But I was unsatisfied with the animations they showed in the video. I wanted to see what Recamán’s sequence looks like on larger scales, so I wrote a Python code to draw it. When I did, I saw something interesting. It’s not obvious looking at it on small scales (in fact, it took me a while to figure it out even on large scales), but when you go to thousands of terms in the sequence, a fractal structure starts to form, with a sort of teardrop-shape that repeats larger and larger each time. And that’s where I got the idea for this video.

I wasn’t the first one to have this idea. Other people have made animations of Recamán’s sequence on YouTube, but much like my “multiplication tables” video, I wanted to make some improvements.

The largest animation of the sequence I could find included 72,000 terms. I decided to go bigger: 300,000 terms! It took my laptop 3 days to animate it. Also, all of the animations just count up over time, and it looks really slow when the pattern gets big enough. My animation speeds up exponentially, so it can keep up as the “teardrop” patterns get bigger and bigger. And finally, all of the animations seem to be only one color, and that makes it hard to see the fractal structure. Thus, after some trial-and-error, I colored my animation to make each teardrop a different color, which makes the self-similarity show through very clearly.

For the music, I used Peer Gynt Suite No. 1 by Norwegian composer Edvard Grieg. I took excerpts from “Anitra’s Dance,” and the finale, the famous “In the Hall of the Mountain King.” I thought the gradually building pace and energy of the music was a good fit to the continuously accelerating animation. Public domain recording from Musopen.

About Alex R. Howe

I'm a full-time astrophysicist and a part-time science fiction writer.
This entry was posted in math, Video and tagged , , . Bookmark the permalink.