Here's how I like to solve my equations: just walk around randomly until I trip over a solution!

A 3D graph showing the random walk evolution

Random walks (check my older post here) and Diophantine equations are two simple mathematical beasts. After a college seminar, I tried putting them together to make something neat, and came up with this: just pick a Diophantine equation, simulate a random walk, and try to see if the random walk went over any solutions! In this report I briefly go over how I came up with this, and show the code I wrote/some results. The Matlab code is all in here (I also have some Python code about random walks here, check my post!).

In the image above, the blue line represents a path taken by the random walk and in orange/red the nodes tell us how far we are from a solution (the smaller the node, the closer we are). Note that this notion of proximity isn't given by actually computing the distance to a known solution, but just by looking at how similar the two sides of the equation are. The image below shows the evolution of three independent random walks trying to find an example solution of \(\frac{4}n = \frac1x + \frac1y + \frac1z\) with \(n = 25\) (that expression is the expression of the Erdös-Straus conjecture).

Three random walks in 3D

Become a better Python 🐍 developer 🚀

+35 chapters. +400 pages. Hundreds of examples. Over 30,000 readers!

My book “Pydon'ts” teaches you how to write elegant, expressive, and Pythonic code, to help you become a better developer. Get it below!

Download from

Previous Post Next Post

Blog Comments powered by Disqus.