## 2+2 = 1? Patterns in Modular arithmetic

When someone is talking about the absolute truth of mathematics and declares that once you have defined **2** and **+**, then **2+2** must equal **4**, there is a slightly glib response:

but 2+2 = 1…Mod 3

Despite this surprise, we actually all use modular arithmetic regularly, quite literally on a daily basis. When we consider six hours after 8am, the answer is not 14, but 2pm. Well you could argue for using a 24 hour clock, but no one would claim that 3am on a Tuesday morning is really 27:00 on Monday (well apparently some do, thanks to kuromagi on reddit for ref) In these cases we are not counting as we usually do, but counting on a circle mod 12 or 24. It is not hard to see that we could do this with other numbers. if we do decide that 2+1 is 0, and not 3 we are now working mod 3. In this case 2+2 is 1, as is 2*2. We can put together a small table:

+ | 0 | 1 | 2 |
---|---|---|---|

0 | 0 | 1 | 2 |

1 | 1 | 2 | 0 |

2 | 2 | 0 | 1 |

Showing what happens when the values for the column and row are added together. We can make the same table for multiplication:

x | 0 | 1 | 2 |
---|---|---|---|

0 | 0 | 0 | 0 |

1 | 0 | 1 | 2 |

2 | 0 | 2 | 1 |

I have to admit these table are a little boring, we can make things more interesting by replacing the numbers by colours. As we are working with modular arithmetic we know that the range of numbers we will come across, lies between 0 and the value we are using for modulus, so we can map these onto some circle of colours. So work mod 151 we get a new table for addition:

Using the same system of colours we can do the same thing for multiplication:

Which is starting to get interesting. We do not need to stop there, we can produce an image where the row number is taken to the power of the column:

This looks a little jumbled, in fact it seems to have very little structure at all. This is not very useful if our goal is to make pretty images, and on this blog that is normally the goal, but it other areas it turns out to be incredibly useful. The process of modular exponentiation is an essential part of public key cryptography, one of the technologies that allows secure communication over the internet. The jumble and lack of pattern that we can see is a sign that modular exponentiation is a good method to use to jumble things up. if there were structure that could be used to help decrypt the messages!

Returning to images, lets make a big version of the multiplication image, mod 1583 (you need to click it to get the full effect, scaling the image down blurs out a lot of structure):

Another option is to make an animation. what happens as we move the modulus value:

There is plenty to study in these images, for example, the curves that can be seen are approximately hyperbolae as they occur when is some fixed value. The central star point occurs in the middle of the image, and there are further stars at 1/3, 2/3, 1/4, 3/4 etc. Can you work out why?

The appearance of hyperbolae perhaps implies that other curves might be possible. What happens if we consider ? An obvious guess from this formula would be circles and we indeed get (for 151):

Playing around a little further this image comes from :

These images are certainly worth repeating for 1583 (again the details get blurred out, so click the images to see the full detail):

To finish let us consider something even simpler. Taking the value of a square to be this will always give a value between 0 and 1. We can then colour again, and animate with and going from 5 to 0:

I first came across these patterns in the December Issue of notices of the AMS, I have always been surprised how little they have been explored. This post is my attempt to do a little to correct that.

Amazing, I have never seen these kind of patterns visualised like this. I am wondering what you used to make the pictures? I have tried to make pictures using maple but never managed to make anything so beautiful…

They are just put together in Mathematica. The formula basically does all the work, with the exception of picking the colours. Obviously as you get further down there is a choice on the formula to use.

Any chance we could see the code? Very interesting animations :)

Sure, send me an email and I will send out the Mathematica file.

Hi gelada, I couldn’t find your email, so will you be kind and tell me how can I contact you for the code?

This is fascinating, although I am a little confused about the mapping between numbers and colours.

For example, In 151_add.png, the image seems to be rotated by pi/2 compared to the addition table. I would expect to see the black line running bottom left to top right, rather than top left to bottom right.

Is it just the way the coordinate system of the image is set up?

You are right, the images have the origin in the bottom left with the x-axis and y-axis positive going up and to the right. The tables have the origin in the top left and the x-axis is now positive going down. I am not sure how to correct this, as each is doing the natural thing, but they are in disagreement as you point out.

In matlab you can make them with:

n = 1000;

[X Y] = meshgrid(1:n);

M = mod(X .* Y, n);

imagesc(M);

colormap(‘hot’);

We used to regularly create and animate these in “demos” (applications designed purely to provide an impressive audiovisual experience and to demonstrate the talents and abilities of the programmers, graphic artists and musicians that created them) on the Commodore Amiga computer back in the 80s and 90s.

They could be created quickly using a simple piece of assembly language code and animated using various techniques including “colour cycling” — changing the colour palette used by the sets of pixels on the screen.

They look even more interesting when you get two sets of them with different parameters and overlay one on top of the other so that the intensity of one image negates the colours of the other. Less mathematically significant, but quite a light show!

Logical operations add a bit to the variety of patterns, see, for example

http://www.cut-the-knot.org/Curriculum/Geometry/ArithDisguise.shtml

Its really awesome towards the end of the last video that the pattern looks like that of the first video as if it were on a 3d tilted plane!

wallpapers?

This inspired me to dig up some similar pictures I had and post them as well.

You might like this one, which has both elliptic and hyperbolic patterns in the same image (link is to a smaller file that is portion of the image, but the full version is available at my post above).

Thank you for your insights into these patterns.

Lovely!

Hi! recently I came across a similar star-like pattern in a very different test (initially) unrelated with modular arithmetic. My test is finding the first decimal digit with value k={0,1,2,3,4,5,6,7,8,9} in the fractional part of sqrt(n), and the same background star-like pattern appeared! According to a peer at Mathematics Stack Exchange the star-like patterns are multifractals. It is amazing that similar structures appeared. It could mean that there is a relationship between modular arithmetic and the first time that an specific digit k appears in the decimal part of sqrt(n). I can not understand the reason, but it seems so. I am adding a link to those tests: http://hobbymaths.blogspot.jp/2015/08/multifractals-in-first-occurrence-of.html Best Regards, D.