Primality#


Table of Contents#


Programming Environment#

import math
from   numba  import jit, njit, prange
import numpy  as np
from   typing import Iterator
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[1], line 2
      1 import math
----> 2 from   numba  import jit, njit, prange
      3 import numpy  as np
      4 from   typing import Iterator

ModuleNotFoundError: No module named 'numba'

Questions

  1. Given a composite integer, how do we find a decomposition into a product of integers larger than 1?

  2. How do we recognize a prime integer?


Euclid’s Lemma#

Theorem [Bressoud 1.1 pp. 1-2]

If a prime divides the product of two integers then it must divide at least one of those integers.

pP[Prime(p)a,bZ[(pab)((pa)(pb))]]

Note that the following cases hold as a consequence.

If a prime p divides a2, then it must divide a.

pP[Prime(p)aZ[(pa2)(pa)]]

Therefore, if p divides a2, then p2 divides a2.

pP[Prime(p)aZ[(pa2)(p2a2)]]

The following theorem is a property which is characteristic of primes and is sometimes used to define them.

Theorem [Humphreys & Prest 1.3.1 pp. 26]

Let p be a prime and let a and b be integers s.t. p divides ab.
p divides either a or b.

pP[Prime(p)a,bZ[(pab)((pa)(pb))]]

Proof [Humphreys & Prest pp. 26]

The only positive divisors of p are 1 and p since p is prime.
Then either gcd(p,a)=p or gcd(p,a)=1.

If gcd(p,a)=p then pa.

[Humphreys & Prest 1.1.6]

If gcd(p,a)=1 then p and a are relatively prime.
Then there are integers r and s s.t. 1=pr+asb=pbr+abs=p(br)+ab(s).
Since p divides p(br) and p divides ab(s), p divides their sum b.

if a prime divides a product then it divides one or the other factor.

The following lemma is an extension of the previous theorem.

Lemma [Humphreys & Prest pp. 27]

Let p be prime and let p divide the product a1a2ar.
Then p divides at least one of a1,a2,,ar.

Proofbyinductiononthenumberroffactorsai [Humphreys & Prest pp. 27]

Base Case

If pa1 then pa1.

Induction Step

Induction Hypothesis: Let pb1b2br1 so that p divides at least one of b1,b2,,br1.
Let p divide the product a1ar which we want to write as a product b1br1 of r1 integers.
Define bi=ai for ir2 and let br1 be the product ar1ar.
Then a1a2ar2(ar1ar) is a product of r1 integers.
Either p divides one of a1,a2,,ar2 or p divides ar1ar.
If the latter, then either p divides ar1 or p divides ar.

Therefore p divides one of a1,a2,,ar.


Prime Factorization#

Definition [Bressoud]

The decomposition of a positive integer into primes is called its factorization, which is expressed by

n=p1a1×p2a2××prar

where p1,p2,,pr are distinct primes.


Relative Primality#

or coprimality

Definition [Bressoud pp. 3]

If integers m and n have no common primes in their respective factorizations then m and n are said to be relatively prime.

Example [Bressoud pp. 3]

45=3×3×5 and 98=2×7×7 are relatively prime.

Definition [Humphreys & Prest pp. 12]

Let a and b be positive integers.
If gcd(a,b)=1 then a and b are said to be relatively prime.

Does this hold for all integers?

Theorem [Humphreys & Prest 1.1.6 pp. 13]

Let a, b, and c be positive integers with a and b relatively prime.
Then

  1. if a divides bc then a divides c

a,b,cP[(RelativePrimes(a,b)(abc))(ac)]
  1. if a divides c and b divides c then ab divides c

a,b,cP[(RelativePrimes(a,b)(ac)(bc))(abc)]
A generalization of Euclid's lemma?

Proof [Humphreys & Prest 1.1.6 pp. 13]

Since a and b are relatively prime there are integers s and t st 1=as+bt by Bézout’s identity.
1=as+btc=cas+cbt=a(cs)+bc(t).

Let abc.
Since aa and abc it is the case that aa(cs)+bc(t)=c.
ac.

Let ac
Then there is an integer m such that am=c.
Let bc
Then there is an integer n such that bn=c.
c=cas+cbt=(bn)as+(am)bt=ab(ns)+ab(mt)=ab(ns+mt)abc.
abc.

Alternatively

Let ac.
acabcbabcbt.
Let bc.
bcabacabcas.
abcas+cbt=c.

Claim

m and n are relatively prime iff m2 and n2 are relatively prime.
Let

m=p1a1×p2a2××prarn=p1b1×p2b2××prbr

gcd(m,n)=1 implies that bi=0 whenever ai>0 and vice versa.

m2=p12a1×p22a2××pr2arn2=p12b1×p22b2××pr2br


Pythagorean Triples#

[DEFINITION - (fundamental) Pythagorean triples]

Three integers (x,y,z) which satisfy x2+y2=z2 are called a Pythagorean triple. If they are all positive and have no common factors, then they are called a fundamental triple.

x,y,zP(PythagoreanTriple(x,y,z)(x2+y2=z2))x,y,zP(FundamentalTriple(x,y,z)(PythagoreanTriple(x,y,z)RelativePrimes(x,y,z)(x,y,z>0)))RelativePrimes(x,y,z)(RelativePrimes(x,y)RelativePrimes(y,z)RelativePrimes(x,z))(x,y,z>0)((x>0)(y>0)(z>0))

Because of the symmetry in x and y, (x,y,z) and (y,x,z) are considered to be the same triple.

(3,4,5)fundamental(5,12,13)fundamental(6,8,10)=2×(3,4,5)Pythagorean


[PROBLEM]

If we want to find all Pythagorean triples, it is sufficient to first find all fundamental triples and then take multiples of the fundamental triples.

Euclid’s Formula#

[THEOREM 1.3 - Euclid’s Formula]

Given any pair of relatively prime integers (a,b) such that one of them is odd and the other even and a>b>0, then

(a2b2,2ab,a2+b2)

is a fundamental triple.

a,bP((RelativePrimes(a,b)EvenOdd(a,b)(a>b>0))FundamentalTriple(a2+b2,2ab,a2b2))

EvenOdd(a,b)((Even(a)Odd(b))(Odd(a)Even(b)))(a>b>0)((a>b)(b>0))

Furthermore, every fundamental triple is of this form.

x,y,zP(FundamentalTriple(x,y,z)a,bP(RelativePrimes(a,b)EvenOdd(a,b)(a>b>0)(x=a2+b2)(y=2ab)(z=a2b2)))

Note that the first and third terms are odd and the second term is even.

(Even(a)Odd(b))(Even(a2)Odd(b2)Even(2ab)Odd(a2b2)Odd(a2+b2))(Odd(a)Even(b))(Odd(a2)Even(b2)Even(2ab)Odd(a2b2)Odd(a2+b2))

First few fundamental triples

a=2,b=1(3,4,5)(2212,2(2)(1),22+12)=(41,2×2,4+1)a=3,b=2(5,12,13)(3222,2(3)(2),32+22)=(94,2×6,9+4)a=4,b=1(15,8,17)(4212,2(4)(1),42+12)=(161,2×4,16+1)a=4,b=3(7,24,25)(4232,2(4)(3),42+32)=(169,2×12,16+9)a=5,b=2(21,20,29)(5222,2(5)(2),52+22)=(254,2×10,25+4)a=5,b=4(9,40,41)(5242,2(5)(4),52+42)=(2516,2×20,25+16)a=6,b=1(35,12,37)(6212,2(6)(1),62+12)=(361,2×6,36+1)a=6,b=5(11,60,61)(6252,2(6)(5),62+52)=(3625,2×30,36+25)a=7,b=2(45,28,53)(7222,2(7)(2),72+22)=(494,2×14,49+4)a=7,b=4(33,56,65)(7242,2(7)(4),72+42)=(4916,2×28,49+16)a=7,b=6(13,84,85)(7262,2(7)(6),72+62)=(4936,2×42,49+36)a=8,b=1(63,16,65)(8212,2(8)(1),82+12)=(641,2×8,64+1)a=8,b=3(55,48,73)(8232,2(8)(3),82+32)=(649,2×24,64+9)a=8,b=5(39,80,89)(8252,2(8)(5),82+52)=(6425,2×40,64+25)a=8,b=7(15,112,113)(8272,2(8)(7),82+72)=(6449,2×56,64+49)a=9,b=2(77,36,85)(9222,2(9)(2),92+22)=(814,2×18,81+4)a=9,b=4(65,72,97)(9242,2(9)(4),92+42)=(8116,2×36,81+16)

Proof

1

That (a2b2,2ab,a2+b2) is a fundamental triple for any pair of relatively prime integers (a,b) such that one of them is odd and the other even and a>b>0.

Let a>b be two positive integers.

Then a2b2, 2ab, and a2+b2 are positive integers and

(a2b2)2+(2ab)2=(a2+b2)2a42a2b2+b4+4a2b2=a4+2a2b2+b4

Proofbycontradiction

2

That a triple is fundamental iff it has the form (a2b2,2ab,a2+b2) for a pair of relatively prime integers (a,b) such that one of them is odd and the other even and a>b>0.

Let (x,y,z) be a fundamental triple. Then it follows from the definition of a fundamental triple that since x, y, and z are not all even, at most one of them is even.

Assume x and y are both odd. Then x2 and y2 are each one more than a multiple of 4 and so z2 must be two more than a multiple of 4.

x=2k+1x2=(2k+1)2=4(k2+k)+1=4+1for integer=k2+k

z2=x2+y2=(4+1)+(4m+1)=4n+2for integern=+m=2(2n+1)2z22z24z2Euclid's lemma4z2modus ponensz24ncontradiction

Therefore, either x or y is even. By symmetry in x and y we can assume it is y=2m that is even.

y2=z2x2=(zx)×(z+x)m2=zx2×z+x2

Since x and z are each odd, both xz2 and x+z2 are integers and they are relatively prime because any common divisor would have to divide both their sum and their difference, but x and z have no common divisors from the definition of a fundamental triple.

zx2+z+x2=zzx2z+x2=x

pzx2pm2pm2p2m2Euclid's lemma

Since pz+x2 it must be the case that p2zx2.

Thus the factorization will only have even exponents which is another way of saying that zx2 is a perfect square. Similarly, z+x2 is a perfect square.

z+x2=a2zx2=b2

a and b are relatively prime.

Since a2+b2=z is odd, one of a or b is odd and the other is even.

x=a2b2y=z2x2=(a4+2a2b2+b4)(a42a2b2+b4)=2abz=a2+b2


The Fundamental Theorem of Arithmetic#

or the Unique Factorization Theorem for Integers

Theorem [Bressoud 1.4 pp. 5]

Factorization into primes is unique up to order.

Example [Bressoud]

There may be several ways of ordering the primes that go into a factorization, but we cannot change the primes that go into the factorization.

30=2×3×5=3×5×2=5×2×3

This does not hold for the extended integers (of the form m+n10).

6=2×3=(4+10)×(410)

Proof [Bressoud]

Sketch of the proof. It will be proved that every integer with non-unique factorization has a proper divisor with non-unique factorization. If there were integers with non-unique factorization, then there would eventually be a prime with non-unique factorization. This contradicts the definition of a prime, that a prime has no divisors other than itself and unity.

Let n be an integer with non-unique (but distinct) factorization n=p1×p2××pr=q1×q2××qr where the primes are not necessarily distinct, but where the second factorization is not simply a reordering of the first.
The prime q1 divides n and so it divides the product of the pi s.

q1nq1(p1×p2××pr)q1pipi{p1,p2,,pr}by repeated application of Euclid's lemmaq1p1by reordering of thepisq1=p1sincePrime(p1)

nq1=p2×p3××pr=q2×q3××qs

Since the factorizations of n are distinct, the factorizations of nq1 are distinct.

Therefore nq1 is a proper divisor of n with non-unique factorization.

The following theorem says that, in some sense, the primes are the multiplicative building blocks from which every (positive) integer may be produced in a unique way. Therefore positive integers, other than 1, which are not prime are referred to as composite.

Theorem [Humphreys & Prest pp. 28] Euclid’s Elements Book VII Proposition 31.

Every positive integer n greater than or equal to 2 may be written in the form n=p1p2pr where the integers n=p1,p2,,pr are prime numbers (which need not be distinct) and r1. This factorization is unique in the sense that if also n=q1q2qs where q1,q2,,qs are primes, then r=s and we can renumber the qi so that qi=pi for i=1,2,,r. In other words, up to rearrangement, there is just one way of writing a positive integer as a product of primes.

The idea of the following proof is as follows. If n is not prime then factor it as ab. If a is not prime then factor it and if b is not prime then factor it. Continue splitting any factors which are not prime. This cannot go on forever because the integers we produce are decreasing and each factorization gives strictly smaller numbers: the process eventually stops with a product of primes.

Proofoftheexistenceofthedecomposition [Humphreys & Prest pp. 28-29]

Show by strong induction that every positive integer greater than or equal to 2 has a factorization as a product of primes.

Base Case

n=2 is prime.

For n>2 either n is prime in which case n has a factorization (with just one factor) of the required form or n can be written as a product ab where 1<a<n and 1<b<n.

Induction Step

Induction Hypothesis: Let a and b both have factorizations into primes.
We obtain a factorization of n as a product of primes by juxtaposing the factorizations of a and b.

Therefore every positive integer greater than or equal to 2 has a factorization as a product of primes.

Examples [Humphreys & Prest pp. 29-30]

4=226=21×318=23=(2)×(2×2)=2×49=20×3210=21×30×5112=22×31=(2)×(2×3)=2×6=(2×2)×(3)=4×314=21×30×50×7115=20×31×5116=24=(2)×(2×2×2)=2×8=(2×2)×(2×2)=4×418=21×32=(2)×(3×3)=2×9=(2×3)×(3)=6×320=22×30×51=(2)×(2×5)=2×10=(2×2)×(5)=4×521=20×31×50×7122=21×30×50×70×11124=23×31=(2)×(2×2×3)=2×12=(2×2)×(2×3)=4×6=(2×2×2)×(3)=8×325=20×30×5226=21×30×50×70×110×13128=22×30×50×71=(2)×(2×7)=2×14=(2×2)×(7)=4×730=21×31×51=(2)×(3×5)=2×15=(2×3)×(5)=6×572=23×32=(2)×(2×2×3×3)=2×36=(2×2)×(2×3×3)=4×18=(2×2×2)×(3×3)=8×9=(2×2×2×3)×(3)=24×3588=22×31×50×72=(2)×(2×3×7×7)=2×294=(3)×(2×2×7×7)=3×196=(7)×(2×2×3×7)=7×84=(2×2)×(3×7×7)=4×147=(2×3)×(2×7×7)=6×98=(2×7)×(2×3×7)=14×42=(2×2×3)×(7×7)=12×49=(2×2×7)×(3×7)=28×21

This proof is based on the observation that if a prime divides one side of the equation then it divides the other, so we can cancel it from each side. This process eventually stops with the equation 1=1. Therefore there must have been the same number of primes, and indeed the same primes, on each side of the original equation.

Proofofuniqueness [Humphreys & Prest pp. 28-29]

Use the standard form of mathematical induction on the number r of prime factors to show that any positive integer which has a factorization into a product of r primes has a unique factorization up to rearrangement.

Base Case

Let n=q1q2qs be a prime.
If we had s2 then n would have distinct divisors 1,q1,q1q2 contradicting that it is prime.
Therefore s=1.

Induction Step

Induction Hypothesis: Any positive integer greater than 2 which has a factorization into r1 primes has a unique factorization.
Let n=p1p2pr=q1q2qs be two prime factorizations of n.
p1 divides n implies that p1 divides one of q1,q2,,qs.
We can renumber the qi so that it is q1 that p1 divides.
It must be the case that p1=q1 since both p1 and q1 are prime.
Therefore p2p3pr=q2q3qs.
The integer p2p3pr is a product of r1 primes.
Therefore r1=s1r=s and after renumbering pi=qi for i=2,,r.
Since we already have p1=q1 we have pi=qi for i=1,2,,r.

Therefore any positive integer has a unique factorization up to rearrangement.


GCD and LCM as prime factorizations#

Corollary [Humphreys & Prest 1.3.5 pp. 30-31]

Let a and b be positive integers.
Let a=p1n1p2n2prnr and b=p1m1p2m2prmr be the prime factorizations of a and b where p1,p2,,pr are distinct primes and n1,n2,,nr,m1,m2,,mr are non-negative integers (some perhaps zero in order to allow a common list of primes to be used).
Then the greatest common divisor d of a and b is given by d=p1k1p2k2prkr where for each i, ki is the smaller of ni and mi, and the least common multiple f of a and b is given by f=p1t1p2t2prtr where for each i, ti is the larger of ni and mi.

Proof [Humphreys & Prest pp. 31]

Examples [Humphreys & Prest pp. 31-32]

2 and 3

a=2=21×30b=3=20×31gcd(a,b)=1=20×30lcm(a,b)=6=21×31

2 and 4

a=2=21b=4=22gcd(a,b)=2=21lcm(a,b)=4=22

56 and 84

a=56=23×30×71b=84=22×31×71gcd(a,b)=28=22×30×71lcm(a,b)=168=23×31×71

135 and 639

a=135=33×51×710b=639=32×50×711gcd(a,b)=9=32×50×710lcm(a,b)=9585=33×51×711

Fermat Primes#

Claim

If 2n+1 is prime where n1 then n must be of the form 2k for some positive integer k.

F(k)=22k+1F(0)=220+1=3primeF(1)=221+1=5primeF(2)=222+1=17primeF(3)=223+1=257primeF(4)=224+1=65,537primeF(5)=225+1=4,294,967,297compositeF(6)=226+1=18,446,744,073,709,551,617composite

Mersenne Primes#

Claim

If 2n1 is prime then n is prime.

M(n)=2n1M(2)=221=3primeM(3)=231=7primeM(5)=251=31primeM(7)=271=127primeM(11)=2111=2,047=23×89compositeM(13)=2131=8,191primeM(17)=2171=131,071primeM(19)=2191=524,287primeM(23)=2231=8,388,607=47×178,481compositeM(29)=2291=536,870,911=233×1,103×2,089compositeM(31)=2311=2,147,483,647primeM(37)=2371=137,438,953,471=?×?compositeM(41)=M(43)=M(47)=M(53)=M(59)=M(61)=M(71)=M(73)=M(79)=M(83)=M(89)=M(97)=M(13,466,917)=213,466,9171=4,000,000-digit integer (2001)M(82,589,933)=282,589,9331=24,862,048-digit integer (2018)

Goldbach’s Conjecture#

Conjecture

Every even number greater than two can be expressed as the sum of two primes.

nP[(Even(n)(n>2))p,qP[Prime(p)Prime(q)(n=p+q)]]

Examples

4=2+2 is the only even integer greater than 2 which is the sum of the prime 2 and another prime (in this case, 2 too).

6=38=3510=512=5714=716=31351118=51371120=31771322=3195171124=519717111326=3237191328=523111730=72311191317

Twin Primes Conjecture#

There are infinitely many pairs (x,y) s.t. x and y are both prime and y=x+2.

x,yP(TwinPrimes(x,y)(Prime(x)Prime(y)(y=x+2)))x,yP(TwinPrimes(x,y)a,bP((a>x)TwinPrimes(a,b)))

Bounded Gap Theorem#

There are infinitely many pairs of primes that differ by at most 70,000,000.

x,yP(BoundedGapPrimes(x,y)(Prime(x)Prime(y)(abs(yx)70,000,000)))x,yP(BoundedGapPrimes(x,y)a,bP((a>x)BoundedGapPrimes(a,b)))