Datasets:
AI4M
/

text
stringlengths
0
3.34M
MODULE mod1 USE mod2 USE mod3 END MODULE mod1
subroutine jtwo(n2,n3,n4,n5,n6,n1,za,zb,zab,zba,j2,jw2) implicit none include 'constants.f' include 'zprods_decl.f' double complex zab(mxpart,4,mxpart),zba(mxpart,4,mxpart), & j2(4,2,2,2,2),j2_34_56_1(4,2,2,2,2),j2_56_34_1(4,2,2,2,2), & jw2(4,2,2,2),jw2_34_56_1(4,2,2,2),jw2_56_34_1(4,2,2,2) integer n1,n2,n3,n4,n5,n6,jdu,h21,h34,h56 C---The two Z-current divided by (-i) call jtwo3456(n2,n3,n4,n5,n6,n1, & za,zb,zab,zba,j2_34_56_1,jw2_34_56_1) call jtwo3456(n2,n5,n6,n3,n4,n1, & za,zb,zab,zba,j2_56_34_1,jw2_56_34_1) do jdu=1,2 do h56=1,2 do h34=1,2 jw2(1:4,jdu,h34,h56)= & jw2_34_56_1(1:4,jdu,h34,h56) & +jw2_56_34_1(1:4,jdu,h56,h34) do h21=1,2 j2(1:4,jdu,h21,h34,h56)= & j2_34_56_1(1:4,jdu,h21,h34,h56) & +j2_56_34_1(1:4,jdu,h21,h56,h34) enddo enddo enddo enddo return end
/- Copyright (c) 2023 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author : Kevin Buzzard -/ import tactic import number_theory.divisors -- added to make Bhavik's proof work /- # Find all integers x ≠ 3 such that x - 3 divides x^3 - 3 This is the second question in Sierpinski's book "250 elementary problems in number theory". My solution: x - 3 divides x^3-27, and hence if it divides x^3-3 then it also divides the difference, which is 24. Conversely, if x-3 divides 24 then because it divides x^3-27 it also divides x^3-3. But getting Lean to find all the integers divisors of 24 is a nightmare! Bhavik (last year) managed to figure out how to do this. -/ -- This isn't so hard lemma lemma1 (x : ℤ) : x - 3 ∣ x^3 - 3 ↔ x - 3 ∣ 24 := begin have h : x - 3 ∣ x ^ 3 - 27, { use x ^ 2 + 3 * x + 9, ring, }, split, { intro h1, have h2 := dvd_sub h1 h, convert h2, ring }, { intro h1, convert dvd_add h h1, ring }, end lemma int_dvd_iff (x : ℤ) (n : ℤ) (hn : n ≠ 0) : x ∣ n ↔ x.nat_abs ∈ n.nat_abs.divisors := by simp [hn] -- Thanks to Bhavik Mehta for showing me how to prove this in Lean 3 without timing out! lemma lemma2 (x : ℤ) : x ∣ 24 ↔ x ∈ ({-24,-12,-8,-6,-4,-3,-2,-1,1,2,3,4,6,8,12,24} : set ℤ) := begin suffices : x ∣ 24 ↔ x.nat_abs ∈ ({1,2,3,4,6,8,12,24} : finset ℕ), { simp only [this, int.nat_abs_eq_iff, set.mem_insert_iff, set.mem_singleton_iff, finset.mem_insert, finset.mem_singleton], norm_cast, rw ←eq_iff_iff, ac_refl }, exact int_dvd_iff _ 24 (by norm_num), end -- This seems much harder :-) (it's really a computer science question, not a maths question, -- feel free to skip) example (x : ℤ) : x - 3 ∣ x^3 - 3 ↔ x ∈ ({-21, -9, -5, -3, -1, 0, 1, 2, 4, 5, 6, 7, 9, 11, 15, 27} : set ℤ) := begin rw lemma1, rw lemma2, simp only [set.mem_insert_iff, sub_eq_neg_self, set.mem_singleton_iff], repeat {apply or_congr }, all_goals { omega }, end
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import ring_theory.adjoin.fg import ring_theory.polynomial.scale_roots import ring_theory.polynomial.tower /-! # 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 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 : polynomial R` evaluated under `f` -/ def ring_hom.is_integral_elem (f : R →+* A) (x : A) := ∃ p : polynomial R, 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 : polynomial R`. 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 : (polynomial R →ₗ[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, monic_map _ hp, 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.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_mul _ _ (fg_adjoin_singleton_of_integral x hx) (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 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} /-- 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 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] @[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 : polynomial A} (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 : polynomial (adjoin R S), 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 monic_map _ pmonic } }, { 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, monic_map f hp, 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), ⟨monic_map (algebra_map R A) hp, _⟩⟩, 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 _), ⟨monic_map _ p_monic, _⟩⟩, 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] [is_domain 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 : polynomial R` 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 (algebra_map R S).injective_iff.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_eq_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 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
import data.fintype.basic import linear_algebra.basic universe variables u v variables {G :Type u} (R : Type v) [group G] /-- A central fonction is a function `f : G → R` s.t `∀ s t : G, f (s * t) = f (t * s)` -/ def central_function (f : G → R) := ∀ s t : G, f (s * t) = f (t * s) lemma central (f : G → R)(hyp : central_function R f) (s t : G) : f (s * t) = f (t * s) := hyp s t /-- A central function satisfy `∀ s t : G, f (t⁻¹ * s * t) = f s` -/ theorem central_function_are_constant_on_conjugacy_classses (f : G → R)(hyp : central_function R f) : ∀ s t : G, f (t⁻¹ * s * t) = f s := begin intros s t, rw hyp,rw ← mul_assoc, rw mul_inv_self, rw one_mul, end variables [comm_ring R] /-- We show that central function form a `free R-submodule` of `G → R` -/ def central_submodule : submodule R (G → R) := { carrier := λ f, central_function R f, zero := begin unfold central_function, intros s t, exact rfl end, add := begin intros f g, intros hypf hypg, intros s t, change f _ + g _ = f _ + g _, erw hypf, erw hypg, end, smul := begin intros c, intros f, intros hyp, intros s t, change c • f _ = c • f _, rw hyp, end }
open classical variables (A B : Prop) example : A ∨ ¬ A := by_contradiction (assume h1 : ¬ (A ∨ ¬ A), have h2 : ¬ A, from assume h3 : A, have h4 : A ∨ ¬ A, from or.inl h3, show false, from h1 h4, have h5 : A ∨ ¬ A, from or.inr h2, show false, from h1 h5) example (p : Prop) : p ∨ ¬ p := em p example (h : ¬ B → ¬ A) : A → B := assume h1 : A, show B, from by_contradiction (assume h2 : ¬ B, have h3 : ¬ A, from h h2, show false, from h3 h1) example (h : ¬ (A ∧ ¬ B)) : A → B := assume : A, show B, from by_contradiction (assume : ¬ B, have A ∧ ¬ B, from and.intro ‹A› this, show false, from h this)
Amongst the many interesting discussions I had at Build Stuff last week was about how it’s desirable to switch off disk caching for the disks used for Event Store databases to help ensure that data is durable in the face of power failures. This is actually true of many databases, indeed, postgres gives you a warning about the possible dire consequences of having write caching switched on when you may experience power failure. Obviously here you should replace /dev/sda with whichever device your database is on! Note that simply disabling drive caching is actually not enough to ensure that writes are durable – many drives still misbehave (especially the Intel 520 series SSDs)!
data Nat : Set where zero : Nat suc : Nat → Nat test : ∀{N M : Nat} → Nat → Nat → Nat test N M = {!.N N .M!}
/- Copyright (c) 2021 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel ! This file was ported from Lean 3 source module analysis.subadditive ! leanprover-community/mathlib commit f2ce6086713c78a7f880485f7917ea547a215982 ! Please do not edit these lines, except to modify the commit id ! if you have ported upstream changes. -/ import Mathlib.Topology.Instances.Real import Mathlib.Order.Filter.Archimedean /-! # Convergence of subadditive sequences A subadditive sequence `u : ℕ → ℝ` is a sequence satisfying `u (m + n) ≤ u m + u n` for all `m, n`. We define this notion as `Subadditive u`, and prove in `Subadditive.tendsto_lim` that, if `u n / n` is bounded below, then it converges to a limit (that we denote by `Subadditive.lim` for convenience). This result is known as Fekete's lemma in the literature. ## TODO Define a bundled `SubadditiveHom`, use it. -/ noncomputable section open Set Filter Topology /-- A real-valued sequence is subadditive if it satisfies the inequality `u (m + n) ≤ u m + u n` for all `m, n`. -/ def Subadditive (u : ℕ → ℝ) : Prop := ∀ m n, u (m + n) ≤ u m + u n #align subadditive Subadditive namespace Subadditive variable {u : ℕ → ℝ} (h : Subadditive u) /-- The limit of a bounded-below subadditive sequence. The fact that the sequence indeed tends to this limit is given in `Subadditive.tendsto_lim` -/ @[nolint unusedArguments] -- porting note: was irreducible protected def lim (_h : Subadditive u) := infₛ ((fun n : ℕ => u n / n) '' Ici 1) #align subadditive.lim Subadditive.lim theorem lim_le_div (hbdd : BddBelow (range fun n => u n / n)) {n : ℕ} (hn : n ≠ 0) : h.lim ≤ u n / n := by rw [Subadditive.lim] exact cinfₛ_le (hbdd.mono <| image_subset_range _ _) ⟨n, hn.bot_lt, rfl⟩ #align subadditive.lim_le_div Subadditive.lim_le_div theorem eventually_div_lt_of_div_lt {L : ℝ} {n : ℕ} (hn : n ≠ 0) (hL : u n / n < L) : ∀ᶠ p in atTop, u p / p < L := by /- It suffices to prove the statement for each arithmetic progression `(n * · + r)`. -/ refine .atTop_of_arithmetic hn fun r _ => ?_ /- `(k * u n + u r) / (k * n + r)` tends to `u n / n < L`, hence `(k * u n + u r) / (k * n + r) < L` for sufficiently large `k`. -/ have A : Tendsto (fun x : ℝ => (u n + u r / x) / (n + r / x)) atTop (𝓝 ((u n + 0) / (n + 0))) := (tendsto_const_nhds.add <| tendsto_const_nhds.div_atTop tendsto_id).div (tendsto_const_nhds.add <| tendsto_const_nhds.div_atTop tendsto_id) <| by simpa have B : Tendsto (fun x => (x * u n + u r) / (x * n + r)) atTop (𝓝 (u n / n)) := by rw [add_zero, add_zero] at A refine A.congr' <| (eventually_ne_atTop 0).mono fun x hx => ?_ simp only [(· ∘ ·), add_div' _ _ _ hx, div_div_div_cancel_right _ hx, mul_comm] refine ((B.comp tendsto_nat_cast_atTop_atTop).eventually (gt_mem_nhds hL)).mono fun k hk => ?_ /- Finally, we use an upper estimate on `u (k * n + r)` to get an estimate on `u (k * n + r) / (k * n + r)`. -/ rw [mul_comm] refine lt_of_le_of_lt ?_ hk simp only [(· ∘ ·), ← Nat.cast_add, ← Nat.cast_mul] exact div_le_div_of_le (Nat.cast_nonneg _) (h.apply_mul_add_le _ _ _) #align subadditive.eventually_div_lt_of_div_lt Subadditive.eventually_div_lt_of_div_lt /-- Fekete's lemma: a subadditive sequence which is bounded below converges. -/ theorem tendsto_lim (hbdd : BddBelow (range fun n => u n / n)) : Tendsto (fun n => u n / n) atTop (𝓝 h.lim) := by refine' tendsto_order.2 ⟨fun l hl => _, fun L hL => _⟩ · refine' eventually_atTop.2 ⟨1, fun n hn => hl.trans_le (h.lim_le_div hbdd (zero_lt_one.trans_le hn).ne')⟩ · obtain ⟨n, npos, hn⟩ : ∃ n : ℕ, 0 < n ∧ u n / n < L := by rw [Subadditive.lim] at hL rcases exists_lt_of_cinfₛ_lt (by simp) hL with ⟨x, hx, xL⟩ rcases (mem_image _ _ _).1 hx with ⟨n, hn, rfl⟩ exact ⟨n, zero_lt_one.trans_le hn, xL⟩ exact h.eventually_div_lt_of_div_lt npos.ne' hn #align subadditive.tendsto_lim Subadditive.tendsto_lim end Subadditive
readallmcmc <- function(file){ years <- scan(file,skip=1,nlines=1) nyrs <- length(years) ages <- scan(file,skip=3,nlines=1) nages <- length(ages) variables <- scan(file,skip=5,nlines=1) #. 1 N etc names(variables) <- c("n","cw","sw","mat","f","cno") n1 <- length(variables[variables==1]) print(paste("n1",n1)) nvar <- 1:length(variables) nvar <- nvar[variables==1] dat <- read.table(file,skip=8,header=F) niter <- nrow(dat)/(nyrs*n1) iter <- 1:niter result <- expand.grid(list(year=years,variable=nvar,iter=iter,age=ages)) result$value <- c(unlist(dat)) return(result) }
-- Math 52: Quiz 5 -- Open this file in a folder that contains 'utils'. import utils definition divides (a b : ℤ) : Prop := ∃ (k : ℤ), b = a * k local infix ∣ := divides axiom not_3_divides : ∀ (m : ℤ), ¬ (3 ∣ m) ↔ 3 ∣ m - 1 ∨ 3 ∣ m + 1 theorem main : ∀ (n : ℤ), ¬ (3 ∣ n) → 3 ∣ n * n - 1 := begin sorry end
module System.File where open import System.FilePath open import Prelude.IO open import Prelude.String open import Prelude.Unit open import Prelude.Function open import Prelude.Bytes {-# FOREIGN GHC import qualified Data.Text as Text #-} {-# FOREIGN GHC import qualified Data.Text.IO as Text #-} {-# FOREIGN GHC import qualified Data.ByteString as B #-} private module Internal where StrFilePath : Set StrFilePath = String postulate readTextFile : StrFilePath → IO String writeTextFile : StrFilePath → String → IO Unit readBinaryFile : StrFilePath → IO Bytes writeBinaryFile : StrFilePath → Bytes → IO Unit {-# COMPILE GHC readTextFile = Text.readFile . Text.unpack #-} {-# COMPILE GHC writeTextFile = Text.writeFile . Text.unpack #-} {-# COMPILE GHC readBinaryFile = B.readFile . Text.unpack #-} {-# COMPILE GHC writeBinaryFile = B.writeFile . Text.unpack #-} {-# COMPILE UHC readTextFile = UHC.Agda.Builtins.primReadFile #-} {-# COMPILE UHC writeTextFile = UHC.Agda.Builtins.primWriteFile #-} readTextFile : ∀ {k} → Path k → IO String readTextFile = Internal.readTextFile ∘ toString writeTextFile : ∀ {k} → Path k → String → IO Unit writeTextFile = Internal.writeTextFile ∘ toString readBinaryFile : ∀ {k} → Path k → IO Bytes readBinaryFile = Internal.readBinaryFile ∘ toString writeBinaryFile : ∀ {k} → Path k → Bytes → IO Unit writeBinaryFile = Internal.writeBinaryFile ∘ toString
State Before: α : Type ?u.308464 inst✝ : Preorder α a b c : ℕ H3 : 2 * (b + c) ≤ 9 * a + 3 h : b < 2 * c ⊢ b < 3 * a + 1 State After: no goals Tactic: linarith
import .love05_inductive_predicates_demo /- # LoVe Demo 7: Metaprogramming Users can extend Lean with custom monadic tactics and tools. This kind of programming—programming the prover—is called metaprogramming. Lean's metaprogramming framework uses mostly the same notions and syntax as Lean's input language itself. Abstract syntax trees __reflect__ internal data structures, e.g., for expressions (terms). The prover's C++ internals are exposed through Lean interfaces, which we can use for accessing the current context and goal, unifying expressions, querying and modifying the environment, and setting attributes (e.g., `@[simp]`). Most of Lean's predefined tactics are implemented in Lean (and not in C++). Example applications: * proof goal transformations; * heuristic proof search; * decision procedures; * definition generators; * advisor tools; * exporters; * ad hoc automation. Advantages of Lean's metaprogramming framework: * Users do not need to learn another programming language to write metaprograms; they can work with the same constructs and notation used to define ordinary objects in the prover's library. * Everything in that library is available for metaprogramming purposes. * Metaprograms can be written and debugged in the same interactive environment, encouraging a style where formal libraries and supporting automation are developed at the same time. -/ set_option pp.beta true set_option pp.generalized_field_notation false namespace LoVe /- ## Tactics and Tactic Combinators When programming our own tactics, we often need to repeat some actions on several goals, or to recover if a tactic fails. Tactic combinators help in such case. `repeat` applies its argument repeatedly on all (sub…sub)goals until it cannot be applied any further. -/ lemma repeat_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, repeat { apply even.add_two }, repeat { sorry } end /- The "orelse" combinator `<|>` tries its first argument and applies its second argument in case of failure. -/ lemma repeat_orelse_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, repeat { apply even.add_two <|> apply even.zero }, repeat { sorry } end /- `iterate` works repeatedly on the first goal until it fails; then it stops. -/ lemma iterate_orelse_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, iterate { apply even.add_two <|> apply even.zero }, repeat { sorry } end /- `all_goals` applies its argument exactly once to each goal. It succeeds only if the argument succeeds on **all** goals. -/ lemma all_goals_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, all_goals { apply even.add_two }, -- fails repeat { sorry } end /- `try` transforms its argument into a tactic that never fails. -/ lemma all_goals_try_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, all_goals { try { apply even.add_two } }, repeat { sorry } end /- `any_goals` applies its argument exactly once to each goal. It succeeds if the argument succeeds on **any** goal. -/ lemma any_goals_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, any_goals { apply even.add_two }, repeat { sorry } end /- `solve1` transforms its argument into an all-or-nothing tactic. If the argument does not prove the goal, `solve1` fails. -/ lemma any_goals_solve1_repeat_orelse_example : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin repeat { apply and.intro }, any_goals { solve1 { repeat { apply even.add_two <|> apply even.zero } } }, repeat { sorry } end /- The combinators `repeat`, `iterate`, `all_goals`, and `any_goals` can easily lead to infinite looping: -/ /- lemma repeat_not_example : ¬ even 1 := begin repeat { apply not.intro }, sorry end -/ /- Let us start with the actual metaprogramming, by coding a custom tactic. The tactic embodies the behavior we hardcoded in the `solve1` example above: -/ meta def intro_and_even : tactic unit := do tactic.repeat (tactic.applyc ``and.intro), tactic.any_goals (tactic.solve1 (tactic.repeat (tactic.applyc ``even.add_two <|> tactic.applyc ``even.zero))), pure () /- The `meta` keyword makes it possible for the function to call other metafunctions. The `do` keyword enters a monad, and the `<|>` operator is the "orelse" operator of alternative monads. At the end, we return `()`, of type `unit`, to ensure the metaprogram has the desired type. Any executable Lean definition can be used as a metaprogram. In addition, we can put `meta` in front of a definition to indicate that is a metadefinition. Such definitions need not terminate but cannot be used in non-`meta` contexts. Let us apply our custom tactic: -/ lemma any_goals_solve1_repeat_orelse_example₂ : even 4 ∧ even 7 ∧ even 3 ∧ even 0 := begin intro_and_even, repeat { sorry } end /- ## The Metaprogramming Monad Tactics have access to * the list of **goals** as metavariables (each metavariables has a type and a local context (hypothesis); they can optionally be instantiated); * the **elaborator** (to elaborate expressions and compute their type); * the **environment**, containing all declarations and inductive types; * the **attributes** (e.g., the list of `@[simp]` rules). The tactic monad is an alternative monad, with `fail` and `<|>`. Tactics can also produce trace messages. -/ lemma even_14 : even 14 := by do tactic.trace "Proving evenness …", intro_and_even meta def hello_then_intro_and_even : tactic unit := do tactic.trace "Proving evenness …", intro_and_even lemma even_16 : even 16 := by hello_then_intro_and_even run_cmd tactic.trace "Hello, Metaworld!" meta def trace_goals : tactic unit := do tactic.trace "local context:", ctx ← tactic.local_context, tactic.trace ctx, tactic.trace "target:", P ← tactic.target, tactic.trace P, tactic.trace "all missing proofs:", Hs ← tactic.get_goals, tactic.trace Hs, τs ← list.mmap tactic.infer_type Hs, tactic.trace τs lemma even_18_and_even_20 (α : Type) (a : α) : even 18 ∧ even 20 := by do tactic.applyc ``and.intro, trace_goals, intro_and_even lemma triv_imp (a : Prop) (h : a) : a := by do h ← tactic.get_local `h, tactic.trace "h:", tactic.trace h, tactic.trace "raw h:", tactic.trace (expr.to_raw_fmt h), tactic.trace "type of h:", τ ← tactic.infer_type h, tactic.trace τ, tactic.trace "type of type of h:", υ ← tactic.infer_type τ, tactic.trace υ, tactic.apply h meta def exact_list : list expr → tactic unit | [] := tactic.fail "no matching expression found" | (h :: hs) := do { tactic.trace "trying", tactic.trace h, tactic.exact h } <|> exact_list hs meta def hypothesis : tactic unit := do hs ← tactic.local_context, exact_list hs lemma app_of_app {α : Type} {p : α → Prop} {a : α} (h : p a) : p a := by hypothesis /- ## Names, Expressions, Declarations, and Environments The metaprogramming framework is articulated around five main types: * `tactic` manages the proof state, the global context, and more; * `name` represents a structured name (e.g., `x`, `even.add_two`); * `expr` represents an expression (a term) as an abstract syntax tree; * `declaration` represents a constant declaration, a definition, an axiom, or a lemma; * `environment` stores all the declarations and notations that make up the global context. -/ #print expr #check expr tt -- elaborated expressions #check expr ff -- unelaborated expressions (pre-expressions) #print name #check (expr.const `ℕ [] : expr) #check expr.sort level.zero -- Sort 0, i.e., Prop #check expr.sort (level.succ level.zero) -- Sort 1, i.e., Type #check expr.var 0 -- bound variable with De Bruijn index 0 #check (expr.local_const `uniq_name `pp_name binder_info.default `(ℕ) : expr) #check (expr.mvar `uniq_name `pp_name `(ℕ) : expr) #check (expr.pi `pp_name binder_info.default `(ℕ) (expr.sort level.zero) : expr) #check (expr.lam `pp_name binder_info.default `(ℕ) (expr.var 0) : expr) #check expr.elet #check expr.macro /- We can create literal expressions conveniently using backticks and parentheses: * Expressions with a single backtick must be fully elaborated. * Expressions with two backticks are __pre-expressions__: They may contain some holes to be filled in later, based on some context. * Expressions with three backticks are pre-expressions without name checking. -/ run_cmd do let e : expr := `(list.map (λn : ℕ, n + 1) [1, 2, 3]), tactic.trace e run_cmd do let e : expr := `(list.map _ [1, 2, 3]), -- fails tactic.trace e run_cmd do let e₁ : pexpr := ``(list.map (λn, n + 1) [1, 2, 3]), let e₂ : pexpr := ``(list.map _ [1, 2, 3]), tactic.trace e₁, tactic.trace e₂ run_cmd do let e : pexpr := ```(seattle.washington), tactic.trace e /- We can also create literal names with backticks: * Names with a single backtick, `n, are not checked for existence. * Names with two backticks, ``n, are resolved and checked. -/ run_cmd tactic.trace `and.intro run_cmd tactic.trace `intro_and_even run_cmd tactic.trace `seattle.washington run_cmd tactic.trace ``and.intro run_cmd tactic.trace ``intro_and_even run_cmd tactic.trace ``seattle.washington -- fails /- __Antiquotations__ embed an existing expression in a larger expression. They are announced by the prefix `%%` followed by a name from the current context. Antiquotations are available with one, two, and three backticks: -/ run_cmd do let x : expr := `(2 : ℕ), let e : expr := `(%%x + 1), tactic.trace e run_cmd do let x : expr := `(@id ℕ), let e : pexpr := ``(list.map %%x), tactic.trace e run_cmd do let x : expr := `(@id ℕ), let e : pexpr := ```(a _ %%x), tactic.trace e lemma one_add_two_eq_three : 1 + 2 = 3 := by do `(%%a + %%b = %%c) ← tactic.target, tactic.trace a, tactic.trace b, tactic.trace c, `(@eq %%α %%l %%r) ← tactic.target, tactic.trace α, tactic.trace l, tactic.trace r, tactic.exact `(refl _ : 3 = 3) #print declaration /- The `environment` type is presented as an abstract type, equipped with some operations to query and modify it. The `environment.fold` metafunction iterates over all declarations making up the environment. -/ run_cmd do env ← tactic.get_env, tactic.trace (environment.fold env 0 (λdecl n, n + 1)) /- ## First Example: A Conjuction-Destructing Tactic We define a `destruct_and` tactic that automates the elimination of `∧` in premises, automating proofs such as these: -/ lemma abcd_a (a b c d : Prop) (h : a ∧ (b ∧ c) ∧ d) : a := and.elim_left h lemma abcd_b (a b c d : Prop) (h : a ∧ (b ∧ c) ∧ d) : b := and.elim_left (and.elim_left (and.elim_right h)) lemma abcd_bc (a b c d : Prop) (h : a ∧ (b ∧ c) ∧ d) : b ∧ c := and.elim_left (and.elim_right h) /- Our tactic relies on a helper metafunction, which takes as argument the hypothesis `h` to use as an expression rather than as a name: -/ meta def destruct_and_helper : expr → tactic unit | h := do t ← tactic.infer_type h, match t with | `(%%a ∧ %%b) := tactic.exact h <|> do { ha ← tactic.to_expr ``(and.elim_left %%h), destruct_and_helper ha } <|> do { hb ← tactic.to_expr ``(and.elim_right %%h), destruct_and_helper hb } | _ := tactic.exact h end meta def destruct_and (nam : name) : tactic unit := do h ← tactic.get_local nam, destruct_and_helper h /- Let us check that our tactic works: -/ lemma abc_a (a b c : Prop) (h : a ∧ b ∧ c) : a := by destruct_and `h lemma abc_b (a b c : Prop) (h : a ∧ b ∧ c) : b := by destruct_and `h lemma abc_bc (a b c : Prop) (h : a ∧ b ∧ c) : b ∧ c := by destruct_and `h lemma abc_ac (a b c : Prop) (h : a ∧ b ∧ c) : a ∧ c := by destruct_and `h -- fails /- ## Second Example: A Provability Advisor Next, we implement a `prove_direct` tool that traverses all lemmas in the database and checks whether one of them can be used to prove the current goal. A similar tactic is available in `mathlib` under the name `library_search`. -/ meta def is_theorem : declaration → bool | (declaration.defn _ _ _ _ _ _) := ff | (declaration.thm _ _ _ _) := tt | (declaration.cnst _ _ _ _) := ff | (declaration.ax _ _ _) := tt meta def get_all_theorems : tactic (list name) := do env ← tactic.get_env, pure (environment.fold env [] (λdecl nams, if is_theorem decl then declaration.to_name decl :: nams else nams)) meta def prove_with_name (nam : name) : tactic unit := do tactic.applyc nam ({ md := tactic.transparency.reducible, unify := ff } : tactic.apply_cfg), tactic.all_goals tactic.assumption, pure () meta def prove_direct : tactic unit := do nams ← get_all_theorems, list.mfirst (λnam, do prove_with_name nam, tactic.trace ("directly proved by " ++ to_string nam)) nams lemma nat.eq_symm (x y : ℕ) (h : x = y) : y = x := by prove_direct lemma nat.eq_symm₂ (x y : ℕ) (h : x = y) : y = x := by library_search lemma list.reverse_twice (xs : list ℕ) : list.reverse (list.reverse xs) = xs := by prove_direct lemma list.reverse_twice_symm (xs : list ℕ) : xs = list.reverse (list.reverse xs) := by prove_direct -- fails /- As a small refinement, we propose a version of `prove_direct` that also looks for equalities stated in symmetric form. -/ meta def prove_direct_symm : tactic unit := prove_direct <|> do { tactic.applyc `eq.symm, prove_direct } lemma list.reverse_twice₂ (xs : list ℕ) : list.reverse (list.reverse xs) = xs := by prove_direct_symm lemma list.reverse_twice_symm₂ (xs : list ℕ) : xs = list.reverse (list.reverse xs) := by prove_direct_symm /- ## A Look at Two Predefined Tactics Quite a few of Lean's predefined tactics are implemented as metaprograms and not in C++. We can find these definitions by clicking the name of a construct in Visual Studio Code while holding the control or command key. -/ #check tactic.intro #check tactic.assumption end LoVe
[STATEMENT] lemma (in real_distribution) char_approx3: fixes t assumes integrable_1: "integrable M (\<lambda>x. x)" and integral_1: "expectation (\<lambda>x. x) = 0" and integrable_2: "integrable M (\<lambda>x. x^2)" and integral_2: "variance (\<lambda>x. x) = \<sigma>2" shows "cmod (char M t - (1 - t^2 * \<sigma>2 / 2)) \<le> (t^2 / 6) * expectation (\<lambda>x. min (6 * x^2) (abs t * (abs x)^3) )" [PROOF STATE] proof (prove) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] proof - [PROOF STATE] proof (state) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] note real_distribution.char_approx2 [of M 2 t, simplified] [PROOF STATE] proof (state) this: \<lbrakk>real_distribution M; \<And>k. k \<le> 2 \<Longrightarrow> integrable M (\<lambda>x. x ^ k)\<rbrakk> \<Longrightarrow> cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k)) \<le> t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / fact 3 goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] have [simp]: "prob UNIV = 1" [PROOF STATE] proof (prove) goal (1 subgoal): 1. prob UNIV = 1 [PROOF STEP] by (metis prob_space space_eq_univ) [PROOF STATE] proof (state) this: prob UNIV = 1 goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] from integral_2 [PROOF STATE] proof (chain) picking this: expectation (\<lambda>x. (x - expectation (\<lambda>x. x))\<^sup>2) = \<sigma>2 [PROOF STEP] have [simp]: "expectation (\<lambda>x. x * x) = \<sigma>2" [PROOF STATE] proof (prove) using this: expectation (\<lambda>x. (x - expectation (\<lambda>x. x))\<^sup>2) = \<sigma>2 goal (1 subgoal): 1. expectation (\<lambda>x. x * x) = \<sigma>2 [PROOF STEP] by (simp add: integral_1 numeral_eq_Suc) [PROOF STATE] proof (state) this: expectation (\<lambda>x. x * x) = \<sigma>2 goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] have 1: "k \<le> 2 \<Longrightarrow> integrable M (\<lambda>x. x^k)" for k [PROOF STATE] proof (prove) goal (1 subgoal): 1. k \<le> 2 \<Longrightarrow> integrable M (\<lambda>x. x ^ k) [PROOF STEP] using assms [PROOF STATE] proof (prove) using this: integrable M (\<lambda>x. x) expectation (\<lambda>x. x) = 0 integrable M power2 expectation (\<lambda>x. (x - expectation (\<lambda>x. x))\<^sup>2) = \<sigma>2 goal (1 subgoal): 1. k \<le> 2 \<Longrightarrow> integrable M (\<lambda>x. x ^ k) [PROOF STEP] by (auto simp: eval_nat_numeral le_Suc_eq) [PROOF STATE] proof (state) this: ?k12 \<le> 2 \<Longrightarrow> integrable M (\<lambda>x. x ^ ?k12) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] note char_approx1 [PROOF STATE] proof (state) this: (\<And>k. k \<le> ?n \<Longrightarrow> integrable M (\<lambda>x. x ^ k)) \<Longrightarrow> cmod (char M ?t - (\<Sum>k\<le>?n. (\<i> * complex_of_real ?t) ^ k / fact k * complex_of_real (expectation (\<lambda>x. x ^ k)))) \<le> 2 * \<bar>?t\<bar> ^ ?n / fact ?n * expectation (\<lambda>x. \<bar>x\<bar> ^ ?n) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] note 2 = char_approx1 [of 2 t, OF 1, simplified] [PROOF STATE] proof (state) this: cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k)) \<le> t\<^sup>2 * expectation power2 goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] have "cmod (char M t - (\<Sum>k\<le>2. (\<i> * t) ^ k * (expectation (\<lambda>x. x ^ k)) / (fact k))) \<le> t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / fact (3::nat)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k)) \<le> t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / fact 3 [PROOF STEP] using char_approx2 [of 2 t, OF 1] [PROOF STATE] proof (prove) using this: (\<And>k. k \<le> 2 \<Longrightarrow> k \<le> 2) \<Longrightarrow> cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k / fact k * complex_of_real (expectation (\<lambda>x. x ^ k)))) \<le> \<bar>t\<bar>\<^sup>2 / fact (Suc 2) * expectation (\<lambda>x. min (2 * \<bar>x\<bar>\<^sup>2 * real (Suc 2)) (\<bar>t\<bar> * \<bar>x\<bar> ^ Suc 2)) goal (1 subgoal): 1. cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k)) \<le> t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / fact 3 [PROOF STEP] by simp [PROOF STATE] proof (state) this: cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k)) \<le> t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / fact 3 goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] also [PROOF STATE] proof (state) this: cmod (char M t - (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k)) \<le> t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / fact 3 goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] have "(\<Sum>k\<le>2. (\<i> * t) ^ k * expectation (\<lambda>x. x ^ k) / (fact k)) = 1 - t^2 * \<sigma>2 / 2" [PROOF STATE] proof (prove) goal (1 subgoal): 1. (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k) = complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2) [PROOF STEP] by (simp add: complex_eq_iff numeral_eq_Suc integral_1 Re_divide Im_divide) [PROOF STATE] proof (state) this: (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k) = complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] also [PROOF STATE] proof (state) this: (\<Sum>k\<le>2. (\<i> * complex_of_real t) ^ k * complex_of_real (expectation (\<lambda>x. x ^ k)) / fact k) = complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] have "fact 3 = 6" [PROOF STATE] proof (prove) goal (1 subgoal): 1. fact 3 = (6::'a) [PROOF STEP] by (simp add: eval_nat_numeral) [PROOF STATE] proof (state) this: fact 3 = (6::?'a13) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] also [PROOF STATE] proof (state) this: fact 3 = (6::?'a13) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] have "t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / 6 = t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3))" [PROOF STATE] proof (prove) goal (1 subgoal): 1. t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / 6 = t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] by (simp add: field_simps) [PROOF STATE] proof (state) this: t\<^sup>2 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) / 6 = t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] finally [PROOF STATE] proof (chain) picking this: cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] show ?thesis [PROOF STATE] proof (prove) using this: cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) goal (1 subgoal): 1. cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) [PROOF STEP] . [PROOF STATE] proof (state) this: cmod (char M t - complex_of_real (1 - t\<^sup>2 * \<sigma>2 / 2)) \<le> t\<^sup>2 / 6 * expectation (\<lambda>x. min (6 * x\<^sup>2) (\<bar>t\<bar> * \<bar>x\<bar> ^ 3)) goal: No subgoals! [PROOF STEP] qed
variables (x y z : ℕ) (p : ℕ → Prop) example (h : p ((x + 0) * (0 + y * 1 + z * 0))) : p (x * y) := by { simp at h, assumption }
[STATEMENT] theorem HFail_Inv2b: "\<lbrakk> Inv2b s; HFail s s' p \<rbrakk> \<Longrightarrow> Inv2b s'" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lbrakk>Inv2b s; HFail s s' p\<rbrakk> \<Longrightarrow> Inv2b s' [PROOF STEP] by (auto simp add: Fail_def InitializePhase_def Inv2b_def Inv2b_inner_def hasRead_def)
A set $S$ is homotopy equivalent to the empty set if and only if $S$ is empty.
lemmas continuous_mult [continuous_intros] = bounded_bilinear.continuous [OF bounded_bilinear_mult]
open classical theorem double_neg_elim: ∀ { P }, ¬¬P → P := begin assume P : Prop, assume pfNotNotP : ¬¬P, cases em P with pfP pfnP, show P, from pfP, have f: false := pfNotNotP pfnP, show P, from false.elim f end theorem double_neg_elim': ∀ {P}, (P ∨ ¬P) → ¬¬P → P := begin assume P: Prop, assume h: P ∨ ¬P, assume notnotP: ¬¬P, cases h with a b, show P, from a, show P, from false.elim (notnotP b), end theorem p_b_c' : ∀ P: Prop, (¬P → false) → P := λ P nnP, double_neg_elim nnP theorem proof_by_contrapositive: ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) := begin assume P Q: Prop, assume nqnp: (¬ Q → ¬ P), assume p : P, have nnq : ¬ Q → false := begin assume nq : ¬Q, have np : ¬P := nqnp nq, show false, from np p end, show Q, from double_neg_elim nnq end theorem proof_by_contrapositive': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) := begin assume P Q: Prop, assume nqnp: (¬ Q → ¬ P), assume p : P, have nnq : ¬ Q → false := λ nq : ¬Q, nqnp nq p, show Q, from double_neg_elim nnq end theorem proof_by_contrapositive''''': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) := begin assume (P Q: Prop) (nqnp: ¬ Q → ¬ P) (p: P), exact double_neg_elim (λ nq : ¬Q, nqnp nq p) end theorem proof_by_contrapositive'''': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) := begin assume P Q: Prop, assume nqnp: (¬ Q → ¬ P), assume p : P, exact double_neg_elim (λ nq : ¬Q, nqnp nq p) end theorem proof_by_contrapositive'': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) := λ (P Q : Prop) (nqnp : ¬ Q → ¬ P) (p: P), double_neg_elim (λ nq : ¬ Q, nqnp nq p) theorem proof_by_contrapositive''': ∀ P Q : Prop, (¬ Q → ¬ P) → (P → Q) := λ P Q nqnp p, double_neg_elim (λ nq, nqnp nq p) theorem z: ∀ { a }, ¬¬a → a := λ a b, begin cases em a with c d, exact c, exact false.elim (b d) end variable k: Prop #check em k #check or.by_cases #check or.cases_on theorem double_neg_elim'': ∀ {a}, ¬¬a → a := λ a b, or.cases_on (em a) (λ a, a) (λ c, false.elim (b c)) example {P: Prop} (a: ¬¬P) : double_neg_elim a = double_neg_elim'' a := rfl theorem j: ∀ a b : Prop, (¬ b → ¬ a) → (a → b) := λ a b c d, z (λ e, c e d) variables P Q: Prop variable q : Q -- proof of Q example : P → Q := λ p : P, q example : P → Q := assume p : P, q -- def prime (p : ℕ) := p ≥ 2 ∧ ∀ n, n | p → n = 1 ∨ n = p
lemma unit_factor_monom [simp]: "unit_factor (monom a n) = [:unit_factor a:]"
{-# OPTIONS --warning=error --safe --without-K #-} open import LogicalFormulae module Maybe where data Maybe {a : _} (A : Set a) : Set a where no : Maybe A yes : A → Maybe A joinMaybe : {a : _} → {A : Set a} → Maybe (Maybe A) → Maybe A joinMaybe no = no joinMaybe (yes s) = s bindMaybe : {a b : _} → {A : Set a} → {B : Set b} → Maybe A → (A → Maybe B) → Maybe B bindMaybe no f = no bindMaybe (yes x) f = f x applyMaybe : {a b : _} → {A : Set a} → {B : Set b} → Maybe (A → B) → Maybe A → Maybe B applyMaybe f no = no applyMaybe no (yes x) = no applyMaybe (yes f) (yes x) = yes (f x) yesInjective : {a : _} → {A : Set a} → {x y : A} → (yes x ≡ yes y) → x ≡ y yesInjective {a} {A} {x} {.x} refl = refl mapMaybe : {a b : _} → {A : Set a} → {B : Set b} → (f : A → B) → Maybe A → Maybe B mapMaybe f no = no mapMaybe f (yes x) = yes (f x) defaultValue : {a : _} → {A : Set a} → (default : A) → Maybe A → A defaultValue default no = default defaultValue default (yes x) = x noNotYes : {a : _} {A : Set a} {b : A} → (no ≡ yes b) → False noNotYes () mapMaybePreservesNo : {a b : _} {A : Set a} {B : Set b} {f : A → B} {x : Maybe A} → mapMaybe f x ≡ no → x ≡ no mapMaybePreservesNo {f = f} {no} pr = refl mapMaybePreservesYes : {a b : _} {A : Set a} {B : Set b} {f : A → B} {x : Maybe A} {y : B} → mapMaybe f x ≡ yes y → Sg A (λ z → (x ≡ yes z) && (f z ≡ y)) mapMaybePreservesYes {f = f} {x} {y} map with x mapMaybePreservesYes {f = f} {x} {y} map | yes z = z , (refl ,, yesInjective map)
From Tealeaves Require Export Classes.Monad Classes.Listable.Functor Classes.Setlike.Monad. Import Sets.Notations. #[local] Generalizable Variable T A. (** * Listable monads *) (******************************************************************************) Section ListableMonad. Context (T : Type -> Type) `{Fmap T} `{Return T} `{Join T} `{Tolist T}. Class ListableMonad := { lmon_monad :> Monad T; lmon_functor :> ListableFunctor T; lmon_ret : `(tolist T ∘ ret T = ret list (A:=A)); lmon_join : `(tolist T ∘ join T = join list ∘ tolist T ∘ fmap T (tolist T (A:=A))); }. End ListableMonad. (** ** Instance for [list] *) (******************************************************************************) Section Listable_list. #[program] Instance: ListableMonad list := {| lmon_functor := ListableFunctor_instance_0; |}. Next Obligation. ext t. unfold compose. unfold_ops @Tolist_list. now rewrite (fun_fmap_id list). Qed. End Listable_list. (** * Characterizations of listable monad compatibility conditions *) (******************************************************************************) Section listable_monad_compatibility_conditions. Generalizable All Variables. Context `{Monad T} `{Tolist T} `{! ListableFunctor T}. (** The left-hand condition states that the natural transformation <<ret T>> commutes with taking <<tolist>>, i.e. that <<ret T>> is a list-preserving natural transformation. The right-hand condition is one half of the statement that <<tolist>> forms a monad homomorphism. *) Lemma tolist_ret_iff {A} : (tolist T ∘ ret T = tolist (fun x => x) (A:=A)) <-> (tolist T ∘ ret T = ret list (A:=A)). Proof with auto. split... Qed. (** The left-hand condition states that the natural transformation <<join T>> is <<tolist>>-preserving. The right-hand condition is one half of the statement that <<tolist>> forms a monad homomorphism. *) Lemma tolist_join_iff {A} : `(tolist T ∘ join T (A:=A) = tolist (T ∘ T)) <-> `(tolist T ∘ join T (A:=A) = join list ∘ tolist T ∘ fmap T (tolist T)). Proof with auto. split... Qed. Theorem listable_monad_compatibility_spec : Monad_Hom T list (@tolist T _) <-> ListPreservingTransformation (@ret T _) /\ ListPreservingTransformation (@join T _). Proof with auto. split. - introv mhom. inverts mhom. inverts mhom_domain. split. + constructor... introv. symmetry. rewrite tolist_ret_iff... + constructor... introv. symmetry. apply tolist_join_iff... - intros [h1 h2]. inverts h1. inverts h2. constructor; try typeclasses eauto. + introv. rewrite <- tolist_ret_iff... + introv. rewrite <- tolist_join_iff... Qed. Theorem listable_monad_compatibility_spec2 : Monad_Hom T list (@tolist T _) <-> ListableMonad T. Proof. rewrite listable_monad_compatibility_spec. split. - intros [[] []]. constructor; try typeclasses eauto; eauto. - intros []. split. + constructor; try typeclasses eauto; eauto. + constructor; try typeclasses eauto; eauto. Qed. End listable_monad_compatibility_conditions. (** * Listable monads *) (******************************************************************************) (** * Properties of listable monads *) (******************************************************************************) Section ListableMonad_theory. Context `{ListableMonad T}. Corollary tolist_ret A (a : A) : tolist T (ret T a) = ret list a. Proof. intros. compose near a on left. now rewrite (lmon_ret T). Qed. Corollary tolist_join A (t : T (T A)) : tolist T (join T t) = join list (tolist T (fmap T (tolist T) t)). Proof. intros. compose near t on left. now rewrite (lmon_join T). Qed. Theorem return_injective : forall A (a b : A), ret T a = ret T b -> a = b. Proof. introv. intro heq. assert (lemma : tolist T (ret T a) = tolist T (ret T b)). { now rewrite heq. } rewrite 2(tolist_ret) in lemma. now inverts lemma. Qed. End ListableMonad_theory. (** ** Listable monads are set-like *) (******************************************************************************) Section ListableMonad_setlike. Context `{ListableMonad T}. Theorem toset_ret_Listable : `(toset T ∘ ret T (A:=A) = ret set). Proof. intros. unfold toset, Toset_Tolist, compose. ext a. rewrite tolist_ret. compose near a on left. rewrite toset_ret_list. reflexivity. Qed. Theorem toset_join_Listable : `(toset T ∘ join T = join set ∘ toset T ∘ fmap T (toset T (A:=A))). Proof. intros. unfold toset, Toset_Tolist. rewrite <- (fun_fmap_fmap T). reassociate -> on right. change_right (join (A:=A) set ∘ toset list ∘ (tolist T ∘ fmap T (toset list)) ∘ fmap T (tolist T)). rewrite <- natural. reassociate <- on right. rewrite <- toset_join_list. reassociate -> on left. now rewrite (lmon_join T). Qed. #[export] Instance SetlikeMonad_Listable : SetlikeMonad T := {| xmon_ret := toset_ret_Listable; xmon_join := toset_join_Listable; xmon_ret_injective := return_injective; |}. End ListableMonad_setlike. (* This needs the Kleisli-style presentation available (** * A counter-example of a respectfulness property. *) (******************************************************************************) (** [list] is a counterexample to the strong respectfulness condition for <<bind>>. *) Example f1 : nat -> list nat := fun n => match n with | 0 => [4 ; 5] | 1 => [ 6 ] | _ => [ 42 ] end. Example f2 : nat -> list nat := fun n => match n with | 0 => [ 4 ] | 1 => [ 5 ; 6 ] | _ => [ 42 ] end. Definition l := [ 0 ; 1 ]. Import Monad.ToKleisli. Import Monad.ToKleisli.Operation. Lemma bind_f1_f2_equal : bind list f1 l = bind list f2 l. reflexivity. Qed. Lemma f1_f2_not_equal : ~(forall x, x ∈ l -> f1 x = f2 x). Proof. intro hyp. assert (0 ∈ l) by (cbn; now left). specialize (hyp 0 ltac:(auto)). cbv in hyp. now inverts hyp. Qed. Lemma list_not_free : ~ (forall (l : list nat), bind list f1 l = bind list f2 l -> (forall x, x ∈ l -> f1 x = f2 x)). Proof. intro H. specialize (H l bind_f1_f2_equal). apply f1_f2_not_equal. apply H. Qed. *)
module Nat1 where data ℕ : Set where zero : ℕ succ : ℕ → ℕ _+_ : ℕ → ℕ → ℕ zero + b = b succ a + b = succ (a + b) open import Equality one = succ zero two = succ one three = succ two 0-is-id : ∀ (n : ℕ) → (n + zero) ≡ n 0-is-id zero = begin (zero + zero) ≈ zero by definition ∎ 0-is-id (succ y) = begin (succ y + zero) ≈ succ (y + zero) by definition ≈ succ y by cong succ (0-is-id y) ∎ +-assoc : ∀ (a b c : ℕ) → (a + b) + c ≡ a + (b + c) +-assoc zero b c = definition +-assoc (succ a) b c = begin ((succ a + b) + c) ≈ succ (a + b) + c by definition ≈ succ ((a + b) + c) by definition ≈ succ (a + (b + c)) by cong succ (+-assoc a b c) ≈ succ a + (b + c) by definition ∎ {- +-assoc zero b c = definition +-assoc (succ a) b c = begin ((succ a + b) + c) ≈ succ (a + b) + c by definition ≈ succ ((a + b) + c) by definition ≈ succ (a + (b + c)) by cong succ (+-assoc a b c) ≈ succ a + (b + c) by definition ∎ -}
lemma content_0 [simp]: "content 0 = 0"
Good news if you are an Amazon/eCom marketer! Launching today at 11am EDT is a new Wordpress store theme called EcomBox which allows you to create profitable eCom/Amazon affiliate store in any niche faster. Apparel and accessories are the fastest growing sectors in eCommerce, and with EcomBox you can tap into these 2 niches faster than before. I'll send you an email when the early bird door opens in just moments away from now. In the meantime, do check out the theme demo here.
{-# OPTIONS --exact-split #-} {-# OPTIONS --no-sized-types #-} {-# OPTIONS --no-universe-polymorphism #-} {-# OPTIONS --without-K #-} module FOT.FOTC.Data.Conat.PropertiesI where open import FOTC.Base open import FOTC.Data.Conat open import FOTC.Data.Conat.PropertiesI open import FOTC.Data.Nat ------------------------------------------------------------------------------ -- 25 April 2014, Failed with --without-K. -- {-# TERMINATING #-} Conat→N : ∀ {n} → Conat n → N n Conat→N Cn with Conat-out Cn ... | inj₁ prf = subst N (sym prf) nzero ... | inj₂ (n' , refl , Cn') = nsucc (Conat→N Cn')
informal statement If $x$ is an element of infinite order in $G$, prove that the elements $x^{n}, n \in \mathbb{Z}$ are all distinct.formal statement theorem exercise_1_6_4 : is_empty (multiplicative ℝ ≃* multiplicative ℂ) :=
||| The content of this module is based on the paper ||| Applications of Applicative Proof Search ||| by Liam O'Connor ||| ||| The main difference is that we use `Colist1` for the type of ||| generators rather than `Stream`. This allows us to avoid generating ||| many duplicates when dealing with finite types which are common in ||| programming (Bool) but even more so in dependently typed programming ||| (Vect 0, Fin (S n), etc.). module Search.Generator import Data.Colist import Data.Colist1 import Data.Fin import Data.List import Data.Stream import Data.Vect ------------------------------------------------------------------------ -- Interface ||| A generator for a given type is a non-empty colist of values of that ||| type. public export interface Generator a where generate : Colist1 a ------------------------------------------------------------------------ -- Implementations -- Finite types ||| ALL of the natural numbers public export Generator Nat where generate = fromStream nats ||| ALL of the booleans public export Generator Bool where generate = True ::: [False] ||| ALL of the Fins public export {n : Nat} -> Generator (Fin (S n)) where generate = fromList1 (allFins n) -- Polymorphic generators ||| We typically want to generate a generator for a unit-terminated right-nested ||| product so we have this special case that keeps the generator minimal. public export Generator a => Generator (a, ()) where generate = map (,()) generate ||| Put two generators together by exploring the plane they define. ||| This uses Cantor's zig zag traversal public export (Generator a, Generator b) => Generator (a, b) where generate = plane generate (\ _ => generate) ||| Put two generators together by exploring the plane they define. ||| This uses Cantor's zig zag traversal public export {0 b : a -> Type} -> (Generator a, (x : a) -> Generator (b x)) => Generator (x : a ** b x) where generate = plane generate (\ x => generate) ||| Build entire vectors of values public export {n : Nat} -> Generator a => Generator (Vect n a) where generate = case n of Z => [] ::: [] S n => map (uncurry (::)) generate ||| Generate arbitrary lists of values ||| Departing from the paper, to avoid having infinitely many copies of ||| the empty list, we handle the case `n = 0` separately. public export Generator a => Generator (List a) where generate = [] ::: forget (planeWith listy generate vectors) where listy : (n : Nat) -> Vect (S n) a -> List a listy _ = toList vectors : (n : Nat) -> Colist1 (Vect (S n) a) vectors n = generate
-------------------------------------------------------------------------------- -- This is part of Agda Inference Systems {-# OPTIONS --guardedness #-} module is-lib.InfSys {𝓁} where open import is-lib.InfSys.Base {𝓁} public open import is-lib.InfSys.Induction {𝓁} public open import is-lib.InfSys.Coinduction {𝓁} public open import is-lib.InfSys.FlexCoinduction {𝓁} public open MetaRule public open FinMetaRule public open IS public
But , in <unk> darkness , guess each sweet
# This file was generated, do not modify it. # hide misclassification_rate(mode.(ŷ), ytrain)
{-# OPTIONS --rewriting #-} module NewEquations where open import Common.Prelude hiding (map; _++_) open import Common.Equality infixr 5 _++_ map : ∀ {A B : Set} → (A → B) → List A → List B map f [] = [] map f (x ∷ xs) = (f x) ∷ (map f xs) _++_ : ∀ {A : Set} → List A → List A → List A [] ++ ys = ys (x ∷ xs) ++ ys = x ∷ (xs ++ ys) fold : ∀ {A B : Set} → (A → B → B) → B → List A → B fold f v [] = v fold f v (x ∷ xs) = f x (fold f v xs) ++-[] : ∀ {A} {xs : List A} → xs ++ [] ≡ xs ++-[] {xs = []} = refl ++-[] {xs = x ∷ xs} = cong (_∷_ x) ++-[] ++-assoc : ∀ {A} {xs ys zs : List A} → (xs ++ ys) ++ zs ≡ xs ++ (ys ++ zs) ++-assoc {xs = []} = refl ++-assoc {xs = x ∷ xs} = cong (_∷_ x) (++-assoc {xs = xs}) map-id : ∀ {A} {xs : List A} → map (λ x → x) xs ≡ xs map-id {xs = []} = refl map-id {xs = x ∷ xs} = cong (_∷_ x) map-id map-fuse : ∀ {A B C} {f : B → C} {g : A → B} {xs : List A} → map f (map g xs) ≡ map (λ x → f (g x)) xs map-fuse {xs = []} = refl map-fuse {xs = x ∷ xs} = cong (_∷_ _) map-fuse map-++ : ∀ {A B} {f : A → B} {xs ys : List A} → map f (xs ++ ys) ≡ (map f xs) ++ (map f ys) map-++ {xs = []} = refl map-++ {xs = x ∷ xs} = cong (_∷_ _) (map-++ {xs = xs}) fold-map : ∀ {A B C} {f : A → B} {c : B → C → C} {n : C} {xs : List A} → fold c n (map f xs) ≡ fold (λ x → c (f x)) n xs fold-map {xs = []} = refl fold-map {c = c} {xs = x ∷ xs} = cong (c _) (fold-map {xs = xs}) fold-++ : ∀ {A B} {c : A → B → B} {n : B} {xs ys : List A} → fold c n (xs ++ ys) ≡ fold c (fold c n ys) xs fold-++ {xs = []} = refl fold-++ {c = c} {xs = x ∷ xs} = cong (c _) (fold-++ {xs = xs}) {-# BUILTIN REWRITE _≡_ #-} {-# REWRITE ++-[] #-} {-# REWRITE ++-assoc #-} {-# REWRITE map-id #-} {-# REWRITE map-fuse #-} {-# REWRITE map-++ #-} {-# REWRITE fold-map #-} {-# REWRITE fold-++ #-} record _×_ (A B : Set) : Set where constructor _,_ field fst : A snd : B swap : ∀ {A B} → A × B → B × A swap (x , y) = y , x test₁ : ∀ {A B} {xs : List (A × B)} → map swap (map swap xs) ≡ xs test₁ = refl
-- vim: set ft=idris sw=2 ts=2: -- -- perfect_number.idr -- Calculate 'perfect' numbers in the Idris programming language -- module PerfectNumber -- predicate to check whether given number is perfect export is_perfect : (Integral a, Ord a) => a -> Bool is_perfect n = if n > 0 then loop n 1 0 else False where loop : a -> a -> a -> Bool loop n i sum = if n == i then (sum == n) else if (n `mod` i) == 0 then loop n (i + 1) (sum + i) else loop n (i + 1) sum -- generate 'perfect' numbers until given limit export perfect_numbers : Nat -> List Nat perfect_numbers n = filter (\x => is_perfect x) $ natRange n
universes u def f {α : Type u} [BEq α] (xs : List α) (y : α) : α := do for x in xs do if x == y then return x return y structure S := (key val : Nat) instance : BEq S := ⟨fun a b => a.key == b.key⟩ theorem ex1 : f (α := S) [⟨1, 2⟩, ⟨3, 4⟩, ⟨5, 6⟩] ⟨3, 0⟩ = ⟨3, 4⟩ := rfl theorem ex2 : f (α := S) [⟨1, 2⟩, ⟨3, 4⟩, ⟨5, 6⟩] ⟨4, 10⟩ = ⟨4, 10⟩ := rfl
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad The order relation on the integers. -/ import Mathlib.Init.Data.Int.Basic import Mathlib.Algebra.Ring.Basic namespace Int theorem nonneg_def {a : ℤ} : NonNeg a ↔ ∃ n : ℕ, a = n := ⟨fun ⟨n⟩ => ⟨n, rfl⟩, fun h => match a, h with | _, ⟨n, rfl⟩ => ⟨n⟩⟩ lemma NonNeg.elim {a : ℤ} : NonNeg a → ∃ n : ℕ, a = n := nonneg_def.1 lemma nonneg_or_nonneg_neg (a : ℤ) : NonNeg a ∨ NonNeg (-a) := match a with | ofNat n => Or.inl ⟨_⟩ | negSucc n => Or.inr ⟨_⟩ theorem le_def (a b : ℤ) : a ≤ b ↔ NonNeg (b - a) := Iff.refl _ theorem lt_iff_add_one_le (a b : ℤ) : a < b ↔ (a+1) ≤ b := Iff.refl _ theorem le.intro_sub {a b : ℤ} (n : ℕ) (h : b - a = n) : a ≤ b := by simp [le_def, h]; constructor attribute [local simp] Int.sub_eq_add_neg Int.add_assoc Int.add_right_neg Int.add_left_neg Int.zero_add Int.add_zero Int.neg_add Int.neg_neg Int.neg_zero theorem le.intro {a b : ℤ} (n : ℕ) (h : a + n = b) : a ≤ b := le.intro_sub n $ by rw [← h, Int.add_comm]; simp theorem le.dest_sub {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, b - a = n := nonneg_def.1 h theorem le.dest {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, a + n = b := let ⟨n, h₁⟩ := le.dest_sub h ⟨n, by rw [← h₁, Int.add_comm]; simp⟩ protected theorem le_total (a b : ℤ) : a ≤ b ∨ b ≤ a := (nonneg_or_nonneg_neg (b - a)).imp_right fun H => by rwa [(by simp [Int.add_comm] : -(b - a) = a - b)] at H @[simp, norm_cast] theorem ofNat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := ⟨fun h => let ⟨k, hk⟩ := le.dest h Nat.le.intro $ Int.ofNat.inj $ (Int.ofNat_add m k).trans hk, fun h => let ⟨k, (hk : m + k = n)⟩ := Nat.le.dest h le.intro k (by rw [← hk]; rfl)⟩ theorem ofNat_zero_le (n : ℕ) : 0 ≤ (↑n : ℤ) := ofNat_le.2 n.zero_le theorem eq_ofNat_of_zero_le {a : ℤ} (h : 0 ≤ a) : ∃ n : ℕ, a = n := by have t := le.dest_sub h; simp at t; exact t theorem eq_succ_of_zero_lt {a : ℤ} (h : 0 < a) : ∃ n : ℕ, a = n.succ := let ⟨n, (h : 1 + n = a)⟩ := le.dest h ⟨n, by rw [Nat.add_comm] at h <;> exact h.symm⟩ theorem lt_add_succ (a : ℤ) (n : ℕ) : a < a + Nat.succ n := le.intro n $ by rw [Int.add_comm, Int.add_left_comm]; rfl theorem lt.intro {a b : ℤ} {n : ℕ} (h : a + Nat.succ n = b) : a < b := h ▸ lt_add_succ a n theorem lt.dest {a b : ℤ} (h : a < b) : ∃ n : ℕ, a + Nat.succ n = b := (le.dest h).imp fun n h => by rwa [Int.add_comm, Int.add_left_comm] at h @[simp, norm_cast] theorem ofNat_lt {n m : ℕ} : (↑n : ℤ) < ↑m ↔ n < m := by rw [lt_iff_add_one_le, ← Nat.cast_succ, ofNat_le]; rfl theorem ofNat_nonneg (n : ℕ) : 0 ≤ ofNat n := ⟨_⟩ theorem ofNat_succ_pos (n : Nat) : 0 < (Nat.succ n : ℤ) := ofNat_lt.2 $ Nat.succ_pos _ protected theorem le_refl (a : ℤ) : a ≤ a := le.intro _ (Int.add_zero a) protected theorem le_trans {a b c : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c := let ⟨n, hn⟩ := le.dest h₁; let ⟨m, hm⟩ := le.dest h₂ le.intro (n + m) $ by rw [← hm, ← hn, Int.add_assoc, Nat.cast_add] protected theorem le_antisymm {a b : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ a) : a = b := by let ⟨n, hn⟩ := le.dest h₁; let ⟨m, hm⟩ := le.dest h₂ have := hn; rw [← hm, Int.add_assoc, ← Nat.cast_add] at this have := Int.ofNat.inj $ Int.add_left_cancel $ this.trans (Int.add_zero _).symm rw [← hn, Nat.eq_zero_of_add_eq_zero_left this, Nat.cast_zero, Int.add_zero a] protected theorem lt_irrefl (a : ℤ) : ¬a < a := fun H => let ⟨n, hn⟩ := lt.dest H have : (a+Nat.succ n) = a+0 := by rw [hn, Int.add_zero] have : Nat.succ n = 0 := Int.coe_nat_inj (Int.add_left_cancel this) show False from Nat.succ_ne_zero _ this protected theorem ne_of_lt {a b : ℤ} (h : a < b) : a ≠ b := fun e => by cases e; exact Int.lt_irrefl _ h theorem le_of_lt {a b : ℤ} (h : a < b) : a ≤ b := let ⟨n, hn⟩ := lt.dest h; le.intro _ hn protected theorem lt_iff_le_and_ne {a b : ℤ} : a < b ↔ a ≤ b ∧ a ≠ b := by refine ⟨fun h => ⟨le_of_lt h, Int.ne_of_lt h⟩, fun ⟨aleb, aneb⟩ => ?_⟩ let ⟨n, hn⟩ := le.dest aleb have : n ≠ 0 := aneb.imp fun this' => by rw [← hn, this', Nat.cast_zero, Int.add_zero] exact lt.intro $ by rwa [← Nat.succ_pred_eq_of_pos (Nat.pos_of_ne_zero this)] at hn theorem lt_succ (a : ℤ) : a < a + 1 := Int.le_refl (a + 1) protected theorem add_le_add_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c + a ≤ c + b := let ⟨n, hn⟩ := le.dest h; le.intro n $ by rw [Int.add_assoc, hn] protected theorem add_lt_add_left {a b : ℤ} (h : a < b) (c : ℤ) : c + a < c + b := by refine Int.lt_iff_le_and_ne.2 ⟨Int.add_le_add_left (le_of_lt h) _, fun heq => ?_⟩ exact Int.lt_irrefl b $ by rwa [Int.add_left_cancel heq] at h protected theorem mul_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b := by let ⟨n, hn⟩ := eq_ofNat_of_zero_le ha let ⟨m, hm⟩ := eq_ofNat_of_zero_le hb rw [hn, hm, ← Nat.cast_mul]; exact ofNat_nonneg _ protected theorem mul_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a * b := by let ⟨n, hn⟩ := eq_succ_of_zero_lt ha let ⟨m, hm⟩ := eq_succ_of_zero_lt hb rw [hn, hm, ← Nat.cast_mul]; exact ofNat_succ_pos _ protected theorem zero_lt_one : (0 : ℤ) < 1 := ⟨_⟩ protected theorem lt_iff_le_not_le {a b : ℤ} : a < b ↔ a ≤ b ∧ ¬b ≤ a := by rw [Int.lt_iff_le_and_ne] constructor <;> refine fun ⟨h, h'⟩ => ⟨h, h'.imp fun h' => ?_⟩ · exact Int.le_antisymm h h' · subst h'; apply Int.le_refl instance : LinearOrder Int where le := (·≤·) le_refl := Int.le_refl le_trans := @Int.le_trans le_antisymm := @Int.le_antisymm lt := (·<·) lt_iff_le_not_le := @Int.lt_iff_le_not_le le_total := Int.le_total decidable_eq := by infer_instance decidable_le := by infer_instance decidable_lt := by infer_instance theorem eq_natAbs_of_zero_le {a : ℤ} (h : 0 ≤ a) : a = natAbs a := by let ⟨n, e⟩ := eq_ofNat_of_zero_le h rw [e]; rfl theorem le_natAbs {a : ℤ} : a ≤ natAbs a := Or.elim (le_total 0 a) (fun h => by rw [eq_natAbs_of_zero_le h]; apply Int.le_refl) fun h => le_trans h (ofNat_zero_le _) theorem neg_succ_lt_zero (n : ℕ) : -[1+ n] < 0 := lt_of_not_ge $ fun h => by let ⟨m, h⟩ := eq_ofNat_of_zero_le h contradiction theorem eq_neg_succ_of_lt_zero : ∀ {a : ℤ}, a < 0 → ∃ n : ℕ, a = -[1+ n] | (n : ℕ), h => absurd h (not_lt_of_ge (ofNat_zero_le _)) | -[1+ n], h => ⟨n, rfl⟩ protected theorem eq_neg_of_eq_neg {a b : ℤ} (h : a = -b) : b = -a := by rw [h, Int.neg_neg] protected theorem neg_add_cancel_left (a b : ℤ) : -a + (a + b) = b := by rw [← Int.add_assoc, Int.add_left_neg, Int.zero_add] protected theorem add_neg_cancel_left (a b : ℤ) : a + (-a + b) = b := by rw [← Int.add_assoc, Int.add_right_neg, Int.zero_add] protected theorem add_neg_cancel_right (a b : ℤ) : a + b + -b = a := by rw [Int.add_assoc, Int.add_right_neg, Int.add_zero] protected theorem neg_add_cancel_right (a b : ℤ) : a + -b + b = a := by rw [Int.add_assoc, Int.add_left_neg, Int.add_zero] protected theorem sub_self (a : ℤ) : a - a = 0 := by rw [Int.sub_eq_add_neg, Int.add_right_neg] protected theorem sub_eq_zero_of_eq {a b : ℤ} (h : a = b) : a - b = 0 := by rw [h, Int.sub_self] protected theorem eq_of_sub_eq_zero {a b : ℤ} (h : a - b = 0) : a = b := by have : 0 + b = b := by rw [Int.zero_add] have : a - b + b = b := by rwa [h] rwa [Int.sub_eq_add_neg, Int.neg_add_cancel_right] at this protected theorem sub_eq_zero_iff_eq {a b : ℤ} : a - b = 0 ↔ a = b := ⟨Int.eq_of_sub_eq_zero, Int.sub_eq_zero_of_eq⟩ @[simp] protected theorem neg_eq_of_add_eq_zero {a b : ℤ} (h : a + b = 0) : -a = b := by rw [← Int.add_zero (-a), ← h, ← Int.add_assoc, Int.add_left_neg, Int.zero_add] protected theorem neg_mul_eq_neg_mul (a b : ℤ) : -(a * b) = -a * b := Int.neg_eq_of_add_eq_zero $ by rw [← Int.distrib_right, Int.add_right_neg, Int.zero_mul] protected theorem neg_mul_eq_mul_neg (a b : ℤ) : -(a * b) = a * -b := Int.neg_eq_of_add_eq_zero $ by rw [← Int.distrib_left, Int.add_right_neg, Int.mul_zero] theorem neg_mul_eq_neg_mul_symm (a b : ℤ) : -a * b = -(a * b) := (Int.neg_mul_eq_neg_mul a b).symm theorem mul_neg_eq_neg_mul_symm (a b : ℤ) : a * -b = -(a * b) := (Int.neg_mul_eq_mul_neg a b).symm attribute [local simp] neg_mul_eq_neg_mul_symm mul_neg_eq_neg_mul_symm protected theorem neg_mul_neg (a b : ℤ) : -a * -b = a * b := by simp protected theorem neg_mul_comm (a b : ℤ) : -a * b = a * -b := by simp protected theorem mul_sub (a b c : ℤ) : a * (b - c) = a * b - a * c := calc a * (b - c) = a * b + a * -c := Int.distrib_left a b (-c) _ = a * b - a * c := by simp protected theorem sub_mul (a b c : ℤ) : (a - b) * c = a * c - b * c := calc (a - b) * c = a * c + -b * c := Int.distrib_right a (-b) c _ = a * c - b * c := by simp protected theorem le_of_add_le_add_left {a b c : ℤ} (h : a + b ≤ a + c) : b ≤ c := by have : -a + (a + b) ≤ -a + (a + c) := Int.add_le_add_left h _ simp [Int.neg_add_cancel_left] at this assumption protected theorem lt_of_add_lt_add_left {a b c : ℤ} (h : a + b < a + c) : b < c := by have : -a + (a + b) < -a + (a + c) := Int.add_lt_add_left h _ simp [Int.neg_add_cancel_left] at this assumption protected theorem add_le_add_right {a b : ℤ} (h : a ≤ b) (c : ℤ) : a + c ≤ b + c := Int.add_comm c a ▸ Int.add_comm c b ▸ Int.add_le_add_left h c protected theorem add_lt_add_right {a b : ℤ} (h : a < b) (c : ℤ) : a + c < b + c := by rw [Int.add_comm a c, Int.add_comm b c] exact Int.add_lt_add_left h c protected theorem add_le_add {a b c d : ℤ} (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d := le_trans (Int.add_le_add_right h₁ c) (Int.add_le_add_left h₂ b) protected theorem le_add_of_nonneg_right {a b : ℤ} (h : 0 ≤ b) : a ≤ a + b := by have : a + b ≥ a + 0 := Int.add_le_add_left h a rwa [Int.add_zero] at this protected theorem le_add_of_nonneg_left {a b : ℤ} (h : 0 ≤ b) : a ≤ b + a := by have : 0 + a ≤ b + a := Int.add_le_add_right h a rwa [Int.zero_add] at this protected theorem add_lt_add {a b c d : ℤ} (h₁ : a < b) (h₂ : c < d) : a + c < b + d := lt_trans (Int.add_lt_add_right h₁ c) (Int.add_lt_add_left h₂ b) protected theorem add_lt_add_of_le_of_lt {a b c d : ℤ} (h₁ : a ≤ b) (h₂ : c < d) : a + c < b + d := lt_of_le_of_lt (Int.add_le_add_right h₁ c) (Int.add_lt_add_left h₂ b) protected theorem add_lt_add_of_lt_of_le {a b c d : ℤ} (h₁ : a < b) (h₂ : c ≤ d) : a + c < b + d := lt_of_lt_of_le (Int.add_lt_add_right h₁ c) (Int.add_le_add_left h₂ b) protected theorem lt_add_of_pos_right (a : ℤ) {b : ℤ} (h : 0 < b) : a < a + b := by have : a + 0 < a + b := Int.add_lt_add_left h a rwa [Int.add_zero] at this protected theorem lt_add_of_pos_left (a : ℤ) {b : ℤ} (h : 0 < b) : a < b + a := by have : 0 + a < b + a := Int.add_lt_add_right h a rwa [Int.zero_add] at this protected theorem le_of_add_le_add_right {a b c : ℤ} (h : a + b ≤ c + b) : a ≤ c := Int.le_of_add_le_add_left (a := b) $ by rwa [Int.add_comm b a, Int.add_comm b c] protected theorem lt_of_add_lt_add_right {a b c : ℤ} (h : a + b < c + b) : a < c := Int.lt_of_add_lt_add_left (a := b) $ by rwa [Int.add_comm b a, Int.add_comm b c] protected theorem add_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b := Int.zero_add 0 ▸ Int.add_le_add ha hb protected theorem add_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a + b := Int.zero_add 0 ▸ Int.add_lt_add ha hb protected theorem add_pos_of_pos_of_nonneg {a b : ℤ} (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b := Int.zero_add 0 ▸ Int.add_lt_add_of_lt_of_le ha hb protected theorem add_pos_of_nonneg_of_pos {a b : ℤ} (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b := Int.zero_add 0 ▸ Int.add_lt_add_of_le_of_lt ha hb protected theorem add_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 := Int.zero_add 0 ▸ Int.add_le_add ha hb protected theorem add_neg {a b : ℤ} (ha : a < 0) (hb : b < 0) : a + b < 0 := Int.zero_add 0 ▸ Int.add_lt_add ha hb protected theorem add_neg_of_neg_of_nonpos {a b : ℤ} (ha : a < 0) (hb : b ≤ 0) : a + b < 0 := Int.zero_add 0 ▸ Int.add_lt_add_of_lt_of_le ha hb protected theorem add_neg_of_nonpos_of_neg {a b : ℤ} (ha : a ≤ 0) (hb : b < 0) : a + b < 0 := Int.zero_add 0 ▸ Int.add_lt_add_of_le_of_lt ha hb protected theorem lt_add_of_le_of_pos {a b c : ℤ} (hbc : b ≤ c) (ha : 0 < a) : b < c + a := Int.add_zero b ▸ Int.add_lt_add_of_le_of_lt hbc ha protected theorem sub_add_cancel (a b : ℤ) : a - b + b = a := Int.neg_add_cancel_right a b protected theorem add_sub_cancel (a b : ℤ) : a + b - b = a := Int.add_neg_cancel_right a b protected theorem add_sub_assoc (a b c : ℤ) : a + b - c = a + (b - c) := by rw [Int.sub_eq_add_neg, Int.add_assoc, ← Int.sub_eq_add_neg] protected theorem neg_le_neg {a b : ℤ} (h : a ≤ b) : -b ≤ -a := by have : 0 ≤ -a + b := Int.add_left_neg a ▸ Int.add_le_add_left h (-a) have : 0 + -b ≤ -a + b + -b := Int.add_le_add_right this (-b) rwa [Int.add_neg_cancel_right, Int.zero_add] at this protected theorem le_of_neg_le_neg {a b : ℤ} (h : -b ≤ -a) : a ≤ b := suffices - -a ≤ - -b by simp [Int.neg_neg] at this; assumption Int.neg_le_neg h protected theorem nonneg_of_neg_nonpos {a : ℤ} (h : -a ≤ 0) : 0 ≤ a := Int.le_of_neg_le_neg $ by rwa [Int.neg_zero] protected theorem neg_nonpos_of_nonneg {a : ℤ} (h : 0 ≤ a) : -a ≤ 0 := by have : -a ≤ -0 := Int.neg_le_neg h rwa [Int.neg_zero] at this protected theorem nonpos_of_neg_nonneg {a : ℤ} (h : 0 ≤ -a) : a ≤ 0 := Int.le_of_neg_le_neg $ by rwa [Int.neg_zero] protected theorem neg_nonneg_of_nonpos {a : ℤ} (h : a ≤ 0) : 0 ≤ -a := by have : -0 ≤ -a := Int.neg_le_neg h rwa [Int.neg_zero] at this protected theorem neg_lt_neg {a b : ℤ} (h : a < b) : -b < -a := by have : 0 < -a + b := Int.add_left_neg a ▸ Int.add_lt_add_left h (-a) have : 0 + -b < -a + b + -b := Int.add_lt_add_right this (-b) rwa [Int.add_neg_cancel_right, Int.zero_add] at this protected theorem lt_of_neg_lt_neg {a b : ℤ} (h : -b < -a) : a < b := Int.neg_neg a ▸ Int.neg_neg b ▸ Int.neg_lt_neg h protected theorem pos_of_neg_neg {a : ℤ} (h : -a < 0) : 0 < a := Int.lt_of_neg_lt_neg $ by rwa [Int.neg_zero] protected theorem neg_neg_of_pos {a : ℤ} (h : 0 < a) : -a < 0 := by have : -a < -0 := Int.neg_lt_neg h rwa [Int.neg_zero] at this protected theorem neg_of_neg_pos {a : ℤ} (h : 0 < -a) : a < 0 := have : -0 < -a := by rwa [Int.neg_zero] Int.lt_of_neg_lt_neg this protected theorem neg_pos_of_neg {a : ℤ} (h : a < 0) : 0 < -a := by have : -0 < -a := Int.neg_lt_neg h rwa [Int.neg_zero] at this protected theorem le_neg_of_le_neg {a b : ℤ} (h : a ≤ -b) : b ≤ -a := by have h := Int.neg_le_neg h rwa [Int.neg_neg] at h protected theorem neg_le_of_neg_le {a b : ℤ} (h : -a ≤ b) : -b ≤ a := by have h := Int.neg_le_neg h rwa [Int.neg_neg] at h protected theorem lt_neg_of_lt_neg {a b : ℤ} (h : a < -b) : b < -a := by have h := Int.neg_lt_neg h rwa [Int.neg_neg] at h protected theorem neg_lt_of_neg_lt {a b : ℤ} (h : -a < b) : -b < a := by have h := Int.neg_lt_neg h rwa [Int.neg_neg] at h protected theorem sub_nonneg_of_le {a b : ℤ} (h : b ≤ a) : 0 ≤ a - b := by have h := Int.add_le_add_right h (-b) rwa [Int.add_right_neg] at h protected theorem le_of_sub_nonneg {a b : ℤ} (h : 0 ≤ a - b) : b ≤ a := by have h := Int.add_le_add_right h b rwa [Int.sub_add_cancel, Int.zero_add] at h protected theorem sub_nonpos_of_le {a b : ℤ} (h : a ≤ b) : a - b ≤ 0 := by have h := Int.add_le_add_right h (-b) rwa [Int.add_right_neg] at h protected theorem le_of_sub_nonpos {a b : ℤ} (h : a - b ≤ 0) : a ≤ b := by have h := Int.add_le_add_right h b rwa [Int.sub_add_cancel, Int.zero_add] at h protected theorem sub_pos_of_lt {a b : ℤ} (h : b < a) : 0 < a - b := by have h := Int.add_lt_add_right h (-b) rwa [Int.add_right_neg] at h protected theorem lt_of_sub_pos {a b : ℤ} (h : 0 < a - b) : b < a := by have h := Int.add_lt_add_right h b rwa [Int.sub_add_cancel, Int.zero_add] at h protected theorem sub_neg_of_lt {a b : ℤ} (h : a < b) : a - b < 0 := by have h := Int.add_lt_add_right h (-b) rwa [Int.add_right_neg] at h protected theorem lt_of_sub_neg {a b : ℤ} (h : a - b < 0) : a < b := by have h := Int.add_lt_add_right h b rwa [Int.sub_add_cancel, Int.zero_add] at h protected theorem add_le_of_le_neg_add {a b c : ℤ} (h : b ≤ -a + c) : a + b ≤ c := by have h := Int.add_le_add_left h a rwa [Int.add_neg_cancel_left] at h protected theorem le_neg_add_of_add_le {a b c : ℤ} (h : a + b ≤ c) : b ≤ -a + c := by have h := Int.add_le_add_left h (-a) rwa [Int.neg_add_cancel_left] at h protected theorem add_le_of_le_sub_left {a b c : ℤ} (h : b ≤ c - a) : a + b ≤ c := by have h := Int.add_le_add_left h a rwa [← Int.add_sub_assoc, Int.add_comm a c, Int.add_sub_cancel] at h protected theorem le_sub_left_of_add_le {a b c : ℤ} (h : a + b ≤ c) : b ≤ c - a := by have h := Int.add_le_add_right h (-a) rwa [Int.add_comm a b, Int.add_neg_cancel_right] at h protected theorem add_le_of_le_sub_right {a b c : ℤ} (h : a ≤ c - b) : a + b ≤ c := by have h := Int.add_le_add_right h b rwa [Int.sub_add_cancel] at h protected theorem le_sub_right_of_add_le {a b c : ℤ} (h : a + b ≤ c) : a ≤ c - b := by have h := Int.add_le_add_right h (-b) rwa [Int.add_neg_cancel_right] at h protected theorem le_add_of_neg_add_le {a b c : ℤ} (h : -b + a ≤ c) : a ≤ b + c := by have h := Int.add_le_add_left h b rwa [Int.add_neg_cancel_left] at h protected theorem neg_add_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -b + a ≤ c := by have h := Int.add_le_add_left h (-b) rwa [Int.neg_add_cancel_left] at h protected theorem le_add_of_sub_left_le {a b c : ℤ} (h : a - b ≤ c) : a ≤ b + c := by have h := Int.add_le_add_right h b rwa [Int.sub_add_cancel, Int.add_comm] at h protected theorem sub_left_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : a - b ≤ c := by have h := Int.add_le_add_right h (-b) rwa [Int.add_comm b c, Int.add_neg_cancel_right] at h protected theorem le_add_of_sub_right_le {a b c : ℤ} (h : a - c ≤ b) : a ≤ b + c := by have h := Int.add_le_add_right h c rwa [Int.sub_add_cancel] at h protected theorem sub_right_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : a - c ≤ b := by have h := Int.add_le_add_right h (-c) rwa [Int.add_neg_cancel_right] at h protected theorem le_add_of_neg_add_le_left {a b c : ℤ} (h : -b + a ≤ c) : a ≤ b + c := by rw [Int.add_comm] at h exact Int.le_add_of_sub_left_le h protected theorem neg_add_le_left_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -b + a ≤ c := by rw [Int.add_comm] exact Int.sub_left_le_of_le_add h protected theorem le_add_of_neg_add_le_right {a b c : ℤ} (h : -c + a ≤ b) : a ≤ b + c := by rw [Int.add_comm] at h exact Int.le_add_of_sub_right_le h protected theorem neg_add_le_right_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -c + a ≤ b := by rw [Int.add_comm] at h exact Int.neg_add_le_left_of_le_add h protected theorem le_add_of_neg_le_sub_left {a b c : ℤ} (h : -a ≤ b - c) : c ≤ a + b := Int.le_add_of_neg_add_le_left (Int.add_le_of_le_sub_right h) protected theorem neg_le_sub_left_of_le_add {a b c : ℤ} (h : c ≤ a + b) : -a ≤ b - c := by have h := Int.le_neg_add_of_add_le (Int.sub_left_le_of_le_add h) rwa [Int.add_comm] at h protected theorem le_add_of_neg_le_sub_right {a b c : ℤ} (h : -b ≤ a - c) : c ≤ a + b := Int.le_add_of_sub_right_le (Int.add_le_of_le_sub_left h) protected theorem neg_le_sub_right_of_le_add {a b c : ℤ} (h : c ≤ a + b) : -b ≤ a - c := Int.le_sub_left_of_add_le (Int.sub_right_le_of_le_add h) protected theorem sub_le_of_sub_le {a b c : ℤ} (h : a - b ≤ c) : a - c ≤ b := Int.sub_left_le_of_le_add (Int.le_add_of_sub_right_le h) protected theorem sub_le_sub_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c - b ≤ c - a := Int.add_le_add_left (Int.neg_le_neg h) c protected theorem sub_le_sub_right {a b : ℤ} (h : a ≤ b) (c : ℤ) : a - c ≤ b - c := Int.add_le_add_right h (-c) protected theorem sub_le_sub {a b c d : ℤ} (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c := Int.add_le_add hab (Int.neg_le_neg hcd) protected theorem add_lt_of_lt_neg_add {a b c : ℤ} (h : b < -a + c) : a + b < c := by have h := Int.add_lt_add_left h a rwa [Int.add_neg_cancel_left] at h protected theorem lt_neg_add_of_add_lt {a b c : ℤ} (h : a + b < c) : b < -a + c := by have h := Int.add_lt_add_left h (-a) rwa [Int.neg_add_cancel_left] at h protected theorem add_lt_of_lt_sub_left {a b c : ℤ} (h : b < c - a) : a + b < c := by have h := Int.add_lt_add_left h a rwa [← Int.add_sub_assoc, Int.add_comm a c, Int.add_sub_cancel] at h protected theorem lt_sub_left_of_add_lt {a b c : ℤ} (h : a + b < c) : b < c - a := by have h := Int.add_lt_add_right h (-a) rwa [Int.add_comm a b, Int.add_neg_cancel_right] at h protected theorem add_lt_of_lt_sub_right {a b c : ℤ} (h : a < c - b) : a + b < c := by have h := Int.add_lt_add_right h b rwa [Int.sub_add_cancel] at h protected theorem lt_sub_right_of_add_lt {a b c : ℤ} (h : a + b < c) : a < c - b := by have h := Int.add_lt_add_right h (-b) rwa [Int.add_neg_cancel_right] at h protected theorem lt_add_of_neg_add_lt {a b c : ℤ} (h : -b + a < c) : a < b + c := by have h := Int.add_lt_add_left h b rwa [Int.add_neg_cancel_left] at h protected theorem neg_add_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : -b + a < c := by have h := Int.add_lt_add_left h (-b) rwa [Int.neg_add_cancel_left] at h protected theorem lt_add_of_sub_left_lt {a b c : ℤ} (h : a - b < c) : a < b + c := by have h := Int.add_lt_add_right h b rwa [Int.sub_add_cancel, Int.add_comm] at h protected theorem sub_left_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : a - b < c := by have h := Int.add_lt_add_right h (-b) rwa [Int.add_comm b c, Int.add_neg_cancel_right] at h protected theorem lt_add_of_sub_right_lt {a b c : ℤ} (h : a - c < b) : a < b + c := by have h := Int.add_lt_add_right h c rwa [Int.sub_add_cancel] at h protected theorem sub_right_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : a - c < b := by have h := Int.add_lt_add_right h (-c) rwa [Int.add_neg_cancel_right] at h protected theorem lt_add_of_neg_add_lt_left {a b c : ℤ} (h : -b + a < c) : a < b + c := by rw [Int.add_comm] at h exact Int.lt_add_of_sub_left_lt h protected theorem neg_add_lt_left_of_lt_add {a b c : ℤ} (h : a < b + c) : -b + a < c := by rw [Int.add_comm] exact Int.sub_left_lt_of_lt_add h protected theorem lt_add_of_neg_add_lt_right {a b c : ℤ} (h : -c + a < b) : a < b + c := by rw [Int.add_comm] at h exact Int.lt_add_of_sub_right_lt h protected theorem neg_add_lt_right_of_lt_add {a b c : ℤ} (h : a < b + c) : -c + a < b := by rw [Int.add_comm] at h exact Int.neg_add_lt_left_of_lt_add h protected theorem lt_add_of_neg_lt_sub_left {a b c : ℤ} (h : -a < b - c) : c < a + b := Int.lt_add_of_neg_add_lt_left (Int.add_lt_of_lt_sub_right h) protected theorem neg_lt_sub_left_of_lt_add {a b c : ℤ} (h : c < a + b) : -a < b - c := by have h := Int.lt_neg_add_of_add_lt (Int.sub_left_lt_of_lt_add h) rwa [Int.add_comm] at h protected theorem lt_add_of_neg_lt_sub_right {a b c : ℤ} (h : -b < a - c) : c < a + b := Int.lt_add_of_sub_right_lt (Int.add_lt_of_lt_sub_left h) protected theorem neg_lt_sub_right_of_lt_add {a b c : ℤ} (h : c < a + b) : -b < a - c := Int.lt_sub_left_of_add_lt (Int.sub_right_lt_of_lt_add h) protected theorem sub_lt_of_sub_lt {a b c : ℤ} (h : a - b < c) : a - c < b := Int.sub_left_lt_of_lt_add (Int.lt_add_of_sub_right_lt h) protected theorem sub_lt_sub_left {a b : ℤ} (h : a < b) (c : ℤ) : c - b < c - a := Int.add_lt_add_left (Int.neg_lt_neg h) c protected theorem sub_lt_sub_right {a b : ℤ} (h : a < b) (c : ℤ) : a - c < b - c := Int.add_lt_add_right h (-c) protected theorem sub_lt_sub {a b c d : ℤ} (hab : a < b) (hcd : c < d) : a - d < b - c := Int.add_lt_add hab (Int.neg_lt_neg hcd) protected theorem sub_lt_sub_of_le_of_lt {a b c d : ℤ} (hab : a ≤ b) (hcd : c < d) : a - d < b - c := Int.add_lt_add_of_le_of_lt hab (Int.neg_lt_neg hcd) protected theorem sub_lt_sub_of_lt_of_le {a b c d : ℤ} (hab : a < b) (hcd : c ≤ d) : a - d < b - c := Int.add_lt_add_of_lt_of_le hab (Int.neg_le_neg hcd) protected theorem sub_le_self (a : ℤ) {b : ℤ} (h : 0 ≤ b) : a - b ≤ a := calc a + -b ≤ a + 0 := Int.add_le_add_left (Int.neg_nonpos_of_nonneg h) _ _ = a := by rw [Int.add_zero] protected theorem sub_lt_self (a : ℤ) {b : ℤ} (h : 0 < b) : a - b < a := calc a + -b < a + 0 := Int.add_lt_add_left (Int.neg_neg_of_pos h) _ _ = a := by rw [Int.add_zero] protected theorem add_le_add_three {a b c d e f : ℤ} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a + b + c ≤ d + e + f := by apply le_trans apply Int.add_le_add apply Int.add_le_add assumption' apply le_refl protected theorem mul_lt_mul_of_pos_left {a b c : ℤ} (h₁ : a < b) (h₂ : 0 < c) : c * a < c * b := by have : 0 < c * (b - a) := Int.mul_pos h₂ (Int.sub_pos_of_lt h₁) rw [Int.mul_sub] at this exact Int.lt_of_sub_pos this protected theorem mul_lt_mul_of_pos_right {a b c : ℤ} (h₁ : a < b) (h₂ : 0 < c) : a * c < b * c := by have : 0 < b - a := Int.sub_pos_of_lt h₁ have : 0 < (b - a) * c := Int.mul_pos this h₂ rw [Int.sub_mul] at this exact Int.lt_of_sub_pos this protected theorem mul_le_mul_of_nonneg_left {a b c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b := by by_cases hba : b ≤ a; { simp [le_antisymm hba h₁] } by_cases hc0 : c ≤ 0; { simp [le_antisymm hc0 h₂, Int.zero_mul] } exact (le_not_le_of_lt (Int.mul_lt_mul_of_pos_left (lt_of_le_not_le h₁ hba) (lt_of_le_not_le h₂ hc0))).left protected theorem mul_le_mul_of_nonneg_right {a b c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c := by by_cases hba : b ≤ a; { simp [le_antisymm hba h₁] } by_cases hc0 : c ≤ 0; { simp [le_antisymm hc0 h₂, Int.mul_zero] } exact (le_not_le_of_lt (Int.mul_lt_mul_of_pos_right (lt_of_le_not_le h₁ hba) (lt_of_le_not_le h₂ hc0))).left protected theorem mul_le_mul {a b c d : ℤ} (hac : a ≤ c) (hbd : b ≤ d) (nn_b : 0 ≤ b) (nn_c : 0 ≤ c) : a * b ≤ c * d := calc a * b ≤ c * b := Int.mul_le_mul_of_nonneg_right hac nn_b _ ≤ c * d := Int.mul_le_mul_of_nonneg_left hbd nn_c protected theorem mul_nonpos_of_nonneg_of_nonpos {a b : ℤ} (ha : 0 ≤ a) (hb : b ≤ 0) : a * b ≤ 0 := by have h : a * b ≤ a * 0 := Int.mul_le_mul_of_nonneg_left hb ha rwa [Int.mul_zero] at h protected theorem mul_nonpos_of_nonpos_of_nonneg {a b : ℤ} (ha : a ≤ 0) (hb : 0 ≤ b) : a * b ≤ 0 := by have h : a * b ≤ 0 * b := Int.mul_le_mul_of_nonneg_right ha hb rwa [Int.zero_mul] at h protected theorem mul_lt_mul {a b c d : ℤ} (hac : a < c) (hbd : b ≤ d) (pos_b : 0 < b) (nn_c : 0 ≤ c) : a * b < c * d := calc a * b < c * b := Int.mul_lt_mul_of_pos_right hac pos_b _ ≤ c * d := Int.mul_le_mul_of_nonneg_left hbd nn_c protected theorem mul_lt_mul' {a b c d : ℤ} (h1 : a ≤ c) (h2 : b < d) (h3 : 0 ≤ b) (h4 : 0 < c) : a * b < c * d := calc a * b ≤ c * b := Int.mul_le_mul_of_nonneg_right h1 h3 _ < c * d := Int.mul_lt_mul_of_pos_left h2 h4 protected theorem mul_neg_of_pos_of_neg {a b : ℤ} (ha : 0 < a) (hb : b < 0) : a * b < 0 := by have h : a * b < a * 0 := Int.mul_lt_mul_of_pos_left hb ha rwa [Int.mul_zero] at h protected theorem mul_neg_of_neg_of_pos {a b : ℤ} (ha : a < 0) (hb : 0 < b) : a * b < 0 := by have h : a * b < 0 * b := Int.mul_lt_mul_of_pos_right ha hb rwa [Int.zero_mul] at h protected theorem mul_le_mul_of_nonpos_right {a b c : ℤ} (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c := have : -c ≥ 0 := Int.neg_nonneg_of_nonpos hc have : b * -c ≤ a * -c := Int.mul_le_mul_of_nonneg_right h this have : -(b * c) ≤ -(a * c) := by rwa [← Int.neg_mul_eq_mul_neg, ← Int.neg_mul_eq_mul_neg] at this Int.le_of_neg_le_neg this protected theorem mul_nonneg_of_nonpos_of_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b := by have : 0 * b ≤ a * b := Int.mul_le_mul_of_nonpos_right ha hb rwa [Int.zero_mul] at this protected theorem mul_lt_mul_of_neg_left {a b c : ℤ} (h : b < a) (hc : c < 0) : c * a < c * b := have : -c > 0 := Int.neg_pos_of_neg hc have : -c * b < -c * a := Int.mul_lt_mul_of_pos_left h this have : -(c * b) < -(c * a) := by rwa [← Int.neg_mul_eq_neg_mul, ← Int.neg_mul_eq_neg_mul] at this Int.lt_of_neg_lt_neg this protected theorem mul_lt_mul_of_neg_right {a b c : ℤ} (h : b < a) (hc : c < 0) : a * c < b * c := have : -c > 0 := Int.neg_pos_of_neg hc have : b * -c < a * -c := Int.mul_lt_mul_of_pos_right h this have : -(b * c) < -(a * c) := by rwa [← Int.neg_mul_eq_mul_neg, ← Int.neg_mul_eq_mul_neg] at this Int.lt_of_neg_lt_neg this protected theorem mul_pos_of_neg_of_neg {a b : ℤ} (ha : a < 0) (hb : b < 0) : 0 < a * b := by have : 0 * b < a * b := Int.mul_lt_mul_of_neg_right ha hb rwa [Int.zero_mul] at this protected theorem mul_self_le_mul_self {a b : ℤ} (h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b := Int.mul_le_mul h2 h2 h1 (le_trans h1 h2) protected theorem mul_self_lt_mul_self {a b : ℤ} (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b := Int.mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2) theorem exists_eq_neg_ofNat {a : ℤ} (H : a ≤ 0) : ∃ n : ℕ, a = -(n : ℤ) := let ⟨n, h⟩ := eq_ofNat_of_zero_le (Int.neg_nonneg_of_nonpos H) ⟨n, Int.eq_neg_of_eq_neg h.symm⟩ theorem natAbs_of_nonneg {a : ℤ} (H : 0 ≤ a) : (natAbs a : ℤ) = a := match a, eq_ofNat_of_zero_le H with | _, ⟨n, rfl⟩ => rfl theorem ofNat_natAbs_of_nonpos {a : ℤ} (H : a ≤ 0) : (natAbs a : ℤ) = -a := by rw [← natAbs_neg, natAbs_of_nonneg (Int.neg_nonneg_of_nonpos H)] theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b := H theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b := H theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 := Int.add_le_add_right H 1 theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b := Int.le_of_add_le_add_right H theorem sub_one_lt_of_le {a b : ℤ} (H : a ≤ b) : a - 1 < b := Int.sub_right_lt_of_lt_add $ lt_add_one_of_le H theorem le_of_sub_one_lt {a b : ℤ} (H : a - 1 < b) : a ≤ b := le_of_lt_add_one $ Int.lt_add_of_sub_right_lt H theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 := Int.le_sub_right_of_add_le H theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b := Int.add_le_of_le_sub_right H theorem sign_of_succ (n : Nat) : sign (Nat.succ n) = 1 := rfl theorem sign_eq_one_of_pos {a : ℤ} (h : 0 < a) : sign a = 1 := match a, eq_succ_of_zero_lt h with | _, ⟨n, rfl⟩ => rfl theorem sign_eq_neg_one_of_neg {a : ℤ} (h : a < 0) : sign a = -1 := match a, eq_neg_succ_of_lt_zero h with | _, ⟨n, rfl⟩ => rfl theorem eq_zero_of_sign_eq_zero : ∀ {a : ℤ}, sign a = 0 → a = 0 | 0, _ => rfl theorem pos_of_sign_eq_one : ∀ {a : ℤ}, sign a = 1 → 0 < a | (n + 1 : ℕ), _ => ofNat_lt.2 (Nat.succ_pos _) theorem neg_of_sign_eq_neg_one : ∀ {a : ℤ}, sign a = -1 → a < 0 | (n + 1 : ℕ), h => nomatch h | 0, h => nomatch h | -[1+ n], _ => neg_succ_lt_zero _ theorem sign_eq_one_iff_pos (a : ℤ) : sign a = 1 ↔ 0 < a := ⟨pos_of_sign_eq_one, sign_eq_one_of_pos⟩ theorem sign_eq_neg_one_iff_neg (a : ℤ) : sign a = -1 ↔ a < 0 := ⟨neg_of_sign_eq_neg_one, sign_eq_neg_one_of_neg⟩ theorem sign_eq_zero_iff_zero (a : ℤ) : sign a = 0 ↔ a = 0 := ⟨eq_zero_of_sign_eq_zero, fun h => by rw [h, sign_zero]⟩ protected protected theorem eq_of_mul_eq_mul_right {a b c : ℤ} (ha : a ≠ 0) (h : b * a = c * a) : b = c := have : b * a - c * a = 0 := Int.sub_eq_zero_of_eq h have : (b - c) * a = 0 := by rw [Int.sub_mul, this] have : b - c = 0 := (Int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right ha Int.eq_of_sub_eq_zero this protected theorem eq_of_mul_eq_mul_left {a b c : ℤ} (ha : a ≠ 0) (h : a * b = a * c) : b = c := have : a * b - a * c = 0 := Int.sub_eq_zero_of_eq h have : a * (b - c) = 0 := by rw [Int.mul_sub, this] have : b - c = 0 := (Int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_left ha Int.eq_of_sub_eq_zero this theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 := Int.eq_of_mul_eq_mul_right Hpos $ by rw [Int.one_mul, H] theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 := Int.eq_of_mul_eq_mul_left Hpos $ by rw [Int.mul_one, H] lemma ofNat_natAbs_eq_of_nonneg : ∀ a : ℤ, 0 ≤ a → Int.ofNat (Int.natAbs a) = a | (ofNat n), h => rfl | -[1+ n], h => absurd (neg_succ_lt_zero n) (not_lt_of_ge h) end Int
module CFT.DependentLens public export record DepLens (s, a : Type) (t : s -> Type) (b : a -> Type) where constructor MkDepLens get : s -> a set : (es : s) -> b (get es) -> t es
theory Ex046 imports Main begin theorem "(A \<and> (A \<longrightarrow> \<not>A)) \<Longrightarrow> (A \<and> (B \<longrightarrow> \<not>A))" proof - assume a:"A \<and> (A \<longrightarrow> \<not>A)" hence b:"A \<longrightarrow> \<not>A" by (rule conjE) from a have c:A by (rule conjE) with b have "\<not>A" by (rule impE) with c have False by contradiction thus ?thesis by (rule FalseE) qed
record R (X : Set) : Set₁ where field P : X → Set f : ∀ {x : X} → P x → P x open R {{…}} test : ∀ {X} {{r : R X}} {x : X} → P x → P x test p = f p -- WAS: instance search fails with several candidates left -- SHOULD: succeed
lemma open_empty [continuous_intros, intro, simp]: "open {}"
[GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 ⊢ g • s = s [PROOFSTEP] suffices ∀ {g' : G} (_ : g' ^ n ^ j = 1), g' • s ⊆ s by refine' le_antisymm (this hg) _ conv_lhs => rw [← smul_inv_smul g s] replace hg : g⁻¹ ^ n ^ j = 1 · rw [inv_zpow, hg, inv_one] simpa only [le_eq_subset, set_smul_subset_set_smul_iff] using this hg [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s ⊢ g • s = s [PROOFSTEP] refine' le_antisymm (this hg) _ [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s ⊢ s ≤ g • s [PROOFSTEP] conv_lhs => rw [← smul_inv_smul g s] [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s | s [PROOFSTEP] rw [← smul_inv_smul g s] [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s | s [PROOFSTEP] rw [← smul_inv_smul g s] [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s | s [PROOFSTEP] rw [← smul_inv_smul g s] [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s ⊢ g • g⁻¹ • s ≤ g • s [PROOFSTEP] replace hg : g⁻¹ ^ n ^ j = 1 [GOAL] case hg G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s ⊢ g⁻¹ ^ n ^ j = 1 [PROOFSTEP] rw [inv_zpow, hg, inv_one] [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ this : ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s hg : g⁻¹ ^ n ^ j = 1 ⊢ g • g⁻¹ • s ≤ g • s [PROOFSTEP] simpa only [le_eq_subset, set_smul_subset_set_smul_iff] using this hg [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 ⊢ ∀ {g' : G}, g' ^ n ^ j = 1 → g' • s ⊆ s [PROOFSTEP] rw [(IsFixedPt.preimage_iterate hs j : (zpowGroupHom n)^[j] ⁻¹' s = s).symm] [GOAL] G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 ⊢ ∀ {g' : G}, g' ^ n ^ j = 1 → g' • (fun x => x ^ n)^[j] ⁻¹' s ⊆ (fun x => x ^ n)^[j] ⁻¹' s [PROOFSTEP] rintro g' hg' - ⟨y, hy, rfl⟩ [GOAL] case intro.intro G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 g' : G hg' : g' ^ n ^ j = 1 y : G hy : y ∈ (fun x => x ^ n)^[j] ⁻¹' s ⊢ (fun x => g' • x) y ∈ (fun x => x ^ n)^[j] ⁻¹' s [PROOFSTEP] change (zpowGroupHom n)^[j] (g' * y) ∈ s [GOAL] case intro.intro G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 g' : G hg' : g' ^ n ^ j = 1 y : G hy : y ∈ (fun x => x ^ n)^[j] ⁻¹' s ⊢ (↑(zpowGroupHom n))^[j] (g' * y) ∈ s [PROOFSTEP] replace hg' : (zpowGroupHom n)^[j] g' = 1 [GOAL] case hg' G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 g' : G hg' : g' ^ n ^ j = 1 y : G hy : y ∈ (fun x => x ^ n)^[j] ⁻¹' s ⊢ (↑(zpowGroupHom n))^[j] g' = 1 [PROOFSTEP] simpa [zpowGroupHom] [GOAL] case intro.intro G : Type u_1 inst✝ : CommGroup G n : ℤ s : Set G hs : (fun x => x ^ n) ⁻¹' s = s g : G j : ℕ hg : g ^ n ^ j = 1 g' y : G hy : y ∈ (fun x => x ^ n)^[j] ⁻¹' s hg' : (↑(zpowGroupHom n))^[j] g' = 1 ⊢ (↑(zpowGroupHom n))^[j] (g' * y) ∈ s [PROOFSTEP] rwa [iterate_map_mul, hg', one_mul]
namespace list universes u variables {α : Type u} {l l₁ l₂: list α} {a : α} @[simp] lemma rev_nil : @list.reverse α [] = [] := begin unfold reverse, unfold reverse_core end @[simp] lemma rev_core_nil : reverse_core [] l = l := rfl @[simp] lemma rev_core_cons : reverse_core (a::l₁) l = reverse_core l₁ (a::l) := rfl @[simp] lemma rev_core_length : (list.length $ list.reverse_core l₁ l₂) = (list.length l₁) + (list.length l₂) := @well_founded.recursion (list α) _ (measure_wf (length)) (λ l₁, ∀ l₂, (list.length $ list.reverse_core (l₁) l₂) = (list.length (l₁)) + (list.length l₂)) (l₁) (λ l₃, list.rec_on l₃ (by simp) (λ h l₃ i p l₂, begin simp, have p₂ : length (reverse_core l₃ (h::l₂)) = length l₃ + length (h::l₂), apply p, focus {simp [measure, inv_image], rw add_comm, apply nat.lt_succ_self }, rw p₂, simp end ) ) l₂ @[simp] lemma l_rev {t : list α} : list.length (list.reverse t) = list.length t := by simp [reverse] end list
[GOAL] V : Type u G : SimpleGraph V K L L' M : Set V ⊢ Function.Injective supp [PROOFSTEP] refine' ConnectedComponent.ind₂ _ [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V ⊢ ∀ (v w : ↑Kᶜ), supp (connectedComponentMk (induce Kᶜ G) v) = supp (connectedComponentMk (induce Kᶜ G) w) → connectedComponentMk (induce Kᶜ G) v = connectedComponentMk (induce Kᶜ G) w [PROOFSTEP] rintro ⟨v, hv⟩ ⟨w, hw⟩ h [GOAL] case mk.mk V : Type u G : SimpleGraph V K L L' M : Set V v : V hv : v ∈ Kᶜ w : V hw : w ∈ Kᶜ h : supp (connectedComponentMk (induce Kᶜ G) { val := v, property := hv }) = supp (connectedComponentMk (induce Kᶜ G) { val := w, property := hw }) ⊢ connectedComponentMk (induce Kᶜ G) { val := v, property := hv } = connectedComponentMk (induce Kᶜ G) { val := w, property := hw } [PROOFSTEP] simp only [Set.ext_iff, ConnectedComponent.eq, Set.mem_setOf_eq, ComponentCompl.supp] at h ⊢ [GOAL] case mk.mk V : Type u G : SimpleGraph V K L L' M : Set V v : V hv : v ∈ Kᶜ w : V hw : w ∈ Kᶜ h : ∀ (x : V), (∃ h, Reachable (induce Kᶜ G) { val := x, property := (_ : ¬x ∈ K) } { val := v, property := hv }) ↔ ∃ h, Reachable (induce Kᶜ G) { val := x, property := (_ : ¬x ∈ K) } { val := w, property := hw } ⊢ Reachable (induce Kᶜ G) { val := v, property := hv } { val := w, property := hw } [PROOFSTEP] exact ((h v).mp ⟨hv, Reachable.refl _⟩).choose_spec [GOAL] V : Type u G✝ : SimpleGraph V K L L' M : Set V G : SimpleGraph V v w : V vK : ¬v ∈ K wK : ¬w ∈ K a : Adj G v w ⊢ componentComplMk G vK = componentComplMk G wK [PROOFSTEP] rw [ConnectedComponent.eq] [GOAL] V : Type u G✝ : SimpleGraph V K L L' M : Set V G : SimpleGraph V v w : V vK : ¬v ∈ K wK : ¬w ∈ K a : Adj G v w ⊢ Reachable (induce Kᶜ G) { val := v, property := vK } { val := w, property := wK } [PROOFSTEP] apply Adj.reachable [GOAL] case h V : Type u G✝ : SimpleGraph V K L L' M : Set V G : SimpleGraph V v w : V vK : ¬v ∈ K wK : ¬w ∈ K a : Adj G v w ⊢ Adj (induce Kᶜ G) { val := v, property := vK } { val := w, property := wK } [PROOFSTEP] exact a [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V β : Sort u_1 f : ⦃v : V⦄ → ¬v ∈ K → β h : ∀ ⦃v w : V⦄ (hv : ¬v ∈ K) (hw : ¬w ∈ K), Adj G v w → f hv = f hw v w : ↑Kᶜ p : Walk (induce Kᶜ G) v w ⊢ Walk.IsPath p → (fun vv => f (_ : ↑vv ∈ Kᶜ)) v = (fun vv => f (_ : ↑vv ∈ Kᶜ)) w [PROOFSTEP] induction' p with _ u v w a q ih [GOAL] case nil V : Type u G : SimpleGraph V K L L' M : Set V β : Sort u_1 f : ⦃v : V⦄ → ¬v ∈ K → β h : ∀ ⦃v w : V⦄ (hv : ¬v ∈ K) (hw : ¬w ∈ K), Adj G v w → f hv = f hw v w u✝ : ↑Kᶜ ⊢ Walk.IsPath Walk.nil → (fun vv => f (_ : ↑vv ∈ Kᶜ)) u✝ = (fun vv => f (_ : ↑vv ∈ Kᶜ)) u✝ [PROOFSTEP] rintro _ [GOAL] case nil V : Type u G : SimpleGraph V K L L' M : Set V β : Sort u_1 f : ⦃v : V⦄ → ¬v ∈ K → β h : ∀ ⦃v w : V⦄ (hv : ¬v ∈ K) (hw : ¬w ∈ K), Adj G v w → f hv = f hw v w u✝ : ↑Kᶜ a✝ : Walk.IsPath Walk.nil ⊢ (fun vv => f (_ : ↑vv ∈ Kᶜ)) u✝ = (fun vv => f (_ : ↑vv ∈ Kᶜ)) u✝ [PROOFSTEP] rfl [GOAL] case cons V : Type u G : SimpleGraph V K L L' M : Set V β : Sort u_1 f : ⦃v : V⦄ → ¬v ∈ K → β h : ∀ ⦃v w : V⦄ (hv : ¬v ∈ K) (hw : ¬w ∈ K), Adj G v w → f hv = f hw v✝ w✝ u v w : ↑Kᶜ a : Adj (induce Kᶜ G) u v q : Walk (induce Kᶜ G) v w ih : Walk.IsPath q → (fun vv => f (_ : ↑vv ∈ Kᶜ)) v = (fun vv => f (_ : ↑vv ∈ Kᶜ)) w ⊢ Walk.IsPath (Walk.cons a q) → (fun vv => f (_ : ↑vv ∈ Kᶜ)) u = (fun vv => f (_ : ↑vv ∈ Kᶜ)) w [PROOFSTEP] rintro h' [GOAL] case cons V : Type u G : SimpleGraph V K L L' M : Set V β : Sort u_1 f : ⦃v : V⦄ → ¬v ∈ K → β h : ∀ ⦃v w : V⦄ (hv : ¬v ∈ K) (hw : ¬w ∈ K), Adj G v w → f hv = f hw v✝ w✝ u v w : ↑Kᶜ a : Adj (induce Kᶜ G) u v q : Walk (induce Kᶜ G) v w ih : Walk.IsPath q → (fun vv => f (_ : ↑vv ∈ Kᶜ)) v = (fun vv => f (_ : ↑vv ∈ Kᶜ)) w h' : Walk.IsPath (Walk.cons a q) ⊢ (fun vv => f (_ : ↑vv ∈ Kᶜ)) u = (fun vv => f (_ : ↑vv ∈ Kᶜ)) w [PROOFSTEP] exact (h u.prop v.prop a).trans (ih h'.of_cons) [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V β : ComponentCompl G K → Prop f : ∀ ⦃v : V⦄ (hv : ¬v ∈ K), β (componentComplMk G hv) ⊢ ∀ (C : ComponentCompl G K), β C [PROOFSTEP] apply ConnectedComponent.ind [GOAL] case h V : Type u G : SimpleGraph V K L L' M : Set V β : ComponentCompl G K → Prop f : ∀ ⦃v : V⦄ (hv : ¬v ∈ K), β (componentComplMk G hv) ⊢ ∀ (v : ↑Kᶜ), β (connectedComponentMk (induce Kᶜ G) v) [PROOFSTEP] exact fun ⟨v, vnK⟩ => f vnK [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G K ⊢ Disjoint K ↑C [PROOFSTEP] rw [Set.disjoint_iff] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G K ⊢ K ∩ ↑C ⊆ ∅ [PROOFSTEP] exact fun v ⟨vK, vC⟩ => vC.choose vK [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V ⊢ Pairwise fun C D => Disjoint ↑C ↑D [PROOFSTEP] rintro C D ne [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C D : ComponentCompl G K ne : C ≠ D ⊢ Disjoint ↑C ↑D [PROOFSTEP] rw [Set.disjoint_iff] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C D : ComponentCompl G K ne : C ≠ D ⊢ ↑C ∩ ↑D ⊆ ∅ [PROOFSTEP] exact fun u ⟨uC, uD⟩ => ne (uC.choose_spec.symm.trans uD.choose_spec) [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G K c d : V x✝ : c ∈ C dnK : ¬d ∈ K cd : Adj G c d cnK : ¬c ∈ K h : componentComplMk G cnK = C ⊢ componentComplMk G dnK = C [PROOFSTEP] rw [← h, ConnectedComponent.eq] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G K c d : V x✝ : c ∈ C dnK : ¬d ∈ K cd : Adj G c d cnK : ¬c ∈ K h : componentComplMk G cnK = C ⊢ Reachable (induce Kᶜ G) { val := d, property := dnK } { val := c, property := cnK } [PROOFSTEP] exact Adj.reachable cd.symm [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K ⊢ ∀ (C : ComponentCompl G K), ∃ ck, ck.fst ∈ C ∧ ck.snd ∈ K ∧ Adj G ck.fst ck.snd [PROOFSTEP] refine' ComponentCompl.ind fun v vnK => _ [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K ⊢ ∃ ck, ck.fst ∈ componentComplMk G vnK ∧ ck.snd ∈ K ∧ Adj G ck.fst ck.snd [PROOFSTEP] let C : G.ComponentCompl K := G.componentComplMk vnK [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK ⊢ ∃ ck, ck.fst ∈ componentComplMk G vnK ∧ ck.snd ∈ K ∧ Adj G ck.fst ck.snd [PROOFSTEP] let dis := Set.disjoint_iff.mp C.disjoint_right [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) ⊢ ∃ ck, ck.fst ∈ componentComplMk G vnK ∧ ck.snd ∈ K ∧ Adj G ck.fst ck.snd [PROOFSTEP] by_contra' h [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd ⊢ False [PROOFSTEP] suffices Set.univ = (C : Set V) by exact dis ⟨hK.choose_spec, this ▸ Set.mem_univ hK.some⟩ [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd this : Set.univ = ↑C ⊢ False [PROOFSTEP] exact dis ⟨hK.choose_spec, this ▸ Set.mem_univ hK.some⟩ [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd ⊢ Set.univ = ↑C [PROOFSTEP] symm [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd ⊢ ↑C = Set.univ [PROOFSTEP] rw [Set.eq_univ_iff_forall] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd ⊢ ∀ (x : V), x ∈ ↑C [PROOFSTEP] rintro u [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd u : V ⊢ u ∈ ↑C [PROOFSTEP] by_contra unC [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd u : V unC : ¬u ∈ ↑C ⊢ False [PROOFSTEP] obtain ⟨p⟩ := Gc v u [GOAL] case intro V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd u : V unC : ¬u ∈ ↑C p : Walk G v u ⊢ False [PROOFSTEP] obtain ⟨⟨⟨x, y⟩, xy⟩, -, xC, ynC⟩ := p.exists_boundary_dart (C : Set V) (G.componentComplMk_mem vnK) unC [GOAL] case intro.intro.mk.mk.intro.intro V : Type u G : SimpleGraph V K L L' M : Set V Gc : Preconnected G hK : Set.Nonempty K v : V vnK : ¬v ∈ K C : ComponentCompl G K := componentComplMk G vnK dis : K ∩ ↑C ⊆ ∅ := Iff.mp Set.disjoint_iff (ComponentCompl.disjoint_right C) h : ∀ (ck : V × V), ck.fst ∈ componentComplMk G vnK → ck.snd ∈ K → ¬Adj G ck.fst ck.snd u : V unC : ¬u ∈ ↑C p : Walk G v u x y : V xy : Adj G (x, y).fst (x, y).snd xC : { toProd := (x, y), is_adj := xy }.toProd.fst ∈ ↑C ynC : ¬{ toProd := (x, y), is_adj := xy }.toProd.snd ∈ ↑C ⊢ False [PROOFSTEP] exact ynC (mem_of_adj x y xC (fun yK : y ∈ K => h ⟨x, y⟩ xC yK xy) xy) [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L ⊢ ↑C ⊆ ↑(hom h C) [PROOFSTEP] rintro c ⟨cL, rfl⟩ [GOAL] case intro V : Type u G : SimpleGraph V K L L' M : Set V h : K ⊆ L c : V cL : ¬c ∈ L ⊢ c ∈ ↑(hom h (componentComplMk G cL)) [PROOFSTEP] exact ⟨fun h' => cL (h h'), rfl⟩ [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L D : ComponentCompl G K ⊢ hom h C = D ↔ ¬Disjoint ↑C ↑D [PROOFSTEP] rw [Set.not_disjoint_iff] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L D : ComponentCompl G K ⊢ hom h C = D ↔ ∃ x, x ∈ ↑C ∧ x ∈ ↑D [PROOFSTEP] constructor [GOAL] case mp V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L D : ComponentCompl G K ⊢ hom h C = D → ∃ x, x ∈ ↑C ∧ x ∈ ↑D [PROOFSTEP] rintro rfl [GOAL] case mp V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L ⊢ ∃ x, x ∈ ↑C ∧ x ∈ ↑(hom h C) [PROOFSTEP] refine C.ind fun x xnL => ?_ [GOAL] case mp V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L x : V xnL : ¬x ∈ L ⊢ ∃ x_1, x_1 ∈ ↑(componentComplMk G xnL) ∧ x_1 ∈ ↑(hom h (componentComplMk G xnL)) [PROOFSTEP] exact ⟨x, ⟨xnL, rfl⟩, ⟨fun xK => xnL (h xK), rfl⟩⟩ [GOAL] case mpr V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L D : ComponentCompl G K ⊢ (∃ x, x ∈ ↑C ∧ x ∈ ↑D) → hom h C = D [PROOFSTEP] refine C.ind fun x xnL => ?_ [GOAL] case mpr V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L D : ComponentCompl G K x : V xnL : ¬x ∈ L ⊢ (∃ x_1, x_1 ∈ ↑(componentComplMk G xnL) ∧ x_1 ∈ ↑D) → hom h (componentComplMk G xnL) = D [PROOFSTEP] rintro ⟨x, ⟨_, e₁⟩, _, rfl⟩ [GOAL] case mpr.intro.intro.intro.intro V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L x✝ : V xnL : ¬x✝ ∈ L x : V w✝¹ : ¬x ∈ L e₁ : componentComplMk G w✝¹ = componentComplMk G xnL w✝ : ¬x ∈ K ⊢ hom h (componentComplMk G xnL) = componentComplMk G w✝ [PROOFSTEP] rw [← e₁] [GOAL] case mpr.intro.intro.intro.intro V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L x✝ : V xnL : ¬x✝ ∈ L x : V w✝¹ : ¬x ∈ L e₁ : componentComplMk G w✝¹ = componentComplMk G xnL w✝ : ¬x ∈ K ⊢ hom h (componentComplMk G w✝¹) = componentComplMk G w✝ [PROOFSTEP] rfl [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L ⊢ hom (_ : L ⊆ L) C = C [PROOFSTEP] change C.map _ = C [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L ⊢ ConnectedComponent.map (induceHom Hom.id (_ : Lᶜ ⊆ Lᶜ)) C = C [PROOFSTEP] erw [induceHom_id G Lᶜ, ConnectedComponent.map_id] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L h' : M ⊆ K ⊢ hom (_ : M ⊆ L) C = hom h' (hom h C) [PROOFSTEP] change C.map _ = (C.map _).map _ [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L h' : M ⊆ K ⊢ ConnectedComponent.map (induceHom Hom.id (_ : Lᶜ ⊆ Mᶜ)) C = ConnectedComponent.map (induceHom Hom.id (_ : Kᶜ ⊆ Mᶜ)) (ConnectedComponent.map (induceHom Hom.id (_ : Lᶜ ⊆ Kᶜ)) C) [PROOFSTEP] erw [ConnectedComponent.map_comp, induceHom_comp] [GOAL] V : Type u G : SimpleGraph V K L L' M : Set V C : ComponentCompl G L h : K ⊆ L h' : M ⊆ K ⊢ ConnectedComponent.map (induceHom Hom.id (_ : Lᶜ ⊆ Mᶜ)) C = ConnectedComponent.map (induceHom (Hom.comp Hom.id Hom.id) (_ : Set.MapsTo (↑Hom.id ∘ fun x => ↑Hom.id x) Lᶜ Mᶜ)) C [PROOFSTEP] rfl [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K ⊢ Set.Infinite (supp C) ↔ ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C [PROOFSTEP] classical constructor · rintro Cinf L h obtain ⟨v, ⟨vK, rfl⟩, vL⟩ := Set.Infinite.nonempty (Set.Infinite.diff Cinf L.finite_toSet) exact ⟨componentComplMk _ vL, rfl⟩ · rintro h Cfin obtain ⟨D, e⟩ := h (K ∪ Cfin.toFinset) (Finset.subset_union_left K Cfin.toFinset) obtain ⟨v, vD⟩ := D.nonempty let Ddis := D.disjoint_right simp_rw [Finset.coe_union, Set.Finite.coe_toFinset, Set.disjoint_union_left, Set.disjoint_iff] at Ddis exact Ddis.right ⟨(ComponentCompl.hom_eq_iff_le _ _ _).mp e vD, vD⟩ [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K ⊢ Set.Infinite (supp C) ↔ ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C [PROOFSTEP] constructor [GOAL] case mp V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K ⊢ Set.Infinite (supp C) → ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C [PROOFSTEP] rintro Cinf L h [GOAL] case mp V : Type u G : SimpleGraph V K✝ L✝ L' M : Set V K : Finset V C : ComponentCompl G ↑K Cinf : Set.Infinite (supp C) L : Finset V h : K ⊆ L ⊢ ∃ D, hom h D = C [PROOFSTEP] obtain ⟨v, ⟨vK, rfl⟩, vL⟩ := Set.Infinite.nonempty (Set.Infinite.diff Cinf L.finite_toSet) [GOAL] case mp.intro.intro.intro V : Type u G : SimpleGraph V K✝ L✝ L' M : Set V K L : Finset V h : K ⊆ L v : V vL : ¬v ∈ ↑L vK : ¬v ∈ ↑K Cinf : Set.Infinite (supp (componentComplMk G vK)) ⊢ ∃ D, hom h D = componentComplMk G vK [PROOFSTEP] exact ⟨componentComplMk _ vL, rfl⟩ [GOAL] case mpr V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K ⊢ (∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C) → Set.Infinite (supp C) [PROOFSTEP] rintro h Cfin [GOAL] case mpr V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K h : ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C Cfin : Set.Finite (supp C) ⊢ False [PROOFSTEP] obtain ⟨D, e⟩ := h (K ∪ Cfin.toFinset) (Finset.subset_union_left K Cfin.toFinset) [GOAL] case mpr.intro V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K h : ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C Cfin : Set.Finite (supp C) D : ComponentCompl G ↑(K ∪ Set.Finite.toFinset Cfin) e : hom (_ : K ⊆ K ∪ Set.Finite.toFinset Cfin) D = C ⊢ False [PROOFSTEP] obtain ⟨v, vD⟩ := D.nonempty [GOAL] case mpr.intro.intro V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K h : ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C Cfin : Set.Finite (supp C) D : ComponentCompl G ↑(K ∪ Set.Finite.toFinset Cfin) e : hom (_ : K ⊆ K ∪ Set.Finite.toFinset Cfin) D = C v : V vD : v ∈ ↑D ⊢ False [PROOFSTEP] let Ddis := D.disjoint_right [GOAL] case mpr.intro.intro V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K h : ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C Cfin : Set.Finite (supp C) D : ComponentCompl G ↑(K ∪ Set.Finite.toFinset Cfin) e : hom (_ : K ⊆ K ∪ Set.Finite.toFinset Cfin) D = C v : V vD : v ∈ ↑D Ddis : Disjoint ↑(K ∪ Set.Finite.toFinset Cfin) ↑D := ComponentCompl.disjoint_right D ⊢ False [PROOFSTEP] simp_rw [Finset.coe_union, Set.Finite.coe_toFinset, Set.disjoint_union_left, Set.disjoint_iff] at Ddis [GOAL] case mpr.intro.intro V : Type u G : SimpleGraph V K✝ L L' M : Set V K : Finset V C : ComponentCompl G ↑K h : ∀ (L : Finset V) (h : K ⊆ L), ∃ D, hom h D = C Cfin : Set.Finite (supp C) D : ComponentCompl G ↑(K ∪ Set.Finite.toFinset Cfin) e : hom (_ : K ⊆ K ∪ Set.Finite.toFinset Cfin) D = C v : V vD : v ∈ ↑D Ddis : ↑K ∩ ↑D ⊆ ∅ ∧ supp C ∩ ↑D ⊆ ∅ ⊢ False [PROOFSTEP] exact Ddis.right ⟨(ComponentCompl.hom_eq_iff_le _ _ _).mp e vD, vD⟩ [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V ⊢ Finite (ComponentCompl G ↑K) [PROOFSTEP] classical rcases K.eq_empty_or_nonempty with rfl | h · dsimp [ComponentCompl] rw [Finset.coe_empty, Set.compl_empty] have := Gpc.out.subsingleton_connectedComponent exact Finite.of_equiv _ (induceUnivIso G).connectedComponentEquiv.symm · let touch (C : G.ComponentCompl K) : {v : V | ∃ k : V, k ∈ K ∧ G.Adj k v} := let p := C.exists_adj_boundary_pair Gpc.out h ⟨p.choose.1, p.choose.2, p.choose_spec.2.1, p.choose_spec.2.2.symm⟩ -- `touch` is injective have touch_inj : touch.Injective := fun C D h' => ComponentCompl.pairwise_disjoint.eq (Set.not_disjoint_iff.mpr ⟨touch C, (C.exists_adj_boundary_pair Gpc.out h).choose_spec.1, h'.symm ▸ (D.exists_adj_boundary_pair Gpc.out h).choose_spec.1⟩) -- `touch` has finite range have : Finite (Set.range touch) := by refine @Subtype.finite _ (Set.Finite.to_subtype ?_) _ apply Set.Finite.ofFinset (K.biUnion (fun v => G.neighborFinset v)) simp only [Finset.mem_biUnion, mem_neighborFinset, Set.mem_setOf_eq, implies_true] -- hence `touch` has a finite domain apply Finite.of_injective_finite_range touch_inj [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V ⊢ Finite (ComponentCompl G ↑K) [PROOFSTEP] rcases K.eq_empty_or_nonempty with rfl | h [GOAL] case inl V : Type u G : SimpleGraph V K L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) ⊢ Finite (ComponentCompl G ↑∅) [PROOFSTEP] dsimp [ComponentCompl] [GOAL] case inl V : Type u G : SimpleGraph V K L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) ⊢ Finite (ConnectedComponent (induce (↑∅)ᶜ G)) [PROOFSTEP] rw [Finset.coe_empty, Set.compl_empty] [GOAL] case inl V : Type u G : SimpleGraph V K L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) ⊢ Finite (ConnectedComponent (induce Set.univ G)) [PROOFSTEP] have := Gpc.out.subsingleton_connectedComponent [GOAL] case inl V : Type u G : SimpleGraph V K L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) this : Subsingleton (ConnectedComponent G) ⊢ Finite (ConnectedComponent (induce Set.univ G)) [PROOFSTEP] exact Finite.of_equiv _ (induceUnivIso G).connectedComponentEquiv.symm [GOAL] case inr V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K ⊢ Finite (ComponentCompl G ↑K) [PROOFSTEP] let touch (C : G.ComponentCompl K) : {v : V | ∃ k : V, k ∈ K ∧ G.Adj k v} := let p := C.exists_adj_boundary_pair Gpc.out h ⟨p.choose.1, p.choose.2, p.choose_spec.2.1, p.choose_spec.2.2.symm⟩ -- `touch` is injective [GOAL] case inr V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K touch : ComponentCompl G ↑K → ↑{v | ∃ k, k ∈ K ∧ Adj G k v} := fun C => let p := (_ : ∃ ck, ck.fst ∈ C ∧ (ck.snd ∈ fun x => x ∈ K.val) ∧ Adj G ck.fst ck.snd); { val := (Exists.choose p).fst, property := (_ : ∃ k, k ∈ K ∧ Adj G k (Exists.choose p).fst) } ⊢ Finite (ComponentCompl G ↑K) [PROOFSTEP] have touch_inj : touch.Injective := fun C D h' => ComponentCompl.pairwise_disjoint.eq (Set.not_disjoint_iff.mpr ⟨touch C, (C.exists_adj_boundary_pair Gpc.out h).choose_spec.1, h'.symm ▸ (D.exists_adj_boundary_pair Gpc.out h).choose_spec.1⟩) -- `touch` has finite range [GOAL] case inr V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K touch : ComponentCompl G ↑K → ↑{v | ∃ k, k ∈ K ∧ Adj G k v} := fun C => let p := (_ : ∃ ck, ck.fst ∈ C ∧ (ck.snd ∈ fun x => x ∈ K.val) ∧ Adj G ck.fst ck.snd); { val := (Exists.choose p).fst, property := (_ : ∃ k, k ∈ K ∧ Adj G k (Exists.choose p).fst) } touch_inj : Function.Injective touch ⊢ Finite (ComponentCompl G ↑K) [PROOFSTEP] have : Finite (Set.range touch) := by refine @Subtype.finite _ (Set.Finite.to_subtype ?_) _ apply Set.Finite.ofFinset (K.biUnion (fun v => G.neighborFinset v)) simp only [Finset.mem_biUnion, mem_neighborFinset, Set.mem_setOf_eq, implies_true] -- hence `touch` has a finite domain [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K touch : ComponentCompl G ↑K → ↑{v | ∃ k, k ∈ K ∧ Adj G k v} := fun C => let p := (_ : ∃ ck, ck.fst ∈ C ∧ (ck.snd ∈ fun x => x ∈ K.val) ∧ Adj G ck.fst ck.snd); { val := (Exists.choose p).fst, property := (_ : ∃ k, k ∈ K ∧ Adj G k (Exists.choose p).fst) } touch_inj : Function.Injective touch ⊢ Finite ↑(Set.range touch) [PROOFSTEP] refine @Subtype.finite _ (Set.Finite.to_subtype ?_) _ [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K touch : ComponentCompl G ↑K → ↑{v | ∃ k, k ∈ K ∧ Adj G k v} := fun C => let p := (_ : ∃ ck, ck.fst ∈ C ∧ (ck.snd ∈ fun x => x ∈ K.val) ∧ Adj G ck.fst ck.snd); { val := (Exists.choose p).fst, property := (_ : ∃ k, k ∈ K ∧ Adj G k (Exists.choose p).fst) } touch_inj : Function.Injective touch ⊢ Set.Finite {v | ∃ k, k ∈ K ∧ Adj G k v} [PROOFSTEP] apply Set.Finite.ofFinset (K.biUnion (fun v => G.neighborFinset v)) [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K touch : ComponentCompl G ↑K → ↑{v | ∃ k, k ∈ K ∧ Adj G k v} := fun C => let p := (_ : ∃ ck, ck.fst ∈ C ∧ (ck.snd ∈ fun x => x ∈ K.val) ∧ Adj G ck.fst ck.snd); { val := (Exists.choose p).fst, property := (_ : ∃ k, k ∈ K ∧ Adj G k (Exists.choose p).fst) } touch_inj : Function.Injective touch ⊢ ∀ (x : V), (x ∈ Finset.biUnion K fun v => neighborFinset G v) ↔ x ∈ {v | ∃ k, k ∈ K ∧ Adj G k v} [PROOFSTEP] simp only [Finset.mem_biUnion, mem_neighborFinset, Set.mem_setOf_eq, implies_true] -- hence `touch` has a finite domain [GOAL] case inr V : Type u G : SimpleGraph V K✝ L L' M : Set V inst✝ : LocallyFinite G Gpc : Fact (Preconnected G) K : Finset V h : Finset.Nonempty K touch : ComponentCompl G ↑K → ↑{v | ∃ k, k ∈ K ∧ Adj G k v} := fun C => let p := (_ : ∃ ck, ck.fst ∈ C ∧ (ck.snd ∈ fun x => x ∈ K.val) ∧ Adj G ck.fst ck.snd); { val := (Exists.choose p).fst, property := (_ : ∃ k, k ∈ K ∧ Adj G k (Exists.choose p).fst) } touch_inj : Function.Injective touch this : Finite ↑(Set.range touch) ⊢ Finite (ComponentCompl G ↑K) [PROOFSTEP] apply Finite.of_injective_finite_range touch_inj [GOAL] V : Type u G : SimpleGraph V K✝ L✝ L' M : Set V s : (j : (Finset V)ᵒᵖ) → (componentComplFunctor G).obj j sec : s ∈ SimpleGraph.end G K L : (Finset V)ᵒᵖ h : L ⟶ K v : V vnL : ¬v ∈ L.unop hs : s L = componentComplMk G vnL ⊢ s K = componentComplMk G (_ : ¬v ∈ fun a => a ∈ K.unop.val) [PROOFSTEP] rw [← sec h, hs] [GOAL] V : Type u G : SimpleGraph V K✝ L✝ L' M : Set V s : (j : (Finset V)ᵒᵖ) → (componentComplFunctor G).obj j sec : s ∈ SimpleGraph.end G K L : (Finset V)ᵒᵖ h : L ⟶ K v : V vnL : ¬v ∈ L.unop hs : s L = componentComplMk G vnL ⊢ (componentComplFunctor G).map h (componentComplMk G vnL) = componentComplMk G (_ : ¬v ∈ fun a => a ∈ K.unop.val) [PROOFSTEP] apply ComponentCompl.hom_mk _ (le_of_op_hom h : _ ⊆ _) [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V K : (Finset V)ᵒᵖ C : (componentComplFunctor G).obj K ⊢ Set.Infinite (ComponentCompl.supp C) ↔ C ∈ Functor.eventualRange (componentComplFunctor G) K [PROOFSTEP] simp only [C.infinite_iff_in_all_ranges, CategoryTheory.Functor.eventualRange, Set.mem_iInter, Set.mem_range, componentComplFunctor_map] [GOAL] V : Type u G : SimpleGraph V K✝ L L' M : Set V K : (Finset V)ᵒᵖ C : (componentComplFunctor G).obj K ⊢ (∀ (L : Finset V) (h : K.unop ⊆ L), ∃ D, ComponentCompl.hom h D = C) ↔ ∀ (i : (Finset V)ᵒᵖ) (i_1 : i ⟶ K), ∃ y, ComponentCompl.hom (_ : K.unop ≤ i.unop) y = C [PROOFSTEP] exact ⟨fun h Lop KL => h Lop.unop (le_of_op_hom KL), fun h L KL => h (Opposite.op L) (opHomOfLE KL)⟩
module Specdris.SpecIOTest import Specdris.SpecIO import Specdris.TestUtil testCase : IO () testCase = do state <- specIOWithState $ do describe "context 1" $ do describe "context 1.1" $ do it "context 1.1.1" $ do a <- pure 1 pure $ do a === 2 a === 1 it "context 1.2" $ do pure $ "hello" `shouldSatisfy` (\str => (length str) > 5) it "context 1.3" $ do pure $ 1 `shouldBe` 2 it "context 1.4" $ do pure $ pendingWith "for some reason" testAndPrint "spec io test" state (MkState 4 3 1 Nothing) (==) withBeforeAndAfterAll : IO () withBeforeAndAfterAll = do state <- specIOWithState {beforeAll = putStrLn "beforeAll"} {afterAll = putStrLn "afterAll"} $ do describe "context 1" $ do it "context 1.1" $ do pure $ 1 === 1 testAndPrint "spec io test with before and after all" state (MkState 1 0 0 Nothing) (==) around : IO SpecResult -> IO SpecResult around spec = do putStrLn "before" result <- spec putStrLn "after" pure result withAround : IO () withAround = do state <- specIOWithState {around = around} $ do describe "context 1" $ do it "context 1.1" $ do putStrLn " => expectation" pure $ 1 === 1 testAndPrint "spec io test with around" state (MkState 1 0 0 Nothing) (==) export specSuite : IO () specSuite = do putStrLn "\n spec-io:" testCase withBeforeAndAfterAll withAround
lemma poly_shift_0 [simp]: "poly_shift n 0 = 0"
myTestRule () { msiHello(*name, *message); } INPUT *name="John" OUTPUT ruleExecOut, *message
import number_theory.sum_two_squares /-! # Sums of two squares The goal of this project is to prove the following statement. **Theorem.** Let n be a positive natural number. Then n can be written as n = a² + b² with natural numbers a and b if and only if every prime q ≡ 3 mod 4 occurs with an even exponent in the prime factorization of n. mathlib has *Fermat's two-squares theorem* that says that a prime p ≡ 1 mod 4 is a sum of two squares. theorem nat.prime.sq_add_sq {p : ℕ} [fact (nat.prime p)] (hp : p % 4 = 1) : ∃ (a b : ℕ), a ^ 2 + b ^ 2 = p From this (and the facts that 2 is a sum of two squares and that the set of sums of two squares is multiplicative), the "if" direction follows fairly easily. For the "only if" direction, one has to show the following **Lemma.** If q ≡ 3 mod 4 is a prime and q divides a² + b², then q divides a and b (and hence q² divides a² + b²). There are the following lemmas in mathlib, which might be helpful. theorem zmod.exists_sq_eq_neg_one_iff {p : ℕ} [fact (nat.prime p)] : is_square (-1 : zmod p) ↔ p % 4 ≠ 3 theorem zmod.mod_four_ne_three_of_sq_eq_neg_sq' {p : ℕ} [fact (nat.prime p)] {x y : zmod p} (hy : y ≠ 0) (hxy : x ^ 2 = -y ^ 2) : p % 4 ≠ 3 -/
lemma of_real_of_nat_eq [simp]: "of_real (of_nat n) = of_nat n"
State Before: α : Type u_1 n : ℕ l : List α s : Multiset α ⊢ ∀ (a : List α), Quotient.mk (isSetoid α) a ∈ powersetLenAux n l ↔ Quotient.mk (isSetoid α) a ≤ ↑l ∧ ↑card (Quotient.mk (isSetoid α) a) = n State After: α : Type u_1 n : ℕ l : List α s : Multiset α ⊢ ∀ (a : List α), (∃ a_1, (a_1 <+ l ∧ length a_1 = n) ∧ a_1 ~ a) ↔ (∃ l_1, l_1 ~ a ∧ l_1 <+ l) ∧ length a = n Tactic: simp [powersetLenAux_eq_map_coe, Subperm] State Before: α : Type u_1 n : ℕ l : List α s : Multiset α ⊢ ∀ (a : List α), (∃ a_1, (a_1 <+ l ∧ length a_1 = n) ∧ a_1 ~ a) ↔ (∃ l_1, l_1 ~ a ∧ l_1 <+ l) ∧ length a = n State After: no goals Tactic: exact fun l₁ => ⟨fun ⟨l₂, ⟨s, e⟩, p⟩ => ⟨⟨_, p, s⟩, p.symm.length_eq.trans e⟩, fun ⟨⟨l₂, p, s⟩, e⟩ => ⟨_, ⟨s, p.length_eq.trans e⟩, p⟩⟩
module Issue4954.M (_ : Set₁) where
[STATEMENT] lemma order_apply_power [simp]: "order f ((f ^ n) \<langle>$\<rangle> a) = order f a" [PROOF STATE] proof (prove) goal (1 subgoal): 1. order f ((f ^ n) \<langle>$\<rangle> a) = order f a [PROOF STEP] by (simp only: order_def comp_def orbit_apply_power)
State Before: α : Type u t : TopologicalSpace α inst✝ : SecondCountableTopology α S : Set (Set α) H : ∀ (s : Set α), s ∈ S → IsOpen s T : Set ↑S cT : Set.Countable T hT : (⋃ (i : ↑S) (_ : i ∈ T), ↑i) = ⋃ (i : ↑S), ↑i ⊢ ⋃₀ (Subtype.val '' T) = ⋃₀ S State After: no goals Tactic: rwa [sUnion_image, sUnion_eq_iUnion]
! ! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ! See https://llvm.org/LICENSE.txt for license information. ! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception ! program p integer :: retval = -42 stop retval end program
constant g (x y : Nat) : Nat constant f (x y : Nat) : Nat axiom f_def (x y : Nat) : f x y = g x y axiom f_ax (x : Nat) : f x x = x theorem ex1 (x : Nat) : g x x = x := by simp [← f_def, f_ax] constant p (x y : Nat) : Prop constant q (x y : Nat) : Prop axiom p_def (x y : Nat) : p x y ↔ q x y axiom p_ax (x : Nat) : p x x theorem ex2 (x : Nat) : q x x := by simp [← p_def, p_ax]
[GOAL] R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x y : L ⊢ ↑χ ⁅x, y⁆ = 0 [PROOFSTEP] rw [LieHom.map_lie, LieRing.of_associative_ring_bracket, mul_comm, sub_self] [GOAL] R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x y : L ⊢ ⁅↑χ x, ↑χ y⁆ = 0 [PROOFSTEP] rw [LieRing.of_associative_ring_bracket, mul_comm, sub_self] [GOAL] R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ derivedSeries R L 1 ⊢ ↑χ x = 0 [PROOFSTEP] rw [derivedSeries_def, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_zero, ← LieSubmodule.mem_coeSubmodule, LieSubmodule.lieIdeal_oper_eq_linear_span] at h [GOAL] R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} ⊢ ↑χ x = 0 [PROOFSTEP] refine' Submodule.span_induction h _ _ _ _ [GOAL] case refine'_1 R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} ⊢ ∀ (x : L), x ∈ {m | ∃ x n, ⁅↑x, ↑n⁆ = m} → ↑χ x = 0 [PROOFSTEP] rintro y ⟨⟨z, hz⟩, ⟨⟨w, hw⟩, rfl⟩⟩ [GOAL] case refine'_1.intro.mk.intro.mk R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} z : L hz : z ∈ ⊤ w : L hw : w ∈ ⊤ ⊢ ↑χ ⁅↑{ val := z, property := hz }, ↑{ val := w, property := hw }⁆ = 0 [PROOFSTEP] apply lieCharacter_apply_lie [GOAL] case refine'_2 R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} ⊢ ↑χ 0 = 0 [PROOFSTEP] exact χ.map_zero [GOAL] case refine'_3 R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} ⊢ ∀ (x y : L), ↑χ x = 0 → ↑χ y = 0 → ↑χ (x + y) = 0 [PROOFSTEP] intro y z hy hz [GOAL] case refine'_3 R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} y z : L hy : ↑χ y = 0 hz : ↑χ z = 0 ⊢ ↑χ (y + z) = 0 [PROOFSTEP] rw [LieHom.map_add, hy, hz, add_zero] [GOAL] case refine'_4 R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} ⊢ ∀ (a : R) (x : L), ↑χ x = 0 → ↑χ (a • x) = 0 [PROOFSTEP] intro t y hy [GOAL] case refine'_4 R : Type u L : Type v inst✝² : CommRing R inst✝¹ : LieRing L inst✝ : LieAlgebra R L χ : LieCharacter R L x : L h : x ∈ Submodule.span R {m | ∃ x n, ⁅↑x, ↑n⁆ = m} t : R y : L hy : ↑χ y = 0 ⊢ ↑χ (t • y) = 0 [PROOFSTEP] rw [LieHom.map_smul, hy, smul_zero] [GOAL] R : Type u L : Type v inst✝³ : CommRing R inst✝² : LieRing L inst✝¹ : LieAlgebra R L inst✝ : IsLieAbelian L ψ : Module.Dual R L x y : L ⊢ AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom ⁅x, y⁆ = ⁅AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom x, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom y⁆ [PROOFSTEP] rw [LieModule.IsTrivial.trivial, LieRing.of_associative_ring_bracket, mul_comm, sub_self, LinearMap.toFun_eq_coe, LinearMap.map_zero] [GOAL] R : Type u L : Type v inst✝³ : CommRing R inst✝² : LieRing L inst✝¹ : LieAlgebra R L inst✝ : IsLieAbelian L χ : LieCharacter R L ⊢ (fun ψ => { toLinearMap := { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }, map_lie' := (_ : ∀ {x y : L}, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom ⁅x, y⁆ = ⁅AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom x, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom y⁆) }) ((fun χ => ↑χ) χ) = χ [PROOFSTEP] ext [GOAL] case h R : Type u L : Type v inst✝³ : CommRing R inst✝² : LieRing L inst✝¹ : LieAlgebra R L inst✝ : IsLieAbelian L χ : LieCharacter R L x✝ : L ⊢ ↑((fun ψ => { toLinearMap := { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }, map_lie' := (_ : ∀ {x y : L}, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom ⁅x, y⁆ = ⁅AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom x, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom y⁆) }) ((fun χ => ↑χ) χ)) x✝ = ↑χ x✝ [PROOFSTEP] rfl [GOAL] R : Type u L : Type v inst✝³ : CommRing R inst✝² : LieRing L inst✝¹ : LieAlgebra R L inst✝ : IsLieAbelian L ψ : Module.Dual R L ⊢ (fun χ => ↑χ) ((fun ψ => { toLinearMap := { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }, map_lie' := (_ : ∀ {x y : L}, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom ⁅x, y⁆ = ⁅AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom x, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom y⁆) }) ψ) = ψ [PROOFSTEP] ext [GOAL] case h R : Type u L : Type v inst✝³ : CommRing R inst✝² : LieRing L inst✝¹ : LieAlgebra R L inst✝ : IsLieAbelian L ψ : Module.Dual R L x✝ : L ⊢ ↑((fun χ => ↑χ) ((fun ψ => { toLinearMap := { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }, map_lie' := (_ : ∀ {x y : L}, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom ⁅x, y⁆ = ⁅AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom x, AddHom.toFun { toAddHom := ψ.toAddHom, map_smul' := (_ : ∀ (r : R) (x : L), AddHom.toFun ψ.toAddHom (r • x) = ↑(RingHom.id R) r • AddHom.toFun ψ.toAddHom x) }.toAddHom y⁆) }) ψ)) x✝ = ↑ψ x✝ [PROOFSTEP] rfl
lemma of_real_of_int_eq [simp]: "of_real (of_int z) = of_int z"
import game.max.level04 -- hide open_locale classical -- hide noncomputable theory -- hide namespace xena -- hide /- # Chapter 4 : Max and abs ## Level 5 `max_le` is really useful; it says that if `a ≤ c` and `b ≤ c` then `max a b ≤ c`. Note that in the Lean formulation, the variables are *implicit*, meaning that Lean will guess them. -/ /- Lemma If $a$, $b$, $c$ are real numbers with $a\leq c$ and $b\leq c$, then $\max(a,b)\leq c.$ -/ theorem max_le {a b c : ℝ} (hac : a ≤ c) (hbc : b ≤ c) : max a b ≤ c := begin cases max_choice a b with ha hb, rw ha, exact hac, rw hb, exact hbc, end end xena --hide
Performance
module Data.Time.Clock.Internal.SystemTime -- ( SystemTime(..) -- , getSystemTime -- , getTime_resolution -- , getTAISystemTime -- ) where --import Data.Bits32 --import Data.Data --import Control.DeepSeq --import Data.Int (Int64) import Data.Time.Clock.Internal.DiffTime --import Data.Word --#include "HsTimeConfig.h" import Internal.CTimespec import Data.Time.Clock.Internal.Fixed -------------------------------------------------------------------------------- -- | 'SystemTime' is time returned by system clock functions. -- Its semantics depends on the clock function, but the epoch is typically the beginning of 1970. -- Note that 'systemNanoseconds' of 1E9 to 2E9-1 can be used to represent leap seconds. public export record SystemTime where constructor MkSystemTime systemSeconds: Integer systemNanoseconds: Integer -- | Get the system time, epoch start of 1970 UTC, leap-seconds ignored. -- 'getSystemTime' is typically much faster than 'getCurrentTime'. export getSystemTime: IO SystemTime getSystemTime = do (MkCTimeSpec x y) <- clock_gettime pure $ MkSystemTime x y -- | The resolution of 'getSystemTime', 'getCurrentTime', 'getPOSIXTime' -- | TODO: Fix this. --getTime_resolution: DiffTime -- getTime_resolution = 100E-9 -- 100ns timespecToSystemTime: CTimeSpec -> SystemTime timespecToSystemTime (MkCTimeSpec s ns) = (MkSystemTime s ns) -- TODO: Currently nano second resolution does not work timespecToDiffTime: CTimeSpec -> DiffTime timespecToDiffTime (MkCTimeSpec s ns) = MkDiffTime (MkFixed (s)) -- + (ns * 1E-9))) --clockGetSystemTime :: ClockID -> IO SystemTime --clockGetSystemTime clock = fmap timespecToSystemTime $ clockGetTime clock --getSystemTime = clockGetSystemTime clock_REALTIME --getTime_resolution = timespecToDiffTime realtimeRes -- Use gettimeofday -- getTime_resolution = 1E-6 -- microsecond
[STATEMENT] theorem C10: "\<lfloor>\<^bold>\<exists>\<^sup>Ax. Godlike x\<rfloor>" [PROOF STATE] proof (prove) goal (1 subgoal): 1. \<lfloor>\<lambda>w. \<exists>x. ((actualizedAt) x \<^bold>\<and> Godlike x) w\<rfloor> [PROOF STEP] using Existence_def Necessary_def abstractness_essential concrete_exist P2 C1 B_axiom [PROOF STATE] proof (prove) using this: E! ?x \<equiv> \<lambda>w. \<exists>x. x actualizedAt w \<and> x = ?x Necessary ?x \<equiv> \<^bold>\<box>E! ?x \<lfloor>\<lambda>w. \<forall>x. (Abstract x \<^bold>\<rightarrow> \<^bold>\<box>Abstract x) w\<rfloor> \<lfloor>\<lambda>w. \<forall>x. (Concrete x \<^bold>\<rightarrow> E! x) w\<rfloor> \<lfloor>\<lambda>w. \<exists>x. ((actualizedAt) x \<^bold>\<and> Necessary x \<^bold>\<and> Abstract x) w\<rfloor> \<lfloor>\<lambda>w. \<forall>x. x actualizedAt w \<longrightarrow> Abstract x w \<longrightarrow> (\<exists>xa. (Concrete xa \<^bold>\<and> x dependsOn xa) w)\<rfloor> universal (\<lambda>x y. x r y \<longrightarrow> y r x) goal (1 subgoal): 1. \<lfloor>\<lambda>w. \<exists>x. ((actualizedAt) x \<^bold>\<and> Godlike x) w\<rfloor> [PROOF STEP] by meson
[STATEMENT] lemma lim_set [simp]: "lim (set r v h) = lim h" [PROOF STATE] proof (prove) goal (1 subgoal): 1. lim (Ref_Time.set r v h) = lim h [PROOF STEP] by (simp add: set_def)
{-# OPTIONS --safe --no-qualified-instances #-} {- Noop removal transformation on bytecode -} module JVM.Transform.Noooops where open import Data.Product open import Data.Sum open import Function using (case_of_) open import Data.List open import Relation.Unary hiding (Empty) open import Relation.Binary.Structures open import Relation.Binary.PropositionalEquality using (refl; _≡_) open import Relation.Ternary.Core open import Relation.Ternary.Structures open import Relation.Ternary.Structures.Syntax hiding (_∣_) open import JVM.Types open import JVM.Model StackTy open import JVM.Syntax.Instructions open import Relation.Ternary.Data.ReflexiveTransitive {{intf-rel}} open IsEquivalence {{...}} using (sym) open import Data.Maybe using (just; nothing; Maybe) is-noop : ∀[ ⟨ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟩ ⇒ (Empty (ψ₁ ≡ ψ₂) ∪ U) ] is-noop noop = inj₁ (emp refl) is-noop _ = inj₂ _ noooop : ∀[ ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ ⇒ ⟪ 𝑭 ∣ ψ₁ ↝ ψ₂ ⟫ ] noooop nil = nil -- (1) not labeled noooop (cons (instr (↓ i) ∙⟨ σ ⟩ is)) = case (is-noop i) of λ where (inj₂ _) → instr (↓ i) ▹⟨ σ ⟩ noooop is (inj₁ (emp refl)) → coe (∙-id⁻ˡ σ) (noooop is) -- (2) is labeled noooop (cons (li@(labeled (l ∙⟨ σ₀ ⟩ ↓ i)) ∙⟨ σ ⟩ is)) = case (is-noop i) of λ where (inj₂ _) → cons (li ∙⟨ σ ⟩ noooop is) (inj₁ (emp refl)) → label-start noop l ⟨ coe {{∙-respects-≈ˡ}} (≈-sym (∙-id⁻ʳ σ₀)) σ ⟩ (noooop is)
import order.filter.basic lemma filter.eventually_eq.eventually_eq_ite {X Y : Type*} {l : filter X} {f g : X → Y} {P : X → Prop} [decidable_pred P] (h : f =ᶠ[l] g) : (λ x, if P x then f x else g x) =ᶠ[l] f := begin apply h.mono (λ x hx, _), dsimp only, split_ifs ; tauto end
informal statement Let $X$ be completely regular. Show that $X$ is connected if and only if the Stone-Čech compactification of $X$ is connected.formal statement theorem exercise_1_3 {F V : Type*} [add_comm_group V] [field F] [module F V] {v : V} : -(-v) = v :=
{-# OPTIONS --without-K --safe --no-sized-types --no-guardedness #-} module Agda.Builtin.IO where postulate IO : ∀ {a} → Set a → Set a {-# BUILTIN IO IO #-} {-# FOREIGN GHC type AgdaIO a b = IO b #-} {-# COMPILE GHC IO = type AgdaIO #-}
lemma contour_integral_0 [simp]: "contour_integral g (\<lambda>x. 0) = 0"
import cv2 import numpy as np cap= cv2.VideoCapture(0) labels = list() example_contour = list() images= list() imname= 0 while (cap.isOpened()): ret, img= cap.read() img= cv2.flip(img, 1) cv2.rectangle(img,(300,300),(0,0),(0,255,0),0) roi= img[0:300, 0:300] gray= cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY) blurred = cv2.GaussianBlur(gray, (35,35), 0) _, edges= cv2.threshold(blurred, 127, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) _, contours, hierarchy = cv2.findContours(edges.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) y=len(contours) area= np.zeros(y) for i in range(0, y): area[i] = cv2.contourArea(contours[i]) index= area.argmax() hand = contours[index] x,y,w,h = cv2.boundingRect(hand) cv2.rectangle(roi,(x,y),(x+w,y+h),(0,0,255),0) temp = np.zeros(roi.shape, np.uint8) M = cv2.moments(hand) cv2.drawContours(img, [hand], -1, (0, 255,0), -1) cv2.drawContours(temp, [hand], -1, (0, 255,0), -1) key = cv2.waitKey(1) if key & 0xFF== ord('q'): c = np.asarray(example_contour) print c.shape print labels np.save('gestures/composite_list.npy', c) np.save('gestures/composite_list_labels.npy', labels) for img in images: i = str(imname) cv2.imwrite('gestures/'+i.zfill(4)+'.jpg', img) imname+=1 break elif key & 0xFF == ord('0'): example_contour.append(hand) images.append(temp) labels.append(0) print len(example_contour) elif key & 0xFF == ord('1'): example_contour.append(hand) images.append(temp) labels.append(1) print len(example_contour) elif key & 0xFF == ord('2'): example_contour.append(hand) images.append(temp) labels.append(2) print len(example_contour) elif key & 0xFF == ord('3'): example_contour.append(hand) images.append(temp) labels.append(3) print len(example_contour) elif key & 0xFF == ord('4'): example_contour.append(hand) images.append(temp) labels.append(4) print len(example_contour) elif key & 0xFF == ord('5'): example_contour.append(hand) images.append(temp) labels.append(5) print len(example_contour) cv2.imshow('Place your hand in the rectangle', img) cv2.imshow('Contour', temp) cv2.moveWindow('Contour', 600, 0)
universes u v inductive Imf {α : Type u} {β : Type v} (f : α → β) : β → Type (max u v) | mk : (a : α) → Imf f (f a) def h {α β} {f : α → β} : {b : β} → Imf f b → α | _, Imf.mk a => a #print h theorem ex : ∀ {α β : Sort u} (h : α = β) (a : α), cast h a ≅ a | α, _, rfl, a => HEq.refl a #print ex
Section MinimalPropositionalLogic. Axiom P : Prop. Axiom Q : Prop. Axiom R : Prop. Axiom T : Prop. Theorem ImplicationsAreTransitive : (P -> Q) -> (Q -> R) -> P -> R. Proof. intro H0. intro H1. intro p. apply H1. apply H0. assumption. Qed. Section AssumptionExample. Hypothesis H : P -> Q -> R. Lemma L1 : P -> Q -> R. Proof. assumption. Qed. End AssumptionExample. Theorem ApplyExample : (Q -> R -> T) -> (P -> Q) -> P -> R -> T. Proof. intros H1 H2 p. apply H1. exact (H2 p). Qed. (* Theorem ImplicationIsDistributive : (forall A B C : Prop, (A -> (A -> B -> C) -> (A -> B) -> (B -> C))). Proof. intro A. intro B. intro C. intro a. intro H1. intro H2. intro H3. apply H1. assumption. apply H3. Qed. *) Theorem ImplicationIsDistributive : ((P -> Q -> R) -> (P -> Q) -> (P -> R)). Proof. intros H1 H2 p. apply H1. assumption. exact (H2 p). Qed. Section ExamplesCh3Section3. Lemma Identity : (P -> P). Proof. intro p. exact p. Qed. Lemma IdentityImplication : ((P -> P) -> (P -> P)). Proof. intro H0. exact H0. Qed. Lemma ImplicationIsTransitive : ((P -> Q) -> (Q -> R) -> P -> R). Proof. intro H1. intro H2. intro p. apply H2. exact (H1 p). Qed. Lemma ImplicationPer : ((P -> Q -> R) -> (Q -> P -> R)). Proof. intro H1. intro H2. intro p. apply H1. - assumption. - apply H2. Qed. Lemma IgnoreQ : ((P -> R) -> P -> Q -> R). Proof. intro H1. intro H2. intro H3. apply H1. apply H2. Qed. Lemma DeltaImplication : ((P -> Q) -> (P -> P -> Q)). Proof. intro H1. intro H2. intro H3. apply H1. apply H2. Qed. Lemma DeltaImplicationReverse : ((P -> P -> Q) -> P -> Q). Proof. intro H1. intro H2. apply H1. assumption. assumption. Qed. Lemma Diamond : ((P -> Q) -> (P -> R) -> (Q -> R -> T) -> P -> T). Proof. intro H1. intro H2. intro H3. intro H4. apply H3. apply H1. apply H4. apply H2. assumption. Qed. Lemma WeakPeirce : (((((P -> Q) -> P) -> P) -> Q) -> Q). Proof. intro H1. apply H1. intro H2. apply H2. intro H3. apply H1. intro H4. assumption. Qed. End ExamplesCh3Section3. Theorem ModusPonens : ((P -> Q) -> P -> Q). Proof. intros. rename H into H1. apply H1. assumption. Qed. (* TODO: Complete Theorem ModusTollens : ((P -> Q) -> ~Q -> ~P). Proof. intros. *) Section ProofOfTripleImplication. Hypothesis H : (((P -> Q) -> Q) -> Q). Hypothesis p : P. Lemma Rem : ((P -> Q) -> Q). Proof (fun H0: (P -> Q) => H0 p). Theorem TripleImplication : Q. Proof (H Rem). End ProofOfTripleImplication. Print TripleImplication. Print Rem. Theorem ThenExample : (P -> Q -> (P -> Q -> R) -> R). Proof. intros p q H1. apply H1; assumption. Qed. Theorem TripleImplicationOneShot : ((((P -> Q) -> Q) -> Q) -> P -> Q). Proof. intros H p; apply H; intro H0; apply H0; assumption. Qed. Theorem ComposeExample : ((P -> Q -> R) -> (P -> Q) -> (P -> R)). Proof. intros H1 H2 p. apply H1; [assumption | apply H2; assumption]. Qed. Lemma L3 : ((P -> Q) -> (P -> R) -> (P -> Q -> R -> T) -> P -> T). Proof. intros H1 H2 H3 p. apply H3; [idtac | apply H1 | apply H2]; assumption. Qed. Theorem ThenFailExample : ((P -> Q) -> (P -> Q)). Proof. intro H; apply H; fail. Qed. Section SectionForCutExample. Hypothesis (H1 : P -> Q) (H2 : Q -> R) (H3 : (P -> R) -> T -> Q) (H4 : (P -> R) -> T). Theorem CutExample : Q. Proof. cut (P -> R). intro H5. apply H3. assumption. apply H4; assumption. intro H6. apply H2. apply H1. assumption. Qed. Print CutExample. Theorem CutWithoutCutExample : Q. Proof. apply H3. intro H5. apply H2. apply H1. assumption. apply H4. intro H5. apply H2. apply H1. assumption. Qed. End SectionForCutExample. End MinimalPropositionalLogic. Print ImplicationIsDistributive. Section UsingImplicationIsDistributive. Variables (P1 P2 P3 : Prop). (* Not working Check (ImplicationIsDistributive P1 P2 P3). *) Theorem Exercise5P5 : (forall A B C D : Set, A = C \/ B = C \/ C = C \/ D = C). Proof. intro A. intro B. intro C. intro D. right. right. left. reflexivity. Qed. Theorem ModusTollens : (forall P Q : Prop, (P -> Q) -> ~Q -> ~P). Proof. intro P. intro Q. intro H. unfold not. apply (ImplicationTransitivity). exact (H). Qed.
||| Additional functions about vectors module Data.Vect.Extra import Data.Vect import Data.Fin import Data.Vect.Elem ||| Version of `map` with access to the current position public export mapWithPos : (f : Fin n -> a -> b) -> Vect n a -> Vect n b mapWithPos f [] = [] mapWithPos f (x :: xs) = f 0 x :: mapWithPos (f . FS) xs ||| Version of `map` with runtime-irrelevant information that the ||| argument is an element of the vector public export mapWithElem : (xs : Vect n a) -> (f : (x : a) -> (0 pos : x `Elem` xs) -> b) -> Vect n b mapWithElem [] f = [] mapWithElem (x :: xs) f = f x Here :: mapWithElem xs (\x,pos => f x (There pos))
[STATEMENT] lemma vifintersection_vintersection_single: assumes "I \<noteq> 0" shows "B \<union>\<^sub>\<circ> (\<Inter>\<^sub>\<circ>i\<in>\<^sub>\<circ>I. A i) = (\<Inter>\<^sub>\<circ>i\<in>\<^sub>\<circ>I. B \<union>\<^sub>\<circ> A i)" [PROOF STATE] proof (prove) goal (1 subgoal): 1. B \<union>\<^sub>\<circ> \<Inter>\<^sub>\<circ> (VLambda I A `\<^sub>\<circ> I) = \<Inter>\<^sub>\<circ> ((\<lambda>a\<in>\<^sub>\<circ>I. B \<union>\<^sub>\<circ> A a) `\<^sub>\<circ> I) [PROOF STEP] by (insert assms, intro vsubset_antisym vsubsetI vifintersectionI) blast+
! { dg-do run } ! { dg-add-options ieee } ! { dg-skip-if "NaN not supported" { spu-*-* } { "*" } { "" } } ! PR37077 Implement Internal Unit I/O for character KIND=4 ! Test case prepared by Jerry DeLisle <[email protected]> program char4_iunit_1 implicit none character(kind=4,len=42) :: string integer(kind=4) :: i,j real(kind=4) :: inf, nan, large large = huge(large) inf = 2 * large nan = 0 nan = nan / nan string = 4_"123456789x" write(string,'(a11)') 4_"abcdefg" if (string .ne. 4_" abcdefg ") call abort write(string,*) 12345 if (string .ne. 4_" 12345 ") call abort write(string, '(i6,5x,i8,a5)') 78932, 123456, "abc" if (string .ne. 4_" 78932 123456 abc ") call abort write(string, *) .true., .false. , .true. if (string .ne. 4_" T F T ") call abort write(string, *) 1.2345e-06, 4.2846e+10_8 if (string .ne. 4_" 1.23450002E-06 42846000000.000000 ") call abort write(string, *) nan, inf if (string .ne. 4_" NaN +Infinity ") call abort write(string, '(10x,f3.1,3x,f9.1)') nan, inf if (string .ne. 4_" NaN +Infinity ") call abort write(string, *) (1.2, 3.4 ) if (string .ne. 4_" ( 1.2000000 , 3.4000001 ) ") call abort end program char4_iunit_1
Require Import List. Require Import ZArith. Require Import String. Import ListNotations. Require Import lang. (* for expression *) Definition exp_var_constr := constr_def (constr_name "var") [type_name "string"]. Definition exp_num_constr := constr_def (constr_name "num") [type_name "num"]. Definition exp_plus_constr := constr_def (constr_name "plus") [type_name "num"; type_name "num"]. (* Not yet cover exp... Inductive exp : Set := | var : vname -> exp | con : cname -> exp | boolean : bool -> exp | num : Z -> exp | str : string -> exp | binary : binop -> exp -> exp -> exp | application : exp -> exp -> exp. *) Definition syntax_exp_decl := type_decl (type_name "exp") [exp_var_constr; exp_num_constr; exp_plus_constr]. Inductive exp_meta_base : val -> exp -> Prop := | exp_mb_var : forall v, exp_meta_base ([[ C # "var" #$ S # v ]]) (V @ v) | exp_mb_num : forall z : Z, exp_meta_base ([[ C # "num" #$ z ]]) z | exp_mb_plus : forall e1 e2 v1 v2, exp_meta_base e1 v1 -> exp_meta_base e2 v2 -> exp_meta_base ([[ C # "plus" #$ e1 #$ e2 ]]) (v1 +' v2) . Notation "x 'Me' #~> y" := (exp_meta_base x y) (at level 20). (* for procedure *) Definition proc_assign_constr := constr_def (constr_name "assign") [type_name "string"; type_name "exp"]. Definition proc_seq_constr := constr_def (constr_name "seq") [type_name "proc"; type_name "proc"]. (* Inductive proc : Set := | Pseq : proc -> proc -> proc | Pwhile : exp -> proc -> proc | Pmatch : exp -> list proc -> proc | Passign : vname -> exp -> proc | Pcall : pname -> proc . *) Definition syntax_proc_decl := type_decl (type_name "proc") [proc_assign_constr; proc_seq_constr]. Inductive proc_meta_base : val -> proc -> Prop := | proc_mb_assign : forall vn v e, exp_meta_base v e -> proc_meta_base ([[ C # "assign" #$ S # vn #$ v ]]) (vn :== e) | proc_mb_seq : forall v1 v2 p1 p2, proc_meta_base v1 p1 -> proc_meta_base v2 p2 -> proc_meta_base ([[ C # "seq" #$ v1 #$ v2 ]]) (p1 ;; p2) . Notation "x 'Mp' #~> y" := (proc_meta_base x y) (at level 25). (* Variable syntax_type_decl : declaration. Definition meta_module := ("meta_syntax", [syntax_proc_decl; syntax_func_decl; syntax_type_decl]). *) Definition test_program_data := (C @ "assign" $ S @ "a" $ (C @ "num" $ 10)). (* a := 10 という文vを作るプログラム *) Definition test_program := "v" :== test_program_data. Goal [] ||- {- True -} test_program {- (forall v p, V @ "v" #~> v -> (v Mp #~> p) -> ([] ||- {- True -} p {-V @ "a" #~> 10 -})) -}. unfold test_program. apply Vweaken with (P := forall (v : val) (p : proc), test_program_data #~> v -> v Mp #~> p -> [] ||- {- True -} p {- V @ "a" #~> 10%Z -}); unfold test_program_data. apply Vassign with (P := fun e => forall (v : val) (p : proc), e #~> v -> v Mp #~> p -> [] ||- {- True -} p {- V @ "a" #~> 10 -}). intro. intros. inversion H0; clear H0; subst. inversion H2; clear H2; subst. inversion H4; clear H4; subst. inversion H3; clear H3; subst. inversion H6; clear H6; subst. inversion H7; clear H7; subst. inversion H2. inversion H0; clear H0; subst. inversion H4; clear H4; subst. inversion H6; clear H6; subst. inversion H0. inversion H1; clear H1; subst. inversion H4; clear H4; subst. eapply Vweaken. eapply Vassign with (P := fun v => v #~> 10). intro. constructor. Qed. (* "a := 10; a := a + 10" *) Definition test_program2_data := C @ "seq" $ (C @ "assign" $ S @ "a" $ (C @ "num" $ 10)) $ (C @ "assign" $ S @ "a" $ (C @ "plus" $ (C @ "var" $ S @ "a") $ (C @ "num" $ 10))). Definition test_program2 := "v" :== test_program2_data. Goal verify [] test_program2 True (forall v p, exp_val (var (var_name "v")) v -> proc_meta_base v p -> verify [] p True (exp_val (var (var_name "a")) (num_val 20%Z))). unfold test_program2. apply Vweaken with (P := forall (v : val) (p : proc), test_program2_data #~> v -> v Mp #~> p -> [] ||- {- True -} p {- V @ "a" #~> 20 -}). apply Vassign with (P := fun e => forall (v : val) (p : proc), e #~> v -> v Mp #~> p -> [] ||- {- True -} p {- V @ "a" #~> 20 -}). intro H; clear H. intros. unfold test_program2_data in H. (* evaluation of expression *) inversion H; clear H; subst. inversion H1; clear H1; subst. inversion H3; clear H3; subst. inversion H2; clear H2; subst. inversion H5; clear H5; subst. inversion H; clear H; subst. inversion H3; clear H3; subst. inversion H2; clear H2; subst. inversion H5; clear H5; subst. inversion H; clear H; subst. inversion H3; clear H3; subst. inversion H2; clear H2; subst. inversion H5; clear H5; subst. inversion H; clear H; subst. inversion H3; clear H3; subst. inversion H5; clear H5; subst. inversion H. inversion H6; clear H6; subst. inversion H7; clear H7; subst. inversion H1. inversion H; clear H; subst. inversion H3; clear H3; subst. inversion H2; clear H2; subst. inversion H5; clear H5; subst. inversion H; clear H; subst. inversion H3; clear H3; subst. inversion H5; clear H5; subst. inversion H. inversion H6; clear H6; subst. inversion H. inversion H8; clear H8; subst. inversion H; clear H; subst. inversion H3; clear H3; subst. inversion H5; clear H5; subst. inversion H. (* meta-to-base *) inversion H0; clear H0; subst. inversion H2; clear H2; subst. inversion H3; clear H3; subst. inversion H4; clear H4; subst. inversion H2; clear H2; subst. inversion H1; clear H1; subst. inversion H4; clear H4; subst. (* generated program verification *) apply Vweaken with (P := 10 +' 10 #~> 20%Z). eapply Vseq. apply Vassign with (P := fun e => e +' 10 #~> 20). apply Vassign with (P := fun e => e #~> 20). (* なんでapplyだけじゃうまく行かないのかよく分からない *) intro H; clear H. eapply val_binop. apply val_num. apply val_num. constructor. Qed.
theory prop_07 imports Main "../../TestTheories/Listi" "../../TestTheories/Naturals" "$HIPSTER_HOME/IsaHipster" begin theorem lemma_aa : "len (maps x2 y2) = len y2" by hipster_induct_schemes end
function results = vl_test_ikmeans(varargin) % VL_TEST_IKMEANS vl_test_init ; function s = setup() rand('state',0) ; s.data = uint8(rand(2,1000) * 255) ; function test_basic(s) [centers, assign] = vl_ikmeans(s.data,100) ; assign_ = vl_ikmeanspush(s.data, centers) ; vl_assert_equal(assign,assign_) ; function test_elkan(s) [centers, assign] = vl_ikmeans(s.data,100,'method','elkan') ; assign_ = vl_ikmeanspush(s.data, centers) ; vl_assert_equal(assign,assign_) ;
import tactic.basic import tactic.ext import data.set.basic meta def my_tactic : tactic unit := `[exact 7, refl] example : ∃ (n : ℕ), n = 7 := begin split, swap, my_tactic, end meta def my_tactic_5 : tactic unit := do `[induction a], tactic.reflexivity, `[simpa]
/- Copyright (c) 2022 María Inés de Frutos-Fernández. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: María Inés de Frutos-Fernández -/ import algebraic_geometry.prime_spectrum.basic import ring_theory.dedekind_domain.ideal import topology.algebra.valued_field /-! # Adic valuations on Dedekind domains Given a Dedekind domain `R` of Krull dimension 1 and a maximal ideal `v` of `R`, we define the `v`-adic valuation on `R` and its extension to the field of fractions `K` of `R`. We prove several properties of this valuation, including the existence of uniformizers. ## Main definitions - `maximal_spectrum` defines the set of nonzero prime ideals of `R`. When `R` is a Dedekind domain of Krull dimension 1, this is the set of maximal ideals of `R`. - `maximal_spectrum.int_valuation v` is the `v`-adic valuation on `R`. - `maximal_spectrum.valuation v` is the `v`-adic valuation on `K`. ## Main results - `int_valuation_le_one` : The `v`-adic valuation on `R` is bounded above by 1. - `int_valuation_lt_one_iff_dvd` : The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. - `int_valuation_le_pow_iff_dvd` : The `v`-adic valuation of `r ∈ R` is less than or equal to `multiplicative.of_add (-n)` if and only if `vⁿ` divides the ideal `(r)`. - `int_valuation_exists_uniformizer` : There exists `π ∈ R` with `v`-adic valuation `multiplicative.of_add (-1)`. - `valuation_well_defined` : The valuation of `k ∈ K` is independent on how we express `k` as a fraction. - `valuation_of_mk'` : The `v`-adic valuation of `r/s ∈ K` is the valuation of `r` divided by the valuation of `s`. - `valuation_of_algebra_map` : The `v`-adic valuation on `K` extends the `v`-adic valuation on `R`. - `valuation_exists_uniformizer` : There exists `π ∈ K` with `v`-adic valuation `multiplicative.of_add (-1)`. ## Implementation notes We are only interested in Dedekind domains with Krull dimension 1. Dedekind domains of Krull dimension 0 are fields, and for them `maximal_spectrum` is the empty set, which does not agree with the set of maximal ideals (which is {(0)}). Most of the code in this file has already been incorporated to mathlib and can be found in the files `ring_theory/dedekind_domain/ideal.lean` and `ring_theory/dedekind_domain/adic_valuation.lean`. Note that `maximal_spectrum` is called `height_one_spectrum` there, and that some of the names of definitions and lemmas have been modified. We keep this version of the code here so that this branch contains all of the code referred to in the article "Formalizing the Rings of Adèles of a Global Field". ## References * [G. J. Janusz, *Algebraic Number Fields*][janusz1996] * [J.W.S. Cassels, A. Frölich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring, adic valuation -/ noncomputable theory open_locale classical variables (R : Type*) [comm_ring R] [is_domain R] [is_dedekind_domain R] {K : Type*} [field K] [algebra R K] [is_fraction_ring R K] /-! ### Maximal spectrum of a Dedekind domain If `R` is a Dedekind domain of Krull dimension 1, the maximal ideals of `R` are exactly its nonzero prime ideals. We define `maximal_spectrum` and provide lemmas to recover the facts that maximal ideals are prime and irreducible. -/ /-- The maximal spectrum of a Dedekind domain `R` of Krull dimension 1 is its set of nonzero prime ideals. Note that this is not the maximal spectrum if `R` has Krull dimension 0. -/ @[ext, nolint has_inhabited_instance unused_arguments] structure maximal_spectrum := (as_ideal : ideal R) (is_prime : as_ideal.is_prime) (ne_bot : as_ideal ≠ ⊥) variables (v : maximal_spectrum R) {R} --Maximal spectrum lemmas lemma maximal_spectrum.prime (v : maximal_spectrum R) : prime v.as_ideal := ideal.prime_of_is_prime v.ne_bot v.is_prime lemma maximal_spectrum.irreducible (v : maximal_spectrum R) : irreducible v.as_ideal := begin rw [unique_factorization_monoid.irreducible_iff_prime], apply v.prime, end lemma maximal_spectrum.associates_irreducible (v : maximal_spectrum R) : irreducible (associates.mk v.as_ideal) := begin rw [associates.irreducible_mk _], apply v.irreducible, end /-! ### Auxiliary lemmas We provide auxiliary lemmas about `multiplicative.of_add`, `is_localization`, `associates` and `ideal`. They will be moved to the appropriate files when the code is integrated in `mathlib`. -/ -- of_add lemmas lemma of_add_le (α : Type*) [partial_order α] (x y : α) : multiplicative.of_add x ≤ multiplicative.of_add y ↔ x ≤ y := by refl lemma of_add_lt (α : Type*) [partial_order α] (x y : α) : multiplicative.of_add x < multiplicative.of_add y ↔ x < y := by refl lemma of_add_inj (α : Type*) (x y : α) (hxy : multiplicative.of_add x = multiplicative.of_add y) : x = y := by rw [← to_add_of_add x, ← to_add_of_add y, hxy] variables {A : Type*} [comm_ring A] [is_domain A] {S : Type*} [field S] [algebra A S] [is_fraction_ring A S] lemma is_localization.mk'_eq_zero {r : A} {s : non_zero_divisors A} (h : is_localization.mk' S r s = 0) : r = 0 := begin rw [is_fraction_ring.mk'_eq_div, div_eq_zero_iff] at h, apply is_fraction_ring.injective A S, rw (algebra_map A S).map_zero, exact or.resolve_right h (is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors s.property) end variable (S) lemma is_localization.mk'_eq_one {r : A} {s : non_zero_divisors A} (h : is_localization.mk' S r s = 1) : r = s := begin rw [is_fraction_ring.mk'_eq_div, div_eq_one_iff_eq] at h, { exact is_fraction_ring.injective A S h }, { exact is_fraction_ring.to_map_ne_zero_of_mem_non_zero_divisors s.property } end -- Ideal lemmas lemma ideal.mem_pow_count {x : R} (hx : x ≠ 0) {I : ideal R} (hI : irreducible I) : x ∈ I^((associates.mk I).count (associates.mk (ideal.span {x})).factors) := begin have hx' := associates.mk_ne_zero'.mpr hx, rw [← associates.le_singleton_iff, associates.prime_pow_dvd_iff_le hx' ((associates.irreducible_mk I).mpr hI)], end namespace maximal_spectrum /-! ### Adic valuations on the Dedekind domain R -/ /-- The additive `v`-adic valuation of `r ∈ R` is the exponent of `v` in the factorization of the ideal `(r)`, if `r` is nonzero, or infinity, if `r = 0`. `int_valuation_def` is the corresponding multiplicative valuation. -/ def int_valuation_def (r : R) : with_zero (multiplicative ℤ) := if r = 0 then 0 else multiplicative.of_add (-(associates.mk v.as_ideal).count (associates.mk (ideal.span {r} : ideal R)).factors : ℤ) lemma int_valuation_def_if_pos {r : R} (hr : r = 0) : v.int_valuation_def r = 0 := if_pos hr lemma int_valuation_def_if_neg {r : R} (hr : r ≠ 0) : v.int_valuation_def r = (multiplicative.of_add (-(associates.mk v.as_ideal).count (associates.mk (ideal.span {r} : ideal R)).factors : ℤ)) := if_neg hr /-- Nonzero elements have nonzero adic valuation. -/ lemma int_valuation_ne_zero (x : R) (hx : x ≠ 0) : v.int_valuation_def x ≠ 0 := begin rw [int_valuation_def, if_neg hx], exact with_zero.coe_ne_zero, end /-- Nonzero divisors have nonzero valuation. -/ lemma int_valuation_ne_zero' (x : non_zero_divisors R) : v.int_valuation_def x ≠ 0 := v.int_valuation_ne_zero x (non_zero_divisors.coe_ne_zero x) /-- Nonzero divisors have valuation greater than zero. -/ lemma int_valuation_zero_le (x : non_zero_divisors R) : 0 < v.int_valuation_def x := begin rw [v.int_valuation_def_if_neg (non_zero_divisors.coe_ne_zero x)], exact with_zero.zero_lt_coe _, end /-- The `v`-adic valuation on `R` is bounded above by 1. -/ lemma int_valuation_le_one (x : R) : v.int_valuation_def x ≤ 1 := begin rw int_valuation_def, by_cases hx : x = 0, { rw if_pos hx, exact with_zero.zero_le 1 }, { rw [if_neg hx, ← with_zero.coe_one, ← of_add_zero, with_zero.coe_le_coe, of_add_le, right.neg_nonpos_iff], exact int.coe_nat_nonneg _ } end /-- The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. -/ lemma int_valuation_lt_one_iff_dvd (r : R) : v.int_valuation_def r < 1 ↔ v.as_ideal ∣ ideal.span {r} := begin rw int_valuation_def, split_ifs with hr, { simpa [hr] using (with_zero.zero_lt_coe _) }, { rw [← with_zero.coe_one, ← of_add_zero, with_zero.coe_lt_coe, of_add_lt, neg_lt_zero, ← int.coe_nat_zero, int.coe_nat_lt, zero_lt_iff], have h : (ideal.span {r} : ideal R) ≠ 0, { rw [ne.def, ideal.zero_eq_bot, ideal.span_singleton_eq_bot], exact hr }, apply associates.count_ne_zero_iff_dvd h (by apply v.irreducible) } end /-- The `v`-adic valuation of `r ∈ R` is less than `multiplicative.of_add (-n)` if and only if `vⁿ` divides the ideal `(r)`. -/ lemma int_valuation_le_pow_iff_dvd (r : R) (n : ℕ) : v.int_valuation_def r ≤ multiplicative.of_add (-(n : ℤ)) ↔ v.as_ideal^n ∣ ideal.span {r} := begin rw int_valuation_def, split_ifs with hr, { simp_rw [hr, ideal.dvd_span_singleton, zero_le', submodule.zero_mem], }, { rw [with_zero.coe_le_coe, of_add_le, neg_le_neg_iff, int.coe_nat_le, ideal.dvd_span_singleton, ← associates.le_singleton_iff, associates.prime_pow_dvd_iff_le (associates.mk_ne_zero'.mpr hr) (by apply v.associates_irreducible)] } end /-- The `v`-adic valuation of `0 : R` equals 0. -/ lemma int_valuation.map_zero' : v.int_valuation_def 0 = 0 := v.int_valuation_def_if_pos (eq.refl 0) /-- The `v`-adic valuation of `1 : R` equals 1. -/ lemma int_valuation.map_one' : v.int_valuation_def 1 = 1 := by rw [v.int_valuation_def_if_neg (zero_ne_one.symm : (1 : R) ≠ 0), ideal.span_singleton_one, ← ideal.one_eq_top, associates.mk_one, associates.factors_one, associates.count_zero (by apply v.associates_irreducible), int.coe_nat_zero, neg_zero, of_add_zero, with_zero.coe_one] /-- The `v`-adic valuation of a product equals the product of the valuations. -/ lemma int_valuation.map_mul' (x y : R) : v.int_valuation_def (x * y) = v.int_valuation_def x * v.int_valuation_def y := begin simp only [int_valuation_def], by_cases hx : x = 0, { rw [hx, zero_mul, if_pos (eq.refl _), zero_mul] }, { by_cases hy : y = 0, { rw [hy, mul_zero, if_pos (eq.refl _), mul_zero] }, { rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← with_zero.coe_mul, with_zero.coe_inj, ← of_add_add, ← ideal.span_singleton_mul_span_singleton, ← associates.mk_mul_mk, ← neg_add, associates.count_mul (by apply associates.mk_ne_zero'.mpr hx) (by apply associates.mk_ne_zero'.mpr hy) (by apply v.associates_irreducible)], refl }} end lemma int_valuation.le_max_iff_min_le {a b c : ℕ} : multiplicative.of_add(-c : ℤ) ≤ max (multiplicative.of_add(-a : ℤ)) (multiplicative.of_add(-b : ℤ)) ↔ min a b ≤ c := by rw [le_max_iff, of_add_le, of_add_le, neg_le_neg_iff, neg_le_neg_iff, int.coe_nat_le, int.coe_nat_le, ← min_le_iff] /- @[simp] lemma with_zero.le_max_iff {M : Type} [linear_ordered_comm_monoid M] {a b c : M} : (a : with_zero M) ≤ max b c ↔ a ≤ max b c := by simp only [with_zero.coe_le_coe, le_max_iff] -/ /-- The `v`-adic valuation of a sum is bounded above by the maximum of the valuations. -/ lemma int_valuation.map_add_le_max' (x y : R) : v.int_valuation_def (x + y) ≤ max (v.int_valuation_def x) (v.int_valuation_def y) := begin by_cases hx : x = 0, { rw [hx, zero_add], conv_rhs {rw [int_valuation_def, if_pos (eq.refl _)]}, rw max_eq_right (with_zero.zero_le (v.int_valuation_def y)), exact le_refl _, }, { by_cases hy : y = 0, { rw [hy, add_zero], conv_rhs {rw [max_comm, int_valuation_def, if_pos (eq.refl _)]}, rw max_eq_right (with_zero.zero_le (v.int_valuation_def x)), exact le_refl _ }, { by_cases hxy : x + y = 0, { rw [int_valuation_def, if_pos hxy], exact zero_le',}, { rw [v.int_valuation_def_if_neg hxy, v.int_valuation_def_if_neg hx, v.int_valuation_def_if_neg hy, with_zero.le_max_iff, int_valuation.le_max_iff_min_le], set nmin := min ((associates.mk v.as_ideal).count (associates.mk (ideal.span {x})).factors) ((associates.mk v.as_ideal).count (associates.mk (ideal.span {y})).factors), have h_dvd_x : x ∈ v.as_ideal ^ (nmin), { rw [← associates.le_singleton_iff x nmin _, associates.prime_pow_dvd_iff_le (associates.mk_ne_zero'.mpr hx) _], exact min_le_left _ _, apply v.associates_irreducible }, have h_dvd_y : y ∈ v.as_ideal ^ nmin, { rw [← associates.le_singleton_iff y nmin _, associates.prime_pow_dvd_iff_le (associates.mk_ne_zero'.mpr hy) _], exact min_le_right _ _, apply v.associates_irreducible }, have h_dvd_xy : associates.mk v.as_ideal^nmin ≤ associates.mk (ideal.span {x + y}), { rw associates.le_singleton_iff, exact ideal.add_mem (v.as_ideal^nmin) h_dvd_x h_dvd_y, }, rw (associates.prime_pow_dvd_iff_le (associates.mk_ne_zero'.mpr hxy) _) at h_dvd_xy, exact h_dvd_xy, apply v.associates_irreducible, }}} end /-- The `v`-adic valuation on `R`. -/ def int_valuation : valuation R (with_zero (multiplicative ℤ)) := { to_fun := v.int_valuation_def, map_zero' := int_valuation.map_zero' v, map_one' := int_valuation.map_one' v, map_mul' := int_valuation.map_mul' v, map_add_le_max' := int_valuation.map_add_le_max' v } lemma int_valuation_apply (r : R) : v.int_valuation r = v.int_valuation_def r := rfl /-- There exists `π ∈ R` with `v`-adic valuation `multiplicative.of_add (-1)`. -/ lemma int_valuation_exists_uniformizer : ∃ (π : R), v.int_valuation_def π = multiplicative.of_add (-1 : ℤ) := begin have hv : _root_.irreducible (associates.mk v.as_ideal) := v.associates_irreducible, have hlt : v.as_ideal^2 < v.as_ideal, { rw ← ideal.dvd_not_unit_iff_lt, exact ⟨v.ne_bot, v.as_ideal, (not_congr ideal.is_unit_iff).mpr (ideal.is_prime.ne_top v.is_prime), sq v.as_ideal⟩ } , obtain ⟨π, mem, nmem⟩ := set_like.exists_of_lt hlt, have hπ : associates.mk (ideal.span {π}) ≠ 0, { rw associates.mk_ne_zero', intro h, rw h at nmem, exact nmem (submodule.zero_mem (v.as_ideal^2)), }, use π, rw [int_valuation_def, if_neg (associates.mk_ne_zero'.mp hπ), with_zero.coe_inj], apply congr_arg, rw [neg_inj, ← int.coe_nat_one, int.coe_nat_inj'], rw [← ideal.dvd_span_singleton, ← associates.mk_le_mk_iff_dvd_iff] at mem nmem, rw [← pow_one ( associates.mk v.as_ideal), associates.prime_pow_dvd_iff_le hπ hv] at mem, rw [associates.mk_pow, associates.prime_pow_dvd_iff_le hπ hv, not_le] at nmem, exact nat.eq_of_le_of_lt_succ mem nmem, end /-! ### Adic valuations on the field of fractions `K` -/ /-- The `v`-adic valuation of `x ∈ K` is the valuation of `r` divided by the valuation of `s`, where `r` and `s` are chosen so that `x = r/s`. -/ def valuation_def (x : K) : (with_zero (multiplicative ℤ)) := let s := classical.some (classical.some_spec (is_localization.mk'_surjective (non_zero_divisors R) x)) in (v.int_valuation_def (classical.some (is_localization.mk'_surjective (non_zero_divisors R) x)))/(v.int_valuation_def s) variable (K) /-- The valuation of `k ∈ K` is independent on how we express `k` as a fraction. -/ lemma valuation_well_defined {r r' : R} {s s' : non_zero_divisors R} (h_mk : is_localization.mk' K r s = is_localization.mk' K r' s') : (v.int_valuation_def r)/(v.int_valuation_def s) = (v.int_valuation_def r')/(v.int_valuation_def s') := begin rw [div_eq_div_iff (int_valuation_ne_zero' v s) (int_valuation_ne_zero' v s'), ← int_valuation.map_mul', ← int_valuation.map_mul', is_fraction_ring.injective R K (is_localization.mk'_eq_iff_eq.mp h_mk)], end /-- The `v`-adic valuation of `r/s ∈ K` is the valuation of `r` divided by the valuation of `s`. -/ lemma valuation_of_mk' {r : R} {s : non_zero_divisors R} : v.valuation_def (is_localization.mk' K r s) = (v.int_valuation_def r)/(v.int_valuation_def s) := begin rw valuation_def, exact valuation_well_defined K v (classical.some_spec (classical.some_spec (is_localization.mk'_surjective (non_zero_divisors R) (is_localization.mk' K r s)))), end variable {K} /-- The `v`-adic valuation on `K` extends the `v`-adic valuation on `R`. -/ lemma valuation_of_algebra_map {r : R} : v.valuation_def (algebra_map R K r) = v.int_valuation_def r := by rw [← is_localization.mk'_one K r, valuation_of_mk', submonoid.coe_one, int_valuation.map_one', div_one _] /-- The `v`-adic valuation on `R` is bounded above by 1. -/ lemma valuation_le_one (r : R) : v.valuation_def (algebra_map R K r) ≤ 1 := by { rw valuation_of_algebra_map, exact v.int_valuation_le_one r } /-- The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. -/ lemma valuation_lt_one_iff_dvd (r : R) : v.valuation_def (algebra_map R K r) < 1 ↔ v.as_ideal ∣ ideal.span {r} := by { rw valuation_of_algebra_map, exact v.int_valuation_lt_one_iff_dvd r } /-- The `v`-adic valuation of `0 : K` equals 0. -/ lemma valuation.map_zero' (v : maximal_spectrum R) : v.valuation_def (0 : K) = 0 := begin rw [← (algebra_map R K).map_zero, valuation_of_algebra_map v], exact v.int_valuation.map_zero', end /-- The `v`-adic valuation of `1 : K` equals 1. -/ lemma valuation.map_one' (v : maximal_spectrum R) : v.valuation_def (1 : K) = 1 := begin rw [← (algebra_map R K).map_one, valuation_of_algebra_map v], exact v.int_valuation.map_one', end /-- The `v`-adic valuation of a product is the product of the valuations. -/ lemma valuation.map_mul' (v : maximal_spectrum R) (x y : K) : v.valuation_def (x * y) = v.valuation_def x * v.valuation_def y := begin rw [valuation_def, valuation_def, valuation_def, div_mul_div_comm₀, ← int_valuation.map_mul', ← int_valuation.map_mul', ← submonoid.coe_mul], apply valuation_well_defined K v, rw [(classical.some_spec (valuation_def._proof_2 (x * y))), is_fraction_ring.mk'_eq_div, (algebra_map R K).map_mul, submonoid.coe_mul, (algebra_map R K).map_mul, ← div_mul_div_comm₀, ← is_fraction_ring.mk'_eq_div, ← is_fraction_ring.mk'_eq_div, (classical.some_spec (valuation_def._proof_2 x)), (classical.some_spec (valuation_def._proof_2 y))], end /-- The `v`-adic valuation of a sum is bounded above by the maximum of the valuations. -/ lemma valuation.map_add_le_max' (v : maximal_spectrum R) (x y : K) : v.valuation_def (x + y) ≤ max (v.valuation_def x) (v.valuation_def y) := begin obtain ⟨rx, sx, hx⟩ := is_localization.mk'_surjective (non_zero_divisors R) x, obtain ⟨rxy, sxy, hxy⟩ := is_localization.mk'_surjective (non_zero_divisors R) (x + y), obtain ⟨ry, sy, hy⟩ := is_localization.mk'_surjective (non_zero_divisors R) y, rw [← hxy, ← hx, ← hy, valuation_of_mk', valuation_of_mk', valuation_of_mk'], have h_frac_xy : is_localization.mk' K rxy sxy = is_localization.mk' K (rx*(sy : R) + ry*(sx : R)) (sx*sy), { rw [is_localization.mk'_add, hx, hy, hxy], }, have h_frac_x : is_localization.mk' K rx sx = is_localization.mk' K (rx*(sy : R)) (sx*sy), { rw [is_localization.mk'_eq_iff_eq, submonoid.coe_mul, mul_assoc, mul_comm (sy : R) _], }, have h_frac_y : is_localization.mk' K ry sy = is_localization.mk' K (ry*(sx : R)) (sx*sy), { rw [is_localization.mk'_eq_iff_eq, submonoid.coe_mul, mul_assoc], }, have h_denom : 0 < v.int_valuation_def ↑(sx * sy), { rw [int_valuation_def, if_neg _], { exact with_zero.zero_lt_coe _ }, { exact non_zero_divisors.ne_zero (submonoid.mul_mem (non_zero_divisors R) sx.property sy.property), }}, rw [valuation_well_defined K v h_frac_x, valuation_well_defined K v h_frac_y, valuation_well_defined K v h_frac_xy, le_max_iff, div_le_div_right₀ (ne_of_gt h_denom), div_le_div_right₀ (ne_of_gt h_denom), ← le_max_iff], exact v.int_valuation.map_add_le_max' _ _, end /-- The `v`-adic valuation on `K`. -/ def valuation (v : maximal_spectrum R) : valuation K (with_zero (multiplicative ℤ)) := { to_fun := v.valuation_def, map_zero' := valuation.map_zero' v, map_one' := valuation.map_one' v, map_mul' := valuation.map_mul' v, map_add_le_max' := valuation.map_add_le_max' v } lemma valuation_apply (k : K) : v.valuation k = v.valuation_def k := rfl variable (K) /-- There exists `π ∈ K` with `v`-adic valuation `multiplicative.of_add (-1)`. -/ lemma valuation_exists_uniformizer : ∃ (π : K), v.valuation_def π = multiplicative.of_add (-1 : ℤ) := begin obtain ⟨r, hr⟩ := v.int_valuation_exists_uniformizer, use algebra_map R K r, rw valuation_of_algebra_map v, exact hr, end /-- Uniformizers are nonzero. -/ lemma valuation_uniformizer_ne_zero : (classical.some (v.valuation_exists_uniformizer K)) ≠ 0 := begin have hu := (classical.some_spec (v.valuation_exists_uniformizer K)), have h : v.valuation_def (classical.some _) = valuation v (classical.some _) := rfl, rw h at hu, exact (valuation.ne_zero_iff _).mp (ne_of_eq_of_ne hu with_zero.coe_ne_zero), end end maximal_spectrum
sucesses = @parallel (+) for i in 1:10^8 Int(any(bitrand(3))) end
using Optim export CFADistributionEM, CFADistributionEMRidge "Confirmatory factor analysis distribution object with a Sigma formulation." type CFADistributionEM Sigma_X::SparseMatrixCSC A::SparseMatrixCSC Sigma_L::AbstractMatrix end Base.length(d::CFADistributionEM) = Int(size(d.A)[1] + nnz(d.A) + (size(d.A)[2]-1)*size(d.A)[2]/2) function Base.rand(d::CFADistributionEM, N::Int) P,K = size(d.A) distL = MvNormal(zeros(K), d.Sigma_L) L = rand(distL, N) X = d.A*L for i in 1:P X[i,:] .+= transpose(rand(Normal(0, d.Sigma_X.nzval[i]), N)) end X end Base.rand(d::CFADistributionEM) = rand(d::CFADistributionEM, 1) "Likelihood of model given the data represented by the covariance S from N samples" function Distributions.loglikelihood(d::CFADistributionEM, S::AbstractMatrix, N::Int64) #@assert minimum(d.Sigma_X.nzval) > 0.0 "Invalid CFADistributionEM! (Theta_X has elements <= 0)" #@assert minimum(eig(d.Sigma_L)[1]) > 0.0 "Invalid CFADistributionEM! (Theta_L has eigen value <= 0)" Theta_X = deepcopy(d.Sigma_X) Theta_X.nzval[:] = 1 ./ d.Sigma_X.nzval Theta_L = inv(d.Sigma_L) # Woodbury transformation of original form allows us to only compute a KxK inversion Theta = Theta_X - Theta_X*d.A*inv(Theta_L + d.A'*Theta_X*d.A)*d.A'*Theta_X @assert minimum(eig(Theta)[1]) > 0.0 "Invalid CFADistributionEM! (Theta has eigen value <= 0)" logdet(Theta) - trace(S*Theta) end function normalize_Sigma_L!(d::CFADistributionEM) scaling = sqrt(diag(d.Sigma_L)) Base.cov2cor!(d.Sigma_L, scaling) vals = nonzeros(d.A) K = size(d.A)[2] for col = 1:K for j in nzrange(d.A, col) vals[j] *= scaling[col] end end end " Run the EM algorithm to find the MLE fit." function Distributions.fit_mle(::Type{CFADistributionEM}, maskSigma_L::AbstractMatrix, A::SparseMatrixCSC, S::AbstractMatrix, N::Int64; iterations=1000, show_trace=true, ftol=1e-10) P,K = size(A) @assert size(maskSigma_L) == (K,K) "Sigma_L mask must be of size K x K (where K = size(A)[2])" #@assert size(maskL) == (K,K) "Sigma_L mask must be of size K x K (where K = size(A)[2])" # just to make sure it is a nice float data type inside our loop maskL = zeros(Float64, K, K) copy!(maskL, maskSigma_L) # init our parameters d = CFADistributionEM(speye(P), deepcopy(A), eye(K)) # find the latent vars each observed is attached to latentInds = Array{Int64}[find(d.A[i,:]) for i in 1:P] Theta_X = deepcopy(d.Sigma_X) lastScore = -Inf timeFindT = 0.0 timeFindW = 0.0 timeFindQ = 0.0 timeUpdateSigma_X = 0.0 timeUpdateA = 0.0 timeUpdateSigma_L = 0.0 stopCount = 0 for count in 1:iterations ## E-step t = time() for i in 1:P Theta_X.nzval[i] = 1/d.Sigma_X.nzval[i] end Theta_L = inv(d.Sigma_L) Theta = Theta_X - Theta_X*d.A*inv(Theta_L + d.A'*Theta_X*d.A)*d.A'*Theta_X #@assert maximum(abs(Theta .- inv(d.Sigma_X + d.A*d.Sigma_L*d.A'))) < 1e-6 T = Theta*d.A*d.Sigma_L timeFindT += time() - t # find W t = time() W = d.Sigma_L - d.Sigma_L*d.A'*Theta*d.A*d.Sigma_L timeFindW += time() - t # find Q (the expected covariance of the hidden variables) t = time() Q = T'*S*T + W #Base.cov2cor!(Q, sqrt(diag(Q))) timeFindQ += time() - t ## M-step # update A and Sigma_X t = time() tmpTS = T'*S # for i in 1:P # gi = grouping[i] # d.A[i,gi] = tmpTS[gi,i]/Q[gi,gi] # d.Sigma_X[i,i] = S[i,i] - (tmpTS[gi,i]^2)/Q[gi,gi] # end #At = d.A' #rows = rowvals(At) #vals = nonzeros(At) for row = 1:P # update Sigma_X inds = latentInds[row] tmp = tmpTS[inds,row] #println(inds, " ", collect(nzrange(At, col))) newLoadings = inv(Q[inds,inds])*tmp #println(S[col,col] - tmpTS[inds,col]'*newLoadings) d.Sigma_X.nzval[row] = (S[row,row] - tmp'*newLoadings)[1] # Update A for (i,ind) in enumerate(inds) d.A[row,ind] = newLoadings[i] end end #d.A = At' timeUpdateA += time() - t # update Sigma_L t = time() d.Sigma_L[:,:] = Q .* maskL # note we enforce the Sigma_L mask here timeUpdateSigma_L += time() - t # print our progress if count % 1000 == 0 && show_trace s = loglikelihood(d, S, N) println("likelihood $count = ", s, " ", s - lastScore) println("timeFindT = $timeFindT") println("timeFindW = $timeFindW") println("timeFindQ = $timeFindQ") println("timeUpdateSigma_X = $timeUpdateSigma_X") println("timeUpdateA = $timeUpdateA") println("timeUpdateSigma_L = $timeUpdateSigma_L") println(d.Sigma_L[1,1], " ", d.Sigma_L[1,2]) println() if s - lastScore < ftol stopCount += 1 end if stopCount > 5 break end lastScore = s end end normalize_Sigma_L!(d) d end type CFADistributionEMRidge rho::Float64 end " Run the EM algorithm to find the MAP fit." function fit_map(prior::CFADistributionEMRidge, ::Type{CFADistributionEM}, A::SparseMatrixCSC, S::AbstractMatrix, N::Int64; iterations=1000, show_trace=true, ftol=1e-10) P,K = size(A) # init our parameters d = CFADistributionEM(speye(P), deepcopy(A), eye(K)) Theta_X = deepcopy(d.Sigma_X) lastScore = -Inf timeFindT = 0.0 timeFindW = 0.0 timeFindQ = 0.0 timeUpdateSigma_X = 0.0 timeUpdateA = 0.0 timeUpdateSigma_L = 0.0 stopCount = 0 for count in 1:iterations ## E-step t = time() for i in 1:P Theta_X.nzval[i] = 1/d.Sigma_X.nzval[i] end Theta_L = inv(d.Sigma_L) Theta = Theta_X - Theta_X*d.A*inv(Theta_L + d.A'*Theta_X*d.A)*d.A'*Theta_X #Theta = inv(Sigma_X + A*Sigma_L*A') T = Theta*d.A*d.Sigma_L timeFindT += time() - t # find W t = time() W = d.Sigma_L - d.Sigma_L*d.A'*Theta*d.A*d.Sigma_L timeFindW += time() - t # find Q (the expected covariance of the hidden variables) t = time() Q = T'*S*T + W timeFindQ += time() - t ## M-step # update A and Sigma_X t = time() tmpTS = T'*S rows = rowvals(d.A) vals = nonzeros(d.A) for col = 1:K for j in nzrange(d.A, col) row = rows[j] d.Sigma_X.nzval[row] = S[row,row] - (tmpTS[col,row]^2)/Q[col,col] vals[j] = tmpTS[col,row]/Q[col,col] end end timeUpdateA += time() - t # update Sigma_L t = time() Base.cov2cor!(Q, sqrt(diag(Q))) d.Sigma_L[:,:] = Q + prior.rho*eye(K) Base.cov2cor!(d.Sigma_L, sqrt(diag(d.Sigma_L))) #Base.cov2cor!(d.Sigma_L, sqrt(prior.rho ./ (diag(Q) + prior.rho))) timeUpdateSigma_L += time() - t # print our progress if count % 1000 == 0 && show_trace s = loglikelihood(d, S, N) println("likelihood $count = ", s, " ", s - lastScore) println("timeFindT = $timeFindT") println("timeFindW = $timeFindW") println("timeFindQ = $timeFindQ") println("timeUpdateSigma_X = $timeUpdateSigma_X") println("timeUpdateA = $timeUpdateA") println("timeUpdateSigma_L = $timeUpdateSigma_L") println(d.Sigma_L[1,1], " ", d.Sigma_L[1,2]) println() if abs(s - lastScore) < ftol stopCount += 1 end if stopCount > 5 break end lastScore = s end end normalize_Sigma_L!(d) d end
Require Import Classes.Joinable. Require Export Base. Require Import Classes.Monad Classes.Monad.MonadState Types.State Classes.Galois Types.Option. Implicit Type S : Type. Implicit Type M : Type → Type. Instance store_stateT {S} {M} `{MM : Monad M} : MonadState S (StateT S M) := { get := λ st, returnM (st, st); put := λ st, λ _, returnM (tt, st); }. Instance get_store_stateT_sound {ST ST' : Type} {GS : Galois ST ST'} {M M' : Type → Type} `{MM : Monad M} `{MM' : Monad M'} {GM : ∀ A A', Galois A A' → Galois (M A) (M' A')} : return_sound M M' → get_state_sound (StateT ST M) (StateT ST' M'). Proof. intros RS. intros a a' Ha. apply returnM_sound. eauto with soundness. Qed. Hint Resolve get_store_stateT_sound : soundness. Instance put_store_stateT_sound {ST ST' : Type} {GS : Galois ST ST'} {M M' : Type → Type} `{MM : Monad M} `{MM' : Monad M'} {GM : ∀ A A', Galois A A' → Galois (M A) (M' A')} : return_sound M M' → put_state_sound (StateT ST M) (StateT ST' M'). Proof. intros RS s s' Hs. cbn. intros ???. apply RS. constructor; cbn. constructor. assumption. Qed. Hint Resolve put_store_stateT_sound : soundness. Instance store_optionT {ST} {M} `{MM : Monad M} {MS : MonadState ST M} : MonadState ST (optionT M) := { get := get >>= λ a, returnM (Some a); put := λ st, put st ;; returnM (Some tt); }. Instance get_store_optionT_sound {ST ST' : Type} {GST : Galois ST ST'} {M M' : Type → Type} `{MM : Monad M} `{MM' : Monad M'} {GM : ∀ A A', Galois A A' → Galois (M A) (M' A')} {MS : MonadState ST M} {MS' : MonadState ST' M'} : bind_sound M M' → return_sound M M' → get_state_sound M M' → get_state_sound (optionT M) (optionT M'). Proof. intros BS RS GS. unfold get_state_sound. unfold get; simpl. eapply BS; auto. intros a a' Ha. eauto with soundness. Qed. Hint Resolve get_store_optionT_sound : soundness. Instance store_optionAT {S} {JS: Joinable S S} {JI : JoinableIdem JS} : MonadState S (optionAT (StateT S option)) := { get := get >>= λ a, returnM (SomeA a); put := λ st, put st ;; returnM (SomeA tt); }. Instance get_store_optionAT_sound {S S' : Type} {GS : Galois S S'} {JS : Joinable S S} {JSI : JoinableIdem JS} : get_state_sound (optionAT (StateT S option)) (optionT (StateT S' option)). Proof. unfold get_state_sound, get; simpl. eauto with soundness. constructor; constructor; simpl; [constructor | ]; assumption. Qed. Hint Resolve get_store_optionAT_sound : soundness. Instance put_store_optionAT_sound {S S' : Type} {GS : Galois S S'} {JS : Joinable S S} {JI : JoinableIdem JS} : put_state_sound (optionAT (StateT S option)) (optionT (StateT S' option)). Proof. intros s s' Hs; cbn. unfold bindM; simpl; unfold bind_stateT. intros s2 s2' Hs2. unfold bindM; simpl; unfold bind_option. constructor. constructor; eauto with soundness. Qed. Hint Resolve put_store_optionAT_sound : soundness.
module Issue373 where data Nat : Set where zero : Nat suc : (n : Nat) → Nat {-# BUILTIN NATURAL Nat #-} {-# FOREIGN GHC data Nat = Zero | Suc Nat #-} {-# COMPILE GHC Nat = data Nat (Zero | Suc) #-} -- should fail when compiling
{-# OPTIONS --verbose=10 #-} module inorder where open import Data.Nat open import Data.Vec open import Agda.Builtin.Sigma open import Data.Product open import Data.Fin using (fromℕ) open import trees open import optics open import lemmas inorderTree : {A : Set} -> Tree A -> Σ[ n ∈ ℕ ] Vec A n × (Vec A n -> Tree A) inorderTree empty = (0 , ([] , λ _ -> empty)) inorderTree {A} (node t x t₁) with inorderTree t | inorderTree t₁ ... | (n₁ , (g₁ , p₁)) | (n₂ , (g₂ , p₂)) = (n₁ + (1 + n₂) , (g₁ ++ (x ∷ g₂) , λ v -> node (p₁ (take n₁ v)) (head (drop n₁ v)) (righttree v))) where righttree : Vec A (n₁ + (1 + n₂)) -> Tree A -- righttree v = p₂ (drop 1 (drop n₁ v)) righttree v rewrite +-suc n₁ n₂ = p₂ (drop (1 + n₁) v) inorder : {A : Set} -> Traversal (Tree A) (Tree A) A A inorder = record{ extract = inorderTree } module tests where tree1 : Tree ℕ tree1 = node (node empty 1 empty) 3 empty open Traversal inorder1 : Vec ℕ 2 inorder1 = get inorder tree1 updatedinorder1 : Tree ℕ updatedinorder1 = put inorder tree1 (2 ∷ 3 ∷ [])
lemma closure_cbox [simp]: "closure (cbox a b) = cbox a b"
(* Title: HOL/ex/LocaleTest2.thy Author: Clemens Ballarin Copyright (c) 2007 by Clemens Ballarin More regression tests for locales. Definitions are less natural in FOL, since there is no selection operator. Hence we do them here in HOL, not in the main test suite for locales, which is FOL/ex/LocaleTest.thy *) section \<open>Test of Locale Interpretation\<close> theory LocaleTest2 imports MainRLT begin section \<open>Interpretation of Defined Concepts\<close> text \<open>Naming convention for global objects: prefixes D and d\<close> subsection \<open>Lattices\<close> text \<open>Much of the lattice proofs are from HOL/Lattice.\<close> subsubsection \<open>Definitions\<close> locale dpo = fixes le :: "['a, 'a] => bool" (infixl "\<sqsubseteq>" 50) assumes refl [intro, simp]: "x \<sqsubseteq> x" and antisym [intro]: "[| x \<sqsubseteq> y; y \<sqsubseteq> x |] ==> x = y" and trans [trans]: "[| x \<sqsubseteq> y; y \<sqsubseteq> z |] ==> x \<sqsubseteq> z" begin theorem circular: "[| x \<sqsubseteq> y; y \<sqsubseteq> z; z \<sqsubseteq> x |] ==> x = y & y = z" by (blast intro: trans) definition less :: "['a, 'a] => bool" (infixl "\<sqsubset>" 50) where "(x \<sqsubset> y) = (x \<sqsubseteq> y & x ~= y)" theorem abs_test: "(\<sqsubset>) = (\<lambda>x y. x \<sqsubset> y)" by simp definition is_inf :: "['a, 'a, 'a] => bool" where "is_inf x y i = (i \<sqsubseteq> x \<and> i \<sqsubseteq> y \<and> (\<forall>z. z \<sqsubseteq> x \<and> z \<sqsubseteq> y \<longrightarrow> z \<sqsubseteq> i))" definition is_sup :: "['a, 'a, 'a] => bool" where "is_sup x y s = (x \<sqsubseteq> s \<and> y \<sqsubseteq> s \<and> (\<forall>z. x \<sqsubseteq> z \<and> y \<sqsubseteq> z \<longrightarrow> s \<sqsubseteq> z))" end locale dlat = dpo + assumes ex_inf: "\<exists>inf. dpo.is_inf le x y inf" and ex_sup: "\<exists>sup. dpo.is_sup le x y sup" begin definition meet :: "['a, 'a] => 'a" (infixl "\<sqinter>" 70) where "x \<sqinter> y = (THE inf. is_inf x y inf)" definition join :: "['a, 'a] => 'a" (infixl "\<squnion>" 65) where "x \<squnion> y = (THE sup. is_sup x y sup)" lemma is_infI [intro?]: "i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> (\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> is_inf x y i" by (unfold is_inf_def) blast lemma is_inf_lower [elim?]: "is_inf x y i \<Longrightarrow> (i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> C) \<Longrightarrow> C" by (unfold is_inf_def) blast lemma is_inf_greatest [elim?]: "is_inf x y i \<Longrightarrow> z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i" by (unfold is_inf_def) blast theorem is_inf_uniq: "is_inf x y i \<Longrightarrow> is_inf x y i' \<Longrightarrow> i = i'" proof - assume inf: "is_inf x y i" assume inf': "is_inf x y i'" show ?thesis proof (rule antisym) from inf' show "i \<sqsubseteq> i'" proof (rule is_inf_greatest) from inf show "i \<sqsubseteq> x" .. from inf show "i \<sqsubseteq> y" .. qed from inf show "i' \<sqsubseteq> i" proof (rule is_inf_greatest) from inf' show "i' \<sqsubseteq> x" .. from inf' show "i' \<sqsubseteq> y" .. qed qed qed theorem is_inf_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_inf x y x" proof - assume "x \<sqsubseteq> y" show ?thesis proof show "x \<sqsubseteq> x" .. show "x \<sqsubseteq> y" by fact fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" show "z \<sqsubseteq> x" by fact qed qed lemma meet_equality [elim?]: "is_inf x y i \<Longrightarrow> x \<sqinter> y = i" proof (unfold meet_def) assume "is_inf x y i" then show "(THE i. is_inf x y i) = i" by (rule the_equality) (rule is_inf_uniq [OF _ \<open>is_inf x y i\<close>]) qed lemma meetI [intro?]: "i \<sqsubseteq> x \<Longrightarrow> i \<sqsubseteq> y \<Longrightarrow> (\<And>z. z \<sqsubseteq> x \<Longrightarrow> z \<sqsubseteq> y \<Longrightarrow> z \<sqsubseteq> i) \<Longrightarrow> x \<sqinter> y = i" by (rule meet_equality, rule is_infI) blast+ lemma is_inf_meet [intro?]: "is_inf x y (x \<sqinter> y)" proof (unfold meet_def) from ex_inf obtain i where "is_inf x y i" .. then show "is_inf x y (THE i. is_inf x y i)" by (rule theI) (rule is_inf_uniq [OF _ \<open>is_inf x y i\<close>]) qed lemma meet_left [intro?]: "x \<sqinter> y \<sqsubseteq> x" by (rule is_inf_lower) (rule is_inf_meet) lemma meet_right [intro?]: "x \<sqinter> y \<sqsubseteq> y" by (rule is_inf_lower) (rule is_inf_meet) lemma meet_le [intro?]: "[| z \<sqsubseteq> x; z \<sqsubseteq> y |] ==> z \<sqsubseteq> x \<sqinter> y" by (rule is_inf_greatest) (rule is_inf_meet) lemma is_supI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> (\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> is_sup x y s" by (unfold is_sup_def) blast lemma is_sup_least [elim?]: "is_sup x y s \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z" by (unfold is_sup_def) blast lemma is_sup_upper [elim?]: "is_sup x y s \<Longrightarrow> (x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> C) \<Longrightarrow> C" by (unfold is_sup_def) blast theorem is_sup_uniq: "is_sup x y s \<Longrightarrow> is_sup x y s' \<Longrightarrow> s = s'" proof - assume sup: "is_sup x y s" assume sup': "is_sup x y s'" show ?thesis proof (rule antisym) from sup show "s \<sqsubseteq> s'" proof (rule is_sup_least) from sup' show "x \<sqsubseteq> s'" .. from sup' show "y \<sqsubseteq> s'" .. qed from sup' show "s' \<sqsubseteq> s" proof (rule is_sup_least) from sup show "x \<sqsubseteq> s" .. from sup show "y \<sqsubseteq> s" .. qed qed qed theorem is_sup_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> is_sup x y y" proof - assume "x \<sqsubseteq> y" show ?thesis proof show "x \<sqsubseteq> y" by fact show "y \<sqsubseteq> y" .. fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z" show "y \<sqsubseteq> z" by fact qed qed lemma join_equality [elim?]: "is_sup x y s \<Longrightarrow> x \<squnion> y = s" proof (unfold join_def) assume "is_sup x y s" then show "(THE s. is_sup x y s) = s" by (rule the_equality) (rule is_sup_uniq [OF _ \<open>is_sup x y s\<close>]) qed lemma joinI [intro?]: "x \<sqsubseteq> s \<Longrightarrow> y \<sqsubseteq> s \<Longrightarrow> (\<And>z. x \<sqsubseteq> z \<Longrightarrow> y \<sqsubseteq> z \<Longrightarrow> s \<sqsubseteq> z) \<Longrightarrow> x \<squnion> y = s" by (rule join_equality, rule is_supI) blast+ lemma is_sup_join [intro?]: "is_sup x y (x \<squnion> y)" proof (unfold join_def) from ex_sup obtain s where "is_sup x y s" .. then show "is_sup x y (THE s. is_sup x y s)" by (rule theI) (rule is_sup_uniq [OF _ \<open>is_sup x y s\<close>]) qed lemma join_left [intro?]: "x \<sqsubseteq> x \<squnion> y" by (rule is_sup_upper) (rule is_sup_join) lemma join_right [intro?]: "y \<sqsubseteq> x \<squnion> y" by (rule is_sup_upper) (rule is_sup_join) lemma join_le [intro?]: "[| x \<sqsubseteq> z; y \<sqsubseteq> z |] ==> x \<squnion> y \<sqsubseteq> z" by (rule is_sup_least) (rule is_sup_join) theorem meet_assoc: "(x \<sqinter> y) \<sqinter> z = x \<sqinter> (y \<sqinter> z)" proof (rule meetI) show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x \<sqinter> y" proof show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> x" .. show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y" proof - have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" .. also have "\<dots> \<sqsubseteq> y" .. finally show ?thesis . qed qed show "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> z" proof - have "x \<sqinter> (y \<sqinter> z) \<sqsubseteq> y \<sqinter> z" .. also have "\<dots> \<sqsubseteq> z" .. finally show ?thesis . qed fix w assume "w \<sqsubseteq> x \<sqinter> y" and "w \<sqsubseteq> z" show "w \<sqsubseteq> x \<sqinter> (y \<sqinter> z)" proof show "w \<sqsubseteq> x" proof - have "w \<sqsubseteq> x \<sqinter> y" by fact also have "\<dots> \<sqsubseteq> x" .. finally show ?thesis . qed show "w \<sqsubseteq> y \<sqinter> z" proof show "w \<sqsubseteq> y" proof - have "w \<sqsubseteq> x \<sqinter> y" by fact also have "\<dots> \<sqsubseteq> y" .. finally show ?thesis . qed show "w \<sqsubseteq> z" by fact qed qed qed theorem meet_commute: "x \<sqinter> y = y \<sqinter> x" proof (rule meetI) show "y \<sqinter> x \<sqsubseteq> x" .. show "y \<sqinter> x \<sqsubseteq> y" .. fix z assume "z \<sqsubseteq> y" and "z \<sqsubseteq> x" then show "z \<sqsubseteq> y \<sqinter> x" .. qed theorem meet_join_absorb: "x \<sqinter> (x \<squnion> y) = x" proof (rule meetI) show "x \<sqsubseteq> x" .. show "x \<sqsubseteq> x \<squnion> y" .. fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> x \<squnion> y" show "z \<sqsubseteq> x" by fact qed theorem join_assoc: "(x \<squnion> y) \<squnion> z = x \<squnion> (y \<squnion> z)" proof (rule joinI) show "x \<squnion> y \<sqsubseteq> x \<squnion> (y \<squnion> z)" proof show "x \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. show "y \<sqsubseteq> x \<squnion> (y \<squnion> z)" proof - have "y \<sqsubseteq> y \<squnion> z" .. also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. finally show ?thesis . qed qed show "z \<sqsubseteq> x \<squnion> (y \<squnion> z)" proof - have "z \<sqsubseteq> y \<squnion> z" .. also have "... \<sqsubseteq> x \<squnion> (y \<squnion> z)" .. finally show ?thesis . qed fix w assume "x \<squnion> y \<sqsubseteq> w" and "z \<sqsubseteq> w" show "x \<squnion> (y \<squnion> z) \<sqsubseteq> w" proof show "x \<sqsubseteq> w" proof - have "x \<sqsubseteq> x \<squnion> y" .. also have "\<dots> \<sqsubseteq> w" by fact finally show ?thesis . qed show "y \<squnion> z \<sqsubseteq> w" proof show "y \<sqsubseteq> w" proof - have "y \<sqsubseteq> x \<squnion> y" .. also have "... \<sqsubseteq> w" by fact finally show ?thesis . qed show "z \<sqsubseteq> w" by fact qed qed qed theorem join_commute: "x \<squnion> y = y \<squnion> x" proof (rule joinI) show "x \<sqsubseteq> y \<squnion> x" .. show "y \<sqsubseteq> y \<squnion> x" .. fix z assume "y \<sqsubseteq> z" and "x \<sqsubseteq> z" then show "y \<squnion> x \<sqsubseteq> z" .. qed theorem join_meet_absorb: "x \<squnion> (x \<sqinter> y) = x" proof (rule joinI) show "x \<sqsubseteq> x" .. show "x \<sqinter> y \<sqsubseteq> x" .. fix z assume "x \<sqsubseteq> z" and "x \<sqinter> y \<sqsubseteq> z" show "x \<sqsubseteq> z" by fact qed theorem meet_idem: "x \<sqinter> x = x" proof - have "x \<sqinter> (x \<squnion> (x \<sqinter> x)) = x" by (rule meet_join_absorb) also have "x \<squnion> (x \<sqinter> x) = x" by (rule join_meet_absorb) finally show ?thesis . qed theorem meet_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<sqinter> y = x" proof (rule meetI) assume "x \<sqsubseteq> y" show "x \<sqsubseteq> x" .. show "x \<sqsubseteq> y" by fact fix z assume "z \<sqsubseteq> x" and "z \<sqsubseteq> y" show "z \<sqsubseteq> x" by fact qed theorem meet_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<sqinter> y = y" by (drule meet_related) (simp add: meet_commute) theorem join_related [elim?]: "x \<sqsubseteq> y \<Longrightarrow> x \<squnion> y = y" proof (rule joinI) assume "x \<sqsubseteq> y" show "y \<sqsubseteq> y" .. show "x \<sqsubseteq> y" by fact fix z assume "x \<sqsubseteq> z" and "y \<sqsubseteq> z" show "y \<sqsubseteq> z" by fact qed theorem join_related2 [elim?]: "y \<sqsubseteq> x \<Longrightarrow> x \<squnion> y = x" by (drule join_related) (simp add: join_commute) text \<open>Additional theorems\<close> theorem meet_connection: "(x \<sqsubseteq> y) = (x \<sqinter> y = x)" proof assume "x \<sqsubseteq> y" then have "is_inf x y x" .. then show "x \<sqinter> y = x" .. next have "x \<sqinter> y \<sqsubseteq> y" .. also assume "x \<sqinter> y = x" finally show "x \<sqsubseteq> y" . qed theorem meet_connection2: "(x \<sqsubseteq> y) = (y \<sqinter> x = x)" using meet_commute meet_connection by simp theorem join_connection: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" proof assume "x \<sqsubseteq> y" then have "is_sup x y y" .. then show "x \<squnion> y = y" .. next have "x \<sqsubseteq> x \<squnion> y" .. also assume "x \<squnion> y = y" finally show "x \<sqsubseteq> y" . qed theorem join_connection2: "(x \<sqsubseteq> y) = (x \<squnion> y = y)" using join_commute join_connection by simp text \<open>Naming according to Jacobson I, p.\ 459.\<close> lemmas L1 = join_commute meet_commute lemmas L2 = join_assoc meet_assoc (*lemmas L3 = join_idem meet_idem*) lemmas L4 = join_meet_absorb meet_join_absorb end locale ddlat = dlat + assumes meet_distr: "dlat.meet le x (dlat.join le y z) = dlat.join le (dlat.meet le x y) (dlat.meet le x z)" begin lemma join_distr: "x \<squnion> (y \<sqinter> z) = (x \<squnion> y) \<sqinter> (x \<squnion> z)" txt \<open>Jacobson I, p.\ 462\<close> proof - have "x \<squnion> (y \<sqinter> z) = (x \<squnion> (x \<sqinter> z)) \<squnion> (y \<sqinter> z)" by (simp add: L4) also have "... = x \<squnion> ((x \<sqinter> z) \<squnion> (y \<sqinter> z))" by (simp add: L2) also have "... = x \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 meet_distr) also have "... = ((x \<squnion> y) \<sqinter> x) \<squnion> ((x \<squnion> y) \<sqinter> z)" by (simp add: L1 L4) also have "... = (x \<squnion> y) \<sqinter> (x \<squnion> z)" by (simp add: meet_distr) finally show ?thesis . qed end locale dlo = dpo + assumes total: "x \<sqsubseteq> y | y \<sqsubseteq> x" begin lemma less_total: "x \<sqsubset> y | x = y | y \<sqsubset> x" using total by (unfold less_def) blast end sublocale dlo < dlat proof fix x y from total have "is_inf x y (if x \<sqsubseteq> y then x else y)" by (auto simp: is_inf_def) then show "\<exists>inf. is_inf x y inf" by blast next fix x y from total have "is_sup x y (if x \<sqsubseteq> y then y else x)" by (auto simp: is_sup_def) then show "\<exists>sup. is_sup x y sup" by blast qed sublocale dlo < ddlat proof fix x y z show "x \<sqinter> (y \<squnion> z) = x \<sqinter> y \<squnion> x \<sqinter> z" (is "?l = ?r") txt \<open>Jacobson I, p.\ 462\<close> proof - { assume c: "y \<sqsubseteq> x" "z \<sqsubseteq> x" from c have "?l = y \<squnion> z" by (metis c (*join_commute*) join_connection2 join_related2 (*meet_commute*) meet_connection meet_related2 total) also from c have "... = ?r" by (metis (*c*) (*join_commute*) meet_related2) finally have "?l = ?r" . } moreover { assume c: "x \<sqsubseteq> y | x \<sqsubseteq> z" from c have "?l = x" by (metis (*antisym*) (*c*) (*circular*) (*join_assoc*)(* join_commute *) join_connection2 (*join_left*) join_related2 meet_connection(* meet_related2*) total trans) also from c have "... = ?r" by (metis join_commute join_related2 meet_connection meet_related2 total) finally have "?l = ?r" . } moreover note total ultimately show ?thesis by blast qed qed subsubsection \<open>Total order \<open><=\<close> on \<^typ>\<open>int\<close>\<close> interpretation int: dpo "(<=) :: [int, int] => bool" rewrites "(dpo.less (<=) (x::int) y) = (x < y)" txt \<open>We give interpretation for less, but not \<open>is_inf\<close> and \<open>is_sub\<close>.\<close> proof - show "dpo ((<=) :: [int, int] => bool)" proof qed auto then interpret int: dpo "(<=) :: [int, int] => bool" . txt \<open>Gives interpreted version of \<open>less_def\<close> (without condition).\<close> show "(dpo.less (<=) (x::int) y) = (x < y)" by (unfold int.less_def) auto qed thm int.circular lemma "\<lbrakk> (x::int) \<le> y; y \<le> z; z \<le> x\<rbrakk> \<Longrightarrow> x = y \<and> y = z" apply (rule int.circular) apply assumption apply assumption apply assumption done thm int.abs_test lemma "((<) :: [int, int] => bool) = (<)" apply (rule int.abs_test) done interpretation int: dlat "(<=) :: [int, int] => bool" rewrites meet_eq: "dlat.meet (<=) (x::int) y = min x y" and join_eq: "dlat.join (<=) (x::int) y = max x y" proof - show "dlat ((<=) :: [int, int] => bool)" apply unfold_locales apply (unfold int.is_inf_def int.is_sup_def) apply arith+ done then interpret int: dlat "(<=) :: [int, int] => bool" . txt \<open>Interpretation to ease use of definitions, which are conditional in general but unconditional after interpretation.\<close> show "dlat.meet (<=) (x::int) y = min x y" apply (unfold int.meet_def) apply (rule the_equality) apply (unfold int.is_inf_def) by auto show "dlat.join (<=) (x::int) y = max x y" apply (unfold int.join_def) apply (rule the_equality) apply (unfold int.is_sup_def) by auto qed interpretation int: dlo "(<=) :: [int, int] => bool" proof qed arith text \<open>Interpreted theorems from the locales, involving defined terms.\<close> thm int.less_def text \<open>from dpo\<close> thm int.meet_left text \<open>from dlat\<close> thm int.meet_distr text \<open>from ddlat\<close> thm int.less_total text \<open>from dlo\<close> subsubsection \<open>Total order \<open><=\<close> on \<^typ>\<open>nat\<close>\<close> interpretation nat: dpo "(<=) :: [nat, nat] => bool" rewrites "dpo.less (<=) (x::nat) y = (x < y)" txt \<open>We give interpretation for less, but not \<open>is_inf\<close> and \<open>is_sub\<close>.\<close> proof - show "dpo ((<=) :: [nat, nat] => bool)" proof qed auto then interpret nat: dpo "(<=) :: [nat, nat] => bool" . txt \<open>Gives interpreted version of \<open>less_def\<close> (without condition).\<close> show "dpo.less (<=) (x::nat) y = (x < y)" apply (unfold nat.less_def) apply auto done qed interpretation nat: dlat "(<=) :: [nat, nat] => bool" rewrites "dlat.meet (<=) (x::nat) y = min x y" and "dlat.join (<=) (x::nat) y = max x y" proof - show "dlat ((<=) :: [nat, nat] => bool)" apply unfold_locales apply (unfold nat.is_inf_def nat.is_sup_def) apply arith+ done then interpret nat: dlat "(<=) :: [nat, nat] => bool" . txt \<open>Interpretation to ease use of definitions, which are conditional in general but unconditional after interpretation.\<close> show "dlat.meet (<=) (x::nat) y = min x y" apply (unfold nat.meet_def) apply (rule the_equality) apply (unfold nat.is_inf_def) by auto show "dlat.join (<=) (x::nat) y = max x y" apply (unfold nat.join_def) apply (rule the_equality) apply (unfold nat.is_sup_def) by auto qed interpretation nat: dlo "(<=) :: [nat, nat] => bool" proof qed arith text \<open>Interpreted theorems from the locales, involving defined terms.\<close> thm nat.less_def text \<open>from dpo\<close> thm nat.meet_left text \<open>from dlat\<close> thm nat.meet_distr text \<open>from ddlat\<close> thm nat.less_total text \<open>from ldo\<close> subsubsection \<open>Lattice \<open>dvd\<close> on \<^typ>\<open>nat\<close>\<close> interpretation nat_dvd: dpo "(dvd) :: [nat, nat] => bool" rewrites "dpo.less (dvd) (x::nat) y = (x dvd y & x ~= y)" txt \<open>We give interpretation for less, but not \<open>is_inf\<close> and \<open>is_sub\<close>.\<close> proof - show "dpo ((dvd) :: [nat, nat] => bool)" proof qed (auto simp: dvd_def) then interpret nat_dvd: dpo "(dvd) :: [nat, nat] => bool" . txt \<open>Gives interpreted version of \<open>less_def\<close> (without condition).\<close> show "dpo.less (dvd) (x::nat) y = (x dvd y & x ~= y)" apply (unfold nat_dvd.less_def) apply auto done qed interpretation nat_dvd: dlat "(dvd) :: [nat, nat] => bool" rewrites "dlat.meet (dvd) (x::nat) y = gcd x y" and "dlat.join (dvd) (x::nat) y = lcm x y" proof - show "dlat ((dvd) :: [nat, nat] => bool)" apply unfold_locales apply (unfold nat_dvd.is_inf_def nat_dvd.is_sup_def) apply (rule_tac x = "gcd x y" in exI) apply auto [1] apply (rule_tac x = "lcm x y" in exI) apply (auto intro: dvd_lcm1 dvd_lcm2 lcm_least) done then interpret nat_dvd: dlat "(dvd) :: [nat, nat] => bool" . txt \<open>Interpretation to ease use of definitions, which are conditional in general but unconditional after interpretation.\<close> show "dlat.meet (dvd) (x::nat) y = gcd x y" apply (unfold nat_dvd.meet_def) apply (rule the_equality) apply (unfold nat_dvd.is_inf_def) by auto show "dlat.join (dvd) (x::nat) y = lcm x y" apply (unfold nat_dvd.join_def) apply (rule the_equality) apply (unfold nat_dvd.is_sup_def) by (auto intro: dvd_lcm1 dvd_lcm2 lcm_least) qed text \<open>Interpreted theorems from the locales, involving defined terms.\<close> thm nat_dvd.less_def text \<open>from dpo\<close> lemma "((x::nat) dvd y & x ~= y) = (x dvd y & x ~= y)" apply (rule nat_dvd.less_def) done thm nat_dvd.meet_left text \<open>from dlat\<close> lemma "gcd x y dvd (x::nat)" apply (rule nat_dvd.meet_left) done subsection \<open>Group example with defined operations \<open>inv\<close> and \<open>unit\<close>\<close> subsubsection \<open>Locale declarations and lemmas\<close> locale Dsemi = fixes prod (infixl "**" 65) assumes assoc: "(x ** y) ** z = x ** (y ** z)" locale Dmonoid = Dsemi + fixes one assumes l_one [simp]: "one ** x = x" and r_one [simp]: "x ** one = x" begin definition inv where "inv x = (THE y. x ** y = one & y ** x = one)" definition unit where "unit x = (\<exists>y. x ** y = one & y ** x = one)" lemma inv_unique: assumes eq: "y ** x = one" "x ** y' = one" shows "y = y'" proof - from eq have "y = y ** (x ** y')" by (simp add: r_one) also have "... = (y ** x) ** y'" by (simp add: assoc) also from eq have "... = y'" by (simp add: l_one) finally show ?thesis . qed lemma unit_one [intro, simp]: "unit one" by (unfold unit_def) auto lemma unit_l_inv_ex: "unit x ==> \<exists>y. y ** x = one" by (unfold unit_def) auto lemma unit_r_inv_ex: "unit x ==> \<exists>y. x ** y = one" by (unfold unit_def) auto lemma unit_l_inv: "unit x ==> inv x ** x = one" apply (simp add: unit_def inv_def) apply (erule exE) apply (rule theI2, fast) apply (rule inv_unique) apply fast+ done lemma unit_r_inv: "unit x ==> x ** inv x = one" apply (simp add: unit_def inv_def) apply (erule exE) apply (rule theI2, fast) apply (rule inv_unique) apply fast+ done lemma unit_inv_unit [intro, simp]: "unit x ==> unit (inv x)" proof - assume x: "unit x" show "unit (inv x)" by (auto simp add: unit_def intro: unit_l_inv unit_r_inv x) qed lemma unit_l_cancel [simp]: "unit x ==> (x ** y = x ** z) = (y = z)" proof assume eq: "x ** y = x ** z" and G: "unit x" then have "(inv x ** x) ** y = (inv x ** x) ** z" by (simp add: assoc) with G show "y = z" by (simp add: unit_l_inv) next assume eq: "y = z" and G: "unit x" then show "x ** y = x ** z" by simp qed lemma unit_inv_inv [simp]: "unit x ==> inv (inv x) = x" proof - assume x: "unit x" then have "inv x ** inv (inv x) = inv x ** x" by (simp add: unit_l_inv unit_r_inv) with x show ?thesis by simp qed lemma inv_inj_on_unit: "inj_on inv {x. unit x}" proof (rule inj_onI, simp) fix x y assume G: "unit x" "unit y" and eq: "inv x = inv y" then have "inv (inv x) = inv (inv y)" by simp with G show "x = y" by simp qed lemma unit_inv_comm: assumes inv: "x ** y = one" and G: "unit x" "unit y" shows "y ** x = one" proof - from G have "x ** y ** x = x ** one" by (auto simp add: inv) with G show ?thesis by (simp del: r_one add: assoc) qed end locale Dgrp = Dmonoid + assumes unit [intro, simp]: "Dmonoid.unit ((**)) one x" begin lemma l_inv_ex [simp]: "\<exists>y. y ** x = one" using unit_l_inv_ex by simp lemma r_inv_ex [simp]: "\<exists>y. x ** y = one" using unit_r_inv_ex by simp lemma l_inv [simp]: "inv x ** x = one" using unit_l_inv by simp lemma l_cancel [simp]: "(x ** y = x ** z) = (y = z)" using unit_l_inv by simp lemma r_inv [simp]: "x ** inv x = one" proof - have "inv x ** (x ** inv x) = inv x ** one" by (simp add: assoc [symmetric] l_inv) then show ?thesis by (simp del: r_one) qed lemma r_cancel [simp]: "(y ** x = z ** x) = (y = z)" proof assume eq: "y ** x = z ** x" then have "y ** (x ** inv x) = z ** (x ** inv x)" by (simp add: assoc [symmetric] del: r_inv) then show "y = z" by simp qed simp lemma inv_one [simp]: "inv one = one" proof - have "inv one = one ** (inv one)" by (simp del: r_inv) moreover have "... = one" by simp finally show ?thesis . qed lemma inv_inv [simp]: "inv (inv x) = x" using unit_inv_inv by simp lemma inv_inj: "inj_on inv UNIV" using inv_inj_on_unit by simp lemma inv_mult_group: "inv (x ** y) = inv y ** inv x" proof - have "inv (x ** y) ** (x ** y) = (inv y ** inv x) ** (x ** y)" by (simp add: assoc l_inv) (simp add: assoc [symmetric]) then show ?thesis by (simp del: l_inv) qed lemma inv_comm: "x ** y = one ==> y ** x = one" by (rule unit_inv_comm) auto lemma inv_equality: "y ** x = one ==> inv x = y" apply (simp add: inv_def) apply (rule the_equality) apply (simp add: inv_comm [of y x]) apply (rule r_cancel [THEN iffD1], auto) done end locale Dhom = prod: Dgrp prod one + sum: Dgrp sum zero for prod (infixl "**" 65) and one and sum (infixl "+++" 60) and zero + fixes hom assumes hom_mult [simp]: "hom (x ** y) = hom x +++ hom y" begin lemma hom_one [simp]: "hom one = zero" proof - have "hom one +++ zero = hom one +++ hom one" by (simp add: hom_mult [symmetric] del: hom_mult) then show ?thesis by (simp del: sum.r_one) qed end subsubsection \<open>Interpretation of Functions\<close> interpretation Dfun: Dmonoid "(o)" "id :: 'a => 'a" rewrites "Dmonoid.unit (o) id f = bij (f::'a => 'a)" (* and "Dmonoid.inv (o) id" = "inv :: ('a => 'a) => ('a => 'a)" *) proof - show "Dmonoid (o) (id :: 'a => 'a)" proof qed (simp_all add: o_assoc) note Dmonoid = this (* from this interpret Dmonoid "(o)" "id :: 'a => 'a" . *) show "Dmonoid.unit (o) (id :: 'a => 'a) f = bij f" apply (unfold Dmonoid.unit_def [OF Dmonoid]) apply rule apply clarify proof - fix f g assume id1: "f o g = id" and id2: "g o f = id" show "bij f" proof (rule bijI) show "inj f" proof (rule inj_onI) fix x y assume "f x = f y" then have "(g o f) x = (g o f) y" by simp with id2 show "x = y" by simp qed next show "surj f" proof (rule surjI) fix x from id1 have "(f o g) x = x" by simp then show "f (g x) = x" by simp qed qed next fix f assume bij: "bij f" then have inv: "f o Hilbert_Choice.inv f = id & Hilbert_Choice.inv f o f = id" by (simp add: bij_def surj_iff inj_iff) show "\<exists>g. f \<circ> g = id \<and> g \<circ> f = id" by rule (rule inv) qed qed thm Dmonoid.unit_def Dfun.unit_def thm Dmonoid.inv_inj_on_unit Dfun.inv_inj_on_unit lemma unit_id: "(f :: unit => unit) = id" by rule simp interpretation Dfun: Dgrp "(o)" "id :: unit => unit" rewrites "Dmonoid.inv (o) id f = inv (f :: unit => unit)" proof - have "Dmonoid (o) (id :: 'a => 'a)" .. note Dmonoid = this show "Dgrp (o) (id :: unit => unit)" apply unfold_locales apply (unfold Dmonoid.unit_def [OF Dmonoid]) apply (insert unit_id) apply simp done show "Dmonoid.inv (o) id f = inv (f :: unit \<Rightarrow> unit)" apply (unfold Dmonoid.inv_def [OF Dmonoid]) apply (insert unit_id) apply simp apply (rule the_equality) apply rule apply rule apply simp done qed thm Dfun.unit_l_inv Dfun.l_inv thm Dfun.inv_equality thm Dfun.inv_equality end
** Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. ** See https://llvm.org/LICENSE.txt for license information. ** SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception * Constant prop. - call in path problems program p parameter (N=1) common iresult(N) dimension iexpect(N) data iexpect / + 9 ! t0 + / iresult(1) = 0 call t0(iresult(1), 5) call check(iresult, iexpect, N) end subroutine t0(ii, n) jj = 1 !jj cannot be copied do i = 1, n ii = jj + ii call set(jj) !jj potentially modified enddo end subroutine set(jj) jj = 2 end
import tactic import data.real.basic import data.pnat.basic local notation `|` x `|` := abs x def is_limit (a : ℕ → ℝ) (l : ℝ) : Prop := ∀ ε > 0, ∃ N, ∀ n ≥ N, | a n - l | < ε def tends_to_plus_infinity (a : ℕ → ℝ) : Prop := ∀ B, ∃ N, ∀ n ≥ N, B < a n def is_convergent (a : ℕ → ℝ) : Prop := ∃ l : ℝ, is_limit a l namespace sheet_five theorem Q1a (x : ℝ) (hx : 0 < x) (n : ℕ) : (1 : ℝ) + n * x ≤ (1 + x)^n := begin sorry end theorem Q1b (x : ℝ) (hx : 0 < x) : is_limit (λ n, (1 + x) ^ (-(n : ℤ))) 0 := begin sorry end theorem Q1c (r : ℝ) (hr : r ∈ set.Ioo (0 : ℝ) 1) : is_limit (λ n, r ^ n) 0 := begin sorry end theorem Q1d (r : ℝ) (hr : 1 < r) : tends_to_plus_infinity (λ n, r ^ n) := begin sorry end
section "Setup of Environment for CAVA Model Checker" theory CAVA_Base imports Collections.CollectionsV1 (*-- {* Compatibility with ICF 1.0 *}*) Collections.Refine_Dflt Statistics (*-- {* Collecting statistics by instrumenting the formalization *}*) CAVA_Code_Target (*-- {* Code Generator Setup *}*) begin hide_const (open) CollectionsV1.ahs_rel (* (* Select-function that selects element from set *) (* TODO: Move! Is select properly integrated into autoref? *) definition select where "select S \<equiv> if S={} then RETURN None else RES {Some s | s. s\<in>S}" lemma select_correct: "select X \<le> SPEC (\<lambda>r. case r of None \<Rightarrow> X={} | Some x \<Rightarrow> x\<in>X)" unfolding select_def apply (refine_rcg refine_vcg) by auto *) text \<open>Cleaning up the namespace a bit\<close> hide_type (open) Word.word text \<open>Some custom setup in cava, that does not match HOL defaults:\<close> declare Let_def[simp add] end
function Model = buildRxnEquations(Model) % Takes a COBRA model and creates reaction equations based % on the metabolites list, `S` matrix and bound information. Returns the % model with the additinal field `rxnEquations`. Is called by `cleanTmodel`, `compareCbModels`, `readCbTmodel`, `verifyModel`, `addSEEDInfo`. % % USAGE: % % Model = buildRxnEquations(Model) % % INPUTS: % Model: COBRA format model or `Tmodel` % % OUTPUTS: % Model: Model with corrected `rxnEquations` field. % % Please cite: % `Sauls, J. T., & Buescher, J. M. (2014). Assimilating genome-scale % metabolic reconstructions with modelBorgifier. Bioinformatics % (Oxford, England), 30(7), 1036?8`. http://doi.org/10.1093/bioinformatics/btt747 % % .. % Edit the above text to modify the response to help addMetInfo % Last Modified by GUIDE v2.5 06-Dec-2013 14:19:28 % This file is published under Creative Commons BY-NC-SA. % % Correspondance: % [email protected] % % Developed at: % BRAIN Aktiengesellschaft % Microbial Production Technologies Unit % Quantitative Biology and Sequencing Platform % Darmstaeter Str. 34-36 % 64673 Zwingenberg, Germany % www.brain-biotech.de if isstruct(Model.lb) % If the function is fed Tmodel, use reaction bounds from first model. modelNames = fieldnames(Model.Models) ; firstModel = modelNames{1} ; lb = Model.lb.(firstModel) ; ub = Model.ub.(firstModel) ; else lb = Model.lb ; ub = Model.ub ; end %% Make the equations. for iRxn = 1:length(Model.rxns) rxnCode = [] ; educts = find(Model.S(:,iRxn) < 0) ; products = find(Model.S(:,iRxn) > 0) ; if lb(iRxn) < 0 && ub(iRxn) > 0 arrow = '<==>' ; elseif lb(iRxn) >= 0 && ub(iRxn) > 0 arrow = '-->' ; elseif lb(iRxn) < 0 && ub(iRxn) <= 0 arrow = '<--' ; elseif lb(iRxn) == 0 && ub(iRxn) == 0 arrow = '|||' ; else disp(['Do not understand directionality of ' Model.rxns{iRxn}]) end if ~isempty(educts) for ie = 1:length(educts) if Model.S(educts(ie), iRxn) ~= -1 rxnCode = [rxnCode '(' num2str(-Model.S(educts(ie),iRxn)) ... ') ' Model.mets{educts(ie)} ] ; else rxnCode = [rxnCode Model.mets{educts(ie)}] ; end rxnCode = [rxnCode ' + '] ; end % Note how just 2 positions are substracted from the end, leaving a % space. rxnCode = [rxnCode(1:end - 2) arrow] ; end if ~isempty(products) rxnCode = [rxnCode ' '] ; for ip = 1:length(products) if Model.S(products(ip), iRxn) ~= 1 rxnCode = [rxnCode '(' num2str(Model.S(products(ip), iRxn))... ') ' Model.mets{products(ip)}] ; else rxnCode = [rxnCode Model.mets{products(ip)}] ; end rxnCode = [rxnCode ' + '] ; end rxnCode = rxnCode(1:end - 3) ; end Model.rxnEquations{iRxn, 1} = rxnCode ; clear educts ; clear products; clear ie ; clear ip ; clear rxcode ; end
c----------------------------------------------------------------------------- c Find total grid points in all blocks for allocating memory c----------------------------------------------------------------------------- integer function total_pts(nblks, idim, jdim) implicit none integer nblks, idim(*), jdim(*) integer id, jd, fid, i total_pts = 0 fid = 10 open(fid, file='grid.0') read(fid,*) nblks do i=1,nblks read(fid,*) id, jd total_pts = total_pts + id*jd idim(i) = id jdim(i) = jd enddo close(fid) return end
structure S := (x := true) def f (s : S) : Bool := s.x #eval f {} theorem ex : f {} = true := rfl
Require Import Coq.Lists.List. Require Import Coq.Classes.Morphisms. Require Import Coq.Setoids.Setoid. Global Instance list_rect_Proper_dep_gen {A P} (RP : forall x : list A, P x -> P x -> Prop) : Proper (RP nil ==> forall_relation (fun x => forall_relation (fun xs => RP xs ==> RP (cons x xs))) ==> forall_relation RP) (@list_rect A P) | 10. Proof. cbv [forall_relation respectful]; intros N N' HN C C' HC ls. induction ls as [|l ls IHls]; cbn [list_rect]; repeat first [ apply IHls | apply HC | apply HN | progress intros | reflexivity ]. Qed. Global Instance list_rect_Proper_dep {A P} : Proper (eq ==> forall_relation (fun _ => forall_relation (fun _ => forall_relation (fun _ => eq))) ==> forall_relation (fun _ => eq)) (@list_rect A P) | 1. Proof. cbv [forall_relation respectful Proper]; intros; eapply (@list_rect_Proper_dep_gen A P (fun _ => eq)); cbv [forall_relation respectful]; intros; subst; eauto. Qed. Global Instance list_rect_Proper_gen {A P} R : Proper (R ==> (eq ==> eq ==> R ==> R) ==> eq ==> R) (@list_rect A (fun _ => P)) | 10. Proof. repeat intro; subst; apply (@list_rect_Proper_dep_gen A (fun _ => P) (fun _ => R)); cbv [forall_relation respectful] in *; eauto. Qed. Global Instance list_rect_Proper {A P} : Proper (eq ==> pointwise_relation _ (pointwise_relation _ (pointwise_relation _ eq)) ==> eq ==> eq) (@list_rect A (fun _ => P)). Proof. repeat intro; subst; apply (@list_rect_Proper_dep A (fun _ => P)); eauto. Qed.
Formal statement is: lemma space_interval_measure [simp]: "space (interval_measure F) = UNIV" Informal statement is: The space of an interval measure is the entire universe.
= = Solving chess = =
f(a,b) = 333.75*b^6+a^2*(11*a^2*b^2 - b^6 - 121*b^4 - 2) + 5.5*b^8 + a/(2*b) a=77617.0 b=33096.0 println("Float64: ", f(a, b)) println("BigFloat: ", f(BigFloat(a), BigFloat(b)))
!***************************************************************************************** !> author: nescirem ! date: 5/05/2019 ! ! Module parse base boundary information. ! module jc_boundary_mod use json_module, CK => json_CK, IK => json_IK use, intrinsic :: iso_fortran_env, only: error_unit use output_mod implicit none private public :: jc_boundary contains !==================================================================== !-------------------------------------------------------------------+ subroutine jc_boundary ! !-------------------------------------------------------------------+ implicit none end subroutine jc_boundary !==================================================================== end module jc_boundary_mod
clear all; close all; clc; spx.cluster.ssc.util.simulate_subspace_preservation(@ssc_omp, 'ssc_omp'); spx.cluster.ssc.util.print_subspace_preservation_results('ssc_omp');
[GOAL] P : PartENat → Prop ⊢ ∀ (a : PartENat), P ⊤ → (∀ (n : ℕ), P ↑n) → P a [PROOFSTEP] exact PartENat.casesOn' [GOAL] x : PartENat ⊢ x + ⊤ = ⊤ [PROOFSTEP] rw [add_comm, top_add] [GOAL] x : PartENat h : x.Dom ⊢ ↑(Part.get x h) = x [PROOFSTEP] exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl [GOAL] x : ℕ h : (↑x).Dom ⊢ Part.get (↑x) h = x [PROOFSTEP] rw [← natCast_inj, natCast_get] [GOAL] x : ℕ y : PartENat h : (↑x + y).Dom ⊢ Part.get (↑x + y) h = x + Part.get y (_ : y.Dom) [PROOFSTEP] rfl [GOAL] a : PartENat ha : a.Dom b : ℕ ⊢ Part.get a ha = b ↔ a = ↑b [PROOFSTEP] rw [get_eq_iff_eq_some] [GOAL] a : PartENat ha : a.Dom b : ℕ ⊢ a = ↑b ↔ a = ↑b [PROOFSTEP] rfl [GOAL] x : PartENat y : ℕ h : x ≤ ↑y ⊢ x.Dom [PROOFSTEP] exact dom_of_le_some h [GOAL] x y : PartENat inst✝¹ : Decidable x.Dom inst✝ : Decidable y.Dom hx : x.Dom ⊢ ?m.35650 x y hx ↔ x ≤ y [PROOFSTEP] rw [le_def] [GOAL] x y : PartENat ⊢ x < y ↔ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] rw [lt_iff_le_not_le, le_def, le_def, not_exists] [GOAL] x y : PartENat ⊢ ((∃ h, ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy) ∧ ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy) ↔ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] constructor [GOAL] case mp x y : PartENat ⊢ ((∃ h, ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy) ∧ ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy) → ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] rintro ⟨⟨hyx, H⟩, h⟩ [GOAL] case mp.intro.intro x y : PartENat h : ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy ⊢ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] by_cases hx : x.Dom [GOAL] case pos x y : PartENat h : ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : x.Dom ⊢ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] use hx [GOAL] case h x y : PartENat h : ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : x.Dom ⊢ ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] intro hy [GOAL] case h x y : PartENat h : ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : x.Dom hy : y.Dom ⊢ Part.get x hx < Part.get y hy [PROOFSTEP] specialize H hy [GOAL] case h x y : PartENat h : ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy hyx : y.Dom → x.Dom hx : x.Dom hy : y.Dom H : Part.get x (_ : x.Dom) ≤ Part.get y hy ⊢ Part.get x hx < Part.get y hy [PROOFSTEP] specialize h fun _ => hy [GOAL] case h x y : PartENat hyx : y.Dom → x.Dom hx : x.Dom hy : y.Dom H : Part.get x (_ : x.Dom) ≤ Part.get y hy h : ¬∀ (hy_1 : x.Dom), Part.get y hy ≤ Part.get x hy_1 ⊢ Part.get x hx < Part.get y hy [PROOFSTEP] rw [not_forall] at h [GOAL] case h x y : PartENat hyx : y.Dom → x.Dom hx : x.Dom hy : y.Dom H : Part.get x (_ : x.Dom) ≤ Part.get y hy h : ∃ x_1, ¬Part.get y hy ≤ Part.get x x_1 ⊢ Part.get x hx < Part.get y hy [PROOFSTEP] cases' h with hx' h [GOAL] case h.intro x y : PartENat hyx : y.Dom → x.Dom hx : x.Dom hy : y.Dom H : Part.get x (_ : x.Dom) ≤ Part.get y hy hx' : x.Dom h : ¬Part.get y hy ≤ Part.get x hx' ⊢ Part.get x hx < Part.get y hy [PROOFSTEP] rw [not_le] at h [GOAL] case h.intro x y : PartENat hyx : y.Dom → x.Dom hx : x.Dom hy : y.Dom H : Part.get x (_ : x.Dom) ≤ Part.get y hy hx' : x.Dom h : Part.get x hx' < Part.get y hy ⊢ Part.get x hx < Part.get y hy [PROOFSTEP] exact h [GOAL] case neg x y : PartENat h : ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : ¬x.Dom ⊢ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] specialize h fun hx' => (hx hx').elim [GOAL] case neg x y : PartENat hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : ¬x.Dom h : ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy ⊢ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] rw [not_forall] at h [GOAL] case neg x y : PartENat hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : ¬x.Dom h : ∃ x_1, ¬Part.get y (_ : y.Dom) ≤ Part.get x x_1 ⊢ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] cases' h with hx' h [GOAL] case neg.intro x y : PartENat hyx : y.Dom → x.Dom H : ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy hx : ¬x.Dom hx' : x.Dom h : ¬Part.get y (_ : y.Dom) ≤ Part.get x hx' ⊢ ∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy [PROOFSTEP] exact (hx hx').elim [GOAL] case mpr x y : PartENat ⊢ (∃ hx, ∀ (hy : y.Dom), Part.get x hx < Part.get y hy) → (∃ h, ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy) ∧ ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy [PROOFSTEP] rintro ⟨hx, H⟩ [GOAL] case mpr.intro x y : PartENat hx : x.Dom H : ∀ (hy : y.Dom), Part.get x hx < Part.get y hy ⊢ (∃ h, ∀ (hy : y.Dom), Part.get x (_ : x.Dom) ≤ Part.get y hy) ∧ ∀ (x_1 : x.Dom → y.Dom), ¬∀ (hy : x.Dom), Part.get y (_ : y.Dom) ≤ Part.get x hy [PROOFSTEP] exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩ [GOAL] x y : ℕ ⊢ ↑x ≤ ↑y ↔ x ≤ y [PROOFSTEP] exact ⟨fun ⟨_, h⟩ => h trivial, fun h => ⟨fun _ => trivial, fun _ => h⟩⟩ [GOAL] x y : ℕ ⊢ ↑x < ↑y ↔ x < y [PROOFSTEP] rw [lt_iff_le_not_le, lt_iff_le_not_le, coe_le_coe, coe_le_coe] [GOAL] x y : PartENat hx : x.Dom hy : y.Dom ⊢ Part.get x hx ≤ Part.get y hy ↔ x ≤ y [PROOFSTEP] conv => lhs rw [← coe_le_coe, natCast_get, natCast_get] [GOAL] x y : PartENat hx : x.Dom hy : y.Dom | Part.get x hx ≤ Part.get y hy ↔ x ≤ y [PROOFSTEP] lhs rw [← coe_le_coe, natCast_get, natCast_get] [GOAL] x y : PartENat hx : x.Dom hy : y.Dom | Part.get x hx ≤ Part.get y hy ↔ x ≤ y [PROOFSTEP] lhs rw [← coe_le_coe, natCast_get, natCast_get] [GOAL] x y : PartENat hx : x.Dom hy : y.Dom | Part.get x hx ≤ Part.get y hy ↔ x ≤ y [PROOFSTEP] lhs [GOAL] x y : PartENat hx : x.Dom hy : y.Dom | Part.get x hx ≤ Part.get y hy [PROOFSTEP] rw [← coe_le_coe, natCast_get, natCast_get] [GOAL] x : PartENat n : ℕ ⊢ x ≤ ↑n ↔ ∃ h, Part.get x h ≤ n [PROOFSTEP] show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n [GOAL] x : PartENat n : ℕ ⊢ (∃ h, ∀ (hy : (↑n).Dom), Part.get x (_ : x.Dom) ≤ Part.get (↑n) hy) ↔ ∃ h, Part.get x h ≤ n [PROOFSTEP] simp only [forall_prop_of_true, dom_natCast, get_natCast'] [GOAL] x : PartENat n : ℕ ⊢ x < ↑n ↔ ∃ h, Part.get x h < n [PROOFSTEP] simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast] [GOAL] n : ℕ x : PartENat ⊢ ↑n ≤ x ↔ ∀ (h : x.Dom), n ≤ Part.get x h [PROOFSTEP] rw [← some_eq_natCast] [GOAL] n : ℕ x : PartENat ⊢ ↑n ≤ x ↔ ∀ (h : x.Dom), n ≤ Part.get x h [PROOFSTEP] simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff] [GOAL] n : ℕ x : PartENat ⊢ (∀ (hy : x.Dom), Part.get ↑n (_ : (↑n).Dom) ≤ Part.get x hy) ↔ ∀ (h : x.Dom), n ≤ Part.get x h [PROOFSTEP] rfl [GOAL] n : ℕ x : PartENat ⊢ ↑n < x ↔ ∀ (h : x.Dom), n < Part.get x h [PROOFSTEP] rw [← some_eq_natCast] [GOAL] n : ℕ x : PartENat ⊢ ↑n < x ↔ ∀ (h : x.Dom), n < Part.get x h [PROOFSTEP] simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff] [GOAL] n : ℕ x : PartENat ⊢ (∀ (hy : x.Dom), Part.get ↑n (_ : (↑n).Dom) < Part.get x hy) ↔ ∀ (h : x.Dom), n < Part.get x h [PROOFSTEP] rfl [GOAL] ⊢ ¬1 = 0 [PROOFSTEP] decide [GOAL] x : ℕ h : ↑x = ⊤ ⊢ ¬(↑x).Dom = ⊤.Dom [PROOFSTEP] simp only [dom_natCast] [GOAL] x : ℕ h : ↑x = ⊤ ⊢ ¬True = ⊤.Dom [PROOFSTEP] exact true_ne_false [GOAL] x : PartENat ⊢ x ≠ ⊤ ↔ ∃ n, x = ↑n [PROOFSTEP] simpa only [← some_eq_natCast] using Part.ne_none_iff [GOAL] x : PartENat ⊢ x ≠ ⊤ ↔ x.Dom [PROOFSTEP] classical exact not_iff_comm.1 Part.eq_none_iff'.symm [GOAL] x : PartENat ⊢ x ≠ ⊤ ↔ x.Dom [PROOFSTEP] exact not_iff_comm.1 Part.eq_none_iff'.symm [GOAL] x : PartENat ⊢ x = ⊤ ↔ ∀ (n : ℕ), ↑n < x [PROOFSTEP] constructor [GOAL] case mp x : PartENat ⊢ x = ⊤ → ∀ (n : ℕ), ↑n < x [PROOFSTEP] rintro rfl n [GOAL] case mp n : ℕ ⊢ ↑n < ⊤ [PROOFSTEP] exact natCast_lt_top _ [GOAL] case mpr x : PartENat ⊢ (∀ (n : ℕ), ↑n < x) → x = ⊤ [PROOFSTEP] contrapose! [GOAL] case mpr x : PartENat ⊢ x ≠ ⊤ → ∃ n, ¬↑n < x [PROOFSTEP] rw [ne_top_iff] [GOAL] case mpr x : PartENat ⊢ (∃ n, x = ↑n) → ∃ n, ¬↑n < x [PROOFSTEP] rintro ⟨n, rfl⟩ [GOAL] case mpr.intro n : ℕ ⊢ ∃ n_1, ¬↑n_1 < ↑n [PROOFSTEP] exact ⟨n, irrefl _⟩ [GOAL] x : PartENat ⊢ 0 < ⊤ ↔ 1 ≤ ⊤ [PROOFSTEP] simp only [iff_true_iff, le_top, natCast_lt_top, ← @Nat.cast_zero PartENat] [GOAL] x : PartENat n : ℕ ⊢ 0 < ↑n ↔ 1 ≤ ↑n [PROOFSTEP] rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe] [GOAL] x : PartENat n : ℕ ⊢ 0 < n ↔ 1 ≤ n [PROOFSTEP] rfl [GOAL] src✝ : PartialOrder PartENat := partialOrder a b : PartENat ⊢ max a b = if a ≤ b then b else a [PROOFSTEP] change (fun a b => a ⊔ b) a b = _ [GOAL] src✝ : PartialOrder PartENat := partialOrder a b : PartENat ⊢ (fun a b => a ⊔ b) a b = if a ≤ b then b else a [PROOFSTEP] rw [@sup_eq_maxDefault PartENat _ (id _) _] [GOAL] src✝ : PartialOrder PartENat := partialOrder a b : PartENat ⊢ maxDefault a b = if a ≤ b then b else a src✝ : PartialOrder PartENat := partialOrder a b : PartENat ⊢ DecidableRel fun x x_1 => x ≤ x_1 [PROOFSTEP] rfl [GOAL] src✝¹ : LinearOrder PartENat := linearOrder src✝ : AddCommMonoid PartENat := addCommMonoid a b : PartENat x✝ : a ≤ b c : PartENat h₁ : b.Dom → a.Dom h₂ : ∀ (hy : b.Dom), Part.get a (_ : a.Dom) ≤ Part.get b hy ⊢ ⊤ + a ≤ ⊤ + b [PROOFSTEP] simp [GOAL] src✝¹ : LinearOrder PartENat := linearOrder src✝ : AddCommMonoid PartENat := addCommMonoid a b : PartENat x✝ : a ≤ b c✝ : PartENat h₁ : b.Dom → a.Dom h₂ : ∀ (hy : b.Dom), Part.get a (_ : a.Dom) ≤ Part.get b hy c : ℕ h : (↑c + b).Dom ⊢ Part.get (↑c + a) (_ : (↑c).Dom ∧ a.Dom) ≤ Part.get (↑c + b) h [PROOFSTEP] simpa only [coe_add_get] using add_le_add_left (h₂ _) c [GOAL] src✝² : SemilatticeSup PartENat := semilatticeSup src✝¹ : OrderBot PartENat := orderBot src✝ : OrderedAddCommMonoid PartENat := orderedAddCommMonoid a✝ b✝ : PartENat b a : ℕ h : ↑a ≤ ↑b ⊢ ↑b = ↑a + ↑(b - a) [PROOFSTEP] rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)] [GOAL] x y : PartENat n : ℕ h : x + y = ↑n ⊢ x = ↑(n - Part.get y (_ : y.Dom)) [PROOFSTEP] lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h) [GOAL] case intro y : PartENat n x : ℕ h : ↑x + y = ↑n ⊢ ↑x = ↑(n - Part.get y (_ : y.Dom)) [PROOFSTEP] lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h) [GOAL] case intro.intro n x y : ℕ h : ↑x + ↑y = ↑n ⊢ ↑x = ↑(n - Part.get ↑y (_ : (↑y).Dom)) [PROOFSTEP] rw [← Nat.cast_add, natCast_inj] at h [GOAL] case intro.intro n x y : ℕ h✝ : ↑x + ↑y = ↑n h : x + y = n ⊢ ↑x = ↑(n - Part.get ↑y (_ : (↑y).Dom)) [PROOFSTEP] rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h] [GOAL] x y z : PartENat h : x < y hz : z ≠ ⊤ ⊢ x + z < y + z [PROOFSTEP] rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ [GOAL] case intro y z : PartENat hz : z ≠ ⊤ m : ℕ h : ↑m < y ⊢ ↑m + z < y + z [PROOFSTEP] rcases ne_top_iff.mp hz with ⟨k, rfl⟩ [GOAL] case intro.intro y : PartENat m : ℕ h : ↑m < y k : ℕ hz : ↑k ≠ ⊤ ⊢ ↑m + ↑k < y + ↑k [PROOFSTEP] induction' y using PartENat.casesOn with n [GOAL] case intro.intro.a y : PartENat m : ℕ h✝ : ↑m < y k : ℕ hz : ↑k ≠ ⊤ h : ↑m < ⊤ ⊢ ↑m + ↑k < ⊤ + ↑k [PROOFSTEP] rw [top_add] -- Porting note: was apply_mod_cast natCast_lt_top [GOAL] case intro.intro.a y : PartENat m : ℕ h✝ : ↑m < y k : ℕ hz : ↑k ≠ ⊤ h : ↑m < ⊤ ⊢ ↑m + ↑k < ⊤ [PROOFSTEP] norm_cast [GOAL] case intro.intro.a y : PartENat m : ℕ h✝ : ↑m < y k : ℕ hz : ↑k ≠ ⊤ h : ↑m < ⊤ ⊢ ↑(m + k) < ⊤ [PROOFSTEP] apply natCast_lt_top [GOAL] case intro.intro.a y : PartENat m : ℕ h✝ : ↑m < y k : ℕ hz : ↑k ≠ ⊤ n : ℕ h : ↑m < ↑n ⊢ ↑m + ↑k < ↑n + ↑k [PROOFSTEP] norm_cast at h [GOAL] case intro.intro.a y : PartENat m : ℕ h✝ : ↑m < y k : ℕ hz : ↑k ≠ ⊤ n : ℕ h : m < n ⊢ ↑m + ↑k < ↑n + ↑k [PROOFSTEP] norm_cast [GOAL] case intro.intro.a y : PartENat m : ℕ h✝ : ↑m < y k : ℕ hz : ↑k ≠ ⊤ n : ℕ h : m < n ⊢ m + k < n + k [PROOFSTEP] apply add_lt_add_right h [GOAL] x y z : PartENat hz : z ≠ ⊤ ⊢ z + x < z + y ↔ x < y [PROOFSTEP] rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz] [GOAL] x y : PartENat hx : x ≠ ⊤ ⊢ x < x + y ↔ 0 < y [PROOFSTEP] conv_rhs => rw [← PartENat.add_lt_add_iff_left hx] [GOAL] x y : PartENat hx : x ≠ ⊤ | 0 < y [PROOFSTEP] rw [← PartENat.add_lt_add_iff_left hx] [GOAL] x y : PartENat hx : x ≠ ⊤ | 0 < y [PROOFSTEP] rw [← PartENat.add_lt_add_iff_left hx] [GOAL] x y : PartENat hx : x ≠ ⊤ | 0 < y [PROOFSTEP] rw [← PartENat.add_lt_add_iff_left hx] [GOAL] x y : PartENat hx : x ≠ ⊤ ⊢ x < x + y ↔ x + 0 < x + y [PROOFSTEP] rw [add_zero] [GOAL] x : PartENat hx : x ≠ ⊤ ⊢ x < x + 1 [PROOFSTEP] rw [PartENat.lt_add_iff_pos_right hx] [GOAL] x : PartENat hx : x ≠ ⊤ ⊢ 0 < 1 [PROOFSTEP] norm_cast [GOAL] x y : PartENat h : x < y + 1 ⊢ x ≤ y [PROOFSTEP] induction' y using PartENat.casesOn with n [GOAL] case a x y : PartENat h✝ : x < y + 1 h : x < ⊤ + 1 ⊢ x ≤ ⊤ [PROOFSTEP] apply le_top [GOAL] case a x y : PartENat h✝ : x < y + 1 n : ℕ h : x < ↑n + 1 ⊢ x ≤ ↑n [PROOFSTEP] rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ -- Porting note: was `apply_mod_cast Nat.le_of_lt_succ; apply_mod_cast h` [GOAL] case a.intro y : PartENat n m : ℕ h✝ : ↑m < y + 1 h : ↑m < ↑n + 1 ⊢ ↑m ≤ ↑n [PROOFSTEP] norm_cast [GOAL] case a.intro y : PartENat n m : ℕ h✝ : ↑m < y + 1 h : ↑m < ↑n + 1 ⊢ m ≤ n [PROOFSTEP] apply Nat.le_of_lt_succ [GOAL] case a.intro.a y : PartENat n m : ℕ h✝ : ↑m < y + 1 h : ↑m < ↑n + 1 ⊢ m < Nat.succ n [PROOFSTEP] norm_cast at h [GOAL] x y : PartENat h : x < y ⊢ x + 1 ≤ y [PROOFSTEP] induction' y using PartENat.casesOn with n [GOAL] case a x y : PartENat h✝ : x < y h : x < ⊤ ⊢ x + 1 ≤ ⊤ [PROOFSTEP] apply le_top [GOAL] case a x y : PartENat h✝ : x < y n : ℕ h : x < ↑n ⊢ x + 1 ≤ ↑n [PROOFSTEP] rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ -- Porting note: was `apply_mod_cast Nat.succ_le_of_lt; apply_mod_cast h` [GOAL] case a.intro y : PartENat n m : ℕ h✝ : ↑m < y h : ↑m < ↑n ⊢ ↑m + 1 ≤ ↑n [PROOFSTEP] norm_cast [GOAL] case a.intro y : PartENat n m : ℕ h✝ : ↑m < y h : ↑m < ↑n ⊢ m + 1 ≤ n [PROOFSTEP] apply Nat.succ_le_of_lt [GOAL] case a.intro.h y : PartENat n m : ℕ h✝ : ↑m < y h : ↑m < ↑n ⊢ m < n [PROOFSTEP] norm_cast at h [GOAL] x y : PartENat hx : x ≠ ⊤ ⊢ x + 1 ≤ y ↔ x < y [PROOFSTEP] refine ⟨fun h => ?_, add_one_le_of_lt⟩ [GOAL] x y : PartENat hx : x ≠ ⊤ h : x + 1 ≤ y ⊢ x < y [PROOFSTEP] rcases ne_top_iff.mp hx with ⟨m, rfl⟩ [GOAL] case intro y : PartENat m : ℕ hx : ↑m ≠ ⊤ h : ↑m + 1 ≤ y ⊢ ↑m < y [PROOFSTEP] induction' y using PartENat.casesOn with n [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m + 1 ≤ y h : ↑m + 1 ≤ ⊤ ⊢ ↑m < ⊤ [PROOFSTEP] apply natCast_lt_top [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m + 1 ≤ y n : ℕ h : ↑m + 1 ≤ ↑n ⊢ ↑m < ↑n [PROOFSTEP] norm_cast [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m + 1 ≤ y n : ℕ h : ↑m + 1 ≤ ↑n ⊢ m < n [PROOFSTEP] apply Nat.lt_of_succ_le [GOAL] case intro.a.h y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m + 1 ≤ y n : ℕ h : ↑m + 1 ≤ ↑n ⊢ Nat.succ m ≤ n [PROOFSTEP] norm_cast at h [GOAL] n : ℕ e : PartENat ⊢ ↑(Nat.succ n) ≤ e ↔ ↑n < e [PROOFSTEP] rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)] [GOAL] x y : PartENat hx : x ≠ ⊤ ⊢ x < y + 1 ↔ x ≤ y [PROOFSTEP] refine ⟨le_of_lt_add_one, fun h => ?_⟩ [GOAL] x y : PartENat hx : x ≠ ⊤ h : x ≤ y ⊢ x < y + 1 [PROOFSTEP] rcases ne_top_iff.mp hx with ⟨m, rfl⟩ [GOAL] case intro y : PartENat m : ℕ hx : ↑m ≠ ⊤ h : ↑m ≤ y ⊢ ↑m < y + 1 [PROOFSTEP] induction' y using PartENat.casesOn with n [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m ≤ y h : ↑m ≤ ⊤ ⊢ ↑m < ⊤ + 1 [PROOFSTEP] rw [top_add] [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m ≤ y h : ↑m ≤ ⊤ ⊢ ↑m < ⊤ [PROOFSTEP] apply natCast_lt_top [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m ≤ y n : ℕ h : ↑m ≤ ↑n ⊢ ↑m < ↑n + 1 [PROOFSTEP] norm_cast [GOAL] case intro.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m ≤ y n : ℕ h : ↑m ≤ ↑n ⊢ m < n + 1 [PROOFSTEP] apply Nat.lt_succ_of_le [GOAL] case intro.a.a y : PartENat m : ℕ hx : ↑m ≠ ⊤ h✝ : ↑m ≤ y n : ℕ h : ↑m ≤ ↑n ⊢ m ≤ n [PROOFSTEP] norm_cast at h [GOAL] x : PartENat n : ℕ hx : x ≠ ⊤ ⊢ x < ↑(Nat.succ n) ↔ x ≤ ↑n [PROOFSTEP] rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx] [GOAL] a b : PartENat ⊢ a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ [PROOFSTEP] refine PartENat.casesOn a ?_ ?_ [GOAL] case refine_1 a b : PartENat ⊢ ⊤ + b = ⊤ ↔ ⊤ = ⊤ ∨ b = ⊤ [PROOFSTEP] refine PartENat.casesOn b ?_ ?_ [GOAL] case refine_2 a b : PartENat ⊢ ∀ (n : ℕ), ↑n + b = ⊤ ↔ ↑n = ⊤ ∨ b = ⊤ [PROOFSTEP] refine PartENat.casesOn b ?_ ?_ [GOAL] case refine_1.refine_1 a b : PartENat ⊢ ⊤ + ⊤ = ⊤ ↔ ⊤ = ⊤ ∨ ⊤ = ⊤ [PROOFSTEP] simp [GOAL] case refine_1.refine_2 a b : PartENat ⊢ ∀ (n : ℕ), ⊤ + ↑n = ⊤ ↔ ⊤ = ⊤ ∨ ↑n = ⊤ [PROOFSTEP] simp [GOAL] case refine_2.refine_1 a b : PartENat ⊢ ∀ (n : ℕ), ↑n + ⊤ = ⊤ ↔ ↑n = ⊤ ∨ ⊤ = ⊤ [PROOFSTEP] simp [GOAL] case refine_2.refine_2 a b : PartENat ⊢ ∀ (n n_1 : ℕ), ↑n_1 + ↑n = ⊤ ↔ ↑n_1 = ⊤ ∨ ↑n = ⊤ [PROOFSTEP] simp [GOAL] case refine_2.refine_2 a b : PartENat ⊢ ∀ (n n_1 : ℕ), ¬↑n_1 + ↑n = ⊤ [PROOFSTEP] simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const] [GOAL] a b c : PartENat hc : c ≠ ⊤ ⊢ a + c = b + c ↔ a = b [PROOFSTEP] rcases ne_top_iff.1 hc with ⟨c, rfl⟩ [GOAL] case intro a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ a + ↑c = b + ↑c ↔ a = b [PROOFSTEP] refine PartENat.casesOn a ?_ ?_ [GOAL] case intro.refine_1 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ⊤ + ↑c = b + ↑c ↔ ⊤ = b [PROOFSTEP] refine PartENat.casesOn b ?_ ?_ [GOAL] case intro.refine_2 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ∀ (n : ℕ), ↑n + ↑c = b + ↑c ↔ ↑n = b [PROOFSTEP] refine PartENat.casesOn b ?_ ?_ [GOAL] case intro.refine_1.refine_1 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ⊤ + ↑c = ⊤ + ↑c ↔ ⊤ = ⊤ [PROOFSTEP] simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat)] [GOAL] case intro.refine_1.refine_2 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ∀ (n : ℕ), ⊤ + ↑c = ↑n + ↑c ↔ ⊤ = ↑n [PROOFSTEP] simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat)] [GOAL] case intro.refine_2.refine_1 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ∀ (n : ℕ), ↑n + ↑c = ⊤ + ↑c ↔ ↑n = ⊤ [PROOFSTEP] simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat)] [GOAL] case intro.refine_2.refine_2 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ∀ (n n_1 : ℕ), ↑n_1 + ↑c = ↑n + ↑c ↔ ↑n_1 = ↑n [PROOFSTEP] simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat)] [GOAL] case intro.refine_2.refine_2 a b : PartENat c : ℕ hc : ↑c ≠ ⊤ ⊢ ∀ (n n_1 : ℕ), ↑n_1 + ↑c = ↑n + ↑c ↔ n_1 = n [PROOFSTEP] simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const] [GOAL] a b c : PartENat ha : a ≠ ⊤ ⊢ a + b = a + c ↔ b = c [PROOFSTEP] rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha] [GOAL] h : Decidable ⊤.Dom ⊢ toWithTop ⊤ = ⊤ [PROOFSTEP] convert toWithTop_top [GOAL] h : Decidable 0.Dom ⊢ toWithTop 0 = 0 [PROOFSTEP] convert toWithTop_zero [GOAL] n : ℕ x✝ : Decidable (↑n).Dom ⊢ toWithTop ↑n = ↑n [PROOFSTEP] simp only [← toWithTop_some] [GOAL] n : ℕ x✝ : Decidable (↑n).Dom ⊢ toWithTop ↑n = toWithTop ↑n [PROOFSTEP] congr [GOAL] n : ℕ h : Decidable (↑n).Dom ⊢ toWithTop ↑n = ↑n [PROOFSTEP] rw [toWithTop_natCast n] [GOAL] x y : PartENat hx : Decidable x.Dom hy : Decidable y.Dom ⊢ toWithTop x ≤ toWithTop y ↔ x ≤ y [PROOFSTEP] induction y using PartENat.casesOn generalizing hy [GOAL] case a x : PartENat hx : Decidable x.Dom hy : Decidable ⊤.Dom ⊢ toWithTop x ≤ toWithTop ⊤ ↔ x ≤ ⊤ [PROOFSTEP] simp [GOAL] case a x : PartENat hx : Decidable x.Dom n✝ : ℕ hy : Decidable (↑n✝).Dom ⊢ toWithTop x ≤ toWithTop ↑n✝ ↔ x ≤ ↑n✝ [PROOFSTEP] induction x using PartENat.casesOn generalizing hx [GOAL] case a.a n✝ : ℕ hy : Decidable (↑n✝).Dom hx : Decidable ⊤.Dom ⊢ toWithTop ⊤ ≤ toWithTop ↑n✝ ↔ ⊤ ≤ ↑n✝ [PROOFSTEP] simp [GOAL] case a.a n✝¹ : ℕ hy : Decidable (↑n✝¹).Dom n✝ : ℕ hx : Decidable (↑n✝).Dom ⊢ toWithTop ↑n✝ ≤ toWithTop ↑n✝¹ ↔ ↑n✝ ≤ ↑n✝¹ [PROOFSTEP] simp -- Porting note: this takes too long. [GOAL] ⊢ ↑Option.none = ⊤ [PROOFSTEP] rfl -- Porting note : new [GOAL] n : ℕ ⊢ ↑(Option.some n) = ↑n [PROOFSTEP] rfl -- Porting note : new [GOAL] n : ℕ∞ x✝ : Decidable (↑n).Dom ⊢ toWithTop ↑n = n [PROOFSTEP] induction n with | none => simp | some n => simp only [toWithTop_natCast', ofENat_some] rfl [GOAL] n : ℕ∞ x✝ : Decidable (↑n).Dom ⊢ toWithTop ↑n = n [PROOFSTEP] induction n with | none => simp | some n => simp only [toWithTop_natCast', ofENat_some] rfl [GOAL] case none x✝ : Decidable (↑Option.none).Dom ⊢ toWithTop ↑Option.none = Option.none [PROOFSTEP] | none => simp [GOAL] case none x✝ : Decidable (↑Option.none).Dom ⊢ toWithTop ↑Option.none = Option.none [PROOFSTEP] simp [GOAL] case some n : ℕ x✝ : Decidable (↑(Option.some n)).Dom ⊢ toWithTop ↑(Option.some n) = Option.some n [PROOFSTEP] | some n => simp only [toWithTop_natCast', ofENat_some] rfl [GOAL] case some n : ℕ x✝ : Decidable (↑(Option.some n)).Dom ⊢ toWithTop ↑(Option.some n) = Option.some n [PROOFSTEP] simp only [toWithTop_natCast', ofENat_some] [GOAL] case some n : ℕ x✝ : Decidable (↑(Option.some n)).Dom ⊢ ↑n = Option.some n [PROOFSTEP] rfl [GOAL] x y : PartENat ⊢ toWithTop (x + y) = toWithTop x + toWithTop y [PROOFSTEP] refine PartENat.casesOn y ?_ ?_ [GOAL] case refine_1 x y : PartENat ⊢ toWithTop (x + ⊤) = toWithTop x + toWithTop ⊤ [PROOFSTEP] refine PartENat.casesOn x ?_ ?_ --Porting note: was `simp [← Nat.cast_add, ← ENat.coe_add]` [GOAL] case refine_2 x y : PartENat ⊢ ∀ (n : ℕ), toWithTop (x + ↑n) = toWithTop x + toWithTop ↑n [PROOFSTEP] refine PartENat.casesOn x ?_ ?_ --Porting note: was `simp [← Nat.cast_add, ← ENat.coe_add]` [GOAL] case refine_1.refine_1 x y : PartENat ⊢ toWithTop (⊤ + ⊤) = toWithTop ⊤ + toWithTop ⊤ [PROOFSTEP] simp only [add_top, toWithTop_top', _root_.add_top] [GOAL] case refine_1.refine_2 x y : PartENat ⊢ ∀ (n : ℕ), toWithTop (↑n + ⊤) = toWithTop ↑n + toWithTop ⊤ [PROOFSTEP] simp only [add_top, toWithTop_top', toWithTop_natCast', _root_.add_top, forall_const] [GOAL] case refine_2.refine_1 x y : PartENat ⊢ ∀ (n : ℕ), toWithTop (⊤ + ↑n) = toWithTop ⊤ + toWithTop ↑n [PROOFSTEP] simp only [top_add, toWithTop_top', toWithTop_natCast', _root_.top_add, forall_const] [GOAL] case refine_2.refine_2 x y : PartENat ⊢ ∀ (n n_1 : ℕ), toWithTop (↑n + ↑n_1) = toWithTop ↑n + toWithTop ↑n_1 [PROOFSTEP] simp_rw [toWithTop_natCast', ← Nat.cast_add, toWithTop_natCast', forall_const] [GOAL] x : PartENat ⊢ (fun x => ↑x) ((fun x => toWithTop x) x) = x [PROOFSTEP] induction x using PartENat.casesOn [GOAL] case a ⊢ (fun x => ↑x) ((fun x => toWithTop x) ⊤) = ⊤ [PROOFSTEP] intros [GOAL] case a n✝ : ℕ ⊢ (fun x => ↑x) ((fun x => toWithTop x) ↑n✝) = ↑n✝ [PROOFSTEP] intros [GOAL] case a ⊢ (fun x => ↑x) ((fun x => toWithTop x) ⊤) = ⊤ [PROOFSTEP] simp [GOAL] case a n✝ : ℕ ⊢ (fun x => ↑x) ((fun x => toWithTop x) ↑n✝) = ↑n✝ [PROOFSTEP] simp [GOAL] case a ⊢ ↑⊤ = ⊤ [PROOFSTEP] rfl [GOAL] case a n✝ : ℕ ⊢ ↑↑n✝ = ↑n✝ [PROOFSTEP] rfl [GOAL] x : ℕ∞ ⊢ (fun x => toWithTop x) ((fun x => ↑x) x) = x [PROOFSTEP] simp [toWithTop_ofENat] [GOAL] ⊢ ↑withTopEquiv 0 = 0 [PROOFSTEP] simpa only [Nat.cast_zero] using withTopEquiv_natCast 0 [GOAL] x y : ℕ∞ ⊢ ↑withTopEquiv.symm x ≤ ↑withTopEquiv.symm y ↔ x ≤ y [PROOFSTEP] rw [← withTopEquiv_le] [GOAL] x y : ℕ∞ ⊢ ↑withTopEquiv (↑withTopEquiv.symm x) ≤ ↑withTopEquiv (↑withTopEquiv.symm y) ↔ x ≤ y [PROOFSTEP] simp [GOAL] x y : ℕ∞ ⊢ ↑withTopEquiv.symm x < ↑withTopEquiv.symm y ↔ x < y [PROOFSTEP] rw [← withTopEquiv_lt] [GOAL] x y : ℕ∞ ⊢ ↑withTopEquiv (↑withTopEquiv.symm x) < ↑withTopEquiv (↑withTopEquiv.symm y) ↔ x < y [PROOFSTEP] simp [GOAL] src✝ : PartENat ≃ ℕ∞ := withTopEquiv x y : PartENat ⊢ Equiv.toFun { toFun := src✝.toFun, invFun := src✝.invFun, left_inv := (_ : Function.LeftInverse src✝.invFun src✝.toFun), right_inv := (_ : Function.RightInverse src✝.invFun src✝.toFun) } (x + y) = Equiv.toFun { toFun := src✝.toFun, invFun := src✝.invFun, left_inv := (_ : Function.LeftInverse src✝.invFun src✝.toFun), right_inv := (_ : Function.RightInverse src✝.invFun src✝.toFun) } x + Equiv.toFun { toFun := src✝.toFun, invFun := src✝.invFun, left_inv := (_ : Function.LeftInverse src✝.invFun src✝.toFun), right_inv := (_ : Function.RightInverse src✝.invFun src✝.toFun) } y [PROOFSTEP] simp only [withTopEquiv] [GOAL] src✝ : PartENat ≃ ℕ∞ := withTopEquiv x y : PartENat ⊢ toWithTop (x + y) = toWithTop x + toWithTop y [PROOFSTEP] exact toWithTop_add [GOAL] ⊢ WellFounded fun x x_1 => x < x_1 [PROOFSTEP] classical change WellFounded fun a b : PartENat => a < b simp_rw [← withTopEquiv_lt] exact InvImage.wf _ (WithTop.wellFounded_lt Nat.lt_wfRel.wf) [GOAL] ⊢ WellFounded fun x x_1 => x < x_1 [PROOFSTEP] change WellFounded fun a b : PartENat => a < b [GOAL] ⊢ WellFounded fun a b => a < b [PROOFSTEP] simp_rw [← withTopEquiv_lt] [GOAL] ⊢ WellFounded fun a b => ↑withTopEquiv a < ↑withTopEquiv b [PROOFSTEP] exact InvImage.wf _ (WithTop.wellFounded_lt Nat.lt_wfRel.wf) [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m ⊢ ↑n < find P [PROOFSTEP] rw [coe_lt_iff] [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m ⊢ ∀ (h : (find P).Dom), n < Part.get (find P) h [PROOFSTEP] intro h₁ [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m h₁ : (find P).Dom ⊢ n < Part.get (find P) h₁ [PROOFSTEP] rw [find_get] [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m h₁ : (find P).Dom ⊢ n < Nat.find h₁ [PROOFSTEP] have h₂ := @Nat.find_spec P _ h₁ [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m h₁ : (find P).Dom h₂ : P (Nat.find h₁) ⊢ n < Nat.find h₁ [PROOFSTEP] revert h₂ [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m h₁ : (find P).Dom ⊢ P (Nat.find h₁) → n < Nat.find h₁ [PROOFSTEP] contrapose! [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (m : ℕ), m ≤ n → ¬P m h₁ : (find P).Dom ⊢ Nat.find h₁ ≤ n → ¬P (Nat.find h₁) [PROOFSTEP] exact h _ [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ ⊢ ↑n < find P ↔ ∀ (m : ℕ), m ≤ n → ¬P m [PROOFSTEP] refine' ⟨_, lt_find P n⟩ [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ ⊢ ↑n < find P → ∀ (m : ℕ), m ≤ n → ¬P m [PROOFSTEP] intro h m hm [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ↑n < find P m : ℕ hm : m ≤ n ⊢ ¬P m [PROOFSTEP] by_cases H : (find P).Dom [GOAL] case pos P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ↑n < find P m : ℕ hm : m ≤ n H : (find P).Dom ⊢ ¬P m [PROOFSTEP] apply Nat.find_min H [GOAL] case pos P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ↑n < find P m : ℕ hm : m ≤ n H : (find P).Dom ⊢ m < Nat.find H [PROOFSTEP] rw [coe_lt_iff] at h [GOAL] case pos P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ∀ (h : (find P).Dom), n < Part.get (find P) h m : ℕ hm : m ≤ n H : (find P).Dom ⊢ m < Nat.find H [PROOFSTEP] specialize h H [GOAL] case pos P : ℕ → Prop inst✝ : DecidablePred P n m : ℕ hm : m ≤ n H : (find P).Dom h : n < Part.get (find P) H ⊢ m < Nat.find H [PROOFSTEP] exact lt_of_le_of_lt hm h [GOAL] case neg P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : ↑n < find P m : ℕ hm : m ≤ n H : ¬(find P).Dom ⊢ ¬P m [PROOFSTEP] exact not_exists.mp H m [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : P n ⊢ find P ≤ ↑n [PROOFSTEP] rw [le_coe_iff] [GOAL] P : ℕ → Prop inst✝ : DecidablePred P n : ℕ h : P n ⊢ ∃ h, Part.get (find P) h ≤ n [PROOFSTEP] refine' ⟨⟨_, h⟩, @Nat.find_min' P _ _ _ h⟩
lemma cball_eq_empty [simp]: "cball x e = {} \<longleftrightarrow> e < 0"
*----------------------------------------------------------------------* subroutine set_interface_targets(tgt_info,name_infile, & name_orbinfo) *----------------------------------------------------------------------* * * Set targets from script interfaces: python iterface * name_infile is the input file name and name_orbinfo * is the name of the file with orbital informations, generated * by interfaces/put_orbinfo * * yuri, oct, 2014 *----------------------------------------------------------------------* implicit none include 'mdef_target_info.h' include 'ifc_input.h' type(target_info), intent(inout) :: & tgt_info character(*), intent(in) :: & name_infile, name_orbinfo integer :: & nkey, ikey, narg, iarg character(len=256) :: & file_name nkey = is_keyword_set('calculate.interfaces') do ikey = 1, nkey narg = is_argument_set('calculate.interfaces','file', & keycount=ikey) do iarg = 1, narg file_name = "" call get_argument_value('calculate.interfaces','file', & keycount=ikey,argcount=iarg,str=file_name) call set_python_targets(tgt_info,file_name,name_infile, & name_orbinfo) end do end do return end
import logic.basic --hide /- ## Exact Sometimes after rewriting the hypotheses and goal enough we reach a point where the goal is exactly the same as one of the hypothesis. In this case we want to tell Lean that we are finished, one of our hypotheses now matches the conclusion we needed to get to. The tactic to do this is called `exact`, and to use it we just need to supply the name of the hypothesis we want to use. For example if we were trying to prove that 3 divides some natural number `n` and we ended up with the goal state: ``` n : ℕ h : 3 ∣ n ⊢ 3 ∣ n ``` then `exact h,` would complete the proof. -/ /- Tactic : exact ## Summary If the goal is `⊢ X` then `exact x` will close the goal if and only if `x` is a term of type `X`. ## Details Say $P$, $Q$ and $R$ are types (i.e., what a mathematician might think of as either sets or propositions), and the local context looks like this: ``` p : P, h : P → Q, j : Q → R ⊢ R ``` If you can spot how to make a term of type `R`, then you can just make it and say you're done using the `exact` tactic together with the formula you have spotted. For example the above goal could be solved with `exact j(h(p)),` because $j(h(p))$ is easily checked to be a term of type $R$ (i.e., an element of the set $R$, or a proof of the proposition $R$). -/ /- Axiom : or_and_distrib_right : ∀ {a b c : Prop}, (a ∨ b) ∧ c ↔ a ∧ c ∨ b ∧ c -/ /- Axiom : not_and_self (a : Prop) : (¬a ∧ a) ↔ false -/ /- Axiom : or_false (a : Prop) : (a ∨ false) ↔ a -/ /- Axiom : and_comm : ∀ (a b : Prop), a ∧ b ↔ b ∧ a -/ /- Axiom : and_assoc : ∀ {c : Prop} (a b : Prop), (a ∧ b) ∧ c ↔ a ∧ b ∧ c -/ /- Axiom : and_self : ∀ (a : Prop), a ∧ a ↔ a -/ /- Lemma : no-side-bar -/ lemma prop_prop (P Q : Prop) (h : Q ∧ P ∧ Q) : (P ∨ ¬ Q) ∧ Q := begin rw or_and_distrib_right, rw not_and_self, rw or_false, rw and_comm at h, rw and_assoc at h, rw and_self at h, exact h, end