# Lecture 25: Modular Arithmetic

• Using equivalence classes to simplify problems

• Operations on integers mod m are well defined
• [a] + [b],  − [a], [a] ⋅ [b], [a]n
• Inverses
• units
• Exponentiation
• n[a] not well defined
• definition of totient (ϕ(m))

## Reminder of facts about integers mod m

Definition: [a] = [b] if a ≡ b(modm) which means m∣(a − b) which means there is some k with a − b = km.

Equivalently, [a] = [b] if and only if a = b + km for some k. We'll use this form several times.

## Operations on modular integers

Claim: defining [a] + [b] as [a + b] is well-defined. That is, if [a] = [aʹ] and [b] = [bʹ] then [a + b] = [aʹ + bʹ].

Proof: to start, we'll just choose a different representative of a.

Suppose [a] = [aʹ]. Then a = aʹ + km for some k. Thus a + b = aʹ + km + b = (aʹ + b) + km. Thus [a + b] = [aʹ + b].

Now, suppose [a] = [aʹ] and [b] = [bʹ]. Then we can use the above twice to conclude [a + b] = [aʹ + bʹ]:
[a + b] = [aʹ + b] = [b + aʹ] = [bʹ + aʹ] = [aʹ + bʹ]

Claim: defining [a][b] as [ab] is well defined.

Proof: as above, we'll just choose a different representative for [a] and then use commutativity.

Suppose [a] = [aʹ]. Then a = aʹ + km for some k. So
ab = (aʹ + km)b = aʹb + (kb)m
Thus [ab] = [aʹb].

Claim: defining  − [a] as [ − a] is well defined.

Proof: suppose [a] = [aʹ]. Then a = aʹ + km. Thus  − a =  − aʹ + ( − k)m. Thus [ − a] = [ − aʹ].

Claim: if n is an integer, then defining [a]n as [an] is well defined.

Proof: use induction on n and the fact that multiplication is well defined.

## Using these facts for computation

• Compute 11734mod 10. Use the fact that [11] = [1]. Answer: [1]

• Compute 9735mod 10. Use the fact that [9] = [ − 1]. Answer: [9]

• Compute 7735mod 10. Use the fact that 7735 = 72 ⋅ 367 + 1 = 49367 ⋅ 7 and [49] = [ − 1]. Answer: [3].

## Inverses and units

• a ring is a set of things that you can add and multiply, and addition and multiplication obey the usual rules (e.g. commutativity, distributivity, etc.)

• in a ring, a unit is an element with a multiplicative inverse. That is, x is a unit of R if there exists a y ∈ R with xy = 1.

• Examples:
• units of Z are 1 (inverse is 1) and -1 (inverse is -1)
• units of Q are everything other than 0. Inverse of p / q is q / p.
• units of R are everything other than 0.
• You proved in homework that units of Zm are [a] where a and m are relatively prime.

• Examples:
• units of Z7 are {[1], [2], [3], [4], [5], [6]}. Inverses:
• inverse of [1] is [1] because [1][1] = [1]
• inverse of [2] is [4] because [2][4] = [8] = [1]
• inverse of [3] is [5] because [3][5] = [15] = [1]
• inverse of [6] is [6] because [6][6] = [36] = [1]
• [0] not a unit because [0] times anything is [0] ≠ [1]
• units of Z4 are {[1], [3]}.
• inverse of [1] is [1]
• inverse of [3] is [3]
• [2] has no inverse: [2][0] = [0] ≠ [1], [2][1] = [2] ≠ [1], [2][2] = [0] ≠ [1] and [2][3] = [2] ≠ [1].

## Exponentiation

Defining n[a] as [na] doesn't work. Counterexample: let m = 5, n = 2, a = 2. Then [a] = [2] = [7], but [22] = [4] and [27] = [128] = [3] ≠ [4].

## Totient

The totient of m, written ϕ(m) (pronounced "phi" of m, LaTeX \phi) is the number of units of Zm.

Examples: ϕ(7) = 6, ϕ(4) = 2.

We'll use totient in next lecture to define exponentiation.