diff --git a/CLAUDE.md b/CLAUDE.md index 2bd340e9..074bd578 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -170,7 +170,7 @@ See CONTRIBUTING.md. Use `(): ` format with imperative moo ## Dependencies -- **Lean**: `leanprover/lean4:v4.30.0` (see `lean-toolchain`) -- **Mathlib**: `v4.30.0` (see `lakefile.toml`) +- **Lean**: `leanprover/lean4:v4.34.0-rc2` (see `lean-toolchain`) +- **Mathlib**: commit `e06eff5f` (see `lakefile.toml`) — pinned to match [cslib](https://github.com/leanprover/cslib)'s `lake-manifest.json` so the foundations can be rebased onto it When updating either, both must be updated in lockstep. diff --git a/Complexitylib/Asymptotics.lean b/Complexitylib/Asymptotics.lean index e5abbfd0..f32972de 100644 --- a/Complexitylib/Asymptotics.lean +++ b/Complexitylib/Asymptotics.lean @@ -7,6 +7,8 @@ Authors: Samuel Schlesinger module public import Mathlib.Analysis.Asymptotics.SpecificAsymptotics public import Mathlib.Data.Nat.Size +public import Mathlib.Algebra.Polynomial.Degree.Defs +public import Mathlib.Algebra.Polynomial.Eval.Degree /-! # Asymptotic notation for natural number functions @@ -103,6 +105,7 @@ theorem BigO.add {f₁ f₂ g : ℕ → ℕ} (h₁ : f₁ =O g) (h₂ : f₂ =O show (fun n => ((f₁ n + f₂ n : ℕ) : ℝ)) =O[atTop] _ have key := IsBigO.add h₁ h₂ convert key using 1 + · rfl ext n; push_cast; ring /-- Product of two big-O bounds: `f₁ = O(g₁) → f₂ = O(g₂) → (f₁·f₂) = O(g₁·g₂)`. -/ @@ -111,6 +114,8 @@ theorem BigO.mul {f₁ f₂ g₁ g₂ : ℕ → ℕ} (h₁ : f₁ =O g₁) (h₂ show (fun n => ((f₁ n * f₂ n : ℕ) : ℝ)) =O[atTop] (fun n => ((g₁ n * g₂ n : ℕ) : ℝ)) have key := IsBigO.mul h₁ h₂ convert key using 1 + · rfl + · rfl · ext n; push_cast; ring · ext n; push_cast; ring @@ -159,6 +164,7 @@ theorem LittleO.add {f₁ f₂ g : ℕ → ℕ} (h₁ : f₁ =o g) (h₂ : f₂ show (fun n => ((f₁ n + f₂ n : ℕ) : ℝ)) =o[atTop] _ have key := IsLittleO.add h₁ h₂ convert key using 1 + · rfl ext n; push_cast; ring /-- Constant multiple preserves little-o. -/ @@ -214,6 +220,7 @@ theorem BigO.const_mul_add (c : ℕ) {f₁ f₂ T₁ T₂ : ℕ → ℕ} (fun n => ((T₁ n + T₂ n : ℕ) : ℝ)) := IsBigO.trans ho₂ (le_add_right T₁ T₂) have := IsBigO.add hcf₁ hf₂ convert this using 1 + · rfl ext n; push_cast; ring -- ════════════════════════════════════════════════════════════════════════ diff --git a/Complexitylib/BooleanAnalysis/FourierExpansion.lean b/Complexitylib/BooleanAnalysis/FourierExpansion.lean index d836dd40..b291f7bd 100644 --- a/Complexitylib/BooleanAnalysis/FourierExpansion.lean +++ b/Complexitylib/BooleanAnalysis/FourierExpansion.lean @@ -227,7 +227,8 @@ theorem inner_eq_one_sub_two_dist (f g : BooleanFunction n) `𝔼[f] = 𝓕 f ∅`. -/ theorem expect_eq_fourierCoeff_empty (f : BooleanFunction n) : 𝔼[f] = 𝓕 f ∅ := by - simp [fourierCoeff, inner_eq_expect] + rw [fourierCoeff_eq_inner (f := f) (S := ∅), inner_eq_expect (f := f) (g := χ ∅)] + simp [Internal.parityFun_empty] /-- **Proposition 1.13**: The variance of `f` in terms of Fourier coefficients: `Var[f] = ∑_{S ≠ ∅} (𝓕 f S)²`. -/ @@ -250,7 +251,7 @@ theorem variance_boolean (f : BooleanFunction n) (hf : IsBooleanValued f) : Var[f] = 1 - (𝔼[f]) ^ 2 := by unfold variance have h1 : 𝔼[fun x => f x ^ 2] = 1 := by - simp only [expect_unfold] + rw [expect_unfold (f := fun x : Cube n => f x ^ 2)] have : ∀ x : Cube n, f x ^ 2 = 1 := by intro x; rcases hf x with h | h <;> simp [h] rw [Finset.sum_congr rfl (fun x _ => this x)] @@ -345,8 +346,10 @@ noncomputable def IsDensity.toPMF {φ : BooleanFunction n} (hφ : IsDensity φ) PMF (Cube n) := PMF.ofFintype (fun x => ENNReal.ofReal (φ x / 2 ^ n)) (by have hsum : ∑ x : Cube n, φ x / 2 ^ n = 1 := by - simp_rw [div_eq_mul_inv, ← Finset.sum_mul] - have h := hφ.expect_one; simp only [expect_unfold] at h + simp_rw [div_eq_mul_inv] + rw [← Finset.sum_mul (s := Finset.univ) (f := fun x : Cube n => φ x) + (a := ((2 : ℝ) ^ n)⁻¹)] + have h := hφ.expect_one; rw [expect_unfold (f := φ)] at h have h2n : (0 : ℝ) < 2 ^ n := pow_pos two_pos n rw [show (∑ x : Cube n, φ x) * (2 ^ n)⁻¹ = 1 / 2 ^ n * ∑ x, φ x from by ring] linarith @@ -499,7 +502,10 @@ theorem fourierCoeff_parityFun (S T : Finset (Fin n)) : theorem fourierCoeff_parityFun_mul (S : Finset (Fin n)) (g : BooleanFunction n) (T : Finset (Fin n)) : 𝓕 (fun x => (χ S) x * g x) T = 𝓕 g (symmDiff S T) := by - rw [fourierCoeff_eq_inner, inner_eq_expect, fourierCoeff_eq_inner, inner_eq_expect] + rw [fourierCoeff_eq_inner (f := fun x : Cube n => (χ S) x * g x) (S := T), + inner_eq_expect (f := fun x : Cube n => (χ S) x * g x) (g := χ T), + fourierCoeff_eq_inner (f := g) (S := symmDiff S T), + inner_eq_expect (f := g) (g := χ (symmDiff S T))] refine Finset.expect_congr rfl fun x _ => ?_ rw [← parityFun_mul]; ring @@ -548,8 +554,8 @@ theorem degreePart_inner_eq_zero (f g : BooleanFunction n) {j k : ℕ} (hjk : j intro S _ rw [fourierCoeff_degreePart, fourierCoeff_degreePart] by_cases hj : S.card = j - · rw [if_neg (show ¬ S.card = k by omega), mul_zero] - · rw [if_neg hj, zero_mul] + · rw [ite_eq_right (show ¬ S.card = k by omega), mul_zero] + · rw [ite_eq_right hj, zero_mul] /-- **The degree-`k` weight is the squared length of the degree-`k` part.** `⟪f^{=k}, f^{=k}⟫ = 𝐖 f k = ∑_{|S|=k} (𝓕 f S)²` — Parseval restricted to level @@ -811,8 +817,8 @@ theorem fourierCoeff_noiseOp (ρ : ℝ) (f : BooleanFunction n) (T : Finset (Fin rw [noiseOp, fourierCoeff_eq_inner, sum_inner] simp only [real_inner_smul_left, ← fourierCoeff_eq_inner, fourierCoeff_parityFun] rw [Finset.sum_eq_single T] - · rw [if_pos rfl, mul_one] - · intro S _ hST; rw [if_neg hST, mul_zero] + · rw [ite_eq_left rfl, mul_one] + · intro S _ hST; rw [ite_eq_right hST, mul_zero] · intro h; exact absurd (Finset.mem_univ T) h /-- **Noise stability is the correlation of `f` with its noised copy**: @@ -837,8 +843,8 @@ theorem noiseOp_zero (f : BooleanFunction n) : fourierCoeff_ext fun S => by rw [fourierCoeff_noiseOp, fourierCoeff_smul, fourierCoeff_parityFun] by_cases hS : S = ∅ - · subst hS; rw [if_pos rfl, expect_eq_fourierCoeff_empty]; simp - · rw [if_neg (Ne.symm hS)] + · subst hS; rw [ite_eq_left rfl, expect_eq_fourierCoeff_empty]; simp + · rw [ite_eq_right (Ne.symm hS)] have hc : S.card ≠ 0 := by simp [Finset.card_eq_zero, hS] rw [zero_pow hc]; ring @@ -1020,7 +1026,7 @@ theorem totalInfluence_parityFun (S : Finset (Fin n)) : simp only [totalInfluence, fourierCoeff_parityFun] rw [Finset.sum_eq_single S] · simp - · intro T _ hT; rw [if_neg (Ne.symm hT)]; simp + · intro T _ hT; rw [ite_eq_right (Ne.symm hT)]; simp · intro h; exact absurd (Finset.mem_univ S) h /-- **Coordinate influence of a parity.** Coordinate `i` influences `χ_S` fully @@ -1099,12 +1105,12 @@ theorem parityFun_flipCoord (i : Fin n) (S : Finset (Fin n)) (x : Cube n) : (χ S) (flipCoord i x) = (if i ∈ S then -1 else 1) * (χ S) x := by simp only [parityFun, flipCoord] by_cases hi : i ∈ S - · rw [if_pos hi, ← Finset.prod_erase_mul S _ hi, ← Finset.prod_erase_mul S _ hi, + · rw [ite_eq_left hi, ← Finset.prod_erase_mul S _ hi, ← Finset.prod_erase_mul S _ hi, Function.update_self] have hrest : ∀ j ∈ S.erase i, chi (Function.update x i (x i + 1) j) = chi (x j) := by intro j hj; rw [Function.update_of_ne (Finset.ne_of_mem_erase hj)] rw [Finset.prod_congr rfl hrest, chi_add_one]; ring - · rw [if_neg hi, one_mul] + · rw [ite_eq_right hi, one_mul] apply Finset.prod_congr rfl intro j hj; rw [Function.update_of_ne (ne_of_mem_of_not_mem hj hi)] @@ -1129,7 +1135,8 @@ theorem expect_flipCoord (i : Fin n) (g : Cube n → ℝ) : `𝓕(f ∘ flipᵢ, T) = (−1)^[i∈T] · 𝓕(f, T)`. -/ theorem fourierCoeff_comp_flipCoord (i : Fin n) (f : BooleanFunction n) (T : Finset (Fin n)) : 𝓕 (fun x => f (flipCoord i x)) T = (if i ∈ T then -1 else 1) * 𝓕 f T := by - rw [fourierCoeff_eq_inner, inner_eq_expect, + rw [fourierCoeff_eq_inner (f := fun x : Cube n => f (flipCoord i x)) (S := T), + inner_eq_expect (f := fun x : Cube n => f (flipCoord i x)) (g := χ T), ← expect_flipCoord i (fun x => f (flipCoord i x) * (χ T) x)] simp only [flipCoord_flipCoord, parityFun_flipCoord] rw [fourierCoeff_eq_inner, inner_eq_expect] @@ -1150,18 +1157,18 @@ theorem fourierCoeff_derivative (i : Fin n) (f : BooleanFunction n) (T : Finset rw [derivative, fourierCoeff_eq_inner, sum_inner] simp only [real_inner_smul_left, ← fourierCoeff_eq_inner, fourierCoeff_parityFun] by_cases hiT : i ∈ T - · rw [if_pos hiT] + · rw [ite_eq_left hiT] apply Finset.sum_eq_zero intro S hS rw [Finset.mem_filter] at hS have hne : S.erase i ≠ T := fun h => (Finset.mem_erase.mp (h ▸ hiT)).1 rfl - rw [if_neg hne, mul_zero] - · rw [if_neg hiT, Finset.sum_eq_single (insert i T)] - · rw [Finset.erase_insert hiT, if_pos rfl, mul_one] + rw [ite_eq_right hne, mul_zero] + · rw [ite_eq_right hiT, Finset.sum_eq_single (insert i T)] + · rw [Finset.erase_insert hiT, ite_eq_left rfl, mul_one] · intro S hS hSne rw [Finset.mem_filter] at hS have hne : S.erase i ≠ T := fun h => hSne (by rw [← h, Finset.insert_erase hS.2]) - rw [if_neg hne, mul_zero] + rw [ite_eq_right hne, mul_zero] · intro h exact absurd (Finset.mem_filter.mpr ⟨Finset.mem_univ (insert i T), Finset.mem_insert_self i T⟩) h @@ -1177,7 +1184,7 @@ theorem influence_eq_norm_sq_derivative (i : Fin n) (f : BooleanFunction n) : apply Finset.sum_eq_zero intro T hT rw [Finset.mem_filter] at hT - rw [fourierCoeff_derivative, if_pos hT.2]; simp + rw [fourierCoeff_derivative, ite_eq_left hT.2]; simp rw [h1, zero_add] apply Finset.sum_nbij' (fun S => S.erase i) (fun T => insert i T) · intro S hS; rw [Finset.mem_filter] at hS ⊢; exact ⟨Finset.mem_univ _, by simp⟩ @@ -1187,7 +1194,7 @@ theorem influence_eq_norm_sq_derivative (i : Fin n) (f : BooleanFunction n) : · intro T hT; rw [Finset.mem_filter] at hT; rw [Finset.erase_insert hT.2] · intro S hS rw [Finset.mem_filter] at hS - rw [fourierCoeff_derivative, if_neg (by simp : i ∉ S.erase i), Finset.insert_erase hS.2] + rw [fourierCoeff_derivative, ite_eq_right (by simp : i ∉ S.erase i), Finset.insert_erase hS.2] /-- The **sensitivity operator** `Lᵢ f` at coordinate `i`, the point-value analogue of the derivative: `(Lᵢ f)(x) = (f(x) − f(x ⊕ eᵢ)) / 2`. It vanishes exactly where `f` @@ -1202,15 +1209,18 @@ theorem fourierCoeff_sensitivityOp (i : Fin n) (f : BooleanFunction n) (T : Fins 𝓕 (sensitivityOp i f) T = if i ∈ T then 𝓕 f T else 0 := by have key : 𝓕 (sensitivityOp i f) T = (1 / 2) * 𝓕 f T - (1 / 2) * 𝓕 (fun x => f (flipCoord i x)) T := by - rw [fourierCoeff_eq_inner, inner_eq_expect, fourierCoeff_eq_inner f, inner_eq_expect, - fourierCoeff_eq_inner (fun x => f (flipCoord i x)), inner_eq_expect] + rw [fourierCoeff_eq_inner (f := sensitivityOp i f) (S := T), + inner_eq_expect (f := sensitivityOp i f) (g := χ T), + fourierCoeff_eq_inner (f := f) (S := T), inner_eq_expect (f := f) (g := χ T), + fourierCoeff_eq_inner (f := fun x : Cube n => f (flipCoord i x)) (S := T), + inner_eq_expect (f := fun x : Cube n => f (flipCoord i x)) (g := χ T)] simp only [expect, sensitivityOp] rw [Finset.mul_expect, Finset.mul_expect, ← Finset.expect_sub_distrib] exact Finset.expect_congr rfl (fun x _ => by ring) rw [key, fourierCoeff_comp_flipCoord] by_cases h : i ∈ T - · rw [if_pos h, if_pos h]; ring - · rw [if_neg h, if_neg h]; ring + · rw [ite_eq_left h, ite_eq_left h]; ring + · rw [ite_eq_right h, ite_eq_right h]; ring /-- **Influence is the squared norm of the sensitivity operator**: `Infᵢ[f] = ‖Lᵢ f‖²`. A second analytic form of coordinate influence, complementing @@ -1221,8 +1231,8 @@ theorem influence_eq_norm_sq_sensitivityOp (i : Fin n) (f : BooleanFunction n) : refine Finset.sum_congr rfl fun S _ => ?_ rw [fourierCoeff_sensitivityOp] by_cases h : i ∈ S - · rw [if_pos h, if_pos h] - · rw [if_neg h, if_neg h]; ring + · rw [ite_eq_left h, ite_eq_left h] + · rw [ite_eq_right h, ite_eq_right h]; ring /-- **The sensitivity operator is the parity-twisted derivative**: `Lᵢ f = χ_{i} · Dᵢ f`. Both strip coordinate `i` from the surviving frequencies, but `Lᵢ` twists each back @@ -1246,12 +1256,12 @@ theorem sensitivityOp_eq_parityFun_mul_derivative (i : Fin n) (f : BooleanFuncti intro T rw [fourierCoeff_sensitivityOp, fourierCoeff_parityFun_mul, fourierCoeff_derivative] by_cases hiT : i ∈ T - · rw [if_pos hiT] + · rw [ite_eq_left hiT] have h1 : i ∉ symmDiff ({i} : Finset (Fin n)) T := by simp [Finset.mem_symmDiff, hiT] - rw [if_neg h1, hins T hiT] - · rw [if_neg hiT] + rw [ite_eq_right h1, hins T hiT] + · rw [ite_eq_right hiT] have h2 : i ∈ symmDiff ({i} : Finset (Fin n)) T := by simp [Finset.mem_symmDiff, hiT] - rw [if_pos h2] + rw [ite_eq_left h2] /-- **Average sensitivity as a probability.** For a Boolean-valued `f`, the influence of coordinate `i` is the probability that flipping `i` flips the output: diff --git a/Complexitylib/BooleanAnalysis/FourierExpansion/Defs.lean b/Complexitylib/BooleanAnalysis/FourierExpansion/Defs.lean index c4c0d413..d483abc9 100644 --- a/Complexitylib/BooleanAnalysis/FourierExpansion/Defs.lean +++ b/Complexitylib/BooleanAnalysis/FourierExpansion/Defs.lean @@ -79,7 +79,7 @@ instance : Inhabited (BooleanFunction n) := inferInstanceAs (Inhabited (Cube n instance : FunLike (BooleanFunction n) (Cube n) ℝ where coe f := f - coe_injective' f g h := show (f : Cube n → ℝ) = g from h + coe_injective f g h := show (f : Cube n → ℝ) = g from h @[ext] theorem ext {f g : BooleanFunction n} (h : ∀ x, f x = g x) : f = g := @@ -242,13 +242,14 @@ scoped notation "𝓕" => fourierCoeff /-- Unfold `𝔼[f]` to the explicit sum form `1/2^n · ∑_x f(x)`. -/ theorem expect_unfold (f : BooleanFunction n) : 𝔼[f] = 1 / 2 ^ n * ∑ x : Cube n, f x := by - simp [expect, Finset.expect_eq_sum_div_card, Finset.card_univ, ZMod.card]; ring + rw [expect, Finset.expect_eq_sum_div_card (f := (f : Cube n → ℝ))] + simp [Finset.card_univ, ZMod.card]; ring /-- The inner product equals the expectation of the product. This is the book's Definition 1.3: `⟪f, g⟫ = 𝔼[f·g]`. -/ theorem inner_eq_expect (f g : BooleanFunction n) : ⟪f, g⟫ = 𝔼[fun x => f x * g x] := by - simp [inner_def, expect_unfold] + simp [inner_def, expect, Finset.expect_eq_sum_div_card, div_eq_inv_mul] /-! ### §1.4 Mean, variance, covariance -/ diff --git a/Complexitylib/BooleanAnalysis/FourierExpansion/Internal.lean b/Complexitylib/BooleanAnalysis/FourierExpansion/Internal.lean index 88e00a6f..987ddbc2 100644 --- a/Complexitylib/BooleanAnalysis/FourierExpansion/Internal.lean +++ b/Complexitylib/BooleanAnalysis/FourierExpansion/Internal.lean @@ -102,7 +102,7 @@ theorem parityFun_zero (S : Finset (Fin n)) : (χ S) 0 = 1 := by theorem expect_parityFun_proof (S : Finset (Fin n)) : 𝔼[χ S] = if S = ∅ then 1 else 0 := by split_ifs with h - · subst h; simp [expect_unfold, parityFun_empty, Fintype.card_fin, ZMod.card] + · subst h; simp [parityFun_empty, expect, Finset.expect_const] · simp only [expect_unfold] obtain ⟨j, hj⟩ := Finset.nonempty_of_ne_empty h let ej : Cube n := Pi.single j 1 @@ -114,11 +114,12 @@ theorem expect_parityFun_proof (S : Finset (Fin n)) : simp [hj] suffices ∑ x : Cube n, (χ S) x = 0 by rw [this, mul_zero] have hself : ∑ x : Cube n, (χ S) x = -(∑ x : Cube n, (χ S) x) := by - conv_lhs => - rw [Fintype.sum_equiv (Equiv.addRight ej) _ (fun y => -(χ S) y) (fun x => by + have key : ∑ x : Cube n, (χ S) x = ∑ y : Cube n, -(χ S) y := + Fintype.sum_equiv (Equiv.addRight ej) _ (fun y => -(χ S) y) (fun x => by show (χ S) x = -(χ S) (x + ej) - rw [parityFun_add, hej, mul_neg_one, neg_neg])] - rw [Finset.sum_neg_distrib] + rw [parityFun_add, hej, mul_neg_one, neg_neg]) + conv_lhs => rw [key] + exact Finset.sum_neg_distrib (f := fun x : Cube n => (χ S) x) linarith /-- **Definition 1.11** (explicit form): For Boolean-valued `f`, @@ -179,7 +180,6 @@ theorem parityFun_mul (S T : Finset (Fin n)) (x : Cube n) : have hsd : (S ∪ T) \ (S ∩ T) = symmDiff S T := by ext i; simp [Finset.mem_symmDiff]; tauto rw [hsd] at hsdiff - simp only [] at hsdiff have hunion := Finset.prod_union_inter (s₁ := S) (s₂ := T) (f := fun i => chi (x i)) have hchi_sq : (∏ i ∈ S ∩ T, chi (x i)) ^ 2 = 1 := by rw [← Finset.prod_pow]; simp [chi_sq] @@ -244,7 +244,7 @@ theorem fourier_expansion_proof (f : BooleanFunction n) (x : Cube n) : rw [parityFun_add]; ring] rw [Finset.sum_comm] simp_rw [← Finset.mul_sum, sum_parityFun, hadd_zero, mul_ite, mul_zero] - rw [Finset.sum_ite_eq' Finset.univ x, if_pos (Finset.mem_univ _)] + rw [Finset.sum_ite_eq' Finset.univ x, ite_eq_left (Finset.mem_univ _)] field_simp /-- **Fourier uniqueness**: If `f(x) = ∑_S c_S · χ_S(x)` for all `x`, @@ -277,8 +277,8 @@ theorem fourier_uniqueness_proof (f : BooleanFunction n) (c : Finset (Fin n) → c S * (1 / (2 : ℝ) ^ n * ∑ x : Cube n, (χ S) x * (χ T) x) = c S * (if S = T then 1 else 0) := by intro S; congr 1 - have := key S; simp only [expect_unfold] at this; exact this - simp_rw [step4, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, if_true] + have := key S; rw [expect_unfold (f := fun x : Cube n => (χ S) x * (χ T) x)] at this; exact this + simp_rw [step4, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, ite_true] /-! ### Orthonormal basis of parity functions @@ -361,10 +361,10 @@ theorem cube_add_right_cancel (z y : Cube n) : z + y + y = z := by /-- `setDensity {0}` evaluates to `2^n` at `0` and `0` elsewhere. -/ theorem setDensity_singleton_zero_ite (y : Cube n) : setDensity ({0} : Finset (Cube n)) y = if y = 0 then (2 : ℝ) ^ n else 0 := by - unfold setDensity indicator; simp only [expect_unfold] + unfold setDensity indicator simp only [Finset.mem_singleton] split_ifs with hy - · subst hy; simp only [Finset.sum_ite_eq', Finset.mem_univ, if_true]; field_simp + · subst hy; simp [expect, Finset.expect_eq_sum_div_card, Finset.card_univ, ZMod.card] · ring /-- `setDensity {0}` equals the sum of all parity functions. -/ @@ -373,10 +373,10 @@ theorem setDensity_singleton_zero_proof : ∑ S : Finset (Fin n), (χ S) y := by intro y unfold setDensity - rw [sum_parityFun]; unfold indicator; simp only [expect_unfold] + rw [sum_parityFun]; unfold indicator simp only [Finset.mem_singleton] split_ifs with hy - · subst hy; simp only [Finset.sum_ite_eq', Finset.mem_univ, if_true]; field_simp + · subst hy; simp [expect, Finset.expect_eq_sum_div_card, Finset.card_univ, ZMod.card] · ring /-- Every Fourier coefficient of `setDensity {0}` is `1`. -/ @@ -385,7 +385,7 @@ theorem fourierCoeff_setDensity_singleton_zero_proof (S : Finset (Fin n)) : simp only [fourierCoeff, inner_def] simp_rw [setDensity_singleton_zero_ite] simp_rw [ite_mul, zero_mul] - rw [Finset.sum_ite_eq', if_pos (Finset.mem_univ _)] + rw [Finset.sum_ite_eq', ite_eq_left (Finset.mem_univ _)] simp [parityFun_zero] /-- The convolution of two densities is again a density. -/ @@ -394,12 +394,16 @@ theorem convolution_density_isDensity_proof (φ ψ : BooleanFunction n) IsDensity (φ ⊛ ψ) := by constructor · intro x - simp only [convolution, expect_unfold] + simp only [convolution] apply mul_nonneg · positivity · apply Finset.sum_nonneg; intro y _ exact mul_nonneg (hφ.nonneg y) (hψ.nonneg (x + y)) · simp only [convolution, expect_unfold] + have hinner : ∀ x : Cube n, 𝔼[fun y => φ y * ψ (x + y)] + = 1 / 2 ^ n * ∑ y : Cube n, φ y * ψ (x + y) := + fun x => expect_unfold (f := fun y : Cube n => φ y * ψ (x + y)) + simp only [hinner] have hshift : ∀ y : Cube n, ∑ x : Cube n, ψ (x + y) = ∑ x : Cube n, ψ x := by intro y; exact Equiv.sum_comp (Equiv.addRight y) ψ rw [show (1 : ℝ) / 2 ^ n * ∑ x, 1 / 2 ^ n * ∑ y, φ y * ψ (x + y) = @@ -408,16 +412,23 @@ theorem convolution_density_isDensity_proof (φ ψ : BooleanFunction n) rw [Finset.sum_comm] have h1 : ∀ y : Cube n, ∑ x : Cube n, φ y * ψ (x + y) = φ y * ∑ x : Cube n, ψ x := by intro y; rw [← Finset.mul_sum]; congr 1; exact hshift y - simp_rw [h1, ← Finset.sum_mul] + simp_rw [h1] + rw [← Finset.sum_mul (s := Finset.univ) (f := fun x : Cube n => φ x) + (a := ∑ x : Cube n, ψ x)] have hφ1 := hφ.expect_one have hψ1 := hψ.expect_one - simp only [expect_unfold] at hφ1 hψ1 + rw [expect_unfold (f := φ)] at hφ1 + rw [expect_unfold (f := ψ)] at hψ1 nlinarith /-- The convolution theorem: `𝓕 (f ⊛ g) S = (𝓕 f S) · (𝓕 g S)`. -/ theorem fourierCoeff_convolution_proof (f g : BooleanFunction n) (S : Finset (Fin n)) : 𝓕 (f ⊛ g) S = (𝓕 f S) * (𝓕 g S) := by - simp only [fourierCoeff, inner_def, convolution, expect_unfold] + simp only [fourierCoeff, inner_def, convolution] + have hconv : ∀ x : Cube n, 𝔼[fun y => f y * g (x + y)] + = 1 / 2 ^ n * ∑ y : Cube n, f y * g (x + y) := + fun x => expect_unfold (f := fun y : Cube n => f y * g (x + y)) + simp only [hconv] have hinner : ∀ y : Cube n, ∑ x : Cube n, g (x + y) * (χ S) x = (χ S) y * ∑ z : Cube n, g z * (χ S) z := by intro y @@ -562,7 +573,15 @@ theorem blr_indicator_eq (f : BooleanFunction n) (hf : IsBooleanValued f) (x y : /-- `𝔼_x[𝔼_y[f(x)·f(y)·f(x+y)]] = ⟪f, f ⊛ f⟫`. -/ theorem triple_expect_eq (f : BooleanFunction n) : 𝔼[fun x => 𝔼[fun y => f x * f y * f (x + y)]] = ⟪f, f ⊛ f⟫ := by - simp only [inner_def, convolution, expect_unfold] + simp only [inner_def, convolution] + have hi1 : ∀ x : Cube n, 𝔼[fun y => f x * f y * f (x + y)] + = 1 / 2 ^ n * ∑ y : Cube n, f x * f y * f (x + y) := + fun x => expect_unfold (f := fun y : Cube n => f x * f y * f (x + y)) + have hi2 : ∀ x : Cube n, 𝔼[fun y => f y * f (x + y)] + = 1 / 2 ^ n * ∑ y : Cube n, f y * f (x + y) := + fun x => expect_unfold (f := fun y : Cube n => f y * f (x + y)) + rw [expect_unfold (f := fun x : Cube n => 𝔼[fun y => f x * f y * f (x + y)])] + simp only [hi1, hi2] congr 1; apply Finset.sum_congr rfl; intro x _ simp_rw [show ∀ y : Cube n, f x * f y * f (x + y) = f x * (f y * f (x + y)) from fun y => by ring, @@ -577,7 +596,10 @@ theorem inner_conv_eq_sum_cube (f : BooleanFunction n) : /-- Linearity of expectation: `𝔼[c + g] = c + 𝔼[g]`. -/ theorem expect_add_const (c : ℝ) (g : BooleanFunction n) : 𝔼[fun x => c + g x] = c + 𝔼[g] := by - simp only [expect, Finset.expect_add_distrib, Fintype.expect_const] + rw [expect_unfold (f := fun x : Cube n => c + g x), expect_unfold (f := g), + Finset.sum_add_distrib (f := fun _ : Cube n => c) (g := fun x : Cube n => g x)] + simp [Finset.card_univ, ZMod.card] + field_simp /-- Linearity of expectation: `𝔼[c · g] = c · 𝔼[g]`. -/ theorem expect_scale (c : ℝ) (g : BooleanFunction n) : @@ -593,15 +615,22 @@ theorem blrAcceptProb_eq_proof (f : BooleanFunction n) (hf : IsBooleanValued f) 𝔼[𝟙 (fun y => f x * f y = f (x + y))] = 1 / 2 + 1 / 2 * 𝔼[fun y => f x * f y * f (x + y)] by simp_rw [hstep] - rw [expect_add_const, expect_scale] + rw [expect_add_const (c := 1 / 2) + (g := fun x : Cube n => 1 / 2 * 𝔼[fun y => f x * f y * f (x + y)]), + expect_scale (c := 1 / 2) + (g := fun x : Cube n => 𝔼[fun y => f x * f y * f (x + y)])] intro x rw [show 𝔼[𝟙 (fun y => f x * f y = f (x + y))] = 𝔼[fun y => (1 + f x * f y * f (x + y)) / 2] from by - simp only [expect_unfold]; congr 1; apply Finset.sum_congr rfl; intro y _ + rw [expect_unfold (f := 𝟙 (fun y : Cube n => f x * f y = f (x + y))), + expect_unfold (f := fun y : Cube n => (1 + f x * f y * f (x + y)) / 2)] + congr 1; apply Finset.sum_congr rfl; intro y _ exact blr_indicator_eq f hf x y, show (fun y : Cube n => (1 + f x * f y * f (x + y)) / 2) = (fun y => 1/2 + 1/2 * (f x * f y * f (x + y))) from by ext y; ring] - rw [expect_add_const, expect_scale] + rw [expect_add_const (c := 1 / 2) + (g := fun y : Cube n => 1 / 2 * (f x * f y * f (x + y))), + expect_scale (c := 1 / 2) (g := fun y : Cube n => f x * f y * f (x + y))] /-- **BLR completeness**: If `f` is linear (i.e., `f = χ_S` for some `S`), then the BLR test accepts with probability 1. -/ @@ -615,8 +644,8 @@ theorem blr_completeness_proof (f : BooleanFunction n) (hf : IsLinear f) : intro x have : (𝟙 (fun y => f x * f y = f (x + y)) : BooleanFunction n) = fun _ => 1 := by ext y; simp [indicator, hev x y] - rw [this]; simp [expect_unfold, Fintype.card_fin, ZMod.card] - simp_rw [hind]; simp [expect_unfold, Fintype.card_fin, ZMod.card] + rw [this]; simp [expect, Finset.expect_const] + simp_rw [hind]; simp [expect, Finset.expect_const] /-- BLR soundness: if the BLR test accepts with probability `≥ 1 - ε`, then `f` is `ε`-close to a linear function. -/ @@ -772,8 +801,8 @@ theorem fourierCoeff_setDensity_proof (A : Finset (Cube n)) (hA : A.Nonempty) 1 / (↑A.card / 2 ^ n) * (𝟙 (· ∈ A)) x * (χ S) x = 1 / (↑A.card / 2 ^ n) * (if x ∈ A then (χ S) x else 0) from by intro x; unfold indicator; split_ifs <;> ring] - rw [← Finset.mul_sum, Finset.sum_ite, Finset.sum_const_zero, add_zero, - Finset.filter_mem_eq_inter, Finset.univ_inter] + rw [← Finset.mul_sum, ← Finset.sum_filter (p := fun x : Cube n => x ∈ A) + (f := fun x : Cube n => (χ S) x), Finset.filter_mem_eq_inter, Finset.univ_inter] field_simp end BooleanAnalysis.Internal diff --git a/Complexitylib/Circuits/AC0/Iteration/Internal.lean b/Complexitylib/Circuits/AC0/Iteration/Internal.lean index 4794a978..49e0198c 100644 --- a/Complexitylib/Circuits/AC0/Iteration/Internal.lean +++ b/Complexitylib/Circuits/AC0/Iteration/Internal.lean @@ -23,6 +23,11 @@ namespace Complexity namespace Switching +attribute [local instance] Classical.propDecidable + +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private def finiteEventCount {α : Type} [Fintype α] [DecidableEq α] (event : α → Prop) [DecidablePred event] : ℕ := @@ -128,6 +133,9 @@ private theorem finiteEventCount_prod_left _ = finiteEventCount event * Fintype.card β := by simp [finiteEventCount] +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private theorem finiteEventCount_exists_mem_le_sum {α β : Type} [Fintype α] [DecidableEq α] [DecidableEq β] (values : List β) @@ -249,7 +257,7 @@ private theorem sum_comp_freeVariables_internal intro index _ by_cases hprior : prior index = none · simp only [Restriction.On.comp, hprior, - Option.none_or, if_pos] + Option.none_or, ite_eq_left] calc (∑ seed : Seed N q, if decode seed index = none then 1 else 0) = @@ -297,6 +305,7 @@ theorem stageFreeSum_internal (N q stageCount : ℕ) : simp [stageFreeSum, StageSeed, finalRestriction, Switching.RestrictionStages.cumulative, Restriction.On.freeVariables] + erw [Finset.card_univ, Fintype.card_unit, one_mul] | succ stageCount ih => rw [stageFreeSum_succ_internal, ih, pow_succ] simp [Nat.mul_assoc] @@ -794,8 +803,13 @@ theorem stageEventCount_stagedBad_mul_pow_le_internal RandomRestriction.StageSeed N q stageCount × RandomRestriction.Seed N q => switchGood pair.1 pair.2) - change Switching.finiteEventCount rootEvent * - q ^ queryCount ≤ + have hEq : RandomRestriction.stageEventCount (N := N) (stageCount := stageCount + 1) q + ((and children).stagedBad queryCount) = Switching.finiteEventCount rootEvent := by + unfold RandomRestriction.stageEventCount Switching.finiteEventCount + congr 1 + congr 1 + rw [hEq] + show _ ≤ (1 + forestSize children) * ((2 * q + 1) ^ N) ^ (stageCount + 1) * (4 * (queryCount + 1)) ^ queryCount @@ -1050,8 +1064,13 @@ theorem stageEventCount_stagedBad_mul_pow_le_internal RandomRestriction.StageSeed N q stageCount × RandomRestriction.Seed N q => switchGood pair.1 pair.2) - change Switching.finiteEventCount rootEvent * - q ^ queryCount ≤ + have hEq : RandomRestriction.stageEventCount (N := N) (stageCount := stageCount + 1) q + ((or children).stagedBad queryCount) = Switching.finiteEventCount rootEvent := by + unfold RandomRestriction.stageEventCount Switching.finiteEventCount + congr 1 + congr 1 + rw [hEq] + show _ ≤ (1 + forestSize children) * ((2 * q + 1) ^ N) ^ (stageCount + 1) * (4 * (queryCount + 1)) ^ queryCount diff --git a/Complexitylib/Circuits/AC0/Normalization/Internal.lean b/Complexitylib/Circuits/AC0/Normalization/Internal.lean index 2731d131..57032c5b 100644 --- a/Complexitylib/Circuits/AC0/Normalization/Internal.lean +++ b/Complexitylib/Circuits/AC0/Normalization/Internal.lean @@ -195,7 +195,7 @@ private theorem signedSupport_eval | false => cases hop : gate.op with | and => - simp only [AndOrOp.dualIf, Bool.false_eq_true, if_false, + simp only [AndOrOp.dualIf, Bool.false_eq_true, ite_false, Gate.signedSupport] have hsupport := image_attach_all (fun input : Fin gate.fanIn => @@ -207,7 +207,7 @@ private theorem signedSupport_eval Basis.unboundedAndOr, hop] rfl | or => - simp only [AndOrOp.dualIf, Bool.false_eq_true, if_false, + simp only [AndOrOp.dualIf, Bool.false_eq_true, ite_false, Gate.signedSupport] have hsupport := image_attach_any (fun input : Fin gate.fanIn => @@ -228,7 +228,7 @@ private theorem signedSupport_eval cases wireValue (gate.inputs input) <;> rfl cases hop : gate.op with | and => - simp only [AndOrOp.dualIf, if_true, AndOrOp.dual, + simp only [AndOrOp.dualIf, ite_true, AndOrOp.dual, Gate.signedSupport] have hsupport := image_attach_any (fun input : Fin gate.fanIn => @@ -242,7 +242,7 @@ private theorem signedSupport_eval rw [foldl_or_not] rfl | or => - simp only [AndOrOp.dualIf, if_true, AndOrOp.dual, + simp only [AndOrOp.dualIf, ite_true, AndOrOp.dual, Gate.signedSupport] have hsupport := image_attach_all (fun input : Fin gate.fanIn => @@ -369,7 +369,7 @@ theorem eval_outputAC0Formula_internal have hsupport := signedSupport_eval gate false (circuit.wireValue input) simp only [Bool.false_xor, AndOrOp.dualIf, - Bool.false_eq_true, if_false] at hsupport + Bool.false_eq_true, ↓reduceIte] at hsupport rw [← hsupport] cases gate.op <;> simp only [AC0Formula.ofOp, AC0Formula.eval, diff --git a/Complexitylib/Circuits/AC0/Switching/Internal.lean b/Complexitylib/Circuits/AC0/Switching/Internal.lean index 3476e052..ae0bc497 100644 --- a/Complexitylib/Circuits/AC0/Switching/Internal.lean +++ b/Complexitylib/Circuits/AC0/Switching/Internal.lean @@ -89,7 +89,7 @@ theorem width_consistentPart_le_internal | cons term terms ih => by_cases hconsistent : TermConsistent term · simp only [consistentPart, List.filter_cons, - hconsistent, decide_true, if_true, + hconsistent, decide_true, ite_true, width, List.foldr_cons] exact max_le_max (le_refl _) ih · simp only [consistentPart, List.filter_cons, @@ -213,7 +213,6 @@ theorem switchingDecisionTreeUnderAux_eq_internal (DecisionTree.On.queryAll (Literal.vars (literal :: tail)).toList) funext branch - dsimp only split · rfl · rw [ih, ← hrestricted, @@ -345,13 +344,13 @@ private theorem recoverable_switchingPhasesAux by_cases hterm : term.all (fun found => found.eval (branch.applyTo fun _ => false)) = true - · rw [if_pos hterm] + · rw [ite_eq_left hterm] apply RecoverablePhases.cons restriction original (literal :: tail) block [] hfirst (by simp) hqueries rw [hassignment] exact RecoverablePhases.nil _ - · rw [if_neg hterm] + · rw [ite_eq_right hterm] apply RecoverablePhases.cons restriction original (literal :: tail) block (switchingPhasesAux fuel formula @@ -423,13 +422,13 @@ private theorem deepPath_switchingDecisionTreeUnderAux by_cases hterm : term.all (fun found => found.eval (branch.applyTo fun _ => false)) = true - · rw [if_pos hterm] + · rw [ite_eq_left hterm] dsimp only [continuation] - rw [hcanonical, if_pos hterm] + rw [hcanonical, ite_eq_left hterm] rfl - · rw [if_neg hterm] + · rw [ite_eq_right hterm] dsimp only [continuation] - rw [hcanonical, if_neg hterm] + rw [hcanonical, ite_eq_right hterm] simp only [List.flatMap_cons] rw [ih] @@ -647,8 +646,9 @@ private theorem original_eq_of_mem_annotateBlock List.get_of_mem hentry have hproject := congrArg PhaseEntry.original hposition - simpa [annotateBlock, List.get_eq_getElem, - List.getElem_mapIdx] using hproject.symm + simp only [annotateBlock] at hproject + erw [List.get_eq_getElem, List.getElem_mapIdx] at hproject + exact hproject.symm private theorem map_query_annotatedSwitchingPhases (fuel : ℕ) (formula : DNF N) @@ -742,11 +742,11 @@ private theorem switchingPhasesAux_valid by_cases hterm : term.all (fun found => found.eval (branch.applyTo fun _ => false)) = true - · rw [if_pos hterm] at hphase + · rw [ite_eq_left hterm] at hphase simp only [List.mem_singleton] at hphase subst phase exact ⟨horiginal, hblock⟩ - · rw [if_neg hterm] at hphase + · rw [ite_eq_right hterm] at hphase simp only [List.mem_cons] at hphase rcases hphase with hhead | htailPhase · subst phase @@ -772,8 +772,9 @@ private theorem phaseEntry_valid List.get_of_mem hentry have hproject := congrArg PhaseEntry.original hposition - simpa [annotateBlock, List.get_eq_getElem, - List.getElem_mapIdx] using hproject.symm + simp only [annotateBlock] at hproject + erw [List.get_eq_getElem, List.getElem_mapIdx] at hproject + exact hproject.symm have hquery : entry.query ∈ block := by rw [← map_query_annotateBlock original block] exact List.mem_map_of_mem hentry @@ -820,7 +821,7 @@ private theorem satisfyingValue_eq_polarity have hindex : literal.var ∈ Literal.vars term := by rw [Literal.mem_vars_iff] exact ⟨literal, hliteral, rfl⟩ - rw [satisfyingValue, dif_pos hindex] + rw [satisfyingValue, dite_eq_left hindex] apply hconsistent (term.get (literalPosition term literal.var hindex)) (List.get_mem _ _) literal hliteral @@ -1899,7 +1900,7 @@ private theorem widthTargetRestriction_eq_transcript widthTranscript, List.map_append, DecisionTree.On.assignmentOfPath_append_internal] rw [ih, hgamma] - simpa only [Restriction.On.comp_assoc] using + simpa only [phaseGamma, Restriction.On.comp_assoc] using assignmentFor_overwrites_path block (satisfyingValue original) (DecisionTree.On.assignmentOfPath @@ -3171,7 +3172,6 @@ private theorem badWidthTranscript_eq_ofFn simpa [length_badWidthTranscript] using hleft have hpair := congrArg (fun items => items[index]?) (badWidthTranscript_queries formula bad) - dsimp only at hpair simp [hindex, hleft] at hpair simp [badWidthGammaValues, List.getElem_ofFn] apply Prod.ext diff --git a/Complexitylib/Circuits/Barrington.lean b/Complexitylib/Circuits/Barrington.lean index 8ea337ed..475b22b3 100644 --- a/Complexitylib/Circuits/Barrington.lean +++ b/Complexitylib/Circuits/Barrington.lean @@ -66,7 +66,7 @@ def BPInstr.inverse {w : ℕ} (ins : BPInstr w) : BPInstr w := @[simp] theorem BPInstr.eval_inverse {w : ℕ} (α : ℕ → Bool) (ins : BPInstr w) : BPInstr.eval α (BPInstr.inverse ins) = (BPInstr.eval α ins)⁻¹ := by simp only [BPInstr.eval, BPInstr.inverse] - cases α ins.var <;> rfl + by_cases h : α ins.var = true <;> simp [h] /-- A constant instruction applies the permutation `c` regardless of the input. -/ def BPInstr.const {w : ℕ} (c : Equiv.Perm (Fin w)) : BPInstr w := @@ -76,7 +76,7 @@ def BPInstr.const {w : ℕ} (c : Equiv.Perm (Fin w)) : BPInstr w := @[simp] theorem BPInstr.eval_const {w : ℕ} (α : ℕ → Bool) (c : Equiv.Perm (Fin w)) : BPInstr.eval α (BPInstr.const c) = c := by simp only [BPInstr.eval, BPInstr.const] - cases α 0 <;> rfl + by_cases h : α 0 = true <;> simp [h] /-- Conjugate both branches of an instruction by the same permutation. -/ def BPInstr.conjugate {w : ℕ} (τ : Equiv.Perm (Fin w)) @@ -91,7 +91,7 @@ def BPInstr.conjugate {w : ℕ} (τ : Equiv.Perm (Fin w)) BPInstr.eval α (BPInstr.conjugate τ ins) = τ * BPInstr.eval α ins * τ⁻¹ := by simp only [BPInstr.eval, BPInstr.conjugate] - cases α ins.var <;> rfl + by_cases h : α ins.var = true <;> simp [h] /-- Right-multiply both branches of an instruction by a fixed permutation. -/ def BPInstr.postMul {w : ℕ} (ins : BPInstr w) @@ -103,7 +103,7 @@ def BPInstr.postMul {w : ℕ} (ins : BPInstr w) (ins : BPInstr w) (c : Equiv.Perm (Fin w)) : BPInstr.eval α (BPInstr.postMul ins c) = BPInstr.eval α ins * c := by simp only [BPInstr.eval, BPInstr.postMul] - cases α ins.var <;> rfl + by_cases h : α ins.var = true <;> simp [h] /-- Conjugate every instruction of a branching program. Unlike wrapping with constant instructions, this operation preserves length exactly. -/ diff --git a/Complexitylib/Circuits/BarringtonCompiler/Internal.lean b/Complexitylib/Circuits/BarringtonCompiler/Internal.lean index bd19c036..43715530 100644 --- a/Complexitylib/Circuits/BarringtonCompiler/Internal.lean +++ b/Complexitylib/Circuits/BarringtonCompiler/Internal.lean @@ -155,7 +155,7 @@ private theorem BP.forall_var_postMul_internal {w bound : ℕ} | append_singleton program last ih => intro instruction hinstruction have hnonempty : program ++ [last] ≠ [] := by simp - simp only [BP.postMul, if_neg hnonempty, + simp only [BP.postMul, ite_eq_right hnonempty, List.modifyLast_concat, List.mem_append, List.mem_singleton] at hinstruction rcases hinstruction with hprefix | rfl @@ -267,7 +267,7 @@ theorem barringtonCompile_computes_internal (formula : BoolFormula) : funext assignment simp [BoolFormula.eval, Bool.not_and, Bool.not_not] rw [hfun] at hfinal - simpa only [barringtonCompile, innerTarget, leftTarget, rightTarget, + simpa only [BP.commutatorProgram, barringtonCompile, innerTarget, leftTarget, rightTarget, leftProgram, rightProgram, inv_inv] using hfinal theorem barringtonCompile_length_le_internal diff --git a/Complexitylib/Circuits/BarringtonConverse/Internal.lean b/Complexitylib/Circuits/BarringtonConverse/Internal.lean index 770b8ef8..5dd18f1d 100644 --- a/Complexitylib/Circuits/BarringtonConverse/Internal.lean +++ b/Complexitylib/Circuits/BarringtonConverse/Internal.lean @@ -105,7 +105,7 @@ theorem eval_reachesFormula_internal {w : ℕ} (α : ℕ → Bool) : have htail : tail = [] := by cases tail <;> simp_all subst tail - simpa [reachesFormula] using BPInstr.eval_reachesFormula_internal α ins x y + simpa [reachesFormula, BP.eval] using BPInstr.eval_reachesFormula_internal α ins x y | succ d ih => intro p x y hp have htake : (p.take (2 ^ d)).length ≤ 2 ^ d := List.length_take_le .. diff --git a/Complexitylib/Circuits/BarringtonTyped/Internal.lean b/Complexitylib/Circuits/BarringtonTyped/Internal.lean index 7b95aa6b..0936df20 100644 --- a/Complexitylib/Circuits/BarringtonTyped/Internal.lean +++ b/Complexitylib/Circuits/BarringtonTyped/Internal.lean @@ -62,7 +62,7 @@ private theorem formulaToBP_function | true => have heval := hsemantics input.toTotal simp only [hvalue] at heval - simpa only [heval] using + simpa only [heval, ite_true] using (show decide (barringtonTargetBase (0 : Fin 5) ≠ 0) = true by decide) diff --git a/Complexitylib/Circuits/Basic.lean b/Complexitylib/Circuits/Basic.lean index a07da0cf..e8383ea6 100644 --- a/Complexitylib/Circuits/Basic.lean +++ b/Complexitylib/Circuits/Basic.lean @@ -5,7 +5,7 @@ Authors: Samuel Schlesinger -/ module -public import Mathlib.Data.Nat.Lattice +public import Mathlib.Order.Lattice.Nat /-! # Boolean Circuit Complexity diff --git a/Complexitylib/Circuits/BinaryComparison/Internal.lean b/Complexitylib/Circuits/BinaryComparison/Internal.lean index 052b2750..3bb23b3c 100644 --- a/Complexitylib/Circuits/BinaryComparison/Internal.lean +++ b/Complexitylib/Circuits/BinaryComparison/Internal.lean @@ -62,11 +62,13 @@ theorem unsignedLE_eq_decide_internal {width : ℕ} cases hleft : left (Fin.last width) <;> cases hright : right (Fin.last width) · simp [BitString.unsignedValue] + rfl · simp [BitString.unsignedValue] omega · simp [BitString.unsignedValue] omega · simp [BitString.unsignedValue] + rfl end BitString @@ -342,7 +344,7 @@ theorem unsignedLERawCircuit_wellFormed_internal (width : ℕ) [NeZero width] : (unsignedLERawCircuit width).WellFormed (width + width) := by have hwidth := NeZero.ne width - letI : NeZero (width + width) := ⟨by omega⟩ + let : NeZero (width + width) := ⟨by omega⟩ constructor · intro hempty have hlength := length_unsignedLERawCircuit_internal width @@ -357,7 +359,7 @@ theorem eval?_unsignedLERawCircuit_internal (width : ℕ) [NeZero width] (BitString.toList (Fin.append left right)) = some (decide (left.unsignedValue ≤ right.unsignedValue)) := by have hwidth := NeZero.ne width - letI : NeZero (width + width) := ⟨by omega⟩ + let : NeZero (width + width) := ⟨by omega⟩ let input := Fin.append left right let wires := (BitString.toList input).toArray have hwiresSize : wires.size = width + width := by @@ -387,7 +389,7 @@ theorem eval?_unsignedLERawCircuit_internal (width : ℕ) [NeZero width] simp [BoolFormula.rawOutputWire, length_unsignedLERawCircuit_internal, BoolFormula.size_unsignedLE_internal] rw [RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false, heval'] + simp only [hnonempty, Bool.false_eq_true, ite_false, heval'] rw [houtputIndex] change result[BoolFormula.rawOutputWire (width + width) (BoolFormula.unsignedLE width)]? = diff --git a/Complexitylib/Circuits/BitString.lean b/Complexitylib/Circuits/BitString.lean index 75f50017..a86ad847 100644 --- a/Complexitylib/Circuits/BitString.lean +++ b/Complexitylib/Circuits/BitString.lean @@ -69,13 +69,13 @@ def ofList (xs : List Bool) {n : ℕ} (h : xs.length = n) : BitString n := @[simp] theorem toList_ofList (xs : List Bool) {n : ℕ} (h : xs.length = n) : toList (ofList xs h) = xs := by subst n - simpa only [toList, ofList, Fin.cast_refl] using List.ofFn_get xs + exact List.ofFn_get xs /-- Round trip, bit-string side: deserializing `toList x` recovers the original bit string `x`. -/ @[simp] theorem ofList_toList (x : BitString n) : ofList (toList x) (length_toList x) = x := by funext i - simp [ofList, toList] + exact List.get_ofFn x _ /-- Serialization is injective: two bit strings have equal `toList` iff they are equal. -/ @[simp] theorem toList_inj {x y : BitString n} : x.toList = y.toList ↔ x = y := diff --git a/Complexitylib/Circuits/BranchingProgramEncoding/Internal.lean b/Complexitylib/Circuits/BranchingProgramEncoding/Internal.lean index 16c17373..777e3f32 100644 --- a/Complexitylib/Circuits/BranchingProgramEncoding/Internal.lean +++ b/Complexitylib/Circuits/BranchingProgramEncoding/Internal.lean @@ -59,7 +59,8 @@ theorem index_lt_two_pow_internal (permutation : Equiv.Perm (Fin 5)) : have hindex : index permutation < table.length := List.idxOf_lt_length_of_mem (mem_table_internal permutation) rw [table_length_internal] at hindex - simpa only [bitWidth] using (show index permutation < 128 by omega) + rw [show (2 : ℕ) ^ bitWidth = 128 from rfl] + omega /-- Internal exact length of a permutation field. -/ theorem length_encode_internal (permutation : Equiv.Perm (Fin 5)) : diff --git a/Complexitylib/Circuits/Composition/Internal.lean b/Complexitylib/Circuits/Composition/Internal.lean index 3184a38e..f7dd0288 100644 --- a/Complexitylib/Circuits/Composition/Internal.lean +++ b/Complexitylib/Circuits/Composition/Internal.lean @@ -690,7 +690,6 @@ theorem wireDepth_compose_outer_le_internal outer.acyclic ⟨wire.val - K, by omega⟩ gateInput change source.val < K + (wire.val - K) at hacyclic omega) source rfl) - dsimp only at hfold omega theorem depth_compose_le_internal @@ -721,7 +720,6 @@ theorem depth_compose_le_internal (fun gateInput => wireDepth_compose_outer_le_internal outer inner ((outer.outputs output).inputs gateInput)) - dsimp only at hfold omega unfold Circuit.depth exact fold_max_le_add_fold_max inner.depth diff --git a/Complexitylib/Circuits/DepthClasses/Internal.lean b/Complexitylib/Circuits/DepthClasses/Internal.lean index 703b9387..c06786c5 100644 --- a/Complexitylib/Circuits/DepthClasses/Internal.lean +++ b/Complexitylib/Circuits/DepthClasses/Internal.lean @@ -91,7 +91,7 @@ theorem mem_NC1_iff_internal {f : BoolFunFamily} : ∃ (F : CircuitFamily Basis.andOr2) (c : ℕ), F.Computes f ∧ F.PolynomialSize ∧ F.DepthBoundedBy (fun n => c * Nat.log 2 n + c) := by - simp only [NC1, NC, Set.mem_setOf_eq] + simp only [NC1, NC, Set.mem_ofPred_eq] constructor · rintro ⟨F, c, hcomputes, hsize, hdepth⟩ exact ⟨F, c, hcomputes, hsize, fun n => by @@ -105,7 +105,7 @@ theorem mem_AC0_iff_internal {f : BoolFunFamily} : ∃ (F : CircuitFamily Basis.unboundedAndOr) (c : ℕ), F.Computes f ∧ F.PolynomialSize ∧ F.DepthBoundedBy (fun _ => c) := by - simp only [AC0, AC, Set.mem_setOf_eq] + simp only [AC0, AC, Set.mem_ofPred_eq] constructor · rintro ⟨F, c, hcomputes, hsize, hdepth⟩ exact ⟨F, c, hcomputes, hsize, fun n => by @@ -119,7 +119,7 @@ theorem mem_TC0_iff_internal {f : BoolFunFamily} : ∃ (F : CircuitFamily Basis.threshold) (c : ℕ), F.Computes f ∧ F.PolynomialSize ∧ F.DepthBoundedBy (fun _ => c) := by - simp only [TC0, TC, Set.mem_setOf_eq] + simp only [TC0, TC, Set.mem_ofPred_eq] constructor · rintro ⟨F, c, hcomputes, hsize, hdepth⟩ exact ⟨F, c, hcomputes, hsize, fun n => by diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Codec/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Codec/Internal.lean index 797c759f..e7e75b3d 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Codec/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Codec/Internal.lean @@ -120,7 +120,7 @@ theorem decode?_encode_internal {inputWidth gateBound : Nat} rw [countValue_encode_internal] have hcount : description.gateCountNat < gateBound + 1 := description.gateCount.isLt - rw [dif_pos hcount] + rw [dite_eq_left hcount] congr 1 rw [Description.mk.injEq] constructor @@ -159,7 +159,7 @@ private theorem encode_decoded_of_countValue_lt change GateSlot.encode (GateSlot.decode (slotBits code position.1)) position.2 = blocks.2 flatCoordinate - rw [GateSlot.encode_decode_internal] + erw [GateSlot.encode_decode_internal] unfold slotBits change blocks.2 (finProdFinEquiv (position.1, position.2)) = blocks.2 flatCoordinate diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Conversion/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Conversion/Internal.lean index ce7a3868..d1c98833 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Conversion/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Conversion/Internal.lean @@ -134,7 +134,7 @@ theorem toRawCircuit_ofRawCircuit_internal GateSlot.ofRawGate (referenceWidth inputWidth gateBound) circuit[index] else GateSlot.zero _).toRawGate = circuit[index] - rw [dif_pos hright] + rw [dite_eq_left hright] exact GateSlot.toRawGate_ofRawGate_internal hfit.1 hfit.2 theorem ofRawCircuit_wellFormed_internal @@ -146,7 +146,7 @@ theorem ofRawCircuit_wellFormed_internal · have hnonempty := hcircuit.1 have hpositive : 0 < circuit.length := List.length_pos_iff.mpr hnonempty - simpa using hpositive + exact hpositive · rw [← topologicallyWellFormed_toRawCircuit_iff] rw [toRawCircuit_ofRawCircuit_internal hcircuit.2 hbound] exact hcircuit.2 diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Gate/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Gate/Internal.lean index 58397b81..688465d2 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Gate/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Gate/Internal.lean @@ -176,7 +176,7 @@ private theorem eval_selected0_internal {inputWidth gateBound : Nat} (decodedSlot inputWidth gateBound slot assignment).input0.unsignedValue < inputWidth + slot.val := by simpa [GateSlot.input0Value, BitString.unsignedValue] using hinput - rw [dif_pos hvalue] + rw [dite_eq_left hvalue] rfl private theorem eval_selected1_internal {inputWidth gateBound : Nat} @@ -195,7 +195,7 @@ private theorem eval_selected1_internal {inputWidth gateBound : Nat} (decodedSlot inputWidth gateBound slot assignment).input1.unsignedValue < inputWidth + slot.val := by simpa [GateSlot.input1Value, BitString.unsignedValue] using hinput - rw [dif_pos hvalue] + rw [dite_eq_left hvalue] rfl theorem eval_gate_internal {inputWidth gateBound : Nat} diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Layout/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Layout/Internal.lean index e5274618..09ba554a 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Layout/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Layout/Internal.lean @@ -30,7 +30,7 @@ theorem sizeAt_eq_internal {inputWidth gateBound : Nat} sizeAt inputWidth gateBound slot.val = GateFormula.gateSize inputWidth gateBound slot := by unfold sizeAt - rw [dif_pos slot.isLt] + rw [dite_eq_left slot.isLt] theorem prefixSize_succ_internal (inputWidth gateBound count : Nat) : prefixSize inputWidth gateBound (count + 1) = diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Output/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Output/Internal.lean index 7553a993..6b0585ff 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Output/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Output/Internal.lean @@ -53,8 +53,6 @@ private theorem get_inputWires_code {inputWidth gateBound : Nat} rw [Array.getElem?_eq_getElem hbound] simp only [EvaluationSequence.inputWires, Array.getElem_ofFn] congr 1 - change EvaluationSequence.combinedInput description input - ⟨coordinate.val, _⟩ = _ rw [show (⟨coordinate.val, _⟩ : Fin (baseWireCount inputWidth gateBound)) = Fin.castAdd inputWidth coordinate by @@ -155,7 +153,7 @@ theorem eval_formula_of_code_internal rw [GateSlot.toList_referenceBits, Nat.fromBitsLE_toBitsLE hcountFits] rw [formula, LookupFormula.eval_select _ _ assignment htable, - hword, hunsigned, dif_pos hcountRange] + hword, hunsigned, dite_eq_left hcountRange] have hindex : (⟨description.gateCountNat, hcountRange⟩ : Fin (gateBound + 1)) = Fin.succ (lastActiveSlot description hpositive) := by @@ -289,7 +287,7 @@ theorem topologicallyWellFormed_compileRaw_internal (fullAvailable inputWidth gateBound) := by have hcode : codeWidth inputWidth gateBound ≠ 0 := NeZero.ne (codeWidth inputWidth gateBound) - letI : NeZero (fullAvailable inputWidth gateBound) := ⟨by + let : NeZero (fullAvailable inputWidth gateBound) := ⟨by unfold fullAvailable baseWireCount omega⟩ unfold compileRaw diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Padded/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Padded/Internal.lean index 236e9aa4..228025c7 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Padded/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Padded/Internal.lean @@ -83,6 +83,7 @@ theorem get_toPaddedRawCircuit_internal (description.slots ⟨slot.val, by simpa [length_toPaddedRawCircuit_internal] using slot.isLt⟩).toRawGate := by + simp only [List.get_eq_getElem] simp [toPaddedRawCircuit] theorem topologicallyWellFormed_toPaddedRawCircuit_internal diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Internal.lean index 6978dc51..4d371b45 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Internal.lean @@ -64,7 +64,7 @@ theorem topologicallyWellFormed_stepCircuit_internal (stepAvailable inputWidth gateBound slot) := by have hcode : codeWidth inputWidth gateBound ≠ 0 := NeZero.ne (codeWidth inputWidth gateBound) - letI : NeZero (stepAvailable inputWidth gateBound slot) := ⟨by + let : NeZero (stepAvailable inputWidth gateBound slot) := ⟨by unfold stepAvailable baseWireCount omega⟩ unfold stepCircuit @@ -83,7 +83,7 @@ theorem topologicallyWellFormed_prefixCircuit_internal rw [prefixCircuit, RawCircuit.topologicallyWellFormed_append] constructor · exact ih (by omega) - · rw [stepCircuitAt, dif_pos hindex] + · rw [stepCircuitAt, dite_eq_left hindex] have havailable : baseWireCount inputWidth gateBound + (prefixCircuit inputWidth gateBound count).length = diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Semantics/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Semantics/Internal.lean index 46e34b5a..bff04ef6 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Semantics/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Evaluation/Sequence/Semantics/Internal.lean @@ -50,7 +50,6 @@ private theorem get_inputWires_code {inputWidth gateBound : Nat} rw [Array.getElem?_eq_getElem hbound] simp only [inputWires, Array.getElem_ofFn] congr 1 - change combinedInput description input ⟨coordinate.val, _⟩ = _ rw [show (⟨coordinate.val, _⟩ : Fin (baseWireCount inputWidth gateBound)) = Fin.castAdd inputWidth coordinate by @@ -72,8 +71,6 @@ private theorem get_inputWires_input {inputWidth gateBound : Nat} rw [Array.getElem?_eq_getElem hbound] simp only [inputWires, Array.getElem_ofFn] congr 1 - change combinedInput description input - ⟨codeWidth inputWidth gateBound + index.val, _⟩ = _ rw [show (⟨codeWidth inputWidth gateBound + index.val, _⟩ : Fin (baseWireCount inputWidth gateBound)) = Fin.natAdd (codeWidth inputWidth gateBound) index by @@ -101,8 +98,9 @@ noncomputable def prefixResultInternal {inputWidth gateBound : Nat} circuitEval := rfl rawEval := by simp [rawPrefix, RawCircuit.evalAux?] circuitSize := by - simp [inputWires, prefixSize, baseWireCount] - rawSize := by simp + rw [inputWires, Array.size_ofFn] + simp [prefixSize, baseWireCount] + rawSize := Array.size_ofFn inputPreserved := by intro wire hwire rfl @@ -197,9 +195,7 @@ noncomputable def prefixResultInternal {inputWidth gateBound : Nat} have hrawBound : inputWidth + earlier.val < previous.rawWires.size := by rw [hrawSize] - have hearlier : earlier.val < count := by - change earlier.val < count - exact earlier.isLt + have hearlier : earlier.val < count := earlier.isLt omega rw [Array.getElem?_eq_getElem hcircuitBound, Array.getElem?_eq_getElem hrawBound] at hcorrespond @@ -276,7 +272,7 @@ noncomputable def prefixResultInternal {inputWidth gateBound : Nat} (inputWires description input) = some circuitNext := by rw [prefixCircuit, RawCircuit.evalAux?_append, - previous.circuitEval, stepCircuitAt, dif_pos hindex] + previous.circuitEval, stepCircuitAt, dite_eq_left hindex] exact hcircuitStep have hrawPrefix : rawPrefix description (count + 1) = @@ -366,7 +362,7 @@ noncomputable def prefixResultInternal {inputWidth gateBound : Nat} _ = rawNext[inputWidth + earlier.val]? := by unfold rawNext rw [Array.getElem?_push, - if_neg (Nat.ne_of_lt hrawBound)] } + ite_eq_right (Nat.ne_of_lt hrawBound)] } end EvaluationSequence diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Internal.lean index 7e077370..cc314030 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Internal.lean @@ -115,7 +115,7 @@ theorem topologicallyWellFormed_toRawCircuit_iff_internal simpa only [length_toRawCircuit_internal] using index.isLt⟩ have hgate := h rawIndex simp only [List.get_eq_getElem, getElem_toRawCircuit_internal] at hgate - simpa only [rawIndex] using hgate + exact hgate · intro h index let active : Fin description.gateCountNat := ⟨index.val, by @@ -123,7 +123,7 @@ theorem topologicallyWellFormed_toRawCircuit_iff_internal simpa only [length_toRawCircuit_internal] using hindex⟩ have hslot := h active simp only [List.get_eq_getElem, getElem_toRawCircuit_internal] - simpa only [active] using hslot + exact hslot theorem wellFormed_toRawCircuit_internal {inputWidth gateBound : Nat} diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Lookup/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Lookup/Internal.lean index d57f193e..b8856a8c 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Lookup/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Lookup/Internal.lean @@ -76,7 +76,7 @@ theorem eval_select_internal {width count : Nat} rw [select, BoolFormula.eval_disjs] by_cases hvalue : (evaluatedWord word assignment).unsignedValue < count - · rw [dif_pos hvalue] + · rw [dite_eq_left hvalue] apply Bool.eq_iff_iff.mpr constructor · intro hselected @@ -105,11 +105,9 @@ theorem eval_select_internal {width count : Nat} · simp only [candidate, BoolFormula.eval, Bool.and_eq_true, eval_wordEqual_internal, decide_eq_true_eq] constructor - · simpa [BitString.unsignedValue] using - (GateSlot.referenceBits_fromBitsLE_internal - (evaluatedWord word assignment)).symm + · exact (GateSlot.referenceBits_fromBitsLE_internal (evaluatedWord word assignment)).symm · exact hselected - · rw [dif_neg hvalue] + · rw [dite_eq_right hvalue] apply Bool.eq_false_of_not_eq_true intro hselected rw [List.any_eq_true] at hselected diff --git a/Complexitylib/Circuits/Encoding/FixedWidth/Validity/Internal.lean b/Complexitylib/Circuits/Encoding/FixedWidth/Validity/Internal.lean index b3d8c253..16aeb7cc 100644 --- a/Complexitylib/Circuits/Encoding/FixedWidth/Validity/Internal.lean +++ b/Complexitylib/Circuits/Encoding/FixedWidth/Validity/Internal.lean @@ -285,7 +285,7 @@ theorem eval_slotWellFormed_internal {inputWidth gateBound : Nat} (inputWidth + slot.val) code havailable, eval_referenceBelow_internal slot false (inputWidth + slot.val) code havailable] - simp [GateSlot.WellFormedAt] + simp [GateSlot.WellFormedAt, ← Bool.decide_and] theorem eval_slotValid_internal {inputWidth gateBound : Nat} (slot : Fin gateBound) @@ -347,7 +347,7 @@ theorem eval_wellFormed_internal (inputWidth gateBound : Nat) unfold EncodedWellFormed unfold decode? by_cases hcount : countValue code < gateBound + 1 - · rw [dif_pos hcount] + · rw [dite_eq_left hcount] let description : Description inputWidth gateBound := { gateCount := ⟨countValue code, hcount⟩ slots := fun slot => GateSlot.decode (slotBits code slot) } @@ -363,8 +363,9 @@ theorem eval_wellFormed_internal (inputWidth gateBound : Nat) description.WellFormed constructor · rintro ⟨hpositive, hcountBound, hslotsValid⟩ - refine ⟨by simpa [Description.Positive, Description.gateCountNat, - description] using hpositive, ?_, ?_⟩ + refine ⟨by + simp only [Description.Positive, Description.gateCountNat, description] + omega, ?_, ?_⟩ · intro index let slot : Fin gateBound := ⟨index.val, lt_of_lt_of_le index.isLt hcountBound⟩ @@ -376,8 +377,7 @@ theorem eval_wellFormed_internal (inputWidth gateBound : Nat) exact (hslotsValid slot).2 hinactive · rintro ⟨hpositive, htopological, hpadded⟩ refine ⟨by - simpa [Description.Positive, Description.gateCountNat, - description] using hpositive, Nat.le_of_lt_succ hcount, ?_⟩ + exact hpositive, Nat.le_of_lt_succ hcount, ?_⟩ intro slot constructor · intro hactive @@ -388,7 +388,7 @@ theorem eval_wellFormed_internal (inputWidth gateBound : Nat) description, index] using hvalid · intro hinactive exact hpadded slot hinactive - · rw [dif_neg hcount] + · rw [dite_eq_right hcount] constructor · rintro ⟨_, hcountBound, _⟩ omega @@ -688,7 +688,7 @@ theorem eval?_compileRaw_internal (inputWidth gateBound : Nat) simp [BoolFormula.rawOutputWire, length_compileRaw_internal, size_wellFormed_internal] rw [RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false, heval'] + simp only [hnonempty, Bool.false_eq_true, ite_false, heval'] rw [houtputIndex] change result[BoolFormula.rawOutputWire (codeWidth inputWidth gateBound) diff --git a/Complexitylib/Circuits/Encoding/Formula/Batch/Internal.lean b/Complexitylib/Circuits/Encoding/Formula/Batch/Internal.lean index 3affdc7d..f5e78b69 100644 --- a/Complexitylib/Circuits/Encoding/Formula/Batch/Internal.lean +++ b/Complexitylib/Circuits/Encoding/Formula/Batch/Internal.lean @@ -136,7 +136,7 @@ private theorem evalAux?_compileRawOutputs hsize hformulaVars hformulaInput have hnextSize : formulaResult.size = available + formula.size := by omega - letI : NeZero (available + formula.size) := ⟨by + let : NeZero (available + formula.size) := ⟨by have havailable := NeZero.ne available have hpositive := formula.one_le_size omega⟩ @@ -231,7 +231,7 @@ private theorem evalAux?_copyOutputs Array.getElem?_eq_none (by omega) rw [htailOutput] at hnone simp at hnone - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] exact htailOutput obtain ⟨result, hevalTail, hresultSize, hresultPrefix, hresultOutputs⟩ := ih values (wires.push value) htailPush @@ -244,7 +244,7 @@ private theorem evalAux?_copyOutputs omega · intro i hi rw [hresultPrefix i (by simp; omega)] - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] · intro j hj cases j with | zero => diff --git a/Complexitylib/Circuits/Encoding/Formula/Internal.lean b/Complexitylib/Circuits/Encoding/Formula/Internal.lean index 547cb847..ef2f407b 100644 --- a/Complexitylib/Circuits/Encoding/Formula/Internal.lean +++ b/Complexitylib/Circuits/Encoding/Formula/Internal.lean @@ -70,7 +70,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl · simp [compileRaw, RawCircuit.evalAux?, CircuitCode.RawGate.copy, hvalue, CircuitCode.RawGate.eval] · intro j hj - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] · have hwire : rawOutputWire available (.var i) = wires.size := by simp [rawOutputWire, size, hsize] rw [hwire] @@ -85,7 +85,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl · simp [compileRaw, RawCircuit.evalAux?, CircuitCode.RawGate.constant, hvalue, CircuitCode.RawGate.eval] · intro j hj - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] · have hwire : rawOutputWire available .tru = wires.size := by simp [rawOutputWire, size, hsize] rw [hwire] @@ -100,7 +100,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl · simp [compileRaw, RawCircuit.evalAux?, CircuitCode.RawGate.constant, hvalue, CircuitCode.RawGate.eval] · intro j hj - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] · have hwire : rawOutputWire available .fls = wires.size := by simp [rawOutputWire, size, hsize] rw [hwire] @@ -117,7 +117,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl · simp only [Array.size_push, hresultSize, size] omega · intro i hi - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] exact hpreserved i hi · have hwire : rawOutputWire available (.neg formula) = formulaResult.size := by simp only [rawOutputWire, size, hresultSize, hsize] @@ -135,7 +135,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl ihLeft available wires hsize hvarsLeft hagreeLeft have hleftSize' : leftResult.size = available + left.size := by omega - letI : NeZero (available + left.size) := ⟨by + let : NeZero (available + left.size) := ⟨by have := NeZero.ne available omega⟩ have hvarsRight : ∀ i ∈ right.vars, i < available + left.size := by @@ -168,7 +168,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl · simp only [Array.size_push, hrightSize, hleftSize, size] omega · intro i hi - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] rw [hrightPreserved i (by omega)] exact hleftPreserved i hi · have hwire : rawOutputWire available (.conj left right) = rightResult.size := by @@ -187,7 +187,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl ihLeft available wires hsize hvarsLeft hagreeLeft have hleftSize' : leftResult.size = available + left.size := by omega - letI : NeZero (available + left.size) := ⟨by + let : NeZero (available + left.size) := ⟨by have := NeZero.ne available omega⟩ have hvarsRight : ∀ i ∈ right.vars, i < available + left.size := by @@ -220,7 +220,7 @@ theorem evalAux?_compileRaw_of_agree_internal (available : ℕ) [NeZero availabl · simp only [Array.size_push, hrightSize, hleftSize, size] omega · intro i hi - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] rw [hrightPreserved i (by omega)] exact hleftPreserved i hi · have hwire : rawOutputWire available (.disj left right) = rightResult.size := by diff --git a/Complexitylib/Circuits/Encoding/Internal/Codec.lean b/Complexitylib/Circuits/Encoding/Internal/Codec.lean index 074fcbc7..afda5dcb 100644 --- a/Complexitylib/Circuits/Encoding/Internal/Codec.lean +++ b/Complexitylib/Circuits/Encoding/Internal/Codec.lean @@ -366,7 +366,7 @@ theorem eval?_isSome_iff_internal (circuit : RawCircuit) (input : List Bool) : rw [hsize, List.size_toArray] simp rw [eval?] - simp only [List.isEmpty_cons, Bool.false_eq_true, if_false, haux] + simp only [List.isEmpty_cons, Bool.false_eq_true, ite_false, haux] change (result[input.length + (gate :: gates).length - 1]?).isSome rw [Array.getElem?_eq_getElem hlt] simp diff --git a/Complexitylib/Circuits/Encoding/Internal/Fragment.lean b/Complexitylib/Circuits/Encoding/Internal/Fragment.lean index 60862b65..682832e8 100644 --- a/Complexitylib/Circuits/Encoding/Internal/Fragment.lean +++ b/Complexitylib/Circuits/Encoding/Internal/Fragment.lean @@ -98,7 +98,7 @@ theorem eval?_append_copy_internal (circuit : RawCircuit) rw [hsize] simp rw [Array.getElem?_push] - rw [if_pos houtputIndex, hget] + rw [ite_eq_left houtputIndex, hget] simp [RawGate.eval] /-- Exact serialization of an output-match extension. -/ @@ -135,7 +135,7 @@ theorem evalCode_appendOutputMatch_encode_iff_of_length_internal some true ↔ circuit.eval? input = some expected := by unfold evalCode - rw [if_pos hwidth, decode?_encode] + rw [ite_eq_left hwidth, decode?_encode] rw [appendOutputMatch] have happly := eval?_append_copy_internal circuit input (!expected) hnonempty rw [hwidth] at happly @@ -199,7 +199,7 @@ theorem evalCode_appendOutputMatchBit_encode_iff_of_length_internal some true ↔ circuit.eval? input = some expected := by unfold evalCode - rw [if_pos hwidth, decode?_encode] + rw [ite_eq_left hwidth, decode?_encode] change (appendOutputMatchBit inputWidth circuit expected).eval? input = some true ↔ circuit.eval? input = some expected @@ -245,7 +245,7 @@ theorem evalAux?_preserves_prefix_internal {circuit : RawCircuit} | some value₁ => simp only [evalAux?, hvalue₀, hvalue₁] at heval have hpreserved := ih heval (by simp only [Array.size_push]; omega) - rw [Array.getElem?_push, if_neg (by omega)] at hpreserved + rw [Array.getElem?_push, ite_eq_right (by omega)] at hpreserved exact hpreserved end RawCircuit diff --git a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Action.lean b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Action.lean index ec5dec1c..5ab08d4c 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Action.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Action.lean @@ -75,9 +75,7 @@ theorem evalFamilyCoreTM_step (c : Cfg workTapeCount evalFamilyCoreTM.Q) output := c.output.writeAndMove action.output.write action.output.dir } := by rw [TM.step] simp only [evalFamilyCoreTM] - split - · next h => exact (hstate h).elim - · rfl + erw [ite_eq_right hstate] end Internal diff --git a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Evaluator.lean b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Evaluator.lean index de207902..2e074bd1 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Evaluator.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Evaluator.lean @@ -145,8 +145,7 @@ theorem evalFamilyTM_hoareTime_internal (bits : List Bool) : (evalFamilyTime bits.length) := by have htest : (TM.pairValidateTM.liftTM workTapeCount).HoareTime (PairStagePre bits) (ValidatorPost bits) (bits.length + 2) := by - simpa [PairStagePre, ValidatorPost] using - TM.pairValidateTM_lift_hoareTime workTapeCount bits + exact TM.pairValidateTM_lift_hoareTime workTapeCount bits have hwf : ∀ inp work out, ValidatorPost bits inp work out → TM.AllTapesWF inp work out := by intro inp work out hpost @@ -252,7 +251,7 @@ theorem evalFamilyTime_bigO_quadratic_internal : (Complexity.BigO.const_mul_left 4 hnQuadratic) (Complexity.BigO.const_mul_left 20 hshiftQuadratic)) (Complexity.BigO.const_le_pow 17 2) - simpa [evalFamilyTime, evalFamilyTMWithTime, evalFamilyCoreTime] using hbound + exact hbound end Internal diff --git a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution.lean b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution.lean index 928daf53..0ede09d8 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution.lean @@ -180,7 +180,8 @@ theorem coreCfg_step (phase : CorePhase) (input code wires counter output : Tape omega subst i simp - · simpa [coreCfg] using hphase + · simp [coreCfg] + exact hphase /-- Any controller branch selecting `CoreAction.reject` halts in one step, writes zero at the current output head, and preserves the named work tapes. -/ @@ -214,7 +215,7 @@ theorem rewindCode_step_cursor {bits : List Bool} {position : ℕ} (coreCfg .rewindCode input code wires counter output) = some (coreCfg .rewindCode input (code.move Dir3.left) wires counter output) := by rw [coreCfg_step .rewindCode input code wires counter output (by decide)] - simp only [coreAction, coreHeads_codeIdx, hcode.read_ne_start, if_false, + simp only [coreAction, coreHeads_codeIdx, hcode.read_ne_start, ite_false, coreHeads_wiresIdx, coreHeads_counterIdx, TapeAction.moveLeft, CoreAction.preserve, TapeAction.preserve] rw [hcode.applyMoveLeft] @@ -235,7 +236,7 @@ theorem rewindCode_step_marker {bits : List Bool} some (coreCfg .rewindWires input (code.move Dir3.right) wires counter output) := by rw [coreCfg_step .rewindCode input code wires counter output (by decide)] - simp only [coreAction, coreHeads_codeIdx, hcode.read_start, if_true, + simp only [coreAction, coreHeads_codeIdx, hcode.read_start, ite_true, coreHeads_wiresIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveRight] have hcodeMove : @@ -295,7 +296,7 @@ theorem rewindWires_step_cursor {bits : List Bool} {position : ℕ} some (coreCfg .rewindWires input code (wires.move Dir3.left) counter output) := by rw [coreCfg_step .rewindWires input code wires counter output (by decide)] - simp only [coreAction, coreHeads_wiresIdx, hwires.read_ne_start, if_false, + simp only [coreAction, coreHeads_wiresIdx, hwires.read_ne_start, ite_false, coreHeads_codeIdx, coreHeads_counterIdx, TapeAction.moveLeft, CoreAction.preserve, TapeAction.preserve] rw [hwires.applyMoveLeft] @@ -316,7 +317,7 @@ theorem rewindWires_step_marker {bits : List Bool} some (coreCfg .familyTag input code (wires.move Dir3.right) counter output) := by rw [coreCfg_step .rewindWires input code wires counter output (by decide)] - simp only [coreAction, coreHeads_wiresIdx, hwires.read_start, if_true, + simp only [coreAction, coreHeads_wiresIdx, hwires.read_start, ite_true, CoreAction.moveWiresRight, coreHeads_codeIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveRight] have hwiresMove : @@ -402,7 +403,7 @@ theorem familyTag_step_empty (rest : List Bool) some (coreCfg .emptyAnswer input (code.move Dir3.right) wires counter output) := by have hcodeRead : code.read = Γ.zero := by - simpa [Γ.ofBool] using hcode.read_of_lt (by simp) + exact hcode.read_of_lt (by simp) have hwiresRead : wires.read = Γ.blank := hwires.read_frontier rw [coreCfg_step .familyTag input code wires counter output (by decide)] simp only [coreAction, coreHeads_codeIdx, coreHeads_wiresIdx, hcodeRead, @@ -438,9 +439,9 @@ theorem familyTag_step_positive (circuitCode inputRest : List Bool) some (coreCfg .count input (code.move Dir3.right) wires counter output) := by have hcodeRead : code.read = Γ.one := by - simpa [Γ.ofBool] using hcode.read_of_lt (by simp) + exact hcode.read_of_lt (by simp) have hwiresRead : wires.read = Γ.ofBool bit := by - simpa using hwires.read_of_lt (by simp) + exact hwires.read_of_lt (by simp) have hwiresKeep : wires.writeAndMove (TM.readBackWrite (Γ.ofBool bit)) (TM.idleDir (Γ.ofBool bit)) = wires := by @@ -597,7 +598,7 @@ theorem rewindCounter_step_cursor {bits : List Bool} {position : ℕ} (counter.move Dir3.left) output) := by rw [coreCfg_step .rewindCounter input code wires counter output (by decide)] simp only [coreAction, coreHeads_counterIdx, hcounter.read_ne_start, - if_false, coreHeads_codeIdx, coreHeads_wiresIdx, TapeAction.moveLeft, + ite_false, coreHeads_codeIdx, coreHeads_wiresIdx, TapeAction.moveLeft, CoreAction.preserve, TapeAction.preserve] rw [hcounter.applyMoveLeft] rw [Tape.writeAndMove_readBack_idle_of_ne_start code hcode] @@ -617,7 +618,7 @@ theorem rewindCounter_step_marker {bits : List Bool} some (coreCfg (.gateCheck false) input code wires (counter.move Dir3.right) output) := by rw [coreCfg_step .rewindCounter input code wires counter output (by decide)] - simp only [coreAction, coreHeads_counterIdx, hcounter.read_start, if_true, + simp only [coreAction, coreHeads_counterIdx, hcounter.read_start, ite_true, coreHeads_codeIdx, coreHeads_wiresIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveRight] have hcounterMove : @@ -741,7 +742,7 @@ theorem familyTag_step_reject_positive_empty (rest : List Bool) (coreCfg .familyTag input code wires counter output) = some (coreCfg .done input code wires counter (output.write Γ.zero)) := by have hcodeRead : code.read = Γ.one := by - simpa [Γ.ofBool] using hcode.read_of_lt (by simp) + exact hcode.read_of_lt (by simp) have hwiresRead : wires.read = Γ.blank := hwires.read_frontier apply coreCfg_step_reject .familyTag input code wires counter output (by decide) @@ -764,9 +765,9 @@ theorem familyTag_step_reject_empty_nonempty (rest inputRest : List Bool) (coreCfg .familyTag input code wires counter output) = some (coreCfg .done input code wires counter (output.write Γ.zero)) := by have hcodeRead : code.read = Γ.zero := by - simpa [Γ.ofBool] using hcode.read_of_lt (by simp) + exact hcode.read_of_lt (by simp) have hwiresRead : wires.read = Γ.ofBool bit := by - simpa using hwires.read_of_lt (by simp) + exact hwires.read_of_lt (by simp) apply coreCfg_step_reject .familyTag input code wires counter output (by decide) · cases bit <;> simp [coreAction, hcodeRead, hwiresRead, Γ.ofBool] @@ -795,7 +796,7 @@ theorem familyTag_step_reject_missing (inputBits : List Bool) simp [coreAction, hcodeRead, hwiresRead] | cons bit rest => have hwiresRead : wires.read = Γ.ofBool bit := by - simpa using hwires.read_of_lt (by simp) + exact hwires.read_of_lt (by simp) cases bit <;> simp [coreAction, hcodeRead, hwiresRead, Γ.ofBool] · exact hinput · exact hcode.read_ne_start @@ -816,7 +817,7 @@ theorem emptyAnswer_step (answer : Bool) (rest : List Bool) some (coreCfg (.emptyEnd answer) input (code.move Dir3.right) wires counter output) := by have hcodeRead : code.read = Γ.ofBool answer := by - simpa using hcode.read_of_lt (by simp) + exact hcode.read_of_lt (by simp) have hcodeMove : code.writeAndMove (TM.readBackWrite (Γ.ofBool answer)) Dir3.right = code.move Dir3.right := by @@ -852,7 +853,7 @@ theorem emptyEnd_step (answer : Bool) have hcodeRead : code.read = Γ.blank := hcode.read_frontier rw [coreCfg_step (.emptyEnd answer) input code wires counter output (by cases answer <;> decide)] - simp only [coreAction, coreHeads_codeIdx, hcodeRead, if_true, + simp only [coreAction, coreHeads_codeIdx, hcodeRead, ite_true, CoreAction.finish, coreHeads_wiresIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.writeStay, Γw.ofBool_toΓ] diff --git a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/EmptyReject.lean b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/EmptyReject.lean index 1df2500d..5c9efae1 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/EmptyReject.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/EmptyReject.lean @@ -62,7 +62,7 @@ theorem emptyEnd_step_reject_trailing (answer bit : Bool) (rest : List Bool) (coreCfg (.emptyEnd answer) input code wires counter output) = some (coreCfg .done input code wires counter (output.write Γ.zero)) := by have hcodeRead : code.read = Γ.ofBool bit := by - simpa using hcode.read_of_lt (by simp) + exact hcode.read_of_lt (by simp) apply coreCfg_step_reject (.emptyEnd answer) input code wires counter output (by cases answer <;> decide) · cases bit <;> simp [coreAction, hcodeRead, Γ.ofBool] diff --git a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/Gate.lean b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/Gate.lean index 9951f8bc..d9387b93 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/Gate.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Execution/Gate.lean @@ -246,7 +246,7 @@ theorem rewindRef0_step_cursor (op negated0 negated1 : Bool) rw [coreCfg_step (.rewindRef0 op negated0 negated1) input code wires counter output (by cases op <;> cases negated0 <;> cases negated1 <;> decide)] - simp only [coreAction, coreHeads_wiresIdx, hwires.read_ne_start, if_false, + simp only [coreAction, coreHeads_wiresIdx, hwires.read_ne_start, ite_false, coreHeads_codeIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveLeft] rw [hwires.applyMoveLeft] @@ -271,7 +271,7 @@ theorem rewindRef0_step_marker (op negated0 negated1 : Bool) rw [coreCfg_step (.rewindRef0 op negated0 negated1) input code wires counter output (by cases op <;> cases negated0 <;> cases negated1 <;> decide)] - simp only [coreAction, coreHeads_wiresIdx, hwires.read_start, if_true, + simp only [coreAction, coreHeads_wiresIdx, hwires.read_start, ite_true, coreHeads_codeIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveRight] have hwiresMove : @@ -338,7 +338,7 @@ theorem rewindRef1_step_cursor (op negated1 value0 : Bool) rw [coreCfg_step (.rewindRef1 op negated1 value0) input code wires counter output (by cases op <;> cases negated1 <;> cases value0 <;> decide)] - simp only [coreAction, coreHeads_wiresIdx, hwires.read_ne_start, if_false, + simp only [coreAction, coreHeads_wiresIdx, hwires.read_ne_start, ite_false, coreHeads_codeIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveLeft] rw [hwires.applyMoveLeft] @@ -363,7 +363,7 @@ theorem rewindRef1_step_marker (op negated1 value0 : Bool) rw [coreCfg_step (.rewindRef1 op negated1 value0) input code wires counter output (by cases op <;> cases negated1 <;> cases value0 <;> decide)] - simp only [coreAction, coreHeads_wiresIdx, hwires.read_start, if_true, + simp only [coreAction, coreHeads_wiresIdx, hwires.read_start, ite_true, coreHeads_codeIdx, coreHeads_counterIdx, CoreAction.preserve, TapeAction.preserve, TapeAction.moveRight] have hwiresMove : diff --git a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Tape.lean b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Tape.lean index 6633ff29..1ea74099 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Tape.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Core/Internal/Tape.lean @@ -225,7 +225,7 @@ theorem applyMoveRight {t : Tape} {bits : List Bool} t.writeAndMove (TM.readBackWrite t.read) Dir3.right = t.move Dir3.right := by show (t.write (TM.readBackWrite t.read)).move Dir3.right = _ - rw [Tape.write, if_pos h.1] + rw [Tape.write, ite_eq_left h.1] /-- The controller's marker bounce returns to the position-zero cursor. -/ theorem returnToFirstBit {t : Tape} {bits : List Bool} diff --git a/Complexitylib/Circuits/Encoding/Machine/Internal/FrontEnd.lean b/Complexitylib/Circuits/Encoding/Machine/Internal/FrontEnd.lean index b847fd81..e4616619 100644 --- a/Complexitylib/Circuits/Encoding/Machine/Internal/FrontEnd.lean +++ b/Complexitylib/Circuits/Encoding/Machine/Internal/FrontEnd.lean @@ -371,8 +371,7 @@ theorem pairStageTM_hoareTime_internal (bits : List Bool) : (pairStageTime bits.length) := by have htest : (TM.pairValidateTM.liftTM workTapeCount).HoareTime (PairStagePre bits) (ValidatorPost bits) (bits.length + 2) := by - simpa [PairStagePre, ValidatorPost] using - TM.pairValidateTM_lift_hoareTime workTapeCount bits + exact TM.pairValidateTM_lift_hoareTime workTapeCount bits have hwf : ∀ inp work out, ValidatorPost bits inp work out → TM.AllTapesWF inp work out := by intro inp work out hpost diff --git a/Complexitylib/Circuits/Encoding/Machine/NatCode/Internal.lean b/Complexitylib/Circuits/Encoding/Machine/NatCode/Internal.lean index 1220add0..cd349bd1 100644 --- a/Complexitylib/Circuits/Encoding/Machine/NatCode/Internal.lean +++ b/Complexitylib/Circuits/Encoding/Machine/NatCode/Internal.lean @@ -52,7 +52,9 @@ private theorem natCodeOutputAt_outAcc (out : Tape) (ys : List Bool) | zero => simpa [natCodeOutputAt] using hout | succ count ih => have hnext := outAcc_append_bit ih true - simpa [natCodeOutputAt, List.replicate_add, List.append_assoc] using hnext + simp only [natCodeOutputAt, List.replicate_add, List.replicate_one] + rw [← List.append_assoc] + exact hnext private theorem HasBinaryNat.parked {t : Tape} {value : ℕ} (h : t.HasBinaryNat value) : Parked t := by @@ -245,9 +247,9 @@ private theorem natCodeIteration_reachesIn have hseq := seqTM_reachesIn_of_reachesIn emit succ hemit rfl hsucc' have hlift := binaryForTM_iteration_reachesIn_internal (emitBitsTM (n := n) [true]) counterIdx limitIdx hseq - simpa [emit, succ, emitNatCodeLoopTM, natCodeIterationStartCfg, - natCodeIterationDoneCfg, binaryForIterationTime, binaryForIterationTM, - binaryForIterationWrap, phase1Wrap, phase2Wrap] using hlift + simp [emitNatCodeLoopTM, natCodeIterationStartCfg, natCodeIterationDoneCfg, + binaryForIterationTime, binaryForIterationTM] + exact hlift private theorem natCodeLoopback_step (counterIdx limitIdx : Fin n) @@ -500,7 +502,7 @@ private theorem natCodeWorkAt_cfg_withinAuxSpace /-- Explicit all-prefix certificate for the binary emission loop. The output is uncharged; comparison and successor cursors stay within a linear function of the preserved limit's binary width. -/ -private def natCodeLoopSpaceSpec +private theorem natCodeLoopSpaceSpec (counterIdx limitIdx : Fin n) (hne : counterIdx ≠ limitIdx) (inp₀ : Tape) (work₀ : Fin n → Tape) (out₀ : Tape) (ys : List Bool) (value inputLength initialSpace : ℕ) @@ -527,7 +529,7 @@ private def natCodeLoopSpaceSpec have hreach' : (emitNatCodeLoopTM counterIdx limitIdx).reachesIn time (natCodeScanCfg counterIdx limitIdx inp₀ work₀ out₀ current) cfg := by - simpa [natCodeLoopSpec] using hreach + exact hreach exact (hstart.reachesIn hreach').mono le_rfl (by simp [binaryForCompareTime] at htime omega) @@ -543,7 +545,7 @@ private def natCodeLoopSpaceSpec have hreach' : (emitNatCodeLoopTM counterIdx limitIdx).reachesIn time (natCodeIterationStartCfg counterIdx limitIdx inp₀ work₀ out₀ current) cfg := by - simpa [natCodeLoopSpec] using hreach + exact hreach have hsucc := binarySuccTime_le current have hsize := Nat.size_le_size (Nat.le_of_lt hcurrent) exact (hstart.reachesIn hreach').mono le_rfl (by @@ -596,7 +598,7 @@ private theorem emitNatCodeLoopTM_hoareSpace exact (natCodeLoopSpaceSpec counterIdx limitIdx hne inp₀ work₀ out ys value inputLength initialSpace hinp hcounter hlimit hother hout hworkSpace hinputSpace).prefix_withinAuxSpace value 0 t c - (by omega) (by simpa [spec] using hreachSpec) htime + (by omega) (by exact hreachSpec) htime /-- Time-and-all-prefix-space contract for the unary-body loop. -/ theorem emitNatCodeLoopTM_hoareTimeSpace_internal diff --git a/Complexitylib/Circuits/Encoding/Parity/Internal.lean b/Complexitylib/Circuits/Encoding/Parity/Internal.lean index 0b4bf23c..140fe03f 100644 --- a/Complexitylib/Circuits/Encoding/Parity/Internal.lean +++ b/Complexitylib/Circuits/Encoding/Parity/Internal.lean @@ -80,12 +80,12 @@ private theorem evalAux?_xorGates (available step input : ℕ) first[accumulatorWire available step]? = some accumulator := by dsimp only [first] - rw [Array.getElem?_push, if_neg haccumulatorNe] + rw [Array.getElem?_push, ite_eq_right haccumulatorNe] exact haccumulator have hinputFirst : first[input]? = some bit := by dsimp only [first] - rw [Array.getElem?_push, if_neg hinputNe] + rw [Array.getElem?_push, ite_eq_right hinputNe] exact hinput have hor : first[orWire available step]? = some (accumulator || bit) := by @@ -112,7 +112,7 @@ private theorem evalAux?_xorGates (available step input : ℕ) simp only [first, Array.size_push, hsize] omega dsimp only [second] - rw [Array.getElem?_push, if_neg hne] + rw [Array.getElem?_push, ite_eq_right hne] exact hor have horSecond' : ((wires.push (accumulator || bit)).push @@ -234,7 +234,7 @@ theorem evalAux?_compileRaw_internal (available : ℕ) [NeZero available] simp [base, orWire, hsize] have hbaseInputs : ∀ i, base[refs i]? = some (bits i) := by intro i - rw [Array.getElem?_push, if_neg (by rw [hsize]; exact ne_of_lt (hrefs i))] + rw [Array.getElem?_push, ite_eq_right (by rw [hsize]; exact ne_of_lt (hrefs i))] exact hinputs i have hbaseAccumulator : base[accumulatorWire available 0]? = some false := by @@ -254,7 +254,7 @@ theorem evalAux?_compileRaw_internal (available : ℕ) [NeZero available] omega · intro i hi rw [hresultPreserved i (by simp [base]; omega)] - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] · simpa [outputWire, Bool.false_xor] using hresultOutput theorem topologicallyWellFormed_compileRaw_internal (available : ℕ) @@ -305,7 +305,7 @@ theorem eval?_compileRaw_internal (available : ℕ) [NeZero available] outputWire available inputCount := by rw [BitString.length_toList, outputWire_eq_internal] rw [RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false] + simp only [hnonempty, Bool.false_eq_true, ite_false] rw [show input.toList.toArray = wires by rfl, heval] rw [houtputIndex] exact houtput diff --git a/Complexitylib/Circuits/Encoding/Shift/Internal.lean b/Complexitylib/Circuits/Encoding/Shift/Internal.lean index cae41e99..6666b41d 100644 --- a/Complexitylib/Circuits/Encoding/Shift/Internal.lean +++ b/Complexitylib/Circuits/Encoding/Shift/Internal.lean @@ -45,25 +45,26 @@ theorem topologicallyWellFormed_shift_iff_internal circuit.TopologicallyWellFormed available := by constructor · intro h index - let shiftedIndex : Fin (circuit.shift offset).length := - ⟨index.val, by - rw [length_shift_internal] - exact index.isLt⟩ - simpa [shift, TopologicallyWellFormed, RawGate.shift, - RawGate.WellFormedAt, Nat.add_assoc] using h shiftedIndex + have hshifted := h ⟨index.val, by + rw [length_shift_internal] + exact index.isLt⟩ + simp only [List.get_eq_getElem] at hshifted ⊢ + simpa [shift, RawGate.shift, RawGate.WellFormedAt, Nat.add_assoc] + using hshifted · intro h index have hlength := length_shift_internal offset circuit have hindex : index.val < circuit.length := by have := index.isLt omega - let localIndex : Fin circuit.length := ⟨index.val, hindex⟩ - simpa [shift, TopologicallyWellFormed, RawGate.shift, - RawGate.WellFormedAt, Nat.add_assoc] using h localIndex + have hlocal := h ⟨index.val, hindex⟩ + simp only [List.get_eq_getElem] at hlocal ⊢ + simpa [shift, RawGate.shift, RawGate.WellFormedAt, Nat.add_assoc] + using hlocal private theorem getElem?_append_offset {offset index : Nat} (leading wires : Array Bool) (hleading : leading.size = offset) : (leading ++ wires)[offset + index]? = wires[index]? := by - rw [Array.getElem?_append, if_neg] + rw [Array.getElem?_append, ite_eq_right] · rw [hleading, Nat.add_sub_cancel_left] · rw [hleading] omega diff --git a/Complexitylib/Circuits/Encoding/Threshold/Internal.lean b/Complexitylib/Circuits/Encoding/Threshold/Internal.lean index a09527c6..29e331ef 100644 --- a/Complexitylib/Circuits/Encoding/Threshold/Internal.lean +++ b/Complexitylib/Circuits/Encoding/Threshold/Internal.lean @@ -114,7 +114,7 @@ private theorem evalAux?_cellGates (available threshold inputRow thresholdColumn have hcurrentPush : (wires.push (bit && lower))[stateWire available threshold inputRow (thresholdColumn + 1)]? = some current := by - rw [Array.getElem?_push, if_neg hstateNe] + rw [Array.getElem?_push, ite_eq_right hstateNe] exact hcurrent have hand : (wires.push (bit && lower))[andWire available threshold inputRow thresholdColumn]? = some (bit && lower) := by @@ -201,8 +201,8 @@ private theorem evalAux?_rowPrefix (available threshold inputRow input columnCou omega simp only [result] rw [Array.getElem?_push, - if_neg (by simp only [Array.size_push]; omega)] - rw [Array.getElem?_push, if_neg (by omega)] + ite_eq_right (by simp only [Array.size_push]; omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] exact hmiddlePreserved i hi · intro required hrequired by_cases hlast : required = columnCount + 1 @@ -220,8 +220,8 @@ private theorem evalAux?_rowPrefix (available threshold inputRow input columnCou stateWire available threshold (inputRow + 1) required < middle.size := (Array.getElem?_eq_some_iff.mp hprevious).choose simp only [result] - rw [Array.getElem?_push, if_neg (by simp only [Array.size_push]; omega)] - rw [Array.getElem?_push, if_neg (by omega)] + rw [Array.getElem?_push, ite_eq_right (by simp only [Array.size_push]; omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] exact hprevious /-- Internal multi-row invariant, with an accumulated count supplied by the @@ -326,8 +326,8 @@ theorem evalAux?_compileRaw_internal (available threshold : ℕ) [NeZero availab exact hrefs i simp only [base] rw [Array.getElem?_push, - if_neg (by simp only [Array.size_push]; omega)] - rw [Array.getElem?_push, if_neg (by omega)] + ite_eq_right (by simp only [Array.size_push]; omega)] + rw [Array.getElem?_push, ite_eq_right (by omega)] exact hinputs i have hbaseStates : ∀ required ≤ threshold, base[stateWire available threshold 0 required]? = @@ -347,7 +347,7 @@ theorem evalAux?_compileRaw_internal (available threshold : ℕ) [NeZero availab have hfalse : (wires.push false)[wires.size]? = some false := Array.getElem?_push_size simp only [base] - rw [Array.getElem?_push, if_neg (by simp)] + rw [Array.getElem?_push, ite_eq_right (by simp)] exact hfalse obtain ⟨table, hevalRows, htableSize, htablePreserved, htableStates⟩ := evalAux?_rows available threshold 0 inputCount 0 refs bits base diff --git a/Complexitylib/Circuits/InputProjection/Internal.lean b/Complexitylib/Circuits/InputProjection/Internal.lean index 0caafe69..9dcdd98b 100644 --- a/Complexitylib/Circuits/InputProjection/Internal.lean +++ b/Complexitylib/Circuits/InputProjection/Internal.lean @@ -18,14 +18,19 @@ namespace Complexity namespace Circuit +/-- Evaluation over `Basis.andOr2` is `AndOrOp.eval`; stated as an equation so it can be +rewritten without unfolding the basis inside the circuit's type. -/ +private theorem andOr2_eval_eq (op : AndOrOp) (n : ℕ) + (h : (Basis.andOr2.arity op).satisfiedBy n) (inputs : BitString n) : + Basis.andOr2.eval op n h inputs = AndOrOp.eval op n inputs := rfl + theorem eval_projectInputs_internal {N M : ℕ} [NeZero N] [NeZero M] (mapInput : Fin M → Fin N) (input : BitString N) : (projectInputs mapInput).eval input = input ∘ mapInput := by funext output unfold Circuit.eval projectInputs inputProjectionOutputGate Gate.eval - change AndOrOp.eval .and 2 _ = _ + simp only [andOr2_eval_eq] rw [AndOrOp.eval_two_and] - dsimp only simp only [Bool.false_xor] rw [Circuit.wireValue_of_lt _ _ _ (by simp)] simp diff --git a/Complexitylib/Circuits/InputSources/Internal.lean b/Complexitylib/Circuits/InputSources/Internal.lean index d8785ac4..06388059 100644 --- a/Complexitylib/Circuits/InputSources/Internal.lean +++ b/Complexitylib/Circuits/InputSources/Internal.lean @@ -18,6 +18,12 @@ namespace Complexity namespace Circuit +/-- Evaluation over `Basis.andOr2` is `AndOrOp.eval`; stated as an equation so it can be +rewritten without unfolding the basis inside the circuit's type. -/ +private theorem andOr2_eval_eq (op : AndOrOp) (n : ℕ) + (h : (Basis.andOr2.arity op).satisfiedBy n) (inputs : BitString n) : + Basis.andOr2.eval op n h inputs = AndOrOp.eval op n inputs := rfl + theorem eval_inputSources_internal {inputWidth outputWidth : ℕ} [NeZero inputWidth] [NeZero outputWidth] (sources : Fin outputWidth → InputSource inputWidth) @@ -34,9 +40,9 @@ theorem eval_inputSources_internal {inputWidth outputWidth : ℕ} cases value with | false => unfold inputSourceOutputGate InputSource.eval Gate.eval - change AndOrOp.eval .and 2 _ = false - rw [AndOrOp.eval_two_and] dsimp only + erw [andOr2_eval_eq] + erw [AndOrOp.eval_two_and] rw [Circuit.wireValue_of_lt _ _ _ (by have hinput : 0 < inputWidth := Nat.pos_of_ne_zero (NeZero.ne inputWidth) @@ -45,9 +51,9 @@ theorem eval_inputSources_internal {inputWidth outputWidth : ℕ} simp | true => unfold inputSourceOutputGate InputSource.eval Gate.eval - change AndOrOp.eval .or 2 _ = true - rw [AndOrOp.eval_two_or] dsimp only + erw [andOr2_eval_eq] + erw [AndOrOp.eval_two_or] rw [Circuit.wireValue_of_lt _ _ _ (by have hinput : 0 < inputWidth := Nat.pos_of_ne_zero (NeZero.ne inputWidth) @@ -56,9 +62,8 @@ theorem eval_inputSources_internal {inputWidth outputWidth : ℕ} simp | input coordinate => unfold inputSourceOutputGate InputSource.eval Gate.eval - change AndOrOp.eval .and 2 _ = input coordinate - rw [AndOrOp.eval_two_and] - dsimp only + simp only [andOr2_eval_eq] + erw [AndOrOp.eval_two_and] simp only [Bool.false_xor] rw [Circuit.wireValue_of_lt _ _ _ (by simp)] simp diff --git a/Complexitylib/Circuits/Internal/CircuitToDescriptor.lean b/Complexitylib/Circuits/Internal/CircuitToDescriptor.lean index 93936494..e994108d 100644 --- a/Complexitylib/Circuits/Internal/CircuitToDescriptor.lean +++ b/Complexitylib/Circuits/Internal/CircuitToDescriptor.lean @@ -140,6 +140,7 @@ theorem wireValue_eq_wireVal {N G : Nat} [NeZero N] rw [this]; clear this -- Now both sides use encodeGate gate; unfold and simplify simp [encodeGate] + rfl intro h' j exact (show ∀ (g : Gate Basis.andOr2 (N + G)) (heq : g = c.gates ⟨↑w - N, h'⟩) (hfanIn : (c.gates ⟨↑w - N, h'⟩).fanIn = g.fanIn) @@ -169,5 +170,6 @@ theorem circuit_eval_eq_eval {N G : Nat} [NeZero N] exact Nat.lt_of_lt_of_le ((c.outputs 0).inputs ⟨1, by omega⟩).isLt (by omega), ite_true] simp only [show ¬(N + G.succ - 1 < N) from by omega, dite_false] + rfl end Complexity diff --git a/Complexitylib/Circuits/Internal/NormalForm.lean b/Complexitylib/Circuits/Internal/NormalForm.lean index 04f5dc17..4150a0a6 100644 --- a/Complexitylib/Circuits/Internal/NormalForm.lean +++ b/Complexitylib/Circuits/Internal/NormalForm.lean @@ -376,13 +376,13 @@ theorem DNF.two_pow_le_complexity_of_flipSensitive (φ : DNF N) (hN : 1 ≤ N) (fun x => φ.terms.findIdx (fun t => t.all (fun l => l.eval x))) · -- MapsTo: findIdx lands in range intro x hx - simp only [Finset.coe_filter, Finset.mem_univ, Set.mem_setOf, true_and] at hx + simp only [Finset.coe_filter, Finset.mem_univ, Set.mem_ofPred, true_and] at hx simp only [Finset.coe_range, Set.mem_Iio, DNF.complexity] rw [List.findIdx_lt_length] exact hfind x hx · -- InjOn: two true assignments with same findIdx must be equal intro x₁ hx₁ x₂ hx₂ heq - simp only [Finset.coe_filter, Finset.mem_univ, Set.mem_setOf, true_and] at hx₁ hx₂ + simp only [Finset.coe_filter, Finset.mem_univ, Set.mem_ofPred, true_and] at hx₁ hx₂ set k := φ.terms.findIdx (fun t => t.all (fun l => l.eval x₂)) have hlt : k < φ.terms.length := by rw [List.findIdx_lt_length]; exact hfind x₂ hx₂ diff --git a/Complexitylib/Circuits/Internal/Schnorr.lean b/Complexitylib/Circuits/Internal/Schnorr.lean index f35ff0b5..4f83d6a4 100644 --- a/Complexitylib/Circuits/Internal/Schnorr.lean +++ b/Complexitylib/Circuits/Internal/Schnorr.lean @@ -219,9 +219,16 @@ private theorem wireVal_restrictD {N s : Nat} (d : CircDesc (N + 1) s) have hgi : w.val + 1 - (N + 1) = w.val - N := by omega simp only [restrictD, hgi] -- Both sides branch on isAnd; congr reduces to per-wire-input goals - split <;> (congr 1 <;> [skip; skip]) <;> - exact remapWireR_effective d a b x w hw _ _ - (fun w' hw' => wireVal_restrictD d a b x w') + split <;> rename_i hAnd + · simp only [hAnd, ite_true] + congr 1 <;> + exact remapWireR_effective d a b x w hw _ _ + (fun w' hw' => wireVal_restrictD d a b x w') + · simp only [Bool.not_eq_true] at hAnd + simp only [hAnd, Bool.false_eq_true, ite_false] + congr 1 <;> + exact remapWireR_effective d a b x w hw _ _ + (fun w' hw' => wireVal_restrictD d a b x w') termination_by w.val /-- Evaluating the restricted circuit on `x` agrees with evaluating the original circuit @@ -461,7 +468,7 @@ private theorem xor_needs_three_gates {N s : Nat} (hN : 2 ≤ N) (hs : 0 < s) (h · subst N -- The two possible gate counts are finite truth-table checks. `+kernel` -- makes the kernel reduce and verify the resulting proof term. - interval_cases s <;> (decide +revert +kernel) + interval_cases s <;> (set_option maxRecDepth 10000 in decide +revert +kernel) · have hN' : 2 ≤ N := by omega intro d comp heval apply ih hN' hs hs2 (restrictD d ⟨0, by omega⟩ false) comp diff --git a/Complexitylib/Circuits/Internal/ShannonUpper.lean b/Complexitylib/Circuits/Internal/ShannonUpper.lean index d3fa580c..05a71912 100644 --- a/Complexitylib/Circuits/Internal/ShannonUpper.lean +++ b/Complexitylib/Circuits/Internal/ShannonUpper.lean @@ -190,8 +190,8 @@ private theorem binop_wireValue_c₁ {N G₁ G₂ : Nat} [NeZero N] -- Change goal to use binopGWP change (binopGWP c₁ c₂ ⟨n - N, _⟩).val.eval _ = _ -- Unfold binopGWP for the first branch - simp only [binopGWP, dif_pos hg] - rw [mkGate2'_eval, andOr2_gate_eval_two_inputs] + simp only [binopGWP, dite_eq_left hg] + erw [mkGate2'_eval, andOr2_gate_eval_two_inputs] have hacyc0 : (gw 0 (c₁.gates ⟨n - N, hg⟩)).val < n := by have := c₁.acyclic ⟨_, hg⟩ ⟨0, by rw [fanIn_andOr2]; omega⟩ simp [gw] at this ⊢; omega @@ -220,10 +220,10 @@ private theorem binop_wireValue_c₂ {N G₁ G₂ : Nat} [NeZero N] intro hn by_cases hlt : n < N · -- Input wire: remap₂ preserves it - simp only [remap₂, dif_pos hlt] + simp only [remap₂, dite_eq_left hlt] rw [Circuit.wireValue_of_lt _ _ _ hlt, Circuit.wireValue_of_lt _ _ _ hlt] · -- Gate wire: remap₂ shifts by G₁ + 1 - simp only [remap₂, dif_neg hlt] + simp only [remap₂, dite_eq_right hlt] have hge : ¬(n + G₁ + 1 < N) := by omega rw [Circuit.wireValue_of_not_lt _ _ _ hge, Circuit.wireValue_of_not_lt _ _ _ hlt] have hg₂ : n - N < G₂ := by omega @@ -234,8 +234,8 @@ private theorem binop_wireValue_c₂ {N G₁ G₂ : Nat} [NeZero N] have hb1 : ¬(n + G₁ + 1 - N < G₁) := by omega have hb2 : ¬(n + G₁ + 1 - N = G₁) := by omega have hb3 : n + G₁ + 1 - N < G₁ + 1 + G₂ := by omega - simp only [binopGWP, dif_neg hb1, dif_neg hb2, dif_pos hb3] - rw [mkGate2'_eval, andOr2_gate_eval_two_inputs] + simp only [binopGWP, dite_eq_right hb1, dite_eq_right hb2, dite_eq_left hb3] + erw [mkGate2'_eval, andOr2_gate_eval_two_inputs] -- Simplify gate index have : (⟨n + G₁ + 1 - N - G₁ - 1, by omega⟩ : Fin G₂) = ⟨n - N, hg₂⟩ := by ext; simp; omega @@ -280,7 +280,7 @@ theorem binopCircuit_or_correct {N G₁ G₂ : Nat} [NeZero N] ⟨G₁, by omega⟩ := Fin.ext (show N + G₁ - N = G₁ by omega) rw [hfin] simp only [binopGWP, show ¬(G₁ < G₁) from Nat.lt_irrefl G₁, dite_false, dite_true] - rw [mkGate2'_eval, andOr2_gate_eval_two_inputs] + erw [mkGate2'_eval, andOr2_gate_eval_two_inputs] cases (c₁.outputs 0).op <;> simp only <;> congr 1 <;> congr 1 all_goals (apply binop_wireValue_c₁; exact (gw _ (c₁.outputs 0)).isLt) -- Wire N + G₁ + G₂ + 1 corresponds to c₂'s output gate @@ -298,7 +298,7 @@ theorem binopCircuit_or_correct {N G₁ G₂ : Nat} [NeZero N] show ¬(G₁ + G₂ + 1 = G₁) by omega, show ¬(G₁ + G₂ + 1 < G₁ + 1 + G₂) by omega, dite_false] - rw [mkGate2'_eval, andOr2_gate_eval_two_inputs] + erw [mkGate2'_eval, andOr2_gate_eval_two_inputs] cases (c₂.outputs 0).op <;> simp only <;> congr 1 <;> congr 1 all_goals (apply binop_wireValue_c₂) -- The output gate of cb applies OR to these two wires @@ -681,6 +681,9 @@ theorem columnPatternIndex_lt (N : Nat) (f : BitString N → Bool) /-! ### Shannon gate array -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private noncomputable def shannonGateArray (N : Nat) [NeZero N] (f : BitString N → Bool) (hN : 16 ≤ N) : (i : Fin (totalSectionGates (addrBits N) (dataBits N))) → @@ -1018,6 +1021,9 @@ private def shiftedBits (N k q : Nat) (hkq : k + q = N) (x : BitString N) : fun j => x ⟨k + j.val, by have := j.isLt; omega⟩ /-- columnFunction at the actual bit-vector address/data values equals f(x). -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private theorem columnFunction_at_actual_bits (N : Nat) [NeZero N] (f : BitString N → Bool) (x : BitString N) (k q : Nat) (hkq : k + q = N) : @@ -1124,6 +1130,9 @@ private theorem dataSum_lt (N : Nat) (hN : 16 ≤ N) (x : BitString N) : sum_cond_pow_fin_lt (dataBits N) (shiftedBits N (addrBits N) (dataBits N) (addrDataSum N hN) x) /-- andLayerSem at y is false when y ≠ dataSum. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private theorem andLayerSem_ne (N : Nat) [NeZero N] (f : BitString N → Bool) (hN : 16 ≤ N) (x : BitString N) (y : Nat) (hy : y < 2 ^ dataBits N) (hne : y ≠ dataSum N hN x) : @@ -1149,9 +1158,9 @@ private theorem or_andLayerSem_eq_f (N : Nat) [NeZero N] have hP_ne : ∀ y, y < 2 ^ dataBits N → y ≠ dataSum N hN x → (if h : y < 2 ^ dataBits N then andLayerSem N f hN x y h else false) = false := by intro y hy hne - rw [dif_pos hy, andLayerSem_ne N f hN x y hy hne] + rw [dite_eq_left hy, andLayerSem_ne N f hN x y hy hne] have hfoldl := foldl_or_unique_true (dataSum N hN x) hds_lt hP_ne - rw [hfoldl, dif_pos hds_lt, andLayerSem_eq N f hN x] + rw [hfoldl, dite_eq_left hds_lt, andLayerSem_eq N f hN x] /-! The OR chain accumulates AND-layer semantic values. @@ -1203,19 +1212,19 @@ private theorem wireValue_dataLeaf (N : Nat) [NeZero N] change (shannonGateArray N f hN ⟨_, _⟩).val.eval _ = _ unfold shannonGateArray simp only [show N + 1 + j - N = 1 + j from by omega] - rw [dif_neg (by omega : ¬(1 + j = 0))] - rw [dif_pos (by unfold addrTreeOffset; omega : 1 + j < addrTreeOffset (dataBits N))] + rw [dite_eq_right (by omega : ¬(1 + j = 0))] + rw [dite_eq_left (by unfold addrTreeOffset; omega : 1 + j < addrTreeOffset (dataBits N))] simp only [show 1 + j - 1 = j from by omega] by_cases hjL1 : j < 4 · - rw [dif_pos hjL1] + rw [dite_eq_left hjL1] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.true_and] simp only [Fin.val_last, Fin.val_castSucc, ite_true, ite_false, show ¬((1 : Nat) = 0) from by omega] - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨addrBits N, _⟩ : Fin _).val < N from by + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨addrBits N, _⟩ : Fin _).val < N from by show addrBits N < N; have := addr_le_N N hN; omega)] - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨addrBits N + 1, _⟩ : Fin _).val < N from by + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨addrBits N + 1, _⟩ : Fin _).val < N from by show addrBits N + 1 < N; have := addr_le_N N hN; omega)] have htl : treeLevel j = 1 := by unfold treeLevel @@ -1247,7 +1256,7 @@ private theorem wireValue_dataLeaf (N : Nat) [NeZero N] cases x ⟨addrBits N, by omega⟩ <;> cases x ⟨addrBits N + 1, by omega⟩ <;> cases j.testBit 1 <;> cases (decide (j % 2 = 1)) <;> simp_all · - rw [dif_neg hjL1] + rw [dite_eq_right hjL1] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.true_and] simp only [Fin.val_last, Fin.val_castSucc, ite_true, ite_false, @@ -1257,7 +1266,7 @@ private theorem wireValue_dataLeaf (N : Nat) [NeZero N] have hbase : treeBase (treeLevel j) ≤ j := treeBase_le_of_level j (by omega) have hpi_lt : treeParentIndex (treeLevel j) (treePosition j (treeLevel j)) < j := treeParentIndex_lt_j _ _ j hl2 rfl hbase - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨addrBits N + treeLevel j, _⟩ : Fin _).val < N + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨addrBits N + treeLevel j, _⟩ : Fin _).val < N from by show addrBits N + treeLevel j < N; omega)] have hpar := ih (treeParentIndex (treeLevel j) (treePosition j (treeLevel j))) hpi_lt (by omega) (by omega) @@ -1395,21 +1404,22 @@ private theorem wireValue_colOutput (N : Nat) [NeZero N] change (shannonGateArray N f hN ⟨_, _⟩).val.eval _ = _ unfold shannonGateArray simp only [show N + addrTreeOffset q + j - N = addrTreeOffset q + j from by omega] - rw [dif_neg (by unfold addrTreeOffset; omega : ¬(addrTreeOffset q + j = 0))] - rw [dif_neg (by unfold addrTreeOffset; omega : ¬(addrTreeOffset q + j < addrTreeOffset q))] - rw [dif_pos (by unfold columnLibraryOffset addrTreeOffset; omega : + rw [dite_eq_right (by unfold addrTreeOffset; omega : ¬(addrTreeOffset q + j = 0))] + rw [dite_eq_right + (by unfold addrTreeOffset; omega : ¬(addrTreeOffset q + j < addrTreeOffset q))] + rw [dite_eq_left (by unfold columnLibraryOffset addrTreeOffset; omega : addrTreeOffset q + j < columnLibraryOffset k q)] simp_rw [show addrTreeOffset q + j - addrTreeOffset (dataBits N) = j from by show addrTreeOffset q + j - addrTreeOffset q = j; omega] by_cases hjL1 : j < 4 - · rw [dif_pos hjL1] + · rw [dite_eq_left hjL1] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.true_and] simp only [Fin.val_last, Fin.val_castSucc, ite_true, ite_false, show ¬((1 : Nat) = 0) from by omega] - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨0, _⟩ : Fin _).val < N from by + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨0, _⟩ : Fin _).val < N from by show 0 < N; linarith [hkq, hk3])] - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨1, _⟩ : Fin _).val < N from by + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨1, _⟩ : Fin _).val < N from by show 1 < N; linarith [hkq, hk3])] have htl : treeLevel j = 1 := by unfold treeLevel @@ -1432,7 +1442,7 @@ private theorem wireValue_colOutput (N : Nat) [NeZero N] simp only [Fin.forall_fin_two, Fin.val_zero, Fin.val_one, Nat.testBit_zero] cases x ⟨0, hN2 0 (by omega)⟩ <;> cases x ⟨1, hN2 1 (by omega)⟩ <;> cases j.testBit 1 <;> cases (decide (j % 2 = 1)) <;> simp_all - · rw [dif_neg hjL1] + · rw [dite_eq_right hjL1] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.true_and] simp only [Fin.val_last, Fin.val_castSucc, ite_true, ite_false, @@ -1443,7 +1453,7 @@ private theorem wireValue_colOutput (N : Nat) [NeZero N] have hpi_lt : treeParentIndex (treeLevel j) (treePosition j (treeLevel j)) < j := treeParentIndex_lt_j _ _ j hl2 rfl hbase simp only [Bool.false_xor] - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨treeLevel j, _⟩ : Fin _).val < N from by + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨treeLevel j, _⟩ : Fin _).val < N from by show treeLevel j < N; linarith [hkq, hlk])] have hpar := ih (treeParentIndex (treeLevel j) (treePosition j (treeLevel j))) hpi_lt (by omega) (by omega) @@ -1536,12 +1546,12 @@ private theorem wireValue_colOutput (N : Nat) [NeZero N] change (shannonGateArray N f hN ⟨N - N, by omega⟩).val.eval ((shannonCircuit N f hN).wireValue x) = false unfold shannonGateArray - rw [dif_pos (show N - N = 0 from by omega)] + rw [dite_eq_left (show N - N = 0 from by omega)] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.true_and] simp only [Fin.val_last, Fin.val_castSucc, ite_true, ite_false, show ¬((1 : Nat) = 0) from by omega, Bool.false_xor, Bool.true_xor] - rw [Circuit.wireValue_of_lt _ _ _ (show (⟨0, _⟩ : Fin _).val < N from h0N)] + erw [Circuit.wireValue_of_lt _ _ _ (show (⟨0, _⟩ : Fin _).val < N from h0N)] cases x ⟨0, h0N⟩ <;> rfl have colChain : ∀ (r : Nat) (hr : r < 2 ^ k - 1) (hrW : N + columnLibraryOffset k q + p * (2 ^ k - 1) + r < N + totalSectionGates k q), @@ -1615,7 +1625,7 @@ private theorem wireValue_colOutput (N : Nat) [NeZero N] unfold shannonGateArray simp only [show N + columnLibraryOffset k q + p * (2 ^ k - 1) + 0 - N = columnLibraryOffset k q + p * (2 ^ k - 1) from by omega] - rw [dif_neg h_ne0, dif_neg h_ge_oC, dif_neg h_ge_oD, dif_pos h_lt_oE] + rw [dite_eq_right h_ne0, dite_eq_right h_ge_oC, dite_eq_right h_ge_oD, dite_eq_left h_lt_oE] simp only [show addrBits N = k from rfl, show dataBits N = q from rfl] simp only [show columnLibraryOffset k q + p * (2 ^ k - 1) - columnLibraryOffset k q = p * (2 ^ k - 1) from by omega] @@ -1658,7 +1668,8 @@ private theorem wireValue_colOutput (N : Nat) [NeZero N] unfold shannonGateArray simp only [show N + columnLibraryOffset k q + p * (2 ^ k - 1) + (r' + 1) - N = columnLibraryOffset k q + p * (2 ^ k - 1) + (r' + 1) from by omega] - rw [dif_neg h_ne0', dif_neg h_ge_oC', dif_neg h_ge_oD', dif_pos h_lt_oE'] + rw [dite_eq_right h_ne0', dite_eq_right h_ge_oC', dite_eq_right h_ge_oD', + dite_eq_left h_lt_oE'] simp only [show addrBits N = k from rfl, show dataBits N = q from rfl] simp_rw [show (columnLibraryOffset k q + p * (2 ^ k - 1) + (r' + 1) - columnLibraryOffset k q) = @@ -1726,18 +1737,18 @@ private theorem wireValue_orChain_sem (N : Nat) [NeZero N] unfold shannonGateArray simp only [show N + andLayerOffset (addrBits N) (dataBits N) + y - N = andLayerOffset (addrBits N) (dataBits N) + y from by omega] - rw [dif_neg (by + rw [dite_eq_right (by unfold andLayerOffset columnLibraryOffset addrTreeOffset; have := pow_ge_4 (dataBits N) (dataBits_ge_two N hN); omega : ¬(andLayerOffset (addrBits N) (dataBits N) + y = 0))] - rw [dif_neg (by unfold andLayerOffset columnLibraryOffset addrTreeOffset; omega : + rw [dite_eq_right (by unfold andLayerOffset columnLibraryOffset addrTreeOffset; omega : ¬(andLayerOffset (addrBits N) (dataBits N) + y < addrTreeOffset (dataBits N)))] - rw [dif_neg (by unfold andLayerOffset columnLibraryOffset; omega : + rw [dite_eq_right (by unfold andLayerOffset columnLibraryOffset; omega : ¬(andLayerOffset (addrBits N) (dataBits N) + y < columnLibraryOffset (addrBits N) (dataBits N)))] - rw [dif_neg (by unfold andLayerOffset; omega : + rw [dite_eq_right (by unfold andLayerOffset; omega : ¬(andLayerOffset (addrBits N) (dataBits N) + y < andLayerOffset (addrBits N) (dataBits N)))] - rw [dif_pos (by unfold orChainOffset; omega : + rw [dite_eq_left (by unfold orChainOffset; omega : andLayerOffset (addrBits N) (dataBits N) + y < orChainOffset (addrBits N) (dataBits N))] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.true_and, ite_self, Bool.false_xor] @@ -1769,17 +1780,18 @@ private theorem wireValue_orChain_sem (N : Nat) [NeZero N] unfold shannonGateArray simp only [show N + orChainOffset (addrBits N) (dataBits N) + 0 - N = orChainOffset (addrBits N) (dataBits N) + 0 from by omega] - rw [dif_neg (by + rw [dite_eq_right (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + 0 = 0))] - rw [dif_neg (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : + rw [dite_eq_right + (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + 0 < addrTreeOffset (dataBits N)))] - rw [dif_neg (by unfold orChainOffset andLayerOffset columnLibraryOffset; omega : + rw [dite_eq_right (by unfold orChainOffset andLayerOffset columnLibraryOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + 0 < columnLibraryOffset (addrBits N) (dataBits N)))] - rw [dif_neg (by unfold orChainOffset andLayerOffset; omega : + rw [dite_eq_right (by unfold orChainOffset andLayerOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + 0 < andLayerOffset (addrBits N) (dataBits N)))] - rw [dif_neg (by omega : + rw [dite_eq_right (by omega : ¬(orChainOffset (addrBits N) (dataBits N) + 0 < orChainOffset (addrBits N) (dataBits N)))] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, Fin.foldl_succ_last, Fin.foldl_zero, Bool.false_or, ite_self, Bool.false_xor] @@ -1799,8 +1811,8 @@ private theorem wireValue_orChain_sem (N : Nat) [NeZero N] andLayer_sem 1 (by omega) (by linarith)] simp only [show List.range (0 + 2) = [0, 1] from by decide, List.foldl_cons, List.foldl_nil, - Bool.false_or, dif_pos (show 0 < 2 ^ dataBits N from by omega), - dif_pos (show 1 < 2 ^ dataBits N from by omega)] + Bool.false_or, dite_eq_left (show 0 < 2 ^ dataBits N from by omega), + dite_eq_left (show 1 < 2 ^ dataBits N from by omega)] | succ r' ih => -- unfolds shannonGateArray through all five section guards; genuine elaboration cost set_option maxHeartbeats 3200000 in @@ -1812,17 +1824,19 @@ private theorem wireValue_orChain_sem (N : Nat) [NeZero N] unfold shannonGateArray simp only [show N + orChainOffset (addrBits N) (dataBits N) + (r' + 1) - N = orChainOffset (addrBits N) (dataBits N) + (r' + 1) from by omega] - rw [dif_neg (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : + rw [dite_eq_right + (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + (r' + 1) = 0))] - rw [dif_neg (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : + rw [dite_eq_right + (by unfold orChainOffset andLayerOffset columnLibraryOffset addrTreeOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + (r' + 1) < addrTreeOffset (dataBits N)))] - rw [dif_neg (by unfold orChainOffset andLayerOffset columnLibraryOffset; omega : + rw [dite_eq_right (by unfold orChainOffset andLayerOffset columnLibraryOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + (r' + 1) < columnLibraryOffset (addrBits N) (dataBits N)))] - rw [dif_neg (by unfold orChainOffset andLayerOffset; omega : + rw [dite_eq_right (by unfold orChainOffset andLayerOffset; omega : ¬(orChainOffset (addrBits N) (dataBits N) + (r' + 1) < andLayerOffset (addrBits N) (dataBits N)))] - rw [dif_neg (by omega : + rw [dite_eq_right (by omega : ¬(orChainOffset (addrBits N) (dataBits N) + (r' + 1) < orChainOffset (addrBits N) (dataBits N)))] simp only [mkG, Gate.eval, Basis.andOr2, AndOrOp.eval, @@ -1851,13 +1865,13 @@ private theorem wireValue_orChain_sem (N : Nat) [NeZero N] have hr2 : r' + 2 < 2 ^ dataBits N := by omega rw [show andLayerSem N f hN x (r' + 2) hr2 = (if h : r' + 2 < 2 ^ dataBits N then andLayerSem N f hN x (r' + 2) h else false) from - by rw [dif_pos hr2]] + by rw [dite_eq_left hr2]] rw [Bool.or_assoc] simp only [show r' + 1 + 2 = r' + 2 + 1 from by omega, show r' + 2 = r' + 1 + 1 from by omega, List.range_succ, List.foldl_append, List.foldl_cons, List.foldl_nil, - dif_pos (show r' + 2 < 2 ^ dataBits N from by omega), - dif_pos (show r' + 1 < 2 ^ dataBits N from by omega), + dite_eq_left (show r' + 2 < 2 ^ dataBits N from by omega), + dite_eq_left (show r' + 1 < 2 ^ dataBits N from by omega), Bool.or_assoc] private theorem lastOrChain_eq_f (N : Nat) [NeZero N] diff --git a/Complexitylib/Circuits/Internal/Simulation.lean b/Complexitylib/Circuits/Internal/Simulation.lean index 75c3b5d0..03255761 100644 --- a/Complexitylib/Circuits/Internal/Simulation.lean +++ b/Complexitylib/Circuits/Internal/Simulation.lean @@ -692,7 +692,8 @@ private lemma compileGate_eval_at_iOffset (c : Circuit Basis.unboundedAndOr N M -- and close subgoals with Fin.ext + iSegLookup_eq. unfold compileGates simp only [compileGateOp, compileGateInputs, compileGateNeg, Fin.val_mk, - dif_pos hInternal, mkChainGate] + dite_eq_left hInternal, mkChainGate] + simp only [hSeg1] convert rfl using 8 all_goals first | rfl @@ -742,7 +743,7 @@ private theorem lastChainValue_eq (c : Circuit Basis.unboundedAndOr N M G) (inpu · -- LHS = identity: unfold and use dual_const simp only [hk0, chainLen_zero, Nat.sub_self, mkChainGate, mkChainOp, mkChainInputs, mkChainNeg, - dite_true, ite_true, + dite_true, Gate.eval, Basis.andOr2, fin2] exact AndOrOp.dual_const _ _ · -- RHS = identity: unfold Gate.eval, use AndOrOp.eval_eq_foldl, then simplify @@ -784,20 +785,20 @@ private theorem lastChainValue_eq (c : Circuit Basis.unboundedAndOr N M G) (inpu intro j hj induction j with | zero => - rw [mkChainGate_eval_ge2_zero _ (by omega : 2 ≤ _)] + erw [mkChainGate_eval_ge2_zero _ (by omega : 2 ≤ _)] rw [hv_remap ⟨0, by omega⟩, hv_remap ⟨1, by omega⟩] - rw [partialFold_two _ v (by omega)] - rw [AndOrOp.identity_binOp] + erw [partialFold_two _ v (by omega)] + erw [AndOrOp.identity_binOp] | succ j' ih => - rw [mkChainGate_eval_ge2_succ _ (by omega : 2 ≤ _) _ _ + erw [mkChainGate_eval_ge2_succ _ (by omega : 2 ≤ _) _ _ (by unfold G'; omega) hj (by unfold G'; omega)] rw [hv_remap ⟨j' + 2, by rw [hcl] at hj; omega⟩] rw [chain_wire j' (by rw [hcl] at hj ⊢; omega), ih (by rw [hcl] at hj ⊢; omega)] - rw [partialFold_succ _ v (j' + 2) (by rw [hcl] at hj; omega)] + erw [partialFold_succ _ v (j' + 2) (by rw [hcl] at hj; omega)] rw [h_fold _ (by omega)] have hk_eq : chainLen (c.gates ⟨i, hi⟩).fanIn - 1 + 2 = (c.gates ⟨i, hi⟩).fanIn := by omega - rw [hk_eq, partialFold_full] + rw [hk_eq]; erw [partialFold_full] simp only [Gate.eval, Basis.unboundedAndOr, AndOrOp.eval_eq_foldl] rfl @@ -857,7 +858,11 @@ private lemma compileGate_eval_at_oOffset (c : Circuit Basis.unboundedAndOr N M have hSeg := oSegLookup_eq c j' hj' p hp hoff_lt unfold compileGates simp only [compileGateOp, compileGateInputs, compileGateNeg, Fin.val_mk, - dif_neg hNotInternal, mkChainGate] + dite_eq_right hNotInternal, mkChainGate] + simp only [hoff] + have hSeg1 : (segLookup M (oChainF c) (prefixSum (oChainF c) j' + p) hoff_lt).1 = j' := by + rw [hSeg] + simp only [hSeg1] convert rfl using 8 all_goals first | rfl @@ -908,7 +913,7 @@ private theorem lastOutputChainValue_eq (c : Circuit Basis.unboundedAndOr N M G) trans (c.outputs ⟨j', hj'⟩).op.identity · simp only [hk0, chainLen_zero, Nat.sub_self, mkChainGate, mkChainOp, mkChainInputs, mkChainNeg, - dite_true, ite_true, + dite_true, Gate.eval, Basis.andOr2, fin2] exact AndOrOp.dual_const _ _ · simp only [Gate.eval, Basis.unboundedAndOr, AndOrOp.eval_eq_foldl, hk0, Fin.foldl_zero] @@ -947,21 +952,21 @@ private theorem lastOutputChainValue_eq (c : Circuit Basis.unboundedAndOr N M G) intro p hp induction p with | zero => - rw [mkChainGate_eval_ge2_zero _ (by omega : 2 ≤ _)] + erw [mkChainGate_eval_ge2_zero _ (by omega : 2 ≤ _)] rw [hv_remap ⟨0, by omega⟩, hv_remap ⟨1, by omega⟩] - rw [partialFold_two _ v (by omega)] - rw [AndOrOp.identity_binOp] + erw [partialFold_two _ v (by omega)] + erw [AndOrOp.identity_binOp] | succ p' ih => - rw [mkChainGate_eval_ge2_succ _ (by omega : 2 ≤ _) _ _ + erw [mkChainGate_eval_ge2_succ _ (by omega : 2 ≤ _) _ _ (by omega) hp (by omega)] rw [hv_remap ⟨p' + 2, by rw [hcl] at hp; omega⟩] rw [chain_wire p' (by rw [hcl] at hp ⊢; omega), ih (by rw [hcl] at hp ⊢; omega)] - rw [partialFold_succ _ v (p' + 2) (by rw [hcl] at hp; omega)] + erw [partialFold_succ _ v (p' + 2) (by rw [hcl] at hp; omega)] rw [h_fold _ (by omega)] have hk_eq : chainLen (c.outputs ⟨j', hj'⟩).fanIn - 1 + 2 = (c.outputs ⟨j', hj'⟩).fanIn := by omega - rw [hk_eq, partialFold_full] + rw [hk_eq]; erw [partialFold_full] simp only [Gate.eval, Basis.unboundedAndOr, AndOrOp.eval_eq_foldl] rfl diff --git a/Complexitylib/Circuits/Internal/Spira.lean b/Complexitylib/Circuits/Internal/Spira.lean index 8649fd73..4358b80e 100644 --- a/Complexitylib/Circuits/Internal/Spira.lean +++ b/Complexitylib/Circuits/Internal/Spira.lean @@ -320,7 +320,7 @@ private theorem spiraBalance_eval (formula : BoolFormula) balancedFalse ihSubformula ihTrue ihFalse => simp only [balancedSubformula, balancedTrue, balancedFalse, split, eval, ihSubformula, ihTrue, ihFalse] - simpa only [spiraSplit_plug] using + simpa only [spiraSplit_plug, eval] using (Context.eval_plug_shannon (spiraSplit formula).1 (spiraSplit formula).2 assignment).symm | case2 formula hsmall => diff --git a/Complexitylib/Circuits/Internal/Valiant.lean b/Complexitylib/Circuits/Internal/Valiant.lean index d9eb4d7b..765899f1 100644 --- a/Complexitylib/Circuits/Internal/Valiant.lean +++ b/Complexitylib/Circuits/Internal/Valiant.lean @@ -156,6 +156,9 @@ omit [Fintype V] in /-- **Extending a simple path by an edge.** In an acyclic digraph, a simple path `p` ending at `u` followed by an edge `u → v` yields a simple path ending at `v` that is one longer. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private lemma extend_simple_path [DecidableEq V] (G : Digraph V) (hac : IsAcyclic G) {u v : V} (huv : G.Adj u v) {n : ℕ} {p : Fin (n + 1) → V} (hsp : G.IsPath p) (hpu : p (Fin.last n) = u) : @@ -310,7 +313,7 @@ private lemma firstDifferBit_of_ne have hxor_ne : x ^^^ y ≠ 0 := Nat.xor_ne_zero_iff.mpr hxne have hxor_lt : x ^^^ y < 2 ^ k := Nat.xor_lt_two_pow hx hy have hlog_lt : Nat.log2 (x ^^^ y) < k := (Nat.log2_lt hxor_ne).mpr hxor_lt - simp only [firstDifferBit, if_neg hxne] + simp only [firstDifferBit, ite_eq_right hxne] omega omit [Fintype V] in @@ -564,7 +567,7 @@ private lemma maskOutI_lt_of_firstDifferBit_not_mem have hmask_y := maskOutI_split_at_pivot hj_mem_D y rw [hx_bit_false] at hmask_x rw [hy_bit_true] at hmask_y - simp only [Bool.false_eq_true, if_false, add_zero, if_true] at hmask_x hmask_y + simp only [Bool.false_eq_true, ite_false, add_zero, ite_true] at hmask_x hmask_y have hlow_x_lt := maskOutI_sum_below_lt I hj_le x rw [hmask_x, hmask_y, ← hup_eq] omega diff --git a/Complexitylib/Circuits/KeyedMinimumTournament/Family/Internal.lean b/Complexitylib/Circuits/KeyedMinimumTournament/Family/Internal.lean index a23210c2..0d69d30c 100644 --- a/Complexitylib/Circuits/KeyedMinimumTournament/Family/Internal.lean +++ b/Complexitylib/Circuits/KeyedMinimumTournament/Family/Internal.lean @@ -36,8 +36,8 @@ theorem eval_parallelKeyedRecordFamily_internal BitString.packKeyedRecords count keys payloads := by induction count with | zero => - simpa [parallelKeyedRecordFamily, BitString.packKeyedRecords] using - heval 0 + simp only [parallelKeyedRecordFamily, BitString.packKeyedRecords] + exact heval 0 | succ count ih => simp only [parallelKeyedRecordFamily, BitString.packKeyedRecords] have hparallel := Circuit.eval_parallel diff --git a/Complexitylib/Circuits/KeyedMinimumTournament/Internal.lean b/Complexitylib/Circuits/KeyedMinimumTournament/Internal.lean index 285039b8..338fec13 100644 --- a/Complexitylib/Circuits/KeyedMinimumTournament/Internal.lean +++ b/Complexitylib/Circuits/KeyedMinimumTournament/Internal.lean @@ -96,12 +96,14 @@ theorem eval_unsignedKeyedMinTournament_internal Fin.append winner.1 winner.2 := by induction count with | zero => - simp [unsignedKeyedMinTournament, BitString.packKeyedRecords, - BitString.unsignedMinimumKeyedRecord, Function.comp_def] + simp only [unsignedKeyedMinTournament, BitString.packKeyedRecords, + BitString.unsignedMinimumKeyedRecord] + erw [Circuit.eval_projectInputs_internal] + rfl | succ count ih => simp only [unsignedKeyedMinTournament, BitString.packKeyedRecords, BitString.unsignedMinimumKeyedRecord] - rw [Circuit.eval_compose] + erw [Circuit.eval_compose] have hparallel := Circuit.eval_parallel ((unsignedKeyedMinTournament keyWidth payloadWidth count).2.reindexInputs (Fin.castAdd (keyWidth + payloadWidth))) @@ -186,10 +188,12 @@ theorem size_unsignedKeyedMinTournament_internal count * (20 * keyWidth + 5 * payloadWidth + 1) := by induction count with | zero => - simp [unsignedKeyedMinTournament] + simp only [unsignedKeyedMinTournament] + erw [Circuit.size_projectInputs] + omega | succ count ih => simp only [unsignedKeyedMinTournament] - rw [Circuit.size_compose] + erw [Circuit.size_compose] have hparallel := Circuit.size_parallel ((unsignedKeyedMinTournament keyWidth payloadWidth count).2.reindexInputs (Fin.castAdd (keyWidth + payloadWidth))) diff --git a/Complexitylib/Circuits/Majority/Internal.lean b/Complexitylib/Circuits/Majority/Internal.lean index 30014671..de204fb8 100644 --- a/Complexitylib/Circuits/Majority/Internal.lean +++ b/Complexitylib/Circuits/Majority/Internal.lean @@ -80,7 +80,7 @@ theorem eval?_strictMajorityRawCircuit_internal (inputCount : ℕ) (strictMajorityThreshold inputCount) (fun i : Fin inputCount => i.val) rw [RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false, heval'] + simp only [hnonempty, Bool.false_eq_true, ite_false, heval'] rw [houtputIndex] exact houtput diff --git a/Complexitylib/Circuits/Multiplexer/Internal.lean b/Complexitylib/Circuits/Multiplexer/Internal.lean index 971a9156..3f8274f6 100644 --- a/Complexitylib/Circuits/Multiplexer/Internal.lean +++ b/Complexitylib/Circuits/Multiplexer/Internal.lean @@ -18,6 +18,12 @@ namespace Complexity namespace Circuit +/-- Evaluation over `Basis.andOr2` is `AndOrOp.eval`; stated as an equation so it can be +rewritten without unfolding the basis inside the circuit's type. -/ +private theorem andOr2_eval_eq (op : AndOrOp) (n : ℕ) + (h : (Basis.andOr2.arity op).satisfiedBy n) (inputs : BitString n) : + Basis.andOr2.eval op n h inputs = AndOrOp.eval op n inputs := rfl + theorem wireValue_multiplexer_left_internal (width : ℕ) [NeZero width] (input : BitString (1 + (width + width))) (coordinate : Fin width) : (multiplexer width).wireValue input @@ -41,14 +47,13 @@ theorem wireValue_multiplexer_left_internal (width : ℕ) [NeZero width] ((multiplexer width).wireValue input) = _ unfold multiplexerInternalGate have hleft : (Fin.castAdd width coordinate).val < width := coordinate.isLt - rw [dif_pos hleft] + rw [dite_eq_left hleft] unfold Gate.eval - change AndOrOp.eval .and 2 _ = _ + simp only [andOr2_eval_eq] rw [AndOrOp.eval_two_and] - dsimp only simp only [Bool.false_xor] - rw [if_pos (by omega : (0 : Fin 2).val = 0)] - rw [if_neg (by omega : ¬(1 : Fin 2).val = 0)] + rw [ite_eq_left (by omega : (0 : Fin 2).val = 0)] + rw [ite_eq_right (by omega : ¬(1 : Fin 2).val = 0)] rw [Circuit.wireValue_of_lt _ _ _ (by simp; omega)] rw [Circuit.wireValue_of_lt _ _ _ (by simp; omega)] simp @@ -80,13 +85,12 @@ theorem wireValue_multiplexer_right_internal (width : ℕ) [NeZero width] unfold multiplexerInternalGate have hright : ¬(Fin.natAdd width coordinate).val < width := by simp - rw [dif_neg hright] + rw [dite_eq_right hright] unfold Gate.eval - change AndOrOp.eval .and 2 _ = _ + simp only [andOr2_eval_eq] rw [AndOrOp.eval_two_and] - dsimp only - rw [if_pos (by omega : (0 : Fin 2).val = 0)] - rw [if_neg (by omega : ¬(1 : Fin 2).val = 0)] + rw [ite_eq_left (by omega : (0 : Fin 2).val = 0)] + rw [ite_eq_right (by omega : ¬(1 : Fin 2).val = 0)] rw [Circuit.wireValue_of_lt _ _ _ (by simp; omega)] rw [Circuit.wireValue_of_lt _ _ _ (by simp; omega)] simp @@ -102,12 +106,11 @@ theorem eval_multiplexer_packed_internal (width : ℕ) [NeZero width] change (multiplexerOutputGate width coordinate).eval ((multiplexer width).wireValue input) = _ unfold Gate.eval multiplexerOutputGate - change AndOrOp.eval .or 2 _ = _ + simp only [andOr2_eval_eq] rw [AndOrOp.eval_two_or] - dsimp only simp only [Bool.false_xor] - rw [if_pos (by omega : (0 : Fin 2).val = 0)] - rw [if_neg (by omega : ¬(1 : Fin 2).val = 0)] + rw [ite_eq_left (by omega : (0 : Fin 2).val = 0)] + rw [ite_eq_right (by omega : ¬(1 : Fin 2).val = 0)] rw [wireValue_multiplexer_left_internal] rw [wireValue_multiplexer_right_internal] cases input ⟨0, by omega⟩ <;> simp @@ -121,7 +124,7 @@ theorem eval_multiplexer_internal (width : ℕ) [NeZero width] rw [eval_multiplexer_packed_internal] cases control <;> simp [BitString.multiplexerInput, Fin.append, Fin.addCases] - rw [dif_neg (by omega)] + rw [dite_eq_right (by omega)] apply congrArg right apply Fin.ext simp diff --git a/Complexitylib/Circuits/RandomRestriction/Internal.lean b/Complexitylib/Circuits/RandomRestriction/Internal.lean index e3f4f3d4..0e071c6d 100644 --- a/Complexitylib/Circuits/RandomRestriction/Internal.lean +++ b/Complexitylib/Circuits/RandomRestriction/Internal.lean @@ -31,6 +31,7 @@ theorem card_decodeSymbol_none_internal (q : ℕ) : Finset.univ.filter (fun symbol : Symbol q => decodeSymbol symbol = none) = {Sum.inl ()} := by ext symbol + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_singleton] cases symbol with | inl freeValue => cases freeValue @@ -115,6 +116,7 @@ theorem card_decodeSymbol_some_internal (q : ℕ) (value : Bool) : decodeSymbol symbol = some value) = Finset.univ.image embed := by ext symbol + simp only [Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_image] cases symbol with | inl freeValue => cases freeValue diff --git a/Complexitylib/Circuits/Threshold/Internal.lean b/Complexitylib/Circuits/Threshold/Internal.lean index 86e8f3f8..4f9f62ae 100644 --- a/Complexitylib/Circuits/Threshold/Internal.lean +++ b/Complexitylib/Circuits/Threshold/Internal.lean @@ -150,9 +150,8 @@ theorem eval_conjunction_internal (n : ℕ) (ThresholdOp.conjunction n).eval n inputs = AndOrOp.eval .and n inputs := by rw [Bool.eq_iff_iff] - simp only [ThresholdOp.eval, ThresholdOp.conjunction, - ThresholdOp.trueCount, decide_eq_true_eq, - and_eval_eq_true_iff] + unfold ThresholdOp.eval ThresholdOp.conjunction ThresholdOp.trueCount + simp only [decide_eq_true_eq, and_eval_eq_true_iff] have hcount := Fin.countP_le inputs rw [show n ≤ Fin.countP inputs ↔ Fin.countP inputs = n by omega] @@ -163,9 +162,8 @@ theorem eval_disjunction_internal (n : ℕ) ThresholdOp.disjunction.eval n inputs = AndOrOp.eval .or n inputs := by rw [Bool.eq_iff_iff] - simp only [ThresholdOp.eval, ThresholdOp.disjunction, - ThresholdOp.trueCount, decide_eq_true_eq, - or_eval_eq_true_iff] + unfold ThresholdOp.eval ThresholdOp.disjunction ThresholdOp.trueCount + simp only [decide_eq_true_eq, or_eval_eq_true_iff] rw [show 1 ≤ Fin.countP inputs ↔ 0 < Fin.countP inputs by omega] exact countP_pos_iff n inputs @@ -175,8 +173,8 @@ theorem eval_majority_internal (n : ℕ) (ThresholdOp.majority n).eval n inputs = decide (n / 2 < Fin.countP inputs) := by rw [Bool.eq_iff_iff] - simp only [ThresholdOp.eval, ThresholdOp.majority, - ThresholdOp.trueCount, decide_eq_true_eq] + unfold ThresholdOp.eval ThresholdOp.majority ThresholdOp.trueCount + simp only [decide_eq_true_eq] omega theorem eval_zero_internal (n : ℕ) (inputs : BitString n) : @@ -186,8 +184,8 @@ theorem eval_zero_internal (n : ℕ) (inputs : BitString n) : theorem eval_of_arity_lt_internal {cutoff n : ℕ} (hcutoff : n < cutoff) (inputs : BitString n) : (ThresholdOp.mk cutoff).eval n inputs = false := by - simp only [ThresholdOp.eval, ThresholdOp.trueCount, - decide_eq_false_iff_not] + unfold ThresholdOp.eval ThresholdOp.trueCount + simp only [decide_eq_false_iff_not] have hcount := Fin.countP_le inputs omega diff --git a/Complexitylib/Circuits/Unrolling/Acceptance/Internal/Evaluation.lean b/Complexitylib/Circuits/Unrolling/Acceptance/Internal/Evaluation.lean index 1b4b1a3f..390dfaf5 100644 --- a/Complexitylib/Circuits/Unrolling/Acceptance/Internal/Evaluation.lean +++ b/Complexitylib/Circuits/Unrolling/Acceptance/Internal/Evaluation.lean @@ -56,8 +56,8 @@ theorem evalAux?_acceptanceRawCircuit_internal traceResult[configWire tm T (traceOutputBase tm T n available layout) (.cell .output ⟨1, by omega⟩ Γ.one)]? = some (decide (c.output.cells 1 = Γ.one)) := by - simpa [c, ConfigAtom.value, TapeSlot.get] using - hencodes (.cell .output ⟨1, by omega⟩ Γ.one) + simp only [c] + exact hencodes (.cell .output ⟨1, by omega⟩ Γ.one) have hacceptance : (decide (c.state = tm.qhalt) && decide (c.output.cells 1 = Γ.one)) = decide (c.state = tm.qhalt ∧ c.output.cells 1 = Γ.one) := by @@ -124,7 +124,7 @@ theorem eval?_acceptanceRawCircuit_internal (acceptanceRawCircuit tm T n available layout).isEmpty = false := by simp [acceptanceRawCircuit] rw [CircuitCode.RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false, wires, heval] + simp only [hnonempty, Bool.false_eq_true, ite_false, wires, heval] rw [houtputIndex] exact Array.getElem?_push_size diff --git a/Complexitylib/Circuits/Unrolling/Amplification/Internal/Evaluation.lean b/Complexitylib/Circuits/Unrolling/Amplification/Internal/Evaluation.lean index 722d30d9..57920336 100644 --- a/Complexitylib/Circuits/Unrolling/Amplification/Internal/Evaluation.lean +++ b/Complexitylib/Circuits/Unrolling/Amplification/Internal/Evaluation.lean @@ -87,7 +87,7 @@ theorem evalAux?_prefixAcceptanceCopiesBuild_internal have hprimaryNonzero := NeZero.ne primaryAvailable change primaryAvailable + previous.circuit.length ≠ 0 omega - letI : NeZero (previous.available primaryAvailable) := + let : NeZero (previous.available primaryAvailable) := ⟨hpreviousNonzero⟩ have hdataMiddle : ∀ j, middle[(runLayout.data j).val]? = some (x j) := by @@ -279,7 +279,7 @@ theorem evalAux?_amplifiedAcceptanceRawCircuit_internal have hprimaryNonzero := NeZero.ne primaryAvailable change primaryAvailable + built.circuit.length ≠ 0 omega - letI : NeZero thresholdAvailable := ⟨hthresholdAvailableNonzero⟩ + let : NeZero thresholdAvailable := ⟨hthresholdAvailableNonzero⟩ obtain ⟨result, hevalThreshold, hresultSize, hmiddlePreserved, houtput⟩ := CircuitCode.Threshold.evalAux?_compileRaw_internal thresholdAvailable @@ -360,7 +360,7 @@ theorem eval?_amplifiedAcceptanceRawCircuit_internal layout).isEmpty = false := by simp [amplifiedAcceptanceRawCircuit, CircuitCode.Threshold.compileRaw] rw [CircuitCode.RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false, wires, heval] + simp only [hnonempty, Bool.false_eq_true, ite_false, wires, heval] rw [houtputIndex] exact houtput diff --git a/Complexitylib/Circuits/Unrolling/Amplification/Internal/Topology.lean b/Complexitylib/Circuits/Unrolling/Amplification/Internal/Topology.lean index ba69758d..ade85efe 100644 --- a/Complexitylib/Circuits/Unrolling/Amplification/Internal/Topology.lean +++ b/Complexitylib/Circuits/Unrolling/Amplification/Internal/Topology.lean @@ -42,7 +42,7 @@ theorem acceptanceCopiesBuildStep_topologicallyWellFormed_internal ).TopologicallyWellFormed primaryAvailable := by let available := build.available primaryAvailable let runLayout := (layout.run j).weaken build.circuit.length - haveI : NeZero available := ⟨by + have : NeZero available := ⟨by simp [available, AcceptanceCopiesBuild.available, NeZero.ne primaryAvailable]⟩ change (build.circuit ++ acceptanceRawCircuit tm T n available @@ -114,7 +114,7 @@ theorem amplifiedAcceptanceRawCircuit_topologicallyWellFormed_internal · simpa [built] using acceptanceCopiesBuild_topologicallyWellFormed_internal tm runs T n primaryAvailable layout - · haveI : NeZero (primaryAvailable + built.circuit.length) := ⟨by + · have : NeZero (primaryAvailable + built.circuit.length) := ⟨by simp [NeZero.ne primaryAvailable]⟩ have hrefs : ∀ j, built.verdictWires j < primaryAvailable + built.circuit.length := by diff --git a/Complexitylib/Circuits/Unrolling/Defs.lean b/Complexitylib/Circuits/Unrolling/Defs.lean index bbbb3f10..14b92951 100644 --- a/Complexitylib/Circuits/Unrolling/Defs.lean +++ b/Complexitylib/Circuits/Unrolling/Defs.lean @@ -218,12 +218,15 @@ private theorem configIndex_eq_equivVal (tm : NTM k) (T : ℕ) cases atom with | state q => rfl | head tape position => + have htape : (tapeSlotEquiv k tape).val = tape.index.val := rfl simp [configIndex, configAtomEquiv, configAtomSumEquiv, headAtomEquiv, - finProdFinEquiv, tapeSlotEquiv, Nat.mul_comm] + finProdFinEquiv, htape, Nat.mul_comm] omega | cell tape position symbol => + have htape : (tapeSlotEquiv k tape).val = tape.index.val := rfl + have hsymbol : (symbolEquiv symbol).val = (symbolIndex symbol).val := rfl simp [configIndex, configAtomEquiv, configAtomSumEquiv, cellAtomEquiv, - finProdFinEquiv, tapeSlotEquiv, symbolEquiv, Nat.mul_comm] + finProdFinEquiv, htape, hsymbol, Nat.mul_comm] omega /-- The explicit arithmetic index agrees with the atom-layout equivalence. -/ diff --git a/Complexitylib/Circuits/Unrolling/Internal/Initialization.lean b/Complexitylib/Circuits/Unrolling/Internal/Initialization.lean index 2da98310..1f624c7e 100644 --- a/Complexitylib/Circuits/Unrolling/Internal/Initialization.lean +++ b/Complexitylib/Circuits/Unrolling/Internal/Initialization.lean @@ -65,8 +65,13 @@ theorem initFragment_topologicallyWellFormed_internal (tm : NTM k) intro i have hgate : ((initFragment tm T n available layout).get i).WellFormedAt available := by - simp only [initFragment, List.get_eq_getElem, List.getElem_map] - exact InitSource.gate_wellFormedAt _ + have hi : (i : ℕ) < (configAtoms tm T).length := by + simpa [initFragment] using i.isLt + have hmap : (initFragment tm T n available layout).get i + = (initSource tm T n available layout ((configAtoms tm T)[(i : ℕ)]'hi)).gate := by + simp only [List.get_eq_getElem]; exact List.getElem_map _ + rw [hmap] + exact InitSource.gate_wellFormedAt (available := available) _ unfold RawGate.WellFormedAt at hgate ⊢ omega @@ -181,7 +186,7 @@ theorem evalAux?_sourceGates_internal (available : ℕ) [NeZero available] rw [hresultSize] omega have hine : i ≠ result.size := by omega - simp only [final, Array.getElem?_push, if_neg hine] + simp only [final, Array.getElem?_push, ite_eq_right hine] exact hprefix i hi · intro j hj have hjbound : j < sources.length + 1 := by simpa using hj @@ -189,7 +194,7 @@ theorem evalAux?_sourceGates_internal (available : ℕ) [NeZero available] · have hjresult : available + j < result.size := by omega rw [show (sources ++ [source])[j]'hj = sources[j]'hbefore by exact List.getElem_append_left hbefore] - simp only [final, Array.getElem?_push, if_neg (Nat.ne_of_lt hjresult)] + simp only [final, Array.getElem?_push, ite_eq_right (Nat.ne_of_lt hjresult)] exact houtputs j hbefore · have hjlast : j = sources.length := by omega subst j diff --git a/Complexitylib/Circuits/Unrolling/Trace/Internal/Evaluation.lean b/Complexitylib/Circuits/Unrolling/Trace/Internal/Evaluation.lean index a98d2e54..0d7dff07 100644 --- a/Complexitylib/Circuits/Unrolling/Trace/Internal/Evaluation.lean +++ b/Complexitylib/Circuits/Unrolling/Trace/Internal/Evaluation.lean @@ -67,7 +67,7 @@ theorem evalAux?_prefixTraceBuild_internal have hbuildNonzero : build.available ≠ 0 := by have havailable := NeZero.ne available omega - letI : NeZero build.available := ⟨hbuildNonzero⟩ + let : NeZero build.available := ⟨hbuildNonzero⟩ let index : Fin T := ⟨i, hiT⟩ have hchoiceMiddle : middle[(layout.choice index).val]? = some (choices index) := by diff --git a/Complexitylib/Circuits/Unrolling/Trace/Internal/Topology.lean b/Complexitylib/Circuits/Unrolling/Trace/Internal/Topology.lean index b3462168..094b020c 100644 --- a/Complexitylib/Circuits/Unrolling/Trace/Internal/Topology.lean +++ b/Complexitylib/Circuits/Unrolling/Trace/Internal/Topology.lean @@ -51,7 +51,7 @@ theorem traceBuildStep_topologicallyWellFormed_internal have hbuildAvailable : 0 < build.available := by rw [havailable] omega - letI : NeZero build.available := ⟨Nat.ne_of_gt hbuildAvailable⟩ + let : NeZero build.available := ⟨Nat.ne_of_gt hbuildAvailable⟩ have hchoice : (layout.choice i).val < build.available := by exact (layout.choice i).isLt.trans_le (by rw [havailable]; omega) have hconfig : build.configBase + configWidth tm T ≤ build.available := diff --git a/Complexitylib/Circuits/Unrolling/Transition/Internal/Semantics.lean b/Complexitylib/Circuits/Unrolling/Transition/Internal/Semantics.lean index 42087eb5..11346060 100644 --- a/Complexitylib/Circuits/Unrolling/Transition/Internal/Semantics.lean +++ b/Complexitylib/Circuits/Unrolling/Transition/Internal/Semantics.lean @@ -162,12 +162,12 @@ theorem effectFormula_eval_internal (tm : NTM k) (T base choiceWire : ℕ) rw [List.mem_map] at hformula obtain ⟨view, _, rfl⟩ := hformula by_cases hselects : selects view.effect = true - · rw [if_pos hselects] at hvalue + · rw [ite_eq_left hselects] at hvalue rw [caseFormula_eval_internal tm T base choiceWire view choice assignment c hchoice hconfig hheads, decide_eq_true_eq] at hvalue subst view exact hselects - · rw [if_neg hselects] at hvalue + · rw [ite_eq_right hselects] at hvalue simp [BoolFormula.eval] at hvalue · intro hselects refine ⟨caseFormula tm T base choiceWire (currentCase tm choice c), ?_, ?_⟩ @@ -238,11 +238,11 @@ theorem predecessorHeadFormula_eval_internal obtain ⟨source, rfl⟩ := hformula dsimp only at hvalue by_cases hmove : movedHeadPosition source.val direction = target.val - · rw [if_pos hmove, + · rw [ite_eq_left hmove, configVar_eval_internal tm T base (.head tape source) assignment c hconfig, ConfigAtom.value, decide_eq_true_eq] at hvalue simpa [hvalue] using hmove - · rw [if_neg hmove] at hvalue + · rw [ite_eq_right hmove] at hvalue simp [BoolFormula.eval] at hvalue · intro hmove let source : Fin (T + 1) := ⟨(tape.get c).head, hhead⟩ @@ -250,7 +250,7 @@ theorem predecessorHeadFormula_eval_internal simpa [source] using hmove refine ⟨_, (List.mem_ofFn' _ _).2 ⟨source, rfl⟩, ?_⟩ dsimp only - rw [if_pos hsourceMove, + rw [ite_eq_left hsourceMove, configVar_eval_internal tm T base (.head tape source) assignment c hconfig] simp [ConfigAtom.value, source] @@ -285,14 +285,14 @@ theorem headAtCellFormula_eval_internal (headAtCellFormula tm T base tape position).eval assignment = decide ((tape.get c).head = position.val) := by by_cases hposition : position.val < T + 1 - · rw [headAtCellFormula, dif_pos hposition, + · rw [headAtCellFormula, dite_eq_left hposition, configVar_eval_internal tm T base (.head tape ⟨position.val, hposition⟩) assignment c hconfig] rfl · have hne : (tape.get c).head ≠ position.val := by have hhead := hheads tape omega - rw [headAtCellFormula, dif_neg hposition] + rw [headAtCellFormula, dite_eq_right hposition] simp [BoolFormula.eval, hne] theorem writtenCellFormula_eval_internal @@ -427,7 +427,9 @@ private theorem writtenCellFormula_eval_successor_internal ConfigAtom.value, successorConfig_writable_cells_internal tm choice c tape position.val, write_cells_of_ne_zero_internal _ _ position.val hposition] - by_cases hhead : (tape.toTapeSlot.get c).head = position.val <;> simp [hhead] + by_cases hhead : (tape.toTapeSlot.get c).head = position.val + · simp [hhead]; rfl + · simp [hhead] private theorem nextFormula_eval_of_halted_internal (tm : NTM k) (T base choiceWire : ℕ) (atom : ConfigAtom tm T) @@ -440,12 +442,12 @@ private theorem nextFormula_eval_of_halted_internal | state state => rw [nextFormula, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_pos hhalt, + ite_eq_left hhalt, configVar_eval_internal tm T base (.state state) assignment c hconfig] | head tape position => rw [nextFormula, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_pos hhalt, + ite_eq_left hhalt, configVar_eval_internal tm T base (.head tape position) assignment c hconfig] | cell tape position symbol => cases tape with @@ -454,22 +456,22 @@ private theorem nextFormula_eval_of_halted_internal assignment c hconfig | work i => by_cases hposition : position.val = 0 - · rw [nextFormula, if_pos hposition, + · rw [nextFormula, ite_eq_left hposition, configVar_eval_internal tm T base (.cell (.work i) position symbol) assignment c hconfig] - · rw [nextFormula, if_neg hposition, + · rw [nextFormula, ite_eq_right hposition, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_pos hhalt, + ite_eq_left hhalt, configVar_eval_internal tm T base (.cell (.work i) position symbol) assignment c hconfig] | output => by_cases hposition : position.val = 0 - · rw [nextFormula, if_pos hposition, + · rw [nextFormula, ite_eq_left hposition, configVar_eval_internal tm T base (.cell .output position symbol) assignment c hconfig] - · rw [nextFormula, if_neg hposition, + · rw [nextFormula, ite_eq_right hposition, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_pos hhalt, + ite_eq_left hhalt, configVar_eval_internal tm T base (.cell .output position symbol) assignment c hconfig] @@ -486,14 +488,14 @@ private theorem nextFormula_eval_of_not_halted_internal | state state => rw [nextFormula, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_neg hhalt, + ite_eq_right hhalt, selectedStateFormula_eval_internal tm T base choiceWire state choice assignment c hchoice hconfig hheads] rfl | head tape position => rw [nextFormula, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_neg hhalt, + ite_eq_right hhalt, movedHeadFormula_eval_internal tm T base choiceWire tape position choice assignment c hchoice hconfig hheads, ConfigAtom.value, @@ -507,11 +509,11 @@ private theorem nextFormula_eval_of_not_halted_internal simp only [ConfigAtom.value, TapeSlot.get] have hcells := successorConfig_input_cells_internal tm choice c position.val simp only [TapeSlot.get] at hcells - rw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] + erw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] simp [hcells] | work i => by_cases hposition : position.val = 0 - · rw [nextFormula, if_pos hposition, + · rw [nextFormula, ite_eq_left hposition, configVar_eval_internal tm T base (.cell (.work i) position symbol) assignment c hconfig] simp only [ConfigAtom.value, TapeSlot.get] @@ -519,17 +521,17 @@ private theorem nextFormula_eval_of_not_halted_internal (.work i) position.val simp only [WritableSlot.toTapeSlot, TapeSlot.get] at hcells rw [hposition, write_cells_zero_internal] at hcells - rw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] + erw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] simp [hposition, hcells] - · rw [nextFormula, if_neg hposition, + · rw [nextFormula, ite_eq_right hposition, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_neg hhalt] + ite_eq_right hhalt] simpa [WritableSlot.toTapeSlot] using writtenCellFormula_eval_successor_internal tm T base choiceWire (.work i) position symbol choice assignment c hchoice hconfig hheads hposition | output => by_cases hposition : position.val = 0 - · rw [nextFormula, if_pos hposition, + · rw [nextFormula, ite_eq_left hposition, configVar_eval_internal tm T base (.cell .output position symbol) assignment c hconfig] simp only [ConfigAtom.value, TapeSlot.get] @@ -537,11 +539,11 @@ private theorem nextFormula_eval_of_not_halted_internal .output position.val simp only [WritableSlot.toTapeSlot, TapeSlot.get] at hcells rw [hposition, write_cells_zero_internal] at hcells - rw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] + erw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] simp [hposition, hcells] - · rw [nextFormula, if_neg hposition, + · rw [nextFormula, ite_eq_right hposition, haltedOrFormula_eval_internal tm T base _ _ assignment c hconfig, - if_neg hhalt] + ite_eq_right hhalt] simpa [WritableSlot.toTapeSlot] using writtenCellFormula_eval_successor_internal tm T base choiceWire .output position symbol choice assignment c hchoice hconfig hheads hposition diff --git a/Complexitylib/Circuits/XOR/Restriction/Internal.lean b/Complexitylib/Circuits/XOR/Restriction/Internal.lean index 1ab22cb5..aa8aab82 100644 --- a/Complexitylib/Circuits/XOR/Restriction/Internal.lean +++ b/Complexitylib/Circuits/XOR/Restriction/Internal.lean @@ -110,7 +110,7 @@ theorem xorOn_applyTo_internal xorOn_insert_internal support index hindex] cases hρ : restriction index with | none => - rw [Finset.filter_insert, if_pos hρ, + rw [Finset.filter_insert, ite_eq_left hρ, xorOn_insert_internal _ index (by simp [hindex])] simp only [Restriction.On.applyTo, hρ, Option.getD_none, ih] @@ -121,7 +121,7 @@ theorem xorOn_applyTo_internal cases input index <;> rfl | some value => rw [Finset.filter_insert, - if_neg (by simp [hρ])] + ite_eq_right (by simp [hρ])] simp only [Restriction.On.applyTo, hρ, Option.getD_some, ih] cases value <;> diff --git a/Complexitylib/Classes/AverageCase/AuxiliaryUnary/Internal.lean b/Complexitylib/Classes/AverageCase/AuxiliaryUnary/Internal.lean index 6a14904f..7acdf1f0 100644 --- a/Complexitylib/Classes/AverageCase/AuxiliaryUnary/Internal.lean +++ b/Complexitylib/Classes/AverageCase/AuxiliaryUnary/Internal.lean @@ -234,7 +234,8 @@ theorem sample_eq_pair_iff_internal {m n : ℕ} (hn : n < m) apply congrArg₂ pair · unfold binary apply List.ofFn_inj.mpr - simpa only [binaryBits] using hbits + simp only [binaryBits] + exact hbits · rfl end AuxiliaryUnarySeed @@ -246,8 +247,8 @@ theorem mass_auxiliaryUnary_pair_internal {m n : ℕ} (hn : n < m) auxiliaryUnary.mass m (pair (List.ofFn x) (List.replicate (m - n) true)) = 1 / ((m : ℚ) * (2 : ℚ) ^ n) := by - letI := auxiliaryUnary.seedFintype m - letI := auxiliaryUnary.seedDecidableEq m + let := auxiliaryUnary.seedFintype m + let := auxiliaryUnary.seedDecidableEq m change uniformProbability (Finset.univ.filter fun seed : AuxiliaryUnarySeed m => diff --git a/Complexitylib/Classes/AverageCase/Ensemble/Internal.lean b/Complexitylib/Classes/AverageCase/Ensemble/Internal.lean index a325aa69..756e569a 100644 --- a/Complexitylib/Classes/AverageCase/Ensemble/Internal.lean +++ b/Complexitylib/Classes/AverageCase/Ensemble/Internal.lean @@ -116,26 +116,25 @@ theorem probability_product_internal (D : DyadicEnsemble α) [DecidablePred P] [DecidablePred Q] : (D.product E).probability n (fun xy => P xy.1 ∧ Q xy.2) = D.probability n P * E.probability n Q := by - simpa [product, probability, event] using - (eventProb_block - (fun seed : Fin (D.seedLength n) → Bool => P (D.sample n seed)) - (fun seed : Fin (E.seedLength n) → Bool => Q (E.sample n seed))) + exact eventProb_block + (fun seed : Fin (D.seedLength n) → Bool => P (D.sample n seed)) + (fun seed : Fin (E.seedLength n) → Bool => Q (E.sample n seed)) theorem probability_dirac_internal (x : ℕ → α) (n : ℕ) (P : α → Prop) [DecidablePred P] : (dirac x).probability n P = if P (x n) then 1 else 0 := by by_cases hP : P (x n) - · rw [if_pos hP] + · rw [ite_eq_left hP] unfold probability rw [show (dirac x).event n P = Finset.univ by ext seed simp [event, dirac, hP]] exact eventProb_univ - · rw [if_neg hP] + · rw [ite_eq_right hP] unfold probability rw [show (dirac x).event n P = ∅ by - ext seed - simp [event, dirac, hP]] + refine Finset.eq_empty_of_forall_notMem fun seed hseed => hP ?_ + exact (Finset.mem_filter.mp hseed).2] exact eventProb_empty theorem probability_uniformBits_internal (n : ℕ) diff --git a/Complexitylib/Classes/AverageCase/FiniteEnsemble.lean b/Complexitylib/Classes/AverageCase/FiniteEnsemble.lean index e22c9c71..8008e95c 100644 --- a/Complexitylib/Classes/AverageCase/FiniteEnsemble.lean +++ b/Complexitylib/Classes/AverageCase/FiniteEnsemble.lean @@ -85,6 +85,9 @@ theorem uniformProbability_product /-- Uniform probability on a product is the average of its conditional fiber probabilities over the first coordinate. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem uniformProbability_product_eq_average_fibers {advice : Type u} {challenge : Type v} [Fintype advice] [DecidableEq advice] [Nonempty advice] @@ -102,6 +105,9 @@ theorem uniformProbability_product_eq_average_fibers /-- Some first-coordinate fiber has probability at least the joint product probability. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem exists_fiber_uniformProbability_ge {advice : Type u} {challenge : Type v} [Fintype advice] [DecidableEq advice] [Nonempty advice] diff --git a/Complexitylib/Classes/AverageCase/FiniteEnsemble/Defs.lean b/Complexitylib/Classes/AverageCase/FiniteEnsemble/Defs.lean index 5ba7489d..6a39ef0b 100644 --- a/Complexitylib/Classes/AverageCase/FiniteEnsemble/Defs.lean +++ b/Complexitylib/Classes/AverageCase/FiniteEnsemble/Defs.lean @@ -109,8 +109,8 @@ def product (D : FiniteEnsemble α) (E : FiniteEnsemble β) : letI := E.seedDecidableEq n infer_instance seedNonempty n := by - letI := D.seedNonempty n - letI := E.seedNonempty n + have := D.seedNonempty n + have := E.seedNonempty n infer_instance sample n seed := (D.sample n seed.1, E.sample n seed.2) diff --git a/Complexitylib/Classes/AverageCase/FiniteEnsemble/Internal.lean b/Complexitylib/Classes/AverageCase/FiniteEnsemble/Internal.lean index b86cdc9d..77975b84 100644 --- a/Complexitylib/Classes/AverageCase/FiniteEnsemble/Internal.lean +++ b/Complexitylib/Classes/AverageCase/FiniteEnsemble/Internal.lean @@ -72,6 +72,9 @@ theorem uniformProbability_union_le_internal {Ω : Type u} gcongr exact_mod_cast Finset.card_union_le event₁ event₂ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem uniformProbability_eq_sum_fiberwise_internal {Ω : Type u} {ι : Type v} [Fintype Ω] [DecidableEq Ω] [DecidableEq ι] (event : Finset Ω) (indices : Finset ι) (f : Ω → ι) @@ -84,6 +87,9 @@ theorem uniformProbability_eq_sum_fiberwise_internal push_cast rw [Finset.sum_div] +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem uniformProbability_product_internal {Ω : Type u} {Ξ : Type v} [Fintype Ω] [DecidableEq Ω] [Fintype Ξ] [DecidableEq Ξ] (P : Ω → Prop) (Q : Ξ → Prop) @@ -109,6 +115,9 @@ theorem uniformProbability_product_internal ((Finset.univ.filter P).card : ℚ) (Fintype.card Ω : ℚ) ((Finset.univ.filter Q).card : ℚ) (Fintype.card Ξ : ℚ)).symm +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem uniformProbability_product_eq_average_fibers_internal {advice : Type u} {challenge : Type v} [Fintype advice] [DecidableEq advice] [Nonempty advice] @@ -154,6 +163,9 @@ theorem uniformProbability_product_eq_average_fibers_internal intro fixed _hfixed field_simp [hadvice, hchallenge] +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem exists_fiber_uniformProbability_ge_internal {advice : Type u} {challenge : Type v} [Fintype advice] [DecidableEq advice] [Nonempty advice] @@ -185,6 +197,9 @@ theorem exists_fiber_uniformProbability_ge_internal (Finset.univ_nonempty : (Finset.univ : Finset advice).Nonempty) hsum exact ⟨fixed, hle⟩ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem uniformMean_le_threshold_add_probability_internal {sample : Type u} [Fintype sample] [DecidableEq sample] [Nonempty sample] (value : sample → ℚ) (threshold : ℚ) @@ -391,6 +406,9 @@ theorem half_le_uniformAtLeastOneProbability_of_singleDrawLower_internal htrials.trans <| mul_le_mul_of_nonneg_left hlower (by positivity) nlinarith +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem uniformProbability_equiv_internal {Ω : Type u} {Ξ : Type v} [Fintype Ω] [DecidableEq Ω] [Fintype Ξ] [DecidableEq Ξ] (e : Ω ≃ Ξ) (P : Ξ → Prop) @@ -430,35 +448,35 @@ variable {α : Type u} {β : Type w} theorem probability_nonneg_internal (D : FiniteEnsemble α) (n : ℕ) (P : α → Prop) [DecidablePred P] : 0 ≤ D.probability n P := by - letI := D.seedFintype n + let := D.seedFintype n exact uniformProbability_nonneg_internal _ theorem probability_le_one_internal (D : FiniteEnsemble α) (n : ℕ) (P : α → Prop) [DecidablePred P] : D.probability n P ≤ 1 := by - letI := D.seedFintype n - letI := D.seedNonempty n + let := D.seedFintype n + let := D.seedNonempty n exact uniformProbability_le_one_internal _ theorem probability_false_internal (D : FiniteEnsemble α) (n : ℕ) : D.probability n (fun _ => False) = 0 := by - letI := D.seedFintype n - letI := D.seedDecidableEq n + let := D.seedFintype n + let := D.seedDecidableEq n simp [probability, event, uniformProbability_empty_internal] theorem probability_true_internal (D : FiniteEnsemble α) (n : ℕ) : D.probability n (fun _ => True) = 1 := by - letI := D.seedFintype n - letI := D.seedDecidableEq n - letI := D.seedNonempty n + let := D.seedFintype n + let := D.seedDecidableEq n + let := D.seedNonempty n simp [probability, event, uniformProbability_univ_internal] theorem probability_not_internal (D : FiniteEnsemble α) (n : ℕ) (P : α → Prop) [DecidablePred P] : D.probability n (fun x => ¬ P x) = 1 - D.probability n P := by - letI := D.seedFintype n - letI := D.seedDecidableEq n - letI := D.seedNonempty n + let := D.seedFintype n + let := D.seedDecidableEq n + let := D.seedNonempty n have hevent : D.event n (fun x => ¬ P x) = (D.event n P)ᶜ := by ext seed simp [event] @@ -469,8 +487,8 @@ theorem probability_or_le_internal (D : FiniteEnsemble α) (n : ℕ) (P Q : α → Prop) [DecidablePred P] [DecidablePred Q] : D.probability n (fun x => P x ∨ Q x) ≤ D.probability n P + D.probability n Q := by - letI := D.seedFintype n - letI := D.seedDecidableEq n + let := D.seedFintype n + let := D.seedDecidableEq n have hevent : D.event n (fun x => P x ∨ Q x) = D.event n P ∪ D.event n Q := by ext seed simp [event] @@ -481,8 +499,8 @@ theorem probability_mono_internal (D : FiniteEnsemble α) (n : ℕ) (P Q : α → Prop) [DecidablePred P] [DecidablePred Q] (hPQ : ∀ x, P x → Q x) : D.probability n P ≤ D.probability n Q := by - letI := D.seedFintype n - letI := D.seedDecidableEq n + let := D.seedFintype n + let := D.seedDecidableEq n unfold probability uniformProbability gcongr intro seed hseed @@ -497,8 +515,8 @@ theorem probability_congr_internal (D : FiniteEnsemble α) (n : ℕ) (P Q : α → Prop) [DecidablePred P] [DecidablePred Q] (hPQ : ∀ x, P x ↔ Q x) : D.probability n P = D.probability n Q := by - letI := D.seedFintype n - letI := D.seedDecidableEq n + let := D.seedFintype n + let := D.seedDecidableEq n unfold probability apply congrArg uniformProbability ext seed @@ -517,9 +535,9 @@ theorem probability_map_internal (D : FiniteEnsemble α) (f : α → β) theorem sum_mass_eq_one_internal [DecidableEq α] (D : FiniteEnsemble α) (n : ℕ) : ∑ x ∈ D.support n, D.mass n x = 1 := by - letI := D.seedFintype n - letI := D.seedDecidableEq n - letI := D.seedNonempty n + let := D.seedFintype n + let := D.seedDecidableEq n + let := D.seedNonempty n have hmaps : ((Finset.univ : Finset (D.Seed n)) : Set (D.Seed n)).MapsTo (D.sample n) (D.support n) := by @@ -535,33 +553,34 @@ theorem probability_product_internal (D : FiniteEnsemble α) [DecidablePred P] [DecidablePred Q] : (D.product E).probability n (fun xy => P xy.1 ∧ Q xy.2) = D.probability n P * E.probability n Q := by - letI := D.seedFintype n - letI := D.seedDecidableEq n - letI := E.seedFintype n - letI := E.seedDecidableEq n - simpa [product, probability, event] using - (uniformProbability_product_internal - (fun seed : D.Seed n => P (D.sample n seed)) - (fun seed : E.Seed n => Q (E.sample n seed))) + let := D.seedFintype n + let := D.seedDecidableEq n + let := E.seedFintype n + let := E.seedDecidableEq n + simp only [product, probability, event] + exact uniformProbability_product_internal + (fun seed : D.Seed n => P (D.sample n seed)) + (fun seed : E.Seed n => Q (E.sample n seed)) theorem probability_dirac_internal (x : ℕ → α) (n : ℕ) (P : α → Prop) [DecidablePred P] : (dirac x).probability n P = if P (x n) then 1 else 0 := by - letI := (dirac x).seedFintype n - letI := (dirac x).seedDecidableEq n - letI := (dirac x).seedNonempty n + let := (dirac x).seedFintype n + let := (dirac x).seedDecidableEq n + let := (dirac x).seedNonempty n by_cases hP : P (x n) - · rw [if_pos hP] + · rw [ite_eq_left hP] unfold probability rw [show (dirac x).event n P = Finset.univ by ext seed simp [event, dirac, hP]] exact uniformProbability_univ_internal - · rw [if_neg hP] + · rw [ite_eq_right hP] unfold probability rw [show (dirac x).event n P = ∅ by ext seed - simp [event, dirac, hP]] + simp [event, dirac, hP] + rfl] exact uniformProbability_empty_internal end FiniteEnsemble diff --git a/Complexitylib/Classes/Containments.lean b/Complexitylib/Classes/Containments.lean index 17970527..bcfcb4e5 100644 --- a/Complexitylib/Classes/Containments.lean +++ b/Complexitylib/Classes/Containments.lean @@ -304,7 +304,7 @@ theorem P_inter {L₁ L₂ : Language} (h₁ : L₁ ∈ P) (h₂ : L₂ ∈ P) : /-- **P is closed under set difference**: `L₁ \ L₂ = L₁ ∩ L₂ᶜ`. -/ theorem P_diff {L₁ L₂ : Language} (h₁ : L₁ ∈ P) (h₂ : L₂ ∈ P) : L₁ \ L₂ ∈ P := by - rw [Set.diff_eq] + rw [Set.sdiff_eq] exact P_inter h₁ (P_compl h₂) /-- **P is closed under symmetric difference**: diff --git a/Complexitylib/Classes/Containments/Internal/BinArith.lean b/Complexitylib/Classes/Containments/Internal/BinArith.lean index 919ab1e8..e2163edc 100644 --- a/Complexitylib/Classes/Containments/Internal/BinArith.lean +++ b/Complexitylib/Classes/Containments/Internal/BinArith.lean @@ -305,12 +305,12 @@ theorem addStepP_mem_FP : addStepP ∈ FP := by (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hc := hfst hid have hw := hsnd hid have hacc := hfst hw @@ -369,13 +369,13 @@ theorem addBitsFn_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : b (fun z => addBits (a z) (b z)) ∈ FP := by have h1 := mem_FP_comp (addRunFn_mem_FP ha hb) Cobham.sndBlock_mem_FP have h2 := mem_FP_comp h1 Cobham.fstBlock_mem_FP - simpa [Function.comp, addBits] using h2 - + simp [addBits] + exact h2 theorem addCarryFn_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : b ∈ FP) : (fun z => addCarry (a z) (b z)) ∈ FP := by have h := mem_FP_comp (addRunFn_mem_FP ha hb) Cobham.fstBlock_mem_FP - simpa [Function.comp, addCarry] using h - + simp [addCarry] + exact h /-! ## Comparison as a recursion -/ /-- Scan two little-endian bitstrings from the bottom, keeping the verdict of the highest @@ -412,10 +412,11 @@ theorem ltBitsLE_spec (f : Bool) (u v : List Bool) (h : v.length = u.length) : have hb : b.toNat ≤ 1 := by cases b <;> simp have hd : d.toNat ≤ 1 := by cases d <;> simp rcases lt_trichotomy (binValLE tu) (binValLE tv) with hlt | heq | hgt - · rw [if_pos hlt, if_pos (by omega)] - · rw [if_neg (by omega), if_neg (by omega), heq] + · rw [ite_eq_left hlt, ite_eq_left (by omega)] + · rw [ite_eq_right (by omega), ite_eq_right (by omega), heq] cases b <;> cases d <;> simp - · rw [if_neg (by omega), if_pos hgt, if_neg (by omega), if_pos (by omega)] + · rw [ite_eq_right (by omega), ite_eq_left hgt, ite_eq_right (by omega), + ite_eq_left (by omega)] /-! ## Comparison as a scan -/ @@ -431,12 +432,12 @@ theorem ltStep_flag (f b : Bool) (tu v : List Bool) : = ([if b = v.headD false then f else v.headD false], tu, v.drop 1) := by rw [ltStep, bit1_eq] by_cases hb : b = v.headD false - · rw [if_pos hb, hb] + · rw [ite_eq_left hb, hb] have : eqFlag [v.headD false] [v.headD false] = [true] := (eqFlag_eq_true_iff _ _).mpr rfl rw [this] rfl - · rw [if_neg hb] + · rw [ite_eq_right hb] have : eqFlag [b] [v.headD false] = [false] := by rcases eqFlag_flag [b] [v.headD false] with hh | hh · exact absurd (by simpa using (eqFlag_eq_true_iff [b] [v.headD false]).mp hh) hb @@ -461,7 +462,7 @@ theorem ltStep_iterate_run (f : Bool) (u v : List Bool) (h : v.length = u.length rw [List.length_cons, Function.iterate_succ_apply, ltStep_flag] simp only [List.headD_cons, List.drop_succ_cons, List.drop_zero] rw [ih _ tv htv, ltBitsLE_cons] - simp + rfl theorem ltStep_iterate_length (f : Bool) (u v : List Bool) (n : ℕ) : (ltStep^[n] ([f], u, v)).1.length = 1 ∧ @@ -546,12 +547,12 @@ theorem ltFlag_eq_true_iff (u v : List Bool) (h : v.length = u.length) : ltFlag u v = [true] ↔ binValLE u < binValLE v := by rw [ltFlag_eq u v h, ltBitsLE_spec false u v h] rcases lt_trichotomy (binValLE u) (binValLE v) with hlt | heq | hgt - · rw [if_pos hlt] + · rw [ite_eq_left hlt] simp [hlt] - · rw [if_neg (by omega), if_neg (by omega)] + · rw [ite_eq_right (by omega), ite_eq_right (by omega)] simp omega - · rw [if_neg (by omega), if_pos hgt] + · rw [ite_eq_right (by omega), ite_eq_left hgt] simp omega @@ -570,12 +571,12 @@ theorem ltStepP_mem_FP : ltStepP ∈ FP := by (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hf := hfst hid have hw := hsnd hid have hru := hfst hw @@ -614,10 +615,10 @@ theorem ltFlagFn_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : b omega have h := Cobham.iterate_mem_FP ltStepP_mem_FP hinit ha hwidth hbound have h1 := mem_FP_comp h Cobham.fstBlock_mem_FP - simpa [Function.comp, ltFlag, ltRun] using h1 + simp [ltFlag, ltRun] + exact h1 /-! ## The larger of two numbers -/ - /-- The larger of two equal-width numbers. -/ def maxBits (u v : List Bool) : List Bool := selectHead (ltFlag u v) v u @@ -625,9 +626,9 @@ theorem maxBits_eq (u v : List Bool) (h : v.length = u.length) : maxBits u v = if binValLE u < binValLE v then v else u := by rw [maxBits] by_cases hlt : binValLE u < binValLE v - · rw [if_pos hlt, (ltFlag_eq_true_iff u v h).mpr hlt] + · rw [ite_eq_left hlt, (ltFlag_eq_true_iff u v h).mpr hlt] rfl - · rw [if_neg hlt] + · rw [ite_eq_right hlt] rcases ltFlag_flag u v h with hf | hf · exact absurd ((ltFlag_eq_true_iff u v h).mp hf) hlt · rw [hf] @@ -659,8 +660,8 @@ theorem binValLE_maxBits (u v : List Bool) (h : v.length = u.length) : binValLE (maxBits u v) = max (binValLE u) (binValLE v) := by rw [maxBits_eq u v h] by_cases hlt : binValLE u < binValLE v - · rw [if_pos hlt]; omega - · rw [if_neg hlt]; omega + · rw [ite_eq_left hlt]; omega + · rw [ite_eq_right hlt]; omega theorem maxBits_length (u v : List Bool) (h : v.length = u.length) : (maxBits u v).length = u.length := by @@ -821,12 +822,12 @@ theorem strIdx_upper (w : List Bool) : strIdx w + 2 ≤ 2 ^ (w.length + 1) := by theorem strIdx_nextStr (w : List Bool) : strIdx (nextStr w) = strIdx w + 1 := by rw [nextStr] by_cases hov : bumpOver w - · rw [if_pos hov, strIdx, strIdx, List.length_replicate, binValLE_replicate_false, + · rw [ite_eq_left hov, strIdx, strIdx, List.length_replicate, binValLE_replicate_false, (bumpOver_iff w).mp hov] have hpos : 0 < 2 ^ w.length := Nat.two_pow_pos _ have : 2 ^ (w.length + 1) = 2 ^ w.length * 2 := by rw [pow_succ] omega - · rw [if_neg hov, strIdx, strIdx, bumpBits_length, + · rw [ite_eq_right hov, strIdx, strIdx, bumpBits_length, binValLE_bumpBits_of_not_over w (by simpa using hov)] omega @@ -922,9 +923,9 @@ theorem nextStrFn_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : funext z rw [nextStr, bumpFlag_eq, bumpCode_eq] by_cases hov : bumpOver (a z) - · rw [if_pos hov, hov, selectHead, padTo_nil] + · rw [ite_eq_left hov, hov, selectHead, padTo_nil] simp - · rw [if_neg hov, selectHead] + · rw [ite_eq_right hov, selectHead] simp only [Bool.not_eq_true] at hov rw [hov] simp diff --git a/Complexitylib/Classes/Containments/Internal/BlockAccept.lean b/Complexitylib/Classes/Containments/Internal/BlockAccept.lean index a9773473..994f4804 100644 --- a/Complexitylib/Classes/Containments/Internal/BlockAccept.lean +++ b/Complexitylib/Classes/Containments/Internal/BlockAccept.lean @@ -86,7 +86,7 @@ theorem acceptStep_pack (k : ℕ) (qcode R ruler flag rest : List Bool) : by_cases hle : (wideRuler (codeBlocks k) R).length ≤ rest.length · rw [acceptPairStep, anyStepPair_pos _ (acceptFlag qcode R ruler) (flag, rest) hle, Cobham.selectHead, - if_pos (by + ite_eq_left (by rw [(Cobham.lenLeFlag_eq_true_iff rest (wideRuler (codeBlocks k) R)).mpr hle] rfl)] rfl @@ -97,7 +97,7 @@ theorem acceptStep_pack (k : ℕ) (qcode R ruler flag rest : List Bool) : · rw [Cobham.lenLeFlag_eq_true_iff] at h omega · exact h - rw [if_neg (by rw [hflag]; simp), if_pos (by rw [hflag]; rfl)] + rw [ite_eq_right (by rw [hflag]; simp), ite_eq_left (by rw [hflag]; rfl)] rfl /-- **The packed iteration is the unpacked one.** -/ @@ -160,12 +160,12 @@ theorem acceptStep_mem_FP (k : ℕ) (qcode : List Bool) : acceptStep k qcode ∈ (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hhead := hfst hid have hR := hfst hhead have hruler := hsnd hhead diff --git a/Complexitylib/Classes/Containments/Internal/BlockMember.lean b/Complexitylib/Classes/Containments/Internal/BlockMember.lean index 52804de5..46922a20 100644 --- a/Complexitylib/Classes/Containments/Internal/BlockMember.lean +++ b/Complexitylib/Classes/Containments/Internal/BlockMember.lean @@ -50,11 +50,11 @@ def anyStepPair (R : List Bool) (f : List Bool → List Bool) theorem anyStepPair_pos (R : List Bool) (f : List Bool → List Bool) (s : List Bool × List Bool) (h : R.length ≤ s.2.length) : anyStepPair R f s = (orBit s.1 (f (s.2.take R.length)), s.2.drop R.length) := - if_pos h + ite_eq_left h theorem anyStepPair_neg (R : List Bool) (f : List Bool → List Bool) (s : List Bool × List Bool) (h : ¬ R.length ≤ s.2.length) : anyStepPair R f s = s := - if_neg h + ite_eq_right h /-- The flag component of a scan is a flag. -/ theorem anyStepPair_flag (R : List Bool) {f : List Bool → List Bool} @@ -109,9 +109,9 @@ theorem anyStepPair_flag_eq_true_iff (R : List Bool) {f : List Bool → List Boo rw [Function.iterate_succ_apply, ih (anyStepPair R f s) hstep] by_cases hle : R.length ≤ s.2.length · have hfst : (anyStepPair R f s).1 = orBit s.1 (f (s.2.take R.length)) := by - rw [anyStepPair, if_pos hle] + rw [anyStepPair, ite_eq_left hle] have hsnd : (anyStepPair R f s).2 = s.2.drop R.length := by - rw [anyStepPair, if_pos hle] + rw [anyStepPair, ite_eq_left hle] rw [hfst, hsnd, orBit_eq_true_iff hs (hf _)] constructor · rintro ((h | h) | ⟨i, hi, hlen, hblk⟩) @@ -137,7 +137,7 @@ theorem anyStepPair_flag_eq_true_iff (R : List Bool) {f : List Bool → List Boo omega · rw [blockAt_drop] exact hblk - · have hfix : anyStepPair R f s = s := by rw [anyStepPair, if_neg hle] + · have hfix : anyStepPair R f s = s := by rw [anyStepPair, ite_eq_right hle] rw [hfix] constructor · rintro (h | ⟨i, hi, hlen, hblk⟩) @@ -210,7 +210,7 @@ theorem memStep_pack (R u f rest : List Bool) : simp only [pairFst_pair, pairSnd_pair] by_cases hle : R.length ≤ rest.length · rw [scanStep, anyStepPair_pos R (eqFlag u) (f, rest) hle, Cobham.selectHead, - if_pos (by rw [(Cobham.lenLeFlag_eq_true_iff rest R).mpr hle]; rfl)] + ite_eq_left (by rw [(Cobham.lenLeFlag_eq_true_iff rest R).mpr hle]; rfl)] rfl · rw [scanStep, anyStepPair_neg R (eqFlag u) (f, rest) hle, Cobham.selectHead] have hflag : Cobham.lenLeFlag rest R = [false] := by @@ -218,7 +218,7 @@ theorem memStep_pack (R u f rest : List Bool) : · rw [Cobham.lenLeFlag_eq_true_iff rest R] at h omega · exact h - rw [if_neg (by rw [hflag]; simp), if_pos (by rw [hflag]; rfl)] + rw [ite_eq_right (by rw [hflag]; simp), ite_eq_left (by rw [hflag]; rfl)] rfl /-- **The packed iteration is the unpacked one.** -/ @@ -272,12 +272,12 @@ theorem memStep_mem_FP : memStep ∈ FP := by (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hR := hfst hid have hw := hsnd hid have hrest := hsnd hw @@ -325,7 +325,7 @@ theorem memFlagFn_mem_FP {Rf uf Vf : List Bool → List Bool} have h1 := mem_FP_comp h Cobham.sndBlock_mem_FP have h2 := mem_FP_comp h1 Cobham.fstBlock_mem_FP have h3 := mem_FP_comp h2 Cobham.sndBlock_mem_FP - simpa [Function.comp] using h3 + exact h3 exact hcomp end Complexity diff --git a/Complexitylib/Classes/Containments/Internal/BlockScan.lean b/Complexitylib/Classes/Containments/Internal/BlockScan.lean index b9a45061..1175edc5 100644 --- a/Complexitylib/Classes/Containments/Internal/BlockScan.lean +++ b/Complexitylib/Classes/Containments/Internal/BlockScan.lean @@ -119,7 +119,7 @@ theorem markStep_run (r : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) (off rw [Scanner.chunkRun, ih, markStep, markCount] by_cases h : cols (off + 3 * m + 1) r = Γ.one · have hm : markOf cols off r m = true := by simp [markOf, h] - rw [if_pos h, hm] + rw [ite_eq_left h, hm] refine Prod.ext ?_ ?_ · simp · show (decide (0 < markCount cols off r m) || decide (1 < markCount cols off r m)) @@ -129,7 +129,7 @@ theorem markStep_run (r : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) (off · have h1 : 0 < markCount cols off r m := h0 simp [h1] · have hm : markOf cols off r m = false := by simp [markOf, h] - rw [if_neg h, hm] + rw [ite_eq_right h, hm] simp /-! ## The symbols -/ @@ -313,24 +313,24 @@ theorem leftStep_state (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) ( refine ⟨rfl, rfl, rfl, ?_⟩ by_cases hA : markOf cols off a 0 = true · have hA' : cols (off + 3 * 0 + 1) a = Γ.one := by simpa [markOf] using hA - rw [if_pos hA] - simp only [hA', if_true, decide_true] + rw [ite_eq_left hA] + simp only [hA', ite_true, decide_true] constructor · intro h exact ⟨by simpa [markOf] using h, by omega⟩ · rintro ⟨h, -⟩ simpa [markOf] using h · have hA' : ¬ (cols (off + 3 * 0 + 1) a = Γ.one) := by simpa [markOf] using hA - rw [if_neg hA] + rw [ite_eq_right hA] simp only [hA', decide_false] exact ⟨fun _ p h1 h2 => absurd h2 (by omega), fun _ => rfl⟩ · obtain ⟨h1, h2, h3, h4⟩ := ih hm0 rw [Scanner.chunkRun, leftStep] - simp only [h1, if_true, h2, h3] + simp only [h1, ite_true, h2, h3] refine ⟨by simp, by simp, by simp [markOf], ?_⟩ by_cases hA : markOf cols off a 0 = true - · rw [if_pos hA] at h4 ⊢ - rw [if_pos hA] + · rw [ite_eq_left hA] at h4 ⊢ + rw [ite_eq_left hA] rw [Bool.and_eq_true, h4] constructor · rintro ⟨⟨hb0, hall⟩, hlast⟩ @@ -345,8 +345,8 @@ theorem leftStep_state (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) ( have := hall m hm0 (by omega) rw [markOf] at this simp [this] - · rw [if_neg hA] at h4 ⊢ - rw [if_neg hA, Bool.and_eq_true, h4] + · rw [ite_eq_right hA] at h4 ⊢ + rw [ite_eq_right hA, Bool.and_eq_true, h4] constructor · rintro ⟨hall, hlast⟩ p hp1 hp2 rcases Nat.lt_or_ge p m with h | h @@ -447,8 +447,8 @@ theorem dirEmit_run (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) (off obtain ⟨-, h2, h3, h4⟩ := leftStep_state a b cols off m hm rw [h2, h3] by_cases hA : markOf cols off a 0 = true - · rw [if_pos hA, h4, if_pos hA] - simp only [movedMark, hA, if_true] + · rw [ite_eq_left hA, h4, ite_eq_left hA] + simp only [movedMark, hA, ite_true] constructor · rintro ⟨hb0, hall⟩ p hp rcases Nat.eq_zero_or_pos p with h0 | h0 @@ -460,9 +460,9 @@ theorem dirEmit_run (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) (off rw [this] simp omega - · rw [if_neg hA, Bool.and_eq_true, h4, if_neg hA] + · rw [ite_eq_right hA, Bool.and_eq_true, h4, ite_eq_right hA] have hA' : markOf cols off a 0 = false := by simpa using hA - simp only [movedMark, hA', Bool.not_eq_true', Bool.false_eq_true, if_false] + simp only [movedMark, hA', Bool.not_eq_true', Bool.false_eq_true, ite_false] constructor · rintro ⟨hall, hlast⟩ p hp rcases Nat.lt_or_ge p (m - 1) with h | h @@ -589,17 +589,17 @@ theorem moved_of_holds {m : ℕ} (cols : ℕ → Fin (j + 1) → Γ) (off : ℕ) rw [hb hd' hdm'] at hh simp only [decide_true] at hh by_cases h0 : hd' = 0 - · rw [h0, if_pos rfl] at hh + · rw [h0, ite_eq_left rfl] at hh exact absurd hh.symm (by simp) - · rw [if_neg h0, hmark (hd' - 1) (by omega)] at hh + · rw [ite_eq_right h0, hmark (hd' - 1) (by omega)] at hh have : hd' - 1 = hd := by simpa using hh.symm omega · intro h p hp rw [hb p hp, h] by_cases h0 : p = 0 - · rw [h0, if_pos rfl] + · rw [h0, ite_eq_left rfl] simp - · rw [if_neg h0, hmark (p - 1) (by omega)] + · rw [ite_eq_right h0, hmark (p - 1) (by omega)] congr 1 simp only [eq_iff_iff] omega @@ -608,7 +608,7 @@ theorem moved_of_holds {m : ℕ} (cols : ℕ → Fin (j + 1) → Γ) (off : ℕ) rw [ha 0 (by omega)] by_cases h0 : hd = 0 · rw [h0] - simp only [decide_true, if_true] + simp only [decide_true, ite_true] constructor · intro h have hh := h hd' hdm' @@ -647,9 +647,9 @@ theorem sym_of_holds {m : ℕ} (cols : ℕ → Fin (j + 1) → Γ) (off : ℕ) ( have hiff : ((decide (p = hd) && decide (0 < p.val)) = true) ↔ (p = hd ∧ 0 < p.val) := by simp only [Bool.and_eq_true, decide_eq_true_eq] by_cases hc : p = hd ∧ 0 < p.val - · rw [if_pos hc, if_pos (hiff.mpr hc)] + · rw [ite_eq_left hc, ite_eq_left (hiff.mpr hc)] exact ⟨fun h => gammaBits_injective h, fun h => by rw [h]⟩ - · rw [if_neg hc, if_neg (fun h => hc (hiff.mp h))] + · rw [ite_eq_right hc, ite_eq_right (fun h => hc (hiff.mp h))] exact ⟨fun h => gammaBits_injective h, fun h => by rw [h]⟩ constructor · intro h @@ -909,7 +909,8 @@ theorem inHeadStep_stay_fst (r r' : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → induction p with | zero => rfl | succ p ih => - rw [Scanner.cellFold, Scanner.cellFold, ← ih] + simp only [Scanner.cellFold] + rw [← ih] rfl theorem bitsOfLenLE_inj {w u v : ℕ} (hu : u < 2 ^ w) (hv : v < 2 ^ w) @@ -933,9 +934,9 @@ theorem inHeadEmit_of_holds (cols : ℕ → Fin (j + 1) → Γ) (off : ℕ) (r r Scanner.runR_eq_cellFold (Scanner.eq j r r') _ w have hrun : (Scanner.eq j r r').run (fun t => cols (off + t)) w = (Scanner.eq j r r').runR (fun t => cols (off + t)) w := by - rw [Scanner.run, Scanner.eq_runL] + erw [Scanner.run, Scanner.eq_runL] show (Scanner.cellFold (inHeadStep r r' Dir3.stay) cols off (true, true) w).1 = true ↔ _ - rw [inHeadStep_stay_fst, Scanner.cellFold_shift, ← hcf, ← hrun, + erw [inHeadStep_stay_fst, Scanner.cellFold_shift, ← hcf, ← hrun, show w = (bitsOfLenLE w u).length from hlu.symm] refine Iff.trans (eq_run_of_holds (fun t => cols (off + t)) r r' _ _ (by rw [hlu, hlv]) h h') ?_ @@ -952,7 +953,7 @@ theorem inHeadEmit_of_holds (cols : ℕ → Fin (j + 1) → Γ) (off : ℕ) (r r exact Scanner.ofRight_runL (Bool × Bool) _ _ _ _ w _ show (Scanner.plusOne j r r').emit (Scanner.cellFold (inHeadStep r r' Dir3.right) cols off (true, true) w) = true ↔ _ - rw [inHeadStep_right_eq, Scanner.cellFold_shift, ← hcf, ← hrun, + erw [inHeadStep_right_eq, Scanner.cellFold_shift, ← hcf, ← hrun, plusOne_of_holds (fun t => cols (off + t)) r r' w u v hu hv h h'] rfl | left => @@ -966,7 +967,7 @@ theorem inHeadEmit_of_holds (cols : ℕ → Fin (j + 1) → Γ) (off : ℕ) (r r exact Scanner.ofRight_runL (Bool × Bool) _ _ _ _ w _ show (Scanner.plusOne j r' r).emit (Scanner.cellFold (inHeadStep r r' Dir3.left) cols off (true, true) w) = true ↔ _ - rw [inHeadStep_left_eq, Scanner.cellFold_shift, ← hcf, ← hrun, + erw [inHeadStep_left_eq, Scanner.cellFold_shift, ← hcf, ← hrun, plusOne_of_holds (fun t => cols (off + t)) r' r w v u hv hu h' h] show u = v + 1 ↔ v = movedIdx Dir3.left u show u = v + 1 ↔ v = u - 1 @@ -1048,7 +1049,7 @@ theorem blockEmit_holds {m : ℕ} [NeZero m] (cols : ℕ → Fin (j + 1) → Γ) simp [Fin.ext_iff] rw [blockEmit_run a b (gammaBits sym) (gammaBits wr) d cols off m hm hend, markCount_eq cols off a hd.val m hA, markCount_eq cols off b hd'.val m hB, - if_pos hd.isLt, if_pos hd'.isLt, + ite_eq_left hd.isLt, ite_eq_left hd'.isLt, sym_of_holds cols off a b hd cl cl' sym wr (markOf_of_holds ha) (symOf_of_holds ha) (symOf_of_holds hb), moved_of_holds cols off a b hd.val hd'.val hd.isLt hd'.isLt d hA hB hend] @@ -1152,13 +1153,13 @@ theorem decodeCfg_input_read (a : Code tm.Q k x.length S) : theorem decodeCfg_work_read (a : Code tm.Q k x.length S) (i : Fin k) : ((decodeCfg x S a).work i).read = wSymOf tm x S a i := by show (if h : (a.2.2.1 i).1.val < S + 1 then (a.2.2.1 i).2 ⟨_, h⟩ else Γ.blank) = _ - rw [dif_pos (a.2.2.1 i).1.isLt] + rw [dite_eq_left (a.2.2.1 i).1.isLt] rfl theorem decodeCfg_output_read (a : Code tm.Q k x.length S) : (decodeCfg x S a).output.read = oSymOf tm x S a := by show (if h : a.2.2.2.1.val < S + 2 then a.2.2.2.2 ⟨_, h⟩ else Γ.blank) = _ - rw [dif_pos a.2.2.2.1.isLt] + rw [dite_eq_left a.2.2.2.1.isLt] rfl /-- The transition a code and a choice bit determine. -/ @@ -1180,9 +1181,9 @@ theorem mem_codeSucc_iff (a a' : Code tm.Q k x.length S) : a' ∈ NTM.codeSucc tm x S a ↔ a.1 ≠ tm.qhalt ∧ ∃ β : Bool, a' = succCode tm x S β a := by rw [NTM.codeSucc, decodeCfg_state] by_cases h : a.1 = tm.qhalt - · rw [if_pos h] + · rw [ite_eq_left h] simp [h] - · rw [if_neg h] + · rw [ite_eq_right h] simp only [Finset.mem_insert, Finset.mem_singleton, h, ne_eq, not_false_eq_true, true_and] constructor · rintro (h1 | h1) @@ -1252,22 +1253,22 @@ theorem succCode_work_cells (a : Code tm.Q k x.length S) (β : Bool) (i : Fin k) have hbase : ∀ q : Fin (S + 1), ((decodeCfg x S a).work i).cells q.val = (a.2.2.1 i).2 q := by intro q show (if h : q.val < S + 1 then (a.2.2.1 i).2 ⟨q.val, h⟩ else Γ.blank) = _ - rw [dif_pos q.isLt] + rw [dite_eq_left q.isLt] have hhead : ((decodeCfg x S a).work i).head = (a.2.2.1 i).1.val := rfl by_cases h0 : (a.2.2.1 i).1.val = 0 - · rw [if_pos (by rw [hhead, h0])] - rw [hbase p, if_neg] + · rw [ite_eq_left (by rw [hhead, h0])] + rw [hbase p, ite_eq_right] rintro ⟨hp, hpos⟩ rw [hp, h0] at hpos omega - · rw [if_neg (by rw [hhead]; exact h0)] + · rw [ite_eq_right (by rw [hhead]; exact h0)] show Function.update ((decodeCfg x S a).work i).cells ((decodeCfg x S a).work i).head _ p.val = _ rw [hhead] by_cases hp : p.val = (a.2.2.1 i).1.val - · rw [hp, Function.update_self, if_pos ⟨Fin.ext hp, by omega⟩] + · rw [hp, Function.update_self, ite_eq_left ⟨Fin.ext hp, by omega⟩] rfl - · rw [Function.update_of_ne hp, hbase p, if_neg] + · rw [Function.update_of_ne hp, hbase p, ite_eq_right] rintro ⟨hq, -⟩ exact hp (by rw [hq]) @@ -1307,21 +1308,21 @@ theorem succCode_output_cells (a : Code tm.Q k x.length S) (β : Bool) (p : Fin have hbase : ∀ q : Fin (S + 2), (decodeCfg x S a).output.cells q.val = a.2.2.2.2 q := by intro q show (if h : q.val < S + 2 then a.2.2.2.2 ⟨q.val, h⟩ else Γ.blank) = _ - rw [dif_pos q.isLt] + rw [dite_eq_left q.isLt] have hhead : (decodeCfg x S a).output.head = a.2.2.2.1.val := rfl by_cases h0 : a.2.2.2.1.val = 0 - · rw [if_pos (by rw [hhead, h0])] - rw [hbase p, if_neg] + · rw [ite_eq_left (by rw [hhead, h0])] + rw [hbase p, ite_eq_right] rintro ⟨hp, hpos⟩ rw [hp, h0] at hpos omega - · rw [if_neg (by rw [hhead]; exact h0)] + · rw [ite_eq_right (by rw [hhead]; exact h0)] show Function.update (decodeCfg x S a).output.cells (decodeCfg x S a).output.head _ p.val = _ rw [hhead] by_cases hp : p.val = a.2.2.2.1.val - · rw [hp, Function.update_self, if_pos ⟨Fin.ext hp, by omega⟩] - · rw [Function.update_of_ne hp, hbase p, if_neg] + · rw [hp, Function.update_self, ite_eq_left ⟨Fin.ext hp, by omega⟩] + · rw [Function.update_of_ne hp, hbase p, ite_eq_right] rintro ⟨hq, -⟩ exact hp (by rw [hq]) diff --git a/Complexitylib/Classes/Containments/Internal/BlockSearch.lean b/Complexitylib/Classes/Containments/Internal/BlockSearch.lean index a2a921de..06851572 100644 --- a/Complexitylib/Classes/Containments/Internal/BlockSearch.lean +++ b/Complexitylib/Classes/Containments/Internal/BlockSearch.lean @@ -100,11 +100,11 @@ def addBlock (R b V : List Bool) : List Bool := selectHead (memFlag R b V) V (V theorem addBlock_eq_self (R b V : List Bool) (h : memFlag R b V = [true]) : addBlock R b V = V := by - rw [addBlock, selectHead, if_pos (by rw [h]; rfl)] + rw [addBlock, selectHead, ite_eq_left (by rw [h]; rfl)] theorem addBlock_eq_append (R b V : List Bool) (h : memFlag R b V = [false]) : addBlock R b V = V ++ b := by - rw [addBlock, selectHead, if_neg (by rw [h]; simp), if_pos (by rw [h]; rfl)] + rw [addBlock, selectHead, ite_eq_right (by rw [h]; simp), ite_eq_left (by rw [h]; rfl)] theorem addBlockFn_mem_FP {a b c : List Bool → List Bool} (ha : a ∈ FP) (hb : b ∈ FP) (hc : c ∈ FP) : (fun z => addBlock (a z) (b z) (c z)) ∈ FP := @@ -131,7 +131,7 @@ theorem guardRulerFn_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb (m : ℕ) : (fun z => guardRuler m (a z) (b z)) ∈ FP := by have hcons : (fun z => false :: b z) ∈ FP := by have := mem_FP_comp hb (Cobham.cons_mem_FP false) - simpa [Function.comp] using this + exact this exact Cobham.mulLenFn_mem_FP hcons (wideRulerFn_mem_FP ha m) @[simp] theorem guardRuler_length (m : ℕ) (R r : List Bool) : @@ -186,15 +186,16 @@ theorem searchStep_pack (tm : NTM k) (m : ℕ) (R r V : List Bool) : rw [searchStep, searchPack, searchStepPair] simp only [pairFst_pair, pairSnd_pair] by_cases hle : (guardRuler m R r).length ≤ V.length - · rw [if_pos hle, selectHead, - if_pos (by rw [(Cobham.lenLeFlag_eq_true_iff V (guardRuler m R r)).mpr hle]; rfl)] + · rw [ite_eq_left hle, selectHead, + ite_eq_left (by rw [(Cobham.lenLeFlag_eq_true_iff V (guardRuler m R r)).mpr hle]; rfl)] rfl · have hflag : lenLeFlag V (guardRuler m R r) = [false] := by rcases Cobham.lenLeFlag_flag V (guardRuler m R r) with h | h · rw [Cobham.lenLeFlag_eq_true_iff V (guardRuler m R r)] at h omega · exact h - rw [if_neg hle, selectHead, if_neg (by rw [hflag]; simp), if_pos (by rw [hflag]; rfl)] + rw [ite_eq_right hle, selectHead, ite_eq_right (by rw [hflag]; simp), + ite_eq_left (by rw [hflag]; rfl)] rfl /-- **The packed iteration is the unpacked one.** -/ @@ -215,19 +216,19 @@ theorem searchStep_mem_FP (tm : NTM k) (m : ℕ) : searchStep tm m ∈ FP := by (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hR := hfst hid have hw := hsnd hid have hr := hfst hw have hV := hsnd hw have hcons : (fun z => false :: pairFst (pairSnd z)) ∈ FP := by have := mem_FP_comp hr (Cobham.cons_mem_FP false) - simpa [Function.comp] using this + exact this exact Cobham.pairFn_mem_FP hR (Cobham.pairFn_mem_FP hcons (Cobham.selectHeadFn_mem_FP (lenLeFlagFn_mem_FP hV (guardRulerFn_mem_FP hR hr m)) (searchBodyFn_mem_FP tm m hR hr hV) hV)) diff --git a/Complexitylib/Classes/Containments/Internal/BlockSearchCorrect.lean b/Complexitylib/Classes/Containments/Internal/BlockSearchCorrect.lean index e70cee47..10e40978 100644 --- a/Complexitylib/Classes/Containments/Internal/BlockSearchCorrect.lean +++ b/Complexitylib/Classes/Containments/Internal/BlockSearchCorrect.lean @@ -237,7 +237,7 @@ theorem searchStepPair_ok (tm : NTM k) {L : Language} {S : ℕ → ℕ} rw [searchStepPair] by_cases hg : (guardRuler (codeBlocks k) (blockRuler W) r).length ≤ (codesOf W cs).flatten.length - · rw [if_pos hg] + · rw [ite_eq_left hg] have hj : r.length < cs.length := by rw [hguard, hlen] at hg by_contra hcon @@ -296,7 +296,7 @@ theorem searchStepPair_ok (tm : NTM k) {L : Language} {S : ℕ → ℕ} exact hcsub₁ _ hmem₁ · rw [hstep₁] exact hmem₂ - · rw [if_neg hg] + · rw [ite_eq_right hg] refine ⟨cs, rfl, hnd, hreach, hinit, ?_⟩ intro i hi hi' β have hi2 : i < r.length + 1 := hi diff --git a/Complexitylib/Classes/Containments/Internal/CodeSearch.lean b/Complexitylib/Classes/Containments/Internal/CodeSearch.lean index a65b51e8..60e5dbf3 100644 --- a/Complexitylib/Classes/Containments/Internal/CodeSearch.lean +++ b/Complexitylib/Classes/Containments/Internal/CodeSearch.lean @@ -75,16 +75,16 @@ theorem decodeCfg_cfgCode {x : List Bool} {S : ℕ} {c : Cfg k Q} · simpa [decodeCfg, cfgCode] using by omega · funext p by_cases hp : p < S + 1 - · simp only [decodeCfg, cfgCode, dif_pos hp] - · simp only [decodeCfg, cfgCode, dif_neg hp] + · simp only [decodeCfg, cfgCode, dite_eq_left hp] + · simp only [decodeCfg, cfgCode, dite_eq_right hp] exact (hw.work i p (by omega)).symm · have hh : c.output.head ≤ S + 1 := hs.2 refine Tape.ext ?_ ?_ · simpa [decodeCfg, cfgCode] using by omega · funext p by_cases hp : p < S + 2 - · simp only [decodeCfg, cfgCode, dif_pos hp] - · simp only [decodeCfg, cfgCode, dif_neg hp] + · simp only [decodeCfg, cfgCode, dite_eq_left hp] + · simp only [decodeCfg, cfgCode, dite_eq_right hp] exact (hw.output p (by omega)).symm namespace NTM @@ -126,7 +126,7 @@ theorem mem_reachCodes_iff {x : List Bool} {S : ℕ} {c₀ : Cfg k tm.Q} | succ t ih => intro a simp only [reachCodes, codeRound, Finset.mem_union, Finset.mem_biUnion, reachSet_succ, - Set.mem_union, Set.mem_setOf_eq] + Set.mem_union, Set.mem_ofPred_eq] constructor · rintro (h | ⟨b, hb, hab⟩) · obtain ⟨c, hc, hca⟩ := (ih a).mp h @@ -135,8 +135,8 @@ theorem mem_reachCodes_iff {x : List Bool} {S : ℕ} {c₀ : Cfg k tm.Q} have hreach := reachesCfg_of_mem_reachSet tm c₀ t hc rw [codeSucc, decodeCfg_cfgCode (hw c hreach) (hs c hreach)] at hab by_cases hhalt : c.state = tm.qhalt - · rw [if_pos hhalt] at hab; exact absurd hab (Finset.notMem_empty a) - · rw [if_neg hhalt, Finset.mem_insert, Finset.mem_singleton] at hab + · rw [ite_eq_left hhalt] at hab; exact absurd hab (Finset.notMem_empty a) + · rw [ite_eq_right hhalt, Finset.mem_insert, Finset.mem_singleton] at hab rcases hab with rfl | rfl · exact ⟨tm.stepCfg false c, Or.inr ⟨c, hc, hhalt, false, rfl⟩, rfl⟩ · exact ⟨tm.stepCfg true c, Or.inr ⟨c, hc, hhalt, true, rfl⟩, rfl⟩ @@ -144,7 +144,7 @@ theorem mem_reachCodes_iff {x : List Bool} {S : ℕ} {c₀ : Cfg k tm.Q} · exact Or.inl ((ih _).mpr ⟨c, hc, rfl⟩) · refine Or.inr ⟨cfgCode x.length S c', (ih _).mpr ⟨c', hc', rfl⟩, ?_⟩ have hreach := reachesCfg_of_mem_reachSet tm c₀ t hc' - rw [codeSucc, decodeCfg_cfgCode (hw c' hreach) (hs c' hreach), if_neg hhalt] + rw [codeSucc, decodeCfg_cfgCode (hw c' hreach) (hs c' hreach), ite_eq_right hhalt] cases b · exact Finset.mem_insert_self _ _ · exact Finset.mem_insert_of_mem (Finset.mem_singleton_self _) diff --git a/Complexitylib/Classes/Containments/Internal/ComplementSpace.lean b/Complexitylib/Classes/Containments/Internal/ComplementSpace.lean index 2c437eda..f4583c1a 100644 --- a/Complexitylib/Classes/Containments/Internal/ComplementSpace.lean +++ b/Complexitylib/Classes/Containments/Internal/ComplementSpace.lean @@ -166,7 +166,7 @@ theorem CompInv.step {tm : TM n} {L : Language} {S : ℕ → ℕ} (hdec : tm.Dec have hqc : q = c₀.state := (Sum.inl.injEq _ _ ▸ hstate).symm have hq0 : c₀.state ≠ tm.qhalt := by rw [← hqc]; exact hq obtain ⟨c₀', hstep0⟩ : ∃ c₀', tm.step c₀ = some c₀' := by - rw [TM.step, if_neg hq0]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq0]; exact ⟨_, rfl⟩ have hsimstep : tm.complementTM.step (complementCfg tm c₀) = some (complementCfg tm c₀') := by have h := complementTM_simulation tm (TM.reachesIn.step hstep0 TM.reachesIn.zero) cases h with diff --git a/Complexitylib/Classes/Containments/Internal/ConfigGraph.lean b/Complexitylib/Classes/Containments/Internal/ConfigGraph.lean index 9671e83d..cdd742d3 100644 --- a/Complexitylib/Classes/Containments/Internal/ConfigGraph.lean +++ b/Complexitylib/Classes/Containments/Internal/ConfigGraph.lean @@ -66,9 +66,9 @@ theorem reachesCfg_trace (tm : NTM k) : | T + 1, choices, c => by rw [NTM.trace] by_cases h : c.state = tm.qhalt - · simp only [h, if_pos] + · simp only [h, ite_eq_left] exact reachesCfg_refl tm c - · simp only [h, if_neg, not_false_iff] + · simp only [h, ite_eq_right, not_false_iff] refine reachesCfg_head ⟨h, choices ⟨0, Nat.zero_lt_succ T⟩, rfl⟩ ?_ exact reachesCfg_trace tm T _ _ @@ -81,8 +81,12 @@ theorem exists_trace_of_reachesCfg {c c' : Cfg k tm.Q} (h : tm.ReachesCfg c c') obtain ⟨hne, b, rfl⟩ := hstep obtain ⟨t, choices, hchoices⟩ := ih refine ⟨t + 1, Fin.cons b choices, ?_⟩ - rw [NTM.trace, if_neg hne] - simpa using hchoices + have hcons : (fun i : Fin t => Fin.cons (α := fun _ => Bool) b choices + ⟨i.val + 1, Nat.succ_lt_succ i.isLt⟩) = choices := by + funext i + exact Fin.cons_succ (α := fun _ => Bool) b choices i + rw [NTM.trace, ite_eq_right hne, hcons] + exact hchoices end NTM diff --git a/Complexitylib/Classes/Containments/Internal/CountingCert.lean b/Complexitylib/Classes/Containments/Internal/CountingCert.lean index 46bdef45..e7be5e00 100644 --- a/Complexitylib/Classes/Containments/Internal/CountingCert.lean +++ b/Complexitylib/Classes/Containments/Internal/CountingCert.lean @@ -85,11 +85,11 @@ theorem mem_reachCodes_iff_walk (tm : NTM k) (x : List Bool) (S : ℕ) refine ⟨fun j => if j ≤ i then f j else a, by simp [h0], by simp, fun j hj => ?_⟩ dsimp only rcases Nat.lt_or_ge j i with hlt | hge - · rw [if_pos (by omega), if_pos (by omega)] + · rw [ite_eq_left (by omega), ite_eq_left (by omega)] exact hf j hlt · have hji : j = i := by omega subst hji - rw [if_neg (by omega), if_pos (by omega), hfi] + rw [ite_eq_right (by omega), ite_eq_left (by omega), hfi] exact hstep · rintro ⟨f, h0, hfi, hf⟩ have hmem : f i ∈ reachCodes tm x S a₀ i := diff --git a/Complexitylib/Classes/Containments/Internal/FPBridge.lean b/Complexitylib/Classes/Containments/Internal/FPBridge.lean index 3ca771eb..b128669d 100644 --- a/Complexitylib/Classes/Containments/Internal/FPBridge.lean +++ b/Complexitylib/Classes/Containments/Internal/FPBridge.lean @@ -70,7 +70,7 @@ theorem unFn_mem_FP {g : List Bool → List Bool} {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => g (a z)) ∈ FP := by have hg' : g ∈ FP := CobhamFP_subset_FP hg have h := mem_FP_comp ha hg' - simpa [Function.comp] using h + exact h /-- **A two-argument member of the algebra is an `FP` closure rule.** The two levels differ only in how arguments are presented: the algebra takes a vector, diff --git a/Complexitylib/Classes/Containments/Internal/IPAssemble.lean b/Complexitylib/Classes/Containments/Internal/IPAssemble.lean index 7e66d023..ec0036d6 100644 --- a/Complexitylib/Classes/Containments/Internal/IPAssemble.lean +++ b/Complexitylib/Classes/Containments/Internal/IPAssemble.lean @@ -224,11 +224,9 @@ theorem ip_mem_PSPACE (prot : Protocol) {L : Language} (rp cp mp r w : Polynomia rw [polyRuler_length] at hlen omega · intro x - rw [hN x] omega · -- the step count intro x - rw [hN x] obtain ⟨hT, _, _, _⟩ := ipT_spec prot L rp hex x have hle := IPM.runBound_le (prot.walkParams x) (prot.rounds x.length) have ht : (prot.walkParams x).t = cp.eval x.length := by @@ -245,7 +243,6 @@ theorem ip_mem_PSPACE (prot : Protocol) {L : Language} (rp cp mp r w : Polynomia · -- the flag stays down intro x i hi hlt obtain ⟨_, hdown, _, _⟩ := ipT_spec prot L rp hex x - rw [hN x] at hlt cases i with | zero => omega | succ j => @@ -254,11 +251,11 @@ theorem ip_mem_PSPACE (prot : Protocol) {L : Language} (rp cp mp r w : Polynomia · -- the flag goes up intro x obtain ⟨_, _, hup, _⟩ := ipT_spec prot L rp hex x - rw [hN x, show ipT prot L rp hex x + 2 = (ipT prot L rp hex x + 1) + 1 from rfl, + erw [show ipT prot L rp hex x + 2 = (ipT prot L rp hex x + 1) + 1 from rfl, horb x (ipT prot L rp hex x + 1), IPM.headD_pair_encSst] exact hup · intro x - rw [hN x, horb x (ipT prot L rp hex x + 2)] + erw [horb x (ipT prot L rp hex x + 2)] intro hc have := congrArg List.length hc rw [pair_length] at this @@ -266,7 +263,7 @@ theorem ip_mem_PSPACE (prot : Protocol) {L : Language} (rp cp mp r w : Polynomia · -- the answer intro x obtain ⟨_, _, _, hans⟩ := ipT_spec prot L rp hex x - rw [hN x, horb x (ipT prot L rp hex x + 2), IPM.headD_pair_encSst] + erw [horb x (ipT prot L rp hex x + 2), IPM.headD_pair_encSst] exact hans.symm /-- The polynomial bounding the length of the state the walk carries. -/ diff --git a/Complexitylib/Classes/Containments/Internal/IPEnc.lean b/Complexitylib/Classes/Containments/Internal/IPEnc.lean index 3677ed32..f6079f5b 100644 --- a/Complexitylib/Classes/Containments/Internal/IPEnc.lean +++ b/Complexitylib/Classes/Containments/Internal/IPEnc.lean @@ -167,9 +167,9 @@ theorem step_encOk (P : Params) (D : ℕ) {s : Sst} (h : EncOk P D s) : simp only [Option.some.injEq] at hw rw [← hw] by_cases hokb : P.ok (roundsOf fs) f.a - · rw [if_pos hokb, bumpBits_length] + · rw [ite_eq_left hokb, bumpBits_length] exact hfl.1 - · rw [if_neg hokb] + · rw [ite_eq_right hokb] exact hfl.1 · rw [step_leaf_next P a f fs hl (by simpa using hov)] refine { stkOk := fun hc => by simp at hc @@ -181,9 +181,9 @@ theorem step_encOk (P : Params) (D : ℕ) {s : Sst} (h : EncOk P D s) : · refine ⟨?_, hfl.2⟩ show (if P.ok (roundsOf fs) f.a then bumpBits f.sum else f.sum).length = P.t + 1 by_cases hokb : P.ok (roundsOf fs) f.a - · rw [if_pos hokb, bumpBits_length] + · rw [ite_eq_left hokb, bumpBits_length] exact hfl.1 - · rw [if_neg hokb] + · rw [ite_eq_right hokb] exact hfl.1 · exact hrest g hg · rw [step_push P a f fs hl] diff --git a/Complexitylib/Classes/Containments/Internal/IPLeaf.lean b/Complexitylib/Classes/Containments/Internal/IPLeaf.lean index 5754fa28..611e3d91 100644 --- a/Complexitylib/Classes/Containments/Internal/IPLeaf.lean +++ b/Complexitylib/Classes/Containments/Internal/IPLeaf.lean @@ -301,20 +301,20 @@ theorem chkOnePFn_mem_FP {vf : List Bool → List Bool} (hvf : vf ∈ FP) have hfst : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hV : (fun z => IPM.fV (Y z)) ∈ FP := hfst (hsnd hy) have hBody : (fun z => IPM.fBody (Y z)) ∈ FP := hsnd (hsnd (hsnd (hsnd (hsnd hy)))) have hcons : (fun z => false :: (IPM.fBody (Y z) ++ [true])) ∈ FP := by have hcat := Cobham.appendFn_mem_FP hBody (constFn_mem_FP [true]) have := mem_FP_comp hcat (Cobham.cons_mem_FP false) - simpa [Function.comp] using this + exact this have harg : (fun z => vf (pair (XU z) (false :: (IPM.fBody (Y z) ++ [true])))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hxu hcons) hvf - simpa [Function.comp] using this + exact this exact eqFlagFn_mem_FP hV harg theorem chkStepPFn_mem_FP {vf : List Bool → List Bool} (hvf : vf ∈ FP) : chkStepP vf ∈ FP := by @@ -322,11 +322,11 @@ theorem chkStepPFn_mem_FP {vf : List Bool → List Bool} (hvf : vf ∈ FP) : chk have hfst : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hxu := hfst hid have hw := hsnd hid have hacc := hfst hw @@ -357,7 +357,8 @@ theorem chkFlagFn_mem_FP {vf : List Bool → List Bool} (hvf : vf ∈ FP) have h := Cobham.iterate_mem_FP (chkStepPFn_mem_FP hvf) hinit hR hwidth hbound have h1 := mem_FP_comp h Cobham.sndBlock_mem_FP have h2 := mem_FP_comp h1 Cobham.fstBlock_mem_FP - simpa [Function.comp, chkFlag] using h2 + simp [chkFlag] + exact h2 theorem okFnFn_mem_FP {vf vd : List Bool → List Bool} (hvf : vf ∈ FP) (hvd : vd ∈ FP) {R X S U : List Bool → List Bool} (hR : R ∈ FP) (hX : X ∈ FP) (hS : S ∈ FP) @@ -365,22 +366,22 @@ theorem okFnFn_mem_FP {vf vd : List Bool → List Bool} (hvf : vf ∈ FP) (hvd : have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hfst : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hxu : (fun z => pair (X z) (U z)) ∈ FP := Cobham.pairFn_mem_FP hX hU have hBody : (fun z => IPM.fBody (pairFst (S z))) ∈ FP := hsnd (hsnd (hsnd (hsnd (hsnd (hfst hS))))) have hcons : (fun z => false :: (IPM.fBody (pairFst (S z)) ++ [true])) ∈ FP := by have hcat := Cobham.appendFn_mem_FP hBody (constFn_mem_FP [true]) have := mem_FP_comp hcat (Cobham.cons_mem_FP false) - simpa [Function.comp] using this + exact this have hverd : (fun z => vd (pair (pair (X z) (U z)) (false :: (IPM.fBody (pairFst (S z)) ++ [true])))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hxu hcons) hvd - simpa [Function.comp] using this + exact this exact andBitFn_mem_FP (chkFlagFn_mem_FP hvf hR hxu (hsnd hS)) hverd /-! ## The leaf test discharges the walk's hypothesis -/ diff --git a/Complexitylib/Classes/Containments/Internal/IPSem.lean b/Complexitylib/Classes/Containments/Internal/IPSem.lean index 5d1e60aa..896c9aed 100644 --- a/Complexitylib/Classes/Containments/Internal/IPSem.lean +++ b/Complexitylib/Classes/Containments/Internal/IPSem.lean @@ -352,9 +352,9 @@ theorem leaf_split (P : Params) (ps : List (List Bool × List Bool)) (k : ℕ) ( classical rw [Ico_eq_insert h, Finset.filter_insert] by_cases hk : P.ok ps (coinOf P k) - · rw [if_pos hk, if_pos hk, Finset.card_insert_of_notMem (by simp)] + · rw [ite_eq_left hk, ite_eq_left hk, Finset.card_insert_of_notMem (by simp)] omega - · rw [if_neg hk, if_neg hk] + · rw [ite_eq_right hk, ite_eq_right hk] omega open Classical in @@ -595,23 +595,23 @@ theorem run_leaf (P : Params) : have hsum : binValLE (if P.ok (roundsOf fs) f.a then bumpBits f.sum else f.sum) = binValLE f.sum + (if P.ok (roundsOf fs) f.a then 1 else 0) := by by_cases hokb : P.ok (roundsOf fs) f.a - · rw [if_pos hokb, if_pos hokb] + · rw [ite_eq_left hokb, ite_eq_left hokb] have h1 : binValLE f.sum + 1 ≤ 2 ^ P.t := by rw [hfv] at hbnd - rw [hsplit, if_pos hokb] at hbnd + rw [hsplit, ite_eq_left hokb] at hbnd omega have h2 : binValLE f.sum + 1 < 2 ^ f.sum.length := by rw [hok.sumLen, pow_succ] have : 0 < 2 ^ P.t := Nat.two_pow_pos _ omega rw [binValLE_bumpBits_of_not_over _ (bumpOver_eq_false_of_lt h2)] - · rw [if_neg hokb, if_neg hokb] + · rw [ite_eq_right hokb, ite_eq_right hokb] omega have hsumLen : (if P.ok (roundsOf fs) f.a then bumpBits f.sum else f.sum).length = P.t + 1 := by by_cases hokb : P.ok (roundsOf fs) f.a - · rw [if_pos hokb, bumpBits_length, hok.sumLen] - · rw [if_neg hokb, hok.sumLen] + · rw [ite_eq_left hokb, bumpBits_length, hok.sumLen] + · rw [ite_eq_right hokb, hok.sumLen] by_cases hov : bumpOver f.a = true · -- the last coin string: pop with the tally have hka : binValLE f.a = 2 ^ P.t - 1 := by @@ -726,7 +726,7 @@ theorem run_branch (P : Params) (hval : ∀ (n : ℕ) (ps : List (List Bool × L coinLen := fun hc => by have hc' : f.lvl.drop 1 = [] := hc show (if f.lvl.drop 1 = [] then zeroCoin P else []).length = P.t - rw [if_pos hc', zeroCoin, List.length_replicate] + rw [ite_eq_left hc', zeroCoin, List.length_replicate] vIdx := fun _ => by show strIdx [] < msgCount P rw [strIdx_nil] @@ -734,7 +734,7 @@ theorem run_branch (P : Params) (hval : ∀ (n : ℕ) (ps : List (List Bool × L aIdx := fun hc => by have hc' : ¬ (f.lvl.drop 1 = []) := hc show strIdx (if f.lvl.drop 1 = [] then zeroCoin P else []) < msgCount P - rw [if_neg hc', strIdx_nil] + rw [ite_eq_right hc', strIdx_nil] exact msgCount_pos P bnd := by rw [childFrm, frameVal_fresh] @@ -895,7 +895,7 @@ theorem frmOk_fresh (P : Params) (hval : ∀ (n : ℕ) (ps : List (List Bool × coinLen := fun hc => by have hc' : lvl = [] := hc show (if lvl = [] then zeroCoin P else []).length = P.t - rw [if_pos hc', zeroCoin, List.length_replicate] + rw [ite_eq_left hc', zeroCoin, List.length_replicate] vIdx := fun _ => by show strIdx [] < msgCount P rw [strIdx_nil] @@ -903,7 +903,7 @@ theorem frmOk_fresh (P : Params) (hval : ∀ (n : ℕ) (ps : List (List Bool × aIdx := fun hc => by have hc' : ¬ (lvl = []) := hc show strIdx (if lvl = [] then zeroCoin P else []) < msgCount P - rw [if_neg hc', strIdx_nil] + rw [ite_eq_right hc', strIdx_nil] exact msgCount_pos P bnd := by rw [frameVal_fresh P ps body lvl]; exact hval _ _ } diff --git a/Complexitylib/Classes/Containments/Internal/IPStep.lean b/Complexitylib/Classes/Containments/Internal/IPStep.lean index 2e0c48f3..aba8cfc7 100644 --- a/Complexitylib/Classes/Containments/Internal/IPStep.lean +++ b/Complexitylib/Classes/Containments/Internal/IPStep.lean @@ -380,15 +380,15 @@ theorem ipStepFn_mem_FP {A B C : List Bool → List Bool} have hfst : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hcons : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => false :: a z) ∈ FP := by intro a ha have := mem_FP_comp ha (Cobham.cons_mem_FP false) - simpa [Function.comp] using this + exact this -- the state's fields have hD : (fun z => sDone (C z)) ∈ FP := hfst hC have hAns : (fun z => sAns (C z)) ∈ FP := hfst (hsnd hC) diff --git a/Complexitylib/Classes/Containments/Internal/PHAssemble.lean b/Complexitylib/Classes/Containments/Internal/PHAssemble.lean index a2d37e80..d3b2f340 100644 --- a/Complexitylib/Classes/Containments/Internal/PHAssemble.lean +++ b/Complexitylib/Classes/Containments/Internal/PHAssemble.lean @@ -138,11 +138,11 @@ theorem rewindX_hoareTime (k : ℕ) (x : List Bool) (B : ℕ) (hB : x.length + 1 · rw [hj] show (if xIdx k ∈ [xIdx k] then (⟨1, (work (xIdx k)).cells⟩ : Tape) else _) = copiedBank k x (xIdx k) - rw [if_pos (List.mem_singleton.mpr rfl), copiedBank, Function.update_self] + rw [ite_eq_left (List.mem_singleton.mpr rfl), copiedBank, Function.update_self] exact Tape.eq_init_move_right_of_hasBinaryString (Tape.hasBinaryString_of_hasBinaryPrefix hx rfl rfl) hx0 · show (if j ∈ [xIdx k] then _ else TM.parkTape (work j)) = copiedBank k x j - rw [if_neg (fun hmem => hj (List.mem_singleton.mp hmem)), copiedBank_of_ne k x j hj, + rw [ite_eq_right (fun hmem => hj (List.mem_singleton.mp hmem)), copiedBank_of_ne k x j hj, hother j hj, TM.parkTape] exact Tape.ext rfl rfl · rw [hpo, ho, TM.parkTape] @@ -200,7 +200,7 @@ theorem enumTM_hoareTime (M : TM k) {L' : Language} {T S : ℕ → ℕ} (N * (bBody + bTest + 5)) := by refine hloop.strengthen_post ?_ rintro inp work out ⟨hi, hw, ho⟩ - exact ⟨hi, hw, by rw [ho, if_pos rfl]⟩ + exact ⟨hi, hw, by rw [ho, ite_eq_left rfl]⟩ have h56 := TM.seqTM_hoareTime _ _ hloop' (hpinned _ _ (enumBank_parked k x N H N _ _) (NTM.outSlot_parked _)) hepi have hprol : (prologueTM k p q).HoareTime diff --git a/Complexitylib/Classes/Containments/Internal/PHBank.lean b/Complexitylib/Classes/Containments/Internal/PHBank.lean index 064ad1f6..4837ab37 100644 --- a/Complexitylib/Classes/Containments/Internal/PHBank.lean +++ b/Complexitylib/Classes/Containments/Internal/PHBank.lean @@ -62,13 +62,13 @@ theorem strTape_startInvariant (l : List Bool) : Tape.StartInvariant (strTape l) theorem regTape_parked (v : ℕ) : TM.Parked (TM.regTape v) := by refine ⟨le_of_eq rfl, fun j hj => ?_⟩ show (if j = 0 then Γ.start else if j ≤ v then Γ.one else Γ.blank) ≠ Γ.start - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] split <;> decide theorem regTape_startInvariant (v : ℕ) : Tape.StartInvariant (TM.regTape v) := by refine ⟨rfl, fun j hj => ?_⟩ show (if j = 0 then Γ.start else if j ≤ v then Γ.one else Γ.blank) ≠ Γ.start - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] split <;> decide /-- **The resting bank at a given count.** The input copy and the horizon are where the prologue @@ -83,12 +83,12 @@ def enumRest (k : ℕ) (x : List Bool) (N H : ℕ) (v : ℕ) : Fin (enumTapes k) @[simp] theorem enumRest_x (k : ℕ) (x : List Bool) (N H v : ℕ) : enumRest k x N H v (xIdx k) = strTape x := by - rw [enumRest, if_pos rfl] + rw [enumRest, ite_eq_left rfl] @[simp] theorem enumRest_w (k : ℕ) (x : List Bool) (N H v : ℕ) : enumRest k x N H v (wIdx k) = strTape (dropTop v) := by obtain ⟨hxw, -⟩ := enumIdx_distinct k - rw [enumRest, if_neg (fun h => hxw h.symm), if_pos rfl] + rw [enumRest, ite_eq_right (fun h => hxw h.symm), ite_eq_left rfl] @[simp] theorem enumRest_n (k : ℕ) (x : List Bool) (N H v : ℕ) : enumRest k x N H v (nIdx k) = natTape N := by @@ -100,7 +100,7 @@ def enumRest (k : ℕ) (x : List Bool) (N H : ℕ) (v : ℕ) : Fin (enumTapes k) have h' := congrArg Fin.val h simp only [nIdx, wIdx] at h' omega - rw [enumRest, if_neg hxn, if_neg hwn, if_pos rfl] + rw [enumRest, ite_eq_right hxn, ite_eq_right hwn, ite_eq_left rfl] /-- **The bank is parked at every index**, which is what the loop rule asks of the tapes its state does not name. -/ diff --git a/Complexitylib/Classes/Containments/Internal/PHBody.lean b/Complexitylib/Classes/Containments/Internal/PHBody.lean index b17ef1ae..f498bd52 100644 --- a/Complexitylib/Classes/Containments/Internal/PHBody.lean +++ b/Complexitylib/Classes/Containments/Internal/PHBody.lean @@ -81,7 +81,7 @@ theorem enumBank_of_ne (k : ℕ) (x : List Bool) (N H v a r : ℕ) (i : Fin (enu enumBank k x N H v a r i = enumRest k x N H (v + 1) i := by rw [enumBank, tallyWork] dsimp only - rw [if_neg hc, if_neg ha, if_neg hr] + rw [ite_eq_right hc, ite_eq_right ha, ite_eq_right hr] theorem ne_tallyRegs {k : ℕ} (i : Fin (enumTapes k)) (h2 : i.val ≠ 3 + k + 2) (h5 : i.val ≠ 3 + k + 5) (h8 : i.val ≠ 3 + k + 8) : @@ -138,7 +138,7 @@ theorem reg_ne_regs (k : ℕ) : regIdx k ≠ cIdx k ∧ regIdx k ≠ aIdx k ∧ theorem enumRest_blank (k : ℕ) (x : List Bool) (N H v : ℕ) (i : Fin (enumTapes k)) (hx : i ≠ xIdx k) (hw : i ≠ wIdx k) (hn : i ≠ nIdx k) (hreg : i ≠ regIdx k) : enumRest k x N H v i = TM.blankTape := by - rw [enumRest, if_neg hx, if_neg hw, if_neg hn, if_neg hreg] + rw [enumRest, ite_eq_right hx, ite_eq_right hw, ite_eq_right hn, ite_eq_right hreg] theorem enumBank_blank (k : ℕ) (x : List Bool) (N H v a r : ℕ) (i : Fin (enumTapes k)) (hc : i ≠ cIdx k) (ha : i ≠ aIdx k) (hr : i ≠ rIdx k) @@ -349,7 +349,7 @@ theorem parkPair_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I : Tape · rw [hpw] funext j by_cases hj : j ∈ ([xIdx k, wIdx k, y1Idx k] : List (Fin (enumTapes k))) - · rw [if_pos hj] + · rw [ite_eq_left hj] rcases List.mem_cons.mp hj with h | h · rw [h, afterPair, Function.update_of_ne (Fin.ne_of_val_ne (by show (0 : ℕ) ≠ 2; omega)), enumBank_x] @@ -363,7 +363,7 @@ theorem parkPair_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I : Tape exact Tape.eq_init_move_right_of_hasBinaryString (Tape.hasBinaryString_of_hasBinaryPrefix hy1 rfl rfl) (hSI (y1Idx k)).1 · exact absurd h (List.not_mem_nil) - · rw [if_neg hj] + · rw [ite_eq_right hj] have hout : ¬ TM.placeWorkInMiddle (post := k + 9) 0 3 j := fun hm => hj ((mem_pairTargets_iff k j).mpr hm) have hwj : work j = enumBank k x N H v a r j := hframe j hout @@ -465,7 +465,7 @@ theorem matrixEntry_afterCopy (M : TM k) (x : List Bool) (N H v a r : ℕ) (I : funext i rw [matrixEntry] by_cases hi : TM.placeWorkInMiddle 3 (k + 2) i - · rw [dif_pos hi] + · rw [dite_eq_left hi] set j := TM.placeWorkCoord 3 (k + 2) i hi with hjdef have hival : i.val = 3 + j.val := by rw [hjdef] @@ -493,7 +493,7 @@ theorem matrixEntry_afterCopy (M : TM k) (x : List Bool) (N H v a r : ℕ) (I : rw [TM.applyPre, Fin.snoc_castSucc] show (if j'.val < k then (Tape.init ([] : List Γ)).move Dir3.right else (Tape.init ((pair x (dropTop (v + 1))).map Γ.ofBool)).move Dir3.right) = _ - rw [if_pos hjk, afterCopy, + rw [ite_eq_left hjk, afterCopy, Function.update_of_ne (Fin.ne_of_val_ne (by rw [hival, hj]; show 3 + j'.val ≠ 2; omega)), Function.update_of_ne (Fin.ne_of_val_ne (by rw [hival, hj]; show 3 + j'.val ≠ 3 + k; omega)), @@ -510,11 +510,11 @@ theorem matrixEntry_afterCopy (M : TM k) (x : List Bool) (N H v a r : ℕ) (I : rw [TM.applyPre, Fin.snoc_castSucc] show (if j'.val < k then (Tape.init ([] : List Γ)).move Dir3.right else (Tape.init ((pair x (dropTop (v + 1))).map Γ.ofBool)).move Dir3.right) = _ - rw [if_neg hjk, hi', afterCopy, + rw [ite_eq_right hjk, hi', afterCopy, Function.update_of_ne (Fin.ne_of_val_ne (by show 3 + k ≠ 2; omega)), Function.update_self] rfl - · rw [dif_neg hi] + · rw [dite_eq_right hi] theorem afterCopy_startInvariant (k : ℕ) (x : List Bool) (N H v a r : ℕ) (i : Fin (enumTapes k)) : Tape.StartInvariant (afterCopy k x N H v a r i) := by @@ -640,12 +640,12 @@ theorem parkVerdict_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I : T have hvw : c'.work (vIdx k) = (⟨1, (work (vIdx k)).cells⟩ : Tape) := by rw [hpw] show (if vIdx k ∈ [vIdx k] then (⟨1, (work (vIdx k)).cells⟩ : Tape) else _) = _ - rw [if_pos (List.mem_singleton.mpr rfl)] + rw [ite_eq_left (List.mem_singleton.mpr rfl)] have hother : ∀ j, j ≠ vIdx k → c'.work j = TM.parkTape (work j) := by intro j hj rw [hpw] show (if j ∈ [vIdx k] then _ else TM.parkTape (work j)) = _ - rw [if_neg (fun hmem => hj (List.mem_singleton.mp hmem))] + rw [ite_eq_right (fun hmem => hj (List.mem_singleton.mp hmem))] refine ⟨c', t, ht, hreach, hhalt, ?_, ?_, ?_, ?_, ?_, ?_⟩ · rw [hpi, hi] exact Tape.ext hIhead.symm rfl @@ -727,20 +727,20 @@ theorem publishVerdict_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I enumBank k x N H v a r (cIdx k) = natTape v := by rw [enumBank, tallyWork] dsimp only - rw [if_pos rfl] + rw [ite_eq_left rfl] @[simp] theorem enumBank_a (k : ℕ) (x : List Bool) (N H v a r : ℕ) : enumBank k x N H v a r (aIdx k) = natTape a := by rw [enumBank, tallyWork] dsimp only - rw [if_neg (Fin.ne_of_val_ne (by show 3 + k + 5 ≠ 3 + k + 2; omega)), if_pos rfl] + rw [ite_eq_right (Fin.ne_of_val_ne (by show 3 + k + 5 ≠ 3 + k + 2; omega)), ite_eq_left rfl] @[simp] theorem enumBank_r (k : ℕ) (x : List Bool) (N H v a r : ℕ) : enumBank k x N H v a r (rIdx k) = natTape r := by rw [enumBank, tallyWork] dsimp only - rw [if_neg (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 2; omega)), - if_neg (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 5; omega)), if_pos rfl] + rw [ite_eq_right (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 2; omega)), + ite_eq_right (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 5; omega)), ite_eq_left rfl] theorem afterCopy_of_ne (k : ℕ) (x : List Bool) (N H v a r : ℕ) (i : Fin (enumTapes k)) (h1 : i ≠ y1Idx k) (h2 : i ≠ yIdx k) : @@ -831,16 +831,16 @@ theorem tallyBump_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I : Tap · rw [hpw, Function.update_self] · rw [hpw, Function.update_of_ne (Fin.ne_of_val_ne (by show 3 + k + 5 ≠ 3 + k + 2; omega))] by_cases hb : b - · rw [if_pos hb, Function.update_self, if_pos hb] - · rw [if_neg hb, Function.update_of_ne - (Fin.ne_of_val_ne (by show 3 + k + 5 ≠ 3 + k + 8; omega)), ha, if_neg hb] + · rw [ite_eq_left hb, Function.update_self, ite_eq_left hb] + · rw [ite_eq_right hb, Function.update_of_ne + (Fin.ne_of_val_ne (by show 3 + k + 5 ≠ 3 + k + 8; omega)), ha, ite_eq_right hb] rfl · rw [hpw, Function.update_of_ne (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 2; omega))] by_cases hb : b - · rw [if_pos hb, Function.update_of_ne - (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 5; omega)), hr, if_pos hb] + · rw [ite_eq_left hb, Function.update_of_ne + (Fin.ne_of_val_ne (by show 3 + k + 8 ≠ 3 + k + 5; omega)), hr, ite_eq_left hb] rfl - · rw [if_neg hb, Function.update_self, if_neg hb] + · rw [ite_eq_right hb, Function.update_self, ite_eq_right hb] · intro i hm h1 h2 h3 rw [hupd i h1 h2 h3] exact hframe i hm @@ -976,8 +976,8 @@ theorem enumRest_eq_of_ne_w (k : ℕ) (x : List Bool) (N H v v' : ℕ) (i : Fin (hw : i ≠ wIdx k) : enumRest k x N H v i = enumRest k x N H v' i := by rw [enumRest, enumRest] by_cases hx : i = xIdx k - · rw [if_pos hx, if_pos hx] - · rw [if_neg hx, if_neg hx, if_neg hw, if_neg hw] + · rw [ite_eq_left hx, ite_eq_left hx] + · rw [ite_eq_right hx, ite_eq_right hx, ite_eq_right hw, ite_eq_right hw] /-- **The wipe, and the bridge back to the loop invariant.** Blanking everything the pass dirtied turns the bank into the one the loop's state names at the next count. -/ @@ -1006,10 +1006,10 @@ theorem wipe_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I : Tape) enumBank_of_ne k x N H v a r _ (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 3 + k + 2; omega)) (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 3 + k + 5; omega)) - (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 3 + k + 8; omega)), enumRest, if_neg - (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 0; omega)), if_neg - (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 1; omega)), if_neg - (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 3 + k + 3; omega)), if_pos rfl] + (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 3 + k + 8; omega)), enumRest, ite_eq_right + (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 0; omega)), ite_eq_right + (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 1; omega)), ite_eq_right + (Fin.ne_of_val_ne (by show 3 + k + 7 ≠ 3 + k + 3; omega)), ite_eq_left rfl] have hy1 : work (y1Idx k) = (⟨(pair x (dropTop (v + 1))).length + 1, (strTape (pair x (dropTop (v + 1)))).cells⟩ : Tape) := by @@ -1053,11 +1053,11 @@ theorem wipe_hoareTime (k : ℕ) (x : List Bool) (N H v a r : ℕ) (I : Tape) rw [hpw] funext j by_cases hj : j ∈ scratchTargets k - · rw [if_pos hj] + · rw [ite_eq_left hj] have hv := scratchTargets_val k j hj exact (enumBank_blank_of_val k x N H (v + 1) (a + if b then 1 else 0) (r + if b then 0 else 1) j hv.1 hv.2).symm - · rw [if_neg hj] + · rw [ite_eq_right hj] by_cases h1 : j = cIdx k · rw [h1, hc, enumBank_c] · by_cases h2 : j = aIdx k diff --git a/Complexitylib/Classes/Containments/Internal/PHBounds.lean b/Complexitylib/Classes/Containments/Internal/PHBounds.lean index a1434094..95e51c1b 100644 --- a/Complexitylib/Classes/Containments/Internal/PHBounds.lean +++ b/Complexitylib/Classes/Containments/Internal/PHBounds.lean @@ -413,13 +413,13 @@ theorem tally_pos_iff (P : ℕ → Bool) : ∀ N, 0 < NTM.tally P N ↔ ∃ j, j · intro h by_cases hPN : P N · exact ⟨N, by omega, hPN⟩ - · rw [if_neg (by simp [hPN])] at h + · rw [ite_eq_right (by simp [hPN])] at h obtain ⟨j, hj, hPj⟩ := ih.mp (by omega) exact ⟨j, by omega, hPj⟩ · rintro ⟨j, hj, hPj⟩ by_cases hjN : j = N · rw [hjN] at hPj - rw [if_pos (by simp [hPj])] + rw [ite_eq_left (by simp [hPj])] omega · have := ih.mpr ⟨j, by omega, hPj⟩ split <;> omega @@ -646,7 +646,7 @@ theorem enumTM_space (M : TM k) {L' : Language} {f : ℕ → ℕ} (s : Polynomia cases c; subst hst; rfl rw [hce] exact hreach) - (hloopC.strengthen_post (fun inp work out h => ⟨h.1, h.2.1, by rw [h.2.2, if_pos rfl]⟩)) + (hloopC.strengthen_post (fun inp work out h => ⟨h.1, h.2.1, by rw [h.2.2, ite_eq_left rfl]⟩)) (by have := prologueTM_hoareTime k p (bHPoly p s) x rw [← hNdef, show (bHPoly p s).eval x.length = H from by rw [hHdef, bHPoly_eval]] at this diff --git a/Complexitylib/Classes/Containments/Internal/PHEpilogue.lean b/Complexitylib/Classes/Containments/Internal/PHEpilogue.lean index cf400baa..221bf1b6 100644 --- a/Complexitylib/Classes/Containments/Internal/PHEpilogue.lean +++ b/Complexitylib/Classes/Containments/Internal/PHEpilogue.lean @@ -135,7 +135,7 @@ theorem epiloguePostTM_hoareTime (k : ℕ) (b : Bool) (I : Tape) (B : ℕ) (hI : ?_ rintro inp' work' out' ⟨-, -, hout'⟩ rw [hout', ho, show (W' (yIdx k)).read = Γ.ofBool b from by - simp only [hW', if_pos rfl] + simp only [hW', ite_eq_left rfl] show (work (yIdx k)).cells 1 = _ exact hcell] exact NTM.outSlot_write Γw.one (TM.readBackWrite (Γ.ofBool b)) @@ -310,7 +310,6 @@ theorem epiloguePreTM_hoareTime (k : ℕ) (x : List Bool) (N H A R : ℕ) (I : T (fun j => if j = 0 then B0 else if j = 1 then B1 else epilogueBank k x N H A R) (fun _ => NTM.outSlot Γw.one) (max (TM.binarySuccTime 0) (TM.binaryRippleSubTime 1 A)) hI (fun j i => by - dsimp only split · exact enumBank_parked k x N H N A R i · split diff --git a/Complexitylib/Classes/Containments/Internal/PHLoopWindow.lean b/Complexitylib/Classes/Containments/Internal/PHLoopWindow.lean index a4cc9dad..7a322734 100644 --- a/Complexitylib/Classes/Containments/Internal/PHLoopWindow.lean +++ b/Complexitylib/Classes/Containments/Internal/PHLoopWindow.lean @@ -213,7 +213,7 @@ theorem loop_hLL (M : TM k) {L' : Language} (x : List Bool) (N H : ℕ) (I : Tap (TM.tallyTestTM (cIdx k) (nIdx k) (resIdx k))).qhalt from hstate, ↓reduceIte] nofun) | rewindOut => - rw [if_neg (by nofun : ¬ (TM.LoopPhase.rewindOut = TM.LoopPhase.check))] at hhead + rw [ite_eq_right (by nofun : ¬ (TM.LoopPhase.rewindOut = TM.LoopPhase.check))] at hhead obtain ⟨hin', hwork', hcells', hhead'⟩ := TM.loop_phase_step_tapes (bodyTM M) (TM.tallyTestTM (cIdx k) (nIdx k) (resIdx k)) hstate (by nofun) hoSI hstep @@ -263,7 +263,7 @@ theorem loop_hLL (M : TM k) {L' : Language} (x : List Bool) (N H : ℕ) (I : Tap have := hhead' omega | check => - rw [if_pos rfl] at hhead + rw [ite_eq_left rfl] at hhead have hhead1 : c.output.head = 1 := hhead have hread : c.output.read ≠ Γ.start := by show c.output.cells c.output.head ≠ Γ.start @@ -302,10 +302,10 @@ theorem loop_hLL (M : TM k) {L' : Language} (x : List Bool) (N H : ℕ) (I : Tap have hc'eq : c' = d := Option.some_inj.mp hstep.symm have hjN' : j ≠ N := by intro hjeq - rw [hjeq, if_pos rfl] at hcells + rw [hjeq, ite_eq_left rfl] at hcells exact hone (by rw [hcells]; rfl) refine ⟨fun _ => ⟨j, by omega, hbase.1, hbase.2.1, - ⟨if j = N then Γw.one else Γw.zero, by rw [if_neg hjN']; nofun, ?_⟩⟩, + ⟨if j = N then Γw.one else Γw.zero, by rw [ite_eq_right hjN']; nofun, ?_⟩⟩, fun hcon => absurd (hc'eq ▸ hcon) (by rw [hdstate]; nofun), fun ph' hph' => absurd (hc'eq ▸ hph') (by rw [hdstate]; nofun)⟩ rw [hbase.2.2] diff --git a/Complexitylib/Classes/Containments/Internal/PHMatrix.lean b/Complexitylib/Classes/Containments/Internal/PHMatrix.lean index e45402a7..453b31e0 100644 --- a/Complexitylib/Classes/Containments/Internal/PHMatrix.lean +++ b/Complexitylib/Classes/Containments/Internal/PHMatrix.lean @@ -121,22 +121,22 @@ theorem matrixTM_hoareTime (M : TM k) {L : Language} {T S : ℕ → ℕ} (hdec : · intro hy show (if h : TM.placeWorkInMiddle 3 (k + 2) (vIdx k) then c'.work (TM.placeWorkCoord 3 (k + 2) (vIdx k) h) else extras (vIdx k)).cells 1 = Γ.one - rw [dif_pos (vIdx_inMiddle k), placeWorkCoord_vIdx k (vIdx_inMiddle k)] + rw [dite_eq_left (vIdx_inMiddle k), placeWorkCoord_vIdx k (vIdx_inMiddle k)] exact hverdict.1 hy · intro hy show (if h : TM.placeWorkInMiddle 3 (k + 2) (vIdx k) then c'.work (TM.placeWorkCoord 3 (k + 2) (vIdx k) h) else extras (vIdx k)).cells 1 = Γ.zero - rw [dif_pos (vIdx_inMiddle k), placeWorkCoord_vIdx k (vIdx_inMiddle k)] + rw [dite_eq_left (vIdx_inMiddle k), placeWorkCoord_vIdx k (vIdx_inMiddle k)] exact hverdict.2 hy · intro j hj show (if h : TM.placeWorkInMiddle 3 (k + 2) j then _ else extras j) = extras j - rw [dif_neg hj] + rw [dite_eq_right hj] · intro j hj have heq : (TM.placeWorkCfg (TM.applyTM M) 3 7 extras c').work j = c'.work (TM.placeWorkCoord 3 (k + 2) j hj) := by show (if h : TM.placeWorkInMiddle 3 (k + 2) j then c'.work (TM.placeWorkCoord 3 (k + 2) j h) else extras j) = _ - rw [dif_pos hj] + rw [dite_eq_left hj] rw [heq] exact hframe _ diff --git a/Complexitylib/Classes/Containments/Internal/PHPrologue.lean b/Complexitylib/Classes/Containments/Internal/PHPrologue.lean index 778803e6..dfdc95d8 100644 --- a/Complexitylib/Classes/Containments/Internal/PHPrologue.lean +++ b/Complexitylib/Classes/Containments/Internal/PHPrologue.lean @@ -48,12 +48,12 @@ theorem blankTape_idle : have hread : TM.blankTape.read = Γ.blank := Tape.init_nil_move_right_read rw [hread] show (TM.blankTape.write Γ.blank).move (TM.idleDir Γ.blank) = TM.blankTape - rw [TM.idleDir, if_neg (by decide)] + rw [TM.idleDir, ite_eq_right (by decide)] refine Tape.ext ?_ ?_ · show (TM.blankTape.write Γ.blank).head = TM.blankTape.head rw [Tape.write_head] · show (TM.blankTape.write Γ.blank).cells = TM.blankTape.cells - rw [Tape.write, if_neg (by show ¬ ((1 : ℕ) = 0); omega)] + rw [Tape.write, ite_eq_right (by show ¬ ((1 : ℕ) = 0); omega)] funext j show Function.update TM.blankTape.cells TM.blankTape.head Γ.blank j = TM.blankTape.cells j by_cases hj : j = TM.blankTape.head @@ -83,9 +83,11 @@ theorem copyStep_blank (idx : Fin n) {c c' : Cfg n (TM.copyInputToWorkTM idx).Q} | copying => show (if iH = Γ.blank then TM.allIdle _ iH wH oH else _).2.1 i = _ ∧ (if iH = Γ.blank then TM.allIdle _ iH wH oH else _).2.2.2.2.1 i = _ - split - · exact ⟨rfl, rfl⟩ - · exact ⟨if_neg hi, if_neg hi⟩ + by_cases hb : iH = Γ.blank + · subst hb + exact ⟨rfl, rfl⟩ + · erw [ite_eq_right hb] + exact ⟨ite_eq_right hi, ite_eq_right hi⟩ | done => exact ⟨rfl, rfl⟩ obtain ⟨hw, hd⟩ := hwrite c.state c.input.read (fun j => (c.work j).read) c.output.read rw [hw, hd, h] @@ -129,9 +131,11 @@ theorem copyStep_blank_out (idx : Fin n) {c c' : Cfg n (TM.copyInputToWorkTM idx | copying => show (if iH = Γ.blank then TM.allIdle _ iH wH oH else _).2.2.1 = _ ∧ (if iH = Γ.blank then TM.allIdle _ iH wH oH else _).2.2.2.2.2 = _ - split - · exact ⟨rfl, rfl⟩ - · exact ⟨rfl, rfl⟩ + by_cases hb : iH = Γ.blank + · subst hb + exact ⟨rfl, rfl⟩ + · erw [ite_eq_right hb] + exact ⟨rfl, rfl⟩ | done => exact ⟨rfl, rfl⟩ obtain ⟨hw, hd⟩ := hwrite c.state c.input.read (fun j => (c.work j).read) c.output.read rw [hw, hd, h] @@ -224,16 +228,16 @@ theorem regTape_eq_natTape' (T : ℕ) : TM.regTape T = natTape (2 ^ T - 1) := by by_cases hj : j = 0 · rw [hj] show (if (0 : ℕ) = 0 then Γ.start else _) = _ - rw [if_pos rfl, Tape.init_cells_zero] + rw [ite_eq_left rfl, Tape.init_cells_zero] · obtain ⟨i, rfl⟩ : ∃ i, j = i + 1 := ⟨j - 1, by omega⟩ rw [Tape.init_cells_succ] show (if i + 1 = 0 then Γ.start else if i + 1 ≤ T then Γ.one else Γ.blank) = (((2 ^ T - 1).bits.map Γ.ofBool)[i]?).getD Γ.blank - rw [if_neg (by omega), hbits] + rw [ite_eq_right (by omega), hbits] by_cases hi : i < T - · rw [if_pos (by omega)] + · rw [ite_eq_left (by omega)] simp [hi, Γ.ofBool] - · rw [if_neg (by omega)] + · rw [ite_eq_right (by omega)] simp [hi] @@ -245,9 +249,9 @@ theorem regTape_zero' : TM.regTape 0 = TM.blankTape := by by_cases hj : j = 0 · rw [hj] show (if (0 : ℕ) = 0 then Γ.start else _) = _ - rw [if_pos rfl, Tape.init_cells_zero] + rw [ite_eq_left rfl, Tape.init_cells_zero] · show (if j = 0 then Γ.start else if j ≤ 0 then Γ.one else Γ.blank) = _ - rw [if_neg hj, if_neg (by omega), show j = (j - 1) + 1 from by omega, + rw [ite_eq_right hj, ite_eq_right (by omega), show j = (j - 1) + 1 from by omega, Tape.init_nil_cells_succ] /-- And so is a counter tape holding zero. -/ @@ -414,7 +418,6 @@ theorem prologueTM_hoareTime (k : ℕ) (p q : Polynomial ℕ) (x : List Bool) : else if j = 6 then V6 else V7) (fun _ => []) (prologueBnd p q lx) hIp ?_ ?_).consequence ?_ ?_ (le_refl _) · intro j i - dsimp only split · exact hV0P i · split @@ -525,16 +528,16 @@ theorem prologueTM_hoareTime (k : ℕ) (p q : Polynomial ℕ) (x : List Bool) : · rw [hg, hV4, Function.update_self, enumBank_of_ne k x (2 ^ (m + 1) - 1) Hq 0 0 0 _ (reg_ne_regs k).1 (reg_ne_regs k).2.1 (reg_ne_regs k).2.2, enumRest, - if_neg (hne _ _ (by show 3 + k + 7 ≠ 0; omega)), - if_neg (hne _ _ (by show 3 + k + 7 ≠ 1; omega)), - if_neg (hne _ _ (by show 3 + k + 7 ≠ 3 + k + 3; omega)), if_pos rfl] + ite_eq_right (hne _ _ (by show 3 + k + 7 ≠ 0; omega)), + ite_eq_right (hne _ _ (by show 3 + k + 7 ≠ 1; omega)), + ite_eq_right (hne _ _ (by show 3 + k + 7 ≠ 3 + k + 3; omega)), ite_eq_left rfl] · rw [hV4, Function.update_of_ne hg, Function.update_of_ne hy] by_cases hn : j = nIdx k · rw [hn, hV3, Function.update_self, regTape_eq_natTape', enumBank_of_ne k x (2 ^ (m + 1) - 1) Hq 0 0 0 _ (n_ne_regs k).1 (n_ne_regs k).2.1 (n_ne_regs k).2.2, enumRest, - if_neg (hne _ _ (by show 3 + k + 3 ≠ 0; omega)), - if_neg (hne _ _ (by show 3 + k + 3 ≠ 1; omega)), if_pos rfl] + ite_eq_right (hne _ _ (by show 3 + k + 3 ≠ 0; omega)), + ite_eq_right (hne _ _ (by show 3 + k + 3 ≠ 1; omega)), ite_eq_left rfl] · rw [hV3, Function.update_of_ne hn, hV2, Function.update_of_ne hn, Function.update_of_ne hy1, hV1, Function.update_of_ne hs, hV0] by_cases hx : j = xIdx k diff --git a/Complexitylib/Classes/Containments/Internal/PPAssemble.lean b/Complexitylib/Classes/Containments/Internal/PPAssemble.lean index e65c42c8..dc68bdd7 100644 --- a/Complexitylib/Classes/Containments/Internal/PPAssemble.lean +++ b/Complexitylib/Classes/Containments/Internal/PPAssemble.lean @@ -70,18 +70,18 @@ theorem bodyBank_cIdx (k N H v a r : ℕ) : bodyBank k N H v a r (cIdx k) = natT theorem bodyBank_aIdx (k N H v a r : ℕ) : bodyBank k N H v a r (aIdx k) = natTape a := by obtain ⟨hca, -⟩ := bodyIdx_distinct k - simp only [bodyBank, tallyWork, if_neg (Ne.symm hca)] + simp only [bodyBank, tallyWork, ite_eq_right (Ne.symm hca)] simp theorem bodyBank_rIdx (k N H v a r : ℕ) : bodyBank k N H v a r (rIdx k) = natTape r := by obtain ⟨-, hcr, har, -⟩ := bodyIdx_distinct k - simp only [bodyBank, tallyWork, if_neg (Ne.symm hcr), if_neg (Ne.symm har)] + simp only [bodyBank, tallyWork, ite_eq_right (Ne.symm hcr), ite_eq_right (Ne.symm har)] simp theorem bodyBank_rest (k N H v a r : ℕ) (j : Fin (bodyTapes k)) (hc : j ≠ cIdx k) (ha : j ≠ aIdx k) (hr : j ≠ rIdx k) : bodyBank k N H v a r j = bodyRest k N H j := by - simp only [bodyBank, tallyWork, if_neg hc, if_neg ha, if_neg hr] + simp only [bodyBank, tallyWork, ite_eq_right hc, ite_eq_right ha, ite_eq_right hr] theorem bodyBank_parked (k N H v a r : ℕ) : ∀ j, TM.Parked (bodyBank k N H v a r j) := by intro j @@ -188,8 +188,8 @@ theorem bodyBank_eq_of (k N H v a r : ℕ) (W : Fin (bodyTapes k) → Tape) funext j by_cases hj : j ∈ wipeTargets k · obtain ⟨h1, h2, h3, h4, h5⟩ := hsim j hj - rw [if_pos hj, bodyBank_rest k N H v a r j h1 h2 h3, bodyRest_other k N H j h4 h5] - · rw [if_neg hj] + rw [ite_eq_left hj, bodyBank_rest k N H v a r j h1 h2 h3, bodyRest_other k N H j h4 h5] + · rw [ite_eq_right hj] by_cases hjc : j = cIdx k · rw [hjc, hc, bodyBank_cIdx] by_cases hja : j = aIdx k @@ -240,7 +240,7 @@ theorem simCfg_entry (tm : NTM k) (x : List Bool) (N H v a r : ℕ) Fin.ext (by show j.val = 0 + j.val; omega), TM.placeWorkCfg_work_middle] show (if j.val < k then TM.blankTape else natTape v) = _ by_cases hjk : j.val < k - · rw [if_pos hjk, + · rw [ite_eq_left hjk, bodyBank_rest k N H v a r j (hne j (cIdx k) (by simp only [cIdx]; omega)) (hne j (aIdx k) (by simp only [aIdx]; omega)) @@ -248,7 +248,8 @@ theorem simCfg_entry (tm : NTM k) (x : List Bool) (N H v a r : ℕ) bodyRest_other k N H j (hne j (nIdx k) (by simp only [nIdx]; omega)) (hne j (regIdx k) (by simp only [regIdx]; omega))] - · rw [if_neg hjk, show j = cIdx k from Fin.ext (by show j.val = k; omega), bodyBank_cIdx] + · rw [ite_eq_right hjk, show j = cIdx k from Fin.ext (by show j.val = k; omega), + bodyBank_cIdx] · rw [TM.placeWorkCfg_work_extra _ _ _ _ _ _ (fun hcon => hmid hcon.2), hex] congr 1 · have hlast : j = vIdx k := Fin.ext (by @@ -447,13 +448,13 @@ theorem parkStage_hoareTime (k N H v a r T : ℕ) (I : Tape) (b : Bool) · show max (work j).head 1 ≤ 1 + T have := hheadW j omega - · rw [hw'' (cIdx k), if_pos (by simp)] + · rw [hw'' (cIdx k), ite_eq_left (by simp)] exact Tape.ext (by rw [(show (natTape v).head = 1 from rfl)]) hcnt - · rw [hw'' (vIdx k), if_pos (by simp)] - · rw [hw'' (vIdx k), if_pos (by simp)] + · rw [hw'' (vIdx k), ite_eq_left (by simp)] + · rw [hw'' (vIdx k), ite_eq_left (by simp)] exact hverdict · intro j h1 h2 h3 - rw [hw'' j, if_neg (by simp [h2, h3]), hreg j h1 h2 h3] + rw [hw'' j, ite_eq_right (by simp [h2, h3]), hreg j h1 h2 h3] refine Tape.ext ?_ rfl show max (bodyBank k N H v a r j).head 1 = (bodyBank k N H v a r j).head rw [bodyBank_head] @@ -557,25 +558,25 @@ theorem bumpStage_hoareTime (k N H v a r T : ℕ) (I : Tape) (b : Bool) intro j h1 h2 h3 rw [hw', Function.update_of_ne h1] cases b - · simp only [Bool.false_eq_true, if_false] + · simp only [Bool.false_eq_true, ite_false] rw [Function.update_of_ne h3] - · simp only [if_true] + · simp only [ite_true] rw [Function.update_of_ne h2] have hwc : c'.work (cIdx k) = natTape (v + 1) := by rw [hw', Function.update_self] have hwa : c'.work (aIdx k) = natTape (a + if b then 1 else 0) := by rw [hw', Function.update_of_ne (Ne.symm hca)] cases b - · simp only [Bool.false_eq_true, if_false] + · simp only [Bool.false_eq_true, ite_false] rw [Function.update_of_ne har, hav] rfl - · simp only [if_true] + · simp only [ite_true] rw [Function.update_self] have hwr : c'.work (rIdx k) = natTape (r + if b then 0 else 1) := by rw [hw', Function.update_of_ne (Ne.symm hcr)] cases b - · simp only [Bool.false_eq_true, if_false] + · simp only [Bool.false_eq_true, ite_false] rw [Function.update_self] - · simp only [if_true] + · simp only [ite_true] rw [Function.update_of_ne (Ne.symm har), hrv] rfl have hInv' : ∀ j, Tape.StartInvariant (c'.work j) := by @@ -1144,7 +1145,6 @@ theorem epiloguePreTM_hoareTime (k N H a r : ℕ) (I O : Tape) (fun _ => O) bnd hI ?_ (fun _ => hO) ?_).consequence (fun _ _ _ h => h) (fun _ _ _ h => h) (le_refl _) · intro j i - dsimp only split · exact hW0P i · split @@ -1236,7 +1236,7 @@ theorem epiloguePostTM_hoareTime (k : ℕ) (b : Bool) (I : Tape) (B : ℕ) (hI : ?_ rintro inp' work' out' ⟨-, -, hout'⟩ rw [hout', ho, show (W' (cIdx k)).read = Γ.ofBool b from by - simp only [hW', if_pos rfl] + simp only [hW', ite_eq_left rfl] show (work (cIdx k)).cells 1 = _ exact hcell] exact outSlot_write Γw.one (TM.readBackWrite (Γ.ofBool b)) @@ -1617,7 +1617,6 @@ theorem prologueTM_hoareTime (k : ℕ) (p : Polynomial ℕ) (x : List Bool) : else Function.update V4 (resIdx k) (TM.regTape 0)) (fun _ => []) bnd hIp ?_ ?_).consequence ?_ ?_ (le_refl _) · intro j i - dsimp only split · exact hV0P i · split @@ -1789,7 +1788,7 @@ theorem ppMachine_hoareTime (k : ℕ) (tm : NTM k) (x : List Bool) refine (epilogueTM_hoareTime k N (1 + T) (tally P N) (tally (fun u => !P u) N) (bodyInput x) hIp hIsi).weaken_pre ?_ rintro inp work out ⟨hi, hw, ho⟩ - exact ⟨hi, hw, by rw [ho, if_pos rfl]⟩ + exact ⟨hi, hw, by rw [ho, ite_eq_left rfl]⟩ exact TM.seqTM_hoareTime _ _ p0 (htr (fun _ => TM.blankTape) TM.blankTape (fun _ => TM.blankTape_parked) TM.blankTape_parked) @@ -1898,7 +1897,7 @@ theorem loopEpilogue_keepsWindowOn (tm : NTM k) (x : List Bool) (hne : tm.qstart · rw [hw] exact funext fun i => TM.transitionTape_eq_self (bodyBank_parked k N (1 + T) N (tally P N) (tally (fun u => !P u) N) i).read_ne_start - · rw [ho, if_pos rfl] + · rw [ho, ite_eq_left rfl] exact TM.transitionTape_eq_self (outSlot_parked Γw.one).read_ne_start @@ -2334,14 +2333,12 @@ theorem zeroTM_hoareTime (k : ℕ) (x : List Bool) : (fun j => if j ≤ 2 then TM.blankTape else outSlot Γw.zero) b hIp ?_ ?_ ?_).consequence (fun _ _ _ h => h) (fun _ _ _ h => h) (le_refl _) · intro j i - dsimp only split · exact hV0P i · split · exact hV1P i · exact hV2P i · intro j - dsimp only split · exact TM.blankTape_parked · exact outSlot_parked _ diff --git a/Complexitylib/Classes/Containments/Internal/PPBody.lean b/Complexitylib/Classes/Containments/Internal/PPBody.lean index aa372382..db05de56 100644 --- a/Complexitylib/Classes/Containments/Internal/PPBody.lean +++ b/Complexitylib/Classes/Containments/Internal/PPBody.lean @@ -134,7 +134,7 @@ theorem condBumpTM_hoareTime (aIdx rIdx : Fin n) (a r : ℕ) (b : Bool) (s : Γw exact ⟨c', t, ht, hreach, hhalt, hb, hpost⟩ · rintro inp work out ⟨hb, rfl, rfl, rfl⟩ refine ⟨hIdI, ?_, hIdO⟩ - rw [if_pos hb] + rw [ite_eq_left hb] funext i exact transitionTape_eq_self (by by_cases hi : i = aIdx @@ -144,7 +144,7 @@ theorem condBumpTM_hoareTime (aIdx rIdx : Fin n) (a r : ℕ) (b : Bool) (s : Γw · rw [Function.update_of_ne hi]; exact (hW i).read_ne_start) · rintro inp work out ⟨hb, rfl, rfl, rfl⟩ refine ⟨hIdI, ?_, hIdO⟩ - rw [if_neg (by simp [hb])] + rw [ite_eq_right (by simp [hb])] funext i exact transitionTape_eq_self (by by_cases hi : i = rIdx @@ -230,14 +230,12 @@ theorem tallyBumpTM_hoareTime (cIdx aIdx rIdx zIdx : Fin n) (max (1 + 1 + max (binarySuccTime a) (binarySuccTime r) + 5) (binarySuccTime v)) hI ?_ ?_ ?_).consequence (fun _ _ _ h => h) (fun _ _ _ h => h) (le_refl _) · intro k i - dsimp only split · exact hW i · split · exact hW₁P i · exact hW₂P i · intro k - dsimp only split · exact hOP · exact hObP diff --git a/Complexitylib/Classes/Containments/Internal/PPLayout.lean b/Complexitylib/Classes/Containments/Internal/PPLayout.lean index b0b578c7..7c793cae 100644 --- a/Complexitylib/Classes/Containments/Internal/PPLayout.lean +++ b/Complexitylib/Classes/Containments/Internal/PPLayout.lean @@ -106,9 +106,9 @@ theorem regTape_zero : TM.regTape 0 = TM.blankTape := by by_cases hj : j = 0 · rw [hj] show (if (0 : ℕ) = 0 then Γ.start else _) = _ - rw [if_pos rfl, Tape.init_cells_zero] + rw [ite_eq_left rfl, Tape.init_cells_zero] · show (if j = 0 then Γ.start else if j ≤ 0 then Γ.one else Γ.blank) = _ - rw [if_neg hj, if_neg (by omega), show j = (j - 1) + 1 from by omega, + rw [ite_eq_right hj, ite_eq_right (by omega), show j = (j - 1) + 1 from by omega, Tape.init_nil_cells_succ] @@ -136,16 +136,16 @@ theorem regTape_eq_natTape (T : ℕ) : TM.regTape T = natTape (2 ^ T - 1) := by by_cases hj : j = 0 · rw [hj] show (if (0 : ℕ) = 0 then Γ.start else _) = _ - rw [if_pos rfl, Tape.init_cells_zero] + rw [ite_eq_left rfl, Tape.init_cells_zero] · obtain ⟨i, rfl⟩ : ∃ i, j = i + 1 := ⟨j - 1, by omega⟩ rw [Tape.init_cells_succ] show (if i + 1 = 0 then Γ.start else if i + 1 ≤ T then Γ.one else Γ.blank) = (((2 ^ T - 1).bits.map Γ.ofBool)[i]?).getD Γ.blank - rw [if_neg (by omega), hbits] + rw [ite_eq_right (by omega), hbits] by_cases hi : i < T - · rw [if_pos (by omega)] + · rw [ite_eq_left (by omega)] simp [hi, Γ.ofBool] - · rw [if_neg (by omega)] + · rw [ite_eq_right (by omega)] simp [hi] /-- **The registers are pairwise distinct**, and none of them is one of the simulation's tapes. -/ @@ -182,12 +182,12 @@ theorem bodyRest_regIdx (k N H : ℕ) : bodyRest k N H (regIdx k) = TM.regTape H have := congrArg Fin.val h simp only [regIdx, nIdx] at this omega - simp only [bodyRest, if_neg h] + simp only [bodyRest, ite_eq_right h] simp theorem bodyRest_other (k N H : ℕ) (j : Fin (bodyTapes k)) (hn : j ≠ nIdx k) (hr : j ≠ regIdx k) : bodyRest k N H j = TM.blankTape := by - simp only [bodyRest, if_neg hn, if_neg hr] + simp only [bodyRest, ite_eq_right hn, ite_eq_right hr] theorem bodyRest_parked (k N H : ℕ) : ∀ j, TM.Parked (bodyRest k N H j) := by intro j diff --git a/Complexitylib/Classes/Containments/Internal/PPParts.lean b/Complexitylib/Classes/Containments/Internal/PPParts.lean index 3d0191b5..8c855a71 100644 --- a/Complexitylib/Classes/Containments/Internal/PPParts.lean +++ b/Complexitylib/Classes/Containments/Internal/PPParts.lean @@ -193,23 +193,23 @@ theorem tallyState_iff {n : ℕ} (cIdx aIdx rIdx : Fin n) simpa [natTape] using hc.eq_init_move_right · by_cases hia : i = aIdx · subst hia - simp only [if_neg hic] + simp only [ite_eq_right hic] simpa [natTape] using ha.eq_init_move_right · by_cases hir : i = rIdx · subst hir - simp only [if_neg hic, if_neg hia] + simp only [ite_eq_right hic, ite_eq_right hia] simpa [natTape] using hr.eq_init_move_right - · simp only [if_neg hic, if_neg hia, if_neg hir] + · simp only [ite_eq_right hic, ite_eq_right hia, ite_eq_right hir] exact hother i hic hia hir · rintro ⟨hi, rfl, ho⟩ refine ⟨hi, ho, ?_, ?_, ?_, ?_⟩ · simpa [tallyWork, natTape] using Tape.init_move_right_hasBinaryNat st.1 - · simp only [tallyWork, if_neg hca.symm] + · simp only [tallyWork, ite_eq_right hca.symm] exact Tape.init_move_right_hasBinaryNat st.2.1 - · simp only [tallyWork, if_neg hcr.symm, if_neg har.symm] + · simp only [tallyWork, ite_eq_right hcr.symm, ite_eq_right har.symm] exact Tape.init_move_right_hasBinaryNat st.2.2 · intro i hic hia hir - simp only [tallyWork, if_neg hic, if_neg hia, if_neg hir] + simp only [tallyWork, ite_eq_right hic, ite_eq_right hia, ite_eq_right hir] /-- Canonical number tapes read a digit or a blank, never the left marker. -/ @@ -264,7 +264,7 @@ theorem binarySucc_tallyState {n : ℕ} (cIdx aIdx rIdx : Fin n) rw [tallyState_iff cIdx aIdx rIdx hca hcr har] at hpre obtain ⟨hinp, hwork, hore⟩ := hpre have hval : (tallyWork cIdx aIdx rIdx rest (v, a, r) aIdx).HasBinaryNat a := by - simp only [tallyWork, if_neg hca.symm] + simp only [tallyWork, ite_eq_right hca.symm] exact Tape.init_move_right_hasBinaryNat a obtain ⟨c', t, ht, hreach, hhalt, hi, hother, hidx, ho⟩ := TM.binarySuccTM_hoareTime_frame aIdx a I (tallyWork cIdx aIdx rIdx rest (v, a, r)) out @@ -274,11 +274,11 @@ theorem binarySucc_tallyState {n : ℕ} (cIdx aIdx rIdx : Fin n) · rw [hother cIdx hca] simpa [tallyWork, natTape] using Tape.init_move_right_hasBinaryNat v · rw [hother rIdx har.symm] - simp only [tallyWork, if_neg hcr.symm, if_neg har.symm] + simp only [tallyWork, ite_eq_right hcr.symm, ite_eq_right har.symm] exact Tape.init_move_right_hasBinaryNat r · intro i hic hia hir rw [hother i hia] - simp only [tallyWork, if_neg hic, if_neg hia, if_neg hir] + simp only [tallyWork, ite_eq_right hic, ite_eq_right hia, ite_eq_right hir] /-- The counter-increment stage. -/ theorem binarySucc_tallyState_counter {n : ℕ} (cIdx aIdx rIdx : Fin n) @@ -300,14 +300,14 @@ theorem binarySucc_tallyState_counter {n : ℕ} (cIdx aIdx rIdx : Fin n) inp work out ⟨hinp, hwork, rfl⟩ refine ⟨c', t, ht, hreach, hhalt, hi, by rw [ho]; exact hore, hidx, ?_, ?_, ?_⟩ · rw [hother aIdx hca.symm] - simp only [tallyWork, if_neg hca.symm] + simp only [tallyWork, ite_eq_right hca.symm] exact Tape.init_move_right_hasBinaryNat a · rw [hother rIdx hcr.symm] - simp only [tallyWork, if_neg hcr.symm, if_neg har.symm] + simp only [tallyWork, ite_eq_right hcr.symm, ite_eq_right har.symm] exact Tape.init_move_right_hasBinaryNat r · intro i hic hia hir rw [hother i hic] - simp only [tallyWork, if_neg hic, if_neg hia, if_neg hir] + simp only [tallyWork, ite_eq_right hic, ite_eq_right hia, ite_eq_right hir] /-- The rejecting-tally-increment stage. -/ theorem binarySucc_tallyState_rej {n : ℕ} (cIdx aIdx rIdx : Fin n) @@ -322,7 +322,7 @@ theorem binarySucc_tallyState_rej {n : ℕ} (cIdx aIdx rIdx : Fin n) rw [tallyState_iff cIdx aIdx rIdx hca hcr har] at hpre obtain ⟨hinp, hwork, hore⟩ := hpre have hval : (tallyWork cIdx aIdx rIdx rest (v, a, r) rIdx).HasBinaryNat r := by - simp only [tallyWork, if_neg hcr.symm, if_neg har.symm] + simp only [tallyWork, ite_eq_right hcr.symm, ite_eq_right har.symm] exact Tape.init_move_right_hasBinaryNat r obtain ⟨c', t, ht, hreach, hhalt, hi, hother, hidx, ho⟩ := TM.binarySuccTM_hoareTime_frame rIdx r I (tallyWork cIdx aIdx rIdx rest (v, a, r)) out @@ -332,11 +332,11 @@ theorem binarySucc_tallyState_rej {n : ℕ} (cIdx aIdx rIdx : Fin n) · rw [hother cIdx hcr] simpa [tallyWork, natTape] using Tape.init_move_right_hasBinaryNat v · rw [hother aIdx har] - simp only [tallyWork, if_neg hca.symm] + simp only [tallyWork, ite_eq_right hca.symm] exact Tape.init_move_right_hasBinaryNat a · intro i hic hia hir rw [hother i hir] - simp only [tallyWork, if_neg hic, if_neg hia, if_neg hir] + simp only [tallyWork, ite_eq_right hic, ite_eq_right hia, ite_eq_right hir] namespace NTM @@ -774,7 +774,7 @@ def outSlot (s : Γw) : Tape where theorem outSlot_parked (s : Γw) : TM.Parked (outSlot s) := by refine ⟨le_refl 1, fun j hj => ?_⟩ show (if j = 0 then Γ.start else if j = 1 then s.toΓ else Γ.blank) ≠ Γ.start - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] split · cases s <;> simp [Γw.toΓ] · simp @@ -881,14 +881,14 @@ theorem tallyLoop_hoareTime_of_hoare {n : ℕ} (tmBody tmTest : TM n) (cIdx aIdx intro a b c hp refine ⟨tallyPost_loopParked cIdx aIdx rIdx I rest P hI hrest N (j + 1) hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_neg (show ¬ (j + 1 = N) by omega)] + rw [ite_eq_right (show ¬ (j + 1 = N) by omega)] exact fun hcon => absurd (outSlot_cells_one_eq_one_iff Γw.zero |>.mp hcon) (by decide) obtain ⟨inp', work', out', t, -, ht, hreach, hp'⟩ := TM.loopTM_continue_of_hoare tmBody tmTest (hbody j hjN) (htest j hjN) (fun a b c hm => hmid j a b c hm) hne inp work out h obtain ⟨hi', hw', ho'⟩ := hp' exact ⟨inp', work', out', t, ht, hreach, hi', hw', Γw.zero, by decide, - by rw [ho', if_neg (by omega)]⟩ + by rw [ho', ite_eq_right (by omega)]⟩ · intro inp work out h have hjN : N - 1 < N := by omega have hhalt : ∀ a b c, tallyPost cIdx aIdx rIdx I rest P N (N - 1 + 1) a b c → @@ -896,7 +896,7 @@ theorem tallyLoop_hoareTime_of_hoare {n : ℕ} (tmBody tmTest : TM n) (cIdx aIdx intro a b c hp refine ⟨tallyPost_loopParked cIdx aIdx rIdx I rest P hI hrest N _ hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_pos hsucc] + rw [ite_eq_left hsucc] exact (outSlot_cells_one_eq_one_iff Γw.one).mpr rfl obtain ⟨c', t, ht, hreach, hstate, hpost⟩ := TM.loopTM_halt_of_hoare tmBody tmTest (hbody (N - 1) hjN) (htest (N - 1) hjN) @@ -932,14 +932,14 @@ theorem tallyLoop_keepsWindow_of_hoare {n : ℕ} (tmBody tmTest : TM n) (cIdx aI intro a b c hp refine ⟨tallyPost_loopParked cIdx aIdx rIdx I rest P hI hrest N (j + 1) hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_neg (show ¬ (j + 1 = N) by omega)] + rw [ite_eq_right (show ¬ (j + 1 = N) by omega)] exact fun hcon => absurd (outSlot_cells_one_eq_one_iff Γw.zero |>.mp hcon) (by decide) obtain ⟨inp', work', out', t, ht1, ht, hreach, hp'⟩ := TM.loopTM_continue_of_hoare tmBody tmTest (hbody j hjN) (htest j hjN) (fun a b c hm => hmid j a b c hm) hne inp work out h obtain ⟨hi', hw', ho'⟩ := hp' exact ⟨inp', work', out', t, ht1, ht, hreach, hi', hw', Γw.zero, by decide, - by rw [ho', if_neg (by omega)]⟩ + by rw [ho', ite_eq_right (by omega)]⟩ · intro inp work out h have hjN : N - 1 < N := by omega have hhalt : ∀ a b c, tallyPost cIdx aIdx rIdx I rest P N (N - 1 + 1) a b c → @@ -947,7 +947,7 @@ theorem tallyLoop_keepsWindow_of_hoare {n : ℕ} (tmBody tmTest : TM n) (cIdx aI intro a b c hp refine ⟨tallyPost_loopParked cIdx aIdx rIdx I rest P hI hrest N _ hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_pos hsucc] + rw [ite_eq_left hsucc] exact (outSlot_cells_one_eq_one_iff Γw.one).mpr rfl obtain ⟨c', t, ht, hreach, hstate, -⟩ := TM.loopTM_halt_of_hoare tmBody tmTest (hbody (N - 1) hjN) (htest (N - 1) hjN) diff --git a/Complexitylib/Classes/Containments/Internal/PPSim.lean b/Complexitylib/Classes/Containments/Internal/PPSim.lean index 3d6bbec8..5c68e2d9 100644 --- a/Complexitylib/Classes/Containments/Internal/PPSim.lean +++ b/Complexitylib/Classes/Containments/Internal/PPSim.lean @@ -132,7 +132,7 @@ def simEntry (tm : NTM k) (x : List Bool) (v : ℕ) : Cfg (k + 1) (simCore tm).Q theorem simEntry_counter (tm : NTM k) (x : List Bool) (v : ℕ) : (simEntry tm x v).work (Fin.last k) = natTape v := by show (if (Fin.last k).val < k then TM.blankTape else natTape v) = _ - rw [if_neg (by simp)] + rw [ite_eq_right (by simp)] theorem simEntry_counter_hasBinaryNat (tm : NTM k) (x : List Bool) (v : ℕ) : ((simEntry tm x v).work (Fin.last k)).HasBinaryNat v := by @@ -158,7 +158,7 @@ theorem simEntry_dropChoice (tm : NTM k) (x : List Bool) (v : ℕ) : · funext i show (if (i.castSucc : Fin (k + 1)).val < k then TM.blankTape else natTape v) = ((Tape.init ([] : List Γ))).move Dir3.right - rw [show (i.castSucc : Fin (k + 1)).val = (i : ℕ) from rfl, if_pos i.isLt] + rw [show (i.castSucc : Fin (k + 1)).val = (i : ℕ) from rfl, ite_eq_left i.isLt] rfl diff --git a/Complexitylib/Classes/Containments/Internal/PPTest.lean b/Complexitylib/Classes/Containments/Internal/PPTest.lean index c9b95697..697d5fc8 100644 --- a/Complexitylib/Classes/Containments/Internal/PPTest.lean +++ b/Complexitylib/Classes/Containments/Internal/PPTest.lean @@ -104,7 +104,7 @@ theorem testTailTM_hoareTime (cIdx nIdx resIdx : Fin n) set Wr := rewoundBank cIdx nIdx resIdx W with hWr have hWrP : ∀ j, Parked (Wr j) := rewoundBank_parked hW have hWrRes : Wr resIdx = ⟨1, (W resIdx).cells⟩ := by - simp only [hWr, rewoundBank, if_pos hresMem] + simp only [hWr, rewoundBank, ite_eq_left hresMem] have hofb : Γ.ofBool b ≠ Γ.start := by cases b <;> simp [Γ.ofBool] have hread : (Wr resIdx).read = Γ.ofBool b := by rw [hWrRes]; show (W resIdx).cells 1 = _; exact hres @@ -118,7 +118,7 @@ theorem testTailTM_hoareTime (cIdx nIdx resIdx : Fin n) refine ⟨le_refl 1, fun i hi => ?_⟩ rw [Tape.move_cells] show (if i = 0 then Γ.start else Γ.blank) ≠ Γ.start - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] simp · rw [hWf, Function.update_of_ne hj]; exact hWrP j set bnd := max (3 * (B + 3) + 1) (resetBinaryWorkTime B 1) with hbnd @@ -129,14 +129,12 @@ theorem testTailTM_hoareTime (cIdx nIdx resIdx : Fin n) (fun k => if k ≤ 1 then O else Ow) bnd hI ?_ ?_ ?_).consequence (fun _ _ _ h => h) (fun _ _ _ h => h) (le_refl _) · intro k i - dsimp only split · exact hW i · split · exact hWrP i · exact hWfP i · intro k - dsimp only split · exact hO · exact hOwP @@ -149,8 +147,8 @@ theorem testTailTM_hoareTime (cIdx nIdx resIdx : Fin n) · rintro inp work out ⟨rfl, rfl, hin, hout⟩ refine ⟨rfl, funext fun j => ?_, rfl⟩ by_cases hj : j ∈ testTargets cIdx nIdx resIdx - · rw [hin j hj]; show _ = Wr j; rw [hWr, rewoundBank, if_pos hj] - · rw [hout j hj]; show _ = Wr j; rw [hWr, rewoundBank, if_neg hj] + · rw [hin j hj]; show _ = Wr j; rw [hWr, rewoundBank, ite_eq_left hj] + · rw [hout j hj]; show _ = Wr j; rw [hWr, rewoundBank, ite_eq_right hj] · show 3 * (B + 3) + 1 ≤ bnd rw [hbnd] exact le_max_left _ _ @@ -231,7 +229,7 @@ theorem tallyTestTM_hoareTime (cIdx nIdx resIdx : Fin n) refine ⟨by rw [hres]; rfl, nofun, fun i _ => ?_⟩ rw [hres, Tape.move_cells] show (if i + 1 = 0 then Γ.start else Γ.blank) = Γ.blank - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] obtain ⟨c', t, ht, hreach, hhalt, hinp', hres', hlhs', hlhsh, hrhs', hrhsh, hother', hout'⟩ := binaryEqTM_reachesIn_frame cIdx nIdx resIdx hd v.bits N.bits I W O hlhs hrhs hprefix @@ -303,19 +301,19 @@ theorem tallyTestTM_hoareTime (cIdx nIdx resIdx : Fin n) by_cases hj1 : j = cIdx · subst hj1 have hmem : j ∈ testTargets j nIdx resIdx := by simp [testTargets] - rw [rewoundBank, if_pos hmem, hc] + rw [rewoundBank, ite_eq_left hmem, hc] have hbn : (⟨1, (work j).cells⟩ : Tape).HasBinaryNat v := ⟨hz j, rfl, h1.1, h1.2⟩ simpa [natTape] using hbn.eq_init_move_right by_cases hj2 : j = nIdx · subst hj2 have hmem : j ∈ testTargets cIdx j resIdx := by simp [testTargets] - rw [rewoundBank, if_pos hmem, hnn] + rw [rewoundBank, ite_eq_left hmem, hnn] have hbn : (⟨1, (work j).cells⟩ : Tape).HasBinaryNat N := ⟨hz j, rfl, h2.1, h2.2⟩ simpa [natTape] using hbn.eq_init_move_right have hmem : j ∉ testTargets cIdx nIdx resIdx := by simp only [testTargets, List.mem_cons, List.not_mem_nil, or_false] exact fun h => h.elim hj1 (fun h => h.elim hj2 hj) - rw [rewoundBank, if_neg hmem] + rw [rewoundBank, ite_eq_right hmem] exact h5 j hj1 hj2 hj exact seqTM_hoareTime _ _ hstep1 htrans hstep2 @@ -332,7 +330,7 @@ theorem outSlot_write (s s' : Γw) : (outSlot s).write s'.toΓ = outSlot s' := b · rw [Tape.write_head] rfl · funext j - rw [Tape.write, if_neg (show ¬ ((outSlot s).head = 0) from by + rw [Tape.write, ite_eq_right (show ¬ ((outSlot s).head = 0) from by show ¬ ((1 : ℕ) = 0); omega)] show Function.update (outSlot s).cells 1 s'.toΓ j = _ by_cases hj : j = 1 @@ -357,8 +355,8 @@ theorem outSlot_blank_eq_blankTape : outSlot Γw.blank = TM.blankTape := by = ((Tape.init ([] : List Γ)).move Dir3.right).cells j rw [Tape.move_cells] by_cases hj : j = 0 - · rw [hj, if_pos rfl, Tape.init_cells_zero] - · rw [if_neg hj, show j = (j - 1) + 1 from by omega, Tape.init_nil_cells_succ] + · rw [hj, ite_eq_left rfl, Tape.init_cells_zero] + · rw [ite_eq_right hj, show j = (j - 1) + 1 from by omega, Tape.init_nil_cells_succ] split <;> rfl /-- Reading a cell back as a writable symbol turns it into `1` exactly when it was `1`. -/ @@ -414,11 +412,11 @@ theorem tallyTestTM_hoareTime_tallyPost (cIdx aIdx rIdx nIdx resIdx : Fin n) have hWc : W cIdx = natTape w := by rw [hW]; simp [tallyWork] have hWn : W nIdx = natTape N := by rw [hW] - simp only [tallyWork, if_neg hnc, if_neg hna, if_neg hnr] + simp only [tallyWork, ite_eq_right hnc, ite_eq_right hna, ite_eq_right hnr] exact hn have hWr : W resIdx = (Tape.init ([] : List Γ)).move Dir3.right := by rw [hW] - simp only [tallyWork, if_neg hsc, if_neg hsa, if_neg hsr] + simp only [tallyWork, ite_eq_right hsc, ite_eq_right hsa, ite_eq_right hsr] exact hr have hcases : ∀ j, W j = natTape w ∨ W j = natTape (tally P w) ∨ W j = natTape (tally (fun u => !P u) w) ∨ W j = rest j := by diff --git a/Complexitylib/Classes/Containments/Internal/PSPACESubsetEXP.lean b/Complexitylib/Classes/Containments/Internal/PSPACESubsetEXP.lean index 2bd5018d..34e3cbda 100644 --- a/Complexitylib/Classes/Containments/Internal/PSPACESubsetEXP.lean +++ b/Complexitylib/Classes/Containments/Internal/PSPACESubsetEXP.lean @@ -35,7 +35,7 @@ theorem Windowed.step {x : List Bool} {S : ℕ} {c c' : Cfg k tm.Q} (hw : Windowed x S c) (hstep : tm.step c = some c') (hspace : c.WithinDecisionSpace x.length S) : Windowed x S c' := by - rw [TM.step, if_neg (TM.state_ne_qhalt_of_step hstep)] at hstep + rw [TM.step, ite_eq_right (TM.state_ne_qhalt_of_step hstep)] at hstep injection hstep with hstep subst hstep refine ⟨?_, ?_, ?_⟩ diff --git a/Complexitylib/Classes/Containments/Internal/PVerdict.lean b/Complexitylib/Classes/Containments/Internal/PVerdict.lean index 089cd817..d82136c6 100644 --- a/Complexitylib/Classes/Containments/Internal/PVerdict.lean +++ b/Complexitylib/Classes/Containments/Internal/PVerdict.lean @@ -55,7 +55,7 @@ def stepOrStay (tm : TM k) (c : Cfg k tm.Q) : Cfg k tm.Q := (tm.step c).getD c theorem stepOrStay_of_halted (tm : TM k) {c : Cfg k tm.Q} (h : c.state = tm.qhalt) : tm.stepOrStay c = c := by - rw [stepOrStay, TM.step, if_pos h] + rw [stepOrStay, TM.step, ite_eq_left h] rfl theorem stepOrStay_of_step (tm : TM k) {c c' : Cfg k tm.Q} (h : tm.step c = some c') : @@ -335,7 +335,7 @@ theorem pVerdict_mem_FP (tm : TM k) (wp tp : Polynomial ℕ) (pair (polyRuler (2 * wp + 2) x) (Cobham.initFn tm (polyRuler (2 * wp + 2) x) x)))) ∈ FP := by have := mem_FP_comp hiter Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this exact acceptFlagFn_mem_FP _ hRf (wideRulerFn_mem_FP hRf (codeBlocks k)) hcode /-! ## The bridge -/ diff --git a/Complexitylib/Classes/Containments/Internal/SavitchAssemble.lean b/Complexitylib/Classes/Containments/Internal/SavitchAssemble.lean index c0ea5a8b..183b4986 100644 --- a/Complexitylib/Classes/Containments/Internal/SavitchAssemble.lean +++ b/Complexitylib/Classes/Containments/Internal/SavitchAssemble.lean @@ -103,7 +103,7 @@ theorem frameVal_savRoot (x : List Bool) rw [savRoot, hR, initRecord_eq tm _ x hxW] have hl : (savRoot tm qp lp x).lvl.length = lp.eval x.length := by rw [savRoot, polyRuler_length] - rw [hkind, if_pos rfl, hu, hl, hR] + rw [hkind, ite_eq_left rfl, hu, hl, hR] rw [accB_cfgCode tm hdec x (qp.eval x.length) (hcardq x.length) hW _ _ (NTM.reachesCfg_refl tm _), hmem] diff --git a/Complexitylib/Classes/Containments/Internal/SavitchBits.lean b/Complexitylib/Classes/Containments/Internal/SavitchBits.lean index e3efa2a0..ff0f32c5 100644 --- a/Complexitylib/Classes/Containments/Internal/SavitchBits.lean +++ b/Complexitylib/Classes/Containments/Internal/SavitchBits.lean @@ -286,12 +286,12 @@ theorem bumpStepP_mem_FP : bumpStepP ∈ FP := by (fun z => pairFst (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this have hsnd : ∀ {a : List Bool → List Bool}, a ∈ FP → (fun z => pairSnd (a z)) ∈ FP := by intro a ha have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this have hc := hfst hid have hw := hsnd hid have hrest := hsnd hw @@ -334,11 +334,12 @@ theorem bumpCodeFn_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => bumpCode (a z)) ∈ FP := by have h1 := mem_FP_comp (bumpRunFn_mem_FP ha) Cobham.sndBlock_mem_FP have h2 := mem_FP_comp h1 Cobham.fstBlock_mem_FP - simpa [Function.comp, bumpCode] using h2 - + simp [bumpCode] + exact h2 theorem bumpFlagFn_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => bumpFlag (a z)) ∈ FP := by have h := mem_FP_comp (bumpRunFn_mem_FP ha) Cobham.fstBlock_mem_FP - simpa [Function.comp, bumpFlag] using h + simp [bumpFlag] + exact h end Complexity diff --git a/Complexitylib/Classes/Containments/Internal/SavitchFrame.lean b/Complexitylib/Classes/Containments/Internal/SavitchFrame.lean index f2714c32..51e19621 100644 --- a/Complexitylib/Classes/Containments/Internal/SavitchFrame.lean +++ b/Complexitylib/Classes/Containments/Internal/SavitchFrame.lean @@ -210,12 +210,12 @@ theorem mkSt_ne_nil (d a R ret stk : List Bool) : mkSt d a R ret stk ≠ [] := b theorem fstBlockOf_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => pairFst (a z)) ∈ FP := by have := mem_FP_comp ha Cobham.fstBlock_mem_FP - simpa [Function.comp] using this + exact this theorem sndBlockOf_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => pairSnd (a z)) ∈ FP := by have := mem_FP_comp ha Cobham.sndBlock_mem_FP - simpa [Function.comp] using this + exact this theorem frKindFn_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => frKind (a z)) ∈ FP := fstBlockOf_mem_FP ha diff --git a/Complexitylib/Classes/Containments/Internal/SavitchStep.lean b/Complexitylib/Classes/Containments/Internal/SavitchStep.lean index 31721e1e..8d563958 100644 --- a/Complexitylib/Classes/Containments/Internal/SavitchStep.lean +++ b/Complexitylib/Classes/Containments/Internal/SavitchStep.lean @@ -291,7 +291,7 @@ theorem savG_mem_FP (tm : NTM k) (qp lp : Polynomial ℕ) : savG tm qp lp ∈ FP have hsnd := sndBlockOf_mem_FP hid have hstep : (fun z => savStep tm (pairFst z)) ∈ FP := by have := mem_FP_comp hfst (savStep_mem_FP tm) - simpa [Function.comp] using this + exact this exact Cobham.pairFn_mem_FP (Cobham.selectHeadFn_mem_FP (emptyFlagFn_mem_FP hfst) (savInitFn_mem_FP tm qp lp hsnd) hstep) hsnd diff --git a/Complexitylib/Classes/Containments/Internal/SpaceIterate.lean b/Complexitylib/Classes/Containments/Internal/SpaceIterate.lean index 94b0156a..938e7bb9 100644 --- a/Complexitylib/Classes/Containments/Internal/SpaceIterate.lean +++ b/Complexitylib/Classes/Containments/Internal/SpaceIterate.lean @@ -101,24 +101,24 @@ def slotOf (s : Γ) : Tape := parkedBlank.write s rfl @[simp] theorem slotOf_cells_one (s : Γ) : (slotOf s).cells 1 = s := by - rw [slotOf, Tape.write, if_neg (by show ¬ (1 : ℕ) = 0; omega)] + rw [slotOf, Tape.write, ite_eq_right (by show ¬ (1 : ℕ) = 0; omega)] show Function.update parkedBlank.cells parkedBlank.head s 1 = s rw [show parkedBlank.head = 1 from rfl] exact Function.update_self (β := fun _ => Γ) 1 s parkedBlank.cells theorem slotOf_cells_of_ne (s : Γ) {c : ℕ} (hc : c ≠ 1) : (slotOf s).cells c = parkedBlank.cells c := by - rw [slotOf, Tape.write, if_neg (by show ¬ (1 : ℕ) = 0; omega)] + rw [slotOf, Tape.write, ite_eq_right (by show ¬ (1 : ℕ) = 0; omega)] exact Function.update_of_ne (by simpa using hc) _ _ @[simp] theorem slotOf_write (s t : Γ) : (slotOf s).write t = slotOf t := by refine Tape.ext (by rw [Tape.write_head, slotOf_head, slotOf_head]) (funext fun c => ?_) by_cases hc : c = 1 · subst hc - rw [Tape.write, if_neg (by show ¬ (slotOf s).head = 0; rw [slotOf_head]; omega)] + rw [Tape.write, ite_eq_right (by show ¬ (slotOf s).head = 0; rw [slotOf_head]; omega)] show Function.update (slotOf s).cells (slotOf s).head t 1 = _ rw [slotOf_head, Function.update_self, slotOf_cells_one] - · rw [Tape.write, if_neg (by show ¬ (slotOf s).head = 0; rw [slotOf_head]; omega)] + · rw [Tape.write, ite_eq_right (by show ¬ (slotOf s).head = 0; rw [slotOf_head]; omega)] show Function.update (slotOf s).cells (slotOf s).head t c = _ rw [slotOf_head, Function.update_of_ne (by simpa using hc), slotOf_cells_of_ne s hc, slotOf_cells_of_ne t hc] @@ -191,7 +191,7 @@ noncomputable def ctrValue (t : Tape) : ℕ := @[simp] theorem ctrValue_natTape (v : ℕ) : ctrValue (natTape v) = v := by classical have hex : ∃ w, natTape v = natTape w := ⟨v, rfl⟩ - rw [ctrValue, dif_pos hex] + rw [ctrValue, dite_eq_left hex] generalize hgen : hex.choose = w have hc : natTape v = natTape w := hgen ▸ hex.choose_spec refine hasBinaryNat_value_unique (t := natTape v) ?_ (Tape.init_move_right_hasBinaryNat v) @@ -219,14 +219,14 @@ noncomputable def iterBank (M : TM k) (y : List Bool) (inp₀ junkT : Tape) @[simp] theorem iterBank_app (M : TM k) (y : List Bool) (inp₀ junkT : Tape) (H c : ℕ) (j : Fin (k + 2)) : iterBank M y inp₀ junkT H c (appIdx j) = TM.applyPre M y inp₀ j := by - rw [iterBank, dif_pos (appIdx_middle j)] + rw [iterBank, dite_eq_left (appIdx_middle j)] congr 1 exact placeWorkCoord_placeWorkIdx 3 0 j theorem iterBank_book (M : TM k) (y : List Bool) (inp₀ junkT : Tape) (H c : ℕ) (i : Fin (3 + (k + 2) + 0)) (hi : ¬ placeWorkInMiddle 3 (k + 2) i) : iterBank M y inp₀ junkT H c i = bookTapes (natTape c) junkT H i := by - rw [iterBank, dif_neg hi] + rw [iterBank, dite_eq_right hi] @[simp] theorem iterBank_rf (M : TM k) (y : List Bool) (inp₀ junkT : Tape) (H c : ℕ) : iterBank M y inp₀ junkT H c rfIdx = natTape c := by @@ -301,8 +301,8 @@ theorem iterBank_succ (M : TM k) (y : List Bool) (inp₀ junkT : Tape) (H c : · rw [hi, Function.update_self, iterBank_rf] · rw [Function.update_of_ne hi, iterBank, iterBank] by_cases hm : placeWorkInMiddle 3 (k + 2) i - · rw [dif_pos hm, dif_pos hm] - · rw [dif_neg hm, dif_neg hm] + · rw [dite_eq_left hm, dite_eq_left hm] + · rw [dite_eq_right hm, dite_eq_right hm] rcases Complexity.layout_cases i with h | h | h | ⟨j, h⟩ · exact absurd h hi · rw [h, bookTapes_wf, bookTapes_wf] @@ -541,7 +541,7 @@ theorem test_pass (M : TM k) (Y : ℕ → List Bool) (inp₀ junkT : Tape) (start + (j + 1))).strengthen_post ?_ rintro inp work out ⟨hi, hw, ho⟩ refine ⟨hi, hw, ?_⟩ - rw [ho, slotSym, if_neg (by omega)] + rw [ho, slotSym, ite_eq_right (by omega)] /-- **One pass of the loop.** The body applies the function once, and the test finds the state not yet done, so the loop comes back to its start state one iteration on. -/ @@ -573,7 +573,7 @@ theorem loop_pass (M : TM k) {G : List Bool → List Bool} {T : ℕ → ℕ} refine ⟨loopState_parked M Y inp₀ junkT hinpP hjunkP H start (j + 1) inp' work' out' hE', ?_⟩ obtain ⟨-, -, ho⟩ := hE' - rw [ho, slotOf_cells_one, slotSym, if_neg (by omega)] + rw [ho, slotOf_cells_one, slotSym, ite_eq_right (by omega)] intro hcon have hhd := (headSym_eq_one_iff (Y (j + 1))).mp hcon rw [hcont (j + 1) (by omega) (by omega)] at hhd @@ -613,7 +613,7 @@ theorem loop_final (M : TM k) {G : List Bool → List Bool} {T : ℕ → ℕ} refine ⟨loopState_parked M Y inp₀ junkT hinpP hjunkP H start (N - 1 + 1) inp' work' out' hE', ?_⟩ obtain ⟨-, -, ho⟩ := hE' - rw [ho, slotOf_cells_one, slotSym, if_neg (by omega), hlast] + rw [ho, slotOf_cells_one, slotSym, ite_eq_right (by omega), hlast] exact (headSym_eq_one_iff (Y N)).mpr hdone /-- **The loop's contract.** The loop runs until the state says it is done: `N` @@ -898,7 +898,7 @@ theorem spaceIterTM_hoareTime (M : TM k) {G : List Bool → List Bool} {T : ℕ (fun i hi => hHy i (by omega)) (fun i hi => hHT i (by omega)) hcont hdone b (fun j hj => hb j (by omega)) inp work out ⟨rfl, by rw [hw, show start + 0 = start from rfl], - by rw [ho, slotSym, if_pos rfl, slotOf_blank]⟩ + by rw [ho, slotSym, ite_eq_left rfl, slotOf_blank]⟩ exact ⟨c', t, ht, hreach, hhalt, by rw [hi']; exact hP, by rw [hi']; exact hSI, by rw [hw', hi'], ho'⟩ -- the epilogue, likewise @@ -1023,7 +1023,7 @@ theorem spaceIterTM_keepsWindow (M : TM k) {G : List Bool → List Bool} {T : (fun i hi => hHy i (by omega)) (fun i hi => hHT i (by omega)) hcont hdone b (fun j hj => hb j (by omega)) inp work out ⟨rfl, by rw [hw, show st + 0 = st from rfl], - by rw [ho, slotSym, if_pos rfl, slotOf_blank]⟩ + by rw [ho, slotSym, ite_eq_left rfl, slotOf_blank]⟩ exact ⟨c', t, ht, hreach, hhalt, by rw [hi']; exact hP, by rw [hi']; exact hSI, by rw [hi']; exact hhead, by rw [hw', hi'], ho'⟩ -- the prologue and the loop, as one contract @@ -1063,7 +1063,7 @@ theorem spaceIterTM_keepsWindow (M : TM k) {G : List Bool → List Bool} {T : (fun j hj => hb j (by omega)) x.length (proBound k p H x.length + 1) (by omega) (by omega) hjunkh).mono_space (by omega) c ⟨hst, rfl, ?_, ?_⟩ c' hreach · rw [hw, show st + 0 = st from rfl] - · rw [ho, slotSym, if_pos rfl, slotOf_blank] + · rw [ho, slotSym, ite_eq_left rfl, slotOf_blank] have w3 : (epilogueTM M).KeepsWindowOn (fun c => c.state = (epilogueTM M).qstart ∧ Parked c.input ∧ Tape.StartInvariant c.input ∧ c.input.head ≤ proBound k p H x.length ∧ diff --git a/Complexitylib/Classes/Containments/Internal/SuccMachine.lean b/Complexitylib/Classes/Containments/Internal/SuccMachine.lean index cc0253c3..e2099b1c 100644 --- a/Complexitylib/Classes/Containments/Internal/SuccMachine.lean +++ b/Complexitylib/Classes/Containments/Internal/SuccMachine.lean @@ -259,23 +259,23 @@ noncomputable def codeBlock {kk : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) @[simp] theorem codeBlock_st {kk : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) (a : Code tm.Q kk x.length S) : codeBlock tm x S a 0 = (qCodec tm.Q).enc a.1 := by - rw [codeBlock, dif_pos rfl] + rw [codeBlock, dite_eq_left rfl] @[simp] theorem codeBlock_hd {kk : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) (a : Code tm.Q kk x.length S) : codeBlock tm x S a 1 = (finCodec (x.length + S + 2)).enc a.2.1 := by - rw [codeBlock, dif_neg (by omega), dif_pos rfl] + rw [codeBlock, dite_eq_right (by omega), dite_eq_left rfl] @[simp] theorem codeBlock_wk {kk : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) (a : Code tm.Q kk x.length S) (i : Fin kk) : codeBlock tm x S a (i.val + 2) = (tapeCodec (S + 1)).enc (a.2.2.1 i) := by - rw [codeBlock, dif_neg (by omega), dif_neg (by omega), dif_pos (by omega), + rw [codeBlock, dite_eq_right (by omega), dite_eq_right (by omega), dite_eq_left (by omega), show (⟨i.val + 2 - 2, by omega⟩ : Fin kk) = i from Fin.ext (by simp)] @[simp] theorem codeBlock_ot {kk : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) (a : Code tm.Q kk x.length S) : codeBlock tm x S a (kk + 2) = (tapeCodec (S + 2)).enc a.2.2.2 := by - rw [codeBlock, dif_neg (by omega), dif_neg (by omega), dif_neg (by omega)] + rw [codeBlock, dite_eq_right (by omega), dite_eq_right (by omega), dite_eq_right (by omega)] theorem codeBlock_length {kk : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) (a : Code tm.Q kk x.length S) (p : ℕ) : @@ -351,15 +351,16 @@ theorem holdsCode_of_blocks {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ HoldsCode tm x S cols 0 (codeRegsOf j) a := by refine ⟨?_, ?_, fun i => ?_, ?_⟩ · have := h 0 (by omega) - rwa [codeBlock, dif_pos rfl] at this + rwa [codeBlock, dite_eq_left rfl] at this · have := h 1 (by omega) - rwa [codeBlock, dif_neg (by omega), dif_pos rfl] at this + rwa [codeBlock, dite_eq_right (by omega), dite_eq_left rfl] at this · have hb := h (i.val + 2) (by omega) - rw [codeBlock, dif_neg (by omega), dif_neg (by omega), dif_pos (by omega), + rw [codeBlock, dite_eq_right (by omega), dite_eq_right (by omega), dite_eq_left (by omega), show (⟨i.val + 2 - 2, by omega⟩ : Fin kk) = i from Fin.ext (by simp)] at hb exact HoldsWindow.of_bits hb · have hb := h (kk + 2) (by omega) - rw [codeBlock, dif_neg (by omega), dif_neg (by omega), dif_neg (by omega)] at hb + rw [codeBlock, dite_eq_right (by omega), dite_eq_right (by omega), + dite_eq_right (by omega)] at hb exact HoldsWindow.of_bits hb /-- **A guess stage can lay down any code.** Given a guess tape whose bits, block by block, are @@ -479,7 +480,7 @@ theorem markOf_end {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) set pw := (succParamsCodec tm.Q kk).width with hpw have hblk : codeBlockScan tm x S a p = List.replicate pw false ++ (codeBlock tm x S a p ++ [false]) := by - rw [codeBlockScan, if_neg hp] + rw [codeBlockScan, ite_eq_right hp] have hlast : (codeBlockScan tm x S a p)[pw + 3 * m]? = some false := by rw [hblk, List.getElem?_append_right (by rw [List.length_replicate]; omega), List.length_replicate, show pw + 3 * m - pw = 3 * m by omega, @@ -507,22 +508,23 @@ theorem holdsCodeScan_of_blocks {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : HoldsBits cols (succParamsCodec tm.Q kk).width (j p) (codeBlock tm x S a p) := by intro p hp hp0 have hb := h p hp - rw [codeBlockScan, if_neg hp0] at hb + rw [codeBlockScan, ite_eq_right hp0] at hb have hdrop := hb.drop_prefix rw [List.length_replicate] at hdrop exact hdrop.of_isPrefix ⟨[false], rfl⟩ refine ⟨?_, ?_, fun i => ?_, ?_⟩ · have hb := h 0 (by omega) - rw [codeBlockScan, if_pos rfl, codeBlock, dif_pos rfl] at hb + rw [codeBlockScan, ite_eq_left rfl, codeBlock, dite_eq_left rfl] at hb exact hb · have hb := hpad 1 (by omega) (by omega) - rwa [codeBlock, dif_neg (by omega), dif_pos rfl] at hb + rwa [codeBlock, dite_eq_right (by omega), dite_eq_left rfl] at hb · have hb := hpad (i.val + 2) (by omega) (by omega) - rw [codeBlock, dif_neg (by omega), dif_neg (by omega), dif_pos (by omega), + rw [codeBlock, dite_eq_right (by omega), dite_eq_right (by omega), dite_eq_left (by omega), show (⟨i.val + 2 - 2, by omega⟩ : Fin kk) = i from Fin.ext (by simp)] at hb exact HoldsWindow.of_bits hb · have hb := hpad (kk + 2) (by omega) (by omega) - rw [codeBlock, dif_neg (by omega), dif_neg (by omega), dif_neg (by omega)] at hb + rw [codeBlock, dite_eq_right (by omega), dite_eq_right (by omega), + dite_eq_right (by omega)] at hb exact HoldsWindow.of_bits hb /-! ## What each scan says about the code the registers hold -/ @@ -905,7 +907,7 @@ theorem bitsOfLenLE_all_false_iff (ℓ v : ℕ) (hv : v < 2 ^ ℓ) : rfl have : (bitsOfLenLE ℓ 0)[q]? = some false := by rw [hrep ℓ, List.getElem?_replicate] - rw [if_pos hq] + rw [ite_eq_left hq] exact Option.some_injective _ (by rw [← List.getElem?_eq_getElem (by rw [bitsOfLenLE_length]; exact hq), this]) @@ -1048,10 +1050,11 @@ theorem dirRead_snd (tm : NTM kk) (cols : ℕ → Fin 2 → Γ) (g₀ : Γ) · show (dirRead tm ((⟨0, Nat.zero_lt_succ _⟩, x₀), g₀) (cols (0 + 1))).2 = cols 1 1 rw [dirRead] show (if (0 : ℕ) = 0 then cols (0 + 1) 1 else g₀) = cols 1 1 - rw [if_pos rfl] + rw [ite_eq_left rfl] · show (Scanner.bitsStep 1 (succParamsCodec tm.Q kk).width (fun _ => 0) (⟨0, Nat.zero_lt_succ _⟩, x₀) (cols (0 + 1))).1.val ≠ 0 - rw [Scanner.bitsStep, dif_pos (show (0 : ℕ) < (succParamsCodec tm.Q kk).width by omega)] + rw [Scanner.bitsStep, + dite_eq_left (show (0 : ℕ) < (succParamsCodec tm.Q kk).width by omega)] exact Nat.succ_ne_zero _ · obtain ⟨ihcap, ihcnt⟩ := ih hp constructor @@ -1060,7 +1063,7 @@ theorem dirRead_snd (tm : NTM kk) (cols : ℕ → Fin 2 → Γ) (g₀ : Γ) rw [dirRead] show (if (Scanner.auxRun ((⟨0, Nat.zero_lt_succ _⟩, x₀), g₀) (dirRead tm) cols p).1.1.val = 0 then _ else _) = cols 1 1 - rw [if_neg ihcnt] + rw [ite_eq_right ihcnt] exact ihcap · show (Scanner.bitsStep 1 (succParamsCodec tm.Q kk).width (fun _ => 0) (Scanner.auxRun ((⟨0, Nat.zero_lt_succ _⟩, x₀), g₀) (dirRead tm) cols p).1 @@ -1436,8 +1439,8 @@ theorem eqScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ) rw [codeBlockScan, codeBlockScan] at h by_cases h0 : p = 0 · subst h0 - rwa [if_pos rfl, if_pos rfl] at h - · rw [if_neg h0, if_neg h0] at h + rwa [ite_eq_left rfl, ite_eq_left rfl] at h + · rw [ite_eq_right h0, ite_eq_right h0] at h exact List.append_cancel_right (List.append_cancel_left h) have hst : a.1 = b.1 := by have h := hfield 0 (by omega) @@ -1490,8 +1493,8 @@ theorem inSymScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : · rw [Scanner.all_emit_run] at h have h0 := h ⟨0, by omega⟩ have h1 := h ⟨1, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0)] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0))] at h1 + rw [ite_eq_left (rfl : (0 : ℕ) = 0)] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0))] at h1 have hzero : a.2.1.val = 0 := (headZeroScanner_decides tm x.length S hd cols (walkScanLen tm x.length S) (headField_le_walkScanLen tm x.length S) a.2.1 hhd).mp h0 @@ -1504,8 +1507,8 @@ theorem inSymScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : · rw [Scanner.all_emit_run] at h have h0 := h ⟨0, by omega⟩ have h1 := h ⟨1, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0)] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0))] at h1 + rw [ite_eq_left (rfl : (0 : ℕ) = 0)] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0))] at h1 have hne : a.2.1.val ≠ 0 := (headNonZeroScanner_decides tm x.length S hd cols (walkScanLen tm x.length S) (headField_le_walkScanLen tm x.length S) a.2.1 hhd).mp h0 @@ -1537,10 +1540,10 @@ theorem inSymScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : rw [Scanner.all_emit_run] intro p by_cases hp : p.val = 0 - · rw [if_pos hp] + · rw [ite_eq_left hp] exact (headZeroScanner_decides tm x.length S hd cols (walkScanLen tm x.length S) (headField_le_walkScanLen tm x.length S) a.2.1 hhd).mpr hz - · rw [if_neg hp] + · rw [ite_eq_right hp] refine (Scanner.isConst_upTo_run jj par Γ.one cols 2 (walkScanLen tm x.length S) (two_le_walkScanLen tm x.length S)).mpr ?_ refine (parStart_iff tm cols par P hpar).mpr ?_ @@ -1550,10 +1553,10 @@ theorem inSymScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : rw [Scanner.all_emit_run] intro p by_cases hp : p.val = 0 - · rw [if_pos hp] + · rw [ite_eq_left hp] exact (headNonZeroScanner_decides tm x.length S hd cols (walkScanLen tm x.length S) (headField_le_walkScanLen tm x.length S) a.2.1 hhd).mpr hz - · rw [if_neg hp] + · rw [ite_eq_right hp] exact (Scanner.isConst_cell jj res Γ.one cols (walkScanLen tm x.length S) (one_le_walkScanLen tm x.length S)).mpr (hres hz) @@ -1642,26 +1645,26 @@ theorem succScanner_verdicts {kk jj : ℕ} (tm : NTM kk) (nn S : ℕ) (par : Fin exact h refine ⟨fun i => ?_, ?_, ?_, ?_, ?_⟩ · have h := hv ⟨i.val, by omega⟩ - rw [dif_pos i.isLt, show (⟨i.val, i.isLt⟩ : Fin kk) = i from Fin.ext rfl] at h + rw [dite_eq_left i.isLt, show (⟨i.val, i.isLt⟩ : Fin kk) = i from Fin.ext rfl] at h exact hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) h · have h := hv ⟨kk, by omega⟩ - rw [dif_neg (by exact Nat.lt_irrefl kk), if_pos (rfl : kk = kk)] at h + rw [dite_eq_right (by exact Nat.lt_irrefl kk), ite_eq_left (rfl : kk = kk)] at h exact hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) h · have h := hv ⟨kk + 1, by omega⟩ - rw [dif_neg (by exact Nat.not_lt.mpr (Nat.le_succ kk)), - if_neg (by exact Nat.succ_ne_self kk), if_pos (rfl : kk + 1 = kk + 1)] at h + rw [dite_eq_right (by exact Nat.not_lt.mpr (Nat.le_succ kk)), + ite_eq_right (by exact Nat.succ_ne_self kk), ite_eq_left (rfl : kk + 1 = kk + 1)] at h exact hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) h · have h := hv ⟨kk + 2, by omega⟩ - rw [dif_neg (by exact Nat.not_lt.mpr (Nat.le_add_right kk 2)), - if_neg (by exact (by omega : kk + 2 ≠ kk)), - if_neg (by exact (by omega : kk + 2 ≠ kk + 1)), - if_pos (rfl : kk + 2 = kk + 2)] at h + rw [dite_eq_right (by exact Nat.not_lt.mpr (Nat.le_add_right kk 2)), + ite_eq_right (by exact (by omega : kk + 2 ≠ kk)), + ite_eq_right (by exact (by omega : kk + 2 ≠ kk + 1)), + ite_eq_left (rfl : kk + 2 = kk + 2)] at h exact hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) h · have h := hv ⟨kk + 3, by omega⟩ - rw [dif_neg (by exact Nat.not_lt.mpr (Nat.le_add_right kk 3)), - if_neg (by exact (by omega : kk + 3 ≠ kk)), - if_neg (by exact (by omega : kk + 3 ≠ kk + 1)), - if_neg (by exact (by omega : kk + 3 ≠ kk + 2))] at h + rw [dite_eq_right (by exact Nat.not_lt.mpr (Nat.le_add_right kk 3)), + ite_eq_right (by exact (by omega : kk + 3 ≠ kk)), + ite_eq_right (by exact (by omega : kk + 3 ≠ kk + 1)), + ite_eq_right (by exact (by omega : kk + 3 ≠ kk + 2))] at h exact hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) h /-- **The successor scan accepts a genuine successor.** The converse of @@ -1725,24 +1728,24 @@ theorem succScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ Scanner.comap_emit, Scanner.comap_run] exact h by_cases hpk : p.val < kk - · rw [dif_pos hpk] + · rw [dite_eq_left hpk] refine hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) ?_ refine (windowScanner_decides tm ⟨p.val, hpk⟩ _ S (a.2.2.1 ⟨p.val, hpk⟩).1 (b.2.2.1 ⟨p.val, hpk⟩).1 (a.2.2.1 ⟨p.val, hpk⟩).2 (b.2.2.1 ⟨p.val, hpk⟩).2 (hawk ⟨p.val, hpk⟩) (hbwk ⟨p.val, hpk⟩) (hendW ⟨p.val, hpk⟩)).mpr ?_ rw [hPw ⟨p.val, hpk⟩] exact ⟨hwsym _, (hwork _).2, (hwork _).1⟩ - · rw [dif_neg hpk] + · rw [dite_eq_right hpk] by_cases hpo : p.val = kk - · rw [if_pos hpo] + · rw [ite_eq_left hpo] refine hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) ?_ refine (outputScanner_decides tm _ S a.2.2.2.1 b.2.2.2.1 a.2.2.2.2 b.2.2.2.2 haot hbot hendO).mpr ?_ rw [hPo] exact ⟨hosym, hout.2, hout.1⟩ - · rw [if_neg hpo] + · rw [ite_eq_right hpo] by_cases hph : p.val = kk + 1 - · rw [if_pos hph] + · rw [ite_eq_left hph] refine hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) ?_ refine (headScanner_decides tm _ (bitWidth (x.length + S + 2)) a.2.1.val b.2.1.val (lt_of_lt_of_le a.2.1.isLt (le_two_pow_bitWidth _)) @@ -1750,17 +1753,17 @@ theorem succScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ hahd.shift hbhd.shift (by rw [hPh]; exact hleft)).mpr ?_ rw [hPh] exact hhead - · rw [if_neg hph] + · rw [ite_eq_right hph] by_cases hps : p.val = kk + 2 - · rw [if_pos hps] + · rw [ite_eq_left hps] refine hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) ?_ refine (stateScanner_decides tm false _ a.1 hast).mpr ?_ - rw [hPsa, if_neg (by simp)] + rw [hPsa, ite_eq_right (by simp)] exact hq - · rw [if_neg hps] + · rw [ite_eq_right hps] refine hcomp _ _ _ (fun _ _ => rfl) (by rw [walkScanLen]; omega) ?_ refine (stateScanner_decides tm true _ b.1 hbst).mpr ?_ - rw [hPsb, if_pos rfl] + rw [hPsb, ite_eq_left rfl] exact hstate /-- **The successor scan decides a successor step.** Given that the parameter register holds a @@ -1813,11 +1816,11 @@ theorem succScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : ℕ have hq : a.1 = P.q := by have h := (stateScanner_decides tm false (fun q c => cols q (stateCols par Ra c)) a.1 hast).mp vsta - rwa [hPsa, if_neg (by simp)] at h + rwa [hPsa, ite_eq_right (by simp)] at h have hstate : b.1 = succState tm P := by have h := (stateScanner_decides tm true (fun q c => cols q (stateCols par Rb c)) b.1 hbst).mp vstb - rwa [hPsb, if_pos rfl] at h + rwa [hPsb, ite_eq_left rfl] at h have hwork : ∀ i, ((a.2.2.1 i).2 (a.2.2.1 i).1 = P.wSym i) ∧ (∀ p, (b.2.2.1 i).2 p = if p = (a.2.2.1 i).1 ∧ 0 < p.val then succWrite tm P i else (a.2.2.1 i).2 p) ∧ @@ -1887,11 +1890,12 @@ theorem counterStepScanner_decides {jj : ℕ} (cntOld cntNew : Fin (jj + 1)) (wc rw [counterStepScanner] at hverdict cases advance with | true => - rw [if_pos rfl, Scanner.upTo_emit_run _ (rightOnly_plusOne jj cntOld cntNew) wc len hw] + rw [ite_eq_left rfl, Scanner.upTo_emit_run _ (rightOnly_plusOne jj cntOld cntNew) wc len hw] at hverdict exact (plusOne_of_holds cols cntOld cntNew wc u v hu hv hold hnew).mp hverdict | false => - rw [if_neg (by simp), Scanner.upTo_emit_run _ (Scanner.rightOnly_eq jj cntOld cntNew) wc len + rw [ite_eq_right (by simp), + Scanner.upTo_emit_run _ (Scanner.rightOnly_eq jj cntOld cntNew) wc len hw] at hverdict show u = v have hbits := (eq_run_of_holds cols cntOld cntNew (bitsOfLenLE wc u) (bitsOfLenLE wc v) @@ -1987,17 +1991,17 @@ theorem dirCheckScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : have h0 := h ⟨0, by omega⟩ have h1 := h ⟨1, by omega⟩ have h2 := h ⟨2, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0), Scanner.or_emit_run] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0)), if_pos (rfl : (1 : ℕ) = 1)] at h1 - rw [if_neg (by exact (by omega : (2 : ℕ) ≠ 0)), - if_neg (by exact (by omega : (2 : ℕ) ≠ 1))] at h2 + rw [ite_eq_left (rfl : (0 : ℕ) = 0), Scanner.or_emit_run] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0)), ite_eq_left (rfl : (1 : ℕ) = 1)] at h1 + rw [ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 0)), + ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 1))] at h2 have hstay : adjustedDir (succTrans tm P).2.2.2.1 a.2.1.val = Dir3.stay := by rw [adjustedDir] rcases h0 with hz | hz - · rw [if_pos (hzO.mp hz)] + · rw [ite_eq_left (hzO.mp hz)] · by_cases ha : a.2.1.val = 0 - · rw [if_pos ha] - · rw [if_neg ha, if_pos (by rw [← hmove]; exact hzN.mp hz)] + · rw [ite_eq_left ha] + · rw [ite_eq_right ha, ite_eq_left (by rw [← hmove]; exact hzN.mp hz)] rw [hstay] exact ⟨(Scanner.isConst_cell jj mv (dc.encMove Dir3.stay) cols (walkScanLen tm x.length S) hlen2).mp h1, @@ -2008,21 +2012,21 @@ theorem dirCheckScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : have h1 := h ⟨1, by omega⟩ have h2 := h ⟨2, by omega⟩ have h3 := h ⟨3, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0)] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0)), if_pos (rfl : (1 : ℕ) = 1)] at h1 - rw [if_neg (by exact (by omega : (2 : ℕ) ≠ 0)), - if_neg (by exact (by omega : (2 : ℕ) ≠ 1)), if_pos (rfl : (2 : ℕ) = 2), + rw [ite_eq_left (rfl : (0 : ℕ) = 0)] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0)), ite_eq_left (rfl : (1 : ℕ) = 1)] at h1 + rw [ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 0)), + ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 1)), ite_eq_left (rfl : (2 : ℕ) = 2), Scanner.upTo_emit_run _ (Scanner.rightOnly_comap (fun _ _ => rfl) (dirCols par mv)) _ _ (succParamsCodec_width_le_walkScanLen tm x.length S), Scanner.comap_emit, Scanner.comap_run] at h2 - rw [if_neg (by exact (by omega : (3 : ℕ) ≠ 0)), - if_neg (by exact (by omega : (3 : ℕ) ≠ 1)), - if_neg (by exact (by omega : (3 : ℕ) ≠ 2)), + rw [ite_eq_right (by exact (by omega : (3 : ℕ) ≠ 0)), + ite_eq_right (by exact (by omega : (3 : ℕ) ≠ 1)), + ite_eq_right (by exact (by omega : (3 : ℕ) ≠ 2)), Scanner.upTo_emit_run _ (Scanner.rightOnly_comap (fun _ _ => rfl) (dirCols par dr)) _ _ (succParamsCodec_width_le_walkScanLen tm x.length S), Scanner.comap_emit, Scanner.comap_run] at h3 have hdir : adjustedDir (succTrans tm P).2.2.2.1 a.2.1.val = (succTrans tm P).2.2.2.1 := by - rw [adjustedDir, if_neg (hnO.mp h0), if_neg (by rw [← hmove]; exact hnN.mp h1)] + rw [adjustedDir, ite_eq_right (hnO.mp h0), ite_eq_right (by rw [← hmove]; exact hnN.mp h1)] rw [hdir] exact ⟨(dirScanner_decides tm dc.encMove (fun q c => cols q (dirCols par mv c)) P hpar).mp h2, (dirScanner_decides tm dc.enc (fun q c => cols q (dirCols par dr c)) P hpar).mp h3⟩ @@ -2056,43 +2060,43 @@ theorem dirCheckScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : · have hstay : adjustedDir (succTrans tm P).2.2.2.1 a.2.1.val = Dir3.stay := by rw [adjustedDir] rcases hz with hz | hz - · rw [if_pos hz] + · rw [ite_eq_left hz] · by_cases ha : a.2.1.val = 0 - · rw [if_pos ha] - · rw [if_neg ha, if_pos (by rw [← hmove]; exact hz)] + · rw [ite_eq_left ha] + · rw [ite_eq_right ha, ite_eq_left (by rw [← hmove]; exact hz)] refine Or.inl ?_ rw [Scanner.all_emit_run] intro p by_cases hp0 : p.val = 0 - · rw [if_pos hp0, Scanner.or_emit_run] + · rw [ite_eq_left hp0, Scanner.or_emit_run] rcases hz with hz | hz · exact Or.inl (hzO.mpr hz) · exact Or.inr (hzN.mpr hz) - · rw [if_neg hp0] + · rw [ite_eq_right hp0] by_cases hp1 : p.val = 1 - · rw [if_pos hp1] + · rw [ite_eq_left hp1] exact (Scanner.isConst_cell jj mv (dc.encMove Dir3.stay) cols (walkScanLen tm x.length S) hlen1).mpr (by rw [hmv, hstay]) - · rw [if_neg hp1] + · rw [ite_eq_right hp1] exact (Scanner.isConst_cell jj dr (dc.enc Dir3.stay) cols (walkScanLen tm x.length S) hlen1).mpr (by rw [hdr, hstay]) · have hzA : a.2.1.val ≠ 0 := fun hc => hz (Or.inl hc) have hzB : b.2.1.val ≠ 0 := fun hc => hz (Or.inr hc) have hdir : adjustedDir (succTrans tm P).2.2.2.1 a.2.1.val = (succTrans tm P).2.2.2.1 := by - rw [adjustedDir, if_neg hzA, if_neg (by rw [← hmove]; exact hzB)] + rw [adjustedDir, ite_eq_right hzA, ite_eq_right (by rw [← hmove]; exact hzB)] refine Or.inr ?_ rw [Scanner.all_emit_run] intro p by_cases hp0 : p.val = 0 - · rw [if_pos hp0] + · rw [ite_eq_left hp0] exact hnO.mpr hzA - · rw [if_neg hp0] + · rw [ite_eq_right hp0] by_cases hp1 : p.val = 1 - · rw [if_pos hp1] + · rw [ite_eq_left hp1] exact hnN.mpr hzB - · rw [if_neg hp1] + · rw [ite_eq_right hp1] by_cases hp2 : p.val = 2 - · rw [if_pos hp2, Scanner.upTo_emit_run _ + · rw [ite_eq_left hp2, Scanner.upTo_emit_run _ (Scanner.rightOnly_comap (fun _ _ => rfl) (dirCols par mv)) _ _ (succParamsCodec_width_le_walkScanLen tm x.length S), Scanner.comap_emit, Scanner.comap_run] @@ -2100,7 +2104,7 @@ theorem dirCheckScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : hpar).mpr ?_ show cols 1 mv = _ rw [hmv, hdir] - · rw [if_neg hp2, Scanner.upTo_emit_run _ + · rw [ite_eq_right hp2, Scanner.upTo_emit_run _ (Scanner.rightOnly_comap (fun _ _ => rfl) (dirCols par dr)) _ _ (succParamsCodec_width_le_walkScanLen tm x.length S), Scanner.comap_emit, Scanner.comap_run] @@ -2136,11 +2140,12 @@ theorem counterStepScanner_accepts {jj : ℕ} (cntOld cntNew : Fin (jj + 1)) (wc rw [counterStepScanner] cases advance with | true => - rw [if_pos rfl, Scanner.upTo_emit_run _ (rightOnly_plusOne jj cntOld cntNew) wc len hw] + rw [ite_eq_left rfl, Scanner.upTo_emit_run _ (rightOnly_plusOne jj cntOld cntNew) wc len hw] exact (plusOne_of_holds cols cntOld cntNew wc u v hu hv hold hnew).mpr (by simpa using hmove) | false => - rw [if_neg (by simp), Scanner.upTo_emit_run _ (Scanner.rightOnly_eq jj cntOld cntNew) wc len + rw [ite_eq_right (by simp), + Scanner.upTo_emit_run _ (Scanner.rightOnly_eq jj cntOld cntNew) wc len hw] have huv : u = v := by simpa using hmove subst huv @@ -2195,10 +2200,10 @@ theorem walkCodeScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : have h0 := h ⟨0, by omega⟩ have h1 := h ⟨1, by omega⟩ have h2 := h ⟨2, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0)] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0)), if_pos (rfl : (1 : ℕ) = 1)] at h1 - rw [if_neg (by exact (by omega : (2 : ℕ) ≠ 0)), - if_neg (by exact (by omega : (2 : ℕ) ≠ 1))] at h2 + rw [ite_eq_left (rfl : (0 : ℕ) = 0)] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0)), ite_eq_left (rfl : (1 : ℕ) = 1)] at h1 + rw [ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 0)), + ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 1))] at h2 exact Or.inl ⟨(eqScanner_decides tm x S cols j j' a b ha hb h0).symm, (Scanner.isConst_cell jj mv (dc.encMove Dir3.stay) cols (walkScanLen tm x.length S) (one_le_walkScanLen tm x.length S)).mp h1, @@ -2208,10 +2213,10 @@ theorem walkCodeScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : have h0 := h ⟨0, by omega⟩ have h1 := h ⟨1, by omega⟩ have h2 := h ⟨2, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0)] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0)), if_pos (rfl : (1 : ℕ) = 1)] at h1 - rw [if_neg (by exact (by omega : (2 : ℕ) ≠ 0)), - if_neg (by exact (by omega : (2 : ℕ) ≠ 1))] at h2 + rw [ite_eq_left (rfl : (0 : ℕ) = 0)] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0)), ite_eq_left (rfl : (1 : ℕ) = 1)] at h1 + rw [ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 0)), + ite_eq_right (by exact (by omega : (2 : ℕ) ≠ 1))] at h2 have hin : P.inSym = inSymOf tm x S a := inSymScanner_decides tm x S cols par (codeRegsOf j).hd res P a g hpar (holdsCodeScan_of_blocks tm x S cols j a ha).2.1 hres hg h2 @@ -2238,14 +2243,14 @@ theorem walkCodeScanner_accepts_stay {kk jj : ℕ} (tm : NTM kk) (x : List Bool) rw [Scanner.all_emit_run] intro p by_cases hp : p.val = 0 - · rw [if_pos hp] + · rw [ite_eq_left hp] exact eqScanner_accepts tm x S cols j j' a ha hb - · rw [if_neg hp] + · rw [ite_eq_right hp] by_cases hp1 : p.val = 1 - · rw [if_pos hp1] + · rw [ite_eq_left hp1] exact (Scanner.isConst_cell jj mv (dc.encMove Dir3.stay) cols (walkScanLen tm x.length S) (one_le_walkScanLen tm x.length S)).mpr hmv - · rw [if_neg hp1] + · rw [ite_eq_right hp1] exact (Scanner.isConst_cell jj dr (dc.enc Dir3.stay) cols (walkScanLen tm x.length S) (one_le_walkScanLen tm x.length S)).mpr hdr @@ -2300,15 +2305,15 @@ theorem walkCodeScanner_accepts_succ {kk jj : ℕ} (tm : NTM kk) (x : List Bool) rw [Scanner.all_emit_run] intro p by_cases hp0 : p.val = 0 - · rw [if_pos hp0] + · rw [ite_eq_left hp0] exact succScanner_accepts tm x S cols par (codeRegsOf j) (codeRegsOf j') a b P hpar (holdsCodeScan_of_blocks tm x S cols j a ha) (holdsCodeScan_of_blocks tm x S cols j' b hb) hendW hendO hq hstate hwsym hosym hhead hwork hout hleft - · rw [if_neg hp0] + · rw [ite_eq_right hp0] by_cases hp1 : p.val = 1 - · rw [if_pos hp1] + · rw [ite_eq_left hp1] exact hdr - · rw [if_neg hp1] + · rw [ite_eq_right hp1] exact hres /-- **One walk step, as a single scan.** Either the guessed code repeats the old one and the @@ -2348,8 +2353,8 @@ theorem walkStepScanner_decides {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : rw [walkStepScanner, Scanner.all_emit_run] at hverdict have h0 := hverdict ⟨0, by omega⟩ have h1 := hverdict ⟨1, by omega⟩ - rw [if_pos (rfl : (0 : ℕ) = 0)] at h0 - rw [if_neg (by exact (by omega : (1 : ℕ) ≠ 0))] at h1 + rw [ite_eq_left (rfl : (0 : ℕ) = 0)] at h0 + rw [ite_eq_right (by exact (by omega : (1 : ℕ) ≠ 0))] at h1 exact ⟨walkCodeScanner_decides tm x S cols par mv dr res dc j j' a b P g hpar ha hb hne hres hg h0, counterStepScanner_decides cntOld cntNew wc (walkScanLen tm x.length S) advance hwc cols u v @@ -2372,9 +2377,9 @@ theorem walkStepScanner_accepts {kk jj : ℕ} (tm : NTM kk) (x : List Bool) (S : rw [walkStepScanner, Scanner.all_emit_run] intro p by_cases hp : p.val = 0 - · rw [if_pos hp] + · rw [ite_eq_left hp] exact hcode - · rw [if_neg hp] + · rw [ite_eq_right hp] exact counterStepScanner_accepts cntOld cntNew wc (walkScanLen tm x.length S) advance hwc cols u v hu hv hold hnew hmove @@ -2849,7 +2854,7 @@ theorem walkStepTM_hoareTime {kk jj : ℕ} (r : ℕ) (tm : NTM kk) (nn S : ℕ) have hsrcRead : (work (Fin.castAdd r (Fin.last (jj + 1))).castSucc).read = Γ.ofBool v := by rw [hregs (Fin.last (jj + 1)), hW₁, Fin.snoc_last] show (resT.write (Γ.ofBool v)).read = _ - rw [Tape.write, if_neg (show resT.head ≠ 0 by rw [hresT]; exact one_ne_zero)] + rw [Tape.write, ite_eq_right (show resT.head ≠ 0 by rw [hresT]; exact one_ne_zero)] show Function.update resT.cells resT.head (Γ.ofBool v) resT.head = _ rw [Function.update_self] refine ⟨c', tt, htt, hreach, hhalt, ?_, ?_, hin', hout', ?_, ?_⟩ @@ -2878,7 +2883,7 @@ theorem walkStepTM_hoareTime {kk jj : ℕ} (r : ℕ) (tm : NTM kk) (nn S : ℕ) have hc : work (Fin.natAdd (jj + 2) c).castSucc = TM.parkTape (G (Fin.natAdd (jj + 2) c).castSucc) := by have := congrFun hwork (Fin.natAdd (jj + 2) c) - rw [this, if_neg (haux c)] + rw [this, ite_eq_right (haux c)] rw [hc, hGaux c, TM.parkTape_eq_self (hhW _)] exact TM.transitionTape_eq_self ((hinvW _).read_ne_start (hhW _)) · rw [hinpP] @@ -2890,7 +2895,7 @@ theorem walkStepTM_hoareTime {kk jj : ℕ} (r : ℕ) (tm : NTM kk) (nn S : ℕ) have hi : work (Fin.castAdd r i).castSucc = (⟨1, (G (Fin.castAdd r i).castSucc).cells⟩ : Tape) := by have := congrFun hwork (Fin.castAdd r i) - rw [this, if_pos (hall i)] + rw [this, ite_eq_left (hall i)] rw [hi, TM.transitionTape_eq_self (by show (⟨1, (G (Fin.castAdd r i).castSucc).cells⟩ : Tape).read ≠ Γ.start exact fun hc => (ginv (Fin.castAdd r i).castSucc).2 1 le_rfl hc)] @@ -3079,7 +3084,7 @@ theorem publishTestTM_hoareTime {jj : ℕ} (Sc : Scanner jj) (len : ℕ) rw [hW₁cast q] exact ⟨le_rfl, fun p hp => ht.ne_start q p hp⟩ have hread : (W₁ (Fin.last (jj + 1))).read = Γ.ofBool v := by - rw [hW₁last, Tape.read, Tape.write_head, hresH, Tape.write, if_neg (by rw [hresH]; omega), + rw [hW₁last, Tape.read, Tape.write_head, hresH, Tape.write, ite_eq_right (by rw [hresH]; omega), hresH] show Function.update resT.cells 1 (Γ.ofBool v) 1 = _ rw [Function.update_self] @@ -3341,13 +3346,13 @@ theorem move_adjusted (t : Tape) (d : Dir3) (h : ℕ) (ht : t.head = max h 1) : (t.move (adjustedDir d h)).head = max (movedIdx d h) 1 := by rw [move_head_eq_movedIdx, ht, adjustedDir] by_cases h0 : h = 0 - · rw [if_pos h0, h0] + · rw [ite_eq_left h0, h0] cases d <;> simp [movedIdx] - · rw [if_neg h0] + · rw [ite_eq_right h0] by_cases h1 : movedIdx d h = 0 - · rw [if_pos h1, h1] + · rw [ite_eq_left h1, h1] cases d <;> simp only [movedIdx] at h1 ⊢ <;> omega - · rw [if_neg h1] + · rw [ite_eq_right h1] cases d <;> simp only [movedIdx] at h1 ⊢ <;> omega /-- **One walk step carries the input head to where the next code says.** Whichever branch the @@ -3622,26 +3627,26 @@ theorem stepIdx_inj (second : Bool) : ∀ p q, p < L.stepBlocks → q < L.stepBl /-- The second step of a pair guesses the old code's blocks. -/ theorem stepIdx_codeA (p : ℕ) (hp : p < kk + 3) : L.stepIdx true (L.scratch + p) = L.codeAIdx p := by - rw [stepIdx, if_neg (by omega), if_pos rfl, L.codeA_eq p hp] + rw [stepIdx, ite_eq_right (by omega), ite_eq_left rfl, L.codeA_eq p hp] /-- The first step guesses the new code's. -/ theorem stepIdx_codeB (p : ℕ) (hp : p < kk + 3) : L.stepIdx false (L.scratch + p) = L.codeBIdx p := by - rw [stepIdx, if_neg (by omega), if_neg (by simp), L.codeB_eq p hp] + rw [stepIdx, ite_eq_right (by omega), ite_eq_right (by simp), L.codeB_eq p hp] omega /-- The first step guesses none of the old code's blocks. -/ theorem stepIdx_ne_codeA (p q : ℕ) (_hp : p < L.stepBlocks) (hq : q < kk + 3) : L.stepIdx false p ≠ L.codeAIdx q := by rw [stepIdx, L.codeA_eq q hq] - split <;> [omega; (rw [if_neg (by simp)]; omega)] + split <;> [omega; (rw [ite_eq_right (by simp)]; omega)] /-- The second guesses none of the new code's. -/ theorem stepIdx_ne_codeB (p q : ℕ) (hp : p < L.stepBlocks) (hq : q < kk + 3) : L.stepIdx true p ≠ L.codeBIdx q := by rw [stepIdx, L.codeB_eq q hq] rw [stepBlocks] at hp - split <;> [omega; (rw [if_pos rfl]; omega)] + split <;> [omega; (rw [ite_eq_left rfl]; omega)] /-- The parameter register. -/ def par : Fin (jj + 1) := L.reg L.parIdx @@ -3762,7 +3767,7 @@ def stepWidth {kk jj : ℕ} {tm : NTM kk} {nn S wc : ℕ} (L : WalkWidths kk jj theorem stepWidth_scratch {kk jj : ℕ} {tm : NTM kk} {nn S wc : ℕ} (L : WalkWidths kk jj tm nn S wc) (p : ℕ) (hp : p < L.toWalkLayout.scratch) : stepWidth L p = L.width p := by - rw [stepWidth, WalkLayout.stepIdx, if_pos hp] + rw [stepWidth, WalkLayout.stepIdx, ite_eq_left hp] /-- A code block is guessed at the code's width. -/ theorem stepWidth_code {kk jj : ℕ} {tm : NTM kk} {nn S wc : ℕ} @@ -3775,7 +3780,7 @@ theorem width_stepIdx_false {kk jj : ℕ} {tm : NTM kk} {nn S wc : ℕ} (L : WalkWidths kk jj tm nn S wc) (p : ℕ) (hp : p < L.toWalkLayout.stepBlocks) : L.width (L.toWalkLayout.stepIdx false p) = stepWidth L p := by by_cases hs : p < L.toWalkLayout.scratch - · rw [stepWidth, WalkLayout.stepIdx, WalkLayout.stepIdx, if_pos hs, if_pos hs] + · rw [stepWidth, WalkLayout.stepIdx, WalkLayout.stepIdx, ite_eq_left hs, ite_eq_left hs] · have hp' : p - L.toWalkLayout.scratch < kk + 3 := by rw [WalkLayout.stepBlocks] at hp omega @@ -4256,7 +4261,7 @@ theorem stepReg_scratch {kk jj r : ℕ} {tm : NTM kk} {nn S wc : ℕ} (L : WalkWidths kk jj tm nn S wc) (second : Bool) (p : ℕ) (hp : p < L.toWalkLayout.scratch) : (stepReg L second p : Fin (jj + 2 + r + 1)) = walkReg (L.toWalkLayout.reg p) := by - rw [stepReg, WalkLayout.stepIdx, if_pos hp] + rw [stepReg, WalkLayout.stepIdx, ite_eq_left hp] /-- And so does its certificate. -/ theorem stepCert_scratch {kk jj : ℕ} {tm : NTM kk} {nn S wc : ℕ} @@ -4266,7 +4271,7 @@ theorem stepCert_scratch {kk jj : ℕ} {tm : NTM kk} {nn S wc : ℕ} (hp : p < L.toWalkLayout.scratch) : stepCert L x dc Ps ds cOlds cNews tgt aOld aNew second s p = stageBits L x dc (Ps s) (ds s) (cOlds s) (cNews s) tgt true (aOld s) (aNew s) p := by - rw [stepCert, WalkLayout.stepIdx, if_pos hp] + rw [stepCert, WalkLayout.stepIdx, ite_eq_left hp] /-- **A register no block of the step is guessed into keeps what it held.** -/ theorem stepCells_retained {kk jj r : ℕ} {tm : NTM kk} {nn S wc : ℕ} diff --git a/Complexitylib/Classes/Containments/Internal/TallyLoopIndexed.lean b/Complexitylib/Classes/Containments/Internal/TallyLoopIndexed.lean index 3ffe4e8b..e06bc2ef 100644 --- a/Complexitylib/Classes/Containments/Internal/TallyLoopIndexed.lean +++ b/Complexitylib/Classes/Containments/Internal/TallyLoopIndexed.lean @@ -63,14 +63,14 @@ theorem tallyLoop_hoareTime_of_hoare_indexed {n : ℕ} (tmBody tmTest : TM n) refine ⟨tallyPost_loopParked cIdx aIdx rIdx I (rest (j + 1)) P hI (hrest (j + 1)) N (j + 1) hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_neg (show ¬ (j + 1 = N) by omega)] + rw [ite_eq_right (show ¬ (j + 1 = N) by omega)] exact fun hcon => absurd (outSlot_cells_one_eq_one_iff Γw.zero |>.mp hcon) (by decide) obtain ⟨inp', work', out', t, -, ht, hreach, hp'⟩ := TM.loopTM_continue_of_hoare tmBody tmTest (hbody j hjN) (htest j hjN) (fun a b c hm => hmid j a b c hm) hne inp work out h obtain ⟨hi', hw', ho'⟩ := hp' exact ⟨inp', work', out', t, ht, hreach, hi', hw', Γw.zero, by decide, - by rw [ho', if_neg (by omega)]⟩ + by rw [ho', ite_eq_right (by omega)]⟩ · intro inp work out h have hjN : N - 1 < N := by omega have hhalt : ∀ a b c, tallyPost cIdx aIdx rIdx I (rest (N - 1 + 1)) P N (N - 1 + 1) a b c → @@ -79,7 +79,7 @@ theorem tallyLoop_hoareTime_of_hoare_indexed {n : ℕ} (tmBody tmTest : TM n) refine ⟨tallyPost_loopParked cIdx aIdx rIdx I (rest (N - 1 + 1)) P hI (hrest _) N _ hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_pos hsucc] + rw [ite_eq_left hsucc] exact (outSlot_cells_one_eq_one_iff Γw.one).mpr rfl obtain ⟨c', t, ht, hreach, hstate, hpost⟩ := TM.loopTM_halt_of_hoare tmBody tmTest (hbody (N - 1) hjN) (htest (N - 1) hjN) @@ -117,14 +117,14 @@ theorem tallyLoop_keepsWindow_of_hoare_indexed {n : ℕ} (tmBody tmTest : TM n) refine ⟨tallyPost_loopParked cIdx aIdx rIdx I (rest (j + 1)) P hI (hrest (j + 1)) N (j + 1) hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_neg (show ¬ (j + 1 = N) by omega)] + rw [ite_eq_right (show ¬ (j + 1 = N) by omega)] exact fun hcon => absurd (outSlot_cells_one_eq_one_iff Γw.zero |>.mp hcon) (by decide) obtain ⟨inp', work', out', t, ht1, ht, hreach, hp'⟩ := TM.loopTM_continue_of_hoare tmBody tmTest (hbody j hjN) (htest j hjN) (fun a b c hm => hmid j a b c hm) hne inp work out h obtain ⟨hi', hw', ho'⟩ := hp' exact ⟨inp', work', out', t, ht1, ht, hreach, hi', hw', Γw.zero, by decide, - by rw [ho', if_neg (by omega)]⟩ + by rw [ho', ite_eq_right (by omega)]⟩ · intro inp work out h have hjN : N - 1 < N := by omega have hhalt : ∀ a b c, tallyPost cIdx aIdx rIdx I (rest (N - 1 + 1)) P N (N - 1 + 1) a b c → @@ -133,7 +133,7 @@ theorem tallyLoop_keepsWindow_of_hoare_indexed {n : ℕ} (tmBody tmTest : TM n) refine ⟨tallyPost_loopParked cIdx aIdx rIdx I (rest (N - 1 + 1)) P hI (hrest _) N _ hp, ?_⟩ obtain ⟨-, -, rfl⟩ := hp - rw [if_pos hsucc] + rw [ite_eq_left hsucc] exact (outSlot_cells_one_eq_one_iff Γw.one).mpr rfl obtain ⟨c', t, ht, hreach, hstate, -⟩ := TM.loopTM_halt_of_hoare tmBody tmTest (hbody (N - 1) hjN) (htest (N - 1) hjN) diff --git a/Complexitylib/Classes/Containments/Internal/TranscriptEnc.lean b/Complexitylib/Classes/Containments/Internal/TranscriptEnc.lean index fd2cf703..2b672cde 100644 --- a/Complexitylib/Classes/Containments/Internal/TranscriptEnc.lean +++ b/Complexitylib/Classes/Containments/Internal/TranscriptEnc.lean @@ -94,7 +94,7 @@ theorem encMsg_length_le (v : List Bool) : (encMsg v).length ≤ 4 * v.length + obtain ⟨y, hy, rfl⟩ := List.mem_map.mp hl obtain ⟨b, _, rfl⟩ := List.mem_map.mp hy exact encBit_length_le b - have := List.sum_le_card_nsmul _ 4 h + have := List.sum_le_length_nsmul _ 4 h rw [List.length_map, List.length_map] at this simp only [smul_eq_mul] at this simp only [List.length_nil] @@ -231,14 +231,15 @@ theorem encFlatFn_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : omega have h := Cobham.iterate_mem_FP encStepP_mem_FP hinit ha hwidth hbound have h1 := mem_FP_comp h Cobham.fstBlock_mem_FP - simpa [Function.comp, encFlat] using h1 + simp [encFlat] + exact h1 theorem encMsgFn_mem_FP {a : List Bool → List Bool} (ha : a ∈ FP) : (fun z => encMsg (a z)) ∈ FP := by have h : (fun z => false :: (encFlat (a z) ++ [true])) ∈ FP := by have hcat := Cobham.appendFn_mem_FP (encFlatFn_mem_FP ha) (constFn_mem_FP [true]) have := mem_FP_comp hcat (Cobham.cons_mem_FP false) - simpa [Function.comp] using this + exact this exact mem_FP_of_eq h fun z => (encMsg_eq_encFlat (a z)).symm /-! ## Transcripts given as rounds -/ diff --git a/Complexitylib/Classes/Containments/Internal/WitnessEnum.lean b/Complexitylib/Classes/Containments/Internal/WitnessEnum.lean index 306d3f3d..6857ab4a 100644 --- a/Complexitylib/Classes/Containments/Internal/WitnessEnum.lean +++ b/Complexitylib/Classes/Containments/Internal/WitnessEnum.lean @@ -83,8 +83,7 @@ theorem bitsOfLen_binVal (w : List Bool) : bitsOfLen w.length (binVal w) = w := have hmod : binVal (b :: w) % 2 ^ w.length = binVal w := by simp only [binVal] cases b <;> simp [Nat.mod_eq_of_lt hlt] - simp only [bitsOfLen, hdiv, hmod, ih] - cases b <;> simp + cases b <;> simp [bitsOfLen, hdiv, hmod, ih] /-- **The other half of the round trip.** The value of the bitstring of length `ℓ` and value `v` is `v` again, provided `v` fits. Together with `bitsOfLen_binVal` this makes the correspondence a @@ -170,8 +169,7 @@ theorem bitsOfLenLE_binValLE (w : List Bool) : bitsOfLenLE w.length (binValLE w) have hdiv : binValLE (b :: w) / 2 = binValLE w := by simp only [binValLE] cases b <;> simp [Nat.add_mul_div_left] - simp only [bitsOfLenLE, hmod, hdiv, ih] - cases b <;> simp + cases b <;> simp [bitsOfLenLE, hdiv, hmod, ih] /-- The round trip, the other way. -/ theorem binValLE_bitsOfLenLE : ∀ (ℓ v : ℕ), v < 2 ^ ℓ → binValLE (bitsOfLenLE ℓ v) = v := by diff --git a/Complexitylib/Classes/EventProb.lean b/Complexitylib/Classes/EventProb.lean index e4a48ce9..1d3ca772 100644 --- a/Complexitylib/Classes/EventProb.lean +++ b/Complexitylib/Classes/EventProb.lean @@ -201,6 +201,9 @@ theorem eventProb_biUnion_le {T : ℕ} {ι : Type*} [DecidableEq ι] (s : Finset /-- Finite additivity: the probability of a disjoint finite union is the sum of the probabilities of its events. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem eventProb_biUnion {T : ℕ} {ι : Type*} [DecidableEq ι] (s : Finset ι) (E : ι → Finset (Fin T → Bool)) (h : (s : Set ι).PairwiseDisjoint E) : diff --git a/Complexitylib/Classes/FNP/Internal.lean b/Complexitylib/Classes/FNP/Internal.lean index 74f7f87e..69b26497 100644 --- a/Complexitylib/Classes/FNP/Internal.lean +++ b/Complexitylib/Classes/FNP/Internal.lean @@ -43,7 +43,7 @@ theorem pairLang_orRelation_mem_P {R₁ R₂ : List Bool → List Bool → Prop} pairLang (OrRelation R₁ R₂) ∈ P := by -- pairLang (OrRelation R₁ R₂) = pairLang R₁ ∪ pairLang R₂ have heq : pairLang (OrRelation R₁ R₂) = pairLang R₁ ∪ pairLang R₂ := by - ext z; simp only [pairLang, OrRelation, Set.mem_setOf_eq, Set.mem_union]; aesop + ext z; simp only [pairLang, OrRelation, Set.mem_ofPred_eq, Set.mem_union]; aesop rw [heq] -- Extract polynomial degrees from P = ⋃ k, DTIME(· ^ k) obtain ⟨d₁, hd₁⟩ := Set.mem_iUnion.mp h₁ diff --git a/Complexitylib/Classes/FiniteCounting.lean b/Complexitylib/Classes/FiniteCounting.lean index aad3d976..31536b77 100644 --- a/Complexitylib/Classes/FiniteCounting.lean +++ b/Complexitylib/Classes/FiniteCounting.lean @@ -148,14 +148,14 @@ theorem card_filter_block {a b : ℕ} rw [← Finset.card_product] apply Finset.card_bij' (fun w _ => blockEquiv a b w) (fun p _ => (blockEquiv a b).symm p) · intro w hw - simp only [Finset.mem_filter, Finset.mem_univ, true_and, blockFst, blockSnd] at hw ⊢ + simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hw exact Finset.mem_product.mpr ⟨Finset.mem_filter.mpr ⟨Finset.mem_univ _, hw.1⟩, Finset.mem_filter.mpr ⟨Finset.mem_univ _, hw.2⟩⟩ · intro p hp simp only [Finset.mem_product, Finset.mem_filter, Finset.mem_univ, true_and] at hp - simp only [Finset.mem_filter, Finset.mem_univ, true_and, blockFst, blockSnd, - Equiv.apply_symm_apply] + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + simp only [blockFst, blockSnd, Equiv.apply_symm_apply] exact ⟨hp.1, hp.2⟩ · intro w _; simp [Equiv.symm_apply_apply] · intro p _; simp [Equiv.apply_symm_apply] @@ -402,7 +402,9 @@ theorem card_repeatRandomSeed_fiber (k T : ℕ) (seed : Fin (k * T) → Bool) : (fun _ : Fin 2 → Bool => True) (fun w => repeatStrideRandomSeed k T w = seed) rw [card_repeatStrideRandomSeed_fiber] at h - simpa [repeatRandomSeed, card_finArrowBool, pow_add] using h + simp [repeatRandomSeed, pow_add] at h ⊢ + convert h using 3 + rfl /-- If a finite Boolean-seed projection has constant fibers, then every event that factors through the projection gains exactly that common fiber factor. -/ @@ -422,7 +424,7 @@ theorem card_filter_of_constant_fibers have hmaps : (fullEvent : Set (Fin total → Bool)).MapsTo randomSeed compactEvent := by intro w hw simp only [fullEvent, compactEvent, Finset.coe_filter, Finset.mem_univ, - Set.mem_setOf_eq, true_and] at hw ⊢ + Set.mem_ofPred_eq, true_and] at hw ⊢ exact (hfactor w).mp hw rw [Finset.card_eq_sum_card_fiberwise hmaps] calc @@ -481,19 +483,26 @@ private theorem card_filter_blockEventCount_eq_iff (k T j : ℕ) (fun w _ => blocksEquiv k T w) (fun f _ => (blocksEquiv k T).symm f) · intro w hw - simpa only [Finset.mem_filter, Finset.mem_univ, true_and, blockEventCount] using hw + simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hw ⊢ + simpa only [blockEventCount] using hw · intro f hf - simpa only [Finset.mem_filter, Finset.mem_univ, true_and, blockEventCount, - Equiv.apply_symm_apply] using hf + simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hf ⊢ + simpa only [blockEventCount, Equiv.apply_symm_apply] using hf · intro w _ exact Equiv.symm_apply_apply _ _ · intro f _ exact Equiv.apply_symm_apply _ _ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private def eventBits {k : ℕ} {α : Type*} [Fintype α] [DecidableEq α] (E : Finset α) (f : Fin k → α) : Fin k → Bool := fun i => decide (f i ∈ E) +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private def eventCount {k : ℕ} {α : Type*} [Fintype α] [DecidableEq α] (E : Finset α) (f : Fin k → α) : ℕ := (Finset.univ.filter (fun i : Fin k => f i ∈ E)).card @@ -546,8 +555,8 @@ private theorem card_eventCount_eq {k : ℕ} {α : Type*} Finset.univ.filter (fun b : Fin k → Bool => popCount b = j)) := by apply Finset.filter_congr intro f _ - simp only [Finset.mem_filter, Finset.mem_univ, true_and, eventCount, popCount, - eventBits, decide_eq_true_eq] + simp only [Finset.mem_filter, Finset.mem_univ, true_and] + simp only [eventCount, popCount, eventBits, decide_eq_true_eq] rw [hfilter, ← Finset.sum_card_fiberwise_eq_card_filter (Finset.univ : Finset (Fin k → α)) (Finset.univ.filter (fun b : Fin k → Bool => popCount b = j)) (eventBits E)] @@ -580,8 +589,7 @@ theorem card_tupleEventCount_eq {k : ℕ} {α : Type*} (fun f : Fin k → α => tupleEventCount E f = j)).card = k.choose j * E.card ^ j * (Fintype.card α - E.card) ^ (k - j) := by - simpa only [tupleEventCount, eventCount] using - card_eventCount_eq (k := k) E j + exact card_eventCount_eq (k := k) E j /-- The number of tuples whose event count lies in a finite set is the corresponding weighted binomial sum. -/ diff --git a/Complexitylib/Classes/NP/Internal/PairBuildTM.lean b/Complexitylib/Classes/NP/Internal/PairBuildTM.lean index a0bdde43..2c07cb29 100644 --- a/Complexitylib/Classes/NP/Internal/PairBuildTM.lean +++ b/Complexitylib/Classes/NP/Internal/PairBuildTM.lean @@ -385,7 +385,7 @@ private theorem pairBuild_copyX1_halt_step {k : ℕ} (yIdx pIdx : Fin k) c'.input = c.input ∧ c'.work yIdx = c.work yIdx ∧ c'.work pIdx = c.work pIdx := by - simp only [TM.step, hst, pairBuildTM, if_pos hread] + simp only [TM.step, hst, pairBuildTM, ite_eq_left hread] refine ⟨_, rfl, rfl, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins · exact tape_writeAndMove_stable (c.work yIdx) hyh hyns @@ -411,10 +411,10 @@ private theorem pairBuild_copyX1_cont_step {k : ℕ} (yIdx pIdx : Fin k) (c'.work pIdx).head = (c.work pIdx).head + 1 ∧ (c'.work pIdx).cells = Function.update (c.work pIdx).cells (c.work pIdx).head c.input.read := by - simp only [TM.step, hst, pairBuildTM, if_neg hread_nb] + simp only [TM.step, hst, pairBuildTM, ite_eq_right hread_nb] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins - · simp only [if_neg hne] + · simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns · simp only [↓reduceIte] simp [Tape.writeAndMove, Tape.write, Tape.move, @@ -448,7 +448,7 @@ private theorem pairBuild_copyX2_step {k : ℕ} (yIdx pIdx : Fin k) · show (c.input.move .right).head = c.input.head + 1 simp [Tape.move] · exact Tape.move_cells _ _ - · simp only [if_neg hne] + · simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns · simp only [↓reduceIte] simp [Tape.writeAndMove, Tape.write, Tape.move, @@ -478,7 +478,7 @@ private theorem pairBuild_writeSep1_step {k : ℕ} (yIdx pIdx : Fin k) simp only [TM.step, hst, pairBuildTM] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins - · simp only [if_neg hne] + · simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns · simp only [↓reduceIte] simp [Tape.writeAndMove, Tape.write, Tape.move, @@ -507,7 +507,7 @@ private theorem pairBuild_writeSep2_step {k : ℕ} (yIdx pIdx : Fin k) simp only [TM.step, hst, pairBuildTM] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins - · simp only [if_neg hne] + · simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns · simp only [↓reduceIte] simp [Tape.writeAndMove, Tape.write, Tape.move, @@ -531,7 +531,7 @@ private theorem pairBuild_copyY_halt_step {k : ℕ} (yIdx pIdx : Fin k) c'.input = c.input ∧ c'.work yIdx = c.work yIdx ∧ c'.work pIdx = c.work pIdx := by - simp only [TM.step, hst, pairBuildTM, if_pos hyread] + simp only [TM.step, hst, pairBuildTM, ite_eq_left hyread] refine ⟨_, rfl, rfl, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins · exact tape_writeAndMove_stable (c.work yIdx) hyh hyns @@ -556,17 +556,17 @@ private theorem pairBuild_copyY_cont_step {k : ℕ} (yIdx pIdx : Fin k) (c'.work pIdx).head = (c.work pIdx).head + 1 ∧ (c'.work pIdx).cells = Function.update (c.work pIdx).cells (c.work pIdx).head (c.work yIdx).read := by - simp only [TM.step, hst, pairBuildTM, if_neg hyread_nb] + simp only [TM.step, hst, pairBuildTM, ite_eq_right hyread_nb] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins · -- yIdx head advances (yIdx ≠ pIdx, condition picks the else branch, which is Dir3.right) - simp only [if_neg hne] + simp only [ite_eq_right hne] show ((c.work yIdx).writeAndMove (readBackWrite (c.work yIdx).read).toΓ Dir3.right).head = (c.work yIdx).head + 1 simp [Tape.writeAndMove, Tape.write, Tape.move, show (c.work yIdx).head ≠ 0 from by omega] · -- yIdx cells unchanged (readBackWrite preserves non-▷ symbols) - simp only [if_neg hne] + simp only [ite_eq_right hne] show ((c.work yIdx).writeAndMove (readBackWrite (c.work yIdx).read).toΓ Dir3.right).cells = (c.work yIdx).cells rw [toΓ_readBackWrite_of_ne_start hyread_ns] @@ -598,11 +598,11 @@ private theorem pairBuild_rewindP1_step_cont {k : ℕ} (yIdx pIdx : Fin k) c'.work yIdx = c.work yIdx ∧ (c'.work pIdx).head = (c.work pIdx).head - 1 ∧ (c'.work pIdx).cells = (c.work pIdx).cells := by - simp only [TM.step, hst, pairBuildTM, if_neg hpread_ns] + simp only [TM.step, hst, pairBuildTM, ite_eq_right hpread_ns] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins · -- yIdx stable (yIdx ≠ pIdx picks else branch; readBackWrite + idle) - simp only [if_neg hne] + simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns · -- pIdx head = head - 1 simp only [↓reduceIte] @@ -630,11 +630,11 @@ private theorem pairBuild_rewindP1_step_base {k : ℕ} (yIdx pIdx : Fin k) c'.work yIdx = c.work yIdx ∧ (c'.work pIdx).head = 1 ∧ (c'.work pIdx).cells = (c.work pIdx).cells := by - simp only [TM.step, hst, pairBuildTM, if_pos hpread] + simp only [TM.step, hst, pairBuildTM, ite_eq_left hpread] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact tape_move_idleDir_stable c.input hih hins · -- yIdx stable (yIdx ≠ pIdx picks else branch) - simp only [if_neg hne] + simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns · -- pIdx head = 1 simp only [↓reduceIte] @@ -1247,7 +1247,7 @@ private theorem pairBuildTM_from_copyX1_initTape_move_right rw [hc1_pc] show (Tape.init []).cells j ≠ Γ.start show (if j = 0 then Γ.start else ([][j - 1]?).getD Γ.blank) ≠ Γ.start - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] simp have hc1_input_data : ∀ i, i < x.length → c1.input.cells (c1.input.head + i) ≠ Γ.blank ∧ @@ -2044,7 +2044,7 @@ theorem pairBuildTM_hoareTime rw [hc2_above _ hi_c2] -- c1.cells = c0.cells. Initial tape is Tape.init [], cells at j ≥ 1 = blank. rw [hc1_pc, hc0_pw_cells] - rw [if_neg (by omega : i + 1 ≠ 0)] + rw [ite_eq_right (by omega : i + 1 ≠ 0)] /-- A compact corollary of `pairBuildTM_hoareTime`: the pair tape satisfies exact equality with the standard initialized pair tape, moved to cell 1. -/ diff --git a/Complexitylib/Classes/Negligible.lean b/Complexitylib/Classes/Negligible.lean index 221f39de..281a0232 100644 --- a/Complexitylib/Classes/Negligible.lean +++ b/Complexitylib/Classes/Negligible.lean @@ -5,7 +5,7 @@ Authors: Samuel Schlesinger -/ module -public import Mathlib.Data.Real.Basic +public import Mathlib.Basic.Real.Basic /-! # Negligible functions diff --git a/Complexitylib/Classes/P/Cobham/Internal.lean b/Complexitylib/Classes/P/Cobham/Internal.lean index 69d763cb..0fecbf14 100644 --- a/Complexitylib/Classes/P/Cobham/Internal.lean +++ b/Complexitylib/Classes/P/Cobham/Internal.lean @@ -193,7 +193,7 @@ theorem selectHeadFn_mem_FP {f a b : List Bool → List Bool} (fun z => selectHead (f z) (a z) (b z)) ∈ FP := by have hflag : ∀ t : Bool, (fun z => headFlag t (f z)) ∈ FP := fun t => by have := mem_FP_comp hf (headFlag_mem_FP t) - simpa [Function.comp] using this + exact this have hx : (fun z => (a z).take ((headFlag true (f z)).length * (a z).length)) ∈ FP := by have := takeLenFn_mem_FP (mulLenFn_mem_FP (hflag true) ha) ha simpa using this @@ -411,7 +411,8 @@ theorem const_replicate_mem_FP (c : ℕ) : | zero => simpa using const_nil_mem_FP | succ c ih => have := mem_FP_comp ih (cons_mem_FP false) - simpa [Function.comp, List.replicate_succ] using this + simp [List.replicate_succ] + exact this /-- A ruler of length exactly `|z| ^ d`. -/ private theorem exists_pow_exact_ruler (d : ℕ) : @@ -481,10 +482,10 @@ theorem loopStep_mem_FP {A B : List Bool → List Bool} (hA : A ∈ FP) (hB : B have hsnd : pairSnd ∈ FP := sndBlock_mem_FP have hcomp₁ : ∀ {g : List Bool → List Bool}, g ∈ FP → (fun v => pairFst (g v)) ∈ FP := fun hg => by - simpa [Function.comp] using mem_FP_comp hg hfst + exact mem_FP_comp hg hfst have hcomp₂ : ∀ {g : List Bool → List Bool}, g ∈ FP → (fun v => pairSnd (g v)) ∈ FP := fun hg => by - simpa [Function.comp] using mem_FP_comp hg hsnd + exact mem_FP_comp hg hsnd have hP : (fun v : List Bool => pairFst v) ∈ FP := hfst have hR : (fun v : List Bool => pairFst (pairFst v)) ∈ FP := hcomp₁ hP have hW : (fun v : List Bool => pairFst (pairSnd (pairFst v))) ∈ FP := @@ -495,9 +496,9 @@ theorem loopStep_mem_FP {A B : List Bool → List Bool} (hA : A ∈ FP) (hB : B have ha : (fun v : List Bool => pairSnd (pairSnd v)) ∈ FP := hcomp₂ hsnd have hrev : ∀ {g : List Bool → List Bool}, g ∈ FP → (fun v => (g v).reverse) ∈ FP := fun hg => by - simpa [Function.comp] using mem_FP_comp hg reverse_mem_FP + exact mem_FP_comp hg reverse_mem_FP have hcons : (fun v : List Bool => false :: pairFst (pairSnd v)) ∈ FP := by - simpa [Function.comp] using mem_FP_comp ht (cons_mem_FP false) + exact mem_FP_comp ht (cons_mem_FP false) have ht' : (fun v : List Bool => (takeLen (pair (false :: pairFst (pairSnd v)) (pairSnd (pairSnd (pairFst v))).reverse)).reverse) ∈ FP := by @@ -521,7 +522,7 @@ theorem loopStep_mem_FP {A B : List Bool → List Bool} (hA : A ∈ FP) (hB : B simpa [takeLen_pair, Function.comp] using this have hall := pairFn_mem_FP (pairFn_mem_FP hR (pairFn_mem_FP hW hs)) (pairFn_mem_FP ht' hacc) - simpa [loopStep, loopStepOn] using hall + exact hall /-- **The loop's invariant.** After `m` iterations the state holds the suffix `s.drop (|s| - m)` and the clamped fold over it. -/ @@ -584,15 +585,15 @@ theorem emptyFlag_head_cons (b : Bool) (t : List Bool) : theorem selectHead_emptyFlag_nil (x y : List Bool) : selectHead (emptyFlag []) x y = x := by rw [emptyFlag_nil, selectHead, - if_pos (show ([true] : List Bool).head? = some true from rfl)] + ite_eq_left (show ([true] : List Bool).head? = some true from rfl)] theorem length_take_le_arg (n : ℕ) (l : List Bool) : (l.take n).length ≤ n := by rw [List.length_take]; omega theorem selectHead_emptyFlag_cons (b : Bool) (t x y : List Bool) : selectHead (emptyFlag (b :: t)) x y = y := by - rw [selectHead, if_neg (by rw [emptyFlag_head_cons]; simp), - if_pos (emptyFlag_head_cons b t)] + rw [selectHead, ite_eq_right (by rw [emptyFlag_head_cons]; simp), + ite_eq_left (emptyFlag_head_cons b t)] theorem selectHead_length_le (s x y : List Bool) : (selectHead s x y).length ≤ max x.length y.length := by @@ -654,25 +655,25 @@ theorem iterStep_iterate_length_le (F : List Bool → List Bool) (x : List Bool) theorem emptyFlag_mem_FP {f : List Bool → List Bool} (hf : f ∈ FP) : (fun z => emptyFlag (f z)) ∈ FP := by have hcst : (fun _ : List Bool => [true]) ∈ FP := by - simpa [Function.comp] using mem_FP_comp const_nil_mem_FP (cons_mem_FP true) + exact mem_FP_comp const_nil_mem_FP (cons_mem_FP true) have h1 : (fun z => headFlag true (f z)) ∈ FP := by - simpa [Function.comp] using mem_FP_comp hf (headFlag_mem_FP true) + exact mem_FP_comp hf (headFlag_mem_FP true) have h2 : (fun z => headFlag false (f z)) ∈ FP := by - simpa [Function.comp] using mem_FP_comp hf (headFlag_mem_FP false) + exact mem_FP_comp hf (headFlag_mem_FP false) exact appendFn_mem_FP (appendFn_mem_FP h1 h2) hcst theorem nextCounter_mem_FP : nextCounter ∈ FP := by have hf : pairFst ∈ FP := fstBlock_mem_FP have hs : pairSnd ∈ FP := sndBlock_mem_FP have hc : (fun w => false :: pairFst (pairFst w)) ∈ FP := by - simpa [Function.comp] using - mem_FP_comp (mem_FP_comp hf hf) (cons_mem_FP false) + exact mem_FP_comp (mem_FP_comp hf hf) (cons_mem_FP false) have hk : (fun w => pairFst (pairFst (pairSnd w))) ∈ FP := by - simpa [Function.comp] using mem_FP_comp hs (mem_FP_comp hf hf) + exact mem_FP_comp (f := pairSnd) (g := fun w => pairFst (pairFst w)) hs + (mem_FP_comp hf hf) have := takeLenFn_mem_FP hc hk have hrev : (fun w => ((pairFst (pairFst (pairSnd w))).take (false :: pairFst (pairFst w)).length).reverse) ∈ FP := by - simpa [Function.comp] using mem_FP_comp this reverse_mem_FP + exact mem_FP_comp this reverse_mem_FP have heq : (fun w => ((pairFst (pairFst (pairSnd w))).take (false :: pairFst (pairFst w)).length).reverse) = nextCounter := by funext w @@ -809,12 +810,12 @@ theorem iterVal_eq_iterate (F : List Bool → List Bool) (W v₀ : List Bool) (M rw [iterVal, ih] by_cases h : i + 2 ≤ M + 1 · have hhead := counter_head_false (M + 1) (i + 2) (by omega) h - rw [selectHead, if_neg (by rw [hhead]; simp), if_pos hhead, + rw [selectHead, ite_eq_right (by rw [hhead]; simp), ite_eq_left hhead, show min i M = i from by omega, ← Function.iterate_succ_apply' F i v₀, List.take_of_length_le (hclamp (i + 1) (by omega)), show min (i + 1) M = i + 1 from by omega] · have hhead := counter_head_true (M + 1) (i + 2) (by omega) - rw [selectHead, if_pos hhead, show min i M = M from by omega, + rw [selectHead, ite_eq_left hhead, show min i M = M from by omega, show min (i + 1) M = M from by omega] /-- **`FP` is closed under bounded iteration** — the one machine-level fact the @@ -896,9 +897,9 @@ theorem iterate_mem_FP {F init ruler width : List Bool → List Bool} -- the wrapper is `FP`, so the composite is have hXFP : X ∈ FP := by have hone : (fun _ : List Bool => [false]) ∈ FP := by - simpa [Function.comp] using mem_FP_comp const_nil_mem_FP (cons_mem_FP false) + exact mem_FP_comp const_nil_mem_FP (cons_mem_FP false) have htrue : (fun _ : List Bool => [true]) ∈ FP := by - simpa [Function.comp] using mem_FP_comp const_nil_mem_FP (cons_mem_FP true) + exact mem_FP_comp const_nil_mem_FP (cons_mem_FP true) have hrl : (fun z => ruler z ++ [false]) ∈ FP := appendFn_mem_FP hruler hone have hrep : (fun z => List.replicate ((ruler z).length + 1) false) ∈ FP := by have := mulLenFn_mem_FP hrl hone @@ -1018,8 +1019,8 @@ theorem recFold_eq_recNotation {n : ℕ} {g : (Fin n → List Bool) → List Boo = _ rw [ih, henc, recNotation_cons] cases b - · simp only [cond_false]; exact hH₀ _ - · simp only [cond_true]; exact hH₁ _ + · simp only [Bool.cond_false]; exact hH₀ _ + · simp only [Bool.cond_true]; exact hH₁ _ /-- Every `FP` function has polynomially bounded output length: a time bound is also an output-length bound (`TM.ComputesInTime.output_length_le`). -/ diff --git a/Complexitylib/Classes/P/Cobham/Internal/Algebra.lean b/Complexitylib/Classes/P/Cobham/Internal/Algebra.lean index 9484328f..c8a0c029 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Algebra.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Algebra.lean @@ -466,13 +466,13 @@ theorem foldr_table_eq (g d val : List Bool) : rintro ⟨p, hp, hpre⟩ hall rcases Decidable.em (a.1 <+: g) with hm | hm · rw [List.foldr_cons, (matchPrefix_eq_true_iff a.1 g).mpr hm, caseBit₀_cons, - cond_true] + Bool.cond_true] exact hall a (by simp) hm · have hmf : matchPrefix a.1 g = [false] := by rcases matchPrefix_flag a.1 g with h | h · exact absurd ((matchPrefix_eq_true_iff a.1 g).mp h) hm · exact h - rw [List.foldr_cons, hmf, caseBit₀_cons, cond_false] + rw [List.foldr_cons, hmf, caseBit₀_cons, Bool.cond_false] refine ih ⟨p, ?_, hpre⟩ fun q hq => hall q (by simp [hq]) rcases List.mem_cons.mp hp with rfl | hp' · exact absurd hpre hm diff --git a/Complexitylib/Classes/P/Cobham/Internal/BlockLoop.lean b/Complexitylib/Classes/P/Cobham/Internal/BlockLoop.lean index db6e68a0..85c314c6 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/BlockLoop.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/BlockLoop.lean @@ -78,11 +78,11 @@ theorem acceptCountAux_length (tm : NTM k) (u x τ s ρ : List Bool) : rw [acceptCountAux, List.length_cons, Finset.sum_range_succ, ← ih] rcases hflag with hf | hf · rw [hf] - simp only [caseBit₀_cons, cond_true, List.length_cons] - rw [if_pos (by rw [← blockOf_eq]; exact hf)] + simp only [caseBit₀_cons, Bool.cond_true, List.length_cons] + rw [ite_eq_left (by rw [← blockOf_eq]; exact hf)] · rw [hf] - simp only [caseBit₀_cons, cond_false] - rw [if_neg (by rw [← blockOf_eq, hf]; simp)] + simp only [caseBit₀_cons, Bool.cond_false] + rw [ite_eq_right (by rw [← blockOf_eq, hf]; simp)] omega /-- The step of the counting recursion. -/ @@ -107,7 +107,7 @@ private theorem recNotation_count (tm : NTM k) (u x τ s ρ : List Bool) : | cons β y ih => rw [recNotation_cons, acceptCountAux] cases β <;> - · simp only [cond_false, cond_true, countStep, Fin.cons_zero, Fin.cons_one] + · simp only [Bool.cond_false, Bool.cond_true, countStep, Fin.cons_zero, Fin.cons_one] rw [show (Fin.cons y (Fin.cons (recNotation (fun _ : Fin 4 → List Bool => ([] : List Bool)) (countStep tm) (countStep tm) y ![u, x, τ, s]) ![u, x, τ, s]) : Fin 6 → List Bool) 2 = u from rfl, @@ -142,7 +142,7 @@ private theorem recNotation_count_length (tm : NTM k) (ρ : List Bool) · simp · cases d <;> simp cases β <;> - · simp only [cond_false, cond_true] + · simp only [Bool.cond_false, Bool.cond_true] have := hstep y (recNotation (fun _ : Fin 4 → List Bool => ([] : List Bool)) (countStep tm) (countStep tm) y v) v diff --git a/Complexitylib/Classes/P/Cobham/Internal/Blocks.lean b/Complexitylib/Classes/P/Cobham/Internal/Blocks.lean index ad5f1eb4..11f7228d 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Blocks.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Blocks.lean @@ -268,7 +268,7 @@ theorem andBit_flag (x y : List Bool) : | cons a x => cases a · exact Or.inr rfl - · rw [caseBit₀_cons, cond_true] + · rw [caseBit₀_cons, Bool.cond_true] cases y with | nil => exact Or.inr rfl | cons d y => cases d <;> simp @@ -291,7 +291,7 @@ theorem matchPrefix_eq_true_iff (c x : List Bool) : cases x with | nil => simp [andBit] | cons a x => - rw [matchPrefix_cons, nonemptyFlag_cons, andBit, caseBit₀_cons, cond_true, + rw [matchPrefix_cons, nonemptyFlag_cons, andBit, caseBit₀_cons, Bool.cond_true, andBit] have hbit : (bif b then bitAt [] (a :: x) else notBit (bitAt [] (a :: x))) = [decide (a = b)] := by diff --git a/Complexitylib/Classes/P/Cobham/Internal/ChoiceSim.lean b/Complexitylib/Classes/P/Cobham/Internal/ChoiceSim.lean index a1bc6638..a6c3382f 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/ChoiceSim.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/ChoiceSim.lean @@ -109,7 +109,7 @@ private theorem cellsCode_of_bits' (x : List Bool) : | cons b x ih => intro t i hcells rw [List.length_cons, cellsCode_succ_left, encodeBits_cons, - show t.cells i = Γ.ofBool b from by simpa using hcells 0 (by simp)] + show t.cells i = Γ.ofBool b from by have h0 := hcells 0 (by simp); simpa using h0] congr 1 exact ih t (i + 1) fun j hj => by have := hcells (j + 1) (by rw [List.length_cons]; omega) @@ -218,9 +218,9 @@ theorem initChoiceFn_eq (tm : NTM k) (W : ℕ) (x c : List Bool) (if i.castSucc = Fin.last k then choiceTape c else (Tape.init [] : Tape))) = fun _ : Fin k => (Tape.init [] : Tape) from by funext i - rw [if_neg (Fin.castSucc_lt_last i).ne]] + rw [ite_eq_right (Fin.castSucc_lt_last i).ne]] rw [List.ofFn_const] - rw [hcast, if_pos rfl, List.replicate_succ] + rw [hcast, ite_eq_left rfl, List.replicate_succ] simp rw [cfgCode, cfgBlocks_eq, List.flatten_cons, flatten_tapesBlocks', hct] simp only [List.map_cons, List.map_nil, List.map_append, List.map_replicate, @@ -247,7 +247,7 @@ theorem runCfg_choiceCfg_startInvariant (tm : NTM k) (x c : List Bool) (n : ℕ) · exact Tape.StartInvariant.init_ofBool c · exact Tape.StartInvariant.init_nil | succ n ih => - rw [TM.runCfg_succ] + erw [TM.runCfg_succ] cases hs : (NTM.choiceTM tm).step (TM.runCfg (NTM.choiceTM tm) (choiceCfg tm x c) n) with | none => rw [Option.getD_none]; exact ih | some c' => @@ -262,11 +262,12 @@ theorem runCfg_choiceCfg_head_le (tm : NTM k) (x c : List Bool) (n : ℕ) : (TM.runCfg (NTM.choiceTM tm) (choiceCfg tm x c) n).output.head ≤ n + 1 := by induction n with | zero => - refine ⟨by simp [choiceCfg], fun i => ?_, by simp [choiceCfg]⟩ + refine ⟨by erw [TM.runCfg_zero]; simp [choiceCfg], fun i => ?_, + by erw [TM.runCfg_zero]; simp [choiceCfg]⟩ show (if i = Fin.last k then choiceTape c else Tape.init []).head ≤ 0 + 1 split <;> simp | succ n ih => - rw [TM.runCfg_succ] + erw [TM.runCfg_succ] cases hs : (NTM.choiceTM tm).step (TM.runCfg (NTM.choiceTM tm) (choiceCfg tm x c) n) with | none => rw [Option.getD_none] @@ -302,7 +303,7 @@ theorem iterate_stepFn_choice (tm : NTM k) (W : ℕ) (x c : List Bool) | succ n ih => intro hn obtain ⟨hinv, hW⟩ := cfgTapes_runCfg_choiceCfg_inv tm x c n W (by omega) - rw [Function.iterate_succ_apply', ih (by omega), TM.runCfg_succ] + rw [Function.iterate_succ_apply', ih (by omega)]; erw [TM.runCfg_succ] cases hs : (NTM.choiceTM tm).step (TM.runCfg (NTM.choiceTM tm) (choiceCfg tm x c) n) with | none => rw [Option.getD_none] @@ -364,7 +365,7 @@ theorem runChoiceFn_mem {n : ℕ} (tm : NTM k) intro c v have hlen := iterate_stepFn_choice_length_le tm (clockRuler (v 1)) (v 2) (v 0) c.length simp only [List.length_flatten, List.map_replicate, List.sum_replicate] - simpa using hlen) + exact hlen) have hg : ∀ i : Fin 4, Cobham (![gc, gc, gu, gx] i) := by intro i match i with @@ -478,12 +479,12 @@ theorem dropChoice_runCfg_choiceCfg (tm : NTM k) (T : ℕ) (x c : List Bool) : TM.runCfg_of_reachesIn _ hreach rcases Nat.lt_or_ge t T with hlt | hge · have hhalt := hstop hlt - rw [show T = t + (T - t) from by omega, TM.runCfg_add, hpart, + erw [show T = t + (T - t) from by omega, TM.runCfg_add, hpart, TM.runCfg_of_halted _ hhalt] · have : t = T := by omega rw [← this, hpart] rw [hrun] - simpa using heq + rw [dropChoice_choiceCfg] at heq; exact heq /-! ## The verdict is the path's verdict -/ diff --git a/Complexitylib/Classes/P/Cobham/Internal/ConsBit.lean b/Complexitylib/Classes/P/Cobham/Internal/ConsBit.lean index 0ccb9ecc..1b22e09b 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/ConsBit.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/ConsBit.lean @@ -122,7 +122,7 @@ private theorem consBitTM_copy_loop (b : Bool) (x : List Bool) : c.output.writeAndMove (readBackWrite c.output.read) (idleDir c.output.read) = c.output := by rw [writeAndMove_readBack c.output (by simp [houtput_blank]), - idleDir, if_neg (by simp [houtput_blank]), Tape.move] + idleDir, ite_eq_right (by simp [houtput_blank]), Tape.move] have hstep : (consBitTM b).step c = some c1 := by simp [TM.step, hstate, consBitTM, hread, c1] refine ⟨c1, .step hstep .zero, rfl, ?_⟩ @@ -196,7 +196,7 @@ theorem consBitTM_computesInTime (b : Bool) : simp [c2, c1, Tape.move_cells] have hc2_input_head : c2.input.head = 0 + 1 := by show (c1.input.move (idleDir c1.input.read)).head = 0 + 1 - rw [idleDir, if_neg hne] + rw [idleDir, ite_eq_right hne] simp [Tape.move, c1, Tape.init] have hc2_output : c2.output.HasBinaryPrefix (b :: x.take 0) := by have hbase : ((Tape.init []).move Dir3.right).HasBinaryPrefix [] := diff --git a/Complexitylib/Classes/P/Cobham/Internal/Encoding.lean b/Complexitylib/Classes/P/Cobham/Internal/Encoding.lean index 500272dc..0c6d82c6 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Encoding.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Encoding.lean @@ -609,7 +609,7 @@ theorem write_correctWrite {t : Tape} (s : Γ) (h : t.StartInvariant) : have hh : t.head = 0 := by by_contra hne exact h.read_ne_start (by omega) hr - rw [Tape.write, if_pos hh, Tape.write, if_pos hh] + rw [Tape.write, ite_eq_left hh, Tape.write, ite_eq_left hh] · rfl /-- Under the invariant, the corrected write agrees with cell `0` when the head @@ -617,7 +617,7 @@ is there — the hypothesis `tapeStepBlocks_eq` needs. -/ theorem correctWrite_at_zero {t : Tape} (s : Γ) (h : t.StartInvariant) (hh : t.head = 0) : correctWrite t s = t.cells t.head := by have hr : t.read = Γ.start := by rw [Tape.read, hh]; exact h.1 - rw [correctWrite, correctWriteSym, if_pos hr] + rw [correctWrite, correctWriteSym, ite_eq_left hr] show Γ.start = t.cells t.head rw [hh] exact h.1.symm @@ -724,7 +724,7 @@ theorem stepActs_eq_stepActsOf {k : ℕ} (tm : TM k) (c : Cfg k tm.Q) : theorem step_state_eq {k : ℕ} (tm : TM k) {c c' : Cfg k tm.Q} (h : tm.step c = some c') : c'.state = stepStateOf tm c.state (cfgReads c) := by have hne : ¬ c.state = tm.qhalt := fun hq => by simp [TM.step, hq] at h - rw [TM.step, if_neg hne] at h + rw [TM.step, ite_eq_right hne] at h injection h with h subst h rfl @@ -736,7 +736,7 @@ theorem cfgTapes_step {k : ℕ} (tm : TM k) {c c' : Cfg k tm.Q} (hwork : ∀ i, (c.work i).StartInvariant) : cfgTapes c' = tapesStep (stepActs tm c) (cfgTapes c) := by have hne : ¬ c.state = tm.qhalt := fun hq => by simp [TM.step, hq] at h - rw [TM.step, if_neg hne] at h + rw [TM.step, ite_eq_right hne] at h injection h with h subst h rw [cfgTapes, cfgTapes, stepActs, tapesStep] diff --git a/Complexitylib/Classes/P/Cobham/Internal/Extract.lean b/Complexitylib/Classes/P/Cobham/Internal/Extract.lean index 39011c32..12fd4879 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Extract.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Extract.lean @@ -136,10 +136,10 @@ theorem runTrue_length {z : List Bool} {n : ℕ} (htrue : ∀ i < n, bitOf z i = | succ m ih => rw [runTrue, List.length_append, ih] rcases Nat.lt_or_ge m n with hm | hm - · rw [if_pos ⟨by omega, htrue m hm⟩] + · rw [ite_eq_left ⟨by omega, htrue m hm⟩] simp only [List.length_cons, List.length_nil] omega - · rw [if_neg ?_] + · rw [ite_eq_right ?_] · simp only [List.length_nil] omega · rintro ⟨h1, h2⟩ @@ -190,7 +190,7 @@ theorem cellBitsFn {n : ℕ} (o : ℕ) {gr gz : (Fin n → List Bool) → List B simp; omega cases b <;> · rw [recNotation_cons] - simp only [cond_true, cond_false] + simp only [Bool.cond_true, Bool.cond_false] rw [cellStep_cons, ih, bitAt_eq, hlen, List.length_cons, cellBits] have hh : Cobham (cellStep o) := (appendFn (Cobham.proj 1) @@ -220,18 +220,18 @@ theorem runTrueFn {n : ℕ} {gr gz : (Fin n → List Bool) → List Bool} | cons b x ih => cases b <;> · rw [recNotation_cons] - simp only [cond_true, cond_false] + simp only [Bool.cond_true, Bool.cond_false] rw [runStep_cons, ih, bitAt_eq, List.length_cons, runTrue] congr 1 rcases Nat.lt_or_ge (runTrue (v 0) x.length).length x.length with hlt | hge - · rw [if_neg (by omega)] + · rw [ite_eq_right (by omega)] cases hd : x.drop (runTrue (v 0) x.length).length with | nil => rw [List.drop_eq_nil_iff] at hd; omega | cons c l => cases c <;> rfl · rw [List.drop_eq_nil_of_le hge] cases hb : bitOf (v 0) x.length - · rw [if_neg (by simp)]; rfl - · rw [if_pos ⟨hge, rfl⟩]; rfl + · rw [ite_eq_right (by simp)]; rfl + · rw [ite_eq_left ⟨hge, rfl⟩]; rfl have hh : Cobham runStep := (appendFn (Cobham.proj 1) (iteFn diff --git a/Complexitylib/Classes/P/Cobham/Internal/HeadFlag.lean b/Complexitylib/Classes/P/Cobham/Internal/HeadFlag.lean index d40d9856..25436557 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/HeadFlag.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/HeadFlag.lean @@ -124,7 +124,7 @@ theorem headFlagTM_computesInTime (target : Bool) : have hstep2 : (headFlagTM target).step c1 = some c2 := by simp [TM.step, headFlagTM, c1, c2, hri] refine ⟨c2, 2, le_rfl, .step hstep1 (.step hstep2 .zero), rfl, ?_⟩ - rw [headFlag, if_pos hb] + rw [headFlag, ite_eq_left hb] refine ⟨fun i hi => ?_, ?_⟩ · have hi0 : i = 0 := by simpa using hi subst hi0 @@ -149,7 +149,7 @@ theorem headFlagTM_computesInTime (target : Bool) : have hstep2 : (headFlagTM target).step c1 = some c2 := by simp [TM.step, headFlagTM, c1, c2, hri] refine ⟨c2, 2, le_rfl, .step hstep1 (.step hstep2 .zero), rfl, ?_⟩ - rw [headFlag, if_neg hb] + rw [headFlag, ite_eq_right hb] refine ⟨fun i hi => by simp at hi, ?_⟩ have hoc : c1.output.read = Γ.blank := by simp [c1, Tape.read, Tape.move, Tape.init] diff --git a/Complexitylib/Classes/P/Cobham/Internal/Iterate.lean b/Complexitylib/Classes/P/Cobham/Internal/Iterate.lean index f6b8dfc2..d1db1e37 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Iterate.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Iterate.lean @@ -217,15 +217,15 @@ def bookTapes (rfT junkT : Tape) (H : ℕ) : Fin (3 + (k + 2) + 0) → Tape := @[simp] theorem bookTapes_rf (rfT junkT : Tape) (H : ℕ) : bookTapes (k := k) rfT junkT H rfIdx = rfT := by - rw [bookTapes, if_pos rfl] + rw [bookTapes, ite_eq_left rfl] @[simp] theorem bookTapes_wf (rfT junkT : Tape) (H : ℕ) : bookTapes (k := k) rfT junkT H wfIdx = regTape H := by - rw [bookTapes, if_neg (fun h => rfIdx_ne_wfIdx h.symm), if_pos rfl] + rw [bookTapes, ite_eq_right (fun h => rfIdx_ne_wfIdx h.symm), ite_eq_left rfl] @[simp] theorem bookTapes_junk (rfT junkT : Tape) (H : ℕ) : bookTapes (k := k) rfT junkT H junkIdx = junkT := by - rw [bookTapes, if_neg junkIdx_ne_rfIdx, if_neg junkIdx_ne_wfIdx] + rw [bookTapes, ite_eq_right junkIdx_ne_rfIdx, ite_eq_right junkIdx_ne_wfIdx] theorem eq_bookTapes_of_not_middle {work : Fin (3 + (k + 2) + 0) → Tape} {rfT junkT : Tape} {H : ℕ} @@ -339,14 +339,14 @@ variable {M : TM k} {Y : ℕ → List Bool} {inp₀ junkT : Tape} {v H : ℕ} @[simp] theorem iterFamily_app (i : ℕ) (j : Fin (k + 2)) : iterFamily M Y inp₀ junkT v H i (appIdx j) = TM.applyPre M (Y i) inp₀ j := by rw [iterFamily] - rw [dif_pos (appIdx_middle j)] + rw [dite_eq_left (appIdx_middle j)] congr 1 exact placeWorkCoord_placeWorkIdx 3 0 j theorem iterFamily_book (i : ℕ) (j : Fin (3 + (k + 2) + 0)) (hj : ¬ placeWorkInMiddle 3 (k + 2) j) : iterFamily M Y inp₀ junkT v H i j = bookTapes (regTape v) junkT H j := by - rw [iterFamily, dif_neg hj] + rw [iterFamily, dite_eq_right hj] @[simp] theorem iterFamily_rf (i : ℕ) : iterFamily M Y inp₀ junkT v H i rfIdx = regTape v := by @@ -437,12 +437,12 @@ def emitStart (extras : Fin (3 + (k + 2) + 0) → Tape) : Fin (3 + (k + 2) + 0) theorem emitStart_middle (extras : Fin (3 + (k + 2) + 0) → Tape) (j : Fin (k + 2)) : emitStart extras (appIdx j) = parkedBlank := by - rw [emitStart, if_pos (appIdx_middle j)] + rw [emitStart, ite_eq_left (appIdx_middle j)] theorem emitStart_extra (extras : Fin (3 + (k + 2) + 0) → Tape) (i : Fin (3 + (k + 2) + 0)) (hi : ¬ placeWorkInMiddle 3 (k + 2) i) : emitStart extras i = extras i := by - rw [emitStart, if_neg hi] + rw [emitStart, ite_eq_right hi] /-- **The setup's emission phase.** From the bumped input holding `x` and an all-blank block, `pair [] x` lands on the result tape and the whole block stays @@ -471,13 +471,13 @@ theorem placedEmit_hoareTime (x : List Bool) (H : ℕ) (hH : x.length + 4 ≤ H) (placeWorkInMiddle 3 (k + 2)) (fun i => by by_cases hi : placeWorkInMiddle 3 (k + 2) i - · rw [emitStart, if_pos hi]; exact hblankSI - · rw [emitStart, if_neg hi]; exact hextraSI i hi) - (fun i hi => by rw [emitStart, if_pos hi, parkedBlank_head]) + · rw [emitStart, ite_eq_left hi]; exact hblankSI + · rw [emitStart, ite_eq_right hi]; exact hextraSI i hi) + (fun i hi => by rw [emitStart, ite_eq_left hi, parkedBlank_head]) (fun i hi j hj => by - rw [emitStart, if_pos hi] + rw [emitStart, ite_eq_left hi] show ((Tape.init ([] : List Γ)).move Dir3.right).cells j = Γ.blank - rw [Tape.move_cells, initNil_cells, if_neg (by omega)]) + rw [Tape.move_cells, initNil_cells, ite_eq_right (by omega)]) refine ((hconf.weaken_pre ?_).strengthen_post ?_).mono_bound (by simp only [TM.pairInputWorkTime, List.length_nil]; omega) · rintro inp work out ⟨rfl, rfl, rfl⟩ @@ -508,8 +508,8 @@ theorem parkedBlank_eq_regTape_zero : parkedBlank = regTape 0 := by show _ = regCells 0 j rw [regCells] by_cases hj : j = 0 - · rw [if_pos hj, if_pos hj] - · rw [if_neg hj, if_neg hj, if_neg (by omega)] + · rw [ite_eq_left hj, ite_eq_left hj] + · rw [ite_eq_right hj, ite_eq_right hj, ite_eq_right (by omega)] /-- The register value cap the padding polynomial's evaluation runs under. -/ def polyM (p : Polynomial ℕ) (n : ℕ) : ℕ := @@ -614,8 +614,8 @@ theorem iterSetup_hoareTime (p : Polynomial ℕ) (x : List Bool) (H : ℕ) Parked (emitStart (bookTapes (regTape x.length) (regTape H) H) i) := by intro i by_cases hi : placeWorkInMiddle 3 (k + 2) i - · rw [emitStart, if_pos hi]; exact parked_parkedBlank - · rw [emitStart, if_neg hi] + · rw [emitStart, ite_eq_left hi]; exact parked_parkedBlank + · rw [emitStart, ite_eq_right hi] exact ⟨bookTapes_head (parked_regTape _) (parked_regTape _) i hi, (bookTapes_startInvariant (startInvariant_regTape _) (startInvariant_regTape _) i hi).2⟩ @@ -697,19 +697,19 @@ theorem iterMain_hoareTime (M : TM k) {G : List Bool → List Bool} {T : ℕ → (teardownExtras v H) (fun i hi => by rcases not_middle_succ_cases i hi with h | h | h | h - · rw [h, teardownExtras, if_neg rfIdx_ne_resIdx, bookTapes_rf] + · rw [h, teardownExtras, ite_eq_right rfIdx_ne_resIdx, bookTapes_rf] exact startInvariant_regTape v - · rw [h, teardownExtras, if_neg wfIdx_ne_resIdx, bookTapes_wf]; exact hregSI - · rw [h, teardownExtras, if_neg junkIdx_ne_resIdx, bookTapes_junk]; exact hregSI - · rw [h, teardownExtras, if_pos rfl] + · rw [h, teardownExtras, ite_eq_right wfIdx_ne_resIdx, bookTapes_wf]; exact hregSI + · rw [h, teardownExtras, ite_eq_right junkIdx_ne_resIdx, bookTapes_junk]; exact hregSI + · rw [h, teardownExtras, ite_eq_left rfl] exact startInvariant_initNil.move Dir3.right) (fun i hi => by rcases not_middle_succ_cases i hi with h | h | h | h - · rw [h, teardownExtras, if_neg rfIdx_ne_resIdx, bookTapes_rf] + · rw [h, teardownExtras, ite_eq_right rfIdx_ne_resIdx, bookTapes_rf] exact (parked_regTape v).1 - · rw [h, teardownExtras, if_neg wfIdx_ne_resIdx, bookTapes_wf]; exact hregP.1 - · rw [h, teardownExtras, if_neg junkIdx_ne_resIdx, bookTapes_junk]; exact hregP.1 - · rw [h, teardownExtras, if_pos rfl]; exact parked_parkedBlank.1) + · rw [h, teardownExtras, ite_eq_right wfIdx_ne_resIdx, bookTapes_wf]; exact hregP.1 + · rw [h, teardownExtras, ite_eq_right junkIdx_ne_resIdx, bookTapes_junk]; exact hregP.1 + · rw [h, teardownExtras, ite_eq_left rfl]; exact parked_parkedBlank.1) -- the two seams are the identity: every tape is parked have hseam : ∀ (W : Fin (3 + (k + 2) + 0) → Tape), (∀ i, Parked (W i)) → ∀ (inp' : Tape) (out' : Tape), inp' = inp → out' = parkedBlank → @@ -748,11 +748,11 @@ theorem iterMain_hoareTime (M : TM k) {G : List Bool → List Bool} {T : ℕ → rw [iterFamily_app] exact congrFun (TM.applyPre_spec M (Y v) inp').1 i · rcases not_middle_succ_cases i hi with h | h | h | h - · rw [h, iterFamily_rf, teardownExtras, if_neg rfIdx_ne_resIdx, bookTapes_rf] - · rw [h, iterFamily_wf, teardownExtras, if_neg wfIdx_ne_resIdx, bookTapes_wf] - · rw [h, iterFamily_junk, teardownExtras, if_neg junkIdx_ne_resIdx, bookTapes_junk] + · rw [h, iterFamily_rf, teardownExtras, ite_eq_right rfIdx_ne_resIdx, bookTapes_rf] + · rw [h, iterFamily_wf, teardownExtras, ite_eq_right wfIdx_ne_resIdx, bookTapes_wf] + · rw [h, iterFamily_junk, teardownExtras, ite_eq_right junkIdx_ne_resIdx, bookTapes_junk] · rw [h, show (resIdx (k := k)) = appIdx (Fin.last (k + 1)) from rfl, iterFamily_app, - teardownExtras, if_pos (show appIdx (Fin.last (k + 1)) = resIdx from rfl), + teardownExtras, ite_eq_left (show appIdx (Fin.last (k + 1)) = resIdx from rfl), TM.applyPre, Fin.snoc_last] · rintro inp' work' out' ⟨hout, -⟩ exact hout diff --git a/Complexitylib/Classes/P/Cobham/Internal/IterateLayout.lean b/Complexitylib/Classes/P/Cobham/Internal/IterateLayout.lean index 33708829..be5d2ff2 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/IterateLayout.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/IterateLayout.lean @@ -356,7 +356,7 @@ theorem applyPre_eq (M : TM k) (x : List Bool) (inp₀ : Tape) (j : Fin (k + 2)) if j = Fin.castSucc (Fin.last k) then (Tape.init (x.map Γ.ofBool)).move Dir3.right else parkedBlank := by refine Fin.lastCases ?_ ?_ j - · rw [TM.applyPre, Fin.snoc_last, if_neg] + · rw [TM.applyPre, Fin.snoc_last, ite_eq_right] intro hc exact absurd (congrArg Fin.val hc) (by simp) · intro j' @@ -365,14 +365,14 @@ theorem applyPre_eq (M : TM k) (x : List Bool) (inp₀ : Tape) (j : Fin (k + 2)) rw [TM.retargetInputStartedCfg] dsimp only by_cases hj : j' = Fin.last k - · rw [hj, if_neg (by simp), if_pos rfl] + · rw [hj, ite_eq_right (by simp), ite_eq_left rfl] · have hlt : j'.val < k := by have := j'.isLt rcases Nat.lt_or_ge j'.val k with h | h · exact h · exact absurd (Fin.ext (show j'.val = (Fin.last k).val by rw [Fin.val_last]; omega)) hj - rw [if_pos hlt, if_neg (fun hc => hj (Fin.castSucc_injective (k + 1) hc))] + rw [ite_eq_left hlt, ite_eq_right (fun hc => hj (Fin.castSucc_injective (k + 1) hc))] rfl theorem resIdx_ne_vinIdx : resIdx (k := k) ≠ vinIdx := by @@ -435,7 +435,7 @@ theorem iterFinish_hoareTime (M : TM k) (H : ℕ) exact hblankSI have hW₀other : ∀ i, i ≠ resIdx → i ≠ vinIdx → Parked (W₀ i) := by intro i hir _; rw [hW₀]; dsimp only - rw [if_neg hir] + rw [ite_eq_right hir] split; · exact hrfP split; · exact hjunkP split; · exact hregP @@ -444,27 +444,30 @@ theorem iterFinish_hoareTime (M : TM k) (H : ℕ) have hW₀vin : W₀ vinIdx = parkedBlank := by rw [hW₀] dsimp only - rw [if_neg (fun h => resIdx_ne_vinIdx h.symm), if_neg (fun h => rfIdx_ne_appIdx _ h.symm), - if_neg (fun h => junkIdx_ne_appIdx _ h.symm), if_neg (fun h => wfIdx_ne_appIdx _ h.symm)] + rw [ite_eq_right (fun h => resIdx_ne_vinIdx h.symm), + ite_eq_right (fun h => rfIdx_ne_appIdx _ h.symm), + ite_eq_right (fun h => junkIdx_ne_appIdx _ h.symm), + ite_eq_right (fun h => wfIdx_ne_appIdx _ h.symm)] have hW₀app : ∀ j : Fin (k + 2), appIdx j ≠ resIdx → W₀ (appIdx j) = parkedBlank := by intro j hj rw [hW₀] dsimp only - rw [if_neg hj, if_neg (fun h => rfIdx_ne_appIdx _ h.symm), - if_neg (fun h => junkIdx_ne_appIdx _ h.symm), if_neg (fun h => wfIdx_ne_appIdx _ h.symm)] + rw [ite_eq_right hj, ite_eq_right (fun h => rfIdx_ne_appIdx _ h.symm), + ite_eq_right (fun h => junkIdx_ne_appIdx _ h.symm), + ite_eq_right (fun h => wfIdx_ne_appIdx _ h.symm)] have hW₀rf : W₀ rfIdx = rfT := by rw [hW₀] dsimp only - rw [if_neg rfIdx_ne_resIdx, if_pos rfl] + rw [ite_eq_right rfIdx_ne_resIdx, ite_eq_left rfl] have hW₀junk : W₀ junkIdx = junkT := by rw [hW₀] dsimp only - rw [if_neg junkIdx_ne_resIdx, if_neg junkIdx_ne_rfIdx, if_pos rfl] + rw [ite_eq_right junkIdx_ne_resIdx, ite_eq_right junkIdx_ne_rfIdx, ite_eq_left rfl] have hW₀wf : W₀ wfIdx = regTape H := by rw [hW₀] dsimp only - rw [if_neg wfIdx_ne_resIdx, if_neg (fun h => rfIdx_ne_wfIdx h.symm), - if_neg (fun h => junkIdx_ne_wfIdx h.symm), if_pos rfl] + rw [ite_eq_right wfIdx_ne_resIdx, ite_eq_right (fun h => rfIdx_ne_wfIdx h.symm), + ite_eq_right (fun h => junkIdx_ne_wfIdx h.symm), ite_eq_left rfl] -- the value tape produced by the copy, and the family after each phase set vinT : Tape := (Tape.init (x.map Γ.ofBool)).move Dir3.right with hvinT have hvinSI : Tape.StartInvariant vinT := (startInvariant_initOfBool x).move Dir3.right @@ -559,9 +562,9 @@ theorem iterFinish_hoareTime (M : TM k) (H : ℕ) hW₁other wfIdx wfIdx_ne_resIdx wfIdx_ne_vinIdx, hW₀wf] · rw [applyPre_eq] by_cases hj : j = Fin.castSucc (Fin.last k) - · rw [if_pos hj, hj, show appIdx (Fin.castSucc (Fin.last k)) = vinIdx from rfl, + · rw [ite_eq_left hj, hj, show appIdx (Fin.castSucc (Fin.last k)) = vinIdx from rfl, hW₂, Function.update_of_ne resIdx_ne_vinIdx.symm, hW₁vin] - · rw [if_neg hj] + · rw [ite_eq_right hj] by_cases hjl : j = Fin.last (k + 1) · rw [hjl, show appIdx (Fin.last (k + 1)) = resIdx from rfl, hW₂, Function.update_self] · have hjr : appIdx j ≠ resIdx := fun h => diff --git a/Complexitylib/Classes/P/Cobham/Internal/MulLen.lean b/Complexitylib/Classes/P/Cobham/Internal/MulLen.lean index 17b61e4b..4bcd4cae 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/MulLen.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/MulLen.lean @@ -228,7 +228,7 @@ def mulLenTM : TM 1 where /-- A content-preserving idle step on a tape whose head is off the left marker. -/ private theorem idle_eq {t : Tape} (h : t.read ≠ Γ.start) : t.writeAndMove (readBackWrite t.read) (idleDir t.read) = t := by - rw [writeAndMove_readBack t h, idleDir, if_neg h, Tape.move] + rw [writeAndMove_readBack t h, idleDir, ite_eq_right h, Tape.move] /-- The emit pass: from `emit`, with `m` marks on the work tape and the work head at cell `k + 1`, the machine writes one `false` for each of the `r` @@ -255,7 +255,7 @@ private theorem mulLenTM_emit_loop : have hwne : (c.work 0).read ≠ Γ.start := by rw [hwread]; decide have houtne : c.output.read ≠ Γ.start := by rw [hpre.read_blank]; decide have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] refine ⟨{ state := MulPhase.rew input := c.input work := c.work @@ -267,7 +267,7 @@ private theorem mulLenTM_emit_loop : have : i = 0 := Subsingleton.elim i 0 subst this exact idle_eq hwne - simp only [TM.step, hstate, mulLenTM, hwread, hinp_eq, reduceCtorEq, if_false] + simp only [TM.step, hstate, mulLenTM, hwread, hinp_eq, reduceCtorEq, ite_false] rw [hwork, idle_eq houtne] | succ r ih => intro k m hkm acc c hstate hcells hhead hinp hpre @@ -275,7 +275,7 @@ private theorem mulLenTM_emit_loop : rw [Tape.read, hcells, hhead]; exact regCells_one (by omega) (by omega) have hwne : (c.work 0).read ≠ Γ.start := by rw [hwread]; decide have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] set c1 : Cfg 1 mulLenTM.Q := { state := MulPhase.emit input := c.input @@ -288,19 +288,19 @@ private theorem mulLenTM_emit_loop : subst hi exact writeAndMove_readBack _ hwne _ have hstep : mulLenTM.step c = some c1 := by - simp only [TM.step, hstate, mulLenTM, hwread, hinp_eq, hc1, reduceCtorEq, if_false, + simp only [TM.step, hstate, mulLenTM, hwread, hinp_eq, hc1, reduceCtorEq, ite_false, reduceIte] rw [hwork] rfl obtain ⟨c', hreach, hst, hcl, hhd, hin, hout⟩ := ih (k + 1) m (by omega) (acc ++ [false]) c1 rfl - (by rw [hc1]; simpa using hcells) + (by rw [hc1]; simpa [Tape.move] using hcells) (by rw [hc1]; simp [Tape.move, hhead]) (by rw [hc1]; simpa using hinp) (by rw [hc1]; exact Tape.hasBinaryPrefix_write_bit false hpre) refine ⟨c', .step hstep hreach, hst, hcl, hhd, by rw [hin, hc1], ?_⟩ rw [List.append_assoc] at hout - simpa using hout + simpa [List.replicate_succ] using hout /-- The rewind pass: from `rew` with the work head at cell `h`, the machine walks back to the left-end marker and re-enters `outer` with the work head at cell one, @@ -325,14 +325,14 @@ private theorem mulLenTM_rew_loop : have hwread : (c.work 0).read = Γ.start := by rw [Tape.read, hcells, hhead]; rfl have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] have hwork : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ Dir3.right) = fun i => (c.work i).move Dir3.right := by funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi show ((c.work 0).write _).move Dir3.right = (c.work 0).move Dir3.right - rw [Tape.write, if_pos hhead] + rw [Tape.write, ite_eq_left hhead] refine ⟨{ state := MulPhase.outer input := c.input work := fun i => (c.work i).move Dir3.right @@ -340,14 +340,14 @@ private theorem mulLenTM_rew_loop : by simp [Tape.move, hhead], rfl, rfl⟩ refine .step ?_ .zero simp only [TM.step, hstate, mulLenTM, hwread, hinp_eq, reduceIte, reduceCtorEq, - if_false] + ite_false] rw [hwork, idle_eq hout] | succ h ih => intro m c hstate hcells hhead hinp hout have hwne : (c.work 0).read ≠ Γ.start := by rw [Tape.read, hcells, hhead]; exact regCells_ne_start (by omega) have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] set c1 : Cfg 1 mulLenTM.Q := { state := MulPhase.rew input := c.input @@ -358,11 +358,11 @@ private theorem mulLenTM_rew_loop : funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi - rw [moveLeftDir, if_neg hwne] + rw [moveLeftDir, ite_eq_right hwne] exact writeAndMove_readBack _ hwne _ have hstep : mulLenTM.step c = some c1 := by - simp only [TM.step, hstate, mulLenTM, hinp_eq, hc1, if_neg hwne, reduceCtorEq, - if_false] + simp only [TM.step, hstate, mulLenTM, hinp_eq, hc1, ite_eq_right hwne, reduceCtorEq, + ite_false] rw [hwork, idle_eq hout] obtain ⟨c', hreach, hst, hcl, hhd, hin, hou⟩ := ih m c1 rfl (by rw [hc1]; simpa [Tape.move_cells] using hcells) @@ -393,7 +393,7 @@ private theorem mulLenTM_outer_loop : rw [Tape.read, hcells, hhead]; exact regCells_ne_start (by omega) have houtne : c.output.read ≠ Γ.start := by rw [hpre.read_blank]; decide have hinp_eq : c.input.move (idleDir Γ.blank) = c.input := by - rw [idleDir, if_neg (by decide), Tape.move] + rw [idleDir, ite_eq_right (by decide), Tape.move] have hwork : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ (idleDir ((c.work i).read))) = c.work := by funext i @@ -406,7 +406,7 @@ private theorem mulLenTM_outer_loop : output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero simp only [TM.step, hstate, mulLenTM, hread, hinp_eq, reduceIte, reduceCtorEq, - if_false] + ite_false] rw [hwork, idle_eq houtne] | cons b B ih => intro m acc c hstate hcells hhead hsuf hpre @@ -427,7 +427,7 @@ private theorem mulLenTM_outer_loop : work := c.work output := c.output } with hc1 have hstep : mulLenTM.step c = some c1 := by - simp only [TM.step, hstate, mulLenTM, hnb, hc1, reduceCtorEq, if_false] + simp only [TM.step, hstate, mulLenTM, hnb, hc1, reduceCtorEq, ite_false] rw [hwork, idle_eq houtne] have hsuf1 : c1.input.HasBinarySuffix B := hsuf.move_right_cons obtain ⟨c2, hreach2, hst2, hcl2, hhd2, hin2, hout2⟩ := @@ -483,13 +483,13 @@ private theorem mulLenTM_scan_loop : exact idle_eq hwne have hread : c.input.read = Γ.blank := hsuf.read_nil have hinp_eq : c.input.move (idleDir Γ.blank) = c.input := by - rw [idleDir, if_neg (by decide), Tape.move] + rw [idleDir, ite_eq_right (by decide), Tape.move] refine ⟨{ state := MulPhase.done input := c.input work := c.work output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero - simp only [TM.step, hstate, mulLenTM, hread, hinp_eq, reduceCtorEq, if_false] + simp only [TM.step, hstate, mulLenTM, hread, hinp_eq, reduceCtorEq, ite_false] rw [hwork, idle_eq houtne] | succ N ih => intro w k hN c hstate hcells hhead hsuf hpre @@ -503,9 +503,9 @@ private theorem mulLenTM_scan_loop : subst hi exact idle_eq hwne have hidleB : ∀ t : Tape, t.move (idleDir Γ.blank) = t := by - intro t; rw [idleDir, if_neg (by decide)]; rfl + intro t; rw [idleDir, ite_eq_right (by decide)]; rfl have hidleZ : ∀ t : Tape, t.move (idleDir Γ.zero) = t := by - intro t; rw [idleDir, if_neg (by decide)]; rfl + intro t; rw [idleDir, ite_eq_right (by decide)]; rfl -- The one-step transition out of `scanA` on a payload bit. have hstepA : ∀ b : Bool, c.input.read = Γ.ofBool b → @@ -516,8 +516,8 @@ private theorem mulLenTM_scan_loop : output := c.output } := by intro b hread cases b <;> - · simp only [TM.step, hstate, mulLenTM, hread, Γ.ofBool, reduceCtorEq, if_false, - cond_true, cond_false] + · simp only [TM.step, hstate, mulLenTM, hread, Γ.ofBool, reduceCtorEq, ite_false, + Bool.cond_true, Bool.cond_false] rw [hwork, idle_eq houtne] match w with | [] => @@ -527,7 +527,7 @@ private theorem mulLenTM_scan_loop : work := c.work output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero - simp only [TM.step, hstate, mulLenTM, hread, hidleB, reduceCtorEq, if_false] + simp only [TM.step, hstate, mulLenTM, hread, hidleB, reduceCtorEq, ite_false] rw [hwork, idle_eq houtne] | [b] => -- One payload symbol then end of input: the block framing is broken. @@ -540,8 +540,8 @@ private theorem mulLenTM_scan_loop : simpa [mulAux_singleton] using hpre⟩ refine .step (hstepA b hsuf.read_cons) (.step ?_ .zero) cases b <;> - · simp only [TM.step, mulLenTM, hread1, hidleB, reduceCtorEq, if_false, - cond_true, cond_false] + · simp only [TM.step, mulLenTM, hread1, hidleB, reduceCtorEq, ite_false, + Bool.cond_true, Bool.cond_false] rw [hwork, idle_eq houtne] | true :: false :: z => -- A broken doubling: halt with empty output. @@ -554,8 +554,8 @@ private theorem mulLenTM_scan_loop : output := c.output }, 2, by omega, ?_, rfl, by simpa [mulAux_broken] using hpre⟩ refine .step (hstepA true hsuf.read_cons) (.step ?_ .zero) - simp only [TM.step, mulLenTM, hread1, hidleZ, reduceCtorEq, if_false, - cond_true] + simp only [TM.step, mulLenTM, hread1, hidleZ, reduceCtorEq, ite_false, + Bool.cond_true] rw [hwork, idle_eq houtne] | false :: true :: z => -- The separator: rewind the work tape and run the outer loop over `z`. @@ -574,7 +574,7 @@ private theorem mulLenTM_scan_loop : work := c.work output := c.output } with hc2 have hstep2 : mulLenTM.step c1 = some c2 := by - simp only [TM.step, hc1, hc2, mulLenTM, hread1, reduceCtorEq, if_false] + simp only [TM.step, hc1, hc2, mulLenTM, hread1, reduceCtorEq, ite_false] rw [hwork, idle_eq houtne] have hsuf2 : c2.input.HasBinarySuffix z := hsuf1.move_right_cons obtain ⟨c3, hreach3, hst3, hcl3, hhd3, hin3, hou3⟩ := @@ -615,12 +615,12 @@ private theorem mulLenTM_scan_loop : have hwmark : (fun i => (c.work i).writeAndMove (Γw.one).toΓ Dir3.right) = fun i => ((c.work i).write Γ.one).move Dir3.right := rfl have hstep2 : mulLenTM.step c1 = some c2 := by - simp only [TM.step, hc1, hc2, mulLenTM, hread1, reduceCtorEq, if_false] + simp only [TM.step, hc1, hc2, mulLenTM, hread1, reduceCtorEq, ite_false] rw [hwmark, idle_eq houtne] have hcells2 : (c2.work 0).cells = regCells (k + 1) := by rw [hc2] show (((c.work 0).write Γ.one).move Dir3.right).cells = _ - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhead]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhead]; omega)] show Function.update (c.work 0).cells ((c.work 0).head) Γ.one = _ rw [hcells, hhead, regCells_update_succ] have hhead2 : (c2.work 0).head = k + 1 + 1 := by @@ -652,12 +652,12 @@ private theorem mulLenTM_scan_loop : have hwmark : (fun i => (c.work i).writeAndMove (Γw.one).toΓ Dir3.right) = fun i => ((c.work i).write Γ.one).move Dir3.right := rfl have hstep2 : mulLenTM.step c1 = some c2 := by - simp only [TM.step, hc1, hc2, mulLenTM, hread1, reduceCtorEq, if_false] + simp only [TM.step, hc1, hc2, mulLenTM, hread1, reduceCtorEq, ite_false] rw [hwmark, idle_eq houtne] have hcells2 : (c2.work 0).cells = regCells (k + 1) := by rw [hc2] show (((c.work 0).write Γ.one).move Dir3.right).cells = _ - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhead]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhead]; omega)] show Function.update (c.work 0).cells ((c.work 0).head) Γ.one = _ rw [hcells, hhead, regCells_update_succ] have hhead2 : (c2.work 0).head = k + 1 + 1 := by diff --git a/Complexitylib/Classes/P/Cobham/Internal/Reverse.lean b/Complexitylib/Classes/P/Cobham/Internal/Reverse.lean index 5f90786f..2a309fd6 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Reverse.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Reverse.lean @@ -107,7 +107,7 @@ def reverseTM : TM 1 where /-- A content-preserving idle step on a tape whose head is off the left marker. -/ private theorem rev_idle_eq {t : Tape} (h : t.read ≠ Γ.start) : t.writeAndMove (readBackWrite t.read) (idleDir t.read) = t := by - rw [writeAndMove_readBack t h, idleDir, if_neg h, Tape.move] + rw [writeAndMove_readBack t h, idleDir, ite_eq_right h, Tape.move] /-- The copy phase: from `copy` with the input cursor on `w` and the work tape holding `acc`, the machine appends `w` to the work tape and enters `emit` with @@ -137,20 +137,20 @@ private theorem reverseTM_copy_loop : exact hwork.2.2 acc.length le_rfl have hwne : (c.work 0).read ≠ Γ.start := by rw [hwread]; decide have hinp_eq : c.input.move (idleDir Γ.blank) = c.input := by - rw [idleDir, if_neg (by decide), Tape.move] + rw [idleDir, ite_eq_right (by decide), Tape.move] have hwmove : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ (moveLeftDir ((c.work i).read))) = fun i => (c.work i).move Dir3.left := by funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi - rw [moveLeftDir, if_neg hwne] + rw [moveLeftDir, ite_eq_right hwne] exact writeAndMove_readBack _ hwne _ refine ⟨{ state := RevPhase.emit input := c.input work := fun i => (c.work i).move Dir3.left output := c.output }, ?_, rfl, ?_, ?_, ?_, by rw [hread]; decide, by simpa⟩ · refine .step ?_ .zero - simp only [TM.step, hstate, reverseTM, hread, hinp_eq, reduceCtorEq, if_false] + simp only [TM.step, hstate, reverseTM, hread, hinp_eq, reduceCtorEq, ite_false] rw [hwmove, rev_idle_eq houtne] · have hc : (c.work 0).HasBinaryContent acc := hwork.2 simpa using hc.move Dir3.left @@ -171,7 +171,7 @@ private theorem reverseTM_copy_loop : have hstep : reverseTM.step c = some c1 := by cases b <;> · simp only [TM.step, hstate, reverseTM, hread, Γ.ofBool, hc1, - reduceCtorEq, if_false] + reduceCtorEq, ite_false] rw [rev_idle_eq houtne] rfl obtain ⟨c', hreach, hst, hcont, hcz, hhd, hinp, hpre⟩ := @@ -206,7 +206,7 @@ private theorem reverseTM_emit_loop : have hwne1 : ¬ (c.work 0).read = Γ.one := by rw [hwread]; decide have houtne : c.output.read ≠ Γ.start := by rw [hout.read_blank]; decide have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] refine ⟨{ state := RevPhase.done input := c.input work := fun i => (c.work i).move Dir3.right @@ -217,10 +217,10 @@ private theorem reverseTM_emit_loop : funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi - rw [Tape.writeAndMove, Tape.write, if_pos (by omega : (c.work 0).head = 0), - idleDir, if_pos hwread] + rw [Tape.writeAndMove, Tape.write, ite_eq_left (by omega : (c.work 0).head = 0), + idleDir, ite_eq_left hwread] simp only [TM.step, hstate, reverseTM, hinp_eq, hwne0, hwne1, reduceCtorEq, - if_false] + ite_false] rw [hwork, rev_idle_eq houtne] | succ j ih => intro bits acc c hstate hcont hw0 hhead hjb hinp hout @@ -230,13 +230,13 @@ private theorem reverseTM_emit_loop : have hwne : (c.work 0).read ≠ Γ.start := by rw [hwread]; exact Γ.ofBool_ne_start _ have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] have hwmove : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ (moveLeftDir ((c.work i).read))) = fun i => (c.work i).move Dir3.left := by funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi - rw [moveLeftDir, if_neg hwne] + rw [moveLeftDir, ite_eq_right hwne] exact writeAndMove_readBack _ hwne _ set c1 : Cfg 1 reverseTM.Q := { state := RevPhase.emit @@ -247,12 +247,12 @@ private theorem reverseTM_emit_loop : rcases hb : bits[j]'hjlt with _ | _ · have h0 : (c.work 0).read = Γ.zero := by rw [hwread, hb]; rfl simp only [TM.step, hstate, reverseTM, hinp_eq, h0, hc1, hb, Γ.ofBool, - reduceCtorEq, if_false, reduceIte] + reduceCtorEq, ite_false, reduceIte] rw [hwmove] rfl · have h1 : (c.work 0).read = Γ.one := by rw [hwread, hb]; rfl simp only [TM.step, hstate, reverseTM, hinp_eq, h1, hc1, hb, Γ.ofBool, - reduceCtorEq, if_false, reduceIte] + reduceCtorEq, ite_false, reduceIte] rw [hwmove] rfl obtain ⟨c', hreach, hhalt, hfin⟩ := diff --git a/Complexitylib/Classes/P/Cobham/Internal/Simulate.lean b/Complexitylib/Classes/P/Cobham/Internal/Simulate.lean index 6b26fa70..e0c816ee 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/Simulate.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/Simulate.lean @@ -44,7 +44,7 @@ theorem step_startInvariant (tm : TM k) {c c' : Cfg k tm.Q} (h : tm.step c = som (hout : c.output.StartInvariant) : c'.input.StartInvariant ∧ (∀ i, (c'.work i).StartInvariant) ∧ c'.output.StartInvariant := by - rw [TM.step, if_neg (TM.state_ne_qhalt_of_step h)] at h + rw [TM.step, ite_eq_right (TM.state_ne_qhalt_of_step h)] at h injection h with h subst h exact ⟨hin.move _, fun i => (hwork i).writeAndMove _ _, hout.writeAndMove _ _⟩ @@ -53,7 +53,7 @@ theorem step_startInvariant (tm : TM k) {c c' : Cfg k tm.Q} (h : tm.step c = som theorem step_head_le (tm : TM k) {c c' : Cfg k tm.Q} (h : tm.step c = some c') : c'.input.head ≤ c.input.head + 1 ∧ (∀ i, (c'.work i).head ≤ (c.work i).head + 1) ∧ c'.output.head ≤ c.output.head + 1 := by - rw [TM.step, if_neg (TM.state_ne_qhalt_of_step h)] at h + rw [TM.step, ite_eq_right (TM.state_ne_qhalt_of_step h)] at h injection h with h subst h exact ⟨Tape.head_move_le _ _, fun i => Tape.head_writeAndMove_le _ _ _, diff --git a/Complexitylib/Classes/P/Cobham/Internal/SndBlock.lean b/Complexitylib/Classes/P/Cobham/Internal/SndBlock.lean index ae07fa8c..f0fcdf29 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/SndBlock.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/SndBlock.lean @@ -132,7 +132,7 @@ private theorem sndBlockTM_emit_loop : .step (by simp [TM.step, hstate, sndBlockTM, hread]) .zero, rfl, ?_⟩ rw [show c.output.writeAndMove (readBackWrite c.output.read) (idleDir c.output.read) = c.output from by - rw [writeAndMove_readBack c.output houtne, idleDir, if_neg houtne, Tape.move]] + rw [writeAndMove_readBack c.output houtne, idleDir, ite_eq_right houtne, Tape.move]] simpa using hpre | cons bit y ih => intro acc c hstate hsuf hpre @@ -185,8 +185,9 @@ private theorem sndBlockTM_scan_loop : .step (by simp [TM.step, hstate, sndBlockTM, hread]) .zero, rfl, ?_⟩ rw [show c.output.writeAndMove (readBackWrite c.output.read) (idleDir c.output.read) = c.output from by - rw [writeAndMove_readBack c.output houtne, idleDir, if_neg houtne, Tape.move]] - simpa [pairSnd] using hpre.hasOutput + rw [writeAndMove_readBack c.output houtne, idleDir, ite_eq_right houtne, Tape.move]] + simp [pairSnd] + exact hpre.hasOutput | succ fuel ih => intro w hw c hstate hsuf hpre -- Halting helper for the malformed / end-of-input branches. @@ -204,8 +205,9 @@ private theorem sndBlockTM_scan_loop : .step (by simp [TM.step, hstate, sndBlockTM, hread]) .zero, rfl, ?_⟩ rw [show c.output.writeAndMove (readBackWrite c.output.read) (idleDir c.output.read) = c.output from by - rw [writeAndMove_readBack c.output houtne, idleDir, if_neg houtne, Tape.move]] - simpa [pairSnd] using hpre.hasOutput + rw [writeAndMove_readBack c.output houtne, idleDir, ite_eq_right houtne, Tape.move]] + simp [pairSnd] + exact hpre.hasOutput | [false] => -- scanA reads false → scanBfalse; next reads blank → done. have hread : c.input.read = Γ.ofBool false := hsuf.read_cons @@ -235,8 +237,10 @@ private theorem sndBlockTM_scan_loop : .step hstep (.step (by simp [TM.step, sndBlockTM, hread1, c1]) .zero), rfl, ?_⟩ rw [show c1.output.writeAndMove (readBackWrite c1.output.read) (idleDir c1.output.read) = c1.output from by - rw [writeAndMove_readBack c1.output houtne1, idleDir, if_neg houtne1, Tape.move]] - simpa [pairSnd] using hpre1.hasOutput + rw [writeAndMove_readBack c1.output houtne1, idleDir, ite_eq_right houtne1, + Tape.move]] + simp [pairSnd] + exact hpre1.hasOutput | [true] => have hread : c.input.read = Γ.ofBool true := hsuf.read_cons let c1 : Cfg 0 sndBlockTM.Q := @@ -265,8 +269,10 @@ private theorem sndBlockTM_scan_loop : .step hstep (.step (by simp [TM.step, sndBlockTM, hread1, c1]) .zero), rfl, ?_⟩ rw [show c1.output.writeAndMove (readBackWrite c1.output.read) (idleDir c1.output.read) = c1.output from by - rw [writeAndMove_readBack c1.output houtne1, idleDir, if_neg houtne1, Tape.move]] - simpa [pairSnd] using hpre1.hasOutput + rw [writeAndMove_readBack c1.output houtne1, idleDir, ite_eq_right houtne1, + Tape.move]] + simp [pairSnd] + exact hpre1.hasOutput | false :: true :: y => -- separator: scanA false → scanBfalse → (reads true) → emit; copy y. have hreadA : c.input.read = Γ.ofBool false := hsuf.read_cons @@ -420,7 +426,8 @@ private theorem sndBlockTM_scan_loop : rfl, ?_⟩ rw [show c1.output.writeAndMove (readBackWrite c1.output.read) (idleDir c1.output.read) = c1.output from by - rw [writeAndMove_readBack c1.output houtne1, idleDir, if_neg houtne1, Tape.move]] + rw [writeAndMove_readBack c1.output houtne1, idleDir, ite_eq_right houtne1, + Tape.move]] have : pairSnd (true :: false :: rest) = [] := by simp [pairSnd, unpair?] rw [this]; simpa using hpre1.hasOutput diff --git a/Complexitylib/Classes/P/Cobham/Internal/StepAlgebra.lean b/Complexitylib/Classes/P/Cobham/Internal/StepAlgebra.lean index 1b45b08a..2ee9b946 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/StepAlgebra.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/StepAlgebra.lean @@ -287,13 +287,13 @@ noncomputable def stepBranch {k : ℕ} (tm : TM k) (R : List Bool) theorem stepBranch_halt {k : ℕ} (tm : TM k) (R : List Bool) {p : tm.Q × (Fin (k + 2) → Γ)} (h : p.1 = tm.qhalt) (z : List Bool) : - stepBranch tm R p z = z := if_pos h + stepBranch tm R p z = z := ite_eq_left h theorem stepBranch_step {k : ℕ} (tm : TM k) (R : List Bool) {p : tm.Q × (Fin (k + 2) → Γ)} (h : p.1 ≠ tm.qhalt) (z : List Bool) : stepBranch tm R p z = branchFn R (stateCode (stepStateOf tm p.1 p.2)) (stepActsOf tm p.1 p.2) z := - if_neg h + ite_eq_right h /-- **One machine step, on encodings.** The table dispatches on the key read out of the encoding and applies that key's branch. -/ @@ -537,7 +537,7 @@ theorem rewindFn_eq {W : ℕ} (t : Tape) (hinv : t.StartInvariant) (hW : t.head by_cases h0 : t.head = 0 · have hread : t.read = Γ.start := by rw [Tape.read, h0]; exact hinv.1 have hmove : t.move Dir3.left = t := move_left_of_head_zero h0 - rw [rewindFn, matchPrefix_symCode t hW, if_pos hread.symm, caseBit₀_cons, cond_true, + rw [rewindFn, matchPrefix_symCode t hW, ite_eq_left hread.symm, caseBit₀_cons, Bool.cond_true, hmove] · have hread : t.read ≠ Γ.start := hinv.read_ne_start (by omega) have hstep : ∀ s : Γ, s = t.read → @@ -615,7 +615,7 @@ theorem encodeBitsFn {n : ℕ} {g : (Fin n → List Bool) → List Bool} (h : Co | cons b x ih => cases b <;> · rw [recNotation_cons] - simp only [cond_true, cond_false] + simp only [Bool.cond_true, Bool.cond_false] rw [encStep_cons, ih, encodeBits_cons] have hs : ∀ b : Bool, Cobham (encStep b) := fun b => (appendFn (Cobham.const (symCode (Γ.ofBool b))) (Cobham.proj 1)).of_eq fun _ => rfl @@ -677,7 +677,7 @@ private theorem cellsCode_of_bits (x : List Bool) : | cons b x ih => intro t i hcells rw [List.length_cons, cellsCode_succ_left, encodeBits_cons, - show t.cells i = Γ.ofBool b from by simpa using hcells 0 (by simp)] + show t.cells i = Γ.ofBool b from hcells 0 (by simp)] congr 1 exact ih t (i + 1) fun j hj => by have := hcells (j + 1) (by rw [List.length_cons]; omega) diff --git a/Complexitylib/Classes/P/Cobham/Internal/StringOps.lean b/Complexitylib/Classes/P/Cobham/Internal/StringOps.lean index 44551105..6e41bb27 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/StringOps.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/StringOps.lean @@ -235,7 +235,7 @@ private theorem recNotation_xor (a b : List Bool) : | cons β x ih => cases β <;> · rw [recNotation_cons, xorSuffix] - simp only [cond_false, cond_true, xorStep, Fin.cons_zero, Fin.cons_one, id] + simp only [Bool.cond_false, Bool.cond_true, xorStep, Fin.cons_zero, Fin.cons_one, id] rw [ih] rfl diff --git a/Complexitylib/Classes/P/Cobham/Internal/TakeLen.lean b/Complexitylib/Classes/P/Cobham/Internal/TakeLen.lean index e769f95a..3dc211c9 100644 --- a/Complexitylib/Classes/P/Cobham/Internal/TakeLen.lean +++ b/Complexitylib/Classes/P/Cobham/Internal/TakeLen.lean @@ -211,7 +211,7 @@ def takeLenTM : TM 1 where /-- A content-preserving idle step on a tape whose head is off the left marker. -/ private theorem take_idle_eq {t : Tape} (h : t.read ≠ Γ.start) : t.writeAndMove (readBackWrite t.read) (idleDir t.read) = t := by - rw [writeAndMove_readBack t h, idleDir, if_neg h, Tape.move] + rw [writeAndMove_readBack t h, idleDir, ite_eq_right h, Tape.move] /-- The copy phase: with `r` marks left under and to the right of the work head, the machine emits the first `r` symbols of the remaining input. -/ @@ -235,7 +235,7 @@ private theorem takeLenTM_copy_loop : have hwne1 : ¬ (c.work 0).read = Γ.one := by rw [hwread]; decide have houtne : c.output.read ≠ Γ.start := by rw [hpre.read_blank]; decide have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hsuf.read_ne_start, Tape.move] + rw [idleDir, ite_eq_right hsuf.read_ne_start, Tape.move] have hwork : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ (idleDir ((c.work i).read))) = c.work := by funext i @@ -247,7 +247,7 @@ private theorem takeLenTM_copy_loop : work := c.work output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero - simp only [TM.step, hstate, takeLenTM, hwne1, hinp_eq, reduceCtorEq, if_false] + simp only [TM.step, hstate, takeLenTM, hwne1, hinp_eq, reduceCtorEq, ite_false] rw [hwork, take_idle_eq houtne] | succ r ih => intro h m hsum hh y acc c hstate hcells hhead hsuf hpre @@ -256,7 +256,7 @@ private theorem takeLenTM_copy_loop : have hwne : (c.work 0).read ≠ Γ.start := by rw [hwread]; decide have houtne : c.output.read ≠ Γ.start := by rw [hpre.read_blank]; decide have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hsuf.read_ne_start, Tape.move] + rw [idleDir, ite_eq_right hsuf.read_ne_start, Tape.move] have hworkIdle : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ (idleDir ((c.work i).read))) = c.work := by funext i @@ -270,7 +270,7 @@ private theorem takeLenTM_copy_loop : subst hi exact writeAndMove_readBack _ hwne _ have hidleB : ∀ t : Tape, t.move (idleDir Γ.blank) = t := by - intro t; rw [idleDir, if_neg (by decide)]; rfl + intro t; rw [idleDir, ite_eq_right (by decide)]; rfl match y with | [] => have hread : c.input.read = Γ.blank := hsuf.read_nil @@ -280,7 +280,7 @@ private theorem takeLenTM_copy_loop : output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero simp only [TM.step, hstate, takeLenTM, hwread, hread, hidleB, reduceCtorEq, - if_false, reduceIte] + ite_false, reduceIte] rw [hworkIdle, take_idle_eq houtne] | b :: y => have hread : c.input.read = Γ.ofBool b := hsuf.read_cons @@ -292,12 +292,12 @@ private theorem takeLenTM_copy_loop : have hstep : takeLenTM.step c = some c1 := by cases b <;> · simp only [TM.step, hstate, takeLenTM, hwread, hread, hc1, Γ.ofBool, - reduceCtorEq, if_false, reduceIte] + reduceCtorEq, ite_false, reduceIte] rw [hworkR] rfl obtain ⟨c', t, ht, hreach, hhalt, hfin⟩ := ih (h + 1) m (by omega) (by omega) y (acc ++ [b]) c1 rfl - (by rw [hc1]; simpa using hcells) + (by rw [hc1]; simpa [Tape.move] using hcells) (by rw [hc1]; simp [Tape.move, hhead]) (by rw [hc1]; exact hsuf.move_right_cons) (by rw [hc1]; exact Tape.hasBinaryPrefix_write_bit b hpre) @@ -326,14 +326,14 @@ private theorem takeLenTM_rew_loop : have hwread : (c.work 0).read = Γ.start := by rw [Tape.read, hcells, hhead]; rfl have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] have hwork : (fun i => (c.work i).writeAndMove (readBackWrite ((c.work i).read)).toΓ Dir3.right) = fun i => (c.work i).move Dir3.right := by funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi show ((c.work 0).write _).move Dir3.right = (c.work 0).move Dir3.right - rw [Tape.write, if_pos hhead] + rw [Tape.write, ite_eq_left hhead] refine ⟨{ state := TakePhase.copy input := c.input work := fun i => (c.work i).move Dir3.right @@ -341,14 +341,14 @@ private theorem takeLenTM_rew_loop : by simp [Tape.move, hhead], rfl, rfl⟩ refine .step ?_ .zero simp only [TM.step, hstate, takeLenTM, hwread, hinp_eq, reduceIte, reduceCtorEq, - if_false] + ite_false] rw [hwork, take_idle_eq hout] | succ h ih => intro m c hstate hcells hhead hinp hout have hwne : (c.work 0).read ≠ Γ.start := by rw [Tape.read, hcells, hhead]; exact regCells_ne_start (by omega) have hinp_eq : c.input.move (idleDir c.input.read) = c.input := by - rw [idleDir, if_neg hinp, Tape.move] + rw [idleDir, ite_eq_right hinp, Tape.move] set c1 : Cfg 1 takeLenTM.Q := { state := TakePhase.rew input := c.input @@ -359,11 +359,11 @@ private theorem takeLenTM_rew_loop : funext i have hi : i = 0 := Subsingleton.elim i 0 subst hi - rw [moveLeftDir, if_neg hwne] + rw [moveLeftDir, ite_eq_right hwne] exact writeAndMove_readBack _ hwne _ have hstep : takeLenTM.step c = some c1 := by - simp only [TM.step, hstate, takeLenTM, hinp_eq, hc1, if_neg hwne, reduceCtorEq, - if_false] + simp only [TM.step, hstate, takeLenTM, hinp_eq, hc1, ite_eq_right hwne, reduceCtorEq, + ite_false] rw [hwork, take_idle_eq hout] obtain ⟨c', hreach, hst, hcl, hhd, hin, hou⟩ := ih m c1 rfl (by rw [hc1]; simpa [Tape.move_cells] using hcells) @@ -401,13 +401,13 @@ private theorem takeLenTM_scan_loop : exact take_idle_eq hwne have hread : c.input.read = Γ.blank := hsuf.read_nil have hidleB : ∀ t : Tape, t.move (idleDir Γ.blank) = t := by - intro t; rw [idleDir, if_neg (by decide)]; rfl + intro t; rw [idleDir, ite_eq_right (by decide)]; rfl refine ⟨{ state := TakePhase.done input := c.input work := c.work output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero - simp only [TM.step, hstate, takeLenTM, hread, hidleB, reduceCtorEq, if_false] + simp only [TM.step, hstate, takeLenTM, hread, hidleB, reduceCtorEq, ite_false] rw [hwork, take_idle_eq houtne] | succ N ih => intro w k hN c hstate hcells hhead hsuf hpre @@ -421,9 +421,9 @@ private theorem takeLenTM_scan_loop : subst hi exact take_idle_eq hwne have hidleB : ∀ t : Tape, t.move (idleDir Γ.blank) = t := by - intro t; rw [idleDir, if_neg (by decide)]; rfl + intro t; rw [idleDir, ite_eq_right (by decide)]; rfl have hidleZ : ∀ t : Tape, t.move (idleDir Γ.zero) = t := by - intro t; rw [idleDir, if_neg (by decide)]; rfl + intro t; rw [idleDir, ite_eq_right (by decide)]; rfl have hstepA : ∀ b : Bool, c.input.read = Γ.ofBool b → takeLenTM.step c = some @@ -433,8 +433,8 @@ private theorem takeLenTM_scan_loop : output := c.output } := by intro b hread cases b <;> - · simp only [TM.step, hstate, takeLenTM, hread, Γ.ofBool, reduceCtorEq, if_false, - cond_true, cond_false] + · simp only [TM.step, hstate, takeLenTM, hread, Γ.ofBool, reduceCtorEq, ite_false, + Bool.cond_true, Bool.cond_false] rw [hwork, take_idle_eq houtne] match w with | [] => @@ -444,7 +444,7 @@ private theorem takeLenTM_scan_loop : work := c.work output := c.output }, 1, by omega, ?_, rfl, by simpa using hpre⟩ refine .step ?_ .zero - simp only [TM.step, hstate, takeLenTM, hread, hidleB, reduceCtorEq, if_false] + simp only [TM.step, hstate, takeLenTM, hread, hidleB, reduceCtorEq, ite_false] rw [hwork, take_idle_eq houtne] | [b] => have hsuf1 : (c.input.move Dir3.right).HasBinarySuffix [] := hsuf.move_right_cons @@ -456,8 +456,8 @@ private theorem takeLenTM_scan_loop : simpa [takeLenAux_singleton] using hpre⟩ refine .step (hstepA b hsuf.read_cons) (.step ?_ .zero) cases b <;> - · simp only [TM.step, takeLenTM, hread1, hidleB, reduceCtorEq, if_false, - cond_true, cond_false] + · simp only [TM.step, takeLenTM, hread1, hidleB, reduceCtorEq, ite_false, + Bool.cond_true, Bool.cond_false] rw [hwork, take_idle_eq houtne] | true :: false :: z => have hsuf1 : (c.input.move Dir3.right).HasBinarySuffix (false :: z) := @@ -469,7 +469,7 @@ private theorem takeLenTM_scan_loop : output := c.output }, 2, by omega, ?_, rfl, by simpa [takeLenAux_broken] using hpre⟩ refine .step (hstepA true hsuf.read_cons) (.step ?_ .zero) - simp only [TM.step, takeLenTM, hread1, hidleZ, reduceCtorEq, if_false, cond_true] + simp only [TM.step, takeLenTM, hread1, hidleZ, reduceCtorEq, ite_false, Bool.cond_true] rw [hwork, take_idle_eq houtne] | false :: true :: z => have hsuf1 : (c.input.move Dir3.right).HasBinarySuffix (true :: z) := @@ -487,7 +487,7 @@ private theorem takeLenTM_scan_loop : work := c.work output := c.output } with hc2 have hstep2 : takeLenTM.step c1 = some c2 := by - simp only [TM.step, hc1, hc2, takeLenTM, hread1, reduceCtorEq, if_false] + simp only [TM.step, hc1, hc2, takeLenTM, hread1, reduceCtorEq, ite_false] rw [hwork, take_idle_eq houtne] have hsuf2 : c2.input.HasBinarySuffix z := hsuf1.move_right_cons obtain ⟨c3, hreach3, hst3, hcl3, hhd3, hin3, hou3⟩ := @@ -520,12 +520,12 @@ private theorem takeLenTM_scan_loop : have hwmark : (fun i => (c.work i).writeAndMove (Γw.one).toΓ Dir3.right) = fun i => ((c.work i).write Γ.one).move Dir3.right := rfl have hstep2 : takeLenTM.step c1 = some c2 := by - simp only [TM.step, hc1, hc2, takeLenTM, hread1, reduceCtorEq, if_false] + simp only [TM.step, hc1, hc2, takeLenTM, hread1, reduceCtorEq, ite_false] rw [hwmark, take_idle_eq houtne] have hcells2 : (c2.work 0).cells = regCells (k + 1) := by rw [hc2] show (((c.work 0).write Γ.one).move Dir3.right).cells = _ - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhead]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhead]; omega)] show Function.update (c.work 0).cells ((c.work 0).head) Γ.one = _ rw [hcells, hhead, regCells_update_succ] have hhead2 : (c2.work 0).head = k + 1 + 1 := by @@ -555,12 +555,12 @@ private theorem takeLenTM_scan_loop : have hwmark : (fun i => (c.work i).writeAndMove (Γw.one).toΓ Dir3.right) = fun i => ((c.work i).write Γ.one).move Dir3.right := rfl have hstep2 : takeLenTM.step c1 = some c2 := by - simp only [TM.step, hc1, hc2, takeLenTM, hread1, reduceCtorEq, if_false] + simp only [TM.step, hc1, hc2, takeLenTM, hread1, reduceCtorEq, ite_false] rw [hwmark, take_idle_eq houtne] have hcells2 : (c2.work 0).cells = regCells (k + 1) := by rw [hc2] show (((c.work 0).write Γ.one).move Dir3.right).cells = _ - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhead]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhead]; omega)] show Function.update (c.work 0).cells ((c.work 0).head) Γ.one = _ rw [hcells, hhead, regCells_update_succ] have hhead2 : (c2.work 0).head = k + 1 + 1 := by diff --git a/Complexitylib/Classes/P/Cobham/Validation.lean b/Complexitylib/Classes/P/Cobham/Validation.lean index 1c82489e..4c263a46 100644 --- a/Complexitylib/Classes/P/Cobham/Validation.lean +++ b/Complexitylib/Classes/P/Cobham/Validation.lean @@ -49,7 +49,11 @@ private def sampleVec : Fin 2 → List Bool := ![[false], [true, false]] private inductive Q where | go | halt - deriving DecidableEq, Fintype + deriving DecidableEq + +private instance : Fintype Q where + elems := ⟨↑([Q.go, Q.halt] : List Q), by decide⟩ + complete := fun x => by cases x <;> decide private def guardedDir (read : Γ) (otherwise : Dir3) : Dir3 := if read = Γ.start then .right else otherwise @@ -117,7 +121,11 @@ example : private inductive HaltQ where | halt - deriving DecidableEq, Fintype + deriving DecidableEq + +private instance : Fintype HaltQ where + elems := ⟨↑([HaltQ.halt] : List HaltQ), by decide⟩ + complete := fun x => by cases x; decide private def haltedTM : TM 0 where Q := HaltQ diff --git a/Complexitylib/Classes/P/FinsetDomain/Internal.lean b/Complexitylib/Classes/P/FinsetDomain/Internal.lean index 52d947e6..d41d1a79 100644 --- a/Complexitylib/Classes/P/FinsetDomain/Internal.lean +++ b/Complexitylib/Classes/P/FinsetDomain/Internal.lean @@ -247,11 +247,12 @@ private theorem lookup_read_bit_step (p : List Bool) (b : Bool) rw [hstate]; exact readState_ne_haltState g S p by_cases hp : p ∈ S.prefixes · cases b <;> - simp [TM.step, lookupTM, hstate, hread, readState, haltState, dif_pos hp, Γ.ofBool] + simp [TM.step, lookupTM, hstate, hread, readState, haltState, dite_eq_left hp, Γ.ofBool] · have hp' : p ++ [b] ∉ S.prefixes := fun h => hp (Finset.mem_prefixes_of_prefix (List.prefix_append p [b]) h) cases b <;> - simp [TM.step, lookupTM, hstate, hread, readState, haltState, dif_neg hp, dif_neg hp', + simp [TM.step, lookupTM, hstate, hread, readState, haltState, dite_eq_right hp, + dite_eq_right hp', Γ.ofBool] /-- Writing back the (blank) symbol under an idle output head keeps the output @@ -331,9 +332,9 @@ private theorem lookup_initial_step (x : List Bool) : readState_ne_haltState g S [] have hstep : (lookupTM g S).step ((lookupTM g S).initCfg x) = some c0 := by by_cases h : ([] : List Bool) ∈ S.prefixes - · simp only [TM.step, hc0, lookupTM, readState, dif_pos h] + · simp only [TM.step, hc0, lookupTM, readState, dite_eq_left h] exact congrArg some (Cfg.ext rfl rfl (Subsingleton.elim _ _) rfl) - · simp only [TM.step, hc0, lookupTM, readState, dif_neg h] + · simp only [TM.step, hc0, lookupTM, readState, dite_eq_right h] exact congrArg some (Cfg.ext rfl rfl (Subsingleton.elim _ _) rfl) refine ⟨c0, hstep, rfl, ?_, ?_, ?_⟩ · rw [hc0]; simp [Tape.move_cells] @@ -360,10 +361,11 @@ private theorem lookup_handoff_step (inp : List Bool) (c : Cfg 0 (lookupTM g S). (idleDir c.output.read) } with hc1 have hstep : (lookupTM g S).step c = some c1 := by by_cases hp : inp ∈ S.prefixes - · simp [TM.step, lookupTM, hstate, hread, readState, writeState, haltState, dif_pos hp, hc1] + · simp [TM.step, lookupTM, hstate, hread, readState, writeState, haltState, dite_eq_left hp, + hc1] · have hpS : inp ∉ S := fun h => hp (Finset.mem_prefixes_self h) - simp [TM.step, lookupTM, hstate, hread, readState, writeState, haltState, dif_neg hp, - if_neg hpS, hc1] + simp [TM.step, lookupTM, hstate, hread, readState, writeState, haltState, dite_eq_right hp, + ite_eq_right hpS, hc1] refine ⟨c1, hstep, by rw [hc1], ?_⟩ rw [hc1] exact hasBinaryPrefix_idle houtput diff --git a/Complexitylib/Classes/P/PairWithInput/Internal.lean b/Complexitylib/Classes/P/PairWithInput/Internal.lean index d71804c0..b315d60b 100644 --- a/Complexitylib/Classes/P/PairWithInput/Internal.lean +++ b/Complexitylib/Classes/P/PairWithInput/Internal.lean @@ -26,7 +26,11 @@ theorem mem_FP_pairWithInput_internal {f : List Bool → List Bool} Polynomial.C 5 * p + Polynomial.X + Polynomial.C 12 apply mem_FP_iff_computesInTime_polynomial_internal.mpr refine ⟨TM.pairWithInputTapeCount k, TM.pairWithInputTM tm, q, ?_⟩ - simpa [q, TM.pairWithInputTime] using - TM.pairWithInputTM_computesInTime hcomp + have h := TM.pairWithInputTM_computesInTime hcomp + have hfun : TM.pairWithInputTime p.eval = q.eval := by + funext x + simp [q, TM.pairWithInputTime] + rw [hfun] at h + exact h end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/AlgCSPModel.lean b/Complexitylib/Classes/PCP/Internal/AlgCSPModel.lean index 0cdc9bd5..cae7e4c1 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgCSPModel.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgCSPModel.lean @@ -118,13 +118,13 @@ theorem answers_posVal (A : AlgCSP) (x π : List Bool) (e : ℕ) rw [List.getElem_map, List.getElem_map, List.getElem_range] by_cases hlow : j < A.width · rw [List.getElem_append_left (by rw [hb0]; exact hlow), getElem_blockOf h0 hlow, - AlgCSP.posVal, if_pos hlow] + AlgCSP.posVal, ite_eq_left hlow] simp [hlow] · have hge : (blockOf A.width π (A.vert false x e)).length ≤ j := by rw [hb0]; omega rw [List.getElem_append_right hge] simp only [hb0] - rw [getElem_blockOf h1 (by omega), AlgCSP.posVal, if_neg hlow] + rw [getElem_blockOf h1 (by omega), AlgCSP.posVal, ite_eq_right hlow] simp [hlow] /-! ### Padding a proof -/ @@ -178,7 +178,7 @@ variable {A : AlgCSP} {α : Type} [Inhabited α] {G : List Bool → ConstraintGr {enc : α → List Bool} {dec : List Bool → α} /-- The proof an assignment writes. -/ -def assignProof (enc : α → List Bool) [Inhabited α] +def assignProof (enc : α → List Bool) (n : ℕ) (a : Fin n → α) : List Bool := proofOf n (fun v => if h : v < n then enc (a ⟨v, h⟩) else enc default) @@ -194,8 +194,7 @@ theorem blockOf_assignProof (hM : A.Models G enc dec) {n : ℕ} (a : Fin n → (f := fun v => if h : v < n then enc (a ⟨v, h⟩) else enc default) (fun i => by by_cases h : i < n <;> simp [h, hM.length_enc]) n v hv rw [assignProof, this] - simp only - rw [dif_pos hv] + rw [dite_eq_left hv] /-- **Completeness transfers.** A satisfying assignment writes a proof the verifier accepts on every edge. -/ diff --git a/Complexitylib/Classes/PCP/Internal/AlgEdge.lean b/Complexitylib/Classes/PCP/Internal/AlgEdge.lean index 3cb4e72b..b9fa7999 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgEdge.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgEdge.lean @@ -61,12 +61,12 @@ theorem posBlk_eq (cardB cardN cardNN cardD k b c : ℕ) (cardV kind block cube = List.replicate (m + n) true := fun m n => (List.replicate_add m n true).symm rw [posBlk, RegCSP.posNum] by_cases h0 : k = 0 - · rw [ifEqLen_pos (by simp [hk, h0]), if_pos h0, marks_eq, length_mulC, hb, hc, happ] - rw [ifEqLen_neg (by simp [hk, h0]), if_neg h0] + · rw [ifEqLen_pos (by simp [hk, h0]), ite_eq_left h0, marks_eq, length_mulC, hb, hc, happ] + rw [ifEqLen_neg (by simp [hk, h0]), ite_eq_right h0] by_cases h1 : k = 1 - · rw [ifEqLen_pos (by simp [hk, h1]), if_pos h1, marks_eq, marks_eq, length_mulC, + · rw [ifEqLen_pos (by simp [hk, h1]), ite_eq_left h1, marks_eq, marks_eq, length_mulC, length_mulC, hb, hc, happ, happ] - rw [ifEqLen_neg (by simp [hk, h1]), if_neg h1, marks_eq, marks_eq, marks_eq, + rw [ifEqLen_neg (by simp [hk, h1]), ite_eq_right h1, marks_eq, marks_eq, marks_eq, length_mulC, length_mulC, length_mulC, hb, hc, happ, happ, happ] congr 2 ring @@ -154,6 +154,9 @@ theorem blockBlk_mem_FP (F : FinBase) (pol : Polynomial ℕ) (r : Round) : (ifEqLen_mem_FP readFn_mem_FP (constFn_mem_FP _) hrot (testFn_mem_FP r)) /-- **The block is the one the read asks for.** -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem blockBlk_eq {β : Type} [Fintype β] [DecidableEq β] [Nonempty β] {R : RegCSP β} [NumEnc R.graph.V] [NumEnc R.graph.D] (F : FinBase) (pol : Polynomial ℕ) (r : Round) {w : List Bool} (p : R.Dart) (i : ReadIdx) @@ -398,7 +401,8 @@ theorem stepFn_eq (F : FinBase) (pol : Polynomial ℕ) (hd : 1 < F.deg) obtain ⟨htest, hvert, hdart, hrand, hread⟩ := blocks_eq r hDpos (by omega) (encGraph G) (NumEnc.enc p.1) (NumEnc.enc p.2) (NumEnc.enc z) (NumEnc.enc i) hblt hclt hilt - rw [edgeRule, tailBlk_eq posF r G (pairFst_pair _ _) htest hrand, + simp only [edgeRule] + rw [tailBlk_eq posF r G (pairFst_pair _ _) htest hrand, RegCSP.tailNum_split' (cZ := r.cZ) _ _ _ _ _ _ hrZ hclt hilt, hposF] rw [codeFn_eq' (B := Dinur.bits (F.toFamily hd) r.T) r hd G hq hdeg hP hC (by omega) p z i (by rw [hrZ, NumEnc.card_eq_fintype_card, card_cube]) hpc hpe dflt diff --git a/Complexitylib/Classes/PCP/Internal/AlgFamily.lean b/Complexitylib/Classes/PCP/Internal/AlgFamily.lean index 824bf827..0f7a5bfc 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgFamily.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgFamily.lean @@ -204,11 +204,11 @@ theorem famRotFn_eq (hd : 1 < F.deg) (n v i : ℕ) (hn : 0 < n) rw [famRotFn, famRotVal] simp only [pairFst_pair, pairSnd_pair] by_cases h1 : i < F.wid hd n * F.fitD - · rw [if_pos h1, ifLtLen_pos (by + · rw [ite_eq_left h1, ifLtLen_pos (by rw [List.length_replicate, length_mulLen, hm, List.length_replicate] exact h1)] by_cases h2 : v + i / F.fitD * n < F.fitN hd n - · rw [if_pos h2, ifLtLen_pos (by rw [hlift, hN]; exact h2)] + · rw [ite_eq_left h2, ifLtLen_pos (by rw [hlift, hN]; exact h2)] have hidx : (mulLen (List.replicate v true ++ mulLen (divC F.fitD (List.replicate i true)) (List.replicate n true)) (List.replicate F.fitD true) ++ modC F.fitD (List.replicate i true)).length @@ -237,11 +237,11 @@ theorem famRotFn_eq (hd : 1 < F.deg) (n v i : ℕ) (hn : 0 < n) length_mulC, divFn2_eq (by rw [hrep]; exact hn), List.length_replicate, hrep, List.length_replicate] exact congrArg (List.replicate · true) (by ring) - · rw [if_neg h2, ifLtLen_neg (by rw [hlift, hN]; exact h2)] + · rw [ite_eq_right h2, ifLtLen_neg (by rw [hlift, hN]; exact h2)] refine congrArg₂ pair ?_ ?_ · rw [marks_eq, List.length_replicate] · rw [marks_eq, List.length_replicate] - · rw [if_neg h1, ifLtLen_neg (by + · rw [ite_eq_right h1, ifLtLen_neg (by rw [List.length_replicate, length_mulLen, hm, List.length_replicate] exact h1)] refine congrArg₂ pair ?_ ?_ diff --git a/Complexitylib/Classes/PCP/Internal/AlgGapCSP.lean b/Complexitylib/Classes/PCP/Internal/AlgGapCSP.lean index 732a27c6..b8d194fe 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgGapCSP.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgGapCSP.lean @@ -118,11 +118,11 @@ noncomputable def gapAlg (hgap : gapAll F hd E padU ∈ FP) : AlgCSP where cases b · refine mem_FP_of_eq (marks_mem_FP (gTailFn_mem_FP Cobham.sndBlock_mem_FP hg)) fun w => ?_ - simp only [cond_false] + simp only [Bool.cond_false] rw [marks_eq, length_recFst_sndBlock] · refine mem_FP_of_eq (marks_mem_FP (gHeadFn_mem_FP Cobham.sndBlock_mem_FP hg)) fun w => ?_ - simp only [cond_true] + simp only [Bool.cond_true] rw [marks_eq, length_recSnd_sndBlock] ok := gapOk F hd E padU ok_mem := gapOk_mem_P F hd E padU hgap @@ -135,11 +135,11 @@ noncomputable def gapAlg (hgap : gapAll F hd E padU ∈ FP) : AlgCSP where theorem vert_gapAlg_false (hgap : gapAll F hd E padU ∈ FP) (x : List Bool) (e : ℕ) : (gapAlg F hd E padU hgap).vert false x e = gTail (gapAll F hd E padU x) e := by - simp only [gapAlg, cond_false] + simp only [gapAlg, Bool.cond_false] theorem vert_gapAlg_true (hgap : gapAll F hd E padU ∈ FP) (x : List Bool) (e : ℕ) : (gapAlg F hd E padU hgap).vert true x e = gHead (gapAll F hd E padU x) e := by - simp only [gapAlg, cond_true] + simp only [gapAlg, Bool.cond_true] @[simp] theorem ok_gapAlg (hgap : gapAll F hd E padU ∈ FP) : (gapAlg F hd E padU hgap).ok = gapOk F hd E padU := rfl diff --git a/Complexitylib/Classes/PCP/Internal/AlgGraph.lean b/Complexitylib/Classes/PCP/Internal/AlgGraph.lean index e35d0011..67782e5e 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgGraph.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgGraph.lean @@ -58,7 +58,7 @@ theorem codeOfRel_lt (f : α → α → Bool) : codeOfRel f < Fintype.card (α → α → Bool) := Fin.isLt _ @[simp] theorem relOfCode_codeOfRel (f : α → α → Bool) : relOfCode α (codeOfRel f) = f := by - rw [relOfCode, dif_pos (codeOfRel_lt f)] + rw [relOfCode, dite_eq_left (codeOfRel_lt f)] simp only [codeOfRel, Fin.eta, Equiv.symm_apply_apply] /-! ### The encoding -/ @@ -142,7 +142,7 @@ theorem length_encGraph_le (G : ConstraintGraph α) : + G.numEdges * (8 * G.numVerts + 4 * Fintype.card (α → α → Bool) + 10) := by have hsum : ((edgeRecs G).map fun a => (DataEncode.bitstringEncode a).length).sum ≤ G.numEdges * (8 * G.numVerts + 4 * Fintype.card (α → α → Bool) + 10) := by - refine le_trans (List.sum_le_card_nsmul _ + refine le_trans (List.sum_le_length_nsmul _ (8 * G.numVerts + 4 * Fintype.card (α → α → Bool) + 10) ?_) ?_ · intro x hx obtain ⟨e, he, rfl⟩ := List.mem_map.mp hx diff --git a/Complexitylib/Classes/PCP/Internal/AlgInit.lean b/Complexitylib/Classes/PCP/Internal/AlgInit.lean index 29d24ba2..ec9e9d99 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgInit.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgInit.lean @@ -179,7 +179,7 @@ theorem baseTailU_val (hE : ∀ x, E x = (Φ x).encode) (h3 : ∀ x, CNF.Is3CNF rw [numEdges_baseCSP] at he rw [baseTailU_eq E hE h3] show _ = (clauseVertex (Φ x) (edgeClause e)).val - rw [clauseVertex, edgeClause, dif_pos (by rw [numVerts]; omega)] + rw [clauseVertex, edgeClause, dite_eq_left (by rw [numVerts]; omega)] theorem baseHeadU_val (hE : ∀ x, E x = (Φ x).encode) (h3 : ∀ x, CNF.Is3CNF (Φ x)) (x : List Bool) (e : ℕ) (he : e < (baseCSP (Φ x)).numEdges) : @@ -196,7 +196,7 @@ theorem baseHeadU_val (hE : ∀ x, E x = (Φ x).encode) (h3 : ∀ x, CNF.Is3CNF exact var_le_maxVar (Φ x) hj hp rw [baseHeadU_eq E hE h3 x he] show _ = (varVertex (Φ x) (litOf (Φ x) (edgeClause e) (edgePos e)).var).val - rw [varVertex, edgeClause, edgePos, dif_pos (by rw [numVerts]; omega)] + rw [varVertex, edgeClause, edgePos, dite_eq_left (by rw [numVerts]; omega)] /-! ### The graph -/ diff --git a/Complexitylib/Classes/PCP/Internal/AlgKey.lean b/Complexitylib/Classes/PCP/Internal/AlgKey.lean index eeb9e81f..a629cac0 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgKey.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgKey.lean @@ -153,7 +153,7 @@ theorem length_digitSum_eq_enc {X : Type} [NumEnc X] {T : ℕ} (s : Fin T → X) show _ = ∑ j ∈ Finset.range T, NumEnc.encAt s j * NumEnc.card X ^ j refine Finset.sum_congr rfl fun j hj => ?_ rw [Finset.mem_range] at hj - rw [h j hj, NumEnc.encAt, dif_pos hj] + rw [h j hj, NumEnc.encAt, dite_eq_left hj] /-- The data a killed walk actually shows. -/ noncomputable def stepKeyOf (G : ConstraintGraph α) (E : ExpanderFamily) {q T : ℕ} @@ -182,14 +182,20 @@ theorem relOfKey_stepKeyOf (G : ConstraintGraph α) (E : ExpanderFamily) {q T : = ((G.preprocess E).killedPow q T hq).rel v x := by rw [rel_killedPow_eq_preRelOfSteps, relOfKey] simp only [stepKeyOf, StepKey.dart, StepKey.par, StepKey.code, StepKey.rev, StepKey.coins, - StepKey.len, RegGraph.kLen, RegGraph.kWalk, Fin.is_lt, dif_pos] - congr 1 - funext i - congr 1 - funext j - rw [RegGraph.killedRev, RegGraph.extWalk] - dsimp only - rw [dif_pos (by have := j.isLt; omega)] + StepKey.len, RegGraph.kLen, RegGraph.kWalk] + congr 1 <;> funext i <;> + first + | (congr 1 + funext j + rw [RegGraph.killedRev, RegGraph.extWalk] + dsimp only + rw [dite_eq_left (by have := j.isLt; omega)]) + | (congr 1 + have hi : (i : ℕ) < stopAt x.2 := by have := i.isLt; omega + simp [hi] + exact Fin.ext rfl) + | (have hi : (i : ℕ) < stopAt x.2 := by have := i.isLt; omega + simp [hi]) set_option synthInstance.maxSize 400 in omit [Nonempty α] in @@ -224,8 +230,8 @@ theorem cubeOfKey_eq (G : ConstraintGraph α) (E : ExpanderFamily) {q T : ℕ} {B : ℕ} (z : Cube (ROf B)) (i : ReadIdx) (encβ : (PreWalk E T → α) → Cube B) : cubeOfKey encβ (stepKeyOf G E v x B z i) = ((G.preprocess E).killedPow q T hq).cubeNum encβ (v, x) z i := by - rw [cubeOfKey, satSetOfKey_stepKeyOf G E hq v x z i encβ, - RegCSP.cubeNum_eq_cubeOfSet] + rw [cubeOfKey, satSetOfKey_stepKeyOf G E hq v x z i encβ] + erw [RegCSP.cubeNum_eq_cubeOfSet] rfl omit [Nonempty α] in @@ -237,8 +243,8 @@ theorem codeOfKey_eq (G : ConstraintGraph α) (E : ExpanderFamily) {q T : ℕ} codeOfKey encβ (stepKeyOf G E v x B z i) = codeOfRel (MultiTest.relOfCheck ((((G.preprocess E).killedPow q T hq).compose encβ).check (v, x) z) i) := by - rw [codeOfKey, satSetOfKey_stepKeyOf G E hq v x z i encβ, - RegCSP.check_eq_checkOfSet] + rw [codeOfKey, satSetOfKey_stepKeyOf G E hq v x z i encβ] + erw [RegCSP.check_eq_checkOfSet] rfl end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/AlgKeyFn.lean b/Complexitylib/Classes/PCP/Internal/AlgKeyFn.lean index 8db5abdc..ed54d238 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgKeyFn.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgKeyFn.lean @@ -273,8 +273,8 @@ theorem walkFn_enc (hd : 1 < F.deg) (G : ConstraintGraph α) {T q : ℕ} (NumEnc.enc x.1 / G.preDeg (F.toFamily hd) ^ k) % G.preDeg (F.toFamily hd) = NumEnc.enc ((G.preprocess (F.toFamily hd)).graph.kWalk x ⟨k, hk⟩) := by intro k hk - rw [G.digit_enc (F.toFamily hd) x.1 hpos k (lt_of_lt_of_le hk hle), RegGraph.kWalk, - RegGraph.preWalk] + rw [G.digit_enc (F.toFamily hd) x.1 hpos k (lt_of_lt_of_le hk hle)] + simp only [RegGraph.kWalk, RegGraph.preWalk] refine (walkFn_eq F pol hd G _ _ hv hpc hpe j).trans ?_ exact congrArg (fun n => List.replicate n true) (G.walkNum_eq (F.toFamily hd) v ((G.preprocess (F.toFamily hd)).graph.kWalk x) @@ -327,13 +327,13 @@ theorem parBlk_eq (hd : 1 < F.deg) (G : ConstraintGraph α) (hq : 0 < r.q) show _ = NumEnc.enc (StepKey.par _ _) rw [stepKeyOf] simp only [StepKey.par] - rw [dif_pos hjk] + rw [dite_eq_left hjk] rfl · rw [ifLtLen_neg (by simpa using hjk), List.length_nil] show _ = NumEnc.enc (StepKey.par _ _) rw [stepKeyOf] simp only [StepKey.par] - rw [dif_neg hjk] + rw [dite_eq_right hjk] rfl omit [Fintype α] [DecidableEq α] in @@ -343,9 +343,9 @@ theorem enc_halfEdge_div_two (G : ConstraintGraph α) (p : G.HalfEdge) : rw [ConstraintGraph.enc_halfEdge, ConstraintGraph.halfCode] rw [hcode] by_cases h : p.2 = true - · rw [if_pos h] + · rw [ite_eq_left h] omega - · rw [if_neg h] + · rw [ite_eq_right h] omega variable {F pol} in @@ -402,7 +402,7 @@ theorem codeBlk_eq (hd : 1 < F.deg) (G : ConstraintGraph α) (hq : 0 < r.q) show _ = NumEnc.enc (StepKey.code _ _) rw [stepKeyOf] simp only [StepKey.code] - rw [dif_pos hjk] + rw [dite_eq_left hjk] have hfin : (⟨NumEnc.enc ((G.preprocess (F.toFamily hd)).graph.walkAt ((G.preprocess (F.toFamily hd)).graph.kLen x) v ((G.preprocess (F.toFamily hd)).graph.kWalk x) j) / 2, hidx⟩ : Fin G.numEdges) @@ -416,7 +416,7 @@ theorem codeBlk_eq (hd : 1 < F.deg) (G : ConstraintGraph α) (hq : 0 < r.q) show _ = NumEnc.enc (StepKey.code _ _) rw [stepKeyOf] simp only [StepKey.code] - rw [dif_neg hjk] + rw [dite_eq_right hjk] rfl variable {F pol} in diff --git a/Complexitylib/Classes/PCP/Internal/AlgKilled.lean b/Complexitylib/Classes/PCP/Internal/AlgKilled.lean index 4e8db05d..c157386b 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgKilled.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgKilled.lean @@ -221,9 +221,9 @@ theorem stopFromNum_eq_findIdx (q c : ℕ) : ∀ (n i : ℕ), stopFromNum q c i intro i rw [stopFromNum, List.finRange_succ, List.findIdx_cons, findIdx_map] by_cases h : (c / q ^ i) % q = 0 - · rw [if_pos h] + · rw [ite_eq_left h] simp [h] - · rw [if_neg h, ih (i + 1)] + · rw [ite_eq_right h, ih (i + 1)] have hcond : ((c / q ^ (i + (0 : Fin (n + 1)).val)) % q == 0) = false := by simpa using h rw [hcond] @@ -234,7 +234,7 @@ theorem stopFromNum_eq_findIdx (q c : ℕ) : ∀ (n i : ℕ), stopFromNum q c i refine findIdx_congr fun x _ => ?_ rw [Fin.val_succ, show i + (x.val + 1) = i + 1 + x.val by omega] rw [hbody] - simp only [cond_false] + simp only [Bool.false_eq_true, ite_false] omega theorem stopAtNum_eq_stopFromNum (T q c : ℕ) : stopAtNum T q c = stopFromNum q c 0 T := by @@ -274,8 +274,8 @@ theorem stopFn_eq {q : ℕ} (hq : 0 < q) {co : List Bool → List Bool} {z : Lis List.length_replicate] rw [stopFn, hdig, stopFromNum] by_cases h : (c / q ^ i) % q = 0 - · rw [if_pos h, ifEqLen_pos (by simp [h])] - · rw [if_neg h, ifEqLen_neg (by simpa using h), ih (i + 1)] + · rw [ite_eq_left h, ifEqLen_pos (by simp [h])] + · rw [ite_eq_right h, ifEqLen_neg (by simpa using h), ih (i + 1)] /-! ### The dart the walk comes back by -/ @@ -373,9 +373,9 @@ theorem length_revSum (hd : 1 < F.deg) (G : ConstraintGraph α) (v s k : ℕ) congr 1 congr 1 by_cases h : n < k - · rw [if_pos h, if_pos h, backFn_eq hd G v s (k - 1 - n) hv hpc hpe, + · rw [ite_eq_left h, ite_eq_left h, backFn_eq hd G v s (k - 1 - n) hv hpc hpe, List.length_replicate] - · rw [if_neg h, if_neg h, pairSnd_pair, pairSnd_pair, + · rw [ite_eq_right h, ite_eq_right h, pairSnd_pair, pairSnd_pair, divC_eq (Nat.pow_pos hPpos), List.length_replicate, modC_eq hPpos] simp diff --git a/Complexitylib/Classes/PCP/Internal/AlgLevel.lean b/Complexitylib/Classes/PCP/Internal/AlgLevel.lean index 22b2be52..0c75e6e2 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgLevel.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgLevel.lean @@ -88,13 +88,13 @@ theorem levelStep_apply (d k s : ℕ) (Z : List Bool) : simp only [List.length_append] omega by_cases h : s < 2 * n - · rw [if_pos h, ifLtLen_pos (by rw [List.length_replicate, hlen]; exact h), + · rw [ite_eq_left h, ifLtLen_pos (by rw [List.length_replicate, hlen]; exact h), marks_eq, length_mulC, List.length_replicate, ← List.replicate_succ'] congr 2 refine List.take_of_length_le ?_ rw [List.length_replicate, List.length_append, List.length_replicate, length_mulC, ← hn] nlinarith [h] - · rw [if_neg h, ifLtLen_neg (by rw [List.length_replicate, hlen]; exact h)] + · rw [ite_eq_right h, ifLtLen_neg (by rw [List.length_replicate, hlen]; exact h)] /-- **The loop's model runs the loop.** -/ theorem levelStep_iterate (d : ℕ) (Z : List Bool) : @@ -109,8 +109,8 @@ theorem levelStep_iterate (d : ℕ) (Z : List Bool) : intro k s rw [Function.iterate_succ_apply', ih k s, levelStep_apply, levelAfter] by_cases h : (levelAfter d Z.length j (k, s)).2 < 2 * Z.length - · rw [if_pos h, if_pos h] - · rw [if_neg h, if_neg h] + · rw [ite_eq_left h, ite_eq_left h] + · rw [ite_eq_right h, ite_eq_right h] /-! ### What the loop settles on -/ @@ -127,7 +127,7 @@ theorem levelAfter_of_lt (d n : ℕ) : have hlt : d ^ (j + 1) < 2 * n := by have := h j (by omega) omega - rw [if_pos hlt] + rw [ite_eq_left hlt] refine Prod.ext rfl ?_ show d ^ j * d * d = d ^ (j + 1 + 1) rw [pow_succ, pow_succ] @@ -140,7 +140,7 @@ theorem levelAfter_stable (d n : ℕ) (p : ℕ × ℕ) (j : ℕ) (h : 2 * n ≤ | zero => rfl | succ i ih => have hji : j + (i + 1) = (j + i) + 1 := by omega - rw [hji, levelAfter, ih, if_neg (by omega)] + rw [hji, levelAfter, ih, ite_eq_right (by omega)] /-- The loop never overshoots by more than a factor of `d`. -/ theorem levelAfter_snd_le (d n : ℕ) : @@ -151,10 +151,10 @@ theorem levelAfter_snd_le (d n : ℕ) : | succ j ih => rw [levelAfter] by_cases h : (levelAfter d n j (0, d)).2 < 2 * n - · rw [if_pos h] + · rw [ite_eq_left h] have : (levelAfter d n j (0, d)).2 * d ≤ 2 * n * d := Nat.mul_le_mul_right _ (by omega) simpa using by omega - · rw [if_neg h] + · rw [ite_eq_right h] exact ih /-- The size the loop carries is always the power the level names. -/ @@ -166,11 +166,11 @@ theorem levelAfter_pow (d n : ℕ) : | succ j ih => rw [levelAfter] by_cases h : (levelAfter d n j (0, d)).2 < 2 * n - · rw [if_pos h] + · rw [ite_eq_left h] show (levelAfter d n j (0, d)).2 * d = d ^ ((levelAfter d n j (0, d)).1 + 1 + 1) rw [ih] ring - · rw [if_neg h] + · rw [ite_eq_right h] exact ih /-- **The level the loop reaches names a size below `d + 2 n d`.** -/ diff --git a/Complexitylib/Classes/PCP/Internal/AlgLog.lean b/Complexitylib/Classes/PCP/Internal/AlgLog.lean index e1407307..6e70e563 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgLog.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgLog.lean @@ -75,9 +75,9 @@ theorem two_pow_rulerLen_le (n : ℕ) : 2 ^ rulerLen n ≤ 2 * n + 1 := by | succ n ih => rw [rulerLen] by_cases h : n + 1 < 2 ^ rulerLen n - · rw [if_pos h] + · rw [ite_eq_left h] omega - · rw [if_neg h, pow_succ] + · rw [ite_eq_right h, pow_succ] omega theorem lt_two_pow_rulerLen (n : ℕ) : n < 2 ^ rulerLen n := by @@ -86,9 +86,9 @@ theorem lt_two_pow_rulerLen (n : ℕ) : n < 2 ^ rulerLen n := by | succ n ih => rw [rulerLen] by_cases h : n + 1 < 2 ^ rulerLen n - · rw [if_pos h] + · rw [ite_eq_left h] exact h - · rw [if_neg h, pow_succ] + · rw [ite_eq_right h, pow_succ] omega /-- **The ruler is at least the binary logarithm.** -/ @@ -184,7 +184,7 @@ theorem logFold_eq (bound : ℕ) : ∀ z : List Bool, 4 * z.length + 4 ≤ bound · rw [ifLtLen_pos (by simpa using h), List.length_cons, show rulerLen (t.length + 1) = rulerLen t.length from by rw [rulerLen] - exact if_pos (by omega)] + exact ite_eq_left (by omega)] refine List.take_of_length_le ?_ rw [pair_length, List.length_replicate, List.length_replicate] have h1 := rulerLen_le t.length @@ -193,7 +193,7 @@ theorem logFold_eq (bound : ℕ) : ∀ z : List Bool, 4 * z.length + 4 ≤ bound · rw [ifLtLen_neg (by simpa using h), List.length_cons, show rulerLen (t.length + 1) = rulerLen t.length + 1 from by rw [rulerLen] - exact if_neg (by omega), + exact ite_eq_right (by omega), ← List.replicate_add, ← two_mul, ← pow_succ', ← List.replicate_succ'] refine List.take_of_length_le ?_ rw [pair_length, List.length_replicate, List.length_replicate] @@ -201,7 +201,7 @@ theorem logFold_eq (bound : ℕ) : ∀ z : List Bool, 4 * z.length + 4 ≤ bound have h2 := two_pow_rulerLen_le (t.length + 1) rw [show rulerLen (t.length + 1) = rulerLen t.length + 1 from by rw [rulerLen] - exact if_neg (by omega)] at h1 h2 + exact ite_eq_right (by omega)] at h1 h2 omega /-- The fold itself, on `pair W z`. -/ diff --git a/Complexitylib/Classes/PCP/Internal/AlgPosNum.lean b/Complexitylib/Classes/PCP/Internal/AlgPosNum.lean index 9539dd20..b6282b3e 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgPosNum.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgPosNum.lean @@ -137,7 +137,7 @@ theorem val_head_toGraph_compose (k : Fin (Fintype.card (R.compose enc).Edge)) : (R.blockNum ((R.compose enc).edgeOf k).1 ((R.compose enc).edgeOf k).2.2) (R.cubeNum enc ((R.compose enc).edgeOf k).1 ((R.compose enc).edgeOf k).2.1 ((R.compose enc).edgeOf k).2.2) := by - rw [MultiTest.val_head_toGraph, enc_pos_compose] + erw [MultiTest.val_head_toGraph, enc_pos_compose] /-- The test's verdict, from the satisfying set alone. -/ noncomputable def checkOfSet (S : Finset (Cube (kOf B))) (z : Cube (ROf B)) @@ -172,7 +172,7 @@ theorem edge_facts (e : ℕ) (he : e < (R.compose enc).toGraph.numEdges) : = MultiTest.relOfCheck ((R.compose enc).check p z) i := by obtain ⟨p, z, i, hp, hz, hi, hsplit⟩ := R.edge_data B enc e he refine ⟨p, z, i, hsplit, (MultiTest.tailNum_eq _ ⟨e, he⟩).symm, ?_, ?_⟩ - · rw [hp, hz, hi, MultiTest.val_head_toGraph, enc_pos_compose] + · erw [hp, hz, hi, MultiTest.val_head_toGraph, enc_pos_compose] rfl · rw [hp, hz, hi] exact MultiTest.rel_toGraph_eq _ _ @@ -191,6 +191,9 @@ theorem satSet_congr (p : R.Dart) (p' : R'.Dart) omit [DecidableEq β] [Nonempty β] [NumEnc R.graph.V] [NumEnc R.graph.D] in /-- **So does the cube a read names**, even across two different systems. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem cubeNum_congr {β' : Type} [Fintype β'] [DecidableEq β'] [Nonempty β'] {R' : RegCSP β'} [NumEnc R'.graph.V] [NumEnc R'.graph.D] {enc' : β' → Cube B} (p : R.Dart) (p' : R'.Dart) (z : Cube (ROf B)) (i : ReadIdx) @@ -200,6 +203,9 @@ theorem cubeNum_congr {β' : Type} [Fintype β'] [DecidableEq β'] [Nonempty β' omit [DecidableEq β] [Nonempty β] [NumEnc R.graph.V] [NumEnc R.graph.D] in /-- **And so does the test's verdict.** -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem check_congr {β' : Type} [Fintype β'] [DecidableEq β'] [Nonempty β'] {R' : RegCSP β'} [NumEnc R'.graph.V] [NumEnc R'.graph.D] {enc' : β' → Cube B} (p : R.Dart) (p' : R'.Dart) (z : Cube (ROf B)) diff --git a/Complexitylib/Classes/PCP/Internal/AlgPreRel.lean b/Complexitylib/Classes/PCP/Internal/AlgPreRel.lean index 49930744..029fc2e6 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgPreRel.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgPreRel.lean @@ -59,16 +59,19 @@ theorem preRel_eq (G : ConstraintGraph α) (E : ExpanderFamily) (p : G.HalfEdge) rw [ConstraintGraph.enc_halfEdge, ConstraintGraph.halfCode] cases p.2 <;> simp rcases G.preDart_cases E d with rfl | rfl | ⟨j, rfl⟩ | ⟨j, rfl⟩ - · rw [G.enc_preLoop E, preRelCode, if_pos rfl] + · rw [G.enc_preLoop E, preRelCode, ite_eq_left rfl] rfl - · rw [G.enc_preEdge E, preRelCode, if_neg one_ne_zero, if_pos rfl, relOfCode_codeOfRel, hmod] + · rw [G.enc_preEdge E, preRelCode, ite_eq_right one_ne_zero, ite_eq_left rfl, relOfCode_codeOfRel, + hmod] show (if p.2 then G.rel p.1 b a else G.rel p.1 a b) = _ cases hb : p.2 <;> simp · have hj := j.isLt - rw [G.enc_preCloud E j, preRelCode, if_neg (by omega), if_neg (by omega), if_pos (by omega)] + rw [G.enc_preCloud E j, preRelCode, ite_eq_right (by omega), ite_eq_right (by omega), + ite_eq_left (by omega)] rfl · have hj := j.isLt - rw [G.enc_preExp E j, preRelCode, if_neg (by omega), if_neg (by omega), if_neg (by omega)] + rw [G.enc_preExp E j, preRelCode, ite_eq_right (by omega), ite_eq_right (by omega), + ite_eq_right (by omega)] rfl /-- Only the parity of a half-edge's number matters. -/ @@ -96,8 +99,8 @@ theorem rel_killedPow_preprocess (G : ConstraintGraph α) (E : ExpanderFamily) { (b ((G.preprocess E).graph.endIdx ((G.preprocess E).graph.kLen_le x) v ((G.preprocess E).graph.kWalk x) i)) = true) := by show decide (∀ i : Fin ((G.preprocess E).graph.kLen x), _ = true) = _ - simp only [preRel_eq] - rfl + rw [decide_eq_decide] + exact forall_congr' fun i => by erw [preRel_eq]; rfl /-- What a killed dart's constraint runs: at each step, the dart it takes, the parity of the vertex it stands on, the code of the constraint there, and where @@ -198,7 +201,7 @@ theorem rel_eq_of_data (G G' : ConstraintGraph α) (E : ExpanderFamily) {q T : ((G'.preprocess E).graph.kWalk x)) : ((G.preprocess E).killedPow q T hq).rel v x = ((G'.preprocess E).killedPow q T hq).rel v' x := by - rw [rel_killedPow_eq_preRelOfSteps, rel_killedPow_eq_preRelOfSteps, hpar, hcode, hend] + erw [rel_killedPow_eq_preRelOfSteps, rel_killedPow_eq_preRelOfSteps, hpar, hcode, hend] rfl end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/AlgPreRot.lean b/Complexitylib/Classes/PCP/Internal/AlgPreRot.lean index ff222c30..e1446081 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgPreRot.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgPreRot.lean @@ -84,9 +84,9 @@ theorem length_cloudMark (Gz u j : List Bool) : rw [cloudMark, pairFst_pair, pairSnd_pair, pairFst_pair, pairSnd_pair] by_cases h : (ownerFn (pair Gz j)).length = u.length - · rw [ifEqLen_pos h, if_pos h] + · rw [ifEqLen_pos h, ite_eq_left h] rfl - · rw [ifEqLen_neg h, if_neg h] + · rw [ifEqLen_neg h, ite_eq_right h] rfl /-- How many half-edges hang from the vertex asked for, on @@ -194,13 +194,13 @@ theorem length_eltMark (Gz u k c : List Bool) : rw [eltMark, pairFst_pair, pairSnd_pair, pairFst_pair, pairSnd_pair, pairFst_pair, pairSnd_pair] by_cases h1 : (ownerFn (pair Gz c)).length = u.length - · rw [ifEqLen_pos h1, if_pos h1] + · rw [ifEqLen_pos h1, ite_eq_left h1] by_cases h2 : (cloudIdxFn (pair Gz c)).length = k.length - · rw [ifEqLen_pos h2, if_pos h2] + · rw [ifEqLen_pos h2, ite_eq_left h2] rfl - · rw [ifEqLen_neg h2, if_neg h2] + · rw [ifEqLen_neg h2, ite_eq_right h2] rfl - · rw [ifEqLen_neg h1, if_neg h1] + · rw [ifEqLen_neg h1, ite_eq_right h1] rfl /-- The `k`-th half-edge of the cloud of `u`, on @@ -235,13 +235,13 @@ theorem ownerFn_eq (G : ConstraintGraph α) (p : ℕ) (hp : p / 2 < G.numEdges) have hmod : (modC 2 (List.replicate p true)) = List.replicate (p % 2) true := by rw [modC_eq (by norm_num), List.length_replicate] rw [ownerFn, pairSnd_pair, pairFst_pair, hdiv, hmod, - List.length_replicate, ConstraintGraph.ownerNum, dif_pos hp] + List.length_replicate, ConstraintGraph.ownerNum, dite_eq_left hp] by_cases h : p % 2 = 0 - · rw [if_pos h, ifEqLen_pos (by rw [h]; rfl)] + · rw [ite_eq_left h, ifEqLen_pos (by rw [h]; rfl)] rw [encGraph, pairSnd_pair, recSnd_eq (l3 := edgeRecs G) (by rw [length_edgeRecs]; exact hp) (getElem_edgeRecs G _ hp)] - · rw [if_neg h, ifEqLen_neg (by + · rw [ite_eq_right h, ifEqLen_neg (by rw [List.length_replicate, List.length_nil] exact h)] rw [encGraph, pairSnd_pair, @@ -350,7 +350,7 @@ theorem length_cloudIdxFn_eq (m : ℕ) (hm : m < 2 * G.numEdges) : (cloudIdxFn (pair (encGraph G) (List.replicate m true))).length = countBelow (G.cloudCodes ⟨G.ownerNum m, by have hme : m / 2 < G.numEdges := by omega - rw [ConstraintGraph.ownerNum, dif_pos hme] + rw [ConstraintGraph.ownerNum, dite_eq_left hme] split <;> exact Fin.isLt _⟩) m := by classical have hme : m / 2 < G.numEdges := by omega @@ -366,9 +366,9 @@ omit [Fintype α] [DecidableEq α] in theorem halfCode_lt (p : G.HalfEdge) : G.halfCode p < 2 * G.numEdges := by rw [ConstraintGraph.halfCode] by_cases hb : p.2 = true - · rw [if_pos hb] + · rw [ite_eq_left hb] omega - · rw [if_neg hb] + · rw [ite_eq_right hb] omega /-- **The search finds the `k`-th half-edge of the cloud.** -/ @@ -400,16 +400,16 @@ theorem length_cloudEltFn_eq (v : Fin G.numVerts) (k : ℕ) rw [length_cloudIdxFn_eq G _ hclt, List.length_replicate] have hv : (⟨G.ownerNum (G.halfCode q), by have hme : G.halfCode q / 2 < G.numEdges := by omega - rw [ConstraintGraph.ownerNum, dif_pos hme] + rw [ConstraintGraph.ownerNum, dite_eq_left hme] split <;> exact Fin.isLt _⟩ : Fin G.numVerts) = v := Fin.ext howner' rw [hv, hcount] - rw [length_eltMark, if_pos hown1, if_pos hidx1] + rw [length_eltMark, ite_eq_left hown1, ite_eq_left hidx1] omega · intro j hj rw [length_eltMark] by_cases h1 : (ownerFn (pair (encGraph G) (List.replicate j true))).length = (List.replicate v.val true).length - · rw [if_pos h1, if_neg ?_] + · rw [ite_eq_left h1, ite_eq_right ?_] have hjlt : j < 2 * G.numEdges := by omega have hjown : G.ownerNum j = v.val := by rw [ownerFn_eq G j (by omega), List.length_replicate, List.length_replicate] at h1 @@ -429,11 +429,11 @@ theorem length_cloudEltFn_eq (v : Fin G.numVerts) (k : ℕ) rw [length_cloudIdxFn_eq G _ hjlt, List.length_replicate] have hjv : (⟨G.ownerNum j, by have hme : j / 2 < G.numEdges := by omega - rw [ConstraintGraph.ownerNum, dif_pos hme] + rw [ConstraintGraph.ownerNum, dite_eq_left hme] split <;> exact Fin.isLt _⟩ : Fin G.numVerts) = v := Fin.ext hjown rw [hjv] omega - · rw [if_neg h1] + · rw [ite_eq_right h1] /-! ### The two moves that need the expander -/ @@ -553,7 +553,7 @@ theorem cloudStepFn_eq (hd : 1 < F.deg) (v : Fin G.numVerts) (c j : ℕ) conv_lhs => rw [cloudSizeFn, countOver_eq_replicate] rw [← cloudSizeFn, hsizelen] have hvfin : (⟨G.ownerNum c, by - rw [ConstraintGraph.ownerNum, dif_pos hce] + rw [ConstraintGraph.ownerNum, dite_eq_left hce] split <;> exact Fin.isLt _⟩ : Fin G.numVerts) = v := Fin.ext hown have hidxlen : (cloudIdxFn (pair (encGraph G) (List.replicate c true))).length = countBelow (G.cloudCodes v) c := by @@ -587,7 +587,7 @@ theorem cloudStepFn_eq (hd : 1 < F.deg) (v : Fin G.numVerts) (c j : ℕ) simp only [pairFst_pair, pairSnd_pair] rw [hsize, hidx, hrot] simp only [pairFst_pair, pairSnd_pair] - rw [helt, ConstraintGraph.cloudStepNum, dif_pos hidxlt] + rw [helt, ConstraintGraph.cloudStepNum, dite_eq_left hidxlt] dsimp only rw [← G.halfCode_getElem_cloudList v _ (Fin.isLt _)] @@ -623,7 +623,7 @@ theorem flipFn_eq (v : ℕ) : ifEqLen_pos (by simp)] simp [List.replicate_succ'] · rw [flipFn, modC_eq (by norm_num), List.length_replicate, - ifEqLen_neg (by simp [h]), if_neg h, dropOne] + ifEqLen_neg (by simp [h]), ite_eq_right h, dropOne] simp /-- **The preprocessed graph's rotation map**, on @@ -724,30 +724,30 @@ theorem preRotFn_eq (hd : 1 < F.deg) (v d : ℕ) (hv : v < 2 * G.numEdges) have hne : 0 < 2 * G.numEdges := Nat.lt_of_le_of_lt (Nat.zero_le _) hv have hvd : v / 2 < G.numEdges := by omega have hulr : G.ownerNum v < G.numVerts := by - rw [ConstraintGraph.ownerNum, dif_pos hvd] + rw [ConstraintGraph.ownerNum, dite_eq_left hvd] split <;> exact Fin.isLt _ rw [preRotFn] simp only [pairFst_pair, pairSnd_pair] rw [ConstraintGraph.preRotNum] by_cases h0 : d = 0 · subst h0 - rw [ifEqLen_pos (by simp), if_pos rfl] + rw [ifEqLen_pos (by simp), ite_eq_left rfl] rfl - rw [ifEqLen_neg (by simpa using h0), if_neg h0] + rw [ifEqLen_neg (by simpa using h0), ite_eq_right h0] by_cases h1 : d = 1 · subst h1 - rw [ifEqLen_pos (by simp), if_pos rfl, flipFn_eq] + rw [ifEqLen_pos (by simp), ite_eq_left rfl, flipFn_eq] rfl - rw [ifEqLen_neg (by simpa using h1), if_neg h1] + rw [ifEqLen_neg (by simpa using h1), ite_eq_right h1] have hdrop2 : (List.replicate d true).drop 2 = List.replicate (d - 2) true := by simp by_cases h2 : d < 2 + (F.toFamily hd).degree · -- the cloud's move have hjlt : d - 2 < (F.toFamily hd).degree := by omega - rw [ifLtLen_pos (by simpa using h2), if_pos h2, hdrop2, + rw [ifLtLen_pos (by simpa using h2), ite_eq_left h2, hdrop2, ownerFn_eq G v hvd, cloudStepFn_eq G F pol hd ⟨G.ownerNum v, hulr⟩ v (d - 2) hv rfl hjlt (hpc ⟨G.ownerNum v, hulr⟩)] - rw [ConstraintGraph.cloudStepN, dif_pos hulr, dif_pos hjlt] + rw [ConstraintGraph.cloudStepN, dite_eq_left hulr, dite_eq_left hjlt] simp only [pairFst_pair, pairSnd_pair] have happ : ∀ n : ℕ, List.replicate n true ++ [true, true] = List.replicate (n + 2) true := by @@ -771,9 +771,9 @@ theorem preRotFn_eq (hd : 1 < F.deg) (v d : ℕ) (hv : v < 2 * G.numEdges) exact (F.famRotVal_eq hd hne ⟨v, hvn⟩ ⟨_, hjn⟩).symm have hdropk : (List.replicate d true).drop (2 + (F.toFamily hd).degree) = List.replicate (d - (2 + (F.toFamily hd).degree)) true := by simp - rw [ifLtLen_neg (by simpa using h2), if_neg h2, hdropk, + rw [ifLtLen_neg (by simpa using h2), ite_eq_right h2, hdropk, expStepFn_eq G F pol hd v (d - (2 + (F.toFamily hd).degree)) hne hpe] - rw [ConstraintGraph.expStepN, dif_pos hvlt, dif_pos hjlt] + rw [ConstraintGraph.expStepN, dite_eq_left hvlt, dite_eq_left hjlt] simp only [pairFst_pair, pairSnd_pair] have hk := key _ horder hvlt hjlt have hk1 := congrArg Prod.fst hk diff --git a/Complexitylib/Classes/PCP/Internal/AlgPreprocess.lean b/Complexitylib/Classes/PCP/Internal/AlgPreprocess.lean index adaac6a8..4fc176a5 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgPreprocess.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgPreprocess.lean @@ -118,7 +118,7 @@ theorem enc_vertexEquiv (x : Fin (G.reduce E).graph.order) : have h : NumEnc.enc ((NumEnc.equivFinCard (G.reduce E).graph.V).symm x) = (NumEnc.equivFinCard (G.reduce E).graph.V ((NumEnc.equivFinCard (G.reduce E).graph.V).symm x)).val := rfl - rw [h, Equiv.apply_symm_apply] + erw [h, Equiv.apply_symm_apply] theorem val_vertexEquiv_symm (v : (G.reduce E).graph.V) : ((E.vertexEquiv (G.reduce E).graph).symm v).val = enc v := rfl @@ -147,7 +147,7 @@ theorem cloudStepNum_eq (p : G.HalfEdge) (j : Fin E.degree) : rw [G.idxOf_cloudList rfl, enc_halfEdge] have hlt' : countBelow (G.cloudCodes (G.owner p)) (enc p) < (G.cloudList (G.owner p)).length := by rw [← hidx]; exact hlt - rw [cloudStepNum, dif_pos hlt', cloudRot, cloudRotAux, dif_pos hlt] + rw [cloudStepNum, dite_eq_left hlt', cloudRot, cloudRotAux, dite_eq_left hlt] simp only [← hidx] refine Prod.ext ?_ rfl dsimp only @@ -181,7 +181,7 @@ theorem ownerNum_enc (p : G.HalfEdge) : G.ownerNum (enc p) = (G.owner p).val := cases p.2 <;> simp have hlt : enc p / 2 < G.numEdges := by rw [hdiv]; exact p.1.isLt have hfin : (⟨enc p / 2, hlt⟩ : Fin G.numEdges) = p.1 := Fin.ext hdiv - rw [ownerNum, dif_pos hlt, hmod, owner, hfin] + rw [ownerNum, dite_eq_left hlt, hmod, owner, hfin] cases p.2 <;> simp /-- The cloud step, on numbers throughout. -/ @@ -218,19 +218,18 @@ theorem preRotNum_eq (v : G.HalfEdge) (d : (G.preprocess E).graph.D) : = (enc (((G.preprocess E).graph.rot (v, d)).1 : G.HalfEdge), enc ((G.preprocess E).graph.rot (v, d)).2) := by rcases G.preDart_cases E d with rfl | rfl | ⟨j, rfl⟩ | ⟨j, rfl⟩ - · rw [G.enc_preLoop E, preRotNum, if_pos rfl, G.rot_preLoop E, G.enc_preLoop E] + · erw [G.enc_preLoop E, preRotNum, ite_eq_left rfl, G.rot_preLoop E] rfl - · rw [G.enc_preEdge E, preRotNum, if_neg one_ne_zero, if_pos rfl, G.rot_preEdge E, - G.enc_preEdge E] + · erw [G.enc_preEdge E, preRotNum, ite_eq_right one_ne_zero, ite_eq_left rfl, G.rot_preEdge E] dsimp only exact Prod.ext (G.enc_flipHalf v).symm rfl · have hj := j.isLt - rw [G.enc_preCloud E j, preRotNum, if_neg (by omega), if_neg (by omega), - if_pos (by omega), G.rot_preCloud E, G.enc_preCloud E] + erw [G.enc_preCloud E j, preRotNum, ite_eq_right (by omega), ite_eq_right (by omega), + ite_eq_left (by omega), G.rot_preCloud E, G.enc_preCloud E] dsimp only rw [G.ownerNum_enc] have harg : (2 + j.val) - 2 = j.val := by omega - rw [harg, cloudStepN, dif_pos (G.owner v).isLt, dif_pos hj] + rw [harg, cloudStepN, dite_eq_left (G.owner v).isLt, dite_eq_left hj] have hv : (⟨(G.owner v).val, (G.owner v).isLt⟩ : Fin G.numVerts) = G.owner v := rfl have hjj : (⟨j.val, hj⟩ : Fin E.degree) = j := rfl rw [hv, hjj, G.cloudStepNum_eq E v j] @@ -239,11 +238,11 @@ theorem preRotNum_eq (v : G.HalfEdge) (d : (G.preprocess E).graph.D) : have hvlt : enc v < (G.reduce E).graph.order := by have := NumEnc.enc_lt v rwa [NumEnc.card_eq_fintype_card] at this - rw [G.enc_preExp E j, preRotNum, if_neg (by omega), if_neg (by omega), - if_neg (by omega), G.rot_preExp E, G.enc_preExp E] + erw [G.enc_preExp E j, preRotNum, ite_eq_right (by omega), ite_eq_right (by omega), + ite_eq_right (by omega), G.rot_preExp E, G.enc_preExp E] dsimp only have harg : 2 + E.degree + j.val - (2 + E.degree) = j.val := by omega - rw [harg, expStepN, dif_pos hvlt, dif_pos hj] + rw [harg, expStepN, dite_eq_left hvlt, dite_eq_left hj] have hv : (⟨enc v, hvlt⟩ : Fin (G.reduce E).graph.order) = (E.vertexEquiv (G.reduce E).graph).symm v := Fin.ext (G.val_vertexEquiv_symm E v).symm diff --git a/Complexitylib/Classes/PCP/Internal/AlgWalk.lean b/Complexitylib/Classes/PCP/Internal/AlgWalk.lean index adeb6c73..101754eb 100644 --- a/Complexitylib/Classes/PCP/Internal/AlgWalk.lean +++ b/Complexitylib/Classes/PCP/Internal/AlgWalk.lean @@ -61,7 +61,7 @@ theorem stopAtNum_eq {T q : ℕ} (hq : 0 < q) (c : Fin T → Fin q) : (fun i hi => encAt_lt c hi) rw [hcard] at h rw [show (enc c : ℕ) = ∑ i ∈ Finset.range T, encAt c i * q ^ i from rfl, h, encAt, - dif_pos j.isLt] + dite_eq_left j.isLt] rw [hdig] rfl @@ -86,7 +86,7 @@ theorem digit_enc {T : ℕ} (s : Fin T → (G.preprocess E).graph.D) (hpos : 0 < (fun i hi => encAt_lt s hi) rw [show (enc s : ℕ) = ∑ i ∈ Finset.range T, encAt s i * card (G.preprocess E).graph.D ^ i from rfl, - preDeg, h, encAt, dif_pos hk] + preDeg, h, encAt, dite_eq_left hk] /-- **Following the digits walks the graph.** The steps are read from any number whose digits are the tuple's entries, so a prefix of a longer walk may be run @@ -129,7 +129,7 @@ theorem killedRevNum_eq {T q : ℕ} (hq : 0 < q) (hpos : 0 < G.preDeg E) (v : G. (fun i hi => encAt_lt s hi) rw [show (enc s : ℕ) = ∑ i ∈ Finset.range T, encAt s i * card (G.preprocess E).graph.D ^ i from rfl, - preDeg, h, encAt, dif_pos hk] + preDeg, h, encAt, dite_eq_left hk] have hstop : stopAtNum T q (enc c) = stopAt c := stopAtNum_eq hq c have hle : stopAt c ≤ T := stopAt_le c rw [killedRevNum, hstop, @@ -139,16 +139,18 @@ theorem killedRevNum_eq {T q : ℕ} (hq : 0 < q) (hpos : 0 < G.preDeg E) (v : G. refine Finset.sum_congr rfl fun j hj => ?_ rw [Finset.mem_range] at hj congr 1 - rw [encAt, dif_pos hj] + rw [encAt, dite_eq_left hj] by_cases hjlt : j < stopAt c - · rw [if_pos hjlt] + · rw [ite_eq_left hjlt] have hk : stopAt c - 1 - j < T := by omega rw [hdig _ hk] have hrev : ((G.preprocess E).graph.killedRev v s c) ⟨j, hj⟩ = (G.preprocess E).graph.backLabel v ((G.preprocess E).graph.preWalk s hle) (Fin.rev ⟨j, hjlt⟩) := by - rw [RegGraph.killedRev, RegGraph.extWalk, dif_pos hjlt, RegGraph.revWalk] - rw [hrev, RegGraph.backLabel] + simp only [RegGraph.killedRev, RegGraph.extWalk, dite_eq_left hjlt, + RegGraph.revWalk] + rw [hrev] + simp only [RegGraph.backLabel] have hidx : (Fin.rev (⟨j, hjlt⟩ : Fin (stopAt c))).val = stopAt c - 1 - j := by rw [Fin.val_rev] show stopAt c - (j + 1) = stopAt c - 1 - j @@ -167,9 +169,9 @@ theorem killedRevNum_eq {T q : ℕ} (hq : 0 < q) (hpos : 0 < G.preDeg E) (v : G. rw [G.digit_enc E s hpos k (lt_of_lt_of_le hk hle), RegGraph.preWalk] rw [G.walkNum_eq E v ((G.preprocess E).graph.preWalk s hle) (enc s) hpre (by omega)] exact congrArg Prod.snd (G.preRotNum_eq E _ _) - · rw [if_neg hjlt, hdig _ hj] + · rw [ite_eq_right hjlt, hdig _ hj] congr 1 - rw [RegGraph.killedRev, RegGraph.extWalk, dif_neg hjlt] + simp only [RegGraph.killedRev, RegGraph.extWalk, dite_eq_right hjlt] /-! ### The powered graph's rotation map -/ @@ -197,7 +199,9 @@ theorem killedRotNum_eq {T q : ℕ} (hq : 0 < q) (hpos : 0 < G.preDeg E) (v : G. intro k hk rw [G.digit_enc E x.1 hpos k (lt_of_lt_of_le hk hle), RegGraph.preWalk] rw [G.walkNum_eq E v ((G.preprocess E).graph.preWalk x.1 hle) (enc x.1) hpre le_rfl] - rw [← hw1, RegGraph.killedEnd, ← RegGraph.walkAt_self_eq_walkEnd] + rw [← hw1] + simp only [RegGraph.killedEnd] + erw [← RegGraph.walkAt_self_eq_walkEnd] rfl · show G.killedRevNum E T q (enc v) (enc x.1) (enc x.2) * q ^ T + enc x.2 = _ rw [G.killedRevNum_eq E hq hpos v x.1 x.2, ← hw2] diff --git a/Complexitylib/Classes/PCP/Internal/AlphabetLift.lean b/Complexitylib/Classes/PCP/Internal/AlphabetLift.lean index 116df595..211b3ebd 100644 --- a/Complexitylib/Classes/PCP/Internal/AlphabetLift.lean +++ b/Complexitylib/Classes/PCP/Internal/AlphabetLift.lean @@ -87,7 +87,7 @@ theorem satisfiable_lift_iff (G : ConstraintGraph α) {f : α → β} (hf : Func have hc₂ : hex₂.choose = a₂ := hf (hex₂.choose_spec.trans h₂.symm) show G.rel e _ _ = true dsimp only - rw [dif_pos hex₁, dif_pos hex₂, hc₁, hc₂] + rw [dite_eq_left hex₁, dite_eq_left hex₂, hc₁, hc₂] exact hrel · rintro ⟨a, ha⟩ refine ⟨fun v => f (a v), fun e => ?_⟩ diff --git a/Complexitylib/Classes/PCP/Internal/Arithmetize.lean b/Complexitylib/Classes/PCP/Internal/Arithmetize.lean index b75ac86c..b41ff7f9 100644 --- a/Complexitylib/Classes/PCP/Internal/Arithmetize.lean +++ b/Complexitylib/Classes/PCP/Internal/Arithmetize.lean @@ -229,7 +229,7 @@ theorem sat_oneHot_pair_iff {k : ℕ} (S : Finset (Cube k)) (a : Cube (k + 2 ^ k (m m' : Fin (2 ^ k)) (hne : m ≠ m') : (oneHotOf S (Sum.inr (Sum.inl (m, m')))).Sat a ↔ rightBlock a m * rightBlock a m' = 0 := by unfold QuadConstraint.Sat QuadConstraint.eval - simp only [oneHotOf, if_neg hne] + simp only [oneHotOf, ite_eq_right hne] rw [hadamard_tensorAssign_basisVec, hadamard_zero_arg, add_zero, add_zero] rfl @@ -237,7 +237,7 @@ theorem sat_oneHot_allowed_iff {k : ℕ} (S : Finset (Cube k)) (a : Cube (k + 2 (m : Fin (2 ^ k)) (hm : (candIdx k).symm m ∉ S) : (oneHotOf S (Sum.inr (Sum.inr (Sum.inl m)))).Sat a ↔ rightBlock a m = 0 := by unfold QuadConstraint.Sat QuadConstraint.eval - simp only [oneHotOf, if_neg hm] + simp only [oneHotOf, ite_eq_right hm] rw [hadamard_zero_arg, hadamard_basisVec, zero_add, add_zero] rfl @@ -320,28 +320,28 @@ theorem sat_oneHotSystem_extend {k : ℕ} (S : Finset (Cube k)) (w : Cube k) (hw rcases x with _ | ⟨⟨m, m'⟩ | m | i⟩ · rw [sat_oneHot_sum_iff] rw [Finset.sum_eq_single (candIdx k w) - (fun m _ hm => by rw [rightBlock_oneHotExtend, if_neg hm]) - (fun hn => absurd (Finset.mem_univ _) hn), rightBlock_oneHotExtend, if_pos rfl] + (fun m _ hm => by rw [rightBlock_oneHotExtend, ite_eq_right hm]) + (fun hn => absurd (Finset.mem_univ _) hn), rightBlock_oneHotExtend, ite_eq_left rfl] · by_cases hne : m = m' - · simp only [oneHotOf, if_pos hne] + · simp only [oneHotOf, ite_eq_left hne] exact QuadConstraint.sat_trivial _ · rw [sat_oneHot_pair_iff S _ m m' hne, rightBlock_oneHotExtend, rightBlock_oneHotExtend] by_cases hm : m = candIdx k w · have hm' : m' ≠ candIdx k w := fun h => hne (hm.trans h.symm) - rw [if_neg hm', mul_zero] - · rw [if_neg hm, zero_mul] + rw [ite_eq_right hm', mul_zero] + · rw [ite_eq_right hm, zero_mul] · by_cases hm : (candIdx k).symm m ∈ S - · simp only [oneHotOf, if_pos hm] + · simp only [oneHotOf, ite_eq_left hm] exact QuadConstraint.sat_trivial _ - · rw [sat_oneHot_allowed_iff S _ m hm, rightBlock_oneHotExtend, if_neg] + · rw [sat_oneHot_allowed_iff S _ m hm, rightBlock_oneHotExtend, ite_eq_right] intro hmw apply hm rw [hmw, Equiv.symm_apply_apply] exact hw · rw [sat_oneHot_coord_iff, leftBlock_oneHotExtend] rw [Finset.sum_eq_single (candIdx k w) - (fun m _ hm => by rw [rightBlock_oneHotExtend, if_neg hm, zero_mul]) - (fun hn => absurd (Finset.mem_univ _) hn), rightBlock_oneHotExtend, if_pos rfl, + (fun m _ hm => by rw [rightBlock_oneHotExtend, ite_eq_right hm, zero_mul]) + (fun hn => absurd (Finset.mem_univ _) hn), rightBlock_oneHotExtend, ite_eq_left rfl, one_mul, Equiv.symm_apply_apply] rcases (by decide : ∀ u : ZMod 2, u + u = 0) (w i) with h' exact h' diff --git a/Complexitylib/Classes/PCP/Internal/BaseAlg.lean b/Complexitylib/Classes/PCP/Internal/BaseAlg.lean index d0625313..88573876 100644 --- a/Complexitylib/Classes/PCP/Internal/BaseAlg.lean +++ b/Complexitylib/Classes/PCP/Internal/BaseAlg.lean @@ -281,11 +281,11 @@ noncomputable def baseAlg (hE : E ∈ FP) : AlgCSP where · have := mem_FP_comp (mem_FP_comp harg (baseTailU_mem_FP E hE)) unaryLength_mem_FP refine mem_FP_of_eq this fun w => ?_ rw [Function.comp_apply, Function.comp_apply] - simp only [cond_false] + simp only [Bool.cond_false] · have := mem_FP_comp (mem_FP_comp harg (baseHeadU_mem_FP E hE)) unaryLength_mem_FP refine mem_FP_of_eq this fun w => ?_ rw [Function.comp_apply, Function.comp_apply] - simp only [cond_true] + simp only [Bool.cond_true] ok := baseOk E 23 ok_mem := baseOk_mem_P E hE 23 @@ -297,12 +297,12 @@ noncomputable def baseAlg (hE : E ∈ FP) : AlgCSP where theorem vert_baseAlg_false (hE : E ∈ FP) (x : List Bool) (e : ℕ) : (baseAlg E hE).vert false x e = (baseTailU E (pair x (List.replicate e true))).length := by - simp only [baseAlg, cond_false] + simp only [baseAlg, Bool.cond_false] theorem vert_baseAlg_true (hE : E ∈ FP) (x : List Bool) (e : ℕ) : (baseAlg E hE).vert true x e = (baseHeadU E (pair x (List.replicate e true))).length := by - simp only [baseAlg, cond_true] + simp only [baseAlg, Bool.cond_true] @[simp] theorem ok_baseAlg (hE : E ∈ FP) : (baseAlg E hE).ok = baseOk E 23 := rfl @@ -360,7 +360,7 @@ theorem baseAlg_tail_eq (hE' : E ∈ FP) (hE : ∀ x, E x = (Φ x).encode) rw [numEdges_baseCSP] at he rw [vert_baseAlg_false, baseTailU_eq E hE h3] show _ = (clauseVertex (Φ x) (edgeClause e)).val - rw [clauseVertex, edgeClause, dif_pos (by rw [numVerts]; omega)] + rw [clauseVertex, edgeClause, dite_eq_left (by rw [numVerts]; omega)] theorem baseAlg_head_eq (hE' : E ∈ FP) (hE : ∀ x, E x = (Φ x).encode) (h3 : ∀ x, CNF.Is3CNF (Φ x)) (x : List Bool) (e : ℕ) @@ -382,7 +382,7 @@ theorem baseAlg_head_eq (hE' : E ∈ FP) (hE : ∀ x, E x = (Φ x).encode) exact var_le_maxVar (Φ x) hj hp rw [vert_baseAlg_true, baseHeadU_eq E hE h3 x he] show _ = (varVertex (Φ x) (litOf (Φ x) (edgeClause e) (edgePos e)).var).val - rw [varVertex, edgeClause, edgePos, dif_pos (by rw [numVerts]; omega)] + rw [varVertex, edgeClause, edgePos, dite_eq_left (by rw [numVerts]; omega)] /-! ### The key on a well-formed argument -/ diff --git a/Complexitylib/Classes/PCP/Internal/BitwiseFP.lean b/Complexitylib/Classes/PCP/Internal/BitwiseFP.lean index 623c8500..8b331bab 100644 --- a/Complexitylib/Classes/PCP/Internal/BitwiseFP.lean +++ b/Complexitylib/Classes/PCP/Internal/BitwiseFP.lean @@ -59,11 +59,11 @@ theorem bitStep_mem_FP {G : List Bool → List Bool} (hG : G ∈ FP) : bitStep G have hsnd : (fun z : List Bool => pairSnd z) ∈ FP := sndBlock_mem_FP have hcnt : (fun z : List Bool => List.replicate (pairFst z).length true) ∈ FP := by have := mem_FP_comp hfst unaryLength_mem_FP - simpa using this + exact this have hquery : (fun z : List Bool => G (pair (pairSnd z) (List.replicate (pairFst z).length true))) ∈ FP := by have := mem_FP_comp (pairFn_mem_FP hsnd hcnt) hG - simpa using this + exact this exact pairFn_mem_FP (appendFn_mem_FP hfst hquery) hsnd /-- Running the step from the empty output builds the first `n` bits. -/ diff --git a/Complexitylib/Classes/PCP/Internal/BoundNotConstructible.lean b/Complexitylib/Classes/PCP/Internal/BoundNotConstructible.lean index e39d0a9e..34cbd9c0 100644 --- a/Complexitylib/Classes/PCP/Internal/BoundNotConstructible.lean +++ b/Complexitylib/Classes/PCP/Internal/BoundNotConstructible.lean @@ -124,7 +124,7 @@ theorem lengthLang_mem_iUnion_PCP (A : Set ℕ) : have hxA : x.length ∈ A := hx have hr : indicatorBound A x.length = 1 := by rw [indicatorBound] - exact if_pos hxA + exact ite_eq_left hxA rw [hr] have huniv : coinLenVerifier.acceptEvent 1 x [] = Finset.univ := by refine Finset.eq_univ_iff_forall.2 fun ρ => ?_ @@ -136,7 +136,7 @@ theorem lengthLang_mem_iUnion_PCP (A : Set ℕ) : have hxA : x.length ∉ A := hx have hr : indicatorBound A x.length = 0 := by rw [indicatorBound] - exact if_neg hxA + exact ite_eq_right hxA rw [hr] have hempty : coinLenVerifier.acceptEvent 0 x π = ∅ := by refine Finset.eq_empty_iff_forall_notMem.2 fun ρ hρ => ?_ diff --git a/Complexitylib/Classes/PCP/Internal/BoundedQuant.lean b/Complexitylib/Classes/PCP/Internal/BoundedQuant.lean index 8955569d..5825a744 100644 --- a/Complexitylib/Classes/PCP/Internal/BoundedQuant.lean +++ b/Complexitylib/Classes/PCP/Internal/BoundedQuant.lean @@ -41,7 +41,7 @@ theorem forall_unary_mem_P {L : Language} (hL : L ∈ P) {len : List Bool → (fun i => g (pair x (List.replicate i true)))) ∈ FP := bitwise_mem_FP hlen hgFP fun _ _ => rfl refine mem_P_of_decisionFn (eqFlagFn_mem_FP hmap hlen) fun x => ?_ - simp only [Set.mem_setOf_eq] + simp only [Set.mem_ofPred_eq] set a := (List.range (len x)).map (fun i => g (pair x (List.replicate i true))) with ha set b := List.replicate (len x) true with hb have hiff : a = b ↔ ∀ i < len x, pair x (List.replicate i true) ∈ L := by diff --git a/Complexitylib/Classes/PCP/Internal/CNFCount.lean b/Complexitylib/Classes/PCP/Internal/CNFCount.lean index 1bce435b..7f8c0dd7 100644 --- a/Complexitylib/Classes/PCP/Internal/CNFCount.lean +++ b/Complexitylib/Classes/PCP/Internal/CNFCount.lean @@ -84,11 +84,11 @@ theorem ccStep_cons₂ (c : List Bool) (b0 b1 : Bool) (r : List Bool) : simp [dropOne] · cases b1 · rw [selectHead_cons] - simp only [dropOne, List.drop_succ_cons, List.drop_zero, if_pos] + simp only [dropOne, List.drop_succ_cons, List.drop_zero, ite_eq_left] rw [selectHead_cons] simp · rw [selectHead_cons] - simp only [dropOne, List.drop_succ_cons, List.drop_zero, if_pos] + simp only [dropOne, List.drop_succ_cons, List.drop_zero, ite_eq_left] rw [selectHead_cons] simp @@ -125,9 +125,9 @@ theorem ccStep_iterate : ∀ (k : ℕ) (c s : List Bool), s.length ≤ 2 * k → exact ⟨m - 1, by omega⟩ rw [ih _ r hr hrev, sepCount_cons₂] by_cases hcase : b0 = true ∧ b1 = false - · rw [if_pos hcase, if_pos hcase, List.replicate_succ, + · rw [ite_eq_left hcase, ite_eq_left hcase, List.replicate_succ, List.cons_append, ← replicate_true_append_cons] - · rw [if_neg hcase, if_neg hcase] + · rw [ite_eq_right hcase, ite_eq_right hcase] /-! ### The scan as one function -/ @@ -183,7 +183,7 @@ theorem clauseCountFn_mem_FP : clauseCountFn ∈ FP := by omega have hiter := Cobham.iterate_mem_FP ccStep_mem_FP hinit id_mem_FP hwidth hbound have := mem_FP_comp hiter Cobham.fstBlock_mem_FP - simpa using this + exact this theorem clauseCountFn_eq {z : List Bool} (h : Even z.length) : clauseCountFn z = List.replicate (sepCount z) true := by diff --git a/Complexitylib/Classes/PCP/Internal/CNFSegment.lean b/Complexitylib/Classes/PCP/Internal/CNFSegment.lean index 12f9383f..e6a99cb7 100644 --- a/Complexitylib/Classes/PCP/Internal/CNFSegment.lean +++ b/Complexitylib/Classes/PCP/Internal/CNFSegment.lean @@ -163,22 +163,22 @@ theorem segStep_cons₂ (tgt cnt coll : List Bool) (b0 b1 : Bool) (r : List Bool = if cnt.length = tgt.length then [true] else [false] := by rw [segHere, hc, ht] by_cases h : cnt.length = tgt.length - · rw [if_pos h, Cobham.lenEqFlag_eq_true_iff] + · rw [ite_eq_left h, Cobham.lenEqFlag_eq_true_iff] exact h - · rw [if_neg h] + · rw [ite_eq_right h] rcases Cobham.lenEqFlag_flag cnt tgt with hf | hf · rw [Cobham.lenEqFlag_eq_true_iff] at hf exact absurd hf h · exact hf rw [segStep, hr, hsep, hhere, ht, hc, hl, emptyFlag_cons, selectHead_cons_false] by_cases hcase : b0 = s0 ∧ b1 = s1 - · rw [if_pos hcase, if_pos hcase, selectHead_cons_true, selectHead_cons_true] + · rw [ite_eq_left hcase, ite_eq_left hcase, selectHead_cons_true, selectHead_cons_true] simp [dropOne] - · rw [if_neg hcase, if_neg hcase, selectHead_cons_false, selectHead_cons_false] + · rw [ite_eq_right hcase, ite_eq_right hcase, selectHead_cons_false, selectHead_cons_false] by_cases hh : cnt.length = tgt.length - · rw [if_pos hh, if_pos hh, selectHead_cons_true] + · rw [ite_eq_left hh, ite_eq_left hh, selectHead_cons_true] simp [dropOne] - · rw [if_neg hh, if_neg hh, selectHead_cons_false] + · rw [ite_eq_right hh, ite_eq_right hh, selectHead_cons_false] simp [dropOne] /-- **The scan collects the segment.** -/ @@ -210,13 +210,13 @@ theorem segStep_iterate : ∀ (k : ℕ) (tgt cnt coll s : List Bool), exact ⟨m - 1, by omega⟩ rw [segStep_cons₂, segFrom_cons₂] by_cases hcase : b0 = s0 ∧ b1 = s1 - · rw [if_pos hcase, if_pos hcase, ih tgt (true :: cnt) coll r hr hrev] + · rw [ite_eq_left hcase, ite_eq_left hcase, ih tgt (true :: cnt) coll r hr hrev] simp - · rw [if_neg hcase, if_neg hcase] + · rw [ite_eq_right hcase, ite_eq_right hcase] by_cases hh : cnt.length = tgt.length - · rw [if_pos hh, if_pos hh, ih tgt cnt _ r hr hrev] + · rw [ite_eq_left hh, ite_eq_left hh, ih tgt cnt _ r hr hrev] simp - · rw [if_neg hh, if_neg hh, ih tgt cnt coll r hr hrev] + · rw [ite_eq_right hh, ite_eq_right hh, ih tgt cnt coll r hr hrev] theorem even_length_segFrom (s0 s1 : Bool) (t : ℕ) : ∀ (n : ℕ) (s : List Bool) (c : ℕ), s.length ≤ n → Even s.length → @@ -243,15 +243,15 @@ theorem even_length_segFrom (s0 s1 : Bool) (t : ℕ) : rcases hev with ⟨m, hm⟩ exact ⟨m - 1, by omega⟩ by_cases hcase : b0 = s0 ∧ b1 = s1 - · rw [if_pos hcase] + · rw [ite_eq_left hcase] exact ih r (c + 1) hr hrev - · rw [if_neg hcase] + · rw [ite_eq_right hcase] by_cases hh : c = t - · rw [if_pos hh] + · rw [ite_eq_left hh] simp only [List.length_cons] rcases ih r c hr hrev with ⟨m, hm⟩ exact ⟨m + 1, by omega⟩ - · rw [if_neg hh] + · rw [ite_eq_right hh] exact ih r c hr hrev /-! ### The scan as one function -/ @@ -336,7 +336,7 @@ theorem segAtFn_mem_FP : segAtFn s0 s1 ∈ FP := by omega have hiter := Cobham.iterate_mem_FP (segStep_mem_FP s0 s1) hinit hs hwidth hbound have := mem_FP_comp hiter segColl_mem_FP - simpa only using this + exact this theorem segAtFn_eq {j : ℕ} {e : List Bool} (h : Even e.length) : segAtFn s0 s1 (pair (List.replicate j true) e) = segFrom s0 s1 j 0 e := by @@ -363,9 +363,9 @@ theorem litSegFn_mem_FP : litSegFn ∈ FP := by have hcl : (fun z : List Bool => segAtFn true false (pair (pairFst (pairFst z)) (pairSnd z))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hj he) (segAtFn_mem_FP true false) - simpa only using this + exact this have := mem_FP_comp (Cobham.pairFn_mem_FP hp hcl) (segAtFn_mem_FP false true) - simpa only using this + exact this theorem litSegFn_eq {j p : ℕ} {e : List Bool} (h : Even e.length) : litSegFn (pair (pair (List.replicate j true) (List.replicate p true)) e) @@ -383,7 +383,7 @@ theorem litVarFn_mem_FP : litVarFn ∈ FP := by refine mem_FP_of_eq this fun z => ?_ rfl have := mem_FP_comp hdrop halfFn_mem_FP - simpa only using this + exact this theorem litVarFn_eq {j p : ℕ} {e : List Bool} (h : Even e.length) : litVarFn (pair (pair (List.replicate j true) (List.replicate p true)) e) diff --git a/Complexitylib/Classes/PCP/Internal/CNFTokens.lean b/Complexitylib/Classes/PCP/Internal/CNFTokens.lean index 486d0e0b..e47b52e7 100644 --- a/Complexitylib/Classes/PCP/Internal/CNFTokens.lean +++ b/Complexitylib/Classes/PCP/Internal/CNFTokens.lean @@ -54,21 +54,21 @@ theorem sepCount_encodeTokens : ∀ toks : List EncToken, cases b · show sepCount ([false, false] ++ encodeTokens ts) = _ rw [show ([false, false] ++ encodeTokens ts) - = false :: false :: encodeTokens ts from rfl, sepCount_cons₂, if_neg (by simp)] + = false :: false :: encodeTokens ts from rfl, sepCount_cons₂, ite_eq_right (by simp)] simp [ih] · show sepCount ([true, true] ++ encodeTokens ts) = _ rw [show ([true, true] ++ encodeTokens ts) - = true :: true :: encodeTokens ts from rfl, sepCount_cons₂, if_neg (by simp)] + = true :: true :: encodeTokens ts from rfl, sepCount_cons₂, ite_eq_right (by simp)] simp [ih] case litSep => show sepCount ([false, true] ++ encodeTokens ts) = _ rw [show ([false, true] ++ encodeTokens ts) - = false :: true :: encodeTokens ts from rfl, sepCount_cons₂, if_neg (by simp)] + = false :: true :: encodeTokens ts from rfl, sepCount_cons₂, ite_eq_right (by simp)] simp [ih] case clauseSep => show sepCount ([true, false] ++ encodeTokens ts) = _ rw [show ([true, false] ++ encodeTokens ts) - = true :: false :: encodeTokens ts from rfl, sepCount_cons₂, if_pos (by simp)] + = true :: false :: encodeTokens ts from rfl, sepCount_cons₂, ite_eq_left (by simp)] simp [ih] theorem clause_tokens_no_sep (c : Clause) : @@ -133,11 +133,11 @@ theorem segFrom_encodeTokens_noSep {sep : EncToken} {b0 b1 : Bool} obtain ⟨c0, c1, henc, hnec⟩ := hne tk (hall tk (by simp)) rw [encodeTokens_cons, henc, List.append_assoc, show ([c0, c1] ++ (encodeTokens ts ++ v)) = c0 :: c1 :: (encodeTokens ts ++ v) from rfl, - segFrom_cons₂, if_neg hnec, ih (fun t' ht' => hall t' (by simp [ht'])) v t c] + segFrom_cons₂, ite_eq_right hnec, ih (fun t' ht' => hall t' (by simp [ht'])) v t c] by_cases h : c = t - · rw [if_pos h, if_pos h, if_pos h] + · rw [ite_eq_left h, ite_eq_left h, ite_eq_left h] rfl - · rw [if_neg h, if_neg h, if_neg h] + · rw [ite_eq_right h, ite_eq_right h, ite_eq_right h] theorem segFrom_of_gt (s0 s1 : Bool) : ∀ (n : ℕ) (s : List Bool) (t c : ℕ), s.length ≤ n → t < c → segFrom s0 s1 t c s = [] := by @@ -159,9 +159,9 @@ theorem segFrom_of_gt (s0 s1 : Bool) : ∀ (n : ℕ) (s : List Bool) (t c : ℕ) omega rw [segFrom_cons₂] by_cases hcase : b0 = s0 ∧ b1 = s1 - · rw [if_pos hcase] + · rw [ite_eq_left hcase] exact ih r t (c + 1) hr (by omega) - · rw [if_neg hcase, if_neg (by omega : ¬ c = t)] + · rw [ite_eq_right hcase, ite_eq_right (by omega : ¬ c = t)] exact ih r t c hr hlt /-- Token segments joined by a separator. -/ @@ -207,14 +207,14 @@ theorem segFrom_tokenJoin {sep : EncToken} {b0 b1 : Bool} (hsep : sep.encode = [ rw [encodeTokens_append, show encodeTokens [sep] = sep.encode from by simp, hsep] rfl - rw [hs, segFrom_cons₂, if_pos (by simp : (b0 = b0 ∧ b1 = b1))] + rw [hs, segFrom_cons₂, ite_eq_left (by simp : (b0 = b0 ∧ b1 = b1))] rcases Nat.eq_or_lt_of_le hle with heq | hlt2 - · rw [if_pos heq, segFrom_of_gt b0 b1 + · rw [ite_eq_left heq, segFrom_of_gt b0 b1 (encodeTokens (tokenJoin sep gs)).length _ t (c + 1) (le_refl _) (by omega)] have hzero : t - c = 0 := by omega simp only [hzero] simp - · rw [if_neg (by omega : ¬ c = t)] + · rw [ite_eq_right (by omega : ¬ c = t)] have hidx : t - c = (t - (c + 1)) + 1 := by omega have hlt' : t - (c + 1) < gs.length := by rw [hidx] at hlt diff --git a/Complexitylib/Classes/PCP/Internal/CSPVerifier.lean b/Complexitylib/Classes/PCP/Internal/CSPVerifier.lean index dbd2a9ec..f26e3675 100644 --- a/Complexitylib/Classes/PCP/Internal/CSPVerifier.lean +++ b/Complexitylib/Classes/PCP/Internal/CSPVerifier.lean @@ -84,7 +84,7 @@ theorem inRange_mem_FP : A.inRange p ∈ FP := by have hn : (fun z : List Bool => List.replicate (A.numEdges (pairFst z)) true) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP A.numEdges_mem - simpa using this + exact this exact lenLeFlagFn_mem_FP hn (mem_FP_comp (edgeU_mem_FP p) (Cobham.cons_mem_FP true)) theorem inRange_eq_true_iff {z : List Bool} @@ -168,7 +168,7 @@ theorem posU_mem_FP : A.posU p ∈ FP := by rw [Function.comp_apply, List.length_replicate, List.length_replicate] have hoff : (fun w => List.replicate (A.offU w).length true) ∈ FP := by have := mem_FP_comp A.offU_mem_FP unaryLength_mem_FP - simpa using this + exact this exact Cobham.appendFn_mem_FP hmul hoff theorem cntU_eq_replicate (z : List Bool) : @@ -215,10 +215,10 @@ theorem verdictLang_mem_P : A.verdictLang p ∈ P := by obtain ⟨g, hgFP, hg⟩ := exists_decisionFn_of_mem_P A.ok_mem have hin : (fun z : List Bool => A.inRange p (pairFst z)) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP (A.inRange_mem_FP p) - simpa using this + exact this have hok : (fun z : List Bool => [g (okArg p z)]) ∈ FP := by have := mem_FP_comp (okArg_mem_FP p) hgFP - simpa using this + exact this have hflag : (fun z : List Bool => Cobham.selectHead (A.inRange p (pairFst z)) [g (okArg p z)] [true]) ∈ FP := Cobham.selectHeadFn_mem_FP hin hok (constFn_mem_FP [true]) @@ -290,10 +290,10 @@ theorem pos_eq {x ρ : List Bool} (h : 2 ^ ρ.length ≤ p.eval (pair x ρ).leng have hlow : A.lowFlag w = if i < A.width then [true] else [false] := by rcases Cobham.lenLeFlag_flag (List.replicate A.width true) (true :: pairSnd w) with hf | hf - · rw [lowFlag, hf, if_pos] + · rw [lowFlag, hf, ite_eq_left] rw [← lowFlag, A.lowFlag_eq_true_iff w, hsnd, List.length_replicate] at hf exact hf - · rw [lowFlag, hf, if_neg] + · rw [lowFlag, hf, ite_eq_right] intro hcon have := (A.lowFlag_eq_true_iff w).mpr (by rw [hsnd, List.length_replicate]; exact hcon) rw [lowFlag, hf] at this @@ -305,18 +305,18 @@ theorem pos_eq {x ρ : List Bool} (h : 2 ^ ρ.length ≤ p.eval (pair x ρ).leng have hoff : (A.offU w).length = if i < A.width then i else i - A.width := by rw [offU, hlow, hsnd] by_cases hi : i < A.width - · rw [if_pos hi, selectHead_cons_true, List.length_replicate, if_pos hi] - · rw [if_neg hi, selectHead_cons_false, List.length_drop, List.length_replicate, - if_neg hi] + · rw [ite_eq_left hi, selectHead_cons_true, List.length_replicate, ite_eq_left hi] + · rw [ite_eq_right hi, selectHead_cons_false, List.length_drop, List.length_replicate, + ite_eq_right hi] show (A.posU p w).length = _ rw [posU, List.length_append, List.length_replicate, List.length_replicate, hoff, posVal] congr 2 rw [hlow] by_cases hi : i < A.width - · rw [if_pos hi, selectHead_cons_true, hv] + · rw [ite_eq_left hi, selectHead_cons_true, hv] simp [hi] - · rw [if_neg hi, selectHead_cons_false, hv] + · rw [ite_eq_right hi, selectHead_cons_false, hv] simp [hi] /-- Edge `e` is satisfied by the proof `π`. -/ diff --git a/Complexitylib/Classes/PCP/Internal/Cheeger.lean b/Complexitylib/Classes/PCP/Internal/Cheeger.lean index 90395896..125da4ab 100644 --- a/Complexitylib/Classes/PCP/Internal/Cheeger.lean +++ b/Complexitylib/Classes/PCP/Internal/Cheeger.lean @@ -220,8 +220,8 @@ theorem coarea {h : ℝ} (hexp : G.EdgeExpansion h) : have hsum : ∑ v : G.V, ψ v = ∑ v : G.V, ψ' v + μ * S.card := by have : ∀ v, ψ v = ψ' v + (if v ∈ S then μ else 0) := fun v => by by_cases hv : v ∈ S - · rw [hψ'in v hv, if_pos hv]; ring - · rw [hψ'out v hv, if_neg hv, hz v hv]; ring + · rw [hψ'in v hv, ite_eq_left hv]; ring + · rw [hψ'out v hv, ite_eq_right hv, hz v hv]; ring rw [Finset.sum_congr rfl fun v _ => this v, Finset.sum_add_distrib] congr 1 rw [Finset.sum_ite_mem, Finset.univ_inter, Finset.sum_const, nsmul_eq_mul, mul_comm] @@ -231,18 +231,21 @@ theorem coarea {h : ℝ} (hexp : G.EdgeExpansion h) : + (if p.1 ∉ S ∧ G.nbr p.1 p.2 ∈ S then (1 : ℝ) else 0)) := by intro p by_cases hu : p.1 ∈ S <;> by_cases hw : G.nbr p.1 p.2 ∈ S - · rw [hψ'in _ hu, hψ'in _ hw, if_neg (by tauto), if_neg (by tauto)] + · rw [hψ'in _ hu, hψ'in _ hw, ite_eq_right (by tauto), ite_eq_right (by tauto)] have : ψ p.1 - μ - (ψ (G.nbr p.1 p.2) - μ) = ψ p.1 - ψ (G.nbr p.1 p.2) := by ring rw [this] ring - · rw [hψ'in _ hu, hψ'out _ hw, hz _ hw, if_pos ⟨hu, hw⟩, if_neg (by tauto), sub_zero, + · rw [hψ'in _ hu, hψ'out _ hw, hz _ hw, ite_eq_left ⟨hu, hw⟩, ite_eq_right (by tauto), + sub_zero, sub_zero, abs_of_nonneg (hpos _), abs_of_nonneg (by linarith [hμle _ hu])] ring - · rw [hψ'out _ hu, hψ'in _ hw, hz _ hu, if_neg (by tauto), if_pos ⟨hu, hw⟩, zero_sub, + · rw [hψ'out _ hu, hψ'in _ hw, hz _ hu, ite_eq_right (by tauto), ite_eq_left ⟨hu, hw⟩, + zero_sub, zero_sub, abs_neg, abs_neg, abs_of_nonneg (hpos _), abs_of_nonneg (by linarith [hμle _ hw])] ring - · rw [hψ'out _ hu, hψ'out _ hw, hz _ hu, hz _ hw, if_neg (by tauto), if_neg (by tauto)] + · rw [hψ'out _ hu, hψ'out _ hw, hz _ hu, hz _ hw, ite_eq_right (by tauto), + ite_eq_right (by tauto)] simp rw [Finset.sum_congr rfl fun p _ => hdart p, Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_add_distrib, G.sum_darts_boundary S, hsum] @@ -322,7 +325,7 @@ theorem exists_median (f : G.V → ℝ) : classical rcases isEmpty_or_nonempty G.V with hV | hV · exact ⟨0, by simp, by simp⟩ - haveI : Nonempty G.V := hV + have : Nonempty G.V := hV set T : Finset ℝ := (Finset.univ.image f).filter fun t => 2 * (Finset.univ.filter fun v => t < f v).card ≤ G.order with hT have hTne : T.Nonempty := by @@ -535,7 +538,7 @@ theorem spectralBound_padLoops_of_edgeExpansion {h : ℝ} (hexp : G.EdgeExpansio intro f hf have hd : (0 : ℝ) < G.deg := by exact_mod_cast G.deg_pos set B : G.V → ℝ := (G.padLoops G.deg).step f with hB - have hBmean : ∑ v : G.V, B v = 0 := by rw [hB, sum_lazy_step]; exact hf + have hBmean : ∑ v : G.V, B v = 0 := by rw [hB]; erw [sum_lazy_step]; exact hf -- the Rayleigh bound, on `f` and on `B f` have hray : ∀ g : G.V → ℝ, ∑ v : G.V, g v = 0 → G.lazyQ g g ≤ (4 * (G.deg : ℝ) * (1 - h ^ 2 / 4)) * ∑ v : G.V, (g v) ^ 2 := by @@ -547,7 +550,7 @@ theorem spectralBound_padLoops_of_edgeExpansion {h : ℝ} (hexp : G.EdgeExpansio have hB' := hray B hBmean -- `‖B f‖²` through the lazy form have hBB : ∑ v : G.V, (B v) ^ 2 = G.lazyQ f B / (4 * (G.deg : ℝ)) := by - rw [← sum_lazy_mul, hB] + erw [← sum_lazy_mul, hB] exact Finset.sum_congr rfl fun v _ => by ring have hcs := G.lazyQ_sq_le f B have hQf := G.lazyQ_nonneg f diff --git a/Complexitylib/Classes/PCP/Internal/Clique.lean b/Complexitylib/Classes/PCP/Internal/Clique.lean index d8a1f709..846ca9bd 100644 --- a/Complexitylib/Classes/PCP/Internal/Clique.lean +++ b/Complexitylib/Classes/PCP/Internal/Clique.lean @@ -83,7 +83,7 @@ theorem spectralBound_cliqueLoops {n : ℕ} (hn : 0 < n) : have hstep : ∀ v : (cliqueLoops n hn).V, (cliqueLoops n hn).step f v = 0 := by intro v rw [step_cliqueLoops hn f v, hf, zero_div] - simp [hstep] + simp only [hstep, zero_pow two_ne_zero, Finset.sum_const_zero, zero_mul, le_refl] end RegGraph diff --git a/Complexitylib/Classes/PCP/Internal/CloudDisagreement.lean b/Complexitylib/Classes/PCP/Internal/CloudDisagreement.lean index b215d1b9..d465877b 100644 --- a/Complexitylib/Classes/PCP/Internal/CloudDisagreement.lean +++ b/Complexitylib/Classes/PCP/Internal/CloudDisagreement.lean @@ -53,6 +53,8 @@ namespace ConstraintGraph variable {α : Type} [Fintype α] [DecidableEq α] [Nonempty α] variable (G : ConstraintGraph α) (E : ExpanderFamily) +attribute [local instance] Classical.propDecidable + /-! ### Plurality decoding -/ /-- The plurality label of `v`'s cloud: a label at least a `1 / card α` @@ -178,7 +180,7 @@ theorem card_dartsBetween_le_card_cloudUnsat (A : (G.reduce E).Assignment) (fun x => ((G.cloudList v)[x.1.val], some x.2)) ?_ ?_ · intro x hx simp only [Finset.mem_coe] at hx ⊢ - rw [RegGraph.dartsBetween, Finset.mem_filter] at hx + simp only [RegGraph.dartsBetween, Finset.mem_filter] at hx obtain ⟨-, hx1, hx2⟩ := hx have hnbr : (E.graph (G.cloudList v).length).nbr x.1 x.2 = (E.rot (G.cloudList v).length (x.1, x.2)).1 := rfl @@ -189,7 +191,7 @@ theorem card_dartsBetween_le_card_cloudUnsat (A : (G.reduce E).Assignment) have howner : G.owner (G.cloudList v)[x.1.val] = v := (G.mem_cloud).mp ((G.mem_cloudList).mp (List.getElem_mem x.1.isLt)) rw [cloudUnsat, Finset.mem_filter] - refine ⟨?_, howner, by simp⟩ + refine ⟨?_, howner, by exact Option.some_ne_none _⟩ rw [RegCSP.mem_unsatDarts] show ¬ ((A (G.cloudList v)[x.1.val] == A ((G.reduce E).graph.nbr (G.cloudList v)[x.1.val] (some x.2))) = true) diff --git a/Complexitylib/Classes/PCP/Internal/Compose.lean b/Complexitylib/Classes/PCP/Internal/Compose.lean index 37dfced7..32ce0c6c 100644 --- a/Complexitylib/Classes/PCP/Internal/Compose.lean +++ b/Complexitylib/Classes/PCP/Internal/Compose.lean @@ -62,7 +62,14 @@ inductive ReadIdx | k4qG | k4tG | k4cF | k4lF | i5r | i5c | i5b | i6r | i6c | i6b - deriving DecidableEq, Fintype + deriving DecidableEq + +open ReadIdx in +/-- All twenty-two reads, in declaration order. -/ +instance : Fintype ReadIdx where + elems := ⟨↑([f1x, f1y, f1s, g2x, g2y, g2s, c3cQ, c3tQ, c3cX, c3xX, c3cY, c3yY, + k4qG, k4tG, k4cF, k4lF, i5r, i5c, i5b, i6r, i6c, i6b] : List ReadIdx), by decide⟩ + complete := fun x => by cases x <;> decide theorem card_readIdx : Fintype.card ReadIdx = 22 := rfl @@ -393,7 +400,7 @@ omit [DecidableEq β] [Nonempty β] in theorem satisfiable_compose (h : R.Satisfiable) : (R.compose enc).toGraph.Satisfiable := by obtain ⟨σ, hσ⟩ := h refine (R.compose enc).satisfiable_toGraph (R.honestTable enc σ) fun p z => ?_ - rw [accepts_compose_iff] + erw [accepts_compose_iff] set a := oneHotExtend (inputVec enc (σ p.1) (σ (R.graph.nbr p.1 p.2))) with ha have hleft : leftBlock a = inputVec enc (σ p.1) (σ (R.graph.nbr p.1 p.2)) := leftBlock_oneHotExtend _ diff --git a/Complexitylib/Classes/PCP/Internal/ConsistencyLang.lean b/Complexitylib/Classes/PCP/Internal/ConsistencyLang.lean index b21d9cc3..4f1e385c 100644 --- a/Complexitylib/Classes/PCP/Internal/ConsistencyLang.lean +++ b/Complexitylib/Classes/PCP/Internal/ConsistencyLang.lean @@ -85,20 +85,20 @@ theorem conW_mem_FP : conW ∈ FP := theorem unary_conC1_mem_FP : (fun y => List.replicate (conC1 y) true) ∈ FP := by have := mem_FP_comp (mem_FP_comp conY1_mem_FP Cobham.sndBlock_mem_FP) unaryLength_mem_FP - simpa using this + exact this theorem unary_conC2_mem_FP : (fun y => List.replicate (conC2 y) true) ∈ FP := by have := mem_FP_comp (mem_FP_comp conY2_mem_FP Cobham.sndBlock_mem_FP) unaryLength_mem_FP - simpa using this + exact this theorem unary_conC3_mem_FP : (fun y => List.replicate (conC3 y) true) ∈ FP := by have := mem_FP_comp (mem_FP_comp Cobham.fstBlock_mem_FP Cobham.sndBlock_mem_FP) unaryLength_mem_FP - simpa using this + exact this theorem unary_conC4_mem_FP : (fun y => List.replicate (conC4 y) true) ∈ FP := by have := mem_FP_comp Cobham.sndBlock_mem_FP unaryLength_mem_FP - simpa using this + exact this /-! ### The check -/ @@ -143,21 +143,21 @@ include hr in theorem conRho_mem_FP : conRho r ∈ FP := by have ht : (fun y : List Bool => List.replicate (r (conX y).length) true) ∈ FP := by have := mem_FP_comp conX_mem_FP hr - simpa using this + exact this exact coinStr_mem_FP ht unary_conC1_mem_FP include hr in theorem conRho'_mem_FP : conRho' r ∈ FP := by have ht : (fun y : List Bool => List.replicate (r (conX y).length) true) ∈ FP := by have := mem_FP_comp conX_mem_FP hr - simpa using this + exact this exact coinStr_mem_FP ht unary_conC2_mem_FP include hf hr in theorem conP_mem_FP : conP f r ∈ FP := by have hb : (fun y => f (pair (conX y) (conRho r y))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP conX_mem_FP (conRho_mem_FP r hr)) hf - simpa using this + exact this have := posAt_mem_FP unary_conC3_mem_FP hb refine mem_FP_of_eq this fun y => ?_ rw [conP, List.length_replicate] @@ -166,7 +166,7 @@ include hf hr in theorem conP'_mem_FP : conP' f r ∈ FP := by have hb : (fun y => f (pair (conX y) (conRho' r y))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP conX_mem_FP (conRho'_mem_FP r hr)) hf - simpa using this + exact this have := posAt_mem_FP unary_conC4_mem_FP hb refine mem_FP_of_eq this fun y => ?_ rw [conP', List.length_replicate] @@ -250,11 +250,11 @@ theorem consLang_mem_P (hrlog : r =O fun n => Nat.log 2 n) : consLang f r Q ∈ have hexp : (fun z : List Bool => List.replicate (2 ^ r (pairFst z).length) true) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP (unaryExp_mem_FP_of_bigO_log hr hrlog) - simpa using this + exact this have hexp2 : (fun y : List Bool => List.replicate (2 ^ r (pairFst (pairFst y)).length) true) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP hexp - simpa using this + exact this have h1 : consL1 f r Q ∈ P := forall_unary_mem_P h2 hexp2 exact forall_unary_mem_P h1 hexp @@ -275,7 +275,7 @@ theorem exists_eqFlag_iff (a b : List Bool) : theorem mem_consInner_iff (y : List Bool) : y ∈ consInner f r Q ↔ (conP f r y = conP' f r y ∧ conP f r y ≠ [] → conB Q y = conB' Q y) := by - rw [consInner, Set.mem_setOf_eq, conChk] + rw [consInner, Set.mem_ofPred_eq, conChk] by_cases hcase : conP f r y = conP' f r y ∧ conP f r y ≠ [] · obtain ⟨heq, hne⟩ := hcase have h1 : Cobham.eqFlag (conP f r y) (conP' f r y) = [true] := @@ -285,7 +285,7 @@ theorem mem_consInner_iff (y : List Bool) : | nil => exact absurd hp hne | cons b t => rw [emptyFlag_cons] rw [h1, h2] - simp only [notBit, andBit, caseBit₀_cons, cond_false, cond_true] + simp only [notBit, andBit, caseBit₀_cons, Bool.cond_false, Bool.cond_true] rw [selectHead_cons_true, exists_eqFlag_iff] exact ⟨fun h _ => h, fun h => h ⟨heq, hne⟩⟩ · have hflag : andBit (Cobham.eqFlag (conP f r y) (conP' f r y)) @@ -389,13 +389,13 @@ theorem mem_consLang_iff_forall (x w : List Bool) : pair x w ∈ consLang f r Q ↔ ∀ c < 2 ^ r x.length, ∀ c' < 2 ^ r x.length, ∀ i < Q, ∀ i' < Q, conArg x w c c' i i' ∈ consInner f r Q := by - rw [consLang, Set.mem_setOf_eq, pairFst_pair] + rw [consLang, Set.mem_ofPred_eq, pairFst_pair] refine forall_congr' fun c => forall_congr' fun _ => ?_ - rw [consL1, Set.mem_setOf_eq, pairFst_pair, pairFst_pair] + rw [consL1, Set.mem_ofPred_eq, pairFst_pair, pairFst_pair] refine forall_congr' fun c' => forall_congr' fun _ => ?_ - rw [consL2, Set.mem_setOf_eq] + rw [consL2, Set.mem_ofPred_eq] refine forall_congr' fun i => forall_congr' fun _ => ?_ - rw [consL3, Set.mem_setOf_eq] + rw [consL3, Set.mem_ofPred_eq] rfl /-! ### The check is consistency -/ diff --git a/Complexitylib/Classes/PCP/Internal/CubeBlocks.lean b/Complexitylib/Classes/PCP/Internal/CubeBlocks.lean index 34dfa7a1..a3baf5da 100644 --- a/Complexitylib/Classes/PCP/Internal/CubeBlocks.lean +++ b/Complexitylib/Classes/PCP/Internal/CubeBlocks.lean @@ -100,7 +100,8 @@ theorem prob_leftBlock (P : Cube a → Prop) : rw [Fintype.card_fun, ZMod.card, Fintype.card_fin] rw [hcard] norm_num - rw [Finset.sum_congr rfl fun x _ => hinner x, ← Finset.mul_sum] + rw [Finset.sum_congr rfl fun x _ => hinner x, + ← Finset.mul_sum (s := Finset.univ) (a := (2 : ℝ) ^ b) (f := fun x : Cube a => 𝟙P x)] rw [pow_add] field_simp @@ -127,7 +128,8 @@ theorem prob_rightBlock (P : Cube b → Prop) : rw [Fintype.card_fun, ZMod.card, Fintype.card_fin] rw [hcard] norm_num - rw [Finset.sum_congr rfl fun y _ => hinner y, ← Finset.mul_sum] + rw [Finset.sum_congr rfl fun y _ => hinner y, + ← Finset.mul_sum (s := Finset.univ) (a := (2 : ℝ) ^ a) (f := fun y : Cube b => 𝟙P y)] rw [pow_add] field_simp @@ -217,7 +219,8 @@ theorem prob₂_eq_prob_blocks {n : ℕ} (P : Cube n → Cube n → Prop) : classical have hL : Pr₂[P] = 1 / 2 ^ n * ∑ x : Cube n, (1 / 2 ^ n * ∑ y : Cube n, indicator (P x) y) := by - rw [BooleanAnalysis.prob₂, expect_unfold] + rw [BooleanAnalysis.prob₂, + expect_unfold (f := fun x : Cube n => 𝔼[𝟙(P x)])] exact congrArg _ (Finset.sum_congr rfl fun x _ => expect_unfold _) have hR : Pr[fun z : Cube (n + n) => P (leftBlock z) (rightBlock z)] = 1 / 2 ^ (n + n) * ∑ p : Cube n × Cube n, indicator (P p.1) p.2 := by @@ -289,7 +292,7 @@ theorem prob_blocks {a b : ℕ} (Q : Cube a → Cube b → Prop) : simp only [indicator, h1, h2] have hR : 𝔼[fun u : Cube a => Pr[Q u]] = 1 / 2 ^ a * ∑ u : Cube a, (1 / 2 ^ b * ∑ v : Cube b, indicator (Q u) v) := by - rw [expect_unfold] + rw [expect_unfold (f := fun u : Cube a => Pr[Q u])] exact congrArg _ (Finset.sum_congr rfl fun u _ => expect_unfold _) rw [hL, hR, Fintype.sum_prod_type, ← Finset.mul_sum, pow_add] field_simp @@ -299,7 +302,7 @@ theorem prob_blocks_ge {a b : ℕ} (Q : Cube a → Cube b → Prop) (c : ℝ) (h : ∀ u, c ≤ Pr[Q u]) : c ≤ Pr[fun z : Cube (a + b) => Q (leftBlock z) (rightBlock z)] := by classical - rw [prob_blocks, expect_unfold] + rw [prob_blocks, expect_unfold (f := fun u : Cube a => Pr[Q u])] have hcard : (Finset.univ : Finset (Cube a)).card = 2 ^ a := by rw [Finset.card_univ] show Fintype.card (Fin a → ZMod 2) = 2 ^ a diff --git a/Complexitylib/Classes/PCP/Internal/DartCorrelation.lean b/Complexitylib/Classes/PCP/Internal/DartCorrelation.lean index a7144f17..f2bd00c3 100644 --- a/Complexitylib/Classes/PCP/Internal/DartCorrelation.lean +++ b/Complexitylib/Classes/PCP/Internal/DartCorrelation.lean @@ -237,7 +237,7 @@ theorem headCount_le (F : Finset (G.V × G.D)) (z : G.V) : G.headCount F z ≤ G have hinj : Set.InjOn (fun p : G.V × G.D => (G.rot p).2) (F.filter fun p => G.nbr p.1 p.2 = z) := by intro p hp p' hp' hval - simp only [Finset.coe_filter, Set.mem_setOf_eq] at hp hp' + simp only [Finset.coe_filter, Set.mem_ofPred_eq] at hp hp' have hp1 : (G.rot p).1 = z := hp.2 have hp'1 : (G.rot p').1 = z := hp'.2 have hpair : G.rot p = G.rot p' := Prod.ext (hp1.trans hp'1.symm) hval diff --git a/Complexitylib/Classes/PCP/Internal/DataScan.lean b/Complexitylib/Classes/PCP/Internal/DataScan.lean index 358bee94..d4db6e74 100644 --- a/Complexitylib/Classes/PCP/Internal/DataScan.lean +++ b/Complexitylib/Classes/PCP/Internal/DataScan.lean @@ -154,9 +154,9 @@ theorem eqFlag_replicate (c i : ℕ) : Cobham.eqFlag (List.replicate c true) (List.replicate i true) = if c = i then [true] else [false] := by by_cases h : c = i - · rw [if_pos h, h] + · rw [ite_eq_left h, h] exact (Cobham.eqFlag_eq_true_iff _ _).mpr rfl - · rw [if_neg h] + · rw [ite_eq_right h] rcases Cobham.eqFlag_flag (List.replicate c true) (List.replicate i true) with hf | hf · rw [Cobham.eqFlag_eq_true_iff] at hf exact absurd (by simpa using congrArg List.length hf) h @@ -294,10 +294,10 @@ theorem scanArg_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : b (fun z => scanArg (a z).length (b z)) ∈ FP := by have hrep : (fun z => List.replicate (a z).length true) ∈ FP := by have := mem_FP_comp ha unaryLength_mem_FP - simpa using this + exact this have hrev : (fun z => (b z).reverse) ∈ FP := by have := mem_FP_comp hb reverse_mem_FP - simpa using this + exact this exact Cobham.pairFn_mem_FP hrep hrev /-- **The scan extracts the child.** Reading the concatenated serializations of diff --git a/Complexitylib/Classes/PCP/Internal/DataScanSpec.lean b/Complexitylib/Classes/PCP/Internal/DataScanSpec.lean index 12e1aed8..5d9c55fc 100644 --- a/Complexitylib/Classes/PCP/Internal/DataScanSpec.lean +++ b/Complexitylib/Classes/PCP/Internal/DataScanSpec.lean @@ -132,7 +132,7 @@ theorem runSpec_toBits (i : ℕ) (y : Data) : simpa using this -- Now the value at hand. rw [hsplit, runSpec_cons, hstep0, runSpec_append, ihx (d + 1) c acc₁, - if_neg (Nat.succ_ne_zero d)] + ite_eq_right (Nat.succ_ne_zero d)] set acc₂ := if c = i then acc₁ ++ x.toBits else acc₁ with hacc₂ rw [huni acc₂, hD, hC] refine Prod.ext rfl (Prod.ext rfl ?_) @@ -140,12 +140,12 @@ theorem runSpec_toBits (i : ℕ) (y : Data) : · have hR' : R = F := by simp only [hc, hacc₁] at hacc simpa using hacc.symm - rw [hacc₂, hacc₁, if_pos hc, if_pos hc, if_pos hc, hR'] + rw [hacc₂, hacc₁, ite_eq_left hc, ite_eq_left hc, ite_eq_left hc, hR'] simp · have hR' : R = [] := by - simp only [if_neg hc, hacc₁] at hacc + simp only [ite_eq_right hc, hacc₁] at hacc simpa using hacc.symm - rw [hacc₂, hacc₁, if_neg hc, if_neg hc, if_neg hc, hR'] + rw [hacc₂, hacc₁, ite_eq_right hc, ite_eq_right hc, ite_eq_right hc, hR'] simp /-! ### A run of children -/ @@ -170,36 +170,36 @@ theorem runSpec_flatten (i : ℕ) : | nil => intro c acc; simp | cons x xs ih => intro c acc - rw [List.map_cons, List.flatten_cons, runSpec_append, runSpec_toBits, if_pos rfl, ih] + rw [List.map_cons, List.flatten_cons, runSpec_append, runSpec_toBits, ite_eq_left rfl, ih] refine Prod.ext rfl (Prod.ext (by simp [List.length_cons]; omega) ?_) simp only by_cases hlt : c < i · have h : c < i := hlt have h1 : selFrom (x :: xs) i c = selFrom xs i (c + 1) := by - rw [selFrom, selFrom, if_pos (by omega : c ≤ i), if_pos (by omega)] + rw [selFrom, selFrom, ite_eq_left (by omega : c ≤ i), ite_eq_left (by omega)] have : i - c = (i - (c + 1)) + 1 := by omega rw [this] simp - rw [if_neg (by omega), h1] + rw [ite_eq_right (by omega), h1] by_cases heq : c = i · subst heq have h1 : selFrom (x :: xs) c c = x.toBits := by - rw [selFrom, if_pos (by omega : c ≤ c)] + rw [selFrom, ite_eq_left (by omega : c ≤ c)] simp have h2 : selFrom xs c (c + 1) = [] := by - rw [selFrom, if_neg (by omega)] - rw [if_pos rfl, h1, h2, List.append_assoc, List.append_nil] + rw [selFrom, ite_eq_right (by omega)] + rw [ite_eq_left rfl, h1, h2, List.append_assoc, List.append_nil] · have h : i < c := by omega - have h1 : selFrom (x :: xs) i c = [] := by rw [selFrom, if_neg (by omega)] - have h2 : selFrom xs i (c + 1) = [] := by rw [selFrom, if_neg (by omega)] - rw [if_neg (by omega), h1, h2] + have h1 : selFrom (x :: xs) i c = [] := by rw [selFrom, ite_eq_right (by omega)] + have h2 : selFrom xs i (c + 1) = [] := by rw [selFrom, ite_eq_right (by omega)] + rw [ite_eq_right (by omega), h1, h2] /-- **The pass over a serialized list.** Reading the bits strictly between the outer brackets returns the requested child's own serialization. -/ theorem runSpec_inner (i : ℕ) (xs : List Data) : runSpec i (0, 0, []) ((xs.map Data.toBits).flatten) = (0, xs.length, ((xs[i]?).map Data.toBits).getD []) := by - rw [runSpec_flatten, selFrom, if_pos (Nat.zero_le i)] + rw [runSpec_flatten, selFrom, ite_eq_left (Nat.zero_le i)] simp end DataScan diff --git a/Complexitylib/Classes/PCP/Internal/DegreeReduction.lean b/Complexitylib/Classes/PCP/Internal/DegreeReduction.lean index 439668b1..1a84803d 100644 --- a/Complexitylib/Classes/PCP/Internal/DegreeReduction.lean +++ b/Complexitylib/Classes/PCP/Internal/DegreeReduction.lean @@ -149,12 +149,12 @@ theorem cloudRotAux_involutive {l : List G.HalfEdge} (hnd : l.Nodup) {p : G.Half set q := E.rot l.length (⟨l.idxOf p, hlt⟩, j) with hq have hq1 : q.1.val < l.length := q.1.isLt have hstep : G.cloudRotAux E l p j = (l.getD q.1.val p, q.2) := by - rw [cloudRotAux, dif_pos hlt] + rw [cloudRotAux, dite_eq_left hlt] have hget : l.getD q.1.val p = l[q.1.val] := (List.getElem_eq_getD p).symm have hidx' : l.idxOf l[q.1.val] = q.1.val := hnd.idxOf_getElem _ hq1 have hlt' : l.idxOf (l.getD q.1.val p) < l.length := by rw [hget, hidx']; exact hq1 - rw [hstep, cloudRotAux, dif_pos hlt'] + rw [hstep, cloudRotAux, dite_eq_left hlt'] have hval : l.idxOf (l.getD q.1.val p) = q.1.val := by rw [hget, hidx'] have hfin : (⟨l.idxOf (l.getD q.1.val p), hlt'⟩ : Fin l.length) = q.1 := Fin.ext hval rw [hfin] @@ -176,7 +176,7 @@ theorem cloudRotAux_mem {l : List G.HalfEdge} {p : G.HalfEdge} (hp : p ∈ l) have hlt : l.idxOf p < l.length := List.idxOf_lt_length_iff.mpr hp have hq1 : (E.rot l.length (⟨l.idxOf p, hlt⟩, j)).1.val < l.length := (E.rot l.length (⟨l.idxOf p, hlt⟩, j)).1.isLt - rw [cloudRotAux, dif_pos hlt] + rw [cloudRotAux, dite_eq_left hlt] dsimp only rw [← List.getElem_eq_getD (h := hq1)] exact List.getElem_mem hq1 @@ -202,7 +202,7 @@ theorem cloudRot_getElem (v : Fin G.numVerts) (i : Fin (G.cloudList v).length) (G.nodup_cloudList v).idxOf_getElem _ i.isLt have hlt : (G.cloudList v).idxOf ((G.cloudList v)[i.val]) < (G.cloudList v).length := by rw [hidx]; exact i.isLt - rw [cloudRot, howner, cloudRotAux, dif_pos hlt] + rw [cloudRot, howner, cloudRotAux, dite_eq_left hlt] have hfin : (⟨(G.cloudList v).idxOf ((G.cloudList v)[i.val]), hlt⟩ : Fin (G.cloudList v).length) = i := Fin.ext hidx rw [hfin] @@ -288,24 +288,24 @@ theorem satisfiable_reduce_of_satisfiable (h : G.Satisfiable) : (G.reduce E).Sat dsimp only show (if p.2 then G.rel p.1 (σ (G.owner ((G.reduceGraph E).nbr p none))) (σ (G.owner p)) else G.rel p.1 (σ (G.owner p)) (σ (G.owner ((G.reduceGraph E).nbr p none)))) = true - rw [nbr_reduceGraph_none] + rw [nbr_reduceGraph_none G E p] have hedge := hσ p.1 rw [Satisfies, satisfies] at hedge by_cases hb : p.2 = true · have h1 : G.owner p = G.head p.1 := by simp [owner, hb] have h2 : G.owner (G.flipHalf p) = G.tail p.1 := by simp [owner, flipHalf, hb] - rw [if_pos hb, h1, h2] + rw [ite_eq_left hb, h1, h2] exact hedge · have hb' : p.2 = false := by simpa using hb have h1 : G.owner p = G.tail p.1 := by simp [owner, hb'] have h2 : G.owner (G.flipHalf p) = G.head p.1 := by simp [owner, flipHalf, hb'] - rw [if_neg hb, h1, h2] + rw [ite_eq_right hb, h1, h2] exact hedge · -- a cloud-link joins half-edges with the same endpoint rw [RegCSP.Satisfies, RegCSP.satisfies] dsimp only show ((σ (G.owner p) == σ (G.owner ((G.reduceGraph E).nbr p (some j)))) = true) - rw [nbr_reduceGraph_some, G.owner_cloudRot E p j] + rw [nbr_reduceGraph_some G E p j, G.owner_cloudRot E p j] simp end ConstraintGraph diff --git a/Complexitylib/Classes/PCP/Internal/DegreeReductionSound.lean b/Complexitylib/Classes/PCP/Internal/DegreeReductionSound.lean index 439b04b2..95c4fece 100644 --- a/Complexitylib/Classes/PCP/Internal/DegreeReductionSound.lean +++ b/Complexitylib/Classes/PCP/Internal/DegreeReductionSound.lean @@ -56,6 +56,8 @@ noncomputable def reduceConst (E : ExpanderFamily) (α : Type) [Fintype α] : variable {α : Type} [Fintype α] [DecidableEq α] [Nonempty α] variable (G : ConstraintGraph α) (E : ExpanderFamily) +attribute [local instance] Classical.propDecidable + /-! ### Splitting the unsatisfied darts -/ /-- The unsatisfied cloud-links. -/ @@ -150,7 +152,7 @@ theorem card_goodEdges_le (A : (G.reduce E).Assignment) : show G.flipHalf (e, false) = (e, true) simp [flipHalf] rw [hnbr] - simp only [if_neg (by simp : ¬ (((e, false) : G.HalfEdge).2 = true))] + simp only [ite_eq_right (by simp : ¬ (((e, false) : G.HalfEdge).2 = true))] rw [hA0, hA1] rw [mem_unsatEdges] at hfail rw [Satisfies, satisfies] at hfail diff --git a/Complexitylib/Classes/PCP/Internal/Dinur.lean b/Complexitylib/Classes/PCP/Internal/Dinur.lean index a6068664..530d23f1 100644 --- a/Complexitylib/Classes/PCP/Internal/Dinur.lean +++ b/Complexitylib/Classes/PCP/Internal/Dinur.lean @@ -92,7 +92,7 @@ theorem basisVec_injective (n : ℕ) : Function.Injective (basisVec (n := n)) := intro i j hij have h := congrFun hij i by_contra hne - simp only [basisVec, if_true, if_neg hne] at h + simp only [basisVec, ite_true, ite_eq_right hne] at h exact absurd h (by decide) /-- The encoding of a powered label: the basis vector at its index. -/ diff --git a/Complexitylib/Classes/PCP/Internal/ExpanderMerge.lean b/Complexitylib/Classes/PCP/Internal/ExpanderMerge.lean index accc8433..eeadf351 100644 --- a/Complexitylib/Classes/PCP/Internal/ExpanderMerge.lean +++ b/Complexitylib/Classes/PCP/Internal/ExpanderMerge.lean @@ -95,7 +95,8 @@ theorem sum_sq_step_lift_le (hn : 0 < n) (hd : 0 < d) (rot : Fin N × Fin d → have hFsq := G.sum_sq_center hordpos F rw [hord] at hFsq have hmean : (N : ℝ) * (G.mean F) ^ 2 = (∑ u, F u) ^ 2 / (N : ℝ) := by - rw [mean, hord] + unfold mean + rw [hord] field_simp rfl show ∑ u, G.step F u ^ 2 ≤ lam ^ 2 * ∑ u, F u ^ 2 + (1 - lam ^ 2) * ((∑ u, F u) ^ 2 / (N : ℝ)) @@ -129,7 +130,7 @@ theorem liftN_isSome {N n m : ℕ} (hm : (m - 1) * n ≤ N) (v : Fin n) {i : ℕ calc v.val + i * n < n + i * n := by omega _ = (i + 1) * n := by ring _ ≤ (m - 1) * n := Nat.mul_le_mul_right _ h1 - rw [dif_pos (lt_of_lt_of_le hle hm)] + rw [dite_eq_left (lt_of_lt_of_le hle hm)] rfl /-- **So at most one slot is empty.** -/ diff --git a/Complexitylib/Classes/PCP/Internal/ExpanderPad.lean b/Complexitylib/Classes/PCP/Internal/ExpanderPad.lean index b616f939..8a078bc7 100644 --- a/Complexitylib/Classes/PCP/Internal/ExpanderPad.lean +++ b/Complexitylib/Classes/PCP/Internal/ExpanderPad.lean @@ -6,7 +6,7 @@ Authors: Bolton Bailey module public import Complexitylib.Classes.PCP.Internal.Expander public import Complexitylib.Classes.PCP.Internal.Mixing -public import Mathlib.Data.Real.Sqrt +public import Mathlib.Analysis.Real.Sqrt /-! # Relabelling darts and padding with loops @@ -87,7 +87,8 @@ theorem spectralBound_relabel {D' : Type} [DecidableEq D'] [Fintype D'] (e : G.D {lam : ℝ} (h : G.SpectralBound lam) : (G.relabel e).SpectralBound lam := by intro f hf have := h f hf - simp only [step_relabel] + have hs : ∀ v, (G.relabel e).step f v = G.step f v := fun v => step_relabel G e f v + simp only [hs] exact this /-! ### Padding with loops -/ @@ -125,7 +126,7 @@ theorem step_padLoops (k : ℕ) (f : G.V → ℝ) (v : G.V) : (G.padLoops k).step f v = ((G.deg : ℝ) * G.step f v + (k : ℝ) * f v) / ((G.deg : ℝ) + k) := by have hd : (G.deg : ℝ) ≠ 0 := G.deg_ne_zero - rw [step, deg_padLoops] + unfold step; erw [deg_padLoops] show (∑ i : G.D ⊕ Fin k, f ((G.padLoops k).nbr v i)) / ((G.deg + k : ℕ) : ℝ) = _ rw [Fintype.sum_sum_type] have h1 : ∀ i : G.D, (G.padLoops k).nbr v (Sum.inl i) = G.nbr v i := fun i => rfl @@ -133,7 +134,7 @@ theorem step_padLoops (k : ℕ) (f : G.V → ℝ) (v : G.V) : simp only [h1, h2, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] push_cast congr 1 - rw [step, mul_div_cancel₀ _ hd] + rw [mul_div_cancel₀ _ hd] /-- **Padding keeps the bound**, with `μ² = α λ² + (1 - α)` for `α` the fraction of real darts. -/ @@ -153,7 +154,7 @@ theorem spectralBound_padLoops (k : ℕ) {lam : ℝ} (h : G.SpectralBound lam) : -- Jensen for two terms have hpt : ∀ v, ((G.padLoops k).step f v) ^ 2 ≤ a * (G.step f v) ^ 2 + (1 - a) * (f v) ^ 2 := by intro v - rw [step_padLoops] + erw [step_padLoops] have hrw : ((G.deg : ℝ) * G.step f v + (k : ℝ) * f v) / ((G.deg : ℝ) + k) = a * G.step f v + (1 - a) * f v := by rw [← hb, ha]; field_simp @@ -215,8 +216,8 @@ theorem spectralBound_relabelV {V' : Type} [DecidableEq V'] [Fintype V'] (e : G. = ∑ w : G.V, (G.step (fun w => f (e w)) w) ^ 2 := (Fintype.sum_equiv e (fun w => (G.step (fun w => f (e w)) w) ^ 2) (fun v => ((G.relabelV e).step f v) ^ 2) fun w => by - dsimp only - rw [step_relabelV, Equiv.symm_apply_apply]).symm + show (G.step (fun w => f (e w)) w) ^ 2 = ((G.relabelV e).step f (e w)) ^ 2 + rw [step_relabelV (G := G) (e := e) (f := f) (v := e w), Equiv.symm_apply_apply]).symm _ ≤ lam ^ 2 * ∑ w : G.V, (f (e w)) ^ 2 := hb _ = lam ^ 2 * ∑ v : V', (f v) ^ 2 := by congr 1 @@ -231,10 +232,10 @@ noncomputable def toFinForm : RegGraph := (G.relabelV (Fintype.equivFin G.V)).relabel (Fintype.equivFin G.D) @[simp] theorem order_toFinForm : G.toFinForm.order = G.order := by - rw [toFinForm, order_relabel, order_relabelV] + unfold toFinForm; erw [ order_relabel, order_relabelV] @[simp] theorem deg_toFinForm : G.toFinForm.deg = G.deg := by - rw [toFinForm, deg_relabel, deg_relabelV] + unfold toFinForm; erw [ deg_relabel, deg_relabelV] theorem spectralBound_toFinForm {lam : ℝ} (h : G.SpectralBound lam) : G.toFinForm.SpectralBound lam := diff --git a/Complexitylib/Classes/PCP/Internal/ExpanderRandom.lean b/Complexitylib/Classes/PCP/Internal/ExpanderRandom.lean index d6187367..77470726 100644 --- a/Complexitylib/Classes/PCP/Internal/ExpanderRandom.lean +++ b/Complexitylib/Classes/PCP/Internal/ExpanderRandom.lean @@ -54,7 +54,8 @@ theorem ten_mul_tOf_le (S : Finset (Fin n)) : 10 * tOf S ≤ S.card := by theorem mem_escLE_iff {S : Finset (Fin n)} {σ : Equiv.Perm (Fin n)} (hS : 1 ≤ S.card) : σ ∈ escLE S (tOf S) ↔ ¬ S.card ≤ 10 * escape σ S := by - simp only [escLE, Finset.mem_filter, Finset.mem_univ, true_and, tOf] + simp only [escLE, Finset.mem_filter, Finset.mem_univ, true_and] + unfold tOf omega /-- The bound on how many permutations fail to expand a set of size `s`. -/ diff --git a/Complexitylib/Classes/PCP/Internal/ExpanderizeCSP.lean b/Complexitylib/Classes/PCP/Internal/ExpanderizeCSP.lean index 7a2ae681..a2d11a6a 100644 --- a/Complexitylib/Classes/PCP/Internal/ExpanderizeCSP.lean +++ b/Complexitylib/Classes/PCP/Internal/ExpanderizeCSP.lean @@ -62,9 +62,7 @@ theorem card_unsatDarts_addTrivial (a : R.Assignment) : classical refine (Finset.card_bij (fun q _ => ((q.1, Sum.inl q.2) : (R.addTrivial H e).Dart)) ?_ ?_ ?_).symm · intro q hq - rw [mem_unsatDarts] at hq ⊢ - intro hcon - exact hq hcon + exact (mem_unsatDarts (R := R.addTrivial H e)).mpr ((mem_unsatDarts (R := R)).mp hq) · intro q _ q' _ heq have h1 : q.1 = q'.1 := congrArg (fun r => (r.1 : R.graph.V)) heq have h2 : Sum.inl q.2 = (Sum.inl q'.2 : R.graph.D ⊕ H.D) := @@ -72,12 +70,8 @@ theorem card_unsatDarts_addTrivial (a : R.Assignment) : exact Prod.ext h1 (Sum.inl.inj h2) · rintro ⟨v, i | j⟩ hq · refine ⟨(v, i), ?_, rfl⟩ - rw [mem_unsatDarts] at hq ⊢ - intro hcon - exact hq hcon - · exfalso - rw [mem_unsatDarts] at hq - exact hq rfl + exact (mem_unsatDarts (R := R)).mpr ((mem_unsatDarts (R := R.addTrivial H e)).mp hq) + · exact absurd rfl ((mem_unsatDarts (R := R.addTrivial H e)).mp hq) /-- Superposing trivial constraints scales the value by `deg / (deg + deg')`. -/ theorem unsatFrac_addTrivial (a : R.Assignment) : @@ -93,10 +87,12 @@ theorem unsatFrac_addTrivial (a : R.Assignment) : rw [hz] at hle omega have hempty' : ((R.addTrivial H e).unsatDarts a).card = 0 := by rw [hcards, hempty] - rw [unsatFrac, unsatFrac, hempty, hempty'] + unfold unsatFrac + rw [hempty, hempty'] simp · have hzq : (0 : ℚ) < (R.graph.order : ℚ) := by exact_mod_cast hz - rw [unsatFrac, unsatFrac, hcards] + unfold unsatFrac + rw [hcards] have hden : (((R.addTrivial H e).graph.order * (R.addTrivial H e).graph.deg : ℕ) : ℚ) = (R.graph.order : ℚ) * ((R.graph.deg : ℚ) + (H.deg : ℚ)) := by rw [graph_addTrivial, RegGraph.order_union, RegGraph.deg_union] @@ -129,16 +125,13 @@ theorem satisfiable_addTrivial_iff : (R.addTrivial H e).Satisfiable ↔ R.Satisf · rintro ⟨a, ha⟩ refine ⟨a, fun p => ?_⟩ have h := ha (p.1, Sum.inl p.2) - rw [Satisfies, satisfies] at h ⊢ exact h · rintro ⟨a, ha⟩ refine ⟨a, ?_⟩ rintro ⟨v, i | j⟩ · have h := ha (v, i) - rw [Satisfies, satisfies] at h ⊢ exact h - · rw [Satisfies, satisfies] - rfl + · rfl /-- `R` with a family expander superposed. -/ noncomputable def expanderize (R : RegCSP α) [NumEnc R.graph.V] (E : ExpanderFamily) : diff --git a/Complexitylib/Classes/PCP/Internal/FamilyFin.lean b/Complexitylib/Classes/PCP/Internal/FamilyFin.lean index a42c396d..7b0eec3b 100644 --- a/Complexitylib/Classes/PCP/Internal/FamilyFin.lean +++ b/Complexitylib/Classes/PCP/Internal/FamilyFin.lean @@ -242,13 +242,15 @@ noncomputable def famRot (n : ℕ) : Fin n × Fin F.famDeg → Fin n × Fin F.fa if hn : 0 < n then (F.famGraph hd hn).rot else id theorem famRot_involutive (n : ℕ) : Function.Involutive (F.famRot hd n) := by - rw [famRot] - split - · exact (F.famGraph hd ‹_›).rot_involutive - · exact fun x => rfl + unfold famRot + by_cases hn : 0 < n + · erw [dite_eq_left hn] + exact (F.famGraph hd hn).rot_involutive + · erw [dite_eq_right hn] + exact fun x => rfl theorem famRot_eq {n : ℕ} (hn : 0 < n) : F.famRot hd n = (F.famGraph hd hn).rot := by - rw [famRot, dif_pos hn] + erw [famRot, dite_eq_left hn] theorem spectral_famRot (n : ℕ) : (RegGraph.ofRot F.famDeg F.famDeg_pos n (F.famRot hd n) @@ -280,7 +282,7 @@ theorem famDartName_symm_of_lt {n : ℕ} (hn : 0 < n) (i : Fin F.famDeg) = Sum.inl (⟨i.val / F.fitD, by exact (Nat.div_lt_iff_lt_mul F.fitD_pos).mpr h⟩, ⟨i.val % F.fitD, Nat.mod_lt _ F.fitD_pos⟩) := by - rw [Equiv.symm_apply_eq] + erw [Equiv.symm_apply_eq] refine Fin.ext ?_ show i.val = i.val % F.fitD + F.fitD * (i.val / F.fitD) exact (Nat.mod_add_div i.val F.fitD).symm @@ -291,7 +293,7 @@ theorem famDartName_symm_of_ge {n : ℕ} (hn : 0 < n) (i : Fin F.famDeg) = (Sum.inr ⟨i.val - F.wid hd n * F.fitD, by have := i.isLt omega⟩ : (F.paddedG hd hn).D) := by - rw [Equiv.symm_apply_eq] + erw [Equiv.symm_apply_eq] refine Fin.ext ?_ show i.val = F.wid hd n * F.fitD + (i.val - F.wid hd n * F.fitD) omega @@ -318,10 +320,10 @@ theorem famRotVal_eq {n : ℕ} (hn : 0 < n) (v : Fin n) (i : Fin F.famDeg) : i = F.famDartName hd hn (Sum.inl (s, c)) := by refine ⟨⟨i.val / F.fitD, (Nat.div_lt_iff_lt_mul F.fitD_pos).mpr hi⟩, ⟨i.val % F.fitD, Nat.mod_lt _ F.fitD_pos⟩, ?_⟩ - rw [← Equiv.symm_apply_eq] + erw [← Equiv.symm_apply_eq] exact F.famDartName_symm_of_lt hd hn i hi simp only [famGraph, RegGraph.relabel, val_famDartName_inl] - rw [Equiv.symm_apply_apply] + erw [Equiv.symm_apply_apply] show F.famRotVal hd n (v.val, c.val + F.fitD * s.val) = (((F.mergedG hd hn).rot (v, (s, c))).1.val, ((F.famDartName hd hn) @@ -329,7 +331,7 @@ theorem famRotVal_eq {n : ℕ} (hn : 0 < n) (v : Fin n) (i : Fin F.famDeg) : by_cases hu : v.val + s.val * n < F.fitN hd n · have hlift : RegGraph.liftN (F.fitN hd n) n v s.val = some (⟨v.val + s.val * n, hu⟩ : Fin (F.fitN hd n)) := by - rw [RegGraph.liftN, dif_pos hu] + rw [RegGraph.liftN, dite_eq_left hu] simp only [mergedG, RegGraph.mergedN, RegGraph.mergeRotN, hlift] have hlt : c.val + F.fitD * s.val < F.wid hd n * F.fitD := by have h1 : c.val < F.fitD := c.isLt @@ -341,12 +343,12 @@ theorem famRotVal_eq {n : ℕ} (hn : 0 < n) (v : Fin n) (i : Fin F.famDeg) : rw [Nat.add_mul_mod_self_left, Nat.mod_eq_of_lt c.isLt] have hrot := F.rotVal_eq (F.fitLevel hd n) (⟨v.val + s.val * n, hu⟩ : Fin (F.size (F.fitLevel hd n))) c - rw [famRotVal, if_pos hlt] + rw [famRotVal, ite_eq_left hlt] dsimp only - rw [hs, hc, if_pos hu, hrot] + rw [hs, hc, ite_eq_left hu, hrot] rfl · have hlift : RegGraph.liftN (F.fitN hd n) n v s.val = none := by - rw [RegGraph.liftN, dif_neg hu] + rw [RegGraph.liftN, dite_eq_right hu] simp only [mergedG, RegGraph.mergedN, RegGraph.mergeRotN, hlift] have hlt : c.val + F.fitD * s.val < F.wid hd n * F.fitD := by have h1 : c.val < F.fitD := c.isLt @@ -354,20 +356,20 @@ theorem famRotVal_eq {n : ℕ} (hn : 0 < n) (v : Fin n) (i : Fin F.famDeg) : nlinarith have hs : (c.val + F.fitD * s.val) / F.fitD = s.val := by rw [Nat.add_mul_div_left _ _ F.fitD_pos, Nat.div_eq_of_lt c.isLt, Nat.zero_add] - rw [famRotVal, if_pos hlt] + rw [famRotVal, ite_eq_left hlt] dsimp only - rw [hs, if_neg hu] + rw [hs, ite_eq_right hu] rfl · obtain ⟨j, rfl⟩ : ∃ j : Fin (F.famDeg - F.wid hd n * F.fitD), i = F.famDartName hd hn (Sum.inr j : (F.paddedG hd hn).D) := by refine ⟨⟨i.val - F.wid hd n * F.fitD, by have := i.isLt; omega⟩, ?_⟩ - rw [← Equiv.symm_apply_eq] + erw [← Equiv.symm_apply_eq] exact F.famDartName_symm_of_ge hd hn i (by omega) simp only [famGraph, RegGraph.relabel] - rw [Equiv.symm_apply_apply] + erw [Equiv.symm_apply_apply] have hge : ¬ (F.wid hd n * F.fitD + j.val < F.wid hd n * F.fitD) := by omega show F.famRotVal hd n (v.val, F.wid hd n * F.fitD + j.val) = _ - rw [famRotVal, if_neg hge] + rw [famRotVal, ite_eq_right hge] rfl /-- **The expander family the numbered tower generates**: one member at every diff --git a/Complexitylib/Classes/PCP/Internal/FiniteKey.lean b/Complexitylib/Classes/PCP/Internal/FiniteKey.lean index e81278de..29ff8dc5 100644 --- a/Complexitylib/Classes/PCP/Internal/FiniteKey.lean +++ b/Complexitylib/Classes/PCP/Internal/FiniteKey.lean @@ -73,9 +73,9 @@ theorem mem_P_of_bounded_key {key : List Bool → List Bool} (hkey : key ∈ FP) refine mem_P_of_decisionFn hcomp fun z => ?_ show Q (key z) ↔ _ by_cases h : Q (key z) - · rw [if_pos (mem_keySet.mpr ⟨hL z, h⟩)] + · rw [ite_eq_left (mem_keySet.mpr ⟨hL z, h⟩)] exact ⟨fun _ => ⟨true, by simp, rfl⟩, fun _ => h⟩ - · rw [if_neg (fun hcon => h (mem_keySet.mp hcon).2)] + · rw [ite_eq_right (fun hcon => h (mem_keySet.mp hcon).2)] simp [h] /-- **A bounded-key value is in `FP`.** The rule computing the value from the @@ -88,7 +88,7 @@ theorem mem_FP_of_bounded_key {key : List Bool → List Bool} (hkey : key ∈ FP ite_mem_finset_mem_FP g (keySet L (fun _ => True)) have hcomp := mem_FP_comp hkey hite refine mem_FP_of_eq hcomp fun z => ?_ - rw [Function.comp_apply, if_pos (mem_keySet.mpr ⟨hL z, trivial⟩)] + rw [Function.comp_apply, ite_eq_left (mem_keySet.mpr ⟨hL z, trivial⟩)] /-- **A value that depends on its input only through a bounded key is in `FP`.** No rule computing the value from the key need be exhibited: agreeing wherever @@ -100,7 +100,7 @@ theorem mem_FP_of_key_congr {key : List Bool → List Bool} (hkey : key ∈ FP) refine mem_FP_of_eq (mem_FP_of_bounded_key hkey hL (fun s => if h : ∃ z, key z = s then val (Classical.choose h) else [])) fun z => ?_ have hex : ∃ w, key w = key z := ⟨z, rfl⟩ - rw [dif_pos hex] + rw [dite_eq_left hex] exact hcongr _ z (Classical.choose_spec hex) end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/GuessVerifyGeneric.lean b/Complexitylib/Classes/PCP/Internal/GuessVerifyGeneric.lean index a0ba9699..2d90d5b0 100644 --- a/Complexitylib/Classes/PCP/Internal/GuessVerifyGeneric.lean +++ b/Complexitylib/Classes/PCP/Internal/GuessVerifyGeneric.lean @@ -109,7 +109,7 @@ theorem padVerifier_mem_P {p : Polynomial ℕ} {L₀ : Language} (hL₀ : L₀ (polyRuler p (pairFst (pairFst w))).length ≤ (pairSnd (pairFst w)).length} ∈ P := by refine mem_P_of_decisionFn (lenLeFlagFn_mem_FP hsf hruler) fun w => ?_ - simp only [Set.mem_setOf_eq] + simp only [Set.mem_ofPred_eq] set a := pairSnd (pairFst w) with ha set b := polyRuler p (pairFst (pairFst w)) with hb constructor diff --git a/Complexitylib/Classes/PCP/Internal/Hadamard.lean b/Complexitylib/Classes/PCP/Internal/Hadamard.lean index b147c3f1..037299e3 100644 --- a/Complexitylib/Classes/PCP/Internal/Hadamard.lean +++ b/Complexitylib/Classes/PCP/Internal/Hadamard.lean @@ -96,24 +96,24 @@ theorem parityFun_basis (S : Finset (Fin n)) (i : Fin n) : classical rw [parityFun] by_cases hi : i ∈ S - · rw [if_pos hi] + · rw [ite_eq_left hi] rw [Finset.prod_eq_single i] · show chi (if i = i then (1 : ZMod 2) else 0) = -1 - rw [if_pos rfl] + rw [ite_eq_left rfl] show chi 1 = -1 simp · intro j _ hj show chi (if j = i then (1 : ZMod 2) else 0) = 1 - rw [if_neg hj] + rw [ite_eq_right hj] show chi 0 = 1 simp · intro hni exact absurd hi hni - · rw [if_neg hi] + · rw [ite_eq_right hi] refine Finset.prod_eq_one fun j hj => ?_ have hji : j ≠ i := fun h => hi (h ▸ hj) show chi (if j = i then (1 : ZMod 2) else 0) = 1 - rw [if_neg hji] + rw [ite_eq_right hji] show chi 0 = 1 simp @@ -214,7 +214,7 @@ theorem parity_eq_signOf_hadamard (S : Finset (Fin n)) : rw [signOf_hadamard] congr 1 ext i - simp only [Finset.mem_filter, Finset.mem_univ, true_and, indicatorAssign] + simp only [indicatorAssign] by_cases hi : i ∈ S · simp [hi] · simp [hi] @@ -237,10 +237,10 @@ theorem hadamard_basisVec (a : Cube n) (i : Fin n) : hadamard a (basisVec i) = a show ∑ j, a j * (basisVec i) j = a i rw [Finset.sum_eq_single i] · show a i * (if i = i then (1 : ZMod 2) else 0) = a i - rw [if_pos rfl, mul_one] + rw [ite_eq_left rfl, mul_one] · intro j _ hj show a j * (if j = i then (1 : ZMod 2) else 0) = 0 - rw [if_neg hj, mul_zero] + rw [ite_eq_right hj, mul_zero] · intro hni exact absurd (Finset.mem_univ i) hni @@ -254,10 +254,10 @@ theorem tensor_basisVec (i j : Fin n) : = if k = finProdFinEquiv (i, j) then (1 : ZMod 2) else 0 by_cases hk : k = finProdFinEquiv (i, j) · subst hk - rw [if_pos rfl, Equiv.symm_apply_apply] + rw [ite_eq_left rfl, Equiv.symm_apply_apply] show (if i = i then (1 : ZMod 2) else 0) * (if j = j then (1 : ZMod 2) else 0) = 1 - rw [if_pos rfl, if_pos rfl, mul_one] - · rw [if_neg hk] + rw [ite_eq_left rfl, ite_eq_left rfl, mul_one] + · rw [ite_eq_right hk] by_cases h1 : (finProdFinEquiv.symm k).1 = i · by_cases h2 : (finProdFinEquiv.symm k).2 = j · exfalso @@ -266,10 +266,10 @@ theorem tensor_basisVec (i j : Fin n) : rw [← hpair, Equiv.apply_symm_apply] · show (if (finProdFinEquiv.symm k).1 = i then (1 : ZMod 2) else 0) * (if (finProdFinEquiv.symm k).2 = j then (1 : ZMod 2) else 0) = 0 - rw [if_neg h2, mul_zero] + rw [ite_eq_right h2, mul_zero] · show (if (finProdFinEquiv.symm k).1 = i then (1 : ZMod 2) else 0) * (if (finProdFinEquiv.symm k).2 = j then (1 : ZMod 2) else 0) = 0 - rw [if_neg h1, zero_mul] + rw [ite_eq_right h1, zero_mul] /-- **Consistency forces the tensor.** A quadratic table that agrees with the product of the linear readings on every outer product *is* the tensor square of @@ -365,7 +365,7 @@ theorem eq_of_hammingDist_lt_half {S T : Finset (Fin n)} by_contra hne have h1 : ⟪χ S, χ T⟫ = 0 := by rw [parityFun_orthonormal] - exact if_neg hne + exact ite_eq_right hne have h2 : ⟪χ S, χ T⟫ = 1 - 2 * hammingDist (χ S) (χ T) := inner_eq_one_sub_two_dist _ _ (isBooleanValued_parityFun S) (isBooleanValued_parityFun T) @@ -410,7 +410,7 @@ theorem chi_eq_one_sub_two (v : ZMod 2) : by_cases h : v = 0 · rw [h] norm_num [chi] - · rw [if_pos h] + · rw [ite_eq_left h] have hchi : chi v = -1 := by simp [chi, h] rw [hchi] norm_num @@ -453,7 +453,7 @@ theorem prob_hadamard_ne_zero (a : Cube n) (ha : a ≠ 0) : · exact h · exact absurd h hi have hexp : 𝔼[signOf (hadamard a)] = 0 := by - rw [signOf_hadamard, expect_parityFun, if_neg hne] + rw [signOf_hadamard, expect_parityFun, ite_eq_right hne] rw [expect_signOf] at hexp linarith @@ -504,8 +504,8 @@ theorem prob_mono {P Q : Cube n → Prop} (h : ∀ x, P x → Q x) : Pr[P] ≤ P simp only [BooleanAnalysis.prob, expect_unfold, BooleanAnalysis.indicator] refine mul_le_mul_of_nonneg_left (Finset.sum_le_sum fun x _ => ?_) (by positivity) by_cases hp : P x - · rw [if_pos hp, if_pos (h x hp)] - · rw [if_neg hp] + · rw [ite_eq_left hp, ite_eq_left (h x hp)] + · rw [ite_eq_right hp] split_ifs <;> norm_num /-- **The bilinear form is nonzero on many rows.** If the quadratic table's @@ -545,7 +545,8 @@ theorem expect_mono {f g : BooleanFunction n} (h : ∀ x, f x ≤ g x) : 𝔼[f] theorem expect_const_mul (c : ℝ) (f : BooleanFunction n) : 𝔼[fun x => c * f x] = c * 𝔼[f] := by - rw [expect_unfold, expect_unfold, ← Finset.mul_sum] + rw [expect_unfold (f := fun x : Cube n => c * f x), expect_unfold (f := f), + ← Finset.mul_sum (s := Finset.univ) (a := c) (f := fun x : Cube n => f x)] ring /-- **A nonzero bilinear form is nonzero on a quarter of all pairs.** For at @@ -568,15 +569,16 @@ theorem prob₂_tensor_ne_zero (c : Cube (n * n)) (hc : c ≠ 0) : funext x rw [hadamard_tensor_row] by_cases hy : tensorRow c y ≠ 0 - · rw [if_pos hy, mul_one, hcond] + · rw [ite_eq_left hy, mul_one, hcond] exact le_of_eq (prob_hadamard_ne_zero _ hy).symm - · rw [if_neg hy, mul_zero] + · rw [ite_eq_right hy, mul_zero] exact BooleanAnalysis.Internal.prob_nonneg _ have hhalf := prob_tensorRow_ne_zero c hc calc (1 : ℝ) / 4 = (1 / 2) * (1 / 2) := by norm_num _ ≤ (1 / 2) * Pr[fun y => tensorRow c y ≠ 0] := by linarith _ = 𝔼[fun y => (1 / 2 : ℝ) * (if tensorRow c y ≠ 0 then (1 : ℝ) else 0)] := by - rw [expect_const_mul] + rw [expect_const_mul (n := n) (c := (1 / 2 : ℝ)) + (f := fun y : Cube n => if tensorRow c y ≠ 0 then (1 : ℝ) else 0)] congr 1 rw [BooleanAnalysis.prob] congr 1 @@ -594,17 +596,21 @@ theorem hadamard_add {m : ℕ} (b c z : Cube m) : theorem expect_add (f g : BooleanFunction n) : 𝔼[fun x => f x + g x] = 𝔼[f] + 𝔼[g] := by - rw [expect_unfold, expect_unfold, expect_unfold, ← mul_add, ← Finset.sum_add_distrib] + rw [expect_unfold (f := fun x : Cube n => f x + g x), expect_unfold (f := f), + expect_unfold (f := g), ← mul_add, + ← Finset.sum_add_distrib (f := fun x : Cube n => f x) (g := fun x : Cube n => g x)] theorem expect_one : 𝔼[fun _ : Cube n => (1 : ℝ)] = 1 := by - rw [expect_unfold, Finset.sum_const, Finset.card_univ, card_cube, nsmul_eq_mul, mul_one] + rw [expect_unfold (f := fun _ : Cube n => (1 : ℝ)), Finset.sum_const, Finset.card_univ, + card_cube, nsmul_eq_mul, mul_one] push_cast field_simp theorem prob₂_compl (P : Cube n → Cube n → Prop) : Pr₂[P] + Pr₂[fun x y => ¬ P x y] = 1 := by classical - rw [BooleanAnalysis.prob₂, BooleanAnalysis.prob₂, ← expect_add, ← expect_one (n := n)] + rw [BooleanAnalysis.prob₂, BooleanAnalysis.prob₂, ← expect_add (f := fun x : Cube n => 𝔼[𝟙(P x)]) + (g := fun x : Cube n => 𝔼[𝟙fun y => ¬P x y]), ← expect_one (n := n)] congr 1 funext x exact BooleanAnalysis.Internal.prob_compl (P x) diff --git a/Complexitylib/Classes/PCP/Internal/KilledCSP.lean b/Complexitylib/Classes/PCP/Internal/KilledCSP.lean index e33dd8bf..2a36c793 100644 --- a/Complexitylib/Classes/PCP/Internal/KilledCSP.lean +++ b/Complexitylib/Classes/PCP/Internal/KilledCSP.lean @@ -171,7 +171,7 @@ theorem satisfies_killedPow_truthful {σ : R.Assignment} (hσ : ∀ p, R.Satisfi rw [Satisfies, satisfies] dsimp only rw [show (R.killedPow q T hq).graph.nbr v y = R.graph.killedEnd v y.1 y.2 from rfl] - rw [rel_killedPow_iff] + erw [rel_killedPow_iff] intro i have hstart : R.kTruthful q T hq σ v (R.graph.startIdx (R.graph.kLen_le y) (R.graph.kWalk y) i) @@ -181,7 +181,8 @@ theorem satisfies_killedPow_truthful {σ : R.Assignment} (hσ : ∀ p, R.Satisfi have hend : R.kTruthful q T hq σ (R.graph.killedEnd v y.1 y.2) (R.graph.endIdx (R.graph.kLen_le y) v (R.graph.kWalk y) i) = σ (R.graph.walkAt (R.graph.kLen y) v (R.graph.kWalk y) (i.val + 1)) := by - rw [kTruthful, R.graph.killedEnd_eq] + simp only [kTruthful] + erw [R.graph.killedEnd_eq] exact congrArg σ (R.graph.walkEnd_endIdx (R.graph.kLen_le y) v (R.graph.kWalk y) i) rw [hstart, hend] have hdart := hσ (R.graph.walkAt (R.graph.kLen y) v (R.graph.kWalk y) i.val, diff --git a/Complexitylib/Classes/PCP/Internal/KilledFirstMoment.lean b/Complexitylib/Classes/PCP/Internal/KilledFirstMoment.lean index 5be6a413..19f20a02 100644 --- a/Complexitylib/Classes/PCP/Internal/KilledFirstMoment.lean +++ b/Complexitylib/Classes/PCP/Internal/KilledFirstMoment.lean @@ -287,7 +287,7 @@ theorem card_good_crossing (A : (R.killedPow q T hq).Assignment) (a : R.graph.V) (fun p => R.opinionOf q T hq A a hiT p = R.kPlurality q T hq A a) (fun s => R.opinionOf q T hq A (R.graph.nbr a d) hjT s = R.kPlurality q T hq A (R.graph.nbr a d)), - truthCount, dif_pos hiT, truthCount, dif_pos hjT] + truthCount, dite_eq_left hiT, truthCount, dite_eq_left hjT] /-! ### Every counted crossing breaks its constraint -/ @@ -714,7 +714,7 @@ theorem card_both_good_le (A : (R.killedPow q T hq).Assignment) {k l : ℕ} refine le_trans (Finset.card_le_card_of_injOn (fun z => z.2.2) (fun _ _ => Finset.mem_univ _) ?_) ?_ · intro z hz z' hz' hzz - simp only [Finset.coe_filter, Set.mem_setOf_eq] at hz hz' + simp only [Finset.coe_filter, Set.mem_ofPred_eq] at hz hz' have hz1 : z.1 = w.1 := congrArg Prod.fst hz.2 have hz2 : z.2.1 = w.2 := congrArg Prod.snd hz.2 have hz1' : z'.1 = w.1 := congrArg Prod.fst hz'.2 @@ -1071,7 +1071,7 @@ noncomputable def crossCount (A : (R.killedPow q T hq).Assignment) (p : R.Dart) theorem crossCount_eq_card (A : (R.killedPow q T hq).Assignment) (p : R.Dart) {i j : ℕ} (hij : i + j + 1 < T) (hiT : i ≤ T) (hjT : (i + j + 1) - (i + 1) ≤ T) : R.crossCount q T hq A p i j = (R.crossingSet q T hq A p.1 p.2 hij hiT hjT).card := by - rw [crossCount, dif_pos hij] + rw [crossCount, dite_eq_left hij] theorem crossCount_eq_prod (A : (R.killedPow q T hq).Assignment) (p : R.Dart) {i j : ℕ} (hij : i + j + 1 < T) : @@ -1215,7 +1215,8 @@ theorem unsatFrac_killedPow_ge (A : (R.killedPow q T hq).Assignment) {LB : ℝ} / ((R.graph.order * (R.graph.deg ^ T * q ^ T) : ℕ) : ℝ) := by rw [RegCSP.unsatFrac, R.card_dart_killedPow q T hq] push_cast - ring + field_simp + norm_cast rw [hfrac] gcongr diff --git a/Complexitylib/Classes/PCP/Internal/KilledPlurality.lean b/Complexitylib/Classes/PCP/Internal/KilledPlurality.lean index d7f3eadf..cd75ced7 100644 --- a/Complexitylib/Classes/PCP/Internal/KilledPlurality.lean +++ b/Complexitylib/Classes/PCP/Internal/KilledPlurality.lean @@ -210,7 +210,7 @@ theorem card_fibre_truth (A : (R.killedPow q T hq).Assignment) (v : R.graph.V) stopAt x.2 = m ∧ R.kOpinionAbout q T hq A v x = R.kPlurality q T hq A v).card = R.truthCount q T hq A v m * (R.graph.deg ^ (T - m) * ((q - 1) ^ m * q ^ (T - m - 1))) := by - rw [R.card_fibre_opinion q T hq A v _ hm, truthCount, dif_pos (le_of_lt hm)] + rw [R.card_fibre_opinion q T hq A v _ hm, truthCount, dite_eq_left (le_of_lt hm)] omit [Fintype α] [DecidableEq α] [Nonempty α] in theorem card_KLabels : Fintype.card (R.KLabels q T) = R.graph.deg ^ T * q ^ T := by diff --git a/Complexitylib/Classes/PCP/Internal/KilledWalk.lean b/Complexitylib/Classes/PCP/Internal/KilledWalk.lean index d23af7e8..cf595a82 100644 --- a/Complexitylib/Classes/PCP/Internal/KilledWalk.lean +++ b/Complexitylib/Classes/PCP/Internal/KilledWalk.lean @@ -70,7 +70,7 @@ def stopAt {T q : ℕ} (c : Fin T → Fin q) : ℕ := theorem stopAt_le {T q : ℕ} (c : Fin T → Fin q) : stopAt c ≤ T := by have h := List.findIdx_le_length (p := fun i : Fin T => (c i).val == 0) (xs := List.finRange T) - simpa using h + simpa [stopAt] using h /-- Before the stopping index every signal is nonzero. -/ theorem signal_ne_zero_of_lt {T q : ℕ} (c : Fin T → Fin q) {j : ℕ} (hj : j < stopAt c) : @@ -86,8 +86,8 @@ theorem signal_eq_zero_of_stopAt_lt {T q : ℕ} (c : Fin T → Fin q) (h : stopA have hlen : stopAt c < (List.finRange T).length := by simpa using h have hg := List.findIdx_getElem (p := fun i : Fin T => (c i).val == 0) (xs := List.finRange T) (w := hlen) - rw [List.getElem_finRange] at hg - simpa using hg + erw [List.getElem_finRange] at hg + simpa [stopAt, Fin.cast] using hg /-- The stopping index is pinned down by the two properties above. -/ theorem stopAt_eq_of {T q : ℕ} (c : Fin T → Fin q) {m : ℕ} (hm : m ≤ T) @@ -133,12 +133,12 @@ theorem card_lt_stopAt {T q : ℕ} {i : ℕ} (hi : i < T) : constructor · intro h j by_cases hj : j.val ≤ i - · simp only [hj, if_true, Finset.mem_filter, Finset.mem_univ, true_and] + · simp only [hj, ite_true, Finset.mem_filter, Finset.mem_univ, true_and] simpa using h j.val hj · simp [hj] · intro h j hj have hmem := h ⟨j, lt_of_le_of_lt hj hi⟩ - simp only [hj, if_true, Finset.mem_filter, Finset.mem_univ, true_and] at hmem + simp only [hj, ite_true, Finset.mem_filter, Finset.mem_univ, true_and] at hmem exact hmem have hnz : (Finset.univ.filter (fun x : Fin q => x.val ≠ 0)).card = q - 1 := by rcases Nat.eq_zero_or_pos q with hq0 | hq0 @@ -279,15 +279,15 @@ theorem card_preWalk_eq {T m : ℕ} (hm : m ≤ T) (w : Fin m → G.D) : constructor · intro h j by_cases hj : j.val < m - · simp only [hj, dif_pos, Finset.mem_singleton] + · simp only [hj, dite_eq_left, Finset.mem_singleton] have hval := congrFun h ⟨j.val, hj⟩ - simpa using hval + simpa [RegGraph.preWalk] using hval · simp [hj] · intro h funext j have hmem := h ⟨j.val, lt_of_lt_of_le j.isLt hm⟩ - simp only [j.isLt, dif_pos, Finset.mem_singleton] at hmem - simpa using hmem + simp only [j.isLt, dite_eq_left, Finset.mem_singleton] at hmem + simpa [RegGraph.preWalk] using hmem have hlt : (Finset.univ.filter fun j : Fin T => j.val < m).card = m := by have himg : (Finset.univ.filter fun j : Fin T => j.val < m).image Fin.val = Finset.range m := by @@ -371,8 +371,8 @@ def killedPower (G : RegGraph) (q T : ℕ) (hq : 0 < q) : RegGraph where haveI := G.decEqD infer_instance nonemptyD := by - haveI := G.nonemptyD - haveI : Nonempty (Fin q) := ⟨⟨0, hq⟩⟩ + have := G.nonemptyD + have : Nonempty (Fin q) := ⟨⟨0, hq⟩⟩ infer_instance rot x := (G.killedEnd x.1 x.2.1 x.2.2, (G.killedRev x.1 x.2.1 x.2.2, x.2.2)) rot_involutive := by diff --git a/Complexitylib/Classes/PCP/Internal/LengthMod.lean b/Complexitylib/Classes/PCP/Internal/LengthMod.lean index dfbb66f4..c3e4377c 100644 --- a/Complexitylib/Classes/PCP/Internal/LengthMod.lean +++ b/Complexitylib/Classes/PCP/Internal/LengthMod.lean @@ -62,15 +62,15 @@ theorem ctrStep_iterate (n : ℕ) : ctrStep^[n] [] = List.replicate (n % 4) true | zero => rfl | succ m ih => rw [Function.iterate_succ_apply', ih, ctrStep, - if_pos (replicate_mem_ctrVals (Nat.mod_lt _ (by norm_num)))] + ite_eq_left (replicate_mem_ctrVals (Nat.mod_lt _ (by norm_num)))] have hlen : (List.replicate (m % 4) true).length = m % 4 := List.length_replicate rw [hlen] by_cases h3 : m % 4 = 3 - · rw [if_pos h3] + · rw [ite_eq_left h3] have : (m + 1) % 4 = 0 := by omega rw [this] rfl - · rw [if_neg h3] + · rw [ite_eq_right h3] have hm : (m + 1) % 4 = m % 4 + 1 := by have := Nat.mod_lt m (show 0 < 4 by norm_num) omega @@ -110,11 +110,11 @@ theorem lenMod4_mem_P : lenMod4 ∈ P := by · refine mem_FP_of_eq (mem_FP_comp lenCtr_mem_FP ctrIsZero_mem_FP) fun z => ?_ show ctrIsZero (lenCtr z) = _ rw [lenCtr, ctrStep_iterate, ctrIsZero, - if_pos (replicate_mem_ctrVals (Nat.mod_lt _ (by norm_num)))] + ite_eq_left (replicate_mem_ctrVals (Nat.mod_lt _ (by norm_num)))] by_cases h : z.length % 4 = 0 · rw [h] - simp [h] - · rw [if_neg (by + rfl + · rw [ite_eq_right (by intro hnil exact h (by have := congrArg List.length hnil diff --git a/Complexitylib/Classes/PCP/Internal/ListEncode.lean b/Complexitylib/Classes/PCP/Internal/ListEncode.lean index efae66aa..5f172b7d 100644 --- a/Complexitylib/Classes/PCP/Internal/ListEncode.lean +++ b/Complexitylib/Classes/PCP/Internal/ListEncode.lean @@ -48,7 +48,7 @@ theorem listStep_mem_FP {E : List Bool → List Bool} (hE : E ∈ FP) : listStep have hE' : (fun st : List Bool => E (pair (pairSnd st) (pairSnd (pairFst st)))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hx hctr) hE - simpa using this + exact this exact Cobham.pairFn_mem_FP (Cobham.pairFn_mem_FP (Cobham.appendFn_mem_FP hacc hE') (mem_FP_comp hctr (Cobham.cons_mem_FP true))) hx diff --git a/Complexitylib/Classes/PCP/Internal/LocalTest.lean b/Complexitylib/Classes/PCP/Internal/LocalTest.lean index bc721642..cd6f48e1 100644 --- a/Complexitylib/Classes/PCP/Internal/LocalTest.lean +++ b/Complexitylib/Classes/PCP/Internal/LocalTest.lean @@ -173,9 +173,9 @@ theorem witnessEdge_mem [Nonempty Q] (A : M.toGraph.Assignment) (x : E × Cube M (hx : x.2 ∈ M.rejects (M.tableOf A) x.1) : M.witnessEdge A x ∈ M.toGraph.unsatEdges A := by classical - rw [witnessEdge, dif_pos hx] - exact Finset.mem_filter.2 - ⟨Finset.mem_univ _, Classical.choose_spec (M.exists_unsat_of_rejects A x.1 x.2 hx)⟩ + rw [witnessEdge, dite_eq_left hx] + erw [ConstraintGraph.mem_unsatEdges] + exact Classical.choose_spec (M.exists_unsat_of_rejects A x.1 x.2 hx) theorem witnessEdge_injective [Nonempty Q] (A : M.toGraph.Assignment) : Function.Injective (M.witnessEdge A) := by @@ -260,7 +260,7 @@ theorem satisfiable_toGraph (T : Table Pos) (h : ∀ e z, M.accepts T e z = true M.toGraph.Satisfiable := by classical refine ⟨M.honest T, fun k => ?_⟩ - rw [satisfies_toGraph_iff] + erw [satisfies_toGraph_iff] refine ⟨?_, ?_⟩ · rw [honest_inr] exact h _ _ diff --git a/Complexitylib/Classes/PCP/Internal/Margulis.lean b/Complexitylib/Classes/PCP/Internal/Margulis.lean index 9e094482..6bb9df12 100644 --- a/Complexitylib/Classes/PCP/Internal/Margulis.lean +++ b/Complexitylib/Classes/PCP/Internal/Margulis.lean @@ -73,8 +73,8 @@ theorem margRot_involutive (m : ℕ) : Function.Involutive (margRot m) := by intro p by_cases h : m = 0 · simp [margRot, h] - · haveI : NeZero m := ⟨h⟩ - simp only [margRot, dif_neg h, Equiv.apply_symm_apply, margGen_pair, margPair_pair, + · have : NeZero m := ⟨h⟩ + simp only [margRot, dite_eq_right h, Equiv.apply_symm_apply, margGen_pair, margPair_pair, Equiv.symm_apply_apply] end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/Materialize.lean b/Complexitylib/Classes/PCP/Internal/Materialize.lean index 15a1920d..873113b6 100644 --- a/Complexitylib/Classes/PCP/Internal/Materialize.lean +++ b/Complexitylib/Classes/PCP/Internal/Materialize.lean @@ -242,10 +242,10 @@ theorem length_findFirst (E : List Bool → List Bool) (x : List Bool) (n : ℕ) rw [pairSnd_pair, pairFst_pair, ← List.replicate_succ', length_isEmptyMark] by_cases h : (∑ k ∈ Finset.range (j + 1), (E (pair x (List.replicate k true))).length) = 0 - · rw [if_pos h, if_pos] + · rw [ite_eq_left h, ite_eq_left] have := length_countOver E x (j + 1) exact List.eq_nil_of_length_eq_zero (by rw [this, h]) - · rw [if_neg h, if_neg] + · rw [ite_eq_right h, ite_eq_right] intro hnil exact h (by rw [← length_countOver E x (j + 1), hnil, List.length_nil]) @@ -262,11 +262,11 @@ theorem length_findFirst_eq {E : List Bool → List Bool} {x : List Bool} {n c : = (if j < c then 1 else 0) := by intro j _ by_cases hj : j < c - · rw [if_pos hj, if_pos] + · rw [ite_eq_left hj, ite_eq_left] refine Finset.sum_eq_zero fun k hk => ?_ rw [Finset.mem_range] at hk exact hmin k (by omega) - · rw [if_neg hj, if_neg] + · rw [ite_eq_right hj, ite_eq_right] intro hzero refine hhit ?_ have hcm : c ∈ Finset.range (j + 1) := Finset.mem_range.mpr (by omega) diff --git a/Complexitylib/Classes/PCP/Internal/MaxLoop.lean b/Complexitylib/Classes/PCP/Internal/MaxLoop.lean index 599b54ed..3a068025 100644 --- a/Complexitylib/Classes/PCP/Internal/MaxLoop.lean +++ b/Complexitylib/Classes/PCP/Internal/MaxLoop.lean @@ -60,7 +60,7 @@ theorem maxStep_mem_FP {f : List Bool → List Bool} (hf : f ∈ FP) : maxStep f have hv : (fun st : List Bool => f (pair (pairSnd st) (pairSnd (pairFst st)))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hz hi) hf - simpa using this + exact this exact Cobham.pairFn_mem_FP (Cobham.pairFn_mem_FP (Cobham.selectHeadFn_mem_FP (lenLeFlagFn_mem_FP hm hv) hm hv) @@ -177,7 +177,7 @@ theorem maxFn_mem_FP {f : List Bool → List Bool} (hf : f ∈ FP) : maxFn f ∈ have hiter := Cobham.iterate_mem_FP (maxStep_mem_FP hf) hinit Cobham.fstBlock_mem_FP hwidth hbound have := mem_FP_comp (mem_FP_comp hiter Cobham.fstBlock_mem_FP) Cobham.fstBlock_mem_FP - simpa using this + exact this theorem maxFn_eq (f : List Bool → List Bool) {n : ℕ} {z : List Bool} : (maxFn f (pair (List.replicate n true) z)).length = maxOver f z n := by diff --git a/Complexitylib/Classes/PCP/Internal/MergeGen.lean b/Complexitylib/Classes/PCP/Internal/MergeGen.lean index 759909b0..5b230776 100644 --- a/Complexitylib/Classes/PCP/Internal/MergeGen.lean +++ b/Complexitylib/Classes/PCP/Internal/MergeGen.lean @@ -5,7 +5,7 @@ Authors: Bolton Bailey -/ module public import Complexitylib.Classes.PCP.Internal.ExpanderMerge -public import Mathlib.Data.Real.Sqrt +public import Mathlib.Analysis.Real.Sqrt /-! # Merging at an arbitrary width @@ -67,7 +67,7 @@ theorem liftN_projN_slotN (hn : 0 < n) (hN : N ≤ m * n) (u : Fin N) : have h : u.val % n + u.val / n * n = u.val := by rw [mul_comm] exact Nat.mod_add_div u.val n - rw [dif_pos (by rw [h]; exact u.isLt)] + rw [dite_eq_left (by rw [h]; exact u.isLt)] congr 1 exact Fin.ext h @@ -175,7 +175,7 @@ theorem step_mergedN (hn : 0 < n) (hd : 0 < d) (hm : 0 < m) (hN : N ≤ m * n) = ∑ i : Fin m, ∑ s : Fin d, f ((mergeRotN hn hN rot (v, (i, s))).1) := Fintype.sum_prod_type (f := fun x : Fin m × Fin d => f ((mergeRotN hn hN rot (v, x)).1)) - rw [RegGraph.step, hdeg, hsum] + simp only [RegGraph.step]; rw [hdeg, hsum] have hinner : ∀ i : Fin m, ∑ s : Fin d, f ((mergeRotN hn hN rot (v, (i, s))).1) = (d : ℝ) * termN hn hd rot hrot f v i.val := by intro i @@ -186,7 +186,7 @@ theorem step_mergedN (hn : 0 < n) (hd : 0 < d) (hm : 0 < m) (hN : N ≤ m * n) simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] | some u => simp only - rw [RegGraph.step, deg_ofRot] + simp only [RegGraph.step]; rw [deg_ofRot] show _ = (d : ℝ) * ((∑ j : Fin d, f (projN n hn (rot (u, j)).1)) / (d : ℝ)) field_simp rw [Finset.sum_congr rfl fun i _ => hinner i, ← Finset.mul_sum] diff --git a/Complexitylib/Classes/PCP/Internal/NatEncode.lean b/Complexitylib/Classes/PCP/Internal/NatEncode.lean index 4a14721e..45946934 100644 --- a/Complexitylib/Classes/PCP/Internal/NatEncode.lean +++ b/Complexitylib/Classes/PCP/Internal/NatEncode.lean @@ -171,11 +171,11 @@ theorem natEncodeFn_mem_FP : natEncodeFn ∈ FP := by have hw : (fun z : List Bool => List.replicate (pairFst z).length true) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP unaryLength_mem_FP - simpa using this + exact this have hv : (fun z : List Bool => List.replicate (pairSnd z).length true) ∈ FP := by have := mem_FP_comp Cobham.sndBlock_mem_FP unaryLength_mem_FP - simpa using this + exact this have hcoin := coinStr_mem_FP hw hv have h1 : (fun z => pair [] (coinStr (pairFst z).length (pairSnd z).length)) ∈ FP := @@ -184,9 +184,9 @@ theorem natEncodeFn_mem_FP : natEncodeFn ∈ FP := by have h3 : (fun z => pair [] (stripFn (pair [] (coinStr (pairFst z).length (pairSnd z).length)))) ∈ FP := by refine Cobham.pairFn_mem_FP (constFn_mem_FP []) ?_ - simpa using h2 + exact h2 have := mem_FP_comp h3 encodeListFn_mem_FP - simpa using this + exact this /-- **It really is the number's encoding**, whenever the width holds the value. -/ diff --git a/Complexitylib/Classes/PCP/Internal/NumEnc.lean b/Complexitylib/Classes/PCP/Internal/NumEnc.lean index c282acb5..74c4f470 100644 --- a/Complexitylib/Classes/PCP/Internal/NumEnc.lean +++ b/Complexitylib/Classes/PCP/Internal/NumEnc.lean @@ -126,14 +126,14 @@ instance instFin (n : ℕ) : NumEnc (Fin n) where enc i := i.val dec i := if h : i < n then some ⟨i, h⟩ else none enc_lt i := i.isLt - dec_enc i := by rw [dif_pos i.isLt] + dec_enc i := by rw [dite_eq_left i.isLt] enc_dec i a h := by by_cases hi : i < n - · rw [dif_pos hi] at h + · rw [dite_eq_left hi] at h exact congrArg Fin.val (Option.some_injective _ h).symm - · rw [dif_neg hi] at h + · rw [dite_eq_right hi] at h exact absurd h (by simp) - dec_isSome i hi := by rw [dif_pos hi]; rfl + dec_isSome i hi := by rw [dite_eq_left hi]; rfl instance instBool : NumEnc Bool where card := 2 @@ -152,7 +152,7 @@ instance instBool : NumEnc Bool where simp at h subst h norm_num - · rw [if_neg h0, if_neg h1] at h + · rw [ite_eq_right h0, ite_eq_right h1] at h exact absurd h (by simp) dec_isSome i hi := by by_cases h0 : i = 0 @@ -169,7 +169,7 @@ instance instUnit : NumEnc Unit where enc_dec i a h := by by_cases h0 : i = 0 · subst h0; rfl - · rw [if_neg h0] at h + · rw [ite_eq_right h0] at h exact absurd h (by simp) dec_isSome i hi := by have h0 : i = 0 := by omega @@ -206,11 +206,11 @@ instance instProd [NumEnc α] [NumEnc β] : NumEnc (α × β) where else none enc_lt p := prod_lt p.1 p.2 dec_enc p := by - rw [if_pos (prod_lt p.1 p.2), prod_div, prod_mod, dec_enc, dec_enc] + rw [ite_eq_left (prod_lt p.1 p.2), prod_div, prod_mod, dec_enc, dec_enc] rfl enc_dec i p h := by by_cases hlt : i < card α * card β - · rw [if_pos hlt] at h + · rw [ite_eq_left hlt] at h rw [Option.bind_eq_some_iff] at h obtain ⟨a, ha, hb⟩ := h rw [Option.map_eq_some_iff] at hb @@ -222,7 +222,7 @@ instance instProd [NumEnc α] [NumEnc β] : NumEnc (α × β) where show enc a * card β + enc b = i rw [hea, heb, Nat.mul_comm] exact Nat.div_add_mod i (card β) - · rw [if_neg hlt] at h + · rw [ite_eq_right hlt] at h exact absurd h (by simp) dec_isSome i hi := by @@ -234,7 +234,7 @@ instance instProd [NumEnc α] [NumEnc β] : NumEnc (α × β) where have him : i % card β < card β := Nat.mod_lt _ hb obtain ⟨a, ha⟩ := Option.isSome_iff_exists.mp (dec_isSome _ hia) obtain ⟨b, hbb⟩ := Option.isSome_iff_exists.mp (dec_isSome _ him) - rw [if_pos hi, ha, hbb] + rw [ite_eq_left hi, ha, hbb] rfl instance instSum [NumEnc α] [NumEnc β] : NumEnc (α ⊕ β) where @@ -251,23 +251,23 @@ instance instSum [NumEnc α] [NumEnc β] : NumEnc (α ⊕ β) where have ha := enc_lt a show (if enc a < card α then _ else _) = _ simp only [Sum.elim_inl] - rw [if_pos ha, dec_enc] + rw [ite_eq_left ha, dec_enc] rfl | inr b => have hb : ¬ card α + enc b < card α := by omega show (if card α + enc b < card α then _ else _) = _ simp only [Sum.elim_inr] - rw [if_neg hb, Nat.add_sub_cancel_left, dec_enc] + rw [ite_eq_right hb, Nat.add_sub_cancel_left, dec_enc] rfl enc_dec i x h := by by_cases hi : i < card α - · rw [if_pos hi, Option.map_eq_some_iff] at h + · rw [ite_eq_left hi, Option.map_eq_some_iff] at h obtain ⟨a, ha, hx⟩ := h have := enc_dec _ a ha rw [← hx] show enc a = i exact this - · rw [if_neg hi, Option.map_eq_some_iff] at h + · rw [ite_eq_right hi, Option.map_eq_some_iff] at h obtain ⟨b, hb, hx⟩ := h have := enc_dec _ b hb rw [← hx] @@ -277,11 +277,11 @@ instance instSum [NumEnc α] [NumEnc β] : NumEnc (α ⊕ β) where dec_isSome i hi := by by_cases h : i < card α · obtain ⟨a, ha⟩ := Option.isSome_iff_exists.mp (dec_isSome (α := α) _ h) - rw [if_pos h, ha] + rw [ite_eq_left h, ha] rfl · have hb : i - card α < card β := by omega obtain ⟨b, hbb⟩ := Option.isSome_iff_exists.mp (dec_isSome (α := β) _ hb) - rw [if_neg h, hbb] + rw [ite_eq_right h, hbb] rfl instance instOption [NumEnc α] : NumEnc (Option α) where @@ -294,18 +294,18 @@ instance instOption [NumEnc α] : NumEnc (Option α) where | some a => have := enc_lt a; show 1 + enc a < _; omega dec_enc o := by cases o with - | none => show (if (0 : ℕ) = 0 then _ else _) = _; rw [if_pos rfl] + | none => show (if (0 : ℕ) = 0 then _ else _) = _; rw [ite_eq_left rfl] | some a => show (if 1 + enc a = 0 then _ else _) = _ - rw [if_neg (by omega), show 1 + enc a - 1 = enc a by omega, dec_enc] + rw [ite_eq_right (by omega), show 1 + enc a - 1 = enc a by omega, dec_enc] rfl enc_dec i o h := by by_cases h0 : i = 0 - · rw [if_pos h0] at h + · rw [ite_eq_left h0] at h rw [← Option.some_injective _ h] show 0 = i omega - · rw [if_neg h0, Option.map_eq_some_iff] at h + · rw [ite_eq_right h0, Option.map_eq_some_iff] at h obtain ⟨a, ha, ho⟩ := h have := enc_dec _ a ha rw [← ho] @@ -313,11 +313,11 @@ instance instOption [NumEnc α] : NumEnc (Option α) where omega dec_isSome i hi := by by_cases h0 : i = 0 - · rw [if_pos h0] + · rw [ite_eq_left h0] rfl · have hb : i - 1 < card α := by omega obtain ⟨a, ha⟩ := Option.isSome_iff_exists.mp (dec_isSome (α := α) _ hb) - rw [if_neg h0, ha] + rw [ite_eq_right h0, ha] rfl /-- Any finite type is numbered by its own enumeration. For a type whose size @@ -329,17 +329,17 @@ bounded key. -/ dec i := if h : i < Fintype.card α then some ((Fintype.equivFin α).symm ⟨i, h⟩) else none enc_lt a := (Fintype.equivFin α a).isLt dec_enc a := by - rw [dif_pos (Fintype.equivFin α a).isLt] + rw [dite_eq_left (Fintype.equivFin α a).isLt] simp enc_dec i a h := by by_cases hi : i < Fintype.card α - · rw [dif_pos hi] at h + · rw [dite_eq_left hi] at h rw [← Option.some_injective _ h] simp - · rw [dif_neg hi] at h + · rw [dite_eq_right hi] at h exact absurd h (by simp) dec_isSome i hi := by - rw [dif_pos hi] + rw [dite_eq_left hi] rfl end NumEnc diff --git a/Complexitylib/Classes/PCP/Internal/NumEncPi.lean b/Complexitylib/Classes/PCP/Internal/NumEncPi.lean index 20a1a5c2..d730aba4 100644 --- a/Complexitylib/Classes/PCP/Internal/NumEncPi.lean +++ b/Complexitylib/Classes/PCP/Internal/NumEncPi.lean @@ -124,7 +124,7 @@ def encAt {n : ℕ} [NumEnc α] (f : Fin n → α) (i : ℕ) : ℕ := theorem encAt_lt {n : ℕ} [NumEnc α] (f : Fin n → α) {i : ℕ} (hi : i < n) : encAt f i < card α := by - rw [encAt, dif_pos hi] + rw [encAt, dite_eq_left hi] exact enc_lt _ /-- **A tuple is numbered like a numeral.** -/ @@ -148,27 +148,27 @@ instance instPi (n : ℕ) [NumEnc α] : NumEnc (Fin n → α) where dec_enc f := by have hlt : (∑ i ∈ Finset.range n, encAt f i * card α ^ i) < card α ^ n := sum_lt_pow _ fun i hi => encAt_lt f hi - rw [dif_pos hlt] + rw [dite_eq_left hlt] congr 1 funext j have hc : 0 < card α := Nat.lt_of_le_of_lt (Nat.zero_le _) (enc_lt (f j)) have hdig := digit_sum (c := card α) hc (encAt f) j.isLt (fun i hi => encAt_lt f hi) have hval : encAt f j.val = enc (f j) := by - rw [encAt, dif_pos j.isLt] + rw [encAt, dite_eq_left j.isLt] exact get_eq _ (hdig.trans hval) enc_dec i f h := by by_cases hi : i < card α ^ n - · rw [dif_pos hi] at h + · rw [dite_eq_left hi] at h have hf := Option.some_injective _ h subst hf show ∑ j ∈ Finset.range n, encAt _ j * card α ^ j = i refine Eq.trans (Finset.sum_congr rfl fun j hj => ?_) (sum_digits hi) - rw [encAt, dif_pos (Finset.mem_range.mp hj), enc_get] - · rw [dif_neg hi] at h + rw [encAt, dite_eq_left (Finset.mem_range.mp hj), enc_get] + · rw [dite_eq_right hi] at h exact absurd h (by simp) dec_isSome i hi := by - rw [dif_pos hi] + rw [dite_eq_left hi] rfl end NumEnc diff --git a/Complexitylib/Classes/PCP/Internal/PCPtoSAT.lean b/Complexitylib/Classes/PCP/Internal/PCPtoSAT.lean index 7007b475..7fc534dd 100644 --- a/Complexitylib/Classes/PCP/Internal/PCPtoSAT.lean +++ b/Complexitylib/Classes/PCP/Internal/PCPtoSAT.lean @@ -163,13 +163,13 @@ theorem eval_consClauses_iff (t Q : ℕ) (x w : List Bool) : rw [consClauses] simp only [List.mem_flatMap] exact ⟨ρ, mem_coinList t ρ, ρ', mem_coinList t ρ', i, List.mem_range.2 hi, - i', List.mem_range.2 hi', by rw [if_pos hpos]; simp⟩ + i', List.mem_range.2 hi', by rw [ite_eq_left hpos]; simp⟩ have hmem2 : ([⟨true, varIdx t Q ρ i⟩, ⟨false, varIdx t Q ρ' i'⟩] : Clause) ∈ V.consClauses t Q x := by rw [consClauses] simp only [List.mem_flatMap] exact ⟨ρ, mem_coinList t ρ, ρ', mem_coinList t ρ', i, List.mem_range.2 hi, - i', List.mem_range.2 hi', by rw [if_pos hpos]; simp⟩ + i', List.mem_range.2 hi', by rw [ite_eq_left hpos]; simp⟩ have h1 := h _ hmem have h2 := h _ hmem2 simp only [Clause.eval, List.any_cons, List.any_nil, Lit.eval, Bool.or_false, @@ -182,7 +182,7 @@ theorem eval_consClauses_iff (t Q : ℕ) (x w : List Bool) : rw [List.mem_range] at hi hi' by_cases hpos : (V.positions x (BitString.toList ρ))[i]? = (V.positions x (BitString.toList ρ'))[i']? - · rw [if_pos hpos] at hc + · rw [ite_eq_left hpos] at hc have heq := h ρ ρ' i i' hi hi' hpos simp only [List.mem_cons] at hc rcases hc with rfl | rfl | hc @@ -195,7 +195,7 @@ theorem eval_consClauses_iff (t Q : ℕ) (x w : List Bool) : rw [heq] cases Assignment.get w (varIdx t Q ρ' i') <;> simp · exact absurd hc (by simp) - · rw [if_neg hpos] at hc + · rw [ite_eq_right hpos] at hc exact absurd hc (by simp) /-! ### Semantics of the acceptance clauses -/ diff --git a/Complexitylib/Classes/PCP/Internal/Pad.lean b/Complexitylib/Classes/PCP/Internal/Pad.lean index 3db63624..019968f5 100644 --- a/Complexitylib/Classes/PCP/Internal/Pad.lean +++ b/Complexitylib/Classes/PCP/Internal/Pad.lean @@ -68,7 +68,7 @@ theorem restrict_extend [Nonempty α] (G : ConstraintGraph α) {N : ℕ} (h : G. (a : G.Assignment) : G.restrict h (G.extend h a) = a := by funext v rw [restrict, extend] - simp only [Fin.val_castLE, dif_pos v.isLt] + exact dite_eq_left v.isLt theorem satisfies_pad_iff (G : ConstraintGraph α) {N : ℕ} (h : G.numVerts ≤ N) (a : (G.pad N h).Assignment) (e : Fin (G.pad N h).numEdges) : @@ -83,6 +83,9 @@ theorem unsatFrac_pad (G : ConstraintGraph α) {N : ℕ} (h : G.numVerts ≤ N) (G.pad N h).unsatFrac a = G.unsatFrac (G.restrict h a) := rfl /-- **Padding does not change the value.** -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem unsatVal_pad [Fintype α] [Nonempty α] [DecidableEq α] (G : ConstraintGraph α) (N : ℕ) (h : G.numVerts ≤ N) : (G.pad N h).unsatVal = G.unsatVal := by diff --git a/Complexitylib/Classes/PCP/Internal/PadGraph.lean b/Complexitylib/Classes/PCP/Internal/PadGraph.lean index 5cec05c9..29b33ead 100644 --- a/Complexitylib/Classes/PCP/Internal/PadGraph.lean +++ b/Complexitylib/Classes/PCP/Internal/PadGraph.lean @@ -54,35 +54,35 @@ theorem tail_padGraph_of_lt {e : ℕ} (he : e < (G.padGraph hv n).numEdges) (h : e < G.numEdges) : ((G.padGraph hv n).tail ⟨e, he⟩).val = (G.tail ⟨e, h⟩).val := by show (dite _ _ _ : Fin G.numVerts).val = _ - rw [dif_pos h] + rw [dite_eq_left h] theorem head_padGraph_of_lt {e : ℕ} (he : e < (G.padGraph hv n).numEdges) (h : e < G.numEdges) : ((G.padGraph hv n).head ⟨e, he⟩).val = (G.head ⟨e, h⟩).val := by show (dite _ _ _ : Fin G.numVerts).val = _ - rw [dif_pos h] + rw [dite_eq_left h] theorem rel_padGraph_of_lt {e : ℕ} (he : e < (G.padGraph hv n).numEdges) (h : e < G.numEdges) : (G.padGraph hv n).rel ⟨e, he⟩ = G.rel ⟨e, h⟩ := by show (dite _ _ _ : α → α → Bool) = _ - rw [dif_pos h] + rw [dite_eq_left h] theorem tail_padGraph_of_ge {e : ℕ} (he : e < (G.padGraph hv n).numEdges) (h : ¬ e < G.numEdges) : ((G.padGraph hv n).tail ⟨e, he⟩).val = 0 := by show (dite _ _ _ : Fin G.numVerts).val = _ - rw [dif_neg h] + rw [dite_eq_right h] theorem head_padGraph_of_ge {e : ℕ} (he : e < (G.padGraph hv n).numEdges) (h : ¬ e < G.numEdges) : ((G.padGraph hv n).head ⟨e, he⟩).val = 0 := by show (dite _ _ _ : Fin G.numVerts).val = _ - rw [dif_neg h] + rw [dite_eq_right h] theorem rel_padGraph_of_ge {e : ℕ} (he : e < (G.padGraph hv n).numEdges) (h : ¬ e < G.numEdges) : (G.padGraph hv n).rel ⟨e, he⟩ = fun _ _ => true := by show (dite _ _ _ : α → α → Bool) = _ - rw [dif_neg h] + rw [dite_eq_right h] /-- The padded graph has the same assignments. -/ theorem assignment_padGraph : (G.padGraph hv n).Assignment = G.Assignment := rfl @@ -95,7 +95,7 @@ theorem satisfiable_padGraph_iff : (G.padGraph hv n).Satisfiable ↔ G.Satisfiab have hlt : e.val < (G.padGraph hv n).numEdges := lt_of_lt_of_le e.isLt (le_max_right _ _) have h := ha ⟨e.val, hlt⟩ - rw [Satisfies, satisfies] at h ⊢ + unfold Satisfies satisfies at h ⊢ rw [rel_padGraph_of_lt hlt e.isLt] at h rw [show (⟨e.val, e.isLt⟩ : Fin G.numEdges) = e from rfl] at h rw [← h] @@ -104,10 +104,10 @@ theorem satisfiable_padGraph_iff : (G.padGraph hv n).Satisfiable ↔ G.Satisfiab · exact congrArg a (Fin.ext (head_padGraph_of_lt hlt e.isLt)).symm · rintro ⟨a, ha⟩ refine ⟨a, fun e => ?_⟩ - rw [Satisfies, satisfies] + unfold Satisfies satisfies by_cases h : e.val < G.numEdges · have hb := ha ⟨e.val, h⟩ - rw [Satisfies, satisfies] at hb + unfold Satisfies satisfies at hb rw [rel_padGraph_of_lt e.isLt h] rw [show a ((G.padGraph hv n).tail e) = a (G.tail ⟨e.val, h⟩) from congrArg a (Fin.ext (tail_padGraph_of_lt e.isLt h)), diff --git a/Complexitylib/Classes/PCP/Internal/PermGraph.lean b/Complexitylib/Classes/PCP/Internal/PermGraph.lean index 5e8a5e9f..19d4bcec 100644 --- a/Complexitylib/Classes/PCP/Internal/PermGraph.lean +++ b/Complexitylib/Classes/PCP/Internal/PermGraph.lean @@ -101,8 +101,10 @@ theorem sum_escape_le_dartsBetween (hD : 0 < D) (σ : Fin D → Equiv.Perm (Fin refine Finset.card_le_card_of_injOn (fun p => (p.2, (p.1, false))) (fun p hp => ?_) ?_ · have hp' : p.2 ∈ S ∧ σ p.1 p.2 ∉ S := by simpa [hE] using hp have hmem : ((p.2, (p.1, false)) : (permsGraph hD σ).V × (permsGraph hD σ).D) - ∈ (permsGraph hD σ).dartsBetween S Sᶜ := - Finset.mem_filter.2 ⟨Finset.mem_univ _, hp'.1, Finset.mem_compl.2 hp'.2⟩ + ∈ (permsGraph hD σ).dartsBetween S Sᶜ := by + simp only [RegGraph.dartsBetween, Finset.mem_filter, Finset.mem_univ, + true_and] + exact ⟨hp'.1, Finset.mem_compl.2 hp'.2⟩ simpa using hmem · intro p _ q _ h have h1 : p.2 = q.2 := congrArg Prod.fst h diff --git a/Complexitylib/Classes/PCP/Internal/PosScan.lean b/Complexitylib/Classes/PCP/Internal/PosScan.lean index 606f82e8..b6c4bef8 100644 --- a/Complexitylib/Classes/PCP/Internal/PosScan.lean +++ b/Complexitylib/Classes/PCP/Internal/PosScan.lean @@ -67,14 +67,14 @@ theorem posAt_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : b ∈ have harg : (fun z => DataScan.scanArg (a z).length (posInner (b z))) ∈ FP := DataScan.scanArg_mem_FP ha (posInner_mem_FP hb) have := mem_FP_comp harg (DataScan.childOf_mem_FP DataScan.scanPoly) - simpa using this + exact this theorem posCount_mem_FP {b : List Bool → List Bool} (hb : b ∈ FP) : (fun z => posCount (b z)) ∈ FP := by have harg : (fun z => DataScan.scanArg (([] : List Bool)).length (posInner (b z))) ∈ FP := DataScan.scanArg_mem_FP (constFn_mem_FP []) (posInner_mem_FP hb) have := mem_FP_comp harg (DataScan.childCount_mem_FP DataScan.scanPoly) - simpa using this + exact this /-! ### What the scan reads -/ diff --git a/Complexitylib/Classes/PCP/Internal/PositionsFP.lean b/Complexitylib/Classes/PCP/Internal/PositionsFP.lean index 1063ec16..634a1a4c 100644 --- a/Complexitylib/Classes/PCP/Internal/PositionsFP.lean +++ b/Complexitylib/Classes/PCP/Internal/PositionsFP.lean @@ -38,7 +38,7 @@ noncomputable def posEntryFn (P : List Bool → List Bool) (w : List Bool) : Lis theorem posEntryFn_mem_FP {P : List Bool → List Bool} (hP : P ∈ FP) : posEntryFn P ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hP hP) natEncodeFn_mem_FP - simpa using this + exact this theorem posEntryFn_eq {P : List Bool → List Bool} (w : List Bool) : posEntryFn P w = DataEncode.bitstringEncode ((P w).length) := by @@ -100,7 +100,7 @@ theorem positions_mem_of_unary {pos : List Bool → ℕ → ℕ} {cnt : List Boo · have hpair : (fun z : List Bool => pair (List.replicate (cnt z) true) z) ∈ FP := mem_FP_pairWithInput hcnt have := mem_FP_comp hpair (listEncFn_mem_FP hEfp p hbound) - simpa using this + exact this · intro z refine listEncFn_eq_bitstringEncode _ ?_ ?_ · rw [pairFst_pair, List.length_replicate, List.length_map, List.length_range] diff --git a/Complexitylib/Classes/PCP/Internal/Power.lean b/Complexitylib/Classes/PCP/Internal/Power.lean index 6c688832..ec9329af 100644 --- a/Complexitylib/Classes/PCP/Internal/Power.lean +++ b/Complexitylib/Classes/PCP/Internal/Power.lean @@ -172,7 +172,7 @@ theorem step_power (t : ℕ) (f : G.V → ℝ) (v : G.V) : have hd : ((G.deg : ℝ)) ^ t ≠ 0 := pow_ne_zero _ G.deg_ne_zero calc (G.power t).step f v = (∑ s : Fin t → G.D, f (G.walkEnd t v s)) / ((G.deg ^ t : ℕ) : ℝ) := by - rw [step, deg_power] + simp only [step, deg_power] rfl _ = ((G.deg : ℝ) ^ t * G.stepIter t f v) / ((G.deg : ℝ) ^ t) := by rw [G.sum_walkEnd f t v] diff --git a/Complexitylib/Classes/PCP/Internal/PoweringBound.lean b/Complexitylib/Classes/PCP/Internal/PoweringBound.lean index e373ac37..463121ae 100644 --- a/Complexitylib/Classes/PCP/Internal/PoweringBound.lean +++ b/Complexitylib/Classes/PCP/Internal/PoweringBound.lean @@ -160,9 +160,10 @@ theorem unsatFrac_killedPow_clean (A : (R.killedPow q T hq).Assignment) {H : ℕ have hfrac : (((R.killedPow q T hq).unsatFrac A : ℚ) : ℝ) = (((R.killedPow q T hq).unsatDarts A).card : ℝ) / ((R.graph.order : ℝ) * ((R.graph.deg : ℝ) ^ T * (q : ℝ) ^ T)) := by - rw [RegCSP.unsatFrac, R.card_dart_killedPow q T hq] + rw [RegCSP.unsatFrac, R.card_dart_killedPow q T hq, Rat.cast_div, + Rat.cast_natCast, Rat.cast_natCast] push_cast - rfl + ring rw [hu, hfrac, powConst] -- the case of no violated darts is trivial by_cases hU0 : ((R.unsatDarts (R.kDecode q T hq A)).card : ℝ) = 0 diff --git a/Complexitylib/Classes/PCP/Internal/RankCount.lean b/Complexitylib/Classes/PCP/Internal/RankCount.lean index f561ce47..4d25960f 100644 --- a/Complexitylib/Classes/PCP/Internal/RankCount.lean +++ b/Complexitylib/Classes/PCP/Internal/RankCount.lean @@ -126,6 +126,6 @@ theorem idxOf_eq_countP {β : Type} [BEq β] [LawfulBEq β] {key : β → ℕ} : have hih := idxOf_eq_countP hpair.2 (fun p hp q hq => hinj p (List.mem_cons_of_mem _ hp) q (List.mem_cons_of_mem _ hq)) hxt rw [List.idxOf_cons_ne _ (Ne.symm hxa), hih, List.countP_cons] - simp only [decide_eq_true_eq, if_pos hlt] + simp only [decide_eq_true_eq, ite_eq_left hlt] end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/RegularGraph.lean b/Complexitylib/Classes/PCP/Internal/RegularGraph.lean index 9533df8b..d0c4b2c6 100644 --- a/Complexitylib/Classes/PCP/Internal/RegularGraph.lean +++ b/Complexitylib/Classes/PCP/Internal/RegularGraph.lean @@ -10,7 +10,7 @@ public import Mathlib.Algebra.Order.BigOperators.Ring.Finset public import Mathlib.Algebra.Order.Chebyshev public import Mathlib.Data.Fintype.BigOperators public import Mathlib.Data.Fintype.Prod -public import Mathlib.Data.Real.Basic +public import Mathlib.Basic.Real.Basic public import Mathlib.Tactic.FieldSimp public import Mathlib.Tactic.Linarith public import Mathlib.Tactic.Positivity diff --git a/Complexitylib/Classes/PCP/Internal/SecondMoment.lean b/Complexitylib/Classes/PCP/Internal/SecondMoment.lean index ba47cd7b..790e27b8 100644 --- a/Complexitylib/Classes/PCP/Internal/SecondMoment.lean +++ b/Complexitylib/Classes/PCP/Internal/SecondMoment.lean @@ -6,7 +6,7 @@ Authors: Bolton Bailey module public import Mathlib.Algebra.Order.BigOperators.Ring.Finset public import Mathlib.Data.Fintype.BigOperators -public import Mathlib.Data.Real.Basic +public import Mathlib.Basic.Real.Basic public import Mathlib.Tactic.Positivity public import Mathlib.Tactic.Linarith diff --git a/Complexitylib/Classes/PCP/Internal/SelfLoops.lean b/Complexitylib/Classes/PCP/Internal/SelfLoops.lean index 664f2b14..17eb2cb2 100644 --- a/Complexitylib/Classes/PCP/Internal/SelfLoops.lean +++ b/Complexitylib/Classes/PCP/Internal/SelfLoops.lean @@ -75,7 +75,8 @@ def addLoops : RegGraph := union (loopGraph G.V) G (Equiv.refl G.V) @[simp] theorem order_addLoops : G.addLoops.order = G.order := rfl @[simp] theorem deg_addLoops : G.addLoops.deg = 1 + G.deg := by - rw [addLoops, deg_union, deg_loopGraph] + rw [addLoops, deg_union (G := loopGraph G.V) (H := G) (e := Equiv.refl G.V), + deg_loopGraph] /-- The canonical self-loop at each vertex of `G.addLoops`. -/ def addLoopsLoops : G.addLoops.Loops where @@ -87,7 +88,7 @@ theorem spectralBound_addLoops {lam : ℝ} (hlam : 0 ≤ lam) (h : G.SpectralBou G.addLoops.SpectralBound ((1 + (G.deg : ℝ) * lam) / (1 + (G.deg : ℝ))) := by have hu := spectralBound_union (loopGraph G.V) G (Equiv.refl G.V) hlam h rw [deg_loopGraph] at hu - simpa using hu + exact_mod_cast hu theorem addLoops_bound_lt_one {lam : ℝ} (hlam1 : lam < 1) : (1 + (G.deg : ℝ) * lam) / (1 + (G.deg : ℝ)) < 1 := by @@ -117,22 +118,16 @@ theorem card_unsatDarts_addLoops (a : R.Assignment) : classical refine (Finset.card_bij (fun q _ => ((q.1, Sum.inr q.2) : R.addLoops.Dart)) ?_ ?_ ?_).symm · intro q hq - rw [mem_unsatDarts] at hq ⊢ - intro hcon - exact hq hcon + exact (mem_unsatDarts (R := R.addLoops)).mpr ((mem_unsatDarts (R := R)).mp hq) · intro q _ q' _ heq have h1 : q.1 = q'.1 := congrArg (fun r => (r.1 : R.graph.V)) heq have h2 : Sum.inr q.2 = (Sum.inr q'.2 : Unit ⊕ R.graph.D) := congrArg (fun r => (r.2 : Unit ⊕ R.graph.D)) heq exact Prod.ext h1 (Sum.inr.inj h2) · rintro ⟨v, _ | i⟩ hq - · exfalso - rw [mem_unsatDarts] at hq - exact hq rfl + · exact absurd rfl ((mem_unsatDarts (R := R.addLoops)).mp hq) · refine ⟨(v, i), ?_, rfl⟩ - rw [mem_unsatDarts] at hq ⊢ - intro hcon - exact hq hcon + exact (mem_unsatDarts (R := R)).mpr ((mem_unsatDarts (R := R.addLoops)).mp hq) /-- Adding loops scales the value by `deg / (deg + 1)`. -/ theorem unsatFrac_addLoops (a : R.Assignment) : @@ -150,10 +145,12 @@ theorem unsatFrac_addLoops (a : R.Assignment) : rw [hz] at hle omega have hempty' : (R.addLoops.unsatDarts a).card = 0 := by rw [hcards, hempty] - rw [unsatFrac, unsatFrac, hempty, hempty'] + unfold unsatFrac + rw [hempty, hempty'] simp · have hzq : (0 : ℚ) < (R.graph.order : ℚ) := by exact_mod_cast hz - rw [unsatFrac, unsatFrac, hcards] + unfold unsatFrac + rw [hcards] have hden : ((R.addLoops.graph.order * R.addLoops.graph.deg : ℕ) : ℚ) = (R.graph.order : ℚ) * ((R.graph.deg : ℚ) + 1) := by rw [graph_addLoops, RegGraph.order_addLoops, RegGraph.deg_addLoops] @@ -182,15 +179,12 @@ theorem satisfiable_addLoops_iff : R.addLoops.Satisfiable ↔ R.Satisfiable := b · rintro ⟨a, ha⟩ refine ⟨a, fun p => ?_⟩ have h := ha (p.1, Sum.inr p.2) - rw [Satisfies, satisfies] at h ⊢ exact h · rintro ⟨a, ha⟩ refine ⟨a, ?_⟩ rintro ⟨v, _ | i⟩ - · rw [Satisfies, satisfies] - rfl + · rfl · have h := ha (v, i) - rw [Satisfies, satisfies] at h ⊢ exact h end RegCSP diff --git a/Complexitylib/Classes/PCP/Internal/SquareVerifier.lean b/Complexitylib/Classes/PCP/Internal/SquareVerifier.lean index fdf64770..56efbbea 100644 --- a/Complexitylib/Classes/PCP/Internal/SquareVerifier.lean +++ b/Complexitylib/Classes/PCP/Internal/SquareVerifier.lean @@ -88,7 +88,7 @@ theorem fstCoinsFn_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : (fun z => fstCoins t (a z) (b z)) ∈ FP := by have hlen : (fun z => List.replicate (t (a z).length) true) ∈ FP := by have := mem_FP_comp ha ht - simpa using this + exact this have := Cobham.takeLenFn_mem_FP hlen hb refine mem_FP_of_eq this fun z => ?_ rw [fstCoins, List.length_replicate] @@ -98,7 +98,7 @@ theorem sndCoinsFn_mem_FP {a b : List Bool → List Bool} (ha : a ∈ FP) (hb : (fun z => sndCoins t (a z) (b z)) ∈ FP := by have hlen : (fun z => List.replicate (t (a z).length) true) ∈ FP := by have := mem_FP_comp ha ht - simpa using this + exact this have := dropLenFn_mem_FP hlen hb refine mem_FP_of_eq this fun z => ?_ rw [sndCoins, List.length_replicate] @@ -116,12 +116,12 @@ theorem sqPositions_mem (hf : f ∈ FP) (fstCoins t (pairFst z) (pairSnd z)))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hx (fstCoinsFn_mem_FP ht hx hr)) hf - simpa using this + exact this have h2 : (fun z : List Bool => f (pair (pairFst z) (sndCoins t (pairFst z) (pairSnd z)))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP hx (sndCoinsFn_mem_FP ht hx hr)) hf - simpa using this + exact this refine ⟨fun z => false :: (posInner (f (pair (pairFst z) (fstCoins t (pairFst z) (pairSnd z)))) ++ posInner (f (pair (pairFst z) @@ -152,7 +152,7 @@ theorem sqVerdict_mem_P (hf : f ∈ FP) sndCoinsFn_mem_FP ht vX_mem_FP vR_mem_FP have hfv : (fun z => f (pair (vX z) (fstCoins t (vX z) (vR z)))) ∈ FP := by have := mem_FP_comp (Cobham.pairFn_mem_FP vX_mem_FP hc1) hf - simpa using this + exact this have hn : (fun z => posCount (f (pair (vX z) (fstCoins t (vX z) (vR z))))) ∈ FP := posCount_mem_FP hfv have hnlen : ∀ z, (posCount (f (pair (vX z) (fstCoins t (vX z) (vR z))))).length @@ -226,7 +226,7 @@ theorem accepts_squareAt (ht : (fun x : List Bool => rw [answers, List.length_map] rw [Accepts, positions_squareAt, sqPositions, answers, List.map_append] show _ ∈ V.sqVerdict t ↔ _ - rw [sqVerdict, Set.mem_setOf_eq] + rw [sqVerdict, Set.mem_ofPred_eq] simp only [vX, vR, vA, pairFst_pair, pairSnd_pair] rw [show List.map (fun i => π.getD i false) (V.positions x (fstCoins t x ρ)) = answers π (V.positions x (fstCoins t x ρ)) from rfl, diff --git a/Complexitylib/Classes/PCP/Internal/StripTrailing.lean b/Complexitylib/Classes/PCP/Internal/StripTrailing.lean index 7eea1340..00239056 100644 --- a/Complexitylib/Classes/PCP/Internal/StripTrailing.lean +++ b/Complexitylib/Classes/PCP/Internal/StripTrailing.lean @@ -70,14 +70,14 @@ theorem stripTrailing_eq_bits (l : List Bool) : stripTrailing l = (binValLE l).b cases b · rw [stripTrailing_false, ih, binValLE_cons_false] by_cases h : (binValLE t).bits = [] - · rw [if_pos h] + · rw [ite_eq_left h] have h0 : binValLE t = 0 := by have hb := binValLE_bits (binValLE t) rw [h] at hb - simpa using hb.symm + exact hb.symm rw [h0] simp - · rw [if_neg h] + · rw [ite_eq_right h] have hne : binValLE t ≠ 0 := by intro h0 rw [h0, Nat.zero_bits] at h @@ -132,10 +132,10 @@ theorem recFoldClamp_stripTrailing (bound : ℕ) (W : List Bool) : rw [stripZero, hstate, stripTrailing_false] cases hs : stripTrailing t with | nil => - rw [emptyFlag_nil, selectHead_cons_true, if_pos rfl] + rw [emptyFlag_nil, selectHead_cons_true, ite_eq_left rfl] simp | cons c s => - rw [emptyFlag_cons, selectHead_cons_false, if_neg (by simp)] + rw [emptyFlag_cons, selectHead_cons_false, ite_eq_right (by simp)] refine List.take_of_length_le ?_ simp only [List.length_cons] rw [hs] at hlt diff --git a/Complexitylib/Classes/PCP/Internal/SubsetNP.lean b/Complexitylib/Classes/PCP/Internal/SubsetNP.lean index a42718b2..00d3c96a 100644 --- a/Complexitylib/Classes/PCP/Internal/SubsetNP.lean +++ b/Complexitylib/Classes/PCP/Internal/SubsetNP.lean @@ -127,9 +127,9 @@ theorem tableFun_eq {t : ℕ} {x : List Bool} {tbl : (Fin t → Bool) → List B classical cases b with | true => - rw [tableFun, if_pos ⟨ρ, i, hpos, hans⟩] + rw [tableFun, ite_eq_left ⟨ρ, i, hpos, hans⟩] | false => - rw [tableFun, if_neg] + rw [tableFun, ite_eq_right] rintro ⟨ρ', i', hpos', hans'⟩ have := hcons ρ ρ' i i' p hpos hpos' rw [hans, hans'] at this @@ -315,12 +315,12 @@ theorem tableOf_witnessOf {t Q : ℕ} (x π : List Bool) (hQ0 : 0 < Q) exact hkey rw [← List.getElem_eq_getD (h := hlen)] show ((List.range (2 ^ t * Q)).map _)[coinIndex ρ * Q + i] = _ - rw [List.getElem_map, List.getElem_range, dif_pos hdivlt, hrho hdivlt, hmod] + erw [List.getElem_map, List.getElem_range, dite_eq_left hdivlt, hrho hdivlt, hmod] show ((List.range (V.positions x (BitString.toList ρ)).length).map fun i => (V.witnessOf t Q x π).getD (coinIndex ρ * Q + i) false)[i] = _ - rw [List.getElem_map, List.getElem_range, hwit] + erw [List.getElem_map, List.getElem_range, hwit] show _ = (List.map (fun i => π.getD i false) _)[i] - rw [List.getElem_map] + erw [List.getElem_map] congr 1 rw [← List.getElem_eq_getD (h := hilt)] diff --git a/Complexitylib/Classes/PCP/Internal/SubsetNPFinal.lean b/Complexitylib/Classes/PCP/Internal/SubsetNPFinal.lean index b71f7b99..d767e997 100644 --- a/Complexitylib/Classes/PCP/Internal/SubsetNPFinal.lean +++ b/Complexitylib/Classes/PCP/Internal/SubsetNPFinal.lean @@ -47,7 +47,7 @@ theorem lenLang_mem_P have hexp : (fun z : List Bool => List.replicate (2 ^ r (pairFst z).length) true) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP (unaryExp_mem_FP_of_bigO_log hr hrlog) - simpa using this + exact this have hQ : (fun _ : List Bool => List.replicate Q false) ∈ FP := Cobham.const_replicate_mem_FP Q have hb : (fun z : List Bool => @@ -59,7 +59,7 @@ theorem lenLang_mem_P rw [exists_eqFlag_iff] constructor · intro h - rw [lenLang, Set.mem_setOf_eq] at h + rw [lenLang, Set.mem_ofPred_eq] at h rw [h] · intro h have := congrArg List.length h @@ -89,14 +89,14 @@ theorem mem_witLang_iff constructor · rintro ⟨hlen, hcons, hacc⟩ have hlen' : w.length = 2 ^ r x.length * Q := by - rw [lenLang, Set.mem_setOf_eq, pairFst_pair, pairSnd_pair] at hlen + rw [lenLang, Set.mem_ofPred_eq, pairFst_pair, pairSnd_pair] at hlen exact hlen refine ⟨hlen', ?_, ?_⟩ · exact (mem_consLang_iff V f r Q hfspec hlen' (hQ x)).mp hcons · exact (mem_accLang_iff V f r Q hfspec hlen' (hQ x)).mp hacc · rintro ⟨hlen, hcons, hacc⟩ refine ⟨?_, ?_, ?_⟩ - · rw [lenLang, Set.mem_setOf_eq, pairFst_pair, pairSnd_pair] + · rw [lenLang, Set.mem_ofPred_eq, pairFst_pair, pairSnd_pair] exact hlen · exact (mem_consLang_iff V f r Q hfspec hlen (hQ x)).mpr hcons · exact (mem_accLang_iff V f r Q hfspec hlen (hQ x)).mpr hacc diff --git a/Complexitylib/Classes/PCP/Internal/SymbolCodec.lean b/Complexitylib/Classes/PCP/Internal/SymbolCodec.lean index fb3256db..8f36338e 100644 --- a/Complexitylib/Classes/PCP/Internal/SymbolCodec.lean +++ b/Complexitylib/Classes/PCP/Internal/SymbolCodec.lean @@ -55,7 +55,7 @@ theorem symDec_symEnc {w : ℕ} (h : Fintype.card α ≤ 2 ^ w) (s : α) : lt_of_lt_of_le (Fintype.equivFin α s).isLt h have hval : binValLE (symEnc α w s) = (Fintype.equivFin α s).val := by rw [symEnc, binValLE_bitsOfLenLE _ _ hlt] - rw [symDec, hval, dif_pos (Fintype.equivFin α s).isLt] + rw [symDec, hval, dite_eq_left (Fintype.equivFin α s).isLt] simp end Complexity diff --git a/Complexitylib/Classes/PCP/Internal/TesterChecks.lean b/Complexitylib/Classes/PCP/Internal/TesterChecks.lean index 5afe4f75..5d68f5f7 100644 --- a/Complexitylib/Classes/PCP/Internal/TesterChecks.lean +++ b/Complexitylib/Classes/PCP/Internal/TesterChecks.lean @@ -225,7 +225,7 @@ theorem decodeLabel_eq {m : ℕ} {β : Type} [Nonempty β] (enc : β → Cube m) (h : bitDist t (hadamard (enc σ)) < 1 / 4) : decodeLabel enc t = σ := by classical have hex : ∃ σ : β, bitDist t (hadamard (enc σ)) < 1 / 4 := ⟨σ, h⟩ - rw [decodeLabel, dif_pos hex] + rw [decodeLabel, dite_eq_left hex] have hspec := Classical.choose_spec hex by_contra hne have hne' : enc (Classical.choose hex) ≠ enc σ := fun heq => hne (henc heq) diff --git a/Complexitylib/Classes/PCP/Internal/TowerFin.lean b/Complexitylib/Classes/PCP/Internal/TowerFin.lean index 2480c7c1..b13a0567 100644 --- a/Complexitylib/Classes/PCP/Internal/TowerFin.lean +++ b/Complexitylib/Classes/PCP/Internal/TowerFin.lean @@ -278,8 +278,7 @@ theorem data_zero_apply (v : Fin (F.size 0)) (i : Fin (F.deg ^ 2)) {p₁ : Fin (F.deg ^ 4) × Fin F.deg} (h1 : p₁ = F.rot (p₀.1, s 1)) : (F.data 0).1 (v, i) = (F.zeroVertName p₁.1, F.zeroDartName ![p₁.2, p₀.2]) := by subst hs h0 h1 - simp only [data, RegGraph.relabel, RegGraph.relabelV, RegGraph.rot_power_two, graph, - RegGraph.ofRot] + simp only [data, RegGraph.relabel, RegGraph.relabelV, graph, RegGraph.ofRot] rfl /-- **The step in full**, with the two walks of the level below spelled out. -/ @@ -296,7 +295,7 @@ theorem data_succ_apply' (k : ℕ) (v : Fin (F.size (k + 1))) (i : Fin (F.deg ^ (F.data (k + 1)).1 (v, i) = (F.vertName k (q₁.1, F.baseName r.1), F.dartName (r.2, p.2)) := by refine F.data_succ_apply k v i hus hab hp (q := (q₁.1, ![q₁.2, q₀.2])) ?_ hr - rw [RegGraph.rot_power_two, rot_graphAt, hq₁, hq₀] + erw [RegGraph.rot_power_two, rot_graphAt, hq₁, hq₀] rfl /-! ### The recursion, in numbers -/ @@ -309,7 +308,7 @@ noncomputable def baseVal (x a : ℕ) : ℕ × ℕ := @[simp] theorem baseVal_apply (x : Fin (F.deg ^ 4)) (a : Fin F.deg) : F.baseVal x.val a.val = ((F.rot (x, a)).1.val, (F.rot (x, a)).2.val) := by - rw [baseVal, dif_pos ⟨x.isLt, a.isLt⟩] + rw [baseVal, dite_eq_left ⟨x.isLt, a.isLt⟩] /-- **The tower's rotation map, on raw numbers.** A level-`(k+1)` vertex `v` splits as `v / deg^4` (the level below) and `v % deg^4` (the base); a dart `i` @@ -387,7 +386,7 @@ theorem rotVal_eq (k : ℕ) (v : Fin (F.size k)) (i : Fin (F.deg ^ 2)) : theorem baseVal_lt {x a : ℕ} (hx : x < F.deg ^ 4) (ha : a < F.deg) : (F.baseVal x a).1 < F.deg ^ 4 ∧ (F.baseVal x a).2 < F.deg := by - rw [baseVal, dif_pos ⟨hx, ha⟩] + rw [baseVal, dite_eq_left ⟨hx, ha⟩] exact ⟨Fin.isLt _, Fin.isLt _⟩ theorem rotVal_lt (k : ℕ) {v i : ℕ} (hv : v < F.size k) (hi : i < F.deg ^ 2) : diff --git a/Complexitylib/Classes/PCP/Internal/TowerTable.lean b/Complexitylib/Classes/PCP/Internal/TowerTable.lean index 5c14c886..8422afd8 100644 --- a/Complexitylib/Classes/PCP/Internal/TowerTable.lean +++ b/Complexitylib/Classes/PCP/Internal/TowerTable.lean @@ -114,7 +114,7 @@ theorem baseRec_eq {x a : ℕ} (hx : x < F.deg ^ 4) (ha : a < F.deg) : ≤ F.baseKeyBound := by rw [pair_length, List.length_replicate, List.length_replicate, baseKeyBound] omega - rw [baseRec, if_pos (mem_keySet.mpr ⟨hlen, trivial⟩), baseRaw, + rw [baseRec, ite_eq_left (mem_keySet.mpr ⟨hlen, trivial⟩), baseRaw, pairFst_pair, pairSnd_pair, List.length_replicate, List.length_replicate] @@ -298,7 +298,7 @@ theorem length_table_le (l : ℕ) : have hlt := F.rotVal_lt l hv hi rw [← encPair_eq, length_encPair] omega - have hsum := List.sum_le_card_nsmul _ _ hbound + have hsum := List.sum_le_length_nsmul _ _ hbound rw [List.length_map, length_tableList] at hsum simp only [smul_eq_mul] at hsum omega diff --git a/Complexitylib/Classes/PCP/Internal/UnaryDivMod.lean b/Complexitylib/Classes/PCP/Internal/UnaryDivMod.lean index 07a3b069..34cd9fdd 100644 --- a/Complexitylib/Classes/PCP/Internal/UnaryDivMod.lean +++ b/Complexitylib/Classes/PCP/Internal/UnaryDivMod.lean @@ -171,17 +171,17 @@ theorem dmRun_mem_FP (b : List Bool) : dmRun b ∈ FP := by Polynomial.eval_X, id, List.length_nil, Nat.zero_add] at * omega have hiter := Cobham.iterate_mem_FP dmStep_mem_FP hinit id_mem_FP hwidth hbound - simpa using hiter + exact hiter theorem divFn_mem_FP (b : List Bool) : divFn b ∈ FP := by have := mem_FP_comp (mem_FP_comp (dmRun_mem_FP b) Cobham.fstBlock_mem_FP) Cobham.fstBlock_mem_FP - simpa using this + exact this theorem modFn_mem_FP (b : List Bool) : modFn b ∈ FP := by have := mem_FP_comp (mem_FP_comp (dmRun_mem_FP b) Cobham.fstBlock_mem_FP) Cobham.sndBlock_mem_FP - simpa using this + exact this theorem divFn_eq {b : List Bool} (hb : 0 < b.length) (s : List Bool) : divFn b s = List.replicate (s.length / b.length) true := by @@ -233,17 +233,17 @@ theorem dmRun2_mem_FP : dmRun2 ∈ FP := by Polynomial.eval_X, id, List.length_nil, Nat.zero_add] at * omega have hiter := Cobham.iterate_mem_FP dmStep_mem_FP hinit Cobham.sndBlock_mem_FP hwidth hbound - simpa using hiter + exact hiter theorem divFn2_mem_FP : divFn2 ∈ FP := by have := mem_FP_comp (mem_FP_comp dmRun2_mem_FP Cobham.fstBlock_mem_FP) Cobham.fstBlock_mem_FP - simpa using this + exact this theorem modFn2_mem_FP : modFn2 ∈ FP := by have := mem_FP_comp (mem_FP_comp dmRun2_mem_FP Cobham.fstBlock_mem_FP) Cobham.sndBlock_mem_FP - simpa using this + exact this theorem divFn2_eq {b : List Bool} (hb : 0 < b.length) (s : List Bool) : divFn2 (pair b s) = List.replicate (s.length / b.length) true := by diff --git a/Complexitylib/Classes/PCP/Internal/Union.lean b/Complexitylib/Classes/PCP/Internal/Union.lean index 5ac7956c..09b51c69 100644 --- a/Complexitylib/Classes/PCP/Internal/Union.lean +++ b/Complexitylib/Classes/PCP/Internal/Union.lean @@ -112,9 +112,9 @@ theorem step_union (f : G.V → ℝ) (v : G.V) : show ∑ i : G.D ⊕ H.D, f ((union G H e).nbr v i) = _ rw [Fintype.sum_sum_type] rfl - rw [step, hsum, deg_union] + unfold step + rw [hsum, deg_union] push_cast - rw [step, step] field_simp /-! ### The combined contraction bound -/ diff --git a/Complexitylib/Classes/PCP/Internal/VerifierLang.lean b/Complexitylib/Classes/PCP/Internal/VerifierLang.lean index fd833557..00f10d67 100644 --- a/Complexitylib/Classes/PCP/Internal/VerifierLang.lean +++ b/Complexitylib/Classes/PCP/Internal/VerifierLang.lean @@ -93,7 +93,7 @@ theorem tableOf_eq_wBlock (V : PCPVerifier) (t Q : ℕ) (x w : List Bool) rwa [V.length_tableOf t Q x w ρ] at h1 rw [getElem_wBlock h hi] show (List.map _ (List.range _))[i] = _ - rw [List.getElem_map, List.getElem_range] + erw [List.getElem_map, List.getElem_range] /-- A one-bit block is the bit it holds. -/ theorem wBlock_one {w : List Bool} {k : ℕ} (h : k < w.length) : @@ -150,10 +150,10 @@ theorem accCoin_mem_FP accCoin r ∈ FP := by have ht : (fun y : List Bool => List.replicate (r (accX y).length) true) ∈ FP := by have := mem_FP_comp accX_mem_FP hr - simpa using this + exact this have hc : (fun y : List Bool => List.replicate (pairSnd y).length true) ∈ FP := by have := mem_FP_comp Cobham.sndBlock_mem_FP unaryLength_mem_FP - simpa using this + exact this exact coinStr_mem_FP ht hc theorem accView_mem_FP (hf : f ∈ FP) @@ -164,7 +164,7 @@ theorem accView_mem_FP (hf : f ∈ FP) Cobham.pairFn_mem_FP accX_mem_FP hcoin have hfv : (fun y => f (pair (accX y) (accCoin r y))) ∈ FP := by have := mem_FP_comp hview hf - simpa using this + exact this have hcount : (fun y => posCount (f (pair (accX y) (accCoin r y)))) ∈ FP := posCount_mem_FP hfv have hoff : (fun y : List Bool => @@ -202,7 +202,7 @@ theorem accLang_mem_P (hf : f ∈ FP) have hlen : (fun z : List Bool => List.replicate (2 ^ r (pairFst z).length) true) ∈ FP := by have := mem_FP_comp Cobham.fstBlock_mem_FP (unaryExp_mem_FP_of_bigO_log hr hrlog) - simpa using this + exact this exact forall_unary_mem_P (accInner_mem_P V f r Q hf hr) hlen /-- What one iteration looks at, on a well-formed input. -/ diff --git a/Complexitylib/Classes/PCP/Internal/WalkPath.lean b/Complexitylib/Classes/PCP/Internal/WalkPath.lean index 03a91909..5faa3fd9 100644 --- a/Complexitylib/Classes/PCP/Internal/WalkPath.lean +++ b/Complexitylib/Classes/PCP/Internal/WalkPath.lean @@ -170,12 +170,12 @@ def padWalk {t : ℕ} (v : G.V) (s : Fin t → G.D) (k h : ℕ) : Fin h → G.D theorem padWalk_of_lt {t : ℕ} (v : G.V) (s : Fin t → G.D) {k h : ℕ} (j : Fin h) (hj : j.val < min k t) : L.padWalk v s k h j = s ⟨j.val, lt_of_lt_of_le hj (min_le_right k t)⟩ := - dif_pos hj + dite_eq_left hj theorem padWalk_of_ge {t : ℕ} (v : G.V) (s : Fin t → G.D) {k h : ℕ} (j : Fin h) (hj : ¬ j.val < min k t) : L.padWalk v s k h j = L.loop (G.walkAt t v s k) := - dif_neg hj + dite_eq_right hj /-- Below `k` the padded walk follows the original. -/ theorem walkAt_padWalk_of_le {t : ℕ} (v : G.V) (s : Fin t → G.D) {k h : ℕ} diff --git a/Complexitylib/Classes/PCP/Internal/WalkSplit.lean b/Complexitylib/Classes/PCP/Internal/WalkSplit.lean index 7a1512b9..f127e815 100644 --- a/Complexitylib/Classes/PCP/Internal/WalkSplit.lean +++ b/Complexitylib/Classes/PCP/Internal/WalkSplit.lean @@ -81,7 +81,7 @@ def segGlue {ℓ i : ℕ} (p : Fin i → G.D) (d : G.D) (s : Fin (ℓ - (i + 1)) have hk := k.isLt have h1 : ¬ (i + 1 + k.val < i) := by omega have h2 : ¬ (i + 1 + k.val = i) := by omega - simp only [segSuf, segGlue, dif_neg h1, dif_neg h2] + simp only [segSuf, segGlue, dite_eq_right h1, dite_eq_right h2] congr 1 have : i + 1 + k.val - (i + 1) = k.val := by omega exact Fin.ext this @@ -97,7 +97,7 @@ theorem segGlue_split {ℓ i : ℕ} (hi : i < ℓ) (W : Fin ℓ → G.D) : simp · have h1 : ¬ (k.val < i) := by omega have h2 : ¬ (k.val = i) := by omega - simp only [segGlue, dif_neg h1, dif_neg h2, segSuf] + simp only [segGlue, dite_eq_right h1, dite_eq_right h2, segSuf] congr 1 have : i + 1 + (k.val - (i + 1)) = k.val := by omega exact Fin.ext this @@ -117,7 +117,7 @@ theorem walkAt_segSuf {ℓ : ℕ} (v : G.V) (W : Fin ℓ → G.D) (i : ℕ) : have hmlt : m < ℓ - (i + 1) := by omega have hilt : i + 1 + m < ℓ := by omega have hidx : i + 1 + (m + 1) = (i + 1 + m) + 1 := by omega - rw [walkAt, dif_pos hmlt, ih hm', hidx, G.walkAt_succ_of_lt v W hilt] + rw [walkAt, dite_eq_left hmlt, ih hm', hidx, G.walkAt_succ_of_lt v W hilt] exact congrArg (G.nbr (G.walkAt ℓ v W (i + 1 + m))) rfl /-- **Reversal commutes with splitting.** Reversing the suffix of a walk gives @@ -316,7 +316,7 @@ theorem walkAt_preWalk {T ℓ : ℕ} (h : ℓ ≤ T) (x : G.V) (s : Fin T → G. intro hk have hkl : k < ℓ := by omega have hkT : k < T := by omega - rw [walkAt, dif_pos hkl, ih (by omega), walkAt, dif_pos hkT] + rw [walkAt, dite_eq_left hkl, ih (by omega), walkAt, dite_eq_left hkT] congr 1 end RegGraph diff --git a/Complexitylib/Classes/PCP/Internal/ZigZag.lean b/Complexitylib/Classes/PCP/Internal/ZigZag.lean index a6390b69..a9705c2f 100644 --- a/Complexitylib/Classes/PCP/Internal/ZigZag.lean +++ b/Complexitylib/Classes/PCP/Internal/ZigZag.lean @@ -117,7 +117,7 @@ def zigzag : RegGraph where haveI := H.fintypeD exact inferInstance nonemptyD := by - haveI := H.nonemptyD + have := H.nonemptyD exact inferInstance rot := zigzagRot G H e rot_involutive := zigzagRot_involutive G H e @@ -152,16 +152,16 @@ theorem step_zigzag (f : (zigzag G H e).V → ℝ) (x : (zigzag G H e).V) : have hsum : (∑ d : (zigzag G H e).D, f ((zigzag G H e).nbr x d)) = ∑ a : H.D, ∑ b : H.D, f ((zigzagRot G H e (x, (a, b))).1) := Fintype.sum_prod_type (f := fun d : H.D × H.D => f ((zigzagRot G H e (x, d)).1)) - rw [RegGraph.step, hdeg, hsum, cloudStep] + erw [RegGraph.step, hdeg, hsum, cloudStep] have hinner : ∀ a : H.D, ∑ b : H.D, f ((zigzagRot G H e (x, (a, b))).1) = (H.deg : ℝ) * cloudStep G H e f (G.rot (x.1, e (H.rot (e.symm x.2, a)).1)) := by intro a - rw [cloudStep] + erw [cloudStep] field_simp rfl - rw [Finset.sum_congr rfl fun a _ => hinner a, ← Finset.mul_sum] + erw [Finset.sum_congr rfl fun a _ => hinner a, ← Finset.mul_sum] show _ = (∑ b : H.D, cloudStep G H e f (G.rot (x.1, e (H.rot (e.symm x.2, b)).1))) / (H.deg : ℝ) field_simp @@ -211,7 +211,6 @@ theorem sum_cloudStep (f : G.V × G.D → ℝ) (v : G.V) : = ∑ u : H.V, H.step (cloudFun G H e f v) u := (Fintype.sum_equiv e (fun u => H.step (cloudFun G H e f v) u) (fun i => cloudStep G H e f (v, i)) fun u => by - dsimp only rw [cloudStep_apply, Equiv.symm_apply_apply]).symm rw [h, H.sum_step, sum_cloudFun] @@ -228,7 +227,6 @@ theorem sum_sq_cloudStep_le {lam : ℝ} (hH : H.SpectralBound lam) = ∑ u : H.V, (H.step (cloudFun G H e f v) u) ^ 2 := (Fintype.sum_equiv e (fun u => (H.step (cloudFun G H e f v) u) ^ 2) (fun i => (cloudStep G H e f (v, i)) ^ 2) fun u => by - dsimp only rw [cloudStep_apply, Equiv.symm_apply_apply]).symm rw [h, ← sum_sq_cloudFun] exact hbound @@ -249,7 +247,7 @@ noncomputable def cloudPerp (f : G.V × G.D → ℝ) : G.V × G.D → ℝ := theorem cloudPar_add_cloudPerp (f : G.V × G.D → ℝ) (x : G.V × G.D) : cloudPar G f x + cloudPerp G f x = f x := by - rw [cloudPerp] + erw [cloudPerp] ring /-- **The cloud move fixes the constant part.** -/ @@ -266,9 +264,9 @@ theorem sum_cloudPerp (f : G.V × G.D → ℝ) (v : G.V) : ∑ i : G.D, cloudPerp G f (v, i) = 0 := by have hdeg : (G.deg : ℝ) ≠ 0 := G.deg_ne_zero have hcard : (Finset.univ : Finset G.D).card = G.deg := Finset.card_univ - rw [show (fun i : G.D => cloudPerp G f (v, i)) + erw [show (fun i : G.D => cloudPerp G f (v, i)) = fun i : G.D => f (v, i) - cloudMean G f v from rfl] - rw [Finset.sum_sub_distrib, Finset.sum_const, hcard, nsmul_eq_mul, cloudMean] + erw [Finset.sum_sub_distrib, Finset.sum_const, hcard, nsmul_eq_mul, cloudMean] field_simp ring @@ -295,13 +293,13 @@ theorem sum_mul_step_comm (K : RegGraph) (f g : K.V → ℝ) : noncomputable def ip (f g : G.V × G.D → ℝ) : ℝ := ∑ x : G.V × G.D, f x * g x theorem ip_comm (f g : G.V × G.D → ℝ) : ip G f g = ip G g f := by - rw [ip, ip] + erw [ip, ip] exact Finset.sum_congr rfl fun x _ => mul_comm _ _ /-- Summing over the product is summing cloud by cloud. -/ theorem ip_eq_sum_clouds (f g : G.V × G.D → ℝ) : ip G f g = ∑ v : G.V, ∑ i : G.D, f (v, i) * g (v, i) := by - rw [ip, Fintype.sum_prod_type] + erw [ip, Fintype.sum_prod_type] /-- **The cloud move is self-adjoint**, because `H`'s walk is. -/ theorem ip_cloudStep (f g : G.V × G.D → ℝ) : @@ -313,7 +311,6 @@ theorem ip_cloudStep (f g : G.V × G.D → ℝ) : (Fintype.sum_equiv e (fun u => H.step (cloudFun G H e f v) u * cloudFun G H e g v u) (fun i => cloudStep G H e f (v, i) * g (v, i)) fun u => by - dsimp only rw [cloudStep_apply, Equiv.symm_apply_apply] rfl).symm have hr : ∑ i : G.D, f (v, i) * cloudStep G H e g (v, i) @@ -321,7 +318,6 @@ theorem ip_cloudStep (f g : G.V × G.D → ℝ) : (Fintype.sum_equiv e (fun u => cloudFun G H e f v u * H.step (cloudFun G H e g v) u) (fun i => f (v, i) * cloudStep G H e g (v, i)) fun u => by - dsimp only rw [cloudStep_apply, Equiv.symm_apply_apply] rfl).symm rw [hl, hr, ← sum_mul_step_comm] @@ -329,7 +325,7 @@ theorem ip_cloudStep (f g : G.V × G.D → ℝ) : /-- **The crossing move is self-adjoint**, because `G.rot` is an involution. -/ theorem ip_crossStep (f g : G.V × G.D → ℝ) : ip G (crossStep G f) g = ip G f (crossStep G g) := by - rw [ip, ip] + erw [ip, ip] refine Fintype.sum_equiv (G.rot_involutive.toPerm) (fun x => crossStep G f x * g x) (fun x => f x * crossStep G g x) fun x => ?_ show f (G.rot x) * g x = f (G.rot x) * g (G.rot (G.rot x)) @@ -338,7 +334,7 @@ theorem ip_crossStep (f g : G.V × G.D → ℝ) : /-- Cauchy–Schwarz for this inner product. -/ theorem ip_sq_le (f g : G.V × G.D → ℝ) : (ip G f g) ^ 2 ≤ ip G f f * ip G g g := by have h := Finset.sum_mul_sq_le_sq_mul_sq (Finset.univ : Finset (G.V × G.D)) f g - rw [ip, ip, ip] + erw [ip, ip, ip] calc (∑ x : G.V × G.D, f x * g x) ^ 2 ≤ (∑ x : G.V × G.D, f x ^ 2) * ∑ x : G.V × G.D, g x ^ 2 := h _ = (∑ x : G.V × G.D, f x * f x) * ∑ x : G.V × G.D, g x * g x := by @@ -359,7 +355,7 @@ product of the functions they come from. -/ theorem ip_cloudPar (f g : G.V × G.D → ℝ) : ip G (cloudPar G f) (cloudPar G g) = (G.deg : ℝ) * ∑ v : G.V, cloudMean G f v * cloudMean G g v := by - rw [ip_eq_sum_clouds, Finset.mul_sum] + erw [ip_eq_sum_clouds, Finset.mul_sum] refine Finset.sum_congr rfl fun v _ => ?_ have hconst : ∀ i : G.D, cloudPar G f (v, i) * cloudPar G g (v, i) = cloudMean G f v * cloudMean G g v := fun _ => rfl @@ -391,18 +387,18 @@ theorem ip_cloudPar_crossStep (f : G.V × G.D → ℝ) : ip G (cloudPar G f) (crossStep G (cloudPar G f)) = (G.deg : ℝ) * ∑ v : G.V, cloudMean G f v * G.step (cloudMean G f) v := by have hdeg : (G.deg : ℝ) ≠ 0 := G.deg_ne_zero - rw [ip_eq_sum_clouds, Finset.mul_sum] + erw [ip_eq_sum_clouds, Finset.mul_sum] refine Finset.sum_congr rfl fun v _ => ?_ have h : ∀ i : G.D, cloudPar G f (v, i) * crossStep G (cloudPar G f) (v, i) = cloudMean G f v * cloudMean G f (G.nbr v i) := fun _ => rfl - rw [Finset.sum_congr rfl fun i _ => h i, ← Finset.mul_sum, RegGraph.step] + erw [Finset.sum_congr rfl fun i _ => h i, ← Finset.mul_sum, RegGraph.step] field_simp /-! ### Linearity -/ theorem cloudStep_add (f g : G.V × G.D → ℝ) (x : G.V × G.D) : cloudStep G H e (fun y => f y + g y) x = cloudStep G H e f x + cloudStep G H e g x := by - rw [cloudStep, cloudStep, cloudStep, ← add_div] + erw [cloudStep, cloudStep, cloudStep, ← add_div] congr 1 exact Finset.sum_add_distrib @@ -411,12 +407,12 @@ theorem crossStep_add (f g : G.V × G.D → ℝ) (x : G.V × G.D) : theorem ip_add_left (f g h : G.V × G.D → ℝ) : ip G (fun x => f x + g x) h = ip G f h + ip G g h := by - rw [ip, ip, ip, ← Finset.sum_add_distrib] + erw [ip, ip, ip, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl fun x _ => by ring theorem ip_add_right (f g h : G.V × G.D → ℝ) : ip G f (fun x => g x + h x) = ip G f g + ip G f h := by - rw [ip, ip, ip, ← Finset.sum_add_distrib] + erw [ip, ip, ip, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl fun x _ => by ring /-- **One cloud move splits into the constant part and a contracted @@ -439,7 +435,7 @@ theorem step_zigzag_decomp (f : (zigzag G H e).V → ℝ) : have hz : (zigzag G H e).step f = cloudStep G H e (crossStep G (cloudStep G H e f)) := by funext x exact hstep x - rw [hz, ← ip_cloudStep] + erw [hz, ← ip_cloudStep] have hdec : cloudStep G H e f = fun x => cloudPar G f x + cloudStep G H e (cloudPerp G f) x := by funext x @@ -455,7 +451,7 @@ theorem ip_crossStep_expand (p q : G.V × G.D → ℝ) : = fun x => crossStep G p x + crossStep G q x := by funext x exact crossStep_add G p q x - rw [hc, ip_add_left, ip_add_right, ip_add_right] + erw [hc, ip_add_left, ip_add_right, ip_add_right] ring /-- **The zig-zag quadratic form, expanded.** The first summand is `G`'s own @@ -491,7 +487,7 @@ theorem ip_cloudStep_cloudPerp_le {lam : ℝ} (hH : H.SpectralBound lam) (f : G.V × G.D → ℝ) : ip G (cloudStep G H e (cloudPerp G f)) (cloudStep G H e (cloudPerp G f)) ≤ lam ^ 2 * ip G (cloudPerp G f) (cloudPerp G f) := by - rw [ip_eq_sum_clouds, ip_eq_sum_clouds, Finset.mul_sum] + erw [ip_eq_sum_clouds, ip_eq_sum_clouds, Finset.mul_sum] refine Finset.sum_le_sum fun v _ => ?_ have hb := sum_sq_cloudStep_cloudPerp_le G H e hH f v have hl : ∑ i : G.D, cloudStep G H e (cloudPerp G f) (v, i) @@ -532,7 +528,7 @@ theorem ip_cloudPar_cloudPerp (f : G.V × G.D → ℝ) : refine Finset.sum_eq_zero fun v _ => ?_ have h : ∀ i : G.D, cloudPar G f (v, i) * cloudPerp G f (v, i) = cloudMean G f v * cloudPerp G f (v, i) := fun _ => rfl - rw [Finset.sum_congr rfl fun i _ => h i, ← Finset.mul_sum, sum_cloudPerp, mul_zero] + erw [Finset.sum_congr rfl fun i _ => h i, ← Finset.mul_sum, sum_cloudPerp, mul_zero] /-- **Pythagoras** for the splitting. -/ theorem ip_self_split (f : G.V × G.D → ℝ) : @@ -553,7 +549,7 @@ theorem ip_two_mul_le (u w : G.V × G.D → ℝ) {t : ℝ} (ht : 0 < t) : Finset.sum_nonneg fun _ _ => sq_nonneg _ have hexp : ∑ x : G.V × G.D, (t * u x - w x) ^ 2 = t ^ 2 * ip G u u - 2 * t * ip G u w + ip G w w := by - rw [ip, ip, ip, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, + erw [ip, ip, ip, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_sub_distrib, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl fun x _ => by ring rw [hexp] at hnn @@ -566,7 +562,7 @@ theorem ip_two_mul_le (u w : G.V × G.D → ℝ) {t : ℝ} (ht : 0 < t) : /-- The crossing move preserves the inner product with itself, in `ip` form. -/ theorem ip_crossStep_self (g : G.V × G.D → ℝ) : ip G (crossStep G g) (crossStep G g) = ip G g g := by - rw [ip, ip] + erw [ip, ip] exact sum_sq_crossStep_aux G g /-! ### The Reingold–Vadhan–Wigderson estimate -/ @@ -596,13 +592,13 @@ theorem ip_step_zigzag_le {lamG lamH : ℝ} (hG : G.SpectralBound lamG) have hsplit : ip G f f = a + b := ip_self_split G f have hterm1 : ip G p (crossStep G p) ≤ lamG * a := ip_cloudPar_crossStep_le G hG hlamG hf have hsym : ip G q (crossStep G p) = ip G p (crossStep G q) := by - rw [← ip_crossStep, ip_comm] + erw [← ip_crossStep, ip_comm] have hcross : 2 * ip G p (crossStep G q) ≤ lamH * a + lamH * b := by rcases eq_or_lt_of_le hlamH with h0 | hpos · have hz : ip G q q = 0 := le_antisymm (by rw [← h0] at hqq; simpa using hqq) hq0 have hqzero : ∀ x, q x = 0 := fun x => eq_zero_of_ip_self_eq_zero G hz x have : ip G p (crossStep G q) = 0 := by - rw [ip] + erw [ip] refine Finset.sum_eq_zero fun x _ => ?_ show p x * q (G.rot x) = 0 rw [hqzero, mul_zero] @@ -635,12 +631,10 @@ theorem ip_cloudStep_le (g : G.V × G.D → ℝ) : = ∑ u : H.V, (H.step (cloudFun G H e g v) u) ^ 2 := (Fintype.sum_equiv e (fun u => (H.step (cloudFun G H e g v) u) ^ 2) (fun i => cloudStep G H e g (v, i) * cloudStep G H e g (v, i)) fun u => by - dsimp only rw [cloudStep_apply, Equiv.symm_apply_apply, sq]).symm have hr : ∑ i : G.D, g (v, i) * g (v, i) = ∑ u : H.V, (cloudFun G H e g v u) ^ 2 := (Fintype.sum_equiv e (fun u => (cloudFun G H e g v u) ^ 2) (fun i => g (v, i) * g (v, i)) fun u => by - dsimp only rw [sq] rfl).symm rw [hl, hr] @@ -650,12 +644,12 @@ theorem ip_cloudStep_le (g : G.V × G.D → ℝ) : theorem ip_neg_left (u w : G.V × G.D → ℝ) : ip G (fun x => -u x) w = -ip G u w := by - rw [ip, ip, ← Finset.sum_neg_distrib] + erw [ip, ip, ← Finset.sum_neg_distrib] exact Finset.sum_congr rfl fun x _ => by ring theorem ip_neg_self (u : G.V × G.D → ℝ) : ip G (fun x => -u x) (fun x => -u x) = ip G u u := by - rw [ip, ip] + erw [ip, ip] exact Finset.sum_congr rfl fun x _ => by ring /-- The weighted bound, two-sided. -/ @@ -716,13 +710,13 @@ theorem abs_ip_step_zigzag_le {lamG lamH : ℝ} (hG : G.SpectralBound lamG) have hterm1 : |ip G p (crossStep G p)| ≤ lamG * a := abs_ip_cloudPar_crossStep_le G hG hlamG hf have hsym : ip G q (crossStep G p) = ip G p (crossStep G q) := by - rw [← ip_crossStep, ip_comm] + erw [← ip_crossStep, ip_comm] have hcross : 2 * |ip G p (crossStep G q)| ≤ lamH * a + lamH * b := by rcases eq_or_lt_of_le hlamH with h0 | hpos · have hz : ip G q q = 0 := le_antisymm (by rw [← h0] at hqq; simpa using hqq) hq0 have hqzero : ∀ x, q x = 0 := fun x => eq_zero_of_ip_self_eq_zero G hz x have hzero2 : ip G p (crossStep G q) = 0 := by - rw [ip] + erw [ip] refine Finset.sum_eq_zero fun x _ => ?_ show p x * q (G.rot x) = 0 rw [hqzero, mul_zero] @@ -760,24 +754,24 @@ theorem step_sub (K : RegGraph) (f g : K.V → ℝ) (v : K.V) : theorem ip_sub_left (f g h : G.V × G.D → ℝ) : ip G (fun x => f x - g x) h = ip G f h - ip G g h := by - rw [ip, ip, ip, ← Finset.sum_sub_distrib] + erw [ip, ip, ip, ← Finset.sum_sub_distrib] exact Finset.sum_congr rfl fun x _ => by ring theorem ip_sub_right (f g h : G.V × G.D → ℝ) : ip G f (fun x => g x - h x) = ip G f g - ip G f h := by - rw [ip, ip, ip, ← Finset.sum_sub_distrib] + erw [ip, ip, ip, ← Finset.sum_sub_distrib] exact Finset.sum_congr rfl fun x _ => by ring /-- The walk of the product is self-adjoint — it is a walk, like any other. -/ theorem ip_step_zigzag_comm (f g : G.V × G.D → ℝ) : ip G ((zigzag G H e).step f) g = ip G f ((zigzag G H e).step g) := by - rw [ip, ip] + erw [ip, ip] exact (sum_mul_step_comm (zigzag G H e) f g).symm /-- The sum of squares over the product's vertices, as an inner product. -/ theorem sum_sq_eq_ip (g : (zigzag G H e).V → ℝ) : ∑ v : (zigzag G H e).V, (g v) ^ 2 = ip G g g := by - rw [ip] + erw [ip] exact Finset.sum_congr rfl fun x _ => sq _ /-- **Polarisation.** -/ @@ -794,11 +788,11 @@ theorem ip_polarise (f g : G.V × G.D → ℝ) : funext x exact step_sub (zigzag G H e) f g x have hcross : ip G ((zigzag G H e).step g) f = ip G ((zigzag G H e).step f) g := by - rw [ip_step_zigzag_comm, ip_comm] + erw [ip_step_zigzag_comm, ip_comm] have key : ip G ((zigzag G H e).step (fun x => f x + g x)) (fun x => f x + g x) - ip G ((zigzag G H e).step (fun x => f x - g x)) (fun x => f x - g x) = 2 * ip G ((zigzag G H e).step f) g + 2 * ip G ((zigzag G H e).step g) f := by - rw [hadd, hsub, ip, ip, ip, ip, ← Finset.sum_sub_distrib, Finset.mul_sum, + erw [hadd, hsub, ip, ip, ip, ip, ← Finset.sum_sub_distrib, Finset.mul_sum, Finset.mul_sum, ← Finset.sum_add_distrib] exact Finset.sum_congr rfl fun x _ => by ring rw [key, hcross] @@ -823,24 +817,24 @@ theorem spectralBound_zigzag {lamG lamH : ℝ} (hG : G.SpectralBound lamG) intro c hc set g : G.V × G.D → ℝ := fun x => c * (zigzag G H e).step f x with hg have hg0 : ∑ x : G.V × G.D, g x = 0 := by - rw [hg, ← Finset.mul_sum, hTf0, mul_zero] + erw [hg, ← Finset.mul_sum, hTf0, mul_zero] have hgg : ip G g g = c ^ 2 * ip G ((zigzag G H e).step f) ((zigzag G H e).step f) := by - rw [hg, ip, ip, Finset.mul_sum] + erw [hg, ip, ip, Finset.mul_sum] exact Finset.sum_congr rfl fun x _ => by ring have hTfg : ip G ((zigzag G H e).step f) g = c * ip G ((zigzag G H e).step f) ((zigzag G H e).step f) := by - rw [hg, ip, ip, Finset.mul_sum] + erw [hg, ip, ip, Finset.mul_sum] exact Finset.sum_congr rfl fun x _ => by ring have hpol := ip_polarise G H e f g have h1 := abs_ip_step_zigzag_le G H e hG hH hlamG hlamH - (fun x => f x + g x) (by rw [Finset.sum_add_distrib, hf', hg0]; ring) + (fun x => f x + g x) (by erw [Finset.sum_add_distrib, hf', hg0]; ring) have h2 := abs_ip_step_zigzag_le G H e hG hH hlamG hlamH - (fun x => f x - g x) (by rw [Finset.sum_sub_distrib, hf', hg0]; ring) + (fun x => f x - g x) (by erw [Finset.sum_sub_distrib, hf', hg0]; ring) have hpar : ip G (fun x => f x + g x) (fun x => f x + g x) + ip G (fun x => f x - g x) (fun x => f x - g x) = 2 * ip G f f + 2 * ip G g g := by - rw [ip_add_left, ip_add_right, ip_add_right, ip_sub_left, ip_sub_right, + erw [ip_add_left, ip_add_right, ip_add_right, ip_sub_left, ip_sub_right, ip_sub_right, ip_comm G g f] ring have hb1 := abs_le.1 h1 diff --git a/Complexitylib/Classes/PH.lean b/Complexitylib/Classes/PH.lean index 2b5e3d6b..e7af7b6e 100644 --- a/Complexitylib/Classes/PH.lean +++ b/Complexitylib/Classes/PH.lean @@ -116,7 +116,7 @@ existential class is the bounded universal class over the complement class. -/ theorem complClass_polyExistsClass (C : Set Language) : complClass (polyExistsClass C) = polyForallClass (complClass C) := by ext L - simp only [mem_complClass, polyExistsClass, polyForallClass, Set.mem_setOf_eq] + simp only [mem_complClass, polyExistsClass, polyForallClass, Set.mem_ofPred_eq] constructor · rintro ⟨p, L', hL', hEq⟩ refine ⟨p, L'ᶜ, by simpa [mem_complClass, compl_compl] using hL', ?_⟩ @@ -129,7 +129,7 @@ class is the bounded existential class over the complement class. -/ theorem complClass_polyForallClass (C : Set Language) : complClass (polyForallClass C) = polyExistsClass (complClass C) := by ext L - simp only [mem_complClass, polyExistsClass, polyForallClass, Set.mem_setOf_eq] + simp only [mem_complClass, polyExistsClass, polyForallClass, Set.mem_ofPred_eq] constructor · rintro ⟨p, L', hL', hEq⟩ refine ⟨p, L'ᶜ, by simpa [mem_complClass, compl_compl] using hL', ?_⟩ diff --git a/Complexitylib/Classes/PH/SipserLautemann/Encode.lean b/Complexitylib/Classes/PH/SipserLautemann/Encode.lean index 52758c65..721354ee 100644 --- a/Complexitylib/Classes/PH/SipserLautemann/Encode.lean +++ b/Complexitylib/Classes/PH/SipserLautemann/Encode.lean @@ -83,7 +83,7 @@ def shiftsOfList (t m : ℕ) (w : List Bool) : Fin t → Fin m → Bool := rw [Nat.mul_comm, Nat.mul_add_mod, Nat.mod_eq_of_lt j.isLt] simp only [shiftsOfList, listOfShifts] rw [getD_listOfSeed _ _ hidx] - simp only [flattenShifts, dif_pos hm] + simp only [flattenShifts, dite_eq_left hm] congr 1 <;> [exact Fin.ext hdiv; exact Fin.ext hmod] end Lautemann diff --git a/Complexitylib/Classes/PH/SipserLautemann/Matrix.lean b/Complexitylib/Classes/PH/SipserLautemann/Matrix.lean index 1cfcefff..6ab02ed3 100644 --- a/Complexitylib/Classes/PH/SipserLautemann/Matrix.lean +++ b/Complexitylib/Classes/PH/SipserLautemann/Matrix.lean @@ -78,9 +78,9 @@ theorem matrixVerdictOn_eq_true_iff (tm : NTM k) (f : ℕ → ℕ) (b : Bool) (x matrixVerdictOn tm f b x w r = true ↔ matrixPred tm f b x w r := by rw [matrixVerdictOn, matrixPred] by_cases h : r.length = ampRuns f x.length * f x.length - · rw [if_pos h] + · rw [ite_eq_left h] simp [h] - · rw [if_neg h] + · rw [ite_eq_right h] simp [h] /-- The innermost predicate of the Lautemann characterization, as a language of diff --git a/Complexitylib/Classes/PH/SipserLautemann/Verdict.lean b/Complexitylib/Classes/PH/SipserLautemann/Verdict.lean index c6081c8f..662966ed 100644 --- a/Complexitylib/Classes/PH/SipserLautemann/Verdict.lean +++ b/Complexitylib/Classes/PH/SipserLautemann/Verdict.lean @@ -106,8 +106,8 @@ theorem acceptCountAux_length_eq (tm : NTM k) (u x τ s ρ : List Bool) (runs : rw [Cobham.acceptChoiceFn_eq_true_iff tm u x (Cobham.blockAtIdx τ.length s j) (by rw [hblen]; omega), pathAccepts_iff, hblen] by_cases h : Cobham.acceptChoiceFn tm u x (Cobham.blockAtIdx τ.length s j) = [true] - · rw [if_pos h, if_pos (hacc.mp h)] - · rw [if_neg h, if_neg (fun hmem => h (hacc.mpr hmem))] + · rw [ite_eq_left h, ite_eq_left (hacc.mp h)] + · rw [ite_eq_right h, ite_eq_right (fun hmem => h (hacc.mpr hmem))] /-- **The algebra's majority flag is the amplified majority verdict.** -/ theorem majorityFlag_eq_true_iff' (tm : NTM k) (u x τ s ρ : List Bool) (runs : ℕ) @@ -131,7 +131,7 @@ theorem getD_padTo (σ b : List Bool) (j : ℕ) (hj : j < σ.length) : · have h1 : (padTo σ b)[j]? = some false := by rw [padTo, List.getElem?_take_of_lt hj, List.getElem?_append_right hb, List.getElem?_replicate] - rw [if_pos (by omega)] + rw [ite_eq_left (by omega)] rw [List.getD, h1, List.getD, List.getElem?_eq_none hb] rfl @@ -290,7 +290,7 @@ private theorem matrixFn_aux (tm : NTM k) (pt : Polynomial ℕ) (b : Bool) (x w · have hflag : Cobham.lenEqFlag r (seedStr pt x) = [true] := by rw [Cobham.lenEqFlag_eq_true_iff, seedStr_length] exact hlen - rw [hflag, if_pos hlen, caseBit₀_cons, cond_true] + rw [hflag, ite_eq_left hlen, caseBit₀_cons, Bool.cond_true] have hiff : Cobham.anyShiftAux tm b (clockStr pt (Fintype.card tm.Q) x) x (Cobham.polyLen pt x) (runsStr pt x) (seedStr pt x) r w (shiftStr pt x) = [true] ↔ ∃ i : Fin (ampShifts pt.eval x.length), @@ -316,7 +316,7 @@ private theorem matrixFn_aux (tm : NTM k) (pt : Polynomial ℕ) (b : Bool) (x w · rw [Cobham.lenEqFlag_eq_true_iff, seedStr_length] at h exact absurd h hlen · exact h - rw [hflag, if_neg hlen, caseBit₀_cons, cond_false] + rw [hflag, ite_eq_right hlen, caseBit₀_cons, Bool.cond_false] /-- **The algebra function computes the matrix verdict.** -/ theorem matrixFn_eq (tm : NTM k) (pt : Polynomial ℕ) (b : Bool) (z : List Bool) : diff --git a/Complexitylib/Classes/PPoly.lean b/Complexitylib/Classes/PPoly.lean index 78ca2f3d..fe383e59 100644 --- a/Complexitylib/Classes/PPoly.lean +++ b/Complexitylib/Classes/PPoly.lean @@ -142,7 +142,7 @@ theorem mem_PPoly_iff {L : Language} : L ∈ PPoly ↔ ∃ (F : CircuitFamily Basis.andOr2) (k : ℕ), F.Decides L ∧ F.size =O ((· ^ k) : ℕ → ℕ) := by - simp only [PPoly, SIZE, SIZEWithBasis, Set.mem_iUnion, Set.mem_setOf_eq] + simp only [PPoly, SIZE, SIZEWithBasis, Set.mem_iUnion, Set.mem_ofPred_eq] constructor · rintro ⟨p, F, hL, hp⟩ exact ⟨F, p.natDegree, hL, Complexity.BigO.of_polynomial_bound p hp⟩ diff --git a/Complexitylib/Classes/PPoly/Advice/Reverse/Internal.lean b/Complexitylib/Classes/PPoly/Advice/Reverse/Internal.lean index f177becd..98dee79f 100644 --- a/Complexitylib/Classes/PPoly/Advice/Reverse/Internal.lean +++ b/Complexitylib/Classes/PPoly/Advice/Reverse/Internal.lean @@ -114,10 +114,7 @@ theorem adviceEvalTime_bigO_internal dsimp [e] omega rw [hexponent] at htime - simpa only [adviceEvalTime, pairedLength, - CircuitCode.Machine.evalFamilyTime, - CircuitCode.Machine.evalFamilyTMWithTime, - CircuitCode.Machine.evalFamilyCoreTime, Nat.add_zero] using htime + exact htime /-- Internal packaging of one polynomial-size deciding circuit family as a polynomial-time advised evaluator. -/ diff --git a/Complexitylib/Classes/PPoly/Oracle/Evaluation/Internal.lean b/Complexitylib/Classes/PPoly/Oracle/Evaluation/Internal.lean index 751aea98..dd6e4ac9 100644 --- a/Complexitylib/Classes/PPoly/Oracle/Evaluation/Internal.lean +++ b/Complexitylib/Classes/PPoly/Oracle/Evaluation/Internal.lean @@ -63,7 +63,7 @@ theorem size_compile_internal unfold compile rw [Circuit.size_compose] unfold queryCircuit queryWidth - rw [Circuit.size_pairInputSources, oracle.circuit_size_eq_family_size] + erw [Circuit.size_pairInputSources, oracle.circuit_size_eq_family_size] end EvaluationOracleCircuit diff --git a/Complexitylib/Classes/PPoly/Oracle/Evaluation/OutputMatch/Internal.lean b/Complexitylib/Classes/PPoly/Oracle/Evaluation/OutputMatch/Internal.lean index d2fe2032..388a4ff9 100644 --- a/Complexitylib/Classes/PPoly/Oracle/Evaluation/OutputMatch/Internal.lean +++ b/Complexitylib/Classes/PPoly/Oracle/Evaluation/OutputMatch/Internal.lean @@ -199,7 +199,7 @@ theorem eval_compile_gateStream_internal have hnotEmpty : input.toList.isEmpty ≠ true := by simpa using hinput unfold evalFamilyCode - rw [if_neg hnotEmpty, BitString.length_toList] + rw [ite_eq_right hnotEmpty, BitString.length_toList] change decide (evalCode inputWidth diff --git a/Complexitylib/Classes/PPoly/Uniform/Preprocessing/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Preprocessing/Internal.lean index 61f67333..07e052f6 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Preprocessing/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Preprocessing/Internal.lean @@ -26,7 +26,7 @@ theorem generatorEvalInput_mem_FP_internal {gen : List Bool → List Bool} have hunary : (fun x : List Bool => unaryList x.length) ∈ FP := by simpa only [unaryList] using unaryLength_mem_FP have hcode : (fun x : List Bool => gen (unaryList x.length)) ∈ FP := by - simpa only [Function.comp_apply] using mem_FP_comp hunary hgen - simpa only [generatorEvalInput, unaryList] using mem_FP_pairWithInput hcode + exact mem_FP_comp hunary hgen + exact mem_FP_pairWithInput hcode end Complexity diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Finalization/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Finalization/Internal.lean index 0d5b29c4..61f8513d 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Finalization/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Finalization/Internal.lean @@ -636,8 +636,8 @@ private theorem prepareAcceptanceReferences_spaceBoundByWidth width inputLength := by have htotal := (hbounds inputLength).cellPrefixMul_le omega - simpa [Work.reference₀, Work.reference₁, Work.configBase, - Work.temporary₀, Work.temporary₁] using hprefix + simp [Work.reference₀, Work.reference₁, Work.configBase, Work.temporary₀, Work.temporary₁] + exact hprefix by_cases hreference₀ : index = Work.reference₀ · subst index simpa [Work.reference₀, Work.reference₁, Work.configBase, @@ -742,25 +742,24 @@ private theorem emitAcceptance_spaceBoundByWidth constructor · apply BinaryRoutine.SpaceBoundByWidthAt.emitRawGateStep_internal · intro inputLength - simpa [BinaryRoutine.binaryCopy] using - hpreparedValues inputLength Work.available + simp [BinaryRoutine.binaryCopy] + exact hpreparedValues inputLength Work.available · intro inputLength - simpa [BinaryRoutine.binaryCopy] using - hpreparedValues inputLength Work.reference₀ + simp [BinaryRoutine.binaryCopy] + exact hpreparedValues inputLength Work.reference₀ · intro inputLength - simpa [BinaryRoutine.binaryCopy] using - hpreparedValues inputLength Work.reference₁ + simp [BinaryRoutine.binaryCopy] + exact hpreparedValues inputLength Work.reference₁ constructor · apply BinaryRoutine.SpaceBoundByWidthAt.clear_internal intro inputLength - simpa [BinaryRoutine.binaryCopy, BinaryRoutine.emitRawGateStep] using - hpreparedValues inputLength Work.reference₀ + simp [BinaryRoutine.binaryCopy, BinaryRoutine.emitRawGateStep] + exact hpreparedValues inputLength Work.reference₀ constructor · apply BinaryRoutine.SpaceBoundByWidthAt.clear_internal intro inputLength - simpa [BinaryRoutine.binaryCopy, BinaryRoutine.emitRawGateStep, - BinaryRoutine.clear] using - hpreparedValues inputLength Work.reference₁ + simp [BinaryRoutine.binaryCopy, BinaryRoutine.emitRawGateStep, BinaryRoutine.clear] + exact hpreparedValues inputLength Work.reference₁ · trivial theorem prepareAcceptanceReferences_requires_internal (tm : TM k) @@ -802,6 +801,7 @@ private theorem prepareAcceptanceCellPrefix_emitted (tm : TM k) BinaryRoutine.set, BinaryRoutine.clear, BinaryRoutine.addConst, BinaryRoutine.add, BinaryRoutine.mulAdd] +set_option maxHeartbeats 1000000 in private theorem prepareAcceptanceCellOffset_emitted (k : ℕ) (values : BinaryValues WorkCount) : (prepareAcceptanceCellOffset k).emitted values = [] := by diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Initialization/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Initialization/Internal.lean index ce77df59..2cf87bca 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Initialization/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Initialization/Internal.lean @@ -404,10 +404,12 @@ theorem emitInitialStates_effect_internal (tm : TM k) (emitInitialStates tm).effect values = Function.update values Work.available (values Work.available + Fintype.card tm.Q) := by - simpa [emitInitialStates] using - seqList_emitConstantGate_effect - (List.ofFn fun index : Fin (Fintype.card tm.Q) => - decide (tm.qstart = (Fintype.equivFin tm.Q).symm index)) values + have h := seqList_emitConstantGate_effect + (List.ofFn fun index : Fin (Fintype.card tm.Q) => + decide (tm.qstart = (Fintype.equivFin tm.Q).symm index)) values + simp only [emitInitialStates, List.map_ofFn, Function.comp_def, + List.length_ofFn] at h ⊢ + exact h theorem emitInitialStates_emitted_internal (tm : TM k) (values : BinaryValues WorkCount) @@ -1320,8 +1322,8 @@ private theorem emitBlankCell_space_le (hreference : values Work.reference₀ ≤ width) : emitBlankCell.spaceBound initialSpace values ≤ initialSpace + 32 * width.size + 32 := by - simpa [emitBlankCell, emitStartCell, emitConstantGate] using - emitStartCell_space_le initialSpace width values havailable hreference + simp [emitBlankCell, emitConstantGate] + exact emitStartCell_space_le initialSpace width values havailable hreference private theorem emitInputDataCell_space_le (initialSpace width : ℕ) (values : BinaryValues WorkCount) @@ -1628,11 +1630,12 @@ private theorem emitInitialStates_spaceBoundByWidthAt width inputLength := by intro inputLength simpa using havailable inputLength - simpa [emitInitialStates] using - seqList_emitConstantGate_spaceBoundByWidthAt - (List.ofFn fun index : Fin (Fintype.card tm.Q) => - decide (tm.qstart = (Fintype.equivFin tm.Q).symm index)) - havailable' hreference + have h := seqList_emitConstantGate_spaceBoundByWidthAt + (initialSpace := initialSpace) + (List.ofFn fun index : Fin (Fintype.card tm.Q) => + decide (tm.qstart = (Fintype.equivFin tm.Q).symm index)) havailable' hreference + simp only [emitInitialStates, List.map_ofFn, Function.comp_def] at h ⊢ + exact h private theorem setHorizonLimit_spaceBoundByWidthAt {initialSpace : ℕ → ℕ} {values : ℕ → BinaryValues WorkCount} diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Offset/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Offset/Internal.lean index c7a9657d..462f1ea4 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Offset/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Offset/Internal.lean @@ -162,8 +162,8 @@ theorem decrementReferenceBy_spaceBoundByWidth_internal omega simp only [BinaryRoutine.binaryPred, Function.update_apply, TM.binaryPredSpace] - rw [if_neg hdistinct.reference_ne_counter] - simp only [if_true] + rw [ite_eq_right hdistinct.reference_ne_counter] + simp only [ite_true] rw [hpred] omega · intro count hcount @@ -195,7 +195,8 @@ theorem decrementReferenceBy_spaceBoundByWidth_internal exact hoffset inputLength have hroutine := BinaryRoutine.SpaceBoundByWidthAt.seq hloop (BinaryRoutine.SpaceBoundByWidthAt.clear counter hcounterAfter) - simpa [decrementReferenceBy, loop] using hroutine + simp [decrementReferenceBy] + exact hroutine theorem prepareDynamicRecentReference_spaceBoundByWidth_internal (reference offset counter : Fin WorkCount) @@ -249,8 +250,8 @@ theorem prepareDynamicRecentReference_spaceBoundByWidth_internal BinaryRoutine.SpaceBoundByWidthAt.identity have hroutine := BinaryRoutine.SpaceBoundByWidthAt.seq hcopy (BinaryRoutine.SpaceBoundByWidthAt.seq hdecrement hid) - simpa [prepareDynamicRecentReference, BinaryRoutine.seqList, copy, copied] - using hroutine + simp [prepareDynamicRecentReference, BinaryRoutine.seqList] + exact hroutine theorem decrementReferenceBy_requires_internal (reference offset counter : Fin WorkCount) @@ -344,8 +345,8 @@ theorem prepareDynamicRecentReference_effect_internal rw [decrementReferenceBy_effect_internal reference offset counter (Function.update values reference (values Work.available)) hdistinct.toDecrementReferenceDistinct] - · simp only [Function.update_apply, if_pos] - simp only [if_neg (Ne.symm hdistinct.reference_ne_offset)] + · simp only [Function.update_apply, ite_eq_left] + simp only [ite_eq_right (Ne.symm hdistinct.reference_ne_offset)] rw [Function.update_idem] · simp [Ne.symm hdistinct.reference_ne_counter, hcounter] @@ -431,13 +432,13 @@ theorem emitDynamicRecentGate_spaceBoundByWidth_internal intro inputLength simp only [values₂, prepare₁, prepareRecentReference_effect, Function.update_apply] - rw [if_neg hdistinct.reference₀_ne_reference₁] + rw [ite_eq_right hdistinct.reference₀_ne_reference₁] simp only [values₁, prepare₀] rw [prepareDynamicRecentReference_effect_internal Work.reference₀ offset counter (values inputLength) hdistinct.toDynamicRecentDistinct (hcounter inputLength)] - simp only [Function.update_apply, if_true] - rw [if_neg hdistinct.reference_ne_counter] + simp only [Function.update_apply, ite_true] + rw [ite_eq_right hdistinct.reference_ne_counter] exact (Nat.sub_le _ _).trans (havailable inputLength) have hvalues₂Reference₁ : ∀ inputLength, values₂ inputLength Work.reference₁ ≤ width inputLength := by @@ -464,7 +465,7 @@ theorem emitDynamicRecentGate_spaceBoundByWidth_internal values₄ inputLength Work.reference₁ ≤ width inputLength := by intro inputLength simp only [values₄, BinaryRoutine.clear, Function.update_apply] - rw [if_neg (Ne.symm hdistinct.reference₀_ne_reference₁)] + rw [ite_eq_right (Ne.symm hdistinct.reference₀_ne_reference₁)] simpa [values₃, emit, BinaryRoutine.emitRawGateStep, Ne.symm hdistinct.available_ne_reference₁] using hvalues₂Reference₁ inputLength @@ -482,8 +483,8 @@ theorem emitDynamicRecentGate_spaceBoundByWidth_internal (BinaryRoutine.SpaceBoundByWidthAt.seq hemit (BinaryRoutine.SpaceBoundByWidthAt.seq hclear₀ (BinaryRoutine.SpaceBoundByWidthAt.seq hclear₁ hid)))) - simpa [emitDynamicRecentGate, BinaryRoutine.seqList, prepare₀, prepare₁, - emit, values₁, values₂, values₃, values₄] using hroutine + simp [emitDynamicRecentGate, BinaryRoutine.seqList] + exact hroutine theorem prepareDynamicRecentReference_emitted_internal (reference offset counter : Fin WorkCount) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/PolynomialOffset/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/PolynomialOffset/Internal.lean index 7566f3d9..a2ef5747 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/PolynomialOffset/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/PolynomialOffset/Internal.lean @@ -264,7 +264,7 @@ theorem emitPolynomialRecentGate_effect_internal · funext i simp only [Function.update_apply] split_ifs <;> simp_all - · simpa using hloop + · exact hloop theorem emitPolynomialRecentGate_emitted_internal (polynomial : Polynomial ℕ) (extra : ℕ) (op : AndOrOp) @@ -287,7 +287,7 @@ theorem emitPolynomialRecentGate_emitted_internal rw [emitDynamicRecentGate_emitted op negated₀ negated₁ Work.temporary₃ Work.loop₃ fixedOffset₁ _ polynomialOffsetDistinct] · simp [Work.temporary₃, Work.available] - · simpa using hloop + · exact hloop end DirectGenerator diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Primitive/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Primitive/Internal.lean index 367b953d..419ff209 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Primitive/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Primitive/Internal.lean @@ -1117,17 +1117,15 @@ private theorem finishCellReference_spaceBoundByWidth constructor · apply BinaryRoutine.SpaceBoundByWidthAt.mulAdd · intro inputLength - simpa [prepareCellPositionOffset_effect, - prepareCellReferenceBase_effect, BinaryRoutine.set, Work.reference₀, - Work.temporary₀, Work.temporary₁, Work.temporary₂, - Work.tapeIndex, Work.position] using - (hbounds inputLength).offset_le + simp [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, + Work.reference₀, Work.temporary₀, Work.temporary₁, Work.temporary₂, Work.tapeIndex, + Work.position] + exact (hbounds inputLength).offset_le · intro inputLength - simpa [prepareCellPositionOffset_effect, - prepareCellReferenceBase_effect, BinaryRoutine.set, Work.reference₀, - Work.temporary₀, Work.temporary₁, Work.temporary₂, - Work.tapeIndex, Work.position] using - (hbounds inputLength).four_le + simp [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, + Work.reference₀, Work.temporary₀, Work.temporary₁, Work.temporary₂, Work.tapeIndex, + Work.position] + exact (hbounds inputLength).four_le · intro inputLength simpa [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, @@ -1139,12 +1137,10 @@ private theorem finishCellReference_spaceBoundByWidth constructor · apply BinaryRoutine.SpaceBoundByWidthAt.add · intro inputLength - simpa [prepareCellPositionOffset_effect, - prepareCellReferenceBase_effect, BinaryRoutine.set, - BinaryRoutine.mulAdd, Work.reference₀, Work.temporary₀, - Work.temporary₁, Work.temporary₂, Work.tapeIndex, - Work.position, Work.symbolIndex] using - hvalues inputLength Work.symbolIndex + simp [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, + BinaryRoutine.mulAdd, Work.reference₀, Work.temporary₀, Work.temporary₁, Work.temporary₂, + Work.tapeIndex, Work.position, Work.symbolIndex] + exact hvalues inputLength Work.symbolIndex · intro inputLength simpa [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, @@ -1157,30 +1153,26 @@ private theorem finishCellReference_spaceBoundByWidth constructor · apply BinaryRoutine.SpaceBoundByWidthAt.clear intro inputLength - simpa [prepareCellPositionOffset_effect, - prepareCellReferenceBase_effect, BinaryRoutine.set, - BinaryRoutine.mulAdd, BinaryRoutine.add, Work.reference₀, - Work.temporary₀, Work.temporary₁, Work.temporary₂, - Work.tapeIndex, Work.position, Work.symbolIndex, Nat.add_assoc] using - (hbounds inputLength).horizonTwo_le + simp [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, + BinaryRoutine.mulAdd, BinaryRoutine.add, Work.reference₀, Work.temporary₀, Work.temporary₁, + Work.temporary₂, Work.tapeIndex, Work.position, Work.symbolIndex, Nat.add_assoc] + exact (hbounds inputLength).horizonTwo_le constructor · apply BinaryRoutine.SpaceBoundByWidthAt.clear intro inputLength - simpa [prepareCellPositionOffset_effect, - prepareCellReferenceBase_effect, BinaryRoutine.set, - BinaryRoutine.mulAdd, BinaryRoutine.add, BinaryRoutine.clear, - Work.reference₀, Work.temporary₀, Work.temporary₁, - Work.temporary₂, Work.tapeIndex, Work.position, - Work.symbolIndex] using (hbounds inputLength).four_le + simp [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, + BinaryRoutine.mulAdd, BinaryRoutine.add, BinaryRoutine.clear, Work.reference₀, + Work.temporary₀, Work.temporary₁, Work.temporary₂, Work.tapeIndex, Work.position, + Work.symbolIndex] + exact (hbounds inputLength).four_le constructor · apply BinaryRoutine.SpaceBoundByWidthAt.clear intro inputLength - simpa [prepareCellPositionOffset_effect, - prepareCellReferenceBase_effect, BinaryRoutine.set, - BinaryRoutine.mulAdd, BinaryRoutine.add, BinaryRoutine.clear, - Work.reference₀, Work.temporary₀, Work.temporary₁, - Work.temporary₂, Work.tapeIndex, Work.position, - Work.symbolIndex] using (hbounds inputLength).offset_le + simp [prepareCellPositionOffset_effect, prepareCellReferenceBase_effect, BinaryRoutine.set, + BinaryRoutine.mulAdd, BinaryRoutine.add, BinaryRoutine.clear, Work.reference₀, + Work.temporary₀, Work.temporary₁, Work.temporary₂, Work.tapeIndex, Work.position, + Work.symbolIndex] + exact (hbounds inputLength).offset_le · trivial theorem prepareCellReference_requires_internal (stateCount tapeCount : ℕ) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Program/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Program/Internal.lean index 8a32481e..cc8d9540 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Program/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Program/Internal.lean @@ -235,7 +235,7 @@ theorem program_requires_inputLengthValues_internal BinaryRoutine.emitBits, BinaryRoutine.inputLengthValues, Work.inputLength] · simp only [program, BinaryRoutine.branchZero] - rw [if_neg (by + rw [ite_eq_right (by simpa [BinaryRoutine.inputLengthValues, Work.inputLength] using hzero)] change (positivePreamble tm q).requires diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Tableau/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Tableau/Internal.lean index 216b0a82..bf787051 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Tableau/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Tableau/Internal.lean @@ -1488,7 +1488,7 @@ theorem positiveTableauBody_requires_internal (tm : TM k) afterInit Work.horizon * directStepSize tm.toNTM (afterInit Work.horizon) := by simpa only [afterSteps] using hstepsRaw - haveI : NeZero n := ⟨Nat.ne_of_gt hn⟩ + have : NeZero n := ⟨Nat.ne_of_gt hn⟩ have hrawBound := tm.directUnrollingRawCircuit_length_le_gateBound f n rw [directUnrollingRawCircuit_length_eq_original] at hrawBound have hfinalBound : afterSteps Work.available + 1 ≤ diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Case/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Case/Internal.lean index c7504940..fb765c71 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Case/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Case/Internal.lean @@ -195,30 +195,18 @@ private theorem ReadFormulaClean.caseReadStartValues temporary₀ := ?_ temporary₁ := ?_ temporary₂ := ?_ } - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.position - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.loop₀ - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.limit₀ - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.reference₀ - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.reference₁ - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.emitCounter - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.copyCounter - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.multiplyCounter - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.addCounter - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.temporary₀ - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.temporary₁ - · simpa [caseReadStartValues, Work.tapeIndex, Work.symbolIndex] using - hclean.temporary₂ + · exact hclean.position + · exact hclean.loop₀ + · exact hclean.limit₀ + · exact hclean.reference₀ + · exact hclean.reference₁ + · exact hclean.emitCounter + · exact hclean.copyCounter + · exact hclean.multiplyCounter + · exact hclean.addCounter + · exact hclean.temporary₀ + · exact hclean.temporary₁ + · exact hclean.temporary₂ private theorem ReadFormulaClean.updateAvailable (values : BinaryValues WorkCount) (amount : ℕ) @@ -411,8 +399,10 @@ theorem prepareCaseReadSize_requires_internal Work.temporary₂ 0) Work.temporary₂ 4) 13 = 0 refine ⟨⟨by decide, by decide, by decide, by decide, by decide, by decide, by decide, by decide, by decide, by decide⟩, ?_, ?_⟩ - · simpa [Work.temporary₂, Work.multiplyCounter] using hmultiply - · simpa [Work.temporary₂, Work.addCounter] using hadd + · simp [Work.temporary₂] + exact hmultiply + · simp [Work.temporary₂] + exact hadd theorem emitCaseConnector_effect_internal (values : BinaryValues WorkCount) : @@ -1155,22 +1145,22 @@ theorem emitCaseFormula_requires_internal rw [emitCaseMembers_effect_internal stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] - simpa [Work.tapeIndex, Work.symbolIndex, Work.available, - Work.emitCounter] using hclean.emitCounter + simp [Work.available, Work.emitCounter] + exact hclean.emitCounter refine ⟨?_, ?_⟩ · apply prepareCaseReadSize_requires_internal · rw [emitConstantGate_effect_internal, emitCaseMembers_effect_internal stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] - simpa [Work.tapeIndex, Work.symbolIndex, Work.available, - Work.multiplyCounter] using hclean.multiplyCounter + simp [Work.available, Work.multiplyCounter] + exact hclean.multiplyCounter · rw [emitConstantGate_effect_internal, emitCaseMembers_effect_internal stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] - simpa [Work.tapeIndex, Work.symbolIndex, Work.available, - Work.addCounter] using hclean.addCounter + simp [Work.available, Work.addCounter] + exact hclean.addCounter refine ⟨?_, ?_⟩ · apply (prepareRecentReference_requires Work.reference₀ 2 _ (by decide) (by decide) (by decide)).2 @@ -1180,9 +1170,8 @@ theorem emitCaseFormula_requires_internal emitCaseMembers_effect_internal stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] - simpa [Work.temporary₂, Work.temporary₃, Work.tapeIndex, - Work.symbolIndex, Work.available, Work.copyCounter] using - hclean.copyCounter + simp [Work.temporary₂, Work.temporary₃, Work.available, Work.copyCounter] + exact hclean.copyCounter · rw [prepareCaseReadSize_effect_internal, emitConstantGate_effect_internal, emitCaseMembers_effect_internal stateCount workCount stateIndex @@ -1199,9 +1188,8 @@ theorem emitCaseFormula_requires_internal emitCaseMembers_effect_internal stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] - simpa [Work.reference₀, Work.temporary₂, Work.temporary₃, - Work.tapeIndex, Work.symbolIndex, Work.available, - Work.copyCounter] using hclean.copyCounter + simp [Work.reference₀, Work.temporary₂, Work.temporary₃, Work.available, Work.copyCounter] + exact hclean.copyCounter · rw [prepareRecentReference_effect, prepareCaseReadSize_effect_internal, emitConstantGate_effect_internal, @@ -1218,9 +1206,8 @@ theorem emitCaseFormula_requires_internal emitCaseMembers_effect_internal stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] - simpa [Work.reference₀, Work.temporary₂, Work.temporary₃, - Work.tapeIndex, Work.symbolIndex, Work.available, - Work.emitCounter] using hclean.emitCounter + simp [Work.reference₀, Work.temporary₂, Work.temporary₃, Work.available, Work.emitCounter] + exact hclean.emitCounter rw [caseFormulaConnectorStart_effect stateCount workCount stateIndex inputSymbolIndex outputSymbolIndex choiceValue workSymbolIndexAt values hclean] @@ -2235,11 +2222,11 @@ private theorem emitCaseMembers_spaceBoundByWidthAt intro inputLength rw [hafterInputEffect inputLength] simp only [Function.update_apply] - rw [if_neg (by decide : Work.horizon ≠ Work.available)] + rw [ite_eq_right (by decide : Work.horizon ≠ Work.available)] unfold caseReadStartValues simp only [Function.update_apply] - rw [if_neg (by decide : Work.horizon ≠ Work.symbolIndex), - if_neg (by decide : Work.horizon ≠ Work.tapeIndex)] + rw [ite_eq_right (by decide : Work.horizon ≠ Work.symbolIndex), + ite_eq_right (by decide : Work.horizon ≠ Work.tapeIndex)] exact hafterStateHorizon inputLength have hafterInputConfig : ∀ inputLength, afterInput inputLength Work.configBase = @@ -2247,11 +2234,11 @@ private theorem emitCaseMembers_spaceBoundByWidthAt intro inputLength rw [hafterInputEffect inputLength] simp only [Function.update_apply] - rw [if_neg (by decide : Work.configBase ≠ Work.available)] + rw [ite_eq_right (by decide : Work.configBase ≠ Work.available)] unfold caseReadStartValues simp only [Function.update_apply] - rw [if_neg (by decide : Work.configBase ≠ Work.symbolIndex), - if_neg (by decide : Work.configBase ≠ Work.tapeIndex)] + rw [ite_eq_right (by decide : Work.configBase ≠ Work.symbolIndex), + ite_eq_right (by decide : Work.configBase ≠ Work.tapeIndex)] exact hafterStateConfig inputLength have hworkFrontier : ∀ inputLength, afterInput inputLength Work.available + @@ -2643,7 +2630,7 @@ private theorem emitPreviousCaseReadConnector_spaceBoundByWidthAt Work.loop₃ (values inputLength) ⟨by decide, by decide, by decide⟩ (hloop inputLength)] simp only [Function.update_apply] - rw [if_neg (by decide : Work.reference₀ ≠ Work.loop₃), if_true] + rw [ite_eq_right (by decide : Work.reference₀ ≠ Work.loop₃), ite_true] exact (Nat.sub_le _ _).trans (hreference₀ inputLength) · intro inputLength rw [show decremented inputLength = @@ -3248,7 +3235,7 @@ theorem emitCaseFormula_spaceBoundByWidth_internal intro inputLength rw [hvalues₆Effect inputLength] simp only [Function.update_apply] - rw [if_neg (by decide : Work.available ≠ Work.reference₁), if_true] + rw [ite_eq_right (by decide : Work.available ≠ Work.reference₁), ite_true] rw [hvalues₅Available inputLength] have hvalues₆Values : ∀ inputLength index, values₆ inputLength index ≤ width inputLength := by @@ -3272,8 +3259,8 @@ theorem emitCaseFormula_spaceBoundByWidth_internal intro inputLength rw [hvalues₆Effect inputLength] simp only [Function.update_apply] - rw [if_neg (by decide : Work.reference₀ ≠ Work.reference₁), - if_neg (by decide : Work.reference₀ ≠ Work.available), if_true] + rw [ite_eq_right (by decide : Work.reference₀ ≠ Work.reference₁), + ite_eq_right (by decide : Work.reference₀ ≠ Work.available), ite_true] rw [hvalues₅Reference₀ inputLength, hvalues₅Offset inputLength, caseFormulaMembersSize, Nat.mul_comm (caseReadSize (values inputLength Work.horizon)) (workCount + 2)] diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Effect/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Effect/Internal.lean index 50755dba..de976d5f 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Effect/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Effect/Internal.lean @@ -61,7 +61,7 @@ private theorem CaseFormulaClean.updateAvailable symbolIndex := ?_ } all_goals simp only [Function.update_apply] - rw [if_neg (by decide)] + rw [ite_eq_right (by decide)] · exact hclean.position · exact hclean.loop₀ · exact hclean.limit₀ @@ -197,7 +197,7 @@ theorem emitEffectCaseAt_requires_internal (tm : NTM k) (effectCaseChoiceAt tm caseIndex)) := by rw [emitEffectCaseAt] by_cases hselected : effectCaseSelectedAt tm selects caseIndex - · rw [if_pos hselected] + · rw [ite_eq_left hselected] rw [emitCaseFormula_effect_internal (Fintype.card tm.Q) k (effectCaseStateIndexAt tm caseIndex) (effectCaseInputSymbolIndexAt tm caseIndex) @@ -205,7 +205,7 @@ theorem emitEffectCaseAt_requires_internal (tm : NTM k) (effectCaseChoiceAt tm caseIndex) (effectCaseWorkSymbolIndexAt tm caseIndex) values hclean] simp [effectFormulaCaseSize, hselected] - · rw [if_neg hselected, emitConstantGate_effect_internal] + · rw [ite_eq_right hselected, emitConstantGate_effect_internal] simp [effectFormulaCaseSize, hselected] theorem emitEffectCaseAt_emitted_internal (tm : NTM k) @@ -225,7 +225,7 @@ theorem emitEffectCaseAt_emitted_internal (tm : NTM k) caseIndex).flatMap CircuitCode.RawGate.encode := by rw [emitEffectCaseAt] by_cases hselected : effectCaseSelectedAt tm selects caseIndex - · rw [if_pos hselected] + · rw [ite_eq_left hselected] rw [emitCaseFormula_emitted_internal (Fintype.card tm.Q) k (effectCaseStateIndexAt tm caseIndex) (effectCaseInputSymbolIndexAt tm caseIndex) @@ -233,7 +233,7 @@ theorem emitEffectCaseAt_emitted_internal (tm : NTM k) (effectCaseChoiceAt tm caseIndex) (effectCaseWorkSymbolIndexAt tm caseIndex) values hclean] simp [effectFormulaCaseBlock, hselected, havailable] - · rw [if_neg hselected, + · rw [ite_eq_right hselected, emitConstantGate_emitted_internal false values hclean.reference₀] simp [effectFormulaCaseBlock, hselected, directInitConstant] @@ -324,7 +324,7 @@ private theorem emitEffectMembersFrom_effect dsimp [current] rw [hcurrent] simp only [Function.update_apply, Work.available] - rw [if_pos True.intro] + rw [ite_eq_left True.intro] change values Work.available + _ = _ rw [havailable, hhorizon, ← hsizeAt] simp [prefixSize] @@ -422,7 +422,7 @@ private theorem emitEffectMembersFrom_emitted dsimp [current] rw [hcurrent] simp only [Function.update_apply, Work.available] - rw [if_pos True.intro] + rw [ite_eq_left True.intro] change values Work.available + _ = _ rw [havailable, hhorizon, ← hsizeAt] simp [prefixSize] @@ -816,7 +816,7 @@ private theorem emitPreviousEffectConnectorsCount_requires dsimp [current] rw [hcurrent] simp only [Function.update_apply, Work.reference₀, Work.available] - rw [if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_left True.intro] change values Work.reference₀ - _ = _ rw [hreference] change (base + prefixSize sizeAt (count + 2) - 1) - _ = _ @@ -893,7 +893,7 @@ private theorem emitPreviousEffectConnectorsCount_effect dsimp [current] rw [hcurrent] simp only [Function.update_apply, Work.reference₀, Work.available] - rw [if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_left True.intro] change values Work.reference₀ - _ = _ rw [hreference] change (base + prefixSize sizeAt (count + 2) - 1) - _ = _ @@ -969,7 +969,7 @@ private theorem emitPreviousEffectConnectorsCount_emitted dsimp [current] rw [hcurrent] simp only [Function.update_apply, Work.reference₀, Work.available] - rw [if_pos True.intro] + rw [ite_eq_left True.intro] change values Work.available + 1 = _ rw [havailable] dsimp [sizeAt] @@ -979,7 +979,7 @@ private theorem emitPreviousEffectConnectorsCount_emitted dsimp [current] rw [hcurrent] simp only [Function.update_apply, Work.reference₀, Work.available] - rw [if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_left True.intro] change values Work.reference₀ - _ = _ rw [hreference, hhorizon] change (base + prefixSize sizeAt (count + 2) - 1) - _ = _ @@ -1128,7 +1128,7 @@ theorem emitEffectConnectors_requires_internal rw [emitReadConnector_effect_internal, hprepared] simp only [Function.update_apply, Work.available, Work.reference₀, Work.reference₁] - rw [if_neg (by decide), if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_right (by decide), ite_eq_left True.intro] change values Work.available - 2 = _ rw [havailable] dsimp [sizeAt] @@ -1198,7 +1198,7 @@ theorem emitEffectConnectors_effect_internal rw [emitReadConnector_effect_internal, hprepared] simp only [Function.update_apply, Work.available, Work.reference₀, Work.reference₁] - rw [if_neg (by decide), if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_right (by decide), ite_eq_left True.intro] change values Work.available - 2 = _ rw [havailable] dsimp [sizeAt] @@ -1277,7 +1277,7 @@ theorem emitEffectConnectors_emitted_internal dsimp [current] rw [emitReadConnector_effect_internal, hprepared] simp only [Function.update_apply, Work.available] - rw [if_pos True.intro] + rw [ite_eq_left True.intro] change values Work.available + 1 = _ rw [havailable] have hcurrentReference : current Work.reference₀ = @@ -1286,7 +1286,7 @@ theorem emitEffectConnectors_emitted_internal rw [emitReadConnector_effect_internal, hprepared] simp only [Function.update_apply, Work.available, Work.reference₀, Work.reference₁] - rw [if_neg (by decide), if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_right (by decide), ite_eq_left True.intro] change values Work.available - 2 = _ rw [havailable] dsimp [sizeAt] @@ -1311,7 +1311,7 @@ theorem emitEffectConnectors_emitted_internal base + prefixSize sizeAt (transitionCases tm).length - 1 := by rw [hprepared] simp only [Function.update_apply, Work.reference₀] - rw [if_pos True.intro] + rw [ite_eq_left True.intro] rw [havailable] dsimp [sizeAt] omega @@ -1319,7 +1319,7 @@ theorem emitEffectConnectors_emitted_internal base + prefixSize sizeAt (transitionCases tm).length := by rw [hprepared] simp only [Function.update_apply, Work.reference₀, Work.available] - rw [if_neg (by decide)] + rw [ite_eq_right (by decide)] change values Work.available - 1 = _ rw [havailable] dsimp [sizeAt] @@ -1567,19 +1567,19 @@ private theorem EffectFormulaWidthCap.frontier private theorem effectCaseStateIndexAt_lt (tm : NTM k) (caseIndex : ℕ) (hcase : caseIndex < (transitionCases tm).length) : effectCaseStateIndexAt tm caseIndex < Fintype.card tm.Q := by - rw [effectCaseStateIndexAt, dif_pos hcase] + rw [effectCaseStateIndexAt, dite_eq_left hcase] exact (Fintype.equivFin tm.Q _).isLt private theorem effectCaseInputSymbolIndexAt_lt (tm : NTM k) (caseIndex : ℕ) (hcase : caseIndex < (transitionCases tm).length) : effectCaseInputSymbolIndexAt tm caseIndex < 4 := by - rw [effectCaseInputSymbolIndexAt, dif_pos hcase] + rw [effectCaseInputSymbolIndexAt, dite_eq_left hcase] exact (symbolIndex _).isLt private theorem effectCaseOutputSymbolIndexAt_lt (tm : NTM k) (caseIndex : ℕ) (hcase : caseIndex < (transitionCases tm).length) : effectCaseOutputSymbolIndexAt tm caseIndex < 4 := by - rw [effectCaseOutputSymbolIndexAt, dif_pos hcase] + rw [effectCaseOutputSymbolIndexAt, dite_eq_left hcase] exact (symbolIndex _).isLt private theorem effectCaseWorkSymbolIndexAt_lt (tm : NTM k) @@ -1587,7 +1587,7 @@ private theorem effectCaseWorkSymbolIndexAt_lt (tm : NTM k) (hcase : caseIndex < (transitionCases tm).length) (hwork : workIndex < k) : effectCaseWorkSymbolIndexAt tm caseIndex workIndex < 4 := by - rw [effectCaseWorkSymbolIndexAt, dif_pos hcase, dif_pos hwork] + rw [effectCaseWorkSymbolIndexAt, dite_eq_left hcase, dite_eq_left hwork] exact (symbolIndex _).isLt private theorem prefixSize_mono_effect @@ -1668,7 +1668,7 @@ private theorem emitEffectCaseAt_spaceBoundByWidthAt initialSpace values width := by rw [emitEffectCaseAt] by_cases hselected : effectCaseSelectedAt tm selects caseIndex - · rw [if_pos hselected] + · rw [ite_eq_left hselected] apply emitCaseFormula_spaceBoundByWidth · exact hclean · exact hvalues @@ -1681,7 +1681,7 @@ private theorem emitEffectCaseAt_spaceBoundByWidthAt have hbound := hcap inputLength tapeIndex symbolIndex position htape hsymbol hposition simpa [effectFormulaCaseSize, hselected] using hbound - · rw [if_neg hselected] + · rw [ite_eq_right hselected] exact emitConstantGate_spaceBoundByWidth false (fun inputLength => hvalues inputLength Work.available) (fun inputLength => hvalues inputLength Work.reference₀) @@ -2113,8 +2113,8 @@ private theorem emitPreviousEffectConnectorsCount_spaceBoundByWidthAt (initialSpace := initialSpace) (values := values) (width := width)) · intro inputLength index - simpa [emitPreviousEffectConnectorsCount, BinaryRoutine.identity] - using hvalues inputLength index + simp [emitPreviousEffectConnectorsCount, BinaryRoutine.identity] + exact hvalues inputLength index | succ count ih => let selected := effectCaseSelectedAt tm selects (count + 1) let choiceValue := effectCaseChoiceAt tm (count + 1) @@ -2241,7 +2241,7 @@ private theorem emitPreviousEffectConnectorsCount_spaceBoundByWidthAt prefixSize_mono_effect sizeAt (by omega) rw [hcurrentEffect inputLength] simp only [Function.update_apply, Work.reference₀, Work.available] - rw [if_neg (by decide), if_pos True.intro] + rw [ite_eq_right (by decide), ite_eq_left True.intro] change values inputLength Work.reference₀ - _ = _ rw [hreference inputLength, hhorizon inputLength] change (base inputLength + prefixSize sizeAt (count + 2) - 1) - @@ -2321,7 +2321,8 @@ private theorem emitEffectConnectors_spaceBoundByWidthAt · constructor · exact BinaryRoutine.SpaceBoundByWidthAt.identity · intro inputLength index - simpa [BinaryRoutine.identity] using hvalues inputLength index + simp [BinaryRoutine.identity] + exact hvalues inputLength index · have hlength : (transitionCases tm).length ≠ 0 := by intro hzero exact hempty (List.isEmpty_iff_length_eq_zero.mpr hzero) @@ -2503,8 +2504,9 @@ private theorem emitEffectConnectors_spaceBoundByWidthAt simp only [BinaryRoutine.SeqListSpaceBoundByWidthAt] exact ⟨hprepare, hinitial, hprevious, hclear, trivial⟩ · intro inputLength index - simpa [BinaryRoutine.seqList, BinaryRoutine.seq, prepare, prepared, - connected, afterPrevious] using hfinalValues inputLength index + simp only [BinaryRoutine.seqList, BinaryRoutine.seq, + BinaryRoutine.identity] + exact hfinalValues inputLength index theorem emitEffectFormula_spaceBoundByWidth_internal (tm : NTM k) (selects : TransitionEffect tm → Bool) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/MovedHead/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/MovedHead/Internal.lean index 88b9e6db..b0ba1e0b 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/MovedHead/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/MovedHead/Internal.lean @@ -61,15 +61,15 @@ private theorem CaseFormulaClean.movedHeadConjunctionClean { temporary₃ := ?_, polynomialScratch := ?_, multiplyCounter := ?_, addCounter := ?_, copyCounter := ?_, loop₃ := ?_, emitCounter := ?_, reference₀ := ?_, reference₁ := ?_ } - · simpa using hclean.temporary₃ - · simpa using hclean.polynomialScratch - · simpa using hclean.multiplyCounter - · simpa using hclean.addCounter - · simpa using hclean.copyCounter - · simpa using hclean.loop₃ - · simpa using hclean.emitCounter - · simpa using hclean.reference₀ - · simpa using hclean.reference₁ + · simpa using! hclean.temporary₃ + · simpa using! hclean.polynomialScratch + · simpa using! hclean.multiplyCounter + · simpa using! hclean.addCounter + · simpa using! hclean.copyCounter + · simpa using! hclean.loop₃ + · simpa using! hclean.emitCounter + · simpa using! hclean.reference₀ + · simpa using! hclean.reference₁ private theorem CaseFormulaClean.updateMovedHeadOuter {values : BinaryValues WorkCount} (hclean : CaseFormulaClean values) @@ -101,7 +101,7 @@ private theorem CaseFormulaClean.updateMovedHeadOuter symbolIndex := ?_ } all_goals simp only [Function.update_apply] - rw [if_neg (by decide)] + rw [ite_eq_right (by decide)] first | exact hclean.position | exact hclean.loop₀ @@ -868,34 +868,34 @@ private theorem CaseFormulaClean.movedHeadMemberResult refine { toReadFormulaClean := { position := rfl, - loop₀ := by simpa [movedHeadMemberResult] using hclean.loop₀, - limit₀ := by simpa [movedHeadMemberResult] using hclean.limit₀, + loop₀ := by simpa [movedHeadMemberResult] using! hclean.loop₀, + limit₀ := by simpa [movedHeadMemberResult] using! hclean.limit₀, reference₀ := by - simpa [movedHeadMemberResult] using hclean.reference₀, + simpa [movedHeadMemberResult] using! hclean.reference₀, reference₁ := by - simpa [movedHeadMemberResult] using hclean.reference₁, + simpa [movedHeadMemberResult] using! hclean.reference₁, emitCounter := by - simpa [movedHeadMemberResult] using hclean.emitCounter, + simpa [movedHeadMemberResult] using! hclean.emitCounter, copyCounter := by - simpa [movedHeadMemberResult] using hclean.copyCounter, + simpa [movedHeadMemberResult] using! hclean.copyCounter, multiplyCounter := by - simpa [movedHeadMemberResult] using hclean.multiplyCounter, + simpa [movedHeadMemberResult] using! hclean.multiplyCounter, addCounter := by - simpa [movedHeadMemberResult] using hclean.addCounter, + simpa [movedHeadMemberResult] using! hclean.addCounter, temporary₀ := by - simpa [movedHeadMemberResult] using hclean.temporary₀, + simpa [movedHeadMemberResult] using! hclean.temporary₀, temporary₁ := by - simpa [movedHeadMemberResult] using hclean.temporary₁, + simpa [movedHeadMemberResult] using! hclean.temporary₁, temporary₂ := by - simpa [movedHeadMemberResult] using hclean.temporary₂ }, - loop₃ := by simpa [movedHeadMemberResult] using hclean.loop₃, + simpa [movedHeadMemberResult] using! hclean.temporary₂ }, + loop₃ := by simpa [movedHeadMemberResult] using! hclean.loop₃, temporary₃ := by - simpa [movedHeadMemberResult] using hclean.temporary₃, + simpa [movedHeadMemberResult] using! hclean.temporary₃, polynomialScratch := by - simpa [movedHeadMemberResult] using hclean.polynomialScratch, + simpa [movedHeadMemberResult] using! hclean.polynomialScratch, tapeIndex := rfl, symbolIndex := by - simpa [movedHeadMemberResult] using hclean.symbolIndex } + simpa [movedHeadMemberResult] using! hclean.symbolIndex } theorem emitMovedHeadFormula_sound_internal (tm : NTM k) (tape : TapeSlot k) : @@ -979,21 +979,20 @@ theorem emitMovedHeadFormula_requires_internal (tm : NTM k) (emitMovedHeadMember tm tape .left 0 Work.savedOutput).effect start = left := by simpa [left, effect₀, selected, choice, start, movedHeadStartValues, - Work.horizon] using - emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput + Work.horizon] using! emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput start hstartClean (by - simpa [start, movedHeadStartValues, Work.loop₁] using hclean.loop₁) - (by simpa [start, movedHeadStartValues, Work.horizon] using hhorizon) + simpa [start, movedHeadStartValues, Work.loop₁] using! hclean.loop₁) + (by simpa [start, movedHeadStartValues, Work.horizon] using! hhorizon) (by simpa [start, movedHeadStartValues, Work.limit₂, Work.position, Work.horizon] using htarget) - (by simpa [start, movedHeadStartValues, Work.available] using havailable) + (by simpa [start, movedHeadStartValues, Work.available] using! havailable) have hrightEffect : (emitMovedHeadMember tm tape .right 1 Work.direction).effect left = right := by simpa [right, effect₁, selected, choice, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, - Work.available, Work.position, Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction + Work.available, Work.position, Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction left hleftClean (by simpa [left, start, movedHeadMemberResult, movedHeadStartValues, Work.loop₁, Work.available, Work.savedOutput, Work.position, @@ -1012,8 +1011,8 @@ theorem emitMovedHeadFormula_requires_internal (tm : NTM k) stay := by simpa [stay, effect₂, selected, choice, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, - Work.available, Work.position, Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind + Work.available, Work.position, Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind right hrightClean (by simpa [right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.loop₁, Work.available, @@ -1037,24 +1036,22 @@ theorem emitMovedHeadFormula_requires_internal (tm : NTM k) connector₀ := by simpa [connector₀] using emitSavedMovedHeadConnector_effect_internal Work.atomKind identity - (by simpa [identity] using hstayClean.reference₁) - (by simpa [identity] using hstayClean.emitCounter) + (by simpa [identity] using! hstayClean.reference₁) + (by simpa [identity] using! hstayClean.emitCounter) have hconnector₁Effect : (emitSavedMovedHeadConnector Work.direction).effect connector₀ = connector₁ := by simpa [connector₁] using emitSavedMovedHeadConnector_effect_internal Work.direction connector₀ - (by simpa [connector₀, identity] using hstayClean.reference₁) - (by simpa [connector₀, identity] using hstayClean.emitCounter) + (by simpa [connector₀, identity] using! hstayClean.reference₁) + (by simpa [connector₀, identity] using! hstayClean.emitCounter) have hconnector₂Effect : (emitSavedMovedHeadConnector Work.savedOutput).effect connector₁ = connector₂ := by simpa [connector₂] using emitSavedMovedHeadConnector_effect_internal Work.savedOutput connector₁ - (by simpa [connector₁, connector₀, identity] using - hstayClean.reference₁) - (by simpa [connector₁, connector₀, identity] using - hstayClean.emitCounter) + (by simpa [connector₁, connector₀, identity] using! hstayClean.reference₁) + (by simpa [connector₁, connector₀, identity] using! hstayClean.emitCounter) have hcopyStart : (BinaryRoutine.binaryCopy Work.position Work.limit₂ Work.copyCounter).requires values := by @@ -1062,11 +1059,11 @@ theorem emitMovedHeadFormula_requires_internal (tm : NTM k) simpa [Work.position, Work.copyCounter] using hclean.caseClean.copyCounter have hleftRequires := emitMovedHeadMember_requires_internal tm tape .left 0 Work.savedOutput start hstartClean (by - simpa [start, movedHeadStartValues, Work.loop₁] using hclean.loop₁) - (by simpa [start, movedHeadStartValues, Work.horizon] using hhorizon) + simpa [start, movedHeadStartValues, Work.loop₁] using! hclean.loop₁) + (by simpa [start, movedHeadStartValues, Work.horizon] using! hhorizon) (by simpa [start, movedHeadStartValues, Work.limit₂, Work.position, Work.horizon] using htarget) - (by simpa [start, movedHeadStartValues, Work.available] using havailable) + (by simpa [start, movedHeadStartValues, Work.available] using! havailable) (Or.inl rfl) have hrightRequires := emitMovedHeadMember_requires_internal tm tape .right 1 Work.direction left hleftClean (by @@ -1099,23 +1096,21 @@ theorem emitMovedHeadFormula_requires_internal (tm : NTM k) have hidentityRequires := emitConstantGate_requires_internal false stay hstayClean.emitCounter have hconnector₀Requires := emitSavedMovedHeadConnector_requires_internal - Work.atomKind identity (by simpa [identity] using hstayClean.copyCounter) - (by simpa [identity] using hstayClean.emitCounter) + Work.atomKind identity (by simpa [identity] using! hstayClean.copyCounter) + (by simpa [identity] using! hstayClean.emitCounter) (by simp [identity, stay, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.available]) (Or.inr (Or.inr rfl)) have hconnector₁Requires := emitSavedMovedHeadConnector_requires_internal Work.direction connector₀ - (by simpa [connector₀, identity] using hstayClean.copyCounter) - (by simpa [connector₀, identity] using hstayClean.emitCounter) + (by simpa [connector₀, identity] using! hstayClean.copyCounter) + (by simpa [connector₀, identity] using! hstayClean.emitCounter) (by simp [connector₀, identity, stay, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.available]) (Or.inr (Or.inl rfl)) have hconnector₂Requires := emitSavedMovedHeadConnector_requires_internal Work.savedOutput connector₁ - (by simpa [connector₁, connector₀, identity] using - hstayClean.copyCounter) - (by simpa [connector₁, connector₀, identity] using - hstayClean.emitCounter) + (by simpa [connector₁, connector₀, identity] using! hstayClean.copyCounter) + (by simpa [connector₁, connector₀, identity] using! hstayClean.emitCounter) (by simp [connector₁, connector₀, identity, stay, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.available]) @@ -1132,8 +1127,7 @@ theorem emitMovedHeadFormula_requires_internal (tm : NTM k) hidentityRequires, hconnector₀Requires, hconnector₁Requires, hconnector₂Requires, trivial, trivial, trivial, ⟨by decide, by decide, by decide, by - simpa [connector₂, connector₁, connector₀, identity] using - hstayClean.copyCounter⟩, + simpa [connector₂, connector₁, connector₀, identity] using! hstayClean.copyCounter⟩, trivial, trivial⟩ set_option maxHeartbeats 1200000 in @@ -1183,21 +1177,20 @@ theorem emitMovedHeadFormula_effect_internal (tm : NTM k) (emitMovedHeadMember tm tape .left 0 Work.savedOutput).effect start = left := by simpa [left, effect₀, selected, choice, start, movedHeadStartValues, - Work.horizon] using - emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput + Work.horizon] using! emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput start hstartClean (by - simpa [start, movedHeadStartValues, Work.loop₁] using hclean.loop₁) - (by simpa [start, movedHeadStartValues, Work.horizon] using hhorizon) + simpa [start, movedHeadStartValues, Work.loop₁] using! hclean.loop₁) + (by simpa [start, movedHeadStartValues, Work.horizon] using! hhorizon) (by simpa [start, movedHeadStartValues, Work.limit₂, Work.position, Work.horizon] using htarget) - (by simpa [start, movedHeadStartValues, Work.available] using havailable) + (by simpa [start, movedHeadStartValues, Work.available] using! havailable) have hrightEffect : (emitMovedHeadMember tm tape .right 1 Work.direction).effect left = right := by simpa [right, effect₁, selected, choice, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, - Work.available, Work.position, Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction + Work.available, Work.position, Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction left hleftClean (by simpa [left, start, movedHeadMemberResult, movedHeadStartValues, Work.loop₁, Work.available, Work.savedOutput, Work.position, @@ -1216,8 +1209,8 @@ theorem emitMovedHeadFormula_effect_internal (tm : NTM k) stay := by simpa [stay, effect₂, selected, choice, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, - Work.available, Work.position, Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind + Work.available, Work.position, Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind right hrightClean (by simpa [right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.loop₁, Work.available, @@ -1241,24 +1234,22 @@ theorem emitMovedHeadFormula_effect_internal (tm : NTM k) connector₀ := by simpa [connector₀] using emitSavedMovedHeadConnector_effect_internal Work.atomKind identity - (by simpa [identity] using hstayClean.reference₁) - (by simpa [identity] using hstayClean.emitCounter) + (by simpa [identity] using! hstayClean.reference₁) + (by simpa [identity] using! hstayClean.emitCounter) have hconnector₁Effect : (emitSavedMovedHeadConnector Work.direction).effect connector₀ = connector₁ := by simpa [connector₁] using emitSavedMovedHeadConnector_effect_internal Work.direction connector₀ - (by simpa [connector₀, identity] using hstayClean.reference₁) - (by simpa [connector₀, identity] using hstayClean.emitCounter) + (by simpa [connector₀, identity] using! hstayClean.reference₁) + (by simpa [connector₀, identity] using! hstayClean.emitCounter) have hconnector₂Effect : (emitSavedMovedHeadConnector Work.savedOutput).effect connector₁ = connector₂ := by simpa [connector₂] using emitSavedMovedHeadConnector_effect_internal Work.savedOutput connector₁ - (by simpa [connector₁, connector₀, identity] using - hstayClean.reference₁) - (by simpa [connector₁, connector₀, identity] using - hstayClean.emitCounter) + (by simpa [connector₁, connector₀, identity] using! hstayClean.reference₁) + (by simpa [connector₁, connector₀, identity] using! hstayClean.emitCounter) simp only [emitMovedHeadFormula, BinaryRoutine.seqList, BinaryRoutine.seq, BinaryRoutine.identity, BinaryRoutine.emitBits] rw [show (BinaryRoutine.clear Work.position).effect @@ -1341,21 +1332,20 @@ theorem emitMovedHeadFormula_emitted_internal (tm : NTM k) (emitMovedHeadMember tm tape .left 0 Work.savedOutput).effect start = left := by simpa [left, effect₀, selected, choice, start, movedHeadStartValues, - Work.horizon] using - emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput + Work.horizon] using! emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput start hstartClean (by - simpa [start, movedHeadStartValues, Work.loop₁] using hclean.loop₁) - (by simpa [start, movedHeadStartValues, Work.horizon] using hhorizon) + simpa [start, movedHeadStartValues, Work.loop₁] using! hclean.loop₁) + (by simpa [start, movedHeadStartValues, Work.horizon] using! hhorizon) (by simpa [start, movedHeadStartValues, Work.limit₂, Work.position, Work.horizon] using htarget) - (by simpa [start, movedHeadStartValues, Work.available] using havailable) + (by simpa [start, movedHeadStartValues, Work.available] using! havailable) have hrightEffect : (emitMovedHeadMember tm tape .right 1 Work.direction).effect left = right := by simpa [right, effect₁, selected, choice, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, - Work.available, Work.position, Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction + Work.available, Work.position, Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction left hleftClean (by simpa [left, start, movedHeadMemberResult, movedHeadStartValues, Work.loop₁, Work.available, Work.savedOutput, Work.position, @@ -1374,8 +1364,8 @@ theorem emitMovedHeadFormula_emitted_internal (tm : NTM k) stay := by simpa [stay, effect₂, selected, choice, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, - Work.available, Work.position, Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind + Work.available, Work.position, Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind right hrightClean (by simpa [right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.loop₁, Work.available, @@ -1394,11 +1384,11 @@ theorem emitMovedHeadFormula_emitted_internal (tm : NTM k) Work.direction, Work.position, Work.tapeIndex]) have hleftEmitted := emitMovedHeadMember_emitted_internal tm tape .left 0 (values Work.available) Work.savedOutput start hstartClean (by - simpa [start, movedHeadStartValues, Work.loop₁] using hclean.loop₁) - (by simpa [start, movedHeadStartValues, Work.horizon] using hhorizon) + simpa [start, movedHeadStartValues, Work.loop₁] using! hclean.loop₁) + (by simpa [start, movedHeadStartValues, Work.horizon] using! hhorizon) (by simpa [start, movedHeadStartValues, Work.limit₂, Work.position, Work.horizon] using htarget) - (by simpa [start, movedHeadStartValues, Work.available] using havailable) + (by simpa [start, movedHeadStartValues, Work.available] using! havailable) rfl (by simp [start, movedHeadStartValues, movedHeadMemberAvailable, prefixSize, Work.available, Work.position, Work.limit₂]) have hrightEmitted := emitMovedHeadMember_emitted_internal tm tape .right 1 @@ -1448,15 +1438,15 @@ theorem emitMovedHeadFormula_emitted_internal (tm : NTM k) connector₀ := by simpa [connector₀] using emitSavedMovedHeadConnector_effect_internal Work.atomKind identity - (by simpa [identity] using hstayClean.reference₁) - (by simpa [identity] using hstayClean.emitCounter) + (by simpa [identity] using! hstayClean.reference₁) + (by simpa [identity] using! hstayClean.emitCounter) have hconnector₁Effect : (emitSavedMovedHeadConnector Work.direction).effect connector₀ = connector₁ := by simpa [connector₁] using emitSavedMovedHeadConnector_effect_internal Work.direction connector₀ - (by simpa [connector₀, identity] using hstayClean.reference₁) - (by simpa [connector₀, identity] using hstayClean.emitCounter) + (by simpa [connector₀, identity] using! hstayClean.reference₁) + (by simpa [connector₀, identity] using! hstayClean.emitCounter) simp only [emitMovedHeadFormula, BinaryRoutine.seqList, BinaryRoutine.seq, BinaryRoutine.identity, BinaryRoutine.emitBits] rw [show (BinaryRoutine.clear Work.position).effect @@ -1767,8 +1757,7 @@ private theorem emitMovedHeadMember_spaceBoundByWidthAt omega · intro inputLength simpa [afterTape, afterPosition, afterEffect, Work.available, - Work.position, Work.tapeIndex, Work.horizon] using - hpredecessorCap inputLength + Work.position, Work.tapeIndex, Work.horizon] using! hpredecessorCap inputLength have hpredecessorTrajectory : ∀ inputLength, (emitPredecessorHeadFormula (Fintype.card tm.Q) directionCode).effect (afterTape inputLength) = afterPredecessor inputLength := by @@ -1790,8 +1779,7 @@ private theorem emitMovedHeadMember_spaceBoundByWidthAt afterPredecessor inputLength Work.loop₃ = 0 := by intro inputLength simpa [afterPredecessor, afterTape, afterPosition, afterEffect, - Work.available, Work.position, Work.tapeIndex] using - (hclean inputLength).loop₃ + Work.available, Work.position, Work.tapeIndex] using! (hclean inputLength).loop₃ have hafterPredecessorAvailable : ∀ inputLength, afterPredecessor inputLength Work.available = afterTape inputLength Work.available + @@ -2078,36 +2066,34 @@ private theorem emitMovedHeadFormulaSuffix_seqListSpaceBoundByWidthAt intro inputLength simpa [v₂] using emitSavedMovedHeadConnector_effect_internal Work.atomKind (v₁ inputLength) - (by simpa [v₁] using (hclean inputLength).reference₁) - (by simpa [v₁] using (hclean inputLength).emitCounter) + (by simpa [v₁] using! (hclean inputLength).reference₁) + (by simpa [v₁] using! (hclean inputLength).emitCounter) have he₃ : ∀ inputLength, (emitSavedMovedHeadConnector Work.direction).effect (v₂ inputLength) = v₃ inputLength := by intro inputLength simpa [v₃] using emitSavedMovedHeadConnector_effect_internal Work.direction (v₂ inputLength) - (by simpa [v₂, v₁] using (hclean inputLength).reference₁) - (by simpa [v₂, v₁] using (hclean inputLength).emitCounter) + (by simpa [v₂, v₁] using! (hclean inputLength).reference₁) + (by simpa [v₂, v₁] using! (hclean inputLength).emitCounter) have he₄ : ∀ inputLength, (emitSavedMovedHeadConnector Work.savedOutput).effect (v₃ inputLength) = v₄ inputLength := by intro inputLength simpa [v₄] using emitSavedMovedHeadConnector_effect_internal Work.savedOutput (v₃ inputLength) - (by simpa [v₃, v₂, v₁] using - (hclean inputLength).reference₁) - (by simpa [v₃, v₂, v₁] using - (hclean inputLength).emitCounter) + (by simpa [v₃, v₂, v₁] using! (hclean inputLength).reference₁) + (by simpa [v₃, v₂, v₁] using! (hclean inputLength).emitCounter) simp only [BinaryRoutine.SeqListSpaceBoundByWidthAt] refine ⟨hs₁, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, trivial⟩ · simpa only [he₁] using hs₂ · simpa only [he₁, he₂] using hs₃ · simpa only [he₁, he₂, he₃] using hs₄ · simpa only [he₁, he₂, he₃, he₄] using hs₅ - · simpa only [he₁, he₂, he₃, he₄] using hs₆ - · simpa only [he₁, he₂, he₃, he₄] using hs₇ - · simpa only [he₁, he₂, he₃, he₄] using hs₈ - · simpa only [he₁, he₂, he₃, he₄] using hs₉ + · simpa only [he₁, he₂, he₃, he₄] using! hs₆ + · simpa only [he₁, he₂, he₃, he₄] using! hs₇ + · simpa only [he₁, he₂, he₃, he₄] using! hs₈ + · simpa only [he₁, he₂, he₃, he₄] using! hs₉ theorem emitMovedHeadFormula_spaceBoundByWidth_internal (tm : NTM k) (tape : TapeSlot k) {initialSpace : ℕ → ℕ} @@ -2270,13 +2256,11 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal have hstartLoop₁ : ∀ inputLength, start inputLength Work.loop₁ = 0 := by intro inputLength - simpa [start, movedHeadStartValues, Work.loop₁] using - (hclean inputLength).loop₁ + simpa [start, movedHeadStartValues, Work.loop₁] using! (hclean inputLength).loop₁ have hstartHorizon : ∀ inputLength, 0 < start inputLength Work.horizon := by intro inputLength - simpa [start, movedHeadStartValues, Work.horizon] using - hhorizon inputLength + simpa [start, movedHeadStartValues, Work.horizon] using! hhorizon inputLength have hstartTarget : ∀ inputLength, start inputLength Work.limit₂ ≤ start inputLength Work.horizon := by intro inputLength @@ -2285,8 +2269,7 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal have hstartAvailable : ∀ inputLength, 1 ≤ start inputLength Work.available := by intro inputLength - simpa [start, movedHeadStartValues, Work.available] using - havailable inputLength + simpa [start, movedHeadStartValues, Work.available] using! havailable inputLength have hleftFrontier : ∀ inputLength, start inputLength Work.available + effect₀ inputLength + movedHeadPredecessorSize (start inputLength Work.horizon) + 1 ≤ @@ -2322,8 +2305,8 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal hsymbol hposition have hc := hcap inputLength stateIndex tapeIndex symbolIndex position hstate htape hsymbol (by - simpa [start, movedHeadStartValues, Work.horizon] using - hposition.trans (Nat.le_add_right _ 1)) + simpa [start, movedHeadStartValues, Work.horizon] + using! hposition.trans (Nat.le_add_right _ 1)) simp [start, movedHeadStartValues, movedHeadFormulaScheduleSize, movedHeadMemberSizeAt, movedHeadDirectionCount, prefixSize, selected, choice, Work.available, Work.horizon, Work.configBase, Work.limit₂, @@ -2336,11 +2319,10 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal Work.savedOutput hstartClean hstartLoop₁ hstartHorizon hstartTarget hstartAvailable hstartValues hleftFrontier hleftEffectCap · intro inputLength - simpa [start, movedHeadStartValues, Work.horizon, Work.configBase] using - hpredecessorCap inputLength + simpa [start, movedHeadStartValues, Work.horizon, Work.configBase] + using! hpredecessorCap inputLength · intro inputLength - simpa [start, movedHeadStartValues, Work.horizon] using - hpolynomialCap inputLength + simpa [start, movedHeadStartValues, Work.horizon] using! hpolynomialCap inputLength have hleftValues : ∀ inputLength index, left inputLength index ≤ width inputLength := by exact movedHeadMemberResult_values_le Work.savedOutput hstartValues @@ -2355,7 +2337,7 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal (start inputLength) = left inputLength := by intro inputLength simpa [left, effect₀, selected, choice, start, movedHeadStartValues, - Work.horizon] using emitMovedHeadMember_effect_internal tm tape .left 0 + Work.horizon] using! emitMovedHeadMember_effect_internal tm tape .left 0 Work.savedOutput (start inputLength) (hstartClean inputLength) (hstartLoop₁ inputLength) (hstartHorizon inputLength) (hstartTarget inputLength) (hstartAvailable inputLength) @@ -2460,7 +2442,7 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal simpa [right, effect₁, selected, choice, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, Work.available, Work.savedOutput, Work.position, Work.tapeIndex, - Work.limit₂] using emitMovedHeadMember_effect_internal tm tape .right + Work.limit₂] using! emitMovedHeadMember_effect_internal tm tape .right 1 Work.direction (left inputLength) (hleftClean inputLength) (hleftLoop₁ inputLength) (hleftHorizon inputLength) (hleftTarget inputLength) (hleftAvailable inputLength) @@ -2568,8 +2550,8 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal simpa [stay, effect₂, selected, choice, right, left, start, movedHeadMemberResult, movedHeadStartValues, Work.horizon, Work.available, Work.savedOutput, Work.direction, Work.position, - Work.tapeIndex, Work.limit₂] using - emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind + Work.tapeIndex, Work.limit₂] + using! emitMovedHeadMember_effect_internal tm tape .stay 2 Work.atomKind (right inputLength) (hrightClean inputLength) (hrightLoop₁ inputLength) (hrightHorizon inputLength) (hrightTarget inputLength) (hrightAvailable inputLength) @@ -2607,7 +2589,7 @@ theorem emitMovedHeadFormula_spaceBoundByWidth_internal · simpa only [hparkedTrajectory, hstartTrajectory, hleftTrajectory, hrightTrajectory] using hstay · simpa only [hparkedTrajectory, hstartTrajectory, hleftTrajectory, - hrightTrajectory, hstayTrajectory] using hsuffix + hrightTrajectory, hstayTrajectory] using! hsuffix end DirectGenerator diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Next/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Next/Internal.lean index 79da6c7c..da865ff3 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Next/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Next/Internal.lean @@ -1423,7 +1423,7 @@ theorem emitNextStateFormula_emitted_internal (tm : NTM k) nextSchedule values hclean.haltedOrClean holdEffect hnextEffect holdEmitted hnextEmitted hsize simpa [emitNextStateFormula, nextStateFormulaSchedule, - nextSchedule, nextFormulaChildAvailable] using hresult + nextSchedule, nextFormulaChildAvailable] using! hresult theorem emitNextStateFormula_spaceBoundByWidth_internal (tm : NTM k) (state : tm.Q) {initialSpace : ℕ → ℕ} @@ -1505,8 +1505,7 @@ theorem emitNextStateFormula_spaceBoundByWidth_internal (tm : NTM k) width inputLength := by intro inputLength simpa [childSize, stateNextChildPolynomial, - nextStateFormulaScheduleSize, nextHaltedOrScheduleSize] using - hcapBase inputLength + nextStateFormulaScheduleSize, nextHaltedOrScheduleSize] using! hcapBase inputLength have hhaltCap : ∀ inputLength, transitionStateRef (values inputLength Work.configBase) (stateIndex tm tm.qhalt) ≤ width inputLength := by @@ -1767,7 +1766,7 @@ theorem emitNextHeadFormula_emitted_internal (tm : NTM k) nextSchedule values (parkedCase_haltedOrClean hcase) holdEffect hnextEffect holdEmitted hnextEmitted hsize simpa [emitNextHeadFormula, nextHeadFormulaSchedule, nextSchedule, - nextFormulaChildAvailable] using hresult + nextFormulaChildAvailable] using! hresult private structure NextHeadFormulaWidthCap (tm : NTM k) (tape : TapeSlot k) (values : ℕ → BinaryValues WorkCount) @@ -2020,8 +2019,7 @@ theorem emitNextHeadFormula_spaceBoundByWidth_internal (tm : NTM k) width inputLength := by intro inputLength simpa [childSize, headNextChildPolynomial, - nextHeadFormulaScheduleSize, nextHaltedOrScheduleSize] using - hcapBase inputLength + nextHeadFormulaScheduleSize, nextHaltedOrScheduleSize] using! hcapBase inputLength have hhaltCap : ∀ inputLength, transitionStateRef (values inputLength Work.configBase) (stateIndex tm tm.qhalt) ≤ width inputLength := by @@ -2274,7 +2272,7 @@ theorem emitNextWrittenCellFormula_emitted_internal (tm : NTM k) nextSchedule values (parkedCase_haltedOrClean hcase) holdEffect hnextEffect holdEmitted hnextEmitted hsize simpa [emitNextWrittenCellFormula, nextWrittenCellFormulaSchedule, - nextSchedule, nextFormulaChildAvailable] using hresult + nextSchedule, nextFormulaChildAvailable] using! hresult private structure NextWrittenCellFormulaWidthCap (tm : NTM k) (tape : WritableSlot k) (symbol : Γ) @@ -2562,8 +2560,7 @@ theorem emitNextWrittenCellFormula_spaceBoundByWidth_internal (tm : NTM k) width inputLength := by intro inputLength simpa [childSize, writtenNextChildPolynomial, - nextWrittenCellFormulaScheduleSize, nextHaltedOrScheduleSize] using - hcapBase inputLength + nextWrittenCellFormulaScheduleSize, nextHaltedOrScheduleSize] using! hcapBase inputLength have hhaltCap : ∀ inputLength, transitionStateRef (values inputLength Work.configBase) (stateIndex tm tm.qhalt) ≤ width inputLength := by diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Predecessor/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Predecessor/Internal.lean index 5bc45689..6cf02d44 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Predecessor/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Predecessor/Internal.lean @@ -442,7 +442,7 @@ private theorem emitHeadReference_effect_of_clean split_ifs all_goals simp_all -set_option maxHeartbeats 800000 in +set_option maxHeartbeats 2400000 in theorem emitStayPredecessorMembers_effect_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -589,7 +589,7 @@ private theorem emitConstantFalse_binaryForTemporaryEffect (values Work.temporary₃ - values Work.loop₀) set_option maxRecDepth 10000 in -set_option maxHeartbeats 800000 in +set_option maxHeartbeats 2400000 in theorem emitLeftPositivePredecessorTail_effect_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hloop : values Work.loop₀ = 0) @@ -680,7 +680,7 @@ theorem emitLeftPositivePredecessorTail_effect_internal · simp [htemp, hloopIdx, havailable, hposition] set_option maxRecDepth 10000 in -set_option maxHeartbeats 800000 in +set_option maxHeartbeats 2400000 in theorem emitRightPositivePredecessorMembers_effect_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -718,7 +718,7 @@ theorem emitRightPositivePredecessorMembers_effect_internal all_goals omega set_option maxRecDepth 10000 in -set_option maxHeartbeats 800000 in +set_option maxHeartbeats 2400000 in theorem emitLeftZeroPredecessorMembers_effect_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -751,7 +751,7 @@ theorem emitLeftZeroPredecessorMembers_effect_internal all_goals omega set_option maxRecDepth 10000 in -set_option maxHeartbeats 3000000 in +set_option maxHeartbeats 9000000 in theorem emitLeftPositivePredecessorMembers_effect_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -891,7 +891,7 @@ theorem emitPredecessorHeadMembers_effect_internal hclean htarget set_option maxRecDepth 10000 in -set_option maxHeartbeats 1200000 in +set_option maxHeartbeats 3600000 in theorem emitStayPredecessorMembers_emitted_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -969,7 +969,7 @@ theorem emitStayPredecessorMembers_emitted_internal Work.position, Work.loop₀, Work.limit₀, Work.temporary₀, Work.reference₀, Function.update_apply] split_ifs - all_goals simp_all [List.flatMap_append] + all_goals simp_all all_goals simp_all [Work.horizon, Work.position] all_goals simp [emitPredecessorFalseRange_effect_internal, BinaryRoutine.binaryCopy, directInitConstant, Work.available, @@ -999,7 +999,7 @@ theorem emitRightZeroPredecessorMembers_emitted_internal simp [hloop', directInitConstant, Work.horizon, Work.loop₀, Work.limit₀] set_option maxRecDepth 10000 in -set_option maxHeartbeats 1200000 in +set_option maxHeartbeats 3600000 in theorem emitRightPositivePredecessorMembers_emitted_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -1100,7 +1100,7 @@ theorem emitRightPositivePredecessorMembers_emitted_internal simp [hgap, htargetValue] set_option maxRecDepth 10000 in -set_option maxHeartbeats 1200000 in +set_option maxHeartbeats 3600000 in theorem emitLeftZeroPredecessorMembers_emitted_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (_hclean : PredecessorHeadClean values) @@ -1181,7 +1181,7 @@ theorem emitLeftZeroPredecessorMembers_emitted_internal simp [hT, hposition] set_option maxRecDepth 10000 in -set_option maxHeartbeats 1200000 in +set_option maxHeartbeats 3600000 in theorem emitLeftPositivePredecessorTail_emitted_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hloop : values Work.loop₀ = 0) : @@ -1251,7 +1251,7 @@ theorem emitLeftPositivePredecessorTail_emitted_internal simp [hgapValue, hloop'] set_option maxRecDepth 10000 in -set_option maxHeartbeats 1800000 in +set_option maxHeartbeats 5400000 in theorem emitLeftPositivePredecessorMembers_emitted_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -1972,7 +1972,7 @@ theorem emitPredecessorHeadConnectors_emitted_internal simp only [hblocks] set_option maxRecDepth 10000 in -set_option maxHeartbeats 1800000 in +set_option maxHeartbeats 5400000 in theorem emitPredecessorHeadFormula_effect_internal (stateCount directionCode : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -2070,7 +2070,7 @@ theorem emitPredecessorHeadFormula_effect_internal all_goals omega set_option maxRecDepth 10000 in -set_option maxHeartbeats 1800000 in +set_option maxHeartbeats 5400000 in theorem emitPredecessorHeadFormula_emitted_internal (stateCount directionCode : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -2276,7 +2276,7 @@ private theorem emitPredecessorHeadConnectors_requires_internal rfl set_option maxRecDepth 10000 in -set_option maxHeartbeats 1800000 in +set_option maxHeartbeats 5400000 in theorem emitStayPredecessorMembers_requires_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -2400,7 +2400,7 @@ theorem emitRightZeroPredecessorMembers_requires_internal emitPredecessorFalseRange_requires_internal afterHorizon hle hemit⟩ set_option maxRecDepth 10000 in -set_option maxHeartbeats 2400000 in +set_option maxHeartbeats 7200000 in theorem emitRightPositivePredecessorMembers_requires_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -2568,7 +2568,7 @@ theorem preparePredecessorHorizonGap_requires_internal simpa [Work.horizon, Work.position, Work.temporary₃] using htarget set_option maxRecDepth 10000 in -set_option maxHeartbeats 1800000 in +set_option maxHeartbeats 5400000 in theorem emitLeftZeroPredecessorMembers_requires_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -2697,7 +2697,7 @@ private theorem emitConstantFalseTemporaryFor_requires constructor <;> simp [Work.available, Work.loop₀, Work.temporary₃] set_option maxRecDepth 10000 in -set_option maxHeartbeats 1800000 in +set_option maxHeartbeats 5400000 in theorem emitLeftPositivePredecessorTail_requires_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hloop : values Work.loop₀ = 0) @@ -2780,7 +2780,7 @@ theorem emitLeftPositivePredecessorTail_requires_internal trivial, trivial, trivial⟩ set_option maxRecDepth 10000 in -set_option maxHeartbeats 3000000 in +set_option maxHeartbeats 9000000 in theorem emitLeftPositivePredecessorMembers_requires_internal (stateCount : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -2920,7 +2920,7 @@ theorem emitPredecessorHeadMembers_requires_internal hclean htarget set_option maxRecDepth 10000 in -set_option maxHeartbeats 2400000 in +set_option maxHeartbeats 7200000 in private theorem predecessorHeadRoutine_requires (stateCount directionCode : ℕ) (values : BinaryValues WorkCount) (hclean : PredecessorHeadClean values) @@ -3629,7 +3629,6 @@ private theorem emitLeftZeroPredecessorMembers_spaceBoundByWidthAt intro n apply BinaryRoutine.values_update_le Work.position (hafterHead₀Values n) - change afterHead₀ n Work.position + 1 ≤ width n rw [show afterHead₀ n Work.position = values n Work.position by simp [afterHead₀, head, emitHeadReference_effect, Work.available, Work.position, Work.temporary₀, Work.reference₀]] @@ -5011,8 +5010,8 @@ theorem emitPredecessorHeadFormula_spaceBoundByWidth_internal apply BinaryRoutine.SpaceBoundByWidthAt.seqList exact ⟨hs₁, hs₂, hs₃, hs₄, hs₅, hs₆, hs₇, hs₈, trivial⟩ - simpa [emitPredecessorHeadFormula, members, identityGate, setOffset, - connectors, clearLoop, clearLimit] using hroutine.restrict + simp [emitPredecessorHeadFormula] + exact hroutine.restrict private theorem predecessor_sound_with_stronger_requires (routine : BinaryRoutine WorkCount) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Read/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Read/Internal.lean index bbffb411..2e3e1e6a 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Read/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Read/Internal.lean @@ -1028,9 +1028,7 @@ private theorem emitReadMembers_spaceBoundByWidthAt simp only [BinaryRoutine.binaryForCount] at hcount simp only [Work.limit₀, Work.position] at hcount hlimit hstart omega - · simpa [pairedInitialSpace, pairedWidth, pairedValues, pairedInput, - pairedCount, loopCount, body, - BinaryRoutine.binaryForClampedValues] using hbody + · exact hbody private theorem emitReadMembers_effect_of_invariant (stateCount tapeCount : ℕ) (values : BinaryValues WorkCount) @@ -1371,9 +1369,7 @@ private theorem emitReadNextConnectors_spaceBoundByWidthAt simp only [BinaryRoutine.binaryForCount] at hcount simp only [Work.limit₀, Work.loop₀] at hcount hlimit hstart omega - · simpa [pairedInitialSpace, pairedWidth, pairedValues, pairedInput, - pairedCount, loopCount, BinaryRoutine.binaryForClampedValues] using - hbody + · exact hbody private theorem emitReadNextConnector_preserves_loop₀ (values : BinaryValues WorkCount) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Effect.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Effect.lean index 07529269..3848157b 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Effect.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Effect.lean @@ -234,23 +234,23 @@ private theorem update_available_preserves_caseClean symbolIndex := ?_ } all_goals first - | simpa [updated, Function.update_apply, Work.available] using hclean.position - | simpa [updated, Function.update_apply, Work.available] using hclean.loop₀ - | simpa [updated, Function.update_apply, Work.available] using hclean.limit₀ - | simpa [updated, Function.update_apply, Work.available] using hclean.reference₀ - | simpa [updated, Function.update_apply, Work.available] using hclean.reference₁ - | simpa [updated, Function.update_apply, Work.available] using hclean.emitCounter - | simpa [updated, Function.update_apply, Work.available] using hclean.copyCounter - | simpa [updated, Function.update_apply, Work.available] using hclean.multiplyCounter - | simpa [updated, Function.update_apply, Work.available] using hclean.addCounter - | simpa [updated, Function.update_apply, Work.available] using hclean.temporary₀ - | simpa [updated, Function.update_apply, Work.available] using hclean.temporary₁ - | simpa [updated, Function.update_apply, Work.available] using hclean.temporary₂ - | simpa [updated, Function.update_apply, Work.available] using hclean.loop₃ - | simpa [updated, Function.update_apply, Work.available] using hclean.temporary₃ - | simpa [updated, Function.update_apply, Work.available] using hclean.polynomialScratch - | simpa [updated, Function.update_apply, Work.available] using hclean.tapeIndex - | simpa [updated, Function.update_apply, Work.available] using hclean.symbolIndex + | simpa [updated, Function.update_apply, Work.available] using! hclean.position + | simpa [updated, Function.update_apply, Work.available] using! hclean.loop₀ + | simpa [updated, Function.update_apply, Work.available] using! hclean.limit₀ + | simpa [updated, Function.update_apply, Work.available] using! hclean.reference₀ + | simpa [updated, Function.update_apply, Work.available] using! hclean.reference₁ + | simpa [updated, Function.update_apply, Work.available] using! hclean.emitCounter + | simpa [updated, Function.update_apply, Work.available] using! hclean.copyCounter + | simpa [updated, Function.update_apply, Work.available] using! hclean.multiplyCounter + | simpa [updated, Function.update_apply, Work.available] using! hclean.addCounter + | simpa [updated, Function.update_apply, Work.available] using! hclean.temporary₀ + | simpa [updated, Function.update_apply, Work.available] using! hclean.temporary₁ + | simpa [updated, Function.update_apply, Work.available] using! hclean.temporary₂ + | simpa [updated, Function.update_apply, Work.available] using! hclean.loop₃ + | simpa [updated, Function.update_apply, Work.available] using! hclean.temporary₃ + | simpa [updated, Function.update_apply, Work.available] using! hclean.polynomialScratch + | simpa [updated, Function.update_apply, Work.available] using! hclean.tapeIndex + | simpa [updated, Function.update_apply, Work.available] using! hclean.symbolIndex private theorem update_available_preserves_movedClean {values : BinaryValues WorkCount} @@ -269,11 +269,11 @@ private theorem update_available_preserves_movedClean exact update_available_preserves_caseClean hclean.caseClean value all_goals first - | simpa [Work.available, Work.limit₂] using hclean.limit₂ - | simpa [Work.available, Work.loop₁] using hclean.loop₁ - | simpa [Work.available, Work.savedOutput] using hclean.savedOutput - | simpa [Work.available, Work.direction] using hclean.direction - | simpa [Work.available, Work.atomKind] using hclean.atomKind + | simpa [Work.available, Work.limit₂] using! hclean.limit₂ + | simpa [Work.available, Work.loop₁] using! hclean.loop₁ + | simpa [Work.available, Work.savedOutput] using! hclean.savedOutput + | simpa [Work.available, Work.direction] using! hclean.direction + | simpa [Work.available, Work.atomKind] using! hclean.atomKind theorem update_available_preserves_stepClean_internal {values : BinaryValues WorkCount} (hclean : StepClean values) (value : ℕ) : @@ -360,23 +360,23 @@ private theorem update_limit₁_preserves_caseClean symbolIndex := ?_ } all_goals first - | simpa [Work.limit₁] using hclean.position - | simpa [Work.limit₁] using hclean.loop₀ - | simpa [Work.limit₁] using hclean.limit₀ - | simpa [Work.limit₁] using hclean.reference₀ - | simpa [Work.limit₁] using hclean.reference₁ - | simpa [Work.limit₁] using hclean.emitCounter - | simpa [Work.limit₁] using hclean.copyCounter - | simpa [Work.limit₁] using hclean.multiplyCounter - | simpa [Work.limit₁] using hclean.addCounter - | simpa [Work.limit₁] using hclean.temporary₀ - | simpa [Work.limit₁] using hclean.temporary₁ - | simpa [Work.limit₁] using hclean.temporary₂ - | simpa [Work.limit₁] using hclean.loop₃ - | simpa [Work.limit₁] using hclean.temporary₃ - | simpa [Work.limit₁] using hclean.polynomialScratch - | simpa [Work.limit₁] using hclean.tapeIndex - | simpa [Work.limit₁] using hclean.symbolIndex + | simpa [Work.limit₁] using! hclean.position + | simpa [Work.limit₁] using! hclean.loop₀ + | simpa [Work.limit₁] using! hclean.limit₀ + | simpa [Work.limit₁] using! hclean.reference₀ + | simpa [Work.limit₁] using! hclean.reference₁ + | simpa [Work.limit₁] using! hclean.emitCounter + | simpa [Work.limit₁] using! hclean.copyCounter + | simpa [Work.limit₁] using! hclean.multiplyCounter + | simpa [Work.limit₁] using! hclean.addCounter + | simpa [Work.limit₁] using! hclean.temporary₀ + | simpa [Work.limit₁] using! hclean.temporary₁ + | simpa [Work.limit₁] using! hclean.temporary₂ + | simpa [Work.limit₁] using! hclean.loop₃ + | simpa [Work.limit₁] using! hclean.temporary₃ + | simpa [Work.limit₁] using! hclean.polynomialScratch + | simpa [Work.limit₁] using! hclean.tapeIndex + | simpa [Work.limit₁] using! hclean.symbolIndex theorem update_limit₁_preserves_phaseClean_internal {values : BinaryValues WorkCount} (hclean : StepPhaseCleanInternal values) @@ -399,11 +399,11 @@ theorem update_limit₁_preserves_phaseClean_internal value all_goals first - | simpa [Work.limit₁] using hclean.movedHeadClean.limit₂ - | simpa [Work.limit₁] using hclean.movedHeadClean.loop₁ - | simpa [Work.limit₁] using hclean.movedHeadClean.savedOutput - | simpa [Work.limit₁] using hclean.movedHeadClean.direction - | simpa [Work.limit₁] using hclean.movedHeadClean.atomKind + | simpa [Work.limit₁] using! hclean.movedHeadClean.limit₂ + | simpa [Work.limit₁] using! hclean.movedHeadClean.loop₁ + | simpa [Work.limit₁] using! hclean.movedHeadClean.savedOutput + | simpa [Work.limit₁] using! hclean.movedHeadClean.direction + | simpa [Work.limit₁] using! hclean.movedHeadClean.atomKind · simpa [Work.limit₁, Work.position] using hclean.position private theorem seqList_stateFormulas_effect @@ -424,7 +424,7 @@ private theorem seqList_stateFormulas_effect funext i by_cases hi : i = Work.available <;> simp [BinaryRoutine.seqList, BinaryRoutine.identity, - BinaryRoutine.emitBits, Function.update_apply, hi] + BinaryRoutine.emitBits, hi] | cons state states ih => rw [List.map_cons, BinaryRoutine.seqList, BinaryRoutine.seq] change (BinaryRoutine.seqList (states.map (emitNextStateFormula tm))).effect @@ -463,7 +463,7 @@ theorem emitStepStateFormulas_effect_internal (tm : NTM k) · simp · intro i hleft hright simp] - simpa using seqList_stateFormulas_effect tm + simpa using! seqList_stateFormulas_effect tm (List.ofFn fun stateIndex : Fin (Fintype.card tm.Q) => (Fintype.equivFin tm.Q).symm stateIndex) values hclean.caseFormulaClean_forEffect @@ -1746,10 +1746,10 @@ private theorem cellCopyBody_effect (tm : NTM k) (tape : TapeSlot k) simpa [stepCellPositionEffectSizeInternal] using emitStepImmutableCellCopies_effect_internal values | work index => - simpa using emitStepWritableCellCopies_effect_internal tm (.work index) + simpa using! emitStepWritableCellCopies_effect_internal tm (.work index) values | output => - simpa using emitStepWritableCellCopies_effect_internal tm .output values + simpa using! emitStepWritableCellCopies_effect_internal tm .output values private theorem clearPosition_after_copyUpdates (values : BinaryValues WorkCount) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Emitted.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Emitted.lean index 3d1b0364..82d3f556 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Emitted.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Emitted.lean @@ -94,7 +94,7 @@ private theorem stepConfigAtomAt_configIndex (tm : NTM k) (T : ℕ) (atom : ConfigAtom tm T) : stepConfigAtomAt tm T (configIndex tm T atom) = atom := by unfold stepConfigAtomAt - rw [dif_pos (configIndex_lt tm T atom)] + rw [dite_eq_left (configIndex_lt tm T atom)] have hindex : (⟨configIndex tm T atom, configIndex_lt tm T atom⟩ : Fin (configWidth tm T)) = configAtomEquiv tm T atom := by @@ -539,7 +539,7 @@ private theorem stepFormulaSizeAtSpecialized_internal_state (tm : NTM k) (T : (Fintype.equivFin tm.Q).symm index)) (effectCaseChoiceAt tm) := by unfold stepFormulaSizeAtSpecializedInternal stepFormulaSizeAt - rw [if_pos] + rw [ite_eq_left] · unfold stepAtomKindAt stepAtomEffectSelectedAt rw [← stateAtom_index tm index, stepConfigAtomAt_configIndex tm T] @@ -645,8 +645,8 @@ private theorem stepFormulaSizeAtSpecialized_internal_head (tm : NTM k) (T : ℕ nextHeadFormulaScheduleSize (transitionCases tm).length k T (movedHeadCaseSelectedAt tm tape) (effectCaseChoiceAt tm) := by unfold stepFormulaSizeAtSpecializedInternal stepFormulaSizeAt - rw [if_pos (by simpa [stepAtomCount, configWidth] using - configIndex_lt tm T (.head tape position))] + rw [ite_eq_left (by simpa [stepAtomCount, configWidth] + using! configIndex_lt tm T (.head tape position))] unfold stepAtomKindAt stepAtomEffectSelectedAt rw [stepConfigAtomAt_configIndex] rfl @@ -678,8 +678,8 @@ private theorem stepFormulaSizeAtSpecialized_internal_cellCopy (tm : NTM k) stepFormulaSizeAtSpecializedInternal tm T (configIndex tm T (.cell tape position symbol)) = 1 := by unfold stepFormulaSizeAtSpecializedInternal stepFormulaSizeAt - rw [if_pos (by simpa [stepAtomCount, configWidth] using - configIndex_lt tm T (.cell tape position symbol))] + rw [ite_eq_left (by simpa [stepAtomCount, configWidth] + using! configIndex_lt tm T (.cell tape position symbol))] unfold stepAtomKindAt stepAtomEffectSelectedAt rw [stepConfigAtomAt_configIndex] rcases hcopy with rfl | hzero @@ -718,8 +718,8 @@ private theorem stepFormulaSizeAtSpecialized_internal_writtenCell (tm : NTM k) (writtenCellEffectSelectedAt tm tape symbol) (effectCaseChoiceAt tm) := by unfold stepFormulaSizeAtSpecializedInternal stepFormulaSizeAt - rw [if_pos (by simpa [stepAtomCount, configWidth] using - configIndex_lt tm T (.cell tape.toTapeSlot position symbol))] + rw [ite_eq_left (by simpa [stepAtomCount, configWidth] + using! configIndex_lt tm T (.cell tape.toTapeSlot position symbol))] unfold stepAtomKindAt stepAtomEffectSelectedAt rw [stepConfigAtomAt_configIndex] cases tape <;> simp [WritableSlot.toTapeSlot, nextAtomKind, @@ -899,7 +899,7 @@ private theorem stepCellPositionEffectSize_eq_fourSize (tm : NTM k) (stepCellStart tm T (.work index) position + 3) = _ at h₃ simp only [Nat.add_zero] at h₀ unfold stepCellPositionSizeEmitted fourSize - simp only [if_neg hzero] + simp only [ite_eq_right hzero] change (List.ofFn fun symbolIndex : Fin 4 => nextWrittenCellFormulaScheduleSize (transitionCases tm).length k T @@ -959,7 +959,7 @@ private theorem stepCellPositionEffectSize_eq_fourSize (tm : NTM k) (stepCellStart tm T .output position + 3) = _ at h₃ simp only [Nat.add_zero] at h₀ unfold stepCellPositionSizeEmitted fourSize - simp only [if_neg hzero] + simp only [ite_eq_right hzero] change (List.ofFn fun symbolIndex : Fin 4 => nextWrittenCellFormulaScheduleSize (transitionCases tm).length k T @@ -1802,13 +1802,11 @@ theorem emitStepCellTapeFormulas_emitted_internal (tm : NTM k) (trajectory index) hmoved | work tapeIndex => simpa [body, trajectory, Work.position, Work.available, - Work.horizon] using - emitStepWritableCellPosition_effect_internal tm (.work tapeIndex) + Work.horizon] using! emitStepWritableCellPosition_effect_internal tm (.work tapeIndex) (trajectory index) hmoved | output => simpa [body, trajectory, Work.position, Work.available, - Work.horizon] using - emitStepWritableCellPosition_effect_internal tm .output + Work.horizon] using! emitStepWritableCellPosition_effect_internal tm .output (trajectory index) hmoved rw [heffect] have hsize := stepCellPositionEffectSize_eq_fourSize tm tape @@ -1851,21 +1849,18 @@ theorem emitStepCellTapeFormulas_emitted_internal (tm : NTM k) cases tape with | input => simpa [body, trajectory, stepCellStart, Work.position, Work.horizon, - Work.configBase] using - emitStepImmutableCellPosition_emitted_internal tm .input + Work.configBase] using! emitStepImmutableCellPosition_emitted_internal tm .input (trajectory index) hmoved (by simpa [trajectory, Work.position, Work.available, Work.horizon]) (Or.inl rfl) stepAvailable havailableAt | work tapeIndex => simpa [body, trajectory, stepCellStart, Work.position, Work.horizon, - Work.configBase] using - emitStepWritableCellPosition_emitted_internal tm (.work tapeIndex) + Work.configBase] using! emitStepWritableCellPosition_emitted_internal tm (.work tapeIndex) (trajectory index) hmoved (by simpa [trajectory, Work.position, Work.available, Work.horizon]) stepAvailable havailableAt | output => simpa [body, trajectory, stepCellStart, Work.position, Work.horizon, - Work.configBase] using - emitStepWritableCellPosition_emitted_internal tm .output + Work.configBase] using! emitStepWritableCellPosition_emitted_internal tm .output (trajectory index) hmoved (by simpa [trajectory, Work.position, Work.available, Work.horizon]) stepAvailable havailableAt have hemittedGlobal : ∀ index < values Work.horizon + 2, @@ -2002,8 +1997,7 @@ theorem emitStepHeadTapeCopies_emitted_internal (tm : NTM k) · funext i by_cases hpositionIdx : i = Work.position · subst i - simpa [trajectory, Work.position, Work.gateCount, Work.available] using - hposition.symm + simpa [trajectory, Work.position, Work.gateCount, Work.available] using! hposition.symm · by_cases hgateIdx : i = Work.gateCount · subst i simpa [trajectory, sizeAt, start, Work.position, Work.gateCount, @@ -2098,14 +2092,12 @@ theorem emitStepCellTapeCopies_emitted_internal (tm : NTM k) | work tapeIndex => simpa [body, trajectory, Work.position, Work.gateCount, Work.available, Work.reference₀, Work.temporary₃, - Work.horizon] using - emitStepWritableCellCopies_effect_internal tm (.work tapeIndex) + Work.horizon] using! emitStepWritableCellCopies_effect_internal tm (.work tapeIndex) (trajectory index) | output => simpa [body, trajectory, Work.position, Work.gateCount, Work.available, Work.reference₀, Work.temporary₃, - Work.horizon] using - emitStepWritableCellCopies_effect_internal tm .output + Work.horizon] using! emitStepWritableCellCopies_effect_internal tm .output (trajectory index) rw [heffect] have heffectSize : stepCellPositionEffectSizeInternal tm tape @@ -2170,8 +2162,8 @@ theorem emitStepCellTapeCopies_emitted_internal (tm : NTM k) cases tape with | input => simpa [body, stepPackedCopySpecializedInternal, stepPackedCopyGate, - stepFormulaOutputRef, sizeAt, Work.horizon, Work.position] using - emitStepImmutableCellCopies_emitted_internal (trajectory index) + stepFormulaOutputRef, sizeAt, Work.horizon, Work.position] + using! emitStepImmutableCellCopies_emitted_internal (trajectory index) sizeAt (stepCellStart tm (values Work.horizon) .input index) stepAvailable hgateAt hrefAt htempAt (fun symbolIndex => stepFormulaSizeAtSpecialized_internal_cellCopyIndex tm @@ -2179,16 +2171,16 @@ theorem emitStepCellTapeCopies_emitted_internal (tm : NTM k) (Or.inl rfl)) | work tapeIndex => simpa [body, Work.horizon, Work.position, Work.gateCount, - Work.available, Work.reference₀, Work.temporary₃] using - emitStepWritableCellCopies_emitted_internal tm (.work tapeIndex) + Work.available, Work.reference₀, Work.temporary₃] + using! emitStepWritableCellCopies_emitted_internal tm (.work tapeIndex) (trajectory index) (by simpa [trajectory, Work.position, Work.gateCount, Work.available, Work.reference₀, Work.temporary₃, Work.horizon]) stepAvailable hgateAt hrefAt htempAt | output => simpa [body, Work.horizon, Work.position, Work.gateCount, - Work.available, Work.reference₀, Work.temporary₃] using - emitStepWritableCellCopies_emitted_internal tm .output + Work.available, Work.reference₀, Work.temporary₃] + using! emitStepWritableCellCopies_emitted_internal tm .output (trajectory index) (by simpa [trajectory, Work.position, Work.gateCount, Work.available, Work.reference₀, Work.temporary₃, Work.horizon]) stepAvailable hgateAt hrefAt @@ -2408,7 +2400,7 @@ theorem stepFormulasEffectSize_eq_prefixSize_internal (tm : NTM k) (T : ℕ) : simp [tapeAt, tapeCount] · intro index hindex dsimp [tapeAt] - rw [dif_pos hindex] + rw [dite_eq_left hindex] have hprefix := headPrefixBlock_internal tm T ((tapeSlotEquiv k).symm ⟨index, hindex⟩) have hidx := tapeSlotEquiv_symm_index_internal (⟨index, hindex⟩ : @@ -2433,7 +2425,7 @@ theorem stepFormulasEffectSize_eq_prefixSize_internal (tm : NTM k) (T : ℕ) : simp [tapeAt, tapeCount] · intro index hindex dsimp [tapeAt] - rw [dif_pos hindex] + rw [dite_eq_left hindex] have hprefix := cellPrefixBlock_internal tm T ((tapeSlotEquiv k).symm ⟨index, hindex⟩) have hidx := tapeSlotEquiv_symm_index_internal (⟨index, hindex⟩ : diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/FormulaSpace.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/FormulaSpace.lean index a028dca6..e8b113c0 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/FormulaSpace.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/FormulaSpace.lean @@ -307,12 +307,12 @@ private theorem emitStepHeadTapeFormulas_spaceBoundByWidthAt_formula change 0 < bodyValues code Work.horizon rw [htrajectory code] simpa [Work.position, Work.available, Work.horizon, - hentryHorizon (inputAt code)] using hhorizon (inputAt code) + hentryHorizon (inputAt code)] using! hhorizon (inputAt code) · intro code change bodyValues code Work.position ≤ bodyValues code Work.horizon rw [htrajectory code] simp [Work.position, Work.available, Work.horizon] - simpa [Work.horizon, hentryHorizon (inputAt code)] using hcountAt code + simpa [Work.horizon, hentryHorizon (inputAt code)] using! hcountAt code · intro code index change bodyValues code index ≤ width (inputAt code) rw [htrajectory code] @@ -412,7 +412,7 @@ private theorem emitStepHeadTapeFormulas_spaceBoundByWidthAt_formula rw [htrajectory code] at hposition simp [Work.position, Work.available, Work.horizon] at hposition simpa [inputLength, Work.horizon, - hentryHorizon (inputAt code)] using hposition + hentryHorizon (inputAt code)] using! hposition have hcap := (henvelope inputLength).cap tm.qstart tape .output .zero stateIndex tapeIndex symbolIndex position hstate htape hsymbol hposition' @@ -945,7 +945,7 @@ private theorem emitStepCellPosition_spaceBoundByWidthAt_formula · simp [trajectory, hindex] have hresult := BinaryRoutine.SpaceBoundByWidthAt.seqList _ hseq cases tape <;> simpa [routineAt, emitStepImmutableCellPosition, - emitStepWritableCellPosition] using hresult + emitStepWritableCellPosition] using! hresult private noncomputable def stepCellFormulaBodyFormula (tm : NTM k) : TapeSlot k → BinaryRoutine WorkCount @@ -1086,7 +1086,7 @@ private theorem emitStepCellTapeFormulas_spaceBoundByWidthAt_formula (entry inputLength Work.available + prefixSize (stepCellPositionEffectSizeInternal tm tape (entry inputLength Work.horizon)) count) by - simpa [body, stepCellFormulaBodyFormula] using htrajectory] + simpa [body, stepCellFormulaBodyFormula] using! htrajectory] simp [Work.position, Work.available] exact le_trans (Nat.le_of_lt hcount') (henvelope inputLength).horizon_add_two_le_internal @@ -1128,7 +1128,7 @@ private theorem emitStepCellTapeFormulas_spaceBoundByWidthAt_formula tm tape (entry (inputAt code)) (hentryPhase (inputAt code)) (countAt code) simpa [body, stepCellFormulaBodyFormula, localSize, - hentryHorizon (inputAt code)] using heffect + hentryHorizon (inputAt code)] using! heffect suffices hbodySpace : BinaryRoutine.SpaceBoundByWidthAt (match tape with | .input => emitStepImmutableCellPosition tm .input @@ -1136,7 +1136,7 @@ private theorem emitStepCellTapeFormulas_spaceBoundByWidthAt_formula | .output => emitStepWritableCellPosition tm .output) (fun code => initialSpace (Nat.unpair code).1) bodyValues (fun code => width (Nat.unpair code).1) by - simpa [body, stepCellFormulaBodyFormula] using hbodySpace + simpa [body, stepCellFormulaBodyFormula] using! hbodySpace apply emitStepCellPosition_spaceBoundByWidthAt_formula tm tape (baseValues := fun code => baseValues (inputAt code)) · intro code @@ -1312,7 +1312,7 @@ private theorem emitStepCellTapeFormulas_spaceBoundByWidthAt_formula (entry inputLength Work.horizon)) (BinaryRoutine.binaryForCount Work.position Work.limit₁ (entry inputLength))) by - simpa [body, stepCellFormulaBodyFormula] using htrajectory] + simpa [body, stepCellFormulaBodyFormula] using! htrajectory] simp [Work.position, Work.available] have htotal' : BinaryRoutine.binaryForCount 30 Work.limit₁ (entry inputLength) = entry inputLength Work.horizon + 2 := by @@ -1493,7 +1493,7 @@ private theorem emitStepHeadTapeList_spaceBoundByWidthAt_formula simp [trajectory, startAt] rw [hzero] at hseq rw [List.map_ofFn] - simpa only [tapeAt, tapeCount] using hseq + simpa only [tapeAt, tapeCount] using! hseq private theorem emitStepCellTapeList_spaceBoundByWidthAt_formula (tm : NTM k) {initialSpace : ℕ → ℕ} @@ -1670,7 +1670,7 @@ private theorem emitStepCellTapeList_spaceBoundByWidthAt_formula simp [trajectory, startAt, tapeCount] rw [hzero] at hseq rw [List.map_ofFn] - simpa only [tapeAt, tapeCount] using hseq + simpa only [tapeAt, tapeCount] using! hseq private theorem emitStepHeadTapeList_effect_formula (tm : NTM k) (values : BinaryValues WorkCount) (hclean : StepClean values) @@ -1797,7 +1797,7 @@ private theorem emitStepHeadTapeList_effect_formula (tm : NTM k) funext index simp [trajectory, startAt] rw [hstart, ← hfinish] - simpa only [tapeAt] using hend + simpa only [tapeAt] using! hend private theorem emitStepCellTapeList_effect_formula (tm : NTM k) (values : BinaryValues WorkCount) (hclean : StepClean values) : @@ -2048,10 +2048,6 @@ theorem emitStepFormulas_spaceBoundByWidth_internal (tm : NTM k) initialSpace values width := by simp only [BinaryRoutine.SeqListSpaceBoundByWidthAt] refine ⟨hstateSpace, ?_⟩ - change BinaryRoutine.SpaceBoundByWidthAt (setStepPositionLimit 1) - initialSpace - (fun inputLength => - (emitStepStateFormulas tm).effect (values inputLength)) width ∧ True exact ⟨by simpa only [hstateEffectFamily] using hlimit₁Space, trivial⟩ have hfirstTwoEffect : (fun inputLength => @@ -2061,7 +2057,7 @@ theorem emitStepFormulas_spaceBoundByWidth_internal (tm : NTM k) funext inputLength simpa only [BinaryRoutine.seqList, BinaryRoutine.seq, BinaryRoutine.identity, BinaryRoutine.emitBits, - hstateEffect inputLength] using hlimit₁Effect inputLength + hstateEffect inputLength] using! hlimit₁Effect inputLength have hheadSeq : BinaryRoutine.SeqListSpaceBoundByWidthAt (tapes.map (emitStepHeadTapeFormulas tm)) initialSpace afterLimit₁ width := by diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Packed.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Packed.lean index 93aa4ffe..46e49635 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Packed.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Packed.lean @@ -155,7 +155,7 @@ private theorem stepConfigAtomAt_configIndex_packed (tm : NTM k) (T : ℕ) (atom : ConfigAtom tm T) : stepConfigAtomAt tm T (configIndex tm T atom) = atom := by unfold stepConfigAtomAt - rw [dif_pos (configIndex_lt tm T atom)] + rw [dite_eq_left (configIndex_lt tm T atom)] have hindex : (⟨configIndex tm T atom, configIndex_lt tm T atom⟩ : Fin (configWidth tm T)) = configAtomEquiv tm T atom := by @@ -179,7 +179,7 @@ private theorem stepFormulaSizeAtSpecialized_state_packed (tm : NTM k) (Fintype.equivFin tm.Q).symm index)) (effectCaseChoiceAt tm) := by unfold stepFormulaSizeAtSpecializedInternal stepFormulaSizeAt - rw [if_pos] + rw [ite_eq_left] · unfold stepAtomKindAt stepAtomEffectSelectedAt rw [← stateAtom_index_packed tm index, stepConfigAtomAt_configIndex_packed tm T] diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Requires.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Requires.lean index 842a02c3..0b4f9b97 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Requires.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Requires.lean @@ -60,25 +60,25 @@ private theorem MovedHeadFormulaClean.updateAvailable_forStep tapeIndex := ?_ symbolIndex := ?_ } · simp [Work.available, Work.position] - · simpa [Work.available, Work.position] using hcase.loop₀ - · simpa [Work.available, Work.position] using hcase.limit₀ - · simpa [Work.available, Work.position] using hcase.reference₀ - · simpa [Work.available, Work.position] using hcase.reference₁ - · simpa [Work.available, Work.position] using hcase.emitCounter - · simpa [Work.available, Work.position] using hcase.copyCounter - · simpa [Work.available, Work.position] using hcase.multiplyCounter - · simpa [Work.available, Work.position] using hcase.addCounter - · simpa [Work.available, Work.position] using hcase.temporary₀ - · simpa [Work.available, Work.position] using hcase.temporary₁ - · simpa [Work.available, Work.position] using hcase.temporary₂ - · simpa [Work.available, Work.position] using hcase.loop₃ - · simpa [Work.available, Work.position] using hcase.temporary₃ - · simpa [Work.available, Work.position] using hcase.polynomialScratch - · simpa [Work.available, Work.position] using hcase.tapeIndex - · simpa [Work.available, Work.position] using hcase.symbolIndex + · simpa [Work.available, Work.position] using! hcase.loop₀ + · simpa [Work.available, Work.position] using! hcase.limit₀ + · simpa [Work.available, Work.position] using! hcase.reference₀ + · simpa [Work.available, Work.position] using! hcase.reference₁ + · simpa [Work.available, Work.position] using! hcase.emitCounter + · simpa [Work.available, Work.position] using! hcase.copyCounter + · simpa [Work.available, Work.position] using! hcase.multiplyCounter + · simpa [Work.available, Work.position] using! hcase.addCounter + · simpa [Work.available, Work.position] using! hcase.temporary₀ + · simpa [Work.available, Work.position] using! hcase.temporary₁ + · simpa [Work.available, Work.position] using! hcase.temporary₂ + · simpa [Work.available, Work.position] using! hcase.loop₃ + · simpa [Work.available, Work.position] using! hcase.temporary₃ + · simpa [Work.available, Work.position] using! hcase.polynomialScratch + · simpa [Work.available, Work.position] using! hcase.tapeIndex + · simpa [Work.available, Work.position] using! hcase.symbolIndex all_goals simp only [Function.update_apply] - rw [if_neg (by decide)] + rw [ite_eq_right (by decide)] · exact hclean.limit₂ · exact hclean.loop₁ · exact hclean.savedOutput @@ -125,35 +125,24 @@ private theorem MovedHeadFormulaClean.updateLimit₁_forStep refine { toReadFormulaClean := { position := by simp [Work.limit₁, Work.position] - loop₀ := by simpa [Work.limit₁, Work.loop₀] using hcase.loop₀ - limit₀ := by simpa [Work.limit₁, Work.limit₀] using hcase.limit₀ - reference₀ := by simpa [Work.limit₁, Work.reference₀] using - hcase.reference₀ - reference₁ := by simpa [Work.limit₁, Work.reference₁] using - hcase.reference₁ - emitCounter := by simpa [Work.limit₁, Work.emitCounter] using - hcase.emitCounter - copyCounter := by simpa [Work.limit₁, Work.copyCounter] using - hcase.copyCounter + loop₀ := by simpa [Work.limit₁, Work.loop₀] using! hcase.loop₀ + limit₀ := by simpa [Work.limit₁, Work.limit₀] using! hcase.limit₀ + reference₀ := by simpa [Work.limit₁, Work.reference₀] using! hcase.reference₀ + reference₁ := by simpa [Work.limit₁, Work.reference₁] using! hcase.reference₁ + emitCounter := by simpa [Work.limit₁, Work.emitCounter] using! hcase.emitCounter + copyCounter := by simpa [Work.limit₁, Work.copyCounter] using! hcase.copyCounter multiplyCounter := by simpa [Work.limit₁, Work.multiplyCounter] - using hcase.multiplyCounter - addCounter := by simpa [Work.limit₁, Work.addCounter] using - hcase.addCounter - temporary₀ := by simpa [Work.limit₁, Work.temporary₀] using - hcase.temporary₀ - temporary₁ := by simpa [Work.limit₁, Work.temporary₁] using - hcase.temporary₁ - temporary₂ := by simpa [Work.limit₁, Work.temporary₂] using - hcase.temporary₂ } - loop₃ := by simpa [Work.limit₁, Work.loop₃] using hcase.loop₃ - temporary₃ := by simpa [Work.limit₁, Work.temporary₃] using - hcase.temporary₃ + using! hcase.multiplyCounter + addCounter := by simpa [Work.limit₁, Work.addCounter] using! hcase.addCounter + temporary₀ := by simpa [Work.limit₁, Work.temporary₀] using! hcase.temporary₀ + temporary₁ := by simpa [Work.limit₁, Work.temporary₁] using! hcase.temporary₁ + temporary₂ := by simpa [Work.limit₁, Work.temporary₂] using! hcase.temporary₂ } + loop₃ := by simpa [Work.limit₁, Work.loop₃] using! hcase.loop₃ + temporary₃ := by simpa [Work.limit₁, Work.temporary₃] using! hcase.temporary₃ polynomialScratch := by simpa [Work.limit₁, Work.polynomialScratch] - using hcase.polynomialScratch - tapeIndex := by simpa [Work.limit₁, Work.tapeIndex] using - hcase.tapeIndex - symbolIndex := by simpa [Work.limit₁, Work.symbolIndex] using - hcase.symbolIndex } + using! hcase.polynomialScratch + tapeIndex := by simpa [Work.limit₁, Work.tapeIndex] using! hcase.tapeIndex + symbolIndex := by simpa [Work.limit₁, Work.symbolIndex] using! hcase.symbolIndex } · simpa [Work.limit₁, Work.limit₂] using hclean.limit₂ · simpa [Work.limit₁, Work.loop₁] using hclean.loop₁ · simpa [Work.limit₁, Work.savedOutput] using hclean.savedOutput @@ -234,53 +223,48 @@ private theorem MovedHeadFormulaClean.afterPackedCopy_forStep { toReadFormulaClean := { position := by simp [Work.position] loop₀ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.loop₀ + Work.reference₀, Work.temporary₃, Work.position] using! havailable.caseClean.loop₀ limit₀ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.limit₀ + Work.reference₀, Work.temporary₃, Work.position] using! havailable.caseClean.limit₀ reference₀ := by simp [Work.reference₀, Work.temporary₃, Work.position] reference₁ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.reference₁ + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.reference₁ emitCounter := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.emitCounter + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.emitCounter copyCounter := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.copyCounter + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.copyCounter multiplyCounter := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.multiplyCounter + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.multiplyCounter addCounter := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.addCounter + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.addCounter temporary₀ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.temporary₀ + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.temporary₀ temporary₁ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.temporary₁ + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.temporary₁ temporary₂ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.temporary₂ } + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.temporary₂ } loop₃ := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.loop₃ + Work.reference₀, Work.temporary₃, Work.position] using! havailable.caseClean.loop₃ temporary₃ := by simp [Work.temporary₃, Work.position] polynomialScratch := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.polynomialScratch + Work.reference₀, Work.temporary₃, Work.position] + using! havailable.caseClean.polynomialScratch tapeIndex := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.tapeIndex + Work.reference₀, Work.temporary₃, Work.position] using! havailable.caseClean.tapeIndex symbolIndex := by simpa [final, Work.gateCount, Work.available, - Work.reference₀, Work.temporary₃, Work.position] using - havailable.caseClean.symbolIndex } + Work.reference₀, Work.temporary₃, Work.position] using! havailable.caseClean.symbolIndex } all_goals simp only [Function.update_apply] - repeat' rw [if_neg (by decide)] + repeat' rw [ite_eq_right (by decide)] · exact hclean.limit₂ · exact hclean.loop₁ · exact hclean.savedOutput @@ -594,9 +578,9 @@ private theorem emitStepWritableCellPosition_requires_preserves_forStep rw [hcurrent.2.1, hcurrent.2.2.1] exact hposition by_cases hzero : current Work.position = 0 - · simp only [BinaryRoutine.branchZero, hzero, if_true] + · simp only [BinaryRoutine.branchZero, hzero, ite_true] exact hcurrent.1.nextCellCopy_requires_forStep _ _ _ _ - · simp only [BinaryRoutine.branchZero, hzero, if_false] + · simp only [BinaryRoutine.branchZero, hzero, ite_false] exact emitNextWrittenCellFormula_requires tm tape (symbolEquiv.symm symbolIndex) current hcurrent.1.writtenClean_forStep hcurrentPosition) @@ -604,7 +588,7 @@ private theorem emitStepWritableCellPosition_requires_preserves_forStep simp only [List.mem_ofFn] at hroutine obtain ⟨symbolIndex, rfl⟩ := hroutine by_cases hzero : current Work.position = 0 - · simp only [BinaryRoutine.branchZero, hzero, if_true] + · simp only [BinaryRoutine.branchZero, hzero, ite_true] have hcase := hcurrent.1.caseClean have heffect := emitNextCellCopy_effect (Fintype.card tm.Q) (k + 2) tape.toTapeSlot.index @@ -621,7 +605,7 @@ private theorem emitStepWritableCellPosition_requires_preserves_forStep hcurrent.2.1, by simpa [Work.available, Work.horizon] using hcurrent.2.2.1, by simpa [Work.available, Work.limit₁] using hcurrent.2.2.2⟩ - · simp only [BinaryRoutine.branchZero, hzero, if_false] + · simp only [BinaryRoutine.branchZero, hzero, ite_false] rw [emitNextWrittenCellFormula_effect tm tape (symbolEquiv.symm symbolIndex) current hcurrent.1.writtenClean_forStep] refine ⟨MovedHeadFormulaClean.updateAvailable_forStep current @@ -676,8 +660,8 @@ private theorem emitStepWritableTapeCellFormulas_requires_preserves_forStep hbody.2.1 _ limit := ?_ } simp only [BinaryRoutine.binaryForStep, Function.update_apply] - rw [if_neg (by decide), hbody.2.2.2.2, - if_neg (by decide), hbody.2.2.2.1] + rw [ite_eq_right (by decide), hbody.2.2.2.2, + ite_eq_right (by decide), hbody.2.2.2.1] exact hcurrent.limit) simp only [BinaryRoutine.seq] exact ⟨⟨hloop.1, trivial⟩, @@ -707,8 +691,8 @@ private theorem emitStepCellTapeFormulas_requires_preserves_forStep hbody.2.1 _ limit := ?_ } simp only [BinaryRoutine.binaryForStep, Function.update_apply] - rw [if_neg (by decide), hbody.2.2.2.2, - if_neg (by decide), hbody.2.2.2.1] + rw [ite_eq_right (by decide), hbody.2.2.2.2, + ite_eq_right (by decide), hbody.2.2.2.1] exact hcurrent.limit) simp only [emitStepCellTapeFormulas, BinaryRoutine.seq] refine ⟨⟨hloop.1, trivial⟩, @@ -1006,8 +990,8 @@ private theorem emitStepHeadTapeCopies_requires_preserves_forStep hbody.2.1 _ limit := ?_ } simp only [BinaryRoutine.binaryForStep, Function.update_apply] - rw [if_neg (by decide), hbody.2.2.2.2, - if_neg (by decide), hbody.2.2.2.1] + rw [ite_eq_right (by decide), hbody.2.2.2.2, + ite_eq_right (by decide), hbody.2.2.2.1] exact hcurrent.limit) simp only [emitStepHeadTapeCopies, BinaryRoutine.seq] refine ⟨⟨hloop.1, trivial⟩, ?_⟩ @@ -1114,25 +1098,25 @@ private theorem emitStepWritableCellCopies_requires_preserves_forStep simp only [List.mem_ofFn] at hroutine obtain ⟨symbolIndex, rfl⟩ := hroutine by_cases hzero : current Work.position = 0 - · simp only [BinaryRoutine.branchZero, hzero, if_true] + · simp only [BinaryRoutine.branchZero, hzero, ite_true] exact (emitPackedFormulaCopy_requires_preserves_forStep (Polynomial.C 1) current hcurrent.1 (by simpa only [Polynomial.eval_C] using Nat.zero_lt_one)).1 - · simp only [BinaryRoutine.branchZero, hzero, if_false] + · simp only [BinaryRoutine.branchZero, hzero, ite_false] exact (emitPackedFormulaCopy_requires_preserves_forStep _ current hcurrent.1 (writtenNextFormulaPolynomial_eval_pos tm tape _ _)).1) (fun routine hroutine current hcurrent => by simp only [List.mem_ofFn] at hroutine obtain ⟨symbolIndex, rfl⟩ := hroutine by_cases hzero : current Work.position = 0 - · simp only [BinaryRoutine.branchZero, hzero, if_true] + · simp only [BinaryRoutine.branchZero, hzero, ite_true] have hbody := emitPackedFormulaCopy_requires_preserves_forStep (Polynomial.C 1) current hcurrent.1 (by simpa only [Polynomial.eval_C] using Nat.zero_lt_one) exact ⟨hbody.2.1, hbody.2.2.1.trans hcurrent.2.1, hbody.2.2.2.1.trans hcurrent.2.2.1, hbody.2.2.2.2.trans hcurrent.2.2.2⟩ - · simp only [BinaryRoutine.branchZero, hzero, if_false] + · simp only [BinaryRoutine.branchZero, hzero, ite_false] have hbody := emitPackedFormulaCopy_requires_preserves_forStep (writtenNextFormulaPolynomial tm tape (symbolEquiv.symm symbolIndex)) current hcurrent.1 @@ -1177,8 +1161,8 @@ private theorem emitStepWritableTapeCellCopies_requires_preserves_forStep hbody.2.1 _ limit := ?_ } simp only [BinaryRoutine.binaryForStep, Function.update_apply] - rw [if_neg (by decide), hbody.2.2.2.2, - if_neg (by decide), hbody.2.2.2.1] + rw [ite_eq_right (by decide), hbody.2.2.2.2, + ite_eq_right (by decide), hbody.2.2.2.1] exact hcurrent.limit) simp only [BinaryRoutine.seq] refine ⟨⟨hloop.1, trivial⟩, ?_⟩ @@ -1212,8 +1196,8 @@ private theorem emitStepCellTapeCopies_requires_preserves_forStep hbody.2.1 _ limit := ?_ } simp only [BinaryRoutine.binaryForStep, Function.update_apply] - rw [if_neg (by decide), hbody.2.2.2.2, - if_neg (by decide), hbody.2.2.2.1] + rw [ite_eq_right (by decide), hbody.2.2.2.2, + ite_eq_right (by decide), hbody.2.2.2.1] exact hcurrent.limit) simp only [emitStepCellTapeCopies, BinaryRoutine.seq] refine ⟨⟨hloop.1, trivial⟩, ?_⟩ diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Space/Packed.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Space/Packed.lean index 67869cd3..f6b6b559 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Space/Packed.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/Step/Internal/Space/Packed.lean @@ -936,13 +936,13 @@ private theorem cellCopyBody_effect_packed (tm : NTM k) Work.reference₀ 0) Work.temporary₃ 0 := by cases tape with | input => - simpa [stepCellPositionEffectSizeInternal] using - emitStepImmutableCellCopies_effect_internal values + simpa [stepCellPositionEffectSizeInternal] + using! emitStepImmutableCellCopies_effect_internal values | work index => - simpa using emitStepWritableCellCopies_effect_internal tm (.work index) + simpa using! emitStepWritableCellCopies_effect_internal tm (.work index) values | output => - simpa using emitStepWritableCellCopies_effect_internal tm .output values + simpa using! emitStepWritableCellCopies_effect_internal tm .output values private theorem emitStepCellTapeCopies_spaceBoundByWidthAt_packed (tm : NTM k) (tape : TapeSlot k) {initialSpace : ℕ → ℕ} diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/WrittenCell/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/WrittenCell/Internal.lean index 7859e8b7..a6fddd13 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/WrittenCell/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Generator/Transition/WrittenCell/Internal.lean @@ -69,10 +69,10 @@ theorem emitHeadAtCurrentCellGate_requires_internal (stateCount : ℕ) (emitHeadAtCurrentCellGate stateCount).requires values := by by_cases hzero : values Work.temporary₃ = 0 · simp only [emitHeadAtCurrentCellGate, BinaryRoutine.branchZero, hzero, - if_true] + ite_true] exact emitConstantGate_requires_internal false values hemit · simp only [emitHeadAtCurrentCellGate, BinaryRoutine.branchZero, hzero, - if_false] + ite_false] exact emitHeadReference_requires stateCount false values hadd hmultiply hemit @@ -86,7 +86,7 @@ theorem emitHeadAtCurrentCellGate_requires_internal (stateCount : ℕ) · simp [emitHeadAtCurrentCellGate, BinaryRoutine.branchZero, hzero, emitConstantGate, BinaryRoutine.emitRawGateStep] · rw [emitHeadAtCurrentCellGate, BinaryRoutine.branchZero] - simp only [hzero, if_false, emitHeadReference_effect] + simp only [hzero, ite_false, emitHeadReference_effect] funext i simp only [Function.update_apply] split_ifs <;> @@ -784,22 +784,14 @@ private theorem HeadAtCurrentCellClean.writtenCellSelectedValues multiplyCounter := ?_ addCounter := ?_ temporary₀ := ?_ } - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.loop₃ - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.temporary₃ - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.reference₀ - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.emitCounter - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.copyCounter - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.multiplyCounter - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.addCounter - · simpa [writtenCellSelectedValues, Work.tapeIndex, Work.symbolIndex] using - hclean.temporary₀ + · exact hclean.loop₃ + · exact hclean.temporary₃ + · exact hclean.reference₀ + · exact hclean.emitCounter + · exact hclean.copyCounter + · exact hclean.multiplyCounter + · exact hclean.addCounter + · exact hclean.temporary₀ private def writtenCellEffectStartValues (values : BinaryValues WorkCount) : BinaryValues WorkCount := @@ -1025,7 +1017,7 @@ private theorem CaseFormulaClean.updateAvailable_for_writtenCell symbolIndex := ?_ } all_goals simp only [Function.update_apply] - rw [if_neg (by decide)] + rw [ite_eq_right (by decide)] · exact hclean.position · exact hclean.loop₀ · exact hclean.limit₀ @@ -1446,10 +1438,12 @@ private theorem emitWrittenCellFinish_requires (emitRecentGate .and true true 1 1).requires afterHead := by apply (emitRecentGate_requires .and true true 1 1 afterHead).2 refine ⟨?_, ?_, ?_, ?_⟩ - · simpa [afterHead, afterLeft, Work.available] using hcopySelected + · simp [afterHead, afterLeft, Work.available] + exact hcopySelected · simp [afterHead, afterLeft, selected, restored, Work.available] · simp [afterHead, afterLeft, selected, restored, Work.available] - · simpa [afterHead, afterLeft, Work.available] using hemitSelected + · simp [afterHead, afterLeft, Work.available] + exact hemitSelected let afterNegated := (emitRecentGate .and true true 1 1).effect afterHead have hcell : @@ -1524,10 +1518,9 @@ theorem emitWrittenCellFormula_requires_internal (tm : NTM k) hstartAvailable have heffectEffect : (emitWrittenCellEffect tm tape symbol).effect start = afterEffect := by - simpa [afterEffect, effectSize, start, writtenCellEffectStartValues, - Work.available, Work.horizon] using - emitWrittenCellEffect_effect_internal tm tape symbol start hstartClean - hstartAvailable + simp [afterEffect, effectSize, start, writtenCellEffectStartValues, Work.available, + Work.horizon] + exact emitWrittenCellEffect_effect_internal tm tape symbol start hstartClean hstartAvailable have hafterEffectClean : CaseFormulaClean afterEffect := CaseFormulaClean.updateAvailable_for_writtenCell start hstartClean _ have hfinishPosition : @@ -1594,10 +1587,9 @@ theorem emitWrittenCellFormula_effect_internal (tm : NTM k) Work.symbolIndex] have heffectEffect : (emitWrittenCellEffect tm tape symbol).effect start = afterEffect := by - simpa [afterEffect, effectSize, start, writtenCellEffectStartValues, - Work.available, Work.horizon] using - emitWrittenCellEffect_effect_internal tm tape symbol start hstartClean - hstartAvailable + simp [afterEffect, effectSize, start, writtenCellEffectStartValues, Work.available, + Work.horizon] + exact emitWrittenCellEffect_effect_internal tm tape symbol start hstartClean hstartAvailable have hafterEffectClean : CaseFormulaClean afterEffect := CaseFormulaClean.updateAvailable_for_writtenCell start hstartClean _ have hsavedOutputValue : values 26 = 0 := by @@ -1704,10 +1696,9 @@ theorem emitWrittenCellFormula_emitted_internal (tm : NTM k) Work.symbolIndex] have heffectEffect : (emitWrittenCellEffect tm tape symbol).effect start = afterEffect := by - simpa [afterEffect, effectSize, start, writtenCellEffectStartValues, - Work.available, Work.horizon] using - emitWrittenCellEffect_effect_internal tm tape symbol start hstartClean - hstartAvailable + simp [afterEffect, effectSize, start, writtenCellEffectStartValues, Work.available, + Work.horizon] + exact emitWrittenCellEffect_effect_internal tm tape symbol start hstartClean hstartAvailable have heffectEmitted : (emitWrittenCellEffect tm tape symbol).emitted start = (effectFormulaSchedule (transitionCases tm).length @@ -2924,7 +2915,7 @@ private theorem writtenCellFinishRoutines_spaceBoundByWidthAt (fun inputLength => by rw [hleftEffect inputLength] simpa [Work.available, Work.position, Work.tapeIndex, Work.symbolIndex] - using hposition inputLength) + using! hposition inputLength) (fun inputLength => by rw [hleftEffect inputLength] simp [Work.available]) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Padded/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Padded/Internal.lean index ce2d552d..424dba68 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Padded/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Padded/Internal.lean @@ -156,7 +156,7 @@ private theorem eval?_append_dead_padding_copy simp rw [CircuitCode.RawCircuit.eval?] rw [hfullNonempty] - simp only [Bool.false_eq_true, if_false] + simp only [Bool.false_eq_true, ite_false] rw [hfullEval] have hlast : input.length + @@ -187,7 +187,6 @@ theorem paddedDirectUnrollingRawCircuit_eval?_internal (tm.directUnrollingRawCircuit f n).eval? x.toList = some (CircuitUnrolling.boundedAcceptanceBit tm.toNTM (f n) x (fun _ => false)) := by - unfold directUnrollingRawCircuit at hrawEval unfold CircuitUnrolling.boundedAcceptanceBit rw [hirrel] at hrawEval exact hrawEval diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Finalization/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Finalization/Internal.lean index 0c5f86cf..656ac425 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Finalization/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Finalization/Internal.lean @@ -59,7 +59,7 @@ theorem getElem_directFinalizationSuffix_padding_internal rw [length_directFinalizationSuffix_internal] omega) = CircuitCode.RawGate.constant 0 false := by unfold directFinalizationSuffix - rw [List.getElem_append_left] + erw [List.getElem_append_left] exact getElem_directPaddingSchedule_internal originalRawGateCount closedBound index theorem getElem_directFinalizationSuffix_terminal_internal @@ -69,7 +69,7 @@ theorem getElem_directFinalizationSuffix_terminal_internal rw [length_directFinalizationSuffix_internal] omega) = directTerminalCopyGate n originalRawGateCount := by unfold directFinalizationSuffix - rw [List.getElem_append_right] + erw [List.getElem_append_right] · simp [length_directPaddingSchedule_internal] · rw [length_directPaddingSchedule_internal] diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Initialization/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Initialization/Internal.lean index f5ed1f27..d050b0dd 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Initialization/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Initialization/Internal.lean @@ -454,7 +454,7 @@ theorem getElem_directInitSchedule_configIndex_internal rw [List.getElem_append_left] · rw [List.getElem_append_left] · rw [List.getElem_append_left] - · rw [getElem_directInitStateGates_internal] + · erw [getElem_directInitStateGates_internal] rfl · rw [length_directInitStateGates_internal] exact hq diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Case/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Case/Internal.lean index 59e750c7..062df25c 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Case/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Case/Internal.lean @@ -348,7 +348,7 @@ theorem getElem_caseFormulaSchedule_identity_internal simp [caseFormulaScheduleSize, caseFormulaMemberCount] omega) = CircuitCode.RawGate.constant 0 true := by unfold caseFormulaSchedule - rw [List.getElem_append_left (by + erw [List.getElem_append_left (by simp [length_caseFormulaMemberGates_internal])] rw [List.getElem_append_right (by rw [length_caseFormulaMemberGates_internal])] @@ -368,7 +368,7 @@ theorem getElem_caseFormulaSchedule_connector_internal (caseFormulaMemberCount workCount) (caseFormulaSizeAt workCount T choiceValue) rank.val := by unfold caseFormulaSchedule - rw [List.getElem_append_right (by + erw [List.getElem_append_right (by simp [length_caseFormulaMemberGates_internal])] have hindex : caseFormulaMembersSize workCount T choiceValue + 1 + rank.val - (caseFormulaMembersSize workCount T choiceValue + 1) = rank.val := by diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Effect/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Effect/Internal.lean index 833712e8..a4b48518 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Effect/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Effect/Internal.lean @@ -68,7 +68,7 @@ theorem length_effectFormulaCaseBlock_internal effectFormulaSizeAt caseCount workCount T selectedAt choiceAt caseIndex := by unfold effectFormulaCaseBlock effectFormulaSizeAt effectFormulaCaseSize - rw [if_pos hcase] + rw [ite_eq_left hcase] by_cases hselected : selectedAt caseIndex · simp [hselected, length_caseFormulaSchedule] · simp [hselected] @@ -119,7 +119,7 @@ theorem getElem_effectFormulaSchedule_identity_internal simp [effectFormulaScheduleSize] omega) = CircuitCode.RawGate.constant 0 false := by unfold effectFormulaSchedule - rw [List.getElem_append_left] + erw [List.getElem_append_left] · rw [List.getElem_append_right] all_goals simp [length_effectFormulaCaseGates_internal] · simp [length_effectFormulaCaseGates_internal] @@ -143,7 +143,7 @@ theorem getElem_effectFormulaSchedule_connector_internal (effectFormulaSizeAt caseCount workCount T selectedAt choiceAt) rank.val := by unfold effectFormulaSchedule - rw [List.getElem_append_right] + erw [List.getElem_append_right] · have hindex : prefixSize (effectFormulaSizeAt caseCount workCount T selectedAt choiceAt) @@ -277,8 +277,8 @@ private theorem compileRaw_effectFormulaAt effectCaseWorkSymbolIndexAt tm caseIndex := by funext workIndex by_cases hworkIndex : workIndex < k - · simp only [effectCaseWorkSymbolIndexAt, dif_pos hcase, - dif_pos hworkIndex] + · simp only [effectCaseWorkSymbolIndexAt, dite_eq_left hcase, + dite_eq_left hworkIndex] dsimp only [view] · simp [effectCaseWorkSymbolIndexAt, hcase, hworkIndex] rw [hwork] at hcompile diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Internal.lean index 847bf46f..806596a0 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Internal.lean @@ -95,7 +95,7 @@ theorem getElem_readFormulaSchedule_member_internal rw [length_readFormulaMemberBlock_internal] exact offset.isLt) := by unfold readFormulaSchedule - rw [List.getElem_append_left] + erw [List.getElem_append_left] · rw [List.getElem_append_left] exact getElem_readFormulaMemberGates_internal stateCount tapeCount T configBase available tapeIndex symbolIndex position offset @@ -110,7 +110,7 @@ theorem getElem_readFormulaSchedule_identity_internal rw [length_readFormulaSchedule_internal] omega) = CircuitCode.RawGate.constant 0 false := by unfold readFormulaSchedule - rw [List.getElem_append_left] + erw [List.getElem_append_left] · rw [List.getElem_append_right] all_goals simp [length_readFormulaMemberGates_internal] · simp [length_readFormulaMemberGates_internal] @@ -125,7 +125,7 @@ theorem getElem_readFormulaSchedule_connector_internal indexedRightFoldConnector .or available (T + 1) (fixedWidthSizeAt (T + 1) 3) rank.val := by unfold readFormulaSchedule - rw [List.getElem_append_right] + erw [List.getElem_append_right] · simp only [List.length_append, length_readFormulaMemberGates_internal, List.length_singleton] have hindex : @@ -161,7 +161,8 @@ theorem getElem_predecessorHeadMemberGates_internal (fun index => [predecessorHeadMemberGate stateCount T configBase tapeIndex target directionCode index]) (by simp) source.val 0 source.isLt (by omega) - simpa using hget + simp only [Nat.mul_one, Nat.add_zero, List.getElem_cons_zero] at hget + exact hget theorem length_predecessorHeadFormulaSchedule_internal (stateCount T configBase available tapeIndex target directionCode : ℕ) : @@ -181,7 +182,7 @@ theorem getElem_predecessorHeadFormulaSchedule_member_internal predecessorHeadMemberGate stateCount T configBase tapeIndex target directionCode source.val := by unfold predecessorHeadFormulaSchedule - rw [List.getElem_append_left] + erw [List.getElem_append_left] · rw [List.getElem_append_left] exact getElem_predecessorHeadMemberGates_internal stateCount T configBase tapeIndex target directionCode source @@ -196,7 +197,7 @@ theorem getElem_predecessorHeadFormulaSchedule_identity_internal rw [length_predecessorHeadFormulaSchedule_internal] omega) = CircuitCode.RawGate.constant 0 false := by unfold predecessorHeadFormulaSchedule - rw [List.getElem_append_left] + erw [List.getElem_append_left] · rw [List.getElem_append_right] all_goals simp [length_predecessorHeadMemberGates_internal] · simp [length_predecessorHeadMemberGates_internal] @@ -211,7 +212,7 @@ theorem getElem_predecessorHeadFormulaSchedule_connector_internal indexedRightFoldConnector .or available (T + 1) (fixedWidthSizeAt (T + 1) 1) rank.val := by unfold predecessorHeadFormulaSchedule - rw [List.getElem_append_right] + erw [List.getElem_append_right] · simp only [List.length_append, length_predecessorHeadMemberGates_internal, List.length_singleton] have hindex : diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/MovedHead/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/MovedHead/Internal.lean index e1620a3f..464bdc9f 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/MovedHead/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/MovedHead/Internal.lean @@ -223,7 +223,7 @@ theorem getElem_movedHeadMemberBlock_effect_internal change offset < effectFormulaScheduleSize caseCount workCount T (selectedAt directionCode) choiceAt at hoffset unfold movedHeadMemberBlock - rw [List.getElem_append_left (by + erw [List.getElem_append_left (by simp omega)] rw [List.getElem_append_left (by @@ -256,7 +256,7 @@ theorem getElem_movedHeadMemberBlock_predecessor_internal exact hoffset) := by change offset < 2 * (T + 1) + 1 at hoffset unfold movedHeadMemberBlock - rw [List.getElem_append_left (by + erw [List.getElem_append_left (by simp [movedHeadEffectSizeAt] omega)] rw [List.getElem_append_right (by @@ -282,7 +282,7 @@ theorem getElem_movedHeadMemberBlock_conjunction_internal movedHeadConjunctionGate caseCount workCount T available selectedAt choiceAt directionCode := by unfold movedHeadMemberBlock - rw [List.getElem_append_right (by + erw [List.getElem_append_right (by simp [movedHeadEffectSizeAt, movedHeadPredecessorSize])] simp [movedHeadEffectSizeAt, movedHeadPredecessorSize] @@ -317,7 +317,7 @@ theorem getElem_movedHeadFormulaSchedule_identity_internal simp [movedHeadFormulaScheduleSize] omega) = CircuitCode.RawGate.constant 0 false := by unfold movedHeadFormulaSchedule - rw [List.getElem_append_left] + erw [List.getElem_append_left] · rw [List.getElem_append_right] all_goals simp [length_movedHeadMemberGates_internal] · simp [length_movedHeadMemberGates_internal] @@ -342,7 +342,7 @@ theorem getElem_movedHeadFormulaSchedule_connector_internal (movedHeadMemberSizeAt caseCount workCount T selectedAt choiceAt) rank.val := by unfold movedHeadFormulaSchedule - rw [List.getElem_append_right] + erw [List.getElem_append_right] · have hoffset : prefixSize (movedHeadMemberSizeAt caseCount workCount T selectedAt choiceAt) @@ -441,7 +441,7 @@ private theorem size_movedHeadMemberFormulaAt rw [BoolFormula.size] rw [size_effectFormula_eq_scheduleSize_movedHead] rw [size_predecessorHeadFormula_eq_movedHeadPredecessorSize] - rw [movedHeadMemberSizeAt, if_pos hdirection, movedHeadEffectSizeAt] + rw [movedHeadMemberSizeAt, ite_eq_left hdirection, movedHeadEffectSizeAt] rw [movedHeadCaseSelectedAt_eq tm tape directionCode hdirection] private theorem compileRaw_movedHeadMemberFormulaAt @@ -532,8 +532,8 @@ private theorem compileRaw_movedHeadMemberFormulaAt | .left => 0 | .right => 1 | .stay => 2) := by - simpa [memberAvailable, predecessorChild, - movedHeadPredecessorAvailable] using hcompile + simp [memberAvailable, predecessorChild, movedHeadPredecessorAvailable] + exact hcompile _ = _ := congrArg (fun code => predecessorHeadFormulaSchedule (Fintype.card tm.Q) T configBase (movedHeadPredecessorAvailable (transitionCases tm).length k T diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Next/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Next/Internal.lean index 29df2b4c..99acbd89 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Next/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Next/Internal.lean @@ -192,7 +192,7 @@ theorem compileRaw_nextWrittenCellFormula_eq_schedule_internal (effectCaseInputSymbolIndexAt tm) (effectCaseOutputSymbolIndexAt tm) (effectCaseWorkSymbolIndexAt tm) := by cases tape <;> - simp only [WritableSlot.toTapeSlot, nextFormula, hposition, if_false] + simp only [WritableSlot.toTapeSlot, nextFormula, hposition, ite_false] all_goals rw [compileRaw_haltedOrFormula_eq_schedule] all_goals simp only [configVar, BoolFormula.size, BoolFormula.compileRaw] all_goals rw [compileRaw_writtenCellFormula_eq_schedule] diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Polynomial/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Polynomial/Internal.lean index ed2e8f63..3d269843 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Polynomial/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Polynomial/Internal.lean @@ -66,7 +66,7 @@ private theorem eval_list_sum (polynomials : List (Polynomial ℕ)) (T : ℕ) : intro caseIndex hcaseIndex simp only [Function.comp_apply, effectCasePolynomial_eval_internal, effectFormulaSizeAt] - rw [if_pos (List.mem_range.mp hcaseIndex)] + rw [ite_eq_left (List.mem_range.mp hcaseIndex)] rw [hmap] omega diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Step/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Step/Internal.lean index 7faf2439..43d9da3b 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Step/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/Step/Internal.lean @@ -108,6 +108,7 @@ private theorem stepFormulas_eq_ofFn_source stepSourceFormulaAt tm T configBase choiceWire index.val := by simp [stepFormulas, configAtoms, stepSourceFormulaAt, stepConfigAtomAt, stepAtomCount, configWidth, Function.comp_def] + and_intros <;> rfl private theorem size_stepSourceFormulaAt (tm : NTM k) (T configBase choiceWire index : ℕ) @@ -118,7 +119,7 @@ private theorem size_stepSourceFormulaAt (effectCaseChoiceAt tm) index := by unfold stepSourceFormulaAt rw [size_nextFormula_eq_scheduleSize] - simp only [stepFormulaSizeAt, if_pos hindex] + simp only [stepFormulaSizeAt, ite_eq_left hindex] unfold stepAtomKindAt stepAtomEffectSelectedAt rfl diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/WrittenCell/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/WrittenCell/Internal.lean index 37b5fcd9..402608d0 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/WrittenCell/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Serializer/Transition/WrittenCell/Internal.lean @@ -47,7 +47,8 @@ theorem getElem_writtenCellSuffixGates_internal [writtenCellSuffixGate stateCount tapeCount T configBase available tapeIndex position symbolIndex effectSize phase]) (by simp) phase.val 0 phase.isLt (by omega) - simpa using hget + simp only [Nat.mul_one, Nat.add_zero, List.getElem_cons_zero] at hget + exact hget theorem length_writtenCellSchedule_internal (caseCount stateCount workCount T configBase choiceWire available tapeIndex @@ -100,7 +101,7 @@ theorem getElem_writtenCellSchedule_effect_internal rw [length_effectFormulaSchedule] exact offset.isLt) := by unfold writtenCellSchedule - rw [List.getElem_append_right] + erw [List.getElem_append_right] · simp only [List.length_singleton] have hindex : offset.val + 1 - 1 = offset.val := by omega simp only [hindex] @@ -135,7 +136,7 @@ theorem getElem_writtenCellSchedule_suffix_internal configBase choiceWire (available + 1) selectedAt choiceAt stateIndexAt inputSymbolIndexAt outputSymbolIndexAt workSymbolIndexAt unfold writtenCellSchedule - rw [List.getElem_append_right] + erw [List.getElem_append_right] · simp only [List.length_singleton] rw [List.getElem_append_right] · simp only [heffectLength] @@ -174,8 +175,8 @@ private theorem size_writtenCellEffectFormula_eq_effectSize decide ((effect.write tape).toΓ = symbol) have hlength := congrArg List.length (compileRaw_effectFormula_eq_schedule tm T configBase choiceWire 0 selects) - simpa only [BoolFormula.length_compileRaw, length_effectFormulaSchedule] using - hlength + simp only [BoolFormula.length_compileRaw, length_effectFormulaSchedule] at hlength ⊢ + exact hlength theorem compileRaw_writtenCellFormula_eq_schedule_internal (tm : NTM k) (T configBase choiceWire available : ℕ) diff --git a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Stream/Internal.lean b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Stream/Internal.lean index bd60470d..507de4ca 100644 --- a/Complexitylib/Classes/PPoly/Uniform/Unrolling/Stream/Internal.lean +++ b/Complexitylib/Classes/PPoly/Uniform/Unrolling/Stream/Internal.lean @@ -96,7 +96,7 @@ private theorem eraseFormulaVars_effectFormula (tm : NTM k) apply List.map_congr_left intro view _ by_cases hselects : selects view.effect = true - · simp only [Function.comp_apply, if_pos hselects] + · simp only [Function.comp_apply, ite_eq_left hselects] exact eraseFormulaVars_caseFormula tm T base base' choiceWire choiceWire' view · simp [Function.comp_apply, hselects, eraseFormulaVars] diff --git a/Complexitylib/Classes/Randomized/ApproximateCounting/Relative/Internal.lean b/Complexitylib/Classes/Randomized/ApproximateCounting/Relative/Internal.lean index 6344de6a..05b8e939 100644 --- a/Complexitylib/Classes/Randomized/ApproximateCounting/Relative/Internal.lean +++ b/Complexitylib/Classes/Randomized/ApproximateCounting/Relative/Internal.lean @@ -73,11 +73,12 @@ private theorem factorApproximationEvent_subset_successEvent intro seed hseed simp only [Weak.factorApproximationEvent, Finset.mem_filter, Finset.mem_univ, true_and] at hseed - unfold successEvent - apply Finset.mem_filter.mpr - refine ⟨Finset.mem_univ _, ?_⟩ - exact boostedEstimate_cartesianPower_isRelativeApproximation - set hprecision hseed + have hgood : IsRelativeApproximation precision set.card + (hashingEstimate precision failureBits set seed) := + boostedEstimate_cartesianPower_isRelativeApproximation set hprecision hseed + exact (Finset.mem_filter_univ (p := fun seed => + IsRelativeApproximation precision set.card + (hashingEstimate precision failureBits set seed)) seed).mpr hgood private theorem add_four_le_two_pow_add_two (n : ℕ) : n + 4 ≤ 2 ^ (n + 2) := by diff --git a/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Hashing/Internal.lean b/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Hashing/Internal.lean index e39574e8..a4b8ec5c 100644 --- a/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Hashing/Internal.lean +++ b/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Hashing/Internal.lean @@ -56,18 +56,15 @@ private theorem eventProb_levelSeed_mem_eq {domainWidth errorBits : ℕ} rw [uniformProbability_bitString_eq_eventProb] _ = uniformProbability (Finset.univ.filter fun seeds : bundle => seeds level ∈ event) := by - simpa only [bundle, levelSeed] using - uniformProbability_equiv - (hashingSeedEquiv domainWidth errorBits) - (fun seeds => seeds level ∈ event) + simp only [bundle, levelSeed] + exact uniformProbability_equiv (hashingSeedEquiv domainWidth errorBits) (fun seeds => seeds + level ∈ event) _ = uniformProbability (Finset.univ.filter fun seeds : BitString (levelSeedWidth domainWidth errorBits level) × rest => seeds.1 ∈ event) := by - simpa only [bundle, rest] using - uniformProbability_equiv - (Equiv.piSplitAt level fun current : Level domainWidth => - BitString (levelSeedWidth domainWidth errorBits current)) - (fun seeds => seeds.1 ∈ event) + simp only [bundle, rest] + exact uniformProbability_equiv (Equiv.piSplitAt level fun current : Level domainWidth => + BitString (levelSeedWidth domainWidth errorBits current)) (fun seeds => seeds.1 ∈ event) _ = uniformProbability event := by rw [show (Finset.univ.filter fun seeds : BitString (levelSeedWidth domainWidth errorBits level) × rest => @@ -139,7 +136,8 @@ theorem eventProb_badLevelEvent_le_internal omega let hash := PairwiseIndependentHash.affine domainWidth level.val let target : BitString level.val := fun _ => false - let failure := hash.majorityEmptyEvent set target errorBits + let failure : Finset (BitString (levelSeedWidth domainWidth errorBits level)) := + hash.majorityEmptyEvent set target errorBits have hevent : badLevelEvent (errorBits := errorBits) set level = Finset.univ.filter fun seed : BitString (hashingSeedWidth domainWidth errorBits) => @@ -163,7 +161,8 @@ theorem eventProb_badLevelEvent_le_internal · by_cases hsmall : 8 * set.card ≤ 2 ^ level.val · let hash := PairwiseIndependentHash.affine domainWidth level.val let target : BitString level.val := fun _ => false - let success := hash.majorityNonemptyEvent set target errorBits + let success : Finset (BitString (levelSeedWidth domainWidth errorBits level)) := + hash.majorityNonemptyEvent set target errorBits have hevent : badLevelEvent (errorBits := errorBits) set level = Finset.univ.filter fun seed : BitString (hashingSeedWidth domainWidth errorBits) => @@ -268,9 +267,9 @@ private theorem goodHashingEvent_subset_factorApproximationEvent have hcardinality : set.card ≤ 2 ^ domainWidth := by simpa [card_finArrowBool] using Finset.card_le_univ set simp only [goodHashingEvent, Finset.mem_filter, Finset.mem_univ, true_and] at hseed - simp only [factorApproximationEvent, Finset.mem_filter, Finset.mem_univ, true_and, - hashingEstimate] - exact estimate_isFactorApproximation hcardinality hseed + simp only [factorApproximationEvent, hashingEstimate] + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, + estimate_isFactorApproximation hcardinality hseed⟩ theorem one_sub_error_le_eventProb_factorApproximationEvent_internal {domainWidth errorBits : ℕ} (set : Finset (BitString domainWidth)) : diff --git a/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Internal.lean b/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Internal.lean index 6a44458b..1e8b1029 100644 --- a/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Internal.lean +++ b/Complexitylib/Classes/Randomized/ApproximateCounting/Weak/Internal.lean @@ -39,7 +39,7 @@ theorem selectedLevel_mem_trueLevels_internal {domainWidth : ℕ} {responses : Level domainWidth → Bool} (hnonempty : (trueLevels responses).Nonempty) : selectedLevel responses ∈ trueLevels responses := by - simp only [selectedLevel, dif_pos hnonempty] + simp only [selectedLevel, dite_eq_left hnonempty] exact Finset.max'_mem _ _ theorem le_selectedLevel_of_mem_internal {domainWidth : ℕ} @@ -47,7 +47,7 @@ theorem le_selectedLevel_of_mem_internal {domainWidth : ℕ} (hlevel : level ∈ trueLevels responses) : level ≤ selectedLevel responses := by have hnonempty : (trueLevels responses).Nonempty := ⟨level, hlevel⟩ - simp only [selectedLevel, dif_pos hnonempty] + simp only [selectedLevel, dite_eq_left hnonempty] exact Finset.le_max' _ _ hlevel theorem response_selectedLevel_eq_true_of_nonempty_internal {domainWidth : ℕ} @@ -146,7 +146,7 @@ theorem cardinality_le_sixteen_mul_estimate_internal le_selectedLevel_of_mem_internal hlevelMem have hpowLe : 2 ^ logarithm ≤ 2 ^ (selectedLevel responses).val := by apply Nat.pow_le_pow_right (by omega) - simpa [level] using hlevelLe + exact Fin.le_def.mp hlevelLe have hquotientLt : cardinality / 8 < 2 ^ logarithm.succ := by simpa [logarithm] using Nat.lt_pow_succ_log_self (by omega) (cardinality / 8) diff --git a/Complexitylib/Classes/Randomized/CircuitAmplification.lean b/Complexitylib/Classes/Randomized/CircuitAmplification.lean index 7100c332..635b1a2c 100644 --- a/Complexitylib/Classes/Randomized/CircuitAmplification.lean +++ b/Complexitylib/Classes/Randomized/CircuitAmplification.lean @@ -56,7 +56,7 @@ theorem canonicalThresholdValue_eq_blockMajority blockMajority (NTM.repeatAcceptEvent tm x.toList T) seed := by rw [finCountP_canonicalAcceptanceBits_eq_blockEventCount] simp only [strictMajorityThreshold, blockMajority] - rw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] + erw [Bool.eq_iff_iff, decide_eq_true_eq, decide_eq_true_eq] omega /-- The canonical typed amplification circuit computes exactly the compact diff --git a/Complexitylib/Classes/Randomized/Hashing/Affine/Circuit/Internal.lean b/Complexitylib/Classes/Randomized/Hashing/Affine/Circuit/Internal.lean index 68e99e4e..5b0690ea 100644 --- a/Complexitylib/Classes/Randomized/Hashing/Affine/Circuit/Internal.lean +++ b/Complexitylib/Classes/Randomized/Hashing/Affine/Circuit/Internal.lean @@ -115,7 +115,7 @@ private theorem evalAux?_productGates (available width : ℕ) rw [hsize] exact ne_of_lt (hcoefficientRefs i.succ) dsimp only [middle] - rw [Array.getElem?_push, if_neg hne] + rw [Array.getElem?_push, ite_eq_right hne] exact hcoefficients i.succ have hinputTail : ∀ i : Fin width, middle[inputRefs i.succ]? = some (input i.succ) := by @@ -124,7 +124,7 @@ private theorem evalAux?_productGates (available width : ℕ) rw [hsize] exact ne_of_lt (hinputRefs i.succ) dsimp only [middle] - rw [Array.getElem?_push, if_neg hne] + rw [Array.getElem?_push, ite_eq_right hne] exact hinputs i.succ obtain ⟨result, hevalTail, hresultSize, hresultPreserved, hresultProducts⟩ := @@ -146,7 +146,7 @@ private theorem evalAux?_productGates (available width : ℕ) omega rw [hresultPreserved i hiMiddle] dsimp only [middle] - rw [Array.getElem?_push, if_neg (ne_of_lt hi)] + rw [Array.getElem?_push, ite_eq_right (ne_of_lt hi)] · intro coordinate refine Fin.cases ?_ (fun i => ?_) coordinate · have hwire : productWire available (0 : Fin (width + 1)) = @@ -229,7 +229,7 @@ theorem evalAux?_compileLinearRaw_internal (available : ℕ) [NeZero available] · simp only [parityRefs, Fin.lastCases_castSucc, bits, Fin.lastCases_castSucc] exact hmiddleProducts coordinate - letI : NeZero (available + width) := ⟨by + let : NeZero (available + width) := ⟨by have := NeZero.ne available omega⟩ obtain ⟨result, hevalParity, hresultSize, hresultPreserved, @@ -328,7 +328,7 @@ theorem evalAux?_compileRowsRaw_internal rw [hsize] exact hinputRefs coordinate)] exact hinputs coordinate - letI : NeZero (available + linearGateCount width) := ⟨by + let : NeZero (available + linearGateCount width) := ⟨by have := NeZero.ne available omega⟩ have havailableLt : @@ -454,7 +454,7 @@ theorem evalAux?_compileZeroRaw_internal middle[outputs row]? = some (values row) := by intro row exact hmiddleOutputs row - letI : NeZero afterRows := ⟨by + let : NeZero afterRows := ⟨by have := NeZero.ne available simp only [afterRows, rowsAvailable] omega⟩ @@ -481,7 +481,7 @@ theorem evalAux?_compileZeroRaw_internal (rowsAvailable available width rowCount) 1 (rowOutputWire available width)) middle = some almost by simpa only [afterRows, outputs] using hevalThreshold] - simpa only [afterRows, outputs] using hevalCopy + simpa only [Option.bind_some, afterRows, outputs] using hevalCopy · simp only [result, Array.size_push, halmostSize, hafterRows, afterRows, rowsAvailable, hsize, zeroGateCount] omega @@ -647,9 +647,9 @@ theorem eval?_compileZeroRaw_internal rw [BitString.length_toList, zeroOutputWire_eq_internal available width rowCount coefficientRefs inputRefs] rw [CircuitCode.RawCircuit.eval?] - simp only [hnonempty, Bool.false_eq_true, if_false] + simp only [hnonempty, Bool.false_eq_true, ite_false] rw [show input.toList.toArray = wires by rfl, heval, houtputIndex] - simpa only [coefficients, selectedInput] using houtput + exact houtput theorem linearValue_affineRow_internal {domainWidth rangeWidth : ℕ} (seed : BitString (affineSeedWidth domainWidth rangeWidth)) diff --git a/Complexitylib/Classes/Randomized/Hashing/Affine/Internal.lean b/Complexitylib/Classes/Randomized/Hashing/Affine/Internal.lean index a01a8bda..e06dae61 100644 --- a/Complexitylib/Classes/Randomized/Hashing/Affine/Internal.lean +++ b/Complexitylib/Classes/Randomized/Hashing/Affine/Internal.lean @@ -53,7 +53,12 @@ def affineEvalHom {domainWidth rangeWidth : ℕ} exact mul_zero _ map_add' first second := by funext row - simp [affineEval, affineRows, Finset.sum_add_distrib, add_mul] + simp only [affineEval, affineRows, Pi.add_apply] + rw [← Finset.sum_add_distrib] + refine Finset.sum_congr rfl fun column _ => ?_ + show (first (finProdFinEquiv (row, column)) + second (finProdFinEquiv (row, column))) * + affineAugment input column = _ + ring /-- The joint outputs on two inputs form an additive map of the seed. -/ def affinePairEvalHom {domainWidth rangeWidth : ℕ} @@ -191,7 +196,9 @@ theorem affine_uniform_internal {domainWidth rangeWidth : ℕ} (affineEvalHom (rangeWidth := rangeWidth) input) (affineEvalHom_surjective_internal (rangeWidth := rangeWidth) input) output - simpa only [affineEvalHom, card_finArrowBool, Nat.cast_pow, Nat.cast_ofNat] using h + simp only [affineEvalHom, AddMonoidHom.coe_mk, ZeroHom.coe_mk, card_finArrowBool, + Nat.cast_pow, Nat.cast_ofNat] at h + exact h theorem affine_pairwise_internal {domainWidth rangeWidth : ℕ} {first second : BitString domainWidth} (hne : first ≠ second) diff --git a/Complexitylib/Classes/SharpP.lean b/Complexitylib/Classes/SharpP.lean index 0b40bc0f..f14d5e40 100644 --- a/Complexitylib/Classes/SharpP.lean +++ b/Complexitylib/Classes/SharpP.lean @@ -69,12 +69,12 @@ theorem acceptLeafCountFrom_le (tm : NTM n) (c : Cfg n tm.Q) (T : ℕ) : split <;> omega | succ T ih => by_cases hhalt : tm.halted c - · rw [acceptLeafCountFrom, if_pos hhalt, Nat.pow_succ] + · rw [acceptLeafCountFrom, ite_eq_left hhalt, Nat.pow_succ] split · have hpow : 0 < 2 ^ T := by positivity omega · omega - · rw [acceptLeafCountFrom, if_neg hhalt, Nat.pow_succ] + · rw [acceptLeafCountFrom, ite_eq_right hhalt, Nat.pow_succ] have hfalse := ih (tm.trace 1 (fun _ => false) c) have htrue := ih (tm.trace 1 (fun _ => true) c) omega @@ -97,12 +97,12 @@ private theorem acceptLeafCountFrom_add_eq (tm : NTM n) (c : Cfg n tm.Q) cases d with | zero => rfl | succ d => - rw [Nat.zero_add, acceptLeafCountFrom, acceptLeafCountFrom, if_pos hc] + rw [Nat.zero_add, acceptLeafCountFrom, acceptLeafCountFrom, ite_eq_left hc] by_cases hout : c.output.cells 1 = Γ.one <;> simp [hc, hout] | succ T ih => by_cases hc : tm.halted c · rw [show T + 1 + d = (T + d) + 1 by omega] - rw [acceptLeafCountFrom, acceptLeafCountFrom, if_pos hc, if_pos hc] + rw [acceptLeafCountFrom, acceptLeafCountFrom, ite_eq_left hc, ite_eq_left hc] · have hbranch (b : Bool) : ∀ choices : Fin T → Bool, tm.halted @@ -111,7 +111,7 @@ private theorem acceptLeafCountFrom_add_eq (tm : NTM n) (c : Cfg n tm.Q) let choices' : Fin (T + 1) → Bool := Fin.cases b choices simpa [choices', NTM.trace, hc] using hhalt choices' rw [Nat.succ_add] - simp only [acceptLeafCountFrom, hc, if_false] + simp only [acceptLeafCountFrom, hc, ite_false] rw [ih _ (hbranch false), ih _ (hbranch true)] /-- Once every path has halted by `T`, extending the observation clock to any diff --git a/Complexitylib/DescriptiveComplexity/Definable.lean b/Complexitylib/DescriptiveComplexity/Definable.lean index a94aae90..81f0237b 100644 --- a/Complexitylib/DescriptiveComplexity/Definable.lean +++ b/Complexitylib/DescriptiveComplexity/Definable.lean @@ -91,7 +91,7 @@ theorem FODefinable.of_reduces {W : Vocabulary} {Q₁ : BooleanQuery V} obtain ⟨φ, hφ⟩ := hQ₂ refine ⟨I.translate φ, fun A => ?_⟩ rw [hI A, hφ (I.apply A)] - simpa only [Sentence.Models] using I.translate_sat A (emptyEnv A.card) φ + exact I.translate_sat A (emptyEnv A.card) φ /-- FO-definability is closed under first-order projections. -/ theorem FODefinable.of_projReduces {W : Vocabulary} {Q₁ : BooleanQuery V} diff --git a/Complexitylib/DescriptiveComplexity/FirstOrder/Substitution.lean b/Complexitylib/DescriptiveComplexity/FirstOrder/Substitution.lean index d883a420..517d5c2c 100644 --- a/Complexitylib/DescriptiveComplexity/FirstOrder/Substitution.lean +++ b/Complexitylib/DescriptiveComplexity/FirstOrder/Substitution.lean @@ -84,7 +84,7 @@ theorem liftSubst_eval {m n : Nat} (A : FinStruct V) (a : Fin A.card) (σ : Env | zero => simp [liftSubst, Term.eval, envCons] | succ j => have hne : (Fin.succ j).val ≠ 0 := by simp [Fin.val_succ] - simp only [liftSubst, dif_neg hne, Term.shift_eval] + simp only [liftSubst, dite_eq_right hne, Term.shift_eval] simp [envCons, Fin.val_succ] /-- Simultaneous substitution of terms for the free variables of a formula. Under a diff --git a/Complexitylib/DescriptiveComplexity/ModelChecking.lean b/Complexitylib/DescriptiveComplexity/ModelChecking.lean index e4ea575c..341fa617 100644 --- a/Complexitylib/DescriptiveComplexity/ModelChecking.lean +++ b/Complexitylib/DescriptiveComplexity/ModelChecking.lean @@ -71,13 +71,13 @@ theorem Formula.evalB_eq_sat (A : DecFinStruct V) : | disj φ ψ ihφ ihψ => intro σ; simp only [Formula.evalB, Formula.Sat, Bool.or_eq_true, ihφ, ihψ] | exist φ ih => intro σ - rw [Formula.evalB, Formula.Sat, List.any_eq_true] + simp only [Formula.evalB, Formula.Sat, List.any_eq_true] constructor · rintro ⟨a, _, ha⟩; exact ⟨a, (ih _).mp ha⟩ · rintro ⟨a, ha⟩; exact ⟨a, List.mem_finRange a, (ih _).mpr ha⟩ | all φ ih => intro σ - rw [Formula.evalB, Formula.Sat, List.all_eq_true] + simp only [Formula.evalB, Formula.Sat, List.all_eq_true] constructor · intro h a; exact (ih _).mp (h a (List.mem_finRange a)) · intro h a _; exact (ih _).mpr (h a) diff --git a/Complexitylib/DescriptiveComplexity/Reduction.lean b/Complexitylib/DescriptiveComplexity/Reduction.lean index e2cfe518..4ba4d0ce 100644 --- a/Complexitylib/DescriptiveComplexity/Reduction.lean +++ b/Complexitylib/DescriptiveComplexity/Reduction.lean @@ -125,12 +125,10 @@ theorem FOInterpretation.translate_sat (I : FOInterpretation V W) (A : FinStruct | relApp i ts => simp only [FOInterpretation.translate] rw [Formula.subst_sat] - show (I.apply A).rel i _ ↔ _ - rw [FOInterpretation.apply_rel] have henv : (fun j => Term.eval (I.apply A) σ (ts j)) = (fun k => Term.eval A σ (I.translateTerm (ts k))) := by funext k; rw [I.translateTerm_eval] - rw [henv] + exact Iff.of_eq (congrArg (fun e => Formula.Sat A e (I.relFormula i)) henv) | eq t₁ t₂ => simp only [FOInterpretation.translate, Formula.Sat] constructor @@ -200,7 +198,8 @@ theorem FOInterpretation.IsQuantifierFree.quantifierRank_translate (I.translate φ).quantifierRank = φ.quantifierRank := by induction φ with | relApp i ts => - simpa [FOInterpretation.translate, Formula.quantifierRank_subst] using hI i + simpa [FOInterpretation.translate, Formula.quantifierRank_subst, + Formula.quantifierRank] using hI i | eq t₁ t₂ => rfl | neg φ ih => simpa [FOInterpretation.translate, Formula.quantifierRank] using ih diff --git a/Complexitylib/Languages/AnBn.lean b/Complexitylib/Languages/AnBn.lean index 828c86af..041cf0e9 100644 --- a/Complexitylib/Languages/AnBn.lean +++ b/Complexitylib/Languages/AnBn.lean @@ -399,8 +399,8 @@ private theorem anbnTM_step_scanZeros_push have hir : c.input.read = Γ.zero := by rw [inv.read_bit hk, hbit]; rfl have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_one : c.input.read ≠ Γ.one := by rw [hir]; decide - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_pos hir, if_neg hir_ne_one] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_left hir, ite_eq_right hir_ne_one] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · -- input.cells unchanged @@ -475,7 +475,7 @@ private theorem anbnTM_step_scanZeros_halt_empty c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_pos hwr] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ (idleDir c.output.read)).cells 1 = Γ.one @@ -491,7 +491,7 @@ private theorem anbnTM_step_scanZeros_halt_nonempty have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_neg hwr] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_right hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ (idleDir c.output.read)).cells 1 = Γ.zero @@ -508,8 +508,8 @@ private theorem anbnTM_step_scanZeros_reject_at_empty have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_pos hwr] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -534,8 +534,8 @@ private theorem anbnTM_step_scanZeros_pop have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr_ne : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_neg hwr_ne] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_right hwr_ne] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic · show (c.input.move Dir3.right).head = k + 1 + 1 @@ -576,7 +576,7 @@ private theorem anbnTM_step_scanOnes_halt_empty c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_pos hwr] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ _).cells 1 = Γ.one @@ -592,7 +592,7 @@ private theorem anbnTM_step_scanOnes_halt_nonempty have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_neg hwr] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_right hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ _).cells 1 = Γ.zero @@ -607,8 +607,8 @@ private theorem anbnTM_step_scanOnes_reject_zero ∃ c', anbnTM.step c = some c' ∧ RejectInv c' x (k + 1) := by have hir : c.input.read = Γ.zero := by rw [inv.read_bit hk, hbit]; rfl have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_pos hir] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_left hir] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -631,8 +631,8 @@ private theorem anbnTM_step_scanOnes_reject_at_empty have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_pos hwr] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -657,8 +657,8 @@ private theorem anbnTM_step_scanOnes_pop have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr_ne : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_neg hwr_ne] + simp only [TM.step, hst, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_right hwr_ne] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic · show (c.input.move Dir3.right).head = k + 1 + 1 @@ -692,7 +692,7 @@ private theorem anbnTM_step_reject_halt ∃ c', anbnTM.step c = some c' ∧ anbnTM.halted c' ∧ c'.output.cells 1 = Γ.zero := by have hir : c.input.read = Γ.blank := inv.read_blank - simp only [TM.step, inv.st, anbnTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, inv.st, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ _).cells 1 = Γ.zero @@ -707,7 +707,7 @@ private theorem anbnTM_step_reject_consume have hir_bit : c.input.read = Γ.ofBool (x[k]'hk) := inv.read_bit hk have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir_bit]; cases x[k] <;> decide - simp only [TM.step, inv.st, anbnTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank] + simp only [TM.step, inv.st, anbnTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -1060,7 +1060,7 @@ private theorem anbnExpected_scanZeros_eq_one_iff (h : ℕ) (x : List Bool) : private theorem anbnExpected_scanZeros_zero_iff_mem (x : List Bool) : anbnExpected .scanZeros 0 x = .one ↔ x ∈ Language.anbn := by rw [anbnExpected_scanZeros_eq_one_iff] - simp only [Language.anbn, Set.mem_setOf_eq, Nat.zero_add] + simp only [Language.anbn, Set.mem_ofPred_eq, Nat.zero_add] /-- From `scanOnes`, output is always `.zero` or `.one`. -/ private theorem anbnExpected_scanOnes_dichotomy (h : ℕ) (rest : List Bool) : diff --git a/Complexitylib/Languages/Balanced.lean b/Complexitylib/Languages/Balanced.lean index 891c0d5b..819cb077 100644 --- a/Complexitylib/Languages/Balanced.lean +++ b/Complexitylib/Languages/Balanced.lean @@ -72,7 +72,7 @@ instance : Fintype BalancedPhase where /-- Push-down TM deciding the balanced language. One work tape is used as a unary counter. The sign (which bit is in excess) is encoded in the control state; the stack height is the absolute difference. -/ -def balancedTM : TM 1 where +@[expose] def balancedTM : TM 1 where Q := BalancedPhase qstart := .start qhalt := .done @@ -386,7 +386,7 @@ private theorem balancedTM_step_scanExcess0_halt_empty c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_pos hwr] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ (idleDir c.output.read)).cells 1 = Γ.one @@ -402,7 +402,7 @@ private theorem balancedTM_step_scanExcess0_halt_nonempty have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_neg hwr] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_right hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ (idleDir c.output.read)).cells 1 = Γ.zero @@ -417,7 +417,7 @@ private theorem balancedTM_step_scanExcess1_halt_empty c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_pos hwr] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ _).cells 1 = Γ.one @@ -433,7 +433,7 @@ private theorem balancedTM_step_scanExcess1_halt_nonempty have hir : c.input.read = Γ.blank := inv.read_blank have hwr : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_pos hir, if_neg hwr] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir, ite_eq_right hwr] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ _).cells 1 = Γ.zero @@ -450,8 +450,8 @@ private theorem balancedTM_step_scanExcess0_push have hir : c.input.read = Γ.zero := by rw [inv.read_bit hk, hbit]; rfl have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_one : c.input.read ≠ Γ.one := by rw [hir]; decide - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_pos hir, if_neg hir_ne_one] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_left hir, ite_eq_right hir_ne_one] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -488,8 +488,8 @@ private theorem balancedTM_step_scanExcess0_switch have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_pos hwr] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -527,8 +527,8 @@ private theorem balancedTM_step_scanExcess0_pop have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr_ne : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_neg hwr_ne] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_right hwr_ne] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -567,8 +567,8 @@ private theorem balancedTM_step_scanExcess1_push have hir : c.input.read = Γ.one := by rw [inv.read_bit hk, hbit]; rfl have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -605,8 +605,8 @@ private theorem balancedTM_step_scanExcess1_switch have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_one : c.input.read ≠ Γ.one := by rw [hir]; decide have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_one, if_pos hir, if_pos hwr] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_one, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -644,8 +644,8 @@ private theorem balancedTM_step_scanExcess1_pop have hir_ne_one : c.input.read ≠ Γ.one := by rw [hir]; decide have hwr_ne : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_one, if_pos hir, if_neg hwr_ne] + simp only [TM.step, hst, balancedTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_one, ite_eq_left hir, ite_eq_right hwr_ne] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -887,7 +887,7 @@ private theorem balancedExpected_scan_eq_one_iff : induction rest with | nil => intro s h hs - rcases hs with hs | hs <;> subst hs <;> simp only [if_true, if_false, reduceCtorEq] + rcases hs with hs | hs <;> subst hs <;> simp only [ite_true, ite_false, reduceCtorEq] · cases h with | zero => simp [balancedExpected, boolDiff_nil] | succ h' => @@ -904,50 +904,50 @@ private theorem balancedExpected_scan_eq_one_iff : intro s h hs rcases hs with hs | hs <;> subst hs <;> cases b · -- scanExcess0 + false → scanExcess0 (h+1) - simp only [balancedExpected, boolDiff_cons_false, if_true] + simp only [balancedExpected, boolDiff_cons_false, ite_true] rw [ih .scanExcess0 (h + 1) (Or.inl rfl)] - simp only [if_true] + simp only [ite_true] constructor · intro hh; push_cast at hh ⊢; linarith · intro hh; push_cast at hh ⊢; linarith · -- scanExcess0 + true: h=0 switches to scanExcess1 1; h+1 pops to scanExcess0 h cases h with | zero => - simp only [balancedExpected, boolDiff_cons_true, if_true] + simp only [balancedExpected, boolDiff_cons_true, ite_true] rw [ih .scanExcess1 1 (Or.inr rfl)] - simp only [reduceCtorEq, if_false] + simp only [reduceCtorEq, ite_false] push_cast constructor · intro hh; linarith · intro hh; linarith | succ h' => - simp only [balancedExpected, boolDiff_cons_true, if_true] + simp only [balancedExpected, boolDiff_cons_true, ite_true] rw [ih .scanExcess0 h' (Or.inl rfl)] - simp only [if_true] + simp only [ite_true] constructor · intro hh; push_cast at hh ⊢; linarith · intro hh; push_cast at hh ⊢; linarith · -- scanExcess1 + false: h=0 switches to scanExcess0 1; h+1 pops to scanExcess1 h cases h with | zero => - simp only [balancedExpected, boolDiff_cons_false, reduceCtorEq, if_false] + simp only [balancedExpected, boolDiff_cons_false, reduceCtorEq, ite_false] rw [ih .scanExcess0 1 (Or.inl rfl)] - simp only [if_true] + simp only [ite_true] push_cast constructor · intro hh; linarith · intro hh; linarith | succ h' => - simp only [balancedExpected, boolDiff_cons_false, reduceCtorEq, if_false] + simp only [balancedExpected, boolDiff_cons_false, reduceCtorEq, ite_false] rw [ih .scanExcess1 h' (Or.inr rfl)] - simp only [reduceCtorEq, if_false] + simp only [reduceCtorEq, ite_false] constructor · intro hh; push_cast at hh ⊢; linarith · intro hh; push_cast at hh ⊢; linarith · -- scanExcess1 + true → scanExcess1 (h+1) - simp only [balancedExpected, boolDiff_cons_true, reduceCtorEq, if_false] + simp only [balancedExpected, boolDiff_cons_true, reduceCtorEq, ite_false] rw [ih .scanExcess1 (h + 1) (Or.inr rfl)] - simp only [reduceCtorEq, if_false] + simp only [reduceCtorEq, ite_false] constructor · intro hh; push_cast at hh ⊢; linarith · intro hh; push_cast at hh ⊢; linarith @@ -961,8 +961,8 @@ private theorem boolDiff_eq_zero_iff (x : List Bool) : private theorem balancedExpected_zero_iff_mem (x : List Bool) : balancedExpected .scanExcess0 0 x = .one ↔ x ∈ Language.balanced := by rw [balancedExpected_scan_eq_one_iff x .scanExcess0 0 (Or.inl rfl)] - simp only [if_true, Nat.cast_zero, neg_zero, Language.balanced, - Set.mem_setOf_eq] + simp only [ite_true, Nat.cast_zero, neg_zero, Language.balanced, + Set.mem_ofPred_eq] exact boolDiff_eq_zero_iff x /-- The output of `balancedExpected` from any scan state is always `.zero` diff --git a/Complexitylib/Languages/FirstCell.lean b/Complexitylib/Languages/FirstCell.lean index 47302fa4..83a71458 100644 --- a/Complexitylib/Languages/FirstCell.lean +++ b/Complexitylib/Languages/FirstCell.lean @@ -157,7 +157,7 @@ private theorem decideFirstCellTM_step_decide (yesOn : Γ → Bool) simp [idleDir, ho_ns] have h1 : (1 : ℕ) ≠ 0 := by omega simp only [Tape.writeAndMove, ho_move, Tape.move, Tape.write, ho_head, - if_neg h1, Function.update_self, Γw.toΓ] + ite_eq_right h1, Function.update_self, Γw.toΓ] split_ifs <;> rfl -- ════════════════════════════════════════════════════════════════════════ @@ -200,14 +200,14 @@ theorem decideFirstCellTM_decidesInTime {yesOn : Γ → Bool} {L : Language} obtain ⟨c', hreach, hhalt, hout⟩ := decideFirstCellTM_reachesIn (n := 0) yesOn x refine ⟨c', 2, le_refl _, hreach, hhalt, ?_, ?_⟩ · intro hxL - rw [hout, if_pos ((hL x).mp hxL)] + rw [hout, ite_eq_left ((hL x).mp hxL)] · intro hxnL rw [hout] have hy : yesOn (firstCell x) = false := by rcases h : yesOn (firstCell x) with _ | _ · rfl · exact absurd ((hL x).mpr h) hxnL - rw [if_neg (by simp [hy])] + rw [ite_eq_right (by simp [hy])] end TM diff --git a/Complexitylib/Languages/LengthDivBy.lean b/Complexitylib/Languages/LengthDivBy.lean index 8d5cdc40..1573af4a 100644 --- a/Complexitylib/Languages/LengthDivBy.lean +++ b/Complexitylib/Languages/LengthDivBy.lean @@ -60,6 +60,9 @@ end Language /-- The "count bits mod k" fold: starting from `seed`, scanning `x` yields `seed + x.length` in `ZMod k`. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] private theorem lengthDivBy_fold (k : ℕ) [NeZero k] : ∀ (x : List Bool) (seed : ZMod k), x.foldl (fun (s : ZMod k) (_ : Bool) => s + 1) seed = diff --git a/Complexitylib/Languages/LengthParity.lean b/Complexitylib/Languages/LengthParity.lean index 73c0ad89..089085f9 100644 --- a/Complexitylib/Languages/LengthParity.lean +++ b/Complexitylib/Languages/LengthParity.lean @@ -133,7 +133,7 @@ private theorem evenLengthTM_step_scan c'.input.head = c.input.head + 1 ∧ c'.input.cells = c.input.cells ∧ c'.output.head = 1 ∧ c'.output.cells = c.output.cells := by rcases hP with hP | hP <;> subst hP <;> - simp only [TM.step, hst, evenLengthTM, reduceCtorEq, ↓reduceIte, if_neg hi_nb] + simp only [TM.step, hst, evenLengthTM, reduceCtorEq, ↓reduceIte, ite_eq_right hi_nb] all_goals have ho_move : idleDir c.output.read = Dir3.stay := by simp [idleDir, Tape.read, ho_head, show c.output.cells 1 ≠ Γ.start from @@ -155,13 +155,13 @@ private theorem evenLengthTM_step_halt_even ∃ c', (evenLengthTM (n := n)).step c = some c' ∧ (evenLengthTM (n := n)).halted c' ∧ c'.output.cells 1 = Γ.one := by - simp only [TM.step, hst, evenLengthTM, reduceCtorEq, ↓reduceIte, if_pos hi_blank] + simp only [TM.step, hst, evenLengthTM, reduceCtorEq, ↓reduceIte, ite_eq_left hi_blank] refine ⟨_, rfl, rfl, ?_⟩ have ho_move : idleDir c.output.read = Dir3.stay := by simp [idleDir, Tape.read, ho_head, show c.output.cells 1 ≠ Γ.start from ho_cell1_nb] have h1 : (1 : ℕ) ≠ 0 := by omega simp only [Tape.writeAndMove, ho_move, Tape.move, Tape.write, ho_head, - if_neg h1, Function.update_self, Γw.toΓ] + ite_eq_right h1, Function.update_self, Γw.toΓ] /-- Halt step: from `.odd` on blank input, writes `Γ.zero` at output cell 1. -/ private theorem evenLengthTM_step_halt_odd @@ -172,13 +172,13 @@ private theorem evenLengthTM_step_halt_odd ∃ c', (evenLengthTM (n := n)).step c = some c' ∧ (evenLengthTM (n := n)).halted c' ∧ c'.output.cells 1 = Γ.zero := by - simp only [TM.step, hst, evenLengthTM, reduceCtorEq, ↓reduceIte, if_pos hi_blank] + simp only [TM.step, hst, evenLengthTM, reduceCtorEq, ↓reduceIte, ite_eq_left hi_blank] refine ⟨_, rfl, rfl, ?_⟩ have ho_move : idleDir c.output.read = Dir3.stay := by simp [idleDir, Tape.read, ho_head, show c.output.cells 1 ≠ Γ.start from ho_cell1_nb] have h1 : (1 : ℕ) ≠ 0 := by omega simp only [Tape.writeAndMove, ho_move, Tape.move, Tape.write, ho_head, - if_neg h1, Function.update_self, Γw.toΓ] + ite_eq_right h1, Function.update_self, Γw.toΓ] -- ════════════════════════════════════════════════════════════════════════ -- Main scan lemma @@ -210,13 +210,13 @@ private theorem evenLengthTM_scan (x : List Bool) (m k : ℕ) show (Tape.init (x.map Γ.ofBool)).cells (k + 1) = Γ.blank simp [Tape.init, hk] by_cases hpar : k % 2 = 0 - · have hst_even : c.state = LengthParityPhase.even := by rw [hst, if_pos hpar] + · have hst_even : c.state = LengthParityPhase.even := by rw [hst, ite_eq_left hpar] obtain ⟨c', hstep, hhalt, hout⟩ := evenLengthTM_step_halt_even c hst_even hi_blank hoh hoc refine ⟨c', .step hstep .zero, hhalt, ?_⟩ rw [hout, hk] at * simp [hpar] - · have hst_odd : c.state = LengthParityPhase.odd := by rw [hst, if_neg hpar] + · have hst_odd : c.state = LengthParityPhase.odd := by rw [hst, ite_eq_right hpar] obtain ⟨c', hstep, hhalt, hout⟩ := evenLengthTM_step_halt_odd c hst_odd hi_blank hoh hoc refine ⟨c', .step hstep .zero, hhalt, ?_⟩ @@ -239,13 +239,13 @@ private theorem evenLengthTM_scan (x : List Bool) (m k : ℕ) have hlen' : x.length = (k + 1) + m := by omega by_cases hpar : k % 2 = 0 · -- state = .even, after scan = .odd - have hst_eo : c.state = LengthParityPhase.even := by rw [hst, if_pos hpar] + have hst_eo : c.state = LengthParityPhase.even := by rw [hst, ite_eq_left hpar] obtain ⟨c₁, hstep, hst₁, hih₁, hic₁, hoh₁, hoc₁⟩ := evenLengthTM_step_scan c LengthParityPhase.even (Or.inl rfl) hst_eo hi_nb hoh hoc have hst₁' : c₁.state = if (k + 1) % 2 = 0 then LengthParityPhase.even else LengthParityPhase.odd := by have h1 : (k + 1) % 2 ≠ 0 := by omega - rw [hst₁, if_pos rfl]; simp [h1] + rw [hst₁, ite_eq_left rfl]; simp [h1]; rfl have hic₁' : c₁.input.cells = (Tape.init (x.map Γ.ofBool)).cells := by rw [hic₁, hic] have hih₁' : c₁.input.head = (k + 1) + 1 := by rw [hih₁, hih] have hoc₁' : c₁.output.cells 1 ≠ Γ.start := by rw [hoc₁]; exact hoc @@ -253,14 +253,15 @@ private theorem evenLengthTM_scan (x : List Bool) (m k : ℕ) ih (k + 1) hlen' c₁ hst₁' hic₁' hih₁' hoh₁ hoc₁' exact ⟨c', .step hstep hreach', hhalt', hout'⟩ · -- state = .odd, after scan = .even - have hst_eo : c.state = LengthParityPhase.odd := by rw [hst, if_neg hpar] + have hst_eo : c.state = LengthParityPhase.odd := by rw [hst, ite_eq_right hpar] obtain ⟨c₁, hstep, hst₁, hih₁, hic₁, hoh₁, hoc₁⟩ := evenLengthTM_step_scan c LengthParityPhase.odd (Or.inr rfl) hst_eo hi_nb hoh hoc have hst₁' : c₁.state = if (k + 1) % 2 = 0 then LengthParityPhase.even else LengthParityPhase.odd := by have h1 : (k + 1) % 2 = 0 := by omega - rw [hst₁, if_neg (by decide : LengthParityPhase.odd ≠ LengthParityPhase.even)] + rw [hst₁, ite_eq_right (by decide : LengthParityPhase.odd ≠ LengthParityPhase.even)] simp [h1] + rfl have hic₁' : c₁.input.cells = (Tape.init (x.map Γ.ofBool)).cells := by rw [hic₁, hic] have hih₁' : c₁.input.head = (k + 1) + 1 := by rw [hih₁, hih] have hoc₁' : c₁.output.cells 1 ≠ Γ.start := by rw [hoc₁]; exact hoc @@ -314,7 +315,7 @@ end Language theorem oddLength_eq_compl_evenLength : Language.oddLength = Language.evenLengthᶜ := by ext x - simp only [Language.evenLength, Language.oddLength, Set.mem_setOf_eq, + simp only [Language.evenLength, Language.oddLength, Set.mem_ofPred_eq, Set.mem_compl_iff] omega @@ -330,10 +331,10 @@ theorem evenLengthTM_decidesInTime : refine ⟨c', x.length + 2, le_refl _, hreach, hhalt, ?_, ?_⟩ · intro hxL have : x.length % 2 = 0 := hxL - rw [hout, if_pos this] + rw [hout, ite_eq_left this] · intro hxnL have : x.length % 2 ≠ 0 := hxnL - rw [hout, if_neg this] + rw [hout, ite_eq_right this] -- ════════════════════════════════════════════════════════════════════════ -- DTIME memberships diff --git a/Complexitylib/Languages/Palindromes.lean b/Complexitylib/Languages/Palindromes.lean index 38463689..ef690834 100644 --- a/Complexitylib/Languages/Palindromes.lean +++ b/Complexitylib/Languages/Palindromes.lean @@ -513,7 +513,7 @@ private theorem palindromesTM_step_copy_push have hir_ne_start : c.input.read ≠ Γ.start := by rw [hib]; cases x[k] <;> decide simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, - if_neg hir_ne_blank, if_neg hir_ne_start] + ite_eq_right hir_ne_blank, ite_eq_right hir_ne_start] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨by omega, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _ @@ -584,7 +584,7 @@ private theorem palindromesTM_step_copy_end ∃ c', palindromesTM.step c = some c' ∧ c'.state = PalindromePhase.rewindInput ∧ RewindInv c' x x.length := by have hir : c.input.read = Γ.blank := inv.read_blank - simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay have hwread : (c.work 0).read = Γ.blank := inv.work_read @@ -636,7 +636,7 @@ private theorem palindromesTM_step_rewindInput_consume have : c.input.cells j ≠ Γ.start := inv.input_ns j hj exact this simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, - if_neg hir_ne_start] + ite_eq_right hir_ne_start] refine ⟨_, rfl, rfl, ?_⟩ have hml : moveLeftDir c.input.read = Dir3.left := by simp [moveLeftDir, hir_ne_start] @@ -678,7 +678,7 @@ private theorem palindromesTM_step_rewindInput_finish have hir : c.input.read = Γ.start := by simp only [Tape.read, inv.ih, inv.ic] simp [Tape.init] - simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hwread : (c.work 0).read = Γ.blank := inv.work_read have hwread_ne : (c.work 0).read ≠ Γ.start := by rw [hwread]; decide @@ -731,7 +731,7 @@ private theorem palindromesTM_step_compare_match show c.input.read = (c.work 0).read exact hir_eq_wr simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, - if_neg hir_ne_blank, if_neg hir_ne_start, if_pos hir_eq] + ite_eq_right hir_ne_blank, ite_eq_right hir_ne_start, ite_eq_left hir_eq] refine ⟨_, rfl, rfl, ?_⟩ have hwr_ne_start : (c.work 0).read ≠ Γ.start := by rw [hwr]; cases x[x.length-k-1] <;> decide @@ -785,7 +785,7 @@ private theorem palindromesTM_step_compare_mismatch simp [hb1, hb2, Γ.ofBool] at h ⊢ have hir_ne : c.input.read ≠ (fun i : Fin 1 => (c.work i).read) 0 := hir_ne_wr simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, - if_neg hir_ne_blank, if_neg hir_ne_start, if_neg hir_ne] + ite_eq_right hir_ne_blank, ite_eq_right hir_ne_start, ite_eq_right hir_ne] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -805,7 +805,7 @@ private theorem palindromesTM_step_compare_halt ∃ c', palindromesTM.step c = some c' ∧ palindromesTM.halted c' ∧ c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_input_blank - simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, hst, palindromesTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hostay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ _).cells 1 = Γ.one @@ -821,7 +821,7 @@ private theorem palindromesTM_step_reject_consume have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir_bit]; cases x[j] <;> decide simp only [TM.step, inv.st, palindromesTM, reduceCtorEq, ↓reduceIte, - if_neg hir_ne_blank] + ite_eq_right hir_ne_blank] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -840,7 +840,7 @@ private theorem palindromesTM_step_reject_halt ∃ c', palindromesTM.step c = some c' ∧ palindromesTM.halted c' ∧ c'.output.cells 1 = Γ.zero := by have hir : c.input.read = Γ.blank := inv.read_blank - simp only [TM.step, inv.st, palindromesTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, inv.st, palindromesTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hostay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ _).cells 1 = Γ.zero @@ -901,7 +901,7 @@ private theorem palindromesTM_compare_to_halt (x : List Bool) : have htriv : ∀ i, (hi : i < x.length) → x.length ≤ i → (x[i]'hi) = (x[x.length - 1 - i]'(by omega)) := by intro i hi hle; exfalso; omega - rw [if_pos htriv] + rw [ite_eq_left htriv] | succ m' ih => intro k c hst inv hlen have hk : k < x.length := by omega @@ -927,13 +927,13 @@ private theorem palindromesTM_compare_to_halt (x : List Bool) : by_cases hik : i = k · subst hik; exact hmatch' · exact hP i hi (by omega) - rw [if_pos hP, if_pos hPk] + rw [ite_eq_left hP, ite_eq_left hPk] · -- Neither have hPk : ¬ ∀ i, (hi : i < x.length) → k ≤ i → (x[i]'hi) = (x[x.length - 1 - i]'(by omega)) := by intro hP'; apply hP intro i hi hle; exact hP' i hi (by omega) - rw [if_neg hP, if_neg hPk] + rw [ite_eq_right hP, ite_eq_right hPk] · -- Mismatch: transition to reject, then reject-to-halt have hmis : (x[k]'hk) ≠ (x[x.length - k - 1]'(by omega)) := hmatch obtain ⟨c₁, hstep, inv₁⟩ := @@ -951,7 +951,7 @@ private theorem palindromesTM_compare_to_halt (x : List Bool) : (x[i]'hi) = (x[x.length - 1 - i]'(by omega)) := by intro hP exact hmis' (hP k hk le_rfl) - rw [if_neg hPk] + rw [ite_eq_right hPk] /-- Rewind input phase: from `RewindInv c x j`, reach `CompareInv c' x 0` in `j + 1` steps. -/ @@ -1121,12 +1121,12 @@ theorem palindromesTM_decidesInTime : rw [hout] have hpal : IsPalindrome x := (isPalindrome_iff_reverse_eq x).mpr hxL - exact if_pos hpal + exact ite_eq_left hpal · intro hxnL rw [hout] have hnot : ¬ IsPalindrome x := fun h => hxnL ((isPalindrome_iff_reverse_eq x).mp h) - exact if_neg hnot + exact ite_eq_right hnot end TM diff --git a/Complexitylib/Languages/ZeroPrefix.lean b/Complexitylib/Languages/ZeroPrefix.lean index 26d3024c..86b0a3c8 100644 --- a/Complexitylib/Languages/ZeroPrefix.lean +++ b/Complexitylib/Languages/ZeroPrefix.lean @@ -72,7 +72,7 @@ instance : Fintype ZeroPrefixPhase where detected by reading `▷` at cell 0). End-of-input is accepted in both scan states — reaching a blank means we consumed the input without a mismatch, so `n ≥ m`. -/ -def zeroPrefixTM : TM 1 where +@[expose] def zeroPrefixTM : TM 1 where Q := ZeroPrefixPhase qstart := .start qhalt := .done @@ -383,8 +383,8 @@ private theorem zeroPrefixTM_step_scanZeros_push have hir : c.input.read = Γ.zero := by rw [inv.read_bit hk, hbit]; rfl have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_one : c.input.read ≠ Γ.one := by rw [hir]; decide - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_pos hir, if_neg hir_ne_one] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_left hir, ite_eq_right hir_ne_one] refine ⟨_, rfl, rfl, ?_⟩ refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -451,7 +451,7 @@ private theorem zeroPrefixTM_step_scanZeros_halt ∃ c', zeroPrefixTM.step c = some c' ∧ zeroPrefixTM.halted c' ∧ c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_blank - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ (idleDir c.output.read)).cells 1 = Γ.one @@ -468,8 +468,8 @@ private theorem zeroPrefixTM_step_scanZeros_reject_at_empty have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_pos hwr] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -494,8 +494,8 @@ private theorem zeroPrefixTM_step_scanZeros_pop have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr_ne : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_neg hwr_ne] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_right hwr_ne] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic · show (c.input.move Dir3.right).head = k + 1 + 1 @@ -530,7 +530,7 @@ private theorem zeroPrefixTM_step_scanOnes_halt ∃ c', zeroPrefixTM.step c = some c' ∧ zeroPrefixTM.halted c' ∧ c'.output.cells 1 = Γ.one := by have hir : c.input.read = Γ.blank := inv.read_blank - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.one.toΓ _).cells 1 = Γ.one @@ -545,8 +545,8 @@ private theorem zeroPrefixTM_step_scanOnes_reject_zero ∃ c', zeroPrefixTM.step c = some c' ∧ RejectInv c' x (k + 1) := by have hir : c.input.read = Γ.zero := by rw [inv.read_bit hk, hbit]; rfl have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_pos hir] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_left hir] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -569,8 +569,8 @@ private theorem zeroPrefixTM_step_scanOnes_reject_at_empty have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir]; decide have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr : (c.work 0).read = Γ.start := inv.work_read_start_iff.mpr rfl - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_pos hwr] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_left hwr] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic @@ -595,8 +595,8 @@ private theorem zeroPrefixTM_step_scanOnes_pop have hir_ne_zero : c.input.read ≠ Γ.zero := by rw [hir]; decide have hwr_ne : (c.work 0).read ≠ Γ.start := by simp only [ne_eq, inv.work_read_start_iff]; omega - simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank, - if_neg hir_ne_zero, if_pos hir, if_neg hwr_ne] + simp only [TM.step, hst, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank, + ite_eq_right hir_ne_zero, ite_eq_left hir, ite_eq_right hwr_ne] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic · show (c.input.move Dir3.right).head = k + 1 + 1 @@ -630,7 +630,7 @@ private theorem zeroPrefixTM_step_reject_halt ∃ c', zeroPrefixTM.step c = some c' ∧ zeroPrefixTM.halted c' ∧ c'.output.cells 1 = Γ.zero := by have hir : c.input.read = Γ.blank := inv.read_blank - simp only [TM.step, inv.st, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_pos hir] + simp only [TM.step, inv.st, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_left hir] refine ⟨_, rfl, rfl, ?_⟩ have hstay := inv.output_stay show (c.output.writeAndMove Γw.zero.toΓ _).cells 1 = Γ.zero @@ -645,7 +645,7 @@ private theorem zeroPrefixTM_step_reject_consume have hir_bit : c.input.read = Γ.ofBool (x[k]'hk) := inv.read_bit hk have hir_ne_blank : c.input.read ≠ Γ.blank := by rw [hir_bit]; cases x[k] <;> decide - simp only [TM.step, inv.st, zeroPrefixTM, reduceCtorEq, ↓reduceIte, if_neg hir_ne_blank] + simp only [TM.step, inv.st, zeroPrefixTM, reduceCtorEq, ↓reduceIte, ite_eq_right hir_ne_blank] refine ⟨_, rfl, ?_, ?_, ?_, ?_, ?_⟩ · rfl · show (c.input.move Dir3.right).cells = _; rw [Tape.move_cells]; exact inv.ic diff --git a/Complexitylib/Mathlib/Digraph.lean b/Complexitylib/Mathlib/Digraph.lean index 080e0f8d..6214654a 100644 --- a/Complexitylib/Mathlib/Digraph.lean +++ b/Complexitylib/Mathlib/Digraph.lean @@ -7,7 +7,7 @@ Authors: Samuel Schlesinger module public import Mathlib.Combinatorics.Digraph.Basic public import Mathlib.Data.Fintype.Prod -public import Mathlib.Data.Nat.Lattice +public import Mathlib.Order.Lattice.Nat public import Std.Tactic.BVDecide.Normalize.Prop /-! # Digraph extensions for Mathlib diff --git a/Complexitylib/Mathlib/NatBits.lean b/Complexitylib/Mathlib/NatBits.lean index b3272c9c..65dce237 100644 --- a/Complexitylib/Mathlib/NatBits.lean +++ b/Complexitylib/Mathlib/NatBits.lean @@ -97,7 +97,7 @@ theorem Nat.toBits_fromBits : ∀ bits : List Bool, Nat.fromBits rest + (if bit then 1 else 0) * 2 ^ rest.length := by simp only [Nat.fromBits] exact Nat.add_comm _ _ - simp only [Nat.toBits, List.cons.injEq] + simp only [List.length_cons, Nat.toBits, List.cons.injEq] constructor · rw [hval, Nat.add_mul_div_right _ _ (Nat.two_pow_pos _), Nat.div_eq_of_lt hlt] cases bit <;> simp @@ -249,7 +249,7 @@ width. -/ lt_of_lt_of_le index.isLt (Nat.le_pow_clog Nat.one_lt_two size) unfold Fin.fromBits? - rw [Fin.length_toBits, dif_pos rfl] + rw [Fin.length_toBits, dite_eq_left rfl] simp only [Fin.toBits] simp [Nat.fromBits_toBits hfits, index.isLt] diff --git a/Complexitylib/Metacomplexity/BooleanDependency/Internal.lean b/Complexitylib/Metacomplexity/BooleanDependency/Internal.lean index 7d4f1977..be83f6fa 100644 --- a/Complexitylib/Metacomplexity/BooleanDependency/Internal.lean +++ b/Complexitylib/Metacomplexity/BooleanDependency/Internal.lean @@ -42,7 +42,7 @@ theorem uniformProbability_restrict_internal {coordinate : Type*} event sample.1) = uniformProbability (Finset.univ.filter event) := by simpa [uniformProbability_univ_internal] using hproduct - simpa [assignmentSplitEquiv] using htransport.trans hproduct' + exact htransport.trans hproduct' theorem extendByFalse_restrict_apply_internal {coordinate : Type*} [DecidableEq coordinate] (coordinates : Finset coordinate) diff --git a/Complexitylib/Metacomplexity/Hamming/Existence/Internal.lean b/Complexitylib/Metacomplexity/Hamming/Existence/Internal.lean index 0f8d410c..c14fae6f 100644 --- a/Complexitylib/Metacomplexity/Hamming/Existence/Internal.lean +++ b/Complexitylib/Metacomplexity/Hamming/Existence/Internal.lean @@ -27,15 +27,16 @@ private theorem isSeparated_insert IsSeparated (insert word code) minimumDistance := by unfold IsSeparated rw [Finset.coe_insert] - apply (Set.pairwise_insert_of_symmetric_of_notMem + have hsymm : Std.Symm (fun left right : Word length => + minimumDistance ≤ distance left right) := by + refine ⟨fun {left right} hdistance => ?_⟩ + rw [distance_comm_internal] + exact hdistance + exact (Set.pairwise_insert_of_symm_of_notMem (r := fun left right : Word length => minimumDistance ≤ distance left right) (a := word) (s := (code : Set (Word length))) - ?_ (by simpa using hword)).2 - · exact ⟨hcode, hfar⟩ - · intro left right hdistance - rw [distance_comm_internal] - exact hdistance + (by simpa using hword)).2 ⟨hcode, hfar⟩ theorem exists_isSeparated_and_covering_internal (length minimumDistance : ℕ) : @@ -49,7 +50,8 @@ theorem exists_isSeparated_and_covering_internal Finset.univ.filter fun code => IsSeparated code minimumDistance have hfamily : family.Nonempty := by refine ⟨∅, ?_⟩ - simp [family, IsSeparated] + refine Finset.mem_filter.mpr ⟨Finset.mem_univ _, ?_⟩ + simp [IsSeparated] obtain ⟨code, hcodeFamily, hmaximum⟩ := Finset.exists_max_image family Finset.card hfamily have hcode : IsSeparated code minimumDistance := by diff --git a/Complexitylib/Metacomplexity/Kolmogorov/Defs.lean b/Complexitylib/Metacomplexity/Kolmogorov/Defs.lean index b1c8df8d..67dc9221 100644 --- a/Complexitylib/Metacomplexity/Kolmogorov/Defs.lean +++ b/Complexitylib/Metacomplexity/Kolmogorov/Defs.lean @@ -8,7 +8,7 @@ module public import Complexitylib.Models.TuringMachine.Universality.Defs public import Mathlib.Data.List.Infix public import Mathlib.Data.Nat.Cast.WithTop -public import Mathlib.Data.Nat.Lattice +public import Mathlib.Order.Lattice.Nat /-! # Machine-relative Kolmogorov complexity diff --git a/Complexitylib/Metacomplexity/Kolmogorov/Depth/Internal.lean b/Complexitylib/Metacomplexity/Kolmogorov/Depth/Internal.lean index f28741c2..1a4bd54a 100644 --- a/Complexitylib/Metacomplexity/Kolmogorov/Depth/Internal.lean +++ b/Complexitylib/Metacomplexity/Kolmogorov/Depth/Internal.lean @@ -97,7 +97,9 @@ theorem descriptionDifference_eq_top_iff_internal | coe upper => induction lower using WithTop.recTopCoe with | top => simp at horder - | coe lower => simp [descriptionDifference] + | coe lower => + simp only [descriptionDifference, WithTop.recTopCoe_coe] + exact iff_of_false WithTop.coe_ne_top WithTop.coe_ne_top theorem descriptionDifference_eq_zero_iff_internal {upper lower : WithTop ℕ} (horder : lower ≤ upper) @@ -124,7 +126,7 @@ theorem descriptionDifference_eq_zero_iff_internal · intro heq apply WithTop.coe_eq_coe.mpr have hvalues : upperValue = lowerValue := by - exact_mod_cast heq + exact WithTop.coe_injective heq simp [hvalues] theorem descriptionDifference_add_internal @@ -151,10 +153,8 @@ theorem descriptionDifference_add_internal have hidentity : (upper - middle) + (middle - lower) = upper - lower := by omega - exact_mod_cast hidentity - + exact congrArg (Nat.cast (R := WithTop ℕ)) hidentity namespace TM - variable {n : ℕ} theorem computationalDepthBetween_add_later_internal diff --git a/Complexitylib/Metacomplexity/Kolmogorov/Internal.lean b/Complexitylib/Metacomplexity/Kolmogorov/Internal.lean index 6df8c8af..f9b8e884 100644 --- a/Complexitylib/Metacomplexity/Kolmogorov/Internal.lean +++ b/Complexitylib/Metacomplexity/Kolmogorov/Internal.lean @@ -199,7 +199,7 @@ theorem simulates_plainKolmogorovComplexity_le_add_internal have hcompiled := plainKolmogorovComplexity_le_internal ((hsim.produces_iff program output).mpr hproduce) rw [← hprogramLength] - simpa using hcompiled.trans (WithTop.coe_le_coe.mpr (hlength program)) + exact hcompiled.trans (WithTop.coe_le_coe.mpr (hlength program)) theorem polynomialTimeOverhead_kolmogorov_transfer_internal {simulator : TM simulatorTapes} {source : TM sourceTapes} @@ -236,7 +236,7 @@ theorem IsUniversal.plainKolmogorovComplexity_ne_top_internal huniversal 0 (copyInputToOutputTM (n := 0)) have hsource : (copyInputToOutputTM (n := 0)).ProducesInTime output output (output.length + 2) := by - simpa using (copyInputToOutputTM_computesInTime 0 output) + simpa [TM.ProducesInTime] using (copyInputToOutputTM_computesInTime 0 output) have hcompiled : simulator.Produces (compile output) output := (hsimulates.produces_iff output output).mpr (produces_of_producesInTime hsource) @@ -252,7 +252,7 @@ theorem IsUniversal.exists_timeBoundedKolmogorovComplexity_ne_top_internal huniversal 0 (copyInputToOutputTM (n := 0)) have hsource : (copyInputToOutputTM (n := 0)).ProducesInTime output output (output.length + 2) := by - simpa using (copyInputToOutputTM_computesInTime 0 output) + simpa [TM.ProducesInTime] using (copyInputToOutputTM_computesInTime 0 output) have hcompiled : simulator.Produces (compile output) output := (hsimulates.produces_iff output output).mpr (produces_of_producesInTime hsource) @@ -278,7 +278,7 @@ theorem IsEfficientlyUniversal.timeBoundedKolmogorovComplexity_printer_internal intro output time htime have hsource : (copyInputToOutputTM (n := 0)).ProducesInTime output output (output.length + 2) := by - simpa using (copyInputToOutputTM_computesInTime 0 output) + simpa [TM.ProducesInTime] using (copyInputToOutputTM_computesInTime 0 output) have hcompiled := htimed.produces output output (output.length + 2) hsource have hclockBound := hclock output (output.length + 2) have harg : output.length + (output.length + 2) + 1 = diff --git a/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Defs.lean b/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Defs.lean index c8d9a2e3..857e3efd 100644 --- a/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Defs.lean +++ b/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Defs.lean @@ -7,7 +7,7 @@ Authors: Samuel Schlesinger module public import Complexitylib.Models.TuringMachine.Oracle.OutputSemantics.Defs public import Mathlib.Data.Nat.Cast.WithTop -public import Mathlib.Data.Nat.Lattice +public import Mathlib.Order.Lattice.Nat /-! # Oracle-relative Kolmogorov complexity -- definitions diff --git a/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Internal.lean b/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Internal.lean index 9e9e8b67..583329fc 100644 --- a/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Internal.lean +++ b/Complexitylib/Metacomplexity/Kolmogorov/Oracle/Internal.lean @@ -157,7 +157,7 @@ theorem toOracleTM_timeBoundedKolmogorovComplexity_eq_internal congr 2 ext size simp only [OracleTM.timeBoundedProducingProgramSizes, - TM.timeBoundedProducingProgramSizes, Set.mem_setOf_eq] + TM.timeBoundedProducingProgramSizes, Set.mem_ofPred_eq] constructor · rintro ⟨program, hlength, hproduce⟩ exact ⟨program, hlength, diff --git a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/FixedWidth/Internal.lean b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/FixedWidth/Internal.lean index c929519f..acca4b0b 100644 --- a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/FixedWidth/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/FixedWidth/Internal.lean @@ -161,7 +161,8 @@ theorem card_validDescription_eq_candidateCodes_internal Fintype.card_congr (candidateCodeFixedWidthEquivInternal arity threshold).symm _ = (candidateCodes arity threshold).card := by - simp [CandidateCode] + simp only [CandidateCode] + exact Fintype.card_coe _ theorem fixedWidth_codeWidth_le_codeLengthBound_internal (arity threshold : Nat) : diff --git a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/Internal.lean b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/Internal.lean index ac121d46..1e364fe8 100644 --- a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Enumeration/Internal.lean @@ -117,9 +117,9 @@ theorem candidateCodes_allFailSomewhere_internal {arity threshold : ℕ} obtain ⟨hwell, hsize⟩ := hsmall by_contra hmissing apply hhard - letI : NeZero + let : NeZero (MCSP.Instance.ofFunction arity threshold target).arity := - ⟨by simpa using NeZero.ne arity⟩ + ⟨by exact NeZero.ne arity⟩ apply (MCSP.Instance.hasCircuitAtMost_iff_sizeComplexity_le_internal (MCSP.Instance.ofFunction arity threshold target)).mpr have hcomputes : diff --git a/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString.lean b/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString.lean index 84854da4..f565abf6 100644 --- a/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString.lean +++ b/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString.lean @@ -155,7 +155,7 @@ theorem hasShrinkExtension_two_mul_arity_of_circuitHardness (hhard : ¬ (MCSP.Instance.ofFunction arity hardnessThreshold target).HasCircuitAtMost) : HasShrinkExtension (2 * arity) target threshold inputs := by - letI : NeZero arity := ⟨by omega⟩ + let : NeZero arity := ⟨by omega⟩ apply hasShrinkExtension_two_mul_arity harity exact everySurvivorTupleCaught_of_circuitHardness target inputs hfits hhard diff --git a/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString/Circuit/Internal.lean b/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString/Circuit/Internal.lean index 9aad37f4..4f91b79c 100644 --- a/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString/Circuit/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/AntiChecker/GoodString/Circuit/Internal.lean @@ -151,7 +151,7 @@ theorem everySurvivorTupleCaught_of_circuitHardness_internal (MCSP.Instance.ofFunction arity hardnessThreshold target).arity ≠ 0 := by simpa [MCSP.Instance.ofFunction] using NeZero.ne arity unfold MCSP.Instance.HasCircuitAtMost - rw [dif_neg harity] + rw [dite_eq_right harity] refine ⟨internalGates, circuit, hsize.trans hfits, ?_⟩ unfold Circuit.Computes rw [MCSP.Instance.function_ofFunction_internal] diff --git a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Internal.lean b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Internal.lean index 32895438..4a3cc3c6 100644 --- a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Internal.lean @@ -113,9 +113,9 @@ theorem isFor_iff_not_hasCircuitAtMost_internal {arity threshold : ℕ} (inputs : List (BitString arity)) : IsFor target threshold inputs ↔ ¬ (SuccinctMCSP.Instance.ofInputs threshold target inputs).HasCircuitAtMost := by - letI : NeZero + let : NeZero (SuccinctMCSP.Instance.ofInputs threshold target inputs).arity := - ⟨by simpa using NeZero.ne arity⟩ + ⟨by exact NeZero.ne arity⟩ rw [isFor_iff_forall_not_agreesOn_internal, SuccinctMCSP.Instance.hasCircuitAtMost_iff_exists_circuit_internal] constructor diff --git a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Rounds/Selection/Internal.lean b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Rounds/Selection/Internal.lean index aa3ba237..25c2cc48 100644 --- a/Complexitylib/Metacomplexity/MCSP/AntiChecker/Rounds/Selection/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/AntiChecker/Rounds/Selection/Internal.lean @@ -100,7 +100,7 @@ theorem IsEstimateSelectionTrace.isShrinkTrace_of_length_le_internal | nil => exact isShrinkTrace_nil_internal target | cons input inputs ih => have htailLt : inputs.length < rounds := by - simpa only [List.length_cons] using hlength + exact hlength refine (isShrinkTrace_cons_iff_internal target input inputs).mpr ⟨ih htrace.1 htailLt.le, ?_⟩ exact htrace.2.isShrinkExtension_double_internal diff --git a/Complexitylib/Metacomplexity/MCSP/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Internal.lean index 45769e79..dc455a3c 100644 --- a/Complexitylib/Metacomplexity/MCSP/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Internal.lean @@ -35,7 +35,8 @@ theorem inputIndex_inputOfIndex_internal {arity : ℕ} (index : Fin (2 ^ arity)) theorem inputOfIndex_inputIndex_internal {arity : ℕ} (input : BitString arity) : inputOfIndex (inputIndex input) = input := by rw [← BitString.toList_inj] - simp only [inputOfIndex, inputIndex, BitString.toList_ofList] + simp only [inputOfIndex, inputIndex] + erw [BitString.toList_ofList] calc Nat.toBitsLE arity (Nat.fromBitsLE input.toList) = Nat.toBitsLE input.toList.length (Nat.fromBitsLE input.toList) := @@ -52,7 +53,8 @@ theorem function_ofFunction_internal (arity threshold : ℕ) (f : BitString arity → Bool) : (ofFunction arity threshold f).function = f := by funext input - simp [function, ofFunction, inputOfIndex_inputIndex_internal] + simp only [function, ofFunction] + exact congrArg f (inputOfIndex_inputIndex_internal input) theorem function_withThreshold_internal (inst : Instance) (threshold : ℕ) : (inst.withThreshold threshold).function = inst.function := by @@ -168,7 +170,7 @@ theorem hasCircuitAtMost_iff_minimumSize_le_internal (inst : Instance) : inst.HasCircuitAtMost ↔ inst.minimumSize ≤ inst.threshold := by by_cases harity : inst.arity = 0 · simp [HasCircuitAtMost, minimumSize, harity] - · letI : NeZero inst.arity := ⟨harity⟩ + · let _ : NeZero inst.arity := ⟨harity⟩ rw [hasCircuitAtMost_iff_sizeComplexity_le_internal, minimumSize_eq_sizeComplexity_internal] @@ -178,7 +180,8 @@ theorem hasCircuitAtMost_withThreshold_mono_internal (inst : Instance) (inst.withThreshold second).HasCircuitAtMost := by by_cases harity : inst.arity = 0 · simp [withThreshold, HasCircuitAtMost, harity] - · simp only [withThreshold, HasCircuitAtMost, harity, dite_false] at hsmall ⊢ + · unfold HasCircuitAtMost withThreshold at hsmall ⊢ + rw [dite_eq_right harity] at hsmall ⊢ obtain ⟨internalGates, circuit, hsize, hcomputes⟩ := hsmall exact ⟨internalGates, circuit, hsize.trans hthreshold, hcomputes⟩ diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Estimator/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Estimator/Internal.lean index 3d98e45b..358771f5 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Estimator/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Estimator/Internal.lean @@ -49,9 +49,10 @@ theorem isAccurateRequiredRoundEstimator_internal family target inputs input hlength] have happrox := hcorrect ⟨inputs.length, hlength⟩ (packTargetSamples target (input :: inputs).get) - simpa only [ - candidateLabeledSurvivorCount_unpack_packTargetSamples_internal, - List.ofFn_get] using happrox + unfold AntiChecker.ApproximatesCandidateSurvivorCount + simp only [candidateLabeledSurvivorCount_unpack_packTargetSamples_internal, + List.ofFn_get] at happrox + exact happrox end ApproximateCounterFamily @@ -73,7 +74,7 @@ theorem eventually_exists_isFor_length_eq_sampleCount_of_correctCounterFamily_in [eventually_exists_isFor_length_eq_sampleCount_of_isHardAt_internal beta] with arity hanti intro harity - letI : NeZero arity := ⟨harity⟩ + let : NeZero arity := ⟨harity⟩ intro overhead family hcorrect target hhard exact hanti harity target (family.extensionEstimator target) hhard (ApproximateCounterFamily.isAccurateRequiredRoundEstimator_internal diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Defs.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Defs.lean index dd50f3ff..2606dd25 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Defs.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Defs.lean @@ -31,7 +31,7 @@ namespace Magnification namespace AntiCheckerLemma /-- Width of the powered survivor tuple quantified by one occupancy query. -/ -def counterSurvivorPowerWidth (beta : PositiveRationalScale) (arity : ℕ) : ℕ := +@[reducible] def counterSurvivorPowerWidth (beta : PositiveRationalScale) (arity : ℕ) : ℕ := survivorPowerWidth arity (smallThreshold beta arity) (roundPrecision arity) /-- Width of the public labeled-sample and affine-seed prefix for one hash-cell diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Internal.lean index 58abce3f..f54e50ef 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Circuit/Internal.lean @@ -62,7 +62,7 @@ theorem evalFamilyCode_code_internal (hashCellPublicInput beta input seed).toList ++ witness.toList ≠ [] := by intro hempty have hzero := congrArg List.length hempty - simp [hashCellPublicWidth, counterInputWidth] at hzero + simp [hashCellPublicWidth, counterInputWidth, hashCellPublicInput] at hzero simpa [code, CircuitCode.evalFamilyCode, hnonempty, hlength] using heval theorem query_mem_extensionLanguage_iff_internal diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Defs.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Defs.lean index 6c7b1797..88faeb3d 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Defs.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Defs.lean @@ -55,7 +55,7 @@ instance {count : ℕ} (arity threshold precision rangeWidth : ℕ) Decidable (HashCellWitness arity threshold precision rangeWidth input seed witness) := by unfold HashCellWitness - infer_instance + exact @instDecidableAnd _ _ (Finset.decidableMem _ _) inferInstance /-- The selected affine zero cell contains at least one powered survivor witness. -/ diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Internal.lean index 62c16693..4cfde19c 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/HashCell/Internal.lean @@ -41,7 +41,7 @@ theorem hashCellWitness_iff_blocks_internal seed witness = fun _ => false := by unfold HashCellWitness survivorPowerWidth ApproximateCounting.Relative.poweredWidth - rw [ApproximateCounting.mem_cartesianPower_iff] + erw [ApproximateCounting.mem_cartesianPower_iff] theorem hashCellNonempty_iff_cellNonempty_internal {count arity threshold precision rangeWidth : ℕ} diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Defs.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Defs.lean index c2787dec..73fdf4ef 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Defs.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Defs.lean @@ -29,7 +29,7 @@ namespace AntiCheckerLemma /-- Width of the packed labeled-sample input for the counter extending a prefix of length `prefixLength`. -/ -def counterInputWidth (arity prefixLength : ℕ) : ℕ := +@[reducible] def counterInputWidth (arity prefixLength : ℕ) : ℕ := (prefixLength + 1) * (arity + 1) instance (arity prefixLength : ℕ) : diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Internal.lean index 58965071..1913c24f 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Hashing/Internal.lean @@ -80,9 +80,10 @@ theorem exists_correct_counter_of_hashingCircuit_internal have haccurate := hfixed input unfold ApproximateCounting.Relative.OutputIsAccurate at haccurate rw [card_encodedSurvivorSet] at haccurate - simpa only [ApproximateCounterCircuit.estimate, counterValue, - BitString.unsignedValue, counter] using haccurate - · simpa only [counter] using hfixedSize + simp only [ApproximateCounterCircuit.estimate, counterValue, counter] + exact haccurate + · simp only [counter] + exact hfixedSize theorem exists_correct_counter_of_oracleProgram_internal {language : Language} diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Relation/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Relation/Internal.lean index 6537f49a..4c3548cd 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Relation/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Counter/Relation/Internal.lean @@ -36,7 +36,7 @@ private theorem codeMatchesLabeledSamples_fixedWidth_iff intro sample unfold CodeMatchesLabeledSample DescriptionMatchesLabeledSample unfold CircuitCode.evalCode - rw [if_pos (BitString.length_toList (samples sample).input)] + rw [ite_eq_left (BitString.length_toList (samples sample).input)] rw [AntiChecker.decode_candidateCodeFixedWidthEquiv] rfl diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Assembly/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Assembly/Internal.lean index a66c7a7f..7cfbb5ac 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Assembly/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Assembly/Internal.lean @@ -45,7 +45,7 @@ theorem eventually_exists_generatorOfCounterFamily_isCorrect_internal beta] with arity hbudget hsize hsemantic intro harity - letI : NeZero arity := ⟨harity⟩ + let : NeZero arity := ⟨harity⟩ intro family hcorrect let generator := generatorOfCounterFamily family hbudget (hsize harity family hbudget) @@ -71,7 +71,7 @@ theorem eventually_existsCorrectGeneratorAt_of_existsCorrectCounterFamilyAt_inte with arity hgenerator harity intro hfamily have harity' : arity ≠ 0 := by omega - letI : NeZero arity := ⟨harity'⟩ + let : NeZero arity := ⟨harity'⟩ obtain ⟨family, hcorrect⟩ := hfamily obtain ⟨generator, hgeneratorCorrect⟩ := hgenerator harity' family hcorrect diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Internal.lean index cf0284bb..be9be49a 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Internal.lean @@ -66,7 +66,7 @@ theorem isHardAt_iff_sizeComplexity_gt_internal {arity : ℕ} IsHardAt beta target ↔ hardThreshold beta arity < Circuit.sizeComplexity Basis.andOr2 target := by - letI : NeZero + let : NeZero (MCSP.Instance.ofFunction arity (hardThreshold beta arity) target).arity := ⟨by simpa using NeZero.ne arity⟩ diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Iteration/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Iteration/Internal.lean index a12266e2..9398dfbb 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Iteration/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Iteration/Internal.lean @@ -165,7 +165,7 @@ theorem counterRoundEstimate_eq_extensionEstimator_internal (truthTable target) (packTargetSamples target inputs) = family.extensionEstimator target (List.ofFn inputs) := by funext input - rw [counterRoundEstimate_truthTable_packTargetSamples_internal] + erw [counterRoundEstimate_truthTable_packTargetSamples_internal] unfold ApproximateCounterFamily.extensionEstimator split_ifs with hlength · let ExtensionData := @@ -231,8 +231,7 @@ theorem exists_eval_selectionPrefixCircuit_isEstimateSelectionTrace_internal ((selectionPrefixCircuit family rounds (selectionPrefixPriorBound hrounds)).2.eval (truthTable target)) := by - simpa [counter] using - eval_selectionPrefixCircuit_succ_internal + simpa [counter] using! eval_selectionPrefixCircuit_succ_internal family hrounds (truthTable target) _ = (selectionRoundStateCircuit counter).2.eval (selectionTraceState target inputs) := @@ -252,8 +251,7 @@ theorem exists_eval_selectionPrefixCircuit_isEstimateSelectionTrace_internal counterRoundEstimate counter (truthTable target) (packTargetSamples target inputs) = family.extensionEstimator target (List.ofFn inputs) := by - simpa [counter] using - counterRoundEstimate_eq_extensionEstimator_internal + simpa [counter] using! counterRoundEstimate_eq_extensionEstimator_internal family target inputs hrounds have hminimum' : AntiChecker.IsEstimateMinimizer @@ -284,8 +282,10 @@ theorem unpackSample_selectionTraceState_projection_internal selectionSampleOutputMap arity rounds) sample = inputs sample := by funext coordinate - simp [unpackSample, selectionTraceState, selectionSampleOutputMap, - selectionRoundInput] + show Fin.append (truthTable target) (packTargetSamples target inputs) + (selectionSampleOutputMap arity rounds + (finProdFinEquiv (sample, coordinate))) = _ + simp [selectionSampleOutputMap, Equiv.symm_apply_apply, Fin.append_right] theorem eval_fullSelectionSamplesCircuit_internal {overhead arity : ℕ} {beta : PositiveRationalScale} [NeZero arity] diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Padding/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Padding/Internal.lean index c7c47d39..5a4d7eaf 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Padding/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Padding/Internal.lean @@ -197,7 +197,7 @@ theorem eventually_eval_paddedSelectionCircuit_isFor_of_correctCounterFamily_int [eventually_padInputsTo_isFor_of_isEstimateSelectionTrace_internal beta] with arity hanti intro harity - letI : NeZero arity := ⟨harity⟩ + let : NeZero arity := ⟨harity⟩ intro overhead family hbudget hcorrect target hhard obtain ⟨inputs, heval, htrace⟩ := exists_eval_paddedSelectionCircuit_isEstimateSelectionTrace_internal diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Round/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Round/Internal.lean index 67498bf7..added890 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Round/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Round/Internal.lean @@ -35,7 +35,8 @@ private theorem selectionRoundSuccessorInputMap_table Fin.castAdd (counterOutputWidth beta arity + (arity + 1)) (Fin.castAdd (prefixLength * (arity + 1)) tableCoordinate) := by apply Fin.ext - simp only [selectionRoundSuccessorInputMap, Fin.addCases_left] + simp only [selectionRoundSuccessorInputMap] + erw [Fin.addCases_left] rfl private theorem selectionRoundSuccessorInputMap_head @@ -47,9 +48,9 @@ private theorem selectionRoundSuccessorInputMap_head Fin.natAdd (selectionRoundInputWidth arity prefixLength) (Fin.natAdd (counterOutputWidth beta arity) coordinate) := by apply Fin.ext - simp only [selectionRoundSuccessorInputMap, Fin.addCases_right, - Equiv.symm_apply_apply, Fin.cases_zero] - simp [selectionRoundInputWidth] + simp only [selectionRoundSuccessorInputMap] + erw [Fin.addCases_right] + simp [selectionRoundInputWidth, Equiv.symm_apply_apply] omega private theorem selectionRoundSuccessorInputMap_tail @@ -62,9 +63,9 @@ private theorem selectionRoundSuccessorInputMap_tail (Fin.natAdd (2 ^ arity) (finProdFinEquiv (prefixRow, coordinate))) := by apply Fin.ext - simp only [selectionRoundSuccessorInputMap, Fin.addCases_right, - Equiv.symm_apply_apply, Fin.cases_succ] - rfl + simp only [selectionRoundSuccessorInputMap] + erw [Fin.addCases_right] + simp [Equiv.symm_apply_apply] private theorem selectionRoundCombinedInput_payload {arity prefixLength keyWidth payloadWidth : ℕ} diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Selection/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Selection/Internal.lean index 9573775b..30ca8771 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Selection/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Selection/Internal.lean @@ -240,10 +240,9 @@ theorem exists_minimumCounterRecord_candidate_isEstimateMinimizer_internal have hminimum := minimumCounterRecord_key_le_candidate_internal counter table packedPrefix (MCSP.Instance.inputIndex input) rw [hrecord] at hminimum - simpa only [counterRoundEstimate, - ApproximateCounterCircuit.estimate, candidateCounterKey, - BitString.unsignedValue, counterValue, - MCSP.Instance.inputIndex_inputOfIndex] using hminimum + simp only [counterRoundEstimate, ApproximateCounterCircuit.estimate, counterValue, + MCSP.Instance.inputIndex_inputOfIndex] + exact hminimum theorem exists_eval_minimumCounterRecordCircuit_eq_candidate_internal {overhead arity prefixLength : ℕ} {beta : PositiveRationalScale} diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Size/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Size/Internal.lean index 5e2940dd..ab3aa6b8 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Size/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Generator/Size/Internal.lean @@ -444,7 +444,7 @@ theorem eventually_size_paddedSelectionCircuit_le_generatorSizeBound_internal counterOverhead beta] with arity hbound intro harity - letI : NeZero arity := ⟨harity⟩ + let : NeZero arity := ⟨harity⟩ intro family hbudget exact (size_paddedSelectionCircuit_le_paddedSelectionSizeBound_internal diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/GoodString/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/GoodString/Internal.lean index 5a35fe92..cb507432 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/GoodString/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/GoodString/Internal.lean @@ -38,7 +38,7 @@ theorem eventually_survivorTupleMajoritySizeBound_le_hardThreshold_internal beta 50 2 filter_upwards [hpolynomial, Filter.eventually_ge_atTop 1] with arity hpolynomial harity - letI : NeZero arity := ⟨by omega⟩ + let : NeZero arity := ⟨by omega⟩ have hsmallScaled : fixedConstant * (arity * smallThreshold beta arity) ≤ hardThreshold beta arity := by diff --git a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Rounds/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Rounds/Internal.lean index 913cf404..98744dfa 100644 --- a/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Rounds/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Magnification/AntiChecker/Rounds/Internal.lean @@ -201,7 +201,7 @@ theorem eventually_padInputsTo_isFor_of_isEstimateSelectionTrace_internal eventually_requiredRoundCount_le_sampleCount_internal beta] with arity hgood hbudget intro harity target estimator inputs hhard hestimate hlength hselection - letI : NeZero arity := ⟨harity⟩ + let : NeZero arity := ⟨harity⟩ have hshrink' := hselection.isShrinkTrace_of_length_le_internal (rounds := requiredRoundCount beta arity) @@ -249,7 +249,7 @@ theorem eventually_exists_isFor_length_eq_sampleCount_of_isHardAt_internal eventually_requiredRoundCount_le_sampleCount_internal beta] with arity htrace hbudget intro harity target estimator hhard hestimate - letI : NeZero arity := ⟨harity⟩ + let : NeZero arity := ⟨harity⟩ obtain ⟨inputs, hlength, hshrink⟩ := htrace target estimator hhard hestimate have hanti : diff --git a/Complexitylib/Metacomplexity/MCSP/Normalization/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Normalization/Internal.lean index 33588e53..0f58f376 100644 --- a/Complexitylib/Metacomplexity/MCSP/Normalization/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Normalization/Internal.lean @@ -49,7 +49,7 @@ theorem exists_circuit_size_le_trivialCircuitSizeBound_internal (inst : Instance let source := andOrNotFor inst.function let circuit := CompileAndOr.compileFn source refine ⟨_, circuit, ?_, ?_⟩ - · rw [trivialCircuitSizeBound, if_neg (NeZero.ne inst.arity)] + · rw [trivialCircuitSizeBound, ite_eq_right (NeZero.ne inst.arity)] have hcompile := CompileAndOr.compileFn_size_le source have hfanIn := andOrNotFor_totalFanIn_le inst.function have hsourceSize : source.size = 2 ^ inst.arity + 1 := rfl @@ -77,8 +77,9 @@ theorem hasCircuitAtMost_trivialCircuitSizeBound_internal (inst : Instance) : (inst.withThreshold inst.trivialCircuitSizeBound).HasCircuitAtMost := by by_cases harity : inst.arity = 0 · simp [withThreshold, HasCircuitAtMost, harity] - · letI : NeZero inst.arity := ⟨harity⟩ - simp only [withThreshold, HasCircuitAtMost, harity, dite_false] + · let : NeZero inst.arity := ⟨harity⟩ + unfold HasCircuitAtMost withThreshold + rw [dite_eq_right harity] exact exists_circuit_size_le_trivialCircuitSizeBound_internal inst theorem effectiveThreshold_le_threshold_internal (inst : Instance) : @@ -98,7 +99,8 @@ theorem hasCircuitAtMost_normalizeThreshold_iff_internal (inst : Instance) : simpa [normalizeThreshold] using hnormalized · intro hsmall by_cases hthreshold : inst.threshold ≤ inst.trivialCircuitSizeBound - · simpa [normalizeThreshold, effectiveThreshold, min_eq_left hthreshold] using hsmall + · simp [normalizeThreshold, effectiveThreshold, min_eq_left hthreshold] + exact hsmall · have hbound : inst.trivialCircuitSizeBound ≤ inst.threshold := by omega have htrivial := hasCircuitAtMost_trivialCircuitSizeBound_internal inst simpa [normalizeThreshold, effectiveThreshold, min_eq_right hbound] using htrivial @@ -107,7 +109,7 @@ theorem trivialCircuitSizeBound_le_encodeLength_internal (inst : Instance) : inst.trivialCircuitSizeBound ≤ (inst.encode.length + 2) ^ 2 := by by_cases harity : inst.arity = 0 · simp [trivialCircuitSizeBound, harity] - · rw [trivialCircuitSizeBound, if_neg harity] + · rw [trivialCircuitSizeBound, ite_eq_right harity] have htable : 2 ^ inst.arity ≤ inst.encode.length := by rw [length_encode_internal] omega @@ -146,7 +148,7 @@ theorem rawWitnessLengthPolynomial_polyBound_internal : ((PolyBound.const 2).mul (PolyBound.id.add hsizeBound)).add (PolyBound.const 6) have htotal := (PolyBound.const 1).add (hsizeBound.mul hfactor) - simpa [rawWitnessLengthPolynomial, sizeBound] using htotal + exact htotal end Instance @@ -171,7 +173,7 @@ theorem mem_MCSP_iff_exists_rawWitnessRelation_internal (bits : List Bool) : cases hdecode : Instance.decode? bits with | none => simp [MCSP, RawWitnessRelation, hdecode] | some inst => - simp only [MCSP, RawWitnessRelation, hdecode, Set.mem_setOf_eq] + simp only [MCSP, RawWitnessRelation, hdecode, Set.mem_ofPred_eq] rw [Instance.exists_isRawCircuitWitness_iff_internal, Instance.hasCircuitAtMost_normalizeThreshold_iff_internal] diff --git a/Complexitylib/Metacomplexity/MCSP/Raw/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Raw/Internal.lean index 4a5f07c5..fa808b3e 100644 --- a/Complexitylib/Metacomplexity/MCSP/Raw/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Raw/Internal.lean @@ -114,7 +114,7 @@ theorem mem_rawAtThreshold_tableBits_iff_internal (threshold : ℕ → ℕ) (inst : Instance) : inst.tableBits ∈ rawAtThreshold threshold ↔ inst.minimumSize ≤ threshold inst.arity := by - simp only [rawAtThreshold, Set.mem_setOf_eq, + simp only [rawAtThreshold, Set.mem_ofPred_eq, rawDecode?_tableBits_internal] rw [Instance.hasCircuitAtMost_iff_minimumSize_le_internal, Instance.minimumSize_withThreshold_internal] @@ -157,7 +157,7 @@ theorem mem_rawSliceNoLanguage_tableBits_iff_internal (parameters : SliceParameters) (inst : MCSP.Instance) : inst.tableBits ∈ rawSliceNoLanguage parameters ↔ parameters.noThreshold inst.arity < inst.minimumSize := by - simp only [rawSliceNoLanguage, Set.mem_setOf_eq, + simp only [rawSliceNoLanguage, Set.mem_ofPred_eq, MCSP.rawDecode?_tableBits_internal] rw [MCSP.Instance.minimumSize_withThreshold_internal] rfl diff --git a/Complexitylib/Metacomplexity/MCSP/Shannon/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Shannon/Internal.lean index fa7cb221..e2b88485 100644 --- a/Complexitylib/Metacomplexity/MCSP/Shannon/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Shannon/Internal.lean @@ -28,11 +28,11 @@ theorem exists_minimumSize_gt_shannonLower_internal inst.arity = arity ∧ inst.threshold = 2 ^ arity / (5 * arity) ∧ inst.minimumSize > 2 ^ arity / (5 * arity) := by - letI : NeZero arity := ⟨by omega⟩ + let : NeZero arity := ⟨by omega⟩ obtain ⟨f, hf⟩ := shannon_sizeComplexity arity harity let inst := Instance.ofFunction arity (2 ^ arity / (5 * arity)) f refine ⟨inst, rfl, rfl, ?_⟩ - letI : NeZero inst.arity := + let : NeZero inst.arity := ⟨by simpa [inst] using (NeZero.ne arity)⟩ rw [Instance.minimumSize_eq_sizeComplexity] simpa [inst] using hf @@ -54,10 +54,10 @@ theorem exists_ofFunction_not_mem_at_shannonLower_internal ∃ f : BitString arity → Bool, (Instance.ofFunction arity (2 ^ arity / (5 * arity)) f).encode ∉ Complexity.MCSP := by - letI : NeZero arity := ⟨by omega⟩ + let : NeZero arity := ⟨by omega⟩ obtain ⟨f, hf⟩ := shannon_sizeComplexity arity harity refine ⟨f, ?_⟩ - letI : NeZero + let : NeZero (Instance.ofFunction arity (2 ^ arity / (5 * arity)) f).arity := ⟨by simpa using (NeZero.ne arity)⟩ rw [Complexity.MCSP.mem_encode_iff_sizeComplexity_le] @@ -67,7 +67,7 @@ theorem mem_encode_of_shannonUpper_le_threshold_internal (inst : Instance) (harity : 16 ≤ inst.arity) (hthreshold : 18 * 2 ^ inst.arity / inst.arity ≤ inst.threshold) : inst.encode ∈ Complexity.MCSP := by - letI : NeZero inst.arity := ⟨by omega⟩ + let : NeZero inst.arity := ⟨by omega⟩ rw [Complexity.MCSP.mem_encode_iff_sizeComplexity_le] exact (shannon_upper_bound inst.arity harity inst.function).trans hthreshold diff --git a/Complexitylib/Metacomplexity/MCSP/Succinct/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Succinct/Internal.lean index a80ba7e0..78163cdf 100644 --- a/Complexitylib/Metacomplexity/MCSP/Succinct/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Succinct/Internal.lean @@ -282,7 +282,7 @@ theorem hasCircuitAtMost_threshold_mono_internal (inst : Instance) (hsmall : ({ inst with threshold := first } : Instance).HasCircuitAtMost) : ({ inst with threshold := second } : Instance).HasCircuitAtMost := by by_cases harity : inst.arity = 0 - · simpa [HasCircuitAtMost, harity] using hsmall + · simpa [HasCircuitAtMost, harity, Instance.SamplesFunction] using hsmall · simp only [HasCircuitAtMost, harity, dite_false] at hsmall ⊢ obtain ⟨internalGates, circuit, hsize, hsamples⟩ := hsmall exact ⟨internalGates, circuit, hsize.trans hthreshold, hsamples⟩ diff --git a/Complexitylib/Metacomplexity/MCSP/Succinct/Normalization/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Succinct/Normalization/Internal.lean index 3b97413b..402502ab 100644 --- a/Complexitylib/Metacomplexity/MCSP/Succinct/Normalization/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Succinct/Normalization/Internal.lean @@ -222,8 +222,10 @@ theorem hasCircuitAtMost_trivialCircuitSizeBound_internal (inst : Instance) (hsmall : inst.HasCircuitAtMost) : ({ inst with threshold := inst.trivialCircuitSizeBound } : Instance).HasCircuitAtMost := by by_cases harity : inst.arity = 0 - · simpa [HasCircuitAtMost, harity] using hsmall - · letI : NeZero inst.arity := ⟨harity⟩ + · unfold HasCircuitAtMost at hsmall ⊢ + rw [dite_eq_left harity] at hsmall ⊢ + exact hsmall + · let : NeZero inst.arity := ⟨harity⟩ obtain ⟨_, circuit, _, hsamples⟩ := (hasCircuitAtMost_iff_exists_circuit_internal inst).mp hsmall apply (exists_isRawCircuitWitness_iff_internal @@ -231,7 +233,7 @@ theorem hasCircuitAtMost_trivialCircuitSizeBound_internal (inst : Instance) let formula := inst.interpolatingFormula let rawCircuit := BoolFormula.compileRaw inst.arity formula refine ⟨rawCircuit.encode, ?_⟩ - simp only [IsRawCircuitWitness, harity, if_false] + simp only [IsRawCircuitWitness, harity, ite_false] change match CircuitCode.RawCircuit.decode? rawCircuit.encode with | none => False @@ -312,7 +314,7 @@ theorem rawWitnessLengthPolynomial_polyBound_internal : PolyBound (fun inputLength => 4 * inputLength + 6) := ((PolyBound.const 4).mul PolyBound.id).add (PolyBound.const 6) have htotal := (PolyBound.const 1).add (PolyBound.id.mul hfactor) - simpa [rawWitnessLengthPolynomial] using htotal + exact htotal theorem exists_normalizedRawWitness_length_le_encode_internal (inst : Instance) (hsmall : inst.HasCircuitAtMost) : @@ -324,7 +326,7 @@ theorem exists_normalizedRawWitness_length_le_encode_internal · refine ⟨[false], ?_, ?_⟩ · simp [normalizeThreshold, IsRawCircuitWitness, harity, hsamples] · simp [rawWitnessLengthPolynomial] - · letI : NeZero inst.arity := ⟨harity⟩ + · let : NeZero inst.arity := ⟨harity⟩ obtain ⟨_, circuit, hsize, _⟩ := (hasCircuitAtMost_iff_exists_circuit_internal inst).mp hsmall have hthreshold : 1 ≤ inst.threshold := by @@ -337,7 +339,7 @@ theorem exists_normalizedRawWitness_length_le_encode_internal [CircuitCode.RawGate.constant 0 false] refine ⟨rawCircuit.encode, ?_, ?_⟩ · simp only [IsRawCircuitWitness, normalizeThreshold, harity, - if_false] + ite_false] change match CircuitCode.RawCircuit.decode? rawCircuit.encode with | none => False @@ -420,7 +422,7 @@ theorem mem_iff_exists_rawWitnessRelation_internal (bits : List Bool) : | none => simp [Complexity.SuccinctMCSP, RawWitnessRelation, hdecode] | some inst => simp only [Complexity.SuccinctMCSP, RawWitnessRelation, hdecode, - Set.mem_setOf_eq] + Set.mem_ofPred_eq] constructor · intro hsmall have hcanonical := diff --git a/Complexitylib/Metacomplexity/MCSP/Succinct/Witness/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Succinct/Witness/Internal.lean index baf3e29f..63b47d27 100644 --- a/Complexitylib/Metacomplexity/MCSP/Succinct/Witness/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Succinct/Witness/Internal.lean @@ -36,7 +36,7 @@ theorem isRawCircuitWitness_encodeCircuit_internal (inst : Instance) (hsize : circuit.size ≤ inst.threshold) (hsamples : inst.SamplesFunction (fun input => circuit.eval input 0)) : inst.IsRawCircuitWitness (CircuitCode.encodeCircuit circuit) := by - simp only [IsRawCircuitWitness, NeZero.ne inst.arity, if_false] + simp only [IsRawCircuitWitness, NeZero.ne inst.arity, ite_false] change match CircuitCode.RawCircuit.decode? (CircuitCode.RawCircuit.ofCircuit circuit).encode with @@ -57,7 +57,7 @@ theorem isRawCircuitWitness_encodeCircuit_internal (inst : Instance) theorem hasCircuitAtMost_of_isRawCircuitWitness_internal (inst : Instance) [NeZero inst.arity] {code : List Bool} (hwitness : inst.IsRawCircuitWitness code) : inst.HasCircuitAtMost := by - simp only [IsRawCircuitWitness, NeZero.ne inst.arity, if_false] at hwitness + simp only [IsRawCircuitWitness, NeZero.ne inst.arity, ite_false] at hwitness cases hdecode : CircuitCode.RawCircuit.decode? code with | none => simp [hdecode] at hwitness | some rawCircuit => @@ -81,7 +81,7 @@ theorem exists_isRawCircuitWitness_iff_internal (inst : Instance) : by_cases harity : inst.arity = 0 · constructor · rintro ⟨code, hwitness⟩ - simp only [IsRawCircuitWitness, harity, if_true] at hwitness + simp only [IsRawCircuitWitness, harity, ite_true] at hwitness cases code with | nil => simp at hwitness | cons output rest => @@ -98,10 +98,10 @@ theorem exists_isRawCircuitWitness_iff_internal (inst : Instance) : obtain ⟨output, hsamples⟩ := (hasCircuitAtMost_of_arity_eq_zero_iff_internal inst harity).mp hsmall refine ⟨[output], ?_⟩ - simp only [IsRawCircuitWitness, harity, if_true] + simp only [IsRawCircuitWitness, harity, ite_true] simpa [SamplesFunction, Sample.MatchesFunction, List.forall_iff_forall_mem] using hsamples - · letI : NeZero inst.arity := ⟨harity⟩ + · let : NeZero inst.arity := ⟨harity⟩ constructor · rintro ⟨code, hwitness⟩ exact hasCircuitAtMost_of_isRawCircuitWitness_internal inst hwitness @@ -119,7 +119,7 @@ theorem isRawCircuitWitness_threshold_mono_internal (inst : Instance) ({ inst with threshold := second } : Instance).IsRawCircuitWitness code := by by_cases harity : inst.arity = 0 · simpa [IsRawCircuitWitness, harity] using hwitness - · simp only [IsRawCircuitWitness, harity, if_false] at hwitness ⊢ + · simp only [IsRawCircuitWitness, harity, ite_false] at hwitness ⊢ cases hdecode : CircuitCode.RawCircuit.decode? code with | none => simp [hdecode] at hwitness | some circuit => @@ -130,14 +130,14 @@ theorem isRawCircuitWitness_length_le_internal (inst : Instance) {code : List Bool} (hwitness : inst.IsRawCircuitWitness code) : code.length ≤ inst.rawWitnessCodeLengthBound := by by_cases harity : inst.arity = 0 - · simp only [IsRawCircuitWitness, harity, if_true] at hwitness + · simp only [IsRawCircuitWitness, harity, ite_true] at hwitness cases code with | nil => simp at hwitness | cons output rest => cases rest with | nil => simp [rawWitnessCodeLengthBound] | cons next rest => simp at hwitness - · simp only [IsRawCircuitWitness, harity, if_false] at hwitness + · simp only [IsRawCircuitWitness, harity, ite_false] at hwitness cases hdecode : CircuitCode.RawCircuit.decode? code with | none => simp [hdecode] at hwitness | some circuit => diff --git a/Complexitylib/Metacomplexity/MCSP/Witness/Internal.lean b/Complexitylib/Metacomplexity/MCSP/Witness/Internal.lean index 0ee03830..92ecf5e3 100644 --- a/Complexitylib/Metacomplexity/MCSP/Witness/Internal.lean +++ b/Complexitylib/Metacomplexity/MCSP/Witness/Internal.lean @@ -35,7 +35,7 @@ theorem isRawCircuitWitness_encodeCircuit_internal (inst : Instance) (hsize : circuit.size ≤ inst.threshold) (hcomputes : circuit.Computes inst.function) : inst.IsRawCircuitWitness (CircuitCode.encodeCircuit circuit) := by - simp only [IsRawCircuitWitness, NeZero.ne inst.arity, if_false] + simp only [IsRawCircuitWitness, NeZero.ne inst.arity, ite_false] change match CircuitCode.RawCircuit.decode? (CircuitCode.RawCircuit.ofCircuit circuit).encode with @@ -59,7 +59,7 @@ theorem isRawCircuitWitness_encodeCircuit_internal (inst : Instance) theorem hasCircuitAtMost_of_isRawCircuitWitness_internal (inst : Instance) [NeZero inst.arity] {code : List Bool} (hwitness : inst.IsRawCircuitWitness code) : inst.HasCircuitAtMost := by - simp only [IsRawCircuitWitness, NeZero.ne inst.arity, if_false] at hwitness + simp only [IsRawCircuitWitness, NeZero.ne inst.arity, ite_false] at hwitness cases hdecode : CircuitCode.RawCircuit.decode? code with | none => simp [hdecode] at hwitness | some rawCircuit => @@ -85,7 +85,7 @@ theorem exists_isRawCircuitWitness_iff_internal (inst : Instance) : (∃ code, inst.IsRawCircuitWitness code) ↔ inst.HasCircuitAtMost := by by_cases harity : inst.arity = 0 · simp [IsRawCircuitWitness, HasCircuitAtMost, harity] - · letI : NeZero inst.arity := ⟨harity⟩ + · let : NeZero inst.arity := ⟨harity⟩ constructor · rintro ⟨code, hwitness⟩ exact hasCircuitAtMost_of_isRawCircuitWitness_internal inst hwitness @@ -101,7 +101,7 @@ theorem isRawCircuitWitness_withThreshold_mono_internal (inst : Instance) (inst.withThreshold second).IsRawCircuitWitness code := by by_cases harity : inst.arity = 0 · simpa [withThreshold, IsRawCircuitWitness, harity] using hwitness - · simp only [withThreshold, IsRawCircuitWitness, harity, if_false] at hwitness ⊢ + · simp only [withThreshold, IsRawCircuitWitness, harity, ite_false] at hwitness ⊢ cases hdecode : CircuitCode.RawCircuit.decode? code with | none => simp [hdecode] at hwitness | some circuit => @@ -114,7 +114,7 @@ theorem isRawCircuitWitness_length_le_internal (inst : Instance) {code : List Bo by_cases harity : inst.arity = 0 · simp [IsRawCircuitWitness, harity] at hwitness simp [hwitness, rawWitnessCodeLengthBound] - · simp only [IsRawCircuitWitness, harity, if_false] at hwitness + · simp only [IsRawCircuitWitness, harity, ite_false] at hwitness cases hdecode : CircuitCode.RawCircuit.decode? code with | none => simp [hdecode] at hwitness | some circuit => @@ -146,7 +146,7 @@ theorem exists_isRawCircuitWitness_length_le_internal (inst : Instance) · refine ⟨[], ?_, ?_⟩ · simp [IsRawCircuitWitness, harity] · simp [rawWitnessCodeLengthBound] - · letI : NeZero inst.arity := ⟨harity⟩ + · let : NeZero inst.arity := ⟨harity⟩ simp only [HasCircuitAtMost, harity, dite_false] at hsmall obtain ⟨internalGates, circuit, hsize, hcomputes⟩ := hsmall refine ⟨CircuitCode.encodeCircuit circuit, diff --git a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Internal.lean b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Internal.lean index c1b10df2..ed8bfb66 100644 --- a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Internal.lean +++ b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Internal.lean @@ -201,7 +201,7 @@ theorem SatisfiesSoIInputs.satisfiesAccounting_internal exact WithTop.coe_le_coe.mpr hbudgetValue have hresult := hconditionCorrection.trans <| hchainCorrection.trans <| hpairLossCorrection.trans hbudget - simpa only [add_assoc] using hresult + simpa only [add_assoc, Nat.cast_add] using hresult end DifferenceEstimator diff --git a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Internal.lean b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Internal.lean index 66ec67d8..8b50fb9d 100644 --- a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Internal.lean +++ b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Internal.lean @@ -86,13 +86,14 @@ theorem Compatible.satisfiesSoIInputsOnQueries_internal ordinaryMachine.timeBoundedKolmogorovComplexity inst.condition (plan.conditionInputTime inst) at hupper rw [hcompatible.conditionInputTime_eq inst] at hupper - simpa [Plan.components, Plan.conditionInput] using hupper + simp [Plan.components, Plan.conditionInput] + exact hupper · intro inst have hpair := hestimate (plan.pairInput inst) ⟨inst, Or.inl rfl⟩ have hlower := hpair.2 rw [hcompatible.pairTransformedTime_eq inst] at hlower - simpa [Plan.components, Plan.pairInput, Plan.accountingSchedule] using - hlower + simp [Plan.components, Plan.pairInput, Plan.accountingSchedule] + exact hlower · exact hcompatible.upperLoss_budget · exact hcompatible.lowerLoss_budget diff --git a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Iterated/Internal.lean b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Iterated/Internal.lean index bbf633de..56c1ec1f 100644 --- a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Iterated/Internal.lean +++ b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Iterated/Internal.lean @@ -188,17 +188,14 @@ theorem IsRegularClock.compatible_internal rfl · exact hpair · intro inst - simpa [Plan.accountingSchedule, Plan.conditionInput, - GapMINKT.Logarithmic.Parameters.logarithmicSlack, - GapMINKT.Logarithmic.Parameters.transformedTime, ordinaryParameters, - plan] using hloss.upper inst + simp [Plan.conditionInput, GapMINKT.Logarithmic.Parameters.logarithmicSlack, + GapMINKT.Logarithmic.Parameters.transformedTime, ordinaryParameters, plan] + exact hloss.upper inst · intro inst - simpa [Plan.accountingSchedule, Plan.pairInput, - GapMINKT.Logarithmic.Parameters.logarithmicSlack, - GapMINKT.Logarithmic.Parameters.transformedTime, - GapMINCKT.Parameters.logarithmicSlack, - GapMINCKT.Parameters.transformedTime, ordinaryParameters, - conditionalParameters, plan] using hloss.lower inst + simp [Plan.pairInput, GapMINKT.Logarithmic.Parameters.logarithmicSlack, + GapMINKT.Logarithmic.Parameters.transformedTime, GapMINCKT.Parameters.logarithmicSlack, + GapMINCKT.Parameters.transformedTime, ordinaryParameters, conditionalParameters, plan] + exact hloss.lower inst theorem IsRegularClock.compatible_of_pairComposition_internal {ordinaryTapes conditionalTapes : ℕ} diff --git a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Slack/Internal.lean b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Slack/Internal.lean index e243ded4..ba239f3c 100644 --- a/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Slack/Internal.lean +++ b/Complexitylib/Metacomplexity/MINCKT/Gap/Difference/SoI/Unconditional/Slack/Internal.lean @@ -137,10 +137,11 @@ theorem lowerLoss_budget_internal have hloss := losses_le_slackExponent_internal hclock additive compilerLoss inst have hslack := slackExponent_le_log_finalClock_internal clock additive compilerLoss inst.output.length inst.condition.length inst.time - exact (by - simpa [plan, Iterated.plan, Plan.pairInput, ordinaryParameters, - GapMINKT.Logarithmic.Parameters.logarithmicSlack, - GapMINKT.Logarithmic.Parameters.transformedTime] using hloss.trans hslack) + have h := hloss.trans hslack + simp only [plan, Iterated.plan, Plan.pairInput, ordinaryParameters, + GapMINKT.Logarithmic.Parameters.logarithmicSlack, + GapMINKT.Logarithmic.Parameters.transformedTime] at h ⊢ + exact h theorem IsRegularClock.compatible_internal {ordinaryTapes conditionalTapes : ℕ} diff --git a/Complexitylib/Metacomplexity/MINCKT/Gap/Internal.lean b/Complexitylib/Metacomplexity/MINCKT/Gap/Internal.lean index 578a97fd..87883cb8 100644 --- a/Complexitylib/Metacomplexity/MINCKT/Gap/Internal.lean +++ b/Complexitylib/Metacomplexity/MINCKT/Gap/Internal.lean @@ -128,7 +128,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : time := baseInst.time threshold := thresholdBits.length } else none) = some inst at hdecode - rw [if_pos hthreshold] at hdecode + rw [ite_eq_left hthreshold] at hdecode cases hdecode have hbaseBits := (MINCKT.Instance.decode?_eq_some_iff_internal @@ -162,7 +162,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : time := baseInst.time threshold := thresholdBits.length } else none) = some inst at hdecode - rw [if_neg hthreshold] at hdecode + rw [ite_eq_right hthreshold] at hdecode contradiction · rintro rfl exact decode?_encode_internal inst diff --git a/Complexitylib/Metacomplexity/MINCKT/Internal.lean b/Complexitylib/Metacomplexity/MINCKT/Internal.lean index 9ed82b29..9bd2ffa8 100644 --- a/Complexitylib/Metacomplexity/MINCKT/Internal.lean +++ b/Complexitylib/Metacomplexity/MINCKT/Internal.lean @@ -53,7 +53,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : by_cases hclock : clock = List.replicate clock.length true · have hbits := eq_pair_of_unpair?_eq_some houter have hremaining := eq_pair_of_unpair?_eq_some hinner - rw [if_pos hclock] at hdecode + rw [ite_eq_left hclock] at hdecode cases hdecode calc bits = pair output remaining := hbits @@ -65,7 +65,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : hclock _ = encode { output, condition, time := clock.length } := rfl - · rw [if_neg hclock] at hdecode + · rw [ite_eq_right hclock] at hdecode contradiction · rintro rfl exact decode?_encode_internal inst diff --git a/Complexitylib/Metacomplexity/MINKT/AuxiliaryUnary/Internal.lean b/Complexitylib/Metacomplexity/MINKT/AuxiliaryUnary/Internal.lean index e13743b6..9e08dd8f 100644 --- a/Complexitylib/Metacomplexity/MINKT/AuxiliaryUnary/Internal.lean +++ b/Complexitylib/Metacomplexity/MINKT/AuxiliaryUnary/Internal.lean @@ -98,8 +98,8 @@ theorem probability_auxiliaryUnary_minkt_eq_average_internal eventProb (machine.timeBoundedStrictlyCompressibleStrings n.val (m - n.val) (threshold n.val)) := by classical - letI := auxiliaryUnary.seedFintype m - letI := auxiliaryUnary.seedDecidableEq m + let := auxiliaryUnary.seedFintype m + let := auxiliaryUnary.seedDecidableEq m unfold auxiliaryUnaryMINKTProbability change uniformProbability (Finset.univ.filter fun seed : AuxiliaryUnarySeed m => diff --git a/Complexitylib/Metacomplexity/MINKT/Gap/Internal.lean b/Complexitylib/Metacomplexity/MINKT/Gap/Internal.lean index 5b921c3a..0caac177 100644 --- a/Complexitylib/Metacomplexity/MINKT/Gap/Internal.lean +++ b/Complexitylib/Metacomplexity/MINKT/Gap/Internal.lean @@ -79,7 +79,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : time := baseInst.time threshold := thresholdBits.length } else none) = some inst at hdecode - rw [if_pos hthreshold] at hdecode + rw [ite_eq_left hthreshold] at hdecode cases hdecode have hbaseBits := (MINKT.Instance.decode?_eq_some_iff_internal @@ -110,7 +110,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : time := baseInst.time threshold := thresholdBits.length } else none) = some inst at hdecode - rw [if_neg hthreshold] at hdecode + rw [ite_eq_right hthreshold] at hdecode contradiction · rintro rfl exact decode?_encode_internal inst diff --git a/Complexitylib/Metacomplexity/MINKT/Gap/Logarithmic/Efficient/Internal.lean b/Complexitylib/Metacomplexity/MINKT/Gap/Logarithmic/Efficient/Internal.lean index 3fcf1718..f68c778e 100644 --- a/Complexitylib/Metacomplexity/MINKT/Gap/Logarithmic/Efficient/Internal.lean +++ b/Complexitylib/Metacomplexity/MINKT/Gap/Logarithmic/Efficient/Internal.lean @@ -144,14 +144,12 @@ private theorem sweepStep_mem_FP (decide : List Bool → Bool) Cobham.pairFn_mem_FP hfst hcounter have haccepted : (fun state => [decide (pair (pairFst state) (pairFst (pairSnd state)))]) ∈ FP := by - simpa [Function.comp] using mem_FP_comp hquery hdecide + exact mem_FP_comp hquery hdecide have hnextCounter : (fun state => true :: pairFst (pairSnd state)) ∈ FP := by - simpa [Function.comp] using - mem_FP_comp hcounter (Cobham.cons_mem_FP true) + exact mem_FP_comp hcounter (Cobham.cons_mem_FP true) have htrue : (fun _ : List Bool => [true]) ∈ FP := by - simpa [Function.comp] using - mem_FP_comp Cobham.const_nil_mem_FP (Cobham.cons_mem_FP true) + exact mem_FP_comp Cobham.const_nil_mem_FP (Cobham.cons_mem_FP true) have hfirstChoice : (fun state => chooseHead [decide (pair (pairFst state) (pairFst (pairSnd state)))] (pairFst (pairSnd state)) @@ -175,38 +173,35 @@ private theorem sweepStep_mem_FP (decide : List Bool → Bool) have hpacked := Cobham.pairFn_mem_FP hfst (Cobham.pairFn_mem_FP hnextCounter (Cobham.pairFn_mem_FP hnextFound hnextBest)) - simpa [sweepStep] using hpacked + exact hpacked private theorem sweepInit_mem_FP : sweepInit ∈ FP := by have hnil : (fun _ : List Bool => ([] : List Bool)) ∈ FP := Cobham.const_nil_mem_FP have hfalse : (fun _ : List Bool => [false]) ∈ FP := by - simpa [Function.comp] using - mem_FP_comp hnil (Cobham.cons_mem_FP false) + exact mem_FP_comp hnil (Cobham.cons_mem_FP false) have hpacked := Cobham.pairFn_mem_FP id_mem_FP (Cobham.pairFn_mem_FP hnil (Cobham.pairFn_mem_FP hfalse Cobham.sndBlock_mem_FP)) - simpa [sweepInit] using hpacked + exact hpacked private theorem sweepRuler_mem_FP : sweepRuler ∈ FP := by have h := mem_FP_comp Cobham.sndBlock_mem_FP (Cobham.cons_mem_FP false) - simpa [Function.comp, sweepRuler] using h + exact h private theorem sweepWidth_mem_FP : sweepWidth ∈ FP := by have hbaseOne : (fun base : List Bool => true :: base) ∈ FP := by simpa [Function.comp] using mem_FP_comp id_mem_FP (Cobham.cons_mem_FP true) have hbaseTwo : (fun base : List Bool => true :: true :: base) ∈ FP := by - simpa [Function.comp] using mem_FP_comp hbaseOne - (Cobham.cons_mem_FP true) + exact mem_FP_comp hbaseOne (Cobham.cons_mem_FP true) have hclockOne : (fun base : List Bool => true :: pairSnd base) ∈ FP := by - simpa [Function.comp] using mem_FP_comp Cobham.sndBlock_mem_FP - (Cobham.cons_mem_FP true) + exact mem_FP_comp Cobham.sndBlock_mem_FP (Cobham.cons_mem_FP true) have hpacked := Cobham.pairFn_mem_FP hbaseTwo (Cobham.pairFn_mem_FP hclockOne hclockOne) - simpa [sweepWidth] using hpacked + exact hpacked private theorem sweep_iterate_length_le_width (decide : List Bool → Bool) (base : List Bool) (iterations : ℕ) @@ -238,7 +233,7 @@ theorem encodedTimeSearchEstimator_mem_FP_internal (fun state => pairSnd (pairSnd (pairSnd state))) ∈ FP := mem_FP_comp hsndSnd Cobham.sndBlock_mem_FP have hout := mem_FP_comp hiter hbest - simpa [encodedTimeSearchEstimator, Function.comp] using hout + exact hout theorem encodedTimeSearchEstimator_encode_internal (decide : List Bool → Bool) (inst : MINKT.Instance) : diff --git a/Complexitylib/Metacomplexity/MINKT/Internal.lean b/Complexitylib/Metacomplexity/MINKT/Internal.lean index 092837da..849977c3 100644 --- a/Complexitylib/Metacomplexity/MINKT/Internal.lean +++ b/Complexitylib/Metacomplexity/MINKT/Internal.lean @@ -51,7 +51,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : change (if clock = List.replicate clock.length true then some { output := output, time := clock.length } else none) = some inst at hdecode - rw [if_pos hclock] at hdecode + rw [ite_eq_left hclock] at hdecode cases hdecode calc bits = pair output clock := hbits @@ -62,7 +62,7 @@ theorem decode?_eq_some_iff_internal (bits : List Bool) (inst : Instance) : change (if clock = List.replicate clock.length true then some { output := output, time := clock.length } else none) = some inst at hdecode - rw [if_neg hclock] at hdecode + rw [ite_eq_right hclock] at hdecode contradiction · rintro rfl exact decode?_encode_internal inst diff --git a/Complexitylib/Metacomplexity/NisanWigderson/Encoding/Internal.lean b/Complexitylib/Metacomplexity/NisanWigderson/Encoding/Internal.lean index 67e6c4d3..d2636340 100644 --- a/Complexitylib/Metacomplexity/NisanWigderson/Encoding/Internal.lean +++ b/Complexitylib/Metacomplexity/NisanWigderson/Encoding/Internal.lean @@ -72,8 +72,8 @@ theorem decode?_encode_internal rw [hfirst, hsecond] at heq exact (design.coordinates output).injective heq unfold decode? - rw [dif_pos (length_encode_internal design), dif_pos hvalid, - dif_pos hinjective] + rw [dite_eq_left (length_encode_internal design), dite_eq_left hvalid, + dite_eq_left hinjective] congr 1 cases design with | mk coordinates => @@ -119,11 +119,11 @@ theorem encode_eq_of_decode?_eq_some_internal some ((decodeCoordinate? outputLength inputLength seedLength bits index.1.1 index.1.2).get (hvalid index.1.1 index.1.2)) := (Option.some_get (hvalid index.1.1 index.1.2)).symm - simp only [decodeCoordinate?, dif_pos hlength] at hcoordinate + simp only [decodeCoordinate?, dite_eq_left hlength] at hcoordinate have hcoordinateBits := Fin.toBits_eq_of_fromBits?_eq_some hcoordinate simp [encode, coordinateBitTable, decodedCoordinates] - simp only [decodeCoordinate?, dif_pos hlength] + simp only [decodeCoordinate?, dite_eq_left hlength] have hbit := congrArg (fun coordinateBits : List Bool => coordinateBits[index.2.val]?) hcoordinateBits simp [index, flatPosition] at hbit diff --git a/Complexitylib/Metacomplexity/NisanWigderson/Reconstruction/GlobalSampling/Internal.lean b/Complexitylib/Metacomplexity/NisanWigderson/Reconstruction/GlobalSampling/Internal.lean index 19f351d5..98b280f8 100644 --- a/Complexitylib/Metacomplexity/NisanWigderson/Reconstruction/GlobalSampling/Internal.lean +++ b/Complexitylib/Metacomplexity/NisanWigderson/Reconstruction/GlobalSampling/Internal.lean @@ -111,7 +111,7 @@ theorem goodReconstructionTrialProbability_eq_average_internal (∑ current : Fin outputLength, design.goodReconstructionAdviceProbability hardFunction test current agreementThreshold) / outputLength := by - letI : Nonempty (Fin outputLength) := ⟨⟨0, houtputLength⟩⟩ + let : Nonempty (Fin outputLength) := ⟨⟨0, houtputLength⟩⟩ let event := fun current (raw : RawReconstructionAdvice outputLength seedLength) => agreementThreshold ≤ @@ -125,9 +125,10 @@ theorem goodReconstructionTrialProbability_eq_average_internal intro current exact goodRawAdviceProbability_eq_internal design hardFunction test current agreementThreshold - simpa [goodReconstructionTrialProbability, goodReconstructionTrialEvent, + simp only [goodReconstructionTrialProbability, goodReconstructionTrialEvent, reconstructionTrialAgreementProbability, reconstructionAdviceOfTrial, - event, hconditional, Fintype.card_fin] using haverage + event, hconditional, Fintype.card_fin] at haverage ⊢ + exact haverage theorem exists_orientation_sum_averageReconstructionAgreement_ge_internal {outputLength inputLength seedLength : ℕ} @@ -296,7 +297,7 @@ theorem repeatedGoodReconstructionTrialProbability_eq_one_sub_pow_internal agreementThreshold trials = 1 - (1 - design.goodReconstructionTrialProbability hardFunction test agreementThreshold) ^ trials := by - letI : Nonempty (ReconstructionTrial outputLength seedLength) := + let : Nonempty (ReconstructionTrial outputLength seedLength) := ⟨(⟨0, houtputLength⟩, (fun _ => false), (fun _ => false), false)⟩ exact uniformAtLeastOneProbability_eq_one_sub_pow_internal (design.goodReconstructionTrialEvent hardFunction test agreementThreshold) @@ -361,7 +362,7 @@ theorem exists_half_le_canonicalRepeatedGoodTrial_of_randomTest_internal obtain ⟨complement, hsingle, hdata⟩ := exists_goodReconstructionTrialProbability_ge_of_randomTest_internal houtputLength hdensity.le hlow hrandom hdense hbudget - letI : Nonempty (ReconstructionTrial outputLength seedLength) := + let : Nonempty (ReconstructionTrial outputLength seedLength) := ⟨(⟨0, houtputLength⟩, (fun _ => false), (fun _ => false), false)⟩ exact ⟨complement, half_le_uniformAtLeastOneProbability_of_singleDrawLower_internal diff --git a/Complexitylib/Metacomplexity/ScaledExponent/Internal.lean b/Complexitylib/Metacomplexity/ScaledExponent/Internal.lean index afaa97ac..e7179333 100644 --- a/Complexitylib/Metacomplexity/ScaledExponent/Internal.lean +++ b/Complexitylib/Metacomplexity/ScaledExponent/Internal.lean @@ -117,7 +117,7 @@ theorem floorMul_add_le_internal (scale : PositiveRationalScale) scale.floorMul (first + second) := by unfold floorMul rw [Nat.mul_add] - exact Nat.add_div_le_add_div _ _ _ + exact Nat.div_add_div_le_add_div theorem tendsto_floorMul_atTop_internal (scale : PositiveRationalScale) : Filter.Tendsto scale.floorMul Filter.atTop Filter.atTop := by diff --git a/Complexitylib/Metacomplexity/StatisticalTest/HybridPrediction/Internal.lean b/Complexitylib/Metacomplexity/StatisticalTest/HybridPrediction/Internal.lean index 8e6a23b4..cf6e65aa 100644 --- a/Complexitylib/Metacomplexity/StatisticalTest/HybridPrediction/Internal.lean +++ b/Complexitylib/Metacomplexity/StatisticalTest/HybridPrediction/Internal.lean @@ -112,9 +112,9 @@ theorem candidateAcceptanceProbability_eq_hybrid_internal have htransport := uniformProbability_equiv (candidateEquiv step) (fun randomness => generator.hybridOutput step.val randomness ∈ test) rw [uniformProbability_finArrowBool] at htransport - simpa [NextBitPrediction.candidateAcceptanceProbability, - testAtCandidate, hybridAcceptanceProbability, - hybridAcceptedRandomness] using htransport + simp [NextBitPrediction.candidateAcceptanceProbability, testAtCandidate, + hybridAcceptanceProbability, hybridAcceptedRandomness] + exact htransport theorem targetAcceptanceProbability_eq_nextHybrid_internal {seedLength outputLength : ℕ} @@ -139,8 +139,10 @@ theorem targetAcceptanceProbability_eq_nextHybrid_internal uniformProbability (Finset.univ.filter fun sample : CandidateBackground seedLength outputLength step × Bool => P sample.1 ∧ True) := by - simpa only [and_true, Finset.filter_true, uniformProbability_univ, - mul_one] using hproduct.symm + have h := hproduct.symm + simp only [and_true, Finset.filter_true, uniformProbability_univ, + mul_one] at h ⊢ + exact h rw [hduplicate] have htransport := uniformProbability_equiv (candidateEquiv step) (fun randomness => diff --git a/Complexitylib/Models/RandomAccessMachine/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Internal.lean index 87d7d68f..44e894b9 100644 --- a/Complexitylib/Models/RandomAccessMachine/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Internal.lean @@ -71,21 +71,21 @@ theorem step_halted {c : Cfg} (h : Halted P c) : step P c = c := by theorem run_halted {c : Cfg} (h : Halted P c) (fuel : ℕ) : run P fuel c = c := by cases fuel with | zero => rfl - | succ f => rw [run_succ, if_pos h] + | succ f => rw [run_succ, ite_eq_left h] /-- A halted configuration accumulates no logarithmic time. -/ theorem logTimeUpto_halted {c : Cfg} (h : Halted P c) (fuel : ℕ) : logTimeUpto P fuel c = 0 := by cases fuel with | zero => rfl - | succ f => rw [logTimeUpto_succ, if_pos h] + | succ f => rw [logTimeUpto_succ, ite_eq_left h] /-- A halted configuration accumulates no unit time. -/ theorem unitTimeUpto_halted {c : Cfg} (h : Halted P c) (fuel : ℕ) : unitTimeUpto P fuel c = 0 := by cases fuel with | zero => rfl - | succ f => rw [unitTimeUpto_succ, if_pos h] + | succ f => rw [unitTimeUpto_succ, ite_eq_left h] /-! ### Run/cost algebra -/ @@ -93,8 +93,8 @@ theorem unitTimeUpto_halted {c : Cfg} (h : Halted P c) (fuel : ℕ) : theorem run_one (c : Cfg) : run P 1 c = step P c := by rw [show (1 : ℕ) = 0 + 1 from rfl, run_succ] by_cases h : Halted P c - · rw [if_pos h, step_halted P h] - · rw [if_neg h, run_zero] + · rw [ite_eq_left h, step_halted P h] + · rw [ite_eq_right h, run_zero] /-- The run decomposes additively: `a + b` steps is `b` steps after `a` steps. -/ theorem run_add (a b : ℕ) (c : Cfg) : run P (a + b) c = run P b (run P a c) := by @@ -103,9 +103,9 @@ theorem run_add (a b : ℕ) (c : Cfg) : run P (a + b) c = run P b (run P a c) := | succ a ih => rw [Nat.succ_add, run_succ, run_succ] by_cases h : Halted P c - · rw [if_pos h, if_pos h] + · rw [ite_eq_left h, ite_eq_left h] exact (run_halted P h b).symm - · rw [if_neg h, if_neg h] + · rw [ite_eq_right h, ite_eq_right h] exact ih (step P c) /-- Running `n + 1` steps is one step after running `n` steps. -/ @@ -121,8 +121,8 @@ theorem logTimeUpto_add (a b : ℕ) (c : Cfg) : | succ a ih => rw [Nat.succ_add, logTimeUpto_succ, logTimeUpto_succ, run_succ] by_cases h : Halted P c - · rw [if_pos h, if_pos h, if_pos h, logTimeUpto_halted P h b] - · rw [if_neg h, if_neg h, if_neg h, ih (step P c)] + · rw [ite_eq_left h, ite_eq_left h, ite_eq_left h, logTimeUpto_halted P h b] + · rw [ite_eq_right h, ite_eq_right h, ite_eq_right h, ih (step P c)] ring /-- Unit time decomposes additively along the run. -/ @@ -134,8 +134,8 @@ theorem unitTimeUpto_add (a b : ℕ) (c : Cfg) : | succ a ih => rw [Nat.succ_add, unitTimeUpto_succ, unitTimeUpto_succ, run_succ] by_cases h : Halted P c - · rw [if_pos h, if_pos h, if_pos h, unitTimeUpto_halted P h b] - · rw [if_neg h, if_neg h, if_neg h, ih (step P c)] + · rw [ite_eq_left h, ite_eq_left h, ite_eq_left h, unitTimeUpto_halted P h b] + · rw [ite_eq_right h, ite_eq_right h, ite_eq_right h, ih (step P c)] ring /-- Once halted after `f` steps, extra fuel does not change the configuration. -/ @@ -185,8 +185,8 @@ theorem unitTimeUpto_le_logTimeUpto (fuel : ℕ) (c : Cfg) : | succ f ih => rw [unitTimeUpto_succ, logTimeUpto_succ] by_cases h : Halted P c - · rw [if_pos h, if_pos h] - · rw [if_neg h, if_neg h] + · rw [ite_eq_left h, ite_eq_left h] + · rw [ite_eq_right h, ite_eq_right h] have h1 : 1 ≤ stepLogCost P c := one_le_stepLogCost P c have h2 := ih (step P c) omega @@ -199,12 +199,12 @@ theorem unitTimeUpto_eq_of_not_halted (c : Cfg) (fuel : ℕ) | zero => simp | succ f ih => have h0 : ¬ Halted P c := h 0 (Nat.succ_pos f) - rw [unitTimeUpto_succ, if_neg h0] + rw [unitTimeUpto_succ, ite_eq_right h0] have hrec : unitTimeUpto P f (step P c) = f := by apply ih intro j hj have hstep : run P j (step P c) = run P (j + 1) c := by - rw [run_succ, if_neg h0] + rw [run_succ, ite_eq_right h0] rw [hstep] exact h (j + 1) (by omega) rw [hrec] @@ -235,7 +235,7 @@ theorem initRegs_finiteSupport (x : List Bool) : rw [not_lt] at hlt apply hi have hi0 : i ≠ 0 := by omega - simp only [initRegs, hi0, if_false, List.getElem?_eq_none (show x.length ≤ i - 1 by omega)] + simp only [initRegs, hi0, ite_false, List.getElem?_eq_none (show x.length ≤ i - 1 by omega)] /-- One instruction preserves finite support of the register file: each instruction writes at most one register. -/ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/DenseOverlay/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/DenseOverlay/Internal.lean index 3a10c663..6c722bbb 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/DenseOverlay/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/DenseOverlay/Internal.lean @@ -54,7 +54,7 @@ theorem write_coversZero_internal (overlay : Store) by_cases haddress : address = 0 · subst address simp - · simpa [Function.update, haddress, Ne.symm haddress] using hcovers + · simpa [CoversZero, Function.update, haddress, Ne.symm haddress] using hcovers theorem Snapshot.initial_decode_internal (input : List Bool) : (Snapshot.initial input).decode input = RAM.initCfg input := by @@ -185,8 +185,8 @@ theorem Snapshot.decode_run_internal (program : Program) (input : List Bool) unfold Snapshot.Halted RAM.Halted Snapshot.curInstr RAM.curInstr rfl by_cases hhalt : snapshot.Halted program - · rw [if_pos hhalt, if_pos (hhalted.mp hhalt)] - · rw [if_neg hhalt, if_neg (fun h => hhalt (hhalted.mpr h))] + · rw [ite_eq_left hhalt, ite_eq_left (hhalted.mp hhalt)] + · rw [ite_eq_right hhalt, ite_eq_right (fun h => hhalt (hhalted.mpr h))] rw [ih (snapshot.step program input) (Snapshot.step_canonical_internal program input snapshot hcanonical)] rw [Snapshot.decode_step_internal program input snapshot hcanonical] @@ -237,7 +237,7 @@ theorem write_length_le_internal (overlay : Store) (address value : ℕ) : · have ih' : (RegisterStore.write rest address (value + 1)).length ≤ rest.length + 1 := by simpa only [write] using ih - simp only [write, RegisterStore.write, haddress, if_false, + simp only [write, RegisterStore.write, haddress, ite_false, List.length_cons] omega @@ -277,9 +277,9 @@ theorem Snapshot.length_run_le_internal (program : Program) have hhalted : snapshot.Halted program ↔ RAM.Halted program (snapshot.decode input) := Iff.rfl by_cases hhalt : snapshot.Halted program - · rw [if_pos hhalt, if_pos (hhalted.mp hhalt)] + · rw [ite_eq_left hhalt, ite_eq_left (hhalted.mp hhalt)] omega - · rw [if_neg hhalt, if_neg (fun h => hhalt (hhalted.mpr h))] + · rw [ite_eq_right hhalt, ite_eq_right (fun h => hhalt (hhalted.mpr h))] have hstep := Snapshot.length_stepInstr_le_internal input (snapshot.curInstr program) snapshot have hstep' : (snapshot.step program input).overlay.length ≤ @@ -422,14 +422,14 @@ theorem Snapshot.encodedStoreLength_run_le_internal (program : Program) RAM.Halted program (snapshot.decode input) := Iff.rfl by_cases hhalt : snapshot.Halted program · have hramHalted := hhalted.mp hhalt - simp only [hhalt, hramHalted, if_true, RAM.unitTimeUpto, + simp only [hhalt, hramHalted, ite_true, RAM.unitTimeUpto, RAM.logTimeUpto] simp · have hramNotHalted : ¬RAM.Halted program (snapshot.decode input) := fun h => hhalt (hhalted.mpr h) - rw [if_neg hhalt] + rw [ite_eq_right hhalt] simp only [RAM.unitTimeUpto, RAM.logTimeUpto, hramNotHalted, - if_false] + ite_false] have hstep := Snapshot.encodedStoreLength_step_le_internal program input snapshot have hnextCanonical := Snapshot.step_canonical_internal diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Internal.lean index 03dbdca7..65166606 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Internal.lean @@ -224,7 +224,7 @@ private theorem initRegs_ne_zero_address_lt (input : List Bool) (address : ℕ) rw [not_lt] at hlt have haddress : address ≠ 0 := by omega apply hvalue - simp only [initRegs, haddress, if_false] + simp only [initRegs, haddress, ite_false] rw [List.getElem?_eq_none (show input.length ≤ address - 1 by omega)] private theorem initRegs_le_length_add_one (input : List Bool) (address : ℕ) : @@ -405,9 +405,9 @@ theorem Snapshot.run_canonical_internal (program : Program) (fuel : ℕ) | succ fuel ih => rw [Snapshot.run] by_cases hhalt : snapshot.Halted program - · rw [if_pos hhalt] + · rw [ite_eq_left hhalt] exact hcanonical - · rw [if_neg hhalt] + · rw [ite_eq_right hhalt] exact ih (snapshot.step program) (Snapshot.step_canonical_internal program snapshot hcanonical) @@ -419,10 +419,10 @@ theorem Snapshot.decode_run_internal (program : Program) (fuel : ℕ) | succ fuel ih => rw [Snapshot.run, RAM.run] by_cases hhalt : snapshot.Halted program - · rw [if_pos hhalt, - if_pos ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt)] - · rw [if_neg hhalt, - if_neg (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt)] + · rw [ite_eq_left hhalt, + ite_eq_left ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt)] + · rw [ite_eq_right hhalt, + ite_eq_right (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt)] rw [ih (snapshot.step program) (Snapshot.step_canonical_internal program snapshot hcanonical)] rw [Snapshot.decode_step_internal program snapshot hcanonical] @@ -624,11 +624,11 @@ theorem Snapshot.length_run_le_internal (program : Program) (fuel : ℕ) | succ fuel ih => rw [Snapshot.run, RAM.unitTimeUpto] by_cases hhalt : snapshot.Halted program - · rw [if_pos hhalt, - if_pos ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt)] + · rw [ite_eq_left hhalt, + ite_eq_left ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt)] omega - · rw [if_neg hhalt, - if_neg (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt)] + · rw [ite_eq_right hhalt, + ite_eq_right (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt)] have hstep := Snapshot.length_stepInstr_le_internal (snapshot.curInstr program) snapshot have hstep' : (snapshot.step program).store.length ≤ @@ -651,13 +651,13 @@ theorem Snapshot.width_run_le_internal (program : Program) (fuel : ℕ) | succ fuel ih => rw [Snapshot.run, RAM.unitTimeUpto, RAM.logTimeUpto] by_cases hhalt : snapshot.Halted program - · rw [if_pos hhalt, - if_pos ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt), - if_pos ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt)] + · rw [ite_eq_left hhalt, + ite_eq_left ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt), + ite_eq_left ((Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt)] omega - · rw [if_neg hhalt, - if_neg (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt), - if_neg (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt)] + · rw [ite_eq_right hhalt, + ite_eq_right (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt), + ite_eq_right (mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt)] have hstepCanonical := Snapshot.step_canonical_internal program snapshot hcanonical have hrun := ih (snapshot.step program) hstepCanonical @@ -857,14 +857,14 @@ theorem Snapshot.encodedStoreLength_run_le_internal (program : Program) by_cases hhalt : snapshot.Halted program · have hramHalted := (Snapshot.halted_decode_iff_internal program snapshot).mpr hhalt - simp only [hhalt, hramHalted, if_true, RAM.unitTimeUpto, + simp only [hhalt, hramHalted, ite_true, RAM.unitTimeUpto, RAM.logTimeUpto] simp · have hramNotHalted : ¬RAM.Halted program snapshot.decode := mt (Snapshot.halted_decode_iff_internal program snapshot).mp hhalt - rw [if_neg hhalt] + rw [ite_eq_right hhalt] simp only [RAM.unitTimeUpto, RAM.logTimeUpto, hramNotHalted, - if_false] + ite_false] have hstep := encodedStoreLength_step_le program snapshot have hnextCanonical := Snapshot.step_canonical_internal program snapshot hcanonical diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/AddressEq/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/AddressEq/Internal.lean index c9c34957..841baa98 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/AddressEq/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/AddressEq/Internal.lean @@ -125,7 +125,8 @@ theorem decodedAddressEqTM_reachesIn_frame_internal {n : ℕ} input := inp₀ work := work₀ output := out₀ } finalCfg := by - simpa [decodedAddressEqTM, rewindTM, compareTM, finalCfg] using hfullReach + simp only [decodedAddressEqTM, rewindTM, compareTM, finalCfg] + exact hfullReach have haddressStartFinal : (finalCfg.work addressIdx).cells 0 = Γ.start := TM.work_cells_zero_eq_start_of_reachesIn (tm := decodedAddressEqTM addressIdx queryIdx resultIdx) addressIdx diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/DenseInputLookup/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/DenseInputLookup/Internal.lean index 01b6b58b..23ce0a23 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/DenseInputLookup/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/DenseInputLookup/Internal.lean @@ -114,7 +114,7 @@ theorem capturePreviousInputBitTM_reachesIn_frame_internal {n : ℕ} simp [denseInputBitTape, TM.resetBinaryBlank, Tape.writeAndMove, Tape.write, Tape.move, TM.idleDir, Tape.read, Tape.init, Γ.ofBool] - · simp only [finalWork, Function.update_of_ne hi, hi, if_false] + · simp only [finalWork, Function.update_of_ne hi, hi, ite_false] exact (hwork i).writeAndMove_readBack_idle · exact houtput.writeAndMove_readBack_idle exact ⟨c₂, .step hstep₁ (.step hstep₂ .zero), rfl, rfl, rfl, rfl⟩ @@ -281,16 +281,16 @@ private theorem denseInputStepResult_eq (input : List Bool) (denseInputResultTape input address processed) = denseInputResultTape input address (processed + 1) := by by_cases hbefore : address ≤ processed - · rw [denseInputStepResult, if_neg (by omega)] + · rw [denseInputStepResult, ite_eq_right (by omega)] unfold denseInputResultTape - rw [if_neg haddress, if_pos hbefore, if_neg haddress, - if_pos (le_trans hbefore (by omega))] + rw [ite_eq_right haddress, ite_eq_left hbefore, ite_eq_right haddress, + ite_eq_left (le_trans hbefore (by omega))] · by_cases hcurrent : address = processed + 1 · subst address have hremaining : processed + 1 - processed = 1 := by omega - rw [denseInputStepResult, if_pos hremaining] + rw [denseInputStepResult, ite_eq_left hremaining] unfold denseInputResultTape - rw [if_neg haddress, if_pos (le_refl (processed + 1))] + rw [ite_eq_right haddress, ite_eq_left (le_refl (processed + 1))] congr 1 have hindex : processed + 1 - 1 = processed := by omega rw [hindex] @@ -298,10 +298,10 @@ private theorem denseInputStepResult_eq (input : List Bool) rfl · have hafter : processed + 1 < address := by omega have hremaining : address - processed ≠ 1 := by omega - rw [denseInputStepResult, if_neg hremaining] + rw [denseInputStepResult, ite_eq_right hremaining] unfold denseInputResultTape - rw [if_neg haddress, if_neg (by omega), if_neg haddress, - if_neg (Nat.not_le_of_lt hafter)] + rw [ite_eq_right haddress, ite_eq_right (by omega), ite_eq_right haddress, + ite_eq_right (Nat.not_le_of_lt hafter)] private def denseInputScanCfg {n : ℕ} (counter result : Fin n) (work₀ : Fin n → Tape) (out₀ : Tape) (input : List Bool) @@ -634,7 +634,7 @@ private theorem denseInputScanTM_body_run {n : ℕ} result = TM.resetBinaryBlank rw [denseInputWork_result] unfold denseInputResultTape - rw [if_neg haddress, if_neg (by omega)]) + rw [ite_eq_right haddress, ite_eq_right (by omega)]) (denseInputWork_parked counter result hne work₀ input address processed hwork) houtput have hdone : done = @@ -729,14 +729,14 @@ private theorem denseInputResultTape_final_hasBinaryNat (Complexity.RAM.initRegs input address) := by by_cases hindex : address ≤ input.length · have hlt : address - 1 < input.length := by omega - rw [denseInputResultTape, if_neg haddress, if_pos hindex] - rw [Complexity.RAM.initRegs, if_neg haddress, + rw [denseInputResultTape, ite_eq_right haddress, ite_eq_left hindex] + rw [Complexity.RAM.initRegs, ite_eq_right haddress, List.getElem?_eq_getElem hlt] simpa using denseInputBitTape_hasBinaryNat_internal (input[address - 1]'hlt) · have hnone : input[address - 1]? = none := List.getElem?_eq_none (by omega) - rw [denseInputResultTape, if_neg haddress, if_neg hindex] + rw [denseInputResultTape, ite_eq_right haddress, ite_eq_right hindex] simpa [Complexity.RAM.initRegs, haddress, hnone, TM.resetBinaryBlank] using Tape.init_move_right_hasBinaryNat 0 @@ -796,7 +796,7 @@ theorem denseInputScanTM_reachesIn_frame_internal {n : ℕ} · subst i rw [denseInputWork_result, hresult] unfold denseInputResultTape - rw [if_neg haddress, if_neg (by omega)] + rw [ite_eq_right haddress, ite_eq_right (by omega)] · rw [denseInputWork_other counter result work₀ input address 0 i hic hir] · rfl @@ -804,7 +804,8 @@ theorem denseInputScanTM_reachesIn_frame_internal {n : ℕ} rw [← hstart] at hrun let done := denseInputDoneCfg counter result work₀ out₀ input address refine ⟨done, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · simpa [denseInputScanTime, spec, denseInputLoopSpec, done] using hrun + · simp [denseInputScanTime, done] + exact hrun · rfl · rfl · rfl @@ -837,7 +838,7 @@ private theorem denseInputStepTime_le_width (address processed : ℕ) : TM.binaryPredTime_le_internal (address - processed - 1) have hwidth : (address - processed).size ≤ address.size := Nat.size_le_size (Nat.sub_le address processed) - rw [denseInputStepTime, if_neg hzero, if_neg hone] + rw [denseInputStepTime, ite_eq_right hzero, ite_eq_right hone] have hsucc : address - processed - 1 + 1 = address - processed := by omega rw [hsucc] at hpred @@ -943,7 +944,7 @@ theorem denseInputLookupTM_hoareTime_internal {n : ℕ} · rw [hdoneOther i hic hir] exact hcopiedParked i exact ⟨done, denseInputScanTime input.length address, le_rfl, - hreach, hhalt, hdoneHead, by simpa [inp₀] using hdoneCells, + hreach, hhalt, hdoneHead, by simp [inp₀]; exact hdoneCells, hdoneCounter, hdoneResult, hdoneOther, hdoneParked, hdoneOutput⟩ let stablePost : TM.TapePred n := fun inp work out => inp.cells = inp₀.cells ∧ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryAppend/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryAppend/Internal.lean index 1758a3ef..7fbe3448 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryAppend/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryAppend/Internal.lean @@ -226,8 +226,9 @@ theorem entryAppendRestoreTM_hoareTime_frame_internal work := fun i => TM.transitionTape (encoded.work i) output := TM.transitionTape encoded.output } tailFinal := by - simpa only [hencodedInputTransition, hencodedWorkTransition, - hencodedOutputTransition] using htailReach + simp only [hencodedInputTransition, hencodedWorkTransition, + hencodedOutputTransition] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (rewindEntryEncodeTM tapes.appendEncodeTapes) (TM.seqTM (TM.rewindWorkTM tapes.entry.query) @@ -241,9 +242,9 @@ theorem entryAppendRestoreTM_hoareTime_frame_internal ?_, hreach, ?_, ?_⟩ · unfold entryAppendRestoreTime omega - · change (entryAppendRestoreTM tapes).halted finalCfg - unfold entryAppendRestoreTM - rw [TM.phase2Wrap_halted_iff] + · unfold entryAppendRestoreTM + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff] exact htailHalt · refine ⟨?_, ?_, ?_⟩ · change restored.input = inp₀ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryCleanup/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryCleanup/Internal.lean index 83bc6df7..7e6b72c6 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryCleanup/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryCleanup/Internal.lean @@ -77,10 +77,9 @@ private theorem readable_target_content EntryMatchTapes.addressCounter, EntryMatchTapes.addressWidth, EntryMatchTapes.valueCounter, EntryMatchTapes.valueWidth, EntryMatchTapes.result, tapes.injective.eq_iff] using hmatch.address - · simpa [entryMissBits, EntryMatchTapes.address, EntryMatchTapes.value, - EntryMatchTapes.addressCounter, EntryMatchTapes.addressWidth, - EntryMatchTapes.valueCounter, EntryMatchTapes.valueWidth, - EntryMatchTapes.result, tapes.injective.eq_iff] using hmatch.value.2 + · simp [entryMissBits, EntryMatchTapes.address, EntryMatchTapes.value, + tapes.injective.eq_iff] + exact hmatch.value.2 · dsimp only [EntryMatchTapes.cleanupIdx] change (matchedWork tapes.addressCounter).HasBinaryContent (entryMissBits tapes entry queryBits tapes.addressCounter) @@ -89,7 +88,7 @@ private theorem readable_target_content tapes.ne (show (3 : Fin 9) ≠ 1 by decide) have hvalue : tapes.addressCounter ≠ tapes.value := tapes.ne (show (3 : Fin 9) ≠ 2 by decide) - rw [if_neg haddress, if_neg hvalue, if_pos rfl] + rw [ite_eq_right haddress, ite_eq_right hvalue, ite_eq_left rfl] exact hmatch.addressCounter.2 · simpa [entryMissBits, EntryMatchTapes.address, EntryMatchTapes.value, EntryMatchTapes.addressCounter, EntryMatchTapes.addressWidth, @@ -108,8 +107,8 @@ private theorem readable_target_content tapes.ne (show (5 : Fin 9) ≠ 3 by decide) have haddressWidth : tapes.valueCounter ≠ tapes.addressWidth := tapes.ne (show (5 : Fin 9) ≠ 4 by decide) - rw [if_neg haddress, if_neg hvalue, if_neg haddressCounter, - if_neg haddressWidth, if_pos rfl] + rw [ite_eq_right haddress, ite_eq_right hvalue, ite_eq_right haddressCounter, + ite_eq_right haddressWidth, ite_eq_left rfl] exact hmatch.valueCounter.2 · simpa [entryMissBits, EntryMatchTapes.address, EntryMatchTapes.value, EntryMatchTapes.addressCounter, EntryMatchTapes.addressWidth, diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/Internal.lean index 9466cf76..ded5debc 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/Internal.lean @@ -153,8 +153,8 @@ theorem entryDecodeTM_reachesIn_frame_internal {n : ℕ} refine ⟨finalCfg, ?_, ?_, hvalueInput.trans haddressInput, hvalueSource, ?_, ?_, hvalueTarget, hvalueStartFinal, ?_, ?_, hvalueCounterFinal, hvalueWidthFinal, ?_, hvalueOutput.trans haddressOutput⟩ - · simpa [entryDecodeTM, entryDecodeTime, addressTM, valueTM, finalCfg] using - hfullReach + · simp only [entryDecodeTM, entryDecodeTime, addressTM, valueTM, finalCfg] + exact hfullReach · exact (TM.phase2Wrap_halted_iff addressTM valueTM valueDone).2 hvalueHalt · change (valueDone.work tapes.address).HasBinaryPrefix entry.1.bits rw [hvalueFrame tapes.address (tapes.ne (by decide)) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/LinearInternal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/LinearInternal.lean index 48ce9325..ebdcc0ec 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/LinearInternal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryDecode/LinearInternal.lean @@ -154,8 +154,9 @@ theorem entryDecodeLinearTM_reachesIn_frame_internal {n : ℕ} refine ⟨finalCfg, ?_, ?_, hvalueInput.trans haddressInput, hvalueSource, ?_, ?_, hvalueTarget, hvalueStartFinal, ?_, hvalueMarkerFinal, ?_, hvalueOutput.trans haddressOutput⟩ - · simpa [entryDecodeLinearTM, entryDecodeLinearTime, addressTM, valueTM, - finalCfg] using hfullReach + · simp only [entryDecodeLinearTM, entryDecodeLinearTime, addressTM, valueTM, + finalCfg] + exact hfullReach · exact (TM.phase2Wrap_halted_iff addressTM valueTM valueDone).2 hvalueHalt · change (valueDone.work tapes.address).HasBinaryPrefix entry.1.bits rw [hvalueFrame tapes.address (tapes.ne (by decide)) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryEncode/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryEncode/Internal.lean index 9473108a..1b07d766 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryEncode/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryEncode/Internal.lean @@ -126,12 +126,11 @@ theorem entryEncodeTM_hoareTime_frame_internal refine ⟨finalCfg, addressTime + 1 + valueTime, ?_, hreach, ?_, ?_⟩ · unfold entryEncodeTime omega - · change (entryEncodeTM tapes).halted finalCfg - unfold entryEncodeTM + · unfold entryEncodeTM rw [TM.phase2Wrap_halted_iff] exact hvalueHalt · refine ⟨?_, ?_, ?_, ?_, hvalueSuffix, ?_, hvalueHeadFinal, ?_, ?_⟩ - · simpa [finalCfg] using hvalueInput.trans haddressInput + · simpa [TM.phase2Wrap, finalCfg] using hvalueInput.trans haddressInput · change (valueDone.work tapes.address).HasBinarySuffix [] rw [hvalueFrame tapes.address tapes.ne] exact haddressSuffix @@ -147,7 +146,7 @@ theorem entryEncodeTM_hoareTime_frame_internal · intro i hia hiv change valueDone.work i = work₀ i exact (hvalueFrame i hiv).trans (haddressFrame i hia) - · simpa [finalCfg, Entry.encode, List.append_assoc] using hvalueOutput + · simpa [TM.phase2Wrap, finalCfg, Entry.encode, List.append_assoc] using hvalueOutput theorem rewindEntryEncodeTM_hoareTime_frame_internal (tapes : EntryEncodeTapes n) (entry : Entry) @@ -252,12 +251,11 @@ theorem rewindEntryEncodeTM_hoareTime_frame_internal refine ⟨finalCfg, addressTime + 1 + valueTime, ?_, hreach, ?_, ?_⟩ · unfold rewindEntryEncodeTime omega - · change (rewindEntryEncodeTM tapes).halted finalCfg - unfold rewindEntryEncodeTM + · unfold rewindEntryEncodeTM rw [TM.phase2Wrap_halted_iff] exact hvalueHalt · refine ⟨?_, ?_, ?_, ?_, hvalueSuffix, ?_, hvalueHeadFinal, ?_, ?_⟩ - · simpa [finalCfg] using hvalueInput.trans haddressInput + · simpa [TM.phase1Wrap, TM.phase2Wrap, finalCfg] using hvalueInput.trans haddressInput · change (valueDone.work tapes.address).HasBinarySuffix [] rw [hvalueFrame tapes.address tapes.ne] exact haddressSuffix @@ -273,7 +271,8 @@ theorem rewindEntryEncodeTM_hoareTime_frame_internal · intro i hia hiv change valueDone.work i = work₀ i exact (hvalueFrame i hiv).trans (haddressFrame i hia) - · simpa [finalCfg, Entry.encode, List.append_assoc] using hvalueOutput + · simpa [TM.phase1Wrap, TM.phase2Wrap, finalCfg, Entry.encode, List.append_assoc] + using hvalueOutput theorem rewindEntryEncodeRestoreTM_hoareTime_frame_internal (tapes : EntryEncodeTapes n) (entry : Entry) (emitted : List Bool) @@ -457,8 +456,8 @@ theorem rewindEntryEncodeRestoreTM_hoareTime_frame_internal work := fun i => TM.transitionTape (encoded.work i) output := TM.transitionTape encoded.output } tailFinal := by - simpa only [hencodedInputTransition, hencodedWorkTransition, - hencodedOutputTransition] using htailReach + rw [hencodedInputTransition, hencodedWorkTransition, hencodedOutputTransition] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (rewindEntryEncodeTM tapes) (TM.seqTM (TM.rewindWorkTM tapes.address) @@ -471,9 +470,8 @@ theorem rewindEntryEncodeRestoreTM_hoareTime_frame_internal ?_, hreach, ?_, ?_⟩ · unfold rewindEntryEncodeRestoreTime omega - · change (rewindEntryEncodeRestoreTM tapes).halted finalCfg - unfold rewindEntryEncodeRestoreTM - rw [TM.phase2Wrap_halted_iff] + · unfold rewindEntryEncodeRestoreTM + erw [TM.phase2Wrap_halted_iff] exact htailHalt · refine ⟨?_, hrestoredWork, ?_⟩ · change restored.input = inp₀ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryLookup/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryLookup/Internal.lean index 20ff15f8..d48d51bd 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryLookup/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryLookup/Internal.lean @@ -45,7 +45,7 @@ private theorem read_eq_matched intro heq exact hmiss prior (by simp) (congrArg Nat.bits heq) simp only [List.cons_append, RegisterStore.read] - rw [if_neg (Ne.symm hprior)] + rw [ite_eq_right (Ne.symm hprior)] apply ih intro candidate hcandidate exact hmiss candidate (by simp [hcandidate]) @@ -61,7 +61,7 @@ private theorem read_eq_zero intro heq exact hmiss entry (by simp) (congrArg Nat.bits heq) simp only [RegisterStore.read] - rw [if_neg (Ne.symm hentry)] + rw [ite_eq_right (Ne.symm hentry)] exact ih (fun candidate hcandidate => hmiss candidate (by simp [hcandidate])) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMatch/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMatch/Internal.lean index 069b314e..7ba66560 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMatch/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMatch/Internal.lean @@ -114,38 +114,38 @@ theorem entryMatchTM_reachesIn_frame_internal {n : ℕ} have hdecodeAddressWidth : (decodeDone.work tapes.addressWidth).HasBinaryNat 0 := by rw [hdecodeFrame tapes.addressWidth - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 0 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 2 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 3 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 5 by decide))] + (tapes.ne (show (4 : Fin 9) ≠ 0 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 2 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 3 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 5 by decide))] exact haddressWidth have hdecodeValueWidth : (decodeDone.work tapes.valueWidth).HasBinaryNat 0 := by rw [hdecodeFrame tapes.valueWidth - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 0 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 2 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 3 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 5 by decide))] + (tapes.ne (show (6 : Fin 9) ≠ 0 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 2 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 3 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 5 by decide))] exact hvalueWidth have hdecodeQuery : (decodeDone.work tapes.query).HasBinaryString queryBits := by rw [hdecodeFrame tapes.query - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 0 by decide)) - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 2 by decide)) - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 3 by decide)) - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 5 by decide))] + (tapes.ne (show (7 : Fin 9) ≠ 0 by decide)) + (tapes.ne (show (7 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (7 : Fin 9) ≠ 2 by decide)) + (tapes.ne (show (7 : Fin 9) ≠ 3 by decide)) + (tapes.ne (show (7 : Fin 9) ≠ 5 by decide))] exact hquery have hdecodeResult : (decodeDone.work tapes.result).HasBinaryPrefix [] := by rw [hdecodeFrame tapes.result - (by simpa using tapes.ne (show (8 : Fin 9) ≠ 0 by decide)) - (by simpa using tapes.ne (show (8 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (8 : Fin 9) ≠ 2 by decide)) - (by simpa using tapes.ne (show (8 : Fin 9) ≠ 3 by decide)) - (by simpa using tapes.ne (show (8 : Fin 9) ≠ 5 by decide))] + (tapes.ne (show (8 : Fin 9) ≠ 0 by decide)) + (tapes.ne (show (8 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (8 : Fin 9) ≠ 2 by decide)) + (tapes.ne (show (8 : Fin 9) ≠ 3 by decide)) + (tapes.ne (show (8 : Fin 9) ≠ 5 by decide))] exact hresult have hdecodeParked : ∀ i, TM.Parked (decodeDone.work i) := by intro i @@ -243,9 +243,9 @@ theorem entryMatchTM_reachesIn_frame_internal {n : ℕ} · subst i apply parked_of_hasBinarySuffix rw [hcompareFrame tapes.source - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (0 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (0 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (0 : Fin 9) ≠ 8 by decide))] simpa using hdecodeSource · by_cases hia : i = tapes.address · subst i @@ -255,41 +255,41 @@ theorem entryMatchTM_reachesIn_frame_internal {n : ℕ} · subst i apply parked_of_hasBinaryPrefix rw [hcompareFrame tapes.value - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (2 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (2 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValue · by_cases hiac : i = tapes.addressCounter · subst i apply parked_of_hasBinaryPrefix rw [hcompareFrame tapes.addressCounter - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (3 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (3 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] simpa using hdecodeAddressCounter · by_cases hiaw : i = tapes.addressWidth · subst i apply parked_of_hasBinaryNat rw [hcompareFrame tapes.addressWidth - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (4 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 8 by decide))] simpa using hdecodeAddressWidth · by_cases hivc : i = tapes.valueCounter · subst i apply parked_of_hasBinaryPrefix rw [hcompareFrame tapes.valueCounter - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (5 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (5 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValueCounter · by_cases hivw : i = tapes.valueWidth · subst i apply parked_of_hasBinaryNat rw [hcompareFrame tapes.valueWidth - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (6 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValueWidth · by_cases hiq : i = tapes.query · subst i @@ -312,52 +312,53 @@ theorem entryMatchTM_reachesIn_frame_internal {n : ℕ} hcompareOutput.trans hdecodeOutput⟩ · simp only [entryMatchTime] omega - · simpa [entryMatchTM, decodeTM, compareTM, finalCfg] using hfullReach + · simp only [entryMatchTM, decodeTM, compareTM, finalCfg] + exact hfullReach · exact (TM.phase2Wrap_halted_iff decodeTM compareTM compareDone).2 hcompareHalt · change (compareDone.work tapes.source).HasBinarySuffix rest rw [hcompareFrame tapes.source - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (0 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (0 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (0 : Fin 9) ≠ 8 by decide))] simpa using hdecodeSource · change (compareDone.work tapes.value).HasBinaryPrefix entry.2.bits rw [hcompareFrame tapes.value - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (2 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (2 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValue · change (compareDone.work tapes.value).cells 0 = Γ.start rw [hcompareFrame tapes.value - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (2 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (2 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValueStart · change (compareDone.work tapes.addressCounter).HasBinaryPrefix (List.replicate (bitlen entry.1) true) rw [hcompareFrame tapes.addressCounter - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (3 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (3 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] simpa using hdecodeAddressCounter · change (compareDone.work tapes.addressWidth).HasBinaryNat 0 rw [hcompareFrame tapes.addressWidth - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (4 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (4 : Fin 9) ≠ 8 by decide))] simpa using hdecodeAddressWidth · change (compareDone.work tapes.valueCounter).HasBinaryPrefix (List.replicate (bitlen entry.2) true) rw [hcompareFrame tapes.valueCounter - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (5 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (5 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValueCounter · change (compareDone.work tapes.valueWidth).HasBinaryNat 0 rw [hcompareFrame tapes.valueWidth - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 1 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 7 by decide)) - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (6 : Fin 9) ≠ 1 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 7 by decide)) + (tapes.ne (show (6 : Fin 9) ≠ 8 by decide))] simpa using hdecodeValueWidth · intro i his hia hiv hiac hiaw hivc hivw hiq hir change compareDone.work i = work₀ i @@ -465,45 +466,45 @@ theorem entryMatchReadTM_reachesIn_frame_internal {n : ℕ} ReadableEntryMatch tapes entry rest queryBits work₀ finalCfg.work := by constructor · rw [hpreserve tapes.source - (by simpa using tapes.ne (show (0 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (0 : Fin 9) ≠ 8 by decide))] exact hmatchSource · rw [hpreserve tapes.address - (by simpa using tapes.ne (show (1 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (1 : Fin 9) ≠ 8 by decide))] exact hmatchAddress · rw [hpreserve tapes.address - (by simpa using tapes.ne (show (1 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (1 : Fin 9) ≠ 8 by decide))] exact hmatchAddressStart · rw [hpreserve tapes.value - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] exact hmatchValue · rw [hpreserve tapes.value - (by simpa using tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (2 : Fin 9) ≠ 8 by decide))] exact hmatchValueStart · rw [hpreserve tapes.addressCounter - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] exact hmatchAddressCounter · rw [hpreserve tapes.addressCounter - (by simpa using tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (3 : Fin 9) ≠ 8 by decide))] exact hmatchAddressCounterStart · rw [hpreserve tapes.addressWidth - (by simpa using tapes.ne (show (4 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (4 : Fin 9) ≠ 8 by decide))] exact hmatchAddressWidth · rw [hpreserve tapes.valueCounter - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] exact hmatchValueCounter · rw [hpreserve tapes.valueCounter - (by simpa using tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (5 : Fin 9) ≠ 8 by decide))] exact hmatchValueCounterStart · rw [hpreserve tapes.valueWidth - (by simpa using tapes.ne (show (6 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (6 : Fin 9) ≠ 8 by decide))] exact hmatchValueWidth · rw [hpreserve tapes.query - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (7 : Fin 9) ≠ 8 by decide))] exact hmatchQuery · rw [hpreserve tapes.query - (by simpa using tapes.ne (show (7 : Fin 9) ≠ 8 by decide))] + (tapes.ne (show (7 : Fin 9) ≠ 8 by decide))] exact hmatchQueryStart - · simpa [resultBits] using hrewindResult + · exact hrewindResult · exact hresultStartFinal · exact hfinalParked · intro i @@ -519,7 +520,8 @@ theorem entryMatchReadTM_reachesIn_frame_internal {n : ℕ} hrewindInput.trans hmatchInput, hreadable, hrewindOutput.trans hmatchOutput⟩ · exact hfullTime - · simpa [entryMatchReadTM, matchTM, rewindTM, finalCfg] using hfullReach + · simp only [entryMatchReadTM, matchTM, rewindTM, finalCfg] + exact hfullReach · exact (TM.phase2Wrap_halted_iff matchTM rewindTM rewindDone).2 hrewindHalt diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMissCopy/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMissCopy/Internal.lean index c42babe9..d3eb388f 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMissCopy/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryMissCopy/Internal.lean @@ -53,13 +53,13 @@ private theorem entryMissCopiedWork_eq funext i by_cases hia : i = tapes.address · subst i - simp only [entryMissCopiedWork, if_pos] + simp only [entryMissCopiedWork, ite_eq_left] exact Tape.ext haddressHead haddressCells · by_cases hiv : i = tapes.value · subst i - simp only [entryMissCopiedWork, hia, if_false, if_pos] + simp only [entryMissCopiedWork, hia, ite_false, ite_eq_left] exact Tape.ext hvalueHead hvalueCells - · simp only [entryMissCopiedWork, hia, hiv, if_false] + · simp only [entryMissCopiedWork, hia, hiv, ite_false] exact hframe i hia hiv private theorem readableEntryMatch_rebase_after_copy @@ -234,9 +234,9 @@ theorem entryMissCopyTM_hoareTime_frame_internal (entryMissHeadBound entry queryBits initialWork tapes.value) + 1 + entryMissCleanupTime tapes entry queryBits copiedWork omega - · change (entryMissCopyTM tapes).halted finalCfg - unfold entryMissCopyTM - rw [TM.phase2Wrap_halted_iff] + · unfold entryMissCopyTM + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff] exact hcleanupHalt · have hreadyGlobal : EntryScanReady tapes rest queryBits initialWork cleaned.work := by @@ -255,7 +255,8 @@ theorem entryMissCopyTM_hoareTime_frame_internal haddressCounter haddressWidth hvalueCounter hvalueWidth hquery hresult)) refine ⟨?_, hreadyGlobal, ?_⟩ - · simpa [finalCfg] using hcleanedInput.trans hencodedInput + · simp [finalCfg] + exact hcleanedInput.trans hencodedInput · change cleaned.output.HasBinaryPrefix (emitted ++ Entry.encode entry) rw [hcleanedOutput] exact hencodedOutput diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryReplace/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryReplace/Internal.lean index 8aa571ec..b97f4f01 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryReplace/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryReplace/Internal.lean @@ -102,9 +102,9 @@ private theorem entryReplaceReadyWork_eq funext i by_cases hia : i = tapes.entry.address · subst i - simp only [entryReplaceReadyWork, if_pos] + simp only [entryReplaceReadyWork, ite_eq_left] exact Tape.ext haddressHead haddressCells - · simp only [entryReplaceReadyWork, hia, if_false] + · simp only [entryReplaceReadyWork, hia, ite_false] exact hframe i hia theorem entryReplaceCleanupTM_hoareTime_frame_internal @@ -289,8 +289,8 @@ theorem entryReplaceCleanupTM_hoareTime_frame_internal work := fun i => TM.transitionTape (encoded.work i) output := TM.transitionTape encoded.output } tailFinal := by - simpa only [hencodedInputTransition, hencodedWorkTransition, - hencodedOutputTransition] using htailReach + simp only [hencodedInputTransition, hencodedWorkTransition, hencodedOutputTransition] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (rewindEntryEncodeTM tapes.encodeTapes) (TM.seqTM (TM.rewindWorkTM tapes.replacement) @@ -308,9 +308,9 @@ theorem entryReplaceCleanupTM_hoareTime_frame_internal 1 + (newValue.bits.length + 1 + 2 + 1 + entryMissCleanupTime tapes.entry entry queryBits readyWork) omega - · change (entryReplaceCleanupTM tapes).halted finalCfg - unfold entryReplaceCleanupTM - rw [TM.phase2Wrap_halted_iff] + · unfold entryReplaceCleanupTM + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff] exact htailHalt · have hreadyGlobal : EntryScanReady tapes.entry rest queryBits initialWork cleaned.work := by @@ -338,7 +338,7 @@ theorem entryReplaceCleanupTM_hoareTime_frame_internal { head := entry.1.bits.length + 1, cells := (matchedWork tapes.replacement).cells } else matchedWork tapes.replacement) = matchedWork tapes.replacement - rw [if_neg hne] + rw [ite_eq_right hne] exact (hready.frame tapes.replacement (tapes.replacement_ne 0) (tapes.replacement_ne 1) (tapes.replacement_ne 2) (tapes.replacement_ne 3) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Bounds.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Bounds.lean index b477d72c..cccaeb2c 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Bounds.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Bounds.lean @@ -71,8 +71,7 @@ private theorem entryMissCleanupTime_canonical_le_linear {n : ℕ} (fun _ => 1 + matchTime) (entryMissTargets tapes) ≤ 7 * (1 + matchTime + 2 * (bitlen entry.1 + bitlen entry.2 + 1) + 9) + 1 := by - simpa [entryMissHeadBound, entryScanCanonicalWork, - TM.resetBinaryBlank, Tape.move, Tape.init] using hreset + exact hreset unfold entryMissCleanupTime entryMissHeadBound entryScanCanonicalWork simp only [Function.const_apply, TM.resetBinaryBlank, Tape.move, Tape.init, Nat.zero_add] diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Ctrl.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Ctrl.lean index 88ce2e1f..1dfb5943 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Ctrl.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryScan/Internal/Ctrl.lean @@ -69,10 +69,10 @@ private theorem entryScanTM_body_step some (entryScanBodyWrap tapes next) := by have hne : cfg.state ≠ (entryScanStepTM tapes.entry).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by + rw [TM.step, ite_eq_right (by simp [entryScanBodyWrap, entryScanTM])] simp only [entryScanBodyWrap, entryScanTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (entryScanStepTM tapes.entry).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -90,10 +90,10 @@ private theorem entryScanTM_pred_step some (entryScanPredWrap tapes next) := by have hne : cfg.state ≠ (TM.binaryPredTM tapes.count).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by + rw [TM.step, ite_eq_right (by simp [entryScanPredWrap, entryScanTM])] simp only [entryScanPredWrap, entryScanTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (TM.binaryPredTM tapes.count).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -129,7 +129,7 @@ theorem entryScanTM_step_test_zero_internal (entryScanTM tapes).step { state := .inl .test, input := inp, work := work, output := out } = some { state := .inl .done, input := inp, work := work, output := out } := by - rw [TM.step, if_neg (by simp [entryScanTM])] + rw [TM.step, ite_eq_right (by simp [entryScanTM])] simp only [entryScanTM, hcount, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) · exact hinput.move_idle @@ -147,7 +147,7 @@ theorem entryScanTM_step_test_positive_internal some (entryScanBodyWrap tapes { state := (entryScanStepTM tapes.entry).qstart input := inp, work := work, output := out }) := by - rw [TM.step, if_neg (by simp [entryScanTM])] + rw [TM.step, ite_eq_right (by simp [entryScanTM])] simp only [entryScanTM, hcount, ↓reduceIte, entryScanBodyWrap] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) · exact hinput.move_idle @@ -164,7 +164,7 @@ theorem entryScanTM_step_body_hit_internal (houtput : TM.Parked cfg.output) : (entryScanTM tapes).step (entryScanBodyWrap tapes cfg) = some (entryScanDoneCfg tapes cfg.input cfg.work cfg.output) := by - rw [TM.step, if_neg (by simp [entryScanBodyWrap, entryScanTM])] + rw [TM.step, ite_eq_right (by simp [entryScanBodyWrap, entryScanTM])] simp only [entryScanBodyWrap, entryScanDoneCfg, entryScanTM, hhalt, hresult, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -184,7 +184,7 @@ theorem entryScanTM_step_body_miss_internal some (entryScanPredWrap tapes { state := (TM.binaryPredTM tapes.count).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryScanBodyWrap, entryScanTM])] + rw [TM.step, ite_eq_right (by simp [entryScanBodyWrap, entryScanTM])] simp only [entryScanBodyWrap, entryScanTM, hhalt, hresult, ↓reduceIte, entryScanPredWrap] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -201,7 +201,7 @@ theorem entryScanTM_step_pred_halt_internal (houtput : TM.Parked cfg.output) : (entryScanTM tapes).step (entryScanPredWrap tapes cfg) = some (entryScanTestCfg tapes cfg.input cfg.work cfg.output) := by - rw [TM.step, if_neg (by simp [entryScanPredWrap, entryScanTM])] + rw [TM.step, ite_eq_right (by simp [entryScanPredWrap, entryScanTM])] simp only [entryScanPredWrap, entryScanTestCfg, entryScanTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Ctrl.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Ctrl.lean index 477ee886..14460adc 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Ctrl.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Ctrl.lean @@ -130,9 +130,9 @@ private theorem entryUpdateTM_match_step some (entryUpdateMatchWrap tapes next) := by have hne : cfg.state ≠ (entryMatchReadTM tapes.entry).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateMatchWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateMatchWrap, entryUpdateTM])] simp only [entryUpdateMatchWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (entryMatchReadTM tapes.entry).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -150,9 +150,9 @@ private theorem entryUpdateTM_miss_step some (entryUpdateMissWrap tapes next) := by have hne : cfg.state ≠ (entryMissCopyTM tapes.entry).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateMissWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateMissWrap, entryUpdateTM])] simp only [entryUpdateMissWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (entryMissCopyTM tapes.entry).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -170,9 +170,9 @@ private theorem entryUpdateTM_delete_step some (entryUpdateDeleteWrap tapes next) := by have hne : cfg.state ≠ (entryMissCleanupTM tapes.entry).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateDeleteWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateDeleteWrap, entryUpdateTM])] simp only [entryUpdateDeleteWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (entryMissCleanupTM tapes.entry).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -190,9 +190,9 @@ private theorem entryUpdateTM_replace_step some (entryUpdateReplaceWrap tapes next) := by have hne : cfg.state ≠ (entryReplaceCleanupTM tapes.replace).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateReplaceWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateReplaceWrap, entryUpdateTM])] simp only [entryUpdateReplaceWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (entryReplaceCleanupTM tapes.replace).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -210,9 +210,9 @@ private theorem entryUpdateTM_append_step some (entryUpdateAppendWrap tapes next) := by have hne : cfg.state ≠ (entryAppendRestoreTM tapes.replace).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateAppendWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateAppendWrap, entryUpdateTM])] simp only [entryUpdateAppendWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (entryAppendRestoreTM tapes.replace).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -230,9 +230,9 @@ private theorem entryUpdateTM_remaining_step some (entryUpdateRemainingWrap tapes next) := by have hne : cfg.state ≠ (TM.binaryPredTM tapes.remaining).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateRemainingWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateRemainingWrap, entryUpdateTM])] simp only [entryUpdateRemainingWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (TM.binaryPredTM tapes.remaining).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -250,9 +250,9 @@ private theorem entryUpdateTM_deleteCount_step some (entryUpdateDeleteCountWrap tapes next) := by have hne : cfg.state ≠ (TM.binaryPredTM tapes.resultCount).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateDeleteCountWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateDeleteCountWrap, entryUpdateTM])] simp only [entryUpdateDeleteCountWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (TM.binaryPredTM tapes.resultCount).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -270,9 +270,9 @@ private theorem entryUpdateTM_appendCount_step some (entryUpdateAppendCountWrap tapes next) := by have hne : cfg.state ≠ (TM.binarySuccTM tapes.resultCount).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [entryUpdateAppendCountWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateAppendCountWrap, entryUpdateTM])] simp only [entryUpdateAppendCountWrap, entryUpdateTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : (TM.binarySuccTM tapes.resultCount).δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -365,7 +365,7 @@ theorem entryUpdateTM_step_test_continue_internal some (entryUpdateMatchWrap tapes { state := (entryMatchReadTM tapes.entry).qstart input := inp, work := work, output := out }) := by - rw [TM.step, if_neg (by simp [entryUpdateTestCfg, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateTestCfg, entryUpdateTM])] simp only [entryUpdateTestCfg, entryUpdateTM, hremaining, ↓reduceIte, entryUpdateMatchWrap] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -382,7 +382,7 @@ theorem entryUpdateTM_step_test_found_internal (houtput : TM.Parked out) : (entryUpdateTM tapes).step (entryUpdateTestCfg tapes inp work out) = some (entryUpdateDoneCfg tapes inp work out) := by - rw [TM.step, if_neg (by simp [entryUpdateTestCfg, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateTestCfg, entryUpdateTM])] simp only [entryUpdateTestCfg, entryUpdateDoneCfg, entryUpdateTM, hremaining, hfound, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -400,7 +400,7 @@ theorem entryUpdateTM_step_test_zero_internal (houtput : TM.Parked out) : (entryUpdateTM tapes).step (entryUpdateTestCfg tapes inp work out) = some (entryUpdateDoneCfg tapes inp work out) := by - rw [TM.step, if_neg (by simp [entryUpdateTestCfg, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateTestCfg, entryUpdateTM])] simp only [entryUpdateTestCfg, entryUpdateDoneCfg, entryUpdateTM, hremaining, hfound, hreplacement, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -420,7 +420,7 @@ theorem entryUpdateTM_step_test_append_internal some (entryUpdateAppendWrap tapes { state := (entryAppendRestoreTM tapes.replace).qstart input := inp, work := work, output := out }) := by - rw [TM.step, if_neg (by simp [entryUpdateTestCfg, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateTestCfg, entryUpdateTM])] simp only [entryUpdateTestCfg, entryUpdateTM, hremaining, hfound, hreplacement, ↓reduceIte, entryUpdateAppendWrap] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -456,7 +456,7 @@ theorem entryUpdateTM_step_match_delete_internal input := cfg.input work := entryUpdateMarkFoundWork tapes cfg.work output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateMatchWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateMatchWrap, entryUpdateTM])] simp only [entryUpdateMatchWrap, entryUpdateDeleteWrap, entryUpdateTM, hhalt, hresult, hreplacement, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -470,7 +470,7 @@ theorem entryUpdateTM_step_match_delete_internal by_cases hi : i = tapes.found · subst i simp [entryUpdateMarkFoundWork] - · simp only [hi, if_false, + · simp only [hi, ite_false, entryUpdateMarkFoundWork_apply_ne tapes cfg.work i hi] exact (hwork i).writeAndMove_readBack_idle · exact houtput.writeAndMove_readBack_idle @@ -489,7 +489,7 @@ theorem entryUpdateTM_step_match_replace_internal input := cfg.input work := entryUpdateMarkFoundWork tapes cfg.work output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateMatchWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateMatchWrap, entryUpdateTM])] simp only [entryUpdateMatchWrap, entryUpdateReplaceWrap, entryUpdateTM, hhalt, hresult, hreplacement, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -503,7 +503,7 @@ theorem entryUpdateTM_step_match_replace_internal by_cases hi : i = tapes.found · subst i simp [entryUpdateMarkFoundWork] - · simp only [hi, if_false, + · simp only [hi, ite_false, entryUpdateMarkFoundWork_apply_ne tapes cfg.work i hi] exact (hwork i).writeAndMove_readBack_idle · exact houtput.writeAndMove_readBack_idle @@ -519,7 +519,7 @@ theorem entryUpdateTM_step_match_miss_internal some (entryUpdateMissWrap tapes { state := (entryMissCopyTM tapes.entry).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateMatchWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateMatchWrap, entryUpdateTM])] simp only [entryUpdateMatchWrap, entryUpdateMissWrap, entryUpdateTM, hhalt, hresult, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -538,7 +538,7 @@ theorem entryUpdateTM_step_miss_halt_internal some (entryUpdateRemainingWrap tapes { state := (TM.binaryPredTM tapes.remaining).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateMissWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateMissWrap, entryUpdateTM])] simp only [entryUpdateMissWrap, entryUpdateRemainingWrap, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -557,7 +557,7 @@ theorem entryUpdateTM_step_delete_halt_internal some (entryUpdateDeleteCountWrap tapes { state := (TM.binaryPredTM tapes.resultCount).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateDeleteWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateDeleteWrap, entryUpdateTM])] simp only [entryUpdateDeleteWrap, entryUpdateDeleteCountWrap, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -576,7 +576,7 @@ theorem entryUpdateTM_step_replace_halt_internal some (entryUpdateRemainingWrap tapes { state := (TM.binaryPredTM tapes.remaining).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateReplaceWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateReplaceWrap, entryUpdateTM])] simp only [entryUpdateReplaceWrap, entryUpdateRemainingWrap, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -595,7 +595,7 @@ theorem entryUpdateTM_step_append_halt_internal some (entryUpdateAppendCountWrap tapes { state := (TM.binarySuccTM tapes.resultCount).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateAppendWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateAppendWrap, entryUpdateTM])] simp only [entryUpdateAppendWrap, entryUpdateAppendCountWrap, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -612,7 +612,7 @@ theorem entryUpdateTM_step_remaining_halt_internal (houtput : TM.Parked cfg.output) : (entryUpdateTM tapes).step (entryUpdateRemainingWrap tapes cfg) = some (entryUpdateTestCfg tapes cfg.input cfg.work cfg.output) := by - rw [TM.step, if_neg (by simp [entryUpdateRemainingWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateRemainingWrap, entryUpdateTM])] simp only [entryUpdateRemainingWrap, entryUpdateTestCfg, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -631,7 +631,7 @@ theorem entryUpdateTM_step_deleteCount_halt_internal some (entryUpdateRemainingWrap tapes { state := (TM.binaryPredTM tapes.remaining).qstart input := cfg.input, work := cfg.work, output := cfg.output }) := by - rw [TM.step, if_neg (by simp [entryUpdateDeleteCountWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateDeleteCountWrap, entryUpdateTM])] simp only [entryUpdateDeleteCountWrap, entryUpdateRemainingWrap, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) @@ -648,7 +648,7 @@ theorem entryUpdateTM_step_appendCount_halt_internal (houtput : TM.Parked cfg.output) : (entryUpdateTM tapes).step (entryUpdateAppendCountWrap tapes cfg) = some (entryUpdateDoneCfg tapes cfg.input cfg.work cfg.output) := by - rw [TM.step, if_neg (by simp [entryUpdateAppendCountWrap, entryUpdateTM])] + rw [TM.step, ite_eq_right (by simp [entryUpdateAppendCountWrap, entryUpdateTM])] simp only [entryUpdateAppendCountWrap, entryUpdateDoneCfg, entryUpdateTM, hhalt, ↓reduceIte] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/End.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/End.lean index 53d72e2c..70847be9 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/End.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/End.lean @@ -89,11 +89,14 @@ theorem entryUpdateTerminal_internal { ready := hinv.ready replacement := hinv.replacement_eq remaining := hinv.remainingCount - found := by simpa [hnotmemStore] using hfoundZero + found := by simp [hnotmemStore]; exact hfoundZero resultCount := by - simpa [hcountEq] using hinv.resultCountTape + have h := hinv.resultCountTape + simp only [hcountEq] at h + exact h frame := hinv.frame } - · simpa [houtputEq] using houtput + · simp only [houtputEq] at houtput + exact houtput · have hreplacementRead : (work tapes.replacement).read ≠ Γ.blank := by intro hblank @@ -214,7 +217,10 @@ theorem entryUpdateTerminal_internal (if address ∈ store.map Prod.fst then 1 else 0) rw [hotherWork tapes.found tapes.found_ne_resultCount] simpa [hnotmemStore] using hfoundZero - resultCount := by simpa [hcountEq] using hsuccCount + resultCount := by + have h := hsuccCount + simp only [hcountEq] at h + exact h frame := hfinalFrame } · simpa [entryUpdateDoneCfg] using hfinalOutput | true => @@ -239,10 +245,14 @@ theorem entryUpdateTerminal_internal { ready := hinv.ready replacement := hinv.replacement_eq remaining := hinv.remainingCount - found := by simpa [hmemStore] using hfoundOne - resultCount := by simpa [hcountEq] using hinv.resultCountTape + found := by simp [hmemStore]; exact hfoundOne + resultCount := by + have h := hinv.resultCountTape + simp only [hcountEq] at h + exact h frame := hinv.frame } - · simpa [houtputEq] using houtput + · simp only [houtputEq] at houtput + exact houtput end Machine diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Time.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Time.lean index 3adae3a8..78d03b9d 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Time.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/EntryUpdate/Internal/Time.lean @@ -149,7 +149,7 @@ private theorem entryMissCopiedWork_target_head · by_cases hvalue : i = tapes.entry.value · subst i simp [entryMissCopiedWork, entryUpdatePostEmitHead, haddress] - · simp only [entryMissCopiedWork, haddress, hvalue, if_false] + · simp only [entryMissCopiedWork, haddress, hvalue, ite_false] exact readable_other_cleanup_target_head tapes entry rest queryBits initialWork matchedWork hmatch i hi haddress hvalue @@ -171,7 +171,7 @@ private theorem entryReplaceReadyWork_target_head hmatch.value.1 · have haddress' : i ≠ tapes.replace.entry.address := by simpa using haddress - rw [entryReplaceReadyWork, if_neg haddress'] + rw [entryReplaceReadyWork, ite_eq_right haddress'] exact readable_other_cleanup_target_head tapes entry rest queryBits initialWork matchedWork hmatch i hi haddress hvalue diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Control.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Control.lean index 7449fcf3..9cbe3714 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Control.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Control.lean @@ -478,7 +478,7 @@ theorem zeroJumpInstructionTM_hoareTime_frame_internal change (work tapes.data.lhs).HasBinaryNat value at hoperand simpa only [Function.update_of_ne tapes.lhs_ne_pc] using hoperand · simpa only [targetTape, Function.update_self, newPC, value, - hzero, if_pos] using htarget + hzero, ite_eq_left] using htarget · intro i by_cases hi : i = tapes.pc · subst i @@ -512,7 +512,7 @@ theorem zeroJumpInstructionTM_hoareTime_frame_internal · rw [hframe tapes.data.lhs tapes.lhs_ne_pc] change (work tapes.data.lhs).HasBinaryNat value exact hlookupResult.destination - · simpa only [newPC, value, if_neg hnonzero] using hfinalPC + · simpa only [newPC, value, ite_eq_right hnonzero] using hfinalPC · intro i by_cases hi : i = tapes.pc · subst i diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseControl.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseControl.lean index 10ccf968..ee7e4107 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseControl.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseControl.lean @@ -163,7 +163,7 @@ private theorem denseControlResult_of_zeroJumpReset rw [hrole 10 (by decide)] rw [show lookupWork (tapes.data.lhsLookup.idx 10) = initialWork (tapes.data.lhsLookup.idx 10) by - simpa using hlookup.countSource] + exact hlookup.countSource] exact hinitial.lookup.countSource · change (finalWork (tapes.data.lhsLookup.idx 11)).HasBinaryNat 0 rw [hrole 11 (by decide)] @@ -258,9 +258,9 @@ theorem denseZeroJumpInstructionTM_hoareTime_frame have htarget : targetTape.HasBinaryNat target := Tape.init_move_right_hasBinaryNat target refine ⟨work, hlookupResult, ?_, ?_, ?_, ?_⟩ - · simpa only [Function.update_of_ne tapes.lhs_ne_pc, value] using - hlookupResult.destination - · simpa only [targetTape, Function.update_self, newPC, hzero, if_pos] + · simp only [Function.update_of_ne tapes.lhs_ne_pc] + exact hlookupResult.destination + · simpa only [targetTape, Function.update_self, newPC, hzero, ite_eq_left] using htarget · intro i by_cases hi : i = tapes.pc @@ -289,8 +289,8 @@ theorem denseZeroJumpInstructionTM_hoareTime_frame hfinalInput.trans hinp, ?_, hfinalOutput.trans hout⟩ refine ⟨work, hlookupResult, ?_, ?_, ?_, hframe⟩ · rw [hframe tapes.data.lhs tapes.lhs_ne_pc] - simpa only [value] using hlookupResult.destination - · simpa only [newPC, if_neg hnonzero] using hfinalPC + exact hlookupResult.destination + · simpa only [newPC, ite_eq_right hnonzero] using hfinalPC · intro i by_cases hi : i = tapes.pc · subst i diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDirect.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDirect.lean index 1dfb8810..f3d84c97 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDirect.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDirect.lean @@ -462,7 +462,7 @@ theorem denseDirectBinaryInstructionTM_hoareTime_frame rintro inp work out ⟨hinp, operands, hout⟩ rcases operands with ⟨lhsWork, hlhsResult, hrhsResult⟩ have hquery : (work tapes.update.entry.query).HasBinaryNat 0 := - ⟨hrhsResult.scanner.queryStart, by simpa using hrhsResult.scanner.query⟩ + ⟨hrhsResult.scanner.queryStart, by exact hrhsResult.scanner.query⟩ have hrun := TM.binaryAddConstTM_hoareTime_frame tapes.update.entry.query destination 0 inp work out hquery (by simpa [hinp] using hinput) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDispatch.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDispatch.lean index 472a1ff0..2c6dade6 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDispatch.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseDispatch.lean @@ -86,8 +86,8 @@ theorem denseDispatchProgramTM_hoareTime_frame have hcleanLhs : cleanWork tapes.liftedLhs = blankTape := by have hzero := hready.1.control.lookup.destination change (cleanWork tapes.liftedLhs).HasBinaryNat 0 at hzero - simpa only [blankTape] using - Tape.HasBinaryNat.eq_init_move_right hzero + simp only [blankTape] + exact Tape.HasBinaryNat.eq_init_move_right hzero have hwork₀Parked : ∀ i, TM.Parked (work₀ i) := by intro i rw [hready.2] @@ -453,7 +453,8 @@ theorem denseProgramStepTM_hoareTime_frame hprogram inp work out (by simpa [inp₀, blank] using hpre) have hsourceStart₀ : (work tapes.liftedSource).cells 0 = Γ.start := by - simpa [hpre.2.1] using hready.control.lookup.sourceStart + simp [hpre.2.1] + exact hready.control.lookup.sourceStart have hsourceStart := TM.work_cells_zero_eq_start_of_reachesIn tapes.liftedSource hreach hsourceStart₀ have hbufferStart₀ : @@ -478,7 +479,8 @@ theorem denseProgramStepTM_hoareTime_frame · simpa only [instruction, nextStore, nextPC, cleanupValues, remainingValue] using hresult · have hsourceHead₀ : (work tapes.liftedSource).head = 1 := by - simpa [hpre.2.1] using hready.control.lookup.sourceHead + simp [hpre.2.1] + exact hready.control.lookup.sourceHead rw [hsourceHead₀] at hsourceHead simp only [sourceBound, denseProgramStepSourceHeadBound] omega diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseImm.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseImm.lean index c4848893..ab3dad12 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseImm.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseImm.lean @@ -92,7 +92,7 @@ theorem denseImmediateInstructionTM_hoareTime_frame rw [show valueWork tapes.update.entry.query = initialWork tapes.update.entry.query by exact Function.update_of_ne hqueryReplacement _ initialWork] - exact ⟨hinitial.scanner.queryStart, by simpa using hinitial.scanner.query⟩ + exact ⟨hinitial.scanner.queryStart, by exact hinitial.scanner.query⟩ have hrun := TM.binaryAddConstTM_hoareTime_frame tapes.update.entry.query destination 0 inp₀ valueWork out₀ hqueryZero hinput diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseLoad.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseLoad.lean index 4d73ff4a..7e0be57a 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseLoad.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseLoad.lean @@ -239,7 +239,7 @@ theorem denseIndirectLoadInstructionTM_hoareTime_frame hloadedResult⟩, hout⟩ have hqueryZero : (work tapes.update.entry.query).HasBinaryNat 0 := ⟨hloadedResult.scanner.queryStart, by - simpa using hloadedResult.scanner.query⟩ + exact hloadedResult.scanner.query⟩ have hrun := TM.binaryAddConstTM_hoareTime_frame tapes.update.entry.query destination 0 inp work out hqueryZero (by simpa [hinp] using hinput) @@ -307,12 +307,9 @@ theorem denseIndirectLoadInstructionTM_hoareTime_frame (DenseOverlay.read input overlay (DenseOverlay.read input overlay addressRegister)) emittedBits updateWork inp₀ out₀ hvalid.1 hscanner - (by simpa only [updateWork, Function.update_of_ne hreplacementNe] using - hloadedResult.value) - (by simpa only [updateWork, Function.update_of_ne hremainingNe] using - hloadedResult.count) - (by simpa only [updateWork, Function.update_of_ne hfoundNe] using - hloadedResult.copyScratch) + (by simp only [updateWork, Function.update_of_ne hreplacementNe]; exact hloadedResult.value) + (by simp only [updateWork, Function.update_of_ne hremainingNe]; exact hloadedResult.count) + (by simp only [updateWork, Function.update_of_ne hfoundNe]; exact hloadedResult.copyScratch) (by simpa only [updateWork, Function.update_of_ne hresultCountNe] using hresultCount) hinput houtput diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseSimData.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseSimData.lean index 766fcfb7..51c42b8b 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseSimData.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseSimData.lean @@ -141,13 +141,13 @@ theorem denseExecuteInstructionTM_imm_hoareTime_frame intro slot fin_cases slot · exact ⟨houtcome.ready.queryStart, by - simpa [cleanupValues, denseInstructionCleanupValue, - instructionCleanupParentSlot] using houtcome.ready.query⟩ + simp [cleanupValues, denseInstructionCleanupValue, instructionCleanupParentSlot] + exact houtcome.ready.query⟩ · change (work tapes.data.update.replacement).HasBinaryNat (value + 1) rw [houtcome.replacement] exact htagValue - · simpa [cleanupValues, denseInstructionCleanupValue, - instructionCleanupParentSlot] using houtcome.found + · simp [cleanupValues, denseInstructionCleanupValue, instructionCleanupParentSlot] + exact houtcome.found · change (work tapes.data.lhs).HasBinaryNat 0 rw [houtcome.frame tapes.data.lhs (fun role => (tapes.data.update_ne_lhs role).symm), @@ -217,7 +217,8 @@ theorem denseExecuteInstructionTM_imm_hoareTime_frame exact hready.dbl refine ⟨hpc, ?_, hsourceContent, hcleanup, ?_, ?_, hshift, htmp, hdbl, houtcome.ready.parked⟩ - · simpa [nextStore] using houtcome.resultCount + · simp [nextStore] + exact houtcome.resultCount · simpa using houtcome.remaining · simpa [cleanupValues, denseInstructionCleanupValue] using houtcome.ready @@ -231,10 +232,9 @@ theorem denseExecuteInstructionTM_imm_hoareTime_frame (denseImmediateInstructionTM tapes.data destination value) (denseImmediateInstructionTime tapes.data overlay destination value) rfl hinput hdata - simpa [denseExecuteInstructionTM, denseExecuteInstructionTime, - DenseInstructionExecutionResult, denseInstructionStore, - denseInstructionPC, DenseOverlay.Snapshot.stepInstr, nextStore, - cleanupValues] using hall + simp [denseExecuteInstructionTM, denseExecuteInstructionTime, DenseInstructionExecutionResult, + denseInstructionStore, denseInstructionPC, DenseOverlay.Snapshot.stepInstr] + exact hall /-- Instruction constructor corresponding to a dense direct arithmetic kernel. -/ @@ -389,9 +389,8 @@ theorem denseExecuteInstructionTM_direct_hoareTime_frame fin_cases slot · exact ⟨houtcome.ready.queryStart, by cases op <;> - simpa [instruction, denseDirectInstruction, cleanupValues, - denseInstructionCleanupValue, instructionCleanupParentSlot] - using houtcome.ready.query⟩ + (simp [instruction, denseDirectInstruction, cleanupValues, denseInstructionCleanupValue, + instructionCleanupParentSlot]; exact houtcome.ready.query)⟩ · change (work tapes.data.update.replacement).HasBinaryNat _ rw [houtcome.replacement] cases op <;> @@ -399,9 +398,8 @@ theorem denseExecuteInstructionTM_direct_hoareTime_frame denseInstructionCleanupValue, lhs, rhs, BinaryInstrOp.eval] using htagValue · cases op <;> - simpa [instruction, denseDirectInstruction, cleanupValues, - denseInstructionCleanupValue, instructionCleanupParentSlot] - using houtcome.found + (simp [instruction, denseDirectInstruction, cleanupValues, denseInstructionCleanupValue, + instructionCleanupParentSlot]; exact houtcome.found) · change (work tapes.data.lhs).HasBinaryNat _ rw [houtcome.frame tapes.data.lhs (fun role => (tapes.data.update_ne_lhs role).symm), @@ -452,11 +450,9 @@ theorem denseExecuteInstructionTM_direct_hoareTime_frame (denseDirectBinaryInstructionTime tapes.data op input overlay destination source₀ source₁) rfl hinput hdata cases op <;> - simpa [instruction, denseDirectInstruction, denseExecuteInstructionTM, - denseExecuteInstructionTime, DenseInstructionExecutionResult, - denseInstructionStore, denseInstructionPC, - DenseOverlay.Snapshot.stepInstr, nextStore, cleanupValues, lhs, rhs, - BinaryInstrOp.eval] using hall + (simp [denseDirectInstruction, denseExecuteInstructionTM, denseExecuteInstructionTime, + DenseInstructionExecutionResult, denseInstructionStore, denseInstructionPC, + DenseOverlay.Snapshot.stepInstr] ; exact hall) /-- Dense direct addition has the common buffered instruction contract. -/ theorem denseExecuteInstructionTM_add_hoareTime_frame @@ -646,14 +642,16 @@ theorem denseExecuteInstructionTM_load_hoareTime_frame intro slot fin_cases slot · exact ⟨houtcome.ready.queryStart, by - simpa [instruction, cleanupValues, denseInstructionCleanupValue, - instructionCleanupParentSlot] using houtcome.ready.query⟩ + simp [instruction, cleanupValues, denseInstructionCleanupValue, + instructionCleanupParentSlot] + exact houtcome.ready.query⟩ · change (work tapes.data.update.replacement).HasBinaryNat _ rw [houtcome.replacement] simpa [instruction, cleanupValues, denseInstructionCleanupValue, address, value] using htagValue - · simpa [instruction, cleanupValues, denseInstructionCleanupValue, - instructionCleanupParentSlot] using houtcome.found + · simp [instruction, cleanupValues, denseInstructionCleanupValue, + instructionCleanupParentSlot] + exact houtcome.found · change (work tapes.data.lhs).HasBinaryNat _ rw [houtcome.frame tapes.data.lhs (fun role => (tapes.data.update_ne_lhs role).symm), @@ -739,11 +737,9 @@ theorem denseExecuteInstructionTM_load_hoareTime_frame (denseIndirectLoadInstructionTM tapes.data destination addressRegister) (denseIndirectLoadInstructionTime tapes.data input overlay destination addressRegister) rfl hinput hdata - simpa [instruction, denseExecuteInstructionTM, - denseExecuteInstructionTime, DenseInstructionExecutionResult, - denseInstructionStore, denseInstructionPC, - DenseOverlay.Snapshot.stepInstr, nextStore, cleanupValues, address, - value] using hall + simp [denseExecuteInstructionTM, denseExecuteInstructionTime, DenseInstructionExecutionResult, + denseInstructionStore, denseInstructionPC, DenseOverlay.Snapshot.stepInstr] + exact hall /-- A dense indirect store produces the generic buffered endpoint and advances the program counter. -/ @@ -874,15 +870,16 @@ theorem denseExecuteInstructionTM_store_hoareTime_frame intro slot fin_cases slot · exact ⟨houtcome.ready.queryStart, by - simpa [instruction, cleanupValues, denseInstructionCleanupValue, - instructionCleanupParentSlot, address] using - houtcome.ready.query⟩ + simp [instruction, cleanupValues, denseInstructionCleanupValue, + instructionCleanupParentSlot] + exact houtcome.ready.query⟩ · change (work tapes.data.update.replacement).HasBinaryNat _ rw [houtcome.replacement] simpa [instruction, cleanupValues, denseInstructionCleanupValue, value] using htagValue - · simpa [instruction, cleanupValues, denseInstructionCleanupValue, - instructionCleanupParentSlot, address] using houtcome.found + · simp [instruction, cleanupValues, denseInstructionCleanupValue, + instructionCleanupParentSlot] + exact houtcome.found · change (work tapes.data.lhs).HasBinaryNat _ rw [houtcome.frame tapes.data.lhs (fun role => (tapes.data.update_ne_lhs role).symm), @@ -979,11 +976,9 @@ theorem denseExecuteInstructionTM_store_hoareTime_frame (denseIndirectStoreInstructionTM tapes.data addressRegister source) (denseIndirectStoreInstructionTime tapes.data input overlay addressRegister source) rfl hinput hdata - simpa [instruction, denseExecuteInstructionTM, - denseExecuteInstructionTime, DenseInstructionExecutionResult, - denseInstructionStore, denseInstructionPC, - DenseOverlay.Snapshot.stepInstr, nextStore, cleanupValues, address, - value] using hall + simp [denseExecuteInstructionTM, denseExecuteInstructionTime, DenseInstructionExecutionResult, + denseInstructionStore, denseInstructionPC, DenseOverlay.Snapshot.stepInstr] + exact hall end Machine end RegisterStore diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseStore.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseStore.lean index 4612872e..eb475a32 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseStore.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/DenseStore.lean @@ -211,10 +211,10 @@ private theorem denseStoreUpdate_ready tapes.update.ne (by decide) refine ⟨hscanner, ?_, ?_, ?_, ?_, hscanner.parked⟩ · simpa only [updateWork, Function.update_self] using hvalueNat - · simpa only [updateWork, Function.update_of_ne hremainingReplacement, - queryWork, Function.update_of_ne hremainingQuery] using hrhs.count - · simpa only [updateWork, Function.update_of_ne hfoundReplacement, - queryWork, Function.update_of_ne hfoundQuery] using hrhs.copyScratch + · simp only [Function.update_of_ne hremainingReplacement, Function.update_of_ne hremainingQuery] + exact hrhs.count + · simp only [Function.update_of_ne hfoundReplacement, Function.update_of_ne hfoundQuery] + exact hrhs.copyScratch · simpa only [updateWork, Function.update_of_ne hresultCountReplacement, queryWork, Function.update_of_ne hresultCountQuery] using hresultCount @@ -277,8 +277,8 @@ theorem denseIndirectStoreInstructionTM_hoareTime_frame out (by simpa [address] using hvalues.1) ⟨(by rcases hops with ⟨_, _, hrhs⟩; exact hrhs.scanner.queryStart), (by rcases hops with ⟨_, _, hrhs⟩; - simpa using hrhs.scanner.query)⟩ - hvalues.2.2.1 (by simpa [hinp] using hinput) + exact hrhs.scanner.query)⟩ + hvalues.2.2.1 (by simp [hinp]; exact hinput) (fun i _ _ _ => hvalues.2.2.2 i) (by simpa [hout] using houtputParked) obtain ⟨final, time, htime, hreach, hhalt, hfinalInput, diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Direct.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Direct.lean index c7820f1f..aaadb855 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Direct.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Direct.lean @@ -145,26 +145,30 @@ theorem scanner_updateQuery_internal resultStart := ?_ parked := ?_ frame := by intro i _ _ _ _ _ _ _ _ _; rfl } - · simpa only [finalWork, Function.update_of_ne hsource] using hscanner.source - · simpa only [finalWork, Function.update_of_ne haddress] using hscanner.address - · simpa only [finalWork, Function.update_of_ne haddress] using - hscanner.addressStart - · simpa only [finalWork, Function.update_of_ne hvalue] using hscanner.value - · simpa only [finalWork, Function.update_of_ne hvalue] using - hscanner.valueStart - · simpa only [finalWork, Function.update_of_ne haddressCounter] using - hscanner.addressCounter - · simpa only [finalWork, Function.update_of_ne haddressWidth] using - hscanner.addressWidth - · simpa only [finalWork, Function.update_of_ne hvalueCounter] using - hscanner.valueCounter - · simpa only [finalWork, Function.update_of_ne hvalueWidth] using - hscanner.valueWidth + · simp only [Function.update_of_ne hsource] + exact hscanner.source + · simp only [Function.update_of_ne haddress] + exact hscanner.address + · simp only [Function.update_of_ne haddress] + exact hscanner.addressStart + · simp only [Function.update_of_ne hvalue] + exact hscanner.value + · simp only [Function.update_of_ne hvalue] + exact hscanner.valueStart + · simp only [Function.update_of_ne haddressCounter] + exact hscanner.addressCounter + · simp only [Function.update_of_ne haddressWidth] + exact hscanner.addressWidth + · simp only [Function.update_of_ne hvalueCounter] + exact hscanner.valueCounter + · simp only [Function.update_of_ne hvalueWidth] + exact hscanner.valueWidth · simpa only [finalWork, Function.update_self] using hnat.2 · simpa only [finalWork, Function.update_self] using hnat.1 - · simpa only [finalWork, Function.update_of_ne hresult] using hscanner.result - · simpa only [finalWork, Function.update_of_ne hresult] using - hscanner.resultStart + · simp only [Function.update_of_ne hresult] + exact hscanner.result + · simp only [Function.update_of_ne hresult] + exact hscanner.resultStart · intro i by_cases hi : i = tapes.update.entry.query · subst i @@ -254,14 +258,18 @@ private theorem directAddress_ready resultCount := ?_ parked := ?_ } · simpa only [Function.update_of_ne hqueryNeLhs] using hlhsValue - · simpa only [Function.update_of_ne hqueryNeRhs] using hrhs.destination + · simp only [Function.update_of_ne hqueryNeRhs] + exact hrhs.destination · simpa only [Function.update_of_ne hqueryNeReplacement, hreplacementEq] using hreplacement - · simpa only [Function.update_of_ne hqueryNeShift] using hrhs.querySource + · simp only [Function.update_of_ne hqueryNeShift] + exact hrhs.querySource · simpa only [Function.update_of_ne hqueryNeTmp, htmpEq] using htmp · simpa only [Function.update_of_ne hqueryNeDbl, hdblEq] using hdbl - · simpa only [Function.update_of_ne hqueryNeRemaining] using hrhs.count - · simpa only [Function.update_of_ne hqueryNeFound] using hrhs.copyScratch + · simp only [Function.update_of_ne hqueryNeRemaining] + exact hrhs.count + · simp only [Function.update_of_ne hqueryNeFound] + exact hrhs.copyScratch · simpa only [Function.update_of_ne hqueryNeResultCount] using hresultCount · exact (scanner_updateQuery_internal tapes store destination operandsWork hrhs.scanner).parked @@ -414,7 +422,7 @@ theorem directBinaryInstructionTM_hoareTime_frame_internal have hquery : (work tapes.update.entry.query).HasBinaryNat 0 := by refine ⟨?_, ?_⟩ · exact hrhsResult.scanner.queryStart - · simpa using hrhsResult.scanner.query + · exact hrhsResult.scanner.query have hrun := TM.binaryAddConstTM_hoareTime_frame tapes.update.entry.query destination 0 inp work out hquery (by simpa [hinp] using hinput) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Immediate.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Immediate.lean index 2ca02aed..e59f4d7e 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Immediate.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Immediate.lean @@ -161,43 +161,43 @@ theorem immediateUpdate_ready_internal resultStart := ?_ parked := ?_ frame := by intro i _ _ _ _ _ _ _ _ _; rfl } - · simpa only [updateWork, valueWork, Function.update_of_ne hsourceQuery, - Function.update_of_ne hsourceReplacement] using hinitial.scanner.source - · simpa only [updateWork, valueWork, Function.update_of_ne haddressQuery, - Function.update_of_ne haddressReplacement] using hinitial.scanner.address - · simpa only [updateWork, valueWork, Function.update_of_ne haddressQuery, - Function.update_of_ne haddressReplacement] using - hinitial.scanner.addressStart - · simpa only [updateWork, valueWork, Function.update_of_ne hvalueQuery, - Function.update_of_ne hvalueReplacement] using hinitial.scanner.value - · simpa only [updateWork, valueWork, Function.update_of_ne hvalueQuery, - Function.update_of_ne hvalueReplacement] using - hinitial.scanner.valueStart - · simpa only [updateWork, valueWork, - Function.update_of_ne haddressCounterQuery, - Function.update_of_ne haddressCounterReplacement] using - hinitial.scanner.addressCounter - · simpa only [updateWork, valueWork, - Function.update_of_ne haddressWidthQuery, - Function.update_of_ne haddressWidthReplacement] using - hinitial.scanner.addressWidth - · simpa only [updateWork, valueWork, - Function.update_of_ne hvalueCounterQuery, - Function.update_of_ne hvalueCounterReplacement] using - hinitial.scanner.valueCounter - · simpa only [updateWork, valueWork, - Function.update_of_ne hvalueWidthQuery, - Function.update_of_ne hvalueWidthReplacement] using - hinitial.scanner.valueWidth + · simp only [updateWork, valueWork, Function.update_of_ne hsourceQuery, + Function.update_of_ne hsourceReplacement] + exact hinitial.scanner.source + · simp only [updateWork, valueWork, Function.update_of_ne haddressQuery, + Function.update_of_ne haddressReplacement] + exact hinitial.scanner.address + · simp only [updateWork, valueWork, Function.update_of_ne haddressQuery, + Function.update_of_ne haddressReplacement] + exact hinitial.scanner.addressStart + · simp only [updateWork, valueWork, Function.update_of_ne hvalueQuery, + Function.update_of_ne hvalueReplacement] + exact hinitial.scanner.value + · simp only [updateWork, valueWork, Function.update_of_ne hvalueQuery, + Function.update_of_ne hvalueReplacement] + exact hinitial.scanner.valueStart + · simp only [updateWork, valueWork, Function.update_of_ne haddressCounterQuery, + Function.update_of_ne haddressCounterReplacement] + exact hinitial.scanner.addressCounter + · simp only [updateWork, valueWork, Function.update_of_ne haddressWidthQuery, + Function.update_of_ne haddressWidthReplacement] + exact hinitial.scanner.addressWidth + · simp only [updateWork, valueWork, Function.update_of_ne hvalueCounterQuery, + Function.update_of_ne hvalueCounterReplacement] + exact hinitial.scanner.valueCounter + · simp only [updateWork, valueWork, Function.update_of_ne hvalueWidthQuery, + Function.update_of_ne hvalueWidthReplacement] + exact hinitial.scanner.valueWidth · simpa only [updateWork, Function.update_self, queryTape] using hqueryNat.2 · simpa only [updateWork, Function.update_self, queryTape] using hqueryNat.1 - · simpa only [updateWork, valueWork, Function.update_of_ne hresultQuery, - Function.update_of_ne hresultReplacement] using hinitial.scanner.result - · simpa only [updateWork, valueWork, Function.update_of_ne hresultQuery, - Function.update_of_ne hresultReplacement] using - hinitial.scanner.resultStart + · simp only [updateWork, valueWork, Function.update_of_ne hresultQuery, + Function.update_of_ne hresultReplacement] + exact hinitial.scanner.result + · simp only [updateWork, valueWork, Function.update_of_ne hresultQuery, + Function.update_of_ne hresultReplacement] + exact hinitial.scanner.resultStart · intro i by_cases hiQuery : i = tapes.update.entry.query · subst i @@ -219,14 +219,13 @@ theorem immediateUpdate_ready_internal refine ⟨hscanner, ?_, ?_, ?_, ?_, hscanner.parked⟩ · simpa only [updateWork, Function.update_of_ne hreplacementQuery, valueWork, Function.update_self, valueTape] using hvalueNat - · simpa only [updateWork, Function.update_of_ne hremainingQuery, - valueWork, Function.update_of_ne hremainingReplacement] using - hinitial.count - · simpa only [updateWork, Function.update_of_ne hfoundQuery, valueWork, - Function.update_of_ne hfoundReplacement] using hinitial.copyScratch - · simpa only [updateWork, Function.update_of_ne hresultCountQuery, - valueWork, Function.update_of_ne hresultCountReplacement] using - hinitial.countSource + · simp only [Function.update_of_ne hremainingQuery, Function.update_of_ne hremainingReplacement] + exact hinitial.count + · simp only [Function.update_of_ne hfoundQuery, Function.update_of_ne hfoundReplacement] + exact hinitial.copyScratch + · simp only [Function.update_of_ne hresultCountQuery, + Function.update_of_ne hresultCountReplacement] + exact hinitial.countSource /-- Exact semantic and time contract for one immediate sparse assignment. -/ theorem immediateInstructionTM_hoareTime_frame_internal @@ -274,7 +273,7 @@ theorem immediateInstructionTM_hoareTime_frame_internal initialWork tapes.update.entry.query := Function.update_of_ne hqueryReplacement _ initialWork rw [heq] - exact ⟨hinitial.scanner.queryStart, by simpa using hinitial.scanner.query⟩ + exact ⟨hinitial.scanner.queryStart, by exact hinitial.scanner.query⟩ have hrun := TM.binaryAddConstTM_hoareTime_frame tapes.update.entry.query destination 0 inp₀ valueWork out₀ hqueryZero hinput diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Internal.lean index ab1a5d98..31600a10 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Internal.lean @@ -153,7 +153,7 @@ theorem binaryInstructionArithmeticTM_hoareTime_frame_internal refine ⟨hinp, ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩, hout⟩ · simpa using hlhs' · simpa using hrhs' - · simpa using hresult' + · exact hresult' · simpa using hshift' · simpa using htmp' · simpa using hdbl' diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Load.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Load.lean index ac51b7e4..3d8579d5 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Load.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Load.lean @@ -121,42 +121,42 @@ theorem scanner_updateQuery_of_indirect_internal have hnat := Tape.init_move_right_hasBinaryNat destination refine { source := by - simpa only [finalWork, Function.update_of_ne hsource] using - hscanner.source + simp only [Function.update_of_ne hsource] + exact hscanner.source address := by - simpa only [finalWork, Function.update_of_ne haddress] using - hscanner.address + simp only [Function.update_of_ne haddress] + exact hscanner.address addressStart := by - simpa only [finalWork, Function.update_of_ne haddress] using - hscanner.addressStart + simp only [Function.update_of_ne haddress] + exact hscanner.addressStart value := by - simpa only [finalWork, Function.update_of_ne hvalue] using - hscanner.value + simp only [Function.update_of_ne hvalue] + exact hscanner.value valueStart := by - simpa only [finalWork, Function.update_of_ne hvalue] using - hscanner.valueStart + simp only [Function.update_of_ne hvalue] + exact hscanner.valueStart addressCounter := by - simpa only [finalWork, Function.update_of_ne haddressCounter] using - hscanner.addressCounter + simp only [Function.update_of_ne haddressCounter] + exact hscanner.addressCounter addressWidth := by - simpa only [finalWork, Function.update_of_ne haddressWidth] using - hscanner.addressWidth + simp only [Function.update_of_ne haddressWidth] + exact hscanner.addressWidth valueCounter := by - simpa only [finalWork, Function.update_of_ne hvalueCounter] using - hscanner.valueCounter + simp only [Function.update_of_ne hvalueCounter] + exact hscanner.valueCounter valueWidth := by - simpa only [finalWork, Function.update_of_ne hvalueWidth] using - hscanner.valueWidth + simp only [Function.update_of_ne hvalueWidth] + exact hscanner.valueWidth query := by simpa only [finalWork, Function.update_self] using hnat.2 queryStart := by simpa only [finalWork, Function.update_self] using hnat.1 result := by - simpa only [finalWork, Function.update_of_ne hresult] using - hscanner.result + simp only [Function.update_of_ne hresult] + exact hscanner.result resultStart := by - simpa only [finalWork, Function.update_of_ne hresult] using - hscanner.resultStart + simp only [Function.update_of_ne hresult] + exact hscanner.resultStart parked := ?_ frame := by intro i _ _ _ _ _ _ _ _ _; rfl } intro i @@ -267,7 +267,7 @@ theorem indirectLoadInstructionTM_hoareTime_frame_internal hloadedResult⟩, hout⟩ have hqueryZero : (work tapes.update.entry.query).HasBinaryNat 0 := ⟨hloadedResult.scanner.queryStart, by - simpa using hloadedResult.scanner.query⟩ + exact hloadedResult.scanner.query⟩ have hrun := TM.binaryAddConstTM_hoareTime_frame tapes.update.entry.query destination 0 inp work out hqueryZero (by simpa [hinp] using hinput) @@ -334,12 +334,9 @@ theorem indirectLoadInstructionTM_hoareTime_frame_internal have hrun := entryUpdateTM_hoareTime_frame tapes.update store destination (RegisterStore.read store (RegisterStore.read store addressRegister)) emittedBits updateWork inp₀ out₀ hcanonical hscanner - (by simpa only [updateWork, Function.update_of_ne hreplacementNe] using - hloadedResult.value) - (by simpa only [updateWork, Function.update_of_ne hremainingNe] using - hloadedResult.count) - (by simpa only [updateWork, Function.update_of_ne hfoundNe] using - hloadedResult.copyScratch) + (by simp only [updateWork, Function.update_of_ne hreplacementNe]; exact hloadedResult.value) + (by simp only [updateWork, Function.update_of_ne hremainingNe]; exact hloadedResult.count) + (by simp only [updateWork, Function.update_of_ne hfoundNe]; exact hloadedResult.copyScratch) (by simpa only [updateWork, Function.update_of_ne hresultCountNe] using hresultCount) hinput houtput diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Control.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Control.lean index 2bb6e096..8cd83a33 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Control.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Control.lean @@ -121,7 +121,7 @@ private theorem finishControlInstructionTM_hoareTime_frame_internal intro slot fin_cases slot · exact ⟨hcontrolResult.ready.lookup.scanner.queryStart, - by simpa [instructionCleanupTape, instructionCleanupParentSlot] using + by simp [instructionCleanupTape, instructionCleanupParentSlot]; exact hcontrolResult.ready.lookup.scanner.query⟩ · change (work tapes.lifted.data.update.replacement).HasBinaryNat 0 rw [show work tapes.lifted.data.update.replacement = @@ -130,10 +130,10 @@ private theorem finishControlInstructionTM_hoareTime_frame_internal (fun role => (tapes.lifted.data.lhsLookup_ne_replacement role).symm)] exact hready.replacement - · simpa [instructionCleanupTape, instructionCleanupParentSlot] using - hcontrolResult.ready.lookup.copyScratch - · simpa [instructionCleanupTape, instructionCleanupParentSlot] using - hcontrolResult.ready.lookup.destination + · simp [instructionCleanupTape, instructionCleanupParentSlot] + exact hcontrolResult.ready.lookup.copyScratch + · simp [instructionCleanupTape, instructionCleanupParentSlot] + exact hcontrolResult.ready.lookup.destination · change (work tapes.lifted.data.rhs).HasBinaryNat 0 rw [show work tapes.lifted.data.rhs = initialWork tapes.lifted.data.rhs from hcontrolResult.frame _ (tapes.lifted.data_ne_pc 14) @@ -332,7 +332,8 @@ private theorem finishControlInstructionTM_hoareTime_frame_internal rw [hi, hw, ho] exact ⟨hinp, hcontrolResult, hout⟩) hcopy - simpa only [finishControlInstructionTM, bits, source, buffer] using hseq + simp only [finishControlInstructionTM] + exact hseq /-- Representation-independent form of the control-instruction finisher. Control instructions preserve the encoded store, leave zero on every cleanup diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Data.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Data.lean index d2f5f298..5e02c2f4 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Data.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Data.lean @@ -473,9 +473,8 @@ theorem retargetBufferedDataKernel_hoareTime_frame_internal (fun j => hparkedBase j) i exact ⟨hinp, hbuffer, hpc, hcount, hsourceContent, hcleanup, hremaining, by - simpa [ControlInstructionTapes.lifted] using - entryScanReady_lifted tapes.data.update.entry _ _ work hscanner - hparked, + simp [ControlInstructionTapes.lifted] + exact entryScanReady_lifted tapes.data.update.entry _ _ work hscanner hparked, hshift, htmp, hdbl, hparked, hout⟩ · exact le_rfl @@ -663,8 +662,8 @@ theorem executeInstructionTM_imm_hoareTime_frame intro slot fin_cases slot · exact ⟨houtcome.ready.queryStart, by - simpa [instructionCleanupValue, instructionCleanupTape, - instructionCleanupParentSlot] using houtcome.ready.query⟩ + simp [instructionCleanupValue, instructionCleanupTape, instructionCleanupParentSlot] + exact houtcome.ready.query⟩ · change ((fun i => work (Fin.castSucc i)) tapes.data.update.replacement).HasBinaryNat value rw [show (fun i => work (Fin.castSucc i)) @@ -681,8 +680,8 @@ theorem executeInstructionTM_imm_hoareTime_frame rw [hvalueWork] exact Function.update_self _ _ _] exact Tape.init_move_right_hasBinaryNat value - · simpa [instructionCleanupValue, instructionCleanupTape, - instructionCleanupParentSlot] using houtcome.found + · simp [instructionCleanupValue, instructionCleanupTape, instructionCleanupParentSlot] + exact houtcome.found · change ((fun i => work (Fin.castSucc i)) tapes.data.lhs).HasBinaryNat 0 rw [show (fun i => work (Fin.castSucc i)) tapes.data.lhs = updateWork tapes.data.lhs from @@ -755,12 +754,13 @@ theorem executeInstructionTM_imm_hoareTime_frame exact hready.dbl refine ⟨hinp, ?_, hpc, ?_, hsourceContent, hcleanup, ?_, ?_, hshift, htmp', hdbl', hparked, hout⟩ - · simpa [instructionStore, Snapshot.stepInstr] using hbuffer' + · simp [instructionStore, Snapshot.stepInstr] + exact hbuffer' · simpa [instructionStore, Snapshot.stepInstr] using hcount - · simpa [instructionRemainingValue] using houtcome.remaining - · simpa [ControlInstructionTapes.lifted] using - entryScanReady_lifted tapes.data.update.entry _ _ work - houtcome.ready hparked + · simp [instructionRemainingValue] + exact houtcome.remaining + · simp [ControlInstructionTapes.lifted] + exact entryScanReady_lifted tapes.data.update.entry _ _ work houtcome.ready hparked · exact le_rfl simpa only [executeInstructionTM, executeInstructionTime] using finishDataInstructionTM_hoareTime_frame_internal tapes @@ -897,8 +897,8 @@ theorem executeInstructionTM_direct_hoareTime_frame fin_cases slot · exact ⟨houtcome.ready.queryStart, by cases op <;> - simpa [directInstruction, instructionCleanupValue, - instructionCleanupParentSlot] using houtcome.ready.query⟩ + (simp [directInstruction, instructionCleanupValue, instructionCleanupParentSlot]; exact + houtcome.ready.query)⟩ · change (work tapes.data.update.replacement).HasBinaryNat _ rw [show work tapes.data.update.replacement = arithmeticWork tapes.data.update.replacement from @@ -907,8 +907,8 @@ theorem executeInstructionTM_direct_hoareTime_frame simpa [directInstruction, instructionCleanupValue, BinaryInstrOp.eval] using harithmetic.result · cases op <;> - simpa [directInstruction, instructionCleanupValue, - instructionCleanupParentSlot] using houtcome.found + (simp [directInstruction, instructionCleanupValue, instructionCleanupParentSlot]; exact + houtcome.found) · change (work tapes.data.lhs).HasBinaryNat _ rw [houtcome.frame tapes.data.lhs (fun role => (tapes.data.update_ne_lhs role).symm)] @@ -1120,8 +1120,8 @@ theorem executeInstructionTM_load_hoareTime_frame intro slot fin_cases slot · exact ⟨houtcome.ready.queryStart, by - simpa [instruction, instructionCleanupValue, - instructionCleanupParentSlot] using houtcome.ready.query⟩ + simp [instruction, instructionCleanupValue, instructionCleanupParentSlot] + exact houtcome.ready.query⟩ · change (work tapes.data.update.replacement).HasBinaryNat _ rw [show work tapes.data.update.replacement = updateWork tapes.data.update.replacement from houtcome.replacement, @@ -1131,8 +1131,8 @@ theorem executeInstructionTM_load_hoareTime_frame exact Function.update_of_ne (tapes.data.update.ne (by decide)) _ _] exact hloaded.value - · simpa [instruction, instructionCleanupValue, - instructionCleanupParentSlot] using houtcome.found + · simp [instruction, instructionCleanupValue, instructionCleanupParentSlot] + exact houtcome.found · change (work tapes.data.lhs).HasBinaryNat _ rw [show work tapes.data.lhs = updateWork tapes.data.lhs from houtcome.frame tapes.data.lhs (fun role => @@ -1312,16 +1312,16 @@ theorem executeInstructionTM_store_hoareTime_frame intro slot fin_cases slot · exact ⟨houtcome.ready.queryStart, by - simpa [instruction, instructionCleanupValue, - instructionCleanupParentSlot] using houtcome.ready.query⟩ + simp [instruction, instructionCleanupValue, instructionCleanupParentSlot] + exact houtcome.ready.query⟩ · change (work tapes.data.update.replacement).HasBinaryNat _ rw [show work tapes.data.update.replacement = updateWork tapes.data.update.replacement from houtcome.replacement, hupdateWork, Function.update_self] exact Tape.init_move_right_hasBinaryNat (RegisterStore.read store source) - · simpa [instruction, instructionCleanupValue, - instructionCleanupParentSlot] using houtcome.found + · simp [instruction, instructionCleanupValue, instructionCleanupParentSlot] + exact houtcome.found · change (work tapes.data.lhs).HasBinaryNat _ rw [show work tapes.data.lhs = updateWork tapes.data.lhs from houtcome.frame tapes.data.lhs (fun role => diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Defs.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Defs.lean index 08e2a6b5..d66a77a9 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Defs.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Defs.lean @@ -72,7 +72,7 @@ theorem liftedSource_ne_buffer {n : ℕ} tapes.liftedSource ≠ tapes.buffer := by intro h have hval : tapes.data.update.entry.source.val = n := by - simpa [liftedSource, buffer, lifted] using congrArg Fin.val h + exact congrArg Fin.val h have hlt := tapes.data.update.entry.source.isLt omega diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Internal.lean index 462124b3..872235d3 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Sim/Internal.lean @@ -119,8 +119,8 @@ theorem dispatchProgramTM_hoareTime_of_execute_internal have hcleanLhs : cleanWork tapes.liftedLhs = blankTape := by have hzero := hready.1.control.lookup.destination change (cleanWork tapes.liftedLhs).HasBinaryNat 0 at hzero - simpa only [blankTape] using - Tape.HasBinaryNat.eq_init_move_right hzero + simp only [blankTape] + exact Tape.HasBinaryNat.eq_init_move_right hzero have hwork₀Parked : ∀ i, TM.Parked (work₀ i) := by intro i rw [hready.2] @@ -376,12 +376,12 @@ theorem bufferedCleanupTM_hoareTime_frame_internal instructionCleanupResetHeadBound sourceHeadBound slot := by intro slot fin_cases slot - · simpa using (hready.result.cleanup 0).2.1.le - · simpa using (hready.result.cleanup 1).2.1.le - · simpa using (hready.result.cleanup 2).2.1.le - · simpa using (hready.result.cleanup 3).2.1.le - · simpa using (hready.result.cleanup 4).2.1.le - · simpa using hready.result.remaining.2.1.le + · exact (hready.result.cleanup 0).2.1.le + · exact (hready.result.cleanup 1).2.1.le + · exact (hready.result.cleanup 2).2.1.le + · exact (hready.result.cleanup 3).2.1.le + · exact (hready.result.cleanup 4).2.1.le + · exact hready.result.remaining.2.1.le · exact hready.sourceHead have hreset := TM.resetBinaryWorkManyTM_hoareTime_frame targets resetBits resetHeads inp₀ initialWork out₀ @@ -471,8 +471,8 @@ theorem bufferedCleanupTM_hoareTime_frame_internal exact TM.resetBinaryWorkManyResult_eq_blank_of_mem initialWork targets _ (List.mem_ofFn.mpr ⟨slot, rfl⟩) have hresetSource : resetWork tapes.liftedSource = TM.resetBinaryBlank := by - simpa [instructionCleanupResetTape, instructionCleanupResetParentSlot, - ControlInstructionTapes.liftedSource] using hresetTarget 6 + simp [ControlInstructionTapes.liftedSource] + exact hresetTarget 6 have hrewoundSource : rewoundWork tapes.liftedSource = TM.resetBinaryBlank := by simp [rewoundWork, tapes.liftedSource_ne_buffer, hresetSource] @@ -1080,10 +1080,8 @@ theorem instructionCleanupTM_hoareTime_frame_internal have hgeneric := bufferedCleanupTM_hoareTime_frame_internal tapes store nextStore nextPC cleanupValues remainingValue sourceHeadBound initialWork inp₀ out₀ hgenericReady hinput houtput - simpa only [nextStore, nextPC, cleanupValues, remainingValue, - instructionCleanupTime, bufferedCleanupTime, - instructionCleanupResetBitsAt, bufferedCleanupResetBitsAt, - instructionCleanupResetBits, bufferedCleanupResetBits] using hgeneric + simp only [instructionCleanupTime, instructionCleanupResetBitsAt] + exact hgeneric /-- One selected instruction followed by cleanup realizes the next reusable sparse-snapshot boundary. -/ @@ -1135,7 +1133,8 @@ theorem programStepTM_hoareTime_frame_internal hprogram inp work out hpre have hsourceStart₀ : (work tapes.liftedSource).cells 0 = Γ.start := by - simpa [hpre.2.1] using hready.control.lookup.sourceStart + simp [hpre.2.1] + exact hready.control.lookup.sourceStart have hsourceStart := TM.work_cells_zero_eq_start_of_reachesIn tapes.liftedSource hreach hsourceStart₀ have hbufferStart₀ : @@ -1155,7 +1154,8 @@ theorem programStepTM_hoareTime_frame_internal bufferStart := hbufferStart sourceHead := ?_ } have hsourceHead₀ : (work tapes.liftedSource).head = 1 := by - simpa [hpre.2.1] using hready.control.lookup.sourceHead + simp [hpre.2.1] + exact hready.control.lookup.sourceHead rw [hsourceHead₀] at hsourceHead simp only [sourceBound, programStepSourceHeadBound] omega diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Store.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Store.lean index 8353c17c..cbaa5a26 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Store.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Instruction/Store.lean @@ -154,46 +154,41 @@ private theorem storeUpdate_ready tapes.update.ne (by decide) refine { source := by - simpa only [updateWork, queryWork, - Function.update_of_ne hsourceReplacement, - Function.update_of_ne hsourceQuery] using hrhs.scanner.source + simp only [updateWork, queryWork, Function.update_of_ne hsourceReplacement, + Function.update_of_ne hsourceQuery] + exact hrhs.scanner.source address := by - simpa only [updateWork, queryWork, - Function.update_of_ne haddressReplacement, - Function.update_of_ne haddressQuery] using hrhs.scanner.address + simp only [updateWork, queryWork, Function.update_of_ne haddressReplacement, + Function.update_of_ne haddressQuery] + exact hrhs.scanner.address addressStart := by - simpa only [updateWork, queryWork, - Function.update_of_ne haddressReplacement, - Function.update_of_ne haddressQuery] using - hrhs.scanner.addressStart + simp only [updateWork, queryWork, Function.update_of_ne haddressReplacement, + Function.update_of_ne haddressQuery] + exact hrhs.scanner.addressStart value := by - simpa only [updateWork, queryWork, - Function.update_of_ne hvalueReplacement, - Function.update_of_ne hvalueQuery] using hrhs.scanner.value + simp only [updateWork, queryWork, Function.update_of_ne hvalueReplacement, + Function.update_of_ne hvalueQuery] + exact hrhs.scanner.value valueStart := by - simpa only [updateWork, queryWork, - Function.update_of_ne hvalueReplacement, - Function.update_of_ne hvalueQuery] using hrhs.scanner.valueStart + simp only [updateWork, queryWork, Function.update_of_ne hvalueReplacement, + Function.update_of_ne hvalueQuery] + exact hrhs.scanner.valueStart addressCounter := by - simpa only [updateWork, queryWork, - Function.update_of_ne haddressCounterReplacement, - Function.update_of_ne haddressCounterQuery] using - hrhs.scanner.addressCounter + simp only [updateWork, queryWork, Function.update_of_ne haddressCounterReplacement, + Function.update_of_ne haddressCounterQuery] + exact hrhs.scanner.addressCounter addressWidth := by - simpa only [updateWork, queryWork, - Function.update_of_ne haddressWidthReplacement, - Function.update_of_ne haddressWidthQuery] using - hrhs.scanner.addressWidth + simp only [updateWork, queryWork, Function.update_of_ne haddressWidthReplacement, + Function.update_of_ne haddressWidthQuery] + exact hrhs.scanner.addressWidth valueCounter := by - simpa only [updateWork, queryWork, - Function.update_of_ne hvalueCounterReplacement, - Function.update_of_ne hvalueCounterQuery] using - hrhs.scanner.valueCounter + simp only [updateWork, queryWork, Function.update_of_ne hvalueCounterReplacement, + Function.update_of_ne hvalueCounterQuery] + exact hrhs.scanner.valueCounter valueWidth := by - simpa only [updateWork, queryWork, - Function.update_of_ne hvalueWidthReplacement, - Function.update_of_ne hvalueWidthQuery] using - hrhs.scanner.valueWidth + simp only [updateWork, queryWork, Function.update_of_ne hvalueWidthReplacement, + Function.update_of_ne hvalueWidthQuery] + exact hrhs.scanner.valueWidth query := by simpa only [updateWork, Function.update_of_ne hqueryReplacement, queryWork, @@ -203,14 +198,13 @@ private theorem storeUpdate_ready Function.update_of_ne hqueryReplacement, queryWork, Function.update_self, queryTape] using hqueryNat.1 result := by - simpa only [updateWork, queryWork, - Function.update_of_ne hresultReplacement, - Function.update_of_ne hresultQuery] using hrhs.scanner.result + simp only [updateWork, queryWork, Function.update_of_ne hresultReplacement, + Function.update_of_ne hresultQuery] + exact hrhs.scanner.result resultStart := by - simpa only [updateWork, queryWork, - Function.update_of_ne hresultReplacement, - Function.update_of_ne hresultQuery] using - hrhs.scanner.resultStart + simp only [updateWork, queryWork, Function.update_of_ne hresultReplacement, + Function.update_of_ne hresultQuery] + exact hrhs.scanner.resultStart parked := ?_ frame := by intro i _ _ _ _ _ _ _ _ _; rfl } intro i @@ -257,13 +251,10 @@ private theorem storeUpdate_ready tapes.update.ne (by decide) refine ⟨hscanner, ?_, ?_, ?_, ?_, hscanner.parked⟩ · simpa only [updateWork, Function.update_self, valueTape] using hvalueNat - · simpa only [updateWork, - Function.update_of_ne hremainingReplacement, queryWork, - Function.update_of_ne hremainingQuery] using hrhs.count - · simpa only [updateWork, - Function.update_of_ne hfoundReplacement, queryWork, - Function.update_of_ne hfoundQuery] using - hrhs.copyScratch + · simp only [Function.update_of_ne hremainingReplacement, Function.update_of_ne hremainingQuery] + exact hrhs.count + · simp only [Function.update_of_ne hfoundReplacement, Function.update_of_ne hfoundQuery] + exact hrhs.copyScratch · simpa only [updateWork, Function.update_of_ne hresultCountReplacement, queryWork, Function.update_of_ne hresultCountQuery] using hresultCount @@ -323,7 +314,7 @@ theorem indirectStoreInstructionTM_hoareTime_frame_internal out (by simpa [address] using hvalues.1) ⟨(by rcases hops with ⟨_, _, hrhs⟩; exact hrhs.scanner.queryStart), (by rcases hops with ⟨_, _, hrhs⟩; - simpa using hrhs.scanner.query)⟩ + exact hrhs.scanner.query)⟩ hvalues.2.2.1 (by simpa [hinp] using hinput) (fun i _ _ _ => hvalues.2.2.2 i) (by simpa [hout] using houtputParked) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Lookup/Internal/Reset.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Lookup/Internal/Reset.lean index 96a46eea..0fd6b0d0 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Lookup/Internal/Reset.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Lookup/Internal/Reset.lean @@ -59,26 +59,26 @@ private theorem found_reset_content · change (finalWork tapes.scan.entry.value).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address tapes.scan.entry.value) - simpa only [entryLookupFoundBits_one] using hreadable.value.2 + simpa only [Tape.HasBinaryContent, Γ.ofBool, entryLookupFoundBits_one] using hreadable.value.2 · change (finalWork tapes.scan.entry.addressCounter).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address tapes.scan.entry.addressCounter) - simpa only [entryLookupFoundBits_two] using + simpa only [Nat.zero_bits, Tape.HasBinaryContent, Γ.ofBool, entryLookupFoundBits_two] using hreadable.addressCounter.2 · change (finalWork tapes.scan.entry.addressWidth).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address tapes.scan.entry.addressWidth) - simpa only [entryLookupFoundBits_three] using + simpa only [Tape.HasBinaryContent, Γ.ofBool, Nat.zero_bits, entryLookupFoundBits_three] using hreadable.addressWidth.2.hasBinaryContent · change (finalWork tapes.scan.entry.valueCounter).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address tapes.scan.entry.valueCounter) - simpa only [entryLookupFoundBits_four] using + simpa only [Tape.HasBinaryContent, Γ.ofBool, Nat.zero_bits, entryLookupFoundBits_four] using hreadable.valueCounter.2 · change (finalWork tapes.scan.entry.valueWidth).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address tapes.scan.entry.valueWidth) - simpa only [entryLookupFoundBits_five] using + simpa only [Tape.HasBinaryContent, Nat.zero_bits, entryLookupFoundBits_five] using hreadable.valueWidth.2.hasBinaryContent · change (finalWork tapes.scan.entry.result).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address @@ -92,7 +92,7 @@ private theorem found_reset_content · change (finalWork tapes.scan.count).HasBinaryContent (entryLookupFoundBits tapes matched (rest.length + 1) address tapes.scan.count) - simpa only [EntryLookupRestoreTapes.scan_count, + simpa only [Nat.zero_bits, EntryLookupRestoreTapes.scan_count, entryLookupFoundBits_eight] using hfound.count.2.hasBinaryContent @@ -223,7 +223,7 @@ private theorem miss_reset_content exact hmiss.ready.query.hasBinaryContent · change (finalWork tapes.scan.count).HasBinaryContent (entryLookupMissBits tapes address tapes.scan.count) - simpa only [EntryLookupRestoreTapes.scan_count, + simpa only [Tape.HasBinaryContent, Nat.zero_bits, EntryLookupRestoreTapes.scan_count, entryLookupMissBits_eight] using hmiss.count.2.hasBinaryContent private theorem miss_reset_start diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Bounds/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Bounds/Internal.lean index c3c5be7c..25d88c43 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Bounds/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Bounds/Internal.lean @@ -271,8 +271,7 @@ private theorem entryMissCleanupTime_canonical_le {m : ℕ} (fun _ => 1 + entryMatchReadTime entry queryBits) (entryMissTargets tapes) ≤ 7 * (1 + entryMatchReadTime entry queryBits + 2 * bound + 9) + 1 := by - simpa [entryMissHeadBound, entryScanCanonicalWork, - TM.resetBinaryBlank, Tape.move, Tape.init] using hreset + exact hreset unfold entryMissCleanupTime entryMissHeadBound entryScanCanonicalWork simp only [Function.const_apply] simp only [TM.resetBinaryBlank, Tape.move, Tape.init] diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DecisionInternal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DecisionInternal.lean index 8e0b4a2c..e99bc54a 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DecisionInternal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DecisionInternal.lean @@ -130,7 +130,8 @@ theorem programDecisionTM_hoareTime_run_internal hinitInputParked.read_ne_start (fun i => (hinitWorkParked i).read_ne_start) hinitOutputParked.read_ne_start - simpa only [hi, hw, ho] using htailReach + simp only [hi, hw, ho] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (programInitTM tapes) (TM.seqTM (programLoopTM tapes program) (programOutputTM tapes)) @@ -142,9 +143,8 @@ theorem programDecisionTM_hoareTime_run_internal · unfold programDecisionTime dsimp only [initial, final] at hloopTime houtputTime ⊢ omega - · change (programDecisionTM tapes program).halted done - unfold programDecisionTM - rw [TM.phase2Wrap_halted_iff] + · unfold programDecisionTM + erw [TM.phase2Wrap_halted_iff] exact htailHalt · change outputDone.output = registerVerdictOutput (RegisterStore.read final.store 0) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseBoundsProof.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseBoundsProof.lean index 7cc5e02e..e3ce5015 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseBoundsProof.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseBoundsProof.lean @@ -374,11 +374,9 @@ private theorem denseOverlayLookupTime_le_volume {m : ℕ} (TM.binaryPredTime (RegisterStore.read overlay address - 1)) ≤ 90000 * denseLookupVolume inputLength overlay address := by apply max_le - · dsimp only at hvolume hfallback ⊢ - unfold denseLookupVolume at hvolume ⊢ + · unfold denseLookupVolume at hvolume ⊢ omega - · dsimp only at hvolume hpred' ⊢ - unfold denseLookupVolume at hvolume ⊢ + · unfold denseLookupVolume at hvolume ⊢ omega unfold denseOverlayLookupTime TM.branchWorkBlankTime omega @@ -1185,6 +1183,11 @@ private theorem bufferedCleanupTime_le_linear {m : ℕ} dsimp only [nextBits] at hnextBits hresetNext ⊢ omega +-- The per-slot cleanup values are covered by a fixed menu of bounds; the +-- `first` alternatives below are each needed by some instruction case, so +-- the unused-tactic linter's per-site view is too narrow here. +set_option linter.unusedTactic false in +set_option linter.unreachableTactic false in private theorem denseInstructionCleanupValue_bits_le (input : List Bool) (instruction : Instr) (pcValue : ℕ) (overlay : Store) (width : ℕ) @@ -1208,7 +1211,15 @@ private theorem denseInstructionCleanupValue_bits_le · exact hbits destination hdestination · exact hbits (value + 1) htag · simp only [denseInstructionCleanupValue] - split <;> simp + split <;> first + | (rw [Nat.size_eq_bits_len]; exact hdestination) + | (rw [Nat.size_eq_bits_len]; exact htag) + | (split_ifs <;> simp [Nat.zero_bits] <;> omega) + | (rw [Nat.size_eq_bits_len]; exact hlhs) + | (rw [Nat.size_eq_bits_len]; exact hrhs) + | (rw [Nat.size_eq_bits_len]; assumption) + | simp [Nat.zero_bits] + | (rw [Nat.size_eq_bits_len]; exact Nat.le_succ_of_le (by assumption)) · simp [denseInstructionCleanupValue] · simp [denseInstructionCleanupValue] | add destination source₀ source₁ => @@ -1231,11 +1242,22 @@ private theorem denseInstructionCleanupValue_bits_le intro slot fin_cases slot · exact hbits destination hdestination - · simpa only [lhs, rhs] using hbits (lhs + rhs + 1) htag · simp only [denseInstructionCleanupValue] - split <;> simp - · simpa only [lhs] using hbits lhs hlhs - · simpa only [rhs] using hbits rhs hrhs + exact hbits (lhs + rhs + 1) htag + · simp only [denseInstructionCleanupValue] + split <;> first + | (rw [Nat.size_eq_bits_len]; exact hdestination) + | (rw [Nat.size_eq_bits_len]; exact htag) + | (split_ifs <;> simp [Nat.zero_bits] <;> omega) + | (rw [Nat.size_eq_bits_len]; exact hlhs) + | (rw [Nat.size_eq_bits_len]; exact hrhs) + | (rw [Nat.size_eq_bits_len]; assumption) + | simp [Nat.zero_bits] + | (rw [Nat.size_eq_bits_len]; exact Nat.le_succ_of_le (by assumption)) + · simp only [denseInstructionCleanupValue] + exact hbits lhs hlhs + · simp only [denseInstructionCleanupValue] + exact hbits rhs hrhs | sub destination source₀ source₁ => simp only [RegisterStore.Instr.staticWidth] at hstatic simp only [Instr.logCost, DenseOverlay.Snapshot.decode, @@ -1262,9 +1284,18 @@ private theorem denseInstructionCleanupValue_bits_le intro slot fin_cases slot · exact hbits destination hdestination - · simpa only [lhs, rhs] using hbits (lhs - rhs + 1) htag · simp only [denseInstructionCleanupValue] - split <;> simp + exact hbits (lhs - rhs + 1) htag + · simp only [denseInstructionCleanupValue] + split <;> first + | (rw [Nat.size_eq_bits_len]; exact hdestination) + | (rw [Nat.size_eq_bits_len]; exact htag) + | (split_ifs <;> simp [Nat.zero_bits] <;> omega) + | (rw [Nat.size_eq_bits_len]; exact hlhs) + | (rw [Nat.size_eq_bits_len]; exact hrhs) + | (rw [Nat.size_eq_bits_len]; assumption) + | simp [Nat.zero_bits] + | (rw [Nat.size_eq_bits_len]; exact Nat.le_succ_of_le (by assumption)) · exact hbits lhs (by omega) · exact hbits rhs (by omega) | mul destination source₀ source₁ => @@ -1287,11 +1318,22 @@ private theorem denseInstructionCleanupValue_bits_le intro slot fin_cases slot · exact hbits destination hdestination - · simpa only [lhs, rhs] using hbits (lhs * rhs + 1) htag · simp only [denseInstructionCleanupValue] - split <;> simp - · simpa only [lhs] using hbits lhs hlhs - · simpa only [rhs] using hbits rhs hrhs + exact hbits (lhs * rhs + 1) htag + · simp only [denseInstructionCleanupValue] + split <;> first + | (rw [Nat.size_eq_bits_len]; exact hdestination) + | (rw [Nat.size_eq_bits_len]; exact htag) + | (split_ifs <;> simp [Nat.zero_bits] <;> omega) + | (rw [Nat.size_eq_bits_len]; exact hlhs) + | (rw [Nat.size_eq_bits_len]; exact hrhs) + | (rw [Nat.size_eq_bits_len]; assumption) + | simp [Nat.zero_bits] + | (rw [Nat.size_eq_bits_len]; exact Nat.le_succ_of_le (by assumption)) + · simp only [denseInstructionCleanupValue] + exact hbits lhs hlhs + · simp only [denseInstructionCleanupValue] + exact hbits rhs hrhs | load destination addressRegister => simp only [RegisterStore.Instr.staticWidth] at hstatic simp only [Instr.logCost, DenseOverlay.Snapshot.decode, @@ -1309,10 +1351,20 @@ private theorem denseInstructionCleanupValue_bits_le intro slot fin_cases slot · exact hbits destination hdestination - · simpa only [address, value] using hbits (value + 1) htag · simp only [denseInstructionCleanupValue] - split <;> simp - · simpa only [address] using hbits address haddress + exact hbits (value + 1) htag + · simp only [denseInstructionCleanupValue] + split <;> first + | (rw [Nat.size_eq_bits_len]; exact hdestination) + | (rw [Nat.size_eq_bits_len]; exact htag) + | (split_ifs <;> simp [Nat.zero_bits] <;> omega) + | (rw [Nat.size_eq_bits_len]; exact hlhs) + | (rw [Nat.size_eq_bits_len]; exact hrhs) + | (rw [Nat.size_eq_bits_len]; assumption) + | simp [Nat.zero_bits] + | (rw [Nat.size_eq_bits_len]; exact Nat.le_succ_of_le (by assumption)) + · simp only [denseInstructionCleanupValue] + exact hbits address haddress · simp [denseInstructionCleanupValue] | store addressRegister source => simp only [RegisterStore.Instr.staticWidth] at hstatic @@ -1330,12 +1382,24 @@ private theorem denseInstructionCleanupValue_bits_le le_trans (bitlen_succ_le value) (by omega) intro slot fin_cases slot - · simpa only [address] using hbits address haddress - · simpa only [value] using hbits (value + 1) htag · simp only [denseInstructionCleanupValue] - split <;> simp - · simpa only [address] using hbits address haddress - · simpa only [value] using hbits value (by omega) + exact hbits address haddress + · simp only [denseInstructionCleanupValue] + exact hbits (value + 1) htag + · simp only [denseInstructionCleanupValue] + split <;> first + | (rw [Nat.size_eq_bits_len]; exact hdestination) + | (rw [Nat.size_eq_bits_len]; exact htag) + | (split_ifs <;> simp [Nat.zero_bits] <;> omega) + | (rw [Nat.size_eq_bits_len]; exact hlhs) + | (rw [Nat.size_eq_bits_len]; exact hrhs) + | (rw [Nat.size_eq_bits_len]; assumption) + | simp [Nat.zero_bits] + | (rw [Nat.size_eq_bits_len]; exact Nat.le_succ_of_le (by assumption)) + · simp only [denseInstructionCleanupValue] + exact hbits address haddress + · simp only [denseInstructionCleanupValue] + exact hbits value (by omega) | jz source target => intro slot fin_cases slot <;> simp [denseInstructionCleanupValue] @@ -1510,15 +1574,15 @@ private theorem denseStepVolume_le_runScale_succ rw [hhalt] rfl unfold denseStepVolume denseStepWidth denseRunScale - rw [RAM.unitTimeUpto_succ, if_pos hramHalt, - RAM.logTimeUpto_succ, if_pos hramHalt] + rw [RAM.unitTimeUpto_succ, ite_eq_left hramHalt, + RAM.logTimeUpto_succ, ite_eq_left hramHalt] rw [hcost] nlinarith · have hramNotHalt : ¬RAM.Halted program (snapshot.decode input) := fun h => hhalt (hhalted.mpr h) unfold denseStepVolume denseStepWidth denseRunScale - rw [RAM.unitTimeUpto_succ, if_neg hramNotHalt, - RAM.logTimeUpto_succ, if_neg hramNotHalt] + rw [RAM.unitTimeUpto_succ, ite_eq_right hramNotHalt, + RAM.logTimeUpto_succ, ite_eq_right hramNotHalt] nlinarith private theorem denseRunScale_step_add_width_le @@ -1554,8 +1618,8 @@ private theorem denseRunScale_step_add_width_le have hdecode := DenseOverlay.Snapshot.decode_step program input snapshot hvalid.1 unfold denseRunScale denseStepWidth - rw [RAM.unitTimeUpto_succ, if_neg hramNotHalt, - RAM.logTimeUpto_succ, if_neg hramNotHalt, hdecode] + rw [RAM.unitTimeUpto_succ, ite_eq_right hramNotHalt, + RAM.logTimeUpto_succ, ite_eq_right hramNotHalt, hdecode] nlinarith private theorem denseDispatchHaltTime_le_width {m : ℕ} diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseDecisionProof.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseDecisionProof.lean index e0095b82..c3ee6089 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseDecisionProof.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseDecisionProof.lean @@ -137,7 +137,8 @@ theorem denseProgramDecisionTM_hoareTime_run_internal (fun i => (hinitWorkParked i).read_ne_start) hinitOutputParked.read_ne_start rw [hi, hw, ho] - simpa only [hinitInput] using htailReach + simp only [hinitInput] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (denseProgramInitTM tapes) (TM.seqTM (denseProgramLoopTM tapes program) @@ -151,9 +152,8 @@ theorem denseProgramDecisionTM_hoareTime_run_internal · unfold denseProgramDecisionTime dsimp only [initial, final] at hloopTime houtputTime ⊢ omega - · change (denseProgramDecisionTM tapes program).halted done - unfold denseProgramDecisionTM - rw [TM.phase2Wrap_halted_iff] + · unfold denseProgramDecisionTM + erw [TM.phase2Wrap_halted_iff] exact htailHalt · change outputDone.output = registerVerdictOutput (DenseOverlay.read input final.overlay 0) diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInitProof.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInitProof.lean index 7d374fb3..9c5a6b5e 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInitProof.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInitProof.lean @@ -52,10 +52,10 @@ private theorem denseInitialLengthLoopTM_body_step have hne : c.state ≠ (initialZeroBitTM tapes).qhalt := TM.state_ne_qhalt_of_step hstep rw [TM.step, - if_neg (by simp [denseInitialLengthWrap, denseInitialLengthLoopTM])] + ite_eq_right (by simp [denseInitialLengthWrap, denseInitialLengthLoopTM])] simp only [denseInitialLengthWrap, denseInitialLengthLoopTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize (initialZeroBitTM tapes).δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -87,7 +87,7 @@ private theorem denseInitialLengthLoopTM_step_scan_data work := c.work output := c.output } := by rw [TM.step, - if_neg (by rw [hstate]; simp [denseInitialLengthLoopTM])] + ite_eq_right (by rw [hstate]; simp [denseInitialLengthLoopTM])] simp only [denseInitialLengthLoopTM, hstate, hblank, TM.allReadBack, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr @@ -95,9 +95,9 @@ private theorem denseInitialLengthLoopTM_step_scan_data · simp [TM.idleDir, hstart, Tape.move] · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl - · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, if_neg houtput] + · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, ite_eq_right houtput] rfl private theorem denseInitialLengthLoopTM_step_scan_blank @@ -112,7 +112,7 @@ private theorem denseInitialLengthLoopTM_step_scan_blank work := c.work output := c.output } := by rw [TM.step, - if_neg (by rw [hstate]; simp [denseInitialLengthLoopTM])] + ite_eq_right (by rw [hstate]; simp [denseInitialLengthLoopTM])] simp only [denseInitialLengthLoopTM, hstate, hblank, TM.allReadBack, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr @@ -120,9 +120,9 @@ private theorem denseInitialLengthLoopTM_step_scan_blank · simp [TM.idleDir, Tape.move] · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl - · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, if_neg houtput] + · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, ite_eq_right houtput] rfl private theorem denseInitialLengthLoopTM_step_body_halt @@ -138,16 +138,16 @@ private theorem denseInitialLengthLoopTM_step_body_halt work := c.work output := c.output } := by rw [TM.step, - if_neg (by simp [denseInitialLengthWrap, denseInitialLengthLoopTM])] + ite_eq_right (by simp [denseInitialLengthWrap, denseInitialLengthLoopTM])] simp only [denseInitialLengthWrap, denseInitialLengthLoopTM, hhalt, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl - · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, if_neg houtput] + · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, ite_eq_right houtput] rfl theorem denseInitialLengthLoopTM_hoareTime_internal @@ -423,7 +423,8 @@ theorem denseProgramInitTM_hoareTime_internal habiWork rw [hworkEq] exact ⟨hiParked.read_ne_start, hiParked.1⟩ - · simpa [denseProgramSnapshotWork, sparseInitial] using habiWork + · simp [denseProgramSnapshotWork] + exact habiWork · exact habiOutput.trans hemitOutputBlank obtain ⟨rewindDone, rewindTime, hrewindTime, hrewindReach, hrewindHalt, hrewindHead, hrewindCells, hrewindWork, @@ -476,8 +477,8 @@ theorem denseProgramInitTM_hoareTime_internal work := fun i => TM.transitionTape (emitDone.work i) output := TM.transitionTape emitDone.output } abiRewindDone := by - simpa only [hemitInputTransition, hemitWorkTransition, - hemitOutputTransition] using habiRewindReach + simp only [hemitInputTransition, hemitWorkTransition, hemitOutputTransition] + exact habiRewindReach have emitTailReach := TM.seqTM_reachesIn_of_reachesIn (initialLengthEmitTM tapes) (TM.seqTM (initialAbiInstallTM tapes) TM.rewindInputTM) @@ -489,7 +490,7 @@ theorem denseProgramInitTM_hoareTime_internal (TM.seqTM (initialLengthEmitTM tapes) (TM.seqTM (initialAbiInstallTM tapes) TM.rewindInputTM)).halted emitTailDone := by - rw [TM.phase2Wrap_halted_iff] + erw [TM.phase2Wrap_halted_iff] exact habiRewindHalt obtain ⟨hloopInputTransition, hloopWorkTransition, hloopOutputTransition⟩ := @@ -509,8 +510,8 @@ theorem denseProgramInitTM_hoareTime_internal work := fun i => TM.transitionTape (loopDone.work i) output := TM.transitionTape loopDone.output } emitTailDone := by - simpa only [hloopInputTransition, hloopWorkTransition, - hloopOutputTransition] using emitTailReach + simp only [hloopInputTransition, hloopWorkTransition, hloopOutputTransition] + exact emitTailReach have loopTailReach := TM.seqTM_reachesIn_of_reachesIn (denseInitialLengthLoopTM tapes) (TM.seqTM (initialLengthEmitTM tapes) @@ -525,7 +526,7 @@ theorem denseProgramInitTM_hoareTime_internal (TM.seqTM (initialLengthEmitTM tapes) (TM.seqTM (initialAbiInstallTM tapes) TM.rewindInputTM))).halted loopTailDone := by - rw [TM.phase2Wrap_halted_iff] + erw [TM.phase2Wrap_halted_iff] exact emitTailHalt obtain ⟨hsetupInputTransition, hsetupWorkTransition, hsetupOutputTransition⟩ := @@ -548,8 +549,8 @@ theorem denseProgramInitTM_hoareTime_internal work := fun i => TM.transitionTape (setupDone.work i) output := TM.transitionTape setupDone.output } loopTailDone := by - simpa only [hsetupInputTransition, hsetupWorkTransition, - hsetupOutputTransition] using loopTailReach + simp only [hsetupInputTransition, hsetupWorkTransition, hsetupOutputTransition] + exact loopTailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (initialSetupTM tapes) (TM.seqTM (denseInitialLengthLoopTM tapes) @@ -567,9 +568,8 @@ theorem denseProgramInitTM_hoareTime_internal ?_, hreach, ?_, ?_⟩ · unfold denseProgramInitTime omega - · change (denseProgramInitTM tapes).halted finalCfg - unfold denseProgramInitTM - rw [TM.phase2Wrap_halted_iff] + · unfold denseProgramInitTM + erw [TM.phase2Wrap_halted_iff] exact loopTailHalt · refine ⟨?_, hrewindWork, hrewindOutput⟩ change rewindDone.input = diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInternal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInternal.lean index 1cdbe83e..2271382e 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInternal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/DenseInternal.lean @@ -317,12 +317,11 @@ theorem denseProgramLoopTM_iteration_internal input := inp₀ work := cbody.work output := instructionHaltOutput (next.curInstr program) } := by - cases ctail - simp only [Complexity.Cfg.mk.injEq] - exact ⟨htailDone, htailInput, htailWork, - htailOutput.trans htestOutput'⟩ - simpa only [denseProgramLoopTM, body, test, inp₀, blank, hcTail] using - hreach + exact Complexity.Cfg.ext htailDone htailInput htailWork + (htailOutput.trans htestOutput') + simp only [denseProgramLoopTM] + rw [hcTail] at hreach + exact hreach · right refine ⟨hhalted, ?_⟩ have hcur : next.curInstr program ≠ .halt := hhalted @@ -341,12 +340,11 @@ theorem denseProgramLoopTM_iteration_internal input := inp₀ work := cbody.work output := blank } := by - cases ctail - simp only [Complexity.Cfg.mk.injEq] - exact ⟨htailStart, htailInput, htailWork, - htailOutput.trans hblankOutput⟩ - simpa only [denseProgramLoopTM, body, test, inp₀, blank, hcTail] using - hreach + exact Complexity.Cfg.ext htailStart htailInput htailWork + (htailOutput.trans hblankOutput) + simp only [denseProgramLoopTM] + rw [hcTail] at hreach + exact hreach /-- A halted dense snapshot is stationary under one selected step. -/ theorem denseSnapshot_step_eq_self_of_halted_internal @@ -366,7 +364,7 @@ theorem denseSnapshot_run_halted_internal ∀ fuel, snapshot.run program input fuel = snapshot | 0 => rfl | fuel + 1 => by - rw [DenseOverlay.Snapshot.run, if_pos hhalted] + rw [DenseOverlay.Snapshot.run, ite_eq_left hhalted] /-- A halted fuel-bounded dense run is realized by the fixed controller loop. The extra iteration handles a snapshot already halted at fuel zero. -/ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Init/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Init/Internal.lean index 56192a8d..36b5996a 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Init/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Init/Internal.lean @@ -203,9 +203,9 @@ private theorem initialInputLoopTM_one_step some (initialInputOneWrap tapes c') := by have hne : c.state ≠ (initialOneBitTM tapes).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [initialInputOneWrap, initialInputLoopTM])] + rw [TM.step, ite_eq_right (by simp [initialInputOneWrap, initialInputLoopTM])] simp only [initialInputOneWrap, initialInputLoopTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize (initialOneBitTM tapes).δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -223,9 +223,9 @@ private theorem initialInputLoopTM_zero_step some (initialInputZeroWrap tapes c') := by have hne : c.state ≠ (initialZeroBitTM tapes).qhalt := TM.state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [initialInputZeroWrap, initialInputLoopTM])] + rw [TM.step, ite_eq_right (by simp [initialInputZeroWrap, initialInputLoopTM])] simp only [initialInputZeroWrap, initialInputLoopTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize (initialZeroBitTM tapes).δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -264,7 +264,7 @@ private theorem initialInputLoopTM_step_scan_one input := c.input work := c.work output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [initialInputLoopTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [initialInputLoopTM])] simp only [initialInputLoopTM, hstate, hone, TM.allReadBack, reduceCtorEq, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr @@ -272,10 +272,10 @@ private theorem initialInputLoopTM_step_scan_one · simp [TM.idleDir, Tape.move] · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, - if_neg houtput] + ite_eq_right houtput] rfl private theorem initialInputLoopTM_step_scan_zero @@ -292,7 +292,7 @@ private theorem initialInputLoopTM_step_scan_zero have hstart : c.input.read ≠ Γ.start := by rw [hzero]; decide have hblank : c.input.read ≠ Γ.blank := by rw [hzero]; decide have hone : c.input.read ≠ Γ.one := by rw [hzero]; decide - rw [TM.step, if_neg (by rw [hstate]; simp [initialInputLoopTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [initialInputLoopTM])] simp only [initialInputLoopTM, hstate, hblank, hone, TM.allReadBack, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr @@ -300,10 +300,10 @@ private theorem initialInputLoopTM_step_scan_zero · simp [TM.idleDir, hstart, Tape.move] · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, - if_neg houtput] + ite_eq_right houtput] rfl private theorem initialInputLoopTM_step_scan_blank @@ -317,7 +317,7 @@ private theorem initialInputLoopTM_step_scan_blank input := c.input work := c.work output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [initialInputLoopTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [initialInputLoopTM])] simp only [initialInputLoopTM, hstate, hblank, TM.allReadBack, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr @@ -325,10 +325,10 @@ private theorem initialInputLoopTM_step_scan_blank · simp [TM.idleDir, Tape.move] · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, - if_neg houtput] + ite_eq_right houtput] rfl private theorem initialInputLoopTM_step_one_halt @@ -343,17 +343,17 @@ private theorem initialInputLoopTM_step_one_halt work := c.work output := c.output } := by rw [TM.step, - if_neg (by simp [initialInputOneWrap, initialInputLoopTM])] + ite_eq_right (by simp [initialInputOneWrap, initialInputLoopTM])] simp only [initialInputOneWrap, initialInputLoopTM, hhalt, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · rfl · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, - if_neg houtput] + ite_eq_right houtput] rfl private theorem initialInputLoopTM_step_zero_halt @@ -368,17 +368,17 @@ private theorem initialInputLoopTM_step_zero_halt work := c.work output := c.output } := by rw [TM.step, - if_neg (by simp [initialInputZeroWrap, initialInputLoopTM])] + ite_eq_right (by simp [initialInputZeroWrap, initialInputLoopTM])] simp only [initialInputZeroWrap, initialInputLoopTM, hhalt, ↓reduceIte] refine congrArg some ((Complexity.Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · rfl · funext i rw [TM.writeAndMove_readBack _ (hwork i), TM.idleDir, - if_neg (hwork i)] + ite_eq_right (hwork i)] rfl · rw [TM.writeAndMove_readBack _ houtput, TM.idleDir, - if_neg houtput] + ite_eq_right houtput] rfl private theorem copyWorkToWorkTM_exact_hoareTime @@ -882,8 +882,9 @@ theorem initialOneBitTM_hoareTime_internal work := fun i => TM.transitionTape (emitted.work i) output := TM.transitionTape emitted.output } tailFinal := by - simpa only [hemitInputTransition, hemitWorkTransition, - hemitOutputTransition] using htailReach + simp only [hemitInputTransition, hemitWorkTransition, + hemitOutputTransition] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (rewindEntryEncodeRestoreTM (initialBitEntryTapes tapes)).retargetOutput (TM.seqTM (TM.binarySuccTM tapes.lifted.data.update.remaining) @@ -896,9 +897,9 @@ theorem initialOneBitTM_hoareTime_internal refine ⟨finalCfg, emitTime + 1 + (countTime + 1 + addressTime), ?_, hreach, ?_, ?_⟩ · omega - · change (initialOneBitTM tapes).halted finalCfg - unfold initialOneBitTM - rw [TM.phase2Wrap_halted_iff] + · unfold initialOneBitTM + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff] exact htailHalt · refine ⟨?_, ?_, ?_⟩ · change advanced.input = inp₀ @@ -924,7 +925,8 @@ theorem initialOneBitTM_hoareTime_internal ((entries ++ [(address, 1)]).flatMap Entry.encode) rw [haddressFrame _ hlhsBuffer.symm, hcountFrame _ hremainingBuffer.symm] - simpa [List.flatMap_append] using hemitBuffer + simp [List.flatMap_append] + exact hemitBuffer · intro i change TM.Parked (advanced.work i) by_cases hi : i = tapes.liftedLhs @@ -1061,7 +1063,7 @@ theorem initialInputLoopTM_hoareTime_internal refine ⟨tailDone, 1 + bodyTime + 1 + tailTime, ?_, ?_, htailHalt, ?_⟩ · simp only [initialInputLoopTime, Bool.false_eq_true, - if_false, Nat.add_zero] + ite_false, Nat.add_zero] omega · simpa [Nat.add_assoc] using hreach · refine ⟨htailInput, ?_, htailOutput.trans hbodyOutput⟩ @@ -1120,7 +1122,7 @@ theorem initialInputLoopTM_hoareTime_internal hseamReach htailReach)) refine ⟨tailDone, 1 + bodyTime + 1 + tailTime, ?_, ?_, htailHalt, ?_⟩ - · simp only [initialInputLoopTime, if_true] + · simp only [initialInputLoopTime, ite_true] omega · simpa [Nat.add_assoc] using hreach · refine ⟨htailInput, ?_, htailOutput.trans hbodyOutput⟩ @@ -1158,7 +1160,7 @@ theorem initialSetupTM_hoareTime_internal input := Tape.init (input.map Γ.ofBool) work := fun _ => Tape.init [] output := Tape.init [] } = some skipped := by - rw [TM.step, if_neg (by simp [TM.skipTM])] + rw [TM.step, ite_eq_right (by simp [TM.skipTM])] simp only [TM.skipTM] refine congrArg some (Complexity.Cfg.ext rfl ?_ ?_ ?_) · simp [skipped, parkedInput, TM.idleDir, Tape.read, Tape.move] @@ -1267,8 +1269,8 @@ theorem initialSetupTM_hoareTime_internal work := fun i => TM.transitionTape (skipped.work i) output := TM.transitionTape skipped.output } tailDone := by - simpa only [hskipInputTransition', hskipWorkTransition', - hskipOutputTransition'] using htailReach + simp only [hskipInputTransition', hskipWorkTransition', hskipOutputTransition'] + exact htailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (TM.skipTM (n := n + 1)) (TM.seqTM (TM.binarySuccTM tapes.liftedLhs) @@ -1296,9 +1298,9 @@ theorem initialSetupTM_hoareTime_internal refine ⟨finalCfg, 1 + 1 + (lhsTime + 1 + rhsTime), ?_, hreach, ?_, ?_⟩ · omega - · change (initialSetupTM tapes).halted finalCfg - unfold initialSetupTM - rw [TM.phase2Wrap_halted_iff] + · unfold initialSetupTM + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff] exact htailHalt · refine ⟨?_, ?_, ?_, ?_⟩ · change rhsDone.input.HasBinarySuffix input @@ -1462,8 +1464,7 @@ theorem initialLengthEmitTM_hoareTime_internal have hrhsBuffer : tapes.lifted.data.rhs ≠ tapes.buffer := tapes.liftedData_ne_buffer 14 refine ⟨finalCfg, emitTime + 1 + countTime, by omega, hreach, ?_, ?_⟩ - · change (initialLengthEmitTM tapes).halted finalCfg - unfold initialLengthEmitTM + · unfold initialLengthEmitTM rw [TM.phase2Wrap_halted_iff] exact hcountHalt · refine ⟨?_, ?_, ?_⟩ @@ -1485,7 +1486,8 @@ theorem initialLengthEmitTM_hoareTime_internal · change (counted.work tapes.buffer).HasBinaryPrefix ((entries ++ [(0, length)]).flatMap Entry.encode) rw [hcountFrame _ hcountBuffer.symm] - simpa [List.flatMap_append] using hemitBuffer + simp [List.flatMap_append] + exact hemitBuffer · intro i change TM.Parked (counted.work i) exact hcountWorkParked i @@ -1672,8 +1674,7 @@ theorem initialLengthInstallTM_hoareTime_internal let finalCfg := TM.phase2Wrap (TM.binaryPredTM tapes.liftedLhs) (initialLengthTM tapes) lengthDone refine ⟨finalCfg, predTime + 1 + lengthTime, by omega, hreach, ?_, ?_⟩ - · change (initialLengthInstallTM tapes).halted finalCfg - unfold initialLengthInstallTM + · unfold initialLengthInstallTM rw [TM.phase2Wrap_halted_iff] exact hlengthHalt · refine ⟨?_, ?_, ?_⟩ @@ -1793,7 +1794,8 @@ theorem initialAbiInstallTM_hoareTime_internal (fun inp work out => inp = inp₀ ∧ work = work₀ ∧ out = out₀) (fun inp work out => inp = inp₀ ∧ work = W₁ ∧ out = out₀) (TM.binaryCopyTime store.length 0) := by - simpa only [W₁, initialAbiCountWork] using hcopy + simp only [W₁, initialAbiCountWork] + exact hcopy have hW₁Parked : ∀ i, TM.Parked (W₁ i) := by exact parked_update hready.parked (binaryTape_parked store.length.bits) have hW₁Buffer : W₁ tapes.buffer = programBinaryPrefixTape storeBits := by @@ -1975,7 +1977,7 @@ private theorem inputBitStoreFrom_address_lower | nil => simp [inputBitStoreFrom] at hentry | cons bit rest ih => by_cases hbit : bit - · simp only [inputBitStoreFrom, hbit, if_true, List.singleton_append, + · simp only [inputBitStoreFrom, hbit, ite_true, List.singleton_append, List.mem_cons] at hentry rcases hentry with rfl | hentry · simp @@ -1990,7 +1992,7 @@ private theorem inputBitStoreFrom_addressesNodup | nil => simp [inputBitStoreFrom, AddressesNodup] | cons bit rest ih => by_cases hbit : bit - · simp only [inputBitStoreFrom, hbit, if_true, List.singleton_append] + · simp only [inputBitStoreFrom, hbit, ite_true, List.singleton_append] change (start :: (inputBitStoreFrom (start + 1) rest).map Prod.fst).Nodup rw [List.nodup_cons] refine ⟨?_, ih (start + 1)⟩ @@ -2008,7 +2010,7 @@ private theorem inputBitStoreFrom_valuesNonzero | nil => simp [inputBitStoreFrom, ValuesNonzero] | cons bit rest ih => by_cases hbit : bit - · simp only [inputBitStoreFrom, hbit, if_true, List.singleton_append] + · simp only [inputBitStoreFrom, hbit, ite_true, List.singleton_append] intro entry hentry simp only [List.mem_cons] at hentry rcases hentry with rfl | hentry @@ -2085,7 +2087,7 @@ private theorem read_inputBitStoreFrom (start target : ℕ) | nil => simp [inputBitStoreFrom, read] | cons bit rest ih => cases bit - · simp only [inputBitStoreFrom, Bool.false_eq_true, if_false, + · simp only [inputBitStoreFrom, Bool.false_eq_true, ite_false, List.nil_append] by_cases htarget : target = start · subst target @@ -2093,26 +2095,26 @@ private theorem read_inputBitStoreFrom (start target : ℕ) simp · by_cases hlt : target < start · rw [ih] - simp only [if_neg (by omega : ¬start + 1 ≤ target), - if_neg (by omega : ¬start ≤ target)] + simp only [ite_eq_right (by omega : ¬start + 1 ≤ target), + ite_eq_right (by omega : ¬start ≤ target)] · have hge : start + 1 ≤ target := by omega have hsub : target - start = (target - (start + 1)) + 1 := by omega - rw [ih, if_pos hge, if_pos (by omega : start ≤ target)] + rw [ih, ite_eq_left hge, ite_eq_left (by omega : start ≤ target)] simp [hsub] - · simp only [inputBitStoreFrom, if_true, List.singleton_append] + · simp only [inputBitStoreFrom, ite_true, List.singleton_append] by_cases htarget : target = start · subst target simp [read] · by_cases hlt : target < start - · rw [read, if_neg htarget, ih] - simp only [if_neg (by omega : ¬start + 1 ≤ target), - if_neg (by omega : ¬start ≤ target)] + · rw [read, ite_eq_right htarget, ih] + simp only [ite_eq_right (by omega : ¬start + 1 ≤ target), + ite_eq_right (by omega : ¬start ≤ target)] · have hge : start + 1 ≤ target := by omega have hsub : target - start = (target - (start + 1)) + 1 := by omega - rw [read, if_neg htarget, ih, if_pos hge, - if_pos (by omega : start ≤ target)] + rw [read, ite_eq_right htarget, ih, ite_eq_left hge, + ite_eq_left (by omega : start ≤ target)] simp [hsub] private theorem read_inputBitStoreFrom_zero (input : List Bool) : @@ -2267,8 +2269,8 @@ theorem programInitTM_hoareTime_internal work := fun i => TM.transitionTape (loopDone.work i) output := TM.transitionTape loopDone.output } finalizeDone := by - simpa only [hloopInputTransition, hloopWorkTransition, - hloopOutputTransition] using hfinalizeReach + simp only [hloopInputTransition, hloopWorkTransition, hloopOutputTransition] + exact hfinalizeReach have hloopTailReach := TM.seqTM_reachesIn_of_reachesIn (initialInputLoopTM tapes) (initialFinalizeTM tapes) hloopReach hloopHalt hfinalizeReach' @@ -2277,7 +2279,8 @@ theorem programInitTM_hoareTime_internal have hloopTailHalt : (TM.seqTM (initialInputLoopTM tapes) (initialFinalizeTM tapes)).halted loopTailDone := by - rw [TM.phase2Wrap_halted_iff] + simp only [loopTailDone] + erw [TM.phase2Wrap_halted_iff] exact hfinalizeHalt have hsetupInputTransition : TM.transitionInput setupDone.input = setupDone.input := @@ -2299,8 +2302,8 @@ theorem programInitTM_hoareTime_internal work := fun i => TM.transitionTape (setupDone.work i) output := TM.transitionTape setupDone.output } loopTailDone := by - simpa only [hsetupInputTransition, hsetupWorkTransition, - hsetupOutputTransition] using hloopTailReach + simp only [hsetupInputTransition, hsetupWorkTransition, hsetupOutputTransition] + exact hloopTailReach have hreach := TM.seqTM_reachesIn_of_reachesIn (initialSetupTM tapes) (TM.seqTM (initialInputLoopTM tapes) (initialFinalizeTM tapes)) @@ -2313,9 +2316,9 @@ theorem programInitTM_hoareTime_internal ?_, hreach, ?_, ?_⟩ · unfold programInitTime omega - · change (programInitTM tapes).halted finalCfg - unfold programInitTM - rw [TM.phase2Wrap_halted_iff] + · unfold programInitTM + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff] exact hloopTailHalt · refine ⟨?_, ?_, ?_⟩ · change abiDone.input.HasBinarySuffix [] diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Internal.lean index 4c1b528a..5628a781 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/Program/Internal.lean @@ -698,7 +698,7 @@ theorem programLoop_rewind_check_internal (tmBody tmTest : TM n) exact TM.transitionTape_eq_self (by rw [hread₃]; simp) refine ⟨c₃, .step hstep₁ (.step hstep₂ (.step hstep₃ .zero)), ?_, ?_, ?_, ?_⟩ - · rw [hstate₃, if_pos hone] + · rw [hstate₃, ite_eq_left hone] · rw [hinput₃, hinput₂, hinput₁] · rw [hwork₃, hwork₂, hwork₁] · rw [houtput₃, houtput₂] @@ -723,7 +723,7 @@ theorem programLoop_rewind_check_internal (tmBody tmTest : TM n) · exact TM.transitionTape_eq_self hread₃Start refine ⟨c₃, .step hstep₁ (.step hstep₂ (.step hstep₃ .zero)), ?_, ?_, ?_, ?_⟩ - · rw [hstate₃, if_neg hone] + · rw [hstate₃, ite_eq_right hone] · rw [hinput₃, hinput₂, hinput₁] · rw [hwork₃, hwork₂, hwork₁] · rw [houtput₃, houtput₂] @@ -798,8 +798,8 @@ theorem dispatchHaltTM_hoareTime_frame_internal have hcleanLhs : cleanWork tapes.liftedLhs = blankTape := by have hzero := hready.1.control.lookup.destination change (cleanWork tapes.liftedLhs).HasBinaryNat 0 at hzero - simpa only [blankTape] using - Tape.HasBinaryNat.eq_init_move_right hzero + simp only [blankTape] + exact Tape.HasBinaryNat.eq_init_move_right hzero have hwork₀Parked : ∀ i, TM.Parked (work₀ i) := by intro i rw [hready.2] @@ -1213,11 +1213,11 @@ theorem programLoopTM_iteration_internal input := inp₀ work := cbody.work output := instructionHaltOutput (next.curInstr program) } := by - cases ctail - simp only [Complexity.Cfg.mk.injEq] - exact ⟨htailDone, htailInput, htailWork, - htailOutput.trans htestOutput'⟩ - simpa only [programLoopTM, body, test, blank, hcTail] using hreach + exact Complexity.Cfg.ext htailDone htailInput htailWork + (htailOutput.trans htestOutput') + simp only [programLoopTM] + rw [hcTail] at hreach + exact hreach · right refine ⟨hhalted, ?_⟩ have hcur : next.curInstr program ≠ .halt := hhalted @@ -1236,11 +1236,11 @@ theorem programLoopTM_iteration_internal input := inp₀ work := cbody.work output := blank } := by - cases ctail - simp only [Complexity.Cfg.mk.injEq] - exact ⟨htailStart, htailInput, htailWork, - htailOutput.trans hblankOutput⟩ - simpa only [programLoopTM, body, test, blank, hcTail] using hreach + exact Complexity.Cfg.ext htailStart htailInput htailWork + (htailOutput.trans hblankOutput) + simp only [programLoopTM] + rw [hcTail] at hreach + exact hreach theorem snapshot_step_eq_self_of_halted_internal (program : Program) (snapshot : Snapshot) @@ -1256,7 +1256,7 @@ theorem snapshot_run_halted_internal ∀ fuel, snapshot.run program fuel = snapshot | 0 => rfl | fuel + 1 => by - rw [Snapshot.run, if_pos hhalted] + rw [Snapshot.run, ite_eq_left hhalted] /-- A halted fuel-bounded sparse run is realized by the fixed controller loop. The extra iteration handles a snapshot that is already halted at fuel zero. -/ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Defs.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Defs.lean index f3b59c0f..8808a68d 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Defs.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Defs.lean @@ -326,7 +326,7 @@ def wordDecodeLinearTM {n : ℕ} intro i hi by_cases him : i = markerIdx · subst i - simpa only [if_pos] using TM.moveLeftDir_right_of_start hi + simpa only [ite_eq_left] using TM.moveLeftDir_right_of_start hi · simp [him, TM.idleDir_right_of_start hi] | copy => cases hmarker : wHeads markerIdx with diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Internal.lean index cad32919..0f412d55 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/Internal.lean @@ -465,7 +465,7 @@ private theorem payloadBitTM_step (sourceIdx targetIdx : Fin n) work := payloadBitWork sourceIdx targetIdx work₀ bit output := out₀ } := by have hread := hsource.read_cons - rw [TM.step, if_neg (by simp [payloadBitTM])] + rw [TM.step, ite_eq_right (by simp [payloadBitTM])] cases bit <;> simp only [payloadBitTM, hread, Γ.ofBool, reduceCtorEq] all_goals @@ -578,7 +578,7 @@ private theorem wordSeparatorTM_step (sourceIdx : Fin n) have hread := hsource.read_cons have hzero : (work₀ sourceIdx).read = Γ.zero := by simpa [Γ.ofBool] using hread - rw [TM.step, if_neg (by simp [wordSeparatorTM])] + rw [TM.step, ite_eq_right (by simp [wordSeparatorTM])] simp only [wordSeparatorTM, hzero, ↓reduceIte] refine congrArg some (Cfg.ext rfl ?_ ?_ ?_) · dsimp only @@ -1060,7 +1060,7 @@ private theorem payloadIterationRun (TM.binarySuccTM counterIdx) hbodyReach rfl hsuccReach' have hlift := TM.binaryForTM_iteration_reachesIn_internal body counterIdx widthIdx hseq - simpa [body, wordPayloadTM, payloadIterationStartCfg, + simpa [body, TM.seqTM, wordPayloadTM, payloadIterationStartCfg, payloadIterationDoneCfg, TM.binaryForIterationTime, TM.binaryForIterationTM, TM.binaryForIterationWrap, TM.phase1Wrap, TM.phase2Wrap, beforeWork, afterWork] using hlift @@ -1194,8 +1194,8 @@ theorem wordPayloadTM_reachesIn_frame_internal {n : ℕ} hdistinct payload width work₀ hcounter hwidth refine ⟨payloadDoneCfg sourceIdx targetIdx counterIdx widthIdx payload width inp₀ work₀ out₀, ?_, rfl, rfl, ?_, ?_, ?_, ?_, ?_, rfl⟩ - · simpa [spec, payloadLoopSpec, wordPayloadTime, wordPayloadTM, - payloadScanCfg, hinitial] using hreach + · simpa [spec, payloadLoopSpec, wordPayloadTime, wordPayloadTM, TM.binaryForTM, + payloadScanCfg, payloadDoneCfg, hinitial] using hreach · change (payloadLoopWork sourceIdx targetIdx counterIdx widthIdx payload width work₀ width width sourceIdx).HasBinarySuffix rest rw [payloadLoopWork_source sourceIdx targetIdx counterIdx widthIdx] @@ -1247,7 +1247,8 @@ theorem wordWidthTM_reachesIn_frame_internal {n : ℕ} have hreach := spec.reachesIn_internal width 0 (by omega) have hinit := initial_work sourceIdx widthIdx hindices work₀ hwidth refine ⟨doneCfg sourceIdx widthIdx width inp₀ work₀ out₀, ?_, rfl, rfl, ?_, ?_, ?_, rfl⟩ - · simpa [spec, loopSpec, wordWidthTime, scanCfg, hinit] using hreach + · simpa [spec, loopSpec, wordWidthTime, wordWidthTM, TM.forWorkOnesTM, scanCfg, hinit] + using hreach · change (wordWidthWork sourceIdx widthIdx work₀ width width sourceIdx).HasBinarySuffix (false :: payload) @@ -1403,7 +1404,7 @@ theorem wordDecodeTM_reachesIn_frame_internal {n : ℕ} output := TM.transitionTape widthDone.output } (TM.phase2Wrap separatorTM payloadTM payloadDone) := by rw [hwidthTransitionInput, hwidthTransitionWork, hwidthTransitionOutput] - simpa [tailTM, separatorTM, payloadTM, TM.phase1Wrap] using htailReach + simpa [tailTM, separatorTM, payloadTM, TM.phase1Wrap, TM.seqTM] using htailReach have hfull := TM.seqTM_reachesIn_of_reachesIn widthTM tailTM (by simpa [widthTM] using hwidthReach) hwidthHalt htailReach' let finalCfg := TM.phase2Wrap widthTM tailTM @@ -1411,8 +1412,7 @@ theorem wordDecodeTM_reachesIn_frame_internal {n : ℕ} refine ⟨finalCfg, ?_, ?_, hpayloadInput.trans (hseparatorInput.trans hwidthInput), hpayloadSource, hpayloadTarget, hpayloadCounter, hpayloadWidth, ?_, hpayloadOutput.trans (hseparatorOutput.trans hwidthOutput)⟩ - · simpa [finalCfg, wordDecodeTM, wordDecodeTime, widthTM, tailTM, - separatorTM, payloadTM] using hfull + · exact hfull · change finalCfg.state = (wordDecodeTM sourceIdx targetIdx counterIdx widthIdx).qhalt change Sum.inr (Sum.inr payloadDone.state) = diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/LinearInternal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/LinearInternal.lean index e892350e..2b43d0d6 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/LinearInternal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordDecode/LinearInternal.lean @@ -64,7 +64,7 @@ private theorem linearMarkStep have hstep : (wordDecodeLinearTM sourceIdx targetIdx markerIdx).step { state := .mark, input := inp, work := work, output := out } = some c' := by - rw [TM.step, if_neg (by simp [wordDecodeLinearTM])] + rw [TM.step, ite_eq_right (by simp [wordDecodeLinearTM])] simp only [wordDecodeLinearTM, hread] apply congrArg some refine Cfg.ext rfl ?_ ?_ ?_ @@ -87,10 +87,10 @@ private theorem linearMarkStep TM.writeAndMove_readBack out houtput Dir3.stay refine ⟨c', hstep, rfl, rfl, ?_, ?_, ?_, rfl, rfl⟩ · dsimp only [c', work', linearMarkWork] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact hsource.move_right_cons · dsimp only [c', work', linearMarkWork] - rw [if_neg (Ne.symm hdistinct.source_marker), if_pos rfl] + rw [ite_eq_right (Ne.symm hdistinct.source_marker), ite_eq_left rfl] simpa [Γw.ofBool, Γ.ofBool, Γw.toΓ] using Tape.hasBinaryPrefix_write_bit true hmarker · intro i his him @@ -197,7 +197,7 @@ private theorem linearSeparatorStep have hstep : (wordDecodeLinearTM sourceIdx targetIdx markerIdx).step { state := .mark, input := inp, work := work, output := out } = some c' := by - rw [TM.step, if_neg (by simp [wordDecodeLinearTM])] + rw [TM.step, ite_eq_right (by simp [wordDecodeLinearTM])] simp only [wordDecodeLinearTM, hread] apply congrArg some refine Cfg.ext rfl ?_ ?_ ?_ @@ -224,15 +224,15 @@ private theorem linearSeparatorStep TM.writeAndMove_readBack out houtput Dir3.stay refine ⟨c', hstep, rfl, rfl, ?_, ?_, ?_, ?_, rfl⟩ · dsimp only [c', work', linearSeparatorWork] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact hsource.move_right_cons · dsimp only [c', work', linearSeparatorWork] - rw [if_neg (Ne.symm hdistinct.source_marker), if_pos rfl] + rw [ite_eq_right (Ne.symm hdistinct.source_marker), ite_eq_left rfl] simp only [Tape.move] rw [hmarker.1] simp · dsimp only [c', work', linearSeparatorWork] - rw [if_neg (Ne.symm hdistinct.source_marker), if_pos rfl, + rw [ite_eq_right (Ne.symm hdistinct.source_marker), ite_eq_left rfl, Tape.move_cells] · intro i his him simp [c', work', linearSeparatorWork, his, him] @@ -267,7 +267,7 @@ private theorem linearRewindLeftStep have hstep : (wordDecodeLinearTM sourceIdx targetIdx markerIdx).step { state := .rewind, input := inp, work := work, output := out } = some c' := by - rw [TM.step, if_neg (by simp [wordDecodeLinearTM])] + rw [TM.step, ite_eq_right (by simp [wordDecodeLinearTM])] simp only [wordDecodeLinearTM, hmarkerRead, ↓reduceIte] apply congrArg some refine Cfg.ext rfl ?_ ?_ ?_ @@ -322,7 +322,7 @@ private theorem linearRewindBaseStep have hstep : (wordDecodeLinearTM sourceIdx targetIdx markerIdx).step { state := .rewind, input := inp, work := work, output := out } = some c' := by - rw [TM.step, if_neg (by simp [wordDecodeLinearTM])] + rw [TM.step, ite_eq_right (by simp [wordDecodeLinearTM])] simp only [wordDecodeLinearTM, hmarkerRead, ↓reduceIte] apply congrArg some refine Cfg.ext rfl ?_ ?_ ?_ @@ -440,7 +440,7 @@ private theorem linearCopyStep have hstep : (wordDecodeLinearTM sourceIdx targetIdx markerIdx).step { state := .copy, input := inp, work := work, output := out } = some c' := by - rw [TM.step, if_neg (by simp [wordDecodeLinearTM])] + rw [TM.step, ite_eq_right (by simp [wordDecodeLinearTM])] cases bit <;> simp only [wordDecodeLinearTM, hmarkerRead, hsourceRead, Γ.ofBool, reduceCtorEq] @@ -473,14 +473,14 @@ private theorem linearCopyStep TM.writeAndMove_readBack out houtput Dir3.stay refine ⟨c', hstep, rfl, rfl, ?_, ?_, ?_, ?_, rfl, rfl⟩ · dsimp only [c', work', linearCopyWork] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact hsource.move_right_cons · dsimp only [c', work', linearCopyWork] - rw [if_neg (Ne.symm hdistinct.source_marker), - if_neg (Ne.symm hdistinct.target_marker), if_pos rfl] + rw [ite_eq_right (Ne.symm hdistinct.source_marker), + ite_eq_right (Ne.symm hdistinct.target_marker), ite_eq_left rfl] exact hmarker.move_right_cons · dsimp only [c', work', linearCopyWork] - rw [if_neg (Ne.symm hdistinct.source_target), if_pos rfl] + rw [ite_eq_right (Ne.symm hdistinct.source_target), ite_eq_left rfl] cases bit with | false => simpa [Γw.ofBool, Γ.ofBool, Γw.toΓ] using @@ -509,7 +509,7 @@ private theorem linearCopyDoneStep have hstep : (wordDecodeLinearTM sourceIdx targetIdx markerIdx).step { state := .copy, input := inp, work := work, output := out } = some c' := by - rw [TM.step, if_neg (by simp [wordDecodeLinearTM])] + rw [TM.step, ite_eq_right (by simp [wordDecodeLinearTM])] simp only [wordDecodeLinearTM, hmarkerRead, TM.allReadBack] apply congrArg some refine Cfg.ext rfl ?_ ?_ ?_ diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordEncode/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordEncode/Internal.lean index efba76ff..969ca729 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordEncode/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/RegisterStore/Machine/WordEncode/Internal.lean @@ -98,7 +98,7 @@ theorem workEmitTM_reachesIn_frame_internal simpa [c'] using TM.transitionTape_eq_self (hother i hi).read_ne_start have houtput' : c'.output.HasBinaryPrefix (emitted ++ [false]) := by - simpa [c'] using Tape.hasBinaryPrefix_write_bit false houtput + simpa [Γ.ofBool, c'] using Tape.hasBinaryPrefix_write_bit false houtput refine ⟨c', .step hstep .zero, rfl, hinputKeep, ?_, ?_, ?_, hotherKeep, ?_⟩ · rw [hsourceKeep] @@ -170,7 +170,7 @@ theorem workEmitTM_reachesIn_frame_internal exact hsource.move_right_cons have houtput₁ : c₁.output.HasBinaryPrefix (emitted ++ [workEmitBit mode bit]) := by - simpa [c₁] using Tape.hasBinaryPrefix_write_bit + simpa [Γ.ofBool, c₁] using Tape.hasBinaryPrefix_write_bit (workEmitBit mode bit) houtput obtain ⟨c', hreach, hhalt, hinput', hsource', hsourceCells, hsourceHead, hother', houtput'⟩ := @@ -350,7 +350,7 @@ theorem wordEncodeTM_hoareTime_frame_internal output := TM.transitionTape widthDone.output } (TM.phase2Wrap (TM.rewindWorkTM idx) (workEmitTM idx .payload) payloadDone) := by - simpa [hwidthInputTransition, hwidthWorkTransition, + simpa [TM.phase2Wrap, TM.phase1Wrap, TM.seqTM, hwidthInputTransition, hwidthWorkTransition, hwidthOutputTransition] using hrestReach have hfullReach := TM.seqTM_reachesIn_of_reachesIn (workEmitTM idx .width) @@ -369,10 +369,11 @@ theorem wordEncodeTM_hoareTime_frame_internal (TM.seqTM (workEmitTM idx .width) (TM.seqTM (TM.rewindWorkTM idx) (workEmitTM idx .payload))).halted finalCfg - rw [TM.phase2Wrap_halted_iff, TM.phase2Wrap_halted_iff] + simp only [finalCfg] + erw [TM.phase2Wrap_halted_iff, TM.phase2Wrap_halted_iff] exact hpayloadHalt · refine ⟨?_, hpayloadSuffix, ?_, ?_, ?_, ?_⟩ - · simpa [finalCfg] using + · simpa [finalCfg, TM.phase2Wrap] using hpayloadInput.trans (hrewindInput.trans hwidthInput) · have hcanonical := Tape.eq_init_move_right_of_hasBinaryString hvalue.2 hvalue.1 @@ -382,12 +383,12 @@ theorem wordEncodeTM_hoareTime_frame_internal · have hrewindHead : (rewindDone.work idx).head = 1 := by rw [hrewindTarget] simp [Tape.move] - simpa [finalCfg, hrewindHead, Nat.add_comm] using hpayloadHead + simpa [finalCfg, TM.phase2Wrap, hrewindHead, Nat.add_comm] using hpayloadHead · intro i hi - simpa [finalCfg] using + simpa [finalCfg, TM.phase2Wrap] using (hpayloadFrame i hi).trans ((hrewindFrame i hi).trans (hwidthFrame i hi)) - · simpa [finalCfg, WordCode.encode, workEmitBits, bitlen, + · simpa [finalCfg, TM.phase2Wrap, WordCode.encode, workEmitBits, bitlen, Nat.toBitsLE_size, Nat.size_eq_bits_len, List.append_assoc] using hpayloadOutput @@ -471,20 +472,19 @@ theorem rewindWordEncodeTM_hoareTime_frame_internal refine ⟨finalCfg, rewindTime + 1 + encodeTime, ?_, hreach, ?_, ?_⟩ · unfold rewindWordEncodeTime omega - · change (rewindWordEncodeTM idx).halted finalCfg - unfold rewindWordEncodeTM + · unfold rewindWordEncodeTM rw [TM.phase2Wrap_halted_iff] exact hencodeHalt · refine ⟨?_, hencodeSuffix, ?_, ?_, ?_, ?_⟩ - · simpa [finalCfg] using hencodeInput.trans hrewindInput + · simpa [finalCfg, TM.phase2Wrap] using hencodeInput.trans hrewindInput · change (encodeDone.work idx).cells = (work₀ idx).cells rw [hencodeCells, hrewindTarget] exact (cells_eq_init_of_binaryContent hcontent hstart).symm - · simpa [finalCfg] using hencodeHead + · simpa [finalCfg, TM.phase2Wrap] using hencodeHead · intro i hi change encodeDone.work i = work₀ i exact (hencodeFrame i hi).trans (hrewindFrame i hi) - · simpa [finalCfg] using hencodeOutput + · simpa [finalCfg, TM.phase2Wrap] using hencodeOutput end Machine diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Internal.lean index cd22252b..2294f276 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Internal.lean @@ -52,7 +52,7 @@ theorem tapeAt_input_internal (cfg : Complexity.Cfg n Q) : theorem tapeAt_work_internal (cfg : Complexity.Cfg n Q) (i : Fin n) : tapeAt cfg ⟨i.val + 1, by omega⟩ = cfg.work i := by simp only [tapeAt] - rw [dif_neg (by omega), dif_neg (by omega)] + rw [dite_eq_right (by omega), dite_eq_right (by omega)] congr 1 theorem tapeAt_output_internal (cfg : Complexity.Cfg n Q) : @@ -65,7 +65,7 @@ theorem encodeRegs_field_internal (tm : TM n) (bound : ℕ) have hreg : fieldReg field < registerCount n bound := (fieldEquiv n bound field).isLt unfold encodeRegs - rw [dif_pos hreg] + rw [dite_eq_left hreg] have hfield : (⟨fieldReg field, hreg⟩ : Fin (registerCount n bound)) = fieldEquiv n bound field := by @@ -109,7 +109,7 @@ private theorem decodeTape_of_represents (tm : TM n) (bound : ℕ) rfl · funext position by_cases hposition : position < bound + 1 - · simp only [decodeTape, hposition, dif_pos] + · simp only [decodeTape, hposition, dite_eq_left] rw [hrepresents (cellField tape ⟨position, hposition⟩)] exact symbolDecode_code_internal _ · simp only [decodeTape, hposition] @@ -123,7 +123,8 @@ theorem decode_of_represents_internal (tm : TM n) (bound : ℕ) · simp only [decode] rw [hrepresents (stateField (n := n) (bound := bound))] exact stateDecode_code_internal tm cfg.state - · simpa [decode, tapeAt_input_internal] using + · rw [← tapeAt_input_internal cfg] + simpa [decode] using decodeTape_of_represents tm bound cfg regs hrepresents hbounded ⟨0, by omega⟩ · funext i diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Capture.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Capture.lean index d46aa046..8adbf57b 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Capture.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Capture.lean @@ -27,7 +27,7 @@ namespace Sparse theorem initRegs_bool_of_pos_internal (x : List Bool) {reg : ℕ} (hpos : 0 < reg) : initRegs x reg = 0 ∨ initRegs x reg = 1 := by - rw [initRegs, if_neg (by omega)] + rw [initRegs, ite_eq_right (by omega)] cases hbit : x[reg - 1]? with | none => simp | some bit => diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Loop.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Loop.lean index 2f8dce6d..a11efb53 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Loop.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Loop.lean @@ -248,7 +248,7 @@ theorem marshalLoopOps_control_internal (n : ℕ) (store : Structured.Store) · simp [stateReg, cellReg, inputTape, cellBase] simpa [marshalLoopOps, sourceAddressed, sourceLoaded, sourceCleared, zeroed, oned, counted, based, encoded, multiplied, destinationAddressed, - destinationStored, final] using + destinationStored, final, Structured.Basic.execList] using And.intro hfinalState (And.intro hfinalZero (And.intro hfinalOne (And.intro hfinalCount (And.intro hfinalBase hfinalDestination)))) @@ -679,8 +679,7 @@ theorem marshalLoop_exec_internal (n cursor : ℕ) hfinalCount, hfinalBase⟩ have hexec := Structured.Exec.whileNonzero hnonzero hbody hloop convert hexec using 1 - simp [marshalLoopSteps, Nat.succ_mul] - omega + all_goals first | rfl | (simp [marshalLoopSteps, Nat.succ_mul]; omega) end Sparse diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Marshal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Marshal.lean index c8ce9a2a..5fde168b 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Marshal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Marshal.lean @@ -86,7 +86,7 @@ private theorem marshalStart_of_not_captured (n : ℕ) (x : List Bool) private theorem initRegs_eq_zero_of_length_lt (x : List Bool) {reg : ℕ} (hreg : x.length < reg) : initRegs x reg = 0 := by - rw [initRegs, if_neg (by omega)] + rw [initRegs, ite_eq_right (by omega)] rw [List.getElem?_eq_none (by omega)] /-- Installing loop constants establishes the invariant before any input @@ -328,8 +328,7 @@ theorem marshalLoop_invariant_exec_internal (n : ℕ) (x : List Bool) max bodySpace loopSpace, ?_, hfinalInvariant⟩ have hexec := Structured.Exec.whileNonzero hstoreNonzero hbody hloop convert hexec using 1 - simp [marshalLoopSteps, Nat.succ_mul] - omega + all_goals first | rfl | (simp only [marshalLoopSteps, Nat.succ_mul]; omega) /-- Exact store selected by one captured-position repair command. -/ def repairBitStore (n : ℕ) (entry : ℕ × ℕ) @@ -460,7 +459,7 @@ theorem repairBitStore_data_internal (n : ℕ) (entry : ℕ × ℕ) rw [hloadedValue] by_cases hzero : store (cellReg n (inputTape n) entry.1) = 0 · simp [hzero, hloadedData] - · simp only [hzero, if_false] + · simp only [hzero, ite_false] let valued := (Structured.Basic.imm (valueReg n) (entry.2 + 1)).exec loaded have hvaluedAddress : valued (addressReg n) = @@ -634,7 +633,7 @@ private theorem initRegs_add_one_eq_input_symbol (x : List Bool) ⟨position - 1, by omega⟩ have hindex : index < x.length := by omega rw [Tape.init_ofBool_cells_lt x index hindex] - simp only [initRegs, show index + 1 ≠ 0 by omega, if_false] + simp only [initRegs, show index + 1 ≠ 0 by omega, ite_false] rw [show index + 1 - 1 = index by omega, List.getElem?_eq_getElem hindex] cases x[index] <;> simp [Γ.ofBool, symbolCode] diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Resources.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Resources.lean index d464d100..3bacc8e9 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Resources.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/ABI/Internal/Resources.lean @@ -566,8 +566,9 @@ private theorem marshalLoop_measured_aux (n : ℕ) (x : List Bool) hnonzero hinitialGlobal hbody hloop refine ⟨final, ?_, hfinalInvariant, ?_⟩ · convert hrun using 1 - all_goals simp [marshalLoopSteps, marshalWidth, - Structured.Internal.valueWidth, Nat.succ_mul] + all_goals try rfl + all_goals simp only [marshalLoopSteps, marshalWidth, + Structured.Internal.valueWidth] all_goals ring · convert hfinalEnvelope using 1 omega @@ -587,7 +588,7 @@ theorem marshalLoop_measured_internal {tm : TM n} (x : List Bool) : marshalLoop_measured_aux n x (processed := 0) (store := marshalStart n x) (by simp) hinvariant hmarshal.storeEnvelope refine ⟨final, ?_, hfinalInvariant, ?_⟩ - · simpa using hrun + · exact hrun · apply hfinalEnvelope.mono le_rfl (show marshalBaseBound n x.length + 0 + x.length ≤ wordBound tm (marshalBound n x.length) by @@ -637,9 +638,8 @@ theorem extractVerdict_measured_internal {tm : TM n} {bound : ℕ} have hchain : Structured.Internal.Basic.EnvelopeChain (registerBound n (bound + 1)) (wordBound tm bound) (extractVerdictOps n) store := by - simpa [extractVerdictOps, addressed, loaded, oned, final] using - And.intro henvelope - (And.intro haddressed (And.intro hloaded (And.intro honed hfinal))) + simp [extractVerdictOps] + exact And.intro henvelope (And.intro haddressed (And.intro hloaded (And.intro honed hfinal))) have hmeasured := Structured.Internal.MeasuredRuns.basicsEnvelopeChain (extractVerdictOps n) store hchain have hverdict := extractVerdict_exec_internal hrepresents @@ -739,7 +739,7 @@ private theorem repairBit_measured_internal {tm : TM n} {bound valueLimit : ℕ} have hrepairStore : repairBitStore n entry store = loaded := by unfold repairBitStore change (if loaded (valueReg n) = 0 then loaded else _) = loaded - rw [if_pos hzero] + rw [ite_eq_left hzero] refine ⟨3, ?_, ?_⟩ · rw [hrepairStore] simpa [repairBit] using hrun' @@ -792,11 +792,12 @@ private theorem repairBit_measured_internal {tm : TM n} {bound valueLimit : ℕ} Structured.Basic.execList [.imm (valueReg n) (entry.2 + 1), .store (addressReg n) (valueReg n)] loaded) = final - rw [if_neg hzero] + rw [ite_eq_right hzero] rfl refine ⟨6, ?_, ?_⟩ · rw [hrepairStore] - simpa [repairBit] using hrun' + simp [repairBit] + exact hrun' · rw [hrepairStore] exact hfinal @@ -833,8 +834,9 @@ private theorem repairCaptured_fromStep_measured {tm : TM n} have hrun := hfirst.seq hrest refine ⟨final, firstSteps + restSteps, ?_, ?_, hfinalEnvelope⟩ · convert hrun using 1 - simp only [List.length_cons] - ring + all_goals try rfl + all_goals simp only [List.length_cons] + all_goals ring · simp [repairStore] at hrestStore ⊢ exact hrestStore @@ -864,8 +866,9 @@ theorem repairCaptured_measured_internal {tm : TM n} {bound valueLimit : ℕ} have hrun := hfirst.seq hrest refine ⟨final, firstSteps + restSteps, ?_, ?_, hfinalEnvelope⟩ · convert hrun using 1 - simp only [List.length_cons] - ring + all_goals try rfl + all_goals simp only [List.length_cons] + all_goals ring · simp [repairStore] at hrestStore ⊢ exact hrestStore @@ -1051,10 +1054,10 @@ theorem marshalLeaf_measured_internal (tm : TM n) (x : List Bool) : (marshalLoopSteps n x.length + (repairSteps + (initializeConfigOps tm).length)), ?_, ?_, ?_⟩ · convert hrun using 1 - simp [marshalLeafTimeBound, marshalBaseWidth, - Structured.Internal.valueWidth, capturedInput, - captureValues_eq_reverse_append] - ring + all_goals try rfl + all_goals simp [capturedInput, captureValues_eq_reverse_append, + marshalLeafTimeBound, marshalBaseWidth, Structured.Internal.valueWidth] + all_goals ring · simpa [final, initializeStore] using hrepresents · simpa [final] using hinitializeEnvelope @@ -1116,8 +1119,9 @@ private theorem captureInput_measured_of_leaf {tm : TM n} (x : List Bool) hnonzero henvelope hrest refine ⟨restSteps + 2, ?_⟩ convert hbranch using 1 - all_goals simp [captureInput, hone, wordWidth, - Structured.Internal.valueWidth] + all_goals try rfl + all_goals simp only [captureInput, hone, wordWidth, + Structured.Internal.valueWidth, List.length_cons] all_goals ring /-- The full public-input marshaller has a concrete resource certificate and @@ -1189,8 +1193,9 @@ theorem decisionProgram_measured_internal {tm : TM n} {steps : ℕ} (runSteps tm steps (tm.initCfg x) + (extractVerdictOps n).length), ?_, hverdict⟩ convert hrun using 1 - simp [decisionTimeBound] - ring + all_goals try rfl + all_goals simp [decisionTimeBound] + all_goals ring /-- Concrete compiled-RAM transfer of the end-to-end resource certificate. -/ theorem compiledDecision_resourceBound_internal {tm : TM n} {steps : ℕ} diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Internal.lean index 5ea24fa0..b41b3e11 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Internal.lean @@ -201,8 +201,8 @@ theorem encodeRegs_head_internal (tm : TM n) (cfg : Complexity.Cfg n tm.Q) encodeRegs tm cfg (headReg tape) = (tapeAt cfg tape).head := by have hstate : headReg tape ≠ stateReg := by simp [headReg, stateReg] - rw [encodeRegs, dif_neg hstate, - dif_pos (headReg_lt_control_internal tape)] + rw [encodeRegs, dite_eq_right hstate, + dite_eq_left (headReg_lt_control_internal tape)] congr 2 apply Fin.ext simp [headReg] @@ -217,7 +217,7 @@ theorem encodeRegs_cell_internal (tm : TM n) (cfg : Complexity.Cfg n tm.Q) simp [stateReg] omega have hnotHead : ¬ cellReg n tape position < n + 3 := by omega - rw [encodeRegs, dif_neg hnotState, dif_neg hnotHead, if_pos hbase, + rw [encodeRegs, dite_eq_right hnotState, dite_eq_right hnotHead, ite_eq_left hbase, decodeCellTape_cellReg_internal, decodeCellPosition_cellReg_internal] theorem encodeRegs_represents_internal (tm : TM n) @@ -242,7 +242,7 @@ theorem decode_of_represents_internal (tm : TM n) rw [hstate] exact stateDecode_code_internal tm cfg.state · apply Tape.ext - · simpa [decode, decodeTape, tapeAt_input_internal] using + · simpa [decode, decodeTape, tapeAt, fieldReg, fieldValue] using hrepresents (Sum.inr (Sum.inl ⟨0, by omega⟩)) · funext position simp only [decode, decodeTape] diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Defs.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Defs.lean index 58ea8c73..e03ee230 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Defs.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Defs.lean @@ -7,6 +7,7 @@ Authors: Samuel Schlesinger module public import Complexitylib.Models.RandomAccessMachine.Simulation.TMConfig.Sparse.Defs public import Complexitylib.Models.RandomAccessMachine.Structured.Switch.Defs +public import Mathlib.Data.Finset.Lattice.Fold /-! # A fixed sparse-RAM block for one Turing-machine transition diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Action.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Action.lean index 54b05213..79489d1e 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Action.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Action.lean @@ -181,7 +181,7 @@ private theorem writeOps_tape {tm : TM n} {cfg : Complexity.Cfg n tm.Q} · by_cases hpositionZero : position = 0 · subst position rw [Function.update_self] - rw [Tape.write, if_neg hheadZero] + rw [Tape.write, ite_eq_right hheadZero] change symbolCode Γ.start = symbolCode (Function.update (tapeAt cfg slot).cells (tapeAt cfg slot).head write.toΓ 0) @@ -638,7 +638,7 @@ private theorem workPrefix_step {tm : TM n} · have hother := writeMoveOps_otherTape_internal (tm := tm) (cfg := current) (Ne.symm (inputTape_ne_workTape n i)) (workWrites i) (workDirections i) store hcurrent hprefix.tapeCount - simpa [current, inputTape] using hother + simpa [Structured.Basic.execList, tapeAt, current, inputTape] using hother · intro j by_cases hji : j = i · subst j @@ -679,7 +679,7 @@ private theorem workPrefix_list {tm : TM n} (items.flatMap (fun i => writeMoveOps n (workTape i) (workWrites i) (workDirections i))) store) := by induction items generalizing processed store with - | nil => simpa using hprefix + | nil => simpa [Structured.Basic.execList] using hprefix | cons i rest ih => have hinot : i ∉ processed := hfresh i (by simp) have hnext := workPrefix_step hprefix i hinot (hstarts i) @@ -710,7 +710,7 @@ theorem actionOps_represents_internal {tm : TM n} (fun i => (cfg.work i).read) cfg.output.read with ⟨nextState, workWrites, outputWrite, inputDirection, workDirections, outputDirection⟩ - rw [TM.step, if_neg hnotHalted, hdelta] at hstep + rw [TM.step, ite_eq_right hnotHalted, hdelta] at hstep dsimp only at hstep injection hstep with hnext subst next @@ -993,10 +993,9 @@ private theorem writeOps_envelopeChain {tm : TM n} {bound : ℕ} · exact cellReg_lt_registerBound tape (bound := bound) (position := 0) (by omega) · simpa [Structured.Internal.Basic.writeValue] using hstartBound - simpa [writeOps, addressOps, first, multiplied, addressed, valued, stored, - final] using And.intro henvelope (And.intro hfirst - (And.intro hmultiplied (And.intro haddressed - (And.intro hvalued (And.intro hstored hfinal))))) + exact And.intro henvelope (And.intro hfirst + (And.intro hmultiplied (And.intro haddressed + (And.intro hvalued (And.intro hstored hfinal))))) private theorem writeMoveOps_envelopeChain {tm : TM n} {bound : ℕ} {cfg : Complexity.Cfg n tm.Q} (tape : Fin (n + 2)) (write : Γw) @@ -1047,7 +1046,7 @@ private theorem workPrefix_list_envelope {tm : TM n} {bound : ℕ} (items.reverse ++ processed) (Structured.Basic.execList ops store) ∧ ResourceEnvelopeChain tm bound ops store := by induction items generalizing processed store with - | nil => exact ⟨by simpa using hprefix, henvelope⟩ + | nil => exact ⟨by simpa [Structured.Basic.execList, Γ.ofBool] using hprefix, henvelope⟩ | cons i rest ih => have hinot : i ∉ processed := hfresh i (by simp) let current : Complexity.Cfg n tm.Q := diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Iteration.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Iteration.lean index d3b0d996..df6e9325 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Iteration.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Iteration.lean @@ -92,7 +92,8 @@ theorem continueCheck_exec_internal {tm : TM n} ⟨stateCode tm cfg.state, stateCode_lt tm cfg.state⟩) cleared final 1 cost space := by refine ⟨branchCost, branchSpace, ?_⟩ - simpa [hbranchState, final] using hbranchExec + simp [hbranchState, final] + exact hbranchExec obtain ⟨dispatchCost, dispatchSpace, hdispatch⟩ := Structured.Switch.select_exec (fun code : Fin (Fintype.card tm.Q) => .basics @@ -102,8 +103,8 @@ theorem continueCheck_exec_internal {tm : TM n} hloaded.2.2.1 (stateScratchReg_ne_one n) hselectedBranch refine ⟨final, loadCost + dispatchCost, max loadSpace dispatchSpace, ?_, hfinalRepresents, hfinalValue, hfinalOne, hfinalCount⟩ - simpa [continueCheck, continueDispatch, continueSteps, loaded] using - Structured.Exec.seq hloadExec hdispatch + simp [continueCheck, continueDispatch, continueSteps] + exact Structured.Exec.seq hloadExec hdispatch theorem starts_of_step_internal {tm : TM n} {cfg next : Complexity.Cfg n tm.Q} (hstep : tm.step cfg = some next) @@ -116,7 +117,7 @@ theorem starts_of_step_internal {tm : TM n} (fun i => (cfg.work i).read) cfg.output.read with ⟨nextState, workWrites, outputWrite, inputDirection, workDirections, outputDirection⟩ - rw [TM.step, if_neg hnotHalted, hdelta] at hstep + rw [TM.step, ite_eq_right hnotHalted, hdelta] at hstep dsimp only at hstep injection hstep with hnext subst next diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Load.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Load.lean index 0532fa55..4fd23ebf 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Load.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Load.lean @@ -99,7 +99,7 @@ private theorem setup_loadedPrefix {tm : TM n} {cfg : Complexity.Cfg n tm.Q} simp [third, second, first, Structured.Basic.exec, zeroReg, oneReg, tapeCountReg, Function.update_of_ne] rw [hthirdState, hthirdZero, hstateStore, Nat.add_zero] - simpa [setupOps, first, second, third, final] using + simpa [Structured.Basic.execList, setupOps, first, second, third, final] using LoadedPrefix.mk hfinalRep hzero hone hcount hstate (by simp) private theorem loadTape_loadedPrefix {tm : TM n} @@ -161,7 +161,7 @@ private theorem loadTapes_loadedPrefix {tm : TM n} LoadedPrefix tm cfg (tapes.reverse ++ processed) (Structured.Basic.execList (tapes.flatMap (loadTapeOps n)) store) := by induction tapes generalizing processed store with - | nil => simpa using hloaded + | nil => simpa [Structured.Basic.execList] using hloaded | cons tape rest ih => have hnext := loadTape_loadedPrefix hloaded tape have hfinal := ih (processed := tape :: processed) hnext diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Resources.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Resources.lean index 538ca2e0..03b1b1ec 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Resources.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Sparse/Step/Internal/Resources.lean @@ -81,7 +81,7 @@ private theorem initRegs_index_le_length {x : List Bool} {reg : ℕ} (hnonzero : initRegs x reg ≠ 0) : reg ≤ x.length := by by_cases hreg : reg = 0 · omega - rw [initRegs, if_neg hreg] at hnonzero + rw [initRegs, ite_eq_right hreg] at hnonzero cases hbit : x[reg - 1]? with | none => simp [hbit] at hnonzero | some bit => @@ -225,9 +225,8 @@ private theorem setupOps_envelopeChain {tm : TM n} {bound : ℕ} · simp only [Structured.Internal.Basic.writeValue] rw [hthirdState, hthirdZero, hstoreState, Nat.add_zero] exact hstateBound - simpa [setupOps, first, second, third, final] using - And.intro henvelope - (And.intro hfirst (And.intro hsecond (And.intro hthird hfinal))) + simp [setupOps] + exact And.intro henvelope (And.intro hfirst (And.intro hsecond (And.intro hthird hfinal))) private theorem setupOps_represents {tm : TM n} {cfg : Complexity.Cfg n tm.Q} {store : Structured.Store} @@ -337,9 +336,8 @@ private theorem loadTapeOps_envelopeChain {tm : TM n} {bound : ℕ} · exact lt_trans (hrange.2.2.2.2.2.2 tape).2 (control_lt_registerBound_internal n bound) · exact haddressed.value_le (addressed (addressReg n)) - simpa [loadTapeOps, addressOps, first, multiplied, addressed, final] using - And.intro henvelope - (And.intro hfirst (And.intro hmultiplied (And.intro haddressed hfinal))) + simp [loadTapeOps, addressOps] + exact And.intro henvelope (And.intro hfirst (And.intro hmultiplied (And.intro haddressed hfinal))) private theorem loadTapes_envelopeChain {tm : TM n} {bound : ℕ} {cfg : Complexity.Cfg n tm.Q} (tapes : List (Fin (n + 2))) @@ -469,8 +467,8 @@ theorem continueCheck_measured_internal {tm : TM n} {bound : ℕ} (runningFlag tm ((Fintype.equivFin tm.Q).symm code))]) ⟨stateCode tm cfg.state, by simp [stateCode]⟩) cleared final 1 (4 * wordWidth tm bound) (spaceBound tm bound) := by - simpa [hbranchState, final, wordWidth, Structured.Internal.valueWidth, - spaceBound, Structured.Internal.envelopeSpace] using hbranch + simp [hbranchState, final, wordWidth, spaceBound] + exact hbranch have hdispatch := Structured.Switch.select_measured (fun code : Fin (Fintype.card tm.Q) => .basics [.imm (valueReg n) @@ -506,7 +504,7 @@ theorem headsBounded_step_internal {tm : TM n} {bound : ℕ} (fun i => (cfg.work i).read) cfg.output.read with ⟨nextState, workWrites, outputWrite, inputDirection, workDirections, outputDirection⟩ - rw [TM.step, if_neg hnotHalted, hdelta] at hstep + rw [TM.step, ite_eq_right hnotHalted, hdelta] at hstep dsimp only at hstep injection hstep with hnext subst next @@ -699,7 +697,7 @@ theorem loop_measured_internal {tm : TM n} {steps base : ℕ} (spaceBound tm bound) := by simpa [loopBody] using hbody have hrun := Structured.Internal.MeasuredRuns.whileNonzeroEnvelope - hnonzero (by simpa [bound, Nat.add_assoc] using henvelope) hbody' hloop' + hnonzero (by simp [bound, Nat.add_assoc]; exact henvelope) hbody' hloop' refine ⟨final, ?_, hfinalRepresents, ?_⟩ · simpa [loopSteps, loopTimeBound, hstep, bound, wordWidth, Structured.Internal.valueWidth, spaceBound, diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Action.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Action.lean index a26c979e..9c7a0084 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Action.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Action.lean @@ -177,7 +177,7 @@ private theorem writeOps_cells (n bound : ℕ) (slot : Fin (n + 2)) (configReg_ne_address hreg) (configReg_ne_value hreg)] rw [hstoreHead] by_cases hheadZero : tape.head = 0 - · rw [Tape.write, if_pos hheadZero] + · rw [Tape.write, ite_eq_left hheadZero] by_cases hpositionZero : position.val = 0 · rw [hheadZero, hpositionZero, Nat.add_zero, Function.update_self, hstart] · have htarget : @@ -187,7 +187,7 @@ private theorem writeOps_cells (n bound : ℕ) (slot : Fin (n + 2)) cellBase n bound slot + position.val ≠ cellBase n bound slot := by omega rw [Function.update_of_ne hbase, Function.update_of_ne htarget, hstoreCell] - · rw [Tape.write, if_neg hheadZero] + · rw [Tape.write, ite_eq_right hheadZero] change Function.update (Function.update store (cellBase n bound slot + tape.head) (writeCode write)) (cellBase n bound slot) (symbolCode Γ.start) @@ -500,7 +500,7 @@ private theorem represents_of_named_tapes {tm : TM n} {bound : ℕ} · rcases state with ⟨state, hstateFin⟩ have hzero : state = 0 := by omega subst state - simpa [fieldReg_state_internal, fieldValue] using hstate + exact hstate · rcases headOrCell with head | cell · change store (headReg head) = (tapeAt cfg head).head by_cases hinputSlot : head = inputTape n @@ -622,7 +622,7 @@ private theorem actionPrelude_workPrefix {tm : TM n} {bound : ℕ} Function.update_of_ne honeReg] using hone have hinputStore : RepresentsTape bound (inputTape n) cfg.input store := by have htape := Represents.tape hrepresents (inputTape n) - simpa [inputTape] using htape + simpa [tapeAt, inputTape] using htape have hinputInitialized : RepresentsTape bound (inputTape n) cfg.input initialized := hinputStore.stateUpdate bound (inputTape n) cfg.input store @@ -718,7 +718,7 @@ private theorem workPrefix_list {tm : TM n} {bound : ℕ} (items.flatMap (fun i => writeMoveOps n bound (workTape i) (workWrites i) (workDirections i))) store) := by induction items generalizing processed store with - | nil => simpa using hprefix + | nil => simpa [Structured.Basic.execList] using hprefix | cons i rest ih => have hinot : i ∉ processed := hfresh i (by simp) have hnext := workPrefix_step hprefix i hinot (hheads i) (hstarts i) @@ -749,7 +749,7 @@ theorem actionOps_represents_internal {tm : TM n} {bound : ℕ} (fun i => (cfg.work i).read) cfg.output.read with ⟨nextState, workWrites, outputWrite, inputDirection, workDirections, outputDirection⟩ - rw [TM.step, if_neg hnotHalted, hdelta] at hstep + rw [TM.step, ite_eq_right hnotHalted, hdelta] at hstep dsimp only at hstep injection hstep with hnext subst next @@ -988,7 +988,8 @@ private theorem writeOps_envelopeChain (tm : TM n) (bound : ℕ) apply hstored.execBasic · exact hbaseLt · simpa [Structured.Internal.Basic.writeValue] using hstartBound - simpa [writeOps, first, addressed, valued, stored, final] using + simpa [StepEnvelopeChain, Structured.Internal.Basic.EnvelopeChain, writeOps, first, addressed, + valued, stored, final] using And.intro henvelope (And.intro hfirst (And.intro haddressed (And.intro hvalued (And.intro hstored hfinal)))) @@ -1030,7 +1031,7 @@ private theorem workPrefix_list_envelope {tm : TM n} {bound : ℕ} (items.reverse ++ processed) (Structured.Basic.execList ops store) ∧ StepEnvelopeChain tm bound ops store := by induction items generalizing processed store with - | nil => exact ⟨by simpa using hprefix, henvelope⟩ + | nil => exact ⟨by simpa [Structured.Basic.execList] using hprefix, henvelope⟩ | cons i rest ih => have hinot : i ∉ processed := hfresh i (by simp) have hselected : RepresentsTape bound (workTape i) (cfg.work i) store := by @@ -1091,7 +1092,7 @@ private theorem actionOps_envelopeChain_internal {tm : TM n} {bound : ℕ} [.imm 0 (stateCode tm nextState)] store := ⟨henvelope, hinitialized⟩ have hinputStore : RepresentsTape bound (inputTape n) cfg.input store := by have htape := Represents.tape hrepresents (inputTape n) - simpa [inputTape] using htape + exact htape have hinputHead : initialized (headReg (inputTape n)) ≤ bound := by have hhead := hheads (inputTape n) rw [show tapeAt cfg (inputTape n) = cfg.input by diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Layout.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Layout.lean index 5ec3702c..e7837745 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Layout.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Layout.lean @@ -109,7 +109,7 @@ theorem encodeRegs_storeBounded_internal (tm : TM n) (bound : ℕ) omega) · intro reg by_cases hreg : reg < registerCount n bound - · rw [encodeRegs, dif_pos hreg] + · rw [encodeRegs, dite_eq_left hreg] let field := (fieldEquiv n bound).symm ⟨reg, hreg⟩ change fieldValue tm bound cfg field ≤ wordBound tm bound rcases field with state | headOrCell diff --git a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Load.lean b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Load.lean index a5aa106c..5c240541 100644 --- a/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Load.lean +++ b/Complexitylib/Models/RandomAccessMachine/Simulation/TMConfig/Step/Internal/Load.lean @@ -158,7 +158,7 @@ private theorem loadTapes_loadedPrefix {tm : TM n} {bound : ℕ} LoadedPrefix tm bound cfg (tapes.reverse ++ processed) (Structured.Basic.execList (tapes.flatMap (loadTapeOps n bound)) store) := by induction tapes generalizing processed store with - | nil => simpa using hloaded + | nil => simpa [Structured.Basic.execList] using hloaded | cons tape rest ih => have hnext := loadTape_loadedPrefix hloaded tape (hheads tape) have hfinal := ih (processed := tape :: processed) hnext @@ -221,7 +221,7 @@ private theorem setupOps_envelopeChain {tm : TM n} {bound : ℕ} · simpa [Structured.Internal.Basic.writeValue] using honeValue have hstateStore : store 0 = stateCode tm cfg.state := by have hstate := hrepresents (stateField (n := n) (bound := bound)) - simpa [fieldReg_state_internal, fieldValue] using hstate + exact hstate have hsecondSource : second 0 = store 0 := by simp [second, first, Structured.Basic.exec, zeroReg, oneReg, scratchBase, registerCount, Function.update_of_ne] @@ -238,7 +238,8 @@ private theorem setupOps_envelopeChain {tm : TM n} {bound : ℕ} · simp only [Structured.Internal.Basic.writeValue] rw [hsecondSource, hsecondZero, hstateStore, Nat.add_zero] exact hstateBound - simpa [setupOps, first, second, final] using + simpa [setupOps, first, second, final, + Structured.Internal.Basic.EnvelopeChain] using And.intro henvelope (And.intro hfirst (And.intro hsecond hfinal)) private theorem loadTapeOps_envelopeChain {tm : TM n} {bound : ℕ} @@ -307,7 +308,8 @@ private theorem loadTapeOps_envelopeChain {tm : TM n} {bound : ℕ} apply haddressed.execBasic · exact hscratch.2.2.2.2.2 tape · exact haddressed.value_le (addressed (addressReg n bound)) - simpa [loadTapeOps, first, addressed, final] using + simpa [loadTapeOps, first, addressed, final, + Structured.Internal.Basic.EnvelopeChain] using And.intro henvelope (And.intro hfirst (And.intro haddressed hfinal)) private theorem loadTapes_envelopeChain {tm : TM n} {bound : ℕ} diff --git a/Complexitylib/Models/RandomAccessMachine/Soundness.lean b/Complexitylib/Models/RandomAccessMachine/Soundness.lean index 019a33dd..873403b6 100644 --- a/Complexitylib/Models/RandomAccessMachine/Soundness.lean +++ b/Complexitylib/Models/RandomAccessMachine/Soundness.lean @@ -58,7 +58,7 @@ private theorem sqProg_getElem_zero (k : ℕ) : private theorem sqProg_getElem_succ {k j : ℕ} (hj : j < k) : (sqProg k)[j + 1]? = some (Instr.mul 1 1 1) := by - simp only [sqProg, List.getElem?_cons_succ, List.getElem?_replicate, if_pos hj] + simp only [sqProg, List.getElem?_cons_succ, List.getElem?_replicate, ite_eq_left hj] /-- Squaring `2 ^ (2 ^ j)` yields `2 ^ (2 ^ (j + 1))`. -/ private theorem sq_pow (j : ℕ) : 2 ^ 2 ^ j * 2 ^ 2 ^ j = 2 ^ 2 ^ (j + 1) := by @@ -79,7 +79,7 @@ private theorem step_sqStart (k : ℕ) : step (sqProg k) sqStart = sqCfg 0 := by by_cases hi : i = 1 · subst hi; rw [Function.update_self]; rfl · rw [Function.update_of_ne hi] - simp only [sqStart, sqCfg, if_neg hi] + simp only [sqStart, sqCfg, ite_eq_right hi] /-- One squaring step from `sqCfg j` reaches `sqCfg (j + 1)`, provided the `(j + 1)`-th instruction is a `mul` (i.e. `j < k`). -/ @@ -97,7 +97,7 @@ private theorem step_sqCfg {k j : ℕ} (hj : j < k) : by_cases hi : i = 1 · subst hi; rw [Function.update_self]; exact sq_pow j · rw [Function.update_of_ne hi] - simp only [sqCfg, if_neg hi] + simp only [sqCfg, ite_eq_right hi] /-- The run invariant: `j + 1` steps of `sqProg k` from the start reach `sqCfg j`, for every `j ≤ k`. -/ @@ -170,7 +170,7 @@ theorem logGap_squaring {k : ℕ} (hk : 1 ≤ k) : -- Evaluate the one-step logarithmic cost of the final `mul`. have hstep1 : logTimeUpto (sqProg (m + 1)) 1 (sqCfg m) = stepLogCost (sqProg (m + 1)) (sqCfg m) := by - rw [show (1 : ℕ) = 0 + 1 from rfl, logTimeUpto_succ, if_neg hnh, logTimeUpto_zero, + rw [show (1 : ℕ) = 0 + 1 from rfl, logTimeUpto_succ, ite_eq_right hnh, logTimeUpto_zero, Nat.add_zero] have hval : (sqCfg m).regs 1 = 2 ^ 2 ^ m := by simp [sqCfg] have hcost : stepLogCost (sqProg (m + 1)) (sqCfg m) = diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/GateEval/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/GateEval/Internal.lean index 4c3fd18e..405bf0fb 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/GateEval/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/GateEval/Internal.lean @@ -272,11 +272,11 @@ private theorem address_measured (gate : CircuitCode.RawGate) (wires : List Bool (.add address0Reg address0Reg baseReg) (inputStore gate wires) hinitial hfirst have hrun1 := MeasuredRuns.basicEnvelope (.add address1Reg address1Reg baseReg) (addressed0 gate wires) hfirst (by - simpa only [addressed, addressOps, Basic.execList] using hfinal) + simpa only [StoreBound, addressed0, addressed, addressOps, Basic.execList] using hfinal) refine ⟨?_, hfinal⟩ have hrun := hrun0.seq hrun1 convert hrun using 1 - ring + all_goals first | rfl | ring private theorem load_measured (gate : CircuitCode.RawGate) (wires : List Bool) (hgate : gate.WellFormedAt wires.length) : @@ -301,11 +301,11 @@ private theorem load_measured (gate : CircuitCode.RawGate) (wires : List Bool) (addressed gate wires) hinitial hfirst have hrun1 := MeasuredRuns.basicEnvelope (.load value1Reg address1Reg) (loaded0 gate wires) hfirst (by - simpa only [loaded, loadOps, Basic.execList] using hfinal) + simpa only [StoreBound, loaded0, loaded, loadOps, Basic.execList] using hfinal) refine ⟨?_, hfinal⟩ have hrun := hrun0.seq hrun1 convert hrun using 1 - ring + all_goals first | rfl | ring private theorem negated0_measured (gate : CircuitCode.RawGate) (wires : List Bool) (value : Bool) (hvalue : wires[gate.input₀]? = some value) @@ -368,11 +368,12 @@ private theorem negated0_measured (gate : CircuitCode.RawGate) (wires : List Boo (negated0Product gate wires) hproduct htwice have hrun3 := MeasuredRuns.basicEnvelope (.sub value0Reg outputReg scratchReg) (negated0Twice gate wires) htwice (by - simpa only [negated0, xorOps, Basic.execList] using hfinal) + simpa only [StoreBound, negated0, negated0Twice, negated0Product, negated0Sum, xorOps, + Basic.execList] using hfinal) refine ⟨?_, hfinal⟩ have hrun := hrun0.seq (hrun1.seq (hrun2.seq hrun3)) convert hrun using 1 - ring + all_goals first | rfl | ring private theorem loaded_apply_of_ne (gate : CircuitCode.RawGate) (wires : List Bool) (index : ℕ) (h0 : index ≠ value0Reg) (h1 : index ≠ value1Reg) @@ -523,11 +524,12 @@ private theorem negated1_measured (gate : CircuitCode.RawGate) (wires : List Boo (negated1Product gate wires) hproduct htwice have hrun3 := MeasuredRuns.basicEnvelope (.sub value1Reg outputReg scratchReg) (negated1Twice gate wires) htwice (by - simpa only [negated1, xorOps, Basic.execList] using hfinal) + simpa only [StoreBound, negated1, negated1Twice, negated1Product, negated1Sum, xorOps, + Basic.execList] using hfinal) refine ⟨?_, hfinal⟩ have hrun := hrun0.seq (hrun1.seq (hrun2.seq hrun3)) convert hrun using 1 - ring + all_goals first | rfl | ring private theorem negated1_value0 (gate : CircuitCode.RawGate) (wires : List Bool) (value : Bool) (hvalue : wires[gate.input₀]? = some value) : @@ -669,11 +671,12 @@ private theorem eval_measured (gate : CircuitCode.RawGate) (wires : List Bool) (evalDelta gate wires) hdelta hselected have hrun5 := MeasuredRuns.basicEnvelope (.sub outputReg outputReg address0Reg) (evalSelected gate wires) hselected (by - simpa only [evaluated, evalOps, Basic.execList] using hfinal) + simpa only [StoreBound, evaluated, evalSelected, evalDelta, evalOr, evalSum, evalProduct, + evalOps, Basic.execList] using hfinal) refine ⟨?_, hfinal⟩ have hrun := hrun0.seq (hrun1.seq (hrun2.seq (hrun3.seq (hrun4.seq hrun5)))) convert hrun using 1 - ring + all_goals first | rfl | ring private theorem evaluated_apply_of_ne (gate : CircuitCode.RawGate) (wires : List Bool) (index : ℕ) (haddress : index ≠ address0Reg) @@ -841,7 +844,7 @@ private theorem append_measured (gate : CircuitCode.RawGate) (wires : List Bool) refine ⟨?_, hfinal⟩ have hrun := hrun0.seq hrun1 convert hrun using 1 - ring + all_goals first | rfl | ring private theorem routineAddressed_address0 {base : ℕ} {gate : CircuitCode.RawGate} {wires : List Bool} {store : Store} (hready : ReadyAt base gate wires store) : @@ -984,7 +987,7 @@ private theorem xor_measured {bound value negated : ℕ} {store : Store} refine ⟨?_, hfinal⟩ have hrun := hrun0.seq (hrun1.seq (hrun2.seq hrun3)) convert hrun using 1 - ring + all_goals first | rfl | ring private theorem routineNegated0_value {base : ℕ} {gate : CircuitCode.RawGate} {wires : List Bool} {store : Store} (hready : ReadyAt base gate wires store) @@ -1370,7 +1373,7 @@ theorem routine_measured_internal {bound base : ℕ} (envelopeSpace bound bound) := by have hrun := haddressRun0.seq haddressRun1 convert hrun using 1 - ring + all_goals first | rfl | ring let loaded0 := (Basic.load value0Reg address0Reg).exec (routineAddressed store) have hloaded0 : StoreEnvelope bound bound loaded0 := by apply haddressed.execBasic (.load value0Reg address0Reg) @@ -1393,7 +1396,7 @@ theorem routine_measured_internal {bound base : ℕ} (envelopeSpace bound bound) := by have hrun := hloadRun0.seq hloadRun1 convert hrun using 1 - ring + all_goals first | rfl | ring have hloadedValue0 := routineLoaded_value0 hready value0 hvalue0 have hloadedNegated0 : routineLoaded store negated0Reg = Input.bitValue gate.negated₀ := by @@ -1433,7 +1436,7 @@ theorem routine_measured_internal {bound base : ℕ} have hnegated1Run : MeasuredRuns (.basics (xorOps value1Reg negated1Reg)) (routineNegated0 store) (routineNegated1 store) 4 (16 * valueWidth bound) (envelopeSpace bound bound) := by - simpa [routineNegated1] using hxor1.1 + exact hxor1.1 have hvalue0Eq := routineNegated1_value0 hready value0 hvalue0 have hvalue1Eq := routineNegated1_value hready value1 hvalue1 have hopEq := routineNegated1_op hready @@ -1529,7 +1532,7 @@ theorem routine_measured_internal {bound base : ℕ} have hrun := hevalRun0.seq (hevalRun1.seq (hevalRun2.seq (hevalRun3.seq (hevalRun4.seq hevalRun5)))) convert hrun using 1 - ring + all_goals first | rfl | ring let appendAddressed := (Basic.add address1Reg baseReg wireCountReg).exec (routineEvaluated store) have happendAddressed : StoreEnvelope bound bound appendAddressed := by @@ -1560,13 +1563,13 @@ theorem routine_measured_internal {bound base : ℕ} (envelopeSpace bound bound) := by have hrun := happendRun0.seq happendRun1 convert hrun using 1 - ring + all_goals first | rfl | ring have hrun := haddressRun.seq (hloadRun.seq (hnegated0Run.seq (hnegated1Run.seq (hevalRun.seq happendRun)))) have hprogram : MeasuredRuns program store (routineFinal store) stepCount (80 * valueWidth bound) (envelopeSpace bound bound) := by convert hrun using 1 - all_goals ring + all_goals first | rfl | ring exact ⟨routineFinal store, hprogram, hfinal, routineFinal_output hready value0 value1 hvalue0 hvalue1, routineFinal_appended hready value0 value1 hvalue0 hvalue1, @@ -1611,6 +1614,7 @@ theorem routine_exec_internal {base : ℕ} {gate : CircuitCode.RawGate} routineFinal_frame hready⟩ · rw [program] convert hrun using 1 + all_goals rfl · intro index hindex exact routineFinal_wire hready index hindex @@ -1647,6 +1651,7 @@ theorem program_exec_internal (gate : CircuitCode.RawGate) (wires : List Bool) (max negated1Space (max evalSpace appendSpace)))), ?_, ?_⟩ · rw [program] convert hrun using 1 + all_goals rfl · exact finalStore_output gate wires value0 value1 hvalue0 hvalue1 theorem program_measured_internal (gate : CircuitCode.RawGate) (wires : List Bool) @@ -1674,8 +1679,7 @@ theorem program_measured_internal (gate : CircuitCode.RawGate) (wires : List Boo (finalStore gate wires) stepCount (timeBound wires.length) (resourceSpace wires.length) := by convert hrun using 1 - simp [timeBound, width, valueWidth] - ring + all_goals first | rfl | (unfold timeBound width valueWidth; ring) obtain ⟨cost, space, hexec, hcost, hspace⟩ := hprogram have hspace' : space ≤ spaceBound wires.length := by rw [← envelopeSpace_eq_spaceBound] diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/GateStep/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/GateStep/Internal.lean index f0d270be..d1adcd01 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/GateStep/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/GateStep/Internal.lean @@ -84,7 +84,7 @@ private theorem setup_measured (gate : CircuitCode.RawGate) (wires : List Bool) · apply hstore.execBasic (.imm UnaryDecode.activeReg 1) <;> simp [cursorBound, inputBits, UnaryDecode.activeReg, UnaryDecode.inputBase] - simpa [UnaryDecode.setup, setupStore] using + simpa [Structured.Basic.execList, UnaryDecode.setupOps, UnaryDecode.setup, setupStore] using MeasuredRuns.basicsEnvelope UnaryDecode.setupOps (inputStore gate wires) hinitial hpreserve @@ -298,7 +298,7 @@ private theorem header_measured (gate : CircuitCode.RawGate) (wires : List Bool) have hrun := r1.seq (r2.seq (r3.seq (r4.seq (r5.seq (r6.seq (r7.seq (r8.seq r9))))))) convert hrun using 1 - ring + all_goals first | rfl | ring private theorem header_cursorReady (gate : CircuitCode.RawGate) (wires : List Bool) : UnaryDecode.CursorReady (inputBits gate wires).length @@ -366,7 +366,7 @@ private theorem header_cursorReady (gate : CircuitCode.RawGate) (wires : List Bo rw [hpreserved] simp only [inputStore, Input.bitStore, UnaryDecode.remainingReg, UnaryDecode.inputBase] - rw [if_neg (by omega : 10 + delta ≠ 3), if_pos (by omega : 7 ≤ 10 + delta)] + erw [ite_eq_right (by omega : 10 + delta ≠ 3), ite_eq_left (by omega : 7 ≤ 10 + delta)] have hoffset : 10 + delta - 7 = 3 + delta := by omega rw [hoffset] change @@ -588,7 +588,7 @@ private theorem saveRestart_measured {bound : ℕ} {store : Store} refine ⟨?_, h4⟩ have hrun := h1.1.seq (r2.seq (r3.seq r4)) convert hrun using 1 - ring + all_goals first | rfl | ring private theorem marshal_measured {bound : ℕ} {store : Store} (hstore : StoreEnvelope bound bound store) (hsmall : 10 < bound) @@ -640,8 +640,8 @@ private theorem marshal_measured {bound : ℕ} {store : Store} · have hrun := r1.1.seq (r2.1.seq (r3.1.seq (r4.1.seq (r5.1.seq (r6.1.seq r7.1))))) convert hrun using 1 - ring - · simpa [marshalStore, marshalOps, s1, s2, s3, s4, s5, s6] using r7.2.1 + all_goals first | rfl | ring + · simpa [Structured.Basic.execList, marshalStore, marshalOps, s1, s2, s3, s4, s5, s6] using r7.2.1 private theorem input_wire (gate : CircuitCode.RawGate) (wires : List Bool) (index : ℕ) : @@ -656,7 +656,7 @@ private theorem input_wire (gate : CircuitCode.RawGate) (wires : List Bool) simp only [memoBase, UnaryDecode.inputBase, UnaryDecode.remainingReg] omega simp only [inputStore, Input.bitStore] - rw [if_neg hlength, if_pos hbase] + rw [ite_eq_right hlength, ite_eq_left hbase] have hoffset : memoBase gate + index - UnaryDecode.inputBase = gate.encode.length + index := by simp [memoBase] @@ -710,7 +710,7 @@ theorem program_measured_internal (gate : CircuitCode.RawGate) (wires : List Boo ((Basic.add savedInput0Reg UnaryDecode.valueReg UnaryDecode.activeReg).exec first) := by apply hfirstBound.execBasic - · simpa [savedInput0Reg, UnaryDecode.inputBase] using hlarge + · simpa [cursorBound, savedInput0Reg, UnaryDecode.inputBase] using hlarge · change first UnaryDecode.valueReg + first UnaryDecode.activeReg ≤ cursorBound gate wires rw [hfirstValue, hfirstActive] @@ -741,7 +741,7 @@ theorem program_measured_internal (gate : CircuitCode.RawGate) (wires : List Boo UnaryDecode.verdictReg, UnaryDecode.valueReg, UnaryDecode.activeReg] · simp [saved, saveRestartStore, saveRestartOps, Basic.execList, Basic.exec, UnaryDecode.verdictReg, UnaryDecode.valueReg, UnaryDecode.activeReg] - · change saved UnaryDecode.pointerReg = _ + · rw [show saved UnaryDecode.pointerReg = first UnaryDecode.pointerReg by apply saveRestart_apply_of_ne <;> simp [savedInput0Reg, UnaryDecode.verdictReg, UnaryDecode.valueReg, @@ -749,14 +749,14 @@ theorem program_measured_internal (gate : CircuitCode.RawGate) (wires : List Boo UnaryDecode.inputBase]] rw [hfirstPointer] omega - · change saved UnaryDecode.remainingReg = secondRemaining.length + · rw [show saved UnaryDecode.remainingReg = first UnaryDecode.remainingReg by apply saveRestart_apply_of_ne <;> simp [savedInput0Reg, UnaryDecode.verdictReg, UnaryDecode.valueReg, UnaryDecode.remainingReg, UnaryDecode.activeReg, UnaryDecode.inputBase]] exact hfirstRemaining - · change saved UnaryDecode.oneReg = 1 + · rw [show saved UnaryDecode.oneReg = first UnaryDecode.oneReg by apply saveRestart_apply_of_ne <;> simp [savedInput0Reg, UnaryDecode.verdictReg, UnaryDecode.valueReg, @@ -984,7 +984,8 @@ theorem program_measured_internal (gate : CircuitCode.RawGate) (wires : List Boo (28 * valueWidth (storeBound gate wires) + 80 * valueWidth (storeBound gate wires))))))) (envelopeSpace (storeBound gate wires) (storeBound gate wires)) := by - simpa [program, UnaryDecode.setup, setupStore, saved, marshaled, + simpa [program, Cmd.seqList, UnaryDecode.setupOps, headerOps, saveRestartOps, marshalOps, + UnaryDecode.setup, setupStore, saved, marshaled, saveRestartStore, marshalStore] using hrun have hcostLe : 20 * valueWidth (storeBound gate wires) + diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/GateStreamStep/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/GateStreamStep/Internal.lean index 5d4f04d3..06acf54e 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/GateStreamStep/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/GateStreamStep/Internal.lean @@ -676,7 +676,7 @@ private theorem decoders_internal {gateStart base : ℕ} {gate : CircuitCode.Raw · simp [saved, saveRestartStore, saveRestartOps, Basic.execList, Basic.exec, UnaryDecode.verdictReg, UnaryDecode.valueReg, UnaryDecode.activeReg] - · change saved UnaryDecode.pointerReg = _ + · rw [show saved UnaryDecode.pointerReg = first UnaryDecode.pointerReg by apply saveRestart_apply_of_ne <;> @@ -686,8 +686,7 @@ private theorem decoders_internal {gateStart base : ℕ} {gate : CircuitCode.Raw rw [hfirstPointer] simp [secondOffset] omega - · change saved UnaryDecode.remainingReg = - (secondRemaining gate tail).length + · rw [show saved UnaryDecode.remainingReg = first UnaryDecode.remainingReg by apply saveRestart_apply_of_ne <;> @@ -695,7 +694,7 @@ private theorem decoders_internal {gateStart base : ℕ} {gate : CircuitCode.Raw UnaryDecode.valueReg, UnaryDecode.remainingReg, UnaryDecode.activeReg]] exact hfirstRemaining - · change saved UnaryDecode.oneReg = 1 + · rw [show saved UnaryDecode.oneReg = first UnaryDecode.oneReg by apply saveRestart_apply_of_ne <;> simp [savedInput0Reg, UnaryDecode.verdictReg, @@ -1053,7 +1052,8 @@ theorem routine_exec_internal {gateStart base : ℕ} (max saveSpace (max secondSpace (max marshalSpace (max gateSpace restoreSpace)))))), ?_⟩ rw [← hsteps] - simpa [routine, setupStore, headerStore, saveRestartStore, marshaled, + simpa [Structured.Basic.execList, Cmd.seqList, setupOps, headerOps, saveRestartOps, + marshalOps, restoreOps, routine, setupStore, headerStore, saveRestartStore, marshaled, final, restoreStore] using hrun obtain ⟨cost, space, hexec⟩ := hexec exact ⟨final, cost, space, hexec, hfinalPointer, hfinalRemaining, diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/Hamming/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/Hamming/Internal.lean index 2d588073..2b8d3898 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/Hamming/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/Hamming/Internal.lean @@ -92,7 +92,7 @@ private theorem branched_bound {bit : Bool} {rest : List Bool} cases bit with | false => simpa [branched] using loaded_bound hinv.store_bound | true => - rw [branched, if_pos rfl] + rw [branched, ite_eq_left rfl] apply (loaded_bound hinv.store_bound).execBasic (.add countReg countReg oneReg) · simp [countReg] @@ -212,7 +212,7 @@ private theorem body_measured {bit : Bool} {rest : List Bool} (resourceSpace inputLength) := MeasuredRuns.basicEnvelope _ _ hadvancedBound hiteratedBound have hrun := hload.seq (hbranch.seq (hadvance.seq hdecrement)) - rw [body, Cmd.seqList] + simp only [body, Cmd.seqList] convert hrun using 1 · cases bit <;> simp [bitValue] · ring @@ -421,7 +421,7 @@ private theorem finalize_measured {inputLength : ℕ} {store : Store} (finalStore store) 1 (4 * width inputLength) (resourceSpace inputLength) := MeasuredRuns.basicEnvelope _ _ hzeroed hfinal have hrun := hzero.seq hadd - rw [finalize, Cmd.seqList] + simp only [finalize, Cmd.seqList] convert hrun using 1 all_goals ring diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/Internal.lean index 843da64f..c18da378 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/Internal.lean @@ -133,7 +133,7 @@ private theorem spaceUpto_add (P : Program) (first second : ℕ) (cfg : Cfg) : simp only [spaceUpto, run_succ] by_cases hhalt : Halted P cfg · simp [hhalt, spaceUpto_halted P hhalt] - · simp only [if_neg hhalt, ih] + · simp only [ite_eq_right hhalt, ih] omega private theorem run_space_le_spaceUpto (P : Program) (fuel : ℕ) (cfg : Cfg) : @@ -274,14 +274,14 @@ theorem compileAt_correct_internal rw [logTimeUpto_add _ branchSteps 1] rw [hbranchRun.2.1, hbranchRun.1] rw [show (1 : ℕ) = 0 + 1 from rfl, logTimeUpto_succ] - rw [if_neg hjmpHalt] + rw [ite_eq_right hjmpHalt] simp [stepLogCost, hjmpInstr', Instr.logCost] rw [spaceUpto] simp [Halted, curInstr] rw [step_jz_nonzero pre _ test _ store htest] rw [spaceUpto_add _ branchSteps 1, hbranchRun.2.2, hbranchRun.1] rw [show (1 : ℕ) = 0 + 1 from rfl, spaceUpto] - rw [if_neg hjmpHalt, hjmp'] + rw [ite_eq_right hjmpHalt, hjmp'] simp only [spaceUpto] have hfinalSpace : final.space ≤ branchSpace := by have hrunSpace := run_space_le_spaceUpto @@ -359,11 +359,11 @@ theorem compileAt_correct_internal rw [show bodySteps + loopSteps + 1 = bodySteps + (loopSteps + 1) by omega] rw [run_add, hbodyRun.1] rw [run_succ] - simp only [if_neg hjmpHalt] + simp only [ite_eq_right hjmpHalt] rw [hjmp', hloopRun.1] rw [logTimeUpto_add _ bodySteps (loopSteps + 1)] rw [hbodyRun.2.1, hbodyRun.1] - rw [logTimeUpto_succ, if_neg hjmpHalt] + rw [logTimeUpto_succ, ite_eq_right hjmpHalt] rw [hjmp', hloopRun.2.1] simp [stepLogCost, hjmpInstr', Instr.logCost] rw [spaceUpto] @@ -372,7 +372,7 @@ theorem compileAt_correct_internal rw [show bodySteps + loopSteps + 1 = bodySteps + (loopSteps + 1) by omega] rw [spaceUpto_add _ bodySteps (loopSteps + 1)] rw [hbodyRun.2.2, hbodyRun.1] - rw [spaceUpto, if_neg hjmpHalt, hjmp', hloopRun.2.2] + rw [spaceUpto, ite_eq_right hjmpHalt, hjmp', hloopRun.2.2] have hinitialSpace : store.space ≤ bodySpace := by have hstart := space_le_spaceUpto (pre ++ Instr.jz test (pre.length + (body.codeSize + 2)) :: diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/Internal/Resources.lean b/Complexitylib/Models/RandomAccessMachine/Structured/Internal/Resources.lean index 76531504..3c4460f2 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/Internal/Resources.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/Internal/Resources.lean @@ -73,9 +73,9 @@ theorem Input.bitStoreEnvelope {lengthReg inputBase indexBound valueBound : ℕ} · intro index by_cases hlengthRegEq : index = lengthReg · simpa [Input.bitStore, hlengthRegEq] using hlength - · rw [Input.bitStore, if_neg hlengthRegEq] + · rw [Input.bitStore, ite_eq_right hlengthRegEq] by_cases hbase : inputBase ≤ index - · rw [if_pos hbase] + · rw [ite_eq_left hbase] cases hlookup : bits[index - inputBase]? with | none => simp | some bit => @@ -319,15 +319,16 @@ theorem exec_basics_exists (ops : List Basic) (initial : Store) : | nil => exact ⟨op.logCost initial, max initial.space (op.exec initial).space, by - simpa [Cmd.basics, Basic.execList] using Exec.basic op initial⟩ + simpa [Cmd.basics, Basic.execList, Cmd.seqList] using Exec.basic op initial⟩ | cons next tail => obtain ⟨cost, space, hrest⟩ := ih (initial := op.exec initial) refine ⟨op.logCost initial + cost, max (max initial.space (op.exec initial).space) space, ?_⟩ have hrun := Exec.seq (Exec.basic op initial) hrest convert hrun using 1 - all_goals simp - all_goals omega + · rfl + · rfl + · simp only [List.length_cons]; omega namespace MeasuredRuns @@ -369,14 +370,14 @@ theorem basicsEnvelope {indexBound valueBound : ℕ} (ops : List Basic) StoreEnvelope indexBound valueBound (Basic.execList ops initial) := by induction ops generalizing initial with | nil => - exact ⟨by simpa [Cmd.basics, Basic.execList] using skipEnvelope hinitial, + exact ⟨by simpa [Cmd.basics, Basic.execList, Cmd.seqList] using skipEnvelope hinitial, hinitial⟩ | cons op rest ih => have hnext := hpreserve op (by simp) initial hinitial have hfirst := basicEnvelope op initial hinitial hnext cases rest with | nil => - exact ⟨by simpa [Cmd.basics, Basic.execList] using hfirst, hnext⟩ + exact ⟨by simpa [Cmd.basics, Basic.execList, Cmd.seqList] using hfirst, hnext⟩ | cons next tail => obtain ⟨hrest, hfinal⟩ := ih (initial := op.exec initial) hnext (by intro candidate hcandidate store hstore @@ -401,7 +402,7 @@ theorem basicsEnvelopeChain {indexBound valueBound : ℕ} (ops : List Basic) StoreEnvelope indexBound valueBound (Basic.execList ops initial) := by induction ops generalizing initial with | nil => - exact ⟨by simpa [Cmd.basics, Basic.execList] using skipEnvelope hchain, + exact ⟨by simpa [Cmd.basics, Basic.execList, Cmd.seqList] using skipEnvelope hchain, hchain⟩ | cons op rest ih => have hinitial := hchain.1 @@ -413,7 +414,7 @@ theorem basicsEnvelopeChain {indexBound valueBound : ℕ} (ops : List Basic) have hfirst := basicEnvelope op initial hinitial hnext cases rest with | nil => - exact ⟨by simpa [Cmd.basics, Basic.execList] using hfirst, hnext⟩ + exact ⟨by simpa [Cmd.basics, Basic.execList, Cmd.seqList] using hfirst, hnext⟩ | cons next tail => obtain ⟨hrest, hfinal⟩ := ih (initial := op.exec initial) htail diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/LastBit.lean b/Complexitylib/Models/RandomAccessMachine/Structured/LastBit.lean index 7f27c5da..7ade26e5 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/LastBit.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/LastBit.lean @@ -41,8 +41,9 @@ theorem program_performance (target : Bool) (bits : List Bool) : cost ≤ timeBound target bits.length ∧ space ≤ spaceBound target bits.length ∧ final verdictReg = Input.bitValue (decide (bits.getLast? = some target)) := by - simpa [spec, lastBit_fold_eq_getLast?] using - Scanner.typed_program_performance (spec target) bits + have h := Scanner.typed_program_performance (spec target) bits + simp only [spec, lastBit_fold_eq_getLast?] at h ⊢ + exact h /-- End-to-end compiled performance and language correctness. -/ theorem compiled_performance (target : Bool) (bits : List Bool) : @@ -68,7 +69,8 @@ theorem compiled_performance (target : Bool) (bits : List Bool) : rw [show (run (compiled target) (stepCount target bits.length) { pc := 0, regs := inputStore target bits }).regs verdictReg = Input.bitValue (decide (bits.getLast? = some target)) by - simpa [spec, lastBit_fold_eq_getLast?] using hresult] + simp only [spec, lastBit_fold_eq_getLast?] at hresult ⊢ + exact hresult] simp [Input.bitValue] /-- The explicit time budget is quasilinear. -/ diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/Scanner/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/Scanner/Internal.lean index f64c60dc..e263930c 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/Scanner/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/Scanner/Internal.lean @@ -526,7 +526,7 @@ private theorem body_measured {spec : Spec} {bit : Bool} {rest : List Bool} constructor · simp only [body, Cmd.basics, bodyOps, List.map_cons, List.map_nil, Cmd.seqList] convert hrun using 1 - ring + all_goals first | rfl | ring · exact hiterated private theorem addressed_address_of_inv {spec : Spec} {bit : Bool} @@ -755,7 +755,7 @@ private theorem finalize_measured {spec : Spec} {inputLength state : ℕ} · simp only [finalize, Cmd.basics, finalizeOps, List.map_cons, List.map_nil, Cmd.seqList] convert hrun using 1 - ring + all_goals first | rfl | ring · change ((Basic.load lengthReg addressReg).exec indexed) lengthReg = _ simp [Basic.exec, haddress, htable] diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/Switch/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/Switch/Internal.lean index f62a6a3a..b0256943 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/Switch/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/Switch/Internal.lean @@ -101,7 +101,7 @@ theorem select_exec_internal {count test one : ℕ} (max (max initial.space ((Basic.sub test test one).exec initial).space) recursiveSpace), ?_⟩ convert hrun using 1 - all_goals simp [stepCount] + all_goals simp [select, stepCount] all_goals omega theorem select_measured_internal {count test one indexBound valueBound : ℕ} @@ -168,7 +168,7 @@ theorem select_measured_internal {count test one indexBound valueBound : ℕ} have hrun := MeasuredRuns.ifNonzeroEnvelope (onZero := branch ⟨0, by omega⟩) hnonzero hinitial (hdecrement.seq hrecursive) - convert hrun using 1 <;> simp [stepCount, costBound] + convert hrun using 1 <;> simp [select, stepCount, costBound] all_goals ring end Switch diff --git a/Complexitylib/Models/RandomAccessMachine/Structured/UnaryDecode/Internal.lean b/Complexitylib/Models/RandomAccessMachine/Structured/UnaryDecode/Internal.lean index b2769341..8b8e363a 100644 --- a/Complexitylib/Models/RandomAccessMachine/Structured/UnaryDecode/Internal.lean +++ b/Complexitylib/Models/RandomAccessMachine/Structured/UnaryDecode/Internal.lean @@ -339,7 +339,8 @@ private theorem false_body_measured {rest : List Bool} hremaining hinv.store_bound (by simpa [consume, Cmd.seqList] using hconsume) refine ⟨?_, hsuccess⟩ - apply MeasuredRuns.weakenCost (by simpa [body] using hrun) + apply MeasuredRuns.weakenCost (by simpa [body, width, consume, Cmd.seqList, resourceSpace] + using hrun) change 3 * width inputLength + (4 * width inputLength + (4 * width inputLength + @@ -382,7 +383,8 @@ private theorem true_body_measured {rest : List Bool} hremaining hinv.store_bound (by simpa [consume, Cmd.seqList] using hconsume) constructor - · apply MeasuredRuns.weakenCost (by simpa [body] using hrun) + · apply MeasuredRuns.weakenCost (by simpa [body, width, consume, Cmd.seqList, resourceSpace, + continuedStore] using hrun) change 3 * width inputLength + (4 * width inputLength + (4 * width inputLength + @@ -508,7 +510,9 @@ private theorem loop_measured {remaining : List Bool} have hrun := MeasuredRuns.whileNonzeroEnvelope hactive hinv.store_bound (by simpa [body] using hbodyRun) hstop refine ⟨truncatedStore store, ?_, ?_, ?_, ?_, ?_, htruncatedBound⟩ - · apply MeasuredRuns.weakenCost (by simpa [mainLoop] using hrun) + · apply MeasuredRuns.weakenCost (by simpa [mainLoop, width, resourceSpace, + CircuitCode.NatCode.decodePrefix?, + CircuitCode.NatCode.decodeAux?] using hrun) change 3 * width inputLength + (width inputLength + 8 * width inputLength) + width inputLength ≤ @@ -548,10 +552,9 @@ private theorem loop_measured {remaining : List Bool} have hrun := MeasuredRuns.whileNonzeroEnvelope hactive hinv.store_bound hbody hstop refine ⟨successStore store, ?_, ?_, ?_, ?_, ?_, hsuccessBound⟩ - · apply MeasuredRuns.weakenCost (by simpa [mainLoop] using hrun) - change 3 * width inputLength + 32 * width inputLength + - width inputLength ≤ - 64 * ((false :: rest).length + 1) * width inputLength + · apply MeasuredRuns.weakenCost (by simpa [mainLoop, width, resourceSpace, + CircuitCode.NatCode.decodePrefix?, + CircuitCode.NatCode.decodeAux?] using hrun) calc _ = 36 * width inputLength := by ring _ ≤ (64 * (rest.length + 2)) * width inputLength := @@ -604,9 +607,6 @@ private theorem loop_measured {remaining : List Bool} convert hrun using 1 all_goals omega apply MeasuredRuns.weakenCost hrun' - change 3 * width inputLength + 32 * width inputLength + - (64 * (rest.length + 1) * width inputLength) ≤ - 64 * ((true :: rest).length + 1) * width inputLength calc _ = (64 * (rest.length + 1) + 35) * width inputLength := by ring _ ≤ (64 * (rest.length + 2)) * width inputLength := @@ -625,9 +625,6 @@ private theorem loop_measured {remaining : List Bool} convert hrun using 1 all_goals omega apply MeasuredRuns.weakenCost hrun' - change 3 * width inputLength + 32 * width inputLength + - (64 * (rest.length + 1) * width inputLength) ≤ - 64 * ((true :: rest).length + 1) * width inputLength calc _ = (64 * (rest.length + 1) + 35) * width inputLength := by ring _ ≤ (64 * (rest.length + 2)) * width inputLength := @@ -688,7 +685,7 @@ theorem mainLoop_measured_internal {remaining : List Bool} exact hspace refine ⟨final, cost, space, ?_, le_trans hcost hcostBound, hspaceBound, hresult, hactive, hone, hframe, hfinalBound⟩ - simpa [loopStepCount] using hexec + exact hexec theorem program_measured_internal (bits : List Bool) : ∃ final cost space, diff --git a/Complexitylib/Models/TuringMachine.lean b/Complexitylib/Models/TuringMachine.lean index 39d7662b..6110e8f0 100644 --- a/Complexitylib/Models/TuringMachine.lean +++ b/Complexitylib/Models/TuringMachine.lean @@ -714,7 +714,7 @@ theorem trace_startInvariant (tm : NTM n) (T : ℕ) | succ T ih => by_cases hhalt : c.state = tm.qhalt · simpa [trace, hhalt] using And.intro hinp (And.intro hwork hout) - · simp only [trace, hhalt, if_false] + · simp only [trace, hhalt, ite_false] apply ih · exact hinp.move _ · intro i @@ -776,7 +776,7 @@ theorem trace_mono (tm : NTM n) {T T' : ℕ} (hle : T ≤ T') rw [hcT, hcT'] · have hch0 := hagree ⟨0, Nat.zero_lt_succ _⟩ have hle' : T ≤ T' := Nat.le_of_succ_le_succ hle - simp only [NTM.trace, hc, hch0, if_false] at h ⊢ + simp only [NTM.trace, hc, hch0, ite_false] at h ⊢ exact ih hle' (fun i => hagree ⟨i.val + 1, by omega⟩) h /-- NTM acceptance is monotone in the time bound: `AcceptsInTime x T` implies diff --git a/Complexitylib/Models/TuringMachine/Branch.lean b/Complexitylib/Models/TuringMachine/Branch.lean index 4dcc95a7..df1b00d8 100644 --- a/Complexitylib/Models/TuringMachine/Branch.lean +++ b/Complexitylib/Models/TuringMachine/Branch.lean @@ -72,8 +72,8 @@ theorem branchTM_step (tm : NTM k) (b : Bool) {c : Cfg k tm.Q} (h : c.state ≠ /-- A halted configuration has no successor on either branch. -/ theorem branchTM_step_of_halted (tm : NTM k) (b : Bool) {c : Cfg k tm.Q} (h : c.state = tm.qhalt) : (tm.branchTM b).step c = none := by - rw [TM.step] - exact if_pos (show c.state = (tm.branchTM b).qhalt from h) + simp only [TM.step] + exact ite_eq_left (show c.state = (tm.branchTM b).qhalt from h) end NTM diff --git a/Complexitylib/Models/TuringMachine/ChoiceTape.lean b/Complexitylib/Models/TuringMachine/ChoiceTape.lean index 644de84e..daaea56d 100644 --- a/Complexitylib/Models/TuringMachine/ChoiceTape.lean +++ b/Complexitylib/Models/TuringMachine/ChoiceTape.lean @@ -52,7 +52,7 @@ def stepCfg (tm : TM k) (c : Cfg k tm.Q) : Cfg k tm.Q := theorem step_of_not_halted (tm : TM k) {c : Cfg k tm.Q} (h : c.state ≠ tm.qhalt) : tm.step c = some (tm.stepCfg c) := by unfold TM.step - rw [if_neg h] + rw [ite_eq_right h] rfl end TM diff --git a/Complexitylib/Models/TuringMachine/Combinators.lean b/Complexitylib/Models/TuringMachine/Combinators.lean index f516ee0a..42270fe6 100644 --- a/Complexitylib/Models/TuringMachine/Combinators.lean +++ b/Complexitylib/Models/TuringMachine/Combinators.lean @@ -325,20 +325,20 @@ def unionTM (tm₁ : TM n₁) (tm₂ : TM n₂) : TM (n₁ + 1 + n₂) := match m with | .rewindOut => dsimp only [fakeOutIdx] - split + by_cases hw : wHeads ⟨n₁, by omega⟩ = Γ.start <;> simp only [hw, ↓reduceIte] · refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ - intro i hwi; simp only []; split + intro i hwi; split · rfl · exact idleDir_right_of_start hwi · refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ - intro i hwi; simp only []; split - · next hn heq => - exfalso; apply hn + intro i hwi; split + · next heq => + exfalso; apply hw rwa [show wHeads ⟨n₁, by omega⟩ = wHeads i from by congr 1; ext; simp [heq]] · exact idleDir_right_of_start hwi | .checkResult => dsimp only [fakeOutIdx] - split + by_cases hw : wHeads ⟨n₁, by omega⟩ = Γ.one <;> simp only [hw, ↓reduceIte] · exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ · exact rightOfStart_allIdle iHead wHeads oHead | .rewindIn => diff --git a/Complexitylib/Models/TuringMachine/Combinators/ApplyDecide.lean b/Complexitylib/Models/TuringMachine/Combinators/ApplyDecide.lean index 87c832a5..c11eb64d 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/ApplyDecide.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/ApplyDecide.lean @@ -63,7 +63,8 @@ theorem retargetInputStarted_hoareTime_decide (M : TM k) {L : Language} {T : ℕ retargetInputStartedCfg M y inp := Cfg.ext rfl rfl hpre.1 hpre.2 refine ⟨c', t, ht, ?_, hhalt, hone, hzero⟩ - convert hreach using 1 + erw [hstart] + exact hreach /-- **The work-to-work evaluator, for a decider.** The verdict lands in cell one of the fresh last work tape, and the real output stays the parked blank tape a wipe needs. -/ @@ -135,7 +136,7 @@ theorem applyTM_entry_eq (M : TM k) (y : List Bool) (realInput : Tape) : show applyPre M y realInput i = (if h : i.val < k + 1 then (retargetInputStartedCfg M y realInput).work ⟨i.val, h⟩ else (retargetInputStartedCfg M y realInput).output) - rw [dif_pos hi, ← congrFun (applyPre_spec M y realInput).1 ⟨i.val, hi⟩, hidx] + rw [dite_eq_left hi, ← congrFun (applyPre_spec M y realInput).1 ⟨i.val, hi⟩, hidx] · have hlast : i = Fin.last (k + 1) := Fin.ext (by have h1 := i.isLt have h2 : (Fin.last (k + 1)).val = k + 1 := rfl @@ -143,7 +144,7 @@ theorem applyTM_entry_eq (M : TM k) (y : List Bool) (realInput : Tape) : show applyPre M y realInput i = (if h : i.val < k + 1 then (retargetInputStartedCfg M y realInput).work ⟨i.val, h⟩ else (retargetInputStartedCfg M y realInput).output) - rw [dif_neg hi, hlast, (applyPre_spec M y realInput).2] + rw [dite_eq_right hi, hlast, (applyPre_spec M y realInput).2] rfl /-- **The decider's evaluator, framed by its space bound.** The disturbance is bounded by the diff --git a/Complexitylib/Models/TuringMachine/Combinators/ForBinaryWork/Internal.lean b/Complexitylib/Models/TuringMachine/Combinators/ForBinaryWork/Internal.lean index 90f2041f..81a7a08c 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/ForBinaryWork/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/ForBinaryWork/Internal.lean @@ -41,9 +41,9 @@ theorem forBinaryWorkTM_body_step_internal (driverIdx : Fin n) (body : TM n) (forBinaryWorkBodyWrap driverIdx body cfg) = some (forBinaryWorkBodyWrap driverIdx body next) := by have hne : cfg.state ≠ body.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [forBinaryWorkBodyWrap, forBinaryWorkTM])] + rw [TM.step, ite_eq_right (by simp [forBinaryWorkBodyWrap, forBinaryWorkTM])] simp only [forBinaryWorkBodyWrap, forBinaryWorkTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize body.δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -85,7 +85,7 @@ theorem forBinaryWorkTM_step_scan_bit_internal have hblank : (cfg.work driverIdx).read ≠ Γ.blank := by rw [hbit] cases bit <;> decide - rw [TM.step, if_neg (by rw [hstate]; simp [forBinaryWorkTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [forBinaryWorkTM])] simp only [forBinaryWorkTM, hstate, hstart, hblank, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) @@ -108,7 +108,7 @@ theorem forBinaryWorkTM_step_scan_blank_internal input := cfg.input work := cfg.work output := cfg.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [forBinaryWorkTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [forBinaryWorkTM])] simp only [forBinaryWorkTM, hstate, hblank, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) @@ -133,7 +133,7 @@ theorem forBinaryWorkTM_step_body_halt_internal if i = driverIdx then (cfg.work i).move Dir3.right else cfg.work i output := cfg.output } := by - rw [TM.step, if_neg (by simp [forBinaryWorkBodyWrap, forBinaryWorkTM])] + rw [TM.step, ite_eq_right (by simp [forBinaryWorkBodyWrap, forBinaryWorkTM])] simp only [forBinaryWorkBodyWrap, forBinaryWorkTM, hhalt, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -141,9 +141,9 @@ theorem forBinaryWorkTM_step_body_halt_internal rw [writeAndMove_readBack _ (hwork i)] split · rfl - · rw [idleDir, if_neg (hwork i)] + · rw [idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- A certified bit-driven loop has its advertised exact remaining run. -/ diff --git a/Complexitylib/Models/TuringMachine/Combinators/ForInput/Internal.lean b/Complexitylib/Models/TuringMachine/Combinators/ForInput/Internal.lean index 5bd8852f..2d6867fe 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/ForInput/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/ForInput/Internal.lean @@ -40,9 +40,9 @@ theorem forInputTM_body_step_internal (body : TM n) (forInputTM body).step (forInputBodyWrap body c) = some (forInputBodyWrap body c') := by have hne : c.state ≠ body.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [forInputBodyWrap, forInputTM])] + rw [TM.step, ite_eq_right (by simp [forInputBodyWrap, forInputTM])] simp only [forInputBodyWrap, forInputTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize body.δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action obtain ⟨q', workWrites, outputWrite, inputDir, workDirs, outputDir⟩ := action @@ -71,13 +71,13 @@ theorem forInputTM_step_scan_bit_internal (body : TM n) input := c.input.move Dir3.right work := c.work output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [forInputTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [forInputTM])] simp only [forInputTM, hstate, hstart, hblank, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i - rw [writeAndMove_readBack _ (hwork i), idleDir, if_neg (hwork i)] + rw [writeAndMove_readBack _ (hwork i), idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- At the first input blank, the driver halts while preserving all off-start @@ -93,14 +93,14 @@ theorem forInputTM_step_scan_blank_internal (body : TM n) work := c.work output := c.output } := by have hstart : c.input.read ≠ Γ.start := by rw [hblank]; decide - rw [TM.step, if_neg (by rw [hstate]; simp [forInputTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [forInputTM])] simp only [forInputTM, hstate, hblank, allReadBack, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · simp [idleDir, Tape.move] · funext i - rw [writeAndMove_readBack _ (hwork i), idleDir, if_neg (hwork i)] + rw [writeAndMove_readBack _ (hwork i), idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- A halted body takes one preserving seam step back to the input scanner. -/ @@ -114,14 +114,14 @@ theorem forInputTM_step_body_halt_internal (body : TM n) input := c.input work := c.work output := c.output } := by - rw [TM.step, if_neg (by simp [forInputBodyWrap, forInputTM])] + rw [TM.step, ite_eq_right (by simp [forInputBodyWrap, forInputTM])] simp only [forInputBodyWrap, forInputTM, hhalt, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i - rw [writeAndMove_readBack _ (hwork i), idleDir, if_neg (hwork i)] + rw [writeAndMove_readBack _ (hwork i), idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- A certified input-driven loop has the advertised exact remaining run. -/ diff --git a/Complexitylib/Models/TuringMachine/Combinators/ForWorkOnes/Internal.lean b/Complexitylib/Models/TuringMachine/Combinators/ForWorkOnes/Internal.lean index 68cdee50..2c338681 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/ForWorkOnes/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/ForWorkOnes/Internal.lean @@ -39,9 +39,9 @@ theorem forWorkOnesTM_body_step_internal (driverIdx : Fin n) (body : TM n) (forWorkOnesBodyWrap driverIdx body cfg) = some (forWorkOnesBodyWrap driverIdx body next) := by have hne : cfg.state ≠ body.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [forWorkOnesBodyWrap, forWorkOnesTM])] + rw [TM.step, ite_eq_right (by simp [forWorkOnesBodyWrap, forWorkOnesTM])] simp only [forWorkOnesBodyWrap, forWorkOnesTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize body.δ cfg.state cfg.input.read (fun i => (cfg.work i).read) cfg.output.read = action @@ -74,18 +74,18 @@ theorem forWorkOnesTM_step_scan_one_internal (driverIdx : Fin n) (body : TM n) work := fun i => if i = driverIdx then (cfg.work i).move Dir3.right else cfg.work i output := cfg.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [forWorkOnesTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [forWorkOnesTM])] simp only [forWorkOnesTM, hstate, hone, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) - · rw [idleDir, if_neg hinput] + · rw [idleDir, ite_eq_right hinput] rfl · funext i rw [writeAndMove_readBack _ (hwork i)] split · rfl - · rw [idleDir, if_neg (hwork i)] + · rw [idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- On the zero separator, the driver halts without consuming it. -/ @@ -103,15 +103,15 @@ theorem forWorkOnesTM_step_scan_zero_internal (driverIdx : Fin n) (body : TM n) output := cfg.output } := by have hstart : (cfg.work driverIdx).read ≠ Γ.start := by rw [hzero]; decide have hone : (cfg.work driverIdx).read ≠ Γ.one := by rw [hzero]; decide - rw [TM.step, if_neg (by rw [hstate]; simp [forWorkOnesTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [forWorkOnesTM])] simp only [forWorkOnesTM, hstate, hstart, hone, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) - · rw [idleDir, if_neg hinput] + · rw [idleDir, ite_eq_right hinput] rfl · funext i - rw [writeAndMove_readBack _ (hwork i), idleDir, if_neg (hwork i)] + rw [writeAndMove_readBack _ (hwork i), idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- A halted body takes one preserving seam step back to the scanner. -/ @@ -126,14 +126,14 @@ theorem forWorkOnesTM_step_body_halt_internal (driverIdx : Fin n) (body : TM n) input := cfg.input work := cfg.work output := cfg.output } := by - rw [TM.step, if_neg (by simp [forWorkOnesBodyWrap, forWorkOnesTM])] + rw [TM.step, ite_eq_right (by simp [forWorkOnesBodyWrap, forWorkOnesTM])] simp only [forWorkOnesBodyWrap, forWorkOnesTM, hhalt, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i - rw [writeAndMove_readBack _ (hwork i), idleDir, if_neg (hwork i)] + rw [writeAndMove_readBack _ (hwork i), idleDir, ite_eq_right (hwork i)] rfl - · rw [writeAndMove_readBack _ houtput, idleDir, if_neg houtput] + · rw [writeAndMove_readBack _ houtput, idleDir, ite_eq_right houtput] rfl /-- A certified consecutive-one loop has its advertised exact remaining run. -/ diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/IdleHeads.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/IdleHeads.lean index b9c68945..86282503 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/IdleHeads.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/IdleHeads.lean @@ -74,7 +74,7 @@ theorem head_writeAndMove_idleDir_le_max (t : Tape) (w : Γw) (h : t.StartInvari (t.writeAndMove w (idleDir t.read)).head ≤ max t.head 1 := by refine head_writeAndMove_le_max t w _ fun hd => ?_ by_contra hne - exact absurd hd (by rw [idleDir, if_neg (h.read_ne_start (by omega))]; nofun) + exact absurd hd (by rw [idleDir, ite_eq_right (h.read_ne_start (by omega))]; nofun) /-- **The single step `seqTM` interposes between its two simulations idles every tape.** -/ theorem seq_head_bound (tm₁ tm₂ : TM n) {c c' : Cfg n (seqTM tm₁ tm₂).Q} diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/If.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/If.lean index f4ecd648..6bf69f79 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/If.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/If.lean @@ -89,9 +89,8 @@ theorem ifTM_test_step (tmTest tmThen tmElse : TM n) {c c' : Cfg n tmTest.Q} have hne : c.state ≠ tmTest.qhalt := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (ifTestWrap tmTest tmThen tmElse c).state = - (ifTM tmTest tmThen tmElse).qhalt then none else some _) = some _ - simp only [ifTestWrap, ifTM, if_neg ifQ_test_ne_halt, if_neg hne] + unfold step + simp only [ifTestWrap, ifTM, ite_eq_right ifQ_test_ne_halt, ite_eq_right hne] /-- Multi-step test phase simulation. -/ theorem ifTM_reachesIn_ifTestWrap (tmTest tmThen tmElse : TM n) {t : ℕ} @@ -115,9 +114,8 @@ theorem ifTM_then_step (tmTest tmThen tmElse : TM n) {c c' : Cfg n tmThen.Q} have hne : c.state ≠ tmThen.qhalt := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (ifThenWrap tmTest tmThen tmElse c).state = - (ifTM tmTest tmThen tmElse).qhalt then none else some _) = some _ - simp only [ifThenWrap, ifTM, if_neg ifQ_then_ne_halt, if_neg hne] + unfold step + simp only [ifThenWrap, ifTM, ite_eq_right ifQ_then_ne_halt, ite_eq_right hne] /-- Multi-step then-branch simulation. -/ theorem ifTM_reachesIn_ifThenWrap (tmTest tmThen tmElse : TM n) {t : ℕ} @@ -141,9 +139,8 @@ theorem ifTM_else_step (tmTest tmThen tmElse : TM n) {c c' : Cfg n tmElse.Q} have hne : c.state ≠ tmElse.qhalt := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (ifElseWrap tmTest tmThen tmElse c).state = - (ifTM tmTest tmThen tmElse).qhalt then none else some _) = some _ - simp only [ifElseWrap, ifTM, if_neg ifQ_else_ne_halt, if_neg hne] + unfold step + simp only [ifElseWrap, ifTM, ite_eq_right ifQ_else_ne_halt, ite_eq_right hne] /-- Multi-step else-branch simulation. -/ theorem ifTM_reachesIn_ifElseWrap (tmTest tmThen tmElse : TM n) {t : ℕ} @@ -167,9 +164,8 @@ theorem ifTM_then_halt_step (tmTest tmThen tmElse : TM n) {c : Cfg n tmThen.Q} input := transitionInput c.input, work := fun i => transitionTape (c.work i), output := transitionTape c.output } := by - show (if (ifThenWrap tmTest tmThen tmElse c).state = - (ifTM tmTest tmThen tmElse).qhalt then none else some _) = some _ - simp only [ifThenWrap, ifTM, if_neg ifQ_then_ne_halt, hhalt, ↓reduceIte] + unfold step + simp only [ifThenWrap, ifTM, ite_eq_right ifQ_then_ne_halt, hhalt, ↓reduceIte] congr 1 /-- When `tmElse` halts, one step transitions to `done`. -/ @@ -180,9 +176,8 @@ theorem ifTM_else_halt_step (tmTest tmThen tmElse : TM n) {c : Cfg n tmElse.Q} input := transitionInput c.input, work := fun i => transitionTape (c.work i), output := transitionTape c.output } := by - show (if (ifElseWrap tmTest tmThen tmElse c).state = - (ifTM tmTest tmThen tmElse).qhalt then none else some _) = some _ - simp only [ifElseWrap, ifTM, if_neg ifQ_else_ne_halt, hhalt, ↓reduceIte] + unfold step + simp only [ifElseWrap, ifTM, ite_eq_right ifQ_else_ne_halt, hhalt, ↓reduceIte] congr 1 -- ════════════════════════════════════════════════════════════════════════ @@ -197,9 +192,8 @@ theorem ifTM_test_to_rewind (tmTest tmThen tmElse : TM n) {c : Cfg n tmTest.Q} input := transitionInput c.input, work := fun i => transitionTape (c.work i), output := transitionTape c.output } := by - show (if (ifTestWrap tmTest tmThen tmElse c).state = - (ifTM tmTest tmThen tmElse).qhalt then none else some _) = some _ - simp only [ifTestWrap, ifTM, if_neg ifQ_test_ne_halt, hhalt, ↓reduceIte] + unfold step + simp only [ifTestWrap, ifTM, ite_eq_right ifQ_test_ne_halt, hhalt, ↓reduceIte] congr 1 -- ════════════════════════════════════════════════════════════════════════ diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/Loop.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/Loop.lean index e544f80b..20691505 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/Loop.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/Loop.lean @@ -72,9 +72,8 @@ theorem loopTM_body_step (tmBody tmTest : TM n) {c c' : Cfg n tmBody.Q} have hne : c.state ≠ tmBody.qhalt := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (loopBodyWrap tmBody tmTest c).state = - (loopTM tmBody tmTest).qhalt then none else some _) = some _ - simp only [loopBodyWrap, loopTM, if_neg loopQ_body_ne_halt, if_neg hne] + unfold step + simp only [loopBodyWrap, loopTM, ite_eq_right loopQ_body_ne_halt, ite_eq_right hne] /-- A `t`-step run of `tmBody` lifts to a `t`-step run of `loopTM` between the body-wrapped configurations. -/ @@ -101,9 +100,8 @@ theorem loopTM_body_to_test (tmBody tmTest : TM n) {c : Cfg n tmBody.Q} input := transitionInput c.input, work := fun i => transitionTape (c.work i), output := transitionTape c.output }) := by - show (if (loopBodyWrap tmBody tmTest c).state = - (loopTM tmBody tmTest).qhalt then none else some _) = some _ - simp only [loopBodyWrap, loopTM, if_neg loopQ_body_ne_halt, hhalt, ↓reduceIte] + unfold step + simp only [loopBodyWrap, loopTM, ite_eq_right loopQ_body_ne_halt, hhalt, ↓reduceIte] congr 1 -- ════════════════════════════════════════════════════════════════════════ @@ -119,9 +117,8 @@ theorem loopTM_test_step (tmBody tmTest : TM n) {c c' : Cfg n tmTest.Q} have hne : c.state ≠ tmTest.qhalt := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (loopTestWrap tmBody tmTest c).state = - (loopTM tmBody tmTest).qhalt then none else some _) = some _ - simp only [loopTestWrap, loopTM, if_neg loopQ_test_ne_halt, if_neg hne] + unfold step + simp only [loopTestWrap, loopTM, ite_eq_right loopQ_test_ne_halt, ite_eq_right hne] /-- A `t`-step run of `tmTest` lifts to a `t`-step run of `loopTM` between the test-wrapped configurations. -/ @@ -147,9 +144,8 @@ theorem loopTM_test_to_rewind (tmBody tmTest : TM n) {c : Cfg n tmTest.Q} input := transitionInput c.input, work := fun i => transitionTape (c.work i), output := transitionTape c.output } := by - show (if (loopTestWrap tmBody tmTest c).state = - (loopTM tmBody tmTest).qhalt then none else some _) = some _ - simp only [loopTestWrap, loopTM, if_neg loopQ_test_ne_halt, hhalt, ↓reduceIte] + unfold step + simp only [loopTestWrap, loopTM, ite_eq_right loopQ_test_ne_halt, hhalt, ↓reduceIte] congr 1 -- ════════════════════════════════════════════════════════════════════════ diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/Retarget.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/Retarget.lean index aedb9175..bdce282a 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/Retarget.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/Retarget.lean @@ -162,9 +162,9 @@ theorem retargetInput_step_commute (M : TM k) {c c' : Cfg k M.Q} = (fun i => (c.work i).read) := by funext i show (if h : i.val < k then c.work ⟨i.val, h⟩ else c.input).read = (c.work i).read - rw [dif_pos i.isLt] + rw [dite_eq_left i.isLt] -- Unfold step on the LHS. `split` reduces the halting ite (the stored - -- decidability instance blocks `simp`/`if_neg` post-v4.30). + -- decidability instance blocks `simp`/`ite_eq_right` post-v4.30). simp only [step, show (retargetWrap M realInput c).state = c.state from rfl, show (retargetInput M).qhalt = M.qhalt from rfl, retargetWrap_input, retargetWrap_output] @@ -184,12 +184,12 @@ theorem retargetInput_step_commute (M : TM k) {c c' : Cfg k M.Q} -- RHS: (retargetWrap... c').work i where c'.work ⟨i.val, _⟩ is the updated tape. rw [retargetWrap_work_lt _ _ _ _ hik] show (_ : Tape).writeAndMove _ _ = (if h : i.val < k then _ else _) - rw [dif_pos hik, dif_pos hik, dif_pos hik] + rw [dite_eq_left hik, dite_eq_left hik, dite_eq_left hik] · -- i.val = k: virtual input case. have hik_eq : i.val = k := by have := i.isLt; omega have hwork_k : (retargetWrap M realInput c).work i = c.input := by show (if h : i.val < k then c.work ⟨i.val, h⟩ else c.input) = c.input - rw [dif_neg hik] + rw [dite_eq_right hik] have hcond : c.input.head = 0 ∨ c.input.read ≠ Γ.start := by by_cases hh : c.input.head = 0 · left; exact hh @@ -199,7 +199,7 @@ theorem retargetInput_step_commute (M : TM k) {c c' : Cfg k M.Q} -- Rewrite LHS via hwork_k, then use tape_writeBack_eq_move. rw [hwork_k] show _ = (if h : i.val < k then _ else _) - rw [dif_neg hik, dif_neg hik, dif_neg hik] + rw [dite_eq_right hik, dite_eq_right hik, dite_eq_right hik] exact tape_writeBack_eq_move c.input _ hcond -- ════════════════════════════════════════════════════════════════════════ @@ -502,7 +502,7 @@ theorem retargetInput_hoareTime (M : TM k) ({ state := (retargetInput M).qstart, input := realInput, work := work, output := out } : Cfg (k + 1) (retargetInput M).Q) := by refine Cfg.mk.injEq _ _ _ _ _ _ _ _ |>.mpr ⟨rfl, rfl, ?_, rfl⟩ - simpa [retargetInput] using hworkField + exact hworkField refine ⟨retargetWrap M finalReal c', t, ht, ?_, ?_, ?_⟩ · rw [← hstart] exact hreachSim diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/RetargetWindow.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/RetargetWindow.lean index 73863821..16a88278 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/RetargetWindow.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/RetargetWindow.lean @@ -97,7 +97,7 @@ theorem retargetInput_keepsWindow_of_reaches (M : TM k) (r₀ : Tape) (c₀ : Cf state_ne_qhalt_of_step hstep' have hne : cM.state ≠ M.qhalt := hne0 obtain ⟨cM', hstep0⟩ : ∃ cM', M.step cM = some cM' := by - rw [TM.step, if_neg hne] + rw [TM.step, ite_eq_right hne] exact ⟨_, rfl⟩ have hcomm := retargetInput_step_commute M hstep0 r hinp have hd'eq := Option.some_inj.mp (hstep'.symm.trans hcomm) diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/Scanner.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/Scanner.lean index d863428a..d5c1eed1 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/Scanner.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/Scanner.lean @@ -69,7 +69,7 @@ private theorem scannerTM_step_scan c'.state = ScannerPhase.scan (scanStep s (decide (c.input.read = Γ.one))) ∧ c'.input.head = c.input.head + 1 ∧ c'.input.cells = c.input.cells ∧ c'.output.head = 1 ∧ c'.output.cells = c.output.cells := by - simp only [TM.step, hst, scannerTM, reduceCtorEq, ↓reduceIte, if_neg hi_nb] + simp only [TM.step, hst, scannerTM, reduceCtorEq, ↓reduceIte, ite_eq_right hi_nb] have hne : c.output.read ≠ Γ.start := by simp only [Tape.read, ho_head]; exact ho_cell1_nb have ho_move : idleDir c.output.read = Dir3.stay := by @@ -91,7 +91,7 @@ private theorem scannerTM_step_halt ∃ c', (scannerTM s₀ scanStep finalOutput).step c = some c' ∧ (scannerTM s₀ scanStep finalOutput).halted c' ∧ c'.output.cells 1 = (finalOutput s).toΓ := by - simp only [TM.step, hst, scannerTM, reduceCtorEq, ↓reduceIte, if_pos hi_blank] + simp only [TM.step, hst, scannerTM, reduceCtorEq, ↓reduceIte, ite_eq_left hi_blank] refine ⟨_, rfl, rfl, ?_⟩ have hne : c.output.read ≠ Γ.start := by simp only [Tape.read, ho_head]; exact ho_cell1_nb @@ -221,14 +221,14 @@ theorem scannerTM_decidesInTime scannerTM_reachesIn s₀ scanStep (fun s => if accept s then .one else .zero) x refine ⟨c', x.length + 2, le_refl _, hreach, hhalt, ?_, ?_⟩ · intro hxL - rw [hout, if_pos ((hL x).mp hxL)]; rfl + rw [hout, ite_eq_left ((hL x).mp hxL)]; rfl · intro hxnL rw [hout] have hacc : accept (x.foldl scanStep s₀) = false := by rcases h : accept (x.foldl scanStep s₀) with _ | _ · rfl · exact absurd ((hL x).mpr h) hxnL - rw [if_neg (by simp [hacc])]; rfl + rw [ite_eq_right (by simp [hacc])]; rfl end TM diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/SentinelStep.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/SentinelStep.lean index 2457a7ef..32105c96 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/SentinelStep.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/SentinelStep.lean @@ -64,7 +64,7 @@ theorem step_of_heads_zero (M : TM k) (c : Cfg k M.Q) intro i; rw [Tape.read, hwork i]; exact hwork0 i have hro : c.output.read = Γ.start := by rw [Tape.read, hout]; exact hout0 have hdirs := M.δ_right_of_start M.qstart Γ.start (fun _ => Γ.start) Γ.start - simp only [TM.step, hstate, if_neg hne, hri, hro, funext hrw] + simp only [TM.step, hstate, ite_eq_right hne, hri, hro, funext hrw] refine congrArg some (Cfg.ext rfl ?_ ?_ ?_) · show (c.input.move _) = _ rw [hdirs.1 rfl] @@ -124,7 +124,7 @@ theorem reachesIn_succ_of_startedTM (M : TM k) (c : Cfg k M.Q) M.reachesIn (t + 1) c c' := by have hq : (startedTM M).qstart = retargetInputStartState M := by show (if M.qstart = M.qhalt then M.qhalt else retargetInputStartState M) = _ - rw [if_neg hne] + rw [ite_eq_right hne] have hstep : M.step c = some ⟨(startedTM M).qstart, c.input.move Dir3.right, fun i => (c.work i).move Dir3.right, c.output.move Dir3.right⟩ := by rw [hq] diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/Seq.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/Seq.lean index 588c31b7..acd77e48 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/Seq.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/Seq.lean @@ -61,9 +61,8 @@ theorem seqTM_phase1_step (tm₁ tm₂ : TM n) {c₁ c₁' : Cfg n tm₁.Q} have hne := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (phase1Wrap tm₁ tm₂ c₁).state = (seqTM tm₁ tm₂).qhalt then none - else some _) = some _ - simp only [phase1Wrap, seqTM, if_neg Sum.inl_ne_inr, if_neg hne] + unfold step + simp only [phase1Wrap, seqTM, ite_eq_right Sum.inl_ne_inr, ite_eq_right hne] /-- Multi-step Phase 1 simulation. -/ theorem seqTM_reachesIn_phase1Wrap (tm₁ tm₂ : TM n) {t : ℕ} @@ -87,9 +86,8 @@ theorem seqTM_transition_step (tm₁ tm₂ : TM n) {c₁ : Cfg n tm₁.Q} input := transitionInput c₁.input, work := fun i => transitionTape (c₁.work i), output := transitionTape c₁.output }) := by - show (if (phase1Wrap tm₁ tm₂ c₁).state = (seqTM tm₁ tm₂).qhalt then none - else some _) = some _ - simp only [phase1Wrap, seqTM, if_neg Sum.inl_ne_inr, hhalt, ↓reduceIte] + unfold step + simp only [phase1Wrap, seqTM, ite_eq_right Sum.inl_ne_inr, hhalt, ↓reduceIte] congr 1 -- ════════════════════════════════════════════════════════════════════════ @@ -103,9 +101,8 @@ theorem seqTM_phase2_step (tm₁ tm₂ : TM n) {c₂ c₂' : Cfg n tm₂.Q} have hne := state_ne_qhalt_of_step hstep simp only [step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - show (if (phase2Wrap tm₁ tm₂ c₂).state = (seqTM tm₁ tm₂).qhalt then none - else some _) = some _ - simp only [phase2Wrap, seqTM, if_neg (Sum.inr_injective.ne hne), if_neg hne] + unfold step + simp only [phase2Wrap, seqTM, ite_eq_right (Sum.inr_injective.ne hne), ite_eq_right hne] /-- Multi-step Phase 2 simulation. -/ theorem seqTM_reachesIn_phase2Wrap (tm₁ tm₂ : TM n) {t : ℕ} diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/Union.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/Union.lean index d25f28d1..873ad18b 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/Union.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/Union.lean @@ -64,7 +64,7 @@ private theorem idleTape_write_blank : unionIdleTape.write Γ.blank = unionIdleT private theorem idleTape_step_idle : (unionIdleTape.write Γw.blank.toΓ).move (idleDir unionIdleTape.read) = unionIdleTape := by show (unionIdleTape.write Γ.blank).move (idleDir unionIdleTape.read) = unionIdleTape - rw [idleTape_read, idleDir, if_neg (by decide)] + rw [idleTape_read, idleDir, ite_eq_right (by decide)] simp [idleTape_write_blank, Tape.move] -- ════════════════════════════════════════════════════════════════════════ @@ -99,7 +99,7 @@ private theorem unionTM_delta_inl (tm₁ : TM n₁) (tm₂ : TM n₂) {q : tm₁ fun i => if h : i.val < n₁ then r.2.2.2.2.1 ⟨i.val, h⟩ else if i.val = n₁ then r.2.2.2.2.2 else idleDir (wHeads i), idleDir oHead) := by - simp only [unionTM, if_neg hne] + simp only [unionTM, ite_eq_right hne] private theorem unionTM_qhalt (tm₁ : TM n₁) (tm₂ : TM n₂) : (unionTM tm₁ tm₂).qhalt = Sum.inr (Sum.inr tm₂.qhalt) := rfl @@ -115,7 +115,7 @@ private theorem unionTM_delta_inr_inr (tm₁ : TM n₁) (tm₂ : TM n₂) {q : t fun i => if h : i.val ≤ n₁ then idleDir (wHeads i) else r.2.2.2.2.1 ⟨i.val - (n₁ + 1), by omega⟩, r.2.2.2.2.2) := by - simp only [unionTM, if_neg hne] + simp only [unionTM, ite_eq_right hne] private theorem phase1Cfg_state (tm₁ : TM n₁) (tm₂ : TM n₂) (c : Cfg n₁ tm₁.Q) : (unionPhase1Cfg tm₁ tm₂ c).state = Sum.inl c.state := rfl @@ -138,12 +138,12 @@ private theorem phase1_step_corr (tm₁ : TM n₁) (tm₂ : TM n₂) -- Establish that the δ calls produce the same result have hfake_read : (if h : (n₁ : ℕ) < n₁ then c.work ⟨n₁, h⟩ else if (n₁ : ℕ) = n₁ then c.output else unionIdleTape).read = c.output.read := by - rw [dif_neg (Nat.lt_irrefl n₁), if_pos rfl] + rw [dite_eq_right (Nat.lt_irrefl n₁), ite_eq_left rfl] have hwork_reads : (phase1WorkReads fun i : Fin (n₁ + 1 + n₂) => (if h : i.val < n₁ then c.work ⟨i.val, h⟩ else if i.val = n₁ then c.output else unionIdleTape).read) = fun j => (c.work j).read := by - ext ⟨j, hj⟩; simp only [phase1WorkReads]; rw [dif_pos (show j < n₁ from hj)] + ext ⟨j, hj⟩; simp only [phase1WorkReads]; rw [dite_eq_left (show j < n₁ from hj)] -- Simplify fakeOutIdx to ⟨n₁, _⟩ and reduce the dite conditions simp only [fakeOutIdx] at hfake_read ⊢ -- Rewrite the work reads and fake output read @@ -187,7 +187,7 @@ private theorem phase1_init_step (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List B (unionTM tm₁ tm₂).step ((unionTM tm₁ tm₂).initCfg x) = some (unionPhase1Cfg tm₁ tm₂ c_mid) := by have hne := state_ne_qhalt_of_step hstep simp only [step] at hstep ⊢ - rw [if_neg hne] at hstep + rw [ite_eq_right hne] at hstep simp only [Option.some.injEq] at hstep subst hstep -- Unfold unionTM qstart/qhalt @@ -241,7 +241,7 @@ theorem unionTM_phase1_simulation (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List private theorem idleDir_stay_of_ge_one (t : Tape) (hhead : t.head ≥ 1) (hno : ∀ i, i ≥ 1 → t.cells i ≠ Γ.start) : idleDir t.read = Dir3.stay := by - rw [idleDir, if_neg]; rw [Tape.read]; exact hno _ hhead + rw [idleDir, ite_eq_right]; rw [Tape.read]; exact hno _ hhead /-- Input head stays constant when moved by idleDir if head ≥ 1 and cells[≥1] ≠ start. -/ private theorem idle_move_preserves_head (t : Tape) @@ -263,7 +263,7 @@ private theorem unionTM_delta_rewindOut_nostart (tm₁ : TM n₁) (tm₂ : TM n .blank, idleDir iHead, fun i => if i.val = n₁ then Dir3.left else idleDir (wHeads i), idleDir oHead ) := by - unfold unionTM; simp only [if_neg hread] + unfold unionTM; simp only [ite_eq_right hread] /-- Delta computation for rewindOut when fake output is at start. -/ private theorem unionTM_delta_rewindOut_start (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -274,7 +274,7 @@ private theorem unionTM_delta_rewindOut_start (tm₁ : TM n₁) (tm₂ : TM n₂ fun _ => .blank, .blank, idleDir iHead, fun i => if i.val = n₁ then Dir3.right else idleDir (wHeads i), idleDir oHead ) := by - unfold unionTM; simp only [if_pos hread] + unfold unionTM; simp only [ite_eq_left hread] /-- Delta computation for checkResult when fake output reads Γ.one. -/ private theorem unionTM_delta_checkResult_one (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -285,7 +285,7 @@ private theorem unionTM_delta_checkResult_one (tm₁ : TM n₁) (tm₂ : TM n₂ fun _ => .blank, .one, idleDir iHead, fun i => idleDir (wHeads i), idleDir oHead ) := by - unfold unionTM; simp only [if_pos hread] + unfold unionTM; simp only [ite_eq_left hread] /-- Delta computation for checkResult when fake output does not read Γ.one. -/ private theorem unionTM_delta_checkResult_notone (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -293,7 +293,7 @@ private theorem unionTM_delta_checkResult_notone (tm₁ : TM n₁) (tm₂ : TM n (hread : wHeads fakeOutIdx ≠ Γ.one) : (unionTM tm₁ tm₂).δ (Sum.inr (Sum.inl UnionPhase.checkResult)) iHead wHeads oHead = allIdle (Sum.inr (Sum.inl UnionPhase.rewindIn)) iHead wHeads oHead := by - unfold unionTM; simp only [if_neg hread] + unfold unionTM; simp only [ite_eq_right hread] /-- Delta computation for rewindIn when input is not at start. -/ private theorem unionTM_delta_rewindIn_nostart (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -304,7 +304,7 @@ private theorem unionTM_delta_rewindIn_nostart (tm₁ : TM n₁) (tm₂ : TM n fun _ => .blank, .blank, Dir3.left, fun i => idleDir (wHeads i), idleDir oHead ) := by - simp only [unionTM, if_neg hread] + simp only [unionTM, ite_eq_right hread] /-- Delta computation for rewindIn when input is at start. -/ private theorem unionTM_delta_rewindIn_start (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -315,7 +315,7 @@ private theorem unionTM_delta_rewindIn_start (tm₁ : TM n₁) (tm₂ : TM n₂) fun _ => .blank, .blank, Dir3.right, fun i => idleDir (wHeads i), idleDir oHead ) := by - simp only [unionTM, if_pos hread] + simp only [unionTM, ite_eq_left hread] /-- Delta computation for setup2. -/ private theorem unionTM_delta_setup2 (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -369,7 +369,7 @@ private theorem step_rewindOut_nostart_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) ((if i.val = n₁ then readBackWrite (c.work fakeOutIdx).read else .blank) : Γw).toΓ).move (if i.val = n₁ then Dir3.left else idleDir (c.work i).read), output := (c.output.write Γw.blank.toΓ).move (idleDir c.output.read) } := by - simp only [step]; rw [hstate]; simp only [unionTM, if_neg hread]; rfl + simp only [step]; rw [hstate]; simp only [unionTM, ite_eq_right hread]; rfl /-- Step the union machine from a rewindOut state when fake output reads start. -/ private theorem step_rewindOut_start_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -382,7 +382,7 @@ private theorem step_rewindOut_start_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) work := fun i => ((c.work i).write (Γw.blank : Γw).toΓ).move (if i.val = n₁ then Dir3.right else idleDir (c.work i).read), output := (c.output.write Γw.blank.toΓ).move (idleDir c.output.read) } := by - simp only [step]; rw [hstate]; simp only [unionTM, if_pos hread]; rfl + simp only [step]; rw [hstate]; simp only [unionTM, ite_eq_left hread]; rfl /-- Step the union machine from checkResult with Γ.one → halted. -/ private theorem step_checkResult_one_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -394,7 +394,7 @@ private theorem step_checkResult_one_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) input := c.input.move (idleDir c.input.read), work := fun i => ((c.work i).write (Γw.blank : Γw).toΓ).move (idleDir (c.work i).read), output := (c.output.write Γw.one.toΓ).move (idleDir c.output.read) } := by - simp only [step]; rw [hstate]; simp only [unionTM, if_pos hread]; rfl + simp only [step]; rw [hstate]; simp only [unionTM, ite_eq_left hread]; rfl /-- Step the union machine from checkResult when not Γ.one → rewindIn (allIdle). -/ private theorem step_checkResult_notone_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -406,7 +406,7 @@ private theorem step_checkResult_notone_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) input := c.input.move (idleDir c.input.read), work := fun i => ((c.work i).write (Γw.blank : Γw).toΓ).move (idleDir (c.work i).read), output := (c.output.write Γw.blank.toΓ).move (idleDir c.output.read) } := by - simp only [step]; rw [hstate]; simp only [unionTM, if_neg hread, allIdle]; rfl + simp only [step]; rw [hstate]; simp only [unionTM, ite_eq_right hread, allIdle]; rfl /-- Step the union machine from rewindIn with non-start input. -/ private theorem step_rewindIn_nostart_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -418,7 +418,7 @@ private theorem step_rewindIn_nostart_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) input := c.input.move Dir3.left, work := fun i => ((c.work i).write (Γw.blank : Γw).toΓ).move (idleDir (c.work i).read), output := (c.output.write Γw.blank.toΓ).move (idleDir c.output.read) } := by - simp only [step]; rw [hstate]; simp only [unionTM, if_neg hread]; rfl + simp only [step]; rw [hstate]; simp only [unionTM, ite_eq_right hread]; rfl /-- Step the union machine from rewindIn when input reads start. -/ private theorem step_rewindIn_start_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -430,7 +430,7 @@ private theorem step_rewindIn_start_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) input := c.input.move Dir3.right, work := fun i => ((c.work i).write (Γw.blank : Γw).toΓ).move (idleDir (c.work i).read), output := (c.output.write Γw.blank.toΓ).move (idleDir c.output.read) } := by - simp only [step]; rw [hstate]; simp only [unionTM, if_pos hread]; rfl + simp only [step]; rw [hstate]; simp only [unionTM, ite_eq_left hread]; rfl /-- Step the union machine from setup2. -/ private theorem step_setup2_cfg (tm₁ : TM n₁) (tm₂ : TM n₂) @@ -650,7 +650,7 @@ theorem unionTM_transition_accept (tm₁ : TM n₁) (tm₂ : TM n₂) -- c_cr fake output cells preserved (write blank at head 0 is no-op) have hcr_fo_cells : (c_cr.work fakeOutIdx).cells = (c_at0.work fakeOutIdx).cells := by simp only [hc_cr_def, show (fakeOutIdx : Fin (n₁ + 1 + n₂)).val = n₁ from rfl, ite_true] - rw [Tape.move_cells]; simp only [Tape.write, if_pos hhead_at0] + rw [Tape.move_cells]; simp only [Tape.write, ite_eq_left hhead_at0] -- c_cr fake output reads cell 1 = Γ.one have hcr_read : (c_cr.work fakeOutIdx).read = Γ.one := by rw [Tape.read, hcr_fo_head, hcr_fo_cells, hcells_at0, hcells_rw]; exact haccept @@ -782,10 +782,10 @@ private theorem phase2_work_step_idle (tm₁ : TM n₁) (tm₂ : TM n₂) congr 1 · congr 1 show (if h : (i : ℕ) < n₁ then _ else if (i : ℕ) = n₁ then _ else Γw.blank) = Γw.blank - rw [dif_neg (show ¬((i : ℕ) < n₁) from by omega), if_neg hine] + rw [dite_eq_right (show ¬((i : ℕ) < n₁) from by omega), ite_eq_right hine] · show (if h : (i : ℕ) < n₁ then _ else if (i : ℕ) = n₁ then _ else idleDir (c.work i).read) = _ - rw [dif_neg (show ¬((i : ℕ) < n₁) from by omega), if_neg hine] + rw [dite_eq_right (show ¬((i : ℕ) < n₁) from by omega), ite_eq_right hine] · rw [hq]; dsimp only [unionTM]; split · congr 1; simp only [hine, ↓reduceIte] · congr 1 @@ -893,7 +893,7 @@ theorem unionTM_transition_reject (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List simp only [Tape.write, hhead_at0, ↓reduceIte, Tape.move] have hcr_fo_cells : (c_cr.work fakeOutIdx).cells = (c_at0.work fakeOutIdx).cells := by simp only [hc_cr_def, show (fakeOutIdx : Fin (n₁ + 1 + n₂)).val = n₁ from rfl, ite_true] - rw [Tape.move_cells]; simp only [Tape.write, if_pos hhead_at0] + rw [Tape.move_cells]; simp only [Tape.write, ite_eq_left hhead_at0] have hcr_read_ne_one : (c_cr.work fakeOutIdx).read ≠ Γ.one := by rw [Tape.read, hcr_fo_head, hcr_fo_cells, hcells_at0, hcells_rw, hreject]; decide -- Step 4: checkResult ≠ Γ.one → rewindIn (1 step) @@ -1011,7 +1011,7 @@ theorem unionTM_transition_reject (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List -- c_mid.input.head = 0 (moveLeftDir of non-start = left, from head 1 → 0) have h1 : c_mid.input.head = 0 := by show (c_s2.input.move (moveLeftDir c_s2.input.read)).head = 0 - rw [moveLeftDir, if_neg hs2_read_ne]; simp [Tape.move, hs2_head] + rw [moveLeftDir, ite_eq_right hs2_read_ne]; simp [Tape.move, hs2_head] -- Combine have hcfg : ∀ (a b : Tape), a.head = b.head → a.cells = b.cells → a = b := by intros a b hh hc; cases a; cases b; simp only [Tape.mk.injEq] at *; exact ⟨hh, hc⟩ @@ -1056,7 +1056,7 @@ theorem unionTM_transition_reject (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List intro j show ((c_at0.work ⟨n₁ + 1 + j.val, by omega⟩).write _).move (if (n₁ + 1 + j.val) = n₁ then _ else _) = _ - rw [if_neg (show n₁ + 1 + j.val ≠ n₁ from by omega), hwork_at0_idle j] + rw [ite_eq_right (show n₁ + 1 + j.val ≠ n₁ from by omega), hwork_at0_idle j] exact idleTape_step_idle -- Step 4 (checkResult→rewindIn): c_ri.work at > n₁ = unionIdleTape have hwork_ri_idle : ∀ (j : Fin n₂), @@ -1085,7 +1085,7 @@ theorem unionTM_transition_reject (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List intro j show ((c_s2.work ⟨n₁ + 1 + j.val, by omega⟩).write _).move (if (n₁ + 1 + j.val) ≤ n₁ then _ else _) = _ - rw [if_neg (show ¬(n₁ + 1 + j.val ≤ n₁) from by omega), hwork_s2_idle j] + rw [ite_eq_right (show ¬(n₁ + 1 + j.val ≤ n₁) from by omega), hwork_s2_idle j] exact idleTape_moveLeft -- Compose all reachesIn steps have hreach_total : (unionTM tm₁ tm₂).reachesIn @@ -1135,7 +1135,7 @@ theorem unionTM_transition_reject (tm₁ : TM n₁) (tm₂ : TM n₂) (x : List by_cases hh : c₁.input.head = 0 · have hread0 : c₁.input.read = Γ.start := by rw [Tape.read, hh, hinput_cells]; simp [Tape.init] - rw [hread0, idleDir, if_pos rfl]; simp [Tape.move, hh] + rw [hread0, idleDir, ite_eq_left rfl]; simp [Tape.move, hh] · have hge : c₁.input.head ≥ 1 := by omega have hc1_ino : ∀ i, i ≥ 1 → c₁.input.cells i ≠ Γ.start := by intro i hi; rw [← hcrw_cells]; exact hcrw_ino i hi @@ -1193,7 +1193,7 @@ private theorem phase2_step_corr (tm₁ : TM n₁) (tm₂ : TM n₂) have hne_u : c_u.state ≠ (unionTM tm₁ tm₂).qhalt := by rw [hcompat.state_eq, unionTM_qhalt]; exact fun h => hne (Sum.inr.inj (Sum.inr.inj h)) -- Unfold the union step; `split` reduces the halting ite (the stored - -- decidability instance blocks `simp`/`rw [if_neg]` here), then pin the + -- decidability instance blocks `simp`/`rw [ite_eq_right]` here), then pin the -- explicit step-result config as the existential witness via `rfl`. simp only [step] split @@ -1208,11 +1208,11 @@ private theorem phase2_step_corr (tm₁ : TM n₁) (tm₂ : TM n₂) refine ⟨?_, ?_, fun ⟨j, hj⟩ => ?_, ?_⟩ <;> dsimp only [] <;> rw [hcompat.state_eq] <;> simp only [unionTM_delta_inr_inr tm₁ tm₂ hne, hcompat.input_eq, hcompat.output_eq, hwork_reads] have hgt : ¬((n₁ + 1 + j) ≤ n₁) := by omega - rw [dif_neg hgt] + rw [dite_eq_right hgt] have hfin : ∀ (p : n₁ + 1 + j - (n₁ + 1) < n₂), (⟨n₁ + 1 + j - (n₁ + 1), p⟩ : Fin n₂) = ⟨j, hj⟩ := by intro p; apply Fin.ext; show n₁ + 1 + j - (n₁ + 1) = j; omega - simp only [hfin, hcompat.work_eq ⟨j, hj⟩, dif_neg hgt] + simp only [hfin, hcompat.work_eq ⟨j, hj⟩, dite_eq_right hgt] -- ════════════════════════════════════════════════════════════════════════ -- Phase 2 simulation diff --git a/Complexitylib/Models/TuringMachine/Combinators/Internal/Window.lean b/Complexitylib/Models/TuringMachine/Combinators/Internal/Window.lean index 1e354523..edec196f 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/Internal/Window.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/Internal/Window.lean @@ -129,7 +129,7 @@ theorem seqTM_respectsWindow (tm₁ tm₂ : TM n) {inputLength space : ℕ} (hs Cfg.ext hstate rfl rfl rfl obtain ⟨c₀', hstep0⟩ : ∃ c₀', tm₁.step ⟨q, c.input, c.work, c.output⟩ = some c₀' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsimstep := seqTM_phase1_step tm₁ tm₂ hstep0 rw [hc] at hstep @@ -144,7 +144,7 @@ theorem seqTM_respectsWindow (tm₁ tm₂ : TM n) {inputLength space : ℕ} (hs Cfg.ext hstate rfl rfl rfl obtain ⟨c₀', hstep0⟩ : ∃ c₀', tm₂.step ⟨q, c.input, c.work, c.output⟩ = some c₀' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsimstep := seqTM_phase2_step tm₁ tm₂ hstep0 rw [hc] at hstep @@ -179,7 +179,7 @@ theorem loopTM_respectsWindow (tmBody tmTest : TM n) {inputLength space : ℕ} ( Cfg.ext hstate rfl rfl rfl obtain ⟨c₀', hstep0⟩ : ∃ c₀', tmTest.step ⟨q, c.input, c.work, c.output⟩ = some c₀' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsimstep := loopTM_test_step tmBody tmTest hstep0 rw [hc] at hstep @@ -193,7 +193,7 @@ theorem loopTM_respectsWindow (tmBody tmTest : TM n) {inputLength space : ℕ} ( Cfg.ext hstate rfl rfl rfl obtain ⟨c₀', hstep0⟩ : ∃ c₀', tmBody.step ⟨q, c.input, c.work, c.output⟩ = some c₀' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsimstep := loopTM_body_step tmBody tmTest hstep0 rw [hc] at hstep @@ -219,7 +219,7 @@ theorem reachesIn_halted_unique {tm : TM n} : cases hb with | zero => rfl | step hstep _ => - rw [TM.step, if_pos hha] at hstep + rw [TM.step, ite_eq_left hha] at hstep exact absurd hstep (by nofun) | succ s ih => intro t c a b ha hb hha hhb @@ -227,7 +227,7 @@ theorem reachesIn_halted_unique {tm : TM n} : | step hstepa hresta => cases hb with | zero => - rw [TM.step, if_pos hhb] at hstepa + rw [TM.step, ite_eq_left hhb] at hstepa exact absurd hstepa (by nofun) | step hstepb hrestb => rw [Option.some_inj.mp (hstepa.symm.trans hstepb)] at hresta @@ -317,7 +317,7 @@ theorem seqTM_keepsWindow (tm₁ tm₂ : TM n) {inputLength space : ℕ} (hs : 1 Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tm₁.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq]; exact ⟨_, rfl⟩ have hsim := seqTM_phase1_step tm₁ tm₂ hstep0 rw [hc] at hst have hc'eq : c' = phase1Wrap tm₁ tm₂ e' := Option.some_inj.mp (hst.symm.trans hsim) @@ -336,7 +336,7 @@ theorem seqTM_keepsWindow (tm₁ tm₂ : TM n) {inputLength space : ℕ} (hs : 1 Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tm₂.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq]; exact ⟨_, rfl⟩ have hsim := seqTM_phase2_step tm₁ tm₂ hstep0 rw [hc] at hst have hc'eq : c' = phase2Wrap tm₁ tm₂ e' := Option.some_inj.mp (hst.symm.trans hsim) @@ -410,7 +410,7 @@ theorem loopTM_keepsWindow (tmBody tmTest : TM n) {inputLength space : ℕ} (hs Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmTest.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq]; exact ⟨_, rfl⟩ have hsim := loopTM_test_step tmBody tmTest hstep0 rw [hc] at hst have hc'eq : c' = loopTestWrap tmBody tmTest e' := @@ -432,7 +432,7 @@ theorem loopTM_keepsWindow (tmBody tmTest : TM n) {inputLength space : ℕ} (hs Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmBody.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq]; exact ⟨_, rfl⟩ have hsim := loopTM_body_step tmBody tmTest hstep0 rw [hc] at hst have hc'eq : c' = loopBodyWrap tmBody tmTest e' := @@ -540,7 +540,7 @@ theorem ifTM_keepsWindow (tmTest tmThen tmElse : TM n) {inputLength space : ℕ} Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmElse.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsim := ifTM_else_step tmTest tmThen tmElse hstep0 rw [hc] at hst @@ -567,7 +567,7 @@ theorem ifTM_keepsWindow (tmTest tmThen tmElse : TM n) {inputLength space : ℕ} Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmThen.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsim := ifTM_then_step tmTest tmThen tmElse hstep0 rw [hc] at hst @@ -594,7 +594,7 @@ theorem ifTM_keepsWindow (tmTest tmThen tmElse : TM n) {inputLength space : ℕ} Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmTest.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsim := ifTM_test_step tmTest tmThen tmElse hstep0 rw [hc] at hst @@ -720,7 +720,7 @@ theorem seqTM_keepsWindowOn (tm₁ tm₂ : TM n) {inputLength space : ℕ} (hs : Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tm₁.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsim := seqTM_phase1_step tm₁ tm₂ hstep0 rw [hc] at hst @@ -741,7 +741,7 @@ theorem seqTM_keepsWindowOn (tm₁ tm₂ : TM n) {inputLength space : ℕ} (hs : Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tm₂.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq] + rw [TM.step, ite_eq_right hq] exact ⟨_, rfl⟩ have hsim := seqTM_phase2_step tm₁ tm₂ hstep0 rw [hc] at hst @@ -1155,7 +1155,7 @@ theorem loopTM_keepsWindowOn_phases (tmBody tmTest : TM n) {inputLength space : Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmBody.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq]; exact ⟨_, rfl⟩ have hsim := loopTM_body_step tmBody tmTest hstep0 rw [hc] at hst have hc'eq : c' = loopBodyWrap tmBody tmTest e' := @@ -1203,7 +1203,7 @@ theorem loopTM_keepsWindowOn_phases (tmBody tmTest : TM n) {inputLength space : Cfg.ext hstate rfl rfl rfl obtain ⟨e', hstep0⟩ : ∃ e', tmTest.step ⟨q, c.input, c.work, c.output⟩ = some e' := by - rw [TM.step, if_neg hq]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hq]; exact ⟨_, rfl⟩ have hsim := loopTM_test_step tmBody tmTest hstep0 rw [hc] at hst have hc'eq : c' = loopTestWrap tmBody tmTest e' := @@ -1255,7 +1255,7 @@ theorem loop_phase_step_tapes (tmBody tmTest : TM n) {c c' : Cfg n (loopTM tmBod rw [hstate] intro hcon exact hph (by injection hcon with h; injection h) - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep rw [← Option.some_inj.mp hstep, hstate] have hcells : ∀ (d : Dir3), d ≠ Dir3.right → c.output.read ≠ Γ.start → (c.output.writeAndMove (readBackWrite c.output.read).toΓ d).cells = c.output.cells ∧ @@ -1283,41 +1283,41 @@ theorem loop_phase_step_tapes (tmBody tmTest : TM n) {c c' : Cfg n (loopTM tmBod | rewindOut => simp only [loopTM] by_cases hread : c.output.read = Γ.start - · rw [if_pos hread] + · rw [ite_eq_left hread] refine ⟨rfl, fun i => rfl, ?_, ?_⟩ · show ((c.output.write Γw.blank.toΓ).move Dir3.right).cells = _ - rw [Tape.move_cells, Tape.write, if_pos (hstart hread)] + rw [Tape.move_cells, Tape.write, ite_eq_left (hstart hread)] · show ((c.output.write Γw.blank.toΓ).move Dir3.right).head ≤ _ show (c.output.write Γw.blank.toΓ).head + 1 ≤ _ rw [Tape.write_head, hstart hread] omega - · rw [if_neg hread] + · rw [ite_eq_right hread] exact ⟨rfl, fun i => rfl, (hcells Dir3.left (by nofun) hread).1, (hcells Dir3.left (by nofun) hread).2⟩ | check => simp only [loopTM] by_cases hone : c.output.read = Γ.one - · rw [if_pos hone] + · rw [ite_eq_left hone] have hread : c.output.read ≠ Γ.start := by rw [hone]; nofun have hd : idleDir c.output.read ≠ Dir3.right := by - rw [idleDir, if_neg hread] + rw [idleDir, ite_eq_right hread] nofun exact ⟨rfl, fun i => rfl, (hcells (idleDir c.output.read) hd hread).1, (hcells (idleDir c.output.read) hd hread).2⟩ - · rw [if_neg hone] + · rw [ite_eq_right hone] by_cases hread : c.output.read = Γ.start · refine ⟨rfl, fun i => rfl, ?_, ?_⟩ · show ((c.output.write (readBackWrite c.output.read).toΓ).move (idleDir c.output.read)).cells = _ - rw [Tape.move_cells, Tape.write, if_pos (hstart hread)] + rw [Tape.move_cells, Tape.write, ite_eq_left (hstart hread)] · show ((c.output.write (readBackWrite c.output.read).toΓ).move (idleDir c.output.read)).head ≤ _ - rw [idleDir, if_pos hread] + rw [idleDir, ite_eq_left hread] show (c.output.write (readBackWrite c.output.read).toΓ).head + 1 ≤ _ rw [Tape.write_head, hstart hread] omega · have hd : idleDir c.output.read ≠ Dir3.right := by - rw [idleDir, if_neg hread] + rw [idleDir, ite_eq_right hread] nofun exact ⟨rfl, fun i => rfl, (hcells (idleDir c.output.read) hd hread).1, (hcells (idleDir c.output.read) hd hread).2⟩ @@ -1333,18 +1333,18 @@ theorem loop_rewind_step_state (tmBody tmTest : TM n) {c c' : Cfg n (loopTM tmBo have hne : c.state ≠ (loopTM tmBody tmTest).qhalt := by rw [hstate] nofun - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep rw [← Option.some_inj.mp hstep, hstate] simp only [loopTM] constructor · intro hread - rw [if_pos hread] + rw [ite_eq_left hread] refine ⟨rfl, ?_⟩ show ((c.output.write Γw.blank.toΓ).move Dir3.right).head = _ show (c.output.write Γw.blank.toΓ).head + 1 = _ rw [Tape.write_head] · intro hread - rw [if_neg hread] + rw [ite_eq_right hread] /-- **A check step leaves every tape exactly as it found it**, when the output head is off the marker — which it is, since the rewind has just put it at cell one. -/ @@ -1356,12 +1356,12 @@ theorem loop_check_step_tapes (tmBody tmTest : TM n) {c c' : Cfg n (loopTM tmBod have hne : c.state ≠ (loopTM tmBody tmTest).qhalt := by rw [hstate] nofun - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep rw [← Option.some_inj.mp hstep, hstate] simp only [loopTM] have hout : c.output.writeAndMove (readBackWrite c.output.read).toΓ (idleDir c.output.read) = c.output := by - rw [idleDir, if_neg hread] + rw [idleDir, ite_eq_right hread] show (c.output.write (readBackWrite c.output.read).toΓ).move Dir3.stay = c.output rw [write_readBack c.output hread] rfl diff --git a/Complexitylib/Models/TuringMachine/Combinators/RetargetCompute/Internal.lean b/Complexitylib/Models/TuringMachine/Combinators/RetargetCompute/Internal.lean index 966f0c0d..d04904c9 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/RetargetCompute/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/RetargetCompute/Internal.lean @@ -44,7 +44,7 @@ theorem retargetInputStarted_reachesIn_of_retargetInput_internal (M : TM k) (fun c => c) _ hreach intro c₀ c₁ hstep change (retargetInputStarted M).step c₀ = some c₁ - rw [retargetInputStarted_step_eq_internal] + erw [retargetInputStarted_step_eq_internal] exact hstep /-- In the nondegenerate case, the wrapper start state is exactly the source @@ -210,7 +210,8 @@ theorem retargetInputStarted_hoareTime_internal (M : TM k) retargetInputStartedCfg M y inp := by exact Cfg.ext rfl rfl hpre.1 hpre.2 refine ⟨c', t, ht, ?_, hhalt, hout⟩ - convert hreach using 1 + erw [hstart] + exact hreach /-- Combined placement seam with an exact preserved physical frame. The source work tapes and virtual input occupy the placed middle block; all prefix and diff --git a/Complexitylib/Models/TuringMachine/Combinators/WorkBranch/Internal.lean b/Complexitylib/Models/TuringMachine/Combinators/WorkBranch/Internal.lean index 8cd90256..d26a2403 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/WorkBranch/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/WorkBranch/Internal.lean @@ -76,12 +76,12 @@ theorem branchWorkBlankTM_blank_step_internal (workBranchBlankWrap idx onBlank onNonblank c) = some (workBranchBlankWrap idx onBlank onNonblank c') := by have hne : c.state ≠ onBlank.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by + rw [TM.step, ite_eq_right (by simp [workBranchBlankWrap, workBranchBlankState, branchWorkBlankTM, hne])] simp only [workBranchBlankWrap, workBranchBlankState, hne, ↓reduceIte, branchWorkBlankTM] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : onBlank.δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -98,12 +98,12 @@ theorem branchWorkBlankTM_nonblank_step_internal (workBranchNonblankWrap idx onBlank onNonblank c) = some (workBranchNonblankWrap idx onBlank onNonblank c') := by have hne : c.state ≠ onNonblank.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by + rw [TM.step, ite_eq_right (by simp [workBranchNonblankWrap, workBranchNonblankState, branchWorkBlankTM, hne])] simp only [workBranchNonblankWrap, workBranchNonblankState, hne, ↓reduceIte, branchWorkBlankTM] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : onNonblank.δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -151,7 +151,7 @@ theorem branchWorkBlankTM_dispatch_blank_internal input := inp work := work output := out }) := by - rw [TM.step, if_neg (by simp [branchWorkBlankTM])] + rw [TM.step, ite_eq_right (by simp [branchWorkBlankTM])] simp only [branchWorkBlankTM, hblank, allReadBack, ↓reduceIte, workBranchBlankWrap] refine congrArg some (Cfg.ext rfl ?_ ?_ ?_) @@ -176,7 +176,7 @@ theorem branchWorkBlankTM_dispatch_nonblank_internal input := inp work := work output := out }) := by - rw [TM.step, if_neg (by simp [branchWorkBlankTM])] + rw [TM.step, ite_eq_right (by simp [branchWorkBlankTM])] simp only [branchWorkBlankTM, hnonblank, allReadBack, ↓reduceIte, workBranchNonblankWrap] refine congrArg some (Cfg.ext rfl ?_ ?_ ?_) diff --git a/Complexitylib/Models/TuringMachine/Combinators/WorkSymbolBranch/Internal.lean b/Complexitylib/Models/TuringMachine/Combinators/WorkSymbolBranch/Internal.lean index df1dba7f..d680380e 100644 --- a/Complexitylib/Models/TuringMachine/Combinators/WorkSymbolBranch/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Combinators/WorkSymbolBranch/Internal.lean @@ -72,12 +72,12 @@ private theorem branchWorkSymbolTM_equal_step (workSymbolEqualWrap idx symbol onEqual onDifferent c) = some (workSymbolEqualWrap idx symbol onEqual onDifferent c') := by have hne : c.state ≠ onEqual.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by + rw [TM.step, ite_eq_right (by simp [workSymbolEqualWrap, workBranchBlankState, branchWorkSymbolTM, hne])] simp only [workSymbolEqualWrap, workBranchBlankState, hne, ↓reduceIte, branchWorkSymbolTM] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : onEqual.δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -94,12 +94,12 @@ private theorem branchWorkSymbolTM_different_step (workSymbolDifferentWrap idx symbol onEqual onDifferent c) = some (workSymbolDifferentWrap idx symbol onEqual onDifferent c') := by have hne : c.state ≠ onDifferent.qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by + rw [TM.step, ite_eq_right (by simp [workSymbolDifferentWrap, workBranchNonblankState, branchWorkSymbolTM, hne])] simp only [workSymbolDifferentWrap, workBranchNonblankState, hne, ↓reduceIte, branchWorkSymbolTM] - rw [TM.step, if_neg hne] at hstep + rw [TM.step, ite_eq_right hne] at hstep revert hstep generalize haction : onDifferent.δ c.state c.input.read (fun i => (c.work i).read) c.output.read = action @@ -143,7 +143,7 @@ private theorem branchWorkSymbolTM_dispatch_equal output := out } = some (workSymbolEqualWrap idx symbol onEqual onDifferent { state := onEqual.qstart, input := inp, work := work, output := out }) := by - rw [TM.step, if_neg (by simp [branchWorkSymbolTM])] + rw [TM.step, ite_eq_right (by simp [branchWorkSymbolTM])] simp only [branchWorkSymbolTM, hequal, allReadBack, ↓reduceIte, workSymbolEqualWrap] refine congrArg some (Cfg.ext rfl ?_ ?_ ?_) @@ -166,7 +166,7 @@ private theorem branchWorkSymbolTM_dispatch_different some (workSymbolDifferentWrap idx symbol onEqual onDifferent { state := onDifferent.qstart, input := inp, work := work, output := out }) := by - rw [TM.step, if_neg (by simp [branchWorkSymbolTM])] + rw [TM.step, ite_eq_right (by simp [branchWorkSymbolTM])] simp only [branchWorkSymbolTM, hdifferent, allReadBack, ↓reduceIte, workSymbolDifferentWrap] refine congrArg some (Cfg.ext rfl ?_ ?_ ?_) diff --git a/Complexitylib/Models/TuringMachine/Composition/Internal.lean b/Complexitylib/Models/TuringMachine/Composition/Internal.lean index 83a2271f..c1331b02 100644 --- a/Complexitylib/Models/TuringMachine/Composition/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Composition/Internal.lean @@ -67,8 +67,8 @@ theorem compositionTM_computesInTime_internal omega · have hreach := seqTM_reachesIn_of_reachesIn first tail hreachF hhaltF hreachTail - simpa [compositionTM, first, tail, final, boundaryInput, boundaryWork, - boundaryOutput] using hreach + simp [compositionTM, first, tail, final] + exact hreach · show (compositionTM tmF tmG).halted final simpa [compositionTM, first, tail, final] using (phase2Wrap_halted_iff first tail D).2 hhaltTail @@ -115,8 +115,8 @@ theorem compositionTM_decidesInTime_preimage_internal omega · have hreach := seqTM_reachesIn_of_reachesIn first tail hreachF hhaltF hreachTail - simpa [compositionTM, first, tail, final, boundaryInput, boundaryWork, - boundaryOutput] using hreach + simp [compositionTM, first, tail, final] + exact hreach · show (compositionTM tmF tmG).halted final simpa [compositionTM, first, tail, final] using (phase2Wrap_halted_iff first tail D).2 hhaltTail diff --git a/Complexitylib/Models/TuringMachine/Composition/Internal/FirstPhase.lean b/Complexitylib/Models/TuringMachine/Composition/Internal/FirstPhase.lean index 3d852ad2..4aa333b7 100644 --- a/Complexitylib/Models/TuringMachine/Composition/Internal/FirstPhase.lean +++ b/Complexitylib/Models/TuringMachine/Composition/Internal/FirstPhase.lean @@ -120,7 +120,7 @@ theorem compositionFirstTM_boundary_internal (tmF : TM nf) (ng : ℕ) cases hreachR cases hreachC simpa [compositionFirstTM, compositionRawOutputIdx, Cfg.init] using hrawR - · rw [hC, compositionRawOutputIdx_eq_firstPlacedLast, + · erw [hC, compositionRawOutputIdx_eq_firstPlacedLast, placeWorkParkedCfg, placeWorkCfg_work_middle] exact hrawR have hvirtual : transitionTape (C.work (compositionVirtualInputIdx nf ng)) = @@ -137,7 +137,7 @@ theorem compositionFirstTM_boundary_internal (tmF : TM nf) (ng : ℕ) ((placeWorkCfg tmF.retargetOutput 0 (ng + 1) (fun _ => (Tape.init []).move Dir3.right) cR).work (compositionVirtualInputIdx nf ng)) = _ - rw [placeWorkCfg_work_extra _ _ _ _ _ _ hnot] + erw [placeWorkCfg_work_extra _ _ _ _ _ _ hnot] exact transitionTape_eq_self (t := (Tape.init []).move Dir3.right) (by decide) have hscratch : ∀ j : Fin ng, @@ -156,7 +156,7 @@ theorem compositionFirstTM_boundary_internal (tmF : TM nf) (ng : ℕ) change transitionTape ((placeWorkCfg tmF.retargetOutput 0 (ng + 1) (fun _ => (Tape.init []).move Dir3.right) cR).work idx) = _ - rw [placeWorkCfg_work_extra _ _ _ _ _ _ hnot] + erw [placeWorkCfg_work_extra _ _ _ _ _ _ hnot] exact transitionTape_eq_self (t := (Tape.init []).move Dir3.right) (by decide) have hinvariants := reachesIn_startInvariant hreachFirst diff --git a/Complexitylib/Models/TuringMachine/Composition/Internal/NondetPlaced.lean b/Complexitylib/Models/TuringMachine/Composition/Internal/NondetPlaced.lean index 2bc01612..012b7f32 100644 --- a/Complexitylib/Models/TuringMachine/Composition/Internal/NondetPlaced.lean +++ b/Complexitylib/Models/TuringMachine/Composition/Internal/NondetPlaced.lean @@ -108,7 +108,7 @@ theorem placedCfg_step (tmF : TM nf) (N : NTM ng) (b : Bool) have h1 := TM.retargetInput_step_commute (N.det b) hstep realInput hvin have hidle : realInput.move (TM.idleDir realInput.read) = realInput := by unfold TM.idleDir - rw [if_neg hri] + rw [ite_eq_right hri] rfl rw [hidle] at h1 have h3 := TM.placeWorkTM_step_placeWorkCfg_stable @@ -143,7 +143,7 @@ theorem placedCfg_trace (tmF : TM nf) (N : NTM ng) intro b c c' h hinv have hne := TM.state_ne_qhalt_of_step h simp only [TM.step, det] at h - rw [if_neg (show ¬(c.state = N.qhalt) from hne)] at h + erw [ite_eq_right (show ¬(c.state = N.qhalt) from hne)] at h have h' := Option.some_injective _ h subst h' exact hinv.move _ @@ -201,7 +201,7 @@ theorem compositionNTM_seam_step (tmF : TM nf) (N : NTM ng) (b : Bool) (TM.startedCfg (N.det b) y hne).state := by show (if (N.det b).qstart = (N.det b).qhalt then (N.det b).qhalt else TM.retargetInputStartState (N.det b)) = _ - rw [if_neg hne] + rw [ite_eq_right hne] simp [TM.retargetInputStartState, TM.startedCfg, TM.step, hne, Tape.read, Tape.init] -- Tape transitions at the seam are identities on the stable boundary tapes. @@ -285,9 +285,9 @@ theorem compositionNTM_seam_step (tmF : TM nf) (N : NTM ng) (b : Bool) (TM.startedCfg (N.det b) y hne)).work (TM.placeWorkCoord (0 + (nf + 1)) (ng + 1) (post := 0) i h) else E.work i - rw [dif_pos hmid] + rw [dite_eq_left hmid] by_cases hlt : (TM.placeWorkCoord (0 + (nf + 1)) (ng + 1) (post := 0) i hmid).val < ng - · rw [TM.retargetWrap_work_lt _ _ _ _ hlt, + · erw [TM.retargetWrap_work_lt _ _ _ _ hlt, TM.startedCfg_work_eq_init_move_right] have hidx : TM.compositionSecondWorkIdx nf ng ⟨(TM.placeWorkCoord (0 + (nf + 1)) (ng + 1) (post := 0) i hmid).val, hlt⟩ = i := by @@ -305,7 +305,7 @@ theorem compositionNTM_seam_step (tmF : TM nf) (N : NTM ng) (b : Bool) (TM.startedCfg (N.det b) y hne).input by show (if h : (TM.placeWorkCoord (0 + (nf + 1)) (ng + 1) (post := 0) i hmid).val < ng then _ else _) = _ - rw [dif_neg hlt], + rw [dite_eq_right hlt], TM.startedCfg_input_eq] have hidx : i = TM.compositionVirtualInputIdx nf ng := by apply Fin.ext @@ -322,7 +322,7 @@ theorem compositionNTM_seam_step (tmF : TM nf) (N : NTM ng) (b : Bool) (TM.startedCfg (N.det b) y hne)).work (TM.placeWorkCoord (0 + (nf + 1)) (ng + 1) (post := 0) i h) else E.work i - rw [dif_neg hmid] + rw [dite_eq_right hmid] · -- Output: parked blank on both sides. show TM.transitionTape E.output = (TM.startedCfg (N.det b) y hne).output rw [houtTr, houtE, TM.startedCfg_output_eq_init_move_right] diff --git a/Complexitylib/Models/TuringMachine/Composition/Internal/Tail.lean b/Complexitylib/Models/TuringMachine/Composition/Internal/Tail.lean index 1d0b0ee8..fa65ef99 100644 --- a/Complexitylib/Models/TuringMachine/Composition/Internal/Tail.lean +++ b/Complexitylib/Models/TuringMachine/Composition/Internal/Tail.lean @@ -518,7 +518,7 @@ private theorem compositionTailTM_hoareTime_of_virtualRun_internal hreachFinal, ?_, ?_⟩ · omega · change (seqTM tm₁ tm₂₃₄).halted cFinal - rw [phase2Wrap_halted_iff, phase2Wrap_halted_iff, phase2Wrap_halted_iff] + erw [phase2Wrap_halted_iff, phase2Wrap_halted_iff, phase2Wrap_halted_iff] exact hhalt₄ · show P C₄.output exact hout₄ diff --git a/Complexitylib/Models/TuringMachine/Composition/Nondeterministic.lean b/Complexitylib/Models/TuringMachine/Composition/Nondeterministic.lean index adfe28a8..a84a23cc 100644 --- a/Complexitylib/Models/TuringMachine/Composition/Nondeterministic.lean +++ b/Complexitylib/Models/TuringMachine/Composition/Nondeterministic.lean @@ -118,7 +118,7 @@ theorem compositionNTM_branchesAgreeAt_rewindVirtual (compositionNTM tmF N).BranchesAgreeAt c := by refine branchesAgreeAt_of_state_eq tmF N hq ?_ dsimp only [compositionNTM, TM.compositionTM, TM.compositionTailTM, TM.seqTM] - rw [if_neg hne, if_neg hne] + rw [ite_eq_right hne, ite_eq_right hne] rfl end BranchAgreement diff --git a/Complexitylib/Models/TuringMachine/Composition/Nondeterministic/Trace.lean b/Complexitylib/Models/TuringMachine/Composition/Nondeterministic/Trace.lean index 87f4865e..603513de 100644 --- a/Complexitylib/Models/TuringMachine/Composition/Nondeterministic/Trace.lean +++ b/Complexitylib/Models/TuringMachine/Composition/Nondeterministic/Trace.lean @@ -100,7 +100,7 @@ theorem compositionNTM_trace_run (tmF : TM nf) (N : NTM ng) -- The remaining steps follow `N` bit for bit. have hread_ns : ∀ tp : Tape, tp.StartInvariant → 1 ≤ tp.head → tp.read ≠ Γ.start := fun tp hinv hh => hinv.2 tp.head hh - rw [placedCfg_trace tmF N (hread_ns _ hinpInv hinpHead) + erw [placedCfg_trace tmF N (hread_ns _ hinpInv hinpHead) (fun i hi => hread_ns _ (hstable i).1 (hstable i).2) s _ _ (by rw [TM.startedCfg_input_eq] diff --git a/Complexitylib/Models/TuringMachine/Composition/PairWithInput/Internal.lean b/Complexitylib/Models/TuringMachine/Composition/PairWithInput/Internal.lean index 06dc9f9a..8acc0c7b 100644 --- a/Complexitylib/Models/TuringMachine/Composition/PairWithInput/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Composition/PairWithInput/Internal.lean @@ -202,7 +202,7 @@ theorem pairWithInputTailTM_hoareTime_internal (nf : ℕ) apply transitionTape_eq_self rw [hout] decide - simpa only [hinputStable, hworkStableAt, houtStable] using + simpa only [PairWithInputEmitterPre, hinputStable, hworkStableAt, houtStable] using (show PairWithInputEmitterPre nf first second inp work out from ⟨hinput, hrawHead, hrawOutput, hworkInv, hout⟩)) hemitter @@ -224,7 +224,7 @@ theorem pairWithInputTailTM_hoareTime_internal (nf : ℕ) apply transitionTape_eq_self rw [hout] decide - simpa only [hinputStable, hworkStableAt, houtStable] using + simpa only [PairWithInputEmitterPre, hinputStable, hworkStableAt, houtStable] using (show PairWithInputAfterRaw nf first second B inp work out from ⟨hrawHead, hrawOutput, hinputCells, hinputInv, hinputHead, hinputBound, hworkInv, hout⟩)) @@ -280,8 +280,7 @@ theorem pairWithInputTM_computesInTime_internal omega · have hreach := seqTM_reachesIn_of_reachesIn first tail hreachF hhaltF hreachTail - simpa [pairWithInputTM, pairWithInputFirstTM, first, tail, final, - boundaryInput, boundaryWork, boundaryOutput] using hreach + exact hreach · show (pairWithInputTM tmF).halted final simpa [pairWithInputTM, first, tail, final] using (phase2Wrap_halted_iff first tail D).2 hhaltTail diff --git a/Complexitylib/Models/TuringMachine/Delay.lean b/Complexitylib/Models/TuringMachine/Delay.lean index 7fef1b71..ecc5b721 100644 --- a/Complexitylib/Models/TuringMachine/Delay.lean +++ b/Complexitylib/Models/TuringMachine/Delay.lean @@ -94,9 +94,9 @@ theorem delayNTM_trace_one_embed (tm : NTM n) (b : Bool) (c : Cfg n tm.Q) : (delayNTM tm).trace 1 (fun _ => b) (delayEmbed tm c) = delayEmbed tm (tm.trace 1 (fun _ => b) c) := by by_cases hc : c.state = tm.qhalt - · rw [NTM.trace, NTM.trace, if_pos ((delayEmbed_halted_iff tm c).mpr hc), if_pos hc] - · rw [NTM.trace, NTM.trace, if_neg (fun h => hc ((delayEmbed_halted_iff tm c).mp h)), - if_neg hc] + · rw [NTM.trace, NTM.trace, ite_eq_left ((delayEmbed_halted_iff tm c).mpr hc), ite_eq_left hc] + · rw [NTM.trace, NTM.trace, ite_eq_right (fun h => hc ((delayEmbed_halted_iff tm c).mp h)), + ite_eq_right hc] rcases hr : tm.δ b c.state c.input.read (fun i => (c.work i).read) c.output.read with ⟨q', ww, ow, iD, wD, oD⟩ have hd : (delayNTM tm).δ b (delayEmbed tm c).state (delayEmbed tm c).input.read @@ -144,7 +144,7 @@ theorem trace_one_of_heads_zero (tm : NTM n) (b : Bool) (c : Cfg n tm.Q) intro i; rw [Tape.read, hwork i]; exact hwork0 i have hro : c.output.read = Γ.start := by rw [Tape.read, hout]; exact hout0 have hdirs := tm.δ_right_of_start b c.state Γ.start (fun _ => Γ.start) Γ.start - rw [NTM.trace, if_neg hne] + rw [NTM.trace, ite_eq_right hne] simp only [hri, hro, funext hrw] rcases hr : tm.δ b c.state Γ.start (fun _ => Γ.start) Γ.start with ⟨q', ww, ow, iD, wD, oD⟩ rw [hr] at hdirs @@ -168,7 +168,7 @@ theorem delayNTM_trace_one_pending (tm : NTM n) (b : Bool) (c : Cfg n (delayNTM ⟨Sum.inr (tm.δ b tm.qstart Γ.start (fun _ => Γ.start) Γ.start).1, c.input, c.work, c.output⟩ := by have hnh : c.state ≠ (delayNTM tm).qhalt := by rw [hstate]; nofun - rw [NTM.trace, if_neg hnh] + rw [NTM.trace, ite_eq_right hnh] have hd : (delayNTM tm).δ b c.state c.input.read (fun i => (c.work i).read) c.output.read = (Sum.inr (tm.δ b tm.qstart Γ.start (fun _ => Γ.start) Γ.start).1, fun i => TM.readBackWrite ((c.work i).read), TM.readBackWrite c.output.read, @@ -177,7 +177,7 @@ theorem delayNTM_trace_one_pending (tm : NTM n) (b : Bool) (c : Cfg n (delayNTM rw [hstate] show (if c.input.read = Γ.start then (Sum.inl () : Unit ⊕ tm.Q) else Sum.inr (tm.δ b tm.qstart Γ.start (fun _ => Γ.start) Γ.start).1, _, _, _, _, _) = _ - rw [if_neg hin] + rw [ite_eq_right hin] simp only [hd, NTM.trace] refine Cfg.ext rfl ?_ ?_ ?_ · exact TM.transitionInput_eq_self hin @@ -201,7 +201,7 @@ theorem delayNTM_trace_two_initCfg (tm : NTM n) (x : List Bool) show (if (Γ.start : Γ) = Γ.start then (Sum.inl () : Unit ⊕ tm.Q) else Sum.inr (tm.δ (choices ⟨0, by omega⟩) tm.qstart Γ.start (fun _ => Γ.start) Γ.start).1) = Sum.inl () - rw [if_pos rfl] + rw [ite_eq_left rfl] rw [NTM.trace_two, hstep1, hδ1] have hinr : ((Tape.init (x.map Γ.ofBool)).move Dir3.right).read ≠ Γ.start := Tape.init_ofBool_move_right_read_ne_start x @@ -249,8 +249,8 @@ theorem delayNTM_acceptCount (tm : NTM n) (x : List Bool) set P : (Fin (T + 1) → Bool) → Prop := fun g => (tm.trace (T + 1) g (tm.initCfg x)).state = tm.qhalt ∧ (tm.trace (T + 1) g (tm.initCfg x)).output.cells 1 = Γ.one with hP - letI : DecidableEq tm.Q := tm.decEq - letI : DecidablePred P := fun _ => inferInstanceAs (Decidable (_ ∧ _)) + let : DecidableEq tm.Q := tm.decEq + let : DecidablePred P := fun _ => inferInstanceAs (Decidable (_ ∧ _)) have hkey := delayNTM_trace_initCfg tm x hne T have hfilter : ∀ ch : Fin (T + 2) → Bool, (((delayNTM tm).trace (T + 2) ch ((delayNTM tm).initCfg x)).state @@ -264,9 +264,9 @@ theorem delayNTM_acceptCount (tm : NTM n) (x : List Bool) (Finset.univ.filter fun ch : Fin (T + 2) → Bool => Q (Fin.tail ch)).card = 2 * (Finset.univ.filter Q).card := by intro Q hQ - haveI : DecidablePred Q := hQ - haveI hf1 : Fintype {g : Fin (T + 1) → Bool // Q g} := Subtype.fintype _ - haveI hf2 : Fintype {ch : Fin (T + 2) → Bool // Q (Fin.tail ch)} := Subtype.fintype _ + have : DecidablePred Q := hQ + have hf1 : Fintype {g : Fin (T + 1) → Bool // Q g} := Subtype.fintype _ + have hf2 : Fintype {ch : Fin (T + 2) → Bool // Q (Fin.tail ch)} := Subtype.fintype _ rw [← Fintype.card_subtype, ← Fintype.card_subtype] rw [Fintype.card_congr (Equiv.mk (fun ch : {ch : Fin (T + 2) → Bool // Q (Fin.tail ch)} => diff --git a/Complexitylib/Models/TuringMachine/Deterministic.lean b/Complexitylib/Models/TuringMachine/Deterministic.lean index fab450cc..d6dbf541 100644 --- a/Complexitylib/Models/TuringMachine/Deterministic.lean +++ b/Complexitylib/Models/TuringMachine/Deterministic.lean @@ -193,16 +193,16 @@ private theorem writeAndMove_readBack_cell1 (t : Tape) (d : Dir3) rw [hcells, Tape.write] by_cases hh0 : t.head = 0 · simp [hh0] - · rw [if_neg hh0] + · rw [ite_eq_right hh0] simp only [Function.update_apply] by_cases h1 : (1 : ℕ) = t.head - · rw [if_pos h1, Tape.read, ← h1] + · rw [ite_eq_left h1, Tape.read, ← h1] cases hg : t.cells 1 · rfl · rfl · rfl · exact absurd hg hns - · rw [if_neg h1] + · rw [ite_eq_right h1] /-- Halt-step correspondence, cells version: when `N` has halted, the simulator's one halt step lands with output cell 1 exactly equal to `N`'s @@ -306,7 +306,7 @@ theorem singleTapeSim_rejectsWithZero {k : ℕ} {N : NTM k} (hk : 1 ≤ k) have hagree : ∀ i : Fin m, choices ⟨i.val, lt_of_lt_of_le i.isLt hle⟩ = ch i.val := by intro i simp only [hch] - rw [dif_pos (lt_of_lt_of_le i.isLt hle)] + rw [dite_eq_left (lt_of_lt_of_le i.isLt hle)] rw [(singleTapeSim N).trace_mono hle hagree hhalted, hcell] exact hrej x hx _ diff --git a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Control/Internal.lean b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Control/Internal.lean index e4ecfa06..c56914d9 100644 --- a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Control/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Control/Internal.lean @@ -557,12 +557,10 @@ private theorem binaryForIteration_reachesIn (body : BinaryRoutine n) simpa [binaryForBodyTime, current, count] using hbodyTime rw [TM.binaryForIterationTime] omega - · simpa [count, current, next, currentOut, nextOut, - TM.binaryForIterationTM, TM.phase1Wrap, TM.phase2Wrap] using hseq - · simpa [count, current, next, currentOut, nextOut, - binaryForIterationStartCfg, binaryForIterationDoneCfg, - TM.binaryForIterationTM, TM.binaryForIterationWrap, - TM.phase1Wrap, TM.phase2Wrap] using hlift + · simp [TM.binaryForIterationTM] + exact hseq + · simp [binaryForIterationStartCfg, binaryForIterationDoneCfg, TM.binaryForIterationTM] + exact hlift private theorem binaryForIterationWitnessOfRequires (body : BinaryRoutine n) (hbodySound : body.Sound) @@ -661,7 +659,7 @@ private theorem binaryForActualIterationTime_spec (binaryForIterationDoneCfg body counterIdx limitIdx initial inp out (initial counterIdx) value) := by dsimp only [binaryForActualIterationTime] - rw [dif_pos ⟨hstart, hlt⟩] + rw [dite_eq_left ⟨hstart, hlt⟩] exact Classical.choose_spec (binaryForIterationWitnessOfRequires body hbodySound counterIdx limitIdx initial inp out ys inputLength initialSpace hrequires hinp hout @@ -757,7 +755,7 @@ private noncomputable def binaryForSegmentSpecOfSound (body : BinaryRoutine n) out ys (initial counterIdx) (initial limitIdx) hinp hout hcounter hlimit · rfl -private noncomputable def binaryForSegmentSpaceSpecOfSound +private theorem binaryForSegmentSpaceSpecOfSound (body : BinaryRoutine n) (hbodySound : body.Sound) (counterIdx limitIdx : Fin n) (initial : BinaryValues n) (inp out : Tape) (ys : List Bool) (inputLength initialSpace : ℕ) @@ -858,7 +856,8 @@ private noncomputable def binaryForSegmentSpaceSpecOfSound (binaryForIterationSpace_le_max body counterIdx initialSpace initial count total hcount) (le_max_right _ _) rw [hcfg] - simpa [TM.binaryForIterationWrap] using hd.mono le_rfl hspaceLe + simp [TM.binaryForIterationWrap] + exact hd.mono le_rfl hspaceLe theorem Sound.branchZero_internal {onZero onPositive : BinaryRoutine n} (hzeroSound : onZero.Sound) (hpositiveSound : onPositive.Sound) @@ -963,8 +962,8 @@ theorem Sound.binaryFor_internal {body : BinaryRoutine n} · simp [spec, binaryForSegmentSpecOfSound, binaryForDoneCfg] · simp [spec, binaryForSegmentSpecOfSound, binaryForDoneCfg, binaryFor, binaryForCount] - · simpa [spec, binaryForSegmentSpecOfSound, binaryForDoneCfg, - binaryFor, total, List.append_assoc] using houtFinal + · simp [spec, binaryForSegmentSpecOfSound, binaryForDoneCfg, binaryFor] + exact houtFinal · intro inp work out hpre cfg hreach rcases hpre with ⟨rfl, rfl, hout⟩ let total := binaryForCount counterIdx limitIdx initial diff --git a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Defs.lean b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Defs.lean index fbbd0c54..3f5b3c38 100644 --- a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Defs.lean @@ -114,8 +114,8 @@ def seq (first second : BinaryRoutine n) : BinaryRoutine n where machine, effect, emitted word, and resource bounds exactly. Soundness requires the replacement precondition to imply the original one. -/ def restrict (routine : BinaryRoutine n) - (requires : BinaryValues n → Prop) : BinaryRoutine n := - { routine with requires := requires } + (newRequires : BinaryValues n → Prop) : BinaryRoutine n := + { routine with requires := newRequires } /-- Increment one canonical binary work value. -/ def binarySucc (idx : Fin n) : BinaryRoutine n where diff --git a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/InputLength/Internal.lean b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/InputLength/Internal.lean index 76e11d55..41193c7b 100644 --- a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/InputLength/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/InputLength/Internal.lean @@ -111,7 +111,7 @@ theorem Sound.afterInputLength_hoareTimeSpace_internal exact ⟨hinput, hwork, houtAcc⟩ exact TM.emitPred_transition hinp₁ (workTapes_parked values) [] inp work out hcanonical - · simpa [List.nil_append] using hright + · exact hright apply hseq.consequence · exact fun _ _ _ hpre => hpre · intro _inp _work out hpost diff --git a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Internal.lean b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Internal.lean index e234b3cc..e7d761c7 100644 --- a/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Experimental/BinaryRoutine/Internal.lean @@ -142,7 +142,8 @@ theorem emitBits_sound_internal (word : List Bool) : subst work exact canonicalWithinAuxSpace (TM.emitBitsTM word) values inp₀ out inputLength initialSpace hinitialSpace hinputSpace) - simpa [emitBits, CanonicalPred] using hrun + simp [emitBits, CanonicalPred] + exact hrun · exact TM.emitBitsTM_isTransducer word theorem identity_sound_internal : (identity (n := n)).Sound := by diff --git a/Complexitylib/Models/TuringMachine/GuessAssembly.lean b/Complexitylib/Models/TuringMachine/GuessAssembly.lean index 5fae3f52..3723b25b 100644 --- a/Complexitylib/Models/TuringMachine/GuessAssembly.lean +++ b/Complexitylib/Models/TuringMachine/GuessAssembly.lean @@ -119,7 +119,7 @@ theorem liftLast_stepCfg (D : TM m) (c : Cfg m D.Q) (τ : Tape) (hτ : τ.read · funext i refine Fin.lastCases ?_ ?_ i · simp only [TM.stepCfg, liftLast, NTM.attach, Fin.snoc_last] - rw [writeAndMove_readBack _ hτ, idleDir, if_neg hτ] + rw [writeAndMove_readBack _ hτ, idleDir, ite_eq_right hτ] rfl · intro j simp [TM.stepCfg, liftLast, NTM.attach] @@ -143,7 +143,7 @@ theorem liftLast_reachesIn (D : TM m) (τ : Tape) (hτ : τ.read ≠ Γ.start) : have hne : c.state ≠ D.qhalt := by intro hq unfold TM.step at hstep - rw [if_pos hq] at hstep + rw [ite_eq_left hq] at hstep exact absurd hstep (by simp) have hb : D.stepCfg c = c₁ := by rw [step_of_not_halted D hne] at hstep @@ -336,6 +336,7 @@ theorem guessProtocol_seqTM {A B : TM (k + 1)} {AdvA : A.Q → Bool} {AdvB : B.Q = (B.δ q iHead wHeads oHead).2.2.2.2.1 := by simp [seqTM, h] rw [hred, hB.dir q h iHead wHeads oHead hs] simp [seqAdv] + rfl · rintro (q | q) hq hadv iHead ww oHead g g' · by_cases h : q = A.qhalt · subst h @@ -457,6 +458,11 @@ instance : Fintype GuessPhase where elems := {.read, .done} complete := fun x => by cases x <;> simp +/-- The advancing state of the guess primitives: only `read` consumes a guess bit. +Stated on `GuessPhase` itself so instance search never has to see through a +machine's `Q` projection. -/ +@[simp] def guessPhaseAdv (q : GuessPhase) : Bool := decide (q = GuessPhase.read) + /-- **The guess-reading primitive.** In one step it copies the symbol under the guess head onto work tape `j`, advances the guess head, and halts. This is the only place a machine assembled with `TM.liftLast` ever consults the guess tape. -/ @@ -493,7 +499,7 @@ def guessReadTM (j : Fin (k + 1)) : TM (k + 1) where /-- The guess-reading primitive advances exactly in its one working state. -/ theorem guessProtocol_guessReadTM (j : Fin (k + 1)) : - GuessProtocol (guessReadTM j) (fun q => decide (q = GuessPhase.read)) := by + GuessProtocol (guessReadTM j) guessPhaseAdv := by refine ⟨?_, ?_, ?_⟩ · rintro (_ | _) hq iHead wHeads oHead · simp only [guessReadTM] @@ -566,7 +572,7 @@ def guessWriteTM (j : Fin (k + 1)) : TM (k + 1) where /-- The guess-writing primitive advances exactly in its one working state. -/ theorem guessProtocol_guessWriteTM (j : Fin (k + 1)) : - GuessProtocol (guessWriteTM j) (fun q => decide (q = GuessPhase.read)) := by + GuessProtocol (guessWriteTM j) guessPhaseAdv := by refine ⟨?_, ?_, ?_⟩ · rintro (_ | _) hq iHead wHeads oHead · simp only [guessWriteTM] @@ -630,13 +636,13 @@ theorem guessWriteTM_hoareTime (j : Fin (k + 1)) (hj : j ≠ Fin.last k) funext i rw [guessWriteTapes] by_cases hij : i = j - · rw [if_pos hij, hij] + · rw [ite_eq_left hij, hij] exact h1 - · rw [if_neg hij] + · rw [ite_eq_right hij] by_cases hil : i = Fin.last k - · rw [if_pos hil, hil] + · rw [ite_eq_left hil, hil] exact h2 - · rw [if_neg hil] + · rw [ite_eq_right hil] exact h3 i hij hil /-! ## Writing a block of guesses @@ -652,8 +658,8 @@ def guessBlockTM (j : Fin (k + 1)) : ℕ → TM (k + 1) /-- Its advancing states: every state of every stage. -/ def guessBlockAdv (j : Fin (k + 1)) : (n : ℕ) → (guessBlockTM j n).Q → Bool - | 0 => fun q => decide (q = GuessPhase.read) - | n + 1 => seqAdv (fun q => decide (q = GuessPhase.read)) (guessBlockAdv j n) + | 0 => guessPhaseAdv + | n + 1 => seqAdv guessPhaseAdv (guessBlockAdv j n) /-- The tapes a block of guess-writes leaves behind. Each stage writes, then the composition's own handoff step passes every tape through `TM.transitionTape`. -/ @@ -722,17 +728,17 @@ theorem guessBlockOutput_eq_self {t : Tape} (h : t.read ≠ Γ.start) : theorem guessWriteTapes_last (j : Fin (k + 1)) (hj : j ≠ Fin.last k) (W : Fin (k + 1) → Tape) (hg : (W (Fin.last k)).read ≠ Γ.start) : guessWriteTapes j W (Fin.last k) = (W (Fin.last k)).move Dir3.right := by - rw [guessWriteTapes, if_neg (Ne.symm hj), if_pos rfl, writeAndMove_readBack _ hg] + rw [guessWriteTapes, ite_eq_right (Ne.symm hj), ite_eq_left rfl, writeAndMove_readBack _ hg] theorem guessWriteTapes_target (j : Fin (k + 1)) (W : Fin (k + 1) → Tape) (hg : (W (Fin.last k)).read ≠ Γ.start) : guessWriteTapes j W j = ((W j).write (W (Fin.last k)).read).move Dir3.right := by - rw [guessWriteTapes, if_pos rfl, toΓ_readBackWrite_of_ne_start hg] + rw [guessWriteTapes, ite_eq_left rfl, toΓ_readBackWrite_of_ne_start hg] theorem guessWriteTapes_other (j : Fin (k + 1)) (W : Fin (k + 1) → Tape) (i : Fin (k + 1)) (hij : i ≠ j) (hil : i ≠ Fin.last k) (h : (W i).read ≠ Γ.start) : guessWriteTapes j W i = W i := by - rw [guessWriteTapes, if_neg hij, if_neg hil, transitionTape_eq_self h] + rw [guessWriteTapes, ite_eq_right hij, ite_eq_right hil, transitionTape_eq_self h] theorem guessWriteTapes_target_head (j : Fin (k + 1)) (W : Fin (k + 1) → Tape) (hg : (W (Fin.last k)).read ≠ Γ.start) : @@ -746,7 +752,7 @@ theorem guessWriteTapes_target_cells (j : Fin (k + 1)) (W : Fin (k + 1) → Tape (guessWriteTapes j W j).cells ((W j).head) = (W (Fin.last k)).read := by rw [guessWriteTapes_target j W hg] show ((W j).write (W (Fin.last k)).read).cells ((W j).head) = _ - rw [Tape.write, if_neg (by omega)] + rw [Tape.write, ite_eq_right (by omega)] exact Function.update_self _ _ _ theorem guessWriteTapes_target_cells_ne (j : Fin (k + 1)) (W : Fin (k + 1) → Tape) @@ -899,7 +905,7 @@ theorem guessProtocol_skipTM : GuessProtocol (skipTM (n := k + 1)) (fun _ => fal refine ⟨fun q _ iHead wHeads oHead => rfl, fun q _ iHead wHeads oHead h => ?_, fun q _ _ iHead ww oHead g g' => ?_⟩ · show idleDir (wHeads (Fin.last k)) = _ - rw [idleDir, if_neg h] + rw [idleDir, ite_eq_right h] simp · simp [visible, skipTM] @@ -1182,7 +1188,7 @@ theorem guessBlocksTM_hoareTime (j : ℕ → Fin (k + 1)) (hj : ∀ t, j t ≠ F induction t with | zero => intro inp₀ out₀ W₀ - simpa using skipTM_hoareTime' inp₀ out₀ W₀ + exact skipTM_hoareTime' inp₀ out₀ W₀ | succ t ih => intro inp₀ out₀ W₀ have hcomp := seqTM_hoareTime (guessBlocksTM j w t) (guessBlockTM (j t) (w t)) diff --git a/Complexitylib/Models/TuringMachine/GuessStream.lean b/Complexitylib/Models/TuringMachine/GuessStream.lean index 7515f640..233dccdd 100644 --- a/Complexitylib/Models/TuringMachine/GuessStream.lean +++ b/Complexitylib/Models/TuringMachine/GuessStream.lean @@ -60,13 +60,13 @@ def traceD (M : TM n) : ℕ → Cfg n M.Q → Cfg n M.Q theorem traceD_succ_of_not_halted (M : TM n) (T : ℕ) {c : Cfg n M.Q} (h : c.state ≠ M.qhalt) : M.traceD (T + 1) c = M.traceD T (M.stepCfg c) := by - rw [traceD, if_neg h] + rw [traceD, ite_eq_right h] theorem traceD_of_halted (M : TM n) (T : ℕ) {c : Cfg n M.Q} (h : c.state = M.qhalt) : M.traceD T c = c := by cases T with | zero => rfl - | succ T => rw [traceD, if_pos h] + | succ T => rw [traceD, ite_eq_left h] /-- A run of `T + 1` steps is a run of `T` steps followed by one more. -/ theorem traceD_succ_back (M : TM n) : ∀ (T : ℕ) (c : Cfg n M.Q), @@ -77,12 +77,12 @@ theorem traceD_succ_back (M : TM n) : ∀ (T : ℕ) (c : Cfg n M.Q), | zero => intro c by_cases h : c.state = M.qhalt - · rw [traceD_of_halted M _ h, traceD_zero, if_pos h] - · rw [traceD_succ_of_not_halted M 0 h, traceD_zero, traceD_zero, if_neg h] + · rw [traceD_of_halted M _ h, traceD_zero, ite_eq_left h] + · rw [traceD_succ_of_not_halted M 0 h, traceD_zero, traceD_zero, ite_eq_right h] | succ T ih => intro c by_cases h : c.state = M.qhalt - · rw [traceD_of_halted M _ h, traceD_of_halted M _ h, if_pos h] + · rw [traceD_of_halted M _ h, traceD_of_halted M _ h, ite_eq_left h] · rw [traceD_succ_of_not_halted M (T + 1) h, traceD_succ_of_not_halted M T h, ih] /-- A fixed-length run is a `reachesIn` run, stopped early exactly when the machine halts. -/ @@ -217,7 +217,7 @@ theorem nrunAt_of_halted (N : NTM k) (choices : ℕ → Bool) {c : Cfg k N.Q} (h : c.state = N.qhalt) (i : ℕ) : nrunAt N choices c i = c := by induction i with | zero => rfl - | succ i ih => rw [nrunAt_succ, ih, if_pos h] + | succ i ih => erw [nrunAt_succ, ih, ite_eq_left h] theorem nrunAt_succ_front (N : NTM k) (choices : ℕ → Bool) {c : Cfg k N.Q} (h : c.state ≠ N.qhalt) (i : ℕ) : @@ -225,10 +225,10 @@ theorem nrunAt_succ_front (N : NTM k) (choices : ℕ → Bool) {c : Cfg k N.Q} = nrunAt N (fun j => choices (j + 1)) (stepCfg N (choices 0) c) i := by induction i with | zero => - rw [nrunAt_succ] + erw [nrunAt_succ] simp only [nrunAt_zero] - rw [if_neg h] - | succ i ih => rw [nrunAt_succ, ih, nrunAt_succ] + erw [ite_eq_right h] + | succ i ih => erw [nrunAt_succ, ih, nrunAt_succ] /-- The absolutely-indexed run is `NTM.trace`. -/ theorem trace_eq_nrunAt (N : NTM k) (choices : ℕ → Bool) : @@ -240,7 +240,7 @@ theorem trace_eq_nrunAt (N : NTM k) (choices : ℕ → Bool) : | succ T ih => intro c by_cases h : c.state = N.qhalt - · rw [trace, if_pos h, nrunAt_of_halted N choices h] + · rw [trace, ite_eq_left h, nrunAt_of_halted N choices h] · rw [trace_succ_of_not_halted N T _ h, nrunAt_succ_front N choices h] exact ih (fun j => choices (j + 1)) _ @@ -352,9 +352,9 @@ theorem searchIdx_eq {P : ℕ → Bool} {T i : ℕ} (hi : i < T) (hP : P i = tru | succ T ih => rw [searchIdx] by_cases h : P T = true - · rw [if_pos h] + · rw [ite_eq_left h] exact huniq T h - · rw [if_neg h] + · rw [ite_eq_right h] refine ih ?_ rcases Nat.lt_or_ge i T with h' | h' · exact h' @@ -366,7 +366,7 @@ variable {k : ℕ} (M : TM (k + 1)) (Adv : M.Q → Bool) (choices : ℕ → Bool /-- Whether the nondeterministic run consumes a guess at step `i`. -/ def consumes (i : ℕ) : Bool := - !decide ((nrunAt (ofGuess M) choices d i).state = M.qhalt) && + !(@decide ((nrunAt (ofGuess M) choices d i).state = M.qhalt) (M.decEq _ _)) && Adv (nrunAt (ofGuess M) choices d i).state /-- Where the guess head sits after `i` steps: one cell on for every guess consumed. -/ @@ -399,7 +399,7 @@ theorem cursor_mono : ∀ {i j : ℕ}, i ≤ j → theorem cursor_lt_of_consumes {i j : ℕ} (hij : i < j) (hi : consumes M Adv choices d i = true) : cursor M Adv choices d i < cursor M Adv choices d j := by refine lt_of_lt_of_le ?_ (cursor_mono M Adv choices d hij) - rw [cursor, if_pos hi] + rw [cursor, ite_eq_left hi] omega theorem cursor_inj_of_consumes {i j : ℕ} (hi : consumes M Adv choices d i = true) @@ -454,7 +454,7 @@ theorem traceD_guessOf {Adv : M.Q → Bool} (hP : TM.GuessProtocol M Adv) (T : induction i with | zero => intro _ - refine ⟨by simp, ?_⟩ + refine ⟨by erw [nrunAt_zero, TM.traceD_zero, dropChoice_attach], ?_⟩ show (attach d (loadTape (guessOf M Adv choices d T))).work (Fin.last k) = _ rw [attach_work_last] rfl @@ -473,8 +473,8 @@ theorem traceD_guessOf {Adv : M.Q → Bool} (hP : TM.GuessProtocol M Adv) (T : have hnhalt : (nrunAt (ofGuess M) choices d i).state = (ofGuess M).qhalt := by rw [← hstate]; exact hhalt refine ⟨?_, ?_⟩ - · rw [TM.traceD_succ_back, if_pos hhalt, ihd, nrunAt_succ, if_pos hnhalt] - · rw [TM.traceD_succ_back, if_pos hhalt, ihw, cursor, hcons] + · erw [TM.traceD_succ_back, ite_eq_left hhalt, ihd, nrunAt_succ, ite_eq_left hnhalt] + · erw [TM.traceD_succ_back, ite_eq_left hhalt, ihw, cursor, hcons] simp · have hcells : (cᵢ.work (Fin.last k)).read = Γ.ofBool (g (cursor M Adv choices d i - 1)) := by @@ -486,10 +486,10 @@ theorem traceD_guessOf {Adv : M.Q → Bool} (hP : TM.GuessProtocol M Adv) (T : have hne : (cᵢ.work (Fin.last k)).read ≠ Γ.start := by rw [hcells]; exact Γ.ofBool_ne_start _ have hstep : M.traceD (i + 1) c₀ = M.stepCfg cᵢ := by - rw [TM.traceD_succ_back, if_neg hhalt] + erw [TM.traceD_succ_back, ite_eq_right hhalt] have hnstep : nrunAt (ofGuess M) choices d (i + 1) = stepCfg (ofGuess M) (choices i) (nrunAt (ofGuess M) choices d i) := by - rw [nrunAt_succ, if_neg (by rw [← hstate]; exact hhalt)] + erw [nrunAt_succ, ite_eq_right (by rw [← hstate]; exact hhalt)] by_cases hadv : Adv cᵢ.state · have hcons : consumes M Adv choices d i = true := by simp [consumes, ← hstate, hhalt, hadv] @@ -498,7 +498,7 @@ theorem traceD_guessOf {Adv : M.Q → Bool} (hP : TM.GuessProtocol M Adv) (T : refine ⟨?_, ?_⟩ · rw [hstep, hnstep, ← ihd] exact dropChoice_stepCfg M (by rw [hcells, hbit]) - · rw [hstep, work_last_stepCfg' M hP cᵢ hhalt hne, if_pos hadv, ihw, cursor, hcons] + · rw [hstep, work_last_stepCfg' M hP cᵢ hhalt hne, ite_eq_left hadv, ihw, cursor, hcons] rfl · have hcons : consumes M Adv choices d i = false := by simp [consumes, ← hstate, hadv] @@ -506,7 +506,7 @@ theorem traceD_guessOf {Adv : M.Q → Bool} (hP : TM.GuessProtocol M Adv) (T : · rw [hstep, hnstep, ← ihd] rw [dropChoice_stepCfg M hcells] exact stepCfg_indep M hP hhalt hadv _ _ - · rw [hstep, work_last_stepCfg' M hP cᵢ hhalt hne, if_neg hadv, ihw, cursor, hcons] + · rw [hstep, work_last_stepCfg' M hP cᵢ hhalt hne, ite_eq_right hadv, ihw, cursor, hcons] rfl end Cursor diff --git a/Complexitylib/Models/TuringMachine/GuessTape.lean b/Complexitylib/Models/TuringMachine/GuessTape.lean index ec605a07..0da8b171 100644 --- a/Complexitylib/Models/TuringMachine/GuessTape.lean +++ b/Complexitylib/Models/TuringMachine/GuessTape.lean @@ -179,7 +179,7 @@ theorem reachesIn_ofGuess_iff (M : TM (k + 1)) (hM : TM.GuessDiscipline M) : induction t with | zero => intro c c' _ - rw [TM.reachesIn_zero_iff, TM.reachesIn_zero_iff] + erw [TM.reachesIn_zero_iff, TM.reachesIn_zero_iff] exact Iff.rfl | succ t ih => intro c c' hbool @@ -189,12 +189,12 @@ theorem reachesIn_ofGuess_iff (M : TM (k + 1)) (hM : TM.GuessDiscipline M) : simp [hhalt] constructor · intro h - rw [TM.reachesIn_succ_iff] at h + erw [TM.reachesIn_succ_iff] at h obtain ⟨c₁, hs, -⟩ := h rw [step_ofGuess M hM hbool.read, h1] at hs exact absurd hs (by simp) · intro h - rw [TM.reachesIn_succ_iff] at h + erw [TM.reachesIn_succ_iff] at h obtain ⟨c₁, hs, -⟩ := h rw [h1] at hs exact absurd hs (by simp) @@ -204,14 +204,14 @@ theorem reachesIn_ofGuess_iff (M : TM (k + 1)) (hM : TM.GuessDiscipline M) : exact hbool.move_right constructor · intro h - rw [TM.reachesIn_succ_iff] at h + erw [TM.reachesIn_succ_iff] at h obtain ⟨c₁, hs, hr⟩ := h rw [step_ofGuess M hM hbool.read, hstep] at hs have hs' : M.stepCfg c = c₁ := Option.some.inj hs subst hs' exact TM.reachesIn.step hstep ((ih _ c' hbool₁).mp hr) · intro h - rw [TM.reachesIn_succ_iff] at h + erw [TM.reachesIn_succ_iff] at h obtain ⟨c₁, hs, hr⟩ := h rw [hstep] at hs have hs' : M.stepCfg c = c₁ := Option.some.inj hs diff --git a/Complexitylib/Models/TuringMachine/Hoare.lean b/Complexitylib/Models/TuringMachine/Hoare.lean index e7ae20c5..f8127773 100644 --- a/Complexitylib/Models/TuringMachine/Hoare.lean +++ b/Complexitylib/Models/TuringMachine/Hoare.lean @@ -57,7 +57,7 @@ theorem seqTM_hoareTime (tm₁ tm₂ : TM n) obtain ⟨c₂, t₂, ht₂, hreach₂, hhalt₂, hpost⟩ := h₂ _ _ _ hmid' refine ⟨phase2Wrap tm₁ tm₂ c₂, t₁ + 1 + t₂, ?_, ?_, ?_, ?_⟩ · omega - · convert seqTM_reachesIn_of_reachesIn tm₁ tm₂ hreach₁ hhalt₁ hreach₂ using 1 + · exact seqTM_reachesIn_of_reachesIn tm₁ tm₂ hreach₁ hhalt₁ hreach₂ · rw [phase2Wrap_halted_iff]; exact hhalt₂ · exact hpost diff --git a/Complexitylib/Models/TuringMachine/Internal.lean b/Complexitylib/Models/TuringMachine/Internal.lean index f60c415e..f3970dda 100644 --- a/Complexitylib/Models/TuringMachine/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Internal.lean @@ -50,13 +50,13 @@ lemma TM.toNTM_trace_reaches (tm : TM n) (c : Cfg n tm.Q) induction T generalizing c with | zero => exact Relation.ReflTransGen.refl | succ T ih => - simp only [NTM.trace] + dsimp only [NTM.trace, TM.toNTM] split · exact Relation.ReflTransGen.refl · next hne => have hne : c.state ≠ tm.qhalt := hne exact Relation.ReflTransGen.head - (show tm.stepRel c _ by simp [TM.stepRel, TM.step, hne, TM.toNTM]) + (show tm.stepRel c _ by simp [TM.stepRel, TM.step, hne]) (ih _ _) /-- For `toNTM`, the trace is independent of the choice sequence since both @@ -67,10 +67,10 @@ lemma TM.toNTM_trace_choice_irrel (tm : TM n) (T : ℕ) (c : Cfg n tm.Q) induction T generalizing c with | zero => rfl | succ T ih => - simp only [NTM.trace] + dsimp only [NTM.trace, TM.toNTM] split · rfl - · simp only [TM.toNTM]; exact ih _ _ _ + · exact ih _ _ _ /-- If a DTM reaches `c'` in exactly `t` steps, then `toNTM.trace t` agrees. -/ private lemma TM.toNTM_reachesIn_trace (tm : TM n) {c c' : Cfg n tm.Q} {t : ℕ} @@ -348,7 +348,7 @@ private theorem tape_cell0_preserved (t : Tape) (s : Γ) (d : Dir3) rw [Tape.move_cells]; simp only [Tape.write] split · exact h0 - · simp only [Function.update, dif_neg (show (0 : ℕ) ≠ t.head from fun h => by omega)] + · simp only [Function.update, dite_eq_right (show (0 : ℕ) ≠ t.head from fun h => by omega)] exact h0 /-- Cells ≥ 1 stay non-Γ.start after writing a non-Γ.start value. -/ @@ -513,7 +513,7 @@ theorem input_cells_trace (tm : NTM n) (T : ℕ) | succ T ih => by_cases hhalt : c.state = tm.qhalt · simp [NTM.trace, hhalt] - · simp only [NTM.trace, hhalt, if_false] + · simp only [NTM.trace, hhalt, ite_false] rw [ih] cases (tm.δ (choices ⟨0, Nat.zero_lt_succ T⟩) c.state c.input.read (fun i => (c.work i).read) c.output.read).2.2.2.1 <;> rfl @@ -528,7 +528,7 @@ theorem input_head_trace_le (tm : NTM n) (T : ℕ) | succ T ih => by_cases hhalt : c.state = tm.qhalt · simp [NTM.trace, hhalt] - · simp only [NTM.trace, hhalt, if_false] + · simp only [NTM.trace, hhalt, ite_false] let b := choices ⟨0, Nat.zero_lt_succ T⟩ let tr := tm.δ b c.state c.input.read (fun i => (c.work i).read) c.output.read let c' : Cfg n tm.Q := @@ -556,7 +556,7 @@ theorem work_head_trace_le (tm : NTM n) (T : ℕ) | succ T ih => by_cases hhalt : c.state = tm.qhalt · simp [NTM.trace, hhalt] - · simp only [NTM.trace, hhalt, if_false] + · simp only [NTM.trace, hhalt, ite_false] let b := choices ⟨0, Nat.zero_lt_succ T⟩ let tr := tm.δ b c.state c.input.read (fun j => (c.work j).read) c.output.read let c' : Cfg n tm.Q := @@ -580,7 +580,7 @@ theorem output_head_trace_le (tm : NTM n) (T : ℕ) | succ T ih => by_cases hhalt : c.state = tm.qhalt · simp [NTM.trace, hhalt] - · simp only [NTM.trace, hhalt, if_false] + · simp only [NTM.trace, hhalt, ite_false] let b := choices ⟨0, Nat.zero_lt_succ T⟩ let tr := tm.δ b c.state c.input.read (fun i => (c.work i).read) c.output.read let c' : Cfg n tm.Q := diff --git a/Complexitylib/Models/TuringMachine/Lift.lean b/Complexitylib/Models/TuringMachine/Lift.lean index fbc84686..82f22fc6 100644 --- a/Complexitylib/Models/TuringMachine/Lift.lean +++ b/Complexitylib/Models/TuringMachine/Lift.lean @@ -72,7 +72,7 @@ private theorem dummy_writeAndMove (w : Tape) have hr : w.read = Γ.blank := by rw [hread, h1]; rfl rw [hr] show w.write (readBackWrite Γ.blank).toΓ = (Tape.init []).move Dir3.right - rw [Tape.write, if_neg (show ¬ w.head = 0 by omega), h1, hc] + rw [Tape.write, ite_eq_right (show ¬ w.head = 0 by omega), h1, hc] rw [show (readBackWrite Γ.blank).toΓ = (Tape.init []).cells 1 from rfl, Function.update_eq_self] rfl @@ -134,13 +134,13 @@ def liftCfg (tm : TM n) (m : ℕ) (c : Cfg n tm.Q) : Cfg (n + m) tm.Q where /-- `liftCfg` maps the first `n` work tapes to `c`'s work tapes. -/ theorem liftCfg_work_lt (tm : TM n) (m : ℕ) (c : Cfg n tm.Q) (i : Fin (n + m)) (h : i.val < n) : - (tm.liftCfg m c).work i = c.work ⟨i.val, h⟩ := dif_pos h + (tm.liftCfg m c).work i = c.work ⟨i.val, h⟩ := dite_eq_left h /-- `liftCfg` maps the extra work tapes to the parked blank tape. -/ theorem liftCfg_work_ge (tm : TM n) (m : ℕ) (c : Cfg n tm.Q) (i : Fin (n + m)) (h : n ≤ i.val) : (tm.liftCfg m c).work i = (Tape.init []).move Dir3.right := - dif_neg (Nat.not_lt.mpr h) + dite_eq_right (Nat.not_lt.mpr h) /-- **Unified step commutation** for `liftTM`. If the extra work tapes of `C` are blank with head at cell 0 or 1 and the rest of `C` matches `c`, @@ -156,9 +156,9 @@ private theorem liftTM_step_of_extras (tm : TM n) (m : ℕ) {c : Cfg n tm.Q} (tm.liftTM m).step C = (tm.step c).map (tm.liftCfg m) := by by_cases hh : c.state = tm.qhalt · -- both machines are halted + have hC : C.state = (tm.liftTM m).qhalt := hs.trans hh have h1 : (tm.liftTM m).step C = none := by - simp only [step, hs, hh, show (tm.liftTM m).qhalt = tm.qhalt from rfl, - ↓reduceIte] + simp only [step, hC, ↓reduceIte] have h2 : tm.step c = none := by simp only [step, hh, ↓reduceIte] rw [h1, h2]; rfl @@ -173,13 +173,14 @@ private theorem liftTM_step_of_extras (tm : TM n) (m : ℕ) {c : Cfg n tm.Q} funext fun i => by rw [hw (Fin.castAdd m i) i.isLt]; rfl simp only [step, Option.map_some] dsimp only [liftTM, liftCfg] - rw [hs, hi, ho, hinner, if_neg hh] + rw [hs, hi, ho, hinner] + simp only [hh, ↓reduceIte] refine congrArg some (Cfg.mk.injEq _ _ _ _ _ _ _ _ |>.mpr ⟨rfl, rfl, ?_, rfl⟩) funext i by_cases hik : i.val < n - · rw [hw i hik, dif_pos hik, dif_pos hik, dif_pos hik] + · rw [hw i hik, dite_eq_left hik, dite_eq_left hik, dite_eq_left hik] · have hdi := hd i (Nat.le_of_not_lt hik) - rw [dif_neg hik, dif_neg hik, dif_neg hik] + rw [dite_eq_right hik, dite_eq_right hik, dite_eq_right hik] exact dummy_writeAndMove (C.work i) hdi.1 hdi.2 /-- **Step commutation** on embedded configurations: once the extra tapes @@ -187,7 +188,7 @@ private theorem liftTM_step_of_extras (tm : TM n) (m : ℕ) {c : Cfg n tm.Q} `liftCfg`. -/ theorem liftTM_step_liftCfg (tm : TM n) (m : ℕ) (c : Cfg n tm.Q) : (tm.liftTM m).step (tm.liftCfg m c) = (tm.step c).map (tm.liftCfg m) := - liftTM_step_of_extras tm m rfl rfl rfl (fun _ h => dif_pos h) + liftTM_step_of_extras tm m rfl rfl rfl (fun _ h => dite_eq_left h) (fun i h => by rw [liftCfg_work_ge tm m c i h] exact ⟨rfl, Nat.le_refl 1⟩) @@ -414,11 +415,11 @@ def retargetCfg (tm : TM n) (c : Cfg n tm.Q) : Cfg (n + 1) tm.Q where /-- `retargetCfg` maps the first `n` work tapes to `c`'s work tapes. -/ theorem retargetCfg_work_lt (tm : TM n) (c : Cfg n tm.Q) (i : Fin (n + 1)) (h : i.val < n) : - (tm.retargetCfg c).work i = c.work ⟨i.val, h⟩ := dif_pos h + (tm.retargetCfg c).work i = c.work ⟨i.val, h⟩ := dite_eq_left h /-- `retargetCfg` maps the last work tape to `c`'s output tape. -/ theorem retargetCfg_work_last (tm : TM n) (c : Cfg n tm.Q) : - (tm.retargetCfg c).work (Fin.last n) = c.output := dif_neg (Nat.lt_irrefl n) + (tm.retargetCfg c).work (Fin.last n) = c.output := dite_eq_right (Nat.lt_irrefl n) /-- **Unified step commutation** for `retargetOutput`: if `C`'s real output tape is blank with head at cell 0 or 1, work tape `n` matches @@ -434,9 +435,9 @@ private theorem retargetOutput_step_of_extras (tm : TM n) {c : Cfg n tm.Q} (tm.retargetOutput).step C = (tm.step c).map tm.retargetCfg := by by_cases hh : c.state = tm.qhalt · -- both machines are halted + have hC : C.state = (tm.retargetOutput).qhalt := hs.trans hh have h1 : (tm.retargetOutput).step C = none := by - simp only [step, hs, hh, show (tm.retargetOutput).qhalt = tm.qhalt from rfl, - ↓reduceIte] + simp only [step, hC, ↓reduceIte] have h2 : tm.step c = none := by simp only [step, hh, ↓reduceIte] rw [h1, h2]; rfl @@ -452,17 +453,18 @@ private theorem retargetOutput_step_of_extras (tm : TM n) {c : Cfg n tm.Q} have hvirt : (C.work (Fin.last n)).read = c.output.read := by rw [hlast] simp only [step, Option.map_some] dsimp only [retargetOutput, retargetCfg] - rw [hs, hi, hinner, hvirt, if_neg hh] + rw [hs, hi, hinner, hvirt] + simp only [hh, ↓reduceIte] refine congrArg some (Cfg.mk.injEq _ _ _ _ _ _ _ _ |>.mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hik : i.val < n - · rw [hw i hik, dif_pos hik, dif_pos hik, dif_pos hik] + · rw [hw i hik, dite_eq_left hik, dite_eq_left hik, dite_eq_left hik] · have hi_last : i = Fin.last n := by apply Fin.ext have := i.isLt simp only [Fin.val_last] omega - rw [dif_neg hik, dif_neg hik, dif_neg hik, hi_last, hlast] + rw [dite_eq_right hik, dite_eq_right hik, dite_eq_right hik, hi_last, hlast] · exact dummy_writeAndMove C.output ho.1 ho.2 /-- **Step commutation** on embedded configurations: once the real output @@ -470,7 +472,7 @@ private theorem retargetOutput_step_of_extras (tm : TM n) {c : Cfg n tm.Q} `retargetCfg`. -/ theorem retargetOutput_step_retargetCfg (tm : TM n) (c : Cfg n tm.Q) : (tm.retargetOutput).step (tm.retargetCfg c) = (tm.step c).map tm.retargetCfg := - retargetOutput_step_of_extras tm rfl rfl (fun _ h => dif_pos h) + retargetOutput_step_of_extras tm rfl rfl (fun _ h => dite_eq_left h) (retargetCfg_work_last tm c) ⟨rfl, Nat.le_refl 1⟩ @@ -577,8 +579,7 @@ theorem retargetOutput_computesInTime_boundary (tm : TM n) theorem IsTransducer.liftTM {tm : TM n} (h : tm.IsTransducer) (m : ℕ) : (tm.liftTM m).IsTransducer := by intro q iHead wHeads oHead - simpa only [liftTM] using h q iHead - (fun i => wHeads (Fin.castAdd m i)) oHead + exact h q iHead (fun i => wHeads (Fin.castAdd m i)) oHead /-- Redirecting output to a work tape leaves the real output direction idle, so the resulting machine is always a one-way-output transducer. -/ diff --git a/Complexitylib/Models/TuringMachine/Oracle/Internal.lean b/Complexitylib/Models/TuringMachine/Oracle/Internal.lean index b0fce1a3..52ec191c 100644 --- a/Complexitylib/Models/TuringMachine/Oracle/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Oracle/Internal.lean @@ -217,7 +217,7 @@ theorem toOracleTM_decidesInTime_iff_internal obtain ⟨cfg, time, htime, hreach, hhalt, hyes, hno⟩ := hdecides input have hreach' : machine.reachesIn time (machine.toOracleTM.initCfg input).erase cfg := by - simpa using hreach + exact hreach obtain ⟨oracleCfg, horacleReach, herase⟩ := exists_toOracleTM_reachesIn_of_reachesIn_erase_internal machine oracle (machine.toOracleTM.initCfg input) hreach' diff --git a/Complexitylib/Models/TuringMachine/Oracle/OutputSemantics/Internal.lean b/Complexitylib/Models/TuringMachine/Oracle/OutputSemantics/Internal.lean index 8935a09d..d109a8f5 100644 --- a/Complexitylib/Models/TuringMachine/Oracle/OutputSemantics/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Oracle/OutputSemantics/Internal.lean @@ -69,7 +69,7 @@ theorem toOracleTM_producesInTime_iff_internal · rintro ⟨cfg, steps, hsteps, hreach, hhalt, houtput⟩ have hreach' : machine.reachesIn steps (machine.toOracleTM.initCfg program).erase cfg := by - simpa using hreach + exact hreach obtain ⟨oracleCfg, horacleReach, herase⟩ := machine.exists_toOracleTM_reachesIn_of_reachesIn_erase oracle (machine.toOracleTM.initCfg program) hreach' diff --git a/Complexitylib/Models/TuringMachine/OutputSemantics/Internal.lean b/Complexitylib/Models/TuringMachine/OutputSemantics/Internal.lean index 3d165629..5640ba3b 100644 --- a/Complexitylib/Models/TuringMachine/OutputSemantics/Internal.lean +++ b/Complexitylib/Models/TuringMachine/OutputSemantics/Internal.lean @@ -52,7 +52,7 @@ private theorem sameExceptInputCells_next {tm : TM n} {first second : Cfg n tm.Q rw [hwork] have houtputRead : first.output.read = second.output.read := by rw [houtput] - simp only [TM.step, hhalt, hhalt', if_false, Option.getD_some] + simp only [TM.step, hhalt, hhalt', ite_false, Option.getD_some] rw [hstate, hread, hworkRead, houtputRead, hwork, houtput] refine ⟨rfl, ?_, rfl, rfl⟩ cases (tm.δ second.state second.input.read @@ -71,7 +71,7 @@ theorem runCfg_of_halted_internal (tm : TM n) {c : Cfg n tm.Q} (hhalt : tm.halted c) (steps : ℕ) : tm.runCfg c steps = c := by induction steps with | zero => rfl - | succ steps ih => rw [runCfg, ih, TM.step, if_pos hhalt, Option.getD_none] + | succ steps ih => rw [runCfg, ih, TM.step, ite_eq_left hhalt, Option.getD_none] theorem runCfg_of_reachesIn_internal (tm : TM n) {c c' : Cfg n tm.Q} {steps : ℕ} (hreach : tm.reachesIn steps c c') : tm.runCfg c steps = c' := by diff --git a/Complexitylib/Models/TuringMachine/Placement/Hoare.lean b/Complexitylib/Models/TuringMachine/Placement/Hoare.lean index bc1bbcbd..19489de8 100644 --- a/Complexitylib/Models/TuringMachine/Placement/Hoare.lean +++ b/Complexitylib/Models/TuringMachine/Placement/Hoare.lean @@ -62,15 +62,15 @@ theorem placeWorkTM_hoareTime (tm : TM n) {pre post : TapePred n} {b : ℕ} show work i = if hi : placeWorkInMiddle pre₀ n i then work (placeWorkIdx pre₀ post₀ (placeWorkCoord pre₀ n i hi)) else extras i by_cases hi : placeWorkInMiddle pre₀ n i - · rw [dif_pos hi, placeWorkIdx_placeWorkCoord i hi] - · rw [dif_neg hi] + · rw [dite_eq_left hi, placeWorkIdx_placeWorkCoord i hi] + · rw [dite_eq_right hi] exact hframe i hi rw [hstart] exact placeWorkTM_reachesIn_placeWorkCfg_of_startInvariant tm pre₀ post₀ extras hreach hinv hhead · intro i hi show (if h : placeWorkInMiddle pre₀ n i then _ else extras i) = extras i - rw [dif_neg hi] + rw [dite_eq_right hi] · show post c'.input (fun j => (placeWorkCfg tm pre₀ post₀ extras c').work (placeWorkIdx pre₀ post₀ j)) c'.output have hw : (fun j => (placeWorkCfg tm pre₀ post₀ extras c').work @@ -79,7 +79,7 @@ theorem placeWorkTM_hoareTime (tm : TM n) {pre post : TapePred n} {b : ℕ} show (if hi : placeWorkInMiddle pre₀ n (placeWorkIdx pre₀ post₀ j) then c'.work (placeWorkCoord pre₀ n (placeWorkIdx pre₀ post₀ j) hi) else extras (placeWorkIdx pre₀ post₀ j)) = c'.work j - rw [dif_pos (placeWorkInMiddle_placeWorkIdx pre₀ post₀ j), + rw [dite_eq_left (placeWorkInMiddle_placeWorkIdx pre₀ post₀ j), placeWorkCoord_placeWorkIdx pre₀ post₀ j] rw [hw] exact hpost diff --git a/Complexitylib/Models/TuringMachine/Placement/Internal.lean b/Complexitylib/Models/TuringMachine/Placement/Internal.lean index d21b15fe..6bb228fb 100644 --- a/Complexitylib/Models/TuringMachine/Placement/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Placement/Internal.lean @@ -45,7 +45,7 @@ private theorem placeWorkFrameStep_blank (t : Tape) · have hr : t.read = Γ.blank := by rw [hread, h1]; rfl rw [hr] show t.write (readBackWrite Γ.blank) = (Tape.init []).move Dir3.right - rw [Tape.write, if_neg (show ¬t.head = 0 by omega), h1, hcells] + rw [Tape.write, ite_eq_right (show ¬t.head = 0 by omega), h1, hcells] rw [show (readBackWrite Γ.blank).toΓ = (Tape.init []).cells 1 from rfl, Function.update_eq_self] rfl @@ -58,7 +58,7 @@ theorem placeWorkTM_step_placeWorkCfg_internal (tm : TM n) (pre post : ℕ) (tm.step c).map (placeWorkCfg tm pre post (placeWorkFrameStep extras)) := by by_cases hhalt : c.state = tm.qhalt - · simp [TM.step, placeWorkCfg, placeWorkTM, hhalt] + · simp [TM.step, placeWorkCfg, placeWorkTM, hhalt]; rfl · cases hstep : tm.step c with | none => exact absurd hstep (by simp [TM.step, hhalt]) | some c' => diff --git a/Complexitylib/Models/TuringMachine/Placement/Window.lean b/Complexitylib/Models/TuringMachine/Placement/Window.lean index 5439f02b..930b98b0 100644 --- a/Complexitylib/Models/TuringMachine/Placement/Window.lean +++ b/Complexitylib/Models/TuringMachine/Placement/Window.lean @@ -70,9 +70,9 @@ theorem placeWorkTM_keepsWindow_of_reaches (tm : TM n) (pre post : ℕ) else extras j := rfl rw [hval] by_cases hj : placeWorkInMiddle pre n j - · rw [dif_pos hj] + · rw [dite_eq_left hj] exact hw _ - · rw [dif_neg hj] + · rw [dite_eq_right hj] exact hextraW j hj end TM diff --git a/Complexitylib/Models/TuringMachine/Registers.lean b/Complexitylib/Models/TuringMachine/Registers.lean index 850c5f9a..c28f9465 100644 --- a/Complexitylib/Models/TuringMachine/Registers.lean +++ b/Complexitylib/Models/TuringMachine/Registers.lean @@ -62,7 +62,7 @@ theorem Parked.writeAndMove_readBack_idle {t : Tape} (h : Parked t) : /-- A parked tape's head does not move under `idleDir`. -/ theorem Parked.move_idle {t : Tape} (h : Parked t) : t.move (idleDir t.read) = t := by - rw [idleDir, if_neg h.read_ne_start] + rw [idleDir, ite_eq_right h.read_ne_start] rfl /-- Parked tapes pass through combinator phase boundaries unchanged. -/ @@ -124,8 +124,8 @@ theorem read_eq {v : ℕ} {t : Tape} (h : IsReg v t) : t.read = if v = 0 then Γ.blank else Γ.one := by rw [Tape.read, h.head_eq] rcases Nat.eq_zero_or_pos v with rfl | hv - · rw [if_pos rfl]; exact h.cells_blank (le_refl _) - · rw [if_neg (by omega)]; exact h.cells_one hv + · rw [ite_eq_left rfl]; exact h.cells_blank (le_refl _) + · rw [ite_eq_right (by omega)]; exact h.cells_one hv end IsReg @@ -134,7 +134,7 @@ theorem reg_zero_init_bumped : IsReg 0 { head := 1, cells := (Tape.init []).cell refine ⟨rfl, by simp [Tape.init], fun _ hi => by omega, fun j hj => ?_⟩ show (Tape.init []).cells j = Γ.blank simp only [Tape.init] - rw [if_neg (by omega : ¬ j = 0)] + rw [ite_eq_right (by omega : ¬ j = 0)] simp -- ════════════════════════════════════════════════════════════════════════ @@ -159,16 +159,16 @@ def regTape (v : ℕ) : Tape := ⟨1, regCells v⟩ /-- Cells `1..v` of the canonical register cells for `v` hold `1`. -/ theorem regCells_one {v j : ℕ} (h1 : 1 ≤ j) (h2 : j ≤ v) : regCells v j = Γ.one := by - rw [regCells, if_neg (by omega), if_pos h2] + rw [regCells, ite_eq_right (by omega), ite_eq_left h2] /-- Cells beyond position `v` of the canonical register cells for `v` are blank. -/ theorem regCells_blank {v j : ℕ} (h : v + 1 ≤ j) : regCells v j = Γ.blank := by - rw [regCells, if_neg (by omega), if_neg (by omega)] + rw [regCells, ite_eq_right (by omega), ite_eq_right (by omega)] /-- Register cells away from the sentinel are never `▷`. -/ theorem regCells_ne_start {v j : ℕ} (hj : 1 ≤ j) : regCells v j ≠ Γ.start := by - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide /-- The canonical register tape `regTape v` satisfies `IsReg v`. -/ diff --git a/Complexitylib/Models/TuringMachine/Registers/DecReg.lean b/Complexitylib/Models/TuringMachine/Registers/DecReg.lean index 1bacb23d..6efc8da4 100644 --- a/Complexitylib/Models/TuringMachine/Registers/DecReg.lean +++ b/Complexitylib/Models/TuringMachine/Registers/DecReg.lean @@ -101,12 +101,12 @@ def decRegTM (q : Fin n) : TM n where dsimp only [] by_cases hir : i = q · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .erase => dsimp only [] split @@ -115,26 +115,26 @@ def decRegTM (q : Fin n) : TM n where dsimp only [] by_cases hir : i = q · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -160,16 +160,16 @@ private theorem decRegTM_step_scan_one (c : Cfg n (decRegTM (n := n) q).Q) { state := .scan, input := c.input, work := Function.update c.work q ((c.work q).move .right), output := c.output } := by - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -182,16 +182,16 @@ private theorem decRegTM_step_scan_blank (c : Cfg n (decRegTM (n := n) q).Q) { state := .erase, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hblank]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -205,7 +205,7 @@ private theorem decRegTM_step_erase_one (c : Cfg n (decRegTM (n := n) q).Q) work := Function.update c.work q (((c.work q).write Γw.blank).move .left), output := c.output } := by - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -213,7 +213,7 @@ private theorem decRegTM_step_erase_one (c : Cfg n (decRegTM (n := n) q).Q) by_cases hir : i = q · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -230,18 +230,18 @@ private theorem decRegTM_step_erase_start (c : Cfg n (decRegTM (n := n) q).Q) have h0 : (c.work q).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst, hs, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -254,15 +254,15 @@ private theorem decRegTM_step_back_left (c : Cfg n (decRegTM (n := n) q).Q) { state := .back, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -279,18 +279,18 @@ private theorem decRegTM_step_back_start (c : Cfg n (decRegTM (n := n) q).Q) have h0 : (c.work q).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -301,7 +301,7 @@ private theorem decRegTM_step_park (c : Cfg n (decRegTM (n := n) q).Q) (decRegTM (n := n) q).step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (decRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decRegTM_ne_halt (by decide) hst)] simp only [decRegTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -491,7 +491,7 @@ theorem decRegTM_hoareTime (q : Fin n) (d : ℕ) (inp₀ : Tape) have hstep₃ := decRegTM_step_erase_start c₂ rfl hs₂ (fun j hj => by rw [hc₂cells] - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide) hinpP₁ hc₂workP houtP₁ set c₃ : Cfg n (decRegTM (n := n) q).Q := @@ -509,7 +509,7 @@ theorem decRegTM_hoareTime (q : Fin n) (d : ℕ) (inp₀ : Tape) omega · intro j hj show (c₂.work i).cells j ≠ Γ.start - rw [hc₂cells, regCells, if_neg (by omega)] + rw [hc₂cells, regCells, ite_eq_right (by omega)] split <;> decide · show Parked (Function.update c₂.work q ((c₂.work q).move .right) i) rw [Function.update_of_ne hir] @@ -556,7 +556,7 @@ theorem decRegTM_hoareTime (q : Fin n) (d : ℕ) (inp₀ : Tape) rw [Function.update_self] show (((c₂.work q).write Γw.blank).move .left).cells = _ show ((c₂.work q).write Γw.blank).cells = _ - rw [Tape.write, if_neg (by rw [hc₂head]; omega)] + rw [Tape.write, ite_eq_right (by rw [hc₂head]; omega)] show Function.update (c₂.work q).cells (c₂.work q).head Γw.blank.toΓ = _ rw [hc₂cells, hc₂head] exact regCells_update_blank_succ e @@ -580,7 +580,7 @@ theorem decRegTM_hoareTime (q : Fin n) (d : ℕ) (inp₀ : Tape) houtP₁ (by rw [hc₃cells]; rfl) (fun j hj => by - rw [hc₃cells, regCells, if_neg (by omega)] + rw [hc₃cells, regCells, ite_eq_right (by omega)] split <;> decide) hc₃head refine ⟨c₄, _, ?_, diff --git a/Complexitylib/Models/TuringMachine/Registers/Emit.lean b/Complexitylib/Models/TuringMachine/Registers/Emit.lean index 11047d00..b8a36cad 100644 --- a/Complexitylib/Models/TuringMachine/Registers/Emit.lean +++ b/Complexitylib/Models/TuringMachine/Registers/Emit.lean @@ -114,7 +114,7 @@ theorem outAcc_nil_init : OutAcc [] { head := 1, cells := (Tape.init []).cells } refine ⟨rfl, by simp [Tape.init], fun i hi => absurd hi (by simp), fun j hj => ?_⟩ show (Tape.init []).cells j = Γ.blank simp only [Tape.init] - rw [if_neg (by omega : ¬ j = 0)] + rw [ite_eq_right (by omega : ¬ j = 0)] simp /-- **Appending one bit.** Writing `Γ.ofBool b` at the accumulator head and @@ -128,12 +128,12 @@ theorem outAcc_append_bit {ys : List Bool} {out : Tape} (h : OutAcc ys out) (b : show ((out.write _).move _).cells = _ rw [Tape.move] show (out.write _).cells = _ - rw [Tape.write, if_neg hne, hhead] + rw [Tape.write, ite_eq_right hne, hhead] have hhead' : (out.writeAndMove (Γ.ofBool b) .right).head = out.head + 1 := by show ((out.write _).move _).head = _ rw [Tape.move] show (out.write _).head + 1 = _ - rw [Tape.write, if_neg hne] + rw [Tape.write, ite_eq_right hne] refine ⟨?_, ?_, ?_, ?_⟩ · rw [hhead', hhead]; simp · rw [hcells, Function.update_of_ne (by omega : ¬ (0 : ℕ) = ys.length + 1)] @@ -187,7 +187,7 @@ theorem parked_init_input (x : List Bool) : refine ⟨le_refl 1, fun j hj => ?_⟩ show (Tape.init (x.map Γ.ofBool)).cells j ≠ Γ.start simp only [Tape.init] - rw [if_neg (by omega : ¬ j = 0)] + rw [ite_eq_right (by omega : ¬ j = 0)] cases h : (x.map Γ.ofBool)[j - 1]? with | none => decide | some g => @@ -250,7 +250,7 @@ private theorem emitBitsTM_step (w : List Bool) (c : Cfg n (emitBitsTM (n := n) rw [hst] simp only [emitBitsTM, Fin.mk.injEq] omega - rw [TM.step, if_neg hne] + rw [TM.step, ite_eq_right hne] simp only [emitBitsTM, hst, hk, ↓reduceDIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -408,33 +408,33 @@ def emitUnaryTM (r : Fin n) : TM n where dsimp only [] by_cases hir : i = r · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hnone => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .emitB => refine ⟨idleDir_right_of_start, fun i hi => ?_, fun _ => rfl⟩ dsimp only [] by_cases hir : i = r - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -459,16 +459,16 @@ private theorem emitUnaryTM_step_emitA_one (c : Cfg n (emitUnaryTM (n := n) r).Q (emitUnaryTM (n := n) r).step c = some { state := .emitB, input := c.input, work := c.work, output := c.output.writeAndMove (Γ.ofBool true) .right } := by - rw [TM.step, if_neg (emitUnaryTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (emitUnaryTM_ne_halt (by decide) hst)] simp only [emitUnaryTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, writeAndMove_readBack _ (by rw [hone]; decide)] + rw [ite_eq_left rfl, writeAndMove_readBack _ (by rw [hone]; decide)] rfl - · rw [if_neg hir] + · rw [ite_eq_right hir] exact (hwork i hir).writeAndMove_readBack_idle · rfl @@ -480,16 +480,16 @@ private theorem emitUnaryTM_step_emitB (c : Cfg n (emitUnaryTM (n := n) r).Q) { state := .emitA, input := c.input, work := Function.update c.work r ((c.work r).move .right), output := c.output.writeAndMove (Γ.ofBool true) .right } := by - rw [TM.step, if_neg (emitUnaryTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (emitUnaryTM_ne_halt (by decide) hst)] simp only [emitUnaryTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · rfl @@ -503,16 +503,16 @@ private theorem emitUnaryTM_step_emitA_blank (c : Cfg n (emitUnaryTM (n := n) r) { state := .back, input := c.input, work := Function.update c.work r ((c.work r).move .left), output := c.output } := by - rw [TM.step, if_neg (emitUnaryTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (emitUnaryTM_ne_halt (by decide) hst)] simp only [emitUnaryTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hblank]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -525,15 +525,15 @@ private theorem emitUnaryTM_step_back_left (c : Cfg n (emitUnaryTM (n := n) r).Q { state := .back, input := c.input, work := Function.update c.work r ((c.work r).move .left), output := c.output } := by - rw [TM.step, if_neg (emitUnaryTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (emitUnaryTM_ne_halt (by decide) hst)] simp only [emitUnaryTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -551,18 +551,18 @@ private theorem emitUnaryTM_step_back_start (c : Cfg n (emitUnaryTM (n := n) r). have h0 : (c.work r).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (emitUnaryTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (emitUnaryTM_ne_halt (by decide) hst)] simp only [emitUnaryTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -572,7 +572,7 @@ private theorem emitUnaryTM_step_park (c : Cfg n (emitUnaryTM (n := n) r).Q) (hout : Parked c.output) : (emitUnaryTM (n := n) r).step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (emitUnaryTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (emitUnaryTM_ne_halt (by decide) hst)] simp only [emitUnaryTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle diff --git a/Complexitylib/Models/TuringMachine/Registers/ForReg.lean b/Complexitylib/Models/TuringMachine/Registers/ForReg.lean index 02e5e532..990eee49 100644 --- a/Complexitylib/Models/TuringMachine/Registers/ForReg.lean +++ b/Complexitylib/Models/TuringMachine/Registers/ForReg.lean @@ -96,27 +96,27 @@ def forRegTM (body : TM n) (r : Fin n) : TM n where dsimp only [] by_cases hir : i = r · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hnone => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .inl .rewind => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .inl .done => exact rightOfStart_allIdle iHead wHeads oHead | .inr q => dsimp only [] @@ -140,10 +140,10 @@ private theorem forRegTM_lift_step (c c' : Cfg n body.Q) (forRegTM body r).step (wrapCfg body r c) = some (wrapCfg body r c') := by have hne : ¬ c.state = body.qhalt := by intro h - rw [TM.step, if_pos h] at hstep + rw [TM.step, ite_eq_left h] at hstep simp at hstep - rw [TM.step, if_neg hne] at hstep - rw [TM.step, if_neg (show ¬ (wrapCfg body r c).state = (forRegTM body r).qhalt from + rw [TM.step, ite_eq_right hne] at hstep + rw [TM.step, ite_eq_right (show ¬ (wrapCfg body r c).state = (forRegTM body r).qhalt from by simp [wrapCfg, forRegTM])] simp only [wrapCfg, forRegTM, hne, ↓reduceIte] revert hstep @@ -169,16 +169,16 @@ private theorem forRegTM_step_test_one (c : Cfg n (forRegTM body r).Q) { state := .inr body.qstart, input := c.input, work := Function.update c.work r ((c.work r).move .right), output := c.output } := by - rw [TM.step, if_neg (forRegTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (forRegTM_ne_halt (by simp) hst)] simp only [forRegTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -191,7 +191,7 @@ private theorem forRegTM_step_test_blank (c : Cfg n (forRegTM body r).Q) { state := .inl .rewind, input := c.input, work := Function.update c.work r ((c.work r).move .left), output := c.output } := by - rw [TM.step, if_neg (forRegTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (forRegTM_ne_halt (by simp) hst)] simp only [forRegTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -200,7 +200,7 @@ private theorem forRegTM_step_test_blank (c : Cfg n (forRegTM body r).Q) · subst hir simp only [↓reduceIte, Function.update_self] rw [writeAndMove_readBack _ (by rw [hblank]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -213,15 +213,15 @@ private theorem forRegTM_step_rewind_left (c : Cfg n (forRegTM body r).Q) { state := .inl .rewind, input := c.input, work := Function.update c.work r ((c.work r).move .left), output := c.output } := by - rw [TM.step, if_neg (forRegTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (forRegTM_ne_halt (by simp) hst)] simp only [forRegTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -238,18 +238,18 @@ private theorem forRegTM_step_rewind_start (c : Cfg n (forRegTM body r).Q) have h0 : (c.work r).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (forRegTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (forRegTM_ne_halt (by simp) hst)] simp only [forRegTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -261,7 +261,7 @@ private theorem forRegTM_step_loopback (c : Cfg n (forRegTM body r).Q) (forRegTM body r).step c = some { state := .inl .test, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (forRegTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (forRegTM_ne_halt (by simp) hst)] simp only [forRegTM, hst, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -394,7 +394,7 @@ private theorem forRegTM_loop_run (inp₀ : Tape) (w : ℕ → Fin n → Tape) show (Function.update (w v) r (⟨v, regCells v⟩ : Tape) r).cells j ≠ Γ.start rw [Function.update_self] show regCells v j ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide) (by show (Function.update (w v) r (⟨v, regCells v⟩ : Tape) r).head = v @@ -452,7 +452,7 @@ private theorem forRegTM_loop_run (inp₀ : Tape) (w : ℕ → Fin n → Tape) rw [Function.update_self] refine ⟨by show (1 : ℕ) ≤ i + 2; omega, fun p hp => ?_⟩ show regCells v p ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide · rw [Function.update_of_ne hjr] exact hwP (i + 1) j hjr diff --git a/Complexitylib/Models/TuringMachine/Registers/InputLen.lean b/Complexitylib/Models/TuringMachine/Registers/InputLen.lean index 4b42965c..6ae15959 100644 --- a/Complexitylib/Models/TuringMachine/Registers/InputLen.lean +++ b/Complexitylib/Models/TuringMachine/Registers/InputLen.lean @@ -75,30 +75,30 @@ def inputLenRegTM (q : Fin n) : TM n where idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · split · exact ⟨fun _ => rfl, fun i hi => idleDir_right_of_start hi, idleDir_right_of_start⟩ · refine ⟨fun _ => rfl, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨fun _ => rfl, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => - refine ⟨fun hi => by rw [if_pos hi], fun i hi => ?_, idleDir_right_of_start⟩ + refine ⟨fun hi => by rw [ite_eq_left hi], fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -125,14 +125,14 @@ private theorem inputLenRegTM_step_scan_bit (c : Cfg n (inputLenRegTM (n := n) q work := Function.update c.work q (((c.work q).write Γw.one).move .right), output := c.output } := by - rw [TM.step, if_neg (inputLenRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (inputLenRegTM_ne_halt (by decide) hst)] simp only [inputLenRegTM, hst, hbl, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = q · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -145,15 +145,15 @@ private theorem inputLenRegTM_step_scan_blank (c : Cfg n (inputLenRegTM (n := n) { state := .back, input := c.input.move .left, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (inputLenRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (inputLenRegTM_ne_halt (by decide) hst)] simp only [inputLenRegTM, hst, hbl, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, if_neg hqns, Function.update_self, + rw [ite_eq_left rfl, ite_eq_right hqns, Function.update_self, writeAndMove_readBack _ hqns] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -166,14 +166,14 @@ private theorem inputLenRegTM_step_back_left (c : Cfg n (inputLenRegTM (n := n) { state := .back, input := c.input.move .left, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (inputLenRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (inputLenRegTM_ne_halt (by decide) hst)] simp only [inputLenRegTM, hst, hqns, hins, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hqns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hqns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -189,17 +189,17 @@ private theorem inputLenRegTM_step_back_start (c : Cfg n (inputLenRegTM (n := n) have h0 : (c.work q).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (inputLenRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (inputLenRegTM_ne_halt (by decide) hst)] simp only [inputLenRegTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -209,7 +209,7 @@ private theorem inputLenRegTM_step_park (c : Cfg n (inputLenRegTM (n := n) q).Q) (hwork : ∀ i, Parked (c.work i)) (hout : Parked c.output) : (inputLenRegTM (n := n) q).step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (inputLenRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (inputLenRegTM_ne_halt (by decide) hst)] simp only [inputLenRegTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -253,7 +253,7 @@ private theorem inputLenRegTM_scan_run (x : List Bool) (m : ℕ) : have hq₁cells : (((c.work q).write Γw.one).move .right).cells = regCells (k + 1) := by show ((c.work q).write Γw.one).cells = _ - rw [Tape.write, if_neg (by rw [hqh]; omega)] + rw [Tape.write, ite_eq_right (by rw [hqh]; omega)] show Function.update (c.work q).cells (c.work q).head Γw.one.toΓ = _ rw [hqh, hqc] exact regCells_update_succ k @@ -448,7 +448,7 @@ theorem inputLenRegTM_hoareTime (q : Fin n) (x : List Bool) show (c₁.work q).cells j ≠ _ rw [h5] show regCells x.length j ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide) (by show (Function.update c₁.work q _ q).head = x.length rw [Function.update_self] diff --git a/Complexitylib/Models/TuringMachine/Registers/Probe.lean b/Complexitylib/Models/TuringMachine/Registers/Probe.lean index 9f2f7255..39352889 100644 --- a/Complexitylib/Models/TuringMachine/Registers/Probe.lean +++ b/Complexitylib/Models/TuringMachine/Registers/Probe.lean @@ -142,7 +142,7 @@ def symProbeTM (f : Γ → Fin 4) (r q : Fin n) : TM n where intro s iHead wHeads oHead match s with | .pre => - refine ⟨fun h => by rw [if_pos h], fun i hi => idleDir_right_of_start hi, + refine ⟨fun h => by rw [ite_eq_left h], fun i hi => idleDir_right_of_start hi, idleDir_right_of_start⟩ | .walk => dsimp only [] @@ -152,13 +152,13 @@ def symProbeTM (f : Γ → Fin 4) (r q : Fin n) : TM n where dsimp only [] by_cases hir : i = r · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi - · refine ⟨fun h => by rw [if_pos h], fun i hi => ?_, + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi + · refine ⟨fun h => by rw [ite_eq_left h], fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .backI k => dsimp only [] split @@ -174,15 +174,15 @@ def symProbeTM (f : Γ → Fin 4) (r q : Fin n) : TM n where idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = r · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .scanQ k => dsimp only [] split @@ -192,20 +192,20 @@ def symProbeTM (f : Γ → Fin 4) (r q : Fin n) : TM n where dsimp only [] by_cases hiq : i = q · subst hiq; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hiq]; exact idleDir_right_of_start hi + · rw [ite_eq_right hiq]; exact idleDir_right_of_start hi · split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hiq : i = q - · subst hiq; rw [if_pos rfl, if_pos hi] - · rw [if_neg hiq]; exact idleDir_right_of_start hi + · subst hiq; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hiq]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hiq : i = q - · rw [if_pos hiq] - · rw [if_neg hiq]; exact idleDir_right_of_start hi + · rw [ite_eq_left hiq] + · rw [ite_eq_right hiq]; exact idleDir_right_of_start hi | .backQ => dsimp only [] split @@ -213,15 +213,15 @@ def symProbeTM (f : Γ → Fin 4) (r q : Fin n) : TM n where idleDir_right_of_start⟩ dsimp only [] by_cases hiq : i = q - · rw [if_pos hiq] - · rw [if_neg hiq]; exact idleDir_right_of_start hi + · rw [ite_eq_left hiq] + · rw [ite_eq_right hiq]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hiq : i = q · subst hiq; exact absurd hi hns - · rw [if_neg hiq]; exact idleDir_right_of_start hi + · rw [ite_eq_right hiq]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -259,7 +259,7 @@ private theorem symProbeTM_step_pre (c : Cfg n (symProbeTM f r q).Q) (symProbeTM f r q).step c = some { state := .walk, input := c.input.move .left, work := c.work, output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hi, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -274,15 +274,15 @@ private theorem symProbeTM_step_walk_one (c : Cfg n (symProbeTM f r q).Q) { state := .walk, input := c.input.move .right, work := Function.update c.work r ((c.work r).move .right), output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -296,15 +296,15 @@ private theorem symProbeTM_step_walk_blank (c : Cfg n (symProbeTM f r q).Q) input := c.input.move (if c.input.read = Γ.start then .right else .left), work := c.work, output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = r · subst hir - rw [writeAndMove_readBack _ (by rw [hblank]; decide), if_pos rfl] + rw [writeAndMove_readBack _ (by rw [hblank]; decide), ite_eq_left rfl] rfl - · rw [if_neg hir] + · rw [ite_eq_right hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -316,7 +316,7 @@ private theorem symProbeTM_step_backI_left {k : Fin 4} (symProbeTM f r q).step c = some { state := .backI k, input := c.input.move .left, work := c.work, output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hi, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -331,7 +331,7 @@ private theorem symProbeTM_step_backI_start {k : Fin 4} (symProbeTM f r q).step c = some { state := .backR k, input := c.input.move .right, work := c.work, output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hi, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -348,15 +348,15 @@ private theorem symProbeTM_step_backR_left {k : Fin 4} { state := .backR k, input := c.input, work := Function.update c.work r ((c.work r).move .left), output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -374,18 +374,18 @@ private theorem symProbeTM_step_backR_start {k : Fin 4} have h0 : (c.work r).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = r · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -399,16 +399,16 @@ private theorem symProbeTM_step_scanQ_one {k : Fin 4} { state := .scanQ k, input := c.input, work := Function.update c.work q ((c.work q).move .right), output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hiq : i = q · subst hiq - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hiq, Function.update_of_ne hiq] + · rw [ite_eq_right hiq, Function.update_of_ne hiq] exact (hwork i hiq).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -422,7 +422,7 @@ private theorem symProbeTM_step_scanQ_blank_zero { state := .backQ, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -430,8 +430,8 @@ private theorem symProbeTM_step_scanQ_blank_zero by_cases hiq : i = q · subst hiq rw [Function.update_self, - writeAndMove_readBack _ (by rw [hblank]; decide), if_pos rfl] - · rw [if_neg hiq, Function.update_of_ne hiq] + writeAndMove_readBack _ (by rw [hblank]; decide), ite_eq_left rfl] + · rw [ite_eq_right hiq, Function.update_of_ne hiq] exact (hwork i hiq).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -446,7 +446,7 @@ private theorem symProbeTM_step_scanQ_blank_succ {k : Fin 4} work := Function.update c.work q (((c.work q).write Γw.one).move .right), output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hblank, reduceCtorEq, ↓reduceIte, hk] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -454,7 +454,7 @@ private theorem symProbeTM_step_scanQ_blank_succ {k : Fin 4} by_cases hiq : i = q · subst hiq simp only [↓reduceIte, Function.update_self] - · rw [if_neg hiq, if_neg hiq, Function.update_of_ne hiq] + · rw [ite_eq_right hiq, ite_eq_right hiq, Function.update_of_ne hiq] exact (hwork i hiq).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -467,15 +467,15 @@ private theorem symProbeTM_step_backQ_left (c : Cfg n (symProbeTM f r q).Q) { state := .backQ, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hiq : i = q · subst hiq - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hiq, Function.update_of_ne hiq] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hiq, Function.update_of_ne hiq] exact (hwork i hiq).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -492,18 +492,18 @@ private theorem symProbeTM_step_backQ_start (c : Cfg n (symProbeTM f r q).Q) have h0 : (c.work q).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hiq : i = q · subst hiq - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hiq, Function.update_of_ne hiq] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hiq, Function.update_of_ne hiq] exact (hwork i hiq).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -514,7 +514,7 @@ private theorem symProbeTM_step_park (c : Cfg n (symProbeTM f r q).Q) (symProbeTM f r q).step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (symProbeTM_ne_halt (by simp) hst)] + rw [TM.step, ite_eq_right (symProbeTM_ne_halt (by simp) hst)] simp only [symProbeTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -750,7 +750,7 @@ private theorem symProbeTM_write_run : ∀ (kv : ℕ) (k : Fin 4), k.val = kv have hwcells : ((((c.work q).write Γw.one)).move .right).cells = regCells (e + 1) := by show ((c.work q).write Γw.one).cells = _ - rw [Tape.write, if_neg (by rw [hhead]; omega)] + rw [Tape.write, ite_eq_right (by rw [hhead]; omega)] show Function.update (c.work q).cells (c.work q).head Γw.one.toΓ = _ rw [hcells, hhead] exact regCells_update_succ e @@ -931,7 +931,7 @@ theorem symProbeTM_hoareTime (f : Γ → Fin 4) (r q : Fin n) (hrq : r ≠ q) ⟨by rw [hhead₂]; omega, fun j hj => by rw [hcells₂] show regCells pos j ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide⟩ have hc₃workP : ∀ i, Parked (c₃.work i) := by intro i @@ -965,7 +965,7 @@ theorem symProbeTM_hoareTime (f : Γ → Fin 4) (r q : Fin n) (hrq : r ≠ q) (fun j hj => by rw [hc₄r] show regCells pos j ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide) rfl have hc₅q : c₅.work q = work q := by @@ -980,7 +980,7 @@ theorem symProbeTM_hoareTime (f : Γ → Fin 4) (r q : Fin n) (hrq : r ≠ q) refine ⟨by rw [hhead₅], fun j hj => ?_⟩ rw [hcells₅, hc₄r] show regCells pos j ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide · rw [hwork₅ i hir, hwork₄] exact hc₃workP i @@ -1038,7 +1038,7 @@ theorem symProbeTM_hoareTime (f : Γ → Fin 4) (r q : Fin n) (hrq : r ≠ q) (fun j hj => by rw [hc₈qcells] show regCells (d + kv) j ≠ Γ.start - rw [regCells, if_neg (by omega)] + rw [regCells, ite_eq_right (by omega)] split <;> decide) hc₈qhead refine ⟨c₉, _, ?_, diff --git a/Complexitylib/Models/TuringMachine/Registers/RegisterOps.lean b/Complexitylib/Models/TuringMachine/Registers/RegisterOps.lean index ad7300d1..a38d47e0 100644 --- a/Complexitylib/Models/TuringMachine/Registers/RegisterOps.lean +++ b/Complexitylib/Models/TuringMachine/Registers/RegisterOps.lean @@ -152,27 +152,27 @@ def incRegTM (q : Fin n) : TM n where dsimp only [] by_cases hir : i = q · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hnone => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -198,16 +198,16 @@ private theorem incRegTM_step_scan_one (c : Cfg n (incRegTM (n := n) q).Q) { state := .scan, input := c.input, work := Function.update c.work q ((c.work q).move .right), output := c.output } := by - rw [TM.step, if_neg (incRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (incRegTM_ne_halt (by decide) hst)] simp only [incRegTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -221,7 +221,7 @@ private theorem incRegTM_step_scan_blank (c : Cfg n (incRegTM (n := n) q).Q) work := Function.update c.work q (((c.work q).write Γw.one).move .left), output := c.output } := by - rw [TM.step, if_neg (incRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (incRegTM_ne_halt (by decide) hst)] simp only [incRegTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -229,7 +229,7 @@ private theorem incRegTM_step_scan_blank (c : Cfg n (incRegTM (n := n) q).Q) by_cases hir : i = q · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -242,15 +242,15 @@ private theorem incRegTM_step_back_left (c : Cfg n (incRegTM (n := n) q).Q) { state := .back, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (incRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (incRegTM_ne_halt (by decide) hst)] simp only [incRegTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -267,18 +267,18 @@ private theorem incRegTM_step_back_start (c : Cfg n (incRegTM (n := n) q).Q) have h0 : (c.work q).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (incRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (incRegTM_ne_halt (by decide) hst)] simp only [incRegTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -288,7 +288,7 @@ private theorem incRegTM_step_park (c : Cfg n (incRegTM (n := n) q).Q) (hout : Parked c.output) : (incRegTM (n := n) q).step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (incRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (incRegTM_ne_halt (by decide) hst)] simp only [incRegTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -450,7 +450,7 @@ theorem incRegTM_hoareTime (q : Fin n) (d : ℕ) (inp₀ : Tape) (work₀ : Fin have hwq₂cells : wq₂.cells = regCells (d + 1) := by rw [hwq₂] show ((c₁.work q).write Γw.one).cells = _ - rw [Tape.write, if_neg (by rw [hhead₁]; omega)] + rw [Tape.write, ite_eq_right (by rw [hhead₁]; omega)] show Function.update (c₁.work q).cells (c₁.work q).head Γw.one.toΓ = _ rw [hhead₁, hcells₁] exact regCells_update_succ d @@ -520,8 +520,8 @@ theorem clearCells_zero (d : ℕ) : clearRegCells d 0 = regCells d := by simp only [clearRegCells, regCells] rcases Nat.eq_zero_or_pos j with rfl | hj · rfl - · rw [if_neg (show ¬ j = 0 from by omega), if_neg (show ¬ j ≤ 0 from by omega), - if_neg (show ¬ j = 0 from by omega)] + · rw [ite_eq_right (show ¬ j = 0 from by omega), ite_eq_right (show ¬ j ≤ 0 from by omega), + ite_eq_right (show ¬ j = 0 from by omega)] /-- After blanking all `d` marks (`k = d`), a mid-clear register is `regCells 0`. -/ theorem clearCells_last (d : ℕ) : clearRegCells d d = regCells 0 := by @@ -529,17 +529,17 @@ theorem clearCells_last (d : ℕ) : clearRegCells d d = regCells 0 := by simp only [clearRegCells, regCells] rcases Nat.eq_zero_or_pos j with rfl | hj · rfl - · rw [if_neg (show ¬ j = 0 from by omega), if_neg (show ¬ j = 0 from by omega), - if_neg (show ¬ j ≤ 0 from by omega)] + · rw [ite_eq_right (show ¬ j = 0 from by omega), ite_eq_right (show ¬ j = 0 from by omega), + ite_eq_right (show ¬ j ≤ 0 from by omega)] by_cases hd : j ≤ d - · rw [if_pos hd] - · rw [if_neg hd, if_neg hd] + · rw [ite_eq_left hd] + · rw [ite_eq_right hd, ite_eq_right hd] /-- No mid-clear cell at position `j ≥ 1` is the `▷` sentinel. -/ theorem clearCells_ne_start {d k j : ℕ} (hj : 1 ≤ j) : clearRegCells d k j ≠ Γ.start := by simp only [clearRegCells] - rw [if_neg (show ¬ j = 0 from by omega)] + rw [ite_eq_right (show ¬ j = 0 from by omega)] split · decide · split <;> decide @@ -552,19 +552,19 @@ theorem clearCells_update_succ (d k : ℕ) : rw [Function.update_apply] by_cases hj : j = k + 1 · subst hj - rw [if_pos rfl] + rw [ite_eq_left rfl] show Γ.blank = clearRegCells d (k + 1) (k + 1) simp only [clearRegCells] - rw [if_neg (show ¬ k + 1 = 0 from by omega), if_pos (le_refl (k + 1))] - · rw [if_neg hj] + rw [ite_eq_right (show ¬ k + 1 = 0 from by omega), ite_eq_left (le_refl (k + 1))] + · rw [ite_eq_right hj] simp only [clearRegCells] rcases Nat.eq_zero_or_pos j with rfl | hj1 · rfl · rcases Nat.lt_or_ge j (k + 1) with hlt | hge - · rw [if_neg (show ¬ j = 0 from by omega), if_neg (show ¬ j = 0 from by omega), - if_pos (show j ≤ k from by omega), if_pos (show j ≤ k + 1 from by omega)] - · rw [if_neg (show ¬ j = 0 from by omega), if_neg (show ¬ j = 0 from by omega), - if_neg (show ¬ j ≤ k from by omega), if_neg (show ¬ j ≤ k + 1 from by omega)] + · rw [ite_eq_right (show ¬ j = 0 from by omega), ite_eq_right (show ¬ j = 0 from by omega), + ite_eq_left (show j ≤ k from by omega), ite_eq_left (show j ≤ k + 1 from by omega)] + · rw [ite_eq_right (show ¬ j = 0 from by omega), ite_eq_right (show ¬ j = 0 from by omega), + ite_eq_right (show ¬ j ≤ k from by omega), ite_eq_right (show ¬ j ≤ k + 1 from by omega)] /-- **Clear register `q`**: sweep right blanking the marks, rewind to cell 1. From `regTape d` to `regTape 0` in `2d + 4` steps; every other tape untouched. -/ @@ -610,27 +610,27 @@ def clearRegTM (q : Fin n) : TM n where dsimp only [] by_cases hir : i = q · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hnone => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = q · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -657,7 +657,7 @@ private theorem clearRegTM_step_scan_one (c : Cfg n (clearRegTM (n := n) q).Q) work := Function.update c.work q (((c.work q).write Γw.blank).move .right), output := c.output } := by - rw [TM.step, if_neg (clearRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clearRegTM_ne_halt (by decide) hst)] simp only [clearRegTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -665,7 +665,7 @@ private theorem clearRegTM_step_scan_one (c : Cfg n (clearRegTM (n := n) q).Q) by_cases hir : i = q · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -678,7 +678,7 @@ private theorem clearRegTM_step_scan_blank (c : Cfg n (clearRegTM (n := n) q).Q) { state := .back, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (clearRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clearRegTM_ne_halt (by decide) hst)] simp only [clearRegTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -687,7 +687,7 @@ private theorem clearRegTM_step_scan_blank (c : Cfg n (clearRegTM (n := n) q).Q) · subst hir simp only [↓reduceIte, Function.update_self] rw [writeAndMove_readBack _ (by rw [hblank]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -700,15 +700,15 @@ private theorem clearRegTM_step_back_left (c : Cfg n (clearRegTM (n := n) q).Q) { state := .back, input := c.input, work := Function.update c.work q ((c.work q).move .left), output := c.output } := by - rw [TM.step, if_neg (clearRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clearRegTM_ne_halt (by decide) hst)] simp only [clearRegTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -725,18 +725,18 @@ private theorem clearRegTM_step_back_start (c : Cfg n (clearRegTM (n := n) q).Q) have h0 : (c.work q).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (clearRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clearRegTM_ne_halt (by decide) hst)] simp only [clearRegTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle · funext i by_cases hir : i = q · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work i).write _).move Dir3.right = (c.work i).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact (hwork i hir).writeAndMove_readBack_idle · exact hout.writeAndMove_readBack_idle @@ -746,7 +746,7 @@ private theorem clearRegTM_step_park (c : Cfg n (clearRegTM (n := n) q).Q) (hout : Parked c.output) : (clearRegTM (n := n) q).step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (clearRegTM_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clearRegTM_ne_halt (by decide) hst)] simp only [clearRegTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact hinp.move_idle @@ -775,14 +775,14 @@ private theorem clearRegTM_scan_run (d m : ℕ) : | succ m ih => intro k hk c hst hinp hwork hout hcells hhead have hone : (c.work q).read = Γ.one := by - rw [Tape.read, hhead, hcells, clearRegCells, if_neg (by omega), if_neg (by omega), - if_pos (by omega)] + rw [Tape.read, hhead, hcells, clearRegCells, ite_eq_right (by omega), ite_eq_right (by omega), + ite_eq_left (by omega)] have hstep := clearRegTM_step_scan_one c hst hone hinp hwork hout set wq₁ : Tape := ((c.work q).write Γw.blank).move .right with hwq₁ have hwq₁cells : wq₁.cells = clearRegCells d (k + 1) := by rw [hwq₁] show ((c.work q).write Γw.blank).cells = _ - rw [Tape.write, if_neg (by rw [hhead]; omega)] + rw [Tape.write, ite_eq_right (by rw [hhead]; omega)] show Function.update (c.work q).cells (c.work q).head Γw.blank.toΓ = _ rw [hhead, hcells] exact clearCells_update_succ d k diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal.lean index 060a9678..44e7d840 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal.lean @@ -323,7 +323,7 @@ theorem repeatAtTime_run_project (tm : NTM n) have hδ : tm.δ b q C.input.read (fun i => (C.work (repeatWorkIdx j i)).read) (C.work (repeatOutputIdx j)).read = (q', workWrites, outputWrite, inputDir, workDirs, outputDir) := by - simpa [r, repeatWorkReads] using hr + exact hr have hright := tm.δ_right_of_start b q C.input.read (repeatWorkReads (fun i => (C.work i).read) j) (C.work (repeatOutputIdx j)).read @@ -393,7 +393,7 @@ theorem repeatAtTime_run_padding_simulates (tm : NTM n) by_cases hzero : (C.work (repeatWorkIdx j i)).head = 0 · exact Or.inl hzero · exact Or.inr ((hinv _).read_ne_start (by omega))) - simpa only [Tape.move_cells] using hpres + simpa only [TM.readBackWrite, Γw.toΓ, Tape.move_cells] using hpres _ = (c.work i).cells := hsim.2.2.1 i · simp [NTM.trace, repeatAtTime, hstate, hq, repeatGuardTransition, repeatPaddingDirs, Tape.move_cells] @@ -404,7 +404,7 @@ theorem repeatAtTime_run_padding_simulates (tm : NTM n) by_cases hzero : (C.work (repeatOutputIdx j)).head = 0 · exact Or.inl hzero · exact Or.inr ((hinv _).read_ne_start (by omega))) - simpa only [Tape.move_cells] using hpres + simpa only [TM.readBackWrite, Γw.toΓ, Tape.move_cells] using hpres _ = c.output.cells := hsim.2.2.2.1 · intro hc exact (hc (hsim.1 ▸ hq)).elim @@ -429,7 +429,7 @@ theorem repeatAtTime_trace_run_prefix (tm : NTM n) (hT : 0 < T) C.output.StartInvariant := by induction m with | zero => - simpa [NTM.trace] using And.intro hstate + exact And.intro hstate (And.intro hsim (And.intro hinp (And.intro hwork hout))) | succ m ih => have hm' : m < T := by omega @@ -462,6 +462,7 @@ theorem repeatAtTime_trace_run_prefix (tm : NTM n) (hT : 0 < T) refine ⟨?_, hstep.2, hinv'.1, hinv'.2.1, hinv'.2.2⟩ rw [hstep.1] simp [repeatAfterRunState, hm] + rfl · have hproj := hprefix.2.1.2.2.2.2 hhalt have hstep := repeatAtTime_run_project_trace tm j ⟨m, hm'⟩ c.state votes C (g m) hprefix.1 hhalt @@ -472,6 +473,7 @@ theorem repeatAtTime_trace_run_prefix (tm : NTM n) (hT : 0 < T) hinv'.1, hinv'.2.1, hinv'.2.2⟩ rw [hstep.1] simp [repeatAfterRunState, hm, c'] + rfl /-- Exactly `T` simulation slots advance trial `j` from its initial `.run` state to rewind counter zero. The active bank agrees with the source `T`-step @@ -528,6 +530,7 @@ theorem repeatAtTime_trace_run (tm : NTM n) (hT : 0 < T) refine ⟨?_, hstep.2, hinv'.1, hinv'.2.1, hinv'.2.2⟩ rw [hstep.1] simp [repeatAfterRunState, hlast] + rfl · have hproj := hprefix.2.1.2.2.2.2 hhalt have hstep := repeatAtTime_run_project_trace tm j ⟨m, hm⟩ c.state votes C (g m) hprefix.1 hhalt diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Boundary.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Boundary.lean index 1757ac77..943d1549 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Boundary.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Boundary.lean @@ -59,8 +59,8 @@ theorem repeatPrefixChoices_succ_suffix repeatStrideChoices choices ⟨m, hm⟩ s := by apply congrArg choices apply Fin.ext - simp only [repeatPrefixIdx, Fin.val_cast, - Fin.val_natAdd, repeatAtTimeSteps, repeatStrideChoiceIdx_val] + simp only [repeatPrefixIdx, repeatAtTimeSteps, repeatStrideChoiceIdx_val] + rfl /-- Advancing one trial boundary is exactly tracing one complete stride from the preceding boundary configuration. -/ @@ -142,12 +142,11 @@ theorem repeatStrideChoices_trace_split (tm : NTM n) (repeatStrideChoices choices j) C = (repeatAtTime tm k T).trace (T + 2) (repeatAdminChoices choices j) ((repeatAtTime tm k T).trace T (repeatSimulationChoices choices j) C) := by - let M := repeatAtTime tm k T have hlen : repeatAtTimeStride T = T + (T + 2) := by simp [repeatAtTimeStride] omega - rw [M.trace_cast hlen] - rw [M.trace_add] + refine ((repeatAtTime tm k T).trace_cast hlen _ C).trans ?_ + refine ((repeatAtTime tm k T).trace_add T (T + 2) _ C).trans ?_ congr 2 /-- The administrative trace splits into `T + 1` fixed-rewind choices and one @@ -158,7 +157,7 @@ theorem repeatAdminChoices_trace_split (tm : NTM n) (repeatAtTime tm k T).trace (T + 2) (repeatAdminChoices choices j) C = (repeatAtTime tm k T).trace 1 (fun _ => repeatFinishChoice choices j) ((repeatAtTime tm k T).trace (T + 1) (repeatRewindChoices choices j) C) := by - rw [(repeatAtTime tm k T).trace_add (T + 1) 1] + refine ((repeatAtTime tm k T).trace_add (T + 1) 1 _ C).trans ?_ congr 2 · funext a apply congrArg (repeatAdminChoices choices j) @@ -175,8 +174,8 @@ theorem repeatStrideChoices_trace_split_three (tm : NTM n) (repeatAtTime tm k T).trace 1 (fun _ => repeatFinishChoice choices j) ((repeatAtTime tm k T).trace (T + 1) (repeatRewindChoices choices j) ((repeatAtTime tm k T).trace T (repeatSimulationChoices choices j) C)) := by - rw [repeatStrideChoices_trace_split] - rw [repeatAdminChoices_trace_split] + refine (repeatStrideChoices_trace_split tm choices j C).trans ?_ + exact repeatAdminChoices_trace_split tm choices j _ end NTM diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Correctness.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Correctness.lean index 68358f0f..f2e32691 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Correctness.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Correctness.lean @@ -58,7 +58,7 @@ theorem repeatAtTime_outer_correct (tm : NTM n) (x : List Bool) let j : Fin k := ⟨m, hm⟩ let C₀ := repeatBoundaryCfg tm x choices m (Nat.le_of_lt hm) have hboundary := ih (Nat.le_of_lt hm) - rw [RepeatBoundary, dif_pos hm] at hboundary + rw [RepeatBoundary, dite_eq_left hm] at hboundary obtain ⟨votes, hvotes, hstate, hproject, hframe, hparked⟩ := hboundary have hinv := (repeatAtTime tm k T).trace_initCfg_startInvariant x (repeatAtTimeSteps m T) (repeatPrefixChoices choices m (Nat.le_of_lt hm)) @@ -95,7 +95,7 @@ theorem repeatAtTime_outer_correct (tm : NTM n) (x : List Bool) rw [repeatStrideChoices_trace_split_three] rw [hstride] by_cases hnext : m + 1 < k - · rw [RepeatBoundary, dif_pos hnext] + · simp only [RepeatBoundary, dite_eq_left hnext] let votes' := Function.update votes j (repeatVotes tm x k T seed j) have hfinish := repeatAtTime_trace_finish_next tm x seed j c.state votes Cfinish finishChoices htrial.1 hnext htrial.2.1 hactiveOutput htrial.2.2.2.2.1 @@ -122,15 +122,17 @@ theorem repeatAtTime_outer_correct (tm : NTM n) (x : List Bool) repeatVotes tm x k T seed := by apply RepeatCompletedVotes.eq_expected tm x seed simpa [j, heq] using hvotes' - rw [RepeatBoundary, dif_neg] - · simpa [hvotesFull] using hfinish + simp only [RepeatBoundary] + rw [dite_eq_right] + · simp only [hvotesFull] at hfinish + exact hfinish · omega · have hk0 : k = 0 := Nat.eq_zero_of_not_pos hk subst k intro m hm have hm0 : m = 0 := by omega subst m - rw [RepeatBoundary, dif_neg (by omega)] + rw [RepeatBoundary, dite_eq_right (by omega)] have hzero := repeatAtTime_trace_zero_repetitions tm x seed choices simpa [repeatBoundaryCfg, repeatPrefixChoices_self] using ⟨hzero.1, hzero.2.1, hzero.2.2.2⟩ @@ -149,7 +151,9 @@ theorem repeatAtTime_trace_correct_internal (tm : NTM n) (x : List Bool) (blockMajority (repeatAcceptEvent tm x T) (repeatRandomSeed k T choices)) := by have houter := repeatAtTime_outer_correct tm x choices hhalt have hfinal := houter.final - simpa [repeatBoundaryCfg, repeatPrefixChoices_self, majority_repeatVotes] using hfinal + simp only [repeatBoundaryCfg, repeatPrefixChoices_self, majority_repeatVotes] + at hfinal + exact hfinal end NTM diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Parked.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Parked.lean index d8123a46..b3e8cdea 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Parked.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Parked.lean @@ -167,7 +167,7 @@ theorem RepeatOtherParked.trace_run_prefix (tm : NTM n) (hT : 0 < T) (tm.trace m (fun i => choices ⟨i.val, by omega⟩) c₀).state votes := by rw [hg] at hprefix simpa [C] using hprefix.1 - rw [(repeatAtTime tm k T).trace_add m 1] + erw [(repeatAtTime tm k T).trace_add m 1] apply RepeatOtherParked.run tm · exact ih (by omega) · exact hCstate diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Rewind.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Rewind.lean index b6bbe5ec..a4f912d3 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Rewind.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Rewind.lean @@ -177,8 +177,7 @@ theorem repeatRewindSnapshotIter_input (j : Fin k) (m : ℕ) induction m generalizing S with | zero => rfl | succ m ih => - simpa [repeatRewindSnapshotIter, repeatRewindSnapshotStep] using - ih (repeatRewindSnapshotStep j S) + exact ih (repeatRewindSnapshotStep j S) /-- Each active bank tape and flag project to the pure one-tape iterator. -/ theorem repeatRewindSnapshotIter_active (j : Fin k) (m : ℕ) @@ -189,8 +188,12 @@ theorem repeatRewindSnapshotIter_active (j : Fin k) (m : ℕ) induction m generalizing S with | zero => rfl | succ m ih => - simpa [repeatRewindSnapshotIter, repeatRewindSnapshotStep] using - ih (repeatRewindSnapshotStep j S) + have hstep : ((repeatRewindSnapshotStep j S).work (repeatTapeIdx j i), + (repeatRewindSnapshotStep j S).bankDone i) + = repeatFixedRewindTapeStep (S.work (repeatTapeIdx j i), S.bankDone i) := by + simp [repeatRewindSnapshotStep] + rw [repeatFixedRewindTapeIter, ← hstep] + exact ih (repeatRewindSnapshotStep j S) /-- Snapshot iteration preserves every inactive physical work tape exactly. -/ theorem repeatRewindSnapshotIter_inactive (j : Fin k) (m : ℕ) @@ -274,13 +277,13 @@ theorem repeatAtTime_trace_rewind_prefix (tm : NTM n) induction m with | zero => rfl | succ m ih => - rw [(repeatAtTime tm k T).trace_snoc m choices] + erw [(repeatAtTime tm k T).trace_snoc m choices] rw [ih (by omega) (fun i => choices i.castSucc)] rw [repeatAtTime_trace_one_rewind tm j ⟨m, by omega⟩ q votes (repeatRewindSnapshotIter j m S) (repeatRewindSnapshotIter_wellFormed j m S hS) (fun _ => choices (Fin.last m))] - simp only [dif_pos hm] + simp only [dite_eq_left hm] rw [repeatRewindSnapshotIter_succ_snoc] /-- Exactly `T + 1` wrapper rewind transitions produce the finish configuration @@ -293,14 +296,14 @@ theorem repeatAtTime_trace_rewind_snapshot (tm : NTM n) (repeatRewindCfg tm j ⟨0, by omega⟩ q votes S) = repeatFinishCfg tm j q votes (repeatRewindSnapshotIter j (T + 1) S) := by - rw [(repeatAtTime tm k T).trace_snoc T choices] + erw [(repeatAtTime tm k T).trace_snoc T choices] rw [repeatAtTime_trace_rewind_prefix tm j q votes S hS T (by omega) (fun i => choices i.castSucc)] rw [repeatAtTime_trace_one_rewind tm j ⟨T, by omega⟩ q votes (repeatRewindSnapshotIter j T S) (repeatRewindSnapshotIter_wellFormed j T S hS) (fun _ => choices (Fin.last T))] - rw [dif_neg (by omega : ¬(T + 1 < T + 1))] + rw [dite_eq_right (by omega : ¬(T + 1 < T + 1))] rw [repeatRewindSnapshotIter_succ_snoc] /-- **Fixed rewind correctness.** Starting from rewind counter zero with all diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Schedule.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Schedule.lean index f6f447d3..f2ae1600 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Schedule.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Schedule.lean @@ -113,6 +113,7 @@ theorem repeatSetupChoiceIdx_ne_stride (k T : ℕ) (a : Fin 2) (j : Fin k) theorem repeatStrideChoiceIdx_sim (T : ℕ) (j : Fin k) (t : Fin T) : repeatStrideChoiceIdx T j (repeatSimulationOffset T t) = repeatChoiceIdx T j t := by apply Fin.ext + rw [repeatStrideChoiceIdx_val] simp [repeatSimulationOffset, repeatAtTimeStride, repeatChoiceIdx] /-- No simulation choice is an administrative choice, even across trials. -/ @@ -260,7 +261,7 @@ theorem RepeatOuterClaim.next {tm : NTM n} {x : List Bool} RepeatOtherParked j (repeatBoundaryCfg tm x choices m (Nat.le_of_lt hm)) := by have hb := h m (Nat.le_of_lt hm) - rw [RepeatBoundary, dif_pos hm] at hb + rw [RepeatBoundary, dite_eq_left hm] at hb simpa only using hb /-- Extract the final halted majority assertion from the outer claim. -/ diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/ScheduleArithmetic.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/ScheduleArithmetic.lean index a04ebfec..71ce0abc 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/ScheduleArithmetic.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/ScheduleArithmetic.lean @@ -56,7 +56,7 @@ theorem repeatRandomSeed_apply_repeatChoiceIdx_internal (k T : ℕ) (choices : Fin (repeatAtTimeSteps k T) → Bool) (j : Fin k) (t : Fin T) : repeatRandomSeed k T choices (finProdFinEquiv (j, t)) = choices (repeatChoiceIdx T j t) := by - rw [repeatRandomSeed_apply] + erw [repeatRandomSeed_apply] congr 1 apply Fin.ext change 2 + (t.val + (2 * T + 2) * j.val) = diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Setup.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Setup.lean index c91969ef..e0e1b4be 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Setup.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Setup.lean @@ -59,17 +59,19 @@ theorem RepeatFrame.begin (tm : NTM n) (x : List Bool) have hp := repeatParked_parkedBlank have hstable := hp.writeAndMove_idle by_cases hT : 0 < T - · simpa [C, j, trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, - repeatPositionBankDirs, hk, hT, hlj] using hstable - · simpa [C, j, trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, - repeatPositionBankDirs, hk, hT, hlj] using hstable + · simp [j, trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, repeatPositionBankDirs, + hk, hT, hlj] + exact hstable + · simp [j, trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, repeatPositionBankDirs, + hk, hT, hlj] + exact hstable · have hp := repeatParked_parkedBlank have hstable := hp.writeAndMove_idle by_cases hT : 0 < T - · simpa [C, trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, - hk, hT] using hstable - · simpa [C, trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, - hk, hT] using hstable + · simp [trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, hk, hT] + exact hstable + · simp [trace, repeatAtTime, repeatParkedCfg, repeatGuardTransition, hk, hT] + exact hstable /-- With at least one trial, the full two-step setup establishes every fact needed to start the first trial and its outer-induction boundary. -/ @@ -143,7 +145,7 @@ theorem repeatAtTime_trace_setup_boundary (tm : NTM n) (x : List Bool) have h := repeatAtTime_trace_setup_ready tm x hk seed choices dsimp only at h rcases h with ⟨hvotes, hstate, hproject, _, _, _, _, _, hframe, hparked⟩ - rw [RepeatBoundary, dif_pos hk] + simp only [RepeatBoundary, dite_eq_left hk] refine ⟨fun _ => false, hvotes, hstate, hproject, ?_, ?_⟩ · exact hframe · exact hparked diff --git a/Complexitylib/Models/TuringMachine/Repetition/Internal/Trial.lean b/Complexitylib/Models/TuringMachine/Repetition/Internal/Trial.lean index baaf69e6..5b87d915 100644 --- a/Complexitylib/Models/TuringMachine/Repetition/Internal/Trial.lean +++ b/Complexitylib/Models/TuringMachine/Repetition/Internal/Trial.lean @@ -68,7 +68,7 @@ theorem RepeatFrame.trace_run_prefix (tm : NTM n) (hT : 0 < T) have hCstate : C.state = .run j ⟨m, hm'⟩ (tm.trace m (fun i => g i.val) c₀).state votes := by simpa [C] using hprefix.1 - rw [(repeatAtTime tm k T).trace_add m 1] + erw [(repeatAtTime tm k T).trace_add m 1] apply RepeatFrame.run tm · exact ih hm' · exact hCstate @@ -266,8 +266,9 @@ theorem repeatAtTime_trace_trial (tm : NTM n) (x : List Bool) simpa using hstate have hhalt' : tm.qstart = tm.qhalt := by simpa [trace] using hhalt - simpa [trace] using repeatAtTime_trace_trial_zero tm x j votes rewindChoices C₀ - hstate' hproject hinp hwork hout hinputHead hactiveHead hframe hparked hhalt' + simp [trace] + exact repeatAtTime_trace_trial_zero tm x j votes rewindChoices C₀ hstate' hproject hinp hwork + hout hinputHead hactiveHead hframe hparked hhalt' end NTM diff --git a/Complexitylib/Models/TuringMachine/SingleTape.lean b/Complexitylib/Models/TuringMachine/SingleTape.lean index b88cc0d1..ce31407d 100644 --- a/Complexitylib/Models/TuringMachine/SingleTape.lean +++ b/Complexitylib/Models/TuringMachine/SingleTape.lean @@ -100,7 +100,7 @@ theorem singleTapeSim_allPathsHaltIn {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {T : have hagree : ∀ i : Fin m, choices ⟨i.val, lt_of_lt_of_le i.isLt hle⟩ = ch i.val := by intro i simp only [hch] - rw [dif_pos (lt_of_lt_of_le i.isLt hle)] + rw [dite_eq_left (lt_of_lt_of_le i.isLt hle)] rw [(singleTapeSim N).trace_mono hle hagree hhalted] exact hhalted @@ -130,7 +130,7 @@ theorem singleTapeSim_acceptsInTime_iff {k : ℕ} (N : NTM k) (hk : 1 ≤ k) (T have hagree : ∀ i : Fin m, choices ⟨i.val, lt_of_lt_of_le i.isLt hle⟩ = ch i.val := by intro i simp only [hch] - rw [dif_pos (lt_of_lt_of_le i.isLt hle)] + rw [dite_eq_left (lt_of_lt_of_le i.isLt hle)] rw [(singleTapeSim N).trace_mono hle hagree hhalted] at hout exact ⟨fun i => SingleTape.inducedChoices k ch i.val, hhaltN, hbit.mp hout⟩ · -- forward flow: simulate the accepting `N`-run, then pad the time bound diff --git a/Complexitylib/Models/TuringMachine/SingleTape/Internal.lean b/Complexitylib/Models/TuringMachine/SingleTape/Internal.lean index 862ff1cd..ae7fbea5 100644 --- a/Complexitylib/Models/TuringMachine/SingleTape/Internal.lean +++ b/Complexitylib/Models/TuringMachine/SingleTape/Internal.lean @@ -222,7 +222,7 @@ theorem simInvAt_init (k : ℕ) : wfStart := fun _ => by simp [Tape.init] noStart := fun _ p hp => by simp only [Tape.init] - rw [if_neg (by omega : ¬ p = 0)] + rw [ite_eq_right (by omega : ¬ p = 0)] simp heads_le := fun _ => by simp [Tape.init] headBit := fun p hp1 hp0 _ => by omega @@ -230,7 +230,7 @@ theorem simInvAt_init (k : ℕ) : sentinel := fun c hc => by rw [blockStart_one] at hc simp only [Tape.init] - rw [if_neg (by omega : ¬ c = 0)] + rw [ite_eq_right (by omega : ¬ c = 0)] simp /-- `SimInvAt` depends on the encoding tape only through its cells (never its diff --git a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Correctness.lean b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Correctness.lean index 94790f86..8974a5de 100644 --- a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Correctness.lean +++ b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Correctness.lean @@ -71,11 +71,11 @@ theorem corr_init {k : ℕ} (N : NTM k) (x : List Bool) : wbeyond := fun _ p hp => by show (Tape.init []).cells p = Γ.blank simp only [Tape.init] - rw [if_neg (by omega : ¬ p = 0)] + rw [ite_eq_right (by omega : ¬ p = 0)] simp inputWf := fun p hp => by show (Tape.init (x.map Γ.ofBool)).cells p ≠ Γ.start - simp only [Tape.init, if_neg (show ¬ p = 0 by omega)] + simp only [Tape.init, ite_eq_right (show ¬ p = 0 by omega)] cases h : (List.map Γ.ofBool x)[p - 1]? with | none => decide | some g => @@ -84,7 +84,7 @@ theorem corr_init {k : ℕ} (N : NTM k) (x : List Bool) : outputWf := fun p hp => by show (Tape.init []).cells p ≠ Γ.start simp only [Tape.init] - rw [if_neg (by omega : ¬ p = 0)] + rw [ite_eq_right (by omega : ¬ p = 0)] simp /-- Writing back the read symbol preserves whether a cell holds the accept bit @@ -105,11 +105,11 @@ theorem accept_bit_preserved (t : Tape) (d : Dir3) : rw [hcells, Tape.write] by_cases hh0 : t.head = 0 · simp [hh0] - · rw [if_neg hh0] + · rw [ite_eq_right hh0] simp only [Function.update_apply] by_cases h1 : (1 : ℕ) = t.head - · rw [if_pos h1, Tape.read, ← h1, readBackWrite_one_iff] - · rw [if_neg h1] + · rw [ite_eq_left h1, Tape.read, ← h1, readBackWrite_one_iff] + · rw [ite_eq_right h1] /-- **Halt correspondence.** When `N` has halted, the simulator (parked at `run N.qhalt`) takes one step to `SimQ.halt`, preserving the accept bit. -/ @@ -161,7 +161,6 @@ theorem run_step {k : ℕ} (N : NTM k) (q : N.Q) (hq : q ≠ N.qhalt) (b : Bool) ((TM.readBackWrite ((c1.work 0).read) : Γw) : Γ) (TM.idleDir ((c1.work 0).read)), output := c1.output.writeAndMove ((TM.readBackWrite c1.output.read : Γw) : Γ) (TM.idleDir c1.output.read) } := by - rw [NTM.trace] simp only [hst, singleTapeSim, simDelta, runStep, SimQ.run, SimQ.halt, SimQ.gather, hq, reduceCtorEq, ↓reduceIte, NTM.trace] @@ -181,7 +180,6 @@ theorem commit_step {k : ℕ} (N : NTM k) (q' : N.Q) (oW : Γw) (oD iD : Dir3) output := c1.output.writeAndMove ((if oSym = Γ.start then TM.readBackWrite c1.output.read else oW : Γw) : Γ) (if oSym = Γ.start then TM.idleDir c1.output.read else safeDir c1.output.read oD) } := by - rw [NTM.trace] simp only [hst, singleTapeSim, simDelta, commitStep, SimQ.commit, SimQ.run, SimQ.halt, Sum.inr.injEq, reduceCtorEq, ↓reduceIte, NTM.trace] @@ -195,7 +193,6 @@ theorem gather_trace1 {k : ℕ} (N : NTM k) (d : GatherData k N.Q) (b : Bool) { state := r.1, input := c1.input.move r.2.2.2.1, work := fun i => (c1.work i).writeAndMove (r.2.1 i) (r.2.2.2.2.1 i), output := c1.output.writeAndMove r.2.2.1 r.2.2.2.2.2 } : Cfg 1 (SimQ k N.Q)) := by - rw [NTM.trace] simp only [hst, singleTapeSim, simDelta, SimQ.gather, SimQ.halt, Sum.inr.injEq, reduceCtorEq, ↓reduceIte, NTM.trace] @@ -316,9 +313,9 @@ private theorem commit_input_eq (t : Tape) (iD : Dir3) else safeDir (t.move (TM.idleDir t.read)).read iD) = t.move iD := by by_cases hr : t.read = Γ.start - · rw [if_pos hr, tape_idle_stay _ (move_idle_read_ne t hwf), hright hr, + · rw [ite_eq_left hr, tape_idle_stay _ (move_idle_read_ne t hwf), hright hr, TM.idleDir_right_of_start hr] - · rw [if_neg hr, tape_idle_stay t hr, + · rw [ite_eq_right hr, tape_idle_stay t hr, show safeDir t.read iD = iD from by simp only [safeDir, hr, ↓reduceIte]] /-- **COMMIT output reconciliation.** Same as `commit_input_eq` but for the output @@ -341,15 +338,15 @@ private theorem commit_output_eq (t : Tape) (oW : Γw) (oD : Dir3) = { t with head := 1 } := by rw [hr, TM.idleDir_start] show (t.write (TM.readBackWrite Γ.start).toΓ).move Dir3.right = { t with head := 1 } - rw [Tape.write, if_pos h0]; simp [Tape.move, h0] + rw [Tape.write, ite_eq_left h0]; simp [Tape.move, h0] have hr1ne : ({ t with head := 1 } : Tape).read ≠ Γ.start := by rw [Tape.read]; exact hwf 1 (le_refl 1) rw [hpr] - simp only [if_pos hr] + simp only [ite_eq_left hr] rw [tape_idle_writeMove _ hr1ne, hright hr] show ({ t with head := 1 } : Tape) = (t.write oW.toΓ).move Dir3.right - rw [Tape.write, if_pos h0]; simp [Tape.move, h0] - · simp only [if_neg hr] + rw [Tape.write, ite_eq_left h0]; simp [Tape.move, h0] + · simp only [ite_eq_right hr] rw [tape_idle_writeMove t hr, show safeDir t.read oD = oD from by simp only [safeDir, hr, ↓reduceIte]] @@ -362,6 +359,14 @@ private theorem trace_three {n : ℕ} (M : NTM n) (bb : Bool) (c : Cfg n M.Q) : simp only [] at h1 h2 rw [show (3 : ℕ) = 1 + 2 from rfl, h1, show (2 : ℕ) = 1 + 1 from rfl, h2] +/-- `trace_three'` specialised to `singleTapeSim`: the state type is stated as + `SimQ k N.Q` so that `rw` can build a type-correct motive. -/ +private theorem trace_three' {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg 1 (SimQ k N.Q)) : + (singleTapeSim N).trace 3 (fun _ => bb) c + = (singleTapeSim N).trace 1 (fun _ => bb) ((singleTapeSim N).trace 1 (fun _ => bb) + ((singleTapeSim N).trace 1 (fun _ => bb) c)) := + trace_three _ _ _ + /-- GATHER slot-`0` step (head-bit): records whether this tape's head marker is present (`rf := wH = one`), advances to slot `1`, leaves contents/heads put. -/ private theorem gather_slot0 {k : ℕ} (N : NTM k) (bb : Bool) @@ -437,6 +442,14 @@ private theorem trace_const_add {n : ℕ} (M : NTM n) (a a' : ℕ) (bb : Bool) ( have h := M.trace_add_fun a a' (fun _ => bb) c simpa using h +/-- `trace_const_add'` specialised to `singleTapeSim`: the state type is stated as + `SimQ k N.Q` so that `rw` can build a type-correct motive. -/ +private theorem trace_const_add' {k : ℕ} (N : NTM k) (a a' : ℕ) (bb : Bool) + (c : Cfg 1 (SimQ k N.Q)) : + (singleTapeSim N).trace (a + a') (fun _ => bb) c + = (singleTapeSim N).trace a' (fun _ => bb) ((singleTapeSim N).trace a (fun _ => bb) c) := + trace_const_add _ _ _ _ _ + /-- One gather **triple** (`trace 3`): starting at slot `0` of tape `j`'s triple in the encoded region (work head at `h`), three GATHER steps read the head-bit (`cells h`), sym-hi (`cells (h+1)`), and sym-lo (`cells (h+2)`) cells, advance @@ -483,8 +496,9 @@ theorem gather_triple {k : ℕ} (N : NTM k) (bb : Bool) ((singleTapeSim N).trace 1 (fun _ => bb) ((singleTapeSim N).trace 1 (fun _ => bb) c1)) (by rw [e1]) (by rw [e1, e0]; exact hb2) (by rw [e1, e0]; exact hs2) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] - simp only [Tape.read, decide_eq_true_eq, dif_pos hj]; rfl + rw [trace_three', e2, e1, e0] + simp only [Tape.read, dite_eq_left hj] + by_cases hone : (c1.work 0).cells (c1.work 0).head = Γ.one <;> simp [hone] /-- **GATHER one block (`trace (3*m)`).** Sweeping the `k`-tape block `b` (`1 ≤ b ≤ M`) starting at tape `0`, slot `0` (work head at `blockStart k b`): after @@ -542,12 +556,12 @@ private theorem gather_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. exact hsym.2 refine ⟨decide ((c1.work 0).cells (blockStart k b + 3 * m) = Γ.one), (c1.work 0).cells (blockStart k b + 3 * m + 1), ?_⟩ - rw [show 3 * (m + 1) = 3 * m + 3 from by omega, trace_const_add, + erw [show 3 * (m + 1) = 3 * m + 3 from by omega, trace_const_add', gather_triple N bb q (fun j => if ↑j < m ∧ (c.work j).head = b then (c.work j).read else acc₀ j) iSym oSym rfm pendingm m hmk ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1) - (by rw [hmeq]; simp only [if_pos hmk]) + (by rw [hmeq]; simp only [ite_eq_left hmk]) (by rw [hmeq]; exact his) (by rw [hmeq]; exact hos) (by @@ -590,7 +604,7 @@ private theorem gather_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. · subst hjm by_cases hb : (c.work ⟨m, hmk⟩).head = b · simp only [hb, ↓reduceIte, Function.update_self, and_true] - rw [if_pos (Nat.lt_succ_self m), Tape.read, hb] + rw [ite_eq_left (Nat.lt_succ_self m), Tape.read, hb] · simp only [hb, ↓reduceIte, reduceCtorEq, Nat.lt_irrefl, and_false] · have hjv : (j : ℕ) ≠ m := fun h => hjm (Fin.ext h) by_cases hjb : (c.work j).head = b @@ -636,7 +650,7 @@ private theorem gather_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. refine (Cfg.mk.injEq ..).mpr ⟨?_, rfl, ?_, rfl⟩ · congr 3 funext j - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] · funext x obtain rfl : x = 0 := Subsingleton.elim x 0 show cwk 0 = { cwk 0 with head := blockStart k 1 } @@ -649,8 +663,8 @@ private theorem gather_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. (by rw [hBeq]) (by rw [hBeq]) (by rw [hBeq]; exact hinv.cells_congr rfl) (by rw [hBeq]; exact his) (by rw [hBeq]; exact hos) k (le_refl k) refine ⟨rf', pending', ?_⟩ - rw [show 3 * k * (B + 1) = 3 * k * B + 3 * k from Nat.mul_succ (3 * k) B, - trace_const_add, hstep, hBeq] + erw [show 3 * k * (B + 1) = 3 * k * B + 3 * k from Nat.mul_succ (3 * k) B, + trace_const_add', hstep, hBeq] dsimp only simp only [lt_self_iff_false, ↓reduceIte] rw [blockStart_succ k (B + 1) (by omega), blockWidth] @@ -660,11 +674,11 @@ private theorem gather_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. simp only [j.isLt, true_and] by_cases hjb : (c.work j).head = B + 1 · simp only [hjb, ↓reduceIte, le_refl, and_true] - rw [if_pos (by omega)] - · rw [if_neg hjb] + rw [ite_eq_left (by omega)] + · rw [ite_eq_right hjb] by_cases hr : 1 ≤ (c.work j).head ∧ (c.work j).head ≤ B - · rw [if_pos hr, if_pos (by omega)] - · rw [if_neg hr, if_neg (by omega)] + · rw [ite_eq_left hr, ite_eq_left (by omega)] + · rw [ite_eq_right hr, ite_eq_right (by omega)] /-- One **GATHER sentinel** step (`trace 1`): reading the `□` that ends the used region fires `N.δ` (the one meaningful use of the choice `bb`) and hands the @@ -781,8 +795,8 @@ theorem gather_acc_eq {k : ℕ} {t : Tape} {w : Fin k → Tape} {M : ℕ} = (fun j : Fin k => (w j).read) := by funext j by_cases h1 : 1 ≤ (w j).head - · rw [if_pos ⟨h1, hinv.heads_le j⟩] - · rw [if_neg (fun h => h1 h.1), hinv.read_eq_start_of_head_eq_zero j (by omega)] + · rw [ite_eq_left ⟨h1, hinv.heads_le j⟩] + · rw [ite_eq_right (fun h => h1 h.1), hinv.read_eq_start_of_head_eq_zero j (by omega)] /-- One **rewind** step (`trace 1`): from a `rewind d` config, the result is the configuration built from `rewindStep`'s output. Basis of the rewind sweep. -/ @@ -793,7 +807,6 @@ theorem rewind_trace1 {k : ℕ} (N : NTM k) (d : RewindData k N.Q) (b : Bool) { state := r.1, input := c1.input.move r.2.2.2.1, work := fun i => (c1.work i).writeAndMove (r.2.1 i) (r.2.2.2.2.1 i), output := c1.output.writeAndMove r.2.2.1 r.2.2.2.2.2 } : Cfg 1 (SimQ k N.Q)) := by - rw [NTM.trace] simp only [hst, singleTapeSim, simDelta, SimQ.rewind, SimQ.halt, Sum.inr.injEq, reduceCtorEq, ↓reduceIte, NTM.trace] @@ -840,7 +853,7 @@ theorem rewind_sweep {k : ℕ} (N : NTM k) (bb : Bool) congr 1 funext x; obtain rfl : x = 0 := Subsingleton.elim x 0 exact work_rewind_step (c1.work 0) hread - rw [show p + 1 + 1 = 1 + (p + 1) from by omega, trace_const_add, e1] + erw [show p + 1 + 1 = 1 + (p + 1) from by omega, trace_const_add', e1] exact ih _ rfl (by simp [hhead]) hcell0 (fun p' hp1 hp2 => hne p' hp1 (by omega)) his hos @@ -935,7 +948,7 @@ theorem scatterInterWork_cells_ne_start (ct : Tape) (wd : Γw × Dir3) {p : ℕ} · rw [hph] show (ct.write wd.1.toΓ).cells ct.head ≠ Γ.start unfold Tape.write - rw [if_neg (show ¬ ct.head = 0 by omega)] + rw [ite_eq_right (show ¬ ct.head = 0 by omega)] show Function.update ct.cells ct.head wd.1.toΓ ct.head ≠ Γ.start rw [Function.update_self] cases wd.1 <;> decide @@ -963,7 +976,7 @@ theorem scatterInterWork_cells_at_head (ct : Tape) (wd : Γw × Dir3) (hh : 1 ≤ ct.head) : (scatterInterWork ct wd).cells ct.head = wd.1.toΓ := by show (ct.write wd.1.toΓ).cells ct.head = wd.1.toΓ unfold Tape.write - rw [if_neg (show ¬ ct.head = 0 by omega)] + rw [ite_eq_right (show ¬ ct.head = 0 by omega)] show Function.update ct.cells ct.head wd.1.toΓ ct.head = wd.1.toΓ rw [Function.update_self] @@ -1519,7 +1532,6 @@ theorem scatter1_trace1 {k : ℕ} (N : NTM k) (d : Scatter1Data k N.Q) (b : Bool { state := r.1, input := c1.input.move r.2.2.2.1, work := fun i => (c1.work i).writeAndMove (r.2.1 i) (r.2.2.2.2.1 i), output := c1.output.writeAndMove r.2.2.1 r.2.2.2.2.2 } : Cfg 1 (SimQ k N.Q)) := by - rw [NTM.trace] simp only [hst, singleTapeSim, simDelta, SimQ.scatter1, SimQ.halt, Sum.inr.injEq, reduceCtorEq, ↓reduceIte, NTM.trace] @@ -1543,7 +1555,7 @@ theorem scatter1_step_right {k : ℕ} (N : NTM k) (d : Scatter1Data k N.Q) (b : = fun _ => Dir3.right := by funext i show (if (c1.work 0).read = Γ.blank ∧ _ then Dir3.left else Dir3.right) = Dir3.right - rw [if_neg (fun h => hwb h.1)] + rw [ite_eq_right (fun h => hwb h.1)] simp only [show (scatter1Step d c1.input.read ((c1.work 0).read) c1.output.read).2.2.2.1 = TM.idleDir c1.input.read from rfl, show (scatter1Step d c1.input.read ((c1.work 0).read) c1.output.read).2.2.1 @@ -1581,7 +1593,7 @@ theorem scatter1_materialize {k : ℕ} (N : NTM k) (b : Bool) (q' : N.Q) funext i show (if (c1.work 0).read = Γ.blank ∧ mat = true ∧ pos = (0, 0) then Dir3.left else Dir3.right) = Dir3.right - rw [if_neg (fun h => hnt h.2)] + rw [ite_eq_right (fun h => hnt h.2)] simp only [show (scatter1Step (q', wact, oWoD, iD, iSym, oSym, pos, rightCarry, isLeftMover, writeFlag, mat) c1.input.read ((c1.work 0).read) c1.output.read).2.2.2.1 @@ -1595,6 +1607,7 @@ theorem scatter1_materialize {k : ℕ} (N : NTM k) (b : Bool) (q' : N.Q) c1.input.read ((c1.work 0).read) c1.output.read).2.2.2.2.2 = TM.idleDir c1.output.read from rfl, hwd, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] + rfl /-- SCATTER sweep-1 **materialize slot-0** step: at the `□` sentinel, slot `0` of a fresh block-tape, deposit the head-bit (`one` if `rightCarry t`, else `zero`), @@ -1617,7 +1630,8 @@ theorem scatter1_mat_slot0 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) output := c1.output } := by rw [scatter1_materialize N bb q' wact oWoD iD iSym oSym (⟨t, by omega⟩, 0) rc ilm false mat c1 hst hnt his hos] - simp only [scatter1Step, hblank, ↓reduceIte, if_neg hnt, dif_pos ht, advanceSweep, Fin.reduceEq, + simp only [scatter1Step, hblank, ↓reduceIte, ite_eq_right hnt, dite_eq_left ht, advanceSweep, + Fin.reduceEq, Fin.isValue] congr 1 funext i @@ -1696,7 +1710,7 @@ theorem scatter1_mat_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [Function.update_of_ne (by omega), Function.update_of_ne (by omega)]; exact hb2) (by rw [e1, e0]; show 1 ≤ (c1.work 0).head + 1 + 1; omega) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] simp only [advanceSweep, Fin.isValue, ↓reduceIte] /-- SCATTER sweep-1 **materialize sweep** (`trace (3*m)`): materialize the first @@ -1755,7 +1769,7 @@ private theorem scatter1_mat_aux {k : ℕ} (N : NTM k) (bb : Bool) (M : ℕ) (q' = SimQ.scatter1 (q', wact, oWoD, iD, iSym, oSym, (⟨m, by omega⟩, 0), (fun j => if (j : ℕ) < m then false else rc j), ilm, false, if m = 0 then false else true) := by - rw [htm]; simp only [if_pos hmk] + rw [htm]; simp only [ite_eq_left hmk]; rfl have hcw : ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).work 0 = wtm := by rw [htm] have hcis : ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).input.read ≠ Γ.start := by rw [show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).input = c1.input from by rw [htm]] @@ -1766,37 +1780,38 @@ private theorem scatter1_mat_aux {k : ℕ} (N : NTM k) (bb : Bool) (M : ℕ) (q' exact hos have hrcm : (fun (j : Fin k) => if (j : ℕ) < m then false else rc j) ⟨m, hmk⟩ = rc ⟨m, hmk⟩ := by - simp only [lt_irrefl, if_false] + simp only [lt_irrefl, ite_false] have hnt : ¬((if m = 0 then false else true) = true ∧ ((⟨m, by omega⟩, 0) : SweepPos k) = (0, 0)) := by rintro ⟨hmat', hpos⟩ have : m = 0 := by - by_contra h; rw [if_neg h] at hmat' + by_contra h; rw [ite_eq_right h] at hmat' exact absurd (congrArg (fun p => (Prod.fst p).val) hpos) (by simp [h]) simp [this] at hmat' have htr := scatter1_mat_triple N bb q' wact oWoD iD iSym oSym m hmk (fun j => if (j : ℕ) < m then false else rc j) ilm (if m = 0 then false else true) ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1) hcs (by rw [hcw]; exact hh) (by rw [hcw]; exact hb0) (by rw [hcw]; exact hb1) (by rw [hcw]; exact hb2) hnt hcis hcos - rw [hcw, hrcm] at htr + erw [hcw] at htr + simp only [hrcm] at htr refine ⟨⟨wtm.head + 3, Function.update (Function.update (Function.update wtm.cells wtm.head (if rc ⟨m, hmk⟩ then Γw.one else Γw.zero).toΓ) (wtm.head + 1) Γw.zero.toΓ) (wtm.head + 2) Γw.zero.toΓ⟩, ?_, ?_, ?_, ?_, ?_⟩ - · rw [show 3 * (m + 1) = 3 * m + 3 from Nat.mul_succ 3 m, trace_const_add, htr, + · erw [show 3 * (m + 1) = 3 * m + 3 from Nat.mul_succ 3 m, trace_const_add', htr, show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).input = c1.input from by rw [htm], show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).output = c1.output from by rw [htm]] refine (Cfg.mk.injEq ..).mpr ⟨?_, rfl, rfl, rfl⟩ - rw [show (if m + 1 = 0 then false else true) = true from if_neg (by omega), + rw [show (if m + 1 = 0 then false else true) = true from ite_eq_right (by omega), show Function.update (fun (j : Fin k) => if (j : ℕ) < m then false else rc j) ⟨m, hmk⟩ false = (fun (j : Fin k) => if (j : ℕ) < m + 1 then false else rc j) from by funext j by_cases hj : j = ⟨m, hmk⟩ - · subst hj; rw [Function.update_self]; simp only [Nat.lt_succ_self, if_true] + · subst hj; rw [Function.update_self]; simp only [Nat.lt_succ_self, ite_true] · rw [Function.update_of_ne hj] have hjm : (j : ℕ) ≠ m := fun h => hj (Fin.ext h) by_cases hlt : (j : ℕ) < m - · simp only [if_pos hlt, if_pos (show (j : ℕ) < m + 1 by omega)] - · simp only [if_neg hlt, if_neg (show ¬ (j : ℕ) < m + 1 by omega)]] + · simp only [ite_eq_left hlt, ite_eq_left (show (j : ℕ) < m + 1 by omega)] + · simp only [ite_eq_right hlt, ite_eq_right (show ¬ (j : ℕ) < m + 1 by omega)]] · show wtm.head + 3 = blockStart k (M + 1) + 3 * (m + 1) rw [hwhm]; omega · intro cc hcc @@ -1877,7 +1892,7 @@ theorem scatter1_nohead_slot0 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 0), rc, ilm, false, mat) bb c1 hst] simp only [scatter1Step, hz, reduceCtorEq, ↓reduceIte, advanceSweep, Fin.reduceEq, Fin.reduceAdd, - dif_pos hj, hrc, Bool.false_eq_true, false_and, tape_idle_stay c1.input his, + dite_eq_left hj, hrc, Bool.false_eq_true, false_and, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -1942,7 +1957,7 @@ theorem scatter1_nohead_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (by rw [e1]; simp only [advanceSweep, Fin.reduceEq, Fin.reduceAdd, ↓reduceIte]) (by rw [e1, e0]; exact hb2) (by rw [e1, e0]; exact hs2) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] simp only [advanceSweep, ↓reduceIte] /-- SCATTER sweep-1 **head slot-0, stay** step: at a head-bit cell with a head @@ -1964,7 +1979,7 @@ theorem scatter1_head_slot0_stay {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 0), rc, ilm, wf, mat) bb c1 hst] simp only [scatter1Step, hone, reduceCtorEq, ↓reduceIte, advanceSweep, Fin.reduceEq, - Fin.reduceAdd, dif_pos hj, hstay, tape_idle_stay c1.input his, + Fin.reduceAdd, dite_eq_left hj, hstay, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -1990,7 +2005,7 @@ theorem scatter1_head_slot0_left {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 0), rc, ilm, wf, mat) bb c1 hst] simp only [scatter1Step, hone, reduceCtorEq, ↓reduceIte, advanceSweep, Fin.reduceEq, - Fin.reduceAdd, dif_pos hj, hleft, tape_idle_stay c1.input his, + Fin.reduceAdd, dite_eq_left hj, hleft, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -2018,7 +2033,7 @@ theorem scatter1_head_slot0_right {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 0), rc, ilm, wf, mat) bb c1 hst] simp only [scatter1Step, hone, reduceCtorEq, ↓reduceIte, advanceSweep, Fin.reduceEq, - Fin.reduceAdd, dif_pos hj, hright, tape_idle_stay c1.input his, + Fin.reduceAdd, dite_eq_left hj, hright, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -2044,7 +2059,7 @@ theorem scatter1_head_sym1 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 1), rc, ilm, true, mat) bb c1 hst] simp only [scatter1Step, hwb, ↓reduceIte, advanceSweep, Fin.reduceEq, Fin.reduceAdd, - dif_pos hj, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] + dite_eq_left hj, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x obtain rfl : x = 0 := Subsingleton.elim x 0 @@ -2070,7 +2085,7 @@ theorem scatter1_head_sym2 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 2), rc, ilm, true, mat) bb c1 hst] simp only [scatter1Step, hwb, ↓reduceIte, advanceSweep, Fin.reduceEq, - dif_pos hj, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] + dite_eq_left hj, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x obtain rfl : x = 0 := Subsingleton.elim x 0 @@ -2110,7 +2125,7 @@ theorem scatter1_head_stay_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (by rw [e1, e0]; simp only [Tape.read]; rw [Function.update_of_ne (by omega)]; exact hb2) (by rw [e1, e0]; show 1 ≤ (c1.work 0).head + 1 + 1; omega) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] /-- SCATTER sweep-1 **head left triple** (`trace 3`): like the stay triple (writes the new symbol, keeps the head-bit here), but records the tape in `isLeftMover` @@ -2148,7 +2163,7 @@ theorem scatter1_head_left_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (by rw [e1, e0]; simp only [Tape.read]; rw [Function.update_of_ne (by omega)]; exact hb2) (by rw [e1, e0]; show 1 ≤ (c1.work 0).head + 1 + 1; omega) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] /-- SCATTER sweep-1 **head right triple** (`trace 3`): a head moving right clears its head-bit here (`zero`), writes its new symbol into the two symbol cells, and @@ -2190,7 +2205,7 @@ theorem scatter1_head_right_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [Function.update_of_ne (by omega), Function.update_of_ne (by omega)]; exact hb2) (by rw [e1, e0]; show 1 ≤ (c1.work 0).head + 1 + 1; omega) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] /-- SCATTER sweep-1 **deposit slot-0** step: at a head-bit cell with no head (`wH = zero`) but an incoming carry (`rc t = true` — a head moved right into @@ -2213,7 +2228,7 @@ theorem scatter1_deposit_slot0 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) rw [scatter1_trace1 N (q', wact, oWoD, iD, iSym, oSym, (⟨j, by omega⟩, 0), rc, ilm, false, mat) bb c1 hst] simp only [scatter1Step, hz, reduceCtorEq, ↓reduceIte, advanceSweep, Fin.reduceEq, - Fin.reduceAdd, dif_pos hj, hrc, tape_idle_stay c1.input his, + Fin.reduceAdd, dite_eq_left hj, hrc, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -2258,7 +2273,7 @@ theorem scatter1_deposit_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (by rw [e1, e0]; simp only [Tape.read]; rw [Function.update_of_ne (by omega)]; exact hb2) (by rw [e1, e0]; simp only [Tape.read]; rw [Function.update_of_ne (by omega)]; exact hs2) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] simp only [advanceSweep, ↓reduceIte] /-- The **SCATTER sweep-1 → sweep-2 turn-around** (`trace 1`): once the freshly @@ -2322,7 +2337,7 @@ theorem scatter1_tape_nohead {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) ( scatterInterWork_cells_of_ne (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩) (Ne.symm hhd) have htriple := scatter1_nohead_triple N bb q' wact oWoD iD iSym oSym m hmk rc ilm false c1 hst hrcf - (by rw [hhead]; exact hot.1.trans (if_neg hhd)) + (by rw [hhead]; exact hot.1.trans (ite_eq_right hhd)) (by rw [hhead, ← hsym, hot.2.1]; exact (encSymΓ_ne_blank _).1) (by rw [hhead, ← hsym2, hot.2.2]; exact (encSymΓ_ne_blank _).2) (by rw [hhead, ← hsym, hot.2.1]; exact (encSymΓ_ne_start _).1) @@ -2333,7 +2348,7 @@ theorem scatter1_tape_nohead {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) ( rw [hhead] · apply scatter1_blockinv_step hb1 hbM hmk hbm · show (c1.work 0).cells (headBitCell k b ⟨m, hmk⟩) = _ - rw [hot.1, if_neg hhd, if_neg hscat] + rw [hot.1, ite_eq_right hhd, ite_eq_right hscat] · show (c1.work 0).cells (symCell k b ⟨m, hmk⟩) = _ rw [hcb]; exact hot.2.1 · show (c1.work 0).cells (symCell k b ⟨m, hmk⟩ + 1) = _ @@ -2376,12 +2391,12 @@ theorem scatter1_tape_deposit {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) have hh1 : 1 ≤ (c1.work 0).head := by rw [hhead]; simp only [headBitCell]; have := one_le_blockStart k b; omega have hscat : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).head = b := by - rw [scatterInterWork_head, if_pos hdr]; omega + rw [scatterInterWork_head, ite_eq_left hdr]; omega have hcb : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).cells b = (c.work ⟨m, hmk⟩).cells b := scatterInterWork_cells_of_ne (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩) (Ne.symm hhd) have htriple := scatter1_deposit_triple N bb q' wact oWoD iD iSym oSym m hmk rc ilm false c1 hst - (by rw [hhead]; exact hot.1.trans (if_neg hhd)) + (by rw [hhead]; exact hot.1.trans (ite_eq_right hhd)) hrc hh1 (by rw [hhead, ← hsym, hot.2.1]; exact (encSymΓ_ne_blank _).1) (by rw [hhead, ← hsym2, hot.2.2]; exact (encSymΓ_ne_blank _).2) @@ -2395,7 +2410,7 @@ theorem scatter1_tape_deposit {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) · apply scatter1_blockinv_step hb1 hbM hmk hbm · show Function.update (c1.work 0).cells (c1.work 0).head Γw.one.toΓ (headBitCell k b ⟨m, hmk⟩) = _ - rw [← hhead, Function.update_self, if_pos hscat]; rfl + rw [← hhead, Function.update_self, ite_eq_left hscat]; rfl · show Function.update (c1.work 0).cells (c1.work 0).head Γw.one.toΓ (symCell k b ⟨m, hmk⟩) = _ rw [Function.update_of_ne (by rw [hhead]; simp only [symCell, headBitCell]; omega), hcb] @@ -2440,13 +2455,14 @@ theorem scatter1_tape_head_stay {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q have hh1 : 1 ≤ (c1.work 0).head := by rw [hhead]; simp only [headBitCell]; have := one_le_blockStart k b; omega have hscat : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).head = b := by - rw [scatterInterWork_head, if_neg (show ¬ (wact ⟨m, hmk⟩).2 = Dir3.right by rw [hstay]; decide)] + rw [scatterInterWork_head, + ite_eq_right (show ¬ (wact ⟨m, hmk⟩).2 = Dir3.right by rw [hstay]; decide)] exact hhdb have hcbh : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).cells b = (wact ⟨m, hmk⟩).1.toΓ := by rw [← hhdb]; exact scatterInterWork_cells_at_head (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩) (by omega) have htriple := scatter1_head_stay_triple N bb q' wact oWoD iD iSym oSym m hmk rc ilm false c1 hst - (by rw [hhead]; exact hot.1.trans (if_pos hhdb)) + (by rw [hhead]; exact hot.1.trans (ite_eq_left hhdb)) hstay hh1 (by rw [hhead, ← hsym, hot.2.1]; exact (encSymΓ_ne_blank _).1) (by rw [hhead, ← hsym2, hot.2.2]; exact (encSymΓ_ne_blank _).2) @@ -2462,7 +2478,7 @@ theorem scatter1_tape_head_stay {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q (headBitCell k b ⟨m, hmk⟩) = _ rw [Function.update_of_ne (by rw [hhead]; omega), Function.update_of_ne (by rw [hhead]; omega), - hot.1, if_pos hhdb, if_pos hscat] + hot.1, ite_eq_left hhdb, ite_eq_left hscat] · show Function.update (Function.update (c1.work 0).cells _ _) _ _ (symCell k b ⟨m, hmk⟩) = _ rw [show symCell k b ⟨m, hmk⟩ = (c1.work 0).head + 1 by rw [hsym, hhead], Function.update_of_ne (by omega), Function.update_self, hcbh] @@ -2508,13 +2524,14 @@ theorem scatter1_tape_head_left {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q have hh1 : 1 ≤ (c1.work 0).head := by rw [hhead]; simp only [headBitCell]; have := one_le_blockStart k b; omega have hscat : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).head = b := by - rw [scatterInterWork_head, if_neg (show ¬ (wact ⟨m, hmk⟩).2 = Dir3.right by rw [hleft]; decide)] + rw [scatterInterWork_head, + ite_eq_right (show ¬ (wact ⟨m, hmk⟩).2 = Dir3.right by rw [hleft]; decide)] exact hhdb have hcbh : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).cells b = (wact ⟨m, hmk⟩).1.toΓ := by rw [← hhdb]; exact scatterInterWork_cells_at_head (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩) (by omega) have htriple := scatter1_head_left_triple N bb q' wact oWoD iD iSym oSym m hmk rc ilm false c1 hst - (by rw [hhead]; exact hot.1.trans (if_pos hhdb)) + (by rw [hhead]; exact hot.1.trans (ite_eq_left hhdb)) hleft hh1 (by rw [hhead, ← hsym, hot.2.1]; exact (encSymΓ_ne_blank _).1) (by rw [hhead, ← hsym2, hot.2.2]; exact (encSymΓ_ne_blank _).2) @@ -2530,7 +2547,7 @@ theorem scatter1_tape_head_left {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q (headBitCell k b ⟨m, hmk⟩) = _ rw [Function.update_of_ne (by rw [hhead]; omega), Function.update_of_ne (by rw [hhead]; omega), - hot.1, if_pos hhdb, if_pos hscat] + hot.1, ite_eq_left hhdb, ite_eq_left hscat] · show Function.update (Function.update (c1.work 0).cells _ _) _ _ (symCell k b ⟨m, hmk⟩) = _ rw [show symCell k b ⟨m, hmk⟩ = (c1.work 0).head + 1 by rw [hsym, hhead], Function.update_of_ne (by omega), Function.update_self, hcbh] @@ -2577,13 +2594,13 @@ theorem scatter1_tape_head_right {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. have hh1 : 1 ≤ (c1.work 0).head := by rw [hhead]; simp only [headBitCell]; have := one_le_blockStart k b; omega have hscat : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).head ≠ b := by - rw [scatterInterWork_head, if_pos hright]; omega + rw [scatterInterWork_head, ite_eq_left hright]; omega have hcbh : (scatterInterWork (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩)).cells b = (wact ⟨m, hmk⟩).1.toΓ := by rw [← hhdb]; exact scatterInterWork_cells_at_head (c.work ⟨m, hmk⟩) (wact ⟨m, hmk⟩) (by omega) have htriple := scatter1_head_right_triple N bb q' wact oWoD iD iSym oSym m hmk rc ilm false c1 hst - (by rw [hhead]; exact hot.1.trans (if_pos hhdb)) + (by rw [hhead]; exact hot.1.trans (ite_eq_left hhdb)) hright hh1 (by rw [hhead, ← hsym, hot.2.1]; exact (encSymΓ_ne_blank _).1) (by rw [hhead, ← hsym2, hot.2.2]; exact (encSymΓ_ne_blank _).2) @@ -2600,7 +2617,7 @@ theorem scatter1_tape_head_right {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N. (headBitCell k b ⟨m, hmk⟩) = _ rw [Function.update_of_ne (by rw [hhead]; omega), Function.update_of_ne (by rw [hhead]; omega), - ← hhead, Function.update_self, if_neg hscat]; rfl + ← hhead, Function.update_self, ite_eq_right hscat]; rfl · show Function.update (Function.update (Function.update (c1.work 0).cells _ _) _ _) _ _ (symCell k b ⟨m, hmk⟩) = _ rw [show symCell k b ⟨m, hmk⟩ = (c1.work 0).head + 1 by rw [hsym, hhead], @@ -2682,12 +2699,12 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k (decide ((c.work ⟨m, hmk⟩).head = b ∧ (wact ⟨m, hmk⟩).2 = Dir3.right)) := by funext j by_cases hj : j = ⟨m, hmk⟩ - · subst hj; rw [Function.update_self]; simp only [Nat.lt_succ_self, if_true] + · subst hj; rw [Function.update_self]; simp only [Nat.lt_succ_self, ite_true] · rw [Function.update_of_ne hj, hRCm] have hjm : (j : ℕ) ≠ m := fun h => hj (Fin.ext h) by_cases hlt : (j : ℕ) < m - · simp only [if_pos hlt, if_pos (show (j : ℕ) < m + 1 by omega)] - · simp only [if_neg hlt, if_neg (show ¬ (j : ℕ) < m + 1 by omega)] + · simp only [ite_eq_left hlt, ite_eq_left (show (j : ℕ) < m + 1 by omega)] + · simp only [ite_eq_right hlt, ite_eq_right (show ¬ (j : ℕ) < m + 1 by omega)] have hstep_ilm : (fun (j : Fin k) => if (j : ℕ) < m + 1 ∧ (c.work j).head = b ∧ (wact j).2 = Dir3.left then true else ilm_in j) @@ -2705,14 +2722,14 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k simp only [hiff] -- ILMm at slot m collapses to the incoming ilm_in have hILMm_at : ILMm ⟨m, hmk⟩ = ilm_in ⟨m, hmk⟩ := by - rw [hILMm]; simp only [lt_irrefl, false_and, if_false] + rw [hILMm]; simp only [lt_irrefl, false_and, ite_false] have hRCm_at : RCm ⟨m, hmk⟩ = rc_in ⟨m, hmk⟩ := by - rw [hRCm]; simp only [lt_irrefl, if_false] + rw [hRCm]; simp only [lt_irrefl, ite_false] -- facts about the IH config cM = trace (3*m) c1 have hcs : ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).state = SimQ.scatter1 (q', wact, oWoD, iD, iSym, oSym, (⟨m, by omega⟩, 0), RCm, ILMm, false, false) := by - rw [htm]; simp only [if_pos hmk] + rw [htm]; simp only [ite_eq_left hmk]; rfl have hch : (((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).work 0).head = headBitCell k b ⟨m, hmk⟩ := by rw [show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).work 0 = wtm @@ -2729,7 +2746,7 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k rw [show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).output = c1.output from by rw [htm]] exact hos - -- assembly closure (the trace_const_add + input/output reconciliation, done once) + -- assembly closure (the trace_const_add' + input/output reconciliation, done once) have key : ∀ (wt : Tape) (rc' ilm' : Fin k → Bool), (singleTapeSim N).trace 3 (fun _ => bb) ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1) @@ -2759,7 +2776,7 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k ∧ Scatter1BlockInv wt' c.work wact M b (m + 1) := by intro wt rc' ilm' htr hrc hilm hwh hbi refine ⟨wt, ?_, ?_, hbi⟩ - · rw [show 3 * (m + 1) = 3 * m + 3 from by omega, trace_const_add, htr, hrc, hilm, + · erw [show 3 * (m + 1) = 3 * m + 3 from by omega, trace_const_add', htr, hrc, hilm, show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).input = c1.input from by rw [htm], show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).output = c1.output from by rw [htm]] @@ -2780,13 +2797,14 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k rw [hRCm_at, hrc_in, decide_eq_false (fun h => by rw [h3] at h; exact absurd h.2 (by decide)), decide_eq_false (hndep_of_eq hhd)], Function.update_eq_self] - · rw [hstep_ilm, if_pos ⟨hhd, h3⟩] + · rw [hstep_ilm, ite_eq_left ⟨hhd, h3⟩] · -- right obtain ⟨wt, htr, hwh, hbi⟩ := scatter1_tape_head_right N bb c b M hb1 hbM m hmk q' wact oWoD iD iSym oSym RCm ILMm _ hcs hch hcbi hhd h3 hcis hcos refine key wt (Function.update RCm ⟨m, hmk⟩ true) ILMm htr ?_ ?_ hwh hbi · rw [hstep_rc, decide_eq_true ⟨hhd, h3⟩] - · rw [hstep_ilm, if_neg (show ¬((c.work ⟨m, hmk⟩).head = b ∧ (wact ⟨m, hmk⟩).2 = Dir3.left) + · rw [hstep_ilm, + ite_eq_right (show ¬((c.work ⟨m, hmk⟩).head = b ∧ (wact ⟨m, hmk⟩).2 = Dir3.left) from fun h => by rw [h3] at h; exact absurd h.2 (by decide)), ← hILMm_at, Function.update_eq_self] · -- stay @@ -2798,7 +2816,8 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k rw [hRCm_at, hrc_in, decide_eq_false (fun h => by rw [h3] at h; exact absurd h.2 (by decide)), decide_eq_false (hndep_of_eq hhd)], Function.update_eq_self] - · rw [hstep_ilm, if_neg (show ¬((c.work ⟨m, hmk⟩).head = b ∧ (wact ⟨m, hmk⟩).2 = Dir3.left) + · rw [hstep_ilm, + ite_eq_right (show ¬((c.work ⟨m, hmk⟩).head = b ∧ (wact ⟨m, hmk⟩).2 = Dir3.left) from fun h => by rw [h3] at h; exact absurd h.2 (by decide)), ← hILMm_at, Function.update_eq_self] · by_cases hdep : (c.work ⟨m, hmk⟩).head = b - 1 ∧ (wact ⟨m, hmk⟩).2 = Dir3.right @@ -2809,7 +2828,8 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k refine key wt (Function.update RCm ⟨m, hmk⟩ false) ILMm htr ?_ ?_ hwh hbi · rw [hstep_rc, decide_eq_false (show ¬((c.work ⟨m, hmk⟩).head = b ∧ _) from fun h => hhd h.1)] - · rw [hstep_ilm, if_neg (show ¬((c.work ⟨m, hmk⟩).head = b ∧ _) from fun h => hhd h.1), + · rw [hstep_ilm, + ite_eq_right (show ¬((c.work ⟨m, hmk⟩).head = b ∧ _) from fun h => hhd h.1), ← hILMm_at, Function.update_eq_self] · -- nohead obtain ⟨wt, htr, hwh, hbi⟩ := scatter1_tape_nohead N bb c b M hb1 hbM m hmk @@ -2820,7 +2840,8 @@ private theorem scatter1_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k = RCm ⟨m, hmk⟩ from by rw [hRCm_at, hrc_in, decide_eq_false (fun h => hhd h.1), decide_eq_false hdep], Function.update_eq_self] - · rw [hstep_ilm, if_neg (show ¬((c.work ⟨m, hmk⟩).head = b ∧ _) from fun h => hhd h.1), + · rw [hstep_ilm, + ite_eq_right (show ¬((c.work ⟨m, hmk⟩).head = b ∧ _) from fun h => hhd h.1), ← hILMm_at, Function.update_eq_self] /-- **SCATTER one full block (`trace (3*k)`).** Sweeping all `k` tapes of block `b` @@ -2856,14 +2877,14 @@ theorem scatter1_block_step {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (b have hrc_k : (fun (j : Fin k) => if (j : ℕ) < k then decide ((c.work j).head = b ∧ (wact j).2 = Dir3.right) else rc_in j) = (fun j => decide ((c.work j).head = b ∧ (wact j).2 = Dir3.right)) := by - funext j; rw [if_pos j.isLt] + funext j; rw [ite_eq_left j.isLt] have hilm_k : (fun (j : Fin k) => if (j : ℕ) < k ∧ (c.work j).head = b ∧ (wact j).2 = Dir3.left then true else ilm_in j) = (fun j => if (c.work j).head = b ∧ (wact j).2 = Dir3.left then true else ilm_in j) := by funext j; simp only [j.isLt, true_and] rw [hrc_k, hilm_k] - simp only [lt_irrefl, if_false] + simp only [lt_irrefl, ite_false] · rw [hwh, blockStart_succ k b hb1, blockWidth] /-- **SCATTER full block sweep (`trace (3*k*B)`).** Sweeping the first `B ≤ M` @@ -2903,7 +2924,7 @@ private theorem scatter1_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k refine (Cfg.mk.injEq ..).mpr ⟨?_, rfl, ?_, rfl⟩ · rw [show (fun (j : Fin k) => if 1 ≤ (c.work j).head ∧ (c.work j).head ≤ 0 ∧ (wact j).2 = Dir3.left then true else ilm_in j) = ilm_in from by - funext j; rw [if_neg (by rintro ⟨h1, h2, _⟩; omega)]] + funext j; rw [ite_eq_right (by rintro ⟨h1, h2, _⟩; omega)]] · funext x obtain rfl : x = 0 := Subsingleton.elim x 0 rfl @@ -2925,8 +2946,8 @@ private theorem scatter1_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k (by rw [hcw]; exact hwhB) (by rw [hcw]; exact hmidB) (by rw [hci]; exact his) (by rw [hco]; exact hos) refine ⟨wt, ?_, ?_, hmid'⟩ - · rw [show 3 * k * (B + 1) = 3 * k * B + 3 * k from Nat.mul_succ (3 * k) B, - trace_const_add, htr, hci, hco] + · erw [show 3 * k * (B + 1) = 3 * k * B + 3 * k from Nat.mul_succ (3 * k) B, + trace_const_add', htr, hci, hco] refine (Cfg.mk.injEq ..).mpr ⟨?_, rfl, rfl, rfl⟩ rw [show (fun (j : Fin k) => if (c.work j).head = B + 1 ∧ (wact j).2 = Dir3.left then true else if 1 ≤ (c.work j).head ∧ (c.work j).head ≤ B ∧ (wact j).2 = Dir3.left then @@ -2937,7 +2958,7 @@ private theorem scatter1_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k by_cases hL : (wact j).2 = Dir3.left · simp only [hL, and_true] split_ifs with h1 h2 h3 <;> first | rfl | omega - · simp only [hL, and_false, if_false]] + · simp only [hL, and_false, ite_false]] · rw [hwh] /-- **One non-turnaround SCATTER sweep-1 step stays in `scatter1`.** As long as the @@ -2957,9 +2978,9 @@ theorem scatter1_step_stays {k : ℕ} (N : NTM k) (b : Bool) (d : Scatter1Data k simp only at hnt ⊢ simp only [scatter1Step] by_cases hwH : (c1.work 0).read = Γ.blank - · rw [if_pos hwH, if_neg (by rintro ⟨hm, hp⟩; exact hnt ⟨hm, hp⟩)] + · rw [ite_eq_left hwH, ite_eq_right (by rintro ⟨hm, hp⟩; exact hnt ⟨hm, hp⟩)] exact ⟨_, rfl, rfl⟩ - · rw [if_neg hwH] + · rw [ite_eq_right hwH] (repeat' split) <;> exact ⟨_, rfl, rfl⟩ /-- **SCATTER block sweep stays in `scatter1` (per step).** Within one block of the @@ -3006,7 +3027,7 @@ theorem scatter1_block_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) rc_in ilm_in hrc_in c1 hst hhead (Scatter1BlockInv.ofMid hbM hmid) his hos (s / 3) (by omega) -- the boundary config is scatter1 with slot `0`, `mat = false` have hsplit : s = 3 * (s / 3) + s % 3 := by omega - rw [hsplit, trace_const_add] + erw [hsplit, trace_const_add'] set c0 := (singleTapeSim N).trace (3 * (s / 3)) (fun _ => bb) c1 with hc0 -- the boundary config's state (slot `0`, `mat = false`) have hc0st : c0.state = SimQ.scatter1 (q', wact, oWoD, iD, iSym, oSym, @@ -3023,7 +3044,7 @@ theorem scatter1_block_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) · obtain ⟨d', hd', _⟩ := step_from_matFalse c0 _ hc0st rfl exact ⟨d', hd'⟩ · -- two steps: first lands at slot 1 (`pos ≠ (0,0)`), second stays scatter1 - rw [show (2 : ℕ) = 1 + 1 from rfl, trace_const_add] + erw [show (2 : ℕ) = 1 + 1 from rfl, trace_const_add'] obtain ⟨d', hd', hpos'⟩ := step_from_matFalse c0 _ hc0st rfl obtain ⟨d'', hd'', _⟩ := step_from_posNe _ d' hd' (by rw [hpos']; simp [advanceSweep]) @@ -3055,7 +3076,7 @@ theorem scatter1_mat_states {k : ℕ} (N : NTM k) (bb : Bool) (M : ℕ) (q' : N. obtain ⟨wt, htr, _, _, _, _⟩ := scatter1_mat_aux N bb M q' wact oWoD iD iSym oSym rc ilm c1 hst hhead hsent his hos (s / 3) (by omega) have hsplit : s = 3 * (s / 3) + s % 3 := by omega - rw [hsplit, trace_const_add] + erw [hsplit, trace_const_add'] set c0 := (singleTapeSim N).trace (3 * (s / 3)) (fun _ => bb) c1 with hc0 have hc0st : c0.state = SimQ.scatter1 (q', wact, oWoD, iD, iSym, oSym, (⟨if s / 3 < k then s / 3 else 0, by split <;> omega⟩, 0), @@ -3071,15 +3092,15 @@ theorem scatter1_mat_states {k : ℕ} (N : NTM k) (bb : Bool) (M : ℕ) (q' : N. have hval : (if s / 3 < k then s / 3 else 0) = 0 := by have := congrArg (fun p => (Prod.fst p).val) hp simpa using this - rw [if_pos hsk] at hval - rw [if_pos hval] at hm + rw [ite_eq_left hsk] at hval + rw [ite_eq_left hval] at hm exact absurd hm (by simp) have hr3 : s % 3 = 0 ∨ s % 3 = 1 ∨ s % 3 = 2 := by omega rcases hr3 with hr | hr | hr <;> rw [hr] · exact ⟨_, hc0st⟩ · obtain ⟨d', hd', _⟩ := step_stays' c0 _ hc0st hnt0 exact ⟨d', hd'⟩ - · rw [show (2 : ℕ) = 1 + 1 from rfl, trace_const_add] + · erw [show (2 : ℕ) = 1 + 1 from rfl, trace_const_add'] obtain ⟨d', hd', hpos'⟩ := step_stays' c0 _ hc0st hnt0 obtain ⟨d'', hd'', _⟩ := step_stays' _ d' hd' (by rw [hpos']; rintro ⟨_, h⟩; exact absurd h (by simp [advanceSweep])) @@ -3143,7 +3164,7 @@ theorem scatter1_sweep_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) have hs : i - 3 * k * B ≤ 3 * k := by omega have hB1M : B + 1 ≤ M := hBlt have hbridge : i = 3 * k * B + (i - 3 * k * B) := by omega - rw [hbridge, trace_const_add] + erw [hbridge, trace_const_add'] obtain ⟨d, hd⟩ := scatter1_block_states N bb c (B + 1) M (Nat.le_add_left 1 B) hB1M q' wact oWoD iD iSym oSym (fun j => decide ((c.work j).head = B ∧ (wact j).2 = Dir3.right)) @@ -3173,7 +3194,7 @@ theorem scatter1_sweep_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) have hbridge : i = 3 * k * M + (i - 3 * k * M) := by omega have hs : i - 3 * k * M ≤ 3 * k := by rw [Nat.mul_succ] at hi; omega - rw [hbridge, trace_const_add, ← hcE] + erw [hbridge, trace_const_add', ← hcE] rcases Nat.lt_or_ge (i - 3 * k * M) (3 * k) with hslt | hsge · -- interior of materialize: `scatter1_mat_states` exact scatter1_mat_states N bb M q' wact oWoD iD iSym oSym _ _ cE hcEst hcEhead hcEsent @@ -3220,9 +3241,9 @@ theorem scatter1_sweep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (M : rw [decide_eq_decide, scatterInterWork_head] have hle := hinv.heads_le j by_cases hr : (wact j).2 = Dir3.right - · rw [if_pos hr] + · rw [ite_eq_left hr] exact ⟨fun h => by obtain ⟨h1, _⟩ := h; omega, fun h => ⟨by omega, hr⟩⟩ - · rw [if_neg hr] + · rw [ite_eq_right hr] exact ⟨fun h => absurd h.2 hr, fun h => absurd h (by omega)⟩ -- bridge: the REWIND carry `initRC` is the block-1 carry have hrc : (fun j => decide ((c.work j).read = Γ.start)) @@ -3267,8 +3288,8 @@ theorem scatter1_sweep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (M : true else (fun _ => false) j) false ((singleTapeSim N).trace (3 * k) (fun _ => bb) ((singleTapeSim N).trace (3 * k * M) (fun _ => bb) c1)) - (by rw [hMat]; simp only [if_neg (show ¬ k < k from Nat.lt_irrefl k), - if_neg (show ¬ k = 0 from by omega), Fin.mk_zero]) + (by rw [hMat]; simp only [ite_eq_right (show ¬ k < k from Nat.lt_irrefl k), + ite_eq_right (show ¬ k = 0 from by omega), Fin.mk_zero]) (by rw [hcwMat]; exact hmatBlank) have hMatin : ((singleTapeSim N).trace (3 * k) (fun _ => bb) ((singleTapeSim N).trace (3 * k * M) (fun _ => bb) c1)).input = c1.input := by @@ -3279,8 +3300,8 @@ theorem scatter1_sweep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (M : refine ⟨fun i => (((singleTapeSim N).trace (3 * k) (fun _ => bb) ((singleTapeSim N).trace (3 * k * M) (fun _ => bb) c1)).work i).writeAndMove Γw.blank.toΓ Dir3.left, ?_, ?_, ?_⟩ - · rw [show 3 * k * (M + 1) + 1 = 3 * k * M + (3 * k + 1) from by rw [Nat.mul_succ]; omega, - trace_const_add, trace_const_add, hTurn, hMatin, hMatout] + · erw [show 3 * k * (M + 1) + 1 = 3 * k * M + (3 * k + 1) from by rw [Nat.mul_succ]; omega, + trace_const_add', trace_const_add', hTurn, hMatin, hMatout] refine (Cfg.mk.injEq ..).mpr ⟨?_, tape_idle_stay c1.input his, rfl, tape_idle_writeMove c1.output hos⟩ rw [show (fun (j : Fin k) => if 1 ≤ (c.work j).head ∧ (c.work j).head ≤ M ∧ @@ -3292,8 +3313,8 @@ theorem scatter1_sweep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (M : rcases Nat.eq_zero_or_pos (c.work j).head with h0 | hp · have hrr := hr0 j h0; rw [hL] at hrr; exact absurd hrr (by decide) · exact hp - rw [if_pos ⟨h1, hinv.heads_le j, hL⟩]; simp [hL] - · rw [if_neg (fun h => hL h.2.2)]; simp [hL]] + rw [ite_eq_left ⟨h1, hinv.heads_le j, hL⟩]; simp [hL] + · rw [ite_eq_right (fun h => hL h.2.2)]; simp [hL]] · -- SimInvAt (M+1) for the intermediate config have hhead0 : ¬ wtMat.head = 0 := by rw [hmatHead]; have := one_le_blockStart k (M + 2); omega have hfc : ((((singleTapeSim N).trace (3 * k) (fun _ => bb) @@ -3302,7 +3323,7 @@ theorem scatter1_sweep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (M : rw [hcwMat] show (wtMat.write Γw.blank.toΓ).cells = wtMat.cells unfold Tape.write - rw [if_neg hhead0] + rw [ite_eq_right hhead0] show Function.update wtMat.cells wtMat.head Γw.blank.toΓ = wtMat.cells rw [show (Γw.blank.toΓ : Γ) = wtMat.cells wtMat.head from hmatBlank.symm, Function.update_eq_self] @@ -3375,7 +3396,6 @@ theorem scatter2_trace1 {k : ℕ} (N : NTM k) (d : Scatter2Data k N.Q) (b : Bool { state := r.1, input := c1.input.move r.2.2.2.1, work := fun i => (c1.work i).writeAndMove (r.2.1 i) (r.2.2.2.2.1 i), output := c1.output.writeAndMove r.2.2.1 r.2.2.2.2.2 } : Cfg 1 (SimQ k N.Q)) := by - rw [NTM.trace] simp only [hst, singleTapeSim, simDelta, SimQ.scatter2, SimQ.halt, Sum.inr.injEq, reduceCtorEq, ↓reduceIte, NTM.trace] @@ -3441,7 +3461,7 @@ theorem scatter2_clear_slot0 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (oWoD output := c1.output } := by rw [scatter2_trace1 N (q', oWoD, iD, iSym, oSym, (⟨t, by omega⟩, 0), isLeftMover, leftCarry) bb c1 hst] - simp only [scatter2Step, hone, ↓reduceIte, hlm, dif_pos ht, and_self, + simp only [scatter2Step, hone, ↓reduceIte, hlm, dite_eq_left ht, and_self, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -3469,7 +3489,7 @@ theorem scatter2_deposit_slot0 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (oWo output := c1.output } := by rw [scatter2_trace1 N (q', oWoD, iD, iSym, oSym, (⟨t, by omega⟩, 0), isLeftMover, leftCarry) bb c1 hst] - simp only [scatter2Step, hns, ↓reduceIte, hnc, hlc, dif_pos ht, + simp only [scatter2Step, hns, ↓reduceIte, hnc, hlc, dite_eq_left ht, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -3495,7 +3515,7 @@ theorem scatter2_keep_slot0 {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (oWoD : output := c1.output } := by rw [scatter2_trace1 N (q', oWoD, iD, iSym, oSym, (⟨t, by omega⟩, 0), isLeftMover, leftCarry) bb c1 hst] - simp only [scatter2Step, hns, ↓reduceIte, hnc, hnl, dif_pos ht, + simp only [scatter2Step, hns, ↓reduceIte, hnc, hnl, dite_eq_left ht, tape_idle_stay c1.input his, tape_idle_writeMove c1.output hos] congr 1 funext x @@ -3537,7 +3557,7 @@ theorem scatter2_clear_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (oWoD rw [show (c1.work 0).head - 1 - 1 = (c1.work 0).head - 2 from by omega]; exact hone) hlm (by rw [e1, e0]; show 1 ≤ (c1.work 0).head - 1 - 1; omega) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] rfl /-- **SCATTER sweep-2 deposit triple** (`trace 3`): three leftward steps over a tape with @@ -3579,7 +3599,7 @@ theorem scatter2_deposit_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (oW rw [show (c1.work 0).head - 1 - 1 = (c1.work 0).head - 2 from by omega]; exact hnc) hlc (by rw [e1, e0]; show 1 ≤ (c1.work 0).head - 1 - 1; omega) (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] rfl /-- **SCATTER sweep-2 keep triple** (`trace 3`): three leftward steps over a tape that is @@ -3619,7 +3639,7 @@ theorem scatter2_keep_triple {k : ℕ} (N : NTM k) (bb : Bool) (q' : N.Q) (oWoD isLeftMover ⟨t, ht⟩ = true); rw [show (c1.work 0).head - 1 - 1 = (c1.work 0).head - 2 from by omega]; exact hnc) hnl (by rw [e1, e0]; exact his) (by rw [e1, e0]; exact hos) - rw [trace_three, e2, e1, e0] + rw [trace_three', e2, e1, e0] rfl /-- **SCATTER sweep-2 per-tape — keep.** Tape `k-1-m` of block `p` is neither a @@ -3670,7 +3690,7 @@ theorem scatter2_tape_keep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (p by_cases hb : (scatterInterWork (c.work ⟨k - 1 - m, by omega⟩) (wact ⟨k - 1 - m, by omega⟩)).head = p · exact hb - · rw [if_neg hb] at h1; exact absurd h1 (by decide)) + · rw [ite_eq_right hb] at h1; exact absurd h1 (by decide)) hnl his hos refine ⟨{ c1.work 0 with head := (c1.work 0).head - 3 }, htriple, ?_, ?_⟩ · show (c1.work 0).head - 3 = headBitCell k p ⟨k - 1 - m, by omega⟩ - 1 @@ -3721,7 +3741,7 @@ theorem scatter2_tape_clear {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (p (by rw [hhead, show headBitCell k p ⟨k - 1 - m, by omega⟩ + 2 - 1 = headBitCell k p ⟨k - 1 - m, by omega⟩ + 1 from by omega, ← hsym1, hot.2.1] exact (encSymΓ_ne_start _).1) - (by rw [heq2, hot.1, if_pos hheadp]) + (by rw [heq2, hot.1, ite_eq_left hheadp]) hlm his hos refine ⟨⟨(c1.work 0).head - 3, Function.update (c1.work 0).cells ((c1.work 0).head - 2) Γw.zero.toΓ⟩, htriple, ?_, ?_⟩ @@ -3730,7 +3750,7 @@ theorem scatter2_tape_clear {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (p · apply scatter2_blockinv_step hp1 hpM hmk hbm · show Function.update (c1.work 0).cells ((c1.work 0).head - 2) Γw.zero.toΓ (headBitCell k p ⟨k - 1 - m, by omega⟩) = _ - rw [← heq2, Function.update_self, if_neg hfinne]; rfl + rw [← heq2, Function.update_self, ite_eq_right hfinne]; rfl · intro cc hcc exact Function.update_of_ne (fun h => hcc (h.trans heq2)) _ _ @@ -3777,7 +3797,7 @@ theorem scatter2_tape_deposit {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) = headBitCell k p ⟨k - 1 - m, by omega⟩ + 1 from by omega, ← hsym1, hot.2.1] exact (encSymΓ_ne_start _).1) (by rw [heq2, hot.1]; split_ifs <;> decide) - (by rw [heq2, hot.1, if_neg hninter]; rintro ⟨h1, _⟩; exact absurd h1 (by decide)) + (by rw [heq2, hot.1, ite_eq_right hninter]; rintro ⟨h1, _⟩; exact absurd h1 (by decide)) hlc his hos refine ⟨⟨(c1.work 0).head - 3, Function.update (c1.work 0).cells ((c1.work 0).head - 2) Γw.one.toΓ⟩, htriple, ?_, ?_⟩ @@ -3786,7 +3806,7 @@ theorem scatter2_tape_deposit {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) · apply scatter2_blockinv_step hp1 hpM hmk hbm · show Function.update (c1.work 0).cells ((c1.work 0).head - 2) Γw.one.toΓ (headBitCell k p ⟨k - 1 - m, by omega⟩) = _ - rw [← heq2, Function.update_self, if_pos hfineq]; rfl + rw [← heq2, Function.update_self, ite_eq_left hfineq]; rfl · intro cc hcc exact Function.update_of_ne (fun h => hcc (h.trans heq2)) _ _ @@ -3856,13 +3876,13 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k ∧ (c.work ⟨k - 1 - m, by omega⟩).head = p)) := by funext j by_cases hj : j = ⟨k - 1 - m, by omega⟩ - · subst hj; rw [Function.update_self, if_pos (by rw [hjval]; omega)] + · subst hj; rw [Function.update_self, ite_eq_left (by rw [hjval]; omega)] · rw [Function.update_of_ne hj, hLCm] have hjm : (j : ℕ) ≠ k - 1 - m := fun h => hj (Fin.ext h) have hjlt := j.isLt by_cases hlt : k - 1 - (j : ℕ) < m - · simp only [if_pos hlt, if_pos (show k - 1 - (j : ℕ) < m + 1 by omega)] - · simp only [if_neg hlt, if_neg (show ¬ k - 1 - (j : ℕ) < m + 1 by omega)] + · simp only [ite_eq_left hlt, ite_eq_left (show k - 1 - (j : ℕ) < m + 1 by omega)] + · simp only [ite_eq_right hlt, ite_eq_right (show ¬ k - 1 - (j : ℕ) < m + 1 by omega)] have hstep_ilm : (fun (j : Fin k) => if k - 1 - (j : ℕ) < m + 1 ∧ (wact j).2 = Dir3.left ∧ (c.work j).head = p + 1 then false else isLeftMover_in j) @@ -3881,13 +3901,13 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k ⟨fun h => ⟨by omega, h.2⟩, fun h => ⟨by omega, h.2⟩⟩ simp only [hiff] have hLCm_at : LCm ⟨k - 1 - m, by omega⟩ = leftCarry_in ⟨k - 1 - m, by omega⟩ := by - rw [hLCm]; simp only [hjval, lt_irrefl, if_false] + rw [hLCm]; simp only [hjval, lt_irrefl, ite_false] have hILMm_at : ILMm ⟨k - 1 - m, by omega⟩ = isLeftMover_in ⟨k - 1 - m, by omega⟩ := by - rw [hILMm]; simp only [hjval, lt_irrefl, false_and, if_false] + rw [hILMm]; simp only [hjval, lt_irrefl, false_and, ite_false] -- facts about the IH config cM = trace (3*m) c1 have hcs : ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).state = SimQ.scatter2 (q', oWoD, iD, iSym, oSym, (⟨k - 1 - m, by omega⟩, 2), ILMm, LCm) := by - rw [htm]; simp only [if_pos hmk] + rw [htm]; simp only [ite_eq_left hmk]; rfl have hch : (((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).work 0).head = headBitCell k p ⟨k - 1 - m, by omega⟩ + 2 := by rw [show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).work 0 = wtm @@ -3912,7 +3932,7 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k apply Prod.ext · apply Fin.ext; simp only; split <;> split <;> omega · rfl - -- assembly closure (trace_const_add + input/output reconciliation, done once) + -- assembly closure (trace_const_add' + input/output reconciliation, done once) have key : ∀ (wt : Tape) (ilm' lc' : Fin k → Bool), (singleTapeSim N).trace 3 (fun _ => bb) ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1) @@ -3941,7 +3961,7 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k ∧ Scatter2BlockInv wt' c.work wact M p (m + 1) := by intro wt ilm' lc' htr hilm hlc hwh hbi refine ⟨wt, ?_, ?_, hbi⟩ - · rw [show 3 * (m + 1) = 3 * m + 3 from by omega, trace_const_add, htr, hilm, hlc, + · erw [show 3 * (m + 1) = 3 * m + 3 from by omega, trace_const_add', htr, hilm, hlc, show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).input = c1.input from by rw [htm], show ((singleTapeSim N).trace (3 * m) (fun _ => bb) c1).output = c1.output from by rw [htm]] @@ -3961,10 +3981,10 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k · have hihl : (scatterInterWork (c.work ⟨k - 1 - m, by omega⟩) (wact ⟨k - 1 - m, by omega⟩)).head = (c.work ⟨k - 1 - m, by omega⟩).head := by - rw [hih, if_neg (by rw [hleft]; decide)] + rw [hih, ite_eq_right (by rw [hleft]; decide)] have hfhl : (scatterFinalWork (c.work ⟨k - 1 - m, by omega⟩) (wact ⟨k - 1 - m, by omega⟩)).head - = (c.work ⟨k - 1 - m, by omega⟩).head - 1 := by rw [hfh, if_pos hleft] + = (c.work ⟨k - 1 - m, by omega⟩).head - 1 := by rw [hfh, ite_eq_left hleft] by_cases hcp : (c.work ⟨k - 1 - m, by omega⟩).head = p · -- clear obtain ⟨wt, htr, hwh, hbi⟩ := scatter2_tape_clear N bb c p M hp1 hpM m hmk @@ -3974,7 +3994,8 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k (by rw [hfhl]; omega) hcis hcos rw [hpos_eq] at htr refine key wt ILMm (Function.update LCm ⟨k - 1 - m, by omega⟩ true) htr ?_ ?_ hwh hbi - · rw [hstep_ilm, if_neg (by rintro ⟨_, h2⟩; omega), ← hILMm_at, Function.update_eq_self] + · rw [hstep_ilm, ite_eq_right (by rintro ⟨_, h2⟩; omega), ← hILMm_at, + Function.update_eq_self] · rw [hstep_lc, decide_eq_true ⟨hleft, hcp⟩] · by_cases hcp1 : (c.work ⟨k - 1 - m, by omega⟩).head = p + 1 · -- deposit @@ -3986,7 +4007,7 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k rw [hpos_eq] at htr refine key wt (Function.update ILMm ⟨k - 1 - m, by omega⟩ false) (Function.update LCm ⟨k - 1 - m, by omega⟩ false) htr ?_ ?_ hwh hbi - · rw [hstep_ilm, if_pos ⟨hleft, hcp1⟩] + · rw [hstep_ilm, ite_eq_left ⟨hleft, hcp1⟩] · rw [hstep_lc, decide_eq_false (by rintro ⟨_, h2⟩; omega)] · -- keep (left-mover, head not p or p+1) obtain ⟨wt, htr, hwh, hbi⟩ := scatter2_tape_keep N bb c p M hp1 hpM m hmk @@ -3997,7 +4018,8 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k (by rw [hihl, hfhl]; constructor <;> intro h <;> omega) hcis hcos rw [hpos_eq] at htr refine key wt ILMm LCm htr ?_ ?_ hwh hbi - · rw [hstep_ilm, if_neg (by rintro ⟨_, h3⟩; omega), ← hILMm_at, Function.update_eq_self] + · rw [hstep_ilm, ite_eq_right (by rintro ⟨_, h3⟩; omega), ← hILMm_at, + Function.update_eq_self] · rw [hstep_lc, show (decide ((wact ⟨k - 1 - m, by omega⟩).2 = Dir3.left ∧ (c.work ⟨k - 1 - m, by omega⟩).head = p)) = LCm ⟨k - 1 - m, by omega⟩ from by @@ -4013,7 +4035,7 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k (wact ⟨k - 1 - m, by omega⟩)).head = (scatterInterWork (c.work ⟨k - 1 - m, by omega⟩) (wact ⟨k - 1 - m, by omega⟩)).head := by - rw [hfh, if_neg hleft] + rw [hfh, ite_eq_right hleft] obtain ⟨wt, htr, hwh, hbi⟩ := scatter2_tape_keep N bb c p M hp1 hpM m hmk q' wact oWoD iD iSym oSym ILMm LCm _ hcs hch hcbi (by rw [hILMm_at, hilmf]; rintro ⟨_, h2⟩; exact absurd h2 (by decide)) @@ -4021,7 +4043,7 @@ private theorem scatter2_block_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k (by rw [hfhnl]) hcis hcos rw [hpos_eq] at htr refine key wt ILMm LCm htr ?_ ?_ hwh hbi - · rw [hstep_ilm, if_neg (by rintro ⟨h2, _⟩; exact hleft h2), ← hILMm_at, + · rw [hstep_ilm, ite_eq_right (by rintro ⟨h2, _⟩; exact hleft h2), ← hILMm_at, Function.update_eq_self] · rw [hstep_lc, show (decide ((wact ⟨k - 1 - m, by omega⟩).2 = Dir3.left @@ -4071,9 +4093,9 @@ theorem scatter2_block_step {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (p have hlc_k : (fun (j : Fin k) => if k - 1 - (j : ℕ) < k then decide ((wact j).2 = Dir3.left ∧ (c.work j).head = p) else leftCarry_in j) = (fun j => decide ((wact j).2 = Dir3.left ∧ (c.work j).head = p)) := by - funext j; rw [if_pos (by have := j.isLt; omega)] + funext j; rw [ite_eq_left (by have := j.isLt; omega)] rw [hilm_k, hlc_k] - simp only [lt_irrefl, if_false] + simp only [lt_irrefl, ite_false] · rw [hwh]; omega /-- **SCATTER sweep-2 full block sweep (`trace (3*k*B)`).** Sweeping the first `B ≤ M+1` @@ -4141,8 +4163,8 @@ private theorem scatter2_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k exact hmidB) (by rw [hci]; exact his) (by rw [hco]; exact hos) refine ⟨wt, ?_, ?_, ?_⟩ - · rw [show 3 * k * (B + 1) = 3 * k * B + 3 * k from Nat.mul_succ (3 * k) B, - trace_const_add, htr, hci, hco] + · erw [show 3 * k * (B + 1) = 3 * k * B + 3 * k from Nat.mul_succ (3 * k) B, + trace_const_add', htr, hci, hco] refine (Cfg.mk.injEq ..).mpr ⟨?_, rfl, rfl, rfl⟩ rw [show (fun j : Fin k => if (wact j).2 = Dir3.left ∧ (c.work j).head = M + 1 - B + 1 then false @@ -4151,12 +4173,12 @@ private theorem scatter2_sweep_aux {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k funext j by_cases hL : (wact j).2 = Dir3.left · by_cases hh : (c.work j).head = M + 1 - B + 1 - · rw [if_pos ⟨hL, hh⟩]; symm; exact decide_eq_false (by rintro ⟨_, h2⟩; omega) - · rw [if_neg (fun h => hh h.2), decide_eq_decide] + · rw [ite_eq_left ⟨hL, hh⟩]; symm; exact decide_eq_false (by rintro ⟨_, h2⟩; omega) + · rw [ite_eq_right (fun h => hh h.2), decide_eq_decide] constructor · rintro ⟨hl, _⟩; exact ⟨hl, by omega⟩ · rintro ⟨hl, _⟩; exact ⟨hl, by omega⟩ - · rw [if_neg (fun h => hL h.1), decide_eq_false (fun h => hL h.1), + · rw [ite_eq_right (fun h => hL h.1), decide_eq_false (fun h => hL h.1), decide_eq_false (fun h => hL h.1)], show (fun j : Fin k => decide ((wact j).2 = Dir3.left ∧ (c.work j).head = M + 1 - B)) = (fun j => decide ((c.work j).head = M + 2 - (B + 1) ∧ (wact j).2 = Dir3.left)) from by @@ -4186,7 +4208,7 @@ theorem scatter2_step_stays {k : ℕ} (N : NTM k) (b : Bool) (d : Scatter2Data k -- the move direction `r.2.2.2.2.1 0` is `left` (off `▷`) have hdir : r.2.2.2.2.1 0 = Dir3.left := by rw [hr]; obtain ⟨q', oWoD, iD, iSym, oSym, pos, isLeftMover, leftCarry⟩ := d - simp only [scatter2Step, if_neg hnsr] + simp only [scatter2Step, ite_eq_right hnsr] have hwork : ((c1.work 0).writeAndMove (r.2.1 0).toΓ (r.2.2.2.2.1 0)) = ⟨(c1.work 0).head - 1, Function.update (c1.work 0).cells (c1.work 0).head (r.2.1 0).toΓ⟩ := by @@ -4194,7 +4216,7 @@ theorem scatter2_step_stays {k : ℕ} (N : NTM k) (b : Bool) (d : Scatter2Data k -- the state is `r.1`; off `▷` every branch yields `scatter2` obtain ⟨d', hd'⟩ : ∃ d', r.1 = SimQ.scatter2 d' := by rw [hr]; obtain ⟨q', oWoD, iD, iSym, oSym, pos, isLeftMover, leftCarry⟩ := d - simp only [scatter2Step, if_neg hnsr] + simp only [scatter2Step, ite_eq_right hnsr] (repeat' split) <;> exact ⟨_, rfl⟩ refine ⟨d', hd', ?_, ?_⟩ · show (((c1.work (0 : Fin 1)).writeAndMove (r.2.1 0).toΓ (r.2.2.2.2.1 0))).head @@ -4236,7 +4258,7 @@ theorem scatter2_block_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) isLeftMover_in leftCarry_in hilm_in hlc_in c1 hst hhead (Scatter2BlockInv.ofMid hp1 hmid) his hos (s / 3) (by omega) have hsplit : s = 3 * (s / 3) + s % 3 := by omega - rw [hsplit, trace_const_add] + erw [hsplit, trace_const_add'] set c0 := (singleTapeSim N).trace (3 * (s / 3)) (fun _ => bb) c1 with hc0 -- the boundary config: scatter2 with datum `d0`, tape `wt`, `Scatter2BlockInv … p (s/3)` obtain ⟨d0, hc0st⟩ : ∃ d, c0.state = SimQ.scatter2 d := ⟨_, by rw [htr]⟩ @@ -4263,7 +4285,7 @@ theorem scatter2_block_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) hc0bi.cells_ne_start hp1 hpM (by omega) have hread1 : (c0.work 0).cells ((c0.work 0).head - 1) ≠ Γ.start := hc0bi.cells_ne_start hp1 hpM (by omega) - rw [show (2 : ℕ) = 1 + 1 from rfl, trace_const_add] + erw [show (2 : ℕ) = 1 + 1 from rfl, trace_const_add'] obtain ⟨d', hd', hh', hcells'⟩ := scatter2_step_stays N bb d0 c0 hc0st (by omega) hread0 set c0' := (singleTapeSim N).trace 1 (fun _ => bb) c0 with hc0' have hread' : (c0'.work 0).cells ((c0'.work 0).head) ≠ Γ.start := by @@ -4336,7 +4358,7 @@ theorem scatter2_sweep_states {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) -- residual `r = i - 3*k*B ≤ 3*k` have hbridge : i = 3 * k * B + (i - 3 * k * B) := by omega have hres : i - 3 * k * B ≤ 3 * k := by omega - rw [hbridge, trace_const_add] + erw [hbridge, trace_const_add'] set cE := (singleTapeSim N).trace (3 * k * B) (fun _ => bb) c1 with hcE -- the block-`p` entry: scatter2 at slot 2 tape `k-1`, head `headBitCell p (k-1) + 2`, -- the `B`-boundary carries are the `p`-block-states carries, `Scatter2MidInv … (p+1)` @@ -4409,14 +4431,14 @@ theorem scatter2_sweep {k : ℕ} (N : NTM k) (bb : Bool) (c : Cfg k N.Q) (M : refine ⟨fun i => (((singleTapeSim N).trace (3 * k * (M + 1)) (fun _ => bb) c1).work i).writeAndMove Γw.blank.toΓ Dir3.right, ?_, ?_, ?_⟩ - · rw [trace_const_add, hstart, hSin, hSout] + · erw [trace_const_add', hstart, hSin, hSout] · apply hsimFinal.cells_congr show ((((singleTapeSim N).trace (3 * k * (M + 1)) (fun _ => bb) c1).work 0).writeAndMove Γw.blank.toΓ Dir3.right).cells = wtS.cells rw [hcwS] show (wtS.write Γw.blank.toΓ).cells = wtS.cells unfold Tape.write - rw [if_pos hh0] + rw [ite_eq_left hh0] · show ((((singleTapeSim N).trace (3 * k * (M + 1)) (fun _ => bb) c1).work 0).writeAndMove Γw.blank.toΓ Dir3.right).head = 1 rw [hcwS, work_blank_right_at0 wtS hh0] @@ -4556,7 +4578,9 @@ theorem run_to_scatter1 {k : ℕ} (N : NTM k) {M : ℕ} output := c1.output.writeAndMove (TM.readBackWrite c1.output.read).toΓ (TM.idleDir c1.output.read) } := by rw [gather_sentinel N bit c.state (fun j => (c.work j).read) c1.input.read c1.output.read - (⟨0, by omega⟩, 0) rf' pending' _ (by rw [hgather]) + (⟨0, by omega⟩, 0) rf' pending' + ((singleTapeSim N).trace (3 * k * M) (fun _ => bit) + ((singleTapeSim N).trace 1 (fun _ => bit) c1)) (by rw [hgather]) (by rw [hcgw]; exact hinv.sentinel (blockStart k (M + 1)) (le_refl _))] refine (Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩ · rw [hcgi]; exact tape_idle_stay _ hisR @@ -4565,10 +4589,10 @@ theorem run_to_scatter1 {k : ℕ} (N : NTM k) {M : ℕ} show Γw.blank.toΓ = (c1.work 0).cells (blockStart k (M + 1)) from (hinv.sentinel (blockStart k (M + 1)) (le_refl _)).symm, Function.update_eq_self] · rw [hcgo]; exact tape_idle_writeMove _ hosR - -- Phase 3: rewind sweep + trace_const_add chaining + -- Phase 3: rewind sweep + trace_const_add' chaining have hbs1 : blockStart k (M + 1) = blockStart k (M + 1) - 1 + 1 := by have := one_le_blockStart k (M + 1); omega - rw [trace_const_add, trace_const_add, trace_const_add, hbs1, + rw [trace_const_add', trace_const_add', trace_const_add', hbs1, rewind_sweep N bit _ _ _ _ c1.input.read c1.output.read (fun j => decide ((c.work j).read = Γ.start)) ((singleTapeSim N).trace 1 (fun _ => bit) @@ -4673,7 +4697,9 @@ theorem macroStep_decision_point_iff {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : output := c1.output.writeAndMove (TM.readBackWrite c1.output.read).toΓ (TM.idleDir c1.output.read) } := by rw [gather_sentinel N b c.state (fun j => (c.work j).read) c1.input.read c1.output.read - (⟨0, by omega⟩, 0) rf' pending' _ (by rw [hgather]) + (⟨0, by omega⟩, 0) rf' pending' + ((singleTapeSim N).trace (3 * k * M) (fun _ => b) + ((singleTapeSim N).trace 1 (fun _ => b) c1)) (by rw [hgather]) (by rw [hcgw]; exact hinv.sentinel (blockStart k (M + 1)) (le_refl _))] refine (Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩ · rw [hcgi]; exact tape_idle_stay _ hisR @@ -4731,7 +4757,7 @@ theorem macroStep_decision_point_iff {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : have hBc1 : (singleTapeSim N).trace B (fun _ => b) c1 = (singleTapeSim N).trace (3 * k * (M + 1) + 1) (fun _ => b) ((singleTapeSim N).trace A (fun _ => b) c1) := by - rw [hBdef, trace_const_add] + erw [hBdef, trace_const_add'] rw [hBc1] apply scatter2_sweep_states N b c M hk dr.1 (dr.2.2.1, dr.2.2.2.2.2) dr.2.2.2.1 c.input.read c.output.read @@ -4767,13 +4793,13 @@ theorem macroStep_decision_point_iff {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : = (singleTapeSim N).trace 1 (fun _ => b) ((singleTapeSim N).trace (3 * k * M) (fun _ => b) ((singleTapeSim N).trace 1 (fun _ => b) c1)) := by - rw [show 1 + 3 * k * M + 1 = 1 + (3 * k * M + 1) from by omega, trace_const_add, - trace_const_add] + erw [show 1 + 3 * k * M + 1 = 1 + (3 * k * M + 1) from by omega, trace_const_add', + trace_const_add'] -- the SCATTER-2 entry config `trace B c1 = trace (3*k*(M+1)+1) (trace A c1)` have hBc1 : (singleTapeSim N).trace B (fun _ => b) c1 = (singleTapeSim N).trace (3 * k * (M + 1) + 1) (fun _ => b) ((singleTapeSim N).trace A (fun _ => b) c1) := by - rw [hBdef, trace_const_add] + erw [hBdef, trace_const_add'] -- helper: off the sentinel position, no step is a `gather`-on-`□` decision point have key : ∀ i, i < B + (3 * k * (M + 1) + 1) + 1 → i ≠ 1 + 3 * k * M → ¬ ((∃ d, ((singleTapeSim N).trace i (fun _ => b) c1).state = SimQ.gather d) ∧ @@ -4790,7 +4816,7 @@ theorem macroStep_decision_point_iff {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : · -- `i ∈ [1, p0)`: the GATHER sweep, where the read is non-blank obtain ⟨j, rfl⟩ : ∃ j, i = 1 + j := ⟨i - 1, by omega⟩ have hj : j < 3 * k * M := by omega - rw [trace_const_add] at hbl + erw [trace_const_add'] at hbl exact (hgsweep j hj).2 hbl · exact hip0 heq · -- after the sentinel: rewind / scatter1 / scatter2 / commit — never `gather` @@ -4799,26 +4825,26 @@ theorem macroStep_decision_point_iff {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : obtain ⟨j, rfl⟩ : ∃ j, i = (1 + 3 * k * M + 1) + j := ⟨i - (1 + 3 * k * M + 1), by omega⟩ have hj : j ≤ blockStart k (M + 1) - 1 := by have := one_le_blockStart k (M + 1); rw [hA] at hiA; omega - rw [trace_const_add, hRewEntry, hrewind j hj] at hg + erw [trace_const_add', hRewEntry, hrewind j hj] at hg exact absurd (Sum.inr.inj hg) (by simp [reduceCtorEq]) · -- SCATTER-1 / SCATTER-2 / COMMIT rcases Nat.lt_or_ge i B with hiB | hiB · -- SCATTER-1: `i ∈ [A, B)` obtain ⟨j, rfl⟩ : ∃ j, i = A + j := ⟨i - A, by omega⟩ have hj : j < 3 * k * (M + 1) + 1 := by rw [hBdef] at hiB; omega - rw [trace_const_add] at hg + erw [trace_const_add'] at hg exact hsc1 j hj ⟨dg, hg⟩ · -- SCATTER-2 / COMMIT rcases Nat.lt_or_ge i (B + (3 * k * (M + 1) + 1)) with hiC | hiC · -- SCATTER-2: `i ∈ [B, B + (3*k*(M+1)+1))` obtain ⟨j, rfl⟩ : ∃ j, i = B + j := ⟨i - B, by omega⟩ have hj : j < 3 * k * (M + 1) + 1 := by omega - rw [trace_const_add] at hg + erw [trace_const_add'] at hg exact hsc2 j hj ⟨dg, hg⟩ · -- COMMIT: `i = B + (3*k*(M+1)+1)` have hiCommit : i = B + (3 * k * (M + 1) + 1) := by omega subst hiCommit - rw [trace_const_add, hBc1, hs2] at hg + erw [trace_const_add', hBc1, hs2] at hg exact absurd (Sum.inr.inj hg) (by simp [reduceCtorEq]) intro i hi by_cases hip0 : i = 1 + 3 * k * M @@ -4883,11 +4909,11 @@ theorem corr_macroStep_explicit {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : ℕ} work := fun t => scatterFinalWork (c.work t) (dr.2.1 t, dr.2.2.2.2.1 t), output := c.output.writeAndMove dr.2.2.1 dr.2.2.2.2.2 } := by rw [trace_one_scatterFinal N (fun _ => b) c hne] - rw [show 1 + 3 * k * M + 1 + blockStart k (M + 1) + (3 * k * (M + 1) + 1) + erw [show 1 + 3 * k * M + 1 + blockStart k (M + 1) + (3 * k * (M + 1) + 1) + (3 * k * (M + 1) + 1) + 1 = 1 + 3 * k * M + 1 + blockStart k (M + 1) + ((3 * k * (M + 1) + 1) + ((3 * k * (M + 1) + 1) + 1)) from by omega, - trace_const_add, trace_const_add, trace_const_add, hcommit, htr1] + trace_const_add', trace_const_add', trace_const_add', hcommit, htr1] -- abbreviate the COMMIT-config (input/output/work after the two scatter sweeps) set cc := (singleTapeSim N).trace (3 * k * (M + 1) + 1) (fun _ => b) ((singleTapeSim N).trace (3 * k * (M + 1) + 1) (fun _ => b) @@ -5031,7 +5057,7 @@ theorem trace_congr_choices {k : ℕ} (N : NTM k) : · apply simDelta_eq_of_forall_ne_blank intro d hd_eq hbad exact hgather ⟨⟨d, hd_eq⟩, hbad⟩ - simp only [NTM.trace, if_neg hcmhalt, Nat.add_zero] + simp only [NTM.trace, ite_eq_right hcmhalt, Nat.add_zero] exact congrArg (fun r => ({ state := r.1, input := cm0.input.move r.2.2.2.1, work := fun i => (cm0.work i).writeAndMove (r.2.1 i).toΓ (r.2.2.2.2.1 i), @@ -5080,10 +5106,10 @@ theorem corr_iterate {k : ℕ} (N : NTM k) (hk : 1 ≤ k) {M : ℕ} refine ⟨m + m', M' + 1, F, ?_, by omega, ?_⟩ · rw [hNsplit, (singleTapeSim N).trace_add_fun m m' F c1] have hpre : (fun i : Fin m => F i.val) = (fun i : Fin m => f i.val) := by - funext i; rw [hF]; simp only []; rw [if_pos i.isLt] + funext i; rw [hF]; simp only []; rw [ite_eq_left i.isLt] have hsuf : (fun i : Fin m' => F (m + i.val)) = choices' := by funext i; rw [hF]; simp only [] - rw [if_neg (by omega), dif_pos (by omega)] + rw [ite_eq_right (by omega), dite_eq_left (by omega)] have hsub : m + i.val - m = i.val := by omega simp only [hsub, Fin.eta] rw [hpre, ← hs_t, hsuf] @@ -5109,7 +5135,7 @@ theorem acceptsInTime_singleTapeSim_of_acceptsInTime {k : ℕ} (N : NTM k) (hk : set g : ℕ → Bool := fun i => if hi : i < Tn then chN ⟨i, hi⟩ else false with hg obtain ⟨m, M', F, hcorr, _hM', hm⟩ := corr_iterate N hk (corr_init N x) g Tn have hgN : (fun i : Fin Tn => g i.val) = chN := by - funext i; rw [hg]; simp only []; rw [dif_pos i.isLt] + funext i; rw [hg]; simp only []; rw [dite_eq_left i.isLt] rw [hgN] at hcorr -- one halt step lands in a halted, accepting simulator config obtain ⟨hhalted, hbit⟩ := halted_of_corr N hcorr hhalt @@ -5120,9 +5146,9 @@ theorem acceptsInTime_singleTapeSim_of_acceptsInTime {k : ℕ} (N : NTM k) (hk : = (singleTapeSim N).trace 1 (fun _ => false) sCfg := by rw [(singleTapeSim N).trace_add_fun m 1 F'] have e1 : (fun i : Fin m => F' i.val) = (fun i : Fin m => F i.val) := by - funext i; rw [hF']; simp only [i.isLt, if_true] + funext i; rw [hF']; simp only [i.isLt, ite_true] have e2 : (fun i : Fin 1 => F' (m + i.val)) = (fun _ => false) := by - funext i; rw [hF']; simp only []; rw [if_neg (by omega)] + funext i; rw [hF']; simp only []; rw [ite_eq_right (by omega)] rw [e1, e2, ← hsCfg] have key : (singleTapeSim N).AcceptsInTime x (m + 1) := by refine ⟨fun i => F' i.val, ?_, ?_⟩ diff --git a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Delta.lean b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Delta.lean index 2a8528f2..459f81b3 100644 --- a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Delta.lean +++ b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Delta.lean @@ -200,7 +200,7 @@ theorem gatherStep_right_of_start {k : ℕ} (N : NTM k) (b : Bool) · simp only [gatherStep]; split_ifs <;> exact TM.idleDir_right_of_start h · subst h simp only [gatherStep] - rw [if_neg (by decide : ¬ (Γ.start = Γ.blank))] + rw [ite_eq_right (by decide : ¬ (Γ.start = Γ.blank))] split_ifs <;> rfl · simp only [gatherStep]; split_ifs <;> exact TM.idleDir_right_of_start h @@ -337,7 +337,7 @@ theorem scatter2Step_right_of_start {k : ℕ} {Q : Type} (d : Scatter2Data k Q) obtain ⟨q', oWoD, iD, iSym, oSym, pos, isLeftMover, leftCarry⟩ := d refine ⟨fun h => ?_, fun _ h => ?_, fun h => ?_⟩ · exact TM.idleDir_right_of_start h - · simp only [scatter2Step]; rw [if_pos h] + · simp only [scatter2Step]; rw [ite_eq_left h] · exact TM.idleDir_right_of_start h /-- The assembled single-tape transition function: dispatch on the phase. The @@ -402,7 +402,7 @@ theorem simDelta_right_of_start {k : ℕ} (N : NTM k) (b : Bool) (q : SimQ k N.Q theorem gatherStep_eq_of_ne_blank {k : ℕ} (N : NTM k) (b b' : Bool) (d : GatherData k N.Q) (iHead wH oHead : Γ) (h : wH ≠ Γ.blank) : gatherStep N b d iHead wH oHead = gatherStep N b' d iHead wH oHead := by - simp only [gatherStep, if_neg h] + simp only [gatherStep, ite_eq_right h] /-- **GATHER stays in GATHER off the sentinel.** As long as the work head is not on the `□` sentinel, the GATHER step's next state is again a GATHER state (the @@ -411,7 +411,7 @@ theorem gatherStep_eq_of_ne_blank {k : ℕ} (N : NTM k) (b b' : Bool) (d : Gathe theorem gatherStep_fst_eq_gather_of_ne_blank {k : ℕ} (N : NTM k) (b : Bool) (d : GatherData k N.Q) (iHead wH oHead : Γ) (h : wH ≠ Γ.blank) : ∃ d', (gatherStep N b d iHead wH oHead).1 = SimQ.gather d' := by - simp only [gatherStep, if_neg h] + simp only [gatherStep, ite_eq_right h] split · exact ⟨_, rfl⟩ · split <;> exact ⟨_, rfl⟩ @@ -427,7 +427,7 @@ theorem gatherStep_snd_eq_of_ne_blank {k : ℕ} (N : NTM k) (b : Bool) (d : Gath (gatherStep N b d iHead wH oHead).2.2.2.1 = TM.idleDir iHead ∧ (gatherStep N b d iHead wH oHead).2.2.2.2.1 = (fun _ => Dir3.right) ∧ (gatherStep N b d iHead wH oHead).2.2.2.2.2 = TM.idleDir oHead := by - simp only [gatherStep, if_neg h] + simp only [gatherStep, ite_eq_right h] split · exact ⟨rfl, rfl, rfl, rfl, rfl⟩ · split <;> exact ⟨rfl, rfl, rfl, rfl, rfl⟩ diff --git a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Pad.lean b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Pad.lean index 8ef62118..be85e7d0 100644 --- a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Pad.lean +++ b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Pad.lean @@ -58,15 +58,15 @@ private theorem pad0_dummy_step (w : Tape) (hc : w.cells = (Tape.init []).cells) rcases Nat.le_one_iff_eq_zero_or_eq_one.mp hh with h0 | h1 · -- head at cell 0: reading `▷`, write is a no-op, move right to cell 1 have hr : w.read = Γ.start := by rw [hread, h0]; rfl - rw [hr, if_pos rfl] + rw [hr, ite_eq_left rfl] show ((w.write _).move .right).cells = _ ∧ ((w.write _).move .right).head ≤ 1 - rw [Tape.write, if_pos h0] + rw [Tape.write, ite_eq_left h0] exact ⟨hc, by rw [Tape.move, h0]⟩ · -- head at cell 1: reading `□`, write `□` over `□`, stay have hr : w.read = Γ.blank := by rw [hread, h1]; rfl - rw [hr, if_neg (by decide : ¬ Γ.blank = Γ.start)] + rw [hr, ite_eq_right (by decide : ¬ Γ.blank = Γ.start)] show ((w.write _).move .stay).cells = _ ∧ ((w.write _).move .stay).head ≤ 1 - rw [Tape.move, Tape.write, if_neg (by rw [h1]; decide : ¬ w.head = 0)] + rw [Tape.move, Tape.write, ite_eq_right (by rw [h1]; decide : ¬ w.head = 0)] constructor · show Function.update w.cells w.head (Γw.blank : Γ) = (Tape.init []).cells have hv : (Γw.blank : Γ) = w.cells w.head := by @@ -109,12 +109,13 @@ theorem pad0_trace (N : NTM 0) : · -- one step, then the inductive hypothesis have hvec : (fun i : Fin 0 => (c.work i).read) = (fun i => i.elim0) := funext fun i => i.elim0 - simp only [NTM.trace, hh, if_false, pad0_δ_apply] - rw [hs, hi, ho, hvec] + dsimp only [NTM.trace, pad0] + simp only [hh, ite_false] split · -- the `pad0` halt test cannot fire: `c.state ≠ qhalt` - next hcontra => exact absurd hcontra hh - · refine ih _ _ _ ?_ ?_ ?_ ?_ ?_ + next hcontra => exact absurd (hs.symm.trans hcontra) hh + · rw [hs, hi, ho, hvec] + refine ih _ _ _ ?_ ?_ ?_ ?_ ?_ · rfl · rfl · rfl diff --git a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Sim.lean b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Sim.lean index 63d9f051..988fea49 100644 --- a/Complexitylib/Models/TuringMachine/SingleTape/Internal/Sim.lean +++ b/Complexitylib/Models/TuringMachine/SingleTape/Internal/Sim.lean @@ -5,8 +5,8 @@ Authors: Samuel Schlesinger -/ module -public import Mathlib.Data.Finite.Prod -public import Mathlib.Data.Finite.Sum +public import Mathlib.Basic.Finite.Prod +public import Mathlib.Basic.Finite.Sum public import Complexitylib.Models.TuringMachine /-! diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryAdd/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryAdd/Internal.lean index 152493a8..35ecd238 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryAdd/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryAdd/Internal.lean @@ -382,10 +382,9 @@ private theorem binaryAddIteration_reachesIn have hseq := seqTM_reachesIn_of_reachesIn body succ hbody rfl hcounter' have hlift := binaryForTM_iteration_reachesIn_internal (binarySuccTM dstIdx) counterIdx srcIdx hseq - simpa [body, succ, binaryAddLoopTM, binaryAddIterationStartCfg, - binaryAddIterationDoneCfg, binaryForIterationTime, - binaryForIterationTM, binaryForIterationWrap, phase1Wrap, phase2Wrap] - using hlift + simp [binaryAddLoopTM, binaryAddIterationStartCfg, binaryAddIterationDoneCfg, + binaryForIterationTime, binaryForIterationTM] + exact hlift private theorem binaryAddLoopback_step (srcIdx dstIdx counterIdx : Fin n) @@ -614,7 +613,7 @@ private theorem binaryAddWorkAt_cfg_withinAuxSpace exact hworkSpace i · exact hinputSpace -private def binaryAddLoopSpaceSpec +private theorem binaryAddLoopSpaceSpec (srcIdx dstIdx counterIdx : Fin n) (hsrcDst : srcIdx ≠ dstIdx) (hsrcCounter : srcIdx ≠ counterIdx) (hdstCounter : dstIdx ≠ counterIdx) @@ -642,7 +641,7 @@ private def binaryAddLoopSpaceSpec have hreach' : (binaryAddLoopTM srcIdx dstIdx counterIdx).reachesIn time (binaryAddScanCfg srcIdx dstIdx counterIdx inp₀ work₀ out₀ dstValue current) cfg := by - simpa [binaryAddLoopSpec] using hreach + exact hreach exact (hstart.reachesIn hreach').mono le_rfl (by simp [binaryForCompareTime, binaryAddLoopSpace] at htime ⊢ omega) @@ -660,7 +659,7 @@ private def binaryAddLoopSpaceSpec have hreach' : (binaryAddLoopTM srcIdx dstIdx counterIdx).reachesIn time (binaryAddIterationStartCfg srcIdx dstIdx counterIdx inp₀ work₀ out₀ dstValue current) cfg := by - simpa [binaryAddLoopSpec] using hreach + exact hreach have hcounterTime := binarySuccTime_le current have hdstTime := binarySuccTime_le (dstValue + current) have hcounterSize := Nat.size_le_size (Nat.le_of_lt hcurrent) @@ -727,7 +726,7 @@ private theorem binaryAddLoopTM_hoareSpace hsrcCounter hdstCounter srcValue dstValue inputLength initialSpace inp₀ work₀ out₀ hsrc hcounter hinp hwork hout hworkSpace hinputSpace exact spaceSpec.prefix_withinAuxSpace srcValue 0 time c (by omega) - (by simpa [spaceSpec, spec] using hreachSpec) htime + (by exact hreachSpec) htime private theorem binaryAddLoopTM_hoareTimeSpace (srcIdx dstIdx counterIdx : Fin n) diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryAddConst/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryAddConst/Internal.lean index f7dae267..2e82c3af 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryAddConst/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryAddConst/Internal.lean @@ -232,8 +232,8 @@ theorem binaryAddConstTM_reachesIn_frame_internal funext fun i => (hprevWork i).transitionTape_eq_self] using hnext have hseq := seqTM_reachesIn_of_reachesIn (binaryAddConstTM idx constant) (binarySuccTM idx) hprev rfl hnext' - simpa [binaryAddConstTM, binaryAddConstTime, binaryAddConstNatTape, - binaryAddConstWorkAt] using hseq + simp only [binaryAddConstTM, binaryAddConstTime, binaryAddConstNatTape] + exact hseq theorem binaryAddConstTM_hoareTime_frame_internal (idx : Fin n) (constant dstValue : ℕ) diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Defs.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Defs.lean index f54df903..ddcd3bb5 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Defs.lean @@ -126,14 +126,14 @@ def binaryBumpTM {n : ℕ} (idx : Fin n) : TM n where · subst i rw [htarget] at hi exact absurd hi (by decide) - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .start => simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .rewind => dsimp only @@ -141,8 +141,8 @@ def binaryBumpTM {n : ℕ} (idx : Fin n) : TM n where · simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi · next hnotStart => simp only @@ -150,7 +150,7 @@ def binaryBumpTM {n : ℕ} (idx : Fin n) : TM n where by_cases hitarget : i = idx · subst i exact absurd hi hnotStart - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .done => exact rightOfStart_allIdle iHead wHeads oHead diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Internal.lean index c395a4bb..668147c1 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryBump/Internal.lean @@ -105,7 +105,7 @@ private theorem binaryBumpTM_step_one (c : Cfg n (binaryBumpTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.zero).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryBumpTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryBumpTM_ne_halt (by decide) hstate)] simp only [binaryBumpTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -115,7 +115,8 @@ private theorem binaryBumpTM_step_one (c : Cfg n (binaryBumpTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Resolve a carry on zero: write one and turn left. -/ @@ -130,7 +131,7 @@ private theorem binaryBumpTM_step_zero (c : Cfg n (binaryBumpTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.one).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryBumpTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryBumpTM_ne_halt (by decide) hstate)] simp only [binaryBumpTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -140,7 +141,8 @@ private theorem binaryBumpTM_step_zero (c : Cfg n (binaryBumpTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Resolve overflow on the terminating blank: append a zero — widening the string — and turn @@ -156,7 +158,7 @@ private theorem binaryBumpTM_step_blank (c : Cfg n (binaryBumpTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.zero).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryBumpTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryBumpTM_ne_halt (by decide) hstate)] simp only [binaryBumpTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -166,7 +168,8 @@ private theorem binaryBumpTM_step_blank (c : Cfg n (binaryBumpTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, Γ.ofBool, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Rewind one ordinary target cell to the left. -/ @@ -180,16 +183,16 @@ private theorem binaryBumpTM_step_rewind (c : Cfg n (binaryBumpTM idx).Q) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryBumpTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryBumpTM_ne_halt (by decide) hstate)] simp only [binaryBumpTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hi : i = idx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hread] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -205,7 +208,7 @@ private theorem binaryBumpTM_step_start (c : Cfg n (binaryBumpTM idx).Q) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryBumpTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryBumpTM_ne_halt (by decide) hstate)] simp only [binaryBumpTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -215,8 +218,8 @@ private theorem binaryBumpTM_step_start (c : Cfg n (binaryBumpTM idx).Q) simp only [↓reduceIte, Function.update_self] show (((c.work idx).write _).move Dir3.right) = (c.work idx).move Dir3.right - rw [Tape.write, if_pos hhead] - · rw [if_neg hi, Function.update_of_ne hi] + rw [Tape.write, ite_eq_left hhead] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -349,7 +352,7 @@ private theorem binaryBumpTM_carry_run have htargetContent : target.HasBinaryContent (List.replicate done false ++ [false]) := by have hwrite := hcontent'.write_append false (by simpa using hhead) - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using hwrite + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.zero Dir3.left hcell0 have htargetHead : target.head = done := by @@ -399,7 +402,7 @@ private theorem binaryBumpTM_carry_run (List.replicate done false ++ true :: rest) := by have hwrite := hcontent.write_set true hhead (by simp) rw [BinaryBump.set_false_to_true] at hwrite - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using hwrite + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.one Dir3.left hcell0 have htargetHead : target.head = done := by @@ -447,7 +450,7 @@ private theorem binaryBumpTM_carry_run (List.replicate (done + 1) false ++ rest) := by have hwrite := hcontent.write_set false hhead (by simp) rw [BinaryBump.set_true_to_false] at hwrite - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using hwrite + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.zero Dir3.right hcell0 have htargetHead : target.head = (done + 1) + 1 := by diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryEq/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryEq/Internal.lean index 25d31684..62127b99 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryEq/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryEq/Internal.lean @@ -71,35 +71,35 @@ private theorem binaryEq_terminal_step {n : ℕ} simp only [TM.step, binaryEqTM] cases result with | false => - simp only [Bool.false_eq_true, if_false] at hterminal + simp only [Bool.false_eq_true, ite_false] at hterminal have hnotBlank : ¬((work lhsIdx).read = Γ.blank ∧ (work rhsIdx).read = Γ.blank) := by intro hblank exact hterminal (hblank.1.trans hblank.2.symm) - rw [if_neg hnotBlank, if_neg hterminal] + rw [ite_eq_right hnotBlank, ite_eq_right hterminal] simp only [show BinaryEqPhase.scan ≠ BinaryEqPhase.done by decide, - if_false] + ite_false] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) funext i by_cases hi : i = resultIdx · subst i simp [binaryEqResultCfg, binaryEqResultWork, Γw.ofBool] - · simpa [binaryEqResultCfg, binaryEqResultWork, hi] using + · simpa [transitionTape, binaryEqResultCfg, binaryEqResultWork, hi] using transitionTape_eq_self (hwork i hi) | true => - simp only [if_true] at hterminal - rw [if_pos hterminal] + simp only [ite_true] at hterminal + rw [ite_eq_left hterminal] simp only [show BinaryEqPhase.scan ≠ BinaryEqPhase.done by decide, - if_false] + ite_false] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) funext i by_cases hi : i = resultIdx · subst i simp [binaryEqResultCfg, binaryEqResultWork, Γw.ofBool] - · simpa [binaryEqResultCfg, binaryEqResultWork, hi] using + · simpa [transitionTape, binaryEqResultCfg, binaryEqResultWork, hi] using transitionTape_eq_self (hwork i hi) private theorem binaryEq_scan_step {n : ℕ} @@ -115,20 +115,20 @@ private theorem binaryEq_scan_step {n : ℕ} { state := .scan, input := inp, work := work, output := out } = some (binaryEqAdvanceCfg lhsIdx rhsIdx inp work out) := by simp only [TM.step, binaryEqTM] - rw [if_neg hnotBlank, if_pos hreadEq] - simp only [show BinaryEqPhase.scan ≠ BinaryEqPhase.done by decide, if_false] + rw [ite_eq_right hnotBlank, ite_eq_left hreadEq] + simp only [show BinaryEqPhase.scan ≠ BinaryEqPhase.done by decide, ite_false] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) funext i by_cases hil : i = lhsIdx · subst i - simp only [binaryEqAdvanceCfg, binaryEqAdvanceWork, if_pos] + simp only [binaryEqAdvanceCfg, binaryEqAdvanceWork, ite_eq_left] exact writeAndMove_readBack_right (hwork lhsIdx) · by_cases hir : i = rhsIdx · subst i - simp only [binaryEqAdvanceCfg, binaryEqAdvanceWork, if_neg hil, if_pos] + simp only [binaryEqAdvanceCfg, binaryEqAdvanceWork, ite_eq_right hil, ite_eq_left] exact writeAndMove_readBack_right (hwork rhsIdx) - · simpa [binaryEqAdvanceCfg, binaryEqAdvanceWork, hil, hir] using + · simpa [transitionTape, binaryEqAdvanceCfg, binaryEqAdvanceWork, hil, hir] using transitionTape_eq_self (hwork i) private theorem binaryEq_terminal_reachesIn {n : ℕ} @@ -181,10 +181,10 @@ private theorem binaryEq_terminal_reachesIn {n : ℕ} · rw [hdecision] cases result with | false => - simpa [c', binaryEqResultCfg, binaryEqResultWork, Γw.ofBool] using + simpa [Γ.ofBool, c', binaryEqResultCfg, binaryEqResultWork, Γw.ofBool] using Tape.hasBinaryPrefix_write_bit false hresult | true => - simpa [c', binaryEqResultCfg, binaryEqResultWork, Γw.ofBool] using + simpa [Γ.ofBool, c', binaryEqResultCfg, binaryEqResultWork, Γw.ofBool] using Tape.hasBinaryPrefix_write_bit true hresult · change (Function.update work₀ resultIdx _ lhsIdx).cells = _ rw [Function.update_of_ne hdistinct.lhs_result] @@ -288,7 +288,7 @@ private theorem binaryEq_suffix_reachesIn {n : ℕ} simpa [work₁, binaryEqAdvanceWork] using hlhs.move_right_cons have hrhs₁ : (work₁ rhsIdx).HasBinarySuffix rhsTail := by simp only [work₁, binaryEqAdvanceWork, - if_neg (Ne.symm hdistinct.lhs_rhs), if_pos] + ite_eq_right (Ne.symm hdistinct.lhs_rhs), ite_eq_left] exact hrhs.move_right_cons have hresult₁ : (work₁ resultIdx).HasBinaryPrefix [] := by simpa [work₁, binaryEqAdvanceWork, @@ -310,7 +310,7 @@ private theorem binaryEq_suffix_reachesIn {n : ℕ} work := work₀ output := out₀ } c' := by exact .step hstep (by - simpa [work₁, binaryEqAdvanceCfg] using hreach) + simpa [work₁, binaryEqAdvanceCfg, binaryEqAdvanceWork, binaryEqTM] using hreach) refine ⟨c', t + 1, ?_, hreach', hhalt, hfinalInput, ?_, ?_, ?_, hfinalLhsHead, hfinalRhsHead, ?_, hfinalOutput⟩ · simp only [binaryEqTime, List.length_cons] at htime ⊢ diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Defs.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Defs.lean index af89ab54..04a7c890 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Defs.lean @@ -145,22 +145,22 @@ def binaryForTM {n : ℕ} (body : TM n) (counterIdx limitIdx : Fin n) : TM n := · subst i rw [hblank.1] at hi exact absurd hi (by decide) - · rw [if_neg hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx · subst i rw [hblank.2] at hi exact absurd hi (by decide) - · rw [if_neg hil] + · rw [ite_eq_right hil] exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only by_cases hic : i = counterIdx - · rw [if_pos hic] - · rw [if_neg hic] + · rw [ite_eq_left hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx - · rw [if_pos hil] - · rw [if_neg hil] + · rw [ite_eq_left hil] + · rw [ite_eq_right hil] exact idleDir_right_of_start hi | .inl (.rewind equalSoFar) => dsimp only @@ -169,23 +169,23 @@ def binaryForTM {n : ℕ} (body : TM n) (counterIdx limitIdx : Fin n) : TM n := idleDir_right_of_start⟩ dsimp only by_cases hic : i = counterIdx - · rw [if_pos hic] - · rw [if_neg hic] + · rw [ite_eq_left hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx - · rw [if_pos hil] - · rw [if_neg hil] + · rw [ite_eq_left hil] + · rw [ite_eq_right hil] exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only by_cases hic : i = counterIdx - · rw [if_pos hic] + · rw [ite_eq_left hic] exact moveLeftDir_right_of_start hi - · rw [if_neg hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx - · rw [if_pos hil] + · rw [ite_eq_left hil] exact moveLeftDir_right_of_start hi - · rw [if_neg hil] + · rw [ite_eq_right hil] exact idleDir_right_of_start hi | .inl .done => exact rightOfStart_allIdle iHead wHeads oHead | .inr q => diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Comparison.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Comparison.lean index c42eb3de..d14c20c5 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Comparison.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Comparison.lean @@ -38,12 +38,12 @@ private def paddedBinarySymbol (bits : List Bool) (i : ℕ) : Γ := private theorem paddedBinarySymbol_of_lt {bits : List Bool} {i : ℕ} (h : i < bits.length) : paddedBinarySymbol bits i = Γ.ofBool bits[i] := by - simp only [paddedBinarySymbol, dif_pos h] + simp only [paddedBinarySymbol, dite_eq_left h] private theorem paddedBinarySymbol_of_ge {bits : List Bool} {i : ℕ} (h : bits.length ≤ i) : paddedBinarySymbol bits i = Γ.blank := by - simp only [paddedBinarySymbol, dif_neg (Nat.not_lt.mpr h)] + simp only [paddedBinarySymbol, dite_eq_right (Nat.not_lt.mpr h)] /-- Boolean equality accumulated through the first `width` padded symbols. -/ private def paddedBinaryPrefixEq (left right : List Bool) : ℕ → Bool @@ -406,7 +406,7 @@ private theorem binaryForCompareCfg_step_scan_blank limitIdx hne equalSoFar c rfl hcounterRead hlimitRead hinp hwork hout dsimp only [c, binaryForCompareCfg] at hstep rw [binaryForWorkAt_move_left work hne] at hstep - simpa using hstep + simpa [binaryForCompareCfg] using hstep private theorem binaryForCompareCfg_step_rewind (body : TM n) (work : Fin n → Tape) @@ -434,7 +434,7 @@ private theorem binaryForCompareCfg_step_rewind hne equalSoFar c rfl hinp hwork hout dsimp only [c, binaryForCompareCfg] at hstep rw [binaryForWorkAt_move_left work hne] at hstep - simpa using hstep + simpa [binaryForCompareCfg] using hstep private theorem binaryForCompareCfg_rewind_reachesIn (body : TM n) (work : Fin n → Tape) @@ -709,12 +709,14 @@ theorem binaryForTM_compare_reachesIn_frame_internal refine ⟨_, hrun, rfl, rfl, rfl, ?_, ?_⟩ · simp · simp + rfl · have hlt : value < limitValue := by omega have hrun := binaryForTM_compare_reachesIn_frame_of_lt_internal body counterIdx limitIdx hne value limitValue hlt inp₀ work₀ out₀ hcounter hlimit hinp hother hout refine ⟨_, hrun, rfl, rfl, rfl, ?_, ?_⟩ · simp [hlt] + rfl · simp [heq] end TM diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Control.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Control.lean index af8162c1..e3c0a034 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Control.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Control.lean @@ -50,11 +50,12 @@ theorem binaryForTM_iteration_step_internal (body : TM n) some (binaryForIterationWrap body counterIdx limitIdx c') := by have hne : c.state ≠ (binaryForIterationTM body counterIdx).qhalt := state_ne_qhalt_of_step hstep - rw [TM.step, if_neg (by simp [binaryForIterationWrap, binaryForTM])] + rw [TM.step, ite_eq_right (by simp [binaryForIterationWrap, binaryForTM])] simp only [binaryForIterationWrap, binaryForTM, hne, ↓reduceIte] - rw [TM.step, if_neg hne] at hstep - simpa only [Option.map_some, binaryForIterationWrap] using - congrArg (Option.map (binaryForIterationWrap body counterIdx limitIdx)) hstep + rw [TM.step, ite_eq_right hne] at hstep + injection hstep with hstep' + subst hstep' + rfl /-- Exact runs of the composite iteration lift through the iteration phase of `binaryForTM`. -/ @@ -88,23 +89,23 @@ theorem binaryForTM_step_scan_internal (body : TM n) (Function.update c.work counterIdx ((c.work counterIdx).move Dir3.right)) limitIdx ((c.work limitIdx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [binaryForTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [binaryForTM])] simp only [binaryForTM, hstate] - rw [if_neg hmore] + rw [ite_eq_right hmore] dsimp only refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hic : i = counterIdx · subst i - rw [if_pos rfl, Function.update_of_ne hne, Function.update_self, + rw [ite_eq_left rfl, Function.update_of_ne hne, Function.update_self, writeAndMove_readBack _ (hwork counterIdx)] - · rw [if_neg hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (hwork limitIdx)] - · rw [if_neg hil, Function.update_of_ne hil, Function.update_of_ne hic] + · rw [ite_eq_right hil, Function.update_of_ne hil, Function.update_of_ne hic] exact transitionTape_eq_self (hwork i) · exact transitionTape_eq_self houtput @@ -126,23 +127,23 @@ theorem binaryForTM_step_scan_blank_internal (body : TM n) (Function.update c.work counterIdx ((c.work counterIdx).move Dir3.left)) limitIdx ((c.work limitIdx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [binaryForTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [binaryForTM])] simp only [binaryForTM, hstate] - rw [if_pos ⟨hcounter, hlimit⟩] + rw [ite_eq_left ⟨hcounter, hlimit⟩] dsimp only refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hic : i = counterIdx · subst i - rw [if_pos rfl, Function.update_of_ne hne, Function.update_self, + rw [ite_eq_left rfl, Function.update_of_ne hne, Function.update_self, writeAndMove_readBack _ (hwork counterIdx)] - · rw [if_neg hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (hwork limitIdx)] - · rw [if_neg hil, Function.update_of_ne hil, Function.update_of_ne hic] + · rw [ite_eq_right hil, Function.update_of_ne hil, Function.update_of_ne hic] exact transitionTape_eq_self (hwork i) · exact transitionTape_eq_self houtput @@ -162,29 +163,29 @@ theorem binaryForTM_step_rewind_internal (body : TM n) (Function.update c.work counterIdx ((c.work counterIdx).move Dir3.left)) limitIdx ((c.work limitIdx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [binaryForTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [binaryForTM])] have hnotboth : ¬((c.work counterIdx).read = Γ.start ∧ (c.work limitIdx).read = Γ.start) := by intro h exact hwork counterIdx h.1 simp only [binaryForTM, hstate] - rw [if_neg hnotboth] + rw [ite_eq_right hnotboth] dsimp only refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hic : i = counterIdx · subst i - rw [if_pos rfl, Function.update_of_ne hne, Function.update_self, + rw [ite_eq_left rfl, Function.update_of_ne hne, Function.update_self, writeAndMove_readBack _ (hwork counterIdx)] simp [moveLeftDir, hwork counterIdx] - · rw [if_neg hic] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (hwork limitIdx)] simp [moveLeftDir, hwork limitIdx] - · rw [if_neg hil, Function.update_of_ne hil, Function.update_of_ne hic] + · rw [ite_eq_right hil, Function.update_of_ne hil, Function.update_of_ne hic] exact transitionTape_eq_self (hwork i) · exact transitionTape_eq_self houtput @@ -209,27 +210,27 @@ theorem binaryForTM_step_rewind_equal_internal (body : TM n) (Function.update c.work counterIdx ((c.work counterIdx).move Dir3.right)) limitIdx ((c.work limitIdx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [binaryForTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [binaryForTM])] simp only [binaryForTM, hstate] - rw [if_pos ⟨hcounter, hlimit⟩] + rw [ite_eq_left ⟨hcounter, hlimit⟩] dsimp only refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hic : i = counterIdx · subst i - rw [if_pos rfl, Function.update_of_ne hne, Function.update_self] + rw [ite_eq_left rfl, Function.update_of_ne hne, Function.update_self] show (((c.work counterIdx).write _).move Dir3.right) = (c.work counterIdx).move Dir3.right - rw [Tape.write, if_pos hcounterHead] - · rw [if_neg hic] + rw [Tape.write, ite_eq_left hcounterHead] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx · subst i - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show (((c.work limitIdx).write _).move Dir3.right) = (c.work limitIdx).move Dir3.right - rw [Tape.write, if_pos hlimitHead] - · rw [if_neg hil, Function.update_of_ne hil, Function.update_of_ne hic] + rw [Tape.write, ite_eq_left hlimitHead] + · rw [ite_eq_right hil, Function.update_of_ne hil, Function.update_of_ne hic] exact transitionTape_eq_self (hother i hic hil) · exact transitionTape_eq_self houtput @@ -255,27 +256,27 @@ theorem binaryForTM_step_rewind_unequal_internal (body : TM n) (Function.update c.work counterIdx ((c.work counterIdx).move Dir3.right)) limitIdx ((c.work limitIdx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (by rw [hstate]; simp [binaryForTM])] + rw [TM.step, ite_eq_right (by rw [hstate]; simp [binaryForTM])] simp only [binaryForTM, hstate] - rw [if_pos ⟨hcounter, hlimit⟩] + rw [ite_eq_left ⟨hcounter, hlimit⟩] dsimp only refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hic : i = counterIdx · subst i - rw [if_pos rfl, Function.update_of_ne hne, Function.update_self] + rw [ite_eq_left rfl, Function.update_of_ne hne, Function.update_self] show (((c.work counterIdx).write _).move Dir3.right) = (c.work counterIdx).move Dir3.right - rw [Tape.write, if_pos hcounterHead] - · rw [if_neg hic] + rw [Tape.write, ite_eq_left hcounterHead] + · rw [ite_eq_right hic] by_cases hil : i = limitIdx · subst i - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show (((c.work limitIdx).write _).move Dir3.right) = (c.work limitIdx).move Dir3.right - rw [Tape.write, if_pos hlimitHead] - · rw [if_neg hil, Function.update_of_ne hil, Function.update_of_ne hic] + rw [Tape.write, ite_eq_left hlimitHead] + · rw [ite_eq_right hil, Function.update_of_ne hil, Function.update_of_ne hic] exact transitionTape_eq_self (hother i hic hil) · exact transitionTape_eq_self houtput @@ -294,7 +295,7 @@ theorem binaryForTM_step_iteration_halt_internal (body : TM n) input := c.input work := c.work output := c.output } := by - rw [TM.step, if_neg (by simp [binaryForIterationWrap, binaryForTM])] + rw [TM.step, ite_eq_right (by simp [binaryForIterationWrap, binaryForTM])] simp only [binaryForIterationWrap, binaryForTM, hhalt, allReadBack, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Hoare.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Hoare.lean index 4b1c067c..a33038c7 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Hoare.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryFor/Internal/Hoare.lean @@ -251,10 +251,10 @@ theorem guessProtocol_binaryForTM_internal {k : ℕ} {body : TM (k + 1)} {Adv : match q with | .inl (.scan e) => dsimp only [binaryForTM, binaryForAdv] - split <;> simp [hc, hl, idleDir, hg] + split <;> simp [hc, hl, idleDir, hg] <;> rfl | .inl (.rewind e) => dsimp only [binaryForTM, binaryForAdv] - split <;> simp [hc, hl, idleDir, hg] + split <;> simp [hc, hl, idleDir, hg] <;> rfl | .inl .done => exact absurd rfl hq | .inr q => by_cases hqh : q = (binaryForIterationTM body counterIdx).qhalt @@ -262,7 +262,8 @@ theorem guessProtocol_binaryForTM_internal {k : ℕ} {body : TM (k + 1)} {Adv : simp [binaryForTM, binaryForAdv, seqAdv, allReadBack, idleDir, hg, binaryForIterationTM, seqTM] · have h := hiter.dir q hqh iHead wHeads oHead hg - simpa [binaryForTM, binaryForAdv, hqh] using h + simp [binaryForTM, binaryForAdv, hqh] + exact h · intro q hq hadv iHead ww oHead g g' obtain ⟨jc, hjc⟩ := Fin.exists_castSucc_eq.mpr hcounter obtain ⟨jl, hjl⟩ := Fin.exists_castSucc_eq.mpr hlimit @@ -282,7 +283,10 @@ theorem guessProtocol_binaryForTM_internal {k : ℕ} {body : TM (k + 1)} {Adv : by_cases hqh : q = (binaryForIterationTM body counterIdx).qhalt · subst hqh simp [binaryForTM, visible, allReadBack, Fin.snoc_castSucc] - · have h := hiter.indep q hqh (by simpa [binaryForAdv] using hadv) iHead ww + · have hadv' : ¬seqAdv Adv (fun _ => false) q = true := by + simp only [binaryForAdv, Bool.not_eq_true] at hadv ⊢ + exact hadv + have h := hiter.indep q hqh hadv' iHead ww oHead g g' simpa [binaryForTM, visible, hqh] using h diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryLength/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryLength/Internal.lean index 7fe3733b..9f3f1d34 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryLength/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryLength/Internal.lean @@ -144,7 +144,8 @@ private theorem binaryLengthTM_scan_bit_step (x : List Bool) exact Γ.ofBool_ne_blank _) (fun i => binaryLengthWork_read_ne_start counterIdx value i) binaryLengthStartedBlank_read_ne_start - simpa [binaryLengthTM, binaryLengthScanCfg, binaryLengthBodyStartCfg, + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, binaryLengthScanCfg, binaryLengthBodyStartCfg, forInputBodyWrap, binaryLengthInput, Tape.move] using hstep private theorem binaryLengthTM_scan_blank_step (x : List Bool) @@ -159,7 +160,8 @@ private theorem binaryLengthTM_scan_blank_step (x : List Bool) exact binaryLengthInput_read_blank x) (fun i => binaryLengthWork_read_ne_start counterIdx x.length i) binaryLengthStartedBlank_read_ne_start - simpa [binaryLengthTM, binaryLengthScanCfg, binaryLengthDoneCfg] using hstep + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, binaryLengthScanCfg, binaryLengthDoneCfg] using hstep private theorem binaryLengthTM_body_run (x : List Bool) (counterIdx : Fin n) (value : ℕ) : @@ -201,7 +203,8 @@ private theorem binaryLengthTM_loopback_step (x : List Bool) (binaryLengthInput_read_ne_start x (value + 2) (by omega)) (fun i => binaryLengthWork_read_ne_start counterIdx (value + 1) i) binaryLengthStartedBlank_read_ne_start - simpa [binaryLengthTM, binaryLengthBodyDoneCfg, binaryLengthScanCfg, + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, binaryLengthBodyDoneCfg, binaryLengthScanCfg, forInputBodyWrap, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] using hstep private def binaryLengthLoopSpec (x : List Bool) (counterIdx : Fin n) : @@ -217,7 +220,8 @@ private def binaryLengthLoopSpec (x : List Bool) (counterIdx : Fin n) : scanStep := fun value hvalue => binaryLengthTM_scan_bit_step x counterIdx value hvalue bodyRun := fun value _ => by - simpa [binaryLengthTM, Experimental.binaryLengthRoutine, + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, Experimental.binaryLengthRoutine, Experimental.Routine.lower] using forInputTM_body_reachesIn_internal (binarySuccTM counterIdx) (binaryLengthTM_body_run x counterIdx value) @@ -253,7 +257,8 @@ private theorem binaryLengthDoneCfg_withinAuxSpace (x : List Bool) (counterIdx : Fin n) : (binaryLengthDoneCfg x counterIdx).WithinAuxSpace x.length (binaryLengthSpace x.length) := by - simpa [binaryLengthDoneCfg, binaryLengthScanCfg] using + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, binaryLengthDoneCfg, binaryLengthScanCfg] using binaryLengthScanCfg_withinAuxSpace x counterIdx x.length le_rfl private theorem binaryLengthBodyStartCfg_withinAuxSpace (x : List Bool) @@ -298,7 +303,7 @@ private theorem binaryLengthBodyPrefix_withinAuxSpace (x : List Bool) _ = binaryLengthSpace x.length := by simp [binaryLengthSpace] -private def binaryLengthLoopSpaceSpec (x : List Bool) (counterIdx : Fin n) : +private theorem binaryLengthLoopSpaceSpec (x : List Bool) (counterIdx : Fin n) : ForInputLoopSpaceSpec (binaryLengthLoopSpec x counterIdx) x.length (binaryLengthSpace x.length) where scanWithin := fun value hvalue => @@ -316,7 +321,8 @@ private def binaryLengthLoopSpaceSpec (x : List Bool) (counterIdx : Fin n) : have hc := (forInputTM (binarySuccTM counterIdx)).reachesIn_right_unique hreach hcanonical rw [hc] - simpa [forInputBodyWrap] using + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, forInputBodyWrap] using binaryLengthBodyPrefix_withinAuxSpace x counterIdx value t d hvalue hprefix @@ -327,7 +333,8 @@ private theorem binaryLengthTM_loop (x : List Bool) (counterIdx : Fin n) : (binaryLengthScanCfg x counterIdx value) (binaryLengthDoneCfg x counterIdx) := by intro count value hlength - simpa [binaryLengthTM, Experimental.binaryLengthRoutine, + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, Experimental.binaryLengthRoutine, Experimental.Routine.lower, binaryLengthLoopTime, binaryLengthLoopSpec] using (binaryLengthLoopSpec x counterIdx).reachesIn_internal @@ -344,7 +351,8 @@ private theorem binaryLengthTM_loop_withinAuxSpace (x : List Bool) intro count value t c hlength hreach htime have hreach' : (forInputTM (binarySuccTM counterIdx)).reachesIn t ((binaryLengthLoopSpec x counterIdx).scanCfg value) c := by - simpa [binaryLengthTM, Experimental.binaryLengthRoutine, + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, Experimental.binaryLengthRoutine, Experimental.Routine.lower, binaryLengthLoopSpec] using hreach exact (binaryLengthLoopSpaceSpec x counterIdx).prefix_withinAuxSpace_internal @@ -430,7 +438,8 @@ theorem binaryLengthTM_reachesIn_frame_internal (counterIdx : Fin n) rw [binaryLengthWork_counter] exact binaryLengthCounterTape_hasBinaryNat x.length · intro i hi - simpa [binaryLengthStartedBlank] using + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, binaryLengthDoneCfg, binaryLengthStartedBlank] using binaryLengthWork_other counterIdx x.length i hi theorem binaryLengthTM_hoareTime_internal (counterIdx : Fin n) @@ -456,7 +465,8 @@ theorem binaryLengthTM_hoareTime_internal (counterIdx : Fin n) rw [binaryLengthWork_counter] exact binaryLengthCounterTape_hasBinaryNat x.length · intro i hi - simpa [binaryLengthStartedBlank] using + simpa [binaryLengthTM, Experimental.binaryLengthRoutine, Experimental.Routine.lower, + Cfg.WithinAuxSpace, binaryLengthDoneCfg, binaryLengthStartedBlank] using binaryLengthWork_other counterIdx x.length i hi theorem binaryLengthTM_hoareTimeSpace_internal (counterIdx : Fin n) diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryMulAdd/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryMulAdd/Internal.lean index 3f3b7ee4..cad0fe4c 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryMulAdd/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryMulAdd/Internal.lean @@ -549,10 +549,9 @@ private theorem binaryMulAddIteration_reachesIn have hseq := seqTM_reachesIn_of_reachesIn body succ hbody rfl hcounter' have hlift := binaryForTM_iteration_reachesIn_internal body mulCounterIdx rightIdx hseq - simpa [body, succ, binaryMulAddLoopTM, binaryMulAddBodyTimeFn, - binaryMulAddIterationStartCfg, binaryMulAddIterationDoneCfg, - binaryForIterationTime, binaryForIterationTM, binaryForIterationWrap, - phase1Wrap, phase2Wrap] using hlift + simp [binaryMulAddLoopTM, binaryMulAddBodyTimeFn, binaryMulAddIterationStartCfg, + binaryMulAddIterationDoneCfg, binaryForIterationTime, binaryForIterationTM] + exact hlift private theorem binaryMulAddLoopback_step (leftIdx rightIdx accIdx mulCounterIdx addCounterIdx : Fin n) @@ -778,8 +777,8 @@ private theorem binaryMulAddLoopTM_hoareTime output := out₀ } refine ⟨c', binaryForLoopTime bodyTime rightValue 0 rightValue, htime, ?_, rfl, rfl, rfl, rfl⟩ - simpa [spec, binaryMulAddLoopSpec, binaryMulAddDoneCfg, bodyTime, - binaryMulAddLoopTM, binaryForTM] using hrun + simp [bodyTime, binaryMulAddLoopTM, binaryForTM] + exact hrun private theorem binaryMulAddWorkAt_cfg_withinAuxSpace {Q : Type} (state : Q) (inp : Tape) (work : Fin n → Tape) @@ -1090,8 +1089,8 @@ private theorem binaryMulAddIterationInner_reachesIn rw [hinpTransition, hworkTransition, houtTransition] exact hcounter have hseq := seqTM_reachesIn_of_reachesIn body succ hbody rfl hcounter' - simpa [body, succ, binaryMulAddBodyTimeFn, binaryForIterationTime, - binaryForIterationTM, phase1Wrap, phase2Wrap] using hseq + simp [binaryMulAddBodyTimeFn, binaryForIterationTime, binaryForIterationTM] + exact hseq private theorem binaryAddSpace_mono_destination (initialSpace leftValue dst₁ dst₂ : ℕ) (hle : dst₁ ≤ dst₂) : @@ -1102,7 +1101,7 @@ private theorem binaryAddSpace_mono_destination simp [binaryAddSpace, binaryAddLoopSpace] omega -private noncomputable def binaryMulAddLoopSpaceSpec +private theorem binaryMulAddLoopSpaceSpec (leftIdx rightIdx accIdx mulCounterIdx addCounterIdx : Fin n) (hdistinct : BinaryMulAddDistinct leftIdx rightIdx accIdx mulCounterIdx addCounterIdx) @@ -1140,7 +1139,7 @@ private noncomputable def binaryMulAddLoopSpaceSpec (binaryMulAddScanCfg leftIdx rightIdx accIdx mulCounterIdx addCounterIdx inp₀ work₀ out₀ leftValue accValue current) cfg := by - simpa [binaryMulAddLoopSpec] using hreach + exact hreach exact (hstart.reachesIn hreach').mono le_rfl (by simp [binaryForCompareTime, binaryMulAddLoopSpace, binaryAddSpace, binaryAddLoopSpace] at htime ⊢ @@ -1185,7 +1184,7 @@ private noncomputable def binaryMulAddLoopSpaceSpec (binaryMulAddIterationStartCfg leftIdx rightIdx accIdx mulCounterIdx addCounterIdx inp₀ work₀ out₀ leftValue accValue current) cfg := by - simpa [binaryMulAddLoopSpec] using hreach + exact hreach have hc : cfg = binaryForIterationWrap body mulCounterIdx rightIdx d := (binaryMulAddLoopTM leftIdx rightIdx accIdx mulCounterIdx addCounterIdx).reachesIn_right_unique hreach' hcanonical @@ -1214,7 +1213,8 @@ private noncomputable def binaryMulAddLoopSpaceSpec simp only [binaryMulAddLoopSpace] omega rw [hc] - simpa [binaryForIterationWrap] using hd.mono le_rfl hspace + simp [binaryForIterationWrap] + exact hd.mono le_rfl hspace private theorem binaryMulAddLoopTM_hoareSpace (leftIdx rightIdx accIdx mulCounterIdx addCounterIdx : Fin n) @@ -1281,7 +1281,7 @@ private theorem binaryMulAddLoopTM_hoareSpace inputLength initialSpace inp₀ work₀ out₀ hleft hright hmulCounter haddCounter hinp hwork hout hworkSpace hinputSpace exact spaceSpec.prefix_withinAuxSpace rightValue 0 time c (by omega) - (by simpa [spaceSpec, spec] using hreachSpec) htime + (by exact hreachSpec) htime private theorem binaryMulAddLoopTM_hoareTimeSpace (leftIdx rightIdx accIdx mulCounterIdx addCounterIdx : Fin n) diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryPolynomial/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryPolynomial/Internal.lean index 7a926c78..17237848 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryPolynomial/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryPolynomial/Internal.lean @@ -73,7 +73,7 @@ private def binaryHornerWork (work : Fin n → Tape) targetIdx sourceIdx inputValue coeffs (accValue * inputValue + coeff) -private def swapBinaryMulAddDistinct +private theorem swapBinaryMulAddDistinct {leftIdx rightIdx accIdx mulCounterIdx addCounterIdx : Fin n} (h : BinaryMulAddDistinct leftIdx rightIdx accIdx mulCounterIdx addCounterIdx) : @@ -89,7 +89,7 @@ private def swapBinaryMulAddDistinct acc_ne_addCounter := h.left_ne_addCounter mulCounter_ne_addCounter := h.mulCounter_ne_addCounter } -private def resultSourceDistinct +private theorem resultSourceDistinct {inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx : Fin n} (h : BinaryPolynomialDistinct inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx) : @@ -106,7 +106,7 @@ private def resultSourceDistinct acc_ne_addCounter := h.scratch_ne_addCounter mulCounter_ne_addCounter := h.mulCounter_ne_addCounter } -private def scratchSourceDistinct +private theorem scratchSourceDistinct {inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx : Fin n} (h : BinaryPolynomialDistinct inputIdx resultIdx scratchIdx mulCounterIdx addCounterIdx) : @@ -481,7 +481,7 @@ private theorem binaryHornerLayersTM_hoareTimeSpace simpa [binaryPolynomialNatTape] using hsource.eq_init_move_right.symm · rw [Function.update_of_ne hi] have hacc : accValue ≤ cap := by - simpa using hcap 0 (by simp) + exact hcap 0 (by simp) have haccSize := Nat.size_le_size (show accValue ≤ 2 * cap by omega) refine hbase.consequence (fun _ _ _ h => h) (fun inp work out h => ?_) (by simp [binaryHornerLayersTime, binaryAddConstTime]) le_rfl ?_ @@ -494,10 +494,10 @@ private theorem binaryHornerLayersTM_hoareTimeSpace omega | cons coeff coeffs ih => have hacc : accValue ≤ cap := by - simpa using hcap 0 (by simp) + exact hcap 0 (by simp) have hnext : accValue * inputValue + coeff ≤ cap := by have h := hcap 1 (by simp) - simpa [List.take_succ_cons, binaryHornerFold_cons_internal] using h + exact h have hlayer := binaryHornerLayerTM_hoareTimeSpace inputIdx sourceIdx targetIdx mulCounterIdx addCounterIdx hdistinct inputValue accValue coeff inputLength initialSpace inp₀ work₀ out₀ hinput hsource @@ -609,7 +609,7 @@ private theorem binaryHornerWork_endpoint induction coeffs generalizing sourceIdx targetIdx accValue work with | nil => simp only [binaryHornerWork, binaryHornerFold, List.length_nil] - rw [if_pos Even.zero] + rw [ite_eq_left Even.zero] rw [update_binaryZero_eq work targetIdx htarget] funext i by_cases hi : i = sourceIdx @@ -631,11 +631,11 @@ private theorem binaryHornerWork_endpoint hsource₁ htarget₁ rw [binaryHornerWork, hih] by_cases heven : Even coeffs.length - · rw [if_pos heven] + · rw [ite_eq_left heven] have hoddCons : ¬Even (coeff :: coeffs).length := by rw [List.length_cons, Nat.even_add_one] exact not_not_intro heven - rw [if_neg hoddCons] + rw [ite_eq_right hoddCons] funext i by_cases his : i = sourceIdx · subst i @@ -645,11 +645,11 @@ private theorem binaryHornerWork_endpoint simp [work₁, binaryHornerLayerWork, nextValue, binaryHornerFold_cons_internal] · simp [work₁, binaryHornerLayerWork, his, hit] - · rw [if_neg heven] + · rw [ite_eq_right heven] have hevenCons : Even (coeff :: coeffs).length := by rw [List.length_cons, Nat.even_add_one] exact heven - rw [if_pos hevenCons] + rw [ite_eq_left hevenCons] funext i by_cases his : i = sourceIdx · subst i @@ -753,14 +753,14 @@ theorem binaryPolynomialEvalTM_hoareTimeSpace_frame_internal inputValue 0 inputLength initialSpace cap coeffs inp₀ work₀ out₀ hinput hresult hscratch hmulCounter haddCounter hinp hwork hout hworkSpace hinputSpace hinputCap hcap - rw [binaryPolynomialEvalTM, if_pos (by simpa [coeffs] using heven)] + rw [binaryPolynomialEvalTM, ite_eq_left (by simpa [coeffs] using heven)] refine hrun.consequence (fun _ _ _ h => h) (fun inp work out h => ?_) (by simp [binaryPolynomialTime, coeffs]) le_rfl (by simp [binaryPolynomialSpace, cap]) refine ⟨h.1, h.2.1.trans ?_, h.2.2⟩ have hend := binaryHornerWork_endpoint work₀ resultIdx scratchIdx hdistinct.result_ne_scratch inputValue 0 coeffs hresult hscratch - rw [if_pos heven] at hend + rw [ite_eq_left heven] at hend rw [hend, update_binaryZero_eq work₀ scratchIdx hscratch, binaryHornerFold_polyCoeffs_internal p inputValue] · have hrun := binaryHornerLayersTM_hoareTimeSpace inputIdx scratchIdx @@ -768,14 +768,14 @@ theorem binaryPolynomialEvalTM_hoareTimeSpace_frame_internal inputValue 0 inputLength initialSpace cap coeffs inp₀ work₀ out₀ hinput hscratch hresult hmulCounter haddCounter hinp hwork hout hworkSpace hinputSpace hinputCap hcap - rw [binaryPolynomialEvalTM, if_neg (by simpa [coeffs] using heven)] + rw [binaryPolynomialEvalTM, ite_eq_right (by simpa [coeffs] using heven)] refine hrun.consequence (fun _ _ _ h => h) (fun inp work out h => ?_) (by simp [binaryPolynomialTime, coeffs]) le_rfl (by simp [binaryPolynomialSpace, cap]) refine ⟨h.1, h.2.1.trans ?_, h.2.2⟩ have hend := binaryHornerWork_endpoint work₀ scratchIdx resultIdx hdistinct.result_ne_scratch.symm inputValue 0 coeffs hscratch hresult - rw [if_neg heven] at hend + rw [ite_eq_right heven] at hend rw [hend, update_binaryZero_eq work₀ scratchIdx hscratch, binaryHornerFold_polyCoeffs_internal p inputValue] diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Defs.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Defs.lean index c7dc5222..00296a0d 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Defs.lean @@ -161,15 +161,15 @@ def binaryPredTM {n : ℕ} (idx : Fin n) : TM n where · subst i rw [htarget] at hi exact absurd hi (by decide) - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .start => simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .check => dsimp only @@ -182,15 +182,15 @@ def binaryPredTM {n : ℕ} (idx : Fin n) : TM n where · subst i rw [htarget] at hi exact absurd hi (by decide) - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .start => simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .erase => dsimp only @@ -198,8 +198,8 @@ def binaryPredTM {n : ℕ} (idx : Fin n) : TM n where · simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi · next hnotStart => simp only @@ -207,7 +207,7 @@ def binaryPredTM {n : ℕ} (idx : Fin n) : TM n where by_cases hitarget : i = idx · subst i exact absurd hi hnotStart - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .rewind => dsimp only @@ -215,8 +215,8 @@ def binaryPredTM {n : ℕ} (idx : Fin n) : TM n where · simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi · next hnotStart => simp only @@ -224,7 +224,7 @@ def binaryPredTM {n : ℕ} (idx : Fin n) : TM n where by_cases hitarget : i = idx · subst i exact absurd hi hnotStart - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .done => exact rightOfStart_allIdle iHead wHeads oHead diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Internal.lean index 1f40aca9..1f673ef6 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryPred/Internal.lean @@ -99,13 +99,13 @@ private theorem HasBinaryContent.binaryPred_erase_last {t : Tape} have hhead0 : t.head ≠ 0 := by omega constructor · intro i hi - rw [Tape.write, if_neg hhead0] + rw [Tape.write, ite_eq_right hhead0] simp only rw [hhead, Function.update_of_ne (by omega)] have hcell := h.1 i (by simp; omega) simpa [List.getElem_append, hi] using hcell · intro i hi - rw [Tape.write, if_neg hhead0] + rw [Tape.write, ite_eq_right hhead0] simp only rw [hhead] by_cases heq : i = bitsPrefix.length @@ -163,7 +163,7 @@ private theorem binaryPredTM_step_zero (c : Cfg n (binaryPredTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.one).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -173,7 +173,8 @@ private theorem binaryPredTM_step_zero (c : Cfg n (binaryPredTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Resolve borrow at the first one and advance to lookahead. -/ @@ -188,7 +189,7 @@ private theorem binaryPredTM_step_one (c : Cfg n (binaryPredTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.zero).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -198,7 +199,8 @@ private theorem binaryPredTM_step_one (c : Cfg n (binaryPredTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Define zero underflow by turning left from the terminating blank. -/ @@ -213,16 +215,16 @@ private theorem binaryPredTM_step_borrow_blank input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hi : i = idx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hread]; decide)] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -239,7 +241,7 @@ private theorem binaryPredTM_step_check_bit (bit : Bool) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] cases bit <;> simp only [Γ.ofBool, binaryPredTM, hstate, hread] all_goals refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) @@ -247,9 +249,9 @@ private theorem binaryPredTM_step_check_bit (bit : Bool) · funext i by_cases hi : i = idx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hread]; decide)] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -265,16 +267,16 @@ private theorem binaryPredTM_step_check_blank input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hi : i = idx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hread]; decide)] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -290,7 +292,7 @@ private theorem binaryPredTM_step_erase (c : Cfg n (binaryPredTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.blank).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -300,7 +302,8 @@ private theorem binaryPredTM_step_erase (c : Cfg n (binaryPredTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, Γ.ofBool, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Rewind one ordinary target cell to the left. -/ @@ -314,16 +317,16 @@ private theorem binaryPredTM_step_rewind (c : Cfg n (binaryPredTM idx).Q) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hi : i = idx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hread] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -339,7 +342,7 @@ private theorem binaryPredTM_step_start (c : Cfg n (binaryPredTM idx).Q) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryPredTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryPredTM_ne_halt (by decide) hstate)] simp only [binaryPredTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -349,8 +352,8 @@ private theorem binaryPredTM_step_start (c : Cfg n (binaryPredTM idx).Q) simp only [↓reduceIte, Function.update_self] show (((c.work idx).write _).move Dir3.right) = (c.work idx).move Dir3.right - rw [Tape.write, if_pos hhead] - · rw [if_neg hi, Function.update_of_ne hi] + rw [Tape.write, ite_eq_left hhead] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -533,7 +536,7 @@ private theorem binaryPredTM_borrow_run (List.replicate (done + 1) true ++ rest) := by have hwrite := hcontent.write_set true hhead (by simp) rw [BinaryPred.set_false_to_true] at hwrite - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.one Dir3.right hcell0 @@ -586,7 +589,7 @@ private theorem binaryPredTM_borrow_run (List.replicate done true ++ [false]) := by have hwrite := hcontent.write_set false hhead (by simp) rw [BinaryPred.set_true_to_false] at hwrite - simpa only [target₁, Tape.HasBinaryContent, Tape.move_cells] + simpa only [Γ.ofBool, target₁, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htarget₁Cell0 : target₁.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.zero Dir3.right hcell0 @@ -698,7 +701,7 @@ private theorem binaryPredTM_borrow_run (List.replicate done true ++ false :: next :: rest) := by have hwrite := hcontent.write_set false hhead (by simp) rw [BinaryPred.set_true_to_false] at hwrite - simpa only [target₁, Tape.HasBinaryContent, Tape.move_cells] + simpa only [Γ.ofBool, target₁, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htarget₁Cell0 : target₁.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.zero Dir3.right hcell0 diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Defs.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Defs.lean index e819ebcf..f68d3ec8 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Defs.lean @@ -119,26 +119,26 @@ def binaryRippleAddScanTM {n : ℕ} intro i hi dsimp only by_cases hresult : i = resultIdx - · rw [if_pos hresult] - · rw [if_neg hresult] + · rw [ite_eq_left hresult] + · rw [ite_eq_right hresult] exact idleDir_right_of_start hi · exact rightOfStart_allReadBack iHead wHeads oHead · refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ intro i hi dsimp only by_cases hresult : i = resultIdx - · rw [if_pos hresult] - · rw [if_neg hresult] + · rw [ite_eq_left hresult] + · rw [ite_eq_right hresult] by_cases hlhs : i = lhsIdx - · rw [if_pos hlhs] + · rw [ite_eq_left hlhs] subst i simp [hi] - · rw [if_neg hlhs] + · rw [ite_eq_right hlhs] by_cases hrhs : i = rhsIdx - · rw [if_pos hrhs] + · rw [ite_eq_left hrhs] subst i simp [hi] - · rw [if_neg hrhs] + · rw [ite_eq_right hrhs] exact idleDir_right_of_start hi | done => exact rightOfStart_allIdle iHead wHeads oHead diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Scan.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Scan.lean index 20ce1a5a..3e303e6c 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Scan.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Scan.lean @@ -80,7 +80,7 @@ private theorem binaryRippleAddScanTM_step_active {n : ℕ} work := binaryRippleAddScanAdvanceWork lhsIdx rhsIdx resultIdx sum work output := out } := by dsimp only - rw [TM.step, if_neg (by simp [binaryRippleAddScanTM])] + rw [TM.step, ite_eq_right (by simp [binaryRippleAddScanTM])] simp only [binaryRippleAddScanTM, hactive, ↓reduceIte] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) @@ -90,25 +90,25 @@ private theorem binaryRippleAddScanTM_step_active {n : ℕ} simp [binaryRippleAddScanAdvanceWork] · by_cases hlhsIdx : i = lhsIdx · subst i - simp only [binaryRippleAddScanAdvanceWork, hresultIdx, if_false, - if_pos] + simp only [binaryRippleAddScanAdvanceWork, hresultIdx, ite_false, + ite_eq_left] by_cases hblank : (work lhsIdx).read = Γ.blank - · rw [if_pos hblank, if_pos hblank] + · rw [ite_eq_left hblank, ite_eq_left hblank] simpa [hblank] using writeAndMove_readBack_stay (show (work lhsIdx).read ≠ Γ.start from hlhs) - · rw [if_neg hblank, if_neg hblank] + · rw [ite_eq_right hblank, ite_eq_right hblank] exact writeAndMove_readBack_right hlhs · by_cases hrhsIdx : i = rhsIdx · subst i - simp only [binaryRippleAddScanAdvanceWork, hresultIdx, if_false, - hlhsIdx, if_pos] + simp only [binaryRippleAddScanAdvanceWork, hresultIdx, ite_false, + hlhsIdx, ite_eq_left] by_cases hblank : (work rhsIdx).read = Γ.blank - · rw [if_pos hblank, if_pos hblank] + · rw [ite_eq_left hblank, ite_eq_left hblank] simpa [hblank] using writeAndMove_readBack_stay (show (work rhsIdx).read ≠ Γ.start from hrhs) - · rw [if_neg hblank, if_neg hblank] + · rw [ite_eq_right hblank, ite_eq_right hblank] exact writeAndMove_readBack_right hrhs - · simp only [binaryRippleAddScanAdvanceWork, hresultIdx, if_false, + · simp only [binaryRippleAddScanAdvanceWork, hresultIdx, ite_false, hlhsIdx, hrhsIdx] exact transitionTape_eq_self (hother i hlhsIdx hrhsIdx hresultIdx) @@ -141,9 +141,9 @@ private theorem binaryRippleAddScanTM_step_terminal {n : ℕ} cases carry with | false => refine ⟨work, ?_, rfl, rfl, rfl, rfl, ?_, hresultStart, ?_⟩ - · rw [TM.step, if_neg (by simp [binaryRippleAddScanTM])] - simp only [binaryRippleAddScanTM, hlhs, hrhs, and_self, if_pos, - Bool.false_eq_true, if_false, allReadBack] + · rw [TM.step, ite_eq_right (by simp [binaryRippleAddScanTM])] + simp only [binaryRippleAddScanTM, hlhs, hrhs, and_self, ite_eq_left, + Bool.false_eq_true, ite_false, allReadBack] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) funext i @@ -166,8 +166,8 @@ private theorem binaryRippleAddScanTM_step_terminal {n : ℕ} let finalWork := Function.update work resultIdx ((work resultIdx).writeAndMove Γ.one Dir3.right) refine ⟨finalWork, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · rw [TM.step, if_neg (by simp [binaryRippleAddScanTM])] - simp only [binaryRippleAddScanTM, hlhs, hrhs, and_self, if_pos] + · rw [TM.step, ite_eq_right (by simp [binaryRippleAddScanTM])] + simp only [binaryRippleAddScanTM, hlhs, hrhs, and_self, ite_eq_left] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) funext i @@ -176,21 +176,21 @@ private theorem binaryRippleAddScanTM_step_terminal {n : ℕ} simp [finalWork] · by_cases hil : i = lhsIdx · subst i - simpa [finalWork, hdistinct.lhs_result] using + simpa [transitionTape, finalWork, hdistinct.lhs_result] using transitionTape_eq_self (by rw [hlhs]; decide) · by_cases hir : i = rhsIdx · subst i - simpa [finalWork, hdistinct.rhs_result] using + simpa [transitionTape, finalWork, hdistinct.rhs_result] using transitionTape_eq_self (by rw [hrhs]; decide) - · simpa [finalWork, hires] using + · simpa [transitionTape, finalWork, hires] using transitionTape_eq_self (hother i hil hir hires) · simp [finalWork, hdistinct.lhs_result] · simp [finalWork, hdistinct.lhs_result] · simp [finalWork, hdistinct.rhs_result] · simp [finalWork, hdistinct.rhs_result] - · simpa [finalWork, BinaryRippleAdd.ripple] using + · simpa [Γ.ofBool, finalWork, BinaryRippleAdd.ripple] using Tape.hasBinaryPrefix_write_bit true hresult - · simpa [finalWork] using + · simpa [Γ.ofBool, finalWork] using Tape.hasBinaryPrefix_write_bit_cell0 true hresult hresultStart · intro i _ _ hires simp [finalWork, hires] @@ -329,9 +329,9 @@ private theorem binaryRippleAddScanTM_suffix_reachesIn {n : ℕ} hrhsNotBlank, Tape.move_cells] using hfinalRhs · rw [hfinalRhsHead] simp only [work₁, binaryRippleAddScanAdvanceWork, - if_neg hdistinct.rhs_result, - if_neg (Ne.symm hdistinct.lhs_rhs), if_pos, - if_neg hrhsNotBlank, Tape.move, List.length_cons] + ite_eq_right hdistinct.rhs_result, + ite_eq_right (Ne.symm hdistinct.lhs_rhs), ite_eq_left, + ite_eq_right hrhsNotBlank, Tape.move, List.length_cons] omega · simpa [BinaryRippleAdd.ripple, sum, nextCarry, List.append_assoc] using hfinalResult @@ -417,7 +417,7 @@ private theorem binaryRippleAddScanTM_suffix_reachesIn {n : ℕ} hfinalLhs · rw [hfinalLhsHead] simp only [work₁, binaryRippleAddScanAdvanceWork, - if_neg hdistinct.lhs_result, if_pos, if_neg hlhsNotBlank, + ite_eq_right hdistinct.lhs_result, ite_eq_left, ite_eq_right hlhsNotBlank, Tape.move, List.length_cons] omega · simpa [work₁, binaryRippleAddScanAdvanceWork, @@ -511,7 +511,7 @@ private theorem binaryRippleAddScanTM_suffix_reachesIn {n : ℕ} hfinalLhs · rw [hfinalLhsHead] simp only [work₁, binaryRippleAddScanAdvanceWork, - if_neg hdistinct.lhs_result, if_pos, if_neg hlhsNotBlank, + ite_eq_right hdistinct.lhs_result, ite_eq_left, ite_eq_right hlhsNotBlank, Tape.move, List.length_cons] omega · simpa [work₁, binaryRippleAddScanAdvanceWork, @@ -519,9 +519,9 @@ private theorem binaryRippleAddScanTM_suffix_reachesIn {n : ℕ} hrhsNotBlank, Tape.move_cells] using hfinalRhs · rw [hfinalRhsHead] simp only [work₁, binaryRippleAddScanAdvanceWork, - if_neg hdistinct.rhs_result, - if_neg (Ne.symm hdistinct.lhs_rhs), if_pos, - if_neg hrhsNotBlank, Tape.move, List.length_cons] + ite_eq_right hdistinct.rhs_result, + ite_eq_right (Ne.symm hdistinct.lhs_rhs), ite_eq_left, + ite_eq_right hrhsNotBlank, Tape.move, List.length_cons] omega · simpa [BinaryRippleAdd.ripple, sum, nextCarry, List.append_assoc] using hfinalResult diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Sem.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Sem.lean index aeca3d12..dbd5f273 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Sem.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleAdd/Internal/Sem.lean @@ -99,7 +99,9 @@ private theorem binaryRippleAddScanTM_hoareTime_frame_internal {n : ℕ} · rw [hfinalRhs] exact hrhs.1 · simpa [Nat.size_eq_bits_len] using hfinalRhsHead - · simpa [BinaryRippleAdd.ripple_natBits_internal] using hfinalResult.2 + · have hcontent := hfinalResult.2 + rw [BinaryRippleAdd.ripple_natBits_internal] at hcontent + exact hcontent · simpa [BinaryRippleAdd.ripple_natBits_internal, Nat.size_eq_bits_len] using hfinalResult.1 diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Defs.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Defs.lean index 95a8f32a..de0a203f 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Defs.lean @@ -182,26 +182,26 @@ def binaryRippleSubCoreTM {n : ℕ} simp only by_cases hresult : i = resultIdx · subst i - rw [if_pos rfl] + rw [ite_eq_left rfl] exact moveLeftDir_right_of_start hi - · rw [if_neg hresult] + · rw [ite_eq_right hresult] exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ intro i hi dsimp only by_cases hresult : i = resultIdx - · rw [if_pos hresult] - · rw [if_neg hresult] + · rw [ite_eq_left hresult] + · rw [ite_eq_right hresult] by_cases hlhs : i = lhsIdx - · rw [if_pos hlhs] + · rw [ite_eq_left hlhs] subst i simp [hi] - · rw [if_neg hlhs] + · rw [ite_eq_right hlhs] by_cases hrhs : i = rhsIdx - · rw [if_pos hrhs] + · rw [ite_eq_left hrhs] subst i simp [hi] - · rw [if_neg hrhs] + · rw [ite_eq_right hrhs] exact idleDir_right_of_start hi | erase => dsimp only @@ -210,8 +210,8 @@ def binaryRippleSubCoreTM {n : ℕ} intro i hi simp only by_cases hresult : i = resultIdx - · rw [if_pos hresult] - · rw [if_neg hresult] + · rw [ite_eq_left hresult] + · rw [ite_eq_right hresult] exact idleDir_right_of_start hi · rename_i hnotStart refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ @@ -219,9 +219,9 @@ def binaryRippleSubCoreTM {n : ℕ} simp only by_cases hresult : i = resultIdx · subst i - rw [if_pos rfl] + rw [ite_eq_left rfl] exact moveLeftDir_right_of_start hi - · rw [if_neg hresult] + · rw [ite_eq_right hresult] exact idleDir_right_of_start hi | trim seenOne => dsimp only @@ -230,8 +230,8 @@ def binaryRippleSubCoreTM {n : ℕ} intro i hi simp only by_cases hresult : i = resultIdx - · rw [if_pos hresult] - · rw [if_neg hresult] + · rw [ite_eq_left hresult] + · rw [ite_eq_right hresult] exact idleDir_right_of_start hi · rename_i hnotStart split <;> @@ -241,9 +241,9 @@ def binaryRippleSubCoreTM {n : ℕ} simp only by_cases hresult : i = resultIdx · subst i - rw [if_pos rfl] + rw [ite_eq_left rfl] exact moveLeftDir_right_of_start hi - · rw [if_neg hresult] + · rw [ite_eq_right hresult] exact idleDir_right_of_start hi | done => exact rightOfStart_allIdle iHead wHeads oHead diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Backward.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Backward.lean index 9403e538..0cc63c21 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Backward.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Backward.lean @@ -37,13 +37,13 @@ theorem HasBinaryContent.write_blank_last_internal {t : Tape} have hhead0 : t.head ≠ 0 := by omega constructor · intro i hi - rw [Tape.write, if_neg hhead0] + rw [Tape.write, ite_eq_right hhead0] simp only rw [hhead, Function.update_of_ne (by omega)] have hcell := h.1 i (by simp; omega) simpa [List.getElem_append, hi] using hcell · intro i hi - rw [Tape.write, if_neg hhead0] + rw [Tape.write, ite_eq_right hhead0] simp only rw [hhead] by_cases heq : i = bitsPrefix.length @@ -80,7 +80,7 @@ private theorem binaryRippleSubCoreTM_step_erase work := Function.update c.work resultIdx (((c.work resultIdx).write Γ.blank).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryRippleSubCoreTM_ne_halt (by simp) hstate)] + rw [TM.step, ite_eq_right (binaryRippleSubCoreTM_ne_halt (by simp) hstate)] simp only [binaryRippleSubCoreTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -90,7 +90,7 @@ private theorem binaryRippleSubCoreTM_step_erase simp only [↓reduceIte, Function.update_self] simp [moveLeftDir, hread] · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, ite_eq_right hi] using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput private theorem binaryRippleSubCoreTM_step_trim_false_zero @@ -106,7 +106,7 @@ private theorem binaryRippleSubCoreTM_step_trim_false_zero work := Function.update c.work resultIdx (((c.work resultIdx).write Γ.blank).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryRippleSubCoreTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryRippleSubCoreTM_ne_halt (by decide) hstate)] simp only [binaryRippleSubCoreTM, hstate] simp [hread] refine ⟨transitionInput_eq_self hinput, ?_, transitionTape_eq_self houtput⟩ @@ -116,7 +116,7 @@ private theorem binaryRippleSubCoreTM_step_trim_false_zero simp only [↓reduceIte, Function.update_self] simp [moveLeftDir] · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, Γw.toΓ, ite_eq_right hi] using transitionTape_eq_self (hother i hi) private theorem binaryRippleSubCoreTM_step_trim_false_one (c : Cfg n (binaryRippleSubCoreTM lhsIdx rhsIdx resultIdx).Q) @@ -131,19 +131,19 @@ private theorem binaryRippleSubCoreTM_step_trim_false_one work := Function.update c.work resultIdx ((c.work resultIdx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryRippleSubCoreTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryRippleSubCoreTM_ne_halt (by decide) hstate)] simp only [binaryRippleSubCoreTM, hstate] simp [hread] refine ⟨transitionInput_eq_self hinput, ?_, transitionTape_eq_self houtput⟩ funext i by_cases hi : i = resultIdx · subst i - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] change (c.work resultIdx).writeAndMove (readBackWrite (c.work resultIdx).read) (moveLeftDir Γ.one) = _ rw [writeAndMove_readBack _ (by rw [hread]; decide)] simp [moveLeftDir] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) private theorem binaryRippleSubCoreTM_step_trim_true @@ -159,20 +159,20 @@ private theorem binaryRippleSubCoreTM_step_trim_true work := Function.update c.work resultIdx ((c.work resultIdx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binaryRippleSubCoreTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binaryRippleSubCoreTM_ne_halt (by decide) hstate)] simp only [binaryRippleSubCoreTM, hstate] simp [hread] refine ⟨transitionInput_eq_self hinput, ?_, transitionTape_eq_self houtput⟩ funext i by_cases hi : i = resultIdx · subst i - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] change (c.work resultIdx).writeAndMove (readBackWrite (c.work resultIdx).read) (moveLeftDir (c.work resultIdx).read) = _ rw [writeAndMove_readBack _ hread] simp [moveLeftDir, hread] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) private theorem binaryRippleSubCoreTM_step_erase_start @@ -189,7 +189,7 @@ private theorem binaryRippleSubCoreTM_step_erase_start work := Function.update c.work resultIdx ((c.work resultIdx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryRippleSubCoreTM_ne_halt (by simp) hstate)] + rw [TM.step, ite_eq_right (binaryRippleSubCoreTM_ne_halt (by simp) hstate)] simp only [binaryRippleSubCoreTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -199,8 +199,8 @@ private theorem binaryRippleSubCoreTM_step_erase_start simp only [↓reduceIte, Function.update_self] show (((c.work resultIdx).write _).move Dir3.right) = (c.work resultIdx).move Dir3.right - rw [Tape.write, if_pos hhead] - · rw [if_neg hi, Function.update_of_ne hi] + rw [Tape.write, ite_eq_left hhead] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -219,7 +219,7 @@ private theorem binaryRippleSubCoreTM_step_trim_start work := Function.update c.work resultIdx ((c.work resultIdx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binaryRippleSubCoreTM_ne_halt (by simp) hstate)] + rw [TM.step, ite_eq_right (binaryRippleSubCoreTM_ne_halt (by simp) hstate)] simp only [binaryRippleSubCoreTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -229,8 +229,8 @@ private theorem binaryRippleSubCoreTM_step_trim_start simp only [↓reduceIte, Function.update_self] show (((c.work resultIdx).write _).move Dir3.right) = (c.work resultIdx).move Dir3.right - rw [Tape.write, if_pos hhead] - · rw [if_neg hi, Function.update_of_ne hi] + rw [Tape.write, ite_eq_left hhead] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Pure.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Pure.lean index 5d066284..93260379 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Pure.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Pure.lean @@ -84,7 +84,8 @@ theorem scan_value_internal (borrow : Bool) (lhs rhs : List Bool) : have hstep := scan_value_step borrow false rhsBit tail.borrow 0 (Nat.fromBitsLE rhsTail) (Nat.fromBitsLE tail.bits) rhsTail.length htail - simpa [scan, tail, nextBorrow, Nat.fromBitsLE_cons] using hstep + simpa [boolValue, show Nat.fromBitsLE ([] : List Bool) = 0 from rfl, scan, tail, + nextBorrow, Nat.fromBitsLE_cons] using hstep | cons lhsBit lhsTail ih => cases rhs with | nil => @@ -98,7 +99,8 @@ theorem scan_value_internal (borrow : Bool) (lhs rhs : List Bool) : have hstep := scan_value_step borrow lhsBit false tail.borrow (Nat.fromBitsLE lhsTail) 0 (Nat.fromBitsLE tail.bits) lhsTail.length htail - simpa [scan, tail, nextBorrow, Nat.fromBitsLE_cons] using hstep + simpa [boolValue, show Nat.fromBitsLE ([] : List Bool) = 0 from rfl, scan, tail, + nextBorrow, Nat.fromBitsLE_cons] using hstep | cons rhsBit rhsTail => let nextBorrow := borrowBit borrow lhsBit rhsBit let tail := scan nextBorrow lhsTail rhsTail @@ -111,7 +113,8 @@ theorem scan_value_internal (borrow : Bool) (lhs rhs : List Bool) : have hstep := scan_value_step borrow lhsBit rhsBit tail.borrow (Nat.fromBitsLE lhsTail) (Nat.fromBitsLE rhsTail) (Nat.fromBitsLE tail.bits) (max lhsTail.length rhsTail.length) htail - simpa [scan, tail, nextBorrow, Nat.fromBitsLE_cons] using hstep + simpa [boolValue, show Nat.fromBitsLE ([] : List Bool) = 0 from rfl, scan, tail, + nextBorrow, Nat.fromBitsLE_cons] using hstep /-- Appending a redundant high zero does not change canonical trimming. -/ theorem trimHighZeros_append_false_internal (bits : List Bool) : @@ -171,21 +174,21 @@ theorem subtract_natBits_internal (lhs rhs : ℕ) : have hinvariant' : lhs + (if raw.borrow then 2 ^ max lhs.size rhs.size else 0) = rhs + Nat.fromBitsLE raw.bits := by - simpa [raw, Nat.fromBitsLE_bits, Nat.size_eq_bits_len] using hinvariant + simpa [raw, boolValue, Nat.fromBitsLE_bits, Nat.size_eq_bits_len] using hinvariant have hrawBound' : Nat.fromBitsLE raw.bits < 2 ^ max lhs.size rhs.size := by rw [hlength'] at hrawBound exact hrawBound change (if raw.borrow then [] else trimHighZeros raw.bits) = (lhs - rhs).bits cases hborrow : raw.borrow with | false => - simp only [Bool.false_eq_true, if_false] + simp only [Bool.false_eq_true, ite_false] rw [trimHighZeros_eq_natBits_internal] have hvalue : Nat.fromBitsLE raw.bits = lhs - rhs := by simp [hborrow] at hinvariant' omega rw [hvalue] | true => - simp only [if_true] + simp only [ite_true] have hlt : lhs < rhs := by simp [hborrow] at hinvariant' omega diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Scan.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Scan.lean index b548c1ea..668a8812 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Scan.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryRippleSub/Internal/Scan.lean @@ -68,7 +68,7 @@ private theorem binaryRippleSubCoreTM_step_active {n : ℕ} work := binaryRippleSubScanAdvanceWork lhsIdx rhsIdx resultIdx diff work output := out } := by dsimp only - rw [TM.step, if_neg (by simp [binaryRippleSubCoreTM])] + rw [TM.step, ite_eq_right (by simp [binaryRippleSubCoreTM])] simp only [binaryRippleSubCoreTM, hactive, ↓reduceIte] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) @@ -78,24 +78,24 @@ private theorem binaryRippleSubCoreTM_step_active {n : ℕ} simp [binaryRippleSubScanAdvanceWork] · by_cases hlhsIdx : i = lhsIdx · subst i - simp only [binaryRippleSubScanAdvanceWork, hresultIdx, if_false, if_pos] + simp only [binaryRippleSubScanAdvanceWork, hresultIdx, ite_false, ite_eq_left] by_cases hblank : (work lhsIdx).read = Γ.blank - · rw [if_pos hblank, if_pos hblank] + · rw [ite_eq_left hblank, ite_eq_left hblank] rw [writeAndMove_readBack _ hlhs Dir3.stay] rfl - · rw [if_neg hblank, if_neg hblank] + · rw [ite_eq_right hblank, ite_eq_right hblank] exact writeAndMove_readBack (work lhsIdx) hlhs Dir3.right · by_cases hrhsIdx : i = rhsIdx · subst i - simp only [binaryRippleSubScanAdvanceWork, hresultIdx, if_false, - hlhsIdx, if_pos] + simp only [binaryRippleSubScanAdvanceWork, hresultIdx, ite_false, + hlhsIdx, ite_eq_left] by_cases hblank : (work rhsIdx).read = Γ.blank - · rw [if_pos hblank, if_pos hblank] + · rw [ite_eq_left hblank, ite_eq_left hblank] rw [writeAndMove_readBack _ hrhs Dir3.stay] rfl - · rw [if_neg hblank, if_neg hblank] + · rw [ite_eq_right hblank, ite_eq_right hblank] exact writeAndMove_readBack (work rhsIdx) hrhs Dir3.right - · simp only [binaryRippleSubScanAdvanceWork, hresultIdx, if_false, + · simp only [binaryRippleSubScanAdvanceWork, hresultIdx, ite_false, hlhsIdx, hrhsIdx] exact transitionTape_eq_self (hother i hlhsIdx hrhsIdx hresultIdx) @@ -132,8 +132,8 @@ private theorem binaryRippleSubCoreTM_step_terminal {n : ℕ} dsimp only let finalWork := binaryRippleSubScanTurnWork resultIdx work refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ - · rw [TM.step, if_neg (by simp [binaryRippleSubCoreTM])] - simp only [binaryRippleSubCoreTM, hlhs, hrhs, and_self, if_pos] + · rw [TM.step, ite_eq_right (by simp [binaryRippleSubCoreTM])] + simp only [binaryRippleSubCoreTM, hlhs, hrhs, and_self, ite_eq_left] refine congrArg some (Cfg.ext rfl (transitionInput_eq_self hinput) ?_ (transitionTape_eq_self houtput)) funext i @@ -148,21 +148,21 @@ private theorem binaryRippleSubCoreTM_step_terminal {n : ℕ} decide) Dir3.left · by_cases hil : i = lhsIdx · subst i - simpa [binaryRippleSubScanTurnWork, + simpa [transitionTape, binaryRippleSubScanTurnWork, hdistinct.lhs_result] using transitionTape_eq_self (by rw [hlhs]; decide) · by_cases hir : i = rhsIdx · subst i - simpa [binaryRippleSubScanTurnWork, + simpa [transitionTape, binaryRippleSubScanTurnWork, hdistinct.rhs_result] using transitionTape_eq_self (by rw [hrhs]; decide) - · simpa [binaryRippleSubScanTurnWork, hires] using + · simpa [transitionTape, binaryRippleSubScanTurnWork, hires] using transitionTape_eq_self (hother i hil hir hires) · simp [binaryRippleSubScanTurnWork, hdistinct.lhs_result] · simp [binaryRippleSubScanTurnWork, hdistinct.lhs_result] · simp [binaryRippleSubScanTurnWork, hdistinct.rhs_result] · simp [binaryRippleSubScanTurnWork, hdistinct.rhs_result] - · simpa [finalWork, binaryRippleSubScanTurnWork, Tape.move_cells] using + · simpa [Tape.HasBinaryContent, finalWork, binaryRippleSubScanTurnWork, Tape.move_cells] using hresult.2 · simp [binaryRippleSubScanTurnWork, Tape.move, hresult.1] · simpa [finalWork, binaryRippleSubScanTurnWork, Tape.move_cells] using @@ -222,7 +222,7 @@ private theorem binaryRippleSubCoreTM_suffix_reachesIn {n : ℕ} hfinalRhsHead, hfinalResult, hfinalResultHead, hfinalResultStart, hfinalOther⟩ refine ⟨c', ?_, by - cases borrow <;> simp [c', BinaryRippleSub.scan], rfl, + cases borrow <;> simp [c', BinaryRippleSub.scan] <;> rfl, rfl, hfinalLhs, ?_, hfinalRhs, ?_, ?_, ?_, hfinalResultStart, hfinalOther, rfl⟩ · have hreach : @@ -317,9 +317,9 @@ private theorem binaryRippleSubCoreTM_suffix_reachesIn {n : ℕ} hrhsNotBlank, Tape.move_cells] using hfinalRhs · rw [hfinalRhsHead] simp only [work₁, binaryRippleSubScanAdvanceWork, - if_neg hdistinct.rhs_result, - if_neg (Ne.symm hdistinct.lhs_rhs), if_pos, - if_neg hrhsNotBlank, Tape.move, List.length_cons] + ite_eq_right hdistinct.rhs_result, + ite_eq_right (Ne.symm hdistinct.lhs_rhs), ite_eq_left, + ite_eq_right hrhsNotBlank, Tape.move, List.length_cons] omega · simpa [BinaryRippleSub.scan, diff, nextBorrow, List.append_assoc] using hfinalResult @@ -408,7 +408,7 @@ private theorem binaryRippleSubCoreTM_suffix_reachesIn {n : ℕ} hfinalLhs · rw [hfinalLhsHead] simp only [work₁, binaryRippleSubScanAdvanceWork, - if_neg hdistinct.lhs_result, if_pos, if_neg hlhsNotBlank, + ite_eq_right hdistinct.lhs_result, ite_eq_left, ite_eq_right hlhsNotBlank, Tape.move, List.length_cons] omega · simpa [work₁, binaryRippleSubScanAdvanceWork, @@ -505,7 +505,7 @@ private theorem binaryRippleSubCoreTM_suffix_reachesIn {n : ℕ} hfinalLhs · rw [hfinalLhsHead] simp only [work₁, binaryRippleSubScanAdvanceWork, - if_neg hdistinct.lhs_result, if_pos, if_neg hlhsNotBlank, + ite_eq_right hdistinct.lhs_result, ite_eq_left, ite_eq_right hlhsNotBlank, Tape.move, List.length_cons] omega · simpa [work₁, binaryRippleSubScanAdvanceWork, @@ -513,9 +513,9 @@ private theorem binaryRippleSubCoreTM_suffix_reachesIn {n : ℕ} hrhsNotBlank, Tape.move_cells] using hfinalRhs · rw [hfinalRhsHead] simp only [work₁, binaryRippleSubScanAdvanceWork, - if_neg hdistinct.rhs_result, - if_neg (Ne.symm hdistinct.lhs_rhs), if_pos, - if_neg hrhsNotBlank, Tape.move, List.length_cons] + ite_eq_right hdistinct.rhs_result, + ite_eq_right (Ne.symm hdistinct.lhs_rhs), ite_eq_left, + ite_eq_right hrhsNotBlank, Tape.move, List.length_cons] omega · simpa [BinaryRippleSub.scan, diff, nextBorrow, List.append_assoc] using hfinalResult diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinaryShiftMul/Internal/Sem.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinaryShiftMul/Internal/Sem.lean index 28fb44ef..61a172b7 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinaryShiftMul/Internal/Sem.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinaryShiftMul/Internal/Sem.lean @@ -329,8 +329,9 @@ private theorem binaryShiftMulDoubleTM_hoareTime_frame {n : ℕ} (fun inp' work' out' => inp' = inp ∧ work' = work ∧ out' = out) (fun inp' work' out' => inp' = inp ∧ work' = work₂ ∧ out' = out) (resetBinaryWorkTime 1 shift.size) := by - simpa only [work₂, binaryShiftMulNatTape, - Nat.size_eq_bits_len] using hresetTmp + simp only [work₂, binaryShiftMulNatTape, ← Nat.size_eq_bits_len, + Nat.zero_bits, List.map_nil] + exact hresetTmp have hwork₂ : ∀ i, Parked (work₂ i) := by intro i by_cases hi : i = abi.tmp @@ -590,7 +591,7 @@ private theorem binaryShiftMulBodyTime_le (bit : Bool) (acc shift width : ℕ) have hdouble := binaryShiftMulDoubleTime_le shift width hshift cases bit <;> simp only [binaryShiftMulBodyTime, binaryShiftMulOneTime, - Bool.false_eq_true, if_false, if_true] <;> + Bool.false_eq_true, ite_false, ite_true] <;> omega private theorem forBinaryWorkLoopTime_le @@ -683,7 +684,7 @@ private theorem binaryShiftMulBitBodyTM_hoareTime_frame {n : ℕ} hfinalShift, hfinalTmp, hfinalDbl, hfinalFrame, hfinalOutput⟩ := hrun have heq : (work₀ abi.rhs).read = Γ.one := by - simpa using hbit + exact hbit obtain ⟨C, hbranch, hbranchHalt, hinputEq, hworkEq, houtputEq⟩ := branchWorkSymbolTM_reachesIn_equal_frame abi.rhs Γ.one (binaryShiftMulOneTM abi) (binaryShiftMulDoubleTM abi) @@ -839,9 +840,9 @@ private theorem binaryShiftMulLoopWork_advance {n : ℕ} funext i by_cases hrhs : i = abi.rhs · subst i - simp only [if_pos, binaryShiftMulLoopWork_rhs] + simp only [ite_eq_left, binaryShiftMulLoopWork_rhs] simp [binaryShiftMulCursorTape, Tape.move] - · rw [if_neg hrhs] + · rw [ite_eq_right hrhs] by_cases hacc : i = abi.acc · subst i rw [binaryShiftMulLoopWork_acc, binaryShiftMulLoopWork_acc] @@ -1095,9 +1096,10 @@ private theorem binaryShiftMulLoopTM_hoareTime_frame {n : ℕ} (fun i => (hworkParked i).read_ne_start) houtput.read_ne_start have hadvance := binaryShiftMulLoopWork_advance abi work₀ index acc shift - simpa [binaryShiftMulBodyDoneCfg, binaryShiftMulScanCfg, + simp only [binaryShiftMulBodyDoneCfg, binaryShiftMulScanCfg, binaryShiftMulPartialWork, work, acc, shift, - binaryShiftMulBodyDoneWork, body, hadvance] using hstep + binaryShiftMulBodyDoneWork, body, hadvance] at hstep ⊢ + exact hstep stopStep := by apply forBinaryWorkTM_step_scan_blank_internal abi.rhs body · rfl @@ -1133,11 +1135,13 @@ private theorem binaryShiftMulLoopTM_hoareTime_frame {n : ℕ} by_cases haccIdx : i = abi.acc · subst i rw [binaryShiftMulPartialWork, binaryShiftMulLoopWork_acc] - simpa [BinaryShiftMul.partialAcc] using hacc.eq_init_move_right.symm + simp [BinaryShiftMul.partialAcc] + exact hacc.eq_init_move_right.symm by_cases hshiftIdx : i = abi.shift · subst i rw [binaryShiftMulPartialWork, binaryShiftMulLoopWork_shift] - simpa [BinaryShiftMul.partialShift] using hshift.eq_init_move_right.symm + simp [BinaryShiftMul.partialShift] + exact hshift.eq_init_move_right.symm by_cases htmpIdx : i = abi.tmp · subst i rw [binaryShiftMulPartialWork, binaryShiftMulLoopWork_tmp] @@ -1163,8 +1167,9 @@ private theorem binaryShiftMulLoopTM_hoareTime_frame {n : ℕ} input := inp₀ work := work₀ output := out₀ } doneCfg := by - simpa [binaryShiftMulLoopTM, spec, binaryShiftMulScanCfg, - hinitialWork, doneCfg, body] using hloop + simp only [binaryShiftMulLoopTM, spec, binaryShiftMulScanCfg, + hinitialWork, doneCfg, body] at hloop ⊢ + exact hloop refine ⟨doneCfg, forBinaryWorkLoopTime bodyTime 0 rhs.size, (by simpa [binaryShiftMulLoopBound] using hloopTime), hreach, rfl, ?_⟩ refine ⟨rfl, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, rfl⟩ @@ -1679,9 +1684,9 @@ private theorem binaryShiftMulCleanupTime_le {n : ℕ} simp [binaryShiftMulWidth] simp only [binaryShiftMulCleanupTime, resetBinaryWorkManyTime, binaryShiftMulCleanupBits, binaryShiftMulCleanupHead, - resetBinaryWorkTime, clearWorkTimeBound, if_pos] - simp only [if_neg (Ne.symm abi.shift_ne_tmp), - if_neg (Ne.symm abi.shift_ne_dbl), List.length_nil] + resetBinaryWorkTime, clearWorkTimeBound, ite_eq_left] + simp only [ite_eq_right (Ne.symm abi.shift_ne_tmp), + ite_eq_right (Ne.symm abi.shift_ne_dbl), List.length_nil] omega /-- The concrete shift-and-add multiplier preserves both operands, writes diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Defs.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Defs.lean index 16b55c3d..d2dff440 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Defs.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Defs.lean @@ -129,14 +129,14 @@ def binarySuccTM {n : ℕ} (idx : Fin n) : TM n where · subst i rw [htarget] at hi exact absurd hi (by decide) - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .start => simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .rewind => dsimp only @@ -144,8 +144,8 @@ def binarySuccTM {n : ℕ} (idx : Fin n) : TM n where · simp only refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ by_cases hitarget : i = idx - · rw [if_pos hitarget] - · rw [if_neg hitarget] + · rw [ite_eq_left hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi · next hnotStart => simp only @@ -153,7 +153,7 @@ def binarySuccTM {n : ℕ} (idx : Fin n) : TM n where by_cases hitarget : i = idx · subst i exact absurd hi hnotStart - · rw [if_neg hitarget] + · rw [ite_eq_right hitarget] exact idleDir_right_of_start hi | .done => exact rightOfStart_allIdle iHead wHeads oHead diff --git a/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Internal.lean index 04ffaad6..379a37d1 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/BinarySucc/Internal.lean @@ -118,7 +118,7 @@ private theorem binarySuccTM_step_one (c : Cfg n (binarySuccTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.zero).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binarySuccTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binarySuccTM_ne_halt (by decide) hstate)] simp only [binarySuccTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -128,7 +128,8 @@ private theorem binarySuccTM_step_one (c : Cfg n (binarySuccTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Resolve a carry on zero: write one and turn left. -/ @@ -143,7 +144,7 @@ private theorem binarySuccTM_step_zero (c : Cfg n (binarySuccTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.one).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binarySuccTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binarySuccTM_ne_halt (by decide) hstate)] simp only [binarySuccTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -153,7 +154,8 @@ private theorem binarySuccTM_step_zero (c : Cfg n (binarySuccTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Resolve overflow on the terminating blank: append one and turn left. -/ @@ -168,7 +170,7 @@ private theorem binarySuccTM_step_blank (c : Cfg n (binarySuccTM idx).Q) work := Function.update c.work idx (((c.work idx).write Γ.one).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binarySuccTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binarySuccTM_ne_halt (by decide) hstate)] simp only [binarySuccTM, hstate, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -178,7 +180,8 @@ private theorem binarySuccTM_step_blank (c : Cfg n (binarySuccTM idx).Q) simp only [↓reduceIte, Function.update_self] rfl · rw [Function.update_of_ne hi] - simpa only [if_neg hi] using transitionTape_eq_self (hother i hi) + simpa only [transitionTape, TM.idleDir, TM.readBackWrite, Γw.toΓ, Γ.ofBool, ite_eq_right hi] + using transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput /-- Rewind one ordinary target cell to the left. -/ @@ -192,16 +195,16 @@ private theorem binarySuccTM_step_rewind (c : Cfg n (binarySuccTM idx).Q) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.left) output := c.output } := by - rw [TM.step, if_neg (binarySuccTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binarySuccTM_ne_halt (by decide) hstate)] simp only [binarySuccTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput · funext i by_cases hi : i = idx · subst i - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hread] - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -217,7 +220,7 @@ private theorem binarySuccTM_step_start (c : Cfg n (binarySuccTM idx).Q) input := c.input work := Function.update c.work idx ((c.work idx).move Dir3.right) output := c.output } := by - rw [TM.step, if_neg (binarySuccTM_ne_halt (by decide) hstate)] + rw [TM.step, ite_eq_right (binarySuccTM_ne_halt (by decide) hstate)] simp only [binarySuccTM, hstate, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinput @@ -227,8 +230,8 @@ private theorem binarySuccTM_step_start (c : Cfg n (binarySuccTM idx).Q) simp only [↓reduceIte, Function.update_self] show (((c.work idx).write _).move Dir3.right) = (c.work idx).move Dir3.right - rw [Tape.write, if_pos hhead] - · rw [if_neg hi, Function.update_of_ne hi] + rw [Tape.write, ite_eq_left hhead] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self houtput @@ -361,7 +364,7 @@ private theorem binarySuccTM_carry_run have htargetContent : target.HasBinaryContent (List.replicate done false ++ [true]) := by have hwrite := hcontent'.write_append true (by simpa using hhead) - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using hwrite + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.one Dir3.left hcell0 have htargetHead : target.head = done := by @@ -411,7 +414,7 @@ private theorem binarySuccTM_carry_run (List.replicate done false ++ true :: rest) := by have hwrite := hcontent.write_set true hhead (by simp) rw [BinarySucc.set_false_to_true] at hwrite - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using hwrite + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.one Dir3.left hcell0 have htargetHead : target.head = done := by @@ -459,7 +462,7 @@ private theorem binarySuccTM_carry_run (List.replicate (done + 1) false ++ rest) := by have hwrite := hcontent.write_set false hhead (by simp) rw [BinarySucc.set_true_to_false] at hwrite - simpa only [target, Tape.HasBinaryContent, Tape.move_cells] using hwrite + simpa only [Γ.ofBool, target, Tape.HasBinaryContent, Tape.move_cells] using hwrite have htargetCell0 : target.cells 0 = Γ.start := by exact Tape.write_move_cell0 Γ.zero Dir3.right hcell0 have htargetHead : target.head = (done + 1) + 1 := by diff --git a/Complexitylib/Models/TuringMachine/Subroutines/Counter.lean b/Complexitylib/Models/TuringMachine/Subroutines/Counter.lean index f60cb3b7..26923a18 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/Counter.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/Counter.lean @@ -430,7 +430,7 @@ theorem inputLengthPlusOneCounterTM_scan_start_initializes_counter (by simp [TM.step, inputLengthPlusOneCounterTM])).work counterIdx).HasUnaryPrefix 0 := by simp [TM.step, inputLengthPlusOneCounterTM, hinp, counterPreserveWork, counterIdleDirs, hcounter] - simpa [Tape.writeAndMove, Tape.write] using + simpa [Tape.writeAndMove, Tape.write, idleDir, Tape.read, Tape.init] using Tape.init_nil_move_right_hasUnaryPrefix_zero /-- In the `scan` phase, reading blank on the input moves the machine to the @@ -671,7 +671,7 @@ private theorem inputLengthPlusOneCounterTM_start_step rw [hcounter] simp [Tape.read, Tape.init] simpa [counterPreserveWork, counterIdleDirs, hcounter, hcounter_read, - Tape.writeAndMove, Tape.write] using + Tape.writeAndMove, Tape.write, idleDir, Tape.read, Tape.init] using Tape.init_nil_move_right_hasUnaryPrefix_zero · simp [counterIdleDirs, hcounter, Tape.writeAndMove, Tape.move_cells, Tape.write, Tape.init] @@ -939,7 +939,7 @@ theorem inputLengthPlusOneCounterTM_hoareTime refine ⟨c4, 1 + x.length + 1 + (x.length + 2 + 1), ?_, ?_, hhalt4, hpost⟩ · simp [inputLengthPlusOneCounterTime] omega - · simpa [c0] using hreach_04 + · simpa [c0, inputLengthPlusOneCounterTM] using hreach_04 /-- Started-tape variant of `inputLengthPlusOneCounterTM_hoareTime`: if the input is already positioned at cell `1` and the counter tape is the started @@ -1020,7 +1020,7 @@ theorem inputLengthPlusOneCounterTM_started_hoareTime ⟨hcounter4, hcell04, hnostart4⟩⟩ · simp [inputLengthPlusOneCounterTime] omega - · simpa [c0] using hreach_04 + · simpa [c0, inputLengthPlusOneCounterTM] using hreach_04 /-- Started-tape variant of the unary counter builder that also records the final input position. The input cells are unchanged, and the input head ends at @@ -1107,7 +1107,7 @@ theorem inputLengthPlusOneCounterTM_started_tracksInput_hoareTime ⟨hinput4_cells, hinput4_head, hcounter4, hcell04, hnostart4⟩⟩ · simp [inputLengthPlusOneCounterTime] omega - · simpa [c0] using hreach_04 + · simpa [c0, inputLengthPlusOneCounterTM] using hreach_04 /-- One-step preservation of a passive started Boolean work tape distinct from the active counter tape. -/ @@ -1128,17 +1128,20 @@ private theorem inputLengthPlusOneCounterTM_step_preserves_started_other_work | scan => by_cases hstart : input.read = Γ.start · simp [TM.step, inputLengthPlusOneCounterTM, hstart] at hstep + injection hstep with hstep subst hstep simpa [counterPreserveWork, counterIdleDirs] using Tape.writeAndMove_readBack_idle_of_ne_start (work passiveIdx) (by simpa [hpassive] using hpassive_read) · by_cases hblank : input.read = Γ.blank · simp [TM.step, inputLengthPlusOneCounterTM, hblank] at hstep + injection hstep with hstep subst hstep simpa [counterWriteOneWork, counterAdvanceDirs, hne] using Tape.writeAndMove_readBack_idle_of_ne_start (work passiveIdx) (by simpa [hpassive] using hpassive_read) · simp [TM.step, inputLengthPlusOneCounterTM, hstart, hblank] at hstep + injection hstep with hstep subst hstep simpa [counterWriteOneWork, counterAdvanceDirs, hne] using Tape.writeAndMove_readBack_idle_of_ne_start (work passiveIdx) @@ -1146,11 +1149,13 @@ private theorem inputLengthPlusOneCounterTM_step_preserves_started_other_work | rewind => by_cases hcounter : (work counterIdx).read = Γ.start · simp [TM.step, inputLengthPlusOneCounterTM, hcounter] at hstep + injection hstep with hstep subst hstep simpa [counterPreserveWork, counterAdvanceDirs, hne] using Tape.writeAndMove_readBack_idle_of_ne_start (work passiveIdx) (by simpa [hpassive] using hpassive_read) · simp [TM.step, inputLengthPlusOneCounterTM, hcounter] at hstep + injection hstep with hstep subst hstep simpa [counterPreserveWork, counterRewindDirs, hne] using Tape.writeAndMove_readBack_idle_of_ne_start (work passiveIdx) @@ -1193,17 +1198,20 @@ private theorem inputLengthPlusOneCounterTM_step_preserves_started_blank_output | scan => by_cases hstart : input.read = Γ.start · simp [TM.step, inputLengthPlusOneCounterTM, hstart] at hstep + injection hstep with hstep subst hstep simpa [hout] using Tape.writeAndMove_readBack_idle_of_ne_start output hout_read · by_cases hblank : input.read = Γ.blank · simp [TM.step, inputLengthPlusOneCounterTM, hblank] at hstep + injection hstep with hstep subst hstep simpa [hout] using Tape.writeAndMove_readBack_idle_of_ne_start output hout_read · simp [TM.step, inputLengthPlusOneCounterTM, hstart, hblank] at hstep + injection hstep with hstep subst hstep simpa [hout] using Tape.writeAndMove_readBack_idle_of_ne_start output @@ -1211,11 +1219,13 @@ private theorem inputLengthPlusOneCounterTM_step_preserves_started_blank_output | rewind => by_cases hcounter : (work counterIdx).read = Γ.start · simp [TM.step, inputLengthPlusOneCounterTM, hcounter] at hstep + injection hstep with hstep subst hstep simpa [hout] using Tape.writeAndMove_readBack_idle_of_ne_start output hout_read · simp [TM.step, inputLengthPlusOneCounterTM, hcounter] at hstep + injection hstep with hstep subst hstep simpa [hout] using Tape.writeAndMove_readBack_idle_of_ne_start output diff --git a/Complexitylib/Models/TuringMachine/Subroutines/GuessBounded.lean b/Complexitylib/Models/TuringMachine/Subroutines/GuessBounded.lean index 2af64c58..e9981653 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/GuessBounded.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/GuessBounded.lean @@ -934,7 +934,12 @@ private theorem guessBoundedNTM_rewind_loop (witnessIdx counterIdx : Fin n) : (choices ⟨0, by omega⟩) c hstate hread hnostart have hstep_choices : (guessBoundedNTM witnessIdx counterIdx).trace 1 choices c = c' := by - simpa using hstep + have hfun : (fun _ : Fin 1 => choices ⟨0, by omega⟩) = choices := by + funext x + congr 1 + exact Fin.ext (by omega) + rw [← hfun] + exact hstep rw [hstep_choices] exact ⟨hhalt, hhead', hcells'⟩ | succ p ih => diff --git a/Complexitylib/Models/TuringMachine/Subroutines/InputMatch.lean b/Complexitylib/Models/TuringMachine/Subroutines/InputMatch.lean index 2b11c59d..0a48e262 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/InputMatch.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/InputMatch.lean @@ -133,12 +133,12 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs t.writeAndMove s.toΓ (idleDir t.read) = ⟨1, Function.update t.cells 1 s.toΓ⟩ := by intro t s hinvt ht have hns : t.read ≠ Γ.start := hinvt.read_ne_start (by omega) - rw [idleDir, if_neg hns] + rw [idleDir, ite_eq_right hns] refine Tape.ext ?_ ?_ · show (t.write s.toΓ).head = 1 rw [Tape.write_head, ht] · show (t.write s.toΓ).cells = _ - rw [Tape.write, if_neg (by omega), ht] + rw [Tape.write, ite_eq_right (by omega), ht] have hright : ∀ (t : Tape), t.StartInvariant → t.head = 1 → t.writeAndMove (readBackWrite t.read).toΓ Dir3.right = ⟨2, t.cells⟩ := by intro t hinvt ht @@ -150,7 +150,7 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs t.writeAndMove (readBackWrite t.read).toΓ (moveLeftDir t.read) = ⟨1, t.cells⟩ := by intro t hinvt ht have hns : t.read ≠ Γ.start := hinvt.read_ne_start (by omega) - rw [writeAndMove_readBack_of_startInvariant t hinvt, moveLeftDir, if_neg hns] + rw [writeAndMove_readBack_of_startInvariant t hinvt, moveLeftDir, ite_eq_right hns] refine Tape.ext ?_ (Tape.move_cells t Dir3.left) show t.head - 1 = 1 omega @@ -158,7 +158,7 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs t.writeAndMove (readBackWrite t.read).toΓ (idleDir t.read) = t := by intro t hinvt ht have hns : t.read ≠ Γ.start := hinvt.read_ne_start ht - rw [writeAndMove_readBack_of_startInvariant t hinvt, idleDir, if_neg hns] + rw [writeAndMove_readBack_of_startInvariant t hinvt, idleDir, ite_eq_right hns] rfl set v₁ : Bool := decide ((work sym).cells 1 = Γ.ofBool (expect inp.read).1) with hv1 set W1 : Fin n → Tape := fun i => @@ -181,35 +181,35 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs simp only [] by_cases hir : i = res · have hisym : ¬ (i = sym) := fun hc => hsr (hc.symm.trans hir) - rw [if_pos hir, if_neg hisym, if_pos hir, + rw [ite_eq_left hir, ite_eq_right hisym, ite_eq_left hir, hstay (work i) _ (hinv i) (by rw [hir]; exact hres), hir] refine Tape.ext rfl ?_ show Function.update (work res).cells 1 _ = Function.update (work res).cells 1 _ rw [hv1, hsymread] by_cases hc : (work sym).cells 1 = Γ.ofBool (expect inp.read).1 - · rw [if_pos hc, decide_eq_true hc] + · rw [ite_eq_left hc, decide_eq_true hc] rfl - · rw [if_neg hc, decide_eq_false hc] + · rw [ite_eq_right hc, decide_eq_false hc] rfl - · rw [if_neg hir, if_neg hir] + · rw [ite_eq_right hir, ite_eq_right hir] by_cases his : i = sym - · rw [if_pos his, if_pos his, his, hright (work sym) (hinv sym) hsym] - · rw [if_neg his, if_neg his, hidle (work i) (hinv i) (hh i)] + · rw [ite_eq_left his, ite_eq_left his, his, hright (work sym) (hinv sym) hsym] + · rw [ite_eq_right his, ite_eq_right his, hidle (work i) (hinv i) (hh i)] · exact transitionTape_eq_self hout -- The tapes after the first step are still well formed. have hW1res : W1 res = ⟨1, Function.update (work res).cells 1 (Γ.ofBool v₁)⟩ := by rw [hW1] show (if res = res then _ else _) = _ - rw [if_pos rfl] + rw [ite_eq_left rfl] have hW1sym : W1 sym = ⟨2, (work sym).cells⟩ := by rw [hW1] show (if sym = res then _ else if sym = sym then _ else _) = _ - rw [if_neg hsr, if_pos rfl] + rw [ite_eq_right hsr, ite_eq_left rfl] have hW1other : ∀ i, i ≠ res → i ≠ sym → W1 i = work i := by intro i h1 h2 rw [hW1] show (if i = res then _ else if i = sym then _ else _) = _ - rw [if_neg h1, if_neg h2] + rw [ite_eq_right h1, ite_eq_right h2] have hinv1 : ∀ i, (W1 i).StartInvariant := by intro i by_cases hir : i = res @@ -269,7 +269,7 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs simp only [] by_cases hir : i = res · have hisym : ¬ (i = sym) := fun hc => hsr (hc.symm.trans hir) - rw [if_pos hir, if_neg hisym, if_pos hir, hir, + rw [ite_eq_left hir, ite_eq_right hisym, ite_eq_left hir, hir, hstay (W1 res) _ (hinv1 res) (by rw [hW1res])] refine Tape.ext rfl ?_ show Function.update (W1 res).cells 1 _ = Function.update (work res).cells 1 _ @@ -280,7 +280,7 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs refine congrArg _ ?_ rw [hv2, inMatchVerdict, hv1] by_cases hc : Γ.ofBool v₁ = Γ.one ∧ (work sym).cells 2 = Γ.ofBool (expect inp.read).2 - · rw [if_pos hc] + · rw [ite_eq_left hc] have h1 : v₁ = true := by rcases hc with ⟨hc1, -⟩ by_contra hne @@ -290,7 +290,7 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs rw [hv1] at h1 rw [h1, decide_eq_true hc.2] rfl - · rw [if_neg hc] + · rw [ite_eq_right hc] have h2 : ¬ (decide ((work sym).cells 1 = Γ.ofBool (expect inp.read).1) && decide ((work sym).cells 2 = Γ.ofBool (expect inp.read).2)) = true := by intro hall @@ -301,12 +301,12 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs rw [Bool.not_eq_true] at h2 rw [h2] rfl - · rw [if_neg hir, if_neg hir] + · rw [ite_eq_right hir, ite_eq_right hir] by_cases his : i = sym - · rw [if_pos his, his, hleft2 (W1 sym) (hinv1 sym) (by rw [hW1sym])] + · rw [ite_eq_left his, his, hleft2 (W1 sym) (hinv1 sym) (by rw [hW1sym])] rw [hW1sym] exact Tape.ext hsym.symm rfl - · rw [if_neg his, hidle (W1 i) (hinv1 i) (hh1 i)] + · rw [ite_eq_right his, hidle (W1 i) (hinv1 i) (hh1 i)] exact hW1other i hir his · exact transitionTape_eq_self hout refine ⟨⟨InMatchPhase.done, inp, W2, out⟩, 2, le_rfl, @@ -314,10 +314,10 @@ theorem inMatchTM_hoareTime (expect : Γ → Bool × Bool) (sym res : Fin n) (hs fun i hi => ?_, ?_⟩ · rw [hW2] show (if i = res then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] · rw [hW2] show (if res = res then _ else _) = _ - rw [if_pos rfl] + rw [ite_eq_left rfl] rfl /-! ## Moving the input head with the simulated one -/ @@ -350,7 +350,7 @@ def inMoveTM (decode : Γ → Γ → Dir3) (mv dir : Fin n) : TM n where intro state iHead wHeads oHead match state with | .go => - exact ⟨fun h => if_pos h, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ + exact ⟨fun h => ite_eq_left h, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ | .done => exact rightOfStart_allIdle iHead wHeads oHead /-- **The contract of the input-head move.** One step; the input head moves as the register says, @@ -369,7 +369,7 @@ theorem inMoveTM_hoareTime (decode : Γ → Γ → Dir3) (mv dir : Fin n) t.writeAndMove (readBackWrite t.read).toΓ (idleDir t.read) = t := by intro t hinvt ht rw [writeAndMove_readBack_of_startInvariant t hinvt, idleDir, - if_neg (hinvt.read_ne_start ht)] + ite_eq_right (hinvt.read_ne_start ht)] rfl have hstep : (inMoveTM decode mv dir).step ⟨InMovePhase.go, inp, work, out⟩ = some ⟨InMovePhase.done, inp.move (decode (work mv).read (work dir).read), work, out⟩ := by @@ -377,7 +377,7 @@ theorem inMoveTM_hoareTime (decode : Γ → Γ → Dir3) (mv dir : Fin n) refine congrArg some (Cfg.ext rfl ?_ ?_ (transitionTape_eq_self hout)) · show inp.move (if inp.read = Γ.start then Dir3.right else decode (work mv).read (work dir).read) = _ - rw [if_neg hinp] + rw [ite_eq_right hinp] · show (fun i => (work i).writeAndMove _ _) = work funext i exact hidle (work i) (hinv i) (hh i) @@ -423,18 +423,18 @@ theorem copyCellTM_hoareTime (src dst : Fin n) (inp₀ out₀ : Tape) (W₀ : Fi t.writeAndMove (readBackWrite t.read).toΓ (idleDir t.read) = t := by intro t hinvt ht rw [writeAndMove_readBack_of_startInvariant t hinvt, idleDir, - if_neg (hinvt.read_ne_start ht)] + ite_eq_right (hinvt.read_ne_start ht)] rfl have hwrite : ∀ (t : Tape) (s : Γ), t.StartInvariant → 1 ≤ t.head → t.writeAndMove s (idleDir t.read) = ⟨t.head, Function.update t.cells t.head s⟩ := by intro t s hinvt ht - rw [idleDir, if_neg (hinvt.read_ne_start ht)] + rw [idleDir, ite_eq_right (hinvt.read_ne_start ht)] refine Tape.ext ?_ ?_ · show (t.write s).head = t.head rw [Tape.write_head] · show (t.write s).cells = _ - rw [Tape.write, if_neg (by omega)] + rw [Tape.write, ite_eq_right (by omega)] have hstep : (copyCellTM src dst).step ⟨InMovePhase.go, inp, work, out⟩ = some ⟨InMovePhase.done, inp, fun i => if i = dst then (⟨(work dst).head, @@ -449,14 +449,14 @@ theorem copyCellTM_hoareTime (src dst : Fin n) (inp₀ out₀ : Tape) (W₀ : Fi ((if i = dst then readBackWrite (work src).read else readBackWrite (work i).read) : Γw).toΓ (idleDir (work i).read) = (if i = dst then _ else _) by_cases hi : i = dst - · rw [if_pos hi, if_pos hi, hi, hwrite (work dst) _ (hinv dst) (hh dst)] - · rw [if_neg hi, if_neg hi, hidle (work i) (hinv i) (hh i)] + · rw [ite_eq_left hi, ite_eq_left hi, hi, hwrite (work dst) _ (hinv dst) (hh dst)] + · rw [ite_eq_right hi, ite_eq_right hi, hidle (work i) (hinv i) (hh i)] refine ⟨_, 1, le_rfl, TM.reachesIn.step hstep TM.reachesIn.zero, rfl, rfl, rfl, fun i hi => ?_, ?_⟩ · show (if i = dst then _ else _) = work i - rw [if_neg hi] + rw [ite_eq_right hi] · show (if dst = dst then _ else _) = _ - rw [if_pos rfl] + rw [ite_eq_left rfl] /-- **Conjoin one register's cell into another.** The destination's cell under its head becomes `1` exactly when both it and the source's cell held `1`. A loop driver with no early exit — such @@ -500,17 +500,17 @@ theorem andCellTM_hoareTime (src dst : Fin n) (inp₀ out₀ : Tape) (W₀ : Fin t.writeAndMove s (idleDir t.read) = ⟨t.head, Function.update t.cells t.head s⟩ := by intro t s hinvt ht - rw [idleDir, if_neg (hinvt.read_ne_start ht)] + rw [idleDir, ite_eq_right (hinvt.read_ne_start ht)] refine Tape.ext ?_ ?_ · show (t.write s).head = t.head rw [Tape.write_head] · show (t.write s).cells = _ - rw [Tape.write, if_neg (by omega)] + rw [Tape.write, ite_eq_right (by omega)] have hidle : ∀ (t : Tape), t.StartInvariant → 1 ≤ t.head → t.writeAndMove (readBackWrite t.read).toΓ (idleDir t.read) = t := by intro t hinvt ht rw [writeAndMove_readBack_of_startInvariant t hinvt, idleDir, - if_neg (hinvt.read_ne_start ht)] + ite_eq_right (hinvt.read_ne_start ht)] rfl have hstep : (andCellTM src dst).step ⟨InMovePhase.go, inp, work, out⟩ = some ⟨InMovePhase.done, inp, @@ -530,19 +530,19 @@ theorem andCellTM_hoareTime (src dst : Fin n) (inp₀ out₀ : Tape) (W₀ : Fin (idleDir (work i).read) = (if i = dst then _ else _) by_cases hi : i = dst · subst hi - rw [if_pos rfl, if_pos rfl, hwrite (work i) _ (hinv i) (hh i)] + rw [ite_eq_left rfl, ite_eq_left rfl, hwrite (work i) _ (hinv i) (hh i)] by_cases hc : (work src).read = Γ.one ∧ (work i).read = Γ.one - · rw [if_pos hc, if_pos hc] + · rw [ite_eq_left hc, ite_eq_left hc] rfl - · rw [if_neg hc, if_neg hc] + · rw [ite_eq_right hc, ite_eq_right hc] rfl - · rw [if_neg hi, if_neg hi, hidle (work i) (hinv i) (hh i)] + · rw [ite_eq_right hi, ite_eq_right hi, hidle (work i) (hinv i) (hh i)] refine ⟨_, 1, le_rfl, TM.reachesIn.step hstep TM.reachesIn.zero, rfl, rfl, rfl, fun i hi => ?_, ?_⟩ · show (if i = dst then _ else _) = work i - rw [if_neg hi] + rw [ite_eq_right hi] · show (if dst = dst then _ else _) = _ - rw [if_pos rfl] + rw [ite_eq_left rfl] /-- **The cell conjunction never consults the guess tape**, so it may sit inside a nondeterministic assembly. -/ diff --git a/Complexitylib/Models/TuringMachine/Subroutines/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/Internal.lean index 9e8f75d6..9ec49192 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/Internal.lean @@ -764,7 +764,7 @@ private theorem blankWorkTM_loop {n : ℕ} (idx : Fin n) (x : List Bool) : (∀ i, x.length ≤ i → (c1.work idx).cells (i + 1) = Γ.blank) := by cases hbit : x[k]'hk_lt with | false => - have hread0 : (c.work idx).read = Γ.zero := by simpa [hbit] using hread + have hread0 : (c.work idx).read = Γ.zero := by simpa [Γ.ofBool, hbit] using hread let c1 : Cfg n (blankWorkTM idx).Q := { state := ScanPhase.scanning input := c.input.move (TM.idleDir c.input.read) @@ -801,7 +801,7 @@ private theorem blankWorkTM_loop {n : ℕ} (idx : Fin n) (x : List Bool) : rw [Function.update_of_ne hne] exact hcell | true => - have hread1 : (c.work idx).read = Γ.one := by simpa [hbit] using hread + have hread1 : (c.work idx).read = Γ.one := by simpa [Γ.ofBool, hbit] using hread let c1 : Cfg n (blankWorkTM idx).Q := { state := ScanPhase.scanning input := c.input.move (TM.idleDir c.input.read) @@ -1040,7 +1040,8 @@ theorem blankWorkTM_hoareTime_frame_of_binaryString {n : ℕ} simp [Tape.read, hhead, hdata k le_rfl hk_lt] cases hbit : x[k]'hk_lt with | false => - have hread0 : (c.work idx).read = Γ.zero := by simpa [hbit] using hread + have hread0 : (c.work idx).read = Γ.zero := by simpa [transitionTape, Γ.ofBool, hbit] + using hread let c1 : Cfg n (blankWorkTM idx).Q := { state := ScanPhase.scanning input := c.input.move (TM.idleDir c.input.read) @@ -1096,7 +1097,8 @@ theorem blankWorkTM_hoareTime_frame_of_binaryString {n : ℕ} hblank_tail1 hinput_keep houtput_keep hwork_keep exact ⟨c', .step hstep1 hreach, hhalt, hhead', hcell0', hblank', hinp', hout', hwork'⟩ | true => - have hread1 : (c.work idx).read = Γ.one := by simpa [hbit] using hread + have hread1 : (c.work idx).read = Γ.one := by simpa [transitionTape, Γ.ofBool, hbit] + using hread let c1 : Cfg n (blankWorkTM idx).Q := { state := ScanPhase.scanning input := c.input.move (TM.idleDir c.input.read) @@ -1290,11 +1292,9 @@ theorem clearWorkTM_hoareTime_frame_of_binaryString {n : ℕ} rw [htarget_tr, hhead1] · rw [hinput_tr, hinp1] exact hinp_ns - · change (TM.transitionTape out1).read ≠ Γ.start - rw [hout_tr, hout1] + · rw [hout_tr, hout1] exact hout_ns - · change (TM.transitionTape out1).head ≥ 1 - rw [hout_tr, hout1] + · rw [hout_tr, hout1] exact hout_h · intro i hi constructor @@ -1306,10 +1306,8 @@ theorem clearWorkTM_hoareTime_frame_of_binaryString {n : ℕ} exact (hother_wf i hi).2 · refine ⟨?_, ?_, ?_⟩ · refine ⟨?_, ?_, ?_⟩ - · change TM.transitionInput inp1 = inp - rw [hinput_tr, hinp1] - · change TM.transitionTape out1 = out - rw [hout_tr, hout1] + · rw [hinput_tr, hinp1] + · rw [hout_tr, hout1] · intro i hi change TM.transitionTape (work1 i) = work i rw [hwork_tr i hi, hwork1 i hi] @@ -1387,7 +1385,7 @@ private theorem copyInputToWorkTM_loop {n : ℕ} (idx : Fin n) (x : List Bool) : simp [TM.idleDir, hread, Tape.move] have hwork_keep : (c.work idx).writeAndMove Γ.blank (TM.idleDir ((c.work idx).read)) = c.work idx := by - simpa [transitionTape, hwork_blank] using + simpa [TM.idleDir, TM.readBackWrite, transitionTape, hwork_blank] using (transitionTape_eq_self (t := c.work idx) (by simp [hwork_blank])) refine ⟨c1, ?_, rfl, ?_, ?_, ?_⟩ · simp [TM.step, hstate, copyInputToWorkTM, hread, c1, allIdle] @@ -1421,7 +1419,7 @@ private theorem copyInputToWorkTM_loop {n : ℕ} (idx : Fin n) (x : List Bool) : cases hbit : x[k]'hk_lt with | false => have hread0 : c.input.read = Γ.zero := by - simpa [hbit] using hread + simpa [Γ.ofBool, hbit] using hread let c1 : Cfg n (copyInputToWorkTM idx).Q := { state := CopyPhase.copying input := c.input.move Dir3.right @@ -1438,10 +1436,10 @@ private theorem copyInputToWorkTM_loop {n : ℕ} (idx : Fin n) (x : List Bool) : c1.work idx = (c.work idx).writeAndMove Γ.zero Dir3.right := by simp [c1] rw [hwidx] - simpa [hbit] using hprefix_next + simpa [Γ.ofBool, hbit] using hprefix_next | true => have hread1 : c.input.read = Γ.one := by - simpa [hbit] using hread + simpa [Γ.ofBool, hbit] using hread let c1 : Cfg n (copyInputToWorkTM idx).Q := { state := CopyPhase.copying input := c.input.move Dir3.right @@ -1458,7 +1456,7 @@ private theorem copyInputToWorkTM_loop {n : ℕ} (idx : Fin n) (x : List Bool) : c1.work idx = (c.work idx).writeAndMove Γ.one Dir3.right := by simp [c1] rw [hwidx] - simpa [hbit] using hprefix_next + simpa [Γ.ofBool, hbit] using hprefix_next obtain ⟨c1, hstep1, hstate1, hcells1, hhead1, hprefix1⟩ := hstep have hrem1 : rem = x.length - (k + 1) := by omega @@ -1582,7 +1580,7 @@ private theorem copyWorkToWorkTM_loop {n : ℕ} cases hbit : x[k]'hk_lt with | false => have hread0 : (c.work src).read = Γ.zero := by - simpa [hbit] using hsrc_read + simpa [Γ.ofBool, hbit] using hsrc_read let c1 : Cfg n (copyWorkToWorkTM src dst).Q := { state := CopyPhase.copying input := c.input.move (TM.idleDir c.input.read) @@ -1609,10 +1607,10 @@ private theorem copyWorkToWorkTM_loop {n : ℕ} c1.work dst = (c.work dst).writeAndMove Γ.zero Dir3.right := by simp [c1] rw [hdst] - simpa [hbit] using hprefix_next + simpa [Γ.ofBool, hbit] using hprefix_next | true => have hread1 : (c.work src).read = Γ.one := by - simpa [hbit] using hsrc_read + simpa [Γ.ofBool, hbit] using hsrc_read let c1 : Cfg n (copyWorkToWorkTM src dst).Q := { state := CopyPhase.copying input := c.input.move (TM.idleDir c.input.read) @@ -1639,7 +1637,7 @@ private theorem copyWorkToWorkTM_loop {n : ℕ} c1.work dst = (c.work dst).writeAndMove Γ.one Dir3.right := by simp [c1] rw [hdst] - simpa [hbit] using hprefix_next + simpa [Γ.ofBool, hbit] using hprefix_next obtain ⟨c1, hstep1, hstate1, hsrc_cells1, hsrc_head1, hprefix1⟩ := hstep have hrem1 : rem = x.length - (k + 1) := by omega @@ -1853,7 +1851,7 @@ theorem copyWorkToWorkTM_hoareTime_frame_of_binaryString {n : ℕ} cases hbit : x[k]'hk_lt with | false => have hread0 : (c.work src).read = Γ.zero := by - simpa [hbit] using hsrc_read + simpa [Γ.ofBool, hbit] using hsrc_read let c1 : Cfg n (copyWorkToWorkTM src dst).Q := { state := CopyPhase.copying input := c.input.move (TM.idleDir c.input.read) @@ -1892,7 +1890,7 @@ theorem copyWorkToWorkTM_hoareTime_frame_of_binaryString {n : ℕ} c1.work dst = (c.work dst).writeAndMove Γ.zero Dir3.right := by simp [c1] rw [hdst] - simpa [hbit] using hprefix_next + simpa [Γ.ofBool, hbit] using hprefix_next have hdst_cell01 : (c1.work dst).cells 0 = Γ.start := by have hdst : c1.work dst = (c.work dst).writeAndMove Γ.zero Dir3.right := by @@ -1909,7 +1907,7 @@ theorem copyWorkToWorkTM_hoareTime_frame_of_binaryString {n : ℕ} hinp', hout', hwork'⟩ | true => have hread1 : (c.work src).read = Γ.one := by - simpa [hbit] using hsrc_read + simpa [Γ.ofBool, hbit] using hsrc_read let c1 : Cfg n (copyWorkToWorkTM src dst).Q := { state := CopyPhase.copying input := c.input.move (TM.idleDir c.input.read) @@ -1948,7 +1946,7 @@ theorem copyWorkToWorkTM_hoareTime_frame_of_binaryString {n : ℕ} c1.work dst = (c.work dst).writeAndMove Γ.one Dir3.right := by simp [c1] rw [hdst] - simpa [hbit] using hprefix_next + simpa [Γ.ofBool, hbit] using hprefix_next have hdst_cell01 : (c1.work dst).cells 0 = Γ.start := by have hdst : c1.work dst = (c.work dst).writeAndMove Γ.one Dir3.right := by diff --git a/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyOutput.lean b/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyOutput.lean index 39c898ff..ccce81f9 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyOutput.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyOutput.lean @@ -103,7 +103,7 @@ private theorem copyInputToOutputTM_loop {n : ℕ} (x : List Bool) : cases hbit : x[k]'hk_lt with | false => have hread0 : c.input.read = Γ.zero := by - simpa [hbit] using hread + simpa [Γ.ofBool, hbit] using hread let c1 : Cfg n (copyInputToOutputTM (n := n)).Q := { state := CopyPhase.copying input := c.input.move Dir3.right @@ -115,10 +115,10 @@ private theorem copyInputToOutputTM_loop {n : ℕ} (x : List Bool) : · simp [TM.step, hstate, copyInputToOutputTM, hread0, c1, readBackWrite] · simpa [c1, Tape.move_cells] using hcells · simp [c1, Tape.move, hhead] - · simpa [c1, hbit] using hprefix_next + · simpa [Γ.ofBool, c1, hbit] using hprefix_next | true => have hread1 : c.input.read = Γ.one := by - simpa [hbit] using hread + simpa [Γ.ofBool, hbit] using hread let c1 : Cfg n (copyInputToOutputTM (n := n)).Q := { state := CopyPhase.copying input := c.input.move Dir3.right @@ -130,7 +130,7 @@ private theorem copyInputToOutputTM_loop {n : ℕ} (x : List Bool) : · simp [TM.step, hstate, copyInputToOutputTM, hread1, c1, readBackWrite] · simpa [c1, Tape.move_cells] using hcells · simp [c1, Tape.move, hhead] - · simpa [c1, hbit] using hprefix_next + · simpa [Γ.ofBool, c1, hbit] using hprefix_next obtain ⟨c1, hstep1, hstate1, hcells1, hhead1, hprefix1⟩ := hstep have hrem1 : rem = x.length - (k + 1) := by omega obtain ⟨c', hreach, hhalt, hcells', hhead', hprefix'⟩ := diff --git a/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyWorkOutput.lean b/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyWorkOutput.lean index e04f1d36..45d70aeb 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyWorkOutput.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/Internal/CopyWorkOutput.lean @@ -144,7 +144,7 @@ private theorem copyWorkOutput_loop {n : ℕ} have hdstTape : c1.work dst = (c.work dst).writeAndMove (Γ.ofBool bit) Dir3.right := by dsimp only [c1] - simp only [if_pos] + simp only [ite_eq_left] rw [Γw.ofBool_toΓ] have hdstPrefix1 : (c1.work dst).HasBinaryPrefix (x.take (k + 1)) := by rw [hdstTape] @@ -152,7 +152,7 @@ private theorem copyWorkOutput_loop {n : ℕ} have hdst01 : (c1.work dst).cells 0 = dstCell0 := by rw [hdstTape] simp only [Tape.writeAndMove, Tape.move_cells, Tape.write] - rw [if_neg (by rw [hprefix.1]; omega)] + rw [ite_eq_right (by rw [hprefix.1]; omega)] change Function.update (c.work dst).cells (c.work dst).head (Γ.ofBool bit) 0 = dstCell0 rw [Function.update_of_ne (by rw [hprefix.1]; omega)] @@ -250,7 +250,7 @@ private theorem copyWorkOutput_step_frame {n : ℕ} (src dst : Fin n) exact hneHalt (by simpa [copyWorkToWorkTM] using hstate) | copying => unfold TM.step at hstep - rw [if_neg hneHalt] at hstep + rw [ite_eq_right hneHalt] at hstep have hc := Option.some.inj hstep rw [← hc] rw [hstate] diff --git a/Complexitylib/Models/TuringMachine/Subroutines/Internal/ScanRight.lean b/Complexitylib/Models/TuringMachine/Subroutines/Internal/ScanRight.lean index 02518d97..e139c1d4 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/Internal/ScanRight.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/Internal/ScanRight.lean @@ -49,7 +49,7 @@ private theorem scanRightTM_step_bit {n : ℕ} (idx : Fin n) have hnotBlank : (c.work idx).read ≠ Γ.blank := by rw [hread] cases bit <;> decide - rw [TM.step, if_neg hstate] + rw [TM.step, ite_eq_right hstate] simp only [scanRightTM, hst, hnotBlank, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -60,7 +60,7 @@ private theorem scanRightTM_step_bit {n : ℕ} (idx : Fin n) apply writeAndMove_readBack rw [hread] cases bit <;> decide - · rw [if_neg hi, Function.update_of_ne hi] + · rw [ite_eq_right hi, Function.update_of_ne hi] exact transitionTape_eq_self (hother i hi) · exact transitionTape_eq_self hout @@ -79,7 +79,7 @@ private theorem scanRightTM_step_blank {n : ℕ} (idx : Fin n) output := c.output } := by have hstate : c.state ≠ (scanRightTM idx).qhalt := by simp [scanRightTM, hst] - rw [TM.step, if_neg hstate] + rw [TM.step, ite_eq_right hstate] simp only [scanRightTM, hst, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp diff --git a/Complexitylib/Models/TuringMachine/Subroutines/MoveLeftStep.lean b/Complexitylib/Models/TuringMachine/Subroutines/MoveLeftStep.lean index b90a8c63..8f979650 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/MoveLeftStep.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/MoveLeftStep.lean @@ -37,7 +37,7 @@ theorem writeAndMove_readBack_of_startInvariant (t : Tape) (h : Tape.StartInvari by_cases hh : t.head = 0 · show (t.write _).move d = t.move d congr 1 - rw [Tape.write, if_pos hh] + rw [Tape.write, ite_eq_left hh] · exact writeAndMove_readBack t (h.read_ne_start (by omega)) d /-- One unconditional step: every work tape named in `targets` moves left @@ -92,14 +92,14 @@ theorem moveLeftStepTM_hoareTime {n : ℕ} (targets : List (Fin n)) 1, le_refl 1, ?_, rfl, hinp.move_idle, hout.writeAndMove_readBack_idle, fun i => ?_⟩ · refine TM.reachesIn.step ?_ .zero simp only [TM.step, moveLeftStepTM, - if_neg (show WipeStepPhase.running ≠ WipeStepPhase.done by decide)] + ite_eq_right (show WipeStepPhase.running ≠ WipeStepPhase.done by decide)] congr 1 congr 1 funext i by_cases hi : i ∈ targets - · simp only [if_pos hi] + · simp only [ite_eq_left hi] exact writeAndMove_readBack_of_startInvariant (work i) (htarget i hi) _ - · simp only [if_neg hi] + · simp only [ite_eq_right hi] · dsimp only split · rfl diff --git a/Complexitylib/Models/TuringMachine/Subroutines/PairEmit/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/PairEmit/Internal.lean index 1a430df2..b77f50d2 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/PairEmit/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/PairEmit/Internal.lean @@ -63,13 +63,13 @@ private theorem pairInputWorkTM_first_loop {n : ℕ} (firstIdx : Fin n) : simp [TM.step, hstate, pairInputWorkTM, hsourceRead, c₁, transitionInput, transitionTape] have hinputKeep₁ : c₁.input = c.input := by - simpa [c₁] using transitionInput_eq_self hinput + simpa [transitionTape, c₁] using transitionInput_eq_self hinput have hsourceKeep₁ : c₁.work firstIdx = c.work firstIdx := by simpa [c₁] using transitionTape_eq_self (by rw [hsourceRead]; decide) have hotherKeep₁ (i) (hi : i ≠ firstIdx) : c₁.work i = c.work i := by - simpa [c₁] using transitionTape_eq_self (hother i hi) + simpa [Γ.ofBool, c₁] using transitionTape_eq_self (hother i hi) have houtput₁ : c₁.output.HasBinaryPrefix (emitted ++ [false]) := by - simpa [c₁] using Tape.hasBinaryPrefix_write_bit false houtput + simpa [Γ.ofBool, c₁] using Tape.hasBinaryPrefix_write_bit false houtput let c₂ : Cfg n (pairInputWorkTM firstIdx).Q := { state := PairInputWorkPhase.second input := transitionInput c₁.input @@ -94,7 +94,7 @@ private theorem pairInputWorkTM_first_loop {n : ℕ} (firstIdx : Fin n) : hstable, hotherKeep₁ i hi] have houtput₂ : c₂.output.HasBinaryPrefix (emitted ++ [false, true]) := by have hwrite := Tape.hasBinaryPrefix_write_bit true houtput₁ - simpa [c₂, List.append_assoc] using hwrite + simpa [c₂, Γ.ofBool, List.append_assoc] using hwrite refine ⟨c₂, ?_, rfl, hinputKeep₂, ?_, ?_, hotherKeep₂, ?_⟩ · simpa using TM.reachesIn.step hstep₁ (TM.reachesIn.step hstep₂ .zero) · rw [hsourceKeep₂] @@ -115,13 +115,13 @@ private theorem pairInputWorkTM_first_loop {n : ℕ} (firstIdx : Fin n) : simp [TM.step, hstate, pairInputWorkTM, hsourceRead, c₁, transitionInput, transitionTape, Γ.ofBool, Γw.toΓ, readBackWrite] have hinputKeep₁ : c₁.input = c.input := by - simpa [c₁] using transitionInput_eq_self hinput + simpa [transitionTape, c₁] using transitionInput_eq_self hinput have hsourceKeep₁ : c₁.work firstIdx = c.work firstIdx := by simpa [c₁] using transitionTape_eq_self hsource.read_ne_start have hotherKeep₁ (i) (hi : i ≠ firstIdx) : c₁.work i = c.work i := by - simpa [c₁] using transitionTape_eq_self (hother i hi) + simpa [Γ.ofBool, c₁] using transitionTape_eq_self (hother i hi) have houtput₁ : c₁.output.HasBinaryPrefix (emitted ++ [bit]) := by - simpa [c₁] using Tape.hasBinaryPrefix_write_bit bit houtput + simpa [Γ.ofBool, c₁] using Tape.hasBinaryPrefix_write_bit bit houtput let c₂ : Cfg n (pairInputWorkTM firstIdx).Q := { state := PairInputWorkPhase.first input := transitionInput c₁.input @@ -165,7 +165,8 @@ private theorem pairInputWorkTM_first_loop {n : ℕ} (firstIdx : Fin n) : exact hother i hi) houtput₂ refine ⟨c', ?_, hstate', ?_, hsource', ?_, ?_, ?_⟩ - · simpa using TM.reachesIn.step hstep₁ (TM.reachesIn.step hstep₂ hreach) + · show TM.reachesIn _ (2 * bits.length + 2 + 1 + 1) _ _ + exact TM.reachesIn.step hstep₁ (TM.reachesIn.step hstep₂ hreach) · exact hinput'.trans hinputKeep₂ · rw [hsourceCells', hsourceMove, Tape.move_cells] · intro i hi @@ -234,7 +235,7 @@ private theorem pairInputWorkTM_second_loop {n : ℕ} (firstIdx : Fin n) : rw [hworkKeep] exact hwork i have houtput₁ : c₁.output.HasBinaryPrefix (emitted ++ [bit]) := by - simpa [c₁] using Tape.hasBinaryPrefix_write_bit bit houtput + simpa [Γ.ofBool, c₁] using Tape.hasBinaryPrefix_write_bit bit houtput obtain ⟨c', hreach, hhalt, hinput', hinputCells', hwork', houtput'⟩ := ih (emitted ++ [bit]) c₁ rfl hinput₁ hwork₁ houtput₁ refine ⟨c', ?_, hhalt, hinput', ?_, ?_, ?_⟩ diff --git a/Complexitylib/Models/TuringMachine/Subroutines/PairSplit/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/PairSplit/Internal.lean index ba8a14bd..a7447303 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/PairSplit/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/PairSplit/Internal.lean @@ -46,7 +46,7 @@ private theorem pairSplit_scanX_false_step {k : ℕ} (xIdx yIdx : Fin k) c'.input.cells = c.input.cells ∧ c'.work xIdx = c.work xIdx ∧ c'.work yIdx = c.work yIdx := by - simp only [TM.step, hst, pairSplitCoreTM, if_pos hiread] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_left hiread] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · simp [Tape.move] · simpa using (Tape.move_cells c.input Dir3.right) @@ -71,7 +71,7 @@ private theorem pairSplit_scanX_true_step {k : ℕ} (xIdx yIdx : Fin k) have hne_zero : c.input.read ≠ Γ.zero := by rw [hiread] decide - simp only [TM.step, hst, pairSplitCoreTM, if_neg hne_zero, if_pos hiread] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_right hne_zero, ite_eq_left hiread] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · simp [Tape.move] · simpa using (Tape.move_cells c.input Dir3.right) @@ -95,7 +95,7 @@ private theorem pairSplit_afterFalse_zero_step {k : ℕ} (xIdx yIdx : Fin k) (c'.work xIdx).cells = Function.update (c.work xIdx).cells (c.work xIdx).head Γ.zero ∧ c'.work yIdx = c.work yIdx := by - simp only [TM.step, hst, pairSplitCoreTM, if_pos hiread] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_left hiread] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · simp [Tape.move] · simpa using (Tape.move_cells c.input Dir3.right) @@ -106,7 +106,7 @@ private theorem pairSplit_afterFalse_zero_step {k : ℕ} (xIdx yIdx : Fin k) simp [Tape.writeAndMove, Tape.move_cells, Tape.write, show (c.work xIdx).head ≠ 0 from by omega] · dsimp only [] - simp only [if_neg (Ne.symm hne)] + simp only [ite_eq_right (Ne.symm hne)] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns /-- In `.afterFalse`, reading `true` recognizes the separator and enters @@ -127,7 +127,7 @@ private theorem pairSplit_afterFalse_sep_step {k : ℕ} (xIdx yIdx : Fin k) have hne_zero : c.input.read ≠ Γ.zero := by rw [hiread] decide - simp only [TM.step, hst, pairSplitCoreTM, if_neg hne_zero, if_pos hiread] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_right hne_zero, ite_eq_left hiread] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · simp [Tape.move] · simpa using (Tape.move_cells c.input Dir3.right) @@ -151,7 +151,7 @@ private theorem pairSplit_writeTrue_step {k : ℕ} (xIdx yIdx : Fin k) (c'.work xIdx).cells = Function.update (c.work xIdx).cells (c.work xIdx).head Γ.one ∧ c'.work yIdx = c.work yIdx := by - simp only [TM.step, hst, pairSplitCoreTM, if_pos hiread] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_left hiread] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · simp [Tape.move] · simpa using (Tape.move_cells c.input Dir3.right) @@ -162,7 +162,7 @@ private theorem pairSplit_writeTrue_step {k : ℕ} (xIdx yIdx : Fin k) simp [Tape.writeAndMove, Tape.move_cells, Tape.write, show (c.work xIdx).head ≠ 0 from by omega] · dsimp only [] - simp only [if_neg (Ne.symm hne)] + simp only [ite_eq_right (Ne.symm hne)] exact tape_writeAndMove_stable (c.work yIdx) hyh hyns /-- Two-step decoding of a doubled `false` bit. -/ @@ -339,9 +339,9 @@ private theorem pairSplit_scanX_loop {k : ℕ} (xIdx yIdx : Fin k) | false => have hread0 : c.input.read = Γ.zero := by show c.input.cells c.input.head = Γ.zero - simpa using hbits0.1 + simpa [Γ.ofBool] using hbits0.1 have hnext0 : c.input.cells (c.input.head + 1) = Γ.zero := by - simpa using hbits0.2 + simpa [Γ.ofBool] using hbits0.2 obtain ⟨c1, hreach1, hst1, hc1_ih, hc1_ic, hc1_xh, hc1_xc, hc1_yw⟩ := pairSplit_false_bit_step xIdx yIdx hne c hst hread0 hnext0 hxh hxns hyh hyns have hc1_ih_ge : c1.input.head ≥ 1 := by rw [hc1_ih]; omega @@ -430,9 +430,9 @@ private theorem pairSplit_scanX_loop {k : ℕ} (xIdx yIdx : Fin k) | true => have hread1 : c.input.read = Γ.one := by show c.input.cells c.input.head = Γ.one - simpa using hbits0.1 + simpa [Γ.ofBool] using hbits0.1 have hnext1 : c.input.cells (c.input.head + 1) = Γ.one := by - simpa using hbits0.2 + simpa [Γ.ofBool] using hbits0.2 obtain ⟨c1, hreach1, hst1, hc1_ih, hc1_ic, hc1_xh, hc1_xc, hc1_yw⟩ := pairSplit_true_bit_step xIdx yIdx hne c hst hread1 hnext1 hxh hxns hyh hyns have hc1_ih_ge : c1.input.head ≥ 1 := by rw [hc1_ih]; omega @@ -531,7 +531,7 @@ private theorem pairSplit_copyY_halt_step {k : ℕ} (xIdx yIdx : Fin k) c'.input = c.input ∧ c'.work xIdx = c.work xIdx ∧ c'.work yIdx = c.work yIdx := by - simp only [TM.step, hst, pairSplitCoreTM, if_pos hiread, pairSplitIdle] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_left hiread, pairSplitIdle] refine ⟨_, rfl, rfl, ?_, ?_, ?_⟩ · simp [hiread, idleDir, Tape.move] · have hxread_ns : (c.work xIdx).read ≠ Γ.start := by simp [hxread] @@ -559,12 +559,12 @@ private theorem pairSplit_copyY_cont_step {k : ℕ} (xIdx yIdx : Fin k) (c'.work yIdx).head = (c.work yIdx).head + 1 ∧ (c'.work yIdx).cells = Function.update (c.work yIdx).cells (c.work yIdx).head c.input.read := by - simp only [TM.step, hst, pairSplitCoreTM, if_neg hiread_nb] + simp only [TM.step, hst, pairSplitCoreTM, ite_eq_right hiread_nb] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · simp [Tape.move] · simpa using (Tape.move_cells c.input Dir3.right) - · simp only [if_neg hne] + · simp only [ite_eq_right hne] exact tape_writeAndMove_stable (c.work xIdx) hxh hxns · dsimp only [] simp only [↓reduceIte] @@ -585,7 +585,7 @@ private theorem pairSplit_copyY_cont_step {k : ℕ} (xIdx yIdx : Fin k) unfold Tape.writeAndMove rw [Tape.move_cells] unfold Tape.write - rw [if_neg (show (c.work yIdx).head ≠ 0 from by omega)] + rw [ite_eq_right (show (c.work yIdx).head ≠ 0 from by omega)] change Function.update (c.work yIdx).cells (c.work yIdx).head _ = Function.update (c.work yIdx).cells (c.work yIdx).head _ exact congrArg (Function.update (c.work yIdx).cells (c.work yIdx).head) hwrite diff --git a/Complexitylib/Models/TuringMachine/Subroutines/PairValidate/Internal.lean b/Complexitylib/Models/TuringMachine/Subroutines/PairValidate/Internal.lean index 30db1961..6d573562 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/PairValidate/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/PairValidate/Internal.lean @@ -107,10 +107,10 @@ theorem pairValidateTM_lift_hoareTime_internal (workTapes : ℕ) (bits : List Bo | succ j => simp [Tape.init]) have hwf : AllTapesWF C.input C.work C.output := by refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ - · rw [liftCfg_input, hinputCells] + · erw [liftCfg_input, hinputCells] rfl · intro j hj - rw [liftCfg_input, hinputCells] + erw [liftCfg_input, hinputCells] exact Tape.init_ofBool_cells_ne_start bits j hj · intro i rw [hwork i] @@ -120,8 +120,8 @@ theorem pairValidateTM_lift_hoareTime_internal (workTapes : ℕ) (bits : List Bo cases j with | zero => omega | succ j => simp [Tape.move, Tape.init] - · simpa only [liftCfg_output] using houtput0 - · simpa only [liftCfg_output] using houtputNoStart + · exact houtput0 + · exact houtputNoStart have hyes : bits ∈ validPairEncoding → C.output.cells 1 = Γ.one := by intro hmem rw [show C.output = c'.output from rfl, hout] diff --git a/Complexitylib/Models/TuringMachine/Subroutines/ParkAll.lean b/Complexitylib/Models/TuringMachine/Subroutines/ParkAll.lean index 1c53a15b..53e3fa19 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/ParkAll.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/ParkAll.lean @@ -37,12 +37,12 @@ theorem move_idleDir_eq_of_startInvariant {t : Tape} (h : Tape.StartInvariant t) · have hh0 : t.head = 0 := by by_contra hc exact (h.2 t.head (by omega)) hh - rw [idleDir, if_pos hh] + rw [idleDir, ite_eq_left hh] refine Tape.ext ?_ (Tape.move_cells t Dir3.right) show t.head + 1 = max t.head 1 omega · have hh0 : t.head ≠ 0 := fun hc => hh (by rw [Tape.read, hc]; exact h.1) - rw [idleDir, if_neg hh] + rw [idleDir, ite_eq_right hh] show t = ⟨max t.head 1, t.cells⟩ have : max t.head 1 = t.head := by omega rw [this] @@ -74,7 +74,7 @@ theorem parkAll_hoareTime {n : ℕ} (inp₀ : Tape) (work₀ : Fin n → Tape) ( 1, le_refl 1, ?_, rfl, ?_, ?_, ?_⟩ · refine TM.reachesIn.step ?_ .zero simp only [TM.step, skipTM, - if_neg (show BumpPhase.go ≠ BumpPhase.done by decide), + ite_eq_right (show BumpPhase.go ≠ BumpPhase.done by decide), writeAndMove_readBack_of_startInvariant out hout] congr 2 funext i diff --git a/Complexitylib/Models/TuringMachine/Subroutines/ParkRewind.lean b/Complexitylib/Models/TuringMachine/Subroutines/ParkRewind.lean index 7c09b543..38423815 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/ParkRewind.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/ParkRewind.lean @@ -112,12 +112,10 @@ theorem parkRewindTM_hoareTime (targets : List (Fin n)) (hnodup : targets.Nodup) (fun _ => O1) b ?_ ?_ (fun _ => hO1P) ?_).consequence (fun _ _ _ h => h) (fun _ _ _ h => h) (le_refl _) · intro k - dsimp only split · exact hI1P · exact hI2P · intro k i - dsimp only split · exact hW1P i · exact hW3P i @@ -152,11 +150,11 @@ theorem parkRewindTM_hoareTime (targets : List (Fin n)) (hnodup : targets.Nodup) by_cases hj : j ∈ targets · rw [hin j hj] show (⟨1, (W1 j).cells⟩ : Tape) = W3 j - simp only [hW3def, if_pos hj] + simp only [hW3def, ite_eq_left hj] rfl · rw [hout j hj] show W1 j = W3 j - simp only [hW3def, if_neg hj] + simp only [hW3def, ite_eq_right hj] rfl exact seqTM_hoareTime skipTM _ hpark htrans hrest @@ -214,10 +212,10 @@ theorem parkRewindWorkTM_hoareTime (targets : List (Fin n)) (hnodup : targets.No by_cases hj : j ∈ targets · rw [hin j hj] show (⟨1, (W1 j).cells⟩ : Tape) = W3 j - simp only [hW3def, if_pos hj] + simp only [hW3def, ite_eq_left hj] rfl · rw [hout j hj, hW3def, hW1def] - simp only [if_neg hj] + simp only [ite_eq_right hj] exact seqTM_hoareTime skipTM _ hpark htrans hrest end TM diff --git a/Complexitylib/Models/TuringMachine/Subroutines/ResetTapes.lean b/Complexitylib/Models/TuringMachine/Subroutines/ResetTapes.lean index c9f9180c..84bb4d09 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/ResetTapes.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/ResetTapes.lean @@ -131,7 +131,7 @@ theorem resetTapes_hoareTime {n : ℕ} (targets : List (Fin n)) (hnodup : target by_cases hjt : j ∈ targets · rw [hts j hjt, hworkC]; simp [hjt] · rw [hnts j hjt, hworkC] - simp only [hjt, if_false] + simp only [hjt, ite_false] exact Tape.ext (by show max (work₀ j).head 1 = (work₀ j).head have := (hother j hjr hjt).1 @@ -173,7 +173,7 @@ theorem resetTapes_hoareTime {n : ℕ} (targets : List (Fin n)) (hnodup : target rintro inp work out ⟨hi, hw, ho⟩ refine ⟨hi, ho.trans hout0.symm, fun j hjt => ?_, ?_, fun j hjr hjt => ?_⟩ · rw [hw, Function.update_of_ne (fun h => hr (by rw [h] at hjt; exact hjt)), - if_pos hjt, hworkC] + ite_eq_left hjt, hworkC] simp [hjt] · rw [hw, Function.update_self] · rw [hw, Function.update_of_ne hjr, hworkC] @@ -233,7 +233,7 @@ theorem resetTapesTM_hoareTime {n : ℕ} (targets : List (Fin n)) (hnodup : targ dsimp only split · exact ⟨show 1 ≤ H + 1 by omega, - fun i hi => by rw [initNil_cells, if_neg (by omega)]; decide⟩ + fun i hi => by rw [initNil_cells, ite_eq_right (by omega)]; decide⟩ · split · exact hregParked · next hjt hjr => exact hother j hjr hjt @@ -241,8 +241,8 @@ theorem resetTapesTM_hoareTime {n : ℕ} (targets : List (Fin n)) (hnodup : targ (workD j).cells 0 = Γ.start ∧ (workD j).head ≤ H + 1 := by intro j hj rw [hworkD] - simp only [if_pos hj] - exact ⟨by rw [initNil_cells, if_pos rfl], le_refl _⟩ + simp only [ite_eq_left hj] + exact ⟨by rw [initNil_cells, ite_eq_left rfl], le_refl _⟩ have hfirst := resetTapes_hoareTime targets hnodup r hr H inp₀ work₀ out₀ hinpSI hinpP hout0 hworkSI htargetHead hworkR hother have hsecond := rewindList_hoareTime targets hnodup (H + 1) inp₀ workD out₀ hinpP houtP @@ -265,7 +265,7 @@ theorem resetTapesTM_hoareTime {n : ℕ} (targets : List (Fin n)) (hnodup : targ · rintro inp work out ⟨hi, ho, hts, hnts⟩ refine ⟨hi, ho, fun j hj => ?_, ?_, fun j hjr hjt => ?_⟩ · rw [hts j hj, hworkD] - simp only [if_pos hj] + simp only [ite_eq_left hj] rfl · rw [hnts r hr, hworkD] simp [hr] diff --git a/Complexitylib/Models/TuringMachine/Subroutines/Scan.lean b/Complexitylib/Models/TuringMachine/Subroutines/Scan.lean index 9bdeb4c6..45bbe78d 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/Scan.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/Scan.lean @@ -142,13 +142,13 @@ def ofRight {j : ℕ} (τ : Type) [DecidableEq τ] [Fintype τ] (start : τ) (p : ℕ) (s : τ) : (ofRight τ start step emit).runL cols p s = s := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL]; exact ih _ + | succ p ih => simp only [runL]; exact ih _ theorem ofRight_run {j : ℕ} (τ : Type) [DecidableEq τ] [Fintype τ] (start : τ) (step : τ → (Fin (j + 1) → Γ) → τ) (emit : τ → Bool) (cols : ℕ → Fin (j + 1) → Γ) (len : ℕ) : (ofRight τ start step emit).run cols len = (ofRight τ start step emit).runR cols len := by - rw [run, ofRight_runL] + rw [run]; apply ofRight_runL /-! ## Running a scanner on a wider tape set @@ -181,7 +181,7 @@ theorem comap_runL {j jj : ℕ} (S : Scanner j) (f : Fin (j + 1) → Fin (jj + 1 (S.comap f).runL cols p s = S.runL (fun q i => cols q (f i)) p s := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL, runL, ih]; rfl + | succ p ih => simp only [runL]; exact ih _ /-- **A scanner run through a map reads exactly the columns the map names.** -/ theorem comap_run {j jj : ℕ} (S : Scanner j) (f : Fin (j + 1) → Fin (jj + 1)) @@ -212,7 +212,7 @@ theorem runL_of_rightOnly {j : ℕ} {S : Scanner j} (hS : RightOnly S) intro p induction p with | zero => intro s; rfl - | succ p ih => intro s; rw [runL, hS, ih] + | succ p ih => intro s; simp only [runL]; rw [hS]; exact ih _ /-- The saturating position counter a frozen check carries. -/ def upToIdx (w p : ℕ) : Fin (w + 1) := ⟨min p w, by omega⟩ @@ -246,7 +246,7 @@ theorem upTo_runR {j : ℕ} (S : Scanner j) (w : ℕ) (cols : ℕ → Fin (j + 1 (S.stepR (S.runR cols (min p w)) (cols (p + 1)), (⟨((upToIdx w p : Fin (w + 1)) : ℕ) + 1, by omega⟩ : Fin (w + 1))) else (S.runR cols (min p w), upToIdx w p)) = _ - rw [dif_pos hlt] + rw [dite_eq_left hlt] refine Prod.ext ?_ (Fin.ext ?_) · show S.stepR (S.runR cols (min p w)) (cols (p + 1)) = S.runR cols (min (p + 1) w) rw [hmin, hmin'] @@ -261,7 +261,7 @@ theorem upTo_runR {j : ℕ} (S : Scanner j) (w : ℕ) (cols : ℕ → Fin (j + 1 (S.stepR (S.runR cols (min p w)) (cols (p + 1)), (⟨((upToIdx w p : Fin (w + 1)) : ℕ) + 1, by omega⟩ : Fin (w + 1))) else (S.runR cols (min p w), upToIdx w p)) = _ - rw [dif_neg hge] + rw [dite_eq_right hge] refine Prod.ext ?_ (Fin.ext ?_) · show S.runR cols (min p w) = S.runR cols (min (p + 1) w) rw [show min (p + 1) w = min p w by omega] @@ -272,7 +272,7 @@ theorem upTo_runL {j : ℕ} (S : Scanner j) (w : ℕ) (cols : ℕ → Fin (j + 1 (s : (S.upTo w).σ) : (S.upTo w).runL cols p s = (S.runL cols p s.1, s.2) := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL, ih]; rfl + | succ p ih => simp only [runL, ih]; rfl /-- **A frozen check gives the verdict it would have given on its own cells.** -/ theorem upTo_emit_run {j : ℕ} (S : Scanner j) (hS : RightOnly S) (w len : ℕ) (hw : w ≤ len) @@ -315,7 +315,7 @@ theorem after_runR {j : ℕ} (S : Scanner j) (w : ℕ) (cols : ℕ → Fin (j + (⟨((upToIdx w p : Fin (w + 1)) : ℕ) + 1, by omega⟩ : Fin (w + 1))) else (S.stepR (S.runR (fun q => cols (w + q)) (p - w)) (cols (p + 1)), upToIdx w p)) = _ - rw [dif_pos hlt] + rw [dite_eq_left hlt] refine Prod.ext ?_ (Fin.ext ?_) · show S.runR (fun q => cols (w + q)) (p - w) = S.runR (fun q => cols (w + q)) (p + 1 - w) @@ -331,7 +331,7 @@ theorem after_runR {j : ℕ} (S : Scanner j) (w : ℕ) (cols : ℕ → Fin (j + (⟨((upToIdx w p : Fin (w + 1)) : ℕ) + 1, by omega⟩ : Fin (w + 1))) else (S.stepR (S.runR (fun q => cols (w + q)) (p - w)) (cols (p + 1)), upToIdx w p)) = _ - rw [dif_neg hge] + rw [dite_eq_right hge] refine Prod.ext ?_ (Fin.ext ?_) · show S.stepR (S.runR (fun q => cols (w + q)) (p - w)) (cols (p + 1)) = S.runR (fun q => cols (w + q)) (p + 1 - w) @@ -345,7 +345,7 @@ theorem after_runL {j : ℕ} (S : Scanner j) (w : ℕ) (cols : ℕ → Fin (j + (s : (S.after w).σ) : (S.after w).runL cols p s = (S.runL cols p s.1, s.2) := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL, ih]; rfl + | succ p ih => simp only [runL, ih]; rfl /-- **A check that skips a prefix reads the cells after it.** -/ theorem after_emit_run {j : ℕ} (S : Scanner j) (hS : RightOnly S) (w len : ℕ) @@ -391,7 +391,7 @@ theorem all_runL {jj : ℕ} (n : ℕ) (S : Fin n → Scanner jj) (cols : ℕ → (all n S).runL cols p s i = (S i).runL cols p (s i) := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL, runL, ih]; rfl + | succ p ih => simp only [runL, runL, ih]; rfl /-- **Each component of a joint scan runs its own scan.** -/ theorem all_run {jj : ℕ} (n : ℕ) (S : Fin n → Scanner jj) (cols : ℕ → Fin (jj + 1) → Γ) @@ -427,14 +427,14 @@ theorem or_runL {jj : ℕ} (S T : Scanner jj) (cols : ℕ → Fin (jj + 1) → (s : S.σ × T.σ) : (S.or T).runL cols p s = (S.runL cols p s.1, T.runL cols p s.2) := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL, ih]; rfl + | succ p ih => simp only [runL]; exact ih _ /-- **A disjunctive scan accepts exactly when one of its halves does.** -/ theorem or_emit_run {jj : ℕ} (S T : Scanner jj) (cols : ℕ → Fin (jj + 1) → Γ) (len : ℕ) : (S.or T).emit ((S.or T).run cols len) = true ↔ S.emit (S.run cols len) = true ∨ T.emit (T.run cols len) = true := by show (S.emit _ || T.emit _) = true ↔ _ - rw [run, or_runL, or_runR] + rw [run]; erw [or_runL, or_runR] simp [run] /-! ## Reading parameters before checking @@ -499,9 +499,9 @@ theorem prefixed_runR_le (c : ℕ) (a₀ : α) (readStep : α → (Fin (j + 1) have hlt : ((prefixed c α τ a₀ readStep t₀ mainStep emit).runR cols p).1.val < c := by rw [h1]; omega constructor - · rw [runR, prefixed_stepR, dif_pos hlt] + · rw [runR]; erw [prefixed_stepR, dite_eq_left hlt] simpa using h1 - · rw [runR, prefixed_stepR, dif_pos hlt, auxRun, h2] + · rw [runR]; erw [prefixed_stepR, dite_eq_left hlt]; rw [auxRun, h2] end Scanner @@ -525,18 +525,18 @@ theorem prefixed_runR (c : ℕ) (a₀ : α) (readStep : α → (Fin (j + 1) → obtain ⟨h1, h2⟩ := prefixed_runR_le (c' + 1) a₀ readStep t₀ mainStep emit cols c' (by omega) have hlt : ((prefixed (c' + 1) α τ a₀ readStep t₀ mainStep emit).runR cols c').1.val < c' + 1 := by rw [h1]; omega - rw [Nat.add_zero, runR, prefixed_stepR, dif_pos hlt, h2, mainRun] + rw [Nat.add_zero, runR]; erw [prefixed_stepR, dite_eq_left hlt, h2, mainRun] refine Prod.ext ?_ (Prod.ext ?_ ?_) · exact Fin.ext (by simpa using h1) · rw [auxRun] - · rw [if_pos (by omega), auxRun] + · rw [ite_eq_left (by omega), auxRun] | succ q ih => have hnot : ¬ ((prefixed c α τ a₀ readStep t₀ mainStep emit).runR cols (c + q)).1.val < c := by rw [ih] exact Nat.lt_irrefl c - rw [show c + (q + 1) = (c + q) + 1 by omega, runR, prefixed_stepR, dif_neg hnot, ih, - mainRun] + rw [show c + (q + 1) = (c + q) + 1 by omega, runR] + erw [prefixed_stepR, dite_eq_right hnot, ih]; rfl /-- **What a parameterized scan reports**: the check the parameters chose, run on the data after them. -/ @@ -551,7 +551,7 @@ theorem prefixed_run (c : ℕ) (a₀ : α) (readStep : α → (Fin (j + 1) → have hrunL : ∀ s : Fin (c + 1) × α × τ, (prefixed c α τ a₀ readStep t₀ mainStep emit).runL cols (c + q) s = s := fun s => ofRight_runL (Fin (c + 1) × α × τ) _ _ _ cols (c + q) s - rw [run, hrunL, prefixed_runR c a₀ readStep t₀ mainStep emit cols hc q] + rw [run]; erw [hrunL, prefixed_runR c a₀ readStep t₀ mainStep emit cols hc q] rfl /-! ## Reading fixed-width fields into the control @@ -605,7 +605,7 @@ theorem bitsStep_run {j : ℕ} (s w : ℕ) (regs : Fin s → Fin (j + 1)) obtain ⟨h1, h2⟩ := ih (by omega) have hlt : (auxRun (⟨0, Nat.zero_lt_succ w⟩, x₀) (bitsStep s w regs) cols p).1.val < w := by rw [h1]; omega - rw [auxRun, bitsStep, dif_pos hlt] + rw [auxRun, bitsStep, dite_eq_left hlt] refine ⟨by simpa using h1, fun t i hi => ?_⟩ dsimp only rcases Nat.lt_or_ge i.val p with h | h @@ -702,7 +702,7 @@ theorem cellFold_chunk {j : ℕ} {χ : Type} = (1, cols (off + 3 * p + 1), (cellFold (chunkStepCell f) cols off (0, u, v, x₀) (3 * p)).2.2.1, chunkRun f cols off x₀ p) := by - rw [chunkStepCell, if_pos h0, hx] + rw [chunkStepCell, ite_eq_left h0, hx] rw [e0] have e1 : chunkStepCell f (1, cols (off + 3 * p + 1), @@ -735,7 +735,7 @@ theorem rightOnly_eq (j : ℕ) (a b : Fin (j + 1)) : RightOnly (eq j a b) := fun (s : Bool) : (eq j a b).runL cols p s = s := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL]; exact ih _ + | succ p ih => simp only [runL]; exact ih _ theorem eq_runR (j : ℕ) (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) : ∀ p : ℕ, (eq j a b).runR cols p = true ↔ ∀ q, 1 ≤ q → q ≤ p → cols q a = cols q b := by @@ -745,7 +745,7 @@ theorem eq_runR (j : ℕ) (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ | succ p ih => rw [runR] show ((eq j a b).runR cols p && decide (cols (p + 1) a = cols (p + 1) b)) = true ↔ _ - rw [Bool.and_eq_true, decide_eq_true_eq] + erw [Bool.and_eq_true, decide_eq_true_eq] constructor · rintro ⟨hall, hlast⟩ q h1 h2 rcases Nat.lt_or_ge q (p + 1) with hlt | hge @@ -758,7 +758,7 @@ theorem eq_runR (j : ℕ) (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ /-- **What the equality scanner reports.** -/ theorem eq_run (j : ℕ) (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) → Γ) (len : ℕ) : (eq j a b).run cols len = true ↔ ∀ q, 1 ≤ q → q ≤ len → cols q a = cols q b := by - rw [run, eq_runL, eq_runR] + rw [run]; erw [eq_runL, eq_runR] /-- **A comparison restricted to a range of cells decides equality there.** This is how a small guessed register is pinned against a field sitting anywhere inside a bigger one. -/ @@ -790,7 +790,7 @@ theorem isConst_runR (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ → Fin (j | succ p ih => rw [runR] show ((isConst j a g).runR cols p && decide (cols (p + 1) a = g)) = true ↔ _ - rw [Bool.and_eq_true, decide_eq_true_eq] + erw [Bool.and_eq_true, decide_eq_true_eq] constructor · rintro ⟨hall, hlast⟩ q h1 h2 rcases Nat.lt_or_ge q (p + 1) with hlt | hge @@ -804,11 +804,11 @@ theorem isConst_runL (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ → Fin (j (s : Bool) : (isConst j a g).runL cols p s = s := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL]; exact ih _ + | succ p ih => simp only [runL]; exact ih _ theorem isConst_run (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ → Fin (j + 1) → Γ) (len : ℕ) : (isConst j a g).run cols len = true ↔ ∀ q, 1 ≤ q → q ≤ len → cols q a = g := by - rw [run, isConst_runL, isConst_runR] + rw [run]; erw [isConst_runL, isConst_runR] theorem rightOnly_isConst (j : ℕ) (a : Fin (j + 1)) (g : Γ) : RightOnly (isConst j a g) := fun _ _ => rfl @@ -844,7 +844,7 @@ theorem isNotConst_runR (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ → Fin | succ p ih => rw [runR] show ((isNotConst j a g).runR cols p || decide (cols (p + 1) a ≠ g)) = true ↔ _ - rw [Bool.or_eq_true, decide_eq_true_eq] + erw [Bool.or_eq_true, decide_eq_true_eq] constructor · rintro (hall | hlast) · obtain ⟨q, h1, h2, h3⟩ := ih.mp hall @@ -859,7 +859,7 @@ theorem isNotConst_runL (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ → Fin (s : Bool) : (isNotConst j a g).runL cols p s = s := by induction p generalizing s with | zero => rfl - | succ p ih => rw [runL]; exact ih _ + | succ p ih => simp only [runL]; exact ih _ theorem rightOnly_isNotConst (j : ℕ) (a : Fin (j + 1)) (g : Γ) : RightOnly (isNotConst j a g) := fun _ _ => rfl @@ -871,7 +871,7 @@ theorem isNotConst_cell (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ → Fin cols 1 a ≠ g := by rw [upTo_emit_run _ (rightOnly_isNotConst j a g) 1 len hlen] show (isNotConst j a g).run cols 1 = true ↔ _ - rw [run, isNotConst_runL, isNotConst_runR] + rw [run]; erw [isNotConst_runL, isNotConst_runR] exact ⟨fun ⟨q, h1, h2, h3⟩ => by rwa [show q = 1 by omega] at h3, fun h => ⟨1, le_rfl, le_rfl, h⟩⟩ @@ -899,7 +899,7 @@ theorem isNotConst_range_run (j : ℕ) (a : Fin (j + 1)) (g : Γ) (cols : ℕ ∃ q, w₁ < q ∧ q ≤ w₂ ∧ cols q a ≠ g := by rw [range_emit_run _ (rightOnly_isNotConst j a g) w₁ w₂ len hw] show (isNotConst j a g).run (fun q => cols (w₁ + q)) (w₂ - w₁) = true ↔ _ - rw [run, isNotConst_runL, isNotConst_runR] + rw [run]; erw [isNotConst_runL, isNotConst_runR] constructor · rintro ⟨q, h1, h2, h3⟩ exact ⟨w₁ + q, by omega, by omega, h3⟩ @@ -928,7 +928,7 @@ theorem andAll_runR (j : ℕ) (cols : ℕ → Fin (j + 1) → Γ) : | succ p ih => rw [runR] show ((andAll j).runR cols p && decide (∀ i, cols (p + 1) i = Γ.one)) = true ↔ _ - rw [Bool.and_eq_true, decide_eq_true_eq] + erw [Bool.and_eq_true, decide_eq_true_eq] constructor · rintro ⟨hall, hlast⟩ q h1 h2 rcases Nat.lt_or_ge q (p + 1) with h | h @@ -944,7 +944,7 @@ theorem andAll_run (j : ℕ) (cols : ℕ → Fin (j + 1) → Γ) (p : ℕ) : (andAll j).run cols p = true ↔ ∀ q, 1 ≤ q → q ≤ p → ∀ i, cols q i = Γ.one := by have hrunL : ∀ s : Bool, (andAll j).runL cols p s = s := fun s => ofRight_runL Bool _ _ _ cols p s - rw [run, hrunL, andAll_runR] + rw [run]; erw [hrunL, andAll_runR] /-- Report whether the *designated* tapes all carry `Γ.one`. The verdict registers of a composite check are scattered — each check owns a contiguous block, so their result tapes are @@ -967,7 +967,7 @@ theorem andSome_runR (j : ℕ) (P : Fin (j + 1) → Bool) (cols : ℕ → Fin (j rw [runR] show ((andSome j P).runR cols p && decide (∀ i, P i = true → cols (p + 1) i = Γ.one)) = true ↔ _ - rw [Bool.and_eq_true, decide_eq_true_eq] + erw [Bool.and_eq_true, decide_eq_true_eq] constructor · rintro ⟨hall, hlast⟩ q h1 h2 rcases Nat.lt_or_ge q (p + 1) with h | h @@ -984,7 +984,7 @@ theorem andSome_run (j : ℕ) (P : Fin (j + 1) → Bool) (cols : ℕ → Fin (j ∀ q, 1 ≤ q → q ≤ p → ∀ i, P i = true → cols q i = Γ.one := by have hrunL : ∀ s : Bool, (andSome j P).runL cols p s = s := fun s => ofRight_runL Bool _ _ _ cols p s - rw [run, hrunL, andSome_runR] + rw [run]; erw [hrunL, andSome_runR] /-- Report whether the designated tapes carry `Γ.one` in their **first** cell. A verdict register holds a single bit and blanks after it, so a scan whose length is set by some longer register must @@ -1008,7 +1008,7 @@ theorem andFirst_runR (j : ℕ) (P : Fin (j + 1) → Bool) (cols : ℕ → Fin ( rcases Nat.eq_zero_or_pos p with hp | hp · subst hp simp - · rw [if_pos (by simpa using hp)] + · rw [ite_eq_left (by simpa using hp)] simp [Nat.ne_of_gt hp] /-- **What the first-cell conjunction scanner reports.** -/ @@ -1018,9 +1018,9 @@ theorem andFirst_run (j : ℕ) (P : Fin (j + 1) → Bool) (cols : ℕ → Fin (j ∀ i, P i = true → cols 1 i = Γ.one := by have hrunL : ∀ s : Bool × Bool, (andFirst j P).runL cols p s = s := fun s => ofRight_runL (Bool × Bool) _ _ _ cols p s - rw [run, hrunL, andFirst_runR] + rw [run]; erw [hrunL, andFirst_runR] show (if p = 0 then true else decide (∀ i, P i = true → cols 1 i = Γ.one)) = true ↔ _ - rw [if_neg (by omega), decide_eq_true_eq] + rw [ite_eq_right (by omega), decide_eq_true_eq] /-- Report an arbitrary function of the **first** column. Verdict registers hold a single bit each, so a composite decision — "these checks all passed, *or* those did" — is a function of one @@ -1041,7 +1041,7 @@ theorem firstCol_runR (j : ℕ) (f : (Fin (j + 1) → Γ) → Bool) (cols : ℕ rcases Nat.eq_zero_or_pos p with hp | hp · subst hp simp - · rw [if_pos (by simpa using hp)] + · rw [ite_eq_left (by simpa using hp)] simp [Nat.ne_of_gt hp] /-- **What the first-column scanner reports.** -/ @@ -1050,9 +1050,9 @@ theorem firstCol_run (j : ℕ) (f : (Fin (j + 1) → Γ) → Bool) (cols : ℕ (firstCol j f).emit ((firstCol j f).run cols p) = f (cols 1) := by have hrunL : ∀ s : Bool × Bool, (firstCol j f).runL cols p s = s := fun s => ofRight_runL (Bool × Bool) _ _ _ cols p s - rw [run, hrunL, firstCol_runR] + rw [run]; erw [hrunL, firstCol_runR] show (if p = 0 then true else f (cols 1)) = _ - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] /-! ## A scanner that checks an increment @@ -1107,7 +1107,7 @@ theorem plusOne_runR (j : ℕ) (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) simp_all [valUpTo] <;> omega · simp only [valUpTo, Bool.and_eq_true, decide_eq_true_eq] cases c <;> cases v <;> - simp only [Bool.false_eq_true, if_true, if_false, Bool.xor_false, Bool.xor_true, + simp only [Bool.false_eq_true, ite_true, ite_false, Bool.xor_false, Bool.xor_true, true_iff, false_iff] at hinv hcar ⊢ <;> cases hA : bitAt cols a (p + 1) <;> cases hB : bitAt cols b (p + 1) <;> simp_all <;> @@ -1121,14 +1121,14 @@ theorem plusOne_run (j : ℕ) (a b : Fin (j + 1)) (cols : ℕ → Fin (j + 1) have hrunL : ∀ (s : Bool × Bool), (plusOne j a b).runL cols len s = s := fun s => ofRight_runL (Bool × Bool) _ _ _ cols len s have hrun' : (plusOne j a b).run cols len = (c, v) := by - rw [run, hrunL, hrun] + rw [run]; erw [hrunL, hrun] rw [hrun'] have hlB : valUpTo (bitAt cols b) len < 2 ^ len := valUpTo_lt _ len clear hrun hrun' hrunL show (!c && v) = true ↔ _ cases c <;> cases v <;> simp only [Bool.not_true, Bool.not_false, Bool.false_and, Bool.true_and, - Bool.false_eq_true, if_true, if_false, true_iff, false_iff] at hcar hinv ⊢ <;> + Bool.false_eq_true, ite_true, ite_false, true_iff, false_iff] at hcar hinv ⊢ <;> omega end Scanner @@ -1236,12 +1236,12 @@ def twoPassTM (S : Scanner j) : TM (j + 2) := /-! ## What one step does -/ private theorem move_idle {t : Tape} (h : t.read ≠ Γ.start) : t.move (idleDir t.read) = t := by - rw [idleDir, if_neg h] + rw [idleDir, ite_eq_right h] rfl private theorem tape_keep {t : Tape} (h : t.read ≠ Γ.start) : t.writeAndMove (readBackWrite t.read) (idleDir t.read) = t := by - rw [writeAndMove_readBack _ h, idleDir, if_neg h] + rw [writeAndMove_readBack _ h, idleDir, ite_eq_right h] rfl private theorem tape_right {t : Tape} (h : t.read ≠ Γ.start) : @@ -1251,7 +1251,7 @@ private theorem tape_right {t : Tape} (h : t.read ≠ Γ.start) : private theorem tape_left {t : Tape} (h : t.read ≠ Γ.start) : t.writeAndMove (readBackWrite t.read) (moveLeftDir t.read) = ⟨t.head - 1, t.cells⟩ := by - rw [writeAndMove_readBack _ h, moveLeftDir, if_neg h] + rw [writeAndMove_readBack _ h, moveLeftDir, ite_eq_right h] rfl /-- The column of symbols under the scanned heads when they are all at cell `h`. -/ @@ -1295,26 +1295,26 @@ theorem twoPassCfg_step_right (S : Scanner j) (s : S.σ) (inp : Tape) = twoPassCfg S (TwoPassPhase.right, S.stepR s (scanCol cells h)) inp cells (h + 1) res out := by refine Cfg.ext ?_ ?_ ?_ ?_ - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, ite_false] rfl - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, ite_false] exact move_idle hok.inp · funext i refine Fin.lastCases ?_ ?_ i - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, ite_false] simp only [Fin.snoc_last] exact tape_keep hok.res · intro i' - simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, if_false] + simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, ite_false] simp only [Fin.snoc_castSucc] exact tape_right (show (⟨h, cells i'⟩ : Tape).read ≠ Γ.start from hc i') - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hne, ite_false] exact tape_keep hok.out private theorem tape_start_right {t : Tape} (hh : t.head = 0) (g : Γ) : t.writeAndMove g Dir3.right = ⟨1, t.cells⟩ := by show (t.write g).move Dir3.right = _ - rw [Tape.write, if_pos hh] + rw [Tape.write, ite_eq_left hh] show (⟨t.head + 1, t.cells⟩ : Tape) = _ rw [hh] @@ -1325,19 +1325,19 @@ theorem twoPassCfg_step_turn (S : Scanner j) (s : S.σ) (inp : Tape) (twoPassTM S).stepCfg (twoPassCfg S (TwoPassPhase.right, s) inp cells h res out) = twoPassCfg S (TwoPassPhase.left, s) inp cells (h - 1) res out := by refine Cfg.ext ?_ ?_ ?_ ?_ - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, if_true] - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, if_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, ite_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, ite_true] exact move_idle hok.inp · funext i refine Fin.lastCases ?_ ?_ i - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, if_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, ite_true] simp only [Fin.snoc_last] exact tape_keep hok.res · intro i' - simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, if_true] + simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, ite_true] simp only [Fin.snoc_castSucc] exact tape_left (show (⟨h, cells i'⟩ : Tape).read ≠ Γ.start from hc i') - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, if_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hb, ite_true] exact tape_keep hok.out /-- The leftward pass, while the left marker is not yet in sight. -/ @@ -1349,20 +1349,20 @@ theorem twoPassCfg_step_left (S : Scanner j) (s : S.σ) (inp : Tape) res out := by have hns : ¬ (cells 0 h = Γ.start) := hc 0 refine Cfg.ext ?_ ?_ ?_ ?_ - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, ite_false] rfl - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, ite_false] exact move_idle hok.inp · funext i refine Fin.lastCases ?_ ?_ i - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, ite_false] simp only [Fin.snoc_last] exact tape_keep hok.res · intro i' - simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, if_false] + simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, ite_false] simp only [Fin.snoc_castSucc] exact tape_left (show (⟨h, cells i'⟩ : Tape).read ≠ Γ.start from hc i') - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, if_false] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hns, ite_false] exact tape_keep hok.out /-- The leftward pass reaches the marker and the scan turns to publishing. -/ @@ -1373,19 +1373,19 @@ theorem twoPassCfg_step_stop (S : Scanner j) (s : S.σ) (inp : Tape) = twoPassCfg S (TwoPassPhase.emit, s) inp cells 1 res out := by have hst : cells 0 0 = Γ.start := hs 0 refine Cfg.ext ?_ ?_ ?_ ?_ - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, if_true] - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, if_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, ite_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, ite_true] exact move_idle hok.inp · funext i refine Fin.lastCases ?_ ?_ i - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, if_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, ite_true] simp only [Fin.snoc_last] exact tape_keep hok.res · intro i' - simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, if_true] + simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, ite_true] simp only [Fin.snoc_castSucc] exact tape_start_right (show (⟨0, cells i'⟩ : Tape).head = 0 from rfl) _ - · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, if_true] + · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read, hst, ite_true] exact tape_keep hok.out /-- Publishing the verdict: one bit onto the result tape, then halt. -/ @@ -1404,7 +1404,7 @@ theorem twoPassCfg_step_emit (S : Scanner j) (s : S.σ) (inp : Tape) · simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read_last] simp only [Fin.snoc_last] show res.writeAndMove _ (idleDir res.read) = _ - rw [idleDir, if_neg hok.res] + rw [idleDir, ite_eq_right hok.res] cases hb : S.emit s <;> rfl · intro i' simp only [TM.stepCfg, twoPassCfg, twoPassTM, work_read] @@ -1568,7 +1568,7 @@ theorem checkTM_hoareTime {jd jj : ℕ} (S : Scanner jd) (f : Fin (jd + 1) → F (res₀.write (Γ.ofBool (S.emit (S.run (fun q i => cells (f i) q) len))))) (2 * len + 3) := by have h := twoPassTM_hoareTime (S.comap f) cells len inp₀ out₀ res₀ hok ht - simpa only [Scanner.comap_run, Scanner.comap_emit, scanCol] using h + simpa only [checkTM, Scanner.comap_run, Scanner.comap_emit, scanCol] using h end TM diff --git a/Complexitylib/Models/TuringMachine/Subroutines/WipeLoop.lean b/Complexitylib/Models/TuringMachine/Subroutines/WipeLoop.lean index 35b176fe..678af834 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/WipeLoop.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/WipeLoop.lean @@ -56,31 +56,31 @@ blanks exactly cells `1 … H` and leaves every other cell alone. -/ theorem wipedTape_cells_of_head_one {t : Tape} (hh : t.head = 1) (H j : ℕ) : (wipedTape t H).cells j = if 1 ≤ j ∧ j ≤ H then Γ.blank else t.cells j := by induction H with - | zero => rw [wipedTape_zero, if_neg (by omega : ¬(1 ≤ j ∧ j ≤ 0))] + | zero => rw [wipedTape_zero, ite_eq_right (by omega : ¬(1 ≤ j ∧ j ≤ 0))] | succ H ih => have hheadH : (wipedTape t H).head = H + 1 := by rw [wipedTape_head, hh]; omega rw [wipedTape_succ] show (((wipedTape t H).write Γw.blank.toΓ).move Dir3.right).cells j = _ - rw [Tape.move_cells, Tape.write, if_neg (by rw [hheadH]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hheadH]; omega)] show Function.update (wipedTape t H).cells (wipedTape t H).head Γw.blank.toΓ j = _ rw [hheadH] by_cases hj : j = H + 1 - · rw [hj, Function.update_self, if_pos ⟨by omega, by omega⟩] + · rw [hj, Function.update_self, ite_eq_left ⟨by omega, by omega⟩] rfl · rw [Function.update_of_ne hj, ih] by_cases hc : 1 ≤ j ∧ j ≤ H - · rw [if_pos hc, if_pos ⟨hc.1, by omega⟩] + · rw [ite_eq_left hc, ite_eq_left ⟨hc.1, by omega⟩] · have hc' : ¬(1 ≤ j ∧ j ≤ H + 1) := by rintro ⟨h1, h2⟩ exact hc ⟨h1, by omega⟩ - rw [if_neg hc, if_neg hc'] + rw [ite_eq_right hc, ite_eq_right hc'] /-- The canonical blank tape's cells, spelled out. -/ theorem initNil_cells (j : ℕ) : (Tape.init ([] : List Γ)).cells j = if j = 0 then Γ.start else Γ.blank := by cases j with | zero => exact Tape.init_cells_zero [] - | succ i => rw [Tape.init_cells_ge [] i (by simp), if_neg (Nat.succ_ne_zero i)] + | succ i => rw [Tape.init_cells_ge [] i (by simp), ite_eq_right (Nat.succ_ne_zero i)] /-- **Wiping really blanks the tape.** A tape parked at cell `1` whose content is confined to cells `1 … H` becomes literally the blank tape (head at `H + 1`) @@ -92,11 +92,11 @@ theorem wipedTape_eq_blank {t : Tape} (H : ℕ) (hh : t.head = 1) refine Tape.ext (by rw [wipedTape_head, hh]; show 1 + H = H + 1; omega) (funext fun j => ?_) rw [wipedTape_cells_of_head_one hh, initNil_cells] by_cases hj0 : j = 0 - · rw [hj0, if_neg (by omega : ¬(1 ≤ 0 ∧ 0 ≤ H)), if_pos rfl, h0] - · rw [if_neg hj0] + · rw [hj0, ite_eq_right (by omega : ¬(1 ≤ 0 ∧ 0 ≤ H)), ite_eq_left rfl, h0] + · rw [ite_eq_right hj0] by_cases hc : 1 ≤ j ∧ j ≤ H - · rw [if_pos hc] - · rw [if_neg hc, hfar j (by omega)] + · rw [ite_eq_left hc] + · rw [ite_eq_right hc, hfar j (by omega)] /-- Wiping preserves `Parked`-ness: the head only advances, and every written or untouched cell beyond the marker stays off `▷`. -/ @@ -114,7 +114,7 @@ theorem wipedTape_parked {t : Tape} (h : Parked t) (i : ℕ) : Parked (wipedTape show 1 ≤ ((wipedTape t i).write Γw.blank.toΓ).head + 1 omega · rw [hheq, Tape.move_cells] - simp only [Tape.write, if_neg hhead_ne] + simp only [Tape.write, ite_eq_right hhead_ne] show Function.update (wipedTape t i).cells (wipedTape t i).head Γw.blank.toΓ j ≠ Γ.start by_cases hje : j = (wipedTape t i).head · rw [hje, Function.update_self]; decide @@ -146,7 +146,7 @@ theorem eq_parkedBlank_of_outAcc_nil {t : Tape} (h : OutAcc [] t) : funext j rcases Nat.eq_zero_or_pos j with hj0 | hj1 · subst hj0; rw [hcell0, Tape.init_cells_zero] - · rw [htail j (by simpa using hj1), show j = (j - 1) + 1 from by omega, + · rw [htail j hj1, show j = (j - 1) + 1 from by omega, Tape.init_cells_ge [] (j - 1) (by simp)] /-- The register-shaped tape at iteration `i` is `Parked`. -/ @@ -183,7 +183,7 @@ theorem wipeLoop_hoareTime {n : ℕ} (targets : List (Fin n)) (r : Fin n) by_cases hjr : j = r · subst hjr; simp [hw, Function.update_self] · rw [Function.update_of_ne hjr] - simp only [hw, if_neg hjr] + simp only [hw, ite_eq_right hjr] split · rfl · rfl @@ -192,13 +192,13 @@ theorem wipeLoop_hoareTime {n : ℕ} (targets : List (Fin n)) (r : Fin n) funext j by_cases hjr : j = r · subst hjr; simp [hw, Function.update_self] - · rw [Function.update_of_ne hjr]; simp [hw, if_neg hjr] + · rw [Function.update_of_ne hjr]; simp [hw, ite_eq_right hjr] have hwork_parked : ∀ i j, j ≠ r → Parked (w i j) := by intro i j hjr by_cases hjt : j ∈ targets - · simp only [hw, if_neg hjr, if_pos hjt] + · simp only [hw, ite_eq_right hjr, ite_eq_left hjt] exact wipedTape_parked (hother j hjr) i - · simp only [hw, if_neg hjr, if_neg hjt] + · simp only [hw, ite_eq_right hjr, ite_eq_right hjt] exact hother j hjr have hbody : ∀ i, i < v → (wipeStepTM targets).HoareTime (fun inp work out => inp = inp₀ ∧ @@ -223,20 +223,20 @@ theorem wipeLoop_hoareTime {n : ℕ} (targets : List (Fin n)) (r : Fin n) rw [hwork j] by_cases hjr : j = r · subst hjr - rw [if_neg hr, hW, Function.update_self, Function.update_self] + rw [ite_eq_right hr, hW, Function.update_self, Function.update_self] · by_cases hjt : j ∈ targets - · rw [if_pos hjt] + · rw [ite_eq_left hjt] have hWj : W j = wipedTape (work₀ j) i := by - rw [hW, Function.update_of_ne hjr, hw]; simp [if_neg hjr, if_pos hjt] + rw [hW, Function.update_of_ne hjr, hw]; simp [ite_eq_right hjr, ite_eq_left hjt] have hRj : Function.update (w (i + 1)) r (⟨i + 2, regCells v⟩ : Tape) j = wipedTape (work₀ j) (i + 1) := by - rw [Function.update_of_ne hjr, hw]; simp [if_neg hjr, if_pos hjt] + rw [Function.update_of_ne hjr, hw]; simp [ite_eq_right hjr, ite_eq_left hjt] rw [hWj, hRj, wipedTape_succ] - · rw [if_neg hjt] + · rw [ite_eq_right hjt] have hWj : W j = work₀ j := by - rw [hW, Function.update_of_ne hjr, hw]; simp [if_neg hjr, if_neg hjt] + rw [hW, Function.update_of_ne hjr, hw]; simp [ite_eq_right hjr, ite_eq_right hjt] have hRj : Function.update (w (i + 1)) r (⟨i + 2, regCells v⟩ : Tape) j = work₀ j := by - rw [Function.update_of_ne hjr, hw]; simp [if_neg hjr, if_neg hjt] + rw [Function.update_of_ne hjr, hw]; simp [ite_eq_right hjr, ite_eq_right hjt] rw [hWj, hRj] have key := forRegTM_hoareTime (wipeStepTM targets) r v inp₀ w (fun _ => []) 1 hinp₀ (fun i => by simp [hw]) hwork_parked hbody diff --git a/Complexitylib/Models/TuringMachine/Subroutines/WipeRewind.lean b/Complexitylib/Models/TuringMachine/Subroutines/WipeRewind.lean index 1eef5114..9102eda7 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/WipeRewind.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/WipeRewind.lean @@ -104,10 +104,10 @@ theorem wipeRewindTM_hoareTime (targets : List (Fin n)) (hnodup : targets.Nodup) refine ⟨rfl, funext fun j => ?_, rfl⟩ simp only [hW1def] by_cases hj : j ∈ targets - · rw [if_pos hj, hin j hj] + · rw [ite_eq_left hj, hin j hj] exact wipedTape_eq_blank H rfl (hworkSI j (fun hjr => hr (hjr ▸ hj))).1 (fun i hi => htargetFar j hj i hi) - · rw [if_neg hj] + · rw [ite_eq_right hj] by_cases hjr : j = r · rw [hjr, hreg, hworkR] · exact hout j hjr hj @@ -129,16 +129,16 @@ theorem wipeRewindTM_hoareTime (targets : List (Fin n)) (hnodup : targets.Nodup) have : targets.length * (H + 1 + 3) = targets.length * (H + 4) := by ring omega) · intro j hj - simp only [hW1def, if_pos hj] + simp only [hW1def, ite_eq_left hj] exact ⟨Tape.init_cells_zero [], le_refl _⟩ · rintro inp work out ⟨rfl, hout, hin, hkeep⟩ refine ⟨rfl, funext fun j => ?_, hout⟩ by_cases hj : j ∈ targets · rw [hin j hj] - simp only [hW1def, if_pos hj] + simp only [hW1def, ite_eq_left hj] exact Tape.ext rfl (by rw [blankTape, Tape.move_cells]) · rw [hkeep j hj] - simp only [hW1def, if_neg hj] + simp only [hW1def, ite_eq_right hj] exact seqTM_hoareTime _ _ hwipe htrans hrew end TM diff --git a/Complexitylib/Models/TuringMachine/Subroutines/WipeStep.lean b/Complexitylib/Models/TuringMachine/Subroutines/WipeStep.lean index 13424708..bc318605 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/WipeStep.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/WipeStep.lean @@ -95,7 +95,7 @@ theorem wipeStepTM_hoareTime {n : ℕ} (targets : List (Fin n)) 1, le_refl 1, ?_, rfl, hinp.move_idle, hout.writeAndMove_readBack_idle, fun i => ?_⟩ · refine TM.reachesIn.step ?_ .zero simp only [TM.step, wipeStepTM, - if_neg (show WipeStepPhase.running ≠ WipeStepPhase.done by decide)] + ite_eq_right (show WipeStepPhase.running ≠ WipeStepPhase.done by decide)] congr 1 congr 1 funext i diff --git a/Complexitylib/Models/TuringMachine/Subroutines/WriteOutputBit.lean b/Complexitylib/Models/TuringMachine/Subroutines/WriteOutputBit.lean index 93357b79..b10ed604 100644 --- a/Complexitylib/Models/TuringMachine/Subroutines/WriteOutputBit.lean +++ b/Complexitylib/Models/TuringMachine/Subroutines/WriteOutputBit.lean @@ -66,7 +66,7 @@ theorem writeOutputBitTM_hoareTime_frame (vIdx : Fin n) exact (hwork i).writeAndMove_readBack_idle · show (out.write (readBackWrite ((work vIdx).read)).toΓ).move (idleDir out.read) = _ have hne : out.read ≠ Γ.start := hout.2 out.head hout.1 - rw [idleDir, if_neg hne] + rw [idleDir, ite_eq_right hne] rfl @@ -94,7 +94,7 @@ theorem writeOutputBitTM_clears (vIdx : Fin n) rfl · funext j rw [Tape.move_cells] - simp only [Tape.write, if_neg hne0] + simp only [Tape.write, ite_eq_right hne0] rw [show Function.update out₀.cells out₀.head (readBackWrite Γ.blank).toΓ = Function.update out₀.cells 1 (readBackWrite Γ.blank).toΓ from by rw [hhead]] by_cases hj : j = 1 diff --git a/Complexitylib/Models/TuringMachine/Tape/Encoding.lean b/Complexitylib/Models/TuringMachine/Tape/Encoding.lean index 86668ae1..40575e6b 100644 --- a/Complexitylib/Models/TuringMachine/Tape/Encoding.lean +++ b/Complexitylib/Models/TuringMachine/Tape/Encoding.lean @@ -102,7 +102,7 @@ theorem HasBinaryContent.write_set {t : Tape} {bits : List Bool} have hhead0 : ¬t.head = 0 := by omega constructor · intro j hj - rw [Tape.write, if_neg hhead0] + rw [Tape.write, ite_eq_right hhead0] simp only rw [List.length_set] at hj rw [hhead] @@ -115,7 +115,7 @@ theorem HasBinaryContent.write_set {t : Tape} {bits : List Bool} List.getElem_set] simp [hij] · intro j hj - rw [Tape.write, if_neg hhead0] + rw [Tape.write, ite_eq_right hhead0] simp only rw [List.length_set] at hj rw [hhead] diff --git a/Complexitylib/Models/TuringMachine/Trace/DetPrefix.lean b/Complexitylib/Models/TuringMachine/Trace/DetPrefix.lean index 48e66688..a566d830 100644 --- a/Complexitylib/Models/TuringMachine/Trace/DetPrefix.lean +++ b/Complexitylib/Models/TuringMachine/Trace/DetPrefix.lean @@ -169,6 +169,7 @@ theorem det_step_congr {N : NTM n} {c : Cfg n N.Q} · simp only [TM.step, det] rw [show N.δ true c.state c.input.read (fun i => (c.work i).read) c.output.read = _ from h] + rfl /-- One non-halted trace step applies the `det`-projection selected by the current choice bit. -/ diff --git a/Complexitylib/Models/TuringMachine/Trace/Internal.lean b/Complexitylib/Models/TuringMachine/Trace/Internal.lean index 8fed659a..56bd76e7 100644 --- a/Complexitylib/Models/TuringMachine/Trace/Internal.lean +++ b/Complexitylib/Models/TuringMachine/Trace/Internal.lean @@ -27,7 +27,7 @@ theorem trace_snoc_internal (tm : NTM n) (T : ℕ) tm.trace (T + 1) choices c = tm.trace 1 (fun _ => choices (Fin.last T)) (tm.trace T (fun i => choices i.castSucc) c) := by - simpa [Fin.castLE, Fin.natAdd] using tm.trace_add T 1 choices c + exact tm.trace_add T 1 choices c theorem trace_invariant_internal (tm : NTM n) (T : ℕ) (choices : Fin T → Bool) (c : Cfg n tm.Q) diff --git a/Complexitylib/Models/TuringMachine/UTM/Clock.lean b/Complexitylib/Models/TuringMachine/UTM/Clock.lean index 0ae618cd..d66cb956 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Clock.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Clock.lean @@ -122,13 +122,13 @@ def liftCfgWith (tm : TM n) (m : ℕ) (extras : Fin m → Tape) (c : Cfg n tm.Q) /-- `liftCfgWith` maps the first `n` work tapes to `c`'s work tapes. -/ theorem liftCfgWith_work_lt (tm : TM n) (m : ℕ) (extras : Fin m → Tape) (c : Cfg n tm.Q) (i : Fin (n + m)) (h : i.val < n) : - (liftCfgWith tm m extras c).work i = c.work ⟨i.val, h⟩ := dif_pos h + (liftCfgWith tm m extras c).work i = c.work ⟨i.val, h⟩ := dite_eq_left h /-- `liftCfgWith` maps the extra work tapes to the pinned tapes. -/ theorem liftCfgWith_work_ge (tm : TM n) (m : ℕ) (extras : Fin m → Tape) (c : Cfg n tm.Q) (i : Fin (n + m)) (h : n ≤ i.val) : (liftCfgWith tm m extras c).work i = extras (extraIdx i h) := - dif_neg (Nat.not_lt.mpr h) + dite_eq_right (Nat.not_lt.mpr h) /-- **Unified step commutation** for `liftTM` with arbitrary parked extras. Mirror of `Lift.lean`'s (private) blank-extras step lemma: the extras' @@ -144,8 +144,8 @@ private theorem liftTM_step_of_parked (tm : TM n) (m : ℕ) {extras : Fin m → by_cases hh : c.state = tm.qhalt · -- both machines are halted have h1 : (tm.liftTM m).step C = none := by - simp only [step, hs, hh, show (tm.liftTM m).qhalt = tm.qhalt from rfl, - ↓reduceIte] + simp only [step] + exact ite_eq_left (show C.state = (tm.liftTM m).qhalt from by rw [hs, hh]; rfl) have h2 : tm.step c = none := by simp only [step, hh, ↓reduceIte] rw [h1, h2]; rfl @@ -160,13 +160,14 @@ private theorem liftTM_step_of_parked (tm : TM n) (m : ℕ) {extras : Fin m → funext fun i => by rw [hw (Fin.castAdd m i) i.isLt]; rfl simp only [step, Option.map_some] dsimp only [liftTM, liftCfgWith] - rw [hs, hi, ho, hinner, if_neg hh] + rw [hs, hi, ho, hinner] + erw [ite_eq_right hh] refine congrArg some (Cfg.mk.injEq _ _ _ _ _ _ _ _ |>.mpr ⟨rfl, rfl, ?_, rfl⟩) funext i by_cases hik : i.val < n - · rw [hw i hik, dif_pos hik, dif_pos hik, dif_pos hik] + · rw [hw i hik, dite_eq_left hik, dite_eq_left hik, dite_eq_left hik] · have hge := Nat.le_of_not_lt hik - rw [dif_neg hik, dif_neg hik, dif_neg hik, hd i hge] + rw [dite_eq_right hik, dite_eq_right hik, dite_eq_right hik, hd i hge] exact transitionTape_eq_self (hex _) /-- **Step commutation** on embedded configurations with arbitrary parked @@ -176,7 +177,7 @@ private theorem liftTM_step_liftCfgWith (tm : TM n) (m : ℕ) {extras : Fin m (tm.liftTM m).step (liftCfgWith tm m extras c) = (tm.step c).map (liftCfgWith tm m extras) := liftTM_step_of_parked tm m hex rfl rfl rfl - (fun _ h => dif_pos h) (fun _ h => dif_neg (Nat.not_lt.mpr h)) + (fun _ h => dite_eq_left h) (fun _ h => dite_eq_right (Nat.not_lt.mpr h)) -- ════════════════════════════════════════════════════════════════════════ -- HoareTime lifting @@ -264,9 +265,9 @@ private theorem holdsExact_replicate_of_cells {t : Tape} {v : ℕ} refine ⟨by rw [h]; rfl, fun i => ?_⟩ rw [h] by_cases hi : i < v - · rw [dif_pos (by rwa [List.length_replicate]), List.getElem_replicate] + · rw [dite_eq_left (by rwa [List.length_replicate]), List.getElem_replicate] exact regCells_one (by omega) (by omega) - · rw [dif_neg (by rw [List.length_replicate]; omega)] + · rw [dite_eq_right (by rw [List.length_replicate]; omega)] exact regCells_blank (by omega) /-- A tape holding exactly `v` unary marks has cells `regCells v`. -/ @@ -358,12 +359,12 @@ def decClockTM : TM 7 where dsimp only [] by_cases hir : i = clkT · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .erase => dsimp only [] split @@ -372,26 +373,26 @@ def decClockTM : TM 7 where dsimp only [] by_cases hir : i = clkT · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -416,16 +417,16 @@ private theorem decClock_step_scan_one (c : Cfg 7 decClockTM.Q) { state := .scan, input := c.input, work := Function.update c.work clkT ((c.work clkT).move .right), output := c.output } := by - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = clkT · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -439,16 +440,16 @@ private theorem decClock_step_scan_blank (c : Cfg 7 decClockTM.Q) { state := .erase, input := c.input, work := Function.update c.work clkT ((c.work clkT).move .left), output := c.output } := by - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = clkT · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hblank]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -463,7 +464,7 @@ private theorem decClock_step_erase_one (c : Cfg 7 decClockTM.Q) work := Function.update c.work clkT (((c.work clkT).write Γw.blank).move .left), output := c.output } := by - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -471,7 +472,7 @@ private theorem decClock_step_erase_one (c : Cfg 7 decClockTM.Q) by_cases hir : i = clkT · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -489,18 +490,18 @@ private theorem decClock_step_erase_start (c : Cfg 7 decClockTM.Q) have h0 : (c.work clkT).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst, hs, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = clkT · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work clkT).write _).move Dir3.right = (c.work clkT).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -514,15 +515,15 @@ private theorem decClock_step_back_left (c : Cfg 7 decClockTM.Q) { state := .back, input := c.input, work := Function.update c.work clkT ((c.work clkT).move .left), output := c.output } := by - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = clkT · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -540,18 +541,18 @@ private theorem decClock_step_back_start (c : Cfg 7 decClockTM.Q) have h0 : (c.work clkT).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = clkT · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work clkT).write _).move Dir3.right = (c.work clkT).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -564,7 +565,7 @@ private theorem decClock_step_park (c : Cfg 7 decClockTM.Q) decClockTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (decClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decClock_ne_halt (by decide) hst)] simp only [decClockTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -837,7 +838,7 @@ theorem decClockTM_hoareTime (v : ℕ) (inp₀ : Tape) (work₀ : Fin 7 → Tape rw [Function.update_self] show (((c₂.work clkT).write Γw.blank).move .left).cells = _ show ((c₂.work clkT).write Γw.blank).cells = _ - rw [Tape.write, if_neg (by rw [hc₂head]; omega)] + rw [Tape.write, ite_eq_right (by rw [hc₂head]; omega)] show Function.update (c₂.work clkT).cells (c₂.work clkT).head Γw.blank.toΓ = _ rw [hc₂cells, hc₂head] exact regCells_update_blank_succ e @@ -927,16 +928,16 @@ private theorem zeroTest_step (c : Cfg 7 zeroTestTM.Q) cells := Function.update c.output.cells c.output.head ((if (c.work clkT).read = Γ.blank then Γw.one else Γw.zero) : Γw).toΓ } } := by - rw [TM.step, if_neg (zeroTest_ne_halt hst)] + rw [TM.step, ite_eq_right (zeroTest_ne_halt hst)] simp only [zeroTestTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hall i) · show c.output.writeAndMove _ (idleDir c.output.read) = _ - rw [idleDir, if_neg hor] + rw [idleDir, ite_eq_right hor] show c.output.write _ = _ - rw [Tape.write, if_neg hh0] + rw [Tape.write, ite_eq_right hh0] /-- **`zeroTestTM` specification** (ghost-initial-tapes style). Starting from `qstart` with the clock tape (`clkT` = work tape 6) holding `v` @@ -967,9 +968,9 @@ theorem zeroTestTM_hoareTime (v : ℕ) (inp₀ : Tape) (work₀ : Fin 7 → Tape have hclkread : (work clkT).read = (if v = 0 then Γ.blank else Γ.one) := by rw [Tape.read, hclkh] rcases Nat.eq_zero_or_pos v with rfl | hv - · rw [if_pos rfl] + · rw [ite_eq_left rfl] exact Tape.HoldsExact.cells_ge hclk (by simp) - · rw [if_neg (by omega)] + · rw [ite_eq_right (by omega)] have h1 := Tape.HoldsExact.cells_lt hclk (i := 0) (by rwa [List.length_replicate]) rw [List.getElem_replicate] at h1 diff --git a/Complexitylib/Models/TuringMachine/UTM/ClockConstructible.lean b/Complexitylib/Models/TuringMachine/UTM/ClockConstructible.lean index dc8b8f0d..fb70592a 100644 --- a/Complexitylib/Models/TuringMachine/UTM/ClockConstructible.lean +++ b/Complexitylib/Models/TuringMachine/UTM/ClockConstructible.lean @@ -59,7 +59,7 @@ theorem Tape.init_move_right_eq_regT_zero : · show (Tape.init []).cells j = regCells 0 j rw [regCells_blank (by omega)] simp only [Tape.init] - rw [if_neg (by omega : ¬ j = 0)] + rw [ite_eq_right (by omega : ¬ j = 0)] simp /-- The output-tape frame carried through all clock-construction phases: @@ -191,27 +191,27 @@ def clockLenTM : TM 8 where · refine ⟨fun hi => absurd hi hns, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨fun _ => rfl, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨fun _ => rfl, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => - refine ⟨fun hi => by rw [if_pos hi], fun i hi => ?_, idleDir_right_of_start⟩ + refine ⟨fun hi => by rw [ite_eq_left hi], fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -236,14 +236,14 @@ private theorem clockLen_step_scan_bit (c : Cfg 8 clockLenTM.Q) { state := .scan, input := c.input.move .right, work := Function.update c.work 6 (((c.work 6).write Γw.one).move .right), output := c.output } := by - rw [TM.step, if_neg (clockLen_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockLen_ne_halt (by decide) hst)] simp only [clockLenTM, hst, hns, hbl, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = (6 : Fin 8) · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -258,15 +258,15 @@ private theorem clockLen_step_scan_blank (c : Cfg 8 clockLenTM.Q) { state := .back, input := c.input.move .left, work := Function.update c.work 6 (((c.work 6).write Γw.one).move .left), output := c.output } := by - rw [TM.step, if_neg (clockLen_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockLen_ne_halt (by decide) hst)] simp only [clockLenTM, hst, hbl, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = (6 : Fin 8) · subst hir simp only [↓reduceIte, Function.update_self] - rw [if_neg hclk] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + rw [ite_eq_right hclk] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -280,15 +280,15 @@ private theorem clockLen_step_back_left (c : Cfg 8 clockLenTM.Q) { state := .back, input := c.input.move .left, work := Function.update c.work 6 ((c.work 6).move .left), output := c.output } := by - rw [TM.step, if_neg (clockLen_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockLen_ne_halt (by decide) hst)] simp only [clockLenTM, hst, hclk, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) - · rw [if_neg hins] + · rw [ite_eq_right hins] · funext i by_cases hir : i = (6 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ hclk] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ hclk] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -305,17 +305,17 @@ private theorem clockLen_step_back_start (c : Cfg 8 clockLenTM.Q) have h0 : (c.work 6).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (clockLen_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockLen_ne_halt (by decide) hst)] simp only [clockLenTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = (6 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work 6).write _).move Dir3.right = (c.work 6).move .right congr 1 - rw [Tape.write, if_pos h0] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h0] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -326,7 +326,7 @@ private theorem clockLen_step_park (c : Cfg 8 clockLenTM.Q) (hout : c.output.read ≠ Γ.start) : clockLenTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (clockLen_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockLen_ne_halt (by decide) hst)] simp only [clockLenTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -368,7 +368,7 @@ private theorem clockLen_scan_run (x : List Bool) (m : ℕ) : have hstep := clockLen_step_scan_bit c hst hns hbl hoth hout have hq₁cells : (((c.work 6).write Γw.one).move .right).cells = regCells (k + 1) := by - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhd]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhd]; omega)] show Function.update (c.work 6).cells (c.work 6).head Γw.one.toΓ = _ rw [hhd, hcl] exact regCells_update_succ k @@ -560,7 +560,7 @@ private theorem clockLenTM_hoareTime (x : List Bool) (work₀ : Fin 8 → Tape) (((c₂.work 6).write Γw.one).move .left) 6).cells = regCells (x.length + 1) := by rw [Function.update_self, Tape.move_cells, Tape.write, - if_neg (by rw [hhd₂]; omega)] + ite_eq_right (by rw [hhd₂]; omega)] show Function.update (c₂.work 6).cells (c₂.work 6).head Γw.one.toΓ = _ rw [hhd₂, hcl₂] exact regCells_update_succ x.length @@ -680,39 +680,39 @@ def moveClockTM : TM 8 where · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir6 : i = (6 : Fin 8) - · rw [if_pos hir6] - · rw [if_neg hir6] + · rw [ite_eq_left hir6] + · rw [ite_eq_right hir6] by_cases hir5 : i = (5 : Fin 8) - · rw [if_pos hir5] - · rw [if_neg hir5]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir5] + · rw [ite_eq_right hir5]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir6 : i = (6 : Fin 8) - · subst hir6; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir6] + · subst hir6; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir6] by_cases hir5 : i = (5 : Fin 8) - · subst hir5; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir5]; exact idleDir_right_of_start hi + · subst hir5; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir5]; exact idleDir_right_of_start hi | .back => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir6 : i = (6 : Fin 8) - · rw [if_pos hir6] - · rw [if_neg hir6] + · rw [ite_eq_left hir6] + · rw [ite_eq_right hir6] by_cases hir5 : i = (5 : Fin 8) - · rw [if_pos hir5] - · rw [if_neg hir5]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir5] + · rw [ite_eq_right hir5]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir6 : i = (6 : Fin 8) · subst hir6; exact absurd hi hns - · rw [if_neg hir6] + · rw [ite_eq_right hir6] by_cases hir5 : i = (5 : Fin 8) - · subst hir5; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir5]; exact idleDir_right_of_start hi + · subst hir5; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir5]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -739,7 +739,7 @@ private theorem moveClock_step_scan_one (c : Cfg 8 moveClockTM.Q) (Function.update c.work 6 (((c.work 6).write Γw.blank).move .right)) 5 (((c.work 5).write Γw.one).move .right), output := c.output } := by - rw [TM.step, if_neg (moveClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (moveClock_ne_halt (by decide) hst)] simp only [moveClockTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -753,7 +753,7 @@ private theorem moveClock_step_scan_one (c : Cfg 8 moveClockTM.Q) rw [Function.update_self] simp only [Fin.isValue, show ¬ ((5 : Fin 8) = 6) from by decide, ↓reduceIte] - · rw [if_neg hir6, if_neg hir5, if_neg hir6, if_neg hir5, + · rw [ite_eq_right hir6, ite_eq_right hir5, ite_eq_right hir6, ite_eq_right hir5, Function.update_of_ne hir5, Function.update_of_ne hir6] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir5 hir6) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -771,7 +771,7 @@ private theorem moveClock_step_scan_turn (c : Cfg 8 moveClockTM.Q) (Function.update c.work 6 ((c.work 6).move .left)) 5 ((c.work 5).move .left), output := c.output } := by - rw [TM.step, if_neg (moveClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (moveClock_ne_halt (by decide) hst)] simp only [moveClockTM, hst, hbl, h5ns, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -787,7 +787,7 @@ private theorem moveClock_step_scan_turn (c : Cfg 8 moveClockTM.Q) simp only [Fin.isValue, show ¬ ((5 : Fin 8) = 6) from by decide, ↓reduceIte] rw [writeAndMove_readBack _ h5ns] - · rw [if_neg hir6, if_neg hir5, Function.update_of_ne hir5, + · rw [ite_eq_right hir6, ite_eq_right hir5, Function.update_of_ne hir5, Function.update_of_ne hir6] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir5 hir6) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -805,7 +805,7 @@ private theorem moveClock_step_back_left (c : Cfg 8 moveClockTM.Q) (Function.update c.work 6 ((c.work 6).move .left)) 5 ((c.work 5).move .left), output := c.output } := by - rw [TM.step, if_neg (moveClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (moveClock_ne_halt (by decide) hst)] simp only [moveClockTM, hst, h6ns, h5ns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -821,7 +821,7 @@ private theorem moveClock_step_back_left (c : Cfg 8 moveClockTM.Q) simp only [Fin.isValue, show ¬ ((5 : Fin 8) = 6) from by decide, ↓reduceIte] rw [writeAndMove_readBack _ h5ns] - · rw [if_neg hir6, if_neg hir5, Function.update_of_ne hir5, + · rw [ite_eq_right hir6, ite_eq_right hir5, Function.update_of_ne hir5, Function.update_of_ne hir6] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir5 hir6) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -839,7 +839,7 @@ private theorem moveClock_step_back_start (c : Cfg 8 moveClockTM.Q) (Function.update c.work 6 ((c.work 6).move .right)) 5 ((c.work 5).move .right), output := c.output } := by - rw [TM.step, if_neg (moveClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (moveClock_ne_halt (by decide) hst)] simp only [moveClockTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -850,7 +850,7 @@ private theorem moveClock_step_back_start (c : Cfg 8 moveClockTM.Q) simp only [Fin.isValue, ↓reduceIte] show ((c.work 6).write _).move Dir3.right = (c.work 6).move .right congr 1 - rw [Tape.write, if_pos h60] + rw [Tape.write, ite_eq_left h60] · by_cases hir5 : i = (5 : Fin 8) · subst hir5 rw [Function.update_self] @@ -858,8 +858,8 @@ private theorem moveClock_step_back_start (c : Cfg 8 moveClockTM.Q) ↓reduceIte] show ((c.work 5).write _).move Dir3.right = (c.work 5).move .right congr 1 - rw [Tape.write, if_pos h50] - · rw [if_neg hir6, if_neg hir5, Function.update_of_ne hir5, + rw [Tape.write, ite_eq_left h50] + · rw [ite_eq_right hir6, ite_eq_right hir5, Function.update_of_ne hir5, Function.update_of_ne hir6] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir5 hir6) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -871,7 +871,7 @@ private theorem moveClock_step_park (c : Cfg 8 moveClockTM.Q) (hout : c.output.read ≠ Γ.start) : moveClockTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (moveClock_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (moveClock_ne_halt (by decide) hst)] simp only [moveClockTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -903,12 +903,12 @@ private theorem moveClock_scan_run (v m : ℕ) : | succ m ih => intro k hk c hst hinp hoth hout hcl5 hhd5 hcl6 hhd6 have hone : (c.work 6).read = Γ.one := by - rw [Tape.read, hhd6, hcl6, clearRegCells, if_neg (by omega), if_neg (by omega), - if_pos (by omega)] + rw [Tape.read, hhd6, hcl6, clearRegCells, ite_eq_right (by omega), ite_eq_right (by omega), + ite_eq_left (by omega)] have hstep := moveClock_step_scan_one c hst hone hinp hoth hout have h6cl : (((c.work 6).write Γw.blank).move .right).cells = clearRegCells v (k + 1) := by - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhd6]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhd6]; omega)] show Function.update (c.work 6).cells (c.work 6).head Γw.blank.toΓ = _ rw [hhd6, hcl6] exact clearCells_update_succ v k @@ -917,7 +917,7 @@ private theorem moveClock_scan_run (v m : ℕ) : rw [Tape.write_head, hhd6] have h5cl : (((c.work 5).write Γw.one).move .right).cells = regCells (k + 1) := by - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhd5]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhd5]; omega)] show Function.update (c.work 5).cells (c.work 5).head Γw.one.toΓ = _ rw [hhd5, hcl5] exact regCells_update_succ k @@ -1283,13 +1283,13 @@ def clockMulTM : TM 8 where · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (5 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (5 : Fin 8) - · subst hir; rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · subst hir; rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .inScan => dsimp only [] split @@ -1300,13 +1300,13 @@ def clockMulTM : TM 8 where · refine ⟨fun hi => absurd hi hns, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨fun _ => rfl, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .inRew => dsimp only [] split @@ -1321,28 +1321,28 @@ def clockMulTM : TM 8 where · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (5 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (5 : Fin 8) · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .rew6 => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · next hns => refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = (6 : Fin 8) · subst hir; exact absurd hi hns - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .park => exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ @@ -1367,16 +1367,16 @@ private theorem clockMul_step_drive_one (c : Cfg 8 clockMulTM.Q) { state := .inScan, input := c.input, work := Function.update c.work 5 ((c.work 5).move .right), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = (5 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hone]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1390,16 +1390,16 @@ private theorem clockMul_step_drive_blank (c : Cfg 8 clockMulTM.Q) { state := .rewC, input := c.input, work := Function.update c.work 5 ((c.work 5).move .left), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hbl, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = (5 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self, + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ (by rw [hbl]; decide)] - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1413,14 +1413,14 @@ private theorem clockMul_step_inScan_bit (c : Cfg 8 clockMulTM.Q) { state := .inScan, input := c.input.move .right, work := Function.update c.work 6 (((c.work 6).write Γw.one).move .right), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hns, hbl, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = (6 : Fin 8) · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1434,14 +1434,14 @@ private theorem clockMul_step_inScan_blank (c : Cfg 8 clockMulTM.Q) { state := .inRew, input := c.input.move .left, work := Function.update c.work 6 (((c.work 6).write Γw.one).move .right), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hbl, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i by_cases hir : i = (6 : Fin 8) · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1453,7 +1453,7 @@ private theorem clockMul_step_inRew_left (c : Cfg 8 clockMulTM.Q) clockMulTM.step c = some { state := .inRew, input := c.input.move .left, work := c.work, output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -1468,7 +1468,7 @@ private theorem clockMul_step_inRew_start (c : Cfg 8 clockMulTM.Q) clockMulTM.step c = some { state := .drive, input := c.input.move .right, work := c.work, output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hi, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -1486,7 +1486,7 @@ private theorem clockMul_step_rewC_left (c : Cfg 8 clockMulTM.Q) { state := .rewC, input := c.input, work := Function.update c.work 5 (((c.work 5).write Γw.blank).move .left), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, h5ns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -1494,7 +1494,7 @@ private theorem clockMul_step_rewC_left (c : Cfg 8 clockMulTM.Q) by_cases hir : i = (5 : Fin 8) · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1509,18 +1509,18 @@ private theorem clockMul_step_rewC_start (c : Cfg 8 clockMulTM.Q) { state := .rew6, input := c.input, work := Function.update c.work 5 ((c.work 5).move .right), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = (5 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work 5).write _).move Dir3.right = (c.work 5).move .right congr 1 - rw [Tape.write, if_pos h50] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h50] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1534,15 +1534,15 @@ private theorem clockMul_step_rew6_left (c : Cfg 8 clockMulTM.Q) { state := .rew6, input := c.input, work := Function.update c.work 6 ((c.work 6).move .left), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, h6ns, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = (6 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self, writeAndMove_readBack _ h6ns] - · rw [if_neg hir, Function.update_of_ne hir] + rw [ite_eq_left rfl, Function.update_self, writeAndMove_readBack _ h6ns] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1557,18 +1557,18 @@ private theorem clockMul_step_rew6_start (c : Cfg 8 clockMulTM.Q) { state := .park, input := c.input, work := Function.update c.work 6 ((c.work 6).move .right), output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst, hs, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i by_cases hir : i = (6 : Fin 8) · subst hir - rw [if_pos rfl, Function.update_self] + rw [ite_eq_left rfl, Function.update_self] show ((c.work 6).write _).move Dir3.right = (c.work 6).move .right congr 1 - rw [Tape.write, if_pos h60] - · rw [if_neg hir, Function.update_of_ne hir] + rw [Tape.write, ite_eq_left h60] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -1579,7 +1579,7 @@ private theorem clockMul_step_park (c : Cfg 8 clockMulTM.Q) (hout : c.output.read ≠ Γ.start) : clockMulTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (clockMul_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (clockMul_ne_halt (by decide) hst)] simp only [clockMulTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -1621,7 +1621,7 @@ private theorem clockMul_inScan_run (x : List Bool) (m : ℕ) : have hstep := clockMul_step_inScan_bit c hst hns hbl hoth hout have hq₁cells : (((c.work 6).write Γw.one).move .right).cells = regCells (d + 1) := by - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhd]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhd]; omega)] show Function.update (c.work 6).cells (c.work 6).head Γw.one.toΓ = _ rw [hhd, hcl] exact regCells_update_succ d @@ -1743,7 +1743,7 @@ private theorem clockMul_rewC_run (h : ℕ) : hinp hoth hout have hq₁cells : ((((c.work 5).write Γw.blank)).move .left).cells = regCells h := by - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhd]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhd]; omega)] show Function.update (c.work 5).cells (c.work 5).head Γw.blank.toΓ = _ rw [hhd, hcl] exact regCells_update_blank_succ h @@ -1947,7 +1947,7 @@ private theorem clockMul_drive_run (x : List Bool) (v : ℕ) (m : ℕ) : have hstep₃ := clockMul_step_inScan_blank c₂ hst₂ hibl₂ hoth₂ ho₂r have hc₃cl : (((c₂.work 6).write Γw.one).move .right).cells = regCells (r * (x.length + 1) + x.length + 1) := by - rw [Tape.move_cells, Tape.write, if_neg (by rw [hhd₂]; omega)] + rw [Tape.move_cells, Tape.write, ite_eq_right (by rw [hhd₂]; omega)] show Function.update (c₂.work 6).cells (c₂.work 6).head Γw.one.toΓ = _ rw [hhd₂, hcl₂] exact regCells_update_succ (r * (x.length + 1) + x.length) diff --git a/Complexitylib/Models/TuringMachine/UTM/ClockedUtm.lean b/Complexitylib/Models/TuringMachine/UTM/ClockedUtm.lean index 54dd38a2..0b01bdcc 100644 --- a/Complexitylib/Models/TuringMachine/UTM/ClockedUtm.lean +++ b/Complexitylib/Models/TuringMachine/UTM/ClockedUtm.lean @@ -655,9 +655,9 @@ private theorem testPhase (α x : List Bool) (mc : Cfg 1 (decodeDesc α).toTM.Q) then Γ.one else Γ.zero) = (if mc.state = (decodeDesc α).toTM.qhalt then Γ.one else Γ.zero) := by by_cases hq : mc.state = (decodeDesc α).toTM.qhalt - · rw [if_pos hq, if_pos + · rw [ite_eq_left hq, ite_eq_left (show S = (takeField (takeField (groupPairs α)).2).1 from hSiff.mpr hq)] - · rw [if_neg hq, if_neg + · rw [ite_eq_right hq, ite_eq_right (show ¬S = (takeField (takeField (groupPairs α)).2).1 from fun hc => hq (hSiff.mp hc))] have hoc1' : c'.output.cells 1 @@ -766,7 +766,7 @@ private theorem extractPhase (α x : List Bool) (V T m v : ℕ) intro k rw [hvout.1] simp only [show ¬(k + 2 = 0) by omega, show ¬(k + 2 = 1) by omega, - if_false, show k + 2 - 1 = k + 1 by omega] + ite_false, show k + 2 - 1 = k + 1 by omega] have hblank2 : (work (Fin.castAdd 1 2)).cells (m + 2) = Γ.blank := by rw [hcells2 m] exact hmb @@ -852,7 +852,7 @@ theorem clockedUtmTM_hoareTime_halt (α x : List Bool) exact testExit_to_branch α x mcF (V - max T 1) inp work out htest · -- test → else routing: vacuous (the verdict is `Γ.one`) rintro inp work out ⟨-, -, -, -, -, -, -, hcell1⟩ hne - rw [if_pos hhalt] at hcell1 + rw [ite_eq_left hhalt] at hcell1 exact absurd hcell1 hne · -- then-branch post survives the final transition (output WF) rintro inp work out ⟨hcopy, h0, hns⟩ @@ -913,7 +913,7 @@ theorem clockedUtmTM_hoareTime_timeout (α x : List Bool) (le_of_eq (by rw [Nat.max_self])) · -- test → then routing: vacuous (the verdict is `Γ.zero`) rintro inp work out ⟨-, -, -, -, -, -, -, hcell1⟩ hone - rw [hcell1, if_neg hnh] at hone + rw [hcell1, ite_eq_right hnh] at hone exact absurd hone (by decide) · -- test → else routing rintro inp work out htest - diff --git a/Complexitylib/Models/TuringMachine/UTM/Diagonal.lean b/Complexitylib/Models/TuringMachine/UTM/Diagonal.lean index 10b44cfc..e57da676 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Diagonal.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Diagonal.lean @@ -369,7 +369,7 @@ private theorem initTM_δ_split (q : InitQ) (hq : q ≠ .done) (i : Γ) idleDir i, fun j => idleDir (w j), idleDir o) := fun o => rfl rcases h4 : w 4 with _ | _ | _ | _ <;> - exact ⟨_, _, _, _, fun o => by rw [harm o, h4]⟩ + exact ⟨_, _, _, _, fun o => by rw [harm o, h4]; rfl⟩ | .rewindDesc => have harm : ∀ o : Γ, initTM.δ .rewindDesc i w o = if w 4 = Γ.start then @@ -382,8 +382,8 @@ private theorem initTM_δ_split (q : InitQ) (hq : q ≠ .done) (i : Γ) fun j => if j = 4 then Dir3.left else idleDir (w j), idleDir o) := fun o => rfl by_cases hs : w 4 = Γ.start - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_pos hs]; exact rfl⟩ - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_neg hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_left hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_right hs]; exact rfl⟩ | .rewindDesc2 => have harm : ∀ o : Γ, initTM.δ .rewindDesc2 i w o = if w 4 = Γ.start then @@ -396,8 +396,8 @@ private theorem initTM_δ_split (q : InitQ) (hq : q ≠ .done) (i : Γ) fun j => if j = 4 then Dir3.left else idleDir (w j), idleDir o) := fun o => rfl by_cases hs : w 4 = Γ.start - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_pos hs]; exact rfl⟩ - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_neg hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_left hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_right hs]; exact rfl⟩ | .rewindState => have harm : ∀ o : Γ, initTM.δ .rewindState i w o = if w 3 = Γ.start then @@ -410,8 +410,8 @@ private theorem initTM_δ_split (q : InitQ) (hq : q ≠ .done) (i : Γ) fun j => if j = 3 then Dir3.left else idleDir (w j), idleDir o) := fun o => rfl by_cases hs : w 3 = Γ.start - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_pos hs]; exact rfl⟩ - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_neg hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_left hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_right hs]; exact rfl⟩ | .rewindV0 => have harm : ∀ o : Γ, initTM.δ .rewindV0 i w o = if w 0 = Γ.start then @@ -424,8 +424,8 @@ private theorem initTM_δ_split (q : InitQ) (hq : q ≠ .done) (i : Γ) fun j => if j = 0 then Dir3.left else idleDir (w j), idleDir o) := fun o => rfl by_cases hs : w 0 = Γ.start - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_pos hs]; exact rfl⟩ - · exact ⟨_, _, _, _, fun o => by rw [harm o, if_neg hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_left hs]; exact rfl⟩ + · exact ⟨_, _, _, _, fun o => by rw [harm o, ite_eq_right hs]; exact rfl⟩ /-- One `initTM` step commutes with replacing the output tape by any other tape parked off `▷`; the original output tape is preserved exactly. -/ @@ -437,13 +437,13 @@ private theorem initTM_step_swap {c c' : Cfg 6 initTM.Q} have hq := state_ne_qhalt_of_step h obtain ⟨q', ww, inD, wD, hδ⟩ := initTM_δ_split c.state hq c.input.read (fun i => (c.work i).read) - rw [TM.step, if_neg hq, hδ c.output.read] at h + rw [TM.step, ite_eq_right hq, hδ c.output.read] at h dsimp only [] at h rw [Option.some.injEq] at h subst h refine ⟨?_, Tape.writeAndMove_readBack_idle_of_ne_start _ hc⟩ have hq' : ¬ ({ c with output := O } : Cfg 6 initTM.Q).state = initTM.qhalt := hq - rw [TM.step, if_neg hq', hδ O.read] + rw [TM.step, ite_eq_right hq', hδ O.read] dsimp only [] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, rfl, ?_⟩) exact Tape.writeAndMove_readBack_idle_of_ne_start _ hO @@ -1039,9 +1039,9 @@ private theorem testPhaseD (α x : List Bool) (mc : Cfg 1 (decodeDesc α).toTM.Q then Γ.one else Γ.zero) = (if mc.state = (decodeDesc α).toTM.qhalt then Γ.one else Γ.zero) := by by_cases hq : mc.state = (decodeDesc α).toTM.qhalt - · rw [if_pos hq, if_pos + · rw [ite_eq_left hq, ite_eq_left (show S = (takeField (takeField (groupPairs α)).2).1 from hSiff.mpr hq)] - · rw [if_neg hq, if_neg + · rw [ite_eq_right hq, ite_eq_right (show ¬S = (takeField (takeField (groupPairs α)).2).1 from fun hc => hq (hSiff.mp hc))] have hoc1' : c'.output.cells 1 @@ -1135,7 +1135,7 @@ private theorem extractPhaseD (α x : List Bool) (V T m v : ℕ) intro k rw [hvout.1] simp only [show ¬(k + 2 = 0) by omega, show ¬(k + 2 = 1) by omega, - if_false, show k + 2 - 1 = k + 1 by omega] + ite_false, show k + 2 - 1 = k + 1 by omega] have hblank2 : (work (Fin.castAdd 1 2)).cells (m + 2) = Γ.blank := by rw [hcells2 m] exact hmb @@ -1208,7 +1208,7 @@ private theorem cleanUtm_halt (α x : List Bool) · rintro inp work out htest - exact testExit_to_branchD α x mcF (V - max T 1) inp work out htest · rintro inp work out ⟨-, -, -, -, -, -, -, hcell1⟩ hne - rw [if_pos hhalt] at hcell1 + rw [ite_eq_left hhalt] at hcell1 exact absurd hcell1 hne · rintro inp work out ⟨hcopy, h0, hns⟩ refine ⟨m, hmT, hmb, hmnb, ?_⟩ @@ -1258,7 +1258,7 @@ private theorem cleanUtm_timeout (α x : List Bool) (testExit_headD α x mcV 0) ?_ ?_ h_then h_else ?_ ?_) (le_of_eq (by rw [Nat.max_self])) · rintro inp work out ⟨-, -, -, -, -, -, -, hcell1⟩ hone - rw [hcell1, if_neg hnh] at hone + rw [hcell1, ite_eq_right hnh] at hone exact absurd hone (by decide) · rintro inp work out htest - exact testExit_to_branchD α x mcV 0 inp work out htest @@ -1332,7 +1332,7 @@ section RunUnique private theorem step_none_of_halted {n : ℕ} {tm : TM n} {c : Cfg n tm.Q} (h : tm.halted c) : tm.step c = none := by unfold TM.step - rw [if_pos h] + rw [ite_eq_left h] /-- A halted endpoint absorbs longer runs: any run at least as long as a halting run ends at the same configuration. -/ @@ -1409,7 +1409,7 @@ private theorem workX_7 (x : List Bool) : private theorem workX_ne7 (x : List Bool) {i : Fin 8} (h : i ≠ 7) : workX x i = (Tape.init []).move Dir3.right := by simp only [workX] - rw [if_neg h] + rw [ite_eq_right h] private theorem workX_park (x : List Bool) : ∀ i, 1 ≤ (workX x i).head ∧ (workX x i).read ≠ Γ.start := by @@ -1485,12 +1485,12 @@ private theorem retargetInput_step_input {k : ℕ} {M : TM k} (h : (retargetInput M).step c = some c') (hread : c.input.read ≠ Γ.start) : c'.input = c.input := by have hq := state_ne_qhalt_of_step h - rw [TM.step, if_neg hq] at h + rw [TM.step, ite_eq_right hq] at h dsimp only [] at h rw [Option.some.injEq] at h subst h show c.input.move (idleDir c.input.read) = c.input - rw [idleDir, if_neg hread] + rw [idleDir, ite_eq_right hread] rfl private theorem retargetInput_run_input {k : ℕ} {M : TM k} : @@ -1867,7 +1867,7 @@ private theorem thenChain_timeout (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) out.cells 0 = Γ.start ∧ (∀ j, 1 ≤ j → out.cells j ≠ Γ.start)) (by rintro inp work out ⟨h1, h0, hns⟩ refine ⟨?_, h0, hns⟩ - rw [h1, if_pos rfl]) + rw [h1, ite_eq_left rfl]) exact seqTM_hoareTime blankOutTM _ hA1 (by intro inp work out h; exact seamA12 x inp work out h) (seqTM_hoareTime clk _ hA2 @@ -1969,7 +1969,7 @@ private theorem toThen_good (x : List Bool) (hb : terminatedRegionB x = true) : exact transitionTape_eq_self (workX_park x i).2 · refine Tape.ext rfl ?_ show out.cells = outVX.cells - rw [hoc, hb, if_pos rfl] + rw [hoc, hb, ite_eq_left rfl] rfl /-- **Case triple, malformed input**: `terminatedRegionB x = false` routes @@ -2009,7 +2009,7 @@ private theorem diag_triple_bad (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) ?_ ?_ h_then h_else ?_ ?_ · rintro inp work out ⟨-, -, -, hoc, -⟩ hone rw [hoc, Function.update_self, hb] at hone - rw [if_neg (by decide)] at hone + rw [ite_eq_right (by decide)] at hone exact absurd hone (by decide) · rintro inp work out ⟨-, -, -, hoc, -⟩ - refine ⟨?_, ?_, ?_⟩ @@ -2077,7 +2077,7 @@ private theorem diag_triple_halt (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) exact toThen_good x hb inp work out h hone · rintro inp work out ⟨-, -, -, hoc, -⟩ hne refine absurd ?_ hne - rw [hoc, Function.update_self, if_pos hb] + rw [hoc, Function.update_self, ite_eq_left hb] · rintro inp work out ⟨h1, h0, hns⟩ show (transitionTape out).cells 1 = _ rw [transitionTape_cells out hns] @@ -2127,7 +2127,7 @@ private theorem diag_triple_timeout (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) exact toThen_good x hb inp work out h hone · rintro inp work out ⟨-, -, -, hoc, -⟩ hne refine absurd ?_ hne - rw [hoc, Function.update_self, if_pos hb] + rw [hoc, Function.update_self, ite_eq_left hb] · rintro inp work out ⟨h1, h0, hns⟩ show (transitionTape out).cells 1 = Γ.zero rw [transitionTape_cells out hns] @@ -2173,8 +2173,8 @@ theorem diagTM_decidesInTime (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) fun hin => hmem.mp hin, ?_⟩ intro hnot by_cases hm : mcF.output.cells 1 = Γ.one - · rw [hcell, if_pos hm] - · exact absurd (hmem.mpr (by rw [hcell, if_neg hm])) hnot + · rw [hcell, ite_eq_left hm] + · exact absurd (hmem.mpr (by rw [hcell, ite_eq_right hm])) hnot · obtain ⟨c, t, ht, hreach, hhalt, hcell⟩ := diag_triple_timeout clk C g hclk x hb (hg1 x.length) mcV hrunV hnh (Tape.init (x.map Γ.ofBool)) (fun _ => Tape.init []) (Tape.init []) @@ -2211,15 +2211,18 @@ theorem diagTM_flips_of_halts (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) ⟨rfl, fun _ => rfl, rfl⟩ rw [diag_mem_iff clk hreach hhalt', hcell] by_cases hm : mcF.output.cells 1 = Γ.one - · rw [if_pos hm] + · rw [ite_eq_left hm] simp [hm] - · rw [if_neg hm] + · rw [ite_eq_right hm] simp [hm] set_option linter.unusedVariables false in /-- Compatibility form of `diagTM_flips_of_halts`. The positivity hypothesis is not needed for the flip itself, but remains in this public signature for callers of the original theorem. -/ +-- The signature mirrors the family this belongs to; the argument is part of +-- that shape even where this member does not consult it. +@[nolint unusedArguments] theorem diagTM_flips (clk : TM 8) (C : ℕ) (g : ℕ → ℕ) (hclk : ClockWitness clk C g) (hg1 : ∀ n, 1 ≤ g n) (x : List Bool) (hterm : TerminatedRegion x) diff --git a/Complexitylib/Models/TuringMachine/UTM/Encoding.lean b/Complexitylib/Models/TuringMachine/UTM/Encoding.lean index e6ba881b..e16d261c 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Encoding.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Encoding.lean @@ -96,7 +96,7 @@ theorem normalize_step_comm (tm : TM n) (c : Cfg n tm.Q) : (tm.step c).map tm.normalizeCfg := by simp only [step, normalize, normalizeCfg] by_cases h : c.state = tm.qhalt - · simp [h, stateEquiv] + · simp [h, stateEquiv]; rfl · have hne : tm.stateEquiv c.state ≠ tm.stateEquiv tm.qhalt := by intro heq; exact h (tm.stateEquiv.injective heq) simp only [h, hne, ↓reduceIte, Option.map, Equiv.symm_apply_apply, normalizeCfg] diff --git a/Complexitylib/Models/TuringMachine/UTM/HierarchySupport.lean b/Complexitylib/Models/TuringMachine/UTM/HierarchySupport.lean index 7672735e..5cfdf1bf 100644 --- a/Complexitylib/Models/TuringMachine/UTM/HierarchySupport.lean +++ b/Complexitylib/Models/TuringMachine/UTM/HierarchySupport.lean @@ -103,7 +103,7 @@ theorem TM.halt_or_run_dichotomy {k : ℕ} (tm : TM k) (c₀ : Cfg k tm.Q) (V : · exact Or.inl ⟨0, c₀, Nat.zero_le _, .zero, hh⟩ · obtain ⟨c₁, hs⟩ : ∃ c₁, tm.step c₀ = some c₁ := by unfold TM.step - rw [if_neg hh] + rw [ite_eq_right hh] exact ⟨_, rfl⟩ rcases ih c₁ with ⟨T, c, hT, hr, hhalt⟩ | ⟨c, hr, hnh⟩ · exact Or.inl ⟨T + 1, c, by omega, .step hs hr, hhalt⟩ diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyApply.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyApply.lean index aeb5e187..267d2154 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyApply.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyApply.lean @@ -60,12 +60,12 @@ theorem grpDir_eq_decDir (b₀ b₁ : Bool) : grpDir b₀ b₁ = decDir [b₀, b private theorem write_readBack_id {t : Tape} (h : t.head = 0 ∨ t.read ≠ Γ.start) : t.write (readBackWrite t.read).toΓ = t := by rcases h with h0 | hne - · unfold Tape.write; rw [if_pos h0] + · unfold Tape.write; rw [ite_eq_left h0] · rw [toΓ_readBackWrite_of_ne_start hne] unfold Tape.write by_cases h0 : t.head = 0 - · rw [if_pos h0] - · rw [if_neg h0] + · rw [ite_eq_left h0] + · rw [ite_eq_right h0] have hupd : Function.update t.cells t.head t.read = t.cells := Function.update_eq_self t.head t.cells rw [hupd] @@ -113,7 +113,7 @@ private theorem peek_leftstep {sim utm : Tape} (h : VShift sim utm) (if utm.read = Γ.start then Dir3.right else Dir3.left) = ⟨sim.head, utm.cells⟩ := by have hr := h.read_ne_start hwf - rw [if_neg hr, writeAndMove_readBack_left hr, h.2, Nat.add_sub_cancel] + rw [ite_eq_right hr, writeAndMove_readBack_left hr, h.2, Nat.add_sub_cancel] /-- The peek-right (return) step: from head `sim.head` the write-back is a no-op (also at the `▷` bounce) and the right move restores the shadow. -/ @@ -214,7 +214,7 @@ theorem peek_correct {c : Cfg 6 bodyTM.Q} {sim0 sim1 sim2 : Tape} · exact peek_leftstep h2 hwf2 · intro i hi0 hi1 hi2 show (if i = vIn then _ else _) = _ - rw [if_neg hi0, if_neg hi1, if_neg hi2] + rw [ite_eq_right hi0, ite_eq_right hi1, ite_eq_right hi2] exact idle_tape_id (hoth i) -- step 2: read the flags, all three virtual heads right obtain ⟨c₂, hc2, hs₂, hi₂, ho₂, hv₂0, hv₂1, hv₂2, hrest₂⟩ : @@ -241,7 +241,7 @@ theorem peek_correct {c : Cfg 6 bodyTM.Q} {sim0 sim1 sim2 : Tape} · exact peek_return' h2 hwf2 hv₁2 · intro i hi0 hi1 hi2 show (if i = vIn then _ else _) = _ - rw [if_neg hi0, if_neg hi1, if_neg hi2] + rw [ite_eq_right hi0, ite_eq_right hi1, ite_eq_right hi2] exact idle_tape_id (by rw [hrest₁ i hi0 hi1 hi2]; exact hoth i) refine ⟨c₂, .step hc1 (.step hc2 .zero), hs₂, hv₂0, hv₂1, hv₂2, ?_, ?_, ?_, hi₂, ho₂⟩ @@ -287,7 +287,7 @@ theorem segCheck_default_step {c : Cfg 6 bodyTM.Q} {f : VFlags} rw [hdc]; exact fun h => nomatch h have hoth := read_ne_start_all (w := c.work) hr0 hr1 hr2 hstT hdsT hscT have harm := arm_segCheck c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_pos hdc] at harm + rw [ite_eq_left hdc] at harm obtain ⟨c', hstep, hs, hi, ho, hv0, hv1, hv2, hrest⟩ : ∃ c', bodyTM.step c = some c' ∧ c'.state = dfScr ∧ c'.input = c.input ∧ c'.output = c.output ∧ @@ -301,32 +301,32 @@ theorem segCheck_default_step {c : Cfg 6 bodyTM.Q} {f : VFlags} · show (c.work vIn).writeAndMove (readBackWrite ((c.work vIn).read)).toΓ (if (c.work vIn).read = Γ.start then Dir3.right else if f.1 then Dir3.right else Dir3.stay) = _ - rw [if_neg hr0] + rw [ite_eq_right hr0] exact writeAndMove_readBack_move hr0 _ · show (c.work vWk).writeAndMove (readBackWrite ((c.work vWk).read)).toΓ (if (c.work vWk).read = Γ.start then Dir3.right else if f.2.1 then Dir3.right else Dir3.stay) = _ - rw [if_neg hr1] + rw [ite_eq_right hr1] exact writeAndMove_readBack_move hr1 _ · show (c.work vOut).writeAndMove (readBackWrite ((c.work vOut).read)).toΓ (if (c.work vOut).read = Γ.start then Dir3.right else if f.2.2 then Dir3.right else Dir3.stay) = _ - rw [if_neg hr2] + rw [ite_eq_right hr2] exact writeAndMove_readBack_move hr2 _ · intro i hi0 hi1 hi2 show (if i = vIn then _ else _) = _ - rw [if_neg hi0, if_neg hi1, if_neg hi2] + rw [ite_eq_right hi0, ite_eq_right hi1, ite_eq_right hi2] exact idle_tape_id (hoth i) refine ⟨c', .step hstep .zero, hs, ?_, ?_, ?_, hrest stT (by decide) (by decide) (by decide), hrest dsT (by decide) (by decide) (by decide), hrest scT (by decide) (by decide) (by decide), hi, ho⟩ · rw [hv0] - exact h0.move _ fun hz => by rw [hf0, decide_eq_true hz, if_pos rfl] + exact h0.move _ fun hz => by rw [hf0, decide_eq_true hz, ite_eq_left rfl] · rw [hv1] - exact h1.move _ fun hz => by rw [hf1, decide_eq_true hz, if_pos rfl] + exact h1.move _ fun hz => by rw [hf1, decide_eq_true hz, ite_eq_left rfl] · rw [hv2] - exact h2.move _ fun hz => by rw [hf2, decide_eq_true hz, if_pos rfl] + exact h2.move _ fun hz => by rw [hf2, decide_eq_true hz, ite_eq_left rfl] /-- **The segCheck continue step** (`segCheck f` reading non-`□` → `mmScr f`): a pure control-state change — every tape is preserved exactly. -/ @@ -338,7 +338,7 @@ theorem segCheck_continue_step {c : Cfg 6 bodyTM.Q} {f : VFlags} ∃ c', bodyTM.reachesIn 1 c c' ∧ c'.state = mmScr f ∧ (∀ i, c'.work i = c.work i) ∧ c'.input = c.input ∧ c'.output = c.output := by have harm := arm_segCheck c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_neg hdc] at harm + rw [ite_eq_right hdc] at harm refine ⟨_, .step (step_mkAct (by rw [hst]; exact fun h => nomatch h) (by rw [hst]; exact harm)) .zero, rfl, ?_, idle_input_id hin, idle_tape_id hout⟩ @@ -379,7 +379,7 @@ theorem appQ'_loop {f : VFlags} (E : ℕ → Γ) (hEns : ∀ j, 1 ≤ j → E j simp only [Tape.read, hheadS, hcS] simpa using hbl have harm := arm_appQ' c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_pos hreads] at harm + rw [ite_eq_left hreads] at harm have hstep := step_mkAct (c := c) (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) @@ -389,7 +389,7 @@ theorem appQ'_loop {f : VFlags} (E : ℕ → Γ) (hEns : ∀ j, 1 ≤ j → E j rw [idle_tape_id (by rw [hreads]; exact fun h => nomatch h)] have hS : (fun j => if a ≤ j ∧ j < a + 0 then E (e + (j - a)) else S j) = S := by funext j - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hS, ← hcS, show a + 0 = (c.work stT).head from by rw [hheadS]; omega] · show (c.work scT).writeAndMove _ _ = _ rw [idle_tape_id (by @@ -410,7 +410,7 @@ theorem appQ'_loop {f : VFlags} (E : ℕ → Γ) (hEns : ∀ j, 1 ≤ j → E j have hreadsc' : (c.work scT).read ≠ Γ.start := by rw [hreadsc]; exact hEns e he have harm := arm_appQ' c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_neg hreadnb] at harm + rw [ite_eq_right hreadnb] at harm have hstep := step_act2 (c := c) (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) @@ -447,34 +447,34 @@ theorem appQ'_loop {f : VFlags} (E : ℕ → Γ) (hEns : ∀ j, 1 ≤ j → E j rfl (by dsimp only - rw [if_pos rfl, if_neg hreads'] + rw [ite_eq_left rfl, ite_eq_right hreads'] show (((c.work stT).write _).move Dir3.right).cells = _ have hw : (c.work stT).write (readBackWrite ((c.work scT).read)).toΓ = { c.work stT with cells := Function.update (c.work stT).cells (c.work stT).head (readBackWrite ((c.work scT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work stT).cells (c.work stT).head _ = _ rw [hcS, hheadS, hEe]) (by dsimp only - rw [if_pos rfl, if_neg hreads'] + rw [ite_eq_left rfl, ite_eq_right hreads'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadS]) (by dsimp only - rw [if_neg (by decide : scT ≠ stT), if_pos rfl, if_neg hreadsc', + rw [ite_eq_right (by decide : scT ≠ stT), ite_eq_left rfl, ite_eq_right hreadsc', tape_readBackWrite_preserves _ _ (Or.inr hreadsc'), hcE]) (by dsimp only - rw [if_neg (by decide : scT ≠ stT), if_pos rfl, if_neg hreadsc'] + rw [ite_eq_right (by decide : scT ≠ stT), ite_eq_left rfl, ite_eq_right hreadsc'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadE]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi hi' => by dsimp only - rw [if_neg hi, if_neg hi', idle_tape_id (hoth i hi hi')] + rw [ite_eq_right hi, ite_eq_right hi', idle_tape_id (hoth i hi hi')] exact hoth i hi hi') refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtS'] @@ -482,14 +482,14 @@ theorem appQ'_loop {f : VFlags} (E : ℕ → Γ) (hEns : ∀ j, 1 ≤ j → E j refine ⟨by omega, ?_⟩ funext j by_cases hj1 : a + 1 ≤ j ∧ j < a + 1 + n - · rw [if_pos hj1, if_pos (by omega)] + · rw [ite_eq_left hj1, ite_eq_left (by omega)] exact congrArg E (by omega) - · rw [if_neg hj1] + · rw [ite_eq_right hj1] by_cases hje : j = a · subst hje - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg E (by omega) - · rw [Function.update_of_ne hje, if_neg (by omega)] + · rw [Function.update_of_ne hje, ite_eq_right (by omega)] · rw [hwtE'] exact congrArg (fun m => (⟨m, E⟩ : Tape)) (by omega) · rw [hin']; exact idle_input_id hin @@ -497,7 +497,7 @@ theorem appQ'_loop {f : VFlags} (E : ℕ → Γ) (hEns : ∀ j, 1 ≤ j → E j · intro i hi hi' rw [hoth' i hi hi'] show (if i = stT then _ else if i = scT then _ else _) = _ - rw [if_neg hi, if_neg hi'] + rw [ite_eq_right hi, ite_eq_right hi'] exact idle_tape_id (hoth i hi hi') -- ════════════════════════════════════════════════════════════════════════ @@ -549,7 +549,7 @@ private theorem appAct_writeGroup {c : Cfg 6 bodyTM.Q} {f : VFlags} {g : Fin 5} exact writeAndMove_readBack_right (Or.inr hsc0) · intro i hi show (if i = scT then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] refine idle_tape_id ?_ by_cases hit : i = t · subst hit; exact htr @@ -573,7 +573,7 @@ private theorem appAct_writeGroup {c : Cfg 6 bodyTM.Q} {f : VFlags} {g : Fin 5} · rw [hi₁]; exact idle_input_id hin · rw [ho₁]; exact idle_tape_id hout · show (if t = scT then _ else if t = t then _ else _) = _ - rw [if_neg ht, if_pos rfl, ht₁, hsc₁, if_neg htr] + rw [ite_eq_right ht, ite_eq_left rfl, ht₁, hsc₁, ite_eq_right htr] rfl · show (c₁.work scT).writeAndMove (readBackWrite ((c₁.work scT).read)).toΓ (if (c₁.work scT).read = Γ.start then Dir3.right else Dir3.right) = _ @@ -581,7 +581,7 @@ private theorem appAct_writeGroup {c : Cfg 6 bodyTM.Q} {f : VFlags} {g : Fin 5} exact writeAndMove_readBack_right (Or.inr hsc1) · intro i hi hit show (if i = scT then _ else if i = t then _ else _) = _ - rw [if_neg hi, if_neg hit] + rw [ite_eq_right hi, ite_eq_right hit] exact idle_tape_id (by rw [hoth₁ i hi]; exact hoth i hi hit) exact ⟨c₂, .step hc1 (.step hc2 .zero), hs₂, htp₂, hsc₂, hi₂, ho₂, fun i hi hit => (hoth₂ i hi hit).trans (hoth₁ i hi)⟩ @@ -632,7 +632,7 @@ private theorem appAct_moveGroup {c : Cfg 6 bodyTM.Q} {f : VFlags} {g : Fin 5} exact writeAndMove_readBack_right (Or.inr hsc0) · intro i hi show (if i = scT then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] refine idle_tape_id ?_ by_cases hit : i = t · subst hit; exact htr @@ -656,7 +656,7 @@ private theorem appAct_moveGroup {c : Cfg 6 bodyTM.Q} {f : VFlags} {g : Fin 5} · rw [hi₁]; exact idle_input_id hin · rw [ho₁]; exact idle_tape_id hout · show (if t = scT then _ else if t = t then _ else _) = _ - rw [if_neg ht, if_pos rfl, ht₁, hsc₁, if_neg htr] + rw [ite_eq_right ht, ite_eq_left rfl, ht₁, hsc₁, ite_eq_right htr] exact writeAndMove_readBack_move htr _ · show (c₁.work scT).writeAndMove (readBackWrite ((c₁.work scT).read)).toΓ (if (c₁.work scT).read = Γ.start then Dir3.right else Dir3.right) = _ @@ -664,7 +664,7 @@ private theorem appAct_moveGroup {c : Cfg 6 bodyTM.Q} {f : VFlags} {g : Fin 5} exact writeAndMove_readBack_right (Or.inr hsc1) · intro i hi hit show (if i = scT then _ else if i = t then _ else _) = _ - rw [if_neg hi, if_neg hit] + rw [ite_eq_right hi, ite_eq_right hit] exact idle_tape_id (by rw [hoth₁ i hi]; exact hoth i hi hit) exact ⟨c₂, .step hc1 (.step hc2 .zero), hs₂, htp₂, hsc₂, hi₂, ho₂, fun i hi hit => (hoth₂ i hi hit).trans (hoth₁ i hi)⟩ @@ -739,10 +739,10 @@ theorem appAct_all {c : Cfg 6 bodyTM.Q} {f : VFlags} {sim0 sim1 sim2 : Tape} · have hno : sim1.write (grpΓw (cellBit (E e)) (cellBit (E (e + 1)))).toΓ = sim1 := by unfold Tape.write - rw [if_pos hz] - rw [hno, hf1, decide_eq_true hz, if_pos rfl] + rw [ite_eq_left hz] + rw [hno, hf1, decide_eq_true hz, ite_eq_left rfl] exact h1.write_origin hz - · rw [hf1, decide_eq_false hz, if_neg Bool.false_ne_true] + · rw [hf1, decide_eq_false hz, ite_eq_right Bool.false_ne_true] exact h1.write _ (by omega) have hwf1w : (sim1.write (grpΓw (cellBit (E e)) (cellBit (E (e + 1)))).toΓ).StartInvariant := hwf1.write _ @@ -779,10 +779,10 @@ theorem appAct_all {c : Cfg 6 bodyTM.Q} {f : VFlags} {sim0 sim1 sim2 : Tape} · have hno : sim2.write (grpΓw (cellBit (E (e + 2))) (cellBit (E (e + 3)))).toΓ = sim2 := by unfold Tape.write - rw [if_pos hz] - rw [hno, hf2, decide_eq_true hz, if_pos rfl] + rw [ite_eq_left hz] + rw [hno, hf2, decide_eq_true hz, ite_eq_left rfl] exact h2.write_origin hz - · rw [hf2, decide_eq_false hz, if_neg Bool.false_ne_true] + · rw [hf2, decide_eq_false hz, ite_eq_right Bool.false_ne_true] exact h2.write _ (by omega) have hwf2w : (sim2.write (grpΓw (cellBit (E (e + 2))) (cellBit (E (e + 3)))).toΓ).StartInvariant := @@ -819,7 +819,7 @@ theorem appAct_all {c : Cfg 6 bodyTM.Q} {f : VFlags} {sim0 sim1 sim2 : Tape} else grpDir (cellBit (E (e + 4))) (cellBit (E (e + 5))))) (c₃.work vIn) := by rw [hv₃'] - exact h0.move _ fun hz => by rw [hf0, decide_eq_true hz, if_pos rfl] + exact h0.move _ fun hz => by rw [hf0, decide_eq_true hz, ite_eq_left rfl] have hwf0m : (sim0.move (if f.1 then Dir3.right else grpDir (cellBit (E (e + 4))) (cellBit (E (e + 5))))).StartInvariant := @@ -861,7 +861,7 @@ theorem appAct_all {c : Cfg 6 bodyTM.Q} {f : VFlags} {sim0 sim1 sim2 : Tape} rw [hv₄', ← hv₁'] exact h1w.move _ fun hz => by rw [Tape.write_head] at hz - rw [hf1, decide_eq_true hz, if_pos rfl] + rw [hf1, decide_eq_true hz, ite_eq_left rfl] have hwf1m : ((sim1.write (grpΓw (cellBit (E e)) (cellBit (E (e + 1)))).toΓ).move (if f.2.1 then Dir3.right else grpDir (cellBit (E (e + 6))) (cellBit (E (e + 7))))).StartInvariant := @@ -903,7 +903,7 @@ theorem appAct_all {c : Cfg 6 bodyTM.Q} {f : VFlags} {sim0 sim1 sim2 : Tape} rw [hv₅', ← hv₂'] exact h2w.move _ fun hz => by rw [Tape.write_head] at hz - rw [hf2, decide_eq_true hz, if_pos rfl] + rw [hf2, decide_eq_true hz, ite_eq_left rfl] -- ── assembly ── refine ⟨c₅, ?_, hs₅, ?_, ?_, h2m, ?_, ?_, hsc₅', hi₅.trans hi₄', ho₅.trans ho₄'⟩ diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyAssembly.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyAssembly.lean index 45b01b67..c1c24ff0 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyAssembly.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyAssembly.lean @@ -572,7 +572,7 @@ theorem cleanupPhase (c : Cfg 6 bodyTM.Q) (E S W : ℕ → Γ) (p sp dp : ℕ) · show E' 0 = Γ.start rw [hE'] dsimp only - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hE0 · intro i show E' (i + 1) = Γ.blank @@ -679,7 +679,7 @@ theorem defaultTail (c : Cfg 6 bodyTM.Q) (E : ℕ → Γ) (SL : List Γw) if 1 ≤ j ∧ j < 1 + SL.length then Γ.blank else (c.work stT).cells j with hB have hB0 : B 0 = Γ.start := by rw [hB]; dsimp only - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hSL_hold.1 have hBns : ∀ j, 1 ≤ j → B j ≠ Γ.start := by intro j hj @@ -796,7 +796,7 @@ theorem defaultTail (c : Cfg 6 bodyTM.Q) (E : ℕ → Γ) (SL : List Γw) · exact hBns j hj have hC0 : C 0 = Γ.start := by rw [hC]; dsimp only - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hB0 -- dfStRew3: rewind the state head obtain ⟨c₈, hr₈, hst₈, hwtS₈, hin₈, hout₈, hoth₈⟩ := @@ -867,11 +867,11 @@ theorem defaultTail (c : Cfg 6 bodyTM.Q) (E : ℕ → Γ) (SL : List Γw) rw [hC] dsimp only by_cases hi : i < (qhaltField (groupPairs α)).length - · rw [if_pos (by omega), dif_pos hi, + · rw [ite_eq_left (by omega), dite_eq_left hi, show (takeField (groupPairs α)).1.length + 2 + (i + 1 - 1) = (takeField (groupPairs α)).1.length + 2 + i by omega] exact descLayout_field2_val hdesc i hi - · rw [if_neg (by omega), dif_neg hi] + · rw [ite_eq_right (by omega), dite_eq_right hi] exact hBblank (i + 1) (by omega) · rw [hoth₉ stT (by decide), hwtS₈] · -- scratch cleared @@ -883,7 +883,7 @@ theorem defaultTail (c : Cfg 6 bodyTM.Q) (E : ℕ → Γ) (SL : List Γw) · show E' 0 = Γ.start rw [hE'] dsimp only - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hE0 · intro i show E' (i + 1) = Γ.blank @@ -1010,7 +1010,7 @@ theorem applyPhase (c : Cfg 6 bodyTM.Q) {f : VFlags} {sim0 sim1 sim2 : Tape} (by rw [hwtSc₂]) (by rw [hwtSc₂]) (by omega) hE_wns (by rw [hwtS₂] dsimp only [Tape.read] - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hS_wns (1 + SL.length) (by omega)) (by rw [hoth₂ dsT (by decide) (by decide), hoth₁ dsT (by decide)] exact hds_read) @@ -1020,7 +1020,7 @@ theorem applyPhase (c : Cfg 6 bodyTM.Q) {f : VFlags} {sim0 sim1 sim2 : Tape} (c.work scT).cells (1 + (j - 1)) else (c.work stT).cells j with hU have hU0 : U 0 = Γ.start := by rw [hU]; dsimp only - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hSL_hold.1 have hUns : ∀ j, 1 ≤ j → U j ≠ Γ.start := by intro j hj @@ -1088,14 +1088,14 @@ theorem applyPhase (c : Cfg 6 bodyTM.Q) {f : VFlags} {sim0 sim1 sim2 : Tape} rw [hU] dsimp only by_cases hi : i < SL.length - · rw [if_pos (by omega), dif_pos (by + · rw [ite_eq_left (by omega), dite_eq_left (by rw [List.length_take] omega), show 1 + (i + 1 - 1) = i + 1 by omega, Tape.HoldsExact.cells_lt hEL_hold (by omega)] congr 1 exact (List.getElem_take ..).symm - · rw [if_neg (by omega), dif_neg (by rw [List.length_take]; omega), + · rw [ite_eq_right (by omega), dite_eq_right (by rw [List.length_take]; omega), show i + 1 = i + 1 by rfl] exact Tape.HoldsExact.cells_ge hSL_hold (by omega) · rw [hwtS₄] diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyInternal.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyInternal.lean index 5d9901b3..22dffe28 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyInternal.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyInternal.lean @@ -46,15 +46,15 @@ theorem step_mkAct {c : Cfg 6 bodyTM.Q} (hne : c.state ≠ bodyDone) output := c.output.writeAndMove (readBackWrite c.output.read).toΓ (idleDir c.output.read) } := by have hne' : c.state ≠ bodyTM.qhalt := hne - simp only [step, if_neg hne', Option.some.injEq] + simp only [step, ite_eq_right hne', Option.some.injEq] show (let (q'', wW, oW, iD, wD, oD) := bodyδ c.state c.input.read (fun i => (c.work i).read) c.output.read ({ state := q'', input := c.input.move iD, work := fun i => (c.work i).writeAndMove (wW i).toΓ (wD i), output := c.output.writeAndMove oW.toΓ oD } : Cfg 6 bodyTM.Q)) = _ rw [h] - simp only [mkAct, Cfg.mk.injEq] - refine ⟨trivial, trivial, ?_, trivial⟩ + simp only [mkAct] + congr 1 funext i cases acts i with | none => rfl @@ -93,8 +93,8 @@ theorem step_act1 {c : Cfg 6 bodyTM.Q} (hne : c.state ≠ bodyDone) (idleDir c.output.read) } := by rw [step_mkAct hne h] refine congrArg some ?_ - simp only [Cfg.mk.injEq] - refine ⟨trivial, trivial, funext fun i => ?_, trivial⟩ + congr 1 + funext i by_cases hi : i = t <;> simp [hi] /-- Closed form of a step whose arm is `act2` (two active tapes). -/ @@ -119,8 +119,8 @@ theorem step_act2 {c : Cfg 6 bodyTM.Q} (hne : c.state ≠ bodyDone) (idleDir c.output.read) } := by rw [step_mkAct hne h] refine congrArg some ?_ - simp only [Cfg.mk.injEq] - refine ⟨trivial, trivial, funext fun i => ?_, trivial⟩ + congr 1 + funext i by_cases h1 : i = t₁ · simp [h1] · by_cases h2 : i = t₂ @@ -152,8 +152,8 @@ theorem step_act3 {c : Cfg 6 bodyTM.Q} (hne : c.state ≠ bodyDone) (idleDir c.output.read) } := by rw [step_mkAct hne h] refine congrArg some ?_ - simp only [Cfg.mk.injEq] - refine ⟨trivial, trivial, funext fun i => ?_, trivial⟩ + congr 1 + funext i by_cases h1 : i = t₁ · simp [h1] · by_cases h2 : i = t₂ @@ -187,21 +187,21 @@ theorem rewStep_loop {cur next : BodyQ} {t : Fin 6} have hread : (c.work t).read = Γ.start := by simp [Tape.read, hhead, hcW, hW0] have harm := hδ c.input.read (fun i => (c.work i).read) c.output.read - rw [rewStep, if_pos hread] at harm + rw [rewStep, ite_eq_left hread] at harm have hstep := step_act1 (by rw [hst]; exact hcur) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, idle_input_id hin, idle_tape_id hout, ?_⟩ · show (if t = t then _ else _) = _ - rw [if_pos rfl, if_pos hread] + rw [ite_eq_left rfl, ite_eq_left hread] have hwr : (c.work t).write (readBackWrite ((c.work t).read)).toΓ = c.work t := by unfold Tape.write - rw [if_pos hhead] + rw [ite_eq_left hhead] show ((c.work t).write _).move .right = _ rw [hwr] simp only [Tape.move, Tape.mk.injEq] exact ⟨by rw [hhead], hcW⟩ · intro i hi show (if i = t then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) | succ p ih => intro c hst hcW hhead hin hout hoth @@ -209,7 +209,7 @@ theorem rewStep_loop {cur next : BodyQ} {t : Fin 6} simp only [Tape.read, hhead, hcW] exact hWns (p + 1) (by omega) have harm := hδ c.input.read (fun i => (c.work i).read) c.output.read - rw [rewStep, if_neg hread] at harm + rw [rewStep, ite_eq_right hread] at harm have hstep := step_act1 (by rw [hst]; exact hcur) (by rw [hst]; exact harm) obtain ⟨c', hreach, hst', hwt', hin', hout', hoth'⟩ := ih { state := cur @@ -225,18 +225,18 @@ theorem rewStep_loop {cur next : BodyQ} {t : Fin 6} rfl (by dsimp only - rw [if_pos rfl, if_neg hread, + rw [ite_eq_left rfl, ite_eq_right hread, tape_readBackWrite_preserves _ _ (Or.inr hread), hcW]) (by dsimp only - rw [if_pos rfl, if_neg hread] + rw [ite_eq_left rfl, ite_eq_right hread] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hhead] omega) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi => by dsimp only - rw [if_neg hi, idle_tape_id (hoth i hi)] + rw [ite_eq_right hi, idle_tape_id (hoth i hi)] exact hoth i hi) refine ⟨c', .step hstep hreach, hst', hwt', ?_, ?_, ?_⟩ · rw [hin']; exact idle_input_id hin @@ -244,7 +244,7 @@ theorem rewStep_loop {cur next : BodyQ} {t : Fin 6} · intro i hi rw [hoth' i hi] show (if i = t then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) -- ════════════════════════════════════════════════════════════════════════ @@ -276,24 +276,24 @@ theorem blankRewStep_loop {cur next : BodyQ} {t : Fin 6} have hread : (c.work t).read = Γ.start := by simp [Tape.read, hhead, hcW, hW0] have harm := hδ c.input.read (fun i => (c.work i).read) c.output.read - rw [blankRewStep, if_pos hread] at harm + rw [blankRewStep, ite_eq_left hread] at harm have hstep := step_act1 (by rw [hst]; exact hcur) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, idle_input_id hin, idle_tape_id hout, ?_⟩ · show (if t = t then _ else _) = (⟨1, _⟩ : Tape) - rw [if_pos rfl, if_pos hread] + rw [ite_eq_left rfl, ite_eq_left hread] have hwr : (c.work t).write (readBackWrite ((c.work t).read)).toΓ = c.work t := by unfold Tape.write - rw [if_pos hhead] + rw [ite_eq_left hhead] show ((c.work t).write _).move .right = _ rw [hwr] simp only [Tape.move, Tape.mk.injEq] refine ⟨by rw [hhead], ?_⟩ rw [hcW] funext j - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] · intro i hi show (if i = t then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) | succ p ih => intro W hW0 hWns c hst hcW hhead hin hout hoth @@ -301,7 +301,7 @@ theorem blankRewStep_loop {cur next : BodyQ} {t : Fin 6} simp only [Tape.read, hhead, hcW] exact hWns (p + 1) (by omega) have harm := hδ c.input.read (fun i => (c.work i).read) c.output.read - rw [blankRewStep, if_neg hread] at harm + rw [blankRewStep, ite_eq_right hread] at harm have hstep := step_act1 (by rw [hst]; exact hcur) (by rw [hst]; exact harm) -- cells after blanking cell p+1 have hupd0 : Function.update W (p + 1) Γ.blank 0 = Γ.start := by @@ -326,45 +326,45 @@ theorem blankRewStep_loop {cur next : BodyQ} {t : Fin 6} rfl (by dsimp only - rw [if_pos rfl, if_neg hread] + rw [ite_eq_left rfl, ite_eq_right hread] show (((c.work t).write _).move Dir3.left).cells = _ have : (c.work t).write Γw.blank.toΓ = { c.work t with cells := Function.update (c.work t).cells (c.work t).head Γw.blank.toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [this] show Function.update (c.work t).cells (c.work t).head Γw.blank.toΓ = _ rw [hcW, hhead] rfl) (by dsimp only - rw [if_pos rfl, if_neg hread] + rw [ite_eq_left rfl, ite_eq_right hread] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hhead] omega) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi => by dsimp only - rw [if_neg hi, idle_tape_id (hoth i hi)] + rw [ite_eq_right hi, idle_tape_id (hoth i hi)] exact hoth i hi) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_⟩ · rw [hwt'] refine congrArg _ ?_ funext j by_cases hj1 : 1 ≤ j ∧ j ≤ p - · rw [if_pos hj1, if_pos (by omega)] - · rw [if_neg hj1] + · rw [ite_eq_left hj1, ite_eq_left (by omega)] + · rw [ite_eq_right hj1] by_cases hje : j = p + 1 · subst hje - rw [Function.update_self, if_pos (by omega)] - · rw [Function.update_of_ne hje, if_neg (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] + · rw [Function.update_of_ne hje, ite_eq_right (by omega)] · rw [hin']; exact idle_input_id hin · rw [hout']; exact idle_tape_id hout · intro i hi rw [hoth' i hi] show (if i = t then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) -- ════════════════════════════════════════════════════════════════════════ @@ -402,11 +402,11 @@ theorem scanRight_loop {cur next : BodyQ} {t : Fin 6} simpa using hbl have hread' : (c.work t).read ≠ Γ.start := by rw [hread]; simp have harm := hδ c.input.read (fun i => (c.work i).read) c.output.read - rw [if_pos hread] at harm + rw [ite_eq_left hread] at harm have hstep := step_act1 (by rw [hst]; exact hcur) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, idle_input_id hin, idle_tape_id hout, ?_⟩ · show (if t = t then _ else _) = (⟨h + 0 + 1, W⟩ : Tape) - rw [if_pos rfl, if_neg hread'] + rw [ite_eq_left rfl, ite_eq_right hread'] show ((c.work t).write _).move .right = _ have hcells := tape_readBackWrite_preserves (c.work t) Dir3.right (Or.inr hread') simp only [Tape.writeAndMove] at hcells @@ -419,7 +419,7 @@ theorem scanRight_loop {cur next : BodyQ} {t : Fin 6} rw [this, hcW] · intro i hi show (if i = t then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) | succ k ih => intro h hh hnb hbl c hst hcW hhead hin hout hoth @@ -431,7 +431,7 @@ theorem scanRight_loop {cur next : BodyQ} {t : Fin 6} have hread' : (c.work t).read ≠ Γ.start := by rw [hread]; exact hWns h hh have harm := hδ c.input.read (fun i => (c.work i).read) c.output.read - rw [if_neg hreadnb] at harm + rw [ite_eq_right hreadnb] at harm have hstep := step_act1 (by rw [hst]; exact hcur) (by rw [hst]; exact harm) obtain ⟨c', hreach, hst', hwt', hin', hout', hoth'⟩ := ih (h + 1) (by omega) @@ -454,17 +454,17 @@ theorem scanRight_loop {cur next : BodyQ} {t : Fin 6} rfl (by dsimp only - rw [if_pos rfl, + rw [ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hread'), hcW]) (by dsimp only - rw [if_pos rfl, if_neg hread'] + rw [ite_eq_left rfl, ite_eq_right hread'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hhead]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi => by dsimp only - rw [if_neg hi, idle_tape_id (hoth i hi)] + rw [ite_eq_right hi, idle_tape_id (hoth i hi)] exact hoth i hi) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_⟩ · rw [hwt'] @@ -474,7 +474,7 @@ theorem scanRight_loop {cur next : BodyQ} {t : Fin 6} · intro i hi rw [hoth' i hi] show (if i = t then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) -- ════════════════════════════════════════════════════════════════════════ @@ -665,7 +665,7 @@ theorem dfBlank_loop : simp only [Tape.read, hhead, hcW] simpa using hbl have harm := arm_dfBlank c.input.read (fun i => (c.work i).read) c.output.read - rw [if_pos hread] at harm + rw [ite_eq_left hread] at harm have hstep := step_mkAct (c := c) (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) @@ -675,7 +675,7 @@ theorem dfBlank_loop : rw [idle_tape_id (by rw [hread]; simp)] have : (fun j => if h ≤ j ∧ j < h + 0 then Γ.blank else W j) = W := by funext j - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [this, ← hcW, show h + 0 = (c.work stT).head from by rw [hhead]; omega] | succ k ih => intro W hWns h hh hnb hbl c hst hcW hhead hin hout hoth @@ -685,7 +685,7 @@ theorem dfBlank_loop : rw [hread] simpa using hnb 0 (by omega) have harm := arm_dfBlank c.input.read (fun i => (c.work i).read) c.output.read - rw [if_neg hreadnb] at harm + rw [ite_eq_right hreadnb] at harm have hread' : (c.work stT).read ≠ Γ.start := by rw [hread]; exact hWns h hh have hstep := step_act1 (c := c) @@ -720,26 +720,26 @@ theorem dfBlank_loop : rfl (by dsimp only - rw [if_pos rfl, if_neg hread'] + rw [ite_eq_left rfl, ite_eq_right hread'] show (((c.work stT).write Γw.blank.toΓ).move Dir3.right).cells = _ have hw : (c.work stT).write Γw.blank.toΓ = { c.work stT with cells := Function.update (c.work stT).cells (c.work stT).head Γw.blank.toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work stT).cells (c.work stT).head Γw.blank.toΓ = _ rw [hcW, hhead] rfl) (by dsimp only - rw [if_pos rfl, if_neg hread'] + rw [ite_eq_left rfl, ite_eq_right hread'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hhead]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi => by dsimp only - rw [if_neg hi, idle_tape_id (hoth i hi)] + rw [ite_eq_right hi, idle_tape_id (hoth i hi)] exact hoth i hi) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_⟩ · rw [hwt'] @@ -747,18 +747,18 @@ theorem dfBlank_loop : refine ⟨by omega, ?_⟩ funext j by_cases hj1 : h + 1 ≤ j ∧ j < h + 1 + k - · rw [if_pos hj1, if_pos (by omega)] - · rw [if_neg hj1] + · rw [ite_eq_left hj1, ite_eq_left (by omega)] + · rw [ite_eq_right hj1] by_cases hje : j = h · subst hje - rw [Function.update_self, if_pos (by omega)] - · rw [Function.update_of_ne hje, if_neg (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] + · rw [Function.update_of_ne hje, ite_eq_right (by omega)] · rw [hin']; exact idle_input_id hin · rw [hout']; exact idle_tape_id hout · intro i hi rw [hoth' i hi] show (if i = stT then _ else _) = _ - rw [if_neg hi] + rw [ite_eq_right hi] exact idle_tape_id (hoth i hi) -- ════════════════════════════════════════════════════════════════════════ @@ -797,7 +797,7 @@ theorem dfCopy_loop (W : ℕ → Γ) (hWns : ∀ j, 1 ≤ j → W j ≠ Γ.start simp only [Tape.read, hheadV, hcV] exact hVns a ha have harm := arm_dfCopy c.input.read (fun i => (c.work i).read) c.output.read - rw [if_pos hreadd] at harm + rw [ite_eq_left hreadd] at harm have hstep := step_mkAct (c := c) (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) @@ -807,7 +807,7 @@ theorem dfCopy_loop (W : ℕ → Γ) (hWns : ∀ j, 1 ≤ j → W j ≠ Γ.start rw [idle_tape_id hreads] have hV : (fun j => if a ≤ j ∧ j < a + 0 then W (b + (j - a)) else V j) = V := by funext j - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hV, ← hcV, show a + 0 = (c.work stT).head from by rw [hheadV]; omega] · show (c.work dsT).writeAndMove _ _ = _ rw [idle_tape_id (by rw [hreadd]; simp)] @@ -825,7 +825,7 @@ theorem dfCopy_loop (W : ℕ → Γ) (hWns : ∀ j, 1 ≤ j → W j ≠ Γ.start simp only [Tape.read, hheadV, hcV] exact hVns a ha have harm := arm_dfCopy c.input.read (fun i => (c.work i).read) c.output.read - rw [if_neg hreadnb] at harm + rw [ite_eq_right hreadnb] at harm have hstep := step_act2 (c := c) (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) @@ -860,34 +860,34 @@ theorem dfCopy_loop (W : ℕ → Γ) (hWns : ∀ j, 1 ≤ j → W j ≠ Γ.start rfl (by dsimp only - rw [if_pos rfl, if_neg hreads] + rw [ite_eq_left rfl, ite_eq_right hreads] show (((c.work stT).write _).move Dir3.right).cells = _ have hw : (c.work stT).write (readBackWrite ((c.work dsT).read)).toΓ = { c.work stT with cells := Function.update (c.work stT).cells (c.work stT).head (readBackWrite ((c.work dsT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work stT).cells (c.work stT).head _ = _ rw [hcV, hheadV, hWb]) (by dsimp only - rw [if_pos rfl, if_neg hreads] + rw [ite_eq_left rfl, ite_eq_right hreads] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadV]) (by dsimp only - rw [if_neg (by decide : dsT ≠ stT), if_pos rfl, if_neg hreadd', + rw [ite_eq_right (by decide : dsT ≠ stT), ite_eq_left rfl, ite_eq_right hreadd', tape_readBackWrite_preserves _ _ (Or.inr hreadd'), hcW]) (by dsimp only - rw [if_neg (by decide : dsT ≠ stT), if_pos rfl, if_neg hreadd'] + rw [ite_eq_right (by decide : dsT ≠ stT), ite_eq_left rfl, ite_eq_right hreadd'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi hi' => by dsimp only - rw [if_neg hi, if_neg hi', idle_tape_id (hoth i hi hi')] + rw [ite_eq_right hi, ite_eq_right hi', idle_tape_id (hoth i hi hi')] exact hoth i hi hi') refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtS'] @@ -895,14 +895,14 @@ theorem dfCopy_loop (W : ℕ → Γ) (hWns : ∀ j, 1 ≤ j → W j ≠ Γ.start refine ⟨by omega, ?_⟩ funext j by_cases hj1 : a + 1 ≤ j ∧ j < a + 1 + k - · rw [if_pos hj1, if_pos (by omega)] + · rw [ite_eq_left hj1, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [if_neg hj1] + · rw [ite_eq_right hj1] by_cases hje : j = a · subst hje - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [Function.update_of_ne hje, if_neg (by omega)] + · rw [Function.update_of_ne hje, ite_eq_right (by omega)] · rw [hwtD'] exact congrArg (fun n => (⟨n, W⟩ : Tape)) (by omega) · rw [hin']; exact idle_input_id hin @@ -910,7 +910,7 @@ theorem dfCopy_loop (W : ℕ → Γ) (hWns : ∀ j, 1 ≤ j → W j ≠ Γ.start · intro i hi hi' rw [hoth' i hi hi'] show (if i = stT then _ else if i = dsT then _ else _) = _ - rw [if_neg hi, if_neg hi'] + rw [ite_eq_right hi, ite_eq_right hi'] exact idle_tape_id (hoth i hi hi') end TM.UTMBody diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyIteration.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyIteration.lean index 2dad9d1c..f28c177c 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyIteration.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyIteration.lean @@ -78,9 +78,9 @@ private theorem sanitize_dir_eq {sim : Tape} (hwf : sim.StartInvariant) (flag : = (if sim.read = Γ.start then Dir3.right else d) := by subst hflag by_cases h0 : sim.head = 0 - · rw [decide_eq_true h0, if_pos rfl, if_pos ((read_start_iff hwf).mpr h0)] - · rw [decide_eq_false h0, if_neg Bool.false_ne_true, - if_neg (fun hc => h0 ((read_start_iff hwf).mp hc))] + · rw [decide_eq_true h0, ite_eq_left rfl, ite_eq_left ((read_start_iff hwf).mpr h0)] + · rw [decide_eq_false h0, ite_eq_right Bool.false_ne_true, + ite_eq_right (fun hc => h0 ((read_start_iff hwf).mp hc))] /-- **The default-move correspondence** (the crux of the no-match branch): the UTM's readback-write plus flag-sanitized move on the shadow tape @@ -93,7 +93,7 @@ private theorem vshift_default_move {sim utm : Tape} (h : VShift sim utm) rw [readBackWrite_eq_readback, writeAndMove_readback_eq_move (h.startInvariant hwf), sanitize_dir_eq hwf flag hflag Dir3.stay] - exact h.move _ (fun h0 => by rw [if_pos ((read_start_iff hwf).mpr h0)]) + exact h.move _ (fun h0 => by rw [ite_eq_left ((read_start_iff hwf).mpr h0)]) /-- The interpreted step in closed form, on a running configuration whose looked-up action is `a`. -/ @@ -110,7 +110,7 @@ private theorem toTM_step_running {d : TMDesc} {mc : Cfg 1 d.toTM.Q} output := mc.output.writeAndMove a.wo.toΓ (if mc.output.read = Γ.start then Dir3.right else a.dOut) } := by subst ha - simp only [TM.step, if_neg hh] + simp only [TM.step, ite_eq_right hh] rfl -- ════════════════════════════════════════════════════════════════════════ diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLookup.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLookup.lean index eeb2909a..0d8180c8 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLookup.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLookup.lean @@ -186,8 +186,8 @@ private theorem parseEntry_eq (w : ℕ) (seg : List Γw) : else none := by rw [parseEntry] by_cases hlen : (seg.filterMap symBit?).length < 2 * w + 16 - · rw [if_pos hlen, if_neg (by omega)] - · rw [if_neg hlen, if_pos (by omega)] + · rw [ite_eq_left hlen, ite_eq_right (by omega)] + · rw [ite_eq_right hlen, ite_eq_left (by omega)] dsimp only rw [drop_add _ (rfl : w + 2 = w + 2), drop_add _ (by omega : w + 2 + 2 = w + 4), @@ -219,7 +219,7 @@ theorem machMatch_iff_parse {w q : ℕ} (hq : q < 2 ^ w) (f : VFlags) rw [MachMatch, parseEntry_eq] constructor · rintro ⟨h1, h2, h3⟩ - rw [if_pos (by omega)] + rw [ite_eq_left (by omega)] have hkey : ((seg.filterMap symBit?).drop w).take 6 = (simRead f.1 v0).encode ++ (simRead f.2.1 v1).encode ++ (simRead f.2.2 v2).encode := by @@ -263,7 +263,7 @@ theorem machMatch_iff_parse {w q : ℕ} (hq : q < 2 ^ w) (f : VFlags) rw [this, decΓ_encode] · rintro ⟨e, hpe, hq', hsi, hsw, hso⟩ by_cases hc : 2 * w + 16 ≤ (seg.filterMap symBit?).length - · rw [if_pos hc] at hpe + · rw [ite_eq_left hc] at hpe injection hpe with hpe subst hpe dsimp only at hq' hsi hsw hso @@ -295,7 +295,7 @@ theorem machMatch_iff_parse {w q : ℕ} (hq : q < 2 ^ w) (f : VFlags) drop_add _ (by omega : w + 2 + 2 = w + 4), hso'] rw [← hseg, ← bitsToSyms_drop, ← bitsToSyms_take, hkey, keyCells, List.append_assoc] - · rw [if_neg hc] at hpe + · rw [ite_eq_right hc] at hpe exact absurd hpe (by simp) -- ════════════════════════════════════════════════════════════════════════ @@ -341,11 +341,11 @@ theorem machFind_matches (w : ℕ) (stSyms keyCs : List Γw) : simp [machFind] at h · rw [machFind_cons_of_ne_blank hs] at h by_cases hm : MachMatch w stSyms keyCs (takeField (s :: rest)).1 - · rw [if_pos hm] at h + · rw [ite_eq_left hm] at h injection h with h subst h exact ⟨hm, takeField_fst_ne_blank _⟩ - · rw [if_neg hm] at h + · rw [ite_eq_right hm] at h exact machFind_matches w stSyms keyCs (takeField (s :: rest)).2 seg h termination_by R => R.length decreasing_by @@ -383,13 +383,13 @@ theorem find?_parseEntries_eq_machFind (w q : ℕ) (hq : q < 2 ^ w) takeField_fst_ne_blank _ by_cases hm : MachMatch w (bitsToSyms (Nat.toBits w q)) (keyCells f v0 v1 v2) (takeField (s :: rest)).1 - · rw [if_pos hm] + · rw [ite_eq_left hm] obtain ⟨e, hpe, hq', hsi, hsw, hso⟩ := (machMatch_iff_parse hq f v0 v1 v2 hnb).mp hm simp only [hpe, Option.bind_some] exact List.find?_cons_of_pos (by simp [keyMatch, hq', hsi, hsw, hso]) - · rw [if_neg hm] + · rw [ite_eq_right hm] cases hpe : parseEntry w (takeField (s :: rest)).1 with | none => exact find?_parseEntries_eq_machFind w q hq f v0 v1 v2 @@ -508,9 +508,9 @@ theorem value_slices {w : ℕ} {seg : List Γw} {e : DescEntry} rw [parseEntry_eq] at hp by_cases hc : 2 * w + 16 ≤ (seg.filterMap symBit?).length swap - · rw [if_neg hc] at hp + · rw [ite_eq_right hc] at hp exact absurd hp (by simp) - rw [if_pos hc] at hp + rw [ite_eq_left hc] at hp injection hp with hp subst hp have hgrp : ∀ i j : ℕ, i + 1 = j → j < (seg.filterMap symBit?).length → diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLoop.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLoop.lean index 71fdb1bf..d1d0b2f9 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLoop.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyLoop.lean @@ -304,11 +304,10 @@ private theorem roundMatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γw) else (c.work scT).cells j) (by intro i hi - dsimp only by_cases hcase : 1 ≤ i ∧ i < 1 + stSyms.length - · rw [if_pos hcase] + · rw [ite_eq_left hcase] exact hWns _ (by omega) - · rw [if_neg hcase] + · rw [ite_eq_right hcase] exact hE_wns i hi) (pos + stSyms.length + 6 + stSyms.length) (1 + stSyms.length) (by omega) (by omega) @@ -350,12 +349,12 @@ private theorem roundMatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γw) reachesIn_trans _ (reachesIn_trans _ (reachesIn_trans _ hr₁ hr₂) hr₃) hr₄, hst₄, ⟨?_, fun i => ?_⟩, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · -- scratch cell 0 - rw [hE₂ 0, if_neg (by omega), if_neg (by omega)] + rw [hE₂ 0, ite_eq_right (by omega), ite_eq_right (by omega)] exact hSc.1 · -- scratch cells: the value slice rw [hE₂ (i + 1)] by_cases hi : i < stSyms.length + 10 - · rw [dif_pos (by rw [hslice_len]; omega)] + · rw [dite_eq_left (by rw [hslice_len]; omega)] have hcell : (c.work dsT).cells (pos + (stSyms.length + 6 + i)) = (seg[stSyms.length + 6 + i]'(by omega)).toΓ := hview _ (by omega) have hsliceval : @@ -364,18 +363,18 @@ private theorem roundMatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γw) = seg[stSyms.length + 6 + i]'(by omega) := by rw [List.getElem_take, List.getElem_drop] by_cases hiw : stSyms.length ≤ i - · rw [if_pos (by omega), + · rw [ite_eq_left (by omega), show pos + stSyms.length + 6 + stSyms.length + (i + 1 - (1 + stSyms.length)) = pos + (stSyms.length + 6 + i) by omega, hcell] exact (congrArg Γw.toΓ hsliceval).symm - · rw [if_neg (by omega), if_pos (by omega), + · rw [ite_eq_right (by omega), ite_eq_left (by omega), show pos + stSyms.length + 6 + (i + 1 - 1) = pos + (stSyms.length + 6 + i) by omega, hcell] exact (congrArg Γw.toΓ hsliceval).symm - · rw [dif_neg (by rw [hslice_len]; omega), if_neg (by omega), - if_neg (by omega)] + · rw [dite_eq_right (by rw [hslice_len]; omega), ite_eq_right (by omega), + ite_eq_right (by omega)] exact Tape.HoldsExact.cells_ge hSc (Nat.zero_le _) · -- scratch head rw [hwtE₄] @@ -847,14 +846,14 @@ private theorem roundMismatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γ · rw [hwtD₃] show pos + stSyms.length + 6 + (seg.length - (stSyms.length + 6)) = _ omega - · rw [hE₁ 0, if_neg (by omega)] + · rw [hE₁ 0, ite_eq_right (by omega)] exact hSc.1 · intro j hj rw [hE₁ j] by_cases hcase : 1 ≤ j ∧ j < 1 + (seg.length - (stSyms.length + 6)) - · rw [if_pos hcase] + · rw [ite_eq_left hcase] exact hWns _ (by omega) - · rw [if_neg hcase] + · rw [ite_eq_right hcase] exact hE_wns j hj · rw [hwtE₃] show 1 ≤ 1 + (seg.length - (stSyms.length + 6)); omega @@ -864,7 +863,7 @@ private theorem roundMismatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γ have hj' : 1 + (seg.length - (stSyms.length + 6)) ≤ j := by rw [hwtE₃] at hj exact hj - rw [hE₁ j, if_neg (by omega)] + rw [hE₁ j, ite_eq_right (by omega)] exact hsc_blank j (by omega) · rw [hoth₃ vIn (by decide) (by decide) (by decide), hoth₂ vIn (by decide) (by decide), @@ -909,11 +908,10 @@ private theorem roundMismatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γ else (c.work scT).cells j) (by intro i hi - dsimp only by_cases hcase : 1 ≤ i ∧ i < 1 + stSyms.length - · rw [if_pos hcase] + · rw [ite_eq_left hcase] exact hWns _ (by omega) - · rw [if_neg hcase] + · rw [ite_eq_right hcase] exact hE_wns i hi) (pos + stSyms.length + 6 + stSyms.length) (1 + stSyms.length) (by omega) (by omega) @@ -966,19 +964,19 @@ private theorem roundMismatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γ show pos + stSyms.length + 6 + stSyms.length + (seg.length - (2 * stSyms.length + 6)) = _ omega - · rw [hE₂ 0, if_neg (by omega), if_neg (by omega)] + · rw [hE₂ 0, ite_eq_right (by omega), ite_eq_right (by omega)] exact hSc.1 · intro j hj rw [hE₂ j] by_cases hcase : 1 + stSyms.length ≤ j ∧ j < 1 + stSyms.length + (seg.length - (2 * stSyms.length + 6)) - · rw [if_pos hcase] + · rw [ite_eq_left hcase] exact hWns _ (by omega) - · rw [if_neg hcase] + · rw [ite_eq_right hcase] by_cases hcase' : 1 ≤ j ∧ j < 1 + stSyms.length - · rw [if_pos hcase'] + · rw [ite_eq_left hcase'] exact hWns _ (by omega) - · rw [if_neg hcase'] + · rw [ite_eq_right hcase'] exact hE_wns j hj · rw [hwtE₄] show 1 ≤ 1 + stSyms.length + (seg.length - (2 * stSyms.length + 6)) @@ -991,7 +989,7 @@ private theorem roundMismatch (f : VFlags) (v0 v1 v2 : Γ) (stSyms seg : List Γ ≤ j := by rw [hwtE₄] at hj exact hj - rw [hE₂ j, if_neg (by omega), if_neg (by omega)] + rw [hE₂ j, ite_eq_right (by omega), ite_eq_right (by omega)] exact hsc_blank j (by omega) · rw [hoth₄ vIn (by decide) (by decide), hoth₃ vIn (by decide) (by decide) (by decide), @@ -1039,7 +1037,7 @@ private theorem segCheck_blank_step {c : Cfg 6 bodyTM.Q} {f : VFlags} rw [hdc]; exact fun h => nomatch h have harm := arm_segCheck c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_pos hdc] at harm + rw [ite_eq_left hdc] at harm have hstep := step_act3 (by rw [hst]; exact fun h => nomatch h) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, ?_, ?_, ?_, @@ -1047,19 +1045,19 @@ private theorem segCheck_blank_step {c : Cfg 6 bodyTM.Q} {f : VFlags} · show (c.work vIn).writeAndMove (readBackWrite ((c.work vIn).read)).toΓ (if (c.work vIn).read = Γ.start then Dir3.right else if f.1 then Dir3.right else Dir3.stay) = _ - rw [if_neg hv0s] + rw [ite_eq_right hv0s] · show (c.work vWk).writeAndMove (readBackWrite ((c.work vWk).read)).toΓ (if (c.work vWk).read = Γ.start then Dir3.right else if f.2.1 then Dir3.right else Dir3.stay) = _ - rw [if_neg hv1s] + rw [ite_eq_right hv1s] · show (c.work vOut).writeAndMove (readBackWrite ((c.work vOut).read)).toΓ (if (c.work vOut).read = Γ.start then Dir3.right else if f.2.2 then Dir3.right else Dir3.stay) = _ - rw [if_neg hv2s] + rw [ite_eq_right hv2s] · intro i hi0 hi1 hi2 show (if i = vIn then _ else if i = vWk then _ else if i = vOut then _ else _) = _ - rw [if_neg hi0, if_neg hi1, if_neg hi2] + rw [ite_eq_right hi0, ite_eq_right hi1, ite_eq_right hi2] refine idle_tape_id ?_ rcases i with ⟨iv, hv⟩ rcases iv with _ | _ | _ | _ | _ | _ | n @@ -1211,7 +1209,7 @@ private theorem matchLoop_go (f : VFlags) (v0 v1 v2 : Γ) (stSyms : List Γw) simp [takeField] at h22 have hfindR : machFind stSyms.length stSyms (keyCells f v0 v1 v2) (s :: rest) = some (takeField (s :: rest)).1 := by - rw [machFind_cons_of_ne_blank hs, if_pos hMM] + rw [machFind_cons_of_ne_blank hs, ite_eq_left hMM] obtain ⟨hMM1, hMM2, h22⟩ := hMM constructor · intro seg hfind' @@ -1273,7 +1271,7 @@ private theorem matchLoop_go (f : VFlags) (v0 v1 v2 : Γ) (stSyms : List Γw) by_cases hs : s = Γw.blank · subst hs simp [machFind] - · rw [machFind_cons_of_ne_blank hs, if_neg hMM] + · rw [machFind_cons_of_ne_blank hs, ite_eq_right hMM] exact machFind_none_of_head_blank hrest0 refine ⟨?_, ?_⟩ · intro seg hfind' @@ -1366,7 +1364,7 @@ private theorem matchLoop_go (f : VFlags) (v0 v1 v2 : Γ) (stSyms : List Γw) rw [hwtSc₃] show (if 1 ≤ 1 ∧ 1 ≤ (c₁.work scT).head then Γ.blank else (c₁.work scT).cells 1) ≠ Γ.start - rw [if_pos ⟨Nat.le_refl _, hsch1⟩] + rw [ite_eq_left ⟨Nat.le_refl _, hsch1⟩] exact fun h => nomatch h -- rewindSt: rewind the state head obtain ⟨c₄, hr₄, hst₄, hwtS₄, hin₄, hout₄, hoth₄⟩ := @@ -1400,14 +1398,14 @@ private theorem matchLoop_go (f : VFlags) (v0 v1 v2 : Γ) (stSyms : List Γw) refine Tape.HoldsExact.nil_iff.mpr ⟨?_, ?_⟩ · show (if 1 ≤ 0 ∧ 0 ≤ (c₁.work scT).head then Γ.blank else (c₁.work scT).cells 0) = Γ.start - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] exact hsc0₁ · intro i show (if 1 ≤ i + 1 ∧ i + 1 ≤ (c₁.work scT).head then Γ.blank else (c₁.work scT).cells (i + 1)) = Γ.blank by_cases hcase : 1 ≤ i + 1 ∧ i + 1 ≤ (c₁.work scT).head - · rw [if_pos hcase] - · rw [if_neg hcase] + · rw [ite_eq_left hcase] + · rw [ite_eq_right hcase] exact hscbl₁ (i + 1) (by omega) have hschead₄ : (c₄.work scT).head = 1 := by rw [hoth₄ scT (by decide), hwtSc₃] @@ -1451,7 +1449,7 @@ private theorem matchLoop_go (f : VFlags) (v0 v1 v2 : Γ) (stSyms : List Γw) (s :: rest) = machFind stSyms.length stSyms (keyCells f v0 v1 v2) (takeField (s :: rest)).2 := by - rw [machFind_cons_of_ne_blank hs, if_neg hMM] + rw [machFind_cons_of_ne_blank hs, ite_eq_right hMM] have hpre_le : t₁ + 1 + ((c₁.work scT).head + 1) + ((c₁.work stT).head + 1) ≤ 4 * stSyms.length + (takeField (s :: rest)).1.length + 34 := by diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyMatch.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyMatch.lean index a7a37672..1c35c89d 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/BodyMatch.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/BodyMatch.lean @@ -45,9 +45,11 @@ theorem step_idle {c : Cfg 6 bodyTM.Q} (hne : c.state ≠ bodyDone) {q' : BodyQ} bodyTM.step c = some { c with state := q' } := by rw [step_mkAct hne h] refine congrArg some ?_ - simp only [Cfg.mk.injEq] - exact ⟨trivial, idle_input_id hin, funext fun i => idle_tape_id (hwk i), - idle_tape_id hout⟩ + refine Cfg.ext ?_ ?_ ?_ ?_ + · rfl + · exact idle_input_id hin + · exact funext fun i => idle_tape_id (hwk i) + · exact idle_tape_id hout /-- Writing back a non-`▷` read leaves the cells unchanged (write-only form of `tape_readBackWrite_preserves`). -/ @@ -138,25 +140,25 @@ theorem lockstep_agree_loop {cur : BodyQ} (hcur : cur ≠ bodyDone) rfl (by dsimp only - rw [if_pos rfl, + rw [ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadS'), hcS]) (by dsimp only - rw [if_pos rfl, if_neg hreadS'] + rw [ite_eq_left rfl, ite_eq_right hreadS'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadS]) (by dsimp only - rw [if_neg (by decide : dsT ≠ stT), if_pos rfl, + rw [ite_eq_right (by decide : dsT ≠ stT), ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_neg (by decide : dsT ≠ stT), if_pos rfl, if_neg hreadW'] + rw [ite_eq_right (by decide : dsT ≠ stT), ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hi hi' => by dsimp only - rw [if_neg hi, if_neg hi', idle_tape_id (hoth i hi hi')] + rw [ite_eq_right hi, ite_eq_right hi', idle_tape_id (hoth i hi hi')] exact hoth i hi hi') refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtS'] @@ -168,7 +170,7 @@ theorem lockstep_agree_loop {cur : BodyQ} (hcur : cur ≠ bodyDone) · intro i hi hi' rw [hoth' i hi hi'] show (if i = stT then _ else if i = dsT then _ else _) = _ - rw [if_neg hi, if_neg hi'] + rw [ite_eq_right hi, ite_eq_right hi'] exact idle_tape_id (hoth i hi hi') -- ════════════════════════════════════════════════════════════════════════ @@ -201,14 +203,14 @@ theorem hc1_match_loop (S W : ℕ → Γ) lockstep_agree_loop (cur := hc1) (fun hcon => nomatch hcon) (fun iH wH oH hs hd he => by have h1 : ¬(wH stT = Γ.blank ∧ wH dsT = Γ.blank) := fun hcon => hs hcon.1 - rw [arm_hc1 iH wH oH, if_neg h1, if_pos ⟨hs, hd, he⟩]) + rw [arm_hc1 iH wH oH, ite_eq_right h1, ite_eq_left ⟨hs, hd, he⟩]) S W hSns hWns n a b ha hb hagree c hst hcS hheadS hcW hheadW hin hout hoth have hreadS₁ : (c₁.work stT).read = Γ.blank := by rw [hwtS₁]; exact hSbl have hreadW₁ : (c₁.work dsT).read = Γ.blank := by rw [hwtD₁]; exact hWbl have harm := arm_hc1 c₁.input.read (fun i => (c₁.work i).read) c₁.output.read - rw [if_pos ⟨hreadS₁, hreadW₁⟩] at harm + rw [ite_eq_left ⟨hreadS₁, hreadW₁⟩] at harm have hwk₁ : ∀ i, (c₁.work i).read ≠ Γ.start := by intro i by_cases hiS : i = stT @@ -249,7 +251,7 @@ theorem hc1_mismatch_loop (S W : ℕ → Γ) lockstep_agree_loop (cur := hc1) (fun hcon => nomatch hcon) (fun iH wH oH hs hd he => by have h1 : ¬(wH stT = Γ.blank ∧ wH dsT = Γ.blank) := fun hcon => hs hcon.1 - rw [arm_hc1 iH wH oH, if_neg h1, if_pos ⟨hs, hd, he⟩]) + rw [arm_hc1 iH wH oH, ite_eq_right h1, ite_eq_left ⟨hs, hd, he⟩]) S W hSns hWns n a b ha hb hagree c hst hcS hheadS hcW hheadW hin hout hoth have hreadS₁ : (c₁.work stT).read = S (a + n) := by rw [hwtS₁]; rfl have hreadW₁ : (c₁.work dsT).read = W (b + n) := by rw [hwtD₁]; rfl @@ -259,7 +261,7 @@ theorem hc1_mismatch_loop (S W : ℕ → Γ) (c₁.work stT).read = (c₁.work dsT).read) := by rw [hreadS₁, hreadW₁]; exact hmm2 have harm := arm_hc1 c₁.input.read (fun i => (c₁.work i).read) c₁.output.read - rw [if_neg hc1', if_neg hc2'] at harm + rw [ite_eq_right hc1', ite_eq_right hc2'] at harm have hwk₁ : ∀ i, (c₁.work i).read ≠ Γ.start := by intro i by_cases hiS : i = stT @@ -304,12 +306,12 @@ theorem cmpQ_match_loop (f : VFlags) (S W : ℕ → Γ) obtain ⟨c₁, hreach₁, hst₁, hwtS₁, hwtD₁, hin₁, hout₁, hoth₁⟩ := lockstep_agree_loop (cur := cmpQ f) (fun hcon => nomatch hcon) (fun iH wH oH hs hd he => by - rw [arm_cmpQ iH wH oH f, if_neg hs, if_pos ⟨hd, he⟩]) + rw [arm_cmpQ iH wH oH f, ite_eq_right hs, ite_eq_left ⟨hd, he⟩]) S W hSns hWns n a b ha hb hagree c hst hcS hheadS hcW hheadW hin hout hoth have hreadS₁ : (c₁.work stT).read = Γ.blank := by rw [hwtS₁]; exact hSbl have hreadW₁ : (c₁.work dsT).read = W (b + n) := by rw [hwtD₁]; rfl have harm := arm_cmpQ c₁.input.read (fun i => (c₁.work i).read) c₁.output.read f - rw [if_pos hreadS₁] at harm + rw [ite_eq_left hreadS₁] at harm have hwk₁ : ∀ i, (c₁.work i).read ≠ Γ.start := by intro i by_cases hiS : i = stT @@ -350,7 +352,7 @@ theorem cmpQ_mismatch_loop (f : VFlags) (S W : ℕ → Γ) obtain ⟨c₁, hreach₁, hst₁, hwtS₁, hwtD₁, hin₁, hout₁, hoth₁⟩ := lockstep_agree_loop (cur := cmpQ f) (fun hcon => nomatch hcon) (fun iH wH oH hs hd he => by - rw [arm_cmpQ iH wH oH f, if_neg hs, if_pos ⟨hd, he⟩]) + rw [arm_cmpQ iH wH oH f, ite_eq_right hs, ite_eq_left ⟨hd, he⟩]) S W hSns hWns n a b ha hb hagree c hst hcS hheadS hcW hheadW hin hout hoth have hreadS₁ : (c₁.work stT).read = S (a + n) := by rw [hwtS₁]; rfl have hreadW₁ : (c₁.work dsT).read = W (b + n) := by rw [hwtD₁]; rfl @@ -359,7 +361,7 @@ theorem cmpQ_mismatch_loop (f : VFlags) (S W : ℕ → Γ) (c₁.work stT).read = (c₁.work dsT).read) := by rw [hreadS₁, hreadW₁]; exact hmm have harm := arm_cmpQ c₁.input.read (fun i => (c₁.work i).read) c₁.output.read f - rw [if_neg hc1', if_neg hc2'] at harm + rw [ite_eq_right hc1', ite_eq_right hc2'] at harm have hwk₁ : ∀ i, (c₁.work i).read ≠ Γ.start := by intro i by_cases hiS : i = stT @@ -419,21 +421,21 @@ theorem cmpS_match_loop (f : VFlags) (v0 v1 v2 : Γ) (W V : ℕ → Γ) (c.work dsT).read ≠ Γ.blank := by rw [hv0, hv1, hv2, hreadW]; exact h0 have harm := arm_cmpS c.input.read (fun i => (c.work i).read) c.output.read f idx - rw [if_pos hcond, dif_neg (show ¬idx.val < 5 by omega)] at harm + rw [ite_eq_left hcond, dite_eq_right (show ¬idx.val < 5 by omega)] at harm have hstep := step_act2 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, ?_, idle_input_id hin, idle_tape_id hout, ?_⟩ · show (c.work stT).writeAndMove _ _ = (⟨a - 1, V⟩ : Tape) - rw [if_neg hreadS'] + rw [ite_eq_right hreadS'] simp only [Tape.writeAndMove, Tape.move, Tape.mk.injEq, Tape.write_head] exact ⟨by omega, by rw [write_readBack_cells hreadS', hcV]⟩ · show (c.work dsT).writeAndMove _ _ = (⟨b + 0 + 1, W⟩ : Tape) - rw [if_neg hreadW'] + rw [ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.mk.injEq, Tape.write_head] exact ⟨by omega, by rw [write_readBack_cells hreadW', hcW]⟩ · intro i hiS hiD show (if i = dsT then _ else if i = stT then _ else _) = _ - rw [if_neg hiD, if_neg hiS] + rw [ite_eq_right hiD, ite_eq_right hiS] exact idle_tape_id (hoth i hiS hiD) | succ k ih => intro idx hk a b ha hb hkey c hst hv0 hv1 hv2 hcV hheadV hcW hheadW hin hout hoth @@ -448,7 +450,7 @@ theorem cmpS_match_loop (f : VFlags) (v0 v1 v2 : Γ) (W V : ℕ → Γ) (c.work dsT).read ≠ Γ.blank := by rw [hv0, hv1, hv2, hreadW]; exact h0 have harm := arm_cmpS c.input.read (fun i => (c.work i).read) c.output.read f idx - rw [if_pos hcond, dif_pos (show idx.val < 5 by omega)] at harm + rw [ite_eq_left hcond, dite_eq_left (show idx.val < 5 by omega)] at harm have hstep := step_act1 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) obtain ⟨c', hreach, hst', hwtS', hwtD', hin', hout', hoth'⟩ := @@ -474,28 +476,28 @@ theorem cmpS_match_loop (f : VFlags) (v0 v1 v2 : Γ) (W V : ℕ → Γ) (idleDir c.output.read) } rfl (by dsimp only - rw [if_neg (by decide : vIn ≠ dsT), + rw [ite_eq_right (by decide : vIn ≠ dsT), idle_tape_id (hoth vIn (by decide) (by decide)), hv0]) (by dsimp only - rw [if_neg (by decide : vWk ≠ dsT), + rw [ite_eq_right (by decide : vWk ≠ dsT), idle_tape_id (hoth vWk (by decide) (by decide)), hv1]) (by dsimp only - rw [if_neg (by decide : vOut ≠ dsT), + rw [ite_eq_right (by decide : vOut ≠ dsT), idle_tape_id (hoth vOut (by decide) (by decide)), hv2]) (by dsimp only - rw [if_neg (by decide : stT ≠ dsT), idle_tape_id hreadS', hcV]) + rw [ite_eq_right (by decide : stT ≠ dsT), idle_tape_id hreadS', hcV]) (by dsimp only - rw [if_neg (by decide : stT ≠ dsT), idle_tape_id hreadS', hheadV]) + rw [ite_eq_right (by decide : stT ≠ dsT), idle_tape_id hreadS', hheadV]) (by dsimp only - rw [if_pos rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) + rw [ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_pos rfl, if_neg hreadW'] + rw [ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hiS hiD => by dsimp only - rw [if_neg hiD, idle_tape_id (hoth i hiS hiD)] + rw [ite_eq_right hiD, idle_tape_id (hoth i hiS hiD)] exact hoth i hiS hiD) refine ⟨c', .step hstep hreach, hst', hwtS', ?_, ?_, ?_, ?_⟩ · rw [hwtD'] @@ -505,7 +507,7 @@ theorem cmpS_match_loop (f : VFlags) (v0 v1 v2 : Γ) (W V : ℕ → Γ) · intro i hiS hiD rw [hoth' i hiS hiD] show (if i = dsT then _ else _) = _ - rw [if_neg hiD] + rw [ite_eq_right hiD] exact idle_tape_id (hoth i hiS hiD) /-- **Key-symbol compare, mismatch case**: from `cmpS f idx` with the desc @@ -545,7 +547,7 @@ theorem cmpS_mismatch_loop (f : VFlags) (v0 v1 v2 : Γ) (W : ℕ → Γ) (c.work dsT).read ≠ Γ.blank) := by rw [hv0, hv1, hv2, hreadW]; exact hMM' have harm := arm_cmpS c.input.read (fun i => (c.work i).read) c.output.read f idx - rw [if_neg hcond] at harm + rw [ite_eq_right hcond] at harm have hwk : ∀ i, (c.work i).read ≠ Γ.start := by intro i by_cases hiD : i = dsT @@ -567,7 +569,7 @@ theorem cmpS_mismatch_loop (f : VFlags) (v0 v1 v2 : Γ) (W : ℕ → Γ) (c.work dsT).read ≠ Γ.blank := by rw [hv0, hv1, hv2, hreadW]; exact h0 have harm := arm_cmpS c.input.read (fun i => (c.work i).read) c.output.read f idx - rw [if_pos hcond, dif_pos (show idx.val < 5 by omega)] at harm + rw [ite_eq_left hcond, dite_eq_left (show idx.val < 5 by omega)] at harm have hstep := step_act1 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) obtain ⟨c', hreach, hst', hwtD', hin', hout', hoth'⟩ := @@ -601,24 +603,24 @@ theorem cmpS_mismatch_loop (f : VFlags) (v0 v1 v2 : Γ) (W : ℕ → Γ) (idleDir c.output.read) } rfl (by dsimp only - rw [if_neg (by decide : vIn ≠ dsT), + rw [ite_eq_right (by decide : vIn ≠ dsT), idle_tape_id (hoth vIn (by decide)), hv0]) (by dsimp only - rw [if_neg (by decide : vWk ≠ dsT), + rw [ite_eq_right (by decide : vWk ≠ dsT), idle_tape_id (hoth vWk (by decide)), hv1]) (by dsimp only - rw [if_neg (by decide : vOut ≠ dsT), + rw [ite_eq_right (by decide : vOut ≠ dsT), idle_tape_id (hoth vOut (by decide)), hv2]) (by dsimp only - rw [if_pos rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) + rw [ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_pos rfl, if_neg hreadW'] + rw [ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hiD => by dsimp only - rw [if_neg hiD, idle_tape_id (hoth i hiD)] + rw [ite_eq_right hiD, idle_tape_id (hoth i hiD)] exact hoth i hiD) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_⟩ · rw [hwtD'] @@ -628,7 +630,7 @@ theorem cmpS_mismatch_loop (f : VFlags) (v0 v1 v2 : Γ) (W : ℕ → Γ) · intro i hiD rw [hoth' i hiD] show (if i = dsT then _ else _) = _ - rw [if_neg hiD] + rw [ite_eq_right hiD] exact idle_tape_id (hoth i hiD) -- ════════════════════════════════════════════════════════════════════════ @@ -674,17 +676,17 @@ theorem copyQ'_copy_loop (f : VFlags) (S W : ℕ → Γ) have hreadE' : (c.work scT).read ≠ Γ.start := by simp only [Tape.read, hheadE, hcE]; exact hE e he have harm := arm_copyQ' c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_pos hreadS] at harm + rw [ite_eq_left hreadS] at harm have hstep := step_act1 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, ?_, ?_, idle_input_id hin, idle_tape_id hout, ?_⟩ · show (c.work stT).writeAndMove _ _ = (⟨1, S⟩ : Tape) - rw [if_pos hreadS] + rw [ite_eq_left hreadS] have hwr : (c.work stT).write (readBackWrite ((c.work stT).read)).toΓ = c.work stT := by unfold Tape.write - rw [if_pos hheadS] + rw [ite_eq_left hheadS] show ((c.work stT).write _).move .right = _ rw [hwr] simp only [Tape.move, Tape.mk.injEq] @@ -696,11 +698,11 @@ theorem copyQ'_copy_loop (f : VFlags) (S W : ℕ → Γ) rw [idle_tape_id hreadE'] have hEmpty : (fun j => if e ≤ j ∧ j < e + 0 then W (b + (j - e)) else E j) = E := by - funext j; rw [if_neg (by omega)] + funext j; rw [ite_eq_right (by omega)] rw [hEmpty, ← hcE, show e + 0 = (c.work scT).head from by omega] · intro i hiS hiD hiE show (if i = stT then _ else _) = _ - rw [if_neg hiS] + rw [ite_eq_right hiS] exact idle_tape_id (hoth i hiS hiD hiE) | succ s ih => intro E hE b e hb he hnb c hst hcS hheadS hcW hheadW hcE hheadE hin hout hoth @@ -718,7 +720,7 @@ theorem copyQ'_copy_loop (f : VFlags) (S W : ℕ → Γ) have hWb : (readBackWrite ((c.work dsT).read)).toΓ = W b := by rw [toΓ_readBackWrite_of_ne_start hreadW', hreadW] have harm := arm_copyQ' c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_neg hreadS', if_neg hreadWnb] at harm + rw [ite_eq_right hreadS', ite_eq_right hreadWnb] at harm have hstep := step_act3 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) have hEupd : ∀ j, 1 ≤ j → Function.update E e (W b) j ≠ Γ.start := by @@ -751,39 +753,40 @@ theorem copyQ'_copy_loop (f : VFlags) (S W : ℕ → Γ) (idleDir c.output.read) } rfl (by dsimp only - rw [if_neg (by decide : stT ≠ scT), if_neg (by decide : stT ≠ dsT), - if_pos rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadS'), hcS]) + rw [ite_eq_right (by decide : stT ≠ scT), ite_eq_right (by decide : stT ≠ dsT), + ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadS'), hcS]) (by dsimp only - rw [if_neg (by decide : stT ≠ scT), if_neg (by decide : stT ≠ dsT), - if_pos rfl, if_neg hreadS'] + rw [ite_eq_right (by decide : stT ≠ scT), ite_eq_right (by decide : stT ≠ dsT), + ite_eq_left rfl, ite_eq_right hreadS'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadS] omega) (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, if_neg hreadW'] + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] show (((c.work scT).write _).move Dir3.right).cells = _ have hw : (c.work scT).write (readBackWrite ((c.work dsT).read)).toΓ = { c.work scT with cells := Function.update (c.work scT).cells (c.work scT).head (readBackWrite ((c.work dsT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work scT).cells (c.work scT).head _ = _ rw [hcE, hheadE, hWb]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadE]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hiS hiD hiE => by dsimp only - rw [if_neg hiE, if_neg hiD, if_neg hiS, idle_tape_id (hoth i hiS hiD hiE)] + rw [ite_eq_right hiE, ite_eq_right hiD, ite_eq_right hiS, + idle_tape_id (hoth i hiS hiD hiE)] exact hoth i hiS hiD hiE) refine ⟨c', .step hstep hreach, hst', hwtS', ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtD'] @@ -793,20 +796,20 @@ theorem copyQ'_copy_loop (f : VFlags) (S W : ℕ → Γ) refine ⟨by omega, ?_⟩ funext j by_cases hj1 : e + 1 ≤ j ∧ j < e + 1 + s - · rw [if_pos hj1, if_pos (by omega)] + · rw [ite_eq_left hj1, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [if_neg hj1] + · rw [ite_eq_right hj1] by_cases hje : j = e · subst hje - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [Function.update_of_ne hje, if_neg (by omega)] + · rw [Function.update_of_ne hje, ite_eq_right (by omega)] · rw [hin']; exact idle_input_id hin · rw [hout']; exact idle_tape_id hout · intro i hiS hiD hiE rw [hoth' i hiS hiD hiE] show (if i = scT then _ else if i = dsT then _ else if i = stT then _ else _) = _ - rw [if_neg hiE, if_neg hiD, if_neg hiS] + rw [ite_eq_right hiE, ite_eq_right hiD, ite_eq_right hiS] exact idle_tape_id (hoth i hiS hiD hiE) /-- **q'-field copy, early-`□` case**: from `copyQ' f` counting down from @@ -849,7 +852,7 @@ theorem copyQ'_blank_loop (f : VFlags) (S W : ℕ → Γ) have hreadE' : (c.work scT).read ≠ Γ.start := by simp only [Tape.read, hheadE, hcE]; exact hE e he have harm := arm_copyQ' c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_neg hreadS', if_pos hreadWbl] at harm + rw [ite_eq_right hreadS', ite_eq_left hreadWbl] at harm have hwk : ∀ i, (c.work i).read ≠ Γ.start := by intro i by_cases hiS : i = stT @@ -866,7 +869,7 @@ theorem copyQ'_blank_loop (f : VFlags) (S W : ℕ → Γ) · rw [← hcW, show b + 0 = (c.work dsT).head from by omega] · have hEmpty : (fun j => if e ≤ j ∧ j < e + 0 then W (b + (j - e)) else E j) = E := by - funext j; rw [if_neg (by omega)] + funext j; rw [ite_eq_right (by omega)] rw [hEmpty, ← hcE, show e + 0 = (c.work scT).head from by omega] | succ n ih => intro E hE s b e hns hb he hnb hbl c hst hcS hheadS hcW hheadW hcE hheadE @@ -884,7 +887,7 @@ theorem copyQ'_blank_loop (f : VFlags) (S W : ℕ → Γ) have hWb : (readBackWrite ((c.work dsT).read)).toΓ = W b := by rw [toΓ_readBackWrite_of_ne_start hreadW', hreadW] have harm := arm_copyQ' c.input.read (fun i => (c.work i).read) c.output.read f - rw [if_neg hreadS', if_neg hreadWnb] at harm + rw [ite_eq_right hreadS', ite_eq_right hreadWnb] at harm have hstep := step_act3 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) have hEupd : ∀ j, 1 ≤ j → Function.update E e (W b) j ≠ Γ.start := by @@ -922,38 +925,39 @@ theorem copyQ'_blank_loop (f : VFlags) (S W : ℕ → Γ) (idleDir c.output.read) } rfl (by dsimp only - rw [if_neg (by decide : stT ≠ scT), if_neg (by decide : stT ≠ dsT), - if_pos rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadS'), hcS]) + rw [ite_eq_right (by decide : stT ≠ scT), ite_eq_right (by decide : stT ≠ dsT), + ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadS'), hcS]) (by dsimp only - rw [if_neg (by decide : stT ≠ scT), if_neg (by decide : stT ≠ dsT), - if_pos rfl, if_neg hreadS'] + rw [ite_eq_right (by decide : stT ≠ scT), ite_eq_right (by decide : stT ≠ dsT), + ite_eq_left rfl, ite_eq_right hreadS'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadS]) (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, if_neg hreadW'] + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] show (((c.work scT).write _).move Dir3.right).cells = _ have hw : (c.work scT).write (readBackWrite ((c.work dsT).read)).toΓ = { c.work scT with cells := Function.update (c.work scT).cells (c.work scT).head (readBackWrite ((c.work dsT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work scT).cells (c.work scT).head _ = _ rw [hcE, hheadE, hWb]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadE]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hiS hiD hiE => by dsimp only - rw [if_neg hiE, if_neg hiD, if_neg hiS, idle_tape_id (hoth i hiS hiD hiE)] + rw [ite_eq_right hiE, ite_eq_right hiD, ite_eq_right hiS, + idle_tape_id (hoth i hiS hiD hiE)] exact hoth i hiS hiD hiE) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtS'] @@ -965,20 +969,20 @@ theorem copyQ'_blank_loop (f : VFlags) (S W : ℕ → Γ) refine ⟨by omega, ?_⟩ funext j by_cases hj1 : e + 1 ≤ j ∧ j < e + 1 + n - · rw [if_pos hj1, if_pos (by omega)] + · rw [ite_eq_left hj1, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [if_neg hj1] + · rw [ite_eq_right hj1] by_cases hje : j = e · subst hje - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [Function.update_of_ne hje, if_neg (by omega)] + · rw [Function.update_of_ne hje, ite_eq_right (by omega)] · rw [hin']; exact idle_input_id hin · rw [hout']; exact idle_tape_id hout · intro i hiS hiD hiE rw [hoth' i hiS hiD hiE] show (if i = scT then _ else if i = dsT then _ else if i = stT then _ else _) = _ - rw [if_neg hiE, if_neg hiD, if_neg hiS] + rw [ite_eq_right hiE, ite_eq_right hiD, ite_eq_right hiS] exact idle_tape_id (hoth i hiS hiD hiE) -- ════════════════════════════════════════════════════════════════════════ @@ -1025,24 +1029,24 @@ theorem copyAct_copy_loop (f : VFlags) (W : ℕ → Γ) have hWb : (readBackWrite ((c.work dsT).read)).toΓ = W b := by rw [toΓ_readBackWrite_of_ne_start hreadW', hreadW] have harm := arm_copyAct c.input.read (fun i => (c.work i).read) c.output.read f j - rw [if_neg hreadWnb, dif_neg (show ¬j.val < 9 by omega)] at harm + rw [ite_eq_right hreadWnb, dite_eq_right (show ¬j.val < 9 by omega)] at harm have hstep := step_act2 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) refine ⟨_, .step hstep .zero, rfl, ?_, ?_, idle_input_id hin, idle_tape_id hout, ?_⟩ · show (c.work dsT).writeAndMove _ _ = (⟨b + 0 + 1, W⟩ : Tape) - rw [if_neg hreadW'] + rw [ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.mk.injEq, Tape.write_head] exact ⟨by omega, by rw [write_readBack_cells hreadW', hcW]⟩ · show (c.work scT).writeAndMove _ _ = _ - rw [if_neg hreadE'] + rw [ite_eq_right hreadE'] show ((c.work scT).write _).move .right = _ have hw : (c.work scT).write (readBackWrite ((c.work dsT).read)).toΓ = { c.work scT with cells := Function.update (c.work scT).cells (c.work scT).head (readBackWrite ((c.work dsT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] simp only [Tape.move, Tape.mk.injEq] refine ⟨by omega, ?_⟩ @@ -1051,12 +1055,12 @@ theorem copyAct_copy_loop (f : VFlags) (W : ℕ → Γ) funext i by_cases hie : i = e · subst hie - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [Function.update_of_ne hie, if_neg (by omega)] + · rw [Function.update_of_ne hie, ite_eq_right (by omega)] · intro i hiD hiE show (if i = scT then _ else if i = dsT then _ else _) = _ - rw [if_neg hiE, if_neg hiD] + rw [ite_eq_right hiE, ite_eq_right hiD] exact idle_tape_id (hoth i hiD hiE) | succ k ih => intro j hk E hE b e hb he hnb c hst hcW hheadW hcE hheadE hin hout hoth @@ -1070,7 +1074,7 @@ theorem copyAct_copy_loop (f : VFlags) (W : ℕ → Γ) have hWb : (readBackWrite ((c.work dsT).read)).toΓ = W b := by rw [toΓ_readBackWrite_of_ne_start hreadW', hreadW] have harm := arm_copyAct c.input.read (fun i => (c.work i).read) c.output.read f j - rw [if_neg hreadWnb, dif_pos (show j.val < 9 by omega)] at harm + rw [ite_eq_right hreadWnb, dite_eq_left (show j.val < 9 by omega)] at harm have hstep := step_act2 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) have hEupd : ∀ i, 1 ≤ i → Function.update E e (W b) i ≠ Γ.start := by @@ -1101,31 +1105,31 @@ theorem copyAct_copy_loop (f : VFlags) (W : ℕ → Γ) (idleDir c.output.read) } rfl (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, if_neg hreadW'] + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] show (((c.work scT).write _).move Dir3.right).cells = _ have hw : (c.work scT).write (readBackWrite ((c.work dsT).read)).toΓ = { c.work scT with cells := Function.update (c.work scT).cells (c.work scT).head (readBackWrite ((c.work dsT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work scT).cells (c.work scT).head _ = _ rw [hcE, hheadE, hWb]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadE]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hiD hiE => by dsimp only - rw [if_neg hiE, if_neg hiD, idle_tape_id (hoth i hiD hiE)] + rw [ite_eq_right hiE, ite_eq_right hiD, idle_tape_id (hoth i hiD hiE)] exact hoth i hiD hiE) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtD'] @@ -1135,20 +1139,20 @@ theorem copyAct_copy_loop (f : VFlags) (W : ℕ → Γ) refine ⟨by omega, ?_⟩ funext i by_cases hi1 : e + 1 ≤ i ∧ i < e + 1 + k + 1 - · rw [if_pos hi1, if_pos (by omega)] + · rw [ite_eq_left hi1, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [if_neg hi1] + · rw [ite_eq_right hi1] by_cases hie : i = e · subst hie - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [Function.update_of_ne hie, if_neg (by omega)] + · rw [Function.update_of_ne hie, ite_eq_right (by omega)] · rw [hin']; exact idle_input_id hin · rw [hout']; exact idle_tape_id hout · intro i hiD hiE rw [hoth' i hiD hiE] show (if i = scT then _ else if i = dsT then _ else _) = _ - rw [if_neg hiE, if_neg hiD] + rw [ite_eq_right hiE, ite_eq_right hiD] exact idle_tape_id (hoth i hiD hiE) /-- **Action-cell copy, early-`□` case**: from `copyAct f j`, the desc tape @@ -1186,7 +1190,7 @@ theorem copyAct_blank_loop (f : VFlags) (W : ℕ → Γ) have hreadE' : (c.work scT).read ≠ Γ.start := by simp only [Tape.read, hheadE, hcE]; exact hE e he have harm := arm_copyAct c.input.read (fun i => (c.work i).read) c.output.read f j - rw [if_pos hreadWbl] at harm + rw [ite_eq_left hreadWbl] at harm have hwk : ∀ i, (c.work i).read ≠ Γ.start := by intro i by_cases hiD : i = dsT @@ -1200,7 +1204,7 @@ theorem copyAct_blank_loop (f : VFlags) (W : ℕ → Γ) · rw [← hcW, show b + 0 = (c.work dsT).head from by omega] · have hEmpty : (fun i => if e ≤ i ∧ i < e + 0 then W (b + (i - e)) else E i) = E := by - funext i; rw [if_neg (by omega)] + funext i; rw [ite_eq_right (by omega)] rw [hEmpty, ← hcE, show e + 0 = (c.work scT).head from by omega] | succ n ih => intro j hn E hE b e hb he hnb hbl c hst hcW hheadW hcE hheadE hin hout hoth @@ -1214,7 +1218,7 @@ theorem copyAct_blank_loop (f : VFlags) (W : ℕ → Γ) have hWb : (readBackWrite ((c.work dsT).read)).toΓ = W b := by rw [toΓ_readBackWrite_of_ne_start hreadW', hreadW] have harm := arm_copyAct c.input.read (fun i => (c.work i).read) c.output.read f j - rw [if_neg hreadWnb, dif_pos (show j.val < 9 by omega)] at harm + rw [ite_eq_right hreadWnb, dite_eq_left (show j.val < 9 by omega)] at harm have hstep := step_act2 (by rw [hst]; exact fun hcon => nomatch hcon) (by rw [hst]; exact harm) have hEupd : ∀ i, 1 ≤ i → Function.update E e (W b) i ≠ Γ.start := by @@ -1249,31 +1253,31 @@ theorem copyAct_blank_loop (f : VFlags) (W : ℕ → Γ) (idleDir c.output.read) } rfl (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, tape_readBackWrite_preserves _ _ (Or.inr hreadW'), hcW]) (by dsimp only - rw [if_neg (by decide : dsT ≠ scT), if_pos rfl, if_neg hreadW'] + rw [ite_eq_right (by decide : dsT ≠ scT), ite_eq_left rfl, ite_eq_right hreadW'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadW]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] show (((c.work scT).write _).move Dir3.right).cells = _ have hw : (c.work scT).write (readBackWrite ((c.work dsT).read)).toΓ = { c.work scT with cells := Function.update (c.work scT).cells (c.work scT).head (readBackWrite ((c.work dsT).read)).toΓ } := by unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] rw [hw] show Function.update (c.work scT).cells (c.work scT).head _ = _ rw [hcE, hheadE, hWb]) (by dsimp only - rw [if_pos rfl, if_neg hreadE'] + rw [ite_eq_left rfl, ite_eq_right hreadE'] simp only [Tape.writeAndMove, Tape.move, Tape.write_head, hheadE]) (by dsimp only; rw [idle_input_id hin]; exact hin) (by dsimp only; rw [idle_tape_id hout]; exact hout) (fun i hiD hiE => by dsimp only - rw [if_neg hiE, if_neg hiD, idle_tape_id (hoth i hiD hiE)] + rw [ite_eq_right hiE, ite_eq_right hiD, idle_tape_id (hoth i hiD hiE)] exact hoth i hiD hiE) refine ⟨c', .step hstep hreach, hst', ?_, ?_, ?_, ?_, ?_⟩ · rw [hwtD'] @@ -1283,20 +1287,20 @@ theorem copyAct_blank_loop (f : VFlags) (W : ℕ → Γ) refine ⟨by omega, ?_⟩ funext i by_cases hi1 : e + 1 ≤ i ∧ i < e + 1 + n - · rw [if_pos hi1, if_pos (by omega)] + · rw [ite_eq_left hi1, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [if_neg hi1] + · rw [ite_eq_right hi1] by_cases hie : i = e · subst hie - rw [Function.update_self, if_pos (by omega)] + rw [Function.update_self, ite_eq_left (by omega)] exact congrArg W (by omega) - · rw [Function.update_of_ne hie, if_neg (by omega)] + · rw [Function.update_of_ne hie, ite_eq_right (by omega)] · rw [hin']; exact idle_input_id hin · rw [hout']; exact idle_tape_id hout · intro i hiD hiE rw [hoth' i hiD hiE] show (if i = scT then _ else if i = dsT then _ else _) = _ - rw [if_neg hiE, if_neg hiD] + rw [ite_eq_right hiE, ite_eq_right hiD] exact idle_tape_id (hoth i hiD hiE) end TM.UTMBody diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/ClockFrontier.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/ClockFrontier.lean index 87e2099d..3e8845b9 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/ClockFrontier.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/ClockFrontier.lean @@ -111,7 +111,7 @@ def decFrontierTM : TM 7 where dsimp only [] by_cases hir : i = clkT · subst hir; rw [hone] at hi; exact absurd hi (by decide) - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · exact ⟨idleDir_right_of_start, fun _ => idleDir_right_of_start, idleDir_right_of_start⟩ | .settle => @@ -139,7 +139,7 @@ private theorem decFrontier_step_dec_one (c : Cfg 7 decFrontierTM.Q) work := Function.update c.work clkT (((c.work clkT).write Γw.blank).move .left), output := c.output } := by - rw [TM.step, if_neg (decFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decFrontier_ne_halt (by decide) hst)] simp only [decFrontierTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -147,7 +147,7 @@ private theorem decFrontier_step_dec_one (c : Cfg 7 decFrontierTM.Q) by_cases hir : i = clkT · subst hir simp only [↓reduceIte, Function.update_self] - · rw [if_neg hir, if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -160,7 +160,7 @@ private theorem decFrontier_step_dec_blank (c : Cfg 7 decFrontierTM.Q) decFrontierTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (decFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decFrontier_ne_halt (by decide) hst)] simp only [decFrontierTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -180,7 +180,7 @@ private theorem decFrontier_step_settle_stay (c : Cfg 7 decFrontierTM.Q) decFrontierTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (decFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decFrontier_ne_halt (by decide) hst)] simp only [decFrontierTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -202,7 +202,7 @@ private theorem decFrontier_step_settle_start (c : Cfg 7 decFrontierTM.Q) have h0 : (c.work clkT).head = 0 := by by_contra hc exact hcr _ (by omega) hs - rw [TM.step, if_neg (decFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (decFrontier_ne_halt (by decide) hst)] simp only [decFrontierTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -216,7 +216,7 @@ private theorem decFrontier_step_settle_start (c : Cfg 7 decFrontierTM.Q) show ((c.work clkT).write Γw.blank).move Dir3.right = (c.work clkT).move .right congr 1 - rw [Tape.write, if_pos h0] + rw [Tape.write, ite_eq_left h0] · rw [Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -266,7 +266,7 @@ theorem decFrontierTM_hoareTime (v : ℕ) (inp₀ : Tape) (work₀ : Fin 7 → T set t₁ : Tape := ((work clkT).write Γw.blank).move .left have ht₁cells : t₁.cells = regCells (v - 1) := by show ((work clkT).write Γw.blank).cells = _ - rw [Tape.write, if_neg (show ¬ (work clkT).head = 0 by rw [hhead]; omega)] + rw [Tape.write, ite_eq_right (show ¬ (work clkT).head = 0 by rw [hhead]; omega)] show Function.update (work clkT).cells (work clkT).head Γw.blank.toΓ = _ rw [hclk, hhead] exact regCells_update hv @@ -390,16 +390,16 @@ private theorem orZero_step (c : Cfg 7 orZeroTM.Q) cells := Function.update c.output.cells c.output.head ((if c.output.read = Γ.one ∨ (c.work clkT).read = Γ.blank then Γw.one else Γw.zero) : Γw).toΓ } } := by - rw [TM.step, if_neg (orZero_ne_halt hst)] + rw [TM.step, ite_eq_right (orZero_ne_halt hst)] simp only [orZeroTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp · funext i exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hall i) · show c.output.writeAndMove _ (idleDir c.output.read) = _ - rw [idleDir, if_neg hor] + rw [idleDir, ite_eq_right hor] show c.output.write _ = _ - rw [Tape.write, if_neg hh0] + rw [Tape.write, ite_eq_right hh0] /-- **`orZeroTM` specification** (ghost-initial-tapes style). Starting from `qstart` with the clock tape (`clkT` = work tape 6) holding `regCells v` @@ -431,9 +431,9 @@ theorem orZeroTM_hoareTime (v : ℕ) (verdict : Γ) (inp₀ : Tape) have hclkread : (work clkT).read = (if v = 0 then Γ.blank else Γ.one) := by rw [Tape.read, hclkh, hclk] rcases Nat.eq_zero_or_pos v with rfl | hv - · rw [if_pos rfl] + · rw [ite_eq_left rfl] exact regCells_blank (le_max_right 0 1) - · rw [if_neg (by omega), max_eq_left hv] + · rw [ite_eq_right (by omega), max_eq_left hv] exact regCells_one hv le_rfl have hclkns : (work clkT).read ≠ Γ.start := by rw [hclkread]; split <;> decide diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/Desc.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/Desc.lean index d69a0c0a..97a0e04d 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/Desc.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/Desc.lean @@ -411,7 +411,7 @@ theorem parseEntry_syms {w : ℕ} {e : DescEntry} have hq_len : (Nat.toBits w e.q).length = w := Nat.length_toBits .. have hq'_len : (Nat.toBits w e.act.q').length = w := Nat.length_toBits .. simp only [parseEntry, hbits] - rw [if_neg (by + rw [ite_eq_right (by simp [Nat.length_toBits, Γ.length_encode, Γw.length_encode, Dir3.length_encode] omega)] rw [List.take_left' hq_len, List.drop_left' hq_len, @@ -496,7 +496,7 @@ theorem decodeDesc_encodeDesc_append {d : TMDesc} (hd : d.WF) (junk : List Bool) takeField_append (fun s hs => bitsToSyms_ne_blank hs)] dsimp only rw [takeField_append (fun s hs => bitsToSyms_ne_blank hs)] - simp only [hlen_s, hlen_h, if_true, + simp only [hlen_s, hlen_h, ite_true, fieldNat_bitsToSyms_toBits hd.qstart_lt, fieldNat_bitsToSyms_toBits hd.qhalt_lt, parseEntries_syms hd.entries_q_lt hd.entries_q'_lt] diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/Extract.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/Extract.lean index 84413b1b..86c40ecb 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/Extract.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/Extract.lean @@ -315,7 +315,7 @@ private theorem extractTM_copy_loop rw [hw i hne]; exact transitionTape_eq_self (hothers i hne) · dsimp only [] simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, hohead] - rw [if_neg (show ¬(j + 1 = 0) by omega)] + rw [ite_eq_right (show ¬(j + 1 = 0) by omega)] dsimp only [] simp [readBackWrite] obtain ⟨c₁, hstep', hst1, hc1, hin1, hw1, hout1⟩ := hstep @@ -361,7 +361,7 @@ private theorem extractTM_copy_loop omega · dsimp only [] simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, hohead] - rw [if_neg (show ¬(j + 1 = 0) by omega)] + rw [ite_eq_right (show ¬(j + 1 = 0) by omega)] dsimp only [] rw [hread, toΓ_readBackWrite_of_ne_start (hWns (j + 2) (by omega))] obtain ⟨c₁, hstep', hst1, hc1, hh1, hin1, hw1, hoh1, hoc1⟩ := hstep diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/HaltTest.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/HaltTest.lean index f9a0d55d..5b8d5ea7 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/HaltTest.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/HaltTest.lean @@ -194,12 +194,12 @@ def haltTestTM : TM 6 where | .rewindSt => refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ intro i hwi; dsimp only []; split - · rename_i heq; subst heq; rw [if_pos hwi] + · rename_i heq; subst heq; rw [ite_eq_left hwi] · exact idleDir_right_of_start hwi | .rewindD => refine ⟨idleDir_right_of_start, ?_, idleDir_right_of_start⟩ intro i hwi; dsimp only []; split - · rename_i heq; subst heq; rw [if_pos hwi] + · rename_i heq; subst heq; rw [ite_eq_left hwi] · exact idleDir_right_of_start hwi | .done => exact rightOfStart_allIdle iHead wHeads oHead @@ -392,14 +392,14 @@ private theorem skip_loop (f : List Γw) (hf : ∀ s ∈ f, s ≠ Γw.blank) : refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin · intro i hne; dsimp only [] - rw [if_neg hne] + rw [ite_eq_right hne] exact tape_idle_fix _ (hothers i hne) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inr hread_ns) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head] obtain ⟨c₁, hstep', hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ := hstep exact ⟨c₁, .step hstep' .zero, hst₁, hin₁, hw₁, hout₁, hcells₁, @@ -425,14 +425,14 @@ private theorem skip_loop (f : List Γw) (hf : ∀ s ∈ f, s ≠ Γw.blank) : refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin · intro i hne; dsimp only [] - rw [if_neg hne] + rw [ite_eq_right hne] exact tape_idle_fix _ (hothers i hne) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inr hread_ns) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head] obtain ⟨c₁, hstep', hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ := hstep obtain ⟨c', hreach, hst', hin', hw', hout', hcells', hhead'⟩ := @@ -536,20 +536,20 @@ private theorem compare_advance_step (c : Cfg 6 haltTestTM.Q) · exact input_idle_fix c.input hin · intro i h3i h4i dsimp only [] - rw [if_neg h3i, if_neg h4i] + rw [ite_eq_right h3i, ite_eq_right h4i] exact tape_idle_fix _ (hoth i h3i h4i) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inr h3) · dsimp only [] - rw [if_neg (by decide : (4 : Fin 6) ≠ 3), if_pos rfl] + rw [ite_eq_right (by decide : (4 : Fin 6) ≠ 3), ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inr h4) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head] · dsimp only [] - rw [if_neg (by decide : (4 : Fin 6) ≠ 3), if_pos rfl] + rw [ite_eq_right (by decide : (4 : Fin 6) ≠ 3), ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head] /-- The lockstep compare loop: with blank-free `A` under the state head @@ -598,7 +598,7 @@ private theorem compare_loop : rw [hw₁] <;> omega | cons b B' => have hr4 : (c.work 4).read = (b).toΓ := by - rw [Tape.read, hh4]; simpa using hc4 0 (by simp) + rw [Tape.read, hh4]; exact hc4 0 (by simp) have hneq : (c.work 3).read ≠ (c.work 4).read := by rw [hr3, hr4] exact fun h => toΓ_ne_blank (hB b (by simp)) h.symm @@ -612,7 +612,7 @@ private theorem compare_loop : | cons a A' ihA => intro hA B hB c p q hstate hh3 hh4 hc3 hb3 hc4 hb4 hin hout hoth have hr3 : (c.work 3).read = a.toΓ := by - rw [Tape.read, hh3]; simpa using hc3 0 (by simp) + rw [Tape.read, hh3]; exact hc3 0 (by simp) have hr3nb : (c.work 3).read ≠ Γ.blank := by rw [hr3]; exact toΓ_ne_blank (hA a (by simp)) have hr3ns : (c.work 3).read ≠ Γ.start := by @@ -633,7 +633,7 @@ private theorem compare_loop : rw [hw₁] <;> omega | cons b B' => have hr4 : (c.work 4).read = b.toΓ := by - rw [Tape.read, hh4]; simpa using hc4 0 (by simp) + rw [Tape.read, hh4]; exact hc4 0 (by simp) by_cases hab : a = b · subst hab have heq : (c.work 3).read = (c.work 4).read := by rw [hr3, hr4] @@ -649,7 +649,7 @@ private theorem compare_loop : (by intro j hj rw [hcl3, show p + 1 + j = p + (j + 1) by omega] - simpa using hc3 (j + 1) (by simpa using Nat.succ_lt_succ hj)) + exact hc3 (j + 1) (by simpa using Nat.succ_lt_succ hj)) (by rw [hcl3, show p + 1 + A'.length = p + (a :: A').length by simp only [List.length_cons]; omega] @@ -657,7 +657,7 @@ private theorem compare_loop : (by intro j hj rw [hcl4, show q + 1 + j = q + (j + 1) by omega] - simpa using hc4 (j + 1) (by simpa using Nat.succ_lt_succ hj)) + exact hc4 (j + 1) (by simpa using Nat.succ_lt_succ hj)) (by rw [hcl4, show q + 1 + B'.length = q + (a :: B').length by simp only [List.length_cons]; omega] @@ -672,7 +672,7 @@ private theorem compare_loop : by rw [hcl3', hcl3], by rw [hcl4', hcl4], by omega, by simp; omega, by omega, by simp; omega⟩ · rw [hst'] - simp only [List.cons.injEq, true_and] + exact if_congr (by simp) rfl rfl · have hneq : (c.work 3).read ≠ (c.work 4).read := by rw [hr3, hr4] exact fun h => hab (toΓ_inj h) @@ -682,7 +682,7 @@ private theorem compare_loop : refine ⟨c₁, 1, by simp, .step hstep' .zero, ?_, hin₁, fun i h3i h4i => hw₁ i, hout₁, by rw [hw₁ 3], by rw [hw₁ 4], ?_, ?_, ?_, ?_⟩ - · rw [hst₁, if_neg (by simp [hab])] + · rw [hst₁, ite_eq_right (by simp [hab])] all_goals (rw [hw₁]; omega) -- ════════════════════════════════════════════════════════════════════════ @@ -710,7 +710,7 @@ private theorem verdict_step (P : Prop) [Decidable P] (c : Cfg 6 haltTestTM.Q) c₁.output.head = 1 := by have hstay : idleDir c.output.read = Dir3.stay := by simp [idleDir, hout] by_cases hP : P - · rw [if_pos hP] at hstate + · rw [ite_eq_left hP] at hstate simp only [TM.step, hstate, haltTestTM] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin @@ -721,15 +721,15 @@ private theorem verdict_step (P : Prop) [Decidable P] (c : Cfg 6 haltTestTM.Q) · by_cases h4i : i = 4 · subst h4i; exact tape_idle_fix _ h4 · exact tape_idle_fix _ (hoth i h3i h4i) - · rw [if_pos hP] + · rw [ite_eq_left hP] show ((c.output.write (Γw.one).toΓ).move (idleDir c.output.read)).cells = _ rw [Tape.move_cells] simp only [Tape.write, hoh, Γw.toΓ] - rw [if_neg Nat.one_ne_zero] + rw [ite_eq_right Nat.one_ne_zero] · show ((c.output.write (Γw.one).toΓ).move (idleDir c.output.read)).head = 1 rw [hstay] simp [Tape.move, Tape.write_head, hoh] - · rw [if_neg hP] at hstate + · rw [ite_eq_right hP] at hstate simp only [TM.step, hstate, haltTestTM] refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin @@ -740,11 +740,11 @@ private theorem verdict_step (P : Prop) [Decidable P] (c : Cfg 6 haltTestTM.Q) · by_cases h4i : i = 4 · subst h4i; exact tape_idle_fix _ h4 · exact tape_idle_fix _ (hoth i h3i h4i) - · rw [if_neg hP] + · rw [ite_eq_right hP] show ((c.output.write (Γw.zero).toΓ).move (idleDir c.output.read)).cells = _ rw [Tape.move_cells] simp only [Tape.write, hoh, Γw.toΓ] - rw [if_neg Nat.one_ne_zero] + rw [ite_eq_right Nat.one_ne_zero] · show ((c.output.write (Γw.zero).toΓ).move (idleDir c.output.read)).head = 1 rw [hstay] simp [Tape.move, Tape.write_head, hoh] @@ -787,16 +787,16 @@ private theorem rewindSt_loop : refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin · intro i hne; dsimp only [] - rw [if_neg hne] + rw [ite_eq_right hne] by_cases h4i : i = 4 · subst h4i; exact tape_idle_fix _ h4 · exact tape_idle_fix _ (hoth i hne h4i) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inl hhead) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head, hhead] obtain ⟨c₁, hstep', hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ := hstep exact ⟨c₁, .step hstep' .zero, hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ @@ -813,16 +813,16 @@ private theorem rewindSt_loop : refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin · intro i hne; dsimp only [] - rw [if_neg hne] + rw [ite_eq_right hne] by_cases h4i : i = 4 · subst h4i; exact tape_idle_fix _ h4 · exact tape_idle_fix _ (hoth i hne h4i) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inr hread) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head, hhead] obtain ⟨c₁, hstep', hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ := hstep obtain ⟨c', hreach, hst', hin', hw', hout', hcells', hhead'⟩ := @@ -874,16 +874,16 @@ private theorem rewindD_loop : refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin · intro i hne; dsimp only [] - rw [if_neg hne] + rw [ite_eq_right hne] by_cases h3i : i = 3 · subst h3i; exact tape_idle_fix _ h3 · exact tape_idle_fix _ (hoth i h3i hne) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inl hhead) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head, hhead] obtain ⟨c₁, hstep', hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ := hstep exact ⟨c₁, .step hstep' .zero, hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ @@ -900,16 +900,16 @@ private theorem rewindD_loop : refine ⟨_, rfl, rfl, ?_, ?_, ?_, ?_, ?_⟩ · exact input_idle_fix c.input hin · intro i hne; dsimp only [] - rw [if_neg hne] + rw [ite_eq_right hne] by_cases h3i : i = 3 · subst h3i; exact tape_idle_fix _ h3 · exact tape_idle_fix _ (hoth i h3i hne) · exact tape_idle_fix c.output hout · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] exact tape_readBackWrite_preserves _ _ (Or.inr hread) · dsimp only [] - rw [if_pos rfl] + rw [ite_eq_left rfl] simp [Tape.writeAndMove, Tape.move, Tape.write_head, hhead] obtain ⟨c₁, hstep', hst₁, hin₁, hw₁, hout₁, hcells₁, hhead₁⟩ := hstep obtain ⟨c', hreach, hst', hin', hw', hout', hcells', hhead'⟩ := diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/Init.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/Init.lean index 2a9ac856..fb359fdd 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/Init.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/Init.lean @@ -342,7 +342,7 @@ private theorem holdsExact_push {t : Tape} {l : List Γw} (h : t.HoldsExact l) ((t.write s.toΓ).move .right).HoldsExact (l ++ [s]) ∧ ((t.write s.toΓ).move .right).head = (l ++ [s]).length + 1 := by have hw : t.write s.toΓ = { t with cells := Function.update t.cells t.head s.toΓ } := by - rw [Tape.write, if_neg (by omega)] + rw [Tape.write, ite_eq_right (by omega)] refine ⟨⟨?_, fun i => ?_⟩, ?_⟩ · show (Tape.move _ .right).cells 0 = Γ.start rw [Tape.move_cells, hw] @@ -355,14 +355,14 @@ private theorem holdsExact_push {t : Tape} {l : List Γw} (h : t.HoldsExact l) by_cases hi : i = l.length · subst hi rw [show l.length + 1 = t.head from hh.symm, Function.update_self] - rw [dif_pos (by simp)] + rw [dite_eq_left (by simp)] simp · rw [Function.update_of_ne (by omega)] rw [h.2 i] by_cases hlt : i < l.length - · rw [dif_pos hlt, dif_pos (by simp; omega)] + · rw [dite_eq_left hlt, dite_eq_left (by simp; omega)] rw [List.getElem_append_left hlt] - · rw [dif_neg hlt, dif_neg (by simp; omega)] + · rw [dite_eq_right hlt, dite_eq_right (by simp; omega)] · simp [Tape.move, Tape.write_head, hh] private theorem bitSym_toΓ (b : Bool) : (bitSym b).toΓ = Γ.ofBool b := by @@ -420,7 +420,7 @@ private theorem inpSfx_initTape (l : List Bool) : InpSfx (Tape.init (l.map Γ.ofBool)) 1 l := by intro j show (if 1 + j = 0 then Γ.start else ((l.map Γ.ofBool)[1 + j - 1]?).getD Γ.blank) = _ - rw [if_neg (by omega), show 1 + j - 1 = j by omega, List.getElem?_map] + rw [ite_eq_right (by omega), show 1 + j - 1 = j by omega, List.getElem?_map] -- ════════════════════════════════════════════════════════════════════════ -- Single-step lemmas @@ -686,7 +686,7 @@ private theorem rewind_loop {idx : Fin 6} {qloop qnext : InitQ} (∀ i, i ≠ idx → c₁.work i = c.work i) ∧ c₁.input = c.input ∧ c₁.output = c.output := by simp only [TM.step, hst, hδ, rewindStep, hread, ↓reduceIte] - rw [if_neg hne'] + rw [ite_eq_right hne'] refine ⟨_, rfl, rfl, ?_, ?_, ?_, by simp [Tape.move, idleDir, hi], tape_idle_preserve _ ho hoh⟩ · simp only [↓reduceIte, Tape.writeAndMove, Tape.move, Tape.write_head, hh] @@ -707,7 +707,7 @@ private theorem rewind_loop {idx : Fin 6} {qloop qnext : InitQ} (∀ i, i ≠ idx → c₁.work i = c.work i) ∧ c₁.input = c.input ∧ c₁.output = c.output := by simp only [TM.step, hst, hδ, rewindStep, hread, ↓reduceIte] - rw [if_neg hne'] + rw [ite_eq_right hne'] refine ⟨_, rfl, rfl, ?_, ?_, ?_, by simp [Tape.move, idleDir, hi], tape_idle_preserve _ ho hoh⟩ · simp only [↓reduceIte, Tape.writeAndMove, Tape.move, Tape.write_head, hh] @@ -1115,9 +1115,9 @@ private theorem copyField_loop : simp only [List.length_cons] at h rw [h] by_cases hj : j < r.length - · rw [dif_pos (by omega), dif_pos hj] + · rw [dite_eq_left (by omega), dite_eq_left hj] simp - · rw [dif_neg (by omega), dif_neg hj] + · rw [dite_eq_right (by omega), dite_eq_right hj] obtain ⟨c', hreach, hst', hin', hw4c', hw4h', hh3', hd3', hfr', hout'⟩ := copyField_loop r (facc ++ [Γw.zero]) (p + 1) c₁ hst₁ hhd4₁ hcells₁ hh3₁ hd3₁ (by rw [hin₁]; exact hi) @@ -1174,9 +1174,9 @@ private theorem copyField_loop : simp only [List.length_cons] at h rw [h] by_cases hj : j < r.length - · rw [dif_pos (by omega), dif_pos hj] + · rw [dite_eq_left (by omega), dite_eq_left hj] simp - · rw [dif_neg (by omega), dif_neg hj] + · rw [dite_eq_right (by omega), dite_eq_right hj] obtain ⟨c', hreach, hst', hin', hw4c', hw4h', hh3', hd3', hfr', hout'⟩ := copyField_loop r (facc ++ [Γw.one]) (p + 1) c₁ hst₁ hhd4₁ hcells₁ hh3₁ hd3₁ (by rw [hin₁]; exact hi) @@ -1210,10 +1210,10 @@ private theorem holdsExact_blank_singleton {t : Tape} (h : t.HoldsExact []) : refine ⟨h.1, fun i => ?_⟩ rw [Tape.HoldsExact.cells_ge h (Nat.zero_le i)] by_cases hi : i < 1 - · rw [dif_pos (show i < [Γw.blank].length by simpa using hi)] + · rw [dite_eq_left (show i < [Γw.blank].length by simpa using hi)] obtain rfl : i = 0 := by omega rfl - · rw [dif_neg (show ¬i < [Γw.blank].length by simpa using hi)] + · rw [dite_eq_right (show ¬i < [Γw.blank].length by simpa using hi)] /-- The exact-contents view of the shifted `x` tape is the `VShift` shadow of `Tape.init (x.map Γ.ofBool)` (see `VShift.init`). -/ @@ -1230,16 +1230,16 @@ private theorem holdsExact_shift_cells {t : Tape} {x : List Bool} have := Tape.HoldsExact.cells_lt h (i := 0) (by simp) simpa using this · obtain ⟨m, rfl⟩ : ∃ m, k = m + 2 := ⟨k - 2, by omega⟩ - simp only [show m + 2 ≠ 0 by omega, if_false, show m + 2 ≠ 1 by omega, + simp only [show m + 2 ≠ 0 by omega, ite_false, show m + 2 ≠ 1 by omega, show m + 2 - 2 = m by omega] rw [show m + 2 = m + 1 + 1 by omega, h.2 (m + 1)] simp only [List.length_cons, bitsToSyms_length] by_cases hm : m < x.length - · rw [dif_pos (by omega), List.getElem_cons_succ, List.getElem?_map, + · rw [dite_eq_left (by omega), List.getElem_cons_succ, List.getElem?_map, List.getElem?_eq_getElem hm] simp only [bitsToSyms, List.getElem_map, Option.map_some, Option.getD_some] exact bitSym_toΓ _ - · rw [dif_neg (by omega), List.getElem?_map, + · rw [dite_eq_right (by omega), List.getElem?_map, List.getElem?_eq_none (by omega)] rfl @@ -1344,7 +1344,7 @@ private theorem initTM_hoareTime_core (α x : List Bool) {c₁ : Cfg 6 initTM.Q} -- ── rewind the desc tape ── obtain ⟨c₅, hreach₅, hst₅, hd4₅, hcl4₅, hfr₅, hin₅, hout₅⟩ := rewind_loop (idx := 4) (qloop := .rewindDesc) (qnext := .copyField) - (fun _ _ _ => rfl) (by decide) + (fun _ _ _ => rfl) nofun ((groupPairs α).length + 1) c₄ hst₄ hd4₄ (Tape.HoldsExact.startInvariant hh4₄).1 (fun j hj => (Tape.HoldsExact.startInvariant hh4₄).2 j hj) @@ -1385,7 +1385,7 @@ private theorem initTM_hoareTime_core (α x : List Bool) {c₁ : Cfg 6 initTM.Q} exact hwo₅ i h3 h4 obtain ⟨c₇, hreach₇, hst₇, hd4₇, hcl4₇, hfr₇, hin₇, hout₇⟩ := rewind_loop (idx := 4) (qloop := .rewindDesc2) (qnext := .rewindState) - (fun _ _ _ => rfl) (by decide) + (fun _ _ _ => rfl) nofun ((takeField (groupPairs α)).1.length + 1) c₆ hst₆ hd4₆' (Tape.HoldsExact.startInvariant hh4₆).1 (fun j hj => (Tape.HoldsExact.startInvariant hh4₆).2 j hj) @@ -1410,7 +1410,7 @@ private theorem initTM_hoareTime_core (α x : List Bool) {c₁ : Cfg 6 initTM.Q} exact hwo₆ i h4 obtain ⟨c₈, hreach₈, hst₈, hd3₈, hcl3₈, hfr₈, hin₈, hout₈⟩ := rewind_loop (idx := 3) (qloop := .rewindState) (qnext := .rewindV0) - (fun _ _ _ => rfl) (by decide) + (fun _ _ _ => rfl) nofun ((takeField (groupPairs α)).1.length + 1) c₇ hst₇ hd3₇ (Tape.HoldsExact.startInvariant hh3₇).1 (fun j hj => (Tape.HoldsExact.startInvariant hh3₇).2 j hj) @@ -1438,7 +1438,7 @@ private theorem initTM_hoareTime_core (α x : List Bool) {c₁ : Cfg 6 initTM.Q} exact hwo₇ i h3 obtain ⟨c₉, hreach₉, hst₉, hd0₉, hcl0₉, hfr₉, hin₉, hout₉⟩ := rewind_loop (idx := 0) (qloop := .rewindV0) (qnext := .done) - (fun _ _ _ => rfl) (by decide) + (fun _ _ _ => rfl) nofun (x.length + 2) c₈ hst₈ hd0₈ (Tape.HoldsExact.startInvariant hh0₈).1 (fun j hj => (Tape.HoldsExact.startInvariant hh0₈).2 j hj) diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/Interp.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/Interp.lean index 9dc92d7c..a9379f10 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/Interp.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/Interp.lean @@ -180,11 +180,11 @@ theorem descOfTM_halted (c : Cfg 1 M.Q) : have hlt : (M.stateEquiv M.qhalt).val ≤ 2 ^ Fintype.card M.Q := Nat.le_of_lt (lt_of_lt_of_le (M.stateEquiv M.qhalt).isLt (Nat.le_of_lt Nat.lt_two_pow_self)) - simp only [halted, Cfg.isHalted, descCfg, TMDesc.toTM, descOfTM, Fin.mk.injEq, + simp only [halted, Cfg.isHalted, descCfg, TMDesc.toTM, descOfTM, Nat.min_eq_left hlt] constructor - · intro h; exact M.stateEquiv.injective (Fin.val_injective h) - · intro h; rw [h] + · intro h; exact M.stateEquiv.injective (Fin.val_injective (Fin.mk.injEq .. ▸ h)) + · intro h; simp [h] /-- The initial configuration embeds correctly. -/ theorem descOfTM_initCfg (x : List Bool) : @@ -203,7 +203,7 @@ theorem descOfTM_step_comm (c : Cfg 1 M.Q) : simp [step, h, hh] · have hne : (M.descCfg c).state ≠ M.descOfTM.toTM.qhalt := fun hh => h ((M.descOfTM_halted c).mp hh) - simp only [step, if_neg h, if_neg hne, Option.map_some] + simp only [step, ite_eq_right h, ite_eq_right hne, Option.map_some] have hro := M.δ_right_of_start c.state c.input.read (fun i => (c.work i).read) c.output.read have hwork : (fun _ : Fin 1 => (c.work 0).read) = (fun i => (c.work i).read) := @@ -219,16 +219,16 @@ theorem descOfTM_step_comm (c : Cfg 1 M.Q) : exact Nat.le_of_lt (lt_of_lt_of_le (M.stateEquiv _).isLt (Nat.le_of_lt Nat.lt_two_pow_self))) · by_cases hi : c.input.read = Γ.start - · rw [if_pos hi, hro.1 hi] - · rw [if_neg hi] + · rw [ite_eq_left hi, hro.1 hi] + · rw [ite_eq_right hi] · funext i obtain rfl : i = 0 := Subsingleton.elim i 0 by_cases hw : (c.work 0).read = Γ.start - · rw [if_pos hw, hro.2.1 0 hw] - · rw [if_neg hw] + · rw [ite_eq_left hw, hro.2.1 0 hw] + · rw [ite_eq_right hw] · by_cases ho : c.output.read = Γ.start - · rw [if_pos ho, hro.2.2 ho] - · rw [if_neg ho] + · rw [ite_eq_left ho, hro.2.2 ho] + · rw [ite_eq_right ho] /-- Multi-step correspondence. -/ theorem descOfTM_reachesIn {t : ℕ} {c c' : Cfg 1 M.Q} diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/SeekFrontier.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/SeekFrontier.lean index 5eb53d55..40476be5 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/SeekFrontier.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/SeekFrontier.lean @@ -112,22 +112,22 @@ def seekFrontierTM : TM 7 where · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .walk => dsimp only [] split · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT - · rw [if_pos hir] - · rw [if_neg hir]; exact idleDir_right_of_start hi + · rw [ite_eq_left hir] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi · refine ⟨idleDir_right_of_start, fun i hi => ?_, idleDir_right_of_start⟩ dsimp only [] by_cases hir : i = clkT · subst hir - rw [if_pos rfl, if_pos hi] - · rw [if_neg hir]; exact idleDir_right_of_start hi + rw [ite_eq_left rfl, ite_eq_left hi] + · rw [ite_eq_right hir]; exact idleDir_right_of_start hi | .done => exact rightOfStart_allIdle iHead wHeads oHead -- ── step lemmas ── @@ -148,7 +148,7 @@ private theorem seekFrontier_step_first_blank (c : Cfg 7 seekFrontierTM.Q) seekFrontierTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output } := by - rw [TM.step, if_neg (seekFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (seekFrontier_ne_halt (by decide) hst)] simp only [seekFrontierTM, hst, hblank, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -169,7 +169,7 @@ private theorem seekFrontier_step_first_one (c : Cfg 7 seekFrontierTM.Q) { state := .walk, input := c.input, work := Function.update c.work clkT ((c.work clkT).move .right), output := c.output } := by - rw [TM.step, if_neg (seekFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (seekFrontier_ne_halt (by decide) hst)] simp only [seekFrontierTM, hst, hone, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -178,7 +178,7 @@ private theorem seekFrontier_step_first_one (c : Cfg 7 seekFrontierTM.Q) · subst hir simp only [↓reduceIte, Function.update_self] exact writeAndMove_readBack_move _ (by rw [hone]; decide) _ - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -192,7 +192,7 @@ private theorem seekFrontier_step_walk_one (c : Cfg 7 seekFrontierTM.Q) { state := .walk, input := c.input, work := Function.update c.work clkT ((c.work clkT).move .right), output := c.output } := by - rw [TM.step, if_neg (seekFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (seekFrontier_ne_halt (by decide) hst)] simp only [seekFrontierTM, hst, hone, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -201,7 +201,7 @@ private theorem seekFrontier_step_walk_one (c : Cfg 7 seekFrontierTM.Q) · subst hir simp only [↓reduceIte, Function.update_self] exact writeAndMove_readBack_move _ (by rw [hone]; decide) _ - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout @@ -216,7 +216,7 @@ private theorem seekFrontier_step_walk_blank (c : Cfg 7 seekFrontierTM.Q) { state := .done, input := c.input, work := Function.update c.work clkT ((c.work clkT).move .left), output := c.output } := by - rw [TM.step, if_neg (seekFrontier_ne_halt (by decide) hst)] + rw [TM.step, ite_eq_right (seekFrontier_ne_halt (by decide) hst)] simp only [seekFrontierTM, hst, hblank, reduceCtorEq, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -225,7 +225,7 @@ private theorem seekFrontier_step_walk_blank (c : Cfg 7 seekFrontierTM.Q) · subst hir simp only [↓reduceIte, Function.update_self] exact writeAndMove_readBack_move _ (by rw [hblank]; decide) _ - · rw [if_neg hir, Function.update_of_ne hir] + · rw [ite_eq_right hir, Function.update_of_ne hir] exact Tape.writeAndMove_readBack_idle_of_ne_start _ (hoth i hir) · exact Tape.writeAndMove_readBack_idle_of_ne_start _ hout diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/Sim.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/Sim.lean index 345bc92e..d5f0f766 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/Sim.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/Sim.lean @@ -78,7 +78,7 @@ theorem vshift_initTape_nil {t : Tape} (h : t.HoldsExact []) (hh : t.head = 1) : · have := (Tape.HoldsExact.nil_iff.mp h).2 (k - 1) rw [show k - 1 + 1 = k by omega] at this rw [this] - simp only [hk0, hk1, if_false] + simp only [hk0, hk1, ite_false] show Γ.blank = (Tape.init []).cells (k - 1) simp [Tape.init, show k - 1 ≠ 0 by omega] @@ -96,9 +96,9 @@ theorem vshift_initTape_x {t : Tape} (x : List Bool) · simp [hk0] · by_cases hk1 : k = 1 · simp [hk1] - · simp only [hk0, hk1, if_false] + · simp only [hk0, hk1, ite_false] show _ = (Tape.init (x.map Γ.ofBool)).cells (k - 1) - simp only [Tape.init, show k - 1 ≠ 0 by omega, if_false, + simp only [Tape.init, show k - 1 ≠ 0 by omega, ite_false, show k - 1 - 1 = k - 2 by omega] /-- **Initialization realizes the invariant**: the tape shape guaranteed by diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/SimClocked.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/SimClocked.lean index ef0361f2..b52f5e3b 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/SimClocked.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/SimClocked.lean @@ -302,7 +302,7 @@ private theorem clocked_rewind_check {n : ℕ} (tmBody tmTest : TM n) · rw [← hread3] exact transitionTape_eq_self (by rw [hread3]; simp) refine ⟨c₃, .step hs1 (.step hs2 (.step hs3 .zero)), ?_, ?_, ?_, ?_⟩ - · rw [hst3, if_pos hone] + · rw [hst3, ite_eq_left hone] · rw [hin3, hin2, hin1] · rw [hwk3, hwk2, hwk1] · rw [hout3, hout_eq] @@ -322,7 +322,7 @@ private theorem clocked_rewind_check {n : ℕ} (tmBody tmTest : TM n) exact hwk i · exact transitionTape_eq_self hread3s refine ⟨c₃, .step hs1 (.step hs2 (.step hs3 .zero)), ?_, ?_, ?_, ?_⟩ - · rw [hst3, if_neg hone] + · rw [hst3, ite_eq_right hone] · rw [hin3, hin2, hin1] · rw [hwk3, hwk2, hwk1] · rw [hout3, hout_eq] @@ -482,9 +482,9 @@ private theorem clockedTest_hoareTime (α : List Bool) then Γ.one else Γ.zero) = (if mc₂.state = (decodeDesc α).toTM.qhalt then Γ.one else Γ.zero) := by by_cases hq : mc₂.state = (decodeDesc α).toTM.qhalt - · rw [if_pos hq, if_pos + · rw [ite_eq_left hq, ite_eq_left (show S = (takeField (takeField (groupPairs α)).2).1 from hSiff.mpr hq)] - · rw [if_neg hq, if_neg + · rw [ite_eq_right hq, ite_eq_right (show ¬S = (takeField (takeField (groupPairs α)).2).1 from fun hc => hq (hSiff.mp hc))] have hoc1' : c'.output.cells 1 @@ -682,15 +682,15 @@ private theorem clocked_iteration (α : List Bool) (hterm : TerminatedRegion α) -- ── branch on the combined verdict ── by_cases hcond : mc₂.state = (decodeDesc α).toTM.qhalt ∨ v - 1 = 0 · have hone : ct.output.cells 1 = Γ.one := by - rw [ht_oc1, if_pos hcond] - rw [if_pos hone] at hr_all + rw [ht_oc1, ite_eq_left hcond] + rw [ite_eq_left hone] at hr_all exact ⟨mc₂, ct.work, ct.output, t_body + 1 + t_test + 1 + 3, htime, hstepd, ht_si', ht_ckc, ht_ckh, ht_oc0, ht_ons, ht_oh, Or.inl ⟨hcond, hone, hr_all⟩⟩ · have hzero : ct.output.cells 1 = Γ.zero := by - rw [ht_oc1, if_neg hcond] + rw [ht_oc1, ite_eq_right hcond] have hone_ne : ct.output.cells 1 ≠ Γ.one := by rw [hzero]; simp - rw [if_neg hone_ne] at hr_all + rw [ite_eq_right hone_ne] at hr_all exact ⟨mc₂, ct.work, ct.output, t_body + 1 + t_test + 1 + 3, htime, hstepd, ht_si', ht_ckc, ht_ckh, ht_oc0, ht_ons, ht_oh, Or.inr ⟨hcond, hr_all⟩⟩ diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/SimLoop.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/SimLoop.lean index d2ad2662..59d14927 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/SimLoop.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/SimLoop.lean @@ -216,7 +216,7 @@ private theorem loopTM_rewind_check {n : ℕ} (tmBody tmTest : TM n) · rw [← hread3] exact transitionTape_eq_self (by rw [hread3]; simp) refine ⟨c₃, .step hs1 (.step hs2 (.step hs3 .zero)), ?_, ?_, ?_, ?_⟩ - · rw [hst3, if_pos hone] + · rw [hst3, ite_eq_left hone] · rw [hin3, hin2, hin1] · rw [hwk3, hwk2, hwk1] · rw [hout3, hout_eq] @@ -236,7 +236,7 @@ private theorem loopTM_rewind_check {n : ℕ} (tmBody tmTest : TM n) exact hwk i · exact transitionTape_eq_self hread3s refine ⟨c₃, .step hs1 (.step hs2 (.step hs3 .zero)), ?_, ?_, ?_, ?_⟩ - · rw [hst3, if_neg hone] + · rw [hst3, ite_eq_right hone] · rw [hin3, hin2, hin1] · rw [hwk3, hwk2, hwk1] · rw [hout3, hout_eq] @@ -330,9 +330,9 @@ private theorem loop_iteration (α : List Bool) (hterm : TerminatedRegion α) then Γ.one else Γ.zero) = (if mc₂.state = (decodeDesc α).toTM.qhalt then Γ.one else Γ.zero) := by by_cases h : mc₂.state = (decodeDesc α).toTM.qhalt - · rw [if_pos h, if_pos + · rw [ite_eq_left h, ite_eq_left (show S = (takeField (takeField (groupPairs α)).2).1 from hSiff.mpr h)] - · rw [if_neg h, if_neg + · rw [ite_eq_right h, ite_eq_right (show ¬S = (takeField (takeField (groupPairs α)).2).1 from fun hc => h (hSiff.mp hc))] have hcell1 : ct.output.cells 1 @@ -423,15 +423,15 @@ private theorem loop_iteration (α : List Bool) (hterm : TerminatedRegion α) -- branch on the verdict by_cases hq : mc₂.state = (decodeDesc α).toTM.qhalt · have hone : ct.output.cells 1 = Γ.one := by - rw [hcell1, if_pos hq] - rw [if_pos hone] at hr_all + rw [hcell1, ite_eq_left hq] + rw [ite_eq_left hone] at hr_all exact ⟨mc₂, cb.work, ct.output, t_body + 1 + t_test + 1 + 3, htime, hstepd, hinv', hctoc0, hctons, htoh, Or.inl ⟨hq, hone, hr_all⟩⟩ · have hzero : ct.output.cells 1 = Γ.zero := by - rw [hcell1, if_neg hq] + rw [hcell1, ite_eq_right hq] have hone_ne : ct.output.cells 1 ≠ Γ.one := by rw [hzero]; simp - rw [if_neg hone_ne] at hr_all + rw [ite_eq_right hone_ne] at hr_all exact ⟨mc₂, cb.work, ct.output, t_body + 1 + t_test + 1 + 3, htime, hstepd, hinv', hctoc0, hctons, htoh, Or.inr ⟨hq, hr_all⟩⟩ @@ -647,7 +647,7 @@ theorem utm_loop_extract_hoareTime (α x : List Bool) (hterm : TerminatedRegion intro k rw [hvout.1] simp only [show ¬(k + 2 = 0) by omega, show ¬(k + 2 = 1) by omega, - if_false, show k + 2 - 1 = k + 1 by omega] + ite_false, show k + 2 - 1 = k + 1 by omega] have hblank2 : (work 2).cells (m + 2) = Γ.blank := by rw [hcells2 m] exact hmb diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/StepGlue.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/StepGlue.lean index 3193e89c..82bcae51 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/StepGlue.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/StepGlue.lean @@ -44,9 +44,9 @@ theorem simRead_flag_eq {sim utm : Tape} (h : VShift sim utm) (hwf : sim.StartInvariant) : simRead (decide (sim.head = 0)) utm.read = sim.read := by by_cases hz : sim.head = 0 - · rw [simRead, decide_eq_true hz, if_pos rfl, Tape.read, hz] + · rw [simRead, decide_eq_true hz, ite_eq_left rfl, Tape.read, hz] exact hwf.1.symm - · rw [simRead, decide_eq_false hz, if_neg Bool.false_ne_true] + · rw [simRead, decide_eq_false hz, ite_eq_right Bool.false_ne_true] exact h.read_eq (by omega) /-- Every entry produced by `parseEntry` has an in-range target, so the @@ -56,9 +56,9 @@ theorem parseEntry_q'_lt {w : ℕ} {seg : List Γw} {e : DescEntry} unfold parseEntry at hp dsimp only at hp by_cases hlen : (seg.filterMap symBit?).length < 2 * w + 16 - · rw [if_pos hlen] at hp + · rw [ite_eq_left hlen] at hp exact absurd hp (by simp) - · rw [if_neg hlen] at hp + · rw [ite_eq_right hlen] at hp simp only [Option.some.injEq] at hp subst hp dsimp only diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/TermCheck.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/TermCheck.lean index 952ba772..b1e2e291 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/TermCheck.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/TermCheck.lean @@ -327,7 +327,7 @@ private theorem termCheck_step_readFst_bit (c : Cfg 8 termCheckTM.Q) termCheckTM.step c = some { state := .readSnd ctrl b, input := c.input.move .right, work := c.work, output := c.output } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] cases b <;> · simp only [Γ.ofBool] at hread simp only [termCheckTM, hst, hread] @@ -345,7 +345,7 @@ private theorem termCheck_step_readFst_blank (c : Cfg 8 termCheckTM.Q) termCheckTM.step c = some { state := .rewind (ctrlVerdict ctrl), input := c.input.move .left, work := c.work, output := c.output } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] simp only [termCheckTM, hst, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -361,7 +361,7 @@ private theorem termCheck_step_readSnd_bit (c : Cfg 8 termCheckTM.Q) termCheckTM.step c = some { state := .readFst (scanStep ctrl (symOfPair b₀ b₁)), input := c.input.move .right, work := c.work, output := c.output } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] cases b₁ <;> · simp only [Γ.ofBool] at hread simp only [termCheckTM, hst, hread] @@ -379,7 +379,7 @@ private theorem termCheck_step_readSnd_blank (c : Cfg 8 termCheckTM.Q) termCheckTM.step c = some { state := .rewind (ctrlVerdict ctrl), input := c.input.move .left, work := c.work, output := c.output } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] simp only [termCheckTM, hst, hread] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -393,7 +393,7 @@ private theorem termCheck_step_rewind_left (c : Cfg 8 termCheckTM.Q) (v : Bool) termCheckTM.step c = some { state := .rewind v, input := c.input.move .left, work := c.work, output := c.output } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] simp only [termCheckTM, hst, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -407,7 +407,7 @@ private theorem termCheck_step_rewind_start (c : Cfg 8 termCheckTM.Q) (v : Bool) termCheckTM.step c = some { state := .emit v, input := c.input.move .right, work := c.work, output := c.output } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] simp only [termCheckTM, hst, hread, ↓reduceIte] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, rfl, ?_, ?_⟩) · funext i @@ -421,7 +421,7 @@ private theorem termCheck_step_emit (c : Cfg 8 termCheckTM.Q) (v : Bool) termCheckTM.step c = some { state := .done, input := c.input, work := c.work, output := c.output.write (if v then Γ.one else Γ.zero) } := by - rw [TM.step, if_neg (termCheck_ne_halt hst nofun)] + rw [TM.step, ite_eq_right (termCheck_ne_halt hst nofun)] simp only [termCheckTM, hst] refine congrArg some ((Cfg.mk.injEq ..).mpr ⟨rfl, ?_, ?_, ?_⟩) · exact transitionInput_eq_self hinp @@ -643,7 +643,7 @@ theorem termCheckTM_hoareTime (x : List Bool) (work₀ : Fin 8 → Tape) (out₀ · show c₂.work = work rw [hw₂, hw₁'] · show (c₂.output.write _).cells = _ - rw [hv, ho₂, ho₁', Tape.write, if_neg (by rw [houth]; omega)] + rw [hv, ho₂, ho₁', Tape.write, ite_eq_right (by rw [houth]; omega)] show Function.update out.cells out.head _ = _ rw [houth] · show (c₂.output.write _).head = 1 diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/VTape.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/VTape.lean index 078453ed..78126d6a 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/VTape.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/VTape.lean @@ -72,12 +72,12 @@ theorem startInvariant {t : Tape} {syms : List Γw} (h : t.HoldsExact syms) : t. /-- Cells within the contents. -/ theorem cells_lt {t : Tape} {syms : List Γw} (h : t.HoldsExact syms) {i : ℕ} (hi : i < syms.length) : t.cells (i + 1) = (syms[i]).toΓ := by - rw [h.2 i, dif_pos hi] + rw [h.2 i, dite_eq_left hi] /-- Cells beyond the contents are blank. -/ theorem cells_ge {t : Tape} {syms : List Γw} (h : t.HoldsExact syms) {i : ℕ} (hi : syms.length ≤ i) : t.cells (i + 1) = Γ.blank := by - rw [h.2 i, dif_neg (by omega)] + rw [h.2 i, dite_eq_right (by omega)] /-- The all-blank (cleared) tape characterization. -/ theorem nil_iff {t : Tape} : @@ -114,8 +114,8 @@ theorem head_pos {sim utm : Tape} (h : VShift sim utm) : 1 ≤ utm.head := by theorem read_eq {sim utm : Tape} (h : VShift sim utm) (hp : 1 ≤ sim.head) : utm.read = sim.read := by rw [Tape.read, Tape.read, h.1, h.2] - simp only [show sim.head + 1 ≠ 0 by omega, if_false, - show sim.head + 1 ≠ 1 by omega, if_false, Nat.add_sub_cancel] + simp only [show sim.head + 1 ≠ 0 by omega, ite_false, + show sim.head + 1 ≠ 1 by omega, ite_false, Nat.add_sub_cancel] /-- At the simulated origin, the shadow reads the permanent `□`. -/ theorem read_blank {sim utm : Tape} (h : VShift sim utm) (hp : sim.head = 0) : @@ -139,10 +139,10 @@ theorem startInvariant {sim utm : Tape} (h : VShift sim utm) (hsim : sim.StartIn · rw [h.1]; simp · intro j hj rw [h.1] - simp only [show j ≠ 0 by omega, if_false] + simp only [show j ≠ 0 by omega, ite_false] by_cases hj1 : j = 1 · simp [hj1] - · simp only [hj1, if_false] + · simp only [hj1, ite_false] exact hsim.2 (j - 1) (by omega) /-- Moves correspond, provided a left move never happens at the simulated @@ -167,7 +167,7 @@ theorem write {sim utm : Tape} (h : VShift sim utm) (s : Γw) (hp : 1 ≤ sim.he have hh : utm.head = sim.head + 1 := h.2 refine ⟨?_, by rw [Tape.write_head, Tape.write_head]; exact hh⟩ unfold Tape.write - rw [if_neg (by omega), if_neg (by omega)] + rw [ite_eq_right (by omega), ite_eq_right (by omega)] funext k show Function.update utm.cells utm.head s.toΓ k = if k = 0 then Γ.start else if k = 1 then Γ.blank @@ -175,15 +175,15 @@ theorem write {sim utm : Tape} (h : VShift sim utm) (s : Γw) (hp : 1 ≤ sim.he by_cases hk : k = utm.head · subst hk rw [Function.update_self, hh] - simp only [show sim.head + 1 ≠ 0 by omega, if_false, - show sim.head + 1 ≠ 1 by omega, if_false] + simp only [show sim.head + 1 ≠ 0 by omega, ite_false, + show sim.head + 1 ≠ 1 by omega, ite_false] rw [Nat.add_sub_cancel, Function.update_self] · rw [Function.update_of_ne hk, h.1] by_cases hk0 : k = 0 · simp [hk0] · by_cases hk1 : k = 1 · simp [hk1] - · simp only [hk0, hk1, if_false] + · simp only [hk0, hk1, ite_false] rw [Function.update_of_ne (by rw [hh] at hk; omega)] /-- A simulated write at the origin is a no-op; the shadow writes `□` over @@ -193,7 +193,7 @@ theorem write_origin {sim utm : Tape} (h : VShift sim utm) (hp : sim.head = 0) : have hh : utm.head = sim.head + 1 := h.2 refine ⟨?_, by rw [Tape.write_head]; exact hh⟩ unfold Tape.write - rw [if_neg (by omega)] + rw [ite_eq_right (by omega)] funext k show Function.update utm.cells utm.head Γ.blank k = if k = 0 then Γ.start else if k = 1 then Γ.blank else sim.cells (k - 1) @@ -212,12 +212,12 @@ theorem writeAndMove {sim utm : Tape} (h : VShift sim utm) (s : Γw) (d : Dir3) VShift (sim.writeAndMove s.toΓ d) (utm.writeAndMove (if sim.head = 0 then Γ.blank else s.toΓ) d) := by rcases Nat.eq_zero_or_pos sim.head with hp | hp - · rw [if_pos hp] - have hw : sim.write s.toΓ = sim := by unfold Tape.write; rw [if_pos hp] + · rw [ite_eq_left hp] + have hw : sim.write s.toΓ = sim := by unfold Tape.write; rw [ite_eq_left hp] show VShift ((sim.write s.toΓ).move d) ((utm.write Γ.blank).move d) rw [hw] exact (h.write_origin hp).move d hd - · rw [if_neg (by omega)] + · rw [ite_eq_right (by omega)] exact (h.write s hp).move d (fun h0 => absurd (by rwa [Tape.write_head] at h0) (by omega)) @@ -233,7 +233,7 @@ theorem init (l : List Γ) : · simp [hk0] · by_cases hk1 : k = 1 · simp [hk1] - · simp only [hk0, hk1, if_false, Tape.init, + · simp only [hk0, hk1, ite_false, Tape.init, show k - 1 ≠ 0 by omega, show k - 1 - 1 = k - 2 by omega] end VShift diff --git a/Complexitylib/Models/TuringMachine/UTM/Internal/Verdict.lean b/Complexitylib/Models/TuringMachine/UTM/Internal/Verdict.lean index 8ee90341..0487762b 100644 --- a/Complexitylib/Models/TuringMachine/UTM/Internal/Verdict.lean +++ b/Complexitylib/Models/TuringMachine/UTM/Internal/Verdict.lean @@ -71,7 +71,7 @@ theorem verdict_running (α : List Bool) {q : ℕ} by_cases hlen : (qhaltField (groupPairs α)).length = d.w · -- well-formed width: symbol-wise equality ⟺ decoded values agree have hqh : d.qhalt = fieldNat (qhaltField (groupPairs α)) := by - rw [hd, decodeDesc_qhalt, if_pos hlen] + rw [hd, decodeDesc_qhalt, ite_eq_left hlen] have hlt : fieldNat (qhaltField (groupPairs α)) < 2 ^ d.w := by rw [fieldNat, ← hlen] calc Nat.fromBits ((qhaltField (groupPairs α)).filterMap symBit?) @@ -98,7 +98,7 @@ theorem verdict_running (α : List Bool) {q : ℕ} from hlenb.symm, Nat.toBits_fromBits, hbits] · -- malformed width: lengths differ on the left; the sentinel on the right have hqh : d.qhalt = 2 ^ d.w := by - rw [hd, decodeDesc_qhalt, if_neg hlen] + rw [hd, decodeDesc_qhalt, ite_eq_right hlen] rw [hqh, Nat.min_self] constructor · intro h diff --git a/Complexitylib/SAT/CircuitSatisfiability/Internal.lean b/Complexitylib/SAT/CircuitSatisfiability/Internal.lean index e36180b7..17ac978b 100644 --- a/Complexitylib/SAT/CircuitSatisfiability/Internal.lean +++ b/Complexitylib/SAT/CircuitSatisfiability/Internal.lean @@ -62,14 +62,12 @@ private theorem validPairEncoding_mem_P : validPairEncoding ∈ P := by private theorem verifierRepack_mem_FP : verifierRepack ∈ FP := by have hcode : (fun input => pairFst (pairFst input)) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp pairFst_mem_FP pairFst_mem_FP + exact mem_FP_comp pairFst_mem_FP pairFst_mem_FP exact mem_FP_pair hcode pairSnd_mem_FP private theorem verifierLengthFlag_mem_FP : verifierLengthFlag ∈ FP := by have hleft : (fun input => pairSnd (pairFst input)) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp pairFst_mem_FP pairSnd_mem_FP + exact mem_FP_comp pairFst_mem_FP pairSnd_mem_FP have hright : (fun input => pairSnd input) ∈ FP := pairSnd_mem_FP have hleftCobham : Cobham (fun v : Fin 1 → List Bool => pairSnd (pairFst (v 0))) := by @@ -83,7 +81,7 @@ private theorem verifierLengthFlag_mem_FP : verifierLengthFlag ∈ FP := by private theorem verifierLengthLanguage_mem_P : verifierLengthLanguage ∈ P := by apply mem_P_of_decisionFn verifierLengthFlag_mem_FP intro input - simp only [verifierLengthLanguage, Set.mem_setOf_eq, verifierLengthFlag] + simp only [verifierLengthLanguage, Set.mem_ofPred_eq, verifierLengthFlag] constructor · intro h refine ⟨true, ?_, rfl⟩ @@ -171,15 +169,12 @@ private def extensionVerifierLengthLanguage : Language := private theorem extensionVerifierRepack_mem_FP : extensionVerifierRepack ∈ FP := by have hquery : (fun input => pairFst input) ∈ FP := pairFst_mem_FP have hcode : (fun input => pairFst (pairFst input)) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp hquery pairFst_mem_FP + exact mem_FP_comp hquery pairFst_mem_FP have hpayload : (fun input => pairSnd (pairFst input)) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp hquery pairSnd_mem_FP + exact mem_FP_comp hquery pairSnd_mem_FP have hprefix : (fun input => pairFst (pairSnd (pairFst input))) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp hpayload pairFst_mem_FP + exact mem_FP_comp hpayload pairFst_mem_FP have hwitness : (fun input => pairSnd input) ∈ FP := pairSnd_mem_FP have hprefixCobham : Cobham (fun v : Fin 1 → List Bool => @@ -198,12 +193,10 @@ private theorem extensionVerifierLengthFlag_mem_FP : extensionVerifierLengthFlag ∈ FP := by have hquery : (fun input => pairFst input) ∈ FP := pairFst_mem_FP have hpayload : (fun input => pairSnd (pairFst input)) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp hquery pairSnd_mem_FP + exact mem_FP_comp hquery pairSnd_mem_FP have hruler : (fun input => pairSnd (pairSnd (pairFst input))) ∈ FP := by - simpa only [Function.comp_apply] using - mem_FP_comp hpayload pairSnd_mem_FP + exact mem_FP_comp hpayload pairSnd_mem_FP have hwitness : (fun input => pairSnd input) ∈ FP := pairSnd_mem_FP have hrulerCobham : Cobham (fun v : Fin 1 → List Bool => @@ -219,7 +212,7 @@ private theorem extensionVerifierLengthLanguage_mem_P : extensionVerifierLengthLanguage ∈ P := by apply mem_P_of_decisionFn extensionVerifierLengthFlag_mem_FP intro input - simp only [extensionVerifierLengthLanguage, Set.mem_setOf_eq, + simp only [extensionVerifierLengthLanguage, Set.mem_ofPred_eq, extensionVerifierLengthFlag] constructor · intro h diff --git a/Complexitylib/SAT/CookLevin.lean b/Complexitylib/SAT/CookLevin.lean index 3d545216..68255046 100644 --- a/Complexitylib/SAT/CookLevin.lean +++ b/Complexitylib/SAT/CookLevin.lean @@ -147,9 +147,9 @@ theorem atMostOne_unique {α : Assignment} {vars : List ℕ} {v w : ℕ} (h : vars.Pairwise (fun a b => ¬(α.get a = true ∧ α.get b = true))) (hv : v ∈ vars) (hw : w ∈ vars) (hvt : α.get v = true) (hwt : α.get w = true) : v = w := by by_contra hne - have hsymm : Symmetric (fun a b => ¬(α.get a = true ∧ α.get b = true)) := - fun a b hab hba => hab ⟨hba.2, hba.1⟩ - exact (h.forall hsymm hv hw hne) ⟨hvt, hwt⟩ + have hsymm : Std.Symm (fun a b => ¬(α.get a = true ∧ α.get b = true)) := + ⟨fun _ _ hab hba => hab ⟨hba.2, hba.1⟩⟩ + exact (h.forall hv hw hne) ⟨hvt, hwt⟩ /-- An implication clause `cond ++ [conseq]` whose `cond` literals are all false is satisfied only if its consequent literal is true. (Each active-transition clause @@ -652,8 +652,8 @@ theorem represents_step (N : NTM 1) (α : Assignment) (steps P : ℕ) (fun _ => (c.work 0).read) c.output.read).2.1 0).toΓ := by unfold traceStep; rw [hout]; split_ifs with hq h0 · rfl - · rw [tape_writeAndMove_cells_self, if_pos h0]; rfl - · rw [tape_writeAndMove_cells_self, if_neg h0] + · rw [tape_writeAndMove_cells_self, ite_eq_left h0]; rfl + · rw [tape_writeAndMove_cells_self, ite_eq_right h0] have hWorkNe : ∀ pos, pos ≠ (c.work 0).head → ((traceStep N c (α.get (vChoice t))).work 0).cells pos = (c.work 0).cells pos := by intro pos hpos; unfold traceStep; split_ifs with hq @@ -666,8 +666,8 @@ theorem represents_step (N : NTM 1) (α : Assignment) (steps P : ℕ) (fun _ => (c.work 0).read) c.output.read).2.2.1.toΓ := by unfold traceStep; rw [hout]; split_ifs with hq h0 · rfl - · rw [tape_writeAndMove_cells_self, if_pos h0]; rfl - · rw [tape_writeAndMove_cells_self, if_neg h0] + · rw [tape_writeAndMove_cells_self, ite_eq_left h0]; rfl + · rw [tape_writeAndMove_cells_self, ite_eq_right h0] have hOutNe : ∀ pos, pos ≠ c.output.head → (traceStep N c (α.get (vChoice t))).output.cells pos = c.output.cells pos := by intro pos hpos; unfold traceStep; split_ifs with hq @@ -886,7 +886,7 @@ theorem vChoice_mem_ftraceVars (N : NTM 1) (x : List Bool) (g : ℕ → Bool) (s · exact absurd (enc_inj heq).1 (by decide) · exact absurd (enc_inj heq).1 (by decide) · rintro ⟨ht, hg⟩ - exact Or.inl (Or.inl (Or.inr ⟨t, ht, by rw [if_pos hg]⟩)) + exact Or.inl (Or.inl (Or.inr ⟨t, ht, by rw [ite_eq_left hg]⟩)) open Tableau in /-- A cell variable is in `ftraceVars` iff it names the run's symbol at an in-range cell. -/ @@ -1126,8 +1126,8 @@ theorem traceStep_work_cells_self : ((traceStep N c b).work 0).cells (c.work 0). else ((N.δ b c.state c.input.read (fun _ => (c.work 0).read) c.output.read).2.1 0).toΓ := by unfold traceStep; rw [ts_hout]; split_ifs with hq h0 · rfl - · rw [tape_writeAndMove_cells_self, if_pos h0]; rfl - · rw [tape_writeAndMove_cells_self, if_neg h0] + · rw [tape_writeAndMove_cells_self, ite_eq_left h0]; rfl + · rw [tape_writeAndMove_cells_self, ite_eq_right h0] /-- The output cell under the head after `traceStep`: unchanged when halted or at cell `0` (writes there are no-ops), otherwise the symbol `N.δ` writes. -/ @@ -1137,8 +1137,8 @@ theorem traceStep_output_cells_self : (traceStep N c b).output.cells c.output.he else (N.δ b c.state c.input.read (fun _ => (c.work 0).read) c.output.read).2.2.1.toΓ := by unfold traceStep; rw [ts_hout]; split_ifs with hq h0 · rfl - · rw [tape_writeAndMove_cells_self, if_pos h0]; rfl - · rw [tape_writeAndMove_cells_self, if_neg h0] + · rw [tape_writeAndMove_cells_self, ite_eq_left h0]; rfl + · rw [tape_writeAndMove_cells_self, ite_eq_right h0] end traceStepFields @@ -1166,7 +1166,7 @@ theorem fassign_acceptClauses (N : NTM 1) (x : List Bool) (g : ℕ → Bool) (st refine ⟨le_refl _, by norm_num, hP, ?_⟩ congr 1 unfold fcellSym - rw [if_neg (by decide : ¬(2:ℕ) = 0), if_neg (by decide : ¬(2:ℕ) = 1)] + rw [ite_eq_right (by decide : ¬(2:ℕ) = 0), ite_eq_right (by decide : ¬(2:ℕ) = 1)] exact hout.symm open Tableau in @@ -1227,14 +1227,14 @@ theorem fassign_activeClausesAt (N : NTM 1) (x : List Bool) (g : ℕ → Bool) ( have hpo : po = (fcfg N x g t).output.head := ((fassign_get_vHead N x g steps P).mp hho).2.2 have hsi : si = (fcfg N x g t).input.read := by rw [symIdx_inj ((fassign_get_vCell N x g steps P).mp hcvi).2.2.2] - unfold fcellSym Tape.read; rw [if_pos rfl, hpi] + unfold fcellSym Tape.read; rw [ite_eq_left rfl, hpi] have hsw : sw = ((fcfg N x g t).work 0).read := by rw [symIdx_inj ((fassign_get_vCell N x g steps P).mp hcvw).2.2.2] - unfold fcellSym Tape.read; rw [if_neg (by decide : (1:ℕ) ≠ 0), if_pos rfl, hpw] + unfold fcellSym Tape.read; rw [ite_eq_right (by decide : (1:ℕ) ≠ 0), ite_eq_left rfl, hpw] have hso : so = (fcfg N x g t).output.read := by rw [symIdx_inj ((fassign_get_vCell N x g steps P).mp hcvo).2.2.2] unfold fcellSym Tape.read - rw [if_neg (by decide : (2:ℕ) ≠ 0), if_neg (by decide : (2:ℕ) ≠ 1), hpo] + rw [ite_eq_right (by decide : (2:ℕ) ≠ 0), ite_eq_right (by decide : (2:ℕ) ≠ 1), hpo] have hb : b = g t := by have hbv' : (fassign N x g steps P).get (vChoice t) = b := by cases hgc : (fassign N x g steps P).get (vChoice t) <;> cases b <;> simp_all @@ -1246,22 +1246,23 @@ theorem fassign_activeClausesAt (N : NTM 1) (x : List Bool) (g : ℕ → Bool) ( refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · exact (fassign_get_vState N x g steps P).mpr ⟨by omega, by rw [fcfg_succ, traceStep_state]⟩ · refine (fassign_get_vCell N x g steps P).mpr ⟨by omega, by omega, hpi, ?_⟩ - congr 1; unfold fcellSym Tape.read; rw [if_pos rfl, fcfg_succ, traceStep_input_cells] + congr 1; unfold fcellSym Tape.read; rw [ite_eq_left rfl, fcfg_succ, traceStep_input_cells] · refine (fassign_get_vCell N x g steps P).mpr ⟨by omega, by omega, hpw, ?_⟩ congr 1; unfold fcellSym - rw [if_neg (by decide : (1:ℕ) ≠ 0), if_pos rfl, fcfg_succ, traceStep_work_cells_self] + rw [ite_eq_right (by decide : (1:ℕ) ≠ 0), ite_eq_left rfl, fcfg_succ, + traceStep_work_cells_self] · refine (fassign_get_vCell N x g steps P).mpr ⟨by omega, by omega, hpo, ?_⟩ congr 1; unfold fcellSym - rw [if_neg (by decide : (2:ℕ) ≠ 0), if_neg (by decide : (2:ℕ) ≠ 1), fcfg_succ, + rw [ite_eq_right (by decide : (2:ℕ) ≠ 0), ite_eq_right (by decide : (2:ℕ) ≠ 1), fcfg_succ, traceStep_output_cells_self] · refine (fassign_get_vHead N x g steps P).mpr ⟨by omega, by omega, ?_⟩ - unfold fheadPos; rw [if_pos rfl, fcfg_succ, traceStep_input_head] + unfold fheadPos; rw [ite_eq_left rfl, fcfg_succ, traceStep_input_head] · refine (fassign_get_vHead N x g steps P).mpr ⟨by omega, by omega, ?_⟩ unfold fheadPos - rw [if_neg (by decide : (1:ℕ) ≠ 0), if_pos rfl, fcfg_succ, traceStep_work_head] + rw [ite_eq_right (by decide : (1:ℕ) ≠ 0), ite_eq_left rfl, fcfg_succ, traceStep_work_head] · refine (fassign_get_vHead N x g steps P).mpr ⟨by omega, by omega, ?_⟩ unfold fheadPos - rw [if_neg (by decide : (2:ℕ) ≠ 0), if_neg (by decide : (2:ℕ) ≠ 1), fcfg_succ, + rw [ite_eq_right (by decide : (2:ℕ) ≠ 0), ite_eq_right (by decide : (2:ℕ) ≠ 1), fcfg_succ, traceStep_output_head] open Tableau in @@ -1281,7 +1282,7 @@ theorem accepts_to_tableau_sat (N : NTM 1) (steps : ℕ) (x : List Bool) set g : ℕ → Bool := fun i => if hi : i < steps then choices ⟨i, hi⟩ else false with hg have hcfg : fcfg N x g steps = N.trace steps choices (N.initCfg x) := by unfold fcfg - congr 1; funext i; simp only [hg]; exact dif_pos i.isLt + congr 1; funext i; simp only [hg]; exact dite_eq_left i.isLt refine ⟨fassign N x g steps (steps + x.length + 1), ?_⟩ rw [tableauCNF_eval_split] exact ⟨fassign_oneHotStates N x g steps _, fassign_oneHotCells N x g steps _, @@ -1408,7 +1409,7 @@ theorem flatToEnc_vStateF {t q : ℕ} (ht : t ≤ steps) (hq : q < Qc) : obtain ⟨h0, h1, h2, h3, h4⟩ := flatVar_decode (A := steps + 1) (B := max Qc 3) (C := P + 2) (D := 4) (tag := 0) (a := t) (b := q) (c := 0) (d := 0) (by omega) (lt_of_lt_of_le hq (le_max_left _ _)) (by omega) (by omega) - rw [vStateF, flatToEnc, if_neg (by rw [h4]; omega), h4, h3, h2, h1, h0, vState] + rw [vStateF, flatToEnc, ite_eq_right (by rw [h4]; omega), h4, h3, h2, h1, h0, vState] @[inherit_doc flatToEnc_vStateF] theorem flatToEnc_vChoiceF {t : ℕ} (ht : t ≤ steps) : @@ -1416,7 +1417,7 @@ theorem flatToEnc_vChoiceF {t : ℕ} (ht : t ≤ steps) : obtain ⟨h0, h1, h2, h3, h4⟩ := flatVar_decode (A := steps + 1) (B := max Qc 3) (C := P + 2) (D := 4) (tag := 1) (a := t) (b := 0) (c := 0) (d := 0) (by omega) (by omega) (by omega) (by omega) - rw [vChoiceF, flatToEnc, if_neg (by rw [h4]; omega), h4, h3, h2, h1, h0, vChoice] + rw [vChoiceF, flatToEnc, ite_eq_right (by rw [h4]; omega), h4, h3, h2, h1, h0, vChoice] @[inherit_doc flatToEnc_vStateF] theorem flatToEnc_vCellF {t tp pos s : ℕ} (ht : t ≤ steps) (htp : tp < 3) @@ -1426,7 +1427,7 @@ theorem flatToEnc_vCellF {t tp pos s : ℕ} (ht : t ≤ steps) (htp : tp < 3) obtain ⟨h0, h1, h2, h3, h4⟩ := flatVar_decode (A := steps + 1) (B := max Qc 3) (C := P + 2) (D := 4) (tag := 2) (a := t) (b := tp) (c := pos) (d := s) (by omega) (lt_of_lt_of_le htp (le_max_right _ _)) hpos hs - rw [vCellF, flatToEnc, if_pos h4, h3, h2, h1, h0, vCell] + rw [vCellF, flatToEnc, ite_eq_left h4, h3, h2, h1, h0, vCell] @[inherit_doc flatToEnc_vStateF] theorem flatToEnc_vHeadF {t tp pos : ℕ} (ht : t ≤ steps) (htp : tp < 3) @@ -1436,7 +1437,7 @@ theorem flatToEnc_vHeadF {t tp pos : ℕ} (ht : t ≤ steps) (htp : tp < 3) obtain ⟨h0, h1, h2, h3, h4⟩ := flatVar_decode (A := steps + 1) (B := max Qc 3) (C := P + 2) (D := 4) (tag := 3) (a := t) (b := tp) (c := pos) (d := 0) (by omega) (lt_of_lt_of_le htp (le_max_right _ _)) hpos (by omega) - rw [vHeadF, flatToEnc, if_neg (by rw [h4]; omega), h4, h3, h2, h1, h0, vHead] + rw [vHeadF, flatToEnc, ite_eq_right (by rw [h4]; omega), h4, h3, h2, h1, h0, vHead] end FlatVars diff --git a/Complexitylib/SAT/CookLevin/Assembly.lean b/Complexitylib/SAT/CookLevin/Assembly.lean index b43ea39a..2e2b50ee 100644 --- a/Complexitylib/SAT/CookLevin/Assembly.lean +++ b/Complexitylib/SAT/CookLevin/Assembly.lean @@ -415,7 +415,7 @@ theorem Tape.inits_update_tFuel (n steps P Qc tf tf' : ℕ) : · rw [Function.update_of_ne hi] show regTape (initVals n steps P Qc tf i) = regTape (initVals n steps P Qc tf' i) congr 1 - rw [initVals, initVals, if_neg hi, if_neg hi] + rw [initVals, initVals, ite_eq_right hi, ite_eq_right hi] /-- Zeroing the scratch registers `tmp`/`tmp2` of an initialized register file is a no-op: they already hold `0`. -/ diff --git a/Complexitylib/SAT/CookLevin/Internal/EmitterActive.lean b/Complexitylib/SAT/CookLevin/Internal/EmitterActive.lean index 4897a851..65aa7937 100644 --- a/Complexitylib/SAT/CookLevin/Internal/EmitterActive.lean +++ b/Complexitylib/SAT/CookLevin/Internal/EmitterActive.lean @@ -709,26 +709,26 @@ theorem activeBLevelTM_hoareTime (q : N.Q) (si sw so : Γ) refine activeLeafTM_hoareTime N q si sw so b _ _ _ _ _ hQc hB haux2 ?_ ?_ ?_ ?_ ?_ inp₀ ys' hinp₀ · by_cases hq : q = N.qhalt - · rw [if_pos hq, if_pos hq] - · rw [if_neg hq, if_neg hq] + · rw [ite_eq_left hq, ite_eq_left hq] + · rw [ite_eq_right hq, ite_eq_right hq] cases hz : pwZero with - | true => rw [if_pos rfl, if_pos (hpwZ hz)] - | false => rw [if_neg (by simp), if_neg (hpwZ' hz)] + | true => rw [ite_eq_left rfl, ite_eq_left (hpwZ hz)] + | false => rw [ite_eq_right (by simp), ite_eq_right (hpwZ' hz)] · by_cases hq : q = N.qhalt - · rw [if_pos hq, if_pos hq] - · rw [if_neg hq, if_neg hq] + · rw [ite_eq_left hq, ite_eq_left hq] + · rw [ite_eq_right hq, ite_eq_right hq] cases hz : poZero with - | true => rw [if_pos rfl, if_pos (hpoZ hz)] - | false => rw [if_neg (by simp), if_neg (hpoZ' hz)] + | true => rw [ite_eq_left rfl, ite_eq_left (hpoZ hz)] + | false => rw [ite_eq_right (by simp), ite_eq_right (hpoZ' hz)] · by_cases hq : q = N.qhalt - · rw [if_pos hq, if_pos hq]; rfl - · rw [if_neg hq, if_neg hq]; rfl + · rw [ite_eq_left hq, ite_eq_left hq]; rfl + · rw [ite_eq_right hq, ite_eq_right hq]; rfl · by_cases hq : q = N.qhalt - · rw [if_pos hq, if_pos hq]; rfl - · rw [if_neg hq, if_neg hq]; rfl + · rw [ite_eq_left hq, ite_eq_left hq]; rfl + · rw [ite_eq_right hq, ite_eq_right hq]; rfl · by_cases hq : q = N.qhalt - · rw [if_pos hq, if_pos hq]; rfl - · rw [if_neg hq, if_neg hq]; rfl + · rw [ite_eq_left hq, ite_eq_left hq]; rfl + · rw [ite_eq_right hq, ite_eq_right hq]; rfl have h := bigSeq_emit_hoareTime (fun b => activeLeafTM N q si sw so b (if q = N.qhalt then sw else if pwZero then sw diff --git a/Complexitylib/SAT/CookLevin/Internal/EmitterStart.lean b/Complexitylib/SAT/CookLevin/Internal/EmitterStart.lean index ad29ca80..de37f900 100644 --- a/Complexitylib/SAT/CookLevin/Internal/EmitterStart.lean +++ b/Complexitylib/SAT/CookLevin/Internal/EmitterStart.lean @@ -172,7 +172,7 @@ theorem startBlankPartTM_hoareTime (tp : ℕ) (htp1 : 1 ≤ tp) (htp : tp < 3) (symIdx (initCellSym x tp (j + 1)))⟩] : Clause) = [⟨true, vCellF Qc steps P 0 tp (1 + j) 2⟩] rw [show initCellSym x tp (j + 1) = Γ.blank from by - rw [initCellSym, if_neg (by omega), if_neg (by omega)], + rw [initCellSym, ite_eq_right (by omega), ite_eq_right (by omega)], show (1 : ℕ) + j = j + 1 from by omega] rfl -- Stage 1: the position-0 clause. diff --git a/Complexitylib/SAT/Internal/GuessVerify.lean b/Complexitylib/SAT/Internal/GuessVerify.lean index 4d74a5bd..fbab25b1 100644 --- a/Complexitylib/SAT/Internal/GuessVerify.lean +++ b/Complexitylib/SAT/Internal/GuessVerify.lean @@ -595,7 +595,7 @@ theorem satVerifyPhaseTM_halts_of_inner_trace_halts (M : TM k) (hinner : M.halted ((M.toNTM).trace T choices (satVerifyInnerCfg M c))) : (satVerifyPhaseTM M).halted (((satVerifyPhaseTM M).toNTM).trace T choices c) := by have hproj := satVerifyPhaseTM_trace_project_prefix M T choices c hpair - rw [satVerifyPhaseTM_halted_iff, hproj] + erw [satVerifyPhaseTM_halted_iff, hproj] exact hinner /-- One verifier-phase step preserves the invariant that the SAT pair tape has @@ -809,7 +809,7 @@ theorem satGuessVerify_counter_trace_prefix (M : TM k) : counterNTM.trace 1 (fun _ => choices ⟨0, by omega⟩) c have hstate : c.state ≠ TM.LinearCounterPhase.done := by have h0 := hnot 0 (by omega) - simpa [counterNTM, NTM.trace] using h0 + exact h0 rw [NTM.trace_succ (satGuessVerifyNTM M) T choices (satCounterWrap M c)] rw [satGuessVerify_counter_trace_one M (choices ⟨0, by omega⟩) c hstate] have htail : ∀ t (ht : t < T), @@ -870,7 +870,8 @@ theorem satGuessVerify_counter_trace_exit (M : TM k) (T : ℕ) (satGuessVerifyNTM M).trace T (fun i => choices i.castSucc) (satCounterWrap M c) = satCounterWrap M cT := by - simpa [counterNTM, counterChoices, cT] using hprefix + simp [counterNTM, counterChoices, cT] + exact hprefix rw [hsplit, hprefix'] change (satGuessVerifyNTM M).trace 1 (fun _ => choices (Fin.last T)) (satCounterWrap M cT) = @@ -1091,15 +1092,15 @@ theorem satGuessVerify_counter_init_exits (M : TM k) (x : List Bool) have hdone : (counterNTM.trace t (fun i => choicesExit ⟨i.val, by omega⟩) c0).state = TM.LinearCounterPhase.done := by - simpa [B, counterNTM, counterChoicesB, choicesExit, c0, TM.halted] - using hhalt + simp [B, counterNTM, choicesExit, c0] + exact hhalt have hnot : ∀ s (hs : s < t), (counterNTM.trace s (fun i => choicesExit ⟨i.val, by omega⟩) c0).state ≠ TM.LinearCounterPhase.done := by intro s hs have hfirst_s := hfirst s hs - simpa [B, counterNTM, counterChoicesB, choicesExit, c0, TM.halted] - using hfirst_s + simp [B, counterNTM, choicesExit, c0] + exact hfirst_s have hexit := satGuessVerify_counter_trace_exit M t choicesExit c0 hnot hdone refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ @@ -1138,7 +1139,8 @@ theorem satGuessVerify_counter_init_exits (M : TM k) (x : List Bool) exact le_trans hmove (by omega) · have hcounter_post : (cT.work (satCounterIdx k)).HasUnaryCounter (x.length + 1) := by - simpa [B, counterNTM, counterChoicesB, counterChoices, cT, c0] using hpost + simp [counterNTM, counterChoices, cT, c0] + exact hpost have hread_counter : (cT.work (satCounterIdx k)).read ≠ Γ.start := by have hcell := hcounter_post.2.1 0 (by omega : 0 < x.length + 1) simp [Tape.read, hcounter_post.1, hcell] @@ -1201,7 +1203,7 @@ theorem satGuessVerify_rewindInput_trace_prefix (M : TM k) : rewindNTM.trace 1 (fun _ => choices ⟨0, by omega⟩) c have hstate : c.state ≠ TM.RewindPhase.done := by have h0 := hnot 0 (by omega) - simpa [rewindNTM, NTM.trace] using h0 + exact h0 rw [NTM.trace_succ (satGuessVerifyNTM M) T choices (satRewindInputWrap M c)] rw [satGuessVerify_rewindInput_trace_one M (choices ⟨0, by omega⟩) c hstate] have htail : ∀ t (ht : t < T), @@ -1262,7 +1264,8 @@ theorem satGuessVerify_rewindInput_trace_exit (M : TM k) (T : ℕ) (satGuessVerifyNTM M).trace T (fun i => choices i.castSucc) (satRewindInputWrap M c) = satRewindInputWrap M cT := by - simpa [rewindNTM, rewindChoices, cT] using hprefix + simp [rewindNTM, rewindChoices, cT] + exact hprefix rw [hsplit, hprefix'] change (satGuessVerifyNTM M).trace 1 (fun _ => choices (Fin.last T)) (satRewindInputWrap M cT) = @@ -1317,21 +1320,22 @@ theorem satGuessVerify_rewindInput_exits (M : TM k) (B : ℕ) have hdone : (rewindNTM.trace t (fun i => choicesExit ⟨i.val, by omega⟩) c0).state = TM.RewindPhase.done := by - simpa [R, rewindNTM, rewindChoicesR, choicesExit, c0, TM.halted] - using hhalt + simp [R, rewindNTM, choicesExit, c0] + exact hhalt have hnot : ∀ s (hs : s < t), (rewindNTM.trace s (fun i => choicesExit ⟨i.val, by omega⟩) c0).state ≠ TM.RewindPhase.done := by intro s hs have hfirst_s := hfirst s hs - simpa [R, rewindNTM, rewindChoicesR, choicesExit, c0, TM.halted] - using hfirst_s + simp [R, rewindNTM, choicesExit, c0] + exact hfirst_s have hexit := satGuessVerify_rewindInput_trace_exit M t choicesExit c0 hnot hdone refine ⟨?_, ?_⟩ · simpa [R, rewindNTM, rewindChoices, cT, choicesExit, c0] using hexit · have hhead : cT.input.head = 1 := by - simpa [R, rewindNTM, rewindChoicesR, rewindChoices, cT, c0] using hpost + simp [rewindNTM, rewindChoices, cT, c0] + exact hpost have hcells := NTM.input_cells_trace rewindNTM t rewindChoices c0 have hnostart : ∀ j, j ≥ 1 → cT.input.cells j ≠ Γ.start := by intro j hj @@ -1410,20 +1414,21 @@ theorem satGuessVerify_rewindInput_exits_with_frames (M : TM k) (B : ℕ) have hdone : (rewindNTM.trace t (fun i => choicesExit ⟨i.val, by omega⟩) c0).state = TM.RewindPhase.done := by - simpa [R, rewindNTM, rewindChoicesR, choicesExit, c0, TM.halted] - using hhalt + simp [R, rewindNTM, choicesExit, c0] + exact hhalt have hnot : ∀ s (hs : s < t), (rewindNTM.trace s (fun i => choicesExit ⟨i.val, by omega⟩) c0).state ≠ TM.RewindPhase.done := by intro s hs have hfirst_s := hfirst s hs - simpa [R, rewindNTM, rewindChoicesR, choicesExit, c0, TM.halted] - using hfirst_s + simp [R, rewindNTM, choicesExit, c0] + exact hfirst_s have hexit := satGuessVerify_rewindInput_trace_exit M t choicesExit c0 hnot hdone have hrich_post : cT.input.head = 1 ∧ cT.work = work ∧ cT.output = out := by - simpa [R, rewindNTM, rewindChoicesR, rewindChoices, cT, c0, P] using hpost + simp [rewindNTM, rewindChoices, cT, c0] + exact hpost refine ⟨?_, ?_, ?_, ?_, ?_⟩ · simpa [R, rewindNTM, rewindChoices, cT, choicesExit, c0] using hexit · have hcells := NTM.input_cells_trace rewindNTM t rewindChoices c0 @@ -1546,7 +1551,7 @@ theorem satGuessVerify_guess_trace_prefix (M : TM k) : guessNTM.trace 1 (fun _ => choices ⟨0, by omega⟩) c have hstate : c.state ≠ NTM.GuessBoundedPhase.done := by have h0 := hnot 0 (by omega) - simpa [guessNTM, NTM.trace] using h0 + exact h0 rw [NTM.trace_succ (satGuessVerifyNTM M) T choices (satGuessWrap M c)] rw [satGuessVerify_guess_trace_one M (choices ⟨0, by omega⟩) c hstate] have htail : ∀ t (ht : t < T), @@ -1607,7 +1612,8 @@ theorem satGuessVerify_guess_trace_exit (M : TM k) (T : ℕ) (satGuessVerifyNTM M).trace T (fun i => choices i.castSucc) (satGuessWrap M c) = satGuessWrap M cT := by - simpa [guessNTM, guessChoices, cT] using hprefix + simp [guessNTM, guessChoices, cT] + exact hprefix rw [hsplit, hprefix'] change (satGuessVerifyNTM M).trace 1 (fun _ => choices (Fin.last T)) (satGuessWrap M cT) = @@ -1668,15 +1674,15 @@ theorem satGuessVerify_guess_exits (M : TM k) (B : ℕ) have hdone : (guessNTM.trace t (fun i => choicesExit ⟨i.val, by omega⟩) c0).state = NTM.GuessBoundedPhase.done := by - simpa [G, guessNTM, guessChoicesG, choicesExit, c0, NTM.halted] - using hhalt + simp [G, guessNTM, choicesExit, c0] + exact hhalt have hnot : ∀ s (hs : s < t), (guessNTM.trace s (fun i => choicesExit ⟨i.val, by omega⟩) c0).state ≠ NTM.GuessBoundedPhase.done := by intro s hs have hfirst_s := hfirst s hs - simpa [G, guessNTM, guessChoicesG, choicesExit, c0, NTM.halted] - using hfirst_s + simp [G, guessNTM, choicesExit, c0] + exact hfirst_s have hexit := satGuessVerify_guess_trace_exit M t choicesExit c0 hnot hdone refine ⟨?_, ?_⟩ @@ -1684,7 +1690,8 @@ theorem satGuessVerify_guess_exits (M : TM k) (B : ℕ) · have hguess_post : (cT.work (satWitnessIdx k)).HasBoundedBinaryString B ∧ (cT.work (satWitnessIdx k)).cells 0 = Γ.start := by - simpa [G, guessNTM, guessChoicesG, guessChoices, cT, c0] using hpost + simp [guessNTM, guessChoices, cT, c0] + exact hpost obtain ⟨bits, hlen, hbits⟩ := hguess_post.1 have hread : (cT.work (satWitnessIdx k)).read ≠ Γ.start := by have hnostart := Tape.cells_ne_start_of_hasBinaryString hbits @@ -1843,7 +1850,7 @@ theorem satGuessVerify_guess_generates_with_pair_frame (M : TM k) (B : ℕ) obtain ⟨choicesG, hchoicesG⟩ := NTM.guessBoundedNTM_choose_generates_witness_initTape_move_right (satWitnessIdx k) (satCounterIdx k) (Ne.symm (satCounterIdx_ne_witnessIdx k)) - B [] y c0 hlen (by simp [c0]) hpre.1 hpre.2.1 hpre.2.2.1 + B [] y c0 hlen rfl hpre.1 hpre.2.1 hpre.2.2.1 obtain ⟨t, ht, hhalt, hfirst⟩ := NTM.exists_first_halt_time_of_trace_halted guessNTM G choicesG c0 hchoicesG.1 let choicesExit : Fin (t + 1) → Bool := fun i => @@ -2092,13 +2099,13 @@ theorem satGuessVerify_rewind_then_guess_generates_pair (M : TM k) (B : ℕ) rewindAllChoices (Fin.castLE (by omega : tr + 1 ≤ B + 2 + 1) i)) := by funext i unfold choices - rw [dif_pos (by simpa [Fin.castLE] using i.isLt)] + rw [dite_eq_left (by simpa [Fin.castLE] using i.isLt)] have hsuffixChoices : (fun i : Fin (tg + 1) => choices (Fin.natAdd (tr + 1) i)) = guessChoices := by funext i unfold choices - rw [dif_neg (by simp [Fin.natAdd]; omega)] + rw [dite_eq_right (by simp [Fin.natAdd]; omega)] exact congrArg guessChoices (Fin.ext (by simp [Fin.natAdd])) rw [NTM.trace_add (satGuessVerifyNTM M) (tr + 1) (tg + 1) choices (satRewindInputWrap M cRewind0)] @@ -2270,13 +2277,13 @@ theorem satGuessVerify_setup_generates_pair (M : TM k) (x y : List Bool) counterAllChoices (Fin.castLE (by omega : tc + 1 ≤ C + 1) i)) := by funext i unfold choices - rw [dif_pos (by simpa [Fin.castLE] using i.isLt)] + rw [dite_eq_left (by simpa [Fin.castLE] using i.isLt)] have hsuffixChoices : (fun i : Fin Ttail => choices (Fin.natAdd (tc + 1) i)) = tailChoices := by funext i unfold choices - rw [dif_neg (by simp [Fin.natAdd]; omega)] + rw [dite_eq_right (by simp [Fin.natAdd]; omega)] exact congrArg tailChoices (Fin.ext (by simp [Fin.natAdd])) rw [NTM.trace_add (satGuessVerifyNTM M) (tc + 1) Ttail choices ((satGuessVerifyNTM M).initCfg x)] @@ -2597,7 +2604,7 @@ theorem satGuessVerify_pair_trace_prefix (M : TM k) : pairNTM.trace 1 (fun _ => choices ⟨0, by omega⟩) c have hstate : c.state ≠ TM.PairBuildPhase.done := by have h0 := hnot 0 (by omega) - simpa [pairNTM, NTM.trace] using h0 + exact h0 rw [NTM.trace_succ (satGuessVerifyNTM M) T choices (satPairWrap M c)] rw [satGuessVerify_pair_trace_one M (choices ⟨0, by omega⟩) c hstate] have htail : ∀ t (ht : t < T), @@ -2658,7 +2665,8 @@ theorem satGuessVerify_pair_trace_exit (M : TM k) (T : ℕ) (satGuessVerifyNTM M).trace T (fun i => choices i.castSucc) (satPairWrap M c) = satPairWrap M cT := by - simpa [pairNTM, pairChoices, cT] using hprefix + simp [pairNTM, pairChoices, cT] + exact hprefix rw [hsplit, hprefix'] change (satGuessVerifyNTM M).trace 1 (fun _ => choices (Fin.last T)) (satPairWrap M cT) = @@ -2728,15 +2736,15 @@ theorem satGuessVerify_pair_exits (M : TM k) (x y : List Bool) have hdone : (pairNTM.trace t (fun i => choicesExit ⟨i.val, by omega⟩) c0).state = TM.PairBuildPhase.done := by - simpa [P, pairNTM, pairChoicesP, choicesExit, c0, inp0, TM.halted] - using hhalt + simp [P, pairNTM, choicesExit, c0, inp0] + exact hhalt have hnot : ∀ s (hs : s < t), (pairNTM.trace s (fun i => choicesExit ⟨i.val, by omega⟩) c0).state ≠ TM.PairBuildPhase.done := by intro s hs have hfirst_s := hfirst s hs - simpa [P, pairNTM, pairChoicesP, choicesExit, c0, inp0, TM.halted] - using hfirst_s + simp [P, pairNTM, choicesExit, c0, inp0] + exact hfirst_s have hexit := satGuessVerify_pair_trace_exit M t choicesExit c0 hnot hdone refine ⟨?_, ?_⟩ @@ -2744,7 +2752,8 @@ theorem satGuessVerify_pair_exits (M : TM k) (x y : List Bool) · have hpair_post : cT.work (satPairIdx k) = (Tape.init ((pair x y).map Γ.ofBool)).move Dir3.right := by - simpa [P, pairNTM, pairChoicesP, pairChoices, cT, c0, inp0] using hpost + simp [pairNTM, pairChoices, cT, c0, inp0] + exact hpost have hread : (cT.work (satPairIdx k)).read ≠ Γ.start := by rw [hpair_post] exact Tape.init_ofBool_move_right_read_ne_start (pair x y) @@ -2872,7 +2881,7 @@ theorem satGuessVerify_verify_trace_prefix (M : TM k) : verifyNTM.trace 1 (fun _ => choices ⟨0, by omega⟩) c have hstate : c.state ≠ M.qhalt := by have h0 := hnot 0 (by omega) - simpa [verifyNTM, NTM.trace] using h0 + exact h0 rw [NTM.trace_succ (satGuessVerifyNTM M) T choices (satVerifyWrap M c)] rw [satGuessVerify_verify_trace_one M (choices ⟨0, by omega⟩) c hstate] have htail : ∀ t (ht : t < T), @@ -2912,7 +2921,8 @@ theorem satGuessVerify_verify_halts_of_phase_halts (M : TM k) M.qhalt := by intro s hs have hfirst_s := hfirst s hs - simpa [verifyNTM, choicesT, NTM.halted] using hfirst_s + simp [verifyNTM, choicesT] + exact hfirst_s have hprefix := satGuessVerify_verify_trace_prefix M t choicesT c hprefixHyp have hhalt_composed_t : (satGuessVerifyNTM M).halted @@ -2975,7 +2985,7 @@ theorem satGuessVerify_verify_outputs_of_inner_trace_output_clean (M : TM k) simpa [verifyNTM, phaseT] using satVerifyPhaseTM_trace_project_prefix M T choices c hguard have hphaseHalt : (satVerifyPhaseTM M).halted phaseT := by - rw [satVerifyPhaseTM_halted_iff, hproj] + erw [satVerifyPhaseTM_halted_iff, hproj] exact hinnerHalt have hphaseOut : phaseT.output.cells 1 = g := by have hprojOut := @@ -2983,7 +2993,7 @@ theorem satGuessVerify_verify_outputs_of_inner_trace_output_clean (M : TM k) exact hprojOut.trans hinnerOut obtain ⟨t, ht, hhalt_t, hfirst⟩ := NTM.exists_first_halt_time_of_trace_halted verifyNTM T choices c - (by simpa [verifyNTM, phaseT] using hphaseHalt) + (by simp only [verifyNTM] ; exact hphaseHalt) let choicesT : Fin t → Bool := fun i => choices (Fin.castLE ht i) have hprefixHyp : ∀ s (hs : s < t), (verifyNTM.trace s @@ -2991,7 +3001,8 @@ theorem satGuessVerify_verify_outputs_of_inner_trace_output_clean (M : TM k) M.qhalt := by intro s hs have hfirst_s := hfirst s hs - simpa [verifyNTM, choicesT, NTM.halted] using hfirst_s + simp [verifyNTM, choicesT] + exact hfirst_s have hprefix := satGuessVerify_verify_trace_prefix M t choicesT c hprefixHyp have hcomposed_t_halt : (satGuessVerifyNTM M).halted @@ -3345,7 +3356,8 @@ theorem satGuessVerify_pair_exits_then_verify_halts (M : TM k) (fun i => runChoices (Fin.castLE (Nat.le_add_right (t + 1) V) i)) (satPairWrap M c0) = satVerifyWrap M cVerify := by rw [hprefixChoices] - simpa [P, pairNTM, pairChoices, c0, cT, cVerify, choicesPair] using hpairExit.1 + simp [P, pairNTM, pairChoices, c0, cT, cVerify, choicesPair] + exact hpairExit.1 have hpairExact : cVerify.work (satPairIdx k) = (Tape.init ((pair x y).map Γ.ofBool)).move Dir3.right := by simpa [P, pairNTM, pairChoices, c0, cT, cVerify, choicesPair, runChoices] @@ -3925,14 +3937,14 @@ theorem satGuessVerify_init_generates_witness_then_verify_halts (M : TM k) setupChoices := by funext i unfold choices - rw [dif_pos (by simp [Fin.castLE])] + rw [dite_eq_left (by simp [Fin.castLE])] exact congrArg setupChoices (Fin.ext (by simp [Fin.castLE])) have hsuffixChoices : (fun i : Fin (tpair + 1 + V) => choices (Fin.natAdd Tsetup i)) = suffixChoices := by funext i unfold choices - rw [dif_neg (by simp [Fin.natAdd])] + rw [dite_eq_right (by simp [Fin.natAdd])] exact satGuessVerify_halts_after_prefix M Tsetup (tpair + 1 + V) choices ((satGuessVerifyNTM M).initCfg x) (satPairWrap M cPair0) (by rw [hprefixChoices]; exact hsetupTrace0) @@ -3995,14 +4007,14 @@ theorem satGuessVerify_init_generates_witness_halts_of_decidesInTime (M : TM k) setupChoices := by funext i unfold choices - rw [dif_pos (by simp [Fin.castLE])] + rw [dite_eq_left (by simp [Fin.castLE])] exact congrArg setupChoices (Fin.ext (by simp [Fin.castLE])) have hsuffixChoices : (fun i : Fin (tpair + 1 + V) => choices (Fin.natAdd Tsetup i)) = suffixChoices := by funext i unfold choices - rw [dif_neg (by simp [Fin.natAdd])] + rw [dite_eq_right (by simp [Fin.natAdd])] exact congrArg suffixChoices (Fin.ext (by simp [Fin.natAdd])) exact satGuessVerify_halts_after_prefix M Tsetup (tpair + 1 + V) choices ((satGuessVerifyNTM M).initCfg x) (satPairWrap M cPair0) @@ -4069,14 +4081,14 @@ theorem satGuessVerify_init_generates_witness_accepts_of_decidesInTime (M : TM k setupChoices := by funext i unfold choices - rw [dif_pos (by simp [Fin.castLE])] + rw [dite_eq_left (by simp [Fin.castLE])] exact congrArg setupChoices (Fin.ext (by simp [Fin.castLE])) have hsuffixChoices : (fun i : Fin (tpair + 1 + V) => choices (Fin.natAdd Tsetup i)) = suffixChoices := by funext i unfold choices - rw [dif_neg (by simp [Fin.natAdd])] + rw [dite_eq_right (by simp [Fin.natAdd])] exact congrArg suffixChoices (Fin.ext (by simp [Fin.natAdd])) exact satGuessVerify_accepts_after_prefix M Tsetup (tpair + 1 + V) choices ((satGuessVerifyNTM M).initCfg x) (satPairWrap M cPair0) diff --git a/Complexitylib/SAT/QBF.lean b/Complexitylib/SAT/QBF.lean index 3fd54b7e..55f037a3 100644 --- a/Complexitylib/SAT/QBF.lean +++ b/Complexitylib/SAT/QBF.lean @@ -190,7 +190,7 @@ theorem eval_update_not_mem (α : ℕ → Bool) (i : ℕ) (b : Bool) (φ : QBF) apply eval_eq_of_agree intro j hj have hji : j ≠ i := fun h => hi (h ▸ hj) - simp only [Function.update_apply, if_neg hji] + simp only [Function.update_apply, ite_eq_right hji] /-- **Vacuous existential quantification.** Quantifying `∃` over a variable that does not occur free is a no-op: `eval α (∃ x_i, φ) = eval α φ`. -/ diff --git a/Complexitylib/SAT/ThreeSAT/Syntax.lean b/Complexitylib/SAT/ThreeSAT/Syntax.lean index 0bb36d17..a5b98a25 100644 --- a/Complexitylib/SAT/ThreeSAT/Syntax.lean +++ b/Complexitylib/SAT/ThreeSAT/Syntax.lean @@ -161,9 +161,9 @@ private theorem foldl_cnf_eq_start_iff (formula : CNF) : rw [CNF.tokens, List.foldl_append] rw [foldl_clause] by_cases hclause : clause.length = 3 - · rw [if_pos hclause, ih] + · rw [ite_eq_left hclause, ih] simp [CNF.is3CNF_cons, hclause] - · rw [if_neg hclause, foldl_invalid] + · rw [ite_eq_right hclause, foldl_invalid] simp [tokenStart, CNF.is3CNF_cons, hclause] /-- A typed CNF's bit encoding is accepted exactly when it is exact 3-CNF. -/ diff --git a/Complexitylib/SAT/Tseitin/Internal/Streaming.lean b/Complexitylib/SAT/Tseitin/Internal/Streaming.lean index 8c322800..b96a213d 100644 --- a/Complexitylib/SAT/Tseitin/Internal/Streaming.lean +++ b/Complexitylib/SAT/Tseitin/Internal/Streaming.lean @@ -178,7 +178,9 @@ private theorem run_raw_literal_internal (st : State) (hscan : st.scan = .bounda simp only [Lit.rawTokens, Lit.encodeRaw, Unary.encode, List.map_cons, run] rw [show step st (.bit sign) = some { st with scan := .literal sign 0 } by simp only [step, hscan]] - simpa only [Nat.zero_add] using run_true_body_internal st sign 0 var + have h := run_true_body_internal st sign 0 var + rw [Nat.zero_add] at h + exact h private theorem run_literal_internal (st : State) (hscan : st.scan = .boundary) (lit : Lit) : diff --git a/Complexitylib/SAT/Tseitin/Machine.lean b/Complexitylib/SAT/Tseitin/Machine.lean index 0ce1e95c..c265e37f 100644 --- a/Complexitylib/SAT/Tseitin/Machine.lean +++ b/Complexitylib/SAT/Tseitin/Machine.lean @@ -39,8 +39,7 @@ reduction within an explicit quartic time bound. -/ theorem reductionTM_computesInTime : reductionTM.ComputesInTime reduction (fun n => 6 * n + 16384 * (n + 2) ^ 4 + 49) := by - simpa only [reductionMachineTime] using - reductionTM_computesInTime_internal + exact reductionTM_computesInTime_internal end Machine diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/BufferSpecs.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/BufferSpecs.lean index 2f57acf3..47cea885 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/BufferSpecs.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/BufferSpecs.lean @@ -191,9 +191,16 @@ theorem emitClauseTM_hoareTime_internal have hC := TM.emitLitTM_hoareTime cSign cReg c inp work ((ys ++ literalBits aSign a) ++ literalBits bSign b) hinp (fun i _ => hwork i) (by rw [hc]; exact TM.reg_regT c) - have hSep := TM.emitBitsTM_hoareTime [true, false] inp work - (((ys ++ literalBits aSign a) ++ literalBits bSign b) ++ literalBits cSign c) - hinp hwork + have hSep : (TM.emitBitsTM (n := workTapeCount) [true, false]).HoareTime + (TM.EmitPred inp work + (((ys ++ literalBits aSign a) ++ literalBits bSign b) ++ literalBits cSign c)) + (TM.EmitPred inp work + ((((ys ++ literalBits aSign a) ++ literalBits bSign b) ++ literalBits cSign c) ++ + [true, false])) + 2 := + TM.emitBitsTM_hoareTime [true, false] inp work + (((ys ++ literalBits aSign a) ++ literalBits bSign b) ++ literalBits cSign c) + hinp hwork have hA' := TM.Experimental.EmitSpec.ofHoareTime hinp hwork (by simpa [literalBits] using hA) have hB' := TM.Experimental.EmitSpec.ofHoareTime hinp hwork diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerLift.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerLift.lean index 3189b021..33d2faa3 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerLift.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerLift.lean @@ -118,7 +118,7 @@ theorem validEmitterTM_increment_step_internal (mode : StreamMode) simp [controllerIncrementCfg, validEmitterTM, controllerIncrement, controllerDone] simp only [TM.step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - rw [TM.step, if_neg hnotDone] + rw [TM.step, ite_eq_right hnotDone] simp only [controllerIncrementCfg, validEmitterTM, controllerIncrement, controllerDone, hne, ↓reduceIte] @@ -170,7 +170,7 @@ theorem validEmitterTM_commit_step_internal (pending : PendingSigns) (sign : Boo simp [controllerCommitCfg, validEmitterTM, controllerCommit, controllerDone] simp only [TM.step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - rw [TM.step, if_neg hnotDone] + rw [TM.step, ite_eq_right hnotDone] simp only [controllerCommitCfg, validEmitterTM, controllerCommit, controllerDone, hne, ↓reduceIte] @@ -223,7 +223,7 @@ theorem validEmitterTM_close_step_internal (pending : PendingSigns) simp [controllerCloseCfg, validEmitterTM, controllerClose, controllerDone] simp only [TM.step, hne, ↓reduceIte, Option.some.injEq] at hstep subst hstep - rw [TM.step, if_neg hnotDone] + rw [TM.step, ite_eq_right hnotDone] simp only [controllerCloseCfg, validEmitterTM, controllerClose, controllerDone, hne, ↓reduceIte] diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerToken.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerToken.lean index fe5de885..c57e0c28 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerToken.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/ControllerToken.lean @@ -157,7 +157,7 @@ theorem validEmitterTM_streaming_step_internal {Q : Type} refine ⟨c', 2 + t, by omega, htotal, ?_⟩ rcases hpost with ⟨hstate, hpost⟩ refine ⟨?_, ?_⟩ - · simpa [old] using hstate + · exact hstate · change BufferPred input' (BufferValues.ofStreaming { next, pending, scan := .literal sign (var + 1), emitted }) @@ -188,7 +188,8 @@ theorem validEmitterTM_streaming_step_internal {Q : Type} refine ⟨c', 2 + t, by omega, htotal, ?_⟩ rcases hpost with ⟨hstate, hpost⟩ refine ⟨?_, ?_⟩ - · simpa [old] using hstate + · simp + exact hstate · change BufferPred input' (BufferValues.ofStreaming (Streaming.pushLiteral old { sign, var })) diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/EmitterSpec.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/EmitterSpec.lean index bb373859..eaa89b0d 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/EmitterSpec.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/EmitterSpec.lean @@ -136,7 +136,8 @@ theorem validEmitterTM_hoareTime_internal (phi : CNF) : refine ⟨controllerDoneCfg cRun, tRun + 1, htime, ?_, ?_, ?_⟩ · simpa only [c₀] using hreach · rfl - · simpa only [controllerDoneCfg] using hpredRun + · simp only [controllerDoneCfg] + exact hpredRun /-- Quartic-rounded typed-input specification for the concrete valid emitter. -/ diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/InvalidBranchSpec.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/InvalidBranchSpec.lean index 74e30ef2..56f564b5 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/InvalidBranchSpec.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/InvalidBranchSpec.lean @@ -61,7 +61,7 @@ private theorem invalidBranch_hoareTime (z : List Bool) : have hseq := TM.seqTM_hoareTime clearValidationOutputTM (TM.emitBitsTM fallbackEncoding) hclear (TM.emitPred_transition hinp hwork []) hemit - simpa only [validationBranchPre, invalidReductionPost] using hseq + exact hseq /-! ## Validation branch routing -/ @@ -74,7 +74,9 @@ private theorem validation_to_invalid_then (z : List Bool) out.cells 1 = Γ.one → False := by rintro inp work out hpost hone have hzero : out.cells 1 = Γ.zero := by - simpa [hvalid] using hpost.2.2.2.2.2.1 + have h := hpost.2.2.2.2.2.1 + rw [hvalid] at h + exact h rw [hzero] at hone contradiction @@ -137,7 +139,7 @@ theorem reductionTMWith_invalid_hoareTime_internal hseedTransition hifBound have hallBound := hall.mono_bound (by omega : (4 * z.length + 11) + 1 + (z.length + 37) ≤ 5 * z.length + 49) - simpa only [reductionTMWith, validBranch, invalidBranch] using hallBound + exact hallBound /-- Execution-level corollary from the standard initial configuration. -/ theorem reductionTMWith_invalid_reachesIn_internal diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/Setup.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/Setup.lean index 6f160417..3f4f585f 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/Setup.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/Setup.lean @@ -124,7 +124,7 @@ theorem clearValidationOutputTM_hoareTime_internal out₀.write Γw.blank := by change (out₀.write Γw.blank).move (TM.idleDir out₀.read) = out₀.write Γw.blank - rw [TM.idleDir, if_neg hout₀.read_ne_start] + rw [TM.idleDir, ite_eq_right hout₀.read_ne_start] rfl have hstep : clearValidationOutputTM.step { state := TM.BumpPhase.go, input := inp₀, work := work₀, output := out₀ } = @@ -241,8 +241,7 @@ theorem fallbackEmitter_hoareTime_internal (TM.EmitPred inp₀ work₀ fallbackEncoding) 28 := by have hlength : fallbackEncoding.length = 28 := by decide - simpa only [List.nil_append, hlength] using - TM.emitBitsTM_hoareTime fallbackEncoding inp₀ work₀ [] hinp₀ hwork₀ + exact TM.emitBitsTM_hoareTime fallbackEncoding inp₀ work₀ [] hinp₀ hwork₀ end Machine diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/ValidBranchAssembly.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/ValidBranchAssembly.lean index da20dc10..5d6af1bf 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/ValidBranchAssembly.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/ValidBranchAssembly.lean @@ -92,7 +92,9 @@ private theorem validation_to_valid_else (z : List Bool) out.cells 1 ≠ Γ.one → False := by rintro inp work out hpost hne have hone : out.cells 1 = Γ.one := by - simpa [hvalid] using hpost.2.2.2.2.2.1 + have h := hpost.2.2.2.2.2.1 + rw [hvalid] at h + exact h exact hne hone /-! ## Full valid path -/ diff --git a/Complexitylib/SAT/Tseitin/Machine/Internal/ValidationFramed.lean b/Complexitylib/SAT/Tseitin/Machine/Internal/ValidationFramed.lean index 15bb5aca..a92bd4af 100644 --- a/Complexitylib/SAT/Tseitin/Machine/Internal/ValidationFramed.lean +++ b/Complexitylib/SAT/Tseitin/Machine/Internal/ValidationFramed.lean @@ -82,7 +82,7 @@ private theorem validationTM_step_halt_framed c'.input = c.input ∧ c'.work = c.work ∧ c'.output = c.output.write (Γw.ofBool state.accepts) := by simp only [TM.step, hst, validationTM, reduceCtorEq, ↓reduceIte, hiStart, - if_pos hiBlank] + ite_eq_left hiBlank] have hoMove : TM.idleDir c.output.read = Dir3.stay := by simp [TM.idleDir, hout.read_ne_start] refine ⟨_, rfl, rfl, ?_, ?_, ?_⟩ diff --git a/Complexitylib/SAT/Verifier.lean b/Complexitylib/SAT/Verifier.lean index fec4d109..e8f5ddd3 100644 --- a/Complexitylib/SAT/Verifier.lean +++ b/Complexitylib/SAT/Verifier.lean @@ -381,7 +381,7 @@ theorem CNF.decode?_sound {z : List Bool} {φ : CNF} simp [htok] at h have hz : z = encodeTokens toks := tokenize?_sound htok have htoks : toks = CNF.tokens φ := by - simpa using (parseTokensAux_sound h) + exact parseTokensAux_sound h calc z = encodeTokens toks := hz _ = encodeTokens (CNF.tokens φ) := by rw [htoks] diff --git a/Complexitylib/SAT/VerifierTM.lean b/Complexitylib/SAT/VerifierTM.lean index 2563a5b5..e4d7a07b 100644 --- a/Complexitylib/SAT/VerifierTM.lean +++ b/Complexitylib/SAT/VerifierTM.lean @@ -116,7 +116,7 @@ private theorem retargetInput_step_preserves_input_of_read_ne_start {k : ℕ} (M simp only [TM.step, TM.retargetInput] at hstep split at hstep · simp at hstep - · simp only [Option.some.injEq] at hstep + · injection hstep with hstep subst hstep simp [TM.idleDir, hinp, Tape.move] @@ -685,7 +685,7 @@ theorem satCounter3TM_started_hoareTime (z α : List Bool) : (∀ i : Fin 2, work ⟨i.val, by omega⟩ = innerWork i) ∧ work ⟨2, by omega⟩ = vin) (TM.inputLengthPlusOneCounterTime z.length) := by - simpa [satCounter3TM] using hret + exact hret refine hret'.strengthen_post ?_ intro _inp work out hpost rcases hpost with ⟨vin, innerWork, hinner, hmap, hvin⟩ @@ -727,7 +727,7 @@ theorem satCounter3TM_started_stableInput_hoareTime (z α : List Bool) : c'.input = inp := retargetInput_reachesIn_preserves_input_of_read_ne_start (TM.inputLengthPlusOneCounterTM (n := 2) counterIdx) - (by simpa [satCounter3TM] using hreach) + (by simp only [satCounter3TM] at hreach; exact hreach) hpre.1 refine ⟨c', t, ht, hreach, hhalt, ?_⟩ rw [hinput_keep] @@ -1630,7 +1630,6 @@ private theorem satEval_rewindAlpha_left_step (mode : SatEvalMode) · have hread0 : (c.work (0 : Fin 1)).read ≠ Γ.start := by simpa using hread simp [c', satEvalOnInputTM, TM.step, satEvalDelta, hstate, hread0] - rfl · exact TM.transitionInput_eq_self hinp · simp [c', Tape.writeAndMove, Tape.move, Tape.write_head] · exact TM.tape_readBackWrite_preserves _ _ (Or.inr hread) @@ -1668,7 +1667,6 @@ private theorem satEval_rewindAlpha_base_step (mode : SatEvalMode) · have hread0 : (c.work (0 : Fin 1)).read = Γ.start := by simpa using hread simp [c', satEvalOnInputTM, TM.step, satEvalDelta, hstate, hread0] - rfl · exact TM.transitionInput_eq_self hinp · have hhead00 : (c.work (0 : Fin 1)).head = 0 := by simpa using hhead0 @@ -1907,6 +1905,7 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : refine ⟨c', 1, by simp only [List.length_nil]; omega, .step hstep .zero, hhalt, ?_⟩ rw [hout', finishEvalMode_toΓ_eq_finish mode var] simp [satEvalSemRun] + rfl | cons tok toks ih => intro mode var c hstate hinput hcells hhead hout have hwork_read : (c.work ⟨0, by omega⟩).read ≠ Γ.start := by @@ -1944,13 +1943,15 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : hstate2 hinput2 hcells2 hhead2 hout2_started refine ⟨c', 2 + t, by simp only [List.length_cons]; omega, TM.reachesIn_trans _ hreach2 hreach, hhalt, ?_⟩ - simpa [satEvalSemRun, satEvalSemStep] using hout' + simp [satEvalSemRun, satEvalSemStep] + exact hout' | inLit cnf clause empty sign => refine ⟨c2, 2, by simp only [List.length_cons]; omega, hreach2, ?_, ?_⟩ - · simpa [satEvalOnInputTM] using hstate2 + · simp [satEvalOnInputTM] + exact hstate2 · rw [hout2, hout] - simpa [satEvalSemRun, satEvalSemStep, tokenOfBits, satEvalTokenStep] - using satEval_reject_output_zero _ (by rfl) + simp [satEvalSemRun, satEvalSemStep, tokenOfBits, satEvalTokenStep] + exact satEval_reject_output_zero _ (by rfl) | true => have hinput_bits : hasBoolSuffix c.input (true :: true :: encodeTokens toks) := by simpa [encodeTokens_cons, EncToken.encode] using hinput @@ -1979,7 +1980,8 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : hstate2 hinput2 hcells2 hhead2 hout2_started refine ⟨c', 2 + t, by simp only [List.length_cons]; omega, TM.reachesIn_trans _ hreach2 hreach, hhalt, ?_⟩ - simpa [satEvalSemRun, satEvalSemStep] using hout' + simp [satEvalSemRun, satEvalSemStep] + exact hout' | inLit cnf clause empty sign => have hcells2 : (c2.work ⟨0, by omega⟩).cells = (Tape.init (α.map Γ.ofBool)).cells := by @@ -1999,7 +2001,8 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : hstate2 hinput2 hcells2 hhead2 hout2_started refine ⟨c', 2 + t, by simp only [List.length_cons]; omega, TM.reachesIn_trans _ hreach2 hreach, hhalt, ?_⟩ - simpa [satEvalSemRun, satEvalSemStep] using hout' + simp [satEvalSemRun, satEvalSemStep] + exact hout' | litSep => have hinput_bits : hasBoolSuffix c.input (false :: true :: encodeTokens toks) := by simpa [encodeTokens_cons, EncToken.encode] using hinput @@ -2009,10 +2012,11 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : cases mode with | boundary cnf clause empty => refine ⟨c2, 2, by simp only [List.length_cons]; omega, hreach2, ?_, ?_⟩ - · simpa [satEvalOnInputTM] using hstate2 + · simp [satEvalOnInputTM] + exact hstate2 · rw [hout2, hout] - simpa [satEvalSemRun, satEvalSemStep, tokenOfBits, satEvalTokenStep] - using satEval_reject_output_zero _ (by rfl) + simp [satEvalSemRun, satEvalSemStep, tokenOfBits, satEvalTokenStep] + exact satEval_reject_output_zero _ (by rfl) | inLit cnf clause empty sign => have hread_alpha : (c.work ⟨0, by omega⟩).read = @@ -2075,7 +2079,8 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : TM.reachesIn_trans _ (TM.reachesIn_trans _ hreach2 hrewind) hreach, hhalt, ?_⟩ - simpa [satEvalSemRun, satEvalSemStep] using hout' + simp [satEvalSemRun, satEvalSemStep] + exact hout' | clauseSep => have hinput_bits : hasBoolSuffix c.input (true :: false :: encodeTokens toks) := by simpa [encodeTokens_cons, EncToken.encode] using hinput @@ -2104,13 +2109,15 @@ private theorem satEvalOnInputTM_token_loop_correct (α : Assignment) : hstate2 hinput2 hcells2 hhead2 hout2_started refine ⟨c', 2 + t, by simp only [List.length_cons]; omega, TM.reachesIn_trans _ hreach2 hreach, hhalt, ?_⟩ - simpa [satEvalSemRun, satEvalSemStep] using hout' + simp [satEvalSemRun, satEvalSemStep] + exact hout' | inLit cnf clause empty sign => refine ⟨c2, 2, by simp only [List.length_cons]; omega, hreach2, ?_, ?_⟩ - · simpa [satEvalOnInputTM] using hstate2 + · simp [satEvalOnInputTM] + exact hstate2 · rw [hout2, hout] - simpa [satEvalSemRun, satEvalSemStep, tokenOfBits, satEvalTokenStep] - using satEval_reject_output_zero _ (by rfl) + simp [satEvalSemRun, satEvalSemStep, tokenOfBits, satEvalTokenStep] + exact satEval_reject_output_zero _ (by rfl) private theorem satEvalOnInputTM_tokenize_none_reject (α : Assignment) : ∀ (suffix : List Bool) (mode : SatEvalMode) (var : ℕ) @@ -2200,7 +2207,8 @@ private theorem satEvalOnInputTM_tokenize_none_reject (α : Assignment) : TM.reachesIn_trans _ hreach2 hreach, hhalt, hout'⟩ | inLit cnf clause empty sign => refine ⟨c2, 2, by simp only [List.length_cons] at hlen; omega, hreach2, ?_, ?_⟩ - · simpa [satEvalOnInputTM] using hstate2 + · simp [satEvalOnInputTM] + exact hstate2 · rw [hout2, hout] simpa [tokenOfBits, satEvalTokenStep] using satEval_reject_output_zero _ (by rfl) @@ -2208,7 +2216,8 @@ private theorem satEvalOnInputTM_tokenize_none_reject (α : Assignment) : cases mode with | boundary cnf clause empty => refine ⟨c2, 2, by simp only [List.length_cons] at hlen; omega, hreach2, ?_, ?_⟩ - · simpa [satEvalOnInputTM] using hstate2 + · simp [satEvalOnInputTM] + exact hstate2 · rw [hout2, hout] simpa [tokenOfBits, satEvalTokenStep] using satEval_reject_output_zero _ (by rfl) @@ -2301,7 +2310,8 @@ private theorem satEvalOnInputTM_tokenize_none_reject (α : Assignment) : TM.reachesIn_trans _ hreach2 hreach, hhalt, hout'⟩ | inLit cnf clause empty sign => refine ⟨c2, 2, by simp only [List.length_cons] at hlen; omega, hreach2, ?_, ?_⟩ - · simpa [satEvalOnInputTM] using hstate2 + · simp [satEvalOnInputTM] + exact hstate2 · rw [hout2, hout] simpa [tokenOfBits, satEvalTokenStep] using satEval_reject_output_zero _ (by rfl) @@ -2410,7 +2420,8 @@ private theorem satEvalOnInputTM_started_correct (α z : List Bool) refine ⟨c', t, ?_, hreach, hhalt, ?_⟩ · have hzlen : z.length = 2 * toks.length := by rw [hz, encodeTokens_length] rw [hzlen]; omega - · simpa [satEvalSemBits, htok] using hout' + · simp [satEvalSemBits, htok] + exact hout' /-- Coarse polynomial budget for the split-input evaluator. Rewinding the assignment after each completed literal gives a quadratic upper bound once @@ -2531,7 +2542,7 @@ private lemma satEvalSemRun_correct (α : Assignment) (toks : List EncToken) : false true) [] [] (clauseRev.reverse :: cnfRev) ⟨rfl, ?_, ?_, ?_⟩ - · simpa [Bool.and_assoc] using h + · exact h · simp [CNF.eval, List.reverse_cons] · simp [Clause.eval] · simp @@ -2560,7 +2571,7 @@ private lemma satEvalSemRun_correct (α : Assignment) (toks : List EncToken) : (Clause.eval α clauseRev.reverse || (Assignment.get α var == sign)) false) [] ({ sign := sign, var := var } :: clauseRev) cnfRev ⟨rfl, rfl, ?_, ?_⟩ - · simpa [Lit.eval, Bool.or_assoc] using h + · exact h · simp [Clause.eval, Lit.eval] · simp | clauseSep => @@ -2582,7 +2593,7 @@ theorem satEvalSemBits_eq_decode_eval (α z : List Bool) : simp have h := satEvalSemRun_correct α toks (.boundary true false true) [] [] [] ⟨rfl, by simp [CNF.eval], by simp [Clause.eval], by simp⟩ - simpa [parseEvalResult] using h + exact h /-- Pure semantic model of the paired SAT verifier: unpair `w` into `(z, α)`, check the witness-length bound `|α| ≤ |z| + 1`, and evaluate the encoded CNF @@ -3130,7 +3141,7 @@ private theorem verifyPairSplit_afterFalse_zero_step simp [verifyPairSplitDirs, Tape.writeAndMove, Tape.move, Tape.write_head] · show (((c.work ⟨0, by omega⟩).writeAndMove _ _)).cells = _ have hne0 : (c.work ⟨0, by omega⟩).head ≠ 0 := by omega - simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, if_neg hne0] + simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, ite_eq_right hne0] simp [verifyPairSplitWrite, boolWrite, Γw.toΓ] · show ((c.work ⟨1, by omega⟩).writeAndMove _ _) = _ rw [show verifyPairSplitWrite false (fun j => (c.work j).read) ⟨1, by omega⟩ = @@ -3142,7 +3153,7 @@ private theorem verifyPairSplit_afterFalse_zero_step simp [verifyPairSplitDirs, Tape.writeAndMove, Tape.move, Tape.write_head] · show (((c.work ⟨2, by omega⟩).writeAndMove _ _)).cells = _ have hne2 : (c.work ⟨2, by omega⟩).head ≠ 0 := by omega - simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, if_neg hne2] + simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, ite_eq_right hne2] simp [verifyPairSplitWrite, Γw.toΓ] · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3248,7 +3259,7 @@ private theorem verifyPairSplit_afterTrue_one_step simp [verifyPairSplitDirs, Tape.writeAndMove, Tape.move, Tape.write_head] · show (((c.work ⟨0, by omega⟩).writeAndMove _ _)).cells = _ have hne0 : (c.work ⟨0, by omega⟩).head ≠ 0 := by omega - simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, if_neg hne0] + simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, ite_eq_right hne0] simp [verifyPairSplitWrite, boolWrite, Γw.toΓ] · show ((c.work ⟨1, by omega⟩).writeAndMove _ _) = _ rw [show verifyPairSplitWrite true (fun j => (c.work j).read) ⟨1, by omega⟩ = @@ -3260,7 +3271,7 @@ private theorem verifyPairSplit_afterTrue_one_step simp [verifyPairSplitDirs, Tape.writeAndMove, Tape.move, Tape.write_head] · show (((c.work ⟨2, by omega⟩).writeAndMove _ _)).cells = _ have hne2 : (c.work ⟨2, by omega⟩).head ≠ 0 := by omega - simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, if_neg hne2] + simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, ite_eq_right hne2] simp [verifyPairSplitWrite, Γw.toΓ] · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3685,7 +3696,6 @@ private theorem verifyPairSplit_rewindCounter_left_step have hstep : verifyPairTM.step c = some c' := by simp [c', verifyPairTM, TM.step, verifyPairDelta, hst, hread2, verifyPairPreserveWork] - rfl refine ⟨c', hstep, rfl, ?_, ?_, ?_, ?_, ?_⟩ · show ((c.work ⟨2, by omega⟩).writeAndMove (TM.readBackWrite (c.work ⟨2, by omega⟩).read).toΓ Dir3.left).head = _ @@ -3696,7 +3706,7 @@ private theorem verifyPairSplit_rewindCounter_left_step simp [Tape.write, Tape.read, Function.update_eq_self] · intro i hi show (c.work i).writeAndMove _ _ = c.work i - rw [if_neg hi] + rw [ite_eq_right hi] exact TM.tape_writeAndMove_stable (c.work i) (hframe i hi).1 (hframe i hi).2 · exact TM.transitionInput_eq_self hinp_read · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3731,7 +3741,6 @@ private theorem verifyPairSplit_rewindCounter_base_step have hstep : verifyPairTM.step c = some c' := by simp [c', verifyPairTM, TM.step, verifyPairDelta, hst, hread2, verifyPairPreserveWork] - rfl refine ⟨c', hstep, rfl, ?_, ?_, ?_, ?_, ?_⟩ · show ((c.work ⟨2, by omega⟩).writeAndMove (TM.readBackWrite (c.work ⟨2, by omega⟩).read).toΓ Dir3.right).head = _ @@ -3742,7 +3751,7 @@ private theorem verifyPairSplit_rewindCounter_base_step simp [Tape.write, hhead2] · intro i hi show (c.work i).writeAndMove _ _ = c.work i - rw [if_neg hi] + rw [ite_eq_right hi] exact TM.tape_writeAndMove_stable (c.work i) (hframe i hi).1 (hframe i hi).2 · exact TM.transitionInput_eq_self hinp_read · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3774,7 +3783,6 @@ private theorem verifyPairSplit_rewindFormula_left_step have hstep : verifyPairTM.step c = some c' := by simp [c', verifyPairTM, TM.step, verifyPairDelta, hst, hread2, verifyPairPreserveWork] - rfl refine ⟨c', hstep, rfl, ?_, ?_, ?_, ?_, ?_⟩ · show ((c.work ⟨0, by omega⟩).writeAndMove (TM.readBackWrite (c.work ⟨0, by omega⟩).read).toΓ Dir3.left).head = _ @@ -3785,7 +3793,7 @@ private theorem verifyPairSplit_rewindFormula_left_step simp [Tape.write, Tape.read, Function.update_eq_self] · intro i hi show (c.work i).writeAndMove _ _ = c.work i - rw [if_neg hi] + rw [ite_eq_right hi] exact TM.tape_writeAndMove_stable (c.work i) (hframe i hi).1 (hframe i hi).2 · exact TM.transitionInput_eq_self hinp_read · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3819,7 +3827,6 @@ private theorem verifyPairSplit_rewindFormula_base_step have hstep : verifyPairTM.step c = some c' := by simp [c', verifyPairTM, TM.step, verifyPairDelta, hst, hread2, verifyPairPreserveWork] - rfl refine ⟨c', hstep, rfl, ?_, ?_, ?_, ?_, ?_⟩ · show ((c.work ⟨0, by omega⟩).writeAndMove (TM.readBackWrite (c.work ⟨0, by omega⟩).read).toΓ Dir3.right).head = _ @@ -3830,7 +3837,7 @@ private theorem verifyPairSplit_rewindFormula_base_step simp [Tape.write, hhead2] · intro i hi show (c.work i).writeAndMove _ _ = c.work i - rw [if_neg hi] + rw [ite_eq_right hi] exact TM.tape_writeAndMove_stable (c.work i) (hframe i hi).1 (hframe i hi).2 · exact TM.transitionInput_eq_self hinp_read · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3862,7 +3869,6 @@ private theorem verifyPairSplit_rewindAssignment_left_step have hstep : verifyPairTM.step c = some c' := by simp [c', verifyPairTM, TM.step, verifyPairDelta, hst, hread2, verifyPairPreserveWork] - rfl refine ⟨c', hstep, rfl, ?_, ?_, ?_, ?_, ?_⟩ · show ((c.work ⟨1, by omega⟩).writeAndMove (TM.readBackWrite (c.work ⟨1, by omega⟩).read).toΓ Dir3.left).head = _ @@ -3873,7 +3879,7 @@ private theorem verifyPairSplit_rewindAssignment_left_step simp [Tape.write, Tape.read, Function.update_eq_self] · intro i hi show (c.work i).writeAndMove _ _ = c.work i - rw [if_neg hi] + rw [ite_eq_right hi] exact TM.tape_writeAndMove_stable (c.work i) (hframe i hi).1 (hframe i hi).2 · exact TM.transitionInput_eq_self hinp_read · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3908,7 +3914,6 @@ private theorem verifyPairSplit_rewindAssignment_base_step have hstep : verifyPairTM.step c = some c' := by simp [c', verifyPairTM, TM.step, verifyPairDelta, hst, hread2, verifyPairPreserveWork] - rfl refine ⟨c', hstep, rfl, ?_, ?_, ?_, ?_, ?_⟩ · show ((c.work ⟨1, by omega⟩).writeAndMove (TM.readBackWrite (c.work ⟨1, by omega⟩).read).toΓ Dir3.right).head = _ @@ -3919,7 +3924,7 @@ private theorem verifyPairSplit_rewindAssignment_base_step simp [Tape.write, hhead2] · intro i hi show (c.work i).writeAndMove _ _ = c.work i - rw [if_neg hi] + rw [ite_eq_right hi] exact TM.tape_writeAndMove_stable (c.work i) (hframe i hi).1 (hframe i hi).2 · exact TM.transitionInput_eq_self hinp_read · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -3975,13 +3980,13 @@ private theorem verifyPairSplit_copyAlpha_bit_step (b : Bool) simp [verifyPairCopyAlphaDirs, Tape.writeAndMove, Tape.move, Tape.write_head] · show ((c.work ⟨1, by omega⟩).writeAndMove _ _).cells = _ have hne1 : (c.work ⟨1, by omega⟩).head ≠ 0 := by omega - simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, if_neg hne1] + simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, ite_eq_right hne1] cases b <;> simp [verifyPairCopyAlphaWrite, boolWrite, Γw.toΓ, Γ.ofBool] · show ((c.work ⟨2, by omega⟩).writeAndMove _ _).head = _ simp [verifyPairCopyAlphaDirs, Tape.writeAndMove, Tape.move, Tape.write_head] · show ((c.work ⟨2, by omega⟩).writeAndMove _ _).cells = _ have hne2 : (c.work ⟨2, by omega⟩).head ≠ 0 := by omega - simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, if_neg hne2] + simp only [Tape.writeAndMove, Tape.move_cells, Tape.write, ite_eq_right hne2] simp [verifyPairCopyAlphaWrite, Γw.toΓ] · exact TM.tape_writeAndMove_stable c.output hoh hons @@ -4072,9 +4077,13 @@ private theorem verifyPairSplit_copyAlpha_loop : | cons a as ih => intro c hst hih hic0 hins hdata h0h h0ns h1h h1c0 h1ns h2h h2c0 h2ns hcnt hoh hons have hib : c.input.read = Γ.ofBool a := by - have := hdata 0 (by simp); simpa using this + have := hdata 0 (by simp) + simp only [Nat.add_zero] at this + exact this have hcounter : (c.work ⟨2, by omega⟩).read = Γ.one := by - have := hcnt 0 (by simp); simpa using this + have := hcnt 0 (by simp) + simp only [Nat.add_zero] at this + exact this obtain ⟨c1, hstep, hst1, hc1_ih, hc1_ic, hc1_0w, hc1_1h, hc1_1c, hc1_2h, hc1_2c, hc1_o⟩ := verifyPairSplit_copyAlpha_bit_step a c hst hib hcounter ⟨h0h, h0ns⟩ h1h h2h hoh hons -- transfer input invariants to c1 @@ -4694,24 +4703,24 @@ private theorem projEval_step (c c' : Cfg 3 verifyPairTM.Q) cases hcst : c.state with | evalReadFirst mode => by_cases hb : (c.work (0 : Fin 3)).read = Γ.blank - · simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + · simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairPreserveWork, hb] have hh := hwbm (TM.idleDir Γ.blank) rw [hb] at hh; exact hh.symm · cases hr : readBit? (c.work (0 : Fin 3)).read with | some b => - simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairPreserveWork, hb, hr] exact (hwbm _).symm | none => - simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairReject, satEvalReject, hb, hr] exact (hwbm _).symm | evalReadSecond mode first => cases hr : readBit? (c.work (0 : Fin 3)).read with | some second => - simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairPreserveWork, verifyPairEvalDirs, hr] refine ⟨?_, (hwbm _).symm, ?_⟩ @@ -4720,16 +4729,16 @@ private theorem projEval_step (c c' : Cfg 3 verifyPairTM.Q) obtain rfl : i = 0 := Subsingleton.elim i 0 simp | none => - simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairReject, satEvalReject, hr] exact (hwbm _).symm | evalRewindAlpha mode => by_cases ha : (c.work (1 : Fin 3)).read = Γ.start - · simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + · simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairPreserveWork, ha] refine ⟨(hwbm _).symm, ?_⟩ funext i; obtain rfl : i = 0 := Subsingleton.elim i 0; simp - · simp [TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, + · simp [Option.map, TM.step, hcst, verifyPairTM, satEvalOnInputTM, projEvalCfg, projEvalState, verifyPairDelta, satEvalDelta, verifyPairPreserveWork, ha] refine ⟨(hwbm _).symm, ?_⟩ funext i; obtain rfl : i = 0 := Subsingleton.elim i 0; simp @@ -4763,7 +4772,7 @@ private theorem verify_eval_next_state (c c' : Cfg 3 verifyPairTM.Q) have hmap : c'.state = (verifyPairDelta c.state c.input.read (fun i => (c.work i).read) c.output.read).1 := by have h := hvstep - rw [TM.step, if_neg hcne] at h + rw [TM.step, ite_eq_right hcne] at h exact congrArg Cfg.state (Option.some.inj h).symm cases hcst : c.state with | evalReadFirst mode => @@ -4780,7 +4789,8 @@ private theorem verify_eval_next_state (c c' : Cfg 3 verifyPairTM.Q) split at hmap · rw [hmap] cases (satEvalTokenStep mode (tokenOfBits first _) - ((fun i => (c.work i).read) ⟨1, by omega⟩)).1 <;> simp [isEvalState] + ((fun i => (c.work i).read) ⟨1, by omega⟩)).1 <;> + (simp [isEvalState]; try rfl) · right; exact hmap | evalRewindAlpha mode => rw [hcst] at hmap @@ -4825,7 +4835,7 @@ private theorem projEval_reaches : · obtain ⟨c', hvstep⟩ : ∃ c', verifyPairTM.step c = some c' := by have hcne : c.state ≠ verifyPairTM.qhalt := by intro h; rw [h] at hev; simp [isEvalState, verifyPairTM] at hev - rw [TM.step, if_neg hcne]; exact ⟨_, rfl⟩ + rw [TM.step, ite_eq_right hcne]; exact ⟨_, rfl⟩ have hps := projEval_step c c' hev hns hvstep rw [hps] at hstep_sat obtain rfl := Option.some.inj hstep_sat @@ -4859,6 +4869,7 @@ private theorem verifyPairSplit_eval_success (z α : List Bool) -- `projEvalCfg c0` is exactly the evaluator's started configuration. have hproj0_state : (projEvalCfg c0).state = .readFirst (.boundary true false true) := by simp only [projEvalCfg, hs0, projEvalState] + rfl have hproj0_input : (projEvalCfg c0).input = (Tape.init (z.map Γ.ofBool)).move Dir3.right := hw0 have hproj0_work : (projEvalCfg c0).work ⟨0, by omega⟩ = @@ -5093,7 +5104,7 @@ private theorem verifyPairSplit_scan_reject : | cons b2 rest2 => have hread1 : c.input.read = Γ.ofBool b1 := hasBoolSuffix_read_cons hsuf have hnext : c.input.cells (c.input.head + 1) = Γ.ofBool b2 := by - simpa using hsuf.2.1 1 (by simp) + exact hsuf.2.1 1 (by simp) cases b1 <;> cases b2 · -- false false: consume `00`, recurse on rest2 have hnone2 : unpair? rest2 = none := by @@ -5143,7 +5154,7 @@ private theorem verifyPairSplit_scan_reject : verifyPairSplit_scanX_true_step c hst hread1 hwst hoh hons have hc1read : c1.input.read = Γ.zero := by show c1.input.cells c1.input.head = _ - rw [hc1ic, hc1ih]; simpa using hnext + rw [hc1ic, hc1ih]; exact hnext obtain ⟨c', hstep2, hhalt, hz⟩ := verifyPairSplit_afterTrue_reject c1 hst1 (Or.inr hc1read) (by rw [hc1o]; exact hout) exact ⟨c', 2, by omega, diff --git a/README.md b/README.md index eccef151..b7475b5a 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ indexed in the root module `Complexitylib.lean` and mechanically guarded in `scr ## Building Install [elan](https://github.com/leanprover/elan); Lean and Mathlib versions -are pinned (currently v4.30.0). +are pinned (currently Lean v4.34.0-rc2, tracking the [cslib](https://github.com/leanprover/cslib) toolchain). ```bash lake build --wfail diff --git a/lake-manifest.json b/lake-manifest.json index c5f63b5f..8d7f2a29 100644 --- a/lake-manifest.json +++ b/lake-manifest.json @@ -5,17 +5,17 @@ "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "c5ea00351c28e24afc9f0f84379aa41082b1188f", + "rev": "e06eff5f95374108acfaf19f1ff7473aa7771df2", "name": "mathlib", "manifestFile": "lake-manifest.json", - "inputRev": "v4.30.0", + "inputRev": "e06eff5f95374108acfaf19f1ff7473aa7771df2", "inherited": false, "configFile": "lakefile.lean"}, {"url": "https://github.com/leanprover-community/plausible", "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "a456461b368b71d2accd95234832cd9c174b5437", + "rev": "d9598f07b1bc701f1e3aae163d2681c1fd978793", "name": "plausible", "manifestFile": "lake-manifest.json", "inputRev": "main", @@ -25,7 +25,7 @@ "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "c5d5b8fe6e5158def25cd28eb94e4141ad97c843", + "rev": "ba67e212be1197b84c1f1f6299488a10a3002713", "name": "LeanSearchClient", "manifestFile": "lake-manifest.json", "inputRev": "main", @@ -35,7 +35,7 @@ "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "515cf9d0c00ece5e661f6de4326a53dedc1e8ea1", + "rev": "d8823026ac7ef130c253089d95685f9877b95323", "name": "importGraph", "manifestFile": "lake-manifest.json", "inputRev": "main", @@ -45,37 +45,37 @@ "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "a84b3e2475d5c5ab979567b1ad8aea21b764bcf8", + "rev": "a8acbfd87375ff4abe14ce09db5b7664d383bc7f", "name": "proofwidgets", "manifestFile": "lake-manifest.json", - "inputRev": "v0.0.99", + "inputRev": "main", "inherited": true, "configFile": "lakefile.lean"}, {"url": "https://github.com/leanprover-community/aesop", "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "558915ae105bfd8074e22d597613d1961822adc2", + "rev": "18889deb9e83ea7420ef51c160d6f88552e744e3", "name": "aesop", "manifestFile": "lake-manifest.json", - "inputRev": "v4.30.0", + "inputRev": "master", "inherited": true, "configFile": "lakefile.toml"}, {"url": "https://github.com/leanprover-community/quote4", "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "a6e6c34c4ef182f83b219a3a5a385f51f44bdc4c", + "rev": "507746ab8f4b643ccdacb2ec4cdb5853fa9f8ab3", "name": "Qq", "manifestFile": "lake-manifest.json", - "inputRev": "v4.30.0", + "inputRev": "master", "inherited": true, "configFile": "lakefile.toml"}, {"url": "https://github.com/leanprover-community/batteries", "type": "git", "subDir": null, "scope": "leanprover-community", - "rev": "32dc18cde3684679f3c003de608743b57498c56f", + "rev": "7e23602c91bc04586b2b06de2708a041853e4681", "name": "batteries", "manifestFile": "lake-manifest.json", "inputRev": "main", @@ -85,10 +85,10 @@ "type": "git", "subDir": null, "scope": "leanprover", - "rev": "6b907cf12b2e445ccb7c24bc208ef04a1f39e84c", + "rev": "ab3a82db9fea14cf0fd7f5a2de650f4b534640af", "name": "Cli", "manifestFile": "lake-manifest.json", - "inputRev": "v4.30.0", + "inputRev": "v4.34.0-rc2", "inherited": true, "configFile": "lakefile.toml"}], "name": "complexitylib", diff --git a/lakefile.toml b/lakefile.toml index c2aab816..f259c775 100644 --- a/lakefile.toml +++ b/lakefile.toml @@ -5,7 +5,7 @@ defaultTargets = ["Complexitylib"] [[require]] name = "mathlib" scope = "leanprover-community" -rev = "v4.30.0" +rev = "e06eff5f95374108acfaf19f1ff7473aa7771df2" [[lean_lib]] name = "Complexitylib" diff --git a/lean-toolchain b/lean-toolchain index af9e5d33..b814d987 100644 --- a/lean-toolchain +++ b/lean-toolchain @@ -1 +1 @@ -leanprover/lean4:v4.30.0 +leanprover/lean4:v4.34.0-rc2 diff --git a/scripts/AxiomGuard.lean b/scripts/AxiomGuard.lean index 94585378..9dd9a2a4 100644 --- a/scripts/AxiomGuard.lean +++ b/scripts/AxiomGuard.lean @@ -120,10 +120,10 @@ run_cmd do unless env.contains headline do throwError "axiom guard: unknown headline `{headline}` — was it renamed?" - let mut moduleCount := 0 - let mut declarationCount := 0 - let mut theoremCount := 0 - let mut axiomCount := 0 + let mut moduleCount : Nat := 0 + let mut declarationCount : Nat := 0 + let mut theoremCount : Nat := 0 + let mut axiomCount : Nat := 0 let mut failures : Array AuditFailure := #[] for h : moduleIdx in *...env.header.moduleData.size do let moduleName := env.header.moduleNames[moduleIdx]!