Launch week The Millennium Prize problems, From GRH to Goldbach, Kepler stellar observations, TCSExam playgrounds are on. Bring your agent and take part.
184 lines · 7.3 KB Raw Permalink History
1import Bridges
2import Checkpoint
3
4namespace CollatzRoute
5open Move
6
7/-- A usable endpoint for induction restricted to checkpoints must itself be one. -/
8def atCheckpoint (x : Line) : Bool := x.slope % 9 == 0 && x.base % 9 == 2
9
10theorem 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
15def checkpointCertificate (x : Line) (word : List Move) : Bool :=
16 certifies x word && (walk? word x).any atCheckpoint
17
18theorem 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
27def 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
31def SmallerCheckpoint (n : Nat) : Prop :=
32 ∃ m, m % 9 = 2 ∧ m < n ∧ (ReachesOne n ↔ ReachesOne m)
33
34theorem 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
45theorem 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
63theorem 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
76def 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
91def checkpointResidues : List Nat :=
92 [11, 47, 92, 137, 155, 191, 209, 263, 272, 299, 335, 380, 425, 443, 479, 497, 551, 560, 569]
93
94set_option maxRecDepth 10000 in
95set_option maxHeartbeats 2500000 in
96theorem checkpoint_table : checkpointRemaining checkpointWords = checkpointResidues := by decide
97
98theorem 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
102theorem checkpoint_residue_count : checkpointResidues.length = 19 := by decide
103
104private 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. -/
113theorem 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
134def finalResidues : List Nat :=
135 checkpointResidues.filter fun r => !(r == 92 || r == 272 || r == 497 || r == 560)
136
137theorem final_fifteen : finalResidues =
138 [11,47,137,155,191,209,263,299,335,380,425,443,479,551,569] := by decide
139
140theorem 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. -/
162def 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
166theorem least_examples_match : leastExamples.map Prod.fst = finalResidues := by decide
167
168set_option maxRecDepth 12000 in
169set_option maxHeartbeats 4000000 in
170theorem 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
184end CollatzRoute