import Mathlib /-! # Theorem 1.1: Positive Unmerged Density Above the Sharp Threshold `a^(d - 1) > d^d` For every integer `d ≥ 2` and `a > 1` with `Nat.Coprime a d` and `d ^ d < a ^ (d - 1)` (equivalently `a > d^(d / (d - 1))`), we prove: 1. Existence of parameters `α > 0`, `ρ = 1 - t ∈ (0, 1)` (with `t = √(L * α / 4) ≍ √α`), `B = 1`, `W₀ > 0` such that the bounded potential `φ(s, μ) = min 1 ((1 + B * ρ^s) * (W₀ / w)^α)` (`w = |μ| / a^s`) is globally superharmonic for the d-adic pair chain. 2. Deterministic growth from `(0, 1)` to states of arbitrarily large weight `w`: * For `d ≥ 3`: one step to `(1, -m₀)` (`m₀ ≥ 1`), followed by the deterministic exponentially-growing path at level `s = 1` where at every step we choose a nonzero digit `i ∈ {1, ..., d - 1}` with `a * i + μ ≢ 0 (mod d)`, giving `|μ'| = (a * |μ| + a * r_i - r_j) / d > |μ|`. * For `d = 2` (`a ≥ 5` odd): the all-`1` orbit in `{(0, m), (1, -m)}` grows without bound. 3. Conclusion (`above_threshold_unmerged`): `∃ ε > 0, ∀ k ≥ 1, C_k(d, a, 1) / d^k ≤ 1 - ε`. -/ namespace DAdicCollatz.AboveThreshold open Filter Topology /-! ## Section 1: Core d-adic pair chain and residue-class link -/ def res (d a : ℕ) (x : ℤ) : ℤ := (-(a : ℤ) * x) % (d : ℤ) def T (d a : ℕ) (x : ℤ) : ℤ := if x % (d : ℤ) = 0 then x / (d : ℤ) else ((a : ℤ) * x + res d a x) / (d : ℤ) structure State where s : ℕ mu : ℤ deriving DecidableEq, Repr def State.norm (st : State) : State := if st.s = 0 then ⟨0, |st.mu|⟩ else st def absorbed : State := ⟨0, 0⟩ def step (d a : ℕ) (st : State) (c : Fin d) : State := let qRem := ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu) % (d : ℤ) if c.val = 0 then if qRem = 0 then (⟨st.s, st.mu / (d : ℤ)⟩ : State).norm else ⟨st.s + 1, ((a : ℤ) * st.mu + res d a st.mu) / (d : ℤ)⟩ else if qRem = 0 then match st.s with | 0 => ⟨1, (res d a (c.val : ℤ) - (a : ℤ) * st.mu) / (d : ℤ)⟩ | s' + 1 => (⟨s', (st.mu - (a : ℤ) ^ s' * res d a (c.val : ℤ)) / (d : ℤ)⟩ : State).norm else (⟨st.s, ((a : ℤ) * st.mu + res d a ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu) - (a : ℤ) ^ st.s * res d a (c.val : ℤ)) / (d : ℤ)⟩ : State).norm def run (d a : ℕ) (st : State) (w : List (Fin d)) : State := w.foldl (step d a) st def Rel (a : ℕ) (st : State) (p q : ℤ) : Prop := q = (a : ℤ) ^ st.s * p + st.mu noncomputable def weight (a : ℕ) (st : State) : ℝ := |(st.mu : ℝ)| / (a : ℝ) ^ st.s theorem isCoprime_int_of_coprime {a d : ℕ} (hcop : Nat.Coprime a d) : IsCoprime (d : ℤ) (a : ℤ) := Nat.isCoprime_iff_coprime.mpr hcop.symm theorem res_nonneg {d a : ℕ} (hd : 0 < d) (x : ℤ) : 0 ≤ res d a x := Int.emod_nonneg _ (by omega) theorem res_lt {d a : ℕ} (hd : 0 < d) (x : ℤ) : res d a x < (d : ℤ) := Int.emod_lt_of_pos _ (by omega) theorem dvd_mul_add_res (d a : ℕ) (x : ℤ) : (d : ℤ) ∣ (a : ℤ) * x + res d a x := by apply Int.dvd_of_emod_eq_zero unfold res rw [Int.add_emod, Int.emod_emod, ← Int.add_emod] have h : (a : ℤ) * x + -(a : ℤ) * x = 0 := by ring rw [h, Int.zero_emod] theorem res_congr {d a : ℕ} {x y : ℤ} (h : x % (d : ℤ) = y % (d : ℤ)) : res d a x = res d a y := by unfold res rw [Int.mul_emod, Int.mul_emod (-(a : ℤ)) y, h] theorem res_add_mul (d a : ℕ) (x t : ℤ) : res d a (x + (d : ℤ) * t) = res d a x := by apply res_congr rw [Int.add_mul_emod_self_left] theorem res_pos_of_emod_ne_zero {d a : ℕ} (hd : 0 < d) (hcop : Nat.Coprime a d) {x : ℤ} (hx : x % (d : ℤ) ≠ 0) : 1 ≤ res d a x := by have h0 : 0 ≤ res d a x := res_nonneg hd x have hne : res d a x ≠ 0 := by intro h apply hx have hdvd : (d : ℤ) ∣ -(a : ℤ) * x := Int.dvd_of_emod_eq_zero h rw [show -(a : ℤ) * x = -((a : ℤ) * x) by ring, dvd_neg] at hdvd exact Int.emod_eq_zero_of_dvd ((isCoprime_int_of_coprime hcop).dvd_of_dvd_mul_left hdvd) omega theorem d_mul_T_of_emod_eq_zero {d a : ℕ} {x : ℤ} (hx : x % (d : ℤ) = 0) : (d : ℤ) * T d a x = x := by unfold T rw [if_pos hx] exact Int.mul_ediv_cancel' (Int.dvd_of_emod_eq_zero hx) theorem d_mul_T_of_emod_ne_zero {d a : ℕ} {x : ℤ} (hx : x % (d : ℤ) ≠ 0) : (d : ℤ) * T d a x = (a : ℤ) * x + res d a x := by unfold T rw [if_neg hx] exact Int.mul_ediv_cancel' (dvd_mul_add_res d a x) theorem T_add_mul {d a : ℕ} (hd : 0 < d) (x t : ℤ) : T d a (x + (d : ℤ) * t) = T d a x + (if x % (d : ℤ) = 0 then 1 else (a : ℤ)) * t := by have hd0 : (d : ℤ) ≠ 0 := by omega apply mul_left_cancel₀ hd0 have hmod : (x + (d : ℤ) * t) % (d : ℤ) = x % (d : ℤ) := Int.add_mul_emod_self_left x d t by_cases hx : x % (d : ℤ) = 0 · rw [if_pos hx, d_mul_T_of_emod_eq_zero (by rw [hmod, hx]), mul_add, d_mul_T_of_emod_eq_zero hx] ring · rw [if_neg hx, d_mul_T_of_emod_ne_zero (by rw [hmod]; exact hx), res_add_mul, mul_add (d : ℤ) (T d a x), d_mul_T_of_emod_ne_zero hx] ring theorem State.norm_s (st : State) : st.norm.s = st.s := by unfold State.norm split_ifs with h · exact h.symm · rfl theorem State.norm_of_pos (s : ℕ) (μ : ℤ) (hs : 0 < s) : (⟨s, μ⟩ : State).norm = ⟨s, μ⟩ := by simp [State.norm, Nat.pos_iff_ne_zero.mp hs] theorem State.norm_zero (μ : ℤ) : (⟨0, μ⟩ : State).norm = ⟨0, |μ|⟩ := by simp [State.norm] theorem weight_norm (a : ℕ) (st : State) : weight a st.norm = weight a st := by unfold State.norm split_ifs with h · simp [weight, h] · rfl theorem step_absorbed {d a : ℕ} (c : Fin d) : step d a absorbed c = absorbed := by unfold step absorbed dsimp only simp only [pow_zero, one_mul, add_zero] have hmod : (c.val : ℤ) % (d : ℤ) = (c.val : ℤ) := Int.emod_eq_of_lt (Int.natCast_nonneg _) (by exact_mod_cast c.isLt) rw [hmod] by_cases hc : c.val = 0 · simp [hc, State.norm] · simp [hc, State.norm] theorem rel_norm_or (a : ℕ) (st : State) (x y : ℤ) (h : y = (a : ℤ) ^ st.s * x + st.mu) : Rel a st.norm x y ∨ Rel a st.norm y x := by unfold State.norm split_ifs with hs · rw [hs, pow_zero, one_mul] at h rcases abs_cases st.mu with ⟨ha, _⟩ | ⟨ha, _⟩ · left; show y = (a : ℤ) ^ 0 * x + |st.mu|; rw [ha, pow_zero, one_mul]; exact h · right; show x = (a : ℤ) ^ 0 * y + |st.mu|; rw [ha, pow_zero, one_mul]; omega · exact Or.inl h def digit (d : ℕ) (hd : 0 < d) (p : ℤ) : Fin d := ⟨(p % (d : ℤ)).toNat, by have h1 : 0 ≤ p % (d : ℤ) := Int.emod_nonneg p (by omega) have h2 : p % (d : ℤ) < (d : ℤ) := Int.emod_lt_of_pos p (by omega) omega⟩ theorem digit_val_cast {d : ℕ} (hd : 0 < d) (p : ℤ) : ((digit d hd p).val : ℤ) = p % (d : ℤ) := Int.toNat_of_nonneg (Int.emod_nonneg p (by omega)) theorem step_rel {d a : ℕ} (hd : 0 < d) (st : State) (p q : ℤ) (h : Rel a st p q) : Rel a (step d a st (digit d hd p)) (T d a p) (T d a q) ∨ Rel a (step d a st (digit d hd p)) (T d a q) (T d a p) := by have hd0 : (d : ℤ) ≠ 0 := by omega obtain ⟨s, μ⟩ := st change q = (a : ℤ) ^ s * p + μ at h set c : Fin d := digit d hd p have hc_cast : (c.val : ℤ) = p % (d : ℤ) := digit_val_cast hd p have hq_mod : q % (d : ℤ) = ((a : ℤ) ^ s * (c.val : ℤ) + μ) % (d : ℤ) := by rw [h, hc_cast, Int.add_emod, Int.mul_emod, Int.add_emod ((a : ℤ) ^ s * (p % (d : ℤ))), Int.mul_emod ((a : ℤ) ^ s), Int.emod_emod] have hres_p : res d a p = res d a (c.val : ℤ) := by apply res_congr; rw [hc_cast, Int.emod_emod] have hres_q : res d a q = res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) := res_congr hq_mod unfold step; dsimp only by_cases hc0 : c.val = 0 · rw [if_pos hc0] have hp0 : p % (d : ℤ) = 0 := by rw [← hc_cast]; exact_mod_cast hc0 have hq_mod' : q % (d : ℤ) = μ % (d : ℤ) := by rw [hq_mod, hc0, Nat.cast_zero, mul_zero, zero_add] have hTp : (d : ℤ) * T d a p = p := d_mul_T_of_emod_eq_zero hp0 by_cases hqr : ((a : ℤ) ^ s * (c.val : ℤ) + μ) % (d : ℤ) = 0 · rw [if_pos hqr] have hq0 : q % (d : ℤ) = 0 := by rw [hq_mod]; exact hqr have hμ0 : μ % (d : ℤ) = 0 := by rw [← hq_mod']; exact hq0 have hTq : (d : ℤ) * T d a q = q := d_mul_T_of_emod_eq_zero hq0 have hμd : (d : ℤ) * (μ / (d : ℤ)) = μ := Int.mul_ediv_cancel' (Int.dvd_of_emod_eq_zero hμ0) apply rel_norm_or show T d a q = (a : ℤ) ^ s * T d a p + μ / (d : ℤ) apply mul_left_cancel₀ hd0 linear_combination hTq + h - (a : ℤ) ^ s * hTp - hμd · rw [if_neg hqr] have hqne : q % (d : ℤ) ≠ 0 := by rw [hq_mod]; exact hqr have hTq : (d : ℤ) * T d a q = (a : ℤ) * q + res d a q := d_mul_T_of_emod_ne_zero hqne have hres_q' : res d a q = res d a μ := res_congr hq_mod' rw [hres_q'] at hTq have hdiv : (d : ℤ) * (((a : ℤ) * μ + res d a μ) / (d : ℤ)) = (a : ℤ) * μ + res d a μ := Int.mul_ediv_cancel' (dvd_mul_add_res d a μ) left show T d a q = (a : ℤ) ^ (s + 1) * T d a p + ((a : ℤ) * μ + res d a μ) / (d : ℤ) apply mul_left_cancel₀ hd0 rw [pow_succ'] linear_combination hTq + (a : ℤ) * h - (a : ℤ) * (a : ℤ) ^ s * hTp - hdiv · rw [if_neg hc0] have hpne : p % (d : ℤ) ≠ 0 := by rw [← hc_cast]; exact_mod_cast hc0 have hTp : (d : ℤ) * T d a p = (a : ℤ) * p + res d a (c.val : ℤ) := by rw [← hres_p]; exact d_mul_T_of_emod_ne_zero hpne by_cases hqr : ((a : ℤ) ^ s * (c.val : ℤ) + μ) % (d : ℤ) = 0 · rw [if_pos hqr] have hq0 : q % (d : ℤ) = 0 := by rw [hq_mod]; exact hqr have hTq : (d : ℤ) * T d a q = q := d_mul_T_of_emod_eq_zero hq0 cases s with | zero => rw [pow_zero, one_mul] at h hqr have hdvd : (d : ℤ) ∣ res d a (c.val : ℤ) - (a : ℤ) * μ := by have h1 := dvd_mul_add_res d a (c.val : ℤ) have h2 : (d : ℤ) ∣ (a : ℤ) * ((c.val : ℤ) + μ) := dvd_mul_of_dvd_right (Int.dvd_of_emod_eq_zero hqr) (a : ℤ) have h3 : res d a (c.val : ℤ) - (a : ℤ) * μ = ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) - (a : ℤ) * ((c.val : ℤ) + μ) := by ring rw [h3]; exact dvd_sub h1 h2 have hdiv : (d : ℤ) * ((res d a (c.val : ℤ) - (a : ℤ) * μ) / (d : ℤ)) = res d a (c.val : ℤ) - (a : ℤ) * μ := Int.mul_ediv_cancel' hdvd right show T d a p = (a : ℤ) ^ 1 * T d a q + (res d a (c.val : ℤ) - (a : ℤ) * μ) / (d : ℤ) apply mul_left_cancel₀ hd0 rw [pow_one] linear_combination hTp - (a : ℤ) * hTq - (a : ℤ) * h - hdiv | succ s' => have hdvd : (d : ℤ) ∣ μ - (a : ℤ) ^ s' * res d a (c.val : ℤ) := by have h1 : (d : ℤ) ∣ (a : ℤ) ^ (s' + 1) * (c.val : ℤ) + μ := Int.dvd_of_emod_eq_zero hqr have h2 : (d : ℤ) ∣ (a : ℤ) ^ s' * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := dvd_mul_of_dvd_right (dvd_mul_add_res d a (c.val : ℤ)) _ have h3 : μ - (a : ℤ) ^ s' * res d a (c.val : ℤ) = ((a : ℤ) ^ (s' + 1) * (c.val : ℤ) + μ) - (a : ℤ) ^ s' * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := by rw [pow_succ]; ring rw [h3]; exact dvd_sub h1 h2 have hdiv : (d : ℤ) * ((μ - (a : ℤ) ^ s' * res d a (c.val : ℤ)) / (d : ℤ)) = μ - (a : ℤ) ^ s' * res d a (c.val : ℤ) := Int.mul_ediv_cancel' hdvd apply rel_norm_or show T d a q = (a : ℤ) ^ s' * T d a p + (μ - (a : ℤ) ^ s' * res d a (c.val : ℤ)) / (d : ℤ) apply mul_left_cancel₀ hd0 rw [pow_succ] at h linear_combination hTq + h - (a : ℤ) ^ s' * hTp - hdiv · rw [if_neg hqr] have hqne : q % (d : ℤ) ≠ 0 := by rw [hq_mod]; exact hqr have hTq : (d : ℤ) * T d a q = (a : ℤ) * q + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) := by rw [← hres_q]; exact d_mul_T_of_emod_ne_zero hqne have hdvd : (d : ℤ) ∣ (a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ) := by have h1 := dvd_mul_add_res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) have h2 : (d : ℤ) ∣ (a : ℤ) ^ s * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := dvd_mul_of_dvd_right (dvd_mul_add_res d a _) _ have h3 : (a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ) = ((a : ℤ) * ((a : ℤ) ^ s * (c.val : ℤ) + μ) + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ)) - (a : ℤ) ^ s * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := by ring rw [h3]; exact dvd_sub h1 h2 have hdiv : (d : ℤ) * (((a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ)) / (d : ℤ)) = (a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ) := Int.mul_ediv_cancel' hdvd apply rel_norm_or show T d a q = (a : ℤ) ^ s * T d a p + ((a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ)) / (d : ℤ) apply mul_left_cancel₀ hd0 linear_combination hTq + (a : ℤ) * h - (a : ℤ) ^ s * hTp - hdiv /-! ## Section 2: `d`-ary `pAbs`, comparison lemmas, and `C_k` link -/ noncomputable def E {S : Type*} {d : ℕ} (stepFn : S → Fin d → S) (f : S → ℝ) : ℕ → S → ℝ | 0, st => f st | k + 1, st => (∑ c : Fin d, E stepFn f k (stepFn st c)) / (d : ℝ) noncomputable def pAbs {S : Type*} [DecidableEq S] {d : ℕ} (stepFn : S → Fin d → S) (abs : S) (k : ℕ) (st : S) : ℝ := E stepFn (fun t => if t = abs then 1 else 0) k st theorem pAbs_zero {S : Type*} [DecidableEq S] {d : ℕ} (stepFn : S → Fin d → S) (abs st : S) : pAbs stepFn abs 0 st = if st = abs then 1 else 0 := rfl theorem pAbs_succ {S : Type*} [DecidableEq S] {d : ℕ} (stepFn : S → Fin d → S) (abs : S) (k : ℕ) (st : S) : pAbs stepFn abs (k + 1) st = (∑ c : Fin d, pAbs stepFn abs k (stepFn st c)) / (d : ℝ) := rfl theorem pAbs_nonneg {S : Type*} [DecidableEq S] {d : ℕ} (stepFn : S → Fin d → S) (abs : S) : ∀ (k : ℕ) (st : S), 0 ≤ pAbs stepFn abs k st | 0, st => by rw [pAbs_zero]; split_ifs <;> norm_num | k + 1, st => by rw [pAbs_succ] exact div_nonneg (Finset.sum_nonneg fun c _ => pAbs_nonneg stepFn abs k _) (Nat.cast_nonneg d) theorem pAbs_le_one {S : Type*} [DecidableEq S] {d : ℕ} (hd : 0 < d) (stepFn : S → Fin d → S) (abs : S) : ∀ (k : ℕ) (st : S), pAbs stepFn abs k st ≤ 1 | 0, st => by rw [pAbs_zero]; split_ifs <;> norm_num | k + 1, st => by have hdpos : (0 : ℝ) < d := by positivity rw [pAbs_succ, div_le_one hdpos] calc ∑ c : Fin d, pAbs stepFn abs k (stepFn st c) ≤ ∑ _c : Fin d, (1 : ℝ) := Finset.sum_le_sum fun c _ => pAbs_le_one hd stepFn abs k _ _ = (d : ℝ) := by simp [Finset.sum_const] theorem pAbs_abs {S : Type*} [DecidableEq S] {d : ℕ} (hd : 0 < d) (stepFn : S → Fin d → S) (abs : S) (habs : ∀ c : Fin d, stepFn abs c = abs) : ∀ k : ℕ, pAbs stepFn abs k abs = 1 | 0 => by simp [pAbs_zero] | k + 1 => by have hd0 : (d : ℝ) ≠ 0 := by positivity rw [pAbs_succ] simp_rw [habs, pAbs_abs hd stepFn abs habs k] simp [Finset.sum_const, hd0] theorem pAbs_le_succ {S : Type*} [DecidableEq S] {d : ℕ} (hd : 0 < d) (stepFn : S → Fin d → S) (abs : S) (habs : ∀ c : Fin d, stepFn abs c = abs) : ∀ (k : ℕ) (st : S), pAbs stepFn abs k st ≤ pAbs stepFn abs (k + 1) st | 0, st => by rw [pAbs_succ, pAbs_zero] split_ifs with hs · subst hs have hd0 : (d : ℝ) ≠ 0 := by positivity simp_rw [habs, pAbs_abs hd stepFn st habs 0] simp [Finset.sum_const, hd0] · exact div_nonneg (Finset.sum_nonneg fun c _ => pAbs_nonneg stepFn abs 0 _) (Nat.cast_nonneg d) | k + 1, st => by rw [pAbs_succ, pAbs_succ] exact div_le_div_of_nonneg_right (Finset.sum_le_sum fun c _ => pAbs_le_succ hd stepFn abs habs k (stepFn st c)) (Nat.cast_nonneg d) theorem pAbs_mono {S : Type*} [DecidableEq S] {d : ℕ} (hd : 0 < d) (stepFn : S → Fin d → S) (abs : S) (habs : ∀ c : Fin d, stepFn abs c = abs) {j k : ℕ} (hjk : j ≤ k) (st : S) : pAbs stepFn abs j st ≤ pAbs stepFn abs k st := by induction hjk with | refl => exact le_rfl | step _ ih => exact ih.trans (pAbs_le_succ hd stepFn abs habs _ st) /-- Any nonnegative globally superharmonic function `φ` with `1 ≤ φ abs` dominates `pAbs`. -/ theorem pAbs_le_of_super {S : Type*} [DecidableEq S] {d : ℕ} (stepFn : S → Fin d → S) (abs : S) (φ : S → ℝ) (h0 : ∀ st, 0 ≤ φ st) (habs : 1 ≤ φ abs) (hsuper : ∀ st, (∑ c : Fin d, φ (stepFn st c)) / (d : ℝ) ≤ φ st) : ∀ (k : ℕ) (st : S), pAbs stepFn abs k st ≤ φ st | 0, st => by rw [pAbs_zero] split_ifs with h · subst h; exact habs · exact h0 st | k + 1, st => by rw [pAbs_succ] calc (∑ c : Fin d, pAbs stepFn abs k (stepFn st c)) / (d : ℝ) ≤ (∑ c : Fin d, φ (stepFn st c)) / (d : ℝ) := div_le_div_of_nonneg_right (Finset.sum_le_sum fun c _ => pAbs_le_of_super stepFn abs φ h0 habs hsuper k _) (Nat.cast_nonneg d) _ ≤ φ st := hsuper st /-- Following a fixed word `w : List (Fin d)` occurs with probability `d^(-|w|)`. -/ theorem pAbs_word_le {S : Type*} [DecidableEq S] {d : ℕ} (hd : 0 < d) (stepFn : S → Fin d → S) (abs : S) (j : ℕ) : ∀ (w : List (Fin d)) (st : S), pAbs stepFn abs (w.length + j) st ≤ 1 - (1 / (d : ℝ)) ^ w.length * (1 - pAbs stepFn abs j (List.foldl stepFn st w)) | [], st => by simp | c :: w, st => by have hdpos : (0 : ℝ) < d := by positivity have hrec := pAbs_word_le hd stepFn abs j w (stepFn st c) have hlen : (c :: w).length + j = (w.length + j) + 1 := by simp; omega rw [hlen, pAbs_succ, List.length_cons, List.foldl_cons, div_le_iff₀ hdpos] have hsum : ∑ b : Fin d, pAbs stepFn abs (w.length + j) (stepFn st b) ≤ ((d : ℝ) - 1) + (1 - (1 / (d : ℝ)) ^ w.length * (1 - pAbs stepFn abs j (List.foldl stepFn (stepFn st c) w))) := by rw [← Finset.add_sum_erase _ _ (Finset.mem_univ c)] have hrest : ∑ b ∈ Finset.univ.erase c, pAbs stepFn abs (w.length + j) (stepFn st b) ≤ (d : ℝ) - 1 := by calc ∑ b ∈ Finset.univ.erase c, pAbs stepFn abs (w.length + j) (stepFn st b) ≤ ∑ _b ∈ Finset.univ.erase c, (1 : ℝ) := Finset.sum_le_sum fun b _ => pAbs_le_one hd stepFn abs _ _ _ = ((Finset.univ.erase c).card : ℝ) := by simp _ = (d : ℝ) - 1 := by rw [Finset.card_erase_of_mem (Finset.mem_univ c), Finset.card_univ, Fintype.card_fin, Nat.cast_sub hd, Nat.cast_one] linarith have hmul : (1 - (1 / (d : ℝ)) ^ (w.length + 1) * (1 - pAbs stepFn abs j (List.foldl stepFn (stepFn st c) w))) * (d : ℝ) = ((d : ℝ) - 1) + (1 - (1 / (d : ℝ)) ^ w.length * (1 - pAbs stepFn abs j (List.foldl stepFn (stepFn st c) w))) := by rw [pow_succ] field_simp ring linarith def Phi (d a : ℕ) (st : State) (k : ℕ) (P : ℤ) : Prop := (T d a)^[k] P = (T d a)^[k] ((a : ℤ) ^ st.s * P + st.mu) def Good (d a : ℕ) (st : State) (k : ℕ) (x : ℤ) : Prop := ∀ t : ℤ, Phi d a st k (x + (d : ℤ) ^ k * t) open Classical in noncomputable def merged (d a : ℕ) (st : State) (k : ℕ) : Finset ℕ := (Finset.range (d ^ k)).filter fun p => Good d a st k (p : ℤ) noncomputable def C_k (d a : ℕ) (m : ℤ) (k : ℕ) : ℕ := (merged d a ⟨0, m⟩ k).card theorem mem_merged (d a : ℕ) (st : State) (k p : ℕ) : p ∈ merged d a st k ↔ p < d ^ k ∧ Good d a st k (p : ℤ) := by simp only [merged, Finset.mem_filter, Finset.mem_range] theorem good_add_mul (d a : ℕ) (st : State) (k : ℕ) (x u : ℤ) : Good d a st k (x + (d : ℤ) ^ k * u) ↔ Good d a st k x := by constructor · intro H t; have h := H (t - u) rwa [show x + (d : ℤ) ^ k * u + (d : ℤ) ^ k * (t - u) = x + (d : ℤ) ^ k * t by ring] at h · intro H t; have h := H (u + t) rwa [show x + (d : ℤ) ^ k * (u + t) = x + (d : ℤ) ^ k * u + (d : ℤ) ^ k * t by ring] at h theorem good_emod (d a : ℕ) (st : State) (k : ℕ) (x : ℤ) : Good d a st k (x % (d : ℤ) ^ k) ↔ Good d a st k x := by have e : x = x % (d : ℤ) ^ k + (d : ℤ) ^ k * (x / (d : ℤ) ^ k) := (Int.emod_add_mul_ediv x ((d : ℤ) ^ k)).symm conv_rhs => rw [e] exact (good_add_mul d a st k _ _).symm def nonDivCount (d a : ℕ) : ℕ → ℤ → ℕ | 0, _ => 0 | k + 1, x => (if x % (d : ℤ) = 0 then 0 else 1) + nonDivCount d a k (T d a x) theorem T_iterate_add {d a : ℕ} (hd : 0 < d) (k : ℕ) (x t : ℤ) : (T d a)^[k] (x + (d : ℤ) ^ k * t) = (T d a)^[k] x + (a : ℤ) ^ nonDivCount d a k x * t := by induction k generalizing x t with | zero => simp [nonDivCount] | succ k ih => have e : x + (d : ℤ) ^ (k + 1) * t = x + (d : ℤ) * ((d : ℤ) ^ k * t) := by rw [pow_succ']; ring rw [Function.iterate_succ_apply, Function.iterate_succ_apply, e, T_add_mul hd] by_cases hx : x % (d : ℤ) = 0 · simp only [if_pos hx, one_mul, nonDivCount, zero_add]; exact ih (T d a x) t · simp only [if_neg hx, nonDivCount] have e' : T d a x + (a : ℤ) * ((d : ℤ) ^ k * t) = T d a x + (d : ℤ) ^ k * ((a : ℤ) * t) := by ring rw [e', ih (T d a x) ((a : ℤ) * t), pow_add, pow_one]; ring theorem good_of_thin {d a : ℕ} (hd : 0 < d) (st : State) (k : ℕ) (y g : ℤ) (hg : g ≠ 0) (H : ∀ t : ℤ, Phi d a st k (y + (d : ℤ) ^ k * (g * t))) : Good d a st k y := by have e1 := T_iterate_add (a := a) hd k y have e2 : ∀ t : ℤ, (T d a)^[k] ((a : ℤ) ^ st.s * (y + (d : ℤ) ^ k * t) + st.mu) = (T d a)^[k] ((a : ℤ) ^ st.s * y + st.mu) + (a : ℤ) ^ nonDivCount d a k ((a : ℤ) ^ st.s * y + st.mu) * ((a : ℤ) ^ st.s * t) := by intro t; rw [← T_iterate_add hd]; congr 1; ring have h0 := H 0; have h1 := H 1 unfold Phi at h0 h1; rw [e1, e2] at h0 h1 have hβ : ((a : ℤ) ^ nonDivCount d a k y - (a : ℤ) ^ nonDivCount d a k ((a : ℤ) ^ st.s * y + st.mu) * (a : ℤ) ^ st.s) * g = 0 := by linear_combination h1 - h0 have hβ' := (mul_eq_zero.mp hβ).resolve_right hg intro t; unfold Phi; rw [e1, e2]; linear_combination h0 + t * hβ' def sig (d k : ℕ) (g h : ℤ) (p : ℕ) : ℕ := ((g * (p : ℤ) + h) % (d : ℤ) ^ k).toNat theorem sig_cast {d : ℕ} (hd : 0 < d) (k : ℕ) (g h : ℤ) (p : ℕ) : ((sig d k g h p : ℕ) : ℤ) = (g * (p : ℤ) + h) % (d : ℤ) ^ k := Int.toNat_of_nonneg (Int.emod_nonneg _ (by positivity)) theorem sig_lt {d : ℕ} (hd : 0 < d) (k : ℕ) (g h : ℤ) (p : ℕ) : sig d k g h p < d ^ k := by have h1 : (g * (p : ℤ) + h) % (d : ℤ) ^ k < (d : ℤ) ^ k := Int.emod_lt_of_pos _ (by positivity) have h2 : ((sig d k g h p : ℕ) : ℤ) < ((d ^ k : ℕ) : ℤ) := by rw [sig_cast hd]; push_cast; exact h1 exact_mod_cast h2 theorem sig_inj {d : ℕ} (hd : 0 < d) (k : ℕ) (g h : ℤ) (hg : IsCoprime (d : ℤ) g) {p p' : ℕ} (hp : p < d ^ k) (hp' : p' < d ^ k) (hpp : sig d k g h p = sig d k g h p') : p = p' := by have hpZ : (p : ℤ) < (d : ℤ) ^ k := by exact_mod_cast hp have hpZ' : (p' : ℤ) < (d : ℤ) ^ k := by exact_mod_cast hp' have h1 : (g * (p : ℤ) + h) % (d : ℤ) ^ k = (g * (p' : ℤ) + h) % (d : ℤ) ^ k := by rw [← sig_cast hd, ← sig_cast hd, hpp] have h2 : ((d : ℤ) ^ k) ∣ (g * (p' : ℤ) + h) - (g * (p : ℤ) + h) := Int.ModEq.dvd h1 have h3 : ((d : ℤ) ^ k) ∣ ((p' : ℤ) - (p : ℤ)) * g := by have e : (g * (p' : ℤ) + h) - (g * (p : ℤ) + h) = ((p' : ℤ) - (p : ℤ)) * g := by ring rwa [e] at h2 have h4 : ((d : ℤ) ^ k) ∣ (p' : ℤ) - (p : ℤ) := hg.pow_left.dvd_of_dvd_mul_right h3 have h5 : (p' : ℤ) - (p : ℤ) = 0 := Int.eq_zero_of_abs_lt_dvd h4 (abs_lt.mpr ⟨by omega, by omega⟩) omega theorem sig_surj {d : ℕ} (hd : 0 < d) (k : ℕ) (g h : ℤ) (hg : IsCoprime (d : ℤ) g) (b : ℕ) (hb : b < d ^ k) : ∃ p, p < d ^ k ∧ sig d k g h p = b := by have hinj : Set.InjOn (sig d k g h) (Finset.range (d ^ k) : Set ℕ) := fun p hp p' hp' hpp => sig_inj hd k g h hg (Finset.mem_range.mp hp) (Finset.mem_range.mp hp') hpp have hsub : (Finset.range (d ^ k)).image (sig d k g h) ⊆ Finset.range (d ^ k) := by intro x hx; obtain ⟨p, _, rfl⟩ := Finset.mem_image.mp hx exact Finset.mem_range.mpr (sig_lt hd k g h p) have heq : (Finset.range (d ^ k)).image (sig d k g h) = Finset.range (d ^ k) := Finset.eq_of_subset_of_card_le hsub (by rw [Finset.card_image_of_injOn hinj]) have hb' : b ∈ (Finset.range (d ^ k)).image (sig d k g h) := by rw [heq]; exact Finset.mem_range.mpr hb obtain ⟨p, hp, rfl⟩ := Finset.mem_image.mp hb' exact ⟨p, Finset.mem_range.mp hp, rfl⟩ theorem aff_ext (a₁ b₁ A₁ B₁ D M : ℤ) {u v : ℤ} (huv : u ≠ v) (hu : A₁ * u + B₁ = D * (a₁ * u + b₁) + M) (hv : A₁ * v + B₁ = D * (a₁ * v + b₁) + M) (w : ℤ) : A₁ * w + B₁ = D * (a₁ * w + b₁) + M := by have h : (A₁ - D * a₁) * (u - v) = 0 := by linear_combination hu - hv have hp : A₁ - D * a₁ = 0 := (mul_eq_zero.mp h).resolve_right (sub_ne_zero.mpr huv) linear_combination hu + (w - u) * hp theorem affine_dichotomy (a₁ b₁ A₁ B₁ D M : ℤ) (R : ∀ u : ℤ, A₁ * u + B₁ = D * (a₁ * u + b₁) + M ∨ a₁ * u + b₁ = D * (A₁ * u + B₁) + M) : (∀ u : ℤ, A₁ * u + B₁ = D * (a₁ * u + b₁) + M) ∨ (∀ u : ℤ, a₁ * u + b₁ = D * (A₁ * u + B₁) + M) := by have h01 : (0 : ℤ) ≠ 1 := by norm_num have h02 : (0 : ℤ) ≠ 2 := by norm_num have h12 : (1 : ℤ) ≠ 2 := by norm_num rcases R 0 with h0 | h0 <;> rcases R 1 with h1 | h1 <;> rcases R 2 with h2 | h2 · exact Or.inl (aff_ext a₁ b₁ A₁ B₁ D M h01 h0 h1) · exact Or.inl (aff_ext a₁ b₁ A₁ B₁ D M h01 h0 h1) · exact Or.inl (aff_ext a₁ b₁ A₁ B₁ D M h02 h0 h2) · exact Or.inr (aff_ext A₁ B₁ a₁ b₁ D M h12 h1 h2) · exact Or.inl (aff_ext a₁ b₁ A₁ B₁ D M h12 h1 h2) · exact Or.inr (aff_ext A₁ B₁ a₁ b₁ D M h02 h0 h2) · exact Or.inr (aff_ext A₁ B₁ a₁ b₁ D M h01 h0 h1) · exact Or.inr (aff_ext A₁ B₁ a₁ b₁ D M h01 h0 h1) theorem digit_mul_add {d : ℕ} (hd : 0 < d) (c : Fin d) (u : ℤ) : digit d hd ((d : ℤ) * u + (c.val : ℤ)) = c := by apply Fin.ext have h1 : ((d : ℤ) * u + (c.val : ℤ)) % (d : ℤ) = (c.val : ℤ) := by rw [add_comm, Int.add_mul_emod_self_left] exact Int.emod_eq_of_lt (Int.natCast_nonneg _) (by exact_mod_cast c.isLt) have h2 := digit_val_cast hd ((d : ℤ) * u + (c.val : ℤ)) rw [h1] at h2; exact_mod_cast h2 theorem step_affine {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (st : State) (c : Fin d) : ∃ g h : ℤ, IsCoprime (d : ℤ) g ∧ g ≠ 0 ∧ ∀ (k : ℕ) (u : ℤ), Phi d a st (k + 1) ((d : ℤ) * u + (c.val : ℤ)) ↔ Phi d a (step d a st c) k (g * u + h) := by have hdpos : 0 < d := by omega have hcopZ : IsCoprime (d : ℤ) (a : ℤ) := isCoprime_int_of_coprime hcop have ha0 : (a : ℤ) ≠ 0 := by omega obtain ⟨a₁, b₁, ha₁_cop, ha₁_ne, hab₁⟩ : ∃ a₁ b₁ : ℤ, IsCoprime (d : ℤ) a₁ ∧ a₁ ≠ 0 ∧ ∀ u : ℤ, T d a ((d : ℤ) * u + (c.val : ℤ)) = a₁ * u + b₁ := by refine ⟨if (c.val : ℤ) % (d : ℤ) = 0 then 1 else (a : ℤ), T d a (c.val : ℤ), ?_, ?_, fun u => ?_⟩ · split_ifs; exact isCoprime_one_right; exact hcopZ · split_ifs; norm_num; exact ha0 · rw [show (d : ℤ) * u + (c.val : ℤ) = (c.val : ℤ) + (d : ℤ) * u by ring, T_add_mul hdpos] ring obtain ⟨A₁, B₁, hA₁_cop, hA₁_ne, hAB₁⟩ : ∃ A₁ B₁ : ℤ, IsCoprime (d : ℤ) A₁ ∧ A₁ ≠ 0 ∧ ∀ u : ℤ, T d a ((a : ℤ) ^ st.s * ((d : ℤ) * u + (c.val : ℤ)) + st.mu) = A₁ * u + B₁ := by refine ⟨(if ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu) % (d : ℤ) = 0 then 1 else (a : ℤ)) * (a : ℤ) ^ st.s, T d a ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu), ?_, ?_, fun u => ?_⟩ · apply IsCoprime.mul_right · split_ifs; exact isCoprime_one_right; exact hcopZ · exact hcopZ.pow_right · apply mul_ne_zero · split_ifs; norm_num; exact ha0 · exact pow_ne_zero _ ha0 · rw [show (a : ℤ) ^ st.s * ((d : ℤ) * u + (c.val : ℤ)) + st.mu = ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu) + (d : ℤ) * ((a : ℤ) ^ st.s * u) by ring, T_add_mul hdpos] ring have R : ∀ u : ℤ, A₁ * u + B₁ = (a : ℤ) ^ (step d a st c).s * (a₁ * u + b₁) + (step d a st c).mu ∨ a₁ * u + b₁ = (a : ℤ) ^ (step d a st c).s * (A₁ * u + B₁) + (step d a st c).mu := by intro u have h := step_rel hdpos st ((d : ℤ) * u + (c.val : ℤ)) ((a : ℤ) ^ st.s * ((d : ℤ) * u + (c.val : ℤ)) + st.mu) rfl rw [digit_mul_add hdpos c u, hab₁ u, hAB₁ u] at h; exact h rcases affine_dichotomy a₁ b₁ A₁ B₁ _ _ R with H | H · refine ⟨a₁, b₁, ha₁_cop, ha₁_ne, fun k u => ?_⟩ unfold Phi; rw [Function.iterate_succ_apply, Function.iterate_succ_apply, hab₁ u, hAB₁ u, H u] · refine ⟨A₁, B₁, hA₁_cop, hA₁_ne, fun k u => ?_⟩ unfold Phi; rw [Function.iterate_succ_apply, Function.iterate_succ_apply, hab₁ u, hAB₁ u, H u] exact eq_comm theorem good_succ_iff {d a : ℕ} (hd : 0 < d) (st : State) (c : Fin d) (g h : ℤ) (hg_ne : g ≠ 0) (k : ℕ) (H : ∀ u : ℤ, Phi d a st (k + 1) ((d : ℤ) * u + (c.val : ℤ)) ↔ Phi d a (step d a st c) k (g * u + h)) (p' : ℕ) : Good d a st (k + 1) ((d * p' + c.val : ℕ) : ℤ) ↔ Good d a (step d a st c) k (sig d k g h p') := by rw [sig_cast hd, good_emod] have key : ∀ t : ℤ, Phi d a st (k + 1) (((d * p' + c.val : ℕ) : ℤ) + (d : ℤ) ^ (k + 1) * t) ↔ Phi d a (step d a st c) k (g * (p' : ℤ) + h + (d : ℤ) ^ k * (g * t)) := by intro t have e1 : ((d * p' + c.val : ℕ) : ℤ) + (d : ℤ) ^ (k + 1) * t = (d : ℤ) * ((p' : ℤ) + (d : ℤ) ^ k * t) + (c.val : ℤ) := by push_cast; rw [pow_succ']; ring have e2 : g * (p' : ℤ) + h + (d : ℤ) ^ k * (g * t) = g * ((p' : ℤ) + (d : ℤ) ^ k * t) + h := by ring rw [e1, e2]; exact H _ exact ⟨fun G => good_of_thin hd _ _ _ g hg_ne fun t => (key t).mp (G t), fun G t => (key t).mpr (G (g * t))⟩ theorem card_residue {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (st : State) (k : ℕ) (c : Fin d) : ((merged d a st (k + 1)).filter (fun p => p % d = c.val)).card = (merged d a (step d a st c) k).card := by have hdpos : 0 < d := by omega obtain ⟨g, h, hg_cop, hg_ne, H⟩ := step_affine hd ha hcop st c apply Finset.card_bij (fun p _ => sig d k g h (p / d)) · intro p hp rw [Finset.mem_filter, mem_merged] at hp obtain ⟨⟨_, hG⟩, hmod⟩ := hp rw [mem_merged]; refine ⟨sig_lt hdpos k g h _, ?_⟩ have e : d * (p / d) + c.val = p := by have := Nat.div_add_mod p d; omega have hG' : Good d a st (k + 1) ((d * (p / d) + c.val : ℕ) : ℤ) := by rw [e]; exact hG exact (good_succ_iff hdpos st c g h hg_ne k (H k) (p / d)).mp hG' · intro p₁ hp₁ p₂ hp₂ heq rw [Finset.mem_filter, mem_merged] at hp₁ hp₂ have h1 : p₁ / d < d ^ k := (Nat.div_lt_iff_lt_mul hdpos).mpr (by rw [← pow_succ]; exact hp₁.1.1) have h2 : p₂ / d < d ^ k := (Nat.div_lt_iff_lt_mul hdpos).mpr (by rw [← pow_succ]; exact hp₂.1.1) have h3 : p₁ / d = p₂ / d := sig_inj hdpos k g h hg_cop h1 h2 heq have hmul : d * (p₁ / d) = d * (p₂ / d) := congrArg (d * ·) h3 have hm₁ := hp₁.2; have hm₂ := hp₂.2 have e₁ := Nat.div_add_mod p₁ d; have e₂ := Nat.div_add_mod p₂ d omega · intro b hb rw [mem_merged] at hb obtain ⟨q, hq, rfl⟩ := sig_surj hdpos k g h hg_cop b hb.1 refine ⟨d * q + c.val, ?_, ?_⟩ · rw [Finset.mem_filter, mem_merged] refine ⟨⟨?_, ?_⟩, ?_⟩ · rw [pow_succ'] have h1 : d * q + d ≤ d * d ^ k := by calc d * q + d = d * (q + 1) := by ring _ ≤ d * d ^ k := Nat.mul_le_mul_left d hq omega · exact (good_succ_iff hdpos st c g h hg_ne k (H k) q).mpr hb.2 · rw [Nat.mul_add_mod, Nat.mod_eq_of_lt c.isLt] · have e : (d * q + c.val) / d = q := by rw [Nat.mul_add_div hdpos, Nat.div_eq_of_lt c.isLt, add_zero] show sig d k g h ((d * q + c.val) / d) = sig d k g h q rw [e] theorem card_merged_zero {d a : ℕ} (ha : 1 < a) (st : State) : (merged d a st 0).card = if st = absorbed then 1 else 0 := by split_ifs with hs · subst hs have hm : merged d a absorbed 0 = {0} := by ext p; rw [mem_merged, Finset.mem_singleton] constructor · rintro ⟨hp, _⟩; simpa using hp · rintro rfl; exact ⟨by norm_num, fun t => by simp [Phi, absorbed]⟩ rw [hm]; rfl · have hm : merged d a st 0 = ∅ := by apply Finset.eq_empty_of_forall_notMem intro p hp; rw [mem_merged] at hp; obtain ⟨hp0, hG⟩ := hp have hp0' : p = 0 := by simpa using hp0 subst hp0' obtain ⟨s, μ⟩ := st have h0 := hG 0; have h1 := hG 1; unfold Phi at h0 h1 simp only [Function.iterate_zero, id_eq, Nat.cast_zero, pow_zero, mul_zero, add_zero, zero_add, mul_one] at h0 h1 have hμ : μ = 0 := h0.symm; subst hμ; rw [add_zero] at h1 have hs0 : s = 0 := by rcases Nat.eq_zero_or_pos s with rfl | hspos · rfl · exfalso have hpow : (1 : ℤ) < (a : ℤ) ^ s := one_lt_pow₀ (by exact_mod_cast ha) hspos.ne' omega exact hs (by rw [hs0]; rfl) rw [hm]; rfl theorem card_merged_succ {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (st : State) (k : ℕ) : (merged d a st (k + 1)).card = ∑ c : Fin d, (merged d a (step d a st c) k).card := by have hdpos : 0 < d := by omega have hpart : merged d a st (k + 1) = Finset.univ.biUnion (fun c : Fin d => (merged d a st (k + 1)).filter (fun p => p % d = c.val)) := by ext p; simp only [Finset.mem_biUnion, Finset.mem_univ, true_and, Finset.mem_filter] exact ⟨fun hp => ⟨⟨p % d, Nat.mod_lt p hdpos⟩, hp, rfl⟩, fun ⟨_, hp, _⟩ => hp⟩ have hdisj : Set.PairwiseDisjoint (↑(Finset.univ : Finset (Fin d)) : Set (Fin d)) (fun (c : Fin d) => (merged d a st (k + 1)).filter (fun p => p % d = c.val)) := by intro c₁ _ c₂ _ hne; dsimp only [Function.onFun]; rw [Finset.disjoint_filter] intro p _ h1 h2; exact hne (Fin.ext (by omega)) conv_lhs => rw [hpart] rw [Finset.card_biUnion hdisj] exact Finset.sum_congr rfl fun c _ => card_residue hd ha hcop st k c theorem card_merged_eq {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) : ∀ (k : ℕ) (st : State), ((merged d a st k).card : ℝ) = pAbs (step d a) absorbed k st * (d : ℝ) ^ k | 0, st => by rw [card_merged_zero ha, pAbs_zero]; split_ifs <;> simp | k + 1, st => by have hd0 : (d : ℝ) ≠ 0 := by positivity rw [card_merged_succ hd ha hcop, Nat.cast_sum, pAbs_succ] simp_rw [card_merged_eq hd ha hcop k] rw [← Finset.sum_mul, pow_succ] field_simp theorem C_k_div_pow_eq_pAbs {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (m : ℤ) (k : ℕ) : ((C_k d a m k : ℕ) : ℝ) / (d : ℝ) ^ k = pAbs (step d a) absorbed k ⟨0, m⟩ := by have hdk : (d : ℝ) ^ k ≠ 0 := pow_ne_zero k (by positivity) unfold C_k rw [card_merged_eq hd ha hcop k ⟨0, m⟩, mul_div_cancel_right₀ _ hdk] /-! ## Section 3: Unique root digit and weight lower bounds -/ theorem d_lt_a_of_thresh {d a : ℕ} (hd : 2 ≤ d) (hthresh : d ^ d < a ^ (d - 1)) : d < a := by by_contra h have hale : a ≤ d := not_lt.mp h have h1 : a ^ (d - 1) ≤ d ^ (d - 1) := Nat.pow_le_pow_left hale (d - 1) have h2 : d ^ (d - 1) < d ^ d := Nat.pow_lt_pow_right (by omega) (by omega) omega /-- Unique root `c₀ : Fin d` of `(a^s * c + μ) % d = 0` when `Nat.Coprime a d`. -/ theorem existsUnique_root_digit {d a : ℕ} (hd : 2 ≤ d) (hcop : Nat.Coprime a d) (s : ℕ) (μ : ℤ) : ∃! c₀ : Fin d, ((a : ℤ) ^ s * (c₀.val : ℤ) + μ) % (d : ℤ) = 0 := by have hdpos : 0 < d := by omega have hcop_pow : IsCoprime ((a : ℤ) ^ s) (d : ℤ) := (Nat.isCoprime_iff_coprime.mpr hcop).pow_left have ⟨u, v, huv⟩ := hcop_pow set r : ℤ := (-u * μ) % (d : ℤ) have hr0 : 0 ≤ r := Int.emod_nonneg _ (by omega) have hrlt : r < (d : ℤ) := Int.emod_lt_of_pos _ (by omega) let c₀ : Fin d := ⟨r.toNat, by omega⟩ have hc₀_cast : (c₀.val : ℤ) = r := Int.toNat_of_nonneg hr0 have hroot : ((a : ℤ) ^ s * (c₀.val : ℤ) + μ) % (d : ℤ) = 0 := by rw [hc₀_cast] apply Int.emod_eq_zero_of_dvd have h1 : (d : ℤ) ∣ r - (-u * μ) := by apply Int.dvd_of_emod_eq_zero change ((-u * μ) % (d : ℤ) - (-u * μ)) % (d : ℤ) = 0 rw [Int.sub_emod, Int.emod_emod, sub_self, Int.zero_emod] have h2 : (a : ℤ) ^ s * r + μ = (a : ℤ) ^ s * (r - (-u * μ)) + (v * μ) * (d : ℤ) := by linear_combination -μ * huv rw [h2] exact dvd_add (dvd_mul_of_dvd_right h1 _) (dvd_mul_left _ _) refine ⟨c₀, hroot, fun c hc => ?_⟩ have hdiff : (d : ℤ) ∣ (a : ℤ) ^ s * ((c.val : ℤ) - (c₀.val : ℤ)) := by have e : (a : ℤ) ^ s * ((c.val : ℤ) - (c₀.val : ℤ)) = ((a : ℤ) ^ s * (c.val : ℤ) + μ) - ((a : ℤ) ^ s * (c₀.val : ℤ) + μ) := by ring rw [e] exact dvd_sub (Int.dvd_of_emod_eq_zero hc) (Int.dvd_of_emod_eq_zero hroot) have hdvd : (d : ℤ) ∣ (c.val : ℤ) - (c₀.val : ℤ) := hcop_pow.symm.dvd_of_dvd_mul_left hdiff have hlt : |(c.val : ℤ) - (c₀.val : ℤ)| < (d : ℤ) := by have h1 := c.isLt; have h2 := c₀.isLt exact abs_lt.mpr ⟨by omega, by omega⟩ have heq0 : (c.val : ℤ) - (c₀.val : ℤ) = 0 := Int.eq_zero_of_abs_lt_dvd hdvd hlt exact Fin.ext (by omega) theorem cast_div_exact {d : ℕ} (hd : 0 < d) {x : ℤ} (h : (d : ℤ) ∣ x) : (((x / (d : ℤ) : ℤ)) : ℝ) = (x : ℝ) / (d : ℝ) := by have h1 : (d : ℤ) * (x / (d : ℤ)) = x := Int.mul_ediv_cancel' h have h2 : (d : ℝ) * ((x / (d : ℤ) : ℤ) : ℝ) = (x : ℝ) := by exact_mod_cast h1 have hd0 : (d : ℝ) ≠ 0 := by positivity field_simp; linarith /-- Weight lower bound for digit `0`: `w' ≥ w / d - 1`. -/ theorem weight_step_zero_ge {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (st : State) : (1 / (d : ℝ)) * weight a st - 1 ≤ weight a (step d a st ⟨0, by omega⟩) := by have hdpos : 0 < d := by omega have hdR : (0 : ℝ) < (d : ℝ) := by positivity have haR : (0 : ℝ) < (a : ℝ) := by positivity have hP1 : (1 : ℝ) ≤ (a : ℝ) ^ st.s := one_le_pow₀ (by exact_mod_cast (by omega : 1 ≤ a)) have ha_ge1 : (1 : ℝ) ≤ (a : ℝ) := by exact_mod_cast (by omega : 1 ≤ a) obtain ⟨s, μ⟩ := st unfold step; dsimp only rw [if_pos rfl, Nat.cast_zero, mul_zero, zero_add] by_cases hμ : μ % (d : ℤ) = 0 · rw [if_pos hμ, weight_norm] unfold weight; dsimp only rw [cast_div_exact hdpos (Int.dvd_of_emod_eq_zero hμ), abs_div, abs_of_pos hdR] have e : |(μ : ℝ)| / (d : ℝ) / (a : ℝ) ^ s = (1 / (d : ℝ)) * (|(μ : ℝ)| / (a : ℝ) ^ s) := by ring rw [e]; linarith · rw [if_neg hμ] unfold weight; dsimp only rw [cast_div_exact hdpos (dvd_mul_add_res d a μ), abs_div, abs_of_pos hdR] have hr0 : (0 : ℝ) ≤ (res d a μ : ℝ) := by exact_mod_cast res_nonneg hdpos μ have hrlt : (res d a μ : ℝ) ≤ (d : ℝ) := by exact_mod_cast (res_lt (a := a) hdpos μ).le have habs : (a : ℝ) * |(μ : ℝ)| - (d : ℝ) ≤ |(a : ℝ) * (μ : ℝ) + (res d a μ : ℝ)| := by have h1 := abs_sub_abs_le_abs_sub ((a : ℝ) * (μ : ℝ)) (-(res d a μ : ℝ)) rw [sub_neg_eq_add, abs_mul, abs_of_pos haR, abs_neg, abs_of_nonneg hr0] at h1 linarith push_cast rw [div_div, le_div_iff₀ (mul_pos hdR (pow_pos haR (s + 1)))] have hpow : (a : ℝ) ^ (s + 1) = (a : ℝ) * (a : ℝ) ^ s := pow_succ' _ s have hmul : ((1 / (d : ℝ)) * (|(μ : ℝ)| / (a : ℝ) ^ s) - 1) * ((d : ℝ) * (a : ℝ) ^ (s + 1)) = (a : ℝ) * |(μ : ℝ)| - (d : ℝ) * ((a : ℝ) * (a : ℝ) ^ s) := by rw [hpow]; field_simp rw [hmul] have hbound : (d : ℝ) ≤ (d : ℝ) * ((a : ℝ) * (a : ℝ) ^ s) := by have h1 : (1 : ℝ) ≤ (a : ℝ) * (a : ℝ) ^ s := by nlinarith nlinarith linarith /-- Weight lower bound for level `0`, nonzero `c`, `qRem = 0`: `w' ≥ w / d - 1`. -/ theorem weight_step_level_zero_q0_ge {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (μ : ℤ) (c : Fin d) (hc : c.val ≠ 0) (hqr : ((c.val : ℤ) + μ) % (d : ℤ) = 0) : (1 / (d : ℝ)) * weight a ⟨0, μ⟩ - 1 ≤ weight a (step d a ⟨0, μ⟩ c) := by have hdpos : 0 < d := by omega have hdR : (0 : ℝ) < (d : ℝ) := by positivity have haR : (0 : ℝ) < (a : ℝ) := by positivity have ha_ge1 : (1 : ℝ) ≤ (a : ℝ) := by exact_mod_cast (by omega : 1 ≤ a) have hdvd : (d : ℤ) ∣ res d a (c.val : ℤ) - (a : ℤ) * μ := by have h1 := dvd_mul_add_res d a (c.val : ℤ) have h2 : (d : ℤ) ∣ (a : ℤ) * ((c.val : ℤ) + μ) := dvd_mul_of_dvd_right (Int.dvd_of_emod_eq_zero hqr) _ have h3 : res d a (c.val : ℤ) - (a : ℤ) * μ = ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) - (a : ℤ) * ((c.val : ℤ) + μ) := by ring rw [h3]; exact dvd_sub h1 h2 unfold step; dsimp only rw [if_neg hc, pow_zero, one_mul, if_pos hqr] unfold weight; dsimp only rw [cast_div_exact hdpos hdvd, abs_div, abs_of_pos hdR, pow_one, pow_zero, div_one] have hr0 : (0 : ℝ) ≤ (res d a (c.val : ℤ) : ℝ) := by exact_mod_cast res_nonneg hdpos _ have hrlt : (res d a (c.val : ℤ) : ℝ) ≤ (d : ℝ) := by exact_mod_cast (res_lt (a := a) hdpos _).le have habs : (a : ℝ) * |(μ : ℝ)| - (d : ℝ) ≤ |(res d a (c.val : ℤ) : ℝ) - (a : ℝ) * (μ : ℝ)| := by have h1 := abs_sub_abs_le_abs_sub ((a : ℝ) * (μ : ℝ)) (res d a (c.val : ℤ) : ℝ) rw [abs_mul, abs_of_pos haR, abs_of_nonneg hr0, abs_sub_comm] at h1 linarith push_cast rw [div_div, le_div_iff₀ (mul_pos hdR haR)] have hmul : (1 / (d : ℝ) * |(μ : ℝ)| - 1) * ((d : ℝ) * (a : ℝ)) = (a : ℝ) * |(μ : ℝ)| - (d : ℝ) * (a : ℝ) := by field_simp rw [hmul] nlinarith /-- Weight lower bound for nonzero `c` away from `(s = 0 ∧ qRem = 0)`: `w' ≥ (a / d) * w - 1`. -/ theorem weight_step_nonzero_ge {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (st : State) (c : Fin d) (hc : c.val ≠ 0) (hnot : ¬ (st.s = 0 ∧ ((c.val : ℤ) + st.mu) % (d : ℤ) = 0)) : ((a : ℝ) / (d : ℝ)) * weight a st - 1 ≤ weight a (step d a st c) := by have hdpos : 0 < d := by omega have hdR : (0 : ℝ) < (d : ℝ) := by positivity have haR : (0 : ℝ) < (a : ℝ) := by positivity have hP1 : (1 : ℝ) ≤ (a : ℝ) ^ st.s := one_le_pow₀ (by exact_mod_cast (by omega : 1 ≤ a)) obtain ⟨s, μ⟩ := st unfold step; dsimp only rw [if_neg hc] by_cases hqr : ((a : ℤ) ^ s * (c.val : ℤ) + μ) % (d : ℤ) = 0 · rw [if_pos hqr] cases s with | zero => exfalso; apply hnot; refine ⟨rfl, ?_⟩; simpa [pow_zero] using hqr | succ s' => have hdvd : (d : ℤ) ∣ μ - (a : ℤ) ^ s' * res d a (c.val : ℤ) := by have h1 : (d : ℤ) ∣ (a : ℤ) ^ (s' + 1) * (c.val : ℤ) + μ := Int.dvd_of_emod_eq_zero hqr have h2 : (d : ℤ) ∣ (a : ℤ) ^ s' * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := dvd_mul_of_dvd_right (dvd_mul_add_res d a _) _ have h3 : μ - (a : ℤ) ^ s' * res d a (c.val : ℤ) = ((a : ℤ) ^ (s' + 1) * (c.val : ℤ) + μ) - (a : ℤ) ^ s' * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := by rw [pow_succ]; ring rw [h3]; exact dvd_sub h1 h2 rw [weight_norm] unfold weight; dsimp only rw [cast_div_exact hdpos hdvd, abs_div, abs_of_pos hdR] have hr0 : (0 : ℝ) ≤ (res d a (c.val : ℤ) : ℝ) := by exact_mod_cast res_nonneg hdpos _ have hrlt : (res d a (c.val : ℤ) : ℝ) ≤ (d : ℝ) := by exact_mod_cast (res_lt (a := a) hdpos _).le have hPs' : (0 : ℝ) < (a : ℝ) ^ s' := pow_pos haR s' have habs : |(μ : ℝ)| - (a : ℝ) ^ s' * (d : ℝ) ≤ |(μ : ℝ) - (a : ℝ) ^ s' * (res d a (c.val : ℤ) : ℝ)| := by have h1 := abs_sub_abs_le_abs_sub (μ : ℝ) ((a : ℝ) ^ s' * (res d a (c.val : ℤ) : ℝ)) rw [abs_mul, abs_of_pos hPs', abs_of_nonneg hr0] at h1 nlinarith push_cast rw [div_div, le_div_iff₀ (mul_pos hdR hPs')] have hmul : ((a : ℝ) / (d : ℝ) * (|(μ : ℝ)| / (a : ℝ) ^ (s' + 1)) - 1) * ((d : ℝ) * (a : ℝ) ^ s') = |(μ : ℝ)| - (a : ℝ) ^ s' * (d : ℝ) := by rw [pow_succ']; field_simp rw [hmul]; exact habs · rw [if_neg hqr, weight_norm] have hdvd : (d : ℤ) ∣ (a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ) := by have h1 := dvd_mul_add_res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) have h2 : (d : ℤ) ∣ (a : ℤ) ^ s * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := dvd_mul_of_dvd_right (dvd_mul_add_res d a _) _ have h3 : (a : ℤ) * μ + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) - (a : ℤ) ^ s * res d a (c.val : ℤ) = ((a : ℤ) * ((a : ℤ) ^ s * (c.val : ℤ) + μ) + res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ)) - (a : ℤ) ^ s * ((a : ℤ) * (c.val : ℤ) + res d a (c.val : ℤ)) := by ring rw [h3]; exact dvd_sub h1 h2 unfold weight; dsimp only rw [cast_div_exact hdpos hdvd, abs_div, abs_of_pos hdR] set r1 : ℝ := (res d a ((a : ℤ) ^ s * (c.val : ℤ) + μ) : ℝ) set r2 : ℝ := (res d a (c.val : ℤ) : ℝ) have hr1_0 : 0 ≤ r1 := by dsimp only [r1]; exact_mod_cast res_nonneg hdpos _ have hr1_le : r1 ≤ (d : ℝ) := by dsimp only [r1]; exact_mod_cast (res_lt (a := a) hdpos _).le have hr2_0 : 0 ≤ r2 := by dsimp only [r2]; exact_mod_cast res_nonneg hdpos _ have hr2_le : r2 ≤ (d : ℝ) := by dsimp only [r2]; exact_mod_cast (res_lt (a := a) hdpos _).le have hdiff : |r1 - (a : ℝ) ^ s * r2| ≤ (a : ℝ) ^ s * (d : ℝ) := by rw [abs_le]; constructor <;> nlinarith have habs : (a : ℝ) * |(μ : ℝ)| - (a : ℝ) ^ s * (d : ℝ) ≤ |(a : ℝ) * (μ : ℝ) + r1 - (a : ℝ) ^ s * r2| := by have e : (a : ℝ) * (μ : ℝ) + r1 - (a : ℝ) ^ s * r2 = (a : ℝ) * (μ : ℝ) - ((a : ℝ) ^ s * r2 - r1) := by ring rw [e] have h1 := abs_sub_abs_le_abs_sub ((a : ℝ) * (μ : ℝ)) ((a : ℝ) ^ s * r2 - r1) rw [abs_mul, abs_of_pos haR, abs_sub_comm] at h1 linarith push_cast rw [div_div, le_div_iff₀ (mul_pos hdR (pow_pos haR s))] have hmul : ((a : ℝ) / (d : ℝ) * (|(μ : ℝ)| / (a : ℝ) ^ s) - 1) * ((d : ℝ) * (a : ℝ) ^ s) = (a : ℝ) * |(μ : ℝ)| - (a : ℝ) ^ s * (d : ℝ) := by field_simp rw [hmul]; exact habs /-! ## Section 4: Superharmonic Potential `φ(s, μ) = min 1 ((1 + B * ρ^s) * (W₀ / w)^α)` -/ /-- The bounded superharmonic potential `φ(s, μ) = min 1 ((1 + B * ρ^s) * (W₀ / w)^α)`. -/ noncomputable def phi (a : ℕ) (B ρ W0 α : ℝ) (st : State) : ℝ := if st.mu = 0 then 1 else min 1 ((1 + B * ρ ^ st.s) * (W0 / weight a st) ^ α) theorem phi_nonneg {a : ℕ} {B ρ W0 α : ℝ} (hB : 0 ≤ B) (hρ : 0 ≤ ρ) (hW0 : 0 ≤ W0) (st : State) : 0 ≤ phi a B ρ W0 α st := by unfold phi split_ifs · exact zero_le_one · have h1 : 0 ≤ 1 + B * ρ ^ st.s := by positivity have h2 : 0 ≤ (W0 / weight a st) ^ α := Real.rpow_nonneg (by unfold weight; positivity) α exact le_min zero_le_one (mul_nonneg h1 h2) theorem phi_le_one (a : ℕ) (B ρ W0 α : ℝ) (st : State) : phi a B ρ W0 α st ≤ 1 := by unfold phi split_ifs · exact le_rfl · exact min_le_left _ _ theorem phi_absorbed (a : ℕ) (B ρ W0 α : ℝ) : phi a B ρ W0 α absorbed = 1 := by simp [phi, absorbed] theorem phi_child_le {a : ℕ} {B ρ W0 α w scale : ℝ} {t : State} (hB : 0 ≤ B) (hρ : 0 ≤ ρ) (hW0 : 0 < W0) (hα : 0 < α) (hw : 0 < w) (hscale : 0 < scale) (h : scale * w ≤ weight a t) : phi a B ρ W0 α t ≤ (1 + B * ρ ^ t.s) * (scale ^ (-α) * (W0 / w) ^ α) := by have hwt : 0 < weight a t := lt_of_lt_of_le (mul_pos hscale hw) h have hmu : t.mu ≠ 0 := by intro h0; simp [weight, h0] at hwt have h1 : W0 / weight a t ≤ scale⁻¹ * (W0 / w) := by rw [show scale⁻¹ * (W0 / w) = W0 / (scale * w) by field_simp] exact div_le_div_of_nonneg_left hW0.le (mul_pos hscale hw) h have h2 : (W0 / weight a t) ^ α ≤ scale ^ (-α) * (W0 / w) ^ α := by calc (W0 / weight a t) ^ α ≤ (scale⁻¹ * (W0 / w)) ^ α := Real.rpow_le_rpow (by positivity) h1 hα.le _ = (scale⁻¹) ^ α * (W0 / w) ^ α := Real.mul_rpow (by positivity) (by positivity) _ = scale ^ (-α) * (W0 / w) ^ α := by rw [Real.inv_rpow hscale.le, Real.rpow_neg hscale.le] unfold phi rw [if_neg hmu] exact (min_le_right _ _).trans (mul_le_mul_of_nonneg_left h2 (by positivity)) /-! ### Existence of superharmonic parameters via `ρ = 1 - t`, `t = √(L * α / 4)` -/ theorem tendsto_rpow_slope {c : ℝ} (hc : 0 < c) : Tendsto (fun α : ℝ => (c ^ α - 1) / α) (𝓝[>] 0) (𝓝 (Real.log c)) := by have hderiv : HasDerivAt (fun x : ℝ => c ^ x) (Real.log c) 0 := by have heq : (fun x : ℝ => c ^ x) = fun x : ℝ => Real.exp (Real.log c * x) := by funext x; exact Real.rpow_def_of_pos hc x rw [heq] have h1 : HasDerivAt (fun x : ℝ => Real.log c * x) (Real.log c) 0 := by simpa using (hasDerivAt_id (0 : ℝ)).const_mul (Real.log c) have h2 : HasDerivAt (fun x : ℝ => Real.exp (Real.log c * x)) (Real.exp (Real.log c * 0) * Real.log c) 0 := (Real.hasDerivAt_exp (Real.log c * 0)).comp (0 : ℝ) h1 simpa using h2 have hsl := hderiv.tendsto_slope_zero_right refine hsl.congr' ?_ filter_upwards [self_mem_nhdsWithin] with α hα simp only [zero_add, Real.rpow_zero, smul_eq_mul] rw [div_eq_inv_mul] /-- Above the threshold `d^d < a^(d-1)`, there exist parameters `α > 0`, `ρ = 1 - t ∈ (0, 1)` (`t = √(L * α / 4)`), `B = 1`, `W₀ > 2 * d` satisfying the three strict contraction inequalities required for global superharmonicity of `phi`. -/ theorem exists_superharmonic_params {d a : ℕ} (hd : 2 ≤ d) (hthresh : d ^ d < a ^ (d - 1)) : ∃ (α ρ B W0 : ℝ), 0 < α ∧ 0 < ρ ∧ ρ < 1 ∧ 0 < B ∧ 2 * (d : ℝ) < W0 ∧ let η : ℝ := (d : ℝ) / W0 let Eη : ℝ := (1 - η) ^ (-α) let u : ℝ := (d : ℝ) ^ α let v : ℝ := ((d : ℝ) / (a : ℝ)) ^ α Eη * (u + ((d : ℝ) - 1) * v) ≤ (d : ℝ) ∧ Eη * (2 * (1 + B * ρ) * u + ((d : ℝ) - 2) * (1 + B) * v) ≤ (d : ℝ) * (1 + B) ∧ Eη * (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v) ≤ (d : ℝ) * ρ := by have hda : d < a := d_lt_a_of_thresh hd hthresh have hdpos : (0 : ℝ) < (d : ℝ) := by positivity have hapos : (0 : ℝ) < (a : ℝ) := by exact_mod_cast (by omega : 0 < a) have hda_pos : (0 : ℝ) < (d : ℝ) / (a : ℝ) := div_pos hdpos hapos -- Define `L = (d - 1) * log (a / d) - log d > 0` set L : ℝ := ((d : ℝ) - 1) * Real.log ((a : ℝ) / (d : ℝ)) - Real.log (d : ℝ) have hL_pos : 0 < L := by have hpow : ((d : ℝ)) ^ d < ((a : ℝ)) ^ (d - 1) := by exact_mod_cast hthresh have hlog : Real.log ((d : ℝ) ^ d) < Real.log ((a : ℝ) ^ (d - 1)) := Real.log_lt_log (pow_pos hdpos d) hpow rw [Real.log_pow, Real.log_pow, Nat.cast_sub (by omega : 1 ≤ d), Nat.cast_one] at hlog dsimp only [L] rw [Real.log_div hapos.ne' hdpos.ne'] linarith -- Slope limits as `α → 0⁺` set su : ℝ → ℝ := fun α => ((d : ℝ) ^ α - 1) / α set sv : ℝ → ℝ := fun α => (((d : ℝ) / (a : ℝ)) ^ α - 1) / α set t : ℝ → ℝ := fun α => Real.sqrt (L * α / 4) have hsu : Tendsto su (𝓝[>] 0) (𝓝 (Real.log (d : ℝ))) := tendsto_rpow_slope hdpos have hsv : Tendsto sv (𝓝[>] 0) (𝓝 (Real.log ((d : ℝ) / (a : ℝ)))) := tendsto_rpow_slope hda_pos have hu1 : Tendsto (fun α : ℝ => (d : ℝ) ^ α) (𝓝[>] 0) (𝓝 1) := by have hcont : Continuous (fun α : ℝ => (d : ℝ) ^ α) := continuous_const.rpow continuous_id (fun _ => Or.inl hdpos.ne') have h := (hcont.continuousAt (x := (0 : ℝ))).tendsto.mono_left (nhdsWithin_le_nhds (s := Set.Ioi (0 : ℝ))) simpa [Real.rpow_zero] using h have ht0 : Tendsto t (𝓝[>] 0) (𝓝 0) := by have hc : Continuous (fun α : ℝ => L * α / 4) := by fun_prop have h1 : Tendsto (fun α : ℝ => L * α / 4) (𝓝[>] 0) (𝓝 0) := by have h := (hc.continuousAt (x := (0 : ℝ))).tendsto.mono_left (nhdsWithin_le_nhds (s := Set.Ioi (0 : ℝ))) simpa using h have h2 := (Real.continuous_sqrt.tendsto (0 : ℝ)).comp h1 simpa [t, Function.comp_def] using h2 have hα_div_t : Tendsto (fun α : ℝ => α / t α) (𝓝[>] 0) (𝓝 0) := by have h1 : Tendsto (fun α : ℝ => Real.sqrt (4 * α / L)) (𝓝[>] 0) (𝓝 0) := by have hc : Continuous (fun α : ℝ => 4 * α / L) := by fun_prop have ht : Tendsto (fun α : ℝ => 4 * α / L) (𝓝[>] 0) (𝓝 0) := by have h := (hc.continuousAt (x := (0 : ℝ))).tendsto.mono_left (nhdsWithin_le_nhds (s := Set.Ioi (0 : ℝ))) simpa using h have h2 := (Real.continuous_sqrt.tendsto (0 : ℝ)).comp ht simpa [Function.comp_def] using h2 refine h1.congr' ?_ filter_upwards [self_mem_nhdsWithin] with α hα have hα_pos : 0 < α := hα have hsq : (Real.sqrt (4 * α / L)) * Real.sqrt (L * α / 4) = α := by rw [← Real.sqrt_mul (by positivity)] have e : (4 * α / L) * (L * α / 4) = α ^ 2 := by field_simp rw [e, Real.sqrt_sq hα_pos.le] have ht_pos : 0 < t α := Real.sqrt_pos.mpr (by positivity) rw [eq_div_iff ht_pos.ne'] exact hsq -- Limit 1: `su α + (d - 1) * sv α → -L < 0` have hlog_eq : Real.log (d : ℝ) + ((d : ℝ) - 1) * Real.log ((d : ℝ) / (a : ℝ)) = -L := by dsimp only [L] rw [Real.log_div hdpos.ne' hapos.ne', Real.log_div hapos.ne' hdpos.ne'] ring have hlim1 : Tendsto (fun α : ℝ => su α + ((d : ℝ) - 1) * sv α) (𝓝[>] 0) (𝓝 (-L)) := by rw [← hlog_eq] exact hsu.add (hsv.const_mul ((d : ℝ) - 1)) -- Limit 2: Regime 3 expression divided by `α` tends to `-3 * L / 4 < 0` have hlim3 : Tendsto (fun α : ℝ => (su α + ((d : ℝ) - 1) * sv α) + t α * (-2 * su α - ((d : ℝ) - 2) * sv α) + (L / 4) * (d : ℝ) ^ α) (𝓝[>] 0) (𝓝 (-3 * L / 4)) := by have hmid : Tendsto (fun α : ℝ => t α * (-2 * su α - ((d : ℝ) - 2) * sv α)) (𝓝[>] 0) (𝓝 0) := by have h2 := (hsu.const_mul (-2)).sub (hsv.const_mul ((d : ℝ) - 2)) simpa using ht0.mul h2 have h3 : Tendsto (fun α : ℝ => (L / 4) * (d : ℝ) ^ α) (𝓝[>] 0) (𝓝 (L / 4)) := by simpa using hu1.const_mul (L / 4) have htot := (hlim1.add hmid).add h3 have hlim_val : -L + 0 + L / 4 = -3 * L / 4 := by ring rwa [hlim_val] at htot -- Limit 3: Regime 2 expression divided by `t α` tends to `-2 < 0` have hlim2 : Tendsto (fun α : ℝ => -2 * (d : ℝ) ^ α + 2 * (α / t α) * (2 * su α + ((d : ℝ) - 2) * sv α)) (𝓝[>] 0) (𝓝 (-2)) := by have h1 : Tendsto (fun α : ℝ => -2 * (d : ℝ) ^ α) (𝓝[>] 0) (𝓝 (-2)) := by simpa using hu1.const_mul (-2) have h2 : Tendsto (fun α : ℝ => 2 * (α / t α) * (2 * su α + ((d : ℝ) - 2) * sv α)) (𝓝[>] 0) (𝓝 0) := by have ha' := (hα_div_t.const_mul 2) have hb' := (hsu.const_mul 2).add (hsv.const_mul ((d : ℝ) - 2)) simpa using ha'.mul hb' simpa using h1.add h2 -- Extract a single `α > 0` satisfying all 4 strict inequalities simultaneously have hev0 : ∀ᶠ α in 𝓝[>] (0 : ℝ), 0 < α := self_mem_nhdsWithin have hev1 : ∀ᶠ α in 𝓝[>] (0 : ℝ), su α + ((d : ℝ) - 1) * sv α < 0 := hlim1.eventually (gt_mem_nhds (by linarith)) have hev2 : ∀ᶠ α in 𝓝[>] (0 : ℝ), -2 * (d : ℝ) ^ α + 2 * (α / t α) * (2 * su α + ((d : ℝ) - 2) * sv α) < 0 := hlim2.eventually (gt_mem_nhds (by norm_num)) have hev3 : ∀ᶠ α in 𝓝[>] (0 : ℝ), (su α + ((d : ℝ) - 1) * sv α) + t α * (-2 * su α - ((d : ℝ) - 2) * sv α) + (L / 4) * (d : ℝ) ^ α < 0 := hlim3.eventually (gt_mem_nhds (by linarith)) have hevt : ∀ᶠ α in 𝓝[>] (0 : ℝ), t α < 1 / 2 := ht0.eventually (gt_mem_nhds (by norm_num)) have hev_all := hev0.and (hevt.and (hev1.and (hev2.and hev3))) obtain ⟨α, hα_pos, ht_lt, h1_lt, h2_lt, h3_lt⟩ := hev_all.exists have ht_pos : 0 < t α := Real.sqrt_pos.mpr (by positivity) set ρ : ℝ := 1 - t α have hρ_pos : 0 < ρ := by linarith have hρ_lt1 : ρ < 1 := by linarith set u : ℝ := (d : ℝ) ^ α set v : ℝ := ((d : ℝ) / (a : ℝ)) ^ α -- Convert the 3 slope inequalities into the 3 strict inequalities have hsu_eq : su α = (u - 1) / α := rfl have hsv_eq : sv α = (v - 1) / α := rfl have hI : u + ((d : ℝ) - 1) * v < (d : ℝ) := by have hmul := mul_neg_of_neg_of_pos h1_lt hα_pos have e : (su α + ((d : ℝ) - 1) * sv α) * α = u + ((d : ℝ) - 1) * v - (d : ℝ) := by rw [hsu_eq, hsv_eq]; field_simp; ring linarith have hII : 2 * (1 + 1 * ρ) * u + ((d : ℝ) - 2) * (1 + 1) * v < (d : ℝ) * (1 + 1) := by have hmul := mul_neg_of_neg_of_pos h2_lt ht_pos have e : (-2 * u + 2 * (α / t α) * (2 * su α + ((d : ℝ) - 2) * sv α)) * t α = 2 * (1 + 1 * ρ) * u + ((d : ℝ) - 2) * (1 + 1) * v - (d : ℝ) * (1 + 1) := by rw [hsu_eq, hsv_eq] dsimp only [ρ] have hα0 : α ≠ 0 := hα_pos.ne' have ht0' : t α ≠ 0 := ht_pos.ne' field_simp ring linarith have hIII : ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v < (d : ℝ) * ρ := by have hmul := mul_neg_of_neg_of_pos h3_lt hα_pos have ht_sq : (t α) ^ 2 = L * α / 4 := Real.sq_sqrt (by positivity) have hL4 : (L / 4) = (t α) ^ 2 / α := by rw [ht_sq]; field_simp have e : ((su α + ((d : ℝ) - 1) * sv α) + t α * (-2 * su α - ((d : ℝ) - 2) * sv α) + (L / 4) * u) * α = ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v - (d : ℝ) * ρ := by rw [hL4, hsu_eq, hsv_eq] dsimp only [ρ] have hα0 : α ≠ 0 := hα_pos.ne' field_simp ring linarith -- Choose `η ∈ (0, 1/2)` so that `(1 - η)^(-α)` preserves all three inequalities have hE_lim : Tendsto (fun η : ℝ => (1 - η) ^ (-α)) (𝓝[>] 0) (𝓝 1) := by have hcont : ContinuousAt (fun η : ℝ => (1 - η) ^ (-α)) 0 := by have h1 : ContinuousAt (fun η : ℝ => 1 - η) 0 := continuous_const.sub continuous_id |>.continuousAt have hne : (1 : ℝ) - 0 ≠ 0 := by norm_num exact h1.rpow_const (Or.inl hne) simpa using hcont.tendsto.mono_left (nhdsWithin_le_nhds (s := Set.Ioi (0 : ℝ))) have hE0 : ∀ᶠ η in 𝓝[>] (0 : ℝ), 0 < η := self_mem_nhdsWithin have hE1 : ∀ᶠ η in 𝓝[>] (0 : ℝ), (1 - η) ^ (-α) * (u + ((d : ℝ) - 1) * v) < (d : ℝ) := by have h := hE_lim.mul_const (u + ((d : ℝ) - 1) * v) rw [one_mul (u + ((d : ℝ) - 1) * v)] at h exact h.eventually (gt_mem_nhds hI) have hE2 : ∀ᶠ η in 𝓝[>] (0 : ℝ), (1 - η) ^ (-α) * (2 * (1 + 1 * ρ) * u + ((d : ℝ) - 2) * (1 + 1) * v) < (d : ℝ) * (1 + 1) := by have h := hE_lim.mul_const (2 * (1 + 1 * ρ) * u + ((d : ℝ) - 2) * (1 + 1) * v) rw [one_mul (2 * (1 + 1 * ρ) * u + ((d : ℝ) - 2) * (1 + 1) * v)] at h exact h.eventually (gt_mem_nhds hII) have hE3 : ∀ᶠ η in 𝓝[>] (0 : ℝ), (1 - η) ^ (-α) * (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v) < (d : ℝ) * ρ := by have h := hE_lim.mul_const (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v) rw [one_mul (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v)] at h exact h.eventually (gt_mem_nhds hIII) have hE_half : ∀ᶠ η in 𝓝[>] (0 : ℝ), η < 1 / 2 := (tendsto_id.mono_left (nhdsWithin_le_nhds (s := Set.Ioi (0 : ℝ)))).eventually (gt_mem_nhds (by norm_num)) have hE_all := hE0.and (hE_half.and (hE1.and (hE2.and hE3))) obtain ⟨η, hη_pos, hη_lt, hE1', hE2', hE3'⟩ := hE_all.exists refine ⟨α, ρ, 1, (d : ℝ) / η, hα_pos, hρ_pos, hρ_lt1, one_pos, ?_, ?_, ?_, ?_⟩ · rw [lt_div_iff₀ hη_pos]; nlinarith · have hη_eq : (d : ℝ) / ((d : ℝ) / η) = η := by field_simp show (1 - (d : ℝ) / ((d : ℝ) / η)) ^ (-α) * (u + ((d : ℝ) - 1) * v) ≤ (d : ℝ) rw [hη_eq]; exact hE1'.le · have hη_eq : (d : ℝ) / ((d : ℝ) / η) = η := by field_simp show (1 - (d : ℝ) / ((d : ℝ) / η)) ^ (-α) * (2 * (1 + 1 * ρ) * u + ((d : ℝ) - 2) * (1 + 1) * v) ≤ (d : ℝ) * (1 + 1) rw [hη_eq]; exact hE2'.le · have hη_eq : (d : ℝ) / ((d : ℝ) / η) = η := by field_simp show (1 - (d : ℝ) / ((d : ℝ) / η)) ^ (-α) * (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v) ≤ (d : ℝ) * ρ rw [hη_eq]; exact hE3'.le /-! ### Global superharmonicity of `phi` -/ theorem sum_fin_split_zero {d : ℕ} (hd : 0 < d) (f : Fin d → ℝ) : ∑ c : Fin d, f c = f ⟨0, hd⟩ + ∑ c ∈ Finset.univ.erase ⟨0, hd⟩, f c := (Finset.add_sum_erase Finset.univ f (Finset.mem_univ ⟨0, hd⟩)).symm theorem sum_fin_split_two {d : ℕ} (hd : 0 < d) (c₀ : Fin d) (hc₀ : c₀ ≠ ⟨0, hd⟩) (f : Fin d → ℝ) : ∑ c : Fin d, f c = f ⟨0, hd⟩ + f c₀ + ∑ c ∈ (Finset.univ.erase ⟨0, hd⟩).erase c₀, f c := by rw [sum_fin_split_zero hd f] have hmem : c₀ ∈ (Finset.univ : Finset (Fin d)).erase ⟨0, hd⟩ := Finset.mem_erase.mpr ⟨hc₀, Finset.mem_univ _⟩ rw [← Finset.add_sum_erase _ f hmem] ring theorem card_erase_zero {d : ℕ} (hd : 0 < d) : ((Finset.univ : Finset (Fin d)).erase ⟨0, hd⟩).card = d - 1 := by rw [Finset.card_erase_of_mem (Finset.mem_univ _), Finset.card_univ, Fintype.card_fin] theorem card_erase_two {d : ℕ} (hd : 2 ≤ d) (c₀ : Fin d) (hc₀ : c₀ ≠ ⟨0, by omega⟩) : (((Finset.univ : Finset (Fin d)).erase ⟨0, by omega⟩).erase c₀).card = d - 2 := by have hmem : c₀ ∈ (Finset.univ : Finset (Fin d)).erase ⟨0, by omega⟩ := Finset.mem_erase.mpr ⟨hc₀, Finset.mem_univ _⟩ rw [Finset.card_erase_of_mem hmem, card_erase_zero (by omega)]; omega /-- Global superharmonicity of `phi a B ρ W0 α` at EVERY state `st : State`. -/ theorem phi_superharmonic {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (_hda : d < a) {α ρ B W0 : ℝ} (hα : 0 < α) (hρ0 : 0 < ρ) (hB : 0 < B) (hW0_gt : 2 * (d : ℝ) < W0) (hI : (1 - (d : ℝ) / W0) ^ (-α) * ((d : ℝ) ^ α + ((d : ℝ) - 1) * ((d : ℝ) / (a : ℝ)) ^ α) ≤ (d : ℝ)) (hII : (1 - (d : ℝ) / W0) ^ (-α) * (2 * (1 + B * ρ) * (d : ℝ) ^ α + ((d : ℝ) - 2) * (1 + B) * ((d : ℝ) / (a : ℝ)) ^ α) ≤ (d : ℝ) * (1 + B)) (hIII : (1 - (d : ℝ) / W0) ^ (-α) * (ρ ^ 2 * (d : ℝ) ^ α + (1 + ((d : ℝ) - 2) * ρ) * ((d : ℝ) / (a : ℝ)) ^ α) ≤ (d : ℝ) * ρ) (st : State) : (∑ c : Fin d, phi a B ρ W0 α (step d a st c)) / (d : ℝ) ≤ phi a B ρ W0 α st := by have hdpos : 0 < d := by omega have hdR : (0 : ℝ) < (d : ℝ) := by positivity have haR : (0 : ℝ) < (a : ℝ) := by positivity have hW0 : 0 < W0 := by linarith rw [div_le_iff₀ hdR] by_cases hmu : st.mu = 0 · have h1 : phi a B ρ W0 α st = 1 := by simp [phi, hmu] rw [h1, one_mul] calc ∑ c : Fin d, phi a B ρ W0 α (step d a st c) ≤ ∑ _c : Fin d, (1 : ℝ) := Finset.sum_le_sum fun c _ => phi_le_one a B ρ W0 α _ _ = (d : ℝ) := by simp [Finset.sum_const] by_cases hψ : 1 ≤ (1 + B * ρ ^ st.s) * (W0 / weight a st) ^ α · have h1 : phi a B ρ W0 α st = 1 := by unfold phi; rw [if_neg hmu, min_eq_left hψ] rw [h1, one_mul] calc ∑ c : Fin d, phi a B ρ W0 α (step d a st c) ≤ ∑ _c : Fin d, (1 : ℝ) := Finset.sum_le_sum fun c _ => phi_le_one a B ρ W0 α _ _ = (d : ℝ) := by simp [Finset.sum_const] replace hψ := not_le.mp hψ have hphi : phi a B ρ W0 α st = (1 + B * ρ ^ st.s) * (W0 / weight a st) ^ α := by unfold phi; rw [if_neg hmu, min_eq_right hψ.le] have hwpos : 0 < weight a st := by unfold weight have : (0 : ℝ) < |(st.mu : ℝ)| := abs_pos.mpr (by exact_mod_cast hmu) exact div_pos this (pow_pos haR _) have hw_gt : W0 < weight a st := by by_contra hcon replace hcon := not_lt.mp hcon have h1 : 1 ≤ W0 / weight a st := (one_le_div hwpos).mpr hcon have h2 : 1 ≤ (W0 / weight a st) ^ α := Real.one_le_rpow h1 hα.le have h3 : (0 : ℝ) < B * ρ ^ st.s := by positivity nlinarith set η : ℝ := (d : ℝ) / W0 have h1mη_pos : 0 < 1 - η := by dsimp only [η]; rw [sub_pos, div_lt_one hW0]; linarith set Eη : ℝ := (1 - η) ^ (-α) set u : ℝ := (d : ℝ) ^ α set v : ℝ := ((d : ℝ) / (a : ℝ)) ^ α set Q : ℝ := (W0 / weight a st) ^ α have hQ0 : 0 ≤ Q := Real.rpow_nonneg (by positivity) α -- Scale-factor identities have hscale1 : ((1 - η) * (1 / (d : ℝ))) ^ (-α) = Eη * u := by rw [Real.mul_rpow h1mη_pos.le (by positivity), one_div, Real.inv_rpow hdR.le, Real.rpow_neg hdR.le, inv_inv] have hscale2 : ((1 - η) * ((a : ℝ) / (d : ℝ))) ^ (-α) = Eη * v := by calc ((1 - η) * ((a : ℝ) / (d : ℝ))) ^ (-α) = (1 - η) ^ (-α) * ((a : ℝ) / (d : ℝ)) ^ (-α) := Real.mul_rpow h1mη_pos.le (by positivity) _ = Eη * v := by congr 1 rw [Real.rpow_neg (by positivity), ← Real.inv_rpow (by positivity), inv_div] -- Weight multiplicative bounds when `weight a st > W0` have hbound_small : ∀ t : State, (1 / (d : ℝ)) * weight a st - 1 ≤ weight a t → phi a B ρ W0 α t ≤ (1 + B * ρ ^ t.s) * (Eη * u * Q) := by intro t ht have hmul : (1 - η) * (1 / (d : ℝ)) * weight a st ≤ weight a t := by have h1 : 1 ≤ η * (1 / (d : ℝ)) * weight a st := by have e : η * (1 / (d : ℝ)) * weight a st = weight a st / W0 := by dsimp only [η]; field_simp rw [e, one_le_div hW0]; exact hw_gt.le linarith have hle := phi_child_le (B := B) (ρ := ρ) (W0 := W0) (α := α) hB.le hρ0.le hW0 hα hwpos (mul_pos h1mη_pos (by positivity)) hmul rwa [hscale1] at hle have hbound_large : ∀ t : State, ((a : ℝ) / (d : ℝ)) * weight a st - 1 ≤ weight a t → phi a B ρ W0 α t ≤ (1 + B * ρ ^ t.s) * (Eη * v * Q) := by intro t ht have hmul : (1 - η) * ((a : ℝ) / (d : ℝ)) * weight a st ≤ weight a t := by have h1 : 1 ≤ η * ((a : ℝ) / (d : ℝ)) * weight a st := by have e : η * ((a : ℝ) / (d : ℝ)) * weight a st = (a : ℝ) * (weight a st / W0) := by dsimp only [η]; field_simp rw [e] have hdaR : (1 : ℝ) ≤ (a : ℝ) := by exact_mod_cast (by omega : 1 ≤ a) have hgw : 1 ≤ weight a st / W0 := (one_le_div hW0).mpr hw_gt.le nlinarith linarith have hle := phi_child_le (B := B) (ρ := ρ) (W0 := W0) (α := α) hB.le hρ0.le hW0 hα hwpos (mul_pos h1mη_pos (by positivity)) hmul rwa [hscale2] at hle rw [hphi] -- Split on whether `d ∣ st.mu` by_cases hdiv : st.mu % (d : ℤ) = 0 · -- Regime 1: `d ∣ st.mu`. All children stay at level `st.s`. have hs_eq : ∀ c : Fin d, (step d a st c).s = st.s := by intro c by_cases hc : c.val = 0 · unfold step; dsimp only rw [if_pos hc, hc, Nat.cast_zero, mul_zero, zero_add, if_pos hdiv, State.norm_s] · have hqr : ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu) % (d : ℤ) ≠ 0 := by intro h0 have hdvd1 : (d : ℤ) ∣ (a : ℤ) ^ st.s * (c.val : ℤ) := by have := dvd_sub (Int.dvd_of_emod_eq_zero h0) (Int.dvd_of_emod_eq_zero hdiv) simpa using this have hdvd2 : (d : ℤ) ∣ (c.val : ℤ) := (isCoprime_int_of_coprime hcop).pow_right.dvd_of_dvd_mul_left hdvd1 have hlt : (c.val : ℤ) < (d : ℤ) := by exact_mod_cast c.isLt have hpos : (0 : ℤ) < (c.val : ℤ) := by omega have hle : (d : ℤ) ≤ (c.val : ℤ) := Int.le_of_dvd hpos hdvd2 omega unfold step; dsimp only rw [if_neg hc, if_neg hqr, State.norm_s] rw [sum_fin_split_zero hdpos] have h0 := hbound_small _ (weight_step_zero_ge hd ha st) rw [hs_eq ⟨0, hdpos⟩] at h0 have hrest : ∑ c ∈ (Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩, phi a B ρ W0 α (step d a st c) ≤ ((d : ℝ) - 1) * ((1 + B * ρ ^ st.s) * (Eη * v * Q)) := by calc ∑ c ∈ (Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩, phi a B ρ W0 α (step d a st c) ≤ ∑ _c ∈ (Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩, ((1 + B * ρ ^ st.s) * (Eη * v * Q)) := by refine Finset.sum_le_sum fun c hc => ?_ have hcne : c.val ≠ 0 := fun h0' => (Finset.mem_erase.mp hc).1 (Fin.ext h0') have hnot : ¬ (st.s = 0 ∧ ((c.val : ℤ) + st.mu) % (d : ℤ) = 0) := by rintro ⟨_, h0'⟩ rw [Int.add_emod, hdiv, add_zero, Int.emod_emod, Int.emod_eq_of_lt (Int.natCast_nonneg _) (by exact_mod_cast c.isLt)] at h0' exact hcne (by exact_mod_cast h0') have hb := hbound_large _ (weight_step_nonzero_ge hd ha st c hcne hnot) rwa [hs_eq c] at hb _ = ((d : ℝ) - 1) * ((1 + B * ρ ^ st.s) * (Eη * v * Q)) := by rw [Finset.sum_const, card_erase_zero hdpos, nsmul_eq_mul, Nat.cast_sub (by omega : 1 ≤ d), Nat.cast_one] have hfac : (1 + B * ρ ^ st.s) * (Eη * u * Q) + ((d : ℝ) - 1) * ((1 + B * ρ ^ st.s) * (Eη * v * Q)) = (Eη * (u + ((d : ℝ) - 1) * v)) * ((1 + B * ρ ^ st.s) * Q) := by ring have hnonneg : 0 ≤ (1 + B * ρ ^ st.s) * Q := mul_nonneg (by positivity) hQ0 have hkey := mul_le_mul_of_nonneg_right hI hnonneg linarith · -- `¬ (d ∣ st.mu)`: unique nonzero root `c₀` obtain ⟨c₀, hc₀_root, hc₀_uniq⟩ := existsUnique_root_digit hd hcop st.s st.mu have hc₀_val : c₀.val ≠ 0 := by intro h0; rw [h0, Nat.cast_zero, mul_zero, zero_add] at hc₀_root; exact hdiv hc₀_root have hc₀_ne : c₀ ≠ ⟨0, hdpos⟩ := fun h => hc₀_val (congrArg Fin.val h) have hqr_ne : ∀ c ∈ ((Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩).erase c₀, ((a : ℤ) ^ st.s * (c.val : ℤ) + st.mu) % (d : ℤ) ≠ 0 := by intro c hc h0 exact (Finset.mem_erase.mp hc).1 (hc₀_uniq c h0) have hs0 : (step d a st ⟨0, hdpos⟩).s = st.s + 1 := by unfold step; dsimp only rw [if_pos rfl, Nat.cast_zero, mul_zero, zero_add, if_neg hdiv] have hs_rest : ∀ c ∈ ((Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩).erase c₀, (step d a st c).s = st.s := by intro c hc have hcne : c.val ≠ 0 := fun h0 => (Finset.mem_erase.mp (Finset.mem_erase.mp hc).2).1 (Fin.ext h0) unfold step; dsimp only rw [if_neg hcne, if_neg (hqr_ne c hc), State.norm_s] have h0 := hbound_small _ (weight_step_zero_ge hd ha st) rw [hs0] at h0 have hrest : ∑ c ∈ ((Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩).erase c₀, phi a B ρ W0 α (step d a st c) ≤ ((d : ℝ) - 2) * ((1 + B * ρ ^ st.s) * (Eη * v * Q)) := by calc ∑ c ∈ ((Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩).erase c₀, phi a B ρ W0 α (step d a st c) ≤ ∑ _c ∈ ((Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩).erase c₀, ((1 + B * ρ ^ st.s) * (Eη * v * Q)) := by refine Finset.sum_le_sum fun c hc => ?_ have hcne : c.val ≠ 0 := fun h0' => (Finset.mem_erase.mp (Finset.mem_erase.mp hc).2).1 (Fin.ext h0') have hnot : ¬ (st.s = 0 ∧ ((c.val : ℤ) + st.mu) % (d : ℤ) = 0) := by rintro ⟨hs0', h0'⟩ apply hqr_ne c hc; rw [hs0', pow_zero, one_mul]; exact h0' have hb := hbound_large _ (weight_step_nonzero_ge hd ha st c hcne hnot) rwa [hs_rest c hc] at hb _ = ((d : ℝ) - 2) * ((1 + B * ρ ^ st.s) * (Eη * v * Q)) := by rw [Finset.sum_const, card_erase_two hd c₀ hc₀_ne, nsmul_eq_mul, Nat.cast_sub hd, Nat.cast_ofNat] rw [sum_fin_split_two hdpos c₀ hc₀_ne] obtain ⟨s, μ⟩ := st dsimp only at hdiv hc₀_root h0 hrest hQ0 ⊢ cases s with | zero => -- Regime 2: `s = 0`, `¬ (d ∣ μ)`. Both `c = 0` and `c = c₀` move to level `1`. rw [pow_zero, one_mul] at hc₀_root have hsc₀ : (step d a ⟨0, μ⟩ c₀).s = 1 := by unfold step; dsimp only; rw [if_neg hc₀_val, pow_zero, one_mul, if_pos hc₀_root] have hc₀_b := hbound_small _ (weight_step_level_zero_q0_ge hd ha μ c₀ hc₀_val hc₀_root) rw [hsc₀] at hc₀_b simp only [zero_add, pow_zero, mul_one, pow_one] at h0 hc₀_b hrest ⊢ have hfac : (1 + B * ρ) * (Eη * u * Q) + (1 + B * ρ) * (Eη * u * Q) + ((d : ℝ) - 2) * ((1 + B) * (Eη * v * Q)) = (Eη * (2 * (1 + B * ρ) * u + ((d : ℝ) - 2) * (1 + B) * v)) * Q := by ring have hkey := mul_le_mul_of_nonneg_right hII hQ0 linarith | succ s' => -- Regime 3: `s = s' + 1`, `¬ (d ∣ μ)`. `c = 0` goes to `s'+2`, `c₀` to `s'`, rest stay `s'+1`. have hsc₀ : (step d a ⟨s' + 1, μ⟩ c₀).s = s' := by unfold step; dsimp only; rw [if_neg hc₀_val, if_pos hc₀_root, State.norm_s] have hc₀_b := hbound_large _ (weight_step_nonzero_ge hd ha ⟨s' + 1, μ⟩ c₀ hc₀_val (by simp)) rw [hsc₀] at hc₀_b have hfac : (1 + B * ρ ^ (s' + 1 + 1)) * (Eη * u * Q) + (1 + B * ρ ^ s') * (Eη * v * Q) + ((d : ℝ) - 2) * ((1 + B * ρ ^ (s' + 1)) * (Eη * v * Q)) = (Eη * (u + ((d : ℝ) - 1) * v) + B * ρ ^ s' * (Eη * (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v))) * Q := by have e1 : ρ ^ (s' + 1) = ρ ^ s' * ρ := pow_succ ρ s' have e2 : ρ ^ (s' + 1 + 1) = ρ ^ s' * ρ ^ 2 := by ring rw [e1, e2]; ring have hcomb : Eη * (u + ((d : ℝ) - 1) * v) + B * ρ ^ s' * (Eη * (ρ ^ 2 * u + (1 + ((d : ℝ) - 2) * ρ) * v)) ≤ (d : ℝ) * (1 + B * ρ ^ (s' + 1)) := by have hpos : 0 ≤ B * ρ ^ s' := by positivity have h3 := mul_le_mul_of_nonneg_left hIII hpos have e1 : ρ ^ (s' + 1) = ρ ^ s' * ρ := pow_succ ρ s' rw [e1]; linarith have hkey := mul_le_mul_of_nonneg_right hcomb hQ0 linarith /-! ## Section 5: Deterministic Growing Paths from `(0, 1)` -/ /-- For `d ≥ 3` and `a > d`, digit `d - 1` takes `(0, 1)` to `(1, -m₀)` with `m₀ ≥ 1`. -/ theorem step_zero_one_to_level_one {d a : ℕ} (hd : 2 ≤ d) (hda : d < a) : ∃ m₀ : ℤ, 1 ≤ m₀ ∧ step d a ⟨0, 1⟩ ⟨d - 1, by omega⟩ = ⟨1, -m₀⟩ := by have hdpos : 0 < d := by omega have hc_ne : d - 1 ≠ 0 := by omega have hqr : ((a : ℤ) ^ 0 * ((d - 1 : ℕ) : ℤ) + 1) % (d : ℤ) = 0 := by rw [pow_zero, one_mul, Nat.cast_sub (by omega : 1 ≤ d), Nat.cast_one] have e : (d : ℤ) - 1 + 1 = (d : ℤ) := by ring rw [e, Int.emod_self] have hdvd : (d : ℤ) ∣ (a : ℤ) - res d a ((d - 1 : ℕ) : ℤ) := by have h1 := dvd_mul_add_res d a ((d - 1 : ℕ) : ℤ) have h2 : (d : ℤ) ∣ (a : ℤ) * (d : ℤ) := dvd_mul_left _ _ have h3 : (a : ℤ) - res d a ((d - 1 : ℕ) : ℤ) = (a : ℤ) * (d : ℤ) - ((a : ℤ) * ((d - 1 : ℕ) : ℤ) + res d a ((d - 1 : ℕ) : ℤ)) := by rw [Nat.cast_sub (by omega : 1 ≤ d), Nat.cast_one]; ring rw [h3]; exact dvd_sub h2 h1 let m₀ : ℤ := ((a : ℤ) - res d a ((d - 1 : ℕ) : ℤ)) / (d : ℤ) have hm₀_mul : (d : ℤ) * m₀ = (a : ℤ) - res d a ((d - 1 : ℕ) : ℤ) := Int.mul_ediv_cancel' hdvd have hrlt : res d a ((d - 1 : ℕ) : ℤ) < (d : ℤ) := res_lt hdpos _ have hdaZ : (d : ℤ) + 1 ≤ (a : ℤ) := by exact_mod_cast hda have hm₀_pos : 1 ≤ m₀ := by have h1 : 0 < (d : ℤ) * m₀ := by linarith nlinarith refine ⟨m₀, hm₀_pos, ?_⟩ unfold step; dsimp only rw [if_neg hc_ne, if_pos hqr] congr 1 have hneg : res d a ((d - 1 : ℕ) : ℤ) - (a : ℤ) * 1 = (d : ℤ) * (-m₀) := by linear_combination hm₀_mul rw [hneg, Int.mul_ediv_cancel_left _ (by omega)] /-- **Deterministic exponentially-growing step at level `s = 1` for `d ≥ 3`.** For any `μ < 0`, there exists a nonzero digit `i ∈ {1, ..., d - 1}` with `a * i + μ ≢ 0 (mod d)` taking `⟨1, μ⟩` to `⟨1, μ'⟩` with `μ' < 0`, `|μ'| = (a * |μ| + a * r_i - r_j) / d`, `d * |μ'| > a * |μ|`, and `|μ'| ≥ |μ| + 1`. -/ theorem level_one_grow_step {d a : ℕ} (hd3 : 3 ≤ d) (hcop : Nat.Coprime a d) (hda : d < a) (μ : ℤ) (hμ : μ < 0) : ∃ (i : Fin d) (μ' : ℤ), i.val ≠ 0 ∧ ((a : ℤ) * (i.val : ℤ) + μ) % (d : ℤ) ≠ 0 ∧ step d a ⟨1, μ⟩ i = ⟨1, μ'⟩ ∧ μ' < 0 ∧ |μ'| = ((a : ℤ) * |μ| + (a : ℤ) * res d a (i.val : ℤ) - res d a ((a : ℤ) * (i.val : ℤ) + μ)) / (d : ℤ) ∧ (a : ℤ) * |μ| < (d : ℤ) * |μ'| ∧ |μ| + 1 ≤ |μ'| := by have hd2 : 2 ≤ d := by omega have hdpos : 0 < d := by omega obtain ⟨c₀, hc₀_root, hc₀_uniq⟩ := existsUnique_root_digit hd2 hcop 1 μ -- Pick `i ∈ Fin d \ {0, c₀}` (exists since `d ≥ 3`) have hnonempty : (((Finset.univ : Finset (Fin d)).erase ⟨0, hdpos⟩).erase c₀).Nonempty := by apply Finset.card_pos.mp by_cases h0 : c₀ = ⟨0, hdpos⟩ · rw [h0, Finset.erase_idem, card_erase_zero hdpos]; omega · rw [card_erase_two hd2 c₀ h0]; omega obtain ⟨i, hi⟩ := hnonempty have hi_ne_c₀ : i ≠ c₀ := (Finset.mem_erase.mp hi).1 have hi_ne_0 : i ≠ ⟨0, hdpos⟩ := (Finset.mem_erase.mp (Finset.mem_erase.mp hi).2).1 have hi_val : i.val ≠ 0 := fun h0 => hi_ne_0 (Fin.ext h0) have hqr : ((a : ℤ) * (i.val : ℤ) + μ) % (d : ℤ) ≠ 0 := by intro h0 apply hi_ne_c₀ apply hc₀_uniq simpa [pow_one] using h0 set r_i : ℤ := res d a (i.val : ℤ) set r_j : ℤ := res d a ((a : ℤ) * (i.val : ℤ) + μ) have hri_ge : 1 ≤ r_i := by apply res_pos_of_emod_ne_zero hdpos hcop rw [Int.emod_eq_of_lt (Int.natCast_nonneg _) (by exact_mod_cast i.isLt)] exact_mod_cast hi_val have hrj_lt : r_j < (d : ℤ) := res_lt hdpos _ have hdvd : (d : ℤ) ∣ (a : ℤ) * |μ| + (a : ℤ) * r_i - r_j := by have h1 := dvd_mul_add_res d a ((a : ℤ) * (i.val : ℤ) + μ) have h2 : (d : ℤ) ∣ (a : ℤ) * ((a : ℤ) * (i.val : ℤ) + r_i) := dvd_mul_of_dvd_right (dvd_mul_add_res d a _) _ have h3 : (a : ℤ) * |μ| + (a : ℤ) * r_i - r_j = (a : ℤ) * ((a : ℤ) * (i.val : ℤ) + r_i) - ((a : ℤ) * ((a : ℤ) * (i.val : ℤ) + μ) + r_j) := by rw [abs_of_neg hμ]; ring rw [h3]; exact dvd_sub h2 h1 let m' : ℤ := ((a : ℤ) * |μ| + (a : ℤ) * r_i - r_j) / (d : ℤ) have hm'_mul : (d : ℤ) * m' = (a : ℤ) * |μ| + (a : ℤ) * r_i - r_j := Int.mul_ediv_cancel' hdvd have hdaZ : (d : ℤ) + 1 ≤ (a : ℤ) := by exact_mod_cast hda have habs_pos : 1 ≤ |μ| := by rw [abs_of_neg hμ]; omega have hgap : (a : ℤ) * r_i - r_j ≥ 2 := by nlinarith have hm'_gt_exp : (a : ℤ) * |μ| < (d : ℤ) * m' := by linarith have hm'_ge_succ : |μ| + 1 ≤ m' := by have h1 : (d : ℤ) * |μ| < (d : ℤ) * m' := by nlinarith nlinarith have hm'_pos : 0 < m' := by omega refine ⟨i, -m', hi_val, hqr, ?_, by omega, ?_, ?_, ?_⟩ · unfold step; dsimp only rw [if_neg hi_val, pow_one, if_neg hqr, State.norm_of_pos 1 _ one_pos] congr 1 have hnum : (a : ℤ) * μ + r_j - (a : ℤ) * r_i = (d : ℤ) * (-m') := by rw [abs_of_neg hμ] at hm'_mul linear_combination hm'_mul rw [hnum, Int.mul_ediv_cancel_left _ (by omega)] · rw [abs_neg, abs_of_pos hm'_pos] · rw [abs_neg, abs_of_pos hm'_pos]; exact hm'_gt_exp · rw [abs_neg, abs_of_pos hm'_pos]; exact hm'_ge_succ /-- For `d ≥ 3`, from `(0, 1)` one can deterministically reach `(1, -m)` with arbitrarily large `m`. -/ theorem reach_large_ge_three {d a : ℕ} (hd3 : 3 ≤ d) (hcop : Nat.Coprime a d) (hda : d < a) : ∀ n : ℕ, ∃ (w : List (Fin d)) (m : ℤ), (n : ℤ) + 1 ≤ m ∧ run d a ⟨0, 1⟩ w = ⟨1, -m⟩ | 0 => by obtain ⟨m₀, hm₀, hstep⟩ := step_zero_one_to_level_one (by omega : 2 ≤ d) hda exact ⟨[⟨d - 1, by omega⟩], m₀, by simp; omega, by simpa [run] using hstep⟩ | n + 1 => by obtain ⟨w, m, hm, hw⟩ := reach_large_ge_three hd3 hcop hda n obtain ⟨i, μ', _, _, hstep, hμ'_neg, _, _, hgrow⟩ := level_one_grow_step hd3 hcop hda (-m) (by omega) refine ⟨w ++ [i], -μ', ?_, ?_⟩ · have h1 : |-m| = m := by rw [abs_neg, abs_of_pos (by omega)] have h2 : |μ'| = -μ' := abs_of_neg hμ'_neg push_cast; linarith · rw [run, List.foldl_append] change step d a (run d a ⟨0, 1⟩ w) i = ⟨1, -(-μ')⟩ rw [hw, hstep, neg_neg] /-! ### Deterministic growing path for `d = 2` (`a ≥ 5` odd) -/ def Fam2 (st : State) (m : ℤ) : Prop := st = ⟨0, m⟩ ∨ st = ⟨1, -m⟩ theorem res_two_of_odd {a : ℕ} (ha_odd : a % 2 = 1) {x : ℤ} (hx : x % 2 = 1) : res 2 a x = 1 := by unfold res have haZ : (-(a : ℤ)) % 2 = 1 := by omega rw [Nat.cast_ofNat, Int.mul_emod, haZ, hx] norm_num theorem step2_one_level_zero {a : ℕ} (ha_odd : a % 2 = 1) (ha5 : 5 ≤ a) (m : ℤ) (hm : 1 ≤ m) : ∃ m' : ℤ, 1 ≤ m' ∧ 5 * m - 1 ≤ 2 * m' ∧ Fam2 (step 2 a ⟨0, m⟩ ⟨1, by norm_num⟩) m' := by have haZ : (a : ℤ) % 2 = 1 := by omega have ha5Z : (5 : ℤ) ≤ (a : ℤ) := by exact_mod_cast ha5 have hp : 5 * m ≤ (a : ℤ) * m := mul_le_mul_of_nonneg_right ha5Z (by omega) have hpm : (a : ℤ) * m % 2 = m % 2 := by rw [Int.mul_emod, haZ, one_mul]; omega have hres1 : res 2 a 1 = 1 := res_two_of_odd ha_odd (by norm_num) rcases Int.emod_two_eq_zero_or_one m with hpar | hpar · have hqr : (1 + m) % 2 ≠ 0 := by omega have hres_q : res 2 a (1 + m) = 1 := res_two_of_odd ha_odd (by omega) have hst : step 2 a ⟨0, m⟩ ⟨1, by norm_num⟩ = ⟨0, (a : ℤ) * m / 2⟩ := by unfold step; dsimp only rw [if_neg (by norm_num), pow_zero, one_mul, Nat.cast_one, Nat.cast_ofNat, if_neg hqr, State.norm_zero, hres_q, hres1] congr 1 have e : (a : ℤ) * m + 1 - 1 * 1 = (a : ℤ) * m := by ring rw [e, abs_of_nonneg] generalize (a : ℤ) * m = p at hp; omega refine ⟨(a : ℤ) * m / 2, ?_, ?_, Or.inl hst⟩ · generalize (a : ℤ) * m = p at hp hpm; omega · generalize (a : ℤ) * m = p at hp hpm; omega · have hqr : (1 + m) % 2 = 0 := by omega have hst : step 2 a ⟨0, m⟩ ⟨1, by norm_num⟩ = ⟨1, -(((a : ℤ) * m - 1) / 2)⟩ := by unfold step; dsimp only rw [if_neg (by norm_num), pow_zero, one_mul, Nat.cast_one, Nat.cast_ofNat, if_pos hqr, hres1] congr 1 generalize (a : ℤ) * m = p at hp hpm; omega refine ⟨((a : ℤ) * m - 1) / 2, ?_, ?_, Or.inr hst⟩ · generalize (a : ℤ) * m = p at hp hpm; omega · generalize (a : ℤ) * m = p at hp hpm; omega theorem fam2_grow {a : ℕ} (ha_odd : a % 2 = 1) (ha5 : 5 ≤ a) (st : State) (m : ℤ) (hm : 1 ≤ m) (h : Fam2 st m) : ∃ (w : List (Fin 2)) (m' : ℤ), m + 1 ≤ m' ∧ Fam2 (run 2 a st w) m' := by have haZ : (a : ℤ) % 2 = 1 := by omega have ha5Z : (5 : ℤ) ≤ (a : ℤ) := by exact_mod_cast ha5 have hp : 5 * m ≤ (a : ℤ) * m := mul_le_mul_of_nonneg_right ha5Z (by omega) have hpm : (a : ℤ) * m % 2 = m % 2 := by rw [Int.mul_emod, haZ, one_mul]; omega have hres1 : res 2 a 1 = 1 := res_two_of_odd ha_odd (by norm_num) rcases h with rfl | rfl · obtain ⟨m', _, h2, h3⟩ := step2_one_level_zero ha_odd ha5 m hm exact ⟨[⟨1, by norm_num⟩], m', by omega, by simpa [run] using h3⟩ · rcases Int.emod_two_eq_zero_or_one m with hpar | hpar · have hqr : ((a : ℤ) + -m) % 2 ≠ 0 := by omega have hres_q : res 2 a ((a : ℤ) + -m) = 1 := res_two_of_odd ha_odd (by omega) have hst : step 2 a ⟨1, -m⟩ ⟨1, by norm_num⟩ = ⟨1, -(((a : ℤ) * m + (a : ℤ) - 1) / 2)⟩ := by unfold step; dsimp only rw [if_neg (by norm_num), pow_one, Nat.cast_one, mul_one, Nat.cast_ofNat, if_neg hqr, State.norm_of_pos 1 _ one_pos, hres_q, hres1] congr 1 have e : (a : ℤ) * -m = -((a : ℤ) * m) := by ring rw [e]; generalize (a : ℤ) * m = p at hp hpm; omega refine ⟨[⟨1, by norm_num⟩], ((a : ℤ) * m + (a : ℤ) - 1) / 2, ?_, Or.inr (by simpa [run] using hst)⟩ generalize (a : ℤ) * m = p at hp hpm; omega · have hqr : ((a : ℤ) + -m) % 2 = 0 := by omega have hst1 : step 2 a ⟨1, -m⟩ ⟨1, by norm_num⟩ = ⟨0, (m + 1) / 2⟩ := by unfold step; dsimp only rw [if_neg (by norm_num), pow_one, Nat.cast_one, mul_one, Nat.cast_ofNat, if_pos hqr, State.norm_zero, pow_zero, one_mul, hres1] congr 1; rw [abs_of_nonpos (by omega)]; omega obtain ⟨m', _, h3, h4⟩ := step2_one_level_zero ha_odd ha5 ((m + 1) / 2) (by omega) refine ⟨[⟨1, by norm_num⟩, ⟨1, by norm_num⟩], m', by omega, ?_⟩ change Fam2 (step 2 a (step 2 a ⟨1, -m⟩ ⟨1, by norm_num⟩) ⟨1, by norm_num⟩) m' rw [hst1]; exact h4 theorem reach_large_two {a : ℕ} (ha_odd : a % 2 = 1) (ha5 : 5 ≤ a) : ∀ n : ℕ, ∃ (w : List (Fin 2)) (m : ℤ), (n : ℤ) + 1 ≤ m ∧ Fam2 (run 2 a ⟨0, 1⟩ w) m | 0 => ⟨[], 1, by norm_num, Or.inl rfl⟩ | n + 1 => by obtain ⟨w, m, hm, hF⟩ := reach_large_two ha_odd ha5 n obtain ⟨w', m', hm', hF'⟩ := fam2_grow ha_odd ha5 _ m (by omega) hF refine ⟨w ++ w', m', by push_cast; omega, ?_⟩ rw [run, List.foldl_append]; exact hF' /-- Unified reachability for ALL `d ≥ 2`: from `(0, 1)` one can reach a state of arbitrarily large weight `w`. -/ theorem reach_large_weight {d a : ℕ} (hd : 2 ≤ d) (hcop : Nat.Coprime a d) (hthresh : d ^ d < a ^ (d - 1)) (W : ℝ) : ∃ w : List (Fin d), W ≤ weight a (run d a ⟨0, 1⟩ w) := by have hda : d < a := d_lt_a_of_thresh hd hthresh have haR : (0 : ℝ) < (a : ℝ) := by exact_mod_cast (by omega : 0 < a) obtain ⟨N, hN⟩ := exists_nat_ge (max W 1 * (a : ℝ)) by_cases hd2 : d = 2 · subst hd2 have ha5 : 5 ≤ a := by simp at hthresh; omega have ha_odd : a % 2 = 1 := by have h := Nat.coprime_two_right.mp hcop exact Nat.odd_iff.mp h obtain ⟨w, m, hm, hF⟩ := reach_large_two ha_odd ha5 N refine ⟨w, ?_⟩ have hmR : (N : ℝ) + 1 ≤ (m : ℝ) := by exact_mod_cast hm have hmpos : (0 : ℝ) < (m : ℝ) := by linarith have ha_ge1 : (1 : ℝ) ≤ (a : ℝ) := by exact_mod_cast (by omega : 1 ≤ a) rcases hF with heq | heq · rw [heq]; unfold weight; dsimp only rw [pow_zero, div_one, abs_of_pos hmpos] have : max W 1 ≤ max W 1 * (a : ℝ) := le_mul_of_one_le_right (by positivity) ha_ge1 linarith [le_max_left W 1] · rw [heq]; unfold weight; dsimp only rw [pow_one, Int.cast_neg, abs_neg, abs_of_pos hmpos, le_div_iff₀ haR] have : W * (a : ℝ) ≤ max W 1 * (a : ℝ) := mul_le_mul_of_nonneg_right (le_max_left W 1) haR.le linarith · have hd3 : 3 ≤ d := by omega obtain ⟨w, m, hm, hw⟩ := reach_large_ge_three hd3 hcop hda N refine ⟨w, ?_⟩ rw [hw]; unfold weight; dsimp only have hmR : (N : ℝ) + 1 ≤ (m : ℝ) := by exact_mod_cast hm have hmpos : (0 : ℝ) < (m : ℝ) := by linarith rw [pow_one, Int.cast_neg, abs_neg, abs_of_pos hmpos, le_div_iff₀ haR] have : W * (a : ℝ) ≤ max W 1 * (a : ℝ) := mul_le_mul_of_nonneg_right (le_max_left W 1) haR.le linarith /-! ## Section 6: Theorem 1.1 (Positive Unmerged Density Above Threshold) -/ /-- **Theorem 1.1 (Saturation of pair-chain absorption above threshold).** -/ theorem saturation_above_threshold {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (hthresh : d ^ d < a ^ (d - 1)) : ∃ ε : ℝ, 0 < ε ∧ ∀ k : ℕ, pAbs (step d a) absorbed k ⟨0, 1⟩ ≤ 1 - ε := by have hdpos : 0 < d := by omega have hda : d < a := d_lt_a_of_thresh hd hthresh obtain ⟨α, ρ, B, W0, hα, hρ0, hρ1, hB, hW0_gt, hI, hII, hIII⟩ := exists_superharmonic_params hd hthresh have hW0 : 0 < W0 := by have : (0 : ℝ) < (d : ℝ) := by positivity linarith have hsuper : ∀ st : State, (∑ c : Fin d, phi a B ρ W0 α (step d a st c)) / (d : ℝ) ≤ phi a B ρ W0 α st := phi_superharmonic hd ha hcop hda hα hρ0 hB hW0_gt hI hII hIII -- Reach a state `st*` with `weight a st* ≥ W0 * (2 * (1 + B)) ^ (1 / α)` so `phi st* ≤ 1/2` set Wtarget : ℝ := W0 * (2 * (1 + B)) ^ (1 / α) obtain ⟨w, hw⟩ := reach_large_weight hd hcop hthresh Wtarget set stStar : State := run d a ⟨0, 1⟩ w have hphi_star : phi a B ρ W0 α stStar ≤ 1 / 2 := by have h2B : (0 : ℝ) < 2 * (1 + B) := by linarith have hWt_pos : 0 < Wtarget := mul_pos hW0 (Real.rpow_pos_of_pos h2B _) have hws_pos : 0 < weight a stStar := lt_of_lt_of_le hWt_pos hw have hmu_ne : stStar.mu ≠ 0 := by intro h0; simp [weight, h0] at hws_pos have hrat : W0 / weight a stStar ≤ ((2 * (1 + B)) ^ (1 / α))⁻¹ := by rw [div_le_iff₀ hws_pos, inv_mul_eq_div, le_div_iff₀ (Real.rpow_pos_of_pos h2B _)] have e : W0 * (2 * (1 + B)) ^ (1 / α) = Wtarget := rfl linarith have hrpow : (W0 / weight a stStar) ^ α ≤ (2 * (1 + B))⁻¹ := by calc (W0 / weight a stStar) ^ α ≤ (((2 * (1 + B)) ^ (1 / α))⁻¹) ^ α := Real.rpow_le_rpow (by positivity) hrat hα.le _ = (((2 * (1 + B)) ^ (1 / α)) ^ α)⁻¹ := Real.inv_rpow (by positivity) α _ = (2 * (1 + B))⁻¹ := by rw [← Real.rpow_mul h2B.le, one_div_mul_cancel hα.ne', Real.rpow_one] have hcoeff : 1 + B * ρ ^ stStar.s ≤ 1 + B := by have hρle : ρ ^ stStar.s ≤ 1 := pow_le_one₀ hρ0.le hρ1.le nlinarith unfold phi rw [if_neg hmu_ne] refine (min_le_right _ _).trans ?_ calc (1 + B * ρ ^ stStar.s) * (W0 / weight a stStar) ^ α ≤ (1 + B) * (2 * (1 + B))⁻¹ := mul_le_mul hcoeff hrpow (Real.rpow_nonneg (by positivity) _) (by linarith) _ = 1 / 2 := by field_simp refine ⟨(1 / (d : ℝ)) ^ w.length * (1 / 2), by positivity, fun k => ?_⟩ have hmono := pAbs_mono hdpos (step d a) absorbed step_absorbed (show k ≤ w.length + k by omega) ⟨0, 1⟩ have hword := pAbs_word_le hdpos (step d a) absorbed k w ⟨0, 1⟩ have hphi := pAbs_le_of_super (step d a) absorbed (phi a B ρ W0 α) (phi_nonneg hB.le hρ0.le hW0.le) (phi_absorbed a B ρ W0 α).ge hsuper k stStar have hrun : List.foldl (step d a) ⟨0, 1⟩ w = stStar := rfl rw [hrun] at hword have hpow : (0 : ℝ) ≤ (1 / (d : ℝ)) ^ w.length := by positivity have hmul : (1 / (d : ℝ)) ^ w.length * (1 / 2) ≤ (1 / (d : ℝ)) ^ w.length * (1 - pAbs (step d a) absorbed k stStar) := mul_le_mul_of_nonneg_left (by linarith) hpow linarith /-- **Theorem 1.1 (Positive unmerged density above the sharp threshold).** For every `d ≥ 2` and `a > 1` with `Nat.Coprime a d` and `d^d < a^(d - 1)`, there exists `ε > 0` such that for all `k ≥ 1`, `C_k(d, a, 1) / d^k ≤ 1 - ε`. -/ theorem above_threshold_unmerged {d a : ℕ} (hd : 2 ≤ d) (ha : 1 < a) (hcop : Nat.Coprime a d) (hthresh : d ^ d < a ^ (d - 1)) : ∃ ε : ℝ, 0 < ε ∧ ∀ k : ℕ, 1 ≤ k → ((C_k d a 1 k : ℕ) : ℝ) / (d : ℝ) ^ k ≤ 1 - ε := by obtain ⟨ε, hε, hsat⟩ := saturation_above_threshold hd ha hcop hthresh refine ⟨ε, hε, fun k _ => ?_⟩ rw [C_k_div_pow_eq_pAbs hd ha hcop 1 k] exact hsat k end DAdicCollatz.AboveThreshold #print axioms DAdicCollatz.AboveThreshold.exists_superharmonic_params #print axioms DAdicCollatz.AboveThreshold.phi_superharmonic #print axioms DAdicCollatz.AboveThreshold.level_one_grow_step #print axioms DAdicCollatz.AboveThreshold.saturation_above_threshold #print axioms DAdicCollatz.AboveThreshold.above_threshold_unmerged