Lean / Reader
Lean reader

Erdos319Witness.lean

313 lines90 declarationsno sorryimports Mathlib
  1. import Mathlib
  2. /-! A finite certificate for a primitive 46-term reciprocal relation.
  3. After clearing denominators the modulus of each of seven disjoint prime-power
  4. layers restricts the integer contribution from that layer. Once denominator 1
  5. is absent, the positive uncovered weights can contribute only 0, 12, 21 or 33
  6. after their common scale is removed. All opposing contributions belong to an
  7. additively closed set containing none of 12, 21 and 33. At zero each group
  8. has selected no terms. Complementing the choice handles denominator 1.
  9. The final theorem uses the same fixed signs on every proper subset.
  10. -/
  11. namespace Erdos319Witness
  12. set_option maxHeartbeats 6000000
  13. set_option maxRecDepth 16384
  14. def bit (b : Bool) : ℤ := if b then 1 else 0
  15. private def good (t : ℤ) : Prop := 34 ≤ t ∨ t ∈ ([0,10,14,15,17,20,24,25,27,28,29,30,31,32] : List ℤ)
  16. private instance (t : ℤ) : Decidable (good t) := inferInstanceAs (Decidable (_ ∨ _))
  17. private theorem good_nonneg {t : ℤ} (h : good t) : 0 ≤ t := by
  18. simp [good] at h; omega
  19. private theorem good_add {a b : ℤ} (ha : good a) (hb : good b) : good (a+b) := by
  20. have ha0 := good_nonneg ha
  21. have hb0 := good_nonneg hb
  22. by_cases aL : 34 ≤ a
  23. · exact Or.inl (by omega)
  24. by_cases bL : 34 ≤ b
  25. · exact Or.inl (by omega)
  26. have finite : ∀ u v : Fin 34, good (u.val : ℤ) → good (v.val : ℤ) → good ((u.val : ℤ)+v.val) := by decide +kernel
  27. let u : Fin 34 := ⟨a.toNat,by omega⟩
  28. let v : Fin 34 := ⟨b.toNat,by omega⟩
  29. have hu : (u.val : ℤ) = a := Int.toNat_of_nonneg ha0
  30. have hv : (v.val : ℤ) = b := Int.toNat_of_nonneg hb0
  31. have step := finite u v
  32. rw [hu,hv] at step
  33. exact step ha hb
  34. private def valid (cost count : ℤ) : Prop := good cost ∧ (cost=0 → count=0)
  35. private instance (a b : ℤ) : Decidable (valid a b) := inferInstanceAs (Decidable (_ ∧ _))
  36. private theorem valid_add {u v i j : ℤ} (h : valid u i) (k : valid v j) : valid (u+v) (i+j) := by
  37. refine ⟨good_add h.1 k.1, ?_⟩
  38. have hu := good_nonneg h.1; have hv := good_nonneg k.1
  39. intro z
  40. have hi := h.2 (by omega); have hj := k.2 (by omega); omega
  41. private theorem block0 : ∀ (b19 b38 b57 b76 : Bool),
  42. let t := (-183783600 : ℤ) * bit b19 + (-91891800 : ℤ) * bit b38 + (-61261200 : ℤ) * bit b57 + (45945900 : ℤ) * bit b76
  43. t % 19 = 0 → valid ((-t)/4157010) (bit b19 + bit b38 + bit b57 + bit b76) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  44. private theorem block1 : ∀ (b17 b34 b51 b68 : Bool),
  45. let t := (-205405200 : ℤ) * bit b17 + (-102702600 : ℤ) * bit b34 + (68468400 : ℤ) * bit b51 + (-51351300 : ℤ) * bit b68
  46. t % 17 = 0 → valid ((-t)/4157010) (bit b17 + bit b34 + bit b51 + bit b68) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  47. private theorem block2 : ∀ (b13 b26 b52 b65 b78 : Bool),
  48. let t := (-268606800 : ℤ) * bit b13 + (134303400 : ℤ) * bit b26 + (67151700 : ℤ) * bit b52 + (53721360 : ℤ) * bit b65 + (-44767800 : ℤ) * bit b78
  49. t % 13 = 0 → valid ((-t)/4157010) (bit b13 + bit b26 + bit b52 + bit b65 + bit b78) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  50. private theorem block3 : ∀ (b22 b33 b44 b55 b66 b77 : Bool),
  51. let t := (-158722200 : ℤ) * bit b22 + (-105814800 : ℤ) * bit b33 + (79361100 : ℤ) * bit b44 + (-63488880 : ℤ) * bit b55 + (52907400 : ℤ) * bit b66 + (-45349200 : ℤ) * bit b77
  52. t % 11 = 0 → valid ((-t)/4157010) (bit b22 + bit b33 + bit b44 + bit b55 + bit b66 + bit b77) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  53. private theorem block4 : ∀ (b25 b50 b75 : Bool),
  54. let t := (-139675536 : ℤ) * bit b25 + (69837768 : ℤ) * bit b50 + (-46558512 : ℤ) * bit b75
  55. t % 5 = 0 → valid ((-t)/4157010) (bit b25 + bit b50 + bit b75) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  56. private theorem block5 : ∀ (b9 b18 b27 b36 b45 b54 b63 b72 : Bool),
  57. let t := (-387987600 : ℤ) * bit b9 + (-193993800 : ℤ) * bit b18 + (-129329200 : ℤ) * bit b27 + (-96996900 : ℤ) * bit b36 + (-77597520 : ℤ) * bit b45 + (-64664600 : ℤ) * bit b54 + (55426800 : ℤ) * bit b63 + (-48498450 : ℤ) * bit b72
  58. t % 9 = 0 → valid ((-t)/4157010) (bit b9 + bit b18 + bit b27 + bit b36 + bit b45 + bit b54 + bit b63 + bit b72) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  59. private theorem block6 : ∀ (b48 b80 : Bool),
  60. let t := (-72747675 : ℤ) * bit b48 + (-43648605 : ℤ) * bit b80
  61. t % 2 = 0 → valid ((-t)/4157010) (bit b48 + bit b80) ∧ t = (-4157010) * ((-t)/4157010) := by decide +kernel
  62. private theorem single12 : ∀ b : Bool, valid (70 * bit b) (bit b) := by decide +kernel
  63. private theorem single14 : ∀ b : Bool, valid (60 * bit b) (bit b) := by decide +kernel
  64. private theorem single20 : ∀ b : Bool, valid (42 * bit b) (bit b) := by decide +kernel
  65. private theorem single21 : ∀ b : Bool, valid (40 * bit b) (bit b) := by decide +kernel
  66. private theorem single24 : ∀ b : Bool, valid (35 * bit b) (bit b) := by decide +kernel
  67. private theorem single28 : ∀ b : Bool, valid (30 * bit b) (bit b) := by decide +kernel
  68. private theorem single30 : ∀ b : Bool, valid (28 * bit b) (bit b) := by decide +kernel
  69. private theorem single35 : ∀ b : Bool, valid (24 * bit b) (bit b) := by decide +kernel
  70. private theorem single42 : ∀ b : Bool, valid (20 * bit b) (bit b) := by decide +kernel
  71. private theorem single56 : ∀ b : Bool, valid (15 * bit b) (bit b) := by decide +kernel
  72. private theorem single60 : ∀ b : Bool, valid (14 * bit b) (bit b) := by decide +kernel
  73. def linear (x : ℕ → Bool) : ℤ :=
  74. (3491888400 : ℤ) * bit (x 1) + (-387987600 : ℤ) * bit (x 9) + (-290990700 : ℤ) * bit (x 12) + (-268606800 : ℤ) * bit (x 13) + (-249420600 : ℤ) * bit (x 14) + (-205405200 : ℤ) * bit (x 17) + (-193993800 : ℤ) * bit (x 18) + (-183783600 : ℤ) * bit (x 19) + (-174594420 : ℤ) * bit (x 20) + (-166280400 : ℤ) * bit (x 21) + (-158722200 : ℤ) * bit (x 22) + (-145495350 : ℤ) * bit (x 24) + (-139675536 : ℤ) * bit (x 25) + (134303400 : ℤ) * bit (x 26) + (-129329200 : ℤ) * bit (x 27) + (-124710300 : ℤ) * bit (x 28) + (-116396280 : ℤ) * bit (x 30) + (-105814800 : ℤ) * bit (x 33) + (-102702600 : ℤ) * bit (x 34) + (-99768240 : ℤ) * bit (x 35) + (-96996900 : ℤ) * bit (x 36) + (-91891800 : ℤ) * bit (x 38) + (87297210 : ℤ) * bit (x 40) + (-83140200 : ℤ) * bit (x 42) + (79361100 : ℤ) * bit (x 44) + (-77597520 : ℤ) * bit (x 45) + (-72747675 : ℤ) * bit (x 48) + (69837768 : ℤ) * bit (x 50) + (68468400 : ℤ) * bit (x 51) + (67151700 : ℤ) * bit (x 52) + (-64664600 : ℤ) * bit (x 54) + (-63488880 : ℤ) * bit (x 55) + (-62355150 : ℤ) * bit (x 56) + (-61261200 : ℤ) * bit (x 57) + (-58198140 : ℤ) * bit (x 60) + (55426800 : ℤ) * bit (x 63) + (53721360 : ℤ) * bit (x 65) + (52907400 : ℤ) * bit (x 66) + (-51351300 : ℤ) * bit (x 68) + (49884120 : ℤ) * bit (x 70) + (-48498450 : ℤ) * bit (x 72) + (-46558512 : ℤ) * bit (x 75) + (45945900 : ℤ) * bit (x 76) + (-45349200 : ℤ) * bit (x 77) + (-44767800 : ℤ) * bit (x 78) + (-43648605 : ℤ) * bit (x 80)
  75. def chosen (x : ℕ → Bool) : ℤ :=
  76. bit (x 1) + bit (x 9) + bit (x 12) + bit (x 13) + bit (x 14) + bit (x 17) + bit (x 18) + bit (x 19) + bit (x 20) + bit (x 21) + bit (x 22) + bit (x 24) + bit (x 25) + bit (x 26) + bit (x 27) + bit (x 28) + bit (x 30) + bit (x 33) + bit (x 34) + bit (x 35) + bit (x 36) + bit (x 38) + bit (x 40) + bit (x 42) + bit (x 44) + bit (x 45) + bit (x 48) + bit (x 50) + bit (x 51) + bit (x 52) + bit (x 54) + bit (x 55) + bit (x 56) + bit (x 57) + bit (x 60) + bit (x 63) + bit (x 65) + bit (x 66) + bit (x 68) + bit (x 70) + bit (x 72) + bit (x 75) + bit (x 76) + bit (x 77) + bit (x 78) + bit (x 80)
  77. private theorem zero_without_anchor (x : ℕ → Bool) (anchor : x 1 = false) (z : linear x = 0) : chosen x = 0 := by
  78. unfold linear at z
  79. let t0 : ℤ := (-183783600 : ℤ) * bit (x 19) + (-91891800 : ℤ) * bit (x 38) + (-61261200 : ℤ) * bit (x 57) + (45945900 : ℤ) * bit (x 76)
  80. have zero0 : t0 = 19 * (-((183783600:ℤ) * bit (x 1) + (-20420400:ℤ) * bit (x 9) + (-15315300:ℤ) * bit (x 12) + (-14137200:ℤ) * bit (x 13) + (-13127400:ℤ) * bit (x 14) + (-10810800:ℤ) * bit (x 17) + (-10210200:ℤ) * bit (x 18) + (-9189180:ℤ) * bit (x 20) + (-8751600:ℤ) * bit (x 21) + (-8353800:ℤ) * bit (x 22) + (-7657650:ℤ) * bit (x 24) + (-7351344:ℤ) * bit (x 25) + (7068600:ℤ) * bit (x 26) + (-6806800:ℤ) * bit (x 27) + (-6563700:ℤ) * bit (x 28) + (-6126120:ℤ) * bit (x 30) + (-5569200:ℤ) * bit (x 33) + (-5405400:ℤ) * bit (x 34) + (-5250960:ℤ) * bit (x 35) + (-5105100:ℤ) * bit (x 36) + (4594590:ℤ) * bit (x 40) + (-4375800:ℤ) * bit (x 42) + (4176900:ℤ) * bit (x 44) + (-4084080:ℤ) * bit (x 45) + (-3828825:ℤ) * bit (x 48) + (3675672:ℤ) * bit (x 50) + (3603600:ℤ) * bit (x 51) + (3534300:ℤ) * bit (x 52) + (-3403400:ℤ) * bit (x 54) + (-3341520:ℤ) * bit (x 55) + (-3281850:ℤ) * bit (x 56) + (-3063060:ℤ) * bit (x 60) + (2917200:ℤ) * bit (x 63) + (2827440:ℤ) * bit (x 65) + (2784600:ℤ) * bit (x 66) + (-2702700:ℤ) * bit (x 68) + (2625480:ℤ) * bit (x 70) + (-2552550:ℤ) * bit (x 72) + (-2450448:ℤ) * bit (x 75) + (-2386800:ℤ) * bit (x 77) + (-2356200:ℤ) * bit (x 78) + (-2297295:ℤ) * bit (x 80))) := by
  81. dsimp [t0]; linear_combination z
  82. have mod0 : t0 % 19 = 0 := by rw [zero0,Int.mul_emod_right]
  83. obtain ⟨v0,r0⟩ := block0 (x 19) (x 38) (x 57) (x 76) mod0
  84. change valid ((-t0)/4157010) (bit (x 19) + bit (x 38) + bit (x 57) + bit (x 76)) at v0
  85. change t0 = (-4157010) * ((-t0)/4157010) at r0
  86. let t1 : ℤ := (-205405200 : ℤ) * bit (x 17) + (-102702600 : ℤ) * bit (x 34) + (68468400 : ℤ) * bit (x 51) + (-51351300 : ℤ) * bit (x 68)
  87. have zero1 : t1 = 17 * (-((205405200:ℤ) * bit (x 1) + (-22822800:ℤ) * bit (x 9) + (-17117100:ℤ) * bit (x 12) + (-15800400:ℤ) * bit (x 13) + (-14671800:ℤ) * bit (x 14) + (-11411400:ℤ) * bit (x 18) + (-10810800:ℤ) * bit (x 19) + (-10270260:ℤ) * bit (x 20) + (-9781200:ℤ) * bit (x 21) + (-9336600:ℤ) * bit (x 22) + (-8558550:ℤ) * bit (x 24) + (-8216208:ℤ) * bit (x 25) + (7900200:ℤ) * bit (x 26) + (-7607600:ℤ) * bit (x 27) + (-7335900:ℤ) * bit (x 28) + (-6846840:ℤ) * bit (x 30) + (-6224400:ℤ) * bit (x 33) + (-5868720:ℤ) * bit (x 35) + (-5705700:ℤ) * bit (x 36) + (-5405400:ℤ) * bit (x 38) + (5135130:ℤ) * bit (x 40) + (-4890600:ℤ) * bit (x 42) + (4668300:ℤ) * bit (x 44) + (-4564560:ℤ) * bit (x 45) + (-4279275:ℤ) * bit (x 48) + (4108104:ℤ) * bit (x 50) + (3950100:ℤ) * bit (x 52) + (-3803800:ℤ) * bit (x 54) + (-3734640:ℤ) * bit (x 55) + (-3667950:ℤ) * bit (x 56) + (-3603600:ℤ) * bit (x 57) + (-3423420:ℤ) * bit (x 60) + (3260400:ℤ) * bit (x 63) + (3160080:ℤ) * bit (x 65) + (3112200:ℤ) * bit (x 66) + (2934360:ℤ) * bit (x 70) + (-2852850:ℤ) * bit (x 72) + (-2738736:ℤ) * bit (x 75) + (2702700:ℤ) * bit (x 76) + (-2667600:ℤ) * bit (x 77) + (-2633400:ℤ) * bit (x 78) + (-2567565:ℤ) * bit (x 80))) := by
  88. dsimp [t1]; linear_combination z
  89. have mod1 : t1 % 17 = 0 := by rw [zero1,Int.mul_emod_right]
  90. obtain ⟨v1,r1⟩ := block1 (x 17) (x 34) (x 51) (x 68) mod1
  91. change valid ((-t1)/4157010) (bit (x 17) + bit (x 34) + bit (x 51) + bit (x 68)) at v1
  92. change t1 = (-4157010) * ((-t1)/4157010) at r1
  93. let t2 : ℤ := (-268606800 : ℤ) * bit (x 13) + (134303400 : ℤ) * bit (x 26) + (67151700 : ℤ) * bit (x 52) + (53721360 : ℤ) * bit (x 65) + (-44767800 : ℤ) * bit (x 78)
  94. have zero2 : t2 = 13 * (-((268606800:ℤ) * bit (x 1) + (-29845200:ℤ) * bit (x 9) + (-22383900:ℤ) * bit (x 12) + (-19186200:ℤ) * bit (x 14) + (-15800400:ℤ) * bit (x 17) + (-14922600:ℤ) * bit (x 18) + (-14137200:ℤ) * bit (x 19) + (-13430340:ℤ) * bit (x 20) + (-12790800:ℤ) * bit (x 21) + (-12209400:ℤ) * bit (x 22) + (-11191950:ℤ) * bit (x 24) + (-10744272:ℤ) * bit (x 25) + (-9948400:ℤ) * bit (x 27) + (-9593100:ℤ) * bit (x 28) + (-8953560:ℤ) * bit (x 30) + (-8139600:ℤ) * bit (x 33) + (-7900200:ℤ) * bit (x 34) + (-7674480:ℤ) * bit (x 35) + (-7461300:ℤ) * bit (x 36) + (-7068600:ℤ) * bit (x 38) + (6715170:ℤ) * bit (x 40) + (-6395400:ℤ) * bit (x 42) + (6104700:ℤ) * bit (x 44) + (-5969040:ℤ) * bit (x 45) + (-5595975:ℤ) * bit (x 48) + (5372136:ℤ) * bit (x 50) + (5266800:ℤ) * bit (x 51) + (-4974200:ℤ) * bit (x 54) + (-4883760:ℤ) * bit (x 55) + (-4796550:ℤ) * bit (x 56) + (-4712400:ℤ) * bit (x 57) + (-4476780:ℤ) * bit (x 60) + (4263600:ℤ) * bit (x 63) + (4069800:ℤ) * bit (x 66) + (-3950100:ℤ) * bit (x 68) + (3837240:ℤ) * bit (x 70) + (-3730650:ℤ) * bit (x 72) + (-3581424:ℤ) * bit (x 75) + (3534300:ℤ) * bit (x 76) + (-3488400:ℤ) * bit (x 77) + (-3357585:ℤ) * bit (x 80))) := by
  95. dsimp [t2]; linear_combination z
  96. have mod2 : t2 % 13 = 0 := by rw [zero2,Int.mul_emod_right]
  97. obtain ⟨v2,r2⟩ := block2 (x 13) (x 26) (x 52) (x 65) (x 78) mod2
  98. change valid ((-t2)/4157010) (bit (x 13) + bit (x 26) + bit (x 52) + bit (x 65) + bit (x 78)) at v2
  99. change t2 = (-4157010) * ((-t2)/4157010) at r2
  100. let t3 : ℤ := (-158722200 : ℤ) * bit (x 22) + (-105814800 : ℤ) * bit (x 33) + (79361100 : ℤ) * bit (x 44) + (-63488880 : ℤ) * bit (x 55) + (52907400 : ℤ) * bit (x 66) + (-45349200 : ℤ) * bit (x 77)
  101. have zero3 : t3 = 11 * (-((317444400:ℤ) * bit (x 1) + (-35271600:ℤ) * bit (x 9) + (-26453700:ℤ) * bit (x 12) + (-24418800:ℤ) * bit (x 13) + (-22674600:ℤ) * bit (x 14) + (-18673200:ℤ) * bit (x 17) + (-17635800:ℤ) * bit (x 18) + (-16707600:ℤ) * bit (x 19) + (-15872220:ℤ) * bit (x 20) + (-15116400:ℤ) * bit (x 21) + (-13226850:ℤ) * bit (x 24) + (-12697776:ℤ) * bit (x 25) + (12209400:ℤ) * bit (x 26) + (-11757200:ℤ) * bit (x 27) + (-11337300:ℤ) * bit (x 28) + (-10581480:ℤ) * bit (x 30) + (-9336600:ℤ) * bit (x 34) + (-9069840:ℤ) * bit (x 35) + (-8817900:ℤ) * bit (x 36) + (-8353800:ℤ) * bit (x 38) + (7936110:ℤ) * bit (x 40) + (-7558200:ℤ) * bit (x 42) + (-7054320:ℤ) * bit (x 45) + (-6613425:ℤ) * bit (x 48) + (6348888:ℤ) * bit (x 50) + (6224400:ℤ) * bit (x 51) + (6104700:ℤ) * bit (x 52) + (-5878600:ℤ) * bit (x 54) + (-5668650:ℤ) * bit (x 56) + (-5569200:ℤ) * bit (x 57) + (-5290740:ℤ) * bit (x 60) + (5038800:ℤ) * bit (x 63) + (4883760:ℤ) * bit (x 65) + (-4668300:ℤ) * bit (x 68) + (4534920:ℤ) * bit (x 70) + (-4408950:ℤ) * bit (x 72) + (-4232592:ℤ) * bit (x 75) + (4176900:ℤ) * bit (x 76) + (-4069800:ℤ) * bit (x 78) + (-3968055:ℤ) * bit (x 80))) := by
  102. dsimp [t3]; linear_combination z
  103. have mod3 : t3 % 11 = 0 := by rw [zero3,Int.mul_emod_right]
  104. obtain ⟨v3,r3⟩ := block3 (x 22) (x 33) (x 44) (x 55) (x 66) (x 77) mod3
  105. change valid ((-t3)/4157010) (bit (x 22) + bit (x 33) + bit (x 44) + bit (x 55) + bit (x 66) + bit (x 77)) at v3
  106. change t3 = (-4157010) * ((-t3)/4157010) at r3
  107. let t4 : ℤ := (-139675536 : ℤ) * bit (x 25) + (69837768 : ℤ) * bit (x 50) + (-46558512 : ℤ) * bit (x 75)
  108. have zero4 : t4 = 5 * (-((698377680:ℤ) * bit (x 1) + (-77597520:ℤ) * bit (x 9) + (-58198140:ℤ) * bit (x 12) + (-53721360:ℤ) * bit (x 13) + (-49884120:ℤ) * bit (x 14) + (-41081040:ℤ) * bit (x 17) + (-38798760:ℤ) * bit (x 18) + (-36756720:ℤ) * bit (x 19) + (-34918884:ℤ) * bit (x 20) + (-33256080:ℤ) * bit (x 21) + (-31744440:ℤ) * bit (x 22) + (-29099070:ℤ) * bit (x 24) + (26860680:ℤ) * bit (x 26) + (-25865840:ℤ) * bit (x 27) + (-24942060:ℤ) * bit (x 28) + (-23279256:ℤ) * bit (x 30) + (-21162960:ℤ) * bit (x 33) + (-20540520:ℤ) * bit (x 34) + (-19953648:ℤ) * bit (x 35) + (-19399380:ℤ) * bit (x 36) + (-18378360:ℤ) * bit (x 38) + (17459442:ℤ) * bit (x 40) + (-16628040:ℤ) * bit (x 42) + (15872220:ℤ) * bit (x 44) + (-15519504:ℤ) * bit (x 45) + (-14549535:ℤ) * bit (x 48) + (13693680:ℤ) * bit (x 51) + (13430340:ℤ) * bit (x 52) + (-12932920:ℤ) * bit (x 54) + (-12697776:ℤ) * bit (x 55) + (-12471030:ℤ) * bit (x 56) + (-12252240:ℤ) * bit (x 57) + (-11639628:ℤ) * bit (x 60) + (11085360:ℤ) * bit (x 63) + (10744272:ℤ) * bit (x 65) + (10581480:ℤ) * bit (x 66) + (-10270260:ℤ) * bit (x 68) + (9976824:ℤ) * bit (x 70) + (-9699690:ℤ) * bit (x 72) + (9189180:ℤ) * bit (x 76) + (-9069840:ℤ) * bit (x 77) + (-8953560:ℤ) * bit (x 78) + (-8729721:ℤ) * bit (x 80))) := by
  109. dsimp [t4]; linear_combination z
  110. have mod4 : t4 % 5 = 0 := by rw [zero4,Int.mul_emod_right]
  111. obtain ⟨v4,r4⟩ := block4 (x 25) (x 50) (x 75) mod4
  112. change valid ((-t4)/4157010) (bit (x 25) + bit (x 50) + bit (x 75)) at v4
  113. change t4 = (-4157010) * ((-t4)/4157010) at r4
  114. let t5 : ℤ := (-387987600 : ℤ) * bit (x 9) + (-193993800 : ℤ) * bit (x 18) + (-129329200 : ℤ) * bit (x 27) + (-96996900 : ℤ) * bit (x 36) + (-77597520 : ℤ) * bit (x 45) + (-64664600 : ℤ) * bit (x 54) + (55426800 : ℤ) * bit (x 63) + (-48498450 : ℤ) * bit (x 72)
  115. have zero5 : t5 = 9 * (-((387987600:ℤ) * bit (x 1) + (-32332300:ℤ) * bit (x 12) + (-29845200:ℤ) * bit (x 13) + (-27713400:ℤ) * bit (x 14) + (-22822800:ℤ) * bit (x 17) + (-20420400:ℤ) * bit (x 19) + (-19399380:ℤ) * bit (x 20) + (-18475600:ℤ) * bit (x 21) + (-17635800:ℤ) * bit (x 22) + (-16166150:ℤ) * bit (x 24) + (-15519504:ℤ) * bit (x 25) + (14922600:ℤ) * bit (x 26) + (-13856700:ℤ) * bit (x 28) + (-12932920:ℤ) * bit (x 30) + (-11757200:ℤ) * bit (x 33) + (-11411400:ℤ) * bit (x 34) + (-11085360:ℤ) * bit (x 35) + (-10210200:ℤ) * bit (x 38) + (9699690:ℤ) * bit (x 40) + (-9237800:ℤ) * bit (x 42) + (8817900:ℤ) * bit (x 44) + (-8083075:ℤ) * bit (x 48) + (7759752:ℤ) * bit (x 50) + (7607600:ℤ) * bit (x 51) + (7461300:ℤ) * bit (x 52) + (-7054320:ℤ) * bit (x 55) + (-6928350:ℤ) * bit (x 56) + (-6806800:ℤ) * bit (x 57) + (-6466460:ℤ) * bit (x 60) + (5969040:ℤ) * bit (x 65) + (5878600:ℤ) * bit (x 66) + (-5705700:ℤ) * bit (x 68) + (5542680:ℤ) * bit (x 70) + (-5173168:ℤ) * bit (x 75) + (5105100:ℤ) * bit (x 76) + (-5038800:ℤ) * bit (x 77) + (-4974200:ℤ) * bit (x 78) + (-4849845:ℤ) * bit (x 80))) := by
  116. dsimp [t5]; linear_combination z
  117. have mod5 : t5 % 9 = 0 := by rw [zero5,Int.mul_emod_right]
  118. obtain ⟨v5,r5⟩ := block5 (x 9) (x 18) (x 27) (x 36) (x 45) (x 54) (x 63) (x 72) mod5
  119. change valid ((-t5)/4157010) (bit (x 9) + bit (x 18) + bit (x 27) + bit (x 36) + bit (x 45) + bit (x 54) + bit (x 63) + bit (x 72)) at v5
  120. change t5 = (-4157010) * ((-t5)/4157010) at r5
  121. let t6 : ℤ := (-72747675 : ℤ) * bit (x 48) + (-43648605 : ℤ) * bit (x 80)
  122. have zero6 : t6 = 2 * (-((1745944200:ℤ) * bit (x 1) + (-193993800:ℤ) * bit (x 9) + (-145495350:ℤ) * bit (x 12) + (-134303400:ℤ) * bit (x 13) + (-124710300:ℤ) * bit (x 14) + (-102702600:ℤ) * bit (x 17) + (-96996900:ℤ) * bit (x 18) + (-91891800:ℤ) * bit (x 19) + (-87297210:ℤ) * bit (x 20) + (-83140200:ℤ) * bit (x 21) + (-79361100:ℤ) * bit (x 22) + (-72747675:ℤ) * bit (x 24) + (-69837768:ℤ) * bit (x 25) + (67151700:ℤ) * bit (x 26) + (-64664600:ℤ) * bit (x 27) + (-62355150:ℤ) * bit (x 28) + (-58198140:ℤ) * bit (x 30) + (-52907400:ℤ) * bit (x 33) + (-51351300:ℤ) * bit (x 34) + (-49884120:ℤ) * bit (x 35) + (-48498450:ℤ) * bit (x 36) + (-45945900:ℤ) * bit (x 38) + (43648605:ℤ) * bit (x 40) + (-41570100:ℤ) * bit (x 42) + (39680550:ℤ) * bit (x 44) + (-38798760:ℤ) * bit (x 45) + (34918884:ℤ) * bit (x 50) + (34234200:ℤ) * bit (x 51) + (33575850:ℤ) * bit (x 52) + (-32332300:ℤ) * bit (x 54) + (-31744440:ℤ) * bit (x 55) + (-31177575:ℤ) * bit (x 56) + (-30630600:ℤ) * bit (x 57) + (-29099070:ℤ) * bit (x 60) + (27713400:ℤ) * bit (x 63) + (26860680:ℤ) * bit (x 65) + (26453700:ℤ) * bit (x 66) + (-25675650:ℤ) * bit (x 68) + (24942060:ℤ) * bit (x 70) + (-24249225:ℤ) * bit (x 72) + (-23279256:ℤ) * bit (x 75) + (22972950:ℤ) * bit (x 76) + (-22674600:ℤ) * bit (x 77) + (-22383900:ℤ) * bit (x 78))) := by
  123. dsimp [t6]; linear_combination z
  124. have mod6 : t6 % 2 = 0 := by rw [zero6,Int.mul_emod_right]
  125. obtain ⟨v6,r6⟩ := block6 (x 48) (x 80) mod6
  126. change valid ((-t6)/4157010) (bit (x 48) + bit (x 80)) at v6
  127. change t6 = (-4157010) * ((-t6)/4157010) at r6
  128. have combined := (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add (valid_add v0 v1) v2) v3) v4) v5) v6) (single12 (x 12))) (single14 (x 14))) (single20 (x 20))) (single21 (x 21))) (single24 (x 24))) (single28 (x 28))) (single30 (x 30))) (single35 (x 35))) (single42 (x 42))) (single56 (x 56))) (single60 (x 60)))
  129. let cost : ℤ := ((-t0)/4157010) + ((-t1)/4157010) + ((-t2)/4157010) + ((-t3)/4157010) + ((-t4)/4157010) + ((-t5)/4157010) + ((-t6)/4157010) + (70 * bit (x 12)) + (60 * bit (x 14)) + (42 * bit (x 20)) + (40 * bit (x 21)) + (35 * bit (x 24)) + (30 * bit (x 28)) + (28 * bit (x 30)) + (24 * bit (x 35)) + (20 * bit (x 42)) + (15 * bit (x 56)) + (14 * bit (x 60))
  130. let amount : ℤ := bit (x 19) + bit (x 38) + bit (x 57) + bit (x 76) + bit (x 17) + bit (x 34) + bit (x 51) + bit (x 68) + bit (x 13) + bit (x 26) + bit (x 52) + bit (x 65) + bit (x 78) + bit (x 22) + bit (x 33) + bit (x 44) + bit (x 55) + bit (x 66) + bit (x 77) + bit (x 25) + bit (x 50) + bit (x 75) + bit (x 9) + bit (x 18) + bit (x 27) + bit (x 36) + bit (x 45) + bit (x 54) + bit (x 63) + bit (x 72) + bit (x 48) + bit (x 80) + bit (x 12) + bit (x 14) + bit (x 20) + bit (x 21) + bit (x 24) + bit (x 28) + bit (x 30) + bit (x 35) + bit (x 42) + bit (x 56) + bit (x 60)
  131. have layout : valid cost amount := by
  132. dsimp only [cost,amount]
  133. simpa only [add_assoc] using combined
  134. have combine_linear : t0 + t1 + t2 + t3 + t4 + t5 + t6 + (3491888400 : ℤ) * bit (x 1) + (-290990700 : ℤ) * bit (x 12) + (-249420600 : ℤ) * bit (x 14) + (-174594420 : ℤ) * bit (x 20) + (-166280400 : ℤ) * bit (x 21) + (-145495350 : ℤ) * bit (x 24) + (-124710300 : ℤ) * bit (x 28) + (-116396280 : ℤ) * bit (x 30) + (-99768240 : ℤ) * bit (x 35) + (87297210 : ℤ) * bit (x 40) + (-83140200 : ℤ) * bit (x 42) + (-62355150 : ℤ) * bit (x 56) + (-58198140 : ℤ) * bit (x 60) + (49884120 : ℤ) * bit (x 70) = 0 := by
  135. dsimp only [t0,t1,t2,t3,t4,t5,t6]; linear_combination z
  136. have small : cost = 21 * bit (x 40) + 12 * bit (x 70) := by
  137. rw [r0,r1,r2,r3,r4,r5,r6] at combine_linear
  138. rw [anchor] at combine_linear
  139. dsimp only [cost]
  140. have hb : bit false = 0 := rfl
  141. rw [hb] at combine_linear
  142. linarith only [combine_linear]
  143. have edge : ∀ b c : Bool, good (21 * bit b + 12 * bit c) → bit b = 0 ∧ bit c = 0 := by decide +kernel
  144. obtain ⟨e40,e70⟩ := edge (x 40) (x 70) (small ▸ layout.1)
  145. have cz : cost = 0 := by rw [small,e40,e70]; norm_num
  146. have az := layout.2 cz
  147. dsimp only [amount] at az
  148. unfold chosen
  149. rw [anchor,e40,e70]
  150. change _ = _
  151. have hz : bit false = 0 := rfl
  152. rw [hz]
  153. linear_combination az
  154. theorem zero_count (x : ℕ → Bool) (z : linear x = 0) : chosen x = 0 ∨ chosen x = 46 := by
  155. cases h : x 1
  156. · exact Or.inl (zero_without_anchor x h z)
  157. · right
  158. let y : ℕ → Bool := fun n => !(x n)
  159. have flip (b : Bool) : bit (!b) = 1 - bit b := by cases b <;> decide
  160. have y1 : y 1 = false := by simp [y,h]
  161. have yz : linear y = 0 := by
  162. unfold linear at z ⊢
  163. simp only [y,flip]
  164. linear_combination -z
  165. have hy := zero_without_anchor y y1 yz
  166. unfold chosen at hy ⊢
  167. simp only [y,flip] at hy
  168. linear_combination -hy
  169. open Finset
  170. private def indices : List ℕ := [1, 9, 12, 13, 14, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 30, 33, 34, 35, 36, 38, 40, 42, 44, 45, 48, 50, 51, 52, 54, 55, 56, 57, 60, 63, 65, 66, 68, 70, 72, 75, 76, 77, 78, 80]
  171. def support : Finset ℕ := indices.toFinset
  172. private def positive : List ℕ := [1, 26, 40, 44, 50, 51, 52, 63, 65, 66, 70, 76]
  173. def sign (n : ℕ) : ℤˣ := if n ∈ positive then 1 else -1
  174. private def weight (n : ℕ) : ℤ := if n ∈ positive then (3491888400:ℤ)/n else -((3491888400:ℤ)/n)
  175. private def mask (B : Finset ℕ) (n : ℕ) : Bool := decide (n ∈ B)
  176. private theorem list_sum {G : Type*} [AddCommMonoid G] (f : ℕ → G) (l : List ℕ) (h : l.Nodup) :
  177. ∑ n ∈ l.toFinset, f n = (l.map f).sum := by
  178. induction l with
  179. | nil => simp
  180. | cons a t ih =>
  181. obtain ⟨ha,ht⟩ := List.nodup_cons.mp h
  182. simp only [List.toFinset_cons, Finset.sum_insert (by simpa using ha : a ∉ t.toFinset),
  183. List.map_cons, List.sum_cons, ih ht]
  184. private theorem expand_support {G : Type*} [AddCommMonoid G] (f : ℕ → G) :
  185. ∑ n ∈ support, f n = f 1 + f 9 + f 12 + f 13 + f 14 + f 17 + f 18 + f 19 + f 20 + f 21 + f 22 + f 24 + f 25 + f 26 + f 27 + f 28 + f 30 + f 33 + f 34 + f 35 + f 36 + f 38 + f 40 + f 42 + f 44 + f 45 + f 48 + f 50 + f 51 + f 52 + f 54 + f 55 + f 56 + f 57 + f 60 + f 63 + f 65 + f 66 + f 68 + f 70 + f 72 + f 75 + f 76 + f 77 + f 78 + f 80 := by
  186. rw [support,list_sum f indices (by decide +kernel)]
  187. simp only [indices,List.map_cons,List.map_nil,List.sum_cons,List.sum_nil,add_zero,add_assoc]
  188. private theorem restrict_sum {G : Type*} [AddCommMonoid G] (B : Finset ℕ) (h : B ⊆ support) (f : ℕ → G) :
  189. (∑ n ∈ support, if n ∈ B then f n else 0) = ∑ n ∈ B, f n := by
  190. rw [← Finset.sum_filter]
  191. have he : support.filter (fun n => n ∈ B) = B := by
  192. ext n; simp only [Finset.mem_filter]; exact ⟨And.right, fun hn => ⟨h hn,hn⟩⟩
  193. rw [he]
  194. private theorem weight1 : weight 1 = 3491888400 := by decide +kernel
  195. private theorem weight9 : weight 9 = -387987600 := by decide +kernel
  196. private theorem weight12 : weight 12 = -290990700 := by decide +kernel
  197. private theorem weight13 : weight 13 = -268606800 := by decide +kernel
  198. private theorem weight14 : weight 14 = -249420600 := by decide +kernel
  199. private theorem weight17 : weight 17 = -205405200 := by decide +kernel
  200. private theorem weight18 : weight 18 = -193993800 := by decide +kernel
  201. private theorem weight19 : weight 19 = -183783600 := by decide +kernel
  202. private theorem weight20 : weight 20 = -174594420 := by decide +kernel
  203. private theorem weight21 : weight 21 = -166280400 := by decide +kernel
  204. private theorem weight22 : weight 22 = -158722200 := by decide +kernel
  205. private theorem weight24 : weight 24 = -145495350 := by decide +kernel
  206. private theorem weight25 : weight 25 = -139675536 := by decide +kernel
  207. private theorem weight26 : weight 26 = 134303400 := by decide +kernel
  208. private theorem weight27 : weight 27 = -129329200 := by decide +kernel
  209. private theorem weight28 : weight 28 = -124710300 := by decide +kernel
  210. private theorem weight30 : weight 30 = -116396280 := by decide +kernel
  211. private theorem weight33 : weight 33 = -105814800 := by decide +kernel
  212. private theorem weight34 : weight 34 = -102702600 := by decide +kernel
  213. private theorem weight35 : weight 35 = -99768240 := by decide +kernel
  214. private theorem weight36 : weight 36 = -96996900 := by decide +kernel
  215. private theorem weight38 : weight 38 = -91891800 := by decide +kernel
  216. private theorem weight40 : weight 40 = 87297210 := by decide +kernel
  217. private theorem weight42 : weight 42 = -83140200 := by decide +kernel
  218. private theorem weight44 : weight 44 = 79361100 := by decide +kernel
  219. private theorem weight45 : weight 45 = -77597520 := by decide +kernel
  220. private theorem weight48 : weight 48 = -72747675 := by decide +kernel
  221. private theorem weight50 : weight 50 = 69837768 := by decide +kernel
  222. private theorem weight51 : weight 51 = 68468400 := by decide +kernel
  223. private theorem weight52 : weight 52 = 67151700 := by decide +kernel
  224. private theorem weight54 : weight 54 = -64664600 := by decide +kernel
  225. private theorem weight55 : weight 55 = -63488880 := by decide +kernel
  226. private theorem weight56 : weight 56 = -62355150 := by decide +kernel
  227. private theorem weight57 : weight 57 = -61261200 := by decide +kernel
  228. private theorem weight60 : weight 60 = -58198140 := by decide +kernel
  229. private theorem weight63 : weight 63 = 55426800 := by decide +kernel
  230. private theorem weight65 : weight 65 = 53721360 := by decide +kernel
  231. private theorem weight66 : weight 66 = 52907400 := by decide +kernel
  232. private theorem weight68 : weight 68 = -51351300 := by decide +kernel
  233. private theorem weight70 : weight 70 = 49884120 := by decide +kernel
  234. private theorem weight72 : weight 72 = -48498450 := by decide +kernel
  235. private theorem weight75 : weight 75 = -46558512 := by decide +kernel
  236. private theorem weight76 : weight 76 = 45945900 := by decide +kernel
  237. private theorem weight77 : weight 77 = -45349200 := by decide +kernel
  238. private theorem weight78 : weight 78 = -44767800 := by decide +kernel
  239. private theorem weight80 : weight 80 = -43648605 := by decide +kernel
  240. private theorem mask_linear (B : Finset ℕ) (h : B ⊆ support) : linear (mask B) = ∑ n ∈ B, weight n := by
  241. calc
  242. linear (mask B) = ∑ n ∈ support, weight n * bit (mask B n) := by
  243. rw [expand_support]
  244. simp only [linear,weight1,weight9,weight12,weight13,weight14,weight17,weight18,weight19,weight20,weight21,weight22,weight24,weight25,weight26,weight27,weight28,weight30,weight33,weight34,weight35,weight36,weight38,weight40,weight42,weight44,weight45,weight48,weight50,weight51,weight52,weight54,weight55,weight56,weight57,weight60,weight63,weight65,weight66,weight68,weight70,weight72,weight75,weight76,weight77,weight78,weight80]
  245. _ = ∑ n ∈ support, if n ∈ B then weight n else 0 := by
  246. apply Finset.sum_congr rfl; intro n _
  247. by_cases hj : n ∈ B <;> simp [mask,bit,hj]
  248. _ = _ := restrict_sum B h weight
  249. private theorem mask_chosen (B : Finset ℕ) (h : B ⊆ support) : chosen (mask B) = (B.card : ℤ) := by
  250. calc
  251. chosen (mask B) = ∑ n ∈ support, bit (mask B n) := by rw [expand_support]; rfl
  252. _ = ∑ n ∈ support, if n ∈ B then (1:ℤ) else 0 := by
  253. apply Finset.sum_congr rfl; intro n _; by_cases hj : n ∈ B <;> simp [mask,bit,hj]
  254. _ = ∑ _n ∈ B, (1:ℤ) := restrict_sum B h (fun _ => 1)
  255. _ = (B.card : ℤ) := by simp
  256. private theorem weight_on : ∀ n ∈ support, ((weight n : ℤ):ℚ) = 3491888400 * ((sign n : ℚ)/n) := by decide +kernel
  257. theorem primitive80 : support ⊆ Finset.Icc 1 80 ∧ support.card = 46 ∧
  258. (∑ n ∈ support, (sign n : ℚ) / n) = 0 ∧
  259. ∀ B ⊂ support, B.Nonempty → (∑ n ∈ B, (sign n : ℚ)/n) ≠ 0 := by
  260. have hcard : support.card = 46 := by decide +kernel
  261. refine ⟨by decide +kernel,hcard,by decide +kernel,?_⟩
  262. intro B hB hn z
  263. have sub := (Finset.ssubset_iff_subset_ne.mp hB).1
  264. have wz : ((linear (mask B):ℤ):ℚ) = 0 := by
  265. rw [mask_linear B sub, Int.cast_sum]
  266. calc
  267. ∑ n ∈ B, ((weight n : ℤ):ℚ) = ∑ n ∈ B, 3491888400 * ((sign n:ℚ)/n) := Finset.sum_congr rfl (fun n hn => weight_on n (sub hn))
  268. _ = 0 := by rw [← Finset.mul_sum,z,mul_zero]
  269. have iz : linear (mask B) = 0 := by exact_mod_cast wz
  270. have hi := zero_count (mask B) iz
  271. rw [mask_chosen B sub] at hi
  272. have lo : 0 < B.card := Finset.card_pos.mpr hn
  273. have high := Finset.card_lt_card hB
  274. omega
  275. theorem exists_primitive_of_ge80 {N : ℕ} (hN : 80 ≤ N) :
  276. ∃ A : Finset ℕ, A ⊆ Finset.Icc 1 N ∧ A.card = 46 ∧
  277. ∃ δ : ℕ → ℤˣ, (∑ n ∈ A, (δ n : ℚ)/n) = 0 ∧
  278. ∀ B ⊂ A, B.Nonempty → (∑ n ∈ B, (δ n : ℚ)/n) ≠ 0 := by
  279. obtain ⟨inc,card,total,proper⟩ := primitive80
  280. refine ⟨support,?_,card,sign,total,proper⟩
  281. intro n hn
  282. have bounds := Finset.mem_Icc.mp (inc hn)
  283. exact Finset.mem_Icc.mpr ⟨bounds.1,bounds.2.trans hN⟩
  284. #print axioms exists_primitive_of_ge80
  285. #print axioms zero_count
  286. #print axioms primitive80
  287. end Erdos319Witness