Lean / Reader
Lean reader

Powerful.lean

83 lines14 declarations1 × sorry / admit / native_decideimports Certificates

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.

  1. import Certificates
  2. namespace Powerful
  3. abbrev Ratio := Nat × Nat
  4. abbrev Box := Array (Nat × Nat)
  5. def times (a b : Ratio) : Ratio := (a.1*b.1,a.2*b.2)
  6. def localEdge (p ell d cap : Nat) (upper : Bool) : Ratio :=
  7. if upper && d==cap then (p,p-1) else
  8. let g := (p^(d+1)-1)/(p-1)
  9. if !upper && ell==cap then (g,p^d) else (g*p^ell+1,p^(d+ell))
  10. def isPrimeSmall (n : Nat) : Bool :=
  11. n≥2 && ((List.range 44).all fun i => decide (i<2 ∨ n < i*i ∨ n%i≠0))
  12. def fourthChoices (lower : Nat) : Array Nat :=
  13. ((List.range 2032).filter fun n => n>lower && isPrimeSmall n).toArray
  14. def boxValue (ps primes : Array Nat) (box : Box) (upper : Bool) : Ratio := Id.run do
  15. let mut v : Ratio := (1,1)
  16. for i in [:4] do
  17. let p := if i<3 then ps[i]! else
  18. primes[if upper then box[5]!.1 else box[5]!.2]!
  19. let e := if upper then box[0]!.1 else box[0]!.2
  20. let d := if upper then box[i+1]!.2 else box[i+1]!.1
  21. v := times v (localEdge p e d 18 upper)
  22. return v
  23. def separated (ps primes : Array Nat) (box : Box) : Bool :=
  24. let l := boxValue ps primes box false
  25. let h := boxValue ps primes box true
  26. decide (l.1>2*l.2 ∨ h.1<2*h.2)
  27. def walk (ps primes : Array Nat) : Nat → Box → List Char → Option (List Char)
  28. | 0, _, _ => none
  29. | _+1, _, [] => none
  30. | fuel+1, box, c::cs => do
  31. if c=='0' then
  32. guard (separated ps primes box)
  33. return cs
  34. let i := c.toNat-'1'.toNat
  35. guard (c≥'1' && i<6)
  36. let (a,b) := box[i]!
  37. guard (a<b)
  38. let mid := if i==5 then (a+b)/2 else min ((a+b)/2) (a+1)
  39. let right ← walk ps primes fuel (box.set! i (a,mid)) cs
  40. walk ps primes fuel (box.set! i (mid+1,b)) right
  41. def checkTree (cert : List Nat × String) : Bool :=
  42. let ps := cert.1.toArray
  43. let primes := fourthChoices ps[2]!
  44. let box := #[(2,18),(0,18),(0,18),(0,18),(0,18),(0,primes.size-1)]
  45. walk ps primes 100 box cert.2.toList == some []
  46. def lowerTripleGap (ps : List Nat) : Bool := Id.run do
  47. for e in [2:6] do
  48. for a in [:6] do
  49. for b in [:6] do
  50. for c in [:6] do
  51. let ds := [a,b,c]
  52. let lo := (ps.zipWith (fun p d => localEdge p e d 5 false) ds).foldl times (1,1)
  53. let hi := (ps.zipWith (fun p d => localEdge p e d 5 true) ds).foldl times (1,1)
  54. -- The second inequality also rules out every fourth prime >= 2032.
  55. if !(lo.1>2*lo.2 || 2032*hi.1<2*2031*hi.2) then return false
  56. return true
  57. def expected : List (List Nat) := [[3,5,7],[3,5,11],[3,5,13],[3,5,17],[3,5,19],
  58. [3,5,23],[3,5,29],[3,7,11],[3,7,13]]
  59. theorem listed_supports : certificates.map Prod.fst = expected := by decide
  60. -- Each digit in a split tree chooses a coordinate. Every leaf recomputes its
  61. -- rational endpoints. No numerical endpoint values are taken from the tree.
  62. set_option maxRecDepth 100000 in
  63. set_option maxHeartbeats 0 in
  64. theorem odd_support_certificate :
  65. (expected.all lowerTripleGap) ∧ (certificates.all checkTree) := by native_decide
  66. end Powerful
  67. #print axioms Powerful.odd_support_certificate