Presentation is loading. Please wait.

Presentation is loading. Please wait.

Modular Arithmetic ICS 6D Sandy Irani.

Similar presentations


Presentation on theme: "Modular Arithmetic ICS 6D Sandy Irani."— Presentation transcript:

1 Modular Arithmetic ICS 6D Sandy Irani

2 DIV and MOD functions d an integer d ≥ 1 n an integer
There are unique integers q for “quotient” r for “remainder” Such that r ∈ {0, 1, 2,…,d-1} n = d·q + r

3 DIV and MOD functions for n < 0
q = floor(n/d) r = n - q·d Example: n = -25, d = 6

4 DIV and MOD functions for n < 0
q = floor(n/d) r = n - q·d Example n = -75, d = 12

5 DIV and MOD functions for n < 0
q = 0 while (r < 0) r = r + d q = q - 1 Example n = -25, d = 6

6 DIV and MOD functions for n < 0
q = 0 while (r < 0) r = r + d q = q -1 Example n = -75, d = 12

7 Modular Arithmetic “Mod n” is a function from ℤ to {0, 1, …, n-1}
Addition mod n: (x + y) mod n Multiplication mod n: xy mod n

8 Modular Arithmetic In computing arithmetic expressions mod n, can compute partial results mod n and the result is the same: ((x mod n) + (y mod n)) mod n = (x + y) mod n ( ) mod 5 = ((x mod n) · (y mod n)) mod n = (x · y) mod n (158 · 219) mod 5 =

9 Modular Arithmetic ( ) mod 11 (56· ) mod 7

10 Modular Arithmetic 210 mod 7 = (25 mod 7) (25 mod 7) mod 7

11 Modular Arithmetic Any multiple of n acts like 0 mod n:

12 Rings A ring is a closed mathematical system with addition and multiplication operations that Obeys certain laws (associative, distributive, etc.) Has identities: 0 + x = x 1·x = x The elements of a ring can be different kinds of objects: Polynomials, sequences, numbers, etc.

13 The ring ℤn The ring ℤn is the set {0, 1, 2, …, n-1} along with
Addition mod n Multiplication mod n Example: ℤ5 + x 01234 01234

14 Equivalence mod n x mod n = y mod n ↔ (x-y) = integer multiple of n ↔ x ≡ y mod n ↔ “x is equivalent to y mod n” Example: n = 5 -9 -8 -7 -6 -5 -4 -3 -2 -1 1 2 3 4 5 6 7 8 9


Download ppt "Modular Arithmetic ICS 6D Sandy Irani."

Similar presentations


Ads by Google