Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Math 152: Intro to Mathematical Software
2017-03-08
Kiran Kedlaya; University of California, San Diego
adapted from lectures by William Stein, University of Washington
** Lecture 24: Algebra and number theory (prep for cryptography): part 1**
(a/k/a preview of Math 187B, to be offered for the first time next quarter)
Announcements:
This week's peer grading due Thursday, March 9 at 8pm, as usual. (Ignore the date typo on the HW.)
Guest lectures next week:
Monday, March 13: Kartik Venkatram
Wednesday, March 15: Alina Bucur
No sections on Monday, March 13.
Office hours next week:
Zonglin: Thursday, March 16, 3:30-5:30 in APM 5748.
Me: Friday, March 17, 11-12 in APM 7202.
Peter: Friday, March 17, 12-1 and 3-4 in APM 6132.
Next week's homework due Friday, March 17 at 8pm. Peer grading due Sunday, March 19 at 8pm.
The first half of this assignment is "normal" (number theory and cryptography).
The second half is freeform: create your own lecture! See the assignment for details.
Please do your course evaluation (CAPE)! Evaluations close Monday, March 20 at 8am.
HW1-6 grades are available on TritonEd, plus some attendance and peer grading scores. Remember, there is no final exam for this course.
A little number theory
It is very very easy to compute the greatest common divisor of two integers, even very large ones, because of the Euclidean algorithm.
The same technique can be used to find, given two integers and , two other integers and such that . This is sometimes called the extended Euclidean algorithm, which helps explain the notation in Sage.
These values can be used to make explicit the Chinese remainder theorem: if , then every system of equations of the form [ x \equiv x_1 \pmod{m}, \qquad x \equiv x_2 \pmod{n} ] has a solution (which is unique up to adding a mulitple of ).
By contrast, finding the prime factorization of a positive integer can be difficult. Not always, though.
What makes the last example particularly easy is that you can test for the very small prime factors quickly (trial division), and then it turns out to be much easier to tell whether or not a big number is prime than to actually factor it. There are other features that make some numbers easier to factor than others, but more on this later.
Modular exponentiation
One reason for this is that it is easy to do modular exponentiation, i.e., the remainder of a^b upon division by c.
How not to do this:
What does work:
Question: how is this possible? Even working mod n, directly computing with factors is not feasible.
One application of this is the Fermat test for primality. This is based on the little Fermat theorem: if is a prime number, then for any positive integer , is divisible by . (In the language of congruences, .)
One possible proof (for the case , but this can be extended to a general argument): in the binomial expansion [ (x+y)^p = x^p + \binom{p}{1} x^{p-1}y + \cdots + \binom{p}{p-1} xy^{p-1} + y^p ] all of the intermediate coefficients are divisible by (so plugging in gives the claim). For example...
The contrapositive of the little Fermat theorem is: if is not divisible by , then is not prime. This test works extremely well!
This method is not foolproof: it can return false positives for primality. Look up Carmichael numbers.
Consequently, this method cannot be used to certify that a particular number is prime, only that it is not prime. There are efficient algorithms that can certify primality, but they are somewhat harder to describe. One important one is the (Agrawal-Kayal-Saxena (AKS) algorithm)[https://en.wikipedia.org/wiki/AKS_primality_test], which is both extremely simple and polynomial-time (though not as efficient in practice as some other methods). Kayal and Saxena were undergraduates at the time they discovered it (2002)!
One way to say this is that "prime numbers are easy to factor". The reason this is not an empty statement is because you have to know when to stop factoring!
In any case, the Fermat test is so effective that any number that passes it is probably prime, and this is sometimes good enough (though not for cryptography!).
The fact that prime numbers are (relatively) easy to identify makes it possible to have functions like this:
Multiplicative order and primitive roots
Let be integers with . Using the extended Euclidean algorithm as above, one can find a multiplicative inverse of modulo , i.e., a value such that . In fact, Sage will do this automatically.
As a consequence of the existence of the multiplicative inverse, there always exists a positive integer such that . (There must be two powers that coincide mod , and we can cancel the powers of from one side.)
If is prime, the little Fermat theorem implies that always works (although it need not be the smallest such value; more on this in a moment). For general , there is a generalization of the Fermat theorem due to Euler: we have where denotes the Euler phi function (or totient function): if has prime factorization , then [ \phi(n) = (p_1 - 1)p_1^{e_1}-1(p_2-1)p_2^{e_2-1} \cdots. ] For those who know group theory: recall that this works because the residue classes mod which have no common factor with form a group under multiplication, and is its order.
So now it makes sense to consider the smallest positive integer such that . This integer must divide , otherwise the remainder of mod would be an even smaller value. (Or use group theory!) This is called the multiplicative order of mod .
Important result: if is prime, then there is always at least one value of for which the multiplicative order of mod is equal to the maximum possible value . Any such is called a primitive root mod . These play an important role in the use of discrete logarithms in cryptography.
(Abstract algebra interpretation; if is prime, then is a cyclic group!)