Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions OutcastsMathLab.lean
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
import OutcastsMathLab.Problems.P000_VerifierSmoke.Proof
import OutcastsMathLab.Research.JacobiObstruction
import OutcastsMathLab.Research.PsiObstruction
import OutcastsMathLab.Research.InvolutionBound
import OutcastsMathLab.Research.DeterministicFailure
import OutcastsMathLab.Research.HardPrimes20261005
106 changes: 106 additions & 0 deletions OutcastsMathLab/Research/DeterministicFailure.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import Mathlib.Data.Nat.Prime.Basic
import Mathlib.Data.Nat.GCD.Basic
import Mathlib.Tactic.NormNum.Prime

/-!
# Finite negative certificates for Dahan's divisor criterion

This module provides the general lemmas behind a *finite negative certificate*:
given the prime factorization `a p + u = ∏ qᵢ^{eᵢ}`, every divisor is a sub-product
`∏ qᵢ^{fᵢ}` with `fᵢ ≤ eᵢ`, so "no divisor `s` has `4au ∣ s + 1`" reduces to a finite
check over the sub-products, decided by `decide`. Primality of the factors is
discharged by `norm_num`.

Nothing here is a new mathematical result; it is the Lean form of the "deterministic
failure" rows of the Outcasts failure atlas (a pair `(a, u)` whose `a p + u` is
small primes times at most one large prime fails for a reason that is fully
visible in the factorization). The concrete certificates live in
`HardPrimes20261005.lean`, generated by `Research/DeterministicFailure/gen_certificates.py`.
-/

namespace OutcastsMathLab.Research.DeterministicFailure

/-- Dahan v1 Theorem 3.9(ii): `s ∣ a p + u` and `s ≡ -1 (mod 4 a u)`. -/
def DivisorWitness (p a u s : ℕ) : Prop :=
s ∣ a * p + u ∧ 4 * a * u ∣ s + 1

/-- `∏ qᵢ^{eᵢ}` for a list of `(qᵢ, eᵢ)`. -/
def prodPow (L : List (ℕ × ℕ)) : ℕ := (L.map fun qe => qe.1 ^ qe.2).prod

/-- All sub-products `∏ qᵢ^{fᵢ}` with `fᵢ ≤ eᵢ`. -/
def subProducts : List (ℕ × ℕ) → List ℕ
| [] => [1]
| (q, e) :: L => (subProducts L).flatMap fun d => (List.range (e + 1)).map fun f => d * q ^ f

/-- The certificate check: no sub-product `d` has `m ∣ d + 1`. -/
def noWitnessCert (L : List (ℕ × ℕ)) (m : ℕ) : Bool :=
(subProducts L).all fun d => (d + 1) % m != 0

theorem prodPow_nil : prodPow [] = 1 := rfl

theorem prodPow_cons (q e : ℕ) (L : List (ℕ × ℕ)) :
prodPow ((q, e) :: L) = q ^ e * prodPow L := by
simp [prodPow]

/-- Splitting a divisor of a product in `ℕ`: `s ∣ m n → s = y z` with `y ∣ m`, `z ∣ n`. -/
theorem dvd_mul_split {s m n : ℕ} (h : s ∣ m * n) : ∃ y z, y ∣ m ∧ z ∣ n ∧ s = y * z := by
rcases Nat.eq_zero_or_pos m with rfl | hm
· exact ⟨s, 1, dvd_zero s, one_dvd n, (mul_one s).symm⟩
· obtain ⟨z, hz⟩ := Nat.gcd_dvd_left s m
obtain ⟨m', hm'⟩ := Nat.gcd_dvd_right s m
have hy : 0 < Nat.gcd s m := Nat.gcd_pos_of_pos_right s hm
refine ⟨Nat.gcd s m, z, Nat.gcd_dvd_right s m, ?_, hz⟩
have h1 : Nat.gcd s m * z ∣ Nat.gcd s m * (m' * n) := by
rw [← hz, ← mul_assoc, ← hm']
exact h
have h2 : z ∣ m' * n := Nat.dvd_of_mul_dvd_mul_left hy h1
have h3 : Nat.Coprime z m' := by
have := Nat.gcd_mul_left (Nat.gcd s m) z m'
rw [← hz, ← hm'] at this
exact Nat.eq_of_mul_eq_mul_left hy (by rw [mul_one]; exact this.symm)
exact (Nat.Coprime.dvd_mul_left h3).mp h2

/-- Every divisor of `∏ qᵢ^{eᵢ}` (all `qᵢ` prime) is one of the sub-products. -/
theorem mem_subProducts_of_dvd :
∀ (L : List (ℕ × ℕ)), (∀ qe ∈ L, Nat.Prime qe.1) →
∀ s, s ∣ prodPow L → s ∈ subProducts L
| [], _, s, hs => by
rw [prodPow_nil] at hs
simp [subProducts, Nat.dvd_one.mp hs]
| (q, e) :: L, hL, s, hs => by
rw [prodPow_cons] at hs
obtain ⟨y, z, hy, hz, rfl⟩ := dvd_mul_split hs
have hq : Nat.Prime q := hL (q, e) (by simp)
obtain ⟨f, hf, rfl⟩ := (Nat.dvd_prime_pow hq).mp hy
have hz' := mem_subProducts_of_dvd L (fun qe h => hL qe (by simp [h])) z hz
simp only [subProducts, List.mem_flatMap, List.mem_map, List.mem_range]
exact ⟨z, hz', f, Nat.lt_succ_of_le hf, mul_comm _ _⟩

/-- Soundness of the certificate. -/
theorem no_witness_of_cert {L : List (ℕ × ℕ)} (hL : ∀ qe ∈ L, Nat.Prime qe.1) {m : ℕ}
(hc : noWitnessCert L m = true) : ∀ s, s ∣ prodPow L → ¬ m ∣ s + 1 := by
intro s hs hdvd
have hmem := mem_subProducts_of_dvd L hL s hs
have h := List.all_eq_true.mp hc s hmem
rw [Nat.mod_eq_zero_of_dvd hdvd] at h
simp at h

/-- The form used by the generated certificates: factorization + primality + check
give "no Dahan witness at `(a, u)` for `p`". -/
theorem no_divisorWitness_of_cert {p a u : ℕ} {L : List (ℕ × ℕ)}
(hL : ∀ qe ∈ L, Nat.Prime qe.1) (hfac : a * p + u = prodPow L)
(hc : noWitnessCert L (4 * a * u) = true) : ∀ s, ¬ DivisorWitness p a u s := by
rintro s ⟨hs, hdvd⟩
rw [hfac] at hs
exact no_witness_of_cert hL hc s hs hdvd

/-- Sanity check on a positive case (Dahan Prop 3.13): `2 · 409 + 1 = 819 = 3² · 7 · 13` has
the witness `s = 7` (`8 ∣ 7 + 1`), so the check must reject this factorization. -/
example : noWitnessCert [(3, 2), (7, 1), (13, 1)] 8 = false := by decide

#print axioms dvd_mul_split
#print axioms mem_subProducts_of_dvd
#print axioms no_witness_of_cert
#print axioms no_divisorWitness_of_cert

end OutcastsMathLab.Research.DeterministicFailure
Loading
Loading