Imports
/-
Copyright (c) 2026 Google LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
module
public import Cryptids.WeakCollatz75
public import Cryptids.Propositions
Semantics of weak_collatz_75 (WeakCollatz75)
Links blank-tape halting of the 75-state machine weakCollatz75
(halts_weakCollatz75_iff_bounded_cycle) to:
Constructive nontrivial cycle existence (halts_weakCollatz75_iff_exists_cycle, zero
Classical.choice): via a constructive finite-pigeonhole reduction on the cycle maximum M
showing that any positive cycle terras^[k] x = x outside {1, 2} has a member M ≥ 3 whose
period j satisfies 1 ≤ j ≤ M - 2 ≤ M;
Constructive Böhm–Sontacchi (1978) Diophantine cycle equation
(halts_weakCollatz75_iff_bohmSontacchi, zero Classical.choice): connecting halting directly
to (2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
(the #1 audited paper on ccchallenge.org);
Tao's Weak Collatz Conjecture (halts_weakCollatz75_iff_not_weakCollatz):
Halts weakCollatz75 ↔ ¬ WeakCollatzConjecture.
@[expose] public sectionnamespace ConjectureMachines.WeakCollatz75private def findEq (f : ℕ → ℕ) (target : ℕ) : ℕ → Option ℕ
| 0 => if f 0 = target then some 0 else none
| r + 1 =>
match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else noneprivate theorem findEq_some_spec (f : ℕ → ℕ) (target r i : ℕ)
(h : findEq f target r = some i) :
i ≤ r ∧ f i = target := f:ℕ → ℕtarget:ℕr:ℕi:ℕh:findEq f target r = some i⊢ i ≤ r ∧ f i = target
induction r generalizing i with
f:ℕ → ℕtarget:ℕi:ℕh:findEq f target 0 = some i⊢ i ≤ 0 ∧ f i = target
f:ℕ → ℕtarget:ℕi:ℕh:(if f 0 = target then some 0 else none) = some i⊢ i ≤ 0 ∧ f i = target
f:ℕ → ℕtarget:ℕi:ℕh0:f 0 = targeth:some 0 = some i⊢ i ≤ 0 ∧ f i = target
f:ℕ → ℕtarget:ℕi:ℕh0:f 0 = targeth:some 0 = some i⊢ i ≤ 0 ∧ f i = target f:ℕ → ℕtarget:ℕi:ℕh0:f 0 = targethi:0 = i⊢ i ≤ 0 ∧ f i = target
f:ℕ → ℕtarget:ℕh0:f 0 = target⊢ 0 ≤ 0 ∧ f 0 = target
All goals completed! 🐙
f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕh:findEq f target (r + 1) = some i⊢ i ≤ r + 1 ∧ f i = target
f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕh:(match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
some i⊢ i ≤ r + 1 ∧ f i = target
cases hprev : findEq f target r with
f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕh:(match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
some ij:ℕhprev:findEq f target r = some j⊢ i ≤ r + 1 ∧ f i = target
succ.some f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕj:ℕh:(match some j with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
some ihprev:findEq f target r = some j⊢ i ≤ r + 1 ∧ f i = target
injection h with hij succ.some f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕj:ℕhprev:findEq f target r = some jhij:j = i⊢ i ≤ r + 1 ∧ f i = target
subst hij succ.some f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targetj:ℕhprev:findEq f target r = some j⊢ j ≤ r + 1 ∧ f j = target
rcases ih j hprev with ⟨hjr, hfj⟩ succ.some f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targetj:ℕhprev:findEq f target r = some jhjr:j ≤ rhfj:f j = target⊢ j ≤ r + 1 ∧ f j = target
exact ⟨by f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targetj:ℕhprev:findEq f target r = some jhjr:j ≤ rhfj:f j = target⊢ j ≤ r + 1 omega All goals completed! 🐙, hfj⟩
| none => succ.none f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕh:(match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
some ihprev:findEq f target r = none⊢ i ≤ r + 1 ∧ f i = target
rw [hprev succ.none f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕh:(match none with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
some ihprev:findEq f target r = none⊢ i ≤ r + 1 ∧ f i = target] at h succ.none f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕh:(match none with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
some ihprev:findEq f target r = none⊢ i ≤ r + 1 ∧ f i = target
split_ifs at h with hr1 pos f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕhprev:findEq f target r = nonehr1:f (r + 1) = targeth:(match none with
| some i => some i
| none => some (r + 1)) =
some i⊢ i ≤ r + 1 ∧ f i = target
· pos f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕhprev:findEq f target r = nonehr1:f (r + 1) = targeth:(match none with
| some i => some i
| none => some (r + 1)) =
some i⊢ i ≤ r + 1 ∧ f i = target injection h with hi pos f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targeti:ℕhprev:findEq f target r = nonehr1:f (r + 1) = targethi:r + 1 = i⊢ i ≤ r + 1 ∧ f i = target
subst hi pos f:ℕ → ℕtarget:ℕr:ℕih:∀ (i : ℕ), findEq f target r = some i → i ≤ r ∧ f i = targethprev:findEq f target r = nonehr1:f (r + 1) = target⊢ r + 1 ≤ r + 1 ∧ f (r + 1) = target
exact ⟨Nat.le_refl _, hr1⟩ All goals completed! 🐙private theorem findEq_none_spec (f : ℕ → ℕ) (target r : ℕ)
(h : findEq f target r = none) :
∀ i : ℕ, i ≤ r → f i ≠ target := by f:ℕ → ℕtarget:ℕr:ℕh:findEq f target r = none⊢ ∀ i ≤ r, f i ≠ target
induction r with
| zero => zero f:ℕ → ℕtarget:ℕh:findEq f target 0 = none⊢ ∀ i ≤ 0, f i ≠ target
dsimp [findEq] at h zero f:ℕ → ℕtarget:ℕh:(if f 0 = target then some 0 else none) = none⊢ ∀ i ≤ 0, f i ≠ target
intro i hi zero f:ℕ → ℕtarget:ℕh:(if f 0 = target then some 0 else none) = nonei:ℕhi:i ≤ 0⊢ f i ≠ target
have hi0 : i = 0 := by f:ℕ → ℕtarget:ℕr:ℕh:findEq f target r = none⊢ ∀ i ≤ r, f i ≠ target omega zero f:ℕ → ℕtarget:ℕh:(if f 0 = target then some 0 else none) = nonei:ℕhi:i ≤ 0hi0:i = 0⊢ f i ≠ target
subst hi0 zero f:ℕ → ℕtarget:ℕh:(if f 0 = target then some 0 else none) = nonehi:0 ≤ 0⊢ f 0 ≠ target
split_ifs at h with h0 neg f:ℕ → ℕtarget:ℕhi:0 ≤ 0h0:¬f 0 = targeth:none = none⊢ f 0 ≠ target
exact h0 All goals completed! 🐙
| succ r ih => succ f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targeth:findEq f target (r + 1) = none⊢ ∀ i ≤ r + 1, f i ≠ target
dsimp [findEq] at h succ f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targeth:(match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
none⊢ ∀ i ≤ r + 1, f i ≠ target
cases hprev : findEq f target r with
| some j => succ.some f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targeth:(match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
nonej:ℕhprev:findEq f target r = some j⊢ ∀ i ≤ r + 1, f i ≠ target
rw [hprev succ.some f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targetj:ℕh:(match some j with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
nonehprev:findEq f target r = some j⊢ ∀ i ≤ r + 1, f i ≠ target] at h succ.some f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targetj:ℕh:(match some j with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
nonehprev:findEq f target r = some j⊢ ∀ i ≤ r + 1, f i ≠ target
cases h All goals completed! 🐙
| none => succ.none f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targeth:(match findEq f target r with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
nonehprev:findEq f target r = none⊢ ∀ i ≤ r + 1, f i ≠ target
rw [hprev succ.none f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targeth:(match none with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
nonehprev:findEq f target r = none⊢ ∀ i ≤ r + 1, f i ≠ target] at h succ.none f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targeth:(match none with
| some i => some i
| none => if f (r + 1) = target then some (r + 1) else none) =
nonehprev:findEq f target r = none⊢ ∀ i ≤ r + 1, f i ≠ target
split_ifs at h with hr1 neg f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
none⊢ ∀ i ≤ r + 1, f i ≠ target
intro i hi neg f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1⊢ f i ≠ target
rcases Nat.lt_or_ge i (r + 1) with hlt | hge neg.inl f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1hlt:i < r + 1⊢ f i ≠ targetneg.inr f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1hge:i ≥ r + 1⊢ f i ≠ target
· neg.inl f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1hlt:i < r + 1⊢ f i ≠ target exact ih hprev i (by f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1hlt:i < r + 1⊢ i ≤ r omega All goals completed! 🐙)
· neg.inr f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1hge:i ≥ r + 1⊢ f i ≠ target have hieq : i = r + 1 := by f:ℕ → ℕtarget:ℕr:ℕh:findEq f target r = none⊢ ∀ i ≤ r, f i ≠ target omega neg.inr f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonei:ℕhi:i ≤ r + 1hge:i ≥ r + 1hieq:i = r + 1⊢ f i ≠ target
subst hieq neg.inr f:ℕ → ℕtarget:ℕr:ℕih:findEq f target r = none → ∀ i ≤ r, f i ≠ targethprev:findEq f target r = nonehr1:¬f (r + 1) = targeth:(match none with
| some i => some i
| none => none) =
nonehi:r + 1 ≤ r + 1hge:r + 1 ≥ r + 1⊢ f (r + 1) ≠ target
exact hr1 All goals completed! 🐙
Constructive finite pigeonhole principle on ℕ (zero Classical.choice).
theorem nat_pigeonhole_constructive (N : ℕ) :
∀ f : ℕ → ℕ, (∀ i : ℕ, i ≤ N + 1 → f i < N + 1) →
∃ a b : ℕ, a < b ∧ b ≤ N + 1 ∧ f a = f b := by N:ℕ⊢ ∀ (f : ℕ → ℕ), (∀ i ≤ N + 1, f i < N + 1) → ∃ a b, a < b ∧ b ≤ N + 1 ∧ f a = f b
induction N with
| zero => zero ⊢ ∀ (f : ℕ → ℕ), (∀ i ≤ 0 + 1, f i < 0 + 1) → ∃ a b, a < b ∧ b ≤ 0 + 1 ∧ f a = f b
intro f hf zero f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1⊢ ∃ a b, a < b ∧ b ≤ 0 + 1 ∧ f a = f b
have h0 : f 0 < 1 := hf 0 (by f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1⊢ 0 ≤ 0 + 1 omega All goals completed! 🐙) zero f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1h0:f 0 < 1⊢ ∃ a b, a < b ∧ b ≤ 0 + 1 ∧ f a = f b
have h1 : f 1 < 1 := hf 1 (by f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1h0:f 0 < 1⊢ 1 ≤ 0 + 1 omega All goals completed! 🐙) zero f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1h0:f 0 < 1h1:f 1 < 1⊢ ∃ a b, a < b ∧ b ≤ 0 + 1 ∧ f a = f b
exact ⟨0, 1, by f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1h0:f 0 < 1h1:f 1 < 1⊢ 0 < 1 omega All goals completed! 🐙, by f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1h0:f 0 < 1h1:f 1 < 1⊢ 1 ≤ 0 + 1 omega All goals completed! 🐙, by f:ℕ → ℕhf:∀ i ≤ 0 + 1, f i < 0 + 1h0:f 0 < 1h1:f 1 < 1⊢ f 0 = f 1 omega All goals completed! 🐙⟩
| succ m ih => succ m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f b⊢ ∀ (f : ℕ → ℕ), (∀ i ≤ m + 1 + 1, f i < m + 1 + 1) → ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
intro f hf succ m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
cases hfind : findEq f (f (m + 2)) (m + 1) with
| some i => succ.some m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1i:ℕhfind:findEq f (f (m + 2)) (m + 1) = some i⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
rcases findEq_some_spec f (f (m + 2)) (m + 1) i hfind with ⟨hi_le, hfi⟩ succ.some m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1i:ℕhfind:findEq f (f (m + 2)) (m + 1) = some ihi_le:i ≤ m + 1hfi:f i = f (m + 2)⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
exact ⟨i, m + 2, by m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1i:ℕhfind:findEq f (f (m + 2)) (m + 1) = some ihi_le:i ≤ m + 1hfi:f i = f (m + 2)⊢ i < m + 2 omega All goals completed! 🐙, by m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1i:ℕhfind:findEq f (f (m + 2)) (m + 1) = some ihi_le:i ≤ m + 1hfi:f i = f (m + 2)⊢ m + 2 ≤ m + 1 + 1 omega All goals completed! 🐙, hfi⟩
| none => succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = none⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
have hne : ∀ i : ℕ, i ≤ m + 1 → f i ≠ f (m + 2) :=
findEq_none_spec f (f (m + 2)) (m + 1) hfind succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
let g : ℕ → ℕ := fun i => if f i < f (m + 2) then f i else f i - 1 succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
have hg_lt : ∀ i : ℕ, i ≤ m + 1 → g i < m + 1 := by N:ℕ⊢ ∀ (f : ℕ → ℕ), (∀ i ≤ N + 1, f i < N + 1) → ∃ a b, a < b ∧ b ≤ N + 1 ∧ f a = f b
intro i hi m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1⊢ g i < m + 1
have hfi_lt : f i < m + 2 := hf i (by m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1⊢ i ≤ m + 1 + 1 omega All goals completed! 🐙) m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2⊢ g i < m + 1
have hfi_ne : f i ≠ f (m + 2) := hne i hi m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)⊢ g i < m + 1
dsimp [g] m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)⊢ (if f i < f (m + 2) then f i else f i - 1) < m + 1
split_ifs with hlt pos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)hlt:f i < f (m + 2)⊢ f i < m + 1neg m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)hlt:¬f i < f (m + 2)⊢ f i - 1 < m + 1
· pos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)hlt:f i < f (m + 2)⊢ f i < m + 1 have hv_lt : f (m + 2) < m + 2 := hf (m + 2) (by m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)hlt:f i < f (m + 2)⊢ m + 2 ≤ m + 1 + 1 omega All goals completed! 🐙) pos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)hlt:f i < f (m + 2)hv_lt:f (m + 2) < m + 2⊢ f i < m + 1
omega All goals completed! 🐙
· neg m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1i:ℕhi:i ≤ m + 1hfi_lt:f i < m + 2hfi_ne:f i ≠ f (m + 2)hlt:¬f i < f (m + 2)⊢ f i - 1 < m + 1 omega succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
rcases ih g hg_lt with ⟨a, b, hab, hb_le, hgab⟩ succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hgab:g a = g b⊢ ∃ a b, a < b ∧ b ≤ m + 1 + 1 ∧ f a = f b
refine ⟨a, b, hab, by m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hgab:g a = g b⊢ b ≤ m + 1 + 1 omega All goals completed! 🐙, ?_⟩
have hfa_ne : f a ≠ f (m + 2) := hne a (by m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hgab:g a = g b⊢ a ≤ m + 1 omega All goals completed! 🐙) succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hgab:g a = g bhfa_ne:f a ≠ f (m + 2)⊢ f a = f b
have hfb_ne : f b ≠ f (m + 2) := hne b hb_le succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hgab:g a = g bhfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)⊢ f a = f b
dsimp [g] at hgab succ.none m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hgab:(if f a < f (m + 2) then f a else f a - 1) = if f b < f (m + 2) then f b else f b - 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)⊢ f a = f b
split_ifs at hgab with ha_lt hb_lt hb_lt2 pos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:f a < f (m + 2)hb_lt:f b < f (m + 2)hgab:f a = f b⊢ f a = f bneg m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:f a < f (m + 2)hb_lt:¬f b < f (m + 2)hgab:f a = f b - 1⊢ f a = f bpos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:¬f a < f (m + 2)hb_lt2:f b < f (m + 2)hgab:f a - 1 = f b⊢ f a = f bneg m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:¬f a < f (m + 2)hb_lt2:¬f b < f (m + 2)hgab:f a - 1 = f b - 1⊢ f a = f b <;> pos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:f a < f (m + 2)hb_lt:f b < f (m + 2)hgab:f a = f b⊢ f a = f bneg m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:f a < f (m + 2)hb_lt:¬f b < f (m + 2)hgab:f a = f b - 1⊢ f a = f bpos m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:¬f a < f (m + 2)hb_lt2:f b < f (m + 2)hgab:f a - 1 = f b⊢ f a = f bneg m:ℕih:∀ (f : ℕ → ℕ), (∀ i ≤ m + 1, f i < m + 1) → ∃ a b, a < b ∧ b ≤ m + 1 ∧ f a = f bf:ℕ → ℕhf:∀ i ≤ m + 1 + 1, f i < m + 1 + 1hfind:findEq f (f (m + 2)) (m + 1) = nonehne:∀ i ≤ m + 1, f i ≠ f (m + 2)g:ℕ → ℕ := fun i ↦ if f i < f (m + 2) then f i else f i - 1hg_lt:∀ i ≤ m + 1, g i < m + 1a:ℕb:ℕhab:a < bhb_le:b ≤ m + 1hfa_ne:f a ≠ f (m + 2)hfb_ne:f b ≠ f (m + 2)ha_lt:¬f a < f (m + 2)hb_lt2:¬f b < f (m + 2)hgab:f a - 1 = f b - 1⊢ f a = f b omega All goals completed! 🐙private theorem terras_le_two_inv (z : ℕ) (hz : z ≤ 2) : terras z ≤ 2 := by z:ℕhz:z ≤ 2⊢ terras z ≤ 2
unfold terras z:ℕhz:z ≤ 2⊢ (if z % 2 = 0 then z / 2 else (3 * z + 1) / 2) ≤ 2
split_ifs pos z:ℕhz:z ≤ 2h✝:z % 2 = 0⊢ z / 2 ≤ 2neg z:ℕhz:z ≤ 2h✝:¬z % 2 = 0⊢ (3 * z + 1) / 2 ≤ 2 <;> pos z:ℕhz:z ≤ 2h✝:z % 2 = 0⊢ z / 2 ≤ 2neg z:ℕhz:z ≤ 2h✝:¬z % 2 = 0⊢ (3 * z + 1) / 2 ≤ 2 omega All goals completed! 🐙private theorem terras_iterate_le_two (t z : ℕ) (hz : z ≤ 2) : terras^[t] z ≤ 2 := by t:ℕz:ℕhz:z ≤ 2⊢ terras^[t] z ≤ 2
induction t generalizing z with
| zero => zero z:ℕhz:z ≤ 2⊢ terras^[0] z ≤ 2 exact hz All goals completed! 🐙
| succ t ih => succ t:ℕih:∀ z ≤ 2, terras^[t] z ≤ 2z:ℕhz:z ≤ 2⊢ terras^[t + 1] z ≤ 2
rw [Function.iterate_succ_apply succ t:ℕih:∀ z ≤ 2, terras^[t] z ≤ 2z:ℕhz:z ≤ 2⊢ terras^[t] (terras z) ≤ 2] succ t:ℕih:∀ z ≤ 2, terras^[t] z ≤ 2z:ℕhz:z ≤ 2⊢ terras^[t] (terras z) ≤ 2
exact ih (terras z) (terras_le_two_inv z hz) All goals completed! 🐙private theorem terras_iterate_mul_period (m k x : ℕ) (hcyc : terras^[k] x = x) :
terras^[m * k] x = x := by m:ℕk:ℕx:ℕhcyc:terras^[k] x = x⊢ terras^[m * k] x = x
induction m with
| zero => zero k:ℕx:ℕhcyc:terras^[k] x = x⊢ terras^[0 * k] x = x rw [Nat.zero_mul zero k:ℕx:ℕhcyc:terras^[k] x = x⊢ terras^[0] x = x] zero k:ℕx:ℕhcyc:terras^[k] x = x⊢ terras^[0] x = x; rfl All goals completed! 🐙
| succ m ih => succ k:ℕx:ℕhcyc:terras^[k] x = xm:ℕih:terras^[m * k] x = x⊢ terras^[(m + 1) * k] x = x
rw [Nat.succ_mul, succ k:ℕx:ℕhcyc:terras^[k] x = xm:ℕih:terras^[m * k] x = x⊢ terras^[m * k + k] x = x Nat.add_comm (m * k) k, succ k:ℕx:ℕhcyc:terras^[k] x = xm:ℕih:terras^[m * k] x = x⊢ terras^[k + m * k] x = x Function.iterate_add_apply, succ k:ℕx:ℕhcyc:terras^[k] x = xm:ℕih:terras^[m * k] x = x⊢ terras^[k] (terras^[m * k] x) = x ih, succ k:ℕx:ℕhcyc:terras^[k] x = xm:ℕih:terras^[m * k] x = x⊢ terras^[k] x = x hcyc succ k:ℕx:ℕhcyc:terras^[k] x = xm:ℕih:terras^[m * k] x = x⊢ x = x] All goals completed! 🐙private theorem terras_orbit_ge_three {x k : ℕ} (hx3 : 3 ≤ x) (hk1 : 1 ≤ k)
(hcyc : terras^[k] x = x) (i : ℕ) :
3 ≤ terras^[i] x := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕ⊢ 3 ≤ terras^[i] x
by_cases hge : 3 ≤ terras^[i] x pos x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:3 ≤ terras^[i] x⊢ 3 ≤ terras^[i] xneg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] x⊢ 3 ≤ terras^[i] x
· pos x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:3 ≤ terras^[i] x⊢ 3 ≤ terras^[i] x exact hge All goals completed! 🐙
· neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] x⊢ 3 ≤ terras^[i] x exfalso neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] x⊢ False
have hle2 : terras^[i] x ≤ 2 := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕ⊢ 3 ≤ terras^[i] x omega neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2⊢ False
have hik : i ≤ i * k := Nat.le_mul_of_pos_right i hk1 neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * k⊢ False
have hsplit : i * k = (i * k - i) + i := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕ⊢ 3 ≤ terras^[i] x omega neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * khsplit:i * k = i * k - i + i⊢ False
have hx_eq : terras^[i * k] x = x := terras_iterate_mul_period i k x hcyc neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * khsplit:i * k = i * k - i + ihx_eq:terras^[i * k] x = x⊢ False
rw [hsplit, neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * khsplit:i * k = i * k - i + ihx_eq:terras^[i * k - i + i] x = x⊢ False Function.iterate_add_apply neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * khsplit:i * k = i * k - i + ihx_eq:terras^[i * k - i] (terras^[i] x) = x⊢ False] at hx_eq neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * khsplit:i * k = i * k - i + ihx_eq:terras^[i * k - i] (terras^[i] x) = x⊢ False
have hx_le2 : terras^[i * k - i] (terras^[i] x) ≤ 2 :=
terras_iterate_le_two (i * k - i) (terras^[i] x) hle2 neg x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xi:ℕhge:¬3 ≤ terras^[i] xhle2:terras^[i] x ≤ 2hik:i ≤ i * khsplit:i * k = i * k - i + ihx_eq:terras^[i * k - i] (terras^[i] x) = xhx_le2:terras^[i * k - i] (terras^[i] x) ≤ 2⊢ False
omega All goals completed! 🐙private def orbitMax (x : ℕ) : ℕ → ℕ
| 0 => x
| r + 1 => max (orbitMax x r) (terras^[r + 1] x)private theorem orbitMax_spec (x r : ℕ) :
(∃ i : ℕ, i ≤ r ∧ terras^[i] x = orbitMax x r) ∧
(∀ i : ℕ, i ≤ r → terras^[i] x ≤ orbitMax x r) := by x:ℕr:ℕ⊢ (∃ i ≤ r, terras^[i] x = orbitMax x r) ∧ ∀ i ≤ r, terras^[i] x ≤ orbitMax x r
induction r with
| zero => zero x:ℕ⊢ (∃ i ≤ 0, terras^[i] x = orbitMax x 0) ∧ ∀ i ≤ 0, terras^[i] x ≤ orbitMax x 0
refine ⟨⟨0, Nat.le_refl 0, rfl⟩, ?_⟩ zero x:ℕ⊢ ∀ i ≤ 0, terras^[i] x ≤ orbitMax x 0
intro i hi zero x:ℕi:ℕhi:i ≤ 0⊢ terras^[i] x ≤ orbitMax x 0
have hi0 : i = 0 := by x:ℕr:ℕ⊢ (∃ i ≤ r, terras^[i] x = orbitMax x r) ∧ ∀ i ≤ r, terras^[i] x ≤ orbitMax x r omega zero x:ℕi:ℕhi:i ≤ 0hi0:i = 0⊢ terras^[i] x ≤ orbitMax x 0
subst hi0 zero x:ℕhi:0 ≤ 0⊢ terras^[0] x ≤ orbitMax x 0
exact Nat.le_refl x All goals completed! 🐙
| succ r ih => succ x:ℕr:ℕih:(∃ i ≤ r, terras^[i] x = orbitMax x r) ∧ ∀ i ≤ r, terras^[i] x ≤ orbitMax x r⊢ (∃ i ≤ r + 1, terras^[i] x = orbitMax x (r + 1)) ∧ ∀ i ≤ r + 1, terras^[i] x ≤ orbitMax x (r + 1)
rcases ih with ⟨⟨i0, hi0_le, hi0_eq⟩, hle⟩ succ x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x r⊢ (∃ i ≤ r + 1, terras^[i] x = orbitMax x (r + 1)) ∧ ∀ i ≤ r + 1, terras^[i] x ≤ orbitMax x (r + 1)
dsimp only [orbitMax] succ x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x r⊢ (∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x)) ∧
∀ i ≤ r + 1, terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x)
refine ⟨?_, ?_⟩ succ.refine_1 x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x r⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x)succ.refine_2 x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x r⊢ ∀ i ≤ r + 1, terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x)
· succ.refine_1 x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x r⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x) by_cases hcmp : orbitMax x r ≤ terras^[r + 1] x pos x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:orbitMax x r ≤ terras^[r + 1] x⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x)neg x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] x⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x)
· pos x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:orbitMax x r ≤ terras^[r + 1] x⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x) exact ⟨r + 1, Nat.le_refl _, (Nat.max_eq_right hcmp).symm⟩ All goals completed! 🐙
· neg x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] x⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x) have hle' : terras^[r + 1] x ≤ orbitMax x r := by x:ℕr:ℕ⊢ (∃ i ≤ r, terras^[i] x = orbitMax x r) ∧ ∀ i ≤ r, terras^[i] x ≤ orbitMax x r omega neg x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] xhle':terras^[r + 1] x ≤ orbitMax x r⊢ ∃ i ≤ r + 1, terras^[i] x = max (orbitMax x r) (terras^[r + 1] x)
exact ⟨i0, by x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] xhle':terras^[r + 1] x ≤ orbitMax x r⊢ i0 ≤ r + 1 omega All goals completed! 🐙, by x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] xhle':terras^[r + 1] x ≤ orbitMax x r⊢ terras^[i0] x = max (orbitMax x r) (terras^[r + 1] x) rw [Nat.max_eq_left hle', x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] xhle':terras^[r + 1] x ≤ orbitMax x r⊢ terras^[i0] x = orbitMax x r hi0_eq x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhcmp:¬orbitMax x r ≤ terras^[r + 1] xhle':terras^[r + 1] x ≤ orbitMax x r⊢ orbitMax x r = orbitMax x r] All goals completed! 🐙⟩
· succ.refine_2 x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x r⊢ ∀ i ≤ r + 1, terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x) intro i hi succ.refine_2 x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1⊢ terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x)
rcases Nat.lt_or_ge i (r + 1) with hlt | hge succ.refine_2.inl x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1hlt:i < r + 1⊢ terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x)succ.refine_2.inr x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1hge:i ≥ r + 1⊢ terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x)
· succ.refine_2.inl x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1hlt:i < r + 1⊢ terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x) exact le_trans (hle i (by x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1hlt:i < r + 1⊢ i ≤ r omega All goals completed! 🐙)) (Nat.le_max_left _ _)
· succ.refine_2.inr x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1hge:i ≥ r + 1⊢ terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x) have hieq : i = r + 1 := by x:ℕr:ℕ⊢ (∃ i ≤ r, terras^[i] x = orbitMax x r) ∧ ∀ i ≤ r, terras^[i] x ≤ orbitMax x r omega succ.refine_2.inr x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x ri:ℕhi:i ≤ r + 1hge:i ≥ r + 1hieq:i = r + 1⊢ terras^[i] x ≤ max (orbitMax x r) (terras^[r + 1] x)
subst hieq succ.refine_2.inr x:ℕr:ℕhle:∀ i ≤ r, terras^[i] x ≤ orbitMax x ri0:ℕhi0_le:i0 ≤ rhi0_eq:terras^[i0] x = orbitMax x rhi:r + 1 ≤ r + 1hge:r + 1 ≥ r + 1⊢ terras^[r + 1] x ≤ max (orbitMax x r) (terras^[r + 1] x)
exact Nat.le_max_right _ _ All goals completed! 🐙
Constructive extraction of the cycle maximum M ≥ 3 and bounded period 1 ≤ j ≤ M - 2
from any nontrivial positive cycle of terras (zero Classical.choice).
theorem exists_bounded_cycle_max {x k : ℕ} (hx3 : 3 ≤ x) (hk1 : 1 ≤ k)
(hcyc : terras^[k] x = x) :
∃ M j : ℕ, 3 ≤ M ∧ 1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧
(∀ t : ℕ, 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧
(∃ i : ℕ, i < k ∧ terras^[i] x = M) := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = x⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
let M := orbitMax x (k - 1) x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
rcases orbitMax_spec x (k - 1) with ⟨⟨i0, hi0_le, hi0_eq⟩, h_le_M⟩ x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hi0_M : terras^[i0] x = M := hi0_eq x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hM3 : 3 ≤ M := by
rw [← hi0_M x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = M⊢ 3 ≤ terras^[i0] x] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = M⊢ 3 ≤ terras^[i0] x
exact terras_orbit_ge_three hx3 hk1 hcyc i0 x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hM_cyc : terras^[k] M = M := by
rw [← hi0_M, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ M⊢ terras^[k] (terras^[i0] x) = terras^[i0] x ← Function.iterate_add_apply, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ M⊢ terras^[k + i0] x = terras^[i0] x Nat.add_comm k i0, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ M⊢ terras^[i0 + k] x = terras^[i0] x
Function.iterate_add_apply, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ M⊢ terras^[i0] (terras^[k] x) = terras^[i0] x hcyc x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ M⊢ terras^[i0] x = terras^[i0] x] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hM_iter_le : ∀ t : ℕ, terras^[t] M ≤ M := by
intro t x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕ⊢ terras^[t] M ≤ M
have ht_eq : terras^[t] M = terras^[t + i0] x := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = x⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
rw [← hi0_M, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕ⊢ terras^[t] (terras^[i0] x) = terras^[t + i0] x ← Function.iterate_add_apply x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕ⊢ terras^[t + i0] x = terras^[t + i0] x] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] x⊢ terras^[t] M ≤ M
rw [ht_eq x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] x⊢ terras^[t + i0] x ≤ M] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] x⊢ terras^[t + i0] x ≤ M
let s := t + i0 x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0⊢ terras^[t + i0] x ≤ M
change terras^[s] x ≤ M x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0⊢ terras^[s] x ≤ M
have hdiv : s = s % k + (s / k) * k := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = x⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hd := Nat.div_add_mod s k x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hd:k * (s / k) + s % k = s⊢ s = s % k + s / k * k
rw [Nat.mul_comm k (s / k), x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hd:s / k * k + s % k = s⊢ s = s % k + s / k * k Nat.add_comm x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hd:s % k + s / k * k = s⊢ s = s % k + s / k * k] at hd x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hd:s % k + s / k * k = s⊢ s = s % k + s / k * k
exact hd.symm x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * k⊢ terras^[s] x ≤ M
rw [hdiv, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * k⊢ terras^[s % k + s / k * k] x ≤ M Function.iterate_add_apply, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * k⊢ terras^[s % k] (terras^[s / k * k] x) ≤ M terras_iterate_mul_period (s / k) k x hcyc x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * k⊢ terras^[s % k] x ≤ M] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * k⊢ terras^[s % k] x ≤ M
have hmod_lt : s % k < k := Nat.mod_lt s hk1 x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * khmod_lt:s % k < k⊢ terras^[s % k] x ≤ M
exact h_le_M (s % k) (by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = Mt:ℕht_eq:terras^[t] M = terras^[t + i0] xs:ℕ := t + i0hdiv:s = s % k + s / k * khmod_lt:s % k < k⊢ s % k ≤ k - 1 omega All goals completed! 🐙) x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
let N := M - 3 x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
let f : ℕ → ℕ := fun t => terras^[t] M - 3 x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hf_lt : ∀ t : ℕ, t ≤ N + 1 → f t < N + 1 := by
intro t _ x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3t:ℕa✝:t ≤ N + 1⊢ f t < N + 1
have ht_ge3 : 3 ≤ terras^[t] M := terras_orbit_ge_three hM3 hk1 hM_cyc t x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3t:ℕa✝:t ≤ N + 1ht_ge3:3 ≤ terras^[t] M⊢ f t < N + 1
have ht_leM : terras^[t] M ≤ M := hM_iter_le t x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3t:ℕa✝:t ≤ N + 1ht_ge3:3 ≤ terras^[t] Mht_leM:terras^[t] M ≤ M⊢ f t < N + 1
dsimp [f, N] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3t:ℕa✝:t ≤ N + 1ht_ge3:3 ≤ terras^[t] Mht_leM:terras^[t] M ≤ M⊢ terras^[t] M - 3 < M - 3 + 1
omega x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
rcases nat_pigeonhole_constructive N f hf_lt with ⟨a, b, hab, hb_le, hfab⟩ x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f b⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have ha_ge3 : 3 ≤ terras^[a] M := terras_orbit_ge_three hM3 hk1 hM_cyc a x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hb_ge3 : 3 ≤ terras^[b] M := terras_orbit_ge_three hM3 hk1 hM_cyc b x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hab_eq : terras^[a] M = terras^[b] M := by
dsimp [f] at hfab x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:terras^[a] M - 3 = terras^[b] M - 3ha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] M⊢ terras^[a] M = terras^[b] M
omega x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
let j := b - a x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - a⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hj_pos : 1 ≤ j := by dsimp [j] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - a⊢ 1 ≤ b - a; omega x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ j⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hj_le : j ≤ M - 2 := by dsimp [j, N] at hb_le ⊢ x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ M - 3 + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ j⊢ b - a ≤ M - 2; omega x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hj_cyc : terras^[j] M = M := by
have happ := congrArg (fun z => terras^[a * (k - 1)] z) hab_eq x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1)] (terras^[a] M) = terras^[a * (k - 1)] (terras^[b] M)⊢ terras^[j] M = M
rw [← Function.iterate_add_apply, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1)] (terras^[b] M)⊢ terras^[j] M = M ← Function.iterate_add_apply x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] M⊢ terras^[j] M = M] at happ x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] M⊢ terras^[j] M = M
have hlhs : a * (k - 1) + a = a * k := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = x⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
have hk_eq : k - 1 + 1 = k := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = x⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M omega x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhk_eq:k - 1 + 1 = k⊢ a * (k - 1) + a = a * k
calc
a * (k - 1) + a = a * (k - 1) + a * 1 := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhk_eq:k - 1 + 1 = k⊢ a * (k - 1) + a = a * (k - 1) + a * 1 rw [Nat.mul_one x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhk_eq:k - 1 + 1 = k⊢ a * (k - 1) + a = a * (k - 1) + a] All goals completed! 🐙
_ = a * (k - 1 + 1) := (Nat.mul_add a (k - 1) 1).symm
_ = a * k := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhk_eq:k - 1 + 1 = k⊢ a * (k - 1 + 1) = a * k rw [hk_eq x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhk_eq:k - 1 + 1 = k⊢ a * k = a * k] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhlhs:a * (k - 1) + a = a * k⊢ terras^[j] M = M
have hrhs : a * (k - 1) + b = j + a * k := by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = x⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
dsimp [j] x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhlhs:a * (k - 1) + a = a * k⊢ a * (k - 1) + b = b - a + a * k
omega x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * (k - 1) + a] M = terras^[a * (k - 1) + b] Mhlhs:a * (k - 1) + a = a * khrhs:a * (k - 1) + b = j + a * k⊢ terras^[j] M = M
rw [hlhs, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * k] M = terras^[a * (k - 1) + b] Mhlhs:a * (k - 1) + a = a * khrhs:a * (k - 1) + b = j + a * k⊢ terras^[j] M = M hrhs, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * k] M = terras^[j + a * k] Mhlhs:a * (k - 1) + a = a * khrhs:a * (k - 1) + b = j + a * k⊢ terras^[j] M = M Function.iterate_add_apply, x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:terras^[a * k] M = terras^[j] (terras^[a * k] M)hlhs:a * (k - 1) + a = a * khrhs:a * (k - 1) + b = j + a * k⊢ terras^[j] M = M
terras_iterate_mul_period a k M hM_cyc x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:M = terras^[j] Mhlhs:a * (k - 1) + a = a * khrhs:a * (k - 1) + b = j + a * k⊢ terras^[j] M = M] at happ x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2happ:M = terras^[j] Mhlhs:a * (k - 1) + a = a * khrhs:a * (k - 1) + b = j + a * k⊢ terras^[j] M = M
exact happ.symm x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2hj_cyc:terras^[j] M = M⊢ ∃ M j,
3 ≤ M ∧
1 ≤ j ∧ j ≤ M - 2 ∧ terras^[j] M = M ∧ (∀ (t : ℕ), 3 ≤ terras^[t] M ∧ terras^[t] M ≤ M) ∧ ∃ i < k, terras^[i] x = M
exact ⟨M, j, hM3, hj_pos, hj_le, hj_cyc,
fun t => ⟨terras_orbit_ge_three hM3 hk1 hM_cyc t, hM_iter_le t⟩,
⟨i0, by x:ℕk:ℕhx3:3 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xM:ℕ := orbitMax x (k - 1)h_le_M:∀ i ≤ k - 1, terras^[i] x ≤ orbitMax x (k - 1)i0:ℕhi0_le:i0 ≤ k - 1hi0_eq:terras^[i0] x = orbitMax x (k - 1)hi0_M:terras^[i0] x = MhM3:3 ≤ MhM_cyc:terras^[k] M = MhM_iter_le:∀ (t : ℕ), terras^[t] M ≤ MN:ℕ := M - 3f:ℕ → ℕ := fun t ↦ terras^[t] M - 3hf_lt:∀ t ≤ N + 1, f t < N + 1a:ℕb:ℕhab:a < bhb_le:b ≤ N + 1hfab:f a = f bha_ge3:3 ≤ terras^[a] Mhb_ge3:3 ≤ terras^[b] Mhab_eq:terras^[a] M = terras^[b] Mj:ℕ := b - ahj_pos:1 ≤ jhj_le:j ≤ M - 2hj_cyc:terras^[j] M = M⊢ i0 < k omega All goals completed! 🐙, hi0_M⟩⟩private theorem bounded_cycle_iff_exists_cycle :
(∃ x j : ℕ, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x) ↔
(∃ x k : ℕ, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) := by ⊢ (∃ x j, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x) ↔ ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
constructor mp ⊢ (∃ x j, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x) → ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2mpr ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) → ∃ x j, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x
· mp ⊢ (∃ x j, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x) → ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2 rintro ⟨x, j, hx3, hj1, _, hcyc⟩ mp x:ℕj:ℕhx3:3 ≤ xhj1:1 ≤ jleft✝:j ≤ xhcyc:terras^[j] x = x⊢ ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
exact ⟨x, j, by x:ℕj:ℕhx3:3 ≤ xhj1:1 ≤ jleft✝:j ≤ xhcyc:terras^[j] x = x⊢ 1 ≤ x omega All goals completed! 🐙, hj1, hcyc, by x:ℕj:ℕhx3:3 ≤ xhj1:1 ≤ jleft✝:j ≤ xhcyc:terras^[j] x = x⊢ x ≠ 1 omega All goals completed! 🐙, by x:ℕj:ℕhx3:3 ≤ xhj1:1 ≤ jleft✝:j ≤ xhcyc:terras^[j] x = x⊢ x ≠ 2 omega All goals completed! 🐙⟩
· mpr ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) → ∃ x j, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x rintro ⟨x, k, hx1, hk1, hcyc, hxne1, hxne2⟩ mpr x:ℕk:ℕhx1:1 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xhxne1:x ≠ 1hxne2:x ≠ 2⊢ ∃ x j, 3 ≤ x ∧ 1 ≤ j ∧ j ≤ x ∧ terras^[j] x = x
rcases exists_bounded_cycle_max (by x:ℕk:ℕhx1:1 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xhxne1:x ≠ 1hxne2:x ≠ 2⊢ 3 ≤ x omega All goals completed! 🐙) hk1 hcyc with
⟨M, j, hM3, hj1, hjM, hj_cyc, -, -⟩
exact ⟨M, j, hM3, hj1, by x:ℕk:ℕhx1:1 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xhxne1:x ≠ 1hxne2:x ≠ 2M:ℕj:ℕhM3:3 ≤ Mhj1:1 ≤ jhjM:j ≤ M - 2hj_cyc:terras^[j] M = M⊢ j ≤ M omega All goals completed! 🐙, hj_cyc⟩
Constructive equivalence between weakCollatz75 blank-tape halting and the existence of a
nontrivial positive cycle of terras.
theorem halts_weakCollatz75_iff_exists_cycle :
ConjectureMachines.Halts weakCollatz75 ↔
∃ x k : ℕ, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2 := by ⊢ ConjectureMachines.Halts weakCollatz75 ↔ ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
exact halts_weakCollatz75_iff_bounded_cycle.trans bounded_cycle_iff_exists_cycle All goals completed! 🐙private theorem two_pow_pos (n : ℕ) : 0 < 2 ^ n := by n:ℕ⊢ 0 < 2 ^ n
induction n with
| zero => zero ⊢ 0 < 2 ^ 0 decide All goals completed! 🐙
| succ n ih => succ n:ℕih:0 < 2 ^ n⊢ 0 < 2 ^ (n + 1) rw [Nat.pow_succ succ n:ℕih:0 < 2 ^ n⊢ 0 < 2 ^ n * 2] succ n:ℕih:0 < 2 ^ n⊢ 0 < 2 ^ n * 2; omega All goals completed! 🐙private theorem three_pow_pos (n : ℕ) : 0 < 3 ^ n := by n:ℕ⊢ 0 < 3 ^ n
induction n with
| zero => zero ⊢ 0 < 3 ^ 0 decide All goals completed! 🐙
| succ n ih => succ n:ℕih:0 < 3 ^ n⊢ 0 < 3 ^ (n + 1) rw [Nat.pow_succ succ n:ℕih:0 < 3 ^ n⊢ 0 < 3 ^ n * 3] succ n:ℕih:0 < 3 ^ n⊢ 0 < 3 ^ n * 3; omega All goals completed! 🐙private theorem collatzCycleNum_eq_zero_iff (v : List ℕ) (hv : ∀ d ∈ v, d ≤ 1) :
collatzCycleNum v = 0 ↔ v.sum = 0 := by v:List ℕhv:∀ d ∈ v, d ≤ 1⊢ collatzCycleNum v = 0 ↔ v.sum = 0
induction v with
| nil => nil hv:∀ d ∈ [], d ≤ 1⊢ collatzCycleNum [] = 0 ↔ [].sum = 0 simp [collatzCycleNum] All goals completed! 🐙
| cons b rest ih => cons b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1⊢ collatzCycleNum (b :: rest) = 0 ↔ (b :: rest).sum = 0
have hb : b ≤ 1 := hv b List.mem_cons_self cons b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1hb:b ≤ 1⊢ collatzCycleNum (b :: rest) = 0 ↔ (b :: rest).sum = 0
have hrest := ih (fun d hd => hv d (List.mem_cons_of_mem b hd)) cons b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1hb:b ≤ 1hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0⊢ collatzCycleNum (b :: rest) = 0 ↔ (b :: rest).sum = 0
dsimp [collatzCycleNum] cons b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1hb:b ≤ 1hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0⊢ (if b = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ b + rest.sum = 0
rcases Nat.eq_zero_or_pos b with rfl | hb_pos cons.inl rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ (if 0 = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ 0 + rest.sum = 0cons.inr b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1hb:b ≤ 1hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hb_pos:b > 0⊢ (if b = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ b + rest.sum = 0
· cons.inl rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ (if 0 = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ 0 + rest.sum = 0 simp only [↓reduceIte, Nat.zero_add] cons.inl rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ 2 * collatzCycleNum rest = 0 ↔ rest.sum = 0
constructor cons.inl.mp rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ 2 * collatzCycleNum rest = 0 → rest.sum = 0cons.inl.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ rest.sum = 0 → 2 * collatzCycleNum rest = 0
· cons.inl.mp rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ 2 * collatzCycleNum rest = 0 → rest.sum = 0 intro h2 cons.inl.mp rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1h2:2 * collatzCycleNum rest = 0⊢ rest.sum = 0
exact hrest.mp (by rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1h2:2 * collatzCycleNum rest = 0⊢ collatzCycleNum rest = 0 omega All goals completed! 🐙)
· cons.inl.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1⊢ rest.sum = 0 → 2 * collatzCycleNum rest = 0 intro hs cons.inl.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1hs:rest.sum = 0⊢ 2 * collatzCycleNum rest = 0
rw [hrest.mpr hs cons.inl.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 0 :: rest, d ≤ 1hb:0 ≤ 1hs:rest.sum = 0⊢ 2 * 0 = 0] All goals completed! 🐙
· cons.inr b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1hb:b ≤ 1hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hb_pos:b > 0⊢ (if b = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ b + rest.sum = 0 have hb1 : b = 1 := by v:List ℕhv:∀ d ∈ v, d ≤ 1⊢ collatzCycleNum v = 0 ↔ v.sum = 0 omega cons.inr b:ℕrest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hv:∀ d ∈ b :: rest, d ≤ 1hb:b ≤ 1hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hb_pos:b > 0hb1:b = 1⊢ (if b = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ b + rest.sum = 0
subst hb1 cons.inr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0⊢ (if 1 = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ 1 + rest.sum = 0
have h1ne0 : ¬ ((1 : ℕ) = 0) := by v:List ℕhv:∀ d ∈ v, d ≤ 1⊢ collatzCycleNum v = 0 ↔ v.sum = 0 decide cons.inr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0⊢ (if 1 = 0 then 2 * collatzCycleNum rest else 3 ^ rest.sum + 2 * collatzCycleNum rest) = 0 ↔ 1 + rest.sum = 0
simp only [h1ne0, ↓reduceIte] cons.inr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 ↔ 1 + rest.sum = 0
have h3 : 0 < 3 ^ rest.sum := three_pow_pos rest.sum cons.inr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sum⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 ↔ 1 + rest.sum = 0
change 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 ↔ 1 + rest.sum = 0 cons.inr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sum⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 ↔ 1 + rest.sum = 0
constructor cons.inr.mp rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sum⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 → 1 + rest.sum = 0cons.inr.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sum⊢ 1 + rest.sum = 0 → 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 <;> cons.inr.mp rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sum⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 → 1 + rest.sum = 0cons.inr.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sum⊢ 1 + rest.sum = 0 → 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 intro h cons.inr.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sumh:1 + rest.sum = 0⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 <;> cons.inr.mp rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sumh:3 ^ rest.sum + 2 * collatzCycleNum rest = 0⊢ 1 + rest.sum = 0cons.inr.mpr rest:List ℕih:(∀ d ∈ rest, d ≤ 1) → (collatzCycleNum rest = 0 ↔ rest.sum = 0)hrest:collatzCycleNum rest = 0 ↔ rest.sum = 0hv:∀ d ∈ 1 :: rest, d ≤ 1hb:1 ≤ 1hb_pos:1 > 0h1ne0:¬1 = 0h3:0 < 3 ^ rest.sumh:1 + rest.sum = 0⊢ 3 ^ rest.sum + 2 * collatzCycleNum rest = 0 omega All goals completed! 🐙private theorem terrasParityWord_digits_le_one (n x d : ℕ)
(hd : d ∈ terrasParityWord n x) : d ≤ 1 := by n:ℕx:ℕd:ℕhd:d ∈ terrasParityWord n x⊢ d ≤ 1
induction n generalizing x with
| zero => zero d:ℕx:ℕhd:d ∈ terrasParityWord 0 x⊢ d ≤ 1 cases hd All goals completed! 🐙
| succ n ih => succ d:ℕn:ℕih:∀ (x : ℕ), d ∈ terrasParityWord n x → d ≤ 1x:ℕhd:d ∈ terrasParityWord (n + 1) x⊢ d ≤ 1
dsimp [terrasParityWord] at hd succ d:ℕn:ℕih:∀ (x : ℕ), d ∈ terrasParityWord n x → d ≤ 1x:ℕhd:d ∈ x % 2 :: terrasParityWord n (terras x)⊢ d ≤ 1
rw [List.mem_cons succ d:ℕn:ℕih:∀ (x : ℕ), d ∈ terrasParityWord n x → d ≤ 1x:ℕhd:d = x % 2 ∨ d ∈ terrasParityWord n (terras x)⊢ d ≤ 1] at hd succ d:ℕn:ℕih:∀ (x : ℕ), d ∈ terrasParityWord n x → d ≤ 1x:ℕhd:d = x % 2 ∨ d ∈ terrasParityWord n (terras x)⊢ d ≤ 1
rcases hd with rfl | htail succ.inl n:ℕx:ℕih:∀ (x_1 : ℕ), x % 2 ∈ terrasParityWord n x_1 → x % 2 ≤ 1⊢ x % 2 ≤ 1succ.inr d:ℕn:ℕih:∀ (x : ℕ), d ∈ terrasParityWord n x → d ≤ 1x:ℕhtail:d ∈ terrasParityWord n (terras x)⊢ d ≤ 1
· succ.inl n:ℕx:ℕih:∀ (x_1 : ℕ), x % 2 ∈ terrasParityWord n x_1 → x % 2 ≤ 1⊢ x % 2 ≤ 1 omega All goals completed! 🐙
· succ.inr d:ℕn:ℕih:∀ (x : ℕ), d ∈ terrasParityWord n x → d ≤ 1x:ℕhtail:d ∈ terrasParityWord n (terras x)⊢ d ≤ 1 exact ih (terras x) htail All goals completed! 🐙private theorem two_pow_mul_terras_iterate_eq (n x : ℕ) :
2 ^ n * terras^[n] x =
3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x) := by n:ℕx:ℕ⊢ 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)
induction n generalizing x with
| zero => zero x:ℕ⊢ 2 ^ 0 * terras^[0] x = 3 ^ (terrasParityWord 0 x).sum * x + collatzCycleNum (terrasParityWord 0 x)
simp [terrasParityWord, collatzCycleNum] All goals completed! 🐙
| succ n ih => succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕ⊢ 2 ^ (n + 1) * terras^[n + 1] x = 3 ^ (terrasParityWord (n + 1) x).sum * x + collatzCycleNum (terrasParityWord (n + 1) x)
rw [Function.iterate_succ_apply succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕ⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (terrasParityWord (n + 1) x).sum * x + collatzCycleNum (terrasParityWord (n + 1) x)] succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕ⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (terrasParityWord (n + 1) x).sum * x + collatzCycleNum (terrasParityWord (n + 1) x)
dsimp only [terrasParityWord, collatzCycleNum, List.sum_cons] succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕ⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
let rest := terrasParityWord n (terras x) succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
have hrec : 2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum rest :=
ih (terras x) succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum rest⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
rcases Nat.mod_two_eq_zero_or_one x with hev | hodd succ.inl n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))succ.inr n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
· succ.inl n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x)) have h2tx : 2 * terras x = x := by n:ℕx:ℕ⊢ 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x) unfold terras n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0⊢ (2 * if x % 2 = 0 then x / 2 else (3 * x + 1) / 2) = x; simp [hev] n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0⊢ 2 * (x / 2) = x; omega succ.inl n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
simp only [hev, ↓reduceIte, Nat.zero_add] succ.inl n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (terrasParityWord n (terras x)).sum * x + 2 * collatzCycleNum (terrasParityWord n (terras x))
calc
2 ^ (n + 1) * terras^[n] (terras x)
= 2 * (2 ^ n * terras^[n] (terras x)) := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 2 ^ (n + 1) * terras^[n] (terras x) = 2 * (2 ^ n * terras^[n] (terras x)) ring All goals completed! 🐙
_ = 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 2 * (2 ^ n * terras^[n] (terras x)) = 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) rw [hrec n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) = 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest)] All goals completed! 🐙
_ = 3 ^ rest.sum * (2 * terras x) + 2 * collatzCycleNum rest := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) = 3 ^ rest.sum * (2 * terras x) + 2 * collatzCycleNum rest ring All goals completed! 🐙
_ = 3 ^ rest.sum * x + 2 * collatzCycleNum rest := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 3 ^ rest.sum * (2 * terras x) + 2 * collatzCycleNum rest = 3 ^ rest.sum * x + 2 * collatzCycleNum rest rw [h2tx n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthev:x % 2 = 0h2tx:2 * terras x = x⊢ 3 ^ rest.sum * x + 2 * collatzCycleNum rest = 3 ^ rest.sum * x + 2 * collatzCycleNum rest] All goals completed! 🐙
· succ.inr n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x)) have h2tx : 2 * terras x = 3 * x + 1 := by n:ℕx:ℕ⊢ 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)
unfold terras n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1⊢ (2 * if x % 2 = 0 then x / 2 else (3 * x + 1) / 2) = 3 * x + 1
have hne : ¬ (x % 2 = 0) := by n:ℕx:ℕ⊢ 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x) omega n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1hne:¬x % 2 = 0⊢ (2 * if x % 2 = 0 then x / 2 else (3 * x + 1) / 2) = 3 * x + 1
simp [hne] n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1hne:¬x % 2 = 0⊢ 2 * ((3 * x + 1) / 2) = 3 * x + 1; omega succ.inr n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
have h1ne0 : ¬ ((1 : ℕ) = 0) := by n:ℕx:ℕ⊢ 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x) decide succ.inr n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (x % 2 + (terrasParityWord n (terras x)).sum) * x +
if x % 2 = 0 then 2 * collatzCycleNum (terrasParityWord n (terras x))
else 3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x))
simp only [hodd, h1ne0, ↓reduceIte] succ.inr n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 2 ^ (n + 1) * terras^[n] (terras x) =
3 ^ (1 + (terrasParityWord n (terras x)).sum) * x +
(3 ^ (terrasParityWord n (terras x)).sum + 2 * collatzCycleNum (terrasParityWord n (terras x)))
calc
2 ^ (n + 1) * terras^[n] (terras x)
= 2 * (2 ^ n * terras^[n] (terras x)) := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 2 ^ (n + 1) * terras^[n] (terras x) = 2 * (2 ^ n * terras^[n] (terras x)) ring All goals completed! 🐙
_ = 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 2 * (2 ^ n * terras^[n] (terras x)) = 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) rw [hrec n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) = 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest)] All goals completed! 🐙
_ = 3 ^ rest.sum * (2 * terras x) + 2 * collatzCycleNum rest := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 2 * (3 ^ rest.sum * terras x + collatzCycleNum rest) = 3 ^ rest.sum * (2 * terras x) + 2 * collatzCycleNum rest ring All goals completed! 🐙
_ = 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 3 ^ rest.sum * (2 * terras x) + 2 * collatzCycleNum rest = 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest rw [h2tx n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest = 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest] All goals completed! 🐙
_ = 3 ^ (1 + rest.sum) * x + (3 ^ rest.sum + 2 * collatzCycleNum rest) := by n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest =
3 ^ (1 + rest.sum) * x + (3 ^ rest.sum + 2 * collatzCycleNum rest)
rw [Nat.add_comm 1 rest.sum, n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest =
3 ^ (rest.sum + 1) * x + (3 ^ rest.sum + 2 * collatzCycleNum rest) Nat.pow_succ n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest = 3 ^ rest.sum * 3 * x + (3 ^ rest.sum + 2 * collatzCycleNum rest)] n:ℕih:∀ (x : ℕ), 2 ^ n * terras^[n] x = 3 ^ (terrasParityWord n x).sum * x + collatzCycleNum (terrasParityWord n x)x:ℕrest:List ℕ := terrasParityWord n (terras x)hrec:2 ^ n * terras^[n] (terras x) = 3 ^ rest.sum * terras x + collatzCycleNum resthodd:x % 2 = 1h2tx:2 * terras x = 3 * x + 1h1ne0:¬1 = 0⊢ 3 ^ rest.sum * (3 * x + 1) + 2 * collatzCycleNum rest = 3 ^ rest.sum * 3 * x + (3 ^ rest.sum + 2 * collatzCycleNum rest); ring All goals completed! 🐙private theorem terras_cycle_iff_bohmSontacchi {x n : ℕ} (hx : 1 ≤ x) (hn : 1 ≤ n) :
terras^[n] x = x ↔
(3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x =
collatzCycleNum (terrasParityWord n x)) := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
let v := terrasParityWord n x x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n x⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
let k := v.sum x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sum⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
change terras^[n] x = x ↔ (3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v) x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sum⊢ terras^[n] x = x ↔ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
have hid : 2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum v :=
two_pow_mul_terras_iterate_eq n x x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum v⊢ terras^[n] x = x ↔ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
have hzero := collatzCycleNum_eq_zero_iff v (terrasParityWord_digits_le_one n x) x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0⊢ terras^[n] x = x ↔ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
constructor mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0⊢ terras^[n] x = x → 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum vmpr x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v → terras^[n] x = x
· mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0⊢ terras^[n] x = x → 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v intro hcyc mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = x⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
have hid_cyc : 2 ^ n * x = 3 ^ k * x + collatzCycleNum v := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
calc
2 ^ n * x = 2 ^ n * terras^[n] x := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = x⊢ 2 ^ n * x = 2 ^ n * terras^[n] x rw [hcyc x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = x⊢ 2 ^ n * x = 2 ^ n * x] All goals completed! 🐙
_ = 3 ^ k * x + collatzCycleNum v := hid mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum v⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
have hnum_pos : 0 < collatzCycleNum v := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
by_cases hz : collatzCycleNum v = 0 pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhz:collatzCycleNum v = 0⊢ 0 < collatzCycleNum vneg x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhz:¬collatzCycleNum v = 0⊢ 0 < collatzCycleNum v
· pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhz:collatzCycleNum v = 0⊢ 0 < collatzCycleNum v have hk0 : k = 0 := hzero.mp hz pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhz:collatzCycleNum v = 0hk0:k = 0⊢ 0 < collatzCycleNum v
rw [hk0, pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ 0 * x + collatzCycleNum vhz:collatzCycleNum v = 0hk0:k = 0⊢ 0 < collatzCycleNum v hz pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 0 < collatzCycleNum v] at hid_cyc pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 0 < collatzCycleNum v
have h2gt1 : 2 ≤ 2 ^ n := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
rcases n with _ | m zero x:ℕhx:1 ≤ xhn:1 ≤ 0v:List ℕ := terrasParityWord 0 xk:ℕ := v.sumhid:2 ^ 0 * terras^[0] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[0] x = xhid_cyc:2 ^ 0 * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 2 ≤ 2 ^ 0succ x:ℕhx:1 ≤ xm:ℕhn:1 ≤ m + 1v:List ℕ := terrasParityWord (m + 1) xk:ℕ := v.sumhid:2 ^ (m + 1) * terras^[m + 1] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[m + 1] x = xhid_cyc:2 ^ (m + 1) * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 2 ≤ 2 ^ (m + 1)
· zero x:ℕhx:1 ≤ xhn:1 ≤ 0v:List ℕ := terrasParityWord 0 xk:ℕ := v.sumhid:2 ^ 0 * terras^[0] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[0] x = xhid_cyc:2 ^ 0 * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 2 ≤ 2 ^ 0 omega All goals completed! 🐙
· succ x:ℕhx:1 ≤ xm:ℕhn:1 ≤ m + 1v:List ℕ := terrasParityWord (m + 1) xk:ℕ := v.sumhid:2 ^ (m + 1) * terras^[m + 1] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[m + 1] x = xhid_cyc:2 ^ (m + 1) * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 2 ≤ 2 ^ (m + 1) rw [Nat.pow_succ succ x:ℕhx:1 ≤ xm:ℕhn:1 ≤ m + 1v:List ℕ := terrasParityWord (m + 1) xk:ℕ := v.sumhid:2 ^ (m + 1) * terras^[m + 1] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[m + 1] x = xhid_cyc:2 ^ (m + 1) * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 2 ≤ 2 ^ m * 2] succ x:ℕhx:1 ≤ xm:ℕhn:1 ≤ m + 1v:List ℕ := terrasParityWord (m + 1) xk:ℕ := v.sumhid:2 ^ (m + 1) * terras^[m + 1] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[m + 1] x = xhid_cyc:2 ^ (m + 1) * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0⊢ 2 ≤ 2 ^ m * 2; have := two_pow_pos m succ x:ℕhx:1 ≤ xm:ℕhn:1 ≤ m + 1v:List ℕ := terrasParityWord (m + 1) xk:ℕ := v.sumhid:2 ^ (m + 1) * terras^[m + 1] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[m + 1] x = xhid_cyc:2 ^ (m + 1) * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0this:0 < 2 ^ m⊢ 2 ≤ 2 ^ m * 2; omega pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0h2gt1:2 ≤ 2 ^ n⊢ 0 < collatzCycleNum v
have h2x : 2 * x ≤ 2 ^ n * x := Nat.mul_le_mul_right x h2gt1 pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ 0 * x + 0hz:collatzCycleNum v = 0hk0:k = 0h2gt1:2 ≤ 2 ^ nh2x:2 * x ≤ 2 ^ n * x⊢ 0 < collatzCycleNum v
omega All goals completed! 🐙
· neg x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhz:¬collatzCycleNum v = 0⊢ 0 < collatzCycleNum v omega mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum v⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
have hlt_pow : 3 ^ k < 2 ^ n := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
by_cases hle : 2 ^ n ≤ 3 ^ k pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhle:2 ^ n ≤ 3 ^ k⊢ 3 ^ k < 2 ^ nneg x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhle:¬2 ^ n ≤ 3 ^ k⊢ 3 ^ k < 2 ^ n
· pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhle:2 ^ n ≤ 3 ^ k⊢ 3 ^ k < 2 ^ n have hm : 2 ^ n * x ≤ 3 ^ k * x := Nat.mul_le_mul_right x hle pos x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhle:2 ^ n ≤ 3 ^ khm:2 ^ n * x ≤ 3 ^ k * x⊢ 3 ^ k < 2 ^ n
omega All goals completed! 🐙
· neg x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhle:¬2 ^ n ≤ 3 ^ k⊢ 3 ^ k < 2 ^ n omega mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhlt_pow:3 ^ k < 2 ^ n⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
have hprod : (2 ^ n - 3 ^ k) * x = collatzCycleNum v := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
rw [Nat.sub_mul, x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhlt_pow:3 ^ k < 2 ^ n⊢ 2 ^ n * x - 3 ^ k * x = collatzCycleNum v hid_cyc, x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhlt_pow:3 ^ k < 2 ^ n⊢ 3 ^ k * x + collatzCycleNum v - 3 ^ k * x = collatzCycleNum v Nat.add_sub_cancel_left x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhlt_pow:3 ^ k < 2 ^ n⊢ collatzCycleNum v = collatzCycleNum v] mp x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hcyc:terras^[n] x = xhid_cyc:2 ^ n * x = 3 ^ k * x + collatzCycleNum vhnum_pos:0 < collatzCycleNum vhlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum v⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v
exact ⟨hlt_pow, hprod⟩ All goals completed! 🐙
· mpr x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0⊢ 3 ^ k < 2 ^ n ∧ (2 ^ n - 3 ^ k) * x = collatzCycleNum v → terras^[n] x = x rintro ⟨hlt_pow, hprod⟩ mpr x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum v⊢ terras^[n] x = x
have hsub : (2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
rw [← Nat.add_mul, x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum v⊢ (2 ^ n - 3 ^ k + 3 ^ k) * x = 2 ^ n * x Nat.sub_add_cancel (Nat.le_of_lt hlt_pow) x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum v⊢ 2 ^ n * x = 2 ^ n * x] mpr x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum vhsub:(2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x⊢ terras^[n] x = x
have h2nx : 2 ^ n * terras^[n] x = 2 ^ n * x := by x:ℕn:ℕhx:1 ≤ xhn:1 ≤ n⊢ terras^[n] x = x ↔
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
rw [hid, x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum vhsub:(2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x⊢ 3 ^ k * x + collatzCycleNum v = 2 ^ n * x ← hprod, x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum vhsub:(2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x⊢ 3 ^ k * x + (2 ^ n - 3 ^ k) * x = 2 ^ n * x Nat.add_comm, x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum vhsub:(2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x⊢ (2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x hsub x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum vhsub:(2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * x⊢ 2 ^ n * x = 2 ^ n * x] mpr x:ℕn:ℕhx:1 ≤ xhn:1 ≤ nv:List ℕ := terrasParityWord n xk:ℕ := v.sumhid:2 ^ n * terras^[n] x = 3 ^ k * x + collatzCycleNum vhzero:collatzCycleNum v = 0 ↔ v.sum = 0hlt_pow:3 ^ k < 2 ^ nhprod:(2 ^ n - 3 ^ k) * x = collatzCycleNum vhsub:(2 ^ n - 3 ^ k) * x + 3 ^ k * x = 2 ^ n * xh2nx:2 ^ n * terras^[n] x = 2 ^ n * x⊢ terras^[n] x = x
exact Nat.eq_of_mul_eq_mul_left (two_pow_pos n) h2nx All goals completed! 🐙
Constructive equivalence between weakCollatz75 blank-tape halting and the Böhm–Sontacchi
(1978) Diophantine cycle equation on x ≥ 3 (zero Classical.choice).
theorem halts_weakCollatz75_iff_bohmSontacchi :
ConjectureMachines.Halts weakCollatz75 ↔
∃ x n : ℕ, 3 ≤ x ∧ 1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x =
collatzCycleNum (terrasParityWord n x) := by ⊢ ConjectureMachines.Halts weakCollatz75 ↔
∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
rw [halts_weakCollatz75_iff_exists_cycle ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) ↔
∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)] ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) ↔
∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
constructor mp ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) →
∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)mpr ⊢ (∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)) →
∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
· mp ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) →
∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x) rintro ⟨x, n, hx1, hn1, hcyc, hxne1, hxne2⟩ mp x:ℕn:ℕhx1:1 ≤ xhn1:1 ≤ nhcyc:terras^[n] x = xhxne1:x ≠ 1hxne2:x ≠ 2⊢ ∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
rcases (terras_cycle_iff_bohmSontacchi hx1 hn1).mp hcyc with ⟨hlt, hprod⟩ mp x:ℕn:ℕhx1:1 ≤ xhn1:1 ≤ nhcyc:terras^[n] x = xhxne1:x ≠ 1hxne2:x ≠ 2hlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)⊢ ∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)
exact ⟨x, n, by x:ℕn:ℕhx1:1 ≤ xhn1:1 ≤ nhcyc:terras^[n] x = xhxne1:x ≠ 1hxne2:x ≠ 2hlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)⊢ 3 ≤ x omega All goals completed! 🐙, hn1, hlt, hprod⟩
· mpr ⊢ (∃ x n,
3 ≤ x ∧
1 ≤ n ∧
3 ^ (terrasParityWord n x).sum < 2 ^ n ∧
(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)) →
∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2 rintro ⟨x, n, hx3, hn1, hlt, hprod⟩ mpr x:ℕn:ℕhx3:3 ≤ xhn1:1 ≤ nhlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)⊢ ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
have hcyc := (terras_cycle_iff_bohmSontacchi (by x:ℕn:ℕhx3:3 ≤ xhn1:1 ≤ nhlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)⊢ 1 ≤ x omega All goals completed! 🐙) hn1).mpr ⟨hlt, hprod⟩ mpr x:ℕn:ℕhx3:3 ≤ xhn1:1 ≤ nhlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)hcyc:terras^[n] x = x⊢ ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
exact ⟨x, n, by x:ℕn:ℕhx3:3 ≤ xhn1:1 ≤ nhlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)hcyc:terras^[n] x = x⊢ 1 ≤ x omega All goals completed! 🐙, hn1, hcyc, by x:ℕn:ℕhx3:3 ≤ xhn1:1 ≤ nhlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)hcyc:terras^[n] x = x⊢ x ≠ 1 omega All goals completed! 🐙, by x:ℕn:ℕhx3:3 ≤ xhn1:1 ≤ nhlt:3 ^ (terrasParityWord n x).sum < 2 ^ nhprod:(2 ^ n - 3 ^ (terrasParityWord n x).sum) * x = collatzCycleNum (terrasParityWord n x)hcyc:terras^[n] x = x⊢ x ≠ 2 omega All goals completed! 🐙⟩
The 75-state machine weakCollatz75 halts on the blank tape if and only if Tao's Weak Collatz
Conjecture is false.
theorem halts_weakCollatz75_iff_not_weakCollatz :
ConjectureMachines.Halts weakCollatz75 ↔ ¬ WeakCollatzConjecture := by ⊢ ConjectureMachines.Halts weakCollatz75 ↔ ¬WeakCollatzConjecture
rw [halts_weakCollatz75_iff_exists_cycle ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) ↔ ¬WeakCollatzConjecture] ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) ↔ ¬WeakCollatzConjecture
constructor mp ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) → ¬WeakCollatzConjecturempr ⊢ ¬WeakCollatzConjecture → ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
· mp ⊢ (∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2) → ¬WeakCollatzConjecture rintro ⟨x, k, hx1, hk1, hcyc, hxne1, hxne2⟩ hW mp x:ℕk:ℕhx1:1 ≤ xhk1:1 ≤ khcyc:terras^[k] x = xhxne1:x ≠ 1hxne2:x ≠ 2hW:WeakCollatzConjecture⊢ False
rcases hW x k hx1 hk1 hcyc with rfl | rfl mp.inl k:ℕhk1:1 ≤ khW:WeakCollatzConjecturehx1:1 ≤ 1hcyc:terras^[k] 1 = 1hxne1:1 ≠ 1hxne2:1 ≠ 2⊢ Falsemp.inr k:ℕhk1:1 ≤ khW:WeakCollatzConjecturehx1:1 ≤ 2hcyc:terras^[k] 2 = 2hxne1:2 ≠ 1hxne2:2 ≠ 2⊢ False <;> mp.inl k:ℕhk1:1 ≤ khW:WeakCollatzConjecturehx1:1 ≤ 1hcyc:terras^[k] 1 = 1hxne1:1 ≠ 1hxne2:1 ≠ 2⊢ Falsemp.inr k:ℕhk1:1 ≤ khW:WeakCollatzConjecturehx1:1 ≤ 2hcyc:terras^[k] 2 = 2hxne1:2 ≠ 1hxne2:2 ≠ 2⊢ False contradiction All goals completed! 🐙
· mpr ⊢ ¬WeakCollatzConjecture → ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2 intro hnotW mpr hnotW:¬WeakCollatzConjecture⊢ ∃ x k, 1 ≤ x ∧ 1 ≤ k ∧ terras^[k] x = x ∧ x ≠ 1 ∧ x ≠ 2
exact by_contra fun hne =>
hnotW fun x k hx1 hk1 hcyc =>
by_contra fun hnot12 =>
hne ⟨x, k, hx1, hk1, hcyc, fun h1 => hnot12 (Or.inl h1),
fun h2 => hnot12 (Or.inr h2)⟩ All goals completed! 🐙end ConjectureMachines.WeakCollatz75