Modular Arithmetic




CS255

Chris Pollett

Apr 8, 2019

Outline

Introduction

Modular Arithmetic

Definition. A group `(S, o+)` is a set together with a binary operation `o+` defined on `S` for which the following properties hold:

  1. Closure: For all `a,b` in `S`, `a o+ b` is in `S`.
  2. Identity: There is an element `e in S`, called the identity of the group, such that `e o+ a = a o+ e = a` for every `a in S`.
  3. Associativity: For all `a, b, c in S`, `(a o+ b) o+ c = a o+ (b o+ c)`.
  4. Inverses: For each `a in S`, there exists a unique element `b in S`, called the inverse of `a`, such that `a o+ b = b o+ a = e`.

Example. `(Z, +)` is a group.

Groups Defined by Modular Arithmetic

Theorem. The system `(ZZ_n^star, cdot)` is a finite abelian group.

Proof. The set is obviously finite as it has fewer then `n` elements. Closure follows from Theorem (**) on an earlier slide. `[1]_n` is easily seen to be an identity. To see the existence of inverses, let `(d, x, y)` be the output of Extended-Euclid(a, n). Then `d = 1` since `a` in `ZZ_n^star` so `ax+ny=1`. So `ax equiv 1 (mod n)`. So `x` is `a`'s inverse. Associativety and commutativety follow from these properties for `ZZ`.

Properties of Groups Defined by Modular Arithmetic

Theorem. If `(S, o+)` is a finite group and `S'` is any nonempty set of `S` closed under `o+`, then `(S', o+)` is a subgroup of `(S, o+)`.

Lagrange's Theorem. If `(S, o+)` is a finite group and `(S', o+)` is a subgroup, then `|S'|` is a divisor of `|S|`.

Proof Idea. Call a set of the form `aS' := {as' : s' in S', a in S}` a left coset of `S'`. The idea is to show that all the left cosets have the same number of elements. Since every element of `S` belongs to some left coset, that means the size of `S`, denoted by `|S|`, is equal to `|S:S'||S'|`, where `|S:S'|` is the number of left cosets. Hence, `|S'|` is a divisor of `|S|`.

Subgroups Generated By an Element

Theorem. For any finite group `(S, o+)` and any `a in S`, `o\r\d(a) = |langle a rangle|`.

Proof. Let `t=\o\r\d(a)`. Since `a^((t)) = e` and `a^((t+k))= a^((t)) o+ a^((k))= a^((k))` for `k ge 1`, if `i>t`, then `a^((i))=a^((j))` for some `j < t`. Thus, no new elements are seen after `a^((t))`. So `langle a rangle ={a^((1)), a^((2)), ... , a^((t))}` and `|langle a rangle| le t`. To see `|langle a rangle| ge t`, suppose `a^((i)) = a^((j))` for some `i,j`, satisfying `1 le i < j le t`. Then, `a^((i+k)) = a^((j+k))` for all `k>=0`. But this implies `a^((i+(t-j))) = a^((j+(t-j))) =e`, a contradiction as `i+(t-j) < t`. So all of `a^((i))` are distinct.

Some Corollaries

Corollary. The sequence `a^((1)), a^((2)), ...` is periodic with period `o\r\d(a)`.

Corollary. If `(S, o+)` is a finite group with identity `e`, then for all `a in S`, `a^((|S|))=e`.

Solving Modular Linear Equations

Theorem (%%). For any positive integers `a` and `n`, if `d = gcd(a,n)` then `langle a rangle = langle d rangle` in `ZZ_n`. Thus, `|langle a rangle| = n/d`.

Proof. We begin by showing that `d` is in `langle a rangle`. Recall that Extended-Euclid(a,n) produces integers `x'` and `y'` such that `ax'+ ny' = d`. Thus `ax' equiv d (mod n)`, so `d` is in `langle a rangle`. Since `d` is in `langle a rangle` it follows that every multiple of `d` is in `langle a rangle`. So `langle d rangle` is contained in `langle a rangle`. But now if `m in langle a rangle`, then `m equiv ax mod n`. So `m = ax+ny`. Since `d | a` and `d | n`, `d | m`; so `m in langle d rangle`. Therefore `langle a rangle subseteq langle d rangle`.

Corollary. The equation `ax equiv b (mod n)` is solvable for the unknown `x` iff `gcd(a,n) | b`.

Proof. The proof above shows us if `d = gcd(a,n)`, that the equation `ax equiv d (mod n)` has a solution. If `gcd(a,n) | b` then `m \cdot gcd(a,n) = b` for some `m`, hence, `amx equiv md equiv b (mod n)`. On the other hand, from the above proof we know `langle a rangle subseteq langle d rangle`, so any multiple of `a` is some multiple of `d` mod `n`. But if `gcd(a,n) ∤ b`, then no such multiple can be equal to `b mod n`.

More on Solving Linear Equations

Corollary. The equation `ax equiv b (mod n)` either has `d` distinct solutions modulo `n`, where `d = gcd(a,n)`, or it has no solutions.

Proof. If `ax equiv b (mod n)` has a solution, then `b in langle a rangle`. As `\o\r\d(a)=|langle a rangle|`, by Theorem (%%), the sequence `Seq ={a^((i)) mod n | i= 0, 1,..., n-1}` is periodic with period `|langle a rangle| = n/d`. So if `b in langle a rangle`, then `b` appears exactly `d` times in `Seq`.

Quiz

Which of the following statements is true?

  1. If x,y are relatively prime then the extended Euclidean algorithm takes exponential time.
  2. The Marker algorithm is `O(ln k)` competitive.
  3. The smallest possible element of the set `{ax+by:x,y\in ZZ}` is always strictly larger than `gcd(a,b)`.