证明冰雹猜想(Collatz 猜想)
3546165164posted 5 days agofor github.com/kisspeople/collatz-conjecture On the list
| 1 | import Bridges |
| 2 | import Checkpoint |
| 3 | |
| 4 | namespace CollatzRoute |
| 5 | open Move |
| 6 | |
| 7 | /-- A usable endpoint for induction restricted to checkpoints must itself be one. -/ |
| 8 | def atCheckpoint (x : Line) : Bool := x.slope % 9 == 0 && x.base % 9 == 2 |
| 9 | |
| 10 | theorem checkpoint_value {x : Line} (h : atCheckpoint x = true) (q : Nat) : |
| 11 | x.value q % 9 = 2 := by |
| 12 | simp [atCheckpoint] at h |
| 13 | simp [Line.value, Nat.add_mod, Nat.mul_mod, h.1, h.2] |
| 14 | |
| 15 | def checkpointCertificate (x : Line) (word : List Move) : Bool := |
| 16 | certifies x word && (walk? word x).any atCheckpoint |
| 17 | |
| 18 | theorem smaller_checkpoint {x : Line} {word : List Move} |
| 19 | (h : checkpointCertificate x word = true) (q : Nat) : |
| 20 | ∃ m, m % 9 = 2 ∧ m < x.value q ∧ (ReachesOne (x.value q) ↔ ReachesOne m) := by |
| 21 | cases hw : walk? word x with |
| 22 | | none => simp [checkpointCertificate, hw] at h |
| 23 | | some y => |
| 24 | simp [checkpointCertificate, hw] at h |
| 25 | exact ⟨y.value q, checkpoint_value h.2 q, (endpoint_smaller hw h.1 q).2, walk_sound hw q⟩ |
| 26 | |
| 27 | def checkpointRemaining (words : List (List Move)) : List Nat := |
| 28 | (((List.range 64).filter fun i => !(words.any (checkpointCertificate ⟨576,9*i+11⟩))).map |
| 29 | fun i => (9*i+11) % 576) |
| 30 | |
| 31 | def SmallerCheckpoint (n : Nat) : Prop := |
| 32 | ∃ m, m % 9 = 2 ∧ m < n ∧ (ReachesOne n ↔ ReachesOne m) |
| 33 | |
| 34 | theorem by_checkpoint_induction |
| 35 | (rule : ∀ n : Nat, 2 < n → n%9 = 2 → |
| 36 | (∀ m : Nat, m < n → m%9 = 2 → ReachesOne m) → ReachesOne n) : Claim := by |
| 37 | apply claim_iff_two_mod_nine.mpr |
| 38 | intro n hr |
| 39 | induction n using Nat.strongRecOn with |
| 40 | | ind n ih => |
| 41 | by_cases small : n = 2 |
| 42 | · subst n; exact ⟨1, by decide⟩ |
| 43 | · exact rule n (by omega) hr ih |
| 44 | |
| 45 | theorem checkpoint_partition (words : List (List Move)) (n : Nat) (hn : 2 < n) (hr : n%9 = 2) : |
| 46 | n%576 ∈ checkpointRemaining words ∨ SmallerCheckpoint n := by |
| 47 | let i := ((n-11)/9)%64 |
| 48 | let q := ((n-11)/9)/64 |
| 49 | let x : Line := ⟨576, 9*i+11⟩ |
| 50 | have hi : i < 64 := Nat.mod_lt _ (by decide) |
| 51 | have repr : x.value q = n := by dsimp [Line.value, x, i, q]; omega |
| 52 | cases hc : words.any (checkpointCertificate x) with |
| 53 | | true => |
| 54 | obtain ⟨w, _, hw⟩ := List.any_eq_true.mp hc |
| 55 | exact Or.inr (repr ▸ smaller_checkpoint hw q) |
| 56 | | false => |
| 57 | left |
| 58 | refine List.mem_map.mpr ⟨i, List.mem_filter.mpr ⟨List.mem_range.mpr hi, ?_⟩, ?_⟩ |
| 59 | · change Bool.not (words.any (checkpointCertificate x)) = true |
| 60 | simp [hc] |
| 61 | · dsimp [Line.value, x] at repr; omega |
| 62 | |
| 63 | theorem claim_iff_checkpoint_remaining (words : List (List Move)) : |
| 64 | Claim ↔ ∀ n : Nat, n%576 ∈ checkpointRemaining words → ReachesOne n := by |
| 65 | constructor |
| 66 | · intro goal n mem |
| 67 | obtain ⟨i, _, eq⟩ := List.mem_map.mp mem |
| 68 | exact goal n (by omega) |
| 69 | · intro leftover |
| 70 | apply by_checkpoint_induction |
| 71 | intro n hn hr ih |
| 72 | rcases checkpoint_partition words n hn hr with mem | ⟨m, hm, hlt, eq⟩ |
| 73 | · exact leftover n mem |
| 74 | · exact eq.mpr (ih m hlt hm) |
| 75 | |
| 76 | def checkpointWords : List (List Move) := [ |
| 77 | [H, U, H], |
| 78 | [U, H, H, H], |
| 79 | [H, H, H, U, H], |
| 80 | [H, H, H, H, H, H], |
| 81 | [H, H, U, H, H, H], |
| 82 | [U, H, U, H, H, H], |
| 83 | [H, H, H, H, H, U, H], |
| 84 | [H, H, U, H, H, U, H], |
| 85 | [H, H, U, H, U, H, H, H], |
| 86 | [U, H, H, U, H, H, U, H], |
| 87 | [U, H, U, H, U, H, H, H], |
| 88 | [H, H, U, H, U, H, H, U, H], |
| 89 | [U, H, H, U, H, U, H, H, H]] |
| 90 | |
| 91 | def checkpointResidues : List Nat := |
| 92 | [11, 47, 92, 137, 155, 191, 209, 263, 272, 299, 335, 380, 425, 443, 479, 497, 551, 560, 569] |
| 93 | |
| 94 | set_option maxRecDepth 10000 in |
| 95 | set_option maxHeartbeats 2500000 in |
| 96 | theorem checkpoint_table : checkpointRemaining checkpointWords = checkpointResidues := by decide |
| 97 | |
| 98 | theorem claim_iff_19_checkpoints : |
| 99 | Claim ↔ ∀ n : Nat, n%576 ∈ checkpointResidues → ReachesOne n := by |
| 100 | simpa only [checkpoint_table] using claim_iff_checkpoint_remaining checkpointWords |
| 101 | |
| 102 | theorem checkpoint_residue_count : checkpointResidues.length = 19 := by decide |
| 103 | |
| 104 | private theorem from_refined_class (n modulus base : Nat) (word : List Move) |
| 105 | (hc : checkpointCertificate ⟨modulus, base⟩ word = true) (hr : n%modulus=base) : |
| 106 | SmallerCheckpoint n := by |
| 107 | have hrepr : (Line.mk modulus base).value (n/modulus) = n := by |
| 108 | have eq := Nat.mod_add_div n modulus |
| 109 | dsimp [Line.value]; omega |
| 110 | exact hrepr ▸ smaller_checkpoint hc (n/modulus) |
| 111 | |
| 112 | /-- Four coarse classes split into two or three certified subclasses each. -/ |
| 113 | theorem four_refined {n : Nat} (h : n%576 = 92 ∨ n%576 = 272 ∨ n%576 = 497 ∨ n%576 = 560) : |
| 114 | SmallerCheckpoint n := by |
| 115 | rcases h with h|h|h|h |
| 116 | · have hsub : n%1152=92 ∨ n%1152=668 := by omega |
| 117 | rcases hsub with hr|hr |
| 118 | · exact from_refined_class n 1152 92 [H, H, U, H, U, H, U, H, H, H] (by decide) hr |
| 119 | · exact from_refined_class n 1152 668 [H, H, U, H, U, H, U, H, H, U, H] (by decide) hr |
| 120 | · have hsub : n%1152=272 ∨ n%1152=848 := by omega |
| 121 | rcases hsub with hr|hr |
| 122 | · exact from_refined_class n 1152 272 [H, H, H, H, U, H, H, U, H] (by decide) hr |
| 123 | · exact from_refined_class n 1152 848 [H, H, H, H, U, H, H, H] (by decide) hr |
| 124 | · have hsub : n%1152=497 ∨ n%1152=1073 := by omega |
| 125 | rcases hsub with hr|hr |
| 126 | · exact from_refined_class n 1152 497 [U, H, H, U, H, H, H, H, P, D, D] (by decide) hr |
| 127 | · exact from_refined_class n 1152 1073 [U, H, H, U, H, H, H, H, U, H] (by decide) hr |
| 128 | · have hsub : n%1728=560 ∨ n%1728=1136 ∨ n%1728=1712 := by omega |
| 129 | rcases hsub with hr|hr|hr |
| 130 | · exact from_refined_class n 1728 560 [H, H, H, P, D, D] (by decide) hr |
| 131 | · exact from_refined_class n 1728 1136 [H, H, H, P] (by decide) hr |
| 132 | · exact from_refined_class n 1728 1712 [H, H, H, P, D, D, D, D] (by decide) hr |
| 133 | |
| 134 | def finalResidues : List Nat := |
| 135 | checkpointResidues.filter fun r => !(r == 92 || r == 272 || r == 497 || r == 560) |
| 136 | |
| 137 | theorem final_fifteen : finalResidues = |
| 138 | [11,47,137,155,191,209,263,299,335,380,425,443,479,551,569] := by decide |
| 139 | |
| 140 | theorem claim_iff_15_checkpoints : |
| 141 | Claim ↔ ∀ n : Nat, n%576 ∈ finalResidues → ReachesOne n := by |
| 142 | constructor |
| 143 | · intro goal n mem |
| 144 | by_cases hn : n=0 |
| 145 | · subst n; simp [final_fifteen] at mem |
| 146 | · exact goal n (by omega) |
| 147 | · intro leftover |
| 148 | apply by_checkpoint_induction |
| 149 | intro n hn hr ih |
| 150 | rcases checkpoint_partition checkpointWords n hn hr with mem | small |
| 151 | · rw [checkpoint_table] at mem |
| 152 | by_cases extra : n%576 = 92 ∨ n%576 = 272 ∨ n%576 = 497 ∨ n%576 = 560 |
| 153 | · obtain ⟨m, hm, hlt, eq⟩ := four_refined extra |
| 154 | exact eq.mpr (ih m hlt hm) |
| 155 | · apply leftover |
| 156 | apply List.mem_filter.mpr |
| 157 | exact ⟨mem, by simpa [and_assoc] using extra⟩ |
| 158 | · obtain ⟨m, hm, hlt, eq⟩ := small |
| 159 | exact eq.mpr (ih m hlt hm) |
| 160 | |
| 161 | /-- First hits for the fifteen least representatives only. -/ |
| 162 | def leastExamples : List (Nat × Nat) := [ |
| 163 | (11,14), (47,104), (137,90), (155,85), (191,44), (209,39), (263,78), |
| 164 | (299,117), (335,68), (380,107), (425,58), (443,53), (479,53), (551,43), (569,56)] |
| 165 | |
| 166 | theorem least_examples_match : leastExamples.map Prod.fst = finalResidues := by decide |
| 167 | |
| 168 | set_option maxRecDepth 12000 in |
| 169 | set_option maxHeartbeats 4000000 in |
| 170 | theorem least_examples_first_hits : |
| 171 | leastExamples.all (fun (n,t) => |
| 172 | orbit t n == 1 && (List.range t).all fun s => orbit s n != 1) = true := by decide |
| 173 | |
| 174 | #print axioms least_examples_match |
| 175 | #print axioms least_examples_first_hits |
| 176 | #print axioms four_refined |
| 177 | #print axioms final_fifteen |
| 178 | #print axioms claim_iff_15_checkpoints |
| 179 | #print axioms smaller_checkpoint |
| 180 | #print axioms checkpoint_table |
| 181 | #print axioms claim_iff_19_checkpoints |
| 182 | #print axioms checkpoint_residue_count |
| 183 | |
| 184 | end CollatzRoute |