Number Theory Proofs CSE 311 Autumn 20
Lecture 14
Warm up: Show that if π2 if even then π is even.
Announcements
HW5 is coming out this evening.
Itβs due Monday November 9th
Itβs also a little longer than usual, so donβt think this is an excuse to put it off.
βPart Iβ of the homework is on number theory β these slides have everything you need.
βPart IIβ is on induction, the topic for next week.
We want to give you feedback on induction proofs before the midterm, hence the different setup.
Announcements
Everyone gets an extra late day!
Why?HW3 grades arenβt back out yet, we want to make sure you donβt repeat mistakes if you learn from them. Theyβll be out this afternoon.
And HWs 3 and 4 seem to be taking some folks longer than anticipated.
Use this as a learning opportunity; 311 homeworks are not like calculus homeworkswhere itβs easy to predict exactly how long it will take. Get started early.
Announcements
Daylight Saving Time ends this Sunday.
If youβre in a part of the U.S. that observes Daylight Saving Time, enjoy your extra hour of sleep.
If youβre notβ¦the time of everything relative to you probably shifts by an hour Sunday (Seattle time). :/
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
gcd(35,27)
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
gcd(35,27) = gcd(27, 35%27) = gcd(27,8)
= gcd(8, 27%8) = gcd(8, 3)
= gcd(3, 8%3) = gcd(3, 2)
= gcd(2, 3%2) = gcd(2,1)
= gcd(1, 2%1) = gcd(1,0)
35 = 1 β 27 + 827 = 3 β 8 + 38 = 2 β 3 + 23 = 1 β 2 + 1
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
35 = 1 β 27 + 827 = 3 β 8 + 38 = 2 β 3 + 23 = 1 β 2 + 1
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
35 = 1 β 27 + 827 = 3 β 8 + 38 = 2 β 3 + 23 = 1 β 2 + 1
8 = 35 β 1 β 273 = 27 β 3 β 82 = 8 β 2 β 31 = 3 β 1 β 2
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
8 = 35 β 1 β 273 = 27 β 3 β 82 = 8 β 2 β 31 = 3 β 1 β 2
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
8 = 35 β 1 β 273 = 27 β 3 β 82 = 8 β 2 β 31 = 3 β 1 β 2
1 = 3 β 1 β 2= 3 β 1 β 8 β 2 β 3= β1 β 8 + 2 β 3
Extended Euclidian Algorithm
Step 1 compute gcd(a,b); keep tableau information.
Step 2 solve all equations for the remainder.
Step 3 substitute backward
8 = 35 β 1 β 273 = 27 β 3 β 82 = 8 β 2 β 31 = 3 β 1 β 2
1 = 3 β 1 β 2= 3 β 1 β 8 β 2 β 3= β1 β 8 + 3 β 3= β1 β 8 + 3 27 β 3 β 8= 3 β 27 β 10 β 8= 3 β 27 β 10(35 β 1 β 27)= 13 β 27 β 10 β 35
gcd(27,35) = 13 β 27 + β10 β 35
When substituting
back, you keep
the larger of π, πand the number
you just
substituted.
Donβt simplify
further! (or you
lose the form you
need)
Soβ¦whatβs it good for?
Suppose I want to solve 7π₯ β‘ 1 πππ π
Just multiply both sides by 1
7β¦
Oh wait. We want a number to multiply by 7 to get 1.
If the gcd(7,n) = 1
Then π β 7 + π‘π = 1, so 7π β 1 = βπ‘π i.e. π|(7π β 1) so 7π β‘ 1 πππ π .
So the π from BΓ©zoutβs Theorem is what we should multiply by!
Try it
Solve the equation 7π¦ β‘ 3(πππ 26)
What do we need to find?
The multiplicative inverse of 7(mod 26)
Finding the inverseβ¦
gcd(26,7) = gcd(7, 26%7) = gcd(7,5)
= gcd(5, 7%5) = gcd(5,2)
= gcd(2, 5%2) = gcd(2, 1)
= gcd(1, 2%1) = gcd(1,0)= 1.
26 = 3 β 7 + 5 ; 5 = 26 β 3 β 7
7 = 5 β 1 + 2 ; 2 = 7 β 5 β 1
5 = 2 β 2 + 1 ; 1 = 5 β 2 β 2
1 = 5 β 2 β 2= 5 β 2(7 β 5 β 1)= 3 β 5 β 2 β 7
= 3 β 26 β 3 β 7 β 2 β 73 β 26 β 11 β 7
β11 is a multiplicative inverse.
Weβll write it as 15, since weβre working mod 26.
Try it
Solve the equation 7π¦ β‘ 3(πππ 26)
What do we need to find?
The multiplicative inverse of 7 (πππ 26).
15 β 7 β π¦ β‘ 15 β 3(πππ 26)
π¦ β‘ 45(πππ 26)
Or π¦ β‘ 19(πππ 26)
So 26|19 β π¦, i.e. 26π = 19 β π¦ (for π β β€) i.e. π¦ = 19 β 26 β π for any π β β€
So {β¦ ,β7,19,45,β¦19 + 26π,β¦ }
Multiplicative Inverse
The number π is a multiplicative inverse of π (mod π) if ππ β‘ 1(πππ π).
If gcd(π, π) = 1 then the multiplicative inverse exists.
If gcd(π, π) β 1 then the inverse does not exist.
Arithmetic (πππ π) for π prime is really nice for that reason.
Sometimes equivalences still have solutions when you donβt have inverses (but sometimes they donβt) β youβll experiment with these facts on HW5.
Proof By Contradiction
Suppose the negation of your claim.
Show that you can derive False (i.e. (Β¬claim) β F )
If your proof is right, the implication is true.
So Β¬claim must be False.
So claim must be True!
Proof By Contradiction
Claim: 2 is irrational (i.e. not rational).
Proof:
Suppose for the sake of contradiction that 2 is rational.
But [] is a contradiction!
Proof By Contradiction
Claim: 2 is irrational (i.e. not rational).
Proof:
Suppose for the sake of contradiction that 2 is rational.
By definition of rational, there are integers s, π‘ such that t β 0 and 2 = π /π‘
Let π =s
gcd s,t, q =
s
gcd s,tNote that gcd π, π = 1.
2 =π
π
Thatβs is a contradiction! We conclude 2 is irrational.
If π2 is even then π is even.
Proof By Contradiction
Claim: 2 is irrational (i.e. not rational).
Proof:
Suppose for the sake of contradiction that 2 is rational.
By definition of rational, there are integers s, π‘ such that t β 0 and 2 = π /π‘
Let π =s
gcd s,t, q =
s
gcd s,tNote that gcd π, π = 1.
2 =π
π
2 =π2
π2
2π2 = π2 so π2 is even.
Thatβs is a contradiction! We conclude 2 is irrational.
If π2 is even then π is even.
Proof By Contradiction
Claim: 2 is irrational (i.e. not rational).
Proof:
Suppose for the sake of contradiction that 2 is rational.
By definition of rational, there are integers s, π‘ such that t β 0 and 2 = π /π‘
Let π =s
gcd s,t, q =
s
gcd s,tNote that gcd π, π = 1.
2 =π
π
2 =π2
π2
2π2 = π2 so π2 is even. By the fact above, π is even, i.e. π = 2π for some integer π. Squaring both sides π2 =4π2
Substituting into our original equation, we have: 2π2 = 4π2, i.e. π2 = 2π2.
So π2 is even. Applying the fact above again, π is even.
But if both π and π are even, gcd π, π β₯ 2 . But we said gcd π, π = 1
Thatβs is a contradiction! We conclude 2 is irrational.
If π2 is even then π is even.
Proof By Contradiction
How in the world did we know how to do that?
In real lifeβ¦lots of attempts that didnβt work.
Be very careful with proof by contradiction β without a clear target, you can easily end up in a loop of trying random things and getting nowhere.
Whatβs the difference?
Whatβs the difference between proof by contrapositive and proof by contradiction?
Show π β π Proof by contradiction Proof by contrapositive
Starting Point Β¬ π β π β‘ (π β§ Β¬π) Β¬π
Target Something false Β¬π
Show π Proof by contradiction Proof by contrapositive
Starting Point Β¬π ---
Target Something false ---
Another Proof By Contradiction
Claim: There are infinitely many primes.
Proof:
Suppose for the sake of contradiction, that there are only finitely many primes. Call them π1, π2, β¦ , ππ.
But [] is a contradiction! So there must be infinitely many primes.
Another Proof By Contradiction
Claim: There are infinitely many primes.
Proof:
Suppose for the sake of contradiction, that there are only finitely many primes. Call them π1, π2, β¦ , ππ.
Consider the number π = π1 β π2 β β― β ππ + 1
Case 1: π is prime
Case 2: π is composite
But [] is a contradiction! So there must be infinitely many primes.
Another Proof By Contradiction
Claim: There are infinitely many primes.
Proof:
Suppose for the sake of contradiction, that there are only finitely many primes. Call them π1, π2, β¦ , ππ.
Consider the number π = π1 β π2 β β― β ππ + 1
Case 1: π is prime
π > ππ for all π. But every prime was supposed to be on the list π1, β¦ , ππ. A contradiction!
Case 2: π is composite
Some prime on the list (say ππ) divides π. So π%ππ = 0. and π1π2β―ππ + 1 %ππ =1. But π = π1π2β―ππ + 1 . Thatβs a contradiction!
In either case we have a contradiction! So there must be infinitely many primes.
An application of all of this modular arithmetic
Amazon chooses random 512-bit (or 1024-bit) prime numbers π, π and an exponent π (often about 60,000).
Amazon calculates n = ππ. They tell your computer (π, π) (not π, π)
You want to send Amazon your credit card number π.
You compute πΆ = ππ%π and send Amazon πΆ.
Amazon computes π, the multiplicative inverse of π (πππ [π β 1][π β 1])
Amazon finds πΆπ%π
Fact: π = πΆπ%π as long as 0 < π < π and π β€ π and π β€ π
How big are those numbers?
1230186684530117755130494958384962720772853569595334792197322
4521517264005072636575187452021997864693899564749427740638459
2519255732630345373154826850791702612214291346167042921431160
2221240479274737794080665351419597459856902143413
3347807169895689878604416984821269081770479498371376856891243
1388982883793878002287614711652531743087737814467999489
3674604366679959042824463379962795263227915816434308764267603
2283815739666511279233373417143396810270092798736308917
How do we accomplish those steps?
That fact? You can prove it in the extra credit problem on HW5. Itβs a nice combination of lots of things weβve done with modular arithmetic.
Letβs talk about finding πΆ = ππ%π.
π is a BIG number (about 216 is a common choice)
int total = 1;
for(int i = 0; i < e; i++){
total = (a * total) % n;
}
Letβs build a faster algorithm.
Fast exponentiation β simple case. What if π is exactly 216?
int total = 1;
for(int i = 0; i < e; i++){
total = a * total % n;
}
Instead:
int total = a;
for(int i = 0; i < log(e); i++){
total = total^2 % n;
}
Fast exponentiation algorithm
What if π isnβt exactly a power of 2?
Step 1: Write π in binary.
Step 2: Find ππ%π for π every power of 2 up to π.
Step 3: calculate ππ by multiplying ππ for all π where binary expansion of π had a 1.
Fast exponentiation algorithm
Find 411%10
Step 1: Write π in binary.
Step 2: Find ππ%π for π every power of 2 up to π.
Step 3: calculate ππ by multiplying ππ for all π where binary expansion of π had a 1.
Start with largest power of 2 less than π (8). 8βs place gets a 1. Subtract power
Go to next lower power of 2, if remainder of π is larger, place gets a 1, subtract power; else place gets a 0 (leave remainder alone).
11 = 10112
Fast exponentiation algorithm
Find 411%10
Step 1: Write π in binary.
Step 2: Find ππ%π for π every power of π up to π.
Step 3: calculate ππ by multiplying ππ for all π where binary expansion of πhad a 1.
41%10 = 4
42%10 = 6
44%10 = 62%10 = 6
48%10 = 62%10 = 6
Fast exponentiation algorithm
Find 411%10
Step 1: Write π in binary.
Step 2: Find ππ%π for π every power of 2 up to π.
Step 3: calculate ππ by multiplying ππ for all π where binary expansion of πhad a π.
41%10 = 4
42%10 = 6
44%10 = 62%10 = 6
48%10 = 62%10 = 6
411%10 = 48+2+1%10 =
[(48%10) β 42%10 β 4%10 ]%10 = (6 β 6 β 4)%10
= 36%10 β 4 %10 = 6 β 4 %10 = 24%10 = 4.
Fast Exponentiation Algorithm
Is itβ¦actually fast?
The number of multiplications is between log2 π and 2 log2 π.
Thatβs A LOT smaller than π
One More Example for Reference
Find 325%7 using the fast exponentiation algorithm.
Find 25 in binary:
16 is the largest power of 2 smaller than 25. 25 β 16 = 9 remaining
8 is smaller than 9. 9 β 8 = 1 remaining.
4s place gets a 0.
2s place gets a 0
1π place gets a 1
110012
One More Example for Reference
Find 325%7 using the fast exponentiation algorithm.
Find 32π%7:
31%7 = 3
32%7 = 9%7 = 2
34%7 = (32 β 32)%7 = (2 β 2)%7 = 4
38%7 = 34 β 34 %7 = 4 β 4 %7 = 2
316%7 = 38 β 38 %7 = 2 β 2 %7 = 4
One More Example for Reference
Find 325%7 using the fast exponentiation algorithm.
31%7 = 3
32%7 = 2
34%7 = 4
38%7 = 2
316%7 = 4
325%7 = 316+8+1%7
= [(316%7) β 38%7 β (31%7)]%7
= 4 β 2 β 3 %7= 1 β 3 %7 = 3
A Brief Concluding Remark
Why does RSA work? i.e. why is my credit card number βsecretβ?
Raising numbers to large exponents (in mod arithmetic) and finding multiplicative inverses in modular arithmetic are things computers can do quickly.
But factoring numbers (to find π, π to get π) or finding an βexponential inverseβ (not a real term) directly are not things computers can do quickly. At least as far as we know.
An application of all of this modular arithmetic
Amazon chooses random 512-bit (or 1024-bit) prime numbers π, π and an exponent π (often about 60,000).
Amazon calculates n = ππ. They tell your computer (π, π) (not π, π)
You want to send Amazon your credit card number π.
You compute πΆ = ππ%π and send Amazon πΆ.
Amazon computes π, the multiplicative inverse of π (πππ [π β 1][π β 1])
Amazon finds πΆπ%π
Fact: π = πΆπ%π as long as 0 < π < π and π β€ π and π β€ π
If π2 is even then π is even
Proof:
We argue by contrapositive.
Suppose π is odd.
π2 is odd.
If π2 is even then π is even
Proof:
We argue by contrapositive.
Suppose π is odd.
By definition of odd, π = 2π + 1 for some integer π.
π2 = 2π + 1 2 = 4π2 + 4π + 1.
Factoring, π2 = 2 2π2 + 2π + 1.
So π2 is odd by definition.
GCD fact
If π and π are positive integers, then gcd(a,b) = gcd(b, a % b)
How do you show two gcds are equal?
Call π = gcd π€, π₯ , π = gcd(π¦, π§)
If π|π€ and π|π₯ then π is a common divisor of π€, π₯ so π β€ π
If π|π¦ and π|π§ then π is a common divisor of π¦, π§, so π β€ π
If π β€ π and π β€ π then π = π
gcd(a,b) = gcd(b, a % b)
Let x = gcd(π, π) and π¦ = gcd(π, π%π).
We show that π¦ is a common divisor of π and π.
By definition of gcd, π¦|π and π¦|(π%π). So it is enough to show that π¦|π.
Applying the definition of divides we get π = π¦π for an integer π, and π%π = π¦π for an integer π.
By definition of mod, π%π is π = ππ + π%π for an integer π.
Plugging in both of our other equations:
π = ππ¦π + π¦π = π¦ ππ + π . Since π, π, and π are integers, π¦|π. Thus π¦ is a common divisor of π, π and thus π¦ β€ π₯.
gcd(a,b) = gcd(b, a % b)
Let x = gcd(π, π) and π¦ = gcd(π, π%π).
We show that π₯ is a common divisor of π and a%π.
By definition of gcd, x|π and π₯|π. So it is enough to show that x|(π%π).
Applying the definition of divides we get π = π₯πβ² for an integer πβ², and a = π₯πβ² for an integer πβ².
By definition of mod, π%π is π = ππ + π%π for an integer π
Plugging in both of our other equations:
π₯πβ² = ππ₯πβ² + π%π. Solving for π%π, we have π%π = π₯πβ² β ππ₯πβ² =π₯ πβ² β ππβ² . So π₯|(π%π). Thus π₯ is a common divisor of π, π%π and thus π₯ β€ π¦.