← Back to list

Reverse engineering Ramanujan and a new formula for perimeter of ellipse

Ramanujan has given us too many formulas and too little explanation. I have wondered, like many others, how he found them. One case is his…

Anita SV · 2026-06-03 10:51 · 2 claps · 2.2 min read
#ramanujan #math #ellipse #matt-parker
Open on Medium ↗
Wiki topics: 📐 · Mathematics

Reverse engineering Ramanujan and a new formula for perimeter of ellipse

Ramanujan has given us too many formulas and too little explanation. I have wondered, like many others, how he found them. One case is his formulas for perimeter of ellipse, which uses square roots. We can easily show these are good, but how he discovered them remained a mystery.

I first saw them in a video by Standup Maths:

[embed]

I knew Ramanujan liked continued fractions a lot. So I vibe coded (Claude Opus 4.8) a search engine exploring paths Ramanujan might have taken, and it bear fruit. Not only it reproduced Ramanujan’s formula’s, it even discovered a new formula that Ramanujan probably missed using 4th roots. Now I can share with you how he might have discovered them.

For an ellipse with semi-axes a and b, define

Eccentricity like

Eccentricity like

If exact circumference is C, we can define g(h) as following.

Defining g(h)

Defining g(h)

All the formulas are just approximations for g(h).

The program generated following equations. After k=5 there was nothing better than rational polynomials.

Generated formulas vs. Historical forms

Generated formulas vs. Historical forms

Ivory and Bessel gave us a Taylor series for g(h):

First, you can convert this into a continued fraction style

And you notice initial few terms are actually simple. Simply truncating at any stage gives you Padé approximations, but we want better. Ramanujan style approximations are using square roots. So try to fit the best square root that gives you 3 terms instead of two terms a linear approximation will give you. For example sqrt(a²+x) is a * sqrt(1 + x/a), and it is approximately a² + x/2a, so when we have such ratios we can just do sqrt. So if it is not a perfect square it is not worth considering. This alone reproduces all Ramanujan’s formulae. You don’t need to write code for this, hand exploring can get the same ones if you follow the same method. Remember to invert and compute Taylor series again.

After I tried higher roots, like 4th roots, and more, I was able discover the new k=4 case. I tried square roots inside square roots, and more complex cases but they didn’t find anything better than Padé approximations.

You can read the code here for all the nitty gritty details:

https://github.com/anitasv/RamanujanEllipse


메타데이터
post_id
8fd4ecbe67c8
slug
reverse-engineering-ramanujan-8fd4ecbe67c8
url
https://medium.com/@anitasv/reverse-engineering-ramanujan-8fd4ecbe67c8
canonical_url
https://medium.com/@anitasv/reverse-engineering-ramanujan-8fd4ecbe67c8
author_url
https://medium.com/@anitasv
status
ok
fetched_at
2026-07-25 23:20:03