What Is Modular Arithmetic? (x Mod y = r)

Introduction to Quantum Computing

Modular Arithmetic

"Modular arithmetic is a system where numbers 'wrap around' when reaching a certain value called the modulus." 

An example of using modular arithmetic is a determining time with a 12-hour clock.  The day is composed of two 12-hour periods. If the time is 9:00 now, then in 4 hours it will be 1:00.  Notice that addition would result in 9 + 4 = 13.  However, the clock 'wrapped around' at 12. The hour number starts over once it passed 12.  So, this is modulo 12.

Clock group.svg
Commons. CC BY-SA 3.0, Link

For the modular arithmetic, the formula is -- x mod y = r  The number 'r' is the remainder of the division; 'x' is the dividend; 'y' is the divisor.  So for the example, x 13 (e.g. what time will it be in 4 hours if it is now 9 -- 9+4=13) and y is 12 the formula is 13 mod(12) = r.  

The steps to answer this arithmetic problem are:

  1. Start by choosing an initial number
    1. in this example, it is 13 - this is the dividend
  2. Choose the divisor
    1. in this example it is 12 - this is the divisor
  3. Divide the number and round down - 13/12 = 1 - this is the quotient
  4. Multiply the divisor by the quotient -  12 * 1 = 12
  5. Subtract this number from the dividend - 13 - 12 = 1.

This number is the result of the modulo operation. Write it as 13 mod 12 = 1.