At the next prime, turn left
The previous post mentioned a Math Overflow question about unexpected mathematical images, and reproduced one that looks like field grass. This post reproduces another set of images from that post.
Start anywhere in the complex plane with integer coordinates and walk west one unit at a time until you run into Gaussian prime [1]. Then turn left (counterclockwise) 90 and keep taking unit steps. Apparently this process will often (always?) return you to your starting point.
Different starting points lead to different patterns. Here's an example given in the post, starting at 3 + 5i.
Here's a more complex walk starting at 27 + 30i.
I tried starting at 127 + 131i and got a simple, uninteresting image. I tried again starting at 127 + 130i and got something much more complicated. I didn't time it, but it took several minutes to plot.
Here's the code that made the plots. (Note that Python uses j rather than i for imaginary unit.)
from sympy import isprimeimport matplotlib.pyplot as pltdef isgaussprime(z: complex): a, b = int(z.real), int(z.imag) if a*b != 0: return isprime(a**2 + b**2) else: c = abs(a+b) return isprime(c) and c % 4 == 3def connect(z1: complex, z2: complex): plt.plot([z1.real, z2.real], [z1.imag, z2.imag], 'b') start = 127 + 130j#start = 3 + 5jstep = 1z = startnext = Nonewhile next != start: next = z + step connect(z, next) if isgaussprime(next): step *= 1j z = nextplt.axes().set_aspect(1) plt.show()Related posts
[1] If a and b are integers, then a + bi is called a Gaussian integer. A Gaussian integer is a Gaussian prime if (1) both a and b are non-zero and a^2 + b^2 is prime, or (2) one of a or b is zero, and the absolute value of the non-zero part is a prime congruent to 3 mod 4.
Why is this definition so complicated? It's actually a theorem. There's a natural generalization of what it means to be prime in a commutative ring, and it works out that an element the Gaussian integers is prime if and only if the above criteria hold.
In general, a non-zero element p of a commutative ring R is prime if whenever p divides a product ab, p must either divide a or divide b.
The post At the next prime, turn left first appeared on John D. Cook.