Skip to content

Commit c6c82b3

Browse files
committed
odd, even
1 parent 0ecdc36 commit c6c82b3

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

CollatzFunction/NonHalt/Even.lean

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ lemma B_even (n: ℕ) (h_even : Even n): ∀ (i: ℕ)(l r: List Γ)(init_cfg: Cf
99
nth_cfg init_cfg i = ⟨B, ⟨one,
1010
Turing.ListBlank.mk (zero :: l),
1111
Turing.ListBlank.mk (List.replicate n one ++ zero :: r)⟩⟩ →
12-
∃ j>i, nth_cfg init_cfg j = ⟨A, ⟨zero,
12+
nth_cfg init_cfg (i+ (n^2)/2 + 7 * n/2 + 4) = ⟨A, ⟨zero,
1313
Turing.ListBlank.mk (List.replicate (1+n/2) one ++ l),
1414
Turing.ListBlank.mk (List.replicate (1+n/2) one ++ r)⟩⟩
1515
:= by
@@ -21,23 +21,18 @@ cases n with
2121
forward h
2222
forward h
2323
forward h
24-
use (4+i)
24+
ring_nf at *
2525
simp [h]
2626
| succ n => cases n with
2727
| zero => tauto
2828
| succ n => ring_nf at h
2929
apply B_step at h
3030
specialize IH n (by omega)
3131
apply IH at h
32-
. obtain ⟨j, _, h⟩ := h
33-
use j
34-
constructor
35-
any_goals omega
32+
. ring_nf at *
33+
have g : 4 + i + (4 + n * 4 + n ^ 2) / 2 + (14 + n * 7) / 2 = (13 + i + n * 2 + n ^ 2 / 2 + n * 7 / 2) := by omega
34+
rw [g]
3635
simp [h]
37-
ring_nf
38-
have h : (2+n)/2 = n/2+1 := by omega
39-
rw [h]
40-
ring_nf
4136
rw [List.append_cons]
4237
rw [← List.replicate_one]
4338
rw [List.replicate_append_replicate]

CollatzFunction/NonHalt/Main.lean

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ cases n with
4545
split_ifs <;> rename_i g
4646
. rw [← (ListBlank_empty_eq_single_zero (List.replicate n one))] at h
4747
apply B_even at h
48-
obtain ⟨j, _, h⟩ := h
4948
forward h
5049
rw [add_comm 1 (n/2)] at h
5150
rw [List.replicate_succ] at h
@@ -55,8 +54,7 @@ cases n with
5554
forward h
5655
apply recF at h
5756
forward h
58-
use (5 + j + n / 2 * 2)
59-
ring_nf at *
57+
use (10 + i + n ^ 2 / 2 + n * 7 / 2 + n / 2 * 2)
6058
simp [h]
6159
repeat any_goals apply And.intro
6260
. omega
@@ -71,6 +69,14 @@ cases n with
7169
simp
7270
ring_nf
7371
tauto
72+
. ring_nf
73+
apply congr
74+
any_goals rfl
75+
apply congr
76+
any_goals rfl
77+
apply congr
78+
any_goals rfl
79+
omega
7480
. rw [← Nat.even_iff] at g
7581
obtain ⟨a, g⟩ := g
7682
cases a with
@@ -81,7 +87,6 @@ cases n with
8187
| succ n =>
8288
rw [← (ListBlank_empty_eq_single_zero (List.replicate (n+1) one))] at h
8389
apply B_odd at h
84-
obtain ⟨j, _, h⟩ := h
8590
forward h
8691
have k : (2+n)/2 = n/2 + 1:= by omega
8792
rw [k] at h
@@ -93,7 +98,7 @@ cases n with
9398
apply G_to_J at h
9499
forward h
95100
forward h
96-
use (11 + j + n / 2 * 13 + (n / 2) ^ 2 * 4)
101+
use (16 + i + (8 + n * 9 + n ^ 2) / 2 + n / 2 * 13 + (n / 2) ^ 2 * 4)
97102
simp [h]
98103
repeat any_goals apply And.intro
99104
. omega

CollatzFunction/NonHalt/Odd.lean

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ lemma B_odd (n: ℕ) (h_odd : Odd n): ∀ (i: ℕ)(l r: List Γ)(init_cfg: Cfg),
4444
nth_cfg init_cfg i = ⟨B, ⟨one,
4545
Turing.ListBlank.mk (zero :: l),
4646
Turing.ListBlank.mk (List.replicate n one ++ zero :: r)⟩⟩ →
47-
∃ j>i, nth_cfg init_cfg j = ⟨C, ⟨zero,
47+
nth_cfg init_cfg (i + (n^2 + 7 * n)/ 2 + 4) = ⟨C, ⟨zero,
4848
Turing.ListBlank.mk (List.replicate ((n+1)/2) one ++ l),
4949
Turing.ListBlank.mk (List.replicate (1+(n+1)/2) one ++ r)⟩⟩
5050
:= by
@@ -62,30 +62,48 @@ cases n with
6262
forward h
6363
forward h
6464
forward h
65-
use (8+i)
65+
ring_nf at *
6666
simp [h]
6767
| succ n => ring_nf at h
6868
apply B_step at h
6969
specialize IH n (by omega)
7070
apply IH at h
71-
. obtain ⟨j, _, h⟩ := h
72-
use j
73-
constructor
74-
any_goals omega
71+
. ring_nf at *
72+
have g : (4 + i + (18 + n * 11 + n ^ 2) / 2) =
73+
(13 + i + n * 2 + (n * 7 + n ^ 2) / 2) := by omega
74+
rw [g]
7575
simp [h]
76-
ring_nf
77-
have h : (3+n)/2 = (1+n)/2+1 := by omega
78-
rw [h]
79-
ring_nf
80-
rw [List.append_cons]
81-
rw [← List.replicate_one]
82-
rw [List.replicate_append_replicate]
83-
ring_nf
84-
rw [List.append_cons]
85-
rw [← List.replicate_one]
86-
rw [List.replicate_append_replicate]
87-
ring_nf
88-
tauto
76+
constructor
77+
. rw [List.append_cons]
78+
rw [← List.replicate_one]
79+
rw [List.replicate_append_replicate]
80+
ring_nf
81+
apply congr
82+
any_goals rfl
83+
apply congr
84+
any_goals rfl
85+
apply congr
86+
any_goals rfl
87+
apply congr
88+
any_goals rfl
89+
apply congr
90+
any_goals rfl
91+
omega
92+
. rw [List.append_cons]
93+
rw [← List.replicate_one]
94+
rw [List.replicate_append_replicate]
95+
ring_nf
96+
apply congr
97+
any_goals rfl
98+
apply congr
99+
any_goals rfl
100+
apply congr
101+
any_goals rfl
102+
apply congr
103+
any_goals rfl
104+
apply congr
105+
any_goals rfl
106+
omega
89107
. obtain ⟨k, h_odd⟩ := h_odd
90108
cases k with
91109
| zero => omega

0 commit comments

Comments
 (0)