Lecture: Modular Arithmetic
This lecture introduces the concept of modular arithmetic and presents a fast algorithm to compute the power of a number modulo another number. Constructive algorithms, based on the extended Euclidean algorithm, to compute modular inverses and solve the Chinese Remainder problem is presented. An algorithm to reconstruct a rational number from its modular image is presented. This algorithm also utilizes the extended Euclidean algorithm and the related concept of continued fraction approximation. Finally, a modular algorithm for integer multiplication is discussed.
Background Material
- Equivalence relations.
- Division with quotient and remainder.
- Euclidean algorithm (and extended version)
Reading
- Lecture notes on the Euclidean algorithm.
- Also study Maple's Power, mod, mods, numtheory[phi]
and chrem functions.
Topics
- Equivalence relations
- Equivalence modulo n
- Equivalence classes modulo n
- Modular arithmetic (Z_n)
- definition of + and *
- proof that it is well defined
- modular inverses
- Examples
- Condition for inverses to exist
- Computing with the extended Euclidean algorithm
- Computing with Fermat's theorem
- The finite field Z_p
- Fermat's theorem and Euler's identity
- Fast algorithm for powering
- repeated multiplication
- binary powering
- Analysis of binary powering
- Chinese Remainder Theorem (CRT)
- Existence proof
- Constructive proof using the Extended Euclidean algorithm
- Modular algorithm for integer multiplication
- Reduce inputs mod sufficiently many primes (wordsize)
- Multiply mod the primes
- Recover integer product using the CRT
- Reconstruction of rational numbers
- Continued fractions and the Euclidean algorithm
- Convergents and the Extended Euclidean algorithm
- Approximation by continued fractions
- RATCONVERT algorithm
Maple worksheets and programs and other resources
- mod.mw -
Maple worksheet on modular arithmetic,
fast powering, the CRT, and modular algorithms
- mod.ppt (mod.pdf)- slides on modular arithmetic
- ratconvert.mw - Maple worksheet
illustrating an algorithm to construct a rational number from its modular image.
- Paul S. Wang, M. J. T. Guy, and J. H. Davenport, P-adic Reconstruction of Rational Numbers,
ACM SIGSAM Bulletin, Volume 16 , Issue 2, 1982, pp. 2-3.
Created: Oct. 5, 2020 by jjohnson AT cs DOT drexel DOT edu