Lean / Reader
Lean readerPowerful.lean
Lean 4 Web has Mathlib, so it can check files that import only Mathlib. This one also imports Certificates, which it does not have: you can read it there, but it will not check. Build the project itself to check it.
import Certificatesnamespace Powerfulabbrev Ratio := Nat × Natabbrev Box := Array (Nat × Nat)def times (a b : Ratio) : Ratio := (a.1*b.1,a.2*b.2)def localEdge (p ell d cap : Nat) (upper : Bool) : Ratio :=if upper && d==cap then (p,p-1) elselet g := (p^(d+1)-1)/(p-1)if !upper && ell==cap then (g,p^d) else (g*p^ell+1,p^(d+ell))def isPrimeSmall (n : Nat) : Bool :=n≥2 && ((List.range 44).all fun i => decide (i<2 ∨ n < i*i ∨ n%i≠0))def fourthChoices (lower : Nat) : Array Nat :=((List.range 2032).filter fun n => n>lower && isPrimeSmall n).toArraydef boxValue (ps primes : Array Nat) (box : Box) (upper : Bool) : Ratio := Id.run dolet mut v : Ratio := (1,1)for i in [:4] dolet p := if i<3 then ps[i]! elseprimes[if upper then box[5]!.1 else box[5]!.2]!let e := if upper then box[0]!.1 else box[0]!.2let d := if upper then box[i+1]!.2 else box[i+1]!.1v := times v (localEdge p e d 18 upper)return vdef separated (ps primes : Array Nat) (box : Box) : Bool :=let l := boxValue ps primes box falselet h := boxValue ps primes box truedecide (l.1>2*l.2 ∨ h.1<2*h.2)def walk (ps primes : Array Nat) : Nat → Box → List Char → Option (List Char)| 0, _, _ => none| _+1, _, [] => none| fuel+1, box, c::cs => doif c=='0' thenguard (separated ps primes box)return cslet i := c.toNat-'1'.toNatguard (c≥'1' && i<6)let (a,b) := box[i]!guard (a<b)let mid := if i==5 then (a+b)/2 else min ((a+b)/2) (a+1)let right ← walk ps primes fuel (box.set! i (a,mid)) cswalk ps primes fuel (box.set! i (mid+1,b)) rightdef checkTree (cert : List Nat × String) : Bool :=let ps := cert.1.toArraylet primes := fourthChoices ps[2]!let box := #[(2,18),(0,18),(0,18),(0,18),(0,18),(0,primes.size-1)]walk ps primes 100 box cert.2.toList == some []def lowerTripleGap (ps : List Nat) : Bool := Id.run dofor e in [2:6] dofor a in [:6] dofor b in [:6] dofor c in [:6] dolet ds := [a,b,c]let lo := (ps.zipWith (fun p d => localEdge p e d 5 false) ds).foldl times (1,1)let hi := (ps.zipWith (fun p d => localEdge p e d 5 true) ds).foldl times (1,1)-- The second inequality also rules out every fourth prime >= 2032.if !(lo.1>2*lo.2 || 2032*hi.1<2*2031*hi.2) then return falsereturn truedef expected : List (List Nat) := [[3,5,7],[3,5,11],[3,5,13],[3,5,17],[3,5,19],[3,5,23],[3,5,29],[3,7,11],[3,7,13]]theorem listed_supports : certificates.map Prod.fst = expected := by decide-- Each digit in a split tree chooses a coordinate. Every leaf recomputes its-- rational endpoints. No numerical endpoint values are taken from the tree.set_option maxRecDepth 100000 inset_option maxHeartbeats 0 intheorem odd_support_certificate :(expected.all lowerTripleGap) ∧ (certificates.all checkTree) := by native_decideend Powerful#print axioms Powerful.odd_support_certificate