import Mathlib /-! # Binary Matrix Semigroup Mortality: Near-Optimal $2^{n - O(\sqrt{n})}$ and $2^{n - O(\log^2 n / \log\log n)}$ Lower Bounds This file constructs an explicit infinite family of **pairs** `(M₀, M₁)` of `n × n` binary (`0`-`1`) matrices that are **mortal** (some non-empty product equals `0`) yet every zero product has length exponential in `n - o(n)`. -/ namespace BinaryMatrixMortality open Finset /-! ## Section 1: Binary Matrices, Products, and NFA Subset Equivalence -/ section MatrixNFA /-- A matrix over a semiring `R` is binary if every entry is `0` or `1`. -/ def IsBinaryMatrix {V R : Type*} [Zero R] [One R] (M : Matrix V V R) : Prop := ∀ i j : V, M i j = 0 ∨ M i j = 1 /-- Left-to-right product of a word of binary choices `false ↦ M₀`, `true ↦ M₁`. -/ def evalMat {V R : Type*} [Fintype V] [DecidableEq V] [Semiring R] (M₀ M₁ : Matrix V V R) (w : List Bool) : Matrix V V R := (w.map fun b => if b then M₁ else M₀).prod /-- A pair `(M₀, M₁)` of `n × n` matrices over `R` is a mortal binary pair if both are binary and some non-empty word multiplies to the zero matrix. -/ def IsMortalBinaryPairOver (R : Type*) [Semiring R] (n : ℕ) (M₀ M₁ : Matrix (Fin n) (Fin n) R) : Prop := IsBinaryMatrix M₀ ∧ IsBinaryMatrix M₁ ∧ ∃ w : List Bool, w ≠ [] ∧ evalMat M₀ M₁ w = 0 /-- Transition matrix over `ℕ` associated with an NFA transition function `δ : V → Finset V`. -/ def toMatrix {V : Type*} [DecidableEq V] (δ : V → Finset V) : Matrix V V ℕ := fun i j => if j ∈ δ i then 1 else 0 theorem isBinaryMatrix_toMatrix {V : Type*} [DecidableEq V] (δ : V → Finset V) : IsBinaryMatrix (toMatrix δ) := by intro i j unfold toMatrix split_ifs <;> simp /-- Subset image of one NFA transition step. -/ def step {V : Type*} [DecidableEq V] (δ : V → Finset V) (S : Finset V) : Finset V := S.biUnion δ /-- Multi-step NFA subset image along a word `w : List Bool`. -/ def evalStep {V : Type*} [DecidableEq V] (δ₀ δ₁ : V → Finset V) (S : Finset V) (w : List Bool) : Finset V := w.foldl (fun acc b => step (if b then δ₁ else δ₀) acc) S @[simp] theorem evalStep_nil {V : Type*} [DecidableEq V] (δ₀ δ₁ : V → Finset V) (S : Finset V) : evalStep δ₀ δ₁ S [] = S := rfl @[simp] theorem evalStep_cons {V : Type*} [DecidableEq V] (δ₀ δ₁ : V → Finset V) (S : Finset V) (b : Bool) (w : List Bool) : evalStep δ₀ δ₁ S (b :: w) = evalStep δ₀ δ₁ (step (if b then δ₁ else δ₀) S) w := rfl theorem evalStep_append {V : Type*} [DecidableEq V] (δ₀ δ₁ : V → Finset V) (S : Finset V) (w₁ w₂ : List Bool) : evalStep δ₀ δ₁ S (w₁ ++ w₂) = evalStep δ₀ δ₁ (evalStep δ₀ δ₁ S w₁) w₂ := by simp [evalStep, List.foldl_append] theorem step_mono {V : Type*} [DecidableEq V] (δ : V → Finset V) {S T : Finset V} (h : S ⊆ T) : step δ S ⊆ step δ T := Finset.biUnion_subset_biUnion_of_subset_left δ h theorem evalStep_mono {V : Type*} [DecidableEq V] (δ₀ δ₁ : V → Finset V) {S T : Finset V} (h : S ⊆ T) (w : List Bool) : evalStep δ₀ δ₁ S w ⊆ evalStep δ₀ δ₁ T w := by induction w generalizing S T with | nil => exact h | cons b w ih => exact ih (step_mono _ h) @[simp] theorem mem_step {V : Type*} [DecidableEq V] (δ : V → Finset V) (S : Finset V) (y : V) : y ∈ step δ S ↔ ∃ x ∈ S, y ∈ δ x := by simp [step] theorem step_biUnion {V W : Type*} [DecidableEq V] [DecidableEq W] (δ : V → Finset V) (S : Finset W) (f : W → Finset V) : step δ (S.biUnion f) = S.biUnion (fun x => step δ (f x)) := by ext y simp only [mem_step, Finset.mem_biUnion] constructor · rintro ⟨a, ⟨x, hx, ha⟩, hy⟩; exact ⟨x, hx, a, ha, hy⟩ · rintro ⟨x, hx, a, ha, hy⟩; exact ⟨a, ⟨x, hx, ha⟩, hy⟩ theorem evalStep_biUnion {V W : Type*} [DecidableEq V] [DecidableEq W] (δ₀ δ₁ : V → Finset V) (S : Finset W) (f : W → Finset V) (w : List Bool) : evalStep δ₀ δ₁ (S.biUnion f) w = S.biUnion (fun x => evalStep δ₀ δ₁ (f x) w) := by induction w generalizing f with | nil => rfl | cons b w ih => simp only [evalStep_cons] rw [step_biUnion] exact ih (fun x => step (if b then δ₁ else δ₀) (f x)) theorem evalMat_append {V R : Type*} [Fintype V] [DecidableEq V] [Semiring R] (M₀ M₁ : Matrix V V R) (w₁ w₂ : List Bool) : evalMat M₀ M₁ (w₁ ++ w₂) = evalMat M₀ M₁ w₁ * evalMat M₀ M₁ w₂ := by simp [evalMat, List.map_append, List.prod_append] theorem evalMat_snoc {V R : Type*} [Fintype V] [DecidableEq V] [Semiring R] (M₀ M₁ : Matrix V V R) (w : List Bool) (b : Bool) : evalMat M₀ M₁ (w ++ [b]) = evalMat M₀ M₁ w * (if b then M₁ else M₀) := by simp [evalMat, List.map_append, List.prod_append] private lemma mul_toMatrix_ne_zero_iff {V : Type*} [Fintype V] [DecidableEq V] (A : Matrix V V ℕ) (δ : V → Finset V) (i j : V) : (A * toMatrix δ) i j ≠ 0 ↔ ∃ s : V, A i s ≠ 0 ∧ j ∈ δ s := by rw [Matrix.mul_apply, ne_eq, Finset.sum_eq_zero_iff] push Not constructor · rintro ⟨s, _, hs⟩ refine ⟨s, ?_, ?_⟩ · intro h0; simp [h0] at hs · by_contra hnot; simp [toMatrix, hnot] at hs · rintro ⟨s, hs1, hs2⟩ exact ⟨s, Finset.mem_univ s, by simp [toMatrix, hs2, hs1]⟩ theorem evalMat_ne_zero_iff {V : Type*} [Fintype V] [DecidableEq V] (δ₀ δ₁ : V → Finset V) (w : List Bool) (i j : V) : evalMat (toMatrix δ₀) (toMatrix δ₁) w i j ≠ 0 ↔ j ∈ evalStep δ₀ δ₁ {i} w := by induction w using List.reverseRecOn generalizing i j with | nil => simp only [evalMat, List.map_nil, List.prod_nil, evalStep_nil, Finset.mem_singleton] by_cases h : i = j · subst h; simp · simp [Matrix.one_apply_ne h, Ne.symm h] | append_singleton w b ih => rw [evalMat_snoc, evalStep_append, evalStep_cons, evalStep_nil] by_cases hb : b · subst hb simp only [ite_true] rw [mul_toMatrix_ne_zero_iff] simp only [ih, mem_step] · simp only [hb, Bool.false_eq_true, ↓reduceIte] rw [mul_toMatrix_ne_zero_iff] simp only [ih, mem_step] theorem evalMat_eq_zero_iff {V : Type*} [Fintype V] [DecidableEq V] (δ₀ δ₁ : V → Finset V) (w : List Bool) : evalMat (toMatrix δ₀) (toMatrix δ₁) w = 0 ↔ evalStep δ₀ δ₁ Finset.univ w = ∅ := by have huniv : (Finset.univ : Finset V) = Finset.univ.biUnion (fun i : V => ({i} : Finset V)) := by ext x; simp constructor · intro h0 rw [huniv, evalStep_biUnion, Finset.eq_empty_iff_forall_notMem] intro j hj simp only [Finset.mem_biUnion, Finset.mem_univ, true_and] at hj obtain ⟨i, hi⟩ := hj have := (evalMat_ne_zero_iff δ₀ δ₁ w i j).2 hi rw [h0] at this exact this rfl · intro h0 ext i j by_contra hne have hj : j ∈ evalStep δ₀ δ₁ {i} w := (evalMat_ne_zero_iff δ₀ δ₁ w i j).1 hne have hsub : evalStep δ₀ δ₁ {i} w ⊆ evalStep δ₀ δ₁ Finset.univ w := evalStep_mono δ₀ δ₁ (Finset.subset_univ _) w rw [h0] at hsub exact Finset.notMem_empty j (hsub hj) /-- Reindexing matrices by an equivalence preserves `evalMat`, `IsBinaryMatrix`, and `= 0`. -/ theorem reindex_evalMat {V W : Type*} (R : Type*) [Fintype V] [DecidableEq V] [Fintype W] [DecidableEq W] [Semiring R] (e : V ≃ W) (M₀ M₁ : Matrix V V R) (w : List Bool) : evalMat (Matrix.reindexRingEquiv R e M₀) (Matrix.reindexRingEquiv R e M₁) w = Matrix.reindexRingEquiv R e (evalMat M₀ M₁ w) := by unfold evalMat rw [map_list_prod] congr 1 induction w with | nil => rfl | cons b w ih => simp only [List.map_cons, List.cons.injEq] exact ⟨by cases b <;> rfl, ih⟩ theorem isBinaryMatrix_reindex {V W : Type*} (R : Type*) [Semiring R] [Fintype V] [Fintype W] (e : V ≃ W) {M : Matrix V V R} (hM : IsBinaryMatrix M) : IsBinaryMatrix (Matrix.reindexRingEquiv R e M) := by intro i j exact hM (e.symm i) (e.symm j) /-- Lifting binary matrix products from `ℕ` to any characteristic-zero semiring `R`. -/ theorem map_natCast_evalMat {V R : Type*} [Fintype V] [DecidableEq V] [Semiring R] (M₀ M₁ : Matrix V V ℕ) (w : List Bool) : evalMat (M₀.map (Nat.cast : ℕ → R)) (M₁.map (Nat.cast : ℕ → R)) w = (evalMat M₀ M₁ w).map (Nat.cast : ℕ → R) := by let f : Matrix V V ℕ →+* Matrix V V R := (Nat.castRingHom R).mapMatrix change evalMat (f M₀) (f M₁) w = f (evalMat M₀ M₁ w) unfold evalMat rw [map_list_prod] congr 1 induction w with | nil => rfl | cons b w ih => simp only [List.map_cons, List.cons.injEq] exact ⟨by cases b <;> rfl, ih⟩ theorem isBinaryMatrix_map_natCast {V R : Type*} [Semiring R] {M : Matrix V V ℕ} (hM : IsBinaryMatrix M) : IsBinaryMatrix (M.map (Nat.cast : ℕ → R)) := by intro i j rcases hM i j with h | h <;> simp [h] theorem map_natCast_eq_zero_iff {V R : Type*} [Semiring R] [CharZero R] (M : Matrix V V ℕ) : M.map (Nat.cast : ℕ → R) = 0 ↔ M = 0 := by constructor · intro h ext i j have hij := congr_fun (congr_fun h i) j simp only [Matrix.map_apply, Matrix.zero_apply, Nat.cast_eq_zero] at hij exact hij · intro h; subst h; ext i j; simp /-- Padding an `n₀ × n₀` matrix with zeros to size `n ≥ n₀`. -/ def padMatrix {n₀ n : ℕ} (_h : n₀ ≤ n) (M : Matrix (Fin n₀) (Fin n₀) ℕ) : Matrix (Fin n) (Fin n) ℕ := fun i j => if hi : i.val < n₀ then if hj : j.val < n₀ then M ⟨i.val, hi⟩ ⟨j.val, hj⟩ else 0 else 0 theorem isBinaryMatrix_padMatrix {n₀ n : ℕ} (h : n₀ ≤ n) {M : Matrix (Fin n₀) (Fin n₀) ℕ} (hM : IsBinaryMatrix M) : IsBinaryMatrix (padMatrix h M) := by intro i j unfold padMatrix split_ifs with hi hj · exact hM ⟨i.val, hi⟩ ⟨j.val, hj⟩ · left; rfl · left; rfl theorem padMatrix_mul {n₀ n : ℕ} (h : n₀ ≤ n) (A B : Matrix (Fin n₀) (Fin n₀) ℕ) : padMatrix h A * padMatrix h B = padMatrix h (A * B) := by ext i j simp only [Matrix.mul_apply, padMatrix] by_cases hi : i.val < n₀ <;> by_cases hj : j.val < n₀ · simp only [hi, hj, ↓reduceDIte] have hfilter : (Finset.univ.filter (fun s : Fin n => s.val < n₀)) = Finset.univ.map ⟨Fin.castLE h, Fin.castLE_injective h⟩ := by ext s simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_map, Function.Embedding.coeFn_mk] constructor · intro hs exact ⟨⟨s.val, hs⟩, Fin.ext rfl⟩ · rintro ⟨a, rfl⟩ exact a.isLt rw [← Finset.sum_filter_add_sum_filter_not (s := (Finset.univ : Finset (Fin n))) (p := fun s => s.val < n₀)] have hzero : (∑ s ∈ Finset.univ.filter (fun s : Fin n => ¬ s.val < n₀), (if hs : s.val < n₀ then A ⟨i.val, hi⟩ ⟨s.val, hs⟩ else 0) * (if hs : s.val < n₀ then B ⟨s.val, hs⟩ ⟨j.val, hj⟩ else 0)) = 0 := by refine Finset.sum_eq_zero fun s hs => ?_ have hnot : ¬ s.val < n₀ := (Finset.mem_filter.1 hs).2 simp [hnot] rw [hzero, add_zero, hfilter, Finset.sum_map] refine Finset.sum_congr rfl fun s _ => ?_ simp [s.isLt] · simp [hi, hj] · simp [hi] · simp [hi] theorem padMatrix_evalMat {n₀ n : ℕ} (h : n₀ ≤ n) (M₀ M₁ : Matrix (Fin n₀) (Fin n₀) ℕ) {w : List Bool} (hw : w ≠ []) : evalMat (padMatrix h M₀) (padMatrix h M₁) w = padMatrix h (evalMat M₀ M₁ w) := by match w with | [] => contradiction | b :: w => clear hw induction w using List.reverseRecOn with | nil => cases b <;> simp [evalMat] | append_singleton w c ih => rw [← List.cons_append, evalMat_snoc, ih, evalMat_snoc] cases c <;> exact padMatrix_mul h _ _ theorem padMatrix_eq_zero_iff {n₀ n : ℕ} (h : n₀ ≤ n) (M : Matrix (Fin n₀) (Fin n₀) ℕ) : padMatrix h M = 0 ↔ M = 0 := by constructor · intro h0 ext i j have hij := congr_fun (congr_fun h0 (Fin.castLE h i)) (Fin.castLE h j) simpa [padMatrix, i.isLt, j.isLt] using hij · intro h0; subst h0 ext i j simp [padMatrix] end MatrixNFA /-! ## Section 2: Pairwise Coprime Moduli and Chinese Remainder Lemma -/ section CoprimeCRT theorem prod_ge_two_of_ge_two {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) : 2 ≤ ms.prod := by induction ms with | nil => contradiction | cons m ms ih => rcases eq_or_ne ms [] with rfl | hms · simpa using hge m (by simp) · have hm := hge m (by simp) have htail := ih hms (fun x hx => hge x (by simp [hx])) rw [List.prod_cons] nlinarith theorem list_prod_dvd_of_pairwise_coprime {ms : List ℕ} {x : ℕ} (hcop : ms.Pairwise Nat.Coprime) (hdvd : ∀ m ∈ ms, m ∣ x) : ms.prod ∣ x := by induction ms with | nil => simp | cons m ms ih => rw [List.pairwise_cons] at hcop rw [List.prod_cons] have hm : m ∣ x := hdvd m (by simp) have hms : ms.prod ∣ x := ih hcop.2 (fun y hy => hdvd y (by simp [hy])) have hcop_prod : Nat.Coprime m ms.prod := Nat.coprime_list_prod_right_iff.mpr hcop.1 rw [← hcop_prod.lcm_eq_mul] exact Nat.lcm_dvd hm hms theorem crt_all_max_mod_iff {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) {pos : ℕ} (hpos : pos < ms.prod) : (∀ r : Fin ms.length, pos % ms[r] = ms[r] - 1) ↔ pos = ms.prod - 1 := by constructor · intro h have hdvd : ∀ m ∈ ms, m ∣ pos + 1 := by intro m hm rw [List.mem_iff_getElem] at hm obtain ⟨r, hr, rfl⟩ := hm have hr' : pos % ms[r] = ms[r] - 1 := h ⟨r, hr⟩ have hm2 : 2 ≤ ms[r] := hge ms[r] (List.getElem_mem hr) have hmod : (pos + 1) % ms[r] = 0 := by rw [Nat.add_mod, hr'] have h1 : 1 % ms[r] = 1 := Nat.mod_eq_of_lt (by omega) rw [h1] have hsum : ms[r] - 1 + 1 = ms[r] := by omega rw [hsum, Nat.mod_self] exact Nat.dvd_of_mod_eq_zero hmod have hprod_dvd : ms.prod ∣ pos + 1 := list_prod_dvd_of_pairwise_coprime hcop hdvd have hle : ms.prod ≤ pos + 1 := Nat.le_of_dvd (Nat.succ_pos pos) hprod_dvd omega · intro h r have hk_pos : 0 < ms.prod := lt_of_le_of_lt (Nat.zero_le _) hpos subst h have hr_mem : ms[r.val] ∈ ms := List.getElem_mem r.isLt have hm2 : 2 ≤ ms[r.val] := hge _ hr_mem obtain ⟨q, hq⟩ := List.dvd_prod hr_mem have hq_pos : 0 < q := by by_contra hq0 have hq' : q = 0 := by omega have h0 : ms.prod = 0 := by rw [hq, hq', mul_zero] omega have hprod_sub : ms.prod - 1 = ms[r.val] * (q - 1) + (ms[r.val] - 1) := by rw [hq] cases q with | zero => omega | succ q' => simp [Nat.mul_succ]; omega simp only [Fin.getElem_fin] rw [hprod_sub, Nat.mul_add_mod] exact Nat.mod_eq_of_lt (by omega) end CoprimeCRT /-! ## Section 3: The Coprime-Clock 2-Letter NFA -/ section CoprimeAutomaton /-- States of the coprime-clock 2-letter NFA for moduli `ms`. -/ inductive Node (ms : List ℕ) : Type | cMid (j : Fin (ms.prod - 1)) | cZero (l : Fin 4) | clock (r : Fin ms.length) (l : Fin 3) (a : Fin ms[r]) | f0 (l : Fin 3) | f1 (l : Fin 3) | g (l : Fin 3) | trap deriving DecidableEq private def nodeEquiv (ms : List ℕ) : Node ms ≃ (Fin (ms.prod - 1) ⊕ Fin 4) ⊕ ((Σ r : Fin ms.length, Fin 3 × Fin ms[r]) ⊕ (Fin 3 ⊕ Fin 3 ⊕ Fin 3 ⊕ Unit)) where toFun | .cMid j => Sum.inl (Sum.inl j) | .cZero l => Sum.inl (Sum.inr l) | .clock r l a => Sum.inr (Sum.inl ⟨r, l, a⟩) | .f0 l => Sum.inr (Sum.inr (Sum.inl l)) | .f1 l => Sum.inr (Sum.inr (Sum.inr (Sum.inl l))) | .g l => Sum.inr (Sum.inr (Sum.inr (Sum.inr (Sum.inl l)))) | .trap => Sum.inr (Sum.inr (Sum.inr (Sum.inr (Sum.inr ())))) invFun | Sum.inl (Sum.inl j) => .cMid j | Sum.inl (Sum.inr l) => .cZero l | Sum.inr (Sum.inl ⟨r, l, a⟩) => .clock r l a | Sum.inr (Sum.inr (Sum.inl l)) => .f0 l | Sum.inr (Sum.inr (Sum.inr (Sum.inl l))) => .f1 l | Sum.inr (Sum.inr (Sum.inr (Sum.inr (Sum.inl l)))) => .g l | Sum.inr (Sum.inr (Sum.inr (Sum.inr (Sum.inr ())))) => .trap left_inv x := by cases x <;> rfl right_inv x := by rcases x with (x | x) | (⟨r, l, a⟩ | (x | x | x | u)) <;> rfl instance instFintypeNode (ms : List ℕ) : Fintype (Node ms) := Fintype.ofEquiv _ (nodeEquiv ms).symm private lemma sum_fin_getElem (ms : List ℕ) : (∑ r : Fin ms.length, ms[r]) = ms.sum := by induction ms with | nil => simp | cons m ms ih => simp only [Fin.sum_univ_succ, List.length_cons, List.sum_cons, Fin.getElem_fin, Fin.val_zero, List.getElem_cons_zero, Fin.val_succ, List.getElem_cons_succ] rw [← ih] rfl theorem card_node {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) : Fintype.card (Node ms) = ms.prod + 3 * ms.sum + 13 := by rw [Fintype.card_congr (nodeEquiv ms)] have hk : 2 ≤ ms.prod := prod_ge_two_of_ge_two hne hge have hsum : (∑ r : Fin ms.length, 3 * ms[r]) = 3 * ms.sum := by rw [← Finset.mul_sum, sum_fin_getElem] simp only [Fintype.card_sum, Fintype.card_fin, Fintype.card_sigma, Fintype.card_prod, Fintype.card_unit] rw [hsum] omega /-- The canonical initial counter subset `START` (all `k` bits set to `1`, clock at `0`, `f0 0`). -/ def startSet (ms : List ℕ) (hge : ∀ m ∈ ms, 2 ≤ m) : Finset (Node ms) := {Node.cZero 0, Node.f0 0} ∪ Finset.univ.image Node.cMid ∪ Finset.univ.image (fun r : Fin ms.length => Node.clock r 0 ⟨0, lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt))⟩) @[simp] theorem mem_startSet_iff {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (x : Node ms) : x ∈ startSet ms hge ↔ match x with | .cMid _ => True | .cZero l => l = 0 | .clock _ l a => l = 0 ∧ a.val = 0 | .f0 l => l = 0 | .f1 _ => False | .g _ => False | .trap => False := by unfold startSet simp only [Finset.mem_union, Finset.mem_insert, Finset.mem_singleton, Finset.mem_image, Finset.mem_univ, true_and] cases x with | cMid j => simp | cZero l => simp only [Node.cZero.injEq, reduceCtorEq, or_false, exists_false] | clock r l a => simp only [reduceCtorEq, false_or, Node.clock.injEq, exists_false, or_false] constructor · rintro ⟨r', hr, hl, ha⟩ subst hr refine ⟨hl.symm, ?_⟩ have hv : (0 : ℕ) = a.val := congrArg Fin.val (eq_of_heq ha) exact hv.symm · rintro ⟨rfl, ha⟩ exact ⟨r, rfl, rfl, heq_of_eq (Fin.ext ha.symm)⟩ | f0 l => simp only [reduceCtorEq, false_or, Node.f0.injEq, or_false, exists_false] | f1 l => simp | g l => simp | trap => simp /-- Helper: MSB index `k - 2 : Fin (ms.prod - 1)` when `2 ≤ ms.prod`. -/ private def msbIdx (ms : List ℕ) (hk : 2 ≤ ms.prod) : Fin (ms.prod - 1) := ⟨ms.prod - 2, by omega⟩ /-- Transition `δS` (letter `false` = Shift / Execute). -/ def δS (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) : Node ms → Finset (Node ms) | .cMid j => if _hj : j.val = 0 then {Node.cZero 0} else {Node.cMid ⟨j.val - 1, by omega⟩} | .cZero 0 => startSet ms hge | .cZero 1 => {Node.cMid (msbIdx ms (prod_ge_two_of_ge_two hne hge))} | .cZero 2 => ∅ | .cZero 3 => {Node.cMid (msbIdx ms (prod_ge_two_of_ge_two hne hge))} | .clock r _ a => let hm : 0 < ms[r] := lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt)) {Node.clock r 0 ⟨(a.val + 1) % ms[r], Nat.mod_lt _ hm⟩} | .f0 0 => {Node.f0 0, Node.cMid (msbIdx ms (prod_ge_two_of_ge_two hne hge))} | .f0 1 => startSet ms hge | .f0 2 => {Node.f1 0} | .f1 0 => startSet ms hge | .f1 1 => {Node.f1 0} | .f1 2 => startSet ms hge | .g 0 => ∅ | .g 1 => ∅ | .g 2 => {Node.f0 0} ∪ Finset.univ.image (fun r : Fin ms.length => Node.clock r 0 ⟨0, lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt))⟩) | .trap => startSet ms hge /-- Transition `δH` (letter `true` = Hold / Prefix). -/ def δH (ms : List ℕ) (_hge : ∀ m ∈ ms, 2 ≤ m) : Node ms → Finset (Node ms) | .cMid j => {Node.cMid j, Node.g 0} | .cZero 0 => {Node.cZero 1, Node.g 0} | .cZero 1 => {Node.cZero 2, Node.g 0} | .cZero 2 => {Node.cZero 3, Node.g 0} | .cZero 3 => {Node.trap} | .clock r 0 a => {Node.clock r 1 a} | .clock r 1 a => {Node.clock r 2 a} | .clock r 2 a => if a.val = ms[r] - 1 then ∅ else {Node.trap} | .f0 0 => {Node.f0 1} | .f0 1 => {Node.f0 2} | .f0 2 => {Node.trap} | .f1 0 => {Node.f1 1} | .f1 1 => {Node.f1 2} | .f1 2 => ∅ | .g 0 => {Node.g 1} | .g 1 => {Node.g 2} | .g 2 => {Node.trap} | .trap => {Node.trap} /-! ### Fast target-indexed preimage lemmas for `δH` and `δS` -/ lemma mem_δH_cMid {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (j : Fin (ms.prod - 1)) : Node.cMid j ∈ δH ms hge y ↔ y = Node.cMid j := by cases y with | cMid j' => simp [δH, eq_comm] | cZero l' => fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l' <;> simp [δH]; split_ifs <;> simp | f0 l' => fin_cases l' <;> simp [δH] | f1 l' => fin_cases l' <;> simp [δH] | g l' => fin_cases l' <;> simp [δH] | trap => simp [δH] lemma mem_δH_cZero {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 4) : Node.cZero l ∈ δH ms hge y ↔ (l = 1 ∧ y = .cZero 0) ∨ (l = 2 ∧ y = .cZero 1) ∨ (l = 3 ∧ y = .cZero 2) := by cases y with | cMid _ => fin_cases l <;> simp [δH] | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l <;> fin_cases l' <;> simp [δH] <;> (try split_ifs <;> simp) | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | g l' => fin_cases l <;> fin_cases l' <;> simp [δH] | trap => fin_cases l <;> simp [δH] lemma mem_δH_clock {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (r : Fin ms.length) (l : Fin 3) (a : Fin ms[r]) : Node.clock r l a ∈ δH ms hge y ↔ (l = 1 ∧ y = .clock r 0 a) ∨ (l = 2 ∧ y = .clock r 1 a) := by cases y with | cMid _ => fin_cases l <;> simp [δH] | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l <;> fin_cases l' <;> simp [δH] all_goals try (split_ifs <;> simp) all_goals ( constructor · rintro ⟨hr, ha⟩; subst hr; cases eq_of_heq ha; exact ⟨rfl, HEq.rfl⟩ · rintro ⟨hr, ha⟩; subst hr; cases eq_of_heq ha; exact ⟨rfl, HEq.rfl⟩) | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | g l' => fin_cases l <;> fin_cases l' <;> simp [δH] | trap => fin_cases l <;> simp [δH] lemma mem_δH_f0 {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 3) : Node.f0 l ∈ δH ms hge y ↔ (l = 1 ∧ y = .f0 0) ∨ (l = 2 ∧ y = .f0 1) := by cases y with | cMid _ => fin_cases l <;> simp [δH] | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l <;> fin_cases l' <;> simp [δH] <;> (try split_ifs <;> simp) | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | g l' => fin_cases l <;> fin_cases l' <;> simp [δH] | trap => fin_cases l <;> simp [δH] lemma mem_δH_f1 {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 3) : Node.f1 l ∈ δH ms hge y ↔ (l = 1 ∧ y = .f1 0) ∨ (l = 2 ∧ y = .f1 1) := by cases y with | cMid _ => fin_cases l <;> simp [δH] | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l <;> fin_cases l' <;> simp [δH] <;> (try split_ifs <;> simp) | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | g l' => fin_cases l <;> fin_cases l' <;> simp [δH] | trap => fin_cases l <;> simp [δH] lemma mem_δH_g {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 3) : Node.g l ∈ δH ms hge y ↔ (l = 0 ∧ ((∃ j, y = .cMid j) ∨ y = .cZero 0 ∨ y = .cZero 1 ∨ y = .cZero 2)) ∨ (l = 1 ∧ y = .g 0) ∨ (l = 2 ∧ y = .g 1) := by cases y with | cMid j' => fin_cases l <;> simp [δH] | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l <;> fin_cases l' <;> simp [δH] <;> (try split_ifs <;> simp) | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δH] | g l' => fin_cases l <;> fin_cases l' <;> simp [δH] | trap => fin_cases l <;> simp [δH] lemma mem_δH_trap {ms : List ℕ} (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) : Node.trap ∈ δH ms hge y ↔ y = .cZero 3 ∨ (∃ r a, a.val ≠ ms[r] - 1 ∧ y = .clock r 2 a) ∨ y = .f0 2 ∨ y = .g 2 ∨ y = .trap := by cases y with | cMid _ => simp [δH] | cZero l' => fin_cases l' <;> simp [δH] | clock r' l' a' => fin_cases l' <;> simp [δH] split_ifs with h · simp only [Finset.notMem_empty, false_iff, not_exists, not_and] intro r'' a'' hne hr ha subst hr cases eq_of_heq ha exact hne h · simp only [Finset.mem_singleton, true_iff] exact ⟨r', a', h, rfl, HEq.rfl⟩ | f0 l' => fin_cases l' <;> simp [δH] | f1 l' => fin_cases l' <;> simp [δH] | g l' => fin_cases l' <;> simp [δH] | trap => simp [δH] /-- Helper predicate: `y` maps to `startSet` under `δS`. -/ def isStartPreS {ms : List ℕ} (y : Node ms) : Prop := y = .cZero 0 ∨ y = .f0 1 ∨ y = .f1 0 ∨ y = .f1 2 ∨ y = .trap theorem startSet_subset_δS_of_isStartPreS {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) {y : Node ms} (hy : isStartPreS y) : startSet ms hge ⊆ δS ms hne hge y := by rcases hy with rfl | rfl | rfl | rfl | rfl <;> simp [δS] lemma mem_δS_cMid {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (j : Fin (ms.prod - 1)) : Node.cMid j ∈ δS ms hne hge y ↔ isStartPreS y ∨ (∃ hj : j.val + 1 < ms.prod - 1, y = .cMid ⟨j.val + 1, hj⟩) ∨ (j.val = ms.prod - 2 ∧ (y = .cZero 1 ∨ y = .cZero 3 ∨ y = .f0 0)) := by have hk := prod_ge_two_of_ge_two hne hge cases y with | cMid j' => simp only [δS, isStartPreS, reduceCtorEq, false_or, or_self] split_ifs with hj' · simp only [Finset.mem_singleton, reduceCtorEq, false_iff, not_or, not_exists] refine ⟨?_, ?_⟩ · intro hj h; cases h; simp at hj' · rintro ⟨_, h⟩; simp at h · simp only [Finset.mem_singleton, Node.cMid.injEq, and_false, or_false] constructor · intro h have hv : j.val = j'.val - 1 := congrArg Fin.val h refine ⟨by omega, Fin.ext ?_⟩ dsimp; omega · rintro ⟨hj, h⟩ have hv : j'.val = j.val + 1 := congrArg Fin.val h exact Fin.ext (by change j.val = j'.val - 1; omega) | cZero l' => fin_cases l' <;> simp [δS, isStartPreS, msbIdx, Fin.ext_iff, eq_comm] | clock r' l' a' => simp [δS, isStartPreS] | f0 l' => fin_cases l' <;> simp [δS, isStartPreS, msbIdx, Fin.ext_iff, eq_comm] | f1 l' => fin_cases l' <;> simp [δS, isStartPreS] | g l' => fin_cases l' <;> simp [δS, isStartPreS] | trap => simp [δS, isStartPreS] lemma mem_δS_cZero {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 4) : Node.cZero l ∈ δS ms hne hge y ↔ (l = 0 ∧ (isStartPreS y ∨ y = .cMid ⟨0, by have := prod_ge_two_of_ge_two hne hge; omega⟩)) := by cases y with | cMid j' => simp only [δS, isStartPreS, reduceCtorEq, false_or, or_self] split_ifs with hj' · simp only [Finset.mem_singleton, Node.cZero.injEq, Node.cMid.injEq] constructor · intro h; subst h; exact ⟨rfl, Fin.ext hj'⟩ · rintro ⟨rfl, _⟩; rfl · simp only [Finset.mem_singleton, reduceCtorEq, false_iff, not_and] intro _ h; cases h; exact hj' rfl | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | clock r' l' a' => fin_cases l <;> simp [δS, isStartPreS] | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | g l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | trap => fin_cases l <;> simp [δS, isStartPreS] lemma mem_δS_clock {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (r : Fin ms.length) (l : Fin 3) (a : Fin ms[r]) : Node.clock r l a ∈ δS ms hne hge y ↔ l = 0 ∧ ((a.val = 0 ∧ (isStartPreS y ∨ y = .g 2)) ∨ (∃ l' a', y = .clock r l' a' ∧ a.val = (a'.val + 1) % ms[r])) := by by_cases hl : l = 0 · subst hl cases y with | cMid j' => simp [δS, isStartPreS]; split_ifs <;> simp | cZero l' => fin_cases l' <;> simp [δS, isStartPreS] | clock r' l' a' => simp only [δS, isStartPreS, reduceCtorEq, or_self, Finset.mem_singleton, true_and] constructor · intro h rw [Node.clock.injEq] at h rcases h with ⟨rfl, _, ha⟩ have hv : a.val = (a'.val + 1) % ms[r] := congrArg Fin.val (eq_of_heq ha) exact Or.inr ⟨l', a', rfl, hv⟩ · rintro (⟨_, hbot⟩ | ⟨l'', a'', h, ha⟩) · exact False.elim hbot · rw [Node.clock.injEq] at h rcases h with ⟨rfl, rfl, ha'⟩ have hv : a'.val = a''.val := congrArg Fin.val (eq_of_heq ha') rw [Node.clock.injEq] exact ⟨rfl, rfl, heq_of_eq (Fin.ext (by simp [ha, hv]))⟩ | f0 l' => fin_cases l' <;> simp [δS, isStartPreS] | f1 l' => fin_cases l' <;> simp [δS, isStartPreS] | g l' => fin_cases l' · simp [δS, isStartPreS] · simp [δS, isStartPreS] · simp only [δS, isStartPreS, Finset.mem_union, Finset.mem_singleton, Finset.mem_image, Finset.mem_univ, true_and, reduceCtorEq, false_or, Node.clock.injEq, false_and, exists_false, or_false] constructor · rintro ⟨r', rfl, ha⟩ exact ⟨(congrArg Fin.val (eq_of_heq ha)).symm, rfl⟩ · rintro ⟨ha, _⟩ exact ⟨r, rfl, heq_of_eq (Fin.ext ha.symm)⟩ | trap => simp [δS, isStartPreS] · simp only [hl, false_and, iff_false] cases y with | cMid j' => simp [δS]; split_ifs <;> simp | cZero l' => fin_cases l' <;> simp [δS, hl] | clock r' l' a' => simp [δS, hl] | f0 l' => fin_cases l' <;> simp [δS, hl] | f1 l' => fin_cases l' <;> simp [δS, hl] | g l' => fin_cases l' <;> simp [δS] exact fun h0 _ => hl h0.symm | trap => simp [δS, hl] lemma mem_δS_f0 {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 3) : Node.f0 l ∈ δS ms hne hge y ↔ l = 0 ∧ (isStartPreS y ∨ y = .f0 0 ∨ y = .g 2) := by cases y with | cMid j' => fin_cases l <;> simp [δS, isStartPreS] <;> (try split_ifs <;> simp) | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | clock r' l' a' => fin_cases l <;> simp [δS, isStartPreS] | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | g l' => fin_cases l <;> fin_cases l' <;> simp [δS, isStartPreS] | trap => fin_cases l <;> simp [δS, isStartPreS] lemma mem_δS_f1 {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 3) : Node.f1 l ∈ δS ms hne hge y ↔ l = 0 ∧ (y = .f0 2 ∨ y = .f1 1) := by cases y with | cMid j' => fin_cases l <;> simp [δS] <;> (try split_ifs <;> simp) | cZero l' => fin_cases l <;> fin_cases l' <;> simp [δS] | clock r' l' a' => fin_cases l <;> simp [δS] | f0 l' => fin_cases l <;> fin_cases l' <;> simp [δS] | f1 l' => fin_cases l <;> fin_cases l' <;> simp [δS] | g l' => fin_cases l <;> fin_cases l' <;> simp [δS] | trap => fin_cases l <;> simp [δS] lemma mem_δS_g {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) (l : Fin 3) : Node.g l ∉ δS ms hne hge y := by cases y with | cMid j' => simp [δS]; split_ifs <;> simp | cZero l' => fin_cases l' <;> simp [δS] | clock r' l' a' => simp [δS] | f0 l' => fin_cases l' <;> simp [δS] | f1 l' => fin_cases l' <;> simp [δS] | g l' => fin_cases l' <;> simp [δS] | trap => simp [δS] lemma mem_δS_trap {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (y : Node ms) : Node.trap ∉ δS ms hne hge y := by cases y with | cMid j' => simp [δS]; split_ifs <;> simp | cZero l' => fin_cases l' <;> simp [δS] | clock r' l' a' => simp [δS] | f0 l' => fin_cases l' <;> simp [δS] | f1 l' => fin_cases l' <;> simp [δS] | g l' => fin_cases l' <;> simp [δS] | trap => simp [δS] /-- Canonical configuration set `cfgSet ms A pos mode phase`. -/ def inCfg (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (pos : ℕ) (mode : Bool) (phase : Fin 3) (x : Node ms) : Prop := let hk : 0 < ms.prod := lt_of_lt_of_le (by norm_num) (prod_ge_two_of_ge_two hne hge) match x with | .cMid j => ⟨(pos + j.val + 1) % ms.prod, Nat.mod_lt _ hk⟩ ∈ A | .cZero l => l.val = phase.val ∧ ⟨pos % ms.prod, Nat.mod_lt _ hk⟩ ∈ A | .clock r l a => l = phase ∧ a.val = pos % ms[r] | .f0 l => mode = false ∧ l = phase | .f1 l => mode = true ∧ l = phase | .g l => A.Nonempty ∧ ((l.val = 0 ∧ 1 ≤ phase.val) ∨ (l.val = 1 ∧ phase.val = 2)) | .trap => False instance instDecidableInCfg (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (pos : ℕ) (mode : Bool) (phase : Fin 3) : DecidablePred (inCfg ms hne hge A pos mode phase) := by intro x cases x <;> unfold inCfg <;> infer_instance def cfgSet (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (pos : ℕ) (mode : Bool) (phase : Fin 3) : Finset (Node ms) := Finset.univ.filter (inCfg ms hne hge A pos mode phase) @[simp] theorem mem_cfgSet {ms : List ℕ} {hne : ms ≠ []} {hge : ∀ m ∈ ms, 2 ≤ m} {A : Finset (Fin ms.prod)} {pos : ℕ} {mode : Bool} {phase : Fin 3} {x : Node ms} : x ∈ cfgSet ms hne hge A pos mode phase ↔ inCfg ms hne hge A pos mode phase x := by simp [cfgSet] theorem startSet_eq_cfgSet (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) : startSet ms hge = cfgSet ms hne hge Finset.univ 0 false 0 := by ext x rw [mem_startSet_iff, mem_cfgSet] cases x with | cMid j => simp [inCfg] | cZero l => simp only [inCfg, Fin.coe_ofNat_eq_mod, Nat.zero_mod, Finset.mem_univ, and_true] omega | clock r l a => simp [inCfg] | f0 l => simp [inCfg] | f1 l => simp [inCfg] | g l => simp [inCfg] | trap => simp [inCfg] /-- Phase-3 set right after `HHH` at `pos = ms.prod - 1` when `A.Nonempty`. -/ def inPhase3 (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (x : Node ms) : Prop := let hk : 2 ≤ ms.prod := prod_ge_two_of_ge_two hne hge match x with | .cMid j => ⟨j.val, by omega⟩ ∈ A | .cZero l => l.val = 3 ∧ ⟨ms.prod - 1, by omega⟩ ∈ A | .clock _ _ _ => False | .f0 _ => False | .f1 _ => False | .g _ => True | .trap => False instance instDecidableInPhase3 (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : DecidablePred (inPhase3 ms hne hge A) := by intro x; cases x <;> unfold inPhase3 <;> infer_instance def phase3Set (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : Finset (Node ms) := Finset.univ.filter (inPhase3 ms hne hge A) @[simp] theorem mem_phase3Set {ms : List ℕ} {hne : ms ≠ []} {hge : ∀ m ∈ ms, 2 ≤ m} {A : Finset (Fin ms.prod)} {x : Node ms} : x ∈ phase3Set ms hne hge A ↔ inPhase3 ms hne hge A x := by simp [phase3Set] /-! ### Exact `FULL` collapse lemma: `FULL * H^4 * S = START` -/ theorem evalStep_univ_HHHHS (ms : List ℕ) (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) : evalStep (δS ms hne hge) (δH ms hge) Finset.univ [true, true, true, true, false] = startSet ms hge := by let S1 := step (δH ms hge) Finset.univ have h1 : ∀ x : Node ms, x ∈ S1 ↔ match x with | .cZero l => l.val ≠ 0 | .clock _ l _ => l.val ≠ 0 | .f0 l => l.val ≠ 0 | .f1 l => l.val ≠ 0 | _ => True := by intro x; simp only [S1, mem_step, Finset.mem_univ, true_and] cases x with | cMid j => simp only [mem_δH_cMid, exists_eq] | cZero l => simp only [mem_δH_cZero]; fin_cases l <;> simp | clock r l a => simp only [mem_δH_clock]; fin_cases l <;> simp | f0 l => simp only [mem_δH_f0]; fin_cases l <;> simp | f1 l => simp only [mem_δH_f1]; fin_cases l <;> simp | g l => simp only [mem_δH_g]; fin_cases l <;> simp let m0 : Node ms := .cMid ⟨0, by have := prod_ge_two_of_ge_two hne hge; omega⟩ exact ⟨m0, Or.inl ⟨_, rfl⟩⟩ | trap => simp only [mem_δH_trap]; exact ⟨fun _ => trivial, fun _ => ⟨.trap, by simp⟩⟩ let S2 := step (δH ms hge) S1 have h2 : ∀ x : Node ms, x ∈ S2 ↔ match x with | .cZero l => l.val = 2 ∨ l.val = 3 | .clock _ l _ => l.val = 2 | .f0 l => l.val = 2 | .f1 l => l.val = 2 | _ => True := by intro x; simp only [S2, mem_step] cases x with | cMid j => simp only [mem_δH_cMid]; exact ⟨fun _ => trivial, fun _ => ⟨.cMid j, (h1 _).2 trivial, rfl⟩⟩ | cZero l => simp only [mem_δH_cZero]; fin_cases l <;> simp [h1] | clock r l a => simp only [mem_δH_clock]; fin_cases l <;> simp [h1] | f0 l => simp only [mem_δH_f0]; fin_cases l <;> simp [h1] | f1 l => simp only [mem_δH_f1]; fin_cases l <;> simp [h1] | g l => simp only [mem_δH_g]; fin_cases l <;> simp [h1] have hk2 := prod_ge_two_of_ge_two hne hge let j0 : Fin (ms.prod - 1) := ⟨0, by omega⟩ exact ⟨.cMid j0, trivial, Or.inl ⟨j0, rfl⟩⟩ | trap => simp only [mem_δH_trap]; exact ⟨fun _ => trivial, fun _ => ⟨.trap, (h1 .trap).2 trivial, by simp⟩⟩ let S3 := step (δH ms hge) S2 have h3 : ∀ x : Node ms, x ∈ S3 ↔ match x with | .cZero l => l.val = 3 | .clock _ _ _ => False | .f0 _ => False | .f1 _ => False | _ => True := by intro x; simp only [S3, mem_step] cases x with | cMid j => simp only [mem_δH_cMid]; exact ⟨fun _ => trivial, fun _ => ⟨.cMid j, (h2 _).2 trivial, rfl⟩⟩ | cZero l => simp only [mem_δH_cZero]; fin_cases l <;> simp [h2] | clock r l a => simp only [mem_δH_clock]; fin_cases l <;> simp [h2] | f0 l => simp only [mem_δH_f0]; fin_cases l <;> simp [h2] | f1 l => simp only [mem_δH_f1]; fin_cases l <;> simp [h2] | g l => simp only [mem_δH_g]; fin_cases l <;> simp [h2] have hk2 := prod_ge_two_of_ge_two hne hge let j0 : Fin (ms.prod - 1) := ⟨0, by omega⟩ exact ⟨.cMid j0, trivial, Or.inl ⟨j0, rfl⟩⟩ | trap => simp only [mem_δH_trap]; exact ⟨fun _ => trivial, fun _ => ⟨.trap, (h2 .trap).2 trivial, by simp⟩⟩ let S4 := step (δH ms hge) S3 have h4 : ∀ x : Node ms, x ∈ S4 ↔ match x with | .cZero _ => False | .clock _ _ _ => False | .f0 _ => False | .f1 _ => False | _ => True := by intro x; simp only [S4, mem_step] cases x with | cMid j => simp only [mem_δH_cMid]; exact ⟨fun _ => trivial, fun _ => ⟨.cMid j, (h3 _).2 trivial, rfl⟩⟩ | cZero l => simp only [mem_δH_cZero]; fin_cases l <;> simp [h3] | clock r l a => simp only [mem_δH_clock]; fin_cases l <;> simp [h3] | f0 l => simp only [mem_δH_f0]; fin_cases l <;> simp [h3] | f1 l => simp only [mem_δH_f1]; fin_cases l <;> simp [h3] | g l => simp only [mem_δH_g]; fin_cases l <;> simp [h3] have hk2 := prod_ge_two_of_ge_two hne hge let j0 : Fin (ms.prod - 1) := ⟨0, by omega⟩ exact ⟨.cMid j0, trivial, Or.inl ⟨j0, rfl⟩⟩ | trap => simp only [mem_δH_trap]; exact ⟨fun _ => trivial, fun _ => ⟨.trap, (h3 .trap).2 trivial, by simp⟩⟩ -- Step 5: δS on S4 gives `startSet ms hge` ext x change x ∈ step (δS ms hne hge) S4 ↔ x ∈ startSet ms hge rw [mem_step, mem_startSet_iff] cases x with | cMid j => simp only [mem_δS_cMid, iff_true] exact ⟨.trap, (h4 .trap).2 trivial, Or.inl (by simp [isStartPreS])⟩ | cZero l => simp only [mem_δS_cZero] fin_cases l · simp only [Fin.zero_eta, true_and, iff_true] exact ⟨.trap, (h4 .trap).2 trivial, Or.inl (by simp [isStartPreS])⟩ all_goals simp | clock r l a => simp only [mem_δS_clock] fin_cases l · simp only [Fin.zero_eta, true_and] constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with ⟨ha, _⟩ | ⟨l', a', h, _⟩ · simp [ha] · rw [h] at hy; exact False.elim ((h4 (.clock r l' a')).1 hy) · intro ha exact ⟨.trap, (h4 .trap).2 trivial, Or.inl ⟨ha, Or.inl (by simp [isStartPreS])⟩⟩ all_goals simp | f0 l => simp only [mem_δS_f0] fin_cases l · simp only [Fin.zero_eta, true_and, iff_true] exact ⟨.trap, (h4 .trap).2 trivial, Or.inl (by simp [isStartPreS])⟩ all_goals simp | f1 l => simp only [mem_δS_f1] fin_cases l · simp only [Fin.zero_eta, true_and, iff_false, not_exists, not_and] rintro y hy (rfl | rfl) · exact (h4 (.f0 2)).1 hy · exact (h4 (.f1 1)).1 hy all_goals simp | g l => simp only [mem_δS_g, and_false, exists_false] | trap => simp only [mem_δS_trap, and_false, exists_false] /-! ### Exact `step` transition lemmas on `cfgSet` and `phase3Set` -/ private lemma exists_bit_at_of_nonempty {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) {A : Finset (Fin ms.prod)} (hA : A.Nonempty) (pos : ℕ) : ⟨pos % ms.prod, Nat.mod_lt _ (lt_of_lt_of_le (by norm_num) (prod_ge_two_of_ge_two hne hge))⟩ ∈ A ∨ ∃ j : Fin (ms.prod - 1), ⟨(pos + j.val + 1) % ms.prod, Nat.mod_lt _ (lt_of_lt_of_le (by norm_num) (prod_ge_two_of_ge_two hne hge))⟩ ∈ A := by have hk : 0 < ms.prod := lt_of_lt_of_le (by norm_num) (prod_ge_two_of_ge_two hne hge) have hk2 : 2 ≤ ms.prod := prod_ge_two_of_ge_two hne hge obtain ⟨a, ha⟩ := hA let p := (a.val + (ms.prod - pos % ms.prod)) % ms.prod have hp_lt : p < ms.prod := Nat.mod_lt _ hk have hp_mod : (pos + p) % ms.prod = a.val := by dsimp [p] rw [Nat.add_mod_mod] have hlt : pos % ms.prod < ms.prod := Nat.mod_lt _ hk have hsum : pos + (a.val + (ms.prod - pos % ms.prod)) = ms.prod * (pos / ms.prod + 1) + a.val := by have hdiv : pos = ms.prod * (pos / ms.prod) + pos % ms.prod := (Nat.div_add_mod pos ms.prod).symm rw [Nat.mul_add, Nat.mul_one] omega rw [hsum, Nat.mul_add_mod] exact Nat.mod_eq_of_lt a.isLt by_cases hp0 : p = 0 · left; convert ha using 1; ext; rw [← hp_mod, hp0, add_zero] · right refine ⟨⟨p - 1, by omega⟩, ?_⟩ convert ha using 1 ext simpa [Nat.sub_add_cancel (Nat.pos_of_ne_zero hp0), add_assoc] using hp_mod theorem step_H_cfgSet_lt2 {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (pos : ℕ) (mode : Bool) {phase : Fin 3} (hph : phase.val < 2) : step (δH ms hge) (cfgSet ms hne hge A pos mode phase) = cfgSet ms hne hge A pos mode ⟨phase.val + 1, by omega⟩ := by ext x rw [mem_step, mem_cfgSet] cases x with | cMid j => simp only [mem_δH_cMid, mem_cfgSet, inCfg] constructor · rintro ⟨y, hy, rfl⟩; exact hy · intro h; exact ⟨.cMid j, h, rfl⟩ | cZero l => simp only [mem_δH_cZero, mem_cfgSet, inCfg] fin_cases l <;> fin_cases phase <;> simp at hph ⊢ | clock r l a => simp only [mem_δH_clock, mem_cfgSet, inCfg] fin_cases l <;> fin_cases phase <;> simp at hph ⊢ | f0 l => simp only [mem_δH_f0, mem_cfgSet, inCfg] fin_cases l <;> fin_cases phase <;> simp at hph ⊢ | f1 l => simp only [mem_δH_f1, mem_cfgSet, inCfg] fin_cases l <;> fin_cases phase <;> simp at hph ⊢ | g l => simp only [mem_δH_g, mem_cfgSet, inCfg] fin_cases l <;> fin_cases phase <;> simp at hph ⊢ · constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with ⟨j, rfl⟩ | rfl | rfl | rfl · exact ⟨_, hy⟩ · exact ⟨_, hy.2⟩ · exact False.elim (by simp at hy) · exact False.elim (by simp at hy) · intro hA rcases exists_bit_at_of_nonempty hne hge hA pos with h0 | ⟨j, hj⟩ · exact ⟨.cZero 0, ⟨rfl, h0⟩, Or.inr (Or.inl rfl)⟩ · exact ⟨.cMid j, hj, Or.inl ⟨j, rfl⟩⟩ · constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with ⟨j, rfl⟩ | rfl | rfl | rfl · exact ⟨_, hy⟩ · exact False.elim (by simp at hy) · exact ⟨_, hy.2⟩ · exact False.elim (by simp at hy) · intro hA rcases exists_bit_at_of_nonempty hne hge hA pos with h0 | ⟨j, hj⟩ · exact ⟨.cZero 1, ⟨rfl, h0⟩, Or.inr (Or.inr (Or.inl rfl))⟩ · exact ⟨.cMid j, hj, Or.inl ⟨j, rfl⟩⟩ | trap => simp only [mem_δH_trap, mem_cfgSet, inCfg, iff_false, not_exists, not_and] intro y hy hcond rcases hcond with rfl | ⟨r, a, _, rfl⟩ | rfl | rfl | rfl · simp at hy; omega · simp at hy; have := congrArg Fin.val hy.1; simp at this; omega · simp at hy; have := congrArg Fin.val hy.2; simp at this; omega · simp at hy · exact hy private lemma mod_prod_mod_getElem {ms : List ℕ} (r : Fin ms.length) (x : ℕ) : (x % ms.prod) % ms[r] = x % ms[r] := by exact Nat.mod_mod_of_dvd x (List.dvd_prod (List.getElem_mem r.isLt)) private lemma mod_add_one_ne_self {k pos : ℕ} (hk : 2 ≤ k) (hpos : pos < k) : (pos + 1) % k ≠ pos := by by_cases h : pos + 1 < k · rw [Nat.mod_eq_of_lt h]; omega · have hEq : pos + 1 = k := by omega rw [hEq, Nat.mod_self]; omega private lemma mod_shift_ne_self {k pos j : ℕ} (hk : 2 ≤ k) (hpos : pos < k) (hj : j + 1 < k - 1) : ((pos + 1) % k + j + 1) % k ≠ pos := by have h1 : ((pos + 1) % k + j + 1) % k = (pos + (j + 2)) % k := by rw [add_assoc, Nat.mod_add_mod]; congr 1; omega rw [h1] by_cases hlt : pos + (j + 2) < k · rw [Nat.mod_eq_of_lt hlt]; omega · have hlt2 : pos + (j + 2) - k < k := by omega have hsub : pos + (j + 2) = k + (pos + (j + 2) - k) := by omega rw [hsub, Nat.add_mod_left, Nat.mod_eq_of_lt hlt2]; omega private lemma mod_shift_msb {k pos : ℕ} (hk : 2 ≤ k) (hpos : pos < k) : ((pos + 1) % k + (k - 2) + 1) % k = pos := by have h1 : ((pos + 1) % k + (k - 2) + 1) % k = (pos + k) % k := by rw [add_assoc, Nat.mod_add_mod]; congr 1; omega rw [h1, Nat.add_mod_right, Nat.mod_eq_of_lt hpos] theorem step_H_cfgSet_phase2_trap_modeFalse {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (pos : ℕ) : Node.trap ∈ step (δH ms hge) (cfgSet ms hne hge A pos false 2) := by rw [mem_step] exact ⟨.f0 2, by simp [inCfg], by simp [δH]⟩ theorem step_H_cfgSet_phase2_trap_posNe {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) (A : Finset (Fin ms.prod)) {pos : ℕ} (hpos : pos < ms.prod) (hne_max : pos ≠ ms.prod - 1) : Node.trap ∈ step (δH ms hge) (cfgSet ms hne hge A pos true 2) := by have hnot : ¬ ∀ r : Fin ms.length, pos % ms[r] = ms[r] - 1 := by intro hall exact hne_max ((crt_all_max_mod_iff hge hcop hpos).1 hall) push Not at hnot obtain ⟨r, hr⟩ := hnot simp only [Fin.getElem_fin] at hr have hm : 0 < ms[r] := lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt)) rw [mem_step] refine ⟨.clock r 2 ⟨pos % ms[r], Nat.mod_lt _ hm⟩, ?_, ?_⟩ · simp [inCfg] · simp [δH, hr] theorem step_H_cfgSet_phase2_empty {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) : step (δH ms hge) (cfgSet ms hne hge ∅ (ms.prod - 1) true 2) = ∅ := by have hk2 := prod_ge_two_of_ge_two hne hge have hmax : ∀ r : Fin ms.length, (ms.prod - 1) % ms[r] = ms[r] - 1 := (crt_all_max_mod_iff hge hcop (by omega)).2 rfl ext x rw [mem_step] simp only [Finset.notMem_empty, iff_false, not_exists, not_and] intro y hy cases x with | cMid j => rw [mem_δH_cMid]; rintro rfl; simp [inCfg] at hy | cZero l => rw [mem_δH_cZero]; rintro (⟨_, rfl⟩ | ⟨_, rfl⟩ | ⟨_, rfl⟩) <;> simp [inCfg] at hy | clock r l a => rw [mem_δH_clock]; rintro (⟨_, rfl⟩ | ⟨_, rfl⟩) <;> simp [inCfg] at hy | f0 l => rw [mem_δH_f0]; rintro (⟨_, rfl⟩ | ⟨_, rfl⟩) <;> simp [inCfg] at hy | f1 l => rw [mem_δH_f1]; rintro (⟨_, rfl⟩ | ⟨_, rfl⟩) <;> simp [inCfg] at hy | g l => rw [mem_δH_g] rintro (⟨_, ⟨j, rfl⟩ | rfl | rfl | rfl⟩ | ⟨_, rfl⟩ | ⟨_, rfl⟩) <;> simp [inCfg] at hy | trap => rw [mem_δH_trap] rintro (rfl | ⟨r, a, hne_a, rfl⟩ | rfl | rfl | rfl) · simp [inCfg] at hy · simp only [mem_cfgSet, inCfg] at hy exact hne_a (hy.2.trans (hmax r)) · simp [inCfg] at hy · simp [inCfg] at hy · simp [inCfg] at hy theorem step_H_cfgSet_phase2_nonempty {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) {A : Finset (Fin ms.prod)} (hA : A.Nonempty) : step (δH ms hge) (cfgSet ms hne hge A (ms.prod - 1) true 2) = phase3Set ms hne hge A := by have hk2 := prod_ge_two_of_ge_two hne hge have hmax : ∀ r : Fin ms.length, (ms.prod - 1) % ms[r] = ms[r] - 1 := (crt_all_max_mod_iff hge hcop (by omega)).2 rfl ext x rw [mem_step, mem_phase3Set] cases x with | cMid j => simp only [mem_δH_cMid, mem_cfgSet, inCfg, inPhase3] have hmod : (ms.prod - 1 + j.val + 1) % ms.prod = j.val := by have hsum : ms.prod - 1 + j.val + 1 = ms.prod + j.val := by omega rw [hsum, Nat.add_mod_left, Nat.mod_eq_of_lt (by omega)] have hfin : (⟨(ms.prod - 1 + j.val + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨j.val, by omega⟩ := Fin.ext hmod constructor · rintro ⟨y, hy, rfl⟩; simpa [hfin] using hy · intro h; exact ⟨.cMid j, by simpa [hfin] using h, rfl⟩ | cZero l => simp only [mem_δH_cZero, mem_cfgSet, inCfg, inPhase3] have hmod : (ms.prod - 1) % ms.prod = ms.prod - 1 := Nat.mod_eq_of_lt (by omega) have hfin : (⟨(ms.prod - 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨ms.prod - 1, by omega⟩ := Fin.ext hmod fin_cases l · simp · simp · simp · constructor · rintro ⟨y, hy, ⟨h1, _⟩ | ⟨h2, _⟩ | ⟨_, rfl⟩⟩ · simp at h1 · simp at h2 · exact ⟨rfl, by simpa [hfin] using hy.2⟩ · rintro ⟨_, h⟩ exact ⟨.cZero 2, ⟨rfl, by simpa [hfin] using h⟩, Or.inr (Or.inr ⟨rfl, rfl⟩)⟩ | clock r l a => simp only [mem_δH_clock, mem_cfgSet, inCfg, inPhase3] fin_cases l <;> simp | f0 l => simp only [mem_δH_f0, mem_cfgSet, inCfg, inPhase3] fin_cases l <;> simp | f1 l => simp only [mem_δH_f1, mem_cfgSet, inCfg, inPhase3] fin_cases l <;> simp | g l => simp only [mem_δH_g, mem_cfgSet, inCfg, inPhase3, iff_true] fin_cases l · rcases exists_bit_at_of_nonempty hne hge hA (ms.prod - 1) with h0 | ⟨j, hj⟩ · exact ⟨.cZero 2, ⟨rfl, h0⟩, Or.inl ⟨rfl, Or.inr (Or.inr (Or.inr rfl))⟩⟩ · exact ⟨.cMid j, hj, Or.inl ⟨rfl, Or.inl ⟨j, rfl⟩⟩⟩ · exact ⟨.g 0, ⟨hA, Or.inl ⟨rfl, by decide⟩⟩, Or.inr (Or.inl ⟨rfl, rfl⟩)⟩ · exact ⟨.g 1, ⟨hA, Or.inr ⟨rfl, rfl⟩⟩, Or.inr (Or.inr ⟨rfl, rfl⟩)⟩ | trap => simp only [mem_δH_trap, mem_cfgSet, inCfg, inPhase3, iff_false, not_exists, not_and] intro y hy hcond rcases hcond with rfl | ⟨r, a, hne_a, rfl⟩ | rfl | rfl | rfl · simp at hy · exact hne_a (hy.2.trans (hmax r)) · simp at hy · simp at hy · exact hy theorem step_H_phase3Set_trap {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : Node.trap ∈ step (δH ms hge) (phase3Set ms hne hge A) := by rw [mem_step] exact ⟨.g 2, by simp [inPhase3], by simp [δH]⟩ theorem step_S_phase3Set {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : step (δS ms hne hge) (phase3Set ms hne hge A) = cfgSet ms hne hge A 0 false 0 := by have hk2 := prod_ge_two_of_ge_two hne hge ext x rw [mem_step, mem_cfgSet] cases x with | cMid j => simp only [mem_δS_cMid, mem_phase3Set, inPhase3, inCfg, isStartPreS] have hjlt : j.val < ms.prod - 1 := j.isLt have hmod : (0 + j.val + 1) % ms.prod = j.val + 1 := by rw [zero_add]; exact Nat.mod_eq_of_lt (by omega) have hfin : (⟨(0 + j.val + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨j.val + 1, by omega⟩ := Fin.ext hmod rw [hfin] constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with (rfl | rfl | rfl | rfl | rfl) | ⟨hj, rfl⟩ | ⟨hj, rfl | rfl | rfl⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · exact hy · simp at hy · convert hy.2 using 1; exact Fin.ext (by dsimp; omega) · simp at hy · intro h by_cases hj : j.val + 1 < ms.prod - 1 · exact ⟨.cMid ⟨j.val + 1, hj⟩, h, Or.inr (Or.inl ⟨hj, rfl⟩)⟩ · have hjEq : j.val = ms.prod - 2 := by omega refine ⟨.cZero 3, ⟨rfl, ?_⟩, Or.inr (Or.inr ⟨hjEq, Or.inr (Or.inl rfl)⟩)⟩ convert h using 1; exact Fin.ext (by dsimp; omega) | cZero l => simp only [mem_δS_cZero, mem_phase3Set, inPhase3, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, Fin.val_zero, Nat.zero_mod, true_and] constructor · rintro ⟨y, hy, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · exact hy · intro h exact ⟨.cMid ⟨0, by omega⟩, h, Or.inr rfl⟩ all_goals simp | clock r l a => simp only [mem_δS_clock, mem_phase3Set, inPhase3, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, Nat.zero_mod, true_and] constructor · rintro ⟨y, hy, ⟨ha, _⟩ | ⟨l', a', rfl, _⟩⟩ · exact ha · exact False.elim hy · intro ha exact ⟨.g 2, trivial, Or.inl ⟨ha, Or.inr rfl⟩⟩ all_goals simp | f0 l => simp only [mem_δS_f0, mem_phase3Set, inPhase3, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, true_and, iff_true] exact ⟨.g 2, trivial, Or.inr (Or.inr rfl)⟩ all_goals simp | f1 l => simp only [mem_δS_f1, mem_phase3Set, inPhase3, inCfg] fin_cases l · simp only [Fin.zero_eta, true_and, Bool.false_eq_true, false_and, iff_false, not_exists, not_and] rintro y hy (rfl | rfl) <;> exact False.elim hy all_goals simp | g l => simp only [mem_δS_g, mem_phase3Set, inCfg] fin_cases l <;> simp | trap => simp only [mem_δS_trap, inCfg, and_false, exists_false] theorem startSet_subset_step_S_of_mem {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) {S : Finset (Node ms)} {y : Node ms} (hy : y ∈ S) (hpre : isStartPreS y) : startSet ms hge ⊆ step (δS ms hne hge) S := by intro x hx rw [mem_step] exact ⟨y, hy, startSet_subset_δS_of_isStartPreS hne hge hpre hx⟩ theorem step_S_cfgSet_false_0_notMem {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) {pos : ℕ} (hpos : pos < ms.prod) (hnot : ⟨pos, hpos⟩ ∉ A) : step (δS ms hne hge) (cfgSet ms hne hge A pos false 0) = cfgSet ms hne hge (insert ⟨pos, hpos⟩ A) ((pos + 1) % ms.prod) false 0 := by have hk2 := prod_ge_two_of_ge_two hne hge have hpos_mod : (⟨pos % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨pos, hpos⟩ := Fin.ext (Nat.mod_eq_of_lt hpos) ext x rw [mem_step, mem_cfgSet] cases x with | cMid j => simp only [mem_δS_cMid, mem_cfgSet, inCfg, isStartPreS] constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with (rfl | rfl | rfl | rfl | rfl) | ⟨hj, rfl⟩ | ⟨hj, rfl | rfl | rfl⟩ · simp [hpos_mod, hnot] at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · apply Finset.mem_insert_of_mem convert hy using 1 refine Fin.ext ?_ dsimp rw [add_assoc, Nat.mod_add_mod]; congr 1; omega · simp at hy · simp at hy · have hm : ((pos + 1) % ms.prod + j.val + 1) % ms.prod = pos := by rw [hj]; exact mod_shift_msb hk2 hpos convert Finset.mem_insert_self (⟨pos, hpos⟩ : Fin ms.prod) A using 1 exact Fin.ext hm · intro h by_cases hj : j.val + 1 < ms.prod - 1 · have hne_pos : (⟨((pos + 1) % ms.prod + j.val + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) ≠ ⟨pos, hpos⟩ := by intro heq exact mod_shift_ne_self hk2 hpos hj (congrArg Fin.val heq) have hA : ⟨((pos + 1) % ms.prod + j.val + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ ∈ A := (Finset.mem_insert.1 h).resolve_left hne_pos refine ⟨.cMid ⟨j.val + 1, hj⟩, ?_, Or.inr (Or.inl ⟨hj, rfl⟩)⟩ convert hA using 1 refine Fin.ext ?_ dsimp symm; rw [add_assoc, Nat.mod_add_mod]; congr 1; omega · have hjEq : j.val = ms.prod - 2 := by omega exact ⟨.f0 0, ⟨trivial, rfl⟩, Or.inr (Or.inr ⟨hjEq, Or.inr (Or.inr rfl)⟩)⟩ | cZero l => simp only [mem_δS_cZero, mem_cfgSet, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, Fin.val_zero, true_and] have hne_pos : (⟨(pos + 1) % ms.prod % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) ≠ ⟨pos, hpos⟩ := by intro heq have hv := congrArg Fin.val heq simp only [Nat.mod_mod] at hv exact mod_add_one_ne_self hk2 hpos hv have hfin : (⟨(pos + 1) % ms.prod % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨(pos + 0 + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ := by ext; simp constructor · rintro ⟨y, hy, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ · simp [hpos_mod, hnot] at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · rw [hfin]; exact Finset.mem_insert_of_mem hy · intro h have hA := (Finset.mem_insert.1 h).resolve_left hne_pos rw [hfin] at hA exact ⟨.cMid ⟨0, by omega⟩, hA, Or.inr rfl⟩ all_goals simp | clock r l a => simp only [mem_δS_clock, mem_cfgSet, inCfg, isStartPreS] have hm : 0 < ms[r] := lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt)) fin_cases l · simp only [Fin.zero_eta, true_and] constructor · rintro ⟨y, hy, ⟨_, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ | ⟨l', a', rfl, ha⟩⟩ · simp [hpos_mod, hnot] at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · simp at hy · rw [ha, hy.2, Nat.mod_add_mod, mod_prod_mod_getElem] · intro ha refine ⟨.clock r 0 ⟨pos % ms[r], Nat.mod_lt _ hm⟩, ⟨rfl, rfl⟩, Or.inr ⟨0, _, rfl, ?_⟩⟩ rw [ha, mod_prod_mod_getElem, Nat.mod_add_mod] all_goals simp | f0 l => simp only [mem_δS_f0, mem_cfgSet, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, true_and, iff_true] exact ⟨.f0 0, by simp, Or.inr (Or.inl rfl)⟩ all_goals simp | f1 l => simp only [mem_δS_f1, mem_cfgSet, inCfg] fin_cases l · simp only [Fin.zero_eta, true_and, Bool.false_eq_true, false_and, iff_false, not_exists, not_and] rintro y hy (rfl | rfl) <;> simp at hy all_goals simp | g l => simp only [mem_δS_g, mem_cfgSet, inCfg] fin_cases l <;> simp | trap => simp only [mem_δS_trap, inCfg, and_false, exists_false] theorem step_S_cfgSet_false_2 {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) {pos : ℕ} (hpos : pos < ms.prod) : step (δS ms hne hge) (cfgSet ms hne hge A pos false 2) = cfgSet ms hne hge (A.erase ⟨pos, hpos⟩) ((pos + 1) % ms.prod) true 0 := by have hk2 := prod_ge_two_of_ge_two hne hge ext x rw [mem_step, mem_cfgSet] cases x with | cMid j => simp only [mem_δS_cMid, mem_cfgSet, inCfg, isStartPreS] constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with (rfl | rfl | rfl | rfl | rfl) | ⟨hj, rfl⟩ | ⟨hj, rfl | rfl | rfl⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · rw [Finset.mem_erase] refine ⟨?_, ?_⟩ · intro heq; exact mod_shift_ne_self hk2 hpos hj (congrArg Fin.val heq) · convert hy using 1 refine Fin.ext ?_ dsimp rw [add_assoc, Nat.mod_add_mod]; congr 1; omega · simp at hy · simp at hy · simp at hy · intro h rw [Finset.mem_erase] at h rcases h with ⟨hne_pos, hA⟩ have hj : j.val + 1 < ms.prod - 1 := by by_contra hge_j have hjEq : j.val = ms.prod - 2 := by omega apply hne_pos ext; dsimp; rw [hjEq]; exact mod_shift_msb hk2 hpos refine ⟨.cMid ⟨j.val + 1, hj⟩, ?_, Or.inr (Or.inl ⟨hj, rfl⟩)⟩ convert hA using 1 refine Fin.ext ?_ dsimp symm; rw [add_assoc, Nat.mod_add_mod]; congr 1; omega | cZero l => simp only [mem_δS_cZero, mem_cfgSet, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, Fin.val_zero, true_and] have hne_pos : (⟨(pos + 1) % ms.prod % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) ≠ ⟨pos, hpos⟩ := by intro heq have hv := congrArg Fin.val heq simp only [Nat.mod_mod] at hv exact mod_add_one_ne_self hk2 hpos hv have hfin : (⟨(pos + 1) % ms.prod % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨(pos + 0 + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ := by ext; simp rw [Finset.mem_erase] constructor · rintro ⟨y, hy, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · exact ⟨hne_pos, by rwa [hfin]⟩ · rintro ⟨_, hA⟩ rw [hfin] at hA exact ⟨.cMid ⟨0, by omega⟩, hA, Or.inr rfl⟩ all_goals simp | clock r l a => simp only [mem_δS_clock, mem_cfgSet, inCfg, isStartPreS] have hm : 0 < ms[r] := lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt)) fin_cases l · simp only [Fin.zero_eta, true_and] constructor · rintro ⟨y, hy, ⟨_, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ | ⟨l', a', rfl, ha⟩⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · simp at hy · rw [ha, hy.2, Nat.mod_add_mod, mod_prod_mod_getElem] · intro ha refine ⟨.clock r 2 ⟨pos % ms[r], Nat.mod_lt _ hm⟩, ⟨rfl, rfl⟩, Or.inr ⟨2, _, rfl, ?_⟩⟩ rw [ha, mod_prod_mod_getElem, Nat.mod_add_mod] all_goals simp | f0 l => simp only [mem_δS_f0, mem_cfgSet, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, true_and, Bool.true_eq_false, false_and, iff_false, not_exists, not_and] rintro y hy ((rfl | rfl | rfl | rfl | rfl) | rfl | rfl) <;> simp at hy all_goals simp | f1 l => simp only [mem_δS_f1, mem_cfgSet, inCfg] fin_cases l · simp only [Fin.zero_eta, true_and, iff_true] exact ⟨.f0 2, by simp, Or.inl rfl⟩ all_goals simp | g l => simp only [mem_δS_g, mem_cfgSet, inCfg] fin_cases l <;> simp | trap => simp only [mem_δS_trap, inCfg, and_false, exists_false] theorem step_S_cfgSet_true_1 {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) {pos : ℕ} (hpos : pos < ms.prod) : step (δS ms hne hge) (cfgSet ms hne hge A pos true 1) = cfgSet ms hne hge A ((pos + 1) % ms.prod) true 0 := by have hk2 := prod_ge_two_of_ge_two hne hge ext x rw [mem_step, mem_cfgSet] cases x with | cMid j => simp only [mem_δS_cMid, mem_cfgSet, inCfg, isStartPreS] constructor · rintro ⟨y, hy, hcond⟩ rcases hcond with (rfl | rfl | rfl | rfl | rfl) | ⟨hj, rfl⟩ | ⟨hj, rfl | rfl | rfl⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · convert hy using 1 refine Fin.ext ?_ dsimp rw [add_assoc, Nat.mod_add_mod]; congr 1; omega · convert hy.2 using 1 ext; dsimp; rw [hj, mod_shift_msb hk2 hpos, Nat.mod_eq_of_lt hpos] · simp at hy · simp at hy · intro h by_cases hj : j.val + 1 < ms.prod - 1 · refine ⟨.cMid ⟨j.val + 1, hj⟩, ?_, Or.inr (Or.inl ⟨hj, rfl⟩)⟩ convert h using 1 refine Fin.ext ?_ dsimp symm; rw [add_assoc, Nat.mod_add_mod]; congr 1; omega · have hjEq : j.val = ms.prod - 2 := by omega refine ⟨.cZero 1, ⟨rfl, ?_⟩, Or.inr (Or.inr ⟨hjEq, Or.inl rfl⟩)⟩ convert h using 1 ext; dsimp; rw [hjEq, mod_shift_msb hk2 hpos, Nat.mod_eq_of_lt hpos] | cZero l => simp only [mem_δS_cZero, mem_cfgSet, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, Fin.val_zero, true_and] have hfin : (⟨(pos + 1) % ms.prod % ms.prod, Nat.mod_lt _ (by omega)⟩ : Fin ms.prod) = ⟨(pos + 0 + 1) % ms.prod, Nat.mod_lt _ (by omega)⟩ := by ext; simp constructor · rintro ⟨y, hy, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · rwa [hfin] · intro h rw [hfin] at h exact ⟨.cMid ⟨0, by omega⟩, h, Or.inr rfl⟩ all_goals simp | clock r l a => simp only [mem_δS_clock, mem_cfgSet, inCfg, isStartPreS] have hm : 0 < ms[r] := lt_of_lt_of_le (by norm_num) (hge _ (List.getElem_mem r.isLt)) fin_cases l · simp only [Fin.zero_eta, true_and] constructor · rintro ⟨y, hy, ⟨_, (rfl | rfl | rfl | rfl | rfl) | rfl⟩ | ⟨l', a', rfl, ha⟩⟩ · simp at hy · simp at hy · simp at hy · simp at hy · exact False.elim hy · simp at hy · rw [ha, hy.2, Nat.mod_add_mod, mod_prod_mod_getElem] · intro ha refine ⟨.clock r 1 ⟨pos % ms[r], Nat.mod_lt _ hm⟩, ⟨rfl, rfl⟩, Or.inr ⟨1, _, rfl, ?_⟩⟩ rw [ha, mod_prod_mod_getElem, Nat.mod_add_mod] all_goals simp | f0 l => simp only [mem_δS_f0, mem_cfgSet, inCfg, isStartPreS] fin_cases l · simp only [Fin.zero_eta, true_and, Bool.true_eq_false, false_and, iff_false, not_exists, not_and] rintro y hy ((rfl | rfl | rfl | rfl | rfl) | rfl | rfl) <;> simp at hy all_goals simp | f1 l => simp only [mem_δS_f1, mem_cfgSet, inCfg] fin_cases l · simp only [Fin.zero_eta, true_and, iff_true] exact ⟨.f1 1, by simp, Or.inr rfl⟩ all_goals simp | g l => simp only [mem_δS_g, mem_cfgSet, inCfg] fin_cases l <;> simp | trap => simp only [mem_δS_trap, inCfg, and_false, exists_false] /-! ### Section 4: Binary Counter Value, Mortality Witness, and Exponential Lower Bound -/ /-- Binary integer value `∑_{i ∈ A} 2^i` of a subset `A ⊆ Fin k`. -/ def bitVal {k : ℕ} (A : Finset (Fin k)) : ℕ := ∑ i ∈ A, 2 ^ i.val theorem bitVal_empty (k : ℕ) : bitVal (∅ : Finset (Fin k)) = 0 := by simp [bitVal] theorem bitVal_insert {k : ℕ} {A : Finset (Fin k)} {a : Fin k} (ha : a ∉ A) : bitVal (insert a A) = bitVal A + 2 ^ a.val := by simp [bitVal, Finset.sum_insert ha, add_comm] theorem bitVal_erase_add {k : ℕ} {A : Finset (Fin k)} {a : Fin k} (ha : a ∈ A) : bitVal (A.erase a) + 2 ^ a.val = bitVal A := by have h := Finset.add_sum_erase A (fun i : Fin k => 2 ^ i.val) ha unfold bitVal; omega theorem bitVal_erase_ge {k : ℕ} (A : Finset (Fin k)) (a : Fin k) : (bitVal A : ℤ) - (2 ^ a.val : ℤ) ≤ (bitVal (A.erase a) : ℤ) := by by_cases ha : a ∈ A · have h := bitVal_erase_add ha have h' : (bitVal (A.erase a) : ℤ) + (2 ^ a.val : ℤ) = (bitVal A : ℤ) := by exact_mod_cast h omega · rw [Finset.erase_eq_of_notMem ha] have hpos : (0 : ℤ) ≤ (2 ^ a.val : ℤ) := by positivity omega theorem bitVal_univ (k : ℕ) : bitVal (Finset.univ : Finset (Fin k)) = 2 ^ k - 1 := by unfold bitVal induction k with | zero => simp | succ k ih => rw [Fin.sum_univ_castSucc] simp only [Fin.val_castSucc, Fin.val_last] rw [ih] have hpow : 1 ≤ 2 ^ k := Nat.one_le_pow _ _ (by norm_num) rw [pow_succ] omega theorem bitVal_eq_zero_iff {k : ℕ} (A : Finset (Fin k)) : bitVal A = 0 ↔ A = ∅ := by unfold bitVal rw [Finset.sum_eq_zero_iff] constructor · intro h ext a simp only [Finset.notMem_empty, iff_false] intro ha have h0 := h a ha have hpos : 0 < 2 ^ a.val := Nat.pos_of_ne_zero (by positivity) omega · intro h a ha; subst h; exact False.elim (Finset.notMem_empty a ha) /-! #### Existence of a mortal word (proving the pair IS mortal) -/ private lemma exists_walk_modeTrue {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : ∀ d pos, pos < ms.prod → ms.prod - 1 - pos = d → ∃ w : List Bool, evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge A pos true 0) w = cfgSet ms hne hge A (ms.prod - 1) true 0 := by intro d induction d with | zero => intro pos _hpos hd have hEq : pos = ms.prod - 1 := by omega subst hEq exact ⟨[], rfl⟩ | succ d ih => intro pos hpos hd have hlt : pos + 1 < ms.prod := by omega have hstep : evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge A pos true 0) [true, false] = cfgSet ms hne hge A (pos + 1) true 0 := by simp only [evalStep_cons, evalStep_nil, Bool.false_eq_true, ↓reduceIte] rw [step_H_cfgSet_lt2 hne hge A pos true (by decide)] change step (δS ms hne hge) (cfgSet ms hne hge A pos true 1) = _ rw [step_S_cfgSet_true_1 hne hge A hpos, Nat.mod_eq_of_lt hlt] obtain ⟨w, hw⟩ := ih (pos + 1) hlt (by omega) refine ⟨[true, false] ++ w, ?_⟩ rw [evalStep_append, hstep, hw] private lemma exists_shift_zeros {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : ∀ p, p < ms.prod → (∀ j : Fin ms.prod, j.val < p → j ∉ A) → ∃ B : Finset (Fin ms.prod), (∀ x : Fin ms.prod, x ∈ B ↔ x ∈ A ∨ x.val < p) ∧ bitVal B = bitVal A + (2 ^ p - 1) ∧ evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge A 0 false 0) (List.replicate p false) = cfgSet ms hne hge B p false 0 := by intro p induction p with | zero => intro _ _ exact ⟨A, by simp, by simp, rfl⟩ | succ p ih => intro hp hzero obtain ⟨B, hBmem, hBval, hBeval⟩ := ih (by omega) (fun j hj => hzero j (by omega)) have hnot : (⟨p, by omega⟩ : Fin ms.prod) ∉ B := by rw [hBmem] push Not exact ⟨hzero ⟨p, by omega⟩ (by dsimp; omega), by dsimp; omega⟩ refine ⟨insert ⟨p, by omega⟩ B, ?_, ?_, ?_⟩ · intro x rw [Finset.mem_insert, hBmem, Fin.ext_iff] by_cases hx : x ∈ A · simp [hx] · simp [hx]; omega · rw [bitVal_insert hnot, hBval] simp only [] have h1 : 1 ≤ 2 ^ p := Nat.one_le_pow _ _ (by norm_num) rw [pow_succ] omega · rw [List.replicate_succ', evalStep_append, hBeval, evalStep_cons, evalStep_nil] simp only [Bool.false_eq_true, ↓reduceIte] rw [step_S_cfgSet_false_0_notMem hne hge B (by omega) hnot, Nat.mod_eq_of_lt hp] theorem exists_mortal_word_from_cfg {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) : ∀ v (A : Finset (Fin ms.prod)), bitVal A = v → ∃ w : List Bool, evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge A 0 false 0) w = ∅ := by have hk2 := prod_ge_two_of_ge_two hne hge intro v induction v with | zero => intro A hv have hA : A = ∅ := (bitVal_eq_zero_iff A).1 hv subst hA -- Apply H H S at pos 0 -> cfgSet ∅ 1 true 0, walk to k-1, then H H H -> ∅ have h1 : evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge ∅ 0 false 0) [true, true, false] = cfgSet ms hne hge ∅ (1 % ms.prod) true 0 := by simp only [evalStep_cons, evalStep_nil, Bool.false_eq_true, ↓reduceIte] rw [step_H_cfgSet_lt2 hne hge ∅ 0 false (by decide)] change step (δS ms hne hge) (step (δH ms hge) (cfgSet ms hne hge ∅ 0 false 1)) = _ rw [step_H_cfgSet_lt2 hne hge ∅ 0 false (by decide)] change step (δS ms hne hge) (cfgSet ms hne hge ∅ 0 false 2) = _ rw [step_S_cfgSet_false_2 hne hge ∅ (by omega)] simp obtain ⟨w2, hw2⟩ := exists_walk_modeTrue hne hge ∅ (ms.prod - 1 - 1 % ms.prod) (1 % ms.prod) (Nat.mod_lt _ (by omega)) rfl have h3 : evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge ∅ (ms.prod - 1) true 0) [true, true, true] = ∅ := by simp only [evalStep_cons, evalStep_nil, ite_true] rw [step_H_cfgSet_lt2 hne hge ∅ (ms.prod - 1) true (by decide)] change step (δH ms hge) (step (δH ms hge) (cfgSet ms hne hge ∅ (ms.prod - 1) true 1)) = _ rw [step_H_cfgSet_lt2 hne hge ∅ (ms.prod - 1) true (by decide)] exact step_H_cfgSet_phase2_empty hne hge hcop refine ⟨[true, true, false] ++ w2 ++ [true, true, true], ?_⟩ rw [evalStep_append, evalStep_append, h1, hw2, h3] | succ v ih => intro A hv have hAne : A.Nonempty := by by_contra hempty rw [Finset.not_nonempty_iff_eq_empty] at hempty subst hempty simp [bitVal] at hv let p : Fin ms.prod := A.min' hAne have hp_mem : p ∈ A := Finset.min'_mem A hAne have hp_min : ∀ j : Fin ms.prod, j.val < p.val → j ∉ A := by intro j hj hjA have hle := Finset.min'_le A j hjA exact absurd (Fin.le_iff_val_le_val.1 hle) (by omega) obtain ⟨B, hBmem, hBval, hBeval⟩ := exists_shift_zeros hne hge A p.val p.isLt hp_min have hp_in_B : p ∈ B := (hBmem p).2 (Or.inl hp_mem) let A' := B.erase p have hA'val : bitVal A' = v := by have h1 := bitVal_erase_add hp_in_B have hpow : 1 ≤ 2 ^ p.val := Nat.one_le_pow _ _ (by norm_num) change bitVal A' + 2 ^ p.val = bitVal B at h1 omega have hHHS : evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge B p.val false 0) [true, true, false] = cfgSet ms hne hge A' ((p.val + 1) % ms.prod) true 0 := by simp only [evalStep_cons, evalStep_nil, Bool.false_eq_true, ↓reduceIte] rw [step_H_cfgSet_lt2 hne hge B p.val false (by decide)] change step (δS ms hne hge) (step (δH ms hge) (cfgSet ms hne hge B p.val false 1)) = _ rw [step_H_cfgSet_lt2 hne hge B p.val false (by decide)] change step (δS ms hne hge) (cfgSet ms hne hge B p.val false 2) = _ exact step_S_cfgSet_false_2 hne hge B p.isLt obtain ⟨w2, hw2⟩ := exists_walk_modeTrue hne hge A' (ms.prod - 1 - (p.val + 1) % ms.prod) ((p.val + 1) % ms.prod) (Nat.mod_lt _ (by omega)) rfl by_cases hA'empty : A' = ∅ · have h3 : evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge ∅ (ms.prod - 1) true 0) [true, true, true] = ∅ := by simp only [evalStep_cons, evalStep_nil, ite_true] rw [step_H_cfgSet_lt2 hne hge ∅ (ms.prod - 1) true (by decide)] change step (δH ms hge) (step (δH ms hge) (cfgSet ms hne hge ∅ (ms.prod - 1) true 1)) = _ rw [step_H_cfgSet_lt2 hne hge ∅ (ms.prod - 1) true (by decide)] exact step_H_cfgSet_phase2_empty hne hge hcop refine ⟨List.replicate p.val false ++ [true, true, false] ++ w2 ++ [true, true, true], ?_⟩ rw [evalStep_append, evalStep_append, evalStep_append, hBeval, hHHS, hw2, hA'empty, h3] · have hA'ne : A'.Nonempty := Finset.nonempty_iff_ne_empty.2 hA'empty have h3 : evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge A' (ms.prod - 1) true 0) [true, true, true, false] = cfgSet ms hne hge A' 0 false 0 := by simp only [evalStep_cons, evalStep_nil, Bool.false_eq_true, ↓reduceIte] rw [step_H_cfgSet_lt2 hne hge A' (ms.prod - 1) true (by decide)] change step (δS ms hne hge) (step (δH ms hge) (step (δH ms hge) (cfgSet ms hne hge A' (ms.prod - 1) true 1))) = _ rw [step_H_cfgSet_lt2 hne hge A' (ms.prod - 1) true (by decide)] change step (δS ms hne hge) (step (δH ms hge) (cfgSet ms hne hge A' (ms.prod - 1) true 2)) = _ rw [step_H_cfgSet_phase2_nonempty hne hge hcop hA'ne, step_S_phase3Set hne hge A'] obtain ⟨w4, hw4⟩ := ih A' hA'val refine ⟨List.replicate p.val false ++ [true, true, false] ++ w2 ++ [true, true, true, false] ++ w4, ?_⟩ rw [evalStep_append, evalStep_append, evalStep_append, evalStep_append, hBeval, hHHS, hw2, h3, hw4] theorem exists_mortal_word_coprime {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) : ∃ w : List Bool, w ≠ [] ∧ evalStep (δS ms hne hge) (δH ms hge) Finset.univ w = ∅ := by obtain ⟨w, hw⟩ := exists_mortal_word_from_cfg hne hge hcop (bitVal Finset.univ) Finset.univ rfl refine ⟨[true, true, true, true, false] ++ w, by simp, ?_⟩ rw [evalStep_append, evalStep_univ_HHHHS, startSet_eq_cfgSet ms hne hge, hw] /-! #### Potential Function and Exponential Lower Bound `(k + 4) * (2^k - 1)` -/ /-- Integer potential on `cfgSet A pos mode phase` (for `pos < k`). -/ def phiCfg (k : ℕ) (A : Finset (Fin k)) (pos : ℕ) (mode : Bool) (phase : Fin 3) : ℤ := if mode then ((k : ℤ) + 4) * (bitVal A : ℤ) + 2 * ((k : ℤ) - 1 - (pos : ℤ)) + 3 - (phase.val : ℤ) else ((k : ℤ) + 4) * ((bitVal A : ℤ) + 1 - (2 ^ pos : ℤ)) - (pos : ℤ) - (phase.val : ℤ) /-- Integer potential on `phase3Set A`. -/ def phiP3 (k : ℕ) (A : Finset (Fin k)) : ℤ := ((k : ℤ) + 4) * (bitVal A : ℤ) /-- Target start potential `(k + 4) * (2^k - 1)`. -/ def phiStart (k : ℕ) : ℤ := ((k : ℤ) + 4) * ((2 ^ k - 1 : ℕ) : ℤ) private lemma phiCfg_start (k : ℕ) : phiCfg k Finset.univ 0 false 0 = phiStart k := by simp [phiCfg, phiStart, bitVal_univ] private lemma cfgSet_nonempty {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) (pos : ℕ) (mode : Bool) (phase : Fin 3) : (cfgSet ms hne hge A pos mode phase).Nonempty := by cases mode with | false => exact ⟨.f0 phase, by simp [inCfg]⟩ | true => exact ⟨.f1 phase, by simp [inCfg]⟩ private lemma phase3Set_nonempty {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (A : Finset (Fin ms.prod)) : (phase3Set ms hne hge A).Nonempty := ⟨.g 0, by simp [inPhase3]⟩ private lemma min_le_succ_of_step {a b M n : ℤ} (hstep : a ≤ b + 1) (hih : min b M ≤ n) : min a M ≤ n + 1 := by rcases le_total b M with h | h · rw [min_eq_left h] at hih exact le_trans (min_le_left _ _) (by omega) · rw [min_eq_right h] at hih exact le_trans (min_le_right _ _) (by omega) /-- Joint strong-induction lower bound on `cfgSet`, `phase3Set`, and trap-containing subsets. -/ theorem evalStep_lower_bound_strong {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) : ∀ N : ℕ, ∀ w : List Bool, w.length = N → (∀ A pos, pos < ms.prod → ∀ mode phase, evalStep (δS ms hne hge) (δH ms hge) (cfgSet ms hne hge A pos mode phase) w = ∅ → min (phiCfg ms.prod A pos mode phase) (phiStart ms.prod) ≤ (w.length : ℤ)) ∧ (∀ A, A.Nonempty → evalStep (δS ms hne hge) (δH ms hge) (phase3Set ms hne hge A) w = ∅ → min (phiP3 ms.prod A) (phiStart ms.prod) ≤ (w.length : ℤ)) ∧ (∀ S : Finset (Node ms), Node.trap ∈ S → evalStep (δS ms hne hge) (δH ms hge) S w = ∅ → phiStart ms.prod + 1 ≤ (w.length : ℤ)) := by have hk2 : 2 ≤ ms.prod := prod_ge_two_of_ge_two hne hge intro N induction N with | zero => intro w hlen have hw : w = [] := List.eq_nil_of_length_eq_zero hlen subst hw refine ⟨?_, ?_, ?_⟩ · intro A pos _ mode phase h0 exact False.elim ((cfgSet_nonempty hne hge A pos mode phase).ne_empty h0) · intro A _ h0 exact False.elim ((phase3Set_nonempty hne hge A).ne_empty h0) · intro S htrap h0 rw [evalStep_nil] at h0; rw [h0] at htrap; exact False.elim (Finset.notMem_empty _ htrap) | succ N ih => intro w hlen cases w with | nil => simp at hlen | cons b w' => have hw'len : w'.length = N := by simpa using hlen obtain ⟨ihCfg, ihP3, ihTrap⟩ := ih w' hw'len have hfromStart : ∀ S : Finset (Node ms), startSet ms hge ⊆ S → evalStep (δS ms hne hge) (δH ms hge) S w' = ∅ → phiStart ms.prod ≤ (w'.length : ℤ) := by intro S hsub h0 have h0' : evalStep (δS ms hne hge) (δH ms hge) (startSet ms hge) w' = ∅ := Finset.subset_empty.1 (h0 ▸ evalStep_mono _ _ hsub w') rw [startSet_eq_cfgSet ms hne hge] at h0' have h := ihCfg Finset.univ 0 (by omega) false 0 h0' rwa [phiCfg_start, min_self] at h have hlen_succ : ((b :: w').length : ℤ) = (w'.length : ℤ) + 1 := by simp refine ⟨?_, ?_, ?_⟩ · -- Case 1: cfgSet A pos mode phase intro A pos hpos mode phase h0 rw [evalStep_cons] at h0 cases b with | true => simp only [ite_true] at h0 by_cases hph : phase.val < 2 · rw [step_H_cfgSet_lt2 hne hge A pos mode hph] at h0 have hih := ihCfg A pos hpos mode ⟨phase.val + 1, by omega⟩ h0 rw [hlen_succ] apply min_le_succ_of_step _ hih cases mode <;> simp [phiCfg] <;> omega · have hph2 : phase = 2 := by fin_cases phase <;> simp at hph ⊢ subst hph2 cases mode with | false => have htrap := step_H_cfgSet_phase2_trap_modeFalse hne hge A pos have hih := ihTrap _ htrap h0 exact le_trans (min_le_right _ _) (by omega) | true => by_cases hmax : pos = ms.prod - 1 · subst hmax by_cases hA : A = ∅ · subst hA have hphi : phiCfg ms.prod ∅ (ms.prod - 1) true 2 = 1 := by dsimp [phiCfg]; rw [bitVal_empty] have hsub : ((ms.prod - 1 : ℕ) : ℤ) = (ms.prod : ℤ) - 1 := by omega rw [hsub]; simp only [Nat.cast_zero, mul_zero, zero_add]; omega rw [hphi] exact le_trans (min_le_left _ _) (by omega) · have hAne : A.Nonempty := Finset.nonempty_iff_ne_empty.2 hA rw [step_H_cfgSet_phase2_nonempty hne hge hcop hAne] at h0 have hih := ihP3 A hAne h0 rw [hlen_succ] apply min_le_succ_of_step _ hih dsimp [phiCfg, phiP3] have hsub : ((ms.prod - 1 : ℕ) : ℤ) = (ms.prod : ℤ) - 1 := by omega rw [hsub]; omega · have htrap := step_H_cfgSet_phase2_trap_posNe hne hge hcop A hpos hmax have hih := ihTrap _ htrap h0 exact le_trans (min_le_right _ _) (by omega) | false => simp only [Bool.false_eq_true, ↓reduceIte] at h0 cases mode with | false => fin_cases phase · -- mode = false, phase = 0 dsimp only at h0 ⊢ change evalStep (δS ms hne hge) (δH ms hge) (step (δS ms hne hge) (cfgSet ms hne hge A pos false 0)) w' = ∅ at h0 change min (phiCfg ms.prod A pos false 0) (phiStart ms.prod) ≤ ((false :: w').length : ℤ) by_cases hmem : (⟨pos, hpos⟩ : Fin ms.prod) ∈ A · have hcz : Node.cZero 0 ∈ cfgSet ms hne hge A pos false 0 := by simp only [mem_cfgSet, inCfg, Fin.val_zero, true_and] convert hmem using 1; exact Fin.ext (Nat.mod_eq_of_lt hpos) have hsub := startSet_subset_step_S_of_mem hne hge hcz (Or.inl rfl) have hih := hfromStart _ hsub h0 exact le_trans (min_le_right _ _) (by omega) · rw [step_S_cfgSet_false_0_notMem hne hge A hpos hmem] at h0 have hih := ihCfg (insert ⟨pos, hpos⟩ A) ((pos + 1) % ms.prod) (Nat.mod_lt _ (by omega)) false 0 h0 rw [hlen_succ] apply min_le_succ_of_step _ hih simp only [phiCfg, Bool.false_eq_true, ↓reduceIte, Fin.val_zero, bitVal_insert hmem, Nat.cast_add, Nat.cast_pow, Nat.cast_ofNat] by_cases hlt : pos + 1 < ms.prod · rw [Nat.mod_eq_of_lt hlt, pow_succ] push_cast ring_nf; omega · have hmod0 : (pos + 1) % ms.prod = 0 := by have : pos + 1 = ms.prod := by omega rw [this, Nat.mod_self] rw [hmod0] have hpow_pos : (1 : ℤ) ≤ (2 : ℤ) ^ pos := by exact_mod_cast Nat.one_le_pow pos 2 (by norm_num) have hmul : (0 : ℤ) ≤ ((ms.prod : ℤ) + 4) * (2 * (2 : ℤ) ^ pos - 1) := by nlinarith simp only [pow_zero, Nat.cast_zero, sub_zero] nlinarith · -- mode = false, phase = 1 -> reset via f0 1 dsimp only at h0 ⊢ have hf : Node.f0 1 ∈ cfgSet ms hne hge A pos false 1 := by simp [inCfg] have hsub := startSet_subset_step_S_of_mem hne hge hf (Or.inr (Or.inl rfl)) have hih := hfromStart _ hsub h0 exact le_trans (min_le_right _ _) (by omega) · -- mode = false, phase = 2 -> decrement step! dsimp only at h0 ⊢ change evalStep (δS ms hne hge) (δH ms hge) (step (δS ms hne hge) (cfgSet ms hne hge A pos false 2)) w' = ∅ at h0 change min (phiCfg ms.prod A pos false 2) (phiStart ms.prod) ≤ ((false :: w').length : ℤ) rw [step_S_cfgSet_false_2 hne hge A hpos] at h0 have hih := ihCfg (A.erase ⟨pos, hpos⟩) ((pos + 1) % ms.prod) (Nat.mod_lt _ (by omega)) true 0 h0 rw [hlen_succ] apply min_le_succ_of_step _ hih have herase : (bitVal A : ℤ) - (2 ^ pos : ℤ) ≤ (bitVal (A.erase ⟨pos, hpos⟩) : ℤ) := bitVal_erase_ge A ⟨pos, hpos⟩ simp only [phiCfg, Bool.false_eq_true, ↓reduceIte, Fin.val_two, Fin.val_zero] by_cases hlt : pos + 1 < ms.prod · rw [Nat.mod_eq_of_lt hlt] push_cast nlinarith · have hmod0 : (pos + 1) % ms.prod = 0 := by have : pos + 1 = ms.prod := by omega rw [this, Nat.mod_self] rw [hmod0] push_cast nlinarith | true => fin_cases phase · -- mode = true, phase = 0 -> reset via f1 0 dsimp only at h0 ⊢ have hf : Node.f1 0 ∈ cfgSet ms hne hge A pos true 0 := by simp [inCfg] have hsub := startSet_subset_step_S_of_mem hne hge hf (Or.inr (Or.inr (Or.inl rfl))) have hih := hfromStart _ hsub h0 exact le_trans (min_le_right _ _) (by omega) · -- mode = true, phase = 1 -> advance pos dsimp only at h0 ⊢ change evalStep (δS ms hne hge) (δH ms hge) (step (δS ms hne hge) (cfgSet ms hne hge A pos true 1)) w' = ∅ at h0 change min (phiCfg ms.prod A pos true 1) (phiStart ms.prod) ≤ ((false :: w').length : ℤ) rw [step_S_cfgSet_true_1 hne hge A hpos] at h0 have hih := ihCfg A ((pos + 1) % ms.prod) (Nat.mod_lt _ (by omega)) true 0 h0 rw [hlen_succ] apply min_le_succ_of_step _ hih simp only [phiCfg, ite_true, Fin.val_one, Fin.val_zero] by_cases hlt : pos + 1 < ms.prod · rw [Nat.mod_eq_of_lt hlt]; push_cast; omega · have hmod0 : (pos + 1) % ms.prod = 0 := by have : pos + 1 = ms.prod := by omega rw [this, Nat.mod_self] rw [hmod0]; push_cast; omega · -- mode = true, phase = 2 -> reset via f1 2 dsimp only at h0 ⊢ have hf : Node.f1 2 ∈ cfgSet ms hne hge A pos true 2 := by simp [inCfg] have hsub := startSet_subset_step_S_of_mem hne hge hf (Or.inr (Or.inr (Or.inr (Or.inl rfl)))) have hih := hfromStart _ hsub h0 exact le_trans (min_le_right _ _) (by omega) · -- Case 2: phase3Set A intro A hAne h0 rw [evalStep_cons] at h0 cases b with | true => simp only [ite_true] at h0 have htrap := step_H_phase3Set_trap hne hge A have hih := ihTrap _ htrap h0 exact le_trans (min_le_right _ _) (by omega) | false => simp only [Bool.false_eq_true, ↓reduceIte] at h0 rw [step_S_phase3Set hne hge A] at h0 have hih := ihCfg A 0 (by omega) false 0 h0 rw [hlen_succ] apply min_le_succ_of_step _ hih simp [phiP3, phiCfg] · -- Case 3: trap ∈ S intro S htrap h0 rw [evalStep_cons] at h0 cases b with | true => simp only [ite_true] at h0 have htrap' : Node.trap ∈ step (δH ms hge) S := by rw [mem_step]; exact ⟨.trap, htrap, by simp [δH]⟩ have hih := ihTrap _ htrap' h0 omega | false => simp only [Bool.false_eq_true, ↓reduceIte] at h0 have hsub := startSet_subset_step_S_of_mem hne hge htrap (Or.inr (Or.inr (Or.inr (Or.inr rfl)))) have hih := hfromStart _ hsub h0 omega theorem evalStep_univ_eq_empty_length_ge {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) {w : List Bool} (hw : evalStep (δS ms hne hge) (δH ms hge) Finset.univ w = ∅) : (ms.prod + 4) * (2 ^ ms.prod - 1) ≤ w.length := by have hk2 := prod_ge_two_of_ge_two hne hge have h0 : evalStep (δS ms hne hge) (δH ms hge) (startSet ms hge) w = ∅ := Finset.subset_empty.1 (hw ▸ evalStep_mono _ _ (Finset.subset_univ _) w) rw [startSet_eq_cfgSet ms hne hge] at h0 have h := (evalStep_lower_bound_strong hne hge hcop w.length w rfl).1 Finset.univ 0 (by omega) false 0 h0 rw [phiCfg_start, min_self] at h unfold phiStart at h exact_mod_cast h /-- Helper inequality: for `k ≥ 2`, `k * 2^k ≤ (k + 4) * (2^k - 1)` and `2^k ≤ (k + 4) * (2^k - 1)`. -/ theorem mul_two_pow_le_lower_bound {k : ℕ} (_hk : 2 ≤ k) : k * 2 ^ k ≤ (k + 4) * (2 ^ k - 1) := by have hpow : k + 4 ≤ 4 * 2 ^ k := by induction k with | zero => omega | succ k ih => have : 1 ≤ 2 ^ k := Nat.one_le_pow _ _ (by norm_num) rw [pow_succ]; omega have h1 : 1 ≤ 2 ^ k := Nat.one_le_pow _ _ (by norm_num) zify [h1] at hpow ⊢ nlinarith /-- **Master Coprime-Clock Theorem**: For any nonempty pairwise coprime list `ms` with all entries `≥ 2`, any dimension `n ≥ ms.prod + 3 * ms.sum + 13`, and any characteristic-zero semiring `R`, there exists a mortal pair `(M₀, M₁)` of `n × n` binary (`0`-`1`) matrices over `R` whose shortest zero product has length at least `(ms.prod + 4) * (2 ^ ms.prod - 1)`. -/ theorem exists_mortal_binary_pair_coprime (R : Type*) [Semiring R] [CharZero R] {ms : List ℕ} (hne : ms ≠ []) (hge : ∀ m ∈ ms, 2 ≤ m) (hcop : ms.Pairwise Nat.Coprime) {n : ℕ} (hn : ms.prod + 3 * ms.sum + 13 ≤ n) : ∃ M₀ M₁ : Matrix (Fin n) (Fin n) R, IsMortalBinaryPairOver R n M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → (ms.prod + 4) * (2 ^ ms.prod - 1) ≤ w.length := by let n₀ := ms.prod + 3 * ms.sum + 13 have hcard : Fintype.card (Node ms) = n₀ := card_node hne hge let e : Node ms ≃ Fin n₀ := Fintype.equivFinOfCardEq hcard let A₀ : Matrix (Fin n₀) (Fin n₀) ℕ := Matrix.reindexRingEquiv ℕ e (toMatrix (δS ms hne hge)) let A₁ : Matrix (Fin n₀) (Fin n₀) ℕ := Matrix.reindexRingEquiv ℕ e (toMatrix (δH ms hge)) let P₀ : Matrix (Fin n) (Fin n) ℕ := padMatrix hn A₀ let P₁ : Matrix (Fin n) (Fin n) ℕ := padMatrix hn A₁ let M₀ : Matrix (Fin n) (Fin n) R := P₀.map Nat.cast let M₁ : Matrix (Fin n) (Fin n) R := P₁.map Nat.cast have hbin₀ : IsBinaryMatrix M₀ := isBinaryMatrix_map_natCast (isBinaryMatrix_padMatrix hn (isBinaryMatrix_reindex ℕ e (isBinaryMatrix_toMatrix _))) have hbin₁ : IsBinaryMatrix M₁ := isBinaryMatrix_map_natCast (isBinaryMatrix_padMatrix hn (isBinaryMatrix_reindex ℕ e (isBinaryMatrix_toMatrix _))) have heval : ∀ w : List Bool, w ≠ [] → (evalMat M₀ M₁ w = 0 ↔ evalStep (δS ms hne hge) (δH ms hge) Finset.univ w = ∅) := by intro w hw rw [map_natCast_evalMat, map_natCast_eq_zero_iff, padMatrix_evalMat hn A₀ A₁ hw, padMatrix_eq_zero_iff, reindex_evalMat, map_eq_zero_iff _ (Matrix.reindexRingEquiv ℕ e).injective, evalMat_eq_zero_iff] refine ⟨M₀, M₁, ⟨hbin₀, hbin₁, ?_⟩, ?_⟩ · obtain ⟨w, hne_w, hw⟩ := exists_mortal_word_coprime hne hge hcop exact ⟨w, hne_w, (heval w hne_w).2 hw⟩ · intro w hne_w hw exact evalStep_univ_eq_empty_length_ge hne hge hcop ((heval w hne_w).1 hw) end CoprimeAutomaton /-! ## Section 5: Universal `2^n - 1` Upper Bound for Mortal Binary Matrix Pairs -/ section UpperBound /-- Any word reaching `∅` from `S` in an NFA on `V` can be shortened to a word of length at most `2 ^ |V| - 1` (by removing subset loops). -/ theorem exists_short_evalStep_empty {V : Type*} [Fintype V] [DecidableEq V] (δ₀ δ₁ : V → Finset V) (S : Finset V) (w : List Bool) (hw : evalStep δ₀ δ₁ S w = ∅) : ∃ w' : List Bool, evalStep δ₀ δ₁ S w' = ∅ ∧ w'.length ≤ 2 ^ Fintype.card V - 1 := by classical -- Choose a shortest word reaching ∅ from S. have hex : ∃ m : ℕ, ∃ w' : List Bool, w'.length = m ∧ evalStep δ₀ δ₁ S w' = ∅ := ⟨w.length, w, rfl, hw⟩ let m := Nat.find hex obtain ⟨w', hlen, h0⟩ := Nat.find_spec hex refine ⟨w', h0, ?_⟩ by_contra hgt push Not at hgt -- Since `2 ^ |V| ≤ w'.length`, the `w'.length + 1` prefix subsets cannot all be distinct. have hcard : Fintype.card (Finset V) < w'.length + 1 := by rw [Fintype.card_finset]; omega let f : Fin (w'.length + 1) → Finset V := fun i => evalStep δ₀ δ₁ S (w'.take i.val) obtain ⟨i, j, hij, hfij⟩ := Fintype.exists_ne_map_eq_of_card_lt f (by simpa using hcard) -- WLOG i < j; excise the loop `w'[i..j)`. have hloop : ∀ a b : Fin (w'.length + 1), a.val < b.val → f a = f b → False := by intro a b hab hfab let w'' := w'.take a.val ++ w'.drop b.val have hw''_eval : evalStep δ₀ δ₁ S w'' = ∅ := by dsimp [w''] rw [evalStep_append] change evalStep δ₀ δ₁ (f a) (w'.drop b.val) = ∅ rw [hfab] dsimp [f] rw [← evalStep_append, List.take_append_drop] exact h0 have hw''_len : w''.length < m := by dsimp [w''] rw [List.length_append, List.length_take, List.length_drop] have ha : a.val ≤ w'.length := by omega have hb : b.val ≤ w'.length := by omega omega exact Nat.find_min hex hw''_len ⟨w'', rfl, hw''_eval⟩ rcases lt_or_gt_of_ne (Fin.val_ne_of_ne hij) with hlt | hgt' · exact hloop i j hlt hfij · exact hloop j i hgt' hfij.symm /-- For a binary matrix `M` over a `CharZero` semiring `R`, construct its NFA transition function. -/ private def matToDelta {n : ℕ} {R : Type*} [Zero R] [DecidableEq R] (M : Matrix (Fin n) (Fin n) R) : Fin n → Finset (Fin n) := fun i => Finset.univ.filter (fun j => M i j ≠ 0) private lemma map_toMatrix_matToDelta {n : ℕ} {R : Type*} [Semiring R] [DecidableEq R] {M : Matrix (Fin n) (Fin n) R} (hM : IsBinaryMatrix M) : (toMatrix (matToDelta M)).map (Nat.cast : ℕ → R) = M := by ext i j simp only [Matrix.map_apply, toMatrix, matToDelta, Finset.mem_filter, Finset.mem_univ, true_and] rcases hM i j with h0 | h1 · simp [h0] · by_cases h10 : (1 : R) = 0 · simp [h1, h10] · simp [h1, h10] /-- **Universal Upper Bound**: Every mortal pair `(M₀, M₁)` of `n × n` binary matrices over a characteristic-zero semiring `R` has a non-empty zero product of length at most `2^n - 1` (for `n ≥ 1`). -/ theorem exists_short_mortal_word_le_two_pow_sub_one (R : Type*) [Semiring R] [CharZero R] {n : ℕ} (hn : 1 ≤ n) {M₀ M₁ : Matrix (Fin n) (Fin n) R} (hmortal : IsMortalBinaryPairOver R n M₀ M₁) : ∃ w : List Bool, w ≠ [] ∧ evalMat M₀ M₁ w = 0 ∧ w.length ≤ 2 ^ n - 1 := by classical rcases hmortal with ⟨h0, h1, w, hwne, hw0⟩ let δ₀ := matToDelta M₀ let δ₁ := matToDelta M₁ have hM₀ : (toMatrix δ₀).map (Nat.cast : ℕ → R) = M₀ := map_toMatrix_matToDelta h0 have hM₁ : (toMatrix δ₁).map (Nat.cast : ℕ → R) = M₁ := map_toMatrix_matToDelta h1 have hstep0 : evalStep δ₀ δ₁ Finset.univ w = ∅ := by rw [← evalMat_eq_zero_iff, ← map_natCast_eq_zero_iff (R := R), ← map_natCast_evalMat, hM₀, hM₁] exact hw0 obtain ⟨w', hw'0, hw'len⟩ := exists_short_evalStep_empty δ₀ δ₁ Finset.univ w hstep0 have hw'ne : w' ≠ [] := by rintro rfl rw [evalStep_nil] at hw'0 have hmem : (⟨0, by omega⟩ : Fin n) ∈ (Finset.univ : Finset (Fin n)) := Finset.mem_univ _ rw [hw'0] at hmem exact Finset.notMem_empty _ hmem refine ⟨w', hw'ne, ?_, by simpa using hw'len⟩ rw [← hM₀, ← hM₁, map_natCast_evalMat, map_natCast_eq_zero_iff, evalMat_eq_zero_iff] exact hw'0 end UpperBound /-! ## Section 6: Everywhere `2^(n - 8√n - 23)`, Exact Exponent Limit `1`, and Primorial `2^(n - O(log² n / log log n))` Bounds -/ section QuantitativeBounds /-- **Everywhere `2^(n - 8√n - 23)` Lower Bound**: For EVERY `n ≥ 34` and EVERY characteristic-zero semiring `R`, there exists a mortal pair `(M₀, M₁)` of `n × n` binary matrices over `R` such that every non-empty zero product has length at least `2 ^ (n - 8 * Nat.sqrt n - 23)`. -/ theorem exists_mortal_binary_pair_sqrt_gap (R : Type*) [Semiring R] [CharZero R] {n : ℕ} (hn : 34 ≤ n) : ∃ M₀ M₁ : Matrix (Fin n) (Fin n) R, IsMortalBinaryPairOver R n M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → 2 ^ (n - 8 * Nat.sqrt n - 23) ≤ w.length := by classical -- Find the largest `m ≥ 2` with `m * (m + 1) + 6 * m + 16 ≤ n`. have hex : ∃ m : ℕ, n < (m + 1) * (m + 2) + 6 * (m + 1) + 16 := ⟨n, by nlinarith⟩ let m := Nat.find hex have hm_spec : n < (m + 1) * (m + 2) + 6 * (m + 1) + 16 := Nat.find_spec hex have hm_ge2 : 2 ≤ m := by by_contra hlt have hm1 : m ≤ 1 := by omega have hle : (m + 1) * (m + 2) + 6 * (m + 1) + 16 ≤ 34 := by nlinarith omega have hm_fit : m * (m + 1) + 6 * m + 16 ≤ n := by have hprev := Nat.find_min hex (show m - 1 < m by omega) push Not at hprev have hsub : m - 1 + 1 = m := by omega have hsub2 : m - 1 + 2 = m + 1 := by omega rw [hsub, hsub2] at hprev exact hprev have hm_le_sqrt : m ≤ Nat.sqrt n := by rw [Nat.le_sqrt] nlinarith have hgap : n - 8 * Nat.sqrt n - 23 ≤ m * (m + 1) := by have h1 : n ≤ m * (m + 1) + 8 * m + 23 := by nlinarith omega let ms : List ℕ := [m, m + 1] have hne : ms ≠ [] := by simp [ms] have hge : ∀ x ∈ ms, 2 ≤ x := by intro x hx; simp only [ms, List.mem_cons, List.not_mem_nil, or_false] at hx rcases hx with rfl | rfl <;> omega have hcop : ms.Pairwise Nat.Coprime := by simp only [ms, List.pairwise_cons, List.mem_cons, List.not_mem_nil, or_false, forall_eq, List.Pairwise.nil, and_true] exact ⟨Nat.coprime_self_add_right.2 (Nat.coprime_one_right m), fun _ h => False.elim h⟩ have hdim : ms.prod + 3 * ms.sum + 13 ≤ n := by simp only [ms, List.prod_cons, List.prod_nil, mul_one, List.sum_cons, List.sum_nil, add_zero] omega obtain ⟨M₀, M₁, hmortal, hlb⟩ := exists_mortal_binary_pair_coprime R hne hge hcop hdim refine ⟨M₀, M₁, hmortal, fun w hne_w hw0 => ?_⟩ have h1 := hlb w hne_w hw0 have hprod : ms.prod = m * (m + 1) := by simp [ms] rw [hprod] at h1 have hk2 : 2 ≤ m * (m + 1) := by nlinarith have h2 : 2 ^ (m * (m + 1)) ≤ (m * (m + 1) + 4) * (2 ^ (m * (m + 1)) - 1) := by have hmul := mul_two_pow_le_lower_bound hk2 have hle : 2 ^ (m * (m + 1)) ≤ m * (m + 1) * 2 ^ (m * (m + 1)) := Nat.le_mul_of_pos_left _ (by omega) exact le_trans hle hmul exact le_trans (Nat.pow_le_pow_right (by norm_num) hgap) (le_trans h2 h1) /-- The binary matrix mortality threshold `mt2 n` (= Ryzhikov's `mt(n, 2)`): the supremum over all mortal pairs `(M₀, M₁)` of `n × n` binary matrices over `ℕ` of their minimum zero-product length. -/ noncomputable def mt2 (n : ℕ) : ℕ := sSup {l : ℕ | ∃ M₀ M₁ : Matrix (Fin n) (Fin n) ℕ, IsMortalBinaryPairOver ℕ n M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → l ≤ w.length} theorem mt2_bddAbove {n : ℕ} (hn : 1 ≤ n) : BddAbove {l : ℕ | ∃ M₀ M₁ : Matrix (Fin n) (Fin n) ℕ, IsMortalBinaryPairOver ℕ n M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → l ≤ w.length} := by refine ⟨2 ^ n - 1, ?_⟩ rintro l ⟨M₀, M₁, hm, hl⟩ obtain ⟨w, hwne, hw0, hwlen⟩ := exists_short_mortal_word_le_two_pow_sub_one ℕ hn hm exact le_trans (hl w hwne hw0) hwlen theorem mt2_le_two_pow_sub_one {n : ℕ} (hn : 1 ≤ n) : mt2 n ≤ 2 ^ n - 1 := by unfold mt2 apply csSup_le · refine ⟨1, 0, 0, ⟨fun _ _ => Or.inl rfl, fun _ _ => Or.inl rfl, [false], by simp, by simp [evalMat]⟩, ?_⟩ intro w hwne _ cases w with | nil => contradiction | cons _ _ => simp · rintro l ⟨M₀, M₁, hm, hl⟩ obtain ⟨w, hwne, hw0, hwlen⟩ := exists_short_mortal_word_le_two_pow_sub_one ℕ hn hm exact le_trans (hl w hwne hw0) hwlen theorem mt2_ge_of_pair {n l : ℕ} (hn : 1 ≤ n) (M₀ M₁ : Matrix (Fin n) (Fin n) ℕ) (hm : IsMortalBinaryPairOver ℕ n M₀ M₁) (hl : ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → l ≤ w.length) : l ≤ mt2 n := le_csSup (mt2_bddAbove hn) ⟨M₀, M₁, hm, hl⟩ theorem mt2_sqrt_lower_bound {n : ℕ} (hn : 34 ≤ n) : 2 ^ (n - 8 * Nat.sqrt n - 23) ≤ mt2 n := by obtain ⟨M₀, M₁, hm, hl⟩ := exists_mortal_binary_pair_sqrt_gap ℕ hn exact mt2_ge_of_pair (by omega) M₀ M₁ hm hl /-- **Exact Asymptotic Exponent Theorem**: `lim_{n → ∞} (log₂ mt2(n)) / n = 1`. This completely resolves the exponential growth base of `mt(n, 2)` (improving Ryzhikov's June 2025 world record `1/3` for `m = 2` and `1/2` for `m = 3` all the way to the optimal `1`). -/ theorem mt2_log2_div_tendsto_one : Filter.Tendsto (fun n : ℕ => Real.logb 2 (mt2 n : ℝ) / (n : ℝ)) Filter.atTop (nhds 1) := by have h1 : Filter.Tendsto (fun n : ℕ => (1 : ℝ) - 8 * Real.sqrt (n : ℝ) / (n : ℝ) - 23 / (n : ℝ)) Filter.atTop (nhds 1) := by have hinv : Filter.Tendsto (fun n : ℕ => ((n : ℝ))⁻¹) Filter.atTop (nhds 0) := tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop have hsqrt_inv : Filter.Tendsto (fun n : ℕ => (Real.sqrt (n : ℝ))⁻¹) Filter.atTop (nhds 0) := by have hsq : Filter.Tendsto (fun n : ℕ => Real.sqrt (n : ℝ)) Filter.atTop Filter.atTop := Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop exact tendsto_inv_atTop_zero.comp hsq have h8 : Filter.Tendsto (fun n : ℕ => 8 * Real.sqrt (n : ℝ) / (n : ℝ)) Filter.atTop (nhds 0) := by have hEq : (fun n : ℕ => 8 * Real.sqrt (n : ℝ) / (n : ℝ)) =ᶠ[Filter.atTop] (fun n : ℕ => 8 * (Real.sqrt (n : ℝ))⁻¹) := by filter_upwards [Filter.eventually_ge_atTop 1] with n hn have hn_pos : (0 : ℝ) < (n : ℝ) := by positivity have hsq_pos : (0 : ℝ) < Real.sqrt (n : ℝ) := Real.sqrt_pos.2 hn_pos field_simp rw [Real.sq_sqrt (le_of_lt hn_pos)] rw [Filter.tendsto_congr' hEq] simpa using hsqrt_inv.const_mul 8 have h23 : Filter.Tendsto (fun n : ℕ => 23 / (n : ℝ)) Filter.atTop (nhds 0) := by simpa [div_eq_mul_inv] using hinv.const_mul 23 simpa using (tendsto_const_nhds.sub h8).sub h23 refine tendsto_of_tendsto_of_tendsto_of_le_of_le' h1 tendsto_const_nhds ?_ ?_ · filter_upwards [Filter.eventually_ge_atTop 121] with n hn have hsqrt_le : (Nat.sqrt n : ℝ) ≤ Real.sqrt (n : ℝ) := by rw [Real.le_sqrt (Nat.cast_nonneg _) (Nat.cast_nonneg _), sq] exact_mod_cast Nat.sqrt_le n have hsub_ok : 8 * Nat.sqrt n + 23 ≤ n := by have hsq : Nat.sqrt n * Nat.sqrt n ≤ n := Nat.sqrt_le n nlinarith [Nat.sqrt_le_self n] have hlb : (2 : ℝ) ^ (n - 8 * Nat.sqrt n - 23) ≤ (mt2 n : ℝ) := by exact_mod_cast mt2_sqrt_lower_bound (by omega : 34 ≤ n) have hlog_lb : ((n - 8 * Nat.sqrt n - 23 : ℕ) : ℝ) ≤ Real.logb 2 (mt2 n : ℝ) := by have hpos : (0 : ℝ) < (2 : ℝ) ^ (n - 8 * Nat.sqrt n - 23) := by positivity have hle := Real.logb_le_logb_of_le (by norm_num : (1 : ℝ) < 2) hpos hlb rwa [Real.logb_pow, Real.logb_self_eq_one (by norm_num : (1 : ℝ) < 2), mul_one] at hle have hn_pos : (0 : ℝ) < (n : ℝ) := by positivity rw [le_div_iff₀ hn_pos] have hcast : ((n - 8 * Nat.sqrt n - 23 : ℕ) : ℝ) = (n : ℝ) - 8 * (Nat.sqrt n : ℝ) - 23 := by have : n - 8 * Nat.sqrt n - 23 + (8 * Nat.sqrt n + 23) = n := by omega have h' : ((n - 8 * Nat.sqrt n - 23 : ℕ) : ℝ) + (8 * (Nat.sqrt n : ℝ) + 23) = (n : ℝ) := by exact_mod_cast this linarith have hlin : (1 - 8 * Real.sqrt (n : ℝ) / (n : ℝ) - 23 / (n : ℝ)) * (n : ℝ) = (n : ℝ) - 8 * Real.sqrt (n : ℝ) - 23 := by field_simp linarith · filter_upwards [Filter.eventually_ge_atTop 34] with n hn have hn_pos : (0 : ℝ) < (n : ℝ) := by positivity have hmt_pos : (0 : ℝ) < (mt2 n : ℝ) := by have h1 : 1 ≤ mt2 n := le_trans (Nat.one_le_pow _ _ (by norm_num)) (mt2_sqrt_lower_bound hn) exact_mod_cast h1 have hub : (mt2 n : ℝ) ≤ (2 : ℝ) ^ n := by have hle : mt2 n ≤ 2 ^ n := le_trans (mt2_le_two_pow_sub_one (by omega)) (Nat.sub_le _ _) exact_mod_cast hle have hlog_ub : Real.logb 2 (mt2 n : ℝ) ≤ (n : ℝ) := by have hle := Real.logb_le_logb_of_le (by norm_num : (1 : ℝ) < 2) hmt_pos hub rwa [Real.logb_pow, Real.logb_self_eq_one (by norm_num : (1 : ℝ) < 2), mul_one] at hle exact (div_le_one hn_pos).2 hlog_ub /-- **Every Sub-Optimal Exponential Base Is Eventually Beaten**: For any `c < 1` (including Ryzhikov's `c = 1/3` for `m = 2` and `c = 1/2` for `m = 3`), eventually `(2 : ℝ) ^ (c * n) < mt2 n`. -/ theorem mt2_beats_any_sublinear_exponent {c : ℝ} (hc : c < 1) : ∀ᶠ n : ℕ in Filter.atTop, (2 : ℝ) ^ (c * (n : ℝ)) < (mt2 n : ℝ) := by have hev := (mt2_log2_div_tendsto_one.eventually (Ioi_mem_nhds hc)) filter_upwards [hev, Filter.eventually_ge_atTop 34] with n hcn hn have hn_pos : (0 : ℝ) < (n : ℝ) := by positivity have hmt_pos : (0 : ℝ) < (mt2 n : ℝ) := by have h1 : 1 ≤ mt2 n := le_trans (Nat.one_le_pow _ _ (by norm_num)) (mt2_sqrt_lower_bound hn) exact_mod_cast h1 have hlt : c * (n : ℝ) < Real.logb 2 (mt2 n : ℝ) := (lt_div_iff₀ hn_pos).1 hcn calc (2 : ℝ) ^ (c * (n : ℝ)) < (2 : ℝ) ^ (Real.logb 2 (mt2 n : ℝ)) := Real.rpow_lt_rpow_of_exponent_lt (by norm_num) hlt _ = (mt2 n : ℝ) := Real.rpow_logb (by norm_num) (by norm_num) hmt_pos /-! ### Elementary Chebyshev Bounds and the Primorial `2^(n - O(log² n / log log n))` Family -/ /-- The finset of all primes in `[2, N]`. -/ def primesUpTo (N : ℕ) : Finset ℕ := (Finset.Icc 2 N).filter Nat.Prime /-- Primorial `∏_{p ≤ N} p`. -/ def primorial (N : ℕ) : ℕ := ∏ p ∈ primesUpTo N, p /-- Sum of primes `∑_{p ≤ N} p`. -/ def primeSum (N : ℕ) : ℕ := ∑ p ∈ primesUpTo N, p /-- Prime counting function `π(N)`. -/ def primeCount (N : ℕ) : ℕ := (primesUpTo N).card private lemma mem_primesUpTo {N p : ℕ} : p ∈ primesUpTo N ↔ p.Prime ∧ p ≤ N := by simp only [primesUpTo, Finset.mem_filter, Finset.mem_Icc] exact ⟨fun ⟨⟨_, hle⟩, hp⟩ => ⟨hp, hle⟩, fun ⟨hp, hle⟩ => ⟨⟨hp.two_le, hle⟩, hp⟩⟩ private lemma centralBinom_le_four_pow (m : ℕ) : (2 * m).choose m ≤ 2 ^ (2 * m) := by rw [← Nat.sum_range_choose] exact Finset.single_le_sum (fun _ _ => Nat.zero_le _) (Finset.mem_range.2 (by omega)) private lemma four_pow_le_mul_centralBinom (m : ℕ) : 2 ^ (2 * m) ≤ (2 * m + 1) * (2 * m).choose m := by rw [← Nat.sum_range_choose] calc ∑ k ∈ Finset.range (2 * m + 1), (2 * m).choose k ≤ ∑ _k ∈ Finset.range (2 * m + 1), (2 * m).choose m := by refine Finset.sum_le_sum fun k _ => ?_ have hmid := Nat.choose_le_middle k (2 * m) simpa [Nat.mul_div_right m (by norm_num : 0 < 2)] using hmid _ = (2 * m + 1) * (2 * m).choose m := by simp private lemma prime_dvd_centralBinom_of_gt {m p : ℕ} (hp : p.Prime) (hgt : m < p) (hle : p ≤ 2 * m) : p ∣ (2 * m).choose m := by have hfac : (2 * m).choose m * m.factorial * m.factorial = (2 * m).factorial := by have h := Nat.choose_mul_factorial_mul_factorial (show m ≤ 2 * m by omega) simpa [show 2 * m - m = m by omega] using h have hdvd_num : p ∣ (2 * m).factorial := hp.dvd_factorial.2 hle have hndvd_den : ¬ p ∣ m.factorial := by rw [hp.dvd_factorial]; omega rw [← hfac] at hdvd_num rcases hp.dvd_mul.1 hdvd_num with h1 | h2 · rcases hp.dvd_mul.1 h1 with h11 | h12 · exact h11 · exact False.elim (hndvd_den h12) · exact False.elim (hndvd_den h2) private lemma finset_prod_dvd_of_pairwise_coprime {S : Finset ℕ} {z : ℕ} (hcop : ∀ p ∈ S, ∀ q ∈ S, p ≠ q → Nat.Coprime p q) (hdvd : ∀ p ∈ S, p ∣ z) : ∏ p ∈ S, p ∣ z := by classical induction S using Finset.induction_on with | empty => simp | insert a s ha ih => rw [Finset.prod_insert ha] have ha_dvd : a ∣ z := hdvd a (Finset.mem_insert_self a s) have hs_dvd : ∏ p ∈ s, p ∣ z := ih (fun p hp q hq hne => hcop p (Finset.mem_insert_of_mem hp) q (Finset.mem_insert_of_mem hq) hne) (fun p hp => hdvd p (Finset.mem_insert_of_mem hp)) have hcop_a : Nat.Coprime a (∏ p ∈ s, p) := Nat.Coprime.prod_right fun p hp => hcop a (Finset.mem_insert_self a s) p (Finset.mem_insert_of_mem hp) (fun heq => ha (heq ▸ hp)) exact hcop_a.mul_dvd_of_dvd_of_dvd ha_dvd hs_dvd private lemma nat_log_lt_of_lt_pow {b x k : ℕ} (hb : 1 < b) (hx : 0 < x) (h : x < b ^ k) : Nat.log b x < k := by have hle : b ^ Nat.log b x ≤ x := Nat.pow_log_le_self b (Nat.pos_iff_ne_zero.1 hx) exact (Nat.pow_lt_pow_iff_right hb).1 (lt_of_le_of_lt hle h) private lemma dyadic_primeCount_step {j : ℕ} (_hj : 1 ≤ j) : j * (primeCount (2 ^ (j + 1)) - primeCount (2 ^ j)) ≤ 2 ^ (j + 1) := by let m := 2 ^ j let S := (Finset.Ioc m (2 * m)).filter Nat.Prime have hdisj : Disjoint (primesUpTo m) S := by rw [Finset.disjoint_left] intro p hp1 hp2 rw [mem_primesUpTo] at hp1 simp only [S, Finset.mem_filter, Finset.mem_Ioc] at hp2 omega have hunion : primesUpTo (2 * m) = primesUpTo m ∪ S := by ext p simp only [Finset.mem_union, mem_primesUpTo, S, Finset.mem_filter, Finset.mem_Ioc] constructor · rintro ⟨hp, hle⟩ by_cases h : p ≤ m · exact Or.inl ⟨hp, h⟩ · exact Or.inr ⟨⟨by omega, hle⟩, hp⟩ · rintro (⟨hp, hle⟩ | ⟨⟨_, hle⟩, hp⟩) · exact ⟨hp, by omega⟩ · exact ⟨hp, hle⟩ have h2m : 2 * m = 2 ^ (j + 1) := by dsimp [m]; rw [pow_succ, mul_comm] have hcard : S.card = primeCount (2 ^ (j + 1)) - primeCount (2 ^ j) := by unfold primeCount rw [← h2m, hunion, Finset.card_union_of_disjoint hdisj] change S.card = (primesUpTo m).card + S.card - (primesUpTo m).card omega have hdvd : ∏ p ∈ S, p ∣ (2 * m).choose m := by refine finset_prod_dvd_of_pairwise_coprime ?_ ?_ · intro p hp q hq hne simp only [S, Finset.mem_filter] at hp hq exact (Nat.coprime_primes hp.2 hq.2).2 hne · intro p hp simp only [S, Finset.mem_filter, Finset.mem_Ioc] at hp exact prime_dvd_centralBinom_of_gt hp.2 hp.1.1 hp.1.2 have hpos : 0 < (2 * m).choose m := Nat.choose_pos (by omega) have hprod_le : ∏ p ∈ S, p ≤ 2 ^ (2 * m) := le_trans (Nat.le_of_dvd hpos hdvd) (centralBinom_le_four_pow m) have hpow_le : m ^ S.card ≤ ∏ p ∈ S, p := by calc m ^ S.card = ∏ _p ∈ S, m := by simp _ ≤ ∏ p ∈ S, p := Finset.prod_le_prod' fun p hp => by simp only [S, Finset.mem_filter, Finset.mem_Ioc] at hp; omega have h2pow : 2 ^ (j * S.card) ≤ 2 ^ (2 ^ (j + 1)) := by rw [pow_mul, ← h2m] exact le_trans hpow_le hprod_le rw [← hcard] exact (Nat.pow_le_pow_iff_right (by norm_num : 1 < 2)).1 h2pow /-- Elementary Chebyshev upper bound on powers of 2: `r * π(2^r) ≤ 4 * 2^r` for all `r ≥ 1`. -/ theorem chebyshev_primeCount_pow_two : ∀ r : ℕ, 1 ≤ r → r * primeCount (2 ^ r) ≤ 4 * 2 ^ r := by intro r hr induction r with | zero => omega | succ r ih => by_cases hr3 : r < 3 · have hle : primeCount (2 ^ (r + 1)) ≤ 2 ^ (r + 1) := by unfold primeCount primesUpTo have hpos : 1 ≤ 2 ^ (r + 1) := Nat.one_le_pow _ _ (by norm_num) calc ((Finset.Icc 2 (2 ^ (r + 1))).filter Nat.Prime).card ≤ (Finset.Icc 2 (2 ^ (r + 1))).card := Finset.card_filter_le _ _ _ ≤ 2 ^ (r + 1) := by rw [Nat.card_Icc]; omega nlinarith · have hih := ih (by omega) have hstep := dyadic_primeCount_step (show 1 ≤ r by omega) have hmono : primeCount (2 ^ r) ≤ primeCount (2 ^ (r + 1)) := by refine Finset.card_le_card fun p hp => ?_ rw [mem_primesUpTo] at hp ⊢ exact ⟨hp.1, le_trans hp.2 (Nat.pow_le_pow_right (by norm_num) (by omega))⟩ have hsum : r * primeCount (2 ^ (r + 1)) ≤ 3 * 2 ^ (r + 1) := by have h1 : r * primeCount (2 ^ (r + 1)) = r * primeCount (2 ^ r) + r * (primeCount (2 ^ (r + 1)) - primeCount (2 ^ r)) := by rw [← Nat.mul_add, Nat.add_sub_of_le hmono] have h2r : 2 ^ (r + 1) = 2 * 2 ^ r := by rw [pow_succ, mul_comm] omega have hmul' : r * ((r + 1) * primeCount (2 ^ (r + 1))) ≤ r * (4 * 2 ^ (r + 1)) := by calc r * ((r + 1) * primeCount (2 ^ (r + 1))) = (r + 1) * (r * primeCount (2 ^ (r + 1))) := by ring _ ≤ (r + 1) * (3 * 2 ^ (r + 1)) := Nat.mul_le_mul_left _ hsum _ = (3 * (r + 1)) * 2 ^ (r + 1) := by ring _ ≤ (4 * r) * 2 ^ (r + 1) := Nat.mul_le_mul_right _ (by omega) _ = r * (4 * 2 ^ (r + 1)) := by ring exact Nat.le_of_mul_le_mul_left hmul' (by omega) private lemma exp_bound_chebyshev : ∀ s : ℕ, 5 ≤ s → 2 * s + 1 + 2 * s * 2 ^ s ≤ 2 ^ (2 * s - 1) := by intro s hs induction s with | zero => omega | succ s ih => by_cases hs5 : s < 5 · have hsEq : s = 4 := by omega subst hsEq; norm_num · have hih := ih (by omega) have hpow2 : 2 ^ (2 * (s + 1) - 1) = 4 * 2 ^ (2 * s - 1) := by have : 2 * (s + 1) - 1 = (2 * s - 1) + 2 := by omega rw [this, pow_add]; ring rw [hpow2, pow_succ] have h2s : 2 ^ s ≥ 32 := by calc 32 = 2 ^ 5 := by norm_num _ ≤ 2 ^ s := Nat.pow_le_pow_right (by norm_num) (by omega) nlinarith /-- Elementary Chebyshev lower bound on primorials at even powers of 2: `2 ^ (2 ^ (2 * s - 1)) ≤ primorial (2 ^ (2 * s))` for all `s ≥ 5`. -/ theorem chebyshev_primorial_lower_bound {s : ℕ} (hs : 5 ≤ s) : 2 ^ (2 ^ (2 * s - 1)) ≤ primorial (2 ^ (2 * s)) := by let m := 2 ^ (2 * s - 1) have h2m : 2 * m = 2 ^ (2 * s) := by dsimp [m] have hsub : 2 * s = (2 * s - 1) + 1 := by omega conv_rhs => rw [hsub] rw [pow_succ, mul_comm] let C := (2 * m).choose m have hCpos : 0 < C := Nat.choose_pos (by omega) have hCne : C ≠ 0 := Nat.pos_iff_ne_zero.1 hCpos have hCfac : ∏ p ∈ C.primeFactors, p ^ (C.factorization p) = C := by have h := Nat.prod_factorization_pow_eq_self hCne rwa [Finsupp.prod, Nat.support_factorization] at h have hsub_primes : C.primeFactors ⊆ primesUpTo (2 * m) := by intro p hp rw [Nat.mem_primeFactors] at hp rw [mem_primesUpTo] refine ⟨hp.1, ?_⟩ have hfac : C * m.factorial * m.factorial = (2 * m).factorial := by have h := Nat.choose_mul_factorial_mul_factorial (show m ≤ 2 * m by omega) simpa [C, show 2 * m - m = m by omega] using h have hdvd : p ∣ (2 * m).factorial := by rw [← hfac]; exact dvd_mul_of_dvd_left (dvd_mul_of_dvd_left hp.2.1 _) _ exact hp.1.dvd_factorial.1 hdvd have hpe_le : ∀ p ∈ C.primeFactors, p ^ (C.factorization p) ≤ 2 * m := by intro p hp have hp_prime : p.Prime := Nat.prime_of_mem_primeFactors hp have : Fact p.Prime := ⟨hp_prime⟩ rw [Nat.factorization_def C hp_prime] have hval_le : padicValNat p C ≤ Nat.log p (2 * m) := by rw [padicValNat_choose (show m ≤ 2 * m by omega) (Nat.lt_succ_self _)] calc ({i ∈ Finset.Ico 1 (Nat.log p (2 * m) + 1) | p ^ i ≤ m % p ^ i + (2 * m - m) % p ^ i}).card ≤ (Finset.Ico 1 (Nat.log p (2 * m) + 1)).card := Finset.card_filter_le _ _ _ = Nat.log p (2 * m) := by simp exact le_trans (Nat.pow_le_pow_right hp_prime.pos hval_le) (Nat.pow_log_le_self p (by dsimp [m]; positivity)) have hpe_large : ∀ p ∈ C.primeFactors, 2 ^ s < p → p ^ (C.factorization p) ≤ p := by intro p hp hgt have hp_prime : p.Prime := Nat.prime_of_mem_primeFactors hp have : Fact p.Prime := ⟨hp_prime⟩ rw [Nat.factorization_def C hp_prime] have hlog_le : Nat.log p (2 * m) ≤ 1 := by have hlt2 : 2 * m < p ^ 2 := by rw [h2m] have hsq : 2 ^ (2 * s) = (2 ^ s) ^ 2 := by rw [← pow_mul, mul_comm] rw [hsq] exact Nat.pow_lt_pow_left hgt (by norm_num) have := nat_log_lt_of_lt_pow hp_prime.one_lt (by dsimp [m]; positivity) hlt2 omega have hval_le : padicValNat p C ≤ 1 := by rw [padicValNat_choose (show m ≤ 2 * m by omega) (Nat.lt_succ_self _)] calc ({i ∈ Finset.Ico 1 (Nat.log p (2 * m) + 1) | p ^ i ≤ m % p ^ i + (2 * m - m) % p ^ i}).card ≤ (Finset.Ico 1 (Nat.log p (2 * m) + 1)).card := Finset.card_filter_le _ _ _ = Nat.log p (2 * m) := by simp _ ≤ 1 := hlog_le calc p ^ padicValNat p C ≤ p ^ 1 := Nat.pow_le_pow_right hp_prime.pos hval_le _ = p := pow_one p let S_small := C.primeFactors.filter (· ≤ 2 ^ s) let S_large := C.primeFactors.filter (fun p => ¬ p ≤ 2 ^ s) have hC_split : C = (∏ p ∈ S_small, p ^ (C.factorization p)) * (∏ p ∈ S_large, p ^ (C.factorization p)) := by conv_lhs => rw [← hCfac] exact (Finset.prod_filter_mul_prod_filter_not C.primeFactors (· ≤ 2 ^ s) (fun p => p ^ (C.factorization p))).symm have hsmall_card : S_small.card ≤ 2 ^ s := by have hsub : S_small ⊆ Finset.Icc 1 (2 ^ s) := by intro p hp simp only [S_small, Finset.mem_filter] at hp rw [Finset.mem_Icc] exact ⟨(Nat.prime_of_mem_primeFactors hp.1).pos, hp.2⟩ calc S_small.card ≤ (Finset.Icc 1 (2 ^ s)).card := Finset.card_le_card hsub _ = 2 ^ s := by simp have hsmall_prod : ∏ p ∈ S_small, p ^ (C.factorization p) ≤ (2 * m) ^ (2 ^ s) := by calc ∏ p ∈ S_small, p ^ (C.factorization p) ≤ ∏ _p ∈ S_small, (2 * m) := Finset.prod_le_prod' fun p hp => hpe_le p (Finset.mem_filter.1 hp).1 _ = (2 * m) ^ S_small.card := by simp _ ≤ (2 * m) ^ (2 ^ s) := Nat.pow_le_pow_right (by dsimp [m]; positivity) hsmall_card have hlarge_prod : ∏ p ∈ S_large, p ^ (C.factorization p) ≤ primorial (2 * m) := by calc ∏ p ∈ S_large, p ^ (C.factorization p) ≤ ∏ p ∈ S_large, p := Finset.prod_le_prod' fun p hp => by rw [Finset.mem_filter] at hp exact hpe_large p hp.1 (by omega) _ ≤ ∏ p ∈ primesUpTo (2 * m), p := by refine Finset.prod_le_prod_of_subset_of_one_le' ?_ ?_ · exact Finset.Subset.trans (Finset.filter_subset _ _) hsub_primes · intro p hp _; exact (mem_primesUpTo.1 hp).1.pos have h4m : 2 ^ (2 * m) ≤ (2 * m + 1) * (2 * m) ^ (2 ^ s) * primorial (2 * m) := by calc 2 ^ (2 * m) ≤ (2 * m + 1) * C := four_pow_le_mul_centralBinom m _ = (2 * m + 1) * ((∏ p ∈ S_small, p ^ (C.factorization p)) * (∏ p ∈ S_large, p ^ (C.factorization p))) := congrArg ((2 * m + 1) * ·) hC_split _ ≤ (2 * m + 1) * ((2 * m) ^ (2 ^ s) * primorial (2 * m)) := Nat.mul_le_mul_left _ (Nat.mul_le_mul hsmall_prod hlarge_prod) _ = (2 * m + 1) * (2 * m) ^ (2 ^ s) * primorial (2 * m) := by ring have hpref : (2 * m + 1) * (2 * m) ^ (2 ^ s) ≤ 2 ^ m := by have h1 : 2 * m + 1 ≤ 2 ^ (2 * s + 1) := by rw [h2m, pow_succ] have : 1 ≤ 2 ^ (2 * s) := Nat.one_le_pow _ _ (by norm_num) omega have h2 : (2 * m) ^ (2 ^ s) = 2 ^ (2 * s * 2 ^ s) := by rw [h2m, ← pow_mul] calc (2 * m + 1) * (2 * m) ^ (2 ^ s) ≤ 2 ^ (2 * s + 1) * 2 ^ (2 * s * 2 ^ s) := by rw [h2]; exact Nat.mul_le_mul_right _ h1 _ = 2 ^ (2 * s + 1 + 2 * s * 2 ^ s) := by rw [← pow_add] _ ≤ 2 ^ m := Nat.pow_le_pow_right (by norm_num) (exp_bound_chebyshev s hs) have hfinal : 2 ^ m * 2 ^ m ≤ 2 ^ m * primorial (2 * m) := by calc 2 ^ m * 2 ^ m = 2 ^ (2 * m) := by rw [← pow_add, two_mul] _ ≤ (2 * m + 1) * (2 * m) ^ (2 ^ s) * primorial (2 * m) := h4m _ ≤ 2 ^ m * primorial (2 * m) := Nat.mul_le_mul_right _ hpref rw [← h2m] exact Nat.le_of_mul_le_mul_left hfinal (by positivity) /-- **Primorial `2^(n - 128 (log₂ n)² / log₂ log₂ n)` Theorem (Infinitely Many `n`)**: For every `s ≥ 5`, setting `k = primorial (2^(2s))` and `n = k + 3 * primeSum (2^(2s)) + 13`, we have `n ≥ 2^(2^(2s - 1))` (arbitrarily large), `Nat.log 2 (Nat.log 2 n) ≥ 1`, and for EVERY characteristic-zero semiring `R`, there exists a mortal pair `(M₀, M₁)` of `n × n` binary matrices over `R` whose shortest zero product has length at least `2 ^ (n - 128 * (Nat.log 2 n)^2 / Nat.log 2 (Nat.log 2 n))`. -/ theorem exists_mortal_binary_pair_primorial_gap (R : Type*) [Semiring R] [CharZero R] {s : ℕ} (hs : 5 ≤ s) : let N := 2 ^ (2 * s) let n := primorial N + 3 * primeSum N + 13 2 ^ (2 ^ (2 * s - 1)) ≤ n ∧ 1 ≤ Nat.log 2 (Nat.log 2 n) ∧ ∃ M₀ M₁ : Matrix (Fin n) (Fin n) R, IsMortalBinaryPairOver R n M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → 2 ^ (n - 128 * (Nat.log 2 n) ^ 2 / Nat.log 2 (Nat.log 2 n)) ≤ w.length := by intro N n have hN2 : 2 ≤ N := by dsimp [N] calc 2 = 2 ^ 1 := by norm_num _ ≤ 2 ^ (2 * s) := Nat.pow_le_pow_right (by norm_num) (by omega) have hk_lb : 2 ^ (2 ^ (2 * s - 1)) ≤ primorial N := chebyshev_primorial_lower_bound hs have hn_lb : 2 ^ (2 ^ (2 * s - 1)) ≤ n := le_trans hk_lb (by dsimp [n]; omega) -- Log lower bounds: `2^(2s-1) ≤ log₂ n` and `1 ≤ log₂ (log₂ n)`. have hlog_n_ge : 2 ^ (2 * s - 1) ≤ Nat.log 2 n := by rw [Nat.le_log_iff_pow_le (by norm_num : 1 < 2) (by have : 1 ≤ 2 ^ (2 ^ (2 * s - 1)) := Nat.one_le_pow _ _ (by norm_num); omega)] exact hn_lb have hloglog_ge1 : 1 ≤ Nat.log 2 (Nat.log 2 n) := by rw [Nat.le_log_iff_pow_le (by norm_num : 1 < 2) (by have : 1 ≤ 2 ^ (2 * s - 1) := Nat.one_le_pow _ _ (by norm_num); omega)] have : 2 ≤ 2 ^ (2 * s - 1) := by calc 2 = 2 ^ 1 := by norm_num _ ≤ 2 ^ (2 * s - 1) := Nat.pow_le_pow_right (by norm_num) (by omega) omega -- Upper bound on `primeSum N` via Chebyshev `2s * π(2^(2s)) ≤ 4 * 2^(2s)`. have hpi_ub : 2 * s * primeCount N ≤ 4 * N := chebyshev_primeCount_pow_two (2 * s) (by omega) have hsum_le : primeSum N ≤ N * primeCount N := by unfold primeSum primeCount calc ∑ p ∈ primesUpTo N, p ≤ ∑ _p ∈ primesUpTo N, N := Finset.sum_le_sum fun p hp => (mem_primesUpTo.1 hp).2 _ = N * (primesUpTo N).card := by simp [mul_comm] have hs_sum : s * primeSum N ≤ 2 * N * N := by have h1 : s * primeCount N ≤ 2 * N := by have h2 : 2 * (s * primeCount N) ≤ 2 * (2 * N) := by linarith exact Nat.le_of_mul_le_mul_left h2 (by norm_num) calc s * primeSum N ≤ s * (N * primeCount N) := Nat.mul_le_mul_left s hsum_le _ = N * (s * primeCount N) := by ring _ ≤ N * (2 * N) := Nat.mul_le_mul_left N h1 _ = 2 * N * N := by ring -- Upper bound on `n` and `Nat.log 2 (Nat.log 2 n) ≤ 4 * s`. have hsum_ge13 : 13 ≤ primeSum N := by have hsub : ({2, 3, 5, 7} : Finset ℕ) ⊆ primesUpTo N := by have hN16 : 16 ≤ N := by dsimp [N] calc 16 = 2 ^ 4 := by norm_num _ ≤ 2 ^ (2 * s) := Nat.pow_le_pow_right (by norm_num) (by omega) intro p hp simp only [Finset.mem_insert, Finset.mem_singleton] at hp rw [mem_primesUpTo] rcases hp with rfl | rfl | rfl | rfl <;> refine ⟨by decide, by omega⟩ have hsum17 : 17 ≤ ∑ p ∈ primesUpTo N, p := by have := Finset.sum_le_sum_of_subset (f := fun p : ℕ => p) hsub simpa using this unfold primeSum; omega have hgap_le_4sum : n - primorial N ≤ 4 * primeSum N := by dsimp [n]; omega have hk_ub : primorial N ≤ 2 ^ (2 * s * N) := by have hcard_le : primeCount N ≤ N := by unfold primeCount primesUpTo calc ((Finset.Icc 2 N).filter Nat.Prime).card ≤ (Finset.Icc 2 N).card := Finset.card_filter_le _ _ _ ≤ N := by rw [Nat.card_Icc]; omega calc primorial N ≤ ∏ _p ∈ primesUpTo N, N := Finset.prod_le_prod' fun p hp => (mem_primesUpTo.1 hp).2 _ = N ^ primeCount N := by simp [primeCount] _ ≤ N ^ N := Nat.pow_le_pow_right (by omega) hcard_le _ = 2 ^ (2 * s * N) := by dsimp [N]; rw [← pow_mul] have h4sum_le_k : 4 * primeSum N ≤ primorial N := by have h1 : 4 * primeSum N ≤ 8 * N * N := by have : 4 * (s * primeSum N) ≤ 4 * (2 * N * N) := Nat.mul_le_mul_left 4 hs_sum have : 4 * primeSum N ≤ s * (4 * primeSum N) := Nat.le_mul_of_pos_left _ (by omega) nlinarith have h2 : 8 * N * N ≤ 2 ^ (2 ^ (2 * s - 1)) := by have hNN : 8 * N * N = 2 ^ (4 * s + 3) := by dsimp [N] calc 8 * 2 ^ (2 * s) * 2 ^ (2 * s) = 2 ^ 3 * 2 ^ (2 * s) * 2 ^ (2 * s) := by norm_num _ = 2 ^ (3 + 2 * s + 2 * s) := by rw [← pow_add, ← pow_add] _ = 2 ^ (4 * s + 3) := by ring_nf rw [hNN] refine Nat.pow_le_pow_right (by norm_num) ?_ have hexp := exp_bound_chebyshev s hs have h2s : 32 ≤ 2 ^ s := by calc 32 = 2 ^ 5 := by norm_num _ ≤ 2 ^ s := Nat.pow_le_pow_right (by norm_num) hs nlinarith exact le_trans h1 (le_trans h2 hk_lb) have hn_lt_pow : n < 2 ^ (2 ^ (4 * s)) := by have hn_le : n ≤ 2 * primorial N := by dsimp [n]; omega have h2k : 2 * primorial N ≤ 2 ^ (2 * s * N + 1) := by calc 2 * primorial N ≤ 2 * 2 ^ (2 * s * N) := Nat.mul_le_mul_left 2 hk_ub _ = 2 ^ (2 * s * N + 1) := by rw [pow_succ, mul_comm] have hexp_lt : 2 * s * N + 1 < 2 ^ (4 * s) := by have h4s : 2 ^ (4 * s) = N * N := by dsimp [N]; rw [← pow_add]; congr 1; omega rw [h4s] have h2s_lt : 2 * s + 1 < N := by dsimp [N] have hlin : ∀ t : ℕ, t + 1 < 2 ^ t ∨ t ≤ 1 := by intro t; induction t with | zero => right; omega | succ t ih => rcases ih with h | h · left; rw [pow_succ]; omega · by_cases ht : t = 0 · right; omega · have ht1 : t = 1 := by omega subst ht1; left; norm_num rcases hlin (2 * s) with h | h <;> omega nlinarith exact lt_of_le_of_lt (le_trans hn_le h2k) (Nat.pow_lt_pow_right (by norm_num) hexp_lt) have hlog_n_lt : Nat.log 2 n < 2 ^ (4 * s) := nat_log_lt_of_lt_pow (by norm_num : 1 < 2) (by have : 1 ≤ 2 ^ (2 ^ (2 * s - 1)) := Nat.one_le_pow _ _ (by norm_num); omega) hn_lt_pow have hloglog_le : Nat.log 2 (Nat.log 2 n) ≤ 4 * s := by have hlt := nat_log_lt_of_lt_pow (by norm_num : 1 < 2) (by have : 1 ≤ 2 ^ (2 * s - 1) := Nat.one_le_pow _ _ (by norm_num); omega) hlog_n_lt omega -- Combine: `(n - k) * log₂(log₂ n) ≤ 128 * (log₂ n)^2`. have hN_eq : N = 2 * 2 ^ (2 * s - 1) := by dsimp [N] have hsub : 2 * s = (2 * s - 1) + 1 := by omega conv_lhs => rw [hsub] rw [pow_succ, mul_comm] have hgap_mul : (n - primorial N) * Nat.log 2 (Nat.log 2 n) ≤ 128 * (Nat.log 2 n) ^ 2 := by calc (n - primorial N) * Nat.log 2 (Nat.log 2 n) ≤ (4 * primeSum N) * (4 * s) := Nat.mul_le_mul hgap_le_4sum hloglog_le _ = 16 * (s * primeSum N) := by ring _ ≤ 16 * (2 * N * N) := Nat.mul_le_mul_left 16 hs_sum _ = 128 * (2 ^ (2 * s - 1)) ^ 2 := by rw [hN_eq]; ring _ ≤ 128 * (Nat.log 2 n) ^ 2 := Nat.mul_le_mul_left 128 (Nat.pow_le_pow_left hlog_n_ge 2) have hgap_div : n - primorial N ≤ 128 * (Nat.log 2 n) ^ 2 / Nat.log 2 (Nat.log 2 n) := (Nat.le_div_iff_mul_le (by omega)).2 hgap_mul have hk_ge_gap : n - 128 * (Nat.log 2 n) ^ 2 / Nat.log 2 (Nat.log 2 n) ≤ primorial N := by omega -- Instantiate the Master Coprime-Clock Theorem on `ms = (primesUpTo N).toList`. let ms := (primesUpTo N).toList have hprod_ms : ms.prod = primorial N := Finset.prod_toList _ have hsum_ms : ms.sum = primeSum N := Finset.sum_toList _ have hne_ms : ms ≠ [] := by intro hnil have h2mem : 2 ∈ primesUpTo N := mem_primesUpTo.2 ⟨Nat.prime_two, hN2⟩ have h2list : 2 ∈ ms := Finset.mem_toList.2 h2mem rw [hnil] at h2list exact List.not_mem_nil h2list have hge_ms : ∀ p ∈ ms, 2 ≤ p := by intro p hp exact (mem_primesUpTo.1 (Finset.mem_toList.1 hp)).1.two_le have hcop_ms : ms.Pairwise Nat.Coprime := by have hnodup : ms.Nodup := Finset.nodup_toList _ rw [List.pairwise_iff_getElem] intro i j hi hj hij have hpi : ms[i].Prime := (mem_primesUpTo.1 (Finset.mem_toList.1 (List.getElem_mem hi))).1 have hpj : ms[j].Prime := (mem_primesUpTo.1 (Finset.mem_toList.1 (List.getElem_mem hj))).1 have hne_ij : ms[i] ≠ ms[j] := by intro heq have hfin : (⟨i, hi⟩ : Fin ms.length) = ⟨j, hj⟩ := (List.nodup_iff_injective_getElem.1 hnodup) heq have hij_eq : i = j := congrArg Fin.val hfin omega exact (Nat.coprime_primes hpi hpj).2 hne_ij have hdim : ms.prod + 3 * ms.sum + 13 ≤ n := by rw [hprod_ms, hsum_ms] obtain ⟨M₀, M₁, hmortal, hlb⟩ := exists_mortal_binary_pair_coprime R hne_ms hge_ms hcop_ms hdim refine ⟨hn_lb, hloglog_ge1, M₀, M₁, hmortal, fun w hne_w hw0 => ?_⟩ have h1 := hlb w hne_w hw0 rw [hprod_ms] at h1 have hk2 : 2 ≤ primorial N := by have h2 : 2 ^ 1 ≤ 2 ^ (2 ^ (2 * s - 1)) := Nat.pow_le_pow_right (by norm_num) (Nat.one_le_pow _ _ (by norm_num)) omega have h2 : 2 ^ primorial N ≤ (primorial N + 4) * (2 ^ primorial N - 1) := by have hmul := mul_two_pow_le_lower_bound hk2 have hle : 2 ^ primorial N ≤ primorial N * 2 ^ primorial N := Nat.le_mul_of_pos_left _ (by omega) exact le_trans hle hmul exact le_trans (Nat.pow_le_pow_right (by norm_num) hk_ge_gap) (le_trans h2 h1) /-- Arbitrarily large dimensions `n` achieve the primorial `2^(n - 128 (log₂ n)² / log₂ log₂ n)` lower bound on `mt2 n`. -/ theorem mt2_primorial_gap_frequently : ∀ N₀ : ℕ, ∃ n : ℕ, N₀ ≤ n ∧ 1 ≤ Nat.log 2 (Nat.log 2 n) ∧ 2 ^ (n - 128 * (Nat.log 2 n) ^ 2 / Nat.log 2 (Nat.log 2 n)) ≤ mt2 n := by intro N₀ let s := max 5 (N₀ + 1) have hs : 5 ≤ s := le_max_left _ _ obtain ⟨hn_lb, hll, M₀, M₁, hm, hlb⟩ := exists_mortal_binary_pair_primorial_gap ℕ hs let N := 2 ^ (2 * s) let n := primorial N + 3 * primeSum N + 13 have hn_ge_N0 : N₀ ≤ n := by have h1 : N₀ ≤ 2 ^ (2 * s - 1) := by have : 2 * s - 1 ≥ N₀ := by omega exact le_trans this (Nat.lt_two_pow_self.le) exact le_trans h1 (le_trans Nat.lt_two_pow_self.le hn_lb) refine ⟨n, hn_ge_N0, hll, mt2_ge_of_pair ?_ M₀ M₁ hm hlb⟩ have : 1 ≤ 2 ^ (2 ^ (2 * s - 1)) := Nat.one_le_pow _ _ (by norm_num) omega end QuantitativeBounds /-! ## Section 7: Concrete World-Record Instantiations and Axiom Verification -/ section ConcreteRecords /-- At `n = 46` (from `ms = [3, 4]`), there exists a mortal pair of `46 × 46` binary matrices over any characteristic-zero semiring `R` whose shortest zero product has length at least `65520`, already beating Ryzhikov's June 2025 bound `2^((46-2)/3) < 26009`. -/ theorem record_dim_46 (R : Type*) [Semiring R] [CharZero R] : ∃ M₀ M₁ : Matrix (Fin 46) (Fin 46) R, IsMortalBinaryPairOver R 46 M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → 65520 ≤ w.length := by have h := exists_mortal_binary_pair_coprime R (ms := [3, 4]) (n := 46) (by decide) (by decide) (by decide) (by decide) simpa using h /-- At `n = 73` (from `ms = [2, 3, 5]`), there exists a mortal pair of `73 × 73` binary matrices over any characteristic-zero semiring `R` whose shortest zero product has length at least `34 * (2^30 - 1) = 36,507,221,982 > 2^35`, simultaneously surpassing BOTH Ryzhikov's `m = 2` bound (`2^(71/3) < 2^24`) AND Ryzhikov's `m = 3` bound (`2^(69/2) < 2^35`). -/ theorem record_dim_73 (R : Type*) [Semiring R] [CharZero R] : ∃ M₀ M₁ : Matrix (Fin 73) (Fin 73) R, IsMortalBinaryPairOver R 73 M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → 34 * (2 ^ 30 - 1) ≤ w.length := by have h := exists_mortal_binary_pair_coprime R (ms := [2, 3, 5]) (n := 73) (by decide) (by decide) (by decide) (by decide) simpa using h /-- At `n = 274` (from `ms = [2, 3, 5, 7]`), there exists a mortal pair of `274 × 274` binary matrices whose shortest zero product has length at least `214 * (2^210 - 1) > 2^217`. -/ theorem record_dim_274 (R : Type*) [Semiring R] [CharZero R] : ∃ M₀ M₁ : Matrix (Fin 274) (Fin 274) R, IsMortalBinaryPairOver R 274 M₀ M₁ ∧ ∀ w : List Bool, w ≠ [] → evalMat M₀ M₁ w = 0 → 214 * (2 ^ 210 - 1) ≤ w.length := by have h := exists_mortal_binary_pair_coprime R (ms := [2, 3, 5, 7]) (n := 274) (by decide) (by decide) (by decide) (by decide) simpa using h end ConcreteRecords end BinaryMatrixMortality #print axioms BinaryMatrixMortality.exists_mortal_binary_pair_coprime #print axioms BinaryMatrixMortality.exists_short_mortal_word_le_two_pow_sub_one #print axioms BinaryMatrixMortality.exists_mortal_binary_pair_sqrt_gap #print axioms BinaryMatrixMortality.mt2_le_two_pow_sub_one #print axioms BinaryMatrixMortality.mt2_sqrt_lower_bound #print axioms BinaryMatrixMortality.mt2_log2_div_tendsto_one #print axioms BinaryMatrixMortality.mt2_beats_any_sublinear_exponent #print axioms BinaryMatrixMortality.chebyshev_primeCount_pow_two #print axioms BinaryMatrixMortality.chebyshev_primorial_lower_bound #print axioms BinaryMatrixMortality.exists_mortal_binary_pair_primorial_gap #print axioms BinaryMatrixMortality.mt2_primorial_gap_frequently #print axioms BinaryMatrixMortality.record_dim_46 #print axioms BinaryMatrixMortality.record_dim_73 #print axioms BinaryMatrixMortality.record_dim_274