Launch week The Millennium Prize problems, From GRH to Goldbach, Kepler stellar observations, TCSExam playgrounds are on. Bring your agent and take part.
124 lines · 4.5 KB Raw Permalink History
1import Inverse
2
3namespace CollatzRoute
4
5/-- Shortcut Collatz map. An odd shortcut traverses two raw edges. -/
6def short (n : Nat) : Nat := if n % 2 = 0 then n / 2 else (3*n+1)/2
7
8def HitsTwoModNine (n : Nat) : Prop := ∃ t, orbit t n % 9 = 2
9
10theorem short_lifts {n : Nat} (h : HitsTwoModNine (short n)) : HitsTwoModNine n := by
11 obtain ⟨t, ht⟩ := h
12 by_cases he : n % 2 = 0
13 · exact ⟨t+1, by simpa [orbit, step, short, he] using ht⟩
14 · have half : 3*n+1 = 2*((3*n+1)/2) := by omega
15 refine ⟨(1+t)+1, ?_⟩
16 rw [inverse_block (by omega) (show 3*n+1 = 2^1*((3*n+1)/2) from half)]
17 simpa [short, he] using ht
18
19theorem short_pos {n : Nat} (hn : 0 < n) : 0 < short n := by
20 unfold short; split <;> omega
21
22private theorem hit_four {n : Nat} (hr : n%9 = 4) : HitsTwoModNine n := by
23 apply short_lifts
24 exact ⟨0, by change short n % 9 = 2; unfold short; split <;> omega⟩
25
26/-- An odd shortcut turns n+1 = a·(2u) into short(n)+1 = (3a)·u.
27The factor u strictly decreases even while the Collatz value itself grows. -/
28private theorem hit_eight_aux (z : Nat) :
29 ∀ a n : Nat, a%2 = 1 → a*z = n+1 → n%9 = 8 → HitsTwoModNine n := by
30 induction z using Nat.strongRecOn with
31 | ind z ih =>
32 intro a n ha hz hr
33 by_cases he : n%2 = 0
34 · apply short_lifts
35 apply hit_four
36 simp only [short, he, ite_true]; omega
37 · have evenz : z%2 = 0 := by
38 have h := congrArg (fun k => k%2) hz
39 simp only [Nat.mul_mod a z 2, ha, Nat.one_mul, Nat.mod_mod] at h
40 omega
41 have posz : 0 < z := by
42 cases z with
43 | zero => simp at hz
44 | succ z => omega
45 have za : 2*(z/2) = z := by omega
46 have hp : 2*(a*(z/2)) = n+1 := by
47 calc
48 2*(a*(z/2)) = a*(2*(z/2)) := by ac_rfl
49 _ = n+1 := by rw [za, hz]
50 apply short_lifts
51 apply ih (z/2) (by omega) (3*a) (short n)
52 · omega
53 · rw [Nat.mul_assoc]
54 simp only [short, he, ite_false]
55 omega
56 · simp only [short, he, ite_false]; omega
57
58private theorem hit_eight {n : Nat} (hr : n%9 = 8) : HitsTwoModNine n :=
59 hit_eight_aux (n+1) 1 n (by decide) (Nat.one_mul _) hr
60
61private theorem hit_seven {n : Nat} (hr : n%9 = 7) : HitsTwoModNine n := by
62 apply short_lifts
63 have h : short n%9 = 2 ∨ short n%9 = 8 := by unfold short; split <;> omega
64 rcases h with target | eight
65 · exact ⟨0, target⟩
66 · exact hit_eight eight
67
68private theorem hit_five {n : Nat} (hr : n%9 = 5) : HitsTwoModNine n := by
69 apply short_lifts
70 have h : short n%9 = 7 ∨ short n%9 = 8 := by unfold short; split <;> omega
71 exact h.elim hit_seven hit_eight
72
73private theorem hit_one_residue {n : Nat} (hr : n%9 = 1) : HitsTwoModNine n := by
74 apply short_lifts
75 have h : short n%9 = 2 ∨ short n%9 = 5 := by unfold short; split <;> omega
76 exact h.elim (fun h => ⟨0,h⟩) hit_five
77
78/-- Raw-rule version of Monks et al., Corollary 5.8 (2013). -/
79theorem every_orbit_hits_two_mod_nine (n : Nat) (hn : 0 < n) : HitsTwoModNine n := by
80 induction n using Nat.strongRecOn with
81 | ind n ih =>
82 by_cases div3 : n%3 = 0
83 · apply short_lifts
84 by_cases he : n%2 = 0
85 · apply ih (short n) _ (short_pos hn)
86 simp only [short, he, ite_true]; omega
87 · apply hit_five
88 simp only [short, he, ite_false]; omega
89 · have opts : n%9 = 1 ∨ n%9 = 2 ∨ n%9 = 4 ∨ n%9 = 5 ∨ n%9 = 7 ∨ n%9 = 8 := by omega
90 rcases opts with h|h|h|h|h|h
91 · exact hit_one_residue h
92 · exact ⟨0,h⟩
93 · exact hit_four h
94 · exact hit_five h
95 · exact hit_seven h
96 · exact hit_eight h
97
98theorem claim_iff_two_mod_nine : Claim ↔ ∀ y : Nat, y%9 = 2 → ReachesOne y := by
99 constructor
100 · intro goal y hy
101 exact goal _ (by omega)
102 · intro checkpoints n hn
103 obtain ⟨s, hs⟩ := every_orbit_hits_two_mod_nine n hn
104 obtain ⟨t, ht⟩ := checkpoints _ hs
105 exact ⟨s+t, by rw [orbit_add]; exact ht⟩
106
107/-- The smaller odd predecessor always sends us back to the same first checkpoint. -/
108theorem predecessor_first_checkpoint (k : Nat) :
109 6*k+1 < 9*k+2 ∧ orbit 2 (6*k+1) = 9*k+2 ∧
110 ∀ t : Fin 2, orbit t.val (6*k+1) % 9 ≠ 2 := by
111 have a : step (6*k+1) = 2*(9*k+2) := by
112 rw [step_odd (by omega : (6*k+1)%2 = 1)]; omega
113 refine ⟨by omega, by simp only [orbit, a, step_double], ?_⟩
114 intro t
115 have casesT : t.val = 0 ∨ t.val = 1 := by omega
116 rcases casesT with h | h
117 · simp only [h, orbit]; omega
118 · simp only [h, orbit, a]; omega
119
120#print axioms predecessor_first_checkpoint
121#print axioms every_orbit_hits_two_mod_nine
122#print axioms claim_iff_two_mod_nine
123
124end CollatzRoute