Two strong pseudoprimes to twenty prime bases

6 of 8 main results in Lean (75%); 2 of 8 certificate-only (Propositions 7 and 8: the external C-sieve searches over (10³⁶, 10³⁷] and over 7 ratios, not required for Theorem 1); 0 written-only; 1 open conjecture (Zhang minimality) · AI-generated and directed by Tyler B. Hughes · No human mathematician has yet refereed the proof.

A fast test tries to tell prime numbers from the rest, using a few small numbers called bases. Two 37-digit numbers that are not prime pass it with each of the 20 smallest primes as base, so those 20 bases are fooled by a number below 2¹²¹.

For p₁ = 1113813905784150541 and p₂ = 1726253494836549181 the numbers p₁, 2p₁ − 1, p₂ and 2p₂ − 1 are all prime, and each of n₁ = p₁(2p₁ − 1) = 2481162833436289154832260656117034821 and n₂ = p₂(2p₂ − 1) = 5959902256870799858089729225626992341 lies above 10³⁶ and at most 10³⁷, is not prime, passes the strong test for each of the 20 smallest primes 2, 3, …, 71 as base, fails it for base 73 and still passes the Fermat test 73ⁿ⁻¹ ≡ 1 (mod n); since 2¹²⁰ < n₁ < 2¹²¹ and 2¹²² < n₂ < 2¹²³, the smallest number ψ₂₀ that is not prime and passes for those 20 bases satisfies ψ₂₀ ≤ n₁ < 2¹²¹, and ψₖ ≤ n₁ for every k ≤ 20.

Computers often check whether a large number is prime with this strong test, and Sorenson and Webster (2017) showed that the 12 smallest primes as bases are never all fooled by a number below 2⁶⁴, the size of everyday 64-bit arithmetic. These two numbers are below 2¹²⁸, so the 20 smallest primes are not enough for 128-bit arithmetic. Bleichenbacher (1996) had listed a 41-digit number that fools the 21 smallest primes, and Zhang (2007) studied numbers of the shape p(2p − 1).

A small number that fools base 2

The strong test for an odd number n ≥ 3 and a base a: write n − 1 = 2ˢ·d with d odd. The number passes when aᵈ leaves remainder 1 on division by n, or when one of aᵈ, a²ᵈ, a⁴ᵈ, …, up to the power 2ˢ⁻¹·d, leaves remainder n − 1.

Take n = 2047 = 23 · 89, which is not prime. Then n − 1 = 2046 = 2 · 1023, so s = 1 and d = 1023.

Base 2: 2¹¹ = 2048 = 2047 + 1, so 2¹¹ leaves remainder 1. Since 1023 = 11 · 93, 2¹⁰²³ = (2¹¹)⁹³ also leaves remainder 1. So 2047 passes for base 2, although it is not prime: it fools base 2.

Base 3: 3¹⁰²³ leaves remainder 1565 (a computer finds this at once). That is neither 1 nor 2046, so 2047 fails for base 3, and base 3 catches it.

Lean checks both facts. The two numbers of this proof play the same trick on all 20 bases 2, 3, 5, …, 71 at once, and are caught only at 73.

The strong test, ψₖ and the K2 shape

A number n passes the strong test for a base a when n is odd, at least 3, and, writing n − 1 = 2ˢ·d with d odd, either aᵈ leaves remainder 1 on division by n or one of aᵈ, a²ᵈ, a⁴ᵈ, …, up to aᵈ squared s − 1 times, leaves remainder n − 1. Passing implies the Fermat test aⁿ⁻¹ ≡ 1 (mod n). ψₖ is the smallest number that is not prime yet passes for each of the k smallest primes, so any one such number is an upper bound for ψₖ. A K2 number is p(2p − 1) with p and 2p − 1 both prime, and it is never prime itself.

  • n passes the strong test for base a
  • n is not prime and passes for the k smallest primes
  • The threshold ψₖ
  • n is the K2 number of p
  • n passes the strong test for base a
  • n fools base a
  • n is not prime and passes for the k smallest primes
  • The threshold ψₖ
  • n is the K2 number of p
  • Passing the strong test implies passing the Fermat test

    If n passes the strong test for a, then aⁿ⁻¹ ≡ 1 (mod n).

    theorem SpspPsi20.isStrongProbablePrime_implies_fermat {n : ℕ} {a : ℕ} (h : IsStrongProbablePrime n a) :
      a ^ (n - 1) ≡ 1 [MOD n]
  • Any example bounds ψₖ from above

    If n is not prime and passes for the k smallest primes, then ψₖ ≤ n.

    theorem SpspPsi20.psi_le_of_spsp {k : ℕ} {n : ℕ} (h : IsFirstKPrimesStrongPseudoprime k n) :
      psi k ≤ n
  • ψⱼ ≤ ψₖ when j ≤ k, if some number passes for the k smallest primes
  • Passing for k primes implies passing for fewer
  • A K2 number is never prime
  • The strong test may use any split n − 1 = 2ˢ·d
  • Splitting off the factors 2 can be done only one way
  • Every positive number is a power of 2 times an odd number, in one way
  • (n − 1)² ≡ 1 (mod n) when n ≥ 2
  • 2047 fools base 2

Arithmetic that Lean can run

Raising a 37-digit number to a 37-digit power is done by repeated squaring, keeping only remainders, and Lean proves that this method gives the true remainder. A Pratt certificate proves a number p prime: the prime factors of p − 1 and one base a with aᵖ⁻¹ leaving remainder 1, while a to the power (p − 1)/q does not for any prime factor q. Lean also proves that the strong test can be run as a yes-or-no computation, and that the primes numbered 0 to 20, counting from 0, are 2, 3, 5, …, 73.

  • A Pratt certificate proves a number prime

    Let p ≥ 2 and take a list of primes whose product is p − 1. If aᵖ⁻¹ leaves remainder 1 on division by p, and a to the power (p − 1)/q does not for any q in the list, both computed by repeated squaring with p − 1 < 2ᵏ for the step limit k, then p is prime.

  • The prime numbered 20, counting from 0, is 73

    Counting 2 as prime number 0, prime number 20 is 73.

    theorem SpspPsi20Challenge.nth_prime_20 :
      Nat.nth Nat.Prime 20 = 73
  • The computation answers yes exactly when n passes

    For odd n ≥ 3, n − 1 = 2ˢ·d with d odd, and n − 1 < 2ᵏ for the step limit k, the computation says yes exactly when n passes the strong test for a.

  • Checking a list of bases at once

    If the computation says yes for each of the k smallest primes, with k ≤ 21 and the conditions on n, d, s and the step limit, then n passes the strong test for each prime numbered below k.

  • The primes numbered 0 to 20 are 2 to 73

    For each i from 0 to 20, prime number i (counting from 0) is entry i of the list 2, 3, …, 73.

  • The list 2, 3, 5, …, 73
  • The strong test as a yes-or-no computation
  • The repeated-squaring loop
  • Powers by repeated squaring with a step limit
  • The step-limited power is right when e < 2 to the step limit

    If e < 2ᵏ, where k is the step limit, the computation gives exactly aᵉ mod m.

  • The number of primes below n

Two 37-digit numbers that pass 20 bases

Pratt certificates prove p₁, 2p₁ − 1, p₂ and 2p₂ − 1 prime, so n₁ and n₂ are K2 numbers and not prime. For both, n − 1 is 4 times an odd number, and Lean itself runs the strong test as arithmetic for the 20 primes 2 to 71 (all pass) and for 73 (it fails, although the Fermat test for 73 passes). So ψ₂₀ ≤ n₁, and n₁ lies between 2¹²⁰ and 2¹²¹.

  • Two 37-digit numbers that fool the 20 smallest primes

    n₁ and n₂ are K2 numbers, each above 10³⁶ and at most 10³⁷, with 2¹²⁰ < n₁ < 2¹²¹ and 2¹²² < n₂ < 2¹²³. Each is not prime, passes the strong test for the 20 smallest primes, fails it for 73, and still has 73ⁿ⁻¹ ≡ 1 (mod n). So ψ₂₀ ≤ n₁, ψ₂₀ < 2¹²¹, and ψₖ ≤ n₁ for every k ≤ 20.

    theorem SpspPsi20Challenge.main_two_witnesses :
      IsK2Number n₁ p₁ ∧
      (10 ^ 36 < n₁ ∧ n₁ ≤ 10 ^ 37) ∧
        (2 ^ 120 < n₁ ∧ n₁ < 2 ^ 121) ∧
          IsFirstKPrimesStrongPseudoprime 20 n₁ ∧
            ¬IsStrongProbablePrime n₁ 73 ∧
              73 ^ (n₁ - 1) ≡ 1 [MOD n₁] ∧
                IsK2Number n₂ p₂ ∧
                  (10 ^ 36 < n₂ ∧ n₂ ≤ 10 ^ 37) ∧
                    (2 ^ 122 < n₂ ∧ n₂ < 2 ^ 123) ∧
                      IsFirstKPrimesStrongPseudoprime 20 n₂ ∧
                        ¬IsStrongProbablePrime n₂ 73 ∧
                          73 ^ (n₂ - 1) ≡ 1 [MOD n₂] ∧ psi 20 ≤ n₁ ∧ psi 20 < 2 ^ 121 ∧ ∀ k ≤ 20, psi k ≤ n₁
  • ψ₂₀ is at most n₁

    The smallest number that is not prime and passes for the 20 smallest primes is at most n₁ = 2481162833436289154832260656117034821.

    theorem SpspPsi20Challenge.psi_20_le_n₁ :
      psi 20 ≤ n₁
  • Two 37-digit numbers that fool the 20 smallest primes, in the library's own words

    The same statement as the main theorem, about the library's n₁ and n₂.

  • ψ₂₀ is at most n₁

    ψ₂₀ ≤ n₁ = 2481162833436289154832260656117034821.

    theorem SpspPsi20.psi_20_le_n₁ :
      psi 20 ≤ n₁
  • n₁ passes for the 20 smallest primes

    n₁ is odd, at least 3 and not prime, and passes the strong test for each of 2, 3, 5, …, 71.

  • n₂ passes for the 20 smallest primes

    n₂ is odd, at least 3 and not prime, and passes the strong test for each of 2, 3, 5, …, 71.

  • n₁ fails the strong test for 73

    The strong test for base 73 catches n₁.

  • n₂ fails the strong test for 73

    The strong test for base 73 catches n₂.

  • p₁ is prime

    A Pratt certificate with base 2 and p₁ − 1 = 2²·3·5·18563565096402509.

  • q₁ = 2p₁ − 1 is prime

    A Pratt certificate with base 101 and q₁ − 1 = 2³·3·5·18563565096402509.

  • p₂ is prime

    A Pratt certificate with base 10 and p₂ − 1 = 2²·3·5·181·158955202102813.

  • q₂ = 2p₂ − 1 is prime

    A Pratt certificate with base 89 and q₂ − 1 = 2³·3·5·181·158955202102813.

  • The prime p₁
  • The prime q₁ = 2p₁ − 1
  • The number n₁ = p₁·q₁
  • The prime p₂
  • The prime q₂ = 2p₂ − 1
  • The number n₂ = p₂·q₂
  • The statement's p₁ is the library's p₁
  • The statement's n₁ is the library's n₁
  • The statement's p₂ is the library's p₂
  • The statement's n₂ is the library's n₂
  • The prime p₁
  • The prime q₁ = 2p₁ − 1
  • The number n₁ = p₁·q₁
  • The prime p₂
  • The prime q₂ = 2p₂ − 1
  • The number n₂ = p₂·q₂
  • The odd part d₁ of n₁ − 1
  • The odd part d₂ of n₂ − 1

When a K2 number passes for a base

Take n = p(2p − 1) with p an odd prime and 2p − 1 prime, and a base b sharing no factor with n. Then n passes the Fermat test for b exactly when b is a square remainder modulo 2p − 1. It passes the strong test for b exactly when the orders of b modulo p and modulo 2p − 1 contain the same number of factors 2, or, said with levels, when the level of b modulo 2p − 1 is one more than its level modulo p.

  • The Fermat and strong tests for a K2 number

    Let n = p(2p − 1) be a K2 number with p odd, and let b share no factor with n. Then bⁿ⁻¹ ≡ 1 (mod n) exactly when (b/(2p − 1)) = 1. And n passes the strong test for b exactly when the orders of b modulo p and modulo 2p − 1 have the same 2-count, and exactly when the level of b modulo 2p − 1 is one more than its level modulo p.

    theorem SpspPsi20Challenge.k2_fermat_and_sprp_criteria {n : ℕ} {p : ℕ} {b : ℕ} (hk2 : IsK2Number n p) (hp_odd : Odd p) [Fact (Nat.Prime (2 * p - 1))] (hcop : b.Coprime n) :
      (b ^ (n - 1) ≡ 1 [MOD n] ↔ legendreSym (2 * p - 1) ↑b = 1) ∧
      (IsStrongProbablePrime n b ↔ padicValNat 2 (orderOf ↑b) = padicValNat 2 (orderOf ↑b)) ∧
        (IsStrongProbablePrime n b ↔ twoPowLevel (2 * p - 1) b = twoPowLevel p b + 1)
  • The Fermat and strong tests for a K2 number, in the library's own words

    The same statement as the main result on the Fermat and strong tests, about the library's definitions.

  • For a K2 number, passing means equal 2-counts of the orders

    If p is odd and b shares no factor with n = p(2p − 1), then n passes the strong test for b exactly when the orders of b modulo p and modulo 2p − 1 have the same 2-count.

  • For a K2 number, passing means the levels differ by one

    If p is odd and b shares no factor with n = p(2p − 1), then n passes the strong test for b exactly when the level of b modulo 2p − 1 is one more than the level modulo p.

  • For a K2 number, the Fermat test is a square-remainder test

    If b shares no factor with n = p(2p − 1), then bⁿ⁻¹ ≡ 1 (mod n) exactly when (b/(2p − 1)) = 1.

  • For a K2 number, the Fermat test reduces to bᵖ⁻¹ modulo 2p − 1

    If b shares no factor with n = p(2p − 1), then bⁿ⁻¹ ≡ 1 (mod n) exactly when bᵖ⁻¹ ≡ 1 (mod 2p − 1).

  • Passing for c forces equal 2-counts of the orders modulo p and q

    If p and q are odd primes, n = pq, and n passes the strong test for c, then the orders of c modulo p and modulo q have the same 2-count.

  • The level of b modulo r
  • The level of b modulo r
  • Level plus order's 2-count equals v₂(r − 1)

    For a prime r and b sharing no factor with r, the level of b modulo r plus the 2-count of the order of b modulo r equals v₂(r − 1).

  • Splitting off the factors 2 in n − 1 and in 2p − 2

    For a K2 number with p − 1 = 2ᵉ·m and m odd, n − 1 = 2ᵉ·((2p + 1)m) with (2p + 1)m odd, and (2p − 1) − 1 = 2ᵉ⁺¹·m.

How many bases a K2 number fools

For n = p(2p − 1) with p an odd prime and 2p − 1 prime, write e for the number of factors 2 in p − 1. Among the bases from 0 to n − 1 that share no factor with n, the share that n fools is exactly (1 + 2·4⁻ᵉ)/6. When p leaves remainder 3 on division by 4 the share is 1/4 and base 2 always catches n. When n passes for base 2 the share is at most 3/16, and it is exactly 3/16 when e = 2, as for n₁ and n₂ (Lean does not state this case separately).

  • The share of strong liars of a K2 number

    Let n = p(2p − 1) be a K2 number with p odd, and e the 2-count of p − 1. The strong liars of n make up exactly (1 + 2·4⁻ᵉ)/6 of the φ(n) bases. If p leaves remainder 3 on division by 4, the share is 1/4 and n fails for base 2. If n passes for base 2, then p leaves remainder 1 on division by 4, 2p − 1 leaves remainder 1 on division by 8, n leaves remainder 1 on division by 4, and the share is at most 3/16. If e = 2, the share is exactly 3/16.

    theorem SpspPsi20Challenge.k2_strongLiar_share_and_base2_cap {n : ℕ} {p : ℕ} (hk2 : IsK2Number n p) (hp_odd : Odd p) :
      ↑(strongLiarCount n) / ↑n.totient = (1 + 2 * 4 ^ (-↑(padicValNat 2 (p - 1)))) / 6 ∧
      (p % 4 = 3 → ↑(strongLiarCount n) / ↑n.totient = 1 / 4 ∧ ¬IsStrongProbablePrime n 2) ∧
        (IsStrongProbablePrime n 2 →
            p % 4 = 1 ∧ (2 * p - 1) % 8 = 1 ∧ n % 4 = 1 ∧ ↑(strongLiarCount n) / ↑n.totient ≤ 3 / 16) ∧
          (padicValNat 2 (p - 1) = 2 → ↑(strongLiarCount n) / ↑n.totient = 3 / 16)
  • The share of strong liars of a K2 number, in the library's own words

    The same statement as the main result on the share of strong liars, about the library's definitions.

  • The share of strong liars is (1 + 2·4⁻ᵉ)/6

    For a K2 number with p odd and e = v₂(p − 1), strong liars make up (1 + 2·4⁻ᵉ)/6 of the φ(n) bases.

  • 3 times the number of strong liars is (4ᵉ + 2)m²

    For a K2 number with p odd and p − 1 = 2ᵉ·m, m odd, three times the number of strong liars equals (4ᵉ + 2)·m².

  • A K2 number that passes base 2 has share at most 3/16

    If a K2 number passes for base 2, its share of strong liars is at most 3/16.

  • Base 2 catches a K2 number when p leaves remainder 3 on division by 4

    If p ≡ 3 (mod 4), then the K2 number p(2p − 1) fails the strong test for 2.

  • Passing base 2 forces remainders of p, 2p − 1 and n

    If a K2 number n passes for base 2, then p ≡ 1 (mod 4), 2p − 1 ≡ 1 (mod 8) and n ≡ 1 (mod 4).

  • The strong liars of n
  • The number of strong liars of n
  • The strong liars of n
  • The number of strong liars of n

Counting the remainders a search can keep

For an odd prime b, the remainders x from 1 to b − 1 for which 2x − 1 is a square remainder modulo b number A(b) = (b − 1)/2 when b leaves remainder 3 on division by 4 and (b − 3)/2 otherwise; for b = 7 they are 1, 5 and 6. Over the ten primes 3 to 31 the products are 4·3·5·…·31 = 401,120,980,260 and A(3)·A(5)·…·A(31) = 10,135,125. Lean also proves that the Jacobsthal sum of χ(x)·χ(2x − 1) equals −(2/b), and from it exactly how many of those A(b) remainders x are square remainders themselves.

  • The count A(b) and the two wheel products

    For every odd prime b, the number of remainders x modulo b with x ≠ 0 and 2x − 1 a square remainder modulo b is (b − 1)/2 when b leaves remainder 3 on division by 4 and (b − 3)/2 otherwise. Also 4·3·5·7·11·13·17·19·23·29·31 = 401120980260, and the ten counts for 3 to 31 multiply to 10135125.

    theorem SpspPsi20Challenge.sieve_admissible_and_wheel {b : ℕ} [Fact (Nat.Prime b)] (hb_odd : Odd b) :
      ({x | x ≠ 0 ∧ (quadraticChar (ZMod b)) (2 * x - 1) = 1}.card = if b % 4 = 3 then (b - 1) / 2 else (b - 3) / 2) ∧
      4 * [3, 5, 7, 11, 13, 17, 19, 23, 29, 31].prod = 401120980260 ∧
        (List.map (fun q => if q % 4 = 3 then (q - 1) / 2 else (q - 3) / 2) [3, 5, 7, 11, 13, 17, 19, 23, 29, 31]).prod =
          10135125
  • The Jacobsthal sum and the split by square remainders

    For every odd prime b, the sum over all x modulo b of χ(x)·χ(2x − 1) is −(2/b). Among the x with χ(2x − 1) = 1, four times the number with χ(x) = −1 is b − 2 − (−1/b) + 2(2/b), and four times the number with χ(x) = 1 is b − 2 − (−1/b) − 2(2/b).

  • The count A(b) and the two wheel products, in the library's own words

    The same statement as the main result on A(b) and the wheel products.

  • The Jacobsthal sum and the split by square remainders, in the library's own words

    The same statement as the main result on the Jacobsthal sum.

  • The count A(b) of remainders to keep

    For an odd prime b, the number of x ≠ 0 modulo b with 2x − 1 a nonzero square remainder is (b − 1)/2 when b ≡ 3 (mod 4) and (b − 3)/2 otherwise.

  • The Jacobsthal sum is −(2/b)

    For an odd prime b, adding χ(x)·χ(2x − 1) over all x modulo b gives −(2/b).

  • The sum of χ(u² − 1) is −1

    For an odd prime b, adding χ(u² − 1) over all u modulo b gives −1.

  • The split of the kept remainders by whether x is a square remainder

    For an odd prime b, among the x with χ(2x − 1) = 1, four times the number with χ(x) = −1 is b − 2 − (−1/b) + 2(2/b), and four times the number with χ(x) = 1 is b − 2 − (−1/b) − 2(2/b).

Other shapes than p(2p − 1)

Take odd primes p and q with b(q − 1) = a(p − 1) for whole numbers a and b that share no factor, b ≥ 1, and suppose n = pq passes the strong test for a base c that shares no factor with n. If a and b contain the same number of factors 2, then (c/p) = (c/q); if a contains more, then (c/q) = 1; if b contains more, then (c/p) = 1. The K2 shape is the case a = 2, b = 1.

  • A rule for products pq with b(q − 1) = a(p − 1)

    Let p and q be odd primes, and a and b whole numbers that share no factor, with b ≥ 1 and b(q − 1) = a(p − 1). Let n = pq, and let c be a base that shares no factor with n and for which n passes the strong test. If a and b have the same 2-count, then (c/p) = (c/q). If the 2-count of b is smaller, then (c/q) = 1. If the 2-count of a is smaller, then (c/p) = 1.

  • The rule for b(q − 1) = a(p − 1)

    The same rule, stated with b(q − 1) = a(p − 1), b ≥ 1 and a and b sharing no factor, as in the paper.

  • The rule for p − 1 = bm and q − 1 = am

    For odd primes p and q with p − 1 = bm, q − 1 = am, m ≥ 1, n = pq, and a base c sharing no factor with n for which n passes, the three cases of the rule for b(q − 1) = a(p − 1) hold.

  • (c/r) = −1 exactly when the order of c has the largest possible 2-count

    For an odd prime r and c sharing no factor with r, (c/r) = −1 exactly when the order of c modulo r has 2-count v₂(r − 1).

  • (c/r) = 1 exactly when the order of c has a smaller 2-count

    For an odd prime r and c sharing no factor with r, (c/r) = 1 exactly when the order's 2-count is below v₂(r − 1).