Ramanujan First Problem

Srinivasa Ramanujan is one of my heroes. A brilliant mind from Southern India (Chennai) who had an incredible talent for numbers and unfortunately a very tragic and brief life. If you want to learn more about him I recommend reading The Man Who Knew Infinity instead of watching the movie. In the movie there is no, zero, mathematics. And if you learn about Ramanujan without appreciating his work in math it is as if you were learning about Einstein without appreciating his work in Physics.

In the book you'll find one of the very first problems proposed by Ramanujan when he was still a kid. It was an infinite series (95% of his work revolved around infinity) where he asked all the top mathematicians in the world if they could solve it. Simply stated, here it is:


What's the value of X? Top mathematicians all over the world jumped into this problem but with no success. They worked on it for months and months until they all, one by one, gave up. Finally Ramanujan gave away the solution. X = 3.

The mathematics behind the proof are pretty advanced. Only if the mathematicians 100+ years ago had access to a Surface Laptop with Visual Studio installed....

Writing a simple code to converge the series above is relatively easy. The equation is very suitable for a recursive solution, and hopefully the convergence will happen quick enough that the stack won't blow up. In my 2-lines recursive function I use a max seed to stop the recursion (remember, this is an infinite sum). Running the code for, say, 70 iterations quickly shows where it is converging towards. Code is below, output down below, cheers, Marcelo.

class Program
{
static void Main(string[] args)
{
int max = 70;
for (int i = 0; i <= max; i++)
{
Console.WriteLine("For terms = {0}, RFP = {1}", i, RamanujanFirstProblem(2, i));
}
}
static double RamanujanFirstProblem(int currentSeed, int maxSeed)
{
if (currentSeed >= maxSeed) return 0.0;
return Math.Sqrt(1 + currentSeed * RamanujanFirstProblem(currentSeed + 1, maxSeed));
}
}

Output:

For terms = 0, RFP = 0
For terms = 1, RFP = 0
For terms = 2, RFP = 0
For terms = 3, RFP = 1
For terms = 4, RFP = 1.73205080756888
For terms = 5, RFP = 2.23606797749979
For terms = 6, RFP = 2.55983016530012
For terms = 7, RFP = 2.7550532613299
For terms = 8, RFP = 2.86710292823774
For terms = 9, RFP = 2.92917335973214
For terms = 10, RFP = 2.96272300427958
For terms = 11, RFP = 2.98055375021182
For terms = 12, RFP = 2.98992036063105
For terms = 13, RFP = 2.99480026926621
For terms = 14, RFP = 2.9973274414787
For terms = 15, RFP = 2.99863031788908
For terms = 16, RFP = 2.99929967806766
For terms = 17, RFP = 2.99964261492875
For terms = 18, RFP = 2.99981791758458
For terms = 19, RFP = 2.99990736080556
For terms = 20, RFP = 2.99995292420987
For terms = 21, RFP = 2.99997610308338
For terms = 22, RFP = 2.99998788059949
For terms = 23, RFP = 2.99999385870344
For terms = 24, RFP = 2.9999968903158
For terms = 25, RFP = 2.99999842644538
For terms = 26, RFP = 2.99999920423618
For terms = 27, RFP = 2.99999959779522
For terms = 28, RFP = 2.99999979681498
For terms = 29, RFP = 2.99999989740273
For terms = 30, RFP = 2.999999948216
For terms = 31, RFP = 2.99999997387325
For terms = 32, RFP = 2.99999998682296
For terms = 33, RFP = 2.99999999335639
For terms = 34, RFP = 2.99999999665146
For terms = 35, RFP = 2.99999999831275
For terms = 36, RFP = 2.99999999915007
For terms = 37, RFP = 2.99999999957197
For terms = 38, RFP = 2.99999999978449
For terms = 39, RFP = 2.99999999989152
For terms = 40, RFP = 2.9999999999454
For terms = 41, RFP = 2.99999999997253
For terms = 42, RFP = 2.99999999998618
For terms = 43, RFP = 2.99999999999305
For terms = 44, RFP = 2.9999999999965
For terms = 45, RFP = 2.99999999999824
For terms = 46, RFP = 2.99999999999912
For terms = 47, RFP = 2.99999999999956
For terms = 48, RFP = 2.99999999999978
For terms = 49, RFP = 2.99999999999989
For terms = 50, RFP = 2.99999999999994
For terms = 51, RFP = 2.99999999999997
For terms = 52, RFP = 2.99999999999999
For terms = 53, RFP = 2.99999999999999
For terms = 54, RFP = 3
For terms = 55, RFP = 3
For terms = 56, RFP = 3
For terms = 57, RFP = 3
For terms = 58, RFP = 3
For terms = 59, RFP = 3
For terms = 60, RFP = 3
For terms = 61, RFP = 3
For terms = 62, RFP = 3
For terms = 63, RFP = 3
For terms = 64, RFP = 3
For terms = 65, RFP = 3
For terms = 66, RFP = 3
For terms = 67, RFP = 3
For terms = 68, RFP = 3
For terms = 69, RFP = 3
For terms = 70, RFP = 3

Comments

Popular posts from this blog

Advent of Code - Day 6, 2024: BFS and FSM

Golang vs. C#: performance characteristics (simple case study)

Advent of Code - Day 7, 2024: Backtracking and Eval