Modular arithmetic

https://arbital.com/p/modular_arithmetic

by Malcolm McCrimmon Jul 30 2016 updated Aug 2 2016

Addition as traveling around a circle, instead of along a line.


[summary: Modular arithmetic is the type of [-addition] we use when calculating dates and times. In ordinary [-arithmetic], $~$9 + 6 = 15$~$, but when working with the hours of the day, 6 hours after 9 o'clock is 3 o'clock, not 15 o'clock. This type of "wrap-around" addition generalizes to many other domains. ]

[todo: needs images!]

In ordinary [-arithmetic], you can think of [-addition] and [-subtraction] as traveling in different directions along an [infinity infinitely] long road. A calculation like $~$9 + 6$~$ can be thought of as starting at kilometer marker 9, then driving for another 6 kilometers, which would bring you to kilometer marker 15 ([-negative_numbers] are analogous to driving along the road backwards). If the road is perfectly straight, you can never go back to a marker you've already visited by driving forward. But what if the road were a circle?

Modular arithmetic is a type of addition that's more like driving around in a circle than along an infinite straight line. In modular arithmetic, you can start with a number, add a positive number to it, and come out with the same number you started with--just as you can drive forward on a circular road to get right back where you started. If the length of the road were 12, for example, then if you drove 12 kilometers you would wind up right back where you started. In this case, we would call it modulus 12 arithmetic, or mod 12 for short.

Modular arithmetic may seem strange, but in fact, you probably use it every day! The hours on the face of a clock "wrap around" from 12 to 1 in exactly the same way that a circular road wraps around on itself. Thus, while in ordinary arithmetic $~$9 + 6 = 15$~$, when figuring out what time it will be 6 hours after 9 o'clock, we use modular arithmetic to arrive at the correct answer of 3 o'clock, rather than 15 o'clock.