-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollatz_#1.lean
More file actions
87 lines (76 loc) · 2.42 KB
/
Collatz_#1.lean
File metadata and controls
87 lines (76 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Mathlib.Tactic.Ring
import Mathlib.Tactic.Linarith
import Mathlib.Data.Int.Basic
import Mathlib.Tactic.LinearCombination
/-
1. DEFINITIONS
'lift' tracks the accumulation of +1s (The Residue).
'IsBalanced' tracks the structural conservation of 1.
-/
def lift : List ℕ → ℤ
| [] => 0
| (k :: ks) => (2 : ℤ)^k * (lift ks) + (3 : ℤ)^(ks.length)
def IsBalanced (n : ℤ) (K : ℕ) (ks : List ℕ) : Prop :=
(3 : ℤ)^(ks.length) * n + lift ks = (2 : ℤ)^K
/-
2. THE UNIVERSAL BRIDGE
Proves that if the successor is balanced, the original number is balanced.
This allows the identity to flow backward from 1 to any n.
-/
theorem universal_balance (n n_next : ℤ) (k : ℕ) (ks : List ℕ) (K : ℕ)
(h_step : 3 * n + 1 = (2 : ℤ)^k * n_next)
(h_next_bal : IsBalanced n_next K ks) :
IsBalanced n (K + k) (k :: ks) :=
by
unfold IsBalanced lift
set m := ks.length
-- Explicitly bridge the list length to (m + 1)
have h_len : (k :: ks).length = m + 1 := by simp [List.length, m]
rw [h_len]
-- Rewrite the power of 3
have h_pow3 : (3 : ℤ)^(m + 1) = 3 * (3 : ℤ)^m := by ring
rw [h_pow3]
-- Collapse the algebra
unfold IsBalanced at h_next_bal
linear_combination (3 : ℤ)^m * h_step + (2 : ℤ)^k * h_next_bal
/-
3. THE UNIQUENESS OF THE RESIDUE (The Deterministic Residue)
Proves that for a fixed n and path ks, there is only one possible R.
-/
theorem uniqueness_of_residue (n : ℤ) (K : ℕ) (ks : List ℕ) (R1 R2 : ℤ) :
(3^ks.length * n + R1 = 2^K) →
(3^ks.length * n + R2 = 2^K) →
R1 = R2 :=
by
intro h1 h2
-- Since both expressions equal 2^K, they are equal to each other
have h : 3^ks.length * n + R1 = 3^ks.length * n + R2 := by rw [h1, h2]
-- Subtracting the shared term 3^m * n proves R1 = R2
linarith
/-
4. THE TERMINAL STATE
Proves that once complexity m=0, n must be a power of 2.
-/
theorem terminal_state (n : ℤ) (K : ℕ) (h_bal : IsBalanced n K []) :
n = (2 : ℤ)^K :=
by
unfold IsBalanced lift at h_bal
simp at h_bal
exact h_bal
/-
5. THE PARITY EXIT
Proves that for odd integers, n = 2^K implies n = 1.
-/
theorem odd_power_of_two_is_one (n : ℤ) (K : ℕ) (h_odd : n % 2 = 1) (h_pow : n = (2 : ℤ)^K) :
n = 1 :=
by
cases K with
| zero =>
rw [h_pow]
norm_num
| succ k =>
have h_even : (2 : ℤ)^(k + 1) % 2 = 0 := by
rw [pow_succ]
simp
rw [← h_pow, h_odd] at h_even
norm_num at h_even