Datasets:
AI4M
/

text
stringlengths
0
3.34M
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import linear_algebra.finite_dimensional import ring_theory.adjoin.fg import ring_theory.polynomial.scale_roots import ring_theory.polynomial.tower import linear_algebra.matrix.determinant /-! # Integral closure of a subring. If A is an R-algebra then `a : A` is integral over R if it is a root of a monic polynomial with coefficients in R. Enough theory is developed to prove that integral elements form a sub-R-algebra of A. ## Main definitions Let `R` be a `comm_ring` and let `A` be an R-algebra. * `ring_hom.is_integral_elem (f : R →+* A) (x : A)` : `x` is integral with respect to the map `f`, * `is_integral (x : A)` : `x` is integral over `R`, i.e., is a root of a monic polynomial with coefficients in `R`. * `integral_closure R A` : the integral closure of `R` in `A`, regarded as a sub-`R`-algebra of `A`. -/ open_locale classical open_locale big_operators polynomial open polynomial submodule section ring variables {R S A : Type*} variables [comm_ring R] [ring A] [ring S] (f : R →+* S) /-- An element `x` of `A` is said to be integral over `R` with respect to `f` if it is a root of a monic polynomial `p : R[X]` evaluated under `f` -/ def ring_hom.is_integral_elem (f : R →+* A) (x : A) := ∃ p : R[X], monic p ∧ eval₂ f x p = 0 /-- A ring homomorphism `f : R →+* A` is said to be integral if every element `A` is integral with respect to the map `f` -/ def ring_hom.is_integral (f : R →+* A) := ∀ x : A, f.is_integral_elem x variables [algebra R A] (R) /-- An element `x` of an algebra `A` over a commutative ring `R` is said to be *integral*, if it is a root of some monic polynomial `p : R[X]`. Equivalently, the element is integral over `R` with respect to the induced `algebra_map` -/ def is_integral (x : A) : Prop := (algebra_map R A).is_integral_elem x variable (A) /-- An algebra is integral if every element of the extension is integral over the base ring -/ def algebra.is_integral : Prop := (algebra_map R A).is_integral variables {R A} lemma ring_hom.is_integral_map {x : R} : f.is_integral_elem (f x) := ⟨X - C x, monic_X_sub_C _, by simp⟩ theorem is_integral_algebra_map {x : R} : is_integral R (algebra_map R A x) := (algebra_map R A).is_integral_map theorem is_integral_of_noetherian (H : is_noetherian R A) (x : A) : is_integral R x := begin let leval : (R[X] →ₗ[R] A) := (aeval x).to_linear_map, let D : ℕ → submodule R A := λ n, (degree_le R n).map leval, let M := well_founded.min (is_noetherian_iff_well_founded.1 H) (set.range D) ⟨_, ⟨0, rfl⟩⟩, have HM : M ∈ set.range D := well_founded.min_mem _ _ _, cases HM with N HN, have HM : ¬M < D (N+1) := well_founded.not_lt_min (is_noetherian_iff_well_founded.1 H) (set.range D) _ ⟨N+1, rfl⟩, rw ← HN at HM, have HN2 : D (N+1) ≤ D N := classical.by_contradiction (λ H, HM (lt_of_le_not_le (map_mono (degree_le_mono (with_bot.coe_le_coe.2 (nat.le_succ N)))) H)), have HN3 : leval (X^(N+1)) ∈ D N, { exact HN2 (mem_map_of_mem (mem_degree_le.2 (degree_X_pow_le _))) }, rcases HN3 with ⟨p, hdp, hpe⟩, refine ⟨X^(N+1) - p, monic_X_pow_sub (mem_degree_le.1 hdp), _⟩, show leval (X ^ (N + 1) - p) = 0, rw [linear_map.map_sub, hpe, sub_self] end theorem is_integral_of_submodule_noetherian (S : subalgebra R A) (H : is_noetherian R S.to_submodule) (x : A) (hx : x ∈ S) : is_integral R x := begin suffices : is_integral R (show S, from ⟨x, hx⟩), { rcases this with ⟨p, hpm, hpx⟩, replace hpx := congr_arg S.val hpx, refine ⟨p, hpm, eq.trans _ hpx⟩, simp only [aeval_def, eval₂, sum_def], rw S.val.map_sum, refine finset.sum_congr rfl (λ n hn, _), rw [S.val.map_mul, S.val.map_pow, S.val.commutes, S.val_apply, subtype.coe_mk], }, refine is_integral_of_noetherian H ⟨x, hx⟩ end end ring section variables {R A B S : Type*} variables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S] variables [algebra R A] [algebra R B] (f : R →+* S) theorem is_integral_alg_hom (f : A →ₐ[R] B) {x : A} (hx : is_integral R x) : is_integral R (f x) := let ⟨p, hp, hpx⟩ := hx in ⟨p, hp, by rw [← aeval_def, aeval_alg_hom_apply, aeval_def, hpx, f.map_zero]⟩ @[simp] theorem is_integral_alg_equiv (f : A ≃ₐ[R] B) {x : A} : is_integral R (f x) ↔ is_integral R x := ⟨λ h, by simpa using is_integral_alg_hom f.symm.to_alg_hom h, is_integral_alg_hom f.to_alg_hom⟩ theorem is_integral_of_is_scalar_tower [algebra A B] [is_scalar_tower R A B] (x : B) (hx : is_integral R x) : is_integral A x := let ⟨p, hp, hpx⟩ := hx in ⟨p.map $ algebra_map R A, hp.map _, by rw [← aeval_def, ← is_scalar_tower.aeval_apply, aeval_def, hpx]⟩ theorem is_integral_of_subring {x : A} (T : subring R) (hx : is_integral T x) : is_integral R x := is_integral_of_is_scalar_tower x hx lemma is_integral.algebra_map [algebra A B] [is_scalar_tower R A B] {x : A} (h : is_integral R x) : is_integral R (algebra_map A B x) := begin rcases h with ⟨f, hf, hx⟩, use [f, hf], rw [is_scalar_tower.algebra_map_eq R A B, ← hom_eval₂, hx, ring_hom.map_zero] end lemma is_integral_algebra_map_iff [algebra A B] [is_scalar_tower R A B] {x : A} (hAB : function.injective (algebra_map A B)) : is_integral R (algebra_map A B x) ↔ is_integral R x := begin refine ⟨_, λ h, h.algebra_map⟩, rintros ⟨f, hf, hx⟩, use [f, hf], exact is_scalar_tower.aeval_eq_zero_of_aeval_algebra_map_eq_zero R A B hAB hx, end theorem is_integral_iff_is_integral_closure_finite {r : A} : is_integral R r ↔ ∃ s : set R, s.finite ∧ is_integral (subring.closure s) r := begin split; intro hr, { rcases hr with ⟨p, hmp, hpr⟩, refine ⟨_, set.finite_mem_finset _, p.restriction, monic_restriction.2 hmp, _⟩, erw [← aeval_def, is_scalar_tower.aeval_apply _ R, map_restriction, aeval_def, hpr] }, rcases hr with ⟨s, hs, hsr⟩, exact is_integral_of_subring _ hsr end theorem fg_adjoin_singleton_of_integral (x : A) (hx : is_integral R x) : (algebra.adjoin R ({x} : set A)).to_submodule.fg := begin rcases hx with ⟨f, hfm, hfx⟩, existsi finset.image ((^) x) (finset.range (nat_degree f + 1)), apply le_antisymm, { rw span_le, intros s hs, rw finset.mem_coe at hs, rcases finset.mem_image.1 hs with ⟨k, hk, rfl⟩, clear hk, exact (algebra.adjoin R {x}).pow_mem (algebra.subset_adjoin (set.mem_singleton _)) k }, intros r hr, change r ∈ algebra.adjoin R ({x} : set A) at hr, rw algebra.adjoin_singleton_eq_range_aeval at hr, rcases (aeval x).mem_range.mp hr with ⟨p, rfl⟩, rw ← mod_by_monic_add_div p hfm, rw ← aeval_def at hfx, rw [alg_hom.map_add, alg_hom.map_mul, hfx, zero_mul, add_zero], have : degree (p %ₘ f) ≤ degree f := degree_mod_by_monic_le p hfm, generalize_hyp : p %ₘ f = q at this ⊢, rw [← sum_C_mul_X_eq q, aeval_def, eval₂_sum, sum_def], refine sum_mem (λ k hkq, _), rw [eval₂_mul, eval₂_C, eval₂_pow, eval₂_X, ← algebra.smul_def], refine smul_mem _ _ (subset_span _), rw finset.mem_coe, refine finset.mem_image.2 ⟨_, _, rfl⟩, rw [finset.mem_range, nat.lt_succ_iff], refine le_of_not_lt (λ hk, _), rw [degree_le_iff_coeff_zero] at this, rw [mem_support_iff] at hkq, apply hkq, apply this, exact lt_of_le_of_lt degree_le_nat_degree (with_bot.coe_lt_coe.2 hk) end theorem fg_adjoin_of_finite {s : set A} (hfs : s.finite) (his : ∀ x ∈ s, is_integral R x) : (algebra.adjoin R s).to_submodule.fg := set.finite.induction_on hfs (λ _, ⟨{1}, submodule.ext $ λ x, by { erw [algebra.adjoin_empty, finset.coe_singleton, ← one_eq_span, one_eq_range, linear_map.mem_range, algebra.mem_bot], refl }⟩) (λ a s has hs ih his, by rw [← set.union_singleton, algebra.adjoin_union_coe_submodule]; exact fg.mul (ih $ λ i hi, his i $ set.mem_insert_of_mem a hi) (fg_adjoin_singleton_of_integral _ $ his a $ set.mem_insert a s)) his lemma is_noetherian_adjoin_finset [is_noetherian_ring R] (s : finset A) (hs : ∀ x ∈ s, is_integral R x) : is_noetherian R (algebra.adjoin R (↑s : set A)) := is_noetherian_of_fg_of_noetherian _ (fg_adjoin_of_finite s.finite_to_set hs) /-- If `S` is a sub-`R`-algebra of `A` and `S` is finitely-generated as an `R`-module, then all elements of `S` are integral over `R`. -/ theorem is_integral_of_mem_of_fg (S : subalgebra R A) (HS : S.to_submodule.fg) (x : A) (hx : x ∈ S) : is_integral R x := begin -- say `x ∈ S`. We want to prove that `x` is integral over `R`. -- Say `S` is generated as an `R`-module by the set `y`. cases HS with y hy, -- We can write `x` as `∑ rᵢ yᵢ` for `yᵢ ∈ Y`. obtain ⟨lx, hlx1, hlx2⟩ : ∃ (l : A →₀ R) (H : l ∈ finsupp.supported R R ↑y), (finsupp.total A A R id) l = x, { rwa [←(@finsupp.mem_span_image_iff_total A A R _ _ _ id ↑y x), set.image_id ↑y, hy] }, -- Note that `y ⊆ S`. have hyS : ∀ {p}, p ∈ y → p ∈ S := λ p hp, show p ∈ S.to_submodule, by { rw ← hy, exact subset_span hp }, -- Now `S` is a subalgebra so the product of two elements of `y` is also in `S`. have : ∀ (jk : (↑(y.product y) : set (A × A))), jk.1.1 * jk.1.2 ∈ S.to_submodule := λ jk, S.mul_mem (hyS (finset.mem_product.1 jk.2).1) (hyS (finset.mem_product.1 jk.2).2), rw [← hy, ← set.image_id ↑y] at this, simp only [finsupp.mem_span_image_iff_total] at this, -- Say `yᵢyⱼ = ∑rᵢⱼₖ yₖ` choose ly hly1 hly2, -- Now let `S₀` be the subring of `R` generated by the `rᵢ` and the `rᵢⱼₖ`. let S₀ : subring R := subring.closure ↑(lx.frange ∪ finset.bUnion finset.univ (finsupp.frange ∘ ly)), -- It suffices to prove that `x` is integral over `S₀`. refine is_integral_of_subring S₀ _, letI : comm_ring S₀ := subring_class.to_comm_ring S₀, letI : algebra S₀ A := algebra.of_subring S₀, -- Claim: the `S₀`-module span (in `A`) of the set `y ∪ {1}` is closed under -- multiplication (indeed, this is the motivation for the definition of `S₀`). have : span S₀ (insert 1 ↑y : set A) * span S₀ (insert 1 ↑y : set A) ≤ span S₀ (insert 1 ↑y : set A), { rw span_mul_span, refine span_le.2 (λ z hz, _), rcases set.mem_mul.1 hz with ⟨p, q, rfl | hp, hq, rfl⟩, { rw one_mul, exact subset_span hq }, rcases hq with rfl | hq, { rw mul_one, exact subset_span (or.inr hp) }, erw ← hly2 ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, rw [finsupp.total_apply, finsupp.sum], refine (span S₀ (insert 1 ↑y : set A)).sum_mem (λ t ht, _), have : ly ⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩ t ∈ S₀ := subring.subset_closure (finset.mem_union_right _ $ finset.mem_bUnion.2 ⟨⟨(p, q), finset.mem_product.2 ⟨hp, hq⟩⟩, finset.mem_univ _, finsupp.mem_frange.2 ⟨finsupp.mem_support_iff.1 ht, _, rfl⟩⟩), change (⟨_, this⟩ : S₀) • t ∈ _, exact smul_mem _ _ (subset_span $ or.inr $ hly1 _ ht) }, -- Hence this span is a subring. Call this subring `S₁`. let S₁ : subring A := { carrier := span S₀ (insert 1 ↑y : set A), one_mem' := subset_span $ or.inl rfl, mul_mem' := λ p q hp hq, this $ mul_mem_mul hp hq, zero_mem' := (span S₀ (insert 1 ↑y : set A)).zero_mem, add_mem' := λ _ _, (span S₀ (insert 1 ↑y : set A)).add_mem, neg_mem' := λ _, (span S₀ (insert 1 ↑y : set A)).neg_mem }, have : S₁ = (algebra.adjoin S₀ (↑y : set A)).to_subring, { ext z, suffices : z ∈ span ↥S₀ (insert 1 ↑y : set A) ↔ z ∈ (algebra.adjoin ↥S₀ (y : set A)).to_submodule, { simpa }, split; intro hz, { exact (span_le.2 (set.insert_subset.2 ⟨(algebra.adjoin S₀ ↑y).one_mem, algebra.subset_adjoin⟩)) hz }, { rw [subalgebra.mem_to_submodule, algebra.mem_adjoin_iff] at hz, suffices : subring.closure (set.range ⇑(algebra_map ↥S₀ A) ∪ ↑y) ≤ S₁, { exact this hz }, refine subring.closure_le.2 (set.union_subset _ (λ t ht, subset_span $ or.inr ht)), rw set.range_subset_iff, intro y, rw algebra.algebra_map_eq_smul_one, exact smul_mem _ y (subset_span (or.inl rfl)) } }, have foo : ∀ z, z ∈ S₁ ↔ z ∈ algebra.adjoin ↥S₀ (y : set A), simp [this], haveI : is_noetherian_ring ↥S₀ := is_noetherian_subring_closure _ (finset.finite_to_set _), refine is_integral_of_submodule_noetherian (algebra.adjoin S₀ ↑y) (is_noetherian_of_fg_of_noetherian _ ⟨insert 1 y, by { rw [finset.coe_insert], ext z, simp [S₁], convert foo z}⟩) _ _, rw [← hlx2, finsupp.total_apply, finsupp.sum], refine subalgebra.sum_mem _ (λ r hr, _), have : lx r ∈ S₀ := subring.subset_closure (finset.mem_union_left _ (finset.mem_image_of_mem _ hr)), change (⟨_, this⟩ : S₀) • r ∈ _, rw finsupp.mem_supported at hlx1, exact subalgebra.smul_mem _ (algebra.subset_adjoin $ hlx1 hr) _ end lemma ring_hom.is_integral_of_mem_closure {x y z : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) (hz : z ∈ subring.closure ({x, y} : set S)) : f.is_integral_elem z := begin letI : algebra R S := f.to_algebra, have := (fg_adjoin_singleton_of_integral x hx).mul (fg_adjoin_singleton_of_integral y hy), rw [← algebra.adjoin_union_coe_submodule, set.singleton_union] at this, exact is_integral_of_mem_of_fg (algebra.adjoin R {x, y}) this z (algebra.mem_adjoin_iff.2 $ subring.closure_mono (set.subset_union_right _ _) hz), end theorem is_integral_of_mem_closure {x y z : A} (hx : is_integral R x) (hy : is_integral R y) (hz : z ∈ subring.closure ({x, y} : set A)) : is_integral R z := (algebra_map R A).is_integral_of_mem_closure hx hy hz lemma ring_hom.is_integral_zero : f.is_integral_elem 0 := f.map_zero ▸ f.is_integral_map theorem is_integral_zero : is_integral R (0:A) := (algebra_map R A).is_integral_zero lemma ring_hom.is_integral_one : f.is_integral_elem 1 := f.map_one ▸ f.is_integral_map theorem is_integral_one : is_integral R (1:A) := (algebra_map R A).is_integral_one lemma ring_hom.is_integral_add {x y : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x + y) := f.is_integral_of_mem_closure hx hy $ subring.add_mem _ (subring.subset_closure (or.inl rfl)) (subring.subset_closure (or.inr rfl)) theorem is_integral_add {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x + y) := (algebra_map R A).is_integral_add hx hy lemma ring_hom.is_integral_neg {x : S} (hx : f.is_integral_elem x) : f.is_integral_elem (-x) := f.is_integral_of_mem_closure hx hx (subring.neg_mem _ (subring.subset_closure (or.inl rfl))) theorem is_integral_neg {x : A} (hx : is_integral R x) : is_integral R (-x) := (algebra_map R A).is_integral_neg hx lemma ring_hom.is_integral_sub {x y : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x - y) := by simpa only [sub_eq_add_neg] using f.is_integral_add hx (f.is_integral_neg hy) theorem is_integral_sub {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x - y) := (algebra_map R A).is_integral_sub hx hy lemma ring_hom.is_integral_mul {x y : S} (hx : f.is_integral_elem x) (hy : f.is_integral_elem y) : f.is_integral_elem (x * y) := f.is_integral_of_mem_closure hx hy (subring.mul_mem _ (subring.subset_closure (or.inl rfl)) (subring.subset_closure (or.inr rfl))) theorem is_integral_mul {x y : A} (hx : is_integral R x) (hy : is_integral R y) : is_integral R (x * y) := (algebra_map R A).is_integral_mul hx hy lemma is_integral_smul [algebra S A] [algebra R S] [is_scalar_tower R S A] {x : A} (r : R) (hx : is_integral S x) : is_integral S (r • x) := begin rw [algebra.smul_def, is_scalar_tower.algebra_map_apply R S A], exact is_integral_mul is_integral_algebra_map hx, end variables (R A) /-- The integral closure of R in an R-algebra A. -/ def integral_closure : subalgebra R A := { carrier := { r | is_integral R r }, zero_mem' := is_integral_zero, one_mem' := is_integral_one, add_mem' := λ _ _, is_integral_add, mul_mem' := λ _ _, is_integral_mul, algebra_map_mem' := λ x, is_integral_algebra_map } theorem mem_integral_closure_iff_mem_fg {r : A} : r ∈ integral_closure R A ↔ ∃ M : subalgebra R A, M.to_submodule.fg ∧ r ∈ M := ⟨λ hr, ⟨algebra.adjoin R {r}, fg_adjoin_singleton_of_integral _ hr, algebra.subset_adjoin rfl⟩, λ ⟨M, Hf, hrM⟩, is_integral_of_mem_of_fg M Hf _ hrM⟩ variables {R} {A} lemma adjoin_le_integral_closure {x : A} (hx : is_integral R x) : algebra.adjoin R {x} ≤ integral_closure R A := begin rw [algebra.adjoin_le_iff], simp only [set_like.mem_coe, set.singleton_subset_iff], exact hx end lemma le_integral_closure_iff_is_integral {S : subalgebra R A} : S ≤ integral_closure R A ↔ algebra.is_integral R S := set_like.forall.symm.trans (forall_congr (λ x, show is_integral R (algebra_map S A x) ↔ is_integral R x, from is_integral_algebra_map_iff subtype.coe_injective)) lemma is_integral_sup {S T : subalgebra R A} : algebra.is_integral R ↥(S ⊔ T) ↔ algebra.is_integral R S ∧ algebra.is_integral R T := by simp only [←le_integral_closure_iff_is_integral, sup_le_iff] /-- Mapping an integral closure along an `alg_equiv` gives the integral closure. -/ lemma integral_closure_map_alg_equiv (f : A ≃ₐ[R] B) : (integral_closure R A).map (f : A →ₐ[R] B) = integral_closure R B := begin ext y, rw subalgebra.mem_map, split, { rintros ⟨x, hx, rfl⟩, exact is_integral_alg_hom f hx }, { intro hy, use [f.symm y, is_integral_alg_hom (f.symm : B →ₐ[R] A) hy], simp } end lemma integral_closure.is_integral (x : integral_closure R A) : is_integral R x := let ⟨p, hpm, hpx⟩ := x.2 in ⟨p, hpm, subtype.eq $ by rwa [← aeval_def, subtype.val_eq_coe, ← subalgebra.val_apply, aeval_alg_hom_apply] at hpx⟩ lemma ring_hom.is_integral_of_is_integral_mul_unit (x y : S) (r : R) (hr : f r * y = 1) (hx : f.is_integral_elem (x * y)) : f.is_integral_elem x := begin obtain ⟨p, ⟨p_monic, hp⟩⟩ := hx, refine ⟨scale_roots p r, ⟨(monic_scale_roots_iff r).2 p_monic, _⟩⟩, convert scale_roots_eval₂_eq_zero f hp, rw [mul_comm x y, ← mul_assoc, hr, one_mul], end theorem is_integral_of_is_integral_mul_unit {x y : A} {r : R} (hr : algebra_map R A r * y = 1) (hx : is_integral R (x * y)) : is_integral R x := (algebra_map R A).is_integral_of_is_integral_mul_unit x y r hr hx /-- Generalization of `is_integral_of_mem_closure` bootstrapped up from that lemma -/ lemma is_integral_of_mem_closure' (G : set A) (hG : ∀ x ∈ G, is_integral R x) : ∀ x ∈ (subring.closure G), is_integral R x := λ x hx, subring.closure_induction hx hG is_integral_zero is_integral_one (λ _ _, is_integral_add) (λ _, is_integral_neg) (λ _ _, is_integral_mul) lemma is_integral_of_mem_closure'' {S : Type*} [comm_ring S] {f : R →+* S} (G : set S) (hG : ∀ x ∈ G, f.is_integral_elem x) : ∀ x ∈ (subring.closure G), f.is_integral_elem x := λ x hx, @is_integral_of_mem_closure' R S _ _ f.to_algebra G hG x hx lemma is_integral.pow {x : A} (h : is_integral R x) (n : ℕ) : is_integral R (x ^ n) := (integral_closure R A).pow_mem h n lemma is_integral.nsmul {x : A} (h : is_integral R x) (n : ℕ) : is_integral R (n • x) := (integral_closure R A).nsmul_mem h n lemma is_integral.zsmul {x : A} (h : is_integral R x) (n : ℤ) : is_integral R (n • x) := (integral_closure R A).zsmul_mem h n lemma is_integral.multiset_prod {s : multiset A} (h : ∀ x ∈ s, is_integral R x) : is_integral R s.prod := (integral_closure R A).multiset_prod_mem h lemma is_integral.multiset_sum {s : multiset A} (h : ∀ x ∈ s, is_integral R x) : is_integral R s.sum := (integral_closure R A).multiset_sum_mem h lemma is_integral.prod {α : Type*} {s : finset α} (f : α → A) (h : ∀ x ∈ s, is_integral R (f x)) : is_integral R (∏ x in s, f x) := (integral_closure R A).prod_mem h lemma is_integral.sum {α : Type*} {s : finset α} (f : α → A) (h : ∀ x ∈ s, is_integral R (f x)) : is_integral R (∑ x in s, f x) := (integral_closure R A).sum_mem h lemma is_integral.det {n : Type*} [fintype n] [decidable_eq n] {M : matrix n n A} (h : ∀ i j, is_integral R (M i j)) : is_integral R M.det := begin rw [matrix.det_apply], exact is_integral.sum _ (λ σ hσ, is_integral.zsmul (is_integral.prod _ (λ i hi, h _ _)) _) end section variables (p : R[X]) (x : S) /-- The monic polynomial whose roots are `p.leading_coeff * x` for roots `x` of `p`. -/ noncomputable def normalize_scale_roots (p : R[X]) : R[X] := ∑ i in p.support, monomial i (if i = p.nat_degree then 1 else p.coeff i * p.leading_coeff ^ (p.nat_degree - 1 - i)) lemma normalize_scale_roots_coeff_mul_leading_coeff_pow (i : ℕ) (hp : 1 ≤ nat_degree p) : (normalize_scale_roots p).coeff i * p.leading_coeff ^ i = p.coeff i * p.leading_coeff ^ (p.nat_degree - 1) := begin simp only [normalize_scale_roots, finset_sum_coeff, coeff_monomial, finset.sum_ite_eq', one_mul, zero_mul, mem_support_iff, ite_mul, ne.def, ite_not], split_ifs with h₁ h₂, { simp [h₁], }, { rw [h₂, leading_coeff, ← pow_succ, tsub_add_cancel_of_le hp], }, { rw [mul_assoc, ← pow_add, tsub_add_cancel_of_le], apply nat.le_pred_of_lt, rw lt_iff_le_and_ne, exact ⟨le_nat_degree_of_ne_zero h₁, h₂⟩, }, end lemma leading_coeff_smul_normalize_scale_roots (p : R[X]) : p.leading_coeff • normalize_scale_roots p = scale_roots p p.leading_coeff := begin ext, simp only [coeff_scale_roots, normalize_scale_roots, coeff_monomial, coeff_smul, finset.smul_sum, ne.def, finset.sum_ite_eq', finset_sum_coeff, smul_ite, smul_zero, mem_support_iff], split_ifs with h₁ h₂, { simp [*] }, { simp [*] }, { rw [algebra.id.smul_eq_mul, mul_comm, mul_assoc, ← pow_succ', tsub_right_comm, tsub_add_cancel_of_le], rw nat.succ_le_iff, exact tsub_pos_of_lt (lt_of_le_of_ne (le_nat_degree_of_ne_zero h₁) h₂) }, end lemma normalize_scale_roots_support : (normalize_scale_roots p).support ≤ p.support := begin intro x, contrapose, simp only [not_mem_support_iff, normalize_scale_roots, finset_sum_coeff, coeff_monomial, finset.sum_ite_eq', mem_support_iff, ne.def, not_not, ite_eq_right_iff], intros h₁ h₂, exact (h₂ h₁).rec _, end lemma normalize_scale_roots_degree : (normalize_scale_roots p).degree = p.degree := begin apply le_antisymm, { exact finset.sup_mono (normalize_scale_roots_support p) }, { rw [← degree_scale_roots, ← leading_coeff_smul_normalize_scale_roots], exact degree_smul_le _ _ } end lemma normalize_scale_roots_eval₂_leading_coeff_mul (h : 1 ≤ p.nat_degree) (f : R →+* S) (x : S) : (normalize_scale_roots p).eval₂ f (f p.leading_coeff * x) = f p.leading_coeff ^ (p.nat_degree - 1) * (p.eval₂ f x) := begin rw [eval₂_eq_sum_range, eval₂_eq_sum_range, finset.mul_sum], apply finset.sum_congr, { rw nat_degree_eq_of_degree_eq (normalize_scale_roots_degree p) }, intros n hn, rw [mul_pow, ← mul_assoc, ← f.map_pow, ← f.map_mul, normalize_scale_roots_coeff_mul_leading_coeff_pow _ _ h, f.map_mul, f.map_pow], ring, end lemma normalize_scale_roots_monic (h : p ≠ 0) : (normalize_scale_roots p).monic := begin delta monic leading_coeff, rw nat_degree_eq_of_degree_eq (normalize_scale_roots_degree p), suffices : p = 0 → (0 : R) = 1, { simpa [normalize_scale_roots, coeff_monomial] }, exact λ h', (h h').rec _, end /-- Given a `p : R[X]` and a `x : S` such that `p.eval₂ f x = 0`, `f p.leading_coeff * x` is integral. -/ lemma ring_hom.is_integral_elem_leading_coeff_mul (h : p.eval₂ f x = 0) : f.is_integral_elem (f p.leading_coeff * x) := begin by_cases h' : 1 ≤ p.nat_degree, { use normalize_scale_roots p, have : p ≠ 0 := λ h'', by { rw [h'', nat_degree_zero] at h', exact nat.not_succ_le_zero 0 h' }, use normalize_scale_roots_monic p this, rw [normalize_scale_roots_eval₂_leading_coeff_mul p h' f x, h, mul_zero] }, { by_cases hp : p.map f = 0, { apply_fun (λ q, coeff q p.nat_degree) at hp, rw [coeff_map, coeff_zero, coeff_nat_degree] at hp, rw [hp, zero_mul], exact f.is_integral_zero }, { rw [nat.one_le_iff_ne_zero, not_not] at h', rw [eq_C_of_nat_degree_eq_zero h', eval₂_C] at h, suffices : p.map f = 0, { exact (hp this).rec _ }, rw [eq_C_of_nat_degree_eq_zero h', map_C, h, C_eq_zero] } } end /-- Given a `p : R[X]` and a root `x : S`, then `p.leading_coeff • x : S` is integral over `R`. -/ lemma is_integral_leading_coeff_smul [algebra R S] (h : aeval x p = 0) : is_integral R (p.leading_coeff • x) := begin rw aeval_def at h, rw algebra.smul_def, exact (algebra_map R S).is_integral_elem_leading_coeff_mul p x h, end end end section is_integral_closure /-- `is_integral_closure A R B` is the characteristic predicate stating `A` is the integral closure of `R` in `B`, i.e. that an element of `B` is integral over `R` iff it is an element of (the image of) `A`. -/ class is_integral_closure (A R B : Type*) [comm_ring R] [comm_semiring A] [comm_ring B] [algebra R B] [algebra A B] : Prop := (algebra_map_injective [] : function.injective (algebra_map A B)) (is_integral_iff : ∀ {x : B}, is_integral R x ↔ ∃ y, algebra_map A B y = x) instance integral_closure.is_integral_closure (R A : Type*) [comm_ring R] [comm_ring A] [algebra R A] : is_integral_closure (integral_closure R A) R A := ⟨subtype.coe_injective, λ x, ⟨λ h, ⟨⟨x, h⟩, rfl⟩, by { rintro ⟨⟨_, h⟩, rfl⟩, exact h }⟩⟩ namespace is_integral_closure variables {R A B : Type*} [comm_ring R] [comm_ring A] [comm_ring B] variables [algebra R B] [algebra A B] [is_integral_closure A R B] variables (R) {A} (B) protected theorem is_integral [algebra R A] [is_scalar_tower R A B] (x : A) : is_integral R x := (is_integral_algebra_map_iff (algebra_map_injective A R B)).mp $ show is_integral R (algebra_map A B x), from is_integral_iff.mpr ⟨x, rfl⟩ theorem is_integral_algebra [algebra R A] [is_scalar_tower R A B] : algebra.is_integral R A := λ x, is_integral_closure.is_integral R B x variables {R} (A) {B} /-- If `x : B` is integral over `R`, then it is an element of the integral closure of `R` in `B`. -/ noncomputable def mk' (x : B) (hx : is_integral R x) : A := classical.some (is_integral_iff.mp hx) @[simp] lemma algebra_map_mk' (x : B) (hx : is_integral R x) : algebra_map A B (mk' A x hx) = x := classical.some_spec (is_integral_iff.mp hx) @[simp] lemma mk'_one (h : is_integral R (1 : B) := is_integral_one) : mk' A 1 h = 1 := algebra_map_injective A R B $ by rw [algebra_map_mk', ring_hom.map_one] @[simp] lemma mk'_zero (h : is_integral R (0 : B) := is_integral_zero) : mk' A 0 h = 0 := algebra_map_injective A R B $ by rw [algebra_map_mk', ring_hom.map_zero] @[simp] lemma mk'_add (x y : B) (hx : is_integral R x) (hy : is_integral R y) : mk' A (x + y) (is_integral_add hx hy) = mk' A x hx + mk' A y hy := algebra_map_injective A R B $ by simp only [algebra_map_mk', ring_hom.map_add] @[simp] lemma mk'_mul (x y : B) (hx : is_integral R x) (hy : is_integral R y) : mk' A (x * y) (is_integral_mul hx hy) = mk' A x hx * mk' A y hy := algebra_map_injective A R B $ by simp only [algebra_map_mk', ring_hom.map_mul] @[simp] lemma mk'_algebra_map [algebra R A] [is_scalar_tower R A B] (x : R) (h : is_integral R (algebra_map R B x) := is_integral_algebra_map) : is_integral_closure.mk' A (algebra_map R B x) h = algebra_map R A x := algebra_map_injective A R B $ by rw [algebra_map_mk', ← is_scalar_tower.algebra_map_apply] section lift variables {R} (A B) {S : Type*} [comm_ring S] [algebra R S] [algebra S B] [is_scalar_tower R S B] variables [algebra R A] [is_scalar_tower R A B] (h : algebra.is_integral R S) /-- If `B / S / R` is a tower of ring extensions where `S` is integral over `R`, then `S` maps (uniquely) into an integral closure `B / A / R`. -/ noncomputable def lift : S →ₐ[R] A := { to_fun := λ x, mk' A (algebra_map S B x) (is_integral.algebra_map (h x)), map_one' := by simp only [ring_hom.map_one, mk'_one], map_zero' := by simp only [ring_hom.map_zero, mk'_zero], map_add' := λ x y, by simp_rw [← mk'_add, ring_hom.map_add], map_mul' := λ x y, by simp_rw [← mk'_mul, ring_hom.map_mul], commutes' := λ x, by simp_rw [← is_scalar_tower.algebra_map_apply, mk'_algebra_map] } @[simp] lemma algebra_map_lift (x : S) : algebra_map A B (lift A B h x) = algebra_map S B x := algebra_map_mk' _ _ _ end lift section equiv variables (R A B) (A' : Type*) [comm_ring A'] [algebra A' B] [is_integral_closure A' R B] variables [algebra R A] [algebra R A'] [is_scalar_tower R A B] [is_scalar_tower R A' B] /-- Integral closures are all isomorphic to each other. -/ noncomputable def equiv : A ≃ₐ[R] A' := alg_equiv.of_alg_hom (lift _ B (is_integral_algebra R B)) (lift _ B (is_integral_algebra R B)) (by { ext x, apply algebra_map_injective A' R B, simp }) (by { ext x, apply algebra_map_injective A R B, simp }) @[simp] lemma algebra_map_equiv (x : A) : algebra_map A' B (equiv R A B A' x) = algebra_map A B x := algebra_map_lift _ _ _ _ end equiv end is_integral_closure end is_integral_closure section algebra open algebra variables {R A B S T : Type*} variables [comm_ring R] [comm_ring A] [comm_ring B] [comm_ring S] [comm_ring T] variables [algebra A B] [algebra R B] (f : R →+* S) (g : S →+* T) lemma is_integral_trans_aux (x : B) {p : A[X]} (pmonic : monic p) (hp : aeval x p = 0) : is_integral (adjoin R (↑(p.map $ algebra_map A B).frange : set B)) x := begin generalize hS : (↑(p.map $ algebra_map A B).frange : set B) = S, have coeffs_mem : ∀ i, (p.map $ algebra_map A B).coeff i ∈ adjoin R S, { intro i, by_cases hi : (p.map $ algebra_map A B).coeff i = 0, { rw hi, exact subalgebra.zero_mem _ }, rw ← hS, exact subset_adjoin (coeff_mem_frange _ _ hi) }, obtain ⟨q, hq⟩ : ∃ q : (adjoin R S)[X], q.map (algebra_map (adjoin R S) B) = (p.map $ algebra_map A B), { rw ← set.mem_range, exact (polynomial.mem_map_range _).2 (λ i, ⟨⟨_, coeffs_mem i⟩, rfl⟩) }, use q, split, { suffices h : (q.map (algebra_map (adjoin R S) B)).monic, { refine monic_of_injective _ h, exact subtype.val_injective }, { rw hq, exact pmonic.map _ } }, { convert hp using 1, replace hq := congr_arg (eval x) hq, convert hq using 1; symmetry; apply eval_map }, end variables [algebra R A] [is_scalar_tower R A B] /-- If A is an R-algebra all of whose elements are integral over R, and x is an element of an A-algebra that is integral over A, then x is integral over R.-/ lemma is_integral_trans (A_int : is_integral R A) (x : B) (hx : is_integral A x) : is_integral R x := begin rcases hx with ⟨p, pmonic, hp⟩, let S : set B := ↑(p.map $ algebra_map A B).frange, refine is_integral_of_mem_of_fg (adjoin R (S ∪ {x})) _ _ (subset_adjoin $ or.inr rfl), refine fg_trans (fg_adjoin_of_finite (finset.finite_to_set _) (λ x hx, _)) _, { rw [finset.mem_coe, frange, finset.mem_image] at hx, rcases hx with ⟨i, _, rfl⟩, rw coeff_map, exact is_integral_alg_hom (is_scalar_tower.to_alg_hom R A B) (A_int _) }, { apply fg_adjoin_singleton_of_integral, exact is_integral_trans_aux _ pmonic hp } end /-- If A is an R-algebra all of whose elements are integral over R, and B is an A-algebra all of whose elements are integral over A, then all elements of B are integral over R.-/ lemma algebra.is_integral_trans (hA : is_integral R A) (hB : is_integral A B) : is_integral R B := λ x, is_integral_trans hA x (hB x) lemma ring_hom.is_integral_trans (hf : f.is_integral) (hg : g.is_integral) : (g.comp f).is_integral := @algebra.is_integral_trans R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra (@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra (ring_hom.comp_apply g f)) hf hg lemma ring_hom.is_integral_of_surjective (hf : function.surjective f) : f.is_integral := λ x, (hf x).rec_on (λ y hy, (hy ▸ f.is_integral_map : f.is_integral_elem x)) lemma is_integral_of_surjective (h : function.surjective (algebra_map R A)) : is_integral R A := (algebra_map R A).is_integral_of_surjective h /-- If `R → A → B` is an algebra tower with `A → B` injective, then if the entire tower is an integral extension so is `R → A` -/ lemma is_integral_tower_bot_of_is_integral (H : function.injective (algebra_map A B)) {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x := begin rcases h with ⟨p, ⟨hp, hp'⟩⟩, refine ⟨p, ⟨hp, _⟩⟩, rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map, eval₂_hom, ← ring_hom.map_zero (algebra_map A B)] at hp', rw [eval₂_eq_eval_map], exact H hp', end lemma ring_hom.is_integral_tower_bot_of_is_integral (hg : function.injective g) (hfg : (g.comp f).is_integral) : f.is_integral := λ x, @is_integral_tower_bot_of_is_integral R S T _ _ _ g.to_algebra (g.comp f).to_algebra f.to_algebra (@is_scalar_tower.of_algebra_map_eq R S T _ _ _ f.to_algebra g.to_algebra (g.comp f).to_algebra (ring_hom.comp_apply g f)) hg x (hfg (g x)) lemma is_integral_tower_bot_of_is_integral_field {R A B : Type*} [comm_ring R] [field A] [comm_ring B] [nontrivial B] [algebra R A] [algebra A B] [algebra R B] [is_scalar_tower R A B] {x : A} (h : is_integral R (algebra_map A B x)) : is_integral R x := is_integral_tower_bot_of_is_integral (algebra_map A B).injective h lemma ring_hom.is_integral_elem_of_is_integral_elem_comp {x : T} (h : (g.comp f).is_integral_elem x) : g.is_integral_elem x := let ⟨p, ⟨hp, hp'⟩⟩ := h in ⟨p.map f, hp.map f, by rwa ← eval₂_map at hp'⟩ lemma ring_hom.is_integral_tower_top_of_is_integral (h : (g.comp f).is_integral) : g.is_integral := λ x, ring_hom.is_integral_elem_of_is_integral_elem_comp f g (h x) /-- If `R → A → B` is an algebra tower, then if the entire tower is an integral extension so is `A → B`. -/ lemma is_integral_tower_top_of_is_integral {x : B} (h : is_integral R x) : is_integral A x := begin rcases h with ⟨p, ⟨hp, hp'⟩⟩, refine ⟨p.map (algebra_map R A), ⟨hp.map (algebra_map R A), _⟩⟩, rw [is_scalar_tower.algebra_map_eq R A B, ← eval₂_map] at hp', exact hp', end lemma ring_hom.is_integral_quotient_of_is_integral {I : ideal S} (hf : f.is_integral) : (ideal.quotient_map I f le_rfl).is_integral := begin rintros ⟨x⟩, obtain ⟨p, ⟨p_monic, hpx⟩⟩ := hf x, refine ⟨p.map (ideal.quotient.mk _), ⟨p_monic.map _, _⟩⟩, simpa only [hom_eval₂, eval₂_map] using congr_arg (ideal.quotient.mk I) hpx end lemma is_integral_quotient_of_is_integral {I : ideal A} (hRA : is_integral R A) : is_integral (R ⧸ I.comap (algebra_map R A)) (A ⧸ I) := (algebra_map R A).is_integral_quotient_of_is_integral hRA lemma is_integral_quotient_map_iff {I : ideal S} : (ideal.quotient_map I f le_rfl).is_integral ↔ ((ideal.quotient.mk I).comp f : R →+* S ⧸ I).is_integral := begin let g := ideal.quotient.mk (I.comap f), have := ideal.quotient_map_comp_mk le_rfl, refine ⟨λ h, _, λ h, ring_hom.is_integral_tower_top_of_is_integral g _ (this ▸ h)⟩, refine this ▸ ring_hom.is_integral_trans g (ideal.quotient_map I f le_rfl) _ h, exact ring_hom.is_integral_of_surjective g ideal.quotient.mk_surjective, end /-- If the integral extension `R → S` is injective, and `S` is a field, then `R` is also a field. -/ lemma is_field_of_is_integral_of_is_field {R S : Type*} [comm_ring R] [nontrivial R] [comm_ring S] [is_domain S] [algebra R S] (H : is_integral R S) (hRS : function.injective (algebra_map R S)) (hS : is_field S) : is_field R := begin refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, λ a ha, _⟩, -- Let `a_inv` be the inverse of `algebra_map R S a`, -- then we need to show that `a_inv` is of the form `algebra_map R S b`. obtain ⟨a_inv, ha_inv⟩ := hS.mul_inv_cancel (λ h, ha (hRS (trans h (ring_hom.map_zero _).symm))), -- Let `p : R[X]` be monic with root `a_inv`, -- and `q` be `p` with coefficients reversed (so `q(a) = q'(a) * a + 1`). -- We claim that `q(a) = 0`, so `-q'(a)` is the inverse of `a`. obtain ⟨p, p_monic, hp⟩ := H a_inv, use -∑ (i : ℕ) in finset.range p.nat_degree, (p.coeff i) * a ^ (p.nat_degree - i - 1), -- `q(a) = 0`, because multiplying everything with `a_inv^n` gives `p(a_inv) = 0`. -- TODO: this could be a lemma for `polynomial.reverse`. have hq : ∑ (i : ℕ) in finset.range (p.nat_degree + 1), (p.coeff i) * a ^ (p.nat_degree - i) = 0, { apply (injective_iff_map_eq_zero (algebra_map R S)).mp hRS, have a_inv_ne_zero : a_inv ≠ 0 := right_ne_zero_of_mul (mt ha_inv.symm.trans one_ne_zero), refine (mul_eq_zero.mp _).resolve_right (pow_ne_zero p.nat_degree a_inv_ne_zero), rw [eval₂_eq_sum_range] at hp, rw [ring_hom.map_sum, finset.sum_mul], refine (finset.sum_congr rfl (λ i hi, _)).trans hp, rw [ring_hom.map_mul, mul_assoc], congr, have : a_inv ^ p.nat_degree = a_inv ^ (p.nat_degree - i) * a_inv ^ i, { rw [← pow_add a_inv, tsub_add_cancel_of_le (nat.le_of_lt_succ (finset.mem_range.mp hi))] }, rw [ring_hom.map_pow, this, ← mul_assoc, ← mul_pow, ha_inv, one_pow, one_mul] }, -- Since `q(a) = 0` and `q(a) = q'(a) * a + 1`, we have `a * -q'(a) = 1`. -- TODO: we could use a lemma for `polynomial.div_X` here. rw [finset.sum_range_succ_comm, p_monic.coeff_nat_degree, one_mul, tsub_self, pow_zero, add_eq_zero_iff_eq_neg, eq_comm] at hq, rw [mul_comm, neg_mul, finset.sum_mul], convert hq using 2, refine finset.sum_congr rfl (λ i hi, _), have : 1 ≤ p.nat_degree - i := le_tsub_of_add_le_left (finset.mem_range.mp hi), rw [mul_assoc, ← pow_succ', tsub_add_cancel_of_le this] end lemma is_field_of_is_integral_of_is_field' {R S : Type*} [comm_ring R] [comm_ring S] [is_domain S] [algebra R S] (H : algebra.is_integral R S) (hR : is_field R) : is_field S := begin letI := hR.to_field, refine ⟨⟨0, 1, zero_ne_one⟩, mul_comm, λ x hx, _⟩, let A := algebra.adjoin R ({x} : set S), haveI : is_noetherian R A := is_noetherian_of_fg_of_noetherian A.to_submodule (fg_adjoin_singleton_of_integral x (H x)), haveI : module.finite R A := module.is_noetherian.finite R A, obtain ⟨y, hy⟩ := linear_map.surjective_of_injective (@lmul_left_injective R A _ _ _ _ ⟨x, subset_adjoin (set.mem_singleton x)⟩ (λ h, hx (subtype.ext_iff.mp h))) 1, exact ⟨y, subtype.ext_iff.mp hy⟩, end lemma is_integral.is_field_iff_is_field {R S : Type*} [comm_ring R] [nontrivial R] [comm_ring S] [is_domain S] [algebra R S] (H : algebra.is_integral R S) (hRS : function.injective (algebra_map R S)) : is_field R ↔ is_field S := ⟨is_field_of_is_integral_of_is_field' H, is_field_of_is_integral_of_is_field H hRS⟩ end algebra theorem integral_closure_idem {R : Type*} {A : Type*} [comm_ring R] [comm_ring A] [algebra R A] : integral_closure (integral_closure R A : set A) A = ⊥ := eq_bot_iff.2 $ λ x hx, algebra.mem_bot.2 ⟨⟨x, @is_integral_trans _ _ _ _ _ _ _ _ (integral_closure R A).algebra _ integral_closure.is_integral x hx⟩, rfl⟩ section is_domain variables {R S : Type*} [comm_ring R] [comm_ring S] [is_domain S] [algebra R S] instance : is_domain (integral_closure R S) := infer_instance end is_domain
(* TODO: That's quite specific to the BFS alg. Move to Edka! *) theory Graph_Impl (* copied from Flow_Networks.Graph_Impl *) imports (* Maxflow_Lib.Refine_Add_Fofu *) "../../Refine_Imperative_HOL/Sepref" Flow_Networks.Graph begin \<comment> \<open>Fixing capacities to integer values\<close> type_synonym capacity_impl = int (* TODO: DUP in Network_Impl. Remove here!*) locale Impl_Succ = fixes absG :: "'ga \<Rightarrow> capacity_impl graph" fixes ifT :: "'ig itself" fixes succ :: "'ga \<Rightarrow> node \<Rightarrow> node list nrest" fixes isG :: "'ga \<Rightarrow> 'gi \<Rightarrow> assn" fixes succ_impl :: "'gi \<Rightarrow> node \<Rightarrow> node list Heap" fixes N :: "node" (*assumes [constraint_rules]: "precise isG"*) assumes si_rule[sepref_fr_rules]: "(uncurry succ_impl,(uncurry succ)) \<in> [\<lambda>(c,u). u\<in>Graph.V (absG c)]\<^sub>a isG\<^sup>k *\<^sub>a (pure nat_rel)\<^sup>k \<rightarrow> list_assn (pure nat_rel)" begin term "Impl_Succ " lemma this_loc: "Impl_Succ absG succ isG succ_impl" apply unfold_locales (* apply simp apply simp using si_rule . *) done sepref_register "succ" :: "'ig \<Rightarrow> node \<Rightarrow> node list nrest" (* TODO: Will not work if succ is not a constant! *) print_theorems end end
module Statistics.GModeling.Models.FixedTreeLDA ( ) where import Statistics.GModeling.DSL data LDATreeLabels = Alpha1 | Alpha2 | Beta | TopicDepth | TopicPath | Topic | Doc | Symbols | Symbol ldaTree :: Network LDATreeLabels ldaTree = [ Only Alpha1 :-> TopicDepth , Only Alpha2 :-> TopicPath , Only Beta :-> Symbols , (TopicPath :@ Doc) :-> Topic , (TopicDepth :@ Doc) :-> Topic , (Symbols :@ Topic) :-> Symbol ]
A Mighty Morphin Power Rangers #5 Review – Where Is Walter Jones? PENCILLERS: Thony Silas, Corin Howell. Cover by Jamal Campbell. Mighty Morphin Power Rangers #5 tells us that before Tommy became Rita Repulsa’s evil Green Ranger, she made a play for Zack, the Black Ranger. After being “upstaged” by Jason during a fight, Goldar and the putties abduct Zack so Rita can make her pitch. Obviously, Zack doesn’t accept. But how do the events of this issue impact Zack’s relationship to the team? And what happens when Zack tells Zordon? Rita tempting one of the Rangers toward the dark side is such a simple, classic tale. It’s perfect for this series. I’m not sure I wouldn’t have gone with Billy instead of Zack, especially considering the scene we saw in issue #2. He was comparing himself to the others, and he seemed to become self conscious and bitter. If Rita could have seen that, she might have exploited it. On the other hand, we’ve seen some curious behavior from Zack in this series. He’s been very suspicious and apprehensive about Tommy. This issue seems to explain why. This experience gives him a negative connection to the Green Ranger that we never knew about. The Zack we’ve seen in this series isn’t the one I expected. On the show, Walter Jones played a fun-loving dancer. Zack is in love with life, and he’s not afraid to show it. That’s not the character we’ve seen in this series. For the most part he’s been very straight faced. I understand he’s in a very tense storyline. But flashes of personality aren’t going to hurt anything, are they? In essence, what we need in this book is a little more Walter Jones. Fussy Fanboy Moment: After Zack is abducted, he wakes up in Rita’s Dark Dimension, which we saw in the show. But in one of the “Green Candle” episodes, which these events obviously predate, Jason says he and Tommy are the only Rangers that have been there. On the plus side, Higgins sneaks in what seems to be a hint at Zack going to the Peace Conference later in the series. He tells Zordon, “I need to do more … I don’t care about leading. It’s not like that.” I like that second line. It speaks to why Rita’s plan for Zack doesn’t work. He’s imperfect like anyone else, but in the end he’s selfless. It’s more about the good that’s being done, as opposed to the glory you get from it. The opening sequence, set in Italy, is a lot of fun. The Rangers face Rita’s monstrous take on The Vitruvian Man, who can apparently only speak in da Vinci quotes. Afterward, they receive some fanfare on the ground. We even have the prime minister in the middle of the action. This is yet another example of Higgins doing something that never could have happened on the show. Thony Silas tags in on pencils for this issue. His style isn’t dramatically different from Hendry Prasetya’s, though his characters are slightly better at emoting. His Rita is particularly sinister. Again, his Zack seems very reserved and stoic, which is not the character we’re used to. “The Ongoing Adventures of Bulk & Skull” still doesn’t do much for me. Though we do get a surprise in this issue: The BOOM! Studios debut of Lieutenant Stone, Bulk & Skull’s foil from seasons 3 and 4. I’d always been under the impression they’d never met before. Either way, I’m glad to see the putty patroller story is over. On to (hopefully) better things. Higgins pleasantly surprised me with this Zack story, by following up on a plot seed he’d planted as far back as issue #1. It makes you wonder what else he might come back to in future issues. Whether it’s how Billy sees his role on the team, Jason feeling threatened by Tommy, or something else fans may have wondered about. There’s so much fertile ground to cover, and I’m hopeful that we’ve only scratched the surface. This entry was posted in Comic Books/Graphic Novels and tagged Billy Cranston, Black Ranger, BOOM! Studios, Bulk & Skull, comic book reviews, comic books, Corin Howell, Green Ranger, Jamal Campbell, Kyle Higgins, Leonardo da Vinci, Megazord, Mighty Morphin Power Rangers, Mighty Morphin Power Rangers #5 (2016), Mighty Morphin Power Rangers (BOOM! Studios), Pink Ranger, Power Rangers, Red Ranger, Rita Repulsa, Rob Siebert, single issue reviews, Steve Orlando, superhero comics, superheroes, The Vitruvian Man, Thony Silas, Tommy Oliver, Walter Emanuel Jones, Zack Taylor, Zordon on 07/21/2016 by primaryignition.
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura Definitions and properties of gcd, lcm, and coprime. -/ import data.nat.basic namespace nat /- gcd -/ theorem gcd_dvd (m n : ℕ) : (gcd m n ∣ m) ∧ (gcd m n ∣ n) := gcd.induction m n (λn, by rw gcd_zero_left; exact ⟨dvd_zero n, dvd_refl n⟩) (λm n npos, by rw ←gcd_rec; exact λ ⟨IH₁, IH₂⟩, ⟨IH₂, (dvd_mod_iff IH₂).1 IH₁⟩) theorem gcd_dvd_left (m n : ℕ) : gcd m n ∣ m := (gcd_dvd m n).left theorem gcd_dvd_right (m n : ℕ) : gcd m n ∣ n := (gcd_dvd m n).right theorem dvd_gcd {m n k : ℕ} : k ∣ m → k ∣ n → k ∣ gcd m n := gcd.induction m n (λn _ kn, by rw gcd_zero_left; exact kn) (λn m mpos IH H1 H2, by rw gcd_rec; exact IH ((dvd_mod_iff H1).2 H2) H1) theorem gcd_comm (m n : ℕ) : gcd m n = gcd n m := dvd_antisymm (dvd_gcd (gcd_dvd_right m n) (gcd_dvd_left m n)) (dvd_gcd (gcd_dvd_right n m) (gcd_dvd_left n m)) theorem gcd_assoc (m n k : ℕ) : gcd (gcd m n) k = gcd m (gcd n k) := dvd_antisymm (dvd_gcd (dvd.trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_left m n)) (dvd_gcd (dvd.trans (gcd_dvd_left (gcd m n) k) (gcd_dvd_right m n)) (gcd_dvd_right (gcd m n) k))) (dvd_gcd (dvd_gcd (gcd_dvd_left m (gcd n k)) (dvd.trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_left n k))) (dvd.trans (gcd_dvd_right m (gcd n k)) (gcd_dvd_right n k))) @[simp] theorem gcd_one_right (n : ℕ) : gcd n 1 = 1 := eq.trans (gcd_comm n 1) $ gcd_one_left n theorem gcd_mul_left (m n k : ℕ) : gcd (m * n) (m * k) = m * gcd n k := gcd.induction n k (λk, by repeat {rw mul_zero <|> rw gcd_zero_left}) (λk n H IH, by rwa [←mul_mod_mul_left, ←gcd_rec, ←gcd_rec] at IH) theorem gcd_mul_right (m n k : ℕ) : gcd (m * n) (k * n) = gcd m k * n := by rw [mul_comm m n, mul_comm k n, mul_comm (gcd m k) n, gcd_mul_left] theorem gcd_pos_of_pos_left {m : ℕ} (n : ℕ) (mpos : m > 0) : gcd m n > 0 := pos_of_dvd_of_pos (gcd_dvd_left m n) mpos theorem gcd_pos_of_pos_right (m : ℕ) {n : ℕ} (npos : n > 0) : gcd m n > 0 := pos_of_dvd_of_pos (gcd_dvd_right m n) npos theorem eq_zero_of_gcd_eq_zero_left {m n : ℕ} (H : gcd m n = 0) : m = 0 := or.elim (eq_zero_or_pos m) id (assume H1 : m > 0, absurd (eq.symm H) (ne_of_lt (gcd_pos_of_pos_left _ H1))) theorem eq_zero_of_gcd_eq_zero_right {m n : ℕ} (H : gcd m n = 0) : n = 0 := by rw gcd_comm at H; exact eq_zero_of_gcd_eq_zero_left H theorem gcd_div {m n k : ℕ} (H1 : k ∣ m) (H2 : k ∣ n) : gcd (m / k) (n / k) = gcd m n / k := or.elim (eq_zero_or_pos k) (λk0, by rw [k0, nat.div_zero, nat.div_zero, nat.div_zero, gcd_zero_right]) (λH3, nat.eq_of_mul_eq_mul_right H3 $ by rw [ nat.div_mul_cancel (dvd_gcd H1 H2), ←gcd_mul_right, nat.div_mul_cancel H1, nat.div_mul_cancel H2]) theorem gcd_dvd_gcd_of_dvd_left {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd m n ∣ gcd k n := dvd_gcd (dvd.trans (gcd_dvd_left m n) H) (gcd_dvd_right m n) theorem gcd_dvd_gcd_of_dvd_right {m k : ℕ} (n : ℕ) (H : m ∣ k) : gcd n m ∣ gcd n k := dvd_gcd (gcd_dvd_left n m) (dvd.trans (gcd_dvd_right n m) H) theorem gcd_dvd_gcd_mul_left (m n k : ℕ) : gcd m n ∣ gcd (k * m) n := gcd_dvd_gcd_of_dvd_left _ (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right (m n k : ℕ) : gcd m n ∣ gcd (m * k) n := gcd_dvd_gcd_of_dvd_left _ (dvd_mul_right _ _) theorem gcd_dvd_gcd_mul_left_right (m n k : ℕ) : gcd m n ∣ gcd m (k * n) := gcd_dvd_gcd_of_dvd_right _ (dvd_mul_left _ _) theorem gcd_dvd_gcd_mul_right_right (m n k : ℕ) : gcd m n ∣ gcd m (n * k) := gcd_dvd_gcd_of_dvd_right _ (dvd_mul_right _ _) theorem gcd_eq_left {m n : ℕ} (H : m ∣ n) : gcd m n = m := dvd_antisymm (gcd_dvd_left _ _) (dvd_gcd (dvd_refl _) H) theorem gcd_eq_right {m n : ℕ} (H : n ∣ m) : gcd m n = n := by rw [gcd_comm, gcd_eq_left H] /- lcm -/ theorem lcm_comm (m n : ℕ) : lcm m n = lcm n m := by delta lcm; rw [mul_comm, gcd_comm] theorem lcm_zero_left (m : ℕ) : lcm 0 m = 0 := by delta lcm; rw [zero_mul, nat.zero_div] theorem lcm_zero_right (m : ℕ) : lcm m 0 = 0 := lcm_comm 0 m ▸ lcm_zero_left m theorem lcm_one_left (m : ℕ) : lcm 1 m = m := by delta lcm; rw [one_mul, gcd_one_left, nat.div_one] theorem lcm_one_right (m : ℕ) : lcm m 1 = m := lcm_comm 1 m ▸ lcm_one_left m theorem lcm_self (m : ℕ) : lcm m m = m := or.elim (eq_zero_or_pos m) (λh, by rw [h, lcm_zero_left]) (λh, by delta lcm; rw [gcd_self, nat.mul_div_cancel _ h]) theorem dvd_lcm_left (m n : ℕ) : m ∣ lcm m n := dvd.intro (n / gcd m n) (nat.mul_div_assoc _ $ gcd_dvd_right m n).symm theorem dvd_lcm_right (m n : ℕ) : n ∣ lcm m n := lcm_comm n m ▸ dvd_lcm_left n m theorem gcd_mul_lcm (m n : ℕ) : gcd m n * lcm m n = m * n := by delta lcm; rw [nat.mul_div_cancel' (dvd.trans (gcd_dvd_left m n) (dvd_mul_right m n))] theorem lcm_dvd {m n k : ℕ} (H1 : m ∣ k) (H2 : n ∣ k) : lcm m n ∣ k := or.elim (eq_zero_or_pos k) (λh, by rw h; exact dvd_zero _) (λkpos, dvd_of_mul_dvd_mul_left (gcd_pos_of_pos_left n (pos_of_dvd_of_pos H1 kpos)) $ by rw [gcd_mul_lcm, ←gcd_mul_right, mul_comm n k]; exact dvd_gcd (mul_dvd_mul_left _ H2) (mul_dvd_mul_right H1 _)) theorem lcm_assoc (m n k : ℕ) : lcm (lcm m n) k = lcm m (lcm n k) := dvd_antisymm (lcm_dvd (lcm_dvd (dvd_lcm_left m (lcm n k)) (dvd.trans (dvd_lcm_left n k) (dvd_lcm_right m (lcm n k)))) (dvd.trans (dvd_lcm_right n k) (dvd_lcm_right m (lcm n k)))) (lcm_dvd (dvd.trans (dvd_lcm_left m n) (dvd_lcm_left (lcm m n) k)) (lcm_dvd (dvd.trans (dvd_lcm_right m n) (dvd_lcm_left (lcm m n) k)) (dvd_lcm_right (lcm m n) k))) /- coprime -/ instance (m n : ℕ) : decidable (coprime m n) := by unfold coprime; apply_instance theorem coprime.gcd_eq_one {m n : ℕ} : coprime m n → gcd m n = 1 := id theorem coprime.symm {m n : ℕ} : coprime n m → coprime m n := (gcd_comm m n).trans theorem coprime_of_dvd {m n : ℕ} (H : ∀ k > 1, k ∣ m → ¬ k ∣ n) : coprime m n := or.elim (eq_zero_or_pos (gcd m n)) (λg0, by rw [eq_zero_of_gcd_eq_zero_left g0, eq_zero_of_gcd_eq_zero_right g0] at H; exact false.elim (H 2 dec_trivial (dvd_zero _) (dvd_zero _))) (λ(g1 : 1 ≤ _), eq.symm $ (lt_or_eq_of_le g1).resolve_left $ λg2, H _ g2 (gcd_dvd_left _ _) (gcd_dvd_right _ _)) theorem coprime_of_dvd' {m n : ℕ} (H : ∀ k, k ∣ m → k ∣ n → k ∣ 1) : coprime m n := coprime_of_dvd $ λk kl km kn, not_le_of_gt kl $ le_of_dvd zero_lt_one (H k km kn) theorem coprime.dvd_of_dvd_mul_right {m n k : ℕ} (H1 : coprime k n) (H2 : k ∣ m * n) : k ∣ m := let t := dvd_gcd (dvd_mul_left k m) H2 in by rwa [gcd_mul_left, H1.gcd_eq_one, mul_one] at t theorem coprime.dvd_of_dvd_mul_left {m n k : ℕ} (H1 : coprime k m) (H2 : k ∣ m * n) : k ∣ n := by rw mul_comm at H2; exact H1.dvd_of_dvd_mul_right H2 theorem coprime.gcd_mul_left_cancel {k : ℕ} (m : ℕ) {n : ℕ} (H : coprime k n) : gcd (k * m) n = gcd m n := have H1 : coprime (gcd (k * m) n) k, by rw [coprime, gcd_assoc, H.symm.gcd_eq_one, gcd_one_right], dvd_antisymm (dvd_gcd (H1.dvd_of_dvd_mul_left (gcd_dvd_left _ _)) (gcd_dvd_right _ _)) (gcd_dvd_gcd_mul_left _ _ _) theorem coprime.gcd_mul_right_cancel (m : ℕ) {k n : ℕ} (H : coprime k n) : gcd (m * k) n = gcd m n := by rw [mul_comm m k, H.gcd_mul_left_cancel m] theorem coprime.gcd_mul_left_cancel_right {k m : ℕ} (n : ℕ) (H : coprime k m) : gcd m (k * n) = gcd m n := by rw [gcd_comm m n, gcd_comm m (k * n), H.gcd_mul_left_cancel n] theorem coprime.gcd_mul_right_cancel_right {k m : ℕ} (n : ℕ) (H : coprime k m) : gcd m (n * k) = gcd m n := by rw [mul_comm n k, H.gcd_mul_left_cancel_right n] theorem coprime_div_gcd_div_gcd {m n : ℕ} (H : gcd m n > 0) : coprime (m / gcd m n) (n / gcd m n) := by delta coprime; rw [gcd_div (gcd_dvd_left m n) (gcd_dvd_right m n), nat.div_self H] theorem not_coprime_of_dvd_of_dvd {m n d : ℕ} (dgt1 : d > 1) (Hm : d ∣ m) (Hn : d ∣ n) : ¬ coprime m n := λ (co : gcd m n = 1), not_lt_of_ge (le_of_dvd zero_lt_one $ by rw ←co; exact dvd_gcd Hm Hn) dgt1 theorem exists_coprime {m n : ℕ} (H : gcd m n > 0) : ∃ m' n', coprime m' n' ∧ m = m' * gcd m n ∧ n = n' * gcd m n := ⟨_, _, coprime_div_gcd_div_gcd H, (nat.div_mul_cancel (gcd_dvd_left m n)).symm, (nat.div_mul_cancel (gcd_dvd_right m n)).symm⟩ theorem exists_coprime' {m n : ℕ} (H : gcd m n > 0) : ∃ g m' n', 0 < g ∧ coprime m' n' ∧ m = m' * g ∧ n = n' * g := let ⟨m', n', h⟩ := exists_coprime H in ⟨_, m', n', H, h⟩ theorem coprime.mul {m n k : ℕ} (H1 : coprime m k) (H2 : coprime n k) : coprime (m * n) k := (H1.gcd_mul_left_cancel n).trans H2 theorem coprime.mul_right {k m n : ℕ} (H1 : coprime k m) (H2 : coprime k n) : coprime k (m * n) := (H1.symm.mul H2.symm).symm theorem coprime.coprime_dvd_left {m k n : ℕ} (H1 : m ∣ k) (H2 : coprime k n) : coprime m n := eq_one_of_dvd_one (by delta coprime at H2; rw ← H2; exact gcd_dvd_gcd_of_dvd_left _ H1) theorem coprime.coprime_dvd_right {m k n : ℕ} (H1 : n ∣ m) (H2 : coprime k m) : coprime k n := (H2.symm.coprime_dvd_left H1).symm theorem coprime.coprime_mul_left {k m n : ℕ} (H : coprime (k * m) n) : coprime m n := H.coprime_dvd_left (dvd_mul_left _ _) theorem coprime.coprime_mul_right {k m n : ℕ} (H : coprime (m * k) n) : coprime m n := H.coprime_dvd_left (dvd_mul_right _ _) theorem coprime.coprime_mul_left_right {k m n : ℕ} (H : coprime m (k * n)) : coprime m n := H.coprime_dvd_right (dvd_mul_left _ _) theorem coprime.coprime_mul_right_right {k m n : ℕ} (H : coprime m (n * k)) : coprime m n := H.coprime_dvd_right (dvd_mul_right _ _) theorem coprime_one_left : ∀ n, coprime 1 n := gcd_one_left theorem coprime_one_right : ∀ n, coprime n 1 := gcd_one_right theorem coprime.pow_left {m k : ℕ} (n : ℕ) (H1 : coprime m k) : coprime (m ^ n) k := nat.rec_on n (coprime_one_left _) (λn IH, IH.mul H1) theorem coprime.pow_right {m k : ℕ} (n : ℕ) (H1 : coprime k m) : coprime k (m ^ n) := (H1.symm.pow_left n).symm theorem coprime.pow {k l : ℕ} (m n : ℕ) (H1 : coprime k l) : coprime (k ^ m) (l ^ n) := (H1.pow_left _).pow_right _ theorem coprime.eq_one_of_dvd {k m : ℕ} (H : coprime k m) (d : k ∣ m) : k = 1 := by rw [← H.gcd_eq_one, gcd_eq_left d] theorem exists_eq_prod_and_dvd_and_dvd {m n k : ℕ} (H : k ∣ m * n) : ∃ m' n', k = m' * n' ∧ m' ∣ m ∧ n' ∣ n := or.elim (eq_zero_or_pos (gcd k m)) (λg0, ⟨0, n, by rw [zero_mul, eq_zero_of_gcd_eq_zero_left g0], by rw [eq_zero_of_gcd_eq_zero_right g0]; apply dvd_zero, dvd_refl _⟩) (λgpos, let hd := (nat.mul_div_cancel' (gcd_dvd_left k m)).symm in ⟨_, _, hd, gcd_dvd_right _ _, dvd_of_mul_dvd_mul_left gpos $ by rw [←hd, ←gcd_mul_right]; exact dvd_gcd (dvd_mul_right _ _) H⟩) theorem pow_dvd_pow_iff {a b n : ℕ} (n0 : 0 < n) : a ^ n ∣ b ^ n ↔ a ∣ b := begin refine ⟨λ h, _, λ h, pow_dvd_pow_of_dvd h _⟩, cases eq_zero_or_pos (gcd a b) with g0 g0, { simp [eq_zero_of_gcd_eq_zero_right g0] }, rcases exists_coprime' g0 with ⟨g, a', b', g0', co, rfl, rfl⟩, rw [mul_pow, mul_pow] at h, replace h := dvd_of_mul_dvd_mul_right (pos_pow_of_pos _ g0') h, have := pow_dvd_pow a' n0, rw [pow_one, (co.pow n n).eq_one_of_dvd h] at this, simp [eq_one_of_dvd_one this] end end nat
[STATEMENT] lemma flip: "((A = True) ==> False) ==> A = False" "((A = False) ==> False) ==> A = True" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((A = True \<Longrightarrow> False) \<Longrightarrow> A = False) &&& ((A = False \<Longrightarrow> False) \<Longrightarrow> A = True) [PROOF STEP] by auto
This episode begins on the annual TGS with Tracy Jordan ( a fictional sketch comedy series ) Sandwich Day . Liz Lemon ( Tina Fey ) receives a phone call from her ex @-@ boyfriend , Floyd ( Jason Sudeikis ) , asking for a place to stay ; Tracy Jordan ( Tracy Morgan ) , Jenna Maroney ( Jane Krakowski ) and the TGS writers try to get a new sandwich for Liz ; Jack Donaghy ( Alec Baldwin ) reconsiders his future at General Electric .
/- Ported by Deniz Aydin from the lean3 prelude: https://github.com/leanprover-community/lean/blob/master/library/init/algebra/order.lean Original file's license: Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Init.Logic /-! # Orders Defines classes for preorders, partial orders, and linear orders and proves some basic lemmas about them. -/ /- TODO: Does Lean4 have an equivalent for this: Make sure instances defined in this file have lower priority than the ones defined for concrete structures set_option default_priority 100 -/ universe u variable {α : Type u} -- set_option auto_param.check_exists false section Preorder /-! ### Definition of `Preorder` and lemmas about types with a `Preorder` -/ /-- A preorder is a reflexive, transitive relation `≤` with `a < b` defined in the obvious way. -/ class Preorder (α : Type u) extends LE α, LT α := (le_refl : ∀ a : α, a ≤ a) (le_trans : ∀ a b c : α, a ≤ b → b ≤ c → a ≤ c) (lt := λ a b => a ≤ b ∧ ¬ b ≤ a) (lt_iff_le_not_le : ∀ a b : α, a < b ↔ (a ≤ b ∧ ¬ b ≤ a)) -- . order_laws_tac) variable [Preorder α] /-- The relation `≤` on a preorder is reflexive. -/ @[simp] theorem le_refl : ∀ (a : α), a ≤ a := Preorder.le_refl /-- The relation `≤` on a preorder is transitive. -/ theorem le_trans : ∀ {a b c : α}, a ≤ b → b ≤ c → a ≤ c := Preorder.le_trans _ _ _ theorem lt_iff_le_not_le : ∀ {a b : α}, a < b ↔ (a ≤ b ∧ ¬ b ≤ a) := Preorder.lt_iff_le_not_le _ _ theorem lt_of_le_not_le : ∀ {a b : α}, a ≤ b → ¬ b ≤ a → a < b | a, b, hab, hba => lt_iff_le_not_le.mpr ⟨hab, hba⟩ theorem le_not_le_of_lt : ∀ {a b : α}, a < b → a ≤ b ∧ ¬ b ≤ a | a, b, hab => lt_iff_le_not_le.mp hab theorem le_of_eq {a b : α} : a = b → a ≤ b := λ h => h ▸ le_refl a theorem ge_trans : ∀ {a b c : α}, a ≥ b → b ≥ c → a ≥ c := λ h₁ h₂ => le_trans h₂ h₁ theorem lt_irrefl : ∀ a : α, ¬ a < a | a, haa => match le_not_le_of_lt haa with | ⟨h1, h2⟩ => h2 h1 theorem gt_irrefl : ∀ a : α, ¬ a > a := lt_irrefl theorem lt_trans : ∀ {a b c : α}, a < b → b < c → a < c | a, b, c, hab, hbc => match le_not_le_of_lt hab, le_not_le_of_lt hbc with | ⟨hab, hba⟩, ⟨hbc, hcb⟩ => lt_of_le_not_le (le_trans hab hbc) (λ hca => hcb (le_trans hca hab)) theorem gt_trans : ∀ {a b c : α}, a > b → b > c → a > c := λ h₁ h₂ => lt_trans h₂ h₁ theorem ne_of_lt {a b : α} (h : a < b) : a ≠ b := λ he => absurd h (he ▸ lt_irrefl a) theorem ne_of_gt {a b : α} (h : b < a) : a ≠ b := λ he => absurd h (he ▸ lt_irrefl a) theorem lt_asymm {a b : α} (h : a < b) : ¬ b < a := λ h1 : b < a => lt_irrefl a (lt_trans h h1) theorem le_of_lt : ∀ {a b : α}, a < b → a ≤ b | a, b, hab => (le_not_le_of_lt hab).left theorem lt_of_lt_of_le : ∀ {a b c : α}, a < b → b ≤ c → a < c | a, b, c, hab, hbc => let ⟨hab, hba⟩ := le_not_le_of_lt hab lt_of_le_not_le (le_trans hab hbc) $ λ hca => hba (le_trans hbc hca) theorem lt_of_le_of_lt : ∀ {a b c : α}, a ≤ b → b < c → a < c | a, b, c, hab, hbc => let ⟨hbc, hcb⟩ := le_not_le_of_lt hbc lt_of_le_not_le (le_trans hab hbc) $ λ hca => hcb (le_trans hca hab) theorem gt_of_gt_of_ge {a b c : α} (h₁ : a > b) (h₂ : b ≥ c) : a > c := lt_of_le_of_lt h₂ h₁ theorem gt_of_ge_of_gt {a b c : α} (h₁ : a ≥ b) (h₂ : b > c) : a > c := lt_of_lt_of_le h₂ h₁ instance : @Trans α α α LE.le LE.le LE.le := ⟨le_trans⟩ instance : @Trans α α α LT.lt LE.le LT.lt := ⟨lt_of_lt_of_le⟩ instance : @Trans α α α LE.le LT.lt LT.lt := ⟨lt_of_le_of_lt⟩ instance : @Trans α α α GE.ge GE.ge GE.ge := ⟨ge_trans⟩ instance : @Trans α α α GT.gt GE.ge GT.gt := ⟨gt_of_gt_of_ge⟩ instance : @Trans α α α GE.ge GT.gt GT.gt := ⟨gt_of_ge_of_gt⟩ theorem not_le_of_gt {a b : α} (h : a > b) : ¬ a ≤ b := (le_not_le_of_lt h).right theorem not_lt_of_ge {a b : α} (h : a ≥ b) : ¬ a < b := λ hab => not_le_of_gt hab h theorem le_of_lt_or_eq : ∀ {a b : α}, (a < b ∨ a = b) → a ≤ b | a, b, (Or.inl hab) => le_of_lt hab | a, b, (Or.inr hab) => hab ▸ le_refl _ theorem le_of_eq_or_lt {a b : α} (h : a = b ∨ a < b) : a ≤ b := match h with | (Or.inl h) => le_of_eq h | (Or.inr h) => le_of_lt h instance decidableLt_of_decidableLe [DecidableRel (. ≤ . : α → α → Prop)] : DecidableRel (. < . : α → α → Prop) | a, b => if hab : a ≤ b then if hba : b ≤ a then isFalse $ λ hab' => not_le_of_gt hab' hba else isTrue $ lt_of_le_not_le hab hba else isFalse $ λ hab' => hab (le_of_lt hab') end Preorder section PartialOrder /-! ### Definition of `PartialOrder` and lemmas about types with a partial order -/ /-- A partial order is a reflexive, transitive, antisymmetric relation `≤`. -/ class PartialOrder (α : Type u) extends Preorder α := (le_antisymm : ∀ a b : α, a ≤ b → b ≤ a → a = b) variable [PartialOrder α] theorem le_antisymm : ∀ {a b : α}, a ≤ b → b ≤ a → a = b := PartialOrder.le_antisymm _ _ theorem le_antisymm_iff {a b : α} : a = b ↔ a ≤ b ∧ b ≤ a := ⟨λ e => ⟨le_of_eq e, le_of_eq e.symm⟩, λ ⟨h1, h2⟩ => le_antisymm h1 h2⟩ theorem lt_of_le_of_ne {a b : α} : a ≤ b → a ≠ b → a < b := λ h₁ h₂ => lt_of_le_not_le h₁ $ mt (le_antisymm h₁) h₂ instance decidableEq_of_decidableLe [DecidableRel (. ≤ . : α → α → Prop)] : DecidableEq α | a, b => if hab : a ≤ b then if hba : b ≤ a then isTrue (le_antisymm hab hba) else isFalse (λ heq => hba (heq ▸ le_refl _)) else isFalse (λ heq => hab (heq ▸ le_refl _)) namespace Decidable variable [@DecidableRel α (. ≤ .)] theorem lt_or_eq_of_le {a b : α} (hab : a ≤ b) : a < b ∨ a = b := if hba : b ≤ a then Or.inr (le_antisymm hab hba) else Or.inl (lt_of_le_not_le hab hba) theorem eq_or_lt_of_le {a b : α} (hab : a ≤ b) : a = b ∨ a < b := (lt_or_eq_of_le hab).symm theorem le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b := ⟨lt_or_eq_of_le, le_of_lt_or_eq⟩ end Decidable attribute [local instance] Classical.propDecidable theorem lt_or_eq_of_le {a b : α} : a ≤ b → a < b ∨ a = b := Decidable.lt_or_eq_of_le theorem le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b := Decidable.le_iff_lt_or_eq end PartialOrder section LinearOrder /-! ### Definition of `LinearOrder` and lemmas about types with a linear order -/ /-- A linear order is reflexive, transitive, antisymmetric and total relation `≤`. We assume that every linear ordered type has decidable `(≤)`, `(<)`, and `(=)`. -/ class LinearOrder (α : Type u) extends PartialOrder α := (le_total : ∀ a b : α, a ≤ b ∨ b ≤ a) (decidable_le : DecidableRel (. ≤ . : α → α → Prop)) (decidable_eq : DecidableEq α := @decidableEq_of_decidableLe _ _ decidable_le) (decidable_lt : DecidableRel (. < . : α → α → Prop) := @decidableLt_of_decidableLe _ _ decidable_le) variable [LinearOrder α] attribute [local instance] LinearOrder.decidable_le theorem le_total : ∀ a b : α, a ≤ b ∨ b ≤ a := LinearOrder.le_total theorem le_of_not_ge {a b : α} : ¬ a ≥ b → a ≤ b := Or.resolve_left (le_total b a) theorem le_of_not_le {a b : α} : ¬ a ≤ b → b ≤ a := Or.resolve_left (le_total a b) theorem not_lt_of_gt {a b : α} (h : a > b) : ¬ a < b := lt_asymm h theorem lt_trichotomy (a b : α) : a < b ∨ a = b ∨ b < a := Or.elim (le_total a b) (λ h : a ≤ b => Or.elim (Decidable.lt_or_eq_of_le h) (λ h : a < b => Or.inl h) (λ h : a = b => Or.inr (Or.inl h))) (λ h : b ≤ a => Or.elim (Decidable.lt_or_eq_of_le h) (λ h : b < a => Or.inr (Or.inr h)) (λ h : b = a => Or.inr (Or.inl h.symm))) theorem le_of_not_lt {a b : α} (h : ¬ b < a) : a ≤ b := match lt_trichotomy a b with | Or.inl hlt => le_of_lt hlt | Or.inr (Or.inl heq) => heq ▸ le_refl a | Or.inr (Or.inr hgt) => absurd hgt h theorem le_of_not_gt {a b : α} : ¬ a > b → a ≤ b := le_of_not_lt theorem lt_of_not_ge {a b : α} (h : ¬ a ≥ b) : a < b := lt_of_le_not_le ((le_total _ _).resolve_right h) h theorem lt_or_le (a b : α) : a < b ∨ b ≤ a := if hba : b ≤ a then Or.inr hba else Or.inl $ lt_of_not_ge hba theorem le_or_lt (a b : α) : a ≤ b ∨ b < a := (lt_or_le b a).symm theorem lt_or_ge : ∀ (a b : α), a < b ∨ a ≥ b := lt_or_le theorem le_or_gt : ∀ (a b : α), a ≤ b ∨ a > b := le_or_lt theorem lt_or_gt_of_ne {a b : α} (h : a ≠ b) : a < b ∨ a > b := match lt_trichotomy a b with | Or.inl hlt => Or.inl hlt | Or.inr (Or.inl heq) => absurd heq h | Or.inr (Or.inr hgt) => Or.inr hgt theorem ne_iff_lt_or_gt {a b : α} : a ≠ b ↔ a < b ∨ a > b := ⟨lt_or_gt_of_ne, λ o => match o with | Or.inl ol => ne_of_lt ol | Or.inr or => ne_of_gt or ⟩ theorem lt_iff_not_ge (x y : α) : x < y ↔ ¬ x ≥ y := ⟨not_le_of_gt, lt_of_not_ge⟩ @[simp] theorem not_lt {a b : α} : ¬ a < b ↔ b ≤ a := ⟨le_of_not_gt, not_lt_of_ge⟩ @[simp] theorem not_le {a b : α} : ¬ a ≤ b ↔ b < a := (lt_iff_not_ge _ _).symm instance (a b : α) : Decidable (a < b) := LinearOrder.decidable_lt a b instance (a b : α) : Decidable (a ≤ b) := LinearOrder.decidable_le a b instance (a b : α) : Decidable (a = b) := LinearOrder.decidable_eq a b theorem eq_or_lt_of_not_lt {a b : α} (h : ¬ a < b) : a = b ∨ b < a := if h₁ : a = b then Or.inl h₁ else Or.inr (lt_of_not_ge (λ hge => h (lt_of_le_of_ne hge h₁))) /- TODO: instances of classes that haven't been defined. instance : is_total_preorder α (≤) := {trans := @le_trans _ _, total := le_total} instance is_strict_weak_order_of_linear_order : is_strict_weak_order α (<) := is_strict_weak_order_of_is_total_preorder lt_iff_not_ge instance is_strict_total_order_of_linear_order : is_strict_total_order α (<) := { trichotomous := lt_trichotomy } -/ /-- Perform a case-split on the ordering of `x` and `y` in a decidable linear order. -/ def lt_by_cases (x y : α) {P : Sort _} (h₁ : x < y → P) (h₂ : x = y → P) (h₃ : y < x → P) : P := if h : x < y then h₁ h else if h' : y < x then h₃ h' else h₂ (le_antisymm (le_of_not_gt h') (le_of_not_gt h)) theorem le_imp_le_of_lt_imp_lt {β} [Preorder α] [LinearOrder β] {a b : α} {c d : β} (H : d < c → b < a) (h : a ≤ b) : c ≤ d := le_of_not_lt $ λ h' => not_le_of_gt (H h') h end LinearOrder
module _ where module Batch4 where data D1 (open Star) (A : ★) : ★ where c : (x : A) → D1 A data D2 (open Star) : ★ where data D3 (open Star) : ★₁ where c : (A : ★) → D3 data D4 : (open Star) → ★ where data D0 (A : Set) (let B = A → A) : B → Set where c : (f : B) → D0 A f module _ where data D5 (open Star) (A : ★) (open MEndo A) : ★ data D5 A (open MEndo A) where c : (f : Endo) → D5 A data D6 (open Star) (A : ★) (open MEndo A) : Endo → ★ where c : (f : Endo) → D6 A f module Batch5 where data D1 (open Star) (A : ★) : ★ data D1 A where c : (x : A) → D1 A data D2 (open Star) : ★ data D2 where data D3 (open Star) : ★₁ data D3 where c : (A : ★) → D3 data D4 : (open Star) → ★ data D4 where open import Common.Equality module Batch6 where BinOp : (A : Set) → Set BinOp A = A → A → A record IsAssoc {A : Set} (_∘_ : BinOp A) : Set where field assoc : ∀ {a b c} → ((a ∘ b) ∘ c) ≡ (a ∘ (b ∘ c)) record RawSemiGroup : Set₁ where field Carrier : Set _∘_ : Carrier → Carrier → Carrier record SemiGroupLaws1 (G : RawSemiGroup) : Set where open RawSemiGroup G field isAssoc : IsAssoc _∘_ module _ where record SemiGroupBLA (G : RawSemiGroup) (open RawSemiGroup G) (ass : IsAssoc _∘_) : Set where record SemiGroupLaws (G : RawSemiGroup) (open RawSemiGroup G) : Set where field isAssoc : IsAssoc {A = Carrier} _∘_ record SemiGroup : Set₁ where field rawSemiGroup : RawSemiGroup semiGroupLaws : SemiGroupLaws rawSemiGroup
Formal statement is: lemma continuous_on_discrete [simp]: "continuous_on A (f :: 'a :: discrete_topology \<Rightarrow> _)" Informal statement is: A function from a discrete space to any space is continuous.
informal statement Let $(p_n)$ be a sequence and $f:\mathbb{N}\to\mathbb{N}$. The sequence $(q_k)_{k\in\mathbb{N}}$ with $q_k=p_{f(k)}$ is called a rearrangement of $(p_n)$. Show that if $f$ is an injection, the limit of a sequence is unaffected by rearrangement.formal statement theorem exercise_2_29 (M : Type*) [metric_space M] (O C : set (set M)) (hO : O = {s | is_open s}) (hC : C = {s | is_closed s}) : ∃ f : O → C, bijective f :=
module Main import Python import Python.Prim import Python.Exceptions -- These modules contain signatures for Python libraries. import Python.Lib.Os import Python.Lib.Requests import Python.Lib.BeautifulSoup import Python.Lib.Queue import Python.Lib.Threading %default total -- Even though field names are strings, -- everything is typechecked according to the signatures imported above. partial main : PIO () main = do reqs <- Requests.import_ -- (/) extracts the named attribute -- ($) calls a function -- (/.) and ($.) work with pure LHS -- (/:) and ($:) work with monadic LHS (useful for chaining) -- -- equivalent to: session = reqs.Session() session <- reqs /. "Session" $. [] -- equivalent to: html = session.get("http://idris-lang.org").text -- Notice that chaining is not a problem. html <- session /. "get" $. ["http://idris-lang.org"] /: "text" -- import Beautiful Soup bs4 <- BeautifulSoup.import_ -- construct soup from HTML soup <- bs4 /. "BeautifulSoup" $. [html, Parsers.HTML] -- get the iterator over <li> elements, given by CSS selector features <- soup /. "select" $. ["div.entry-content li"] -- print all <li> elements as features putStrLn' $ "Idris has got the following exciting features:" count <- iterate features 0 $ \i : Int, li : Obj Element => do -- collect : Iterator a -> PIO (List a) line <- concat <$> collect (li /. "strings") putStrLn' $ show (i+1) ++ ". " ++ line pure $ i + 1 putStrLn' $ "Total number of features: " ++ show count putStrLn' "" -- ### Concurrency ### let thread : (String -> PIO Nat) = \name => do putStrLn' $ "thread " ++ name ++ " starting" html <- session /. "get" $. ["http://idris-lang.org"] /: "text" putStrLn' $ "thread " ++ name ++ " done" pure $ length html thrA <- forkPIO $ thread "A" thrB <- forkPIO $ thread "B" resA <- wait thrA resB <- wait thrB putStrLn' $ "thread A says " ++ show resA putStrLn' $ "thread B says " ++ show resB putStrLn' "" -- ### Exceptions ### os <- Os.import_ putStrLn' "And now, let's fail!" -- the standard try-catch variant try (do os /. "mkdir" $. ["/root/hello"] putStrLn' $ "Something's wrong, your root's homedir is writable!" ) `catch` (\etype, e => case etype of OSError => putStrLn' $ " -> (1) everything's fine: " ++ showException e _ => raise e ) -- Idris sugar, originally used in Effects OK ret <- try $ os /. "mkdir" $. ["/root/hello"] | Except OSError e => putStrLn' (" -> (2) everything's fine: " ++ showException e) | Except _ e => raise e putStrLn' $ "Your root could probably use some security lessons!" exports : FFI_Export FFI_Py "example.py" [] exports = Fun greet "greet" $ End where greet : String -> PIO () greet name = putStrLn' $ "Hello " ++ name ++ "!"
############################################################################### #### Single spin ############################################################## ############################################################################### # SingleSpin(x::T, y::T, z::T) where T = [x, y, z] ############################################################################### #### Product states ########################################################### ############################################################################### ProductState(states::Array{Array{Float64, 1}, 1}) where T = hcat(states...) ProductState(N::Int, state::AbstractVector{Float64}) where T = ProductState([state for i in 1:N]) ############################################################################### #### magnetization ############################################################ ############################################################################### function magnetization(s::AbstractMatrix, x::Symbol=:x) match = Dict(:x => 1, :y => 2, :z=>3) N = size(s, 2) 1/N * sum(s[match[x], :]) end magnetization(sol::OrdinaryDiffEq.ODECompositeSolution, t) = magnetization(sol(t)') magnetization(sim::EnsembleSolution, t) = magnetization(timepoint_mean(sim, t)') ############################################################################### #### dtwa states ############################################################ ############################################################################### function dtwa_state(x::AbstractVector) res = normalize(x) nullspace(permutedims(x))[:, 1] vec(res .+ sum(rand([-1, 1], 1, 2) .* nullspace(permutedims(res)), dims=2)) end function dtwa_state(x::AbstractMatrix) res = similar(x) for i in 1:size(x, 2) res[:, i] .= dtwa_state(x[:, i]) end res end # end #module SpinState
module Group_property2 import congruence import Monoid import Group import Group_property %access public export ||| Property 8 - If f : g -> h is group homomorphism then f(inv(a)) = inv(f(a)) total Group_property_8 : (dom : Type) -> ((*) : dom -> dom -> dom) -> (pfdom : IsGroup dom (*)) -> (cod : Type) -> ((+) : cod -> cod -> cod) -> (pfcod : IsGroup cod (+)) -> (f : dom -> cod) -> (pfhom : (Hom dom (*) pfdom cod (+) pfcod f)) -> (a : dom) -> ( (f (Inv dom (*) pfdom a)) = (Inv cod (+) pfcod (f a)) ) Group_property_8 dom (*) pfdom cod (+) pfcod f pfhom a = let pfid1_dom = (fst (snd pfdom)) e_dom1 = (fst pfid1_dom) -- identity in the IdentityExists e_dom1_pf = (snd pfid1_dom) -- proof that e_dom1 is the identity pfid2_dom = (fst (snd (snd pfdom))) e_dom2 = (fst pfid2_dom) -- identity in the InverseExists e_dom2_pf = (snd pfid2_dom) -- prood that it is the identity pf_eq_dom_id12 = (Group_property_1 dom (*) pfdom e_dom1 e_dom2 e_dom1_pf e_dom2_pf) -- proof that e_dom1 and e_dom2 are equal pfid1_cod = (fst (snd pfcod)) e_cod1 = (fst pfid1_cod) -- identity in the IdentityExists e_cod1_pf = (snd pfid1_cod) -- proof that e_cod1 is the identity pfid2_cod = (fst (snd (snd pfcod))) e_cod2 = (fst pfid2_cod) -- identity in the InverseExists e_cod2_pf = (snd pfid2_cod) -- prood that it is the identity pf_eq_cod_id12 = (Group_property_1 cod (+) pfcod e_cod1 e_cod2 e_cod1_pf e_cod2_pf) -- proof that e_cod1 and e_cod2 are equal a_inv_with_pf = snd (snd (snd pfdom)) a -- (Inv_with_pf dom (*) pfdom a) a_inv = fst a_inv_with_pf b = (f a_inv) c = (Inv cod (+) pfcod (f a)) pf_id_to_id = (fst pfhom) pf_res = (snd pfhom) --aux_pf1 : ( ( Group_id dom (*) pfdom ) = (fst (snd pfdom)) ) --aux_pf1 = Refl -- proof that fst (Group_id dom (*) pfdom) = fst (fst (snd pfdom)) pf1 = (pf_res a a_inv) -- proof that f(a * a_inv) = f a + f a_inv pf2 = (fst (snd a_inv_with_pf)) -- proof that a * a_inv = e_dom2 pf3 = congruence dom cod (a * a_inv) e_dom2 f pf2 -- proof that a * a_inv = e_dom2 pf4 = trans (sym pf1) pf3 -- proof that f(a * a_inv) = f e_dom2 pf5 = (Group_property_1 cod (+) pfcod (f e_dom1) e_cod1 pf_id_to_id e_cod1_pf) -- proof that f e_dom1 = e_cod1 pf6 = congruence dom cod e_dom1 e_dom2 f pf_eq_dom_id12-- proof that f e_dom1 = f e_dom2 pf7 = trans (trans pf4 (sym pf6)) pf5 -- proof that (f a) + (f a_inv) = e_cod1 pf8 = Group_property_7 cod (+) pfcod (f a) (f a_inv) pf7 -- proof that inverse of (f a) -- is (f a_inv) pf9 = snd (Inv_with_pf cod (+) pfcod (f a)) -- proof that c is a inverse of (f a) with -- e_cod2 as identity pf9.1 = fst pf9 -- proof that (f a) + c = e_cod2 pf9.2 = snd pf9 -- proof that c + (f a) = e_cod2 pf10.1 = trans pf9.1 (sym pf_eq_cod_id12) -- proof that (f a) + c = e_cod1 pf10.2 = trans pf9.2 (sym pf_eq_cod_id12) -- -- proof that c + (f a) = e_cod1 pf10 = (pf10.1, pf10.2) in (Group_property_2 cod (+) pfcod (f a) b c pf8 pf10) ||| Property 9 - If a*b = c then b = Inv(a) * c total Group_property_9 : (grp : Type) -> ((*) : grp -> grp -> grp) -> (pfgrp : IsGroup grp (*)) -> (a, b, c : grp) -> (a*b = c) -> (b = (Inv grp (*) pfgrp a)*c) Group_property_9 grp (*) pfgrp a b c pfEq = ?rhs
# http://stackoverflow.com/questions/6461209/how-to-round-up-to-the-nearest-10-or-100-or-x #library(plyr) data <- read.table("./integrity.dat", header=T, sep="|") counts <- table(data$integrity) #print(counts) source("round.r") #diff <- data$Quantity - data$fixed #counts <- table(data$fixed, diff) png(filename="./integrity.png", height=500, width=500, bg="white") #print(max(counts)) #print(ceiling(max(counts))) #print(round_any(max(counts), 10, f = ceiling)) barpos <- barplot(counts, ylim=c(0,round_up(max(counts))), main="Vollständigkeit der Produktangaben (in %)", col=c("#468847")) #print(barpos) #text(barpos, counts, labels=counts) title(xlab="Vollständigkeit in %") title(ylab="Häufigkeit")
INTEGER FUNCTION toto( N ) IMPLICIT NONE INTEGER :: N toto = 2 * N END FUNCTION toto
-- AIM XXXV, 2022-05-06, issue #5891. -- When checking that the sort of a data type admits data definitions -- (checkDataSort), we need to handle the case of PiSort. mutual Univ1 = _ Univ2 = _ Univ3 = _ postulate A1 : Univ1 A2 : Univ2 A : Univ3 A = A1 → A2 -- This demonstrates that the sort of a data types can be a PiSort -- (temporarily, until further information becomes available later): data Empty : Univ3 where _ : Univ1 _ = Set _ : Univ2 _ = Set -- Should succeed.
function [ulf, vlf, lf, hf, lfhf, ttlpwr] = CalcLfHfParams(PSD, F, limits,plot_on) % [ulf, vlf, lf, hf, lfhf, ttlpwr] = CalcLfHfParams(PSD, F, limits,plot_on) % % OVERVIEW: Compute the frequency domain features for a given PSD and % frequency bans limits % % INPUT: % PSD - power spectral density % F - frequency vector % limits - frequency domain analysis limits % plot_on - % % OUTPUT: % - ulf : (ms^2) Power in the ultra low frequency range (default < 0.003 Hz) % - vlf : (ms^2) Power in very low frequency range (default 0.003 <= vlf < 0.04 Hz) % - lf : (ms^2) Power in low frequency range (default 0.04Hz <= lf < 0.15 Hz) % - hf : (ms^2) Power in high frequency range (default 0.15 <= hf < 0.4 Hz) % - lfhf : Ratio LF [ms^2]/HF [ms^2] % - ttlpwr : (ms^2) Total spectral power (approximately <0.4 Hz) % % REPO: % https://github.com/cliffordlab/PhysioNet-Cardiovascular-Signal-Toolbox % ORIGINAL SOURCE AND AUTHORS: % Main script written by Adriana N. Vest % Dependent scripts written by various authors % (see functions for details) % COPYRIGHT (C) 2016 % LICENSE: % This software is offered freely and without warranty under % the GNU (v3 or later) public license. See license file for % more information %% if nargin <3 ULF = [0 .003]; VLF = [0.003 .04]; LF = [.04 .15]; HF = [0.15 0.4]; limits = [ULF; VLF; LF; HF]; end if nargin < 4 plot_on =1; end Indx_ULF = find( (limits(1,1) <= F) & (F <= limits(1,2)) ); Indx_VLF = find( (limits(2,1) <= F) & (F <= limits(2,2)) ); Indx_LF = find( (limits(3,1) <= F) & (F <= limits(3,2)) ); Indx_HF = find( (limits(4,1) <= F) & (F <= limits(4,2)) ); space = F(2)-F(1); ulf = sum(PSD(Indx_ULF)*space) * 1e6; % convert to ms^2 vlf = sum(PSD(Indx_VLF)*space) * 1e6; % convert to ms^2 lf = sum(PSD(Indx_LF)*space) * 1e6; % convert to ms^2 hf = sum(PSD(Indx_HF)*space) * 1e6; % convert to ms^2 ttlpwr = sum([ulf vlf lf hf]); lf_n = lf/ttlpwr; % normalized hf_n = hf/ttlpwr; lfhf = round(lf_n/hf_n*100)/100; % lf/hf ratio if plot_on figure % plot PSD plot(F,10*log10(PSD),'b','linewidth',2) hold on % plot limits on graph for lf and hf plot([F(Indx_LF(1)) F(Indx_LF(1))],[-80 40],'k:') hold on plot([F(Indx_LF(end)) F(Indx_LF(end))],[-80 40],'k:') hold on plot([F(Indx_HF(end)) F(Indx_HF(end))],[-80 40],'k:') % labelsc text(0.07,30,'LF','Fontname','Times New Roman','Fontsize',10) text(0.25,30,'HF','Fontname','Times New Roman','Fontsize',10) %text(0.15, 35, 'Power Spectral Density','Fontname','Times New Roman','Fontsize',10) text(0.3, -60, strcat('LF/HF=',num2str(lfhf)),'Fontname','Times New Roman','Fontsize',10) ylabel('Normalized PSD (db/Hz)','Fontname','Times New Roman','fontsize',10) xlabel('Frequency (Hz)','Fontname','Times New Roman','fontsize',10) axis([0 .45 -80 40]); box off end % end plot end % end function
import IdrisJvm.IO import IdrisJvm.System import IdrisJvm.JvmImport import Java.Lang import Java.Util import Java.Util.Function import Data.Vect import Mmhelloworld.IdrisSpringBoot.Boot import Mmhelloworld.IdrisSpringBoot.Web.Bind.Annotation import Mmhelloworld.IdrisSpringBoot.Context.Annotation import Mmhelloworld.IdrisSpringBoot.Boot.Autoconfigure import Mmhelloworld.IdrisSpringBoot.Context %access public export namespace BeanDefinitionCustomizer BeanDefinitionCustomizer : Type BeanDefinitionCustomizer = javaInterface "org/springframework/beans/factory/config/BeanDefinitionCustomizer" namespace GenericApplicationContext GenericApplicationContext : Type GenericApplicationContext = javaClass "org/springframework/context/support/GenericApplicationContext" registerBean : GenericApplicationContext -> JClass -> Supplier -> JVM_Array BeanDefinitionCustomizer -> JVM_IO () registerBean = invokeInstance "registerBean" (GenericApplicationContext -> JClass -> Supplier -> JVM_Array BeanDefinitionCustomizer -> JVM_IO ()) Inherits ConfigurableApplicationContext GenericApplicationContext where {} namespace ApplicationContextInitializer ApplicationContextInitializer : Type ApplicationContextInitializer = javaInterface "org/springframework/context/ApplicationContextInitializer" %inline jlambda : (ConfigurableApplicationContext -> JVM_IO ()) -> ApplicationContextInitializer jlambda f = javalambda "initialize" (ConfigurableApplicationContext -> JVM_IO ()) g where g : ConfigurableApplicationContext -> () g context = believe_me $ unsafePerformIO (f context) namespace ApplicationArguments ApplicationArguments : Type ApplicationArguments = javaInterface "org/springframework/boot/ApplicationArguments" namespace SpringApplicationBuilder SpringApplicationBuilder : Type SpringApplicationBuilder = javaClass "org/springframework/boot/builder/SpringApplicationBuilder" new : JVM_Array JClass -> JVM_IO SpringApplicationBuilder new = FFI.new (JVM_Array JClass -> JVM_IO SpringApplicationBuilder) initializers : SpringApplicationBuilder -> JVM_Array ApplicationContextInitializer -> JVM_IO SpringApplicationBuilder initializers = invokeInstance "initializers" (SpringApplicationBuilder -> JVM_Array ApplicationContextInitializer -> JVM_IO SpringApplicationBuilder) run : SpringApplicationBuilder -> StringArray -> JVM_IO ConfigurableApplicationContext run = invokeInstance "run" (SpringApplicationBuilder -> StringArray -> JVM_IO ConfigurableApplicationContext) namespace ApplicationRunner ApplicationRunner : Type ApplicationRunner = javaInterface "org/springframework/boot/ApplicationRunner" clazz : JClass clazz = classLit "org/springframework/boot/ApplicationRunner" %inline jlambda : (ApplicationArguments -> JVM_IO ()) -> ApplicationRunner jlambda f = javalambda "run" (ApplicationArguments -> JVM_IO ()) g where g : ApplicationArguments -> () g args = believe_me $ unsafePerformIO (f args) namespace Publisher PublisherClass : JVM_NativeTy PublisherClass = Interface "org/reactivestreams/Publisher" Publisher : Type Publisher = javaInterface "org/reactivestreams/Publisher" namespace Mono MonoClass : JVM_NativeTy MonoClass = Class "reactor/core/publisher/Mono" Mono : Type Mono = javaClass "reactor/core/publisher/Mono" just : a -> JVM_IO Mono just d = invokeStatic MonoClass "just" (Object -> JVM_IO Mono) $ believe_me d MonoClass inherits PublisherClass namespace ServerRequest ServerRequest : Type ServerRequest = javaInterface "org/springframework/web/reactive/function/server/ServerRequest" namespace HandlerFunction HandlerFunction : Type HandlerFunction = javaInterface "org/springframework/web/reactive/function/server/HandlerFunction" %inline jlambda : (ServerRequest -> JVM_IO Mono) -> HandlerFunction jlambda f = javalambda "handle" (ServerRequest -> JVM_IO Mono) g where g : ServerRequest -> Mono g request = unsafePerformIO (f request) namespace RequestPredicate RequestPredicate : Type RequestPredicate = javaInterface "org/springframework/web/reactive/function/server/RequestPredicate" namespace RequestPredicates RequestPredicatesClass : JVM_NativeTy RequestPredicatesClass = Class "org/springframework/web/reactive/function/server/RequestPredicates" get : String -> JVM_IO RequestPredicate get = invokeStatic RequestPredicatesClass "GET" (String -> JVM_IO RequestPredicate) namespace RouterFunction RouterFunctionClass : JVM_NativeTy RouterFunctionClass = Class "org/springframework/web/reactive/function/server/RouterFunction" RouterFunction : Type RouterFunction = javaInterface "org/springframework/web/reactive/function/server/RouterFunction" clazz : JClass clazz = classLit "org/springframework/web/reactive/function/server/RouterFunction" namespace RouterFunctions RouterFunctionsClass : JVM_NativeTy RouterFunctionsClass = Class "org/springframework/web/reactive/function/server/RouterFunctions" route : RequestPredicate -> HandlerFunction -> JVM_IO RouterFunction route = invokeStatic RouterFunctionsClass "route" (RequestPredicate -> HandlerFunction -> JVM_IO RouterFunction) namespace ServerResponse namespace BodyBuilder BodyBuilderClass : JVM_NativeTy BodyBuilderClass = Class "org/springframework/web/reactive/function/server/ServerResponse$BodyBuilder" BodyBuilder : Type BodyBuilder = javaInterface "org/springframework/web/reactive/function/server/ServerResponse$BodyBuilder" body : BodyBuilder -> Publisher -> JClass -> JVM_IO Mono body = invokeInstance "body" (BodyBuilder -> Publisher -> JClass -> JVM_IO Mono) ServerResponseClass : JVM_NativeTy ServerResponseClass = Interface "org/springframework/web/reactive/function/server/ServerResponse" ok : JVM_IO BodyBuilder ok = invokeStatic ServerResponseClass "ok" (JVM_IO BodyBuilder) classWith : String classWith = "" ok : String -> JVM_IO Mono ok str = body !ServerResponse.ok !(just str) (classLit "java/lang/String") Bean : Type Bean = ConfigurableApplicationContext -> JVM_IO () runner : (ApplicationArguments -> JVM_IO ()) -> Bean runner f context = do let genericContext = the GenericApplicationContext (believe_me context) let beanSupplier = Supplier.jlambda $ pure (ApplicationRunner.jlambda f) noCustomizers <- newArray BeanDefinitionCustomizer 0 registerBean genericContext ApplicationRunner.clazz beanSupplier noCustomizers route : RequestPredicate -> (ServerRequest -> JVM_IO Mono) -> Bean route requestPredicate f context = do let genericContext = the GenericApplicationContext (believe_me context) let beanSupplier = Supplier.jlambda $ RouterFunctions.route requestPredicate $ HandlerFunction.jlambda f noCustomizers <- newArray BeanDefinitionCustomizer 0 registerBean genericContext RouterFunction.clazz beanSupplier noCustomizers get : String -> (ServerRequest -> JVM_IO Mono) -> Bean get pattern f context = do requestPredicate <- RequestPredicates.get pattern route requestPredicate f context registerBeans : List Bean -> ConfigurableApplicationContext -> JVM_IO () registerBeans [] context = pure () registerBeans (bean :: beans) context = do bean context registerBeans beans context runSpring : JClass -> List Bean -> StringArray -> JVM_IO () runSpring clazz beans args = do sources <- listToArray [clazz] appBuilder <- SpringApplicationBuilder.new sources let initializer = ApplicationContextInitializer.jlambda (registerBeans beans) _ <- initializers appBuilder !(listToArray [initializer]) SpringApplicationBuilder.run appBuilder args pure ()
subroutine sub1(num) write(6, *) num end subroutine sub2(subr) call subr(2) end program prog call sub1(1) call sub2(sub1) end
# this is the funtion that appears in the # FoggySurface and FoggyContour graphics, # It is the Octave sombrero, tilted a bit function FoggyMountainObj(θ₁, θ₂) r = sqrt(θ₁^2.0 + θ₂^2.0) + 1e-10 z = sin(r) / (2*r) z = z + θ₁/40.0 - 2*(θ₁/40.0)^2.0 + θ₂/40.0 - 2*(θ₂/40.0)^2.0 z = -z/10.0 # switch to minimization end function FoggyMountainObj(θ) θ₁ = θ[1] θ₂ = θ[2] FoggyMountainObj(θ₁, θ₂) end
import data.nat.gcd open nat /-1. Let a and b be coprime positive integers (recall that coprime here means gcd(a, b) = 1). I open a fast food restaurant which sells chicken nuggets in two sizes – you can either buy a box with a nuggets in, or a box with b nuggets in. Prove that there is some integer N with the property that for all integers m ≥ N, it is possible to buy exactly m nuggets. -/ variables {a b N m c d : ℕ} theorem chicken_mcnugget (hp: gcd a b = 1) (h1: a > 0) (h2 : b >0): ∃ N, ∀ m ≥ N, m = a*c + b*d := sorry
COLUMBUS, Ohio – Ohio State starting pitcher Dan DeLucia went the distance for his second complete game in a 4-1 victory over Illinois in the opening game of a Big Ten series Saturday at Bill Davis Stadium. The Buckeye offense backed him up with 13 hits to improve to a conference best 4-1. DeLucia, a junior from Columbus, Ohio (Bishop Watterson) pitched all nine inning and equaled a career high with nine strikeouts against three walks. He allowed just the one run on six hits to improve to 5-1 this season. His five wins lead the Big Ten. The Buckeyes supported DeLucia’s left arm with 13 hits and started the scoring in the first inning. It was the 15th game this season the Buckeyes had scored in the fifth inning. They have outscored their opponents 32-13 in the opening inning. Ohio State scored twice in the bottom of the first inning to take the early 2-0 lead. Jonathan Zizzo (So., Youngstown, Ohio/Sarasota [Fla.]) led off the inning with a single to center field and went to second on a sacrifice bunt by Matt Angle (So., Whitehall, Ohio/Whitehall-Yearling). Zizzo went to third on fielder’s choice by Eric Fryer (So., Reynoldsburg, Ohio/Reynoldsburg). That put runners at the corners for Ronnie Bourquin (Jr., Canton, Ohio/Canton South), who sent a ball to the right-field corner to plate both base runners. Fryer launched his third home run of the season against the wind out to left field and gave Ohio State a 3-0 lead. Illinois (14-10, 2-3) got that run back in the top of the fifth inning on an RBI single down the left field line by Ryan Snowden. Ryan Hastings led off the inning with a single to left before a foul out and a ground out brought Snowden to the plate with Hastings at second. The Buckeyes (17-6, 4-1) turned a lead-off hit by Bourquin into their fourth run of the game. Jedidiah Stephen (Sr., Caldwell, Ohio/Shenandoah) singled through the left side to put runners at first and second. J.B. Shuck (Fr., Galion, Ohio/Galion) bunted both runners into scoring position before Bourquin scored on a ground out by Adam Schneider (Jr., Agoura Hills, Calif./Agoura) to give Ohio State a 4-1 lead. Jason Zoeller (Jr., Verona, Pa./Shady Side Academy) finished 3-for-4 in the game, while Bourquin was 2-for-4 and drove in two runs. Angle, Fryer and Stephen had two hits and Fryer and Schneider added RBI. Chase Kliment was 2-for-4 to lead the Illini. The teams will play another game Saturday before concluding the series with a doubleheader Sunday at 1:05 p.m. All three games will be broadcast on AM 920 WMNI.
State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X ⊢ RegularSpace X State After: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T ⊢ RegularSpace X Tactic: let _ := sInf T State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T ⊢ RegularSpace X State After: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T this : ∀ (a : X), HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i ⊢ RegularSpace X Tactic: have : ∀ a, (𝓝 a).HasBasis (fun If : ΣI : Set T, I → Set X => If.1.Finite ∧ ∀ i : If.1, If.2 i ∈ @nhds X i a ∧ @IsClosed X i (If.2 i)) fun If => ⋂ i : If.1, If.snd i := by intro a rw [nhds_sInf, ← iInf_subtype''] exact hasBasis_iInf fun t : T => @closed_nhds_basis X t (h t t.2) a State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T this : ∀ (a : X), HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i ⊢ RegularSpace X State After: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a✝ : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T this : ∀ (a : X), HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i a : X If : (I : Set ↑T) × (↑I → Set X) hIf : Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i) i : ↑If.fst ⊢ IsClosed (Sigma.snd If i) Tactic: refine' RegularSpace.ofBasis this fun a If hIf => isClosed_iInter fun i => _ State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a✝ : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T this : ∀ (a : X), HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i a : X If : (I : Set ↑T) × (↑I → Set X) hIf : Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i) i : ↑If.fst ⊢ IsClosed (Sigma.snd If i) State After: no goals Tactic: exact (hIf.2 i).2.mono (sInf_le (i : T).2) State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T ⊢ ∀ (a : X), HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i State After: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a✝ : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T a : X ⊢ HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i Tactic: intro a State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a✝ : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T a : X ⊢ HasBasis (𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i State After: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a✝ : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T a : X ⊢ HasBasis (⨅ (i : ↑T), 𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i Tactic: rw [nhds_sInf, ← iInf_subtype''] State Before: α : Type u β : Type v inst✝¹ : TopologicalSpace α inst✝ : RegularSpace α a✝ : α s : Set α X : Type u_1 T : Set (TopologicalSpace X) h : ∀ (t : TopologicalSpace X), t ∈ T → RegularSpace X x✝ : TopologicalSpace X := sInf T a : X ⊢ HasBasis (⨅ (i : ↑T), 𝓝 a) (fun If => Set.Finite If.fst ∧ ∀ (i : ↑If.fst), Sigma.snd If i ∈ 𝓝 a ∧ IsClosed (Sigma.snd If i)) fun If => ⋂ (i : ↑If.fst), Sigma.snd If i State After: no goals Tactic: exact hasBasis_iInf fun t : T => @closed_nhds_basis X t (h t t.2) a
Best airfare and ticket deals for HRO to DEN flights are based on recent deals found by Expedia.com customers. Distance and aircraft type by airline for flights from Boone County Airport to Denver International Airport. Scan through flights from Boone County Airport (HRO) to Denver International Airport (DEN) for the upcoming week. Sort the list by any column, and click on a dollar sign to see the latest prices available for each flight. Whether it’s for an obligation or the sake of your sanity, sometimes you need to get away. Maybe you need flights from Harrison to Denver to attend your cousin’s wedding, to pitch a business idea to your boss, or perhaps simply to treat yourself to a mini vacation. Regardless of the reasons behind packing your bags and needing to find the cheapest flights from HRO to DEN, we’ve got you covered here at Flights.com. We present you with some of the hottest deals on airfare so stop that Google flights search. We want you to spend less on your flight from Harrison to Denver, so you can spend more during your getaway. With Flights.com, you’ll find it simple to land airline tickets with itineraries matching your travel schedule. What’s more, we provide you with all the information you need to confidently make reservations on your family, business, or personal trip.
-- File created: 2009-07-11 20:29:49 module Haschoo.Parser (runParser, programValue, value, number) where import Control.Applicative ((<$>)) import Control.Arrow (first) import Control.Monad (liftM2) import Data.Char (digitToInt, toLower) import Data.Complex (Complex((:+)), mkPolar) import Data.Maybe (fromJust, fromMaybe, isJust) import Data.Ratio ((%)) import Numeric (readInt) import Text.ParserCombinators.Parsec hiding (runParser) import Haschoo.Types (ScmValue(..), toScmString, toScmVector) import Haschoo.Utils (void, (.:)) runParser :: Parser a -> SourceName -> String -> Either String a runParser = (either (Left . show) Right .:) . parse programValue :: Maybe SourcePos -> Parser (Maybe (ScmValue, String, SourcePos)) programValue pos = do maybe (return ()) setPosition pos optional atmosphere v <- (Just <$> value) <|> (eof >> return Nothing) case v of Nothing -> return Nothing Just v' -> liftM2 (Just .: (,,) v') getInput getPosition values :: Parser [ScmValue] values = optional atmosphere >> (many $ value `discard` atmosphere) value :: Parser ScmValue value = do quotes <- concat <$> many (choice [ string "'" , string "`" , liftM2 (:) (char ',') (string "@" <|> return "") ] `discard` atmosphere) val <- choice [ ident , list , vector , bool , number 10 , character , quotedString ] return $ quote quotes val where quote [] = id quote ('\'' :qs) = quoteWith "quote" qs quote ('`' :qs) = quoteWith "quasiquote" qs quote (',' :'@':qs) = quoteWith "unquote-splicing" qs quote (',' :qs) = quoteWith "unquote" qs quote _ = error "Parser.quote :: the impossible happened" quoteWith s qs = ScmList . (ScmIdentifier s :) . (:[]) . quote qs ident :: Parser ScmValue ident = do -- peculiar needs the try due to negative numbers x <- try $ choice [ peculiar `discard` try delimiter , ordinary `discard` delimiter ] return (ScmIdentifier $ map toLower x) where peculiar = choice [return <$> oneOf "+-", string "..."] ordinary = do x <- oneOf initial xs <- many (oneOf (initial ++ "+-.@" ++ ['0'..'9'])) return (x:xs) where initial = ['a'..'z'] ++ ['A'..'Z'] ++ "!$%&*/:<=>?^_~" bool :: Parser ScmValue bool = ScmBool . (`elem` "tT") <$> try (char '#' >> oneOf "ftFT") character :: Parser ScmValue character = do try (string "#\\") c <- try named <|> anyChar delimiter return (ScmChar c) where named = choice [ string "space" >> return ' ' , string "newline" >> return '\n' ] quotedString :: Parser ScmValue quotedString = fmap toScmString . between (try $ char '"') (char '"') . many $ (char '\\' >> (oneOf "\\\"" <?> concat [show "\\"," or ",show "\""])) <|> satisfy (/= '"') list :: Parser ScmValue list = between (try $ char '(') (optional atmosphere >> char ')') $ do vals <- values if null vals then return$ ScmList vals else do optional atmosphere dot <- optionMaybe (char '.') if isJust dot then do atmosphere end <- value return$ case end of ScmList l -> ScmList (vals ++ l) _ -> mkDotted vals end else return$ ScmList vals where -- Flatten (1 . (2 . 3)) to (1 2 . 3) mkDotted xs (ScmDottedList ys z) = mkDotted (xs ++ ys) z mkDotted xs x = ScmDottedList xs x vector :: Parser ScmValue vector = do try (char '#' >> char '(') toScmVector <$> values `discard` (optional atmosphere >> char ')') number :: Int -> Parser ScmValue number defRadix = do (radix,exact) <- try prefix let p = if isJust radix || isJust exact then id else try n <- p $ complex (fromMaybe False exact) (fromMaybe defRadix radix) delimiter return$ if fromMaybe True exact then n else case n of ScmInt x -> ScmReal (fromInteger x) ScmRat x -> ScmReal (fromRational x) _ -> n where prefix = do r <- radix e <- exactness -- They can be in either order flip (,) e <$> if isJust r then return r else radix where radix = f [('B',2), ('O',8), ('D',10), ('X',16)] exactness = f [('E',True), ('I',False)] f xs = optionMaybe . try $ do char '#' let xs' = map (first toLower) xs ++ xs fromJust . (`lookup` xs') <$> oneOf (map fst xs') complex exact radix = choice [ try $ do n <- sreal False radix ncChar 'i' return (mkImaginary n) , try $ do a <- real exact radix at <- optionMaybe (char '@') if isJust at then mkComplex mkPolar a <$> real False radix else do b <- optionMaybe $ try imaginaryUnit <|> do n <- sreal False radix ncChar 'i' return n return $ case b of Nothing -> a Just n -> mkComplex (:+) a n , mkImaginary <$> imaginaryUnit ] where imaginaryUnit = do neg <- sign ncChar 'i' return (ScmInt neg) mkImaginary = mkComplex (:+) (ScmInt 0) mkComplex f a b = ScmComplex $ f (toDouble a) (toDouble b) toDouble (ScmInt i) = fromInteger i toDouble (ScmRat r) = fromRational r toDouble (ScmReal r) = r toDouble _ = error "number.toDouble :: internal error" real exact radix = do neg <- optionMaybe sign applySign (fromMaybe 1 neg) <$> ureal exact radix sreal exact radix = do neg <- sign applySign neg <$> ureal exact radix applySign neg (ScmInt n) = ScmInt (fromIntegral neg * n) applySign neg (ScmRat n) = ScmRat (fromIntegral neg * n) applySign neg (ScmReal n) = ScmReal (fromIntegral neg * n) applySign _ _ = error "number.applySign :: іnternal error" ureal exact radix = choice [ string "nan.#" >> return (ScmReal $ 0/0) , string "inf.#" >> return (ScmReal $ 1/0) , decimal exact radix , do a <- uint radix b <- optionMaybe $ char '/' >> uint radix case b of Nothing -> if radix == 10 then tryExponent exact a else return a Just n -> return (mkRatio a n) ] mkRatio (ScmInt a) (ScmInt b) = ScmRat (a % b) mkRatio _ _ = error "number.mkRatio :: internal error" decimal exact radix | radix /= 10 = fail "Decimal outside radix 10" | otherwise = tryExponent exact =<< (try . choice) [ do char '.' n <- many1 (digitN 10) skipMany (char '#') return $ readDecimal exact "0" n , do a <- many1 (digitN 10) char '.' b <- many (digitN 10) skipMany (char '#') -- read doesn't like "123." so add a 0 if -- necessary return $ readDecimal exact a (if null b then "0" else b) , do n <- many1 (digitN 10) hashes <- map (const '0') <$> many1 (char '#') char '.' hashes2 <- many (char '#') return . inexactHashes (hashes ++ hashes2) . ScmInt $ readInteger 10 (n ++ hashes) ] tryExponent exact n = do ex <- optionMaybe $ do oneOf "esfdlESFDL" -- Ignore the exponent: all Double neg <- optionMaybe sign xs <- many1 (digitN 10) return$ fromMaybe 1 neg * readInteger 10 xs return$ case ex of Nothing -> n Just e | not exact -> ScmReal (10^^e * toDouble n) | otherwise -> case n of ScmInt x -> ScmRat (10^^e * fromInteger x) ScmRat x -> ScmRat (10^^e * x) _ -> error$ "Parser.tryExponent :: " ++ "the impossible happened" uint radix = do n <- many1 (digitN radix) hashes <- map (const '0') <$> many (char '#') return . inexactHashes hashes . ScmInt $ readInteger radix (n ++ hashes) -- If any # were present, the value is inexact (R5RS 6.2.4) inexactHashes :: String -> ScmValue -> ScmValue inexactHashes [] = id inexactHashes _ = ScmReal . toDouble digitN :: Int -> Parser Char digitN 2 = oneOf "01" digitN 8 = octDigit digitN 10 = digit digitN 16 = hexDigit digitN _ = error "number.digitN :: internal error" sign = (\c -> if c == '+' then 1 else -1) <$> oneOf "+-" -- These read functions all assume correctly formed input readInteger :: Int -> String -> Integer readInteger radix = fst.head . readInt (fromIntegral radix) (const True) digitToInt readDecimal :: Bool -> String -> String -> ScmValue readDecimal False as bs = ScmReal . read . concat $ [as, ".", bs] readDecimal True as bs = ScmRat $ fromInteger (readInteger 10 as) + fromInteger (readInteger 10 bs) / 10 ^ length bs -- Pushes back anything relevant for other parsers delimiter :: Parser () delimiter = choice [ whitespaceOrComment , void . lookAhead . try $ oneOf "()\"" , try eof ] atmosphere :: Parser () atmosphere = skipMany whitespaceOrComment whitespaceOrComment :: Parser () whitespaceOrComment = choice [ void newline , char '\r' >> optional newline , void space , char ';' >> skipMany (noneOf "\n\r") ] ncChar :: Char -> Parser Char ncChar c = toLower <$> satisfy ((== c) . toLower) discard :: Parser a -> Parser b -> Parser a discard a b = a >>= \a' -> b >> return a'
theory Proof_3_2 imports HandDryer VCTheoryLemmas Extra begin theorem proof_3_2: "VC2 inv3 s0 hands_value" apply(simp only: VC2_def inv3_def R3_def dryer_def) apply(rule impI) apply(rule conjI) apply(rule conjI) apply(simp) proof - define s:: state where "s = (toEnv (setPstate (setVarBool (setVarAny s0 hands_value) (Suc (Suc 0)) ON) Ctrl drying))" assume VC: " ((toEnvP s0 \<and> (\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)))) \<and> extraInv s0) \<and> env (setVarAny s0 hands_value) hands_value \<and> getPstate (setVarAny s0 hands_value) Ctrl = waiting \<and> getVarBool (setVarAny s0 hands_value) hands = ON" show " \<forall>s1 s2. substate s1 s2 \<and> substate s2 (toEnv (setPstate (setVarBool (setVarAny s0 hands_value) (Suc (Suc 0)) ON) Ctrl drying)) \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 (toEnv (setPstate (setVarBool (setVarAny s0 hands_value) (Suc (Suc 0)) ON) Ctrl drying)) \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 (toEnv (setPstate (setVarBool (setVarAny s0 hands_value) (Suc (Suc 0)) ON) Ctrl drying)) \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF))" apply(simp only: s_def[symmetric]) proof(rule allI; rule allI; rule impI) fix s1 s2 assume req_prems: "substate s1 s2 \<and> substate s2 s \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF" then obtain "10 \<le> toEnvNum s2 s" by auto from le_imp_less_or_eq[OF this] show " \<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof assume 1: "10 < toEnvNum s2 s" with req_prems substate_eq_or_predEnv toEnvNum_id s_def have 2: "substate s2 s0" by (simp add: s_def split: if_splits) from VC obtain "\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF))" by auto with req_prems 1 2 have "\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" by (auto simp add: s_def split: if_splits) then obtain s4 where 3: " toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" .. have "(toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof from 3 show "toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)" by (simp add: s_def) next from 3 show "\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by simp qed thus ?thesis by auto next assume 4: "10 = toEnvNum s2 s" from substate_asym have 5: "\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s2 \<and> s3 \<noteq> s2 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto show ?thesis proof - define s5:: state where "s5=s2" have "toEnvP s5 \<and> substate s2 s5 \<and> substate s5 s \<longrightarrow>pred3 s2 s s5" proof(induction rule: state_down_ind) case 1 then show ?case using req_prems s_def by auto next case 2 then show ?case apply(simp only: pred3_def) proof assume 6: " \<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s \<and> s3 \<noteq> s \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" have " (toEnvP s \<and> substate s s \<and> substate s s \<and> toEnvNum s2 s \<le> 10) \<and> (getVarBool s (Suc (Suc 0)) = OFF \<or> getVarBool s hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s s3 \<and> substate s3 s \<and> s3 \<noteq> s \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof from 4 substate_refl s_def req_prems show "(toEnvP s \<and> substate s s \<and> substate s s \<and> toEnvNum s2 s \<le> 10 )" by auto next from VC have " (getVarBool s (Suc (Suc 0)) = OFF \<or> getVarBool s hands = ON)" by (simp add: s_def) moreover from substate_asym have "\<forall>s3. toEnvP s3 \<and> substate s s3 \<and> substate s3 s \<and> s3 \<noteq> s \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto ultimately show "(getVarBool s (Suc (Suc 0)) = OFF \<or> getVarBool s hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s s3 \<and> substate s3 s \<and> s3 \<noteq> s \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" .. qed thus "\<exists>s4. toEnvP s4 \<and> substate s s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" by auto qed next case (3 s5) then show ?case apply(simp only: pred3_def) proof from 3(3) have 6: " (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s5 \<and> s3 \<noteq> s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF) \<Longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s5 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s5 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)) " by (auto simp add: pred3_def) assume 7: " \<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 (predEnv s5) \<and> s3 \<noteq> predEnv s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" show "\<exists>s4. toEnvP s4 \<and> substate (predEnv s5) s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof cases assume 10: "(getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON)" from predEnv_substate 3 substate_trans have 8: "substate (predEnv s5) s" by blast from 3(2) substate_eq_or_predEnv req_prems have 9: "substate s2 (predEnv s5)" by auto have "toEnvP (predEnv s5) \<and> substate (predEnv s5) (predEnv s5) \<and> substate (predEnv s5) s \<and> toEnvNum s2 (predEnv s5) \<le> 10 \<and> (getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 (predEnv s5) \<and> s3 \<noteq> (predEnv s5) \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof - from predEnvP_or_emptyState[of s5] have "toEnvP (predEnv s5)" proof assume "toEnvP (predEnv s5)" thus ?thesis by assumption next assume "predEnv s5 = emptyState" with 9 req_prems show ?thesis by (cases s2; auto) qed moreover from substate_refl have " substate (predEnv s5) (predEnv s5)" by auto moreover from 8 have "substate (predEnv s5) s" by assumption moreover from 4 8 9 toEnvNum3 have "toEnvNum s2 (predEnv s5) \<le> 10" by auto moreover from 10 have "(getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON)" by assumption moreover from substate_asym have "\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 (predEnv s5) \<and> s3 \<noteq> predEnv s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto ultimately show ?thesis by auto qed thus ?thesis by auto next assume 10: "\<not> (getVarBool (predEnv s5) (Suc (Suc 0)) = OFF \<or> getVarBool (predEnv s5) hands = ON)" with substate_eq_or_predEnv 7 have " \<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s5 \<and> s3 \<noteq> s5 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto from 6[OF this] obtain s4 where 11: "toEnvP s4 \<and> substate s5 s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s5 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" .. have "(toEnvP s4 \<and> substate (predEnv s5) s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)) \<and> (\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)" proof from 11 predEnv_substate substate_trans show "toEnvP s4 \<and> substate (predEnv s5) s4 \<and> substate s4 s \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON)" by blast next show "\<forall>s3. toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" proof(rule allI; rule impI) fix s3 assume 12: "toEnvP s3 \<and> substate (predEnv s5) s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4" with 11 3(1) predEnv_substate_imp_eq_or_substate have "s3 = predEnv s5 \<or> substate s5 s3" by auto with 10 11 12 show "getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF" by auto qed qed thus ?thesis by auto qed qed qed with s5_def req_prems substate_refl pred3_def 5 show ?thesis by auto qed qed qed next assume "((toEnvP s0 \<and> (\<forall>s1 s2. substate s1 s2 \<and> substate s2 s0 \<and> toEnvP s1 \<and> toEnvP s2 \<and> toEnvNum s1 s2 = hands \<and> 10 \<le> toEnvNum s2 s0 \<and> getVarBool s1 hands = ON \<and> getVarBool s1 (Suc (Suc 0)) = ON \<and> getVarBool s2 hands = OFF \<longrightarrow> (\<exists>s4. toEnvP s4 \<and> substate s2 s4 \<and> substate s4 s0 \<and> toEnvNum s2 s4 \<le> 10 \<and> (getVarBool s4 (Suc (Suc 0)) = OFF \<or> getVarBool s4 hands = ON) \<and> (\<forall>s3. toEnvP s3 \<and> substate s2 s3 \<and> substate s3 s4 \<and> s3 \<noteq> s4 \<longrightarrow> getVarBool s3 (Suc (Suc 0)) = ON \<and> getVarBool s3 hands = OFF)))) \<and> extraInv s0) \<and> env (setVarAny s0 hands_value) hands_value \<and> getPstate (setVarAny s0 hands_value) Ctrl = waiting \<and> getVarBool (setVarAny s0 hands_value) hands = ON " with extra2 show "extraInv (toEnv (setPstate (setVarBool (setVarAny s0 hands_value) (Suc (Suc 0)) ON) Ctrl drying))" by (auto simp add: VC2_def dryer_def) qed end
! ################################################################################################################################## ! Begin MIT license text. ! _______________________________________________________________________________________________________ ! Copyright 2019 Dr William R Case, Jr ([email protected]) ! Permission is hereby granted, free of charge, to any person obtaining a copy of this software and ! associated documentation files (the "Software"), to deal in the Software without restriction, including ! without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ! copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to ! the following conditions: ! The above copyright notice and this permission notice shall be included in all copies or substantial ! portions of the Software and documentation. ! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ! OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ! FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ! AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ! LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ! THE SOFTWARE. ! _______________________________________________________________________________________________________ ! End MIT license text. SUBROUTINE TETRA ( OPT, INT_ELEM_ID, IORD, RED_INT_SHEAR, WRITE_WARN ) ! Isoparametric tetrahedron solid element (4 or 10 nodes). Full gaussian integration is the only option (no reduced integration) ! Subroutine calculates: ! 1) ME = element mass matrix , if OPT(1) = 'Y' ! 2) PTE = element thermal load vectors , if OPT(2) = 'Y' ! 3) SEi, STEi = element stress data recovery matrices, if OPT(3) = 'Y' ! 4) KE = element linea stiffness matrix , if OPT(4) = 'Y' ! 5) KED = element differen stiff matrix calc , if OPT(6) = 'Y' = 'Y' USE PENTIUM_II_KIND, ONLY : BYTE, LONG, DOUBLE USE IOUNT1, ONLY : WRT_ERR, WRT_LOG, ERR, F04, F06 USE SCONTR, ONLY : BLNK_SUB_NAM, FATAL_ERR, MAX_ORDER_TETRA, NTSUB USE TIMDAT, ONLY : TSEC USE CONSTANTS_1, ONLY : QUARTER, ZERO, FOUR USE DEBUG_PARAMETERS, ONLY : DEBUG USE SUBR_BEGEND_LEVELS, ONLY : TETRA_BEGEND USE PARAMS, ONLY : EPSIL USE MODEL_STUF, ONLY : ALPVEC, BE1, BE2, DT, EID, ELGP, NUM_EMG_FATAL_ERRS, ES, KE, ME, PTE, RHO, & SE1, SE2, STE1, TREF, TYPE USE TETRA_USE_IFs IMPLICIT NONE CHARACTER(LEN=LEN(BLNK_SUB_NAM)):: SUBR_NAME = 'TETRA' CHARACTER( 1*BYTE), INTENT(IN) :: RED_INT_SHEAR ! If 'Y', use Gaussian weighted avg of B matrices for shear terms CHARACTER( 1*BYTE), INTENT(IN) :: OPT(6) ! 'Y'/'N' flags for whether to calc certain elem matrices CHARACTER(LEN=*), INTENT(IN) :: WRITE_WARN ! If 'Y" write warning messages, otherwise do not INTEGER(LONG) :: GAUSS_PT ! Gauss point number (used for DEBUG output in subr SHP3DP CHARACTER(46*BYTE) :: IORD_MSG ! Character name of an integ order (used for debug output) INTEGER(LONG), INTENT(IN) :: INT_ELEM_ID ! Internal element ID INTEGER(LONG), INTENT(IN) :: IORD ! Gaussian integ order for element INTEGER(LONG) :: I,J,K,L,M,N ! DO loop indices INTEGER(LONG) :: II,JJ ! Counters INTEGER(LONG) :: ID(3*ELGP) ! Array which shows equivalence of DOF's in virgin element with the ! 6 DOF/grid of the final element stiffness matrix ! Indicator of no output of elem data to BUG file INTEGER(LONG), PARAMETER :: SUBR_BEGEND = TETRA_BEGEND REAL(DOUBLE) :: ALP(6) ! First col of ALPVEC REAL(DOUBLE) :: B(6,3*ELGP,IORD*IORD*IORD) ! Strain-displ matrix for this element for all Gauss points REAL(DOUBLE) :: BI(6,3*ELGP) ! Strain-displ matrix for this element for one Gauss point REAL(DOUBLE) :: DETJ(IORD*IORD*IORD) ! Determinant of JAC for all Gauss points REAL(DOUBLE) :: DPSHG(3,ELGP) ! Output from subr SHP3DT. Derivatives of PSH wrt elem isopar coord REAL(DOUBLE) :: DPSHX(3,ELGP) ! Derivatives of PSH wrt elem x, y coords. REAL(DOUBLE) :: DUM0(3*ELGP) ! Intermediate matrix used in solving for elem matrices REAL(DOUBLE) :: DUM1(3*ELGP) ! Intermediate matrix used in solving for elem matrices REAL(DOUBLE) :: DUM2(6,3*ELGP) ! Intermediate matrix used in solving for elem matrices REAL(DOUBLE) :: DUM3(3*ELGP,3*ELGP) ! Intermediate matrix used in solving for elem matrices REAL(DOUBLE) :: DUM4(6,3*ELGP) ! Intermediate matrix used in solving for elem matrices REAL(DOUBLE) :: DUM5(3*ELGP,3*ELGP) ! Intermediate matrix used in solving for KE elem matrices REAL(DOUBLE) :: EALP(6) ! Intermed var used in calc PTE therm lds & STEi therm stress coeff REAL(DOUBLE) :: EPS1 ! A small number to compare to real zero ! Array of all DT values at the grids GRID_DT_ARRAY(i,j) = DT(i,j) REAL(DOUBLE) :: GRID_DT_ARRAY(ELGP,NTSUB) REAL(DOUBLE) :: HHH_IJK(MAX_ORDER_TETRA)! An output from subr ORDER_TRIA, called herein. Gauss weights. REAL(DOUBLE) :: INTFAC ! An integ factor (constant multiplier for the Gauss integ) REAL(DOUBLE) :: JAC(3,3) ! An output from subr JAC3D, called herein. 3 x 3 Jacobian matrix. REAL(DOUBLE) :: JACI(3,3) ! An output from subr JAC3D, called herein. 3 x 3 Jacobian inverse. REAL(DOUBLE) :: M0 ! An intermediate variable used in calc elem mass, ME REAL(DOUBLE) :: PSH(ELGP) ! Output from subr SHP3DT. Shape fcn at Gauss pts SSI, SSJ REAL(DOUBLE) :: SSS_I(MAX_ORDER_TETRA) ! An output from subr ORDER_TRIA, called herein. Gauss abscissa's. REAL(DOUBLE) :: SSS_J(MAX_ORDER_TETRA) ! An output from subr ORDER_TRIA, called herein. Gauss abscissa's. REAL(DOUBLE) :: SSS_K(MAX_ORDER_TETRA) ! An output from subr ORDER_TRIA, called herein. Gauss abscissa's. REAL(DOUBLE) :: TBAR(NTSUB) ! Average elem temperature for each subcase REAL(DOUBLE) :: TEMP ! Temperature to use in PTE calc REAL(DOUBLE) :: TGAUSS(1,NTSUB) ! Temp at a Gauss point for a theral subcase REAL(DOUBLE) :: TREF1 ! TREF(1) REAL(DOUBLE) :: VOLUME ! 3D element volume ! ********************************************************************************************************************************** IF (WRT_LOG >= SUBR_BEGEND) THEN CALL OURTIM WRITE(F04,9001) SUBR_NAME,TSEC 9001 FORMAT(1X,A,' BEGN ',F10.3) ENDIF ! ********************************************************************************************************************************** EPS1 = EPSIL(1) ! Calculate volume by Gaussian integration CALL ORDER_TETRA ( IORD, SSS_I, SSS_J, SSS_K, HHH_IJK ) IORD_MSG = ' ' IORD_MSG = 'for 3-D solid strains, input IORD = ' VOLUME = ZERO DO I=1,IORD CALL SHP3DT ( I, ELGP, SUBR_NAME, IORD_MSG, IORD, SSS_I(I), SSS_J(I), SSS_K(I), 'Y', PSH, DPSHG ) CALL JAC3D ( SSS_I(I), SSS_J(I), SSS_K(I), DPSHG, 'Y', JAC, JACI, DETJ(I) ) VOLUME = VOLUME + HHH_IJK(I)*DETJ(I) ENDDO ! If VOLUME <= 0, write error and return IF (VOLUME < EPS1) THEN WRITE(ERR,1925) EID, TYPE, 'VOLUME', VOLUME WRITE(F06,1925) EID, TYPE, 'VOLUME', VOLUME NUM_EMG_FATAL_ERRS = NUM_EMG_FATAL_ERRS + 1 FATAL_ERR = FATAL_ERR + 1 RETURN ENDIF ! Calculate ID array JJ = 0 DO I=1,ELGP II = 6*(I - 1) DO J=1,3 II = II + 1 JJ = JJ + 1 ID(JJ) = II ENDDO ENDDO ! ALP is first col of ALPVEC ALP(1) = ALPVEC(1,1) ALP(2) = ALPVEC(2,1) ALP(3) = ALPVEC(3,1) ALP(4) = ZERO ALP(5) = ZERO ALP(6) = ZERO TREF1 = TREF(1) ! EALP is needed to calculate both PTE and STE2 CALL MATMULT_FFF ( ES, ALP, 6, 6, 1, EALP ) ! Calc TBAR (used for PTE, STEi) IF ((OPT(2) == 'Y') .OR. (OPT(3) == 'Y')) THEN DO J=1,NTSUB TBAR(J) = ZERO DO K=1,ELGP TBAR(J) = TBAR(J) + DT(K,J) ENDDO TBAR(J) = TBAR(J)/ELGP - TREF1 ENDDO ENDIF ! ********************************************************************************************************************************** ! Generate the mass matrix for this element. IF (OPT(1) == 'Y') THEN M0 = (RHO(1))*VOLUME/ELGP DO I=1,ELGP DO J=1,3 K = 6*(I-1) + J ME(K,K) = M0 ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** ! Generate B matrices. The B matrix terms for Gauss point k are B(i,j,k) DO I=1,6 DO J=1,3*ELGP DO K=1,IORD*IORD*IORD B(I,J,K) = ZERO ENDDO ENDDO ENDDO IORD_MSG = 'for 3-D solid strains, input IORD = ' DO I=1,IORD CALL SHP3DT ( I, ELGP, SUBR_NAME, IORD_MSG, IORD, SSS_I(I), SSS_J(I), SSS_K(I), 'N', PSH,DPSHG ) CALL JAC3D ( SSS_I(I), SSS_J(I), SSS_K(I), DPSHG, 'N', JAC, JACI, DETJ(I) ) CALL MATMULT_FFF ( JACI, DPSHG, 3, 3, ELGP, DPSHX ) CALL B3D_ISOPARAMETRIC ( DPSHX, I, I, I, I, 'direct strains', 'Y', BI ) DO L=1,6 DO M=1,3*ELGP B(L,M,I) = BI(L,M) ENDDO ENDDO ENDDO ! ********************************************************************************************************************************** ! Calculate element thermal loads. IF (OPT(2) == 'Y') THEN DO N=1,NTSUB DO L=1,ELGP GRID_DT_ARRAY(L,N) = DT(L,N) ENDDO ENDDO DO N=1,NTSUB DO L=1,3*ELGP DUM0(L) = ZERO DUM1(L) = ZERO ENDDO IORD_MSG = 'for 3-D solid strains, input IORD = ' GAUSS_PT = 0 DO I=1,IORD GAUSS_PT = GAUSS_PT + 1 DO L=1,6 DO M=1,3*ELGP BI(L,M) = B(L,M,GAUSS_PT) ENDDO ENDDO CALL MATMULT_FFF_T ( BI, EALP, 6, 3*ELGP, 1, DUM0 ) INTFAC = DETJ(GAUSS_PT)*HHH_IJK(I) IF (DEBUG(192) == 0) THEN ! Use temperatures at Gauss points for PTE CALL SHP3DT ( I, ELGP, SUBR_NAME, IORD_MSG, IORD, SSS_I(I), SSS_J(I), SSS_K(I), 'N', PSH, DPSHG ) CALL MATMULT_FFF ( PSH, GRID_DT_ARRAY, 1, ELGP, NTSUB, TGAUSS ) TEMP = TGAUSS(1,N) - TREF1 ELSE ! Use avg element temperature for PTE TEMP = TBAR(N) ENDIF DO L=1,3*ELGP DUM1(L) = DUM1(L) + DUM0(L)*TEMP*INTFAC ENDDO ENDDO DO L=1,3*ELGP PTE(ID(L),N) = DUM1(L) ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** ! Calculate BEi, SEi matrices for strain, stress data recovery. IF (OPT(3) == 'Y') THEN DO K=1,6 DO L=1,3*ELGP DUM2(K,L) = ZERO ENDDO ENDDO GAUSS_PT = 1 ! Calc SE1,2,3 IORD_MSG = 'for 3-D solid strains, = ' CALL SHP3DT ( 1, ELGP, SUBR_NAME, IORD_MSG, 1, QUARTER, QUARTER, QUARTER, 'N', PSH, DPSHG ) CALL JAC3D ( QUARTER, QUARTER, QUARTER, DPSHG, 'N', JAC, JACI, DETJ(GAUSS_PT) ) CALL MATMULT_FFF ( JACI, DPSHG, 3, 3, ELGP, DPSHX ) CALL B3D_ISOPARAMETRIC ( DPSHX, GAUSS_PT, 1, 1, 1, 'all strains', 'N', BI ) CALL MATMULT_FFF ( ES, BI, 6, 6, 3*ELGP, DUM2 ) DO I=1,3 DO J=1,3*ELGP SE1(I,ID(J),1) = DUM2(I ,J) SE2(I,ID(J),1) = DUM2(I+3,J) ENDDO ENDDO DO J=1,NTSUB ! STE thermal stress terms STE1(1,J,1) = EALP(1)*TBAR(J) STE1(2,J,1) = EALP(2)*TBAR(J) STE1(3,J,1) = EALP(3)*TBAR(J) ENDDO DO I=1,3 ! Strain-displ matrix DO J=1,3*ELGP BE1(I,ID(J),1) = BI(I ,J) BE2(I,ID(J),1) = BI(I+3,J) ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** ! Calculate element stiffness matrix KE. IF (OPT(4) == 'Y') THEN DO I=1,3*ELGP DO J=1,3*ELGP DUM3(I,J) = ZERO ENDDO ENDDO IORD_MSG = ' ' DO I=1,IORD DO L=1,6 DO M=1,3*ELGP BI(L,M) = B(L,M,I) ENDDO ENDDO CALL MATMULT_FFF ( ES, BI, 6, 6, 3*ELGP, DUM4 ) CALL MATMULT_FFF_T ( BI, DUM4, 6, 3*ELGP, 3*ELGP, DUM5 ) INTFAC = DETJ(I)*HHH_IJK(I) DO L=1,3*ELGP DO M=1,3*ELGP DUM3(L,M) = DUM3(L,M) + DUM5(L,M)*INTFAC ENDDO ENDDO ENDDO DO I=1,3*ELGP DO J=1,3*ELGP KE(ID(I),ID(J)) = DUM3(I,J) ENDDO ENDDO ! Set lower triangular portion of KE equal to upper portion DO I=2,6*ELGP DO J=1,I-1 KE(I,J) = KE(J,I) ENDDO ENDDO ENDIF ! ********************************************************************************************************************************** IF (WRT_LOG >= SUBR_BEGEND) THEN CALL OURTIM WRITE(F04,9002) SUBR_NAME,TSEC 9002 FORMAT(1X,A,' END ',F10.3) ENDIF RETURN ! ********************************************************************************************************************************** 1925 FORMAT(' *ERROR 1925: ELEMENT ',I8,', TYPE ',A,', HAS ZERO OR NEGATIVE ',A,' = ',1ES9.1) ! ********************************************************************************************************************************** END SUBROUTINE TETRA
record R₁ (M : Set → Set) : Set₁ where field return : ∀ {A} → A → M A map : ∀ {A B} → (A → B) → M A → M B open R₁ ⦃ … ⦄ public record R₂ (M : Set → Set) : Set₁ where field instance r₁ : R₁ M data Wrap₁ (A : Set) : Set where box : A → Wrap₁ A instance r₁ : R₁ Wrap₁ R₁.return r₁ x = box x R₁.map r₁ f (box x) = box (f x) record Wrap₂ (A : Set) : Set where field run : A postulate instance r₂ : R₂ Wrap₂ A : Set f : A → A g : A → Wrap₁ A _≡_ : {A : Set} → A → A → Set refl : {A : Set} (x : A) → x ≡ x trans : {A : Set} (x : A) {y z : A} → x ≡ y → y ≡ z → x ≡ z id : {A : Set} (x : A) {y : A} → x ≡ y → x ≡ y h : ∀ x → map f (g x) ≡ map f (return x) → map f (g x) ≡ return (f x) h x eq = trans (map f (g x)) eq (id (map f (return x)) (refl (return (f x))))
def f (x : Nat) : Nat := match x with | 30 => 31 | y+1 => y | 0 => 10 #eval f 20 #eval f 0 #eval f 30 universe u theorem ex1 {α : Sort u} {a b : α} (h : a ≅ b) : a = b := match α, a, b, h with | _, _, _, HEq.refl _ => rfl theorem ex2 {α : Sort u} {a b : α} (h : a ≅ b) : a = b := match a, b, h with | _, _, HEq.refl _ => rfl theorem ex3 {α : Sort u} {a b : α} (h : a ≅ b) : a = b := match b, h with | _, HEq.refl _ => rfl theorem ex4 {α β : Sort u} {b : β} {a a' : α} (h₁ : a = a') (h₂ : a' ≅ b) : a ≅ b := match β, a', b, h₁, h₂ with | _, _, _, rfl, HEq.refl _ => HEq.refl _ theorem ex5 {α β : Sort u} {b : β} {a a' : α} (h₁ : a = a') (h₂ : a' ≅ b) : a ≅ b := match a', h₁, h₂ with | _, rfl, h₂ => h₂ theorem ex6 {α β : Sort u} {b : β} {a a' : α} (h₁ : a = a') (h₂ : a' ≅ b) : a ≅ b := by { subst h₁; assumption } theorem ex7 (a : Bool) (p q : Prop) (h₁ : a = true → p) (h₂ : a = false → q) : p ∨ q := match (generalizing := false) h:a with | true => Or.inl $ h₁ h | false => Or.inr $ h₂ h theorem ex7' (a : Bool) (p q : Prop) (h₁ : a = true → p) (h₂ : a = false → q) : p ∨ q := match a with | true => Or.inl $ h₁ rfl | false => Or.inr $ h₂ rfl def head {α} (xs : List α) (h : xs = [] → False) : α := match he:xs with | [] => by contradiction | x::_ => x variable {α : Type u} {p : α → Prop} theorem ex8 {a1 a2 : {x // p x}} (h : a1.val = a2.val) : a1 = a2 := match a1, a2, h with | ⟨_, _⟩, ⟨_, _⟩, rfl => rfl universe v variable {β : α → Type v} theorem ex9 {p₁ p₂ : Sigma (fun a => β a)} (h₁ : p₁.1 = p₂.1) (h : p₁.2 ≅ p₂.2) : p₁ = p₂ := match p₁, p₂, h₁, h with | ⟨_, _⟩, ⟨_, _⟩, rfl, HEq.refl _ => rfl inductive F : Nat → Type | z : {n : Nat} → F (n+1) | s : {n : Nat} → F n → F (n+1) def f0 {α : Sort u} (x : F 0) : α := nomatch x def f0' {α : Sort u} (x : F 0) : α := nomatch id x def f1 {α : Sort u} (x : F 0 × Bool) : α := nomatch x def f2 {α : Sort u} (x : Sum (F 0) (F 0)) : α := nomatch x def f3 {α : Sort u} (x : Bool × F 0) : α := nomatch x def f4 (x : Sum (F 0 × Bool) Nat) : Nat := match x with | Sum.inr x => x #eval f4 $ Sum.inr 100
lemma cis_zero [simp]: "cis 0 = 1"
[STATEMENT] lemma parts_insert_Sign [simp]: "parts (insert (Sign X Y) H) = insert (Sign X Y) (parts {X} \<union> parts H)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. parts (insert (Sign X Y) H) = insert (Sign X Y) (parts {X} \<union> parts H) [PROOF STEP] apply (rule equalityI) [PROOF STATE] proof (prove) goal (2 subgoals): 1. parts (insert (Sign X Y) H) \<subseteq> insert (Sign X Y) (parts {X} \<union> parts H) 2. insert (Sign X Y) (parts {X} \<union> parts H) \<subseteq> parts (insert (Sign X Y) H) [PROOF STEP] apply (rule subsetI) [PROOF STATE] proof (prove) goal (2 subgoals): 1. \<And>x. x \<in> parts (insert (Sign X Y) H) \<Longrightarrow> x \<in> insert (Sign X Y) (parts {X} \<union> parts H) 2. insert (Sign X Y) (parts {X} \<union> parts H) \<subseteq> parts (insert (Sign X Y) H) [PROOF STEP] apply (erule parts.induct, auto) [PROOF STATE] proof (prove) goal: No subgoals! [PROOF STEP] done
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import analysis.specific_limits import order.filter.countable_Inter import topology.G_delta /-! # Baire theorem In a complete metric space, a countable intersection of dense open subsets is dense. The good concept underlying the theorem is that of a Gδ set, i.e., a countable intersection of open sets. Then Baire theorem can also be formulated as the fact that a countable intersection of dense Gδ sets is a dense Gδ set. We prove Baire theorem, giving several different formulations that can be handy. We also prove the important consequence that, if the space is covered by a countable union of closed sets, then the union of their interiors is dense. The names of the theorems do not contain the string "Baire", but are instead built from the form of the statement. "Baire" is however in the docstring of all the theorems, to facilitate grep searches. We also define the filter `residual α` generated by dense `Gδ` sets and prove that this filter has the countable intersection property. -/ noncomputable theory open_locale classical topological_space filter ennreal open filter encodable set variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*} section Baire_theorem open emetric ennreal variables [emetric_space α] [complete_space α] /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here when the source space is ℕ (and subsumed below by `dense_Inter_of_open` working with any encodable source space). -/ theorem dense_Inter_of_open_nat {f : ℕ → set α} (ho : ∀n, is_open (f n)) (hd : ∀n, dense (f n)) : dense (⋂n, f n) := begin let B : ℕ → ℝ≥0∞ := λn, 1/2^n, have Bpos : ∀n, 0 < B n, { intro n, simp only [B, one_div, one_mul, ennreal.inv_pos], exact pow_ne_top two_ne_top }, /- Translate the density assumption into two functions `center` and `radius` associating to any n, x, δ, δpos a center and a positive radius such that `closed_ball center radius` is included both in `f n` and in `closed_ball x δ`. We can also require `radius ≤ (1/2)^(n+1)`, to ensure we get a Cauchy sequence later. -/ have : ∀n x δ, δ > 0 → ∃y r, r > 0 ∧ r ≤ B (n+1) ∧ closed_ball y r ⊆ (closed_ball x δ) ∩ f n, { assume n x δ δpos, have : x ∈ closure (f n) := hd n x, rcases emetric.mem_closure_iff.1 this (δ/2) (ennreal.half_pos δpos) with ⟨y, ys, xy⟩, rw edist_comm at xy, obtain ⟨r, rpos, hr⟩ : ∃ r > 0, closed_ball y r ⊆ f n := nhds_basis_closed_eball.mem_iff.1 (is_open_iff_mem_nhds.1 (ho n) y ys), refine ⟨y, min (min (δ/2) r) (B (n+1)), _, _, λz hz, ⟨_, _⟩⟩, show 0 < min (min (δ / 2) r) (B (n+1)), from lt_min (lt_min (ennreal.half_pos δpos) rpos) (Bpos (n+1)), show min (min (δ / 2) r) (B (n+1)) ≤ B (n+1), from min_le_right _ _, show z ∈ closed_ball x δ, from calc edist z x ≤ edist z y + edist y x : edist_triangle _ _ _ ... ≤ (min (min (δ / 2) r) (B (n+1))) + (δ/2) : add_le_add hz (le_of_lt xy) ... ≤ δ/2 + δ/2 : add_le_add (le_trans (min_le_left _ _) (min_le_left _ _)) (le_refl _) ... = δ : ennreal.add_halves δ, show z ∈ f n, from hr (calc edist z y ≤ min (min (δ / 2) r) (B (n+1)) : hz ... ≤ r : le_trans (min_le_left _ _) (min_le_right _ _)) }, choose! center radius H using this, refine λ x, (mem_closure_iff_nhds_basis nhds_basis_closed_eball).2 (λ ε εpos, _), /- `ε` is positive. We have to find a point in the ball of radius `ε` around `x` belonging to all `f n`. For this, we construct inductively a sequence `F n = (c n, r n)` such that the closed ball `closed_ball (c n) (r n)` is included in the previous ball and in `f n`, and such that `r n` is small enough to ensure that `c n` is a Cauchy sequence. Then `c n` converges to a limit which belongs to all the `f n`. -/ let F : ℕ → (α × ℝ≥0∞) := λn, nat.rec_on n (prod.mk x (min ε (B 0))) (λn p, prod.mk (center n p.1 p.2) (radius n p.1 p.2)), let c : ℕ → α := λn, (F n).1, let r : ℕ → ℝ≥0∞ := λn, (F n).2, have rpos : ∀n, r n > 0, { assume n, induction n with n hn, exact lt_min εpos (Bpos 0), exact (H n (c n) (r n) hn).1 }, have rB : ∀n, r n ≤ B n, { assume n, induction n with n hn, exact min_le_right _ _, exact (H n (c n) (r n) (rpos n)).2.1 }, have incl : ∀n, closed_ball (c (n+1)) (r (n+1)) ⊆ (closed_ball (c n) (r n)) ∩ (f n) := λn, (H n (c n) (r n) (rpos n)).2.2, have cdist : ∀n, edist (c n) (c (n+1)) ≤ B n, { assume n, rw edist_comm, have A : c (n+1) ∈ closed_ball (c (n+1)) (r (n+1)) := mem_closed_ball_self, have I := calc closed_ball (c (n+1)) (r (n+1)) ⊆ closed_ball (c n) (r n) : subset.trans (incl n) (inter_subset_left _ _) ... ⊆ closed_ball (c n) (B n) : closed_ball_subset_closed_ball (rB n), exact I A }, have : cauchy_seq c := cauchy_seq_of_edist_le_geometric_two _ one_ne_top cdist, -- as the sequence `c n` is Cauchy in a complete space, it converges to a limit `y`. rcases cauchy_seq_tendsto_of_complete this with ⟨y, ylim⟩, -- this point `y` will be the desired point. We will check that it belongs to all -- `f n` and to `ball x ε`. use y, simp only [exists_prop, set.mem_Inter], have I : ∀n, ∀m ≥ n, closed_ball (c m) (r m) ⊆ closed_ball (c n) (r n), { assume n, refine nat.le_induction _ (λm hnm h, _), { exact subset.refl _ }, { exact subset.trans (incl m) (subset.trans (inter_subset_left _ _) h) }}, have yball : ∀n, y ∈ closed_ball (c n) (r n), { assume n, refine is_closed_ball.mem_of_tendsto ylim _, refine (filter.eventually_ge_at_top n).mono (λ m hm, _), exact I n m hm mem_closed_ball_self }, split, show ∀n, y ∈ f n, { assume n, have : closed_ball (c (n+1)) (r (n+1)) ⊆ f n := subset.trans (incl n) (inter_subset_right _ _), exact this (yball (n+1)) }, show edist y x ≤ ε, from le_trans (yball 0) (min_le_left _ _), end /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/ theorem dense_sInter_of_open {S : set (set α)} (ho : ∀s∈S, is_open s) (hS : countable S) (hd : ∀s∈S, dense s) : dense (⋂₀S) := begin cases S.eq_empty_or_nonempty with h h, { simp [h] }, { rcases hS.exists_surjective h with ⟨f, hf⟩, have F : ∀n, f n ∈ S := λn, by rw hf; exact mem_range_self _, rw [hf, sInter_range], exact dense_Inter_of_open_nat (λn, ho _ (F n)) (λn, hd _ (F n)) } end /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_bInter_of_open {S : set β} {f : β → set α} (ho : ∀s∈S, is_open (f s)) (hS : countable S) (hd : ∀s∈S, dense (f s)) : dense (⋂s∈S, f s) := begin rw ← sInter_image, apply dense_sInter_of_open, { rwa ball_image_iff }, { exact hS.image _ }, { rwa ball_image_iff } end /-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with an index set which is an encodable type. -/ theorem dense_Inter_of_open [encodable β] {f : β → set α} (ho : ∀s, is_open (f s)) (hd : ∀s, dense (f s)) : dense (⋂s, f s) := begin rw ← sInter_range, apply dense_sInter_of_open, { rwa forall_range_iff }, { exact countable_range _ }, { rwa forall_range_iff } end /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with ⋂₀. -/ theorem dense_sInter_of_Gδ {S : set (set α)} (ho : ∀s∈S, is_Gδ s) (hS : countable S) (hd : ∀s∈S, dense s) : dense (⋂₀S) := begin -- the result follows from the result for a countable intersection of dense open sets, -- by rewriting each set as a countable intersection of open sets, which are of course dense. choose T hT using ho, have : ⋂₀ S = ⋂₀ (⋃s∈S, T s ‹_›) := (sInter_bUnion (λs hs, (hT s hs).2.2)).symm, rw this, refine dense_sInter_of_open _ (hS.bUnion (λs hs, (hT s hs).2.1)) _; simp only [set.mem_Union, exists_prop]; rintro t ⟨s, hs, tTs⟩, show is_open t, { exact (hT s hs).1 t tTs }, show dense t, { intro x, have := hd s hs x, rw (hT s hs).2.2 at this, exact closure_mono (sInter_subset_of_mem tTs) this } end /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with an index set which is an encodable type. -/ theorem dense_Inter_of_Gδ [encodable β] {f : β → set α} (ho : ∀s, is_Gδ (f s)) (hd : ∀s, dense (f s)) : dense (⋂s, f s) := begin rw ← sInter_range, exact dense_sInter_of_Gδ (forall_range_iff.2 ‹_›) (countable_range _) (forall_range_iff.2 ‹_›) end /-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_bInter_of_Gδ {S : set β} {f : Π x ∈ S, set α} (ho : ∀s∈S, is_Gδ (f s ‹_›)) (hS : countable S) (hd : ∀s∈S, dense (f s ‹_›)) : dense (⋂s∈S, f s ‹_›) := begin rw bInter_eq_Inter, haveI := hS.to_encodable, exact dense_Inter_of_Gδ (λ s, ho s s.2) (λ s, hd s s.2) end /-- Baire theorem: the intersection of two dense Gδ sets is dense. -/ theorem dense.inter_of_Gδ {s t : set α} (hs : is_Gδ s) (ht : is_Gδ t) (hsc : dense s) (htc : dense t) : dense (s ∩ t) := begin rw [inter_eq_Inter], apply dense_Inter_of_Gδ; simp [bool.forall_bool, *] end /-- A property holds on a residual (comeagre) set if and only if it holds on some dense `Gδ` set. -/ lemma eventually_residual {p : α → Prop} : (∀ᶠ x in residual α, p x) ↔ ∃ (t : set α), is_Gδ t ∧ dense t ∧ ∀ x ∈ t, p x := calc (∀ᶠ x in residual α, p x) ↔ ∀ᶠ x in ⨅ (t : set α) (ht : is_Gδ t ∧ dense t), 𝓟 t, p x : by simp only [residual, infi_and] ... ↔ ∃ (t : set α) (ht : is_Gδ t ∧ dense t), ∀ᶠ x in 𝓟 t, p x : mem_binfi (λ t₁ h₁ t₂ h₂, ⟨t₁ ∩ t₂, ⟨h₁.1.inter h₂.1, dense.inter_of_Gδ h₁.1 h₂.1 h₁.2 h₂.2⟩, by simp⟩) ⟨univ, is_Gδ_univ, dense_univ⟩ ... ↔ _ : by simp [and_assoc] /-- A set is residual (comeagre) if and only if it includes a dense `Gδ` set. -/ lemma mem_residual {s : set α} : s ∈ residual α ↔ ∃ t ⊆ s, is_Gδ t ∧ dense t := (@eventually_residual α _ _ (λ x, x ∈ s)).trans $ exists_congr $ λ t, by rw [exists_prop, and_comm (t ⊆ s), subset_def, and_assoc] instance : countable_Inter_filter (residual α) := ⟨begin intros S hSc hS, simp only [mem_residual] at *, choose T hTs hT using hS, refine ⟨⋂ s ∈ S, T s ‹_›, _, _, _⟩, { rw [sInter_eq_bInter], exact Inter_subset_Inter (λ s, Inter_subset_Inter $ hTs s) }, { exact is_Gδ_bInter hSc (λ s hs, (hT s hs).1) }, { exact dense_bInter_of_Gδ (λ s hs, (hT s hs).1) hSc (λ s hs, (hT s hs).2) } end⟩ /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with an index set which is a countable set in any type. -/ theorem dense_bUnion_interior_of_closed {S : set β} {f : β → set α} (hc : ∀s∈S, is_closed (f s)) (hS : countable S) (hU : (⋃s∈S, f s) = univ) : dense (⋃s∈S, interior (f s)) := begin let g := λs, (frontier (f s))ᶜ, have : dense (⋂s∈S, g s), { refine dense_bInter_of_open (λs hs, _) hS (λs hs, _), show is_open (g s), from is_open_compl_iff.2 is_closed_frontier, show dense (g s), { intro x, simp [interior_frontier (hc s hs)] }}, refine this.mono _, show (⋂s∈S, g s) ⊆ (⋃s∈S, interior (f s)), assume x hx, have : x ∈ ⋃s∈S, f s, { have := mem_univ x, rwa ← hU at this }, rcases mem_bUnion_iff.1 this with ⟨s, hs, xs⟩, have : x ∈ g s := mem_bInter_iff.1 hx s hs, have : x ∈ interior (f s), { have : x ∈ f s \ (frontier (f s)) := mem_inter xs this, simpa [frontier, xs, (hc s hs).closure_eq] using this }, exact mem_bUnion_iff.2 ⟨s, ⟨hs, this⟩⟩ end /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with `⋃₀`. -/ theorem dense_sUnion_interior_of_closed {S : set (set α)} (hc : ∀s∈S, is_closed s) (hS : countable S) (hU : (⋃₀ S) = univ) : dense (⋃s∈S, interior s) := by rw sUnion_eq_bUnion at hU; exact dense_bUnion_interior_of_closed hc hS hU /-- Baire theorem: if countably many closed sets cover the whole space, then their interiors are dense. Formulated here with an index set which is an encodable type. -/ theorem dense_Union_interior_of_closed [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) : dense (⋃s, interior (f s)) := begin rw ← bUnion_univ, apply dense_bUnion_interior_of_closed, { simp [hc] }, { apply countable_encodable }, { rwa ← bUnion_univ at hU } end /-- One of the most useful consequences of Baire theorem: if a countable union of closed sets covers the space, then one of the sets has nonempty interior. -/ theorem nonempty_interior_of_Union_of_closed [nonempty α] [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) : ∃s, (interior $ f s).nonempty := begin by_contradiction h, simp only [not_exists, not_nonempty_iff_eq_empty] at h, have := calc ∅ = closure (⋃s, interior (f s)) : by simp [h] ... = univ : (dense_Union_interior_of_closed hc hU).closure_eq, exact univ_nonempty.ne_empty this.symm end end Baire_theorem
// // Copyright 2005-2007 Adobe Systems Incorporated // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt // #ifndef BOOST_GIL_CONCEPTS_CONCEPTS_CHECK_HPP #define BOOST_GIL_CONCEPTS_CONCEPTS_CHECK_HPP #include <boost/config.hpp> #if defined(BOOST_CLANG) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wfloat-equal" #pragma clang diagnostic ignored "-Wuninitialized" #endif #if defined(BOOST_GCC) && (BOOST_GCC >= 40600) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" #pragma GCC diagnostic ignored "-Wuninitialized" #endif #include <boost/concept_check.hpp> #if defined(BOOST_CLANG) #pragma clang diagnostic pop #endif #if defined(BOOST_GCC) && (BOOST_GCC >= 40600) #pragma GCC diagnostic pop #endif // TODO: Document BOOST_GIL_USE_CONCEPT_CHECK here namespace boost { namespace gil { // TODO: What is GIL_CLASS_REQUIRE for; Why not use BOOST_CLASS_REQUIRE? // TODO: What is gil_function_requires for; Why not function_requires? #ifdef BOOST_GIL_USE_CONCEPT_CHECK #define GIL_CLASS_REQUIRE(type_var, ns, concept) \ BOOST_CLASS_REQUIRE(type_var, ns, concept); template <typename Concept> void gil_function_requires() { function_requires<Concept>(); } #else #define GIL_CLASS_REQUIRE(type_var, ns, concept) template <typename C> void gil_function_requires() {} #endif }} // namespace boost::gil: #endif
data Nat : Set where zero : Nat suc : Nat → Nat pattern plus-two n = suc (suc n) f : Nat → Nat f (plus-two n) = f n f (suc zero) = plus-two zero f zero = zero
Formal statement is: lemma homeomorphism_moving_points_exists_gen: assumes K: "finite K" "\<And>i. i \<in> K \<Longrightarrow> x i \<in> S \<and> y i \<in> S" "pairwise (\<lambda>i j. (x i \<noteq> x j) \<and> (y i \<noteq> y j)) K" and "2 \<le> aff_dim S" and ope: "openin (top_of_set (affine hull S)) S" and "S \<subseteq> T" "T \<subseteq> affine hull S" "connected S" shows "\<exists>f g. homeomorphism T T f g \<and> (\<forall>i \<in> K. f(x i) = y i) \<and> {x. \<not> (f x = x \<and> g x = x)} \<subseteq> S \<and> bounded {x. \<not> (f x = x \<and> g x = x)}" Informal statement is: Suppose $S$ is a connected subset of an affine space of dimension at least 2, and $K$ is a finite set of points in $S$. Then there exists a homeomorphism $f$ of $S$ such that $f$ fixes every point of $S$ except for the points in $K$, and the set of points that are moved by $f$ is bounded.
{-| This module defines the 'Consume' typeclass, used for incrementally destructing inputs to random non-strict functions. Calling 'consume' on some value lazily returns an abstract type of 'Input', which contains all the entropy present in the original value. Paired with 'Test.StrictCheck.Produce', these @Input@ values can be used to generate random non-strict functions, whose strictness behavior is dependent on the values given to them. -} module Test.StrictCheck.Consume ( -- * Incrementally consuming input Input , Inputs , Consume(..) -- * Manually writing 'Consume' instances , constructor , normalize , consumeTrivial , consumePrimitive -- * Generically deriving 'Consume' instances , GConsume , gConsume ) where import Test.QuickCheck import Generics.SOP import Generics.SOP.NS import Test.StrictCheck.Internal.Inputs import Data.Complex import Data.Foldable as Fold import Data.List.NonEmpty (NonEmpty(..)) import Data.Tree as Tree import Data.Set as Set import Data.Map as Map import Data.Sequence as Seq import Data.IntMap as IntMap import Data.IntSet as IntSet -- | Lazily monomorphize some input value, by converting it into an @Input@. -- This is an incremental version of QuickCheck's @CoArbitrary@ typeclass. -- It can also be seen as a generalization of the @NFData@ class. -- -- Instances of @Consume@ can be derived automatically for any type implementing -- the @Generic@ class from "GHC.Generics". Using the @DeriveAnyClass@ -- extension, we can say: -- -- > import GHC.Generics as GHC -- > import Generics.SOP as SOP -- > -- > data D x y -- > = A -- > | B (x, y) -- > deriving (GHC.Generic, SOP.Generic, Consume) -- -- This automatic derivation follows these rules, which you can follow too if -- you're manually writing an instance for some type which is not @Generic@: -- -- For each distinct constructor, make a single call to 'constructor' with -- a distinct @Int@, and a list of @Input@s, each created by recursively calling -- 'consume' on every field in that constructor. For abstract types (e.g. sets), -- the same procedure can be used upon an extracted list representation of the -- contents. class Consume a where -- | Convert an @a@ into an @Input@ by recursively destructing it using calls -- to @consume@ consume :: a -> Input default consume :: GConsume a => a -> Input consume = gConsume -- | Reassemble pieces of input into a larger Input: this is to be called on the -- result of @consume@-ing subparts of input constructor :: Int -> [Input] -> Input constructor n !is = Input (Variant (variant n)) is -- | Use the CoArbitrary instance for a type to consume it -- -- This should only be used for "flat" types, i.e. those which contain no -- interesting consumable substructure, as it's fully strict (non-incremental) consumePrimitive :: CoArbitrary a => a -> Input consumePrimitive !a = Input (Variant (coarbitrary a)) [] -- | Consume a type which has no observable structure whatsoever -- -- This should only be used for types for which there is only one inhabitant, or -- for which inhabitants cannot be distinguished at all. consumeTrivial :: a -> Input consumeTrivial !_ = Input mempty [] -- | Fully normalize something which can be consumed normalize :: Consume a => a -> () normalize (consume -> input) = go input where go (Input _ is) = Fold.foldr seq () (fmap go is) -------------------------------------------- -- Deriving Consume instances generically -- -------------------------------------------- -- | The constraints necessary to generically @consume@ something type GConsume a = (Generic a, All2 Consume (Code a)) -- | Generic 'consume' gConsume :: GConsume a => a -> Input gConsume !(from -> sop) = constructor (index_SOP sop) . hcollapse . hcliftA (Proxy @Consume) (K . consume . unI) $ sop --------------- -- Instances -- --------------- instance Consume (a -> b) where consume = consumeTrivial instance Consume (Proxy p) where consume = consumeTrivial instance Consume Char where consume = consumePrimitive instance Consume Word where consume = consumePrimitive instance Consume Int where consume = consumePrimitive instance Consume Double where consume = consumePrimitive instance Consume Float where consume = consumePrimitive instance Consume Rational where consume = consumePrimitive instance Consume Integer where consume = consumePrimitive instance (CoArbitrary a, RealFloat a) => Consume (Complex a) where consume = consumePrimitive instance Consume () instance Consume Bool instance Consume Ordering instance Consume a => Consume (Maybe a) instance (Consume a, Consume b) => Consume (Either a b) instance Consume a => Consume [a] instance Consume a => Consume (NonEmpty a) where consume (a :| as) = constructor 0 [consume a, consume as] instance Consume a => Consume (Tree a) where consume (Node a as) = constructor 0 [consume a, consume as] instance Consume v => Consume (Map k v) where consume = constructor 0 . fmap (consume . snd) . Map.toList consumeContainer :: (Consume a, Foldable t) => t a -> Input consumeContainer = constructor 0 . fmap consume . Fold.toList instance Consume v => Consume (Seq v) where consume = consumeContainer instance Consume v => Consume (Set v) where consume = consumeContainer instance Consume v => Consume (IntMap v) where consume = consumeContainer instance Consume IntSet where consume = consumeContainer . IntSet.toList -- TODO: instances for the rest of Containers instance (Consume a, Consume b) => Consume (a, b) instance (Consume a, Consume b, Consume c) => Consume (a, b, c) instance (Consume a, Consume b, Consume c, Consume d) => Consume (a, b, c, d) instance ( Consume a, Consume b, Consume c, Consume d, Consume e ) => Consume (a, b, c, d, e) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f ) => Consume (a, b, c, d, e, f) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g ) => Consume (a, b, c, d, e, f, g) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h ) => Consume (a, b, c, d, e, f, g, h) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i ) => Consume (a, b, c, d, e, f, g, h, i) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j ) => Consume (a, b, c, d, e, f, g, h, i, j) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k ) => Consume (a, b, c, d, e, f, g, h, i, j, k) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t, Consume u ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t, Consume u, Consume v ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t, Consume u, Consume v, Consume w ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t, Consume u, Consume v, Consume w, Consume x ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t, Consume u, Consume v, Consume w, Consume x , Consume y ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y) instance ( Consume a, Consume b, Consume c, Consume d, Consume e, Consume f , Consume g, Consume h, Consume i, Consume j, Consume k, Consume l , Consume m, Consume n, Consume o, Consume p, Consume q, Consume r , Consume s, Consume t, Consume u, Consume v, Consume w, Consume x , Consume y, Consume z ) => Consume (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
[STATEMENT] theorem TBtheorem4b_P: assumes "ineM P M E" and "subcomponents PQ = {P,Q}" and "correctCompositionIn PQ" and "\<exists> ch. ((ch \<in> (ins Q)) \<and> (exprChannel ch E) \<and> (ch \<notin> (loc PQ)) \<and> (ch \<in> M))" shows "ineM PQ M E" [PROOF STATE] proof (prove) goal (1 subgoal): 1. ineM PQ M E [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: ineM P M E subcomponents PQ = {P, Q} correctCompositionIn PQ \<exists>ch. ch \<in> ins Q \<and> exprChannel ch E \<and> ch \<notin> loc PQ \<and> ch \<in> M goal (1 subgoal): 1. ineM PQ M E [PROOF STEP] by (simp add: ineM_def correctCompositionIn_def, auto)
Fox bets Women’s World Cup will bring attention! | www.worldcupdebate.com - The Internet's #1 FIFA World Cup resources website! Remember the frenzy over the U.S. Men’s National Soccer Team during the 2014 FIFA World Cup? The crowds in the streets? The viewing parties in apartments and bars? The social media explosion? Fox Sports is betting World Cup fever will return as the U.S. Women’s National Soccer Team takes the pitch for the FIFA Women’s World Cup Canada 2015 on June 6. The network planned to use its telecast of the Daytona 500 today to launch a $10 million, 100-day promotional push for its first World Cup coverage. The emotional ad begins with the 2-1 loss to Belgium that eliminated the men’s team last July. Images include fallen goalkeeper Tim Howard, crushed fans, crowds dispersing. The underdog U.S. men’s team’s surprise run created a “cultural whirlwind” last summer, noted Robert Gottlieb, Fox Sports’ evp of marketing. Fox’s creative strategy is to show the torch being passed from one U.S. team to the other, he said. Now, Fox’s “Nothing Is Over” rallying cry may sound like Rambo in First Blood, but Gottlieb and Fox “believe very strongly” the country will rally around the women’s team this summer. Some critics will see the “America has a score to settle” line as jingoistic. But Gottlieb says it works on several fronts. For one, the U.S. women’s team hasn’t won the World Cup since 1999, when Mia Hamm and Brandi Chastain became household names. Despite ranking as the national team’s all-time leading scorer, Wambach has never won a World Cup. Other stars are burning to avenge their loss to Japan in the 2011 FIFA World Cup. The “It’s Not Over” spot will kick off what Fox says will be the biggest network marketing push for a Women’s World Cup. There will be more TV ads focusing on individual players such as Morgan and Wambach, according to Gottlieb. Fox is planning a 30-channel media roadblock around a 30-second version of “It’s Not Over” that will air Tuesday at 8 p.m. As soccer gains popularity within the U.S., Simon Wardle, chief strategy officer of Octagon Worldwide, believes World Cup fever will reignite when the U.S. women’s team starts play this summer. “It’s one of the few occasions where Team USA can take on the world,” he said.
State Before: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b State After: case pos a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] h2 : ¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b case neg a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] h2 : ¬¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b Tactic: by_cases h2 : (0 : ℝ) ∉ [[a, b]] State Before: case neg a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] h2 : ¬¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b State After: case neg a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b Tactic: rw [eq_false h2, or_false_iff] at h State Before: case neg a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b State After: case neg.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 < r.re ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b case neg.inr a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b Tactic: rcases lt_or_eq_of_le h with (h' | h') State Before: case neg.inr a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b State After: case neg.inr.refine'_1 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ AEStronglyMeasurable (fun x => ↑x ^ r) (Measure.restrict μ (Ι a b)) case neg.inr.refine'_2 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ IntervalIntegrable (fun t => ‖↑t ^ r‖) μ a b Tactic: refine' (IntervalIntegrable.intervalIntegrable_norm_iff _).mp _ State Before: case neg.inr.refine'_2 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ IntervalIntegrable (fun t => ‖↑t ^ r‖) μ a b State After: case neg.inr.refine'_2 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re this : ∀ (c : ℝ), IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c ⊢ IntervalIntegrable (fun t => ‖↑t ^ r‖) μ a b case this a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ ∀ (c : ℝ), IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c Tactic: suffices : ∀ c : ℝ, IntervalIntegrable (fun x : ℝ => ‖(x:ℂ) ^ r‖) μ 0 c State Before: case neg.inr.refine'_2 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re this : ∀ (c : ℝ), IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c ⊢ IntervalIntegrable (fun t => ‖↑t ^ r‖) μ a b case this a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ ∀ (c : ℝ), IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c State After: case this a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ ∀ (c : ℝ), IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c Tactic: exact (this a).symm.trans (this b) State Before: case this a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ ∀ (c : ℝ), IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c State After: case this a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c Tactic: intro c State Before: case this a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c State After: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c case this.inr a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c Tactic: rcases le_or_lt 0 c with (hc | hc) State Before: case pos a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] h2 : ¬0 ∈ [[a, b]] ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b State After: case pos a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] h2 : ¬0 ∈ [[a, b]] x : ℝ hx : x ∈ [[a, b]] ⊢ ContinuousAt (fun x => ↑x ^ r) x Tactic: refine' (ContinuousAt.continuousOn fun x hx => _).intervalIntegrable State Before: case pos a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re ∨ ¬0 ∈ [[a, b]] h2 : ¬0 ∈ [[a, b]] x : ℝ hx : x ∈ [[a, b]] ⊢ ContinuousAt (fun x => ↑x ^ r) x State After: no goals Tactic: exact Complex.continuousAt_ofReal_cpow_const _ _ (Or.inr <| ne_of_mem_of_not_mem hx h2) State Before: case neg.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 < r.re ⊢ IntervalIntegrable (fun x => ↑x ^ r) μ a b State After: no goals Tactic: exact (Complex.continuous_ofReal_cpow_const h').intervalIntegrable _ _ State Before: case neg.inr.refine'_1 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ AEStronglyMeasurable (fun x => ↑x ^ r) (Measure.restrict μ (Ι a b)) State After: case neg.inr.refine'_1 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ ContinuousOn (fun x => ↑x ^ r) ({0}ᶜ) Tactic: refine' (measurable_of_continuousOn_compl_singleton (0 : ℝ) _).aestronglyMeasurable State Before: case neg.inr.refine'_1 a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re ⊢ ContinuousOn (fun x => ↑x ^ r) ({0}ᶜ) State After: no goals Tactic: exact ContinuousAt.continuousOn fun x hx => Complex.continuousAt_ofReal_cpow_const x r (Or.inr hx) State Before: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c State After: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntervalIntegrable (fun x => 1) μ 0 c ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c Tactic: have : IntervalIntegrable (fun _ => 1 : ℝ → ℝ) μ 0 c := intervalIntegrable_const State Before: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntervalIntegrable (fun x => 1) μ 0 c ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c State After: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntegrableOn (fun x => 1) (Set.Ioc 0 c) ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioc 0 c) Tactic: rw [intervalIntegrable_iff_integrable_Ioc_of_le hc] at this ⊢ State Before: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntegrableOn (fun x => 1) (Set.Ioc 0 c) ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioc 0 c) State After: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntegrableOn (fun x => 1) (Set.Ioc 0 c) x : ℝ hx : x ∈ Set.Ioc 0 c ⊢ 1 = ‖↑x ^ r‖ Tactic: refine' IntegrableOn.congr_fun this (fun x hx => _) measurableSet_Ioc State Before: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntegrableOn (fun x => 1) (Set.Ioc 0 c) x : ℝ hx : x ∈ Set.Ioc 0 c ⊢ 1 = ‖↑x ^ r‖ State After: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntegrableOn (fun x => 1) (Set.Ioc 0 c) x : ℝ hx : x ∈ Set.Ioc 0 c ⊢ 1 = ‖↑x ^ r‖ Tactic: dsimp only State Before: case this.inl a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : 0 ≤ c this : IntegrableOn (fun x => 1) (Set.Ioc 0 c) x : ℝ hx : x ∈ Set.Ioc 0 c ⊢ 1 = ‖↑x ^ r‖ State After: no goals Tactic: rw [Complex.norm_eq_abs, Complex.abs_cpow_eq_rpow_re_of_pos hx.1, ← h', rpow_zero] State Before: case this.inr a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ 0 c State After: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ c 0 Tactic: apply IntervalIntegrable.symm State Before: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ IntervalIntegrable (fun x => ‖↑x ^ r‖) μ c 0 State After: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioc c 0) Tactic: rw [intervalIntegrable_iff_integrable_Ioc_of_le hc.le] State Before: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioc c 0) State After: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioc c 0) Tactic: have : Ioc c 0 = Ioo c 0 ∪ {(0 : ℝ)} := by rw [← Ioo_union_Icc_eq_Ioc hc (le_refl 0), ← Icc_def] simp_rw [← le_antisymm_iff, setOf_eq_eq_singleton'] State Before: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioc c 0) State After: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) {0} ∧ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioo c 0) Tactic: rw [this, integrableOn_union, and_comm] State Before: case this.inr.h a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) {0} ∧ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioo c 0) State After: case this.inr.h.left a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) {0} case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioo c 0) Tactic: constructor State Before: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} State After: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ Set.Ioo c 0 ∪ {x | 0 ≤ x ∧ x ≤ 0} = Set.Ioo c 0 ∪ {0} Tactic: rw [← Ioo_union_Icc_eq_Ioc hc (le_refl 0), ← Icc_def] State Before: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 ⊢ Set.Ioo c 0 ∪ {x | 0 ≤ x ∧ x ≤ 0} = Set.Ioo c 0 ∪ {0} State After: no goals Tactic: simp_rw [← le_antisymm_iff, setOf_eq_eq_singleton'] State Before: case this.inr.h.left a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) {0} State After: case this.inr.h.left a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ ↑↑μ {0} < ⊤ Tactic: refine' integrableOn_singleton_iff.mpr (Or.inr _) State Before: case this.inr.h.left a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ ↑↑μ {0} < ⊤ State After: no goals Tactic: exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_singleton State Before: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioo c 0) State After: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioo c 0) Tactic: have : ∀ x : ℝ, x ∈ Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖(x : ℂ) ^ r‖ := by intro x hx rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_eq_abs (_ ^ _), Complex.abs_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul] State Before: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ IntegrableOn (fun x => ‖↑x ^ r‖) (Set.Ioo c 0) State After: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ IntegrableOn (fun x => ‖Complex.exp (↑π * Complex.I * r)‖) (Set.Ioo c 0) Tactic: refine' IntegrableOn.congr_fun _ this measurableSet_Ioo State Before: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ IntegrableOn (fun x => ‖Complex.exp (↑π * Complex.I * r)‖) (Set.Ioo c 0) State After: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ ‖Complex.exp (↑π * Complex.I * r)‖ = 0 ∨ ↑↑μ (Set.Ioo c 0) < ⊤ Tactic: rw [integrableOn_const] State Before: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ ‖Complex.exp (↑π * Complex.I * r)‖ = 0 ∨ ↑↑μ (Set.Ioo c 0) < ⊤ State After: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ ↑↑μ (Set.Icc c 0) < ⊤ Tactic: refine' Or.inr ((measure_mono Set.Ioo_subset_Icc_self).trans_lt _) State Before: case this.inr.h.right a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this✝ : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} this : ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ ⊢ ↑↑μ (Set.Icc c 0) < ⊤ State After: no goals Tactic: exact isFiniteMeasureOnCompacts_of_isLocallyFiniteMeasure.lt_top_of_isCompact isCompact_Icc State Before: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} ⊢ ∀ (x : ℝ), x ∈ Set.Ioo c 0 → ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ State After: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} x : ℝ hx : x ∈ Set.Ioo c 0 ⊢ ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ Tactic: intro x hx State Before: a b : ℝ n : ℕ f : ℝ → ℝ μ ν : MeasureTheory.Measure ℝ inst✝ : IsLocallyFiniteMeasure μ c✝ d : ℝ r : ℂ h : 0 ≤ r.re h2 : ¬¬0 ∈ [[a, b]] h' : 0 = r.re c : ℝ hc : c < 0 this : Set.Ioc c 0 = Set.Ioo c 0 ∪ {0} x : ℝ hx : x ∈ Set.Ioo c 0 ⊢ ‖Complex.exp (↑π * Complex.I * r)‖ = ‖↑x ^ r‖ State After: no goals Tactic: rw [Complex.ofReal_cpow_of_nonpos hx.2.le, norm_mul, ← Complex.ofReal_neg, Complex.norm_eq_abs (_ ^ _), Complex.abs_cpow_eq_rpow_re_of_pos (neg_pos.mpr hx.2), ← h', rpow_zero, one_mul]
[GOAL] p q : Primes h : ↑p = ↑q ⊢ ↑p = ↑q [PROOFSTEP] injection h [GOAL] n m : ℕ+ ⊢ 0 < Nat.lcm ↑n ↑m [PROOFSTEP] let h := mul_pos n.pos m.pos [GOAL] n m : ℕ+ h : 0 < ↑n * ↑m := mul_pos (pos n) (pos m) ⊢ 0 < Nat.lcm ↑n ↑m [PROOFSTEP] rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h [GOAL] n m : ℕ+ h : 0 < Nat.lcm ↑n ↑m * Nat.gcd ↑n ↑m ⊢ 0 < Nat.lcm ↑n ↑m [PROOFSTEP] exact pos_of_dvd_of_pos (Dvd.intro (Nat.gcd (n : ℕ) (m : ℕ)) rfl) h [GOAL] n : ℕ+ ⊢ n < 2 → n = 1 [PROOFSTEP] intro h [GOAL] n : ℕ+ h : n < 2 ⊢ n = 1 [PROOFSTEP] apply le_antisymm [GOAL] case a n : ℕ+ h : n < 2 ⊢ n ≤ 1 case a n : ℕ+ h : n < 2 ⊢ 1 ≤ n [PROOFSTEP] swap [GOAL] case a n : ℕ+ h : n < 2 ⊢ 1 ≤ n case a n : ℕ+ h : n < 2 ⊢ n ≤ 1 [PROOFSTEP] apply PNat.one_le [GOAL] case a n : ℕ+ h : n < 2 ⊢ n ≤ 1 [PROOFSTEP] exact PNat.lt_add_one_iff.1 h [GOAL] p m : ℕ+ pp : Prime p ⊢ m ∣ p ↔ m = 1 ∨ m = p [PROOFSTEP] rw [PNat.dvd_iff] [GOAL] p m : ℕ+ pp : Prime p ⊢ ↑m ∣ ↑p ↔ m = 1 ∨ m = p [PROOFSTEP] rw [Nat.dvd_prime pp] [GOAL] p m : ℕ+ pp : Prime p ⊢ ↑m = 1 ∨ ↑m = ↑p ↔ m = 1 ∨ m = p [PROOFSTEP] simp [GOAL] p : ℕ+ ⊢ Prime p → p ≠ 1 [PROOFSTEP] intro pp [GOAL] p : ℕ+ pp : Prime p ⊢ p ≠ 1 [PROOFSTEP] intro contra [GOAL] p : ℕ+ pp : Prime p contra : p = 1 ⊢ False [PROOFSTEP] apply Nat.Prime.ne_one pp [GOAL] p : ℕ+ pp : Prime p contra : p = 1 ⊢ ↑p = 1 [PROOFSTEP] rw [PNat.coe_eq_one_iff] [GOAL] p : ℕ+ pp : Prime p contra : p = 1 ⊢ p = 1 [PROOFSTEP] apply contra [GOAL] p : ℕ+ pp : Prime p ⊢ ¬p ∣ 1 [PROOFSTEP] rw [dvd_iff] [GOAL] p : ℕ+ pp : Prime p ⊢ ¬↑p ∣ ↑1 [PROOFSTEP] apply Nat.Prime.not_dvd_one pp [GOAL] n : ℕ+ hn : n ≠ 1 ⊢ ∃ p, Prime p ∧ p ∣ n [PROOFSTEP] obtain ⟨p, hp⟩ := Nat.exists_prime_and_dvd (mt coe_eq_one_iff.mp hn) [GOAL] case intro n : ℕ+ hn : n ≠ 1 p : ℕ hp : Nat.Prime p ∧ p ∣ ↑n ⊢ ∃ p, Prime p ∧ p ∣ n [PROOFSTEP] exists (⟨p, Nat.Prime.pos hp.left⟩ : ℕ+) [GOAL] case intro n : ℕ+ hn : n ≠ 1 p : ℕ hp : Nat.Prime p ∧ p ∣ ↑n ⊢ Prime { val := p, property := (_ : 0 < p) } ∧ { val := p, property := (_ : 0 < p) } ∣ n [PROOFSTEP] rw [dvd_iff] [GOAL] case intro n : ℕ+ hn : n ≠ 1 p : ℕ hp : Nat.Prime p ∧ p ∣ ↑n ⊢ Prime { val := p, property := (_ : 0 < p) } ∧ ↑{ val := p, property := (_ : 0 < p) } ∣ ↑n [PROOFSTEP] apply hp [GOAL] m n : ℕ+ ⊢ coprime ↑m ↑n ↔ Coprime m n [PROOFSTEP] unfold coprime Coprime [GOAL] m n : ℕ+ ⊢ Nat.gcd ↑m ↑n = 1 ↔ gcd m n = 1 [PROOFSTEP] rw [← coe_inj] [GOAL] m n : ℕ+ ⊢ Nat.gcd ↑m ↑n = 1 ↔ ↑(gcd m n) = ↑1 [PROOFSTEP] simp [GOAL] k m n : ℕ+ ⊢ Coprime m k → Coprime n k → Coprime (m * n) k [PROOFSTEP] repeat' rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ Coprime m k → Coprime n k → Coprime (m * n) k [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑m ↑k → Coprime n k → Coprime (m * n) k [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑m ↑k → coprime ↑n ↑k → Coprime (m * n) k [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑m ↑k → coprime ↑n ↑k → coprime ↑(m * n) ↑k [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑m ↑k → coprime ↑n ↑k → coprime ↑(m * n) ↑k [PROOFSTEP] rw [mul_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑m ↑k → coprime ↑n ↑k → coprime (↑m * ↑n) ↑k [PROOFSTEP] apply Nat.coprime.mul [GOAL] k m n : ℕ+ ⊢ Coprime k m → Coprime k n → Coprime k (m * n) [PROOFSTEP] repeat' rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ Coprime k m → Coprime k n → Coprime k (m * n) [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑k ↑m → Coprime k n → Coprime k (m * n) [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑k ↑m → coprime ↑k ↑n → Coprime k (m * n) [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑k ↑m → coprime ↑k ↑n → coprime ↑k ↑(m * n) [PROOFSTEP] rw [← coprime_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑k ↑m → coprime ↑k ↑n → coprime ↑k ↑(m * n) [PROOFSTEP] rw [mul_coe] [GOAL] k m n : ℕ+ ⊢ coprime ↑k ↑m → coprime ↑k ↑n → coprime (↑k) (↑m * ↑n) [PROOFSTEP] apply Nat.coprime.mul_right [GOAL] m n : ℕ+ ⊢ gcd m n = gcd n m [PROOFSTEP] apply eq [GOAL] case a m n : ℕ+ ⊢ ↑(gcd m n) = ↑(gcd n m) [PROOFSTEP] simp only [gcd_coe] [GOAL] case a m n : ℕ+ ⊢ Nat.gcd ↑m ↑n = Nat.gcd ↑n ↑m [PROOFSTEP] apply Nat.gcd_comm [GOAL] m n : ℕ+ ⊢ m ∣ n ↔ gcd m n = m [PROOFSTEP] rw [dvd_iff] [GOAL] m n : ℕ+ ⊢ ↑m ∣ ↑n ↔ gcd m n = m [PROOFSTEP] rw [Nat.gcd_eq_left_iff_dvd] [GOAL] m n : ℕ+ ⊢ Nat.gcd ↑m ↑n = ↑m ↔ gcd m n = m [PROOFSTEP] rw [← coe_inj] [GOAL] m n : ℕ+ ⊢ Nat.gcd ↑m ↑n = ↑m ↔ ↑(gcd m n) = ↑m [PROOFSTEP] simp [GOAL] m n : ℕ+ ⊢ m ∣ n ↔ gcd n m = m [PROOFSTEP] rw [gcd_comm] [GOAL] m n : ℕ+ ⊢ m ∣ n ↔ gcd m n = m [PROOFSTEP] apply gcd_eq_left_iff_dvd [GOAL] m n k : ℕ+ ⊢ Coprime k n → gcd (k * m) n = gcd m n [PROOFSTEP] intro h [GOAL] m n k : ℕ+ h : Coprime k n ⊢ gcd (k * m) n = gcd m n [PROOFSTEP] apply eq [GOAL] case a m n k : ℕ+ h : Coprime k n ⊢ ↑(gcd (k * m) n) = ↑(gcd m n) [PROOFSTEP] simp only [gcd_coe, mul_coe] [GOAL] case a m n k : ℕ+ h : Coprime k n ⊢ Nat.gcd (↑k * ↑m) ↑n = Nat.gcd ↑m ↑n [PROOFSTEP] apply Nat.coprime.gcd_mul_left_cancel [GOAL] case a.H m n k : ℕ+ h : Coprime k n ⊢ coprime ↑k ↑n [PROOFSTEP] simpa [GOAL] m n k : ℕ+ ⊢ Coprime k n → gcd (m * k) n = gcd m n [PROOFSTEP] rw [mul_comm] [GOAL] m n k : ℕ+ ⊢ Coprime k n → gcd (k * m) n = gcd m n [PROOFSTEP] apply Coprime.gcd_mul_left_cancel [GOAL] m n k : ℕ+ ⊢ Coprime k m → gcd m (k * n) = gcd m n [PROOFSTEP] intro h [GOAL] m n k : ℕ+ h : Coprime k m ⊢ gcd m (k * n) = gcd m n [PROOFSTEP] iterate 2 rw [gcd_comm]; symm; [GOAL] m n k : ℕ+ h : Coprime k m ⊢ gcd m (k * n) = gcd m n [PROOFSTEP] rw [gcd_comm] [GOAL] m n k : ℕ+ h : Coprime k m ⊢ gcd (k * n) m = gcd m n [PROOFSTEP] symm [GOAL] m n k : ℕ+ h : Coprime k m ⊢ gcd m n = gcd (k * n) m [PROOFSTEP] rw [gcd_comm] [GOAL] m n k : ℕ+ h : Coprime k m ⊢ gcd n m = gcd (k * n) m [PROOFSTEP] symm [GOAL] m n k : ℕ+ h : Coprime k m ⊢ gcd (k * n) m = gcd n m [PROOFSTEP] apply Coprime.gcd_mul_left_cancel _ h [GOAL] m n k : ℕ+ ⊢ Coprime k m → gcd m (n * k) = gcd m n [PROOFSTEP] rw [mul_comm] [GOAL] m n k : ℕ+ ⊢ Coprime k m → gcd m (k * n) = gcd m n [PROOFSTEP] apply Coprime.gcd_mul_left_cancel_right [GOAL] n : ℕ+ ⊢ gcd 1 n = 1 [PROOFSTEP] rw [← gcd_eq_left_iff_dvd] [GOAL] n : ℕ+ ⊢ 1 ∣ n [PROOFSTEP] apply one_dvd [GOAL] n : ℕ+ ⊢ gcd n 1 = 1 [PROOFSTEP] rw [gcd_comm] [GOAL] n : ℕ+ ⊢ gcd 1 n = 1 [PROOFSTEP] apply one_gcd [GOAL] m n : ℕ+ ⊢ Coprime m n → Coprime n m [PROOFSTEP] unfold Coprime [GOAL] m n : ℕ+ ⊢ gcd m n = 1 → gcd n m = 1 [PROOFSTEP] rw [gcd_comm] [GOAL] m n : ℕ+ ⊢ gcd n m = 1 → gcd n m = 1 [PROOFSTEP] simp [GOAL] m k n : ℕ+ ⊢ m ∣ k → Coprime k n → Coprime m n [PROOFSTEP] rw [dvd_iff] [GOAL] m k n : ℕ+ ⊢ ↑m ∣ ↑k → Coprime k n → Coprime m n [PROOFSTEP] repeat' rw [← coprime_coe] [GOAL] m k n : ℕ+ ⊢ ↑m ∣ ↑k → Coprime k n → Coprime m n [PROOFSTEP] rw [← coprime_coe] [GOAL] m k n : ℕ+ ⊢ ↑m ∣ ↑k → coprime ↑k ↑n → Coprime m n [PROOFSTEP] rw [← coprime_coe] [GOAL] m k n : ℕ+ ⊢ ↑m ∣ ↑k → coprime ↑k ↑n → coprime ↑m ↑n [PROOFSTEP] rw [← coprime_coe] [GOAL] m k n : ℕ+ ⊢ ↑m ∣ ↑k → coprime ↑k ↑n → coprime ↑m ↑n [PROOFSTEP] apply Nat.coprime.coprime_dvd_left [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd (a * b) m [PROOFSTEP] rw [gcd_eq_left_iff_dvd] at am [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n ⊢ a = gcd (a * b) m [PROOFSTEP] conv_lhs => rw [← am] [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n | a [PROOFSTEP] rw [← am] [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n | a [PROOFSTEP] rw [← am] [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n | a [PROOFSTEP] rw [← am] [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n ⊢ gcd a m = gcd (a * b) m [PROOFSTEP] rw [eq_comm] [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n ⊢ gcd (a * b) m = gcd a m [PROOFSTEP] apply Coprime.gcd_mul_right_cancel a [GOAL] a b m n : ℕ+ cop : Coprime m n am : gcd a m = a bn : b ∣ n ⊢ Coprime b m [PROOFSTEP] apply Coprime.coprime_dvd_left bn cop.symm [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd (b * a) m [PROOFSTEP] rw [mul_comm] [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd (a * b) m [PROOFSTEP] apply Coprime.factor_eq_gcd_left cop am bn [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd m (a * b) [PROOFSTEP] rw [gcd_comm] [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd (a * b) m [PROOFSTEP] apply Coprime.factor_eq_gcd_left cop am bn [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd m (b * a) [PROOFSTEP] rw [gcd_comm] [GOAL] a b m n : ℕ+ cop : Coprime m n am : a ∣ m bn : b ∣ n ⊢ a = gcd (b * a) m [PROOFSTEP] apply Coprime.factor_eq_gcd_right cop am bn [GOAL] k m n : ℕ+ h : Coprime m n ⊢ gcd k (m * n) = gcd k m * gcd k n [PROOFSTEP] rw [← coprime_coe] at h [GOAL] k m n : ℕ+ h : coprime ↑m ↑n ⊢ gcd k (m * n) = gcd k m * gcd k n [PROOFSTEP] apply eq [GOAL] case a k m n : ℕ+ h : coprime ↑m ↑n ⊢ ↑(gcd k (m * n)) = ↑(gcd k m * gcd k n) [PROOFSTEP] simp only [gcd_coe, mul_coe] [GOAL] case a k m n : ℕ+ h : coprime ↑m ↑n ⊢ Nat.gcd (↑k) (↑m * ↑n) = Nat.gcd ↑k ↑m * Nat.gcd ↑k ↑n [PROOFSTEP] apply Nat.coprime.gcd_mul k h [GOAL] m n : ℕ+ ⊢ m ∣ n → gcd m n = m [PROOFSTEP] rw [dvd_iff] [GOAL] m n : ℕ+ ⊢ ↑m ∣ ↑n → gcd m n = m [PROOFSTEP] intro h [GOAL] m n : ℕ+ h : ↑m ∣ ↑n ⊢ gcd m n = m [PROOFSTEP] apply eq [GOAL] case a m n : ℕ+ h : ↑m ∣ ↑n ⊢ ↑(gcd m n) = ↑m [PROOFSTEP] simp only [gcd_coe] [GOAL] case a m n : ℕ+ h : ↑m ∣ ↑n ⊢ Nat.gcd ↑m ↑n = ↑m [PROOFSTEP] apply Nat.gcd_eq_left h [GOAL] m n : ℕ+ k l : ℕ h : Coprime m n ⊢ coprime (↑m ^ k) (↑n ^ l) [PROOFSTEP] rw [← coprime_coe] at * [GOAL] m n : ℕ+ k l : ℕ h : coprime ↑m ↑n ⊢ coprime (↑m ^ k) (↑n ^ l) [PROOFSTEP] apply Nat.coprime.pow [GOAL] case H1 m n : ℕ+ k l : ℕ h : coprime ↑m ↑n ⊢ coprime ↑m ↑n [PROOFSTEP] apply h
lemmas of_real_eq_0_iff [simp] = of_real_eq_iff [of _ 0, simplified]
lemma bdd_below_image_dist[intro, simp]: "bdd_below (dist x ` A)"
import LMT variable {I} [Nonempty I] {E} [Nonempty E] [Nonempty (A I E)] example {a1 a2 a3 : A I E} : ((a2).write i2 (v3)) ≠ (a2) → ((a1).write i2 (v3)) = (a2) → False := by arr
[STATEMENT] lemma cpx_mat_cnj_cnj [simp]: "(M\<^sup>\<star>)\<^sup>\<star> = M" [PROOF STATE] proof (prove) goal (1 subgoal): 1. M\<^sup>\<star>\<^sup>\<star> = M [PROOF STEP] by (auto simp: cpx_mat_cnj_def)
Formal statement is: lemma snd_quot_of_fract_to_fract [simp]: "snd (quot_of_fract (to_fract x)) = 1" Informal statement is: The denominator of the fractional representation of a rational number is 1.
Require Import Coq.Program.Basics. Require Import ExtLib.Structures.Monads. Require Import ExtLib.Data.Monads.OptionMonad. Require Import ASN1FP.Aux.Option. Import MonadNotation. Local Open Scope monad_scope. (* `b` is inverse of `f` wrt. heterogenous equality `e` *) Definition bool_het_inverse (A1 B A2 : Type) (f: A1 -> B) (b: B -> A2) (e: A1 -> A2 -> bool) (x: A1) : Prop := e x (b (f x)) = true. (* monadic version of `bool_het_inverse` *) Definition bool_het_inverse' (m: Type -> Type) `{Monad m} (A1 B A2 : Type) (f: A1 -> m B) (b: B -> m A2) (e: A1 -> A2 -> bool) (x: A1) : m bool:= y <- f x ;; x' <- b y ;; ret (e x x'). (* * "Round-trip" converting between types A1, B, A2: * A1 -> B -> A2 * * if * forward pass happens * then * backward pass happens * and * backward pass returns an element, * equivalent to the starting one *) Definition roundtrip_option (A1 B A2 : Type) (f: A1 -> option B) (* forward pass *) (b: B -> option A2) (* backward pass *) (e: A1 -> A2 -> bool) (* equivalence on A *) (x: A1) (* value *) : Prop := is_Some_b (f x) = true -> bool_het_inverse' option A1 B A2 f b e x = Some true. (* * if * b1 = f1^(-1) * and * b2 = f2^(-1) * then * b1 . b2 = (f2 . f1)^(-1) *) Lemma inv_trans {A1 A2 B C : Type} {f1 : A1 -> B} {b1 : B -> A2} {ea : A1 -> A2 -> bool} {f2 : B -> C} {b2 : C -> B} {eb : B -> B -> bool} {x : A1} : (forall (y z : B), eb y z = true -> b1 y = b1 z) -> bool_het_inverse A1 B A2 f1 b1 ea x -> bool_het_inverse B C B f2 b2 eb (f1 x) -> bool_het_inverse A1 C A2 (compose f2 f1) (compose b1 b2) ea x. Proof. unfold bool_het_inverse, compose. intros H H1 H2. apply H in H2. rewrite <- H2. apply H1. Qed.
module BBHeap.Order.Properties {A : Set}(_≤_ : A → A → Set) where open import BBHeap _≤_ open import BBHeap.Order _≤_ renaming (Acc to Accₕ ; acc to accₕ) open import Data.Nat open import Induction.Nat open import Induction.WellFounded ii-acc : ∀ {b} {h} → Acc _<′_ (# {b} h) → Accₕ h ii-acc (acc rs) = accₕ (λ h' #h'<′#h → ii-acc (rs (# h') #h'<′#h)) ≺-wf : ∀ {b} h → Accₕ {b} h ≺-wf = λ h → ii-acc (<-well-founded (# h))
{-# LANGUAGE BangPatterns #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE FlexibleContexts #-} module FokkerPlanck.FourierSeries ( fourierMellin , sampleScale -- , computeFourierCoefficients , computeHarmonicsArray , computeHarmonicsArraySparse -- , computeHarmonicsArrayGPU , getHarmonics , computeThetaRHarmonics , computeFourierSeriesThetaR -- , computeFourierSeriesR2 , normalizeFreqArr -- , normalizeFreqArr' , plotThetaDimension , computeFourierSeriesOfLogPolarHarmonicsArray , computeRectangularInverseHarmonics ) where import Array.UnboxedArray as UA import Control.DeepSeq import Data.Array.IArray as IA import Data.Array.Repa as R import Data.Binary import Data.Complex import Data.DList as DL import Data.List as L import Data.Vector.Generic as VG import Data.Vector.Unboxed as VU import FokkerPlanck.BrownianMotion import FokkerPlanck.Histogram import GHC.Generics (Generic) import Text.Printf import Utils.Array import Utils.Parallel import Utils.Time import Graphics.Rendering.Chart.Backend.Cairo import Graphics.Rendering.Chart.Easy import Image.IO import System.FilePath import Utils.SimpsonRule import Numeric.LinearAlgebra as NL import Numeric.LinearAlgebra.Data as NL import Utils.Distribution import Pinwheel.Base -- {-# INLINE fourierMellin' #-} -- fourierMellin' :: Int -> Int -> (Double, Double) -> Complex Double -- fourierMellin' !angularFreq !radialFreq (!x, !y) = -- if x == 0 && y == 0 -- then 0 -- else exp $ (-1 * log rho) :+ (tf * atan2 y x + rf * (log rho)) {-# INLINE sampleScale #-} sampleScale :: Double -> Double -> Double -> Double -> Double -> [Particle] -> Complex Double sampleScale !phiFreq !rhoFreq !thetaFreq !rFreq !halfLogPeriod = L.sum . L.map (\(Particle newPhi newRho theta newR _) -> if newRho == 0 -- || newR == 0 then 0 else (cos (phiFreq * newPhi + thetaFreq * (theta - newPhi)) :+ 0) * (cis $ (-pi) * (rhoFreq * (newRho) + rFreq * (newR - newRho)) / halfLogPeriod)) -- {-# INLINE computeFourierCoefficients #-} -- computeFourierCoefficients :: -- [Double] -- -> [Double] -- -> [Double] -- -> [Double] -- -> Double -- -> Double -- -> [DList Particle] -- -> Histogram (Complex Double) -- computeFourierCoefficients !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !halfLogPeriod !deltaLogRho !xs = -- Histogram -- [L.length phiFreqs, L.length rhoFreqs, L.length thetaFreqs, L.length rFreqs] -- (L.length ys) . -- toUnboxedVector . -- UA.accum -- (+) -- 0 -- ( (1, 1, 1, 1) -- , ( L.length rFreqs -- , L.length thetaFreqs -- , L.length rhoFreqs -- , L.length phiFreqs)) . -- L.concat . -- parMap -- rdeepseq -- (\(particle@(Particle phi rho theta r)) -> -- let !n = floor $ (log r + halfLogPeriod) / deltaLogRho -- !samples = -- -- L.map moveParticle $ -- particle : -- [ -- (Particle -- -- phi -- -- rho -- -- theta -- -- (exp $ (fromIntegral i * deltaLogRho - halfLogPeriod))) -- -- | i <- [0 .. n] -- ] -- in L.map -- (\((rFreq, i), (thetaFreq, j), (rhoFreq, k), (phiFreq, l)) -> -- ( (i, j, k, l) -- , -- (deltaLogRho :+ 0) * -- 1/ (16 * pi^2 * halfLogPeriod :+ 0) * -- sampleScale -- phiFreq -- rhoFreq -- thetaFreq -- rFreq -- halfLogPeriod -- samples)) -- freqs) $ -- ys -- where -- !ys = DL.toList . DL.concat $ xs -- !freqs = -- [ (rFreq', thetaFreq', rhoFreq', phiFreq') -- | rFreq' <- L.zip rFreqs [1 ..] -- , thetaFreq' <- L.zip thetaFreqs [1 ..] -- , rhoFreq' <- L.zip rhoFreqs [1 ..] -- , phiFreq' <- L.zip phiFreqs [1 ..] -- ] -- {-# INLINE normalizeFreqArr #-} -- normalizeFreqArr :: -- Double -- -> [Double] -- -> [Double] -- -> R.Array U DIM4 (Complex Double) -- -> R.Array U DIM4 (Complex Double) -- normalizeFreqArr !std !phiFreqs !rhoFreqs arr = -- computeUnboxedS . -- R.traverse3 -- arr -- (fromListUnboxed (Z :. L.length phiFreqs) phiFreqs) -- (fromListUnboxed (Z :. L.length rhoFreqs) rhoFreqs) -- (\sh _ _ -> sh) $ \fArr fPhi fRho idx@(Z :. r :. theta :. rho :. phi) -> -- fArr idx * -- ((exp $ -- (-1) * -- ((fPhi (Z :. phi)) ^ 2 + (fPhi (Z :. theta)) ^ 2 + (fRho (Z :. rho)) ^ 2 + -- (fRho (Z :. r)) ^ 2) / -- 2 / -- (std ^ 2)) :+ -- 0) {-# INLINE normalizeFreqArr #-} normalizeFreqArr :: Double -> Double -> [Double] -> [Double] -> R.Array U DIM4 (Complex Double) -> R.Array U DIM4 (Complex Double) normalizeFreqArr !stdA !stdR !phiFreqs !rhoFreqs arr | stdA == 0 && stdR == 0 = arr | stdA == 0 = computeUnboxedS . R.traverse3 arr (fromListUnboxed (Z :. L.length phiFreqs) phiFreqs) (fromListUnboxed (Z :. L.length rhoFreqs) rhoFreqs) (\sh _ _ -> sh) $ \fArr fPhi fRho idx@(Z :. r :. theta :. rho :. phi) -> fArr idx * (exp $ ((-1) * ((fRho (Z :. rho)) ^ 2 + (fRho (Z :. r)) ^ 2) / (2 * stdR ^ 2)) :+ 0) | stdR == 0 = computeUnboxedS . R.traverse3 arr (fromListUnboxed (Z :. L.length phiFreqs) phiFreqs) (fromListUnboxed (Z :. L.length rhoFreqs) rhoFreqs) (\sh _ _ -> sh) $ \fArr fPhi fRho idx@(Z :. _ :. theta :. rho :. phi) -> fArr idx * ((exp $ (-1) * ((fPhi (Z :. phi)) ^ 2 + (fPhi (Z :. theta)) ^ 2) / (2 * stdA ^ 2)) :+ 0) | otherwise = computeUnboxedS . R.traverse3 arr (fromListUnboxed (Z :. L.length phiFreqs) phiFreqs) (fromListUnboxed (Z :. L.length rhoFreqs) rhoFreqs) (\sh _ _ -> sh) $ \fArr fPhi fRho idx@(Z :. r :. theta :. rho :. phi) -> fArr idx * ((exp $ (-1) * ((fPhi (Z :. phi)) ^ 2 + (fPhi (Z :. theta)) ^ 2) / (2 * stdA ^ 2) - ((fRho (Z :. rho)) ^ 2 + (fRho (Z :. r)) ^ 2) / (2 * stdR ^ 2)) :+ 0) -- {-# INLINE computeHarmonicsArray #-} computeHarmonicsArray :: (VG.Vector vector (Complex Double), NFData (vector (Complex Double))) => Int -> Double -> Int -> Double -> [Double] -> [Double] -> [Double] -> [Double] -> Double -> Double -> IA.Array (Int, Int) (vector (Complex Double)) computeHarmonicsArray !numRows !deltaRow !numCols !deltaCol !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !halfLogPeriod !cutoff = let !centerRow = div numRows 2 !centerCol = div numCols 2 rangeFunc1 xs ys = [(L.head xs - L.last ys) .. (L.last xs - L.head ys)] rangeFunc2 xs ys = (round (L.head xs - L.last ys), round (L.last xs - L.head ys)) (!tfLB, !tfUB) = rangeFunc2 phiFreqs thetaFreqs (!rfLB, !rfUB) = rangeFunc2 rhoFreqs rFreqs !xs = parMap rdeepseq (\(!rf, !tf) -> let !vec = VG.convert . toUnboxed . computeS . fromFunction (Z :. numCols :. numRows) $ \(Z :. c :. r) -> let !x = fromIntegral (c - centerCol) * deltaCol !y = fromIntegral (r - centerRow) * deltaRow !rho = 0 + (sqrt $ x ^ 2 + y ^ 2) !rho2 = fromIntegral $ (c - centerCol) ^ 2 + (r - centerRow) ^ 2 in if rho2 > cutoff ^ 2 || (rho <= 0) -- || pi * rho < (abs tf) -- || log ((rho + 1) / rho) > (1 / (2 * rf)) then 0 -- (x :+ y) ** (tf :+ 0) * -- ((x ^ 2 + y ^ 2) :+ 0) ** -- (((-tf - 0.5) :+ rf) / 2) else ((rho :+ 0) ** ((-1) :+ rf)) * (cis (tf * atan2 y x)) in ((round rf, round tf), vec)) [ (rf, tf) | rf <- rangeFunc1 rhoFreqs rFreqs , tf <- rangeFunc1 phiFreqs thetaFreqs ] in IA.array ((rfLB, tfLB), (rfUB, tfUB)) xs -- {-# INLINE computeHarmonicsArraySparse #-} computeHarmonicsArraySparse :: Int -> Double -> Int -> Double -> [Double] -> [Double] -> [Double] -> [Double] -> Double -> Double -> Double -> IA.Array (Int, Int) (R.Array U DIM2 (Complex Double)) computeHarmonicsArraySparse !numRows !deltaRow !numCols !deltaCol !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !halfLogPeriod !cutoff !envelopeSigma = let !centerRow = div numRows 2 !centerCol = div numCols 2 rangeFunc1 xs ys = [(round $ L.head xs - L.last ys) .. (round $ L.last xs - L.head ys)] rangeFunc2 xs ys = ((round $ (L.head xs - L.last ys)), (round $ (L.last xs - L.head ys))) (!tfLB, !tfUB) = rangeFunc2 phiFreqs thetaFreqs (!rfLB, !rfUB) = rangeFunc2 rhoFreqs rFreqs !xs = parMap rseq (\(!rf, !tf) -> let !arr = computeS . fromFunction (Z :. numCols :. numRows) $ \(Z :. c :. r) -> let !x = fromIntegral (c - centerCol) * deltaCol !y = fromIntegral (r - centerRow) * deltaRow !rho = ((sqrt $ x ^ 2 + y ^ 2)) !rho2 = fromIntegral $ (c - centerCol) ^ 2 + (r - centerRow) ^ 2 in if (rho <= 0) || rho2 > cutoff ^ 2 then 0 else (x :+ y) ** (fromIntegral tf :+ 0) * (((x ^ 2 + y ^ 2) :+ 0) ** (((-(fromIntegral tf) - envelopeSigma) :+ (2 * pi / halfLogPeriod * fromIntegral rf)) / 2)) in deepSeqArray arr ((rf, tf), arr)) [ (rf, tf) | rf <- rangeFunc1 rhoFreqs rFreqs , tf <- rangeFunc1 phiFreqs thetaFreqs ] in IA.array ((rfLB, tfLB), (rfUB, tfUB)) xs -- {-# INLINE computeHarmonicsArrayGPU #-} -- computeHarmonicsArrayGPU :: -- (VG.Vector vector (Complex Double), NFData (vector (Complex Double))) -- => Int -- -> Double -- -> Int -- -> Double -- -> [Double] -- -> [Double] -- -> [Double] -- -> [Double] -- -> Double -- -> Double -- -> IA.Array (Int, Int) (vector (Complex Double)) -- computeHarmonicsArrayGPU !numRows !deltaRow !numCols !deltaCol !phiFreqs !rhoFreqs !thetaFreqs !rFreqs !halfLogPeriod !cutoff = -- let !centerRow = div numRows 2 -- !centerCol = div numCols 2 -- rangeFunc1 xs ys = -- [round (L.head xs - L.last ys) .. round (L.last xs - L.head ys)] -- rangeFunc2 xs ys = -- (round (L.head xs - L.last ys), round (L.last xs - L.head ys)) -- (!tfLB, !tfUB) = rangeFunc2 phiFreqs thetaFreqs -- (!rfLB, !rfUB) = rangeFunc2 rhoFreqs rFreqs -- !xs = -- parMap -- rdeepseq -- (\(!rf, !tf) -> -- let !vec = -- VG.convert . -- toUnboxed . computeS . fromFunction (Z :. numCols :. numRows) $ \(Z :. c :. r) -> -- let !x = fromIntegral (c - centerCol) * deltaCol -- !y = fromIntegral (r - centerRow) * deltaRow -- !r2 = x ^ 2 + y ^ 2 -- in if (x == 0 && y == 0) || r2 > cutoff ^ 2 -- then 0 -- else cis $ -- fromIntegral tf * atan2 y x + -- (pi * (fromIntegral rf * 0.5 * log r2) / -- halfLogPeriod - pi) -- in ((rf, tf), vec)) -- [ (rf, tf) -- | rf <- (rangeFunc1 rhoFreqs rFreqs) -- , tf <- L.reverse (rangeFunc1 phiFreqs thetaFreqs) -- ] -- in IA.array ((rfLB, tfLB), (rfUB, tfUB)) xs {-# INLINE getHarmonics #-} getHarmonics :: (VG.Vector vector e) => IA.Array (Int, Int) (vector e) -> Double -> Double -> Double -> Double -> vector e getHarmonics harmonicsArray phiFreq rhoFreq thetaFreq rFreq = harmonicsArray IA.! (round (rhoFreq - rFreq), round $ (phiFreq - thetaFreq)) -- {-# INLINE computeFourierSeriesR2 #-} -- computeFourierSeriesR2 :: -- Int -- -> Double -- -> Int -- -> Double -- -> [Double] -- -> [Double] -- -> [Double] -- -> [Double] -- -> Double -- -> Double -- -> IA.Array (Int, Int) (VU.Vector (Complex Double)) -- -> R.Array U DIM4 (Complex Double) -- -> [VU.Vector (Complex Double)] -- computeFourierSeriesR2 numRows deltaRow numCols deltaCol phiFreqs rhoFreqs thetaFreqs rFreqs halfLogPeriod cutoff harmonicsArray arr = -- let (Z :. (!numRFreq) :. (!numThetaFreq) :. _ :. _) = extent arr -- !initVec = VU.replicate (VU.length (harmonicsArray IA.! (0, 0))) 0 -- in parMap -- rdeepseq -- (\((!r, !rFreq), (!theta, !thetaFreq)) -> -- L.foldl' -- (\(!vec) ((!rho, !rhoFreq), (!phi, !phiFreq)) -> -- VU.zipWith -- (+) -- vec -- (VU.map -- (* (arr R.! (Z :. r :. theta :. rho :. phi))) -- (getHarmonics harmonicsArray phiFreq rhoFreq thetaFreq rFreq))) -- initVec $ -- (,) <$> (L.zip [0 ..] rhoFreqs) <*> (L.zip [0 ..] phiFreqs)) $ -- (,) <$> (L.zip [0 ..] rFreqs) <*> (L.zip [0 ..] thetaFreqs) -- {-# INLINE computeThetaRHarmonics #-} computeThetaRHarmonics :: Int -> Int -> [Double] -> [Double] -> Double -> [[(Complex Double)]] computeThetaRHarmonics !numOrientation !numScale !thetaFreqs !rFreqs !halfLogPeriod = let !deltaTheta = 2 * pi / fromIntegral numOrientation !deltaScale = 2 * halfLogPeriod / fromIntegral numScale !numRFreq = L.length rFreqs !numThetaFreq = L.length thetaFreqs in if numScale == 1 then parMap rdeepseq (\o -> L.map (\freq -> cis $ freq * (fromIntegral o * deltaTheta)) thetaFreqs) $ [0 .. numOrientation - 1] else parMap rdeepseq (\(!o, !s) -> R.toList . R.traverse2 (fromListUnboxed (Z :. numRFreq) rFreqs) (fromListUnboxed (Z :. numThetaFreq) thetaFreqs) (\_ _ -> (Z :. numRFreq :. numThetaFreq)) $ \fRFreq fThetaFreq idx@(Z :. rFreq :. thetaFreq) -> -- exp $ -- (-0.5 * (fromIntegral s * deltaScale - halfLogPeriod)) :+ -- ((fRFreq (Z :. rFreq)) * -- (fromIntegral s * deltaScale - halfLogPeriod) + -- fThetaFreq (Z :. thetaFreq) * fromIntegral o * deltaTheta) cis ((fRFreq (Z :. rFreq)) * (pi * (fromIntegral s * deltaScale - halfLogPeriod) / halfLogPeriod) + fThetaFreq (Z :. thetaFreq) * fromIntegral o * deltaTheta) ) $ (,) <$> [0 .. numOrientation - 1] <*> [0 .. numScale - 1] {-# INLINE computeFourierSeriesThetaR #-} computeFourierSeriesThetaR :: (VG.Vector vector (Complex Double), NFData (vector (Complex Double))) => [[(Complex Double)]] -> [vector (Complex Double)] -> [vector (Complex Double)] computeFourierSeriesThetaR !harmonics !vecs = let !initVec = VG.replicate (VG.length . L.head $ vecs) 0 in parMap rdeepseq (L.foldl' (\vec0 (!vec1, !v) -> VG.zipWith (+) vec0 . VG.map (* v) $ vec1) initVec . L.zip vecs) $ harmonics plotThetaDimension :: (R.Source s Double) => FilePath -> String -> (Int, Int) -> R.Array s DIM3 Double -> IO () plotThetaDimension folderPath prefix (x', y') inputArr = do let centerCol = div cols 2 centerRow = div rows 2 x = x' + centerCol y = y' + centerRow (Z :. numOrientation :. cols :. rows) = extent inputArr centerArr = fromFunction (Z :. (1 :: Int) :. cols :. rows) $ \(Z :. _ :. i :. j) -> if i == x && j == y then 1 :: Double else 0 plotImageRepa (folderPath </> printf "%s(%d,%d)_center.png" prefix x' y') . ImageRepa 8 . computeS $ centerArr let ys' = R.toList . R.slice inputArr $ (Z :. R.All :. x :. y) !maxY = L.maximum ys' -- ys = L.map (/maxY) ys' ys = ys' deltaTheta = (360 ::Double) / fromIntegral numOrientation xs = [fromIntegral x * deltaTheta | x <- [0 .. numOrientation - 1]] toFile def (folderPath </> printf "%s(%d,%d)_theta.png" prefix x' y') $ do layout_title .= printf "%s(%d,%d)" prefix x' y' layout_x_axis . laxis_generate .= scaledAxis def (0, 359) layout_y_axis . laxis_generate .= scaledAxis def (0, maxY) plot (line "" [L.zip xs ys]) -- The codes below compute Fourier series in R2 computeFourierSeriesOfLogPolarHarmonicsArray :: (VG.Vector vector (Complex Double), NFData (vector (Complex Double))) => Double -> Double -> Int -> Int -> Int -> Int -> Int -> Double -> IA.Array (Int, Int) (vector (Complex Double)) computeFourierSeriesOfLogPolarHarmonicsArray !radius !delta !r2Freq !phiFreq !rhoFreq !thetaFreq !rFreq !halfLogPeriod = let ((!angularFreqLB, !angularFreqUB), angularFreqs) = freqRange phiFreq thetaFreq ((!radialFreqLB, !radialFreqUB), radialFreqs) = freqRange phiFreq thetaFreq !numPoints' = round $ (2 * radius + 1) / delta !numPoints = if odd numPoints' then numPoints' else numPoints' - 1 !center = div numPoints 2 !period = 2 * radius + 1 !periodConstant = delta * 2 * pi / period !numR2Freq = 2 * r2Freq + 1 !std = fromIntegral $ div r2Freq 2 !simpsonWeights = toUnboxed . computeS $ (computeWeightArrFromListOfShape [numPoints, numPoints] :: R.Array D DIM2 (Complex Double)) !weightedRectangularHarmonics = parMap rdeepseq (\(freq1, freq2) -> VU.zipWith (*) simpsonWeights . toUnboxed . computeS . fromFunction (Z :. numPoints :. numPoints) $ \(Z :. i :. j) -> cis (-periodConstant * fromIntegral (freq1 * (i - center) + freq2 * (j - center)))) [ (freq1, freq2) | freq1 <- [-r2Freq .. r2Freq] , freq2 <- [-r2Freq .. r2Freq] ] !cartesianGrid = toUnboxed . computeS . fromFunction (Z :. numPoints :. numPoints) $ \(Z :. c :. r) -> let !x = fromIntegral (c - center) * delta !y = fromIntegral (r - center) * delta in (x, y) !simpsonNorm = (delta / 3) ^ 2 :+ 0 !xs = parMap rdeepseq (\(!radialFreq, !angularFreq) -> let !logPolarHarmonics = VU.map (fourierMellin 0.5 angularFreq radialFreq) cartesianGrid coefficients = fromListUnboxed (Z :. numR2Freq :. numR2Freq) . L.map (VU.sum . VU.zipWith (*) logPolarHarmonics) $ weightedRectangularHarmonics !coefficientsGaussian = VG.convert . toUnboxed . computeS . R.traverse coefficients id $ \f idx@(Z :. xFreq :. yFreq) -> simpsonNorm * (f idx) * (gaussian2D (fromIntegral $ xFreq - r2Freq) (fromIntegral $ yFreq - r2Freq) std :+ 0) in ((radialFreq, angularFreq), coefficientsGaussian)) [ (radialFreq, angularFreq) | radialFreq <- radialFreqs , angularFreq <- angularFreqs ] in IA.array ((radialFreqLB, angularFreqLB), (radialFreqUB, angularFreqUB)) xs computeRectangularInverseHarmonics :: (VG.Vector vector (Complex Double), NFData (vector (Complex Double))) => Int -> Int -> Double -> Double -> Int -> [vector (Complex Double)] computeRectangularInverseHarmonics !numRows !numCols !delta !radius !maxFreq = let !period = 2 * radius + 1 !periodConstant = delta * 2 * pi / period !centerRow = div numRows 2 !centerCol = div numCols 2 in parMap rdeepseq (\(col, row) -> VG.fromList [ cis (periodConstant * fromIntegral (freq1 * (row - centerRow) + freq2 * (col - centerCol))) | freq1 <- [-maxFreq .. maxFreq] , freq2 <- [-maxFreq .. maxFreq] ]) [(col, row) | col <- [0 .. numCols - 1], row <- [0 .. numRows - 1]] -- Utilities {-# INLINE freqRange #-} freqRange :: Int -> Int -> ((Int, Int), [Int]) freqRange n m = let !x = n + m in ((-x, x), [-x .. x])
! PR middle-end/59706 ! { dg-do compile } integer i do concurrent (i=1:2) end do contains subroutine foo end end
(* Title: HOL/HOLCF/ex/Dnat.thy Author: Franz Regensburger Theory for the domain of natural numbers dnat = one ++ dnat *) theory Dnat imports HOLCF begin domain dnat = dzero | dsucc (dpred :: dnat) definition iterator :: "dnat -> ('a -> 'a) -> 'a -> 'a" where "iterator = fix $ (LAM h n f x. case n of dzero => x | dsucc $ m => f $ (h $ m $ f $ x))" text {* \medskip Expand fixed point properties. *} lemma iterator_def2: "iterator = (LAM n f x. case n of dzero => x | dsucc$m => f$(iterator$m$f$x))" apply (rule trans) apply (rule fix_eq2) apply (rule iterator_def [THEN eq_reflection]) apply (rule beta_cfun) apply simp done text {* \medskip Recursive properties. *} lemma iterator1: "iterator $ UU $ f $ x = UU" apply (subst iterator_def2) apply simp done lemma iterator2: "iterator $ dzero $ f $ x = x" apply (subst iterator_def2) apply simp done lemma iterator3: "n ~= UU ==> iterator $ (dsucc $ n) $ f $ x = f $ (iterator $ n $ f $ x)" apply (rule trans) apply (subst iterator_def2) apply simp apply (rule refl) done lemmas iterator_rews = iterator1 iterator2 iterator3 lemma dnat_flat: "ALL x y::dnat. x<<y --> x=UU | x=y" apply (rule allI) apply (induct_tac x) apply fast apply (rule allI) apply (case_tac y) apply simp apply simp apply simp apply (rule allI) apply (case_tac y) apply (fast intro!: bottomI) apply (thin_tac "ALL y. dnat << y --> dnat = UU | dnat = y") apply simp apply (simp (no_asm_simp)) apply (drule_tac x="dnata" in spec) apply simp done end
data Term (V : Set) : Set where App : Term V -> Term V -> Term V Abs : (V -> Term V) -> Term V -- ouch, posititity.
{-# OPTIONS --without-K --safe #-} module Categories.Category.Monoidal.Instance.Setoids where open import Level open import Data.Product open import Data.Product.Relation.Binary.Pointwise.NonDependent open import Data.Sum open import Data.Sum.Relation.Binary.Pointwise open import Function.Equality open import Relation.Binary using (Setoid) open import Categories.Category open import Categories.Category.Instance.Setoids open import Categories.Category.Cartesian open import Categories.Category.Cocartesian open import Categories.Category.Instance.SingletonSet open import Categories.Category.Instance.EmptySet module _ {o ℓ} where Setoids-Cartesian : Cartesian (Setoids o ℓ) Setoids-Cartesian = record { terminal = SingletonSetoid-⊤ ; products = record { product = λ {A B} → let module A = Setoid A module B = Setoid B in record { A×B = ×-setoid A B -- the stdlib doesn't provide projections! ; π₁ = record { _⟨$⟩_ = proj₁ ; cong = proj₁ } ; π₂ = record { _⟨$⟩_ = proj₂ ; cong = proj₂ } ; ⟨_,_⟩ = λ f g → record { _⟨$⟩_ = λ x → f ⟨$⟩ x , g ⟨$⟩ x ; cong = λ eq → cong f eq , cong g eq } ; project₁ = λ {_ h i} eq → cong h eq ; project₂ = λ {_ h i} eq → cong i eq ; unique = λ {W h i j} eq₁ eq₂ eq → A.sym (eq₁ (Setoid.sym W eq)) , B.sym (eq₂ (Setoid.sym W eq)) } } } module Setoids-Cartesian = Cartesian Setoids-Cartesian open Setoids-Cartesian renaming (monoidal to Setoids-Monoidal) public Setoids-Cocartesian : Cocartesian (Setoids o (o ⊔ ℓ)) Setoids-Cocartesian = record { initial = EmptySetoid-⊥ ; coproducts = record { coproduct = λ {A} {B} → record { A+B = ⊎-setoid A B ; i₁ = record { _⟨$⟩_ = inj₁ ; cong = inj₁ } ; i₂ = record { _⟨$⟩_ = inj₂ ; cong = inj₂ } ; [_,_] = λ f g → record { _⟨$⟩_ = [ f ⟨$⟩_ , g ⟨$⟩_ ] ; cong = λ { (inj₁ x) → Π.cong f x ; (inj₂ x) → Π.cong g x } } ; inject₁ = λ {_} {f} → Π.cong f ; inject₂ = λ {_} {_} {g} → Π.cong g ; unique = λ { {C} h≈f h≈g (inj₁ x) → Setoid.sym C (h≈f (Setoid.sym A x)) ; {C} h≈f h≈g (inj₂ x) → Setoid.sym C (h≈g (Setoid.sym B x)) } } } }
{------------------------------------------------------------------------------ SimpleArray.idr ------------------------------------------------------------------------------} ||| A simple mutable array type built on `Data.IOArray`. module SimpleArray import Data.IOArray %default total ||| A wrapper around `Data.IOArray` that also stores the number of elements in ||| the array. public export record SimpleArray (elem : Type) where constructor MkSimpleArray inner : IOArray elem size : Int ||| Creates a new `SimpleArray` of the given size with all elements initialized ||| to the given default value. export new : Int -> elem -> IO (SimpleArray elem) new n e = do inner <- newArray n e pure $ MkSimpleArray inner n ||| get an element from the array; yields `Nothing` if index is negative or ||| larger than the array size. export get : SimpleArray elem -> Int -> IO (Maybe elem) get array@(MkSimpleArray inner size) i = pure $ if size <= i then Nothing else Just !(unsafeReadArray inner i) ||| Write a value into the array, yielding `Nothing` if the index is negative ||| or larger than the array size. export put : SimpleArray elem -> Int -> elem -> IO (Maybe ()) put array@(MkSimpleArray inner size) i e = pure $ if size <= i then Nothing else Just !(unsafeWriteArray inner i e) ||| Map a function over the given array, creating a new array holding the ||| results. export map : Monoid b => (a -> b) -> SimpleArray a -> IO (SimpleArray b) map f array@(MkSimpleArray from size) = do to <- newArray size neutral for (take (toNat size) $ iterate (+1) 0) (\i => do e <- unsafeReadArray from i unsafeWriteArray to i $ f e ) pure $ MkSimpleArray to size ||| Map an IO function over the given array, creating a new array holding the ||| results. export mapIO : Monoid b => (a -> IO b) -> SimpleArray a -> IO (SimpleArray b) mapIO f array@(MkSimpleArray from size) = do to <- newArray size neutral for (take (toNat size) $ iterate (+1) 0) (\i => do e <- unsafeReadArray from i unsafeWriteArray to i $ !(f e) ) pure $ MkSimpleArray to size ||| Map a function over the given array, writing the result values directly ||| into the array. export mapInplace : (elem -> elem) -> SimpleArray elem -> IO (SimpleArray elem) mapInplace f array@(MkSimpleArray inner size) = do for (take (toNat size) $ iterate (+1) 0) (\i => do e <- unsafeReadArray inner i unsafeWriteArray inner i $ f e ) pure array ||| Fill array elements with result of applying the given function to each ||| element index. export fromIndex : SimpleArray elem -> (Int -> elem) -> IO (SimpleArray elem) fromIndex array@(MkSimpleArray inner size) f = do for (take (toNat size) $ iterate (+1) 0) (\i => do unsafeWriteArray inner i $ f i ) pure array ||| Check if a given element is contained in this array. export covering contains : Eq elem => SimpleArray elem -> elem -> IO Bool contains (MkSimpleArray inner size) e = rec 0 where covering rec : Int -> IO Bool rec i = if i == size then pure False else if e == !(unsafeReadArray inner i) then pure True else rec (i+1) ||| Array contents on a single line. export show : Show elem => SimpleArray elem -> IO String show (MkSimpleArray inner size) = do elems <- for (take (toNat size) $ iterate (+1) 0) (\i => pure $ show !(unsafeReadArray inner i) ++ if i < (size - 1) then "," else "" ) pure $ "[" ++ (concat elems) ++ "]" ||| Array contents with a single element per line. export showPretty : Show elem => SimpleArray elem -> IO String showPretty (MkSimpleArray inner size) = do elems <- for (take (toNat size) $ iterate (+1) 0) (\i => pure $ show !(unsafeReadArray inner i) ++ if i < (size - 1) then ",\n " else "\n" ) pure $ "[\n " ++ (concat elems) ++ "]" export covering test : IO () test = do array <- new 5 9 putStrLn !(show array) putStrLn $ "contains 9: " ++ show !(contains array 9) putStrLn $ "contains 10: " ++ show !(contains array 10) _ <- fromIndex array (\i => i * 3) putStrLn !(show array) _ <- mapInplace (+1) array putStrLn !(show array) _ <- mapInplace (*2) array putStrLn !(showPretty array)
An important pathophysiological mechanism of <unk> in AML is the epigenetic induction of <unk> by genetic mutations that alter the function of epigenetic enzymes , such as the DNA <unk> <unk> and the metabolic enzymes <unk> and <unk> , which lead to the generation of a novel <unk> , D @-@ 2 @-@ <unk> , which inhibits the activity of epigenetic enzymes such as <unk> . The hypothesis is that such epigenetic mutations lead to the silencing of tumor suppressor genes and / or the activation of proto @-@ oncogenes .
data {-sdaf-} Nat {-sdaf-} : {-sdaf-} Set {-sdaf-} where {-sdaf-} zero {-sdaf-} : {-sdaf-} Nat {-sdaf-} suc {-sdaf-} :{-sdaf-} Nat {-sdaf-} -> {-sdaf-} Nat {-sdaf-} data Impossible : Set where {-Comment which should not be duplicated-}
A set $M$ is a ring of sets if and only if $M$ is a subset of the power set of $\Omega$, $M$ contains the empty set, $M$ is closed under union, and $M$ is closed under set difference.
/- Copyright (c) 2022 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash ! This file was ported from Lean 3 source module measure_theory.covering.liminf_limsup ! leanprover-community/mathlib commit b2ff9a3d7a15fd5b0f060b135421d6a89a999c2f ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathbin.MeasureTheory.Covering.DensityTheorem /-! # Liminf, limsup, and doubling measures. This file is a place to collect lemmas about liminf and limsup for subsets of a metric space carrying a doubling measure. ## Main results: * `blimsup_cthickening_mul_ae_eq`: the limsup of the closed thickening of a sequence of subsets of a metric space is unchanged almost everywhere for a doubling measure if the sequence of distances is multiplied by a positive scale factor. This is a generalisation of a result of Cassels, appearing as Lemma 9 on page 217 of [J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950). * `blimsup_thickening_mul_ae_eq`: a variant of `blimsup_cthickening_mul_ae_eq` for thickenings rather than closed thickenings. -/ open Set Filter Metric MeasureTheory TopologicalSpace open NNReal ENNReal Topology variable {α : Type _} [MetricSpace α] [SecondCountableTopology α] [MeasurableSpace α] [BorelSpace α] variable (μ : Measure α) [IsLocallyFiniteMeasure μ] [IsDoublingMeasure μ] /-- This is really an auxiliary result en route to `blimsup_cthickening_ae_le_of_eventually_mul_le` (which is itself an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`). NB: The `set : α` type ascription is present because of issue #16932 on GitHub. -/ theorem blimsup_cthickening_ae_le_of_eventually_mul_le_aux (p : ℕ → Prop) {s : ℕ → Set α} (hs : ∀ i, IsClosed (s i)) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0)) (hrp : 0 ≤ r₁) {M : ℝ} (hM : 0 < M) (hM' : M < 1) (hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) : (blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ] (blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by /- Sketch of proof: Assume that `p` is identically true for simplicity. Let `Y₁ i = cthickening (r₁ i) (s i)`, define `Y₂` similarly except using `r₂`, and let `(Z i) = ⋃_{j ≥ i} (Y₂ j)`. Our goal is equivalent to showing that `μ ((limsup Y₁) \ (Z i)) = 0` for all `i`. Assume for contradiction that `μ ((limsup Y₁) \ (Z i)) ≠ 0` for some `i` and let `W = (limsup Y₁) \ (Z i)`. Apply Lebesgue's density theorem to obtain a point `d` in `W` of density `1`. Since `d ∈ limsup Y₁`, there is a subsequence of `j ↦ Y₁ j`, indexed by `f 0 < f 1 < ...`, such that `d ∈ Y₁ (f j)` for all `j`. For each `j`, we may thus choose `w j ∈ s (f j)` such that `d ∈ B j`, where `B j = closed_ball (w j) (r₁ (f j))`. Note that since `d` has density one, `μ (W ∩ (B j)) / μ (B j) → 1`. We obtain our contradiction by showing that there exists `η < 1` such that `μ (W ∩ (B j)) / μ (B j) ≤ η` for sufficiently large `j`. In fact we claim that `η = 1 - C⁻¹` is such a value where `C` is the scaling constant of `M⁻¹` for the doubling measure `μ`. To prove the claim, let `b j = closed_ball (w j) (M * r₁ (f j))` and for given `j` consider the sets `b j` and `W ∩ (B j)`. These are both subsets of `B j` and are disjoint for large enough `j` since `M * r₁ j ≤ r₂ j` and thus `b j ⊆ Z i ⊆ Wᶜ`. We thus have: `μ (b j) + μ (W ∩ (B j)) ≤ μ (B j)`. Combining this with `μ (B j) ≤ C * μ (b j)` we obtain the required inequality. -/ set Y₁ : ℕ → Set α := fun i => cthickening (r₁ i) (s i) set Y₂ : ℕ → Set α := fun i => cthickening (r₂ i) (s i) let Z : ℕ → Set α := fun i => ⋃ (j) (h : p j ∧ i ≤ j), Y₂ j suffices ∀ i, μ (at_top.blimsup Y₁ p \ Z i) = 0 by rwa [ae_le_set, @blimsup_eq_infi_bsupr_of_nat _ _ _ Y₂, infi_eq_Inter, diff_Inter, measure_Union_null_iff] intros set W := at_top.blimsup Y₁ p \ Z i by_contra contra obtain ⟨d, hd, hd'⟩ : ∃ d, d ∈ W ∧ ∀ {ι : Type _} {l : Filter ι} (w : ι → α) (δ : ι → ℝ), tendsto δ l (𝓝[>] 0) → (∀ᶠ j in l, d ∈ closed_ball (w j) (2 * δ j)) → tendsto (fun j => μ (W ∩ closed_ball (w j) (δ j)) / μ (closed_ball (w j) (δ j))) l (𝓝 1) := measure.exists_mem_of_measure_ne_zero_of_ae contra (IsDoublingMeasure.ae_tendsto_measure_inter_div μ W 2) replace hd : d ∈ blimsup Y₁ at_top p := ((mem_diff _).mp hd).1 obtain ⟨f : ℕ → ℕ, hf⟩ := exists_forall_mem_of_has_basis_mem_blimsup' at_top_basis hd simp only [forall_and] at hf obtain ⟨hf₀ : ∀ j, d ∈ cthickening (r₁ (f j)) (s (f j)), hf₁, hf₂ : ∀ j, j ≤ f j⟩ := hf have hf₃ : tendsto f at_top at_top := tendsto_at_top_at_top.mpr fun j => ⟨f j, fun i hi => (hf₂ j).trans (hi.trans <| hf₂ i)⟩ replace hr : tendsto (r₁ ∘ f) at_top (𝓝[>] 0) := hr.comp hf₃ replace hMr : ∀ᶠ j in at_top, M * r₁ (f j) ≤ r₂ (f j) := hf₃.eventually hMr replace hf₀ : ∀ j, ∃ w ∈ s (f j), d ∈ closed_ball w (2 * r₁ (f j)) · intro j specialize hrp (f j) rw [Pi.zero_apply] at hrp rcases eq_or_lt_of_le hrp with (hr0 | hrp') · specialize hf₀ j rw [← hr0, cthickening_zero, (hs (f j)).closure_eq] at hf₀ exact ⟨d, hf₀, by simp [← hr0]⟩ · exact mem_Union₂.mp (cthickening_subset_Union_closed_ball_of_lt (s (f j)) (by positivity) (lt_two_mul_self hrp') (hf₀ j)) choose w hw hw' using hf₀ let C := IsDoublingMeasure.scalingConstantOf μ M⁻¹ have hC : 0 < C := lt_of_lt_of_le zero_lt_one (IsDoublingMeasure.one_le_scalingConstantOf μ M⁻¹) suffices ∃ η < (1 : ℝ≥0), ∀ᶠ j in at_top, μ (W ∩ closed_ball (w j) (r₁ (f j))) / μ (closed_ball (w j) (r₁ (f j))) ≤ η by obtain ⟨η, hη, hη'⟩ := this replace hη' : 1 ≤ η := by simpa only [ENNReal.one_le_coe_iff] using le_of_tendsto (hd' w (fun j => r₁ (f j)) hr <| eventually_of_forall hw') hη' exact (lt_self_iff_false _).mp (lt_of_lt_of_le hη hη') refine' ⟨1 - C⁻¹, tsub_lt_self zero_lt_one (inv_pos.mpr hC), _⟩ replace hC : C ≠ 0 := ne_of_gt hC let b : ℕ → Set α := fun j => closed_ball (w j) (M * r₁ (f j)) let B : ℕ → Set α := fun j => closed_ball (w j) (r₁ (f j)) have h₁ : ∀ j, b j ⊆ B j := fun j => closed_ball_subset_closed_ball (mul_le_of_le_one_left (hrp (f j)) hM'.le) have h₂ : ∀ j, W ∩ B j ⊆ B j := fun j => inter_subset_right W (B j) have h₃ : ∀ᶠ j in at_top, Disjoint (b j) (W ∩ B j) := by apply hMr.mp rw [eventually_at_top] refine' ⟨i, fun j hj hj' => Disjoint.inf_right (B j) <| Disjoint.inf_right' (blimsup Y₁ at_top p) _⟩ change Disjoint (b j) (Z iᶜ) rw [disjoint_compl_right_iff_subset] refine' (closed_ball_subset_cthickening (hw j) (M * r₁ (f j))).trans ((cthickening_mono hj' _).trans fun a ha => _) simp only [mem_Union, exists_prop] exact ⟨f j, ⟨hf₁ j, hj.le.trans (hf₂ j)⟩, ha⟩ have h₄ : ∀ᶠ j in at_top, μ (B j) ≤ C * μ (b j) := (hr.eventually (IsDoublingMeasure.eventually_measure_le_scaling_constant_mul' μ M hM)).mono fun j hj => hj (w j) refine' (h₃.and h₄).mono fun j hj₀ => _ change μ (W ∩ B j) / μ (B j) ≤ ↑(1 - C⁻¹) rcases eq_or_ne (μ (B j)) ∞ with (hB | hB) · simp [hB] apply ENNReal.div_le_of_le_mul rw [WithTop.coe_sub, ENNReal.coe_one, ENNReal.sub_mul fun _ _ => hB, one_mul] replace hB : ↑C⁻¹ * μ (B j) ≠ ∞ · refine' ENNReal.mul_ne_top _ hB rwa [ENNReal.coe_inv hC, Ne.def, ENNReal.inv_eq_top, ENNReal.coe_eq_zero] obtain ⟨hj₁ : Disjoint (b j) (W ∩ B j), hj₂ : μ (B j) ≤ C * μ (b j)⟩ := hj₀ replace hj₂ : ↑C⁻¹ * μ (B j) ≤ μ (b j) · rw [ENNReal.coe_inv hC, ← ENNReal.div_eq_inv_mul] exact ENNReal.div_le_of_le_mul' hj₂ have hj₃ : ↑C⁻¹ * μ (B j) + μ (W ∩ B j) ≤ μ (B j) := by refine' le_trans (add_le_add_right hj₂ _) _ rw [← measure_union' hj₁ measurableSet_closedBall] exact measure_mono (union_subset (h₁ j) (h₂ j)) replace hj₃ := tsub_le_tsub_right hj₃ (↑C⁻¹ * μ (B j)) rwa [ENNReal.add_sub_cancel_left hB] at hj₃ #align blimsup_cthickening_ae_le_of_eventually_mul_le_aux blimsup_cthickening_ae_le_of_eventually_mul_le_aux /-- This is really an auxiliary result en route to `blimsup_cthickening_mul_ae_eq`. NB: The `set : α` type ascription is present because of issue #16932 on GitHub. -/ theorem blimsup_cthickening_ae_le_of_eventually_mul_le (p : ℕ → Prop) {s : ℕ → Set α} {M : ℝ} (hM : 0 < M) {r₁ r₂ : ℕ → ℝ} (hr : Tendsto r₁ atTop (𝓝[>] 0)) (hMr : ∀ᶠ i in atTop, M * r₁ i ≤ r₂ i) : (blimsup (fun i => cthickening (r₁ i) (s i)) atTop p : Set α) ≤ᵐ[μ] (blimsup (fun i => cthickening (r₂ i) (s i)) atTop p : Set α) := by let R₁ i := max 0 (r₁ i) let R₂ i := max 0 (r₂ i) have hRp : 0 ≤ R₁ := fun i => le_max_left 0 (r₁ i) replace hMr : ∀ᶠ i in at_top, M * R₁ i ≤ R₂ i · refine' hMr.mono fun i hi => _ rw [mul_max_of_nonneg _ _ hM.le, MulZeroClass.mul_zero] exact max_le_max (le_refl 0) hi simp_rw [← cthickening_max_zero (r₁ _), ← cthickening_max_zero (r₂ _)] cases' le_or_lt 1 M with hM' hM' · apply HasSubset.Subset.eventuallyLE change _ ≤ _ refine' mono_blimsup' (hMr.mono fun i hi hp => cthickening_mono _ (s i)) exact (le_mul_of_one_le_left (hRp i) hM').trans hi · simp only [← @cthickening_closure _ _ _ (s _)] have hs : ∀ i, IsClosed (closure (s i)) := fun i => isClosed_closure exact blimsup_cthickening_ae_le_of_eventually_mul_le_aux μ p hs (tendsto_nhds_max_right hr) hRp hM hM' hMr #align blimsup_cthickening_ae_le_of_eventually_mul_le blimsup_cthickening_ae_le_of_eventually_mul_le /-- Given a sequence of subsets `sᵢ` of a metric space, together with a sequence of radii `rᵢ` such that `rᵢ → 0`, the set of points which belong to infinitely many of the closed `rᵢ`-thickenings of `sᵢ` is unchanged almost everywhere for a doubling measure if the `rᵢ` are all scaled by a positive constant. This lemma is a generalisation of Lemma 9 appearing on page 217 of [J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950). See also `blimsup_thickening_mul_ae_eq`. NB: The `set : α` type ascription is present because of issue #16932 on GitHub. -/ theorem blimsup_cthickening_mul_ae_eq (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M) (r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) : (blimsup (fun i => cthickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) := by have : ∀ (p : ℕ → Prop) {r : ℕ → ℝ} (hr : tendsto r at_top (𝓝[>] 0)), (blimsup (fun i => cthickening (M * r i) (s i)) at_top p : Set α) =ᵐ[μ] (blimsup (fun i => cthickening (r i) (s i)) at_top p : Set α) := by clear p hr r intro p r hr have hr' : tendsto (fun i => M * r i) at_top (𝓝[>] 0) := by convert tendsto_nhds_within_Ioi.const_mul hM hr <;> simp only [MulZeroClass.mul_zero] refine' eventually_le_antisymm_iff.mpr ⟨_, _⟩ · exact blimsup_cthickening_ae_le_of_eventually_mul_le μ p (inv_pos.mpr hM) hr' (eventually_of_forall fun i => by rw [inv_mul_cancel_left₀ hM.ne' (r i)]) · exact blimsup_cthickening_ae_le_of_eventually_mul_le μ p hM hr (eventually_of_forall fun i => le_refl _) let r' : ℕ → ℝ := fun i => if 0 < r i then r i else 1 / ((i : ℝ) + 1) have hr' : tendsto r' at_top (𝓝[>] 0) := by refine' tendsto_nhds_within_iff.mpr ⟨tendsto.if' hr tendsto_one_div_add_atTop_nhds_0_nat, eventually_of_forall fun i => _⟩ by_cases hi : 0 < r i · simp [hi, r'] · simp only [hi, r', one_div, mem_Ioi, if_false, inv_pos] positivity have h₀ : ∀ i, p i ∧ 0 < r i → cthickening (r i) (s i) = cthickening (r' i) (s i) := by rintro i ⟨-, hi⟩ congr change r i = ite (0 < r i) (r i) _ simp [hi] have h₁ : ∀ i, p i ∧ 0 < r i → cthickening (M * r i) (s i) = cthickening (M * r' i) (s i) := by rintro i ⟨-, hi⟩ simp only [hi, mul_ite, if_true] have h₂ : ∀ i, p i ∧ r i ≤ 0 → cthickening (M * r i) (s i) = cthickening (r i) (s i) := by rintro i ⟨-, hi⟩ have hi' : M * r i ≤ 0 := mul_nonpos_of_nonneg_of_nonpos hM.le hi rw [cthickening_of_nonpos hi, cthickening_of_nonpos hi'] have hp : p = fun i => p i ∧ 0 < r i ∨ p i ∧ r i ≤ 0 := by ext i simp [← and_or_left, lt_or_le 0 (r i)] rw [hp, blimsup_or_eq_sup, blimsup_or_eq_sup, sup_eq_union, blimsup_congr (eventually_of_forall h₀), blimsup_congr (eventually_of_forall h₁), blimsup_congr (eventually_of_forall h₂)] exact ae_eq_set_union (this (fun i => p i ∧ 0 < r i) hr') (ae_eq_refl _) #align blimsup_cthickening_mul_ae_eq blimsup_cthickening_mul_ae_eq theorem blimsup_cthickening_ae_eq_blimsup_thickening {p : ℕ → Prop} {s : ℕ → Set α} {r : ℕ → ℝ} (hr : Tendsto r atTop (𝓝 0)) (hr' : ∀ᶠ i in atTop, p i → 0 < r i) : (blimsup (fun i => cthickening (r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by refine' eventually_le_antisymm_iff.mpr ⟨_, HasSubset.Subset.eventuallyLE (_ : _ ≤ _)⟩ · rw [eventually_le_congr (blimsup_cthickening_mul_ae_eq μ p s (@one_half_pos ℝ _) r hr).symm eventually_eq.rfl] apply HasSubset.Subset.eventuallyLE change _ ≤ _ refine' mono_blimsup' (hr'.mono fun i hi pi => cthickening_subset_thickening' (hi pi) _ (s i)) nlinarith [hi pi] · exact mono_blimsup fun i pi => thickening_subset_cthickening _ _ #align blimsup_cthickening_ae_eq_blimsup_thickening blimsup_cthickening_ae_eq_blimsup_thickening /-- An auxiliary result en route to `blimsup_thickening_mul_ae_eq`. -/ theorem blimsup_thickening_mul_ae_eq_aux (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M) (r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) (hr' : ∀ᶠ i in atTop, p i → 0 < r i) : (blimsup (fun i => thickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by have h₁ := blimsup_cthickening_ae_eq_blimsup_thickening μ hr hr' have h₂ := blimsup_cthickening_mul_ae_eq μ p s hM r hr replace hr : tendsto (fun i => M * r i) at_top (𝓝 0); · convert hr.const_mul M simp replace hr' : ∀ᶠ i in at_top, p i → 0 < M * r i := hr'.mono fun i hi hip => mul_pos hM (hi hip) have h₃ := blimsup_cthickening_ae_eq_blimsup_thickening μ hr hr' exact h₃.symm.trans (h₂.trans h₁) #align blimsup_thickening_mul_ae_eq_aux blimsup_thickening_mul_ae_eq_aux /-- Given a sequence of subsets `sᵢ` of a metric space, together with a sequence of radii `rᵢ` such that `rᵢ → 0`, the set of points which belong to infinitely many of the `rᵢ`-thickenings of `sᵢ` is unchanged almost everywhere for a doubling measure if the `rᵢ` are all scaled by a positive constant. This lemma is a generalisation of Lemma 9 appearing on page 217 of [J.W.S. Cassels, *Some metrical theorems in Diophantine approximation. I*](cassels1950). See also `blimsup_cthickening_mul_ae_eq`. NB: The `set : α` type ascription is present because of issue #16932 on GitHub. -/ theorem blimsup_thickening_mul_ae_eq (p : ℕ → Prop) (s : ℕ → Set α) {M : ℝ} (hM : 0 < M) (r : ℕ → ℝ) (hr : Tendsto r atTop (𝓝 0)) : (blimsup (fun i => thickening (M * r i) (s i)) atTop p : Set α) =ᵐ[μ] (blimsup (fun i => thickening (r i) (s i)) atTop p : Set α) := by let q : ℕ → Prop := fun i => p i ∧ 0 < r i have h₁ : blimsup (fun i => thickening (r i) (s i)) at_top p = blimsup (fun i => thickening (r i) (s i)) at_top q := by refine' blimsup_congr' (eventually_of_forall fun i h => _) replace hi : 0 < r i · contrapose! h apply thickening_of_nonpos h simp only [hi, iff_self_and, imp_true_iff] have h₂ : blimsup (fun i => thickening (M * r i) (s i)) at_top p = blimsup (fun i => thickening (M * r i) (s i)) at_top q := by refine' blimsup_congr' (eventually_of_forall fun i h => _) replace h : 0 < r i · rw [← zero_lt_mul_left hM] contrapose! h apply thickening_of_nonpos h simp only [h, iff_self_and, imp_true_iff] rw [h₁, h₂] exact blimsup_thickening_mul_ae_eq_aux μ q s hM r hr (eventually_of_forall fun i hi => hi.2) #align blimsup_thickening_mul_ae_eq blimsup_thickening_mul_ae_eq
module GridIO import Effects import Effect.File import Grid %access public export LIFE_CHAR : Char LIFE_CHAR = 'o' readGrid : Int -> Int -> Eff Grid [FILE R] readGrid columnN rowN = do lines <- mapE (\_ => tryReadLine) [1 .. rowN] let numberedLines = zip lines (the (List Int) [0 .. (columnN - 1)]) pure $ foldl addLine (MkGrid 0 0 columnN rowN empty) numberedLines where tryReadLine : Eff String [FILE R] tryReadLine = do Result line <- readLine | FError _ => pure "" pure line addChar : Int -> Grid -> (Char, Int) -> Grid addChar row grid (c, column) = if c == 'o' then addLife (column, row) grid else grid addLine : Grid -> (String, Int) -> Grid addLine grid (line, row) = foldl (addChar row) grid $ zip (unpack line) (the (List Int) [0 .. (rowN - 1)]) writeGrid : Grid -> Eff () [FILE W] writeGrid grid = do Success <- writeString toString | FError _ => pure () pure () where coords : List (List (Int, Int)) coords = map (\row => map (\column => (column, row)) [0 .. (columnN grid - 1)]) [0 .. (rowN grid - 1)] lines : List String lines = map (\q => pack (map (\point => if containsLife point grid then 'o' else '.') q)) coords toString : String toString = unlines lines
function generate_animation(genp::GeneratorPyramid, α, β, amplifier, z_rec) z = build_zero_pyramid(z_rec, genp.noise_shapes) st = Base.length(genp.noise_shapes) z_rand = amplifier * randn_like(z_rec, size(z_rec)) z_prev1 = @. 0.95f0 * z_rec + 0.05f0 z_prev2 = z_rec for i in 1:100 z_rand = amplifier * randn_like(z_rec, size(z_rec)) diff_curr = @. β * (z_prev1 - z_prev2) + (1 - β) * z_rand z_curr = @. α * z_rec + (1 - α) * (z_prev1 + diff_curr) z_prev1 = z_curr z_prev2 = z_prev1 z[1] = z_curr img = genp(z, st, false) save_array_as_image(animation_savepath(i), view(img, :, :, :, 1)) end end
[STATEMENT] lemma rat_one_code [code abstract]: "quotient_of 1 = (1, 1)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. quotient_of 1 = (1, 1) [PROOF STEP] by (simp add: One_rat_def quotient_of_Fract normalize_def)
import data.fin namespace fin lemma lt_or_eq_nat {n : ℕ} (i : fin n.succ) : (i : ℕ) < n ∨ (i : ℕ) = n := begin cases nat.decidable_lt i n with h, { right, exact nat.eq_of_lt_succ_of_not_lt (fin.is_lt i) h, }, { left, exact h, } end lemma lt_coe_iff_val_lt {n m : ℕ} (i : fin n.succ) (hle : m < n.succ) : (i : ℕ) < m ↔ i < (m : fin n.succ) := begin rw fin.lt_def, repeat {rw fin.val_eq_coe}, rw fin.coe_coe_of_lt hle, end lemma lt_or_eq_fin {n : ℕ} (i : fin n.succ) : i < (n : fin n.succ) ∨ i = (n : fin n.succ) := begin cases fin.lt_or_eq_nat i with h, { left, rw ← fin.lt_coe_iff_val_lt i (nat.lt_succ_self _), exact h, }, { right, rw ← fin.coe_coe_eq_self i, have f := @congr_arg _ _ (i : ℕ) n fin.of_nat h, simp only [fin.of_nat_eq_coe] at f, exact f, } end /-- converts an n-ary tuple to an n.succ-ary tuple -/ @[simp] def x_val {A : Type*} {n} (x : A) (val : fin n → A) : fin n.succ → A := @fin.cases n (λ _, A) x (λ i, val i) end fin
module Control.Algebra infixl 6 <-> infixl 7 <.> public export interface Semigroup ty => SemigroupV ty where semigroupOpIsAssociative : (l, c, r : ty) -> l <+> (c <+> r) = (l <+> c) <+> r public export interface (Monoid ty, SemigroupV ty) => MonoidV ty where monoidNeutralIsNeutralL : (l : ty) -> l <+> neutral {ty} = l monoidNeutralIsNeutralR : (r : ty) -> neutral {ty} <+> r = r ||| Sets equipped with a single binary operation that is associative, ||| along with a neutral element for that binary operation and ||| inverses for all elements. Satisfies the following laws: ||| ||| + Associativity of `<+>`: ||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c ||| + Neutral for `<+>`: ||| forall a, a <+> neutral == a ||| forall a, neutral <+> a == a ||| + Inverse for `<+>`: ||| forall a, a <+> inverse a == neutral ||| forall a, inverse a <+> a == neutral public export interface MonoidV ty => Group ty where inverse : ty -> ty groupInverseIsInverseR : (r : ty) -> inverse r <+> r = neutral {ty} (<->) : Group ty => ty -> ty -> ty (<->) left right = left <+> (inverse right) ||| Sets equipped with a single binary operation that is associative ||| and commutative, along with a neutral element for that binary ||| operation and inverses for all elements. Satisfies the following ||| laws: ||| ||| + Associativity of `<+>`: ||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c ||| + Commutativity of `<+>`: ||| forall a b, a <+> b == b <+> a ||| + Neutral for `<+>`: ||| forall a, a <+> neutral == a ||| forall a, neutral <+> a == a ||| + Inverse for `<+>`: ||| forall a, a <+> inverse a == neutral ||| forall a, inverse a <+> a == neutral public export interface Group ty => AbelianGroup ty where groupOpIsCommutative : (l, r : ty) -> l <+> r = r <+> l ||| A homomorphism is a mapping that preserves group structure. public export interface (Group a, Group b) => GroupHomomorphism a b where to : a -> b toGroup : (x, y : a) -> to (x <+> y) = (to x) <+> (to y) ||| Sets equipped with two binary operations, one associative and ||| commutative supplied with a neutral element, and the other ||| associative, with distributivity laws relating the two operations. ||| Satisfies the following laws: ||| ||| + Associativity of `<+>`: ||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c ||| + Commutativity of `<+>`: ||| forall a b, a <+> b == b <+> a ||| + Neutral for `<+>`: ||| forall a, a <+> neutral == a ||| forall a, neutral <+> a == a ||| + Inverse for `<+>`: ||| forall a, a <+> inverse a == neutral ||| forall a, inverse a <+> a == neutral ||| + Associativity of `<.>`: ||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c ||| + Distributivity of `<.>` and `<+>`: ||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c) ||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c) public export interface Group ty => Ring ty where (<.>) : ty -> ty -> ty ringOpIsAssociative : (l, c, r : ty) -> l <.> (c <.> r) = (l <.> c) <.> r ringOpIsDistributiveL : (l, c, r : ty) -> l <.> (c <+> r) = (l <.> c) <+> (l <.> r) ringOpIsDistributiveR : (l, c, r : ty) -> (l <+> c) <.> r = (l <.> r) <+> (c <.> r) ||| Sets equipped with two binary operations, one associative and ||| commutative supplied with a neutral element, and the other ||| associative supplied with a neutral element, with distributivity ||| laws relating the two operations. Satisfies the following laws: ||| ||| + Associativity of `<+>`: ||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c ||| + Commutativity of `<+>`: ||| forall a b, a <+> b == b <+> a ||| + Neutral for `<+>`: ||| forall a, a <+> neutral == a ||| forall a, neutral <+> a == a ||| + Inverse for `<+>`: ||| forall a, a <+> inverse a == neutral ||| forall a, inverse a <+> a == neutral ||| + Associativity of `<.>`: ||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c ||| + Neutral for `<.>`: ||| forall a, a <.> unity == a ||| forall a, unity <.> a == a ||| + Distributivity of `<.>` and `<+>`: ||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c) ||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c) public export interface Ring ty => RingWithUnity ty where unity : ty unityIsRingIdL : (l : ty) -> l <.> unity = l unityIsRingIdR : (r : ty) -> unity <.> r = r ||| Sets equipped with two binary operations – both associative, ||| commutative and possessing a neutral element – and distributivity ||| laws relating the two operations. All elements except the additive ||| identity should have a multiplicative inverse. Should (but may ||| not) satisfy the following laws: ||| ||| + Associativity of `<+>`: ||| forall a b c, a <+> (b <+> c) == (a <+> b) <+> c ||| + Commutativity of `<+>`: ||| forall a b, a <+> b == b <+> a ||| + Neutral for `<+>`: ||| forall a, a <+> neutral == a ||| forall a, neutral <+> a == a ||| + Inverse for `<+>`: ||| forall a, a <+> inverse a == neutral ||| forall a, inverse a <+> a == neutral ||| + Associativity of `<.>`: ||| forall a b c, a <.> (b <.> c) == (a <.> b) <.> c ||| + Unity for `<.>`: ||| forall a, a <.> unity == a ||| forall a, unity <.> a == a ||| + InverseM of `<.>`, except for neutral ||| forall a /= neutral, a <.> inverseM a == unity ||| forall a /= neutral, inverseM a <.> a == unity ||| + Distributivity of `<.>` and `<+>`: ||| forall a b c, a <.> (b <+> c) == (a <.> b) <+> (a <.> c) ||| forall a b c, (a <+> b) <.> c == (a <.> c) <+> (b <.> c) public export interface RingWithUnity ty => Field ty where inverseM : (x : ty) -> Not (x = neutral {ty}) -> ty
Require Import Arith. Section strong_induction. Theorem induction1: forall P : nat -> Prop, (forall n : nat, (forall k : nat, (k < n -> P k)) -> (forall k : nat, (k <= n -> P k))) -> (forall n : nat, (forall k : nat, (k <= n -> P k))). Proof. induction n. intro. apply H. intro. intro. unfold lt in H0. inversion H0. apply H. intro. intro. apply IHn. unfold lt in H0. apply le_S_n in H0. assumption. Qed. Theorem strong_induction: forall P : nat -> Prop, (forall n : nat, (forall k : nat, (k < n -> P k)) -> P n) -> (forall n : nat, P n). Proof. intro. intro. assert ( forall n:nat, (forall k:nat, k < n -> P k) -> (forall k:nat, k <= n -> P k) ). intro. intro. intro. intro. inversion H1. apply H. assumption. apply H0. rewrite <- H3. unfold lt. apply le_n_S. assumption. assert( forall n : nat, (forall k : nat, (k <= n -> P k)) ). apply induction1. assumption. intro. assert (forall k:nat, k <= n -> P k). apply H1. apply H2. constructor. Qed.
{-# LANGUAGE TypeOperators #-} {-# LANGUAGE BangPatterns #-} module Lib ( trilinear , resample , affine , array_correlation , fisher_transform , naive_12p_registration ) where import Data.Array.Repa import qualified Data.Array.Repa as Repa import Data.Array.Repa.Algorithms.Matrix import Statistics.Sample import Data.Array.Repa.Repr.Unboxed type DIM3D = (Z :. Double :. Double :. Double) trilinear :: (Unbox a, Floating a, Fractional a) => Array U DIM3 a -> DIM3D -> a trilinear !arr !(Z :. x :. y :. z) = let x0 = floor x x1 = ceiling x :: Int y0 = floor y y1 = ceiling y :: Int z0 = floor z z1 = ceiling z :: Int in let v000 = arr ! (Z :. x0 :. y0 :. z0) v100 = arr ! (Z :. x1 :. y0 :. z0) v010 = arr ! (Z :. x0 :. y1 :. z0) v110 = arr ! (Z :. x1 :. y1 :. z0) v001 = arr ! (Z :. x0 :. y0 :. z1) v101 = arr ! (Z :. x1 :. y0 :. y1) v011 = arr ! (Z :. x0 :. y1 :. y1) v111 = arr ! (Z :. x1 :. y1 :. y1) xd = if x0 /= x1 then ((fromIntegral x0) - (realToFrac x)) / (fromIntegral (x0 - x1)) else 0 yd = if y0 /= y1 then ((fromIntegral y0) - (realToFrac y)) / (fromIntegral (y0 - y1)) else 0 zd = if z0 /= z1 then ((fromIntegral z0) - realToFrac z) / (fromIntegral (z0 - z1)) else 0 in let c00 = v000 * (1 - xd) + v100 * xd c01 = v001 * (1 - xd) + v101 * xd c10 = v010 * (1 - xd) + v110 * xd c11 = v011 * (1 - xd) + v111 * xd in let c0 = c00 * (1 - yd) + c10 * yd c1 = c01 * (1 - yd) + c11 * yd in c0 * (1 - zd) + c1 * zd resample :: (Floating a, Floating b, Unbox a, Unbox b, Fractional a, Fractional b) => Array U DIM3 a -> (DIM3 -> DIM3D) -> --fun from coordinate system to coordinate system (Array U DIM3 a -> DIM3D -> b) -> --interpolator Array D DIM3 b resample !arr !xfm !interp = Repa.traverse arr id xfm_and_interp where xfm_and_interp = \_ d -> ((interp arr (xfm d))) affine :: (Unbox a, Floating a, Fractional a, Real a) => DIM3 -> Array U DIM2 a -> DIM3D affine !(Z :. x :. y :. z) !xfm = (Z :. x' :. y' :. z') where [x',y',z',_] = (toList (mmultS (computeS $ Repa.map realToFrac xfm) pnt_array)) where pnt_array = (fromListUnboxed (Z :. (3 :: Int) :. (1 :: Int)) (fmap fromIntegral [x,y,z])) -- :: Array U DIM2 Double array_correlation :: (Unbox a, Real a, Fractional a) => Array U DIM3 a -> Array U DIM3 a -> a array_correlation !arr1 !arr2 = realToFrac (correlation (toUnboxed (computeS (Repa.zipWith coerce_and_tuple arr1 arr2)))) where coerce_and_tuple x y = (realToFrac x, realToFrac y) fisher_transform = atanh -- Test code naive_12p_registration :: (Unbox a, Floating a, Fractional a, Real a) => Array U DIM3 a -> [a] -> a naive_12p_registration !arr !params = array_correlation arr (computeS $ resample arr (flip affine xfm) trilinear) where xfm = fromListUnboxed (Z :. 4 :. 4) params
module lib.Library export salute : String salute = "Hello, library example of idris"
(* Title: HOL/Proofs/Extraction/Pigeonhole.thy Author: Stefan Berghofer, TU Muenchen *) section \<open>The pigeonhole principle\<close> theory Pigeonhole imports Util "HOL-Library.Realizers" "HOL-Library.Code_Target_Numeral" begin text \<open> We formalize two proofs of the pigeonhole principle, which lead to extracted programs of quite different complexity. The original formalization of these proofs in {\sc Nuprl} is due to Aleksey Nogin @{cite "Nogin-ENTCS-2000"}. This proof yields a polynomial program. \<close> theorem pigeonhole: "\<And>f. (\<And>i. i \<le> Suc n \<Longrightarrow> f i \<le> n) \<Longrightarrow> \<exists>i j. i \<le> Suc n \<and> j < i \<and> f i = f j" proof (induct n) case 0 then have "Suc 0 \<le> Suc 0 \<and> 0 < Suc 0 \<and> f (Suc 0) = f 0" by simp then show ?case by iprover next case (Suc n) have r: "k \<le> Suc (Suc n) \<Longrightarrow> (\<And>i j. Suc k \<le> i \<Longrightarrow> i \<le> Suc (Suc n) \<Longrightarrow> j < i \<Longrightarrow> f i \<noteq> f j) \<Longrightarrow> (\<exists>i j. i \<le> k \<and> j < i \<and> f i = f j)" for k proof (induct k) case 0 let ?f = "\<lambda>i. if f i = Suc n then f (Suc (Suc n)) else f i" have "\<not> (\<exists>i j. i \<le> Suc n \<and> j < i \<and> ?f i = ?f j)" proof assume "\<exists>i j. i \<le> Suc n \<and> j < i \<and> ?f i = ?f j" then obtain i j where i: "i \<le> Suc n" and j: "j < i" and f: "?f i = ?f j" by iprover from j have i_nz: "Suc 0 \<le> i" by simp from i have iSSn: "i \<le> Suc (Suc n)" by simp have S0SSn: "Suc 0 \<le> Suc (Suc n)" by simp show False proof cases assume fi: "f i = Suc n" show False proof cases assume fj: "f j = Suc n" from i_nz and iSSn and j have "f i \<noteq> f j" by (rule 0) moreover from fi have "f i = f j" by (simp add: fj [symmetric]) ultimately show ?thesis .. next from i and j have "j < Suc (Suc n)" by simp with S0SSn and le_refl have "f (Suc (Suc n)) \<noteq> f j" by (rule 0) moreover assume "f j \<noteq> Suc n" with fi and f have "f (Suc (Suc n)) = f j" by simp ultimately show False .. qed next assume fi: "f i \<noteq> Suc n" show False proof cases from i have "i < Suc (Suc n)" by simp with S0SSn and le_refl have "f (Suc (Suc n)) \<noteq> f i" by (rule 0) moreover assume "f j = Suc n" with fi and f have "f (Suc (Suc n)) = f i" by simp ultimately show False .. next from i_nz and iSSn and j have "f i \<noteq> f j" by (rule 0) moreover assume "f j \<noteq> Suc n" with fi and f have "f i = f j" by simp ultimately show False .. qed qed qed moreover have "?f i \<le> n" if "i \<le> Suc n" for i proof - from that have i: "i < Suc (Suc n)" by simp have "f (Suc (Suc n)) \<noteq> f i" by (rule 0) (simp_all add: i) moreover have "f (Suc (Suc n)) \<le> Suc n" by (rule Suc) simp moreover from i have "i \<le> Suc (Suc n)" by simp then have "f i \<le> Suc n" by (rule Suc) ultimately show ?thesis by simp qed then have "\<exists>i j. i \<le> Suc n \<and> j < i \<and> ?f i = ?f j" by (rule Suc) ultimately show ?case .. next case (Suc k) from search [OF nat_eq_dec] show ?case proof assume "\<exists>j<Suc k. f (Suc k) = f j" then show ?case by (iprover intro: le_refl) next assume nex: "\<not> (\<exists>j<Suc k. f (Suc k) = f j)" have "\<exists>i j. i \<le> k \<and> j < i \<and> f i = f j" proof (rule Suc) from Suc show "k \<le> Suc (Suc n)" by simp fix i j assume k: "Suc k \<le> i" and i: "i \<le> Suc (Suc n)" and j: "j < i" show "f i \<noteq> f j" proof cases assume eq: "i = Suc k" show ?thesis proof assume "f i = f j" then have "f (Suc k) = f j" by (simp add: eq) with nex and j and eq show False by iprover qed next assume "i \<noteq> Suc k" with k have "Suc (Suc k) \<le> i" by simp then show ?thesis using i and j by (rule Suc) qed qed then show ?thesis by (iprover intro: le_SucI) qed qed show ?case by (rule r) simp_all qed text \<open> The following proof, although quite elegant from a mathematical point of view, leads to an exponential program: \<close> theorem pigeonhole_slow: "\<And>f. (\<And>i. i \<le> Suc n \<Longrightarrow> f i \<le> n) \<Longrightarrow> \<exists>i j. i \<le> Suc n \<and> j < i \<and> f i = f j" proof (induct n) case 0 have "Suc 0 \<le> Suc 0" .. moreover have "0 < Suc 0" .. moreover from 0 have "f (Suc 0) = f 0" by simp ultimately show ?case by iprover next case (Suc n) from search [OF nat_eq_dec] show ?case proof assume "\<exists>j < Suc (Suc n). f (Suc (Suc n)) = f j" then show ?case by (iprover intro: le_refl) next assume "\<not> (\<exists>j < Suc (Suc n). f (Suc (Suc n)) = f j)" then have nex: "\<forall>j < Suc (Suc n). f (Suc (Suc n)) \<noteq> f j" by iprover let ?f = "\<lambda>i. if f i = Suc n then f (Suc (Suc n)) else f i" have "\<And>i. i \<le> Suc n \<Longrightarrow> ?f i \<le> n" proof - fix i assume i: "i \<le> Suc n" show "?thesis i" proof (cases "f i = Suc n") case True from i and nex have "f (Suc (Suc n)) \<noteq> f i" by simp with True have "f (Suc (Suc n)) \<noteq> Suc n" by simp moreover from Suc have "f (Suc (Suc n)) \<le> Suc n" by simp ultimately have "f (Suc (Suc n)) \<le> n" by simp with True show ?thesis by simp next case False from Suc and i have "f i \<le> Suc n" by simp with False show ?thesis by simp qed qed then have "\<exists>i j. i \<le> Suc n \<and> j < i \<and> ?f i = ?f j" by (rule Suc) then obtain i j where i: "i \<le> Suc n" and ji: "j < i" and f: "?f i = ?f j" by iprover have "f i = f j" proof (cases "f i = Suc n") case True show ?thesis proof (cases "f j = Suc n") assume "f j = Suc n" with True show ?thesis by simp next assume "f j \<noteq> Suc n" moreover from i ji nex have "f (Suc (Suc n)) \<noteq> f j" by simp ultimately show ?thesis using True f by simp qed next case False show ?thesis proof (cases "f j = Suc n") assume "f j = Suc n" moreover from i nex have "f (Suc (Suc n)) \<noteq> f i" by simp ultimately show ?thesis using False f by simp next assume "f j \<noteq> Suc n" with False f show ?thesis by simp qed qed moreover from i have "i \<le> Suc (Suc n)" by simp ultimately show ?thesis using ji by iprover qed qed extract pigeonhole pigeonhole_slow text \<open> The programs extracted from the above proofs look as follows: @{thm [display] pigeonhole_def} @{thm [display] pigeonhole_slow_def} The program for searching for an element in an array is @{thm [display,eta_contract=false] search_def} The correctness statement for \<^term>\<open>pigeonhole\<close> is @{thm [display] pigeonhole_correctness [no_vars]} In order to analyze the speed of the above programs, we generate ML code from them. \<close> instantiation nat :: default begin definition "default = (0::nat)" instance .. end instantiation prod :: (default, default) default begin definition "default = (default, default)" instance .. end definition "test n u = pigeonhole (nat_of_integer n) (\<lambda>m. m - 1)" definition "test' n u = pigeonhole_slow (nat_of_integer n) (\<lambda>m. m - 1)" definition "test'' u = pigeonhole 8 (List.nth [0, 1, 2, 3, 4, 5, 6, 3, 7, 8])" ML_val "timeit (@{code test} 10)" ML_val "timeit (@{code test'} 10)" ML_val "timeit (@{code test} 20)" ML_val "timeit (@{code test'} 20)" ML_val "timeit (@{code test} 25)" ML_val "timeit (@{code test'} 25)" ML_val "timeit (@{code test} 500)" ML_val "timeit @{code test''}" end
theory P08 imports Main begin fun p08 :: "'a list \<Rightarrow> 'a list" where "p08 [] = []"| "p08 [x] = [x]"| "p08 (x#y#xs) = (if x= y then p08 (y#xs) else x # p08 (y#xs))" lemma "length (p08 ls) \<le> length ls" using [[simp_trace_new mode=full]] proof (induct ls) case Nil then show ?case by simp next case (Cons a ls) assume a:"length (p08 ls) \<le> length ls" show ?case proof (cases ls) case Nil assume "ls = []" then show ?thesis by simp next case (Cons aa list) assume b:"ls = aa # list" with a show ?thesis by simp qed qed lemma "x \<in> \<nat> \<Longrightarrow> x < length ls - 1 \<Longrightarrow> ls ! x = ls ! (x+1) \<Longrightarrow> length ls \<ge> 2 \<Longrightarrow> length (p08 ls) < length ls" proof (cases ls rule : p08.cases) case 1 then show ?thesis next case (2 x) then show ?thesis sorry next case (3 x y xs) then show ?thesis sorry qed lemma "x \<in> \<nat> \<Longrightarrow> x < length ls - 1 \<Longrightarrow> ls ! x = ls ! (x+1) \<Longrightarrow> length ls \<ge> 2 \<Longrightarrow> length (p08 ls) < length ls" proof (induct ls) case Nil then show ?case by simp next case (Cons a ls) assume a:"x \<in> \<nat> \<Longrightarrow> x < length ls - 1 \<Longrightarrow> ls ! x = ls ! (x + 1) \<Longrightarrow> 2 \<le> length ls \<Longrightarrow> length (p08 ls) < length ls" assume b:"x \<in> \<nat>" assume c:"x < length (a # ls) - 1" assume d:"(a # ls) ! x = (a # ls) ! (x + 1)" assume e:"2 \<le> length (a # ls)" show ?case proof (cases ls) case Nil with e show ?thesis by simp next case (Cons aa list) assume f:"ls = aa # list" show ?thesis proof (cases "aa = a") case True with f show ?thesis next case False then show ?thesis sorry qed qed qed lemma "\<not>(\<exists>x. )"
% % NAME: mrAlign (ver 3) % AUTHOR: DJH % DATE: 8/2001 % PURPOSE: % Main routine for menu driven matlab program to view and analyze % volumes of anatomical and functional MRI data. % HISTORY: % Dozens of people contributed to the original mrAlign. It was written % using scripts in matlab 4 without any data structures. This is an % attempt to make a fresh start. % disp('mrAlign (version 3)'); % Global Variables global HOMEDIR HOMEDIR = pwd; % Matlab controls for menu driven program global volinc voldec global volslislice volslimin1 volslimax1 volslimin2 volslimax2 volslicut global interpflag global volcmap % Color map global checkAutoRotFlag % Flag whether auto rotation has been checked % Windows global sagwin obwin joywin navigwin % Number of Sagittal slices global numSlices % Local Variables volselpts = []; % Selected region in volume. rvolselpts = []; inpts = []; % list of alignment points in inplane volpts = []; % corresponding points in volume obX = [0,0]; % Coordinates of sagittal and oblique slices obY = [0,0]; obXM = []; % Coordinates of user set inplane slices obYM = []; lp = []; % pointers to the inplane lines we draw ipThickness = -99; % inplanes thickness (mm) ipSkip = -99; % amount of space skipped between inplane (mm) curSag = -99; % sagittal slice currently displaying reflections = [1,1]; % Keeps track up left/right, up/down flips done by user sagX = [0,0]; sagY = [0,0]; obMin = 0; obMax = 0; sagMin = 0; sagMax = 500; numSlices = 124; % Number of planes of volume anatomy obslice = []; sagwin = []; % Figure with sagittal view obwin = []; % Figure with oblique view sagSlice = []; % Current sagittal image sagPts = []; % Samples for the current sagittal slice. sagSize = []; % Current sagittal size sagCrop = []; % Sagittal crop region volume = []; % Volume of data obPts = []; % Locations in volume of oblique slice obSlice = []; % Current oblique image obSize = []; % Size of oblique image obSizeOrig = []; % real size of oblique, used for point selection %%%%%%%%%%%% global constants and variable inits for rotation %%%%%%%%%%% global axial coronal axial = 1; coronal = 2; % used to identify axis of rotation cTheta = 0; % default rotation angles aTheta = 0; sagDelta = 0.03; % angle delta in radians sagDeltaMin = 0.003; sagDeltaMax = 0.06; transDelta = 10; % trans delta in mm transDeltaMin = 0; transDeltaMax = 20; aThetaSave = 0; cThetaSave = 0; curInplane = 0; inpRotDelta = 20; % inplane grid rotation increment (deg) inpRotDeltaMin = .5; inpRotDeltaMax = 35; inOutDelta = 5; % in/out translation in mm inOutDeltaMin = 0; inOutDeltaMax = 20; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % mrLoadRet stuff % The goal here is to make mrAlign a standalone program so that you don't % need to be running mrLoadRet. This stuff needs to be set up to allow % mrAlign to run on its own. global mrSESSION dataTYPES vANATOMYPATH load mrSESSION subject = mrSESSION.subject; vAnatPath = getVAnatomyPath(subject) numofanats = mrSESSION.inplanes.nSlices; curSize = mrSESSION.inplanes.cropSize; anatsz = [curSize,numofanats]; inplane_pix_size = 1./mrSESSION.inplanes.voxelSize; % open inplane window global INPLANE openInplaneWindowForAlign3; set(gcf, 'MenuBar', 'figure'); retwin = INPLANE.ui.figNum; %mrLoadRet window INPLANE = loadAnat(INPLANE); INPLANE = refreshView(INPLANE); set(gcf,'Units','Normalized','Position',[.5 .05 .45 .45]); % open screen save window if (~exist('Raw/Anatomy/SS','dir')) disp('No SS found'); sswin=0; else openSSWindow; sswin = gcf; set(sswin,'Units','Normalized','Position',[.5 .05 .45 .45]); end try openSSWindow; sswin = gcf; set(sswin,'Units','Normalized','Position',[.5 .05 .45 .45]); catch disp('Couldn''t find Screen Save, so no SS Window') sswin = []; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% volcmap = gray(110); % Set up color map volcmap = [volcmap;hsv(110)]; % Sagittal window sagwin = figure('MenuBar','none'); set(sagwin,'Units','Normalized','Position',[.05 .5 .45 .45]); colormap(volcmap); % Interpolated Oblique window obwin = figure('MenuBar','none'); set(obwin,'Units','Normalized','Position',[.5 .5 .45 .45]); colormap(volcmap); % Navigation window joywin = figure('MenuBar','none'); set(joywin,'Position', [0, 100, 650, 170]); colormap(volcmap); set(retwin, 'Name', 'Inplane'); if (sswin) set(sswin, 'Name', 'Screen Save'); end set(sagwin, 'Name', 'Interpolated Screen Save'); set(obwin, 'Name', 'Interpolated Inplane'); set(joywin, 'Name', 'Navigation Control'); % Make sagwin active. figure(sagwin); %%%%% Sagittal Buttons %%%%% % These are the arrows for moving from one sagittal to another % Rightward one step volinc = uicontrol('Style','pushbutton','String','->','Units','normalized','Position',[.9,.95,.1,.05],'Callback','curSag=curSag+1;[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); % Leftward one step voldec = uicontrol('Style','pushbutton','String','<-','Units','normalized','Position',[.8,.95,.1,.05],'Callback','curSag=curSag-1;[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); % Slider for moving across sagittals faster by dragging volslislice = uicontrol('Style','slider','String','Pos','Units','normalized','Position',[.6,.95,.1,.05],'Callback','curSag=ceil(numSlices*get(volslislice,''value''));[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); % Contrast controls % Choose the max value set to highest display intensity volslimax1 = uicontrol('Style','slider','String','Max','Units',... 'normalized','Position',[.9,.6,.1,.05],'Callback',... 'myShowImageVol(sagSlice,sagSize,max(sagSlice)*get(volslimin1,''value''),max(sagSlice)*get(volslimax1,''value''),obX,obY)'); % Choose the min value set to lowest display intensity volslimin1 = uicontrol('Style','slider','String','Min','Units',... 'normalized','Position',[.9,.4,.1,.05],'Callback',... 'myShowImageVol(sagSlice,sagSize,max(sagSlice)*get(volslimin1,''value''),max(sagSlice)*get(volslimax1,''value''),obX,obY)'); set(volslimin1,'value',0); set(volslimax1,'value',.50); %%%%% Sagittal File Menu %%%%% ld = uimenu('Label','File','separator','on'); % Reload volume anatomy data set. uimenu(ld,'Label','Load Volume Anatomy','CallBack', ... '[volume,mmPerPix,volSize] = readVolAnat(vAnatPath); sagSize = volSize(1:2); numSlices = volSize(3); curSag = floor(numSlices/2); sagSlice = mrShowSagVol(volume,sagSize,curSag,[]);',... 'Separator','off'); % Load AlignParams uimenu(ld,'Label','(Re-)Load AlignParams','CallBack',... 'load AlignParams;[obX,obY,obSize,obSizeOrig,sagPts,sagSlice,lp,obPts,obSlice]=mrReloadParams(lp,curInplane,obXM,obYM,sagSize,numSlices,volume,cTheta,aTheta,curSag,reflections,scaleFac);',... 'Separator','on'); % Save AlignParams uimenu(ld,'Label','Save AlignParams','CallBack',... 'aThetaSave= aTheta; cThetaSave=cTheta;mrSaveAlignParams(obXM,obYM,subject,inplane_pix_size,ipThickness,ipSkip,curSag,curInplane,aTheta,cTheta)',... 'Separator','on'); % Load alignment uimenu(ld,'Label','Load Alignment (bestrotvol)','CallBack',... 'eval(sprintf(''load bestrotvol''));disp(''Loaded: bestrotvol.mat'');',... 'Separator','on'); % Save alignment uimenu(ld,'Label','Save Alignment (bestrotvol)','CallBack',... 'eval(sprintf(''save bestrotvol inpts volpts trans rot scaleFac''));disp(''Saved: bestrotvol.mat'');',... 'Separator','on'); % Quit uimenu(ld,'Label','Quit','CallBack', ... 'close all; clear all;',... 'Separator','on'); %%%%% Sagittal Inplanes Menu %%%%% ld = uimenu('Label','Inplanes','separator','on'); % Create of the set of inplane lines initially uimenu(ld,'Label','Setup/Refresh Inplanes','CallBack',... '[obX,obY,obXM,obYM,lp,ipThickness,ipSkip] =mrSetupInplanes(numofanats,obXM,obYM,lp,ipThickness,ipSkip,volume_pix_size,inplane_pix_size,curInplane);','Separator','on'); % Translate inplanes uimenu(ld,'Label','Translate Inplanes','CallBack',... '[obX,obY,obXM,obYM,lp] = mrTransInplanes(numofanats,obXM,obYM,lp,curInplane);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);','Separator','on'); % Rotate inplanes uimenu(ld,'Label','Clip Inplanes','CallBack', ... '[obX,obY,obXM,obYM,lp] = mrClipInplanes(numofanats,obXM,obYM,lp,curInplane); [obSize,obSizeOrig] = mrFindObSize(obX,obY,sagSize,numSlices,curInplane);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);','Separator','on'); % Select inplane uimenu(ld,'Label','Select Inplane','CallBack',... ['[obX,obY,lp,curInplane]=mrSelInplane(numofanats,obXM,obYM,lp,curInplane);[obSize,obSizeOrig] = mrFindObSize(obX,obY,sagSize,numSlices,curInplane);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'... 'INPLANE = viewSet(INPLANE, ''Current Slice'',curInplane);refreshView(INPLANE);'],'Accelerator','S','Separator','on'); %%%%% Sagittal Alignment Menu %%%%% ld = uimenu('Label','Alignment','separator','on'); uimenu(ld,'Label','Compute Alignment from Many Points','CallBack', ... '[trans,rot]=mrDoAlignVol(inpts,volpts,scaleFac,curSize,sagSize,volume,numSlices,retwin,sagwin,obwin);','Separator','on'); uimenu(ld,'Label','Compute Alignment Automatically','CallBack', ... 'NCoarseIter = 4; Usebestrotvol = 0; regEstRot;', 'separator', 'on'); uimenu(ld,'Label','Compute Alignment Automatically (use bestrotvol.mat as starting point)','CallBack', ... 'NCoarseIter = 4; Usebestrotvol = 1; regEstRot;', 'separator', 'on'); % ON - in this case, if the alignment in bestrotvol is good, I guess that the % coarse iterations can be eliminated. For now, and for safety, I leave % it to be 4 (if bestrotvol is a previous manual alignment, then it will be % good. But if it is a copy of an alignment computed for data acquired using % the same slice prescription, it might be not good enough to eliminate % the coarse iterations). uimenu(ld,'Label','Check Alignment (current slice)','CallBack', ... 'chkImg = mrCheckAlignVol(rot,trans,scaleFac,curSize,viewGet(INPLANE, ''Current Slice''),volume,sagSize,numSlices,obwin);','Separator','on'); uimenu(ld,'Label','Check Alignment (all slices)',... 'CallBack','regCheckRotAll', 'separator', 'on'); uimenu(ld,'Label','Check Alignment (overlay)',... 'CallBack','OverlayRegCheck;', 'separator', 'on'); %%%%% Oblique Buttons %%%%% figure(obwin); %Select Points button uicontrol('style','pushbutton','string','Select Points','units','normalized',... 'Position',[0.0,.95,.2,.05],'CallBack',... '[inpts,volpts]=mrSelectPoints(inpts,volpts,retwin,obwin,viewGet(INPLANE, ''Current Slice''),obPts,obSizeOrig,reflections);'); %Undo Last Point button uicontrol('style','pushbutton','string','Undo Last Point','units','normalized',... 'Position',[.26,.95,.2,.05],'CallBack', ... '[inpts,volpts]=mrUndoAPoint(inpts,volpts);'); %Clear all points button uicontrol('style','pushbutton','string','Clear All Points','units','normalized',... 'Position',[.53,.95,.2,.05],'CallBack', ... '[inpts,volpts]=mrClearPoints(inpts,volpts);'); %Flip image left/right uicontrol('style','pushbutton','string','Flip Right/Left','units','normalized',... 'Position',[.26,.0,.2,.05],'CallBack', '[obSlice,reflections] = mrReflectObl(obSlice,obSize,reflections,1,1);'); %Flip image up/down uicontrol('style','pushbutton','string','Flip Up/Down','units','normalized',... 'Position',[.53,.0,.2,.05],'CallBack', '[obSlice,reflections] = mrReflectObl(obSlice,obSize,reflections,2,1);'); % Contrast controls volslimax2 = uicontrol('Style','slider','String','Max','Units',... 'normalized','Position',[.9,.6,.1,.05],'Callback',... 'myShowImageVol(obSlice,obSize,max(obSlice)*get(volslimin2,''value''),max(obSlice)*get(volslimax2,''value''),sagX,sagY)'); volslimin2 = uicontrol('Style','slider','String','Min','Units',... 'normalized','Position',[.9,.4,.1,.05],'Callback',... 'myShowImageVol(obSlice,obSize,max(obSlice)*get(volslimin2,''value''),max(obSlice)*get(volslimax2,''value''),sagX,sagY)'); set(volslimin2,'value',.15); set(volslimax2,'value',.90); %%%%%%%%%%% Joystick Control Buttons %%%%%%%%%%%% figure(joywin); %%% Sagittal rotation %%% uicontrol('Style','Text','Position',[42,140,90,14],'String','Sagittal rotation'); uicontrol('Style','pushbutton','String','<--','Position',[25,65,45,20],'CallBack', '[sagSlice,sagPts,cTheta,aTheta,obSlice,obPts]=mrRotSagVol2(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,axial,sagDelta,curSag,reflections,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','-->','Position',[100,65,45,20],'CallBack', '[sagSlice,sagPts,cTheta,aTheta,obSlice,obPts]=mrRotSagVol2(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,axial,-sagDelta,curSag,reflections,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','^','Position',[75,90,20,45],'CallBack', '[sagSlice,sagPts,cTheta,aTheta,obSlice,obPts]=mrRotSagVol2(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,coronal,sagDelta,curSag,reflections,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','v','Position',[75,15,20,45],'CallBack', '[sagSlice,sagPts,cTheta,aTheta,obSlice,obPts]=mrRotSagVol2(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,coronal,-sagDelta,curSag,reflections,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','0,0','Position',[75,65,20,20],'CallBack','aTheta=0;cTheta=0;[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); sagDeltaslider = uicontrol('Style','slider','Position',[120,100,80,20],... 'Min',sagDeltaMin,'Max',sagDeltaMax,'Value',sagDelta,... 'Callback','sagDelta=get(sagDeltaslider,''value'');'); %%% Translation %%% uicontrol('Style','Text','Position',[230,140,60,14],'String','Translation'); uicontrol('Style','pushbutton','String','<--','Position',[200,65,45,20],'CallBack', '[obX,obY,obXM,obYM,lp] = mrTransByButton(numofanats,obXM,obYM,lp,curInplane,transDelta,1);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','-->','Position',[275,65,45,20],'CallBack', '[obX,obY,obXM,obYM,lp] = mrTransByButton(numofanats,obXM,obYM,lp,curInplane,transDelta,2);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','^','Position',[250,90,20,45],'CallBack','[obX,obY,obXM,obYM,lp] = mrTransByButton(numofanats,obXM,obYM,lp,curInplane,transDelta,3);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);' ); uicontrol('Style','pushbutton','String','v','Position',[250,15,20,45],'CallBack','[obX,obY,obXM,obYM,lp] = mrTransByButton(numofanats,obXM,obYM,lp,curInplane,transDelta,4);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); transDeltaslider = uicontrol('Style','slider','Position',[295,100,80,20],... 'Min',transDeltaMin,'Max',transDeltaMax,'Value',transDelta,... 'Callback','transDelta=get(transDeltaslider,''value'');'); %%% Rotation %%% uicontrol('Style','Text','Position',[405,140,60,14],'String','Rotation'); uicontrol('Style','pushbutton','String','<--','Position',[375,65,45,20],'CallBack','[obXM,obYM]=mrRotInplanes(numofanats,obXM,obYM,(-1*inpRotDelta),curInplane);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','-->','Position',[450,65,45,20],'CallBack','[obXM,obYM] = mrRotInplanes(numofanats,obXM,obYM,inpRotDelta,curInplane);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); inpRotDeltaslider = uicontrol('Style','slider','Position',[415,100,80,20],... 'Min',inpRotDeltaMin,'Max',inpRotDeltaMax,'Value', inpRotDelta,... 'Callback','inpRotDelta=get(inpRotDeltaslider,''Value'');'); %%% In/out translation %%% uicontrol('Style','Text','Position',[550,140,90,14],'String','In/Out'); uicontrol('Style','pushbutton','String','Out','Position',[525,65,45,20],'CallBack', '[obX,obY,obXM,obYM,lp] = mrPerpTransByButton(numofanats,obXM,obYM,lp,curInplane,inOutDelta,1);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); uicontrol('Style','pushbutton','String','In','Position',[600,65,45,20],'CallBack', '[obX,obY,obXM,obYM,lp] = mrPerpTransByButton(numofanats,obXM,obYM,lp,curInplane,inOutDelta,-1);[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane);lp = mrRefreshInplanes(lp,obXM,obYM,curInplane,0);'); inOutDeltaslider = uicontrol('Style','slider','Position',[525,100,122,20],... 'Min',inOutDeltaMin,'Max',inOutDeltaMax,'Value', inOutDelta,... 'Callback','inOutDelta=get(inOutDeltaslider,''Value'');disp([''inOutDelta: '' num2str(inOutDelta)]);'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%% Matlab executes code from here to end, exits, then stays resident %%%%%%% % Re-worked the logic of obtaining critical parameters -- 07.23.97 SPG,ABP % AlignParams.mat doesn't exist %Check if 'AlignParams' exist. %If not, then create 'AlignParams'. if ~check4File('AlignParams') mrSaveAlignParams(obXM,obYM,subject,... inplane_pix_size,... ipThickness,ipSkip,curSag,curInplane,aTheta,cTheta); end % Load AlignParams mrLoadAlignParams; %Load in the volume anatomy and display it sagwin [volume,mmPerPix,volSize] = readVolAnat(vAnatPath); sagSize = volSize(1:2); numSlices = volSize(3); %[volume, sagSize, numSlices, calc, dataRange] = mrLoadVAnatomy(voldr,subject); % Get the volume pixel size here. volume_pix_size = 1./mmPerPix; %[volume_pix_size] = mrGetVolPixSize(voldr,subject); %compile the scale factors for inplane and volume anatomies scaleFac = [inplane_pix_size;volume_pix_size]; % First time through this will not be a parameter in VolParams.mat if curSag < 0 curSag = floor(numSlices/2); end figure(sagwin); sagSlice = mrShowSagVol(volume,sagSize,curSag,[]); %[sagSlice,sagPts,obSlice,obPts]=mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane); interpflag = 1; % global required to do 3dlinearinterp % If the user has an inplane that is selected, display it. if (curInplane ~=0) % draw the inplanes [obX,obY,obXM,obYM,lp,ipThickness,ipSkip] = mrSetupInplanes(numofanats,obXM,obYM,lp,ipThickness,ipSkip,volume_pix_size,inplane_pix_size,curInplane); % interpolated image size [obSize,obSizeOrig] = mrFindObSize(obX,obY,sagSize,numSlices,curInplane); % draw it [sagSlice,sagPts,obSlice,obPts] = mrRotSagVol(volume,obXM,obYM,obSize,sagSize,cTheta,aTheta,curSag,reflections,1,1/scaleFac(1,3),curInplane); end
import data.fin import tactic -- This does exist in mathlib lemma fin_zero_le_any_val (n : ℕ) : ∀ i : fin (n + 2), 0 ≤ i := begin intro i, have j0 : 0 < n + 1 + 1, linarith, have j0 := @fin.coe_val_of_lt (n+1) 0 j0, have h3 : 0 ≤ i.val, linarith, apply fin.le_iff_val_le_val.mpr, rw ← j0 at h3, exact h3, end lemma fin_zero_le_any_val_v1 (n : ℕ) (i : fin (n + 1)) : 0 ≤ i := fin.le_iff_val_le_val.mpr $ nat.zero_le _ -- This exists in mathlib, but in a form that is not immediately useful lemma fin_le_last_val (n : ℕ) (i : fin (n + 2)) : i ≤ (n+1) := begin have j0 : n + 1 < n + 1 + 1, linarith, have j0 := @fin.coe_val_of_lt (n+1) (n+1) j0, have h3 : i.val ≤ n + 1, linarith [i.is_lt], apply fin.le_iff_val_le_val.mpr, rw ← j0 at h3, exact h3, end lemma fin_le_last_val_v1 (n : ℕ) (i : fin (n + 1)) : i ≤ n := fin.le_iff_val_le_val.mpr $ (fin.coe_val_of_lt $ nat.lt_succ_self n).symm ▸ nat.le_of_lt_succ i.2 lemma fin_le_last_val_v2 (n : ℕ) : ∀ i : fin (n + 2), i ≤ (n+1) := begin intro i, change i.val ≤ ((_ + _) : fin (n+2)).val, norm_cast, have := i.2, rw fin.coe_val_of_lt; omega end -- Another version with a better name from Y. Pechersky lemma fin.le_coe_last {n : ℕ} (i : fin (n + 1)) : i ≤ n := begin rw [fin.le_def, <-nat.lt_succ_iff, fin.coe_val_of_lt (lt_add_one n)], exact i.is_lt, end /- I'd also like to obtain the result this way lemma fin_le_last_val_v3 (n : ℕ) (i : fin (n + 1)) : i ≤ n := begin have h1 := fin.le_last i, have h01 := @fin.coe_last n, have h2 := fin.last_val n, have h3 := (fin.le_iff_val_le_val).mp h1, rw h2 at h3, obtain ⟨i, hi ⟩ := i, sorry end example {n : ℕ} (i j : fin n) (h : i < j) : n = ↑i + (↑j - ↑i + 1 + (n - 1 - ↑j)) := begin cases i, cases j, dsimp, change i_val < j_val at h, omega, done end -/ -- This is very particular, only needed in my own proof -- This is courtesy Shing Tak Lam lemma shing (n : ℕ) (i j : fin (n+1)) (h : (j.val : fin (n+2)) < (i.val.succ : fin (n+2))) : j.val < i.val.succ := begin change (j.val : fin (n+2)).val < (i.val.succ : fin (n+2)).val at h, rwa [fin.coe_val_of_lt (show j.1 < n + 2, by linarith [j.2]), fin.coe_val_of_lt (show i.1 + 1 < n + 2, by linarith [i.2])] at h, end -- Again thanks to Shing Tak Lam lemma fin_lt_succ (n : ℕ) (i : fin (n + 1)) : (i : fin (n+2)) < (i+1) := begin cases i with i hi, change (_ : fin (n+2)).val < (_ : fin (n+2)).val, simp only [fin.coe_mk, coe_coe], norm_cast, rw [fin.coe_val_of_lt, fin.coe_val_of_lt]; omega, end -- Some `fin` lemmas from Y. Pechersky lemma fin.coe_succ_eq_succ {n : ℕ} (i : fin n) : ((i : fin (n + 1)) + 1) = i.succ := begin rw [fin.eq_iff_veq, fin.succ_val, coe_coe], norm_cast, apply fin.coe_coe_of_lt, exact add_lt_add_right i.is_lt 1 end lemma fin.coe_eq_cast_succ {n : ℕ} (i : fin n) : (i : fin (n + 1)) = i.cast_succ := begin rw [fin.cast_succ, fin.cast_add, fin.cast_le, fin.cast_lt], obtain ⟨i, hi⟩ := i, rw fin.eq_iff_veq, have : i.succ = i + 1 := rfl, simp only [this], apply fin.coe_val_of_lt, exact nat.lt.step hi, end lemma fin.val_coe_eq_self {n : ℕ} (i : fin n) : (i : fin (n + 1)).val = i.val := by { rw fin.coe_eq_cast_succ, refl } lemma fin.lt_succ {n : ℕ} (i : fin n) : (i : fin (n + 1)) < i.succ := begin rw [fin.coe_eq_cast_succ, fin.cast_succ, fin.lt_iff_val_lt_val, fin.cast_add_val, fin.succ_val], exact lt_add_one i.val end lemma fin_lt_succ' (n : ℕ) (i : fin (n + 1)) : (i : fin (n + 2)) < (i + 1) := by { rw fin.coe_succ_eq_succ, exact fin.lt_succ _ } -- Lemmas from Y. Kudryashov @[simp] lemma mk_zero (n : ℕ) : (⟨0, n.zero_lt_succ⟩ : fin (n + 1)) = 0 := rfl @[simp] lemma mk_one (n : ℕ) (hn : 1 < n + 1) : (⟨1, hn⟩ : fin (n + 1)) = 1 := fin.eq_of_veq (nat.mod_eq_of_lt hn).symm @[simp] lemma mk_bit0 {m n : ℕ} (h : bit0 m < n) : (⟨_, h⟩ : fin n) = bit0 ⟨m, (nat.le_add_right _ _).trans_lt h⟩ := fin.eq_of_veq (nat.mod_eq_of_lt h).symm @[simp] lemma mk_bit1 {m n : ℕ} (h : bit1 m < n + 1) : (⟨bit1 m, h⟩ : fin (n + 1)) = bit1 ⟨m, (nat.le_add_right m m).trans_lt ((m + m).lt_succ_self.trans h)⟩ := begin ext, simp only [bit1, bit0] at h ⊢, simp only [fin.val_add, fin.one_val, ← nat.add_mod, nat.mod_eq_of_lt h] end
import GMLInit.Data.BEq import GMLInit.Data.Fin import GMLInit.Data.List.Basic namespace Array protected theorem eq : {as bs : Array α} → as.data = bs.data → as = bs | ⟨_⟩, ⟨_⟩, rfl => rfl @[simp] theorem data_nil {α} : #[].data = ([] : List α) := rfl /- get -/ theorem get_fin_eq_data_get_fin {α} (as : Array α) (i : Fin as.size) : as.get i = as.data.get i := rfl /- set -/ theorem get_set_of_eq (as : Array α) {i : Fin as.size} {j : Nat} {x : α} {hj : j < (as.set i x).size} : i.val = j → (as.set i x)[j]'hj = x := by intro h have hj' : j < as.size := as.size_set i x ▸ hj rw [as.get_set i j hj'] rw [if_pos h] theorem get_set_of_ne (as : Array α) {i : Fin as.size} {j : Nat} {x : α} {hj : j < (as.set i x).size} : i.val ≠ j → (as.set i x)[j]'hj = as[j]'(as.size_set i x ▸ hj) := by intro h; have hj' : j < as.size := as.size_set i x ▸ hj rw [as.get_set i j hj'] rw [if_neg h] /- pop -/ theorem get_pop.aux (as : Array α) {i : Nat} : i < as.pop.size → i < as.size := fun h => Nat.lt_of_lt_of_le h (as.size_pop ▸ Nat.pred_le as.size) theorem get_pop (as : Array α) (i : Nat) (hi : i < as.pop.size) : as.pop[i] = as[i]'(get_pop.aux as hi) := by rw [←as.get_eq_getElem ⟨i, get_pop.aux as hi⟩] rw [←as.pop.get_eq_getElem ⟨i, hi⟩] rw [get, get] unfold pop rw [List.get_dropLast] /- swap -/ theorem get_swap.aux (as : Array α) (i j : Fin as.size) {k : Nat} : k < (as.swap i j).size → k < as.size := fun h => as.size_swap i j ▸ h theorem get_swap_fst (as : Array α) (i j : Fin as.size) : (as.swap i j)[i.val]'(by simp [i.isLt]) = as[j.val] := by simp only [swap] rw [get_set] split next heq => have : j.val = i.val := by rw [←heq] apply Fin.val_eq_val_of_heq rw [size_set] elim_casts reflexivity simp [get_eq_getElem, this] next => rw [get_set_eq, get_eq_getElem] theorem get_swap_snd (as : Array α) (i j : Fin as.size) : (as.swap i j)[j.val]'(by simp [j.isLt]) = as[i.val] := by simp only [swap] rw [get_set_of_eq] rw [get_eq_getElem] apply Fin.val_eq_val_of_heq rw [size_set] elim_casts reflexivity theorem get_swap_other (as : Array α) {i j : Fin as.size} (k : Nat) (hk : k < (as.swap i j).size) : i.val ≠ k → j.val ≠ k → (as.swap i j)[k]'(hk) = as[k]'(as.size_swap i j ▸ hk) := by intro hik hjk have hjk : ((size_set as i (get as j)).symm ▸ j).val ≠ k := by intro h cases h apply hjk apply Fin.val_eq_val_of_heq rw [size_set] elim_casts reflexivity simp only [swap] rw [get_set_of_ne] rw [get_set_of_ne as hik] exact hjk theorem get_swap (as : Array α) (i j : Fin as.size) (k : Nat) (hk : k < (as.swap i j).size) : (as.swap i j)[k]'(hk) = if j.val = k then as[i] else if i.val = k then as[j] else as[k]'(get_swap.aux as i j hk) := by split next hkj => cases hkj; rw [get_swap_snd]; rfl next hkj => split next hki => cases hki; rw [get_swap_fst]; rfl next hki => rw [get_swap_other as k hk hki hkj] /- del -/ def del (as : Array α) (k : Fin as.size) : Array α := have : as.size ≠ 0 := Nat.not_eq_zero_of_lt k.isLt let last : Fin as.size := ⟨as.size-1, Nat.pred_lt this⟩ (as.swap k last).pop theorem size_del (as : Array α) (k : Fin as.size) : (as.del k).size = as.size-1 := by simp [del] theorem get_del.aux0 (as : Array α) (k : Fin as.size) : as.size ≠ 0 := Nat.not_eq_zero_of_lt k.isLt theorem get_del.aux1 (as : Array α) (k : Fin as.size) : as.size-1 < as.size := Nat.pred_lt (aux0 as k) theorem get_del.aux2 (as : Array α) (k : Fin as.size) {i : Nat} : i < (as.del k).size → i < as.size := fun h => Nat.lt_of_lt_of_le (as.size_del k ▸ h : i < as.size-1) (Nat.pred_le as.size) theorem get_del (as : Array α) (k : Fin as.size) (i : Nat) (hi : i < (as.del k).size) : (as.del k)[i] = if k.val = i then as[as.size-1]'(get_del.aux1 as k) else as[i]'(get_del.aux2 as k hi) := by have hi' : as.size - 1 ≠ i := Ne.symm <| Nat.ne_of_lt <| size_del as k ▸ hi simp only [del] rw [get_pop] rw [get_swap] rw [if_neg hi'] rfl section foldlM variable {m} [Monad m] (f : β → α → m β) (b : β) theorem foldlM_stop (as : Array α) (stop : Nat) (hstop : stop ≤ as.size) : as.foldlM f b stop stop = pure b := by simp only [Array.foldlM] rw [dif_pos hstop] rw [Array.foldlM.loop] rw [dif_neg (by irreflexivity)] theorem foldlM_step (as : Array α) (start stop : Nat) (hstart : start < stop) (hstop : stop ≤ as.size) : have : start < as.size := Nat.lt_of_lt_of_le hstart hstop as.foldlM f b start stop = f b as[start] >>= fun b => as.foldlM f b (start+1) stop := by simp only [Array.foldlM] rw [dif_pos hstop] rw [Array.foldlM.loop] rw [dif_pos hstart] split next heq => absurd heq apply Nat.sub_ne_zero_of_lt hstart next heq => simp congr funext b rw [dif_pos hstop] rw [Nat.sub_succ, heq, Nat.pred_succ] end foldlM section foldl variable (f : β → α → β) (b : β) theorem foldl_stop (as : Array α) (stop : Nat) (hstop : stop ≤ as.size) : as.foldl f b stop stop = b := by apply foldlM_stop; assumption theorem foldl_step (as : Array α) (start stop : Nat) (hstart : start < stop) (hstop : stop ≤ as.size) : have : start < as.size := Nat.lt_of_lt_of_le hstart hstop as.foldl f b start stop = as.foldl f (f b as[start]) (start+1) stop := by apply foldlM_step; assumption; assumption variable (h : α → α → α) [Lean.IsAssociative h] theorem foldl_assoc (as : Array α) (b c : α) (start stop : Nat) (hstart : start ≤ stop) (hstop : stop ≤ as.size) : as.foldl h (h b c) start stop = h b (as.foldl h c start stop) := by by_cases start = stop with | isTrue heq => cases heq rw [foldl_stop] <;> try (exact hstop) rw [foldl_stop]; exact hstop | isFalse hne => have hstart' : start < stop := Nat.lt_of_le_of_ne hstart hne have : start < as.size := Nat.lt_of_lt_of_le hstart' hstop rw [foldl_step h (h b c)] <;> try (first | exact hstop | exact hstart') rw [foldl_step h c] <;> try (first | exact hstop | exact hstart') rw [Lean.IsAssociative.assoc (op:=h)] rw [foldl_assoc as b (h c as[start]) (start+1) stop hstart' hstop] termination_by foldl_assoc => stop - start end foldl section foldrM variable {m} [Monad m] (f : α → β → m β) (b : β) theorem foldrM_stop (as : Array α) (stop : Nat) (hstop : stop ≤ as.size) : as.foldrM f b stop stop = pure b := by simp only [Array.foldrM] rw [dif_pos hstop] rw [if_neg (by irreflexivity)] theorem foldrM_step (as : Array α) (start stop : Nat) (hstop : stop ≤ start) (hstart : start < as.size) : as.foldrM f b (start+1) stop = f as[start] b >>= fun b => as.foldrM f b start stop := by simp only [Array.foldrM] rw [dif_pos (Nat.succ_le_of_lt hstart)] rw [if_pos (Nat.lt_succ_of_le hstop)] simp only [foldrM.fold] split next heq => absurd (eq_of_beq heq) apply Nat.ne_of_gt apply Nat.lt_succ_of_le exact hstop next hne => congr funext b rw [dif_pos (Nat.le_of_lt hstart)] split next => rfl next hge => have : stop = start := by antisymmetry using LE.le · exact hstop · exact Nat.le_of_not_gt hge simp [this] unfold foldrM.fold rw [BEq.rfl, if_pos rfl] end foldrM section foldr variable (f : α → β → β) (b : β) theorem foldr_stop (as : Array α) (stop : Nat) (hstop : stop ≤ as.size) : as.foldr f b stop stop = b := by apply foldrM_stop; assumption theorem foldr_step (as : Array α) (start stop : Nat) (hstop : stop ≤ start) (hstart : start < as.size) : as.foldr f b (start+1) stop = as.foldr f (f as[start] b) start stop := by apply foldrM_step; assumption end foldr section append theorem size_append_aux {as bs : Array α} (start stop : Nat) (hstart : start ≤ stop) (hstop : stop ≤ bs.size) : (foldl push as bs start stop).size = as.size + (stop - start) := by by_cases start = stop with | isTrue heq => rw [heq] rw [foldl_stop] rw [Nat.sub_self] rw [Nat.add_zero] exact hstop | isFalse hne => have hstart' : start < stop := Nat.lt_of_le_of_ne hstart hne rw [foldl_step push as bs start stop hstart' hstop] rw [size_append_aux (start+1) stop hstart' hstop] rw [size_push] rw [Nat.sub_succ'] rw [Nat.add_assoc] congr rw [Nat.add_comm] have : 1 ≤ stop - start := by rw [Nat.le_sub_iff_add_le hstart] rw [Nat.add_comm] exact hstart' rw [Nat.sub_add_cancel this] termination_by size_append_aux => stop - start theorem get_append_aux_lo {as bs : Array α} (start stop i : Nat) (hstart : start ≤ stop) (hstop : stop ≤ bs.size) (hi : i < as.size) (h : i < (foldl push as bs start stop).size := by simp_arith [*]) : (foldl push as bs start stop)[i] = as[i] := by simp only [autoParam] at h by_cases start = stop with | isTrue heq => congr rw [heq] rw [foldl_stop] exact hstop | isFalse hne => have hstart' : start < stop := Nat.lt_of_le_of_ne hstart hne have : start < bs.size := Nat.lt_of_lt_of_le hstart' hstop have : i < (foldl push (as.push bs[start]) bs (start+1) stop).size := by rw [←foldl_step] exact h exact hstart' exact hstop transitivity (foldl push (as.push bs[start]) bs (start+1) stop)[i] · congr 1 rw [foldl_step] exact hstart' exact hstop · rw [get_append_aux_lo (start+1) stop i hstart' hstop] rw [get_push_lt] termination_by get_append_aux_lo => stop - start theorem get_append_aux_hi {as bs : Array α} (start stop i : Nat) (hstart : start ≤ stop) (hstop : stop ≤ bs.size) (hi : i < stop - start) (ha : as.size + i < (foldl push as bs start stop).size := by simp_arith [*]) (hb : start + i < bs.size := by simp_arith [*]): (foldl push as bs start stop)[as.size + i] = bs[start + i] := by simp only [autoParam] at ha hb by_cases start = stop with | isTrue heq => rw [heq, Nat.sub_self] at hi contradiction | isFalse hne => have hstart' : start < stop := Nat.lt_of_le_of_ne hstart hne have : start < bs.size := Nat.lt_of_lt_of_le hstart' hstop have : as.size + i < (foldl push (as.push bs[start]) bs (start+1) stop).size := by rw [size_append_aux (start+1) stop (Nat.succ_le_of_lt hstart') hstop] rw [size_push] rw [Nat.add_assoc] apply Nat.add_lt_add_left rw [Nat.add_comm] rw [Nat.sub_succ'] rw [Nat.sub_add_cancel] exact hi rw [Nat.le_sub_iff_add_le hstart] rw [Nat.add_comm] exact Nat.succ_le_of_lt hstart' transitivity (foldl push (as.push bs[start]) bs (start+1) stop)[as.size + i] · congr 1 rw [foldl_step] exact hstart' exact hstop · match i with | 0 => transitivity (as.push bs[start])[as.size] · have h : as.size < (as.push bs[start]).size := by simp; done exact get_append_aux_lo (start+1) stop as.size (Nat.succ_le_of_lt hstart') hstop h _ · rw [get_push_eq]; rfl | i+1 => have : (as.push bs[start]).size + i < (foldl push (as.push bs[start]) bs (start+1) stop).size := by rw [size_append_aux (start+1) stop (Nat.succ_le_of_lt hstart') hstop] rw [size_push] apply Nat.add_lt_add_left rw [Nat.sub_succ'] rw [Nat.lt_sub_iff_add_lt] exact hi transitivity (foldl push (as.push bs[start]) bs (start+1) stop)[(as.push bs[start]).size + i] · congr 1 rw [size_push] rw [Nat.add_right_comm, Nat.add_assoc] · have hi' : i < stop - (start+1) := by rw [Nat.sub_succ'] rw [Nat.lt_sub_iff_add_lt] exact hi have : start + 1 + i < bs.size := by rw [Nat.add_assoc, Nat.add_comm 1]; exact hb rw [get_append_aux_hi (start+1) stop i (Nat.succ_le_of_lt hstart') hstop hi' _ _] congr 1 rw [Nat.add_right_comm, Nat.add_assoc] assumption theorem data_append_aux {as bs : Array α} (start stop : Nat) (hstart : start ≤ stop) (hstop : stop ≤ bs.size) : (foldl push as bs start stop).data = as.data ++ bs.data.extract start stop := by by_cases start = stop with | isTrue heq => cases heq rw [foldl_stop] <;> try assumption rw [List.extract_stop] rw [List.append_nil] | isFalse hne => have hstart' : start < stop := Nat.lt_of_le_of_ne hstart hne have : start < bs.size := Nat.lt_of_lt_of_le hstart' hstop rw [foldl_step] <;> try assumption rw [List.extract_step] rw [data_append_aux (start+1) stop] <;> try assumption rw [push_data] rw [getElem_eq_data_get] rw [List.append_assoc] rw [List.singleton_append] termination_by data_append_aux => stop - start theorem size_append (as bs : Array α) : (as ++ bs).size = as.size + bs.size := size_append_aux 0 bs.size (Nat.zero_le _) (Nat.le_refl _) theorem get_append_left {as bs : Array α} (i : Nat) (hi : i < as.size) : have : i < (as ++ bs).size := size_append as bs ▸ Nat.lt_add_right _ _ _ hi (as ++ bs)[i] = as[i] := get_append_aux_lo 0 bs.size i (Nat.zero_le _) (Nat.le_refl _) hi _ theorem get_append_right {as bs : Array α} (i : Nat) (hi : i < bs.size) : have : as.size + i < (as ++ bs).size := size_append as bs ▸ Nat.add_lt_add_left hi as.size (as ++ bs)[as.size + i] = bs[i] := by simp only [HAppend.hAppend, Append.append, Array.append] rw [get_append_aux_hi 0 bs.size i (Nat.zero_le _) (Nat.le_refl _) hi _ _] congr rw [Nat.zero_add] rw [Nat.zero_add] exact hi theorem data_append {as bs : Array α} : (as ++ bs).data = as.data ++ bs.data := by simp only [HAppend.hAppend, Append.append, Array.append] rw [data_append_aux 0 bs.size (Nat.zero_le _) (Nat.le_refl _)] rw [List.extract_all]; rfl theorem nil_append (as : Array α) : #[] ++ as = as := by apply Array.eq repeat rw [data_append] rw [data_nil] exact List.nil_append .. theorem append_nil (as : Array α) : as ++ #[] = as := by apply Array.eq repeat rw [data_append] rw [data_nil] exact List.append_nil .. theorem append_assoc (as bs cs : Array α) : (as ++ bs) ++ cs = as ++ (bs ++ cs) := by apply Array.eq repeat rw [data_append] exact List.append_assoc .. end append section sum local instance : Lean.IsAssociative (α:=Nat) (.+.) where assoc := Nat.add_assoc def sum (ns : Array Nat) (start := 0) (stop := ns.size) : Nat := ns.foldl (.+.) 0 start stop theorem sum_stop (ns : Array Nat) (stop : Nat) (hstop : stop ≤ ns.size) : ns.sum stop stop = 0 := by simp only [sum] rw [foldl_stop] exact hstop theorem sum_step (ns : Array Nat) (start stop : Nat) (hstart : start < stop) (hstop : stop ≤ ns.size) : have : start < ns.size := Nat.lt_of_lt_of_le hstart hstop ns.sum start stop = ns[start] + ns.sum (start+1) stop := by have : start < ns.size := Nat.lt_of_lt_of_le hstart hstop simp only [sum] rw [foldl_step] <;> try assumption rw [Nat.add_comm 0 ns[start]] rw [ns.foldl_assoc (.+.) ns[start] 0 (start+1) stop (Nat.succ_le_of_lt hstart) hstop] end sum section join local instance : Lean.IsAssociative (α:=Array α) (.++.) where assoc := append_assoc def join (as : Array (Array α)) (start := 0) (stop := as.size) : Array α := as.foldl (.++.) #[] start stop def join_stop (as : Array (Array α)) (stop : Nat) (hstop : stop ≤ as.size) : as.join stop stop = #[] := by simp only [join] rw [foldl_stop] exact hstop def join_step (as : Array (Array α)) (start stop : Nat) (hstart : start < stop) (hstop : stop ≤ as.size) : have : start < as.size := Nat.lt_of_lt_of_le hstart hstop as.join start stop = as[start] ++ as.join (start+1) stop := by have : start < as.size := Nat.lt_of_lt_of_le hstart hstop simp only [join] rw [foldl_step] <;> try assumption transitivity (foldl (.++.) (as[start] ++ #[]) as (start+1) stop) · rw [nil_append, append_nil] · rw [foldl_assoc] <;> assumption end join section ofFun variable {α n} (f : Fin n → α) unsafe def ofFunUnsafe : Array α := Id.run do let mut res := #[] for i in [:n] do res := res.push (f ⟨i, lcProof⟩) return res @[implemented_by ofFunUnsafe] protected def ofFun : Array α where data := List.ofFun f theorem ofFun_size : (Array.ofFun f).size = n := by unfold Array.ofFun rw [Array.size_mk] rw [List.ofFun_length] theorem ofFun_getElem (i : Fin (Array.ofFun f).size) : (Array.ofFun f)[i] = f (Array.ofFun_size f ▸ i) := by unfold Array.ofFun rw [Array.getElem_fin_eq_data_get] rw [List.ofFun_get] theorem ofFun_get (i : Fin (Array.ofFun f).size) : (Array.ofFun f).get i = f (Array.ofFun_size f ▸ i) := ofFun_getElem f i end ofFun end Array
(* Title: CoW_Equations/Equations_Basic.thy Author: Štěpán Holub, Charles University Author: Martin Raška, Charles University Author: Štěpán Starosta, CTU in Prague Part of Combinatorics on Words Formalized. See https://gitlab.com/formalcow/combinatorics-on-words-formalized/ *) theory Equations_Basic imports Periodicity_Lemma Lyndon_Schutzenberger Submonoids Binary_Code_Morphisms begin chapter "Equations on words - basics" text \<open>Contains various nontrivial auxiliary or rudimentary facts related to equations. Often moderately advanced or even fairly advanced. May change significantly in the future.\<close> section \<open>Factor interpretation\<close> definition factor_interpretation :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list list \<Rightarrow> bool" ("_ _ _ \<sim>\<^sub>\<I> _" [51,51,51,51] 60) where "factor_interpretation p u s ws = (p <p hd ws \<and> s <s last ws \<and> p \<cdot> u \<cdot> s = concat ws)" lemma fac_interpret_nemp: "u \<noteq> \<epsilon> \<Longrightarrow> p u s \<sim>\<^sub>\<I> ws \<Longrightarrow> ws \<noteq> \<epsilon>" unfolding factor_interpretation_def by auto lemma fac_interpretE: assumes "p u s \<sim>\<^sub>\<I> ws" shows "p <p hd ws" and "s <s last ws" and "p \<cdot> u \<cdot> s = concat ws" using assms unfolding factor_interpretation_def by blast+ lemma fac_interpretI: "p <p hd ws \<Longrightarrow> s <s last ws \<Longrightarrow> p \<cdot> u \<cdot> s = concat ws \<Longrightarrow> p u s \<sim>\<^sub>\<I> ws" unfolding factor_interpretation_def by blast lemma obtain_fac_interpret: assumes "pu \<cdot> u \<cdot> su = concat ws" and "u \<noteq> \<epsilon>" obtains ps ss p s vs where "p u s \<sim>\<^sub>\<I> vs" and "ps \<cdot> vs \<cdot> ss = ws" and "concat ps \<cdot> p = pu" and "s \<cdot> concat ss = su" using assms proof (induction "\<^bold>|ws\<^bold>|" arbitrary: ws pu su thesis rule: less_induct) case less then show ?case proof- have "ws \<noteq> \<epsilon>" using \<open>u \<noteq> \<epsilon>\<close> \<open>pu \<cdot> u \<cdot> su = concat ws\<close> by force have "\<^bold>|tl ws\<^bold>| < \<^bold>|ws\<^bold>|" and "\<^bold>|butlast ws\<^bold>| < \<^bold>|ws\<^bold>|" using \<open>ws \<noteq> \<epsilon>\<close> by force+ show thesis proof (cases) assume "hd ws \<le>p pu \<or> last ws \<le>s su" then show thesis proof assume "hd ws \<le>p pu" from prefixE[OF this] obtain pu' where "pu = hd ws \<cdot> pu'". from \<open>pu \<cdot> u \<cdot> su = concat ws\<close>[unfolded this, folded arg_cong[OF hd_tl[OF \<open>ws \<noteq> \<epsilon>\<close>], of concat]] have "pu' \<cdot> u \<cdot> su = concat (tl ws)" by force from less.hyps[OF \<open>\<^bold>|tl ws\<^bold>| < \<^bold>|ws\<^bold>|\<close> _ \<open>pu' \<cdot> u \<cdot> su = concat (tl ws)\<close> \<open>u \<noteq> \<epsilon>\<close>] obtain p s vs ps' ss where "p u s \<sim>\<^sub>\<I> vs" and "ps' \<cdot> vs \<cdot> ss = tl ws" and "concat ps' \<cdot> p = pu'" and "s \<cdot> concat ss = su". have "(hd ws # ps') \<cdot> vs \<cdot> ss = ws" using \<open>ws \<noteq> \<epsilon>\<close> \<open>ps' \<cdot> vs \<cdot> ss = tl ws\<close> by auto have "concat (hd ws # ps') \<cdot> p = pu" using \<open>concat ps' \<cdot> p = pu'\<close> unfolding \<open>pu = hd ws \<cdot> pu'\<close> by fastforce from less.prems(1)[OF \<open>p u s \<sim>\<^sub>\<I> vs\<close> \<open>(hd ws # ps') \<cdot> vs \<cdot> ss = ws\<close> \<open>concat (hd ws # ps') \<cdot> p = pu\<close> \<open>s \<cdot> concat ss = su\<close>] show thesis. next assume "last ws \<le>s su" from suffixE[OF this] obtain su' where "su = su' \<cdot> last ws". from \<open>pu \<cdot> u \<cdot> su = concat ws\<close>[unfolded this, folded arg_cong[OF hd_tl[reversed, OF \<open>ws \<noteq> \<epsilon>\<close>], of concat]] have "pu \<cdot> u \<cdot> su' = concat (butlast ws)" by force from less.hyps[OF \<open>\<^bold>|butlast ws\<^bold>| < \<^bold>|ws\<^bold>|\<close> _ \<open>pu \<cdot> u \<cdot> su' = concat (butlast ws)\<close> \<open>u \<noteq> \<epsilon>\<close>] obtain p s vs ps ss' where "p u s \<sim>\<^sub>\<I> vs" and "ps \<cdot> vs \<cdot> ss' = butlast ws" and "concat ps \<cdot> p = pu" and "s \<cdot> concat ss' = su'". have "ps \<cdot> vs \<cdot> (ss' \<cdot> [last ws]) = ws" using append_butlast_last_id[OF \<open>ws \<noteq> \<epsilon>\<close>, folded \<open>ps \<cdot> vs \<cdot> ss' = butlast ws\<close>] unfolding rassoc. have "s \<cdot> concat (ss' \<cdot> [last ws]) = su" using \<open>s \<cdot> concat ss' = su'\<close> \<open>su = su' \<cdot> last ws\<close> by fastforce from less.prems(1)[OF \<open>p u s \<sim>\<^sub>\<I> vs\<close> \<open>ps \<cdot> vs \<cdot> (ss' \<cdot> [last ws]) = ws\<close> \<open>concat ps \<cdot> p = pu\<close> \<open>s \<cdot> concat (ss' \<cdot> [last ws]) = su\<close>] show thesis. qed next assume not_or: "\<not> (hd ws \<le>p pu \<or> last ws \<le>s su)" hence "pu <p hd ws" and "su <s last ws" using ruler[OF concat_hd_pref[OF \<open>ws \<noteq> \<epsilon>\<close>] prefI'[OF \<open>pu \<cdot> u \<cdot> su = concat ws\<close>[symmetric]]] ruler[reversed, OF concat_hd_pref[reversed, OF \<open>ws \<noteq> \<epsilon>\<close>] prefI'[reversed, OF \<open>pu \<cdot> u \<cdot> su = concat ws\<close>[symmetric, unfolded lassoc]]] by auto from fac_interpretI[OF this \<open>pu \<cdot> u \<cdot> su = concat ws\<close>] have "pu u su \<sim>\<^sub>\<I> ws". from less.prems(1)[OF this, of \<epsilon> \<epsilon>] show thesis by simp qed qed qed lemma obtain_fac_interp': assumes "u \<le>f concat ws" and "u \<noteq> \<epsilon>" obtains p s vs where "p u s \<sim>\<^sub>\<I> vs" and "vs \<le>f ws" proof- from facE[OF \<open>u \<le>f concat ws\<close>] obtain pu su where "concat ws = pu \<cdot> u \<cdot> su". from obtain_fac_interpret[OF this[symmetric] \<open>u \<noteq> \<epsilon>\<close>] that show thesis using facI' by metis qed lemma rev_in_set_map_rev_conv: "rev u \<in> set (map rev ws) \<longleftrightarrow> u \<in> set ws" by auto lemma rev_fac_interp: assumes "p u s \<sim>\<^sub>\<I> ws" shows "(rev s) (rev u) (rev p) \<sim>\<^sub>\<I> rev (map rev ws)" proof (rule fac_interpretI) note fac_interpretE[OF assms] show \<open>rev s <p hd (rev (map rev ws))\<close> using \<open>s <s last ws\<close> by (metis \<open>p <p hd ws\<close> \<open>p \<cdot> u \<cdot> s = concat ws\<close> append_is_Nil_conv concat.simps(1) hd_rev last_map list.simps(8) rev_is_Nil_conv strict_suffix_to_prefix) show "rev p <s last (rev (map rev ws))" using \<open> p <p hd ws\<close> by (metis \<open>p \<cdot> u \<cdot> s = concat ws\<close> \<open>s <s last ws\<close> append_is_Nil_conv concat.simps(1) last_rev list.map_sel(1) list.simps(8) rev_is_Nil_conv spref_rev_suf_iff) show "rev s \<cdot> rev u \<cdot> rev p = concat (rev (map rev ws))" using \<open>p \<cdot> u \<cdot> s = concat ws\<close> by (metis append_assoc rev_append rev_concat rev_map) qed lemma rev_fac_interp_iff [reversal_rule]: "(rev s) (rev u) (rev p) \<sim>\<^sub>\<I> rev (map rev ws) \<longleftrightarrow> p u s \<sim>\<^sub>\<I> ws" using rev_fac_interp by (metis (no_types, lifting) map_rev_involution rev_map rev_rev_ident) section Miscellanea subsection \<open>Mismatch additions\<close> lemma mismatch_pref_comm_len: assumes "w1 \<in> \<langle>{u,v}\<rangle>" and "w2 \<in> \<langle>{u,v}\<rangle>" and "p \<le>p w1" "u \<cdot> p \<le>p v \<cdot> w2" and "\<^bold>|v\<^bold>| \<le> \<^bold>|p\<^bold>|" shows "u \<cdot> v = v \<cdot> u" proof (rule ccontr) assume "u \<cdot> v \<noteq> v \<cdot> u" then interpret binary_code u v by unfold_locales show False using bin_code_prefs bin_code_prefs[OF \<open>w1 \<in> \<langle>{u,v}\<rangle>\<close> \<open>p \<le>p w1\<close> \<open>w2 \<in> \<langle>{u,v}\<rangle>\<close> \<open>\<^bold>|v\<^bold>| \<le> \<^bold>|p\<^bold>|\<close>] \<open>u \<cdot> p \<le>p v \<cdot> w2\<close> bin_code_prefs by blast qed lemma mismatch_pref_comm: assumes "w1 \<in> \<langle>{u,v}\<rangle>" and "w2 \<in> \<langle>{u,v}\<rangle>" and "u \<cdot> w1 \<cdot> v \<le>p v \<cdot> w2 \<cdot> u" shows "u \<cdot> v = v \<cdot> u" using assms by mismatch lemma mismatch_eq_comm: assumes "w1 \<in> \<langle>{u,v}\<rangle>" and "w2 \<in> \<langle>{u,v}\<rangle>" and "u \<cdot> w1 = v \<cdot> w2" shows "u \<cdot> v = v \<cdot> u" using assms by mismatch lemmas mismatch_suf_comm = mismatch_pref_comm[reversed] and mismatch_suf_comm_len = mismatch_pref_comm_len[reversed, unfolded rassoc] subsection \<open>Conjugate words with conjugate periods\<close> lemma conj_pers_conj_comm_aux: assumes "(u \<cdot> v)\<^sup>@Suc k \<cdot> u = r \<cdot> s" and "(v \<cdot> u)\<^sup>@Suc l \<cdot> v = (s \<cdot> r)\<^sup>@Suc (Suc m)" shows "u \<cdot> v = v \<cdot> u" proof (rule nemp_comm) assume "u \<noteq> \<epsilon>" and "v \<noteq> \<epsilon>" hence "u \<cdot> v \<noteq> \<epsilon>" and "v \<cdot> u \<noteq> \<epsilon>" by blast+ have "l \<noteq> 0" \<comment> \<open>impossible by a length argument\<close> proof (rule notI) assume "l = 0" hence "v \<cdot> u \<cdot> v = (s \<cdot> r)\<^sup>@ Suc(Suc m)" using assms(2) by simp from lenarg[OF assms(1)] \<open>u \<noteq> \<epsilon>\<close> have "\<^bold>|v \<cdot> u\<^bold>| + \<^bold>|u\<^bold>| \<le> \<^bold>|r \<cdot> s\<^bold>|" unfolding lenmorph pow_len by simp hence "\<^bold>|v \<cdot> u \<cdot> v \<cdot> u\<^bold>| \<le> 2*\<^bold>|r \<cdot> s\<^bold>|" unfolding lenmorph pow_len by simp hence "\<^bold>|v \<cdot> u \<cdot> v\<^bold>| < 2*\<^bold>|r \<cdot> s\<^bold>|" unfolding lenmorph pow_len using nemp_len[OF \<open>u \<noteq> \<epsilon>\<close>] by linarith from this[unfolded \<open>v \<cdot> u \<cdot> v = (s \<cdot> r)\<^sup>@ Suc(Suc m)\<close>] show False unfolding lenmorph pow_len by simp qed \<comment> \<open>we can therefore use the Periodicity lemma\<close> then obtain l' where "l = Suc l'" using not0_implies_Suc by auto let ?w = "(v \<cdot> u)\<^sup>@Suc l \<cdot> v" have per1: "?w \<le>p (v \<cdot> u) \<cdot> ?w" using \<open>v \<cdot> u \<noteq> \<epsilon>\<close> per_rootD[of ?w "v \<cdot> u", unfolded per_eq] by blast have per2: "?w \<le>p (s \<cdot> r) \<cdot> ?w" unfolding assms(2) using pref_pow_ext' by blast have len: "\<^bold>|v \<cdot> u\<^bold>| + \<^bold>|s \<cdot> r\<^bold>| \<le> \<^bold>|?w\<^bold>|" proof- have len1: "2*\<^bold>|s \<cdot> r\<^bold>| \<le> \<^bold>|?w\<^bold>|" unfolding \<open>(v \<cdot> u)\<^sup>@Suc l \<cdot> v = (s \<cdot> r)\<^sup>@Suc (Suc m)\<close> lenmorph pow_len by simp moreover have len2: "2*\<^bold>|v \<cdot> u\<^bold>| \<le> \<^bold>|?w\<^bold>|" unfolding lenmorph pow_len \<open>l = Suc l'\<close> by simp ultimately show ?thesis using len1 len2 by linarith qed from two_pers[OF per1 per2 len] have "(v \<cdot> u) \<cdot> (s \<cdot> r) = (s \<cdot> r) \<cdot> (v \<cdot> u)". hence "(v \<cdot> u)\<^sup>@Suc l \<cdot> (s \<cdot> r)\<^sup>@Suc (Suc m) = (s \<cdot> r)\<^sup>@Suc (Suc m) \<cdot> (v \<cdot> u)\<^sup>@Suc l" using comm_add_exps by blast from comm_drop_exp'[OF this[folded assms(2), unfolded rassoc cancel]] show "u \<cdot> v = v \<cdot> u" unfolding rassoc cancel. qed lemma conj_pers_conj_comm: assumes "\<rho> (v \<cdot> (u \<cdot> v)\<^sup>@(Suc k)) \<sim> \<rho> ((u \<cdot> v)\<^sup>@(Suc m) \<cdot> u)" shows "u \<cdot> v = v \<cdot> u" proof (rule nemp_comm) let ?v = "v \<cdot> (u \<cdot> v)\<^sup>@(Suc k)" and ?u = "(u \<cdot> v)\<^sup>@(Suc m) \<cdot> u" assume "u \<noteq> \<epsilon>" and "v \<noteq> \<epsilon>" hence "u \<cdot> v \<noteq> \<epsilon>" and "?v \<noteq> \<epsilon>" and "?u \<noteq> \<epsilon>" by simp_all obtain r s where "r \<cdot> s = \<rho> ?v" and "s \<cdot> r = \<rho> ?u" using conjugE[OF assms]. then obtain k1 k2 where "?v = (r \<cdot> s)\<^sup>@Suc k1" and "?u = (s \<cdot> r)\<^sup>@Suc k2" using primroot_expE[OF \<open>?v \<noteq> \<epsilon>\<close>] primroot_expE[OF \<open>?u \<noteq> \<epsilon>\<close>] by metis hence eq: "(s \<cdot> r)\<^sup>@Suc k2 \<cdot> (r \<cdot> s)\<^sup>@Suc k1 = (u \<cdot> v)\<^sup>@(Suc m + Suc 0 + Suc k)" unfolding add_exps pow_one rassoc by simp have ineq: "2 \<le> Suc m + Suc 0 + Suc k" by simp consider (two_two) "2 \<le> Suc k1 \<and> 2 \<le> Suc k2"| (one_one) "Suc k1 = 1 \<and> Suc k2 = 1" | (two_one) "2 \<le> Suc k1 \<and> Suc k2 = 1" | (one_two) "Suc k1 = 1 \<and> 2 \<le> Suc k2" unfolding numerals One_nat_def Suc_le_mono by fastforce then show "u \<cdot> v = v \<cdot> u" proof (cases) case (two_two) with Lyndon_Schutzenberger(1)[OF eq _ _ ineq] have "(s \<cdot> r) \<cdot> (r \<cdot> s) = (r \<cdot> s) \<cdot> (s \<cdot> r)" using eqd_eq[of "s \<cdot> r" "r \<cdot> s" "r \<cdot> s" "s \<cdot> r"] by fastforce from comm_add_exps[OF this, of "Suc k2" "Suc k1", folded \<open>?v = (r \<cdot> s)\<^sup>@Suc k1\<close> \<open>?u = (s \<cdot> r)\<^sup>@Suc k2\<close>, folded shift_pow, unfolded pow_Suc] have "(u \<cdot> v) \<cdot> ((u \<cdot> v) \<^sup>@ m \<cdot> u) \<cdot> ((v \<cdot> u) \<cdot> (v \<cdot> u) \<^sup>@ k \<cdot> v) = (v \<cdot> u) \<cdot> (((v \<cdot> u) \<^sup>@ k) \<cdot> v) \<cdot> ((u \<cdot> v) \<cdot> (u \<cdot> v) \<^sup>@ m \<cdot> u)" unfolding rassoc. from eqd_eq[OF this, unfolded lenmorph] show "u \<cdot> v = v \<cdot> u" by fastforce next case (one_one) hence "(s \<cdot> r) \<^sup>@ Suc k2 \<cdot> (r \<cdot> s) \<^sup>@ Suc k1 = (s \<cdot> r) \<cdot> (r \<cdot> s)" using pow_one by simp from eq[unfolded conjunct1[OF one_one] conjunct2[OF one_one] pow_one'] pow_nemp_imprim[OF ineq, folded eq[unfolded this]] Lyndon_Schutzenberger_conjug[of "s \<cdot> r" "r \<cdot> s", OF conjugI'] have "(s \<cdot> r) \<cdot> (r \<cdot> s) = (r \<cdot> s) \<cdot> (s \<cdot> r)" by metis from comm_add_exps[OF this, of "Suc k2" "Suc k1", folded \<open>?v = (r \<cdot> s)\<^sup>@Suc k1\<close> \<open>?u = (s \<cdot> r)\<^sup>@Suc k2\<close>, folded shift_pow, unfolded pow_Suc] have "(u \<cdot> v) \<cdot> ((u \<cdot> v) \<^sup>@ m \<cdot> u) \<cdot> ((v \<cdot> u) \<cdot> (v \<cdot> u) \<^sup>@ k \<cdot> v) = (v \<cdot> u) \<cdot> (((v \<cdot> u) \<^sup>@ k) \<cdot> v) \<cdot> ((u \<cdot> v) \<cdot> (u \<cdot> v) \<^sup>@ m \<cdot> u)" unfolding rassoc. from eqd_eq[OF this, unfolded lenmorph] show "u \<cdot> v = v \<cdot> u" by fastforce next case (two_one) hence "?u = s \<cdot> r" using \<open>?u = (s \<cdot> r)\<^sup>@Suc k2\<close> by simp obtain l where "Suc k1 = Suc (Suc l)" using conjunct1[OF two_one, unfolded numerals(2)] Suc_le_D le_Suc_eq by metis from \<open>?v = (r \<cdot> s)\<^sup>@Suc k1\<close>[folded shift_pow, unfolded this] have "(v \<cdot> u) \<^sup>@ Suc k \<cdot> v = (r \<cdot> s)\<^sup>@Suc (Suc l)". from conj_pers_conj_comm_aux[OF \<open>?u = s \<cdot> r\<close> this] show "u \<cdot> v = v \<cdot> u". next case (one_two) hence "?v = r \<cdot> s" using \<open>?v = (r \<cdot> s)\<^sup>@Suc k1\<close> by simp obtain l where "Suc k2 = Suc (Suc l)" using conjunct2[OF one_two, unfolded numerals(2)] Suc_le_D le_Suc_eq by metis from \<open>?u = (s \<cdot> r)\<^sup>@Suc k2\<close>[unfolded this] have "(u \<cdot> v) \<^sup>@ Suc m \<cdot> u = (s \<cdot> r) \<^sup>@ Suc (Suc l)". from conj_pers_conj_comm_aux[OF \<open>?v = r \<cdot> s\<close>[folded shift_pow] this, symmetric] show "u \<cdot> v = v \<cdot> u". qed qed hide_fact conj_pers_conj_comm_aux subsection \<open>Covering uvvu\<close> lemma uv_fac_uvv: assumes "p \<cdot> u \<cdot> v \<le>p u \<cdot> v \<cdot> v" and "p \<noteq> \<epsilon>" and "p \<le>s w" and "w \<in> \<langle>{u,v}\<rangle>" shows "u \<cdot> v = v \<cdot> u" proof (rule nemp_comm) assume "u \<noteq> \<epsilon>" and "v \<noteq> \<epsilon>" obtain s where "u \<cdot> v \<cdot> v = p \<cdot> u \<cdot> v \<cdot> s" using \<open>p \<cdot> u \<cdot> v \<le>p u \<cdot> v \<cdot> v\<close> by (auto simp add: prefix_def) obtain p' where "u \<cdot> p' = p \<cdot> u" and "p' \<cdot> v \<cdot> s = v \<cdot> v" using eqdE[of u "v \<cdot> v" "p \<cdot> u" "v \<cdot> s", unfolded rassoc, OF \<open>u \<cdot> v \<cdot> v = p \<cdot> u \<cdot> v \<cdot> s\<close> suf_len']. hence "p' \<noteq> \<epsilon>" using \<open>p \<noteq> \<epsilon>\<close> by force have "p' \<cdot> v \<cdot> s = v \<cdot> v" using \<open>u \<cdot> v \<cdot> v = p \<cdot> u \<cdot> v \<cdot> s\<close> \<open>u \<cdot> p' = p \<cdot> u\<close> cancel rassoc by metis from mid_sq[OF this] have "v \<cdot> p' = p' \<cdot> v" by simp from this primroot_prim[OF \<open>v \<noteq> \<epsilon>\<close>] obtain r where "r = \<rho> v" and "r = \<rho> p'" and "primitive r" unfolding comm_primroots[OF \<open>v \<noteq> \<epsilon>\<close> \<open>p' \<noteq> \<epsilon>\<close>] by blast+ have "w \<in> \<langle>{u, v}\<rangle>" by fact obtain m where "p' = r\<^sup>@m \<cdot> r" using primroot_expE[OF \<open>p' \<noteq> \<epsilon>\<close>, folded \<open>r = \<rho> p'\<close>] power_Suc2 by metis hence "(u \<cdot> r\<^sup>@m) \<cdot> r \<le>s (r \<cdot> w) \<cdot> u" using \<open>u \<cdot> p' = p \<cdot> u\<close> \<open>p \<le>s w\<close> unfolding suf_def by force note mismatch_rule = mismatch_suf_comm_len[OF _ _ _ this, of "u \<cdot> r\<^sup>@m"] have "u \<cdot> r = r \<cdot> u" proof (rule mismatch_rule) have "w \<in> \<langle>{r, u}\<rangle>" using \<open>w \<in> \<langle>{u, v}\<rangle>\<close> \<open>r = \<rho> v\<close> \<open>v \<noteq> \<epsilon>\<close> doubleton_eq_iff gen_prim by metis thus "r \<cdot> w \<in> \<langle>{r, u}\<rangle>" by blast show "\<^bold>|u\<^bold>| \<le> \<^bold>|u \<cdot> r \<^sup>@ m\<^bold>|" by simp show "u \<cdot> r\<^sup>@m \<in> \<langle>{r, u}\<rangle>" by (simp add: gen_in hull.prod_cl power_in) qed simp thus "u \<cdot> v = v \<cdot> u" using \<open>r = \<rho> v\<close> comm_primroot_conv by auto qed lemmas uv_fac_uvv_suf = uv_fac_uvv[reversed, unfolded rassoc] lemma assumes "p \<cdot> u \<cdot> v \<cdot> u \<cdot> q = u \<cdot> v \<cdot> v \<cdot> u" and "p \<noteq> \<epsilon>" and "q \<noteq> \<epsilon>" shows "u \<cdot> v = v \<cdot> u" oops \<comment> \<open>counterexample: v = abaaba, u = a, p = aab, q = baa; aab.a.abaaba.a.baa = a.abaaba.abaaba.a\<close> lemma uvu_pref_uvv: assumes "p \<cdot> u \<cdot> v \<cdot> v \<cdot> s = u \<cdot> v \<cdot> u \<cdot> q" and "p <p u" and "q \<le>p w" and "s \<le>p w'" and "w \<in> \<langle>{u,v}\<rangle>" and "w' \<in> \<langle>{u,v}\<rangle>" and "\<^bold>|u\<^bold>| \<le> \<^bold>|s\<^bold>|" shows "u \<cdot> v = v \<cdot> u" proof(rule nemp_comm) \<comment> \<open>Preliminaries\<close> assume "u \<noteq> \<epsilon>" and "v \<noteq> \<epsilon>" hence "u \<cdot> v \<noteq> \<epsilon>" by blast have "\<^bold>|p \<cdot> u \<cdot> v\<^bold>| \<le> \<^bold>|u \<cdot> v \<cdot> u\<^bold>|" using \<open>p <p u\<close> unfolding lenmorph by (simp add: prefix_length_less less_imp_le) \<comment> \<open>p commutes with @{term "u \<cdot> v"}\<close> have "p \<cdot> (u \<cdot> v) = (u \<cdot> v) \<cdot> p" by (rule pref_marker[of "u \<cdot> v \<cdot> u"], simp, rule eq_le_pref, unfold rassoc, fact+) \<comment> \<open>equality which will yield the main result\<close> have "p \<cdot> v \<cdot> s = u \<cdot> q" proof- have "((u \<cdot> v) \<cdot> p) \<cdot> v \<cdot> s = (u \<cdot> v) \<cdot> u \<cdot> q" unfolding \<open>p \<cdot> u \<cdot> v = (u \<cdot> v) \<cdot> p\<close>[symmetric] unfolding rassoc by fact from this[unfolded rassoc cancel] show ?thesis. qed hence "p \<cdot> v \<cdot> s \<le>p u \<cdot> w" using \<open>q \<le>p w\<close> by force then show "u \<cdot> v = v \<cdot> u" proof (cases "p = \<epsilon>") assume "p = \<epsilon>" thm mismatch_pref_comm note local_rule = mismatch_pref_comm_len[OF _ _ \<open>s \<le>p w'\<close> _ \<open>\<^bold>|u\<^bold>| \<le> \<^bold>|s\<^bold>|\<close>, of v w, symmetric] show "u \<cdot> v = v \<cdot> u" proof (rule local_rule) show "w \<in> \<langle>{v, u}\<rangle>" using \<open>w \<in> \<langle>{u,v}\<rangle>\<close> by (simp add: insert_commute) show "v \<cdot> s \<le>p u \<cdot> w" using \<open>p = \<epsilon>\<close> \<open>p \<cdot> v \<cdot> s = u \<cdot> q\<close> \<open>q \<le>p w\<close> by simp show "w' \<in> \<langle>{v, u}\<rangle>" using \<open>w' \<in> \<langle>{u, v}\<rangle>\<close> insert_commute by metis qed next assume "p \<noteq> \<epsilon>" show "u \<cdot> v = v \<cdot> u" proof (rule ccontr) obtain r where "r = \<rho> p" and "r = \<rho> (u \<cdot> v)" using \<open>p \<cdot> u \<cdot> v = (u \<cdot> v) \<cdot> p\<close>[symmetric, unfolded comm_primroots[OF \<open>u \<cdot> v \<noteq> \<epsilon>\<close> \<open>p \<noteq> \<epsilon>\<close>]] by blast obtain k m where "r\<^sup>@k = p" and "r\<^sup>@m = u \<cdot> v" using \<open>u \<cdot> v \<noteq> \<epsilon>\<close> \<open>p \<noteq> \<epsilon>\<close> \<open>r = \<rho> p\<close> \<open>r = \<rho> (u \<cdot> v)\<close> primroot_expE by metis \<comment> \<open>Idea: maximal r-prefix of @{term "p \<cdot> v \<cdot> s"} is @{term "p \<cdot> bin_code_lcp"}, since the maximal r-prefix of @{term "v \<cdot> u"} is @{term "v \<cdot> u \<and>\<^sub>p u \<cdot> v"}; on the other hand, maximal r-prefix of @{term "u \<cdot> w \<cdot> bin_code_lcp"} is at least @{term "u \<cdot> bin_code_lcp"}, since this is, in particular, a prefix of @{term "u \<cdot> v \<cdot> u \<cdot> v \<in> r*"}\<close> assume "u \<cdot> v \<noteq> v \<cdot> u" then interpret binary_code u v by (unfold_locales) term "p \<cdot> v \<cdot> s = u \<cdot> q" have "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_snd] \<le>p u \<cdot> w \<cdot> bin_code_lcp" proof- have "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_snd] \<le>p p \<cdot> v \<cdot> w' \<cdot> bin_code_lcp" unfolding pref_cancel_conv using pref_prolong[OF bin_snd_mismatch bin_lcp_pref_all_hull, OF \<open>w' \<in> \<langle>{u,v}\<rangle>\<close>]. note local_rule = ruler_le[OF this] have "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_snd] \<le>p p \<cdot> v \<cdot> s" proof (rule local_rule) show "p \<cdot> v \<cdot> s \<le>p p \<cdot> v \<cdot> w' \<cdot> bin_code_lcp" using \<open>s \<le>p w'\<close> by fastforce show "\<^bold>|p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_snd]\<^bold>| \<le> \<^bold>|p \<cdot> v \<cdot> s\<^bold>|" using bin_lcp_short \<open>\<^bold>|u\<^bold>| \<le> \<^bold>|s\<^bold>|\<close> by force qed from pref_ext[OF pref_trans[OF this \<open>p \<cdot> v \<cdot> s \<le>p u \<cdot> w\<close>]] show "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_snd] \<le>p u \<cdot> w \<cdot> bin_code_lcp" by force qed moreover have "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_fst] \<le>p u \<cdot> w \<cdot> bin_code_lcp" proof (rule pref_trans[of _ "u \<cdot> bin_code_lcp"]) show "u \<cdot> bin_code_lcp \<le>p u \<cdot> w \<cdot> bin_code_lcp" using bin_lcp_pref_all_hull[OF \<open>w \<in> \<langle>{u,v}\<rangle>\<close>] by auto show "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_fst] \<le>p u \<cdot> bin_code_lcp" proof (rule ruler_le) show "\<^bold>|p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_fst]\<^bold>| \<le> \<^bold>|u \<cdot> bin_code_lcp\<^bold>|" unfolding lenmorph using prefix_length_less[OF \<open>p <p u\<close>] by simp show "u \<cdot> bin_code_lcp \<le>p r \<^sup>@ (m + m)" unfolding add_exps \<open>r\<^sup>@m = u \<cdot> v\<close> rassoc pref_cancel_conv using bin_lcp_pref_snd_fst pref_prolong prefix_def by metis show "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_fst] \<le>p r \<^sup>@ (m + m)" proof (rule pref_trans) show "p \<cdot> bin_code_lcp \<cdot> [bin_code_mismatch_fst] \<le>p r\<^sup>@(k+m)" unfolding power_add \<open>r \<^sup>@ k = p\<close> \<open>r \<^sup>@ m = u \<cdot> v\<close> pref_cancel_conv using bin_fst_mismatch'. show "r \<^sup>@ (k + m) \<le>p r \<^sup>@ (m + m)" unfolding power_add \<open>r \<^sup>@ k = p\<close> \<open>r \<^sup>@ m = u \<cdot> v\<close> \<open>p \<cdot> u \<cdot> v = (u \<cdot> v) \<cdot> p\<close> using \<open>p <p u\<close> by force qed qed qed ultimately show False using bin_mismatch_neq by (force simp add: prefix_def) qed qed qed lemma uvu_pref_uvvu: assumes "p \<cdot> u \<cdot> v \<cdot> v \<cdot> u = u \<cdot> v \<cdot> u \<cdot> q" and "p <p u" and "q \<le>p w" and " w \<in> \<langle>{u,v}\<rangle>" shows "u \<cdot> v = v \<cdot> u" using uvu_pref_uvv[OF \<open>p \<cdot> u \<cdot> v \<cdot> v \<cdot> u = u \<cdot> v \<cdot> u \<cdot> q\<close> \<open>p <p u\<close> \<open>q \<le>p w\<close> _ \<open>w \<in> \<langle>{u,v}\<rangle>\<close>, of u] by blast lemma uvu_pref_uvvu_interpret: assumes interp: "p u \<cdot> v \<cdot> v \<cdot> u s \<sim>\<^sub>\<I> ws" and "[u, v, u] \<le>p ws" and "ws \<in> lists {u,v}" shows "u \<cdot> v = v \<cdot> u" proof- note fac_interpretE[OF interp] obtain ws' where "[u,v,u] \<cdot> ws' = ws" and "ws' \<in> lists {u,v}" using \<open>[u, v, u] \<le>p ws\<close> \<open>ws \<in> lists {u,v}\<close> by (force simp add: prefix_def) have "p \<cdot> u \<cdot> v \<cdot> v \<cdot> u \<cdot> s = u \<cdot> v \<cdot> u \<cdot> concat ws'" using \<open>p \<cdot> (u \<cdot> v \<cdot> v \<cdot> u) \<cdot> s = concat ws\<close>[folded \<open>[u,v,u] \<cdot> ws' = ws\<close>, unfolded concat_morph rassoc] by simp from lenarg[OF this, unfolded lenmorph] have "\<^bold>|s\<^bold>| \<le> \<^bold>|concat ws'\<^bold>|" by auto hence "s \<le>s concat ws'" using eqd[reversed, OF \<open>p \<cdot> u \<cdot> v \<cdot> v \<cdot> u \<cdot> s = u \<cdot> v \<cdot> u \<cdot> concat ws'\<close>[unfolded lassoc]] by blast note local_rule = uvu_pref_uvv[of p u v u "concat ws'\<^sup><\<inverse>s" "concat ws'" u] show "u \<cdot> v = v \<cdot> u" proof (rule local_rule) show "p <p u" using \<open>p <p hd ws\<close> pref_hd_eq[OF \<open>[u, v, u] \<le>p ws\<close> list.distinct(1)[of u "[v,u]", symmetric]] by force have "p \<cdot> u \<cdot> v \<cdot> v \<cdot> u \<cdot> s = u \<cdot> v \<cdot> u \<cdot> (concat ws'\<^sup><\<inverse>s) \<cdot> s" using \<open>p \<cdot> u \<cdot> v \<cdot> v \<cdot> u \<cdot> s = u \<cdot> v \<cdot> u \<cdot> concat ws'\<close> unfolding rq_suf[OF \<open>s \<le>s concat ws'\<close>]. thus "p \<cdot> u \<cdot> v \<cdot> v \<cdot> u = u \<cdot> v \<cdot> u \<cdot> concat ws'\<^sup><\<inverse>s" by simp show "concat ws' \<in> \<langle>{u,v}\<rangle>" using \<open>ws' \<in> lists {u,v}\<close> by blast show "concat ws'\<^sup><\<inverse>s \<le>p concat ws'" using rq_suf[OF \<open>s \<le>s concat ws'\<close>] by fast qed auto qed lemmas uvu_suf_uvvu = uvu_pref_uvvu[reversed, unfolded rassoc] and uvu_suf_uvv = uvu_pref_uvv[reversed, unfolded rassoc] lemma uvu_suf_uvvu_interp: "p u \<cdot> v \<cdot> v \<cdot> u s \<sim>\<^sub>\<I> ws \<Longrightarrow> [u, v, u] \<le>s ws \<Longrightarrow> ws \<in> lists {u,v} \<Longrightarrow> u \<cdot> v = v \<cdot> u" by (rule uvu_pref_uvvu_interpret[reversed, unfolded rassoc clean_emp, symmetric, of p u v s ws], simp, force, simp add: image_iff rev_in_lists rev_map) subsection \<open>Conjugate words\<close> lemma conjug_pref_suf_mismatch: assumes "w1 \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>" and "w2 \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>" and "r \<cdot> w1 = w2 \<cdot> s" shows "r = s \<or> r = \<epsilon> \<or> s = \<epsilon>" proof (rule ccontr) assume "\<not> (r = s \<or> r = \<epsilon> \<or> s = \<epsilon>)" hence "r \<noteq> s" and "r \<noteq> \<epsilon>" and "s \<noteq> \<epsilon>" by simp_all from assms show False proof (induct "\<^bold>|w1\<^bold>|" arbitrary: w1 w2 rule: less_induct) case less have "w1 \<in> \<langle>{r,s}\<rangle>" using \<open>w1 \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>\<close> by force obtain w1' where "(w1 = \<epsilon> \<or> w1 = r \<cdot> s \<cdot> w1' \<or> w1 = s \<cdot> r \<cdot> w1') \<and> w1' \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>" using hull.cases[OF \<open>w1 \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>\<close>] empty_iff insert_iff mult_assoc \<open>w1 \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> by metis hence "w1' \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>" and cases1: "(w1 = \<epsilon> \<or> w1 = r \<cdot> s \<cdot> w1' \<or> w1 = s \<cdot> r \<cdot> w1')" by blast+ hence "w1' \<in> \<langle>{r,s}\<rangle>" by force obtain w2' where "(w2 = \<epsilon> \<or> w2 = r \<cdot> s \<cdot> w2' \<or> w2 = s \<cdot> r \<cdot> w2') \<and> w2' \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>" using hull.cases[OF \<open>w2 \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>\<close>] empty_iff insert_iff mult_assoc \<open>w1 \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> by metis hence "w2' \<in> \<langle>{r\<cdot>s,s\<cdot>r}\<rangle>" and cases2: "(w2 = \<epsilon> \<or> w2 = r \<cdot> s \<cdot> w2' \<or> w2 = s \<cdot> r \<cdot> w2')" by blast+ hence "w2' \<in> \<langle>{r,s}\<rangle>" by force consider (empty2) "w2 = \<epsilon>" | (sr2) "w2 = s \<cdot> r \<cdot> w2'" | (rs2) "w2 = r \<cdot> s \<cdot> w2'"using cases2 by blast thus False proof (cases) case empty2 consider (empty1) "w1 = \<epsilon>" | (sr1) "w1 = s \<cdot> r \<cdot> w1'" | (rs1) "w1 = r \<cdot> s \<cdot> w1'" using cases1 by blast thus False proof (cases) case empty1 show False using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded empty1 empty2 rassoc] \<open>r \<noteq> s\<close> by simp next case sr1 show False using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded sr1 empty2 rassoc] \<open>r \<noteq> \<epsilon>\<close> fac_triv by auto next case rs1 show False using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs1 empty2 rassoc clean_emp] \<open>r \<noteq> \<epsilon>\<close> fac_triv[of "r \<cdot> r" s w1', unfolded rassoc] by force qed next case sr2 have "r \<cdot> s = s \<cdot> r" using \<open>w2' \<in> \<langle>{r,s}\<rangle>\<close> \<open>w1 \<in> \<langle>{r,s}\<rangle>\<close> \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded sr2 rassoc] by (mismatch) consider (empty1) "w1 = \<epsilon>" | (sr1) "w1 = s \<cdot> r \<cdot> w1'" | (rs1) "w1 = r \<cdot> s \<cdot> w1'" using cases1 by blast thus False proof (cases) case empty1 then show False using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded sr2 empty1 rassoc cancel clean_emp, symmetric] \<open>s \<noteq> \<epsilon>\<close> fac_triv by blast next case rs1 then have "r \<cdot> s = s \<cdot> r" using \<open>w2' \<in> \<langle>{r,s}\<rangle>\<close> \<open>w1' \<in> \<langle>{r,s}\<rangle>\<close> \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs1 sr2 rassoc cancel] by mismatch hence "r \<cdot> w1' = w2' \<cdot> s" using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs1 sr2] rassoc cancel by metis from less.hyps[OF _ \<open>w1' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>w2' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> this] show False using lenarg[OF \<open>w1 = r \<cdot> s \<cdot> w1'\<close>, unfolded lenmorph] nemp_len[OF \<open>s \<noteq> \<epsilon>\<close>] by linarith next case sr1 then have "r \<cdot> s = s \<cdot> r" using \<open>w2' \<in> \<langle>{r,s}\<rangle>\<close> \<open>w1' \<in> \<langle>{r,s}\<rangle>\<close> \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded sr1 sr2 rassoc cancel] by mismatch hence "r \<cdot> w1' = w2' \<cdot> s" using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded sr1 sr2] rassoc cancel by metis from less.hyps[OF _ \<open>w1' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>w2' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> this] show False using less.hyps[OF _ \<open>w1' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>w2' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>r \<cdot> w1' = w2' \<cdot> s\<close>] lenarg[OF \<open>w1 = s \<cdot> r \<cdot> w1'\<close>, unfolded lenmorph] nemp_len[OF \<open>s \<noteq> \<epsilon>\<close>] by linarith qed next case rs2 consider (empty1) "w1 = \<epsilon>" | (sr1) "w1 = s \<cdot> r \<cdot> w1'" | (rs1) "w1 = r \<cdot> s \<cdot> w1'" using cases1 by blast thus False proof (cases) case empty1 then show False using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs2 empty1 rassoc cancel] \<open>s \<noteq> \<epsilon>\<close> by blast next case rs1 then have "r \<cdot> s = s \<cdot> r" using \<open>w2' \<in> \<langle>{r,s}\<rangle>\<close> \<open>w1' \<in> \<langle>{r,s}\<rangle>\<close> \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs2 rs1 rassoc cancel] by mismatch hence "r \<cdot> w1' = w2' \<cdot> s" using \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs1 rs2] rassoc cancel by metis from less.hyps[OF _ \<open>w1' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>w2' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> this] show False using less.hyps[OF _ \<open>w1' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>w2' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>r \<cdot> w1' = w2' \<cdot> s\<close>] lenarg[OF \<open>w1 = r \<cdot> s \<cdot> w1'\<close>, unfolded lenmorph] nemp_len[OF \<open>s \<noteq> \<epsilon>\<close>] by linarith next case sr1 then show False using less.hyps[OF _ \<open>w1' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>w2' \<in> \<langle>{r \<cdot> s, s \<cdot> r}\<rangle>\<close> \<open>r \<cdot> w1 = w2 \<cdot> s\<close>[unfolded rs2 sr1 rassoc cancel]] lenarg[OF \<open>w1 = s \<cdot> r \<cdot> w1'\<close>, unfolded lenmorph] nemp_len[OF \<open>s \<noteq> \<epsilon>\<close>] by linarith qed qed qed qed lemma conjug_conjug_primroots: assumes "u \<noteq> \<epsilon>" and "r \<noteq> \<epsilon>" and "\<rho> (u \<cdot> v) = r \<cdot> s" and "\<rho> (v \<cdot> u) = s \<cdot> r" obtains k m where "(r \<cdot> s)\<^sup>@k \<cdot> r = u" and "(s \<cdot> r)\<^sup>@m \<cdot> s = v" proof- have "v \<cdot> u \<noteq> \<epsilon>" and "u \<cdot> v \<noteq> \<epsilon>" using \<open>u \<noteq> \<epsilon>\<close> by blast+ have "\<rho> (s \<cdot> r) = s \<cdot> r" using primroot_idemp[OF \<open>v \<cdot> u \<noteq> \<epsilon>\<close>, unfolded \<open>\<rho> (v \<cdot> u) = s \<cdot> r\<close>]. obtain n where "(r \<cdot> s)\<^sup>@Suc n = u \<cdot> v" using primroot_expE[OF \<open>u \<cdot> v \<noteq> \<epsilon>\<close>, unfolded \<open>\<rho> (u \<cdot> v) = r \<cdot> s\<close>]. obtain n' where "(s \<cdot> r)\<^sup>@Suc n' = v \<cdot> u" using primroot_expE[OF \<open>v \<cdot> u \<noteq> \<epsilon>\<close>, unfolded \<open>\<rho> (v \<cdot> u) = s \<cdot> r\<close>]. have "(s \<cdot> u) \<cdot> (s \<cdot> r) = (s \<cdot> r) \<cdot> (s \<cdot> u)" proof (rule pref_marker) show "(s \<cdot> u) \<cdot> s \<cdot> r \<le>p s \<cdot> (r \<cdot> s)\<^sup>@(Suc n+ Suc n)" unfolding rassoc add_exps \<open>(r \<cdot> s)\<^sup>@Suc n = u \<cdot> v\<close> unfolding lassoc \<open>(s \<cdot> r)\<^sup>@Suc n' = v \<cdot> u\<close>[symmetric] pow_Suc by force have aux: "(s \<cdot> r) \<cdot> s \<cdot> (r \<cdot> s) \<^sup>@ (Suc n + Suc n) = s \<cdot> (r \<cdot> s)\<^sup>@(Suc n + Suc n) \<cdot> (r \<cdot> s)" by (simp add: pow_comm) show "s \<cdot> (r \<cdot> s) \<^sup>@ (Suc n + Suc n) \<le>p (s \<cdot> r) \<cdot> s \<cdot> (r \<cdot> s) \<^sup>@ (Suc n + Suc n)" unfolding aux pref_cancel_conv by blast qed from comm_primroot_exp[OF primroot_nemp[OF \<open>v \<cdot> u \<noteq> \<epsilon>\<close>, unfolded \<open>\<rho> (v \<cdot> u) = s \<cdot> r\<close>] this] obtain k where "(s \<cdot> r)\<^sup>@Suc k = s \<cdot> u" using nemp_pow_SucE[OF suf_nemp[OF \<open>u \<noteq> \<epsilon>\<close>, of s]] \<open>\<rho> (s \<cdot> r) = s \<cdot> r\<close> by metis hence u: "(r \<cdot> s)\<^sup>@k \<cdot> r = u" unfolding pow_Suc rassoc cancel shift_pow by fast from exp_pref_cancel[OF \<open>(r \<cdot> s)\<^sup>@Suc n = u \<cdot> v\<close>[folded this, unfolded rassoc, symmetric]] have "r \<cdot> v = (r \<cdot> s) \<^sup>@ (Suc n - k)". from nemp_pow_SucE[OF _ this] obtain m where "r \<cdot> v = (r \<cdot> s)\<^sup>@Suc m" using \<open>r \<noteq> \<epsilon>\<close> by blast from this[unfolded pow_Suc rassoc cancel shift_pow[symmetric], symmetric] have v: "(s \<cdot> r)\<^sup>@m \<cdot> s = v". show thesis using that[OF u v]. qed subsection \<open>Predicate ``commutes''\<close> definition commutes :: "'a list set \<Rightarrow> bool" where "commutes A = (\<forall>x y. x \<in> A \<longrightarrow> y \<in> A \<longrightarrow> x\<cdot>y = y\<cdot>x)" lemma commutesE: "commutes A \<Longrightarrow> x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x\<cdot>y = y\<cdot>x" using commutes_def by blast lemma commutes_root: assumes "commutes A" obtains r where "\<And>x. x \<in> A \<Longrightarrow> x \<in> r*" using assms comm_primroots emp_all_roots primroot_is_root unfolding commutes_def by metis lemma commutes_primroot: assumes "commutes A" obtains r where "\<And>x. x \<in> A \<Longrightarrow> x \<in> r*" and "primitive r" using commutes_root[OF assms] emp_all_roots prim_sing primroot_is_root primroot_prim root_trans by metis lemma commutesI [intro]: "(\<And>x y. x \<in> A \<Longrightarrow> y \<in> A \<Longrightarrow> x\<cdot>y = y\<cdot>x) \<Longrightarrow> commutes A" unfolding commutes_def by blast lemma commutesI': assumes "x \<noteq> \<epsilon>" and "\<And>y. y \<in> A \<Longrightarrow> x\<cdot>y = y\<cdot>x" shows "commutes A" proof- have "\<And>x' y'. x' \<in> A \<Longrightarrow> y' \<in> A \<Longrightarrow> x'\<cdot>y' = y'\<cdot>x'" proof- fix x' y' assume "x' \<in> A" "y' \<in> A" hence "x'\<cdot>x = x\<cdot>x'" and "y'\<cdot>x = x\<cdot>y'" using assms(2) by auto+ from comm_trans[OF this assms(1)] show "x'\<cdot>y' = y'\<cdot>x'". qed thus ?thesis by (simp add: commutesI) qed lemma commutesI_root: "\<forall>x \<in> A. x \<in> t* \<Longrightarrow> commutes A" by (meson comm_root commutesI) lemma commutes_sub: "commutes A \<Longrightarrow> B \<subseteq> A \<Longrightarrow> commutes B" by (simp add: commutes_def subsetD) lemma commutes_insert: "commutes A \<Longrightarrow> x \<in> A \<Longrightarrow> x \<noteq> \<epsilon> \<Longrightarrow> x\<cdot>y = y\<cdot>x \<Longrightarrow> commutes (insert y A)" using commutesE[of A x] commutesI'[of x "insert y A"] insertE by blast lemma commutes_emp [simp]: "commutes {\<epsilon>, w}" by (simp add: commutes_def) lemma commutes_emp'[simp]: "commutes {w, \<epsilon>}" by (simp add: commutes_def) lemma commutes_cancel: "commutes (insert y (insert (x \<cdot> y) A)) \<Longrightarrow> commutes (insert y (insert x A))" proof fix u v assume com: "commutes (insert y (insert (x \<cdot> y) A))" and "u \<in> insert y (insert x A)" "v \<in> insert y (insert x A)" then consider "u = y" | "u = x" | "u \<in> A" by blast note u_cases = this consider "v = y" | "v = x" | "v \<in> A" using \<open>v \<in> insert y (insert x A)\<close> by blast note v_cases = this have "y \<cdot> (x \<cdot> y) = (x \<cdot> y) \<cdot> y" using \<open>commutes (insert y (insert (x \<cdot> y) A))\<close> commutesE by blast hence "x \<cdot> y = y \<cdot> x" by simp have[simp]: "w \<in> A \<Longrightarrow> y \<cdot> w = w \<cdot> y" for w using com by (simp add: commutesE) hence[simp]: "w \<in> A \<Longrightarrow> x \<cdot> w = w \<cdot> x" for w using \<open>x \<cdot> y = y \<cdot> x\<close> com commutesE comm_trans insertCI shifts_rev(37) by metis have[simp]: "u \<in> A \<Longrightarrow> v \<in> A \<Longrightarrow> u \<cdot> v = v \<cdot> u" using com commutesE by blast show "u \<cdot> v = v \<cdot> u" by (rule u_cases, (rule v_cases, simp_all add: \<open>x \<cdot> y = y \<cdot> x\<close> com)+) qed subsection \<open>Strong elementary lemmas\<close> text\<open>Discovered by smt\<close> lemma xyx_per_comm: assumes "x\<cdot>y\<cdot>x \<le>p q\<cdot>x\<cdot>y\<cdot>x" and "q \<noteq> \<epsilon>" and "q \<le>p y \<cdot> q" shows "x\<cdot>y = y\<cdot>x" (* by (smt (verit, best) assms(1) assms(2) assms(3) pref_cancel pref_cancel' pref_marker pref_prolong prefix_same_cases root_comm_root triv_pref) *) proof(cases) assume "x \<cdot> y \<le>p q" from pref_marker[OF \<open>q \<le>p y \<cdot> q\<close> this] show "x \<cdot> y = y \<cdot> x". next have "(x \<cdot> y) \<cdot> x \<le>p q \<cdot> x \<cdot> y \<cdot> x" unfolding rassoc by fact assume "\<not> x \<cdot> y \<le>p q" hence "q \<le>p x \<cdot> y" using ruler_prefE[OF \<open>(x \<cdot> y) \<cdot> x \<le>p q \<cdot> x \<cdot> y \<cdot> x\<close>] by argo from pref_prolong[OF \<open>q \<le>p y \<cdot> q\<close> this, unfolded lassoc] have"q \<le>p (y \<cdot> x) \<cdot> y". from ruler_pref'[OF this, THEN disjE] \<open>q \<le>p x \<cdot> y\<close> have "q \<le>p y \<cdot> x" using pref_trans[OF _ \<open>q \<le>p x \<cdot> y\<close>, of "y \<cdot> x", THEN pref_comm_eq] by metis from pref_cancel'[OF this, of x] have "x \<cdot> q = q \<cdot> x" using pref_marker[OF \<open>x \<cdot> y \<cdot> x \<le>p q \<cdot> x \<cdot> y \<cdot> x\<close>, of x] by blast hence "x \<cdot> y \<cdot> x \<le>p x \<cdot> x \<cdot> y \<cdot> x" using root_comm_root[OF _ _ \<open>q \<noteq> \<epsilon>\<close>, of "x \<cdot> y \<cdot> x" x] \<open>x \<cdot> y \<cdot> x \<le>p q \<cdot> x \<cdot> y \<cdot> x\<close> by fast thus "x\<cdot>y = y\<cdot>x" by mismatch qed lemma two_elem_root_suf_comm: assumes "u \<le>p v \<cdot> u" and "v \<le>s p \<cdot> u" and "p \<in> \<langle>{u,v}\<rangle>" shows "u \<cdot> v = v \<cdot> u" using root_suf_comm[OF \<open>u \<le>p v \<cdot> u\<close> two_elem_suf[OF \<open>v \<le>s p \<cdot> u\<close> \<open>p \<in> \<langle>{u,v}\<rangle>\<close>], symmetric]. lemma two_elem_root_suf_comm': assumes "u \<le>p v \<cdot> u" and "q \<le>s p" and "q \<cdot> u \<cdot> v = v \<cdot> q \<cdot> u" and "p \<in> \<langle>{u,v}\<rangle>" shows "u \<cdot> v = v \<cdot> u" proof (rule nemp_comm) assume "u \<noteq> \<epsilon>" and "v \<noteq> \<epsilon>" have "p \<in> \<langle>{u, \<rho> v}\<rangle>" using gen_prim[OF \<open>v \<noteq> \<epsilon>\<close> \<open>p \<in> \<langle>{u,v}\<rangle>\<close>]. have "(q \<cdot> u) \<cdot> v = v \<cdot> (q \<cdot> u)" using \<open>q \<cdot> u \<cdot> v = v \<cdot> q \<cdot> u\<close> by fastforce hence "(q \<cdot> u) \<cdot> \<rho> v = \<rho> v \<cdot> (q \<cdot> u)" unfolding comm_primroot_conv[OF \<open>v \<noteq> \<epsilon>\<close>]. have "u \<le>p \<rho> v \<cdot> u" using \<open>u \<le>p v \<cdot> u\<close> \<open>v \<noteq> \<epsilon>\<close> comm_primroot_conv root_comm_root by metis have "\<rho> v \<le>s q \<cdot> u" using suf_nemp[OF \<open>u \<noteq> \<epsilon>\<close>] primroot_suf \<open>(q \<cdot> u) \<cdot> v = v \<cdot> q \<cdot> u\<close> \<open>v \<noteq> \<epsilon>\<close> comm_primroots by metis hence "\<rho> v \<le>s p \<cdot> u" using suf_trans \<open>q \<le>s p\<close> by (auto simp add: suf_def) from two_elem_root_suf_comm[OF \<open>u \<le>p \<rho> v \<cdot> u\<close> this \<open>p \<in> \<langle>{u,\<rho> v}\<rangle>\<close>] have "u \<cdot> \<rho> v = \<rho> v \<cdot> u". thus "u \<cdot> v = v \<cdot> u" using \<open>v \<noteq> \<epsilon>\<close> comm_primroot_conv by metis qed subsection \<open>Binary words without a letter square\<close> lemma no_repetition_list: assumes "set ws \<subseteq> {a,b}" and not_per: "\<not> ws \<le>p [a,b] \<cdot> ws" "\<not> ws \<le>p [b,a] \<cdot> ws" and not_square: "\<not> [a,a] \<le>f ws" and "\<not> [b,b] \<le>f ws" shows False using assms proof (induction ws, simp) case (Cons d ws) show ?case proof (rule "Cons.IH") show "set ws \<subseteq> {a,b}" using \<open>set (d # ws) \<subseteq> {a, b}\<close> by auto have "ws \<noteq> \<epsilon>" using "Cons.IH" Cons.prems by force from hd_tl[OF this] have "hd ws \<noteq> d" using Cons.prems(1,4-5) hd_pref[OF \<open>ws \<noteq> \<epsilon>\<close>] by force thus "\<not> [a, a] \<le>f ws" and "\<not> [b, b] \<le>f ws" using Cons.prems(4-5) unfolding sublist_code(3) by blast+ show "\<not> ws \<le>p [a, b] \<cdot> ws" proof (rule notI) assume "ws \<le>p [a, b] \<cdot> ws" from pref_hd_eq[OF this \<open>ws \<noteq> \<epsilon>\<close>] have "hd ws = a" by simp hence "d = b" using \<open>set (d # ws) \<subseteq> {a, b}\<close> \<open>hd ws \<noteq> d\<close> by auto show False using \<open>ws \<le>p [a, b] \<cdot> ws\<close> \<open>\<not> d # ws \<le>p [b, a] \<cdot> d # ws\<close>[unfolded \<open>d = b\<close>] by force qed show "\<not> ws \<le>p [b, a] \<cdot> ws" proof (rule notI) assume "ws \<le>p [b, a] \<cdot> ws" from pref_hd_eq[OF this \<open>ws \<noteq> \<epsilon>\<close>] have "hd ws = b" by simp hence "d = a" using \<open>set (d # ws) \<subseteq> {a, b}\<close> \<open>hd ws \<noteq> d\<close> by auto show False using \<open>ws \<le>p [b, a] \<cdot> ws\<close> \<open>\<not> d # ws \<le>p [a, b] \<cdot> d # ws\<close>[unfolded \<open>d = a\<close>] by force qed qed qed lemma hd_Cons_append[intro,simp]: "hd ((a#v) \<cdot> u) = a" by simp lemma no_repetition_list_bin: fixes ws :: "binA list" assumes not_square: "\<And> c. \<not> [c,c] \<le>f ws" shows "ws \<le>p [hd ws, 1-(hd ws)] \<cdot> ws" proof (cases "ws = \<epsilon>", simp) assume "ws \<noteq> \<epsilon>" have set: "set ws \<subseteq> {hd ws, 1-hd ws}" using swap_UNIV by auto have "\<not> ws \<le>p [1 - hd ws, hd ws] \<cdot> ws" using pref_hd_eq[OF _ \<open>ws \<noteq> \<epsilon>\<close>, of "[1 - hd ws, hd ws] \<cdot> ws"] bin_swap_neq' unfolding hd_Cons_append by blast from no_repetition_list[OF set _ this not_square not_square] show "ws \<le>p [hd ws, 1-(hd ws)] \<cdot> ws" by blast qed lemma per_root_hd_last_root: assumes "ws \<le>p [a,b] \<cdot> ws" and "hd ws \<noteq> last ws" shows "ws \<in> [a,b]*" using assms proof (induction "\<^bold>|ws\<^bold>|" arbitrary: ws rule: less_induct) case less then show ?case proof (cases "ws = \<epsilon>", simp) assume "ws \<noteq> \<epsilon>" with \<open>hd ws \<noteq> last ws\<close> have *: "[hd ws, hd (tl ws)] \<cdot> tl (tl ws) = ws" using append_Cons last_ConsL[of "tl ws" "hd ws"] list.exhaust_sel[of ws] hd_tl by metis have ind: "\<^bold>|tl (tl ws)\<^bold>| < \<^bold>|ws\<^bold>|" using \<open>ws \<noteq> \<epsilon>\<close> by auto have "[hd ws, hd (tl ws)] \<cdot> tl (tl ws) \<le>p [a,b] \<cdot> ws " unfolding * using \<open>ws \<le>p [a, b] \<cdot> ws\<close>. hence "[a,b] = [hd ws, hd (tl ws)]" by simp hence "hd ws = a" by simp have "tl (tl ws) \<le>p [a,b] \<cdot> tl (tl ws)" unfolding pref_cancel_conv[of "[a,b]" "tl (tl ws)", symmetric] \<open>[a,b] = [hd ws, hd (tl ws)]\<close> * using \<open>ws \<le>p [a, b] \<cdot> ws\<close>[unfolded \<open>[a,b] = [hd ws, hd (tl ws)]\<close>]. have "tl (tl ws) \<in> [a, b]*" proof (cases "tl (tl ws) = \<epsilon>", simp) assume "tl (tl ws) \<noteq> \<epsilon>" from pref_hd_eq[OF \<open>tl (tl ws) \<le>p [a, b] \<cdot> tl (tl ws)\<close> this] have "hd (tl (tl ws)) = a" by simp have "last (tl (tl ws)) = last ws" using \<open>tl (tl ws) \<noteq> \<epsilon>\<close> last_tl tl_Nil by metis from \<open>hd ws \<noteq> last ws\<close>[unfolded \<open>hd ws =a\<close>, folded this \<open>hd (tl (tl ws)) = a\<close>] have "hd (tl (tl ws)) \<noteq> last (tl (tl ws))". from less.hyps[OF ind \<open>tl (tl ws) \<le>p [a,b] \<cdot> tl (tl ws)\<close> this] show "tl (tl ws) \<in> [a, b]*". qed thus "ws \<in> [a,b]*" unfolding add_root[of "[a,b]" "tl(tl ws)", symmetric] *[folded \<open>[a,b] = [hd ws, hd (tl ws)]\<close> ]. qed qed lemma no_cyclic_repetition_list: assumes "set ws \<subseteq> {a,b}" "ws \<notin> [a,b]*" "ws \<notin> [b,a]*" "hd ws \<noteq> last ws" "\<not> [a,a] \<le>f ws" "\<not> [b,b] \<le>f ws" shows False using per_root_hd_last_root[OF _ \<open>hd ws \<noteq> last ws\<close>] \<open>ws \<notin> [a,b]*\<close> \<open>ws \<notin> [b,a]*\<close> no_repetition_list[OF assms(1) _ _ assms(5-6)] by blast subsection \<open>Three covers\<close> \<comment> \<open>Example: $v = a$ $t = (b a^(j+1))^k b a$ $r = a b (a^(j+1) b)^k$ $t' = $ $w = (a (b a^(j+1))^l b) a^(j+1) ((b a^(j+1))^m b a)$ \<close> lemma three_covers_example: assumes v: "v = [0::nat]" and t: "t = ([1] \<cdot> [0]\<^sup>@Suc j)\<^sup>@Suc (m + l) \<cdot> [1,0] " and r: "r = [0,1] \<cdot> ([0]\<^sup>@Suc j \<cdot> [1])\<^sup>@Suc (m + l)" and t': "t' = ([1] \<cdot> [0]\<^sup>@Suc j)\<^sup>@m \<cdot> [1,0] " and r': "r' = [0,1] \<cdot> ([0]\<^sup>@Suc j \<cdot> [1])\<^sup>@l" and w: "w = [0] \<cdot> ([1] \<cdot> [0]\<^sup>@Suc j)\<^sup>@Suc (m + l) \<cdot> [1,0]" shows "w = v \<cdot> t" and "w = r \<cdot> v" and "w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'" and "t' <p t" and "r' <s r" proof- show "w = v \<cdot> t" unfolding w v t.. show "w = r \<cdot> v" unfolding w r v by comparison show "t' <p t" unfolding t t' pow_Suc2[of _ "m+l"] add_exps rassoc spref_cancel_conv unfolding lassoc unfolding rassoc[of _ "[1]"] pow_comm unfolding pow_Suc rassoc by simp have "r = [0,1] \<cdot> ([0]\<^sup>@Suc j \<cdot> [1])\<^sup>@ m \<cdot> [0]\<^sup>@j \<cdot> r'" unfolding r' r by comparison thus "r' <s r" by force show "w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'" unfolding w r' v t' by comparison qed lemma three_covers_pers: \<comment> \<open>alias Old Good Lemma\<close> assumes "w = v \<cdot> t" and "w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'" and "w = r \<cdot> v" and "r' <s r" and "t' <p t" shows "period w (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|)" and "period w (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)" and "(\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) + (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|) = \<^bold>|w\<^bold>| + Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>|" proof- let ?per_r = "\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" let ?per_t = "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|" let ?gcd = "gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)" have "w \<noteq> \<epsilon>" using \<open>w = v \<cdot> t\<close> \<open>t' <p t\<close> by auto obtain "r''" where "r'' \<cdot> r' = r" and "r'' \<noteq> \<epsilon>" using ssufD[OF \<open>r' <s r\<close>] sufD by blast hence "w \<le>p r'' \<cdot> w" using assms unfolding pow_Suc using rassoc triv_pref by metis thus "period w ?per_r" using lenarg[OF \<open>r'' \<cdot> r' = r\<close>] period_I[OF \<open>w \<noteq> \<epsilon>\<close> \<open>r'' \<noteq> \<epsilon>\<close> \<open>w \<le>p r'' \<cdot> w\<close>] unfolding lenmorph by (metis add_diff_cancel_right') have "\<^bold>|r'\<^bold>| < \<^bold>|r\<^bold>|" using suffix_length_less[OF \<open>r' <s r\<close>]. obtain "t''" where "t' \<cdot> t'' = t" and "t'' \<noteq> \<epsilon>" using sprefD[OF \<open>t' <p t\<close>] prefD by blast hence "w \<le>s w \<cdot> t''" using assms unfolding pow_Suc2 using rassoc triv_suf by metis have "\<^bold>|t'\<^bold>| < \<^bold>|t\<^bold>|" using prefix_length_less[OF \<open>t' <p t\<close>]. show "period w ?per_t" using lenarg[OF \<open>t' \<cdot> t'' = t\<close>] period_I[reversed, OF \<open>w \<noteq> \<epsilon>\<close> \<open>t'' \<noteq> \<epsilon>\<close> \<open>w \<le>s w \<cdot> t''\<close> ] unfolding lenmorph by (metis add_diff_cancel_left') show eq: "?per_t + ?per_r = \<^bold>|w\<^bold>| + Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>|" using lenarg[OF \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close>] lenarg[OF \<open>w = v \<cdot> t\<close>] lenarg[OF \<open>w = r \<cdot> v\<close>] \<open>\<^bold>|t'\<^bold>| < \<^bold>|t\<^bold>|\<close> \<open>\<^bold>|r'\<^bold>| < \<^bold>|r\<^bold>|\<close> unfolding pow_len lenmorph by force qed lemma three_covers_per0: assumes "w = v \<cdot> t" and "w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'" and "w = r \<cdot> v" and "r' <s r" and "t' <p t" and "\<^bold>|t'\<^bold>| \<le> \<^bold>|r'\<^bold>|" and "primitive v" shows "period w (gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|))" using assms proof (induct "\<^bold>|w\<^bold>|" arbitrary: w t r t' r' v rule: less_induct) case less then show ?case proof- let ?per_r = "\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" let ?per_t = "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|" let ?gcd = "gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)" have "v \<noteq> \<epsilon>" using prim_nemp[OF \<open>primitive v\<close>]. have "w \<noteq> \<epsilon>" using \<open>w = v \<cdot> t\<close> \<open>t' <p t\<close> by blast note prefix_length_less[OF \<open>t' <p t\<close>] prefix_length_less[reversed, OF \<open>r' <s r\<close>] have "?gcd \<noteq> 0" using \<open>\<^bold>|t'\<^bold>| < \<^bold>|t\<^bold>|\<close> gcd_eq_0_iff zero_less_diff' by metis have "period w ?per_t" and "period w ?per_r" and eq: "?per_t + ?per_r = \<^bold>|w\<^bold>| + Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>|" using three_covers_pers[OF \<open>w = v \<cdot> t\<close> \<open>w = r' \<cdot> v \<^sup>@ Suc j \<cdot> t'\<close> \<open>w = r \<cdot> v\<close> \<open>r' <s r\<close> \<open>t' <p t\<close>]. obtain "r''" where "r'' \<cdot> r' = r" and "r'' \<noteq> \<epsilon>" using ssufD[OF \<open>r' <s r\<close>] sufD by blast hence "w \<le>p r'' \<cdot> w" using less.prems unfolding pow_Suc using rassoc triv_pref by metis obtain "t''" where "t' \<cdot> t'' = t" and "t'' \<noteq> \<epsilon>" using sprefD[OF \<open>t' <p t\<close>] prefD by blast show "period w ?gcd" proof (cases) have local_rule: "a - c \<le> b \<Longrightarrow> k + a - c - b \<le> k" for a b c k :: nat by simp assume "Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>| \<le> ?gcd" \<comment> \<open>Condition allowing to use the Periodicity lemma\<close> from local_rule[OF this] have len: "?per_t + ?per_r - ?gcd \<le> \<^bold>|w\<^bold>|" unfolding eq. show "period w ?gcd" using per_lemma[OF \<open>period w ?per_t\<close> \<open>period w ?per_r\<close> len]. next assume "\<not> Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>| \<le> ?gcd" \<comment> \<open>Periods are too long for the Periodicity lemma\<close> hence "?gcd \<le> \<^bold>|v\<^sup>@Suc j\<^bold>| - 2*\<^bold>|v\<^bold>|" \<comment> \<open>But then we have a potential for using the Periodicity lemma on the power of v's\<close> unfolding pow_len by linarith have "\<^bold>|v \<^sup>@ Suc j\<^bold>| - Suc (Suc 0) * \<^bold>|v\<^bold>| + \<^bold>|v\<^bold>| \<le> \<^bold>|v \<^sup>@ Suc j\<^bold>|" by simp with add_le_mono1[OF \<open>?gcd \<le> \<^bold>|v\<^sup>@Suc j\<^bold>| - 2*\<^bold>|v\<^bold>|\<close>, of "\<^bold>|v\<^bold>|"] have "?gcd + \<^bold>|v\<^bold>| \<le> \<^bold>|v \<^sup>@ Suc j\<^bold>|" unfolding numerals using le_trans by blast show "period w ?gcd" proof (cases) assume "\<^bold>|r'\<^bold>| = \<^bold>|t'\<^bold>|" \<comment> \<open>The trivial case\<close> hence "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>| = \<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" using conj_len[OF \<open>w = v \<cdot> t\<close>[unfolded \<open>w = r \<cdot> v\<close>]] by force show "period w (gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|))" unfolding \<open>\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>| = \<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|\<close> gcd_idem_nat using \<open>period w (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)\<close>. next assume "\<^bold>|r'\<^bold>| \<noteq> \<^bold>|t'\<^bold>|" \<comment> \<open>The nontrivial case\<close> hence "\<^bold>|t'\<^bold>| < \<^bold>|r'\<^bold>|" using \<open>\<^bold>|t'\<^bold>| \<le> \<^bold>|r'\<^bold>|\<close> by force have "r' \<cdot> v <p w" using \<open>\<^bold>|r'\<^bold>| < \<^bold>|r\<^bold>|\<close> \<open>r'' \<cdot> r' = r\<close> \<open>w \<le>p r'' \<cdot> w\<close> \<open>w = r \<cdot> v\<close> by force obtain p where "r' \<cdot> v = v \<cdot> p" using ruler_le[OF triv_pref[of v t , folded \<open>w = v \<cdot> t\<close>], of "r' \<cdot> v"] unfolding lenmorph \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close>[unfolded pow_Suc] rassoc by (force simp add: prefix_def) from \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close>[unfolded pow_Suc lassoc this \<open>w = v \<cdot> t\<close>, unfolded rassoc cancel] have "p \<le>p t" by blast have "\<^bold>|v \<cdot> p\<^bold>| < \<^bold>|w\<^bold>|" using prefix_length_less[OF \<open>r' \<cdot> v <p w\<close>, unfolded \<open>r' \<cdot> v = v \<cdot> p\<close>]. have "v \<cdot> p \<le>s w" \<comment> \<open>r'v is a long border of w\<close> using \<open>r' \<cdot> v = v \<cdot> p\<close> \<open>w = r \<cdot> v\<close> \<open>r' <s r\<close> same_suffix_suffix ssufD by metis have "\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|" using conj_len[OF \<open>r' \<cdot> v = v \<cdot> p\<close>]. note \<open>\<^bold>|t'\<^bold>| \<le> \<^bold>|r'\<^bold>|\<close>[unfolded \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close>] hence "t' <p p" using \<open>t = p \<cdot> v \<^sup>@ j \<cdot> t'\<close> \<open>t' \<cdot> t'' = t\<close> \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close> \<open>\<^bold>|t'\<^bold>| < \<^bold>|r'\<^bold>|\<close> \<open>p \<le>p t\<close> pref_prod_long_less by metis show ?thesis proof (cases) assume "\<^bold>|v \<cdot> p\<^bold>| \<le> \<^bold>|v\<^sup>@Suc j \<cdot> t'\<^bold>|" \<comment> \<open>The border does not cover the whole power of v's. In this case, everything commutes\<close> have "\<rho> (rev v) = rev (\<rho> v)" using \<open>v \<noteq> \<epsilon>\<close> primroot_rev by auto from pref_marker_ext[reversed, OF \<open>\<^bold>|t'\<^bold>| \<le> \<^bold>|p\<^bold>|\<close> \<open>v \<noteq> \<epsilon>\<close>] suf_prod_le[OF \<open>v \<cdot> p \<le>s w\<close>[unfolded \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close>] \<open>\<^bold>|v \<cdot> p\<^bold>| \<le> \<^bold>|v\<^sup>@Suc j \<cdot> t'\<^bold>|\<close>] obtain k where "p = v\<^sup>@k \<cdot> t'" unfolding prim_self_root[OF \<open>primitive v\<close>]. hence "p \<le>p v\<^sup>@k \<cdot> p" using \<open>t' <p p\<close> by simp from root_comm_root[OF this power_commutes[symmetric]] have "p \<le>p v \<cdot> p" using \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close> \<open>\<^bold>|r'\<^bold>| \<noteq> \<^bold>|t'\<^bold>|\<close> \<open>p = v \<^sup>@ k \<cdot> t'\<close> by force hence "p = r'" using \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close> \<open>r' \<cdot> v = v \<cdot> p\<close> pref_prod_eq by metis note \<open>r' \<cdot> v = v \<cdot> p\<close>[folded this] \<open>r' \<cdot> v = v \<cdot> p\<close>[unfolded this] then obtain er' where "r' = v\<^sup>@er'" using \<open>primitive v\<close> by auto from \<open>p \<cdot> v = v \<cdot> p\<close>[unfolded \<open>p = v\<^sup>@k \<cdot> t'\<close> lassoc pow_comm[symmetric], unfolded rassoc cancel] have "t' \<cdot> v = v \<cdot> t'". then obtain et' where "t' = v\<^sup>@et'" using \<open>primitive v\<close> by auto have "t \<cdot> v = v \<cdot> t" by (simp add: pow_comm \<open>p = r'\<close> \<open>r' \<cdot> v = v \<cdot> r'\<close> \<open>t = p \<cdot> v \<^sup>@ j \<cdot> t'\<close> \<open>t' \<cdot> v = v \<cdot> t'\<close>) then obtain et where "t = v\<^sup>@et" using \<open>primitive v\<close> by auto have "r \<cdot> v = v \<cdot> r" using \<open>t \<cdot> v = v \<cdot> t\<close> cancel_right \<open>w = v \<cdot> t\<close> \<open>w = r \<cdot> v\<close> by metis then obtain er where "r = v\<^sup>@er" using \<open>primitive v\<close> by auto have "w \<cdot> v = v \<cdot> w" by (simp add: \<open>r \<cdot> v = v \<cdot> r\<close> \<open>w = r \<cdot> v\<close>) then obtain ew where "w = v\<^sup>@ew" using \<open>primitive v\<close> by auto hence "period w \<^bold>|v\<^bold>|" using \<open>v \<noteq> \<epsilon>\<close> \<open>w \<cdot> v = v \<cdot> w\<close> \<open>w \<noteq> \<epsilon>\<close> by blast have dift: "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>| = (et - et')*\<^bold>|v\<^bold>|" using lenarg[OF \<open>t = v\<^sup>@et\<close>] lenarg[OF \<open>t' = v\<^sup>@et'\<close>] unfolding lenmorph pow_len by (simp add: diff_mult_distrib) have difr: "(\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|) = (er - er')*\<^bold>|v\<^bold>|" using lenarg[OF \<open>r = v\<^sup>@er\<close>] lenarg[OF \<open>r' = v\<^sup>@er'\<close>] unfolding lenmorph pow_len by (simp add: diff_mult_distrib) obtain g where g: "g*\<^bold>|v\<^bold>| = ?gcd" unfolding dift difr mult.commute[of _ "\<^bold>|v\<^bold>|"] gcd_mult_distrib_nat[symmetric] by blast hence "g \<noteq> 0" using nemp_len[OF \<open>v \<noteq> \<epsilon>\<close>] per_positive[OF \<open>period w (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)\<close>] gcd_nat.neutr_eq_iff mult_is_0 by metis from per_mult[OF \<open>period w \<^bold>|v\<^bold>|\<close> this] show ?thesis unfolding g. next assume "\<not> \<^bold>|v \<cdot> p\<^bold>| \<le> \<^bold>|v \<^sup>@ Suc j \<cdot> t'\<^bold>|" \<comment> \<open>The border covers the whole power. An induction is available.\<close> then obtain ri' where "v \<cdot> p = ri'\<cdot>v\<^sup>@Suc j \<cdot> t'" and "ri' \<le>s r'" using \<open>v \<cdot> p \<le>s w\<close> unfolding \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close> using suffix_append suffix_length_le by blast hence "ri' <s r'" using \<open>r' \<cdot> v = v \<cdot> p\<close> cancel_right less.prems(2) less.prems(3) less.prems(4) suffix_order.le_neq_trans by metis have gcd_eq: "gcd (\<^bold>|p\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r'\<^bold>| - \<^bold>|ri'\<^bold>|) = ?gcd" \<comment> \<open>The two gcd's are the same\<close> proof- have "\<^bold>|r'\<^bold>| \<le> \<^bold>|r\<^bold>|" by (simp add: \<open>\<^bold>|r'\<^bold>| < \<^bold>|r\<^bold>|\<close> dual_order.strict_implies_order) have "\<^bold>|t\<^bold>| = \<^bold>|r\<^bold>|" using lenarg[OF \<open>w = v \<cdot> t\<close>] unfolding lenarg[OF \<open>w = r \<cdot> v\<close>] lenmorph by auto have e1: "\<^bold>|r'\<^bold>| - \<^bold>|ri'\<^bold>| = \<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" using lenarg[OF \<open>v \<cdot> p = ri'\<cdot>v\<^sup>@Suc j \<cdot> t'\<close>[folded \<open>r' \<cdot> v = v \<cdot> p\<close>]] lenarg[OF \<open>w = r \<cdot> v\<close>[unfolded \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close>]] unfolding lenmorph pow_len by (simp add: add.commute diff_add_inverse diff_diff_add) have "\<^bold>|t\<^bold>| = \<^bold>|p\<^bold>| + \<^bold>|r'\<^bold>| - \<^bold>|ri'\<^bold>|" unfolding add_diff_assoc[OF suffix_length_le[OF \<open>ri' \<le>s r'\<close>], unfolded e1, symmetric] \<open>\<^bold>|t\<^bold>| = \<^bold>|r\<^bold>|\<close> unfolding \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close> using \<open>\<^bold>|r'\<^bold>| < \<^bold>|r\<^bold>|\<close>[unfolded \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close>] by linarith (* TODO *) hence e2: "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>| = (\<^bold>|p\<^bold>| - \<^bold>|t'\<^bold>|) + (\<^bold>|r'\<^bold>| - \<^bold>|ri'\<^bold>|)" using \<open>\<^bold>|t'\<^bold>| \<le> \<^bold>|p\<^bold>|\<close> diff_commute \<open>ri' \<le>s r'\<close> \<open>\<^bold>|r'\<^bold>| = \<^bold>|p\<^bold>|\<close> \<open>\<^bold>|r'\<^bold>| \<le> \<^bold>|r\<^bold>|\<close> \<open>\<^bold>|t\<^bold>| = \<^bold>|r\<^bold>|\<close> by linarith show ?thesis unfolding e2 e1 gcd_add1.. qed have per_vp: "period (v \<cdot> p) ?gcd" proof (cases) assume "\<^bold>|t'\<^bold>| \<le> \<^bold>|ri'\<^bold>|" \<comment> \<open>By induction.\<close> from less.hyps[OF \<open>\<^bold>|v \<cdot> p\<^bold>| < \<^bold>|w\<^bold>|\<close> refl \<open>v \<cdot> p = ri'\<cdot>v\<^sup>@Suc j \<cdot> t'\<close> \<open>r' \<cdot> v = v \<cdot> p\<close>[symmetric] \<open>ri' <s r'\<close> \<open>t' <p p\<close> this \<open>primitive v\<close>] show "period (v \<cdot> p) ?gcd" unfolding gcd_eq by blast next \<comment> \<open>...(using symmetry)\<close> assume "\<not> \<^bold>|t'\<^bold>| \<le> \<^bold>|ri'\<^bold>|" hence "\<^bold>|ri'\<^bold>| \<le> \<^bold>|t'\<^bold>|" by simp have "period (rev p \<cdot> rev v) (gcd (\<^bold>|rev r'\<^bold>| - \<^bold>|rev ri'\<^bold>|) (\<^bold>|rev p\<^bold>| - \<^bold>|rev t'\<^bold>|))" proof (rule less.hyps[OF _ _ _ refl]) show "\<^bold>|rev p \<cdot> rev v\<^bold>| < \<^bold>|w\<^bold>|" using \<open>\<^bold>|v \<cdot> p\<^bold>| < \<^bold>|w\<^bold>|\<close> by simp show "rev p \<cdot> rev v = rev v \<cdot> rev r'" using \<open>r' \<cdot> v = v \<cdot> p\<close> unfolding rev_append[symmetric] by simp show "rev p \<cdot> rev v = rev t' \<cdot> rev v \<^sup>@ Suc j \<cdot> rev ri'" using \<open>v \<cdot> p = ri'\<cdot>v\<^sup>@Suc j \<cdot> t'\<close> unfolding rev_append[symmetric] rev_pow[symmetric] rassoc by simp show "rev t' <s rev p" using \<open>t' <p p\<close> by (auto simp add: prefix_def) show "rev ri' <p rev r'" using \<open>ri' <s r'\<close> strict_suffix_to_prefix by blast show "\<^bold>|rev ri'\<^bold>| \<le> \<^bold>|rev t'\<^bold>|" by (simp add: \<open>\<^bold>|ri'\<^bold>| \<le> \<^bold>|t'\<^bold>|\<close>) show "primitive (rev v)" by (simp add: \<open>primitive v\<close> prim_rev_iff) qed thus ?thesis unfolding length_rev rev_append[symmetric] period_rev_conv gcd.commute[of "\<^bold>|r'\<^bold>| - \<^bold>|ri'\<^bold>|"] gcd_eq. qed have "period (v\<^sup>@Suc j) (gcd \<^bold>|v\<^bold>| ?gcd)" proof (rule per_lemma) show " \<^bold>|v\<^bold>| + ?gcd - gcd \<^bold>|v\<^bold>| (gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)) \<le> \<^bold>|v \<^sup>@ Suc j\<^bold>|" using \<open>?gcd + \<^bold>|v\<^bold>| \<le> \<^bold>|v \<^sup>@ Suc j\<^bold>|\<close> by linarith show "period (v \<^sup>@ Suc j) \<^bold>|v\<^bold>|" using \<open>v \<noteq> \<epsilon>\<close> pow_per by blast have "v \<^sup>@ Suc j \<noteq> \<epsilon>" using \<open>v \<noteq> \<epsilon>\<close> by auto from period_fac[OF per_vp[unfolded \<open>v \<cdot> p = ri' \<cdot> v \<^sup>@ Suc j \<cdot> t'\<close>] this] show "period (v \<^sup>@ Suc j) ?gcd". qed have per_vp': "period (v \<cdot> p) (gcd \<^bold>|v\<^bold>| ?gcd)" proof (rule refine_per) show "gcd \<^bold>|v\<^bold>| ?gcd dvd ?gcd" by blast show "?gcd \<le> \<^bold>|v\<^sup>@Suc j\<^bold>|" using \<open>?gcd + \<^bold>|v\<^bold>| \<le> \<^bold>|v \<^sup>@ Suc j\<^bold>|\<close> add_leE by blast show "v \<^sup>@ Suc j \<le>f v \<cdot> p" using facI'[OF \<open>v \<cdot> p = ri' \<cdot> v \<^sup>@ Suc j \<cdot> t'\<close>[symmetric]]. qed fact+ have "period w (gcd \<^bold>|v\<^bold>| ?gcd)" proof (rule per_glue) show "v \<cdot> p \<le>p w" using \<open>p \<le>p t\<close> \<open>w = v \<cdot> t\<close> by auto have "\<^bold>|v \<^sup>@ Suc j\<^bold>| + \<^bold>|t'\<^bold>| \<le> \<^bold>|v\<^bold>| + \<^bold>|p\<^bold>|" using \<open>\<not> \<^bold>|v \<cdot> p\<^bold>| \<le> \<^bold>|v \<^sup>@ Suc j \<cdot> t'\<^bold>|\<close> by auto moreover have "\<^bold>|r'\<^bold>| + gcd \<^bold>|v\<^bold>| ?gcd \<le> \<^bold>|v\<^bold>| + \<^bold>|p\<^bold>|" using lenarg[OF \<open>r' \<cdot> v = v \<cdot> p\<close>, unfolded lenmorph] \<open>v \<noteq> \<epsilon>\<close> gcd_le1_nat length_0_conv nat_add_left_cancel_le by metis ultimately show "\<^bold>|w\<^bold>| + gcd \<^bold>|v\<^bold>| ?gcd \<le> \<^bold>|v \<cdot> p\<^bold>| + \<^bold>|v \<cdot> p\<^bold>|" unfolding lenarg[OF \<open>w = r' \<cdot> v \<^sup>@ Suc j \<cdot> t'\<close>] lenmorph add.commute[of "\<^bold>|r'\<^bold>|"] by linarith qed fact+ obtain k where k: "?gcd = k*(gcd \<^bold>|v\<^bold>| ?gcd)" using gcd_dvd2 unfolding dvd_def mult.commute[of _ "gcd \<^bold>|v\<^bold>| ?gcd"] by blast hence "k \<noteq> 0" using \<open>?gcd \<noteq> 0\<close> by algebra from per_mult[OF \<open>period w (gcd \<^bold>|v\<^bold>| ?gcd)\<close> this, folded k] show ?thesis. qed qed qed qed qed lemma three_covers_per: assumes "w = v \<cdot> t" and "w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'" and "w = r \<cdot> v" and "r' <s r" and "t' <p t" shows "period w (gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|))" proof- let ?per_r = "\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" let ?per_t = "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|" let ?gcd = "gcd (\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|)" have "period w ?per_t" and "period w ?per_r" and len: "(\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|) + (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|) = \<^bold>|w\<^bold>| + Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>|" using three_covers_pers[OF \<open>w = v \<cdot> t\<close> \<open>w = r' \<cdot> v \<^sup>@ Suc j \<cdot> t'\<close> \<open>w = r \<cdot> v\<close> \<open>r' <s r\<close> \<open>t' <p t\<close>] by blast+ show ?thesis proof(cases) assume "v = \<epsilon>" have "\<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>| + (\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|) = \<^bold>|w\<^bold>|" using \<open>w = v \<cdot> t\<close> \<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close> \<open>w = r \<cdot> v\<close> unfolding \<open>v = \<epsilon>\<close> emp_pow clean_emp by force from per_lemma[OF \<open>period w ?per_t\<close> \<open>period w ?per_r\<close>, unfolded this] show "period w ?gcd" by fastforce next assume "v \<noteq> \<epsilon>" show ?thesis proof (cases) assume "j \<le> 1" hence "(j = 0 \<Longrightarrow> P) \<Longrightarrow> (j = 1 \<Longrightarrow> P) \<Longrightarrow> P" for P by force hence "\<^bold>|w\<^bold>| + Suc j*\<^bold>|v\<^bold>| - 2*\<^bold>|v\<^bold>| - ?gcd \<le> \<^bold>|w\<^bold>|" \<comment> \<open>Condition allowing to use the Periodicity lemma\<close> by (cases, simp_all) thus "period w ?gcd" using per_lemma[OF \<open>period w ?per_t\<close> \<open>period w ?per_r\<close>] unfolding len by blast next assume "\<not> j \<le> 1" hence "2 \<le> j" by simp obtain e where "v = \<rho> v\<^sup>@Suc e" using \<open>v \<noteq> \<epsilon>\<close> primroot_expE by metis have "e + (Suc e * (Suc j - 2) + 2 + e) = Suc e * (Suc j - 2) + Suc e + Suc e" by auto also have "... = Suc e * (Suc j - 2 + Suc 0 + Suc 0)" unfolding add_mult_distrib2 by simp also have "... = Suc e * Suc j" using \<open>2 \<le> j\<close> by auto finally have calc: "e + (Suc e * (Suc j - 2) + 2 + e) = Suc e * Suc j". have "w = \<rho> v \<cdot> (\<rho> v\<^sup>@e \<cdot> t)" using \<open>v = \<rho> v \<^sup>@ Suc e\<close> \<open>w = v \<cdot> t\<close> by fastforce have "w = (r \<cdot> \<rho> v\<^sup>@e) \<cdot> \<rho> v" unfolding rassoc pow_Suc2[symmetric] \<open>v = \<rho> v \<^sup>@ Suc e\<close>[symmetric] by fact obtain e' where e': "Suc e' = Suc e * (Suc j - 2) + 2" by auto have "w = (r' \<cdot> \<rho> v\<^sup>@e) \<cdot> \<rho> v \<^sup>@Suc e' \<cdot> (\<rho> v\<^sup>@e \<cdot> t')" unfolding e'\<open>w = r' \<cdot> v\<^sup>@Suc j \<cdot> t'\<close> rassoc cancel unfolding lassoc cancel_right add_exps[symmetric] calc pow_mult \<open>v = \<rho> v\<^sup>@Suc e\<close>[symmetric].. show ?thesis proof(cases) assume "\<^bold>|t'\<^bold>| \<le> \<^bold>|r'\<^bold>|" have dif1: "\<^bold>|\<rho> v \<^sup>@ e \<cdot> t\<^bold>| - \<^bold>|\<rho> v \<^sup>@ e \<cdot> t'\<^bold>| = \<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|" unfolding lenmorph by simp have dif2: "\<^bold>|r \<cdot> \<rho> v \<^sup>@ e\<^bold>| - \<^bold>|r' \<cdot> \<rho> v \<^sup>@ e\<^bold>| = \<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" unfolding lenmorph by simp show ?thesis proof (rule three_covers_per0[OF \<open>w = \<rho> v \<cdot> (\<rho> v\<^sup>@e \<cdot> t)\<close> \<open>w = (r' \<cdot> \<rho> v\<^sup>@e) \<cdot> \<rho> v \<^sup>@Suc e' \<cdot> (\<rho> v\<^sup>@e \<cdot> t')\<close> \<open>w = (r \<cdot> \<rho> v\<^sup>@e) \<cdot> \<rho> v\<close>, unfolded dif1 dif2]) show "r' \<cdot> \<rho> v \<^sup>@ e <s r \<cdot> \<rho> v \<^sup>@ e" using \<open>r' <s r\<close> by auto show "\<rho> v \<^sup>@ e \<cdot> t' <p \<rho> v \<^sup>@ e \<cdot> t" using \<open>t' <p t\<close> by auto show "\<^bold>|\<rho> v \<^sup>@ e \<cdot> t'\<^bold>| \<le> \<^bold>|r' \<cdot> \<rho> v \<^sup>@ e\<^bold>|" unfolding lenmorph using \<open>\<^bold>|t'\<^bold>| \<le> \<^bold>|r'\<^bold>|\<close> by auto show "primitive (\<rho> v)" using primroot_prim[OF \<open>v \<noteq> \<epsilon>\<close>]. qed next let ?w = "rev w" and ?r = "rev t" and ?t = "rev r" and ?\<rho> = "rev (\<rho> v)" and ?r' = "rev t'" and ?t' = "rev r'" assume "\<not> \<^bold>|t'\<^bold>| \<le> \<^bold>|r'\<^bold>|" hence "\<^bold>|?t'\<^bold>| \<le> \<^bold>|?r'\<^bold>|" by auto have "?w = (?r \<cdot> ?\<rho>\<^sup>@e) \<cdot> ?\<rho>" unfolding rev_pow[symmetric] rev_append[symmetric] \<open>w = \<rho> v \<cdot> (\<rho> v\<^sup>@e \<cdot> t)\<close> rassoc.. have "?w = ?\<rho> \<cdot> (?\<rho>\<^sup>@e \<cdot> ?t)" unfolding rev_pow[symmetric] rev_append[symmetric] \<open>w = (r \<cdot> \<rho> v\<^sup>@e) \<cdot> \<rho> v\<close>.. have "?w = (?r' \<cdot> ?\<rho>\<^sup>@e) \<cdot> ?\<rho>\<^sup>@Suc e' \<cdot> (?\<rho>\<^sup>@e \<cdot> ?t')" unfolding rev_pow[symmetric] rev_append[symmetric] \<open>w = (r' \<cdot> \<rho> v\<^sup>@e) \<cdot> \<rho> v \<^sup>@Suc e' \<cdot> (\<rho> v\<^sup>@e \<cdot> t')\<close> rassoc.. have dif1: "\<^bold>|?\<rho> \<^sup>@ e \<cdot> ?t\<^bold>| - \<^bold>|?\<rho> \<^sup>@ e \<cdot> ?t'\<^bold>| = \<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|" unfolding lenmorph by simp have dif2: "\<^bold>|?r \<cdot> ?\<rho> \<^sup>@ e\<^bold>| - \<^bold>|?r' \<cdot> ?\<rho> \<^sup>@ e\<^bold>| = \<^bold>|t\<^bold>| - \<^bold>|t'\<^bold>|" unfolding lenmorph by simp show ?thesis proof (rule three_covers_per0[OF \<open>?w = ?\<rho> \<cdot> (?\<rho>\<^sup>@e \<cdot> ?t)\<close> \<open>?w = (?r' \<cdot> ?\<rho>\<^sup>@e) \<cdot> ?\<rho>\<^sup>@Suc e' \<cdot> (?\<rho>\<^sup>@e \<cdot> ?t')\<close> \<open>?w = (?r \<cdot> ?\<rho>\<^sup>@e) \<cdot> ?\<rho>\<close>, unfolded dif1 dif2 period_rev_conv gcd.commute[of "\<^bold>|r\<^bold>| - \<^bold>|r'\<^bold>|"]]) show "?r' \<cdot> ?\<rho> \<^sup>@ e <s ?r \<cdot> ?\<rho> \<^sup>@ e" using \<open>t' <p t\<close> by (auto simp add: prefix_def) show "?\<rho> \<^sup>@ e \<cdot> ?t' <p ?\<rho> \<^sup>@ e \<cdot> ?t" using \<open>r' <s r\<close> by (auto simp add: suf_def) show "\<^bold>|?\<rho> \<^sup>@ e \<cdot> ?t'\<^bold>| \<le> \<^bold>|?r' \<cdot> ?\<rho> \<^sup>@ e\<^bold>|" unfolding lenmorph using \<open>\<^bold>|?t'\<^bold>| \<le> \<^bold>|?r'\<^bold>|\<close> by auto show "primitive ?\<rho>" using primroot_prim[OF \<open>v \<noteq> \<epsilon>\<close>] by (simp add: prim_rev_iff) qed qed qed qed qed hide_fact three_covers_per0 lemma three_covers_pref_suf_pow: assumes "x \<cdot> y \<le>p w" and "y \<cdot> x \<le>s w" and "w \<le>f y\<^sup>@k" and "\<^bold>|y\<^bold>| \<le> \<^bold>|x\<^bold>|" shows "x \<cdot> y = y \<cdot> x" using fac_marker_suf[OF fac_trans[OF pref_fac[OF \<open>x \<cdot> y \<le>p w\<close>] \<open>w \<le>f y\<^sup>@k\<close>]] fac_marker_pref[OF fac_trans[OF suf_fac[OF \<open>y \<cdot> x \<le>s w\<close>] \<open>w \<le>f y\<^sup>@k\<close>]] root_suf_comm'[OF _ suf_prod_long, OF _ _ \<open>\<^bold>|y\<^bold>| \<le> \<^bold>|x\<^bold>|\<close>, of x] by presburger subsection \<open>Binary Equality Words\<close> (*rudimentary material for classification of binary equality words *) \<comment> \<open>translation of a combinatorial lemma into the language of "something is not BEW"\<close> definition binary_equality_word :: "binA list \<Rightarrow> bool" where "binary_equality_word w = (\<exists> (g :: binA list \<Rightarrow> nat list) h. binary_code_morphism g \<and> binary_code_morphism h \<and> g \<noteq> h \<and> w \<in> g =\<^sub>M h)" lemma not_bew_baiba: assumes "\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|" and "x \<le>s y" and "u \<le>s v" and "y \<cdot> x \<^sup>@ k \<cdot> y = v \<cdot> u \<^sup>@ k \<cdot> v" shows "commutes {x,y,u,v}" proof- obtain p where "y\<cdot>p = v" using eqdE[OF \<open>y \<cdot> x \<^sup>@ k \<cdot> y = v \<cdot> u \<^sup>@ k \<cdot> v\<close> less_imp_le[OF \<open>\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|\<close>]] by blast have "\<^bold>|u \<^sup>@ k \<cdot> v\<^bold>| \<le> \<^bold>|x \<^sup>@ k \<cdot> y\<^bold>|" using lenarg[OF \<open>y \<cdot> x \<^sup>@ k \<cdot> y = v \<cdot> u \<^sup>@ k \<cdot> v\<close>] \<open>\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|\<close> unfolding lenmorph by linarith obtain s where "s\<cdot>y = v" using eqdE[reversed, OF \<open>y \<cdot> x \<^sup>@ k \<cdot> y = v \<cdot> u \<^sup>@ k \<cdot> v\<close>[unfolded lassoc] less_imp_le[OF \<open>\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|\<close>]]. have "s \<noteq> \<epsilon>" using \<open>\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|\<close> \<open>s \<cdot> y = v\<close> by force have "p \<noteq> \<epsilon>" using \<open>\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|\<close> \<open>y \<cdot> p = v\<close> by force have "s \<cdot> y = y \<cdot> p" by (simp add: \<open>s \<cdot> y = v\<close> \<open>y \<cdot> p = v\<close>) obtain w w' q t where p_def: "p = (w'\<cdot>w)\<^sup>@Suc q" and s_def: "s = (w\<cdot>w')\<^sup>@Suc q" and y_def: "y = (w\<cdot>w')\<^sup>@t\<cdot>w" and "w' \<noteq> \<epsilon>" and "primitive (w\<cdot>w')" using conjug_eq_primrootE[OF \<open>s \<cdot> y = y \<cdot> p\<close> \<open>s \<noteq> \<epsilon>\<close>, of thesis] by blast have "primitive (w'\<cdot>w)" using \<open>primitive (w \<cdot> w')\<close> prim_conjug by auto have "y \<cdot> x \<^sup>@ k \<cdot> y = y\<cdot> p \<cdot> u \<^sup>@ k \<cdot> s \<cdot> y" using \<open>s \<cdot> y = v\<close> \<open>y \<cdot> p = v\<close> \<open>y \<cdot> x \<^sup>@ k \<cdot> y = v \<cdot> u \<^sup>@ k \<cdot> v\<close> by auto hence "x\<^sup>@k = p\<cdot>u\<^sup>@k\<cdot>s" by auto hence "x \<noteq> \<epsilon>" using \<open>p \<noteq> \<epsilon>\<close> by force have "w\<cdot>w' \<le>s x\<^sup>@k" using \<open>x \<^sup>@ k = p \<cdot> u \<^sup>@ k \<cdot> s\<close>[unfolded s_def] unfolding CoWBasic.power_Suc2 using sufI[of "p \<cdot> u \<^sup>@ k \<cdot> (w \<cdot> w') \<^sup>@ q" "w \<cdot> w'" "x\<^sup>@k", unfolded rassoc] by argo have "\<^bold>|w\<cdot>w'\<^bold>| \<le> \<^bold>|x\<^bold>|" proof(intro leI notI) assume "\<^bold>|x\<^bold>| < \<^bold>|w \<cdot> w'\<^bold>|" have "x \<le>s (w\<cdot>w')\<cdot>y" using \<open>x \<le>s y\<close> by (auto simp add: suf_def) have "(w'\<cdot>w) \<le>s (w\<cdot>w')\<cdot>y" unfolding \<open>y = (w\<cdot>w')\<^sup>@t\<cdot>w\<close> lassoc pow_comm[symmetric] suf_cancel_conv by blast from ruler_le[reversed, OF \<open>x \<le>s (w\<cdot>w')\<cdot>y\<close> this less_imp_le[OF \<open>\<^bold>|x\<^bold>| < \<^bold>|w \<cdot> w'\<^bold>|\<close>[unfolded swap_len]]] have "x \<le>s w'\<cdot> w". hence "x \<le>s p" unfolding p_def pow_Suc2 suffix_append by blast from root_suf_comm[OF _ suf_ext[OF this]] have "x\<cdot>p = p\<cdot>x" using pref_prod_root[OF prefI[OF \<open>x \<^sup>@ k = p \<cdot> u \<^sup>@ k \<cdot> s\<close>[symmetric]]] by blast from comm_drop_exp[OF _ this[unfolded \<open>p = (w' \<cdot> w) \<^sup>@ Suc q\<close>]] have "x \<cdot> (w' \<cdot> w) = (w' \<cdot> w) \<cdot> x" by force from prim_comm_short_emp[OF \<open>primitive (w'\<cdot>w)\<close> this \<open>\<^bold>|x\<^bold>| < \<^bold>|w\<cdot>w'\<^bold>|\<close>[unfolded swap_len]] show False using \<open>x \<noteq> \<epsilon>\<close> by blast qed hence "w\<cdot>w' \<le>s x" using suf_prod_le[OF suf_prod_root[OF \<open>w \<cdot> w' \<le>s x \<^sup>@ k\<close>]] by blast from suffix_order.trans[OF this \<open>x \<le>s y\<close>] have "w \<cdot> w' \<le>s y". hence "\<^bold>|w \<cdot> w'\<^bold>| \<le> \<^bold>|y\<^bold>|" using suffix_length_le by blast then obtain t' where "t = Suc t'" unfolding y_def lenmorph pow_len \<open>w' \<noteq> \<epsilon>\<close> add.commute[of _ "\<^bold>|w\<^bold>|"] nat_add_left_cancel_le using \<open>w' \<noteq> \<epsilon>\<close> mult_0[of "\<^bold>|w\<^bold>| + \<^bold>|w'\<^bold>|"] npos_len[of w'] not0_implies_Suc[of t] by force from ruler_eq_len[reversed, OF \<open>w \<cdot> w' \<le>s y\<close> _ swap_len, unfolded y_def this pow_Suc2 rassoc] have "w \<cdot> w' = w'\<cdot> w" unfolding lassoc suf_cancel_conv by blast from comm_not_prim[OF _ \<open>w' \<noteq> \<epsilon>\<close> this] have "w = \<epsilon>" using \<open>primitive (w \<cdot> w')\<close> by blast hence "primitive w'" using \<open>primitive (w' \<cdot> w)\<close> by auto have "k \<noteq> 0" using \<open>\<^bold>|y\<^bold>| < \<^bold>|v\<^bold>|\<close> lenarg[OF \<open>y \<cdot> x \<^sup>@ k \<cdot> y = v \<cdot> u \<^sup>@ k \<cdot> v\<close>, unfolded lenmorph pow_len] not_add_less1 by fastforce have "y = w'\<^sup>@t" using y_def \<open>w = \<epsilon>\<close> by force hence "y \<in> w'*" using rootI by blast have "s \<in> w'*" using s_def \<open>w = \<epsilon>\<close> rootI by force hence "v \<in> w'*" using \<open>s \<cdot> y = v\<close> \<open>y \<in> w'*\<close> add_roots by blast have "w' \<le>p x" using \<open>x\<^sup>@k = p\<cdot>u\<^sup>@k\<cdot>s\<close> eq_le_pref[OF _ \<open>\<^bold>|w\<cdot>w'\<^bold>| \<le> \<^bold>|x\<^bold>|\<close>, of "w' \<^sup>@ q \<cdot> u \<cdot> u \<^sup>@ (k - 1) \<cdot> s" "x \<^sup>@ (k - 1)"] unfolding p_def \<open>w = \<epsilon>\<close> clean_emp pop_pow_one[OF \<open>k \<noteq> 0\<close>] pow_Suc rassoc by argo have "x \<cdot> w' = w' \<cdot> x" using \<open>x \<le>s y\<close> \<open>w' \<le>p x\<close> y_def[unfolded \<open>w = \<epsilon>\<close> \<open>t = Suc t'\<close> clean_emp] pref_suf_pows_comm[of w' x 0 0 0 t', unfolded pow_zero clean_emp, folded y_def[unfolded \<open>w = \<epsilon>\<close> \<open>t = Suc t'\<close>, unfolded clean_emp]] by force hence "x \<in> w'*" using prim_comm_exp[OF \<open>primitive w'\<close>, of x] unfolding root_def by metis have "p \<in> w'*" using \<open>s \<in> w'*\<close> \<open>y \<in> w'*\<close> \<open>s \<cdot> y = v\<close>[folded \<open>y \<cdot> p = v\<close>] by (simp add: \<open>s \<cdot> y = y \<cdot> p\<close> \<open>s \<in> w'*\<close> \<open>y \<in> w'*\<close> \<open>w \<cdot> w' = w' \<cdot> w\<close> p_def s_def) obtain k' where "k = Suc k'" using \<open>k \<noteq> 0\<close> not0_implies_Suc by auto have "u\<^sup>@k \<in> w'*" using root_suf_cancel[OF \<open>s \<in> w'*\<close>, of "p \<cdot> u \<^sup>@ k", THEN root_pref_cancel[OF _ \<open>p \<in> w'*\<close>], unfolded rassoc, folded \<open>x\<^sup>@k = p\<cdot>u\<^sup>@k\<cdot>s\<close>, OF root_pow_root[OF \<open>x \<in> w'*\<close>]]. from prim_root_drop_exp[OF \<open>k \<noteq> 0\<close> \<open>primitive w'\<close> this] have "u \<in> w'*". show "commutes {x,y,u,v}" by (intro commutesI_root[of _ w'], unfold Set.ball_simps(7), simp add: \<open>x \<in> w'*\<close> \<open>y \<in> w'*\<close> \<open>u \<in> w'*\<close> \<open>v \<in> w'*\<close>) qed lemma not_bew_baibaib: assumes "\<^bold>|x\<^bold>| < \<^bold>|u\<^bold>|" and "1 < i" and "x \<cdot> y\<^sup>@i\<cdot> x \<cdot> y\<^sup>@i \<cdot> x = u \<cdot> v\<^sup>@i\<cdot> u \<cdot> v\<^sup>@i \<cdot> u" shows "commutes {x,y,u,v}" proof- have "i \<noteq> 0" using assms(2) by auto from lenarg[OF \<open>x \<cdot> y\<^sup>@i\<cdot> x \<cdot> y\<^sup>@i \<cdot> x = u \<cdot> v\<^sup>@i\<cdot> u \<cdot> v\<^sup>@i \<cdot> u\<close>] have "2*\<^bold>|x \<cdot> y\<^sup>@i\<^bold>| + \<^bold>|x\<^bold>| = 2*\<^bold>|u \<cdot> v\<^sup>@i\<^bold>| + \<^bold>|u\<^bold>|" by auto hence "\<^bold>|u \<cdot> v\<^sup>@i\<^bold>| < \<^bold>|x \<cdot> y\<^sup>@i\<^bold>|" using \<open>\<^bold>|x\<^bold>| < \<^bold>|u\<^bold>|\<close> by fastforce hence "u \<cdot> v\<^sup>@i <p x \<cdot> y\<^sup>@i" using assms(3) eq_le_pref less_or_eq_imp_le mult_assoc sprefI2 by metis have "x\<cdot>y\<^sup>@i \<noteq> \<epsilon>" by (metis \<open>u \<cdot> v \<^sup>@ i <p x \<cdot> y \<^sup>@ i\<close> strict_prefix_simps(1)) have "u\<cdot>v\<^sup>@i \<noteq> \<epsilon>" using assms(1) gr_implies_not0 by blast have "(u\<cdot>v\<^sup>@i) \<cdot> (x\<cdot>y\<^sup>@i) = (x\<cdot>y\<^sup>@i) \<cdot> (u\<cdot>v\<^sup>@i)" proof(rule sq_short_per) have eq: "(x \<cdot> y \<^sup>@ i) \<cdot> (x \<cdot> y \<^sup>@ i) \<cdot> x = (u \<cdot> v \<^sup>@ i) \<cdot> (u \<cdot> v \<^sup>@ i) \<cdot> u" using assms(3) by auto from lenarg[OF this] have "\<^bold>|u \<cdot> v\<^sup>@i \<cdot> u\<^bold>| < \<^bold>|x \<cdot> y\<^sup>@i \<cdot> x \<cdot> y\<^sup>@i\<^bold>|" unfolding lenmorph using \<open>\<^bold>|x\<^bold>| < \<^bold>|u\<^bold>|\<close> by linarith from eq_le_pref[OF _ less_imp_le[OF this]] have "(u \<cdot> v\<^sup>@i)\<cdot>u \<le>p (x \<cdot> y\<^sup>@i) \<cdot> (x \<cdot> y\<^sup>@i)" using eq[symmetric] unfolding rassoc by blast hence "(u \<cdot> v \<^sup>@ i) \<cdot> (u \<cdot> v\<^sup>@i) \<cdot> u \<le>p (u \<cdot> v \<^sup>@ i) \<cdot> ((x \<cdot> y\<^sup>@i) \<cdot> (x \<cdot> y\<^sup>@i))" unfolding same_prefix_prefix. from pref_trans[OF prefI[of "(x \<cdot> y \<^sup>@ i) \<cdot> (x \<cdot> y \<^sup>@ i)" x "(x \<cdot> y \<^sup>@ i) \<cdot> (x \<cdot> y \<^sup>@ i) \<cdot> x"] this[folded \<open>(x \<cdot> y \<^sup>@ i) \<cdot> (x \<cdot> y \<^sup>@ i) \<cdot> x = (u \<cdot> v \<^sup>@ i) \<cdot> (u \<cdot> v \<^sup>@ i) \<cdot> u\<close>], unfolded rassoc, OF refl] show "(x \<cdot> y\<^sup>@i)\<cdot>(x \<cdot> y\<^sup>@i) \<le>p (u \<cdot> v\<^sup>@i) \<cdot> ((x \<cdot> y\<^sup>@i) \<cdot> (x \<cdot> y\<^sup>@i))" by fastforce show "\<^bold>|u \<cdot> v \<^sup>@ i\<^bold>| \<le> \<^bold>|x \<cdot> y \<^sup>@ i\<^bold>|" using less_imp_le_nat[OF \<open>\<^bold>|u \<cdot> v \<^sup>@ i\<^bold>| < \<^bold>|x \<cdot> y \<^sup>@ i\<^bold>|\<close>]. qed obtain r m k where "x\<cdot>y\<^sup>@i = r\<^sup>@k" "u\<cdot>v\<^sup>@i = r\<^sup>@m" "primitive r" using \<open>(u \<cdot> v \<^sup>@ i) \<cdot> x \<cdot> y \<^sup>@ i = (x \<cdot> y \<^sup>@ i) \<cdot> u \<cdot> v \<^sup>@ i\<close>[unfolded comm_primroots[OF \<open>u \<cdot> v \<^sup>@ i \<noteq> \<epsilon>\<close> \<open>x \<cdot> y \<^sup>@ i \<noteq> \<epsilon>\<close>]] \<open>u \<cdot> v \<^sup>@ i \<noteq> \<epsilon>\<close> \<open>x \<cdot> y \<^sup>@ i \<noteq> \<epsilon>\<close> primroot_expE primroot_prim by metis have "m < k" using \<open>\<^bold>|u \<cdot> v \<^sup>@ i\<^bold>| < \<^bold>|x \<cdot> y \<^sup>@ i\<^bold>|\<close> unfolding strict_prefix_def \<open>u \<cdot> v \<^sup>@ i = r \<^sup>@ m\<close> \<open>x \<cdot> y \<^sup>@ i = r \<^sup>@ k\<close> pow_len by simp have "x\<cdot>y\<^sup>@i = u\<cdot>v\<^sup>@i\<cdot>r\<^sup>@(k-m)" by (simp add: \<open>m < k\<close> \<open>u \<cdot> v \<^sup>@ i = r \<^sup>@ m\<close> \<open>x \<cdot> y \<^sup>@ i = r \<^sup>@ k\<close> lassoc less_imp_le_nat pop_pow) have "\<^bold>|y \<^sup>@ i\<^bold>| = \<^bold>|v \<^sup>@ i\<^bold>| + 3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|" and "\<^bold>|r\<^bold>| \<le> \<^bold>|y\<^sup>@(i-1)\<^bold>|" proof- have "\<^bold>|x \<cdot> y\<^sup>@i\<^bold>| = \<^bold>|r\<^sup>@(k-m)\<^bold>| + \<^bold>|u \<cdot> v\<^sup>@i\<^bold>|" using lenarg[OF \<open>x\<cdot>y\<^sup>@i = u\<cdot>v\<^sup>@i\<cdot>r\<^sup>@(k-m)\<close>] by auto have "\<^bold>|u\<^bold>| = 2 * \<^bold>|r \<^sup>@ (k - m)\<^bold>| + \<^bold>|x\<^bold>|" using \<open>2*\<^bold>|x \<cdot> y\<^sup>@i\<^bold>| + \<^bold>|x\<^bold>| = 2*\<^bold>|u \<cdot> v\<^sup>@i\<^bold>| + \<^bold>|u\<^bold>|\<close> unfolding \<open>\<^bold>|x \<cdot> y\<^sup>@i\<^bold>| = \<^bold>|r\<^sup>@(k-m)\<^bold>| + \<^bold>|u \<cdot> v\<^sup>@i\<^bold>|\<close> add_mult_distrib2 by simp have "2*\<^bold>|y\<^sup>@i\<^bold>| + 3*\<^bold>|x\<^bold>| = 2*\<^bold>|v\<^sup>@i\<^bold>| + 3*\<^bold>|u\<^bold>|" using lenarg[OF \<open>x \<cdot> y\<^sup>@i\<cdot> x \<cdot> y\<^sup>@i \<cdot> x = u \<cdot> v\<^sup>@i\<cdot> u \<cdot> v\<^sup>@i \<cdot> u\<close>] unfolding lenmorph numeral_3_eq_3 numerals(2) by linarith have "2 * \<^bold>|y \<^sup>@ i\<^bold>| = 2 * \<^bold>|v \<^sup>@ i\<^bold>| + 3 * (2 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|)" using \<open>2*\<^bold>|y\<^sup>@i\<^bold>| + 3*\<^bold>|x\<^bold>| = 2*\<^bold>|v\<^sup>@i\<^bold>| + 3*\<^bold>|u\<^bold>|\<close> unfolding \<open>\<^bold>|u\<^bold>| = 2 * \<^bold>|r \<^sup>@ (k - m)\<^bold>| + \<^bold>|x\<^bold>|\<close> add_mult_distrib2 by simp hence "2 * \<^bold>|y \<^sup>@ i\<^bold>| = 2 * \<^bold>|v \<^sup>@ i\<^bold>| + 2 * (3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|)" by presburger hence "2 * \<^bold>|y \<^sup>@ i\<^bold>| = 2 * (\<^bold>|v \<^sup>@ i\<^bold>| + (3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|))" by simp thus "\<^bold>|y \<^sup>@ i\<^bold>| = \<^bold>|v \<^sup>@ i\<^bold>| + 3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|" using nat_mult_eq_cancel1[of 2] zero_less_numeral by force hence "3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>| \<le> \<^bold>|y \<^sup>@ i\<^bold>|" using le_add2 by presburger moreover have "\<^bold>|r\<^bold>| \<le> \<^bold>|r \<^sup>@ (k - m)\<^bold>|" by (metis CoWBasic.power.power_Suc CoWBasic.power_Suc2 \<open>primitive r\<close> \<open>u \<cdot> v \<^sup>@ i <p x \<cdot> y \<^sup>@ i\<close> \<open>x \<cdot> y \<^sup>@ i = u \<cdot> v \<^sup>@ i \<cdot> r \<^sup>@ (k - m)\<close> not_le prim_comm_short_emp self_append_conv strict_prefix_def) ultimately have "3 * \<^bold>|r\<^bold>| \<le> \<^bold>|y \<^sup>@ i\<^bold>|" by (meson le_trans mult_le_mono2) hence "3 * \<^bold>|r\<^bold>| \<le> i*\<^bold>|y\<^bold>|" by (simp add: pow_len) moreover have "i \<le> 3*(i-1)" using assms(2) by linarith ultimately have "3*\<^bold>|r\<^bold>| \<le> 3*((i-1)*\<^bold>|y\<^bold>|)" by (metis (no_types, lifting) le_trans mult.assoc mult_le_mono1) hence "\<^bold>|r\<^bold>| \<le> (i-1)*\<^bold>|y\<^bold>|" by (meson nat_mult_le_cancel1 zero_less_numeral) thus "\<^bold>|r\<^bold>| \<le> \<^bold>|y\<^sup>@(i-1)\<^bold>|" unfolding pow_len. qed have "\<^bold>|r\<^bold>| + \<^bold>|y\<^bold>| \<le> \<^bold>|y \<^sup>@ i\<^bold>|" using \<open>\<^bold>|r\<^bold>| \<le> \<^bold>|y\<^sup>@(i-1)\<^bold>|\<close> unfolding pow_len nat_add_left_cancel_le[of "\<^bold>|y\<^bold>|" "\<^bold>|r\<^bold>|", symmetric] using add.commute \<open>i \<noteq> 0\<close> mult_eq_if by force have "y\<^sup>@i \<le>s y\<^sup>@i\<cdot>r" using triv_suf[of "y \<^sup>@ i" x, unfolded \<open>x \<cdot> y \<^sup>@ i = r \<^sup>@ k\<close>, THEN suf_prod_root]. have "y\<^sup>@i \<le>s y\<^sup>@i\<cdot>y" by (simp add: suf_pow_ext') from two_pers[reversed, OF \<open>y\<^sup>@i \<le>s y\<^sup>@i\<cdot>r\<close> \<open>y\<^sup>@i \<le>s y\<^sup>@i\<cdot>y\<close> \<open>\<^bold>|r\<^bold>| + \<^bold>|y\<^bold>| \<le> \<^bold>|y \<^sup>@ i\<^bold>|\<close>] have "y \<cdot> r = r \<cdot> y". have "x \<cdot> y \<^sup>@ i \<cdot> r = r \<cdot> x \<cdot> y \<^sup>@ i" by (simp add: power_commutes \<open>x \<cdot> y \<^sup>@ i = r \<^sup>@ k\<close> lassoc) hence "x \<cdot> r \<cdot> y \<^sup>@ i = r \<cdot> x \<cdot> y \<^sup>@ i" by (simp add: \<open>y \<cdot> r = r \<cdot> y\<close> comm_add_exp) hence "x \<cdot> r = r \<cdot> x" by auto obtain n where "y = r\<^sup>@n" using \<open>primitive r\<close> \<open>y \<cdot> r = r \<cdot> y\<close> by blast hence "\<^bold>|y\<^sup>@i\<^bold>| = i*n*\<^bold>|r\<^bold>|" by (simp add: pow_len) hence "\<^bold>|v \<^sup>@ i\<^bold>| = i*n*\<^bold>|r\<^bold>| - 3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|" using \<open>\<^bold>|y \<^sup>@ i\<^bold>| = \<^bold>|v \<^sup>@ i\<^bold>| + 3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|\<close> diff_add_inverse2 by presburger hence "\<^bold>|v \<^sup>@ i\<^bold>| = (i*n - 3*(k-m))*\<^bold>|r\<^bold>|" by (simp add: \<open>\<^bold>|v \<^sup>@ i\<^bold>| = i * n * \<^bold>|r\<^bold>| - 3 * \<^bold>|r \<^sup>@ (k - m)\<^bold>|\<close> ab_semigroup_mult_class.mult_ac(1) left_diff_distrib' pow_len) have "v\<^sup>@i \<in> r*" using per_exp_eq[reversed, OF _ \<open>\<^bold>|v \<^sup>@ i\<^bold>| = (i*n - 3*(k-m))*\<^bold>|r\<^bold>|\<close>] \<open>u \<cdot> v \<^sup>@ i = r \<^sup>@ m\<close> suf_prod_root triv_suf by metis have "u \<cdot> r = r \<cdot> u" using root_suf_cancel[OF \<open>v \<^sup>@ i \<in> r*\<close> rootI[of r m, folded \<open>u \<cdot> v \<^sup>@ i = r \<^sup>@ m\<close>]] self_root[of r] unfolding comm_root by blast have "v \<cdot> r = r \<cdot> v" using comm_drop_exp[OF \<open>i \<noteq> 0\<close>, OF comm_rootI[OF self_root \<open>v\<^sup>@i \<in> r*\<close>]]. show ?thesis using commutesI_root[of "{x, y, u, v}" r] prim_comm_root[OF \<open>primitive r\<close> \<open>u \<cdot> r = r \<cdot> u\<close>] prim_comm_root[OF \<open>primitive r\<close> \<open>v \<cdot> r = r \<cdot> v\<close>] prim_comm_root[OF \<open>primitive r\<close> \<open>x \<cdot> r = r \<cdot> x\<close>] prim_comm_root[OF \<open>primitive r\<close> \<open>y \<cdot> r = r \<cdot> y\<close>] by auto qed theorem "\<not> binary_equality_word (\<zero> \<cdot> \<one>\<^sup>@Suc k \<cdot> \<zero> \<cdot> \<one>)" proof assume "binary_equality_word (\<zero> \<cdot> \<one> \<^sup>@ Suc k \<cdot> \<zero> \<cdot> \<one>)" then obtain g' h' where g'_morph: "binary_code_morphism (g' :: binA list \<Rightarrow> nat list)" and h'_morph: "binary_code_morphism h'" and "g' \<noteq> h'" and msol': "(\<zero> \<cdot> \<one> \<^sup>@ Suc k \<cdot> \<zero> \<cdot> \<one>) \<in> g' =\<^sub>M h'" using binary_equality_word_def by blast interpret g': binary_code_morphism g' by fact interpret h': binary_code_morphism h' by fact interpret gh: two_morphisms g' h' by (simp add: g'.morphism_axioms h'.morphism_axioms two_morphisms_def) have "\<^bold>|g'(\<zero> \<cdot> \<one>)\<^bold>| \<noteq> \<^bold>|h'(\<zero> \<cdot> \<one>)\<^bold>|" proof assume len: "\<^bold>|g'(\<zero> \<cdot> \<one>)\<^bold>| = \<^bold>|h'(\<zero> \<cdot> \<one>)\<^bold>|" hence eq1: "g'(\<zero> \<cdot> \<one>) = h'(\<zero> \<cdot> \<one>)" and eq2: "g' (\<one>\<^sup>@k \<cdot> \<zero> \<cdot> \<one>) = h' (\<one>\<^sup>@k \<cdot> \<zero> \<cdot> \<one>)" using msol' eqd_eq[OF _ len, of "g' (\<one>\<^sup>@k \<cdot> \<zero> \<cdot> \<one>)" "h' (\<one>\<^sup>@k \<cdot> \<zero> \<cdot> \<one>) "] unfolding minsoldef pow_Suc pow_one g'.morph[symmetric] h'.morph[symmetric] rassoc by blast+ hence "g' (\<one>\<^sup>@k) = h' (\<one>\<^sup>@k)" by (simp add: g'.morph h'.morph) show False proof (cases "k = 0") assume "k = 0" from minsolD_min[OF msol' _ _ eq1, unfolded \<open>k = 0\<close> pow_one] show False by simp next assume "k \<noteq> 0" hence "g' (\<one>) = h' (\<one>)" using \<open>g' (\<one>\<^sup>@k) = h' (\<one>\<^sup>@k)\<close> unfolding g'.pow_morph h'.pow_morph using pow_eq_eq by blast hence "g' (\<zero>) = h' (\<zero>)" using \<open>g'(\<zero> \<cdot> \<one>) = h'(\<zero> \<cdot> \<one>)\<close> unfolding g'.morph h'.morph by simp show False using gh.def_on_sings_eq[OF finite_2.induct[of "\<lambda> a. g'[a] = h'[a]", OF \<open>g' (\<zero>) = h' (\<zero>)\<close> \<open>g' (\<one>) = h' (\<one>)\<close>]] \<open>g' \<noteq> h'\<close> by blast qed qed then have less': "\<^bold>|(if \<^bold>|g' (\<zero> \<cdot> \<one>)\<^bold>| < \<^bold>|h' (\<zero> \<cdot> \<one>)\<^bold>| then g' else h') (\<zero> \<cdot> \<one>)\<^bold>| < \<^bold>|(if \<^bold>|g' (\<zero> \<cdot> \<one>)\<^bold>| < \<^bold>|h' (\<zero> \<cdot> \<one>)\<^bold>| then h' else g') (\<zero> \<cdot> \<one>)\<^bold>|" by simp obtain g h where g_morph: "binary_code_morphism (g :: binA list \<Rightarrow> nat list)" and h_morph: "binary_code_morphism h" and msol: "g (\<zero> \<cdot> \<one> \<^sup>@ Suc k \<cdot> \<zero> \<cdot> \<one>) = h (\<zero> \<cdot> \<one> \<^sup>@ Suc k \<cdot> \<zero> \<cdot> \<one>)" and less: "\<^bold>|g(\<zero> \<cdot> \<one>)\<^bold>| < \<^bold>|h(\<zero> \<cdot> \<one>)\<^bold>|" using that[of "(if \<^bold>|g' (\<zero> \<cdot> \<one>)\<^bold>| < \<^bold>|h' (\<zero> \<cdot> \<one>)\<^bold>| then g' else h')" "(if \<^bold>|g' (\<zero> \<cdot> \<one>)\<^bold>| < \<^bold>|h' (\<zero> \<cdot> \<one>)\<^bold>| then h' else g')", OF _ _ _ less'] g'_morph h'_morph minsolD[OF msol'] by presburger interpret g: binary_code_morphism g using g_morph by blast interpret h: binary_code_morphism h using h_morph by blast have "g \<one> \<le>s g (\<zero> \<cdot> \<one>)" and "h \<one> \<le>s h (\<zero> \<cdot> \<one>)" unfolding g.morph h.morph by blast+ from not_bew_baiba[OF less this, of k] msol have "commutes {g \<one>, g (\<zero> \<cdot> \<one>), h \<one>, h (\<zero> \<cdot> \<one>)}" unfolding g.morph h.morph g.pow_morph h.pow_morph pow_Suc rassoc by blast hence "g \<one> \<cdot> g (\<zero> \<cdot> \<one>) = g (\<zero> \<cdot> \<one>) \<cdot> g \<one>" unfolding commutes_def by blast from this[unfolded g.morph lassoc cancel_right] show False using g.non_comm_morph by simp qed end
lemma inner_sum_Basis[simp]: "i \<in> Basis \<Longrightarrow> (\<Sum>Basis) \<bullet> i = 1"
[STATEMENT] lemma moebius_mat_eq_refl [simp]: shows "moebius_mat_eq x x" [PROOF STATE] proof (prove) goal (1 subgoal): 1. moebius_mat_eq x x [PROOF STEP] by transfer simp
program problem_10 implicit none logical :: isPrime integer(kind = 8) :: total integer :: limit integer :: current ! This code is inneficient as fuck, sorry guys [~85.19 s]. total = 2 current = 3 limit = 2000000 do while (current .LT. limit) if (isPrime(current)) then total = total + current endif current = current + 2 enddo print *, total end program problem_10 logical function isPrime(number) implicit none integer :: number integer :: i if ((number .EQ. 0) .OR. (number .EQ. 1) .OR. ((number .NE. 2) .AND. (modulo(number, 2) .EQ. 0))) then isPrime = .FALSE. return endif do i=3, number / 3, 2 if (modulo(number, i) .EQ. 0) then isPrime = .FALSE. return endif enddo isPrime = .TRUE. return end function isPrime
/*============================================================================= Copyright (c) 2010-2016 Bolero MURAKAMI https://github.com/bolero-MURAKAMI/Sprig Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) =============================================================================*/ #ifndef SPRIG_TMP_ITER_INDEX_HPP #define SPRIG_TMP_ITER_INDEX_HPP #include <sprig/config/config.hpp> #ifdef SPRIG_USING_PRAGMA_ONCE # pragma once #endif // #ifdef SPRIG_USING_PRAGMA_ONCE #include <boost/mpl/distance.hpp> #include <boost/mpl/begin.hpp> namespace sprig { namespace tmp { // // iter_index // template<typename Sequence, typename Iterator> struct iter_index : public boost::mpl::distance< typename boost::mpl::begin<Sequence>::type, Iterator > {}; } // namespace tmp } // namespace sprig #endif // #ifndef SPRIG_TMP_ITER_INDEX_HPP
{-# OPTIONS --cubical #-} module Type.Cubical.Path.Equality where open import Functional open import Function.Axioms import Lvl open import Type open import Type.Cubical open import Type.Cubical.Path open import Type.Cubical.Path.Proofs as Path open import Structure.Function open import Structure.Operator open import Structure.Relator.Equivalence open import Structure.Relator.Properties open import Structure.Relator open import Structure.Setoid using (Equiv ; intro) open import Structure.Type.Identity private variable ℓ ℓ₁ ℓ₂ ℓₚ : Lvl.Level private variable T A B C : Type{ℓ} private variable f : A → B private variable _▫_ : A → B → C private variable P : T → Type{ℓ} private variable x y : T _≡_ : T → T → Type _≡_ = Path instance Path-reflexivity : Reflexivity{T = T}(Path) Path-reflexivity = intro Path.point instance Path-symmetry : Symmetry{T = T}(Path) Path-symmetry = intro Path.reverse instance Path-transitivity : Transitivity{T = T}(Path) Path-transitivity = intro Path.concat instance Path-equivalence : Equivalence{T = T}(Path) Path-equivalence = intro instance Path-equiv : Equiv(T) Path-equiv = intro(Path) ⦃ Path-equivalence ⦄ instance Path-congruence₁ : Function(f) Path-congruence₁ {f = f} = intro(Path.map f) instance Path-congruence₂ : BinaryOperator(_▫_) Path-congruence₂ {_▫_ = _▫_} = intro(Path.map₂(_▫_)) instance Path-substitution₁ : UnaryRelator(P) Path-substitution₁ {P = P} = intro(Path.liftedSpaceMap P) instance Path-substitution₂ : BinaryRelator(_▫_) Path-substitution₂ {_▫_ = _▫_} = intro(Path.liftedSpaceMap₂(_▫_)) instance Path-coercion : Path ⊆₂ (_→ᶠ_ {ℓ}{ℓ}) Path-coercion = intro(Path.spaceMap) Path-sub-of-reflexive : ⦃ refl : Reflexivity(_▫_) ⦄ → (Path ⊆₂ (_▫_)) Path-sub-of-reflexive {_▫_ = _▫_} = intro(\{a b} → ab ↦ sub₂(Path)(_→ᶠ_) ⦃ Path-coercion ⦄ (congruence₂ᵣ(_▫_)(a) ab) (reflexivity(_▫_) {a})) instance Path-function-extensionality : FunctionExtensionality A B Path-function-extensionality = intro Path.mapping instance Path-dependent-function-extensionality : ∀{A : Type{ℓ₁}}{B : (a : A) → Type{ℓ₂}} → DependentFunctionExtensionality A B Path-dependent-function-extensionality = intro Path.mapping instance Path-function-application : FunctionApplication A B Path-function-application = intro Path.mappingPoint Path-identity-eliminator : IdentityEliminator{ℓₚ = ℓₚ}(Path{P = T}) IdentityEliminator.elim Path-identity-eliminator P prefl eq = sub₂(Path)(_→ᶠ_) ⦃ Path-coercion ⦄ (\i → P(\j → eq(Interval.min i j))) prefl -- TODO: Organize and move everything below open import Type.Properties.MereProposition open import Type.Properties.Singleton prop-is-prop-unit : ⦃ proof : MereProposition(A) ⦄ → IsUnit(MereProposition(A)) MereProposition.uniqueness (IsUnit.unit prop-is-prop-unit) {x} {y} = uniqueness _ MereProposition.uniqueness (IsUnit.uniqueness (prop-is-prop-unit {A = A}) {intro p} i) {x}{y} j = Interval.hComp d x where d : Interval → Interval.Partial (Interval.max (Interval.max (Interval.flip i) i) (Interval.max (Interval.flip j) j)) A d k (i = Interval.𝟎) = uniqueness(A) {x}{p{x}{y} j} k d k (i = Interval.𝟏) = uniqueness(A) {x}{uniqueness(A) {x}{y} j} k d k (j = Interval.𝟎) = uniqueness(A) {x}{x} k d k (j = Interval.𝟏) = uniqueness(A) {x}{y} k {- Path-isUnit : ∀{ℓ}{A : Type{ℓ}} → ⦃ _ : MereProposition(A) ⦄ → (∀{x y : A} → IsUnit(x ≡ y)) IsUnit.unit (Path-isUnit {A = A}) = uniqueness(A) IsUnit.uniqueness (Path-isUnit {A = A} ⦃ mere-A ⦄ {x = x} {y = y}) {p} i = Interval.hComp d p where d : Interval → Interval.Partial (Interval.max (Interval.flip i) i) (Path x y) d j (i = Interval.𝟎) = p d j (i = Interval.𝟏) = {!uniqueness(A) {x}{y}!} -- congruence₁ (prop ↦ MereProposition.uniqueness prop {x}{y}) (IsUnit.uniqueness prop-is-prop-unit {intro (\{x y} → {!p!})}) -} {- open import Structure.Setoid.Uniqueness open import Type.Dependent -} -- TODO -- ∀{eu₁ eu₂ : ∃!{Obj = Obj}(Pred)} → () → (eu₁ ≡ eu₂) {- Unique-MereProposition-equivalence : ⦃ prop : ∀{x} → MereProposition(P(x)) ⦄ → (Unique(P) ↔ MereProposition(∃ P)) Unique-MereProposition-equivalence {P = P} = [↔]-intro l r where l : Unique(P) ← MereProposition(∃ P) l (intro p) {x} {y} px py = mapP([∃]-witness) (p{[∃]-intro x ⦃ px ⦄} {[∃]-intro y ⦃ py ⦄}) r : Unique(P) → MereProposition(∃ P) MereProposition.uniqueness (r p) {[∃]-intro w₁ ⦃ p₁ ⦄} {[∃]-intro w₂ ⦃ p₂ ⦄} i = mapP (mapP (\w p → [∃]-intro w ⦃ p ⦄) (p p₁ p₂) i) {!!} i -- mapP [∃]-intro (p p₁ p₂) i ⦃ {!!} ⦄ Unique-prop : ⦃ prop : ∀{x} → MereProposition(P(x)) ⦄ → MereProposition(Unique(P)) MereProposition.uniqueness Unique-prop {u₁} {u₂} i {x} {y} px py j = Interval.hComp d x where d : Interval → Interval.Partial (Interval.max (Interval.max (Interval.flip i) i) (Interval.max (Interval.flip j) j)) A d k (i = Interval.𝟎) = {!!} d k (i = Interval.𝟏) = {!!} d k (j = Interval.𝟎) = {!!} d k (j = Interval.𝟏) = {!!} [∃!trunc]-to-existence : ⦃ prop : ∀{x} → MereProposition(Pred(x)) ⦄ → HTrunc₁(∃!{Obj = Obj}(Pred)) → HomotopyLevel(0)(∃{Obj = Obj}(Pred)) [∃!trunc]-to-existence {Pred = Pred} (trunc ([∧]-intro e u)) = intro e (\{e₂} i → [∃]-intro (u ([∃]-proof e₂) ([∃]-proof e) i) ⦃ {!!} ⦄) -- MereProposition.uniqueness test) {u _ _ _} -- sub₂(_≡_)(_→ᶠ_) ⦃ [≡][→]-sub ⦄ (congruence₁(Pred) ?) ? [∃!trunc]-to-existence (trunc-proof i) = {!!} -} {- [∃!]-squashed-witness : HTrunc₁(∃!{Obj = Obj}(Pred)) → Obj [∃!]-squashed-witness (trunc eu) = [∃]-witness([∧]-elimₗ eu) [∃!]-squashed-witness (trunc-proof {trunc ([∧]-intro e₁ u₁)} {trunc ([∧]-intro e₂ u₂)} i) = u₁ ([∃]-proof e₁) ([∃]-proof e₂) i [∃!]-squashed-witness (trunc-proof {trunc ([∧]-intro e₁ u₁)} {trunc-proof j} i) = {!!} [∃!]-squashed-witness (trunc-proof {trunc-proof i₁} {trunc x} i) = {!!} [∃!]-squashed-witness (trunc-proof {trunc-proof i₁} {trunc-proof i₂} i) = {!!} -}
(* Title: HOL/Analysis/Bounded_Linear_Function.thy Author: Fabian Immler, TU München *) section \<open>\<open>Complex_Bounded_Linear_Function0\<close> -- Bounded Linear Function\<close> theory Complex_Bounded_Linear_Function0 imports "HOL-Analysis.Bounded_Linear_Function" Complex_Inner_Product Complex_Euclidean_Space0 begin unbundle cinner_syntax lemma conorm_componentwise: assumes "bounded_clinear f" shows "onorm f \<le> (\<Sum>i\<in>CBasis. norm (f i))" proof - { fix i::'a assume "i \<in> CBasis" hence "onorm (\<lambda>x. (i \<bullet>\<^sub>C x) *\<^sub>C f i) \<le> onorm (\<lambda>x. (i \<bullet>\<^sub>C x)) * norm (f i)" by (auto intro!: onorm_scaleC_left_lemma bounded_clinear_cinner_right) also have "\<dots> \<le> norm i * norm (f i)" apply (rule mult_right_mono) apply (simp add: complex_inner_class.Cauchy_Schwarz_ineq2 onorm_bound) by simp finally have "onorm (\<lambda>x. (i \<bullet>\<^sub>C x) *\<^sub>C f i) \<le> norm (f i)" using \<open>i \<in> CBasis\<close> by simp } hence "onorm (\<lambda>x. \<Sum>i\<in>CBasis. (i \<bullet>\<^sub>C x) *\<^sub>C f i) \<le> (\<Sum>i\<in>CBasis. norm (f i))" by (auto intro!: order_trans[OF onorm_sum_le] bounded_clinear_scaleC_const sum_mono bounded_clinear_cinner_right bounded_clinear.bounded_linear) also have "(\<lambda>x. \<Sum>i\<in>CBasis. (i \<bullet>\<^sub>C x) *\<^sub>C f i) = (\<lambda>x. f (\<Sum>i\<in>CBasis. (i \<bullet>\<^sub>C x) *\<^sub>C i))" by (simp add: clinear.scaleC linear_sum bounded_clinear.clinear clinear.linear assms) also have "\<dots> = f" by (simp add: ceuclidean_representation) finally show ?thesis . qed lemmas conorm_componentwise_le = order_trans[OF conorm_componentwise] subsection\<^marker>\<open>tag unimportant\<close> \<open>Intro rules for \<^term>\<open>bounded_linear\<close>\<close> (* We share the same attribute [bounded_linear_intros] with Bounded_Linear_Function *) (* named_theorems bounded_linear_intros *) lemma onorm_cinner_left: assumes "bounded_linear r" shows "onorm (\<lambda>x. r x \<bullet>\<^sub>C f) \<le> onorm r * norm f" proof (rule onorm_bound) fix x have "norm (r x \<bullet>\<^sub>C f) \<le> norm (r x) * norm f" by (simp add: Cauchy_Schwarz_ineq2) also have "\<dots> \<le> onorm r * norm x * norm f" by (simp add: assms mult.commute mult_left_mono onorm) finally show "norm (r x \<bullet>\<^sub>C f) \<le> onorm r * norm f * norm x" by (simp add: ac_simps) qed (intro mult_nonneg_nonneg norm_ge_zero onorm_pos_le assms) lemma onorm_cinner_right: assumes "bounded_linear r" shows "onorm (\<lambda>x. f \<bullet>\<^sub>C r x) \<le> norm f * onorm r" proof (rule onorm_bound) fix x have "norm (f \<bullet>\<^sub>C r x) \<le> norm f * norm (r x)" by (simp add: Cauchy_Schwarz_ineq2) also have "\<dots> \<le> onorm r * norm x * norm f" by (simp add: assms mult.commute mult_left_mono onorm) finally show "norm (f \<bullet>\<^sub>C r x) \<le> norm f * onorm r * norm x" by (simp add: ac_simps) qed (intro mult_nonneg_nonneg norm_ge_zero onorm_pos_le assms) lemmas [bounded_linear_intros] = bounded_clinear_zero bounded_clinear_add bounded_clinear_const_mult bounded_clinear_mult_const bounded_clinear_scaleC_const bounded_clinear_const_scaleC bounded_clinear_const_scaleR bounded_clinear_ident bounded_clinear_sum (* bounded_clinear_Pair *) (* The Product_Vector theory does not instantiate Pair for complex vector spaces *) bounded_clinear_sub (* bounded_clinear_fst_comp *) (* The Product_Vector theory does not instantiate Pair for complex vector spaces *) (* bounded_clinear_snd_comp *) (* The Product_Vector theory does not instantiate Pair for complex vector spaces *) bounded_antilinear_cinner_left_comp bounded_clinear_cinner_right_comp subsection\<^marker>\<open>tag unimportant\<close> \<open>declaration of derivative/continuous/tendsto introduction rules for bounded linear functions\<close> attribute_setup bounded_clinear = \<open>let val bounded_linear = Attrib.attribute \<^context> (the_single @{attributes [bounded_linear]}) in Scan.succeed (Thm.declaration_attribute (fn thm => Thm.attribute_declaration bounded_linear (thm RS @{thm bounded_clinear.bounded_linear}) o fold (fn (r, s) => Named_Theorems.add_thm s (thm RS r)) [ (* Not present in Bounded_Linear_Function *) (@{thm bounded_clinear_compose}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_clinear_o_bounded_antilinear[unfolded o_def]}, \<^named_theorems>\<open>bounded_linear_intros\<close>) ])) end\<close> (* Analogue to [bounded_clinear], not present in Bounded_Linear_Function *) attribute_setup bounded_antilinear = \<open>let val bounded_linear = Attrib.attribute \<^context> (the_single @{attributes [bounded_linear]}) in Scan.succeed (Thm.declaration_attribute (fn thm => Thm.attribute_declaration bounded_linear (thm RS @{thm bounded_antilinear.bounded_linear}) o fold (fn (r, s) => Named_Theorems.add_thm s (thm RS r)) [ (* Not present in Bounded_Linear_Function *) (@{thm bounded_antilinear_o_bounded_clinear[unfolded o_def]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_antilinear_o_bounded_antilinear[unfolded o_def]}, \<^named_theorems>\<open>bounded_linear_intros\<close>) ])) end\<close> attribute_setup bounded_cbilinear = \<open>let val bounded_bilinear = Attrib.attribute \<^context> (the_single @{attributes [bounded_bilinear]}) in Scan.succeed (Thm.declaration_attribute (fn thm => Thm.attribute_declaration bounded_bilinear (thm RS @{thm bounded_cbilinear.bounded_bilinear}) o fold (fn (r, s) => Named_Theorems.add_thm s (thm RS r)) [ (@{thm bounded_clinear_compose[OF bounded_cbilinear.bounded_clinear_left]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_clinear_compose[OF bounded_cbilinear.bounded_clinear_right]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_clinear_o_bounded_antilinear[unfolded o_def, OF bounded_cbilinear.bounded_clinear_left]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_clinear_o_bounded_antilinear[unfolded o_def, OF bounded_cbilinear.bounded_clinear_right]}, \<^named_theorems>\<open>bounded_linear_intros\<close>) ])) end\<close> (* Analogue to [bounded_sesquilinear], not present in Bounded_Linear_Function *) attribute_setup bounded_sesquilinear = \<open>let val bounded_bilinear = Attrib.attribute \<^context> (the_single @{attributes [bounded_bilinear]}) in Scan.succeed (Thm.declaration_attribute (fn thm => Thm.attribute_declaration bounded_bilinear (thm RS @{thm bounded_sesquilinear.bounded_bilinear}) o fold (fn (r, s) => Named_Theorems.add_thm s (thm RS r)) [ (@{thm bounded_antilinear_o_bounded_clinear[unfolded o_def, OF bounded_sesquilinear.bounded_antilinear_left]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_clinear_compose[OF bounded_sesquilinear.bounded_clinear_right]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_antilinear_o_bounded_antilinear[unfolded o_def, OF bounded_sesquilinear.bounded_antilinear_left]}, \<^named_theorems>\<open>bounded_linear_intros\<close>), (@{thm bounded_clinear_o_bounded_antilinear[unfolded o_def, OF bounded_sesquilinear.bounded_clinear_right]}, \<^named_theorems>\<open>bounded_linear_intros\<close>) ])) end\<close> subsection \<open>Type of complex bounded linear functions\<close> typedef\<^marker>\<open>tag important\<close> (overloaded) ('a, 'b) cblinfun ("(_ \<Rightarrow>\<^sub>C\<^sub>L /_)" [22, 21] 21) = "{f::'a::complex_normed_vector\<Rightarrow>'b::complex_normed_vector. bounded_clinear f}" morphisms cblinfun_apply CBlinfun by (blast intro: bounded_linear_intros) declare [[coercion "cblinfun_apply :: ('a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L'b::complex_normed_vector) \<Rightarrow> 'a \<Rightarrow> 'b"]] lemma bounded_clinear_cblinfun_apply[bounded_linear_intros]: "bounded_clinear g \<Longrightarrow> bounded_clinear (\<lambda>x. cblinfun_apply f (g x))" by (metis cblinfun_apply mem_Collect_eq bounded_clinear_compose) setup_lifting type_definition_cblinfun lemma cblinfun_eqI: "(\<And>i. cblinfun_apply x i = cblinfun_apply y i) \<Longrightarrow> x = y" by transfer auto lemma bounded_clinear_CBlinfun_apply: "bounded_clinear f \<Longrightarrow> cblinfun_apply (CBlinfun f) = f" by (auto simp: CBlinfun_inverse) subsection \<open>Type class instantiations\<close> instantiation cblinfun :: (complex_normed_vector, complex_normed_vector) complex_normed_vector begin lift_definition\<^marker>\<open>tag important\<close> norm_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> real" is onorm . lift_definition minus_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>f g x. f x - g x" by (rule bounded_clinear_sub) definition dist_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> real" where "dist_cblinfun a b = norm (a - b)" definition [code del]: "(uniformity :: (('a \<Rightarrow>\<^sub>C\<^sub>L 'b) \<times> ('a \<Rightarrow>\<^sub>C\<^sub>L 'b)) filter) = (INF e\<in>{0 <..}. principal {(x, y). dist x y < e})" definition open_cblinfun :: "('a \<Rightarrow>\<^sub>C\<^sub>L 'b) set \<Rightarrow> bool" where [code del]: "open_cblinfun S = (\<forall>x\<in>S. \<forall>\<^sub>F (x', y) in uniformity. x' = x \<longrightarrow> y \<in> S)" lift_definition uminus_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>f x. - f x" by (rule bounded_clinear_minus) lift_definition\<^marker>\<open>tag important\<close> zero_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>x. 0" by (rule bounded_clinear_zero) lift_definition\<^marker>\<open>tag important\<close> plus_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>f g x. f x + g x" by (metis bounded_clinear_add) lift_definition\<^marker>\<open>tag important\<close> scaleC_cblinfun::"complex \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>r f x. r *\<^sub>C f x" by (metis bounded_clinear_compose bounded_clinear_scaleC_right) lift_definition\<^marker>\<open>tag important\<close> scaleR_cblinfun::"real \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>r f x. r *\<^sub>R f x" by (rule bounded_clinear_const_scaleR) definition sgn_cblinfun :: "'a \<Rightarrow>\<^sub>C\<^sub>L 'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" where "sgn_cblinfun x = scaleC (inverse (norm x)) x" instance proof fix a b c :: "'a \<Rightarrow>\<^sub>C\<^sub>L'b" and r q :: real and s t :: complex show \<open>a + b + c = a + (b + c)\<close> apply transfer by auto show \<open>0 + a = a\<close> apply transfer by auto show \<open>a + b = b + a\<close> apply transfer by auto show \<open>- a + a = 0\<close> apply transfer by auto show \<open>a - b = a + - b\<close> apply transfer by auto show scaleR_scaleC: \<open>((*\<^sub>R) r::('a \<Rightarrow>\<^sub>C\<^sub>L 'b) \<Rightarrow> _) = (*\<^sub>C) (complex_of_real r)\<close> for r apply (rule ext, transfer fixing: r) by (simp add: scaleR_scaleC) show \<open>s *\<^sub>C (b + c) = s *\<^sub>C b + s *\<^sub>C c\<close> apply transfer by (simp add: scaleC_add_right) show \<open>(s + t) *\<^sub>C a = s *\<^sub>C a + t *\<^sub>C a\<close> apply transfer by (simp add: scaleC_left.add) show \<open>s *\<^sub>C t *\<^sub>C a = (s * t) *\<^sub>C a\<close> apply transfer by auto show \<open>1 *\<^sub>C a = a\<close> apply transfer by auto show \<open>dist a b = norm (a - b)\<close> unfolding dist_cblinfun_def by simp show \<open>sgn a = (inverse (norm a)) *\<^sub>R a\<close> unfolding sgn_cblinfun_def unfolding scaleR_scaleC by auto show \<open>uniformity = (INF e\<in>{0<..}. principal {(x, y). dist (x::('a \<Rightarrow>\<^sub>C\<^sub>L 'b)) y < e})\<close> by (simp add: uniformity_cblinfun_def) show \<open>open U = (\<forall>x\<in>U. \<forall>\<^sub>F (x', y) in uniformity. (x'::('a \<Rightarrow>\<^sub>C\<^sub>L 'b)) = x \<longrightarrow> y \<in> U)\<close> for U by (simp add: open_cblinfun_def) show \<open>(norm a = 0) = (a = 0)\<close> apply transfer using bounded_clinear.bounded_linear onorm_eq_0 by blast show \<open>norm (a + b) \<le> norm a + norm b\<close> apply transfer by (simp add: bounded_clinear.bounded_linear onorm_triangle) show \<open>norm (s *\<^sub>C a) = cmod s * norm a\<close> apply transfer using onorm_scalarC by blast show \<open>norm (r *\<^sub>R a) = \<bar>r\<bar> * norm a\<close> apply transfer using bounded_clinear.bounded_linear onorm_scaleR by blast show \<open>r *\<^sub>R (a + b) = r *\<^sub>R a + r *\<^sub>R b\<close> apply transfer by (simp add: scaleR_add_right) show \<open>(r + q) *\<^sub>R a = r *\<^sub>R a + q *\<^sub>R a\<close> apply transfer by (simp add: scaleR_add_left) show \<open>r *\<^sub>R q *\<^sub>R a = (r * q) *\<^sub>R a\<close> apply transfer by auto show \<open>1 *\<^sub>R a = a\<close> apply transfer by auto qed end declare uniformity_Abort[where 'a="('a :: complex_normed_vector) \<Rightarrow>\<^sub>C\<^sub>L ('b :: complex_normed_vector)", code] lemma norm_cblinfun_eqI: assumes "n \<le> norm (cblinfun_apply f x) / norm x" assumes "\<And>x. norm (cblinfun_apply f x) \<le> n * norm x" assumes "0 \<le> n" shows "norm f = n" by (auto simp: norm_cblinfun_def intro!: antisym onorm_bound assms order_trans[OF _ le_onorm] bounded_clinear.bounded_linear bounded_linear_intros) lemma norm_cblinfun: "norm (cblinfun_apply f x) \<le> norm f * norm x" apply transfer by (simp add: bounded_clinear.bounded_linear onorm) lemma norm_cblinfun_bound: "0 \<le> b \<Longrightarrow> (\<And>x. norm (cblinfun_apply f x) \<le> b * norm x) \<Longrightarrow> norm f \<le> b" by transfer (rule onorm_bound) lemma bounded_cbilinear_cblinfun_apply[bounded_cbilinear]: "bounded_cbilinear cblinfun_apply" proof fix f g::"'a \<Rightarrow>\<^sub>C\<^sub>L 'b" and a b::'a and r::complex show "(f + g) a = f a + g a" "(r *\<^sub>C f) a = r *\<^sub>C f a" by (transfer, simp)+ interpret bounded_clinear f for f::"'a \<Rightarrow>\<^sub>C\<^sub>L 'b" by (auto intro!: bounded_linear_intros) show "f (a + b) = f a + f b" "f (r *\<^sub>C a) = r *\<^sub>C f a" by (simp_all add: add scaleC) show "\<exists>K. \<forall>a b. norm (cblinfun_apply a b) \<le> norm a * norm b * K" by (auto intro!: exI[where x=1] norm_cblinfun) qed interpretation cblinfun: bounded_cbilinear cblinfun_apply by (rule bounded_cbilinear_cblinfun_apply) lemmas bounded_clinear_apply_cblinfun[intro, simp] = cblinfun.bounded_clinear_left declare cblinfun.zero_left [simp] cblinfun.zero_right [simp] context bounded_cbilinear begin named_theorems cbilinear_simps lemmas [cbilinear_simps] = add_left add_right diff_left diff_right minus_left minus_right scaleC_left scaleC_right zero_left zero_right sum_left sum_right end instance cblinfun :: (complex_normed_vector, cbanach) cbanach (* The proof is almost the same as for \<open>instance blinfun :: (real_normed_vector, banach) banach\<close> *) proof fix X::"nat \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" assume "Cauchy X" { fix x::'a { fix x::'a assume "norm x \<le> 1" have "Cauchy (\<lambda>n. X n x)" proof (rule CauchyI) fix e::real assume "0 < e" from CauchyD[OF \<open>Cauchy X\<close> \<open>0 < e\<close>] obtain M where M: "\<And>m n. m \<ge> M \<Longrightarrow> n \<ge> M \<Longrightarrow> norm (X m - X n) < e" by auto show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (X m x - X n x) < e" proof (safe intro!: exI[where x=M]) fix m n assume le: "M \<le> m" "M \<le> n" have "norm (X m x - X n x) = norm ((X m - X n) x)" by (simp add: cblinfun.cbilinear_simps) also have "\<dots> \<le> norm (X m - X n) * norm x" by (rule norm_cblinfun) also have "\<dots> \<le> norm (X m - X n) * 1" using \<open>norm x \<le> 1\<close> norm_ge_zero by (rule mult_left_mono) also have "\<dots> = norm (X m - X n)" by simp also have "\<dots> < e" using le by fact finally show "norm (X m x - X n x) < e" . qed qed hence "convergent (\<lambda>n. X n x)" by (metis Cauchy_convergent_iff) } note convergent_norm1 = this define y where "y = x /\<^sub>R norm x" have y: "norm y \<le> 1" and xy: "x = norm x *\<^sub>R y" by (simp_all add: y_def inverse_eq_divide) have "convergent (\<lambda>n. norm x *\<^sub>R X n y)" by (intro bounded_bilinear.convergent[OF bounded_bilinear_scaleR] convergent_const convergent_norm1 y) also have "(\<lambda>n. norm x *\<^sub>R X n y) = (\<lambda>n. X n x)" by (metis cblinfun.scaleC_right scaleR_scaleC xy) finally have "convergent (\<lambda>n. X n x)" . } then obtain v where v: "\<And>x. (\<lambda>n. X n x) \<longlonglongrightarrow> v x" unfolding convergent_def by metis have "Cauchy (\<lambda>n. norm (X n))" proof (rule CauchyI) fix e::real assume "e > 0" from CauchyD[OF \<open>Cauchy X\<close> \<open>0 < e\<close>] obtain M where M: "\<And>m n. m \<ge> M \<Longrightarrow> n \<ge> M \<Longrightarrow> norm (X m - X n) < e" by auto show "\<exists>M. \<forall>m\<ge>M. \<forall>n\<ge>M. norm (norm (X m) - norm (X n)) < e" proof (safe intro!: exI[where x=M]) fix m n assume mn: "m \<ge> M" "n \<ge> M" have "norm (norm (X m) - norm (X n)) \<le> norm (X m - X n)" by (metis norm_triangle_ineq3 real_norm_def) also have "\<dots> < e" using mn by fact finally show "norm (norm (X m) - norm (X n)) < e" . qed qed then obtain K where K: "(\<lambda>n. norm (X n)) \<longlonglongrightarrow> K" unfolding Cauchy_convergent_iff convergent_def by metis have "bounded_clinear v" proof fix x y and r::complex from tendsto_add[OF v[of x] v [of y]] v[of "x + y", unfolded cblinfun.cbilinear_simps] tendsto_scaleC[OF tendsto_const[of r] v[of x]] v[of "r *\<^sub>C x", unfolded cblinfun.cbilinear_simps] show "v (x + y) = v x + v y" "v (r *\<^sub>C x) = r *\<^sub>C v x" by (metis (poly_guards_query) LIMSEQ_unique)+ show "\<exists>K. \<forall>x. norm (v x) \<le> norm x * K" proof (safe intro!: exI[where x=K]) fix x have "norm (v x) \<le> K * norm x" apply (rule tendsto_le[OF _ tendsto_mult[OF K tendsto_const] tendsto_norm[OF v]]) by (auto simp: norm_cblinfun) thus "norm (v x) \<le> norm x * K" by (simp add: ac_simps) qed qed hence Bv: "\<And>x. (\<lambda>n. X n x) \<longlonglongrightarrow> CBlinfun v x" by (auto simp: bounded_clinear_CBlinfun_apply v) have "X \<longlonglongrightarrow> CBlinfun v" proof (rule LIMSEQ_I) fix r::real assume "r > 0" define r' where "r' = r / 2" have "0 < r'" "r' < r" using \<open>r > 0\<close> by (simp_all add: r'_def) from CauchyD[OF \<open>Cauchy X\<close> \<open>r' > 0\<close>] obtain M where M: "\<And>m n. m \<ge> M \<Longrightarrow> n \<ge> M \<Longrightarrow> norm (X m - X n) < r'" by metis show "\<exists>no. \<forall>n\<ge>no. norm (X n - CBlinfun v) < r" proof (safe intro!: exI[where x=M]) fix n assume n: "M \<le> n" have "norm (X n - CBlinfun v) \<le> r'" proof (rule norm_cblinfun_bound) fix x have "eventually (\<lambda>m. m \<ge> M) sequentially" by (metis eventually_ge_at_top) hence ev_le: "eventually (\<lambda>m. norm (X n x - X m x) \<le> r' * norm x) sequentially" proof eventually_elim case (elim m) have "norm (X n x - X m x) = norm ((X n - X m) x)" by (simp add: cblinfun.cbilinear_simps) also have "\<dots> \<le> norm ((X n - X m)) * norm x" by (rule norm_cblinfun) also have "\<dots> \<le> r' * norm x" using M[OF n elim] by (simp add: mult_right_mono) finally show ?case . qed have tendsto_v: "(\<lambda>m. norm (X n x - X m x)) \<longlonglongrightarrow> norm (X n x - CBlinfun v x)" by (auto intro!: tendsto_intros Bv) show "norm ((X n - CBlinfun v) x) \<le> r' * norm x" by (auto intro!: tendsto_upperbound tendsto_v ev_le simp: cblinfun.cbilinear_simps) qed (simp add: \<open>0 < r'\<close> less_imp_le) thus "norm (X n - CBlinfun v) < r" by (metis \<open>r' < r\<close> le_less_trans) qed qed thus "convergent X" by (rule convergentI) qed subsection\<^marker>\<open>tag unimportant\<close> \<open>On Euclidean Space\<close> (* No different in complex case *) (* lemma Zfun_sum: assumes "finite s" assumes f: "\<And>i. i \<in> s \<Longrightarrow> Zfun (f i) F" shows "Zfun (\<lambda>x. sum (\<lambda>i. f i x) s) F" *) lemma norm_cblinfun_ceuclidean_le: fixes a::"'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'b::complex_normed_vector" shows "norm a \<le> sum (\<lambda>x. norm (a x)) CBasis" apply (rule norm_cblinfun_bound) apply (simp add: sum_nonneg) apply (subst ceuclidean_representation[symmetric, where 'a='a]) apply (simp only: cblinfun.cbilinear_simps sum_distrib_right) apply (rule order.trans[OF norm_sum sum_mono]) apply (simp add: abs_mult mult_right_mono ac_simps CBasis_le_norm) by (metis complex_inner_class.Cauchy_Schwarz_ineq2 mult.commute mult.left_neutral mult_right_mono norm_CBasis norm_ge_zero) lemma ctendsto_componentwise1: fixes a::"'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'b::complex_normed_vector" and b::"'c \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" assumes "(\<And>j. j \<in> CBasis \<Longrightarrow> ((\<lambda>n. b n j) \<longlongrightarrow> a j) F)" shows "(b \<longlongrightarrow> a) F" proof - have "\<And>j. j \<in> CBasis \<Longrightarrow> Zfun (\<lambda>x. norm (b x j - a j)) F" using assms unfolding tendsto_Zfun_iff Zfun_norm_iff . hence "Zfun (\<lambda>x. \<Sum>j\<in>CBasis. norm (b x j - a j)) F" by (auto intro!: Zfun_sum) thus ?thesis unfolding tendsto_Zfun_iff by (rule Zfun_le) (auto intro!: order_trans[OF norm_cblinfun_ceuclidean_le] simp: cblinfun.cbilinear_simps) qed lift_definition cblinfun_of_matrix::"('b::ceuclidean_space \<Rightarrow> 'a::ceuclidean_space \<Rightarrow> complex) \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" is "\<lambda>a x. \<Sum>i\<in>CBasis. \<Sum>j\<in>CBasis. ((j \<bullet>\<^sub>C x) * a i j) *\<^sub>C i" by (intro bounded_linear_intros) lemma cblinfun_of_matrix_works: fixes f::"'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'b::ceuclidean_space" shows "cblinfun_of_matrix (\<lambda>i j. i \<bullet>\<^sub>C (f j)) = f" proof (transfer, rule, rule ceuclidean_eqI) fix f::"'a \<Rightarrow> 'b" and x::'a and b::'b assume "bounded_clinear f" and b: "b \<in> CBasis" then interpret bounded_clinear f by simp have "(\<Sum>j\<in>CBasis. \<Sum>i\<in>CBasis. (i \<bullet>\<^sub>C x * (j \<bullet>\<^sub>C f i)) *\<^sub>C j) \<bullet>\<^sub>C b = (\<Sum>j\<in>CBasis. if j = b then (\<Sum>i\<in>CBasis. (x \<bullet>\<^sub>C i * (f i \<bullet>\<^sub>C j))) else 0)" using b apply (simp add: cinner_sum_left cinner_CBasis if_distrib cong: if_cong) by (simp add: sum.swap) also have "\<dots> = (\<Sum>i\<in>CBasis. ((x \<bullet>\<^sub>C i) * (f i \<bullet>\<^sub>C b)))" using b by (simp) also have "\<dots> = f x \<bullet>\<^sub>C b" proof - have \<open>(\<Sum>i\<in>CBasis. (x \<bullet>\<^sub>C i) * (f i \<bullet>\<^sub>C b)) = (\<Sum>i\<in>CBasis. (i \<bullet>\<^sub>C x) *\<^sub>C f i) \<bullet>\<^sub>C b\<close> by (auto simp: cinner_sum_left) also have \<open>\<dots> = f x \<bullet>\<^sub>C b\<close> by (simp add: ceuclidean_representation sum[symmetric] scale[symmetric]) finally show ?thesis by - qed finally show "(\<Sum>j\<in>CBasis. \<Sum>i\<in>CBasis. (i \<bullet>\<^sub>C x * (j \<bullet>\<^sub>C f i)) *\<^sub>C j) \<bullet>\<^sub>C b = f x \<bullet>\<^sub>C b" . qed lemma cblinfun_of_matrix_apply: "cblinfun_of_matrix a x = (\<Sum>i\<in>CBasis. \<Sum>j\<in>CBasis. ((j \<bullet>\<^sub>C x) * a i j) *\<^sub>C i)" apply transfer by simp lemma cblinfun_of_matrix_minus: "cblinfun_of_matrix x - cblinfun_of_matrix y = cblinfun_of_matrix (x - y)" by transfer (auto simp: algebra_simps sum_subtractf) lemma norm_cblinfun_of_matrix: "norm (cblinfun_of_matrix a) \<le> (\<Sum>i\<in>CBasis. \<Sum>j\<in>CBasis. cmod (a i j))" apply (rule norm_cblinfun_bound) apply (simp add: sum_nonneg) apply (simp only: cblinfun_of_matrix_apply sum_distrib_right) apply (rule order_trans[OF norm_sum sum_mono]) apply (rule order_trans[OF norm_sum sum_mono]) apply (simp add: abs_mult mult_right_mono ac_simps Basis_le_norm) by (metis complex_inner_class.Cauchy_Schwarz_ineq2 complex_scaleC_def mult.left_neutral mult_right_mono norm_CBasis norm_ge_zero norm_scaleC) lemma tendsto_cblinfun_of_matrix: assumes "\<And>i j. i \<in> CBasis \<Longrightarrow> j \<in> CBasis \<Longrightarrow> ((\<lambda>n. b n i j) \<longlongrightarrow> a i j) F" shows "((\<lambda>n. cblinfun_of_matrix (b n)) \<longlongrightarrow> cblinfun_of_matrix a) F" proof - have "\<And>i j. i \<in> CBasis \<Longrightarrow> j \<in> CBasis \<Longrightarrow> Zfun (\<lambda>x. norm (b x i j - a i j)) F" using assms unfolding tendsto_Zfun_iff Zfun_norm_iff . hence "Zfun (\<lambda>x. (\<Sum>i\<in>CBasis. \<Sum>j\<in>CBasis. cmod (b x i j - a i j))) F" by (auto intro!: Zfun_sum) thus ?thesis unfolding tendsto_Zfun_iff cblinfun_of_matrix_minus by (rule Zfun_le) (auto intro!: order_trans[OF norm_cblinfun_of_matrix]) qed lemma ctendsto_componentwise: fixes a::"'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'b::ceuclidean_space" and b::"'c \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'b" shows "(\<And>i j. i \<in> CBasis \<Longrightarrow> j \<in> CBasis \<Longrightarrow> ((\<lambda>n. b n j \<bullet>\<^sub>C i) \<longlongrightarrow> a j \<bullet>\<^sub>C i) F) \<Longrightarrow> (b \<longlongrightarrow> a) F" apply (subst cblinfun_of_matrix_works[of a, symmetric]) apply (subst cblinfun_of_matrix_works[of "b x" for x, symmetric, abs_def]) apply (rule tendsto_cblinfun_of_matrix) apply (subst (1) cinner_commute, subst (2) cinner_commute) by (metis lim_cnj) lemma continuous_cblinfun_componentwiseI: fixes f:: "'b::t2_space \<Rightarrow> 'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'c::ceuclidean_space" assumes "\<And>i j. i \<in> CBasis \<Longrightarrow> j \<in> CBasis \<Longrightarrow> continuous F (\<lambda>x. (f x) j \<bullet>\<^sub>C i)" shows "continuous F f" using assms by (auto simp: continuous_def intro!: ctendsto_componentwise) lemma continuous_cblinfun_componentwiseI1: fixes f:: "'b::t2_space \<Rightarrow> 'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'c::complex_normed_vector" assumes "\<And>i. i \<in> CBasis \<Longrightarrow> continuous F (\<lambda>x. f x i)" shows "continuous F f" using assms by (auto simp: continuous_def intro!: ctendsto_componentwise1) lemma continuous_on_cblinfun_componentwise: fixes f:: "'d::t2_space \<Rightarrow> 'e::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'f::complex_normed_vector" assumes "\<And>i. i \<in> CBasis \<Longrightarrow> continuous_on s (\<lambda>x. f x i)" shows "continuous_on s f" using assms by (auto intro!: continuous_at_imp_continuous_on intro!: ctendsto_componentwise1 simp: continuous_on_eq_continuous_within continuous_def) lemma bounded_antilinear_cblinfun_matrix: "bounded_antilinear (\<lambda>x. (x::_\<Rightarrow>\<^sub>C\<^sub>L _) j \<bullet>\<^sub>C i)" by (auto intro!: bounded_linear_intros) lemma continuous_cblinfun_matrix: fixes f:: "'b::t2_space \<Rightarrow> 'a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L 'c::complex_inner" assumes "continuous F f" shows "continuous F (\<lambda>x. (f x) j \<bullet>\<^sub>C i)" by (rule bounded_antilinear.continuous[OF bounded_antilinear_cblinfun_matrix assms]) lemma continuous_on_cblinfun_matrix: fixes f::"'a::t2_space \<Rightarrow> 'b::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L 'c::complex_inner" assumes "continuous_on S f" shows "continuous_on S (\<lambda>x. (f x) j \<bullet>\<^sub>C i)" using assms by (auto simp: continuous_on_eq_continuous_within continuous_cblinfun_matrix) lemma continuous_on_cblinfun_of_matrix[continuous_intros]: assumes "\<And>i j. i \<in> CBasis \<Longrightarrow> j \<in> CBasis \<Longrightarrow> continuous_on S (\<lambda>s. g s i j)" shows "continuous_on S (\<lambda>s. cblinfun_of_matrix (g s))" using assms by (auto simp: continuous_on intro!: tendsto_cblinfun_of_matrix) (* Not specific to complex/real *) (* lemma mult_if_delta: "(if P then (1::'a::comm_semiring_1) else 0) * q = (if P then q else 0)" *) (* Needs that ceuclidean_space is heine_borel. This is shown for euclidean_space in Toplogy_Euclidean_Space which has not been ported to complex *) (* lemma compact_cblinfun_lemma: fixes f :: "nat \<Rightarrow> 'a::ceuclidean_space \<Rightarrow>\<^sub>C\<^sub>L 'b::ceuclidean_space" assumes "bounded (range f)" shows "\<forall>d\<subseteq>CBasis. \<exists>l::'a \<Rightarrow>\<^sub>C\<^sub>L 'b. \<exists> r::nat\<Rightarrow>nat. strict_mono r \<and> (\<forall>e>0. eventually (\<lambda>n. \<forall>i\<in>d. dist (f (r n) i) (l i) < e) sequentially)" apply (rule compact_lemma_general[where unproj = "\<lambda>e. cblinfun_of_matrix (\<lambda>i j. e j \<bullet>\<^sub>C i)"]) by (auto intro!: euclidean_eqI[where 'a='b] bounded_linear_image assms simp: blinfun_of_matrix_works blinfun_of_matrix_apply inner_Basis mult_if_delta sum.delta' scaleR_sum_left[symmetric]) *) lemma cblinfun_euclidean_eqI: "(\<And>i. i \<in> CBasis \<Longrightarrow> cblinfun_apply x i = cblinfun_apply y i) \<Longrightarrow> x = y" apply (auto intro!: cblinfun_eqI) apply (subst (2) ceuclidean_representation[symmetric, where 'a='a]) apply (subst (1) ceuclidean_representation[symmetric, where 'a='a]) by (simp add: cblinfun.cbilinear_simps) lemma CBlinfun_eq_matrix: "bounded_clinear f \<Longrightarrow> CBlinfun f = cblinfun_of_matrix (\<lambda>i j. i \<bullet>\<^sub>C f j)" apply (intro cblinfun_euclidean_eqI) by (auto simp: cblinfun_of_matrix_apply bounded_clinear_CBlinfun_apply cinner_CBasis if_distrib if_distribR sum.delta' ceuclidean_representation cong: if_cong) (* Conflicts with: cblinfun :: (complex_normed_vector, cbanach) complete_space *) (* instance cblinfun :: (ceuclidean_space, ceuclidean_space) heine_borel *) subsection\<^marker>\<open>tag unimportant\<close> \<open>concrete bounded linear functions\<close> lemma transfer_bounded_cbilinear_bounded_clinearI: assumes "g = (\<lambda>i x. (cblinfun_apply (f i) x))" shows "bounded_cbilinear g = bounded_clinear f" proof assume "bounded_cbilinear g" then interpret bounded_cbilinear f by (simp add: assms) show "bounded_clinear f" proof (unfold_locales, safe intro!: cblinfun_eqI) fix i show "f (x + y) i = (f x + f y) i" "f (r *\<^sub>C x) i = (r *\<^sub>C f x) i" for r x y by (auto intro!: cblinfun_eqI simp: cblinfun.cbilinear_simps) from _ nonneg_bounded show "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K" by (rule ex_reg) (auto intro!: onorm_bound simp: norm_cblinfun.rep_eq ac_simps) qed qed (auto simp: assms intro!: cblinfun.comp) lemma transfer_bounded_cbilinear_bounded_clinear[transfer_rule]: "(rel_fun (rel_fun (=) (pcr_cblinfun (=) (=))) (=)) bounded_cbilinear bounded_clinear" by (auto simp: pcr_cblinfun_def cr_cblinfun_def rel_fun_def OO_def intro!: transfer_bounded_cbilinear_bounded_clinearI) (* Not present in Bounded_Linear_Function *) lemma transfer_bounded_sesquilinear_bounded_antilinearI: assumes "g = (\<lambda>i x. (cblinfun_apply (f i) x))" shows "bounded_sesquilinear g = bounded_antilinear f" proof assume "bounded_sesquilinear g" then interpret bounded_sesquilinear f by (simp add: assms) show "bounded_antilinear f" proof (unfold_locales, safe intro!: cblinfun_eqI) fix i show "f (x + y) i = (f x + f y) i" "f (r *\<^sub>C x) i = (cnj r *\<^sub>C f x) i" for r x y by (auto intro!: cblinfun_eqI simp: cblinfun.scaleC_left scaleC_left add_left cblinfun.add_left) from _ real.nonneg_bounded show "\<exists>K. \<forall>x. norm (f x) \<le> norm x * K" by (rule ex_reg) (auto intro!: onorm_bound simp: norm_cblinfun.rep_eq ac_simps) qed next assume "bounded_antilinear f" then obtain K where K: \<open>norm (f x) \<le> norm x * K\<close> for x using bounded_antilinear.bounded by blast have \<open>norm (cblinfun_apply (f a) b) \<le> norm (f a) * norm b\<close> for a b by (simp add: norm_cblinfun) also have \<open>\<dots> a b \<le> norm a * norm b * K\<close> for a b by (smt (verit, best) K mult.assoc mult.commute mult_mono' norm_ge_zero) finally have *: \<open>norm (cblinfun_apply (f a) b) \<le> norm a * norm b * K\<close> for a b by simp show "bounded_sesquilinear g" using \<open>bounded_antilinear f\<close> apply (auto intro!: bounded_sesquilinear.intro simp: assms cblinfun.add_left cblinfun.add_right linear_simps bounded_antilinear.bounded_linear antilinear.scaleC bounded_antilinear.antilinear cblinfun.scaleC_left cblinfun.scaleC_right) using * by blast qed lemma transfer_bounded_sesquilinear_bounded_antilinear[transfer_rule]: "(rel_fun (rel_fun (=) (pcr_cblinfun (=) (=))) (=)) bounded_sesquilinear bounded_antilinear" by (auto simp: pcr_cblinfun_def cr_cblinfun_def rel_fun_def OO_def intro!: transfer_bounded_sesquilinear_bounded_antilinearI) context bounded_cbilinear begin lift_definition prod_left::"'b \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'c" is "(\<lambda>b a. prod a b)" by (rule bounded_clinear_left) declare prod_left.rep_eq[simp] lemma bounded_clinear_prod_left[bounded_clinear]: "bounded_clinear prod_left" by transfer (rule flip) lift_definition prod_right::"'a \<Rightarrow> 'b \<Rightarrow>\<^sub>C\<^sub>L 'c" is "(\<lambda>a b. prod a b)" by (rule bounded_clinear_right) declare prod_right.rep_eq[simp] lemma bounded_clinear_prod_right[bounded_clinear]: "bounded_clinear prod_right" by transfer (rule bounded_cbilinear_axioms) end lift_definition id_cblinfun::"'a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L 'a" is "\<lambda>x. x" by (rule bounded_clinear_ident) lemmas cblinfun_id_cblinfun_apply[simp] = id_cblinfun.rep_eq (* Stronger than norm_blinfun_id because we replaced the perfect_space typeclass by not_singleton *) lemma norm_cblinfun_id[simp]: "norm (id_cblinfun::'a::{complex_normed_vector, not_singleton} \<Rightarrow>\<^sub>C\<^sub>L 'a) = 1" apply transfer apply (rule onorm_id[internalize_sort' 'a]) apply standard[1] by simp lemma norm_cblinfun_id_le: "norm (id_cblinfun::'a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L 'a) \<le> 1" by transfer (auto simp: onorm_id_le) (* Skipped because we do not have "prod :: (cbanach, cbanach) cbanach" (Product_Vector not ported to complex)*) (* lift_definition fst_cblinfun::"('a::complex_normed_vector \<times> 'b::complex_normed_vector) \<Rightarrow>\<^sub>C\<^sub>L 'a" is fst *) (* lemma cblinfun_apply_fst_cblinfun[simp]: "cblinfun_apply fst_cblinfun = fst" *) (* lift_definition snd_cblinfun::"('a::complex_normed_vector \<times> 'b::complex_normed_vector) \<Rightarrow>\<^sub>C\<^sub>L 'b" is snd *) (* lemma blinfun_apply_snd_blinfun[simp]: "blinfun_apply snd_blinfun = snd" *) lift_definition cblinfun_compose:: "'a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L 'b::complex_normed_vector \<Rightarrow> 'c::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L 'a \<Rightarrow> 'c \<Rightarrow>\<^sub>C\<^sub>L 'b" (infixl "o\<^sub>C\<^sub>L" 67) is "(o)" (* Difference from Real_Vector_Spaces: Priority of o\<^sub>C\<^sub>L is 55 there. But we want "a - b o\<^sub>C\<^sub>L c" to parse as "a - (b o\<^sub>C\<^sub>L c)". *) parametric comp_transfer unfolding o_def by (rule bounded_clinear_compose) lemma cblinfun_apply_cblinfun_compose[simp]: "(a o\<^sub>C\<^sub>L b) c = a (b c)" by (simp add: cblinfun_compose.rep_eq) lemma norm_cblinfun_compose: "norm (f o\<^sub>C\<^sub>L g) \<le> norm f * norm g" apply transfer by (auto intro!: onorm_compose simp: bounded_clinear.bounded_linear) lemma bounded_cbilinear_cblinfun_compose[bounded_cbilinear]: "bounded_cbilinear (o\<^sub>C\<^sub>L)" by unfold_locales (auto intro!: cblinfun_eqI exI[where x=1] simp: cblinfun.cbilinear_simps norm_cblinfun_compose) lemma cblinfun_compose_zero[simp]: "blinfun_compose 0 = (\<lambda>_. 0)" "blinfun_compose x 0 = 0" by (auto simp: blinfun.bilinear_simps intro!: blinfun_eqI) lemma cblinfun_bij2: fixes f::"'a \<Rightarrow>\<^sub>C\<^sub>L 'a::ceuclidean_space" assumes "f o\<^sub>C\<^sub>L g = id_cblinfun" shows "bij (cblinfun_apply g)" proof (rule bijI) show "inj g" using assms by (metis cblinfun_id_cblinfun_apply cblinfun_compose.rep_eq injI inj_on_imageI2) then show "surj g" using bounded_clinear_def cblinfun.bounded_clinear_right ceucl.linear_inj_imp_surj by blast qed lemma cblinfun_bij1: fixes f::"'a \<Rightarrow>\<^sub>C\<^sub>L 'a::ceuclidean_space" assumes "f o\<^sub>C\<^sub>L g = id_cblinfun" shows "bij (cblinfun_apply f)" proof (rule bijI) show "surj (cblinfun_apply f)" by (metis assms cblinfun_apply_cblinfun_compose cblinfun_id_cblinfun_apply surjI) then show "inj (cblinfun_apply f)" using bounded_clinear_def cblinfun.bounded_clinear_right ceucl.linear_surjective_imp_injective by blast qed lift_definition cblinfun_cinner_right::"'a::complex_inner \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L complex" is "(\<bullet>\<^sub>C)" by (rule bounded_clinear_cinner_right) declare cblinfun_cinner_right.rep_eq[simp] lemma bounded_antilinear_cblinfun_cinner_right[bounded_antilinear]: "bounded_antilinear cblinfun_cinner_right" apply transfer by (simp add: bounded_sesquilinear_cinner) (* Cannot be defined. cinner is antilinear in first argument. *) (* lift_definition cblinfun_cinner_left::"'a::complex_inner \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L complex" is "\<lambda>x y. y \<bullet>\<^sub>C x" *) (* declare cblinfun_cinner_left.rep_eq[simp] *) (* lemma bounded_clinear_cblinfun_cinner_left[bounded_clinear]: "bounded_clinear cblinfun_cinner_left" *) lift_definition cblinfun_scaleC_right::"complex \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'a::complex_normed_vector" is "(*\<^sub>C)" by (rule bounded_clinear_scaleC_right) declare cblinfun_scaleC_right.rep_eq[simp] lemma bounded_clinear_cblinfun_scaleC_right[bounded_clinear]: "bounded_clinear cblinfun_scaleC_right" by transfer (rule bounded_cbilinear_scaleC) lift_definition cblinfun_scaleC_left::"'a::complex_normed_vector \<Rightarrow> complex \<Rightarrow>\<^sub>C\<^sub>L 'a" is "\<lambda>x y. y *\<^sub>C x" by (rule bounded_clinear_scaleC_left) lemmas [simp] = cblinfun_scaleC_left.rep_eq lemma bounded_clinear_cblinfun_scaleC_left[bounded_clinear]: "bounded_clinear cblinfun_scaleC_left" by transfer (rule bounded_cbilinear.flip[OF bounded_cbilinear_scaleC]) lift_definition cblinfun_mult_right::"'a \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'a::complex_normed_algebra" is "(*)" by (rule bounded_clinear_mult_right) declare cblinfun_mult_right.rep_eq[simp] lemma bounded_clinear_cblinfun_mult_right[bounded_clinear]: "bounded_clinear cblinfun_mult_right" by transfer (rule bounded_cbilinear_mult) lift_definition cblinfun_mult_left::"'a::complex_normed_algebra \<Rightarrow> 'a \<Rightarrow>\<^sub>C\<^sub>L 'a" is "\<lambda>x y. y * x" by (rule bounded_clinear_mult_left) lemmas [simp] = cblinfun_mult_left.rep_eq lemma bounded_clinear_cblinfun_mult_left[bounded_clinear]: "bounded_clinear cblinfun_mult_left" by transfer (rule bounded_cbilinear.flip[OF bounded_cbilinear_mult]) lemmas bounded_clinear_function_uniform_limit_intros[uniform_limit_intros] = bounded_clinear.uniform_limit[OF bounded_clinear_apply_cblinfun] bounded_clinear.uniform_limit[OF bounded_clinear_cblinfun_apply] bounded_antilinear.uniform_limit[OF bounded_antilinear_cblinfun_matrix] subsection \<open>The strong operator topology on continuous linear operators\<close> text \<open>Let \<open>'a\<close> and \<open>'b\<close> be two normed real vector spaces. Then the space of linear continuous operators from \<open>'a\<close> to \<open>'b\<close> has a canonical norm, and therefore a canonical corresponding topology (the type classes instantiation are given in \<^file>\<open>Complex_Bounded_Linear_Function0.thy\<close>). However, there is another topology on this space, the strong operator topology, where \<open>T\<^sub>n\<close> tends to \<open>T\<close> iff, for all \<open>x\<close> in \<open>'a\<close>, then \<open>T\<^sub>n x\<close> tends to \<open>T x\<close>. This is precisely the product topology where the target space is endowed with the norm topology. It is especially useful when \<open>'b\<close> is the set of real numbers, since then this topology is compact. We can not implement it using type classes as there is already a topology, but at least we can define it as a topology. Note that there is yet another (common and useful) topology on operator spaces, the weak operator topology, defined analogously using the product topology, but where the target space is given the weak-* topology, i.e., the pullback of the weak topology on the bidual of the space under the canonical embedding of a space into its bidual. We do not define it there, although it could also be defined analogously. \<close> definition\<^marker>\<open>tag important\<close> cstrong_operator_topology::"('a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L'b::complex_normed_vector) topology" where "cstrong_operator_topology = pullback_topology UNIV cblinfun_apply euclidean" lemma cstrong_operator_topology_topspace: "topspace cstrong_operator_topology = UNIV" unfolding cstrong_operator_topology_def topspace_pullback_topology topspace_euclidean by auto lemma cstrong_operator_topology_basis: fixes f::"('a::complex_normed_vector \<Rightarrow>\<^sub>C\<^sub>L'b::complex_normed_vector)" and U::"'i \<Rightarrow> 'b set" and x::"'i \<Rightarrow> 'a" assumes "finite I" "\<And>i. i \<in> I \<Longrightarrow> open (U i)" shows "openin cstrong_operator_topology {f. \<forall>i\<in>I. cblinfun_apply f (x i) \<in> U i}" proof - have "open {g::('a\<Rightarrow>'b). \<forall>i\<in>I. g (x i) \<in> U i}" by (rule product_topology_basis'[OF assms]) moreover have "{f. \<forall>i\<in>I. cblinfun_apply f (x i) \<in> U i} = cblinfun_apply-`{g::('a\<Rightarrow>'b). \<forall>i\<in>I. g (x i) \<in> U i} \<inter> UNIV" by auto ultimately show ?thesis unfolding cstrong_operator_topology_def by (subst openin_pullback_topology) auto qed lemma cstrong_operator_topology_continuous_evaluation: "continuous_map cstrong_operator_topology euclidean (\<lambda>f. cblinfun_apply f x)" proof - have "continuous_map cstrong_operator_topology euclidean ((\<lambda>f. f x) o cblinfun_apply)" unfolding cstrong_operator_topology_def apply (rule continuous_map_pullback) using continuous_on_product_coordinates by fastforce then show ?thesis unfolding comp_def by simp qed lemma continuous_on_cstrong_operator_topo_iff_coordinatewise: "continuous_map T cstrong_operator_topology f \<longleftrightarrow> (\<forall>x. continuous_map T euclidean (\<lambda>y. cblinfun_apply (f y) x))" proof (auto) fix x::"'b" assume "continuous_map T cstrong_operator_topology f" with continuous_map_compose[OF this cstrong_operator_topology_continuous_evaluation] have "continuous_map T euclidean ((\<lambda>z. cblinfun_apply z x) o f)" by simp then show "continuous_map T euclidean (\<lambda>y. cblinfun_apply (f y) x)" unfolding comp_def by auto next assume *: "\<forall>x. continuous_map T euclidean (\<lambda>y. cblinfun_apply (f y) x)" have "\<And>i. continuous_map T euclidean (\<lambda>x. cblinfun_apply (f x) i)" using * unfolding comp_def by auto then have "continuous_map T euclidean (cblinfun_apply o f)" unfolding o_def by (metis (no_types) continuous_map_componentwise_UNIV euclidean_product_topology) show "continuous_map T cstrong_operator_topology f" unfolding cstrong_operator_topology_def apply (rule continuous_map_pullback') by (auto simp add: \<open>continuous_map T euclidean (cblinfun_apply o f)\<close>) qed lemma cstrong_operator_topology_weaker_than_euclidean: "continuous_map euclidean cstrong_operator_topology (\<lambda>f. f)" apply (subst continuous_on_cstrong_operator_topo_iff_coordinatewise) by (auto simp add: linear_continuous_on continuous_at_imp_continuous_on linear_continuous_at bounded_clinear.bounded_linear) end
[STATEMENT] theorem wf_plan_soundness_theorem: assumes "plan_action_path I \<pi>s M" defines "\<alpha>s \<equiv> map (pddl_opr_to_act \<circ> resolve_instantiate) \<pi>s" defines "s\<^sub>0 \<equiv> wm_to_state I" shows "\<exists>s'. compose_actions \<alpha>s s\<^sub>0 = Some s' \<and> (\<forall>\<phi>\<in>close_world M. s' \<Turnstile>\<^sub>= \<phi>)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<exists>s'. compose_actions \<alpha>s s\<^sub>0 = Some s' \<and> (\<forall>\<phi>\<in>close_world M. close_eq s' \<Turnstile> \<phi>) [PROOF STEP] apply (rule STRIPS_sema_sound) [PROOF STATE] proof (prove) goal (4 subgoals): 1. sound_system ?\<Sigma> ?M\<^sub>0 ?s\<^sub>0 ?f 2. set ?\<alpha>s \<subseteq> ?\<Sigma> 3. ground_action_path ?M\<^sub>0 ?\<alpha>s ?M' 4. \<And>s'. \<lbrakk>compose_actions (map ?f ?\<alpha>s) ?s\<^sub>0 = Some s'; \<forall>fmla\<in>close_world ?M'. close_eq s' \<Turnstile> fmla\<rbrakk> \<Longrightarrow> \<exists>s'. compose_actions \<alpha>s s\<^sub>0 = Some s' \<and> (\<forall>\<phi>\<in>close_world M. close_eq s' \<Turnstile> \<phi>) [PROOF STEP] apply (rule wf_plan_sound_system) [PROOF STATE] proof (prove) goal (4 subgoals): 1. Ball (set ?\<pi>s5) wf_plan_action 2. set ?\<alpha>s \<subseteq> set (map resolve_instantiate ?\<pi>s5) 3. ground_action_path I ?\<alpha>s ?M' 4. \<And>s'. \<lbrakk>compose_actions (map pddl_opr_to_act ?\<alpha>s) (wm_to_state I) = Some s'; \<forall>fmla\<in>close_world ?M'. close_eq s' \<Turnstile> fmla\<rbrakk> \<Longrightarrow> \<exists>s'. compose_actions \<alpha>s s\<^sub>0 = Some s' \<and> (\<forall>\<phi>\<in>close_world M. close_eq s' \<Turnstile> \<phi>) [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: plan_action_path I \<pi>s M \<alpha>s \<equiv> map ((pddl_opr_to_act \<circ>\<circ> ast_problem.resolve_instantiate) P) \<pi>s s\<^sub>0 \<equiv> wm_to_state I goal (4 subgoals): 1. Ball (set ?\<pi>s5) wf_plan_action 2. set ?\<alpha>s \<subseteq> set (map resolve_instantiate ?\<pi>s5) 3. ground_action_path I ?\<alpha>s ?M' 4. \<And>s'. \<lbrakk>compose_actions (map pddl_opr_to_act ?\<alpha>s) (wm_to_state I) = Some s'; \<forall>fmla\<in>close_world ?M'. close_eq s' \<Turnstile> fmla\<rbrakk> \<Longrightarrow> \<exists>s'. compose_actions \<alpha>s s\<^sub>0 = Some s' \<and> (\<forall>\<phi>\<in>close_world M. close_eq s' \<Turnstile> \<phi>) [PROOF STEP] unfolding plan_action_path_def [PROOF STATE] proof (prove) using this: Ball (set \<pi>s) wf_plan_action \<and> ground_action_path I (map resolve_instantiate \<pi>s) M \<alpha>s \<equiv> map ((pddl_opr_to_act \<circ>\<circ> ast_problem.resolve_instantiate) P) \<pi>s s\<^sub>0 \<equiv> wm_to_state I goal (4 subgoals): 1. Ball (set ?\<pi>s5) wf_plan_action 2. set ?\<alpha>s \<subseteq> set (map resolve_instantiate ?\<pi>s5) 3. ground_action_path I ?\<alpha>s ?M' 4. \<And>s'. \<lbrakk>compose_actions (map pddl_opr_to_act ?\<alpha>s) (wm_to_state I) = Some s'; \<forall>fmla\<in>close_world ?M'. close_eq s' \<Turnstile> fmla\<rbrakk> \<Longrightarrow> \<exists>s'. compose_actions \<alpha>s s\<^sub>0 = Some s' \<and> (\<forall>\<phi>\<in>close_world M. close_eq s' \<Turnstile> \<phi>) [PROOF STEP] by (auto simp add: image_def)
[GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β x y : α S U Z : Set α ⊢ IsGenericPoint x S ↔ ∀ (y : α), x ⤳ y ↔ y ∈ S [PROOFSTEP] simp only [specializes_iff_mem_closure, IsGenericPoint, Set.ext_iff] [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β x y : α S U Z : Set α h : IsGenericPoint x S hU : IsOpen U ⊢ Disjoint S U ↔ ¬x ∈ U [PROOFSTEP] rw [h.mem_open_set_iff hU, ← not_disjoint_iff_nonempty_inter, Classical.not_not] [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β x y : α S U Z : Set α h : IsGenericPoint x S hZ : IsClosed Z ⊢ x ∈ Z ↔ S ⊆ Z [PROOFSTEP] rw [← h.def, hZ.closure_subset_iff, singleton_subset_iff] [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β x y : α S U Z : Set α h : IsGenericPoint x S f : α → β hf : Continuous f ⊢ IsGenericPoint (f x) (closure (f '' S)) [PROOFSTEP] rw [isGenericPoint_def, ← h.def, ← image_singleton, closure_image_closure hf] [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β x y : α S U Z : Set α hS : IsClosed S hxS : x ∈ S ⊢ IsGenericPoint x S ↔ ∀ (Z : Set α), IsClosed Z → x ∈ Z → S ⊆ Z [PROOFSTEP] have : closure { x } ⊆ S := closure_minimal (singleton_subset_iff.2 hxS) hS [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β x y : α S U Z : Set α hS : IsClosed S hxS : x ∈ S this : closure {x} ⊆ S ⊢ IsGenericPoint x S ↔ ∀ (Z : Set α), IsClosed Z → x ∈ Z → S ⊆ Z [PROOFSTEP] simp_rw [IsGenericPoint, subset_antisymm_iff, this, true_and_iff, closure, subset_sInter_iff, mem_setOf_eq, and_imp, singleton_subset_iff] [GOAL] α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : IrreducibleSpace α ⊢ IsGenericPoint (genericPoint α) ⊤ [PROOFSTEP] simpa using (IrreducibleSpace.isIrreducible_univ α).genericPoint_spec [GOAL] α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : IrreducibleSpace α x : α ⊢ x ∈ closure univ [PROOFSTEP] simp [GOAL] α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : T0Space α x : α ⊢ IsGenericPoint x (closure (closure {x})) [PROOFSTEP] rw [closure_closure] [GOAL] α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : T0Space α x : α ⊢ IsGenericPoint x (closure {x}) [PROOFSTEP] exact isGenericPoint_closure [GOAL] α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : T0Space α ⊢ ∀ {a b : ↑{s | IsIrreducible s ∧ IsClosed s}}, ↑{ toFun := fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s), invFun := fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }, left_inv := (_ : ∀ (s : ↑{s | IsIrreducible s ∧ IsClosed s}), (fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }) ((fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s)) s) = s), right_inv := (_ : ∀ (x : α), IsIrreducible.genericPoint (_ : IsIrreducible (closure {x})) = x) } a ≤ ↑{ toFun := fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s), invFun := fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }, left_inv := (_ : ∀ (s : ↑{s | IsIrreducible s ∧ IsClosed s}), (fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }) ((fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s)) s) = s), right_inv := (_ : ∀ (x : α), IsIrreducible.genericPoint (_ : IsIrreducible (closure {x})) = x) } b ↔ a ≤ b [PROOFSTEP] rintro ⟨s, hs⟩ ⟨t, ht⟩ [GOAL] case mk.mk α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : T0Space α s : Set α hs : s ∈ {s | IsIrreducible s ∧ IsClosed s} t : Set α ht : t ∈ {s | IsIrreducible s ∧ IsClosed s} ⊢ ↑{ toFun := fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s), invFun := fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }, left_inv := (_ : ∀ (s : ↑{s | IsIrreducible s ∧ IsClosed s}), (fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }) ((fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s)) s) = s), right_inv := (_ : ∀ (x : α), IsIrreducible.genericPoint (_ : IsIrreducible (closure {x})) = x) } { val := s, property := hs } ≤ ↑{ toFun := fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s), invFun := fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }, left_inv := (_ : ∀ (s : ↑{s | IsIrreducible s ∧ IsClosed s}), (fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }) ((fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s)) s) = s), right_inv := (_ : ∀ (x : α), IsIrreducible.genericPoint (_ : IsIrreducible (closure {x})) = x) } { val := t, property := ht } ↔ { val := s, property := hs } ≤ { val := t, property := ht } [PROOFSTEP] refine specializes_iff_closure_subset.trans ?_ [GOAL] case mk.mk α : Type u_1 β : Type u_2 inst✝³ : TopologicalSpace α inst✝² : TopologicalSpace β inst✝¹ : QuasiSober α inst✝ : T0Space α s : Set α hs : s ∈ {s | IsIrreducible s ∧ IsClosed s} t : Set α ht : t ∈ {s | IsIrreducible s ∧ IsClosed s} ⊢ closure {↑{ toFun := fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s), invFun := fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }, left_inv := (_ : ∀ (s : ↑{s | IsIrreducible s ∧ IsClosed s}), (fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }) ((fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s)) s) = s), right_inv := (_ : ∀ (x : α), IsIrreducible.genericPoint (_ : IsIrreducible (closure {x})) = x) } { val := s, property := hs }} ⊆ closure {↑{ toFun := fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s), invFun := fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }, left_inv := (_ : ∀ (s : ↑{s | IsIrreducible s ∧ IsClosed s}), (fun x => { val := closure {x}, property := (_ : IsIrreducible (closure {x}) ∧ IsClosed (closure {x})) }) ((fun s => IsIrreducible.genericPoint (_ : IsIrreducible ↑s)) s) = s), right_inv := (_ : ∀ (x : α), IsIrreducible.genericPoint (_ : IsIrreducible (closure {x})) = x) } { val := t, property := ht }} ↔ { val := s, property := hs } ≤ { val := t, property := ht } [PROOFSTEP] simp [hs.2.closure_eq, ht.2.closure_eq] [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : ClosedEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] have hS'' := hS.image f hf.continuous.continuousOn [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : ClosedEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] obtain ⟨x, hx⟩ := QuasiSober.sober hS'' (hf.isClosedMap _ hS') [GOAL] case intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : ClosedEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) x : β hx : IsGenericPoint x (f '' S✝) ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] obtain ⟨y, -, rfl⟩ := hx.mem [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : ClosedEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) y : α hx : IsGenericPoint (f y) (f '' S✝) ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] use y [GOAL] case h α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : ClosedEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) y : α hx : IsGenericPoint (f y) (f '' S✝) ⊢ IsGenericPoint y S✝ [PROOFSTEP] apply image_injective.mpr hf.inj [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : ClosedEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) y : α hx : IsGenericPoint (f y) (f '' S✝) ⊢ f '' closure {y} = f '' S✝ [PROOFSTEP] rw [← hx.def, ← hf.closure_image_eq, image_singleton] [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] have hS'' := hS.image f hf.continuous.continuousOn [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] obtain ⟨x, hx⟩ := QuasiSober.sober hS''.closure isClosed_closure [GOAL] case intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β S✝ : Set α hS : IsIrreducible S✝ hS' : IsClosed S✝ hS'' : IsIrreducible (f '' S✝) x : β hx : IsGenericPoint x (closure (f '' S✝)) ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] obtain ⟨T, hT, rfl⟩ := hf.toInducing.isClosed_iff.mp hS' [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (f '' (f ⁻¹' T)) hx : IsGenericPoint x (closure (f '' (f ⁻¹' T))) ⊢ ∃ x, IsGenericPoint x (f ⁻¹' T) [PROOFSTEP] rw [image_preimage_eq_inter_range] at hx hS'' [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) ⊢ ∃ x, IsGenericPoint x (f ⁻¹' T) [PROOFSTEP] have hxT : x ∈ T := by rw [← hT.closure_eq] exact closure_mono (inter_subset_left _ _) hx.mem [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) ⊢ x ∈ T [PROOFSTEP] rw [← hT.closure_eq] [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) ⊢ x ∈ closure T [PROOFSTEP] exact closure_mono (inter_subset_left _ _) hx.mem [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) hxT : x ∈ T ⊢ ∃ x, IsGenericPoint x (f ⁻¹' T) [PROOFSTEP] obtain ⟨y, rfl⟩ : x ∈ range f := by rw [hx.mem_open_set_iff hf.open_range] refine' Nonempty.mono _ hS''.1 simpa using subset_closure [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) hxT : x ∈ T ⊢ x ∈ range f [PROOFSTEP] rw [hx.mem_open_set_iff hf.open_range] [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) hxT : x ∈ T ⊢ Set.Nonempty (closure (T ∩ range f) ∩ range f) [PROOFSTEP] refine' Nonempty.mono _ hS''.1 [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β x : β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) hx : IsGenericPoint x (closure (T ∩ range f)) hxT : x ∈ T ⊢ T ∩ range f ⊆ closure (T ∩ range f) ∩ range f [PROOFSTEP] simpa using subset_closure [GOAL] case intro.intro.intro.intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T ⊢ ∃ x, IsGenericPoint x (f ⁻¹' T) [PROOFSTEP] use y [GOAL] case h α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T ⊢ IsGenericPoint y (f ⁻¹' T) [PROOFSTEP] change _ = _ [GOAL] case h α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T ⊢ closure {y} = f ⁻¹' T [PROOFSTEP] rw [hf.toEmbedding.closure_eq_preimage_closure_image, image_singleton, show _ = _ from hx] [GOAL] case h α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T ⊢ f ⁻¹' closure (T ∩ range f) = f ⁻¹' T [PROOFSTEP] apply image_injective.mpr hf.inj [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T ⊢ f '' (f ⁻¹' closure (T ∩ range f)) = f '' (f ⁻¹' T) [PROOFSTEP] ext z [GOAL] case h.a.h α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T z : β ⊢ z ∈ f '' (f ⁻¹' closure (T ∩ range f)) ↔ z ∈ f '' (f ⁻¹' T) [PROOFSTEP] simp only [image_preimage_eq_inter_range, mem_inter_iff, and_congr_left_iff] [GOAL] case h.a.h α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β f : α → β hf : OpenEmbedding f inst✝ : QuasiSober β T : Set β hT : IsClosed T hS : IsIrreducible (f ⁻¹' T) hS' : IsClosed (f ⁻¹' T) hS'' : IsIrreducible (T ∩ range f) y : α hx : IsGenericPoint (f y) (closure (T ∩ range f)) hxT : f y ∈ T z : β ⊢ z ∈ range f → (z ∈ closure (T ∩ range f) ↔ z ∈ T) [PROOFSTEP] exact fun hy => ⟨fun h => hT.closure_eq ▸ closure_mono (inter_subset_left _ _) h, fun h => subset_closure ⟨h, hy⟩⟩ [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ ⊢ QuasiSober α [PROOFSTEP] rw [quasiSober_iff] [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ ⊢ ∀ {S : Set α}, IsIrreducible S → IsClosed S → ∃ x, IsGenericPoint x S [PROOFSTEP] intro t h h' [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t ⊢ ∃ x, IsGenericPoint x t [PROOFSTEP] obtain ⟨x, hx⟩ := h.1 [GOAL] case intro α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t ⊢ ∃ x, IsGenericPoint x t [PROOFSTEP] obtain ⟨U, hU, hU'⟩ : x ∈ ⋃₀ S := by rw [hS''] trivial [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t ⊢ x ∈ ⋃₀ S [PROOFSTEP] rw [hS''] [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t ⊢ x ∈ ⊤ [PROOFSTEP] trivial [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U ⊢ ∃ x, IsGenericPoint x t [PROOFSTEP] haveI : QuasiSober U := hS' ⟨U, hU⟩ [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this : QuasiSober ↑U ⊢ ∃ x, IsGenericPoint x t [PROOFSTEP] have H : IsPreirreducible ((↑) ⁻¹' t : Set U) := h.2.preimage (hS ⟨U, hU⟩).openEmbedding_subtype_val [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this : QuasiSober ↑U H : IsPreirreducible (Subtype.val ⁻¹' t) ⊢ ∃ x, IsGenericPoint x t [PROOFSTEP] replace H : IsIrreducible ((↑) ⁻¹' t : Set U) := ⟨⟨⟨x, hU'⟩, by simpa using hx⟩, H⟩ [GOAL] α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this : QuasiSober ↑U H : IsPreirreducible (Subtype.val ⁻¹' t) ⊢ { val := x, property := hU' } ∈ Subtype.val ⁻¹' t [PROOFSTEP] simpa using hx [GOAL] case intro.intro.intro α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) ⊢ ∃ x, IsGenericPoint x t [PROOFSTEP] use H.genericPoint [GOAL] case h α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) ⊢ IsGenericPoint (↑(IsIrreducible.genericPoint H)) t [PROOFSTEP] have := continuous_subtype_val.closure_preimage_subset _ H.genericPoint_spec.mem [GOAL] case h α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' closure t ⊢ IsGenericPoint (↑(IsIrreducible.genericPoint H)) t [PROOFSTEP] rw [h'.closure_eq] at this [GOAL] case h α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ IsGenericPoint (↑(IsIrreducible.genericPoint H)) t [PROOFSTEP] apply le_antisymm [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ closure {↑(IsIrreducible.genericPoint H)} ≤ t [PROOFSTEP] apply h'.closure_subset_iff.mpr [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ {↑(IsIrreducible.genericPoint H)} ⊆ t [PROOFSTEP] simpa using this [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ t ≤ closure {↑(IsIrreducible.genericPoint H)} [PROOFSTEP] rw [← image_singleton, ← closure_image_closure continuous_subtype_val, H.genericPoint_spec.def] [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ t ≤ closure (Subtype.val '' closure (Subtype.val ⁻¹' t)) [PROOFSTEP] refine' (subset_closure_inter_of_isPreirreducible_of_isOpen h.2 (hS ⟨U, hU⟩) ⟨x, hx, hU'⟩).trans (closure_mono _) [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ t ∩ ↑{ val := U, property := hU } ⊆ Subtype.val '' closure (Subtype.val ⁻¹' t) [PROOFSTEP] rw [← Subtype.image_preimage_coe] [GOAL] case h.a α : Type u_1 β : Type u_2 inst✝¹ : TopologicalSpace α inst✝ : TopologicalSpace β S : Set (Set α) hS : ∀ (s : ↑S), IsOpen ↑s hS' : ∀ (s : ↑S), QuasiSober ↑↑s hS'' : ⋃₀ S = ⊤ t : Set α h : IsIrreducible t h' : IsClosed t x : α hx : x ∈ t U : Set α hU : U ∈ S hU' : x ∈ U this✝ : QuasiSober ↑U H : IsIrreducible (Subtype.val ⁻¹' t) this : IsIrreducible.genericPoint H ∈ Subtype.val ⁻¹' t ⊢ Subtype.val '' (Subtype.val ⁻¹' t) ⊆ Subtype.val '' closure (Subtype.val ⁻¹' t) [PROOFSTEP] exact Set.image_subset _ subset_closure [GOAL] α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : T2Space α S✝ : Set α h : IsIrreducible S✝ x✝ : IsClosed S✝ ⊢ ∃ x, IsGenericPoint x S✝ [PROOFSTEP] obtain ⟨x, rfl⟩ := isIrreducible_iff_singleton.mp h [GOAL] case intro α : Type u_1 β : Type u_2 inst✝² : TopologicalSpace α inst✝¹ : TopologicalSpace β inst✝ : T2Space α x : α h : IsIrreducible {x} x✝ : IsClosed {x} ⊢ ∃ x_1, IsGenericPoint x_1 {x} [PROOFSTEP] exact ⟨x, closure_singleton⟩
#include <boost/fusion/algorithm/transformation/erase.hpp>
# Tests for UCB Algorithms @testset "UCB" begin bandit1 = [ Arms.Bernoulli( 0.45 ), Arms.Bernoulli( 0.60 ), Arms.Bernoulli( 0.65 ) ]; @testset "UCB1" begin e1 = Experiments.Compare( bandit1, [ Algorithms.UCB1(length(bandit1)) ] ) @test @test_nothrow r1 = Experiments.run( e1, 100, 100 ) end @testset "D-UCB" begin e2 = Experiments.Compare( bandit1, [Algorithms.DUCB(length(bandit1),0.9) ] ) @test @test_nothrow r2 = Experiments.run( e2, 100, 100 ) end @testset "SW-UCB" begin e3 = Experiments.Compare( bandit1, [Algorithms.SWUCB(length(bandit1),10) ] ) @test @test_nothrow r2 = Experiments.run( e3, 100, 100 ) end end nothing
Remember when the left went crazy over candidate Trump’s body movements while talking about a disabled liberal reporter who was unjustly trashing him? Even though multiple videos proved then-presidential candidate Trump frequently used similar or the same body movements on many occasions while mocking people who were not disabled, the media and the Democrat Party milked the lie for months. The media completely ignored Democrat strategist Adam Parkhomenko’s sick tweet today, where he asked his 253K+ followers to make sure a video of Senate Majority Leader Mitch McConnell (R-KY), falling onto the stage (after tripping on his partially paralyzed leg from a bout with polio at the age of 12), went viral. According to Wikipedia, Adam Parkhomenko is a Democratic political strategist and organizer who served as National Field Director for the Democratic National Committee in 2016. He was the co-founder and executive director of Ready for Hillary, a super PAC established to persuade Hillary Clinton to run for the presidency of the United States in 2016. In the 2017 party election, Parkhomenko was a candidate for Vice Chair of the Democratic National Committee. Earlier today, Adam Parkhomenko tweeted this video, saying that Mitch McConnell does not want to let this video get up to 1 million views. Did the GOP Senate Majority Leader tell Parkhomenko that, or is this just another case of a demented Democrat making fun of someone with a disability and hoping fellow Democrats will help him to humiliate McConnell over his disability even more? The former DNC field director was immediately slammed for mocking a disabled person simply because he doesn’t agree with his politics. So you enjoy picking on handicapped/disabled people? The Senator suffered from Polio as a child, resulting in a paralyzed left leg. You exemplify the Democrat Party. Contemptible, vindictive losers. EducatëdHillbilly™‏ tweeted a part of Senator Mitch McConnell’s bio, explaining how his upper left leg was paralyzed after he was afflicted with polio at the age of 12. Mindy Robertson reminded the Democrat hack about McConnell’s disability: McConnell had polio as a kid and his leg is partially paralyzed because of it, you POS. But great way to demonstrate that “moral superiority” you Dems keep thinking you have over us….. What do you think? Should the media be calling our Parkhomenko for his disgusting behavior? Tell us what you think in the comment section below?
(* Title: Native_Cast_Uint.thy Author: Andreas Lochbihler, Digital Asset *) theory Native_Cast_Uint imports Native_Cast Uint begin lift_definition uint_of_uint8 :: "uint8 \<Rightarrow> uint" is ucast . lift_definition uint_of_uint16 :: "uint16 \<Rightarrow> uint" is ucast . lift_definition uint_of_uint32 :: "uint32 \<Rightarrow> uint" is ucast . lift_definition uint_of_uint64 :: "uint64 \<Rightarrow> uint" is ucast . lift_definition uint8_of_uint :: "uint \<Rightarrow> uint8" is ucast . lift_definition uint16_of_uint :: "uint \<Rightarrow> uint16" is ucast . lift_definition uint32_of_uint :: "uint \<Rightarrow> uint32" is ucast . lift_definition uint64_of_uint :: "uint \<Rightarrow> uint64" is ucast . code_printing constant uint_of_uint8 \<rightharpoonup> (SML) "Word.fromLarge (Word8.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint.Word)" and (Scala) "((_).toInt & 0xFF)" | constant uint_of_uint16 \<rightharpoonup> (SML_word) "Word.fromLarge (Word16.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint.Word)" and (Scala) "(_).toInt" | constant uint_of_uint32 \<rightharpoonup> (SML) "Word.fromLarge (Word32.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint.Word)" and (Scala) "_" and (OCaml) "(Int32.to'_int _) land Uint.int'_mask" | constant uint_of_uint64 \<rightharpoonup> (SML) "Word.fromLarge (Uint64.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint.Word)" and (Scala) "(_).toInt" and (OCaml) "Int64.to'_int" | constant uint8_of_uint \<rightharpoonup> (SML) "Word8.fromLarge (Word.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint8.Word8)" and (Scala) "(_).toByte" | constant uint16_of_uint \<rightharpoonup> (SML_word) "Word16.fromLarge (Word.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint16.Word16)" and (Scala) "(_).toChar" | constant uint32_of_uint \<rightharpoonup> (SML) "Word32.fromLarge (Word.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint32.Word32)" and (Scala) "_" and (OCaml) "Int32.logand (Int32.of'_int _) Uint.int32'_mask" | constant uint64_of_uint \<rightharpoonup> (SML) "Uint64.fromLarge (Word.toLarge _)" and (Haskell) "(Prelude.fromIntegral _ :: Uint64.Word64)" and (Scala) "((_).toLong & 0xFFFFFFFFL)" and (OCaml) "Int64.logand (Int64.of'_int _) Uint.int64'_mask" lemma uint8_of_uint_code [code]: "uint8_of_uint x = Abs_uint8' (ucast (Rep_uint' x))" unfolding Rep_uint'_def by transfer simp lemma uint16_of_uint_code [code]: "uint16_of_uint x = Abs_uint16' (ucast (Rep_uint' x))" unfolding Rep_uint'_def by transfer simp lemma uint32_of_uint_code [code]: "uint32_of_uint x = Abs_uint32' (ucast (Rep_uint' x))" unfolding Rep_uint'_def by transfer simp lemma uint64_of_uint_code [code]: "uint64_of_uint x = Abs_uint64' (ucast (Rep_uint' x))" unfolding Rep_uint'_def by transfer simp lemma uint_of_uint8_code [code]: "uint_of_uint8 x = Abs_uint' (ucast (Rep_uint8' x))" by transfer simp lemma uint_of_uint16_code [code]: "uint_of_uint16 x = Abs_uint' (ucast (Rep_uint16' x))" by transfer simp lemma uint_of_uint32_code [code]: "uint_of_uint32 x = Abs_uint' (ucast (Rep_uint32' x))" by transfer simp lemma uint_of_uint64_code [code]: "uint_of_uint64 x = Abs_uint' (ucast (Rep_uint64' x))" by transfer simp end
[STATEMENT] lemma useful_tautologies_4[PLM]: "[(\<^bold>\<not>\<psi> \<^bold>\<rightarrow> \<^bold>\<not>\<phi>) \<^bold>\<rightarrow> (\<phi> \<^bold>\<rightarrow> \<psi>) in v]" [PROOF STATE] proof (prove) goal (1 subgoal): 1. [\<^bold>\<not>\<psi> \<^bold>\<rightarrow> \<^bold>\<not>\<phi> \<^bold>\<rightarrow> (\<phi> \<^bold>\<rightarrow> \<psi>) in v] [PROOF STEP] by (meson pl_1 pl_2 pl_3 ded_thm_cor_3 ded_thm_cor_4 axiom_instance)
#include <Eigen/Core> #include <Eigen/SparseCore> #include <mimkl/definitions.hpp> #include <mimkl/linear_algebra.hpp> #include <numeric> #include <sstream> #include <string> #include <vector> using mimkl::definitions::Index; typedef std::function< void(const MATRIX(double) &, const MATRIX(double) &, MATRIX(double) &)> void_fun; typedef std::function<MATRIX(double)(const MATRIX(double) &, const MATRIX(double) &)> nonvoid_fun; class Example { public: void set(std::string msg) { _msg = msg; } void many(const std::vector<std::string> &msgs); std::string greet() { return _msg; } private: std::string _msg; }; double apply_5(std::function<double(double)>); double add_to_3(double); std::vector<double> map(std::function<double(double)>, std::vector<double>); std::vector<double> zip_map(std::vector<std::function<double(double)>>, std::vector<double>); MATRIX(double) sum_plain_matrices(const std::vector<MATRIX(double)>); MATRIX(double) sum_matrices(const MATRIX(double) &, const MATRIX(double) &, const std::vector<nonvoid_fun> &); template <typename Scalar, typename Function> MATRIX(Scalar) sum_matrices_temp(const MATRIX(Scalar) & lhs, const MATRIX(Scalar) & rhs, const std::vector<Function> &Ks) { // fold over Ks return std::accumulate(Ks.begin(), Ks.end(), MATRIX(Scalar)::Zero(lhs.rows(), rhs.rows()).eval(), [&, lhs, rhs](const MATRIX(Scalar) & acc, const Function &fun) { return acc + fun(lhs, rhs); }); } template <typename Scalar, typename Function> MATRIX(Scalar) sum_matrices_temp_inline(const MATRIX(Scalar) & lhs, const MATRIX(Scalar) & rhs, const std::vector<Function> &Ks) { MATRIX(Scalar) acc = MATRIX(Scalar)::Zero(lhs.rows(), rhs.rows()).eval(); // for( auto iter = Ks.begin(); iter != Ks.end(); ++iter){ for (auto iter : Ks) { // acc = acc + (*iter)(lhs,rhs); acc += iter(lhs, rhs); // (*iter) } return acc; } template <typename Scalar, typename Function> Scalar sum_temp(const Scalar &x, const Scalar &y, const std::vector<Function> &fs) { // fold over Ks return std::accumulate(fs.begin(), fs.end(), (Scalar)0, [&](const Scalar &acc, const Function &fun) { return acc + fun(x, y); }); } template <typename Scalar, typename Function> Scalar sum_mat_return_scalar_temp(const MATRIX(Scalar) & x, const MATRIX(Scalar) & y, const std::vector<Function> &fs) { // fold over Ks return std::accumulate(fs.begin(), fs.end(), (Scalar)0, [&](const Scalar &acc, const Function &fun) { return acc + fun(x, y); }); } MATRIX(double) sum_fun_matrices_reference(const MATRIX(double) &, const MATRIX(double) &, const std::vector<void_fun>); void_fun convert_function(nonvoid_fun); nonvoid_fun convert_function(void_fun); std::vector<void_fun> convert_function(std::vector<nonvoid_fun>); std::vector<nonvoid_fun> convert_function(std::vector<void_fun>); MATRIX(double) sum_fun_matrices_return(const MATRIX(double) &, const MATRIX(double) &, const std::vector<nonvoid_fun>); MATRIX(double) sum_converted_fun_matrices_return(const MATRIX(double) &, const MATRIX(double) &, const std::vector<void_fun>); Eigen::SparseMatrix<double> add_sparse(Eigen::SparseMatrix<double>, Eigen::SparseMatrix<double>);
lemma at_top_le_at_infinity: "at_top \<le> (at_infinity :: real filter)"
function f = f_function ( x, y1, y2, Md, Nd, L ) %*****************************************************************************80 % %% F_FUNCTION: RHS function from exact coefficient Q and the exact solution U. % % Discussion: % % The differential equation has the form: % % ( q(x) u_x(x) )_x = f(x) % % Licensing: % % This code is distributed under the GNU LGPL license. % % Parameters: % % x = physical space point of length one % % y1 = stochastic vector of length Md (from the expansion for u) % % y2 = stochastic vector of length Nd (from the expansion for q) % % Md = dimension of the probability space for u % % Nd = dimension of the probability space for q % % L = the correlation length of the random variables % [n_nodes, dim] = size(x); f = zeros( n_nodes, 1 ); for n=1:Nd for m=1:Md f = f + qn(n) * um( m ) * pn(y2, n) * pm(y1, m) * ... ( -(pi/L)^2 * m^2 .* sin((m*pi*x)/L) .* cos((n*pi*x)/L) ... -n*m * (pi/L)^2 * cos((m*pi*x)/L) .* sin((n*pi*x)/L) ); end end return end function p_m = pm( y, m ) %*****************************************************************************80 % %% PM % p_m = y(m); return end function p_n = pn( y, n ) %*****************************************************************************80 % %% PN % p_n = y(n); return end function q_n = qn( n ) %*****************************************************************************80 % %% QN % q_n = 1; return end function u_m = um( m ) %*****************************************************************************80 % %% UM % u_m = 1; return end
import sys import threading import logging import time import numpy as np import sounddevice as sd class OutputSignal(threading.Thread): """ Represents an output signal such as the speaker Runs in its own thread to push data onto the buffer Attributes ---------- device: String A string representation of the sound device being used. 'default' is usually all that is needed buffer : FiFoBuffer A thread-safe FifoBuffer that reads the underlying data stream (stereo sound) stepSize: int The number of signal frames or matrix rows used in the transfer of data to the server waitCondition: Condition The threading condition or lock that is used to signal when output can start stopped: Boolean A flag indicating if the algorithm is running """ def __init__(self, device, buffer, stepSize, waitCondition, threadName): """ Parameters ---------- device: String A string representation of the sound device being used. 'default' is usually all that is needed buffer : FiFoBuffer A thread-safe FifoBuffer that reads the underlying data stream (stereo sound) stepSize: int The number of signal frames or matrix rows used in the transfer of data to the server waitCondition: Condition The threading condition or lock that is used to signal when output can start threadName : str The name of the thread. Utilized for debugging. """ logging.debug('Initializing Output Speaker thread') threading.Thread.__init__(self, name=threadName, daemon=True) self.device = device self.buffer = buffer self.stepSize = stepSize self.waitCondition = waitCondition self.stopped = False def listener(self, outdata, frames, time, status): """ Callback function for sounddevice OutputStream Is called periodically to place data from the buffer into the speaker output This is driven by PulseAudio under the covers of sounddevice Parameters ---------- outdata: numpy.ndarray The numpy matrix that contains the microphone data with one column per channel frames: int The number of rows for indata time: CData Provides a CFFI structure with timestamps indicating the ADC capture time of the first sample in the input buffer status: CallbackFlags Instance indicating whether input and/or output buffers have been inserted or will be dropped to overcome underflow or overflow conditions. Returns ------- None Raises ------ None """ data = self.buffer.pop() size = data.shape[0] outdata[:size] = data def stop(self): """ Called when the algorithm is stopped and sets the stopped flag to False Parameters ---------- None Returns ------- None Raises ------ None """ self.stopped = True def run(self): """ The primary thread function that initializes the OutputStream and continuously calls the Stream listener to place data from the buffer into the Stream Parameters ---------- None Returns ------- None Raises ------ None """ try: logging.debug('Running Output Speaker thread') with self.waitCondition: self.waitCondition.wait() with sd.OutputStream(device=self.device, channels=2, blocksize=self.stepSize, callback=self.listener): while not self.stopped: # time takes up less cpu cycles than 'pass' time.sleep(1) except Exception as e: logging.exception(f'Exception thrown: {e}')
[STATEMENT] lemma open_empty [continuous_intros, intro, simp]: "open {}" [PROOF STATE] proof (prove) goal (1 subgoal): 1. open {} [PROOF STEP] using open_Union [of "{}"] [PROOF STATE] proof (prove) using this: Ball {} open \<Longrightarrow> open (\<Union> {}) goal (1 subgoal): 1. open {} [PROOF STEP] by simp
import System import System.Info main : IO () main = do 0 <- system "bash zero.sh" | r => do putStrLn ("expecting zero, got " ++ (show r)) exitFailure -- `system` returns result of `waitpid` which is not trivial to decode let True = !(System.system "bash seventeen.sh") /= 0 | False => putStrLn "expecting 17, got zero" let nastyStr = "Hello \"world\" $PATH %PATH% \\\" `echo 'Uh, oh'`" ignore $ system $ "echo " ++ escapeArg nastyStr ignore $ system ["echo", nastyStr] if not isWindows then do ignore $ system $ "echo " ++ escapeArg "Hello\nworld" ignore $ system ["echo", "Hello\nworld"] else do putStrLn "Hello\nworld\nHello\nworld" -- Windows has no way of escaping '\n', so skip test
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module Issue15 where infix 7 _≡_ infixr 5 _∧_ infix 5 ∃ infixr 4 _∨_ data _∨_ (A B : Set) : Set where inj₁ : A → A ∨ B inj₂ : B → A ∨ B data _∧_ (A B : Set) : Set where _,_ : A → B → A ∧ B postulate D : Set _·_ : D → D → D succ : D → D zero : D data ∃ (A : D → Set) : Set where _,_ : (t : D) → A t → ∃ A syntax ∃ (λ x → e) = ∃[ x ] e data _≡_ (x : D) : D → Set where refl : x ≡ x postulate Conat : D → Set postulate Conat-out : ∀ {n} → Conat n → n ≡ zero ∨ (∃[ n' ] n ≡ succ n' ∧ Conat n') {-# ATP axiom Conat-out #-} postulate Conat-coind : (A : D → Set) → -- A is post-fixed point of NatF. (∀ {n} → A n → n ≡ zero ∨ (∃[ n' ] n ≡ succ n' ∧ A n')) → -- Conat is greater than A. ∀ {n} → A n → Conat n -- See Issue #81. A : D → Set A n = n ≡ zero ∨ (∃[ n' ] n ≡ succ n' ∧ Conat n') {-# ATP definition A #-} Conat-in : ∀ {n} → n ≡ zero ∨ (∃[ n' ] n ≡ succ n' ∧ Conat n') → Conat n Conat-in h = Conat-coind A h' h where postulate h' : ∀ {n} → A n → n ≡ zero ∨ (∃[ n' ] n ≡ succ n' ∧ A n') {-# ATP prove h' #-}
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro ! This file was ported from Lean 3 source module data.int.char_zero ! leanprover-community/mathlib commit acee671f47b8e7972a1eb6f4eed74b4b3abce829 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Data.Int.Cast.Field /-! # Injectivity of `Int.Cast` into characteristic zero rings and fields. -/ variable {α : Type _} open Nat namespace Int @[simp] theorem cast_eq_zero [AddGroupWithOne α] [CharZero α] {n : ℤ} : (n : α) = 0 ↔ n = 0 := ⟨fun h => by cases n · erw [Int.cast_ofNat] at h exact congr_arg _ (Nat.cast_eq_zero.1 h) · rw [cast_negSucc, neg_eq_zero, Nat.cast_eq_zero] at h contradiction, fun h => by rw [h, cast_zero]⟩ #align int.cast_eq_zero Int.cast_eq_zero @[simp, norm_cast] theorem cast_inj [AddGroupWithOne α] [CharZero α] {m n : ℤ} : (m : α) = n ↔ m = n := by rw [← sub_eq_zero, ← cast_sub, cast_eq_zero, sub_eq_zero] #align int.cast_inj Int.cast_inj theorem cast_injective [AddGroupWithOne α] [CharZero α] : Function.Injective (Int.cast : ℤ → α) | _, _ => cast_inj.1 #align int.cast_injective Int.cast_injective theorem cast_ne_zero [AddGroupWithOne α] [CharZero α] {n : ℤ} : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero #align int.cast_ne_zero Int.cast_ne_zero @[simp, norm_cast] theorem cast_div_charZero {k : Type _} [DivisionRing k] [CharZero k] {m n : ℤ} (n_dvd : n ∣ m) : ((m / n : ℤ) : k) = m / n := by rcases eq_or_ne n 0 with (rfl | hn) · simp [Int.ediv_zero] · exact cast_div n_dvd (cast_ne_zero.mpr hn) #align int.cast_div_char_zero Int.cast_div_charZero end Int theorem RingHom.injective_int {α : Type _} [NonAssocRing α] (f : ℤ →+* α) [CharZero α] : Function.Injective f := Subsingleton.elim (Int.castRingHom _) f ▸ Int.cast_injective #align ring_hom.injective_int RingHom.injective_int
A set $B$ is a topological basis if and only if for every open set $O$, every point $x \in O$ is contained in some element of $B$ that is contained in $O$.
WALDWICK, N.J. -- Thomas J. McLaughlin, of Waldwick, died Thursday, Nov. 17. He was 86. Born in the Bronx, in 1930, he was a longtime resident of Waldwick. He was a construction supervisor at AJ Contracting in Manhattan, before retiring. He served in the U.S. Army during peacetime. He is survived by his wife, Theresa F. McLaughlin; children, Thomas J. McLaughlin Jr. and his wife Jayne, Theresa Karole, Michael McLaughlin, Maureen McGinle and her husband Lawrence and Ellen M. McLaughlin; grandchildren, Katherine, Devin, Thomas, John, Michael and Ashley; and sister, Mary Kate Jensen. Visitation will from 2-5 p.m. Sunday at the Vander Plaat Funeral Home, 257 Godwin Ave., Wyckoff. A funeral Mass will be celebrated at 11 a.m. Monday at Church of the Nativity, 315 Prospect St., Midland Park. Interment will follow at Ascension Cemetery in Monsey, N.Y.
#include <Boost/SocketServer.h> #include <boost/asio.hpp> int main() { using namespace EL; boost::asio::io_service service; auto server = std::make_shared<SocketServer>(service, 5000); server->Start(); service.run(); return 0; }
[STATEMENT] lemma Collect_parametric: "((A ===> (=)) ===> rel_pred A) Collect Collect" \<comment> \<open>Declare this rule as @{attribute transfer_rule} only locally because it blows up the search space for @{method transfer} (in combination with @{thm [source] Collect_transfer})\<close> [PROOF STATE] proof (prove) goal (1 subgoal): 1. ((A ===> (=)) ===> rel_pred A) Collect Collect [PROOF STEP] by(simp add: rel_funI rel_predI)
------------------------------------------------------------------------ -- Code related to the paper "Logical properties of a modality for -- erasure" -- -- Nils Anders Danielsson ------------------------------------------------------------------------ -- Note that the code does not follow the paper exactly. For instance, -- some definitions use bijections (functions with quasi-inverses) -- instead of equivalences. Some other differences are mentioned -- below. -- This file is not checked using --safe, because some parts use -- --cubical, and some parts use --with-K. However, all files -- imported below use --safe. {-# OPTIONS --cubical --with-K #-} module README.Erased where import Agda.Builtin.Equality import Agda.Builtin.Cubical.Id import Agda.Builtin.Cubical.Path import Embedding import Equality import Equality.Id import Equality.Instances-related import Equality.Path import Equality.Propositional import Equivalence import Erased import Erased.Cubical import Erased.With-K import Function-universe import H-level import Nat.Wrapper import Nat.Wrapper.Cubical import Prelude import Queue.Truncated import Quotient ------------------------------------------------------------------------ -- 3: Erased -- Erased. Erased = Erased.Erased ------------------------------------------------------------------------ -- 3.1: Erased is a monad -- Bind. bind = Erased._>>=′_ -- Erased is a monad. erased-monad = Erased.monad -- Lemma 3. Lemma-3 = Erased.Erased-Erased↔Erased ------------------------------------------------------------------------ -- 3.2: The relationship between @0 and Erased -- Lemma 4 and Lemma 5. Lemmas-4-and-5 = Erased.Π-Erased≃Π0[] -- The equality type family, defined as an inductive family. Equality-defined-as-an-inductive-family = Agda.Builtin.Equality._≡_ -- Cubical Agda paths. Path = Agda.Builtin.Cubical.Path._≡_ -- The Cubical Agda identity type family. Id = Agda.Builtin.Cubical.Id.Id -- The code uses an axiomatisation of "equality with J". The -- axiomatisation is a little convoluted in order to support using -- equality at all universe levels. Furthermore the axiomatisation -- supports choosing specific definitions for other functions, like -- cong, to make the code more usable when it is instantiated with -- Cubical Agda paths (for which the canonical definition of cong -- computes in a different way than typical definitions obtained -- using J). -- Equality and reflexivity. ≡-refl = Equality.Reflexive-relation -- The J rule and its computation rule. J-J-refl = Equality.Equality-with-J₀ -- Extended variants of the two definitions above. Equivalence-relation⁺ = Equality.Equivalence-relation⁺ Equality-with-J = Equality.Equality-with-J -- To see how the code is axiomatised, see the module header of, say, -- Erased. module See-the-module-header-of = Erased -- The equality type family defined as an inductive family, Cubical -- Agda paths and the Cubical Agda identity type family can all be -- used to instantiate the axioms. Equality-with-J-for-equality-defined-as-an-inductive-family = Equality.Propositional.equality-with-J Equality-with-J-for-Path = Equality.Path.equality-with-J Equality-with-J-for-Id = Equality.Id.equality-with-J -- Lemma 7 in Cubical Agda. Lemma-7-cubical = Erased.Cubical.Π-Erased≃Π0[] -- Lemma 7 in traditional Agda. Lemma-7-traditional = Erased.With-K.Π-Erased≃Π0[] ------------------------------------------------------------------------ -- 3.3: Erased commutes -- Some lemmas. Lemma-8 = Erased.Erased-⊤↔⊤ Lemma-9 = Erased.Erased-⊥↔⊥ Lemma-10 = Erased.Erased-Π↔Π Lemma-11 = Erased.Erased-Π↔Π-Erased Lemma-12 = Erased.Erased-Σ↔Σ -- W-types. W = Prelude.W -- Lemma 14 (Erased commutes with W-types up to logical equivalence). Lemma-14 = Erased.Erased-W⇔W -- Erased commutes with W-types, assuming extensionality for functions -- and []-cong. -- -- The code uses a universe of "function formers" which makes it -- possible to prove a single statement that can be instantiated both -- as a logical equivalence that does not rely on extensionality, as -- well as an equivalence that does rely on extensionality (and in -- other ways). This lemma, and several others, are stated in that -- way. Lemma-14′ = Erased.Erased-W↔W ------------------------------------------------------------------------ -- 3.4: The []-cong property -- []-cong, proved in traditional Agda. []-cong-traditional = Erased.With-K.[]-cong -- []-cong, proved in Cubical Agda for paths. []-cong-cubical-paths = Erased.Cubical.[]-cong-Path -- Every family of equality types satisfying the axiomatisation -- discussed above is in pointwise bijective correspondence with every -- other, with the bijections mapping reflexivity to reflexivity. Families-equivalent = Equality.Instances-related.all-equality-types-isomorphic -- []-cong, proved in Cubical Agda for an arbitrary equality type -- family satisfying the axiomatisation discussed above. []-cong-cubical = Erased.Cubical.[]-cong -- Lemmas 17 and 18 in traditional Agda. Lemma-17-traditional = Erased.With-K.[]-cong-equivalence Lemma-18-traditional = Erased.With-K.[]-cong-[refl] -- Lemmas 17 and 18 in Cubical Agda, with paths. Lemma-17-cubical-paths = Erased.Cubical.[]-cong-Path-equivalence Lemma-18-cubical-paths = Erased.Cubical.[]-cong-Path-[refl] -- Lemmas 17 and 18 in Cubical Agda, with an arbitrary family of -- equality types satisfying the axiomatisation discussed above. Lemma-17-cubical = Erased.Cubical.[]-cong-equivalence Lemma-18-cubical = Erased.Cubical.[]-cong-[refl] ------------------------------------------------------------------------ -- 3.5: H-levels -- H-level, For-iterated-equality and Contractible. H-level = H-level.H-level′ For-iterated-equality = H-level.For-iterated-equality Contractible = Equality.Reflexive-relation′.Contractible -- Sometimes the code uses the following definition of h-levels -- instead of the one used in the paper. Other-definition-of-h-levels = H-level.H-level -- The two definitions are pointwise logically equivalent, and -- pointwise equivalent if equality is extensional for functions. H-level≃H-level′ = Function-universe.H-level↔H-level′ -- There is a single statement for Lemmas 22 and 23. Lemmas-22-and-23 = Erased.Erased-H-level′↔H-level′ ------------------------------------------------------------------------ -- 3.6: Erased is a modality -- Some lemmas. Lemma-24 = Erased.uniquely-eliminating-modality Lemma-25 = Erased.lex-modality -- The map function. map = Erased.map -- Erased is a Σ-closed reflective subuniverse. Σ-closed-reflective-subuniverse = Erased.Erased-Σ-closed-reflective-subuniverse -- Another lemma. Lemma-27 = Erased.Erased-connected↔Erased-Is-equivalence ------------------------------------------------------------------------ -- 3.7: Is [_] an embedding? -- The function cong is unique up to pointwise equality if it is -- required to map the canonical proof of reflexivity to the canonical -- proof of reflexivity. cong-canonical = Equality.Derived-definitions-and-properties.cong-canonical -- Is-embedding. Is-embedding = Embedding.Is-embedding -- Embeddings are injective. embeddings-are-injective = Embedding.injective -- Some lemmas. Lemma-29 = Erased.Is-proposition→Is-embedding-[] Lemma-30 = Erased.With-K.Injective-[] Lemma-31 = Erased.With-K.Is-embedding-[] Lemma-32 = Erased.With-K.Is-proposition-Erased→Is-proposition ------------------------------------------------------------------------ -- 3.8: More commutation properties -- There is a single statement for Lemmas 33–38 (and more). Lemmas-33-to-38 = Erased.Erased-↝↔↝ -- There is also a single statement for the variants of Lemmas 33–38, -- stated as logical equivalences instead of equivalences, that can be -- proved without using extensionality. Lemmas-33-to-38-with-⇔ = Erased.Erased-↝↝↝ -- Some lemmas. Lemma-39 = Erased.Erased-cong-≃ Lemma-40 = Erased.Erased-Is-equivalence↔Is-equivalence -- A generalisation of Lemma 41. Lemma-41 = Function-universe.Σ-cong -- More lemmas. Lemma-42 = Erased.Erased-Split-surjective↔Split-surjective Lemma-43 = Erased.Erased-Has-quasi-inverse↔Has-quasi-inverse Lemma-44 = Erased.Erased-Injective↔Injective Lemma-45 = Erased.Erased-Is-embedding↔Is-embedding Lemma-46 = Erased.map-cong≡cong-map -- There is a single statement for Lemmas 47–52 (and more). Lemmas-47-to-52 = Erased.Erased-cong -- The map function is functorial. map-id = Erased.map-id map-∘ = Erased.map-∘ -- All preservation lemmas (47–52) map identity to identity (assuming -- extensionality, except for logical equivalences). Erased-cong-id = Erased.Erased-cong-id -- All preservation lemmas (47–52) commute with composition (assuming -- extensionality, except for logical equivalences). Erased-cong-∘ = Erased.Erased-cong-∘ ------------------------------------------------------------------------ -- 4.1: Stable types -- Stable. Stable = Erased.Stable -- Some lemmas. Lemma-54 = Erased.¬¬-stable→Stable Lemma-55 = Erased.Erased→¬¬ Lemma-56 = Erased.Dec→Stable ------------------------------------------------------------------------ -- 4.2: Very stable types -- Very-stable. Very-stable = Erased.Very-stable -- A generalisation of Very-stable′. Very-stable′ = Erased.Stable-[_] -- Very stable types are stable (and Very-stable A implies -- Very-stable′ A, and more). Very-stable→Stable = Erased.Very-stable→Stable -- [_] is an embedding for very stable types. Very-stable→Is-embedding-[] = Erased.Very-stable→Is-embedding-[] -- Some lemmas. Lemma-59 = Erased.Stable→Left-inverse→Very-stable Lemma-60 = Erased.Stable-proposition→Very-stable Lemma-61 = Erased.Very-stable-Erased -- It is not the case that every very stable type is a proposition. ¬-Very-stable→Is-proposition = Erased.¬-Very-stable→Is-proposition -- More lemmas. Lemma-62 = Erased.Very-stable-∃-Very-stable Lemma-63 = Erased.Stable-∃-Very-stable ------------------------------------------------------------------------ -- 4.3: Stability for equality types -- Stable-≡ and Very-stable-≡. Stable-≡ = Erased.Stable-≡ Very-stable-≡ = Erased.Very-stable-≡ -- Some lemmas. Lemma-66 = Erased.Stable→H-level-suc→Very-stable Lemma-67 = Erased.Decidable-equality→Very-stable-≡ Lemma-68 = Erased.H-level→Very-stable -- Lemmas 69 and 70, stated both as logical equivalences, and as -- equivalences depending on extensionality. Lemma-69 = Erased.Stable-≡↔Injective-[] Lemma-70 = Erased.Very-stable-≡↔Is-embedding-[] -- Equality is always very stable in traditional Agda. Very-stable-≡-trivial = Erased.With-K.Very-stable-≡-trivial ------------------------------------------------------------------------ -- 4.4: Map-like functions -- Lemma 71. Lemma-71 = Erased.Stable-map-⇔ -- There is a single statement for Lemmas 72 and 73. Lemmas-72-and-73 = Erased.Very-stable-cong -- Lemma 74. Lemma-74 = Erased.Very-stable-Erased↝Erased -- Lemma 74, with Stable instead of Very-stable, and no assumption of -- extensionality. Lemma-74-Stable = Erased.Stable-Erased↝Erased ------------------------------------------------------------------------ -- 4.5: Closure properties -- Lots of lemmas. Lemmas-75-and-76 = Erased.Very-stable→Very-stable-≡ Lemma-77 = Erased.Very-stable-⊤ Lemma-78 = Erased.Very-stable-⊥ Lemma-79 = Erased.Stable-Π Lemma-80 = Erased.Very-stable-Π Lemma-81 = Erased.Very-stable-Stable-Σ Lemma-82 = Erased.Very-stable-Σ Lemma-83 = Erased.Stable-× Lemma-84 = Erased.Very-stable-× Lemma-85 = Erased.Very-stable-W Lemmas-86-and-87 = Erased.Stable-H-level′ Lemmas-88-and-89 = Erased.Very-stable-H-level′ Lemma-90 = Erased.Stable-≡-⊎ Lemma-91 = Erased.Very-stable-≡-⊎ Lemma-92 = Erased.Stable-≡-List Lemma-93 = Erased.Very-stable-≡-List Lemma-94 = Quotient.Very-stable-≡-/ ------------------------------------------------------------------------ -- 4.6: []‐cong can be proved using extensionality -- The proof has been changed. Lemmas 95 and 97 have been removed. -- A lemma. Lemma-96 = Equivalence.≃-≡ -- []-cong, proved using extensionality, along with proofs showing -- that it is an equivalence and that it satisfies the computation -- rule of []-cong. Extensionality→[]-cong = Erased.Extensionality→[]-cong-axiomatisation ------------------------------------------------------------------------ -- 5.1: Singleton types with erased equality proofs -- Some lemmas. Lemma-99 = Erased.erased-singleton-contractible Lemma-100 = Erased.erased-singleton-with-erased-center-propositional -- The generalisation of Lemma 82 used in the proof of Lemma 100. Lemma-82-generalised = Erased.Very-stable-Σⁿ -- Another lemma. Lemma-101 = Erased.Σ-Erased-Erased-singleton↔ ------------------------------------------------------------------------ -- 5.2: Efficient natural numbers -- An implementation of natural numbers as lists of bits with the -- least significant bit first and an erased invariant that ensures -- that there are no trailing zeros. import Nat.Binary -- Nat-[_]. Nat-[_] = Nat.Wrapper.Nat-[_] -- A lemma. Lemma-103 = Nat.Wrapper.[]-cong.Nat-[]-propositional -- Nat. Nat = Nat.Wrapper.Nat -- ⌊_⌋. @0 ⌊_⌋ : _ ⌊_⌋ = Nat.Wrapper.⌊_⌋ -- Another lemma. Lemma-106 = Nat.Wrapper.[]-cong.≡-for-indices↔≡ ------------------------------------------------------------------------ -- 5.2.1: Arithmetic -- The functions unary-[] and unary. unary-[] = Nat.Wrapper.unary-[] unary = Nat.Wrapper.unary -- Similar functions for arbitrary arities. n-ary-[] = Nat.Wrapper.n-ary-[] n-ary = Nat.Wrapper.n-ary ------------------------------------------------------------------------ -- 5.2.2: Converting Nat to ℕ -- Some lemmas. Lemma-109 = Nat.Wrapper.Nat-[]↔Σℕ Lemma-110 = Nat.Wrapper.[]-cong.Nat↔ℕ -- The function Nat→ℕ. Nat→ℕ = Nat.Wrapper.Nat→ℕ -- Some lemmas. @0 Lemma-111 : _ Lemma-111 = Nat.Wrapper.≡⌊⌋ Lemma-112 = Nat.Wrapper.unary-correct -- A variant of Lemma 112 for n-ary. Lemma-112-for-n-ary = Nat.Wrapper.n-ary-correct ------------------------------------------------------------------------ -- 5.2.3: Decidable equality -- Some lemmas. Lemma-113 = Nat.Wrapper.Operations-for-Nat._≟_ Lemma-114 = Nat.Wrapper.Operations-for-Nat-[]._≟_ ------------------------------------------------------------------------ -- 5.3: Queues -- The implementation of queues (parametrised by an underlying queue -- implementation). module Queue = Queue.Truncated -- The functions enqueue and dequeue. enqueue = Queue.Truncated.Non-indexed.enqueue dequeue = Queue.Truncated.Non-indexed.dequeue ------------------------------------------------------------------------ -- 6: Discussion and related work -- Nat-[_]′. Nat-[_]′ = Nat.Wrapper.Cubical.Nat-[_]′ -- An alternative implementation of Nat. Alternative-Nat = Nat.Wrapper.Cubical.Nat-with-∥∥ -- The alternative implementation of Nat is isomorphic to the unit -- type. Alternative-Nat-isomorphic-to-⊤ = Nat.Wrapper.Cubical.Nat-with-∥∥↔⊤ -- The alternative implementation of Nat is not isomorphic to the -- natural numbers. Alternative-Nat-not-isomorphic-to-ℕ = Nat.Wrapper.Cubical.¬-Nat-with-∥∥↔ℕ
module BBHeap.Complete.Base {A : Set}(_≤_ : A → A → Set) where open import BBHeap _≤_ open import BBHeap.Complete.Alternative _≤_ renaming (lemma-bbheap-complete to lemma-bbheap-complete') open import BTree.Complete.Alternative.Correctness {A} open import BTree.Complete.Base {A} open import Bound.Lower A open import Function using (_∘_) lemma-bbheap-complete : {b : Bound}(h : BBHeap b) → Complete (forget h) lemma-bbheap-complete = lemma-complete'-complete ∘ lemma-bbheap-complete'
module Types public export data IsIt = Z | O