Context
stringlengths
285
157k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
18
3.69k
theorem
stringlengths
25
2.71k
proof
stringlengths
5
10.6k
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.FieldTheory.Separable import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.Algebra.CharP.Reduced /-! # Perfect fields and rings In this file we define perfect fields, together with a generalisation to (commutative) rings in prime characteristic. ## Main definitions / statements: * `PerfectRing`: a ring of characteristic `p` (prime) is said to be perfect in the sense of Serre, if its absolute Frobenius map `x ↦ xᵖ` is bijective. * `PerfectField`: a field `K` is said to be perfect if every irreducible polynomial over `K` is separable. * `PerfectRing.toPerfectField`: a field that is perfect in the sense of Serre is a perfect field. * `PerfectField.toPerfectRing`: a perfect field of characteristic `p` (prime) is perfect in the sense of Serre. * `PerfectField.ofCharZero`: all fields of characteristic zero are perfect. * `PerfectField.ofFinite`: all finite fields are perfect. * `PerfectField.separable_iff_squarefree`: a polynomial over a perfect field is separable iff it is square-free. * `Algebra.IsAlgebraic.isSeparable_of_perfectField`, `Algebra.IsAlgebraic.perfectField`: if `L / K` is an algebraic extension, `K` is a perfect field, then `L / K` is separable, and `L` is also a perfect field. -/ open Function Polynomial /-- A perfect ring of characteristic `p` (prime) in the sense of Serre. NB: This is not related to the concept with the same name introduced by Bass (related to projective covers of modules). -/ class PerfectRing (R : Type*) (p : ℕ) [CommSemiring R] [ExpChar R p] : Prop where /-- A ring is perfect if the Frobenius map is bijective. -/ bijective_frobenius : Bijective <| frobenius R p section PerfectRing variable (R : Type*) (p m n : ℕ) [CommSemiring R] [ExpChar R p] /-- For a reduced ring, surjectivity of the Frobenius map is a sufficient condition for perfection. -/ lemma PerfectRing.ofSurjective (R : Type*) (p : ℕ) [CommRing R] [ExpChar R p] [IsReduced R] (h : Surjective <| frobenius R p) : PerfectRing R p := ⟨frobenius_inj R p, h⟩ #align perfect_ring.of_surjective PerfectRing.ofSurjective instance PerfectRing.ofFiniteOfIsReduced (R : Type*) [CommRing R] [ExpChar R p] [Finite R] [IsReduced R] : PerfectRing R p := ofSurjective _ _ <| Finite.surjective_of_injective (frobenius_inj R p) variable [PerfectRing R p] @[simp] theorem bijective_frobenius : Bijective (frobenius R p) := PerfectRing.bijective_frobenius theorem bijective_iterateFrobenius : Bijective (iterateFrobenius R p n) := coe_iterateFrobenius R p n ▸ (bijective_frobenius R p).iterate n @[simp] theorem injective_frobenius : Injective (frobenius R p) := (bijective_frobenius R p).1 @[simp] theorem surjective_frobenius : Surjective (frobenius R p) := (bijective_frobenius R p).2 /-- The Frobenius automorphism for a perfect ring. -/ @[simps! apply] noncomputable def frobeniusEquiv : R ≃+* R := RingEquiv.ofBijective (frobenius R p) PerfectRing.bijective_frobenius #align frobenius_equiv frobeniusEquiv @[simp] theorem coe_frobeniusEquiv : ⇑(frobeniusEquiv R p) = frobenius R p := rfl #align coe_frobenius_equiv coe_frobeniusEquiv theorem frobeniusEquiv_def (x : R) : frobeniusEquiv R p x = x ^ p := rfl /-- The iterated Frobenius automorphism for a perfect ring. -/ @[simps! apply] noncomputable def iterateFrobeniusEquiv : R ≃+* R := RingEquiv.ofBijective (iterateFrobenius R p n) (bijective_iterateFrobenius R p n) @[simp] theorem coe_iterateFrobeniusEquiv : ⇑(iterateFrobeniusEquiv R p n) = iterateFrobenius R p n := rfl theorem iterateFrobeniusEquiv_def (x : R) : iterateFrobeniusEquiv R p n x = x ^ p ^ n := rfl theorem iterateFrobeniusEquiv_add_apply (x : R) : iterateFrobeniusEquiv R p (m + n) x = iterateFrobeniusEquiv R p m (iterateFrobeniusEquiv R p n x) := iterateFrobenius_add_apply R p m n x theorem iterateFrobeniusEquiv_add : iterateFrobeniusEquiv R p (m + n) = (iterateFrobeniusEquiv R p n).trans (iterateFrobeniusEquiv R p m) := RingEquiv.ext (iterateFrobeniusEquiv_add_apply R p m n) theorem iterateFrobeniusEquiv_symm_add_apply (x : R) : (iterateFrobeniusEquiv R p (m + n)).symm x = (iterateFrobeniusEquiv R p m).symm ((iterateFrobeniusEquiv R p n).symm x) := (iterateFrobeniusEquiv R p (m + n)).injective <| by rw [RingEquiv.apply_symm_apply, add_comm, iterateFrobeniusEquiv_add_apply, RingEquiv.apply_symm_apply, RingEquiv.apply_symm_apply] theorem iterateFrobeniusEquiv_symm_add : (iterateFrobeniusEquiv R p (m + n)).symm = (iterateFrobeniusEquiv R p n).symm.trans (iterateFrobeniusEquiv R p m).symm := RingEquiv.ext (iterateFrobeniusEquiv_symm_add_apply R p m n) theorem iterateFrobeniusEquiv_zero_apply (x : R) : iterateFrobeniusEquiv R p 0 x = x := by rw [iterateFrobeniusEquiv_def, pow_zero, pow_one]
Mathlib/FieldTheory/Perfect.lean
116
117
theorem iterateFrobeniusEquiv_one_apply (x : R) : iterateFrobeniusEquiv R p 1 x = x ^ p := by
rw [iterateFrobeniusEquiv_def, pow_one]
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.Data.Matroid.Dual /-! # Matroid Restriction Given `M : Matroid α` and `R : Set α`, the independent sets of `M` that are contained in `R` are the independent sets of another matroid `M ↾ R` with ground set `R`, called the 'restriction' of `M` to `R`. For `I, R ⊆ M.E`, `I` is a basis of `R` in `M` if and only if `I` is a base of the restriction `M ↾ R`, so this construction relates `Matroid.Basis` to `Matroid.Base`. If `N M : Matroid α` satisfy `N = M ↾ R` for some `R ⊆ M.E`, then we call `N` a 'restriction of `M`', and write `N ≤r M`. This is a partial order. This file proves that the restriction is a matroid and that the `≤r` order is a partial order, and gives related API. It also proves some `Basis` analogues of `Base` lemmas that, while they could be stated in `Data.Matroid.Basic`, are hard to prove without `Matroid.restrict` API. ## Main Definitions * `M.restrict R`, written `M ↾ R`, is the restriction of `M : Matroid α` to `R : Set α`: i.e. the matroid with ground set `R` whose independent sets are the `M`-independent subsets of `R`. * `Matroid.Restriction N M`, written `N ≤r M`, means that `N = M ↾ R` for some `R ⊆ M.E`. * `Matroid.StrictRestriction N M`, written `N <r M`, means that `N = M ↾ R` for some `R ⊂ M.E`. * `Matroidᵣ α` is a type synonym for `Matroid α`, equipped with the `PartialOrder` `≤r`. ## Implementation Notes Since `R` and `M.E` are both terms in `Set α`, to define the restriction `M ↾ R`, we need to either insist that `R ⊆ M.E`, or to say what happens when `R` contains the junk outside `M.E`. It turns out that `R ⊆ M.E` is just an unnecessary hypothesis; if we say the restriction `M ↾ R` has ground set `R` and its independent sets are the `M`-independent subsets of `R`, we always get a matroid, in which the elements of `R \ M.E` aren't in any independent sets. We could instead define this matroid to always be 'smaller' than `M` by setting `(M ↾ R).E := R ∩ M.E`, but this is worse definitionally, and more generally less convenient. This makes it possible to actually restrict a matroid 'upwards'; for instance, if `M : Matroid α` satisfies `M.E = ∅`, then `M ↾ Set.univ` is the matroid on `α` whose ground set is all of `α`, where the empty set is only the independent set. (Elements of `R` outside the ground set are all 'loops' of the matroid.) This is mathematically strange, but is useful for API building. The cost of allowing a restriction of `M` to be 'bigger' than the `M` itself is that the statement `M ↾ R ≤r M` is only true with the hypothesis `R ⊆ M.E` (at least, if we want `≤r` to be a partial order). But this isn't too inconvenient in practice. Indeed `(· ⊆ M.E)` proofs can often be automatically provided by `aesop_mat`. We define the restriction order `≤r` to give a `PartialOrder` instance on the type synonym `Matroidᵣ α` rather than `Matroid α` itself, because the `PartialOrder (Matroid α)` instance is reserved for the more mathematically important 'minor' order. -/ open Set namespace Matroid variable {α : Type*} {M : Matroid α} {R I J X Y : Set α} section restrict /-- The `IndepMatroid` whose independent sets are the independent subsets of `R`. -/ @[simps] def restrictIndepMatroid (M : Matroid α) (R : Set α) : IndepMatroid α where E := R Indep I := M.Indep I ∧ I ⊆ R indep_empty := ⟨M.empty_indep, empty_subset _⟩ indep_subset := fun I J h hIJ ↦ ⟨h.1.subset hIJ, hIJ.trans h.2⟩ indep_aug := by rintro I I' ⟨hI, hIY⟩ (hIn : ¬ M.Basis' I R) (hI' : M.Basis' I' R) rw [basis'_iff_basis_inter_ground] at hIn hI' obtain ⟨B', hB', rfl⟩ := hI'.exists_base obtain ⟨B, hB, hIB, hBIB'⟩ := hI.exists_base_subset_union_base hB' rw [hB'.inter_basis_iff_compl_inter_basis_dual, diff_inter_diff] at hI' have hss : M.E \ (B' ∪ (R ∩ M.E)) ⊆ M.E \ (B ∪ (R ∩ M.E)) := by apply diff_subset_diff_right rw [union_subset_iff, and_iff_left subset_union_right, union_comm] exact hBIB'.trans (union_subset_union_left _ (subset_inter hIY hI.subset_ground)) have hi : M✶.Indep (M.E \ (B ∪ (R ∩ M.E))) := by rw [dual_indep_iff_exists] exact ⟨B, hB, disjoint_of_subset_right subset_union_left disjoint_sdiff_left⟩ have h_eq := hI'.eq_of_subset_indep hi hss (diff_subset_diff_right subset_union_right) rw [h_eq, ← diff_inter_diff, ← hB.inter_basis_iff_compl_inter_basis_dual] at hI' obtain ⟨J, hJ, hIJ⟩ := hI.subset_basis_of_subset (subset_inter hIB (subset_inter hIY hI.subset_ground)) obtain rfl := hI'.indep.eq_of_basis hJ have hIJ' : I ⊂ B ∩ (R ∩ M.E) := hIJ.ssubset_of_ne (fun he ↦ hIn (by rwa [he])) obtain ⟨e, he⟩ := exists_of_ssubset hIJ' exact ⟨e, ⟨⟨(hBIB' he.1.1).elim (fun h ↦ (he.2 h).elim) id,he.1.2⟩, he.2⟩, hI'.indep.subset (insert_subset he.1 hIJ), insert_subset he.1.2.1 hIY⟩ indep_maximal := by rintro A hAX I ⟨hI, _⟩ hIA obtain ⟨J, hJ, hIJ⟩ := hI.subset_basis'_of_subset hIA; use J rw [mem_maximals_setOf_iff, and_iff_left hJ.subset, and_iff_left hIJ, and_iff_right ⟨hJ.indep, hJ.subset.trans hAX⟩] exact fun K ⟨⟨hK, _⟩, _, hKA⟩ hJK ↦ hJ.eq_of_subset_indep hK hJK hKA subset_ground I := And.right /-- Change the ground set of a matroid to some `R : Set α`. The independent sets of the restriction are the independent subsets of the new ground set. Most commonly used when `R ⊆ M.E`, but it is convenient not to require this. The elements of `R \ M.E` become 'loops'. -/ def restrict (M : Matroid α) (R : Set α) : Matroid α := (M.restrictIndepMatroid R).matroid /-- `M ↾ R` means `M.restrict R`. -/ scoped infixl:65 " ↾ " => Matroid.restrict @[simp] theorem restrict_indep_iff : (M ↾ R).Indep I ↔ M.Indep I ∧ I ⊆ R := Iff.rfl theorem Indep.indep_restrict_of_subset (h : M.Indep I) (hIR : I ⊆ R) : (M ↾ R).Indep I := restrict_indep_iff.mpr ⟨h,hIR⟩ theorem Indep.of_restrict (hI : (M ↾ R).Indep I) : M.Indep I := (restrict_indep_iff.1 hI).1 @[simp] theorem restrict_ground_eq : (M ↾ R).E = R := rfl theorem restrict_finite {R : Set α} (hR : R.Finite) : (M ↾ R).Finite := ⟨hR⟩ @[simp] theorem restrict_dep_iff : (M ↾ R).Dep X ↔ ¬ M.Indep X ∧ X ⊆ R := by rw [Dep, restrict_indep_iff, restrict_ground_eq]; tauto @[simp] theorem restrict_ground_eq_self (M : Matroid α) : (M ↾ M.E) = M := by refine eq_of_indep_iff_indep_forall rfl ?_; aesop theorem restrict_restrict_eq {R₁ R₂ : Set α} (M : Matroid α) (hR : R₂ ⊆ R₁) : (M ↾ R₁) ↾ R₂ = M ↾ R₂ := by refine eq_of_indep_iff_indep_forall rfl ?_ simp only [restrict_ground_eq, restrict_indep_iff, and_congr_left_iff, and_iff_left_iff_imp] exact fun _ h _ _ ↦ h.trans hR @[simp] theorem restrict_idem (M : Matroid α) (R : Set α) : M ↾ R ↾ R = M ↾ R := by rw [M.restrict_restrict_eq Subset.rfl] @[simp] theorem base_restrict_iff (hX : X ⊆ M.E := by aesop_mat) : (M ↾ X).Base I ↔ M.Basis I X := by simp_rw [base_iff_maximal_indep, basis_iff', restrict_indep_iff, and_iff_left hX, and_assoc] aesop theorem base_restrict_iff' : (M ↾ X).Base I ↔ M.Basis' I X := by simp_rw [Basis', base_iff_maximal_indep, mem_maximals_setOf_iff, restrict_indep_iff] theorem Basis.restrict_base (h : M.Basis I X) : (M ↾ X).Base I := by rw [basis_iff'] at h simp_rw [base_iff_maximal_indep, restrict_indep_iff, and_imp, and_assoc, and_iff_right h.1.1, and_iff_right h.1.2.1] exact fun J hJ hJX hIJ ↦ h.1.2.2 _ hJ hIJ hJX instance restrict_finiteRk [M.FiniteRk] (R : Set α) : (M ↾ R).FiniteRk := let ⟨_, hB⟩ := (M ↾ R).exists_base hB.finiteRk_of_finite (hB.indep.of_restrict.finite) instance restrict_finitary [Finitary M] (R : Set α) : Finitary (M ↾ R) := by refine ⟨fun I hI ↦ ?_⟩ simp only [restrict_indep_iff] at * rw [indep_iff_forall_finite_subset_indep] exact ⟨fun J hJ hJfin ↦ (hI J hJ hJfin).1, fun e heI ↦ singleton_subset_iff.1 (hI _ (by simpa) (toFinite _)).2⟩ @[simp] theorem Basis.base_restrict (h : M.Basis I X) : (M ↾ X).Base I := (base_restrict_iff h.subset_ground).mpr h theorem Basis.basis_restrict_of_subset (hI : M.Basis I X) (hXY : X ⊆ Y) : (M ↾ Y).Basis I X := by rwa [← base_restrict_iff, M.restrict_restrict_eq hXY, base_restrict_iff] theorem basis'_restrict_iff : (M ↾ R).Basis' I X ↔ M.Basis' I (X ∩ R) ∧ I ⊆ R := by simp_rw [Basis', mem_maximals_setOf_iff, restrict_indep_iff, subset_inter_iff, and_imp]; tauto theorem basis_restrict_iff' : (M ↾ R).Basis I X ↔ M.Basis I (X ∩ M.E) ∧ X ⊆ R := by rw [basis_iff_basis'_subset_ground, basis'_restrict_iff, restrict_ground_eq, and_congr_left_iff, ← basis'_iff_basis_inter_ground] intro hXR rw [inter_eq_self_of_subset_left hXR, and_iff_left_iff_imp] exact fun h ↦ h.subset.trans hXR theorem basis_restrict_iff (hR : R ⊆ M.E := by aesop_mat) : (M ↾ R).Basis I X ↔ M.Basis I X ∧ X ⊆ R := by rw [basis_restrict_iff', and_congr_left_iff] intro hXR rw [← basis'_iff_basis_inter_ground, basis'_iff_basis] theorem restrict_eq_restrict_iff (M M' : Matroid α) (X : Set α) : M ↾ X = M' ↾ X ↔ ∀ I, I ⊆ X → (M.Indep I ↔ M'.Indep I) := by refine ⟨fun h I hIX ↦ ?_, fun h ↦ eq_of_indep_iff_indep_forall rfl fun I (hI : I ⊆ X) ↦ ?_⟩ · rw [← and_iff_left (a := (M.Indep I)) hIX, ← and_iff_left (a := (M'.Indep I)) hIX, ← restrict_indep_iff, h, restrict_indep_iff] rw [restrict_indep_iff, and_iff_left hI, restrict_indep_iff, and_iff_left hI, h _ hI] @[simp] theorem restrict_eq_self_iff : M ↾ R = M ↔ R = M.E := ⟨fun h ↦ by rw [← h]; rfl, fun h ↦ by simp [h]⟩ end restrict section Restriction variable {N : Matroid α} /-- `Restriction N M` means that `N = M ↾ R` for some subset `R` of `M.E` -/ def Restriction (N M : Matroid α) : Prop := ∃ R ⊆ M.E, N = M ↾ R /-- `StrictRestriction N M` means that `N = M ↾ R` for some strict subset `R` of `M.E` -/ def StrictRestriction (N M : Matroid α) : Prop := Restriction N M ∧ ¬ Restriction M N /-- `N ≤r M` means that `N` is a `Restriction` of `M`. -/ scoped infix:50 " ≤r " => Restriction /-- `N <r M` means that `N` is a `StrictRestriction` of `M`. -/ scoped infix:50 " <r " => StrictRestriction /-- A type synonym for matroids with the restriction order. (The `PartialOrder` on `Matroid α` is reserved for the minor order) -/ @[ext] structure Matroidᵣ (α : Type*) where ofMatroid :: /-- The underlying `Matroid`.-/ toMatroid : Matroid α instance {α : Type*} : CoeOut (Matroidᵣ α) (Matroid α) where coe := Matroidᵣ.toMatroid @[simp] theorem Matroidᵣ.coe_inj {M₁ M₂ : Matroidᵣ α} : (M₁ : Matroid α) = (M₂ : Matroid α) ↔ M₁ = M₂ := by cases M₁; cases M₂; simp instance {α : Type*} : PartialOrder (Matroidᵣ α) where le := (· ≤r ·) le_refl M := ⟨(M : Matroid α).E, Subset.rfl, (M : Matroid α).restrict_ground_eq_self.symm⟩ le_trans M₁ M₂ M₃ := by rintro ⟨R, hR, h₁⟩ ⟨R', hR', h₂⟩ change _ ≤r _ rw [h₂] at h₁ hR rw [h₁, restrict_restrict_eq _ (show R ⊆ R' from hR)] exact ⟨R, hR.trans hR', rfl⟩ le_antisymm M₁ M₂ := by rintro ⟨R, hR, h⟩ ⟨R', hR', h'⟩ rw [h', restrict_ground_eq] at hR rw [h, restrict_ground_eq] at hR' rw [← Matroidᵣ.coe_inj, h, h', hR.antisymm hR', restrict_idem] @[simp] protected theorem Matroidᵣ.le_iff {M M' : Matroidᵣ α} : M ≤ M' ↔ (M : Matroid α) ≤r (M' : Matroid α) := Iff.rfl @[simp] protected theorem Matroidᵣ.lt_iff {M M' : Matroidᵣ α} : M < M' ↔ (M : Matroid α) <r (M' : Matroid α) := Iff.rfl theorem ofMatroid_le_iff {M M' : Matroid α} : Matroidᵣ.ofMatroid M ≤ Matroidᵣ.ofMatroid M' ↔ M ≤r M' := by simp theorem ofMatroid_lt_iff {M M' : Matroid α} : Matroidᵣ.ofMatroid M < Matroidᵣ.ofMatroid M' ↔ M <r M' := by simp theorem Restriction.refl : M ≤r M := le_refl (Matroidᵣ.ofMatroid M) theorem Restriction.antisymm {M' : Matroid α} (h : M ≤r M') (h' : M' ≤r M) : M = M' := by simpa using (ofMatroid_le_iff.2 h).antisymm (ofMatroid_le_iff.2 h') theorem Restriction.trans {M₁ M₂ M₃ : Matroid α} (h : M₁ ≤r M₂) (h' : M₂ ≤r M₃) : M₁ ≤r M₃ := le_trans (α := Matroidᵣ α) h h' theorem restrict_restriction (M : Matroid α) (R : Set α) (hR : R ⊆ M.E := by aesop_mat) : M ↾ R ≤r M := ⟨R, hR, rfl⟩ theorem Restriction.eq_restrict (h : N ≤r M) : M ↾ N.E = N := by obtain ⟨R, -, rfl⟩ := h; rw [restrict_ground_eq] theorem Restriction.subset (h : N ≤r M) : N.E ⊆ M.E := by obtain ⟨R, hR, rfl⟩ := h; exact hR theorem Restriction.exists_eq_restrict (h : N ≤r M) : ∃ R ⊆ M.E, N = M ↾ R := h theorem Restriction.of_subset {R' : Set α} (M : Matroid α) (h : R ⊆ R') : (M ↾ R) ≤r (M ↾ R') := by rw [← restrict_restrict_eq M h]; exact restrict_restriction _ _ h theorem restriction_iff_exists : (N ≤r M) ↔ ∃ R, R ⊆ M.E ∧ N = M ↾ R := by use Restriction.exists_eq_restrict; rintro ⟨R, hR, rfl⟩; exact restrict_restriction M R hR theorem StrictRestriction.restriction (h : N <r M) : N ≤r M := h.1 theorem StrictRestriction.ne (h : N <r M) : N ≠ M := by rintro rfl; rw [← ofMatroid_lt_iff] at h; simp at h theorem StrictRestriction.irrefl (M : Matroid α) : ¬ (M <r M) := fun h ↦ h.ne rfl theorem StrictRestriction.ssubset (h : N <r M) : N.E ⊂ M.E := by obtain ⟨R, -, rfl⟩ := h.1 refine h.restriction.subset.ssubset_of_ne (fun h' ↦ h.2 ⟨R, Subset.rfl, ?_⟩) rw [show R = M.E from h', restrict_idem, restrict_ground_eq_self] theorem StrictRestriction.eq_restrict (h : N <r M) : M ↾ N.E = N := h.restriction.eq_restrict theorem StrictRestriction.exists_eq_restrict (h : N <r M) : ∃ R, R ⊂ M.E ∧ N = M ↾ R := ⟨N.E, h.ssubset, by rw [h.eq_restrict]⟩ theorem Restriction.strictRestriction_of_ne (h : N ≤r M) (hne : N ≠ M) : N <r M := ⟨h, fun h' ↦ hne <| h.antisymm h'⟩ theorem Restriction.eq_or_strictRestriction (h : N ≤r M) : N = M ∨ N <r M := by simpa using eq_or_lt_of_le (ofMatroid_le_iff.2 h) theorem restrict_strictRestriction {M : Matroid α} (hR : R ⊂ M.E) : M ↾ R <r M := by refine (M.restrict_restriction R hR.subset).strictRestriction_of_ne (fun h ↦ ?_) rw [← h, restrict_ground_eq] at hR exact hR.ne rfl theorem Restriction.strictRestriction_of_ground_ne (h : N ≤r M) (hne : N.E ≠ M.E) : N <r M := by rw [← h.eq_restrict] exact restrict_strictRestriction (h.subset.ssubset_of_ne hne) theorem StrictRestriction.of_ssubset {R' : Set α} (M : Matroid α) (h : R ⊂ R') : (M ↾ R) <r (M ↾ R') := (Restriction.of_subset M h.subset).strictRestriction_of_ground_ne h.ne theorem Restriction.finite {M : Matroid α} [M.Finite] (h : N ≤r M) : N.Finite := by obtain ⟨R, hR, rfl⟩ := h exact restrict_finite <| M.ground_finite.subset hR theorem Restriction.finiteRk {M : Matroid α} [FiniteRk M] (h : N ≤r M) : N.FiniteRk := by obtain ⟨R, -, rfl⟩ := h infer_instance theorem Restriction.finitary {M : Matroid α} [Finitary M] (h : N ≤r M) : N.Finitary := by obtain ⟨R, -, rfl⟩ := h infer_instance theorem finite_setOf_restriction (M : Matroid α) [M.Finite] : {N | N ≤r M}.Finite := (M.ground_finite.finite_subsets.image (fun R ↦ M ↾ R)).subset <| by rintro _ ⟨R, hR, rfl⟩; exact ⟨_, hR, rfl⟩
Mathlib/Data/Matroid/Restrict.lean
351
352
theorem Indep.of_restriction (hI : N.Indep I) (hNM : N ≤r M) : M.Indep I := by
obtain ⟨R, -, rfl⟩ := hNM; exact hI.of_restrict
/- Copyright (c) 2020 Jalex Stark. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jalex Stark, Scott Morrison, Eric Wieser, Oliver Nash, Wen Yang -/ import Mathlib.Data.Matrix.Basic import Mathlib.LinearAlgebra.Matrix.Trace #align_import data.matrix.basis from "leanprover-community/mathlib"@"320df450e9abeb5fc6417971e75acb6ae8bc3794" /-! # Matrices with a single non-zero element. This file provides `Matrix.stdBasisMatrix`. The matrix `Matrix.stdBasisMatrix i j c` has `c` at position `(i, j)`, and zeroes elsewhere. -/ variable {l m n : Type*} variable {R α : Type*} namespace Matrix open Matrix variable [DecidableEq l] [DecidableEq m] [DecidableEq n] variable [Semiring α] /-- `stdBasisMatrix i j a` is the matrix with `a` in the `i`-th row, `j`-th column, and zeroes elsewhere. -/ def stdBasisMatrix (i : m) (j : n) (a : α) : Matrix m n α := fun i' j' => if i = i' ∧ j = j' then a else 0 #align matrix.std_basis_matrix Matrix.stdBasisMatrix @[simp] theorem smul_stdBasisMatrix [SMulZeroClass R α] (r : R) (i : m) (j : n) (a : α) : r • stdBasisMatrix i j a = stdBasisMatrix i j (r • a) := by unfold stdBasisMatrix ext simp [smul_ite] #align matrix.smul_std_basis_matrix Matrix.smul_stdBasisMatrix @[simp] theorem stdBasisMatrix_zero (i : m) (j : n) : stdBasisMatrix i j (0 : α) = 0 := by unfold stdBasisMatrix ext simp #align matrix.std_basis_matrix_zero Matrix.stdBasisMatrix_zero theorem stdBasisMatrix_add (i : m) (j : n) (a b : α) : stdBasisMatrix i j (a + b) = stdBasisMatrix i j a + stdBasisMatrix i j b := by unfold stdBasisMatrix; ext split_ifs with h <;> simp [h] #align matrix.std_basis_matrix_add Matrix.stdBasisMatrix_add theorem mulVec_stdBasisMatrix [Fintype m] (i : n) (j : m) (c : α) (x : m → α) : mulVec (stdBasisMatrix i j c) x = Function.update (0 : n → α) i (c * x j) := by ext i' simp [stdBasisMatrix, mulVec, dotProduct] rcases eq_or_ne i i' with rfl|h · simp simp [h, h.symm] theorem matrix_eq_sum_std_basis [Fintype m] [Fintype n] (x : Matrix m n α) : x = ∑ i : m, ∑ j : n, stdBasisMatrix i j (x i j) := by ext i j; symm iterate 2 rw [Finset.sum_apply] -- Porting note: was `convert` refine (Fintype.sum_eq_single i ?_).trans ?_; swap · -- Porting note: `simp` seems unwilling to apply `Fintype.sum_apply` simp (config := { unfoldPartialApp := true }) only [stdBasisMatrix] rw [Fintype.sum_apply, Fintype.sum_apply] simp · intro j' hj' -- Porting note: `simp` seems unwilling to apply `Fintype.sum_apply` simp (config := { unfoldPartialApp := true }) only [stdBasisMatrix] rw [Fintype.sum_apply, Fintype.sum_apply] simp [hj'] #align matrix.matrix_eq_sum_std_basis Matrix.matrix_eq_sum_std_basis -- TODO: tie this up with the `Basis` machinery of linear algebra -- this is not completely trivial because we are indexing by two types, instead of one -- TODO: add `std_basis_vec` theorem std_basis_eq_basis_mul_basis (i : m) (j : n) : stdBasisMatrix i j (1 : α) = vecMulVec (fun i' => ite (i = i') 1 0) fun j' => ite (j = j') 1 0 := by ext i' j' -- Porting note: was `norm_num [std_basis_matrix, vec_mul_vec]` though there are no numerals -- involved. simp only [stdBasisMatrix, vecMulVec, mul_ite, mul_one, mul_zero, of_apply] -- Porting note: added next line simp_rw [@and_comm (i = i')] exact ite_and _ _ _ _ #align matrix.std_basis_eq_basis_mul_basis Matrix.std_basis_eq_basis_mul_basis -- todo: the old proof used fintypes, I don't know `Finsupp` but this feels generalizable @[elab_as_elim] protected theorem induction_on' [Finite m] [Finite n] {P : Matrix m n α → Prop} (M : Matrix m n α) (h_zero : P 0) (h_add : ∀ p q, P p → P q → P (p + q)) (h_std_basis : ∀ (i : m) (j : n) (x : α), P (stdBasisMatrix i j x)) : P M := by cases nonempty_fintype m; cases nonempty_fintype n rw [matrix_eq_sum_std_basis M, ← Finset.sum_product'] apply Finset.sum_induction _ _ h_add h_zero · intros apply h_std_basis #align matrix.induction_on' Matrix.induction_on' @[elab_as_elim] protected theorem induction_on [Finite m] [Finite n] [Nonempty m] [Nonempty n] {P : Matrix m n α → Prop} (M : Matrix m n α) (h_add : ∀ p q, P p → P q → P (p + q)) (h_std_basis : ∀ i j x, P (stdBasisMatrix i j x)) : P M := Matrix.induction_on' M (by inhabit m inhabit n simpa using h_std_basis default default 0) h_add h_std_basis #align matrix.induction_on Matrix.induction_on namespace StdBasisMatrix section variable (i : m) (j : n) (c : α) (i' : m) (j' : n) @[simp] theorem apply_same : stdBasisMatrix i j c i j = c := if_pos (And.intro rfl rfl) #align matrix.std_basis_matrix.apply_same Matrix.StdBasisMatrix.apply_same @[simp] theorem apply_of_ne (h : ¬(i = i' ∧ j = j')) : stdBasisMatrix i j c i' j' = 0 := by simp only [stdBasisMatrix, and_imp, ite_eq_right_iff] tauto #align matrix.std_basis_matrix.apply_of_ne Matrix.StdBasisMatrix.apply_of_ne @[simp] theorem apply_of_row_ne {i i' : m} (hi : i ≠ i') (j j' : n) (a : α) : stdBasisMatrix i j a i' j' = 0 := by simp [hi] #align matrix.std_basis_matrix.apply_of_row_ne Matrix.StdBasisMatrix.apply_of_row_ne @[simp] theorem apply_of_col_ne (i i' : m) {j j' : n} (hj : j ≠ j') (a : α) : stdBasisMatrix i j a i' j' = 0 := by simp [hj] #align matrix.std_basis_matrix.apply_of_col_ne Matrix.StdBasisMatrix.apply_of_col_ne end section variable (i j : n) (c : α) (i' j' : n) @[simp] theorem diag_zero (h : j ≠ i) : diag (stdBasisMatrix i j c) = 0 := funext fun _ => if_neg fun ⟨e₁, e₂⟩ => h (e₂.trans e₁.symm) #align matrix.std_basis_matrix.diag_zero Matrix.StdBasisMatrix.diag_zero @[simp] theorem diag_same : diag (stdBasisMatrix i i c) = Pi.single i c := by ext j by_cases hij : i = j <;> (try rw [hij]) <;> simp [hij] #align matrix.std_basis_matrix.diag_same Matrix.StdBasisMatrix.diag_same variable [Fintype n] @[simp] theorem trace_zero (h : j ≠ i) : trace (stdBasisMatrix i j c) = 0 := by -- Porting note: added `-diag_apply` simp [trace, -diag_apply, h] #align matrix.std_basis_matrix.trace_zero Matrix.StdBasisMatrix.trace_zero @[simp] theorem trace_eq : trace (stdBasisMatrix i i c) = c := by -- Porting note: added `-diag_apply` simp [trace, -diag_apply] #align matrix.std_basis_matrix.trace_eq Matrix.StdBasisMatrix.trace_eq @[simp] theorem mul_left_apply_same (b : n) (M : Matrix n n α) : (stdBasisMatrix i j c * M) i b = c * M j b := by simp [mul_apply, stdBasisMatrix] #align matrix.std_basis_matrix.mul_left_apply_same Matrix.StdBasisMatrix.mul_left_apply_same @[simp] theorem mul_right_apply_same (a : n) (M : Matrix n n α) : (M * stdBasisMatrix i j c) a j = M a i * c := by simp [mul_apply, stdBasisMatrix, mul_comm] #align matrix.std_basis_matrix.mul_right_apply_same Matrix.StdBasisMatrix.mul_right_apply_same @[simp] theorem mul_left_apply_of_ne (a b : n) (h : a ≠ i) (M : Matrix n n α) : (stdBasisMatrix i j c * M) a b = 0 := by simp [mul_apply, h.symm] #align matrix.std_basis_matrix.mul_left_apply_of_ne Matrix.StdBasisMatrix.mul_left_apply_of_ne @[simp] theorem mul_right_apply_of_ne (a b : n) (hbj : b ≠ j) (M : Matrix n n α) : (M * stdBasisMatrix i j c) a b = 0 := by simp [mul_apply, hbj.symm] #align matrix.std_basis_matrix.mul_right_apply_of_ne Matrix.StdBasisMatrix.mul_right_apply_of_ne @[simp] theorem mul_same (k : n) (d : α) : stdBasisMatrix i j c * stdBasisMatrix j k d = stdBasisMatrix i k (c * d) := by ext a b simp only [mul_apply, stdBasisMatrix, boole_mul] by_cases h₁ : i = a <;> by_cases h₂ : k = b <;> simp [h₁, h₂] #align matrix.std_basis_matrix.mul_same Matrix.StdBasisMatrix.mul_same @[simp] theorem mul_of_ne {k l : n} (h : j ≠ k) (d : α) : stdBasisMatrix i j c * stdBasisMatrix k l d = 0 := by ext a b simp only [mul_apply, boole_mul, stdBasisMatrix] by_cases h₁ : i = a -- porting note (#10745): was `simp [h₁, h, h.symm]` · simp only [h₁, true_and, mul_ite, ite_mul, zero_mul, mul_zero, ← ite_and, zero_apply] refine Finset.sum_eq_zero (fun x _ => ?_) apply if_neg rintro ⟨⟨rfl, rfl⟩, h⟩ contradiction · simp only [h₁, false_and, ite_false, mul_ite, zero_mul, mul_zero, ite_self, Finset.sum_const_zero, zero_apply] #align matrix.std_basis_matrix.mul_of_ne Matrix.StdBasisMatrix.mul_of_ne end end StdBasisMatrix section Commute variable [Fintype n] theorem row_eq_zero_of_commute_stdBasisMatrix {i j k : n} {M : Matrix n n α} (hM : Commute (stdBasisMatrix i j 1) M) (hkj : k ≠ j) : M j k = 0 := by have := ext_iff.mpr hM i k aesop theorem col_eq_zero_of_commute_stdBasisMatrix {i j k : n} {M : Matrix n n α} (hM : Commute (stdBasisMatrix i j 1) M) (hki : k ≠ i) : M k i = 0 := by have := ext_iff.mpr hM k j aesop theorem diag_eq_of_commute_stdBasisMatrix {i j : n} {M : Matrix n n α} (hM : Commute (stdBasisMatrix i j 1) M) : M i i = M j j := by have := ext_iff.mpr hM i j aesop /-- `M` is a scalar matrix if it commutes with every non-diagonal `stdBasisMatrix`. ​-/
Mathlib/Data/Matrix/Basis.lean
247
263
theorem mem_range_scalar_of_commute_stdBasisMatrix {M : Matrix n n α} (hM : Pairwise fun i j => Commute (stdBasisMatrix i j 1) M) : M ∈ Set.range (Matrix.scalar n) := by
cases isEmpty_or_nonempty n · exact ⟨0, Subsingleton.elim _ _⟩ obtain ⟨i⟩ := ‹Nonempty n› refine ⟨M i i, Matrix.ext fun j k => ?_⟩ simp only [scalar_apply] obtain rfl | hkl := Decidable.eq_or_ne j k · rw [diagonal_apply_eq] obtain rfl | hij := Decidable.eq_or_ne i j · rfl · exact diag_eq_of_commute_stdBasisMatrix (hM hij) · rw [diagonal_apply_ne _ hkl] obtain rfl | hij := Decidable.eq_or_ne i j · rw [col_eq_zero_of_commute_stdBasisMatrix (hM hkl.symm) hkl] · rw [row_eq_zero_of_commute_stdBasisMatrix (hM hij) hkl.symm]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.MeasureTheory.Function.ConditionalExpectation.Unique import Mathlib.MeasureTheory.Function.L2Space #align_import measure_theory.function.conditional_expectation.condexp_L2 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Conditional expectation in L2 This file contains one step of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. We build the conditional expectation of an `L²` function, as an element of `L²`. This is the orthogonal projection on the subspace of almost everywhere `m`-measurable functions. ## Main definitions * `condexpL2`: Conditional expectation of a function in L2 with respect to a sigma-algebra: it is the orthogonal projection on the subspace `lpMeas`. ## Implementation notes Most of the results in this file are valid for a complete real normed space `F`. However, some lemmas also use `𝕜 : RCLike`: * `condexpL2` is defined only for an `InnerProductSpace` for now, and we use `𝕜` for its field. * results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to have `NormedSpace 𝕜 F`. -/ set_option linter.uppercaseLean3 false open TopologicalSpace Filter ContinuousLinearMap open scoped ENNReal Topology MeasureTheory namespace MeasureTheory variable {α E E' F G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- E for an inner product space [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] -- E' for an inner product space on which we compute integrals [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E'] -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y local notation "⟪" x ", " y "⟫₂" => @inner 𝕜 (α →₂[μ] E) _ x y -- Porting note: the argument `E` of `condexpL2` is not automatically filled in Lean 4. -- To avoid typing `(E := _)` every time it is made explicit. variable (E 𝕜) /-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/ noncomputable def condexpL2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] lpMeas E 𝕜 m 2 μ := @orthogonalProjection 𝕜 (α →₂[μ] E) _ _ _ (lpMeas E 𝕜 m 2 μ) haveI : Fact (m ≤ m0) := ⟨hm⟩ inferInstance #align measure_theory.condexp_L2 MeasureTheory.condexpL2 variable {E 𝕜} theorem aeStronglyMeasurable'_condexpL2 (hm : m ≤ m0) (f : α →₂[μ] E) : AEStronglyMeasurable' (β := E) m (condexpL2 E 𝕜 hm f) μ := lpMeas.aeStronglyMeasurable' _ #align measure_theory.ae_strongly_measurable'_condexp_L2 MeasureTheory.aeStronglyMeasurable'_condexpL2 theorem integrableOn_condexpL2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) : IntegrableOn (E := E) (condexpL2 E 𝕜 hm f) s μ := integrableOn_Lp_of_measure_ne_top (condexpL2 E 𝕜 hm f : α →₂[μ] E) fact_one_le_two_ennreal.elim hμs #align measure_theory.integrable_on_condexp_L2_of_measure_ne_top MeasureTheory.integrableOn_condexpL2_of_measure_ne_top theorem integrable_condexpL2_of_isFiniteMeasure (hm : m ≤ m0) [IsFiniteMeasure μ] {f : α →₂[μ] E} : Integrable (β := E) (condexpL2 E 𝕜 hm f) μ := integrableOn_univ.mp <| integrableOn_condexpL2_of_measure_ne_top hm (measure_ne_top _ _) f #align measure_theory.integrable_condexp_L2_of_is_finite_measure MeasureTheory.integrable_condexpL2_of_isFiniteMeasure theorem norm_condexpL2_le_one (hm : m ≤ m0) : ‖@condexpL2 α E 𝕜 _ _ _ _ _ _ μ hm‖ ≤ 1 := haveI : Fact (m ≤ m0) := ⟨hm⟩ orthogonalProjection_norm_le _ #align measure_theory.norm_condexp_L2_le_one MeasureTheory.norm_condexpL2_le_one theorem norm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖condexpL2 E 𝕜 hm f‖ ≤ ‖f‖ := ((@condexpL2 _ E 𝕜 _ _ _ _ _ _ μ hm).le_opNorm f).trans (mul_le_of_le_one_left (norm_nonneg _) (norm_condexpL2_le_one hm)) #align measure_theory.norm_condexp_L2_le MeasureTheory.norm_condexpL2_le theorem snorm_condexpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : snorm (F := E) (condexpL2 E 𝕜 hm f) 2 μ ≤ snorm f 2 μ := by rw [lpMeas_coe, ← ENNReal.toReal_le_toReal (Lp.snorm_ne_top _) (Lp.snorm_ne_top _), ← Lp.norm_def, ← Lp.norm_def, Submodule.norm_coe] exact norm_condexpL2_le hm f #align measure_theory.snorm_condexp_L2_le MeasureTheory.snorm_condexpL2_le theorem norm_condexpL2_coe_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖(condexpL2 E 𝕜 hm f : α →₂[μ] E)‖ ≤ ‖f‖ := by rw [Lp.norm_def, Lp.norm_def, ← lpMeas_coe] refine (ENNReal.toReal_le_toReal ?_ (Lp.snorm_ne_top _)).mpr (snorm_condexpL2_le hm f) exact Lp.snorm_ne_top _ #align measure_theory.norm_condexp_L2_coe_le MeasureTheory.norm_condexpL2_coe_le theorem inner_condexpL2_left_eq_right (hm : m ≤ m0) {f g : α →₂[μ] E} : ⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, (condexpL2 E 𝕜 hm g : α →₂[μ] E)⟫₂ := haveI : Fact (m ≤ m0) := ⟨hm⟩ inner_orthogonalProjection_left_eq_right _ f g #align measure_theory.inner_condexp_L2_left_eq_right MeasureTheory.inner_condexpL2_left_eq_right theorem condexpL2_indicator_of_measurable (hm : m ≤ m0) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (c : E) : (condexpL2 E 𝕜 hm (indicatorConstLp 2 (hm s hs) hμs c) : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := by rw [condexpL2] haveI : Fact (m ≤ m0) := ⟨hm⟩ have h_mem : indicatorConstLp 2 (hm s hs) hμs c ∈ lpMeas E 𝕜 m 2 μ := mem_lpMeas_indicatorConstLp hm hs hμs let ind := (⟨indicatorConstLp 2 (hm s hs) hμs c, h_mem⟩ : lpMeas E 𝕜 m 2 μ) have h_coe_ind : (ind : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := rfl have h_orth_mem := orthogonalProjection_mem_subspace_eq_self ind rw [← h_coe_ind, h_orth_mem] #align measure_theory.condexp_L2_indicator_of_measurable MeasureTheory.condexpL2_indicator_of_measurable theorem inner_condexpL2_eq_inner_fun (hm : m ≤ m0) (f g : α →₂[μ] E) (hg : AEStronglyMeasurable' m g μ) : ⟪(condexpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, g⟫₂ := by symm rw [← sub_eq_zero, ← inner_sub_left, condexpL2] simp only [mem_lpMeas_iff_aeStronglyMeasurable'.mpr hg, orthogonalProjection_inner_eq_zero f g] #align measure_theory.inner_condexp_L2_eq_inner_fun MeasureTheory.inner_condexpL2_eq_inner_fun section Real variable {hm : m ≤ m0} theorem integral_condexpL2_eq_of_fin_meas_real (f : Lp 𝕜 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = ∫ x in s, f x ∂μ := by rw [← L2.inner_indicatorConstLp_one (𝕜 := 𝕜) (hm s hs) hμs f] have h_eq_inner : ∫ x in s, (condexpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = inner (indicatorConstLp 2 (hm s hs) hμs (1 : 𝕜)) (condexpL2 𝕜 𝕜 hm f) := by rw [L2.inner_indicatorConstLp_one (hm s hs) hμs] rw [h_eq_inner, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable hm hs hμs] #align measure_theory.integral_condexp_L2_eq_of_fin_meas_real MeasureTheory.integral_condexpL2_eq_of_fin_meas_real theorem lintegral_nnnorm_condexpL2_le (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (f : Lp ℝ 2 μ) : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ ≤ ∫⁻ x in s, ‖f x‖₊ ∂μ := by let h_meas := lpMeas.aeStronglyMeasurable' (condexpL2 ℝ ℝ hm f) let g := h_meas.choose have hg_meas : StronglyMeasurable[m] g := h_meas.choose_spec.1 have hg_eq : g =ᵐ[μ] condexpL2 ℝ ℝ hm f := h_meas.choose_spec.2.symm have hg_eq_restrict : g =ᵐ[μ.restrict s] condexpL2 ℝ ℝ hm f := ae_restrict_of_ae hg_eq have hg_nnnorm_eq : (fun x => (‖g x‖₊ : ℝ≥0∞)) =ᵐ[μ.restrict s] fun x => (‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ : ℝ≥0∞) := by refine hg_eq_restrict.mono fun x hx => ?_ dsimp only simp_rw [hx] rw [lintegral_congr_ae hg_nnnorm_eq.symm] refine lintegral_nnnorm_le_of_forall_fin_meas_integral_eq hm (Lp.stronglyMeasurable f) ?_ ?_ ?_ ?_ hs hμs · exact integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs · exact hg_meas · rw [IntegrableOn, integrable_congr hg_eq_restrict] exact integrableOn_condexpL2_of_measure_ne_top hm hμs f · intro t ht hμt rw [← integral_condexpL2_eq_of_fin_meas_real f ht hμt.ne] exact setIntegral_congr_ae (hm t ht) (hg_eq.mono fun x hx _ => hx) #align measure_theory.lintegral_nnnorm_condexp_L2_le MeasureTheory.lintegral_nnnorm_condexpL2_le theorem condexpL2_ae_eq_zero_of_ae_eq_zero (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {f : Lp ℝ 2 μ} (hf : f =ᵐ[μ.restrict s] 0) : condexpL2 ℝ ℝ hm f =ᵐ[μ.restrict s] (0 : α → ℝ) := by suffices h_nnnorm_eq_zero : ∫⁻ x in s, ‖(condexpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ = 0 by rw [lintegral_eq_zero_iff] at h_nnnorm_eq_zero · refine h_nnnorm_eq_zero.mono fun x hx => ?_ dsimp only at hx rw [Pi.zero_apply] at hx ⊢ · rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] at hx · refine Measurable.coe_nnreal_ennreal (Measurable.nnnorm ?_) rw [lpMeas_coe] exact (Lp.stronglyMeasurable _).measurable refine le_antisymm ?_ (zero_le _) refine (lintegral_nnnorm_condexpL2_le hs hμs f).trans (le_of_eq ?_) rw [lintegral_eq_zero_iff] · refine hf.mono fun x hx => ?_ dsimp only rw [hx] simp · exact (Lp.stronglyMeasurable _).ennnorm #align measure_theory.condexp_L2_ae_eq_zero_of_ae_eq_zero MeasureTheory.condexpL2_ae_eq_zero_of_ae_eq_zero theorem lintegral_nnnorm_condexpL2_indicator_le_real (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ ≤ μ (s ∩ t) := by refine (lintegral_nnnorm_condexpL2_le ht hμt _).trans (le_of_eq ?_) have h_eq : ∫⁻ x in t, ‖(indicatorConstLp 2 hs hμs (1 : ℝ)) x‖₊ ∂μ = ∫⁻ x in t, s.indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ := by refine lintegral_congr_ae (ae_restrict_of_ae ?_) refine (@indicatorConstLp_coeFn _ _ _ 2 _ _ _ hs hμs (1 : ℝ)).mono fun x hx => ?_ dsimp only rw [hx] classical simp_rw [Set.indicator_apply] split_ifs <;> simp rw [h_eq, lintegral_indicator _ hs, lintegral_const, Measure.restrict_restrict hs] simp only [one_mul, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply] #align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le_real MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le_real end Real /-- `condexpL2` commutes with taking inner products with constants. See the lemma `condexpL2_comp_continuousLinearMap` for a more general result about commuting with continuous linear maps. -/ theorem condexpL2_const_inner (hm : m ≤ m0) (f : Lp E 2 μ) (c : E) : condexpL2 𝕜 𝕜 hm (((Lp.memℒp f).const_inner c).toLp fun a => ⟪c, f a⟫) =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := by rw [lpMeas_coe] have h_mem_Lp : Memℒp (fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫) 2 μ := by refine Memℒp.const_inner _ ?_; rw [lpMeas_coe]; exact Lp.memℒp _ have h_eq : h_mem_Lp.toLp _ =ᵐ[μ] fun a => ⟪c, (condexpL2 E 𝕜 hm f : α → E) a⟫ := h_mem_Lp.coeFn_toLp refine EventuallyEq.trans ?_ h_eq refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜 hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) ?_ ?_ ?_ ?_ · intro s _ hμs rw [IntegrableOn, integrable_congr (ae_restrict_of_ae h_eq)] exact (integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _).const_inner _ · intro s hs hμs rw [← lpMeas_coe, integral_condexpL2_eq_of_fin_meas_real _ hs hμs.ne, integral_congr_ae (ae_restrict_of_ae h_eq), lpMeas_coe, ← L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 (↑(condexpL2 E 𝕜 hm f)) (hm s hs) c hμs.ne, ← inner_condexpL2_left_eq_right, condexpL2_indicator_of_measurable _ hs, L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 f (hm s hs) c hμs.ne, setIntegral_congr_ae (hm s hs) ((Memℒp.coeFn_toLp ((Lp.memℒp f).const_inner c)).mono fun x hx _ => hx)] · rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _ · refine AEStronglyMeasurable'.congr ?_ h_eq.symm exact (lpMeas.aeStronglyMeasurable' _).const_inner _ #align measure_theory.condexp_L2_const_inner MeasureTheory.condexpL2_const_inner /-- `condexpL2` verifies the equality of integrals defining the conditional expectation. -/ theorem integral_condexpL2_eq (hm : m ≤ m0) (f : Lp E' 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condexpL2 E' 𝕜 hm f : α → E') x ∂μ = ∫ x in s, f x ∂μ := by rw [← sub_eq_zero, lpMeas_coe, ← integral_sub' (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs) (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)] refine integral_eq_zero_of_forall_integral_inner_eq_zero 𝕜 _ ?_ ?_ · rw [integrable_congr (ae_restrict_of_ae (Lp.coeFn_sub (↑(condexpL2 E' 𝕜 hm f)) f).symm)] exact integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs intro c simp_rw [Pi.sub_apply, inner_sub_right] rw [integral_sub ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c) ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)] have h_ae_eq_f := Memℒp.coeFn_toLp (E := 𝕜) ((Lp.memℒp f).const_inner c) rw [← lpMeas_coe, sub_eq_zero, ← setIntegral_congr_ae (hm s hs) ((condexpL2_const_inner hm f c).mono fun x hx _ => hx), ← setIntegral_congr_ae (hm s hs) (h_ae_eq_f.mono fun x hx _ => hx)] exact integral_condexpL2_eq_of_fin_meas_real _ hs hμs #align measure_theory.integral_condexp_L2_eq MeasureTheory.integral_condexpL2_eq variable {E'' 𝕜' : Type*} [RCLike 𝕜'] [NormedAddCommGroup E''] [InnerProductSpace 𝕜' E''] [CompleteSpace E''] [NormedSpace ℝ E''] variable (𝕜 𝕜') theorem condexpL2_comp_continuousLinearMap (hm : m ≤ m0) (T : E' →L[ℝ] E'') (f : α →₂[μ] E') : (condexpL2 E'' 𝕜' hm (T.compLp f) : α →₂[μ] E'') =ᵐ[μ] T.compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') := by refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜' hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condexpL2_of_measure_ne_top hm hμs.ne _) (fun s _ hμs => integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne) ?_ ?_ ?_ · intro s hs hμs rw [T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne), ← lpMeas_coe, ← lpMeas_coe, integral_condexpL2_eq hm f hs hμs.ne, integral_condexpL2_eq hm (T.compLp f) hs hμs.ne, T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs.ne)] · rw [← lpMeas_coe]; exact lpMeas.aeStronglyMeasurable' _ · have h_coe := T.coeFn_compLp (condexpL2 E' 𝕜 hm f : α →₂[μ] E') rw [← EventuallyEq] at h_coe refine AEStronglyMeasurable'.congr ?_ h_coe.symm exact (lpMeas.aeStronglyMeasurable' (condexpL2 E' 𝕜 hm f)).continuous_comp T.continuous #align measure_theory.condexp_L2_comp_continuous_linear_map MeasureTheory.condexpL2_comp_continuousLinearMap variable {𝕜 𝕜'} section CondexpL2Indicator variable (𝕜) theorem condexpL2_indicator_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) =ᵐ[μ] fun a => (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ)) : α → ℝ) a • x := by rw [indicatorConstLp_eq_toSpanSingleton_compLp hs hμs x] have h_comp := condexpL2_comp_continuousLinearMap ℝ 𝕜 hm (toSpanSingleton ℝ x) (indicatorConstLp 2 hs hμs (1 : ℝ)) rw [← lpMeas_coe] at h_comp refine h_comp.trans ?_ exact (toSpanSingleton ℝ x).coeFn_compLp _ #align measure_theory.condexp_L2_indicator_ae_eq_smul MeasureTheory.condexpL2_indicator_ae_eq_smul theorem condexpL2_indicator_eq_toSpanSingleton_comp (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α →₂[μ] E') = (toSpanSingleton ℝ x).compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) := by ext1 rw [← lpMeas_coe] refine (condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).trans ?_ have h_comp := (toSpanSingleton ℝ x).coeFn_compLp (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α →₂[μ] ℝ) rw [← EventuallyEq] at h_comp refine EventuallyEq.trans ?_ h_comp.symm filter_upwards with y using rfl #align measure_theory.condexp_L2_indicator_eq_to_span_singleton_comp MeasureTheory.condexpL2_indicator_eq_toSpanSingleton_comp variable {𝕜} theorem set_lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ = ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := set_lintegral_congr_fun (hm t ht) ((condexpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const, lpMeas_coe] exact (Lp.stronglyMeasurable _).ennnorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _ #align measure_theory.set_lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.set_lintegral_nnnorm_condexpL2_indicator_le theorem lintegral_nnnorm_condexpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖(condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_ · rw [lpMeas_coe] exact (Lp.aestronglyMeasurable _).ennnorm refine (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.lintegral_nnnorm_condexp_L2_indicator_le MeasureTheory.lintegral_nnnorm_condexpL2_indicator_le /-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set with finite measure is integrable. -/ theorem integrable_condexpL2_indicator (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : Integrable (β := E') (condexpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x)) μ := by refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) (ENNReal.mul_lt_top hμs ENNReal.coe_ne_top) ?_ ?_ · rw [lpMeas_coe]; exact Lp.aestronglyMeasurable _ · refine fun t ht hμt => (set_lintegral_nnnorm_condexpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.integrable_condexp_L2_indicator MeasureTheory.integrable_condexpL2_indicator end CondexpL2Indicator section CondexpIndSMul variable [NormedSpace ℝ G] {hm : m ≤ m0} /-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/ noncomputable def condexpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : Lp G 2 μ := (toSpanSingleton ℝ x).compLpL 2 μ (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ))) #align measure_theory.condexp_ind_smul MeasureTheory.condexpIndSMul theorem aeStronglyMeasurable'_condexpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : AEStronglyMeasurable' m (condexpIndSMul hm hs hμs x) μ := by have h : AEStronglyMeasurable' m (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) μ := aeStronglyMeasurable'_condexpL2 _ _ rw [condexpIndSMul] suffices AEStronglyMeasurable' m (toSpanSingleton ℝ x ∘ condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) μ by refine AEStronglyMeasurable'.congr this ?_ refine EventuallyEq.trans ?_ (coeFn_compLpL _ _).symm rfl exact AEStronglyMeasurable'.continuous_comp (toSpanSingleton ℝ x).continuous h #align measure_theory.ae_strongly_measurable'_condexp_ind_smul MeasureTheory.aeStronglyMeasurable'_condexpIndSMul theorem condexpIndSMul_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condexpIndSMul hm hs hμs (x + y) = condexpIndSMul hm hs hμs x + condexpIndSMul hm hs hμs y := by simp_rw [condexpIndSMul]; rw [toSpanSingleton_add, add_compLpL, add_apply] #align measure_theory.condexp_ind_smul_add MeasureTheory.condexpIndSMul_add theorem condexpIndSMul_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condexpIndSMul hm hs hμs (c • x) = c • condexpIndSMul hm hs hμs x := by simp_rw [condexpIndSMul]; rw [toSpanSingleton_smul, smul_compLpL, smul_apply] #align measure_theory.condexp_ind_smul_smul MeasureTheory.condexpIndSMul_smul theorem condexpIndSMul_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condexpIndSMul hm hs hμs (c • x) = c • condexpIndSMul hm hs hμs x := by rw [condexpIndSMul, condexpIndSMul, toSpanSingleton_smul', (toSpanSingleton ℝ x).smul_compLpL c, smul_apply] #align measure_theory.condexp_ind_smul_smul' MeasureTheory.condexpIndSMul_smul' theorem condexpIndSMul_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndSMul hm hs hμs x =ᵐ[μ] fun a => (condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x := (toSpanSingleton ℝ x).coeFn_compLpL _ #align measure_theory.condexp_ind_smul_ae_eq_smul MeasureTheory.condexpIndSMul_ae_eq_smul theorem set_lintegral_nnnorm_condexpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : (∫⁻ a in t, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ) ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ = ∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := set_lintegral_congr_fun (hm t ht) ((condexpIndSMul_ae_eq_smul hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condexpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const, lpMeas_coe] exact (Lp.stronglyMeasurable _).ennnorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condexpL2_indicator_le_real hs hμs ht hμt) _ #align measure_theory.set_lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.set_lintegral_nnnorm_condexpIndSMul_le theorem lintegral_nnnorm_condexpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) ?_ fun t ht hμt => ?_ · exact (Lp.aestronglyMeasurable _).ennnorm refine (set_lintegral_nnnorm_condexpIndSMul_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.lintegral_nnnorm_condexp_ind_smul_le MeasureTheory.lintegral_nnnorm_condexpIndSMul_le /-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set with finite measure is integrable. -/ theorem integrable_condexpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : Integrable (condexpIndSMul hm hs hμs x) μ := by refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) (ENNReal.mul_lt_top hμs ENNReal.coe_ne_top) ?_ ?_ · exact Lp.aestronglyMeasurable _ · refine fun t ht hμt => (set_lintegral_nnnorm_condexpIndSMul_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left #align measure_theory.integrable_condexp_ind_smul MeasureTheory.integrable_condexpIndSMul theorem condexpIndSMul_empty {x : G} : condexpIndSMul hm MeasurableSet.empty ((measure_empty (μ := μ)).le.trans_lt ENNReal.coe_lt_top).ne x = 0 := by rw [condexpIndSMul, indicatorConstLp_empty] simp only [Submodule.coe_zero, ContinuousLinearMap.map_zero] #align measure_theory.condexp_ind_smul_empty MeasureTheory.condexpIndSMul_empty theorem setIntegral_condexpL2_indicator (hs : MeasurableSet[m] s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) : ∫ x in s, (condexpL2 ℝ ℝ hm (indicatorConstLp 2 ht hμt 1) : α → ℝ) x ∂μ = (μ (t ∩ s)).toReal := calc ∫ x in s, (condexpL2 ℝ ℝ hm (indicatorConstLp 2 ht hμt 1) : α → ℝ) x ∂μ = ∫ x in s, indicatorConstLp 2 ht hμt (1 : ℝ) x ∂μ := @integral_condexpL2_eq α _ ℝ _ _ _ _ _ _ _ _ _ hm (indicatorConstLp 2 ht hμt (1 : ℝ)) hs hμs _ = (μ (t ∩ s)).toReal • (1 : ℝ) := setIntegral_indicatorConstLp (hm s hs) ht hμt 1 _ = (μ (t ∩ s)).toReal := by rw [smul_eq_mul, mul_one] #align measure_theory.set_integral_condexp_L2_indicator MeasureTheory.setIntegral_condexpL2_indicator @[deprecated (since := "2024-04-17")] alias set_integral_condexpL2_indicator := setIntegral_condexpL2_indicator
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL2.lean
485
495
theorem setIntegral_condexpIndSMul (hs : MeasurableSet[m] s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (x : G') : ∫ a in s, (condexpIndSMul hm ht hμt x) a ∂μ = (μ (t ∩ s)).toReal • x := calc ∫ a in s, (condexpIndSMul hm ht hμt x) a ∂μ = ∫ a in s, (condexpL2 ℝ ℝ hm (indicatorConstLp 2 ht hμt 1) : α → ℝ) a • x ∂μ := setIntegral_congr_ae (hm s hs) ((condexpIndSMul_ae_eq_smul hm ht hμt x).mono fun x hx _ => hx) _ = (∫ a in s, (condexpL2 ℝ ℝ hm (indicatorConstLp 2 ht hμt 1) : α → ℝ) a ∂μ) • x := (integral_smul_const _ x) _ = (μ (t ∩ s)).toReal • x := by
rw [setIntegral_condexpL2_indicator hs ht hμs hμt]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Group.Instances import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Data.Finset.Preimage import Mathlib.Order.Interval.Set.Disjoint import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.Bases #align_import order.filter.at_top_bot from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # `Filter.atTop` and `Filter.atBot` filters on preorders, monoids and groups. In this file we define the filters * `Filter.atTop`: corresponds to `n → +∞`; * `Filter.atBot`: corresponds to `n → -∞`. Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”. -/ set_option autoImplicit true variable {ι ι' α β γ : Type*} open Set namespace Filter /-- `atTop` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def atTop [Preorder α] : Filter α := ⨅ a, 𝓟 (Ici a) #align filter.at_top Filter.atTop /-- `atBot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def atBot [Preorder α] : Filter α := ⨅ a, 𝓟 (Iic a) #align filter.at_bot Filter.atBot theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ := mem_iInf_of_mem a <| Subset.refl _ #align filter.mem_at_top Filter.mem_atTop theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) := mem_atTop a #align filter.Ici_mem_at_top Filter.Ici_mem_atTop theorem Ioi_mem_atTop [Preorder α] [NoMaxOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) := let ⟨z, hz⟩ := exists_gt x mem_of_superset (mem_atTop z) fun _ h => lt_of_lt_of_le hz h #align filter.Ioi_mem_at_top Filter.Ioi_mem_atTop theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ := mem_iInf_of_mem a <| Subset.refl _ #align filter.mem_at_bot Filter.mem_atBot theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) := mem_atBot a #align filter.Iic_mem_at_bot Filter.Iic_mem_atBot theorem Iio_mem_atBot [Preorder α] [NoMinOrder α] (x : α) : Iio x ∈ (atBot : Filter α) := let ⟨z, hz⟩ := exists_lt x mem_of_superset (mem_atBot z) fun _ h => lt_of_le_of_lt h hz #align filter.Iio_mem_at_bot Filter.Iio_mem_atBot theorem disjoint_atBot_principal_Ioi [Preorder α] (x : α) : Disjoint atBot (𝓟 (Ioi x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_atBot x) (mem_principal_self _) #align filter.disjoint_at_bot_principal_Ioi Filter.disjoint_atBot_principal_Ioi theorem disjoint_atTop_principal_Iio [Preorder α] (x : α) : Disjoint atTop (𝓟 (Iio x)) := @disjoint_atBot_principal_Ioi αᵒᵈ _ _ #align filter.disjoint_at_top_principal_Iio Filter.disjoint_atTop_principal_Iio theorem disjoint_atTop_principal_Iic [Preorder α] [NoMaxOrder α] (x : α) : Disjoint atTop (𝓟 (Iic x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_atTop x) (mem_principal_self _) #align filter.disjoint_at_top_principal_Iic Filter.disjoint_atTop_principal_Iic theorem disjoint_atBot_principal_Ici [Preorder α] [NoMinOrder α] (x : α) : Disjoint atBot (𝓟 (Ici x)) := @disjoint_atTop_principal_Iic αᵒᵈ _ _ _ #align filter.disjoint_at_bot_principal_Ici Filter.disjoint_atBot_principal_Ici theorem disjoint_pure_atTop [Preorder α] [NoMaxOrder α] (x : α) : Disjoint (pure x) atTop := Disjoint.symm <| (disjoint_atTop_principal_Iic x).mono_right <| le_principal_iff.2 <| mem_pure.2 right_mem_Iic #align filter.disjoint_pure_at_top Filter.disjoint_pure_atTop theorem disjoint_pure_atBot [Preorder α] [NoMinOrder α] (x : α) : Disjoint (pure x) atBot := @disjoint_pure_atTop αᵒᵈ _ _ _ #align filter.disjoint_pure_at_bot Filter.disjoint_pure_atBot theorem not_tendsto_const_atTop [Preorder α] [NoMaxOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atTop := tendsto_const_pure.not_tendsto (disjoint_pure_atTop x) #align filter.not_tendsto_const_at_top Filter.not_tendsto_const_atTop theorem not_tendsto_const_atBot [Preorder α] [NoMinOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atBot := tendsto_const_pure.not_tendsto (disjoint_pure_atBot x) #align filter.not_tendsto_const_at_bot Filter.not_tendsto_const_atBot
Mathlib/Order/Filter/AtTopBot.lean
118
125
theorem disjoint_atBot_atTop [PartialOrder α] [Nontrivial α] : Disjoint (atBot : Filter α) atTop := by
rcases exists_pair_ne α with ⟨x, y, hne⟩ by_cases hle : x ≤ y · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot x) (Ici_mem_atTop y) exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_le · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot y) (Ici_mem_atTop x) exact Iic_disjoint_Ici.2 hle
/- Copyright (c) 2023 Bulhwi Cha. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bulhwi Cha, Mario Carneiro -/ import Batteries.Data.Char import Batteries.Data.List.Lemmas import Batteries.Data.String.Basic import Batteries.Tactic.Lint.Misc import Batteries.Tactic.SeqFocus namespace String attribute [ext] ext theorem lt_trans {s₁ s₂ s₃ : String} : s₁ < s₂ → s₂ < s₃ → s₁ < s₃ := List.lt_trans' (α := Char) Nat.lt_trans (fun h1 h2 => Nat.not_lt.2 <| Nat.le_trans (Nat.not_lt.1 h2) (Nat.not_lt.1 h1)) theorem lt_antisymm {s₁ s₂ : String} (h₁ : ¬s₁ < s₂) (h₂ : ¬s₂ < s₁) : s₁ = s₂ := ext <| List.lt_antisymm' (α := Char) (fun h1 h2 => Char.le_antisymm (Nat.not_lt.1 h2) (Nat.not_lt.1 h1)) h₁ h₂ instance : Batteries.TransOrd String := .compareOfLessAndEq String.lt_irrefl String.lt_trans String.lt_antisymm instance : Batteries.LTOrd String := .compareOfLessAndEq String.lt_irrefl String.lt_trans String.lt_antisymm instance : Batteries.BEqOrd String := .compareOfLessAndEq String.lt_irrefl @[simp] theorem mk_length (s : List Char) : (String.mk s).length = s.length := rfl attribute [simp] toList -- prefer `String.data` over `String.toList` in lemmas private theorem add_csize_pos : 0 < i + csize c := Nat.add_pos_right _ (csize_pos c) private theorem ne_add_csize_add_self : i ≠ n + csize c + i := Nat.ne_of_lt (Nat.lt_add_of_pos_left add_csize_pos) private theorem ne_self_add_add_csize : i ≠ i + (n + csize c) := Nat.ne_of_lt (Nat.lt_add_of_pos_right add_csize_pos) /-- The UTF-8 byte length of a list of characters. (This is intended for specification purposes.) -/ @[inline] def utf8Len : List Char → Nat := utf8ByteSize.go @[simp] theorem utf8ByteSize.go_eq : utf8ByteSize.go = utf8Len := rfl @[simp] theorem utf8ByteSize_mk (cs) : utf8ByteSize ⟨cs⟩ = utf8Len cs := rfl @[simp] theorem utf8Len_nil : utf8Len [] = 0 := rfl @[simp] theorem utf8Len_cons (c cs) : utf8Len (c :: cs) = utf8Len cs + csize c := rfl @[simp] theorem utf8Len_append (cs₁ cs₂) : utf8Len (cs₁ ++ cs₂) = utf8Len cs₁ + utf8Len cs₂ := by induction cs₁ <;> simp [*, Nat.add_right_comm] @[simp] theorem utf8Len_reverseAux (cs₁ cs₂) : utf8Len (cs₁.reverseAux cs₂) = utf8Len cs₁ + utf8Len cs₂ := by induction cs₁ generalizing cs₂ <;> simp [*, ← Nat.add_assoc, Nat.add_right_comm] @[simp] theorem utf8Len_reverse (cs) : utf8Len cs.reverse = utf8Len cs := utf8Len_reverseAux .. @[simp] theorem utf8Len_eq_zero : utf8Len l = 0 ↔ l = [] := by cases l <;> simp [Nat.ne_of_gt add_csize_pos] section open List theorem utf8Len_le_of_sublist : ∀ {cs₁ cs₂}, cs₁ <+ cs₂ → utf8Len cs₁ ≤ utf8Len cs₂ | _, _, .slnil => Nat.le_refl _ | _, _, .cons _ h => Nat.le_trans (utf8Len_le_of_sublist h) (Nat.le_add_right ..) | _, _, .cons₂ _ h => Nat.add_le_add_right (utf8Len_le_of_sublist h) _ theorem utf8Len_le_of_infix (h : cs₁ <:+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist theorem utf8Len_le_of_suffix (h : cs₁ <:+ cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist theorem utf8Len_le_of_prefix (h : cs₁ <+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ := utf8Len_le_of_sublist h.sublist end @[simp] theorem endPos_eq (cs : List Char) : endPos ⟨cs⟩ = ⟨utf8Len cs⟩ := rfl namespace Pos attribute [ext] ext theorem lt_addChar (p : Pos) (c : Char) : p < p + c := Nat.lt_add_of_pos_right (csize_pos _) private theorem zero_ne_addChar {i : Pos} {c : Char} : 0 ≠ i + c := ne_of_lt add_csize_pos /-- A string position is valid if it is equal to the UTF-8 length of an initial substring of `s`. -/ def Valid (s : String) (p : Pos) : Prop := ∃ cs cs', cs ++ cs' = s.1 ∧ p.1 = utf8Len cs @[simp] theorem valid_zero : Valid s 0 := ⟨[], s.1, rfl, rfl⟩ @[simp] theorem valid_endPos : Valid s (endPos s) := ⟨s.1, [], by simp, rfl⟩ theorem Valid.mk (cs cs' : List Char) : Valid ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ := ⟨cs, cs', rfl, rfl⟩ theorem Valid.le_endPos : ∀ {s p}, Valid s p → p ≤ endPos s | ⟨_⟩, ⟨_⟩, ⟨cs, cs', rfl, rfl⟩ => by simp [Nat.le_add_right] end Pos theorem endPos_eq_zero : ∀ (s : String), endPos s = 0 ↔ s = "" | ⟨_⟩ => Pos.ext_iff.trans <| utf8Len_eq_zero.trans ext_iff.symm theorem isEmpty_iff (s : String) : isEmpty s ↔ s = "" := (beq_iff_eq ..).trans (endPos_eq_zero _) /-- Induction along the valid positions in a list of characters. (This definition is intended only for specification purposes.) -/ def utf8InductionOn {motive : List Char → Pos → Sort u} (s : List Char) (i p : Pos) (nil : ∀ i, motive [] i) (eq : ∀ c cs, motive (c :: cs) p) (ind : ∀ (c : Char) cs i, i ≠ p → motive cs (i + c) → motive (c :: cs) i) : motive s i := match s with | [] => nil i | c::cs => if h : i = p then h ▸ eq c cs else ind c cs i h (utf8InductionOn cs (i + c) p nil eq ind) theorem utf8GetAux_add_right_cancel (s : List Char) (i p n : Nat) : utf8GetAux s ⟨i + n⟩ ⟨p + n⟩ = utf8GetAux s ⟨i⟩ ⟨p⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨p⟩ (motive := fun s i => utf8GetAux s ⟨i.byteIdx + n⟩ ⟨p + n⟩ = utf8GetAux s i ⟨p⟩) <;> simp [utf8GetAux] intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem utf8GetAux_addChar_right_cancel (s : List Char) (i p : Pos) (c : Char) : utf8GetAux s (i + c) (p + c) = utf8GetAux s i p := utf8GetAux_add_right_cancel .. theorem utf8GetAux_of_valid (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8GetAux (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs'.headD default := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8GetAux] | c::cs, cs' => simp [utf8GetAux, -List.headD_eq_head?]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine utf8GetAux_of_valid cs cs' ?_ simpa [Nat.add_assoc, Nat.add_comm] using hp theorem get_of_valid (cs cs' : List Char) : get ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = cs'.headD default := utf8GetAux_of_valid _ _ (Nat.zero_add _) theorem get_cons_addChar (c : Char) (cs : List Char) (i : Pos) : get ⟨c :: cs⟩ (i + c) = get ⟨cs⟩ i := by simp [get, utf8GetAux, Pos.zero_ne_addChar, utf8GetAux_addChar_right_cancel] theorem utf8GetAux?_of_valid (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8GetAux? (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs'.head? := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8GetAux?] | c::cs, cs' => simp [utf8GetAux?]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine utf8GetAux?_of_valid cs cs' ?_ simpa [Nat.add_assoc, Nat.add_comm] using hp theorem get?_of_valid (cs cs' : List Char) : get? ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = cs'.head? := utf8GetAux?_of_valid _ _ (Nat.zero_add _) theorem utf8SetAux_of_valid (c' : Char) (cs cs' : List Char) {i p : Nat} (hp : i + utf8Len cs = p) : utf8SetAux c' (cs ++ cs') ⟨i⟩ ⟨p⟩ = cs ++ cs'.modifyHead fun _ => c' := by match cs, cs' with | [], [] => rfl | [], c::cs' => simp [← hp, utf8SetAux] | c::cs, cs' => simp [utf8SetAux]; rw [if_neg] case hnc => simp [← hp, Pos.ext_iff]; exact ne_self_add_add_csize refine congrArg (c::·) (utf8SetAux_of_valid c' cs cs' ?_) simpa [Nat.add_assoc, Nat.add_comm] using hp theorem set_of_valid (cs cs' : List Char) (c' : Char) : set ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ c' = ⟨cs ++ cs'.modifyHead fun _ => c'⟩ := ext (utf8SetAux_of_valid _ _ _ (Nat.zero_add _)) theorem modify_of_valid (cs cs' : List Char) : modify ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ f = ⟨cs ++ cs'.modifyHead f⟩ := by rw [modify, set_of_valid, get_of_valid]; cases cs' <;> rfl theorem next_of_valid' (cs cs' : List Char) : next ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs + csize (cs'.headD default)⟩ := by simp only [next, get_of_valid]; rfl theorem next_of_valid (cs : List Char) (c : Char) (cs' : List Char) : next ⟨cs ++ c :: cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs + csize c⟩ := next_of_valid' .. @[simp] theorem atEnd_iff (s : String) (p : Pos) : atEnd s p ↔ s.endPos ≤ p := decide_eq_true_iff _ theorem valid_next {p : Pos} (h : p.Valid s) (h₂ : p < s.endPos) : (next s p).Valid s := by match s, p, h with | ⟨_⟩, ⟨_⟩, ⟨cs, [], rfl, rfl⟩ => simp at h₂ | ⟨_⟩, ⟨_⟩, ⟨cs, c::cs', rfl, rfl⟩ => rw [utf8ByteSize.go_eq, next_of_valid] simpa using Pos.Valid.mk (cs ++ [c]) cs' theorem utf8PrevAux_of_valid {cs cs' : List Char} {c : Char} {i p : Nat} (hp : i + (utf8Len cs + csize c) = p) : utf8PrevAux (cs ++ c :: cs') ⟨i⟩ ⟨p⟩ = ⟨i + utf8Len cs⟩ := by match cs with | [] => simp [utf8PrevAux, ← hp, Pos.addChar_eq] | c'::cs => simp [utf8PrevAux, Pos.addChar_eq, ← hp]; rw [if_neg] case hnc => simp [Pos.ext_iff]; rw [Nat.add_right_comm, Nat.add_left_comm]; apply ne_add_csize_add_self refine (utf8PrevAux_of_valid (by simp [Nat.add_assoc, Nat.add_left_comm])).trans ?_ simp [Nat.add_assoc, Nat.add_comm] theorem prev_of_valid (cs : List Char) (c : Char) (cs' : List Char) : prev ⟨cs ++ c :: cs'⟩ ⟨utf8Len cs + csize c⟩ = ⟨utf8Len cs⟩ := by simp [prev]; refine (if_neg (Pos.ne_of_gt add_csize_pos)).trans ?_ rw [utf8PrevAux_of_valid] <;> simp theorem prev_of_valid' (cs cs' : List Char) : prev ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ = ⟨utf8Len cs.dropLast⟩ := by match cs, cs.eq_nil_or_concat with | _, .inl rfl => rfl | _, .inr ⟨cs, c, rfl⟩ => simp [prev_of_valid] theorem front_eq (s : String) : front s = s.1.headD default := by unfold front; exact get_of_valid [] s.1 theorem back_eq (s : String) : back s = s.1.getLastD default := by match s, s.1.eq_nil_or_concat with | ⟨_⟩, .inl rfl => rfl | ⟨_⟩, .inr ⟨cs, c, rfl⟩ => simp [back, prev_of_valid, get_of_valid] theorem atEnd_of_valid (cs : List Char) (cs' : List Char) : atEnd ⟨cs ++ cs'⟩ ⟨utf8Len cs⟩ ↔ cs' = [] := by rw [atEnd_iff] cases cs' <;> simp [Nat.lt_add_of_pos_right add_csize_pos] unseal posOfAux findAux in theorem posOfAux_eq (s c) : posOfAux s c = findAux s (· == c) := rfl unseal posOfAux findAux in theorem posOf_eq (s c) : posOf s c = find s (· == c) := rfl unseal revPosOfAux revFindAux in theorem revPosOfAux_eq (s c) : revPosOfAux s c = revFindAux s (· == c) := rfl unseal revPosOfAux revFindAux in theorem revPosOf_eq (s c) : revPosOf s c = revFind s (· == c) := rfl @[nolint unusedHavesSuffices] -- false positive from unfolding String.findAux theorem findAux_of_valid (p) : ∀ l m r, findAux ⟨l ++ m ++ r⟩ p ⟨utf8Len l + utf8Len m⟩ ⟨utf8Len l⟩ = ⟨utf8Len l + utf8Len (m.takeWhile (!p ·))⟩ | l, [], r => by unfold findAux List.takeWhile; simp | l, c::m, r => by unfold findAux List.takeWhile rw [dif_pos (by exact Nat.lt_add_of_pos_right add_csize_pos)] have h1 := get_of_valid l (c::m++r); have h2 := next_of_valid l c (m++r) simp at h1 h2; simp [h1, h2] cases p c <;> simp have foo := findAux_of_valid p (l++[c]) m r; simp at foo rw [Nat.add_right_comm, Nat.add_assoc] at foo rw [foo, Nat.add_right_comm, Nat.add_assoc] theorem find_of_valid (p s) : find s p = ⟨utf8Len (s.1.takeWhile (!p ·))⟩ := by simpa using findAux_of_valid p [] s.1 [] @[nolint unusedHavesSuffices] -- false positive from unfolding String.revFindAux theorem revFindAux_of_valid (p) : ∀ l r, revFindAux ⟨l.reverse ++ r⟩ p ⟨utf8Len l⟩ = (l.dropWhile (!p ·)).tail?.map (⟨utf8Len ·⟩) | [], r => by unfold revFindAux List.dropWhile; simp | c::l, r => by unfold revFindAux List.dropWhile rw [dif_neg (by exact Pos.ne_of_gt add_csize_pos)] have h1 := get_of_valid l.reverse (c::r); have h2 := prev_of_valid l.reverse c r simp at h1 h2; simp [h1, h2] cases p c <;> simp exact revFindAux_of_valid p l (c::r) theorem revFind_of_valid (p s) : revFind s p = (s.1.reverse.dropWhile (!p ·)).tail?.map (⟨utf8Len ·⟩) := by simpa using revFindAux_of_valid p s.1.reverse [] theorem firstDiffPos_loop_eq (l₁ l₂ r₁ r₂ stop p) (hl₁ : p = utf8Len l₁) (hl₂ : p = utf8Len l₂) (hstop : stop = min (utf8Len l₁ + utf8Len r₁) (utf8Len l₂ + utf8Len r₂)) : firstDiffPos.loop ⟨l₁ ++ r₁⟩ ⟨l₂ ++ r₂⟩ ⟨stop⟩ ⟨p⟩ = ⟨p + utf8Len (List.takeWhile₂ (· = ·) r₁ r₂).1⟩ := by unfold List.takeWhile₂; split <;> unfold firstDiffPos.loop · next a r₁ b r₂ => rw [ dif_pos <| by rw [hstop, ← hl₁, ← hl₂] refine Nat.lt_min.2 ⟨?_, ?_⟩ <;> exact Nat.lt_add_of_pos_right add_csize_pos, show get ⟨l₁ ++ a :: r₁⟩ ⟨p⟩ = a by simp [hl₁, get_of_valid], show get ⟨l₂ ++ b :: r₂⟩ ⟨p⟩ = b by simp [hl₂, get_of_valid]] simp; split <;> simp subst b rw [show next ⟨l₁ ++ a :: r₁⟩ ⟨p⟩ = ⟨utf8Len l₁ + csize a⟩ by simp [hl₁, next_of_valid]] simpa [← hl₁, ← Nat.add_assoc, Nat.add_right_comm] using firstDiffPos_loop_eq (l₁ ++ [a]) (l₂ ++ [a]) r₁ r₂ stop (p + csize a) (by simp [hl₁]) (by simp [hl₂]) (by simp [hstop, ← Nat.add_assoc, Nat.add_right_comm]) · next h => rw [dif_neg] <;> simp [hstop, ← hl₁, ← hl₂, -Nat.not_lt, Nat.lt_min] intro h₁ h₂ have : ∀ {cs}, p < p + utf8Len cs → cs ≠ [] := by rintro _ h rfl; simp at h obtain ⟨a, as, e₁⟩ := List.exists_cons_of_ne_nil (this h₁) obtain ⟨b, bs, e₂⟩ := List.exists_cons_of_ne_nil (this h₂) exact h _ _ _ _ e₁ e₂ theorem firstDiffPos_eq (a b : String) : firstDiffPos a b = ⟨utf8Len (List.takeWhile₂ (· = ·) a.1 b.1).1⟩ := by simpa [firstDiffPos] using firstDiffPos_loop_eq [] [] a.1 b.1 ((utf8Len a.1).min (utf8Len b.1)) 0 rfl rfl (by simp) theorem extract.go₂_add_right_cancel (s : List Char) (i e n : Nat) : go₂ s ⟨i + n⟩ ⟨e + n⟩ = go₂ s ⟨i⟩ ⟨e⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨e⟩ (motive := fun s i => go₂ s ⟨i.byteIdx + n⟩ ⟨e + n⟩ = go₂ s i ⟨e⟩) <;> simp [go₂] intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem extract.go₂_append_left : ∀ (s t : List Char) (i e : Nat), e = utf8Len s + i → go₂ (s ++ t) ⟨i⟩ ⟨e⟩ = s | [], t, i, _, rfl => by cases t <;> simp [go₂] | c :: cs, t, i, _, rfl => by simp [go₂, Pos.ext_iff, ne_add_csize_add_self, Pos.addChar_eq] apply go₂_append_left; rw [Nat.add_right_comm, Nat.add_assoc] theorem extract.go₁_add_right_cancel (s : List Char) (i b e n : Nat) : go₁ s ⟨i + n⟩ ⟨b + n⟩ ⟨e + n⟩ = go₁ s ⟨i⟩ ⟨b⟩ ⟨e⟩ := by apply utf8InductionOn s ⟨i⟩ ⟨b⟩ (motive := fun s i => go₁ s ⟨i.byteIdx + n⟩ ⟨b + n⟩ ⟨e + n⟩ = go₁ s i ⟨b⟩ ⟨e⟩) <;> simp [go₁] · intro c cs apply go₂_add_right_cancel · intro c cs ⟨i⟩ h ih simp [Pos.ext_iff, Pos.addChar_eq] at h ih ⊢ simp [Nat.add_right_cancel_iff, h] rw [Nat.add_right_comm] exact ih theorem extract.go₁_cons_addChar (c : Char) (cs : List Char) (b e : Pos) : go₁ (c :: cs) 0 (b + c) (e + c) = go₁ cs 0 b e := by simp [go₁, Pos.ext_iff, Nat.ne_of_lt add_csize_pos] apply go₁_add_right_cancel theorem extract.go₁_append_right : ∀ (s t : List Char) (i b : Nat) (e : Pos), b = utf8Len s + i → go₁ (s ++ t) ⟨i⟩ ⟨b⟩ e = go₂ t ⟨b⟩ e | [], t, i, _, e, rfl => by cases t <;> simp [go₁, go₂] | c :: cs, t, i, _, e, rfl => by simp [go₁, Pos.ext_iff, ne_add_csize_add_self, Pos.addChar_eq] apply go₁_append_right; rw [Nat.add_right_comm, Nat.add_assoc] theorem extract.go₁_zero_utf8Len (s : List Char) : go₁ s 0 0 ⟨utf8Len s⟩ = s := (go₁_append_right [] s 0 0 ⟨utf8Len s⟩ rfl).trans <| by simpa using go₂_append_left s [] 0 (utf8Len s) rfl theorem extract_cons_addChar (c : Char) (cs : List Char) (b e : Pos) : extract ⟨c :: cs⟩ (b + c) (e + c) = extract ⟨cs⟩ b e := by simp [extract, Nat.add_le_add_iff_right] split <;> [rfl; rw [extract.go₁_cons_addChar]] theorem extract_zero_endPos : ∀ (s : String), s.extract 0 (endPos s) = s | ⟨[]⟩ => rfl | ⟨c :: cs⟩ => by simp [extract, Nat.ne_of_gt add_csize_pos]; congr apply extract.go₁_zero_utf8Len theorem extract_of_valid (l m r : List Char) : extract ⟨l ++ m ++ r⟩ ⟨utf8Len l⟩ ⟨utf8Len l + utf8Len m⟩ = ⟨m⟩ := by simp only [extract] split · next h => rw [utf8Len_eq_zero.1 <| Nat.le_zero.1 <| Nat.add_le_add_iff_left.1 h] · congr; rw [List.append_assoc, extract.go₁_append_right _ _ _ _ _ (by rfl)] apply extract.go₂_append_left; apply Nat.add_comm theorem splitAux_of_valid (p l m r acc) : splitAux ⟨l ++ m ++ r⟩ p ⟨utf8Len l⟩ ⟨utf8Len l + utf8Len m⟩ acc = acc.reverse ++ (List.splitOnP.go p r m.reverse).map mk := by unfold splitAux simp [by simpa using atEnd_of_valid (l ++ m) r]; split · subst r; simpa [List.splitOnP.go] using extract_of_valid l m [] · obtain ⟨c, r, rfl⟩ := r.exists_cons_of_ne_nil ‹_› simp [by simpa using (⟨get_of_valid (l++m) (c::r), next_of_valid (l++m) c r, extract_of_valid l m (c::r)⟩ : _∧_∧_), List.splitOnP.go] split · simpa [Nat.add_assoc] using splitAux_of_valid p (l++m++[c]) [] r (⟨m⟩::acc) · simpa [Nat.add_assoc] using splitAux_of_valid p l (m++[c]) r acc
.lake/packages/batteries/Batteries/Data/String/Lemmas.lean
408
409
theorem split_of_valid (s p) : split s p = (List.splitOnP p s.1).map mk := by
simpa [split] using splitAux_of_valid p [] [] s.1 []
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Tactic.NthRewrite #align_import data.nat.gcd.basic from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Definitions and properties of `Nat.gcd`, `Nat.lcm`, and `Nat.coprime` Generalizations of these are provided in a later file as `GCDMonoid.gcd` and `GCDMonoid.lcm`. Note that the global `IsCoprime` is not a straightforward generalization of `Nat.coprime`, see `Nat.isCoprime_iff_coprime` for the connection between the two. -/ namespace Nat /-! ### `gcd` -/ theorem gcd_greatest {a b d : ℕ} (hda : d ∣ a) (hdb : d ∣ b) (hd : ∀ e : ℕ, e ∣ a → e ∣ b → e ∣ d) : d = a.gcd b := (dvd_antisymm (hd _ (gcd_dvd_left a b) (gcd_dvd_right a b)) (dvd_gcd hda hdb)).symm #align nat.gcd_greatest Nat.gcd_greatest /-! Lemmas where one argument consists of addition of a multiple of the other -/ @[simp] theorem gcd_add_mul_right_right (m n k : ℕ) : gcd m (n + k * m) = gcd m n := by simp [gcd_rec m (n + k * m), gcd_rec m n] #align nat.gcd_add_mul_right_right Nat.gcd_add_mul_right_right @[simp] theorem gcd_add_mul_left_right (m n k : ℕ) : gcd m (n + m * k) = gcd m n := by simp [gcd_rec m (n + m * k), gcd_rec m n] #align nat.gcd_add_mul_left_right Nat.gcd_add_mul_left_right @[simp] theorem gcd_mul_right_add_right (m n k : ℕ) : gcd m (k * m + n) = gcd m n := by simp [add_comm _ n] #align nat.gcd_mul_right_add_right Nat.gcd_mul_right_add_right @[simp] theorem gcd_mul_left_add_right (m n k : ℕ) : gcd m (m * k + n) = gcd m n := by simp [add_comm _ n] #align nat.gcd_mul_left_add_right Nat.gcd_mul_left_add_right @[simp] theorem gcd_add_mul_right_left (m n k : ℕ) : gcd (m + k * n) n = gcd m n := by rw [gcd_comm, gcd_add_mul_right_right, gcd_comm] #align nat.gcd_add_mul_right_left Nat.gcd_add_mul_right_left @[simp] theorem gcd_add_mul_left_left (m n k : ℕ) : gcd (m + n * k) n = gcd m n := by rw [gcd_comm, gcd_add_mul_left_right, gcd_comm] #align nat.gcd_add_mul_left_left Nat.gcd_add_mul_left_left @[simp] theorem gcd_mul_right_add_left (m n k : ℕ) : gcd (k * n + m) n = gcd m n := by rw [gcd_comm, gcd_mul_right_add_right, gcd_comm] #align nat.gcd_mul_right_add_left Nat.gcd_mul_right_add_left @[simp] theorem gcd_mul_left_add_left (m n k : ℕ) : gcd (n * k + m) n = gcd m n := by rw [gcd_comm, gcd_mul_left_add_right, gcd_comm] #align nat.gcd_mul_left_add_left Nat.gcd_mul_left_add_left /-! Lemmas where one argument consists of an addition of the other -/ @[simp] theorem gcd_add_self_right (m n : ℕ) : gcd m (n + m) = gcd m n := Eq.trans (by rw [one_mul]) (gcd_add_mul_right_right m n 1) #align nat.gcd_add_self_right Nat.gcd_add_self_right @[simp] theorem gcd_add_self_left (m n : ℕ) : gcd (m + n) n = gcd m n := by rw [gcd_comm, gcd_add_self_right, gcd_comm] #align nat.gcd_add_self_left Nat.gcd_add_self_left @[simp] theorem gcd_self_add_left (m n : ℕ) : gcd (m + n) m = gcd n m := by rw [add_comm, gcd_add_self_left] #align nat.gcd_self_add_left Nat.gcd_self_add_left @[simp] theorem gcd_self_add_right (m n : ℕ) : gcd m (m + n) = gcd m n := by rw [add_comm, gcd_add_self_right] #align nat.gcd_self_add_right Nat.gcd_self_add_right /-! Lemmas where one argument consists of a subtraction of the other -/ @[simp] theorem gcd_sub_self_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) m = gcd n m := by calc gcd (n - m) m = gcd (n - m + m) m := by rw [← gcd_add_self_left (n - m) m] _ = gcd n m := by rw [Nat.sub_add_cancel h] @[simp] theorem gcd_sub_self_right {m n : ℕ} (h : m ≤ n) : gcd m (n - m) = gcd m n := by rw [gcd_comm, gcd_sub_self_left h, gcd_comm] @[simp] theorem gcd_self_sub_left {m n : ℕ} (h : m ≤ n) : gcd (n - m) n = gcd m n := by have := Nat.sub_add_cancel h rw [gcd_comm m n, ← this, gcd_add_self_left (n - m) m] have : gcd (n - m) n = gcd (n - m) m := by nth_rw 2 [← Nat.add_sub_cancel' h] rw [gcd_add_self_right, gcd_comm] convert this @[simp] theorem gcd_self_sub_right {m n : ℕ} (h : m ≤ n) : gcd n (n - m) = gcd n m := by rw [gcd_comm, gcd_self_sub_left h, gcd_comm] /-! ### `lcm` -/ theorem lcm_dvd_mul (m n : ℕ) : lcm m n ∣ m * n := lcm_dvd (dvd_mul_right _ _) (dvd_mul_left _ _) #align nat.lcm_dvd_mul Nat.lcm_dvd_mul theorem lcm_dvd_iff {m n k : ℕ} : lcm m n ∣ k ↔ m ∣ k ∧ n ∣ k := ⟨fun h => ⟨(dvd_lcm_left _ _).trans h, (dvd_lcm_right _ _).trans h⟩, and_imp.2 lcm_dvd⟩ #align nat.lcm_dvd_iff Nat.lcm_dvd_iff theorem lcm_pos {m n : ℕ} : 0 < m → 0 < n → 0 < m.lcm n := by simp_rw [pos_iff_ne_zero] exact lcm_ne_zero #align nat.lcm_pos Nat.lcm_pos theorem lcm_mul_left {m n k : ℕ} : (m * n).lcm (m * k) = m * n.lcm k := by apply dvd_antisymm · exact lcm_dvd (mul_dvd_mul_left m (dvd_lcm_left n k)) (mul_dvd_mul_left m (dvd_lcm_right n k)) · have h : m ∣ lcm (m * n) (m * k) := (dvd_mul_right m n).trans (dvd_lcm_left (m * n) (m * k)) rw [← dvd_div_iff h, lcm_dvd_iff, dvd_div_iff h, dvd_div_iff h, ← lcm_dvd_iff] theorem lcm_mul_right {m n k : ℕ} : (m * n).lcm (k * n) = m.lcm k * n := by rw [mul_comm, mul_comm k n, lcm_mul_left, mul_comm] /-! ### `Coprime` See also `Nat.coprime_of_dvd` and `Nat.coprime_of_dvd'` to prove `Nat.Coprime m n`. -/ instance (m n : ℕ) : Decidable (Coprime m n) := inferInstanceAs (Decidable (gcd m n = 1)) theorem Coprime.lcm_eq_mul {m n : ℕ} (h : Coprime m n) : lcm m n = m * n := by rw [← one_mul (lcm m n), ← h.gcd_eq_one, gcd_mul_lcm] #align nat.coprime.lcm_eq_mul Nat.Coprime.lcm_eq_mul theorem Coprime.symmetric : Symmetric Coprime := fun _ _ => Coprime.symm #align nat.coprime.symmetric Nat.Coprime.symmetric theorem Coprime.dvd_mul_right {m n k : ℕ} (H : Coprime k n) : k ∣ m * n ↔ k ∣ m := ⟨H.dvd_of_dvd_mul_right, fun h => dvd_mul_of_dvd_left h n⟩ #align nat.coprime.dvd_mul_right Nat.Coprime.dvd_mul_right theorem Coprime.dvd_mul_left {m n k : ℕ} (H : Coprime k m) : k ∣ m * n ↔ k ∣ n := ⟨H.dvd_of_dvd_mul_left, fun h => dvd_mul_of_dvd_right h m⟩ #align nat.coprime.dvd_mul_left Nat.Coprime.dvd_mul_left @[simp] theorem coprime_add_self_right {m n : ℕ} : Coprime m (n + m) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_self_right] #align nat.coprime_add_self_right Nat.coprime_add_self_right @[simp] theorem coprime_self_add_right {m n : ℕ} : Coprime m (m + n) ↔ Coprime m n := by rw [add_comm, coprime_add_self_right] #align nat.coprime_self_add_right Nat.coprime_self_add_right @[simp] theorem coprime_add_self_left {m n : ℕ} : Coprime (m + n) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_self_left] #align nat.coprime_add_self_left Nat.coprime_add_self_left @[simp] theorem coprime_self_add_left {m n : ℕ} : Coprime (m + n) m ↔ Coprime n m := by rw [Coprime, Coprime, gcd_self_add_left] #align nat.coprime_self_add_left Nat.coprime_self_add_left @[simp] theorem coprime_add_mul_right_right (m n k : ℕ) : Coprime m (n + k * m) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_right_right] #align nat.coprime_add_mul_right_right Nat.coprime_add_mul_right_right @[simp] theorem coprime_add_mul_left_right (m n k : ℕ) : Coprime m (n + m * k) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_left_right] #align nat.coprime_add_mul_left_right Nat.coprime_add_mul_left_right @[simp] theorem coprime_mul_right_add_right (m n k : ℕ) : Coprime m (k * m + n) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_mul_right_add_right] #align nat.coprime_mul_right_add_right Nat.coprime_mul_right_add_right @[simp] theorem coprime_mul_left_add_right (m n k : ℕ) : Coprime m (m * k + n) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_mul_left_add_right] #align nat.coprime_mul_left_add_right Nat.coprime_mul_left_add_right @[simp] theorem coprime_add_mul_right_left (m n k : ℕ) : Coprime (m + k * n) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_right_left] #align nat.coprime_add_mul_right_left Nat.coprime_add_mul_right_left @[simp] theorem coprime_add_mul_left_left (m n k : ℕ) : Coprime (m + n * k) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_add_mul_left_left] #align nat.coprime_add_mul_left_left Nat.coprime_add_mul_left_left @[simp] theorem coprime_mul_right_add_left (m n k : ℕ) : Coprime (k * n + m) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_mul_right_add_left] #align nat.coprime_mul_right_add_left Nat.coprime_mul_right_add_left @[simp] theorem coprime_mul_left_add_left (m n k : ℕ) : Coprime (n * k + m) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_mul_left_add_left] #align nat.coprime_mul_left_add_left Nat.coprime_mul_left_add_left @[simp] theorem coprime_sub_self_left {m n : ℕ} (h : m ≤ n) : Coprime (n - m) m ↔ Coprime n m := by rw [Coprime, Coprime, gcd_sub_self_left h] @[simp] theorem coprime_sub_self_right {m n : ℕ} (h : m ≤ n) : Coprime m (n - m) ↔ Coprime m n := by rw [Coprime, Coprime, gcd_sub_self_right h] @[simp] theorem coprime_self_sub_left {m n : ℕ} (h : m ≤ n) : Coprime (n - m) n ↔ Coprime m n := by rw [Coprime, Coprime, gcd_self_sub_left h] @[simp] theorem coprime_self_sub_right {m n : ℕ} (h : m ≤ n) : Coprime n (n - m) ↔ Coprime n m := by rw [Coprime, Coprime, gcd_self_sub_right h] @[simp] theorem coprime_pow_left_iff {n : ℕ} (hn : 0 < n) (a b : ℕ) : Nat.Coprime (a ^ n) b ↔ Nat.Coprime a b := by obtain ⟨n, rfl⟩ := exists_eq_succ_of_ne_zero hn.ne' rw [Nat.pow_succ, Nat.coprime_mul_iff_left] exact ⟨And.right, fun hab => ⟨hab.pow_left _, hab⟩⟩ #align nat.coprime_pow_left_iff Nat.coprime_pow_left_iff @[simp] theorem coprime_pow_right_iff {n : ℕ} (hn : 0 < n) (a b : ℕ) : Nat.Coprime a (b ^ n) ↔ Nat.Coprime a b := by rw [Nat.coprime_comm, coprime_pow_left_iff hn, Nat.coprime_comm] #align nat.coprime_pow_right_iff Nat.coprime_pow_right_iff theorem not_coprime_zero_zero : ¬Coprime 0 0 := by simp #align nat.not_coprime_zero_zero Nat.not_coprime_zero_zero theorem coprime_one_left_iff (n : ℕ) : Coprime 1 n ↔ True := by simp [Coprime] #align nat.coprime_one_left_iff Nat.coprime_one_left_iff theorem coprime_one_right_iff (n : ℕ) : Coprime n 1 ↔ True := by simp [Coprime] #align nat.coprime_one_right_iff Nat.coprime_one_right_iff theorem gcd_mul_of_coprime_of_dvd {a b c : ℕ} (hac : Coprime a c) (b_dvd_c : b ∣ c) : gcd (a * b) c = b := by rcases exists_eq_mul_left_of_dvd b_dvd_c with ⟨d, rfl⟩ rw [gcd_mul_right] convert one_mul b exact Coprime.coprime_mul_right_right hac #align nat.gcd_mul_of_coprime_of_dvd Nat.gcd_mul_of_coprime_of_dvd theorem Coprime.eq_of_mul_eq_zero {m n : ℕ} (h : m.Coprime n) (hmn : m * n = 0) : m = 0 ∧ n = 1 ∨ m = 1 ∧ n = 0 := (Nat.eq_zero_of_mul_eq_zero hmn).imp (fun hm => ⟨hm, n.coprime_zero_left.mp <| hm ▸ h⟩) fun hn => let eq := hn ▸ h.symm ⟨m.coprime_zero_left.mp <| eq, hn⟩ #align nat.coprime.eq_of_mul_eq_zero Nat.Coprime.eq_of_mul_eq_zero /-- Represent a divisor of `m * n` as a product of a divisor of `m` and a divisor of `n`. See `exists_dvd_and_dvd_of_dvd_mul` for the more general but less constructive version for other `GCDMonoid`s. -/ def prodDvdAndDvdOfDvdProd {m n k : ℕ} (H : k ∣ m * n) : { d : { m' // m' ∣ m } × { n' // n' ∣ n } // k = d.1 * d.2 } := by cases h0 : gcd k m with | zero => obtain rfl : k = 0 := eq_zero_of_gcd_eq_zero_left h0 obtain rfl : m = 0 := eq_zero_of_gcd_eq_zero_right h0 exact ⟨⟨⟨0, dvd_refl 0⟩, ⟨n, dvd_refl n⟩⟩, (zero_mul n).symm⟩ | succ tmp => have hpos : 0 < gcd k m := h0.symm ▸ Nat.zero_lt_succ _; clear h0 tmp have hd : gcd k m * (k / gcd k m) = k := Nat.mul_div_cancel' (gcd_dvd_left k m) refine ⟨⟨⟨gcd k m, gcd_dvd_right k m⟩, ⟨k / gcd k m, ?_⟩⟩, hd.symm⟩ apply Nat.dvd_of_mul_dvd_mul_left hpos rw [hd, ← gcd_mul_right] exact dvd_gcd (dvd_mul_right _ _) H #align nat.prod_dvd_and_dvd_of_dvd_prod Nat.prodDvdAndDvdOfDvdProd theorem dvd_mul {x m n : ℕ} : x ∣ m * n ↔ ∃ y z, y ∣ m ∧ z ∣ n ∧ y * z = x := by constructor · intro h obtain ⟨⟨⟨y, hy⟩, ⟨z, hz⟩⟩, rfl⟩ := prod_dvd_and_dvd_of_dvd_prod h exact ⟨y, z, hy, hz, rfl⟩ · rintro ⟨y, z, hy, hz, rfl⟩ exact mul_dvd_mul hy hz #align nat.dvd_mul Nat.dvd_mul theorem pow_dvd_pow_iff {a b n : ℕ} (n0 : n ≠ 0) : a ^ n ∣ b ^ n ↔ a ∣ b := by refine ⟨fun h => ?_, fun h => pow_dvd_pow_of_dvd h _⟩ rcases Nat.eq_zero_or_pos (gcd a b) with g0 | g0 · simp [eq_zero_of_gcd_eq_zero_right g0] rcases exists_coprime' g0 with ⟨g, a', b', g0', co, rfl, rfl⟩ rw [mul_pow, mul_pow] at h replace h := Nat.dvd_of_mul_dvd_mul_right (pow_pos g0' _) h have := pow_dvd_pow a' <| Nat.pos_of_ne_zero n0 rw [pow_one, (co.pow n n).eq_one_of_dvd h] at this simp [eq_one_of_dvd_one this] #align nat.pow_dvd_pow_iff Nat.pow_dvd_pow_iff theorem coprime_iff_isRelPrime {m n : ℕ} : m.Coprime n ↔ IsRelPrime m n := by simp_rw [coprime_iff_gcd_eq_one, IsRelPrime, ← and_imp, ← dvd_gcd_iff, isUnit_iff_dvd_one] exact ⟨fun h _ ↦ (h ▸ ·), (dvd_one.mp <| · dvd_rfl)⟩ /-- If `k:ℕ` divides coprime `a` and `b` then `k = 1` -/ theorem eq_one_of_dvd_coprimes {a b k : ℕ} (h_ab_coprime : Coprime a b) (hka : k ∣ a) (hkb : k ∣ b) : k = 1 := dvd_one.mp (isUnit_iff_dvd_one.mp <| coprime_iff_isRelPrime.mp h_ab_coprime hka hkb) #align nat.eq_one_of_dvd_coprimes Nat.eq_one_of_dvd_coprimes theorem Coprime.mul_add_mul_ne_mul {m n a b : ℕ} (cop : Coprime m n) (ha : a ≠ 0) (hb : b ≠ 0) : a * m + b * n ≠ m * n := by intro h obtain ⟨x, rfl⟩ : n ∣ a := cop.symm.dvd_of_dvd_mul_right ((Nat.dvd_add_iff_left (Nat.dvd_mul_left n b)).mpr ((congr_arg _ h).mpr (Nat.dvd_mul_left n m))) obtain ⟨y, rfl⟩ : m ∣ b := cop.dvd_of_dvd_mul_right ((Nat.dvd_add_iff_right (Nat.dvd_mul_left m (n * x))).mpr ((congr_arg _ h).mpr (Nat.dvd_mul_right m n))) rw [mul_comm, mul_ne_zero_iff, ← one_le_iff_ne_zero] at ha hb refine mul_ne_zero hb.2 ha.2 (eq_zero_of_mul_eq_self_left (ne_of_gt (add_le_add ha.1 hb.1)) ?_) rw [← mul_assoc, ← h, add_mul, add_mul, mul_comm _ n, ← mul_assoc, mul_comm y] #align nat.coprime.mul_add_mul_ne_mul Nat.Coprime.mul_add_mul_ne_mul variable {x n m : ℕ} theorem dvd_gcd_mul_iff_dvd_mul : x ∣ gcd x n * m ↔ x ∣ n * m := by refine ⟨(·.trans <| mul_dvd_mul_right (x.gcd_dvd_right n) m), fun ⟨y, hy⟩ ↦ ?_⟩ rw [← gcd_mul_right, hy, gcd_mul_left] exact dvd_mul_right x (gcd m y) theorem dvd_mul_gcd_iff_dvd_mul : x ∣ n * gcd x m ↔ x ∣ n * m := by rw [mul_comm, dvd_gcd_mul_iff_dvd_mul, mul_comm] theorem dvd_gcd_mul_gcd_iff_dvd_mul : x ∣ gcd x n * gcd x m ↔ x ∣ n * m := by rw [dvd_gcd_mul_iff_dvd_mul, dvd_mul_gcd_iff_dvd_mul]
Mathlib/Data/Nat/GCD/Basic.lean
359
363
theorem gcd_mul_gcd_eq_iff_dvd_mul_of_coprime (hcop : Coprime n m) : gcd x n * gcd x m = x ↔ x ∣ n * m := by
refine ⟨fun h ↦ ?_, (dvd_antisymm ?_ <| dvd_gcd_mul_gcd_iff_dvd_mul.mpr ·)⟩ refine h ▸ Nat.mul_dvd_mul ?_ ?_ <;> exact x.gcd_dvd_right _ refine (hcop.gcd_both x x).mul_dvd_of_dvd_of_dvd ?_ ?_ <;> exact x.gcd_dvd_left _
/- Copyright (c) 2021 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Algebra.Ring.Invertible import Mathlib.Data.Nat.Cast.Order #align_import algebra.order.invertible from "leanprover-community/mathlib"@"ee0c179cd3c8a45aa5bffbf1b41d8dbede452865" /-! # Lemmas about `invOf` in ordered (semi)rings. -/ variable {α : Type*} [LinearOrderedSemiring α] {a : α} @[simp]
Mathlib/Algebra/Order/Invertible.lean
19
21
theorem invOf_pos [Invertible a] : 0 < ⅟ a ↔ 0 < a := haveI : 0 < a * ⅟ a := by
simp only [mul_invOf_self, zero_lt_one] ⟨fun h => pos_of_mul_pos_left this h.le, fun h => pos_of_mul_pos_right this h.le⟩
/- 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 -/ import Mathlib.Data.Matrix.Basis import Mathlib.Data.Matrix.DMatrix import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Reindex import Mathlib.Tactic.FieldSimp #align_import linear_algebra.matrix.transvection from "leanprover-community/mathlib"@"0e2aab2b0d521f060f62a14d2cf2e2c54e8491d6" /-! # Transvections Transvections are matrices of the form `1 + StdBasisMatrix i j c`, where `StdBasisMatrix i j c` is the basic matrix with a `c` at position `(i, j)`. Multiplying by such a transvection on the left (resp. on the right) amounts to adding `c` times the `j`-th row to the `i`-th row (resp `c` times the `i`-th column to the `j`-th column). Therefore, they are useful to present algorithms operating on rows and columns. Transvections are a special case of *elementary matrices* (according to most references, these also contain the matrices exchanging rows, and the matrices multiplying a row by a constant). We show that, over a field, any matrix can be written as `L * D * L'`, where `L` and `L'` are products of transvections and `D` is diagonal. In other words, one can reduce a matrix to diagonal form by operations on its rows and columns, a variant of Gauss' pivot algorithm. ## Main definitions and results * `Transvection i j c` is the matrix equal to `1 + StdBasisMatrix i j c`. * `TransvectionStruct n R` is a structure containing the data of `i, j, c` and a proof that `i ≠ j`. These are often easier to manipulate than straight matrices, especially in inductive arguments. * `exists_list_transvec_mul_diagonal_mul_list_transvec` states that any matrix `M` over a field can be written in the form `t_1 * ... * t_k * D * t'_1 * ... * t'_l`, where `D` is diagonal and the `t_i`, `t'_j` are transvections. * `diagonal_transvection_induction` shows that a property which is true for diagonal matrices and transvections, and invariant under product, is true for all matrices. * `diagonal_transvection_induction_of_det_ne_zero` is the same statement over invertible matrices. ## Implementation details The proof of the reduction results is done inductively on the size of the matrices, reducing an `(r + 1) × (r + 1)` matrix to a matrix whose last row and column are zeroes, except possibly for the last diagonal entry. This step is done as follows. If all the coefficients on the last row and column are zero, there is nothing to do. Otherwise, one can put a nonzero coefficient in the last diagonal entry by a row or column operation, and then subtract this last diagonal entry from the other entries in the last row and column to make them vanish. This step is done in the type `Fin r ⊕ Unit`, where `Fin r` is useful to choose arbitrarily some order in which we cancel the coefficients, and the sum structure is useful to use the formalism of block matrices. To proceed with the induction, we reindex our matrices to reduce to the above situation. -/ universe u₁ u₂ namespace Matrix open Matrix variable (n p : Type*) (R : Type u₂) {𝕜 : Type*} [Field 𝕜] variable [DecidableEq n] [DecidableEq p] variable [CommRing R] section Transvection variable {R n} (i j : n) /-- The transvection matrix `Transvection i j c` is equal to the identity plus `c` at position `(i, j)`. Multiplying by it on the left (as in `Transvection i j c * M`) corresponds to adding `c` times the `j`-th line of `M` to its `i`-th line. Multiplying by it on the right corresponds to adding `c` times the `i`-th column to the `j`-th column. -/ def transvection (c : R) : Matrix n n R := 1 + Matrix.stdBasisMatrix i j c #align matrix.transvection Matrix.transvection @[simp] theorem transvection_zero : transvection i j (0 : R) = 1 := by simp [transvection] #align matrix.transvection_zero Matrix.transvection_zero section /-- A transvection matrix is obtained from the identity by adding `c` times the `j`-th row to the `i`-th row. -/ theorem updateRow_eq_transvection [Finite n] (c : R) : updateRow (1 : Matrix n n R) i ((1 : Matrix n n R) i + c • (1 : Matrix n n R) j) = transvection i j c := by cases nonempty_fintype n ext a b by_cases ha : i = a · by_cases hb : j = b · simp only [updateRow_self, transvection, ha, hb, Pi.add_apply, StdBasisMatrix.apply_same, one_apply_eq, Pi.smul_apply, mul_one, Algebra.id.smul_eq_mul, add_apply] · simp only [updateRow_self, transvection, ha, hb, StdBasisMatrix.apply_of_ne, Pi.add_apply, Ne, not_false_iff, Pi.smul_apply, and_false_iff, one_apply_ne, Algebra.id.smul_eq_mul, mul_zero, add_apply] · simp only [updateRow_ne, transvection, ha, Ne.symm ha, StdBasisMatrix.apply_of_ne, add_zero, Algebra.id.smul_eq_mul, Ne, not_false_iff, DMatrix.add_apply, Pi.smul_apply, mul_zero, false_and_iff, add_apply] #align matrix.update_row_eq_transvection Matrix.updateRow_eq_transvection variable [Fintype n] theorem transvection_mul_transvection_same (h : i ≠ j) (c d : R) : transvection i j c * transvection i j d = transvection i j (c + d) := by simp [transvection, Matrix.add_mul, Matrix.mul_add, h, h.symm, add_smul, add_assoc, stdBasisMatrix_add] #align matrix.transvection_mul_transvection_same Matrix.transvection_mul_transvection_same @[simp] theorem transvection_mul_apply_same (b : n) (c : R) (M : Matrix n n R) : (transvection i j c * M) i b = M i b + c * M j b := by simp [transvection, Matrix.add_mul] #align matrix.transvection_mul_apply_same Matrix.transvection_mul_apply_same @[simp] theorem mul_transvection_apply_same (a : n) (c : R) (M : Matrix n n R) : (M * transvection i j c) a j = M a j + c * M a i := by simp [transvection, Matrix.mul_add, mul_comm] #align matrix.mul_transvection_apply_same Matrix.mul_transvection_apply_same @[simp] theorem transvection_mul_apply_of_ne (a b : n) (ha : a ≠ i) (c : R) (M : Matrix n n R) : (transvection i j c * M) a b = M a b := by simp [transvection, Matrix.add_mul, ha] #align matrix.transvection_mul_apply_of_ne Matrix.transvection_mul_apply_of_ne @[simp] theorem mul_transvection_apply_of_ne (a b : n) (hb : b ≠ j) (c : R) (M : Matrix n n R) : (M * transvection i j c) a b = M a b := by simp [transvection, Matrix.mul_add, hb] #align matrix.mul_transvection_apply_of_ne Matrix.mul_transvection_apply_of_ne @[simp] theorem det_transvection_of_ne (h : i ≠ j) (c : R) : det (transvection i j c) = 1 := by rw [← updateRow_eq_transvection i j, det_updateRow_add_smul_self _ h, det_one] #align matrix.det_transvection_of_ne Matrix.det_transvection_of_ne end variable (R n) /-- A structure containing all the information from which one can build a nontrivial transvection. This structure is easier to manipulate than transvections as one has a direct access to all the relevant fields. -/ -- porting note (#5171): removed @[nolint has_nonempty_instance] structure TransvectionStruct where (i j : n) hij : i ≠ j c : R #align matrix.transvection_struct Matrix.TransvectionStruct instance [Nontrivial n] : Nonempty (TransvectionStruct n R) := by choose x y hxy using exists_pair_ne n exact ⟨⟨x, y, hxy, 0⟩⟩ namespace TransvectionStruct variable {R n} /-- Associating to a `transvection_struct` the corresponding transvection matrix. -/ def toMatrix (t : TransvectionStruct n R) : Matrix n n R := transvection t.i t.j t.c #align matrix.transvection_struct.to_matrix Matrix.TransvectionStruct.toMatrix @[simp] theorem toMatrix_mk (i j : n) (hij : i ≠ j) (c : R) : TransvectionStruct.toMatrix ⟨i, j, hij, c⟩ = transvection i j c := rfl #align matrix.transvection_struct.to_matrix_mk Matrix.TransvectionStruct.toMatrix_mk @[simp] protected theorem det [Fintype n] (t : TransvectionStruct n R) : det t.toMatrix = 1 := det_transvection_of_ne _ _ t.hij _ #align matrix.transvection_struct.det Matrix.TransvectionStruct.det @[simp] theorem det_toMatrix_prod [Fintype n] (L : List (TransvectionStruct n 𝕜)) : det (L.map toMatrix).prod = 1 := by induction' L with t L IH · simp · simp [IH] #align matrix.transvection_struct.det_to_matrix_prod Matrix.TransvectionStruct.det_toMatrix_prod /-- The inverse of a `TransvectionStruct`, designed so that `t.inv.toMatrix` is the inverse of `t.toMatrix`. -/ @[simps] protected def inv (t : TransvectionStruct n R) : TransvectionStruct n R where i := t.i j := t.j hij := t.hij c := -t.c #align matrix.transvection_struct.inv Matrix.TransvectionStruct.inv section variable [Fintype n] theorem inv_mul (t : TransvectionStruct n R) : t.inv.toMatrix * t.toMatrix = 1 := by rcases t with ⟨_, _, t_hij⟩ simp [toMatrix, transvection_mul_transvection_same, t_hij] #align matrix.transvection_struct.inv_mul Matrix.TransvectionStruct.inv_mul theorem mul_inv (t : TransvectionStruct n R) : t.toMatrix * t.inv.toMatrix = 1 := by rcases t with ⟨_, _, t_hij⟩ simp [toMatrix, transvection_mul_transvection_same, t_hij] #align matrix.transvection_struct.mul_inv Matrix.TransvectionStruct.mul_inv theorem reverse_inv_prod_mul_prod (L : List (TransvectionStruct n R)) : (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (L.map toMatrix).prod = 1 := by induction' L with t L IH · simp · suffices (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod * (t.inv.toMatrix * t.toMatrix) * (L.map toMatrix).prod = 1 by simpa [Matrix.mul_assoc] simpa [inv_mul] using IH #align matrix.transvection_struct.reverse_inv_prod_mul_prod Matrix.TransvectionStruct.reverse_inv_prod_mul_prod theorem prod_mul_reverse_inv_prod (L : List (TransvectionStruct n R)) : (L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod = 1 := by induction' L with t L IH · simp · suffices t.toMatrix * ((L.map toMatrix).prod * (L.reverse.map (toMatrix ∘ TransvectionStruct.inv)).prod) * t.inv.toMatrix = 1 by simpa [Matrix.mul_assoc] simp_rw [IH, Matrix.mul_one, t.mul_inv] #align matrix.transvection_struct.prod_mul_reverse_inv_prod Matrix.TransvectionStruct.prod_mul_reverse_inv_prod /-- `M` is a scalar matrix if it commutes with every nontrivial transvection (elementary matrix). -/ theorem _root_.Matrix.mem_range_scalar_of_commute_transvectionStruct {M : Matrix n n R} (hM : ∀ t : TransvectionStruct n R, Commute t.toMatrix M) : M ∈ Set.range (Matrix.scalar n) := by refine mem_range_scalar_of_commute_stdBasisMatrix ?_ intro i j hij simpa [transvection, mul_add, add_mul] using (hM ⟨i, j, hij, 1⟩).eq
Mathlib/LinearAlgebra/Matrix/Transvection.lean
246
252
theorem _root_.Matrix.mem_range_scalar_iff_commute_transvectionStruct {M : Matrix n n R} : M ∈ Set.range (Matrix.scalar n) ↔ ∀ t : TransvectionStruct n R, Commute t.toMatrix M := by
refine ⟨fun h t => ?_, mem_range_scalar_of_commute_transvectionStruct⟩ rw [mem_range_scalar_iff_commute_stdBasisMatrix] at h refine (Commute.one_left M).add_left ?_ convert (h _ _ t.hij).smul_left t.c using 1 rw [smul_stdBasisMatrix, smul_eq_mul, mul_one]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Aut import Mathlib.Algebra.Group.Invertible.Basic import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.GroupTheory.GroupAction.Units #align_import group_theory.group_action.group from "leanprover-community/mathlib"@"3b52265189f3fb43aa631edffce5d060fafaf82f" /-! # Group actions applied to various types of group This file contains lemmas about `SMul` on `GroupWithZero`, and `Group`. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} section MulAction section Group variable [Group α] [MulAction α β] @[to_additive (attr := simp)] theorem inv_smul_smul (c : α) (x : β) : c⁻¹ • c • x = x := by rw [smul_smul, mul_left_inv, one_smul] #align inv_smul_smul inv_smul_smul #align neg_vadd_vadd neg_vadd_vadd @[to_additive (attr := simp)] theorem smul_inv_smul (c : α) (x : β) : c • c⁻¹ • x = x := by rw [smul_smul, mul_right_inv, one_smul] #align smul_inv_smul smul_inv_smul #align vadd_neg_vadd vadd_neg_vadd /-- Given an action of a group `α` on `β`, each `g : α` defines a permutation of `β`. -/ @[to_additive (attr := simps)] def MulAction.toPerm (a : α) : Equiv.Perm β := ⟨fun x => a • x, fun x => a⁻¹ • x, inv_smul_smul a, smul_inv_smul a⟩ #align mul_action.to_perm MulAction.toPerm #align add_action.to_perm AddAction.toPerm #align add_action.to_perm_apply AddAction.toPerm_apply #align mul_action.to_perm_apply MulAction.toPerm_apply #align add_action.to_perm_symm_apply AddAction.toPerm_symm_apply #align mul_action.to_perm_symm_apply MulAction.toPerm_symm_apply /-- Given an action of an additive group `α` on `β`, each `g : α` defines a permutation of `β`. -/ add_decl_doc AddAction.toPerm /-- `MulAction.toPerm` is injective on faithful actions. -/ @[to_additive "`AddAction.toPerm` is injective on faithful actions."] theorem MulAction.toPerm_injective [FaithfulSMul α β] : Function.Injective (MulAction.toPerm : α → Equiv.Perm β) := (show Function.Injective (Equiv.toFun ∘ MulAction.toPerm) from smul_left_injective').of_comp #align mul_action.to_perm_injective MulAction.toPerm_injective #align add_action.to_perm_injective AddAction.toPerm_injective variable (α) (β) /-- Given an action of a group `α` on a set `β`, each `g : α` defines a permutation of `β`. -/ @[simps] def MulAction.toPermHom : α →* Equiv.Perm β where toFun := MulAction.toPerm map_one' := Equiv.ext <| one_smul α map_mul' u₁ u₂ := Equiv.ext <| mul_smul (u₁ : α) u₂ #align mul_action.to_perm_hom MulAction.toPermHom #align mul_action.to_perm_hom_apply MulAction.toPermHom_apply /-- Given an action of an additive group `α` on a set `β`, each `g : α` defines a permutation of `β`. -/ @[simps!] def AddAction.toPermHom (α : Type*) [AddGroup α] [AddAction α β] : α →+ Additive (Equiv.Perm β) := MonoidHom.toAdditive'' <| MulAction.toPermHom (Multiplicative α) β #align add_action.to_perm_hom AddAction.toPermHom /-- The tautological action by `Equiv.Perm α` on `α`. This generalizes `Function.End.applyMulAction`. -/ instance Equiv.Perm.applyMulAction (α : Type*) : MulAction (Equiv.Perm α) α where smul f a := f a one_smul _ := rfl mul_smul _ _ _ := rfl #align equiv.perm.apply_mul_action Equiv.Perm.applyMulAction @[simp] protected theorem Equiv.Perm.smul_def {α : Type*} (f : Equiv.Perm α) (a : α) : f • a = f a := rfl #align equiv.perm.smul_def Equiv.Perm.smul_def /-- `Equiv.Perm.applyMulAction` is faithful. -/ instance Equiv.Perm.applyFaithfulSMul (α : Type*) : FaithfulSMul (Equiv.Perm α) α := ⟨Equiv.ext⟩ #align equiv.perm.apply_has_faithful_smul Equiv.Perm.applyFaithfulSMul variable {α} {β} @[to_additive] theorem inv_smul_eq_iff {a : α} {x y : β} : a⁻¹ • x = y ↔ x = a • y := (MulAction.toPerm a).symm_apply_eq #align inv_smul_eq_iff inv_smul_eq_iff #align neg_vadd_eq_iff neg_vadd_eq_iff @[to_additive] theorem eq_inv_smul_iff {a : α} {x y : β} : x = a⁻¹ • y ↔ a • x = y := (MulAction.toPerm a).eq_symm_apply #align eq_inv_smul_iff eq_inv_smul_iff #align eq_neg_vadd_iff eq_neg_vadd_iff
Mathlib/GroupTheory/GroupAction/Group.lean
114
116
theorem smul_inv [Group β] [SMulCommClass α β β] [IsScalarTower α β β] (c : α) (x : β) : (c • x)⁻¹ = c⁻¹ • x⁻¹ := by
rw [inv_eq_iff_mul_eq_one, smul_mul_smul, mul_right_inv, mul_right_inv, one_smul]
/- Copyright (c) 2021 Aaron Anderson, Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Kevin Buzzard, Yaël Dillies, Eric Wieser -/ import Mathlib.Data.Finset.Sigma import Mathlib.Data.Finset.Pairwise import Mathlib.Data.Finset.Powerset import Mathlib.Data.Fintype.Basic import Mathlib.Order.CompleteLatticeIntervals #align_import order.sup_indep from "leanprover-community/mathlib"@"c4c2ed622f43768eff32608d4a0f8a6cec1c047d" /-! # Supremum independence In this file, we define supremum independence of indexed sets. An indexed family `f : ι → α` is sup-independent if, for all `a`, `f a` and the supremum of the rest are disjoint. ## Main definitions * `Finset.SupIndep s f`: a family of elements `f` are supremum independent on the finite set `s`. * `CompleteLattice.SetIndependent s`: a set of elements are supremum independent. * `CompleteLattice.Independent f`: a family of elements are supremum independent. ## Main statements * In a distributive lattice, supremum independence is equivalent to pairwise disjointness: * `Finset.supIndep_iff_pairwiseDisjoint` * `CompleteLattice.setIndependent_iff_pairwiseDisjoint` * `CompleteLattice.independent_iff_pairwiseDisjoint` * Otherwise, supremum independence is stronger than pairwise disjointness: * `Finset.SupIndep.pairwiseDisjoint` * `CompleteLattice.SetIndependent.pairwiseDisjoint` * `CompleteLattice.Independent.pairwiseDisjoint` ## Implementation notes For the finite version, we avoid the "obvious" definition `∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f)` because `erase` would require decidable equality on `ι`. -/ variable {α β ι ι' : Type*} /-! ### On lattices with a bottom element, via `Finset.sup` -/ namespace Finset section Lattice variable [Lattice α] [OrderBot α] /-- Supremum independence of finite sets. We avoid the "obvious" definition using `s.erase i` because `erase` would require decidable equality on `ι`. -/ def SupIndep (s : Finset ι) (f : ι → α) : Prop := ∀ ⦃t⦄, t ⊆ s → ∀ ⦃i⦄, i ∈ s → i ∉ t → Disjoint (f i) (t.sup f) #align finset.sup_indep Finset.SupIndep variable {s t : Finset ι} {f : ι → α} {i : ι} instance [DecidableEq ι] [DecidableEq α] : Decidable (SupIndep s f) := by refine @Finset.decidableForallOfDecidableSubsets _ _ _ (?_) rintro t - refine @Finset.decidableDforallFinset _ _ _ (?_) rintro i - have : Decidable (Disjoint (f i) (sup t f)) := decidable_of_iff' (_ = ⊥) disjoint_iff infer_instance theorem SupIndep.subset (ht : t.SupIndep f) (h : s ⊆ t) : s.SupIndep f := fun _ hu _ hi => ht (hu.trans h) (h hi) #align finset.sup_indep.subset Finset.SupIndep.subset @[simp] theorem supIndep_empty (f : ι → α) : (∅ : Finset ι).SupIndep f := fun _ _ a ha => (not_mem_empty a ha).elim #align finset.sup_indep_empty Finset.supIndep_empty theorem supIndep_singleton (i : ι) (f : ι → α) : ({i} : Finset ι).SupIndep f := fun s hs j hji hj => by rw [eq_empty_of_ssubset_singleton ⟨hs, fun h => hj (h hji)⟩, sup_empty] exact disjoint_bot_right #align finset.sup_indep_singleton Finset.supIndep_singleton theorem SupIndep.pairwiseDisjoint (hs : s.SupIndep f) : (s : Set ι).PairwiseDisjoint f := fun _ ha _ hb hab => sup_singleton.subst <| hs (singleton_subset_iff.2 hb) ha <| not_mem_singleton.2 hab #align finset.sup_indep.pairwise_disjoint Finset.SupIndep.pairwiseDisjoint theorem SupIndep.le_sup_iff (hs : s.SupIndep f) (hts : t ⊆ s) (hi : i ∈ s) (hf : ∀ i, f i ≠ ⊥) : f i ≤ t.sup f ↔ i ∈ t := by refine ⟨fun h => ?_, le_sup⟩ by_contra hit exact hf i (disjoint_self.1 <| (hs hts hi hit).mono_right h) #align finset.sup_indep.le_sup_iff Finset.SupIndep.le_sup_iff /-- The RHS looks like the definition of `CompleteLattice.Independent`. -/ theorem supIndep_iff_disjoint_erase [DecidableEq ι] : s.SupIndep f ↔ ∀ i ∈ s, Disjoint (f i) ((s.erase i).sup f) := ⟨fun hs _ hi => hs (erase_subset _ _) hi (not_mem_erase _ _), fun hs _ ht i hi hit => (hs i hi).mono_right (sup_mono fun _ hj => mem_erase.2 ⟨ne_of_mem_of_not_mem hj hit, ht hj⟩)⟩ #align finset.sup_indep_iff_disjoint_erase Finset.supIndep_iff_disjoint_erase theorem SupIndep.image [DecidableEq ι] {s : Finset ι'} {g : ι' → ι} (hs : s.SupIndep (f ∘ g)) : (s.image g).SupIndep f := by intro t ht i hi hit rw [mem_image] at hi obtain ⟨i, hi, rfl⟩ := hi haveI : DecidableEq ι' := Classical.decEq _ suffices hts : t ⊆ (s.erase i).image g by refine (supIndep_iff_disjoint_erase.1 hs i hi).mono_right ((sup_mono hts).trans ?_) rw [sup_image] rintro j hjt obtain ⟨j, hj, rfl⟩ := mem_image.1 (ht hjt) exact mem_image_of_mem _ (mem_erase.2 ⟨ne_of_apply_ne g (ne_of_mem_of_not_mem hjt hit), hj⟩) #align finset.sup_indep.image Finset.SupIndep.image theorem supIndep_map {s : Finset ι'} {g : ι' ↪ ι} : (s.map g).SupIndep f ↔ s.SupIndep (f ∘ g) := by refine ⟨fun hs t ht i hi hit => ?_, fun hs => ?_⟩ · rw [← sup_map] exact hs (map_subset_map.2 ht) ((mem_map' _).2 hi) (by rwa [mem_map']) · classical rw [map_eq_image] exact hs.image #align finset.sup_indep_map Finset.supIndep_map @[simp] theorem supIndep_pair [DecidableEq ι] {i j : ι} (hij : i ≠ j) : ({i, j} : Finset ι).SupIndep f ↔ Disjoint (f i) (f j) := ⟨fun h => h.pairwiseDisjoint (by simp) (by simp) hij, fun h => by rw [supIndep_iff_disjoint_erase] intro k hk rw [Finset.mem_insert, Finset.mem_singleton] at hk obtain rfl | rfl := hk · convert h using 1 rw [Finset.erase_insert, Finset.sup_singleton] simpa using hij · convert h.symm using 1 have : ({i, k} : Finset ι).erase k = {i} := by ext rw [mem_erase, mem_insert, mem_singleton, mem_singleton, and_or_left, Ne, not_and_self_iff, or_false_iff, and_iff_right_of_imp] rintro rfl exact hij rw [this, Finset.sup_singleton]⟩ #align finset.sup_indep_pair Finset.supIndep_pair theorem supIndep_univ_bool (f : Bool → α) : (Finset.univ : Finset Bool).SupIndep f ↔ Disjoint (f false) (f true) := haveI : true ≠ false := by simp only [Ne, not_false_iff] (supIndep_pair this).trans disjoint_comm #align finset.sup_indep_univ_bool Finset.supIndep_univ_bool @[simp]
Mathlib/Order/SupIndep.lean
158
161
theorem supIndep_univ_fin_two (f : Fin 2 → α) : (Finset.univ : Finset (Fin 2)).SupIndep f ↔ Disjoint (f 0) (f 1) := haveI : (0 : Fin 2) ≠ 1 := by
simp supIndep_pair this
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Complex.Module import Mathlib.Data.Complex.Order import Mathlib.Data.Complex.Exponential import Mathlib.Analysis.RCLike.Basic import Mathlib.Topology.Algebra.InfiniteSum.Module import Mathlib.Topology.Instances.RealVectorSpace #align_import analysis.complex.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Normed space structure on `ℂ`. This file gathers basic facts on complex numbers of an analytic nature. ## Main results This file registers `ℂ` as a normed field, expresses basic properties of the norm, and gives tools on the real vector space structure of `ℂ`. Notably, in the namespace `Complex`, it defines functions: * `reCLM` * `imCLM` * `ofRealCLM` * `conjCLE` They are bundled versions of the real part, the imaginary part, the embedding of `ℝ` in `ℂ`, and the complex conjugate as continuous `ℝ`-linear maps. The last two are also bundled as linear isometries in `ofRealLI` and `conjLIE`. We also register the fact that `ℂ` is an `RCLike` field. -/ assert_not_exists Absorbs noncomputable section namespace Complex variable {z : ℂ} open ComplexConjugate Topology Filter instance : Norm ℂ := ⟨abs⟩ @[simp] theorem norm_eq_abs (z : ℂ) : ‖z‖ = abs z := rfl #align complex.norm_eq_abs Complex.norm_eq_abs lemma norm_I : ‖I‖ = 1 := abs_I theorem norm_exp_ofReal_mul_I (t : ℝ) : ‖exp (t * I)‖ = 1 := by simp only [norm_eq_abs, abs_exp_ofReal_mul_I] set_option linter.uppercaseLean3 false in #align complex.norm_exp_of_real_mul_I Complex.norm_exp_ofReal_mul_I instance instNormedAddCommGroup : NormedAddCommGroup ℂ := AddGroupNorm.toNormedAddCommGroup { abs with map_zero' := map_zero abs neg' := abs.map_neg eq_zero_of_map_eq_zero' := fun _ => abs.eq_zero.1 } instance : NormedField ℂ where dist_eq _ _ := rfl norm_mul' := map_mul abs instance : DenselyNormedField ℂ where lt_norm_lt r₁ r₂ h₀ hr := let ⟨x, h⟩ := exists_between hr ⟨x, by rwa [norm_eq_abs, abs_ofReal, abs_of_pos (h₀.trans_lt h.1)]⟩ instance {R : Type*} [NormedField R] [NormedAlgebra R ℝ] : NormedAlgebra R ℂ where norm_smul_le r x := by rw [← algebraMap_smul ℝ r x, real_smul, norm_mul, norm_eq_abs, abs_ofReal, ← Real.norm_eq_abs, norm_algebraMap'] variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℂ E] -- see Note [lower instance priority] /-- The module structure from `Module.complexToReal` is a normed space. -/ instance (priority := 900) _root_.NormedSpace.complexToReal : NormedSpace ℝ E := NormedSpace.restrictScalars ℝ ℂ E #align normed_space.complex_to_real NormedSpace.complexToReal -- see Note [lower instance priority] /-- The algebra structure from `Algebra.complexToReal` is a normed algebra. -/ instance (priority := 900) _root_.NormedAlgebra.complexToReal {A : Type*} [SeminormedRing A] [NormedAlgebra ℂ A] : NormedAlgebra ℝ A := NormedAlgebra.restrictScalars ℝ ℂ A theorem dist_eq (z w : ℂ) : dist z w = abs (z - w) := rfl #align complex.dist_eq Complex.dist_eq theorem dist_eq_re_im (z w : ℂ) : dist z w = √((z.re - w.re) ^ 2 + (z.im - w.im) ^ 2) := by rw [sq, sq] rfl #align complex.dist_eq_re_im Complex.dist_eq_re_im @[simp] theorem dist_mk (x₁ y₁ x₂ y₂ : ℝ) : dist (mk x₁ y₁) (mk x₂ y₂) = √((x₁ - x₂) ^ 2 + (y₁ - y₂) ^ 2) := dist_eq_re_im _ _ #align complex.dist_mk Complex.dist_mk theorem dist_of_re_eq {z w : ℂ} (h : z.re = w.re) : dist z w = dist z.im w.im := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, zero_add, Real.sqrt_sq_eq_abs, Real.dist_eq] #align complex.dist_of_re_eq Complex.dist_of_re_eq theorem nndist_of_re_eq {z w : ℂ} (h : z.re = w.re) : nndist z w = nndist z.im w.im := NNReal.eq <| dist_of_re_eq h #align complex.nndist_of_re_eq Complex.nndist_of_re_eq theorem edist_of_re_eq {z w : ℂ} (h : z.re = w.re) : edist z w = edist z.im w.im := by rw [edist_nndist, edist_nndist, nndist_of_re_eq h] #align complex.edist_of_re_eq Complex.edist_of_re_eq theorem dist_of_im_eq {z w : ℂ} (h : z.im = w.im) : dist z w = dist z.re w.re := by rw [dist_eq_re_im, h, sub_self, zero_pow two_ne_zero, add_zero, Real.sqrt_sq_eq_abs, Real.dist_eq] #align complex.dist_of_im_eq Complex.dist_of_im_eq theorem nndist_of_im_eq {z w : ℂ} (h : z.im = w.im) : nndist z w = nndist z.re w.re := NNReal.eq <| dist_of_im_eq h #align complex.nndist_of_im_eq Complex.nndist_of_im_eq theorem edist_of_im_eq {z w : ℂ} (h : z.im = w.im) : edist z w = edist z.re w.re := by rw [edist_nndist, edist_nndist, nndist_of_im_eq h] #align complex.edist_of_im_eq Complex.edist_of_im_eq theorem dist_conj_self (z : ℂ) : dist (conj z) z = 2 * |z.im| := by rw [dist_of_re_eq (conj_re z), conj_im, dist_comm, Real.dist_eq, sub_neg_eq_add, ← two_mul, _root_.abs_mul, abs_of_pos (zero_lt_two' ℝ)] #align complex.dist_conj_self Complex.dist_conj_self theorem nndist_conj_self (z : ℂ) : nndist (conj z) z = 2 * Real.nnabs z.im := NNReal.eq <| by rw [← dist_nndist, NNReal.coe_mul, NNReal.coe_two, Real.coe_nnabs, dist_conj_self] #align complex.nndist_conj_self Complex.nndist_conj_self theorem dist_self_conj (z : ℂ) : dist z (conj z) = 2 * |z.im| := by rw [dist_comm, dist_conj_self] #align complex.dist_self_conj Complex.dist_self_conj theorem nndist_self_conj (z : ℂ) : nndist z (conj z) = 2 * Real.nnabs z.im := by rw [nndist_comm, nndist_conj_self] #align complex.nndist_self_conj Complex.nndist_self_conj @[simp 1100] theorem comap_abs_nhds_zero : comap abs (𝓝 0) = 𝓝 0 := comap_norm_nhds_zero #align complex.comap_abs_nhds_zero Complex.comap_abs_nhds_zero theorem norm_real (r : ℝ) : ‖(r : ℂ)‖ = ‖r‖ := abs_ofReal _ #align complex.norm_real Complex.norm_real @[simp 1100] theorem norm_rat (r : ℚ) : ‖(r : ℂ)‖ = |(r : ℝ)| := by rw [← ofReal_ratCast] exact norm_real _ #align complex.norm_rat Complex.norm_rat @[simp 1100] theorem norm_nat (n : ℕ) : ‖(n : ℂ)‖ = n := abs_natCast _ #align complex.norm_nat Complex.norm_nat @[simp 1100] lemma norm_int {n : ℤ} : ‖(n : ℂ)‖ = |(n : ℝ)| := abs_intCast n #align complex.norm_int Complex.norm_int theorem norm_int_of_nonneg {n : ℤ} (hn : 0 ≤ n) : ‖(n : ℂ)‖ = n := by rw [norm_int, ← Int.cast_abs, _root_.abs_of_nonneg hn] #align complex.norm_int_of_nonneg Complex.norm_int_of_nonneg lemma normSq_eq_norm_sq (z : ℂ) : normSq z = ‖z‖ ^ 2 := by rw [normSq_eq_abs, norm_eq_abs] @[continuity] theorem continuous_abs : Continuous abs := continuous_norm #align complex.continuous_abs Complex.continuous_abs @[continuity] theorem continuous_normSq : Continuous normSq := by simpa [← normSq_eq_abs] using continuous_abs.pow 2 #align complex.continuous_norm_sq Complex.continuous_normSq @[simp, norm_cast] theorem nnnorm_real (r : ℝ) : ‖(r : ℂ)‖₊ = ‖r‖₊ := Subtype.ext <| norm_real r #align complex.nnnorm_real Complex.nnnorm_real @[simp, norm_cast] theorem nnnorm_nat (n : ℕ) : ‖(n : ℂ)‖₊ = n := Subtype.ext <| by simp #align complex.nnnorm_nat Complex.nnnorm_nat @[simp, norm_cast] theorem nnnorm_int (n : ℤ) : ‖(n : ℂ)‖₊ = ‖n‖₊ := Subtype.ext norm_int #align complex.nnnorm_int Complex.nnnorm_int theorem nnnorm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖₊ = 1 := (pow_left_inj zero_le' zero_le' hn).1 <| by rw [← nnnorm_pow, h, nnnorm_one, one_pow] #align complex.nnnorm_eq_one_of_pow_eq_one Complex.nnnorm_eq_one_of_pow_eq_one theorem norm_eq_one_of_pow_eq_one {ζ : ℂ} {n : ℕ} (h : ζ ^ n = 1) (hn : n ≠ 0) : ‖ζ‖ = 1 := congr_arg Subtype.val (nnnorm_eq_one_of_pow_eq_one h hn) #align complex.norm_eq_one_of_pow_eq_one Complex.norm_eq_one_of_pow_eq_one theorem equivRealProd_apply_le (z : ℂ) : ‖equivRealProd z‖ ≤ abs z := by simp [Prod.norm_def, abs_re_le_abs, abs_im_le_abs] #align complex.equiv_real_prod_apply_le Complex.equivRealProd_apply_le theorem equivRealProd_apply_le' (z : ℂ) : ‖equivRealProd z‖ ≤ 1 * abs z := by simpa using equivRealProd_apply_le z #align complex.equiv_real_prod_apply_le' Complex.equivRealProd_apply_le' theorem lipschitz_equivRealProd : LipschitzWith 1 equivRealProd := by simpa using AddMonoidHomClass.lipschitz_of_bound equivRealProdLm 1 equivRealProd_apply_le' #align complex.lipschitz_equiv_real_prod Complex.lipschitz_equivRealProd theorem antilipschitz_equivRealProd : AntilipschitzWith (NNReal.sqrt 2) equivRealProd := AddMonoidHomClass.antilipschitz_of_bound equivRealProdLm fun z ↦ by simpa only [Real.coe_sqrt, NNReal.coe_ofNat] using abs_le_sqrt_two_mul_max z #align complex.antilipschitz_equiv_real_prod Complex.antilipschitz_equivRealProd theorem uniformEmbedding_equivRealProd : UniformEmbedding equivRealProd := antilipschitz_equivRealProd.uniformEmbedding lipschitz_equivRealProd.uniformContinuous #align complex.uniform_embedding_equiv_real_prod Complex.uniformEmbedding_equivRealProd instance : CompleteSpace ℂ := (completeSpace_congr uniformEmbedding_equivRealProd).mpr inferInstance instance instT2Space : T2Space ℂ := TopologicalSpace.t2Space_of_metrizableSpace /-- The natural `ContinuousLinearEquiv` from `ℂ` to `ℝ × ℝ`. -/ @[simps! (config := { simpRhs := true }) apply symm_apply_re symm_apply_im] def equivRealProdCLM : ℂ ≃L[ℝ] ℝ × ℝ := equivRealProdLm.toContinuousLinearEquivOfBounds 1 (√2) equivRealProd_apply_le' fun p => abs_le_sqrt_two_mul_max (equivRealProd.symm p) #align complex.equiv_real_prod_clm Complex.equivRealProdCLM theorem equivRealProdCLM_symm_apply (p : ℝ × ℝ) : Complex.equivRealProdCLM.symm p = p.1 + p.2 * Complex.I := Complex.equivRealProd_symm_apply p instance : ProperSpace ℂ := (id lipschitz_equivRealProd : LipschitzWith 1 equivRealProdCLM.toHomeomorph).properSpace /-- The `abs` function on `ℂ` is proper. -/ theorem tendsto_abs_cocompact_atTop : Tendsto abs (cocompact ℂ) atTop := tendsto_norm_cocompact_atTop #align complex.tendsto_abs_cocompact_at_top Complex.tendsto_abs_cocompact_atTop /-- The `normSq` function on `ℂ` is proper. -/ theorem tendsto_normSq_cocompact_atTop : Tendsto normSq (cocompact ℂ) atTop := by simpa [mul_self_abs] using tendsto_abs_cocompact_atTop.atTop_mul_atTop tendsto_abs_cocompact_atTop #align complex.tendsto_norm_sq_cocompact_at_top Complex.tendsto_normSq_cocompact_atTop open ContinuousLinearMap /-- Continuous linear map version of the real part function, from `ℂ` to `ℝ`. -/ def reCLM : ℂ →L[ℝ] ℝ := reLm.mkContinuous 1 fun x => by simp [abs_re_le_abs] #align complex.re_clm Complex.reCLM @[continuity, fun_prop] theorem continuous_re : Continuous re := reCLM.continuous #align complex.continuous_re Complex.continuous_re @[simp] theorem reCLM_coe : (reCLM : ℂ →ₗ[ℝ] ℝ) = reLm := rfl #align complex.re_clm_coe Complex.reCLM_coe @[simp] theorem reCLM_apply (z : ℂ) : (reCLM : ℂ → ℝ) z = z.re := rfl #align complex.re_clm_apply Complex.reCLM_apply /-- Continuous linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/ def imCLM : ℂ →L[ℝ] ℝ := imLm.mkContinuous 1 fun x => by simp [abs_im_le_abs] #align complex.im_clm Complex.imCLM @[continuity, fun_prop] theorem continuous_im : Continuous im := imCLM.continuous #align complex.continuous_im Complex.continuous_im @[simp] theorem imCLM_coe : (imCLM : ℂ →ₗ[ℝ] ℝ) = imLm := rfl #align complex.im_clm_coe Complex.imCLM_coe @[simp] theorem imCLM_apply (z : ℂ) : (imCLM : ℂ → ℝ) z = z.im := rfl #align complex.im_clm_apply Complex.imCLM_apply theorem restrictScalars_one_smulRight' (x : E) : ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] E) = reCLM.smulRight x + I • imCLM.smulRight x := by ext ⟨a, b⟩ simp [mk_eq_add_mul_I, mul_smul, smul_comm I b x] #align complex.restrict_scalars_one_smul_right' Complex.restrictScalars_one_smulRight' theorem restrictScalars_one_smulRight (x : ℂ) : ContinuousLinearMap.restrictScalars ℝ ((1 : ℂ →L[ℂ] ℂ).smulRight x : ℂ →L[ℂ] ℂ) = x • (1 : ℂ →L[ℝ] ℂ) := by ext1 z dsimp apply mul_comm #align complex.restrict_scalars_one_smul_right Complex.restrictScalars_one_smulRight /-- The complex-conjugation function from `ℂ` to itself is an isometric linear equivalence. -/ def conjLIE : ℂ ≃ₗᵢ[ℝ] ℂ := ⟨conjAe.toLinearEquiv, abs_conj⟩ #align complex.conj_lie Complex.conjLIE @[simp] theorem conjLIE_apply (z : ℂ) : conjLIE z = conj z := rfl #align complex.conj_lie_apply Complex.conjLIE_apply @[simp] theorem conjLIE_symm : conjLIE.symm = conjLIE := rfl #align complex.conj_lie_symm Complex.conjLIE_symm theorem isometry_conj : Isometry (conj : ℂ → ℂ) := conjLIE.isometry #align complex.isometry_conj Complex.isometry_conj @[simp] theorem dist_conj_conj (z w : ℂ) : dist (conj z) (conj w) = dist z w := isometry_conj.dist_eq z w #align complex.dist_conj_conj Complex.dist_conj_conj @[simp] theorem nndist_conj_conj (z w : ℂ) : nndist (conj z) (conj w) = nndist z w := isometry_conj.nndist_eq z w #align complex.nndist_conj_conj Complex.nndist_conj_conj
Mathlib/Analysis/Complex/Basic.lean
353
354
theorem dist_conj_comm (z w : ℂ) : dist (conj z) w = dist z (conj w) := by
rw [← dist_conj_conj, conj_conj]
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.Algebra.NeZero import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.Lifts import Mathlib.Algebra.Polynomial.Splits import Mathlib.RingTheory.RootsOfUnity.Complex import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.RingTheory.RootsOfUnity.Basic import Mathlib.FieldTheory.RatFunc.AsPolynomial #align_import ring_theory.polynomial.cyclotomic.basic from "leanprover-community/mathlib"@"7fdeecc0d03cd40f7a165e6cf00a4d2286db599f" /-! # Cyclotomic polynomials. For `n : ℕ` and an integral domain `R`, we define a modified version of the `n`-th cyclotomic polynomial with coefficients in `R`, denoted `cyclotomic' n R`, as `∏ (X - μ)`, where `μ` varies over the primitive `n`th roots of unity. If there is a primitive `n`th root of unity in `R` then this the standard definition. We then define the standard cyclotomic polynomial `cyclotomic n R` with coefficients in any ring `R`. ## Main definition * `cyclotomic n R` : the `n`-th cyclotomic polynomial with coefficients in `R`. ## Main results * `Polynomial.degree_cyclotomic` : The degree of `cyclotomic n` is `totient n`. * `Polynomial.prod_cyclotomic_eq_X_pow_sub_one` : `X ^ n - 1 = ∏ (cyclotomic i)`, where `i` divides `n`. * `Polynomial.cyclotomic_eq_prod_X_pow_sub_one_pow_moebius` : The Möbius inversion formula for `cyclotomic n R` over an abstract fraction field for `R[X]`. ## Implementation details Our definition of `cyclotomic' n R` makes sense in any integral domain `R`, but the interesting results hold if there is a primitive `n`-th root of unity in `R`. In particular, our definition is not the standard one unless there is a primitive `n`th root of unity in `R`. For example, `cyclotomic' 3 ℤ = 1`, since there are no primitive cube roots of unity in `ℤ`. The main example is `R = ℂ`, we decided to work in general since the difficulties are essentially the same. To get the standard cyclotomic polynomials, we use `unique_int_coeff_of_cycl`, with `R = ℂ`, to get a polynomial with integer coefficients and then we map it to `R[X]`, for any ring `R`. -/ open scoped Polynomial noncomputable section universe u namespace Polynomial section Cyclotomic' section IsDomain variable {R : Type*} [CommRing R] [IsDomain R] /-- The modified `n`-th cyclotomic polynomial with coefficients in `R`, it is the usual cyclotomic polynomial if there is a primitive `n`-th root of unity in `R`. -/ def cyclotomic' (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : R[X] := ∏ μ ∈ primitiveRoots n R, (X - C μ) #align polynomial.cyclotomic' Polynomial.cyclotomic' /-- The zeroth modified cyclotomic polyomial is `1`. -/ @[simp] theorem cyclotomic'_zero (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 0 R = 1 := by simp only [cyclotomic', Finset.prod_empty, primitiveRoots_zero] #align polynomial.cyclotomic'_zero Polynomial.cyclotomic'_zero /-- The first modified cyclotomic polyomial is `X - 1`. -/ @[simp] theorem cyclotomic'_one (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' 1 R = X - 1 := by simp only [cyclotomic', Finset.prod_singleton, RingHom.map_one, IsPrimitiveRoot.primitiveRoots_one] #align polynomial.cyclotomic'_one Polynomial.cyclotomic'_one /-- The second modified cyclotomic polyomial is `X + 1` if the characteristic of `R` is not `2`. -/ @[simp] theorem cyclotomic'_two (R : Type*) [CommRing R] [IsDomain R] (p : ℕ) [CharP R p] (hp : p ≠ 2) : cyclotomic' 2 R = X + 1 := by rw [cyclotomic'] have prim_root_two : primitiveRoots 2 R = {(-1 : R)} := by simp only [Finset.eq_singleton_iff_unique_mem, mem_primitiveRoots two_pos] exact ⟨IsPrimitiveRoot.neg_one p hp, fun x => IsPrimitiveRoot.eq_neg_one_of_two_right⟩ simp only [prim_root_two, Finset.prod_singleton, RingHom.map_neg, RingHom.map_one, sub_neg_eq_add] #align polynomial.cyclotomic'_two Polynomial.cyclotomic'_two /-- `cyclotomic' n R` is monic. -/ theorem cyclotomic'.monic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).Monic := monic_prod_of_monic _ _ fun _ _ => monic_X_sub_C _ #align polynomial.cyclotomic'.monic Polynomial.cyclotomic'.monic /-- `cyclotomic' n R` is different from `0`. -/ theorem cyclotomic'_ne_zero (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : cyclotomic' n R ≠ 0 := (cyclotomic'.monic n R).ne_zero #align polynomial.cyclotomic'_ne_zero Polynomial.cyclotomic'_ne_zero /-- The natural degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem natDegree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).natDegree = Nat.totient n := by rw [cyclotomic'] rw [natDegree_prod (primitiveRoots n R) fun z : R => X - C z] · simp only [IsPrimitiveRoot.card_primitiveRoots h, mul_one, natDegree_X_sub_C, Nat.cast_id, Finset.sum_const, nsmul_eq_mul] intro z _ exact X_sub_C_ne_zero z #align polynomial.nat_degree_cyclotomic' Polynomial.natDegree_cyclotomic' /-- The degree of `cyclotomic' n R` is `totient n` if there is a primitive root of unity in `R`. -/ theorem degree_cyclotomic' {ζ : R} {n : ℕ} (h : IsPrimitiveRoot ζ n) : (cyclotomic' n R).degree = Nat.totient n := by simp only [degree_eq_natDegree (cyclotomic'_ne_zero n R), natDegree_cyclotomic' h] #align polynomial.degree_cyclotomic' Polynomial.degree_cyclotomic' /-- The roots of `cyclotomic' n R` are the primitive `n`-th roots of unity. -/ theorem roots_of_cyclotomic (n : ℕ) (R : Type*) [CommRing R] [IsDomain R] : (cyclotomic' n R).roots = (primitiveRoots n R).val := by rw [cyclotomic']; exact roots_prod_X_sub_C (primitiveRoots n R) #align polynomial.roots_of_cyclotomic Polynomial.roots_of_cyclotomic /-- If there is a primitive `n`th root of unity in `K`, then `X ^ n - 1 = ∏ (X - μ)`, where `μ` varies over the `n`-th roots of unity. -/ theorem X_pow_sub_one_eq_prod {ζ : R} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : X ^ n - 1 = ∏ ζ ∈ nthRootsFinset n R, (X - C ζ) := by classical rw [nthRootsFinset, ← Multiset.toFinset_eq (IsPrimitiveRoot.nthRoots_one_nodup h)] simp only [Finset.prod_mk, RingHom.map_one] rw [nthRoots] have hmonic : (X ^ n - C (1 : R)).Monic := monic_X_pow_sub_C (1 : R) (ne_of_lt hpos).symm symm apply prod_multiset_X_sub_C_of_monic_of_roots_card_eq hmonic rw [@natDegree_X_pow_sub_C R _ _ n 1, ← nthRoots] exact IsPrimitiveRoot.card_nthRoots_one h set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_eq_prod Polynomial.X_pow_sub_one_eq_prod end IsDomain section Field variable {K : Type*} [Field K] /-- `cyclotomic' n K` splits. -/ theorem cyclotomic'_splits (n : ℕ) : Splits (RingHom.id K) (cyclotomic' n K) := by apply splits_prod (RingHom.id K) intro z _ simp only [splits_X_sub_C (RingHom.id K)] #align polynomial.cyclotomic'_splits Polynomial.cyclotomic'_splits /-- If there is a primitive `n`-th root of unity in `K`, then `X ^ n - 1` splits. -/ theorem X_pow_sub_one_splits {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : Splits (RingHom.id K) (X ^ n - C (1 : K)) := by rw [splits_iff_card_roots, ← nthRoots, IsPrimitiveRoot.card_nthRoots_one h, natDegree_X_pow_sub_C] set_option linter.uppercaseLean3 false in #align polynomial.X_pow_sub_one_splits Polynomial.X_pow_sub_one_splits /-- If there is a primitive `n`-th root of unity in `K`, then `∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1`. -/ theorem prod_cyclotomic'_eq_X_pow_sub_one {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : ∏ i ∈ Nat.divisors n, cyclotomic' i K = X ^ n - 1 := by classical have hd : (n.divisors : Set ℕ).PairwiseDisjoint fun k => primitiveRoots k K := fun x _ y _ hne => IsPrimitiveRoot.disjoint hne simp only [X_pow_sub_one_eq_prod hpos h, cyclotomic', ← Finset.prod_biUnion hd, h.nthRoots_one_eq_biUnion_primitiveRoots] set_option linter.uppercaseLean3 false in #align polynomial.prod_cyclotomic'_eq_X_pow_sub_one Polynomial.prod_cyclotomic'_eq_X_pow_sub_one /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K = (X ^ k - 1) /ₘ (∏ i ∈ Nat.properDivisors k, cyclotomic' i K)`. -/ theorem cyclotomic'_eq_X_pow_sub_one_div {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (hpos : 0 < n) (h : IsPrimitiveRoot ζ n) : cyclotomic' n K = (X ^ n - 1) /ₘ ∏ i ∈ Nat.properDivisors n, cyclotomic' i K := by rw [← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] have prod_monic : (∏ i ∈ Nat.properDivisors n, cyclotomic' i K).Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K rw [(div_modByMonic_unique (cyclotomic' n K) 0 prod_monic _).1] simp only [degree_zero, zero_add] refine ⟨by rw [mul_comm], ?_⟩ rw [bot_lt_iff_ne_bot] intro h exact Monic.ne_zero prod_monic (degree_eq_bot.1 h) set_option linter.uppercaseLean3 false in #align polynomial.cyclotomic'_eq_X_pow_sub_one_div Polynomial.cyclotomic'_eq_X_pow_sub_one_div /-- If there is a primitive `n`-th root of unity in `K`, then `cyclotomic' n K` comes from a monic polynomial with integer coefficients. -/ theorem int_coeff_of_cyclotomic' {K : Type*} [CommRing K] [IsDomain K] {ζ : K} {n : ℕ} (h : IsPrimitiveRoot ζ n) : ∃ P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K ∧ P.degree = (cyclotomic' n K).degree ∧ P.Monic := by refine lifts_and_degree_eq_and_monic ?_ (cyclotomic'.monic n K) induction' n using Nat.strong_induction_on with k ihk generalizing ζ rcases k.eq_zero_or_pos with (rfl | hpos) · use 1 simp only [cyclotomic'_zero, coe_mapRingHom, Polynomial.map_one] let B : K[X] := ∏ i ∈ Nat.properDivisors k, cyclotomic' i K have Bmo : B.Monic := by apply monic_prod_of_monic intro i _ exact cyclotomic'.monic i K have Bint : B ∈ lifts (Int.castRingHom K) := by refine Subsemiring.prod_mem (lifts (Int.castRingHom K)) ?_ intro x hx have xsmall := (Nat.mem_properDivisors.1 hx).2 obtain ⟨d, hd⟩ := (Nat.mem_properDivisors.1 hx).1 rw [mul_comm] at hd exact ihk x xsmall (h.pow hpos hd) replace Bint := lifts_and_degree_eq_and_monic Bint Bmo obtain ⟨B₁, hB₁, _, hB₁mo⟩ := Bint let Q₁ : ℤ[X] := (X ^ k - 1) /ₘ B₁ have huniq : 0 + B * cyclotomic' k K = X ^ k - 1 ∧ (0 : K[X]).degree < B.degree := by constructor · rw [zero_add, mul_comm, ← prod_cyclotomic'_eq_X_pow_sub_one hpos h, ← Nat.cons_self_properDivisors hpos.ne', Finset.prod_cons] · simpa only [degree_zero, bot_lt_iff_ne_bot, Ne, degree_eq_bot] using Bmo.ne_zero replace huniq := div_modByMonic_unique (cyclotomic' k K) (0 : K[X]) Bmo huniq simp only [lifts, RingHom.mem_rangeS] use Q₁ rw [coe_mapRingHom, map_divByMonic (Int.castRingHom K) hB₁mo, hB₁, ← huniq.1] simp #align polynomial.int_coeff_of_cyclotomic' Polynomial.int_coeff_of_cyclotomic' /-- If `K` is of characteristic `0` and there is a primitive `n`-th root of unity in `K`, then `cyclotomic n K` comes from a unique polynomial with integer coefficients. -/ theorem unique_int_coeff_of_cycl {K : Type*} [CommRing K] [IsDomain K] [CharZero K] {ζ : K} {n : ℕ+} (h : IsPrimitiveRoot ζ n) : ∃! P : ℤ[X], map (Int.castRingHom K) P = cyclotomic' n K := by obtain ⟨P, hP⟩ := int_coeff_of_cyclotomic' h refine ⟨P, hP.1, fun Q hQ => ?_⟩ apply map_injective (Int.castRingHom K) Int.cast_injective rw [hP.1, hQ] #align polynomial.unique_int_coeff_of_cycl Polynomial.unique_int_coeff_of_cycl end Field end Cyclotomic' section Cyclotomic /-- The `n`-th cyclotomic polynomial with coefficients in `R`. -/ def cyclotomic (n : ℕ) (R : Type*) [Ring R] : R[X] := if h : n = 0 then 1 else map (Int.castRingHom R) (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose #align polynomial.cyclotomic Polynomial.cyclotomic theorem int_cyclotomic_rw {n : ℕ} (h : n ≠ 0) : cyclotomic n ℤ = (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n h)).choose := by simp only [cyclotomic, h, dif_neg, not_false_iff] ext i simp only [coeff_map, Int.cast_id, eq_intCast] #align polynomial.int_cyclotomic_rw Polynomial.int_cyclotomic_rw /-- `cyclotomic n R` comes from `cyclotomic n ℤ`. -/ theorem map_cyclotomic_int (n : ℕ) (R : Type*) [Ring R] : map (Int.castRingHom R) (cyclotomic n ℤ) = cyclotomic n R := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, dif_pos, Polynomial.map_one] simp [cyclotomic, hzero] #align polynomial.map_cyclotomic_int Polynomial.map_cyclotomic_int theorem int_cyclotomic_spec (n : ℕ) : map (Int.castRingHom ℂ) (cyclotomic n ℤ) = cyclotomic' n ℂ ∧ (cyclotomic n ℤ).degree = (cyclotomic' n ℂ).degree ∧ (cyclotomic n ℤ).Monic := by by_cases hzero : n = 0 · simp only [hzero, cyclotomic, degree_one, monic_one, cyclotomic'_zero, dif_pos, eq_self_iff_true, Polynomial.map_one, and_self_iff] rw [int_cyclotomic_rw hzero] exact (int_coeff_of_cyclotomic' (Complex.isPrimitiveRoot_exp n hzero)).choose_spec #align polynomial.int_cyclotomic_spec Polynomial.int_cyclotomic_spec theorem int_cyclotomic_unique {n : ℕ} {P : ℤ[X]} (h : map (Int.castRingHom ℂ) P = cyclotomic' n ℂ) : P = cyclotomic n ℤ := by apply map_injective (Int.castRingHom ℂ) Int.cast_injective rw [h, (int_cyclotomic_spec n).1] #align polynomial.int_cyclotomic_unique Polynomial.int_cyclotomic_unique /-- The definition of `cyclotomic n R` commutes with any ring homomorphism. -/ @[simp] theorem map_cyclotomic (n : ℕ) {R S : Type*} [Ring R] [Ring S] (f : R →+* S) : map f (cyclotomic n R) = cyclotomic n S := by rw [← map_cyclotomic_int n R, ← map_cyclotomic_int n S, map_map] have : Subsingleton (ℤ →+* S) := inferInstance congr! #align polynomial.map_cyclotomic Polynomial.map_cyclotomic theorem cyclotomic.eval_apply {R S : Type*} (q : R) (n : ℕ) [Ring R] [Ring S] (f : R →+* S) : eval (f q) (cyclotomic n S) = f (eval q (cyclotomic n R)) := by rw [← map_cyclotomic n f, eval_map, eval₂_at_apply] #align polynomial.cyclotomic.eval_apply Polynomial.cyclotomic.eval_apply /-- The zeroth cyclotomic polyomial is `1`. -/ @[simp]
Mathlib/RingTheory/Polynomial/Cyclotomic/Basic.lean
305
306
theorem cyclotomic_zero (R : Type*) [Ring R] : cyclotomic 0 R = 1 := by
simp only [cyclotomic, dif_pos]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg #align norm_nonneg' norm_nonneg' #align norm_nonneg norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ #align abs_norm abs_norm namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are nonnegative, via `norm_nonneg'`. -/ @[positivity Norm.norm _] def evalMulNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg' $a)) | _, _, _ => throwError "not ‖ · ‖" /-- Extension for the `positivity` tactic: additive norms are nonnegative, via `norm_nonneg`. -/ @[positivity Norm.norm _] def evalAddNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedAddGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg $a)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] #align norm_one' norm_one' #align norm_zero norm_zero @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' #align ne_one_of_norm_ne_zero ne_one_of_norm_ne_zero #align ne_zero_of_norm_ne_zero ne_zero_of_norm_ne_zero @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] #align norm_of_subsingleton' norm_of_subsingleton' #align norm_of_subsingleton norm_of_subsingleton @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity #align zero_lt_one_add_norm_sq' zero_lt_one_add_norm_sq' #align zero_lt_one_add_norm_sq zero_lt_one_add_norm_sq @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b #align norm_div_le norm_div_le #align norm_sub_le norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ #align norm_div_le_of_le norm_div_le_of_le #align norm_sub_le_of_le norm_sub_le_of_le @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le #align dist_le_norm_add_norm' dist_le_norm_add_norm' #align dist_le_norm_add_norm dist_le_norm_add_norm @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 #align abs_norm_sub_norm_le' abs_norm_sub_norm_le' #align abs_norm_sub_norm_le abs_norm_sub_norm_le @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) #align norm_sub_norm_le' norm_sub_norm_le' #align norm_sub_norm_le norm_sub_norm_le @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b #align dist_norm_norm_le' dist_norm_norm_le' #align dist_norm_norm_le dist_norm_norm_le @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] #align norm_le_norm_add_norm_div' norm_le_norm_add_norm_div' #align norm_le_norm_add_norm_sub' norm_le_norm_add_norm_sub' @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u #align norm_le_norm_add_norm_div norm_le_norm_add_norm_div #align norm_le_norm_add_norm_sub norm_le_norm_add_norm_sub alias norm_le_insert' := norm_le_norm_add_norm_sub' #align norm_le_insert' norm_le_insert' alias norm_le_insert := norm_le_norm_add_norm_sub #align norm_le_insert norm_le_insert @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ #align norm_le_mul_norm_add norm_le_mul_norm_add #align norm_le_add_norm_add norm_le_add_norm_add @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] #align ball_eq' ball_eq' #align ball_eq ball_eq @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp #align ball_one_eq ball_one_eq #align ball_zero_eq ball_zero_eq @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] #align mem_ball_iff_norm'' mem_ball_iff_norm'' #align mem_ball_iff_norm mem_ball_iff_norm @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] #align mem_ball_iff_norm''' mem_ball_iff_norm''' #align mem_ball_iff_norm' mem_ball_iff_norm' @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] #align mem_ball_one_iff mem_ball_one_iff #align mem_ball_zero_iff mem_ball_zero_iff @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] #align mem_closed_ball_iff_norm'' mem_closedBall_iff_norm'' #align mem_closed_ball_iff_norm mem_closedBall_iff_norm @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] #align mem_closed_ball_one_iff mem_closedBall_one_iff #align mem_closed_ball_zero_iff mem_closedBall_zero_iff @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] #align mem_closed_ball_iff_norm''' mem_closedBall_iff_norm''' #align mem_closed_ball_iff_norm' mem_closedBall_iff_norm' @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_le_of_mem_closed_ball' norm_le_of_mem_closedBall' #align norm_le_of_mem_closed_ball norm_le_of_mem_closedBall @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' #align norm_le_norm_add_const_of_dist_le' norm_le_norm_add_const_of_dist_le' #align norm_le_norm_add_const_of_dist_le norm_le_norm_add_const_of_dist_le @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_lt_of_mem_ball' norm_lt_of_mem_ball' #align norm_lt_of_mem_ball norm_lt_of_mem_ball @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right'] using norm_sub_norm_le' (u / w) (v / w) #align norm_div_sub_norm_div_le_norm_div norm_div_sub_norm_div_le_norm_div #align norm_sub_sub_norm_sub_le_norm_sub norm_sub_sub_norm_sub_le_norm_sub @[to_additive isBounded_iff_forall_norm_le] theorem isBounded_iff_forall_norm_le' : Bornology.IsBounded s ↔ ∃ C, ∀ x ∈ s, ‖x‖ ≤ C := by simpa only [Set.subset_def, mem_closedBall_one_iff] using isBounded_iff_subset_closedBall (1 : E) #align bounded_iff_forall_norm_le' isBounded_iff_forall_norm_le' #align bounded_iff_forall_norm_le isBounded_iff_forall_norm_le alias ⟨Bornology.IsBounded.exists_norm_le', _⟩ := isBounded_iff_forall_norm_le' #align metric.bounded.exists_norm_le' Bornology.IsBounded.exists_norm_le' alias ⟨Bornology.IsBounded.exists_norm_le, _⟩ := isBounded_iff_forall_norm_le #align metric.bounded.exists_norm_le Bornology.IsBounded.exists_norm_le attribute [to_additive existing exists_norm_le] Bornology.IsBounded.exists_norm_le' @[to_additive exists_pos_norm_le] theorem Bornology.IsBounded.exists_pos_norm_le' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ ≤ R := let ⟨R₀, hR₀⟩ := hs.exists_norm_le' ⟨max R₀ 1, by positivity, fun x hx => (hR₀ x hx).trans <| le_max_left _ _⟩ #align metric.bounded.exists_pos_norm_le' Bornology.IsBounded.exists_pos_norm_le' #align metric.bounded.exists_pos_norm_le Bornology.IsBounded.exists_pos_norm_le @[to_additive Bornology.IsBounded.exists_pos_norm_lt] theorem Bornology.IsBounded.exists_pos_norm_lt' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ < R := let ⟨R, hR₀, hR⟩ := hs.exists_pos_norm_le' ⟨R + 1, by positivity, fun x hx ↦ (hR x hx).trans_lt (lt_add_one _)⟩ @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_iff_norm' mem_sphere_iff_norm' #align mem_sphere_iff_norm mem_sphere_iff_norm @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_one_iff_norm mem_sphere_one_iff_norm #align mem_sphere_zero_iff_norm mem_sphere_zero_iff_norm @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 #align norm_eq_of_mem_sphere' norm_eq_of_mem_sphere' #align norm_eq_of_mem_sphere norm_eq_of_mem_sphere @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] #align ne_one_of_mem_sphere ne_one_of_mem_sphere #align ne_zero_of_mem_sphere ne_zero_of_mem_sphere @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ #align ne_one_of_mem_unit_sphere ne_one_of_mem_unit_sphere #align ne_zero_of_mem_unit_sphere ne_zero_of_mem_unit_sphere variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ #align norm_group_seminorm normGroupSeminorm #align norm_add_group_seminorm normAddGroupSeminorm @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl #align coe_norm_group_seminorm coe_normGroupSeminorm #align coe_norm_add_group_seminorm coe_normAddGroupSeminorm variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] #align normed_comm_group.tendsto_nhds_one NormedCommGroup.tendsto_nhds_one #align normed_add_comm_group.tendsto_nhds_zero NormedAddCommGroup.tendsto_nhds_zero @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] #align normed_comm_group.tendsto_nhds_nhds NormedCommGroup.tendsto_nhds_nhds #align normed_add_comm_group.tendsto_nhds_nhds NormedAddCommGroup.tendsto_nhds_nhds @[to_additive] theorem NormedCommGroup.cauchySeq_iff [Nonempty α] [SemilatticeSup α] {u : α → E} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → ‖u m / u n‖ < ε := by simp [Metric.cauchySeq_iff, dist_eq_norm_div] #align normed_comm_group.cauchy_seq_iff NormedCommGroup.cauchySeq_iff #align normed_add_comm_group.cauchy_seq_iff NormedAddCommGroup.cauchySeq_iff @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball #align normed_comm_group.nhds_basis_norm_lt NormedCommGroup.nhds_basis_norm_lt #align normed_add_comm_group.nhds_basis_norm_lt NormedAddCommGroup.nhds_basis_norm_lt @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp #align normed_comm_group.nhds_one_basis_norm_lt NormedCommGroup.nhds_one_basis_norm_lt #align normed_add_comm_group.nhds_zero_basis_norm_lt NormedAddCommGroup.nhds_zero_basis_norm_lt @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] #align normed_comm_group.uniformity_basis_dist NormedCommGroup.uniformity_basis_dist #align normed_add_comm_group.uniformity_basis_dist NormedAddCommGroup.uniformity_basis_dist open Finset variable [FunLike 𝓕 E F] /-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/ @[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."] theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f := LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.lipschitz_of_bound MonoidHomClass.lipschitz_of_bound #align add_monoid_hom_class.lipschitz_of_bound AddMonoidHomClass.lipschitz_of_bound @[to_additive] theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_on_with_iff_norm_div_le lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with_iff_norm_sub_le lipschitzOnWith_iff_norm_sub_le alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with.norm_div_le LipschitzOnWith.norm_div_le attribute [to_additive] LipschitzOnWith.norm_div_le @[to_additive] theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s) (ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le ha hb).trans <| by gcongr #align lipschitz_on_with.norm_div_le_of_le LipschitzOnWith.norm_div_le_of_le #align lipschitz_on_with.norm_sub_le_of_le LipschitzOnWith.norm_sub_le_of_le @[to_additive] theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_with_iff_norm_div_le lipschitzWith_iff_norm_div_le #align lipschitz_with_iff_norm_sub_le lipschitzWith_iff_norm_sub_le alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le #align lipschitz_with.norm_div_le LipschitzWith.norm_div_le attribute [to_additive] LipschitzWith.norm_div_le @[to_additive] theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le _ _).trans <| by gcongr #align lipschitz_with.norm_div_le_of_le LipschitzWith.norm_div_le_of_le #align lipschitz_with.norm_sub_le_of_le LipschitzWith.norm_sub_le_of_le /-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/ @[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"] theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f := (MonoidHomClass.lipschitz_of_bound f C h).continuous #align monoid_hom_class.continuous_of_bound MonoidHomClass.continuous_of_bound #align add_monoid_hom_class.continuous_of_bound AddMonoidHomClass.continuous_of_bound @[to_additive] theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f := (MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous #align monoid_hom_class.uniform_continuous_of_bound MonoidHomClass.uniformContinuous_of_bound #align add_monoid_hom_class.uniform_continuous_of_bound AddMonoidHomClass.uniformContinuous_of_bound @[to_additive IsCompact.exists_bound_of_continuousOn] theorem IsCompact.exists_bound_of_continuousOn' [TopologicalSpace α] {s : Set α} (hs : IsCompact s) {f : α → E} (hf : ContinuousOn f s) : ∃ C, ∀ x ∈ s, ‖f x‖ ≤ C := (isBounded_iff_forall_norm_le'.1 (hs.image_of_continuousOn hf).isBounded).imp fun _C hC _x hx => hC _ <| Set.mem_image_of_mem _ hx #align is_compact.exists_bound_of_continuous_on' IsCompact.exists_bound_of_continuousOn' #align is_compact.exists_bound_of_continuous_on IsCompact.exists_bound_of_continuousOn @[to_additive] theorem HasCompactMulSupport.exists_bound_of_continuous [TopologicalSpace α] {f : α → E} (hf : HasCompactMulSupport f) (h'f : Continuous f) : ∃ C, ∀ x, ‖f x‖ ≤ C := by simpa using (hf.isCompact_range h'f).isBounded.exists_norm_le' @[to_additive] theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) : Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div] refine ⟨fun h x => ?_, fun h x y => h _⟩ simpa using h x 1 #align monoid_hom_class.isometry_iff_norm MonoidHomClass.isometry_iff_norm #align add_monoid_hom_class.isometry_iff_norm AddMonoidHomClass.isometry_iff_norm alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm #align monoid_hom_class.isometry_of_norm MonoidHomClass.isometry_of_norm attribute [to_additive] MonoidHomClass.isometry_of_norm section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ #align seminormed_group.to_has_nnnorm SeminormedGroup.toNNNorm #align seminormed_add_group.to_has_nnnorm SeminormedAddGroup.toNNNorm @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl #align coe_nnnorm' coe_nnnorm' #align coe_nnnorm coe_nnnorm @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl #align coe_comp_nnnorm' coe_comp_nnnorm' #align coe_comp_nnnorm coe_comp_nnnorm @[to_additive norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ #align norm_to_nnreal' norm_toNNReal' #align norm_to_nnreal norm_toNNReal @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ #align nndist_eq_nnnorm_div nndist_eq_nnnorm_div #align nndist_eq_nnnorm_sub nndist_eq_nnnorm_sub alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub #align nndist_eq_nnnorm nndist_eq_nnnorm @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' #align nnnorm_one' nnnorm_one' #align nnnorm_zero nnnorm_zero @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' #align ne_one_of_nnnorm_ne_zero ne_one_of_nnnorm_ne_zero #align ne_zero_of_nnnorm_ne_zero ne_zero_of_nnnorm_ne_zero @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b #align nnnorm_mul_le' nnnorm_mul_le' #align nnnorm_add_le nnnorm_add_le @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a #align nnnorm_inv' nnnorm_inv' #align nnnorm_neg nnnorm_neg open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ #align nnnorm_div_le nnnorm_div_le #align nnnorm_sub_le nnnorm_sub_le @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b #align nndist_nnnorm_nnnorm_le' nndist_nnnorm_nnnorm_le' #align nndist_nnnorm_nnnorm_le nndist_nnnorm_nnnorm_le @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ #align nnnorm_le_nnnorm_add_nnnorm_div nnnorm_le_nnnorm_add_nnnorm_div #align nnnorm_le_nnnorm_add_nnnorm_sub nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ #align nnnorm_le_nnnorm_add_nnnorm_div' nnnorm_le_nnnorm_add_nnnorm_div' #align nnnorm_le_nnnorm_add_nnnorm_sub' nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' #align nnnorm_le_insert' nnnorm_le_insert' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub #align nnnorm_le_insert nnnorm_le_insert @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ #align nnnorm_le_mul_nnnorm_add nnnorm_le_mul_nnnorm_add #align nnnorm_le_add_nnnorm_add nnnorm_le_add_nnnorm_add @[to_additive ofReal_norm_eq_coe_nnnorm] theorem ofReal_norm_eq_coe_nnnorm' (a : E) : ENNReal.ofReal ‖a‖ = ‖a‖₊ := ENNReal.ofReal_eq_coe_nnreal _ #align of_real_norm_eq_coe_nnnorm' ofReal_norm_eq_coe_nnnorm' #align of_real_norm_eq_coe_nnnorm ofReal_norm_eq_coe_nnnorm /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl @[to_additive] theorem edist_eq_coe_nnnorm_div (a b : E) : edist a b = ‖a / b‖₊ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_coe_nnnorm'] #align edist_eq_coe_nnnorm_div edist_eq_coe_nnnorm_div #align edist_eq_coe_nnnorm_sub edist_eq_coe_nnnorm_sub @[to_additive edist_eq_coe_nnnorm] theorem edist_eq_coe_nnnorm' (x : E) : edist x 1 = (‖x‖₊ : ℝ≥0∞) := by rw [edist_eq_coe_nnnorm_div, div_one] #align edist_eq_coe_nnnorm' edist_eq_coe_nnnorm' #align edist_eq_coe_nnnorm edist_eq_coe_nnnorm open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball (1 : E) r ↔ ↑‖a‖₊ < r := by rw [EMetric.mem_ball, edist_eq_coe_nnnorm'] #align mem_emetric_ball_one_iff mem_emetric_ball_one_iff #align mem_emetric_ball_zero_iff mem_emetric_ball_zero_iff @[to_additive] theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0) (h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f := @Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h #align monoid_hom_class.lipschitz_of_bound_nnnorm MonoidHomClass.lipschitz_of_bound_nnnorm #align add_monoid_hom_class.lipschitz_of_bound_nnnorm AddMonoidHomClass.lipschitz_of_bound_nnnorm @[to_additive] theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f := AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.antilipschitz_of_bound MonoidHomClass.antilipschitz_of_bound #align add_monoid_hom_class.antilipschitz_of_bound AddMonoidHomClass.antilipschitz_of_bound @[to_additive LipschitzWith.norm_le_mul] theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1 #align lipschitz_with.norm_le_mul' LipschitzWith.norm_le_mul' #align lipschitz_with.norm_le_mul LipschitzWith.norm_le_mul @[to_additive LipschitzWith.nnorm_le_mul] theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖₊ ≤ K * ‖x‖₊ := h.norm_le_mul' hf x #align lipschitz_with.nnorm_le_mul' LipschitzWith.nnorm_le_mul' #align lipschitz_with.nnorm_le_mul LipschitzWith.nnorm_le_mul @[to_additive AntilipschitzWith.le_mul_norm] theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by simpa only [dist_one_right, hf] using h.le_mul_dist x 1 #align antilipschitz_with.le_mul_norm' AntilipschitzWith.le_mul_norm' #align antilipschitz_with.le_mul_norm AntilipschitzWith.le_mul_norm @[to_additive AntilipschitzWith.le_mul_nnnorm] theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ := h.le_mul_norm' hf x #align antilipschitz_with.le_mul_nnnorm' AntilipschitzWith.le_mul_nnnorm' #align antilipschitz_with.le_mul_nnnorm AntilipschitzWith.le_mul_nnnorm @[to_additive] theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ := h.le_mul_nnnorm' (map_one f) x #align one_hom_class.bound_of_antilipschitz OneHomClass.bound_of_antilipschitz #align zero_hom_class.bound_of_antilipschitz ZeroHomClass.bound_of_antilipschitz @[to_additive] theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖₊ = ‖x‖₊ := Subtype.ext <| hi.norm_map_of_map_one h₁ x end NNNorm @[to_additive] theorem tendsto_iff_norm_div_tendsto_zero {f : α → E} {a : Filter α} {b : E} : Tendsto f a (𝓝 b) ↔ Tendsto (fun e => ‖f e / b‖) a (𝓝 0) := by simp only [← dist_eq_norm_div, ← tendsto_iff_dist_tendsto_zero] #align tendsto_iff_norm_tendsto_one tendsto_iff_norm_div_tendsto_zero #align tendsto_iff_norm_tendsto_zero tendsto_iff_norm_sub_tendsto_zero @[to_additive] theorem tendsto_one_iff_norm_tendsto_zero {f : α → E} {a : Filter α} : Tendsto f a (𝓝 1) ↔ Tendsto (‖f ·‖) a (𝓝 0) := tendsto_iff_norm_div_tendsto_zero.trans <| by simp only [div_one] #align tendsto_one_iff_norm_tendsto_one tendsto_one_iff_norm_tendsto_zero #align tendsto_zero_iff_norm_tendsto_zero tendsto_zero_iff_norm_tendsto_zero @[to_additive] theorem comap_norm_nhds_one : comap norm (𝓝 0) = 𝓝 (1 : E) := by simpa only [dist_one_right] using nhds_comap_dist (1 : E) #align comap_norm_nhds_one comap_norm_nhds_one #align comap_norm_nhds_zero comap_norm_nhds_zero /-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `1` (neutral element of `SeminormedGroup`). In this pair of lemmas (`squeeze_one_norm'` and `squeeze_one_norm`), following a convention of similar lemmas in `Topology.MetricSpace.Basic` and `Topology.Algebra.Order`, the `'` version is phrased using "eventually" and the non-`'` version is phrased absolutely. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `0`. In this pair of lemmas (`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of similar lemmas in `Topology.MetricSpace.PseudoMetric` and `Topology.Algebra.Order`, the `'` version is phrased using \"eventually\" and the non-`'` version is phrased absolutely."] theorem squeeze_one_norm' {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ᶠ n in t₀, ‖f n‖ ≤ a n) (h' : Tendsto a t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 1) := tendsto_one_iff_norm_tendsto_zero.2 <| squeeze_zero' (eventually_of_forall fun _n => norm_nonneg' _) h h' #align squeeze_one_norm' squeeze_one_norm' #align squeeze_zero_norm' squeeze_zero_norm' /-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `1`. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `0`."] theorem squeeze_one_norm {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ n, ‖f n‖ ≤ a n) : Tendsto a t₀ (𝓝 0) → Tendsto f t₀ (𝓝 1) := squeeze_one_norm' <| eventually_of_forall h #align squeeze_one_norm squeeze_one_norm #align squeeze_zero_norm squeeze_zero_norm @[to_additive] theorem tendsto_norm_div_self (x : E) : Tendsto (fun a => ‖a / x‖) (𝓝 x) (𝓝 0) := by simpa [dist_eq_norm_div] using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (x : E)) (𝓝 x) _) #align tendsto_norm_div_self tendsto_norm_div_self #align tendsto_norm_sub_self tendsto_norm_sub_self @[to_additive tendsto_norm] theorem tendsto_norm' {x : E} : Tendsto (fun a => ‖a‖) (𝓝 x) (𝓝 ‖x‖) := by simpa using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (1 : E)) _ _) #align tendsto_norm' tendsto_norm' #align tendsto_norm tendsto_norm @[to_additive]
Mathlib/Analysis/Normed/Group/Basic.lean
1,220
1,221
theorem tendsto_norm_one : Tendsto (fun a : E => ‖a‖) (𝓝 1) (𝓝 0) := by
simpa using tendsto_norm_div_self (1 : E)
/- Copyright (c) 2019 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Topology.Constructions #align_import topology.continuous_on from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Neighborhoods and continuity relative to a subset This file defines relative versions * `nhdsWithin` of `nhds` * `ContinuousOn` of `Continuous` * `ContinuousWithinAt` of `ContinuousAt` and proves their basic properties, including the relationships between these restricted notions and the corresponding notions for the subtype equipped with the subspace topology. ## Notation * `𝓝 x`: the filter of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`. -/ open Set Filter Function Topology Filter variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variable [TopologicalSpace α] @[simp] theorem nhds_bind_nhdsWithin {a : α} {s : Set α} : ((𝓝 a).bind fun x => 𝓝[s] x) = 𝓝[s] a := bind_inf_principal.trans <| congr_arg₂ _ nhds_bind_nhds rfl #align nhds_bind_nhds_within nhds_bind_nhdsWithin @[simp] theorem eventually_nhds_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝 a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := Filter.ext_iff.1 nhds_bind_nhdsWithin { x | p x } #align eventually_nhds_nhds_within eventually_nhds_nhdsWithin theorem eventually_nhdsWithin_iff {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ x in 𝓝[s] a, p x) ↔ ∀ᶠ x in 𝓝 a, x ∈ s → p x := eventually_inf_principal #align eventually_nhds_within_iff eventually_nhdsWithin_iff theorem frequently_nhdsWithin_iff {z : α} {s : Set α} {p : α → Prop} : (∃ᶠ x in 𝓝[s] z, p x) ↔ ∃ᶠ x in 𝓝 z, p x ∧ x ∈ s := frequently_inf_principal.trans <| by simp only [and_comm] #align frequently_nhds_within_iff frequently_nhdsWithin_iff theorem mem_closure_ne_iff_frequently_within {z : α} {s : Set α} : z ∈ closure (s \ {z}) ↔ ∃ᶠ x in 𝓝[≠] z, x ∈ s := by simp [mem_closure_iff_frequently, frequently_nhdsWithin_iff] #align mem_closure_ne_iff_frequently_within mem_closure_ne_iff_frequently_within @[simp] theorem eventually_nhdsWithin_nhdsWithin {a : α} {s : Set α} {p : α → Prop} : (∀ᶠ y in 𝓝[s] a, ∀ᶠ x in 𝓝[s] y, p x) ↔ ∀ᶠ x in 𝓝[s] a, p x := by refine ⟨fun h => ?_, fun h => (eventually_nhds_nhdsWithin.2 h).filter_mono inf_le_left⟩ simp only [eventually_nhdsWithin_iff] at h ⊢ exact h.mono fun x hx hxs => (hx hxs).self_of_nhds hxs #align eventually_nhds_within_nhds_within eventually_nhdsWithin_nhdsWithin theorem nhdsWithin_eq (a : α) (s : Set α) : 𝓝[s] a = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (t ∩ s) := ((nhds_basis_opens a).inf_principal s).eq_biInf #align nhds_within_eq nhdsWithin_eq theorem nhdsWithin_univ (a : α) : 𝓝[Set.univ] a = 𝓝 a := by rw [nhdsWithin, principal_univ, inf_top_eq] #align nhds_within_univ nhdsWithin_univ theorem nhdsWithin_hasBasis {p : β → Prop} {s : β → Set α} {a : α} (h : (𝓝 a).HasBasis p s) (t : Set α) : (𝓝[t] a).HasBasis p fun i => s i ∩ t := h.inf_principal t #align nhds_within_has_basis nhdsWithin_hasBasis theorem nhdsWithin_basis_open (a : α) (t : Set α) : (𝓝[t] a).HasBasis (fun u => a ∈ u ∧ IsOpen u) fun u => u ∩ t := nhdsWithin_hasBasis (nhds_basis_opens a) t #align nhds_within_basis_open nhdsWithin_basis_open theorem mem_nhdsWithin {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u, IsOpen u ∧ a ∈ u ∧ u ∩ s ⊆ t := by simpa only [and_assoc, and_left_comm] using (nhdsWithin_basis_open a s).mem_iff #align mem_nhds_within mem_nhdsWithin theorem mem_nhdsWithin_iff_exists_mem_nhds_inter {t : Set α} {a : α} {s : Set α} : t ∈ 𝓝[s] a ↔ ∃ u ∈ 𝓝 a, u ∩ s ⊆ t := (nhdsWithin_hasBasis (𝓝 a).basis_sets s).mem_iff #align mem_nhds_within_iff_exists_mem_nhds_inter mem_nhdsWithin_iff_exists_mem_nhds_inter theorem diff_mem_nhdsWithin_compl {x : α} {s : Set α} (hs : s ∈ 𝓝 x) (t : Set α) : s \ t ∈ 𝓝[tᶜ] x := diff_mem_inf_principal_compl hs t #align diff_mem_nhds_within_compl diff_mem_nhdsWithin_compl theorem diff_mem_nhdsWithin_diff {x : α} {s t : Set α} (hs : s ∈ 𝓝[t] x) (t' : Set α) : s \ t' ∈ 𝓝[t \ t'] x := by rw [nhdsWithin, diff_eq, diff_eq, ← inf_principal, ← inf_assoc] exact inter_mem_inf hs (mem_principal_self _) #align diff_mem_nhds_within_diff diff_mem_nhdsWithin_diff theorem nhds_of_nhdsWithin_of_nhds {s t : Set α} {a : α} (h1 : s ∈ 𝓝 a) (h2 : t ∈ 𝓝[s] a) : t ∈ 𝓝 a := by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.mp h2 with ⟨_, Hw, hw⟩ exact (𝓝 a).sets_of_superset ((𝓝 a).inter_sets Hw h1) hw #align nhds_of_nhds_within_of_nhds nhds_of_nhdsWithin_of_nhds theorem mem_nhdsWithin_iff_eventually {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ ∀ᶠ y in 𝓝 x, y ∈ s → y ∈ t := eventually_inf_principal #align mem_nhds_within_iff_eventually mem_nhdsWithin_iff_eventually theorem mem_nhdsWithin_iff_eventuallyEq {s t : Set α} {x : α} : t ∈ 𝓝[s] x ↔ s =ᶠ[𝓝 x] (s ∩ t : Set α) := by simp_rw [mem_nhdsWithin_iff_eventually, eventuallyEq_set, mem_inter_iff, iff_self_and] #align mem_nhds_within_iff_eventually_eq mem_nhdsWithin_iff_eventuallyEq theorem nhdsWithin_eq_iff_eventuallyEq {s t : Set α} {x : α} : 𝓝[s] x = 𝓝[t] x ↔ s =ᶠ[𝓝 x] t := set_eventuallyEq_iff_inf_principal.symm #align nhds_within_eq_iff_eventually_eq nhdsWithin_eq_iff_eventuallyEq theorem nhdsWithin_le_iff {s t : Set α} {x : α} : 𝓝[s] x ≤ 𝓝[t] x ↔ t ∈ 𝓝[s] x := set_eventuallyLE_iff_inf_principal_le.symm.trans set_eventuallyLE_iff_mem_inf_principal #align nhds_within_le_iff nhdsWithin_le_iff -- Porting note: golfed, dropped an unneeded assumption theorem preimage_nhdsWithin_coinduced' {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝[t] a := by lift a to t using h replace hs : (fun x : t => π x) ⁻¹' s ∈ 𝓝 a := preimage_nhds_coinduced hs rwa [← map_nhds_subtype_val, mem_map] #align preimage_nhds_within_coinduced' preimage_nhdsWithin_coinduced'ₓ theorem mem_nhdsWithin_of_mem_nhds {s t : Set α} {a : α} (h : s ∈ 𝓝 a) : s ∈ 𝓝[t] a := mem_inf_of_left h #align mem_nhds_within_of_mem_nhds mem_nhdsWithin_of_mem_nhds theorem self_mem_nhdsWithin {a : α} {s : Set α} : s ∈ 𝓝[s] a := mem_inf_of_right (mem_principal_self s) #align self_mem_nhds_within self_mem_nhdsWithin theorem eventually_mem_nhdsWithin {a : α} {s : Set α} : ∀ᶠ x in 𝓝[s] a, x ∈ s := self_mem_nhdsWithin #align eventually_mem_nhds_within eventually_mem_nhdsWithin theorem inter_mem_nhdsWithin (s : Set α) {t : Set α} {a : α} (h : t ∈ 𝓝 a) : s ∩ t ∈ 𝓝[s] a := inter_mem self_mem_nhdsWithin (mem_inf_of_left h) #align inter_mem_nhds_within inter_mem_nhdsWithin theorem nhdsWithin_mono (a : α) {s t : Set α} (h : s ⊆ t) : 𝓝[s] a ≤ 𝓝[t] a := inf_le_inf_left _ (principal_mono.mpr h) #align nhds_within_mono nhdsWithin_mono theorem pure_le_nhdsWithin {a : α} {s : Set α} (ha : a ∈ s) : pure a ≤ 𝓝[s] a := le_inf (pure_le_nhds a) (le_principal_iff.2 ha) #align pure_le_nhds_within pure_le_nhdsWithin theorem mem_of_mem_nhdsWithin {a : α} {s t : Set α} (ha : a ∈ s) (ht : t ∈ 𝓝[s] a) : a ∈ t := pure_le_nhdsWithin ha ht #align mem_of_mem_nhds_within mem_of_mem_nhdsWithin theorem Filter.Eventually.self_of_nhdsWithin {p : α → Prop} {s : Set α} {x : α} (h : ∀ᶠ y in 𝓝[s] x, p y) (hx : x ∈ s) : p x := mem_of_mem_nhdsWithin hx h #align filter.eventually.self_of_nhds_within Filter.Eventually.self_of_nhdsWithin theorem tendsto_const_nhdsWithin {l : Filter β} {s : Set α} {a : α} (ha : a ∈ s) : Tendsto (fun _ : β => a) l (𝓝[s] a) := tendsto_const_pure.mono_right <| pure_le_nhdsWithin ha #align tendsto_const_nhds_within tendsto_const_nhdsWithin theorem nhdsWithin_restrict'' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s] a = 𝓝[s ∩ t] a := le_antisymm (le_inf inf_le_left (le_principal_iff.mpr (inter_mem self_mem_nhdsWithin h))) (inf_le_inf_left _ (principal_mono.mpr Set.inter_subset_left)) #align nhds_within_restrict'' nhdsWithin_restrict'' theorem nhdsWithin_restrict' {a : α} (s : Set α) {t : Set α} (h : t ∈ 𝓝 a) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict'' s <| mem_inf_of_left h #align nhds_within_restrict' nhdsWithin_restrict' theorem nhdsWithin_restrict {a : α} (s : Set α) {t : Set α} (h₀ : a ∈ t) (h₁ : IsOpen t) : 𝓝[s] a = 𝓝[s ∩ t] a := nhdsWithin_restrict' s (IsOpen.mem_nhds h₁ h₀) #align nhds_within_restrict nhdsWithin_restrict theorem nhdsWithin_le_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[t] a ≤ 𝓝[s] a := nhdsWithin_le_iff.mpr h #align nhds_within_le_of_mem nhdsWithin_le_of_mem theorem nhdsWithin_le_nhds {a : α} {s : Set α} : 𝓝[s] a ≤ 𝓝 a := by rw [← nhdsWithin_univ] apply nhdsWithin_le_of_mem exact univ_mem #align nhds_within_le_nhds nhdsWithin_le_nhds theorem nhdsWithin_eq_nhdsWithin' {a : α} {s t u : Set α} (hs : s ∈ 𝓝 a) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict' t hs, nhdsWithin_restrict' u hs, h₂] #align nhds_within_eq_nhds_within' nhdsWithin_eq_nhdsWithin' theorem nhdsWithin_eq_nhdsWithin {a : α} {s t u : Set α} (h₀ : a ∈ s) (h₁ : IsOpen s) (h₂ : t ∩ s = u ∩ s) : 𝓝[t] a = 𝓝[u] a := by rw [nhdsWithin_restrict t h₀ h₁, nhdsWithin_restrict u h₀ h₁, h₂] #align nhds_within_eq_nhds_within nhdsWithin_eq_nhdsWithin @[simp] theorem nhdsWithin_eq_nhds {a : α} {s : Set α} : 𝓝[s] a = 𝓝 a ↔ s ∈ 𝓝 a := inf_eq_left.trans le_principal_iff #align nhds_within_eq_nhds nhdsWithin_eq_nhds theorem IsOpen.nhdsWithin_eq {a : α} {s : Set α} (h : IsOpen s) (ha : a ∈ s) : 𝓝[s] a = 𝓝 a := nhdsWithin_eq_nhds.2 <| h.mem_nhds ha #align is_open.nhds_within_eq IsOpen.nhdsWithin_eq theorem preimage_nhds_within_coinduced {π : α → β} {s : Set β} {t : Set α} {a : α} (h : a ∈ t) (ht : IsOpen t) (hs : s ∈ @nhds β (.coinduced (fun x : t => π x) inferInstance) (π a)) : π ⁻¹' s ∈ 𝓝 a := by rw [← ht.nhdsWithin_eq h] exact preimage_nhdsWithin_coinduced' h hs #align preimage_nhds_within_coinduced preimage_nhds_within_coinduced @[simp] theorem nhdsWithin_empty (a : α) : 𝓝[∅] a = ⊥ := by rw [nhdsWithin, principal_empty, inf_bot_eq] #align nhds_within_empty nhdsWithin_empty theorem nhdsWithin_union (a : α) (s t : Set α) : 𝓝[s ∪ t] a = 𝓝[s] a ⊔ 𝓝[t] a := by delta nhdsWithin rw [← inf_sup_left, sup_principal] #align nhds_within_union nhdsWithin_union theorem nhdsWithin_biUnion {ι} {I : Set ι} (hI : I.Finite) (s : ι → Set α) (a : α) : 𝓝[⋃ i ∈ I, s i] a = ⨆ i ∈ I, 𝓝[s i] a := Set.Finite.induction_on hI (by simp) fun _ _ hT ↦ by simp only [hT, nhdsWithin_union, iSup_insert, biUnion_insert] #align nhds_within_bUnion nhdsWithin_biUnion theorem nhdsWithin_sUnion {S : Set (Set α)} (hS : S.Finite) (a : α) : 𝓝[⋃₀ S] a = ⨆ s ∈ S, 𝓝[s] a := by rw [sUnion_eq_biUnion, nhdsWithin_biUnion hS] #align nhds_within_sUnion nhdsWithin_sUnion theorem nhdsWithin_iUnion {ι} [Finite ι] (s : ι → Set α) (a : α) : 𝓝[⋃ i, s i] a = ⨆ i, 𝓝[s i] a := by rw [← sUnion_range, nhdsWithin_sUnion (finite_range s), iSup_range] #align nhds_within_Union nhdsWithin_iUnion theorem nhdsWithin_inter (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓝[t] a := by delta nhdsWithin rw [inf_left_comm, inf_assoc, inf_principal, ← inf_assoc, inf_idem] #align nhds_within_inter nhdsWithin_inter theorem nhdsWithin_inter' (a : α) (s t : Set α) : 𝓝[s ∩ t] a = 𝓝[s] a ⊓ 𝓟 t := by delta nhdsWithin rw [← inf_principal, inf_assoc] #align nhds_within_inter' nhdsWithin_inter' theorem nhdsWithin_inter_of_mem {a : α} {s t : Set α} (h : s ∈ 𝓝[t] a) : 𝓝[s ∩ t] a = 𝓝[t] a := by rw [nhdsWithin_inter, inf_eq_right] exact nhdsWithin_le_of_mem h #align nhds_within_inter_of_mem nhdsWithin_inter_of_mem theorem nhdsWithin_inter_of_mem' {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : 𝓝[s ∩ t] a = 𝓝[s] a := by rw [inter_comm, nhdsWithin_inter_of_mem h] #align nhds_within_inter_of_mem' nhdsWithin_inter_of_mem' @[simp] theorem nhdsWithin_singleton (a : α) : 𝓝[{a}] a = pure a := by rw [nhdsWithin, principal_singleton, inf_eq_right.2 (pure_le_nhds a)] #align nhds_within_singleton nhdsWithin_singleton @[simp] theorem nhdsWithin_insert (a : α) (s : Set α) : 𝓝[insert a s] a = pure a ⊔ 𝓝[s] a := by rw [← singleton_union, nhdsWithin_union, nhdsWithin_singleton] #align nhds_within_insert nhdsWithin_insert theorem mem_nhdsWithin_insert {a : α} {s t : Set α} : t ∈ 𝓝[insert a s] a ↔ a ∈ t ∧ t ∈ 𝓝[s] a := by simp #align mem_nhds_within_insert mem_nhdsWithin_insert theorem insert_mem_nhdsWithin_insert {a : α} {s t : Set α} (h : t ∈ 𝓝[s] a) : insert a t ∈ 𝓝[insert a s] a := by simp [mem_of_superset h] #align insert_mem_nhds_within_insert insert_mem_nhdsWithin_insert theorem insert_mem_nhds_iff {a : α} {s : Set α} : insert a s ∈ 𝓝 a ↔ s ∈ 𝓝[≠] a := by simp only [nhdsWithin, mem_inf_principal, mem_compl_iff, mem_singleton_iff, or_iff_not_imp_left, insert_def] #align insert_mem_nhds_iff insert_mem_nhds_iff @[simp] theorem nhdsWithin_compl_singleton_sup_pure (a : α) : 𝓝[≠] a ⊔ pure a = 𝓝 a := by rw [← nhdsWithin_singleton, ← nhdsWithin_union, compl_union_self, nhdsWithin_univ] #align nhds_within_compl_singleton_sup_pure nhdsWithin_compl_singleton_sup_pure theorem nhdsWithin_prod {α : Type*} [TopologicalSpace α] {β : Type*} [TopologicalSpace β] {s u : Set α} {t v : Set β} {a : α} {b : β} (hu : u ∈ 𝓝[s] a) (hv : v ∈ 𝓝[t] b) : u ×ˢ v ∈ 𝓝[s ×ˢ t] (a, b) := by rw [nhdsWithin_prod_eq] exact prod_mem_prod hu hv #align nhds_within_prod nhdsWithin_prod theorem nhdsWithin_pi_eq' {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = ⨅ i, comap (fun x => x i) (𝓝 (x i) ⊓ ⨅ (_ : i ∈ I), 𝓟 (s i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, comap_inf, comap_iInf, pi_def, comap_principal, ← iInf_principal_finite hI, ← iInf_inf_eq] #align nhds_within_pi_eq' nhdsWithin_pi_eq' theorem nhdsWithin_pi_eq {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} (hI : I.Finite) (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi I s] x = (⨅ i ∈ I, comap (fun x => x i) (𝓝[s i] x i)) ⊓ ⨅ (i) (_ : i ∉ I), comap (fun x => x i) (𝓝 (x i)) := by simp only [nhdsWithin, nhds_pi, Filter.pi, pi_def, ← iInf_principal_finite hI, comap_inf, comap_principal, eval] rw [iInf_split _ fun i => i ∈ I, inf_right_comm] simp only [iInf_inf_eq] #align nhds_within_pi_eq nhdsWithin_pi_eq theorem nhdsWithin_pi_univ_eq {ι : Type*} {α : ι → Type*} [Finite ι] [∀ i, TopologicalSpace (α i)] (s : ∀ i, Set (α i)) (x : ∀ i, α i) : 𝓝[pi univ s] x = ⨅ i, comap (fun x => x i) (𝓝[s i] x i) := by simpa [nhdsWithin] using nhdsWithin_pi_eq finite_univ s x #align nhds_within_pi_univ_eq nhdsWithin_pi_univ_eq theorem nhdsWithin_pi_eq_bot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : 𝓝[pi I s] x = ⊥ ↔ ∃ i ∈ I, 𝓝[s i] x i = ⊥ := by simp only [nhdsWithin, nhds_pi, pi_inf_principal_pi_eq_bot] #align nhds_within_pi_eq_bot nhdsWithin_pi_eq_bot theorem nhdsWithin_pi_neBot {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : (𝓝[pi I s] x).NeBot ↔ ∀ i ∈ I, (𝓝[s i] x i).NeBot := by simp [neBot_iff, nhdsWithin_pi_eq_bot] #align nhds_within_pi_ne_bot nhdsWithin_pi_neBot theorem Filter.Tendsto.piecewise_nhdsWithin {f g : α → β} {t : Set α} [∀ x, Decidable (x ∈ t)] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ t] a) l) (h₁ : Tendsto g (𝓝[s ∩ tᶜ] a) l) : Tendsto (piecewise t f g) (𝓝[s] a) l := by apply Tendsto.piecewise <;> rwa [← nhdsWithin_inter'] #align filter.tendsto.piecewise_nhds_within Filter.Tendsto.piecewise_nhdsWithin theorem Filter.Tendsto.if_nhdsWithin {f g : α → β} {p : α → Prop} [DecidablePred p] {a : α} {s : Set α} {l : Filter β} (h₀ : Tendsto f (𝓝[s ∩ { x | p x }] a) l) (h₁ : Tendsto g (𝓝[s ∩ { x | ¬p x }] a) l) : Tendsto (fun x => if p x then f x else g x) (𝓝[s] a) l := h₀.piecewise_nhdsWithin h₁ #align filter.tendsto.if_nhds_within Filter.Tendsto.if_nhdsWithin theorem map_nhdsWithin (f : α → β) (a : α) (s : Set α) : map f (𝓝[s] a) = ⨅ t ∈ { t : Set α | a ∈ t ∧ IsOpen t }, 𝓟 (f '' (t ∩ s)) := ((nhdsWithin_basis_open a s).map f).eq_biInf #align map_nhds_within map_nhdsWithin theorem tendsto_nhdsWithin_mono_left {f : α → β} {a : α} {s t : Set α} {l : Filter β} (hst : s ⊆ t) (h : Tendsto f (𝓝[t] a) l) : Tendsto f (𝓝[s] a) l := h.mono_left <| nhdsWithin_mono a hst #align tendsto_nhds_within_mono_left tendsto_nhdsWithin_mono_left theorem tendsto_nhdsWithin_mono_right {f : β → α} {l : Filter β} {a : α} {s t : Set α} (hst : s ⊆ t) (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝[t] a) := h.mono_right (nhdsWithin_mono a hst) #align tendsto_nhds_within_mono_right tendsto_nhdsWithin_mono_right theorem tendsto_nhdsWithin_of_tendsto_nhds {f : α → β} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f (𝓝 a) l) : Tendsto f (𝓝[s] a) l := h.mono_left inf_le_left #align tendsto_nhds_within_of_tendsto_nhds tendsto_nhdsWithin_of_tendsto_nhds theorem eventually_mem_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : ∀ᶠ i in l, f i ∈ s := by simp_rw [nhdsWithin_eq, tendsto_iInf, mem_setOf_eq, tendsto_principal, mem_inter_iff, eventually_and] at h exact (h univ ⟨mem_univ a, isOpen_univ⟩).2 #align eventually_mem_of_tendsto_nhds_within eventually_mem_of_tendsto_nhdsWithin theorem tendsto_nhds_of_tendsto_nhdsWithin {f : β → α} {a : α} {s : Set α} {l : Filter β} (h : Tendsto f l (𝓝[s] a)) : Tendsto f l (𝓝 a) := h.mono_right nhdsWithin_le_nhds #align tendsto_nhds_of_tendsto_nhds_within tendsto_nhds_of_tendsto_nhdsWithin theorem nhdsWithin_neBot_of_mem {s : Set α} {x : α} (hx : x ∈ s) : NeBot (𝓝[s] x) := mem_closure_iff_nhdsWithin_neBot.1 <| subset_closure hx #align nhds_within_ne_bot_of_mem nhdsWithin_neBot_of_mem theorem IsClosed.mem_of_nhdsWithin_neBot {s : Set α} (hs : IsClosed s) {x : α} (hx : NeBot <| 𝓝[s] x) : x ∈ s := hs.closure_eq ▸ mem_closure_iff_nhdsWithin_neBot.2 hx #align is_closed.mem_of_nhds_within_ne_bot IsClosed.mem_of_nhdsWithin_neBot theorem DenseRange.nhdsWithin_neBot {ι : Type*} {f : ι → α} (h : DenseRange f) (x : α) : NeBot (𝓝[range f] x) := mem_closure_iff_clusterPt.1 (h x) #align dense_range.nhds_within_ne_bot DenseRange.nhdsWithin_neBot theorem mem_closure_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {I : Set ι} {s : ∀ i, Set (α i)} {x : ∀ i, α i} : x ∈ closure (pi I s) ↔ ∀ i ∈ I, x i ∈ closure (s i) := by simp only [mem_closure_iff_nhdsWithin_neBot, nhdsWithin_pi_neBot] #align mem_closure_pi mem_closure_pi theorem closure_pi_set {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] (I : Set ι) (s : ∀ i, Set (α i)) : closure (pi I s) = pi I fun i => closure (s i) := Set.ext fun _ => mem_closure_pi #align closure_pi_set closure_pi_set theorem dense_pi {ι : Type*} {α : ι → Type*} [∀ i, TopologicalSpace (α i)] {s : ∀ i, Set (α i)} (I : Set ι) (hs : ∀ i ∈ I, Dense (s i)) : Dense (pi I s) := by simp only [dense_iff_closure_eq, closure_pi_set, pi_congr rfl fun i hi => (hs i hi).closure_eq, pi_univ] #align dense_pi dense_pi theorem eventuallyEq_nhdsWithin_iff {f g : α → β} {s : Set α} {a : α} : f =ᶠ[𝓝[s] a] g ↔ ∀ᶠ x in 𝓝 a, x ∈ s → f x = g x := mem_inf_principal #align eventually_eq_nhds_within_iff eventuallyEq_nhdsWithin_iff theorem eventuallyEq_nhdsWithin_of_eqOn {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := mem_inf_of_right h #align eventually_eq_nhds_within_of_eq_on eventuallyEq_nhdsWithin_of_eqOn theorem Set.EqOn.eventuallyEq_nhdsWithin {f g : α → β} {s : Set α} {a : α} (h : EqOn f g s) : f =ᶠ[𝓝[s] a] g := eventuallyEq_nhdsWithin_of_eqOn h #align set.eq_on.eventually_eq_nhds_within Set.EqOn.eventuallyEq_nhdsWithin theorem tendsto_nhdsWithin_congr {f g : α → β} {s : Set α} {a : α} {l : Filter β} (hfg : ∀ x ∈ s, f x = g x) (hf : Tendsto f (𝓝[s] a) l) : Tendsto g (𝓝[s] a) l := (tendsto_congr' <| eventuallyEq_nhdsWithin_of_eqOn hfg).1 hf #align tendsto_nhds_within_congr tendsto_nhdsWithin_congr theorem eventually_nhdsWithin_of_forall {s : Set α} {a : α} {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_inf_of_right h #align eventually_nhds_within_of_forall eventually_nhdsWithin_of_forall theorem tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within {a : α} {l : Filter β} {s : Set α} (f : β → α) (h1 : Tendsto f l (𝓝 a)) (h2 : ∀ᶠ x in l, f x ∈ s) : Tendsto f l (𝓝[s] a) := tendsto_inf.2 ⟨h1, tendsto_principal.2 h2⟩ #align tendsto_nhds_within_of_tendsto_nhds_of_eventually_within tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within theorem tendsto_nhdsWithin_iff {a : α} {l : Filter β} {s : Set α} {f : β → α} : Tendsto f l (𝓝[s] a) ↔ Tendsto f l (𝓝 a) ∧ ∀ᶠ n in l, f n ∈ s := ⟨fun h => ⟨tendsto_nhds_of_tendsto_nhdsWithin h, eventually_mem_of_tendsto_nhdsWithin h⟩, fun h => tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ h.1 h.2⟩ #align tendsto_nhds_within_iff tendsto_nhdsWithin_iff @[simp] theorem tendsto_nhdsWithin_range {a : α} {l : Filter β} {f : β → α} : Tendsto f l (𝓝[range f] a) ↔ Tendsto f l (𝓝 a) := ⟨fun h => h.mono_right inf_le_left, fun h => tendsto_inf.2 ⟨h, tendsto_principal.2 <| eventually_of_forall mem_range_self⟩⟩ #align tendsto_nhds_within_range tendsto_nhdsWithin_range theorem Filter.EventuallyEq.eq_of_nhdsWithin {s : Set α} {f g : α → β} {a : α} (h : f =ᶠ[𝓝[s] a] g) (hmem : a ∈ s) : f a = g a := h.self_of_nhdsWithin hmem #align filter.eventually_eq.eq_of_nhds_within Filter.EventuallyEq.eq_of_nhdsWithin theorem eventually_nhdsWithin_of_eventually_nhds {α : Type*} [TopologicalSpace α] {s : Set α} {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∀ᶠ x in 𝓝[s] a, p x := mem_nhdsWithin_of_mem_nhds h #align eventually_nhds_within_of_eventually_nhds eventually_nhdsWithin_of_eventually_nhds /-! ### `nhdsWithin` and subtypes -/ theorem mem_nhdsWithin_subtype {s : Set α} {a : { x // x ∈ s }} {t u : Set { x // x ∈ s }} : t ∈ 𝓝[u] a ↔ t ∈ comap ((↑) : s → α) (𝓝[(↑) '' u] a) := by rw [nhdsWithin, nhds_subtype, principal_subtype, ← comap_inf, ← nhdsWithin] #align mem_nhds_within_subtype mem_nhdsWithin_subtype theorem nhdsWithin_subtype (s : Set α) (a : { x // x ∈ s }) (t : Set { x // x ∈ s }) : 𝓝[t] a = comap ((↑) : s → α) (𝓝[(↑) '' t] a) := Filter.ext fun _ => mem_nhdsWithin_subtype #align nhds_within_subtype nhdsWithin_subtype theorem nhdsWithin_eq_map_subtype_coe {s : Set α} {a : α} (h : a ∈ s) : 𝓝[s] a = map ((↑) : s → α) (𝓝 ⟨a, h⟩) := (map_nhds_subtype_val ⟨a, h⟩).symm #align nhds_within_eq_map_subtype_coe nhdsWithin_eq_map_subtype_coe theorem mem_nhds_subtype_iff_nhdsWithin {s : Set α} {a : s} {t : Set s} : t ∈ 𝓝 a ↔ (↑) '' t ∈ 𝓝[s] (a : α) := by rw [← map_nhds_subtype_val, image_mem_map_iff Subtype.val_injective] #align mem_nhds_subtype_iff_nhds_within mem_nhds_subtype_iff_nhdsWithin theorem preimage_coe_mem_nhds_subtype {s t : Set α} {a : s} : (↑) ⁻¹' t ∈ 𝓝 a ↔ t ∈ 𝓝[s] ↑a := by rw [← map_nhds_subtype_val, mem_map] #align preimage_coe_mem_nhds_subtype preimage_coe_mem_nhds_subtype theorem eventually_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∀ᶠ x : s in 𝓝 a, P x) ↔ ∀ᶠ x in 𝓝[s] a, P x := preimage_coe_mem_nhds_subtype theorem frequently_nhds_subtype_iff (s : Set α) (a : s) (P : α → Prop) : (∃ᶠ x : s in 𝓝 a, P x) ↔ ∃ᶠ x in 𝓝[s] a, P x := eventually_nhds_subtype_iff s a (¬ P ·) |>.not theorem tendsto_nhdsWithin_iff_subtype {s : Set α} {a : α} (h : a ∈ s) (f : α → β) (l : Filter β) : Tendsto f (𝓝[s] a) l ↔ Tendsto (s.restrict f) (𝓝 ⟨a, h⟩) l := by rw [nhdsWithin_eq_map_subtype_coe h, tendsto_map'_iff]; rfl #align tendsto_nhds_within_iff_subtype tendsto_nhdsWithin_iff_subtype variable [TopologicalSpace β] [TopologicalSpace γ] [TopologicalSpace δ] /-- If a function is continuous within `s` at `x`, then it tends to `f x` within `s` by definition. We register this fact for use with the dot notation, especially to use `Filter.Tendsto.comp` as `ContinuousWithinAt.comp` will have a different meaning. -/ theorem ContinuousWithinAt.tendsto {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝 (f x)) := h #align continuous_within_at.tendsto ContinuousWithinAt.tendsto theorem ContinuousOn.continuousWithinAt {f : α → β} {s : Set α} {x : α} (hf : ContinuousOn f s) (hx : x ∈ s) : ContinuousWithinAt f s x := hf x hx #align continuous_on.continuous_within_at ContinuousOn.continuousWithinAt theorem continuousWithinAt_univ (f : α → β) (x : α) : ContinuousWithinAt f Set.univ x ↔ ContinuousAt f x := by rw [ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_within_at_univ continuousWithinAt_univ theorem continuous_iff_continuousOn_univ {f : α → β} : Continuous f ↔ ContinuousOn f univ := by simp [continuous_iff_continuousAt, ContinuousOn, ContinuousAt, ContinuousWithinAt, nhdsWithin_univ] #align continuous_iff_continuous_on_univ continuous_iff_continuousOn_univ theorem continuousWithinAt_iff_continuousAt_restrict (f : α → β) {x : α} {s : Set α} (h : x ∈ s) : ContinuousWithinAt f s x ↔ ContinuousAt (s.restrict f) ⟨x, h⟩ := tendsto_nhdsWithin_iff_subtype h f _ #align continuous_within_at_iff_continuous_at_restrict continuousWithinAt_iff_continuousAt_restrict theorem ContinuousWithinAt.tendsto_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : MapsTo f s t) : Tendsto f (𝓝[s] x) (𝓝[t] f x) := tendsto_inf.2 ⟨h, tendsto_principal.2 <| mem_inf_of_right <| mem_principal.2 <| ht⟩ #align continuous_within_at.tendsto_nhds_within ContinuousWithinAt.tendsto_nhdsWithin theorem ContinuousWithinAt.tendsto_nhdsWithin_image {f : α → β} {x : α} {s : Set α} (h : ContinuousWithinAt f s x) : Tendsto f (𝓝[s] x) (𝓝[f '' s] f x) := h.tendsto_nhdsWithin (mapsTo_image _ _) #align continuous_within_at.tendsto_nhds_within_image ContinuousWithinAt.tendsto_nhdsWithin_image theorem ContinuousWithinAt.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} {x : α} {y : β} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g t y) : ContinuousWithinAt (Prod.map f g) (s ×ˢ t) (x, y) := by unfold ContinuousWithinAt at * rw [nhdsWithin_prod_eq, Prod.map, nhds_prod_eq] exact hf.prod_map hg #align continuous_within_at.prod_map ContinuousWithinAt.prod_map theorem continuousWithinAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨x.1, ·⟩) {b | (x.1, b) ∈ s} x.2 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, pure_prod, ← map_inf_principal_preimage]; rfl theorem continuousWithinAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} {x : α × β} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (f ⟨·, x.2⟩) {a | (a, x.2) ∈ s} x.1 := by rw [← x.eta]; simp_rw [ContinuousWithinAt, nhdsWithin, nhds_prod_eq, nhds_discrete, prod_pure, ← map_inf_principal_preimage]; rfl theorem continuousAt_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨x.1, ·⟩) x.2 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_left theorem continuousAt_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {x : α × β} : ContinuousAt f x ↔ ContinuousAt (f ⟨·, x.2⟩) x.1 := by simp_rw [← continuousWithinAt_univ]; exact continuousWithinAt_prod_of_discrete_right theorem continuousOn_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ a, ContinuousOn (f ⟨a, ·⟩) {b | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_left]; rfl theorem continuousOn_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} {s : Set (α × β)} : ContinuousOn f s ↔ ∀ b, ContinuousOn (f ⟨·, b⟩) {a | (a, b) ∈ s} := by simp_rw [ContinuousOn, Prod.forall, continuousWithinAt_prod_of_discrete_right]; apply forall_swap /-- If a function `f a b` is such that `y ↦ f a b` is continuous for all `a`, and `a` lives in a discrete space, then `f` is continuous, and vice versa. -/ theorem continuous_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : Continuous f ↔ ∀ a, Continuous (f ⟨a, ·⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_left theorem continuous_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : Continuous f ↔ ∀ b, Continuous (f ⟨·, b⟩) := by simp_rw [continuous_iff_continuousOn_univ]; exact continuousOn_prod_of_discrete_right theorem isOpenMap_prod_of_discrete_left [DiscreteTopology α] {f : α × β → γ} : IsOpenMap f ↔ ∀ a, IsOpenMap (f ⟨a, ·⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, nhds_prod_eq, nhds_discrete, pure_prod, map_map] rfl theorem isOpenMap_prod_of_discrete_right [DiscreteTopology β] {f : α × β → γ} : IsOpenMap f ↔ ∀ b, IsOpenMap (f ⟨·, b⟩) := by simp_rw [isOpenMap_iff_nhds_le, Prod.forall, forall_swap (α := α) (β := β), nhds_prod_eq, nhds_discrete, prod_pure, map_map]; rfl theorem continuousWithinAt_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ∀ i, ContinuousWithinAt (fun y => f y i) s x := tendsto_pi_nhds #align continuous_within_at_pi continuousWithinAt_pi theorem continuousOn_pi {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} : ContinuousOn f s ↔ ∀ i, ContinuousOn (fun y => f y i) s := ⟨fun h i x hx => tendsto_pi_nhds.1 (h x hx) i, fun h x hx => tendsto_pi_nhds.2 fun i => h i x hx⟩ #align continuous_on_pi continuousOn_pi @[fun_prop] theorem continuousOn_pi' {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] {f : α → ∀ i, π i} {s : Set α} (hf : ∀ i, ContinuousOn (fun y => f y i) s) : ContinuousOn f s := continuousOn_pi.2 hf theorem ContinuousWithinAt.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {a : α} {s : Set α} (hf : ContinuousWithinAt f s a) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousWithinAt g s a) : ContinuousWithinAt (fun a => i.insertNth (f a) (g a)) s a := hf.tendsto.fin_insertNth i hg #align continuous_within_at.fin_insert_nth ContinuousWithinAt.fin_insertNth nonrec theorem ContinuousOn.fin_insertNth {n} {π : Fin (n + 1) → Type*} [∀ i, TopologicalSpace (π i)] (i : Fin (n + 1)) {f : α → π i} {s : Set α} (hf : ContinuousOn f s) {g : α → ∀ j : Fin n, π (i.succAbove j)} (hg : ContinuousOn g s) : ContinuousOn (fun a => i.insertNth (f a) (g a)) s := fun a ha => (hf a ha).fin_insertNth i (hg a ha) #align continuous_on.fin_insert_nth ContinuousOn.fin_insertNth theorem continuousOn_iff {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ x ∈ s, ∀ t : Set β, IsOpen t → f x ∈ t → ∃ u, IsOpen u ∧ x ∈ u ∧ u ∩ s ⊆ f ⁻¹' t := by simp only [ContinuousOn, ContinuousWithinAt, tendsto_nhds, mem_nhdsWithin] #align continuous_on_iff continuousOn_iff theorem continuousOn_iff_continuous_restrict {f : α → β} {s : Set α} : ContinuousOn f s ↔ Continuous (s.restrict f) := by rw [ContinuousOn, continuous_iff_continuousAt]; constructor · rintro h ⟨x, xs⟩ exact (continuousWithinAt_iff_continuousAt_restrict f xs).mp (h x xs) intro h x xs exact (continuousWithinAt_iff_continuousAt_restrict f xs).mpr (h ⟨x, xs⟩) #align continuous_on_iff_continuous_restrict continuousOn_iff_continuous_restrict -- Porting note: 2 new lemmas alias ⟨ContinuousOn.restrict, _⟩ := continuousOn_iff_continuous_restrict theorem ContinuousOn.restrict_mapsTo {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (ht : MapsTo f s t) : Continuous (ht.restrict f s t) := hf.restrict.codRestrict _ theorem continuousOn_iff' {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ t : Set β, IsOpen t → ∃ u, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsOpen (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsOpen u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isOpen_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff] constructor <;> · rintro ⟨u, ou, useq⟩ exact ⟨u, ou, by simpa only [Set.inter_comm, eq_comm] using useq⟩ rw [continuousOn_iff_continuous_restrict, continuous_def]; simp only [this] #align continuous_on_iff' continuousOn_iff' /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any finer topology on the source space. -/ theorem ContinuousOn.mono_dom {α β : Type*} {t₁ t₂ : TopologicalSpace α} {t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₁) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₃ f s) : @ContinuousOn α β t₂ t₃ f s := fun x hx _u hu => map_mono (inf_le_inf_right _ <| nhds_mono h₁) (h₂ x hx hu) #align continuous_on.mono_dom ContinuousOn.mono_dom /-- If a function is continuous on a set for some topologies, then it is continuous on the same set with respect to any coarser topology on the target space. -/ theorem ContinuousOn.mono_rng {α β : Type*} {t₁ : TopologicalSpace α} {t₂ t₃ : TopologicalSpace β} (h₁ : t₂ ≤ t₃) {s : Set α} {f : α → β} (h₂ : @ContinuousOn α β t₁ t₂ f s) : @ContinuousOn α β t₁ t₃ f s := fun x hx _u hu => h₂ x hx <| nhds_mono h₁ hu #align continuous_on.mono_rng ContinuousOn.mono_rng theorem continuousOn_iff_isClosed {f : α → β} {s : Set α} : ContinuousOn f s ↔ ∀ t : Set β, IsClosed t → ∃ u, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by have : ∀ t, IsClosed (s.restrict f ⁻¹' t) ↔ ∃ u : Set α, IsClosed u ∧ f ⁻¹' t ∩ s = u ∩ s := by intro t rw [isClosed_induced_iff, Set.restrict_eq, Set.preimage_comp] simp only [Subtype.preimage_coe_eq_preimage_coe_iff, eq_comm, Set.inter_comm s] rw [continuousOn_iff_continuous_restrict, continuous_iff_isClosed]; simp only [this] #align continuous_on_iff_is_closed continuousOn_iff_isClosed theorem ContinuousOn.prod_map {f : α → γ} {g : β → δ} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hg : ContinuousOn g t) : ContinuousOn (Prod.map f g) (s ×ˢ t) := fun ⟨x, y⟩ ⟨hx, hy⟩ => ContinuousWithinAt.prod_map (hf x hx) (hg y hy) #align continuous_on.prod_map ContinuousOn.prod_map theorem continuous_of_cover_nhds {ι : Sort*} {f : α → β} {s : ι → Set α} (hs : ∀ x : α, ∃ i, s i ∈ 𝓝 x) (hf : ∀ i, ContinuousOn f (s i)) : Continuous f := continuous_iff_continuousAt.mpr fun x ↦ let ⟨i, hi⟩ := hs x; by rw [ContinuousAt, ← nhdsWithin_eq_nhds.2 hi] exact hf _ _ (mem_of_mem_nhds hi) #align continuous_of_cover_nhds continuous_of_cover_nhds theorem continuousOn_empty (f : α → β) : ContinuousOn f ∅ := fun _ => False.elim #align continuous_on_empty continuousOn_empty @[simp] theorem continuousOn_singleton (f : α → β) (a : α) : ContinuousOn f {a} := forall_eq.2 <| by simpa only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_left] using fun s => mem_of_mem_nhds #align continuous_on_singleton continuousOn_singleton theorem Set.Subsingleton.continuousOn {s : Set α} (hs : s.Subsingleton) (f : α → β) : ContinuousOn f s := hs.induction_on (continuousOn_empty f) (continuousOn_singleton f) #align set.subsingleton.continuous_on Set.Subsingleton.continuousOn theorem nhdsWithin_le_comap {x : α} {s : Set α} {f : α → β} (ctsf : ContinuousWithinAt f s x) : 𝓝[s] x ≤ comap f (𝓝[f '' s] f x) := ctsf.tendsto_nhdsWithin_image.le_comap #align nhds_within_le_comap nhdsWithin_le_comap @[simp] theorem comap_nhdsWithin_range {α} (f : α → β) (y : β) : comap f (𝓝[range f] y) = comap f (𝓝 y) := comap_inf_principal_range #align comap_nhds_within_range comap_nhdsWithin_range theorem ContinuousWithinAt.mono {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x) (hs : s ⊆ t) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_mono x hs) #align continuous_within_at.mono ContinuousWithinAt.mono theorem ContinuousWithinAt.mono_of_mem {f : α → β} {s t : Set α} {x : α} (h : ContinuousWithinAt f t x) (hs : t ∈ 𝓝[s] x) : ContinuousWithinAt f s x := h.mono_left (nhdsWithin_le_of_mem hs) #align continuous_within_at.mono_of_mem ContinuousWithinAt.mono_of_mem theorem continuousWithinAt_congr_nhds {f : α → β} {s t : Set α} {x : α} (h : 𝓝[s] x = 𝓝[t] x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, h] theorem continuousWithinAt_inter' {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝[s] x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict'' s h] #align continuous_within_at_inter' continuousWithinAt_inter' theorem continuousWithinAt_inter {f : α → β} {s t : Set α} {x : α} (h : t ∈ 𝓝 x) : ContinuousWithinAt f (s ∩ t) x ↔ ContinuousWithinAt f s x := by simp [ContinuousWithinAt, nhdsWithin_restrict' s h] #align continuous_within_at_inter continuousWithinAt_inter theorem continuousWithinAt_union {f : α → β} {s t : Set α} {x : α} : ContinuousWithinAt f (s ∪ t) x ↔ ContinuousWithinAt f s x ∧ ContinuousWithinAt f t x := by simp only [ContinuousWithinAt, nhdsWithin_union, tendsto_sup] #align continuous_within_at_union continuousWithinAt_union theorem ContinuousWithinAt.union {f : α → β} {s t : Set α} {x : α} (hs : ContinuousWithinAt f s x) (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s ∪ t) x := continuousWithinAt_union.2 ⟨hs, ht⟩ #align continuous_within_at.union ContinuousWithinAt.union theorem ContinuousWithinAt.mem_closure_image {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) : f x ∈ closure (f '' s) := haveI := mem_closure_iff_nhdsWithin_neBot.1 hx mem_closure_of_tendsto h <| mem_of_superset self_mem_nhdsWithin (subset_preimage_image f s) #align continuous_within_at.mem_closure_image ContinuousWithinAt.mem_closure_image theorem ContinuousWithinAt.mem_closure {f : α → β} {s : Set α} {x : α} {A : Set β} (h : ContinuousWithinAt f s x) (hx : x ∈ closure s) (hA : MapsTo f s A) : f x ∈ closure A := closure_mono (image_subset_iff.2 hA) (h.mem_closure_image hx) #align continuous_within_at.mem_closure ContinuousWithinAt.mem_closure theorem Set.MapsTo.closure_of_continuousWithinAt {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t) (hc : ∀ x ∈ closure s, ContinuousWithinAt f s x) : MapsTo f (closure s) (closure t) := fun x hx => (hc x hx).mem_closure hx h #align set.maps_to.closure_of_continuous_within_at Set.MapsTo.closure_of_continuousWithinAt theorem Set.MapsTo.closure_of_continuousOn {f : α → β} {s : Set α} {t : Set β} (h : MapsTo f s t) (hc : ContinuousOn f (closure s)) : MapsTo f (closure s) (closure t) := h.closure_of_continuousWithinAt fun x hx => (hc x hx).mono subset_closure #align set.maps_to.closure_of_continuous_on Set.MapsTo.closure_of_continuousOn theorem ContinuousWithinAt.image_closure {f : α → β} {s : Set α} (hf : ∀ x ∈ closure s, ContinuousWithinAt f s x) : f '' closure s ⊆ closure (f '' s) := ((mapsTo_image f s).closure_of_continuousWithinAt hf).image_subset #align continuous_within_at.image_closure ContinuousWithinAt.image_closure theorem ContinuousOn.image_closure {f : α → β} {s : Set α} (hf : ContinuousOn f (closure s)) : f '' closure s ⊆ closure (f '' s) := ContinuousWithinAt.image_closure fun x hx => (hf x hx).mono subset_closure #align continuous_on.image_closure ContinuousOn.image_closure @[simp] theorem continuousWithinAt_singleton {f : α → β} {x : α} : ContinuousWithinAt f {x} x := by simp only [ContinuousWithinAt, nhdsWithin_singleton, tendsto_pure_nhds] #align continuous_within_at_singleton continuousWithinAt_singleton @[simp] theorem continuousWithinAt_insert_self {f : α → β} {x : α} {s : Set α} : ContinuousWithinAt f (insert x s) x ↔ ContinuousWithinAt f s x := by simp only [← singleton_union, continuousWithinAt_union, continuousWithinAt_singleton, true_and_iff] #align continuous_within_at_insert_self continuousWithinAt_insert_self alias ⟨_, ContinuousWithinAt.insert_self⟩ := continuousWithinAt_insert_self #align continuous_within_at.insert_self ContinuousWithinAt.insert_self theorem ContinuousWithinAt.diff_iff {f : α → β} {s t : Set α} {x : α} (ht : ContinuousWithinAt f t x) : ContinuousWithinAt f (s \ t) x ↔ ContinuousWithinAt f s x := ⟨fun h => (h.union ht).mono <| by simp only [diff_union_self, subset_union_left], fun h => h.mono diff_subset⟩ #align continuous_within_at.diff_iff ContinuousWithinAt.diff_iff @[simp] theorem continuousWithinAt_diff_self {f : α → β} {s : Set α} {x : α} : ContinuousWithinAt f (s \ {x}) x ↔ ContinuousWithinAt f s x := continuousWithinAt_singleton.diff_iff #align continuous_within_at_diff_self continuousWithinAt_diff_self @[simp] theorem continuousWithinAt_compl_self {f : α → β} {a : α} : ContinuousWithinAt f {a}ᶜ a ↔ ContinuousAt f a := by rw [compl_eq_univ_diff, continuousWithinAt_diff_self, continuousWithinAt_univ] #align continuous_within_at_compl_self continuousWithinAt_compl_self @[simp] theorem continuousWithinAt_update_same [DecidableEq α] {f : α → β} {s : Set α} {x : α} {y : β} : ContinuousWithinAt (update f x y) s x ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := calc ContinuousWithinAt (update f x y) s x ↔ Tendsto (update f x y) (𝓝[s \ {x}] x) (𝓝 y) := by { rw [← continuousWithinAt_diff_self, ContinuousWithinAt, update_same] } _ ↔ Tendsto f (𝓝[s \ {x}] x) (𝓝 y) := tendsto_congr' <| eventually_nhdsWithin_iff.2 <| eventually_of_forall fun z hz => update_noteq hz.2 _ _ #align continuous_within_at_update_same continuousWithinAt_update_same @[simp] theorem continuousAt_update_same [DecidableEq α] {f : α → β} {x : α} {y : β} : ContinuousAt (Function.update f x y) x ↔ Tendsto f (𝓝[≠] x) (𝓝 y) := by rw [← continuousWithinAt_univ, continuousWithinAt_update_same, compl_eq_univ_diff] #align continuous_at_update_same continuousAt_update_same theorem IsOpenMap.continuousOn_image_of_leftInvOn {f : α → β} {s : Set α} (h : IsOpenMap (s.restrict f)) {finv : β → α} (hleft : LeftInvOn finv f s) : ContinuousOn finv (f '' s) := by refine continuousOn_iff'.2 fun t ht => ⟨f '' (t ∩ s), ?_, ?_⟩ · rw [← image_restrict] exact h _ (ht.preimage continuous_subtype_val) · rw [inter_eq_self_of_subset_left (image_subset f inter_subset_right), hleft.image_inter'] #align is_open_map.continuous_on_image_of_left_inv_on IsOpenMap.continuousOn_image_of_leftInvOn theorem IsOpenMap.continuousOn_range_of_leftInverse {f : α → β} (hf : IsOpenMap f) {finv : β → α} (hleft : Function.LeftInverse finv f) : ContinuousOn finv (range f) := by rw [← image_univ] exact (hf.restrict isOpen_univ).continuousOn_image_of_leftInvOn fun x _ => hleft x #align is_open_map.continuous_on_range_of_left_inverse IsOpenMap.continuousOn_range_of_leftInverse theorem ContinuousOn.congr_mono {f g : α → β} {s s₁ : Set α} (h : ContinuousOn f s) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) : ContinuousOn g s₁ := by intro x hx unfold ContinuousWithinAt have A := (h x (h₁ hx)).mono h₁ unfold ContinuousWithinAt at A rw [← h' hx] at A exact A.congr' h'.eventuallyEq_nhdsWithin.symm #align continuous_on.congr_mono ContinuousOn.congr_mono theorem ContinuousOn.congr {f g : α → β} {s : Set α} (h : ContinuousOn f s) (h' : EqOn g f s) : ContinuousOn g s := h.congr_mono h' (Subset.refl _) #align continuous_on.congr ContinuousOn.congr theorem continuousOn_congr {f g : α → β} {s : Set α} (h' : EqOn g f s) : ContinuousOn g s ↔ ContinuousOn f s := ⟨fun h => ContinuousOn.congr h h'.symm, fun h => h.congr h'⟩ #align continuous_on_congr continuousOn_congr theorem ContinuousAt.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : ContinuousAt f x) : ContinuousWithinAt f s x := ContinuousWithinAt.mono ((continuousWithinAt_univ f x).2 h) (subset_univ _) #align continuous_at.continuous_within_at ContinuousAt.continuousWithinAt theorem continuousWithinAt_iff_continuousAt {f : α → β} {s : Set α} {x : α} (h : s ∈ 𝓝 x) : ContinuousWithinAt f s x ↔ ContinuousAt f x := by rw [← univ_inter s, continuousWithinAt_inter h, continuousWithinAt_univ] #align continuous_within_at_iff_continuous_at continuousWithinAt_iff_continuousAt theorem ContinuousWithinAt.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (hs : s ∈ 𝓝 x) : ContinuousAt f x := (continuousWithinAt_iff_continuousAt hs).mp h #align continuous_within_at.continuous_at ContinuousWithinAt.continuousAt theorem IsOpen.continuousOn_iff {f : α → β} {s : Set α} (hs : IsOpen s) : ContinuousOn f s ↔ ∀ ⦃a⦄, a ∈ s → ContinuousAt f a := forall₂_congr fun _ => continuousWithinAt_iff_continuousAt ∘ hs.mem_nhds #align is_open.continuous_on_iff IsOpen.continuousOn_iff theorem ContinuousOn.continuousAt {f : α → β} {s : Set α} {x : α} (h : ContinuousOn f s) (hx : s ∈ 𝓝 x) : ContinuousAt f x := (h x (mem_of_mem_nhds hx)).continuousAt hx #align continuous_on.continuous_at ContinuousOn.continuousAt theorem ContinuousAt.continuousOn {f : α → β} {s : Set α} (hcont : ∀ x ∈ s, ContinuousAt f x) : ContinuousOn f s := fun x hx => (hcont x hx).continuousWithinAt #align continuous_at.continuous_on ContinuousAt.continuousOn theorem ContinuousWithinAt.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) (h : MapsTo f s t) : ContinuousWithinAt (g ∘ f) s x := hg.tendsto.comp (hf.tendsto_nhdsWithin h) #align continuous_within_at.comp ContinuousWithinAt.comp theorem ContinuousWithinAt.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} {x : α} (hg : ContinuousWithinAt g t (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) (s ∩ f ⁻¹' t) x := hg.comp (hf.mono inter_subset_left) inter_subset_right #align continuous_within_at.comp' ContinuousWithinAt.comp' theorem ContinuousAt.comp_continuousWithinAt {g : β → γ} {f : α → β} {s : Set α} {x : α} (hg : ContinuousAt g (f x)) (hf : ContinuousWithinAt f s x) : ContinuousWithinAt (g ∘ f) s x := hg.continuousWithinAt.comp hf (mapsTo_univ _ _) #align continuous_at.comp_continuous_within_at ContinuousAt.comp_continuousWithinAt theorem ContinuousOn.comp {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : MapsTo f s t) : ContinuousOn (g ∘ f) s := fun x hx => ContinuousWithinAt.comp (hg _ (h hx)) (hf x hx) h #align continuous_on.comp ContinuousOn.comp @[fun_prop] theorem ContinuousOn.comp'' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) (h : Set.MapsTo f s t) : ContinuousOn (fun x => g (f x)) s := ContinuousOn.comp hg hf h theorem ContinuousOn.mono {f : α → β} {s t : Set α} (hf : ContinuousOn f s) (h : t ⊆ s) : ContinuousOn f t := fun x hx => (hf x (h hx)).mono_left (nhdsWithin_mono _ h) #align continuous_on.mono ContinuousOn.mono theorem antitone_continuousOn {f : α → β} : Antitone (ContinuousOn f) := fun _s _t hst hf => hf.mono hst #align antitone_continuous_on antitone_continuousOn @[fun_prop] theorem ContinuousOn.comp' {g : β → γ} {f : α → β} {s : Set α} {t : Set β} (hg : ContinuousOn g t) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) (s ∩ f ⁻¹' t) := hg.comp (hf.mono inter_subset_left) inter_subset_right #align continuous_on.comp' ContinuousOn.comp' @[fun_prop] theorem Continuous.continuousOn {f : α → β} {s : Set α} (h : Continuous f) : ContinuousOn f s := by rw [continuous_iff_continuousOn_univ] at h exact h.mono (subset_univ _) #align continuous.continuous_on Continuous.continuousOn theorem Continuous.continuousWithinAt {f : α → β} {s : Set α} {x : α} (h : Continuous f) : ContinuousWithinAt f s x := h.continuousAt.continuousWithinAt #align continuous.continuous_within_at Continuous.continuousWithinAt theorem Continuous.comp_continuousOn {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (g ∘ f) s := hg.continuousOn.comp hf (mapsTo_univ _ _) #align continuous.comp_continuous_on Continuous.comp_continuousOn @[fun_prop] theorem Continuous.comp_continuousOn' {α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} {s : Set α} (hg : Continuous g) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ g (f x)) s := hg.comp_continuousOn hf theorem ContinuousOn.comp_continuous {g : β → γ} {f : α → β} {s : Set β} (hg : ContinuousOn g s) (hf : Continuous f) (hs : ∀ x, f x ∈ s) : Continuous (g ∘ f) := by rw [continuous_iff_continuousOn_univ] at * exact hg.comp hf fun x _ => hs x #align continuous_on.comp_continuous ContinuousOn.comp_continuous @[fun_prop] theorem continuousOn_apply {ι : Type*} {π : ι → Type*} [∀ i, TopologicalSpace (π i)] (i : ι) (s) : ContinuousOn (fun p : ∀ i, π i => p i) s := Continuous.continuousOn (continuous_apply i) theorem ContinuousWithinAt.preimage_mem_nhdsWithin {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝 (f x)) : f ⁻¹' t ∈ 𝓝[s] x := h ht #align continuous_within_at.preimage_mem_nhds_within ContinuousWithinAt.preimage_mem_nhdsWithin theorem Set.LeftInvOn.map_nhdsWithin_eq {f : α → β} {g : β → α} {x : β} {s : Set β} (h : LeftInvOn f g s) (hx : f (g x) = x) (hf : ContinuousWithinAt f (g '' s) (g x)) (hg : ContinuousWithinAt g s x) : map g (𝓝[s] x) = 𝓝[g '' s] g x := by apply le_antisymm · exact hg.tendsto_nhdsWithin (mapsTo_image _ _) · have A : g ∘ f =ᶠ[𝓝[g '' s] g x] id := h.rightInvOn_image.eqOn.eventuallyEq_of_mem self_mem_nhdsWithin refine le_map_of_right_inverse A ?_ simpa only [hx] using hf.tendsto_nhdsWithin (h.mapsTo (surjOn_image _ _)) #align set.left_inv_on.map_nhds_within_eq Set.LeftInvOn.map_nhdsWithin_eq theorem Function.LeftInverse.map_nhds_eq {f : α → β} {g : β → α} {x : β} (h : Function.LeftInverse f g) (hf : ContinuousWithinAt f (range g) (g x)) (hg : ContinuousAt g x) : map g (𝓝 x) = 𝓝[range g] g x := by simpa only [nhdsWithin_univ, image_univ] using (h.leftInvOn univ).map_nhdsWithin_eq (h x) (by rwa [image_univ]) hg.continuousWithinAt #align function.left_inverse.map_nhds_eq Function.LeftInverse.map_nhds_eq theorem ContinuousWithinAt.preimage_mem_nhdsWithin' {f : α → β} {x : α} {s : Set α} {t : Set β} (h : ContinuousWithinAt f s x) (ht : t ∈ 𝓝[f '' s] f x) : f ⁻¹' t ∈ 𝓝[s] x := h.tendsto_nhdsWithin (mapsTo_image _ _) ht #align continuous_within_at.preimage_mem_nhds_within' ContinuousWithinAt.preimage_mem_nhdsWithin' theorem ContinuousWithinAt.preimage_mem_nhdsWithin'' {f : α → β} {x : α} {y : β} {s t : Set β} (h : ContinuousWithinAt f (f ⁻¹' s) x) (ht : t ∈ 𝓝[s] y) (hxy : y = f x) : f ⁻¹' t ∈ 𝓝[f ⁻¹' s] x := by rw [hxy] at ht exact h.preimage_mem_nhdsWithin' (nhdsWithin_mono _ (image_preimage_subset f s) ht) theorem Filter.EventuallyEq.congr_continuousWithinAt {f g : α → β} {s : Set α} {x : α} (h : f =ᶠ[𝓝[s] x] g) (hx : f x = g x) : ContinuousWithinAt f s x ↔ ContinuousWithinAt g s x := by rw [ContinuousWithinAt, hx, tendsto_congr' h, ContinuousWithinAt] #align filter.eventually_eq.congr_continuous_within_at Filter.EventuallyEq.congr_continuousWithinAt theorem ContinuousWithinAt.congr_of_eventuallyEq {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x := (h₁.congr_continuousWithinAt hx).2 h #align continuous_within_at.congr_of_eventually_eq ContinuousWithinAt.congr_of_eventuallyEq theorem ContinuousWithinAt.congr {f f₁ : α → β} {s : Set α} {x : α} (h : ContinuousWithinAt f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContinuousWithinAt f₁ s x := h.congr_of_eventuallyEq (mem_of_superset self_mem_nhdsWithin h₁) hx #align continuous_within_at.congr ContinuousWithinAt.congr theorem ContinuousWithinAt.congr_mono {f g : α → β} {s s₁ : Set α} {x : α} (h : ContinuousWithinAt f s x) (h' : EqOn g f s₁) (h₁ : s₁ ⊆ s) (hx : g x = f x) : ContinuousWithinAt g s₁ x := (h.mono h₁).congr h' hx #align continuous_within_at.congr_mono ContinuousWithinAt.congr_mono @[fun_prop] theorem continuousOn_const {s : Set α} {c : β} : ContinuousOn (fun _ => c) s := continuous_const.continuousOn #align continuous_on_const continuousOn_const theorem continuousWithinAt_const {b : β} {s : Set α} {x : α} : ContinuousWithinAt (fun _ : α => b) s x := continuous_const.continuousWithinAt #align continuous_within_at_const continuousWithinAt_const theorem continuousOn_id {s : Set α} : ContinuousOn id s := continuous_id.continuousOn #align continuous_on_id continuousOn_id @[fun_prop] theorem continuousOn_id' (s : Set α) : ContinuousOn (fun x : α => x) s := continuousOn_id theorem continuousWithinAt_id {s : Set α} {x : α} : ContinuousWithinAt id s x := continuous_id.continuousWithinAt #align continuous_within_at_id continuousWithinAt_id theorem continuousOn_open_iff {f : α → β} {s : Set α} (hs : IsOpen s) : ContinuousOn f s ↔ ∀ t, IsOpen t → IsOpen (s ∩ f ⁻¹' t) := by rw [continuousOn_iff'] constructor · intro h t ht rcases h t ht with ⟨u, u_open, hu⟩ rw [inter_comm, hu] apply IsOpen.inter u_open hs · intro h t ht refine ⟨s ∩ f ⁻¹' t, h t ht, ?_⟩ rw [@inter_comm _ s (f ⁻¹' t), inter_assoc, inter_self] #align continuous_on_open_iff continuousOn_open_iff theorem ContinuousOn.isOpen_inter_preimage {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) (ht : IsOpen t) : IsOpen (s ∩ f ⁻¹' t) := (continuousOn_open_iff hs).1 hf t ht #align continuous_on.preimage_open_of_open ContinuousOn.isOpen_inter_preimage theorem ContinuousOn.isOpen_preimage {f : α → β} {s : Set α} {t : Set β} (h : ContinuousOn f s) (hs : IsOpen s) (hp : f ⁻¹' t ⊆ s) (ht : IsOpen t) : IsOpen (f ⁻¹' t) := by convert (continuousOn_open_iff hs).mp h t ht rw [inter_comm, inter_eq_self_of_subset_left hp] #align continuous_on.is_open_preimage ContinuousOn.isOpen_preimage theorem ContinuousOn.preimage_isClosed_of_isClosed {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsClosed s) (ht : IsClosed t) : IsClosed (s ∩ f ⁻¹' t) := by rcases continuousOn_iff_isClosed.1 hf t ht with ⟨u, hu⟩ rw [inter_comm, hu.2] apply IsClosed.inter hu.1 hs #align continuous_on.preimage_closed_of_closed ContinuousOn.preimage_isClosed_of_isClosed theorem ContinuousOn.preimage_interior_subset_interior_preimage {f : α → β} {s : Set α} {t : Set β} (hf : ContinuousOn f s) (hs : IsOpen s) : s ∩ f ⁻¹' interior t ⊆ s ∩ interior (f ⁻¹' t) := calc s ∩ f ⁻¹' interior t ⊆ interior (s ∩ f ⁻¹' t) := interior_maximal (inter_subset_inter (Subset.refl _) (preimage_mono interior_subset)) (hf.isOpen_inter_preimage hs isOpen_interior) _ = s ∩ interior (f ⁻¹' t) := by rw [interior_inter, hs.interior_eq] #align continuous_on.preimage_interior_subset_interior_preimage ContinuousOn.preimage_interior_subset_interior_preimage theorem continuousOn_of_locally_continuousOn {f : α → β} {s : Set α} (h : ∀ x ∈ s, ∃ t, IsOpen t ∧ x ∈ t ∧ ContinuousOn f (s ∩ t)) : ContinuousOn f s := by intro x xs rcases h x xs with ⟨t, open_t, xt, ct⟩ have := ct x ⟨xs, xt⟩ rwa [ContinuousWithinAt, ← nhdsWithin_restrict _ xt open_t] at this #align continuous_on_of_locally_continuous_on continuousOn_of_locally_continuousOn -- Porting note (#10756): new lemma theorem continuousOn_to_generateFrom_iff {s : Set α} {T : Set (Set β)} {f : α → β} : @ContinuousOn α β _ (.generateFrom T) f s ↔ ∀ x ∈ s, ∀ t ∈ T, f x ∈ t → f ⁻¹' t ∈ 𝓝[s] x := forall₂_congr fun x _ => by delta ContinuousWithinAt simp only [TopologicalSpace.nhds_generateFrom, tendsto_iInf, tendsto_principal, mem_setOf_eq, and_imp] exact forall_congr' fun t => forall_swap -- Porting note: dropped an unneeded assumption theorem continuousOn_isOpen_of_generateFrom {β : Type*} {s : Set α} {T : Set (Set β)} {f : α → β} (h : ∀ t ∈ T, IsOpen (s ∩ f ⁻¹' t)) : @ContinuousOn α β _ (.generateFrom T) f s := continuousOn_to_generateFrom_iff.2 fun _x hx t ht hxt => mem_nhdsWithin.2 ⟨_, h t ht, ⟨hx, hxt⟩, fun _y hy => hy.1.2⟩ #align continuous_on_open_of_generate_from continuousOn_isOpen_of_generateFromₓ theorem ContinuousWithinAt.prod {f : α → β} {g : α → γ} {s : Set α} {x : α} (hf : ContinuousWithinAt f s x) (hg : ContinuousWithinAt g s x) : ContinuousWithinAt (fun x => (f x, g x)) s x := hf.prod_mk_nhds hg #align continuous_within_at.prod ContinuousWithinAt.prod @[fun_prop] theorem ContinuousOn.prod {f : α → β} {g : α → γ} {s : Set α} (hf : ContinuousOn f s) (hg : ContinuousOn g s) : ContinuousOn (fun x => (f x, g x)) s := fun x hx => ContinuousWithinAt.prod (hf x hx) (hg x hx) #align continuous_on.prod ContinuousOn.prod theorem ContinuousAt.comp₂_continuousWithinAt {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} (hf : ContinuousAt f (g x, h x)) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := ContinuousAt.comp_continuousWithinAt hf (hg.prod hh) theorem ContinuousAt.comp₂_continuousWithinAt_of_eq {f : β × γ → δ} {g : α → β} {h : α → γ} {x : α} {s : Set α} {y : β × γ} (hf : ContinuousAt f y) (hg : ContinuousWithinAt g s x) (hh : ContinuousWithinAt h s x) (e : (g x, h x) = y) : ContinuousWithinAt (fun x ↦ f (g x, h x)) s x := by rw [← e] at hf exact hf.comp₂_continuousWithinAt hg hh theorem Inducing.continuousWithinAt_iff {f : α → β} {g : β → γ} (hg : Inducing g) {s : Set α} {x : α} : ContinuousWithinAt f s x ↔ ContinuousWithinAt (g ∘ f) s x := by simp_rw [ContinuousWithinAt, Inducing.tendsto_nhds_iff hg]; rfl #align inducing.continuous_within_at_iff Inducing.continuousWithinAt_iff theorem Inducing.continuousOn_iff {f : α → β} {g : β → γ} (hg : Inducing g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := by simp_rw [ContinuousOn, hg.continuousWithinAt_iff] #align inducing.continuous_on_iff Inducing.continuousOn_iff theorem Embedding.continuousOn_iff {f : α → β} {g : β → γ} (hg : Embedding g) {s : Set α} : ContinuousOn f s ↔ ContinuousOn (g ∘ f) s := Inducing.continuousOn_iff hg.1 #align embedding.continuous_on_iff Embedding.continuousOn_iff theorem Embedding.map_nhdsWithin_eq {f : α → β} (hf : Embedding f) (s : Set α) (x : α) : map f (𝓝[s] x) = 𝓝[f '' s] f x := by rw [nhdsWithin, Filter.map_inf hf.inj, hf.map_nhds_eq, map_principal, ← nhdsWithin_inter', inter_eq_self_of_subset_right (image_subset_range _ _)] #align embedding.map_nhds_within_eq Embedding.map_nhdsWithin_eq theorem OpenEmbedding.map_nhdsWithin_preimage_eq {f : α → β} (hf : OpenEmbedding f) (s : Set β) (x : α) : map f (𝓝[f ⁻¹' s] x) = 𝓝[s] f x := by rw [hf.toEmbedding.map_nhdsWithin_eq, image_preimage_eq_inter_range] apply nhdsWithin_eq_nhdsWithin (mem_range_self _) hf.isOpen_range rw [inter_assoc, inter_self] #align open_embedding.map_nhds_within_preimage_eq OpenEmbedding.map_nhdsWithin_preimage_eq theorem continuousWithinAt_of_not_mem_closure {f : α → β} {s : Set α} {x : α} (hx : x ∉ closure s) : ContinuousWithinAt f s x := by rw [mem_closure_iff_nhdsWithin_neBot, not_neBot] at hx rw [ContinuousWithinAt, hx] exact tendsto_bot #align continuous_within_at_of_not_mem_closure continuousWithinAt_of_not_mem_closure theorem ContinuousOn.if' {s : Set α} {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hpf : ∀ a ∈ s ∩ frontier { a | p a }, Tendsto f (𝓝[s ∩ { a | p a }] a) (𝓝 <| if p a then f a else g a)) (hpg : ∀ a ∈ s ∩ frontier { a | p a }, Tendsto g (𝓝[s ∩ { a | ¬p a }] a) (𝓝 <| if p a then f a else g a)) (hf : ContinuousOn f <| s ∩ { a | p a }) (hg : ContinuousOn g <| s ∩ { a | ¬p a }) : ContinuousOn (fun a => if p a then f a else g a) s := by intro x hx by_cases hx' : x ∈ frontier { a | p a } · exact (hpf x ⟨hx, hx'⟩).piecewise_nhdsWithin (hpg x ⟨hx, hx'⟩) · rw [← inter_univ s, ← union_compl_self { a | p a }, inter_union_distrib_left] at hx ⊢ cases' hx with hx hx · apply ContinuousWithinAt.union · exact (hf x hx).congr (fun y hy => if_pos hy.2) (if_pos hx.2) · have : x ∉ closure { a | p a }ᶜ := fun h => hx' ⟨subset_closure hx.2, by rwa [closure_compl] at h⟩ exact continuousWithinAt_of_not_mem_closure fun h => this (closure_inter_subset_inter_closure _ _ h).2 · apply ContinuousWithinAt.union · have : x ∉ closure { a | p a } := fun h => hx' ⟨h, fun h' : x ∈ interior { a | p a } => hx.2 (interior_subset h')⟩ exact continuousWithinAt_of_not_mem_closure fun h => this (closure_inter_subset_inter_closure _ _ h).2 · exact (hg x hx).congr (fun y hy => if_neg hy.2) (if_neg hx.2) #align continuous_on.if' ContinuousOn.if' theorem ContinuousOn.piecewise' {s t : Set α} {f g : α → β} [∀ a, Decidable (a ∈ t)] (hpf : ∀ a ∈ s ∩ frontier t, Tendsto f (𝓝[s ∩ t] a) (𝓝 (piecewise t f g a))) (hpg : ∀ a ∈ s ∩ frontier t, Tendsto g (𝓝[s ∩ tᶜ] a) (𝓝 (piecewise t f g a))) (hf : ContinuousOn f <| s ∩ t) (hg : ContinuousOn g <| s ∩ tᶜ) : ContinuousOn (piecewise t f g) s := hf.if' hpf hpg hg #align continuous_on.piecewise' ContinuousOn.piecewise' theorem ContinuousOn.if {α β : Type*} [TopologicalSpace α] [TopologicalSpace β] {p : α → Prop} [∀ a, Decidable (p a)] {s : Set α} {f g : α → β} (hp : ∀ a ∈ s ∩ frontier { a | p a }, f a = g a) (hf : ContinuousOn f <| s ∩ closure { a | p a }) (hg : ContinuousOn g <| s ∩ closure { a | ¬p a }) : ContinuousOn (fun a => if p a then f a else g a) s := by apply ContinuousOn.if' · rintro a ha simp only [← hp a ha, ite_self] apply tendsto_nhdsWithin_mono_left (inter_subset_inter_right s subset_closure) exact hf a ⟨ha.1, ha.2.1⟩ · rintro a ha simp only [hp a ha, ite_self] apply tendsto_nhdsWithin_mono_left (inter_subset_inter_right s subset_closure) rcases ha with ⟨has, ⟨_, ha⟩⟩ rw [← mem_compl_iff, ← closure_compl] at ha apply hg a ⟨has, ha⟩ · exact hf.mono (inter_subset_inter_right s subset_closure) · exact hg.mono (inter_subset_inter_right s subset_closure) #align continuous_on.if ContinuousOn.if theorem ContinuousOn.piecewise {s t : Set α} {f g : α → β} [∀ a, Decidable (a ∈ t)] (ht : ∀ a ∈ s ∩ frontier t, f a = g a) (hf : ContinuousOn f <| s ∩ closure t) (hg : ContinuousOn g <| s ∩ closure tᶜ) : ContinuousOn (piecewise t f g) s := hf.if ht hg #align continuous_on.piecewise ContinuousOn.piecewise theorem continuous_if' {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hpf : ∀ a ∈ frontier { x | p x }, Tendsto f (𝓝[{ x | p x }] a) (𝓝 <| ite (p a) (f a) (g a))) (hpg : ∀ a ∈ frontier { x | p x }, Tendsto g (𝓝[{ x | ¬p x }] a) (𝓝 <| ite (p a) (f a) (g a))) (hf : ContinuousOn f { x | p x }) (hg : ContinuousOn g { x | ¬p x }) : Continuous fun a => ite (p a) (f a) (g a) := by rw [continuous_iff_continuousOn_univ] apply ContinuousOn.if' <;> simp [*] <;> assumption #align continuous_if' continuous_if' theorem continuous_if {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hp : ∀ a ∈ frontier { x | p x }, f a = g a) (hf : ContinuousOn f (closure { x | p x })) (hg : ContinuousOn g (closure { x | ¬p x })) : Continuous fun a => if p a then f a else g a := by rw [continuous_iff_continuousOn_univ] apply ContinuousOn.if <;> simp <;> assumption #align continuous_if continuous_if theorem Continuous.if {p : α → Prop} {f g : α → β} [∀ a, Decidable (p a)] (hp : ∀ a ∈ frontier { x | p x }, f a = g a) (hf : Continuous f) (hg : Continuous g) : Continuous fun a => if p a then f a else g a := continuous_if hp hf.continuousOn hg.continuousOn #align continuous.if Continuous.if theorem continuous_if_const (p : Prop) {f g : α → β} [Decidable p] (hf : p → Continuous f) (hg : ¬p → Continuous g) : Continuous fun a => if p then f a else g a := by split_ifs with h exacts [hf h, hg h] #align continuous_if_const continuous_if_const theorem Continuous.if_const (p : Prop) {f g : α → β} [Decidable p] (hf : Continuous f) (hg : Continuous g) : Continuous fun a => if p then f a else g a := continuous_if_const p (fun _ => hf) fun _ => hg #align continuous.if_const Continuous.if_const theorem continuous_piecewise {s : Set α} {f g : α → β} [∀ a, Decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : ContinuousOn f (closure s)) (hg : ContinuousOn g (closure sᶜ)) : Continuous (piecewise s f g) := continuous_if hs hf hg #align continuous_piecewise continuous_piecewise theorem Continuous.piecewise {s : Set α} {f g : α → β} [∀ a, Decidable (a ∈ s)] (hs : ∀ a ∈ frontier s, f a = g a) (hf : Continuous f) (hg : Continuous g) : Continuous (piecewise s f g) := hf.if hs hg #align continuous.piecewise Continuous.piecewise section Indicator variable [One β] {f : α → β} {s : Set α} @[to_additive] lemma continuous_mulIndicator (hs : ∀ a ∈ frontier s, f a = 1) (hf : ContinuousOn f (closure s)) : Continuous (mulIndicator s f) := by classical exact continuous_piecewise hs hf continuousOn_const @[to_additive] protected lemma Continuous.mulIndicator (hs : ∀ a ∈ frontier s, f a = 1) (hf : Continuous f) : Continuous (mulIndicator s f) := by classical exact hf.piecewise hs continuous_const end Indicator theorem IsOpen.ite' {s s' t : Set α} (hs : IsOpen s) (hs' : IsOpen s') (ht : ∀ x ∈ frontier t, x ∈ s ↔ x ∈ s') : IsOpen (t.ite s s') := by classical simp only [isOpen_iff_continuous_mem, Set.ite] at * convert continuous_piecewise (fun x hx => propext (ht x hx)) hs.continuousOn hs'.continuousOn rename_i x by_cases hx : x ∈ t <;> simp [hx] #align is_open.ite' IsOpen.ite' theorem IsOpen.ite {s s' t : Set α} (hs : IsOpen s) (hs' : IsOpen s') (ht : s ∩ frontier t = s' ∩ frontier t) : IsOpen (t.ite s s') := hs.ite' hs' fun x hx => by simpa [hx] using ext_iff.1 ht x #align is_open.ite IsOpen.ite theorem ite_inter_closure_eq_of_inter_frontier_eq {s s' t : Set α} (ht : s ∩ frontier t = s' ∩ frontier t) : t.ite s s' ∩ closure t = s ∩ closure t := by rw [closure_eq_self_union_frontier, inter_union_distrib_left, inter_union_distrib_left, ite_inter_self, ite_inter_of_inter_eq _ ht] #align ite_inter_closure_eq_of_inter_frontier_eq ite_inter_closure_eq_of_inter_frontier_eq theorem ite_inter_closure_compl_eq_of_inter_frontier_eq {s s' t : Set α} (ht : s ∩ frontier t = s' ∩ frontier t) : t.ite s s' ∩ closure tᶜ = s' ∩ closure tᶜ := by rw [← ite_compl, ite_inter_closure_eq_of_inter_frontier_eq] rwa [frontier_compl, eq_comm] #align ite_inter_closure_compl_eq_of_inter_frontier_eq ite_inter_closure_compl_eq_of_inter_frontier_eq
Mathlib/Topology/ContinuousOn.lean
1,344
1,351
theorem continuousOn_piecewise_ite' {s s' t : Set α} {f f' : α → β} [∀ x, Decidable (x ∈ t)] (h : ContinuousOn f (s ∩ closure t)) (h' : ContinuousOn f' (s' ∩ closure tᶜ)) (H : s ∩ frontier t = s' ∩ frontier t) (Heq : EqOn f f' (s ∩ frontier t)) : ContinuousOn (t.piecewise f f') (t.ite s s') := by
apply ContinuousOn.piecewise · rwa [ite_inter_of_inter_eq _ H] · rwa [ite_inter_closure_eq_of_inter_frontier_eq H] · rwa [ite_inter_closure_compl_eq_of_inter_frontier_eq H]
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.RingTheory.Valuation.Basic import Mathlib.NumberTheory.Padics.PadicNorm import Mathlib.Analysis.Normed.Field.Basic #align_import number_theory.padics.padic_numbers from "leanprover-community/mathlib"@"b9b2114f7711fec1c1e055d507f082f8ceb2c3b7" /-! # p-adic numbers This file defines the `p`-adic numbers (rationals) `ℚ_[p]` as the completion of `ℚ` with respect to the `p`-adic norm. We show that the `p`-adic norm on `ℚ` extends to `ℚ_[p]`, that `ℚ` is embedded in `ℚ_[p]`, and that `ℚ_[p]` is Cauchy complete. ## Important definitions * `Padic` : the type of `p`-adic numbers * `padicNormE` : the rational valued `p`-adic norm on `ℚ_[p]` * `Padic.addValuation` : the additive `p`-adic valuation on `ℚ_[p]`, with values in `WithTop ℤ` ## Notation We introduce the notation `ℚ_[p]` for the `p`-adic numbers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. We use the same concrete Cauchy sequence construction that is used to construct `ℝ`. `ℚ_[p]` inherits a field structure from this construction. The extension of the norm on `ℚ` to `ℚ_[p]` is *not* analogous to extending the absolute value to `ℝ` and hence the proof that `ℚ_[p]` is complete is different from the proof that ℝ is complete. A small special-purpose simplification tactic, `padic_index_simp`, is used to manipulate sequence indices in the proof that the norm extends. `padicNormE` is the rational-valued `p`-adic norm on `ℚ_[p]`. To instantiate `ℚ_[p]` as a normed field, we must cast this into an `ℝ`-valued norm. The `ℝ`-valued norm, using notation `‖ ‖` from normed spaces, is the canonical representation of this norm. `simp` prefers `padicNorm` to `padicNormE` when possible. Since `padicNormE` and `‖ ‖` have different types, `simp` does not rewrite one to the other. Coercions from `ℚ` to `ℚ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation, cauchy, completion, p-adic completion -/ noncomputable section open scoped Classical open Nat multiplicity padicNorm CauSeq CauSeq.Completion Metric /-- The type of Cauchy sequences of rationals with respect to the `p`-adic norm. -/ abbrev PadicSeq (p : ℕ) := CauSeq _ (padicNorm p) #align padic_seq PadicSeq namespace PadicSeq section variable {p : ℕ} [Fact p.Prime] /-- The `p`-adic norm of the entries of a nonzero Cauchy sequence of rationals is eventually constant. -/ theorem stationary {f : CauSeq ℚ (padicNorm p)} (hf : ¬f ≈ 0) : ∃ N, ∀ m n, N ≤ m → N ≤ n → padicNorm p (f n) = padicNorm p (f m) := have : ∃ ε > 0, ∃ N1, ∀ j ≥ N1, ε ≤ padicNorm p (f j) := CauSeq.abv_pos_of_not_limZero <| not_limZero_of_not_congr_zero hf let ⟨ε, hε, N1, hN1⟩ := this let ⟨N2, hN2⟩ := CauSeq.cauchy₂ f hε ⟨max N1 N2, fun n m hn hm ↦ by have : padicNorm p (f n - f m) < ε := hN2 _ (max_le_iff.1 hn).2 _ (max_le_iff.1 hm).2 have : padicNorm p (f n - f m) < padicNorm p (f n) := lt_of_lt_of_le this <| hN1 _ (max_le_iff.1 hn).1 have : padicNorm p (f n - f m) < max (padicNorm p (f n)) (padicNorm p (f m)) := lt_max_iff.2 (Or.inl this) by_contra hne rw [← padicNorm.neg (f m)] at hne have hnam := add_eq_max_of_ne hne rw [padicNorm.neg, max_comm] at hnam rw [← hnam, sub_eq_add_neg, add_comm] at this apply _root_.lt_irrefl _ this⟩ #align padic_seq.stationary PadicSeq.stationary /-- For all `n ≥ stationaryPoint f hf`, the `p`-adic norm of `f n` is the same. -/ def stationaryPoint {f : PadicSeq p} (hf : ¬f ≈ 0) : ℕ := Classical.choose <| stationary hf #align padic_seq.stationary_point PadicSeq.stationaryPoint theorem stationaryPoint_spec {f : PadicSeq p} (hf : ¬f ≈ 0) : ∀ {m n}, stationaryPoint hf ≤ m → stationaryPoint hf ≤ n → padicNorm p (f n) = padicNorm p (f m) := @(Classical.choose_spec <| stationary hf) #align padic_seq.stationary_point_spec PadicSeq.stationaryPoint_spec /-- Since the norm of the entries of a Cauchy sequence is eventually stationary, we can lift the norm to sequences. -/ def norm (f : PadicSeq p) : ℚ := if hf : f ≈ 0 then 0 else padicNorm p (f (stationaryPoint hf)) #align padic_seq.norm PadicSeq.norm theorem norm_zero_iff (f : PadicSeq p) : f.norm = 0 ↔ f ≈ 0 := by constructor · intro h by_contra hf unfold norm at h split_ifs at h · contradiction apply hf intro ε hε exists stationaryPoint hf intro j hj have heq := stationaryPoint_spec hf le_rfl hj simpa [h, heq] · intro h simp [norm, h] #align padic_seq.norm_zero_iff PadicSeq.norm_zero_iff end section Embedding open CauSeq variable {p : ℕ} [Fact p.Prime] theorem equiv_zero_of_val_eq_of_equiv_zero {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) (hf : f ≈ 0) : g ≈ 0 := fun ε hε ↦ let ⟨i, hi⟩ := hf _ hε ⟨i, fun j hj ↦ by simpa [h] using hi _ hj⟩ #align padic_seq.equiv_zero_of_val_eq_of_equiv_zero PadicSeq.equiv_zero_of_val_eq_of_equiv_zero theorem norm_nonzero_of_not_equiv_zero {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm ≠ 0 := hf ∘ f.norm_zero_iff.1 #align padic_seq.norm_nonzero_of_not_equiv_zero PadicSeq.norm_nonzero_of_not_equiv_zero theorem norm_eq_norm_app_of_nonzero {f : PadicSeq p} (hf : ¬f ≈ 0) : ∃ k, f.norm = padicNorm p k ∧ k ≠ 0 := have heq : f.norm = padicNorm p (f <| stationaryPoint hf) := by simp [norm, hf] ⟨f <| stationaryPoint hf, heq, fun h ↦ norm_nonzero_of_not_equiv_zero hf (by simpa [h] using heq)⟩ #align padic_seq.norm_eq_norm_app_of_nonzero PadicSeq.norm_eq_norm_app_of_nonzero theorem not_limZero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬LimZero (const (padicNorm p) q) := fun h' ↦ hq <| const_limZero.1 h' #align padic_seq.not_lim_zero_const_of_nonzero PadicSeq.not_limZero_const_of_nonzero theorem not_equiv_zero_const_of_nonzero {q : ℚ} (hq : q ≠ 0) : ¬const (padicNorm p) q ≈ 0 := fun h : LimZero (const (padicNorm p) q - 0) ↦ not_limZero_const_of_nonzero hq <| by simpa using h #align padic_seq.not_equiv_zero_const_of_nonzero PadicSeq.not_equiv_zero_const_of_nonzero theorem norm_nonneg (f : PadicSeq p) : 0 ≤ f.norm := if hf : f ≈ 0 then by simp [hf, norm] else by simp [norm, hf, padicNorm.nonneg] #align padic_seq.norm_nonneg PadicSeq.norm_nonneg /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_left_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v2 v3 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max (stationaryPoint hf) (max v2 v3))) := by apply stationaryPoint_spec hf · apply le_max_left · exact le_rfl #align padic_seq.lift_index_left_left PadicSeq.lift_index_left_left /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_left {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v3 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max v1 (max (stationaryPoint hf) v3))) := by apply stationaryPoint_spec hf · apply le_trans · apply le_max_left _ v3 · apply le_max_right · exact le_rfl #align padic_seq.lift_index_left PadicSeq.lift_index_left /-- An auxiliary lemma for manipulating sequence indices. -/ theorem lift_index_right {f : PadicSeq p} (hf : ¬f ≈ 0) (v1 v2 : ℕ) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f (max v1 (max v2 (stationaryPoint hf)))) := by apply stationaryPoint_spec hf · apply le_trans · apply le_max_right v2 · apply le_max_right · exact le_rfl #align padic_seq.lift_index_right PadicSeq.lift_index_right end Embedding section Valuation open CauSeq variable {p : ℕ} [Fact p.Prime] /-! ### Valuation on `PadicSeq` -/ /-- The `p`-adic valuation on `ℚ` lifts to `PadicSeq p`. `Valuation f` is defined to be the valuation of the (`ℚ`-valued) stationary point of `f`. -/ def valuation (f : PadicSeq p) : ℤ := if hf : f ≈ 0 then 0 else padicValRat p (f (stationaryPoint hf)) #align padic_seq.valuation PadicSeq.valuation theorem norm_eq_pow_val {f : PadicSeq p} (hf : ¬f ≈ 0) : f.norm = (p : ℚ) ^ (-f.valuation : ℤ) := by rw [norm, valuation, dif_neg hf, dif_neg hf, padicNorm, if_neg] intro H apply CauSeq.not_limZero_of_not_congr_zero hf intro ε hε use stationaryPoint hf intro n hn rw [stationaryPoint_spec hf le_rfl hn] simpa [H] using hε #align padic_seq.norm_eq_pow_val PadicSeq.norm_eq_pow_val theorem val_eq_iff_norm_eq {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : f.valuation = g.valuation ↔ f.norm = g.norm := by rw [norm_eq_pow_val hf, norm_eq_pow_val hg, ← neg_inj, zpow_inj] · exact mod_cast (Fact.out : p.Prime).pos · exact mod_cast (Fact.out : p.Prime).ne_one #align padic_seq.val_eq_iff_norm_eq PadicSeq.val_eq_iff_norm_eq end Valuation end PadicSeq section open PadicSeq -- Porting note: Commented out `padic_index_simp` tactic /- private unsafe def index_simp_core (hh hf hg : expr) (at_ : Interactive.Loc := Interactive.Loc.ns [none]) : tactic Unit := do let [v1, v2, v3] ← [hh, hf, hg].mapM fun n => tactic.mk_app `` stationary_point [n] <|> return n let e1 ← tactic.mk_app `` lift_index_left_left [hh, v2, v3] <|> return q(True) let e2 ← tactic.mk_app `` lift_index_left [hf, v1, v3] <|> return q(True) let e3 ← tactic.mk_app `` lift_index_right [hg, v1, v2] <|> return q(True) let sl ← [e1, e2, e3].foldlM (fun s e => simp_lemmas.add s e) simp_lemmas.mk when at_ (tactic.simp_target sl >> tactic.skip) let hs ← at_.get_locals hs (tactic.simp_hyp sl []) #align index_simp_core index_simp_core /-- This is a special-purpose tactic that lifts `padicNorm (f (stationary_point f))` to `padicNorm (f (max _ _ _))`. -/ unsafe def tactic.interactive.padic_index_simp (l : interactive.parse interactive.types.pexpr_list) (at_ : interactive.parse interactive.types.location) : tactic Unit := do let [h, f, g] ← l.mapM tactic.i_to_expr index_simp_core h f g at_ #align tactic.interactive.padic_index_simp tactic.interactive.padic_index_simp -/ end namespace PadicSeq section Embedding open CauSeq variable {p : ℕ} [hp : Fact p.Prime] theorem norm_mul (f g : PadicSeq p) : (f * g).norm = f.norm * g.norm := if hf : f ≈ 0 then by have hg : f * g ≈ 0 := mul_equiv_zero' _ hf simp only [hf, hg, norm, dif_pos, zero_mul] else if hg : g ≈ 0 then by have hf : f * g ≈ 0 := mul_equiv_zero _ hg simp only [hf, hg, norm, dif_pos, mul_zero] else by unfold norm split_ifs with hfg · exact (mul_not_equiv_zero hf hg hfg).elim -- Porting note: originally `padic_index_simp [hfg, hf, hg]` rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg] apply padicNorm.mul #align padic_seq.norm_mul PadicSeq.norm_mul theorem eq_zero_iff_equiv_zero (f : PadicSeq p) : mk f = 0 ↔ f ≈ 0 := mk_eq #align padic_seq.eq_zero_iff_equiv_zero PadicSeq.eq_zero_iff_equiv_zero theorem ne_zero_iff_nequiv_zero (f : PadicSeq p) : mk f ≠ 0 ↔ ¬f ≈ 0 := not_iff_not.2 (eq_zero_iff_equiv_zero _) #align padic_seq.ne_zero_iff_nequiv_zero PadicSeq.ne_zero_iff_nequiv_zero theorem norm_const (q : ℚ) : norm (const (padicNorm p) q) = padicNorm p q := if hq : q = 0 then by have : const (padicNorm p) q ≈ 0 := by simp [hq]; apply Setoid.refl (const (padicNorm p) 0) subst hq; simp [norm, this] else by have : ¬const (padicNorm p) q ≈ 0 := not_equiv_zero_const_of_nonzero hq simp [norm, this] #align padic_seq.norm_const PadicSeq.norm_const theorem norm_values_discrete (a : PadicSeq p) (ha : ¬a ≈ 0) : ∃ z : ℤ, a.norm = (p : ℚ) ^ (-z) := by let ⟨k, hk, hk'⟩ := norm_eq_norm_app_of_nonzero ha simpa [hk] using padicNorm.values_discrete hk' #align padic_seq.norm_values_discrete PadicSeq.norm_values_discrete theorem norm_one : norm (1 : PadicSeq p) = 1 := by have h1 : ¬(1 : PadicSeq p) ≈ 0 := one_not_equiv_zero _ simp [h1, norm, hp.1.one_lt] #align padic_seq.norm_one PadicSeq.norm_one private theorem norm_eq_of_equiv_aux {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) (h : padicNorm p (f (stationaryPoint hf)) ≠ padicNorm p (g (stationaryPoint hg))) (hlt : padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) : False := by have hpn : 0 < padicNorm p (f (stationaryPoint hf)) - padicNorm p (g (stationaryPoint hg)) := sub_pos_of_lt hlt cases' hfg _ hpn with N hN let i := max N (max (stationaryPoint hf) (stationaryPoint hg)) have hi : N ≤ i := le_max_left _ _ have hN' := hN _ hi -- Porting note: originally `padic_index_simp [N, hf, hg] at hN' h hlt` rw [lift_index_left hf N (stationaryPoint hg), lift_index_right hg N (stationaryPoint hf)] at hN' h hlt have hpne : padicNorm p (f i) ≠ padicNorm p (-g i) := by rwa [← padicNorm.neg (g i)] at h rw [CauSeq.sub_apply, sub_eq_add_neg, add_eq_max_of_ne hpne, padicNorm.neg, max_eq_left_of_lt hlt] at hN' have : padicNorm p (f i) < padicNorm p (f i) := by apply lt_of_lt_of_le hN' apply sub_le_self apply padicNorm.nonneg exact lt_irrefl _ this private theorem norm_eq_of_equiv {f g : PadicSeq p} (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) (hfg : f ≈ g) : padicNorm p (f (stationaryPoint hf)) = padicNorm p (g (stationaryPoint hg)) := by by_contra h cases' Decidable.em (padicNorm p (g (stationaryPoint hg)) < padicNorm p (f (stationaryPoint hf))) with hlt hnlt · exact norm_eq_of_equiv_aux hf hg hfg h hlt · apply norm_eq_of_equiv_aux hg hf (Setoid.symm hfg) (Ne.symm h) apply lt_of_le_of_ne · apply le_of_not_gt hnlt · apply h theorem norm_equiv {f g : PadicSeq p} (hfg : f ≈ g) : f.norm = g.norm := if hf : f ≈ 0 then by have hg : g ≈ 0 := Setoid.trans (Setoid.symm hfg) hf simp [norm, hf, hg] else by have hg : ¬g ≈ 0 := hf ∘ Setoid.trans hfg unfold norm; split_ifs; exact norm_eq_of_equiv hf hg hfg #align padic_seq.norm_equiv PadicSeq.norm_equiv private theorem norm_nonarchimedean_aux {f g : PadicSeq p} (hfg : ¬f + g ≈ 0) (hf : ¬f ≈ 0) (hg : ¬g ≈ 0) : (f + g).norm ≤ max f.norm g.norm := by unfold norm; split_ifs -- Porting note: originally `padic_index_simp [hfg, hf, hg]` rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg] apply padicNorm.nonarchimedean theorem norm_nonarchimedean (f g : PadicSeq p) : (f + g).norm ≤ max f.norm g.norm := if hfg : f + g ≈ 0 then by have : 0 ≤ max f.norm g.norm := le_max_of_le_left (norm_nonneg _) simpa only [hfg, norm] else if hf : f ≈ 0 then by have hfg' : f + g ≈ g := by change LimZero (f - 0) at hf show LimZero (f + g - g); · simpa only [sub_zero, add_sub_cancel_right] using hf have hcfg : (f + g).norm = g.norm := norm_equiv hfg' have hcl : f.norm = 0 := (norm_zero_iff f).2 hf have : max f.norm g.norm = g.norm := by rw [hcl]; exact max_eq_right (norm_nonneg _) rw [this, hcfg] else if hg : g ≈ 0 then by have hfg' : f + g ≈ f := by change LimZero (g - 0) at hg show LimZero (f + g - f); · simpa only [add_sub_cancel_left, sub_zero] using hg have hcfg : (f + g).norm = f.norm := norm_equiv hfg' have hcl : g.norm = 0 := (norm_zero_iff g).2 hg have : max f.norm g.norm = f.norm := by rw [hcl]; exact max_eq_left (norm_nonneg _) rw [this, hcfg] else norm_nonarchimedean_aux hfg hf hg #align padic_seq.norm_nonarchimedean PadicSeq.norm_nonarchimedean theorem norm_eq {f g : PadicSeq p} (h : ∀ k, padicNorm p (f k) = padicNorm p (g k)) : f.norm = g.norm := if hf : f ≈ 0 then by have hg : g ≈ 0 := equiv_zero_of_val_eq_of_equiv_zero h hf simp only [hf, hg, norm, dif_pos] else by have hg : ¬g ≈ 0 := fun hg ↦ hf <| equiv_zero_of_val_eq_of_equiv_zero (by simp only [h, forall_const, eq_self_iff_true]) hg simp only [hg, hf, norm, dif_neg, not_false_iff] let i := max (stationaryPoint hf) (stationaryPoint hg) have hpf : padicNorm p (f (stationaryPoint hf)) = padicNorm p (f i) := by apply stationaryPoint_spec · apply le_max_left · exact le_rfl have hpg : padicNorm p (g (stationaryPoint hg)) = padicNorm p (g i) := by apply stationaryPoint_spec · apply le_max_right · exact le_rfl rw [hpf, hpg, h] #align padic_seq.norm_eq PadicSeq.norm_eq theorem norm_neg (a : PadicSeq p) : (-a).norm = a.norm := norm_eq <| by simp #align padic_seq.norm_neg PadicSeq.norm_neg theorem norm_eq_of_add_equiv_zero {f g : PadicSeq p} (h : f + g ≈ 0) : f.norm = g.norm := by have : LimZero (f + g - 0) := h have : f ≈ -g := show LimZero (f - -g) by simpa only [sub_zero, sub_neg_eq_add] have : f.norm = (-g).norm := norm_equiv this simpa only [norm_neg] using this #align padic_seq.norm_eq_of_add_equiv_zero PadicSeq.norm_eq_of_add_equiv_zero theorem add_eq_max_of_ne {f g : PadicSeq p} (hfgne : f.norm ≠ g.norm) : (f + g).norm = max f.norm g.norm := have hfg : ¬f + g ≈ 0 := mt norm_eq_of_add_equiv_zero hfgne if hf : f ≈ 0 then by have : LimZero (f - 0) := hf have : f + g ≈ g := show LimZero (f + g - g) by simpa only [sub_zero, add_sub_cancel_right] have h1 : (f + g).norm = g.norm := norm_equiv this have h2 : f.norm = 0 := (norm_zero_iff _).2 hf rw [h1, h2, max_eq_right (norm_nonneg _)] else if hg : g ≈ 0 then by have : LimZero (g - 0) := hg have : f + g ≈ f := show LimZero (f + g - f) by simpa only [add_sub_cancel_left, sub_zero] have h1 : (f + g).norm = f.norm := norm_equiv this have h2 : g.norm = 0 := (norm_zero_iff _).2 hg rw [h1, h2, max_eq_left (norm_nonneg _)] else by unfold norm at hfgne ⊢; split_ifs at hfgne ⊢ -- Porting note: originally `padic_index_simp [hfg, hf, hg] at hfgne ⊢` rw [lift_index_left hf, lift_index_right hg] at hfgne · rw [lift_index_left_left hfg, lift_index_left hf, lift_index_right hg] exact padicNorm.add_eq_max_of_ne hfgne #align padic_seq.add_eq_max_of_ne PadicSeq.add_eq_max_of_ne end Embedding end PadicSeq /-- The `p`-adic numbers `ℚ_[p]` are the Cauchy completion of `ℚ` with respect to the `p`-adic norm. -/ def Padic (p : ℕ) [Fact p.Prime] := CauSeq.Completion.Cauchy (padicNorm p) #align padic Padic /-- notation for p-padic rationals -/ notation "ℚ_[" p "]" => Padic p namespace Padic section Completion variable {p : ℕ} [Fact p.Prime] instance field : Field ℚ_[p] := Cauchy.field instance : Inhabited ℚ_[p] := ⟨0⟩ -- short circuits instance : CommRing ℚ_[p] := Cauchy.commRing instance : Ring ℚ_[p] := Cauchy.ring instance : Zero ℚ_[p] := by infer_instance instance : One ℚ_[p] := by infer_instance instance : Add ℚ_[p] := by infer_instance instance : Mul ℚ_[p] := by infer_instance instance : Sub ℚ_[p] := by infer_instance instance : Neg ℚ_[p] := by infer_instance instance : Div ℚ_[p] := by infer_instance instance : AddCommGroup ℚ_[p] := by infer_instance /-- Builds the equivalence class of a Cauchy sequence of rationals. -/ def mk : PadicSeq p → ℚ_[p] := Quotient.mk' #align padic.mk Padic.mk variable (p) theorem zero_def : (0 : ℚ_[p]) = ⟦0⟧ := rfl #align padic.zero_def Padic.zero_def theorem mk_eq {f g : PadicSeq p} : mk f = mk g ↔ f ≈ g := Quotient.eq' #align padic.mk_eq Padic.mk_eq theorem const_equiv {q r : ℚ} : const (padicNorm p) q ≈ const (padicNorm p) r ↔ q = r := ⟨fun heq ↦ eq_of_sub_eq_zero <| const_limZero.1 heq, fun heq ↦ by rw [heq]⟩ #align padic.const_equiv Padic.const_equiv @[norm_cast] theorem coe_inj {q r : ℚ} : (↑q : ℚ_[p]) = ↑r ↔ q = r := ⟨(const_equiv p).1 ∘ Quotient.eq'.1, fun h ↦ by rw [h]⟩ #align padic.coe_inj Padic.coe_inj instance : CharZero ℚ_[p] := ⟨fun m n ↦ by rw [← Rat.cast_natCast] norm_cast exact id⟩ @[norm_cast] theorem coe_add : ∀ {x y : ℚ}, (↑(x + y) : ℚ_[p]) = ↑x + ↑y := Rat.cast_add _ _ #align padic.coe_add Padic.coe_add @[norm_cast] theorem coe_neg : ∀ {x : ℚ}, (↑(-x) : ℚ_[p]) = -↑x := Rat.cast_neg _ #align padic.coe_neg Padic.coe_neg @[norm_cast] theorem coe_mul : ∀ {x y : ℚ}, (↑(x * y) : ℚ_[p]) = ↑x * ↑y := Rat.cast_mul _ _ #align padic.coe_mul Padic.coe_mul @[norm_cast] theorem coe_sub : ∀ {x y : ℚ}, (↑(x - y) : ℚ_[p]) = ↑x - ↑y := Rat.cast_sub _ _ #align padic.coe_sub Padic.coe_sub @[norm_cast] theorem coe_div : ∀ {x y : ℚ}, (↑(x / y) : ℚ_[p]) = ↑x / ↑y := Rat.cast_div _ _ #align padic.coe_div Padic.coe_div @[norm_cast] theorem coe_one : (↑(1 : ℚ) : ℚ_[p]) = 1 := rfl #align padic.coe_one Padic.coe_one @[norm_cast] theorem coe_zero : (↑(0 : ℚ) : ℚ_[p]) = 0 := rfl #align padic.coe_zero Padic.coe_zero end Completion end Padic /-- The rational-valued `p`-adic norm on `ℚ_[p]` is lifted from the norm on Cauchy sequences. The canonical form of this function is the normed space instance, with notation `‖ ‖`. -/ def padicNormE {p : ℕ} [hp : Fact p.Prime] : AbsoluteValue ℚ_[p] ℚ where toFun := Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _ map_mul' q r := Quotient.inductionOn₂ q r <| PadicSeq.norm_mul nonneg' q := Quotient.inductionOn q <| PadicSeq.norm_nonneg eq_zero' q := Quotient.inductionOn q fun r ↦ by rw [Padic.zero_def, Quotient.eq] exact PadicSeq.norm_zero_iff r add_le' q r := by trans max ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) q) ((Quotient.lift PadicSeq.norm <| @PadicSeq.norm_equiv _ _) r) · exact Quotient.inductionOn₂ q r <| PadicSeq.norm_nonarchimedean refine max_le_add_of_nonneg (Quotient.inductionOn q <| PadicSeq.norm_nonneg) ?_ exact Quotient.inductionOn r <| PadicSeq.norm_nonneg #align padic_norm_e padicNormE namespace padicNormE section Embedding open PadicSeq variable {p : ℕ} [Fact p.Prime] -- Porting note: Expanded `⟦f⟧` to `Padic.mk f` theorem defn (f : PadicSeq p) {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padicNormE (Padic.mk f - f i : ℚ_[p]) < ε := by dsimp [padicNormE] change ∃ N, ∀ i ≥ N, (f - const _ (f i)).norm < ε by_contra! h cases' cauchy₂ f hε with N hN rcases h N with ⟨i, hi, hge⟩ have hne : ¬f - const (padicNorm p) (f i) ≈ 0 := fun h ↦ by rw [PadicSeq.norm, dif_pos h] at hge exact not_lt_of_ge hge hε unfold PadicSeq.norm at hge; split_ifs at hge · exact not_le_of_gt hε hge apply not_le_of_gt _ hge cases' _root_.em (N ≤ stationaryPoint hne) with hgen hngen · apply hN _ hgen _ hi · have := stationaryPoint_spec hne le_rfl (le_of_not_le hngen) rw [← this] exact hN _ le_rfl _ hi #align padic_norm_e.defn padicNormE.defn /-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the equivalent theorems about `norm` (`‖ ‖`). -/ theorem nonarchimedean' (q r : ℚ_[p]) : padicNormE (q + r : ℚ_[p]) ≤ max (padicNormE q) (padicNormE r) := Quotient.inductionOn₂ q r <| norm_nonarchimedean #align padic_norm_e.nonarchimedean' padicNormE.nonarchimedean' /-- Theorems about `padicNormE` are named with a `'` so the names do not conflict with the equivalent theorems about `norm` (`‖ ‖`). -/ theorem add_eq_max_of_ne' {q r : ℚ_[p]} : padicNormE q ≠ padicNormE r → padicNormE (q + r : ℚ_[p]) = max (padicNormE q) (padicNormE r) := Quotient.inductionOn₂ q r fun _ _ ↦ PadicSeq.add_eq_max_of_ne #align padic_norm_e.add_eq_max_of_ne' padicNormE.add_eq_max_of_ne' @[simp] theorem eq_padic_norm' (q : ℚ) : padicNormE (q : ℚ_[p]) = padicNorm p q := norm_const _ #align padic_norm_e.eq_padic_norm' padicNormE.eq_padic_norm' protected theorem image' {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, padicNormE q = (p : ℚ) ^ (-n) := Quotient.inductionOn q fun f hf ↦ have : ¬f ≈ 0 := (ne_zero_iff_nequiv_zero f).1 hf norm_values_discrete f this #align padic_norm_e.image' padicNormE.image' end Embedding end padicNormE namespace Padic section Complete open PadicSeq Padic variable {p : ℕ} [Fact p.Prime] (f : CauSeq _ (@padicNormE p _)) theorem rat_dense' (q : ℚ_[p]) {ε : ℚ} (hε : 0 < ε) : ∃ r : ℚ, padicNormE (q - r : ℚ_[p]) < ε := Quotient.inductionOn q fun q' ↦ have : ∃ N, ∀ m ≥ N, ∀ n ≥ N, padicNorm p (q' m - q' n) < ε := cauchy₂ _ hε let ⟨N, hN⟩ := this ⟨q' N, by dsimp [padicNormE] -- Porting note: `change` → `convert_to` (`change` times out!) -- and add `PadicSeq p` type annotation convert_to PadicSeq.norm (q' - const _ (q' N) : PadicSeq p) < ε cases' Decidable.em (q' - const (padicNorm p) (q' N) ≈ 0) with heq hne' · simpa only [heq, PadicSeq.norm, dif_pos] · simp only [PadicSeq.norm, dif_neg hne'] change padicNorm p (q' _ - q' _) < ε cases' Decidable.em (stationaryPoint hne' ≤ N) with hle hle · -- Porting note: inlined `stationaryPoint_spec` invocation. have := (stationaryPoint_spec hne' le_rfl hle).symm simp only [const_apply, sub_apply, padicNorm.zero, sub_self] at this simpa only [this] · exact hN _ (lt_of_not_ge hle).le _ le_rfl⟩ #align padic.rat_dense' Padic.rat_dense' open scoped Classical private theorem div_nat_pos (n : ℕ) : 0 < 1 / (n + 1 : ℚ) := div_pos zero_lt_one (mod_cast succ_pos _) /-- `limSeq f`, for `f` a Cauchy sequence of `p`-adic numbers, is a sequence of rationals with the same limit point as `f`. -/ def limSeq : ℕ → ℚ := fun n ↦ Classical.choose (rat_dense' (f n) (div_nat_pos n)) #align padic.lim_seq Padic.limSeq theorem exi_rat_seq_conv {ε : ℚ} (hε : 0 < ε) : ∃ N, ∀ i ≥ N, padicNormE (f i - (limSeq f i : ℚ_[p]) : ℚ_[p]) < ε := by refine (exists_nat_gt (1 / ε)).imp fun N hN i hi ↦ ?_ have h := Classical.choose_spec (rat_dense' (f i) (div_nat_pos i)) refine lt_of_lt_of_le h ((div_le_iff' <| mod_cast succ_pos _).mpr ?_) rw [right_distrib] apply le_add_of_le_of_nonneg · exact (div_le_iff hε).mp (le_trans (le_of_lt hN) (mod_cast hi)) · apply le_of_lt simpa #align padic.exi_rat_seq_conv Padic.exi_rat_seq_conv theorem exi_rat_seq_conv_cauchy : IsCauSeq (padicNorm p) (limSeq f) := fun ε hε ↦ by have hε3 : 0 < ε / 3 := div_pos hε (by norm_num) let ⟨N, hN⟩ := exi_rat_seq_conv f hε3 let ⟨N2, hN2⟩ := f.cauchy₂ hε3 exists max N N2 intro j hj suffices padicNormE (limSeq f j - f (max N N2) + (f (max N N2) - limSeq f (max N N2)) : ℚ_[p]) < ε by ring_nf at this ⊢ rw [← padicNormE.eq_padic_norm'] exact mod_cast this apply lt_of_le_of_lt · apply padicNormE.add_le · rw [← add_thirds ε] apply _root_.add_lt_add · suffices padicNormE (limSeq f j - f j + (f j - f (max N N2)) : ℚ_[p]) < ε / 3 + ε / 3 by simpa only [sub_add_sub_cancel] apply lt_of_le_of_lt · apply padicNormE.add_le · apply _root_.add_lt_add · rw [padicNormE.map_sub] apply mod_cast hN j exact le_of_max_le_left hj · exact hN2 _ (le_of_max_le_right hj) _ (le_max_right _ _) · apply mod_cast hN (max N N2) apply le_max_left #align padic.exi_rat_seq_conv_cauchy Padic.exi_rat_seq_conv_cauchy private def lim' : PadicSeq p := ⟨_, exi_rat_seq_conv_cauchy f⟩ private def lim : ℚ_[p] := ⟦lim' f⟧ theorem complete' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (q - f i : ℚ_[p]) < ε := ⟨lim f, fun ε hε ↦ by obtain ⟨N, hN⟩ := exi_rat_seq_conv f (half_pos hε) obtain ⟨N2, hN2⟩ := padicNormE.defn (lim' f) (half_pos hε) refine ⟨max N N2, fun i hi ↦ ?_⟩ rw [← sub_add_sub_cancel _ (lim' f i : ℚ_[p]) _] refine (padicNormE.add_le _ _).trans_lt ?_ rw [← add_halves ε] apply _root_.add_lt_add · apply hN2 _ (le_of_max_le_right hi) · rw [padicNormE.map_sub] exact hN _ (le_of_max_le_left hi)⟩ #align padic.complete' Padic.complete' theorem complete'' : ∃ q : ℚ_[p], ∀ ε > 0, ∃ N, ∀ i ≥ N, padicNormE (f i - q : ℚ_[p]) < ε := by obtain ⟨x, hx⟩ := complete' f refine ⟨x, fun ε hε => ?_⟩ obtain ⟨N, hN⟩ := hx ε hε refine ⟨N, fun i hi => ?_⟩ rw [padicNormE.map_sub] exact hN i hi end Complete section NormedSpace variable (p : ℕ) [Fact p.Prime] instance : Dist ℚ_[p] := ⟨fun x y ↦ padicNormE (x - y : ℚ_[p])⟩ instance metricSpace : MetricSpace ℚ_[p] where dist_self := by simp [dist] dist := dist dist_comm x y := by simp [dist, ← padicNormE.map_neg (x - y : ℚ_[p])] dist_triangle x y z := by dsimp [dist] exact mod_cast padicNormE.sub_le x y z eq_of_dist_eq_zero := by dsimp [dist]; intro _ _ h apply eq_of_sub_eq_zero apply padicNormE.eq_zero.1 exact mod_cast h -- Porting note: added because autoparam was not ported edist_dist := by intros; exact (ENNReal.ofReal_eq_coe_nnreal _).symm instance : Norm ℚ_[p] := ⟨fun x ↦ padicNormE x⟩ instance normedField : NormedField ℚ_[p] := { Padic.field, Padic.metricSpace p with dist_eq := fun _ _ ↦ rfl norm_mul' := by simp [Norm.norm, map_mul] norm := norm } instance isAbsoluteValue : IsAbsoluteValue fun a : ℚ_[p] ↦ ‖a‖ where abv_nonneg' := norm_nonneg abv_eq_zero' := norm_eq_zero abv_add' := norm_add_le abv_mul' := by simp [Norm.norm, map_mul] #align padic.is_absolute_value Padic.isAbsoluteValue theorem rat_dense (q : ℚ_[p]) {ε : ℝ} (hε : 0 < ε) : ∃ r : ℚ, ‖q - r‖ < ε := let ⟨ε', hε'l, hε'r⟩ := exists_rat_btwn hε let ⟨r, hr⟩ := rat_dense' q (ε := ε') (by simpa using hε'l) ⟨r, lt_trans (by simpa [Norm.norm] using hr) hε'r⟩ #align padic.rat_dense Padic.rat_dense end NormedSpace end Padic namespace padicNormE section NormedSpace variable {p : ℕ} [hp : Fact p.Prime] -- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned @[simp (high)] protected theorem mul (q r : ℚ_[p]) : ‖q * r‖ = ‖q‖ * ‖r‖ := by simp [Norm.norm, map_mul] #align padic_norm_e.mul padicNormE.mul protected theorem is_norm (q : ℚ_[p]) : ↑(padicNormE q) = ‖q‖ := rfl #align padic_norm_e.is_norm padicNormE.is_norm theorem nonarchimedean (q r : ℚ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := by dsimp [norm] exact mod_cast nonarchimedean' _ _ #align padic_norm_e.nonarchimedean padicNormE.nonarchimedean theorem add_eq_max_of_ne {q r : ℚ_[p]} (h : ‖q‖ ≠ ‖r‖) : ‖q + r‖ = max ‖q‖ ‖r‖ := by dsimp [norm] at h ⊢ have : padicNormE q ≠ padicNormE r := mod_cast h exact mod_cast add_eq_max_of_ne' this #align padic_norm_e.add_eq_max_of_ne padicNormE.add_eq_max_of_ne @[simp] theorem eq_padicNorm (q : ℚ) : ‖(q : ℚ_[p])‖ = padicNorm p q := by dsimp [norm] rw [← padicNormE.eq_padic_norm'] #align padic_norm_e.eq_padic_norm padicNormE.eq_padicNorm @[simp] theorem norm_p : ‖(p : ℚ_[p])‖ = (p : ℝ)⁻¹ := by rw [← @Rat.cast_natCast ℝ _ p] rw [← @Rat.cast_natCast ℚ_[p] _ p] simp [hp.1.ne_zero, hp.1.ne_one, norm, padicNorm, padicValRat, padicValInt, zpow_neg, -Rat.cast_natCast] #align padic_norm_e.norm_p padicNormE.norm_p theorem norm_p_lt_one : ‖(p : ℚ_[p])‖ < 1 := by rw [norm_p] apply inv_lt_one exact mod_cast hp.1.one_lt #align padic_norm_e.norm_p_lt_one padicNormE.norm_p_lt_one -- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned @[simp (high)] theorem norm_p_zpow (n : ℤ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n) := by rw [norm_zpow, norm_p, zpow_neg, inv_zpow] #align padic_norm_e.norm_p_zpow padicNormE.norm_p_zpow -- Porting note: Linter thinks this is a duplicate simp lemma, so `priority` is assigned @[simp (high)] theorem norm_p_pow (n : ℕ) : ‖(p : ℚ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by rw [← norm_p_zpow, zpow_natCast] #align padic_norm_e.norm_p_pow padicNormE.norm_p_pow instance : NontriviallyNormedField ℚ_[p] := { Padic.normedField p with non_trivial := ⟨p⁻¹, by rw [norm_inv, norm_p, inv_inv] exact mod_cast hp.1.one_lt⟩ } protected theorem image {q : ℚ_[p]} : q ≠ 0 → ∃ n : ℤ, ‖q‖ = ↑((p : ℚ) ^ (-n)) := Quotient.inductionOn q fun f hf ↦ have : ¬f ≈ 0 := (PadicSeq.ne_zero_iff_nequiv_zero f).1 hf let ⟨n, hn⟩ := PadicSeq.norm_values_discrete f this ⟨n, by rw [← hn]; rfl⟩ #align padic_norm_e.image padicNormE.image protected theorem is_rat (q : ℚ_[p]) : ∃ q' : ℚ, ‖q‖ = q' := if h : q = 0 then ⟨0, by simp [h]⟩ else let ⟨n, hn⟩ := padicNormE.image h ⟨_, hn⟩ #align padic_norm_e.is_rat padicNormE.is_rat /-- `ratNorm q`, for a `p`-adic number `q` is the `p`-adic norm of `q`, as rational number. The lemma `padicNormE.eq_ratNorm` asserts `‖q‖ = ratNorm q`. -/ def ratNorm (q : ℚ_[p]) : ℚ := Classical.choose (padicNormE.is_rat q) #align padic_norm_e.rat_norm padicNormE.ratNorm theorem eq_ratNorm (q : ℚ_[p]) : ‖q‖ = ratNorm q := Classical.choose_spec (padicNormE.is_rat q) #align padic_norm_e.eq_rat_norm padicNormE.eq_ratNorm theorem norm_rat_le_one : ∀ {q : ℚ} (_ : ¬p ∣ q.den), ‖(q : ℚ_[p])‖ ≤ 1 | ⟨n, d, hn, hd⟩ => fun hq : ¬p ∣ d ↦ if hnz : n = 0 then by have : (⟨n, d, hn, hd⟩ : ℚ) = 0 := Rat.zero_iff_num_zero.mpr hnz set_option tactic.skipAssignedInstances false in norm_num [this] else by have hnz' : (⟨n, d, hn, hd⟩ : ℚ) ≠ 0 := mt Rat.zero_iff_num_zero.1 hnz rw [padicNormE.eq_padicNorm] norm_cast -- Porting note: `Nat.cast_zero` instead of another `norm_cast` call rw [padicNorm.eq_zpow_of_nonzero hnz', padicValRat, neg_sub, padicValNat.eq_zero_of_not_dvd hq, Nat.cast_zero, zero_sub, zpow_neg, zpow_natCast] apply inv_le_one norm_cast apply one_le_pow exact hp.1.pos #align padic_norm_e.norm_rat_le_one padicNormE.norm_rat_le_one theorem norm_int_le_one (z : ℤ) : ‖(z : ℚ_[p])‖ ≤ 1 := suffices ‖((z : ℚ) : ℚ_[p])‖ ≤ 1 by simpa norm_rat_le_one <| by simp [hp.1.ne_one] #align padic_norm_e.norm_int_le_one padicNormE.norm_int_le_one theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k := by constructor · intro h contrapose! h apply le_of_eq rw [eq_comm] calc ‖(k : ℚ_[p])‖ = ‖((k : ℚ) : ℚ_[p])‖ := by norm_cast _ = padicNorm p k := padicNormE.eq_padicNorm _ _ = 1 := mod_cast (int_eq_one_iff k).mpr h · rintro ⟨x, rfl⟩ push_cast rw [padicNormE.mul] calc _ ≤ ‖(p : ℚ_[p])‖ * 1 := mul_le_mul le_rfl (by simpa using norm_int_le_one _) (norm_nonneg _) (norm_nonneg _) _ < 1 := by rw [mul_one, padicNormE.norm_p] apply inv_lt_one exact mod_cast hp.1.one_lt #align padic_norm_e.norm_int_lt_one_iff_dvd padicNormE.norm_int_lt_one_iff_dvd theorem norm_int_le_pow_iff_dvd (k : ℤ) (n : ℕ) : ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k := by have : (p : ℝ) ^ (-n : ℤ) = (p : ℚ) ^ (-n : ℤ) := by simp rw [show (k : ℚ_[p]) = ((k : ℚ) : ℚ_[p]) by norm_cast, eq_padicNorm, this] norm_cast rw [← padicNorm.dvd_iff_norm_le] #align padic_norm_e.norm_int_le_pow_iff_dvd padicNormE.norm_int_le_pow_iff_dvd theorem eq_of_norm_add_lt_right {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ := _root_.by_contradiction fun hne ↦ not_lt_of_ge (by rw [padicNormE.add_eq_max_of_ne hne]; apply le_max_right) h #align padic_norm_e.eq_of_norm_add_lt_right padicNormE.eq_of_norm_add_lt_right theorem eq_of_norm_add_lt_left {z1 z2 : ℚ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ := _root_.by_contradiction fun hne ↦ not_lt_of_ge (by rw [padicNormE.add_eq_max_of_ne hne]; apply le_max_left) h #align padic_norm_e.eq_of_norm_add_lt_left padicNormE.eq_of_norm_add_lt_left end NormedSpace end padicNormE namespace Padic variable {p : ℕ} [hp : Fact p.Prime] -- Porting note: remove `set_option eqn_compiler.zeta true` instance complete : CauSeq.IsComplete ℚ_[p] norm where isComplete f := by have cau_seq_norm_e : IsCauSeq padicNormE f := fun ε hε => by have h := isCauSeq f ε (mod_cast hε) dsimp [norm] at h exact mod_cast h -- Porting note: Padic.complete' works with `f i - q`, but the goal needs `q - f i`, -- using `rewrite [padicNormE.map_sub]` causes time out, so a separate lemma is created cases' Padic.complete'' ⟨f, cau_seq_norm_e⟩ with q hq exists q intro ε hε cases' exists_rat_btwn hε with ε' hε' norm_cast at hε' cases' hq ε' hε'.1 with N hN exists N intro i hi have h := hN i hi change norm (f i - q) < ε refine lt_trans ?_ hε'.2 dsimp [norm] exact mod_cast h #align padic.complete Padic.complete theorem padicNormE_lim_le {f : CauSeq ℚ_[p] norm} {a : ℝ} (ha : 0 < a) (hf : ∀ i, ‖f i‖ ≤ a) : ‖f.lim‖ ≤ a := by -- Porting note: `Setoid.symm` cannot work out which `Setoid` to use, so instead swap the order -- now, I use a rewrite to swap it later obtain ⟨N, hN⟩ := (CauSeq.equiv_lim f) _ ha rw [← sub_add_cancel f.lim (f N)] refine le_trans (padicNormE.nonarchimedean _ _) ?_ rw [norm_sub_rev] exact max_le (le_of_lt (hN _ le_rfl)) (hf _) -- Porting note: the following nice `calc` block does not work -- exact calc -- ‖f.lim‖ = ‖f.lim - f N + f N‖ := sorry -- ‖f.lim - f N + f N‖ ≤ max ‖f.lim - f N‖ ‖f N‖ := sorry -- (padicNormE.nonarchimedean _ _) -- max ‖f.lim - f N‖ ‖f N‖ = max ‖f N - f.lim‖ ‖f N‖ := sorry -- by congr; rw [norm_sub_rev] -- max ‖f N - f.lim‖ ‖f N‖ ≤ a := sorry -- max_le (le_of_lt (hN _ le_rfl)) (hf _) #align padic.padic_norm_e_lim_le Padic.padicNormE_lim_le open Filter Set instance : CompleteSpace ℚ_[p] := by apply complete_of_cauchySeq_tendsto intro u hu let c : CauSeq ℚ_[p] norm := ⟨u, Metric.cauchySeq_iff'.mp hu⟩ refine ⟨c.lim, fun s h ↦ ?_⟩ rcases Metric.mem_nhds_iff.1 h with ⟨ε, ε0, hε⟩ have := c.equiv_lim ε ε0 simp only [mem_map, mem_atTop_sets, mem_setOf_eq] exact this.imp fun N hN n hn ↦ hε (hN n hn) /-! ### Valuation on `ℚ_[p]` -/ /-- `Padic.valuation` lifts the `p`-adic valuation on rationals to `ℚ_[p]`. -/ def valuation : ℚ_[p] → ℤ := Quotient.lift (@PadicSeq.valuation p _) fun f g h ↦ by by_cases hf : f ≈ 0 · have hg : g ≈ 0 := Setoid.trans (Setoid.symm h) hf simp [hf, hg, PadicSeq.valuation] · have hg : ¬g ≈ 0 := fun hg ↦ hf (Setoid.trans h hg) rw [PadicSeq.val_eq_iff_norm_eq hf hg] exact PadicSeq.norm_equiv h #align padic.valuation Padic.valuation @[simp] theorem valuation_zero : valuation (0 : ℚ_[p]) = 0 := dif_pos ((const_equiv p).2 rfl) #align padic.valuation_zero Padic.valuation_zero @[simp] theorem valuation_one : valuation (1 : ℚ_[p]) = 0 := by change dite (CauSeq.const (padicNorm p) 1 ≈ _) _ _ = _ have h : ¬CauSeq.const (padicNorm p) 1 ≈ 0 := by intro H erw [const_equiv p] at H exact one_ne_zero H rw [dif_neg h] simp #align padic.valuation_one Padic.valuation_one theorem norm_eq_pow_val {x : ℚ_[p]} : x ≠ 0 → ‖x‖ = (p : ℝ) ^ (-x.valuation) := by refine Quotient.inductionOn' x fun f hf => ?_ change (PadicSeq.norm _ : ℝ) = (p : ℝ) ^ (-PadicSeq.valuation _) rw [PadicSeq.norm_eq_pow_val] · change ↑((p : ℚ) ^ (-PadicSeq.valuation f)) = (p : ℝ) ^ (-PadicSeq.valuation f) rw [Rat.cast_zpow, Rat.cast_natCast] · apply CauSeq.not_limZero_of_not_congr_zero -- Porting note: was `contrapose! hf` intro hf' apply hf apply Quotient.sound simpa using hf' #align padic.norm_eq_pow_val Padic.norm_eq_pow_val @[simp] theorem valuation_p : valuation (p : ℚ_[p]) = 1 := by have h : (1 : ℝ) < p := mod_cast (Fact.out : p.Prime).one_lt refine neg_injective ((zpow_strictMono h).injective <| (norm_eq_pow_val ?_).symm.trans ?_) · exact mod_cast (Fact.out : p.Prime).ne_zero · simp #align padic.valuation_p Padic.valuation_p
Mathlib/NumberTheory/Padics/PadicNumbers.lean
1,072
1,085
theorem valuation_map_add {x y : ℚ_[p]} (hxy : x + y ≠ 0) : min (valuation x) (valuation y) ≤ valuation (x + y : ℚ_[p]) := by
by_cases hx : x = 0 · rw [hx, zero_add] exact min_le_right _ _ · by_cases hy : y = 0 · rw [hy, add_zero] exact min_le_left _ _ · have h_norm : ‖x + y‖ ≤ max ‖x‖ ‖y‖ := padicNormE.nonarchimedean x y have hp_one : (1 : ℝ) < p := by rw [← Nat.cast_one, Nat.cast_lt] exact Nat.Prime.one_lt hp.elim rwa [norm_eq_pow_val hx, norm_eq_pow_val hy, norm_eq_pow_val hxy, zpow_le_max_iff_min_le hp_one] at h_norm
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Ring.Hom.Basic import Mathlib.Algebra.Ring.Int import Mathlib.Data.Nat.Cast.Basic import Mathlib.Data.Nat.Cast.Commute #align_import data.int.cast.lemmas from "leanprover-community/mathlib"@"acebd8d49928f6ed8920e502a6c90674e75bd441" /-! # Cast of integers (additional theorems) This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`), particularly results involving algebraic homomorphisms or the order structure on `ℤ` which were not available in the import dependencies of `Data.Int.Cast.Basic`. ## Main declarations * `castAddHom`: `cast` bundled as an `AddMonoidHom`. * `castRingHom`: `cast` bundled as a `RingHom`. -/ assert_not_exists OrderedCommMonoid open Additive Function Multiplicative Nat variable {F ι α β : Type*} namespace Int /-- Coercion `ℕ → ℤ` as a `RingHom`. -/ def ofNatHom : ℕ →+* ℤ := Nat.castRingHom ℤ #align int.of_nat_hom Int.ofNatHom section cast @[simp, norm_cast] theorem cast_ite [AddGroupWithOne α] (P : Prop) [Decidable P] (m n : ℤ) : ((ite P m n : ℤ) : α) = ite P (m : α) (n : α) := apply_ite _ _ _ _ #align int.cast_ite Int.cast_ite /-- `coe : ℤ → α` as an `AddMonoidHom`. -/ def castAddHom (α : Type*) [AddGroupWithOne α] : ℤ →+ α where toFun := Int.cast map_zero' := cast_zero map_add' := cast_add #align int.cast_add_hom Int.castAddHom section AddGroupWithOne variable [AddGroupWithOne α] @[simp] lemma coe_castAddHom : ⇑(castAddHom α) = fun x : ℤ => (x : α) := rfl #align int.coe_cast_add_hom Int.coe_castAddHom lemma _root_.Even.intCast {n : ℤ} (h : Even n) : Even (n : α) := h.map (castAddHom α) variable [CharZero α] {m n : ℤ} @[simp] lemma cast_eq_zero : (n : α) = 0 ↔ n = 0 where mp h := by cases n · erw [Int.cast_natCast] at h exact congr_arg _ (Nat.cast_eq_zero.1 h) · rw [cast_negSucc, neg_eq_zero, Nat.cast_eq_zero] at h contradiction mpr h := by rw [h, cast_zero] #align int.cast_eq_zero Int.cast_eq_zero @[simp, norm_cast] lemma cast_inj : (m : α) = n ↔ m = n := by rw [← sub_eq_zero, ← cast_sub, cast_eq_zero, sub_eq_zero] #align int.cast_inj Int.cast_inj lemma cast_injective : Injective (Int.cast : ℤ → α) := fun _ _ ↦ cast_inj.1 #align int.cast_injective Int.cast_injective lemma cast_ne_zero : (n : α) ≠ 0 ↔ n ≠ 0 := not_congr cast_eq_zero #align int.cast_ne_zero Int.cast_ne_zero @[simp] lemma cast_eq_one : (n : α) = 1 ↔ n = 1 := by rw [← cast_one, cast_inj] #align int.cast_eq_one Int.cast_eq_one lemma cast_ne_one : (n : α) ≠ 1 ↔ n ≠ 1 := cast_eq_one.not #align int.cast_ne_one Int.cast_ne_one end AddGroupWithOne section NonAssocRing variable [NonAssocRing α] {a b : α} {n : ℤ} variable (α) in /-- `coe : ℤ → α` as a `RingHom`. -/ def castRingHom : ℤ →+* α where toFun := Int.cast map_zero' := cast_zero map_add' := cast_add map_one' := cast_one map_mul' := cast_mul #align int.cast_ring_hom Int.castRingHom @[simp] lemma coe_castRingHom : ⇑(castRingHom α) = fun x : ℤ ↦ (x : α) := rfl #align int.coe_cast_ring_hom Int.coe_castRingHom lemma cast_commute : ∀ (n : ℤ) (a : α), Commute ↑n a | (n : ℕ), x => by simpa using n.cast_commute x | -[n+1], x => by simpa only [cast_negSucc, Commute.neg_left_iff, Commute.neg_right_iff] using (n + 1).cast_commute (-x) #align int.cast_commute Int.cast_commute lemma cast_comm (n : ℤ) (x : α) : n * x = x * n := (cast_commute ..).eq #align int.cast_comm Int.cast_comm lemma commute_cast (a : α) (n : ℤ) : Commute a n := (cast_commute ..).symm #align int.commute_cast Int.commute_cast @[simp] lemma _root_.zsmul_eq_mul (a : α) : ∀ n : ℤ, n • a = n * a | (n : ℕ) => by rw [natCast_zsmul, nsmul_eq_mul, Int.cast_natCast] | -[n+1] => by simp [Nat.cast_succ, neg_add_rev, Int.cast_negSucc, add_mul] #align zsmul_eq_mul zsmul_eq_mul lemma _root_.zsmul_eq_mul' (a : α) (n : ℤ) : n • a = a * n := by rw [zsmul_eq_mul, (n.cast_commute a).eq] #align zsmul_eq_mul' zsmul_eq_mul' end NonAssocRing section Ring variable [Ring α] {n : ℤ} lemma _root_.Odd.intCast (hn : Odd n) : Odd (n : α) := hn.map (castRingHom α) end Ring theorem cast_dvd_cast [CommRing α] (m n : ℤ) (h : m ∣ n) : (m : α) ∣ (n : α) := RingHom.map_dvd (Int.castRingHom α) h #align int.cast_dvd Int.cast_dvd_cast @[deprecated (since := "2024-05-25")] alias coe_int_dvd := cast_dvd_cast end cast end Int open Int namespace SemiconjBy variable [Ring α] {a x y : α} @[simp] lemma intCast_mul_right (h : SemiconjBy a x y) (n : ℤ) : SemiconjBy a (n * x) (n * y) := SemiconjBy.mul_right (Int.commute_cast _ _) h #align semiconj_by.cast_int_mul_right SemiconjBy.intCast_mul_right @[simp] lemma intCast_mul_left (h : SemiconjBy a x y) (n : ℤ) : SemiconjBy (n * a) x y := SemiconjBy.mul_left (Int.cast_commute _ _) h #align semiconj_by.cast_int_mul_left SemiconjBy.intCast_mul_left @[simp] lemma intCast_mul_intCast_mul (h : SemiconjBy a x y) (m n : ℤ) : SemiconjBy (m * a) (n * x) (n * y) := (h.intCast_mul_left m).intCast_mul_right n #align semiconj_by.cast_int_mul_cast_int_mul SemiconjBy.intCast_mul_intCast_mul @[deprecated (since := "2024-05-27")] alias cast_int_mul_right := intCast_mul_right @[deprecated (since := "2024-05-27")] alias cast_int_mul_left := intCast_mul_left @[deprecated (since := "2024-05-27")] alias cast_int_mul_cast_int_mul := intCast_mul_intCast_mul end SemiconjBy namespace Commute section NonAssocRing variable [NonAssocRing α] {a b : α} {n : ℤ} @[simp] lemma intCast_left : Commute (n : α) a := Int.cast_commute _ _ #align commute.cast_int_left Commute.intCast_left @[simp] lemma intCast_right : Commute a n := Int.commute_cast _ _ #align commute.cast_int_right Commute.intCast_right @[deprecated (since := "2024-05-27")] alias cast_int_right := intCast_right @[deprecated (since := "2024-05-27")] alias cast_int_left := intCast_left end NonAssocRing section Ring variable [Ring α] {a b : α} {n : ℤ} @[simp] lemma intCast_mul_right (h : Commute a b) (m : ℤ) : Commute a (m * b) := SemiconjBy.intCast_mul_right h m #align commute.cast_int_mul_right Commute.intCast_mul_right @[simp] lemma intCast_mul_left (h : Commute a b) (m : ℤ) : Commute (m * a) b := SemiconjBy.intCast_mul_left h m #align commute.cast_int_mul_left Commute.intCast_mul_left lemma intCast_mul_intCast_mul (h : Commute a b) (m n : ℤ) : Commute (m * a) (n * b) := SemiconjBy.intCast_mul_intCast_mul h m n #align commute.cast_int_mul_cast_int_mul Commute.intCast_mul_intCast_mul variable (a) (m n : ℤ) /- Porting note (#10618): `simp` attribute removed as linter reports: simp can prove this: by simp only [Commute.cast_int_right, Commute.refl, Commute.mul_right] -/ -- @[simp] lemma self_intCast_mul : Commute a (n * a : α) := (Commute.refl a).intCast_mul_right n #align commute.self_cast_int_mul Commute.self_intCast_mul /- Porting note (#10618): `simp` attribute removed as linter reports: simp can prove this: by simp only [Commute.cast_int_left, Commute.refl, Commute.mul_left] -/ -- @[simp] lemma intCast_mul_self : Commute ((n : α) * a) a := (Commute.refl a).intCast_mul_left n #align commute.cast_int_mul_self Commute.intCast_mul_self lemma self_intCast_mul_intCast_mul : Commute (m * a : α) (n * a : α) := (Commute.refl a).intCast_mul_intCast_mul m n #align commute.self_cast_int_mul_cast_int_mul Commute.self_intCast_mul_intCast_mul @[deprecated (since := "2024-05-27")] alias cast_int_mul_right := intCast_mul_right @[deprecated (since := "2024-05-27")] alias cast_int_mul_left := intCast_mul_left @[deprecated (since := "2024-05-27")] alias cast_int_mul_cast_int_mul := intCast_mul_intCast_mul @[deprecated (since := "2024-05-27")] alias self_cast_int_mul := self_intCast_mul @[deprecated (since := "2024-05-27")] alias cast_int_mul_self := intCast_mul_self @[deprecated (since := "2024-05-27")] alias self_cast_int_mul_cast_int_mul := self_intCast_mul_intCast_mul end Ring end Commute namespace AddMonoidHom variable {A : Type*} /-- Two additive monoid homomorphisms `f`, `g` from `ℤ` to an additive monoid are equal if `f 1 = g 1`. -/ @[ext high] theorem ext_int [AddMonoid A] {f g : ℤ →+ A} (h1 : f 1 = g 1) : f = g := have : f.comp (Int.ofNatHom : ℕ →+ ℤ) = g.comp (Int.ofNatHom : ℕ →+ ℤ) := ext_nat' _ _ h1 have this' : ∀ n : ℕ, f n = g n := DFunLike.ext_iff.1 this ext fun n => match n with | (n : ℕ) => this' n | .negSucc n => eq_on_neg _ _ (this' <| n + 1) #align add_monoid_hom.ext_int AddMonoidHom.ext_int variable [AddGroupWithOne A] theorem eq_intCastAddHom (f : ℤ →+ A) (h1 : f 1 = 1) : f = Int.castAddHom A := ext_int <| by simp [h1] #align add_monoid_hom.eq_int_cast_hom AddMonoidHom.eq_intCastAddHom @[deprecated (since := "2024-04-17")] alias eq_int_castAddHom := eq_intCastAddHom end AddMonoidHom theorem eq_intCast' [AddGroupWithOne α] [FunLike F ℤ α] [AddMonoidHomClass F ℤ α] (f : F) (h₁ : f 1 = 1) : ∀ n : ℤ, f n = n := DFunLike.ext_iff.1 <| (f : ℤ →+ α).eq_intCastAddHom h₁ #align eq_int_cast' eq_intCast' @[simp] lemma zsmul_one [AddGroupWithOne α] (n : ℤ) : n • (1 : α) = n := by cases n <;> simp #align zsmul_one zsmul_one @[simp] theorem Int.castAddHom_int : Int.castAddHom ℤ = AddMonoidHom.id ℤ := ((AddMonoidHom.id ℤ).eq_intCastAddHom rfl).symm #align int.cast_add_hom_int Int.castAddHom_int namespace MonoidHom variable {M : Type*} [Monoid M] open Multiplicative @[ext] theorem ext_mint {f g : Multiplicative ℤ →* M} (h1 : f (ofAdd 1) = g (ofAdd 1)) : f = g := MonoidHom.toAdditive''.injective <| AddMonoidHom.ext_int <| Additive.toMul.injective h1 #align monoid_hom.ext_mint MonoidHom.ext_mint /-- If two `MonoidHom`s agree on `-1` and the naturals then they are equal. -/ @[ext]
Mathlib/Data/Int/Cast/Lemmas.lean
289
295
theorem ext_int {f g : ℤ →* M} (h_neg_one : f (-1) = g (-1)) (h_nat : f.comp Int.ofNatHom.toMonoidHom = g.comp Int.ofNatHom.toMonoidHom) : f = g := by
ext (x | x) · exact (DFunLike.congr_fun h_nat x : _) · rw [Int.negSucc_eq, ← neg_one_mul, f.map_mul, g.map_mul] congr 1 exact mod_cast (DFunLike.congr_fun h_nat (x + 1) : _)
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Normed.Group.Hom import Mathlib.Analysis.NormedSpace.Basic import Mathlib.Analysis.NormedSpace.LinearIsometry import Mathlib.Algebra.Star.SelfAdjoint import Mathlib.Algebra.Star.Subalgebra import Mathlib.Algebra.Star.Unitary import Mathlib.Topology.Algebra.Module.Star #align_import analysis.normed_space.star.basic from "leanprover-community/mathlib"@"aa6669832974f87406a3d9d70fc5707a60546207" /-! # Normed star rings and algebras A normed star group is a normed group with a compatible `star` which is isometric. A C⋆-ring is a normed star group that is also a ring and that verifies the stronger condition `‖x⋆ * x‖ = ‖x‖^2` for all `x`. If a C⋆-ring is also a star algebra, then it is a C⋆-algebra. To get a C⋆-algebra `E` over field `𝕜`, use `[NormedField 𝕜] [StarRing 𝕜] [NormedRing E] [StarRing E] [CstarRing E] [NormedAlgebra 𝕜 E] [StarModule 𝕜 E]`. ## TODO - Show that `‖x⋆ * x‖ = ‖x‖^2` is equivalent to `‖x⋆ * x‖ = ‖x⋆‖ * ‖x‖`, which is used as the definition of C*-algebras in some sources (e.g. Wikipedia). -/ open Topology local postfix:max "⋆" => star /-- A normed star group is a normed group with a compatible `star` which is isometric. -/ class NormedStarGroup (E : Type*) [SeminormedAddCommGroup E] [StarAddMonoid E] : Prop where norm_star : ∀ x : E, ‖x⋆‖ = ‖x‖ #align normed_star_group NormedStarGroup export NormedStarGroup (norm_star) attribute [simp] norm_star variable {𝕜 E α : Type*} section NormedStarGroup variable [SeminormedAddCommGroup E] [StarAddMonoid E] [NormedStarGroup E] @[simp] theorem nnnorm_star (x : E) : ‖star x‖₊ = ‖x‖₊ := Subtype.ext <| norm_star _ #align nnnorm_star nnnorm_star /-- The `star` map in a normed star group is a normed group homomorphism. -/ def starNormedAddGroupHom : NormedAddGroupHom E E := { starAddEquiv with bound' := ⟨1, fun _ => le_trans (norm_star _).le (one_mul _).symm.le⟩ } #align star_normed_add_group_hom starNormedAddGroupHom /-- The `star` map in a normed star group is an isometry -/ theorem star_isometry : Isometry (star : E → E) := show Isometry starAddEquiv from AddMonoidHomClass.isometry_of_norm starAddEquiv (show ∀ x, ‖x⋆‖ = ‖x‖ from norm_star) #align star_isometry star_isometry instance (priority := 100) NormedStarGroup.to_continuousStar : ContinuousStar E := ⟨star_isometry.continuous⟩ #align normed_star_group.to_has_continuous_star NormedStarGroup.to_continuousStar end NormedStarGroup instance RingHomIsometric.starRingEnd [NormedCommRing E] [StarRing E] [NormedStarGroup E] : RingHomIsometric (starRingEnd E) := ⟨@norm_star _ _ _ _⟩ #align ring_hom_isometric.star_ring_end RingHomIsometric.starRingEnd /-- A C*-ring is a normed star ring that satisfies the stronger condition `‖x⋆ * x‖ = ‖x‖^2` for every `x`. -/ class CstarRing (E : Type*) [NonUnitalNormedRing E] [StarRing E] : Prop where norm_star_mul_self : ∀ {x : E}, ‖x⋆ * x‖ = ‖x‖ * ‖x‖ #align cstar_ring CstarRing instance : CstarRing ℝ where norm_star_mul_self {x} := by simp only [star, id, norm_mul] namespace CstarRing section NonUnital variable [NonUnitalNormedRing E] [StarRing E] [CstarRing E] -- see Note [lower instance priority] /-- In a C*-ring, star preserves the norm. -/ instance (priority := 100) to_normedStarGroup : NormedStarGroup E := ⟨by intro x by_cases htriv : x = 0 · simp only [htriv, star_zero] · have hnt : 0 < ‖x‖ := norm_pos_iff.mpr htriv have hnt_star : 0 < ‖x⋆‖ := norm_pos_iff.mpr ((AddEquiv.map_ne_zero_iff starAddEquiv (M := E)).mpr htriv) have h₁ := calc ‖x‖ * ‖x‖ = ‖x⋆ * x‖ := norm_star_mul_self.symm _ ≤ ‖x⋆‖ * ‖x‖ := norm_mul_le _ _ have h₂ := calc ‖x⋆‖ * ‖x⋆‖ = ‖x * x⋆‖ := by rw [← norm_star_mul_self, star_star] _ ≤ ‖x‖ * ‖x⋆‖ := norm_mul_le _ _ exact le_antisymm (le_of_mul_le_mul_right h₂ hnt_star) (le_of_mul_le_mul_right h₁ hnt)⟩ #align cstar_ring.to_normed_star_group CstarRing.to_normedStarGroup theorem norm_self_mul_star {x : E} : ‖x * x⋆‖ = ‖x‖ * ‖x‖ := by nth_rw 1 [← star_star x] simp only [norm_star_mul_self, norm_star] #align cstar_ring.norm_self_mul_star CstarRing.norm_self_mul_star theorem norm_star_mul_self' {x : E} : ‖x⋆ * x‖ = ‖x⋆‖ * ‖x‖ := by rw [norm_star_mul_self, norm_star] #align cstar_ring.norm_star_mul_self' CstarRing.norm_star_mul_self' theorem nnnorm_self_mul_star {x : E} : ‖x * x⋆‖₊ = ‖x‖₊ * ‖x‖₊ := Subtype.ext norm_self_mul_star #align cstar_ring.nnnorm_self_mul_star CstarRing.nnnorm_self_mul_star theorem nnnorm_star_mul_self {x : E} : ‖x⋆ * x‖₊ = ‖x‖₊ * ‖x‖₊ := Subtype.ext norm_star_mul_self #align cstar_ring.nnnorm_star_mul_self CstarRing.nnnorm_star_mul_self @[simp] theorem star_mul_self_eq_zero_iff (x : E) : x⋆ * x = 0 ↔ x = 0 := by rw [← norm_eq_zero, norm_star_mul_self] exact mul_self_eq_zero.trans norm_eq_zero #align cstar_ring.star_mul_self_eq_zero_iff CstarRing.star_mul_self_eq_zero_iff theorem star_mul_self_ne_zero_iff (x : E) : x⋆ * x ≠ 0 ↔ x ≠ 0 := by simp only [Ne, star_mul_self_eq_zero_iff] #align cstar_ring.star_mul_self_ne_zero_iff CstarRing.star_mul_self_ne_zero_iff @[simp] theorem mul_star_self_eq_zero_iff (x : E) : x * x⋆ = 0 ↔ x = 0 := by simpa only [star_eq_zero, star_star] using @star_mul_self_eq_zero_iff _ _ _ _ (star x) #align cstar_ring.mul_star_self_eq_zero_iff CstarRing.mul_star_self_eq_zero_iff theorem mul_star_self_ne_zero_iff (x : E) : x * x⋆ ≠ 0 ↔ x ≠ 0 := by simp only [Ne, mul_star_self_eq_zero_iff] #align cstar_ring.mul_star_self_ne_zero_iff CstarRing.mul_star_self_ne_zero_iff end NonUnital section ProdPi variable {ι R₁ R₂ : Type*} {R : ι → Type*} variable [NonUnitalNormedRing R₁] [StarRing R₁] [CstarRing R₁] variable [NonUnitalNormedRing R₂] [StarRing R₂] [CstarRing R₂] variable [∀ i, NonUnitalNormedRing (R i)] [∀ i, StarRing (R i)] /-- This instance exists to short circuit type class resolution because of problems with inference involving Π-types. -/ instance _root_.Pi.starRing' : StarRing (∀ i, R i) := inferInstance #align pi.star_ring' Pi.starRing' variable [Fintype ι] [∀ i, CstarRing (R i)] instance _root_.Prod.cstarRing : CstarRing (R₁ × R₂) where norm_star_mul_self {x} := by dsimp only [norm] simp only [Prod.fst_mul, Prod.fst_star, Prod.snd_mul, Prod.snd_star, norm_star_mul_self, ← sq] refine le_antisymm ?_ ?_ · refine max_le ?_ ?_ <;> rw [sq_le_sq, abs_of_nonneg (norm_nonneg _)] · exact (le_max_left _ _).trans (le_abs_self _) · exact (le_max_right _ _).trans (le_abs_self _) · rw [le_sup_iff] rcases le_total ‖x.fst‖ ‖x.snd‖ with (h | h) <;> simp [h] #align prod.cstar_ring Prod.cstarRing instance _root_.Pi.cstarRing : CstarRing (∀ i, R i) where norm_star_mul_self {x} := by simp only [norm, Pi.mul_apply, Pi.star_apply, nnnorm_star_mul_self, ← sq] norm_cast exact (Finset.comp_sup_eq_sup_comp_of_is_total (fun x : NNReal => x ^ 2) (fun x y h => by simpa only [sq] using mul_le_mul' h h) (by simp)).symm #align pi.cstar_ring Pi.cstarRing instance _root_.Pi.cstarRing' : CstarRing (ι → R₁) := Pi.cstarRing #align pi.cstar_ring' Pi.cstarRing' end ProdPi section Unital variable [NormedRing E] [StarRing E] [CstarRing E] @[simp, nolint simpNF] -- Porting note (#10959): simp cannot prove this theorem norm_one [Nontrivial E] : ‖(1 : E)‖ = 1 := by have : 0 < ‖(1 : E)‖ := norm_pos_iff.mpr one_ne_zero rw [← mul_left_inj' this.ne', ← norm_star_mul_self, mul_one, star_one, one_mul] #align cstar_ring.norm_one CstarRing.norm_one -- see Note [lower instance priority] instance (priority := 100) [Nontrivial E] : NormOneClass E := ⟨norm_one⟩
Mathlib/Analysis/NormedSpace/Star/Basic.lean
212
214
theorem norm_coe_unitary [Nontrivial E] (U : unitary E) : ‖(U : E)‖ = 1 := by
rw [← sq_eq_sq (norm_nonneg _) zero_le_one, one_pow 2, sq, ← CstarRing.norm_star_mul_self, unitary.coe_star_mul_self, CstarRing.norm_one]
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Data.Nat.Multiplicity import Mathlib.Data.ZMod.Algebra import Mathlib.RingTheory.WittVector.Basic import Mathlib.RingTheory.WittVector.IsPoly import Mathlib.FieldTheory.Perfect #align_import ring_theory.witt_vector.frobenius from "leanprover-community/mathlib"@"0723536a0522d24fc2f159a096fb3304bef77472" /-! ## The Frobenius operator If `R` has characteristic `p`, then there is a ring endomorphism `frobenius R p` that raises `r : R` to the power `p`. By applying `WittVector.map` to `frobenius R p`, we obtain a ring endomorphism `𝕎 R →+* 𝕎 R`. It turns out that this endomorphism can be described by polynomials over `ℤ` that do not depend on `R` or the fact that it has characteristic `p`. In this way, we obtain a Frobenius endomorphism `WittVector.frobeniusFun : 𝕎 R → 𝕎 R` for every commutative ring `R`. Unfortunately, the aforementioned polynomials can not be obtained using the machinery of `wittStructureInt` that was developed in `StructurePolynomial.lean`. We therefore have to define the polynomials by hand, and check that they have the required property. In case `R` has characteristic `p`, we show in `frobenius_eq_map_frobenius` that `WittVector.frobeniusFun` is equal to `WittVector.map (frobenius R p)`. ### Main definitions and results * `frobeniusPoly`: the polynomials that describe the coefficients of `frobeniusFun`; * `frobeniusFun`: the Frobenius endomorphism on Witt vectors; * `frobeniusFun_isPoly`: the tautological assertion that Frobenius is a polynomial function; * `frobenius_eq_map_frobenius`: the fact that in characteristic `p`, Frobenius is equal to `WittVector.map (frobenius R p)`. TODO: Show that `WittVector.frobeniusFun` is a ring homomorphism, and bundle it into `WittVector.frobenius`. ## References * [Hazewinkel, *Witt Vectors*][Haze09] * [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21] -/ namespace WittVector variable {p : ℕ} {R S : Type*} [hp : Fact p.Prime] [CommRing R] [CommRing S] local notation "𝕎" => WittVector p -- type as `\bbW` noncomputable section open MvPolynomial Finset variable (p) /-- The rational polynomials that give the coefficients of `frobenius x`, in terms of the coefficients of `x`. These polynomials actually have integral coefficients, see `frobeniusPoly` and `map_frobeniusPoly`. -/ def frobeniusPolyRat (n : ℕ) : MvPolynomial ℕ ℚ := bind₁ (wittPolynomial p ℚ ∘ fun n => n + 1) (xInTermsOfW p ℚ n) #align witt_vector.frobenius_poly_rat WittVector.frobeniusPolyRat theorem bind₁_frobeniusPolyRat_wittPolynomial (n : ℕ) : bind₁ (frobeniusPolyRat p) (wittPolynomial p ℚ n) = wittPolynomial p ℚ (n + 1) := by delta frobeniusPolyRat rw [← bind₁_bind₁, bind₁_xInTermsOfW_wittPolynomial, bind₁_X_right, Function.comp_apply] #align witt_vector.bind₁_frobenius_poly_rat_witt_polynomial WittVector.bind₁_frobeniusPolyRat_wittPolynomial /-- An auxiliary definition, to avoid an excessive amount of finiteness proofs for `multiplicity p n`. -/ private def pnat_multiplicity (n : ℕ+) : ℕ := (multiplicity p n).get <| multiplicity.finite_nat_iff.mpr <| ⟨ne_of_gt hp.1.one_lt, n.2⟩ local notation "v" => pnat_multiplicity /-- An auxiliary polynomial over the integers, that satisfies `p * (frobeniusPolyAux p n) + X n ^ p = frobeniusPoly p n`. This makes it easy to show that `frobeniusPoly p n` is congruent to `X n ^ p` modulo `p`. -/ noncomputable def frobeniusPolyAux : ℕ → MvPolynomial ℕ ℤ | n => X (n + 1) - ∑ i : Fin n, have _ := i.is_lt ∑ j ∈ range (p ^ (n - i)), (((X (i : ℕ) ^ p) ^ (p ^ (n - (i : ℕ)) - (j + 1)) : MvPolynomial ℕ ℤ) * (frobeniusPolyAux i) ^ (j + 1)) * C (((p ^ (n - i)).choose (j + 1) / (p ^ (n - i - v p ⟨j + 1, Nat.succ_pos j⟩)) * ↑p ^ (j - v p ⟨j + 1, Nat.succ_pos j⟩) : ℕ) : ℤ) #align witt_vector.frobenius_poly_aux WittVector.frobeniusPolyAux theorem frobeniusPolyAux_eq (n : ℕ) : frobeniusPolyAux p n = X (n + 1) - ∑ i ∈ range n, ∑ j ∈ range (p ^ (n - i)), (X i ^ p) ^ (p ^ (n - i) - (j + 1)) * frobeniusPolyAux p i ^ (j + 1) * C ↑((p ^ (n - i)).choose (j + 1) / p ^ (n - i - v p ⟨j + 1, Nat.succ_pos j⟩) * ↑p ^ (j - v p ⟨j + 1, Nat.succ_pos j⟩) : ℕ) := by rw [frobeniusPolyAux, ← Fin.sum_univ_eq_sum_range] #align witt_vector.frobenius_poly_aux_eq WittVector.frobeniusPolyAux_eq /-- The polynomials that give the coefficients of `frobenius x`, in terms of the coefficients of `x`. -/ def frobeniusPoly (n : ℕ) : MvPolynomial ℕ ℤ := X n ^ p + C (p : ℤ) * frobeniusPolyAux p n #align witt_vector.frobenius_poly WittVector.frobeniusPoly /- Our next goal is to prove ``` lemma map_frobeniusPoly (n : ℕ) : MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n ``` This lemma has a rather long proof, but it mostly boils down to applying induction, and then using the following two key facts at the right point. -/ /-- A key divisibility fact for the proof of `WittVector.map_frobeniusPoly`. -/ theorem map_frobeniusPoly.key₁ (n j : ℕ) (hj : j < p ^ n) : p ^ (n - v p ⟨j + 1, j.succ_pos⟩) ∣ (p ^ n).choose (j + 1) := by apply multiplicity.pow_dvd_of_le_multiplicity rw [hp.out.multiplicity_choose_prime_pow hj j.succ_ne_zero] rfl #align witt_vector.map_frobenius_poly.key₁ WittVector.map_frobeniusPoly.key₁ /-- A key numerical identity needed for the proof of `WittVector.map_frobeniusPoly`. -/ theorem map_frobeniusPoly.key₂ {n i j : ℕ} (hi : i ≤ n) (hj : j < p ^ (n - i)) : j - v p ⟨j + 1, j.succ_pos⟩ + n = i + j + (n - i - v p ⟨j + 1, j.succ_pos⟩) := by generalize h : v p ⟨j + 1, j.succ_pos⟩ = m rsuffices ⟨h₁, h₂⟩ : m ≤ n - i ∧ m ≤ j · rw [tsub_add_eq_add_tsub h₂, add_comm i j, add_tsub_assoc_of_le (h₁.trans (Nat.sub_le n i)), add_assoc, tsub_right_comm, add_comm i, tsub_add_cancel_of_le (le_tsub_of_add_le_right ((le_tsub_iff_left hi).mp h₁))] have hle : p ^ m ≤ j + 1 := h ▸ Nat.le_of_dvd j.succ_pos (multiplicity.pow_multiplicity_dvd _) exact ⟨(pow_le_pow_iff_right hp.1.one_lt).1 (hle.trans hj), Nat.le_of_lt_succ ((Nat.lt_pow_self hp.1.one_lt m).trans_le hle)⟩ #align witt_vector.map_frobenius_poly.key₂ WittVector.map_frobeniusPoly.key₂ theorem map_frobeniusPoly (n : ℕ) : MvPolynomial.map (Int.castRingHom ℚ) (frobeniusPoly p n) = frobeniusPolyRat p n := by rw [frobeniusPoly, RingHom.map_add, RingHom.map_mul, RingHom.map_pow, map_C, map_X, eq_intCast, Int.cast_natCast, frobeniusPolyRat] refine Nat.strong_induction_on n ?_; clear n intro n IH rw [xInTermsOfW_eq] simp only [AlgHom.map_sum, AlgHom.map_sub, AlgHom.map_mul, AlgHom.map_pow, bind₁_C_right] have h1 : (p : ℚ) ^ n * ⅟ (p : ℚ) ^ n = 1 := by rw [← mul_pow, mul_invOf_self, one_pow] rw [bind₁_X_right, Function.comp_apply, wittPolynomial_eq_sum_C_mul_X_pow, sum_range_succ, sum_range_succ, tsub_self, add_tsub_cancel_left, pow_zero, pow_one, pow_one, sub_mul, add_mul, add_mul, mul_right_comm, mul_right_comm (C ((p : ℚ) ^ (n + 1))), ← C_mul, ← C_mul, pow_succ', mul_assoc (p : ℚ) ((p : ℚ) ^ n), h1, mul_one, C_1, one_mul, add_comm _ (X n ^ p), add_assoc, ← add_sub, add_right_inj, frobeniusPolyAux_eq, RingHom.map_sub, map_X, mul_sub, sub_eq_add_neg, add_comm _ (C (p : ℚ) * X (n + 1)), ← add_sub, add_right_inj, neg_eq_iff_eq_neg, neg_sub, eq_comm] simp only [map_sum, mul_sum, sum_mul, ← sum_sub_distrib] apply sum_congr rfl intro i hi rw [mem_range] at hi rw [← IH i hi] clear IH rw [add_comm (X i ^ p), add_pow, sum_range_succ', pow_zero, tsub_zero, Nat.choose_zero_right, one_mul, Nat.cast_one, mul_one, mul_add, add_mul, Nat.succ_sub (le_of_lt hi), Nat.succ_eq_add_one (n - i), pow_succ', pow_mul, add_sub_cancel_right, mul_sum, sum_mul] apply sum_congr rfl intro j hj rw [mem_range] at hj rw [RingHom.map_mul, RingHom.map_mul, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow, RingHom.map_pow, map_C, map_X, mul_pow] rw [mul_comm (C (p : ℚ) ^ i), mul_comm _ ((X i ^ p) ^ _), mul_comm (C (p : ℚ) ^ (j + 1)), mul_comm (C (p : ℚ))] simp only [mul_assoc] apply congr_arg apply congr_arg rw [← C_eq_coe_nat] simp only [← RingHom.map_pow, ← C_mul] rw [C_inj] simp only [invOf_eq_inv, eq_intCast, inv_pow, Int.cast_natCast, Nat.cast_mul, Int.cast_mul] rw [Rat.natCast_div _ _ (map_frobeniusPoly.key₁ p (n - i) j hj)] simp only [Nat.cast_pow, pow_add, pow_one] suffices (((p ^ (n - i)).choose (j + 1): ℚ) * (p : ℚ) ^ (j - v p ⟨j + 1, j.succ_pos⟩) * ↑p * (p ^ n : ℚ)) = (p : ℚ) ^ j * p * ↑((p ^ (n - i)).choose (j + 1) * p ^ i) * (p : ℚ) ^ (n - i - v p ⟨j + 1, j.succ_pos⟩) by have aux : ∀ k : ℕ, (p : ℚ)^ k ≠ 0 := by intro; apply pow_ne_zero; exact mod_cast hp.1.ne_zero simpa [aux, -one_div, -pow_eq_zero_iff', field_simps] using this.symm rw [mul_comm _ (p : ℚ), mul_assoc, mul_assoc, ← pow_add, map_frobeniusPoly.key₂ p hi.le hj, Nat.cast_mul, Nat.cast_pow] ring #align witt_vector.map_frobenius_poly WittVector.map_frobeniusPoly theorem frobeniusPoly_zmod (n : ℕ) : MvPolynomial.map (Int.castRingHom (ZMod p)) (frobeniusPoly p n) = X n ^ p := by rw [frobeniusPoly, RingHom.map_add, RingHom.map_pow, RingHom.map_mul, map_X, map_C] simp only [Int.cast_natCast, add_zero, eq_intCast, ZMod.natCast_self, zero_mul, C_0] #align witt_vector.frobenius_poly_zmod WittVector.frobeniusPoly_zmod @[simp]
Mathlib/RingTheory/WittVector/Frobenius.lean
203
207
theorem bind₁_frobeniusPoly_wittPolynomial (n : ℕ) : bind₁ (frobeniusPoly p) (wittPolynomial p ℤ n) = wittPolynomial p ℤ (n + 1) := by
apply MvPolynomial.map_injective (Int.castRingHom ℚ) Int.cast_injective simp only [map_bind₁, map_frobeniusPoly, bind₁_frobeniusPolyRat_wittPolynomial, map_wittPolynomial]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.BoxIntegral.Partition.Filter import Mathlib.Analysis.BoxIntegral.Partition.Measure import Mathlib.Topology.UniformSpace.Compact import Mathlib.Init.Data.Bool.Lemmas #align_import analysis.box_integral.basic from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Integrals of Riemann, Henstock-Kurzweil, and McShane In this file we define the integral of a function over a box in `ℝⁿ`. The same definition works for Riemann, Henstock-Kurzweil, and McShane integrals. As usual, we represent `ℝⁿ` as the type of functions `ι → ℝ` for some finite type `ι`. A rectangular box `(l, u]` in `ℝⁿ` is defined to be the set `{x : ι → ℝ | ∀ i, l i < x i ∧ x i ≤ u i}`, see `BoxIntegral.Box`. Let `vol` be a box-additive function on boxes in `ℝⁿ` with codomain `E →L[ℝ] F`. Given a function `f : ℝⁿ → E`, a box `I` and a tagged partition `π` of this box, the *integral sum* of `f` over `π` with respect to the volume `vol` is the sum of `vol J (f (π.tag J))` over all boxes of `π`. Here `π.tag J` is the point (tag) in `ℝⁿ` associated with the box `J`. The integral is defined as the limit of integral sums along a filter. Different filters correspond to different integration theories. In order to avoid code duplication, all our definitions and theorems take an argument `l : BoxIntegral.IntegrationParams`. This is a type that holds three boolean values, and encodes eight filters including those corresponding to Riemann, Henstock-Kurzweil, and McShane integrals. Following the design of infinite sums (see `hasSum` and `tsum`), we define a predicate `BoxIntegral.HasIntegral` and a function `BoxIntegral.integral` that returns a vector satisfying the predicate or zero if the function is not integrable. Then we prove some basic properties of box integrals (linearity, a formula for the integral of a constant). We also prove a version of the Henstock-Sacks inequality (see `BoxIntegral.Integrable.dist_integralSum_le_of_memBaseSet` and `BoxIntegral.Integrable.dist_integralSum_sum_integral_le_of_memBaseSet_of_iUnion_eq`), prove integrability of continuous functions, and provide a criterion for integrability w.r.t. a non-Riemann filter (e.g., Henstock-Kurzweil and McShane). ## Notation - `ℝⁿ`: local notation for `ι → ℝ` ## Tags integral -/ open scoped Classical Topology NNReal Filter Uniformity BoxIntegral open Set Finset Function Filter Metric BoxIntegral.IntegrationParams noncomputable section namespace BoxIntegral universe u v w variable {ι : Type u} {E : Type v} {F : Type w} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {I J : Box ι} {π : TaggedPrepartition I} open TaggedPrepartition local notation "ℝⁿ" => ι → ℝ /-! ### Integral sum and its basic properties -/ /-- The integral sum of `f : ℝⁿ → E` over a tagged prepartition `π` w.r.t. box-additive volume `vol` with codomain `E →L[ℝ] F` is the sum of `vol J (f (π.tag J))` over all boxes of `π`. -/ def integralSum (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : F := ∑ J ∈ π.boxes, vol J (f (π.tag J)) #align box_integral.integral_sum BoxIntegral.integralSum theorem integralSum_biUnionTagged (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : Prepartition I) (πi : ∀ J, TaggedPrepartition J) : integralSum f vol (π.biUnionTagged πi) = ∑ J ∈ π.boxes, integralSum f vol (πi J) := by refine (π.sum_biUnion_boxes _ _).trans <| sum_congr rfl fun J hJ => sum_congr rfl fun J' hJ' => ?_ rw [π.tag_biUnionTagged hJ hJ'] #align box_integral.integral_sum_bUnion_tagged BoxIntegral.integralSum_biUnionTagged theorem integralSum_biUnion_partition (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) (πi : ∀ J, Prepartition J) (hπi : ∀ J ∈ π, (πi J).IsPartition) : integralSum f vol (π.biUnionPrepartition πi) = integralSum f vol π := by refine (π.sum_biUnion_boxes _ _).trans (sum_congr rfl fun J hJ => ?_) calc (∑ J' ∈ (πi J).boxes, vol J' (f (π.tag <| π.toPrepartition.biUnionIndex πi J'))) = ∑ J' ∈ (πi J).boxes, vol J' (f (π.tag J)) := sum_congr rfl fun J' hJ' => by rw [Prepartition.biUnionIndex_of_mem _ hJ hJ'] _ = vol J (f (π.tag J)) := (vol.map ⟨⟨fun g : E →L[ℝ] F => g (f (π.tag J)), rfl⟩, fun _ _ => rfl⟩).sum_partition_boxes le_top (hπi J hJ) #align box_integral.integral_sum_bUnion_partition BoxIntegral.integralSum_biUnion_partition theorem integralSum_inf_partition (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) {π' : Prepartition I} (h : π'.IsPartition) : integralSum f vol (π.infPrepartition π') = integralSum f vol π := integralSum_biUnion_partition f vol π _ fun _J hJ => h.restrict (Prepartition.le_of_mem _ hJ) #align box_integral.integral_sum_inf_partition BoxIntegral.integralSum_inf_partition theorem integralSum_fiberwise {α} (g : Box ι → α) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : (∑ y ∈ π.boxes.image g, integralSum f vol (π.filter (g · = y))) = integralSum f vol π := π.sum_fiberwise g fun J => vol J (f <| π.tag J) #align box_integral.integral_sum_fiberwise BoxIntegral.integralSum_fiberwise theorem integralSum_sub_partitions (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) {π₁ π₂ : TaggedPrepartition I} (h₁ : π₁.IsPartition) (h₂ : π₂.IsPartition) : integralSum f vol π₁ - integralSum f vol π₂ = ∑ J ∈ (π₁.toPrepartition ⊓ π₂.toPrepartition).boxes, (vol J (f <| (π₁.infPrepartition π₂.toPrepartition).tag J) - vol J (f <| (π₂.infPrepartition π₁.toPrepartition).tag J)) := by rw [← integralSum_inf_partition f vol π₁ h₂, ← integralSum_inf_partition f vol π₂ h₁, integralSum, integralSum, Finset.sum_sub_distrib] simp only [infPrepartition_toPrepartition, inf_comm] #align box_integral.integral_sum_sub_partitions BoxIntegral.integralSum_sub_partitions @[simp] theorem integralSum_disjUnion (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) {π₁ π₂ : TaggedPrepartition I} (h : Disjoint π₁.iUnion π₂.iUnion) : integralSum f vol (π₁.disjUnion π₂ h) = integralSum f vol π₁ + integralSum f vol π₂ := by refine (Prepartition.sum_disj_union_boxes h _).trans (congr_arg₂ (· + ·) (sum_congr rfl fun J hJ => ?_) (sum_congr rfl fun J hJ => ?_)) · rw [disjUnion_tag_of_mem_left _ hJ] · rw [disjUnion_tag_of_mem_right _ hJ] #align box_integral.integral_sum_disj_union BoxIntegral.integralSum_disjUnion @[simp] theorem integralSum_add (f g : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (f + g) vol π = integralSum f vol π + integralSum g vol π := by simp only [integralSum, Pi.add_apply, (vol _).map_add, Finset.sum_add_distrib] #align box_integral.integral_sum_add BoxIntegral.integralSum_add @[simp] theorem integralSum_neg (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (-f) vol π = -integralSum f vol π := by simp only [integralSum, Pi.neg_apply, (vol _).map_neg, Finset.sum_neg_distrib] #align box_integral.integral_sum_neg BoxIntegral.integralSum_neg @[simp]
Mathlib/Analysis/BoxIntegral/Basic.lean
149
151
theorem integralSum_smul (c : ℝ) (f : ℝⁿ → E) (vol : ι →ᵇᵃ E →L[ℝ] F) (π : TaggedPrepartition I) : integralSum (c • f) vol π = c • integralSum f vol π := by
simp only [integralSum, Finset.smul_sum, Pi.smul_apply, ContinuousLinearMap.map_smul]
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue /-! # Measure with a given density with respect to another measure For a measure `μ` on `α` and a function `f : α → ℝ≥0∞`, we define a new measure `μ.withDensity f`. On a measurable set `s`, that measure has value `∫⁻ a in s, f a ∂μ`. An important result about `withDensity` is the Radon-Nikodym theorem. It states that, given measures `μ, ν`, if `HaveLebesgueDecomposition μ ν` then `μ` is absolutely continuous with respect to `ν` if and only if there exists a measurable function `f : α → ℝ≥0∞` such that `μ = ν.withDensity f`. See `MeasureTheory.Measure.absolutelyContinuous_iff_withDensity_rnDeriv_eq`. -/ open Set hiding restrict restrict_apply open Filter ENNReal NNReal MeasureTheory.Measure namespace MeasureTheory variable {α : Type*} {m0 : MeasurableSpace α} {μ : Measure α} /-- Given a measure `μ : Measure α` and a function `f : α → ℝ≥0∞`, `μ.withDensity f` is the measure such that for a measurable set `s` we have `μ.withDensity f s = ∫⁻ a in s, f a ∂μ`. -/ noncomputable def Measure.withDensity {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : Measure α := Measure.ofMeasurable (fun s _ => ∫⁻ a in s, f a ∂μ) (by simp) fun s hs hd => lintegral_iUnion hs hd _ #align measure_theory.measure.with_density MeasureTheory.Measure.withDensity @[simp] theorem withDensity_apply (f : α → ℝ≥0∞) {s : Set α} (hs : MeasurableSet s) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := Measure.ofMeasurable_apply s hs #align measure_theory.with_density_apply MeasureTheory.withDensity_apply theorem withDensity_apply_le (f : α → ℝ≥0∞) (s : Set α) : ∫⁻ a in s, f a ∂μ ≤ μ.withDensity f s := by let t := toMeasurable (μ.withDensity f) s calc ∫⁻ a in s, f a ∂μ ≤ ∫⁻ a in t, f a ∂μ := lintegral_mono_set (subset_toMeasurable (withDensity μ f) s) _ = μ.withDensity f t := (withDensity_apply f (measurableSet_toMeasurable (withDensity μ f) s)).symm _ = μ.withDensity f s := measure_toMeasurable s /-! In the next theorem, the s-finiteness assumption is necessary. Here is a counterexample without this assumption. Let `α` be an uncountable space, let `x₀` be some fixed point, and consider the σ-algebra made of those sets which are countable and do not contain `x₀`, and of their complements. This is the σ-algebra generated by the sets `{x}` for `x ≠ x₀`. Define a measure equal to `+∞` on nonempty sets. Let `s = {x₀}` and `f` the indicator of `sᶜ`. Then * `∫⁻ a in s, f a ∂μ = 0`. Indeed, consider a simple function `g ≤ f`. It vanishes on `s`. Then `∫⁻ a in s, g a ∂μ = 0`. Taking the supremum over `g` gives the claim. * `μ.withDensity f s = +∞`. Indeed, this is the infimum of `μ.withDensity f t` over measurable sets `t` containing `s`. As `s` is not measurable, such a set `t` contains a point `x ≠ x₀`. Then `μ.withDensity f t ≥ μ.withDensity f {x} = ∫⁻ a in {x}, f a ∂μ = μ {x} = +∞`. One checks that `μ.withDensity f = μ`, while `μ.restrict s` gives zero mass to sets not containing `x₀`, and infinite mass to those that contain it. -/ theorem withDensity_apply' [SFinite μ] (f : α → ℝ≥0∞) (s : Set α) : μ.withDensity f s = ∫⁻ a in s, f a ∂μ := by apply le_antisymm ?_ (withDensity_apply_le f s) let t := toMeasurable μ s calc μ.withDensity f s ≤ μ.withDensity f t := measure_mono (subset_toMeasurable μ s) _ = ∫⁻ a in t, f a ∂μ := withDensity_apply f (measurableSet_toMeasurable μ s) _ = ∫⁻ a in s, f a ∂μ := by congr 1; exact restrict_toMeasurable_of_sFinite s @[simp] lemma withDensity_zero_left (f : α → ℝ≥0∞) : (0 : Measure α).withDensity f = 0 := by ext s hs rw [withDensity_apply _ hs] simp theorem withDensity_congr_ae {f g : α → ℝ≥0∞} (h : f =ᵐ[μ] g) : μ.withDensity f = μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] exact lintegral_congr_ae (ae_restrict_of_ae h) #align measure_theory.with_density_congr_ae MeasureTheory.withDensity_congr_ae lemma withDensity_mono {f g : α → ℝ≥0∞} (hfg : f ≤ᵐ[μ] g) : μ.withDensity f ≤ μ.withDensity g := by refine le_iff.2 fun s hs ↦ ?_ rw [withDensity_apply _ hs, withDensity_apply _ hs] refine set_lintegral_mono_ae' hs ?_ filter_upwards [hfg] with x h_le using fun _ ↦ h_le theorem withDensity_add_left {f : α → ℝ≥0∞} (hf : Measurable f) (g : α → ℝ≥0∞) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.add_apply, withDensity_apply _ hs, withDensity_apply _ hs, ← lintegral_add_left hf] simp only [Pi.add_apply] #align measure_theory.with_density_add_left MeasureTheory.withDensity_add_left theorem withDensity_add_right (f : α → ℝ≥0∞) {g : α → ℝ≥0∞} (hg : Measurable g) : μ.withDensity (f + g) = μ.withDensity f + μ.withDensity g := by simpa only [add_comm] using withDensity_add_left hg f #align measure_theory.with_density_add_right MeasureTheory.withDensity_add_right theorem withDensity_add_measure {m : MeasurableSpace α} (μ ν : Measure α) (f : α → ℝ≥0∞) : (μ + ν).withDensity f = μ.withDensity f + ν.withDensity f := by ext1 s hs simp only [withDensity_apply f hs, restrict_add, lintegral_add_measure, Measure.add_apply] #align measure_theory.with_density_add_measure MeasureTheory.withDensity_add_measure theorem withDensity_sum {ι : Type*} {m : MeasurableSpace α} (μ : ι → Measure α) (f : α → ℝ≥0∞) : (sum μ).withDensity f = sum fun n => (μ n).withDensity f := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply f hs, restrict_sum μ hs, lintegral_sum_measure] #align measure_theory.with_density_sum MeasureTheory.withDensity_sum theorem withDensity_smul (r : ℝ≥0∞) {f : α → ℝ≥0∞} (hf : Measurable f) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul r hf] simp only [Pi.smul_apply, smul_eq_mul] #align measure_theory.with_density_smul MeasureTheory.withDensity_smul theorem withDensity_smul' (r : ℝ≥0∞) (f : α → ℝ≥0∞) (hr : r ≠ ∞) : μ.withDensity (r • f) = r • μ.withDensity f := by refine Measure.ext fun s hs => ?_ rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, ← lintegral_const_mul' r f hr] simp only [Pi.smul_apply, smul_eq_mul] #align measure_theory.with_density_smul' MeasureTheory.withDensity_smul' theorem withDensity_smul_measure (r : ℝ≥0∞) (f : α → ℝ≥0∞) : (r • μ).withDensity f = r • μ.withDensity f := by ext s hs rw [withDensity_apply _ hs, Measure.coe_smul, Pi.smul_apply, withDensity_apply _ hs, smul_eq_mul, set_lintegral_smul_measure] theorem isFiniteMeasure_withDensity {f : α → ℝ≥0∞} (hf : ∫⁻ a, f a ∂μ ≠ ∞) : IsFiniteMeasure (μ.withDensity f) := { measure_univ_lt_top := by rwa [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ, lt_top_iff_ne_top] } #align measure_theory.is_finite_measure_with_density MeasureTheory.isFiniteMeasure_withDensity theorem withDensity_absolutelyContinuous {m : MeasurableSpace α} (μ : Measure α) (f : α → ℝ≥0∞) : μ.withDensity f ≪ μ := by refine AbsolutelyContinuous.mk fun s hs₁ hs₂ => ?_ rw [withDensity_apply _ hs₁] exact set_lintegral_measure_zero _ _ hs₂ #align measure_theory.with_density_absolutely_continuous MeasureTheory.withDensity_absolutelyContinuous @[simp] theorem withDensity_zero : μ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] #align measure_theory.with_density_zero MeasureTheory.withDensity_zero @[simp] theorem withDensity_one : μ.withDensity 1 = μ := by ext1 s hs simp [withDensity_apply _ hs] #align measure_theory.with_density_one MeasureTheory.withDensity_one @[simp] theorem withDensity_const (c : ℝ≥0∞) : μ.withDensity (fun _ ↦ c) = c • μ := by ext1 s hs simp [withDensity_apply _ hs] theorem withDensity_tsum {f : ℕ → α → ℝ≥0∞} (h : ∀ i, Measurable (f i)) : μ.withDensity (∑' n, f n) = sum fun n => μ.withDensity (f n) := by ext1 s hs simp_rw [sum_apply _ hs, withDensity_apply _ hs] change ∫⁻ x in s, (∑' n, f n) x ∂μ = ∑' i : ℕ, ∫⁻ x, f i x ∂μ.restrict s rw [← lintegral_tsum fun i => (h i).aemeasurable] exact lintegral_congr fun x => tsum_apply (Pi.summable.2 fun _ => ENNReal.summable) #align measure_theory.with_density_tsum MeasureTheory.withDensity_tsum theorem withDensity_indicator {s : Set α} (hs : MeasurableSet s) (f : α → ℝ≥0∞) : μ.withDensity (s.indicator f) = (μ.restrict s).withDensity f := by ext1 t ht rw [withDensity_apply _ ht, lintegral_indicator _ hs, restrict_comm hs, ← withDensity_apply _ ht] #align measure_theory.with_density_indicator MeasureTheory.withDensity_indicator theorem withDensity_indicator_one {s : Set α} (hs : MeasurableSet s) : μ.withDensity (s.indicator 1) = μ.restrict s := by rw [withDensity_indicator hs, withDensity_one] #align measure_theory.with_density_indicator_one MeasureTheory.withDensity_indicator_one
Mathlib/MeasureTheory/Measure/WithDensity.lean
195
206
theorem withDensity_ofReal_mutuallySingular {f : α → ℝ} (hf : Measurable f) : (μ.withDensity fun x => ENNReal.ofReal <| f x) ⟂ₘ μ.withDensity fun x => ENNReal.ofReal <| -f x := by
set S : Set α := { x | f x < 0 } have hS : MeasurableSet S := measurableSet_lt hf measurable_const refine ⟨S, hS, ?_, ?_⟩ · rw [withDensity_apply _ hS, lintegral_eq_zero_iff hf.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS).mono fun x hx => ENNReal.ofReal_eq_zero.2 (le_of_lt hx) · rw [withDensity_apply _ hS.compl, lintegral_eq_zero_iff hf.neg.ennreal_ofReal, EventuallyEq] exact (ae_restrict_mem hS.compl).mono fun x hx => ENNReal.ofReal_eq_zero.2 (not_lt.1 <| mt neg_pos.1 hx)
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Matthew Robert Ballard -/ import Mathlib.NumberTheory.Divisors import Mathlib.Data.Nat.Digits import Mathlib.Data.Nat.MaxPowDiv import Mathlib.Data.Nat.Multiplicity import Mathlib.Tactic.IntervalCases #align_import number_theory.padics.padic_val from "leanprover-community/mathlib"@"60fa54e778c9e85d930efae172435f42fb0d71f7" /-! # `p`-adic Valuation This file defines the `p`-adic valuation on `ℕ`, `ℤ`, and `ℚ`. The `p`-adic valuation on `ℚ` is the difference of the multiplicities of `p` in the numerator and denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate assumptions on `p`. The `p`-adic valuations on `ℕ` and `ℤ` agree with that on `ℚ`. The valuation induces a norm on `ℚ`. This norm is defined in padicNorm.lean. ## Notations This file uses the local notation `/.` for `Rat.mk`. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. ## Calculations with `p`-adic valuations * `padicValNat_factorial`: Legendre's Theorem. The `p`-adic valuation of `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound greater than `log p n`. See `Nat.Prime.multiplicity_factorial` for the same result but stated in the language of prime multiplicity. * `sub_one_mul_padicValNat_factorial`: Legendre's Theorem. Taking (`p - 1`) times the `p`-adic valuation of `n!` equals `n` minus the sum of base `p` digits of `n`. * `padicValNat_choose`: Kummer's Theorem. The `p`-adic valuation of `n.choose k` is the number of carries when `k` and `n - k` are added in base `p`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound greater than `log p n`. See `Nat.Prime.multiplicity_choose` for the same result but stated in the language of prime multiplicity. * `sub_one_mul_padicValNat_choose_eq_sub_sum_digits`: Kummer's Theorem. Taking (`p - 1`) times the `p`-adic valuation of the binomial `n` over `k` equals the sum of the digits of `k` plus the sum of the digits of `n - k` minus the sum of digits of `n`, all base `p`. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, norm, valuation -/ universe u open Nat open Rat open multiplicity /-- For `p ≠ 1`, the `p`-adic valuation of a natural `n ≠ 0` is the largest natural number `k` such that `p^k` divides `n`. If `n = 0` or `p = 1`, then `padicValNat p q` defaults to `0`. -/ def padicValNat (p : ℕ) (n : ℕ) : ℕ := if h : p ≠ 1 ∧ 0 < n then (multiplicity p n).get (multiplicity.finite_nat_iff.2 h) else 0 #align padic_val_nat padicValNat namespace padicValNat open multiplicity variable {p : ℕ} /-- `padicValNat p 0` is `0` for any `p`. -/ @[simp] protected theorem zero : padicValNat p 0 = 0 := by simp [padicValNat] #align padic_val_nat.zero padicValNat.zero /-- `padicValNat p 1` is `0` for any `p`. -/ @[simp] protected theorem one : padicValNat p 1 = 0 := by unfold padicValNat split_ifs · simp · rfl #align padic_val_nat.one padicValNat.one /-- If `p ≠ 0` and `p ≠ 1`, then `padicValNat p p` is `1`. -/ @[simp] theorem self (hp : 1 < p) : padicValNat p p = 1 := by have neq_one : ¬p = 1 ↔ True := iff_of_true hp.ne' trivial have eq_zero_false : p = 0 ↔ False := iff_false_intro (zero_lt_one.trans hp).ne' simp [padicValNat, neq_one, eq_zero_false] #align padic_val_nat.self padicValNat.self @[simp] theorem eq_zero_iff {n : ℕ} : padicValNat p n = 0 ↔ p = 1 ∨ n = 0 ∨ ¬p ∣ n := by simp only [padicValNat, dite_eq_right_iff, PartENat.get_eq_iff_eq_coe, Nat.cast_zero, multiplicity_eq_zero, and_imp, pos_iff_ne_zero, Ne, ← or_iff_not_imp_left] #align padic_val_nat.eq_zero_iff padicValNat.eq_zero_iff theorem eq_zero_of_not_dvd {n : ℕ} (h : ¬p ∣ n) : padicValNat p n = 0 := eq_zero_iff.2 <| Or.inr <| Or.inr h #align padic_val_nat.eq_zero_of_not_dvd padicValNat.eq_zero_of_not_dvd open Nat.maxPowDiv theorem maxPowDiv_eq_multiplicity {p n : ℕ} (hp : 1 < p) (hn : 0 < n) : p.maxPowDiv n = multiplicity p n := by apply multiplicity.unique <| pow_dvd p n intro h apply Nat.not_lt.mpr <| le_of_dvd hp hn h simp theorem maxPowDiv_eq_multiplicity_get {p n : ℕ} (hp : 1 < p) (hn : 0 < n) (h : Finite p n) : p.maxPowDiv n = (multiplicity p n).get h := by rw [PartENat.get_eq_iff_eq_coe.mpr] apply maxPowDiv_eq_multiplicity hp hn|>.symm /-- Allows for more efficient code for `padicValNat` -/ @[csimp] theorem padicValNat_eq_maxPowDiv : @padicValNat = @maxPowDiv := by ext p n by_cases h : 1 < p ∧ 0 < n · dsimp [padicValNat] rw [dif_pos ⟨Nat.ne_of_gt h.1,h.2⟩, maxPowDiv_eq_multiplicity_get h.1 h.2] · simp only [not_and_or,not_gt_eq,Nat.le_zero] at h apply h.elim · intro h interval_cases p · simp [Classical.em] · dsimp [padicValNat, maxPowDiv] rw [go, if_neg, dif_neg] <;> simp · intro h simp [h] end padicValNat /-- For `p ≠ 1`, the `p`-adic valuation of an integer `z ≠ 0` is the largest natural number `k` such that `p^k` divides `z`. If `x = 0` or `p = 1`, then `padicValInt p q` defaults to `0`. -/ def padicValInt (p : ℕ) (z : ℤ) : ℕ := padicValNat p z.natAbs #align padic_val_int padicValInt namespace padicValInt open multiplicity variable {p : ℕ} theorem of_ne_one_ne_zero {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) : padicValInt p z = (multiplicity (p : ℤ) z).get (by apply multiplicity.finite_int_iff.2 simp [hp, hz]) := by rw [padicValInt, padicValNat, dif_pos (And.intro hp (Int.natAbs_pos.mpr hz))] simp only [multiplicity.Int.natAbs p z] #align padic_val_int.of_ne_one_ne_zero padicValInt.of_ne_one_ne_zero /-- `padicValInt p 0` is `0` for any `p`. -/ @[simp] protected theorem zero : padicValInt p 0 = 0 := by simp [padicValInt] #align padic_val_int.zero padicValInt.zero /-- `padicValInt p 1` is `0` for any `p`. -/ @[simp] protected theorem one : padicValInt p 1 = 0 := by simp [padicValInt] #align padic_val_int.one padicValInt.one /-- The `p`-adic value of a natural is its `p`-adic value as an integer. -/ @[simp] theorem of_nat {n : ℕ} : padicValInt p n = padicValNat p n := by simp [padicValInt] #align padic_val_int.of_nat padicValInt.of_nat /-- If `p ≠ 0` and `p ≠ 1`, then `padicValInt p p` is `1`. -/ theorem self (hp : 1 < p) : padicValInt p p = 1 := by simp [padicValNat.self hp] #align padic_val_int.self padicValInt.self theorem eq_zero_of_not_dvd {z : ℤ} (h : ¬(p : ℤ) ∣ z) : padicValInt p z = 0 := by rw [padicValInt, padicValNat] split_ifs <;> simp [multiplicity.Int.natAbs, multiplicity_eq_zero.2 h] #align padic_val_int.eq_zero_of_not_dvd padicValInt.eq_zero_of_not_dvd end padicValInt /-- `padicValRat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the valuation of `q.den`. If `q = 0` or `p = 1`, then `padicValRat p q` defaults to `0`. -/ def padicValRat (p : ℕ) (q : ℚ) : ℤ := padicValInt p q.num - padicValNat p q.den #align padic_val_rat padicValRat lemma padicValRat_def (p : ℕ) (q : ℚ) : padicValRat p q = padicValInt p q.num - padicValNat p q.den := rfl namespace padicValRat open multiplicity variable {p : ℕ} /-- `padicValRat p q` is symmetric in `q`. -/ @[simp] protected theorem neg (q : ℚ) : padicValRat p (-q) = padicValRat p q := by simp [padicValRat, padicValInt] #align padic_val_rat.neg padicValRat.neg /-- `padicValRat p 0` is `0` for any `p`. -/ @[simp] protected theorem zero : padicValRat p 0 = 0 := by simp [padicValRat] #align padic_val_rat.zero padicValRat.zero /-- `padicValRat p 1` is `0` for any `p`. -/ @[simp] protected theorem one : padicValRat p 1 = 0 := by simp [padicValRat] #align padic_val_rat.one padicValRat.one /-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic_value as a rational. -/ @[simp] theorem of_int {z : ℤ} : padicValRat p z = padicValInt p z := by simp [padicValRat] #align padic_val_rat.of_int padicValRat.of_int /-- The `p`-adic value of an integer `z ≠ 0` is the multiplicity of `p` in `z`. -/ theorem of_int_multiplicity {z : ℤ} (hp : p ≠ 1) (hz : z ≠ 0) : padicValRat p (z : ℚ) = (multiplicity (p : ℤ) z).get (finite_int_iff.2 ⟨hp, hz⟩) := by rw [of_int, padicValInt.of_ne_one_ne_zero hp hz] #align padic_val_rat.of_int_multiplicity padicValRat.of_int_multiplicity theorem multiplicity_sub_multiplicity {q : ℚ} (hp : p ≠ 1) (hq : q ≠ 0) : padicValRat p q = (multiplicity (p : ℤ) q.num).get (finite_int_iff.2 ⟨hp, Rat.num_ne_zero.2 hq⟩) - (multiplicity p q.den).get (by rw [← finite_iff_dom, finite_nat_iff] exact ⟨hp, q.pos⟩) := by rw [padicValRat, padicValInt.of_ne_one_ne_zero hp, padicValNat, dif_pos] · exact ⟨hp, q.pos⟩ · exact Rat.num_ne_zero.2 hq #align padic_val_rat.multiplicity_sub_multiplicity padicValRat.multiplicity_sub_multiplicity /-- The `p`-adic value of an integer `z ≠ 0` is its `p`-adic value as a rational. -/ @[simp] theorem of_nat {n : ℕ} : padicValRat p n = padicValNat p n := by simp [padicValRat] #align padic_val_rat.of_nat padicValRat.of_nat /-- If `p ≠ 0` and `p ≠ 1`, then `padicValRat p p` is `1`. -/ theorem self (hp : 1 < p) : padicValRat p p = 1 := by simp [hp] #align padic_val_rat.self padicValRat.self end padicValRat section padicValNat variable {p : ℕ} theorem zero_le_padicValRat_of_nat (n : ℕ) : 0 ≤ padicValRat p n := by simp #align zero_le_padic_val_rat_of_nat zero_le_padicValRat_of_nat /-- `padicValRat` coincides with `padicValNat`. -/ @[norm_cast] theorem padicValRat_of_nat (n : ℕ) : ↑(padicValNat p n) = padicValRat p n := by simp #align padic_val_rat_of_nat padicValRat_of_nat /-- A simplification of `padicValNat` when one input is prime, by analogy with `padicValRat_def`. -/ theorem padicValNat_def [hp : Fact p.Prime] {n : ℕ} (hn : 0 < n) : padicValNat p n = (multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨hp.out.ne_one, hn⟩) := dif_pos ⟨hp.out.ne_one, hn⟩ #align padic_val_nat_def padicValNat_def theorem padicValNat_def' {n : ℕ} (hp : p ≠ 1) (hn : 0 < n) : ↑(padicValNat p n) = multiplicity p n := by simp [padicValNat, hp, hn] #align padic_val_nat_def' padicValNat_def' @[simp]
Mathlib/NumberTheory/Padics/PadicVal.lean
288
290
theorem padicValNat_self [Fact p.Prime] : padicValNat p p = 1 := by
rw [padicValNat_def (@Fact.out p.Prime).pos] simp
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers import Mathlib.CategoryTheory.Abelian.Images import Mathlib.CategoryTheory.Preadditive.Basic #align_import category_theory.abelian.non_preadditive from "leanprover-community/mathlib"@"829895f162a1f29d0133f4b3538f4cd1fb5bffd3" /-! # Every NonPreadditiveAbelian category is preadditive In mathlib, we define an abelian category as a preadditive category with a zero object, kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is normal. While virtually every interesting abelian category has a natural preadditive structure (which is why it is included in the definition), preadditivity is not actually needed: Every category that has all of the other properties appearing in the definition of an abelian category admits a preadditive structure. This is the construction we carry out in this file. The proof proceeds in roughly five steps: 1. Prove some results (for example that all equalizers exist) that would be trivial if we already had the preadditive structure but are a bit of work without it. 2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel. The results of the first two steps are also useful for the "normal" development of abelian categories, and will be used there. 3. For every object `A`, define a "subtraction" morphism `σ : A ⨯ A ⟶ A` and use it to define subtraction on morphisms as `f - g := prod.lift f g ≫ σ`. 4. Prove a small number of identities about this subtraction from the definition of `σ`. 5. From these identities, prove a large number of other identities that imply that defining `f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition is bilinear. The construction is non-trivial and it is quite remarkable that this abelian group structure can be constructed purely from the existence of a few limits and colimits. Even more remarkably, since abelian categories admit exactly one preadditive structure (see `subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly reconstruct any natural preadditive structure the category may have. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section open CategoryTheory open CategoryTheory.Limits namespace CategoryTheory section universe v u variable (C : Type u) [Category.{v} C] /-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary products and coproducts, and every monomorphism and every epimorphism is normal. -/ class NonPreadditiveAbelian extends HasZeroMorphisms C, NormalMonoCategory C, NormalEpiCategory C where [has_zero_object : HasZeroObject C] [has_kernels : HasKernels C] [has_cokernels : HasCokernels C] [has_finite_products : HasFiniteProducts C] [has_finite_coproducts : HasFiniteCoproducts C] #align category_theory.non_preadditive_abelian CategoryTheory.NonPreadditiveAbelian attribute [instance] NonPreadditiveAbelian.has_zero_object attribute [instance] NonPreadditiveAbelian.has_kernels attribute [instance] NonPreadditiveAbelian.has_cokernels attribute [instance] NonPreadditiveAbelian.has_finite_products attribute [instance] NonPreadditiveAbelian.has_finite_coproducts end end CategoryTheory open CategoryTheory universe v u variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C] namespace CategoryTheory.NonPreadditiveAbelian section Factor variable {P Q : C} (f : P ⟶ Q) /-- The map `p : P ⟶ image f` is an epimorphism -/ instance : Epi (Abelian.factorThruImage f) := let I := Abelian.image f let p := Abelian.factorThruImage f let i := kernel.ι (cokernel.π f) -- It will suffice to consider some g : I ⟶ R such that p ≫ g = 0 and show that g = 0. NormalMonoCategory.epi_of_zero_cancel _ fun R (g : I ⟶ R) (hpg : p ≫ g = 0) => by -- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h. let u := kernel.ι g ≫ i haveI : Mono u := mono_comp _ _ haveI hu := normalMonoOfMono u let h := hu.g -- By hypothesis, p factors through the kernel of g via some t. obtain ⟨t, ht⟩ := kernel.lift' g p hpg have fh : f ≫ h = 0 := calc f ≫ h = (p ≫ i) ≫ h := (Abelian.image.fac f).symm ▸ rfl _ = ((t ≫ kernel.ι g) ≫ i) ≫ h := ht ▸ rfl _ = t ≫ u ≫ h := by simp only [u, Category.assoc] _ = t ≫ 0 := hu.w ▸ rfl _ = 0 := HasZeroMorphisms.comp_zero _ _ -- h factors through the cokernel of f via some l. obtain ⟨l, hl⟩ := cokernel.desc' f h fh have hih : i ≫ h = 0 := calc i ≫ h = i ≫ cokernel.π f ≫ l := hl ▸ rfl _ = 0 ≫ l := by rw [← Category.assoc, kernel.condition] _ = 0 := zero_comp -- i factors through u = ker h via some s. obtain ⟨s, hs⟩ := NormalMono.lift' u i hih have hs' : (s ≫ kernel.ι g) ≫ i = 𝟙 I ≫ i := by rw [Category.assoc, hs, Category.id_comp] haveI : Epi (kernel.ι g) := epi_of_epi_fac ((cancel_mono _).1 hs') -- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required. exact zero_of_epi_comp _ (kernel.condition g) instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := isIso_of_mono_of_epi <| Abelian.factorThruImage f #align category_theory.non_preadditive_abelian.is_iso_factor_thru_image CategoryTheory.NonPreadditiveAbelian.isIso_factorThruImage /-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/ instance : Mono (Abelian.factorThruCoimage f) := let I := Abelian.coimage f let i := Abelian.factorThruCoimage f let p := cokernel.π (kernel.ι f) NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R ⟶ I) (hgi : g ≫ i = 0) => by -- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h. let u := p ≫ cokernel.π g haveI : Epi u := epi_comp _ _ haveI hu := normalEpiOfEpi u let h := hu.g -- By hypothesis, i factors through the cokernel of g via some t. obtain ⟨t, ht⟩ := cokernel.desc' g i hgi have hf : h ≫ f = 0 := calc h ≫ f = h ≫ p ≫ i := (Abelian.coimage.fac f).symm ▸ rfl _ = h ≫ p ≫ cokernel.π g ≫ t := ht ▸ rfl _ = h ≫ u ≫ t := by simp only [u, Category.assoc] _ = 0 ≫ t := by rw [← Category.assoc, hu.w] _ = 0 := zero_comp -- h factors through the kernel of f via some l. obtain ⟨l, hl⟩ := kernel.lift' f h hf have hhp : h ≫ p = 0 := calc h ≫ p = (l ≫ kernel.ι f) ≫ p := hl ▸ rfl _ = l ≫ 0 := by rw [Category.assoc, cokernel.condition] _ = 0 := comp_zero -- p factors through u = coker h via some s. obtain ⟨s, hs⟩ := NormalEpi.desc' u p hhp have hs' : p ≫ cokernel.π g ≫ s = p ≫ 𝟙 I := by rw [← Category.assoc, hs, Category.comp_id] haveI : Mono (cokernel.π g) := mono_of_mono_fac ((cancel_epi _).1 hs') -- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required. exact zero_of_comp_mono _ (cokernel.condition g) instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := isIso_of_mono_of_epi _ #align category_theory.non_preadditive_abelian.is_iso_factor_thru_coimage CategoryTheory.NonPreadditiveAbelian.isIso_factorThruCoimage end Factor section CokernelOfKernel variable {X Y : C} {f : X ⟶ Y} /-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely: If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel of `Fork.ι s`. -/ def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) : IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) := IsCokernel.cokernelIso _ _ (cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h) (ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _)) (asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f) #align category_theory.non_preadditive_abelian.epi_is_cokernel_of_kernel CategoryTheory.NonPreadditiveAbelian.epiIsCokernelOfKernel /-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely: If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel of `Cofork.π s`. -/ def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) : IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) := IsKernel.isoKernel _ _ (kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _)) (CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _)) (asIso <| Abelian.factorThruImage f) (Abelian.image.fac f) #align category_theory.non_preadditive_abelian.mono_is_kernel_of_cokernel CategoryTheory.NonPreadditiveAbelian.monoIsKernelOfCokernel end CokernelOfKernel section /-- The composite `A ⟶ A ⨯ A ⟶ cokernel (Δ A)`, where the first map is `(𝟙 A, 0)` and the second map is the canonical projection into the cokernel. -/ abbrev r (A : C) : A ⟶ cokernel (diag A) := prod.lift (𝟙 A) 0 ≫ cokernel.π (diag A) #align category_theory.non_preadditive_abelian.r CategoryTheory.NonPreadditiveAbelian.r instance mono_Δ {A : C} : Mono (diag A) := mono_of_mono_fac <| prod.lift_fst _ _ #align category_theory.non_preadditive_abelian.mono_Δ CategoryTheory.NonPreadditiveAbelian.mono_Δ instance mono_r {A : C} : Mono (r A) := by let hl : IsLimit (KernelFork.ofι (diag A) (cokernel.condition (diag A))) := monoIsKernelOfCokernel _ (colimit.isColimit _) apply NormalEpiCategory.mono_of_cancel_zero intro Z x hx have hxx : (x ≫ prod.lift (𝟙 A) (0 : A ⟶ A)) ≫ cokernel.π (diag A) = 0 := by rw [Category.assoc, hx] obtain ⟨y, hy⟩ := KernelFork.IsLimit.lift' hl _ hxx rw [KernelFork.ι_ofι] at hy have hyy : y = 0 := by erw [← Category.comp_id y, ← Limits.prod.lift_snd (𝟙 A) (𝟙 A), ← Category.assoc, hy, Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero] haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1 rw [← hy, hyy, zero_comp, zero_comp] #align category_theory.non_preadditive_abelian.mono_r CategoryTheory.NonPreadditiveAbelian.mono_r instance epi_r {A : C} : Epi (r A) := by have hlp : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ Limits.prod.snd = 0 := prod.lift_snd _ _ let hp1 : IsLimit (KernelFork.ofι (prod.lift (𝟙 A) (0 : A ⟶ A)) hlp) := by refine Fork.IsLimit.mk _ (fun s => Fork.ι s ≫ Limits.prod.fst) ?_ ?_ · intro s apply prod.hom_ext <;> simp · intro s m h haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _) apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1 convert h apply prod.hom_ext <;> simp let hp2 : IsColimit (CokernelCofork.ofπ (Limits.prod.snd : A ⨯ A ⟶ A) hlp) := epiIsCokernelOfKernel _ hp1 apply NormalMonoCategory.epi_of_zero_cancel intro Z z hz have h : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ cokernel.π (diag A) ≫ z = 0 := by rw [← Category.assoc, hz] obtain ⟨t, ht⟩ := CokernelCofork.IsColimit.desc' hp2 _ h rw [CokernelCofork.π_ofπ] at ht have htt : t = 0 := by rw [← Category.id_comp t] change 𝟙 A ≫ t = 0 rw [← Limits.prod.lift_snd (𝟙 A) (𝟙 A), Category.assoc, ht, ← Category.assoc, cokernel.condition, zero_comp] apply (cancel_epi (cokernel.π (diag A))).1 rw [← ht, htt, comp_zero, comp_zero] #align category_theory.non_preadditive_abelian.epi_r CategoryTheory.NonPreadditiveAbelian.epi_r instance isIso_r {A : C} : IsIso (r A) := isIso_of_mono_of_epi _ #align category_theory.non_preadditive_abelian.is_iso_r CategoryTheory.NonPreadditiveAbelian.isIso_r /-- The composite `A ⨯ A ⟶ cokernel (diag A) ⟶ A` given by the natural projection into the cokernel followed by the inverse of `r`. In the category of modules, using the normal kernels and cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `σ` for "subtraction". -/ abbrev σ {A : C} : A ⨯ A ⟶ A := cokernel.π (diag A) ≫ inv (r A) #align category_theory.non_preadditive_abelian.σ CategoryTheory.NonPreadditiveAbelian.σ end -- Porting note (#10618): simp can prove these @[reassoc] theorem diag_σ {X : C} : diag X ≫ σ = 0 := by rw [cokernel.condition_assoc, zero_comp] #align category_theory.non_preadditive_abelian.diag_σ CategoryTheory.NonPreadditiveAbelian.diag_σ @[reassoc (attr := simp)] theorem lift_σ {X : C} : prod.lift (𝟙 X) 0 ≫ σ = 𝟙 X := by rw [← Category.assoc, IsIso.hom_inv_id] #align category_theory.non_preadditive_abelian.lift_σ CategoryTheory.NonPreadditiveAbelian.lift_σ @[reassoc] theorem lift_map {X Y : C} (f : X ⟶ Y) : prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f = f ≫ prod.lift (𝟙 Y) 0 := by simp #align category_theory.non_preadditive_abelian.lift_map CategoryTheory.NonPreadditiveAbelian.lift_map /-- σ is a cokernel of Δ X. -/ def isColimitσ {X : C} : IsColimit (CokernelCofork.ofπ (σ : X ⨯ X ⟶ X) diag_σ) := cokernel.cokernelIso _ σ (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv]) #align category_theory.non_preadditive_abelian.is_colimit_σ CategoryTheory.NonPreadditiveAbelian.isColimitσ /-- This is the key identity satisfied by `σ`. -/ theorem σ_comp {X Y : C} (f : X ⟶ Y) : σ ≫ f = Limits.prod.map f f ≫ σ := by obtain ⟨g, hg⟩ := CokernelCofork.IsColimit.desc' isColimitσ (Limits.prod.map f f ≫ σ) (by rw [prod.diag_map_assoc, diag_σ, comp_zero]) suffices hfg : f = g by rw [← hg, Cofork.π_ofπ, hfg] calc f = f ≫ prod.lift (𝟙 Y) 0 ≫ σ := by rw [lift_σ, Category.comp_id] _ = prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f ≫ σ := by rw [lift_map_assoc] _ = prod.lift (𝟙 X) 0 ≫ σ ≫ g := by rw [← hg, CokernelCofork.π_ofπ] _ = g := by rw [← Category.assoc, lift_σ, Category.id_comp] #align category_theory.non_preadditive_abelian.σ_comp CategoryTheory.NonPreadditiveAbelian.σ_comp section -- We write `f - g` for `prod.lift f g ≫ σ`. /-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/ def hasSub {X Y : C} : Sub (X ⟶ Y) := ⟨fun f g => prod.lift f g ≫ σ⟩ #align category_theory.non_preadditive_abelian.has_sub CategoryTheory.NonPreadditiveAbelian.hasSub attribute [local instance] hasSub -- We write `-f` for `0 - f`. /-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/ def hasNeg {X Y : C} : Neg (X ⟶ Y) where neg := fun f => 0 - f #align category_theory.non_preadditive_abelian.has_neg CategoryTheory.NonPreadditiveAbelian.hasNeg attribute [local instance] hasNeg -- We write `f + g` for `f - (-g)`. /-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/ def hasAdd {X Y : C} : Add (X ⟶ Y) := ⟨fun f g => f - -g⟩ #align category_theory.non_preadditive_abelian.has_add CategoryTheory.NonPreadditiveAbelian.hasAdd attribute [local instance] hasAdd theorem sub_def {X Y : C} (a b : X ⟶ Y) : a - b = prod.lift a b ≫ σ := rfl #align category_theory.non_preadditive_abelian.sub_def CategoryTheory.NonPreadditiveAbelian.sub_def theorem add_def {X Y : C} (a b : X ⟶ Y) : a + b = a - -b := rfl #align category_theory.non_preadditive_abelian.add_def CategoryTheory.NonPreadditiveAbelian.add_def theorem neg_def {X Y : C} (a : X ⟶ Y) : -a = 0 - a := rfl #align category_theory.non_preadditive_abelian.neg_def CategoryTheory.NonPreadditiveAbelian.neg_def theorem sub_zero {X Y : C} (a : X ⟶ Y) : a - 0 = a := by rw [sub_def] conv_lhs => congr; congr; rw [← Category.comp_id a] case a.g => rw [show 0 = a ≫ (0 : Y ⟶ Y) by simp] rw [← prod.comp_lift, Category.assoc, lift_σ, Category.comp_id] #align category_theory.non_preadditive_abelian.sub_zero CategoryTheory.NonPreadditiveAbelian.sub_zero theorem sub_self {X Y : C} (a : X ⟶ Y) : a - a = 0 := by rw [sub_def, ← Category.comp_id a, ← prod.comp_lift, Category.assoc, diag_σ, comp_zero] #align category_theory.non_preadditive_abelian.sub_self CategoryTheory.NonPreadditiveAbelian.sub_self theorem lift_sub_lift {X Y : C} (a b c d : X ⟶ Y) : prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) := by simp only [sub_def] ext · rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst] · rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd] #align category_theory.non_preadditive_abelian.lift_sub_lift CategoryTheory.NonPreadditiveAbelian.lift_sub_lift theorem sub_sub_sub {X Y : C} (a b c d : X ⟶ Y) : a - c - (b - d) = a - b - (c - d) := by rw [sub_def, ← lift_sub_lift, sub_def, Category.assoc, σ_comp, prod.lift_map_assoc]; rfl #align category_theory.non_preadditive_abelian.sub_sub_sub CategoryTheory.NonPreadditiveAbelian.sub_sub_sub theorem neg_sub {X Y : C} (a b : X ⟶ Y) : -a - b = -b - a := by conv_lhs => rw [neg_def, ← sub_zero b, sub_sub_sub, sub_zero, ← neg_def] #align category_theory.non_preadditive_abelian.neg_sub CategoryTheory.NonPreadditiveAbelian.neg_sub theorem neg_neg {X Y : C} (a : X ⟶ Y) : - -a = a := by rw [neg_def, neg_def] conv_lhs => congr; rw [← sub_self a] rw [sub_sub_sub, sub_zero, sub_self, sub_zero] #align category_theory.non_preadditive_abelian.neg_neg CategoryTheory.NonPreadditiveAbelian.neg_neg theorem add_comm {X Y : C} (a b : X ⟶ Y) : a + b = b + a := by rw [add_def] conv_lhs => rw [← neg_neg a] rw [neg_def, neg_def, neg_def, sub_sub_sub] conv_lhs => congr next => skip rw [← neg_def, neg_sub] rw [sub_sub_sub, add_def, ← neg_def, neg_neg b, neg_def] #align category_theory.non_preadditive_abelian.add_comm CategoryTheory.NonPreadditiveAbelian.add_comm theorem add_neg {X Y : C} (a b : X ⟶ Y) : a + -b = a - b := by rw [add_def, neg_neg] #align category_theory.non_preadditive_abelian.add_neg CategoryTheory.NonPreadditiveAbelian.add_neg theorem add_neg_self {X Y : C} (a : X ⟶ Y) : a + -a = 0 := by rw [add_neg, sub_self] #align category_theory.non_preadditive_abelian.add_neg_self CategoryTheory.NonPreadditiveAbelian.add_neg_self theorem neg_add_self {X Y : C} (a : X ⟶ Y) : -a + a = 0 := by rw [add_comm, add_neg_self] #align category_theory.non_preadditive_abelian.neg_add_self CategoryTheory.NonPreadditiveAbelian.neg_add_self theorem neg_sub' {X Y : C} (a b : X ⟶ Y) : -(a - b) = -a + b := by rw [neg_def, neg_def] conv_lhs => rw [← sub_self (0 : X ⟶ Y)] rw [sub_sub_sub, add_def, neg_def] #align category_theory.non_preadditive_abelian.neg_sub' CategoryTheory.NonPreadditiveAbelian.neg_sub' theorem neg_add {X Y : C} (a b : X ⟶ Y) : -(a + b) = -a - b := by rw [add_def, neg_sub', add_neg] #align category_theory.non_preadditive_abelian.neg_add CategoryTheory.NonPreadditiveAbelian.neg_add theorem sub_add {X Y : C} (a b c : X ⟶ Y) : a - b + c = a - (b - c) := by rw [add_def, neg_def, sub_sub_sub, sub_zero] #align category_theory.non_preadditive_abelian.sub_add CategoryTheory.NonPreadditiveAbelian.sub_add theorem add_assoc {X Y : C} (a b c : X ⟶ Y) : a + b + c = a + (b + c) := by conv_lhs => congr; rw [add_def] rw [sub_add, ← add_neg, neg_sub', neg_neg] #align category_theory.non_preadditive_abelian.add_assoc CategoryTheory.NonPreadditiveAbelian.add_assoc theorem add_zero {X Y : C} (a : X ⟶ Y) : a + 0 = a := by rw [add_def, neg_def, sub_self, sub_zero] #align category_theory.non_preadditive_abelian.add_zero CategoryTheory.NonPreadditiveAbelian.add_zero theorem comp_sub {X Y Z : C} (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g - h) = f ≫ g - f ≫ h := by rw [sub_def, ← Category.assoc, prod.comp_lift, sub_def] #align category_theory.non_preadditive_abelian.comp_sub CategoryTheory.NonPreadditiveAbelian.comp_sub theorem sub_comp {X Y Z : C} (f g : X ⟶ Y) (h : Y ⟶ Z) : (f - g) ≫ h = f ≫ h - g ≫ h := by rw [sub_def, Category.assoc, σ_comp, ← Category.assoc, prod.lift_map, sub_def] #align category_theory.non_preadditive_abelian.sub_comp CategoryTheory.NonPreadditiveAbelian.sub_comp theorem comp_add (X Y Z : C) (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g + h) = f ≫ g + f ≫ h := by rw [add_def, comp_sub, neg_def, comp_sub, comp_zero, add_def, neg_def] #align category_theory.non_preadditive_abelian.comp_add CategoryTheory.NonPreadditiveAbelian.comp_add
Mathlib/CategoryTheory/Abelian/NonPreadditive.lean
439
440
theorem add_comp (X Y Z : C) (f g : X ⟶ Y) (h : Y ⟶ Z) : (f + g) ≫ h = f ≫ h + g ≫ h := by
rw [add_def, sub_comp, neg_def, sub_comp, zero_comp, add_def, neg_def]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad -/ import Mathlib.Algebra.Order.Ring.Defs import Mathlib.Data.Set.Finite #align_import order.filter.basic from "leanprover-community/mathlib"@"d4f691b9e5f94cfc64639973f3544c95f8d5d494" /-! # Theory of filters on sets ## Main definitions * `Filter` : filters on a set; * `Filter.principal` : filter of all sets containing a given set; * `Filter.map`, `Filter.comap` : operations on filters; * `Filter.Tendsto` : limit with respect to filters; * `Filter.Eventually` : `f.eventually p` means `{x | p x} ∈ f`; * `Filter.Frequently` : `f.frequently p` means `{x | ¬p x} ∉ f`; * `filter_upwards [h₁, ..., hₙ]` : a tactic that takes a list of proofs `hᵢ : sᵢ ∈ f`, and replaces a goal `s ∈ f` with `∀ x, x ∈ s₁ → ... → x ∈ sₙ → x ∈ s`; * `Filter.NeBot f` : a utility class stating that `f` is a non-trivial filter. Filters on a type `X` are sets of sets of `X` satisfying three conditions. They are mostly used to abstract two related kinds of ideas: * *limits*, including finite or infinite limits of sequences, finite or infinite limits of functions at a point or at infinity, etc... * *things happening eventually*, including things happening for large enough `n : ℕ`, or near enough a point `x`, or for close enough pairs of points, or things happening almost everywhere in the sense of measure theory. Dually, filters can also express the idea of *things happening often*: for arbitrarily large `n`, or at a point in any neighborhood of given a point etc... In this file, we define the type `Filter X` of filters on `X`, and endow it with a complete lattice structure. This structure is lifted from the lattice structure on `Set (Set X)` using the Galois insertion which maps a filter to its elements in one direction, and an arbitrary set of sets to the smallest filter containing it in the other direction. We also prove `Filter` is a monadic functor, with a push-forward operation `Filter.map` and a pull-back operation `Filter.comap` that form a Galois connections for the order on filters. The examples of filters appearing in the description of the two motivating ideas are: * `(Filter.atTop : Filter ℕ)` : made of sets of `ℕ` containing `{n | n ≥ N}` for some `N` * `𝓝 x` : made of neighborhoods of `x` in a topological space (defined in topology.basic) * `𝓤 X` : made of entourages of a uniform space (those space are generalizations of metric spaces defined in `Mathlib/Topology/UniformSpace/Basic.lean`) * `MeasureTheory.ae` : made of sets whose complement has zero measure with respect to `μ` (defined in `Mathlib/MeasureTheory/OuterMeasure/AE`) The general notion of limit of a map with respect to filters on the source and target types is `Filter.Tendsto`. It is defined in terms of the order and the push-forward operation. The predicate "happening eventually" is `Filter.Eventually`, and "happening often" is `Filter.Frequently`, whose definitions are immediate after `Filter` is defined (but they come rather late in this file in order to immediately relate them to the lattice structure). For instance, anticipating on Topology.Basic, the statement: "if a sequence `u` converges to some `x` and `u n` belongs to a set `M` for `n` large enough then `x` is in the closure of `M`" is formalized as: `Tendsto u atTop (𝓝 x) → (∀ᶠ n in atTop, u n ∈ M) → x ∈ closure M`, which is a special case of `mem_closure_of_tendsto` from Topology.Basic. ## Notations * `∀ᶠ x in f, p x` : `f.Eventually p`; * `∃ᶠ x in f, p x` : `f.Frequently p`; * `f =ᶠ[l] g` : `∀ᶠ x in l, f x = g x`; * `f ≤ᶠ[l] g` : `∀ᶠ x in l, f x ≤ g x`; * `𝓟 s` : `Filter.Principal s`, localized in `Filter`. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] Important note: Bourbaki requires that a filter on `X` cannot contain all sets of `X`, which we do *not* require. This gives `Filter X` better formal properties, in particular a bottom element `⊥` for its lattice structure, at the cost of including the assumption `[NeBot f]` in a number of lemmas and definitions. -/ set_option autoImplicit true open Function Set Order open scoped Classical universe u v w x y /-- A filter `F` on a type `α` is a collection of sets of `α` which contains the whole `α`, is upwards-closed, and is stable under intersection. We do not forbid this collection to be all sets of `α`. -/ structure Filter (α : Type*) where /-- The set of sets that belong to the filter. -/ sets : Set (Set α) /-- The set `Set.univ` belongs to any filter. -/ univ_sets : Set.univ ∈ sets /-- If a set belongs to a filter, then its superset belongs to the filter as well. -/ sets_of_superset {x y} : x ∈ sets → x ⊆ y → y ∈ sets /-- If two sets belong to a filter, then their intersection belongs to the filter as well. -/ inter_sets {x y} : x ∈ sets → y ∈ sets → x ∩ y ∈ sets #align filter Filter /-- If `F` is a filter on `α`, and `U` a subset of `α` then we can write `U ∈ F` as on paper. -/ instance {α : Type*} : Membership (Set α) (Filter α) := ⟨fun U F => U ∈ F.sets⟩ namespace Filter variable {α : Type u} {f g : Filter α} {s t : Set α} @[simp] protected theorem mem_mk {t : Set (Set α)} {h₁ h₂ h₃} : s ∈ mk t h₁ h₂ h₃ ↔ s ∈ t := Iff.rfl #align filter.mem_mk Filter.mem_mk @[simp] protected theorem mem_sets : s ∈ f.sets ↔ s ∈ f := Iff.rfl #align filter.mem_sets Filter.mem_sets instance inhabitedMem : Inhabited { s : Set α // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ #align filter.inhabited_mem Filter.inhabitedMem theorem filter_eq : ∀ {f g : Filter α}, f.sets = g.sets → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align filter.filter_eq Filter.filter_eq theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ #align filter.filter_eq_iff Filter.filter_eq_iff protected theorem ext_iff : f = g ↔ ∀ s, s ∈ f ↔ s ∈ g := by simp only [filter_eq_iff, ext_iff, Filter.mem_sets] #align filter.ext_iff Filter.ext_iff @[ext] protected theorem ext : (∀ s, s ∈ f ↔ s ∈ g) → f = g := Filter.ext_iff.2 #align filter.ext Filter.ext /-- An extensionality lemma that is useful for filters with good lemmas about `sᶜ ∈ f` (e.g., `Filter.comap`, `Filter.coprod`, `Filter.Coprod`, `Filter.cofinite`). -/ protected theorem coext (h : ∀ s, sᶜ ∈ f ↔ sᶜ ∈ g) : f = g := Filter.ext <| compl_surjective.forall.2 h #align filter.coext Filter.coext @[simp] theorem univ_mem : univ ∈ f := f.univ_sets #align filter.univ_mem Filter.univ_mem theorem mem_of_superset {x y : Set α} (hx : x ∈ f) (hxy : x ⊆ y) : y ∈ f := f.sets_of_superset hx hxy #align filter.mem_of_superset Filter.mem_of_superset instance : Trans (· ⊇ ·) ((· ∈ ·) : Set α → Filter α → Prop) (· ∈ ·) where trans h₁ h₂ := mem_of_superset h₂ h₁ theorem inter_mem {s t : Set α} (hs : s ∈ f) (ht : t ∈ f) : s ∩ t ∈ f := f.inter_sets hs ht #align filter.inter_mem Filter.inter_mem @[simp] theorem inter_mem_iff {s t : Set α} : s ∩ t ∈ f ↔ s ∈ f ∧ t ∈ f := ⟨fun h => ⟨mem_of_superset h inter_subset_left, mem_of_superset h inter_subset_right⟩, and_imp.2 inter_mem⟩ #align filter.inter_mem_iff Filter.inter_mem_iff theorem diff_mem {s t : Set α} (hs : s ∈ f) (ht : tᶜ ∈ f) : s \ t ∈ f := inter_mem hs ht #align filter.diff_mem Filter.diff_mem theorem univ_mem' (h : ∀ a, a ∈ s) : s ∈ f := mem_of_superset univ_mem fun x _ => h x #align filter.univ_mem' Filter.univ_mem' theorem mp_mem (hs : s ∈ f) (h : { x | x ∈ s → x ∈ t } ∈ f) : t ∈ f := mem_of_superset (inter_mem hs h) fun _ ⟨h₁, h₂⟩ => h₂ h₁ #align filter.mp_mem Filter.mp_mem theorem congr_sets (h : { x | x ∈ s ↔ x ∈ t } ∈ f) : s ∈ f ↔ t ∈ f := ⟨fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mp), fun hs => mp_mem hs (mem_of_superset h fun _ => Iff.mpr)⟩ #align filter.congr_sets Filter.congr_sets /-- Override `sets` field of a filter to provide better definitional equality. -/ protected def copy (f : Filter α) (S : Set (Set α)) (hmem : ∀ s, s ∈ S ↔ s ∈ f) : Filter α where sets := S univ_sets := (hmem _).2 univ_mem sets_of_superset h hsub := (hmem _).2 <| mem_of_superset ((hmem _).1 h) hsub inter_sets h₁ h₂ := (hmem _).2 <| inter_mem ((hmem _).1 h₁) ((hmem _).1 h₂) lemma copy_eq {S} (hmem : ∀ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem @[simp] lemma mem_copy {S hmem} : s ∈ f.copy S hmem ↔ s ∈ S := Iff.rfl @[simp] theorem biInter_mem {β : Type v} {s : β → Set α} {is : Set β} (hf : is.Finite) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := Finite.induction_on hf (by simp) fun _ _ hs => by simp [hs] #align filter.bInter_mem Filter.biInter_mem @[simp] theorem biInter_finset_mem {β : Type v} {s : β → Set α} (is : Finset β) : (⋂ i ∈ is, s i) ∈ f ↔ ∀ i ∈ is, s i ∈ f := biInter_mem is.finite_toSet #align filter.bInter_finset_mem Filter.biInter_finset_mem alias _root_.Finset.iInter_mem_sets := biInter_finset_mem #align finset.Inter_mem_sets Finset.iInter_mem_sets -- attribute [protected] Finset.iInter_mem_sets porting note: doesn't work @[simp] theorem sInter_mem {s : Set (Set α)} (hfin : s.Finite) : ⋂₀ s ∈ f ↔ ∀ U ∈ s, U ∈ f := by rw [sInter_eq_biInter, biInter_mem hfin] #align filter.sInter_mem Filter.sInter_mem @[simp] theorem iInter_mem {β : Sort v} {s : β → Set α} [Finite β] : (⋂ i, s i) ∈ f ↔ ∀ i, s i ∈ f := (sInter_mem (finite_range _)).trans forall_mem_range #align filter.Inter_mem Filter.iInter_mem theorem exists_mem_subset_iff : (∃ t ∈ f, t ⊆ s) ↔ s ∈ f := ⟨fun ⟨_, ht, ts⟩ => mem_of_superset ht ts, fun hs => ⟨s, hs, Subset.rfl⟩⟩ #align filter.exists_mem_subset_iff Filter.exists_mem_subset_iff theorem monotone_mem {f : Filter α} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst #align filter.monotone_mem Filter.monotone_mem theorem exists_mem_and_iff {P : Set α → Prop} {Q : Set α → Prop} (hP : Antitone P) (hQ : Antitone Q) : ((∃ u ∈ f, P u) ∧ ∃ u ∈ f, Q u) ↔ ∃ u ∈ f, P u ∧ Q u := by constructor · rintro ⟨⟨u, huf, hPu⟩, v, hvf, hQv⟩ exact ⟨u ∩ v, inter_mem huf hvf, hP inter_subset_left hPu, hQ inter_subset_right hQv⟩ · rintro ⟨u, huf, hPu, hQu⟩ exact ⟨⟨u, huf, hPu⟩, u, huf, hQu⟩ #align filter.exists_mem_and_iff Filter.exists_mem_and_iff theorem forall_in_swap {β : Type*} {p : Set α → β → Prop} : (∀ a ∈ f, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ f, p a b := Set.forall_in_swap #align filter.forall_in_swap Filter.forall_in_swap end Filter namespace Mathlib.Tactic open Lean Meta Elab Tactic /-- `filter_upwards [h₁, ⋯, hₙ]` replaces a goal of the form `s ∈ f` and terms `h₁ : t₁ ∈ f, ⋯, hₙ : tₙ ∈ f` with `∀ x, x ∈ t₁ → ⋯ → x ∈ tₙ → x ∈ s`. The list is an optional parameter, `[]` being its default value. `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ` is a short form for `{ filter_upwards [h₁, ⋯, hₙ], intros a₁ a₂ ⋯ aₖ }`. `filter_upwards [h₁, ⋯, hₙ] using e` is a short form for `{ filter_upwards [h1, ⋯, hn], exact e }`. Combining both shortcuts is done by writing `filter_upwards [h₁, ⋯, hₙ] with a₁ a₂ ⋯ aₖ using e`. Note that in this case, the `aᵢ` terms can be used in `e`. -/ syntax (name := filterUpwards) "filter_upwards" (" [" term,* "]")? (" with" (ppSpace colGt term:max)*)? (" using " term)? : tactic elab_rules : tactic | `(tactic| filter_upwards $[[$[$args],*]]? $[with $wth*]? $[using $usingArg]?) => do let config : ApplyConfig := {newGoals := ApplyNewGoals.nonDependentOnly} for e in args.getD #[] |>.reverse do let goal ← getMainGoal replaceMainGoal <| ← goal.withContext <| runTermElab do let m ← mkFreshExprMVar none let lem ← Term.elabTermEnsuringType (← ``(Filter.mp_mem $e $(← Term.exprToSyntax m))) (← goal.getType) goal.assign lem return [m.mvarId!] liftMetaTactic fun goal => do goal.apply (← mkConstWithFreshMVarLevels ``Filter.univ_mem') config evalTactic <|← `(tactic| dsimp (config := {zeta := false}) only [Set.mem_setOf_eq]) if let some l := wth then evalTactic <|← `(tactic| intro $[$l]*) if let some e := usingArg then evalTactic <|← `(tactic| exact $e) end Mathlib.Tactic namespace Filter variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {ι : Sort x} section Principal /-- The principal filter of `s` is the collection of all supersets of `s`. -/ def principal (s : Set α) : Filter α where sets := { t | s ⊆ t } univ_sets := subset_univ s sets_of_superset hx := Subset.trans hx inter_sets := subset_inter #align filter.principal Filter.principal @[inherit_doc] scoped notation "𝓟" => Filter.principal @[simp] theorem mem_principal {s t : Set α} : s ∈ 𝓟 t ↔ t ⊆ s := Iff.rfl #align filter.mem_principal Filter.mem_principal theorem mem_principal_self (s : Set α) : s ∈ 𝓟 s := Subset.rfl #align filter.mem_principal_self Filter.mem_principal_self end Principal open Filter section Join /-- The join of a filter of filters is defined by the relation `s ∈ join f ↔ {t | s ∈ t} ∈ f`. -/ def join (f : Filter (Filter α)) : Filter α where sets := { s | { t : Filter α | s ∈ t } ∈ f } univ_sets := by simp only [mem_setOf_eq, univ_sets, ← Filter.mem_sets, setOf_true] sets_of_superset hx xy := mem_of_superset hx fun f h => mem_of_superset h xy inter_sets hx hy := mem_of_superset (inter_mem hx hy) fun f ⟨h₁, h₂⟩ => inter_mem h₁ h₂ #align filter.join Filter.join @[simp] theorem mem_join {s : Set α} {f : Filter (Filter α)} : s ∈ join f ↔ { t | s ∈ t } ∈ f := Iff.rfl #align filter.mem_join Filter.mem_join end Join section Lattice variable {f g : Filter α} {s t : Set α} instance : PartialOrder (Filter α) where le f g := ∀ ⦃U : Set α⦄, U ∈ g → U ∈ f le_antisymm a b h₁ h₂ := filter_eq <| Subset.antisymm h₂ h₁ le_refl a := Subset.rfl le_trans a b c h₁ h₂ := Subset.trans h₂ h₁ theorem le_def : f ≤ g ↔ ∀ x ∈ g, x ∈ f := Iff.rfl #align filter.le_def Filter.le_def protected theorem not_le : ¬f ≤ g ↔ ∃ s ∈ g, s ∉ f := by simp_rw [le_def, not_forall, exists_prop] #align filter.not_le Filter.not_le /-- `GenerateSets g s`: `s` is in the filter closure of `g`. -/ inductive GenerateSets (g : Set (Set α)) : Set α → Prop | basic {s : Set α} : s ∈ g → GenerateSets g s | univ : GenerateSets g univ | superset {s t : Set α} : GenerateSets g s → s ⊆ t → GenerateSets g t | inter {s t : Set α} : GenerateSets g s → GenerateSets g t → GenerateSets g (s ∩ t) #align filter.generate_sets Filter.GenerateSets /-- `generate g` is the largest filter containing the sets `g`. -/ def generate (g : Set (Set α)) : Filter α where sets := {s | GenerateSets g s} univ_sets := GenerateSets.univ sets_of_superset := GenerateSets.superset inter_sets := GenerateSets.inter #align filter.generate Filter.generate lemma mem_generate_of_mem {s : Set <| Set α} {U : Set α} (h : U ∈ s) : U ∈ generate s := GenerateSets.basic h theorem le_generate_iff {s : Set (Set α)} {f : Filter α} : f ≤ generate s ↔ s ⊆ f.sets := Iff.intro (fun h _ hu => h <| GenerateSets.basic <| hu) fun h _ hu => hu.recOn (fun h' => h h') univ_mem (fun _ hxy hx => mem_of_superset hx hxy) fun _ _ hx hy => inter_mem hx hy #align filter.sets_iff_generate Filter.le_generate_iff theorem mem_generate_iff {s : Set <| Set α} {U : Set α} : U ∈ generate s ↔ ∃ t ⊆ s, Set.Finite t ∧ ⋂₀ t ⊆ U := by constructor <;> intro h · induction h with | @basic V V_in => exact ⟨{V}, singleton_subset_iff.2 V_in, finite_singleton _, (sInter_singleton _).subset⟩ | univ => exact ⟨∅, empty_subset _, finite_empty, subset_univ _⟩ | superset _ hVW hV => rcases hV with ⟨t, hts, ht, htV⟩ exact ⟨t, hts, ht, htV.trans hVW⟩ | inter _ _ hV hW => rcases hV, hW with ⟨⟨t, hts, ht, htV⟩, u, hus, hu, huW⟩ exact ⟨t ∪ u, union_subset hts hus, ht.union hu, (sInter_union _ _).subset.trans <| inter_subset_inter htV huW⟩ · rcases h with ⟨t, hts, tfin, h⟩ exact mem_of_superset ((sInter_mem tfin).2 fun V hV => GenerateSets.basic <| hts hV) h #align filter.mem_generate_iff Filter.mem_generate_iff @[simp] lemma generate_singleton (s : Set α) : generate {s} = 𝓟 s := le_antisymm (fun _t ht ↦ mem_of_superset (mem_generate_of_mem <| mem_singleton _) ht) <| le_generate_iff.2 <| singleton_subset_iff.2 Subset.rfl /-- `mkOfClosure s hs` constructs a filter on `α` whose elements set is exactly `s : Set (Set α)`, provided one gives the assumption `hs : (generate s).sets = s`. -/ protected def mkOfClosure (s : Set (Set α)) (hs : (generate s).sets = s) : Filter α where sets := s univ_sets := hs ▸ univ_mem sets_of_superset := hs ▸ mem_of_superset inter_sets := hs ▸ inter_mem #align filter.mk_of_closure Filter.mkOfClosure theorem mkOfClosure_sets {s : Set (Set α)} {hs : (generate s).sets = s} : Filter.mkOfClosure s hs = generate s := Filter.ext fun u => show u ∈ (Filter.mkOfClosure s hs).sets ↔ u ∈ (generate s).sets from hs.symm ▸ Iff.rfl #align filter.mk_of_closure_sets Filter.mkOfClosure_sets /-- Galois insertion from sets of sets into filters. -/ def giGenerate (α : Type*) : @GaloisInsertion (Set (Set α)) (Filter α)ᵒᵈ _ _ Filter.generate Filter.sets where gc _ _ := le_generate_iff le_l_u _ _ h := GenerateSets.basic h choice s hs := Filter.mkOfClosure s (le_antisymm hs <| le_generate_iff.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets #align filter.gi_generate Filter.giGenerate /-- The infimum of filters is the filter generated by intersections of elements of the two filters. -/ instance : Inf (Filter α) := ⟨fun f g : Filter α => { sets := { s | ∃ a ∈ f, ∃ b ∈ g, s = a ∩ b } univ_sets := ⟨_, univ_mem, _, univ_mem, by simp⟩ sets_of_superset := by rintro x y ⟨a, ha, b, hb, rfl⟩ xy refine ⟨a ∪ y, mem_of_superset ha subset_union_left, b ∪ y, mem_of_superset hb subset_union_left, ?_⟩ rw [← inter_union_distrib_right, union_eq_self_of_subset_left xy] inter_sets := by rintro x y ⟨a, ha, b, hb, rfl⟩ ⟨c, hc, d, hd, rfl⟩ refine ⟨a ∩ c, inter_mem ha hc, b ∩ d, inter_mem hb hd, ?_⟩ ac_rfl }⟩ theorem mem_inf_iff {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, s = t₁ ∩ t₂ := Iff.rfl #align filter.mem_inf_iff Filter.mem_inf_iff theorem mem_inf_of_left {f g : Filter α} {s : Set α} (h : s ∈ f) : s ∈ f ⊓ g := ⟨s, h, univ, univ_mem, (inter_univ s).symm⟩ #align filter.mem_inf_of_left Filter.mem_inf_of_left theorem mem_inf_of_right {f g : Filter α} {s : Set α} (h : s ∈ g) : s ∈ f ⊓ g := ⟨univ, univ_mem, s, h, (univ_inter s).symm⟩ #align filter.mem_inf_of_right Filter.mem_inf_of_right theorem inter_mem_inf {α : Type u} {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∩ t ∈ f ⊓ g := ⟨s, hs, t, ht, rfl⟩ #align filter.inter_mem_inf Filter.inter_mem_inf theorem mem_inf_of_inter {f g : Filter α} {s t u : Set α} (hs : s ∈ f) (ht : t ∈ g) (h : s ∩ t ⊆ u) : u ∈ f ⊓ g := mem_of_superset (inter_mem_inf hs ht) h #align filter.mem_inf_of_inter Filter.mem_inf_of_inter theorem mem_inf_iff_superset {f g : Filter α} {s : Set α} : s ∈ f ⊓ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ∩ t₂ ⊆ s := ⟨fun ⟨t₁, h₁, t₂, h₂, Eq⟩ => ⟨t₁, h₁, t₂, h₂, Eq ▸ Subset.rfl⟩, fun ⟨_, h₁, _, h₂, sub⟩ => mem_inf_of_inter h₁ h₂ sub⟩ #align filter.mem_inf_iff_superset Filter.mem_inf_iff_superset instance : Top (Filter α) := ⟨{ sets := { s | ∀ x, x ∈ s } univ_sets := fun x => mem_univ x sets_of_superset := fun hx hxy a => hxy (hx a) inter_sets := fun hx hy _ => mem_inter (hx _) (hy _) }⟩ theorem mem_top_iff_forall {s : Set α} : s ∈ (⊤ : Filter α) ↔ ∀ x, x ∈ s := Iff.rfl #align filter.mem_top_iff_forall Filter.mem_top_iff_forall @[simp] theorem mem_top {s : Set α} : s ∈ (⊤ : Filter α) ↔ s = univ := by rw [mem_top_iff_forall, eq_univ_iff_forall] #align filter.mem_top Filter.mem_top section CompleteLattice /- We lift the complete lattice along the Galois connection `generate` / `sets`. Unfortunately, we want to have different definitional equalities for some lattice operations. So we define them upfront and change the lattice operations for the complete lattice instance. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter α) := { @OrderDual.instCompleteLattice _ (giGenerate α).liftCompleteLattice with le := (· ≤ ·) top := ⊤ le_top := fun _ _s hs => (mem_top.1 hs).symm ▸ univ_mem inf := (· ⊓ ·) inf_le_left := fun _ _ _ => mem_inf_of_left inf_le_right := fun _ _ _ => mem_inf_of_right le_inf := fun _ _ _ h₁ h₂ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm ▸ inter_mem (h₁ ha) (h₂ hb) sSup := join ∘ 𝓟 le_sSup := fun _ _f hf _s hs => hs hf sSup_le := fun _ _f hf _s hs _g hg => hf _ hg hs } instance : Inhabited (Filter α) := ⟨⊥⟩ end CompleteLattice /-- A filter is `NeBot` if it is not equal to `⊥`, or equivalently the empty set does not belong to the filter. Bourbaki include this assumption in the definition of a filter but we prefer to have a `CompleteLattice` structure on `Filter _`, so we use a typeclass argument in lemmas instead. -/ class NeBot (f : Filter α) : Prop where /-- The filter is nontrivial: `f ≠ ⊥` or equivalently, `∅ ∉ f`. -/ ne' : f ≠ ⊥ #align filter.ne_bot Filter.NeBot theorem neBot_iff {f : Filter α} : NeBot f ↔ f ≠ ⊥ := ⟨fun h => h.1, fun h => ⟨h⟩⟩ #align filter.ne_bot_iff Filter.neBot_iff theorem NeBot.ne {f : Filter α} (hf : NeBot f) : f ≠ ⊥ := hf.ne' #align filter.ne_bot.ne Filter.NeBot.ne @[simp] theorem not_neBot {f : Filter α} : ¬f.NeBot ↔ f = ⊥ := neBot_iff.not_left #align filter.not_ne_bot Filter.not_neBot theorem NeBot.mono {f g : Filter α} (hf : NeBot f) (hg : f ≤ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ #align filter.ne_bot.mono Filter.NeBot.mono theorem neBot_of_le {f g : Filter α} [hf : NeBot f] (hg : f ≤ g) : NeBot g := hf.mono hg #align filter.ne_bot_of_le Filter.neBot_of_le @[simp] theorem sup_neBot {f g : Filter α} : NeBot (f ⊔ g) ↔ NeBot f ∨ NeBot g := by simp only [neBot_iff, not_and_or, Ne, sup_eq_bot_iff] #align filter.sup_ne_bot Filter.sup_neBot theorem not_disjoint_self_iff : ¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] #align filter.not_disjoint_self_iff Filter.not_disjoint_self_iff theorem bot_sets_eq : (⊥ : Filter α).sets = univ := rfl #align filter.bot_sets_eq Filter.bot_sets_eq /-- Either `f = ⊥` or `Filter.NeBot f`. This is a version of `eq_or_ne` that uses `Filter.NeBot` as the second alternative, to be used as an instance. -/ theorem eq_or_neBot (f : Filter α) : f = ⊥ ∨ NeBot f := (eq_or_ne f ⊥).imp_right NeBot.mk theorem sup_sets_eq {f g : Filter α} : (f ⊔ g).sets = f.sets ∩ g.sets := (giGenerate α).gc.u_inf #align filter.sup_sets_eq Filter.sup_sets_eq theorem sSup_sets_eq {s : Set (Filter α)} : (sSup s).sets = ⋂ f ∈ s, (f : Filter α).sets := (giGenerate α).gc.u_sInf #align filter.Sup_sets_eq Filter.sSup_sets_eq theorem iSup_sets_eq {f : ι → Filter α} : (iSup f).sets = ⋂ i, (f i).sets := (giGenerate α).gc.u_iInf #align filter.supr_sets_eq Filter.iSup_sets_eq theorem generate_empty : Filter.generate ∅ = (⊤ : Filter α) := (giGenerate α).gc.l_bot #align filter.generate_empty Filter.generate_empty theorem generate_univ : Filter.generate univ = (⊥ : Filter α) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) #align filter.generate_univ Filter.generate_univ theorem generate_union {s t : Set (Set α)} : Filter.generate (s ∪ t) = Filter.generate s ⊓ Filter.generate t := (giGenerate α).gc.l_sup #align filter.generate_union Filter.generate_union theorem generate_iUnion {s : ι → Set (Set α)} : Filter.generate (⋃ i, s i) = ⨅ i, Filter.generate (s i) := (giGenerate α).gc.l_iSup #align filter.generate_Union Filter.generate_iUnion @[simp] theorem mem_bot {s : Set α} : s ∈ (⊥ : Filter α) := trivial #align filter.mem_bot Filter.mem_bot @[simp] theorem mem_sup {f g : Filter α} {s : Set α} : s ∈ f ⊔ g ↔ s ∈ f ∧ s ∈ g := Iff.rfl #align filter.mem_sup Filter.mem_sup theorem union_mem_sup {f g : Filter α} {s t : Set α} (hs : s ∈ f) (ht : t ∈ g) : s ∪ t ∈ f ⊔ g := ⟨mem_of_superset hs subset_union_left, mem_of_superset ht subset_union_right⟩ #align filter.union_mem_sup Filter.union_mem_sup @[simp] theorem mem_sSup {x : Set α} {s : Set (Filter α)} : x ∈ sSup s ↔ ∀ f ∈ s, x ∈ (f : Filter α) := Iff.rfl #align filter.mem_Sup Filter.mem_sSup @[simp] theorem mem_iSup {x : Set α} {f : ι → Filter α} : x ∈ iSup f ↔ ∀ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, iff_self_iff, mem_iInter] #align filter.mem_supr Filter.mem_iSup @[simp] theorem iSup_neBot {f : ι → Filter α} : (⨆ i, f i).NeBot ↔ ∃ i, (f i).NeBot := by simp [neBot_iff] #align filter.supr_ne_bot Filter.iSup_neBot theorem iInf_eq_generate (s : ι → Filter α) : iInf s = generate (⋃ i, (s i).sets) := show generate _ = generate _ from congr_arg _ <| congr_arg sSup <| (range_comp _ _).symm #align filter.infi_eq_generate Filter.iInf_eq_generate theorem mem_iInf_of_mem {f : ι → Filter α} (i : ι) {s} (hs : s ∈ f i) : s ∈ ⨅ i, f i := iInf_le f i hs #align filter.mem_infi_of_mem Filter.mem_iInf_of_mem theorem mem_iInf_of_iInter {ι} {s : ι → Filter α} {U : Set α} {I : Set ι} (I_fin : I.Finite) {V : I → Set α} (hV : ∀ i, V i ∈ s i) (hU : ⋂ i, V i ⊆ U) : U ∈ ⨅ i, s i := by haveI := I_fin.fintype refine mem_of_superset (iInter_mem.2 fun i => ?_) hU exact mem_iInf_of_mem (i : ι) (hV _) #align filter.mem_infi_of_Inter Filter.mem_iInf_of_iInter theorem mem_iInf {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : I → Set α, (∀ i, V i ∈ s i) ∧ U = ⋂ i, V i := by constructor · rw [iInf_eq_generate, mem_generate_iff] rintro ⟨t, tsub, tfin, tinter⟩ rcases eq_finite_iUnion_of_finite_subset_iUnion tfin tsub with ⟨I, Ifin, σ, σfin, σsub, rfl⟩ rw [sInter_iUnion] at tinter set V := fun i => U ∪ ⋂₀ σ i with hV have V_in : ∀ i, V i ∈ s i := by rintro i have : ⋂₀ σ i ∈ s i := by rw [sInter_mem (σfin _)] apply σsub exact mem_of_superset this subset_union_right refine ⟨I, Ifin, V, V_in, ?_⟩ rwa [hV, ← union_iInter, union_eq_self_of_subset_right] · rintro ⟨I, Ifin, V, V_in, rfl⟩ exact mem_iInf_of_iInter Ifin V_in Subset.rfl #align filter.mem_infi Filter.mem_iInf theorem mem_iInf' {ι} {s : ι → Filter α} {U : Set α} : (U ∈ ⨅ i, s i) ↔ ∃ I : Set ι, I.Finite ∧ ∃ V : ι → Set α, (∀ i, V i ∈ s i) ∧ (∀ i ∉ I, V i = univ) ∧ (U = ⋂ i ∈ I, V i) ∧ U = ⋂ i, V i := by simp only [mem_iInf, SetCoe.forall', biInter_eq_iInter] refine ⟨?_, fun ⟨I, If, V, hVs, _, hVU, _⟩ => ⟨I, If, fun i => V i, fun i => hVs i, hVU⟩⟩ rintro ⟨I, If, V, hV, rfl⟩ refine ⟨I, If, fun i => if hi : i ∈ I then V ⟨i, hi⟩ else univ, fun i => ?_, fun i hi => ?_, ?_⟩ · dsimp only split_ifs exacts [hV _, univ_mem] · exact dif_neg hi · simp only [iInter_dite, biInter_eq_iInter, dif_pos (Subtype.coe_prop _), Subtype.coe_eta, iInter_univ, inter_univ, eq_self_iff_true, true_and_iff] #align filter.mem_infi' Filter.mem_iInf' theorem exists_iInter_of_mem_iInf {ι : Type*} {α : Type*} {f : ι → Filter α} {s} (hs : s ∈ ⨅ i, f i) : ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := let ⟨_, _, V, hVs, _, _, hVU'⟩ := mem_iInf'.1 hs; ⟨V, hVs, hVU'⟩ #align filter.exists_Inter_of_mem_infi Filter.exists_iInter_of_mem_iInf theorem mem_iInf_of_finite {ι : Type*} [Finite ι] {α : Type*} {f : ι → Filter α} (s) : (s ∈ ⨅ i, f i) ↔ ∃ t : ι → Set α, (∀ i, t i ∈ f i) ∧ s = ⋂ i, t i := by refine ⟨exists_iInter_of_mem_iInf, ?_⟩ rintro ⟨t, ht, rfl⟩ exact iInter_mem.2 fun i => mem_iInf_of_mem i (ht i) #align filter.mem_infi_of_finite Filter.mem_iInf_of_finite @[simp] theorem le_principal_iff {s : Set α} {f : Filter α} : f ≤ 𝓟 s ↔ s ∈ f := ⟨fun h => h Subset.rfl, fun hs _ ht => mem_of_superset hs ht⟩ #align filter.le_principal_iff Filter.le_principal_iff theorem Iic_principal (s : Set α) : Iic (𝓟 s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff #align filter.Iic_principal Filter.Iic_principal theorem principal_mono {s t : Set α} : 𝓟 s ≤ 𝓟 t ↔ s ⊆ t := by simp only [le_principal_iff, iff_self_iff, mem_principal] #align filter.principal_mono Filter.principal_mono @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (𝓟 : Set α → Filter α) := fun _ _ => principal_mono.2 #align filter.monotone_principal Filter.monotone_principal @[simp] theorem principal_eq_iff_eq {s t : Set α} : 𝓟 s = 𝓟 t ↔ s = t := by simp only [le_antisymm_iff, le_principal_iff, mem_principal]; rfl #align filter.principal_eq_iff_eq Filter.principal_eq_iff_eq @[simp] theorem join_principal_eq_sSup {s : Set (Filter α)} : join (𝓟 s) = sSup s := rfl #align filter.join_principal_eq_Sup Filter.join_principal_eq_sSup @[simp] theorem principal_univ : 𝓟 (univ : Set α) = ⊤ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] #align filter.principal_univ Filter.principal_univ @[simp] theorem principal_empty : 𝓟 (∅ : Set α) = ⊥ := bot_unique fun _ _ => empty_subset _ #align filter.principal_empty Filter.principal_empty theorem generate_eq_biInf (S : Set (Set α)) : generate S = ⨅ s ∈ S, 𝓟 s := eq_of_forall_le_iff fun f => by simp [le_generate_iff, le_principal_iff, subset_def] #align filter.generate_eq_binfi Filter.generate_eq_biInf /-! ### Lattice equations -/ theorem empty_mem_iff_bot {f : Filter α} : ∅ ∈ f ↔ f = ⊥ := ⟨fun h => bot_unique fun s _ => mem_of_superset h (empty_subset s), fun h => h.symm ▸ mem_bot⟩ #align filter.empty_mem_iff_bot Filter.empty_mem_iff_bot theorem nonempty_of_mem {f : Filter α} [hf : NeBot f] {s : Set α} (hs : s ∈ f) : s.Nonempty := s.eq_empty_or_nonempty.elim (fun h => absurd hs (h.symm ▸ mt empty_mem_iff_bot.mp hf.1)) id #align filter.nonempty_of_mem Filter.nonempty_of_mem theorem NeBot.nonempty_of_mem {f : Filter α} (hf : NeBot f) {s : Set α} (hs : s ∈ f) : s.Nonempty := @Filter.nonempty_of_mem α f hf s hs #align filter.ne_bot.nonempty_of_mem Filter.NeBot.nonempty_of_mem @[simp] theorem empty_not_mem (f : Filter α) [NeBot f] : ¬∅ ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl #align filter.empty_not_mem Filter.empty_not_mem theorem nonempty_of_neBot (f : Filter α) [NeBot f] : Nonempty α := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) #align filter.nonempty_of_ne_bot Filter.nonempty_of_neBot theorem compl_not_mem {f : Filter α} {s : Set α} [NeBot f] (h : s ∈ f) : sᶜ ∉ f := fun hsc => (nonempty_of_mem (inter_mem h hsc)).ne_empty <| inter_compl_self s #align filter.compl_not_mem Filter.compl_not_mem theorem filter_eq_bot_of_isEmpty [IsEmpty α] (f : Filter α) : f = ⊥ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim #align filter.filter_eq_bot_of_is_empty Filter.filter_eq_bot_of_isEmpty protected lemma disjoint_iff {f g : Filter α} : Disjoint f g ↔ ∃ s ∈ f, ∃ t ∈ g, Disjoint s t := by simp only [disjoint_iff, ← empty_mem_iff_bot, mem_inf_iff, inf_eq_inter, bot_eq_empty, @eq_comm _ ∅] #align filter.disjoint_iff Filter.disjoint_iff theorem disjoint_of_disjoint_of_mem {f g : Filter α} {s t : Set α} (h : Disjoint s t) (hs : s ∈ f) (ht : t ∈ g) : Disjoint f g := Filter.disjoint_iff.mpr ⟨s, hs, t, ht, h⟩ #align filter.disjoint_of_disjoint_of_mem Filter.disjoint_of_disjoint_of_mem theorem NeBot.not_disjoint (hf : f.NeBot) (hs : s ∈ f) (ht : t ∈ f) : ¬Disjoint s t := fun h => not_disjoint_self_iff.2 hf <| Filter.disjoint_iff.2 ⟨s, hs, t, ht, h⟩ #align filter.ne_bot.not_disjoint Filter.NeBot.not_disjoint theorem inf_eq_bot_iff {f g : Filter α} : f ⊓ g = ⊥ ↔ ∃ U ∈ f, ∃ V ∈ g, U ∩ V = ∅ := by simp only [← disjoint_iff, Filter.disjoint_iff, Set.disjoint_iff_inter_eq_empty] #align filter.inf_eq_bot_iff Filter.inf_eq_bot_iff theorem _root_.Pairwise.exists_mem_filter_of_disjoint {ι : Type*} [Finite ι] {l : ι → Filter α} (hd : Pairwise (Disjoint on l)) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ Pairwise (Disjoint on s) := by have : Pairwise fun i j => ∃ (s : {s // s ∈ l i}) (t : {t // t ∈ l j}), Disjoint s.1 t.1 := by simpa only [Pairwise, Function.onFun, Filter.disjoint_iff, exists_prop, Subtype.exists] using hd choose! s t hst using this refine ⟨fun i => ⋂ j, @s i j ∩ @t j i, fun i => ?_, fun i j hij => ?_⟩ exacts [iInter_mem.2 fun j => inter_mem (@s i j).2 (@t j i).2, (hst hij).mono ((iInter_subset _ j).trans inter_subset_left) ((iInter_subset _ i).trans inter_subset_right)] #align pairwise.exists_mem_filter_of_disjoint Pairwise.exists_mem_filter_of_disjoint theorem _root_.Set.PairwiseDisjoint.exists_mem_filter {ι : Type*} {l : ι → Filter α} {t : Set ι} (hd : t.PairwiseDisjoint l) (ht : t.Finite) : ∃ s : ι → Set α, (∀ i, s i ∈ l i) ∧ t.PairwiseDisjoint s := by haveI := ht.to_subtype rcases (hd.subtype _ _).exists_mem_filter_of_disjoint with ⟨s, hsl, hsd⟩ lift s to (i : t) → {s // s ∈ l i} using hsl rcases @Subtype.exists_pi_extension ι (fun i => { s // s ∈ l i }) _ _ s with ⟨s, rfl⟩ exact ⟨fun i => s i, fun i => (s i).2, hsd.set_of_subtype _ _⟩ #align set.pairwise_disjoint.exists_mem_filter Set.PairwiseDisjoint.exists_mem_filter /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty α] : Unique (Filter α) where default := ⊥ uniq := filter_eq_bot_of_isEmpty #align filter.unique Filter.unique theorem NeBot.nonempty (f : Filter α) [hf : f.NeBot] : Nonempty α := not_isEmpty_iff.mp fun _ ↦ hf.ne (Subsingleton.elim _ _) /-- There are only two filters on a `Subsingleton`: `⊥` and `⊤`. If the type is empty, then they are equal. -/ theorem eq_top_of_neBot [Subsingleton α] (l : Filter α) [NeBot l] : l = ⊤ := by refine top_unique fun s hs => ?_ obtain rfl : s = univ := Subsingleton.eq_univ_of_nonempty (nonempty_of_mem hs) exact univ_mem #align filter.eq_top_of_ne_bot Filter.eq_top_of_neBot theorem forall_mem_nonempty_iff_neBot {f : Filter α} : (∀ s : Set α, s ∈ f → s.Nonempty) ↔ NeBot f := ⟨fun h => ⟨fun hf => not_nonempty_empty (h ∅ <| hf.symm ▸ mem_bot)⟩, @nonempty_of_mem _ _⟩ #align filter.forall_mem_nonempty_iff_ne_bot Filter.forall_mem_nonempty_iff_neBot instance instNontrivialFilter [Nonempty α] : Nontrivial (Filter α) := ⟨⟨⊤, ⊥, NeBot.ne <| forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty]⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter α) ↔ Nonempty α := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter α) inferInstance, @Filter.instNontrivialFilter α⟩ #align filter.nontrivial_iff_nonempty Filter.nontrivial_iff_nonempty theorem eq_sInf_of_mem_iff_exists_mem {S : Set (Filter α)} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ f ∈ S, s ∈ f) : l = sInf S := le_antisymm (le_sInf fun f hf _ hs => h.2 ⟨f, hf, hs⟩) fun _ hs => let ⟨_, hf, hs⟩ := h.1 hs; (sInf_le hf) hs #align filter.eq_Inf_of_mem_iff_exists_mem Filter.eq_sInf_of_mem_iff_exists_mem theorem eq_iInf_of_mem_iff_exists_mem {f : ι → Filter α} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, s ∈ f i) : l = iInf f := eq_sInf_of_mem_iff_exists_mem <| h.trans exists_range_iff.symm #align filter.eq_infi_of_mem_iff_exists_mem Filter.eq_iInf_of_mem_iff_exists_mem theorem eq_biInf_of_mem_iff_exists_mem {f : ι → Filter α} {p : ι → Prop} {l : Filter α} (h : ∀ {s}, s ∈ l ↔ ∃ i, p i ∧ s ∈ f i) : l = ⨅ (i) (_ : p i), f i := by rw [iInf_subtype'] exact eq_iInf_of_mem_iff_exists_mem fun {_} => by simp only [Subtype.exists, h, exists_prop] #align filter.eq_binfi_of_mem_iff_exists_mem Filter.eq_biInf_of_mem_iff_exists_memₓ theorem iInf_sets_eq {f : ι → Filter α} (h : Directed (· ≥ ·) f) [ne : Nonempty ι] : (iInf f).sets = ⋃ i, (f i).sets := let ⟨i⟩ := ne let u := { sets := ⋃ i, (f i).sets univ_sets := mem_iUnion.2 ⟨i, univ_mem⟩ sets_of_superset := by simp only [mem_iUnion, exists_imp] exact fun i hx hxy => ⟨i, mem_of_superset hx hxy⟩ inter_sets := by simp only [mem_iUnion, exists_imp] intro x y a hx b hy rcases h a b with ⟨c, ha, hb⟩ exact ⟨c, inter_mem (ha hx) (hb hy)⟩ } have : u = iInf f := eq_iInf_of_mem_iff_exists_mem mem_iUnion -- Porting note: it was just `congr_arg filter.sets this.symm` (congr_arg Filter.sets this.symm).trans <| by simp only #align filter.infi_sets_eq Filter.iInf_sets_eq theorem mem_iInf_of_directed {f : ι → Filter α} (h : Directed (· ≥ ·) f) [Nonempty ι] (s) : s ∈ iInf f ↔ ∃ i, s ∈ f i := by simp only [← Filter.mem_sets, iInf_sets_eq h, mem_iUnion] #align filter.mem_infi_of_directed Filter.mem_iInf_of_directed theorem mem_biInf_of_directed {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) {t : Set α} : (t ∈ ⨅ i ∈ s, f i) ↔ ∃ i ∈ s, t ∈ f i := by haveI := ne.to_subtype simp_rw [iInf_subtype', mem_iInf_of_directed h.directed_val, Subtype.exists, exists_prop] #align filter.mem_binfi_of_directed Filter.mem_biInf_of_directed theorem biInf_sets_eq {f : β → Filter α} {s : Set β} (h : DirectedOn (f ⁻¹'o (· ≥ ·)) s) (ne : s.Nonempty) : (⨅ i ∈ s, f i).sets = ⋃ i ∈ s, (f i).sets := ext fun t => by simp [mem_biInf_of_directed h ne] #align filter.binfi_sets_eq Filter.biInf_sets_eq theorem iInf_sets_eq_finite {ι : Type*} (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset ι, (⨅ i ∈ t, f i).sets := by rw [iInf_eq_iInf_finset, iInf_sets_eq] exact directed_of_isDirected_le fun _ _ => biInf_mono #align filter.infi_sets_eq_finite Filter.iInf_sets_eq_finite theorem iInf_sets_eq_finite' (f : ι → Filter α) : (⨅ i, f i).sets = ⋃ t : Finset (PLift ι), (⨅ i ∈ t, f (PLift.down i)).sets := by rw [← iInf_sets_eq_finite, ← Equiv.plift.surjective.iInf_comp, Equiv.plift_apply] #align filter.infi_sets_eq_finite' Filter.iInf_sets_eq_finite' theorem mem_iInf_finite {ι : Type*} {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset ι, s ∈ ⨅ i ∈ t, f i := (Set.ext_iff.1 (iInf_sets_eq_finite f) s).trans mem_iUnion #align filter.mem_infi_finite Filter.mem_iInf_finite theorem mem_iInf_finite' {f : ι → Filter α} (s) : s ∈ iInf f ↔ ∃ t : Finset (PLift ι), s ∈ ⨅ i ∈ t, f (PLift.down i) := (Set.ext_iff.1 (iInf_sets_eq_finite' f) s).trans mem_iUnion #align filter.mem_infi_finite' Filter.mem_iInf_finite' @[simp] theorem sup_join {f₁ f₂ : Filter (Filter α)} : join f₁ ⊔ join f₂ = join (f₁ ⊔ f₂) := Filter.ext fun x => by simp only [mem_sup, mem_join] #align filter.sup_join Filter.sup_join @[simp] theorem iSup_join {ι : Sort w} {f : ι → Filter (Filter α)} : ⨆ x, join (f x) = join (⨆ x, f x) := Filter.ext fun x => by simp only [mem_iSup, mem_join] #align filter.supr_join Filter.iSup_join instance : DistribLattice (Filter α) := { Filter.instCompleteLatticeFilter with le_sup_inf := by intro x y z s simp only [and_assoc, mem_inf_iff, mem_sup, exists_prop, exists_imp, and_imp] rintro hs t₁ ht₁ t₂ ht₂ rfl exact ⟨t₁, x.sets_of_superset hs inter_subset_left, ht₁, t₂, x.sets_of_superset hs inter_subset_right, ht₂, rfl⟩ } -- The dual version does not hold! `Filter α` is not a `CompleteDistribLattice`. -/ instance : Coframe (Filter α) := { Filter.instCompleteLatticeFilter with iInf_sup_le_sup_sInf := fun f s t ⟨h₁, h₂⟩ => by rw [iInf_subtype'] rw [sInf_eq_iInf', iInf_sets_eq_finite, mem_iUnion] at h₂ obtain ⟨u, hu⟩ := h₂ rw [← Finset.inf_eq_iInf] at hu suffices ⨅ i : s, f ⊔ ↑i ≤ f ⊔ u.inf fun i => ↑i from this ⟨h₁, hu⟩ refine Finset.induction_on u (le_sup_of_le_right le_top) ?_ rintro ⟨i⟩ u _ ih rw [Finset.inf_insert, sup_inf_left] exact le_inf (iInf_le _ _) ih } theorem mem_iInf_finset {s : Finset α} {f : α → Filter β} {t : Set β} : (t ∈ ⨅ a ∈ s, f a) ↔ ∃ p : α → Set β, (∀ a ∈ s, p a ∈ f a) ∧ t = ⋂ a ∈ s, p a := by simp only [← Finset.set_biInter_coe, biInter_eq_iInter, iInf_subtype'] refine ⟨fun h => ?_, ?_⟩ · rcases (mem_iInf_of_finite _).1 h with ⟨p, hp, rfl⟩ refine ⟨fun a => if h : a ∈ s then p ⟨a, h⟩ else univ, fun a ha => by simpa [ha] using hp ⟨a, ha⟩, ?_⟩ refine iInter_congr_of_surjective id surjective_id ?_ rintro ⟨a, ha⟩ simp [ha] · rintro ⟨p, hpf, rfl⟩ exact iInter_mem.2 fun a => mem_iInf_of_mem a (hpf a a.2) #align filter.mem_infi_finset Filter.mem_iInf_finset /-- If `f : ι → Filter α` is directed, `ι` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed` for a version assuming `Nonempty α` instead of `Nonempty ι`. -/ theorem iInf_neBot_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : (∀ i, NeBot (f i)) → NeBot (iInf f) := not_imp_not.1 <| by simpa only [not_forall, not_neBot, ← empty_mem_iff_bot, mem_iInf_of_directed hd] using id #align filter.infi_ne_bot_of_directed' Filter.iInf_neBot_of_directed' /-- If `f : ι → Filter α` is directed, `α` is not empty, and `∀ i, f i ≠ ⊥`, then `iInf f ≠ ⊥`. See also `iInf_neBot_of_directed'` for a version assuming `Nonempty ι` instead of `Nonempty α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb #align filter.infi_ne_bot_of_directed Filter.iInf_neBot_of_directed theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ #align filter.Inf_ne_bot_of_directed' Filter.sInf_neBot_of_directed' theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ #align filter.Inf_ne_bot_of_directed Filter.sInf_neBot_of_directed theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ #align filter.infi_ne_bot_iff_of_directed' Filter.iInf_neBot_iff_of_directed' theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ #align filter.infi_ne_bot_iff_of_directed Filter.iInf_neBot_iff_of_directed @[elab_as_elim] theorem iInf_sets_induct {f : ι → Filter α} {s : Set α} (hs : s ∈ iInf f) {p : Set α → Prop} (uni : p univ) (ins : ∀ {i s₁ s₂}, s₁ ∈ f i → p s₂ → p (s₁ ∩ s₂)) : p s := by rw [mem_iInf_finite'] at hs simp only [← Finset.inf_eq_iInf] at hs rcases hs with ⟨is, his⟩ induction is using Finset.induction_on generalizing s with | empty => rwa [mem_top.1 his] | insert _ ih => rw [Finset.inf_insert, mem_inf_iff] at his rcases his with ⟨s₁, hs₁, s₂, hs₂, rfl⟩ exact ins hs₁ (ih hs₂) #align filter.infi_sets_induct Filter.iInf_sets_induct /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) #align filter.inf_principal Filter.inf_principal @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] #align filter.sup_principal Filter.sup_principal @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] #align filter.supr_principal Filter.iSup_principal @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff #align filter.principal_eq_bot_iff Filter.principal_eq_bot_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm #align filter.principal_ne_bot_iff Filter.principal_neBot_iff alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff #align set.nonempty.principal_ne_bot Set.Nonempty.principal_neBot theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] #align filter.is_compl_principal Filter.isCompl_principal theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] #align filter.mem_inf_principal' Filter.mem_inf_principal' lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] #align filter.mem_inf_principal Filter.mem_inf_principal lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] #align filter.supr_inf_principal Filter.iSup_inf_principal theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] #align filter.inf_principal_eq_bot Filter.inf_principal_eq_bot theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h #align filter.mem_of_eq_bot Filter.mem_of_eq_bot theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ #align filter.diff_mem_inf_principal_compl Filter.diff_mem_inf_principal_compl theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] #align filter.principal_le_iff Filter.principal_le_iff @[simp] theorem iInf_principal_finset {ι : Type w} (s : Finset ι) (f : ι → Set α) : ⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by induction' s using Finset.induction_on with i s _ hs · simp · rw [Finset.iInf_insert, Finset.set_biInter_insert, hs, inf_principal] #align filter.infi_principal_finset Filter.iInf_principal_finset theorem iInf_principal {ι : Sort w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := by cases nonempty_fintype (PLift ι) rw [← iInf_plift_down, ← iInter_plift_down] simpa using iInf_principal_finset Finset.univ (f <| PLift.down ·) /-- A special case of `iInf_principal` that is safe to mark `simp`. -/ @[simp] theorem iInf_principal' {ι : Type w} [Finite ι] (f : ι → Set α) : ⨅ i, 𝓟 (f i) = 𝓟 (⋂ i, f i) := iInf_principal _ #align filter.infi_principal Filter.iInf_principal theorem iInf_principal_finite {ι : Type w} {s : Set ι} (hs : s.Finite) (f : ι → Set α) : ⨅ i ∈ s, 𝓟 (f i) = 𝓟 (⋂ i ∈ s, f i) := by lift s to Finset ι using hs exact mod_cast iInf_principal_finset s f #align filter.infi_principal_finite Filter.iInf_principal_finite end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs #align filter.join_mono Filter.join_mono /-! ### Eventually -/ /-- `f.Eventually p` or `∀ᶠ x in f, p x` mean that `{x | p x} ∈ f`. E.g., `∀ᶠ x in atTop, p x` means that `p` holds true for sufficiently large `x`. -/ protected def Eventually (p : α → Prop) (f : Filter α) : Prop := { x | p x } ∈ f #align filter.eventually Filter.Eventually @[inherit_doc Filter.Eventually] notation3 "∀ᶠ "(...)" in "f", "r:(scoped p => Filter.Eventually p f) => r theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl #align filter.eventually_iff Filter.eventually_iff @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl #align filter.eventually_mem_set Filter.eventually_mem_set protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h #align filter.ext' Filter.ext' theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp #align filter.eventually.filter_mono Filter.Eventually.filter_mono theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h #align filter.eventually_of_mem Filter.eventually_of_mem protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem #align filter.eventually.and Filter.Eventually.and @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem #align filter.eventually_true Filter.eventually_true theorem eventually_of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp #align filter.eventually_of_forall Filter.eventually_of_forall @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot #align filter.eventually_false_iff_eq_bot Filter.eventually_false_iff_eq_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] #align filter.eventually_const Filter.eventually_const theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm #align filter.eventually_iff_exists_mem Filter.eventually_iff_exists_mem theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp #align filter.eventually.exists_mem Filter.Eventually.exists_mem theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq #align filter.eventually.mp Filter.Eventually.mp theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (eventually_of_forall hq) #align filter.eventually.mono Filter.Eventually.mono theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y #align filter.forall_eventually_of_eventually_forall Filter.forall_eventually_of_eventually_forall @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff #align filter.eventually_and Filter.eventually_and theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) #align filter.eventually.congr Filter.Eventually.congr theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ #align filter.eventually_congr Filter.eventually_congr @[simp] theorem eventually_all {ι : Sort*} [Finite ι] {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i, p i x) ↔ ∀ i, ∀ᶠ x in l, p i x := by simpa only [Filter.Eventually, setOf_forall] using iInter_mem #align filter.eventually_all Filter.eventually_all @[simp] theorem eventually_all_finite {ι} {I : Set ι} (hI : I.Finite) {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := by simpa only [Filter.Eventually, setOf_forall] using biInter_mem hI #align filter.eventually_all_finite Filter.eventually_all_finite alias _root_.Set.Finite.eventually_all := eventually_all_finite #align set.finite.eventually_all Set.Finite.eventually_all -- attribute [protected] Set.Finite.eventually_all @[simp] theorem eventually_all_finset {ι} (I : Finset ι) {l} {p : ι → α → Prop} : (∀ᶠ x in l, ∀ i ∈ I, p i x) ↔ ∀ i ∈ I, ∀ᶠ x in l, p i x := I.finite_toSet.eventually_all #align filter.eventually_all_finset Filter.eventually_all_finset alias _root_.Finset.eventually_all := eventually_all_finset #align finset.eventually_all Finset.eventually_all -- attribute [protected] Finset.eventually_all @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] #align filter.eventually_or_distrib_left Filter.eventually_or_distrib_left @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] #align filter.eventually_or_distrib_right Filter.eventually_or_distrib_right theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := eventually_all #align filter.eventually_imp_distrib_left Filter.eventually_imp_distrib_left @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ #align filter.eventually_bot Filter.eventually_bot @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl #align filter.eventually_top Filter.eventually_top @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl #align filter.eventually_sup Filter.eventually_sup @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl #align filter.eventually_Sup Filter.eventually_sSup @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup #align filter.eventually_supr Filter.eventually_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl #align filter.eventually_principal Filter.eventually_principal theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset #align filter.eventually_inf Filter.eventually_inf theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal #align filter.eventually_inf_principal Filter.eventually_inf_principal /-! ### Frequently -/ /-- `f.Frequently p` or `∃ᶠ x in f, p x` mean that `{x | ¬p x} ∉ f`. E.g., `∃ᶠ x in atTop, p x` means that there exist arbitrarily large `x` for which `p` holds true. -/ protected def Frequently (p : α → Prop) (f : Filter α) : Prop := ¬∀ᶠ x in f, ¬p x #align filter.frequently Filter.Frequently @[inherit_doc Filter.Frequently] notation3 "∃ᶠ "(...)" in "f", "r:(scoped p => Filter.Frequently p f) => r theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_not_mem h #align filter.eventually.frequently Filter.Eventually.frequently theorem frequently_of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (eventually_of_forall h) #align filter.frequently_of_forall Filter.frequently_of_forall theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h #align filter.frequently.mp Filter.Frequently.mp theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h #align filter.frequently.filter_mono Filter.Frequently.filter_mono theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (eventually_of_forall hpq) #align filter.frequently.mono Filter.Frequently.mono theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ #align filter.frequently.and_eventually Filter.Frequently.and_eventually theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp #align filter.eventually.and_frequently Filter.Eventually.and_frequently theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := eventually_of_forall (not_exists.1 H) exact hp H #align filter.frequently.exists Filter.Frequently.exists theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists #align filter.eventually.exists Filter.Eventually.exists lemma frequently_iff_neBot {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp q hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ #align filter.frequently_iff_forall_eventually_exists_and Filter.frequently_iff_forall_eventually_exists_and theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl #align filter.frequently_iff Filter.frequently_iff @[simp]
Mathlib/Order/Filter/Basic.lean
1,354
1,355
theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by
simp [Filter.Frequently]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive]
Mathlib/Analysis/Normed/Group/Basic.lean
439
440
theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by
rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right]
/- Copyright (c) 2021 Yury Kudriashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudriashov, Malo Jaffré -/ import Mathlib.Analysis.Convex.Function import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.Linarith #align_import analysis.convex.slope from "leanprover-community/mathlib"@"a8b2226cfb0a79f5986492053fc49b1a0c6aeffb" /-! # Slopes of convex functions This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity of their slopes. The main use is to show convexity/concavity from monotonicity of the derivative. -/ variable {𝕜 : Type*} [LinearOrderedField 𝕜] {s : Set 𝕜} {f : 𝕜 → 𝕜} #adaptation_note /-- after v4.7.0-rc1, there is a performance problem in `field_simp`. (Part of the code was ignoring the `maxDischargeDepth` setting: now that we have to increase it, other paths become slow.) -/ /-- If `f : 𝕜 → 𝕜` is convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConvexOn.slope_mono_adjacent (hf : ConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) ≤ (f z - f y) / (z - y) := by have hxz := hxy.trans hyz rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) ≤ f x / (y - x) + f z / (z - y) by ring_nf at this ⊢ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a • x + b • z = y := by field_simp [a, b]; ring have key := hf.2 hx hz (show 0 ≤ a by apply div_nonneg <;> linarith) (show 0 ≤ b by apply div_nonneg <;> linarith) (show a + b = 1 by field_simp [a, b]) rw [hy] at key replace key := mul_le_mul_of_nonneg_left key hxz.le field_simp [a, b, mul_comm (z - x) _] at key ⊢ rw [div_le_div_right] · linarith · nlinarith #align convex_on.slope_mono_adjacent ConvexOn.slope_mono_adjacent /-- If `f : 𝕜 → 𝕜` is concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/ theorem ConcaveOn.slope_anti_adjacent (hf : ConcaveOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) ≤ (f y - f x) / (y - x) := by have := neg_le_neg (ConvexOn.slope_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this #align concave_on.slope_anti_adjacent ConcaveOn.slope_anti_adjacent /-- If `f : 𝕜 → 𝕜` is strictly convex, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on `[x, z]`. -/ theorem StrictConvexOn.slope_strict_mono_adjacent (hf : StrictConvexOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f y - f x) / (y - x) < (f z - f y) / (z - y) := by have hxz := hxy.trans hyz have hxz' := hxz.ne rw [← sub_pos] at hxy hxz hyz suffices f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y) by ring_nf at this ⊢ linarith set a := (z - y) / (z - x) set b := (y - x) / (z - x) have hy : a • x + b • z = y := by field_simp [a, b]; ring have key := hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz) (show a + b = 1 by field_simp [a, b]) rw [hy] at key replace key := mul_lt_mul_of_pos_left key hxz field_simp [mul_comm (z - x) _] at key ⊢ rw [div_lt_div_right] · linarith · nlinarith #align strict_convex_on.slope_strict_mono_adjacent StrictConvexOn.slope_strict_mono_adjacent /-- If `f : 𝕜 → 𝕜` is strictly concave, then for any three points `x < y < z` the slope of the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on `[x, z]`. -/
Mathlib/Analysis/Convex/Slope.lean
89
93
theorem StrictConcaveOn.slope_anti_adjacent (hf : StrictConcaveOn 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) : (f z - f y) / (z - y) < (f y - f x) / (y - x) := by
have := neg_lt_neg (StrictConvexOn.slope_strict_mono_adjacent hf.neg hx hz hxy hyz) simp only [Pi.neg_apply, ← neg_div, neg_sub', neg_neg] at this exact this
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL2 #align_import measure_theory.function.conditional_expectation.condexp_L1 from "leanprover-community/mathlib"@"d8bbb04e2d2a44596798a9207ceefc0fb236e41e" /-! # Conditional expectation in L1 This file contains two more steps of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. The contitional expectation of an `L²` function is defined in `MeasureTheory.Function.ConditionalExpectation.CondexpL2`. In this file, we perform two steps. * Show that the conditional expectation of the indicator of a measurable set with finite measure is integrable and define a map `Set α → (E →L[ℝ] (α →₁[μ] E))` which to a set associates a linear map. That linear map sends `x ∈ E` to the conditional expectation of the indicator of the set with value `x`. * Extend that map to `condexpL1CLM : (α →₁[μ] E) →L[ℝ] (α →₁[μ] E)`. This is done using the same construction as the Bochner integral (see the file `MeasureTheory/Integral/SetToL1`). ## Main definitions * `condexpL1`: Conditional expectation of a function as a linear map from `L1` to itself. -/ noncomputable section open TopologicalSpace MeasureTheory.Lp Filter ContinuousLinearMap open scoped NNReal ENNReal Topology MeasureTheory namespace MeasureTheory variable {α β F F' G G' 𝕜 : Type*} {p : ℝ≥0∞} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- F' for integrals on a Lp submodule [NormedAddCommGroup F'] [NormedSpace 𝕜 F'] [NormedSpace ℝ F'] [CompleteSpace F'] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] section CondexpInd /-! ## Conditional expectation of an indicator as a continuous linear map. The goal of this section is to build `condexpInd (hm : m ≤ m0) (μ : Measure α) (s : Set s) : G →L[ℝ] α →₁[μ] G`, which takes `x : G` to the conditional expectation of the indicator of the set `s` with value `x`, seen as an element of `α →₁[μ] G`. -/ variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} [NormedSpace ℝ G] section CondexpIndL1Fin set_option linter.uppercaseLean3 false /-- Conditional expectation of the indicator of a measurable set with finite measure, as a function in L1. -/ def condexpIndL1Fin (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : α →₁[μ] G := (integrable_condexpIndSMul hm hs hμs x).toL1 _ #align measure_theory.condexp_ind_L1_fin MeasureTheory.condexpIndL1Fin theorem condexpIndL1Fin_ae_eq_condexpIndSMul (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndL1Fin hm hs hμs x =ᵐ[μ] condexpIndSMul hm hs hμs x := (integrable_condexpIndSMul hm hs hμs x).coeFn_toL1 #align measure_theory.condexp_ind_L1_fin_ae_eq_condexp_ind_smul MeasureTheory.condexpIndL1Fin_ae_eq_condexpIndSMul variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] -- Porting note: this lemma fills the hole in `refine' (Memℒp.coeFn_toLp _) ...` -- which is not automatically filled in Lean 4 private theorem q {hs : MeasurableSet s} {hμs : μ s ≠ ∞} {x : G} : Memℒp (condexpIndSMul hm hs hμs x) 1 μ := by rw [memℒp_one_iff_integrable]; apply integrable_condexpIndSMul theorem condexpIndL1Fin_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condexpIndL1Fin hm hs hμs (x + y) = condexpIndL1Fin hm hs hμs x + condexpIndL1Fin hm hs hμs y := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm refine EventuallyEq.trans ?_ (EventuallyEq.add (Memℒp.coeFn_toLp q).symm (Memℒp.coeFn_toLp q).symm) rw [condexpIndSMul_add] refine (Lp.coeFn_add _ _).trans (eventually_of_forall fun a => ?_) rfl #align measure_theory.condexp_ind_L1_fin_add MeasureTheory.condexpIndL1Fin_add theorem condexpIndL1Fin_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condexpIndL1Fin hm hs hμs (c • x) = c • condexpIndL1Fin hm hs hμs x := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condexpIndSMul_smul hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] #align measure_theory.condexp_ind_L1_fin_smul MeasureTheory.condexpIndL1Fin_smul theorem condexpIndL1Fin_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condexpIndL1Fin hm hs hμs (c • x) = c • condexpIndL1Fin hm hs hμs x := by ext1 refine (Memℒp.coeFn_toLp q).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_smul _ _).symm rw [condexpIndSMul_smul' hs hμs c x] refine (Lp.coeFn_smul _ _).trans ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun y hy => ?_ simp only [Pi.smul_apply, hy] #align measure_theory.condexp_ind_L1_fin_smul' MeasureTheory.condexpIndL1Fin_smul' theorem norm_condexpIndL1Fin_le (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : ‖condexpIndL1Fin hm hs hμs x‖ ≤ (μ s).toReal * ‖x‖ := by have : 0 ≤ ∫ a : α, ‖condexpIndL1Fin hm hs hμs x a‖ ∂μ := by positivity rw [L1.norm_eq_integral_norm, ← ENNReal.toReal_ofReal (norm_nonneg x), ← ENNReal.toReal_mul, ← ENNReal.toReal_ofReal this, ENNReal.toReal_le_toReal ENNReal.ofReal_ne_top (ENNReal.mul_ne_top hμs ENNReal.ofReal_ne_top), ofReal_integral_norm_eq_lintegral_nnnorm] swap; · rw [← memℒp_one_iff_integrable]; exact Lp.memℒp _ have h_eq : ∫⁻ a, ‖condexpIndL1Fin hm hs hμs x a‖₊ ∂μ = ∫⁻ a, ‖condexpIndSMul hm hs hμs x a‖₊ ∂μ := by refine lintegral_congr_ae ?_ refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x).mono fun z hz => ?_ dsimp only rw [hz] rw [h_eq, ofReal_norm_eq_coe_nnnorm] exact lintegral_nnnorm_condexpIndSMul_le hm hs hμs x #align measure_theory.norm_condexp_ind_L1_fin_le MeasureTheory.norm_condexpIndL1Fin_le theorem condexpIndL1Fin_disjoint_union (hs : MeasurableSet s) (ht : MeasurableSet t) (hμs : μ s ≠ ∞) (hμt : μ t ≠ ∞) (hst : s ∩ t = ∅) (x : G) : condexpIndL1Fin hm (hs.union ht) ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne x = condexpIndL1Fin hm hs hμs x + condexpIndL1Fin hm ht hμt x := by ext1 have hμst := ((measure_union_le s t).trans_lt (lt_top_iff_ne_top.mpr (ENNReal.add_ne_top.mpr ⟨hμs, hμt⟩))).ne refine (condexpIndL1Fin_ae_eq_condexpIndSMul hm (hs.union ht) hμst x).trans ?_ refine EventuallyEq.trans ?_ (Lp.coeFn_add _ _).symm have hs_eq := condexpIndL1Fin_ae_eq_condexpIndSMul hm hs hμs x have ht_eq := condexpIndL1Fin_ae_eq_condexpIndSMul hm ht hμt x refine EventuallyEq.trans ?_ (EventuallyEq.add hs_eq.symm ht_eq.symm) rw [condexpIndSMul] rw [indicatorConstLp_disjoint_union hs ht hμs hμt hst (1 : ℝ)] rw [(condexpL2 ℝ ℝ hm).map_add] push_cast rw [((toSpanSingleton ℝ x).compLpL 2 μ).map_add] refine (Lp.coeFn_add _ _).trans ?_ filter_upwards with y using rfl #align measure_theory.condexp_ind_L1_fin_disjoint_union MeasureTheory.condexpIndL1Fin_disjoint_union end CondexpIndL1Fin open scoped Classical section CondexpIndL1 set_option linter.uppercaseLean3 false /-- Conditional expectation of the indicator of a set, as a function in L1. Its value for sets which are not both measurable and of finite measure is not used: we set it to 0. -/ def condexpIndL1 {m m0 : MeasurableSpace α} (hm : m ≤ m0) (μ : Measure α) (s : Set α) [SigmaFinite (μ.trim hm)] (x : G) : α →₁[μ] G := if hs : MeasurableSet s ∧ μ s ≠ ∞ then condexpIndL1Fin hm hs.1 hs.2 x else 0 #align measure_theory.condexp_ind_L1 MeasureTheory.condexpIndL1 variable {hm : m ≤ m0} [SigmaFinite (μ.trim hm)] theorem condexpIndL1_of_measurableSet_of_measure_ne_top (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condexpIndL1 hm μ s x = condexpIndL1Fin hm hs hμs x := by simp only [condexpIndL1, And.intro hs hμs, dif_pos, Ne, not_false_iff, and_self_iff] #align measure_theory.condexp_ind_L1_of_measurable_set_of_measure_ne_top MeasureTheory.condexpIndL1_of_measurableSet_of_measure_ne_top theorem condexpIndL1_of_measure_eq_top (hμs : μ s = ∞) (x : G) : condexpIndL1 hm μ s x = 0 := by simp only [condexpIndL1, hμs, eq_self_iff_true, not_true, Ne, dif_neg, not_false_iff, and_false_iff] #align measure_theory.condexp_ind_L1_of_measure_eq_top MeasureTheory.condexpIndL1_of_measure_eq_top theorem condexpIndL1_of_not_measurableSet (hs : ¬MeasurableSet s) (x : G) : condexpIndL1 hm μ s x = 0 := by simp only [condexpIndL1, hs, dif_neg, not_false_iff, false_and_iff] #align measure_theory.condexp_ind_L1_of_not_measurable_set MeasureTheory.condexpIndL1_of_not_measurableSet theorem condexpIndL1_add (x y : G) : condexpIndL1 hm μ s (x + y) = condexpIndL1 hm μ s x + condexpIndL1 hm μ s y := by by_cases hs : MeasurableSet s swap; · simp_rw [condexpIndL1_of_not_measurableSet hs]; rw [zero_add] by_cases hμs : μ s = ∞ · simp_rw [condexpIndL1_of_measure_eq_top hμs]; rw [zero_add] · simp_rw [condexpIndL1_of_measurableSet_of_measure_ne_top hs hμs] exact condexpIndL1Fin_add hs hμs x y #align measure_theory.condexp_ind_L1_add MeasureTheory.condexpIndL1_add
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL1.lean
210
217
theorem condexpIndL1_smul (c : ℝ) (x : G) : condexpIndL1 hm μ s (c • x) = c • condexpIndL1 hm μ s x := by
by_cases hs : MeasurableSet s swap; · simp_rw [condexpIndL1_of_not_measurableSet hs]; rw [smul_zero] by_cases hμs : μ s = ∞ · simp_rw [condexpIndL1_of_measure_eq_top hμs]; rw [smul_zero] · simp_rw [condexpIndL1_of_measurableSet_of_measure_ne_top hs hμs] exact condexpIndL1Fin_smul hs hμs c x
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn -/ import Mathlib.Tactic.Lemma import Mathlib.Mathport.Attributes import Mathlib.Mathport.Rename import Mathlib.Tactic.Relation.Trans import Mathlib.Tactic.ProjectionNotation import Batteries.Tactic.Alias import Batteries.Tactic.Lint.Misc import Batteries.Logic -- Only needed for #align set_option autoImplicit true #align opt_param_eq optParam_eq #align non_contradictory_intro not_not_intro /- Eq -/ theorem not_of_eq_false {p : Prop} (h : p = False) : ¬p := fun hp ↦ h ▸ hp theorem cast_proof_irrel (h₁ h₂ : α = β) (a : α) : cast h₁ a = cast h₂ a := rfl attribute [symm] Eq.symm /- Ne -/ attribute [symm] Ne.symm /- HEq -/ alias eq_rec_heq := eqRec_heq -- FIXME This is still rejected after #857 -- attribute [refl] HEq.refl attribute [symm] HEq.symm attribute [trans] HEq.trans attribute [trans] heq_of_eq_of_heq theorem heq_of_eq_rec_left {φ : α → Sort v} {a a' : α} {p₁ : φ a} {p₂ : φ a'} : (e : a = a') → (h₂ : Eq.rec (motive := fun a _ ↦ φ a) p₁ e = p₂) → HEq p₁ p₂ | rfl, rfl => HEq.rfl theorem heq_of_eq_rec_right {φ : α → Sort v} {a a' : α} {p₁ : φ a} {p₂ : φ a'} : (e : a' = a) → (h₂ : p₁ = Eq.rec (motive := fun a _ ↦ φ a) p₂ e) → HEq p₁ p₂ | rfl, rfl => HEq.rfl theorem of_heq_true {a : Prop} (h : HEq a True) : a := of_eq_true (eq_of_heq h) theorem eq_rec_compose {α β φ : Sort u} : ∀ (p₁ : β = φ) (p₂ : α = β) (a : α), (Eq.recOn p₁ (Eq.recOn p₂ a : β) : φ) = Eq.recOn (Eq.trans p₂ p₁) a | rfl, rfl, _ => rfl theorem heq_prop {P Q : Prop} (p : P) (q : Q) : HEq p q := Subsingleton.helim (propext <| iff_of_true p q) _ _ /- and -/ variable {a b c d : Prop} #align and.symm And.symm #align and.swap And.symm /- or -/ #align non_contradictory_em not_not_em #align or.symm Or.symm #align or.swap Or.symm /- xor -/ def Xor' (a b : Prop) := (a ∧ ¬ b) ∨ (b ∧ ¬ a) #align xor Xor' /- iff -/ #align iff.mp Iff.mp #align iff.elim_left Iff.mp #align iff.mpr Iff.mpr #align iff.elim_right Iff.mpr attribute [refl] Iff.refl attribute [trans] Iff.trans attribute [symm] Iff.symm -- This is needed for `calc` to work with `iff`. instance : Trans Iff Iff Iff where trans := fun p q ↦ p.trans q #align not_congr not_congr #align not_iff_not_of_iff not_congr #align not_non_contradictory_iff_absurd not_not_not alias ⟨not_of_not_not_not, _⟩ := not_not_not -- FIXME -- attribute [congr] not_congr #align and.comm and_comm #align and_comm and_comm #align and_assoc and_assoc #align and.assoc and_assoc #align and.left_comm and_left_comm #align and_iff_left and_iff_leftₓ -- reorder implicits variable (p) -- FIXME: remove _iff and add _eq for the lean 4 core versions theorem and_true_iff : p ∧ True ↔ p := iff_of_eq (and_true _) #align and_true and_true_iff theorem true_and_iff : True ∧ p ↔ p := iff_of_eq (true_and _) #align true_and true_and_iff theorem and_false_iff : p ∧ False ↔ False := iff_of_eq (and_false _) #align and_false and_false_iff theorem false_and_iff : False ∧ p ↔ False := iff_of_eq (false_and _) #align false_and false_and_iff #align not_and_self not_and_self_iff #align and_not_self and_not_self_iff #align and_self and_self_iff #align or.imp Or.impₓ -- reorder implicits #align and.elim And.elimₓ #align iff.elim Iff.elimₓ #align imp_congr imp_congrₓ #align imp_congr_ctx imp_congr_ctxₓ #align imp_congr_right imp_congr_rightₓ #align eq_true_intro eq_true #align eq_false_intro eq_false #align or.comm or_comm #align or_comm or_comm #align or.assoc or_assoc #align or_assoc or_assoc #align or_left_comm or_left_comm #align or.left_comm or_left_comm #align or_iff_left_of_imp or_iff_left_of_impₓ -- reorder implicits theorem true_or_iff : True ∨ p ↔ True := iff_of_eq (true_or _) #align true_or true_or_iff theorem or_true_iff : p ∨ True ↔ True := iff_of_eq (or_true _) #align or_true or_true_iff theorem false_or_iff : False ∨ p ↔ p := iff_of_eq (false_or _) #align false_or false_or_iff theorem or_false_iff : p ∨ False ↔ p := iff_of_eq (or_false _) #align or_false or_false_iff #align or_self or_self_iff theorem not_or_of_not : ¬a → ¬b → ¬(a ∨ b) := fun h1 h2 ↦ not_or.2 ⟨h1, h2⟩ #align not_or not_or_of_not theorem iff_true_iff : (a ↔ True) ↔ a := iff_of_eq (iff_true _) #align iff_true iff_true_iff theorem true_iff_iff : (True ↔ a) ↔ a := iff_of_eq (true_iff _) #align true_iff true_iff_iff theorem iff_false_iff : (a ↔ False) ↔ ¬a := iff_of_eq (iff_false _) #align iff_false iff_false_iff theorem false_iff_iff : (False ↔ a) ↔ ¬a := iff_of_eq (false_iff _) #align false_iff false_iff_iff theorem iff_self_iff (a : Prop) : (a ↔ a) ↔ True := iff_of_eq (iff_self _) #align iff_self iff_self_iff #align iff_congr iff_congrₓ -- reorder implicits #align implies_true_iff imp_true_iff #align false_implies_iff false_imp_iff #align true_implies_iff true_imp_iff #align Exists Exists -- otherwise it would get the name ExistsCat -- TODO -- attribute [intro] Exists.intro /- exists unique -/ def ExistsUnique (p : α → Prop) := ∃ x, p x ∧ ∀ y, p y → y = x namespace Mathlib.Notation open Lean /-- Checks to see that `xs` has only one binder. -/ def isExplicitBinderSingular (xs : TSyntax ``explicitBinders) : Bool := match xs with | `(explicitBinders| $_:binderIdent $[: $_]?) => true | `(explicitBinders| ($_:binderIdent : $_)) => true | _ => false open TSyntax.Compat in /-- `∃! x : α, p x` means that there exists a unique `x` in `α` such that `p x`. This is notation for `ExistsUnique (fun (x : α) ↦ p x)`. This notation does not allow multiple binders like `∃! (x : α) (y : β), p x y` as a shorthand for `∃! (x : α), ∃! (y : β), p x y` since it is liable to be misunderstood. Often, the intended meaning is instead `∃! q : α × β, p q.1 q.2`. -/ macro "∃!" xs:explicitBinders ", " b:term : term => do if !isExplicitBinderSingular xs then Macro.throwErrorAt xs "\ The `ExistsUnique` notation should not be used with more than one binder.\n\ \n\ The reason for this is that `∃! (x : α), ∃! (y : β), p x y` has a completely different \ meaning from `∃! q : α × β, p q.1 q.2`. \ To prevent confusion, this notation requires that you be explicit \ and use one with the correct interpretation." expandExplicitBinders ``ExistsUnique xs b /-- Pretty-printing for `ExistsUnique`, following the same pattern as pretty printing for `Exists`. However, it does *not* merge binders. -/ @[app_unexpander ExistsUnique] def unexpandExistsUnique : Lean.PrettyPrinter.Unexpander | `($(_) fun $x:ident ↦ $b) => `(∃! $x:ident, $b) | `($(_) fun ($x:ident : $t) ↦ $b) => `(∃! $x:ident : $t, $b) | _ => throw () /-- `∃! x ∈ s, p x` means `∃! x, x ∈ s ∧ p x`, which is to say that there exists a unique `x ∈ s` such that `p x`. Similarly, notations such as `∃! x ≤ n, p n` are supported, using any relation defined using the `binder_predicate` command. -/ syntax "∃! " binderIdent binderPred ", " term : term macro_rules | `(∃! $x:ident $p:binderPred, $b) => `(∃! $x:ident, satisfies_binder_pred% $x $p ∧ $b) | `(∃! _ $p:binderPred, $b) => `(∃! x, satisfies_binder_pred% x $p ∧ $b) end Mathlib.Notation -- @[intro] -- TODO theorem ExistsUnique.intro {p : α → Prop} (w : α) (h₁ : p w) (h₂ : ∀ y, p y → y = w) : ∃! x, p x := ⟨w, h₁, h₂⟩ theorem ExistsUnique.elim {α : Sort u} {p : α → Prop} {b : Prop} (h₂ : ∃! x, p x) (h₁ : ∀ x, p x → (∀ y, p y → y = x) → b) : b := Exists.elim h₂ (fun w hw ↦ h₁ w (And.left hw) (And.right hw)) theorem exists_unique_of_exists_of_unique {α : Sort u} {p : α → Prop} (hex : ∃ x, p x) (hunique : ∀ y₁ y₂, p y₁ → p y₂ → y₁ = y₂) : ∃! x, p x := Exists.elim hex (fun x px ↦ ExistsUnique.intro x px (fun y (h : p y) ↦ hunique y x h px)) theorem ExistsUnique.exists {p : α → Prop} : (∃! x, p x) → ∃ x, p x | ⟨x, h, _⟩ => ⟨x, h⟩ #align exists_of_exists_unique ExistsUnique.exists #align exists_unique.exists ExistsUnique.exists theorem ExistsUnique.unique {α : Sort u} {p : α → Prop} (h : ∃! x, p x) {y₁ y₂ : α} (py₁ : p y₁) (py₂ : p y₂) : y₁ = y₂ := let ⟨_, _, hy⟩ := h; (hy _ py₁).trans (hy _ py₂).symm #align unique_of_exists_unique ExistsUnique.unique #align exists_unique.unique ExistsUnique.unique /- exists, forall, exists unique congruences -/ -- TODO -- attribute [congr] forall_congr' -- attribute [congr] exists_congr' #align forall_congr forall_congr' #align Exists.imp Exists.imp #align exists_imp_exists Exists.imp -- @[congr] theorem exists_unique_congr {p q : α → Prop} (h : ∀ a, p a ↔ q a) : (∃! a, p a) ↔ ∃! a, q a := exists_congr fun _ ↦ and_congr (h _) <| forall_congr' fun _ ↦ imp_congr_left (h _) /- decidable -/ #align decidable.to_bool Decidable.decide theorem decide_True' (h : Decidable True) : decide True = true := by simp #align to_bool_true_eq_tt decide_True' theorem decide_False' (h : Decidable False) : decide False = false := by simp #align to_bool_false_eq_ff decide_False' namespace Decidable def recOn_true [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : p) (h₄ : h₁ h₃) : Decidable.recOn h h₂ h₁ := cast (by match h with | .isTrue _ => rfl) h₄ #align decidable.rec_on_true Decidable.recOn_true def recOn_false [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} (h₃ : ¬p) (h₄ : h₂ h₃) : Decidable.recOn h h₂ h₁ := cast (by match h with | .isFalse _ => rfl) h₄ #align decidable.rec_on_false Decidable.recOn_false alias by_cases := byCases alias by_contradiction := byContradiction alias not_not_iff := not_not end Decidable #align decidable_of_decidable_of_iff decidable_of_decidable_of_iff #align decidable_of_decidable_of_eq decidable_of_decidable_of_eq #align or.by_cases Or.by_cases alias Or.decidable := instDecidableOr alias And.decidable := instDecidableAnd alias Not.decidable := instDecidableNot alias Iff.decidable := instDecidableIff alias decidableTrue := instDecidableTrue alias decidableFalse := instDecidableFalse #align decidable.true decidableTrue #align decidable.false decidableFalse #align or.decidable Or.decidable #align and.decidable And.decidable #align not.decidable Not.decidable #align iff.decidable Iff.decidable instance [Decidable p] [Decidable q] : Decidable (Xor' p q) := inferInstanceAs (Decidable (Or ..)) def IsDecEq {α : Sort u} (p : α → α → Bool) : Prop := ∀ ⦃x y : α⦄, p x y = true → x = y def IsDecRefl {α : Sort u} (p : α → α → Bool) : Prop := ∀ x, p x x = true def decidableEq_of_bool_pred {α : Sort u} {p : α → α → Bool} (h₁ : IsDecEq p) (h₂ : IsDecRefl p) : DecidableEq α | x, y => if hp : p x y = true then isTrue (h₁ hp) else isFalse (fun hxy : x = y ↦ absurd (h₂ y) (by rwa [hxy] at hp)) #align decidable_eq_of_bool_pred decidableEq_of_bool_pred theorem decidableEq_inl_refl {α : Sort u} [h : DecidableEq α] (a : α) : h a a = isTrue (Eq.refl a) := match h a a with | isTrue _ => rfl theorem decidableEq_inr_neg {α : Sort u} [h : DecidableEq α] {a b : α} (n : a ≠ b) : h a b = isFalse n := match h a b with | isFalse _ => rfl #align inhabited.default Inhabited.default #align arbitrary Inhabited.default #align nonempty_of_inhabited instNonemptyOfInhabited /- subsingleton -/ theorem rec_subsingleton {p : Prop} [h : Decidable p] {h₁ : p → Sort u} {h₂ : ¬p → Sort u} [h₃ : ∀ h : p, Subsingleton (h₁ h)] [h₄ : ∀ h : ¬p, Subsingleton (h₂ h)] : Subsingleton (Decidable.recOn h h₂ h₁) := match h with | isTrue h => h₃ h | isFalse h => h₄ h theorem imp_of_if_pos {c t e : Prop} [Decidable c] (h : ite c t e) (hc : c) : t := (if_pos hc ▸ h :) #align implies_of_if_pos imp_of_if_pos theorem imp_of_if_neg {c t e : Prop} [Decidable c] (h : ite c t e) (hnc : ¬c) : e := (if_neg hnc ▸ h :) #align implies_of_if_neg imp_of_if_neg theorem if_ctx_congr {α : Sort u} {b c : Prop} [dec_b : Decidable b] [dec_c : Decidable c] {x y u v : α} (h_c : b ↔ c) (h_t : c → x = u) (h_e : ¬c → y = v) : ite b x y = ite c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) theorem if_congr {α : Sort u} {b c : Prop} [Decidable b] [Decidable c] {x y u v : α} (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := if_ctx_congr h_c (fun _ ↦ h_t) (fun _ ↦ h_e) theorem if_ctx_congr_prop {b c x y u v : Prop} [dec_b : Decidable b] [dec_c : Decidable c] (h_c : b ↔ c) (h_t : c → (x ↔ u)) (h_e : ¬c → (y ↔ v)) : ite b x y ↔ ite c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) -- @[congr] theorem if_congr_prop {b c x y u v : Prop} [Decidable b] [Decidable c] (h_c : b ↔ c) (h_t : x ↔ u) (h_e : y ↔ v) : ite b x y ↔ ite c u v := if_ctx_congr_prop h_c (fun _ ↦ h_t) (fun _ ↦ h_e) theorem if_ctx_simp_congr_prop {b c x y u v : Prop} [Decidable b] (h_c : b ↔ c) (h_t : c → (x ↔ u)) -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- (h_e : ¬c → (y ↔ v)) : ite b x y ↔ ite c (h := decidable_of_decidable_of_iff h_c) u v := (h_e : ¬c → (y ↔ v)) : ite b x y ↔ @ite _ c (decidable_of_decidable_of_iff h_c) u v := if_ctx_congr_prop (dec_c := decidable_of_decidable_of_iff h_c) h_c h_t h_e theorem if_simp_congr_prop {b c x y u v : Prop} [Decidable b] (h_c : b ↔ c) (h_t : x ↔ u) -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- (h_e : y ↔ v) : ite b x y ↔ (ite c (h := decidable_of_decidable_of_iff h_c) u v) := (h_e : y ↔ v) : ite b x y ↔ (@ite _ c (decidable_of_decidable_of_iff h_c) u v) := if_ctx_simp_congr_prop h_c (fun _ ↦ h_t) (fun _ ↦ h_e) -- @[congr] theorem dif_ctx_congr {α : Sort u} {b c : Prop} [dec_b : Decidable b] [dec_c : Decidable c] {x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α} (h_c : b ↔ c) (h_t : ∀ h : c, x (Iff.mpr h_c h) = u h) (h_e : ∀ h : ¬c, y (Iff.mpr (not_congr h_c) h) = v h) : @dite α b dec_b x y = @dite α c dec_c u v := match dec_b, dec_c with | isFalse _, isFalse h₂ => h_e h₂ | isTrue _, isTrue h₂ => h_t h₂ | isFalse h₁, isTrue h₂ => absurd h₂ (Iff.mp (not_congr h_c) h₁) | isTrue h₁, isFalse h₂ => absurd h₁ (Iff.mpr (not_congr h_c) h₂) theorem dif_ctx_simp_congr {α : Sort u} {b c : Prop} [Decidable b] {x : b → α} {u : c → α} {y : ¬b → α} {v : ¬c → α} (h_c : b ↔ c) (h_t : ∀ h : c, x (Iff.mpr h_c h) = u h) (h_e : ∀ h : ¬c, y (Iff.mpr (not_congr h_c) h) = v h) : -- FIXME: after https://github.com/leanprover/lean4/issues/1867 is fixed, -- this should be changed back to: -- dite b x y = dite c (h := decidable_of_decidable_of_iff h_c) u v := dite b x y = @dite _ c (decidable_of_decidable_of_iff h_c) u v := dif_ctx_congr (dec_c := decidable_of_decidable_of_iff h_c) h_c h_t h_e def AsTrue (c : Prop) [Decidable c] : Prop := if c then True else False def AsFalse (c : Prop) [Decidable c] : Prop := if c then False else True theorem AsTrue.get {c : Prop} [h₁ : Decidable c] (_ : AsTrue c) : c := match h₁ with | isTrue h_c => h_c #align of_as_true AsTrue.get #align ulift ULift #align ulift.up ULift.up #align ulift.down ULift.down #align plift PLift #align plift.up PLift.up #align plift.down PLift.down /- Equalities for rewriting let-expressions -/ theorem let_value_eq {α : Sort u} {β : Sort v} {a₁ a₂ : α} (b : α → β) (h : a₁ = a₂) : (let x : α := a₁; b x) = (let x : α := a₂; b x) := congrArg b h
Mathlib/Init/Logic.lean
453
454
theorem let_value_heq {α : Sort v} {β : α → Sort u} {a₁ a₂ : α} (b : ∀ x : α, β x) (h : a₁ = a₂) : HEq (let x : α := a₁; b x) (let x : α := a₂; b x) := by
cases h; rfl
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.AbsoluteValue import Mathlib.Algebra.Order.Field.Basic import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Ring.Pi import Mathlib.GroupTheory.GroupAction.Pi import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.Init.Align import Mathlib.Tactic.GCongr import Mathlib.Tactic.Ring #align_import data.real.cau_seq from "leanprover-community/mathlib"@"9116dd6709f303dcf781632e15fdef382b0fc579" /-! # Cauchy sequences A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where applicable, lemmas that will be reused in other contexts have been stated in extra generality. There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology. This is a concrete implementation that is useful for simplicity and computability reasons. ## Important definitions * `IsCauSeq`: a predicate that says `f : ℕ → β` is Cauchy. * `CauSeq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value function `abv`. ## Tags sequence, cauchy, abs val, absolute value -/ assert_not_exists Finset assert_not_exists Module assert_not_exists Submonoid assert_not_exists FloorRing variable {α β : Type*} open IsAbsoluteValue section variable [LinearOrderedField α] [Ring β] (abv : β → α) [IsAbsoluteValue abv] theorem rat_add_continuous_lemma {ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε := ⟨ε / 2, half_pos ε0, fun {a₁ a₂ b₁ b₂} h₁ h₂ => by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩ #align rat_add_continuous_lemma rat_add_continuous_lemma theorem rat_mul_continuous_lemma {ε K₁ K₂ : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ → abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε := by have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _) have εK := div_pos (half_pos ε0) K0 refine ⟨_, εK, fun {a₁ a₂ b₁ b₂} ha₁ hb₂ h₁ h₂ => ?_⟩ replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _)) replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _)) set M := max 1 (max K₁ K₂) have : abv (a₁ - b₁) * abv b₂ + abv (a₂ - b₂) * abv a₁ < ε / 2 / M * M + ε / 2 / M * M := by gcongr rw [← abv_mul abv, mul_comm, div_mul_cancel₀ _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this simpa [sub_eq_add_neg, mul_add, add_mul, add_left_comm] using lt_of_le_of_lt (abv_add abv _ _) this #align rat_mul_continuous_lemma rat_mul_continuous_lemma theorem rat_inv_continuous_lemma {β : Type*} [DivisionRing β] (abv : β → α) [IsAbsoluteValue abv] {ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) : ∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b → abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε := by refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, fun {a b} ha hb h => ?_⟩ have a0 := K0.trans_le ha have b0 := K0.trans_le hb rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv, abv_inv abv, abv_inv abv, abv_sub abv] refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right ?_ b0.le) a0.le rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ← mul_assoc, mul_inv_cancel a0.ne', one_mul] refine h.trans_le ?_ gcongr #align rat_inv_continuous_lemma rat_inv_continuous_lemma end /-- A sequence is Cauchy if the distance between its entries tends to zero. -/ def IsCauSeq {α : Type*} [LinearOrderedField α] {β : Type*} [Ring β] (abv : β → α) (f : ℕ → β) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε #align is_cau_seq IsCauSeq namespace IsCauSeq variable [LinearOrderedField α] [Ring β] {abv : β → α} [IsAbsoluteValue abv] {f g : ℕ → β} -- see Note [nolint_ge] --@[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := by refine (hf _ (half_pos ε0)).imp fun i hi j ij k ik => ?_ rw [← add_halves ε] refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) ?_) rw [abv_sub abv]; exact hi _ ik #align is_cau_seq.cauchy₂ IsCauSeq.cauchy₂ theorem cauchy₃ (hf : IsCauSeq abv f) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := let ⟨i, H⟩ := hf.cauchy₂ ε0 ⟨i, fun _ ij _ jk => H _ (le_trans ij jk) _ ij⟩ #align is_cau_seq.cauchy₃ IsCauSeq.cauchy₃ lemma bounded (hf : IsCauSeq abv f) : ∃ r, ∀ i, abv (f i) < r := by obtain ⟨i, h⟩ := hf _ zero_lt_one set R : ℕ → α := @Nat.rec (fun _ => α) (abv (f 0)) fun i c => max c (abv (f i.succ)) with hR have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i := by refine Nat.rec (by simp [hR]) ?_ rintro i hi j (rfl | hj) · simp [R] · exact (hi j hj).trans (le_max_left _ _) refine ⟨R i + 1, fun j ↦ ?_⟩ obtain hji | hij := le_total j i · exact (this i _ hji).trans_lt (lt_add_one _) · simpa using (abv_add abv _ _).trans_lt $ add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ hij) lemma bounded' (hf : IsCauSeq abv f) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := let ⟨r, h⟩ := hf.bounded ⟨max r (x + 1), (lt_add_one x).trans_le (le_max_right _ _), fun i ↦ (h i).trans_le (le_max_left _ _)⟩ lemma const (x : β) : IsCauSeq abv fun _ ↦ x := fun ε ε0 ↦ ⟨0, fun j _ => by simpa [abv_zero] using ε0⟩ theorem add (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f + g) := fun _ ε0 => let ⟨_, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun _ ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (H₁ _ ij) (H₂ _ ij)⟩ #align is_cau_seq.add IsCauSeq.add lemma mul (hf : IsCauSeq abv f) (hg : IsCauSeq abv g) : IsCauSeq abv (f * g) := fun _ ε0 => let ⟨_, _, hF⟩ := hf.bounded' 0 let ⟨_, _, hG⟩ := hg.bounded' 0 let ⟨_, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0 let ⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) ⟨i, fun j ij => let ⟨H₁, H₂⟩ := H _ le_rfl Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩ @[simp] lemma _root_.isCauSeq_neg : IsCauSeq abv (-f) ↔ IsCauSeq abv f := by simp only [IsCauSeq, Pi.neg_apply, ← neg_sub', abv_neg] protected alias ⟨of_neg, neg⟩ := isCauSeq_neg end IsCauSeq /-- `CauSeq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value function `abv`. -/ def CauSeq {α : Type*} [LinearOrderedField α] (β : Type*) [Ring β] (abv : β → α) : Type _ := { f : ℕ → β // IsCauSeq abv f } #align cau_seq CauSeq namespace CauSeq variable [LinearOrderedField α] section Ring variable [Ring β] {abv : β → α} instance : CoeFun (CauSeq β abv) fun _ => ℕ → β := ⟨Subtype.val⟩ -- Porting note: Remove coeFn theorem /-@[simp] theorem mk_to_fun (f) (hf : IsCauSeq abv f) : @coeFn (CauSeq β abv) _ _ ⟨f, hf⟩ = f := rfl -/ #noalign cau_seq.mk_to_fun @[ext] theorem ext {f g : CauSeq β abv} (h : ∀ i, f i = g i) : f = g := Subtype.eq (funext h) #align cau_seq.ext CauSeq.ext theorem isCauSeq (f : CauSeq β abv) : IsCauSeq abv f := f.2 #align cau_seq.is_cau CauSeq.isCauSeq theorem cauchy (f : CauSeq β abv) : ∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := @f.2 #align cau_seq.cauchy CauSeq.cauchy /-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with the same values as `f`. -/ def ofEq (f : CauSeq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : CauSeq β abv := ⟨g, fun ε => by rw [show g = f from (funext e).symm]; exact f.cauchy⟩ #align cau_seq.of_eq CauSeq.ofEq variable [IsAbsoluteValue abv] -- see Note [nolint_ge] -- @[nolint ge_or_gt] -- Porting note: restore attribute theorem cauchy₂ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂ #align cau_seq.cauchy₂ CauSeq.cauchy₂ theorem cauchy₃ (f : CauSeq β abv) {ε} : 0 < ε → ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃ #align cau_seq.cauchy₃ CauSeq.cauchy₃ theorem bounded (f : CauSeq β abv) : ∃ r, ∀ i, abv (f i) < r := f.2.bounded #align cau_seq.bounded CauSeq.bounded theorem bounded' (f : CauSeq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r := f.2.bounded' x #align cau_seq.bounded' CauSeq.bounded' instance : Add (CauSeq β abv) := ⟨fun f g => ⟨f + g, f.2.add g.2⟩⟩ @[simp, norm_cast] theorem coe_add (f g : CauSeq β abv) : ⇑(f + g) = (f : ℕ → β) + g := rfl #align cau_seq.coe_add CauSeq.coe_add @[simp, norm_cast] theorem add_apply (f g : CauSeq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl #align cau_seq.add_apply CauSeq.add_apply variable (abv) /-- The constant Cauchy sequence. -/ def const (x : β) : CauSeq β abv := ⟨fun _ ↦ x, IsCauSeq.const _⟩ #align cau_seq.const CauSeq.const variable {abv} /-- The constant Cauchy sequence -/ local notation "const" => const abv @[simp, norm_cast] theorem coe_const (x : β) : (const x : ℕ → β) = Function.const ℕ x := rfl #align cau_seq.coe_const CauSeq.coe_const @[simp, norm_cast] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl #align cau_seq.const_apply CauSeq.const_apply theorem const_inj {x y : β} : (const x : CauSeq β abv) = const y ↔ x = y := ⟨fun h => congr_arg (fun f : CauSeq β abv => (f : ℕ → β) 0) h, congr_arg _⟩ #align cau_seq.const_inj CauSeq.const_inj instance : Zero (CauSeq β abv) := ⟨const 0⟩ instance : One (CauSeq β abv) := ⟨const 1⟩ instance : Inhabited (CauSeq β abv) := ⟨0⟩ @[simp, norm_cast] theorem coe_zero : ⇑(0 : CauSeq β abv) = 0 := rfl #align cau_seq.coe_zero CauSeq.coe_zero @[simp, norm_cast] theorem coe_one : ⇑(1 : CauSeq β abv) = 1 := rfl #align cau_seq.coe_one CauSeq.coe_one @[simp, norm_cast] theorem zero_apply (i) : (0 : CauSeq β abv) i = 0 := rfl #align cau_seq.zero_apply CauSeq.zero_apply @[simp, norm_cast] theorem one_apply (i) : (1 : CauSeq β abv) i = 1 := rfl #align cau_seq.one_apply CauSeq.one_apply @[simp] theorem const_zero : const 0 = 0 := rfl #align cau_seq.const_zero CauSeq.const_zero @[simp] theorem const_one : const 1 = 1 := rfl #align cau_seq.const_one CauSeq.const_one theorem const_add (x y : β) : const (x + y) = const x + const y := rfl #align cau_seq.const_add CauSeq.const_add instance : Mul (CauSeq β abv) := ⟨fun f g ↦ ⟨f * g, f.2.mul g.2⟩⟩ @[simp, norm_cast] theorem coe_mul (f g : CauSeq β abv) : ⇑(f * g) = (f : ℕ → β) * g := rfl #align cau_seq.coe_mul CauSeq.coe_mul @[simp, norm_cast] theorem mul_apply (f g : CauSeq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl #align cau_seq.mul_apply CauSeq.mul_apply theorem const_mul (x y : β) : const (x * y) = const x * const y := rfl #align cau_seq.const_mul CauSeq.const_mul instance : Neg (CauSeq β abv) := ⟨fun f ↦ ⟨-f, f.2.neg⟩⟩ @[simp, norm_cast] theorem coe_neg (f : CauSeq β abv) : ⇑(-f) = -f := rfl #align cau_seq.coe_neg CauSeq.coe_neg @[simp, norm_cast] theorem neg_apply (f : CauSeq β abv) (i) : (-f) i = -f i := rfl #align cau_seq.neg_apply CauSeq.neg_apply theorem const_neg (x : β) : const (-x) = -const x := rfl #align cau_seq.const_neg CauSeq.const_neg instance : Sub (CauSeq β abv) := ⟨fun f g => ofEq (f + -g) (fun x => f x - g x) fun i => by simp [sub_eq_add_neg]⟩ @[simp, norm_cast] theorem coe_sub (f g : CauSeq β abv) : ⇑(f - g) = (f : ℕ → β) - g := rfl #align cau_seq.coe_sub CauSeq.coe_sub @[simp, norm_cast] theorem sub_apply (f g : CauSeq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl #align cau_seq.sub_apply CauSeq.sub_apply theorem const_sub (x y : β) : const (x - y) = const x - const y := rfl #align cau_seq.const_sub CauSeq.const_sub section SMul variable {G : Type*} [SMul G β] [IsScalarTower G β β] instance : SMul G (CauSeq β abv) := ⟨fun a f => (ofEq (const (a • (1 : β)) * f) (a • (f : ℕ → β))) fun _ => smul_one_mul _ _⟩ @[simp, norm_cast] theorem coe_smul (a : G) (f : CauSeq β abv) : ⇑(a • f) = a • (f : ℕ → β) := rfl #align cau_seq.coe_smul CauSeq.coe_smul @[simp, norm_cast] theorem smul_apply (a : G) (f : CauSeq β abv) (i : ℕ) : (a • f) i = a • f i := rfl #align cau_seq.smul_apply CauSeq.smul_apply theorem const_smul (a : G) (x : β) : const (a • x) = a • const x := rfl #align cau_seq.const_smul CauSeq.const_smul instance : IsScalarTower G (CauSeq β abv) (CauSeq β abv) := ⟨fun a f g => Subtype.ext <| smul_assoc a (f : ℕ → β) (g : ℕ → β)⟩ end SMul instance addGroup : AddGroup (CauSeq β abv) := Function.Injective.addGroup Subtype.val Subtype.val_injective rfl coe_add coe_neg coe_sub (fun _ _ => coe_smul _ _) fun _ _ => coe_smul _ _ instance instNatCast : NatCast (CauSeq β abv) := ⟨fun n => const n⟩ instance instIntCast : IntCast (CauSeq β abv) := ⟨fun n => const n⟩ instance addGroupWithOne : AddGroupWithOne (CauSeq β abv) := Function.Injective.addGroupWithOne Subtype.val Subtype.val_injective rfl rfl coe_add coe_neg coe_sub (by intros; rfl) (by intros; rfl) (by intros; rfl) (by intros; rfl) instance : Pow (CauSeq β abv) ℕ := ⟨fun f n => (ofEq (npowRec n f) fun i => f i ^ n) <| by induction n <;> simp [*, npowRec, pow_succ]⟩ @[simp, norm_cast] theorem coe_pow (f : CauSeq β abv) (n : ℕ) : ⇑(f ^ n) = (f : ℕ → β) ^ n := rfl #align cau_seq.coe_pow CauSeq.coe_pow @[simp, norm_cast] theorem pow_apply (f : CauSeq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n := rfl #align cau_seq.pow_apply CauSeq.pow_apply theorem const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n := rfl #align cau_seq.const_pow CauSeq.const_pow instance ring : Ring (CauSeq β abv) := Function.Injective.ring Subtype.val Subtype.val_injective rfl rfl coe_add coe_mul coe_neg coe_sub (fun _ _ => coe_smul _ _) (fun _ _ => coe_smul _ _) coe_pow (fun _ => rfl) fun _ => rfl instance {β : Type*} [CommRing β] {abv : β → α} [IsAbsoluteValue abv] : CommRing (CauSeq β abv) := { CauSeq.ring with mul_comm := fun a b => ext fun n => by simp [mul_left_comm, mul_comm] } /-- `LimZero f` holds when `f` approaches 0. -/ def LimZero {abv : β → α} (f : CauSeq β abv) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε #align cau_seq.lim_zero CauSeq.LimZero theorem add_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f + g) | ε, ε0 => (exists_forall_ge_and (hf _ <| half_pos ε0) (hg _ <| half_pos ε0)).imp fun i H j ij => by let ⟨H₁, H₂⟩ := H _ ij simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂) #align cau_seq.add_lim_zero CauSeq.add_limZero theorem mul_limZero_right (f : CauSeq β abv) {g} (hg : LimZero g) : LimZero (f * g) | ε, ε0 => let ⟨F, F0, hF⟩ := f.bounded' 0 (hg _ <| div_pos ε0 F0).imp fun i H j ij => by have := mul_lt_mul' (le_of_lt <| hF j) (H _ ij) (abv_nonneg abv _) F0 rwa [mul_comm F, div_mul_cancel₀ _ (ne_of_gt F0), ← abv_mul] at this #align cau_seq.mul_lim_zero_right CauSeq.mul_limZero_right theorem mul_limZero_left {f} (g : CauSeq β abv) (hg : LimZero f) : LimZero (f * g) | ε, ε0 => let ⟨G, G0, hG⟩ := g.bounded' 0 (hg _ <| div_pos ε0 G0).imp fun i H j ij => by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _) rwa [div_mul_cancel₀ _ (ne_of_gt G0), ← abv_mul] at this #align cau_seq.mul_lim_zero_left CauSeq.mul_limZero_left theorem neg_limZero {f : CauSeq β abv} (hf : LimZero f) : LimZero (-f) := by rw [← neg_one_mul f] exact mul_limZero_right _ hf #align cau_seq.neg_lim_zero CauSeq.neg_limZero theorem sub_limZero {f g : CauSeq β abv} (hf : LimZero f) (hg : LimZero g) : LimZero (f - g) := by simpa only [sub_eq_add_neg] using add_limZero hf (neg_limZero hg) #align cau_seq.sub_lim_zero CauSeq.sub_limZero theorem limZero_sub_rev {f g : CauSeq β abv} (hfg : LimZero (f - g)) : LimZero (g - f) := by simpa using neg_limZero hfg #align cau_seq.lim_zero_sub_rev CauSeq.limZero_sub_rev theorem zero_limZero : LimZero (0 : CauSeq β abv) | ε, ε0 => ⟨0, fun j _ => by simpa [abv_zero abv] using ε0⟩ #align cau_seq.zero_lim_zero CauSeq.zero_limZero theorem const_limZero {x : β} : LimZero (const x) ↔ x = 0 := ⟨fun H => (abv_eq_zero abv).1 <| (eq_of_le_of_forall_le_of_dense (abv_nonneg abv _)) fun _ ε0 => let ⟨_, hi⟩ := H _ ε0 le_of_lt <| hi _ le_rfl, fun e => e.symm ▸ zero_limZero⟩ #align cau_seq.const_lim_zero CauSeq.const_limZero instance equiv : Setoid (CauSeq β abv) := ⟨fun f g => LimZero (f - g), ⟨fun f => by simp [zero_limZero], fun f ε hε => by simpa using neg_limZero f ε hε, fun fg gh => by simpa using add_limZero fg gh⟩⟩ #align cau_seq.equiv CauSeq.equiv theorem add_equiv_add {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 + g1 ≈ f2 + g2 := by simpa only [← add_sub_add_comm] using add_limZero hf hg #align cau_seq.add_equiv_add CauSeq.add_equiv_add theorem neg_equiv_neg {f g : CauSeq β abv} (hf : f ≈ g) : -f ≈ -g := by simpa only [neg_sub'] using neg_limZero hf #align cau_seq.neg_equiv_neg CauSeq.neg_equiv_neg theorem sub_equiv_sub {f1 f2 g1 g2 : CauSeq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) : f1 - g1 ≈ f2 - g2 := by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg) #align cau_seq.sub_equiv_sub CauSeq.sub_equiv_sub theorem equiv_def₃ {f g : CauSeq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) : ∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε := (exists_forall_ge_and (h _ <| half_pos ε0) (f.cauchy₃ <| half_pos ε0)).imp fun i H j ij k jk => by let ⟨h₁, h₂⟩ := H _ ij have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk)) rwa [sub_add_sub_cancel', add_halves] at this #align cau_seq.equiv_def₃ CauSeq.equiv_def₃ theorem limZero_congr {f g : CauSeq β abv} (h : f ≈ g) : LimZero f ↔ LimZero g := ⟨fun l => by simpa using add_limZero (Setoid.symm h) l, fun l => by simpa using add_limZero h l⟩ #align cau_seq.lim_zero_congr CauSeq.limZero_congr theorem abv_pos_of_not_limZero {f : CauSeq β abv} (hf : ¬LimZero f) : ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) := by haveI := Classical.propDecidable by_contra nk refine hf fun ε ε0 => ?_ simp? [not_forall] at nk says simp only [gt_iff_lt, ge_iff_le, not_exists, not_and, not_forall, Classical.not_imp, not_le] at nk cases' f.cauchy₃ (half_pos ε0) with i hi rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩ refine ⟨j, fun k jk => ?_⟩ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj) rwa [sub_add_cancel, add_halves] at this #align cau_seq.abv_pos_of_not_lim_zero CauSeq.abv_pos_of_not_limZero theorem of_near (f : ℕ → β) (g : CauSeq β abv) (h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) : IsCauSeq abv f | ε, ε0 => let ⟨i, hi⟩ := exists_forall_ge_and (h _ (half_pos <| half_pos ε0)) (g.cauchy₃ <| half_pos ε0) ⟨i, fun j ij => by cases' hi _ le_rfl with h₁ h₂; rw [abv_sub abv] at h₁ have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁) have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij)) rwa [add_halves, add_halves, add_right_comm, sub_add_sub_cancel, sub_add_sub_cancel] at this⟩ #align cau_seq.of_near CauSeq.of_near
Mathlib/Algebra/Order/CauSeq/Basic.lean
529
532
theorem not_limZero_of_not_congr_zero {f : CauSeq _ abv} (hf : ¬f ≈ 0) : ¬LimZero f := by
intro h have : LimZero (f - 0) := by simp [h] exact hf this
/- Copyright (c) 2021 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Damiano Testa, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Division import Mathlib.Algebra.Polynomial.Degree.Definitions import Mathlib.Algebra.Polynomial.Induction import Mathlib.Algebra.Polynomial.EraseLead import Mathlib.Order.Interval.Finset.Nat #align_import data.polynomial.inductions from "leanprover-community/mathlib"@"57e09a1296bfb4330ddf6624f1028ba186117d82" /-! # Induction on polynomials This file contains lemmas dealing with different flavours of induction on polynomials. -/ noncomputable section open Polynomial open Finset namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {A : Type z} {a b : R} {n : ℕ} section Semiring variable [Semiring R] {p q : R[X]} /-- `divX p` returns a polynomial `q` such that `q * X + C (p.coeff 0) = p`. It can be used in a semiring where the usual division algorithm is not possible -/ def divX (p : R[X]) : R[X] := ⟨AddMonoidAlgebra.divOf p.toFinsupp 1⟩ set_option linter.uppercaseLean3 false in #align polynomial.div_X Polynomial.divX @[simp] theorem coeff_divX : (divX p).coeff n = p.coeff (n + 1) := by rw [add_comm]; cases p; rfl set_option linter.uppercaseLean3 false in #align polynomial.coeff_div_X Polynomial.coeff_divX theorem divX_mul_X_add (p : R[X]) : divX p * X + C (p.coeff 0) = p := ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, Nat.succ_ne_zero, coeff_mul_X] set_option linter.uppercaseLean3 false in #align polynomial.div_X_mul_X_add Polynomial.divX_mul_X_add @[simp] theorem X_mul_divX_add (p : R[X]) : X * divX p + C (p.coeff 0) = p := ext <| by rintro ⟨_ | _⟩ <;> simp [coeff_C, Nat.succ_ne_zero, coeff_mul_X] @[simp] theorem divX_C (a : R) : divX (C a) = 0 := ext fun n => by simp [coeff_divX, coeff_C, Finsupp.single_eq_of_ne _] set_option linter.uppercaseLean3 false in #align polynomial.div_X_C Polynomial.divX_C theorem divX_eq_zero_iff : divX p = 0 ↔ p = C (p.coeff 0) := ⟨fun h => by simpa [eq_comm, h] using divX_mul_X_add p, fun h => by rw [h, divX_C]⟩ set_option linter.uppercaseLean3 false in #align polynomial.div_X_eq_zero_iff Polynomial.divX_eq_zero_iff theorem divX_add : divX (p + q) = divX p + divX q := ext <| by simp set_option linter.uppercaseLean3 false in #align polynomial.div_X_add Polynomial.divX_add @[simp] theorem divX_zero : divX (0 : R[X]) = 0 := leadingCoeff_eq_zero.mp rfl @[simp] theorem divX_one : divX (1 : R[X]) = 0 := by ext simpa only [coeff_divX, coeff_zero] using coeff_one @[simp] theorem divX_C_mul : divX (C a * p) = C a * divX p := by ext simp
Mathlib/Algebra/Polynomial/Inductions.lean
88
92
theorem divX_X_pow : divX (X ^ n : R[X]) = if (n = 0) then 0 else X ^ (n - 1) := by
cases n · simp · ext n simp [coeff_X_pow]
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.AffineMap import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Comp import Mathlib.Analysis.Calculus.LocalExtr.Rolle import Mathlib.Analysis.Convex.Normed import Mathlib.Analysis.RCLike.Basic #align_import analysis.calculus.mean_value from "leanprover-community/mathlib"@"3bce8d800a6f2b8f63fe1e588fd76a9ff4adcebe" /-! # The mean value inequality and equalities In this file we prove the following facts: * `Convex.norm_image_sub_le_of_norm_deriv_le` : if `f` is differentiable on a convex set `s` and the norm of its derivative is bounded by `C`, then `f` is Lipschitz continuous on `s` with constant `C`; also a variant in which what is bounded by `C` is the norm of the difference of the derivative from a fixed linear map. This lemma and its versions are formulated using `RCLike`, so they work both for real and complex derivatives. * `image_le_of*`, `image_norm_le_of_*` : several similar lemmas deducing `f x ≤ B x` or `‖f x‖ ≤ B x` from upper estimates on `f'` or `‖f'‖`, respectively. These lemmas differ by their assumptions: * `of_liminf_*` lemmas assume that limit inferior of some ratio is less than `B' x`; * `of_deriv_right_*`, `of_norm_deriv_right_*` lemmas assume that the right derivative or its norm is less than `B' x`; * `of_*_lt_*` lemmas assume a strict inequality whenever `f x = B x` or `‖f x‖ = B x`; * `of_*_le_*` lemmas assume a non-strict inequality everywhere on `[a, b)`; * name of a lemma ends with `'` if (1) it assumes that `B` is continuous on `[a, b]` and has a right derivative at every point of `[a, b)`, and (2) the lemma has a counterpart assuming that `B` is differentiable everywhere on `ℝ` * `norm_image_sub_le_*_segment` : if derivative of `f` on `[a, b]` is bounded above by a constant `C`, then `‖f x - f a‖ ≤ C * ‖x - a‖`; several versions deal with right derivative and derivative within `[a, b]` (`HasDerivWithinAt` or `derivWithin`). * `Convex.is_const_of_fderivWithin_eq_zero` : if a function has derivative `0` on a convex set `s`, then it is a constant on `s`. * `exists_ratio_hasDerivAt_eq_ratio_slope` and `exists_ratio_deriv_eq_ratio_slope` : Cauchy's Mean Value Theorem. * `exists_hasDerivAt_eq_slope` and `exists_deriv_eq_slope` : Lagrange's Mean Value Theorem. * `domain_mvt` : Lagrange's Mean Value Theorem, applied to a segment in a convex domain. * `Convex.image_sub_lt_mul_sub_of_deriv_lt`, `Convex.mul_sub_lt_image_sub_of_lt_deriv`, `Convex.image_sub_le_mul_sub_of_deriv_le`, `Convex.mul_sub_le_image_sub_of_le_deriv`, if `∀ x, C (</≤/>/≥) (f' x)`, then `C * (y - x) (</≤/>/≥) (f y - f x)` whenever `x < y`. * `monotoneOn_of_deriv_nonneg`, `antitoneOn_of_deriv_nonpos`, `strictMono_of_deriv_pos`, `strictAnti_of_deriv_neg` : if the derivative of a function is non-negative/non-positive/positive/negative, then the function is monotone/antitone/strictly monotone/strictly monotonically decreasing. * `convexOn_of_deriv`, `convexOn_of_deriv2_nonneg` : if the derivative of a function is increasing or its second derivative is nonnegative, then the original function is convex. * `hasStrictFDerivAt_of_hasFDerivAt_of_continuousAt` : a C^1 function over the reals is strictly differentiable. (This is a corollary of the mean value inequality.) -/ variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] open Metric Set Asymptotics ContinuousLinearMap Filter open scoped Classical Topology NNReal /-! ### One-dimensional fencing inequalities -/ /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by change Icc a b ⊆ { x | f x ≤ B x } set s := { x | f x ≤ B x } ∩ Icc a b have A : ContinuousOn (fun x => (f x, B x)) (Icc a b) := hf.prod hB have : IsClosed s := by simp only [s, inter_comm] exact A.preimage_isClosed_of_isClosed isClosed_Icc OrderClosedTopology.isClosed_le' apply this.Icc_subset_of_forall_exists_gt ha rintro x ⟨hxB : f x ≤ B x, xab⟩ y hy cases' hxB.lt_or_eq with hxB hxB · -- If `f x < B x`, then all we need is continuity of both sides refine nonempty_of_mem (inter_mem ?_ (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩)) have : ∀ᶠ x in 𝓝[Icc a b] x, f x < B x := A x (Ico_subset_Icc_self xab) (IsOpen.mem_nhds (isOpen_lt continuous_fst continuous_snd) hxB) have : ∀ᶠ x in 𝓝[>] x, f x < B x := nhdsWithin_le_of_mem (Icc_mem_nhdsWithin_Ioi xab) this exact this.mono fun y => le_of_lt · rcases exists_between (bound x xab hxB) with ⟨r, hfr, hrB⟩ specialize hf' x xab r hfr have HB : ∀ᶠ z in 𝓝[>] x, r < slope B x z := (hasDerivWithinAt_iff_tendsto_slope' <| lt_irrefl x).1 (hB' x xab).Ioi_of_Ici (Ioi_mem_nhds hrB) obtain ⟨z, hfz, hzB, hz⟩ : ∃ z, slope f x z < r ∧ r < slope B x z ∧ z ∈ Ioc x y := (hf'.and_eventually (HB.and (Ioc_mem_nhdsWithin_Ioi ⟨le_rfl, hy⟩))).exists refine ⟨z, ?_, hz⟩ have := (hfz.trans hzB).le rwa [slope_def_field, slope_def_field, div_le_div_right (sub_pos.2 hz.1), hxB, sub_le_sub_iff_right] at this #align image_le_of_liminf_slope_right_lt_deriv_boundary' image_le_of_liminf_slope_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (f z - f x) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_liminf_slope_right_lt_deriv_boundary image_le_of_liminf_slope_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(f z - f x) / (z - x)` is bounded above by `B'`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_liminf_slope_right_le_deriv_boundary {f : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) -- `bound` actually says `liminf (f z - f x) / (z - x) ≤ B' x` (bound : ∀ x ∈ Ico a b, ∀ r, B' x < r → ∃ᶠ z in 𝓝[>] x, slope f x z < r) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := by have Hr : ∀ x ∈ Icc a b, ∀ r > 0, f x ≤ B x + r * (x - a) := fun x hx r hr => by apply image_le_of_liminf_slope_right_lt_deriv_boundary' hf bound · rwa [sub_self, mul_zero, add_zero] · exact hB.add (continuousOn_const.mul (continuousOn_id.sub continuousOn_const)) · intro x hx exact (hB' x hx).add (((hasDerivWithinAt_id x (Ici x)).sub_const a).const_mul r) · intro x _ _ rw [mul_one] exact (lt_add_iff_pos_right _).2 hr exact hx intro x hx have : ContinuousWithinAt (fun r => B x + r * (x - a)) (Ioi 0) 0 := continuousWithinAt_const.add (continuousWithinAt_id.mul continuousWithinAt_const) convert continuousWithinAt_const.closure_le _ this (Hr x hx) using 1 <;> simp #align image_le_of_liminf_slope_right_le_deriv_boundary image_le_of_liminf_slope_right_le_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has right derivative `B'` at every point of `[a, b)`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary' {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_le hr) ha hB hB' bound #align image_le_of_deriv_right_lt_deriv_boundary' image_le_of_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x < B' x` whenever `f x = B x`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_lt_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, f x = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_le_of_deriv_right_lt_deriv_boundary image_le_of_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `f a ≤ B a`; * `B` has derivative `B'` everywhere on `ℝ`; * `f` has right derivative `f'` at every point of `[a, b)`; * we have `f' x ≤ B' x` on `[a, b)`. Then `f x ≤ B x` everywhere on `[a, b]`. -/ theorem image_le_of_deriv_right_le_deriv_boundary {f f' : ℝ → ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : f a ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, f' x ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → f x ≤ B x := image_le_of_liminf_slope_right_le_deriv_boundary hf ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_le (lt_of_le_of_lt (bound x hx) hr) #align image_le_of_deriv_right_le_deriv_boundary image_le_of_deriv_right_le_deriv_boundary /-! ### Vector-valued functions `f : ℝ → E` -/ section variable {f : ℝ → E} {a b : ℝ} /-- General fencing theorem for continuous functions with an estimate on the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `B` has right derivative at every point of `[a, b)`; * for each `x ∈ [a, b)` the right-side limit inferior of `(‖f z‖ - ‖f x‖) / (z - x)` is bounded above by a function `f'`; * we have `f' x < B' x` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. -/ theorem image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary {E : Type*} [NormedAddCommGroup E] {f : ℝ → E} {f' : ℝ → ℝ} (hf : ContinuousOn f (Icc a b)) -- `hf'` actually says `liminf (‖f z‖ - ‖f x‖) / (z - x) ≤ f' x` (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, slope (norm ∘ f) x z < r) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → f' x < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_le_of_liminf_slope_right_lt_deriv_boundary' (continuous_norm.comp_continuousOn hf) hf' ha hB hB' bound #align image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_liminf_right_slope_norm_lt_deriv_boundary hf (fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le hr) ha hB hB' bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary' image_norm_le_of_norm_deriv_right_lt_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * the norm of `f'` is strictly less than `B'` whenever `‖f x‖ = B x`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_lt_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f x‖ = B x → ‖f' x‖ < B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_norm_deriv_right_lt_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_lt_deriv_boundary image_norm_le_of_norm_deriv_right_lt_deriv_boundary /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` and `B` have right derivatives `f'` and `B'` respectively at every point of `[a, b)`; * we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary' {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ContinuousOn B (Icc a b)) (hB' : ∀ x ∈ Ico a b, HasDerivWithinAt B (B' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_le_of_liminf_slope_right_le_deriv_boundary (continuous_norm.comp_continuousOn hf) ha hB hB' fun x hx _ hr => (hf' x hx).liminf_right_slope_norm_le ((bound x hx).trans_lt hr) #align image_norm_le_of_norm_deriv_right_le_deriv_boundary' image_norm_le_of_norm_deriv_right_le_deriv_boundary' /-- General fencing theorem for continuous functions with an estimate on the norm of the derivative. Let `f` and `B` be continuous functions on `[a, b]` such that * `‖f a‖ ≤ B a`; * `f` has right derivative `f'` at every point of `[a, b)`; * `B` has derivative `B'` everywhere on `ℝ`; * we have `‖f' x‖ ≤ B x` everywhere on `[a, b)`. Then `‖f x‖ ≤ B x` everywhere on `[a, b]`. We use one-sided derivatives in the assumptions to make this theorem work for piecewise differentiable functions. -/ theorem image_norm_le_of_norm_deriv_right_le_deriv_boundary {f' : ℝ → E} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) {B B' : ℝ → ℝ} (ha : ‖f a‖ ≤ B a) (hB : ∀ x, HasDerivAt B (B' x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ B' x) : ∀ ⦃x⦄, x ∈ Icc a b → ‖f x‖ ≤ B x := image_norm_le_of_norm_deriv_right_le_deriv_boundary' hf hf' ha (fun x _ => (hB x).continuousAt.continuousWithinAt) (fun x _ => (hB x).hasDerivWithinAt) bound #align image_norm_le_of_norm_deriv_right_le_deriv_boundary image_norm_le_of_norm_deriv_right_le_deriv_boundary /-- A function on `[a, b]` with the norm of the right derivative bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`. -/ theorem norm_image_sub_le_of_norm_deriv_right_le_segment {f' : ℝ → E} {C : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by let g x := f x - f a have hg : ContinuousOn g (Icc a b) := hf.sub continuousOn_const have hg' : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x := by intro x hx simpa using (hf' x hx).sub (hasDerivWithinAt_const _ _ _) let B x := C * (x - a) have hB : ∀ x, HasDerivAt B C x := by intro x simpa using (hasDerivAt_const x C).mul ((hasDerivAt_id x).sub (hasDerivAt_const x a)) convert image_norm_le_of_norm_deriv_right_le_deriv_boundary hg hg' _ hB bound simp only [g, B]; rw [sub_self, norm_zero, sub_self, mul_zero] #align norm_image_sub_le_of_norm_deriv_right_le_segment norm_image_sub_le_of_norm_deriv_right_le_segment /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc a b, HasDerivWithinAt f (f' x) (Icc a b) x) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_right_le_segment (fun x hx => (hf x hx).continuousWithinAt) (fun x hx => ?_) bound exact (hf x <| Ico_subset_Icc_self hx).mono_of_mem (Icc_mem_nhdsWithin_Ici hx) #align norm_image_sub_le_of_norm_deriv_le_segment' norm_image_sub_le_of_norm_deriv_le_segment' /-- A function on `[a, b]` with the norm of the derivative within `[a, b]` bounded by `C` satisfies `‖f x - f a‖ ≤ C * (x - a)`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment {C : ℝ} (hf : DifferentiableOn ℝ f (Icc a b)) (bound : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ C) : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ C * (x - a) := by refine norm_image_sub_le_of_norm_deriv_le_segment' ?_ bound exact fun x hx => (hf x hx).hasDerivWithinAt #align norm_image_sub_le_of_norm_deriv_le_segment norm_image_sub_le_of_norm_deriv_le_segment /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `HasDerivWithinAt` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01' {f' : ℝ → E} {C : ℝ} (hf : ∀ x ∈ Icc (0 : ℝ) 1, HasDerivWithinAt f (f' x) (Icc (0 : ℝ) 1) x) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖f' x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment' hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01' norm_image_sub_le_of_norm_deriv_le_segment_01' /-- A function on `[0, 1]` with the norm of the derivative within `[0, 1]` bounded by `C` satisfies `‖f 1 - f 0‖ ≤ C`, `derivWithin` version. -/ theorem norm_image_sub_le_of_norm_deriv_le_segment_01 {C : ℝ} (hf : DifferentiableOn ℝ f (Icc (0 : ℝ) 1)) (bound : ∀ x ∈ Ico (0 : ℝ) 1, ‖derivWithin f (Icc (0 : ℝ) 1) x‖ ≤ C) : ‖f 1 - f 0‖ ≤ C := by simpa only [sub_zero, mul_one] using norm_image_sub_le_of_norm_deriv_le_segment hf bound 1 (right_mem_Icc.2 zero_le_one) #align norm_image_sub_le_of_norm_deriv_le_segment_01 norm_image_sub_le_of_norm_deriv_le_segment_01 theorem constant_of_has_deriv_right_zero (hcont : ContinuousOn f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, HasDerivWithinAt f 0 (Ici x) x) : ∀ x ∈ Icc a b, f x = f a := by have : ∀ x ∈ Icc a b, ‖f x - f a‖ ≤ 0 * (x - a) := fun x hx => norm_image_sub_le_of_norm_deriv_right_le_segment hcont hderiv (fun _ _ => norm_zero.le) x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using this #align constant_of_has_deriv_right_zero constant_of_has_deriv_right_zero theorem constant_of_derivWithin_zero (hdiff : DifferentiableOn ℝ f (Icc a b)) (hderiv : ∀ x ∈ Ico a b, derivWithin f (Icc a b) x = 0) : ∀ x ∈ Icc a b, f x = f a := by have H : ∀ x ∈ Ico a b, ‖derivWithin f (Icc a b) x‖ ≤ 0 := by simpa only [norm_le_zero_iff] using fun x hx => hderiv x hx simpa only [zero_mul, norm_le_zero_iff, sub_eq_zero] using fun x hx => norm_image_sub_le_of_norm_deriv_le_segment hdiff H x hx #align constant_of_deriv_within_zero constant_of_derivWithin_zero variable {f' g : ℝ → E} /-- If two continuous functions on `[a, b]` have the same right derivative and are equal at `a`, then they are equal everywhere on `[a, b]`. -/ theorem eq_of_has_deriv_right_eq (derivf : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (derivg : ∀ x ∈ Ico a b, HasDerivWithinAt g (f' x) (Ici x) x) (fcont : ContinuousOn f (Icc a b)) (gcont : ContinuousOn g (Icc a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by simp only [← @sub_eq_zero _ _ (f _)] at hi ⊢ exact hi ▸ constant_of_has_deriv_right_zero (fcont.sub gcont) fun y hy => by simpa only [sub_self] using (derivf y hy).sub (derivg y hy) #align eq_of_has_deriv_right_eq eq_of_has_deriv_right_eq /-- If two differentiable functions on `[a, b]` have the same derivative within `[a, b]` everywhere on `[a, b)` and are equal at `a`, then they are equal everywhere on `[a, b]`. -/
Mathlib/Analysis/Calculus/MeanValue.lean
423
433
theorem eq_of_derivWithin_eq (fdiff : DifferentiableOn ℝ f (Icc a b)) (gdiff : DifferentiableOn ℝ g (Icc a b)) (hderiv : EqOn (derivWithin f (Icc a b)) (derivWithin g (Icc a b)) (Ico a b)) (hi : f a = g a) : ∀ y ∈ Icc a b, f y = g y := by
have A : ∀ y ∈ Ico a b, HasDerivWithinAt f (derivWithin f (Icc a b) y) (Ici y) y := fun y hy => (fdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) have B : ∀ y ∈ Ico a b, HasDerivWithinAt g (derivWithin g (Icc a b) y) (Ici y) y := fun y hy => (gdiff y (mem_Icc_of_Ico hy)).hasDerivWithinAt.mono_of_mem (Icc_mem_nhdsWithin_Ici hy) exact eq_of_has_deriv_right_eq A (fun y hy => (hderiv hy).symm ▸ B y hy) fdiff.continuousOn gdiff.continuousOn hi
/- Copyright (c) 2020 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Thomas Browning, Patrick Lutz -/ import Mathlib.FieldTheory.Extension import Mathlib.FieldTheory.SplittingField.Construction import Mathlib.GroupTheory.Solvable #align_import field_theory.normal from "leanprover-community/mathlib"@"9fb8964792b4237dac6200193a0d533f1b3f7423" /-! # Normal field extensions In this file we define normal field extensions and prove that for a finite extension, being normal is the same as being a splitting field (`Normal.of_isSplittingField` and `Normal.exists_isSplittingField`). ## Main Definitions - `Normal F K` where `K` is a field extension of `F`. -/ noncomputable section open scoped Classical Polynomial open Polynomial IsScalarTower variable (F K : Type*) [Field F] [Field K] [Algebra F K] /-- Typeclass for normal field extension: `K` is a normal extension of `F` iff the minimal polynomial of every element `x` in `K` splits in `K`, i.e. every conjugate of `x` is in `K`. -/ class Normal extends Algebra.IsAlgebraic F K : Prop where splits' (x : K) : Splits (algebraMap F K) (minpoly F x) #align normal Normal variable {F K} theorem Normal.isIntegral (_ : Normal F K) (x : K) : IsIntegral F x := Algebra.IsIntegral.isIntegral x #align normal.is_integral Normal.isIntegral theorem Normal.splits (_ : Normal F K) (x : K) : Splits (algebraMap F K) (minpoly F x) := Normal.splits' x #align normal.splits Normal.splits theorem normal_iff : Normal F K ↔ ∀ x : K, IsIntegral F x ∧ Splits (algebraMap F K) (minpoly F x) := ⟨fun h x => ⟨h.isIntegral x, h.splits x⟩, fun h => { isAlgebraic := fun x => (h x).1.isAlgebraic splits' := fun x => (h x).2 }⟩ #align normal_iff normal_iff theorem Normal.out : Normal F K → ∀ x : K, IsIntegral F x ∧ Splits (algebraMap F K) (minpoly F x) := normal_iff.1 #align normal.out Normal.out variable (F K) instance normal_self : Normal F F where isAlgebraic := fun _ => isIntegral_algebraMap.isAlgebraic splits' := fun x => (minpoly.eq_X_sub_C' x).symm ▸ splits_X_sub_C _ #align normal_self normal_self theorem Normal.exists_isSplittingField [h : Normal F K] [FiniteDimensional F K] : ∃ p : F[X], IsSplittingField F K p := by let s := Basis.ofVectorSpace F K refine ⟨∏ x, minpoly F (s x), splits_prod _ fun x _ => h.splits (s x), Subalgebra.toSubmodule.injective ?_⟩ rw [Algebra.top_toSubmodule, eq_top_iff, ← s.span_eq, Submodule.span_le, Set.range_subset_iff] refine fun x => Algebra.subset_adjoin (Multiset.mem_toFinset.mpr <| (mem_roots <| mt (Polynomial.map_eq_zero <| algebraMap F K).1 <| Finset.prod_ne_zero_iff.2 fun x _ => ?_).2 ?_) · exact minpoly.ne_zero (h.isIntegral (s x)) rw [IsRoot.def, eval_map, ← aeval_def, AlgHom.map_prod] exact Finset.prod_eq_zero (Finset.mem_univ _) (minpoly.aeval _ _) #align normal.exists_is_splitting_field Normal.exists_isSplittingField section NormalTower variable (E : Type*) [Field E] [Algebra F E] [Algebra K E] [IsScalarTower F K E] theorem Normal.tower_top_of_normal [h : Normal F E] : Normal K E := normal_iff.2 fun x => by cases' h.out x with hx hhx rw [algebraMap_eq F K E] at hhx exact ⟨hx.tower_top, Polynomial.splits_of_splits_of_dvd (algebraMap K E) (Polynomial.map_ne_zero (minpoly.ne_zero hx)) ((Polynomial.splits_map_iff (algebraMap F K) (algebraMap K E)).mpr hhx) (minpoly.dvd_map_of_isScalarTower F K x)⟩ #align normal.tower_top_of_normal Normal.tower_top_of_normal theorem AlgHom.normal_bijective [h : Normal F E] (ϕ : E →ₐ[F] K) : Function.Bijective ϕ := h.toIsAlgebraic.bijective_of_isScalarTower' ϕ #align alg_hom.normal_bijective AlgHom.normal_bijective -- Porting note: `[Field F] [Field E] [Algebra F E]` added by hand. variable {F E} {E' : Type*} [Field F] [Field E] [Algebra F E] [Field E'] [Algebra F E']
Mathlib/FieldTheory/Normal.lean
107
111
theorem Normal.of_algEquiv [h : Normal F E] (f : E ≃ₐ[F] E') : Normal F E' := by
rw [normal_iff] at h ⊢ intro x; specialize h (f.symm x) rw [← f.apply_symm_apply x, minpoly.algEquiv_eq, ← f.toAlgHom.comp_algebraMap] exact ⟨h.1.map f, splits_comp_of_splits _ _ h.2⟩
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Init.Data.Sigma.Lex import Mathlib.Data.Prod.Lex import Mathlib.Data.Sigma.Lex import Mathlib.Order.Antichain import Mathlib.Order.OrderIsoNat import Mathlib.Order.WellFounded import Mathlib.Tactic.TFAE #align_import order.well_founded_set from "leanprover-community/mathlib"@"2c84c2c5496117349007d97104e7bbb471381592" /-! # Well-founded sets A well-founded subset of an ordered type is one on which the relation `<` is well-founded. ## Main Definitions * `Set.WellFoundedOn s r` indicates that the relation `r` is well-founded when restricted to the set `s`. * `Set.IsWF s` indicates that `<` is well-founded when restricted to `s`. * `Set.PartiallyWellOrderedOn s r` indicates that the relation `r` is partially well-ordered (also known as well quasi-ordered) when restricted to the set `s`. * `Set.IsPWO s` indicates that any infinite sequence of elements in `s` contains an infinite monotone subsequence. Note that this is equivalent to containing only two comparable elements. ## Main Results * Higman's Lemma, `Set.PartiallyWellOrderedOn.partiallyWellOrderedOn_sublistForall₂`, shows that if `r` is partially well-ordered on `s`, then `List.SublistForall₂` is partially well-ordered on the set of lists of elements of `s`. The result was originally published by Higman, but this proof more closely follows Nash-Williams. * `Set.wellFoundedOn_iff` relates `well_founded_on` to the well-foundedness of a relation on the original type, to avoid dealing with subtypes. * `Set.IsWF.mono` shows that a subset of a well-founded subset is well-founded. * `Set.IsWF.union` shows that the union of two well-founded subsets is well-founded. * `Finset.isWF` shows that all `Finset`s are well-founded. ## TODO Prove that `s` is partial well ordered iff it has no infinite descending chain or antichain. ## References * [Higman, *Ordering by Divisibility in Abstract Algebras*][Higman52] * [Nash-Williams, *On Well-Quasi-Ordering Finite Trees*][Nash-Williams63] -/ variable {ι α β γ : Type*} {π : ι → Type*} namespace Set /-! ### Relations well-founded on sets -/ /-- `s.WellFoundedOn r` indicates that the relation `r` is well-founded when restricted to `s`. -/ def WellFoundedOn (s : Set α) (r : α → α → Prop) : Prop := WellFounded fun a b : s => r a b #align set.well_founded_on Set.WellFoundedOn @[simp] theorem wellFoundedOn_empty (r : α → α → Prop) : WellFoundedOn ∅ r := wellFounded_of_isEmpty _ #align set.well_founded_on_empty Set.wellFoundedOn_empty section WellFoundedOn variable {r r' : α → α → Prop} section AnyRel variable {f : β → α} {s t : Set α} {x y : α} theorem wellFoundedOn_iff : s.WellFoundedOn r ↔ WellFounded fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := by have f : RelEmbedding (fun (a : s) (b : s) => r a b) fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s := ⟨⟨(↑), Subtype.coe_injective⟩, by simp⟩ refine ⟨fun h => ?_, f.wellFounded⟩ rw [WellFounded.wellFounded_iff_has_min] intro t ht by_cases hst : (s ∩ t).Nonempty · rw [← Subtype.preimage_coe_nonempty] at hst rcases h.has_min (Subtype.val ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩ exact ⟨m, mt, fun x xt ⟨xm, xs, _⟩ => hm ⟨x, xs⟩ xt xm⟩ · rcases ht with ⟨m, mt⟩ exact ⟨m, mt, fun x _ ⟨_, _, ms⟩ => hst ⟨m, ⟨ms, mt⟩⟩⟩ #align set.well_founded_on_iff Set.wellFoundedOn_iff @[simp] theorem wellFoundedOn_univ : (univ : Set α).WellFoundedOn r ↔ WellFounded r := by simp [wellFoundedOn_iff] #align set.well_founded_on_univ Set.wellFoundedOn_univ theorem _root_.WellFounded.wellFoundedOn : WellFounded r → s.WellFoundedOn r := InvImage.wf _ #align well_founded.well_founded_on WellFounded.wellFoundedOn @[simp] theorem wellFoundedOn_range : (range f).WellFoundedOn r ↔ WellFounded (r on f) := by let f' : β → range f := fun c => ⟨f c, c, rfl⟩ refine ⟨fun h => (InvImage.wf f' h).mono fun c c' => id, fun h => ⟨?_⟩⟩ rintro ⟨_, c, rfl⟩ refine Acc.of_downward_closed f' ?_ _ ?_ · rintro _ ⟨_, c', rfl⟩ - exact ⟨c', rfl⟩ · exact h.apply _ #align set.well_founded_on_range Set.wellFoundedOn_range @[simp] theorem wellFoundedOn_image {s : Set β} : (f '' s).WellFoundedOn r ↔ s.WellFoundedOn (r on f) := by rw [image_eq_range]; exact wellFoundedOn_range #align set.well_founded_on_image Set.wellFoundedOn_image namespace WellFoundedOn protected theorem induction (hs : s.WellFoundedOn r) (hx : x ∈ s) {P : α → Prop} (hP : ∀ y ∈ s, (∀ z ∈ s, r z y → P z) → P y) : P x := by let Q : s → Prop := fun y => P y change Q ⟨x, hx⟩ refine WellFounded.induction hs ⟨x, hx⟩ ?_ simpa only [Subtype.forall] #align set.well_founded_on.induction Set.WellFoundedOn.induction protected theorem mono (h : t.WellFoundedOn r') (hle : r ≤ r') (hst : s ⊆ t) : s.WellFoundedOn r := by rw [wellFoundedOn_iff] at * exact Subrelation.wf (fun xy => ⟨hle _ _ xy.1, hst xy.2.1, hst xy.2.2⟩) h #align set.well_founded_on.mono Set.WellFoundedOn.mono theorem mono' (h : ∀ (a) (_ : a ∈ s) (b) (_ : b ∈ s), r' a b → r a b) : s.WellFoundedOn r → s.WellFoundedOn r' := Subrelation.wf @fun a b => h _ a.2 _ b.2 #align set.well_founded_on.mono' Set.WellFoundedOn.mono' theorem subset (h : t.WellFoundedOn r) (hst : s ⊆ t) : s.WellFoundedOn r := h.mono le_rfl hst #align set.well_founded_on.subset Set.WellFoundedOn.subset open Relation open List in /-- `a` is accessible under the relation `r` iff `r` is well-founded on the downward transitive closure of `a` under `r` (including `a` or not). -/ theorem acc_iff_wellFoundedOn {α} {r : α → α → Prop} {a : α} : TFAE [Acc r a, WellFoundedOn { b | ReflTransGen r b a } r, WellFoundedOn { b | TransGen r b a } r] := by tfae_have 1 → 2 · refine fun h => ⟨fun b => InvImage.accessible _ ?_⟩ rw [← acc_transGen_iff] at h ⊢ obtain h' | h' := reflTransGen_iff_eq_or_transGen.1 b.2 · rwa [h'] at h · exact h.inv h' tfae_have 2 → 3 · exact fun h => h.subset fun _ => TransGen.to_reflTransGen tfae_have 3 → 1 · refine fun h => Acc.intro _ (fun b hb => (h.apply ⟨b, .single hb⟩).of_fibration Subtype.val ?_) exact fun ⟨c, hc⟩ d h => ⟨⟨d, .head h hc⟩, h, rfl⟩ tfae_finish #align set.well_founded_on.acc_iff_well_founded_on Set.WellFoundedOn.acc_iff_wellFoundedOn end WellFoundedOn end AnyRel section IsStrictOrder variable [IsStrictOrder α r] {s t : Set α} instance IsStrictOrder.subset : IsStrictOrder α fun a b : α => r a b ∧ a ∈ s ∧ b ∈ s where toIsIrrefl := ⟨fun a con => irrefl_of r a con.1⟩ toIsTrans := ⟨fun _ _ _ ab bc => ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩⟩ #align set.is_strict_order.subset Set.IsStrictOrder.subset theorem wellFoundedOn_iff_no_descending_seq : s.WellFoundedOn r ↔ ∀ f : ((· > ·) : ℕ → ℕ → Prop) ↪r r, ¬∀ n, f n ∈ s := by simp only [wellFoundedOn_iff, RelEmbedding.wellFounded_iff_no_descending_seq, ← not_exists, ← not_nonempty_iff, not_iff_not] constructor · rintro ⟨⟨f, hf⟩⟩ have H : ∀ n, f n ∈ s := fun n => (hf.2 n.lt_succ_self).2.2 refine ⟨⟨f, ?_⟩, H⟩ simpa only [H, and_true_iff] using @hf · rintro ⟨⟨f, hf⟩, hfs : ∀ n, f n ∈ s⟩ refine ⟨⟨f, ?_⟩⟩ simpa only [hfs, and_true_iff] using @hf #align set.well_founded_on_iff_no_descending_seq Set.wellFoundedOn_iff_no_descending_seq theorem WellFoundedOn.union (hs : s.WellFoundedOn r) (ht : t.WellFoundedOn r) : (s ∪ t).WellFoundedOn r := by rw [wellFoundedOn_iff_no_descending_seq] at * rintro f hf rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hg | hg⟩ exacts [hs (g.dual.ltEmbedding.trans f) hg, ht (g.dual.ltEmbedding.trans f) hg] #align set.well_founded_on.union Set.WellFoundedOn.union @[simp] theorem wellFoundedOn_union : (s ∪ t).WellFoundedOn r ↔ s.WellFoundedOn r ∧ t.WellFoundedOn r := ⟨fun h => ⟨h.subset subset_union_left, h.subset subset_union_right⟩, fun h => h.1.union h.2⟩ #align set.well_founded_on_union Set.wellFoundedOn_union end IsStrictOrder end WellFoundedOn /-! ### Sets well-founded w.r.t. the strict inequality -/ section LT variable [LT α] {s t : Set α} /-- `s.IsWF` indicates that `<` is well-founded when restricted to `s`. -/ def IsWF (s : Set α) : Prop := WellFoundedOn s (· < ·) #align set.is_wf Set.IsWF @[simp] theorem isWF_empty : IsWF (∅ : Set α) := wellFounded_of_isEmpty _ #align set.is_wf_empty Set.isWF_empty theorem isWF_univ_iff : IsWF (univ : Set α) ↔ WellFounded ((· < ·) : α → α → Prop) := by simp [IsWF, wellFoundedOn_iff] #align set.is_wf_univ_iff Set.isWF_univ_iff theorem IsWF.mono (h : IsWF t) (st : s ⊆ t) : IsWF s := h.subset st #align set.is_wf.mono Set.IsWF.mono end LT section Preorder variable [Preorder α] {s t : Set α} {a : α} protected nonrec theorem IsWF.union (hs : IsWF s) (ht : IsWF t) : IsWF (s ∪ t) := hs.union ht #align set.is_wf.union Set.IsWF.union @[simp] theorem isWF_union : IsWF (s ∪ t) ↔ IsWF s ∧ IsWF t := wellFoundedOn_union #align set.is_wf_union Set.isWF_union end Preorder section Preorder variable [Preorder α] {s t : Set α} {a : α} theorem isWF_iff_no_descending_seq : IsWF s ↔ ∀ f : ℕ → α, StrictAnti f → ¬∀ n, f (OrderDual.toDual n) ∈ s := wellFoundedOn_iff_no_descending_seq.trans ⟨fun H f hf => H ⟨⟨f, hf.injective⟩, hf.lt_iff_lt⟩, fun H f => H f fun _ _ => f.map_rel_iff.2⟩ #align set.is_wf_iff_no_descending_seq Set.isWF_iff_no_descending_seq end Preorder /-! ### Partially well-ordered sets A set is partially well-ordered by a relation `r` when any infinite sequence contains two elements where the first is related to the second by `r`. Equivalently, any antichain (see `IsAntichain`) is finite, see `Set.partiallyWellOrderedOn_iff_finite_antichains`. -/ /-- A subset is partially well-ordered by a relation `r` when any infinite sequence contains two elements where the first is related to the second by `r`. -/ def PartiallyWellOrderedOn (s : Set α) (r : α → α → Prop) : Prop := ∀ f : ℕ → α, (∀ n, f n ∈ s) → ∃ m n : ℕ, m < n ∧ r (f m) (f n) #align set.partially_well_ordered_on Set.PartiallyWellOrderedOn section PartiallyWellOrderedOn variable {r : α → α → Prop} {r' : β → β → Prop} {f : α → β} {s : Set α} {t : Set α} {a : α} theorem PartiallyWellOrderedOn.mono (ht : t.PartiallyWellOrderedOn r) (h : s ⊆ t) : s.PartiallyWellOrderedOn r := fun f hf => ht f fun n => h <| hf n #align set.partially_well_ordered_on.mono Set.PartiallyWellOrderedOn.mono @[simp] theorem partiallyWellOrderedOn_empty (r : α → α → Prop) : PartiallyWellOrderedOn ∅ r := fun _ h => (h 0).elim #align set.partially_well_ordered_on_empty Set.partiallyWellOrderedOn_empty theorem PartiallyWellOrderedOn.union (hs : s.PartiallyWellOrderedOn r) (ht : t.PartiallyWellOrderedOn r) : (s ∪ t).PartiallyWellOrderedOn r := by rintro f hf rcases Nat.exists_subseq_of_forall_mem_union f hf with ⟨g, hgs | hgt⟩ · rcases hs _ hgs with ⟨m, n, hlt, hr⟩ exact ⟨g m, g n, g.strictMono hlt, hr⟩ · rcases ht _ hgt with ⟨m, n, hlt, hr⟩ exact ⟨g m, g n, g.strictMono hlt, hr⟩ #align set.partially_well_ordered_on.union Set.PartiallyWellOrderedOn.union @[simp] theorem partiallyWellOrderedOn_union : (s ∪ t).PartiallyWellOrderedOn r ↔ s.PartiallyWellOrderedOn r ∧ t.PartiallyWellOrderedOn r := ⟨fun h => ⟨h.mono subset_union_left, h.mono subset_union_right⟩, fun h => h.1.union h.2⟩ #align set.partially_well_ordered_on_union Set.partiallyWellOrderedOn_union theorem PartiallyWellOrderedOn.image_of_monotone_on (hs : s.PartiallyWellOrderedOn r) (hf : ∀ a₁ ∈ s, ∀ a₂ ∈ s, r a₁ a₂ → r' (f a₁) (f a₂)) : (f '' s).PartiallyWellOrderedOn r' := by intro g' hg' choose g hgs heq using hg' obtain rfl : f ∘ g = g' := funext heq obtain ⟨m, n, hlt, hmn⟩ := hs g hgs exact ⟨m, n, hlt, hf _ (hgs m) _ (hgs n) hmn⟩ #align set.partially_well_ordered_on.image_of_monotone_on Set.PartiallyWellOrderedOn.image_of_monotone_on
Mathlib/Order/WellFoundedSet.lean
312
317
theorem _root_.IsAntichain.finite_of_partiallyWellOrderedOn (ha : IsAntichain r s) (hp : s.PartiallyWellOrderedOn r) : s.Finite := by
refine not_infinite.1 fun hi => ?_ obtain ⟨m, n, hmn, h⟩ := hp (fun n => hi.natEmbedding _ n) fun n => (hi.natEmbedding _ n).2 exact hmn.ne ((hi.natEmbedding _).injective <| Subtype.val_injective <| ha.eq (hi.natEmbedding _ m).2 (hi.natEmbedding _ n).2 h)
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Alex Kontorovich, Heather Macbeth -/ import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.MeasureTheory.Measure.Haar.Quotient import Mathlib.MeasureTheory.Constructions.Polish import Mathlib.MeasureTheory.Integral.IntervalIntegral import Mathlib.Topology.Algebra.Order.Floor #align_import measure_theory.integral.periodic from "leanprover-community/mathlib"@"9f55d0d4363ae59948c33864cbc52e0b12e0e8ce" /-! # Integrals of periodic functions In this file we prove that the half-open interval `Ioc t (t + T)` in `ℝ` is a fundamental domain of the action of the subgroup `ℤ ∙ T` on `ℝ`. A consequence is `AddCircle.measurePreserving_mk`: the covering map from `ℝ` to the "additive circle" `ℝ ⧸ (ℤ ∙ T)` is measure-preserving, with respect to the restriction of Lebesgue measure to `Ioc t (t + T)` (upstairs) and with respect to Haar measure (downstairs). Another consequence (`Function.Periodic.intervalIntegral_add_eq` and related declarations) is that `∫ x in t..t + T, f x = ∫ x in s..s + T, f x` for any (not necessarily measurable) function with period `T`. -/ open Set Function MeasureTheory MeasureTheory.Measure TopologicalSpace AddSubgroup intervalIntegral open scoped MeasureTheory NNReal ENNReal @[measurability] protected theorem AddCircle.measurable_mk' {a : ℝ} : Measurable (β := AddCircle a) ((↑) : ℝ → AddCircle a) := Continuous.measurable <| AddCircle.continuous_mk' a #align add_circle.measurable_mk' AddCircle.measurable_mk' theorem isAddFundamentalDomain_Ioc {T : ℝ} (hT : 0 < T) (t : ℝ) (μ : Measure ℝ := by volume_tac) : IsAddFundamentalDomain (AddSubgroup.zmultiples T) (Ioc t (t + T)) μ := by refine IsAddFundamentalDomain.mk' measurableSet_Ioc.nullMeasurableSet fun x => ?_ have : Bijective (codRestrict (fun n : ℤ => n • T) (AddSubgroup.zmultiples T) _) := (Equiv.ofInjective (fun n : ℤ => n • T) (zsmul_strictMono_left hT).injective).bijective refine this.existsUnique_iff.2 ?_ simpa only [add_comm x] using existsUnique_add_zsmul_mem_Ioc hT x t #align is_add_fundamental_domain_Ioc isAddFundamentalDomain_Ioc theorem isAddFundamentalDomain_Ioc' {T : ℝ} (hT : 0 < T) (t : ℝ) (μ : Measure ℝ := by volume_tac) : IsAddFundamentalDomain (AddSubgroup.op <| .zmultiples T) (Ioc t (t + T)) μ := by refine IsAddFundamentalDomain.mk' measurableSet_Ioc.nullMeasurableSet fun x => ?_ have : Bijective (codRestrict (fun n : ℤ => n • T) (AddSubgroup.zmultiples T) _) := (Equiv.ofInjective (fun n : ℤ => n • T) (zsmul_strictMono_left hT).injective).bijective refine (AddSubgroup.equivOp _).bijective.comp this |>.existsUnique_iff.2 ?_ simpa using existsUnique_add_zsmul_mem_Ioc hT x t #align is_add_fundamental_domain_Ioc' isAddFundamentalDomain_Ioc' namespace AddCircle variable (T : ℝ) [hT : Fact (0 < T)] /-- Equip the "additive circle" `ℝ ⧸ (ℤ ∙ T)` with, as a standard measure, the Haar measure of total mass `T` -/ noncomputable instance measureSpace : MeasureSpace (AddCircle T) := { QuotientAddGroup.measurableSpace _ with volume := ENNReal.ofReal T • addHaarMeasure ⊤ } #align add_circle.measure_space AddCircle.measureSpace #adaptation_note /-- nightly-2024-04-01 The simpNF linter now times out on this lemma. -/ @[simp, nolint simpNF] protected theorem measure_univ : volume (Set.univ : Set (AddCircle T)) = ENNReal.ofReal T := by dsimp [volume] rw [← PositiveCompacts.coe_top] simp [addHaarMeasure_self (G := AddCircle T), -PositiveCompacts.coe_top] #align add_circle.measure_univ AddCircle.measure_univ instance : IsAddHaarMeasure (volume : Measure (AddCircle T)) := IsAddHaarMeasure.smul _ (by simp [hT.out]) ENNReal.ofReal_ne_top instance isFiniteMeasure : IsFiniteMeasure (volume : Measure (AddCircle T)) where measure_univ_lt_top := by simp #align add_circle.is_finite_measure AddCircle.isFiniteMeasure instance : HasAddFundamentalDomain (AddSubgroup.op <| .zmultiples T) ℝ where ExistsIsAddFundamentalDomain := ⟨Ioc 0 (0 + T), isAddFundamentalDomain_Ioc' Fact.out 0⟩ instance : AddQuotientMeasureEqMeasurePreimage volume (volume : Measure (AddCircle T)) := by apply MeasureTheory.leftInvariantIsAddQuotientMeasureEqMeasurePreimage simp [(isAddFundamentalDomain_Ioc' hT.out 0).covolume_eq_volume, AddCircle.measure_univ] /-- The covering map from `ℝ` to the "additive circle" `ℝ ⧸ (ℤ ∙ T)` is measure-preserving, considered with respect to the standard measure (defined to be the Haar measure of total mass `T`) on the additive circle, and with respect to the restriction of Lebsegue measure on `ℝ` to an interval (t, t + T]. -/ protected theorem measurePreserving_mk (t : ℝ) : MeasurePreserving (β := AddCircle T) ((↑) : ℝ → AddCircle T) (volume.restrict (Ioc t (t + T))) := measurePreserving_quotientAddGroup_mk_of_AddQuotientMeasureEqMeasurePreimage volume (𝓕 := Ioc t (t+T)) (isAddFundamentalDomain_Ioc' hT.out _) _ #align add_circle.measure_preserving_mk AddCircle.measurePreserving_mk lemma add_projection_respects_measure (t : ℝ) {U : Set (AddCircle T)} (meas_U : MeasurableSet U) : volume U = volume (QuotientAddGroup.mk ⁻¹' U ∩ (Ioc t (t + T))) := (isAddFundamentalDomain_Ioc' hT.out _).addProjection_respects_measure_apply (volume : Measure (AddCircle T)) meas_U theorem volume_closedBall {x : AddCircle T} (ε : ℝ) : volume (Metric.closedBall x ε) = ENNReal.ofReal (min T (2 * ε)) := by have hT' : |T| = T := abs_eq_self.mpr hT.out.le let I := Ioc (-(T / 2)) (T / 2) have h₁ : ε < T / 2 → Metric.closedBall (0 : ℝ) ε ∩ I = Metric.closedBall (0 : ℝ) ε := by intro hε rw [inter_eq_left, Real.closedBall_eq_Icc, zero_sub, zero_add] rintro y ⟨hy₁, hy₂⟩; constructor <;> linarith have h₂ : (↑) ⁻¹' Metric.closedBall (0 : AddCircle T) ε ∩ I = if ε < T / 2 then Metric.closedBall (0 : ℝ) ε else I := by conv_rhs => rw [← if_ctx_congr (Iff.rfl : ε < T / 2 ↔ ε < T / 2) h₁ fun _ => rfl, ← hT'] apply coe_real_preimage_closedBall_inter_eq simpa only [hT', Real.closedBall_eq_Icc, zero_add, zero_sub] using Ioc_subset_Icc_self rw [addHaar_closedBall_center, add_projection_respects_measure T (-(T/2)) measurableSet_closedBall, (by linarith : -(T / 2) + T = T / 2), h₂] by_cases hε : ε < T / 2 · simp [hε, min_eq_right (by linarith : 2 * ε ≤ T)] · simp [I, hε, min_eq_left (by linarith : T ≤ 2 * ε)] #align add_circle.volume_closed_ball AddCircle.volume_closedBall instance : IsUnifLocDoublingMeasure (volume : Measure (AddCircle T)) := by refine ⟨⟨Real.toNNReal 2, Filter.eventually_of_forall fun ε x => ?_⟩⟩ simp only [volume_closedBall] erw [← ENNReal.ofReal_mul zero_le_two] apply ENNReal.ofReal_le_ofReal rw [mul_min_of_nonneg _ _ (zero_le_two : (0 : ℝ) ≤ 2)] exact min_le_min (by linarith [hT.out]) (le_refl _) /-- The isomorphism `AddCircle T ≃ Ioc a (a + T)` whose inverse is the natural quotient map, as an equivalence of measurable spaces. -/ noncomputable def measurableEquivIoc (a : ℝ) : AddCircle T ≃ᵐ Ioc a (a + T) where toEquiv := equivIoc T a measurable_toFun := measurable_of_measurable_on_compl_singleton _ (continuousOn_iff_continuous_restrict.mp <| ContinuousAt.continuousOn fun _x hx => continuousAt_equivIoc T a hx).measurable measurable_invFun := AddCircle.measurable_mk'.comp measurable_subtype_coe #align add_circle.measurable_equiv_Ioc AddCircle.measurableEquivIoc /-- The isomorphism `AddCircle T ≃ Ico a (a + T)` whose inverse is the natural quotient map, as an equivalence of measurable spaces. -/ noncomputable def measurableEquivIco (a : ℝ) : AddCircle T ≃ᵐ Ico a (a + T) where toEquiv := equivIco T a measurable_toFun := measurable_of_measurable_on_compl_singleton _ (continuousOn_iff_continuous_restrict.mp <| ContinuousAt.continuousOn fun _x hx => continuousAt_equivIco T a hx).measurable measurable_invFun := AddCircle.measurable_mk'.comp measurable_subtype_coe #align add_circle.measurable_equiv_Ico AddCircle.measurableEquivIco attribute [local instance] Subtype.measureSpace in /-- The lower integral of a function over `AddCircle T` is equal to the lower integral over an interval (t, t + T] in `ℝ` of its lift to `ℝ`. -/ protected theorem lintegral_preimage (t : ℝ) (f : AddCircle T → ℝ≥0∞) : (∫⁻ a in Ioc t (t + T), f a) = ∫⁻ b : AddCircle T, f b := by have m : MeasurableSet (Ioc t (t + T)) := measurableSet_Ioc have := lintegral_map_equiv (μ := volume) f (measurableEquivIoc T t).symm simp only [measurableEquivIoc, equivIoc, QuotientAddGroup.equivIocMod, MeasurableEquiv.symm_mk, MeasurableEquiv.coe_mk, Equiv.coe_fn_symm_mk] at this rw [← (AddCircle.measurePreserving_mk T t).map_eq] convert this.symm using 1 · rw [← map_comap_subtype_coe m _] exact MeasurableEmbedding.lintegral_map (MeasurableEmbedding.subtype_coe m) _ · congr 1 have : ((↑) : Ioc t (t + T) → AddCircle T) = ((↑) : ℝ → AddCircle T) ∘ ((↑) : _ → ℝ) := by ext1 x; rfl simp_rw [this] rw [← map_map AddCircle.measurable_mk' measurable_subtype_coe, ← map_comap_subtype_coe m] rfl #align add_circle.lintegral_preimage AddCircle.lintegral_preimage variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] attribute [local instance] Subtype.measureSpace in /-- The integral of an almost-everywhere strongly measurable function over `AddCircle T` is equal to the integral over an interval (t, t + T] in `ℝ` of its lift to `ℝ`. -/ protected theorem integral_preimage (t : ℝ) (f : AddCircle T → E) : (∫ a in Ioc t (t + T), f a) = ∫ b : AddCircle T, f b := by have m : MeasurableSet (Ioc t (t + T)) := measurableSet_Ioc have := integral_map_equiv (μ := volume) (measurableEquivIoc T t).symm f simp only [measurableEquivIoc, equivIoc, QuotientAddGroup.equivIocMod, MeasurableEquiv.symm_mk, MeasurableEquiv.coe_mk, Equiv.coe_fn_symm_mk] at this rw [← (AddCircle.measurePreserving_mk T t).map_eq, ← integral_subtype m, ← this] have : ((↑) : Ioc t (t + T) → AddCircle T) = ((↑) : ℝ → AddCircle T) ∘ ((↑) : _ → ℝ) := by ext1 x; rfl simp_rw [this] rw [← map_map AddCircle.measurable_mk' measurable_subtype_coe, ← map_comap_subtype_coe m] rfl #align add_circle.integral_preimage AddCircle.integral_preimage /-- The integral of an almost-everywhere strongly measurable function over `AddCircle T` is equal to the integral over an interval (t, t + T] in `ℝ` of its lift to `ℝ`. -/ protected theorem intervalIntegral_preimage (t : ℝ) (f : AddCircle T → E) : ∫ a in t..t + T, f a = ∫ b : AddCircle T, f b := by rw [integral_of_le, AddCircle.integral_preimage T t f] linarith [hT.out] #align add_circle.interval_integral_preimage AddCircle.intervalIntegral_preimage end AddCircle namespace UnitAddCircle attribute [local instance] Real.fact_zero_lt_one protected theorem measure_univ : volume (Set.univ : Set UnitAddCircle) = 1 := by simp #align unit_add_circle.measure_univ UnitAddCircle.measure_univ /-- The covering map from `ℝ` to the "unit additive circle" `ℝ ⧸ ℤ` is measure-preserving, considered with respect to the standard measure (defined to be the Haar measure of total mass 1) on the additive circle, and with respect to the restriction of Lebsegue measure on `ℝ` to an interval (t, t + 1]. -/ protected theorem measurePreserving_mk (t : ℝ) : MeasurePreserving (β := UnitAddCircle) ((↑) : ℝ → UnitAddCircle) (volume.restrict (Ioc t (t + 1))) := AddCircle.measurePreserving_mk 1 t #align unit_add_circle.measure_preserving_mk UnitAddCircle.measurePreserving_mk /-- The integral of a measurable function over `UnitAddCircle` is equal to the integral over an interval (t, t + 1] in `ℝ` of its lift to `ℝ`. -/ protected theorem lintegral_preimage (t : ℝ) (f : UnitAddCircle → ℝ≥0∞) : (∫⁻ a in Ioc t (t + 1), f a) = ∫⁻ b : UnitAddCircle, f b := AddCircle.lintegral_preimage 1 t f #align unit_add_circle.lintegral_preimage UnitAddCircle.lintegral_preimage variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] /-- The integral of an almost-everywhere strongly measurable function over `UnitAddCircle` is equal to the integral over an interval (t, t + 1] in `ℝ` of its lift to `ℝ`. -/ protected theorem integral_preimage (t : ℝ) (f : UnitAddCircle → E) : (∫ a in Ioc t (t + 1), f a) = ∫ b : UnitAddCircle, f b := AddCircle.integral_preimage 1 t f #align unit_add_circle.integral_preimage UnitAddCircle.integral_preimage /-- The integral of an almost-everywhere strongly measurable function over `UnitAddCircle` is equal to the integral over an interval (t, t + 1] in `ℝ` of its lift to `ℝ`. -/ protected theorem intervalIntegral_preimage (t : ℝ) (f : UnitAddCircle → E) : ∫ a in t..t + 1, f a = ∫ b : UnitAddCircle, f b := AddCircle.intervalIntegral_preimage 1 t f #align unit_add_circle.interval_integral_preimage UnitAddCircle.intervalIntegral_preimage end UnitAddCircle variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] namespace Function namespace Periodic variable {f : ℝ → E} {T : ℝ} /-- An auxiliary lemma for a more general `Function.Periodic.intervalIntegral_add_eq`. -/ theorem intervalIntegral_add_eq_of_pos (hf : Periodic f T) (hT : 0 < T) (t s : ℝ) : ∫ x in t..t + T, f x = ∫ x in s..s + T, f x := by simp only [integral_of_le, hT.le, le_add_iff_nonneg_right] haveI : VAddInvariantMeasure (AddSubgroup.zmultiples T) ℝ volume := ⟨fun c s _ => measure_preimage_add _ _ _⟩ apply IsAddFundamentalDomain.setIntegral_eq (G := AddSubgroup.zmultiples T) exacts [isAddFundamentalDomain_Ioc hT t, isAddFundamentalDomain_Ioc hT s, hf.map_vadd_zmultiples] #align function.periodic.interval_integral_add_eq_of_pos Function.Periodic.intervalIntegral_add_eq_of_pos /-- If `f` is a periodic function with period `T`, then its integral over `[t, t + T]` does not depend on `t`. -/ theorem intervalIntegral_add_eq (hf : Periodic f T) (t s : ℝ) : ∫ x in t..t + T, f x = ∫ x in s..s + T, f x := by rcases lt_trichotomy (0 : ℝ) T with (hT | rfl | hT) · exact hf.intervalIntegral_add_eq_of_pos hT t s · simp · rw [← neg_inj, ← integral_symm, ← integral_symm] simpa only [← sub_eq_add_neg, add_sub_cancel_right] using hf.neg.intervalIntegral_add_eq_of_pos (neg_pos.2 hT) (t + T) (s + T) #align function.periodic.interval_integral_add_eq Function.Periodic.intervalIntegral_add_eq /-- If `f` is an integrable periodic function with period `T`, then its integral over `[t, s + T]` is the sum of its integrals over the intervals `[t, s]` and `[t, t + T]`. -/ theorem intervalIntegral_add_eq_add (hf : Periodic f T) (t s : ℝ) (h_int : ∀ t₁ t₂, IntervalIntegrable f MeasureSpace.volume t₁ t₂) : ∫ x in t..s + T, f x = (∫ x in t..s, f x) + ∫ x in t..t + T, f x := by rw [hf.intervalIntegral_add_eq t s, integral_add_adjacent_intervals (h_int t s) (h_int s _)] #align function.periodic.interval_integral_add_eq_add Function.Periodic.intervalIntegral_add_eq_add /-- If `f` is an integrable periodic function with period `T`, and `n` is an integer, then its integral over `[t, t + n • T]` is `n` times its integral over `[t, t + T]`. -/ theorem intervalIntegral_add_zsmul_eq (hf : Periodic f T) (n : ℤ) (t : ℝ) (h_int : ∀ t₁ t₂, IntervalIntegrable f MeasureSpace.volume t₁ t₂) : ∫ x in t..t + n • T, f x = n • ∫ x in t..t + T, f x := by -- Reduce to the case `b = 0` suffices (∫ x in (0)..(n • T), f x) = n • ∫ x in (0)..T, f x by simp only [hf.intervalIntegral_add_eq t 0, (hf.zsmul n).intervalIntegral_add_eq t 0, zero_add, this] -- First prove it for natural numbers have : ∀ m : ℕ, (∫ x in (0)..m • T, f x) = m • ∫ x in (0)..T, f x := fun m ↦ by induction' m with m ih · simp · simp only [succ_nsmul, hf.intervalIntegral_add_eq_add 0 (m • T) h_int, ih, zero_add] -- Then prove it for all integers cases' n with n n · simp [← this n] · conv_rhs => rw [negSucc_zsmul] have h₀ : Int.negSucc n • T + (n + 1) • T = 0 := by simp; linarith rw [integral_symm, ← (hf.nsmul (n + 1)).funext, neg_inj] simp_rw [integral_comp_add_right, h₀, zero_add, this (n + 1), add_comm T, hf.intervalIntegral_add_eq ((n + 1) • T) 0, zero_add] #align function.periodic.interval_integral_add_zsmul_eq Function.Periodic.intervalIntegral_add_zsmul_eq section RealValued open Filter variable {g : ℝ → ℝ} variable (hg : Periodic g T) (h_int : ∀ t₁ t₂, IntervalIntegrable g MeasureSpace.volume t₁ t₂) /-- If `g : ℝ → ℝ` is periodic with period `T > 0`, then for any `t : ℝ`, the function `t ↦ ∫ x in 0..t, g x` is bounded below by `t ↦ X + ⌊t/T⌋ • Y` for appropriate constants `X` and `Y`. -/ theorem sInf_add_zsmul_le_integral_of_pos (hT : 0 < T) (t : ℝ) : (sInf ((fun t => ∫ x in (0)..t, g x) '' Icc 0 T) + ⌊t / T⌋ • ∫ x in (0)..T, g x) ≤ ∫ x in (0)..t, g x := by let ε := Int.fract (t / T) * T conv_rhs => rw [← Int.fract_div_mul_self_add_zsmul_eq T t (by linarith), ← integral_add_adjacent_intervals (h_int 0 ε) (h_int _ _)] rw [hg.intervalIntegral_add_zsmul_eq ⌊t / T⌋ ε h_int, hg.intervalIntegral_add_eq ε 0, zero_add, add_le_add_iff_right] exact (continuous_primitive h_int 0).continuousOn.sInf_image_Icc_le <| mem_Icc_of_Ico (Int.fract_div_mul_self_mem_Ico T t hT) #align function.periodic.Inf_add_zsmul_le_integral_of_pos Function.Periodic.sInf_add_zsmul_le_integral_of_pos /-- If `g : ℝ → ℝ` is periodic with period `T > 0`, then for any `t : ℝ`, the function `t ↦ ∫ x in 0..t, g x` is bounded above by `t ↦ X + ⌊t/T⌋ • Y` for appropriate constants `X` and `Y`. -/
Mathlib/MeasureTheory/Integral/Periodic.lean
335
345
theorem integral_le_sSup_add_zsmul_of_pos (hT : 0 < T) (t : ℝ) : (∫ x in (0)..t, g x) ≤ sSup ((fun t => ∫ x in (0)..t, g x) '' Icc 0 T) + ⌊t / T⌋ • ∫ x in (0)..T, g x := by
let ε := Int.fract (t / T) * T conv_lhs => rw [← Int.fract_div_mul_self_add_zsmul_eq T t (by linarith), ← integral_add_adjacent_intervals (h_int 0 ε) (h_int _ _)] rw [hg.intervalIntegral_add_zsmul_eq ⌊t / T⌋ ε h_int, hg.intervalIntegral_add_eq ε 0, zero_add, add_le_add_iff_right] exact (continuous_primitive h_int 0).continuousOn.le_sSup_image_Icc (mem_Icc_of_Ico (Int.fract_div_mul_self_mem_Ico T t hT))
/- 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 -/ import Mathlib.Analysis.Calculus.Deriv.Pow import Mathlib.Analysis.Calculus.MeanValue #align_import analysis.calculus.fderiv_symmetric from "leanprover-community/mathlib"@"2c1d8ca2812b64f88992a5294ea3dba144755cd1" /-! # Symmetry of the second derivative We show that, over the reals, the second derivative is symmetric. The most precise result is `Convex.second_derivative_within_at_symmetric`. It asserts that, if a function is differentiable inside a convex set `s` with nonempty interior, and has a second derivative within `s` at a point `x`, then this second derivative at `x` is symmetric. Note that this result does not require continuity of the first derivative. The following particular cases of this statement are especially relevant: `second_derivative_symmetric_of_eventually` asserts that, if a function is differentiable on a neighborhood of `x`, and has a second derivative at `x`, then this second derivative is symmetric. `second_derivative_symmetric` asserts that, if a function is differentiable, and has a second derivative at `x`, then this second derivative is symmetric. ## Implementation note For the proof, we obtain an asymptotic expansion to order two of `f (x + v + w) - f (x + v)`, by using the mean value inequality applied to a suitable function along the segment `[x + v, x + v + w]`. This expansion involves `f'' ⬝ w` as we move along a segment directed by `w` (see `Convex.taylor_approx_two_segment`). Consider the alternate sum `f (x + v + w) + f x - f (x + v) - f (x + w)`, corresponding to the values of `f` along a rectangle based at `x` with sides `v` and `w`. One can write it using the two sides directed by `w`, as `(f (x + v + w) - f (x + v)) - (f (x + w) - f x)`. Together with the previous asymptotic expansion, one deduces that it equals `f'' v w + o(1)` when `v, w` tends to `0`. Exchanging the roles of `v` and `w`, one instead gets an asymptotic expansion `f'' w v`, from which the equality `f'' v w = f'' w v` follows. In our most general statement, we only assume that `f` is differentiable inside a convex set `s`, so a few modifications have to be made. Since we don't assume continuity of `f` at `x`, we consider instead the rectangle based at `x + v + w` with sides `v` and `w`, in `Convex.isLittleO_alternate_sum_square`, but the argument is essentially the same. It only works when `v` and `w` both point towards the interior of `s`, to make sure that all the sides of the rectangle are contained in `s` by convexity. The general case follows by linearity, though. -/ open Asymptotics Set open scoped Topology variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] {s : Set E} (s_conv : Convex ℝ s) {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ x ∈ interior s, HasFDerivAt f (f' x) x) {x : E} (xs : x ∈ s) (hx : HasFDerivWithinAt f' f'' (interior s) x) /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one can Taylor-expand to order two the function `f` on the segment `[x + h v, x + h (v + w)]`, giving a bilinear estimate for `f (x + hv + hw) - f (x + hv)` in terms of `f' w` and of `f'' ⬝ w`, up to `o(h^2)`. This is a technical statement used to show that the second derivative is symmetric. -/ theorem Convex.taylor_approx_two_segment {v w : E} (hv : x + v ∈ interior s) (hw : x + v + w ∈ interior s) : (fun h : ℝ => f (x + h • v + h • w) - f (x + h • v) - h • f' x w - h ^ 2 • f'' v w - (h ^ 2 / 2) • f'' w w) =o[𝓝[>] 0] fun h => h ^ 2 := by -- it suffices to check that the expression is bounded by `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2` for -- small enough `h`, for any positive `ε`. refine IsLittleO.trans_isBigO (isLittleO_iff.2 fun ε εpos => ?_) (isBigO_const_mul_self ((‖v‖ + ‖w‖) * ‖w‖) _ _) -- consider a ball of radius `δ` around `x` in which the Taylor approximation for `f''` is -- good up to `δ`. rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff] at hx rcases Metric.mem_nhdsWithin_iff.1 (hx εpos) with ⟨δ, δpos, sδ⟩ have E1 : ∀ᶠ h in 𝓝[>] (0 : ℝ), h * (‖v‖ + ‖w‖) < δ := by have : Filter.Tendsto (fun h => h * (‖v‖ + ‖w‖)) (𝓝[>] (0 : ℝ)) (𝓝 (0 * (‖v‖ + ‖w‖))) := (continuous_id.mul continuous_const).continuousWithinAt apply (tendsto_order.1 this).2 δ simpa only [zero_mul] using δpos have E2 : ∀ᶠ h in 𝓝[>] (0 : ℝ), (h : ℝ) < 1 := mem_nhdsWithin_Ioi_iff_exists_Ioo_subset.2 ⟨(1 : ℝ), by simp only [mem_Ioi, zero_lt_one], fun x hx => hx.2⟩ filter_upwards [E1, E2, self_mem_nhdsWithin] with h hδ h_lt_1 hpos -- we consider `h` small enough that all points under consideration belong to this ball, -- and also with `0 < h < 1`. replace hpos : 0 < h := hpos have xt_mem : ∀ t ∈ Icc (0 : ℝ) 1, x + h • v + (t * h) • w ∈ interior s := by intro t ht have : x + h • v ∈ interior s := s_conv.add_smul_mem_interior xs hv ⟨hpos, h_lt_1.le⟩ rw [← smul_smul] apply s_conv.interior.add_smul_mem this _ ht rw [add_assoc] at hw rw [add_assoc, ← smul_add] exact s_conv.add_smul_mem_interior xs hw ⟨hpos, h_lt_1.le⟩ -- define a function `g` on `[0,1]` (identified with `[v, v + w]`) such that `g 1 - g 0` is the -- quantity to be estimated. We will check that its derivative is given by an explicit -- expression `g'`, that we can bound. Then the desired bound for `g 1 - g 0` follows from the -- mean value inequality. let g t := f (x + h • v + (t * h) • w) - (t * h) • f' x w - (t * h ^ 2) • f'' v w - ((t * h) ^ 2 / 2) • f'' w w set g' := fun t => f' (x + h • v + (t * h) • w) (h • w) - h • f' x w - h ^ 2 • f'' v w - (t * h ^ 2) • f'' w w with hg' -- check that `g'` is the derivative of `g`, by a straightforward computation have g_deriv : ∀ t ∈ Icc (0 : ℝ) 1, HasDerivWithinAt g (g' t) (Icc 0 1) t := by intro t ht apply_rules [HasDerivWithinAt.sub, HasDerivWithinAt.add] · refine (hf _ ?_).comp_hasDerivWithinAt _ ?_ · exact xt_mem t ht apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.const_add, HasDerivAt.smul_const, hasDerivAt_mul_const] · apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_mul_const] · apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_mul_const] · suffices H : HasDerivWithinAt (fun u => ((u * h) ^ 2 / 2) • f'' w w) ((((2 : ℕ) : ℝ) * (t * h) ^ (2 - 1) * (1 * h) / 2) • f'' w w) (Icc 0 1) t by convert H using 2 ring apply_rules [HasDerivAt.hasDerivWithinAt, HasDerivAt.smul_const, hasDerivAt_id', HasDerivAt.pow, HasDerivAt.mul_const] -- check that `g'` is uniformly bounded, with a suitable bound `ε * ((‖v‖ + ‖w‖) * ‖w‖) * h^2`. have g'_bound : ∀ t ∈ Ico (0 : ℝ) 1, ‖g' t‖ ≤ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by intro t ht have I : ‖h • v + (t * h) • w‖ ≤ h * (‖v‖ + ‖w‖) := calc ‖h • v + (t * h) • w‖ ≤ ‖h • v‖ + ‖(t * h) • w‖ := norm_add_le _ _ _ = h * ‖v‖ + t * (h * ‖w‖) := by simp only [norm_smul, Real.norm_eq_abs, hpos.le, abs_of_nonneg, abs_mul, ht.left, mul_assoc] _ ≤ h * ‖v‖ + 1 * (h * ‖w‖) := by gcongr; exact ht.2.le _ = h * (‖v‖ + ‖w‖) := by ring calc ‖g' t‖ = ‖(f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)) (h • w)‖ := by rw [hg'] have : h * (t * h) = t * (h * h) := by ring simp only [ContinuousLinearMap.coe_sub', ContinuousLinearMap.map_add, pow_two, ContinuousLinearMap.add_apply, Pi.smul_apply, smul_sub, smul_add, smul_smul, ← sub_sub, ContinuousLinearMap.coe_smul', Pi.sub_apply, ContinuousLinearMap.map_smul, this] _ ≤ ‖f' (x + h • v + (t * h) • w) - f' x - f'' (h • v + (t * h) • w)‖ * ‖h • w‖ := (ContinuousLinearMap.le_opNorm _ _) _ ≤ ε * ‖h • v + (t * h) • w‖ * ‖h • w‖ := by apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) have H : x + h • v + (t * h) • w ∈ Metric.ball x δ ∩ interior s := by refine ⟨?_, xt_mem t ⟨ht.1, ht.2.le⟩⟩ rw [add_assoc, add_mem_ball_iff_norm] exact I.trans_lt hδ simpa only [mem_setOf_eq, add_assoc x, add_sub_cancel_left] using sδ H _ ≤ ε * (‖h • v‖ + ‖h • w‖) * ‖h • w‖ := by gcongr apply (norm_add_le _ _).trans gcongr simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, ht.1, hpos.le, mul_assoc] exact mul_le_of_le_one_left (mul_nonneg hpos.le (norm_nonneg _)) ht.2.le _ = ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by simp only [norm_smul, Real.norm_eq_abs, abs_mul, abs_of_nonneg, hpos.le]; ring -- conclude using the mean value inequality have I : ‖g 1 - g 0‖ ≤ ε * ((‖v‖ + ‖w‖) * ‖w‖) * h ^ 2 := by simpa only [mul_one, sub_zero] using norm_image_sub_le_of_norm_deriv_le_segment' g_deriv g'_bound 1 (right_mem_Icc.2 zero_le_one) convert I using 1 · congr 1 simp only [g, Nat.one_ne_zero, add_zero, one_mul, zero_div, zero_mul, sub_zero, zero_smul, Ne, not_false_iff, bit0_eq_zero, zero_pow] abel · simp only [Real.norm_eq_abs, abs_mul, add_nonneg (norm_nonneg v) (norm_nonneg w), abs_of_nonneg, hpos.le, mul_assoc, norm_nonneg, abs_pow] #align convex.taylor_approx_two_segment Convex.taylor_approx_two_segment /-- One can get `f'' v w` as the limit of `h ^ (-2)` times the alternate sum of the values of `f` along the vertices of a quadrilateral with sides `h v` and `h w` based at `x`. In a setting where `f` is not guaranteed to be continuous at `f`, we can still get this if we use a quadrilateral based at `h v + h w`. -/ theorem Convex.isLittleO_alternate_sum_square {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : (fun h : ℝ => f (x + h • (2 • v + 2 • w)) + f (x + h • (v + w)) - f (x + h • (2 • v + w)) - f (x + h • (v + 2 • w)) - h ^ 2 • f'' v w) =o[𝓝[>] 0] fun h => h ^ 2 := by have A : (1 : ℝ) / 2 ∈ Ioc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩ have B : (1 : ℝ) / 2 ∈ Icc (0 : ℝ) 1 := ⟨by norm_num, by norm_num⟩ have C : ∀ w : E, (2 : ℝ) • w = 2 • w := fun w => by simp only [two_smul] have h2v2w : x + (2 : ℝ) • v + (2 : ℝ) • w ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h4v h4w B using 1 simp only [smul_sub, smul_smul, one_div, add_sub_add_left_eq_sub, mul_add, add_smul] norm_num simp only [show (4 : ℝ) = (2 : ℝ) + (2 : ℝ) by norm_num, _root_.add_smul] abel have h2vww : x + (2 • v + w) + w ∈ interior s := by convert h2v2w using 1 simp only [two_smul] abel have h2v : x + (2 : ℝ) • v ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h4v A using 1 simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj] norm_num have h2w : x + (2 : ℝ) • w ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h4w A using 1 simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj] norm_num have hvw : x + (v + w) ∈ interior s := by convert s_conv.add_smul_sub_mem_interior xs h2v2w A using 1 simp only [smul_smul, one_div, add_sub_cancel_left, add_right_inj, smul_add, smul_sub] norm_num abel have h2vw : x + (2 • v + w) ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h2v h2v2w B using 1 simp only [smul_add, smul_sub, smul_smul, ← C] norm_num abel have hvww : x + (v + w) + w ∈ interior s := by convert s_conv.interior.add_smul_sub_mem h2w h2v2w B using 1 rw [one_div, add_sub_add_right_eq_sub, add_sub_cancel_left, inv_smul_smul₀ two_ne_zero, two_smul] abel have TA1 := s_conv.taylor_approx_two_segment hf xs hx h2vw h2vww have TA2 := s_conv.taylor_approx_two_segment hf xs hx hvw hvww convert TA1.sub TA2 using 1 ext h simp only [two_smul, smul_add, ← add_assoc, ContinuousLinearMap.map_add, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', ContinuousLinearMap.map_smul] abel #align convex.is_o_alternate_sum_square Convex.isLittleO_alternate_sum_square /-- Assume that `f` is differentiable inside a convex set `s`, and that its derivative `f'` is differentiable at a point `x`. Then, given two vectors `v` and `w` pointing inside `s`, one has `f'' v w = f'' w v`. Superseded by `Convex.second_derivative_within_at_symmetric`, which removes the assumption that `v` and `w` point inside `s`. -/ theorem Convex.second_derivative_within_at_symmetric_of_mem_interior {v w : E} (h4v : x + (4 : ℝ) • v ∈ interior s) (h4w : x + (4 : ℝ) • w ∈ interior s) : f'' w v = f'' v w := by have A : (fun h : ℝ => h ^ 2 • (f'' w v - f'' v w)) =o[𝓝[>] 0] fun h => h ^ 2 := by convert (s_conv.isLittleO_alternate_sum_square hf xs hx h4v h4w).sub (s_conv.isLittleO_alternate_sum_square hf xs hx h4w h4v) using 1 ext h simp only [add_comm, smul_add, smul_sub] abel have B : (fun _ : ℝ => f'' w v - f'' v w) =o[𝓝[>] 0] fun _ => (1 : ℝ) := by have : (fun h : ℝ => 1 / h ^ 2) =O[𝓝[>] 0] fun h => 1 / h ^ 2 := isBigO_refl _ _ have C := this.smul_isLittleO A apply C.congr' _ _ · filter_upwards [self_mem_nhdsWithin] intro h (hpos : 0 < h) rw [← one_smul ℝ (f'' w v - f'' v w), smul_smul, smul_smul] congr 1 field_simp [LT.lt.ne' hpos] · filter_upwards [self_mem_nhdsWithin] with h (hpos : 0 < h) field_simp [LT.lt.ne' hpos, SMul.smul] simpa only [sub_eq_zero] using isLittleO_const_const_iff.1 B #align convex.second_derivative_within_at_symmetric_of_mem_interior Convex.second_derivative_within_at_symmetric_of_mem_interior /-- If a function is differentiable inside a convex set with nonempty interior, and has a second derivative at a point of this convex set, then this second derivative is symmetric. -/
Mathlib/Analysis/Calculus/FDeriv/Symmetric.lean
259
304
theorem Convex.second_derivative_within_at_symmetric {s : Set E} (s_conv : Convex ℝ s) (hne : (interior s).Nonempty) {f : E → F} {f' : E → E →L[ℝ] F} {f'' : E →L[ℝ] E →L[ℝ] F} (hf : ∀ x ∈ interior s, HasFDerivAt f (f' x) x) {x : E} (xs : x ∈ s) (hx : HasFDerivWithinAt f' f'' (interior s) x) (v w : E) : f'' v w = f'' w v := by
/- we work around a point `x + 4 z` in the interior of `s`. For any vector `m`, then `x + 4 (z + t m)` also belongs to the interior of `s` for small enough `t`. This means that we will be able to apply `second_derivative_within_at_symmetric_of_mem_interior` to show that `f''` is symmetric, after cancelling all the contributions due to `z`. -/ rcases hne with ⟨y, hy⟩ obtain ⟨z, hz⟩ : ∃ z, z = ((1 : ℝ) / 4) • (y - x) := ⟨((1 : ℝ) / 4) • (y - x), rfl⟩ have A : ∀ m : E, Filter.Tendsto (fun t : ℝ => x + (4 : ℝ) • (z + t • m)) (𝓝 0) (𝓝 y) := by intro m have : x + (4 : ℝ) • (z + (0 : ℝ) • m) = y := by simp [hz] rw [← this] refine tendsto_const_nhds.add <| tendsto_const_nhds.smul <| tendsto_const_nhds.add ?_ exact continuousAt_id.smul continuousAt_const have B : ∀ m : E, ∀ᶠ t in 𝓝[>] (0 : ℝ), x + (4 : ℝ) • (z + t • m) ∈ interior s := by intro m apply nhdsWithin_le_nhds apply A m rw [mem_interior_iff_mem_nhds] at hy exact interior_mem_nhds.2 hy -- we choose `t m > 0` such that `x + 4 (z + (t m) m)` belongs to the interior of `s`, for any -- vector `m`. choose t ts tpos using fun m => ((B m).and self_mem_nhdsWithin).exists -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z` -- and `z + (t m) m`, we deduce that `f'' m z = f'' z m` for all `m`. have C : ∀ m : E, f'' m z = f'' z m := by intro m have : f'' (z + t m • m) (z + t 0 • (0 : E)) = f'' (z + t 0 • (0 : E)) (z + t m • m) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts 0) (ts m) simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, add_right_inj, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', add_zero, ContinuousLinearMap.zero_apply, smul_zero, ContinuousLinearMap.map_zero] at this exact smul_right_injective F (tpos m).ne' this -- applying `second_derivative_within_at_symmetric_of_mem_interior` to the vectors `z + (t v) v` -- and `z + (t w) w`, we deduce that `f'' v w = f'' w v`. Cross terms involving `z` can be -- eliminated thanks to the fact proved above that `f'' m z = f'' z m`. have : f'' (z + t v • v) (z + t w • w) = f'' (z + t w • w) (z + t v • v) := s_conv.second_derivative_within_at_symmetric_of_mem_interior hf xs hx (ts w) (ts v) simp only [ContinuousLinearMap.map_add, ContinuousLinearMap.map_smul, smul_add, smul_smul, ContinuousLinearMap.add_apply, Pi.smul_apply, ContinuousLinearMap.coe_smul', C] at this rw [add_assoc, add_assoc, add_right_inj, add_left_comm, add_right_inj, add_right_inj, mul_comm] at this apply smul_right_injective F _ this simp [(tpos v).ne', (tpos w).ne']
/- Copyright (c) 2023 François G. Dorais. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: François G. Dorais -/ import Batteries.Data.Array.Lemmas namespace ByteArray @[ext] theorem ext : {a b : ByteArray} → a.data = b.data → a = b | ⟨_⟩, ⟨_⟩, rfl => rfl theorem getElem_eq_data_getElem (a : ByteArray) (h : i < a.size) : a[i] = a.data[i] := rfl /-! ### uget/uset -/ @[simp] theorem uset_eq_set (a : ByteArray) {i : USize} (h : i.toNat < a.size) (v : UInt8) : a.uset i v h = a.set ⟨i.toNat, h⟩ v := rfl /-! ### empty -/ @[simp] theorem mkEmpty_data (cap) : (mkEmpty cap).data = #[] := rfl @[simp] theorem empty_data : empty.data = #[] := rfl @[simp] theorem size_empty : empty.size = 0 := rfl /-! ### push -/ @[simp] theorem push_data (a : ByteArray) (b : UInt8) : (a.push b).data = a.data.push b := rfl @[simp] theorem size_push (a : ByteArray) (b : UInt8) : (a.push b).size = a.size + 1 := Array.size_push .. @[simp] theorem get_push_eq (a : ByteArray) (x : UInt8) : (a.push x)[a.size] = x := Array.get_push_eq .. theorem get_push_lt (a : ByteArray) (x : UInt8) (i : Nat) (h : i < a.size) : (a.push x)[i]'(size_push .. ▸ Nat.lt_succ_of_lt h) = a[i] := Array.get_push_lt .. /-! ### set -/ @[simp] theorem set_data (a : ByteArray) (i : Fin a.size) (v : UInt8) : (a.set i v).data = a.data.set i v := rfl @[simp] theorem size_set (a : ByteArray) (i : Fin a.size) (v : UInt8) : (a.set i v).size = a.size := Array.size_set .. @[simp] theorem get_set_eq (a : ByteArray) (i : Fin a.size) (v : UInt8) : (a.set i v)[i.val] = v := Array.get_set_eq .. theorem get_set_ne (a : ByteArray) (i : Fin a.size) (v : UInt8) (hj : j < a.size) (h : i.val ≠ j) : (a.set i v)[j]'(a.size_set .. ▸ hj) = a[j] := Array.get_set_ne (h:=h) .. theorem set_set (a : ByteArray) (i : Fin a.size) (v v' : UInt8) : (a.set i v).set ⟨i, by simp [i.2]⟩ v' = a.set i v' := ByteArray.ext <| Array.set_set .. /-! ### copySlice -/ @[simp] theorem copySlice_data (a i b j len exact) : (copySlice a i b j len exact).data = b.data.extract 0 j ++ a.data.extract i (i + len) ++ b.data.extract (j + min len (a.data.size - i)) b.data.size := rfl /-! ### append -/ @[simp] theorem append_eq (a b) : ByteArray.append a b = a ++ b := rfl @[simp] theorem append_data (a b : ByteArray) : (a ++ b).data = a.data ++ b.data := by rw [←append_eq]; simp [ByteArray.append, size] rw [Array.extract_empty_of_stop_le_start (h:=Nat.le_add_right ..), Array.append_nil] theorem size_append (a b : ByteArray) : (a ++ b).size = a.size + b.size := by simp only [size, append_eq, append_data]; exact Array.size_append ..
.lake/packages/batteries/Batteries/Data/ByteArray.lean
79
82
theorem get_append_left {a b : ByteArray} (hlt : i < a.size) (h : i < (a ++ b).size := size_append .. ▸ Nat.lt_of_lt_of_le hlt (Nat.le_add_right ..)) : (a ++ b)[i] = a[i] := by
simp [getElem_eq_data_getElem]; exact Array.get_append_left hlt
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Probability.IdentDistrib import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.Analysis.SpecificLimits.FloorPow import Mathlib.Analysis.PSeries import Mathlib.Analysis.Asymptotics.SpecificAsymptotics #align_import probability.strong_law from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # The strong law of large numbers We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`: If `X n` is a sequence of independent identically distributed integrable random variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. This file also contains the Lᵖ version of the strong law of large numbers provided by `ProbabilityTheory.strong_law_Lp` which shows `∑ i ∈ range n, X i / n` converges in Lᵖ to `𝔼[X 0]` provided `X n` is independent identically distributed and is Lᵖ. ## Implementation The main point is to prove the result for real-valued random variables, as the general case of Banach-space valued random variables follows from this case and approximation by simple functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`. We follow the proof by Etemadi [Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law], which goes as follows. It suffices to prove the result for nonnegative `X`, as one can prove the general result by splitting a general `X` into its positive part and negative part. Consider `Xₙ` a sequence of nonnegative integrable identically distributed pairwise independent random variables. Let `Yₙ` be the truncation of `Xₙ` up to `n`. We claim that * Almost surely, `Xₙ = Yₙ` for all but finitely many indices. Indeed, `∑ ℙ (Xₙ ≠ Yₙ)` is bounded by `1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`). * Let `c > 1`. Along the sequence `n = c ^ k`, then `(∑_{i=0}^{n-1} Yᵢ - 𝔼[Yᵢ])/n` converges almost surely to `0`. This follows from a variance control, as ``` ∑_k ℙ (|∑_{i=0}^{c^k - 1} Yᵢ - 𝔼[Yᵢ]| > c^k ε) ≤ ∑_k (c^k ε)^{-2} ∑_{i=0}^{c^k - 1} Var[Yᵢ] (by Markov inequality) ≤ ∑_i (C/i^2) Var[Yᵢ] (as ∑_{c^k > i} 1/(c^k)^2 ≤ C/i^2) ≤ ∑_i (C/i^2) 𝔼[Yᵢ^2] ≤ 2C 𝔼[X^2] (see `sum_variance_truncation_le`) ``` * As `𝔼[Yᵢ]` converges to `𝔼[X]`, it follows from the two previous items and Cesàro that, along the sequence `n = c^k`, one has `(∑_{i=0}^{n-1} Xᵢ) / n → 𝔼[X]` almost surely. * To generalize it to all indices, we use the fact that `∑_{i=0}^{n-1} Xᵢ` is nondecreasing and that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small. -/ noncomputable section open MeasureTheory Filter Finset Asymptotics open Set (indicator) open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal namespace ProbabilityTheory /-! ### Prerequisites on truncations -/ section Truncation variable {α : Type*} /-- Truncating a real-valued function to the interval `(-A, A]`. -/ def truncation (f : α → ℝ) (A : ℝ) := indicator (Set.Ioc (-A) A) id ∘ f #align probability_theory.truncation ProbabilityTheory.truncation variable {m : MeasurableSpace α} {μ : Measure α} {f : α → ℝ} theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f μ) {A : ℝ} : AEStronglyMeasurable (truncation f A) μ := by apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable #align measure_theory.ae_strongly_measurable.truncation MeasureTheory.AEStronglyMeasurable.truncation theorem abs_truncation_le_bound (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |A| := by simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs with h · exact abs_le_abs h.2 (neg_le.2 h.1.le) · simp [abs_nonneg] #align probability_theory.abs_truncation_le_bound ProbabilityTheory.abs_truncation_le_bound @[simp] theorem truncation_zero (f : α → ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl #align probability_theory.truncation_zero ProbabilityTheory.truncation_zero theorem abs_truncation_le_abs_self (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |f x| := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs · exact le_rfl · simp [abs_nonneg] #align probability_theory.abs_truncation_le_abs_self ProbabilityTheory.abs_truncation_le_abs_self theorem truncation_eq_self {f : α → ℝ} {A : ℝ} {x : α} (h : |f x| < A) : truncation f A x = f x := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff] intro H apply H.elim simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le] #align probability_theory.truncation_eq_self ProbabilityTheory.truncation_eq_self theorem truncation_eq_of_nonneg {f : α → ℝ} {A : ℝ} (h : ∀ x, 0 ≤ f x) : truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by ext x rcases (h x).lt_or_eq with (hx | hx) · simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply, true_and_iff] by_cases h'x : f x ≤ A · have : -A < f x := by linarith [h x] simp only [this, true_and_iff] · simp only [h'x, and_false_iff] · simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self] #align probability_theory.truncation_eq_of_nonneg ProbabilityTheory.truncation_eq_of_nonneg theorem truncation_nonneg {f : α → ℝ} (A : ℝ) {x : α} (h : 0 ≤ f x) : 0 ≤ truncation f A x := Set.indicator_apply_nonneg fun _ => h #align probability_theory.truncation_nonneg ProbabilityTheory.truncation_nonneg theorem _root_.MeasureTheory.AEStronglyMeasurable.memℒp_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} {p : ℝ≥0∞} : Memℒp (truncation f A) p μ := Memℒp.of_bound hf.truncation |A| (eventually_of_forall fun _ => abs_truncation_le_bound _ _ _) #align measure_theory.ae_strongly_measurable.mem_ℒp_truncation MeasureTheory.AEStronglyMeasurable.memℒp_truncation theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} : Integrable (truncation f A) μ := by rw [← memℒp_one_iff_integrable]; exact hf.memℒp_truncation #align measure_theory.ae_strongly_measurable.integrable_truncation MeasureTheory.AEStronglyMeasurable.integrable_truncation theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) {n : ℕ} (hn : n ≠ 0) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in -A..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) ∂μ = _ rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · linarith · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable #align probability_theory.moment_truncation_eq_interval_integral ProbabilityTheory.moment_truncation_eq_intervalIntegral theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} {n : ℕ} (hn : n ≠ 0) (h'f : 0 ≤ f) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in (0)..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc rw [truncation_eq_of_nonneg h'f] change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) ∂μ = _ rcases le_or_lt 0 A with (hA | hA) · rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le hA, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable · rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_ge hA.le, ← integral_indicator M'] · simp only [Set.Ioc_eq_empty_of_le hA.le, zero_pow hn, Set.indicator_empty, integral_zero, zero_eq_neg] apply integral_eq_zero_of_ae have : ∀ᵐ x ∂Measure.map f μ, (0 : ℝ) ≤ x := (ae_map_iff hf.aemeasurable measurableSet_Ici).2 (eventually_of_forall h'f) filter_upwards [this] with x hx simp only [indicator, Set.mem_Ioc, Pi.zero_apply, ite_eq_right_iff, and_imp] intro _ h''x have : x = 0 := by linarith simp [this, zero_pow hn] · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable #align probability_theory.moment_truncation_eq_interval_integral_of_nonneg ProbabilityTheory.moment_truncation_eq_intervalIntegral_of_nonneg theorem integral_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) : ∫ x, truncation f A x ∂μ = ∫ y in -A..A, y ∂Measure.map f μ := by simpa using moment_truncation_eq_intervalIntegral hf hA one_ne_zero #align probability_theory.integral_truncation_eq_interval_integral ProbabilityTheory.integral_truncation_eq_intervalIntegral theorem integral_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} (h'f : 0 ≤ f) : ∫ x, truncation f A x ∂μ = ∫ y in (0)..A, y ∂Measure.map f μ := by simpa using moment_truncation_eq_intervalIntegral_of_nonneg hf one_ne_zero h'f #align probability_theory.integral_truncation_eq_interval_integral_of_nonneg ProbabilityTheory.integral_truncation_eq_intervalIntegral_of_nonneg theorem integral_truncation_le_integral_of_nonneg (hf : Integrable f μ) (h'f : 0 ≤ f) {A : ℝ} : ∫ x, truncation f A x ∂μ ≤ ∫ x, f x ∂μ := by apply integral_mono_of_nonneg (eventually_of_forall fun x => ?_) hf (eventually_of_forall fun x => ?_) · exact truncation_nonneg _ (h'f x) · calc truncation f A x ≤ |truncation f A x| := le_abs_self _ _ ≤ |f x| := abs_truncation_le_abs_self _ _ _ _ = f x := abs_of_nonneg (h'f x) #align probability_theory.integral_truncation_le_integral_of_nonneg ProbabilityTheory.integral_truncation_le_integral_of_nonneg /-- If a function is integrable, then the integral of its truncated versions converges to the integral of the whole function. -/ theorem tendsto_integral_truncation {f : α → ℝ} (hf : Integrable f μ) : Tendsto (fun A => ∫ x, truncation f A x ∂μ) atTop (𝓝 (∫ x, f x ∂μ)) := by refine tendsto_integral_filter_of_dominated_convergence (fun x => abs (f x)) ?_ ?_ ?_ ?_ · exact eventually_of_forall fun A ↦ hf.aestronglyMeasurable.truncation · filter_upwards with A filter_upwards with x rw [Real.norm_eq_abs] exact abs_truncation_le_abs_self _ _ _ · exact hf.abs · filter_upwards with x apply tendsto_const_nhds.congr' _ filter_upwards [Ioi_mem_atTop (abs (f x))] with A hA exact (truncation_eq_self hA).symm #align probability_theory.tendsto_integral_truncation ProbabilityTheory.tendsto_integral_truncation theorem IdentDistrib.truncation {β : Type*} [MeasurableSpace β] {ν : Measure β} {f : α → ℝ} {g : β → ℝ} (h : IdentDistrib f g μ ν) {A : ℝ} : IdentDistrib (truncation f A) (truncation g A) μ ν := h.comp (measurable_id.indicator measurableSet_Ioc) #align probability_theory.ident_distrib.truncation ProbabilityTheory.IdentDistrib.truncation end Truncation section StrongLawAeReal variable {Ω : Type*} [MeasureSpace Ω] [IsProbabilityMeasure (ℙ : Measure Ω)] section MomentEstimates theorem sum_prob_mem_Ioc_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) {K : ℕ} {N : ℕ} (hKN : K ≤ N) : ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} ≤ ENNReal.ofReal (𝔼[X] + 1) := by let ρ : Measure ℝ := Measure.map X ℙ haveI : IsProbabilityMeasure ρ := isProbabilityMeasure_map hint.aemeasurable have A : ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ ≤ 𝔼[X] + 1 := calc ∑ j ∈ range K, ∫ _ in j..N, (1 : ℝ) ∂ρ = ∑ j ∈ range K, ∑ i ∈ Ico j N, ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by apply sum_congr rfl fun j hj => ?_ rw [intervalIntegral.sum_integral_adjacent_intervals_Ico ((mem_range.1 hj).le.trans hKN)] intro k _ exact continuous_const.intervalIntegrable _ _ _ = ∑ i ∈ range N, ∑ j ∈ range (min (i + 1) K), ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by simp_rw [sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add simp Nat.lt_succ_iff) _ ≤ ∑ i ∈ range N, (i + 1) * ∫ _ in i..(i + 1 : ℕ), (1 : ℝ) ∂ρ := by apply sum_le_sum fun i _ => ?_ simp only [Nat.cast_add, Nat.cast_one, sum_const, card_range, nsmul_eq_mul, Nat.cast_min] refine mul_le_mul_of_nonneg_right (min_le_left _ _) ?_ apply intervalIntegral.integral_nonneg · simp only [le_add_iff_nonneg_right, zero_le_one] · simp only [zero_le_one, imp_true_iff] _ ≤ ∑ i ∈ range N, ∫ x in i..(i + 1 : ℕ), x + 1 ∂ρ := by apply sum_le_sum fun i _ => ?_ have I : (i : ℝ) ≤ (i + 1 : ℕ) := by simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] simp_rw [intervalIntegral.integral_of_le I, ← integral_mul_left] apply setIntegral_mono_on · exact continuous_const.integrableOn_Ioc · exact (continuous_id.add continuous_const).integrableOn_Ioc · exact measurableSet_Ioc · intro x hx simp only [Nat.cast_add, Nat.cast_one, Set.mem_Ioc] at hx simp [hx.1.le] _ = ∫ x in (0)..N, x + 1 ∂ρ := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] · norm_cast · exact (continuous_id.add continuous_const).intervalIntegrable _ _ _ = ∫ x in (0)..N, x ∂ρ + ∫ x in (0)..N, 1 ∂ρ := by rw [intervalIntegral.integral_add] · exact continuous_id.intervalIntegrable _ _ · exact continuous_const.intervalIntegrable _ _ _ = 𝔼[truncation X N] + ∫ x in (0)..N, 1 ∂ρ := by rw [integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] _ ≤ 𝔼[X] + ∫ x in (0)..N, 1 ∂ρ := (add_le_add_right (integral_truncation_le_integral_of_nonneg hint hnonneg) _) _ ≤ 𝔼[X] + 1 := by refine add_le_add le_rfl ?_ rw [intervalIntegral.integral_of_le (Nat.cast_nonneg _)] simp only [integral_const, Measure.restrict_apply', measurableSet_Ioc, Set.univ_inter, Algebra.id.smul_eq_mul, mul_one] rw [← ENNReal.one_toReal] exact ENNReal.toReal_mono ENNReal.one_ne_top prob_le_one have B : ∀ a b, ℙ {ω | X ω ∈ Set.Ioc a b} = ENNReal.ofReal (∫ _ in Set.Ioc a b, (1 : ℝ) ∂ρ) := by intro a b rw [ofReal_setIntegral_one ρ _, Measure.map_apply_of_aemeasurable hint.aemeasurable measurableSet_Ioc] rfl calc ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N} = ∑ j ∈ range K, ENNReal.ofReal (∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by simp_rw [B] _ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in Set.Ioc (j : ℝ) N, (1 : ℝ) ∂ρ) := by rw [ENNReal.ofReal_sum_of_nonneg] simp only [integral_const, Algebra.id.smul_eq_mul, mul_one, ENNReal.toReal_nonneg, imp_true_iff] _ = ENNReal.ofReal (∑ j ∈ range K, ∫ _ in (j : ℝ)..N, (1 : ℝ) ∂ρ) := by congr 1 refine sum_congr rfl fun j hj => ?_ rw [intervalIntegral.integral_of_le (Nat.cast_le.2 ((mem_range.1 hj).le.trans hKN))] _ ≤ ENNReal.ofReal (𝔼[X] + 1) := ENNReal.ofReal_le_ofReal A #align probability_theory.sum_prob_mem_Ioc_le ProbabilityTheory.sum_prob_mem_Ioc_le theorem tsum_prob_mem_Ioi_lt_top {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) : (∑' j : ℕ, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)}) < ∞ := by suffices ∀ K : ℕ, ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)} ≤ ENNReal.ofReal (𝔼[X] + 1) from (le_of_tendsto_of_tendsto (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds (eventually_of_forall this)).trans_lt ENNReal.ofReal_lt_top intro K have A : Tendsto (fun N : ℕ => ∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioc (j : ℝ) N}) atTop (𝓝 (∑ j ∈ range K, ℙ {ω | X ω ∈ Set.Ioi (j : ℝ)})) := by refine tendsto_finset_sum _ fun i _ => ?_ have : {ω | X ω ∈ Set.Ioi (i : ℝ)} = ⋃ N : ℕ, {ω | X ω ∈ Set.Ioc (i : ℝ) N} := by apply Set.Subset.antisymm _ _ · intro ω hω obtain ⟨N, hN⟩ : ∃ N : ℕ, X ω ≤ N := exists_nat_ge (X ω) exact Set.mem_iUnion.2 ⟨N, hω, hN⟩ · simp (config := {contextual := true}) only [Set.mem_Ioc, Set.mem_Ioi, Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff] rw [this] apply tendsto_measure_iUnion intro m n hmn x hx exact ⟨hx.1, hx.2.trans (Nat.cast_le.2 hmn)⟩ apply le_of_tendsto_of_tendsto A tendsto_const_nhds filter_upwards [Ici_mem_atTop K] with N hN exact sum_prob_mem_Ioc_le hint hnonneg hN #align probability_theory.tsum_prob_mem_Ioi_lt_top ProbabilityTheory.tsum_prob_mem_Ioi_lt_top
Mathlib/Probability/StrongLaw.lean
329
383
theorem sum_variance_truncation_le {X : Ω → ℝ} (hint : Integrable X) (hnonneg : 0 ≤ X) (K : ℕ) : ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation X j ^ 2] ≤ 2 * 𝔼[X] := by
set Y := fun n : ℕ => truncation X n let ρ : Measure ℝ := Measure.map X ℙ have Y2 : ∀ n, 𝔼[Y n ^ 2] = ∫ x in (0)..n, x ^ 2 ∂ρ := by intro n change 𝔼[fun x => Y n x ^ 2] = _ rw [moment_truncation_eq_intervalIntegral_of_nonneg hint.1 two_ne_zero hnonneg] calc ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[Y j ^ 2] = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∫ x in (0)..j, x ^ 2 ∂ρ := by simp_rw [Y2] _ = ∑ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * ∑ k ∈ range j, ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by congr 1 with j congr 1 rw [intervalIntegral.sum_integral_adjacent_intervals] · norm_cast intro k _ exact (continuous_id.pow _).intervalIntegrable _ _ _ = ∑ k ∈ range K, (∑ j ∈ Ioo k K, ((j : ℝ) ^ 2)⁻¹) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ <;> aesop (add unsafe lt_trans) _ ≤ ∑ k ∈ range K, 2 / (k + 1 : ℝ) * ∫ x in k..(k + 1 : ℕ), x ^ 2 ∂ρ := by apply sum_le_sum fun k _ => ?_ refine mul_le_mul_of_nonneg_right (sum_Ioo_inv_sq_le _ _) ?_ refine intervalIntegral.integral_nonneg_of_forall ?_ fun u => sq_nonneg _ simp only [Nat.cast_add, Nat.cast_one, le_add_iff_nonneg_right, zero_le_one] _ ≤ ∑ k ∈ range K, ∫ x in k..(k + 1 : ℕ), 2 * x ∂ρ := by apply sum_le_sum fun k _ => ?_ have Ik : (k : ℝ) ≤ (k + 1 : ℕ) := by simp rw [← intervalIntegral.integral_const_mul, intervalIntegral.integral_of_le Ik, intervalIntegral.integral_of_le Ik] refine setIntegral_mono_on ?_ ?_ measurableSet_Ioc fun x hx => ?_ · apply Continuous.integrableOn_Ioc exact continuous_const.mul (continuous_pow 2) · apply Continuous.integrableOn_Ioc exact continuous_const.mul continuous_id' · calc ↑2 / (↑k + ↑1) * x ^ 2 = x / (k + 1) * (2 * x) := by ring _ ≤ 1 * (2 * x) := (mul_le_mul_of_nonneg_right (by convert (div_le_one _).2 hx.2 · norm_cast simp only [Nat.cast_add, Nat.cast_one] linarith only [show (0 : ℝ) ≤ k from Nat.cast_nonneg k]) (mul_nonneg zero_le_two ((Nat.cast_nonneg k).trans hx.1.le))) _ = 2 * x := by rw [one_mul] _ = 2 * ∫ x in (0 : ℝ)..K, x ∂ρ := by rw [intervalIntegral.sum_integral_adjacent_intervals fun k _ => ?_] swap; · exact (continuous_const.mul continuous_id').intervalIntegrable _ _ rw [intervalIntegral.integral_const_mul] norm_cast _ ≤ 2 * 𝔼[X] := mul_le_mul_of_nonneg_left (by rw [← integral_truncation_eq_intervalIntegral_of_nonneg hint.1 hnonneg] exact integral_truncation_le_integral_of_nonneg hint hnonneg) zero_le_two
/- Copyright (c) 2014 Robert Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Lewis, Leonardo de Moura, Mario Carneiro, Floris van Doorn -/ import Mathlib.Algebra.Field.Basic import Mathlib.Algebra.GroupWithZero.Units.Equiv import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Order.Bounds.OrderIso import Mathlib.Tactic.Positivity.Core #align_import algebra.order.field.basic from "leanprover-community/mathlib"@"84771a9f5f0bd5e5d6218811556508ddf476dcbd" /-! # Lemmas about linear ordered (semi)fields -/ open Function OrderDual variable {ι α β : Type*} section LinearOrderedSemifield variable [LinearOrderedSemifield α] {a b c d e : α} {m n : ℤ} /-- `Equiv.mulLeft₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulLeft₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulLeft₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_left ha } #align order_iso.mul_left₀ OrderIso.mulLeft₀ #align order_iso.mul_left₀_symm_apply OrderIso.mulLeft₀_symm_apply #align order_iso.mul_left₀_apply OrderIso.mulLeft₀_apply /-- `Equiv.mulRight₀` as an order_iso. -/ @[simps! (config := { simpRhs := true })] def OrderIso.mulRight₀ (a : α) (ha : 0 < a) : α ≃o α := { Equiv.mulRight₀ a ha.ne' with map_rel_iff' := @fun _ _ => mul_le_mul_right ha } #align order_iso.mul_right₀ OrderIso.mulRight₀ #align order_iso.mul_right₀_symm_apply OrderIso.mulRight₀_symm_apply #align order_iso.mul_right₀_apply OrderIso.mulRight₀_apply /-! ### Relating one division with another term. -/ theorem le_div_iff (hc : 0 < c) : a ≤ b / c ↔ a * c ≤ b := ⟨fun h => div_mul_cancel₀ b (ne_of_lt hc).symm ▸ mul_le_mul_of_nonneg_right h hc.le, fun h => calc a = a * c * (1 / c) := mul_mul_div a (ne_of_lt hc).symm _ ≤ b * (1 / c) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hc).le _ = b / c := (div_eq_mul_one_div b c).symm ⟩ #align le_div_iff le_div_iff theorem le_div_iff' (hc : 0 < c) : a ≤ b / c ↔ c * a ≤ b := by rw [mul_comm, le_div_iff hc] #align le_div_iff' le_div_iff' theorem div_le_iff (hb : 0 < b) : a / b ≤ c ↔ a ≤ c * b := ⟨fun h => calc a = a / b * b := by rw [div_mul_cancel₀ _ (ne_of_lt hb).symm] _ ≤ c * b := mul_le_mul_of_nonneg_right h hb.le , fun h => calc a / b = a * (1 / b) := div_eq_mul_one_div a b _ ≤ c * b * (1 / b) := mul_le_mul_of_nonneg_right h (one_div_pos.2 hb).le _ = c * b / b := (div_eq_mul_one_div (c * b) b).symm _ = c := by refine (div_eq_iff (ne_of_gt hb)).mpr rfl ⟩ #align div_le_iff div_le_iff theorem div_le_iff' (hb : 0 < b) : a / b ≤ c ↔ a ≤ b * c := by rw [mul_comm, div_le_iff hb] #align div_le_iff' div_le_iff' lemma div_le_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b ≤ c ↔ a / c ≤ b := by rw [div_le_iff hb, div_le_iff' hc] theorem lt_div_iff (hc : 0 < c) : a < b / c ↔ a * c < b := lt_iff_lt_of_le_iff_le <| div_le_iff hc #align lt_div_iff lt_div_iff theorem lt_div_iff' (hc : 0 < c) : a < b / c ↔ c * a < b := by rw [mul_comm, lt_div_iff hc] #align lt_div_iff' lt_div_iff' theorem div_lt_iff (hc : 0 < c) : b / c < a ↔ b < a * c := lt_iff_lt_of_le_iff_le (le_div_iff hc) #align div_lt_iff div_lt_iff theorem div_lt_iff' (hc : 0 < c) : b / c < a ↔ b < c * a := by rw [mul_comm, div_lt_iff hc] #align div_lt_iff' div_lt_iff' lemma div_lt_comm₀ (hb : 0 < b) (hc : 0 < c) : a / b < c ↔ a / c < b := by rw [div_lt_iff hb, div_lt_iff' hc] theorem inv_mul_le_iff (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_le_iff' h #align inv_mul_le_iff inv_mul_le_iff theorem inv_mul_le_iff' (h : 0 < b) : b⁻¹ * a ≤ c ↔ a ≤ c * b := by rw [inv_mul_le_iff h, mul_comm] #align inv_mul_le_iff' inv_mul_le_iff' theorem mul_inv_le_iff (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ b * c := by rw [mul_comm, inv_mul_le_iff h] #align mul_inv_le_iff mul_inv_le_iff theorem mul_inv_le_iff' (h : 0 < b) : a * b⁻¹ ≤ c ↔ a ≤ c * b := by rw [mul_comm, inv_mul_le_iff' h] #align mul_inv_le_iff' mul_inv_le_iff' theorem div_self_le_one (a : α) : a / a ≤ 1 := if h : a = 0 then by simp [h] else by simp [h] #align div_self_le_one div_self_le_one theorem inv_mul_lt_iff (h : 0 < b) : b⁻¹ * a < c ↔ a < b * c := by rw [inv_eq_one_div, mul_comm, ← div_eq_mul_one_div] exact div_lt_iff' h #align inv_mul_lt_iff inv_mul_lt_iff theorem inv_mul_lt_iff' (h : 0 < b) : b⁻¹ * a < c ↔ a < c * b := by rw [inv_mul_lt_iff h, mul_comm] #align inv_mul_lt_iff' inv_mul_lt_iff' theorem mul_inv_lt_iff (h : 0 < b) : a * b⁻¹ < c ↔ a < b * c := by rw [mul_comm, inv_mul_lt_iff h] #align mul_inv_lt_iff mul_inv_lt_iff theorem mul_inv_lt_iff' (h : 0 < b) : a * b⁻¹ < c ↔ a < c * b := by rw [mul_comm, inv_mul_lt_iff' h] #align mul_inv_lt_iff' mul_inv_lt_iff' theorem inv_pos_le_iff_one_le_mul (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ b * a := by rw [inv_eq_one_div] exact div_le_iff ha #align inv_pos_le_iff_one_le_mul inv_pos_le_iff_one_le_mul theorem inv_pos_le_iff_one_le_mul' (ha : 0 < a) : a⁻¹ ≤ b ↔ 1 ≤ a * b := by rw [inv_eq_one_div] exact div_le_iff' ha #align inv_pos_le_iff_one_le_mul' inv_pos_le_iff_one_le_mul' theorem inv_pos_lt_iff_one_lt_mul (ha : 0 < a) : a⁻¹ < b ↔ 1 < b * a := by rw [inv_eq_one_div] exact div_lt_iff ha #align inv_pos_lt_iff_one_lt_mul inv_pos_lt_iff_one_lt_mul theorem inv_pos_lt_iff_one_lt_mul' (ha : 0 < a) : a⁻¹ < b ↔ 1 < a * b := by rw [inv_eq_one_div] exact div_lt_iff' ha #align inv_pos_lt_iff_one_lt_mul' inv_pos_lt_iff_one_lt_mul' /-- One direction of `div_le_iff` where `b` is allowed to be `0` (but `c` must be nonnegative) -/ theorem div_le_of_nonneg_of_le_mul (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ c * b) : a / b ≤ c := by rcases eq_or_lt_of_le hb with (rfl | hb') · simp only [div_zero, hc] · rwa [div_le_iff hb'] #align div_le_of_nonneg_of_le_mul div_le_of_nonneg_of_le_mul /-- One direction of `div_le_iff` where `c` is allowed to be `0` (but `b` must be nonnegative) -/ lemma mul_le_of_nonneg_of_le_div (hb : 0 ≤ b) (hc : 0 ≤ c) (h : a ≤ b / c) : a * c ≤ b := by obtain rfl | hc := hc.eq_or_lt · simpa using hb · rwa [le_div_iff hc] at h #align mul_le_of_nonneg_of_le_div mul_le_of_nonneg_of_le_div theorem div_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a / b ≤ 1 := div_le_of_nonneg_of_le_mul hb zero_le_one <| by rwa [one_mul] #align div_le_one_of_le div_le_one_of_le lemma mul_inv_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : a * b⁻¹ ≤ 1 := by simpa only [← div_eq_mul_inv] using div_le_one_of_le h hb lemma inv_mul_le_one_of_le (h : a ≤ b) (hb : 0 ≤ b) : b⁻¹ * a ≤ 1 := by simpa only [← div_eq_inv_mul] using div_le_one_of_le h hb /-! ### Bi-implications of inequalities using inversions -/ @[gcongr] theorem inv_le_inv_of_le (ha : 0 < a) (h : a ≤ b) : b⁻¹ ≤ a⁻¹ := by rwa [← one_div a, le_div_iff' ha, ← div_eq_mul_inv, div_le_iff (ha.trans_le h), one_mul] #align inv_le_inv_of_le inv_le_inv_of_le /-- See `inv_le_inv_of_le` for the implication from right-to-left with one fewer assumption. -/ theorem inv_le_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by rw [← one_div, div_le_iff ha, ← div_eq_inv_mul, le_div_iff hb, one_mul] #align inv_le_inv inv_le_inv /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ ≤ b ↔ b⁻¹ ≤ a`. See also `inv_le_of_inv_le` for a one-sided implication with one fewer assumption. -/ theorem inv_le (ha : 0 < a) (hb : 0 < b) : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by rw [← inv_le_inv hb (inv_pos.2 ha), inv_inv] #align inv_le inv_le theorem inv_le_of_inv_le (ha : 0 < a) (h : a⁻¹ ≤ b) : b⁻¹ ≤ a := (inv_le ha ((inv_pos.2 ha).trans_le h)).1 h #align inv_le_of_inv_le inv_le_of_inv_le theorem le_inv (ha : 0 < a) (hb : 0 < b) : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by rw [← inv_le_inv (inv_pos.2 hb) ha, inv_inv] #align le_inv le_inv /-- See `inv_lt_inv_of_lt` for the implication from right-to-left with one fewer assumption. -/ theorem inv_lt_inv (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b⁻¹ ↔ b < a := lt_iff_lt_of_le_iff_le (inv_le_inv hb ha) #align inv_lt_inv inv_lt_inv @[gcongr] theorem inv_lt_inv_of_lt (hb : 0 < b) (h : b < a) : a⁻¹ < b⁻¹ := (inv_lt_inv (hb.trans h) hb).2 h #align inv_lt_inv_of_lt inv_lt_inv_of_lt /-- In a linear ordered field, for positive `a` and `b` we have `a⁻¹ < b ↔ b⁻¹ < a`. See also `inv_lt_of_inv_lt` for a one-sided implication with one fewer assumption. -/ theorem inv_lt (ha : 0 < a) (hb : 0 < b) : a⁻¹ < b ↔ b⁻¹ < a := lt_iff_lt_of_le_iff_le (le_inv hb ha) #align inv_lt inv_lt theorem inv_lt_of_inv_lt (ha : 0 < a) (h : a⁻¹ < b) : b⁻¹ < a := (inv_lt ha ((inv_pos.2 ha).trans h)).1 h #align inv_lt_of_inv_lt inv_lt_of_inv_lt theorem lt_inv (ha : 0 < a) (hb : 0 < b) : a < b⁻¹ ↔ b < a⁻¹ := lt_iff_lt_of_le_iff_le (inv_le hb ha) #align lt_inv lt_inv theorem inv_lt_one (ha : 1 < a) : a⁻¹ < 1 := by rwa [inv_lt (zero_lt_one.trans ha) zero_lt_one, inv_one] #align inv_lt_one inv_lt_one theorem one_lt_inv (h₁ : 0 < a) (h₂ : a < 1) : 1 < a⁻¹ := by rwa [lt_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_lt_inv one_lt_inv theorem inv_le_one (ha : 1 ≤ a) : a⁻¹ ≤ 1 := by rwa [inv_le (zero_lt_one.trans_le ha) zero_lt_one, inv_one] #align inv_le_one inv_le_one theorem one_le_inv (h₁ : 0 < a) (h₂ : a ≤ 1) : 1 ≤ a⁻¹ := by rwa [le_inv (@zero_lt_one α _ _ _ _ _) h₁, inv_one] #align one_le_inv one_le_inv theorem inv_lt_one_iff_of_pos (h₀ : 0 < a) : a⁻¹ < 1 ↔ 1 < a := ⟨fun h₁ => inv_inv a ▸ one_lt_inv (inv_pos.2 h₀) h₁, inv_lt_one⟩ #align inv_lt_one_iff_of_pos inv_lt_one_iff_of_pos theorem inv_lt_one_iff : a⁻¹ < 1 ↔ a ≤ 0 ∨ 1 < a := by rcases le_or_lt a 0 with ha | ha · simp [ha, (inv_nonpos.2 ha).trans_lt zero_lt_one] · simp only [ha.not_le, false_or_iff, inv_lt_one_iff_of_pos ha] #align inv_lt_one_iff inv_lt_one_iff theorem one_lt_inv_iff : 1 < a⁻¹ ↔ 0 < a ∧ a < 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans h), inv_inv a ▸ inv_lt_one h⟩, and_imp.2 one_lt_inv⟩ #align one_lt_inv_iff one_lt_inv_iff theorem inv_le_one_iff : a⁻¹ ≤ 1 ↔ a ≤ 0 ∨ 1 ≤ a := by rcases em (a = 1) with (rfl | ha) · simp [le_rfl] · simp only [Ne.le_iff_lt (Ne.symm ha), Ne.le_iff_lt (mt inv_eq_one.1 ha), inv_lt_one_iff] #align inv_le_one_iff inv_le_one_iff theorem one_le_inv_iff : 1 ≤ a⁻¹ ↔ 0 < a ∧ a ≤ 1 := ⟨fun h => ⟨inv_pos.1 (zero_lt_one.trans_le h), inv_inv a ▸ inv_le_one h⟩, and_imp.2 one_le_inv⟩ #align one_le_inv_iff one_le_inv_iff /-! ### Relating two divisions. -/ @[mono, gcongr] lemma div_le_div_of_nonneg_right (hab : a ≤ b) (hc : 0 ≤ c) : a / c ≤ b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_le_mul_of_nonneg_right hab (one_div_nonneg.2 hc) #align div_le_div_of_le_of_nonneg div_le_div_of_nonneg_right @[gcongr] lemma div_lt_div_of_pos_right (h : a < b) (hc : 0 < c) : a / c < b / c := by rw [div_eq_mul_one_div a c, div_eq_mul_one_div b c] exact mul_lt_mul_of_pos_right h (one_div_pos.2 hc) #align div_lt_div_of_lt div_lt_div_of_pos_right -- Not a `mono` lemma b/c `div_le_div` is strictly more general @[gcongr] lemma div_le_div_of_nonneg_left (ha : 0 ≤ a) (hc : 0 < c) (h : c ≤ b) : a / b ≤ a / c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_le_mul_of_nonneg_left ((inv_le_inv (hc.trans_le h) hc).mpr h) ha #align div_le_div_of_le_left div_le_div_of_nonneg_left @[gcongr] lemma div_lt_div_of_pos_left (ha : 0 < a) (hc : 0 < c) (h : c < b) : a / b < a / c := by simpa only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv (hc.trans h) hc] #align div_lt_div_of_lt_left div_lt_div_of_pos_left -- 2024-02-16 @[deprecated] alias div_le_div_of_le_of_nonneg := div_le_div_of_nonneg_right @[deprecated] alias div_lt_div_of_lt := div_lt_div_of_pos_right @[deprecated] alias div_le_div_of_le_left := div_le_div_of_nonneg_left @[deprecated] alias div_lt_div_of_lt_left := div_lt_div_of_pos_left @[deprecated div_le_div_of_nonneg_right (since := "2024-02-16")] lemma div_le_div_of_le (hc : 0 ≤ c) (hab : a ≤ b) : a / c ≤ b / c := div_le_div_of_nonneg_right hab hc #align div_le_div_of_le div_le_div_of_le theorem div_le_div_right (hc : 0 < c) : a / c ≤ b / c ↔ a ≤ b := ⟨le_imp_le_of_lt_imp_lt fun hab ↦ div_lt_div_of_pos_right hab hc, fun hab ↦ div_le_div_of_nonneg_right hab hc.le⟩ #align div_le_div_right div_le_div_right theorem div_lt_div_right (hc : 0 < c) : a / c < b / c ↔ a < b := lt_iff_lt_of_le_iff_le <| div_le_div_right hc #align div_lt_div_right div_lt_div_right theorem div_lt_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b < a / c ↔ c < b := by simp only [div_eq_mul_inv, mul_lt_mul_left ha, inv_lt_inv hb hc] #align div_lt_div_left div_lt_div_left theorem div_le_div_left (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) : a / b ≤ a / c ↔ c ≤ b := le_iff_le_iff_lt_iff_lt.2 (div_lt_div_left ha hc hb) #align div_le_div_left div_le_div_left theorem div_lt_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b < c / d ↔ a * d < c * b := by rw [lt_div_iff d0, div_mul_eq_mul_div, div_lt_iff b0] #align div_lt_div_iff div_lt_div_iff theorem div_le_div_iff (b0 : 0 < b) (d0 : 0 < d) : a / b ≤ c / d ↔ a * d ≤ c * b := by rw [le_div_iff d0, div_mul_eq_mul_div, div_le_iff b0] #align div_le_div_iff div_le_div_iff @[mono, gcongr] theorem div_le_div (hc : 0 ≤ c) (hac : a ≤ c) (hd : 0 < d) (hbd : d ≤ b) : a / b ≤ c / d := by rw [div_le_div_iff (hd.trans_le hbd) hd] exact mul_le_mul hac hbd hd.le hc #align div_le_div div_le_div @[gcongr] theorem div_lt_div (hac : a < c) (hbd : d ≤ b) (c0 : 0 ≤ c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans_le hbd) d0).2 (mul_lt_mul hac hbd d0 c0) #align div_lt_div div_lt_div theorem div_lt_div' (hac : a ≤ c) (hbd : d < b) (c0 : 0 < c) (d0 : 0 < d) : a / b < c / d := (div_lt_div_iff (d0.trans hbd) d0).2 (mul_lt_mul' hac hbd d0.le c0) #align div_lt_div' div_lt_div' /-! ### Relating one division and involving `1` -/ theorem div_le_self (ha : 0 ≤ a) (hb : 1 ≤ b) : a / b ≤ a := by simpa only [div_one] using div_le_div_of_nonneg_left ha zero_lt_one hb #align div_le_self div_le_self theorem div_lt_self (ha : 0 < a) (hb : 1 < b) : a / b < a := by simpa only [div_one] using div_lt_div_of_pos_left ha zero_lt_one hb #align div_lt_self div_lt_self theorem le_div_self (ha : 0 ≤ a) (hb₀ : 0 < b) (hb₁ : b ≤ 1) : a ≤ a / b := by simpa only [div_one] using div_le_div_of_nonneg_left ha hb₀ hb₁ #align le_div_self le_div_self
Mathlib/Algebra/Order/Field/Basic.lean
364
364
theorem one_le_div (hb : 0 < b) : 1 ≤ a / b ↔ b ≤ a := by
rw [le_div_iff hb, one_mul]
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg #align norm_nonneg' norm_nonneg' #align norm_nonneg norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ #align abs_norm abs_norm namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are nonnegative, via `norm_nonneg'`. -/ @[positivity Norm.norm _] def evalMulNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg' $a)) | _, _, _ => throwError "not ‖ · ‖" /-- Extension for the `positivity` tactic: additive norms are nonnegative, via `norm_nonneg`. -/ @[positivity Norm.norm _] def evalAddNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedAddGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg $a)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] #align norm_one' norm_one' #align norm_zero norm_zero @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' #align ne_one_of_norm_ne_zero ne_one_of_norm_ne_zero #align ne_zero_of_norm_ne_zero ne_zero_of_norm_ne_zero @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] #align norm_of_subsingleton' norm_of_subsingleton' #align norm_of_subsingleton norm_of_subsingleton @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity #align zero_lt_one_add_norm_sq' zero_lt_one_add_norm_sq' #align zero_lt_one_add_norm_sq zero_lt_one_add_norm_sq @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b #align norm_div_le norm_div_le #align norm_sub_le norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ #align norm_div_le_of_le norm_div_le_of_le #align norm_sub_le_of_le norm_sub_le_of_le @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le #align dist_le_norm_add_norm' dist_le_norm_add_norm' #align dist_le_norm_add_norm dist_le_norm_add_norm @[to_additive abs_norm_sub_norm_le]
Mathlib/Analysis/Normed/Group/Basic.lean
634
635
theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by
simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Finset.Fin import Mathlib.Data.Int.Order.Units import Mathlib.GroupTheory.OrderOfElement import Mathlib.GroupTheory.Perm.Support import Mathlib.Logic.Equiv.Fintype #align_import group_theory.perm.sign from "leanprover-community/mathlib"@"f694c7dead66f5d4c80f446c796a5aad14707f0e" /-! # Permutations on `Fintype`s This file contains miscellaneous lemmas about `Equiv.Perm` and `Equiv.swap`, building on top of those in `Data/Equiv/Basic` and other files in `GroupTheory/Perm/*`. -/ universe u v open Equiv Function Fintype Finset variable {α : Type u} {β : Type v} -- An example on how to determine the order of an element of a finite group. example : orderOf (-1 : ℤˣ) = 2 := orderOf_eq_prime (Int.units_sq _) (by decide) namespace Equiv.Perm section Conjugation variable [DecidableEq α] [Fintype α] {σ τ : Perm α} theorem isConj_of_support_equiv (f : { x // x ∈ (σ.support : Set α) } ≃ { x // x ∈ (τ.support : Set α) }) (hf : ∀ (x : α) (hx : x ∈ (σ.support : Set α)), (f ⟨σ x, apply_mem_support.2 hx⟩ : α) = τ ↑(f ⟨x, hx⟩)) : IsConj σ τ := by refine isConj_iff.2 ⟨Equiv.extendSubtype f, ?_⟩ rw [mul_inv_eq_iff_eq_mul] ext x simp only [Perm.mul_apply] by_cases hx : x ∈ σ.support · rw [Equiv.extendSubtype_apply_of_mem, Equiv.extendSubtype_apply_of_mem] · exact hf x (Finset.mem_coe.2 hx) · rwa [Classical.not_not.1 ((not_congr mem_support).1 (Equiv.extendSubtype_not_mem f _ _)), Classical.not_not.1 ((not_congr mem_support).mp hx)] #align equiv.perm.is_conj_of_support_equiv Equiv.Perm.isConj_of_support_equiv end Conjugation
Mathlib/GroupTheory/Perm/Finite.lean
57
65
theorem perm_inv_on_of_perm_on_finset {s : Finset α} {f : Perm α} (h : ∀ x ∈ s, f x ∈ s) {y : α} (hy : y ∈ s) : f⁻¹ y ∈ s := by
have h0 : ∀ y ∈ s, ∃ (x : _) (hx : x ∈ s), y = (fun i (_ : i ∈ s) => f i) x hx := Finset.surj_on_of_inj_on_of_card_le (fun x hx => (fun i _ => f i) x hx) (fun a ha => h a ha) (fun a₁ a₂ ha₁ ha₂ heq => (Equiv.apply_eq_iff_eq f).mp heq) rfl.ge obtain ⟨y2, hy2, heq⟩ := h0 y hy convert hy2 rw [heq] simp only [inv_apply_self]
/- Copyright (c) 2018 Andreas Swerdlow. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andreas Swerdlow -/ import Mathlib.Algebra.Module.LinearMap.Basic import Mathlib.LinearAlgebra.Basic import Mathlib.LinearAlgebra.Basis import Mathlib.LinearAlgebra.BilinearMap #align_import linear_algebra.sesquilinear_form from "leanprover-community/mathlib"@"87c54600fe3cdc7d32ff5b50873ac724d86aef8d" /-! # Sesquilinear maps This files provides properties about sesquilinear maps and forms. The maps considered are of the form `M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M`, where `I₁ : R₁ →+* R` and `I₂ : R₂ →+* R` are ring homomorphisms and `M₁` is a module over `R₁`, `M₂` is a module over `R₂` and `M` is a module over `R`. Sesquilinear forms are the special case that `M₁ = M₂`, `M = R₁ = R₂ = R`, and `I₁ = RingHom.id R`. Taking additionally `I₂ = RingHom.id R`, then one obtains bilinear forms. These forms are a special case of the bilinear maps defined in `BilinearMap.lean` and all basic lemmas about construction and elementary calculations are found there. ## Main declarations * `IsOrtho`: states that two vectors are orthogonal with respect to a sesquilinear map * `IsSymm`, `IsAlt`: states that a sesquilinear form is symmetric and alternating, respectively * `orthogonalBilin`: provides the orthogonal complement with respect to sesquilinear form ## References * <https://en.wikipedia.org/wiki/Sesquilinear_form#Over_arbitrary_rings> ## Tags Sesquilinear form, Sesquilinear map, -/ variable {R R₁ R₂ R₃ M M₁ M₂ M₃ Mₗ₁ Mₗ₁' Mₗ₂ Mₗ₂' K K₁ K₂ V V₁ V₂ n : Type*} namespace LinearMap /-! ### Orthogonal vectors -/ section CommRing -- the `ₗ` subscript variables are for special cases about linear (as opposed to semilinear) maps variable [CommSemiring R] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] [CommSemiring R₂] [AddCommMonoid M₂] [Module R₂ M₂] [AddCommMonoid M] [Module R M] {I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R} /-- The proposition that two elements of a sesquilinear map space are orthogonal -/ def IsOrtho (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x : M₁) (y : M₂) : Prop := B x y = 0 #align linear_map.is_ortho LinearMap.IsOrtho theorem isOrtho_def {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} {x y} : B.IsOrtho x y ↔ B x y = 0 := Iff.rfl #align linear_map.is_ortho_def LinearMap.isOrtho_def theorem isOrtho_zero_left (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B (0 : M₁) x := by dsimp only [IsOrtho] rw [map_zero B, zero_apply] #align linear_map.is_ortho_zero_left LinearMap.isOrtho_zero_left theorem isOrtho_zero_right (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) (x) : IsOrtho B x (0 : M₂) := map_zero (B x) #align linear_map.is_ortho_zero_right LinearMap.isOrtho_zero_right theorem isOrtho_flip {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {x y} : B.IsOrtho x y ↔ B.flip.IsOrtho y x := by simp_rw [isOrtho_def, flip_apply] #align linear_map.is_ortho_flip LinearMap.isOrtho_flip /-- A set of vectors `v` is orthogonal with respect to some bilinear map `B` if and only if for all `i ≠ j`, `B (v i) (v j) = 0`. For orthogonality between two elements, use `BilinForm.isOrtho` -/ def IsOrthoᵢ (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) (v : n → M₁) : Prop := Pairwise (B.IsOrtho on v) set_option linter.uppercaseLean3 false in #align linear_map.is_Ortho LinearMap.IsOrthoᵢ theorem isOrthoᵢ_def {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M} {v : n → M₁} : B.IsOrthoᵢ v ↔ ∀ i j : n, i ≠ j → B (v i) (v j) = 0 := Iff.rfl set_option linter.uppercaseLean3 false in #align linear_map.is_Ortho_def LinearMap.isOrthoᵢ_def theorem isOrthoᵢ_flip (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₁'] M) {v : n → M₁} : B.IsOrthoᵢ v ↔ B.flip.IsOrthoᵢ v := by simp_rw [isOrthoᵢ_def] constructor <;> intro h i j hij · rw [flip_apply] exact h j i (Ne.symm hij) simp_rw [flip_apply] at h exact h j i (Ne.symm hij) set_option linter.uppercaseLean3 false in #align linear_map.is_Ortho_flip LinearMap.isOrthoᵢ_flip end CommRing section Field variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁] [Field K₂] [AddCommGroup V₂] [Module K₂ V₂] {I₁ : K₁ →+* K} {I₂ : K₂ →+* K} {I₁' : K₁ →+* K} {J₁ : K →+* K} {J₂ : K →+* K} -- todo: this also holds for [CommRing R] [IsDomain R] when J₁ is invertible theorem ortho_smul_left {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₁} (ha : a ≠ 0) : IsOrtho B x y ↔ IsOrtho B (a • x) y := by dsimp only [IsOrtho] constructor <;> intro H · rw [map_smulₛₗ₂, H, smul_zero] · rw [map_smulₛₗ₂, smul_eq_zero] at H cases' H with H H · rw [map_eq_zero I₁] at H trivial · exact H #align linear_map.ortho_smul_left LinearMap.ortho_smul_left -- todo: this also holds for [CommRing R] [IsDomain R] when J₂ is invertible theorem ortho_smul_right {B : V₁ →ₛₗ[I₁] V₂ →ₛₗ[I₂] V} {x y} {a : K₂} {ha : a ≠ 0} : IsOrtho B x y ↔ IsOrtho B x (a • y) := by dsimp only [IsOrtho] constructor <;> intro H · rw [map_smulₛₗ, H, smul_zero] · rw [map_smulₛₗ, smul_eq_zero] at H cases' H with H H · simp at H exfalso exact ha H · exact H #align linear_map.ortho_smul_right LinearMap.ortho_smul_right /-- A set of orthogonal vectors `v` with respect to some sesquilinear map `B` is linearly independent if for all `i`, `B (v i) (v i) ≠ 0`. -/ theorem linearIndependent_of_isOrthoᵢ {B : V₁ →ₛₗ[I₁] V₁ →ₛₗ[I₁'] V} {v : n → V₁} (hv₁ : B.IsOrthoᵢ v) (hv₂ : ∀ i, ¬B.IsOrtho (v i) (v i)) : LinearIndependent K₁ v := by classical rw [linearIndependent_iff'] intro s w hs i hi have : B (s.sum fun i : n ↦ w i • v i) (v i) = 0 := by rw [hs, map_zero, zero_apply] have hsum : (s.sum fun j : n ↦ I₁ (w j) • B (v j) (v i)) = I₁ (w i) • B (v i) (v i) := by apply Finset.sum_eq_single_of_mem i hi intro j _hj hij rw [isOrthoᵢ_def.1 hv₁ _ _ hij, smul_zero] simp_rw [B.map_sum₂, map_smulₛₗ₂, hsum] at this apply (map_eq_zero I₁).mp exact (smul_eq_zero.mp this).elim _root_.id (hv₂ i · |>.elim) set_option linter.uppercaseLean3 false in #align linear_map.linear_independent_of_is_Ortho LinearMap.linearIndependent_of_isOrthoᵢ end Field /-! ### Reflexive bilinear maps -/ section Reflexive variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M} /-- The proposition that a sesquilinear map is reflexive -/ def IsRefl (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop := ∀ x y, B x y = 0 → B y x = 0 #align linear_map.is_refl LinearMap.IsRefl namespace IsRefl variable (H : B.IsRefl) theorem eq_zero : ∀ {x y}, B x y = 0 → B y x = 0 := fun {x y} ↦ H x y #align linear_map.is_refl.eq_zero LinearMap.IsRefl.eq_zero theorem ortho_comm {x y} : IsOrtho B x y ↔ IsOrtho B y x := ⟨eq_zero H, eq_zero H⟩ #align linear_map.is_refl.ortho_comm LinearMap.IsRefl.ortho_comm theorem domRestrict (H : B.IsRefl) (p : Submodule R₁ M₁) : (B.domRestrict₁₂ p p).IsRefl := fun _ _ ↦ by simp_rw [domRestrict₁₂_apply] exact H _ _ #align linear_map.is_refl.dom_restrict_refl LinearMap.IsRefl.domRestrict @[simp] theorem flip_isRefl_iff : B.flip.IsRefl ↔ B.IsRefl := ⟨fun h x y H ↦ h y x ((B.flip_apply _ _).trans H), fun h x y ↦ h y x⟩ #align linear_map.is_refl.flip_is_refl_iff LinearMap.IsRefl.flip_isRefl_iff theorem ker_flip_eq_bot (H : B.IsRefl) (h : LinearMap.ker B = ⊥) : LinearMap.ker B.flip = ⊥ := by refine ker_eq_bot'.mpr fun _ hx ↦ ker_eq_bot'.mp h _ ?_ ext exact H _ _ (LinearMap.congr_fun hx _) #align linear_map.is_refl.ker_flip_eq_bot LinearMap.IsRefl.ker_flip_eq_bot theorem ker_eq_bot_iff_ker_flip_eq_bot (H : B.IsRefl) : LinearMap.ker B = ⊥ ↔ LinearMap.ker B.flip = ⊥ := by refine ⟨ker_flip_eq_bot H, fun h ↦ ?_⟩ exact (congr_arg _ B.flip_flip.symm).trans (ker_flip_eq_bot (flip_isRefl_iff.mpr H) h) #align linear_map.is_refl.ker_eq_bot_iff_ker_flip_eq_bot LinearMap.IsRefl.ker_eq_bot_iff_ker_flip_eq_bot end IsRefl end Reflexive /-! ### Symmetric bilinear forms -/ section Symmetric variable [CommSemiring R] [AddCommMonoid M] [Module R M] {I : R →+* R} {B : M →ₛₗ[I] M →ₗ[R] R} /-- The proposition that a sesquilinear form is symmetric -/ def IsSymm (B : M →ₛₗ[I] M →ₗ[R] R) : Prop := ∀ x y, I (B x y) = B y x #align linear_map.is_symm LinearMap.IsSymm namespace IsSymm protected theorem eq (H : B.IsSymm) (x y) : I (B x y) = B y x := H x y #align linear_map.is_symm.eq LinearMap.IsSymm.eq theorem isRefl (H : B.IsSymm) : B.IsRefl := fun x y H1 ↦ by rw [← H.eq] simp [H1] #align linear_map.is_symm.is_refl LinearMap.IsSymm.isRefl theorem ortho_comm (H : B.IsSymm) {x y} : IsOrtho B x y ↔ IsOrtho B y x := H.isRefl.ortho_comm #align linear_map.is_symm.ortho_comm LinearMap.IsSymm.ortho_comm theorem domRestrict (H : B.IsSymm) (p : Submodule R M) : (B.domRestrict₁₂ p p).IsSymm := fun _ _ ↦ by simp_rw [domRestrict₁₂_apply] exact H _ _ #align linear_map.is_symm.dom_restrict_symm LinearMap.IsSymm.domRestrict end IsSymm @[simp] theorem isSymm_zero : (0 : M →ₛₗ[I] M →ₗ[R] R).IsSymm := fun _ _ => map_zero _ theorem isSymm_iff_eq_flip {B : LinearMap.BilinForm R M} : B.IsSymm ↔ B = B.flip := by constructor <;> intro h · ext rw [← h, flip_apply, RingHom.id_apply] intro x y conv_lhs => rw [h] rfl #align linear_map.is_symm_iff_eq_flip LinearMap.isSymm_iff_eq_flip end Symmetric /-! ### Alternating bilinear maps -/ section Alternating section CommSemiring section AddCommMonoid variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {I : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M} /-- The proposition that a sesquilinear map is alternating -/ def IsAlt (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Prop := ∀ x, B x x = 0 #align linear_map.is_alt LinearMap.IsAlt variable (H : B.IsAlt) theorem IsAlt.self_eq_zero (x : M₁) : B x x = 0 := H x #align linear_map.is_alt.self_eq_zero LinearMap.IsAlt.self_eq_zero end AddCommMonoid section AddCommGroup namespace IsAlt variable [CommSemiring R] [AddCommGroup M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {I : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M} variable (H : B.IsAlt) theorem neg (x y : M₁) : -B x y = B y x := by have H1 : B (y + x) (y + x) = 0 := self_eq_zero H (y + x) simp? [map_add, self_eq_zero H] at H1 says simp only [map_add, add_apply, self_eq_zero H, zero_add, add_zero] at H1 rw [add_eq_zero_iff_neg_eq] at H1 exact H1 #align linear_map.is_alt.neg LinearMap.IsAlt.neg theorem isRefl : B.IsRefl := by intro x y h rw [← neg H, h, neg_zero] #align linear_map.is_alt.is_refl LinearMap.IsAlt.isRefl theorem ortho_comm {x y} : IsOrtho B x y ↔ IsOrtho B y x := H.isRefl.ortho_comm #align linear_map.is_alt.ortho_comm LinearMap.IsAlt.ortho_comm end IsAlt end AddCommGroup end CommSemiring section Semiring variable [CommRing R] [AddCommGroup M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] {I : R₁ →+* R} theorem isAlt_iff_eq_neg_flip [NoZeroDivisors R] [CharZero R] {B : M₁ →ₛₗ[I] M₁ →ₛₗ[I] R} : B.IsAlt ↔ B = -B.flip := by constructor <;> intro h · ext simp_rw [neg_apply, flip_apply] exact (h.neg _ _).symm intro x let h' := congr_fun₂ h x x simp only [neg_apply, flip_apply, ← add_eq_zero_iff_eq_neg] at h' exact add_self_eq_zero.mp h' #align linear_map.is_alt_iff_eq_neg_flip LinearMap.isAlt_iff_eq_neg_flip end Semiring end Alternating end LinearMap namespace Submodule /-! ### The orthogonal complement -/ variable [CommRing R] [CommRing R₁] [AddCommGroup M₁] [Module R₁ M₁] [AddCommGroup M] [Module R M] {I₁ : R₁ →+* R} {I₂ : R₁ →+* R} {B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M} /-- The orthogonal complement of a submodule `N` with respect to some bilinear map is the set of elements `x` which are orthogonal to all elements of `N`; i.e., for all `y` in `N`, `B x y = 0`. Note that for general (neither symmetric nor antisymmetric) bilinear maps this definition has a chirality; in addition to this "left" orthogonal complement one could define a "right" orthogonal complement for which, for all `y` in `N`, `B y x = 0`. This variant definition is not currently provided in mathlib. -/ def orthogonalBilin (N : Submodule R₁ M₁) (B : M₁ →ₛₗ[I₁] M₁ →ₛₗ[I₂] M) : Submodule R₁ M₁ where carrier := { m | ∀ n ∈ N, B.IsOrtho n m } zero_mem' x _ := B.isOrtho_zero_right x add_mem' hx hy n hn := by rw [LinearMap.IsOrtho, map_add, show B n _ = 0 from hx n hn, show B n _ = 0 from hy n hn, zero_add] smul_mem' c x hx n hn := by rw [LinearMap.IsOrtho, LinearMap.map_smulₛₗ, show B n x = 0 from hx n hn, smul_zero] #align submodule.orthogonal_bilin Submodule.orthogonalBilin variable {N L : Submodule R₁ M₁} @[simp] theorem mem_orthogonalBilin_iff {m : M₁} : m ∈ N.orthogonalBilin B ↔ ∀ n ∈ N, B.IsOrtho n m := Iff.rfl #align submodule.mem_orthogonal_bilin_iff Submodule.mem_orthogonalBilin_iff theorem orthogonalBilin_le (h : N ≤ L) : L.orthogonalBilin B ≤ N.orthogonalBilin B := fun _ hn l hl ↦ hn l (h hl) #align submodule.orthogonal_bilin_le Submodule.orthogonalBilin_le theorem le_orthogonalBilin_orthogonalBilin (b : B.IsRefl) : N ≤ (N.orthogonalBilin B).orthogonalBilin B := fun n hn _m hm ↦ b _ _ (hm n hn) #align submodule.le_orthogonal_bilin_orthogonal_bilin Submodule.le_orthogonalBilin_orthogonalBilin end Submodule namespace LinearMap section Orthogonal variable [Field K] [AddCommGroup V] [Module K V] [Field K₁] [AddCommGroup V₁] [Module K₁ V₁] [AddCommGroup V₂] [Module K V₂] {J : K →+* K} {J₁ : K₁ →+* K} {J₁' : K₁ →+* K} -- ↓ This lemma only applies in fields as we require `a * b = 0 → a = 0 ∨ b = 0` theorem span_singleton_inf_orthogonal_eq_bot (B : V₁ →ₛₗ[J₁] V₁ →ₛₗ[J₁'] V₂) (x : V₁) (hx : ¬B.IsOrtho x x) : (K₁ ∙ x) ⊓ Submodule.orthogonalBilin (K₁ ∙ x) B = ⊥ := by rw [← Finset.coe_singleton] refine eq_bot_iff.2 fun y h ↦ ?_ rcases mem_span_finset.1 h.1 with ⟨μ, rfl⟩ replace h := h.2 x (by simp [Submodule.mem_span] : x ∈ Submodule.span K₁ ({x} : Finset V₁)) rw [Finset.sum_singleton] at h ⊢ suffices hμzero : μ x = 0 by rw [hμzero, zero_smul, Submodule.mem_bot] rw [isOrtho_def, map_smulₛₗ] at h exact Or.elim (smul_eq_zero.mp h) (fun y ↦ by simpa using y) (fun hfalse ↦ False.elim <| hx hfalse) #align linear_map.span_singleton_inf_orthogonal_eq_bot LinearMap.span_singleton_inf_orthogonal_eq_bot -- ↓ This lemma only applies in fields since we use the `mul_eq_zero` theorem orthogonal_span_singleton_eq_to_lin_ker {B : V →ₗ[K] V →ₛₗ[J] V₂} (x : V) : Submodule.orthogonalBilin (K ∙ x) B = LinearMap.ker (B x) := by ext y simp_rw [Submodule.mem_orthogonalBilin_iff, LinearMap.mem_ker, Submodule.mem_span_singleton] constructor · exact fun h ↦ h x ⟨1, one_smul _ _⟩ · rintro h _ ⟨z, rfl⟩ rw [isOrtho_def, map_smulₛₗ₂, smul_eq_zero] exact Or.intro_right _ h #align linear_map.orthogonal_span_singleton_eq_to_lin_ker LinearMap.orthogonal_span_singleton_eq_to_lin_ker -- todo: Generalize this to sesquilinear maps theorem span_singleton_sup_orthogonal_eq_top {B : V →ₗ[K] V →ₗ[K] K} {x : V} (hx : ¬B.IsOrtho x x) : (K ∙ x) ⊔ Submodule.orthogonalBilin (N := K ∙ x) (B := B) = ⊤ := by rw [orthogonal_span_singleton_eq_to_lin_ker] exact (B x).span_singleton_sup_ker_eq_top hx #align linear_map.span_singleton_sup_orthogonal_eq_top LinearMap.span_singleton_sup_orthogonal_eq_top -- todo: Generalize this to sesquilinear maps /-- Given a bilinear form `B` and some `x` such that `B x x ≠ 0`, the span of the singleton of `x` is complement to its orthogonal complement. -/ theorem isCompl_span_singleton_orthogonal {B : V →ₗ[K] V →ₗ[K] K} {x : V} (hx : ¬B.IsOrtho x x) : IsCompl (K ∙ x) (Submodule.orthogonalBilin (N := K ∙ x) (B := B)) := { disjoint := disjoint_iff.2 <| span_singleton_inf_orthogonal_eq_bot B x hx codisjoint := codisjoint_iff.2 <| span_singleton_sup_orthogonal_eq_top hx } #align linear_map.is_compl_span_singleton_orthogonal LinearMap.isCompl_span_singleton_orthogonal end Orthogonal /-! ### Adjoint pairs -/ section AdjointPair section AddCommMonoid variable [CommSemiring R] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid M₁] [Module R M₁] variable [AddCommMonoid M₂] [Module R M₂] variable [AddCommMonoid M₃] [Module R M₃] variable {I : R →+* R} variable {B F : M →ₗ[R] M →ₛₗ[I] M₃} {B' : M₁ →ₗ[R] M₁ →ₛₗ[I] M₃} {B'' : M₂ →ₗ[R] M₂ →ₛₗ[I] M₃} variable {f f' : M →ₗ[R] M₁} {g g' : M₁ →ₗ[R] M} variable (B B' f g) /-- Given a pair of modules equipped with bilinear maps, this is the condition for a pair of maps between them to be mutually adjoint. -/ def IsAdjointPair := ∀ x y, B' (f x) y = B x (g y) #align linear_map.is_adjoint_pair LinearMap.IsAdjointPair variable {B B' f g} theorem isAdjointPair_iff_comp_eq_compl₂ : IsAdjointPair B B' f g ↔ B'.comp f = B.compl₂ g := by constructor <;> intro h · ext x y rw [comp_apply, compl₂_apply] exact h x y · intro _ _ rw [← compl₂_apply, ← comp_apply, h] #align linear_map.is_adjoint_pair_iff_comp_eq_compl₂ LinearMap.isAdjointPair_iff_comp_eq_compl₂ theorem isAdjointPair_zero : IsAdjointPair B B' 0 0 := fun _ _ ↦ by simp only [zero_apply, map_zero] #align linear_map.is_adjoint_pair_zero LinearMap.isAdjointPair_zero theorem isAdjointPair_id : IsAdjointPair B B 1 1 := fun _ _ ↦ rfl #align linear_map.is_adjoint_pair_id LinearMap.isAdjointPair_id theorem IsAdjointPair.add (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B B' f' g') : IsAdjointPair B B' (f + f') (g + g') := fun x _ ↦ by rw [f.add_apply, g.add_apply, B'.map_add₂, (B x).map_add, h, h'] #align linear_map.is_adjoint_pair.add LinearMap.IsAdjointPair.add theorem IsAdjointPair.comp {f' : M₁ →ₗ[R] M₂} {g' : M₂ →ₗ[R] M₁} (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B' B'' f' g') : IsAdjointPair B B'' (f'.comp f) (g.comp g') := fun _ _ ↦ by rw [LinearMap.comp_apply, LinearMap.comp_apply, h', h] #align linear_map.is_adjoint_pair.comp LinearMap.IsAdjointPair.comp theorem IsAdjointPair.mul {f g f' g' : Module.End R M} (h : IsAdjointPair B B f g) (h' : IsAdjointPair B B f' g') : IsAdjointPair B B (f * f') (g' * g) := h'.comp h #align linear_map.is_adjoint_pair.mul LinearMap.IsAdjointPair.mul end AddCommMonoid section AddCommGroup variable [CommRing R] variable [AddCommGroup M] [Module R M] variable [AddCommGroup M₁] [Module R M₁] variable [AddCommGroup M₂] [Module R M₂] variable {B F : M →ₗ[R] M →ₗ[R] M₂} {B' : M₁ →ₗ[R] M₁ →ₗ[R] M₂} variable {f f' : M →ₗ[R] M₁} {g g' : M₁ →ₗ[R] M} theorem IsAdjointPair.sub (h : IsAdjointPair B B' f g) (h' : IsAdjointPair B B' f' g') : IsAdjointPair B B' (f - f') (g - g') := fun x _ ↦ by rw [f.sub_apply, g.sub_apply, B'.map_sub₂, (B x).map_sub, h, h'] #align linear_map.is_adjoint_pair.sub LinearMap.IsAdjointPair.sub theorem IsAdjointPair.smul (c : R) (h : IsAdjointPair B B' f g) : IsAdjointPair B B' (c • f) (c • g) := fun _ _ ↦ by simp [h _] #align linear_map.is_adjoint_pair.smul LinearMap.IsAdjointPair.smul end AddCommGroup end AdjointPair /-! ### Self-adjoint pairs-/ section SelfadjointPair section AddCommMonoid variable [CommSemiring R] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid M₁] [Module R M₁] variable {I : R →+* R} variable (B F : M →ₗ[R] M →ₛₗ[I] M₁) /-- The condition for an endomorphism to be "self-adjoint" with respect to a pair of bilinear maps on the underlying module. In the case that these two maps are identical, this is the usual concept of self adjointness. In the case that one of the maps is the negation of the other, this is the usual concept of skew adjointness. -/ def IsPairSelfAdjoint (f : Module.End R M) := IsAdjointPair B F f f #align linear_map.is_pair_self_adjoint LinearMap.IsPairSelfAdjoint /-- An endomorphism of a module is self-adjoint with respect to a bilinear map if it serves as an adjoint for itself. -/ protected def IsSelfAdjoint (f : Module.End R M) := IsAdjointPair B B f f #align linear_map.is_self_adjoint LinearMap.IsSelfAdjoint end AddCommMonoid section AddCommGroup variable [CommRing R] variable [AddCommGroup M] [Module R M] [AddCommGroup M₁] [Module R M₁] variable [AddCommGroup M₂] [Module R M₂] (B F : M →ₗ[R] M →ₗ[R] M₂) /-- The set of pair-self-adjoint endomorphisms are a submodule of the type of all endomorphisms. -/ def isPairSelfAdjointSubmodule : Submodule R (Module.End R M) where carrier := { f | IsPairSelfAdjoint B F f } zero_mem' := isAdjointPair_zero add_mem' hf hg := hf.add hg smul_mem' c _ h := h.smul c #align linear_map.is_pair_self_adjoint_submodule LinearMap.isPairSelfAdjointSubmodule /-- An endomorphism of a module is skew-adjoint with respect to a bilinear map if its negation serves as an adjoint. -/ def IsSkewAdjoint (f : Module.End R M) := IsAdjointPair B B f (-f) #align linear_map.is_skew_adjoint LinearMap.IsSkewAdjoint /-- The set of self-adjoint endomorphisms of a module with bilinear map is a submodule. (In fact it is a Jordan subalgebra.) -/ def selfAdjointSubmodule := isPairSelfAdjointSubmodule B B #align linear_map.self_adjoint_submodule LinearMap.selfAdjointSubmodule /-- The set of skew-adjoint endomorphisms of a module with bilinear map is a submodule. (In fact it is a Lie subalgebra.) -/ def skewAdjointSubmodule := isPairSelfAdjointSubmodule (-B) B #align linear_map.skew_adjoint_submodule LinearMap.skewAdjointSubmodule variable {B F} @[simp] theorem mem_isPairSelfAdjointSubmodule (f : Module.End R M) : f ∈ isPairSelfAdjointSubmodule B F ↔ IsPairSelfAdjoint B F f := Iff.rfl #align linear_map.mem_is_pair_self_adjoint_submodule LinearMap.mem_isPairSelfAdjointSubmodule theorem isPairSelfAdjoint_equiv (e : M₁ ≃ₗ[R] M) (f : Module.End R M) : IsPairSelfAdjoint B F f ↔ IsPairSelfAdjoint (B.compl₁₂ ↑e ↑e) (F.compl₁₂ ↑e ↑e) (e.symm.conj f) := by have hₗ : (F.compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M)).comp (e.symm.conj f) = (F.comp f).compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M) := by ext simp only [LinearEquiv.symm_conj_apply, coe_comp, LinearEquiv.coe_coe, compl₁₂_apply, LinearEquiv.apply_symm_apply, Function.comp_apply] have hᵣ : (B.compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M)).compl₂ (e.symm.conj f) = (B.compl₂ f).compl₁₂ (↑e : M₁ →ₗ[R] M) (↑e : M₁ →ₗ[R] M) := by ext simp only [LinearEquiv.symm_conj_apply, compl₂_apply, coe_comp, LinearEquiv.coe_coe, compl₁₂_apply, LinearEquiv.apply_symm_apply, Function.comp_apply] have he : Function.Surjective (⇑(↑e : M₁ →ₗ[R] M) : M₁ → M) := e.surjective simp_rw [IsPairSelfAdjoint, isAdjointPair_iff_comp_eq_compl₂, hₗ, hᵣ, compl₁₂_inj he he] #align linear_map.is_pair_self_adjoint_equiv LinearMap.isPairSelfAdjoint_equiv theorem isSkewAdjoint_iff_neg_self_adjoint (f : Module.End R M) : B.IsSkewAdjoint f ↔ IsAdjointPair (-B) B f f := show (∀ x y, B (f x) y = B x ((-f) y)) ↔ ∀ x y, B (f x) y = (-B) x (f y) by simp #align linear_map.is_skew_adjoint_iff_neg_self_adjoint LinearMap.isSkewAdjoint_iff_neg_self_adjoint @[simp] theorem mem_selfAdjointSubmodule (f : Module.End R M) : f ∈ B.selfAdjointSubmodule ↔ B.IsSelfAdjoint f := Iff.rfl #align linear_map.mem_self_adjoint_submodule LinearMap.mem_selfAdjointSubmodule @[simp] theorem mem_skewAdjointSubmodule (f : Module.End R M) : f ∈ B.skewAdjointSubmodule ↔ B.IsSkewAdjoint f := by rw [isSkewAdjoint_iff_neg_self_adjoint] exact Iff.rfl #align linear_map.mem_skew_adjoint_submodule LinearMap.mem_skewAdjointSubmodule end AddCommGroup end SelfadjointPair /-! ### Nondegenerate bilinear maps -/ section Nondegenerate section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [CommSemiring R₁] [AddCommMonoid M₁] [Module R₁ M₁] [CommSemiring R₂] [AddCommMonoid M₂] [Module R₂ M₂] {I₁ : R₁ →+* R} {I₂ : R₂ →+* R} {I₁' : R₁ →+* R} /-- A bilinear map is called left-separating if the only element that is left-orthogonal to every other element is `0`; i.e., for every nonzero `x` in `M₁`, there exists `y` in `M₂` with `B x y ≠ 0`. -/ def SeparatingLeft (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop := ∀ x : M₁, (∀ y : M₂, B x y = 0) → x = 0 #align linear_map.separating_left LinearMap.SeparatingLeft variable (M₁ M₂ I₁ I₂) /-- In a non-trivial module, zero is not non-degenerate. -/ theorem not_separatingLeft_zero [Nontrivial M₁] : ¬(0 : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M).SeparatingLeft := let ⟨m, hm⟩ := exists_ne (0 : M₁) fun h ↦ hm (h m fun _n ↦ rfl) #align linear_map.not_separating_left_zero LinearMap.not_separatingLeft_zero variable {M₁ M₂ I₁ I₂} theorem SeparatingLeft.ne_zero [Nontrivial M₁] {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} (h : B.SeparatingLeft) : B ≠ 0 := fun h0 ↦ not_separatingLeft_zero M₁ M₂ I₁ I₂ <| h0 ▸ h #align linear_map.separating_left.ne_zero LinearMap.SeparatingLeft.ne_zero section Linear variable [AddCommMonoid Mₗ₁] [AddCommMonoid Mₗ₂] [AddCommMonoid Mₗ₁'] [AddCommMonoid Mₗ₂'] variable [Module R Mₗ₁] [Module R Mₗ₂] [Module R Mₗ₁'] [Module R Mₗ₂'] variable {B : Mₗ₁ →ₗ[R] Mₗ₂ →ₗ[R] M} (e₁ : Mₗ₁ ≃ₗ[R] Mₗ₁') (e₂ : Mₗ₂ ≃ₗ[R] Mₗ₂') theorem SeparatingLeft.congr (h : B.SeparatingLeft) : (e₁.arrowCongr (e₂.arrowCongr (LinearEquiv.refl R M)) B).SeparatingLeft := by intro x hx rw [← e₁.symm.map_eq_zero_iff] refine h (e₁.symm x) fun y ↦ ?_ specialize hx (e₂ y) simp only [LinearEquiv.arrowCongr_apply, LinearEquiv.symm_apply_apply, LinearEquiv.map_eq_zero_iff] at hx exact hx #align linear_map.separating_left.congr LinearMap.SeparatingLeft.congr @[simp] theorem separatingLeft_congr_iff : (e₁.arrowCongr (e₂.arrowCongr (LinearEquiv.refl R M)) B).SeparatingLeft ↔ B.SeparatingLeft := ⟨fun h ↦ by convert h.congr e₁.symm e₂.symm ext x y simp, SeparatingLeft.congr e₁ e₂⟩ #align linear_map.separating_left_congr_iff LinearMap.separatingLeft_congr_iff end Linear /-- A bilinear map is called right-separating if the only element that is right-orthogonal to every other element is `0`; i.e., for every nonzero `y` in `M₂`, there exists `x` in `M₁` with `B x y ≠ 0`. -/ def SeparatingRight (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop := ∀ y : M₂, (∀ x : M₁, B x y = 0) → y = 0 #align linear_map.separating_right LinearMap.SeparatingRight /-- A bilinear map is called non-degenerate if it is left-separating and right-separating. -/ def Nondegenerate (B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M) : Prop := SeparatingLeft B ∧ SeparatingRight B #align linear_map.nondegenerate LinearMap.Nondegenerate @[simp] theorem flip_separatingRight {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} : B.flip.SeparatingRight ↔ B.SeparatingLeft := ⟨fun hB x hy ↦ hB x hy, fun hB x hy ↦ hB x hy⟩ #align linear_map.flip_separating_right LinearMap.flip_separatingRight @[simp] theorem flip_separatingLeft {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} : B.flip.SeparatingLeft ↔ SeparatingRight B := by rw [← flip_separatingRight, flip_flip] #align linear_map.flip_separating_left LinearMap.flip_separatingLeft @[simp] theorem flip_nondegenerate {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} : B.flip.Nondegenerate ↔ B.Nondegenerate := Iff.trans and_comm (and_congr flip_separatingRight flip_separatingLeft) #align linear_map.flip_nondegenerate LinearMap.flip_nondegenerate
Mathlib/LinearAlgebra/SesquilinearForm.lean
710
718
theorem separatingLeft_iff_linear_nontrivial {B : M₁ →ₛₗ[I₁] M₂ →ₛₗ[I₂] M} : B.SeparatingLeft ↔ ∀ x : M₁, B x = 0 → x = 0 := by
constructor <;> intro h x hB · simpa only [hB, zero_apply, eq_self_iff_true, forall_const] using h x have h' : B x = 0 := by ext rw [zero_apply] exact hB _ exact h x h'
/- Copyright (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Batteries.Tactic.Alias import Batteries.Data.Nat.Basic /-! # Basic lemmas about natural numbers The primary purpose of the lemmas in this file is to assist with reasoning about sizes of objects, array indices and such. For a more thorough development of the theory of natural numbers, we recommend using Mathlib. -/ namespace Nat /-! ### rec/cases -/ @[simp] theorem recAux_zero {motive : Nat → Sort _} (zero : motive 0) (succ : ∀ n, motive n → motive (n+1)) : Nat.recAux zero succ 0 = zero := rfl theorem recAux_succ {motive : Nat → Sort _} (zero : motive 0) (succ : ∀ n, motive n → motive (n+1)) (n) : Nat.recAux zero succ (n+1) = succ n (Nat.recAux zero succ n) := rfl @[simp] theorem recAuxOn_zero {motive : Nat → Sort _} (zero : motive 0) (succ : ∀ n, motive n → motive (n+1)) : Nat.recAuxOn 0 zero succ = zero := rfl theorem recAuxOn_succ {motive : Nat → Sort _} (zero : motive 0) (succ : ∀ n, motive n → motive (n+1)) (n) : Nat.recAuxOn (n+1) zero succ = succ n (Nat.recAuxOn n zero succ) := rfl @[simp] theorem casesAuxOn_zero {motive : Nat → Sort _} (zero : motive 0) (succ : ∀ n, motive (n+1)) : Nat.casesAuxOn 0 zero succ = zero := rfl theorem casesAuxOn_succ {motive : Nat → Sort _} (zero : motive 0) (succ : ∀ n, motive (n+1)) (n) : Nat.casesAuxOn (n+1) zero succ = succ n := rfl
.lake/packages/batteries/Batteries/Data/Nat/Lemmas.lean
44
46
theorem strongRec_eq {motive : Nat → Sort _} (ind : ∀ n, (∀ m, m < n → motive m) → motive n) (t : Nat) : Nat.strongRec ind t = ind t fun m _ => Nat.strongRec ind m := by
conv => lhs; unfold Nat.strongRec
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor import Mathlib.CategoryTheory.Monoidal.Functor #align_import category_theory.monoidal.preadditive from "leanprover-community/mathlib"@"986c4d5761f938b2e1c43c01f001b6d9d88c2055" /-! # Preadditive monoidal categories A monoidal category is `MonoidalPreadditive` if it is preadditive and tensor product of morphisms is linear in both factors. -/ noncomputable section open scoped Classical namespace CategoryTheory open CategoryTheory.Limits open CategoryTheory.MonoidalCategory variable (C : Type*) [Category C] [Preadditive C] [MonoidalCategory C] /-- A category is `MonoidalPreadditive` if tensoring is additive in both factors. Note we don't `extend Preadditive C` here, as `Abelian C` already extends it, and we'll need to have both typeclasses sometimes. -/ class MonoidalPreadditive : Prop where whiskerLeft_zero : ∀ {X Y Z : C}, X ◁ (0 : Y ⟶ Z) = 0 := by aesop_cat zero_whiskerRight : ∀ {X Y Z : C}, (0 : Y ⟶ Z) ▷ X = 0 := by aesop_cat whiskerLeft_add : ∀ {X Y Z : C} (f g : Y ⟶ Z), X ◁ (f + g) = X ◁ f + X ◁ g := by aesop_cat add_whiskerRight : ∀ {X Y Z : C} (f g : Y ⟶ Z), (f + g) ▷ X = f ▷ X + g ▷ X := by aesop_cat #align category_theory.monoidal_preadditive CategoryTheory.MonoidalPreadditive attribute [simp] MonoidalPreadditive.whiskerLeft_zero MonoidalPreadditive.zero_whiskerRight attribute [simp] MonoidalPreadditive.whiskerLeft_add MonoidalPreadditive.add_whiskerRight variable {C} variable [MonoidalPreadditive C] namespace MonoidalPreadditive -- The priority setting will not be needed when we replace `𝟙 X ⊗ f` by `X ◁ f`. @[simp (low)] theorem tensor_zero {W X Y Z : C} (f : W ⟶ X) : f ⊗ (0 : Y ⟶ Z) = 0 := by simp [tensorHom_def] -- The priority setting will not be needed when we replace `f ⊗ 𝟙 X` by `f ▷ X`. @[simp (low)] theorem zero_tensor {W X Y Z : C} (f : Y ⟶ Z) : (0 : W ⟶ X) ⊗ f = 0 := by simp [tensorHom_def] theorem tensor_add {W X Y Z : C} (f : W ⟶ X) (g h : Y ⟶ Z) : f ⊗ (g + h) = f ⊗ g + f ⊗ h := by simp [tensorHom_def] theorem add_tensor {W X Y Z : C} (f g : W ⟶ X) (h : Y ⟶ Z) : (f + g) ⊗ h = f ⊗ h + g ⊗ h := by simp [tensorHom_def] end MonoidalPreadditive instance tensorLeft_additive (X : C) : (tensorLeft X).Additive where #align category_theory.tensor_left_additive CategoryTheory.tensorLeft_additive instance tensorRight_additive (X : C) : (tensorRight X).Additive where #align category_theory.tensor_right_additive CategoryTheory.tensorRight_additive instance tensoringLeft_additive (X : C) : ((tensoringLeft C).obj X).Additive where #align category_theory.tensoring_left_additive CategoryTheory.tensoringLeft_additive instance tensoringRight_additive (X : C) : ((tensoringRight C).obj X).Additive where #align category_theory.tensoring_right_additive CategoryTheory.tensoringRight_additive /-- A faithful additive monoidal functor to a monoidal preadditive category ensures that the domain is monoidal preadditive. -/ theorem monoidalPreadditive_of_faithful {D} [Category D] [Preadditive D] [MonoidalCategory D] (F : MonoidalFunctor D C) [F.Faithful] [F.Additive] : MonoidalPreadditive D := { whiskerLeft_zero := by intros apply F.toFunctor.map_injective simp [F.map_whiskerLeft] zero_whiskerRight := by intros apply F.toFunctor.map_injective simp [F.map_whiskerRight] whiskerLeft_add := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerLeft, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.whiskerLeft_add] add_whiskerRight := by intros apply F.toFunctor.map_injective simp only [F.map_whiskerRight, Functor.map_add, Preadditive.comp_add, Preadditive.add_comp, MonoidalPreadditive.add_whiskerRight] } #align category_theory.monoidal_preadditive_of_faithful CategoryTheory.monoidalPreadditive_of_faithful theorem whiskerLeft_sum (P : C) {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) : P ◁ ∑ j ∈ s, g j = ∑ j ∈ s, P ◁ g j := map_sum ((tensoringLeft C).obj P).mapAddHom g s theorem sum_whiskerRight {Q R : C} {J : Type*} (s : Finset J) (g : J → (Q ⟶ R)) (P : C) : (∑ j ∈ s, g j) ▷ P = ∑ j ∈ s, g j ▷ P := map_sum ((tensoringRight C).obj P).mapAddHom g s theorem tensor_sum {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (f ⊗ ∑ j ∈ s, g j) = ∑ j ∈ s, f ⊗ g j := by simp only [tensorHom_def, whiskerLeft_sum, Preadditive.comp_sum] #align category_theory.tensor_sum CategoryTheory.tensor_sum theorem sum_tensor {P Q R S : C} {J : Type*} (s : Finset J) (f : P ⟶ Q) (g : J → (R ⟶ S)) : (∑ j ∈ s, g j) ⊗ f = ∑ j ∈ s, g j ⊗ f := by simp only [tensorHom_def, sum_whiskerRight, Preadditive.sum_comp] #align category_theory.sum_tensor CategoryTheory.sum_tensor -- In a closed monoidal category, this would hold because -- `tensorLeft X` is a left adjoint and hence preserves all colimits. -- In any case it is true in any preadditive category. instance (X : C) : PreservesFiniteBiproducts (tensorLeft X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← id_tensorHom] simp only [← tensor_comp, Category.comp_id, ← tensor_sum, ← tensor_id, IsBilimit.total i]) } } instance (X : C) : PreservesFiniteBiproducts (tensorRight X) where preserves {J} := { preserves := fun {f} => { preserves := fun {b} i => isBilimitOfTotal _ (by dsimp simp_rw [← tensorHom_id] simp only [← tensor_comp, Category.comp_id, ← sum_tensor, ← tensor_id, IsBilimit.total i]) } } variable [HasFiniteBiproducts C] /-- The isomorphism showing how tensor product on the left distributes over direct sums. -/ def leftDistributor {J : Type} [Fintype J] (X : C) (f : J → C) : X ⊗ ⨁ f ≅ ⨁ fun j => X ⊗ f j := (tensorLeft X).mapBiproduct f #align category_theory.left_distributor CategoryTheory.leftDistributor
Mathlib/CategoryTheory/Monoidal/Preadditive.lean
151
158
theorem leftDistributor_hom {J : Type} [Fintype J] (X : C) (f : J → C) : (leftDistributor X f).hom = ∑ j : J, (X ◁ biproduct.π f j) ≫ biproduct.ι (fun j => X ⊗ f j) j := by
ext dsimp [leftDistributor, Functor.mapBiproduct, Functor.mapBicone] erw [biproduct.lift_π] simp only [Preadditive.sum_comp, Category.assoc, biproduct.ι_π, comp_dite, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, ite_true, eqToHom_refl, Category.comp_id]
/- Copyright (c) 2023 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Xavier Roblot -/ import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.MeasureTheory.Group.FundamentalDomain import Mathlib.MeasureTheory.Measure.Lebesgue.EqHaar import Mathlib.RingTheory.Localization.Module #align_import algebra.module.zlattice from "leanprover-community/mathlib"@"a3e83f0fa4391c8740f7d773a7a9b74e311ae2a3" /-! # ℤ-lattices Let `E` be a finite dimensional vector space over a `NormedLinearOrderedField` `K` with a solid norm that is also a `FloorRing`, e.g. `ℝ`. A (full) `ℤ`-lattice `L` of `E` is a discrete subgroup of `E` such that `L` spans `E` over `K`. A `ℤ`-lattice `L` can be defined in two ways: * For `b` a basis of `E`, then `L = Submodule.span ℤ (Set.range b)` is a ℤ-lattice of `E` * As an `AddSubgroup E` with the additional properties: * `DiscreteTopology L`, that is `L` is discrete * `Submodule.span ℝ (L : Set E) = ⊤`, that is `L` spans `E` over `K`. Results about the first point of view are in the `Zspan` namespace and results about the second point of view are in the `Zlattice` namespace. ## Main results * `Zspan.isAddFundamentalDomain`: for a ℤ-lattice `Submodule.span ℤ (Set.range b)`, proves that the set defined by `Zspan.fundamentalDomain` is a fundamental domain. * `Zlattice.module_free`: an AddSubgroup of `E` that is discrete and spans `E` over `K` is a free `ℤ`-module * `Zlattice.rank`: an AddSubgroup of `E` that is discrete and spans `E` over `K` is a free `ℤ`-module of `ℤ`-rank equal to the `K`-rank of `E` -/ noncomputable section namespace Zspan open MeasureTheory MeasurableSet Submodule Bornology variable {E ι : Type*} section NormedLatticeField variable {K : Type*} [NormedLinearOrderedField K] variable [NormedAddCommGroup E] [NormedSpace K E] variable (b : Basis ι K E) theorem span_top : span K (span ℤ (Set.range b) : Set E) = ⊤ := by simp [span_span_of_tower] /-- The fundamental domain of the ℤ-lattice spanned by `b`. See `Zspan.isAddFundamentalDomain` for the proof that it is a fundamental domain. -/ def fundamentalDomain : Set E := {m | ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1} #align zspan.fundamental_domain Zspan.fundamentalDomain @[simp] theorem mem_fundamentalDomain {m : E} : m ∈ fundamentalDomain b ↔ ∀ i, b.repr m i ∈ Set.Ico (0 : K) 1 := Iff.rfl #align zspan.mem_fundamental_domain Zspan.mem_fundamentalDomain theorem map_fundamentalDomain {F : Type*} [NormedAddCommGroup F] [NormedSpace K F] (f : E ≃ₗ[K] F) : f '' (fundamentalDomain b) = fundamentalDomain (b.map f) := by ext x rw [mem_fundamentalDomain, Basis.map_repr, LinearEquiv.trans_apply, ← mem_fundamentalDomain, show f.symm x = f.toEquiv.symm x by rfl, ← Set.mem_image_equiv] rfl @[simp] theorem fundamentalDomain_reindex {ι' : Type*} (e : ι ≃ ι') : fundamentalDomain (b.reindex e) = fundamentalDomain b := by ext simp_rw [mem_fundamentalDomain, Basis.repr_reindex_apply] rw [Equiv.forall_congr' e] simp_rw [implies_true] lemma fundamentalDomain_pi_basisFun [Fintype ι] : fundamentalDomain (Pi.basisFun ℝ ι) = Set.pi Set.univ fun _ : ι ↦ Set.Ico (0 : ℝ) 1 := by ext; simp variable [FloorRing K] section Fintype variable [Fintype ι] /-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained by rounding down its coordinates on the basis `b`. -/ def floor (m : E) : span ℤ (Set.range b) := ∑ i, ⌊b.repr m i⌋ • b.restrictScalars ℤ i #align zspan.floor Zspan.floor /-- The map that sends a vector of `E` to the element of the ℤ-lattice spanned by `b` obtained by rounding up its coordinates on the basis `b`. -/ def ceil (m : E) : span ℤ (Set.range b) := ∑ i, ⌈b.repr m i⌉ • b.restrictScalars ℤ i #align zspan.ceil Zspan.ceil @[simp] theorem repr_floor_apply (m : E) (i : ι) : b.repr (floor b m) i = ⌊b.repr m i⌋ := by classical simp only [floor, zsmul_eq_smul_cast K, b.repr.map_smul, Finsupp.single_apply, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum, Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum] #align zspan.repr_floor_apply Zspan.repr_floor_apply @[simp] theorem repr_ceil_apply (m : E) (i : ι) : b.repr (ceil b m) i = ⌈b.repr m i⌉ := by classical simp only [ceil, zsmul_eq_smul_cast K, b.repr.map_smul, Finsupp.single_apply, Finset.sum_apply', Basis.repr_self, Finsupp.smul_single', mul_one, Finset.sum_ite_eq', coe_sum, Finset.mem_univ, if_true, coe_smul_of_tower, Basis.restrictScalars_apply, map_sum] #align zspan.repr_ceil_apply Zspan.repr_ceil_apply @[simp] theorem floor_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (floor b m : E) = m := by apply b.ext_elem simp_rw [repr_floor_apply b] intro i obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i rw [← hz] exact congr_arg (Int.cast : ℤ → K) (Int.floor_intCast z) #align zspan.floor_eq_self_of_mem Zspan.floor_eq_self_of_mem @[simp] theorem ceil_eq_self_of_mem (m : E) (h : m ∈ span ℤ (Set.range b)) : (ceil b m : E) = m := by apply b.ext_elem simp_rw [repr_ceil_apply b] intro i obtain ⟨z, hz⟩ := (b.mem_span_iff_repr_mem ℤ _).mp h i rw [← hz] exact congr_arg (Int.cast : ℤ → K) (Int.ceil_intCast z) #align zspan.ceil_eq_self_of_mem Zspan.ceil_eq_self_of_mem /-- The map that sends a vector `E` to the `fundamentalDomain` of the lattice, see `Zspan.fract_mem_fundamentalDomain`, and `fractRestrict` for the map with the codomain restricted to `fundamentalDomain`. -/ def fract (m : E) : E := m - floor b m #align zspan.fract Zspan.fract theorem fract_apply (m : E) : fract b m = m - floor b m := rfl #align zspan.fract_apply Zspan.fract_apply @[simp] theorem repr_fract_apply (m : E) (i : ι) : b.repr (fract b m) i = Int.fract (b.repr m i) := by rw [fract, map_sub, Finsupp.coe_sub, Pi.sub_apply, repr_floor_apply, Int.fract] #align zspan.repr_fract_apply Zspan.repr_fract_apply @[simp] theorem fract_fract (m : E) : fract b (fract b m) = fract b m := Basis.ext_elem b fun _ => by classical simp only [repr_fract_apply, Int.fract_fract] #align zspan.fract_fract Zspan.fract_fract @[simp] theorem fract_zspan_add (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) : fract b (v + m) = fract b m := by classical refine (Basis.ext_elem_iff b).mpr fun i => ?_ simp_rw [repr_fract_apply, Int.fract_eq_fract] use (b.restrictScalars ℤ).repr ⟨v, h⟩ i rw [map_add, Finsupp.coe_add, Pi.add_apply, add_tsub_cancel_right, ← eq_intCast (algebraMap ℤ K) _, Basis.restrictScalars_repr_apply, coe_mk] #align zspan.fract_zspan_add Zspan.fract_zspan_add @[simp] theorem fract_add_zspan (m : E) {v : E} (h : v ∈ span ℤ (Set.range b)) : fract b (m + v) = fract b m := by rw [add_comm, fract_zspan_add b m h] #align zspan.fract_add_zspan Zspan.fract_add_zspan variable {b} theorem fract_eq_self {x : E} : fract b x = x ↔ x ∈ fundamentalDomain b := by classical simp only [Basis.ext_elem_iff b, repr_fract_apply, Int.fract_eq_self, mem_fundamentalDomain, Set.mem_Ico] #align zspan.fract_eq_self Zspan.fract_eq_self variable (b) theorem fract_mem_fundamentalDomain (x : E) : fract b x ∈ fundamentalDomain b := fract_eq_self.mp (fract_fract b _) #align zspan.fract_mem_fundamental_domain Zspan.fract_mem_fundamentalDomain /-- The map `fract` with codomain restricted to `fundamentalDomain`. -/ def fractRestrict (x : E) : fundamentalDomain b := ⟨fract b x, fract_mem_fundamentalDomain b x⟩ theorem fractRestrict_surjective : Function.Surjective (fractRestrict b) := fun x => ⟨↑x, Subtype.eq (fract_eq_self.mpr (Subtype.mem x))⟩ @[simp] theorem fractRestrict_apply (x : E) : (fractRestrict b x : E) = fract b x := rfl theorem fract_eq_fract (m n : E) : fract b m = fract b n ↔ -m + n ∈ span ℤ (Set.range b) := by classical rw [eq_comm, Basis.ext_elem_iff b] simp_rw [repr_fract_apply, Int.fract_eq_fract, eq_comm, Basis.mem_span_iff_repr_mem, sub_eq_neg_add, map_add, map_neg, Finsupp.coe_add, Finsupp.coe_neg, Pi.add_apply, Pi.neg_apply, ← eq_intCast (algebraMap ℤ K) _, Set.mem_range] #align zspan.fract_eq_fract Zspan.fract_eq_fract theorem norm_fract_le [HasSolidNorm K] (m : E) : ‖fract b m‖ ≤ ∑ i, ‖b i‖ := by classical calc ‖fract b m‖ = ‖∑ i, b.repr (fract b m) i • b i‖ := by rw [b.sum_repr] _ = ‖∑ i, Int.fract (b.repr m i) • b i‖ := by simp_rw [repr_fract_apply] _ ≤ ∑ i, ‖Int.fract (b.repr m i) • b i‖ := norm_sum_le _ _ _ = ∑ i, ‖Int.fract (b.repr m i)‖ * ‖b i‖ := by simp_rw [norm_smul] _ ≤ ∑ i, ‖b i‖ := Finset.sum_le_sum fun i _ => ?_ suffices ‖Int.fract ((b.repr m) i)‖ ≤ 1 by convert mul_le_mul_of_nonneg_right this (norm_nonneg _ : 0 ≤ ‖b i‖) exact (one_mul _).symm rw [(norm_one.symm : 1 = ‖(1 : K)‖)] apply norm_le_norm_of_abs_le_abs rw [abs_one, Int.abs_fract] exact le_of_lt (Int.fract_lt_one _) #align zspan.norm_fract_le Zspan.norm_fract_le section Unique variable [Unique ι] @[simp] theorem coe_floor_self (k : K) : (floor (Basis.singleton ι K) k : K) = ⌊k⌋ := Basis.ext_elem _ fun _ => by rw [repr_floor_apply, Basis.singleton_repr, Basis.singleton_repr] #align zspan.coe_floor_self Zspan.coe_floor_self @[simp] theorem coe_fract_self (k : K) : (fract (Basis.singleton ι K) k : K) = Int.fract k := Basis.ext_elem _ fun _ => by rw [repr_fract_apply, Basis.singleton_repr, Basis.singleton_repr] #align zspan.coe_fract_self Zspan.coe_fract_self end Unique end Fintype
Mathlib/Algebra/Module/Zlattice/Basic.lean
235
240
theorem fundamentalDomain_isBounded [Finite ι] [HasSolidNorm K] : IsBounded (fundamentalDomain b) := by
cases nonempty_fintype ι refine isBounded_iff_forall_norm_le.2 ⟨∑ j, ‖b j‖, fun x hx ↦ ?_⟩ rw [← fract_eq_self.mpr hx] apply norm_fract_le
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FormalMultilinearSeries #align_import analysis.calculus.cont_diff_def from "leanprover-community/mathlib"@"3a69562db5a458db8322b190ec8d9a8bbd8a5b14" /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. Finally, it is `C^∞` if it is `C^n` for all n. We formalize these notions by defining iteratively the `n+1`-th derivative of a function as the derivative of the `n`-th derivative. It is called `iteratedFDeriv 𝕜 n f x` where `𝕜` is the field, `n` is the number of iterations, `f` is the function and `x` is the point, and it is given as an `n`-multilinear map. We also define a version `iteratedFDerivWithin` relative to a domain, as well as predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `HasFTaylorSeriesUpTo n f p`: expresses that the formal multilinear series `p` is a sequence of iterated derivatives of `f`, up to the `n`-th term (where `n` is a natural number or `∞`). * `HasFTaylorSeriesUpToOn n f p s`: same thing, but inside a set `s`. The notion of derivative is now taken inside `s`. In particular, derivatives don't have to be unique. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. * `iteratedFDerivWithin 𝕜 n f s x` is an `n`-th derivative of `f` over the field `𝕜` on the set `s` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative within `s` of `iteratedFDerivWithin 𝕜 (n-1) f s` if one exists, and `0` otherwise. * `iteratedFDeriv 𝕜 n f x` is the `n`-th derivative of `f` over the field `𝕜` at the point `x`. It is a continuous multilinear map from `E^n` to `F`, defined as a derivative of `iteratedFDeriv 𝕜 (n-1) f` if one exists, and `0` otherwise. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ### Side of the composition, and universe issues With a naïve direct definition, the `n`-th derivative of a function belongs to the space `E →L[𝕜] (E →L[𝕜] (E ... F)...)))` where there are n iterations of `E →L[𝕜]`. This space may also be seen as the space of continuous multilinear functions on `n` copies of `E` with values in `F`, by uncurrying. This is the point of view that is usually adopted in textbooks, and that we also use. This means that the definition and the first proofs are slightly involved, as one has to keep track of the uncurrying operation. The uncurrying can be done from the left or from the right, amounting to defining the `n+1`-th derivative either as the derivative of the `n`-th derivative, or as the `n`-th derivative of the derivative. For proofs, it would be more convenient to use the latter approach (from the right), as it means to prove things at the `n+1`-th step we only need to understand well enough the derivative in `E →L[𝕜] F` (contrary to the approach from the left, where one would need to know enough on the `n`-th derivative to deduce things on the `n+1`-th derivative). However, the definition from the right leads to a universe polymorphism problem: if we define `iteratedFDeriv 𝕜 (n + 1) f x = iteratedFDeriv 𝕜 n (fderiv 𝕜 f) x` by induction, we need to generalize over all spaces (as `f` and `fderiv 𝕜 f` don't take values in the same space). It is only possible to generalize over all spaces in some fixed universe in an inductive definition. For `f : E → F`, then `fderiv 𝕜 f` is a map `E → (E →L[𝕜] F)`. Therefore, the definition will only work if `F` and `E →L[𝕜] F` are in the same universe. This issue does not appear with the definition from the left, where one does not need to generalize over all spaces. Therefore, we use the definition from the left. This means some proofs later on become a little bit more complicated: to prove that a function is `C^n`, the most efficient approach is to exhibit a formula for its `n`-th derivative and prove it is continuous (contrary to the inductive approach where one would prove smoothness statements without giving a formula for the derivative). In the end, this approach is still satisfactory as it is good to have formulas for the iterated derivatives in various constructions. One point where we depart from this explicit approach is in the proof of smoothness of a composition: there is a formula for the `n`-th derivative of a composition (Faà di Bruno's formula), but it is very complicated and barely usable, while the inductive proof is very simple. Thus, we give the inductive proof. As explained above, it works by generalizing over the target space, hence it only works well if all spaces belong to the same universe. To get the general version, we lift things to a common universe using a trick. ### Variables management The textbook definitions and proofs use various identifications and abuse of notations, for instance when saying that the natural space in which the derivative lives, i.e., `E →L[𝕜] (E →L[𝕜] ( ... →L[𝕜] F))`, is the same as a space of multilinear maps. When doing things formally, we need to provide explicit maps for these identifications, and chase some diagrams to see everything is compatible with the identifications. In particular, one needs to check that taking the derivative and then doing the identification, or first doing the identification and then taking the derivative, gives the same result. The key point for this is that taking the derivative commutes with continuous linear equivalences. Therefore, we need to implement all our identifications with continuous linear equivs. ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `⊤ : ℕ∞` with `∞`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open scoped Classical open NNReal Topology Filter local notation "∞" => (⊤ : ℕ∞) /- Porting note: These lines are not required in Mathlib4. attribute [local instance 1001] NormedAddCommGroup.toAddCommGroup NormedSpace.toModule' AddCommGroup.toAddCommMonoid -/ open Set Fin Filter Function universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Functions with a Taylor series on a domain -/ /-- `HasFTaylorSeriesUpToOn n f p s` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to `HasFDerivWithinAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an additional `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpToOn (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) (s : Set E) : Prop where zero_eq : ∀ x ∈ s, (p x 0).uncurry0 = f x protected fderivWithin : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x ∈ s, HasFDerivWithinAt (p · m) (p x m.succ).curryLeft s x cont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (p · m) s #align has_ftaylor_series_up_to_on HasFTaylorSeriesUpToOn theorem HasFTaylorSeriesUpToOn.zero_eq' (h : HasFTaylorSeriesUpToOn n f p s) {x : E} (hx : x ∈ s) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x hx] exact (p x 0).uncurry0_curry0.symm #align has_ftaylor_series_up_to_on.zero_eq' HasFTaylorSeriesUpToOn.zero_eq' /-- If two functions coincide on a set `s`, then a Taylor series for the first one is as well a Taylor series for the second one. -/ theorem HasFTaylorSeriesUpToOn.congr (h : HasFTaylorSeriesUpToOn n f p s) (h₁ : ∀ x ∈ s, f₁ x = f x) : HasFTaylorSeriesUpToOn n f₁ p s := by refine ⟨fun x hx => ?_, h.fderivWithin, h.cont⟩ rw [h₁ x hx] exact h.zero_eq x hx #align has_ftaylor_series_up_to_on.congr HasFTaylorSeriesUpToOn.congr theorem HasFTaylorSeriesUpToOn.mono (h : HasFTaylorSeriesUpToOn n f p s) {t : Set E} (hst : t ⊆ s) : HasFTaylorSeriesUpToOn n f p t := ⟨fun x hx => h.zero_eq x (hst hx), fun m hm x hx => (h.fderivWithin m hm x (hst hx)).mono hst, fun m hm => (h.cont m hm).mono hst⟩ #align has_ftaylor_series_up_to_on.mono HasFTaylorSeriesUpToOn.mono theorem HasFTaylorSeriesUpToOn.of_le (h : HasFTaylorSeriesUpToOn n f p s) (hmn : m ≤ n) : HasFTaylorSeriesUpToOn m f p s := ⟨h.zero_eq, fun k hk x hx => h.fderivWithin k (lt_of_lt_of_le hk hmn) x hx, fun k hk => h.cont k (le_trans hk hmn)⟩ #align has_ftaylor_series_up_to_on.of_le HasFTaylorSeriesUpToOn.of_le theorem HasFTaylorSeriesUpToOn.continuousOn (h : HasFTaylorSeriesUpToOn n f p s) : ContinuousOn f s := by have := (h.cont 0 bot_le).congr fun x hx => (h.zero_eq' hx).symm rwa [← (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_continuousOn_iff] #align has_ftaylor_series_up_to_on.continuous_on HasFTaylorSeriesUpToOn.continuousOn theorem hasFTaylorSeriesUpToOn_zero_iff : HasFTaylorSeriesUpToOn 0 f p s ↔ ContinuousOn f s ∧ ∀ x ∈ s, (p x 0).uncurry0 = f x := by refine ⟨fun H => ⟨H.continuousOn, H.zero_eq⟩, fun H => ⟨H.2, fun m hm => False.elim (not_le.2 hm bot_le), fun m hm ↦ ?_⟩⟩ obtain rfl : m = 0 := mod_cast hm.antisymm (zero_le _) have : EqOn (p · 0) ((continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f) s := fun x hx ↦ (continuousMultilinearCurryFin0 𝕜 E F).eq_symm_apply.2 (H.2 x hx) rw [continuousOn_congr this, LinearIsometryEquiv.comp_continuousOn_iff] exact H.1 #align has_ftaylor_series_up_to_on_zero_iff hasFTaylorSeriesUpToOn_zero_iff theorem hasFTaylorSeriesUpToOn_top_iff : HasFTaylorSeriesUpToOn ∞ f p s ↔ ∀ n : ℕ, HasFTaylorSeriesUpToOn n f p s := by constructor · intro H n; exact H.of_le le_top · intro H constructor · exact (H 0).zero_eq · intro m _ apply (H m.succ).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) · intro m _ apply (H m).cont m le_rfl #align has_ftaylor_series_up_to_on_top_iff hasFTaylorSeriesUpToOn_top_iff /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpToOn`. -/ theorem hasFTaylorSeriesUpToOn_top_iff' : HasFTaylorSeriesUpToOn ∞ f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ ∀ m : ℕ, ∀ x ∈ s, HasFDerivWithinAt (fun y => p y m) (p x m.succ).curryLeft s x := -- Everything except for the continuity is trivial: ⟨fun h => ⟨h.1, fun m => h.2 m (WithTop.coe_lt_top m)⟩, fun h => ⟨h.1, fun m _ => h.2 m, fun m _ x hx => -- The continuity follows from the existence of a derivative: (h.2 m x hx).continuousWithinAt⟩⟩ #align has_ftaylor_series_up_to_on_top_iff' hasFTaylorSeriesUpToOn_top_iff' /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivWithinAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : x ∈ s) : HasFDerivWithinAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x := by have A : ∀ y ∈ s, f y = (continuousMultilinearCurryFin0 𝕜 E F) (p y 0) := fun y hy ↦ (h.zero_eq y hy).symm suffices H : HasFDerivWithinAt (continuousMultilinearCurryFin0 𝕜 E F ∘ (p · 0)) (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) s x from H.congr A (A x hx) rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] have : ((0 : ℕ) : ℕ∞) < n := zero_lt_one.trans_le hn convert h.fderivWithin _ this x hx ext y v change (p x 1) (snoc 0 y) = (p x 1) (cons y v) congr with i rw [Unique.eq_default (α := Fin 1) i] rfl #align has_ftaylor_series_up_to_on.has_fderiv_within_at HasFTaylorSeriesUpToOn.hasFDerivWithinAt theorem HasFTaylorSeriesUpToOn.differentiableOn (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun _x hx => (h.hasFDerivWithinAt hn hx).differentiableWithinAt #align has_ftaylor_series_up_to_on.differentiable_on HasFTaylorSeriesUpToOn.differentiableOn /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then the term of order `1` of this series is a derivative of `f` at `x`. -/ theorem HasFTaylorSeriesUpToOn.hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := (h.hasFDerivWithinAt hn (mem_of_mem_nhds hx)).hasFDerivAt hx #align has_ftaylor_series_up_to_on.has_fderiv_at HasFTaylorSeriesUpToOn.hasFDerivAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then in a neighborhood of `x`, the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpToOn.eventually_hasFDerivAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p y 1)) y := (eventually_eventually_nhds.2 hx).mono fun _y hy => h.hasFDerivAt hn hy #align has_ftaylor_series_up_to_on.eventually_has_fderiv_at HasFTaylorSeriesUpToOn.eventually_hasFDerivAt /-- If a function has a Taylor series at order at least `1` on a neighborhood of `x`, then it is differentiable at `x`. -/ theorem HasFTaylorSeriesUpToOn.differentiableAt (h : HasFTaylorSeriesUpToOn n f p s) (hn : 1 ≤ n) (hx : s ∈ 𝓝 x) : DifferentiableAt 𝕜 f x := (h.hasFDerivAt hn hx).differentiableAt #align has_ftaylor_series_up_to_on.differentiable_at HasFTaylorSeriesUpToOn.differentiableAt /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p` is a Taylor series up to `n`, and `p (n + 1)` is a derivative of `p n`. -/ theorem hasFTaylorSeriesUpToOn_succ_iff_left {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1) f p s ↔ HasFTaylorSeriesUpToOn n f p s ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y n) (p x n.succ).curryLeft s x) ∧ ContinuousOn (fun x => p x (n + 1)) s := by constructor · exact fun h ↦ ⟨h.of_le (WithTop.coe_le_coe.2 (Nat.le_succ n)), h.fderivWithin _ (WithTop.coe_lt_coe.2 (lt_add_one n)), h.cont (n + 1) le_rfl⟩ · intro h constructor · exact h.1.zero_eq · intro m hm by_cases h' : m < n · exact h.1.fderivWithin m (WithTop.coe_lt_coe.2 h') · have : m = n := Nat.eq_of_lt_succ_of_not_lt (WithTop.coe_lt_coe.1 hm) h' rw [this] exact h.2.1 · intro m hm by_cases h' : m ≤ n · apply h.1.cont m (WithTop.coe_le_coe.2 h') · have : m = n + 1 := le_antisymm (WithTop.coe_le_coe.1 hm) (not_le.1 h') rw [this] exact h.2.2 #align has_ftaylor_series_up_to_on_succ_iff_left hasFTaylorSeriesUpToOn_succ_iff_left #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4119, without `set_option maxSynthPendingDepth 2` this proof needs substantial repair. -/ set_option maxSynthPendingDepth 2 in -- Porting note: this was split out from `hasFTaylorSeriesUpToOn_succ_iff_right` to avoid a timeout. theorem HasFTaylorSeriesUpToOn.shift_of_succ {n : ℕ} (H : HasFTaylorSeriesUpToOn (n + 1 : ℕ) f p s) : (HasFTaylorSeriesUpToOn n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) (fun x => (p x).shift)) s := by constructor · intro x _ rfl · intro m (hm : (m : ℕ∞) < n) x (hx : x ∈ s) have A : (m.succ : ℕ∞) < n.succ := by rw [Nat.cast_lt] at hm ⊢ exact Nat.succ_lt_succ hm change HasFDerivWithinAt ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm ∘ (p · m.succ)) (p x m.succ.succ).curryRight.curryLeft s x rw [((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm).comp_hasFDerivWithinAt_iff'] convert H.fderivWithin _ A x hx ext y v change p x (m + 2) (snoc (cons y (init v)) (v (last _))) = p x (m + 2) (cons y v) rw [← cons_snoc_eq_snoc_cons, snoc_init_self] · intro m (hm : (m : ℕ∞) ≤ n) suffices A : ContinuousOn (p · (m + 1)) s from ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm).continuous.comp_continuousOn A refine H.cont _ ?_ rw [Nat.cast_le] at hm ⊢ exact Nat.succ_le_succ hm /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem hasFTaylorSeriesUpToOn_succ_iff_right {n : ℕ} : HasFTaylorSeriesUpToOn (n + 1 : ℕ) f p s ↔ (∀ x ∈ s, (p x 0).uncurry0 = f x) ∧ (∀ x ∈ s, HasFDerivWithinAt (fun y => p y 0) (p x 1).curryLeft s x) ∧ HasFTaylorSeriesUpToOn n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) (fun x => (p x).shift) s := by constructor · intro H refine ⟨H.zero_eq, H.fderivWithin 0 (Nat.cast_lt.2 (Nat.succ_pos n)), ?_⟩ exact H.shift_of_succ · rintro ⟨Hzero_eq, Hfderiv_zero, Htaylor⟩ constructor · exact Hzero_eq · intro m (hm : (m : ℕ∞) < n.succ) x (hx : x ∈ s) cases' m with m · exact Hfderiv_zero x hx · have A : (m : ℕ∞) < n := by rw [Nat.cast_lt] at hm ⊢ exact Nat.lt_of_succ_lt_succ hm have : HasFDerivWithinAt ((continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm ∘ (p · m.succ)) ((p x).shift m.succ).curryLeft s x := Htaylor.fderivWithin _ A x hx rw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] at this convert this ext y v change (p x (Nat.succ (Nat.succ m))) (cons y v) = (p x m.succ.succ) (snoc (cons y (init v)) (v (last _))) rw [← cons_snoc_eq_snoc_cons, snoc_init_self] · intro m (hm : (m : ℕ∞) ≤ n.succ) cases' m with m · have : DifferentiableOn 𝕜 (fun x => p x 0) s := fun x hx => (Hfderiv_zero x hx).differentiableWithinAt exact this.continuousOn · refine (continuousMultilinearCurryRightEquiv' 𝕜 m E F).symm.comp_continuousOn_iff.mp ?_ refine Htaylor.cont _ ?_ rw [Nat.cast_le] at hm ⊢ exact Nat.lt_succ_iff.mp hm #align has_ftaylor_series_up_to_on_succ_iff_right hasFTaylorSeriesUpToOn_succ_iff_right /-! ### Smooth functions within a set around a point -/ variable (𝕜) /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := ∀ m : ℕ, (m : ℕ∞) ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u #align cont_diff_within_at ContDiffWithinAt variable {𝕜} theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le hm⟩⟩ #align cont_diff_within_at_nat contDiffWithinAt_nat theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := fun k hk => h k (le_trans hk hmn) #align cont_diff_within_at.of_le ContDiffWithinAt.of_le theorem contDiffWithinAt_iff_forall_nat_le : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _m hm => H.of_le hm, fun H m hm => H m hm _ le_rfl⟩ #align cont_diff_within_at_iff_forall_nat_le contDiffWithinAt_iff_forall_nat_le theorem contDiffWithinAt_top : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] #align cont_diff_within_at_top contDiffWithinAt_top theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by rcases h 0 bot_le with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem hu.2 #align cont_diff_within_at.continuous_within_at ContDiffWithinAt.continuousWithinAt theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := fun m hm => let ⟨u, hu, p, H⟩ := h m hm ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ => And.right⟩ #align cont_diff_within_at.congr_of_eventually_eq ContDiffWithinAt.congr_of_eventuallyEq theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ : _) #align cont_diff_within_at.congr_of_eventually_eq_insert ContDiffWithinAt.congr_of_eventuallyEq_insert theorem ContDiffWithinAt.congr_of_eventually_eq' (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx #align cont_diff_within_at.congr_of_eventually_eq' ContDiffWithinAt.congr_of_eventually_eq' theorem Filter.EventuallyEq.contDiffWithinAt_iff (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H => ContDiffWithinAt.congr_of_eventuallyEq H h₁.symm hx.symm, fun H => H.congr_of_eventuallyEq h₁ hx⟩ #align filter.eventually_eq.cont_diff_within_at_iff Filter.EventuallyEq.contDiffWithinAt_iff theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx #align cont_diff_within_at.congr ContDiffWithinAt.congr theorem ContDiffWithinAt.congr' (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) #align cont_diff_within_at.congr' ContDiffWithinAt.congr' theorem ContDiffWithinAt.mono_of_mem (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ #align cont_diff_within_at.mono_of_mem ContDiffWithinAt.mono_of_mem theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem <| Filter.mem_of_superset self_mem_nhdsWithin hst #align cont_diff_within_at.mono ContDiffWithinAt.mono theorem ContDiffWithinAt.congr_nhds (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem <| hst ▸ self_mem_nhdsWithin #align cont_diff_within_at.congr_nhds ContDiffWithinAt.congr_nhds theorem contDiffWithinAt_congr_nhds {t : Set E} (hst : 𝓝[s] x = 𝓝[t] x) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ #align cont_diff_within_at_congr_nhds contDiffWithinAt_congr_nhds theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_nhds <| Eq.symm <| nhdsWithin_restrict'' _ h #align cont_diff_within_at_inter' contDiffWithinAt_inter' theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) #align cont_diff_within_at_inter contDiffWithinAt_inter theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | h) · exact contDiffWithinAt_insert_self simp_rw [ContDiffWithinAt, insert_comm x y, nhdsWithin_insert_of_ne h] #align cont_diff_within_at_insert contDiffWithinAt_insert alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert #align cont_diff_within_at.of_insert ContDiffWithinAt.of_insert #align cont_diff_within_at.insert' ContDiffWithinAt.insert' protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' #align cont_diff_within_at.insert ContDiffWithinAt.insert /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiable_within_at' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases h 1 hn with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu have := ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 this #align cont_diff_within_at.differentiable_within_at' ContDiffWithinAt.differentiable_within_at' theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiable_within_at' hn).mono (subset_insert x s) #align cont_diff_within_at.differentiable_within_at ContDiffWithinAt.differentiableWithinAt /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt {n : ℕ} : ContDiffWithinAt 𝕜 (n + 1 : ℕ) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by constructor · intro h rcases h n.succ le_rfl with ⟨u, hu, p, Hp⟩ refine ⟨u, hu, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)) hy, ?_⟩ intro m hm refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · -- Porting note: without the explicit argument Lean is not sure of the type. convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp exact Hp.2.2.of_le hm · rintro ⟨u, hu, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_nat] rcases Hf' n le_rfl with ⟨v, hv, p', Hp'⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y -- Porting note: needed `erw` here. -- https://github.com/leanprover-community/mathlib4/issues/5164 erw [LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] #align cont_diff_within_at_succ_iff_has_fderiv_within_at contDiffWithinAt_succ_iff_hasFDerivWithinAt /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' {n : ℕ} : ContDiffWithinAt 𝕜 (n + 1 : ℕ) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f', huf', hf'⟩ := contDiffWithinAt_succ_iff_hasFDerivWithinAt.mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, f', fun y hy => ?_, ?_⟩ · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f', huf', hf'⟩ exact ⟨u, hu, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ #align cont_diff_within_at_succ_iff_has_fderiv_within_at' contDiffWithinAt_succ_iff_hasFDerivWithinAt' /-! ### Smooth functions within a set -/ variable (𝕜) /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x #align cont_diff_on ContDiffOn variable {𝕜} theorem HasFTaylorSeriesUpToOn.contDiffOn {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and_iff] exact ⟨f', hf.of_le hm⟩ #align has_ftaylor_series_up_to_on.cont_diff_on HasFTaylorSeriesUpToOn.contDiffOn theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx #align cont_diff_on.cont_diff_within_at ContDiffOn.contDiffWithinAt theorem ContDiffWithinAt.contDiffOn' {m : ℕ} (hm : (m : ℕ∞) ≤ n) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases h m hm with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ #align cont_diff_within_at.cont_diff_on' ContDiffWithinAt.contDiffOn' theorem ContDiffWithinAt.contDiffOn {m : ℕ} (hm : (m : ℕ∞) ≤ n) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := let ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ #align cont_diff_within_at.cont_diff_on ContDiffWithinAt.contDiffOn protected theorem ContDiffWithinAt.eventually {n : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_nhdsWithin_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 #align cont_diff_within_at.eventually ContDiffWithinAt.eventually theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn #align cont_diff_on.of_le ContDiffOn.of_le theorem ContDiffOn.of_succ {n : ℕ} (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le <| WithTop.coe_le_coe.mpr le_self_add #align cont_diff_on.of_succ ContDiffOn.of_succ theorem ContDiffOn.one_of_succ {n : ℕ} (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le <| WithTop.coe_le_coe.mpr le_add_self #align cont_diff_on.one_of_succ ContDiffOn.one_of_succ theorem contDiffOn_iff_forall_nat_le : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le hm, fun H x hx m hm => H m hm x hx m le_rfl⟩ #align cont_diff_on_iff_forall_nat_le contDiffOn_iff_forall_nat_le theorem contDiffOn_top : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] #align cont_diff_on_top contDiffOn_top theorem contDiffOn_all_iff_nat : (∀ n, ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_top.2 H, H n] #align cont_diff_on_all_iff_nat contDiffOn_all_iff_nat theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt #align cont_diff_on.continuous_on ContDiffOn.continuousOn theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) #align cont_diff_on.congr ContDiffOn.congr theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ #align cont_diff_on_congr contDiffOn_congr theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst #align cont_diff_on.mono ContDiffOn.mono theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ #align cont_diff_on.congr_mono ContDiffOn.congr_mono /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn #align cont_diff_on.differentiable_on ContDiffOn.differentiableOn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu #align cont_diff_on_of_locally_cont_diff_on contDiffOn_of_locally_contDiffOn /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt {n : ℕ} : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (h x hx) n.succ le_rfl with ⟨u, hu, p, Hp⟩ refine ⟨u, hu, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)) hy, ?_⟩ rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp intro z hz m hm refine ⟨u, ?_, fun x : E => (p x).shift, Hp.2.2.of_le hm⟩ -- Porting note: without the explicit arguments `convert` can not determine the type. convert @self_mem_nhdsWithin _ _ z u exact insert_eq_of_mem hz · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt] rcases h x hx with ⟨u, u_nhbd, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f', hu, hf' x this⟩ #align cont_diff_on_succ_iff_has_fderiv_within_at contDiffOn_succ_iff_hasFDerivWithinAt /-! ### Iterated derivative within a set -/ variable (𝕜) /-- The `n`-th derivative of a function along a set, defined inductively by saying that the `n+1`-th derivative of `f` is the derivative of the `n`-th derivative of `f` along this set, together with an uncurrying step to see it as a multilinear map in `n+1` variables.. -/ noncomputable def iteratedFDerivWithin (n : ℕ) (f : E → F) (s : Set E) : E → E[×n]→L[𝕜] F := Nat.recOn n (fun x => ContinuousMultilinearMap.curry0 𝕜 E (f x)) fun _ rec x => ContinuousLinearMap.uncurryLeft (fderivWithin 𝕜 rec s x) #align iterated_fderiv_within iteratedFDerivWithin /-- Formal Taylor series associated to a function within a set. -/ def ftaylorSeriesWithin (f : E → F) (s : Set E) (x : E) : FormalMultilinearSeries 𝕜 E F := fun n => iteratedFDerivWithin 𝕜 n f s x #align ftaylor_series_within ftaylorSeriesWithin variable {𝕜} @[simp] theorem iteratedFDerivWithin_zero_apply (m : Fin 0 → E) : (iteratedFDerivWithin 𝕜 0 f s x : (Fin 0 → E) → F) m = f x := rfl #align iterated_fderiv_within_zero_apply iteratedFDerivWithin_zero_apply theorem iteratedFDerivWithin_zero_eq_comp : iteratedFDerivWithin 𝕜 0 f s = (continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f := rfl #align iterated_fderiv_within_zero_eq_comp iteratedFDerivWithin_zero_eq_comp @[simp] theorem norm_iteratedFDerivWithin_zero : ‖iteratedFDerivWithin 𝕜 0 f s x‖ = ‖f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_zero_eq_comp, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_within_zero norm_iteratedFDerivWithin_zero theorem iteratedFDerivWithin_succ_apply_left {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDerivWithin 𝕜 (n + 1) f s x : (Fin (n + 1) → E) → F) m = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s x : E → E[×n]→L[𝕜] F) (m 0) (tail m) := rfl #align iterated_fderiv_within_succ_apply_left iteratedFDerivWithin_succ_apply_left /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ theorem iteratedFDerivWithin_succ_eq_comp_left {n : ℕ} : iteratedFDerivWithin 𝕜 (n + 1) f s = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F : (E →L[𝕜] (E [×n]→L[𝕜] F)) → (E [×n.succ]→L[𝕜] F)) ∘ fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s := rfl #align iterated_fderiv_within_succ_eq_comp_left iteratedFDerivWithin_succ_eq_comp_left theorem fderivWithin_iteratedFDerivWithin {s : Set E} {n : ℕ} : fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F).symm ∘ iteratedFDerivWithin 𝕜 (n + 1) f s := by rw [iteratedFDerivWithin_succ_eq_comp_left] ext1 x simp only [Function.comp_apply, LinearIsometryEquiv.symm_apply_apply] theorem norm_fderivWithin_iteratedFDerivWithin {n : ℕ} : ‖fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n + 1) f s x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_succ_eq_comp_left, comp_apply, LinearIsometryEquiv.norm_map] #align norm_fderiv_within_iterated_fderiv_within norm_fderivWithin_iteratedFDerivWithin theorem iteratedFDerivWithin_succ_apply_right {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) (m : Fin (n + 1) → E) : (iteratedFDerivWithin 𝕜 (n + 1) f s x : (Fin (n + 1) → E) → F) m = iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s x (init m) (m (last n)) := by induction' n with n IH generalizing x · rw [iteratedFDerivWithin_succ_eq_comp_left, iteratedFDerivWithin_zero_eq_comp, iteratedFDerivWithin_zero_apply, Function.comp_apply, LinearIsometryEquiv.comp_fderivWithin _ (hs x hx)] rfl · let I := continuousMultilinearCurryRightEquiv' 𝕜 n E F have A : ∀ y ∈ s, iteratedFDerivWithin 𝕜 n.succ f s y = (I ∘ iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) y := fun y hy ↦ by ext m rw [@IH y hy m] rfl calc (iteratedFDerivWithin 𝕜 (n + 2) f s x : (Fin (n + 2) → E) → F) m = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n.succ f s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := rfl _ = (fderivWithin 𝕜 (I ∘ iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := by rw [fderivWithin_congr A (A x hx)] _ = (I ∘ fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) s x : E → E[×n + 1]→L[𝕜] F) (m 0) (tail m) := by #adaptation_note /-- After https://github.com/leanprover/lean4/pull/4119 we need to either use `set_option maxSynthPendingDepth 2 in` or fill in an explicit argument as ``` simp only [LinearIsometryEquiv.comp_fderivWithin _ (f := iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s) (hs x hx)] ``` -/ set_option maxSynthPendingDepth 2 in simp only [LinearIsometryEquiv.comp_fderivWithin _ (hs x hx)] rfl _ = (fderivWithin 𝕜 (iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) s x : E → E[×n]→L[𝕜] E →L[𝕜] F) (m 0) (init (tail m)) ((tail m) (last n)) := rfl _ = iteratedFDerivWithin 𝕜 (Nat.succ n) (fun y => fderivWithin 𝕜 f s y) s x (init m) (m (last (n + 1))) := by rw [iteratedFDerivWithin_succ_apply_left, tail_init_eq_init_tail] rfl #align iterated_fderiv_within_succ_apply_right iteratedFDerivWithin_succ_apply_right /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the `n`-th derivative of the derivative. -/ theorem iteratedFDerivWithin_succ_eq_comp_right {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 (n + 1) f s x = (continuousMultilinearCurryRightEquiv' 𝕜 n E F ∘ iteratedFDerivWithin 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) x := by ext m; rw [iteratedFDerivWithin_succ_apply_right hs hx]; rfl #align iterated_fderiv_within_succ_eq_comp_right iteratedFDerivWithin_succ_eq_comp_right theorem norm_iteratedFDerivWithin_fderivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : ‖iteratedFDerivWithin 𝕜 n (fderivWithin 𝕜 f s) s x‖ = ‖iteratedFDerivWithin 𝕜 (n + 1) f s x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_within_fderiv_within norm_iteratedFDerivWithin_fderivWithin @[simp] theorem iteratedFDerivWithin_one_apply (h : UniqueDiffWithinAt 𝕜 s x) (m : Fin 1 → E) : iteratedFDerivWithin 𝕜 1 f s x m = fderivWithin 𝕜 f s x (m 0) := by simp only [iteratedFDerivWithin_succ_apply_left, iteratedFDerivWithin_zero_eq_comp, (continuousMultilinearCurryFin0 𝕜 E F).symm.comp_fderivWithin h] rfl #align iterated_fderiv_within_one_apply iteratedFDerivWithin_one_apply /-- On a set of unique differentiability, the second derivative is obtained by taking the derivative of the derivative. -/ lemma iteratedFDerivWithin_two_apply (f : E → F) {z : E} (hs : UniqueDiffOn 𝕜 s) (hz : z ∈ s) (m : Fin 2 → E) : iteratedFDerivWithin 𝕜 2 f s z m = fderivWithin 𝕜 (fderivWithin 𝕜 f s) s z (m 0) (m 1) := by simp only [iteratedFDerivWithin_succ_apply_right hs hz] rfl theorem Filter.EventuallyEq.iteratedFDerivWithin' (h : f₁ =ᶠ[𝓝[s] x] f) (ht : t ⊆ s) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ t =ᶠ[𝓝[s] x] iteratedFDerivWithin 𝕜 n f t := by induction' n with n ihn · exact h.mono fun y hy => DFunLike.ext _ _ fun _ => hy · have : fderivWithin 𝕜 _ t =ᶠ[𝓝[s] x] fderivWithin 𝕜 _ t := ihn.fderivWithin' ht apply this.mono intro y hy simp only [iteratedFDerivWithin_succ_eq_comp_left, hy, (· ∘ ·)] #align filter.eventually_eq.iterated_fderiv_within' Filter.EventuallyEq.iteratedFDerivWithin' protected theorem Filter.EventuallyEq.iteratedFDerivWithin (h : f₁ =ᶠ[𝓝[s] x] f) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s =ᶠ[𝓝[s] x] iteratedFDerivWithin 𝕜 n f s := h.iteratedFDerivWithin' Subset.rfl n #align filter.eventually_eq.iterated_fderiv_within Filter.EventuallyEq.iteratedFDerivWithin /-- If two functions coincide in a neighborhood of `x` within a set `s` and at `x`, then their iterated differentials within this set at `x` coincide. -/ theorem Filter.EventuallyEq.iteratedFDerivWithin_eq (h : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s x = iteratedFDerivWithin 𝕜 n f s x := have : f₁ =ᶠ[𝓝[insert x s] x] f := by simpa [EventuallyEq, hx] (this.iteratedFDerivWithin' (subset_insert _ _) n).self_of_nhdsWithin (mem_insert _ _) #align filter.eventually_eq.iterated_fderiv_within_eq Filter.EventuallyEq.iteratedFDerivWithin_eq /-- If two functions coincide on a set `s`, then their iterated differentials within this set coincide. See also `Filter.EventuallyEq.iteratedFDerivWithin_eq` and `Filter.EventuallyEq.iteratedFDerivWithin`. -/ theorem iteratedFDerivWithin_congr (hs : EqOn f₁ f s) (hx : x ∈ s) (n : ℕ) : iteratedFDerivWithin 𝕜 n f₁ s x = iteratedFDerivWithin 𝕜 n f s x := (hs.eventuallyEq.filter_mono inf_le_right).iteratedFDerivWithin_eq (hs hx) _ #align iterated_fderiv_within_congr iteratedFDerivWithin_congr /-- If two functions coincide on a set `s`, then their iterated differentials within this set coincide. See also `Filter.EventuallyEq.iteratedFDerivWithin_eq` and `Filter.EventuallyEq.iteratedFDerivWithin`. -/ protected theorem Set.EqOn.iteratedFDerivWithin (hs : EqOn f₁ f s) (n : ℕ) : EqOn (iteratedFDerivWithin 𝕜 n f₁ s) (iteratedFDerivWithin 𝕜 n f s) s := fun _x hx => iteratedFDerivWithin_congr hs hx n #align set.eq_on.iterated_fderiv_within Set.EqOn.iteratedFDerivWithin theorem iteratedFDerivWithin_eventually_congr_set' (y : E) (h : s =ᶠ[𝓝[{y}ᶜ] x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 n f t := by induction' n with n ihn generalizing x · rfl · refine (eventually_nhds_nhdsWithin.2 h).mono fun y hy => ?_ simp only [iteratedFDerivWithin_succ_eq_comp_left, (· ∘ ·)] rw [(ihn hy).fderivWithin_eq_nhds, fderivWithin_congr_set' _ hy] #align iterated_fderiv_within_eventually_congr_set' iteratedFDerivWithin_eventually_congr_set' theorem iteratedFDerivWithin_eventually_congr_set (h : s =ᶠ[𝓝 x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 n f t := iteratedFDerivWithin_eventually_congr_set' x (h.filter_mono inf_le_left) n #align iterated_fderiv_within_eventually_congr_set iteratedFDerivWithin_eventually_congr_set theorem iteratedFDerivWithin_congr_set (h : s =ᶠ[𝓝 x] t) (n : ℕ) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (iteratedFDerivWithin_eventually_congr_set h n).self_of_nhds #align iterated_fderiv_within_congr_set iteratedFDerivWithin_congr_set /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x` within `s`. -/ theorem iteratedFDerivWithin_inter' {n : ℕ} (hu : u ∈ 𝓝[s] x) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_congr_set (nhdsWithin_eq_iff_eventuallyEq.1 <| nhdsWithin_inter_of_mem' hu) _ #align iterated_fderiv_within_inter' iteratedFDerivWithin_inter' /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with a neighborhood of `x`. -/ theorem iteratedFDerivWithin_inter {n : ℕ} (hu : u ∈ 𝓝 x) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_inter' (mem_nhdsWithin_of_mem_nhds hu) #align iterated_fderiv_within_inter iteratedFDerivWithin_inter /-- The iterated differential within a set `s` at a point `x` is not modified if one intersects `s` with an open set containing `x`. -/ theorem iteratedFDerivWithin_inter_open {n : ℕ} (hu : IsOpen u) (hx : x ∈ u) : iteratedFDerivWithin 𝕜 n f (s ∩ u) x = iteratedFDerivWithin 𝕜 n f s x := iteratedFDerivWithin_inter (hu.mem_nhds hx) #align iterated_fderiv_within_inter_open iteratedFDerivWithin_inter_open @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => ?_⟩ intro x hx m hm have : (m : ℕ∞) = 0 := le_antisymm hm bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ #align cont_diff_on_zero contDiffOn_zero theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟨u, H, p, hp⟩ := h 0 le_rfl refine ⟨u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟨u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' #align cont_diff_within_at_zero contDiffWithinAt_zero /-- On a set with unique differentiability, any choice of iterated differential has to coincide with the one we have chosen in `iteratedFDerivWithin 𝕜 m f s`. -/ theorem HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn (h : HasFTaylorSeriesUpToOn n f p s) {m : ℕ} (hmn : (m : ℕ∞) ≤ n) (hs : UniqueDiffOn 𝕜 s) (hx : x ∈ s) : p x m = iteratedFDerivWithin 𝕜 m f s x := by induction' m with m IH generalizing x · rw [h.zero_eq' hx, iteratedFDerivWithin_zero_eq_comp]; rfl · have A : (m : ℕ∞) < n := lt_of_lt_of_le (WithTop.coe_lt_coe.2 (lt_add_one m)) hmn have : HasFDerivWithinAt (fun y : E => iteratedFDerivWithin 𝕜 m f s y) (ContinuousMultilinearMap.curryLeft (p x (Nat.succ m))) s x := (h.fderivWithin m A x hx).congr (fun y hy => (IH (le_of_lt A) hy).symm) (IH (le_of_lt A) hx).symm rw [iteratedFDerivWithin_succ_eq_comp_left, Function.comp_apply, this.fderivWithin (hs x hx)] exact (ContinuousMultilinearMap.uncurry_curryLeft _).symm #align has_ftaylor_series_up_to_on.eq_ftaylor_series_of_unique_diff_on HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn @[deprecated] alias HasFTaylorSeriesUpToOn.eq_ftaylor_series_of_uniqueDiffOn := HasFTaylorSeriesUpToOn.eq_iteratedFDerivWithin_of_uniqueDiffOn -- 2024-03-28 /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.uncurry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx rcases (h x hx) m.succ (ENat.add_one_le_of_lt hm) with ⟨u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (WithTop.coe_le_coe.2 (Nat.le_succ m)) (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (WithTop.coe_lt_coe.2 (lt_add_one m)) x ⟨hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases h x hx m hm with ⟨u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟨o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm #align cont_diff_on.ftaylor_series_within ContDiffOn.ftaylorSeriesWithin theorem contDiffOn_of_continuousOn_differentiableOn (Hcont : ∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.uncurry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le hk hm) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans hk hm) #align cont_diff_on_of_continuous_on_differentiable_on contDiffOn_of_continuousOn_differentiableOn theorem contDiffOn_of_differentiableOn (h : ∀ m : ℕ, (m : ℕ∞) ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) #align cont_diff_on_of_differentiable_on contDiffOn_of_differentiableOn theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := (h.ftaylorSeriesWithin hs).cont m hmn #align cont_diff_on.continuous_on_iterated_fderiv_within ContDiffOn.continuousOn_iteratedFDerivWithin theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := fun x hx => ((h.ftaylorSeriesWithin hs).fderivWithin m hmn x hx).differentiableWithinAt #align cont_diff_on.differentiable_on_iterated_fderiv_within ContDiffOn.differentiableOn_iteratedFDerivWithin theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : (m : ℕ∞) < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by rcases h.contDiffOn' (ENat.add_one_le_of_lt hmn) with ⟨u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =ᶠ[𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟨mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds #align cont_diff_within_at.differentiable_within_at_iterated_fderiv_within ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin theorem contDiffOn_iff_continuousOn_differentiableOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, (m : ℕ∞) ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, (m : ℕ∞) < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin hm hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin hm hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ #align cont_diff_on_iff_continuous_on_differentiable_on contDiffOn_iff_continuousOn_differentiableOn theorem contDiffOn_succ_of_fderivWithin {n : ℕ} (hf : DifferentiableOn 𝕜 f s) (h : ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s := by intro x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt, insert_eq_of_mem hx] exact ⟨s, self_mem_nhdsWithin, fderivWithin 𝕜 f s, fun y hy => (hf y hy).hasFDerivWithinAt, h x hx⟩ #align cont_diff_on_succ_of_fderiv_within contDiffOn_succ_of_fderivWithin /-- A function is `C^(n + 1)` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 n (fun y => fderivWithin 𝕜 f s y) s := by refine ⟨fun H => ?_, fun h => contDiffOn_succ_of_fderivWithin h.1 h.2⟩ refine ⟨H.differentiableOn (WithTop.coe_le_coe.2 (Nat.le_add_left 1 n)), fun x hx => ?_⟩ rcases contDiffWithinAt_succ_iff_hasFDerivWithinAt.1 (H x hx) with ⟨u, hu, f', hff', hf'⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm, insert_eq_of_mem hx] at ho have := hf'.mono ho rw [contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds o_open xo))] at this apply this.congr_of_eventually_eq' _ hx have : o ∩ s ∈ 𝓝[s] x := mem_nhdsWithin.2 ⟨o, o_open, xo, Subset.refl _⟩ rw [inter_comm] at this refine Filter.eventuallyEq_of_mem this fun y hy => ?_ have A : fderivWithin 𝕜 f (s ∩ o) y = f' y := ((hff' y (ho hy)).mono ho).fderivWithin (hs.inter o_open y hy) rwa [fderivWithin_inter (o_open.mem_nhds hy.2)] at A #align cont_diff_on_succ_iff_fderiv_within contDiffOn_succ_iff_fderivWithin theorem contDiffOn_succ_iff_hasFDerivWithin {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ ∃ f' : E → E →L[𝕜] F, ContDiffOn 𝕜 n f' s ∧ ∀ x, x ∈ s → HasFDerivWithinAt f (f' x) s x := by rw [contDiffOn_succ_iff_fderivWithin hs] refine ⟨fun h => ⟨fderivWithin 𝕜 f s, h.2, fun x hx => (h.1 x hx).hasFDerivWithinAt⟩, fun h => ?_⟩ rcases h with ⟨f', h1, h2⟩ refine ⟨fun x hx => (h2 x hx).differentiableWithinAt, fun x hx => ?_⟩ exact (h1 x hx).congr' (fun y hy => (h2 y hy).fderivWithin (hs y hy)) hx #align cont_diff_on_succ_iff_has_fderiv_within contDiffOn_succ_iff_hasFDerivWithin /-- A function is `C^(n + 1)` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^n`. -/ theorem contDiffOn_succ_iff_fderiv_of_isOpen {n : ℕ} (hs : IsOpen s) : ContDiffOn 𝕜 (n + 1 : ℕ) f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 n (fun y => fderiv 𝕜 f y) s := by rw [contDiffOn_succ_iff_fderivWithin hs.uniqueDiffOn] exact Iff.rfl.and (contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx) #align cont_diff_on_succ_iff_fderiv_of_open contDiffOn_succ_iff_fderiv_of_isOpen /-- A function is `C^∞` on a domain with unique derivatives if and only if it is differentiable there, and its derivative (expressed with `fderivWithin`) is `C^∞`. -/ theorem contDiffOn_top_iff_fderivWithin (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fun y => fderivWithin 𝕜 f s y) s := by constructor · intro h refine ⟨h.differentiableOn le_top, ?_⟩ refine contDiffOn_top.2 fun n => ((contDiffOn_succ_iff_fderivWithin hs).1 ?_).2 exact h.of_le le_top · intro h refine contDiffOn_top.2 fun n => ?_ have A : (n : ℕ∞) ≤ ∞ := le_top apply ((contDiffOn_succ_iff_fderivWithin hs).2 ⟨h.1, h.2.of_le A⟩).of_le exact WithTop.coe_le_coe.2 (Nat.le_succ n) #align cont_diff_on_top_iff_fderiv_within contDiffOn_top_iff_fderivWithin /-- A function is `C^∞` on an open domain if and only if it is differentiable there, and its derivative (expressed with `fderiv`) is `C^∞`. -/ theorem contDiffOn_top_iff_fderiv_of_isOpen (hs : IsOpen s) : ContDiffOn 𝕜 ∞ f s ↔ DifferentiableOn 𝕜 f s ∧ ContDiffOn 𝕜 ∞ (fun y => fderiv 𝕜 f y) s := by rw [contDiffOn_top_iff_fderivWithin hs.uniqueDiffOn] exact Iff.rfl.and <| contDiffOn_congr fun x hx ↦ fderivWithin_of_isOpen hs hx #align cont_diff_on_top_iff_fderiv_of_open contDiffOn_top_iff_fderiv_of_isOpen protected theorem ContDiffOn.fderivWithin (hf : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fun y => fderivWithin 𝕜 f s y) s := by cases' m with m · change ∞ + 1 ≤ n at hmn have : n = ∞ := by simpa using hmn rw [this] at hf exact ((contDiffOn_top_iff_fderivWithin hs).1 hf).2 · change (m.succ : ℕ∞) ≤ n at hmn exact ((contDiffOn_succ_iff_fderivWithin hs).1 (hf.of_le hmn)).2 #align cont_diff_on.fderiv_within ContDiffOn.fderivWithin theorem ContDiffOn.fderiv_of_isOpen (hf : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hmn : m + 1 ≤ n) : ContDiffOn 𝕜 m (fun y => fderiv 𝕜 f y) s := (hf.fderivWithin hs.uniqueDiffOn hmn).congr fun _ hx => (fderivWithin_of_isOpen hs hx).symm #align cont_diff_on.fderiv_of_open ContDiffOn.fderiv_of_isOpen theorem ContDiffOn.continuousOn_fderivWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) (hn : 1 ≤ n) : ContinuousOn (fun x => fderivWithin 𝕜 f s x) s := ((contDiffOn_succ_iff_fderivWithin hs).1 (h.of_le hn)).2.continuousOn #align cont_diff_on.continuous_on_fderiv_within ContDiffOn.continuousOn_fderivWithin theorem ContDiffOn.continuousOn_fderiv_of_isOpen (h : ContDiffOn 𝕜 n f s) (hs : IsOpen s) (hn : 1 ≤ n) : ContinuousOn (fun x => fderiv 𝕜 f x) s := ((contDiffOn_succ_iff_fderiv_of_isOpen hs).1 (h.of_le hn)).2.continuousOn #align cont_diff_on.continuous_on_fderiv_of_open ContDiffOn.continuousOn_fderiv_of_isOpen /-! ### Functions with a Taylor series on the whole space -/ /-- `HasFTaylorSeriesUpTo n f p` registers the fact that `p 0 = f` and `p (m+1)` is a derivative of `p m` for `m < n`, and is continuous for `m ≤ n`. This is a predicate analogous to `HasFDerivAt` but for higher order derivatives. Notice that `p` does not sum up to `f` on the diagonal (`FormalMultilinearSeries.sum`), even if `f` is analytic and `n = ∞`: an addition `1/m!` factor on the `m`th term is necessary for that. -/ structure HasFTaylorSeriesUpTo (n : ℕ∞) (f : E → F) (p : E → FormalMultilinearSeries 𝕜 E F) : Prop where zero_eq : ∀ x, (p x 0).uncurry0 = f x fderiv : ∀ m : ℕ, (m : ℕ∞) < n → ∀ x, HasFDerivAt (fun y => p y m) (p x m.succ).curryLeft x cont : ∀ m : ℕ, (m : ℕ∞) ≤ n → Continuous fun x => p x m #align has_ftaylor_series_up_to HasFTaylorSeriesUpTo theorem HasFTaylorSeriesUpTo.zero_eq' (h : HasFTaylorSeriesUpTo n f p) (x : E) : p x 0 = (continuousMultilinearCurryFin0 𝕜 E F).symm (f x) := by rw [← h.zero_eq x] exact (p x 0).uncurry0_curry0.symm #align has_ftaylor_series_up_to.zero_eq' HasFTaylorSeriesUpTo.zero_eq' theorem hasFTaylorSeriesUpToOn_univ_iff : HasFTaylorSeriesUpToOn n f p univ ↔ HasFTaylorSeriesUpTo n f p := by constructor · intro H constructor · exact fun x => H.zero_eq x (mem_univ x) · intro m hm x rw [← hasFDerivWithinAt_univ] exact H.fderivWithin m hm x (mem_univ x) · intro m hm rw [continuous_iff_continuousOn_univ] exact H.cont m hm · intro H constructor · exact fun x _ => H.zero_eq x · intro m hm x _ rw [hasFDerivWithinAt_univ] exact H.fderiv m hm x · intro m hm rw [← continuous_iff_continuousOn_univ] exact H.cont m hm #align has_ftaylor_series_up_to_on_univ_iff hasFTaylorSeriesUpToOn_univ_iff theorem HasFTaylorSeriesUpTo.hasFTaylorSeriesUpToOn (h : HasFTaylorSeriesUpTo n f p) (s : Set E) : HasFTaylorSeriesUpToOn n f p s := (hasFTaylorSeriesUpToOn_univ_iff.2 h).mono (subset_univ _) #align has_ftaylor_series_up_to.has_ftaylor_series_up_to_on HasFTaylorSeriesUpTo.hasFTaylorSeriesUpToOn theorem HasFTaylorSeriesUpTo.ofLe (h : HasFTaylorSeriesUpTo n f p) (hmn : m ≤ n) : HasFTaylorSeriesUpTo m f p := by rw [← hasFTaylorSeriesUpToOn_univ_iff] at h ⊢; exact h.of_le hmn #align has_ftaylor_series_up_to.of_le HasFTaylorSeriesUpTo.ofLe theorem HasFTaylorSeriesUpTo.continuous (h : HasFTaylorSeriesUpTo n f p) : Continuous f := by rw [← hasFTaylorSeriesUpToOn_univ_iff] at h rw [continuous_iff_continuousOn_univ] exact h.continuousOn #align has_ftaylor_series_up_to.continuous HasFTaylorSeriesUpTo.continuous theorem hasFTaylorSeriesUpTo_zero_iff : HasFTaylorSeriesUpTo 0 f p ↔ Continuous f ∧ ∀ x, (p x 0).uncurry0 = f x := by simp [hasFTaylorSeriesUpToOn_univ_iff.symm, continuous_iff_continuousOn_univ, hasFTaylorSeriesUpToOn_zero_iff] #align has_ftaylor_series_up_to_zero_iff hasFTaylorSeriesUpTo_zero_iff theorem hasFTaylorSeriesUpTo_top_iff : HasFTaylorSeriesUpTo ∞ f p ↔ ∀ n : ℕ, HasFTaylorSeriesUpTo n f p := by simp only [← hasFTaylorSeriesUpToOn_univ_iff, hasFTaylorSeriesUpToOn_top_iff] #align has_ftaylor_series_up_to_top_iff hasFTaylorSeriesUpTo_top_iff /-- In the case that `n = ∞` we don't need the continuity assumption in `HasFTaylorSeriesUpTo`. -/ theorem hasFTaylorSeriesUpTo_top_iff' : HasFTaylorSeriesUpTo ∞ f p ↔ (∀ x, (p x 0).uncurry0 = f x) ∧ ∀ (m : ℕ) (x), HasFDerivAt (fun y => p y m) (p x m.succ).curryLeft x := by simp only [← hasFTaylorSeriesUpToOn_univ_iff, hasFTaylorSeriesUpToOn_top_iff', mem_univ, forall_true_left, hasFDerivWithinAt_univ] #align has_ftaylor_series_up_to_top_iff' hasFTaylorSeriesUpTo_top_iff' /-- If a function has a Taylor series at order at least `1`, then the term of order `1` of this series is a derivative of `f`. -/ theorem HasFTaylorSeriesUpTo.hasFDerivAt (h : HasFTaylorSeriesUpTo n f p) (hn : 1 ≤ n) (x : E) : HasFDerivAt f (continuousMultilinearCurryFin1 𝕜 E F (p x 1)) x := by rw [← hasFDerivWithinAt_univ] exact (hasFTaylorSeriesUpToOn_univ_iff.2 h).hasFDerivWithinAt hn (mem_univ _) #align has_ftaylor_series_up_to.has_fderiv_at HasFTaylorSeriesUpTo.hasFDerivAt theorem HasFTaylorSeriesUpTo.differentiable (h : HasFTaylorSeriesUpTo n f p) (hn : 1 ≤ n) : Differentiable 𝕜 f := fun x => (h.hasFDerivAt hn x).differentiableAt #align has_ftaylor_series_up_to.differentiable HasFTaylorSeriesUpTo.differentiable /-- `p` is a Taylor series of `f` up to `n+1` if and only if `p.shift` is a Taylor series up to `n` for `p 1`, which is a derivative of `f`. -/ theorem hasFTaylorSeriesUpTo_succ_iff_right {n : ℕ} : HasFTaylorSeriesUpTo (n + 1 : ℕ) f p ↔ (∀ x, (p x 0).uncurry0 = f x) ∧ (∀ x, HasFDerivAt (fun y => p y 0) (p x 1).curryLeft x) ∧ HasFTaylorSeriesUpTo n (fun x => continuousMultilinearCurryFin1 𝕜 E F (p x 1)) fun x => (p x).shift := by simp only [hasFTaylorSeriesUpToOn_succ_iff_right, ← hasFTaylorSeriesUpToOn_univ_iff, mem_univ, forall_true_left, hasFDerivWithinAt_univ] #align has_ftaylor_series_up_to_succ_iff_right hasFTaylorSeriesUpTo_succ_iff_right /-! ### Smooth functions at a point -/ variable (𝕜) /-- A function is continuously differentiable up to `n` at a point `x` if, for any integer `k ≤ n`, there is a neighborhood of `x` where `f` admits derivatives up to order `n`, which are continuous. -/ def ContDiffAt (n : ℕ∞) (f : E → F) (x : E) : Prop := ContDiffWithinAt 𝕜 n f univ x #align cont_diff_at ContDiffAt variable {𝕜} theorem contDiffWithinAt_univ : ContDiffWithinAt 𝕜 n f univ x ↔ ContDiffAt 𝕜 n f x := Iff.rfl #align cont_diff_within_at_univ contDiffWithinAt_univ theorem contDiffAt_top : ContDiffAt 𝕜 ∞ f x ↔ ∀ n : ℕ, ContDiffAt 𝕜 n f x := by simp [← contDiffWithinAt_univ, contDiffWithinAt_top] #align cont_diff_at_top contDiffAt_top theorem ContDiffAt.contDiffWithinAt (h : ContDiffAt 𝕜 n f x) : ContDiffWithinAt 𝕜 n f s x := h.mono (subset_univ _) #align cont_diff_at.cont_diff_within_at ContDiffAt.contDiffWithinAt theorem ContDiffWithinAt.contDiffAt (h : ContDiffWithinAt 𝕜 n f s x) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := by rwa [ContDiffAt, ← contDiffWithinAt_inter hx, univ_inter] #align cont_diff_within_at.cont_diff_at ContDiffWithinAt.contDiffAt -- Porting note (#10756): new lemma theorem ContDiffOn.contDiffAt (h : ContDiffOn 𝕜 n f s) (hx : s ∈ 𝓝 x) : ContDiffAt 𝕜 n f x := (h _ (mem_of_mem_nhds hx)).contDiffAt hx theorem ContDiffAt.congr_of_eventuallyEq (h : ContDiffAt 𝕜 n f x) (hg : f₁ =ᶠ[𝓝 x] f) : ContDiffAt 𝕜 n f₁ x := h.congr_of_eventually_eq' (by rwa [nhdsWithin_univ]) (mem_univ x) #align cont_diff_at.congr_of_eventually_eq ContDiffAt.congr_of_eventuallyEq theorem ContDiffAt.of_le (h : ContDiffAt 𝕜 n f x) (hmn : m ≤ n) : ContDiffAt 𝕜 m f x := ContDiffWithinAt.of_le h hmn #align cont_diff_at.of_le ContDiffAt.of_le theorem ContDiffAt.continuousAt (h : ContDiffAt 𝕜 n f x) : ContinuousAt f x := by simpa [continuousWithinAt_univ] using h.continuousWithinAt #align cont_diff_at.continuous_at ContDiffAt.continuousAt /-- If a function is `C^n` with `n ≥ 1` at a point, then it is differentiable there. -/ theorem ContDiffAt.differentiableAt (h : ContDiffAt 𝕜 n f x) (hn : 1 ≤ n) : DifferentiableAt 𝕜 f x := by simpa [hn, differentiableWithinAt_univ] using h.differentiableWithinAt #align cont_diff_at.differentiable_at ContDiffAt.differentiableAt nonrec lemma ContDiffAt.contDiffOn {m : ℕ} (h : ContDiffAt 𝕜 n f x) (hm : m ≤ n) : ∃ u ∈ 𝓝 x, ContDiffOn 𝕜 m f u := by simpa [nhdsWithin_univ] using h.contDiffOn hm /-- A function is `C^(n + 1)` at a point iff locally, it has a derivative which is `C^n`. -/ theorem contDiffAt_succ_iff_hasFDerivAt {n : ℕ} : ContDiffAt 𝕜 (n + 1 : ℕ) f x ↔ ∃ f' : E → E →L[𝕜] F, (∃ u ∈ 𝓝 x, ∀ x ∈ u, HasFDerivAt f (f' x) x) ∧ ContDiffAt 𝕜 n f' x := by rw [← contDiffWithinAt_univ, contDiffWithinAt_succ_iff_hasFDerivWithinAt] simp only [nhdsWithin_univ, exists_prop, mem_univ, insert_eq_of_mem] constructor · rintro ⟨u, H, f', h_fderiv, h_cont_diff⟩ rcases mem_nhds_iff.mp H with ⟨t, htu, ht, hxt⟩ refine ⟨f', ⟨t, ?_⟩, h_cont_diff.contDiffAt H⟩ refine ⟨mem_nhds_iff.mpr ⟨t, Subset.rfl, ht, hxt⟩, ?_⟩ intro y hyt refine (h_fderiv y (htu hyt)).hasFDerivAt ?_ exact mem_nhds_iff.mpr ⟨t, htu, ht, hyt⟩ · rintro ⟨f', ⟨u, H, h_fderiv⟩, h_cont_diff⟩ refine ⟨u, H, f', ?_, h_cont_diff.contDiffWithinAt⟩ intro x hxu exact (h_fderiv x hxu).hasFDerivWithinAt #align cont_diff_at_succ_iff_has_fderiv_at contDiffAt_succ_iff_hasFDerivAt protected theorem ContDiffAt.eventually {n : ℕ} (h : ContDiffAt 𝕜 n f x) : ∀ᶠ y in 𝓝 x, ContDiffAt 𝕜 n f y := by simpa [nhdsWithin_univ] using ContDiffWithinAt.eventually h #align cont_diff_at.eventually ContDiffAt.eventually /-! ### Smooth functions -/ variable (𝕜) /-- A function is continuously differentiable up to `n` if it admits derivatives up to order `n`, which are continuous. Contrary to the case of definitions in domains (where derivatives might not be unique) we do not need to localize the definition in space or time. -/ def ContDiff (n : ℕ∞) (f : E → F) : Prop := ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpTo n f p #align cont_diff ContDiff variable {𝕜} /-- If `f` has a Taylor series up to `n`, then it is `C^n`. -/ theorem HasFTaylorSeriesUpTo.contDiff {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpTo n f f') : ContDiff 𝕜 n f := ⟨f', hf⟩ #align has_ftaylor_series_up_to.cont_diff HasFTaylorSeriesUpTo.contDiff theorem contDiffOn_univ : ContDiffOn 𝕜 n f univ ↔ ContDiff 𝕜 n f := by constructor · intro H use ftaylorSeriesWithin 𝕜 f univ rw [← hasFTaylorSeriesUpToOn_univ_iff] exact H.ftaylorSeriesWithin uniqueDiffOn_univ · rintro ⟨p, hp⟩ x _ m hm exact ⟨univ, Filter.univ_sets _, p, (hp.hasFTaylorSeriesUpToOn univ).of_le hm⟩ #align cont_diff_on_univ contDiffOn_univ theorem contDiff_iff_contDiffAt : ContDiff 𝕜 n f ↔ ∀ x, ContDiffAt 𝕜 n f x := by simp [← contDiffOn_univ, ContDiffOn, ContDiffAt] #align cont_diff_iff_cont_diff_at contDiff_iff_contDiffAt theorem ContDiff.contDiffAt (h : ContDiff 𝕜 n f) : ContDiffAt 𝕜 n f x := contDiff_iff_contDiffAt.1 h x #align cont_diff.cont_diff_at ContDiff.contDiffAt theorem ContDiff.contDiffWithinAt (h : ContDiff 𝕜 n f) : ContDiffWithinAt 𝕜 n f s x := h.contDiffAt.contDiffWithinAt #align cont_diff.cont_diff_within_at ContDiff.contDiffWithinAt theorem contDiff_top : ContDiff 𝕜 ∞ f ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp [contDiffOn_univ.symm, contDiffOn_top] #align cont_diff_top contDiff_top theorem contDiff_all_iff_nat : (∀ n, ContDiff 𝕜 n f) ↔ ∀ n : ℕ, ContDiff 𝕜 n f := by simp only [← contDiffOn_univ, contDiffOn_all_iff_nat] #align cont_diff_all_iff_nat contDiff_all_iff_nat theorem ContDiff.contDiffOn (h : ContDiff 𝕜 n f) : ContDiffOn 𝕜 n f s := (contDiffOn_univ.2 h).mono (subset_univ _) #align cont_diff.cont_diff_on ContDiff.contDiffOn @[simp] theorem contDiff_zero : ContDiff 𝕜 0 f ↔ Continuous f := by rw [← contDiffOn_univ, continuous_iff_continuousOn_univ] exact contDiffOn_zero #align cont_diff_zero contDiff_zero theorem contDiffAt_zero : ContDiffAt 𝕜 0 f x ↔ ∃ u ∈ 𝓝 x, ContinuousOn f u := by rw [← contDiffWithinAt_univ]; simp [contDiffWithinAt_zero, nhdsWithin_univ] #align cont_diff_at_zero contDiffAt_zero theorem contDiffAt_one_iff : ContDiffAt 𝕜 1 f x ↔ ∃ f' : E → E →L[𝕜] F, ∃ u ∈ 𝓝 x, ContinuousOn f' u ∧ ∀ x ∈ u, HasFDerivAt f (f' x) x := by simp_rw [show (1 : ℕ∞) = (0 + 1 : ℕ) from (zero_add 1).symm, contDiffAt_succ_iff_hasFDerivAt, show ((0 : ℕ) : ℕ∞) = 0 from rfl, contDiffAt_zero, exists_mem_and_iff antitone_bforall antitone_continuousOn, and_comm] #align cont_diff_at_one_iff contDiffAt_one_iff theorem ContDiff.of_le (h : ContDiff 𝕜 n f) (hmn : m ≤ n) : ContDiff 𝕜 m f := contDiffOn_univ.1 <| (contDiffOn_univ.2 h).of_le hmn #align cont_diff.of_le ContDiff.of_le theorem ContDiff.of_succ {n : ℕ} (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 n f := h.of_le <| WithTop.coe_le_coe.mpr le_self_add #align cont_diff.of_succ ContDiff.of_succ theorem ContDiff.one_of_succ {n : ℕ} (h : ContDiff 𝕜 (n + 1) f) : ContDiff 𝕜 1 f := h.of_le <| WithTop.coe_le_coe.mpr le_add_self #align cont_diff.one_of_succ ContDiff.one_of_succ theorem ContDiff.continuous (h : ContDiff 𝕜 n f) : Continuous f := contDiff_zero.1 (h.of_le bot_le) #align cont_diff.continuous ContDiff.continuous /-- If a function is `C^n` with `n ≥ 1`, then it is differentiable. -/ theorem ContDiff.differentiable (h : ContDiff 𝕜 n f) (hn : 1 ≤ n) : Differentiable 𝕜 f := differentiableOn_univ.1 <| (contDiffOn_univ.2 h).differentiableOn hn #align cont_diff.differentiable ContDiff.differentiable theorem contDiff_iff_forall_nat_le : ContDiff 𝕜 n f ↔ ∀ m : ℕ, ↑m ≤ n → ContDiff 𝕜 m f := by simp_rw [← contDiffOn_univ]; exact contDiffOn_iff_forall_nat_le #align cont_diff_iff_forall_nat_le contDiff_iff_forall_nat_le /-- A function is `C^(n+1)` iff it has a `C^n` derivative. -/ theorem contDiff_succ_iff_hasFDerivAt {n : ℕ} : ContDiff 𝕜 (n + 1 : ℕ) f ↔ ∃ f' : E → E →L[𝕜] F, ContDiff 𝕜 n f' ∧ ∀ x, HasFDerivAt f (f' x) x := by simp only [← contDiffOn_univ, ← hasFDerivWithinAt_univ, contDiffOn_succ_iff_hasFDerivWithin uniqueDiffOn_univ, Set.mem_univ, forall_true_left] #align cont_diff_succ_iff_has_fderiv contDiff_succ_iff_hasFDerivAt /-! ### Iterated derivative -/ variable (𝕜) /-- The `n`-th derivative of a function, as a multilinear map, defined inductively. -/ noncomputable def iteratedFDeriv (n : ℕ) (f : E → F) : E → E[×n]→L[𝕜] F := Nat.recOn n (fun x => ContinuousMultilinearMap.curry0 𝕜 E (f x)) fun _ rec x => ContinuousLinearMap.uncurryLeft (fderiv 𝕜 rec x) #align iterated_fderiv iteratedFDeriv /-- Formal Taylor series associated to a function. -/ def ftaylorSeries (f : E → F) (x : E) : FormalMultilinearSeries 𝕜 E F := fun n => iteratedFDeriv 𝕜 n f x #align ftaylor_series ftaylorSeries variable {𝕜} @[simp] theorem iteratedFDeriv_zero_apply (m : Fin 0 → E) : (iteratedFDeriv 𝕜 0 f x : (Fin 0 → E) → F) m = f x := rfl #align iterated_fderiv_zero_apply iteratedFDeriv_zero_apply theorem iteratedFDeriv_zero_eq_comp : iteratedFDeriv 𝕜 0 f = (continuousMultilinearCurryFin0 𝕜 E F).symm ∘ f := rfl #align iterated_fderiv_zero_eq_comp iteratedFDeriv_zero_eq_comp @[simp] theorem norm_iteratedFDeriv_zero : ‖iteratedFDeriv 𝕜 0 f x‖ = ‖f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_zero_eq_comp, comp_apply, LinearIsometryEquiv.norm_map] #align norm_iterated_fderiv_zero norm_iteratedFDeriv_zero theorem iteratedFDerivWithin_zero_eq : iteratedFDerivWithin 𝕜 0 f s = iteratedFDeriv 𝕜 0 f := rfl #align iterated_fderiv_with_zero_eq iteratedFDerivWithin_zero_eq theorem iteratedFDeriv_succ_apply_left {n : ℕ} (m : Fin (n + 1) → E) : (iteratedFDeriv 𝕜 (n + 1) f x : (Fin (n + 1) → E) → F) m = (fderiv 𝕜 (iteratedFDeriv 𝕜 n f) x : E → E[×n]→L[𝕜] F) (m 0) (tail m) := rfl #align iterated_fderiv_succ_apply_left iteratedFDeriv_succ_apply_left /-- Writing explicitly the `n+1`-th derivative as the composition of a currying linear equiv, and the derivative of the `n`-th derivative. -/ theorem iteratedFDeriv_succ_eq_comp_left {n : ℕ} : iteratedFDeriv 𝕜 (n + 1) f = continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F ∘ fderiv 𝕜 (iteratedFDeriv 𝕜 n f) := rfl #align iterated_fderiv_succ_eq_comp_left iteratedFDeriv_succ_eq_comp_left /-- Writing explicitly the derivative of the `n`-th derivative as the composition of a currying linear equiv, and the `n + 1`-th derivative. -/ theorem fderiv_iteratedFDeriv {n : ℕ} : fderiv 𝕜 (iteratedFDeriv 𝕜 n f) = (continuousMultilinearCurryLeftEquiv 𝕜 (fun _ : Fin (n + 1) => E) F).symm ∘ iteratedFDeriv 𝕜 (n + 1) f := by rw [iteratedFDeriv_succ_eq_comp_left] ext1 x simp only [Function.comp_apply, LinearIsometryEquiv.symm_apply_apply] #align fderiv_iterated_fderiv fderiv_iteratedFDeriv theorem tsupport_iteratedFDeriv_subset (n : ℕ) : tsupport (iteratedFDeriv 𝕜 n f) ⊆ tsupport f := by induction' n with n IH · rw [iteratedFDeriv_zero_eq_comp] exact closure_minimal ((support_comp_subset (LinearIsometryEquiv.map_zero _) _).trans subset_closure) isClosed_closure · rw [iteratedFDeriv_succ_eq_comp_left] exact closure_minimal ((support_comp_subset (LinearIsometryEquiv.map_zero _) _).trans ((support_fderiv_subset 𝕜).trans IH)) isClosed_closure theorem support_iteratedFDeriv_subset (n : ℕ) : support (iteratedFDeriv 𝕜 n f) ⊆ tsupport f := subset_closure.trans (tsupport_iteratedFDeriv_subset n) theorem HasCompactSupport.iteratedFDeriv (hf : HasCompactSupport f) (n : ℕ) : HasCompactSupport (iteratedFDeriv 𝕜 n f) := hf.of_isClosed_subset isClosed_closure (tsupport_iteratedFDeriv_subset n) #align has_compact_support.iterated_fderiv HasCompactSupport.iteratedFDeriv theorem norm_fderiv_iteratedFDeriv {n : ℕ} : ‖fderiv 𝕜 (iteratedFDeriv 𝕜 n f) x‖ = ‖iteratedFDeriv 𝕜 (n + 1) f x‖ := by -- Porting note: added `comp_apply`. rw [iteratedFDeriv_succ_eq_comp_left, comp_apply, LinearIsometryEquiv.norm_map] #align norm_fderiv_iterated_fderiv norm_fderiv_iteratedFDeriv
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
1,627
1,632
theorem iteratedFDerivWithin_univ {n : ℕ} : iteratedFDerivWithin 𝕜 n f univ = iteratedFDeriv 𝕜 n f := by
induction' n with n IH · ext x; simp · ext x m rw [iteratedFDeriv_succ_apply_left, iteratedFDerivWithin_succ_apply_left, IH, fderivWithin_univ]
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Combinatorics.SimpleGraph.Connectivity import Mathlib.Combinatorics.SimpleGraph.Operations import Mathlib.Data.Finset.Pairwise #align_import combinatorics.simple_graph.clique from "leanprover-community/mathlib"@"3365b20c2ffa7c35e47e5209b89ba9abdddf3ffe" /-! # Graph cliques This file defines cliques in simple graphs. A clique is a set of vertices that are pairwise adjacent. ## Main declarations * `SimpleGraph.IsClique`: Predicate for a set of vertices to be a clique. * `SimpleGraph.IsNClique`: Predicate for a set of vertices to be an `n`-clique. * `SimpleGraph.cliqueFinset`: Finset of `n`-cliques of a graph. * `SimpleGraph.CliqueFree`: Predicate for a graph to have no `n`-cliques. ## TODO * Clique numbers * Dualise all the API to get independent sets -/ open Finset Fintype Function SimpleGraph.Walk namespace SimpleGraph variable {α β : Type*} (G H : SimpleGraph α) /-! ### Cliques -/ section Clique variable {s t : Set α} /-- A clique in a graph is a set of vertices that are pairwise adjacent. -/ abbrev IsClique (s : Set α) : Prop := s.Pairwise G.Adj #align simple_graph.is_clique SimpleGraph.IsClique theorem isClique_iff : G.IsClique s ↔ s.Pairwise G.Adj := Iff.rfl #align simple_graph.is_clique_iff SimpleGraph.isClique_iff /-- A clique is a set of vertices whose induced graph is complete. -/ theorem isClique_iff_induce_eq : G.IsClique s ↔ G.induce s = ⊤ := by rw [isClique_iff] constructor · intro h ext ⟨v, hv⟩ ⟨w, hw⟩ simp only [comap_adj, Subtype.coe_mk, top_adj, Ne, Subtype.mk_eq_mk] exact ⟨Adj.ne, h hv hw⟩ · intro h v hv w hw hne have h2 : (G.induce s).Adj ⟨v, hv⟩ ⟨w, hw⟩ = _ := rfl conv_lhs at h2 => rw [h] simp only [top_adj, ne_eq, Subtype.mk.injEq, eq_iff_iff] at h2 exact h2.1 hne #align simple_graph.is_clique_iff_induce_eq SimpleGraph.isClique_iff_induce_eq instance [DecidableEq α] [DecidableRel G.Adj] {s : Finset α} : Decidable (G.IsClique s) := decidable_of_iff' _ G.isClique_iff variable {G H} {a b : α} lemma isClique_empty : G.IsClique ∅ := by simp #align simple_graph.is_clique_empty SimpleGraph.isClique_empty lemma isClique_singleton (a : α) : G.IsClique {a} := by simp #align simple_graph.is_clique_singleton SimpleGraph.isClique_singleton lemma isClique_pair : G.IsClique {a, b} ↔ a ≠ b → G.Adj a b := Set.pairwise_pair_of_symmetric G.symm #align simple_graph.is_clique_pair SimpleGraph.isClique_pair @[simp] lemma isClique_insert : G.IsClique (insert a s) ↔ G.IsClique s ∧ ∀ b ∈ s, a ≠ b → G.Adj a b := Set.pairwise_insert_of_symmetric G.symm #align simple_graph.is_clique_insert SimpleGraph.isClique_insert lemma isClique_insert_of_not_mem (ha : a ∉ s) : G.IsClique (insert a s) ↔ G.IsClique s ∧ ∀ b ∈ s, G.Adj a b := Set.pairwise_insert_of_symmetric_of_not_mem G.symm ha #align simple_graph.is_clique_insert_of_not_mem SimpleGraph.isClique_insert_of_not_mem lemma IsClique.insert (hs : G.IsClique s) (h : ∀ b ∈ s, a ≠ b → G.Adj a b) : G.IsClique (insert a s) := hs.insert_of_symmetric G.symm h #align simple_graph.is_clique.insert SimpleGraph.IsClique.insert theorem IsClique.mono (h : G ≤ H) : G.IsClique s → H.IsClique s := Set.Pairwise.mono' h #align simple_graph.is_clique.mono SimpleGraph.IsClique.mono theorem IsClique.subset (h : t ⊆ s) : G.IsClique s → G.IsClique t := Set.Pairwise.mono h #align simple_graph.is_clique.subset SimpleGraph.IsClique.subset protected theorem IsClique.map {s : Set α} (h : G.IsClique s) {f : α ↪ β} : (G.map f).IsClique (f '' s) := by rintro _ ⟨a, ha, rfl⟩ _ ⟨b, hb, rfl⟩ hab exact ⟨a, b, h ha hb <| ne_of_apply_ne _ hab, rfl, rfl⟩ #align simple_graph.is_clique.map SimpleGraph.IsClique.map @[simp] theorem isClique_bot_iff : (⊥ : SimpleGraph α).IsClique s ↔ (s : Set α).Subsingleton := Set.pairwise_bot_iff #align simple_graph.is_clique_bot_iff SimpleGraph.isClique_bot_iff alias ⟨IsClique.subsingleton, _⟩ := isClique_bot_iff #align simple_graph.is_clique.subsingleton SimpleGraph.IsClique.subsingleton end Clique /-! ### `n`-cliques -/ section NClique variable {n : ℕ} {s : Finset α} /-- An `n`-clique in a graph is a set of `n` vertices which are pairwise connected. -/ structure IsNClique (n : ℕ) (s : Finset α) : Prop where clique : G.IsClique s card_eq : s.card = n #align simple_graph.is_n_clique SimpleGraph.IsNClique theorem isNClique_iff : G.IsNClique n s ↔ G.IsClique s ∧ s.card = n := ⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩ #align simple_graph.is_n_clique_iff SimpleGraph.isNClique_iff instance [DecidableEq α] [DecidableRel G.Adj] {n : ℕ} {s : Finset α} : Decidable (G.IsNClique n s) := decidable_of_iff' _ G.isNClique_iff variable {G H} {a b c : α} @[simp] lemma isNClique_empty : G.IsNClique n ∅ ↔ n = 0 := by simp [isNClique_iff, eq_comm] #align simple_graph.is_n_clique_empty SimpleGraph.isNClique_empty @[simp] lemma isNClique_singleton : G.IsNClique n {a} ↔ n = 1 := by simp [isNClique_iff, eq_comm] #align simple_graph.is_n_clique_singleton SimpleGraph.isNClique_singleton
Mathlib/Combinatorics/SimpleGraph/Clique.lean
149
151
theorem IsNClique.mono (h : G ≤ H) : G.IsNClique n s → H.IsNClique n s := by
simp_rw [isNClique_iff] exact And.imp_left (IsClique.mono h)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Kyle Miller -/ import Mathlib.Data.Finset.Basic import Mathlib.Data.Finite.Basic import Mathlib.Data.Set.Functor import Mathlib.Data.Set.Lattice #align_import data.set.finite from "leanprover-community/mathlib"@"65a1391a0106c9204fe45bc73a039f056558cb83" /-! # Finite sets This file defines predicates for finite and infinite sets and provides `Fintype` instances for many set constructions. It also proves basic facts about finite sets and gives ways to manipulate `Set.Finite` expressions. ## Main definitions * `Set.Finite : Set α → Prop` * `Set.Infinite : Set α → Prop` * `Set.toFinite` to prove `Set.Finite` for a `Set` from a `Finite` instance. * `Set.Finite.toFinset` to noncomputably produce a `Finset` from a `Set.Finite` proof. (See `Set.toFinset` for a computable version.) ## Implementation A finite set is defined to be a set whose coercion to a type has a `Finite` instance. There are two components to finiteness constructions. The first is `Fintype` instances for each construction. This gives a way to actually compute a `Finset` that represents the set, and these may be accessed using `set.toFinset`. This gets the `Finset` in the correct form, since otherwise `Finset.univ : Finset s` is a `Finset` for the subtype for `s`. The second component is "constructors" for `Set.Finite` that give proofs that `Fintype` instances exist classically given other `Set.Finite` proofs. Unlike the `Fintype` instances, these *do not* use any decidability instances since they do not compute anything. ## Tags finite sets -/ assert_not_exists OrderedRing assert_not_exists MonoidWithZero open Set Function universe u v w x variable {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x} namespace Set /-- A set is finite if the corresponding `Subtype` is finite, i.e., if there exists a natural `n : ℕ` and an equivalence `s ≃ Fin n`. -/ protected def Finite (s : Set α) : Prop := Finite s #align set.finite Set.Finite -- The `protected` attribute does not take effect within the same namespace block. end Set namespace Set theorem finite_def {s : Set α} : s.Finite ↔ Nonempty (Fintype s) := finite_iff_nonempty_fintype s #align set.finite_def Set.finite_def protected alias ⟨Finite.nonempty_fintype, _⟩ := finite_def #align set.finite.nonempty_fintype Set.Finite.nonempty_fintype theorem finite_coe_iff {s : Set α} : Finite s ↔ s.Finite := .rfl #align set.finite_coe_iff Set.finite_coe_iff /-- Constructor for `Set.Finite` using a `Finite` instance. -/ theorem toFinite (s : Set α) [Finite s] : s.Finite := ‹_› #align set.to_finite Set.toFinite /-- Construct a `Finite` instance for a `Set` from a `Finset` with the same elements. -/ protected theorem Finite.ofFinset {p : Set α} (s : Finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : p.Finite := have := Fintype.ofFinset s H; p.toFinite #align set.finite.of_finset Set.Finite.ofFinset /-- Projection of `Set.Finite` to its `Finite` instance. This is intended to be used with dot notation. See also `Set.Finite.Fintype` and `Set.Finite.nonempty_fintype`. -/ protected theorem Finite.to_subtype {s : Set α} (h : s.Finite) : Finite s := h #align set.finite.to_subtype Set.Finite.to_subtype /-- A finite set coerced to a type is a `Fintype`. This is the `Fintype` projection for a `Set.Finite`. Note that because `Finite` isn't a typeclass, this definition will not fire if it is made into an instance -/ protected noncomputable def Finite.fintype {s : Set α} (h : s.Finite) : Fintype s := h.nonempty_fintype.some #align set.finite.fintype Set.Finite.fintype /-- Using choice, get the `Finset` that represents this `Set`. -/ protected noncomputable def Finite.toFinset {s : Set α} (h : s.Finite) : Finset α := @Set.toFinset _ _ h.fintype #align set.finite.to_finset Set.Finite.toFinset theorem Finite.toFinset_eq_toFinset {s : Set α} [Fintype s] (h : s.Finite) : h.toFinset = s.toFinset := by -- Porting note: was `rw [Finite.toFinset]; congr` -- in Lean 4, a goal is left after `congr` have : h.fintype = ‹_› := Subsingleton.elim _ _ rw [Finite.toFinset, this] #align set.finite.to_finset_eq_to_finset Set.Finite.toFinset_eq_toFinset @[simp] theorem toFinite_toFinset (s : Set α) [Fintype s] : s.toFinite.toFinset = s.toFinset := s.toFinite.toFinset_eq_toFinset #align set.to_finite_to_finset Set.toFinite_toFinset theorem Finite.exists_finset {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ∀ a : α, a ∈ s' ↔ a ∈ s := by cases h.nonempty_fintype exact ⟨s.toFinset, fun _ => mem_toFinset⟩ #align set.finite.exists_finset Set.Finite.exists_finset theorem Finite.exists_finset_coe {s : Set α} (h : s.Finite) : ∃ s' : Finset α, ↑s' = s := by cases h.nonempty_fintype exact ⟨s.toFinset, s.coe_toFinset⟩ #align set.finite.exists_finset_coe Set.Finite.exists_finset_coe /-- Finite sets can be lifted to finsets. -/ instance : CanLift (Set α) (Finset α) (↑) Set.Finite where prf _ hs := hs.exists_finset_coe /-- A set is infinite if it is not finite. This is protected so that it does not conflict with global `Infinite`. -/ protected def Infinite (s : Set α) : Prop := ¬s.Finite #align set.infinite Set.Infinite @[simp] theorem not_infinite {s : Set α} : ¬s.Infinite ↔ s.Finite := not_not #align set.not_infinite Set.not_infinite alias ⟨_, Finite.not_infinite⟩ := not_infinite #align set.finite.not_infinite Set.Finite.not_infinite attribute [simp] Finite.not_infinite /-- See also `finite_or_infinite`, `fintypeOrInfinite`. -/ protected theorem finite_or_infinite (s : Set α) : s.Finite ∨ s.Infinite := em _ #align set.finite_or_infinite Set.finite_or_infinite protected theorem infinite_or_finite (s : Set α) : s.Infinite ∨ s.Finite := em' _ #align set.infinite_or_finite Set.infinite_or_finite /-! ### Basic properties of `Set.Finite.toFinset` -/ namespace Finite variable {s t : Set α} {a : α} (hs : s.Finite) {ht : t.Finite} @[simp] protected theorem mem_toFinset : a ∈ hs.toFinset ↔ a ∈ s := @mem_toFinset _ _ hs.fintype _ #align set.finite.mem_to_finset Set.Finite.mem_toFinset @[simp] protected theorem coe_toFinset : (hs.toFinset : Set α) = s := @coe_toFinset _ _ hs.fintype #align set.finite.coe_to_finset Set.Finite.coe_toFinset @[simp] protected theorem toFinset_nonempty : hs.toFinset.Nonempty ↔ s.Nonempty := by rw [← Finset.coe_nonempty, Finite.coe_toFinset] #align set.finite.to_finset_nonempty Set.Finite.toFinset_nonempty /-- Note that this is an equality of types not holding definitionally. Use wisely. -/ theorem coeSort_toFinset : ↥hs.toFinset = ↥s := by rw [← Finset.coe_sort_coe _, hs.coe_toFinset] #align set.finite.coe_sort_to_finset Set.Finite.coeSort_toFinset /-- The identity map, bundled as an equivalence between the subtypes of `s : Set α` and of `h.toFinset : Finset α`, where `h` is a proof of finiteness of `s`. -/ @[simps!] def subtypeEquivToFinset : {x // x ∈ s} ≃ {x // x ∈ hs.toFinset} := (Equiv.refl α).subtypeEquiv fun _ ↦ hs.mem_toFinset.symm variable {hs} @[simp] protected theorem toFinset_inj : hs.toFinset = ht.toFinset ↔ s = t := @toFinset_inj _ _ _ hs.fintype ht.fintype #align set.finite.to_finset_inj Set.Finite.toFinset_inj @[simp]
Mathlib/Data/Set/Finite.lean
198
199
theorem toFinset_subset {t : Finset α} : hs.toFinset ⊆ t ↔ s ⊆ t := by
rw [← Finset.coe_subset, Finite.coe_toFinset]
/- Copyright (c) 2020 Ashvni Narayanan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ashvni Narayanan -/ import Mathlib.Algebra.Group.Subgroup.Basic import Mathlib.Algebra.Ring.Subsemiring.Basic #align_import ring_theory.subring.basic from "leanprover-community/mathlib"@"b915e9392ecb2a861e1e766f0e1df6ac481188ca" /-! # Subrings Let `R` be a ring. This file defines the "bundled" subring type `Subring R`, a type whose terms correspond to subrings of `R`. This is the preferred way to talk about subrings in mathlib. Unbundled subrings (`s : Set R` and `IsSubring s`) are not in this file, and they will ultimately be deprecated. We prove that subrings are a complete lattice, and that you can `map` (pushforward) and `comap` (pull back) them along ring homomorphisms. We define the `closure` construction from `Set R` to `Subring R`, sending a subset of `R` to the subring it generates, and prove that it is a Galois insertion. ## Main definitions Notation used here: `(R : Type u) [Ring R] (S : Type u) [Ring S] (f g : R →+* S)` `(A : Subring R) (B : Subring S) (s : Set R)` * `Subring R` : the type of subrings of a ring `R`. * `instance : CompleteLattice (Subring R)` : the complete lattice structure on the subrings. * `Subring.center` : the center of a ring `R`. * `Subring.closure` : subring closure of a set, i.e., the smallest subring that includes the set. * `Subring.gi` : `closure : Set M → Subring M` and coercion `(↑) : Subring M → et M` form a `GaloisInsertion`. * `comap f B : Subring A` : the preimage of a subring `B` along the ring homomorphism `f` * `map f A : Subring B` : the image of a subring `A` along the ring homomorphism `f`. * `prod A B : Subring (R × S)` : the product of subrings * `f.range : Subring B` : the range of the ring homomorphism `f`. * `eqLocus f g : Subring R` : given ring homomorphisms `f g : R →+* S`, the subring of `R` where `f x = g x` ## Implementation notes A subring is implemented as a subsemiring which is also an additive subgroup. The initial PR was as a submonoid which is also an additive subgroup. Lattice inclusion (e.g. `≤` and `⊓`) is used rather than set notation (`⊆` and `∩`), although `∈` is defined as membership of a subring's underlying set. ## Tags subring, subrings -/ universe u v w variable {R : Type u} {S : Type v} {T : Type w} [Ring R] section SubringClass /-- `SubringClass S R` states that `S` is a type of subsets `s ⊆ R` that are both a multiplicative submonoid and an additive subgroup. -/ class SubringClass (S : Type*) (R : Type u) [Ring R] [SetLike S R] extends SubsemiringClass S R, NegMemClass S R : Prop #align subring_class SubringClass -- See note [lower instance priority] instance (priority := 100) SubringClass.addSubgroupClass (S : Type*) (R : Type u) [SetLike S R] [Ring R] [h : SubringClass S R] : AddSubgroupClass S R := { h with } #align subring_class.add_subgroup_class SubringClass.addSubgroupClass variable [SetLike S R] [hSR : SubringClass S R] (s : S) @[aesop safe apply (rule_sets := [SetLike])] theorem intCast_mem (n : ℤ) : (n : R) ∈ s := by simp only [← zsmul_one, zsmul_mem, one_mem] #align coe_int_mem intCast_mem -- 2024-04-05 @[deprecated _root_.intCast_mem] alias coe_int_mem := intCast_mem namespace SubringClass instance (priority := 75) toHasIntCast : IntCast s := ⟨fun n => ⟨n, intCast_mem s n⟩⟩ #align subring_class.to_has_int_cast SubringClass.toHasIntCast -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a ring inherits a ring structure -/ instance (priority := 75) toRing : Ring s := Subtype.coe_injective.ring (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl #align subring_class.to_ring SubringClass.toRing -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a `CommRing` is a `CommRing`. -/ instance (priority := 75) toCommRing {R} [CommRing R] [SetLike S R] [SubringClass S R] : CommRing s := Subtype.coe_injective.commRing (↑) rfl rfl (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) fun _ => rfl #align subring_class.to_comm_ring SubringClass.toCommRing -- Prefer subclasses of `Ring` over subclasses of `SubringClass`. /-- A subring of a domain is a domain. -/ instance (priority := 75) {R} [Ring R] [IsDomain R] [SetLike S R] [SubringClass S R] : IsDomain s := NoZeroDivisors.to_isDomain _ /-- The natural ring hom from a subring of ring `R` to `R`. -/ def subtype (s : S) : s →+* R := { SubmonoidClass.subtype s, AddSubgroupClass.subtype s with toFun := (↑) } #align subring_class.subtype SubringClass.subtype @[simp] theorem coeSubtype : (subtype s : s → R) = ((↑) : s → R) := rfl #align subring_class.coe_subtype SubringClass.coeSubtype @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : s) : R) = n := map_natCast (subtype s) n #align subring_class.coe_nat_cast SubringClass.coe_natCast @[simp, norm_cast] theorem coe_intCast (n : ℤ) : ((n : s) : R) = n := map_intCast (subtype s) n #align subring_class.coe_int_cast SubringClass.coe_intCast end SubringClass end SubringClass variable [Ring S] [Ring T] /-- `Subring R` is the type of subrings of `R`. A subring of `R` is a subset `s` that is a multiplicative submonoid and an additive subgroup. Note in particular that it shares the same 0 and 1 as R. -/ structure Subring (R : Type u) [Ring R] extends Subsemiring R, AddSubgroup R #align subring Subring /-- Reinterpret a `Subring` as a `Subsemiring`. -/ add_decl_doc Subring.toSubsemiring /-- Reinterpret a `Subring` as an `AddSubgroup`. -/ add_decl_doc Subring.toAddSubgroup namespace Subring -- Porting note: there is no `Subring.toSubmonoid` but we can't define it because there is a -- projection `s.toSubmonoid` #noalign subring.to_submonoid instance : SetLike (Subring R) R where coe s := s.carrier coe_injective' p q h := by cases p; cases q; congr; exact SetLike.ext' h instance : SubringClass (Subring R) R where zero_mem s := s.zero_mem' add_mem {s} := s.add_mem' one_mem s := s.one_mem' mul_mem {s} := s.mul_mem' neg_mem {s} := s.neg_mem' @[simp] theorem mem_toSubsemiring {s : Subring R} {x : R} : x ∈ s.toSubsemiring ↔ x ∈ s := Iff.rfl theorem mem_carrier {s : Subring R} {x : R} : x ∈ s.carrier ↔ x ∈ s := Iff.rfl #align subring.mem_carrier Subring.mem_carrier @[simp] theorem mem_mk {S : Subsemiring R} {x : R} (h) : x ∈ (⟨S, h⟩ : Subring R) ↔ x ∈ S := Iff.rfl #align subring.mem_mk Subring.mem_mkₓ @[simp] theorem coe_set_mk (S : Subsemiring R) (h) : ((⟨S, h⟩ : Subring R) : Set R) = S := rfl #align subring.coe_set_mk Subring.coe_set_mkₓ @[simp] theorem mk_le_mk {S S' : Subsemiring R} (h₁ h₂) : (⟨S, h₁⟩ : Subring R) ≤ (⟨S', h₂⟩ : Subring R) ↔ S ≤ S' := Iff.rfl #align subring.mk_le_mk Subring.mk_le_mkₓ /-- Two subrings are equal if they have the same elements. -/ @[ext] theorem ext {S T : Subring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := SetLike.ext h #align subring.ext Subring.ext /-- Copy of a subring with a new `carrier` equal to the old one. Useful to fix definitional equalities. -/ protected def copy (S : Subring R) (s : Set R) (hs : s = ↑S) : Subring R := { S.toSubsemiring.copy s hs with carrier := s neg_mem' := hs.symm ▸ S.neg_mem' } #align subring.copy Subring.copy @[simp] theorem coe_copy (S : Subring R) (s : Set R) (hs : s = ↑S) : (S.copy s hs : Set R) = s := rfl #align subring.coe_copy Subring.coe_copy theorem copy_eq (S : Subring R) (s : Set R) (hs : s = ↑S) : S.copy s hs = S := SetLike.coe_injective hs #align subring.copy_eq Subring.copy_eq theorem toSubsemiring_injective : Function.Injective (toSubsemiring : Subring R → Subsemiring R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subring.to_subsemiring_injective Subring.toSubsemiring_injective @[mono] theorem toSubsemiring_strictMono : StrictMono (toSubsemiring : Subring R → Subsemiring R) := fun _ _ => id #align subring.to_subsemiring_strict_mono Subring.toSubsemiring_strictMono @[mono] theorem toSubsemiring_mono : Monotone (toSubsemiring : Subring R → Subsemiring R) := toSubsemiring_strictMono.monotone #align subring.to_subsemiring_mono Subring.toSubsemiring_mono theorem toAddSubgroup_injective : Function.Injective (toAddSubgroup : Subring R → AddSubgroup R) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subring.to_add_subgroup_injective Subring.toAddSubgroup_injective @[mono] theorem toAddSubgroup_strictMono : StrictMono (toAddSubgroup : Subring R → AddSubgroup R) := fun _ _ => id #align subring.to_add_subgroup_strict_mono Subring.toAddSubgroup_strictMono @[mono] theorem toAddSubgroup_mono : Monotone (toAddSubgroup : Subring R → AddSubgroup R) := toAddSubgroup_strictMono.monotone #align subring.to_add_subgroup_mono Subring.toAddSubgroup_mono theorem toSubmonoid_injective : Function.Injective (fun s : Subring R => s.toSubmonoid) | _, _, h => ext (SetLike.ext_iff.mp h : _) #align subring.to_submonoid_injective Subring.toSubmonoid_injective @[mono] theorem toSubmonoid_strictMono : StrictMono (fun s : Subring R => s.toSubmonoid) := fun _ _ => id #align subring.to_submonoid_strict_mono Subring.toSubmonoid_strictMono @[mono] theorem toSubmonoid_mono : Monotone (fun s : Subring R => s.toSubmonoid) := toSubmonoid_strictMono.monotone #align subring.to_submonoid_mono Subring.toSubmonoid_mono /-- Construct a `Subring R` from a set `s`, a submonoid `sm`, and an additive subgroup `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/ protected def mk' (s : Set R) (sm : Submonoid R) (sa : AddSubgroup R) (hm : ↑sm = s) (ha : ↑sa = s) : Subring R := { sm.copy s hm.symm, sa.copy s ha.symm with } #align subring.mk' Subring.mk' @[simp] theorem coe_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (Subring.mk' s sm sa hm ha : Set R) = s := rfl #align subring.coe_mk' Subring.coe_mk' @[simp] theorem mem_mk' {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) {x : R} : x ∈ Subring.mk' s sm sa hm ha ↔ x ∈ s := Iff.rfl #align subring.mem_mk' Subring.mem_mk' @[simp] theorem mk'_toSubmonoid {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (Subring.mk' s sm sa hm ha).toSubmonoid = sm := SetLike.coe_injective hm.symm #align subring.mk'_to_submonoid Subring.mk'_toSubmonoid @[simp] theorem mk'_toAddSubgroup {s : Set R} {sm : Submonoid R} (hm : ↑sm = s) {sa : AddSubgroup R} (ha : ↑sa = s) : (Subring.mk' s sm sa hm ha).toAddSubgroup = sa := SetLike.coe_injective ha.symm #align subring.mk'_to_add_subgroup Subring.mk'_toAddSubgroup end Subring /-- A `Subsemiring` containing -1 is a `Subring`. -/ def Subsemiring.toSubring (s : Subsemiring R) (hneg : (-1 : R) ∈ s) : Subring R where toSubsemiring := s neg_mem' h := by rw [← neg_one_mul] exact mul_mem hneg h #align subsemiring.to_subring Subsemiring.toSubring namespace Subring variable (s : Subring R) /-- A subring contains the ring's 1. -/ protected theorem one_mem : (1 : R) ∈ s := one_mem _ #align subring.one_mem Subring.one_mem /-- A subring contains the ring's 0. -/ protected theorem zero_mem : (0 : R) ∈ s := zero_mem _ #align subring.zero_mem Subring.zero_mem /-- A subring is closed under multiplication. -/ protected theorem mul_mem {x y : R} : x ∈ s → y ∈ s → x * y ∈ s := mul_mem #align subring.mul_mem Subring.mul_mem /-- A subring is closed under addition. -/ protected theorem add_mem {x y : R} : x ∈ s → y ∈ s → x + y ∈ s := add_mem #align subring.add_mem Subring.add_mem /-- A subring is closed under negation. -/ protected theorem neg_mem {x : R} : x ∈ s → -x ∈ s := neg_mem #align subring.neg_mem Subring.neg_mem /-- A subring is closed under subtraction -/ protected theorem sub_mem {x y : R} (hx : x ∈ s) (hy : y ∈ s) : x - y ∈ s := sub_mem hx hy #align subring.sub_mem Subring.sub_mem /-- Product of a list of elements in a subring is in the subring. -/ protected theorem list_prod_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.prod ∈ s := list_prod_mem #align subring.list_prod_mem Subring.list_prod_mem /-- Sum of a list of elements in a subring is in the subring. -/ protected theorem list_sum_mem {l : List R} : (∀ x ∈ l, x ∈ s) → l.sum ∈ s := list_sum_mem #align subring.list_sum_mem Subring.list_sum_mem /-- Product of a multiset of elements in a subring of a `CommRing` is in the subring. -/ protected theorem multiset_prod_mem {R} [CommRing R] (s : Subring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.prod ∈ s := multiset_prod_mem _ #align subring.multiset_prod_mem Subring.multiset_prod_mem /-- Sum of a multiset of elements in a `Subring` of a `Ring` is in the `Subring`. -/ protected theorem multiset_sum_mem {R} [Ring R] (s : Subring R) (m : Multiset R) : (∀ a ∈ m, a ∈ s) → m.sum ∈ s := multiset_sum_mem _ #align subring.multiset_sum_mem Subring.multiset_sum_mem /-- Product of elements of a subring of a `CommRing` indexed by a `Finset` is in the subring. -/ protected theorem prod_mem {R : Type*} [CommRing R] (s : Subring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∏ i ∈ t, f i) ∈ s := prod_mem h #align subring.prod_mem Subring.prod_mem /-- Sum of elements in a `Subring` of a `Ring` indexed by a `Finset` is in the `Subring`. -/ protected theorem sum_mem {R : Type*} [Ring R] (s : Subring R) {ι : Type*} {t : Finset ι} {f : ι → R} (h : ∀ c ∈ t, f c ∈ s) : (∑ i ∈ t, f i) ∈ s := sum_mem h #align subring.sum_mem Subring.sum_mem /-- A subring of a ring inherits a ring structure -/ instance toRing : Ring s := SubringClass.toRing s #align subring.to_ring Subring.toRing protected theorem zsmul_mem {x : R} (hx : x ∈ s) (n : ℤ) : n • x ∈ s := zsmul_mem hx n #align subring.zsmul_mem Subring.zsmul_mem protected theorem pow_mem {x : R} (hx : x ∈ s) (n : ℕ) : x ^ n ∈ s := pow_mem hx n #align subring.pow_mem Subring.pow_mem @[simp, norm_cast] theorem coe_add (x y : s) : (↑(x + y) : R) = ↑x + ↑y := rfl #align subring.coe_add Subring.coe_add @[simp, norm_cast] theorem coe_neg (x : s) : (↑(-x) : R) = -↑x := rfl #align subring.coe_neg Subring.coe_neg @[simp, norm_cast] theorem coe_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y := rfl #align subring.coe_mul Subring.coe_mul @[simp, norm_cast] theorem coe_zero : ((0 : s) : R) = 0 := rfl #align subring.coe_zero Subring.coe_zero @[simp, norm_cast] theorem coe_one : ((1 : s) : R) = 1 := rfl #align subring.coe_one Subring.coe_one @[simp, norm_cast] theorem coe_pow (x : s) (n : ℕ) : ↑(x ^ n) = (x : R) ^ n := SubmonoidClass.coe_pow x n #align subring.coe_pow Subring.coe_pow -- TODO: can be generalized to `AddSubmonoidClass` -- @[simp] -- Porting note (#10618): simp can prove this theorem coe_eq_zero_iff {x : s} : (x : R) = 0 ↔ x = 0 := ⟨fun h => Subtype.ext (Trans.trans h s.coe_zero.symm), fun h => h.symm ▸ s.coe_zero⟩ #align subring.coe_eq_zero_iff Subring.coe_eq_zero_iff /-- A subring of a `CommRing` is a `CommRing`. -/ instance toCommRing {R} [CommRing R] (s : Subring R) : CommRing s := SubringClass.toCommRing s #align subring.to_comm_ring Subring.toCommRing /-- A subring of a non-trivial ring is non-trivial. -/ instance {R} [Ring R] [Nontrivial R] (s : Subring R) : Nontrivial s := s.toSubsemiring.nontrivial /-- A subring of a ring with no zero divisors has no zero divisors. -/ instance {R} [Ring R] [NoZeroDivisors R] (s : Subring R) : NoZeroDivisors s := s.toSubsemiring.noZeroDivisors /-- A subring of a domain is a domain. -/ instance {R} [Ring R] [IsDomain R] (s : Subring R) : IsDomain s := NoZeroDivisors.to_isDomain _ /-- The natural ring hom from a subring of ring `R` to `R`. -/ def subtype (s : Subring R) : s →+* R := { s.toSubmonoid.subtype, s.toAddSubgroup.subtype with toFun := (↑) } #align subring.subtype Subring.subtype @[simp] theorem coeSubtype : ⇑s.subtype = ((↑) : s → R) := rfl #align subring.coe_subtype Subring.coeSubtype @[norm_cast] -- Porting note (#10618): simp can prove this (removed `@[simp]`) theorem coe_natCast : ∀ n : ℕ, ((n : s) : R) = n := map_natCast s.subtype #align subring.coe_nat_cast Subring.coe_natCast @[norm_cast] -- Porting note (#10618): simp can prove this (removed `@[simp]`) theorem coe_intCast : ∀ n : ℤ, ((n : s) : R) = n := map_intCast s.subtype #align subring.coe_int_cast Subring.coe_intCast /-! ## Partial order -/ -- Porting note (#10756): new theorem @[simp] theorem coe_toSubsemiring (s : Subring R) : (s.toSubsemiring : Set R) = s := rfl @[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this theorem mem_toSubmonoid {s : Subring R} {x : R} : x ∈ s.toSubmonoid ↔ x ∈ s := Iff.rfl #align subring.mem_to_submonoid Subring.mem_toSubmonoid @[simp] theorem coe_toSubmonoid (s : Subring R) : (s.toSubmonoid : Set R) = s := rfl #align subring.coe_to_submonoid Subring.coe_toSubmonoid @[simp, nolint simpNF] -- Porting note (#10675): dsimp can not prove this theorem mem_toAddSubgroup {s : Subring R} {x : R} : x ∈ s.toAddSubgroup ↔ x ∈ s := Iff.rfl #align subring.mem_to_add_subgroup Subring.mem_toAddSubgroup @[simp] theorem coe_toAddSubgroup (s : Subring R) : (s.toAddSubgroup : Set R) = s := rfl #align subring.coe_to_add_subgroup Subring.coe_toAddSubgroup /-! ## top -/ /-- The subring `R` of the ring `R`. -/ instance : Top (Subring R) := ⟨{ (⊤ : Submonoid R), (⊤ : AddSubgroup R) with }⟩ @[simp] theorem mem_top (x : R) : x ∈ (⊤ : Subring R) := Set.mem_univ x #align subring.mem_top Subring.mem_top @[simp] theorem coe_top : ((⊤ : Subring R) : Set R) = Set.univ := rfl #align subring.coe_top Subring.coe_top /-- The ring equiv between the top element of `Subring R` and `R`. -/ @[simps!] def topEquiv : (⊤ : Subring R) ≃+* R := Subsemiring.topEquiv #align subring.top_equiv Subring.topEquiv theorem card_top (R) [Ring R] [Fintype R] : Fintype.card (⊤ : Subring R) = Fintype.card R := Fintype.card_congr topEquiv.toEquiv /-! ## comap -/ /-- The preimage of a subring along a ring homomorphism is a subring. -/ def comap {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring S) : Subring R := { s.toSubmonoid.comap (f : R →* S), s.toAddSubgroup.comap (f : R →+ S) with carrier := f ⁻¹' s.carrier } #align subring.comap Subring.comap @[simp] theorem coe_comap (s : Subring S) (f : R →+* S) : (s.comap f : Set R) = f ⁻¹' s := rfl #align subring.coe_comap Subring.coe_comap @[simp] theorem mem_comap {s : Subring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := Iff.rfl #align subring.mem_comap Subring.mem_comap theorem comap_comap (s : Subring T) (g : S →+* T) (f : R →+* S) : (s.comap g).comap f = s.comap (g.comp f) := rfl #align subring.comap_comap Subring.comap_comap /-! ## map -/ /-- The image of a subring along a ring homomorphism is a subring. -/ def map {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) (s : Subring R) : Subring S := { s.toSubmonoid.map (f : R →* S), s.toAddSubgroup.map (f : R →+ S) with carrier := f '' s.carrier } #align subring.map Subring.map @[simp] theorem coe_map (f : R →+* S) (s : Subring R) : (s.map f : Set S) = f '' s := rfl #align subring.coe_map Subring.coe_map @[simp] theorem mem_map {f : R →+* S} {s : Subring R} {y : S} : y ∈ s.map f ↔ ∃ x ∈ s, f x = y := Iff.rfl #align subring.mem_map Subring.mem_map @[simp] theorem map_id : s.map (RingHom.id R) = s := SetLike.coe_injective <| Set.image_id _ #align subring.map_id Subring.map_id theorem map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) := SetLike.coe_injective <| Set.image_image _ _ _ #align subring.map_map Subring.map_map theorem map_le_iff_le_comap {f : R →+* S} {s : Subring R} {t : Subring S} : s.map f ≤ t ↔ s ≤ t.comap f := Set.image_subset_iff #align subring.map_le_iff_le_comap Subring.map_le_iff_le_comap theorem gc_map_comap (f : R →+* S) : GaloisConnection (map f) (comap f) := fun _ _ => map_le_iff_le_comap #align subring.gc_map_comap Subring.gc_map_comap /-- A subring is isomorphic to its image under an injective function -/ noncomputable def equivMapOfInjective (f : R →+* S) (hf : Function.Injective f) : s ≃+* s.map f := { Equiv.Set.image f s hf with map_mul' := fun _ _ => Subtype.ext (f.map_mul _ _) map_add' := fun _ _ => Subtype.ext (f.map_add _ _) } #align subring.equiv_map_of_injective Subring.equivMapOfInjective @[simp] theorem coe_equivMapOfInjective_apply (f : R →+* S) (hf : Function.Injective f) (x : s) : (equivMapOfInjective s f hf x : S) = f x := rfl #align subring.coe_equiv_map_of_injective_apply Subring.coe_equivMapOfInjective_apply end Subring namespace RingHom variable (g : S →+* T) (f : R →+* S) /-! ## range -/ /-- The range of a ring homomorphism, as a subring of the target. See Note [range copy pattern]. -/ def range {R : Type u} {S : Type v} [Ring R] [Ring S] (f : R →+* S) : Subring S := ((⊤ : Subring R).map f).copy (Set.range f) Set.image_univ.symm #align ring_hom.range RingHom.range @[simp] theorem coe_range : (f.range : Set S) = Set.range f := rfl #align ring_hom.coe_range RingHom.coe_range @[simp] theorem mem_range {f : R →+* S} {y : S} : y ∈ f.range ↔ ∃ x, f x = y := Iff.rfl #align ring_hom.mem_range RingHom.mem_range
Mathlib/Algebra/Ring/Subring/Basic.lean
607
609
theorem range_eq_map (f : R →+* S) : f.range = Subring.map f ⊤ := by
ext simp
/- Copyright (c) 2023 Jireh Loreaux. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jireh Loreaux -/ import Mathlib.Algebra.Algebra.Unitization import Mathlib.Algebra.Star.NonUnitalSubalgebra import Mathlib.Algebra.Star.Subalgebra import Mathlib.GroupTheory.GroupAction.Ring /-! # Relating unital and non-unital substructures This file relates various algebraic structures and provides maps (generally algebra homomorphisms), from the unitization of a non-unital subobject into the full structure. The range of this map is the unital closure of the non-unital subobject (e.g., `Algebra.adjoin`, `Subring.closure`, `Subsemiring.closure` or `StarAlgebra.adjoin`). When the underlying scalar ring is a field, for this map to be injective it suffices that the range omits `1`. In this setting we provide suitable `AlgEquiv` (or `StarAlgEquiv`) onto the range. ## Main declarations * `NonUnitalSubalgebra.unitization s : Unitization R s →ₐ[R] A`: where `s` is a non-unital subalgebra of a unital `R`-algebra `A`, this is the natural algebra homomorphism sending `(r, a)` to `r • 1 + a`. The range of this map is `Algebra.adjoin R (s : Set A)`. * `NonUnitalSubalgebra.unitizationAlgEquiv s : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A)` when `R` is a field and `1 ∉ s`. This is `NonUnitalSubalgebra.unitization` upgraded to an `AlgEquiv` onto its range. * `NonUnitalSubsemiring.unitization : Unitization ℕ s →ₐ[ℕ] R`: the natural `ℕ`-algebra homomorphism from the unitization of a non-unital subsemiring `s` into the ring containing it. The range of this map is `subalgebraOfSubsemiring (Subsemiring.closure s)`. This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because there is an instance Lean can't find on its own due to `outParam`. * `NonUnitalSubring.unitization : Unitization ℤ s →ₐ[ℤ] R`: the natural `ℤ`-algebra homomorphism from the unitization of a non-unital subring `s` into the ring containing it. The range of this map is `subalgebraOfSubring (Subring.closure s)`. This is just `NonUnitalSubalgebra.unitization s` but we provide a separate declaration because there is an instance Lean can't find on its own due to `outParam`. * `NonUnitalStarSubalgebra s : Unitization R s →⋆ₐ[R] A`: a version of `NonUnitalSubalgebra.unitization` for star algebras. * `NonUnitalStarSubalgebra.unitizationStarAlgEquiv s :` `Unitization R s ≃⋆ₐ[R] StarAlgebra.adjoin R (s : Set A)`: a version of `NonUnitalSubalgebra.unitizationAlgEquiv` for star algebras. -/ /-! ## Subalgebras -/ section Subalgebra variable {R A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] /-- Turn a `Subalgebra` into a `NonUnitalSubalgebra` by forgetting that it contains `1`. -/ def Subalgebra.toNonUnitalSubalgebra (S : Subalgebra R A) : NonUnitalSubalgebra R A := { S with smul_mem' := fun r _x hx => S.smul_mem hx r } theorem Subalgebra.one_mem_toNonUnitalSubalgebra (S : Subalgebra R A) : (1 : A) ∈ S.toNonUnitalSubalgebra := S.one_mem /-- Turn a non-unital subalgebra containing `1` into a subalgebra. -/ def NonUnitalSubalgebra.toSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) : Subalgebra R A := { S with one_mem' := h1 algebraMap_mem' := fun r => (Algebra.algebraMap_eq_smul_one (R := R) (A := A) r).symm ▸ SMulMemClass.smul_mem r h1 } theorem Subalgebra.toNonUnitalSubalgebra_toSubalgebra (S : Subalgebra R A) : S.toNonUnitalSubalgebra.toSubalgebra S.one_mem = S := by cases S; rfl theorem NonUnitalSubalgebra.toSubalgebra_toNonUnitalSubalgebra (S : NonUnitalSubalgebra R A) (h1 : (1 : A) ∈ S) : (NonUnitalSubalgebra.toSubalgebra S h1).toNonUnitalSubalgebra = S := by cases S; rfl open Submodule in lemma Algebra.adjoin_nonUnitalSubalgebra_eq_span (s : NonUnitalSubalgebra R A) : Subalgebra.toSubmodule (adjoin R (s : Set A)) = span R {1} ⊔ s.toSubmodule := by rw [adjoin_eq_span, Submonoid.closure_eq_one_union, span_union, ← NonUnitalAlgebra.adjoin_eq_span, NonUnitalAlgebra.adjoin_eq] variable (R) lemma NonUnitalAlgebra.adjoin_le_algebra_adjoin (s : Set A) : adjoin R s ≤ (Algebra.adjoin R s).toNonUnitalSubalgebra := adjoin_le Algebra.subset_adjoin lemma Algebra.adjoin_nonUnitalSubalgebra (s : Set A) : adjoin R (NonUnitalAlgebra.adjoin R s : Set A) = adjoin R s := le_antisymm (adjoin_le <| NonUnitalAlgebra.adjoin_le_algebra_adjoin R s) (adjoin_le <| (NonUnitalAlgebra.subset_adjoin R).trans subset_adjoin) end Subalgebra namespace Unitization variable {R A C : Type*} [CommSemiring R] [NonUnitalSemiring A] variable [Module R A] [SMulCommClass R A A] [IsScalarTower R A A] [Semiring C] [Algebra R C] theorem lift_range_le {f : A →ₙₐ[R] C} {S : Subalgebra R C} : (lift f).range ≤ S ↔ NonUnitalAlgHom.range f ≤ S.toNonUnitalSubalgebra := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rintro - ⟨x, rfl⟩ exact @h (f x) ⟨x, by simp⟩ · rintro - ⟨x, rfl⟩ induction x with | _ r a => simpa using add_mem (algebraMap_mem S r) (h ⟨a, rfl⟩) theorem lift_range (f : A →ₙₐ[R] C) : (lift f).range = Algebra.adjoin R (NonUnitalAlgHom.range f : Set C) := eq_of_forall_ge_iff fun c ↦ by rw [lift_range_le, Algebra.adjoin_le_iff]; rfl end Unitization namespace NonUnitalSubalgebra section Semiring variable {R S A : Type*} [CommSemiring R] [Semiring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubsemiringClass S A] [hSRA : SMulMemClass S R A] (s : S) /-- The natural `R`-algebra homomorphism from the unitization of a non-unital subalgebra into the algebra containing it. -/ def unitization : Unitization R s →ₐ[R] A := Unitization.lift (NonUnitalSubalgebraClass.subtype s) @[simp] theorem unitization_apply (x : Unitization R s) : unitization s x = algebraMap R A x.fst + x.snd := rfl theorem unitization_range : (unitization s).range = Algebra.adjoin R (s : Set A) := by rw [unitization, Unitization.lift_range] simp only [NonUnitalAlgHom.coe_range, NonUnitalSubalgebraClass.coeSubtype, Subtype.range_coe_subtype, SetLike.mem_coe] rfl end Semiring /-- A sufficient condition for injectivity of `NonUnitalSubalgebra.unitization` when the scalars are a commutative ring. When the scalars are a field, one should use the more natural `NonUnitalStarSubalgebra.unitization_injective` whose hypothesis is easier to verify. -/ theorem _root_.AlgHomClass.unitization_injective' {F R S A : Type*} [CommRing R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) (h : ∀ r, r ≠ 0 → algebraMap R A r ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A] (f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by refine (injective_iff_map_eq_zero f).mpr fun x hx => ?_ induction' x with r a simp_rw [map_add, hf, ← Unitization.algebraMap_eq_inl, AlgHomClass.commutes] at hx rw [add_eq_zero_iff_eq_neg] at hx ⊢ by_cases hr : r = 0 · ext <;> simp [hr] at hx ⊢ exact hx · exact (h r hr <| hx ▸ (neg_mem a.property)).elim /-- This is a generic version which allows us to prove both `NonUnitalSubalgebra.unitization_injective` and `NonUnitalStarSubalgebra.unitization_injective`. -/ theorem _root_.AlgHomClass.unitization_injective {F R S A : Type*} [Field R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) (h1 : 1 ∉ s) [FunLike F (Unitization R s) A] [AlgHomClass F R (Unitization R s) A] (f : F) (hf : ∀ x : s, f x = x) : Function.Injective f := by refine AlgHomClass.unitization_injective' s (fun r hr hr' ↦ ?_) f hf rw [Algebra.algebraMap_eq_smul_one] at hr' exact h1 <| inv_smul_smul₀ hr (1 : A) ▸ SMulMemClass.smul_mem r⁻¹ hr' section Field variable {R S A : Type*} [Field R] [Ring A] [Algebra R A] [SetLike S A] [hSA : NonUnitalSubringClass S A] [hSRA : SMulMemClass S R A] (s : S) theorem unitization_injective (h1 : (1 : A) ∉ s) : Function.Injective (unitization s) := AlgHomClass.unitization_injective s h1 (unitization s) fun _ ↦ by simp /-- If a `NonUnitalSubalgebra` over a field does not contain `1`, then its unitization is isomorphic to its `Algebra.adjoin`. -/ @[simps! apply_coe] noncomputable def unitizationAlgEquiv (h1 : (1 : A) ∉ s) : Unitization R s ≃ₐ[R] Algebra.adjoin R (s : Set A) := let algHom : Unitization R s →ₐ[R] Algebra.adjoin R (s : Set A) := ((unitization s).codRestrict _ fun x ↦ (unitization_range s).le <| AlgHom.mem_range_self _ x) AlgEquiv.ofBijective algHom <| by refine ⟨?_, fun x ↦ ?_⟩ · have := AlgHomClass.unitization_injective s h1 ((Subalgebra.val _).comp algHom) fun _ ↦ by simp [algHom] rw [AlgHom.coe_comp] at this exact this.of_comp · obtain (⟨a, ha⟩ : (x : A) ∈ (unitization s).range) := (unitization_range s).ge x.property exact ⟨a, Subtype.ext ha⟩ end Field end NonUnitalSubalgebra /-! ## Subsemirings -/ section Subsemiring variable {R : Type*} [NonAssocSemiring R] /-- Turn a `Subsemiring` into a `NonUnitalSubsemiring` by forgetting that it contains `1`. -/ def Subsemiring.toNonUnitalSubsemiring (S : Subsemiring R) : NonUnitalSubsemiring R := { S with } theorem Subsemiring.one_mem_toNonUnitalSubsemiring (S : Subsemiring R) : (1 : R) ∈ S.toNonUnitalSubsemiring := S.one_mem /-- Turn a non-unital subsemiring containing `1` into a subsemiring. -/ def NonUnitalSubsemiring.toSubsemiring (S : NonUnitalSubsemiring R) (h1 : (1 : R) ∈ S) : Subsemiring R := { S with one_mem' := h1 } theorem Subsemiring.toNonUnitalSubsemiring_toSubsemiring (S : Subsemiring R) : S.toNonUnitalSubsemiring.toSubsemiring S.one_mem = S := by cases S; rfl theorem NonUnitalSubsemiring.toSubsemiring_toNonUnitalSubsemiring (S : NonUnitalSubsemiring R) (h1 : (1 : R) ∈ S) : (NonUnitalSubsemiring.toSubsemiring S h1).toNonUnitalSubsemiring = S := by cases S; rfl end Subsemiring namespace NonUnitalSubsemiring variable {R S : Type*} [Semiring R] [SetLike S R] [hSR : NonUnitalSubsemiringClass S R] (s : S) /-- The natural `ℕ`-algebra homomorphism from the unitization of a non-unital subsemiring to its `Subsemiring.closure`. -/ def unitization : Unitization ℕ s →ₐ[ℕ] R := NonUnitalSubalgebra.unitization (hSRA := AddSubmonoidClass.nsmulMemClass) s @[simp] theorem unitization_apply (x : Unitization ℕ s) : unitization s x = x.fst + x.snd := rfl
Mathlib/Algebra/Algebra/Subalgebra/Unitization.lean
241
244
theorem unitization_range : (unitization s).range = subalgebraOfSubsemiring (Subsemiring.closure s) := by
have := AddSubmonoidClass.nsmulMemClass (S := S) rw [unitization, NonUnitalSubalgebra.unitization_range (hSRA := this), Algebra.adjoin_nat]
/- Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Patrick Massot This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl. -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.Coset #align_import group_theory.quotient_group from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Quotients of groups by normal subgroups This files develops the basic theory of quotients of groups by normal subgroups. In particular it proves Noether's first and second isomorphism theorems. ## Main definitions * `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`. * `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that `N ⊆ ker φ`. * `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that `N ⊆ f⁻¹(M)`. ## Main statements * `QuotientGroup.quotientKerEquivRange`: Noether's first isomorphism theorem, an explicit isomorphism `G/ker φ → range φ` for every group homomorphism `φ : G →* H`. * `QuotientGroup.quotientInfEquivProdNormalQuotient`: Noether's second isomorphism theorem, an explicit isomorphism between `H/(H ∩ N)` and `(HN)/N` given a subgroup `H` and a normal subgroup `N` of a group `G`. * `QuotientGroup.quotientQuotientEquivQuotient`: Noether's third isomorphism theorem, the canonical isomorphism between `(G / N) / (M / N)` and `G / M`, where `N ≤ M`. ## Tags isomorphism theorems, quotient groups -/ open Function open scoped Pointwise universe u v w x namespace QuotientGroup variable {G : Type u} [Group G] (N : Subgroup G) [nN : N.Normal] {H : Type v} [Group H] {M : Type x} [Monoid M] /-- The congruence relation generated by a normal subgroup. -/ @[to_additive "The additive congruence relation generated by a normal additive subgroup."] protected def con : Con G where toSetoid := leftRel N mul' := @fun a b c d hab hcd => by rw [leftRel_eq] at hab hcd ⊢ dsimp only calc (a * c)⁻¹ * (b * d) = c⁻¹ * (a⁻¹ * b) * c⁻¹⁻¹ * (c⁻¹ * d) := by simp only [mul_inv_rev, mul_assoc, inv_mul_cancel_left] _ ∈ N := N.mul_mem (nN.conj_mem _ hab _) hcd #align quotient_group.con QuotientGroup.con #align quotient_add_group.con QuotientAddGroup.con @[to_additive] instance Quotient.group : Group (G ⧸ N) := (QuotientGroup.con N).group #align quotient_group.quotient.group QuotientGroup.Quotient.group #align quotient_add_group.quotient.add_group QuotientAddGroup.Quotient.addGroup /-- The group homomorphism from `G` to `G/N`. -/ @[to_additive "The additive group homomorphism from `G` to `G/N`."] def mk' : G →* G ⧸ N := MonoidHom.mk' QuotientGroup.mk fun _ _ => rfl #align quotient_group.mk' QuotientGroup.mk' #align quotient_add_group.mk' QuotientAddGroup.mk' @[to_additive (attr := simp)] theorem coe_mk' : (mk' N : G → G ⧸ N) = mk := rfl #align quotient_group.coe_mk' QuotientGroup.coe_mk' #align quotient_add_group.coe_mk' QuotientAddGroup.coe_mk' @[to_additive (attr := simp)] theorem mk'_apply (x : G) : mk' N x = x := rfl #align quotient_group.mk'_apply QuotientGroup.mk'_apply #align quotient_add_group.mk'_apply QuotientAddGroup.mk'_apply @[to_additive] theorem mk'_surjective : Surjective <| mk' N := @mk_surjective _ _ N #align quotient_group.mk'_surjective QuotientGroup.mk'_surjective #align quotient_add_group.mk'_surjective QuotientAddGroup.mk'_surjective @[to_additive] theorem mk'_eq_mk' {x y : G} : mk' N x = mk' N y ↔ ∃ z ∈ N, x * z = y := QuotientGroup.eq'.trans <| by simp only [← _root_.eq_inv_mul_iff_mul_eq, exists_prop, exists_eq_right] #align quotient_group.mk'_eq_mk' QuotientGroup.mk'_eq_mk' #align quotient_add_group.mk'_eq_mk' QuotientAddGroup.mk'_eq_mk' open scoped Pointwise in @[to_additive] theorem sound (U : Set (G ⧸ N)) (g : N.op) : g • (mk' N) ⁻¹' U = (mk' N) ⁻¹' U := by ext x simp only [Set.mem_preimage, Set.mem_smul_set_iff_inv_smul_mem] congr! 1 exact Quotient.sound ⟨g⁻¹, rfl⟩ /-- Two `MonoidHom`s from a quotient group are equal if their compositions with `QuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext 1100) "Two `AddMonoidHom`s from an additive quotient group are equal if their compositions with `AddQuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. "] theorem monoidHom_ext ⦃f g : G ⧸ N →* M⦄ (h : f.comp (mk' N) = g.comp (mk' N)) : f = g := MonoidHom.ext fun x => QuotientGroup.induction_on x <| (DFunLike.congr_fun h : _) #align quotient_group.monoid_hom_ext QuotientGroup.monoidHom_ext #align quotient_add_group.add_monoid_hom_ext QuotientAddGroup.addMonoidHom_ext @[to_additive (attr := simp)] theorem eq_one_iff {N : Subgroup G} [nN : N.Normal] (x : G) : (x : G ⧸ N) = 1 ↔ x ∈ N := by refine QuotientGroup.eq.trans ?_ rw [mul_one, Subgroup.inv_mem_iff] #align quotient_group.eq_one_iff QuotientGroup.eq_one_iff #align quotient_add_group.eq_zero_iff QuotientAddGroup.eq_zero_iff @[to_additive] theorem ker_le_range_iff {I : Type w} [Group I] (f : G →* H) [f.range.Normal] (g : H →* I) : g.ker ≤ f.range ↔ (mk' f.range).comp g.ker.subtype = 1 := ⟨fun h => MonoidHom.ext fun ⟨_, hx⟩ => (eq_one_iff _).mpr <| h hx, fun h x hx => (eq_one_iff _).mp <| by exact DFunLike.congr_fun h ⟨x, hx⟩⟩ @[to_additive (attr := simp)] theorem ker_mk' : MonoidHom.ker (QuotientGroup.mk' N : G →* G ⧸ N) = N := Subgroup.ext eq_one_iff #align quotient_group.ker_mk QuotientGroup.ker_mk' #align quotient_add_group.ker_mk QuotientAddGroup.ker_mk' -- Porting note: I think this is misnamed without the prime @[to_additive] theorem eq_iff_div_mem {N : Subgroup G} [nN : N.Normal] {x y : G} : (x : G ⧸ N) = y ↔ x / y ∈ N := by refine eq_comm.trans (QuotientGroup.eq.trans ?_) rw [nN.mem_comm_iff, div_eq_mul_inv] #align quotient_group.eq_iff_div_mem QuotientGroup.eq_iff_div_mem #align quotient_add_group.eq_iff_sub_mem QuotientAddGroup.eq_iff_sub_mem -- for commutative groups we don't need normality assumption @[to_additive] instance Quotient.commGroup {G : Type*} [CommGroup G] (N : Subgroup G) : CommGroup (G ⧸ N) := { toGroup := @QuotientGroup.Quotient.group _ _ N N.normal_of_comm mul_comm := fun a b => Quotient.inductionOn₂' a b fun a b => congr_arg mk (mul_comm a b) } #align quotient_group.quotient.comm_group QuotientGroup.Quotient.commGroup #align quotient_add_group.quotient.add_comm_group QuotientAddGroup.Quotient.addCommGroup local notation " Q " => G ⧸ N @[to_additive (attr := simp)] theorem mk_one : ((1 : G) : Q) = 1 := rfl #align quotient_group.coe_one QuotientGroup.mk_one #align quotient_add_group.coe_zero QuotientAddGroup.mk_zero @[to_additive (attr := simp)] theorem mk_mul (a b : G) : ((a * b : G) : Q) = a * b := rfl #align quotient_group.coe_mul QuotientGroup.mk_mul #align quotient_add_group.coe_add QuotientAddGroup.mk_add @[to_additive (attr := simp)] theorem mk_inv (a : G) : ((a⁻¹ : G) : Q) = (a : Q)⁻¹ := rfl #align quotient_group.coe_inv QuotientGroup.mk_inv #align quotient_add_group.coe_neg QuotientAddGroup.mk_neg @[to_additive (attr := simp)] theorem mk_div (a b : G) : ((a / b : G) : Q) = a / b := rfl #align quotient_group.coe_div QuotientGroup.mk_div #align quotient_add_group.coe_sub QuotientAddGroup.mk_sub @[to_additive (attr := simp)] theorem mk_pow (a : G) (n : ℕ) : ((a ^ n : G) : Q) = (a : Q) ^ n := rfl #align quotient_group.coe_pow QuotientGroup.mk_pow #align quotient_add_group.coe_nsmul QuotientAddGroup.mk_nsmul @[to_additive (attr := simp)] theorem mk_zpow (a : G) (n : ℤ) : ((a ^ n : G) : Q) = (a : Q) ^ n := rfl #align quotient_group.coe_zpow QuotientGroup.mk_zpow #align quotient_add_group.coe_zsmul QuotientAddGroup.mk_zsmul @[to_additive (attr := simp)] theorem mk_prod {G ι : Type*} [CommGroup G] (N : Subgroup G) (s : Finset ι) {f : ι → G} : ((Finset.prod s f : G) : G ⧸ N) = Finset.prod s (fun i => (f i : G ⧸ N)) := map_prod (QuotientGroup.mk' N) _ _ @[to_additive (attr := simp)] lemma map_mk'_self : N.map (mk' N) = ⊥ := by aesop /-- A group homomorphism `φ : G →* M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a group homomorphism `G/N →* M`. -/ @[to_additive "An `AddGroup` homomorphism `φ : G →+ M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a group homomorphism `G/N →* M`."] def lift (φ : G →* M) (HN : N ≤ φ.ker) : Q →* M := (QuotientGroup.con N).lift φ fun x y h => by simp only [QuotientGroup.con, leftRel_apply, Con.rel_mk] at h rw [Con.ker_rel] calc φ x = φ (y * (x⁻¹ * y)⁻¹) := by rw [mul_inv_rev, inv_inv, mul_inv_cancel_left] _ = φ y := by rw [φ.map_mul, HN (N.inv_mem h), mul_one] #align quotient_group.lift QuotientGroup.lift #align quotient_add_group.lift QuotientAddGroup.lift @[to_additive (attr := simp)] theorem lift_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (g : Q) = φ g := rfl #align quotient_group.lift_mk QuotientGroup.lift_mk #align quotient_add_group.lift_mk QuotientAddGroup.lift_mk @[to_additive (attr := simp)] theorem lift_mk' {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (mk g : Q) = φ g := rfl -- TODO: replace `mk` with `mk'`) #align quotient_group.lift_mk' QuotientGroup.lift_mk' #align quotient_add_group.lift_mk' QuotientAddGroup.lift_mk' @[to_additive (attr := simp)] theorem lift_quot_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (Quot.mk _ g : Q) = φ g := rfl #align quotient_group.lift_quot_mk QuotientGroup.lift_quot_mk #align quotient_add_group.lift_quot_mk QuotientAddGroup.lift_quot_mk /-- A group homomorphism `f : G →* H` induces a map `G/N →* H/M` if `N ⊆ f⁻¹(M)`. -/ @[to_additive "An `AddGroup` homomorphism `f : G →+ H` induces a map `G/N →+ H/M` if `N ⊆ f⁻¹(M)`."] def map (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) : G ⧸ N →* H ⧸ M := by refine QuotientGroup.lift N ((mk' M).comp f) ?_ intro x hx refine QuotientGroup.eq.2 ?_ rw [mul_one, Subgroup.inv_mem_iff] exact h hx #align quotient_group.map QuotientGroup.map #align quotient_add_group.map QuotientAddGroup.map @[to_additive (attr := simp)] theorem map_mk (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) : map N M f h ↑x = ↑(f x) := rfl #align quotient_group.map_coe QuotientGroup.map_mk #align quotient_add_group.map_coe QuotientAddGroup.map_mk @[to_additive] theorem map_mk' (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) : map N M f h (mk' _ x) = ↑(f x) := rfl #align quotient_group.map_mk' QuotientGroup.map_mk' #align quotient_add_group.map_mk' QuotientAddGroup.map_mk' @[to_additive] theorem map_id_apply (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) (x) : map N N (MonoidHom.id _) h x = x := induction_on' x fun _x => rfl #align quotient_group.map_id_apply QuotientGroup.map_id_apply #align quotient_add_group.map_id_apply QuotientAddGroup.map_id_apply @[to_additive (attr := simp)] theorem map_id (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) : map N N (MonoidHom.id _) h = MonoidHom.id _ := MonoidHom.ext (map_id_apply N h) #align quotient_group.map_id QuotientGroup.map_id #align quotient_add_group.map_id QuotientAddGroup.map_id @[to_additive (attr := simp)] theorem map_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal] (f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O) (hgf : N ≤ Subgroup.comap (g.comp f) O := hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _))) (x : G ⧸ N) : map M O g hg (map N M f hf x) = map N O (g.comp f) hgf x := by refine induction_on' x fun x => ?_ simp only [map_mk, MonoidHom.comp_apply] #align quotient_group.map_map QuotientGroup.map_map #align quotient_add_group.map_map QuotientAddGroup.map_map @[to_additive (attr := simp)] theorem map_comp_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal] (f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O) (hgf : N ≤ Subgroup.comap (g.comp f) O := hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _))) : (map M O g hg).comp (map N M f hf) = map N O (g.comp f) hgf := MonoidHom.ext (map_map N M O f g hf hg hgf) #align quotient_group.map_comp_map QuotientGroup.map_comp_map #align quotient_add_group.map_comp_map QuotientAddGroup.map_comp_map section Pointwise open Set @[to_additive (attr := simp)] lemma image_coe : ((↑) : G → Q) '' N = 1 := congr_arg ((↑) : Subgroup Q → Set Q) <| map_mk'_self N @[to_additive] lemma preimage_image_coe (s : Set G) : ((↑) : G → Q) ⁻¹' ((↑) '' s) = N * s := by ext a constructor · rintro ⟨b, hb, h⟩ refine ⟨a / b, (QuotientGroup.eq_one_iff _).1 ?_, b, hb, div_mul_cancel _ _⟩ simp only [h, QuotientGroup.mk_div, div_self'] · rintro ⟨a, ha, b, hb, rfl⟩ refine ⟨b, hb, ?_⟩ simpa only [QuotientGroup.mk_mul, self_eq_mul_left, QuotientGroup.eq_one_iff] @[to_additive] lemma image_coe_inj {s t : Set G} : ((↑) : G → Q) '' s = ((↑) : G → Q) '' t ↔ ↑N * s = N * t := by simp_rw [← preimage_image_coe] exact QuotientGroup.mk_surjective.preimage_injective.eq_iff.symm end Pointwise section congr variable (G' : Subgroup G) (H' : Subgroup H) [Subgroup.Normal G'] [Subgroup.Normal H'] /-- `QuotientGroup.congr` lifts the isomorphism `e : G ≃ H` to `G ⧸ G' ≃ H ⧸ H'`, given that `e` maps `G` to `H`. -/ @[to_additive "`QuotientAddGroup.congr` lifts the isomorphism `e : G ≃ H` to `G ⧸ G' ≃ H ⧸ H'`, given that `e` maps `G` to `H`."] def congr (e : G ≃* H) (he : G'.map e = H') : G ⧸ G' ≃* H ⧸ H' := { map G' H' e (he ▸ G'.le_comap_map (e : G →* H)) with toFun := map G' H' e (he ▸ G'.le_comap_map (e : G →* H)) invFun := map H' G' e.symm (he ▸ (G'.map_equiv_eq_comap_symm e).le) left_inv := fun x => by rw [map_map G' H' G' e e.symm (he ▸ G'.le_comap_map (e : G →* H)) (he ▸ (G'.map_equiv_eq_comap_symm e).le)] simp only [map_map, ← MulEquiv.coe_monoidHom_trans, MulEquiv.self_trans_symm, MulEquiv.coe_monoidHom_refl, map_id_apply] right_inv := fun x => by rw [map_map H' G' H' e.symm e (he ▸ (G'.map_equiv_eq_comap_symm e).le) (he ▸ G'.le_comap_map (e : G →* H)) ] simp only [← MulEquiv.coe_monoidHom_trans, MulEquiv.symm_trans_self, MulEquiv.coe_monoidHom_refl, map_id_apply] } #align quotient_group.congr QuotientGroup.congr #align quotient_add_group.congr QuotientAddGroup.congr @[simp] theorem congr_mk (e : G ≃* H) (he : G'.map ↑e = H') (x) : congr G' H' e he (mk x) = e x := rfl #align quotient_group.congr_mk QuotientGroup.congr_mk theorem congr_mk' (e : G ≃* H) (he : G'.map ↑e = H') (x) : congr G' H' e he (mk' G' x) = mk' H' (e x) := rfl #align quotient_group.congr_mk' QuotientGroup.congr_mk' @[simp] theorem congr_apply (e : G ≃* H) (he : G'.map ↑e = H') (x : G) : congr G' H' e he x = mk' H' (e x) := rfl #align quotient_group.congr_apply QuotientGroup.congr_apply @[simp] theorem congr_refl (he : G'.map (MulEquiv.refl G : G →* G) = G' := Subgroup.map_id G') : congr G' G' (MulEquiv.refl G) he = MulEquiv.refl (G ⧸ G') := by ext ⟨x⟩ rfl #align quotient_group.congr_refl QuotientGroup.congr_refl @[simp] theorem congr_symm (e : G ≃* H) (he : G'.map ↑e = H') : (congr G' H' e he).symm = congr H' G' e.symm ((Subgroup.map_symm_eq_iff_map_eq _).mpr he) := rfl #align quotient_group.congr_symm QuotientGroup.congr_symm end congr variable (φ : G →* H) open MonoidHom /-- The induced map from the quotient by the kernel to the codomain. -/ @[to_additive "The induced map from the quotient by the kernel to the codomain."] def kerLift : G ⧸ ker φ →* H := lift _ φ fun _g => φ.mem_ker.mp #align quotient_group.ker_lift QuotientGroup.kerLift #align quotient_add_group.ker_lift QuotientAddGroup.kerLift @[to_additive (attr := simp)] theorem kerLift_mk (g : G) : (kerLift φ) g = φ g := lift_mk _ _ _ #align quotient_group.ker_lift_mk QuotientGroup.kerLift_mk #align quotient_add_group.ker_lift_mk QuotientAddGroup.kerLift_mk @[to_additive (attr := simp)] theorem kerLift_mk' (g : G) : (kerLift φ) (mk g) = φ g := lift_mk' _ _ _ #align quotient_group.ker_lift_mk' QuotientGroup.kerLift_mk' #align quotient_add_group.ker_lift_mk' QuotientAddGroup.kerLift_mk' @[to_additive] theorem kerLift_injective : Injective (kerLift φ) := fun a b => Quotient.inductionOn₂' a b fun a b (h : φ a = φ b) => Quotient.sound' <| by rw [leftRel_apply, mem_ker, φ.map_mul, ← h, φ.map_inv, inv_mul_self] #align quotient_group.ker_lift_injective QuotientGroup.kerLift_injective #align quotient_add_group.ker_lift_injective QuotientAddGroup.kerLift_injective -- Note that `ker φ` isn't definitionally `ker (φ.rangeRestrict)` -- so there is a bit of annoying code duplication here /-- The induced map from the quotient by the kernel to the range. -/ @[to_additive "The induced map from the quotient by the kernel to the range."] def rangeKerLift : G ⧸ ker φ →* φ.range := lift _ φ.rangeRestrict fun g hg => (mem_ker _).mp <| by rwa [ker_rangeRestrict] #align quotient_group.range_ker_lift QuotientGroup.rangeKerLift #align quotient_add_group.range_ker_lift QuotientAddGroup.rangeKerLift @[to_additive] theorem rangeKerLift_injective : Injective (rangeKerLift φ) := fun a b => Quotient.inductionOn₂' a b fun a b (h : φ.rangeRestrict a = φ.rangeRestrict b) => Quotient.sound' <| by rw [leftRel_apply, ← ker_rangeRestrict, mem_ker, φ.rangeRestrict.map_mul, ← h, φ.rangeRestrict.map_inv, inv_mul_self] #align quotient_group.range_ker_lift_injective QuotientGroup.rangeKerLift_injective #align quotient_add_group.range_ker_lift_injective QuotientAddGroup.rangeKerLift_injective @[to_additive] theorem rangeKerLift_surjective : Surjective (rangeKerLift φ) := by rintro ⟨_, g, rfl⟩ use mk g rfl #align quotient_group.range_ker_lift_surjective QuotientGroup.rangeKerLift_surjective #align quotient_add_group.range_ker_lift_surjective QuotientAddGroup.rangeKerLift_surjective /-- **Noether's first isomorphism theorem** (a definition): the canonical isomorphism between `G/(ker φ)` to `range φ`. -/ @[to_additive "The first isomorphism theorem (a definition): the canonical isomorphism between `G/(ker φ)` to `range φ`."] noncomputable def quotientKerEquivRange : G ⧸ ker φ ≃* range φ := MulEquiv.ofBijective (rangeKerLift φ) ⟨rangeKerLift_injective φ, rangeKerLift_surjective φ⟩ #align quotient_group.quotient_ker_equiv_range QuotientGroup.quotientKerEquivRange #align quotient_add_group.quotient_ker_equiv_range QuotientAddGroup.quotientKerEquivRange /-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a homomorphism `φ : G →* H` with a right inverse `ψ : H → G`. -/ @[to_additive (attr := simps) "The canonical isomorphism `G/(ker φ) ≃+ H` induced by a homomorphism `φ : G →+ H` with a right inverse `ψ : H → G`."] def quotientKerEquivOfRightInverse (ψ : H → G) (hφ : RightInverse ψ φ) : G ⧸ ker φ ≃* H := { kerLift φ with toFun := kerLift φ invFun := mk ∘ ψ left_inv := fun x => kerLift_injective φ (by rw [Function.comp_apply, kerLift_mk', hφ]) right_inv := hφ } #align quotient_group.quotient_ker_equiv_of_right_inverse QuotientGroup.quotientKerEquivOfRightInverse #align quotient_add_group.quotient_ker_equiv_of_right_inverse QuotientAddGroup.quotientKerEquivOfRightInverse /-- The canonical isomorphism `G/⊥ ≃* G`. -/ @[to_additive (attr := simps!) "The canonical isomorphism `G/⊥ ≃+ G`."] def quotientBot : G ⧸ (⊥ : Subgroup G) ≃* G := quotientKerEquivOfRightInverse (MonoidHom.id G) id fun _x => rfl #align quotient_group.quotient_bot QuotientGroup.quotientBot #align quotient_add_group.quotient_bot QuotientAddGroup.quotientBot /-- The canonical isomorphism `G/(ker φ) ≃* H` induced by a surjection `φ : G →* H`. For a `computable` version, see `QuotientGroup.quotientKerEquivOfRightInverse`. -/ @[to_additive "The canonical isomorphism `G/(ker φ) ≃+ H` induced by a surjection `φ : G →+ H`. For a `computable` version, see `QuotientAddGroup.quotientKerEquivOfRightInverse`."] noncomputable def quotientKerEquivOfSurjective (hφ : Surjective φ) : G ⧸ ker φ ≃* H := quotientKerEquivOfRightInverse φ _ hφ.hasRightInverse.choose_spec #align quotient_group.quotient_ker_equiv_of_surjective QuotientGroup.quotientKerEquivOfSurjective #align quotient_add_group.quotient_ker_equiv_of_surjective QuotientAddGroup.quotientKerEquivOfSurjective /-- If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are isomorphic. -/ @[to_additive "If two normal subgroups `M` and `N` of `G` are the same, their quotient groups are isomorphic."] def quotientMulEquivOfEq {M N : Subgroup G} [M.Normal] [N.Normal] (h : M = N) : G ⧸ M ≃* G ⧸ N := { Subgroup.quotientEquivOfEq h with map_mul' := fun q r => Quotient.inductionOn₂' q r fun _g _h => rfl } #align quotient_group.quotient_mul_equiv_of_eq QuotientGroup.quotientMulEquivOfEq #align quotient_add_group.quotient_add_equiv_of_eq QuotientAddGroup.quotientAddEquivOfEq @[to_additive (attr := simp)] theorem quotientMulEquivOfEq_mk {M N : Subgroup G} [M.Normal] [N.Normal] (h : M = N) (x : G) : QuotientGroup.quotientMulEquivOfEq h (QuotientGroup.mk x) = QuotientGroup.mk x := rfl #align quotient_group.quotient_mul_equiv_of_eq_mk QuotientGroup.quotientMulEquivOfEq_mk #align quotient_add_group.quotient_add_equiv_of_eq_mk QuotientAddGroup.quotientAddEquivOfEq_mk /-- Let `A', A, B', B` be subgroups of `G`. If `A' ≤ B'` and `A ≤ B`, then there is a map `A / (A' ⊓ A) →* B / (B' ⊓ B)` induced by the inclusions. -/ @[to_additive "Let `A', A, B', B` be subgroups of `G`. If `A' ≤ B'` and `A ≤ B`, then there is a map `A / (A' ⊓ A) →+ B / (B' ⊓ B)` induced by the inclusions."] def quotientMapSubgroupOfOfLe {A' A B' B : Subgroup G} [_hAN : (A'.subgroupOf A).Normal] [_hBN : (B'.subgroupOf B).Normal] (h' : A' ≤ B') (h : A ≤ B) : A ⧸ A'.subgroupOf A →* B ⧸ B'.subgroupOf B := map _ _ (Subgroup.inclusion h) <| Subgroup.comap_mono h' #align quotient_group.quotient_map_subgroup_of_of_le QuotientGroup.quotientMapSubgroupOfOfLe #align quotient_add_group.quotient_map_add_subgroup_of_of_le QuotientAddGroup.quotientMapAddSubgroupOfOfLe @[to_additive (attr := simp)] theorem quotientMapSubgroupOfOfLe_mk {A' A B' B : Subgroup G} [_hAN : (A'.subgroupOf A).Normal] [_hBN : (B'.subgroupOf B).Normal] (h' : A' ≤ B') (h : A ≤ B) (x : A) : quotientMapSubgroupOfOfLe h' h x = ↑(Subgroup.inclusion h x : B) := rfl #align quotient_group.quotient_map_subgroup_of_of_le_coe QuotientGroup.quotientMapSubgroupOfOfLe_mk #align quotient_add_group.quotient_map_add_subgroup_of_of_le_coe QuotientAddGroup.quotientMapAddSubgroupOfOfLe_mk /-- Let `A', A, B', B` be subgroups of `G`. If `A' = B'` and `A = B`, then the quotients `A / (A' ⊓ A)` and `B / (B' ⊓ B)` are isomorphic. Applying this equiv is nicer than rewriting along the equalities, since the type of `(A'.subgroupOf A : Subgroup A)` depends on `A`. -/ @[to_additive "Let `A', A, B', B` be subgroups of `G`. If `A' = B'` and `A = B`, then the quotients `A / (A' ⊓ A)` and `B / (B' ⊓ B)` are isomorphic. Applying this equiv is nicer than rewriting along the equalities, since the type of `(A'.addSubgroupOf A : AddSubgroup A)` depends on on `A`. "] def equivQuotientSubgroupOfOfEq {A' A B' B : Subgroup G} [hAN : (A'.subgroupOf A).Normal] [hBN : (B'.subgroupOf B).Normal] (h' : A' = B') (h : A = B) : A ⧸ A'.subgroupOf A ≃* B ⧸ B'.subgroupOf B := MonoidHom.toMulEquiv (quotientMapSubgroupOfOfLe h'.le h.le) (quotientMapSubgroupOfOfLe h'.ge h.ge) (by ext ⟨x, hx⟩; rfl) (by ext ⟨x, hx⟩; rfl) #align quotient_group.equiv_quotient_subgroup_of_of_eq QuotientGroup.equivQuotientSubgroupOfOfEq #align quotient_add_group.equiv_quotient_add_subgroup_of_of_eq QuotientAddGroup.equivQuotientAddSubgroupOfOfEq section ZPow variable {A B C : Type u} [CommGroup A] [CommGroup B] [CommGroup C] variable (f : A →* B) (g : B →* A) (e : A ≃* B) (d : B ≃* C) (n : ℤ) /-- The map of quotients by powers of an integer induced by a group homomorphism. -/ @[to_additive "The map of quotients by multiples of an integer induced by an additive group homomorphism."] def homQuotientZPowOfHom : A ⧸ (zpowGroupHom n : A →* A).range →* B ⧸ (zpowGroupHom n : B →* B).range := lift _ ((mk' _).comp f) fun g ⟨h, (hg : h ^ n = g)⟩ => (eq_one_iff _).mpr ⟨f h, by simp only [← hg, map_zpow, zpowGroupHom_apply]⟩ #align quotient_group.hom_quotient_zpow_of_hom QuotientGroup.homQuotientZPowOfHom #align quotient_add_group.hom_quotient_zsmul_of_hom QuotientAddGroup.homQuotientZSMulOfHom @[to_additive (attr := simp)] theorem homQuotientZPowOfHom_id : homQuotientZPowOfHom (MonoidHom.id A) n = MonoidHom.id _ := monoidHom_ext _ rfl #align quotient_group.hom_quotient_zpow_of_hom_id QuotientGroup.homQuotientZPowOfHom_id #align quotient_add_group.hom_quotient_zsmul_of_hom_id QuotientAddGroup.homQuotientZSMulOfHom_id @[to_additive (attr := simp)] theorem homQuotientZPowOfHom_comp : homQuotientZPowOfHom (f.comp g) n = (homQuotientZPowOfHom f n).comp (homQuotientZPowOfHom g n) := monoidHom_ext _ rfl #align quotient_group.hom_quotient_zpow_of_hom_comp QuotientGroup.homQuotientZPowOfHom_comp #align quotient_add_group.hom_quotient_zsmul_of_hom_comp QuotientAddGroup.homQuotientZSMulOfHom_comp @[to_additive (attr := simp)] theorem homQuotientZPowOfHom_comp_of_rightInverse (i : Function.RightInverse g f) : (homQuotientZPowOfHom f n).comp (homQuotientZPowOfHom g n) = MonoidHom.id _ := monoidHom_ext _ <| MonoidHom.ext fun x => congrArg _ <| i x #align quotient_group.hom_quotient_zpow_of_hom_comp_of_right_inverse QuotientGroup.homQuotientZPowOfHom_comp_of_rightInverse #align quotient_add_group.hom_quotient_zsmul_of_hom_comp_of_right_inverse QuotientAddGroup.homQuotientZSMulOfHom_comp_of_rightInverse /-- The equivalence of quotients by powers of an integer induced by a group isomorphism. -/ @[to_additive "The equivalence of quotients by multiples of an integer induced by an additive group isomorphism."] def equivQuotientZPowOfEquiv : A ⧸ (zpowGroupHom n : A →* A).range ≃* B ⧸ (zpowGroupHom n : B →* B).range := MonoidHom.toMulEquiv _ _ (homQuotientZPowOfHom_comp_of_rightInverse (e.symm : B →* A) (e : A →* B) n e.left_inv) (homQuotientZPowOfHom_comp_of_rightInverse (e : A →* B) (e.symm : B →* A) n e.right_inv) -- Porting note: had to explicitly coerce the `MulEquiv`s to `MonoidHom`s #align quotient_group.equiv_quotient_zpow_of_equiv QuotientGroup.equivQuotientZPowOfEquiv #align quotient_add_group.equiv_quotient_zsmul_of_equiv QuotientAddGroup.equivQuotientZSMulOfEquiv @[to_additive (attr := simp)] theorem equivQuotientZPowOfEquiv_refl : MulEquiv.refl (A ⧸ (zpowGroupHom n : A →* A).range) = equivQuotientZPowOfEquiv (MulEquiv.refl A) n := by ext x rw [← Quotient.out_eq' x] rfl #align quotient_group.equiv_quotient_zpow_of_equiv_refl QuotientGroup.equivQuotientZPowOfEquiv_refl #align quotient_add_group.equiv_quotient_zsmul_of_equiv_refl QuotientAddGroup.equivQuotientZSMulOfEquiv_refl @[to_additive (attr := simp)] theorem equivQuotientZPowOfEquiv_symm : (equivQuotientZPowOfEquiv e n).symm = equivQuotientZPowOfEquiv e.symm n := rfl #align quotient_group.equiv_quotient_zpow_of_equiv_symm QuotientGroup.equivQuotientZPowOfEquiv_symm #align quotient_add_group.equiv_quotient_zsmul_of_equiv_symm QuotientAddGroup.equivQuotientZSMulOfEquiv_symm @[to_additive (attr := simp)] theorem equivQuotientZPowOfEquiv_trans : (equivQuotientZPowOfEquiv e n).trans (equivQuotientZPowOfEquiv d n) = equivQuotientZPowOfEquiv (e.trans d) n := by ext x rw [← Quotient.out_eq' x] rfl #align quotient_group.equiv_quotient_zpow_of_equiv_trans QuotientGroup.equivQuotientZPowOfEquiv_trans #align quotient_add_group.equiv_quotient_zsmul_of_equiv_trans QuotientAddGroup.equivQuotientZSMulOfEquiv_trans end ZPow section SndIsomorphismThm open Subgroup /-- **Noether's second isomorphism theorem**: given two subgroups `H` and `N` of a group `G`, where `N` is normal, defines an isomorphism between `H/(H ∩ N)` and `(HN)/N`. -/ @[to_additive "The second isomorphism theorem: given two subgroups `H` and `N` of a group `G`, where `N` is normal, defines an isomorphism between `H/(H ∩ N)` and `(H + N)/N`"] noncomputable def quotientInfEquivProdNormalQuotient (H N : Subgroup G) [N.Normal] : H ⧸ N.subgroupOf H ≃* _ ⧸ N.subgroupOf (H ⊔ N) := let φ :-- φ is the natural homomorphism H →* (HN)/N. H →* _ ⧸ N.subgroupOf (H ⊔ N) := (mk' <| N.subgroupOf (H ⊔ N)).comp (inclusion le_sup_left) have φ_surjective : Surjective φ := fun x => x.inductionOn' <| by rintro ⟨y, hy : y ∈ (H ⊔ N)⟩; rw [← SetLike.mem_coe] at hy rw [mul_normal H N] at hy rcases hy with ⟨h, hh, n, hn, rfl⟩ use ⟨h, hh⟩ let _ : Setoid ↑(H ⊔ N) := (@leftRel ↑(H ⊔ N) (H ⊔ N : Subgroup G).toGroup (N.subgroupOf (H ⊔ N))) -- Porting note: Lean couldn't find this automatically refine Quotient.eq.mpr ?_ change Setoid.r _ _ rw [leftRel_apply] change h⁻¹ * (h * n) ∈ N rwa [← mul_assoc, inv_mul_self, one_mul] (quotientMulEquivOfEq (by simp [φ, ← comap_ker])).trans (quotientKerEquivOfSurjective φ φ_surjective) #align quotient_group.quotient_inf_equiv_prod_normal_quotient QuotientGroup.quotientInfEquivProdNormalQuotient #align quotient_add_group.quotient_inf_equiv_sum_normal_quotient QuotientAddGroup.quotientInfEquivSumNormalQuotient end SndIsomorphismThm section ThirdIsoThm variable (M : Subgroup G) [nM : M.Normal] @[to_additive] instance map_normal : (M.map (QuotientGroup.mk' N)).Normal := nM.map _ mk_surjective #align quotient_group.map_normal QuotientGroup.map_normal #align quotient_add_group.map_normal QuotientAddGroup.map_normal variable (h : N ≤ M) /-- The map from the third isomorphism theorem for groups: `(G / N) / (M / N) → G / M`. -/ @[to_additive "The map from the third isomorphism theorem for additive groups: `(A / N) / (M / N) → A / M`."] def quotientQuotientEquivQuotientAux : (G ⧸ N) ⧸ M.map (mk' N) →* G ⧸ M := lift (M.map (mk' N)) (map N M (MonoidHom.id G) h) (by rintro _ ⟨x, hx, rfl⟩ rw [mem_ker, map_mk' N M _ _ x] exact (QuotientGroup.eq_one_iff _).mpr hx) #align quotient_group.quotient_quotient_equiv_quotient_aux QuotientGroup.quotientQuotientEquivQuotientAux #align quotient_add_group.quotient_quotient_equiv_quotient_aux QuotientAddGroup.quotientQuotientEquivQuotientAux @[to_additive (attr := simp)] theorem quotientQuotientEquivQuotientAux_mk (x : G ⧸ N) : quotientQuotientEquivQuotientAux N M h x = QuotientGroup.map N M (MonoidHom.id G) h x := QuotientGroup.lift_mk' _ _ x #align quotient_group.quotient_quotient_equiv_quotient_aux_coe QuotientGroup.quotientQuotientEquivQuotientAux_mk #align quotient_add_group.quotient_quotient_equiv_quotient_aux_coe QuotientAddGroup.quotientQuotientEquivQuotientAux_mk @[to_additive] theorem quotientQuotientEquivQuotientAux_mk_mk (x : G) : quotientQuotientEquivQuotientAux N M h (x : G ⧸ N) = x := QuotientGroup.lift_mk' (M.map (mk' N)) _ x #align quotient_group.quotient_quotient_equiv_quotient_aux_coe_coe QuotientGroup.quotientQuotientEquivQuotientAux_mk_mk #align quotient_add_group.quotient_quotient_equiv_quotient_aux_coe_coe QuotientAddGroup.quotientQuotientEquivQuotientAux_mk_mk /-- **Noether's third isomorphism theorem** for groups: `(G / N) / (M / N) ≃* G / M`. -/ @[to_additive "**Noether's third isomorphism theorem** for additive groups: `(A / N) / (M / N) ≃+ A / M`."] def quotientQuotientEquivQuotient : (G ⧸ N) ⧸ M.map (QuotientGroup.mk' N) ≃* G ⧸ M := MonoidHom.toMulEquiv (quotientQuotientEquivQuotientAux N M h) (QuotientGroup.map _ _ (QuotientGroup.mk' N) (Subgroup.le_comap_map _ _)) (by ext; simp) (by ext; simp) #align quotient_group.quotient_quotient_equiv_quotient QuotientGroup.quotientQuotientEquivQuotient #align quotient_add_group.quotient_quotient_equiv_quotient QuotientAddGroup.quotientQuotientEquivQuotient end ThirdIsoThm section trivial @[to_additive]
Mathlib/GroupTheory/QuotientGroup.lean
704
707
theorem subsingleton_quotient_top : Subsingleton (G ⧸ (⊤ : Subgroup G)) := by
dsimp [HasQuotient.Quotient, QuotientGroup.instHasQuotientSubgroup, Quotient] rw [leftRel_eq] exact Trunc.instSubsingletonTrunc
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot, Yury Kudryashov, Rémy Degenne -/ import Mathlib.Order.MinMax import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.Says #align_import data.set.intervals.basic from "leanprover-community/mathlib"@"3ba15165bd6927679be7c22d6091a87337e3cd0c" /-! # Intervals In any preorder `α`, we define intervals (which on each side can be either infinite, open, or closed) using the following naming conventions: - `i`: infinite - `o`: open - `c`: closed Each interval has the name `I` + letter for left side + letter for right side. For instance, `Ioc a b` denotes the interval `(a, b]`. This file contains these definitions, and basic facts on inclusion, intersection, difference of intervals (where the precise statements may depend on the properties of the order, in particular for some statements it should be `LinearOrder` or `DenselyOrdered`). TODO: This is just the beginning; a lot of rules are missing -/ open Function open OrderDual (toDual ofDual) variable {α β : Type*} namespace Set section Preorder variable [Preorder α] {a a₁ a₂ b b₁ b₂ c x : α} /-- Left-open right-open interval -/ def Ioo (a b : α) := { x | a < x ∧ x < b } #align set.Ioo Set.Ioo /-- Left-closed right-open interval -/ def Ico (a b : α) := { x | a ≤ x ∧ x < b } #align set.Ico Set.Ico /-- Left-infinite right-open interval -/ def Iio (a : α) := { x | x < a } #align set.Iio Set.Iio /-- Left-closed right-closed interval -/ def Icc (a b : α) := { x | a ≤ x ∧ x ≤ b } #align set.Icc Set.Icc /-- Left-infinite right-closed interval -/ def Iic (b : α) := { x | x ≤ b } #align set.Iic Set.Iic /-- Left-open right-closed interval -/ def Ioc (a b : α) := { x | a < x ∧ x ≤ b } #align set.Ioc Set.Ioc /-- Left-closed right-infinite interval -/ def Ici (a : α) := { x | a ≤ x } #align set.Ici Set.Ici /-- Left-open right-infinite interval -/ def Ioi (a : α) := { x | a < x } #align set.Ioi Set.Ioi theorem Ioo_def (a b : α) : { x | a < x ∧ x < b } = Ioo a b := rfl #align set.Ioo_def Set.Ioo_def theorem Ico_def (a b : α) : { x | a ≤ x ∧ x < b } = Ico a b := rfl #align set.Ico_def Set.Ico_def theorem Iio_def (a : α) : { x | x < a } = Iio a := rfl #align set.Iio_def Set.Iio_def theorem Icc_def (a b : α) : { x | a ≤ x ∧ x ≤ b } = Icc a b := rfl #align set.Icc_def Set.Icc_def theorem Iic_def (b : α) : { x | x ≤ b } = Iic b := rfl #align set.Iic_def Set.Iic_def theorem Ioc_def (a b : α) : { x | a < x ∧ x ≤ b } = Ioc a b := rfl #align set.Ioc_def Set.Ioc_def theorem Ici_def (a : α) : { x | a ≤ x } = Ici a := rfl #align set.Ici_def Set.Ici_def theorem Ioi_def (a : α) : { x | a < x } = Ioi a := rfl #align set.Ioi_def Set.Ioi_def @[simp] theorem mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := Iff.rfl #align set.mem_Ioo Set.mem_Ioo @[simp] theorem mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := Iff.rfl #align set.mem_Ico Set.mem_Ico @[simp] theorem mem_Iio : x ∈ Iio b ↔ x < b := Iff.rfl #align set.mem_Iio Set.mem_Iio @[simp] theorem mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := Iff.rfl #align set.mem_Icc Set.mem_Icc @[simp] theorem mem_Iic : x ∈ Iic b ↔ x ≤ b := Iff.rfl #align set.mem_Iic Set.mem_Iic @[simp] theorem mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := Iff.rfl #align set.mem_Ioc Set.mem_Ioc @[simp] theorem mem_Ici : x ∈ Ici a ↔ a ≤ x := Iff.rfl #align set.mem_Ici Set.mem_Ici @[simp] theorem mem_Ioi : x ∈ Ioi a ↔ a < x := Iff.rfl #align set.mem_Ioi Set.mem_Ioi instance decidableMemIoo [Decidable (a < x ∧ x < b)] : Decidable (x ∈ Ioo a b) := by assumption #align set.decidable_mem_Ioo Set.decidableMemIoo instance decidableMemIco [Decidable (a ≤ x ∧ x < b)] : Decidable (x ∈ Ico a b) := by assumption #align set.decidable_mem_Ico Set.decidableMemIco instance decidableMemIio [Decidable (x < b)] : Decidable (x ∈ Iio b) := by assumption #align set.decidable_mem_Iio Set.decidableMemIio instance decidableMemIcc [Decidable (a ≤ x ∧ x ≤ b)] : Decidable (x ∈ Icc a b) := by assumption #align set.decidable_mem_Icc Set.decidableMemIcc instance decidableMemIic [Decidable (x ≤ b)] : Decidable (x ∈ Iic b) := by assumption #align set.decidable_mem_Iic Set.decidableMemIic instance decidableMemIoc [Decidable (a < x ∧ x ≤ b)] : Decidable (x ∈ Ioc a b) := by assumption #align set.decidable_mem_Ioc Set.decidableMemIoc instance decidableMemIci [Decidable (a ≤ x)] : Decidable (x ∈ Ici a) := by assumption #align set.decidable_mem_Ici Set.decidableMemIci instance decidableMemIoi [Decidable (a < x)] : Decidable (x ∈ Ioi a) := by assumption #align set.decidable_mem_Ioi Set.decidableMemIoi -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioo : a ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioo Set.left_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl] #align set.left_mem_Ico Set.left_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.left_mem_Icc Set.left_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem left_mem_Ioc : a ∈ Ioc a b ↔ False := by simp [lt_irrefl] #align set.left_mem_Ioc Set.left_mem_Ioc theorem left_mem_Ici : a ∈ Ici a := by simp #align set.left_mem_Ici Set.left_mem_Ici -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioo : b ∈ Ioo a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ioo Set.right_mem_Ioo -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ico : b ∈ Ico a b ↔ False := by simp [lt_irrefl] #align set.right_mem_Ico Set.right_mem_Ico -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl] #align set.right_mem_Icc Set.right_mem_Icc -- Porting note (#10618): `simp` can prove this -- @[simp] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl] #align set.right_mem_Ioc Set.right_mem_Ioc theorem right_mem_Iic : a ∈ Iic a := by simp #align set.right_mem_Iic Set.right_mem_Iic @[simp] theorem dual_Ici : Ici (toDual a) = ofDual ⁻¹' Iic a := rfl #align set.dual_Ici Set.dual_Ici @[simp] theorem dual_Iic : Iic (toDual a) = ofDual ⁻¹' Ici a := rfl #align set.dual_Iic Set.dual_Iic @[simp] theorem dual_Ioi : Ioi (toDual a) = ofDual ⁻¹' Iio a := rfl #align set.dual_Ioi Set.dual_Ioi @[simp] theorem dual_Iio : Iio (toDual a) = ofDual ⁻¹' Ioi a := rfl #align set.dual_Iio Set.dual_Iio @[simp] theorem dual_Icc : Icc (toDual a) (toDual b) = ofDual ⁻¹' Icc b a := Set.ext fun _ => and_comm #align set.dual_Icc Set.dual_Icc @[simp] theorem dual_Ioc : Ioc (toDual a) (toDual b) = ofDual ⁻¹' Ico b a := Set.ext fun _ => and_comm #align set.dual_Ioc Set.dual_Ioc @[simp] theorem dual_Ico : Ico (toDual a) (toDual b) = ofDual ⁻¹' Ioc b a := Set.ext fun _ => and_comm #align set.dual_Ico Set.dual_Ico @[simp] theorem dual_Ioo : Ioo (toDual a) (toDual b) = ofDual ⁻¹' Ioo b a := Set.ext fun _ => and_comm #align set.dual_Ioo Set.dual_Ioo @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≤ b := ⟨fun ⟨_, hx⟩ => hx.1.trans hx.2, fun h => ⟨a, left_mem_Icc.2 h⟩⟩ #align set.nonempty_Icc Set.nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_lt hx.2, fun h => ⟨a, left_mem_Ico.2 h⟩⟩ #align set.nonempty_Ico Set.nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := ⟨fun ⟨_, hx⟩ => hx.1.trans_le hx.2, fun h => ⟨b, right_mem_Ioc.2 h⟩⟩ #align set.nonempty_Ioc Set.nonempty_Ioc @[simp] theorem nonempty_Ici : (Ici a).Nonempty := ⟨a, left_mem_Ici⟩ #align set.nonempty_Ici Set.nonempty_Ici @[simp] theorem nonempty_Iic : (Iic a).Nonempty := ⟨a, right_mem_Iic⟩ #align set.nonempty_Iic Set.nonempty_Iic @[simp] theorem nonempty_Ioo [DenselyOrdered α] : (Ioo a b).Nonempty ↔ a < b := ⟨fun ⟨_, ha, hb⟩ => ha.trans hb, exists_between⟩ #align set.nonempty_Ioo Set.nonempty_Ioo @[simp] theorem nonempty_Ioi [NoMaxOrder α] : (Ioi a).Nonempty := exists_gt a #align set.nonempty_Ioi Set.nonempty_Ioi @[simp] theorem nonempty_Iio [NoMinOrder α] : (Iio a).Nonempty := exists_lt a #align set.nonempty_Iio Set.nonempty_Iio theorem nonempty_Icc_subtype (h : a ≤ b) : Nonempty (Icc a b) := Nonempty.to_subtype (nonempty_Icc.mpr h) #align set.nonempty_Icc_subtype Set.nonempty_Icc_subtype theorem nonempty_Ico_subtype (h : a < b) : Nonempty (Ico a b) := Nonempty.to_subtype (nonempty_Ico.mpr h) #align set.nonempty_Ico_subtype Set.nonempty_Ico_subtype theorem nonempty_Ioc_subtype (h : a < b) : Nonempty (Ioc a b) := Nonempty.to_subtype (nonempty_Ioc.mpr h) #align set.nonempty_Ioc_subtype Set.nonempty_Ioc_subtype /-- An interval `Ici a` is nonempty. -/ instance nonempty_Ici_subtype : Nonempty (Ici a) := Nonempty.to_subtype nonempty_Ici #align set.nonempty_Ici_subtype Set.nonempty_Ici_subtype /-- An interval `Iic a` is nonempty. -/ instance nonempty_Iic_subtype : Nonempty (Iic a) := Nonempty.to_subtype nonempty_Iic #align set.nonempty_Iic_subtype Set.nonempty_Iic_subtype theorem nonempty_Ioo_subtype [DenselyOrdered α] (h : a < b) : Nonempty (Ioo a b) := Nonempty.to_subtype (nonempty_Ioo.mpr h) #align set.nonempty_Ioo_subtype Set.nonempty_Ioo_subtype /-- In an order without maximal elements, the intervals `Ioi` are nonempty. -/ instance nonempty_Ioi_subtype [NoMaxOrder α] : Nonempty (Ioi a) := Nonempty.to_subtype nonempty_Ioi #align set.nonempty_Ioi_subtype Set.nonempty_Ioi_subtype /-- In an order without minimal elements, the intervals `Iio` are nonempty. -/ instance nonempty_Iio_subtype [NoMinOrder α] : Nonempty (Iio a) := Nonempty.to_subtype nonempty_Iio #align set.nonempty_Iio_subtype Set.nonempty_Iio_subtype instance [NoMinOrder α] : NoMinOrder (Iio a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, lt_trans hb a.2⟩, hb⟩⟩ instance [NoMinOrder α] : NoMinOrder (Iic a) := ⟨fun a => let ⟨b, hb⟩ := exists_lt (a : α) ⟨⟨b, hb.le.trans a.2⟩, hb⟩⟩ instance [NoMaxOrder α] : NoMaxOrder (Ioi a) := OrderDual.noMaxOrder (α := Iio (toDual a)) instance [NoMaxOrder α] : NoMaxOrder (Ici a) := OrderDual.noMaxOrder (α := Iic (toDual a)) @[simp] theorem Icc_eq_empty (h : ¬a ≤ b) : Icc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Icc_eq_empty Set.Icc_eq_empty @[simp] theorem Ico_eq_empty (h : ¬a < b) : Ico a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_lt hb) #align set.Ico_eq_empty Set.Ico_eq_empty @[simp] theorem Ioc_eq_empty (h : ¬a < b) : Ioc a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans_le hb) #align set.Ioc_eq_empty Set.Ioc_eq_empty @[simp] theorem Ioo_eq_empty (h : ¬a < b) : Ioo a b = ∅ := eq_empty_iff_forall_not_mem.2 fun _ ⟨ha, hb⟩ => h (ha.trans hb) #align set.Ioo_eq_empty Set.Ioo_eq_empty @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = ∅ := Icc_eq_empty h.not_le #align set.Icc_eq_empty_of_lt Set.Icc_eq_empty_of_lt @[simp] theorem Ico_eq_empty_of_le (h : b ≤ a) : Ico a b = ∅ := Ico_eq_empty h.not_lt #align set.Ico_eq_empty_of_le Set.Ico_eq_empty_of_le @[simp] theorem Ioc_eq_empty_of_le (h : b ≤ a) : Ioc a b = ∅ := Ioc_eq_empty h.not_lt #align set.Ioc_eq_empty_of_le Set.Ioc_eq_empty_of_le @[simp] theorem Ioo_eq_empty_of_le (h : b ≤ a) : Ioo a b = ∅ := Ioo_eq_empty h.not_lt #align set.Ioo_eq_empty_of_le Set.Ioo_eq_empty_of_le -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty <| lt_irrefl _ #align set.Ico_self Set.Ico_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty <| lt_irrefl _ #align set.Ioc_self Set.Ioc_self -- Porting note (#10618): `simp` can prove this -- @[simp] theorem Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty <| lt_irrefl _ #align set.Ioo_self Set.Ioo_self theorem Ici_subset_Ici : Ici a ⊆ Ici b ↔ b ≤ a := ⟨fun h => h <| left_mem_Ici, fun h _ hx => h.trans hx⟩ #align set.Ici_subset_Ici Set.Ici_subset_Ici @[gcongr] alias ⟨_, _root_.GCongr.Ici_subset_Ici_of_le⟩ := Ici_subset_Ici theorem Iic_subset_Iic : Iic a ⊆ Iic b ↔ a ≤ b := @Ici_subset_Ici αᵒᵈ _ _ _ #align set.Iic_subset_Iic Set.Iic_subset_Iic @[gcongr] alias ⟨_, _root_.GCongr.Iic_subset_Iic_of_le⟩ := Iic_subset_Iic theorem Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a := ⟨fun h => h left_mem_Ici, fun h _ hx => h.trans_le hx⟩ #align set.Ici_subset_Ioi Set.Ici_subset_Ioi theorem Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b := ⟨fun h => h right_mem_Iic, fun h _ hx => lt_of_le_of_lt hx h⟩ #align set.Iic_subset_Iio Set.Iic_subset_Iio @[gcongr] theorem Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioo a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans_le h₂⟩ #align set.Ioo_subset_Ioo Set.Ioo_subset_Ioo @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b := Ioo_subset_Ioo h le_rfl #align set.Ioo_subset_Ioo_left Set.Ioo_subset_Ioo_left @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ := Ioo_subset_Ioo le_rfl h #align set.Ioo_subset_Ioo_right Set.Ioo_subset_Ioo_right @[gcongr] theorem Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ico a₁ b₁ ⊆ Ico a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, hx₂.trans_le h₂⟩ #align set.Ico_subset_Ico Set.Ico_subset_Ico @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b := Ico_subset_Ico h le_rfl #align set.Ico_subset_Ico_left Set.Ico_subset_Ico_left @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ := Ico_subset_Ico le_rfl h #align set.Ico_subset_Ico_right Set.Ico_subset_Ico_right @[gcongr] theorem Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Icc a₁ b₁ ⊆ Icc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans hx₁, le_trans hx₂ h₂⟩ #align set.Icc_subset_Icc Set.Icc_subset_Icc @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b := Icc_subset_Icc h le_rfl #align set.Icc_subset_Icc_left Set.Icc_subset_Icc_left @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ := Icc_subset_Icc le_rfl h #align set.Icc_subset_Icc_right Set.Icc_subset_Icc_right theorem Icc_subset_Ioo (ha : a₂ < a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ := fun _ hx => ⟨ha.trans_le hx.1, hx.2.trans_lt hb⟩ #align set.Icc_subset_Ioo Set.Icc_subset_Ioo theorem Icc_subset_Ici_self : Icc a b ⊆ Ici a := fun _ => And.left #align set.Icc_subset_Ici_self Set.Icc_subset_Ici_self theorem Icc_subset_Iic_self : Icc a b ⊆ Iic b := fun _ => And.right #align set.Icc_subset_Iic_self Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b ⊆ Iic b := fun _ => And.right #align set.Ioc_subset_Iic_self Set.Ioc_subset_Iic_self @[gcongr] theorem Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) : Ioc a₁ b₁ ⊆ Ioc a₂ b₂ := fun _ ⟨hx₁, hx₂⟩ => ⟨h₁.trans_lt hx₁, hx₂.trans h₂⟩ #align set.Ioc_subset_Ioc Set.Ioc_subset_Ioc @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b := Ioc_subset_Ioc h le_rfl #align set.Ioc_subset_Ioc_left Set.Ioc_subset_Ioc_left @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ := Ioc_subset_Ioc le_rfl h #align set.Ioc_subset_Ioc_right Set.Ioc_subset_Ioc_right theorem Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b := fun _ => And.imp_left h₁.trans_le #align set.Ico_subset_Ioo_left Set.Ico_subset_Ioo_left theorem Ioc_subset_Ioo_right (h : b₁ < b₂) : Ioc a b₁ ⊆ Ioo a b₂ := fun _ => And.imp_right fun h' => h'.trans_lt h #align set.Ioc_subset_Ioo_right Set.Ioc_subset_Ioo_right theorem Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ := fun _ => And.imp_right fun h₂ => h₂.trans_lt h₁ #align set.Icc_subset_Ico_right Set.Icc_subset_Ico_right theorem Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := fun _ => And.imp_left le_of_lt #align set.Ioo_subset_Ico_self Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := fun _ => And.imp_right le_of_lt #align set.Ioo_subset_Ioc_self Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b ⊆ Icc a b := fun _ => And.imp_right le_of_lt #align set.Ico_subset_Icc_self Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := fun _ => And.imp_left le_of_lt #align set.Ioc_subset_Icc_self Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b := Subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self #align set.Ioo_subset_Icc_self Set.Ioo_subset_Icc_self theorem Ico_subset_Iio_self : Ico a b ⊆ Iio b := fun _ => And.right #align set.Ico_subset_Iio_self Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := fun _ => And.right #align set.Ioo_subset_Iio_self Set.Ioo_subset_Iio_self theorem Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := fun _ => And.left #align set.Ioc_subset_Ioi_self Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := fun _ => And.left #align set.Ioo_subset_Ioi_self Set.Ioo_subset_Ioi_self theorem Ioi_subset_Ici_self : Ioi a ⊆ Ici a := fun _ hx => le_of_lt hx #align set.Ioi_subset_Ici_self Set.Ioi_subset_Ici_self theorem Iio_subset_Iic_self : Iio a ⊆ Iic a := fun _ hx => le_of_lt hx #align set.Iio_subset_Iic_self Set.Iio_subset_Iic_self theorem Ico_subset_Ici_self : Ico a b ⊆ Ici a := fun _ => And.left #align set.Ico_subset_Ici_self Set.Ico_subset_Ici_self theorem Ioi_ssubset_Ici_self : Ioi a ⊂ Ici a := ⟨Ioi_subset_Ici_self, fun h => lt_irrefl a (h le_rfl)⟩ #align set.Ioi_ssubset_Ici_self Set.Ioi_ssubset_Ici_self theorem Iio_ssubset_Iic_self : Iio a ⊂ Iic a := @Ioi_ssubset_Ici_self αᵒᵈ _ _ #align set.Iio_ssubset_Iic_self Set.Iio_ssubset_Iic_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Icc_iff Set.Icc_subset_Icc_iff theorem Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ioo_iff Set.Icc_subset_Ioo_iff theorem Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans hx, hx'.trans_lt h'⟩⟩ #align set.Icc_subset_Ico_iff Set.Icc_subset_Ico_iff theorem Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ := ⟨fun h => ⟨(h ⟨le_rfl, h₁⟩).1, (h ⟨h₁, le_rfl⟩).2⟩, fun ⟨h, h'⟩ _ ⟨hx, hx'⟩ => ⟨h.trans_le hx, hx'.trans h'⟩⟩ #align set.Icc_subset_Ioc_iff Set.Icc_subset_Ioc_iff theorem Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans_lt h⟩ #align set.Icc_subset_Iio_iff Set.Icc_subset_Iio_iff theorem Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans_le hx⟩ #align set.Icc_subset_Ioi_iff Set.Icc_subset_Ioi_iff theorem Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ := ⟨fun h => h ⟨h₁, le_rfl⟩, fun h _ ⟨_, hx'⟩ => hx'.trans h⟩ #align set.Icc_subset_Iic_iff Set.Icc_subset_Iic_iff theorem Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) : Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ := ⟨fun h => h ⟨le_rfl, h₁⟩, fun h _ ⟨hx, _⟩ => h.trans hx⟩ #align set.Icc_subset_Ici_iff Set.Icc_subset_Ici_iff theorem Icc_ssubset_Icc_left (hI : a₂ ≤ b₂) (ha : a₂ < a₁) (hb : b₁ ≤ b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc (le_of_lt ha) hb)).mpr ⟨a₂, left_mem_Icc.mpr hI, not_and.mpr fun f _ => lt_irrefl a₂ (ha.trans_le f)⟩ #align set.Icc_ssubset_Icc_left Set.Icc_ssubset_Icc_left theorem Icc_ssubset_Icc_right (hI : a₂ ≤ b₂) (ha : a₂ ≤ a₁) (hb : b₁ < b₂) : Icc a₁ b₁ ⊂ Icc a₂ b₂ := (ssubset_iff_of_subset (Icc_subset_Icc ha (le_of_lt hb))).mpr ⟨b₂, right_mem_Icc.mpr hI, fun f => lt_irrefl b₁ (hb.trans_le f.2)⟩ #align set.Icc_ssubset_Icc_right Set.Icc_ssubset_Icc_right /-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/ @[gcongr] theorem Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a := fun _ hx => h.trans_lt hx #align set.Ioi_subset_Ioi Set.Ioi_subset_Ioi /-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/ theorem Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a := Subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self #align set.Ioi_subset_Ici Set.Ioi_subset_Ici /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/ @[gcongr] theorem Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b := fun _ hx => lt_of_lt_of_le hx h #align set.Iio_subset_Iio Set.Iio_subset_Iio /-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/ theorem Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b := Subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self #align set.Iio_subset_Iic Set.Iio_subset_Iic theorem Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl #align set.Ici_inter_Iic Set.Ici_inter_Iic theorem Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl #align set.Ici_inter_Iio Set.Ici_inter_Iio theorem Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl #align set.Ioi_inter_Iic Set.Ioi_inter_Iic theorem Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl #align set.Ioi_inter_Iio Set.Ioi_inter_Iio theorem Iic_inter_Ici : Iic a ∩ Ici b = Icc b a := inter_comm _ _ #align set.Iic_inter_Ici Set.Iic_inter_Ici theorem Iio_inter_Ici : Iio a ∩ Ici b = Ico b a := inter_comm _ _ #align set.Iio_inter_Ici Set.Iio_inter_Ici theorem Iic_inter_Ioi : Iic a ∩ Ioi b = Ioc b a := inter_comm _ _ #align set.Iic_inter_Ioi Set.Iic_inter_Ioi theorem Iio_inter_Ioi : Iio a ∩ Ioi b = Ioo b a := inter_comm _ _ #align set.Iio_inter_Ioi Set.Iio_inter_Ioi theorem mem_Icc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Icc a b := Ioo_subset_Icc_self h #align set.mem_Icc_of_Ioo Set.mem_Icc_of_Ioo theorem mem_Ico_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ico a b := Ioo_subset_Ico_self h #align set.mem_Ico_of_Ioo Set.mem_Ico_of_Ioo theorem mem_Ioc_of_Ioo (h : x ∈ Ioo a b) : x ∈ Ioc a b := Ioo_subset_Ioc_self h #align set.mem_Ioc_of_Ioo Set.mem_Ioc_of_Ioo theorem mem_Icc_of_Ico (h : x ∈ Ico a b) : x ∈ Icc a b := Ico_subset_Icc_self h #align set.mem_Icc_of_Ico Set.mem_Icc_of_Ico theorem mem_Icc_of_Ioc (h : x ∈ Ioc a b) : x ∈ Icc a b := Ioc_subset_Icc_self h #align set.mem_Icc_of_Ioc Set.mem_Icc_of_Ioc theorem mem_Ici_of_Ioi (h : x ∈ Ioi a) : x ∈ Ici a := Ioi_subset_Ici_self h #align set.mem_Ici_of_Ioi Set.mem_Ici_of_Ioi theorem mem_Iic_of_Iio (h : x ∈ Iio a) : x ∈ Iic a := Iio_subset_Iic_self h #align set.mem_Iic_of_Iio Set.mem_Iic_of_Iio theorem Icc_eq_empty_iff : Icc a b = ∅ ↔ ¬a ≤ b := by rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Icc] #align set.Icc_eq_empty_iff Set.Icc_eq_empty_iff
Mathlib/Order/Interval/Set/Basic.lean
700
701
theorem Ico_eq_empty_iff : Ico a b = ∅ ↔ ¬a < b := by
rw [← not_nonempty_iff_eq_empty, not_iff_not, nonempty_Ico]
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Init.ZeroOne import Mathlib.Data.Set.Defs import Mathlib.Order.Basic import Mathlib.Order.SymmDiff import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators #align_import data.set.basic from "leanprover-community/mathlib"@"001ffdc42920050657fd45bd2b8bfbec8eaaeb29" /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the core library. This file provides some basic definitions related to sets and functions not present in the core library, as well as extra lemmas for functions in the core library (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ /-! ### Set coercion to a type -/ open Function universe u v w x namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebraSet : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl #align set.top_eq_univ Set.top_eq_univ @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl #align set.bot_eq_empty Set.bot_eq_empty @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl #align set.sup_eq_union Set.sup_eq_union @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl #align set.inf_eq_inter Set.inf_eq_inter @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl #align set.le_eq_subset Set.le_eq_subset @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl #align set.lt_eq_ssubset Set.lt_eq_ssubset theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl #align set.le_iff_subset Set.le_iff_subset theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl #align set.lt_iff_ssubset Set.lt_iff_ssubset alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset #align has_subset.subset.le HasSubset.Subset.le alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset #align has_ssubset.ssubset.lt HasSSubset.SSubset.lt instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s #align set.pi_set_coe.can_lift Set.PiSetCoe.canLift instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s #align set.pi_set_coe.can_lift' Set.PiSetCoe.canLift' end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl #align set.coe_eq_subtype Set.coe_eq_subtype @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl #align set.coe_set_of Set.coe_setOf -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall #align set_coe.forall SetCoe.forall -- Porting note (#10618): removed `simp` because `simp` can prove it theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists #align set_coe.exists SetCoe.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm #align set_coe.exists' SetCoe.exists' theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm #align set_coe.forall' SetCoe.forall' @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl #align set_coe_cast set_coe_cast theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq #align set_coe.ext SetCoe.ext theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl #align set_coe.ext_iff SetCoe.ext_iff end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop #align subtype.mem Subtype.mem /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ #align eq.subset Eq.subset namespace Set variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ theorem ext_iff {s t : Set α} : s = t ↔ ∀ x, x ∈ s ↔ x ∈ t := ⟨fun h x => by rw [h], ext⟩ #align set.ext_iff Set.ext_iff @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx #align set.mem_of_mem_of_subset Set.mem_of_mem_of_subset theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto #align set.forall_in_swap Set.forall_in_swap /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl #align set.mem_set_of Set.mem_setOf /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h #align has_mem.mem.out Membership.mem.out theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl #align set.nmem_set_of_iff Set.nmem_setOf_iff @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl #align set.set_of_mem_eq Set.setOf_mem_eq theorem setOf_set {s : Set α} : setOf s = s := rfl #align set.set_of_set Set.setOf_set theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl #align set.set_of_app_iff Set.setOf_app_iff theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl #align set.mem_def Set.mem_def theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id #align set.set_of_bijective Set.setOf_bijective theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl #align set.set_of_subset_set_of Set.setOf_subset_setOf theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl #align set.set_of_and Set.setOf_and theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl #align set.set_of_or Set.setOf_or /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl #align set.subset_def Set.subset_def theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl #align set.ssubset_def Set.ssubset_def @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id #align set.subset.refl Set.Subset.refl theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s #align set.subset.rfl Set.Subset.rfl @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h #align set.subset.trans Set.Subset.trans @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h #align set.mem_of_eq_of_mem Set.mem_of_eq_of_mem theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ #align set.subset.antisymm Set.Subset.antisymm theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ #align set.subset.antisymm_iff Set.Subset.antisymm_iff -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm #align set.eq_of_subset_of_subset Set.eq_of_subset_of_subset theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ #align set.mem_of_subset_of_mem Set.mem_of_subset_of_mem theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h #align set.not_mem_subset Set.not_mem_subset theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] #align set.not_subset Set.not_subset lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h #align set.eq_or_ssubset_of_subset Set.eq_or_ssubset_of_subset theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 #align set.exists_of_ssubset Set.exists_of_ssubset protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t #align set.ssubset_iff_subset_ne Set.ssubset_iff_subset_ne theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ #align set.ssubset_iff_of_subset Set.ssubset_iff_of_subset protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ #align set.ssubset_of_ssubset_of_subset Set.ssubset_of_ssubset_of_subset protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ #align set.ssubset_of_subset_of_ssubset Set.ssubset_of_subset_of_ssubset theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id #align set.not_mem_empty Set.not_mem_empty -- Porting note (#10618): removed `simp` because `simp` can prove it theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not #align set.not_not_mem Set.not_not_mem /-! ### Non-empty sets -/ -- Porting note: we seem to need parentheses at `(↥s)`, -- even if we increase the right precedence of `↥` in `Mathlib.Tactic.Coe`. -- Porting note: removed `simp` as it is competing with `nonempty_subtype`. -- @[simp] theorem nonempty_coe_sort {s : Set α} : Nonempty (↥s) ↔ s.Nonempty := nonempty_subtype #align set.nonempty_coe_sort Set.nonempty_coe_sort alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort #align set.nonempty.coe_sort Set.Nonempty.coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl #align set.nonempty_def Set.nonempty_def theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ #align set.nonempty_of_mem Set.nonempty_of_mem theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx #align set.nonempty.not_subset_empty Set.Nonempty.not_subset_empty /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h #align set.nonempty.some Set.Nonempty.some protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h #align set.nonempty.some_mem Set.Nonempty.some_mem theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht #align set.nonempty.mono Set.Nonempty.mono theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ #align set.nonempty_of_not_subset Set.nonempty_of_not_subset theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 #align set.nonempty_of_ssubset Set.nonempty_of_ssubset theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.of_diff Set.Nonempty.of_diff theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff #align set.nonempty_of_ssubset' Set.nonempty_of_ssubset' theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl #align set.nonempty.inl Set.Nonempty.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr #align set.nonempty.inr Set.Nonempty.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or #align set.union_nonempty Set.union_nonempty theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left #align set.nonempty.left Set.Nonempty.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right #align set.nonempty.right Set.Nonempty.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl #align set.inter_nonempty Set.inter_nonempty theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] #align set.inter_nonempty_iff_exists_left Set.inter_nonempty_iff_exists_left theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] #align set.inter_nonempty_iff_exists_right Set.inter_nonempty_iff_exists_right theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ #align set.nonempty_iff_univ_nonempty Set.nonempty_iff_univ_nonempty @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ #align set.univ_nonempty Set.univ_nonempty theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 #align set.nonempty.to_subtype Set.Nonempty.to_subtype theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ #align set.nonempty.to_type Set.Nonempty.to_type instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype #align set.univ.nonempty Set.univ.nonempty theorem nonempty_of_nonempty_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› #align set.nonempty_of_nonempty_subtype Set.nonempty_of_nonempty_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl #align set.empty_def Set.empty_def @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl #align set.mem_empty_iff_false Set.mem_empty_iff_false @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl #align set.set_of_false Set.setOf_false @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun #align set.empty_subset Set.empty_subset theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm #align set.subset_empty_iff Set.subset_empty_iff theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm #align set.eq_empty_iff_forall_not_mem Set.eq_empty_iff_forall_not_mem theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h #align set.eq_empty_of_forall_not_mem Set.eq_empty_of_forall_not_mem theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 #align set.eq_empty_of_subset_empty Set.eq_empty_of_subset_empty theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x #align set.eq_empty_of_is_empty Set.eq_empty_of_isEmpty /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty #align set.unique_empty Set.uniqueEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] #align set.not_nonempty_iff_eq_empty Set.not_nonempty_iff_eq_empty /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right #align set.nonempty_iff_ne_empty Set.nonempty_iff_ne_empty /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty #align set.nonempty.ne_empty Set.Nonempty.ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx #align set.not_nonempty_empty Set.not_nonempty_empty -- Porting note: removing `@[simp]` as it is competing with `isEmpty_subtype`. -- @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty #align set.is_empty_coe_sort Set.isEmpty_coe_sort theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 #align set.eq_empty_or_nonempty Set.eq_empty_or_nonempty theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h #align set.subset_eq_empty Set.subset_eq_empty theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim #align set.ball_empty_iff Set.forall_mem_empty @[deprecated (since := "2024-03-23")] alias ball_empty_iff := forall_mem_empty instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm #align set.empty_ssubset Set.empty_ssubset alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset #align set.nonempty.empty_ssubset Set.Nonempty.empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl #align set.set_of_true Set.setOf_true @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ #align set.univ_eq_empty_iff Set.univ_eq_empty_iff theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm #align set.empty_ne_univ Set.empty_ne_univ @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial #align set.subset_univ Set.subset_univ @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s #align set.univ_subset_iff Set.univ_subset_iff alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff #align set.eq_univ_of_univ_subset Set.eq_univ_of_univ_subset theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial #align set.eq_univ_iff_forall Set.eq_univ_iff_forall theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align set.eq_univ_of_forall Set.eq_univ_of_forall theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] #align set.nonempty.eq_univ Set.Nonempty.eq_univ theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) #align set.eq_univ_of_subset Set.eq_univ_of_subset theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ #align set.exists_mem_of_nonempty Set.exists_mem_of_nonempty theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] #align set.ne_univ_iff_exists_not_mem Set.ne_univ_iff_exists_not_mem theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] #align set.not_subset_iff_exists_mem_not_mem Set.not_subset_iff_exists_mem_not_mem theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default #align set.univ_unique Set.univ_unique theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top #align set.ssubset_univ_iff Set.ssubset_univ_iff instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ #align set.nontrivial_of_nonempty Set.nontrivial_of_nonempty /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl #align set.union_def Set.union_def theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl #align set.mem_union_left Set.mem_union_left theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr #align set.mem_union_right Set.mem_union_right theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H #align set.mem_or_mem_of_mem_union Set.mem_or_mem_of_mem_union theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ #align set.mem_union.elim Set.MemUnion.elim @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl #align set.mem_union Set.mem_union @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff #align set.union_self Set.union_self @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => or_false_iff _ #align set.union_empty Set.union_empty @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => false_or_iff _ #align set.empty_union Set.empty_union theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm #align set.union_comm Set.union_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc #align set.union_assoc Set.union_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ #align set.union_is_assoc Set.union_isAssoc instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ #align set.union_is_comm Set.union_isComm theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm #align set.union_left_comm Set.union_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm #align set.union_right_comm Set.union_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left #align set.union_eq_left_iff_subset Set.union_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right #align set.union_eq_right_iff_subset Set.union_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h #align set.union_eq_self_of_subset_left Set.union_eq_self_of_subset_left theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h #align set.union_eq_self_of_subset_right Set.union_eq_self_of_subset_right @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl #align set.subset_union_left Set.subset_union_left @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr #align set.subset_union_right Set.subset_union_right theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) #align set.union_subset Set.union_subset @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and #align set.union_subset_iff Set.union_subset_iff @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) #align set.union_subset_union Set.union_subset_union @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl #align set.union_subset_union_left Set.union_subset_union_left @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h #align set.union_subset_union_right Set.union_subset_union_right theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left #align set.subset_union_of_subset_left Set.subset_union_of_subset_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right #align set.subset_union_of_subset_right Set.subset_union_of_subset_right -- Porting note: replaced `⊔` in RHS theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu #align set.union_congr_left Set.union_congr_left theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht #align set.union_congr_right Set.union_congr_right theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left #align set.union_eq_union_iff_left Set.union_eq_union_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right #align set.union_eq_union_iff_right Set.union_eq_union_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff #align set.union_empty_iff Set.union_empty_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ #align set.union_univ Set.union_univ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ #align set.univ_union Set.univ_union /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl #align set.inter_def Set.inter_def @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl #align set.mem_inter_iff Set.mem_inter_iff theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ #align set.mem_inter Set.mem_inter theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left #align set.mem_of_mem_inter_left Set.mem_of_mem_inter_left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right #align set.mem_of_mem_inter_right Set.mem_of_mem_inter_right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff #align set.inter_self Set.inter_self @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => and_false_iff _ #align set.inter_empty Set.inter_empty @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => false_and_iff _ #align set.empty_inter Set.empty_inter theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm #align set.inter_comm Set.inter_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc #align set.inter_assoc Set.inter_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ #align set.inter_is_assoc Set.inter_isAssoc instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ #align set.inter_is_comm Set.inter_isComm theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm #align set.inter_left_comm Set.inter_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm #align set.inter_right_comm Set.inter_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left #align set.inter_subset_left Set.inter_subset_left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right #align set.inter_subset_right Set.inter_subset_right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ #align set.subset_inter Set.subset_inter @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and #align set.subset_inter_iff Set.subset_inter_iff @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left #align set.inter_eq_left_iff_subset Set.inter_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right #align set.inter_eq_right_iff_subset Set.inter_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr #align set.inter_eq_self_of_subset_left Set.inter_eq_self_of_subset_left theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr #align set.inter_eq_self_of_subset_right Set.inter_eq_self_of_subset_right theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu #align set.inter_congr_left Set.inter_congr_left theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht #align set.inter_congr_right Set.inter_congr_right theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left #align set.inter_eq_inter_iff_left Set.inter_eq_inter_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right #align set.inter_eq_inter_iff_right Set.inter_eq_inter_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ #align set.inter_univ Set.inter_univ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ #align set.univ_inter Set.univ_inter @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) #align set.inter_subset_inter Set.inter_subset_inter @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl #align set.inter_subset_inter_left Set.inter_subset_inter_left @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H #align set.inter_subset_inter_right Set.inter_subset_inter_right theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left #align set.union_inter_cancel_left Set.union_inter_cancel_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right #align set.union_inter_cancel_right Set.union_inter_cancel_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl #align set.inter_set_of_eq_sep Set.inter_setOf_eq_sep theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ #align set.set_of_inter_eq_sep Set.setOf_inter_eq_sep /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ #align set.inter_distrib_left Set.inter_union_distrib_left theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ #align set.inter_distrib_right Set.union_inter_distrib_right theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ #align set.union_distrib_left Set.union_inter_distrib_left theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ #align set.union_distrib_right Set.inter_union_distrib_right -- 2024-03-22 @[deprecated] alias inter_distrib_left := inter_union_distrib_left @[deprecated] alias inter_distrib_right := union_inter_distrib_right @[deprecated] alias union_distrib_left := union_inter_distrib_left @[deprecated] alias union_distrib_right := inter_union_distrib_right theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ #align set.union_union_distrib_left Set.union_union_distrib_left theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ #align set.union_union_distrib_right Set.union_union_distrib_right theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ #align set.inter_inter_distrib_left Set.inter_inter_distrib_left theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ #align set.inter_inter_distrib_right Set.inter_inter_distrib_right theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ #align set.union_union_union_comm Set.union_union_union_comm theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ #align set.inter_inter_inter_comm Set.inter_inter_inter_comm /-! ### Lemmas about `insert` `insert α s` is the set `{α} ∪ s`. -/ theorem insert_def (x : α) (s : Set α) : insert x s = { y | y = x ∨ y ∈ s } := rfl #align set.insert_def Set.insert_def @[simp] theorem subset_insert (x : α) (s : Set α) : s ⊆ insert x s := fun _ => Or.inr #align set.subset_insert Set.subset_insert theorem mem_insert (x : α) (s : Set α) : x ∈ insert x s := Or.inl rfl #align set.mem_insert Set.mem_insert theorem mem_insert_of_mem {x : α} {s : Set α} (y : α) : x ∈ s → x ∈ insert y s := Or.inr #align set.mem_insert_of_mem Set.mem_insert_of_mem theorem eq_or_mem_of_mem_insert {x a : α} {s : Set α} : x ∈ insert a s → x = a ∨ x ∈ s := id #align set.eq_or_mem_of_mem_insert Set.eq_or_mem_of_mem_insert theorem mem_of_mem_insert_of_ne : b ∈ insert a s → b ≠ a → b ∈ s := Or.resolve_left #align set.mem_of_mem_insert_of_ne Set.mem_of_mem_insert_of_ne theorem eq_of_not_mem_of_mem_insert : b ∈ insert a s → b ∉ s → b = a := Or.resolve_right #align set.eq_of_not_mem_of_mem_insert Set.eq_of_not_mem_of_mem_insert @[simp] theorem mem_insert_iff {x a : α} {s : Set α} : x ∈ insert a s ↔ x = a ∨ x ∈ s := Iff.rfl #align set.mem_insert_iff Set.mem_insert_iff @[simp] theorem insert_eq_of_mem {a : α} {s : Set α} (h : a ∈ s) : insert a s = s := ext fun _ => or_iff_right_of_imp fun e => e.symm ▸ h #align set.insert_eq_of_mem Set.insert_eq_of_mem theorem ne_insert_of_not_mem {s : Set α} (t : Set α) {a : α} : a ∉ s → s ≠ insert a t := mt fun e => e.symm ▸ mem_insert _ _ #align set.ne_insert_of_not_mem Set.ne_insert_of_not_mem @[simp] theorem insert_eq_self : insert a s = s ↔ a ∈ s := ⟨fun h => h ▸ mem_insert _ _, insert_eq_of_mem⟩ #align set.insert_eq_self Set.insert_eq_self theorem insert_ne_self : insert a s ≠ s ↔ a ∉ s := insert_eq_self.not #align set.insert_ne_self Set.insert_ne_self theorem insert_subset_iff : insert a s ⊆ t ↔ a ∈ t ∧ s ⊆ t := by simp only [subset_def, mem_insert_iff, or_imp, forall_and, forall_eq] #align set.insert_subset Set.insert_subset_iff theorem insert_subset (ha : a ∈ t) (hs : s ⊆ t) : insert a s ⊆ t := insert_subset_iff.mpr ⟨ha, hs⟩ theorem insert_subset_insert (h : s ⊆ t) : insert a s ⊆ insert a t := fun _ => Or.imp_right (@h _) #align set.insert_subset_insert Set.insert_subset_insert @[simp] theorem insert_subset_insert_iff (ha : a ∉ s) : insert a s ⊆ insert a t ↔ s ⊆ t := by refine ⟨fun h x hx => ?_, insert_subset_insert⟩ rcases h (subset_insert _ _ hx) with (rfl | hxt) exacts [(ha hx).elim, hxt] #align set.insert_subset_insert_iff Set.insert_subset_insert_iff theorem subset_insert_iff_of_not_mem (ha : a ∉ s) : s ⊆ insert a t ↔ s ⊆ t := forall₂_congr fun _ hb => or_iff_right <| ne_of_mem_of_not_mem hb ha #align set.subset_insert_iff_of_not_mem Set.subset_insert_iff_of_not_mem theorem ssubset_iff_insert {s t : Set α} : s ⊂ t ↔ ∃ a ∉ s, insert a s ⊆ t := by simp only [insert_subset_iff, exists_and_right, ssubset_def, not_subset] aesop #align set.ssubset_iff_insert Set.ssubset_iff_insert theorem ssubset_insert {s : Set α} {a : α} (h : a ∉ s) : s ⊂ insert a s := ssubset_iff_insert.2 ⟨a, h, Subset.rfl⟩ #align set.ssubset_insert Set.ssubset_insert theorem insert_comm (a b : α) (s : Set α) : insert a (insert b s) = insert b (insert a s) := ext fun _ => or_left_comm #align set.insert_comm Set.insert_comm -- Porting note (#10618): removing `simp` attribute because `simp` can prove it theorem insert_idem (a : α) (s : Set α) : insert a (insert a s) = insert a s := insert_eq_of_mem <| mem_insert _ _ #align set.insert_idem Set.insert_idem theorem insert_union : insert a s ∪ t = insert a (s ∪ t) := ext fun _ => or_assoc #align set.insert_union Set.insert_union @[simp] theorem union_insert : s ∪ insert a t = insert a (s ∪ t) := ext fun _ => or_left_comm #align set.union_insert Set.union_insert @[simp] theorem insert_nonempty (a : α) (s : Set α) : (insert a s).Nonempty := ⟨a, mem_insert a s⟩ #align set.insert_nonempty Set.insert_nonempty instance (a : α) (s : Set α) : Nonempty (insert a s : Set α) := (insert_nonempty a s).to_subtype theorem insert_inter_distrib (a : α) (s t : Set α) : insert a (s ∩ t) = insert a s ∩ insert a t := ext fun _ => or_and_left #align set.insert_inter_distrib Set.insert_inter_distrib theorem insert_union_distrib (a : α) (s t : Set α) : insert a (s ∪ t) = insert a s ∪ insert a t := ext fun _ => or_or_distrib_left #align set.insert_union_distrib Set.insert_union_distrib theorem insert_inj (ha : a ∉ s) : insert a s = insert b s ↔ a = b := ⟨fun h => eq_of_not_mem_of_mem_insert (h.subst <| mem_insert a s) ha, congr_arg (fun x => insert x s)⟩ #align set.insert_inj Set.insert_inj -- useful in proofs by induction theorem forall_of_forall_insert {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ insert a s → P x) (x) (h : x ∈ s) : P x := H _ (Or.inr h) #align set.forall_of_forall_insert Set.forall_of_forall_insert theorem forall_insert_of_forall {P : α → Prop} {a : α} {s : Set α} (H : ∀ x, x ∈ s → P x) (ha : P a) (x) (h : x ∈ insert a s) : P x := h.elim (fun e => e.symm ▸ ha) (H _) #align set.forall_insert_of_forall Set.forall_insert_of_forall /- Porting note: ∃ x ∈ insert a s, P x is parsed as ∃ x, x ∈ insert a s ∧ P x, where in Lean3 it was parsed as `∃ x, ∃ (h : x ∈ insert a s), P x` -/ theorem exists_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∃ x ∈ insert a s, P x) ↔ (P a ∨ ∃ x ∈ s, P x) := by simp [mem_insert_iff, or_and_right, exists_and_left, exists_or] #align set.bex_insert_iff Set.exists_mem_insert @[deprecated (since := "2024-03-23")] alias bex_insert_iff := exists_mem_insert theorem forall_mem_insert {P : α → Prop} {a : α} {s : Set α} : (∀ x ∈ insert a s, P x) ↔ P a ∧ ∀ x ∈ s, P x := forall₂_or_left.trans <| and_congr_left' forall_eq #align set.ball_insert_iff Set.forall_mem_insert @[deprecated (since := "2024-03-23")] alias ball_insert_iff := forall_mem_insert /-! ### Lemmas about singletons -/ /- porting note: instance was in core in Lean3 -/ instance : LawfulSingleton α (Set α) := ⟨fun x => Set.ext fun a => by simp only [mem_empty_iff_false, mem_insert_iff, or_false] exact Iff.rfl⟩ theorem singleton_def (a : α) : ({a} : Set α) = insert a ∅ := (insert_emptyc_eq a).symm #align set.singleton_def Set.singleton_def @[simp] theorem mem_singleton_iff {a b : α} : a ∈ ({b} : Set α) ↔ a = b := Iff.rfl #align set.mem_singleton_iff Set.mem_singleton_iff @[simp] theorem setOf_eq_eq_singleton {a : α} : { n | n = a } = {a} := rfl #align set.set_of_eq_eq_singleton Set.setOf_eq_eq_singleton @[simp] theorem setOf_eq_eq_singleton' {a : α} : { x | a = x } = {a} := ext fun _ => eq_comm #align set.set_of_eq_eq_singleton' Set.setOf_eq_eq_singleton' -- TODO: again, annotation needed --Porting note (#11119): removed `simp` attribute theorem mem_singleton (a : α) : a ∈ ({a} : Set α) := @rfl _ _ #align set.mem_singleton Set.mem_singleton theorem eq_of_mem_singleton {x y : α} (h : x ∈ ({y} : Set α)) : x = y := h #align set.eq_of_mem_singleton Set.eq_of_mem_singleton @[simp] theorem singleton_eq_singleton_iff {x y : α} : {x} = ({y} : Set α) ↔ x = y := ext_iff.trans eq_iff_eq_cancel_left #align set.singleton_eq_singleton_iff Set.singleton_eq_singleton_iff theorem singleton_injective : Injective (singleton : α → Set α) := fun _ _ => singleton_eq_singleton_iff.mp #align set.singleton_injective Set.singleton_injective theorem mem_singleton_of_eq {x y : α} (H : x = y) : x ∈ ({y} : Set α) := H #align set.mem_singleton_of_eq Set.mem_singleton_of_eq theorem insert_eq (x : α) (s : Set α) : insert x s = ({x} : Set α) ∪ s := rfl #align set.insert_eq Set.insert_eq @[simp] theorem singleton_nonempty (a : α) : ({a} : Set α).Nonempty := ⟨a, rfl⟩ #align set.singleton_nonempty Set.singleton_nonempty @[simp] theorem singleton_ne_empty (a : α) : ({a} : Set α) ≠ ∅ := (singleton_nonempty _).ne_empty #align set.singleton_ne_empty Set.singleton_ne_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem empty_ssubset_singleton : (∅ : Set α) ⊂ {a} := (singleton_nonempty _).empty_ssubset #align set.empty_ssubset_singleton Set.empty_ssubset_singleton @[simp] theorem singleton_subset_iff {a : α} {s : Set α} : {a} ⊆ s ↔ a ∈ s := forall_eq #align set.singleton_subset_iff Set.singleton_subset_iff theorem singleton_subset_singleton : ({a} : Set α) ⊆ {b} ↔ a = b := by simp #align set.singleton_subset_singleton Set.singleton_subset_singleton theorem set_compr_eq_eq_singleton {a : α} : { b | b = a } = {a} := rfl #align set.set_compr_eq_eq_singleton Set.set_compr_eq_eq_singleton @[simp] theorem singleton_union : {a} ∪ s = insert a s := rfl #align set.singleton_union Set.singleton_union @[simp] theorem union_singleton : s ∪ {a} = insert a s := union_comm _ _ #align set.union_singleton Set.union_singleton @[simp] theorem singleton_inter_nonempty : ({a} ∩ s).Nonempty ↔ a ∈ s := by simp only [Set.Nonempty, mem_inter_iff, mem_singleton_iff, exists_eq_left] #align set.singleton_inter_nonempty Set.singleton_inter_nonempty @[simp] theorem inter_singleton_nonempty : (s ∩ {a}).Nonempty ↔ a ∈ s := by rw [inter_comm, singleton_inter_nonempty] #align set.inter_singleton_nonempty Set.inter_singleton_nonempty @[simp] theorem singleton_inter_eq_empty : {a} ∩ s = ∅ ↔ a ∉ s := not_nonempty_iff_eq_empty.symm.trans singleton_inter_nonempty.not #align set.singleton_inter_eq_empty Set.singleton_inter_eq_empty @[simp] theorem inter_singleton_eq_empty : s ∩ {a} = ∅ ↔ a ∉ s := by rw [inter_comm, singleton_inter_eq_empty] #align set.inter_singleton_eq_empty Set.inter_singleton_eq_empty theorem nmem_singleton_empty {s : Set α} : s ∉ ({∅} : Set (Set α)) ↔ s.Nonempty := nonempty_iff_ne_empty.symm #align set.nmem_singleton_empty Set.nmem_singleton_empty instance uniqueSingleton (a : α) : Unique (↥({a} : Set α)) := ⟨⟨⟨a, mem_singleton a⟩⟩, fun ⟨_, h⟩ => Subtype.eq h⟩ #align set.unique_singleton Set.uniqueSingleton theorem eq_singleton_iff_unique_mem : s = {a} ↔ a ∈ s ∧ ∀ x ∈ s, x = a := Subset.antisymm_iff.trans <| and_comm.trans <| and_congr_left' singleton_subset_iff #align set.eq_singleton_iff_unique_mem Set.eq_singleton_iff_unique_mem theorem eq_singleton_iff_nonempty_unique_mem : s = {a} ↔ s.Nonempty ∧ ∀ x ∈ s, x = a := eq_singleton_iff_unique_mem.trans <| and_congr_left fun H => ⟨fun h' => ⟨_, h'⟩, fun ⟨x, h⟩ => H x h ▸ h⟩ #align set.eq_singleton_iff_nonempty_unique_mem Set.eq_singleton_iff_nonempty_unique_mem set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 -- while `simp` is capable of proving this, it is not capable of turning the LHS into the RHS. @[simp] theorem default_coe_singleton (x : α) : (default : ({x} : Set α)) = ⟨x, rfl⟩ := rfl #align set.default_coe_singleton Set.default_coe_singleton /-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/ section Sep variable {p q : α → Prop} {x : α} theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } := ⟨xs, px⟩ #align set.mem_sep Set.mem_sep @[simp] theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t := rfl #align set.sep_mem_eq Set.sep_mem_eq @[simp] theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x := Iff.rfl #align set.mem_sep_iff Set.mem_sep_iff theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by simp_rw [ext_iff, mem_sep_iff, and_congr_right_iff] #align set.sep_ext_iff Set.sep_ext_iff theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s := inter_eq_self_of_subset_right h #align set.sep_eq_of_subset Set.sep_eq_of_subset @[simp] theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left #align set.sep_subset Set.sep_subset @[simp] theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by simp_rw [ext_iff, mem_sep_iff, and_iff_left_iff_imp] #align set.sep_eq_self_iff_mem_true Set.sep_eq_self_iff_mem_true @[simp] theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by simp_rw [ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false_iff, not_and] #align set.sep_eq_empty_iff_mem_false Set.sep_eq_empty_iff_mem_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_true : { x ∈ s | True } = s := inter_univ s #align set.sep_true Set.sep_true --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_false : { x ∈ s | False } = ∅ := inter_empty s #align set.sep_false Set.sep_false --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ := empty_inter {x | p x} #align set.sep_empty Set.sep_empty --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } := univ_inter {x | p x} #align set.sep_univ Set.sep_univ @[simp] theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } := union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p #align set.sep_union Set.sep_union @[simp] theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } := inter_inter_distrib_right s t {x | p x} #align set.sep_inter Set.sep_inter @[simp] theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } := inter_inter_distrib_left s {x | p x} {x | q x} #align set.sep_and Set.sep_and @[simp] theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } := inter_union_distrib_left s p q #align set.sep_or Set.sep_or @[simp] theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } := rfl #align set.sep_set_of Set.sep_setOf end Sep @[simp] theorem subset_singleton_iff {α : Type*} {s : Set α} {x : α} : s ⊆ {x} ↔ ∀ y ∈ s, y = x := Iff.rfl #align set.subset_singleton_iff Set.subset_singleton_iff theorem subset_singleton_iff_eq {s : Set α} {x : α} : s ⊆ {x} ↔ s = ∅ ∨ s = {x} := by obtain rfl | hs := s.eq_empty_or_nonempty · exact ⟨fun _ => Or.inl rfl, fun _ => empty_subset _⟩ · simp [eq_singleton_iff_nonempty_unique_mem, hs, hs.ne_empty] #align set.subset_singleton_iff_eq Set.subset_singleton_iff_eq theorem Nonempty.subset_singleton_iff (h : s.Nonempty) : s ⊆ {a} ↔ s = {a} := subset_singleton_iff_eq.trans <| or_iff_right h.ne_empty #align set.nonempty.subset_singleton_iff Set.Nonempty.subset_singleton_iff theorem ssubset_singleton_iff {s : Set α} {x : α} : s ⊂ {x} ↔ s = ∅ := by rw [ssubset_iff_subset_ne, subset_singleton_iff_eq, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] exact fun h => h ▸ (singleton_ne_empty _).symm #align set.ssubset_singleton_iff Set.ssubset_singleton_iff theorem eq_empty_of_ssubset_singleton {s : Set α} {x : α} (hs : s ⊂ {x}) : s = ∅ := ssubset_singleton_iff.1 hs #align set.eq_empty_of_ssubset_singleton Set.eq_empty_of_ssubset_singleton theorem eq_of_nonempty_of_subsingleton {α} [Subsingleton α] (s t : Set α) [Nonempty s] [Nonempty t] : s = t := nonempty_of_nonempty_subtype.eq_univ.trans nonempty_of_nonempty_subtype.eq_univ.symm theorem eq_of_nonempty_of_subsingleton' {α} [Subsingleton α] {s : Set α} (t : Set α) (hs : s.Nonempty) [Nonempty t] : s = t := have := hs.to_subtype; eq_of_nonempty_of_subsingleton s t set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_zero [Subsingleton α] [Zero α] {s : Set α} (h : s.Nonempty) : s = {0} := eq_of_nonempty_of_subsingleton' {0} h set_option backward.synthInstance.canonInstances false in -- See https://github.com/leanprover-community/mathlib4/issues/12532 theorem Nonempty.eq_one [Subsingleton α] [One α] {s : Set α} (h : s.Nonempty) : s = {1} := eq_of_nonempty_of_subsingleton' {1} h /-! ### Disjointness -/ protected theorem disjoint_iff : Disjoint s t ↔ s ∩ t ⊆ ∅ := disjoint_iff_inf_le #align set.disjoint_iff Set.disjoint_iff theorem disjoint_iff_inter_eq_empty : Disjoint s t ↔ s ∩ t = ∅ := disjoint_iff #align set.disjoint_iff_inter_eq_empty Set.disjoint_iff_inter_eq_empty theorem _root_.Disjoint.inter_eq : Disjoint s t → s ∩ t = ∅ := Disjoint.eq_bot #align disjoint.inter_eq Disjoint.inter_eq theorem disjoint_left : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → a ∉ t := disjoint_iff_inf_le.trans <| forall_congr' fun _ => not_and #align set.disjoint_left Set.disjoint_left theorem disjoint_right : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ t → a ∉ s := by rw [disjoint_comm, disjoint_left] #align set.disjoint_right Set.disjoint_right lemma not_disjoint_iff : ¬Disjoint s t ↔ ∃ x, x ∈ s ∧ x ∈ t := Set.disjoint_iff.not.trans <| not_forall.trans <| exists_congr fun _ ↦ not_not #align set.not_disjoint_iff Set.not_disjoint_iff lemma not_disjoint_iff_nonempty_inter : ¬ Disjoint s t ↔ (s ∩ t).Nonempty := not_disjoint_iff #align set.not_disjoint_iff_nonempty_inter Set.not_disjoint_iff_nonempty_inter alias ⟨_, Nonempty.not_disjoint⟩ := not_disjoint_iff_nonempty_inter #align set.nonempty.not_disjoint Set.Nonempty.not_disjoint lemma disjoint_or_nonempty_inter (s t : Set α) : Disjoint s t ∨ (s ∩ t).Nonempty := (em _).imp_right not_disjoint_iff_nonempty_inter.1 #align set.disjoint_or_nonempty_inter Set.disjoint_or_nonempty_inter lemma disjoint_iff_forall_ne : Disjoint s t ↔ ∀ ⦃a⦄, a ∈ s → ∀ ⦃b⦄, b ∈ t → a ≠ b := by simp only [Ne, disjoint_left, @imp_not_comm _ (_ = _), forall_eq'] #align set.disjoint_iff_forall_ne Set.disjoint_iff_forall_ne alias ⟨_root_.Disjoint.ne_of_mem, _⟩ := disjoint_iff_forall_ne #align disjoint.ne_of_mem Disjoint.ne_of_mem lemma disjoint_of_subset_left (h : s ⊆ u) (d : Disjoint u t) : Disjoint s t := d.mono_left h #align set.disjoint_of_subset_left Set.disjoint_of_subset_left lemma disjoint_of_subset_right (h : t ⊆ u) (d : Disjoint s u) : Disjoint s t := d.mono_right h #align set.disjoint_of_subset_right Set.disjoint_of_subset_right lemma disjoint_of_subset (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) (h : Disjoint s₂ t₂) : Disjoint s₁ t₁ := h.mono hs ht #align set.disjoint_of_subset Set.disjoint_of_subset @[simp] lemma disjoint_union_left : Disjoint (s ∪ t) u ↔ Disjoint s u ∧ Disjoint t u := disjoint_sup_left #align set.disjoint_union_left Set.disjoint_union_left @[simp] lemma disjoint_union_right : Disjoint s (t ∪ u) ↔ Disjoint s t ∧ Disjoint s u := disjoint_sup_right #align set.disjoint_union_right Set.disjoint_union_right @[simp] lemma disjoint_empty (s : Set α) : Disjoint s ∅ := disjoint_bot_right #align set.disjoint_empty Set.disjoint_empty @[simp] lemma empty_disjoint (s : Set α) : Disjoint ∅ s := disjoint_bot_left #align set.empty_disjoint Set.empty_disjoint @[simp] lemma univ_disjoint : Disjoint univ s ↔ s = ∅ := top_disjoint #align set.univ_disjoint Set.univ_disjoint @[simp] lemma disjoint_univ : Disjoint s univ ↔ s = ∅ := disjoint_top #align set.disjoint_univ Set.disjoint_univ lemma disjoint_sdiff_left : Disjoint (t \ s) s := disjoint_sdiff_self_left #align set.disjoint_sdiff_left Set.disjoint_sdiff_left lemma disjoint_sdiff_right : Disjoint s (t \ s) := disjoint_sdiff_self_right #align set.disjoint_sdiff_right Set.disjoint_sdiff_right -- TODO: prove this in terms of a lattice lemma theorem disjoint_sdiff_inter : Disjoint (s \ t) (s ∩ t) := disjoint_of_subset_right inter_subset_right disjoint_sdiff_left #align set.disjoint_sdiff_inter Set.disjoint_sdiff_inter theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut #align set.diff_union_diff_cancel Set.diff_union_diff_cancel theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h #align set.diff_diff_eq_sdiff_union Set.diff_diff_eq_sdiff_union @[simp default+1] lemma disjoint_singleton_left : Disjoint {a} s ↔ a ∉ s := by simp [Set.disjoint_iff, subset_def] #align set.disjoint_singleton_left Set.disjoint_singleton_left @[simp] lemma disjoint_singleton_right : Disjoint s {a} ↔ a ∉ s := disjoint_comm.trans disjoint_singleton_left #align set.disjoint_singleton_right Set.disjoint_singleton_right lemma disjoint_singleton : Disjoint ({a} : Set α) {b} ↔ a ≠ b := by simp #align set.disjoint_singleton Set.disjoint_singleton lemma subset_diff : s ⊆ t \ u ↔ s ⊆ t ∧ Disjoint s u := le_iff_subset.symm.trans le_sdiff #align set.subset_diff Set.subset_diff lemma ssubset_iff_sdiff_singleton : s ⊂ t ↔ ∃ a ∈ t, s ⊆ t \ {a} := by simp [ssubset_iff_insert, subset_diff, insert_subset_iff]; aesop theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ #align set.inter_diff_distrib_left Set.inter_diff_distrib_left theorem inter_diff_distrib_right (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ #align set.inter_diff_distrib_right Set.inter_diff_distrib_right /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl #align set.compl_def Set.compl_def theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h #align set.mem_compl Set.mem_compl theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl #align set.compl_set_of Set.compl_setOf theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h #align set.not_mem_of_mem_compl Set.not_mem_of_mem_compl theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not #align set.not_mem_compl_iff Set.not_mem_compl_iff @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot #align set.inter_compl_self Set.inter_compl_self @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot #align set.compl_inter_self Set.compl_inter_self @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot #align set.compl_empty Set.compl_empty @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup #align set.compl_union Set.compl_union theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf #align set.compl_inter Set.compl_inter @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top #align set.compl_univ Set.compl_univ @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot #align set.compl_empty_iff Set.compl_empty_iff @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top #align set.compl_univ_iff Set.compl_univ_iff theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm #align set.compl_ne_univ Set.compl_ne_univ theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_not_mem s).symm #align set.nonempty_compl Set.nonempty_compl @[simp] lemma nonempty_compl_of_nontrivial [Nontrivial α] (x : α) : Set.Nonempty {x}ᶜ := by obtain ⟨y, hy⟩ := exists_ne x exact ⟨y, by simp [hy]⟩ theorem mem_compl_singleton_iff {a x : α} : x ∈ ({a} : Set α)ᶜ ↔ x ≠ a := Iff.rfl #align set.mem_compl_singleton_iff Set.mem_compl_singleton_iff theorem compl_singleton_eq (a : α) : ({a} : Set α)ᶜ = { x | x ≠ a } := rfl #align set.compl_singleton_eq Set.compl_singleton_eq @[simp] theorem compl_ne_eq_singleton (a : α) : ({ x | x ≠ a } : Set α)ᶜ = {a} := compl_compl _ #align set.compl_ne_eq_singleton Set.compl_ne_eq_singleton theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not #align set.union_eq_compl_compl_inter_compl Set.union_eq_compl_compl_inter_compl theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not #align set.inter_eq_compl_compl_union_compl Set.inter_eq_compl_compl_union_compl @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ #align set.union_compl_self Set.union_compl_self @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] #align set.compl_union_self Set.compl_union_self theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ #align set.compl_subset_comm Set.compl_subset_comm theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t #align set.subset_compl_comm Set.subset_compl_comm @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ #align set.compl_subset_compl Set.compl_subset_compl @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_compl_iff_disjoint_left : s ⊆ tᶜ ↔ Disjoint t s := @le_compl_iff_disjoint_left (Set α) _ _ _ #align set.subset_compl_iff_disjoint_left Set.subset_compl_iff_disjoint_left theorem subset_compl_iff_disjoint_right : s ⊆ tᶜ ↔ Disjoint s t := @le_compl_iff_disjoint_right (Set α) _ _ _ #align set.subset_compl_iff_disjoint_right Set.subset_compl_iff_disjoint_right theorem disjoint_compl_left_iff_subset : Disjoint sᶜ t ↔ t ⊆ s := disjoint_compl_left_iff #align set.disjoint_compl_left_iff_subset Set.disjoint_compl_left_iff_subset theorem disjoint_compl_right_iff_subset : Disjoint s tᶜ ↔ s ⊆ t := disjoint_compl_right_iff #align set.disjoint_compl_right_iff_subset Set.disjoint_compl_right_iff_subset alias ⟨_, _root_.Disjoint.subset_compl_right⟩ := subset_compl_iff_disjoint_right #align disjoint.subset_compl_right Disjoint.subset_compl_right alias ⟨_, _root_.Disjoint.subset_compl_left⟩ := subset_compl_iff_disjoint_left #align disjoint.subset_compl_left Disjoint.subset_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_left⟩ := disjoint_compl_left_iff_subset #align has_subset.subset.disjoint_compl_left HasSubset.Subset.disjoint_compl_left alias ⟨_, _root_.HasSubset.Subset.disjoint_compl_right⟩ := disjoint_compl_right_iff_subset #align has_subset.subset.disjoint_compl_right HasSubset.Subset.disjoint_compl_right theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le #align set.subset_union_compl_iff_inter_subset Set.subset_union_compl_iff_inter_subset theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left #align set.compl_subset_iff_union Set.compl_subset_iff_union @[simp] theorem subset_compl_singleton_iff {a : α} {s : Set α} : s ⊆ {a}ᶜ ↔ a ∉ s := subset_compl_comm.trans singleton_subset_iff #align set.subset_compl_singleton_iff Set.subset_compl_singleton_iff theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or #align set.inter_subset Set.inter_subset theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm #align set.inter_compl_nonempty_iff Set.inter_compl_nonempty_iff /-! ### Lemmas about set difference -/ theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx #align set.not_mem_diff_of_mem Set.not_mem_diff_of_mem theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left #align set.mem_of_mem_diff Set.mem_of_mem_diff theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right #align set.not_mem_of_mem_diff Set.not_mem_of_mem_diff theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] #align set.diff_eq_compl_inter Set.diff_eq_compl_inter theorem nonempty_diff {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff #align set.nonempty_diff Set.nonempty_diff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le #align set.diff_subset Set.diff_subset theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ #align set.union_diff_cancel' Set.union_diff_cancel' theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h #align set.union_diff_cancel Set.union_diff_cancel theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_left Set.union_diff_cancel_left theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h #align set.union_diff_cancel_right Set.union_diff_cancel_right @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self #align set.union_diff_left Set.union_diff_left @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self #align set.union_diff_right Set.union_diff_right theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff #align set.union_diff_distrib Set.union_diff_distrib theorem inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc #align set.inter_diff_assoc Set.inter_diff_assoc @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right #align set.inter_diff_self Set.inter_diff_self @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t #align set.inter_union_diff Set.inter_union_diff @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ #align set.diff_union_inter Set.diff_union_inter @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ #align set.inter_union_compl Set.inter_union_compl @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff #align set.diff_subset_diff Set.diff_subset_diff @[gcongr] theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› #align set.diff_subset_diff_left Set.diff_subset_diff_left @[gcongr] theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› #align set.diff_subset_diff_right Set.diff_subset_diff_right theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm #align set.compl_eq_univ_diff Set.compl_eq_univ_diff @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff #align set.empty_diff Set.empty_diff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff #align set.diff_eq_empty Set.diff_eq_empty @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot #align set.diff_empty Set.diff_empty @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) #align set.diff_univ Set.diff_univ theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left #align set.diff_diff Set.diff_diff -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm #align set.diff_diff_comm Set.diff_diff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff #align set.diff_subset_iff Set.diff_subset_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup #align set.subset_diff_union Set.subset_diff_union theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) #align set.diff_union_of_subset Set.diff_union_of_subset @[simp] theorem diff_singleton_subset_iff {x : α} {s t : Set α} : s \ {x} ⊆ t ↔ s ⊆ insert x t := by rw [← union_singleton, union_comm] apply diff_subset_iff #align set.diff_singleton_subset_iff Set.diff_singleton_subset_iff theorem subset_diff_singleton {x : α} {s t : Set α} (h : s ⊆ t) (hx : x ∉ s) : s ⊆ t \ {x} := subset_inter h <| subset_compl_comm.1 <| singleton_subset_iff.2 hx #align set.subset_diff_singleton Set.subset_diff_singleton theorem subset_insert_diff_singleton (x : α) (s : Set α) : s ⊆ insert x (s \ {x}) := by rw [← diff_singleton_subset_iff] #align set.subset_insert_diff_singleton Set.subset_insert_diff_singleton theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm #align set.diff_subset_comm Set.diff_subset_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf #align set.diff_inter Set.diff_inter theorem diff_inter_diff {s t u : Set α} : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm #align set.diff_inter_diff Set.diff_inter_diff theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl #align set.diff_compl Set.diff_compl theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' #align set.diff_diff_right Set.diff_diff_right @[simp] theorem insert_diff_of_mem (s) (h : a ∈ t) : insert a s \ t = s \ t := by ext constructor <;> simp (config := { contextual := true }) [or_imp, h] #align set.insert_diff_of_mem Set.insert_diff_of_mem theorem insert_diff_of_not_mem (s) (h : a ∉ t) : insert a s \ t = insert a (s \ t) := by classical ext x by_cases h' : x ∈ t · have : x ≠ a := by intro H rw [H] at h' exact h h' simp [h, h', this] · simp [h, h'] #align set.insert_diff_of_not_mem Set.insert_diff_of_not_mem theorem insert_diff_self_of_not_mem {a : α} {s : Set α} (h : a ∉ s) : insert a s \ {a} = s := by ext x simp [and_iff_left_of_imp fun hx : x ∈ s => show x ≠ a from fun hxa => h <| hxa ▸ hx] #align set.insert_diff_self_of_not_mem Set.insert_diff_self_of_not_mem @[simp] theorem insert_diff_eq_singleton {a : α} {s : Set α} (h : a ∉ s) : insert a s \ s = {a} := by ext rw [Set.mem_diff, Set.mem_insert_iff, Set.mem_singleton_iff, or_and_right, and_not_self_iff, or_false_iff, and_iff_left_iff_imp] rintro rfl exact h #align set.insert_diff_eq_singleton Set.insert_diff_eq_singleton theorem inter_insert_of_mem (h : a ∈ s) : s ∩ insert a t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.inter_insert_of_mem Set.inter_insert_of_mem theorem insert_inter_of_mem (h : a ∈ t) : insert a s ∩ t = insert a (s ∩ t) := by rw [insert_inter_distrib, insert_eq_of_mem h] #align set.insert_inter_of_mem Set.insert_inter_of_mem theorem inter_insert_of_not_mem (h : a ∉ s) : s ∩ insert a t = s ∩ t := ext fun _ => and_congr_right fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.inter_insert_of_not_mem Set.inter_insert_of_not_mem theorem insert_inter_of_not_mem (h : a ∉ t) : insert a s ∩ t = s ∩ t := ext fun _ => and_congr_left fun hx => or_iff_right <| ne_of_mem_of_not_mem hx h #align set.insert_inter_of_not_mem Set.insert_inter_of_not_mem @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ #align set.union_diff_self Set.union_diff_self @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ #align set.diff_union_self Set.diff_union_self @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left #align set.diff_inter_self Set.diff_inter_self @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ #align set.diff_inter_self_eq_diff Set.diff_inter_self_eq_diff @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ #align set.diff_self_inter Set.diff_self_inter @[simp] theorem diff_singleton_eq_self {a : α} {s : Set α} (h : a ∉ s) : s \ {a} = s := sdiff_eq_self_iff_disjoint.2 <| by simp [h] #align set.diff_singleton_eq_self Set.diff_singleton_eq_self @[simp] theorem diff_singleton_sSubset {s : Set α} {a : α} : s \ {a} ⊂ s ↔ a ∈ s := sdiff_le.lt_iff_ne.trans <| sdiff_eq_left.not.trans <| by simp #align set.diff_singleton_ssubset Set.diff_singleton_sSubset @[simp] theorem insert_diff_singleton {a : α} {s : Set α} : insert a (s \ {a}) = insert a s := by simp [insert_eq, union_diff_self, -union_singleton, -singleton_union] #align set.insert_diff_singleton Set.insert_diff_singleton theorem insert_diff_singleton_comm (hab : a ≠ b) (s : Set α) : insert a (s \ {b}) = insert a s \ {b} := by simp_rw [← union_singleton, union_diff_distrib, diff_singleton_eq_self (mem_singleton_iff.not.2 hab.symm)] #align set.insert_diff_singleton_comm Set.insert_diff_singleton_comm --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self #align set.diff_self Set.diff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self #align set.diff_diff_right_self Set.diff_diff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h #align set.diff_diff_cancel_left Set.diff_diff_cancel_left theorem mem_diff_singleton {x y : α} {s : Set α} : x ∈ s \ {y} ↔ x ∈ s ∧ x ≠ y := Iff.rfl #align set.mem_diff_singleton Set.mem_diff_singleton theorem mem_diff_singleton_empty {t : Set (Set α)} : s ∈ t \ {∅} ↔ s ∈ t ∧ s.Nonempty := mem_diff_singleton.trans <| and_congr_right' nonempty_iff_ne_empty.symm #align set.mem_diff_singleton_empty Set.mem_diff_singleton_empty theorem subset_insert_iff {s t : Set α} {x : α} : s ⊆ insert x t ↔ s ⊆ t ∨ (x ∈ s ∧ s \ {x} ⊆ t) := by rw [← diff_singleton_subset_iff] by_cases hx : x ∈ s · rw [and_iff_right hx, or_iff_right_of_imp diff_subset.trans] rw [diff_singleton_eq_self hx, or_iff_left_of_imp And.right] theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf #align set.union_eq_diff_union_diff_union_inter Set.union_eq_diff_union_diff_union_inter /-! ### Lemmas about pairs -/ --Porting note (#10618): removed `simp` attribute because `simp` can prove it theorem pair_eq_singleton (a : α) : ({a, a} : Set α) = {a} := union_self _ #align set.pair_eq_singleton Set.pair_eq_singleton theorem pair_comm (a b : α) : ({a, b} : Set α) = {b, a} := union_comm _ _ #align set.pair_comm Set.pair_comm theorem pair_eq_pair_iff {x y z w : α} : ({x, y} : Set α) = {z, w} ↔ x = z ∧ y = w ∨ x = w ∧ y = z := by simp [subset_antisymm_iff, insert_subset_iff]; aesop #align set.pair_eq_pair_iff Set.pair_eq_pair_iff theorem pair_diff_left (hne : a ≠ b) : ({a, b} : Set α) \ {a} = {b} := by rw [insert_diff_of_mem _ (mem_singleton a), diff_singleton_eq_self (by simpa)] theorem pair_diff_right (hne : a ≠ b) : ({a, b} : Set α) \ {b} = {a} := by rw [pair_comm, pair_diff_left hne.symm] theorem pair_subset_iff : {a, b} ⊆ s ↔ a ∈ s ∧ b ∈ s := by rw [insert_subset_iff, singleton_subset_iff] theorem pair_subset (ha : a ∈ s) (hb : b ∈ s) : {a, b} ⊆ s := pair_subset_iff.2 ⟨ha,hb⟩ theorem subset_pair_iff : s ⊆ {a, b} ↔ ∀ x ∈ s, x = a ∨ x = b := by simp [subset_def] theorem subset_pair_iff_eq {x y : α} : s ⊆ {x, y} ↔ s = ∅ ∨ s = {x} ∨ s = {y} ∨ s = {x, y} := by refine ⟨?_, by rintro (rfl | rfl | rfl | rfl) <;> simp [pair_subset_iff]⟩ rw [subset_insert_iff, subset_singleton_iff_eq, subset_singleton_iff_eq, ← subset_empty_iff (s := s \ {x}), diff_subset_iff, union_empty, subset_singleton_iff_eq] have h : x ∈ s → {y} = s \ {x} → s = {x,y} := fun h₁ h₂ ↦ by simp [h₁, h₂] tauto theorem Nonempty.subset_pair_iff_eq (hs : s.Nonempty) : s ⊆ {a, b} ↔ s = {a} ∨ s = {b} ∨ s = {a, b} := by rw [Set.subset_pair_iff_eq, or_iff_right]; exact hs.ne_empty /-! ### Symmetric difference -/ section open scoped symmDiff theorem mem_symmDiff : a ∈ s ∆ t ↔ a ∈ s ∧ a ∉ t ∨ a ∈ t ∧ a ∉ s := Iff.rfl #align set.mem_symm_diff Set.mem_symmDiff protected theorem symmDiff_def (s t : Set α) : s ∆ t = s \ t ∪ t \ s := rfl #align set.symm_diff_def Set.symmDiff_def theorem symmDiff_subset_union : s ∆ t ⊆ s ∪ t := @symmDiff_le_sup (Set α) _ _ _ #align set.symm_diff_subset_union Set.symmDiff_subset_union @[simp] theorem symmDiff_eq_empty : s ∆ t = ∅ ↔ s = t := symmDiff_eq_bot #align set.symm_diff_eq_empty Set.symmDiff_eq_empty @[simp] theorem symmDiff_nonempty : (s ∆ t).Nonempty ↔ s ≠ t := nonempty_iff_ne_empty.trans symmDiff_eq_empty.not #align set.symm_diff_nonempty Set.symmDiff_nonempty theorem inter_symmDiff_distrib_left (s t u : Set α) : s ∩ t ∆ u = (s ∩ t) ∆ (s ∩ u) := inf_symmDiff_distrib_left _ _ _ #align set.inter_symm_diff_distrib_left Set.inter_symmDiff_distrib_left theorem inter_symmDiff_distrib_right (s t u : Set α) : s ∆ t ∩ u = (s ∩ u) ∆ (t ∩ u) := inf_symmDiff_distrib_right _ _ _ #align set.inter_symm_diff_distrib_right Set.inter_symmDiff_distrib_right theorem subset_symmDiff_union_symmDiff_left (h : Disjoint s t) : u ⊆ s ∆ u ∪ t ∆ u := h.le_symmDiff_sup_symmDiff_left #align set.subset_symm_diff_union_symm_diff_left Set.subset_symmDiff_union_symmDiff_left theorem subset_symmDiff_union_symmDiff_right (h : Disjoint t u) : s ⊆ s ∆ t ∪ s ∆ u := h.le_symmDiff_sup_symmDiff_right #align set.subset_symm_diff_union_symm_diff_right Set.subset_symmDiff_union_symmDiff_right end /-! ### Powerset -/ #align set.powerset Set.powerset theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h #align set.mem_powerset Set.mem_powerset theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h #align set.subset_of_mem_powerset Set.subset_of_mem_powerset @[simp] theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s := Iff.rfl #align set.mem_powerset_iff Set.mem_powerset_iff theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t := ext fun _ => subset_inter_iff #align set.powerset_inter Set.powerset_inter @[simp] theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t := ⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩ #align set.powerset_mono Set.powerset_mono theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2 #align set.monotone_powerset Set.monotone_powerset @[simp] theorem powerset_nonempty : (𝒫 s).Nonempty := ⟨∅, fun _ h => empty_subset s h⟩ #align set.powerset_nonempty Set.powerset_nonempty @[simp] theorem powerset_empty : 𝒫(∅ : Set α) = {∅} := ext fun _ => subset_empty_iff #align set.powerset_empty Set.powerset_empty @[simp] theorem powerset_univ : 𝒫(univ : Set α) = univ := eq_univ_of_forall subset_univ #align set.powerset_univ Set.powerset_univ /-- The powerset of a singleton contains only `∅` and the singleton itself. -/ theorem powerset_singleton (x : α) : 𝒫({x} : Set α) = {∅, {x}} := by ext y rw [mem_powerset_iff, subset_singleton_iff_eq, mem_insert_iff, mem_singleton_iff] #align set.powerset_singleton Set.powerset_singleton /-! ### Sets defined as an if-then-else -/ theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) : (x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h := by split_ifs with hp · exact ⟨fun hx => ⟨fun _ => hx, fun hnp => (hnp hp).elim⟩, fun hx => hx.1 hp⟩ · exact ⟨fun hx => ⟨fun h => (hp h).elim, fun _ => hx⟩, fun hx => hx.2 hp⟩ theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by split_ifs <;> simp_all #align set.mem_dite_univ_right Set.mem_dite_univ_right @[simp] theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t Set.univ ↔ p → x ∈ t := mem_dite_univ_right p (fun _ => t) x #align set.mem_ite_univ_right Set.mem_ite_univ_right theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by split_ifs <;> simp_all #align set.mem_dite_univ_left Set.mem_dite_univ_left @[simp] theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p Set.univ t ↔ ¬p → x ∈ t := mem_dite_univ_left p (fun _ => t) x #align set.mem_ite_univ_left Set.mem_ite_univ_left theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false, not_not] exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩ #align set.mem_dite_empty_right Set.mem_dite_empty_right @[simp] theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t ∅ ↔ p ∧ x ∈ t := (mem_dite_empty_right p (fun _ => t) x).trans (by simp) #align set.mem_ite_empty_right Set.mem_ite_empty_right theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false] exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩ #align set.mem_dite_empty_left Set.mem_dite_empty_left @[simp] theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t := (mem_dite_empty_left p (fun _ => t) x).trans (by simp) #align set.mem_ite_empty_left Set.mem_ite_empty_left /-! ### If-then-else for sets -/ /-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`. Defined as `s ∩ t ∪ s' \ t`. -/ protected def ite (t s s' : Set α) : Set α := s ∩ t ∪ s' \ t #align set.ite Set.ite @[simp] theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty] #align set.ite_inter_self Set.ite_inter_self @[simp] theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq] #align set.ite_compl Set.ite_compl @[simp] theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by rw [← ite_compl, ite_inter_self] #align set.ite_inter_compl_self Set.ite_inter_compl_self @[simp] theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t := ite_inter_compl_self t s s' #align set.ite_diff_self Set.ite_diff_self @[simp] theorem ite_same (t s : Set α) : t.ite s s = s := inter_union_diff _ _ #align set.ite_same Set.ite_same @[simp] theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite] #align set.ite_left Set.ite_left @[simp] theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite] #align set.ite_right Set.ite_right @[simp] theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite] #align set.ite_empty Set.ite_empty @[simp] theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite] #align set.ite_univ Set.ite_univ @[simp] theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite] #align set.ite_empty_left Set.ite_empty_left @[simp] theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite] #align set.ite_empty_right Set.ite_empty_right theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') : t.ite s₁ s₁' ⊆ t.ite s₂ s₂' := union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h') #align set.ite_mono Set.ite_mono theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' := union_subset_union inter_subset_left diff_subset #align set.ite_subset_union Set.ite_subset_union theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' := ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right #align set.inter_subset_ite Set.inter_subset_ite
Mathlib/Data/Set/Basic.lean
2,327
2,331
theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) : t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by
ext x simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union] tauto
/- Copyright (c) 2022 Julian Kuelshammer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Julian Kuelshammer -/ import Mathlib.Algebra.BigOperators.Fin import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Algebra.CharZero.Lemmas import Mathlib.Data.Finset.NatAntidiagonal import Mathlib.Data.Nat.Choose.Central import Mathlib.Data.Tree.Basic import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.GCongr import Mathlib.Tactic.Positivity #align_import combinatorics.catalan from "leanprover-community/mathlib"@"26b40791e4a5772a4e53d0e28e4df092119dc7da" /-! # Catalan numbers The Catalan numbers (http://oeis.org/A000108) are probably the most ubiquitous sequence of integers in mathematics. They enumerate several important objects like binary trees, Dyck paths, and triangulations of convex polygons. ## Main definitions * `catalan n`: the `n`th Catalan number, defined recursively as `catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)`. ## Main results * `catalan_eq_centralBinom_div`: The explicit formula for the Catalan number using the central binomial coefficient, `catalan n = Nat.centralBinom n / (n + 1)`. * `treesOfNodesEq_card_eq_catalan`: The number of binary trees with `n` internal nodes is `catalan n` ## Implementation details The proof of `catalan_eq_centralBinom_div` follows https://math.stackexchange.com/questions/3304415 ## TODO * Prove that the Catalan numbers enumerate many interesting objects. * Provide the many variants of Catalan numbers, e.g. associated to complex reflection groups, Fuss-Catalan, etc. -/ open Finset open Finset.antidiagonal (fst_le snd_le) /-- The recursive definition of the sequence of Catalan numbers: `catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i)` -/ def catalan : ℕ → ℕ | 0 => 1 | n + 1 => ∑ i : Fin n.succ, catalan i * catalan (n - i) #align catalan catalan @[simp] theorem catalan_zero : catalan 0 = 1 := by rw [catalan] #align catalan_zero catalan_zero theorem catalan_succ (n : ℕ) : catalan (n + 1) = ∑ i : Fin n.succ, catalan i * catalan (n - i) := by rw [catalan] #align catalan_succ catalan_succ
Mathlib/Combinatorics/Enumerative/Catalan.lean
72
75
theorem catalan_succ' (n : ℕ) : catalan (n + 1) = ∑ ij ∈ antidiagonal n, catalan ij.1 * catalan ij.2 := by
rw [catalan_succ, Nat.sum_antidiagonal_eq_sum_range_succ (fun x y => catalan x * catalan y) n, sum_range]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.RingTheory.Localization.Basic #align_import ring_theory.localization.integer from "leanprover-community/mathlib"@"9556784a5b84697562e9c6acb40500d4a82e675a" /-! # Integer elements of a localization ## Main definitions * `IsLocalization.IsInteger` is a predicate stating that `x : S` is in the image of `R` ## Implementation notes See `RingTheory/Localization/Basic.lean` for a design overview. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ variable {R : Type*} [CommSemiring R] {M : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] open Function namespace IsLocalization section variable (R) -- TODO: define a subalgebra of `IsInteger`s /-- Given `a : S`, `S` a localization of `R`, `IsInteger R a` iff `a` is in the image of the localization map from `R` to `S`. -/ def IsInteger (a : S) : Prop := a ∈ (algebraMap R S).rangeS #align is_localization.is_integer IsLocalization.IsInteger end theorem isInteger_zero : IsInteger R (0 : S) := Subsemiring.zero_mem _ #align is_localization.is_integer_zero IsLocalization.isInteger_zero theorem isInteger_one : IsInteger R (1 : S) := Subsemiring.one_mem _ #align is_localization.is_integer_one IsLocalization.isInteger_one theorem isInteger_add {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a + b) := Subsemiring.add_mem _ ha hb #align is_localization.is_integer_add IsLocalization.isInteger_add theorem isInteger_mul {a b : S} (ha : IsInteger R a) (hb : IsInteger R b) : IsInteger R (a * b) := Subsemiring.mul_mem _ ha hb #align is_localization.is_integer_mul IsLocalization.isInteger_mul theorem isInteger_smul {a : R} {b : S} (hb : IsInteger R b) : IsInteger R (a • b) := by rcases hb with ⟨b', hb⟩ use a * b' rw [← hb, (algebraMap R S).map_mul, Algebra.smul_def] #align is_localization.is_integer_smul IsLocalization.isInteger_smul variable (M) variable [IsLocalization M S] /-- Each element `a : S` has an `M`-multiple which is an integer. This version multiplies `a` on the right, matching the argument order in `LocalizationMap.surj`. -/ theorem exists_integer_multiple' (a : S) : ∃ b : M, IsInteger R (a * algebraMap R S b) := let ⟨⟨Num, denom⟩, h⟩ := IsLocalization.surj _ a ⟨denom, Set.mem_range.mpr ⟨Num, h.symm⟩⟩ #align is_localization.exists_integer_multiple' IsLocalization.exists_integer_multiple' /-- Each element `a : S` has an `M`-multiple which is an integer. This version multiplies `a` on the left, matching the argument order in the `SMul` instance. -/ theorem exists_integer_multiple (a : S) : ∃ b : M, IsInteger R ((b : R) • a) := by simp_rw [Algebra.smul_def, mul_comm _ a] apply exists_integer_multiple' #align is_localization.exists_integer_multiple IsLocalization.exists_integer_multiple /-- We can clear the denominators of a `Finset`-indexed family of fractions. -/ theorem exist_integer_multiples {ι : Type*} (s : Finset ι) (f : ι → S) : ∃ b : M, ∀ i ∈ s, IsLocalization.IsInteger R ((b : R) • f i) := by haveI := Classical.propDecidable refine ⟨∏ i ∈ s, (sec M (f i)).2, fun i hi => ⟨?_, ?_⟩⟩ · exact (∏ j ∈ s.erase i, (sec M (f j)).2) * (sec M (f i)).1 rw [RingHom.map_mul, sec_spec', ← mul_assoc, ← (algebraMap R S).map_mul, ← Algebra.smul_def] congr 2 refine _root_.trans ?_ (map_prod (Submonoid.subtype M) _ _).symm rw [mul_comm,Submonoid.coe_finset_prod, -- Porting note: explicitly supplied `f` ← Finset.prod_insert (f := fun i => ((sec M (f i)).snd : R)) (s.not_mem_erase i), Finset.insert_erase hi] rfl #align is_localization.exist_integer_multiples IsLocalization.exist_integer_multiples /-- We can clear the denominators of a finite indexed family of fractions. -/
Mathlib/RingTheory/Localization/Integer.lean
107
111
theorem exist_integer_multiples_of_finite {ι : Type*} [Finite ι] (f : ι → S) : ∃ b : M, ∀ i, IsLocalization.IsInteger R ((b : R) • f i) := by
cases nonempty_fintype ι obtain ⟨b, hb⟩ := exist_integer_multiples M Finset.univ f exact ⟨b, fun i => hb i (Finset.mem_univ _)⟩
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Functor.ReflectsIso #align_import category_theory.monoidal.center from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7" /-! # Half braidings and the Drinfeld center of a monoidal category We define `Center C` to be pairs `⟨X, b⟩`, where `X : C` and `b` is a half-braiding on `X`. We show that `Center C` is braided monoidal, and provide the monoidal functor `Center.forget` from `Center C` back to `C`. ## Implementation notes Verifying the various axioms directly requires tedious rewriting. Using the `slice` tactic may make the proofs marginally more readable. More exciting, however, would be to make possible one of the following options: 1. Integration with homotopy.io / globular to give "picture proofs". 2. The monoidal coherence theorem, so we can ignore associators (after which most of these proofs are trivial). 3. Automating these proofs using `rewrite_search` or some relative. In this file, we take the second approach using the monoidal composition `⊗≫` and the `coherence` tactic. -/ open CategoryTheory open CategoryTheory.MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- A half-braiding on `X : C` is a family of isomorphisms `X ⊗ U ≅ U ⊗ X`, monoidally natural in `U : C`. Thinking of `C` as a 2-category with a single `0`-morphism, these are the same as natural transformations (in the pseudo- sense) of the identity 2-functor on `C`, which send the unique `0`-morphism to `X`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. structure HalfBraiding (X : C) where β : ∀ U, X ⊗ U ≅ U ⊗ X monoidal : ∀ U U', (β (U ⊗ U')).hom = (α_ _ _ _).inv ≫ ((β U).hom ▷ U') ≫ (α_ _ _ _).hom ≫ (U ◁ (β U').hom) ≫ (α_ _ _ _).inv := by aesop_cat naturality : ∀ {U U'} (f : U ⟶ U'), (X ◁ f) ≫ (β U').hom = (β U).hom ≫ (f ▷ X) := by aesop_cat #align category_theory.half_braiding CategoryTheory.HalfBraiding attribute [reassoc, simp] HalfBraiding.monoidal -- the reassoc lemma is redundant as a simp lemma attribute [simp, reassoc] HalfBraiding.naturality variable (C) /-- The Drinfeld center of a monoidal category `C` has as objects pairs `⟨X, b⟩`, where `X : C` and `b` is a half-braiding on `X`. -/ -- @[nolint has_nonempty_instance] -- Porting note(#5171): This linter does not exist yet. def Center := Σ X : C, HalfBraiding X #align category_theory.center CategoryTheory.Center namespace Center variable {C} /-- A morphism in the Drinfeld center of `C`. -/ -- Porting note(#5171): linter not ported yet @[ext] -- @[nolint has_nonempty_instance] structure Hom (X Y : Center C) where f : X.1 ⟶ Y.1 comm : ∀ U, (f ▷ U) ≫ (Y.2.β U).hom = (X.2.β U).hom ≫ (U ◁ f) := by aesop_cat #align category_theory.center.hom CategoryTheory.Center.Hom attribute [reassoc (attr := simp)] Hom.comm instance : Quiver (Center C) where Hom := Hom @[ext] theorem ext {X Y : Center C} (f g : X ⟶ Y) (w : f.f = g.f) : f = g := by cases f; cases g; congr #align category_theory.center.ext CategoryTheory.Center.ext instance : Category (Center C) where id X := { f := 𝟙 X.1 } comp f g := { f := f.f ≫ g.f } @[simp] theorem id_f (X : Center C) : Hom.f (𝟙 X) = 𝟙 X.1 := rfl #align category_theory.center.id_f CategoryTheory.Center.id_f @[simp] theorem comp_f {X Y Z : Center C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).f = f.f ≫ g.f := rfl #align category_theory.center.comp_f CategoryTheory.Center.comp_f /-- Construct an isomorphism in the Drinfeld center from a morphism whose underlying morphism is an isomorphism. -/ @[simps] def isoMk {X Y : Center C} (f : X ⟶ Y) [IsIso f.f] : X ≅ Y where hom := f inv := ⟨inv f.f, fun U => by simp [← cancel_epi (f.f ▷ U), ← comp_whiskerRight_assoc, ← MonoidalCategory.whiskerLeft_comp] ⟩ #align category_theory.center.iso_mk CategoryTheory.Center.isoMk instance isIso_of_f_isIso {X Y : Center C} (f : X ⟶ Y) [IsIso f.f] : IsIso f := by change IsIso (isoMk f).hom infer_instance #align category_theory.center.is_iso_of_f_is_iso CategoryTheory.Center.isIso_of_f_isIso /-- Auxiliary definition for the `MonoidalCategory` instance on `Center C`. -/ @[simps] def tensorObj (X Y : Center C) : Center C := ⟨X.1 ⊗ Y.1, { β := fun U => α_ _ _ _ ≪≫ (whiskerLeftIso X.1 (Y.2.β U)) ≪≫ (α_ _ _ _).symm ≪≫ (whiskerRightIso (X.2.β U) Y.1) ≪≫ α_ _ _ _ monoidal := fun U U' => by dsimp only [Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] simp only [HalfBraiding.monoidal] -- We'd like to commute `X.1 ◁ U ◁ (HalfBraiding.β Y.2 U').hom` -- and `((HalfBraiding.β X.2 U).hom ▷ U' ▷ Y.1)` past each other. -- We do this with the help of the monoidal composition `⊗≫` and the `coherence` tactic. calc _ = 𝟙 _ ⊗≫ X.1 ◁ (HalfBraiding.β Y.2 U).hom ▷ U' ⊗≫ (_ ◁ (HalfBraiding.β Y.2 U').hom ≫ (HalfBraiding.β X.2 U).hom ▷ _) ⊗≫ U ◁ (HalfBraiding.β X.2 U').hom ▷ Y.1 ⊗≫ 𝟙 _ := by coherence _ = _ := by rw [whisker_exchange]; coherence naturality := fun {U U'} f => by dsimp only [Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ (X.1 ◁ (Y.1 ◁ f ≫ (HalfBraiding.β Y.2 U').hom)) ⊗≫ (HalfBraiding.β X.2 U').hom ▷ Y.1 ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X.1 ◁ (HalfBraiding.β Y.2 U).hom ⊗≫ (X.1 ◁ f ≫ (HalfBraiding.β X.2 U').hom) ▷ Y.1 ⊗≫ 𝟙 _ := by rw [HalfBraiding.naturality]; coherence _ = _ := by rw [HalfBraiding.naturality]; coherence }⟩ #align category_theory.center.tensor_obj CategoryTheory.Center.tensorObj @[reassoc]
Mathlib/CategoryTheory/Monoidal/Center.lean
166
179
theorem whiskerLeft_comm (X : Center C) {Y₁ Y₂ : Center C} (f : Y₁ ⟶ Y₂) (U : C) : (X.1 ◁ f.f) ▷ U ≫ ((tensorObj X Y₂).2.β U).hom = ((tensorObj X Y₁).2.β U).hom ≫ U ◁ X.1 ◁ f.f := by
dsimp only [tensorObj_fst, tensorObj_snd_β, Iso.trans_hom, whiskerLeftIso_hom, Iso.symm_hom, whiskerRightIso_hom] calc _ = 𝟙 _ ⊗≫ X.fst ◁ (f.f ▷ U ≫ (HalfBraiding.β Y₂.snd U).hom) ⊗≫ (HalfBraiding.β X.snd U).hom ▷ Y₂.fst ⊗≫ 𝟙 _ := by coherence _ = 𝟙 _ ⊗≫ X.fst ◁ (HalfBraiding.β Y₁.snd U).hom ⊗≫ ((X.fst ⊗ U) ◁ f.f ≫ (HalfBraiding.β X.snd U).hom ▷ Y₂.fst) ⊗≫ 𝟙 _ := by rw [f.comm]; coherence _ = _ := by rw [whisker_exchange]; coherence
/- Copyright (c) 2018 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad -/ import Mathlib.Data.PFunctor.Univariate.M #align_import data.qpf.univariate.basic from "leanprover-community/mathlib"@"14b69e9f3c16630440a2cbd46f1ddad0d561dee7" /-! # Quotients of Polynomial Functors We assume the following: * `P`: a polynomial functor * `W`: its W-type * `M`: its M-type * `F`: a functor We define: * `q`: `QPF` data, representing `F` as a quotient of `P` The main goal is to construct: * `Fix`: the initial algebra with structure map `F Fix → Fix`. * `Cofix`: the final coalgebra with structure map `Cofix → F Cofix` We also show that the composition of qpfs is a qpf, and that the quotient of a qpf is a qpf. The present theory focuses on the univariate case for qpfs ## References * [Jeremy Avigad, Mario M. Carneiro and Simon Hudon, *Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019] -/ universe u /-- Quotients of polynomial functors. Roughly speaking, saying that `F` is a quotient of a polynomial functor means that for each `α`, elements of `F α` are represented by pairs `⟨a, f⟩`, where `a` is the shape of the object and `f` indexes the relevant elements of `α`, in a suitably natural manner. -/ class QPF (F : Type u → Type u) [Functor F] where P : PFunctor.{u} abs : ∀ {α}, P α → F α repr : ∀ {α}, F α → P α abs_repr : ∀ {α} (x : F α), abs (repr x) = x abs_map : ∀ {α β} (f : α → β) (p : P α), abs (P.map f p) = f <$> abs p #align qpf QPF namespace QPF variable {F : Type u → Type u} [Functor F] [q : QPF F] open Functor (Liftp Liftr) /- Show that every qpf is a lawful functor. Note: every functor has a field, `map_const`, and `lawfulFunctor` has the defining characterization. We can only propagate the assumption. -/ theorem id_map {α : Type _} (x : F α) : id <$> x = x := by rw [← abs_repr x] cases' repr x with a f rw [← abs_map] rfl #align qpf.id_map QPF.id_map theorem comp_map {α β γ : Type _} (f : α → β) (g : β → γ) (x : F α) : (g ∘ f) <$> x = g <$> f <$> x := by rw [← abs_repr x] cases' repr x with a f rw [← abs_map, ← abs_map, ← abs_map] rfl #align qpf.comp_map QPF.comp_map theorem lawfulFunctor (h : ∀ α β : Type u, @Functor.mapConst F _ α _ = Functor.map ∘ Function.const β) : LawfulFunctor F := { map_const := @h id_map := @id_map F _ _ comp_map := @comp_map F _ _ } #align qpf.is_lawful_functor QPF.lawfulFunctor /- Lifting predicates and relations -/ section open Functor theorem liftp_iff {α : Type u} (p : α → Prop) (x : F α) : Liftp p x ↔ ∃ a f, x = abs ⟨a, f⟩ ∧ ∀ i, p (f i) := by constructor · rintro ⟨y, hy⟩ cases' h : repr y with a f use a, fun i => (f i).val constructor · rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨a, f, h₀, h₁⟩ use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, h₀]; rfl #align qpf.liftp_iff QPF.liftp_iff theorem liftp_iff' {α : Type u} (p : α → Prop) (x : F α) : Liftp p x ↔ ∃ u : q.P α, abs u = x ∧ ∀ i, p (u.snd i) := by constructor · rintro ⟨y, hy⟩ cases' h : repr y with a f use ⟨a, fun i => (f i).val⟩ dsimp constructor · rw [← hy, ← abs_repr y, h, ← abs_map] rfl intro i apply (f i).property rintro ⟨⟨a, f⟩, h₀, h₁⟩; dsimp at * use abs ⟨a, fun i => ⟨f i, h₁ i⟩⟩ rw [← abs_map, ← h₀]; rfl #align qpf.liftp_iff' QPF.liftp_iff' theorem liftr_iff {α : Type u} (r : α → α → Prop) (x y : F α) : Liftr r x y ↔ ∃ a f₀ f₁, x = abs ⟨a, f₀⟩ ∧ y = abs ⟨a, f₁⟩ ∧ ∀ i, r (f₀ i) (f₁ i) := by constructor · rintro ⟨u, xeq, yeq⟩ cases' h : repr u with a f use a, fun i => (f i).val.fst, fun i => (f i).val.snd constructor · rw [← xeq, ← abs_repr u, h, ← abs_map] rfl constructor · rw [← yeq, ← abs_repr u, h, ← abs_map] rfl intro i exact (f i).property rintro ⟨a, f₀, f₁, xeq, yeq, h⟩ use abs ⟨a, fun i => ⟨(f₀ i, f₁ i), h i⟩⟩ constructor · rw [xeq, ← abs_map] rfl rw [yeq, ← abs_map]; rfl #align qpf.liftr_iff QPF.liftr_iff end /- Think of trees in the `W` type corresponding to `P` as representatives of elements of the least fixed point of `F`, and assign a canonical representative to each equivalence class of trees. -/ /-- does recursion on `q.P.W` using `g : F α → α` rather than `g : P α → α` -/ def recF {α : Type _} (g : F α → α) : q.P.W → α | ⟨a, f⟩ => g (abs ⟨a, fun x => recF g (f x)⟩) set_option linter.uppercaseLean3 false in #align qpf.recF QPF.recF theorem recF_eq {α : Type _} (g : F α → α) (x : q.P.W) : recF g x = g (abs (q.P.map (recF g) x.dest)) := by cases x rfl set_option linter.uppercaseLean3 false in #align qpf.recF_eq QPF.recF_eq theorem recF_eq' {α : Type _} (g : F α → α) (a : q.P.A) (f : q.P.B a → q.P.W) : recF g ⟨a, f⟩ = g (abs (q.P.map (recF g) ⟨a, f⟩)) := rfl set_option linter.uppercaseLean3 false in #align qpf.recF_eq' QPF.recF_eq' /-- two trees are equivalent if their F-abstractions are -/ inductive Wequiv : q.P.W → q.P.W → Prop | ind (a : q.P.A) (f f' : q.P.B a → q.P.W) : (∀ x, Wequiv (f x) (f' x)) → Wequiv ⟨a, f⟩ ⟨a, f'⟩ | abs (a : q.P.A) (f : q.P.B a → q.P.W) (a' : q.P.A) (f' : q.P.B a' → q.P.W) : abs ⟨a, f⟩ = abs ⟨a', f'⟩ → Wequiv ⟨a, f⟩ ⟨a', f'⟩ | trans (u v w : q.P.W) : Wequiv u v → Wequiv v w → Wequiv u w set_option linter.uppercaseLean3 false in #align qpf.Wequiv QPF.Wequiv /-- `recF` is insensitive to the representation -/ theorem recF_eq_of_Wequiv {α : Type u} (u : F α → α) (x y : q.P.W) : Wequiv x y → recF u x = recF u y := by intro h induction h with | ind a f f' _ ih => simp only [recF_eq', PFunctor.map_eq, Function.comp, ih] | abs a f a' f' h => simp only [recF_eq', abs_map, h] | trans x y z _ _ ih₁ ih₂ => exact Eq.trans ih₁ ih₂ set_option linter.uppercaseLean3 false in #align qpf.recF_eq_of_Wequiv QPF.recF_eq_of_Wequiv theorem Wequiv.abs' (x y : q.P.W) (h : QPF.abs x.dest = QPF.abs y.dest) : Wequiv x y := by cases x cases y apply Wequiv.abs apply h set_option linter.uppercaseLean3 false in #align qpf.Wequiv.abs' QPF.Wequiv.abs' theorem Wequiv.refl (x : q.P.W) : Wequiv x x := by cases' x with a f exact Wequiv.abs a f a f rfl set_option linter.uppercaseLean3 false in #align qpf.Wequiv.refl QPF.Wequiv.refl theorem Wequiv.symm (x y : q.P.W) : Wequiv x y → Wequiv y x := by intro h induction h with | ind a f f' _ ih => exact Wequiv.ind _ _ _ ih | abs a f a' f' h => exact Wequiv.abs _ _ _ _ h.symm | trans x y z _ _ ih₁ ih₂ => exact QPF.Wequiv.trans _ _ _ ih₂ ih₁ set_option linter.uppercaseLean3 false in #align qpf.Wequiv.symm QPF.Wequiv.symm /-- maps every element of the W type to a canonical representative -/ def Wrepr : q.P.W → q.P.W := recF (PFunctor.W.mk ∘ repr) set_option linter.uppercaseLean3 false in #align qpf.Wrepr QPF.Wrepr theorem Wrepr_equiv (x : q.P.W) : Wequiv (Wrepr x) x := by induction' x with a f ih apply Wequiv.trans · change Wequiv (Wrepr ⟨a, f⟩) (PFunctor.W.mk (q.P.map Wrepr ⟨a, f⟩)) apply Wequiv.abs' have : Wrepr ⟨a, f⟩ = PFunctor.W.mk (repr (abs (q.P.map Wrepr ⟨a, f⟩))) := rfl rw [this, PFunctor.W.dest_mk, abs_repr] rfl apply Wequiv.ind; exact ih set_option linter.uppercaseLean3 false in #align qpf.Wrepr_equiv QPF.Wrepr_equiv /-- Define the fixed point as the quotient of trees under the equivalence relation `Wequiv`. -/ def Wsetoid : Setoid q.P.W := ⟨Wequiv, @Wequiv.refl _ _ _, @Wequiv.symm _ _ _, @Wequiv.trans _ _ _⟩ set_option linter.uppercaseLean3 false in #align qpf.W_setoid QPF.Wsetoid attribute [local instance] Wsetoid /-- inductive type defined as initial algebra of a Quotient of Polynomial Functor -/ -- Porting note(#5171): this linter isn't ported yet. -- @[nolint has_nonempty_instance] def Fix (F : Type u → Type u) [Functor F] [q : QPF F] := Quotient (Wsetoid : Setoid q.P.W) #align qpf.fix QPF.Fix /-- recursor of a type defined by a qpf -/ def Fix.rec {α : Type _} (g : F α → α) : Fix F → α := Quot.lift (recF g) (recF_eq_of_Wequiv g) #align qpf.fix.rec QPF.Fix.rec /-- access the underlying W-type of a fixpoint data type -/ def fixToW : Fix F → q.P.W := Quotient.lift Wrepr (recF_eq_of_Wequiv fun x => @PFunctor.W.mk q.P (repr x)) set_option linter.uppercaseLean3 false in #align qpf.fix_to_W QPF.fixToW /-- constructor of a type defined by a qpf -/ def Fix.mk (x : F (Fix F)) : Fix F := Quot.mk _ (PFunctor.W.mk (q.P.map fixToW (repr x))) #align qpf.fix.mk QPF.Fix.mk /-- destructor of a type defined by a qpf -/ def Fix.dest : Fix F → F (Fix F) := Fix.rec (Functor.map Fix.mk) #align qpf.fix.dest QPF.Fix.dest theorem Fix.rec_eq {α : Type _} (g : F α → α) (x : F (Fix F)) : Fix.rec g (Fix.mk x) = g (Fix.rec g <$> x) := by have : recF g ∘ fixToW = Fix.rec g := by apply funext apply Quotient.ind intro x apply recF_eq_of_Wequiv rw [fixToW] apply Wrepr_equiv conv => lhs rw [Fix.rec, Fix.mk] dsimp cases' h : repr x with a f rw [PFunctor.map_eq, recF_eq, ← PFunctor.map_eq, PFunctor.W.dest_mk, PFunctor.map_map, abs_map, ← h, abs_repr, this] #align qpf.fix.rec_eq QPF.Fix.rec_eq theorem Fix.ind_aux (a : q.P.A) (f : q.P.B a → q.P.W) : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦⟨a, f⟩⟧ := by have : Fix.mk (abs ⟨a, fun x => ⟦f x⟧⟩) = ⟦Wrepr ⟨a, f⟩⟧ := by apply Quot.sound; apply Wequiv.abs' rw [PFunctor.W.dest_mk, abs_map, abs_repr, ← abs_map, PFunctor.map_eq] simp only [Wrepr, recF_eq, PFunctor.W.dest_mk, abs_repr, Function.comp] rfl rw [this] apply Quot.sound apply Wrepr_equiv #align qpf.fix.ind_aux QPF.Fix.ind_aux theorem Fix.ind_rec {α : Type u} (g₁ g₂ : Fix F → α) (h : ∀ x : F (Fix F), g₁ <$> x = g₂ <$> x → g₁ (Fix.mk x) = g₂ (Fix.mk x)) : ∀ x, g₁ x = g₂ x := by apply Quot.ind intro x induction' x with a f ih change g₁ ⟦⟨a, f⟩⟧ = g₂ ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f]; apply h rw [← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq] congr with x apply ih #align qpf.fix.ind_rec QPF.Fix.ind_rec theorem Fix.rec_unique {α : Type u} (g : F α → α) (h : Fix F → α) (hyp : ∀ x, h (Fix.mk x) = g (h <$> x)) : Fix.rec g = h := by ext x apply Fix.ind_rec intro x hyp' rw [hyp, ← hyp', Fix.rec_eq] #align qpf.fix.rec_unique QPF.Fix.rec_unique theorem Fix.mk_dest (x : Fix F) : Fix.mk (Fix.dest x) = x := by change (Fix.mk ∘ Fix.dest) x = id x apply Fix.ind_rec (mk ∘ dest) id intro x rw [Function.comp_apply, id_eq, Fix.dest, Fix.rec_eq, id_map, comp_map] intro h rw [h] #align qpf.fix.mk_dest QPF.Fix.mk_dest theorem Fix.dest_mk (x : F (Fix F)) : Fix.dest (Fix.mk x) = x := by unfold Fix.dest; rw [Fix.rec_eq, ← Fix.dest, ← comp_map] conv => rhs rw [← id_map x] congr with x apply Fix.mk_dest #align qpf.fix.dest_mk QPF.Fix.dest_mk theorem Fix.ind (p : Fix F → Prop) (h : ∀ x : F (Fix F), Liftp p x → p (Fix.mk x)) : ∀ x, p x := by apply Quot.ind intro x induction' x with a f ih change p ⟦⟨a, f⟩⟧ rw [← Fix.ind_aux a f] apply h rw [liftp_iff] refine ⟨_, _, rfl, ?_⟩ convert ih #align qpf.fix.ind QPF.Fix.ind end QPF /- Construct the final coalgebra to a qpf. -/ namespace QPF variable {F : Type u → Type u} [Functor F] [q : QPF F] open Functor (Liftp Liftr) /-- does recursion on `q.P.M` using `g : α → F α` rather than `g : α → P α` -/ def corecF {α : Type _} (g : α → F α) : α → q.P.M := PFunctor.M.corec fun x => repr (g x) set_option linter.uppercaseLean3 false in #align qpf.corecF QPF.corecF theorem corecF_eq {α : Type _} (g : α → F α) (x : α) : PFunctor.M.dest (corecF g x) = q.P.map (corecF g) (repr (g x)) := by rw [corecF, PFunctor.M.dest_corec] set_option linter.uppercaseLean3 false in #align qpf.corecF_eq QPF.corecF_eq -- Equivalence /-- A pre-congruence on `q.P.M` *viewed as an F-coalgebra*. Not necessarily symmetric. -/ def IsPrecongr (r : q.P.M → q.P.M → Prop) : Prop := ∀ ⦃x y⦄, r x y → abs (q.P.map (Quot.mk r) (PFunctor.M.dest x)) = abs (q.P.map (Quot.mk r) (PFunctor.M.dest y)) #align qpf.is_precongr QPF.IsPrecongr /-- The maximal congruence on `q.P.M`. -/ def Mcongr : q.P.M → q.P.M → Prop := fun x y => ∃ r, IsPrecongr r ∧ r x y set_option linter.uppercaseLean3 false in #align qpf.Mcongr QPF.Mcongr /-- coinductive type defined as the final coalgebra of a qpf -/ def Cofix (F : Type u → Type u) [Functor F] [q : QPF F] := Quot (@Mcongr F _ q) #align qpf.cofix QPF.Cofix instance [Inhabited q.P.A] : Inhabited (Cofix F) := ⟨Quot.mk _ default⟩ /-- corecursor for type defined by `Cofix` -/ def Cofix.corec {α : Type _} (g : α → F α) (x : α) : Cofix F := Quot.mk _ (corecF g x) #align qpf.cofix.corec QPF.Cofix.corec /-- destructor for type defined by `Cofix` -/ def Cofix.dest : Cofix F → F (Cofix F) := Quot.lift (fun x => Quot.mk Mcongr <$> abs (PFunctor.M.dest x)) (by rintro x y ⟨r, pr, rxy⟩ dsimp have : ∀ x y, r x y → Mcongr x y := by intro x y h exact ⟨r, pr, h⟩ rw [← Quot.factor_mk_eq _ _ this] conv => lhs rw [comp_map, ← abs_map, pr rxy, abs_map, ← comp_map]) #align qpf.cofix.dest QPF.Cofix.dest theorem Cofix.dest_corec {α : Type u} (g : α → F α) (x : α) : Cofix.dest (Cofix.corec g x) = Cofix.corec g <$> g x := by conv => lhs rw [Cofix.dest, Cofix.corec]; dsimp rw [corecF_eq, abs_map, abs_repr, ← comp_map]; rfl #align qpf.cofix.dest_corec QPF.Cofix.dest_corec -- Porting note: Needed to add `(motive := _)` to get `Quot.inductionOn` to work private theorem Cofix.bisim_aux (r : Cofix F → Cofix F → Prop) (h' : ∀ x, r x x) (h : ∀ x y, r x y → Quot.mk r <$> Cofix.dest x = Quot.mk r <$> Cofix.dest y) : ∀ x y, r x y → x = y := by intro x apply Quot.inductionOn (motive := _) x clear x intro x y apply Quot.inductionOn (motive := _) y clear y intro y rxy apply Quot.sound let r' x y := r (Quot.mk _ x) (Quot.mk _ y) have : IsPrecongr r' := by intro a b r'ab have h₀ : Quot.mk r <$> Quot.mk Mcongr <$> abs (PFunctor.M.dest a) = Quot.mk r <$> Quot.mk Mcongr <$> abs (PFunctor.M.dest b) := h _ _ r'ab have h₁ : ∀ u v : q.P.M, Mcongr u v → Quot.mk r' u = Quot.mk r' v := by intro u v cuv apply Quot.sound simp only [r'] rw [Quot.sound cuv] apply h' let f : Quot r → Quot r' := Quot.lift (Quot.lift (Quot.mk r') h₁) (by intro c; apply Quot.inductionOn (motive := _) c; clear c intro c d; apply Quot.inductionOn (motive := _) d; clear d intro d rcd; apply Quot.sound; apply rcd) have : f ∘ Quot.mk r ∘ Quot.mk Mcongr = Quot.mk r' := rfl rw [← this, ← PFunctor.map_map _ _ f, ← PFunctor.map_map _ _ (Quot.mk r), abs_map, abs_map, abs_map, h₀] rw [← PFunctor.map_map _ _ f, ← PFunctor.map_map _ _ (Quot.mk r), abs_map, abs_map, abs_map] exact ⟨r', this, rxy⟩ theorem Cofix.bisim_rel (r : Cofix F → Cofix F → Prop) (h : ∀ x y, r x y → Quot.mk r <$> Cofix.dest x = Quot.mk r <$> Cofix.dest y) : ∀ x y, r x y → x = y := by let r' (x y) := x = y ∨ r x y intro x y rxy apply Cofix.bisim_aux r' · intro x left rfl · intro x y r'xy cases' r'xy with r'xy r'xy · rw [r'xy] have : ∀ x y, r x y → r' x y := fun x y h => Or.inr h rw [← Quot.factor_mk_eq _ _ this] dsimp [r'] rw [@comp_map _ _ q _ _ _ (Quot.mk r), @comp_map _ _ q _ _ _ (Quot.mk r)] rw [h _ _ r'xy] right; exact rxy #align qpf.cofix.bisim_rel QPF.Cofix.bisim_rel theorem Cofix.bisim (r : Cofix F → Cofix F → Prop) (h : ∀ x y, r x y → Liftr r (Cofix.dest x) (Cofix.dest y)) : ∀ x y, r x y → x = y := by apply Cofix.bisim_rel intro x y rxy rcases (liftr_iff r _ _).mp (h x y rxy) with ⟨a, f₀, f₁, dxeq, dyeq, h'⟩ rw [dxeq, dyeq, ← abs_map, ← abs_map, PFunctor.map_eq, PFunctor.map_eq] congr 2 with i apply Quot.sound apply h' #align qpf.cofix.bisim QPF.Cofix.bisim theorem Cofix.bisim' {α : Type*} (Q : α → Prop) (u v : α → Cofix F) (h : ∀ x, Q x → ∃ a f f', Cofix.dest (u x) = abs ⟨a, f⟩ ∧ Cofix.dest (v x) = abs ⟨a, f'⟩ ∧ ∀ i, ∃ x', Q x' ∧ f i = u x' ∧ f' i = v x') : ∀ x, Q x → u x = v x := fun x Qx => let R := fun w z : Cofix F => ∃ x', Q x' ∧ w = u x' ∧ z = v x' Cofix.bisim R (fun x y ⟨x', Qx', xeq, yeq⟩ => by rcases h x' Qx' with ⟨a, f, f', ux'eq, vx'eq, h'⟩ rw [liftr_iff] exact ⟨a, f, f', xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, h'⟩) _ _ ⟨x, Qx, rfl, rfl⟩ #align qpf.cofix.bisim' QPF.Cofix.bisim' end QPF /- Composition of qpfs. -/ namespace QPF variable {F₂ : Type u → Type u} [Functor F₂] [q₂ : QPF F₂] variable {F₁ : Type u → Type u} [Functor F₁] [q₁ : QPF F₁] /-- composition of qpfs gives another qpf -/ def comp : QPF (Functor.Comp F₂ F₁) where P := PFunctor.comp q₂.P q₁.P abs {α} := by dsimp [Functor.Comp] intro p exact abs ⟨p.1.1, fun x => abs ⟨p.1.2 x, fun y => p.2 ⟨x, y⟩⟩⟩ repr {α} := by dsimp [Functor.Comp] intro y refine ⟨⟨(repr y).1, fun u => (repr ((repr y).2 u)).1⟩, ?_⟩ dsimp [PFunctor.comp] intro x exact (repr ((repr y).2 x.1)).snd x.2 abs_repr {α} := by dsimp [Functor.Comp] intro x conv => rhs rw [← abs_repr x] cases' repr x with a f dsimp congr with x cases' h' : repr (f x) with b g dsimp; rw [← h', abs_repr] abs_map {α β} f := by dsimp (config := { unfoldPartialApp := true }) [Functor.Comp, PFunctor.comp] intro p cases' p with a g; dsimp cases' a with b h; dsimp symm trans · symm apply abs_map congr rw [PFunctor.map_eq] dsimp [Function.comp_def] congr ext x rw [← abs_map] rfl #align qpf.comp QPF.comp end QPF /- Quotients. We show that if `F` is a qpf and `G` is a suitable quotient of `F`, then `G` is a qpf. -/ namespace QPF variable {F : Type u → Type u} [Functor F] [q : QPF F] variable {G : Type u → Type u} [Functor G] variable {FG_abs : ∀ {α}, F α → G α} variable {FG_repr : ∀ {α}, G α → F α} /-- Given a qpf `F` and a well-behaved surjection `FG_abs` from `F α` to functor `G α`, `G` is a qpf. We can consider `G` a quotient on `F` where elements `x y : F α` are in the same equivalence class if `FG_abs x = FG_abs y`. -/ def quotientQPF (FG_abs_repr : ∀ {α} (x : G α), FG_abs (FG_repr x) = x) (FG_abs_map : ∀ {α β} (f : α → β) (x : F α), FG_abs (f <$> x) = f <$> FG_abs x) : QPF G where P := q.P abs {α} p := FG_abs (abs p) repr {α} x := repr (FG_repr x) abs_repr {α} x := by simp only; rw [abs_repr, FG_abs_repr] abs_map {α β} f x := by simp only; rw [abs_map, FG_abs_map] #align qpf.quotient_qpf QPF.quotientQPF end QPF /- Support. -/ namespace QPF variable {F : Type u → Type u} [Functor F] [q : QPF F] open Functor (Liftp Liftr supp) open Set theorem mem_supp {α : Type u} (x : F α) (u : α) : u ∈ supp x ↔ ∀ a f, abs ⟨a, f⟩ = x → u ∈ f '' univ := by rw [supp]; dsimp; constructor · intro h a f haf have : Liftp (fun u => u ∈ f '' univ) x := by rw [liftp_iff] exact ⟨a, f, haf.symm, fun i => mem_image_of_mem _ (mem_univ _)⟩ exact h this intro h p; rw [liftp_iff] rintro ⟨a, f, xeq, h'⟩ rcases h a f xeq.symm with ⟨i, _, hi⟩ rw [← hi]; apply h' #align qpf.mem_supp QPF.mem_supp theorem supp_eq {α : Type u} (x : F α) : supp x = { u | ∀ a f, abs ⟨a, f⟩ = x → u ∈ f '' univ } := by ext apply mem_supp #align qpf.supp_eq QPF.supp_eq theorem has_good_supp_iff {α : Type u} (x : F α) : (∀ p, Liftp p x ↔ ∀ u ∈ supp x, p u) ↔ ∃ a f, abs ⟨a, f⟩ = x ∧ ∀ a' f', abs ⟨a', f'⟩ = x → f '' univ ⊆ f' '' univ := by constructor · intro h have : Liftp (supp x) x := by rw [h]; intro u; exact id rw [liftp_iff] at this rcases this with ⟨a, f, xeq, h'⟩ refine ⟨a, f, xeq.symm, ?_⟩ intro a' f' h'' rintro u ⟨i, _, hfi⟩ have : u ∈ supp x := by rw [← hfi]; apply h' exact (mem_supp x u).mp this _ _ h'' rintro ⟨a, f, xeq, h⟩ p; rw [liftp_iff]; constructor · rintro ⟨a', f', xeq', h'⟩ u usuppx rcases (mem_supp x u).mp usuppx a' f' xeq'.symm with ⟨i, _, f'ieq⟩ rw [← f'ieq] apply h' intro h' refine ⟨a, f, xeq.symm, ?_⟩; intro i apply h'; rw [mem_supp] intro a' f' xeq' apply h a' f' xeq' apply mem_image_of_mem _ (mem_univ _) #align qpf.has_good_supp_iff QPF.has_good_supp_iff /-- A qpf is said to be uniform if every polynomial functor representing a single value all have the same range. -/ def IsUniform : Prop := ∀ ⦃α : Type u⦄ (a a' : q.P.A) (f : q.P.B a → α) (f' : q.P.B a' → α), abs ⟨a, f⟩ = abs ⟨a', f'⟩ → f '' univ = f' '' univ #align qpf.is_uniform QPF.IsUniform /-- does `abs` preserve `Liftp`? -/ def LiftpPreservation : Prop := ∀ ⦃α⦄ (p : α → Prop) (x : q.P α), Liftp p (abs x) ↔ Liftp p x #align qpf.liftp_preservation QPF.LiftpPreservation /-- does `abs` preserve `supp`? -/ def SuppPreservation : Prop := ∀ ⦃α⦄ (x : q.P α), supp (abs x) = supp x #align qpf.supp_preservation QPF.SuppPreservation theorem supp_eq_of_isUniform (h : q.IsUniform) {α : Type u} (a : q.P.A) (f : q.P.B a → α) : supp (abs ⟨a, f⟩) = f '' univ := by ext u; rw [mem_supp]; constructor · intro h' apply h' _ _ rfl intro h' a' f' e rw [← h _ _ _ _ e.symm]; apply h' #align qpf.supp_eq_of_is_uniform QPF.supp_eq_of_isUniform theorem liftp_iff_of_isUniform (h : q.IsUniform) {α : Type u} (x : F α) (p : α → Prop) : Liftp p x ↔ ∀ u ∈ supp x, p u := by rw [liftp_iff, ← abs_repr x] cases' repr x with a f; constructor · rintro ⟨a', f', abseq, hf⟩ u rw [supp_eq_of_isUniform h, h _ _ _ _ abseq] rintro ⟨i, _, hi⟩ rw [← hi] apply hf intro h' refine ⟨a, f, rfl, fun i => h' _ ?_⟩ rw [supp_eq_of_isUniform h] exact ⟨i, mem_univ i, rfl⟩ #align qpf.liftp_iff_of_is_uniform QPF.liftp_iff_of_isUniform theorem supp_map (h : q.IsUniform) {α β : Type u} (g : α → β) (x : F α) : supp (g <$> x) = g '' supp x := by rw [← abs_repr x]; cases' repr x with a f; rw [← abs_map, PFunctor.map_eq] rw [supp_eq_of_isUniform h, supp_eq_of_isUniform h, image_comp] #align qpf.supp_map QPF.supp_map theorem suppPreservation_iff_uniform : q.SuppPreservation ↔ q.IsUniform := by constructor · intro h α a a' f f' h' rw [← PFunctor.supp_eq, ← PFunctor.supp_eq, ← h, h', h] · rintro h α ⟨a, f⟩ rwa [supp_eq_of_isUniform, PFunctor.supp_eq] #align qpf.supp_preservation_iff_uniform QPF.suppPreservation_iff_uniform theorem suppPreservation_iff_liftpPreservation : q.SuppPreservation ↔ q.LiftpPreservation := by constructor <;> intro h · rintro α p ⟨a, f⟩ have h' := h rw [suppPreservation_iff_uniform] at h' dsimp only [SuppPreservation, supp] at h rw [liftp_iff_of_isUniform h', supp_eq_of_isUniform h', PFunctor.liftp_iff'] simp only [image_univ, mem_range, exists_imp] constructor <;> intros <;> subst_vars <;> solve_by_elim · rintro α ⟨a, f⟩ simp only [LiftpPreservation] at h simp only [supp, h] #align qpf.supp_preservation_iff_liftp_preservation QPF.suppPreservation_iff_liftpPreservation
Mathlib/Data/QPF/Univariate/Basic.lean
721
722
theorem liftpPreservation_iff_uniform : q.LiftpPreservation ↔ q.IsUniform := by
rw [← suppPreservation_iff_liftpPreservation, suppPreservation_iff_uniform]
/- Copyright (c) 2021 Anatole Dedecker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker -/ import Mathlib.Topology.ContinuousOn #align_import topology.algebra.order.left_right from "leanprover-community/mathlib"@"bcfa726826abd57587355b4b5b7e78ad6527b7e4" /-! # Left and right continuity In this file we prove a few lemmas about left and right continuous functions: * `continuousWithinAt_Ioi_iff_Ici`: two definitions of right continuity (with `(a, ∞)` and with `[a, ∞)`) are equivalent; * `continuousWithinAt_Iio_iff_Iic`: two definitions of left continuity (with `(-∞, a)` and with `(-∞, a]`) are equivalent; * `continuousAt_iff_continuous_left_right`, `continuousAt_iff_continuous_left'_right'` : a function is continuous at `a` if and only if it is left and right continuous at `a`. ## Tags left continuous, right continuous -/ open Set Filter Topology section Preorder variable {α : Type*} [TopologicalSpace α] [Preorder α] lemma frequently_lt_nhds (a : α) [NeBot (𝓝[<] a)] : ∃ᶠ x in 𝓝 a, x < a := frequently_iff_neBot.2 ‹_› lemma frequently_gt_nhds (a : α) [NeBot (𝓝[>] a)] : ∃ᶠ x in 𝓝 a, a < x := frequently_iff_neBot.2 ‹_› theorem Filter.Eventually.exists_lt {a : α} [NeBot (𝓝[<] a)] {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∃ b < a, p b := ((frequently_lt_nhds a).and_eventually h).exists #align filter.eventually.exists_lt Filter.Eventually.exists_lt theorem Filter.Eventually.exists_gt {a : α} [NeBot (𝓝[>] a)] {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∃ b > a, p b := ((frequently_gt_nhds a).and_eventually h).exists #align filter.eventually.exists_gt Filter.Eventually.exists_gt theorem nhdsWithin_Ici_neBot {a b : α} (H₂ : a ≤ b) : NeBot (𝓝[Ici a] b) := nhdsWithin_neBot_of_mem H₂ #align nhds_within_Ici_ne_bot nhdsWithin_Ici_neBot instance nhdsWithin_Ici_self_neBot (a : α) : NeBot (𝓝[≥] a) := nhdsWithin_Ici_neBot (le_refl a) #align nhds_within_Ici_self_ne_bot nhdsWithin_Ici_self_neBot theorem nhdsWithin_Iic_neBot {a b : α} (H : a ≤ b) : NeBot (𝓝[Iic b] a) := nhdsWithin_neBot_of_mem H #align nhds_within_Iic_ne_bot nhdsWithin_Iic_neBot instance nhdsWithin_Iic_self_neBot (a : α) : NeBot (𝓝[≤] a) := nhdsWithin_Iic_neBot (le_refl a) #align nhds_within_Iic_self_ne_bot nhdsWithin_Iic_self_neBot theorem nhds_left'_le_nhds_ne (a : α) : 𝓝[<] a ≤ 𝓝[≠] a := nhdsWithin_mono a fun _ => ne_of_lt #align nhds_left'_le_nhds_ne nhds_left'_le_nhds_ne theorem nhds_right'_le_nhds_ne (a : α) : 𝓝[>] a ≤ 𝓝[≠] a := nhdsWithin_mono a fun _ => ne_of_gt #align nhds_right'_le_nhds_ne nhds_right'_le_nhds_ne -- TODO: add instances for `NeBot (𝓝[<] x)` on (indexed) product types lemma IsAntichain.interior_eq_empty [∀ x : α, (𝓝[<] x).NeBot] {s : Set α} (hs : IsAntichain (· ≤ ·) s) : interior s = ∅ := by refine eq_empty_of_forall_not_mem fun x hx ↦ ?_ have : ∀ᶠ y in 𝓝 x, y ∈ s := mem_interior_iff_mem_nhds.1 hx rcases this.exists_lt with ⟨y, hyx, hys⟩ exact hs hys (interior_subset hx) hyx.ne hyx.le #align is_antichain.interior_eq_empty IsAntichain.interior_eq_empty lemma IsAntichain.interior_eq_empty' [∀ x : α, (𝓝[>] x).NeBot] {s : Set α} (hs : IsAntichain (· ≤ ·) s) : interior s = ∅ := have : ∀ x : αᵒᵈ, NeBot (𝓝[<] x) := ‹_› hs.to_dual.interior_eq_empty end Preorder section PartialOrder variable {α β : Type*} [TopologicalSpace α] [PartialOrder α] [TopologicalSpace β] theorem continuousWithinAt_Ioi_iff_Ici {a : α} {f : α → β} : ContinuousWithinAt f (Ioi a) a ↔ ContinuousWithinAt f (Ici a) a := by simp only [← Ici_diff_left, continuousWithinAt_diff_self] #align continuous_within_at_Ioi_iff_Ici continuousWithinAt_Ioi_iff_Ici theorem continuousWithinAt_Iio_iff_Iic {a : α} {f : α → β} : ContinuousWithinAt f (Iio a) a ↔ ContinuousWithinAt f (Iic a) a := @continuousWithinAt_Ioi_iff_Ici αᵒᵈ _ _ _ _ _ f #align continuous_within_at_Iio_iff_Iic continuousWithinAt_Iio_iff_Iic end PartialOrder section TopologicalSpace variable {α β : Type*} [TopologicalSpace α] [LinearOrder α] [TopologicalSpace β] theorem nhds_left_sup_nhds_right (a : α) : 𝓝[≤] a ⊔ 𝓝[≥] a = 𝓝 a := by rw [← nhdsWithin_union, Iic_union_Ici, nhdsWithin_univ] #align nhds_left_sup_nhds_right nhds_left_sup_nhds_right theorem nhds_left'_sup_nhds_right (a : α) : 𝓝[<] a ⊔ 𝓝[≥] a = 𝓝 a := by rw [← nhdsWithin_union, Iio_union_Ici, nhdsWithin_univ] #align nhds_left'_sup_nhds_right nhds_left'_sup_nhds_right
Mathlib/Topology/Order/LeftRight.lean
119
120
theorem nhds_left_sup_nhds_right' (a : α) : 𝓝[≤] a ⊔ 𝓝[>] a = 𝓝 a := by
rw [← nhdsWithin_union, Iic_union_Ioi, nhdsWithin_univ]
/- Copyright (c) 2021 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Johan Commelin, Scott Morrison -/ import Mathlib.Analysis.Normed.Group.SemiNormedGroupCat import Mathlib.Analysis.Normed.Group.Quotient import Mathlib.CategoryTheory.Limits.Shapes.Kernels #align_import analysis.normed.group.SemiNormedGroup.kernels from "leanprover-community/mathlib"@"17ef379e997badd73e5eabb4d38f11919ab3c4b3" /-! # Kernels and cokernels in SemiNormedGroupCat₁ and SemiNormedGroupCat We show that `SemiNormedGroupCat₁` has cokernels (for which of course the `cokernel.π f` maps are norm non-increasing), as well as the easier result that `SemiNormedGroupCat` has cokernels. We also show that `SemiNormedGroupCat` has kernels. So far, I don't see a way to state nicely what we really want: `SemiNormedGroupCat` has cokernels, and `cokernel.π f` is norm non-increasing. The problem is that the limits API doesn't promise you any particular model of the cokernel, and in `SemiNormedGroupCat` one can always take a cokernel and rescale its norm (and hence making `cokernel.π f` arbitrarily large in norm), obtaining another categorical cokernel. -/ open CategoryTheory CategoryTheory.Limits universe u namespace SemiNormedGroupCat₁ noncomputable section /-- Auxiliary definition for `HasCokernels SemiNormedGroupCat₁`. -/ def cokernelCocone {X Y : SemiNormedGroupCat₁.{u}} (f : X ⟶ Y) : Cofork f 0 := Cofork.ofπ (@SemiNormedGroupCat₁.mkHom _ (SemiNormedGroupCat.of (Y ⧸ NormedAddGroupHom.range f.1)) f.1.range.normedMk (NormedAddGroupHom.isQuotientQuotient _).norm_le) (by ext x -- Porting note(https://github.com/leanprover-community/mathlib4/issues/5026): was -- simp only [comp_apply, Limits.zero_comp, NormedAddGroupHom.zero_apply, -- SemiNormedGroupCat₁.mkHom_apply, SemiNormedGroupCat₁.zero_apply, -- ← NormedAddGroupHom.mem_ker, f.1.range.ker_normedMk, f.1.mem_range] -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [Limits.zero_comp, comp_apply, SemiNormedGroupCat₁.mkHom_apply, SemiNormedGroupCat₁.zero_apply, ← NormedAddGroupHom.mem_ker, f.1.range.ker_normedMk, f.1.mem_range] use x rfl) set_option linter.uppercaseLean3 false in #align SemiNormedGroup₁.cokernel_cocone SemiNormedGroupCat₁.cokernelCocone /-- Auxiliary definition for `HasCokernels SemiNormedGroupCat₁`. -/ def cokernelLift {X Y : SemiNormedGroupCat₁.{u}} (f : X ⟶ Y) (s : CokernelCofork f) : (cokernelCocone f).pt ⟶ s.pt := by fconstructor -- The lift itself: · apply NormedAddGroupHom.lift _ s.π.1 rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [zero_apply] -- The lift has norm at most one: exact NormedAddGroupHom.lift_normNoninc _ _ _ s.π.2 set_option linter.uppercaseLean3 false in #align SemiNormedGroup₁.cokernel_lift SemiNormedGroupCat₁.cokernelLift instance : HasCokernels SemiNormedGroupCat₁.{u} where has_colimit f := HasColimit.mk { cocone := cokernelCocone f isColimit := isColimitAux _ (cokernelLift f) (fun s => by ext apply NormedAddGroupHom.lift_mk f.1.range rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [zero_apply]) fun s m w => Subtype.eq (NormedAddGroupHom.lift_unique f.1.range _ _ _ (congr_arg Subtype.val w : _)) } -- Sanity check example : HasCokernels SemiNormedGroupCat₁ := by infer_instance end end SemiNormedGroupCat₁ namespace SemiNormedGroupCat section EqualizersAndKernels -- Porting note: these weren't needed in Lean 3 instance {V W : SemiNormedGroupCat.{u}} : Sub (V ⟶ W) := (inferInstance : Sub (NormedAddGroupHom V W)) noncomputable instance {V W : SemiNormedGroupCat.{u}} : Norm (V ⟶ W) := (inferInstance : Norm (NormedAddGroupHom V W)) noncomputable instance {V W : SemiNormedGroupCat.{u}} : NNNorm (V ⟶ W) := (inferInstance : NNNorm (NormedAddGroupHom V W)) /-- The equalizer cone for a parallel pair of morphisms of seminormed groups. -/ def fork {V W : SemiNormedGroupCat.{u}} (f g : V ⟶ W) : Fork f g := @Fork.ofι _ _ _ _ _ _ (of (f - g : NormedAddGroupHom V W).ker) (NormedAddGroupHom.incl (f - g).ker) <| by -- Porting note: not needed in mathlib3 change NormedAddGroupHom V W at f g ext v have : v.1 ∈ (f - g).ker := v.2 simpa only [NormedAddGroupHom.incl_apply, Pi.zero_apply, coe_comp, NormedAddGroupHom.coe_zero, NormedAddGroupHom.mem_ker, NormedAddGroupHom.coe_sub, Pi.sub_apply, sub_eq_zero] using this set_option linter.uppercaseLean3 false in #align SemiNormedGroup.fork SemiNormedGroupCat.fork instance hasLimit_parallelPair {V W : SemiNormedGroupCat.{u}} (f g : V ⟶ W) : HasLimit (parallelPair f g) where exists_limit := Nonempty.intro { cone := fork f g isLimit := Fork.IsLimit.mk _ (fun c => NormedAddGroupHom.ker.lift (Fork.ι c) _ <| show NormedAddGroupHom.compHom (f - g) c.ι = 0 by rw [AddMonoidHom.map_sub, AddMonoidHom.sub_apply, sub_eq_zero]; exact c.condition) (fun c => NormedAddGroupHom.ker.incl_comp_lift _ _ _) fun c g h => by -- Porting note: the `simp_rw` was was `rw [← h]` but motive is not type correct in mathlib4 ext x; dsimp; simp_rw [← h]; rfl} set_option linter.uppercaseLean3 false in #align SemiNormedGroup.has_limit_parallel_pair SemiNormedGroupCat.hasLimit_parallelPair instance : Limits.HasEqualizers.{u, u + 1} SemiNormedGroupCat := @hasEqualizers_of_hasLimit_parallelPair SemiNormedGroupCat _ fun {_ _ f g} => SemiNormedGroupCat.hasLimit_parallelPair f g end EqualizersAndKernels section Cokernel -- PROJECT: can we reuse the work to construct cokernels in `SemiNormedGroupCat₁` here? -- I don't see a way to do this that is less work than just repeating the relevant parts. /-- Auxiliary definition for `HasCokernels SemiNormedGroupCat`. -/ noncomputable def cokernelCocone {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : Cofork f 0 := @Cofork.ofπ _ _ _ _ _ _ (SemiNormedGroupCat.of (Y ⧸ NormedAddGroupHom.range f)) f.range.normedMk (by ext a simp only [comp_apply, Limits.zero_comp] -- Porting note: `simp` not firing on the below -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [comp_apply, NormedAddGroupHom.zero_apply] -- Porting note: Lean 3 didn't need this instance letI : SeminormedAddCommGroup ((forget SemiNormedGroupCat).obj Y) := (inferInstance : SeminormedAddCommGroup Y) -- Porting note: again simp doesn't seem to be firing in the below line -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [← NormedAddGroupHom.mem_ker, f.range.ker_normedMk, f.mem_range] -- This used to be `simp only [exists_apply_eq_apply]` before leanprover/lean4#2644 convert exists_apply_eq_apply f a) set_option linter.uppercaseLean3 false in #align SemiNormedGroup.cokernel_cocone SemiNormedGroupCat.cokernelCocone /-- Auxiliary definition for `HasCokernels SemiNormedGroupCat`. -/ noncomputable def cokernelLift {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) (s : CokernelCofork f) : (cokernelCocone f).pt ⟶ s.pt := NormedAddGroupHom.lift _ s.π (by rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [zero_apply]) set_option linter.uppercaseLean3 false in #align SemiNormedGroup.cokernel_lift SemiNormedGroupCat.cokernelLift /-- Auxiliary definition for `HasCokernels SemiNormedGroupCat`. -/ noncomputable def isColimitCokernelCocone {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : IsColimit (cokernelCocone f) := isColimitAux _ (cokernelLift f) (fun s => by ext apply NormedAddGroupHom.lift_mk f.range rintro _ ⟨b, rfl⟩ change (f ≫ s.π) b = 0 simp -- This used to be the end of the proof before leanprover/lean4#2644 erw [zero_apply]) fun s m w => NormedAddGroupHom.lift_unique f.range _ _ _ w set_option linter.uppercaseLean3 false in #align SemiNormedGroup.is_colimit_cokernel_cocone SemiNormedGroupCat.isColimitCokernelCocone instance : HasCokernels SemiNormedGroupCat.{u} where has_colimit f := HasColimit.mk { cocone := cokernelCocone f isColimit := isColimitCokernelCocone f } -- Sanity check example : HasCokernels SemiNormedGroupCat := by infer_instance section ExplicitCokernel /-- An explicit choice of cokernel, which has good properties with respect to the norm. -/ noncomputable def explicitCokernel {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : SemiNormedGroupCat.{u} := (cokernelCocone f).pt set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel SemiNormedGroupCat.explicitCokernel /-- Descend to the explicit cokernel. -/ noncomputable def explicitCokernelDesc {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : explicitCokernel f ⟶ Z := (isColimitCokernelCocone f).desc (Cofork.ofπ g (by simp [w])) set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_desc SemiNormedGroupCat.explicitCokernelDesc /-- The projection from `Y` to the explicit cokernel of `X ⟶ Y`. -/ noncomputable def explicitCokernelπ {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : Y ⟶ explicitCokernel f := (cokernelCocone f).ι.app WalkingParallelPair.one set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_π SemiNormedGroupCat.explicitCokernelπ theorem explicitCokernelπ_surjective {X Y : SemiNormedGroupCat.{u}} {f : X ⟶ Y} : Function.Surjective (explicitCokernelπ f) := surjective_quot_mk _ set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_π_surjective SemiNormedGroupCat.explicitCokernelπ_surjective @[simp, reassoc] theorem comp_explicitCokernelπ {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : f ≫ explicitCokernelπ f = 0 := by convert (cokernelCocone f).w WalkingParallelPairHom.left simp set_option linter.uppercaseLean3 false in #align SemiNormedGroup.comp_explicit_cokernel_π SemiNormedGroupCat.comp_explicitCokernelπ -- Porting note: wasn't necessary in Lean 3. Is this a bug? attribute [simp] comp_explicitCokernelπ_assoc @[simp] theorem explicitCokernelπ_apply_dom_eq_zero {X Y : SemiNormedGroupCat.{u}} {f : X ⟶ Y} (x : X) : (explicitCokernelπ f) (f x) = 0 := show (f ≫ explicitCokernelπ f) x = 0 by rw [comp_explicitCokernelπ]; rfl set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_π_apply_dom_eq_zero SemiNormedGroupCat.explicitCokernelπ_apply_dom_eq_zero @[simp, reassoc] theorem explicitCokernelπ_desc {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) : explicitCokernelπ f ≫ explicitCokernelDesc w = g := (isColimitCokernelCocone f).fac _ _ set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_π_desc SemiNormedGroupCat.explicitCokernelπ_desc @[simp] theorem explicitCokernelπ_desc_apply {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {cond : f ≫ g = 0} (x : Y) : explicitCokernelDesc cond (explicitCokernelπ f x) = g x := show (explicitCokernelπ f ≫ explicitCokernelDesc cond) x = g x by rw [explicitCokernelπ_desc] set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_π_desc_apply SemiNormedGroupCat.explicitCokernelπ_desc_apply theorem explicitCokernelDesc_unique {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) (e : explicitCokernel f ⟶ Z) (he : explicitCokernelπ f ≫ e = g) : e = explicitCokernelDesc w := by apply (isColimitCokernelCocone f).uniq (Cofork.ofπ g (by simp [w])) rintro (_ | _) · convert w.symm simp · exact he set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_desc_unique SemiNormedGroupCat.explicitCokernelDesc_unique theorem explicitCokernelDesc_comp_eq_desc {X Y Z W : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} -- Porting note: renamed `cond` to `cond'` to avoid -- failed to rewrite using equation theorems for 'cond' {h : Z ⟶ W} {cond' : f ≫ g = 0} : explicitCokernelDesc cond' ≫ h = explicitCokernelDesc (show f ≫ g ≫ h = 0 by rw [← CategoryTheory.Category.assoc, cond', Limits.zero_comp]) := by refine explicitCokernelDesc_unique _ _ ?_ rw [← CategoryTheory.Category.assoc, explicitCokernelπ_desc] set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_desc_comp_eq_desc SemiNormedGroupCat.explicitCokernelDesc_comp_eq_desc @[simp] theorem explicitCokernelDesc_zero {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} : explicitCokernelDesc (show f ≫ (0 : Y ⟶ Z) = 0 from CategoryTheory.Limits.comp_zero) = 0 := Eq.symm <| explicitCokernelDesc_unique _ _ CategoryTheory.Limits.comp_zero set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_desc_zero SemiNormedGroupCat.explicitCokernelDesc_zero @[ext] theorem explicitCokernel_hom_ext {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} (e₁ e₂ : explicitCokernel f ⟶ Z) (h : explicitCokernelπ f ≫ e₁ = explicitCokernelπ f ≫ e₂) : e₁ = e₂ := by let g : Y ⟶ Z := explicitCokernelπ f ≫ e₂ have w : f ≫ g = 0 := by simp [g] have : e₂ = explicitCokernelDesc w := by apply explicitCokernelDesc_unique; rfl rw [this] apply explicitCokernelDesc_unique exact h set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_hom_ext SemiNormedGroupCat.explicitCokernel_hom_ext instance explicitCokernelπ.epi {X Y : SemiNormedGroupCat.{u}} {f : X ⟶ Y} : Epi (explicitCokernelπ f) := by constructor intro Z g h H ext x -- Porting note: no longer needed -- obtain ⟨x, hx⟩ := explicitCokernelπ_surjective (explicitCokernelπ f x) -- change (explicitCokernelπ f ≫ g) _ = _ rw [H] set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_π.epi SemiNormedGroupCat.explicitCokernelπ.epi theorem isQuotient_explicitCokernelπ {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : NormedAddGroupHom.IsQuotient (explicitCokernelπ f) := NormedAddGroupHom.isQuotientQuotient _ set_option linter.uppercaseLean3 false in #align SemiNormedGroup.is_quotient_explicit_cokernel_π SemiNormedGroupCat.isQuotient_explicitCokernelπ theorem normNoninc_explicitCokernelπ {X Y : SemiNormedGroupCat.{u}} (f : X ⟶ Y) : (explicitCokernelπ f).NormNoninc := (isQuotient_explicitCokernelπ f).norm_le set_option linter.uppercaseLean3 false in #align SemiNormedGroup.norm_noninc_explicit_cokernel_π SemiNormedGroupCat.normNoninc_explicitCokernelπ open scoped NNReal theorem explicitCokernelDesc_norm_le_of_norm_le {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} (w : f ≫ g = 0) (c : ℝ≥0) (h : ‖g‖ ≤ c) : ‖explicitCokernelDesc w‖ ≤ c := NormedAddGroupHom.lift_norm_le _ _ _ h set_option linter.uppercaseLean3 false in #align SemiNormedGroup.explicit_cokernel_desc_norm_le_of_norm_le SemiNormedGroupCat.explicitCokernelDesc_norm_le_of_norm_le
Mathlib/Analysis/Normed/Group/SemiNormedGroupCat/Kernels.lean
348
354
theorem explicitCokernelDesc_normNoninc {X Y Z : SemiNormedGroupCat.{u}} {f : X ⟶ Y} {g : Y ⟶ Z} {cond : f ≫ g = 0} (hg : g.NormNoninc) : (explicitCokernelDesc cond).NormNoninc := by
refine NormedAddGroupHom.NormNoninc.normNoninc_iff_norm_le_one.2 ?_ rw [← NNReal.coe_one] exact explicitCokernelDesc_norm_le_of_norm_le cond 1 (NormedAddGroupHom.NormNoninc.normNoninc_iff_norm_le_one.1 hg)
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Scott Morrison, Mario Carneiro, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.Limits.Products #align_import topology.category.Top.limits.pullbacks from "leanprover-community/mathlib"@"178a32653e369dce2da68dc6b2694e385d484ef1" /-! # Pullbacks and pushouts in the category of topological spaces -/ -- Porting note: every ML3 decl has an uppercase letter set_option linter.uppercaseLean3 false open TopologicalSpace open CategoryTheory open CategoryTheory.Limits universe v u w noncomputable section namespace TopCat variable {J : Type v} [SmallCategory J] section Pullback variable {X Y Z : TopCat.{u}} /-- The first projection from the pullback. -/ abbrev pullbackFst (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ X := ⟨Prod.fst ∘ Subtype.val, by apply Continuous.comp <;> set_option tactic.skipAssignedInstances false in continuity⟩ #align Top.pullback_fst TopCat.pullbackFst lemma pullbackFst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackFst f g x = x.1.1 := rfl /-- The second projection from the pullback. -/ abbrev pullbackSnd (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ Y := ⟨Prod.snd ∘ Subtype.val, by apply Continuous.comp <;> set_option tactic.skipAssignedInstances false in continuity⟩ #align Top.pullback_snd TopCat.pullbackSnd lemma pullbackSnd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackSnd f g x = x.1.2 := rfl /-- The explicit pullback cone of `X, Y` given by `{ p : X × Y // f p.1 = g p.2 }`. -/ def pullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) : PullbackCone f g := PullbackCone.mk (pullbackFst f g) (pullbackSnd f g) (by dsimp [pullbackFst, pullbackSnd, Function.comp_def] ext ⟨x, h⟩ -- Next 2 lines were -- `rw [comp_apply, ContinuousMap.coe_mk, comp_apply, ContinuousMap.coe_mk]` -- `exact h` before leanprover/lean4#2644 rw [comp_apply, comp_apply] congr!) #align Top.pullback_cone TopCat.pullbackCone /-- The constructed cone is a limit. -/ def pullbackConeIsLimit (f : X ⟶ Z) (g : Y ⟶ Z) : IsLimit (pullbackCone f g) := PullbackCone.isLimitAux' _ (by intro S constructor; swap · exact { toFun := fun x => ⟨⟨S.fst x, S.snd x⟩, by simpa using ConcreteCategory.congr_hom S.condition x⟩ continuous_toFun := by apply Continuous.subtype_mk <| Continuous.prod_mk ?_ ?_ · exact (PullbackCone.fst S)|>.continuous_toFun · exact (PullbackCone.snd S)|>.continuous_toFun } refine ⟨?_, ?_, ?_⟩ · delta pullbackCone ext a -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [comp_apply, ContinuousMap.coe_mk] · delta pullbackCone ext a -- This used to be `rw`, but we need `erw` after leanprover/lean4#2644 erw [comp_apply, ContinuousMap.coe_mk] · intro m h₁ h₂ -- Porting note: used to be ext x apply ContinuousMap.ext; intro x apply Subtype.ext apply Prod.ext · simpa using ConcreteCategory.congr_hom h₁ x · simpa using ConcreteCategory.congr_hom h₂ x) #align Top.pullback_cone_is_limit TopCat.pullbackConeIsLimit /-- The pullback of two maps can be identified as a subspace of `X × Y`. -/ def pullbackIsoProdSubtype (f : X ⟶ Z) (g : Y ⟶ Z) : pullback f g ≅ TopCat.of { p : X × Y // f p.1 = g p.2 } := (limit.isLimit _).conePointUniqueUpToIso (pullbackConeIsLimit f g) #align Top.pullback_iso_prod_subtype TopCat.pullbackIsoProdSubtype @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.fst = pullbackFst f g := by simp [pullbackCone, pullbackIsoProdSubtype] #align Top.pullback_iso_prod_subtype_inv_fst TopCat.pullbackIsoProdSubtype_inv_fst theorem pullbackIsoProdSubtype_inv_fst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : (pullback.fst : pullback f g ⟶ _) ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).fst := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_fst f g) x #align Top.pullback_iso_prod_subtype_inv_fst_apply TopCat.pullbackIsoProdSubtype_inv_fst_apply @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.snd = pullbackSnd f g := by simp [pullbackCone, pullbackIsoProdSubtype] #align Top.pullback_iso_prod_subtype_inv_snd TopCat.pullbackIsoProdSubtype_inv_snd theorem pullbackIsoProdSubtype_inv_snd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : (pullback.snd : pullback f g ⟶ _) ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).snd := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_snd f g) x #align Top.pullback_iso_prod_subtype_inv_snd_apply TopCat.pullbackIsoProdSubtype_inv_snd_apply theorem pullbackIsoProdSubtype_hom_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackFst f g = pullback.fst := by rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_fst] #align Top.pullback_iso_prod_subtype_hom_fst TopCat.pullbackIsoProdSubtype_hom_fst theorem pullbackIsoProdSubtype_hom_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackSnd f g = pullback.snd := by rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_snd] #align Top.pullback_iso_prod_subtype_hom_snd TopCat.pullbackIsoProdSubtype_hom_snd -- Porting note: why do I need to tell Lean to coerce pullback to a type theorem pullbackIsoProdSubtype_hom_apply {f : X ⟶ Z} {g : Y ⟶ Z} (x : ConcreteCategory.forget.obj (pullback f g)) : (pullbackIsoProdSubtype f g).hom x = ⟨⟨(pullback.fst : pullback f g ⟶ _) x, (pullback.snd : pullback f g ⟶ _) x⟩, by simpa using ConcreteCategory.congr_hom pullback.condition x⟩ := by apply Subtype.ext; apply Prod.ext exacts [ConcreteCategory.congr_hom (pullbackIsoProdSubtype_hom_fst f g) x, ConcreteCategory.congr_hom (pullbackIsoProdSubtype_hom_snd f g) x] #align Top.pullback_iso_prod_subtype_hom_apply TopCat.pullbackIsoProdSubtype_hom_apply theorem pullback_topology {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : (pullback f g).str = induced (pullback.fst : pullback f g ⟶ _) X.str ⊓ induced (pullback.snd : pullback f g ⟶ _) Y.str := by let homeo := homeoOfIso (pullbackIsoProdSubtype f g) refine homeo.inducing.induced.trans ?_ change induced homeo (induced _ ( (induced Prod.fst X.str) ⊓ (induced Prod.snd Y.str))) = _ simp only [induced_compose, induced_inf] congr #align Top.pullback_topology TopCat.pullback_topology theorem range_pullback_to_prod {X Y Z : TopCat} (f : X ⟶ Z) (g : Y ⟶ Z) : Set.range (prod.lift pullback.fst pullback.snd : pullback f g ⟶ X ⨯ Y) = { x | (Limits.prod.fst ≫ f) x = (Limits.prod.snd ≫ g) x } := by ext x constructor · rintro ⟨y, rfl⟩ change (_ ≫ _ ≫ f) _ = (_ ≫ _ ≫ g) _ -- new `change` after #13170 simp [pullback.condition] · rintro (h : f (_, _).1 = g (_, _).2) use (pullbackIsoProdSubtype f g).inv ⟨⟨_, _⟩, h⟩ change (forget TopCat).map _ _ = _ -- new `change` after #13170 apply Concrete.limit_ext rintro ⟨⟨⟩⟩ <;> erw [← comp_apply, ← comp_apply, limit.lift_π] <;> -- now `erw` after #13170 -- This used to be `simp` before leanprover/lean4#2644 aesop_cat #align Top.range_pullback_to_prod TopCat.range_pullback_to_prod /-- The pullback along an embedding is (isomorphic to) the preimage. -/ noncomputable def pullbackHomeoPreimage {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] (f : X → Z) (hf : Continuous f) (g : Y → Z) (hg : Embedding g) : { p : X × Y // f p.1 = g p.2 } ≃ₜ f ⁻¹' Set.range g where toFun := fun x ↦ ⟨x.1.1, _, x.2.symm⟩ invFun := fun x ↦ ⟨⟨x.1, Exists.choose x.2⟩, (Exists.choose_spec x.2).symm⟩ left_inv := by intro x ext <;> dsimp apply hg.inj convert x.prop exact Exists.choose_spec (p := fun y ↦ g y = f (↑x : X × Y).1) _ right_inv := fun x ↦ rfl continuous_toFun := by apply Continuous.subtype_mk exact continuous_fst.comp continuous_subtype_val continuous_invFun := by apply Continuous.subtype_mk refine continuous_prod_mk.mpr ⟨continuous_subtype_val, hg.toInducing.continuous_iff.mpr ?_⟩ convert hf.comp continuous_subtype_val ext x exact Exists.choose_spec x.2 theorem inducing_pullback_to_prod {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : Inducing <| ⇑(prod.lift pullback.fst pullback.snd : pullback f g ⟶ X ⨯ Y) := ⟨by simp [topologicalSpace_coe, prod_topology, pullback_topology, induced_compose, ← coe_comp]⟩ #align Top.inducing_pullback_to_prod TopCat.inducing_pullback_to_prod theorem embedding_pullback_to_prod {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : Embedding <| ⇑(prod.lift pullback.fst pullback.snd : pullback f g ⟶ X ⨯ Y) := ⟨inducing_pullback_to_prod f g, (TopCat.mono_iff_injective _).mp inferInstance⟩ #align Top.embedding_pullback_to_prod TopCat.embedding_pullback_to_prod /-- If the map `S ⟶ T` is mono, then there is a description of the image of `W ×ₛ X ⟶ Y ×ₜ Z`. -/ theorem range_pullback_map {W X Y Z S T : TopCat} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) [H₃ : Mono i₃] (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : Set.range (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) = (pullback.fst : pullback g₁ g₂ ⟶ _) ⁻¹' Set.range i₁ ∩ (pullback.snd : pullback g₁ g₂ ⟶ _) ⁻¹' Set.range i₂ := by ext constructor · rintro ⟨y, rfl⟩ simp only [Set.mem_inter_iff, Set.mem_preimage, Set.mem_range] erw [← comp_apply, ← comp_apply] -- now `erw` after #13170 simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, comp_apply] exact ⟨exists_apply_eq_apply _ _, exists_apply_eq_apply _ _⟩ rintro ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩⟩ have : f₁ x₁ = f₂ x₂ := by apply (TopCat.mono_iff_injective _).mp H₃ erw [← comp_apply, eq₁, ← comp_apply, eq₂, -- now `erw` after #13170 comp_apply, comp_apply, hx₁, hx₂, ← comp_apply, pullback.condition] rfl -- `rfl` was not needed before #13170 use (pullbackIsoProdSubtype f₁ f₂).inv ⟨⟨x₁, x₂⟩, this⟩ change (forget TopCat).map _ _ = _ apply Concrete.limit_ext rintro (_ | _ | _) <;> erw [← comp_apply, ← comp_apply] -- now `erw` after #13170 simp only [Category.assoc, limit.lift_π, PullbackCone.mk_π_app_one] · simp only [cospan_one, pullbackIsoProdSubtype_inv_fst_assoc, comp_apply] erw [pullbackFst_apply, hx₁] rw [← limit.w _ WalkingCospan.Hom.inl, cospan_map_inl, comp_apply (g := g₁)] rfl -- `rfl` was not needed before #13170 · simp only [cospan_left, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, pullbackIsoProdSubtype_inv_fst_assoc, comp_apply] erw [hx₁] -- now `erw` after #13170 rfl -- `rfl` was not needed before #13170 · simp only [cospan_right, limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app, pullbackIsoProdSubtype_inv_snd_assoc, comp_apply] erw [hx₂] -- now `erw` after #13170 rfl -- `rfl` was not needed before #13170 #align Top.range_pullback_map TopCat.range_pullback_map theorem pullback_fst_range {X Y S : TopCat} (f : X ⟶ S) (g : Y ⟶ S) : Set.range (pullback.fst : pullback f g ⟶ _) = { x : X | ∃ y : Y, f x = g y } := by ext x constructor · rintro ⟨(y : (forget TopCat).obj _), rfl⟩ use (pullback.snd : pullback f g ⟶ _) y exact ConcreteCategory.congr_hom pullback.condition y · rintro ⟨y, eq⟩ use (TopCat.pullbackIsoProdSubtype f g).inv ⟨⟨x, y⟩, eq⟩ rw [pullbackIsoProdSubtype_inv_fst_apply] #align Top.pullback_fst_range TopCat.pullback_fst_range theorem pullback_snd_range {X Y S : TopCat} (f : X ⟶ S) (g : Y ⟶ S) : Set.range (pullback.snd : pullback f g ⟶ _) = { y : Y | ∃ x : X, f x = g y } := by ext y constructor · rintro ⟨(x : (forget TopCat).obj _), rfl⟩ use (pullback.fst : pullback f g ⟶ _) x exact ConcreteCategory.congr_hom pullback.condition x · rintro ⟨x, eq⟩ use (TopCat.pullbackIsoProdSubtype f g).inv ⟨⟨x, y⟩, eq⟩ rw [pullbackIsoProdSubtype_inv_snd_apply] #align Top.pullback_snd_range TopCat.pullback_snd_range /-- If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are embeddings, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an embedding. W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z -/ theorem pullback_map_embedding_of_embeddings {W X Y Z S T : TopCat.{u}} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z} (H₁ : Embedding i₁) (H₂ : Embedding i₂) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : Embedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine embedding_of_embedding_compose (ContinuousMap.continuous_toFun _) (show Continuous (prod.lift pullback.fst pullback.snd : pullback g₁ g₂ ⟶ Y ⨯ Z) from ContinuousMap.continuous_toFun _) ?_ suffices Embedding (prod.lift pullback.fst pullback.snd ≫ Limits.prod.map i₁ i₂ : pullback f₁ f₂ ⟶ _) by simpa [← coe_comp] using this rw [coe_comp] exact Embedding.comp (embedding_prod_map H₁ H₂) (embedding_pullback_to_prod _ _) #align Top.pullback_map_embedding_of_embeddings TopCat.pullback_map_embedding_of_embeddings /-- If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are open embeddings, and `S ⟶ T` is mono, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an open embedding. W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z -/
Mathlib/Topology/Category/TopCat/Limits/Pullbacks.lean
308
320
theorem pullback_map_openEmbedding_of_open_embeddings {W X Y Z S T : TopCat.{u}} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z} (H₁ : OpenEmbedding i₁) (H₂ : OpenEmbedding i₂) (i₃ : S ⟶ T) [H₃ : Mono i₃] (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : OpenEmbedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by
constructor · apply pullback_map_embedding_of_embeddings f₁ f₂ g₁ g₂ H₁.toEmbedding H₂.toEmbedding i₃ eq₁ eq₂ · rw [range_pullback_map] apply IsOpen.inter <;> apply Continuous.isOpen_preimage · apply ContinuousMap.continuous_toFun · exact H₁.isOpen_range · apply ContinuousMap.continuous_toFun · exact H₂.isOpen_range
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Equiv.piFinSucc 2 G).trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, Function.funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, apply_eq_self, sub_self, LinearMap.zero_apply, Pi.zero_apply] /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 0 1 := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.coe_fin_one, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 1 2 := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ (inhomogeneousCochains A).d 2 3 := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, LinearMap.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by show ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A) = _ have h1 : _ ≫ ModuleCat.ofHom (dOne A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 : _ ≫ ModuleCat.ofHom (dTwo A) = _ ≫ _ := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero] end Differentials section Cocycles /-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A) /-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G × G, A) → Fun(G × G × G, A)` sending `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A) variable {A} theorem mem_oneCocycles_def (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 := LinearMap.mem_ker.trans <| by rw [Function.funext_iff] simp only [dOne_apply, Pi.zero_apply, Prod.forall] theorem mem_oneCocycles_iff (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm] @[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f.1 1 = 0 := by have := (mem_oneCocycles_def f.1).1 f.2 1 1 simpa only [map_one, LinearMap.one_apply, mul_one, sub_self, zero_add] using this @[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) : A.ρ g (f.1 g⁻¹) = - f.1 g := by rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_self g, (mem_oneCocycles_iff f.1).1 f.2 g g⁻¹] theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) : f.1 (g * h) = f.1 g + f.1 h := by rw [(mem_oneCocycles_iff f.1).1 f.2, apply_eq_self A.ρ g (f.1 h), add_comm] theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) : f ∘ Additive.ofMul ∈ oneCocycles A := (mem_oneCocycles_iff _).2 fun g h => by simp only [Function.comp_apply, ofMul_mul, map_add, oneCocycles_map_mul_of_isTrivial, apply_eq_self A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))] variable (A) /-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the group homs `G → A`. -/ @[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] : oneCocycles A ≃ₗ[k] Additive G →+ A where toFun f := { toFun := f.1 ∘ Additive.toMul map_zero' := oneCocycles_map_one f map_add' := oneCocycles_map_mul_of_isTrivial f } map_add' x y := rfl map_smul' r x := rfl invFun f := { val := f property := mem_oneCocycles_of_addMonoidHom f } left_inv f := by ext; rfl right_inv f := by ext; rfl variable {A} theorem mem_twoCocycles_def (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 := LinearMap.mem_ker.trans <| by rw [Function.funext_iff] simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall] theorem mem_twoCocycles_iff (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, f (g * h, j) + f (g, h) = A.ρ g (f (h, j)) + f (g, h * j) := by simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm, add_comm (f (_ * _, _))] theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) : f.1 (1, g) = f.1 (1, 1) := by have := ((mem_twoCocycles_iff f.1).1 f.2 1 1 g).symm simpa only [map_one, LinearMap.one_apply, one_mul, add_right_inj, this] theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) : f.1 (g, 1) = A.ρ g (f.1 (1, 1)) := by have := (mem_twoCocycles_iff f.1).1 f.2 g 1 1 simpa only [mul_one, add_left_inj, this] lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) : A.ρ g (f.1 (g⁻¹, g)) - f.1 (g, g⁻¹) = f.1 (1, 1) - f.1 (g, 1) := by have := (mem_twoCocycles_iff f.1).1 f.2 g g⁻¹ g simp only [mul_right_inv, mul_left_inv, twoCocycles_map_one_fst _ g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm end Cocycles section Coboundaries /-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map `A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/ def oneCoboundaries : Submodule k (oneCocycles A) := LinearMap.range ((dZero A).codRestrict (oneCocycles A) fun c => LinearMap.ext_iff.1 (dOne_comp_dZero A) c) /-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def twoCoboundaries : Submodule k (twoCocycles A) := LinearMap.range ((dOne A).codRestrict (twoCocycles A) fun c => LinearMap.ext_iff.1 (dTwo_comp_dOne.{u} A) c) variable {A} /-- Makes a 1-coboundary out of `f ∈ Im(d⁰)`. -/ def oneCoboundariesOfMemRange {f : G → A} (h : f ∈ LinearMap.range (dZero A)) : oneCoboundaries A := ⟨⟨f, LinearMap.range_le_ker_iff.2 (dOne_comp_dZero A) h⟩, by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩⟩ theorem oneCoboundaries_of_mem_range_apply {f : G → A} (h : f ∈ LinearMap.range (dZero A)) : (oneCoboundariesOfMemRange h).1.1 = f := rfl /-- Makes a 1-coboundary out of `f : G → A` and `x` such that `ρ(g)(x) - x = f(g)` for all `g : G`. -/ def oneCoboundariesOfEq {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) : oneCoboundaries A := oneCoboundariesOfMemRange ⟨x, by ext g; exact hf g⟩ theorem oneCoboundariesOfEq_apply {f : G → A} {x : A} (hf : ∀ g, A.ρ g x - x = f g) : (oneCoboundariesOfEq hf).1.1 = f := rfl theorem mem_range_of_mem_oneCoboundaries {f : oneCocycles A} (h : f ∈ oneCoboundaries A) : f.1 ∈ LinearMap.range (dZero A) := by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩ theorem oneCoboundaries_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] : oneCoboundaries A = ⊥ := by simp_rw [oneCoboundaries, dZero_eq_zero] exact LinearMap.range_eq_bot.2 rfl /-- Makes a 2-coboundary out of `f ∈ Im(d¹)`. -/ def twoCoboundariesOfMemRange {f : G × G → A} (h : f ∈ LinearMap.range (dOne A)) : twoCoboundaries A := ⟨⟨f, LinearMap.range_le_ker_iff.2 (dTwo_comp_dOne A) h⟩, by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩⟩ theorem twoCoboundariesOfMemRange_apply {f : G × G → A} (h : f ∈ LinearMap.range (dOne A)) : (twoCoboundariesOfMemRange h).1.1 = f := rfl /-- Makes a 2-coboundary out of `f : G × G → A` and `x : G → A` such that `ρ(g)(x(h)) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/ def twoCoboundariesOfEq {f : G × G → A} {x : G → A} (hf : ∀ g h, A.ρ g (x h) - x (g * h) + x g = f (g, h)) : twoCoboundaries A := twoCoboundariesOfMemRange ⟨x, by ext g; exact hf g.1 g.2⟩ theorem twoCoboundariesOfEq_apply {f : G × G → A} {x : G → A} (hf : ∀ g h, A.ρ g (x h) - x (g * h) + x g = f (g, h)) : (twoCoboundariesOfEq hf).1.1 = f := rfl theorem mem_range_of_mem_twoCoboundaries {f : twoCocycles A} (h : f ∈ twoCoboundaries A) : (twoCocycles A).subtype f ∈ LinearMap.range (dOne A) := by rcases h with ⟨x, rfl⟩; exact ⟨x, rfl⟩ end Coboundaries section IsCocycle section variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A] /-- A function `f : G → A` satisfies the 1-cocycle condition if `f(gh) = g • f(h) + f(g)` for all `g, h : G`. -/ def IsOneCocycle (f : G → A) : Prop := ∀ g h : G, f (g * h) = g • f h + f g /-- A function `f : G × G → A` satisfies the 2-cocycle condition if `f(gh, j) + f(g, h) = g • f(h, j) + f(g, hj)` for all `g, h : G`. -/ def IsTwoCocycle (f : G × G → A) : Prop := ∀ g h j : G, f (g * h, j) + f (g, h) = g • (f (h, j)) + f (g, h * j) end section variable {G A : Type*} [Monoid G] [AddCommGroup A] [MulAction G A] theorem map_one_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) : f 1 = 0 := by simpa only [mul_one, one_smul, self_eq_add_right] using hf 1 1 theorem map_one_fst_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : f (1, g) = f (1, 1) := by simpa only [one_smul, one_mul, mul_one, add_right_inj] using (hf 1 1 g).symm theorem map_one_snd_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : f (g, 1) = g • f (1, 1) := by simpa only [mul_one, add_left_inj] using hf g 1 1 end section variable {G A : Type*} [Group G] [AddCommGroup A] [MulAction G A] @[simp] theorem map_inv_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) (g : G) : g • f g⁻¹ = - f g := by rw [← add_eq_zero_iff_eq_neg, ← map_one_of_isOneCocycle hf, ← mul_inv_self g, hf g g⁻¹] theorem smul_map_inv_sub_map_inv_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : g • f (g⁻¹, g) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by have := hf g g⁻¹ g simp only [mul_right_inv, mul_left_inv, map_one_fst_of_isTwoCocycle hf g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm end end IsCocycle section IsCoboundary variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A] /-- A function `f : G → A` satisfies the 1-coboundary condition if there's `x : A` such that `g • x - x = f(g)` for all `g : G`. -/ def IsOneCoboundary (f : G → A) : Prop := ∃ x : A, ∀ g : G, g • x - x = f g /-- A function `f : G × G → A` satisfies the 2-coboundary condition if there's `x : G → A` such that `g • x(h) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/ def IsTwoCoboundary (f : G × G → A) : Prop := ∃ x : G → A, ∀ g h : G, g • x h - x (g * h) + x g = f (g, h) end IsCoboundary section ofDistribMulAction variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A] [DistribMulAction G A] [SMulCommClass G k A] /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G → A` satisfying the 1-cocycle condition, produces a 1-cocycle for the representation on `A` induced by the `DistribMulAction`. -/ def oneCocyclesOfIsOneCocycle {f : G → A} (hf : IsOneCocycle f) : oneCocycles (Rep.ofDistribMulAction k G A) := ⟨f, (mem_oneCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩ theorem isOneCocycle_of_oneCocycles (f : oneCocycles (Rep.ofDistribMulAction k G A)) : IsOneCocycle (A := A) f.1 := (mem_oneCocycles_iff f.1).1 f.2 /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G → A` satisfying the 1-coboundary condition, produces a 1-coboundary for the representation on `A` induced by the `DistribMulAction`. -/ def oneCoboundariesOfIsOneCoboundary {f : G → A} (hf : IsOneCoboundary f) : oneCoboundaries (Rep.ofDistribMulAction k G A) := oneCoboundariesOfMemRange (by rcases hf with ⟨x, hx⟩; exact ⟨x, by ext g; exact hx g⟩) theorem isOneCoboundary_of_oneCoboundaries (f : oneCoboundaries (Rep.ofDistribMulAction k G A)) : IsOneCoboundary (A := A) f.1.1 := by rcases mem_range_of_mem_oneCoboundaries f.2 with ⟨x, hx⟩ exact ⟨x, by rw [← hx]; intro g; rfl⟩ /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G × G → A` satisfying the 2-cocycle condition, produces a 2-cocycle for the representation on `A` induced by the `DistribMulAction`. -/ def twoCocyclesOfIsTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) : twoCocycles (Rep.ofDistribMulAction k G A) := ⟨f, (mem_twoCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩ theorem isTwoCocycle_of_twoCocycles (f : twoCocycles (Rep.ofDistribMulAction k G A)) : IsTwoCocycle (A := A) f.1 := (mem_twoCocycles_iff f.1).1 f.2 /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G × G → A` satisfying the 2-coboundary condition, produces a 2-coboundary for the representation on `A` induced by the `DistribMulAction`. -/ def twoCoboundariesOfIsTwoCoboundary {f : G × G → A} (hf : IsTwoCoboundary f) : twoCoboundaries (Rep.ofDistribMulAction k G A) := twoCoboundariesOfMemRange (by rcases hf with ⟨x, hx⟩; exact ⟨x, by ext g; exact hx g.1 g.2⟩) theorem isTwoCoboundary_of_twoCoboundaries (f : twoCoboundaries (Rep.ofDistribMulAction k G A)) : IsTwoCoboundary (A := A) f.1.1 := by rcases mem_range_of_mem_twoCoboundaries f.2 with ⟨x, hx⟩ exact ⟨x, fun g h => Function.funext_iff.1 hx (g, h)⟩ end ofDistribMulAction /-! The next few sections, until the section `Cohomology`, are a multiplicative copy of the previous few sections beginning with `IsCocycle`. Unfortunately `@[to_additive]` doesn't work with scalar actions. -/ section IsMulCocycle section variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M] /-- A function `f : G → M` satisfies the multiplicative 1-cocycle condition if `f(gh) = g • f(h) * f(g)` for all `g, h : G`. -/ def IsMulOneCocycle (f : G → M) : Prop := ∀ g h : G, f (g * h) = g • f h * f g /-- A function `f : G × G → M` satisfies the multiplicative 2-cocycle condition if `f(gh, j) * f(g, h) = g • f(h, j) * f(g, hj)` for all `g, h : G`. -/ def IsMulTwoCocycle (f : G × G → M) : Prop := ∀ g h j : G, f (g * h, j) * f (g, h) = g • (f (h, j)) * f (g, h * j) end section variable {G M : Type*} [Monoid G] [CommGroup M] [MulAction G M]
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
524
526
theorem map_one_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) : f 1 = 1 := by
simpa only [mul_one, one_smul, self_eq_mul_right] using hf 1 1
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Floris van Doorn, Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Ordinal import Mathlib.SetTheory.Ordinal.FixedPoint #align_import set_theory.cardinal.cofinality from "leanprover-community/mathlib"@"7c2ce0c2da15516b4e65d0c9e254bb6dc93abd1f" /-! # Cofinality This file contains the definition of cofinality of an ordinal number and regular cardinals ## Main Definitions * `Ordinal.cof o` is the cofinality of the ordinal `o`. If `o` is the order type of the relation `<` on `α`, then `o.cof` is the smallest cardinality of a subset `s` of α that is *cofinal* in `α`, i.e. `∀ x : α, ∃ y ∈ s, ¬ y < x`. * `Cardinal.IsStrongLimit c` means that `c` is a strong limit cardinal: `c ≠ 0 ∧ ∀ x < c, 2 ^ x < c`. * `Cardinal.IsRegular c` means that `c` is a regular cardinal: `ℵ₀ ≤ c ∧ c.ord.cof = c`. * `Cardinal.IsInaccessible c` means that `c` is strongly inaccessible: `ℵ₀ < c ∧ IsRegular c ∧ IsStrongLimit c`. ## Main Statements * `Ordinal.infinite_pigeonhole_card`: the infinite pigeonhole principle * `Cardinal.lt_power_cof`: A consequence of König's theorem stating that `c < c ^ c.ord.cof` for `c ≥ ℵ₀` * `Cardinal.univ_inaccessible`: The type of ordinals in `Type u` form an inaccessible cardinal (in `Type v` with `v > u`). This shows (externally) that in `Type u` there are at least `u` inaccessible cardinals. ## Implementation Notes * The cofinality is defined for ordinals. If `c` is a cardinal number, its cofinality is `c.ord.cof`. ## Tags cofinality, regular cardinals, limits cardinals, inaccessible cardinals, infinite pigeonhole principle -/ noncomputable section open Function Cardinal Set Order open scoped Classical open Cardinal Ordinal universe u v w variable {α : Type*} {r : α → α → Prop} /-! ### Cofinality of orders -/ namespace Order /-- Cofinality of a reflexive order `≼`. This is the smallest cardinality of a subset `S : Set α` such that `∀ a, ∃ b ∈ S, a ≼ b`. -/ def cof (r : α → α → Prop) : Cardinal := sInf { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c } #align order.cof Order.cof /-- The set in the definition of `Order.cof` is nonempty. -/ theorem cof_nonempty (r : α → α → Prop) [IsRefl α r] : { c | ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = c }.Nonempty := ⟨_, Set.univ, fun a => ⟨a, ⟨⟩, refl _⟩, rfl⟩ #align order.cof_nonempty Order.cof_nonempty theorem cof_le (r : α → α → Prop) {S : Set α} (h : ∀ a, ∃ b ∈ S, r a b) : cof r ≤ #S := csInf_le' ⟨S, h, rfl⟩ #align order.cof_le Order.cof_le theorem le_cof {r : α → α → Prop} [IsRefl α r] (c : Cardinal) : c ≤ cof r ↔ ∀ {S : Set α}, (∀ a, ∃ b ∈ S, r a b) → c ≤ #S := by rw [cof, le_csInf_iff'' (cof_nonempty r)] use fun H S h => H _ ⟨S, h, rfl⟩ rintro H d ⟨S, h, rfl⟩ exact H h #align order.le_cof Order.le_cof end Order theorem RelIso.cof_le_lift {α : Type u} {β : Type v} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) ≤ Cardinal.lift.{max u v} (Order.cof s) := by rw [Order.cof, Order.cof, lift_sInf, lift_sInf, le_csInf_iff'' ((Order.cof_nonempty s).image _)] rintro - ⟨-, ⟨u, H, rfl⟩, rfl⟩ apply csInf_le' refine ⟨_, ⟨f.symm '' u, fun a => ?_, rfl⟩, lift_mk_eq.{u, v, max u v}.2 ⟨(f.symm.toEquiv.image u).symm⟩⟩ rcases H (f a) with ⟨b, hb, hb'⟩ refine ⟨f.symm b, mem_image_of_mem _ hb, f.map_rel_iff.1 ?_⟩ rwa [RelIso.apply_symm_apply] #align rel_iso.cof_le_lift RelIso.cof_le_lift theorem RelIso.cof_eq_lift {α : Type u} {β : Type v} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) : Cardinal.lift.{max u v} (Order.cof r) = Cardinal.lift.{max u v} (Order.cof s) := (RelIso.cof_le_lift f).antisymm (RelIso.cof_le_lift f.symm) #align rel_iso.cof_eq_lift RelIso.cof_eq_lift theorem RelIso.cof_le {α β : Type u} {r : α → α → Prop} {s} [IsRefl β s] (f : r ≃r s) : Order.cof r ≤ Order.cof s := lift_le.1 (RelIso.cof_le_lift f) #align rel_iso.cof_le RelIso.cof_le theorem RelIso.cof_eq {α β : Type u} {r s} [IsRefl α r] [IsRefl β s] (f : r ≃r s) : Order.cof r = Order.cof s := lift_inj.1 (RelIso.cof_eq_lift f) #align rel_iso.cof_eq RelIso.cof_eq /-- Cofinality of a strict order `≺`. This is the smallest cardinality of a set `S : Set α` such that `∀ a, ∃ b ∈ S, ¬ b ≺ a`. -/ def StrictOrder.cof (r : α → α → Prop) : Cardinal := Order.cof (swap rᶜ) #align strict_order.cof StrictOrder.cof /-- The set in the definition of `Order.StrictOrder.cof` is nonempty. -/ theorem StrictOrder.cof_nonempty (r : α → α → Prop) [IsIrrefl α r] : { c | ∃ S : Set α, Unbounded r S ∧ #S = c }.Nonempty := @Order.cof_nonempty α _ (IsRefl.swap rᶜ) #align strict_order.cof_nonempty StrictOrder.cof_nonempty /-! ### Cofinality of ordinals -/ namespace Ordinal /-- Cofinality of an ordinal. This is the smallest cardinal of a subset `S` of the ordinal which is unbounded, in the sense `∀ a, ∃ b ∈ S, a ≤ b`. It is defined for all ordinals, but `cof 0 = 0` and `cof (succ o) = 1`, so it is only really interesting on limit ordinals (when it is an infinite cardinal). -/ def cof (o : Ordinal.{u}) : Cardinal.{u} := o.liftOn (fun a => StrictOrder.cof a.r) (by rintro ⟨α, r, wo₁⟩ ⟨β, s, wo₂⟩ ⟨⟨f, hf⟩⟩ haveI := wo₁; haveI := wo₂ dsimp only apply @RelIso.cof_eq _ _ _ _ ?_ ?_ · constructor exact @fun a b => not_iff_not.2 hf · dsimp only [swap] exact ⟨fun _ => irrefl _⟩ · dsimp only [swap] exact ⟨fun _ => irrefl _⟩) #align ordinal.cof Ordinal.cof theorem cof_type (r : α → α → Prop) [IsWellOrder α r] : (type r).cof = StrictOrder.cof r := rfl #align ordinal.cof_type Ordinal.cof_type theorem le_cof_type [IsWellOrder α r] {c} : c ≤ cof (type r) ↔ ∀ S, Unbounded r S → c ≤ #S := (le_csInf_iff'' (StrictOrder.cof_nonempty r)).trans ⟨fun H S h => H _ ⟨S, h, rfl⟩, by rintro H d ⟨S, h, rfl⟩ exact H _ h⟩ #align ordinal.le_cof_type Ordinal.le_cof_type theorem cof_type_le [IsWellOrder α r] {S : Set α} (h : Unbounded r S) : cof (type r) ≤ #S := le_cof_type.1 le_rfl S h #align ordinal.cof_type_le Ordinal.cof_type_le theorem lt_cof_type [IsWellOrder α r] {S : Set α} : #S < cof (type r) → Bounded r S := by simpa using not_imp_not.2 cof_type_le #align ordinal.lt_cof_type Ordinal.lt_cof_type theorem cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ #S = cof (type r) := csInf_mem (StrictOrder.cof_nonempty r) #align ordinal.cof_eq Ordinal.cof_eq theorem ord_cof_eq (r : α → α → Prop) [IsWellOrder α r] : ∃ S, Unbounded r S ∧ type (Subrel r S) = (cof (type r)).ord := by let ⟨S, hS, e⟩ := cof_eq r let ⟨s, _, e'⟩ := Cardinal.ord_eq S let T : Set α := { a | ∃ aS : a ∈ S, ∀ b : S, s b ⟨_, aS⟩ → r b a } suffices Unbounded r T by refine ⟨T, this, le_antisymm ?_ (Cardinal.ord_le.2 <| cof_type_le this)⟩ rw [← e, e'] refine (RelEmbedding.ofMonotone (fun a : T => (⟨a, let ⟨aS, _⟩ := a.2 aS⟩ : S)) fun a b h => ?_).ordinal_type_le rcases a with ⟨a, aS, ha⟩ rcases b with ⟨b, bS, hb⟩ change s ⟨a, _⟩ ⟨b, _⟩ refine ((trichotomous_of s _ _).resolve_left fun hn => ?_).resolve_left ?_ · exact asymm h (ha _ hn) · intro e injection e with e subst b exact irrefl _ h intro a have : { b : S | ¬r b a }.Nonempty := let ⟨b, bS, ba⟩ := hS a ⟨⟨b, bS⟩, ba⟩ let b := (IsWellFounded.wf : WellFounded s).min _ this have ba : ¬r b a := IsWellFounded.wf.min_mem _ this refine ⟨b, ⟨b.2, fun c => not_imp_not.1 fun h => ?_⟩, ba⟩ rw [show ∀ b : S, (⟨b, b.2⟩ : S) = b by intro b; cases b; rfl] exact IsWellFounded.wf.not_lt_min _ this (IsOrderConnected.neg_trans h ba) #align ordinal.ord_cof_eq Ordinal.ord_cof_eq /-! ### Cofinality of suprema and least strict upper bounds -/ private theorem card_mem_cof {o} : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = o.card := ⟨_, _, lsub_typein o, mk_ordinal_out o⟩ /-- The set in the `lsub` characterization of `cof` is nonempty. -/ theorem cof_lsub_def_nonempty (o) : { a : Cardinal | ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a }.Nonempty := ⟨_, card_mem_cof⟩ #align ordinal.cof_lsub_def_nonempty Ordinal.cof_lsub_def_nonempty theorem cof_eq_sInf_lsub (o : Ordinal.{u}) : cof o = sInf { a : Cardinal | ∃ (ι : Type u) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = a } := by refine le_antisymm (le_csInf (cof_lsub_def_nonempty o) ?_) (csInf_le' ?_) · rintro a ⟨ι, f, hf, rfl⟩ rw [← type_lt o] refine (cof_type_le fun a => ?_).trans (@mk_le_of_injective _ _ (fun s : typein ((· < ·) : o.out.α → o.out.α → Prop) ⁻¹' Set.range f => Classical.choose s.prop) fun s t hst => by let H := congr_arg f hst rwa [Classical.choose_spec s.prop, Classical.choose_spec t.prop, typein_inj, Subtype.coe_inj] at H) have := typein_lt_self a simp_rw [← hf, lt_lsub_iff] at this cases' this with i hi refine ⟨enum (· < ·) (f i) ?_, ?_, ?_⟩ · rw [type_lt, ← hf] apply lt_lsub · rw [mem_preimage, typein_enum] exact mem_range_self i · rwa [← typein_le_typein, typein_enum] · rcases cof_eq (· < · : (Quotient.out o).α → (Quotient.out o).α → Prop) with ⟨S, hS, hS'⟩ let f : S → Ordinal := fun s => typein LT.lt s.val refine ⟨S, f, le_antisymm (lsub_le fun i => typein_lt_self (o := o) i) (le_of_forall_lt fun a ha => ?_), by rwa [type_lt o] at hS'⟩ rw [← type_lt o] at ha rcases hS (enum (· < ·) a ha) with ⟨b, hb, hb'⟩ rw [← typein_le_typein, typein_enum] at hb' exact hb'.trans_lt (lt_lsub.{u, u} f ⟨b, hb⟩) #align ordinal.cof_eq_Inf_lsub Ordinal.cof_eq_sInf_lsub @[simp] theorem lift_cof (o) : Cardinal.lift.{u, v} (cof o) = cof (Ordinal.lift.{u, v} o) := by refine inductionOn o ?_ intro α r _ apply le_antisymm · refine le_cof_type.2 fun S H => ?_ have : Cardinal.lift.{u, v} #(ULift.up ⁻¹' S) ≤ #(S : Type (max u v)) := by rw [← Cardinal.lift_umax.{v, u}, ← Cardinal.lift_id'.{v, u} #S] exact mk_preimage_of_injective_lift.{v, max u v} ULift.up S (ULift.up_injective.{u, v}) refine (Cardinal.lift_le.2 <| cof_type_le ?_).trans this exact fun a => let ⟨⟨b⟩, bs, br⟩ := H ⟨a⟩ ⟨b, bs, br⟩ · rcases cof_eq r with ⟨S, H, e'⟩ have : #(ULift.down.{u, v} ⁻¹' S) ≤ Cardinal.lift.{u, v} #S := ⟨⟨fun ⟨⟨x⟩, h⟩ => ⟨⟨x, h⟩⟩, fun ⟨⟨x⟩, h₁⟩ ⟨⟨y⟩, h₂⟩ e => by simp at e; congr⟩⟩ rw [e'] at this refine (cof_type_le ?_).trans this exact fun ⟨a⟩ => let ⟨b, bs, br⟩ := H a ⟨⟨b⟩, bs, br⟩ #align ordinal.lift_cof Ordinal.lift_cof theorem cof_le_card (o) : cof o ≤ card o := by rw [cof_eq_sInf_lsub] exact csInf_le' card_mem_cof #align ordinal.cof_le_card Ordinal.cof_le_card theorem cof_ord_le (c : Cardinal) : c.ord.cof ≤ c := by simpa using cof_le_card c.ord #align ordinal.cof_ord_le Ordinal.cof_ord_le theorem ord_cof_le (o : Ordinal.{u}) : o.cof.ord ≤ o := (ord_le_ord.2 (cof_le_card o)).trans (ord_card_le o) #align ordinal.ord_cof_le Ordinal.ord_cof_le theorem exists_lsub_cof (o : Ordinal) : ∃ (ι : _) (f : ι → Ordinal), lsub.{u, u} f = o ∧ #ι = cof o := by rw [cof_eq_sInf_lsub] exact csInf_mem (cof_lsub_def_nonempty o) #align ordinal.exists_lsub_cof Ordinal.exists_lsub_cof theorem cof_lsub_le {ι} (f : ι → Ordinal) : cof (lsub.{u, u} f) ≤ #ι := by rw [cof_eq_sInf_lsub] exact csInf_le' ⟨ι, f, rfl, rfl⟩ #align ordinal.cof_lsub_le Ordinal.cof_lsub_le theorem cof_lsub_le_lift {ι} (f : ι → Ordinal) : cof (lsub.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← mk_uLift.{u, v}] convert cof_lsub_le.{max u v} fun i : ULift.{v, u} ι => f i.down exact lsub_eq_of_range_eq.{u, max u v, max u v} (Set.ext fun x => ⟨fun ⟨i, hi⟩ => ⟨ULift.up.{v, u} i, hi⟩, fun ⟨i, hi⟩ => ⟨_, hi⟩⟩) #align ordinal.cof_lsub_le_lift Ordinal.cof_lsub_le_lift theorem le_cof_iff_lsub {o : Ordinal} {a : Cardinal} : a ≤ cof o ↔ ∀ {ι} (f : ι → Ordinal), lsub.{u, u} f = o → a ≤ #ι := by rw [cof_eq_sInf_lsub] exact (le_csInf_iff'' (cof_lsub_def_nonempty o)).trans ⟨fun H ι f hf => H _ ⟨ι, f, hf, rfl⟩, fun H b ⟨ι, f, hf, hb⟩ => by rw [← hb] exact H _ hf⟩ #align ordinal.le_cof_iff_lsub Ordinal.le_cof_iff_lsub theorem lsub_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : lsub.{u, v} f < c := lt_of_le_of_ne (lsub_le.{v, u} hf) fun h => by subst h exact (cof_lsub_le_lift.{u, v} f).not_lt hι #align ordinal.lsub_lt_ord_lift Ordinal.lsub_lt_ord_lift theorem lsub_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → lsub.{u, u} f < c := lsub_lt_ord_lift (by rwa [(#ι).lift_id]) #align ordinal.lsub_lt_ord Ordinal.lsub_lt_ord theorem cof_sup_le_lift {ι} {f : ι → Ordinal} (H : ∀ i, f i < sup.{u, v} f) : cof (sup.{u, v} f) ≤ Cardinal.lift.{v, u} #ι := by rw [← sup_eq_lsub_iff_lt_sup.{u, v}] at H rw [H] exact cof_lsub_le_lift f #align ordinal.cof_sup_le_lift Ordinal.cof_sup_le_lift theorem cof_sup_le {ι} {f : ι → Ordinal} (H : ∀ i, f i < sup.{u, u} f) : cof (sup.{u, u} f) ≤ #ι := by rw [← (#ι).lift_id] exact cof_sup_le_lift H #align ordinal.cof_sup_le Ordinal.cof_sup_le theorem sup_lt_ord_lift {ι} {f : ι → Ordinal} {c : Ordinal} (hι : Cardinal.lift.{v, u} #ι < c.cof) (hf : ∀ i, f i < c) : sup.{u, v} f < c := (sup_le_lsub.{u, v} f).trans_lt (lsub_lt_ord_lift hι hf) #align ordinal.sup_lt_ord_lift Ordinal.sup_lt_ord_lift theorem sup_lt_ord {ι} {f : ι → Ordinal} {c : Ordinal} (hι : #ι < c.cof) : (∀ i, f i < c) → sup.{u, u} f < c := sup_lt_ord_lift (by rwa [(#ι).lift_id]) #align ordinal.sup_lt_ord Ordinal.sup_lt_ord theorem iSup_lt_lift {ι} {f : ι → Cardinal} {c : Cardinal} (hι : Cardinal.lift.{v, u} #ι < c.ord.cof) (hf : ∀ i, f i < c) : iSup.{max u v + 1, u + 1} f < c := by rw [← ord_lt_ord, iSup_ord (Cardinal.bddAbove_range.{u, v} _)] refine sup_lt_ord_lift hι fun i => ?_ rw [ord_lt_ord] apply hf #align ordinal.supr_lt_lift Ordinal.iSup_lt_lift theorem iSup_lt {ι} {f : ι → Cardinal} {c : Cardinal} (hι : #ι < c.ord.cof) : (∀ i, f i < c) → iSup f < c := iSup_lt_lift (by rwa [(#ι).lift_id]) #align ordinal.supr_lt Ordinal.iSup_lt theorem nfpFamily_lt_ord_lift {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} (ha : a < c) : nfpFamily.{u, v} f a < c := by refine sup_lt_ord_lift ((Cardinal.lift_le.2 (mk_list_le_max ι)).trans_lt ?_) fun l => ?_ · rw [lift_max] apply max_lt _ hc' rwa [Cardinal.lift_aleph0] · induction' l with i l H · exact ha · exact hf _ _ H #align ordinal.nfp_family_lt_ord_lift Ordinal.nfpFamily_lt_ord_lift theorem nfpFamily_lt_ord {ι} {f : ι → Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : #ι < cof c) (hf : ∀ (i), ∀ b < c, f i b < c) {a} : a < c → nfpFamily.{u, u} f a < c := nfpFamily_lt_ord_lift hc (by rwa [(#ι).lift_id]) hf #align ordinal.nfp_family_lt_ord Ordinal.nfpFamily_lt_ord theorem nfpBFamily_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : Cardinal.lift.{v, u} o.card < cof c) (hf : ∀ (i hi), ∀ b < c, f i hi b < c) {a} : a < c → nfpBFamily.{u, v} o f a < c := nfpFamily_lt_ord_lift hc (by rwa [mk_ordinal_out]) fun i => hf _ _ #align ordinal.nfp_bfamily_lt_ord_lift Ordinal.nfpBFamily_lt_ord_lift theorem nfpBFamily_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hc' : o.card < cof c) (hf : ∀ (i hi), ∀ b < c, f i hi b < c) {a} : a < c → nfpBFamily.{u, u} o f a < c := nfpBFamily_lt_ord_lift hc (by rwa [o.card.lift_id]) hf #align ordinal.nfp_bfamily_lt_ord Ordinal.nfpBFamily_lt_ord theorem nfp_lt_ord {f : Ordinal → Ordinal} {c} (hc : ℵ₀ < cof c) (hf : ∀ i < c, f i < c) {a} : a < c → nfp f a < c := nfpFamily_lt_ord_lift hc (by simpa using Cardinal.one_lt_aleph0.trans hc) fun _ => hf #align ordinal.nfp_lt_ord Ordinal.nfp_lt_ord theorem exists_blsub_cof (o : Ordinal) : ∃ f : ∀ a < (cof o).ord, Ordinal, blsub.{u, u} _ f = o := by rcases exists_lsub_cof o with ⟨ι, f, hf, hι⟩ rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf rw [← hι, hι'] exact ⟨_, hf⟩ #align ordinal.exists_blsub_cof Ordinal.exists_blsub_cof theorem le_cof_iff_blsub {b : Ordinal} {a : Cardinal} : a ≤ cof b ↔ ∀ {o} (f : ∀ a < o, Ordinal), blsub.{u, u} o f = b → a ≤ o.card := le_cof_iff_lsub.trans ⟨fun H o f hf => by simpa using H _ hf, fun H ι f hf => by rcases Cardinal.ord_eq ι with ⟨r, hr, hι'⟩ rw [← @blsub_eq_lsub' ι r hr] at hf simpa using H _ hf⟩ #align ordinal.le_cof_iff_blsub Ordinal.le_cof_iff_blsub theorem cof_blsub_le_lift {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← mk_ordinal_out o] exact cof_lsub_le_lift _ #align ordinal.cof_blsub_le_lift Ordinal.cof_blsub_le_lift theorem cof_blsub_le {o} (f : ∀ a < o, Ordinal) : cof (blsub.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_blsub_le_lift f #align ordinal.cof_blsub_le Ordinal.cof_blsub_le theorem blsub_lt_ord_lift {o : Ordinal.{u}} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, v} o f < c := lt_of_le_of_ne (blsub_le hf) fun h => ho.not_le (by simpa [← iSup_ord, hf, h] using cof_blsub_le_lift.{u, v} f) #align ordinal.blsub_lt_ord_lift Ordinal.blsub_lt_ord_lift theorem blsub_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) (hf : ∀ i hi, f i hi < c) : blsub.{u, u} o f < c := blsub_lt_ord_lift (by rwa [o.card.lift_id]) hf #align ordinal.blsub_lt_ord Ordinal.blsub_lt_ord theorem cof_bsup_le_lift {o : Ordinal} {f : ∀ a < o, Ordinal} (H : ∀ i h, f i h < bsup.{u, v} o f) : cof (bsup.{u, v} o f) ≤ Cardinal.lift.{v, u} o.card := by rw [← bsup_eq_blsub_iff_lt_bsup.{u, v}] at H rw [H] exact cof_blsub_le_lift.{u, v} f #align ordinal.cof_bsup_le_lift Ordinal.cof_bsup_le_lift theorem cof_bsup_le {o : Ordinal} {f : ∀ a < o, Ordinal} : (∀ i h, f i h < bsup.{u, u} o f) → cof (bsup.{u, u} o f) ≤ o.card := by rw [← o.card.lift_id] exact cof_bsup_le_lift #align ordinal.cof_bsup_le Ordinal.cof_bsup_le theorem bsup_lt_ord_lift {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : Cardinal.lift.{v, u} o.card < c.cof) (hf : ∀ i hi, f i hi < c) : bsup.{u, v} o f < c := (bsup_le_blsub f).trans_lt (blsub_lt_ord_lift ho hf) #align ordinal.bsup_lt_ord_lift Ordinal.bsup_lt_ord_lift theorem bsup_lt_ord {o : Ordinal} {f : ∀ a < o, Ordinal} {c : Ordinal} (ho : o.card < c.cof) : (∀ i hi, f i hi < c) → bsup.{u, u} o f < c := bsup_lt_ord_lift (by rwa [o.card.lift_id]) #align ordinal.bsup_lt_ord Ordinal.bsup_lt_ord /-! ### Basic results -/ @[simp] theorem cof_zero : cof 0 = 0 := by refine LE.le.antisymm ?_ (Cardinal.zero_le _) rw [← card_zero] exact cof_le_card 0 #align ordinal.cof_zero Ordinal.cof_zero @[simp] theorem cof_eq_zero {o} : cof o = 0 ↔ o = 0 := ⟨inductionOn o fun α r _ z => let ⟨S, hl, e⟩ := cof_eq r type_eq_zero_iff_isEmpty.2 <| ⟨fun a => let ⟨b, h, _⟩ := hl a (mk_eq_zero_iff.1 (e.trans z)).elim' ⟨_, h⟩⟩, fun e => by simp [e]⟩ #align ordinal.cof_eq_zero Ordinal.cof_eq_zero theorem cof_ne_zero {o} : cof o ≠ 0 ↔ o ≠ 0 := cof_eq_zero.not #align ordinal.cof_ne_zero Ordinal.cof_ne_zero @[simp] theorem cof_succ (o) : cof (succ o) = 1 := by apply le_antisymm · refine inductionOn o fun α r _ => ?_ change cof (type _) ≤ _ rw [← (_ : #_ = 1)] · apply cof_type_le refine fun a => ⟨Sum.inr PUnit.unit, Set.mem_singleton _, ?_⟩ rcases a with (a | ⟨⟨⟨⟩⟩⟩) <;> simp [EmptyRelation] · rw [Cardinal.mk_fintype, Set.card_singleton] simp · rw [← Cardinal.succ_zero, succ_le_iff] simpa [lt_iff_le_and_ne, Cardinal.zero_le] using fun h => succ_ne_zero o (cof_eq_zero.1 (Eq.symm h)) #align ordinal.cof_succ Ordinal.cof_succ @[simp] theorem cof_eq_one_iff_is_succ {o} : cof.{u} o = 1 ↔ ∃ a, o = succ a := ⟨inductionOn o fun α r _ z => by rcases cof_eq r with ⟨S, hl, e⟩; rw [z] at e cases' mk_ne_zero_iff.1 (by rw [e]; exact one_ne_zero) with a refine ⟨typein r a, Eq.symm <| Quotient.sound ⟨RelIso.ofSurjective (RelEmbedding.ofMonotone ?_ fun x y => ?_) fun x => ?_⟩⟩ · apply Sum.rec <;> [exact Subtype.val; exact fun _ => a] · rcases x with (x | ⟨⟨⟨⟩⟩⟩) <;> rcases y with (y | ⟨⟨⟨⟩⟩⟩) <;> simp [Subrel, Order.Preimage, EmptyRelation] exact x.2 · suffices r x a ∨ ∃ _ : PUnit.{u}, ↑a = x by convert this dsimp [RelEmbedding.ofMonotone]; simp rcases trichotomous_of r x a with (h | h | h) · exact Or.inl h · exact Or.inr ⟨PUnit.unit, h.symm⟩ · rcases hl x with ⟨a', aS, hn⟩ rw [(_ : ↑a = a')] at h · exact absurd h hn refine congr_arg Subtype.val (?_ : a = ⟨a', aS⟩) haveI := le_one_iff_subsingleton.1 (le_of_eq e) apply Subsingleton.elim, fun ⟨a, e⟩ => by simp [e]⟩ #align ordinal.cof_eq_one_iff_is_succ Ordinal.cof_eq_one_iff_is_succ /-- A fundamental sequence for `a` is an increasing sequence of length `o = cof a` that converges at `a`. We provide `o` explicitly in order to avoid type rewrites. -/ def IsFundamentalSequence (a o : Ordinal.{u}) (f : ∀ b < o, Ordinal.{u}) : Prop := o ≤ a.cof.ord ∧ (∀ {i j} (hi hj), i < j → f i hi < f j hj) ∧ blsub.{u, u} o f = a #align ordinal.is_fundamental_sequence Ordinal.IsFundamentalSequence namespace IsFundamentalSequence variable {a o : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} protected theorem cof_eq (hf : IsFundamentalSequence a o f) : a.cof.ord = o := hf.1.antisymm' <| by rw [← hf.2.2] exact (ord_le_ord.2 (cof_blsub_le f)).trans (ord_card_le o) #align ordinal.is_fundamental_sequence.cof_eq Ordinal.IsFundamentalSequence.cof_eq protected theorem strict_mono (hf : IsFundamentalSequence a o f) {i j} : ∀ hi hj, i < j → f i hi < f j hj := hf.2.1 #align ordinal.is_fundamental_sequence.strict_mono Ordinal.IsFundamentalSequence.strict_mono theorem blsub_eq (hf : IsFundamentalSequence a o f) : blsub.{u, u} o f = a := hf.2.2 #align ordinal.is_fundamental_sequence.blsub_eq Ordinal.IsFundamentalSequence.blsub_eq theorem ord_cof (hf : IsFundamentalSequence a o f) : IsFundamentalSequence a a.cof.ord fun i hi => f i (hi.trans_le (by rw [hf.cof_eq])) := by have H := hf.cof_eq subst H exact hf #align ordinal.is_fundamental_sequence.ord_cof Ordinal.IsFundamentalSequence.ord_cof theorem id_of_le_cof (h : o ≤ o.cof.ord) : IsFundamentalSequence o o fun a _ => a := ⟨h, @fun _ _ _ _ => id, blsub_id o⟩ #align ordinal.is_fundamental_sequence.id_of_le_cof Ordinal.IsFundamentalSequence.id_of_le_cof protected theorem zero {f : ∀ b < (0 : Ordinal), Ordinal} : IsFundamentalSequence 0 0 f := ⟨by rw [cof_zero, ord_zero], @fun i j hi => (Ordinal.not_lt_zero i hi).elim, blsub_zero f⟩ #align ordinal.is_fundamental_sequence.zero Ordinal.IsFundamentalSequence.zero protected theorem succ : IsFundamentalSequence (succ o) 1 fun _ _ => o := by refine ⟨?_, @fun i j hi hj h => ?_, blsub_const Ordinal.one_ne_zero o⟩ · rw [cof_succ, ord_one] · rw [lt_one_iff_zero] at hi hj rw [hi, hj] at h exact h.false.elim #align ordinal.is_fundamental_sequence.succ Ordinal.IsFundamentalSequence.succ protected theorem monotone (hf : IsFundamentalSequence a o f) {i j : Ordinal} (hi : i < o) (hj : j < o) (hij : i ≤ j) : f i hi ≤ f j hj := by rcases lt_or_eq_of_le hij with (hij | rfl) · exact (hf.2.1 hi hj hij).le · rfl #align ordinal.is_fundamental_sequence.monotone Ordinal.IsFundamentalSequence.monotone theorem trans {a o o' : Ordinal.{u}} {f : ∀ b < o, Ordinal.{u}} (hf : IsFundamentalSequence a o f) {g : ∀ b < o', Ordinal.{u}} (hg : IsFundamentalSequence o o' g) : IsFundamentalSequence a o' fun i hi => f (g i hi) (by rw [← hg.2.2]; apply lt_blsub) := by refine ⟨?_, @fun i j _ _ h => hf.2.1 _ _ (hg.2.1 _ _ h), ?_⟩ · rw [hf.cof_eq] exact hg.1.trans (ord_cof_le o) · rw [@blsub_comp.{u, u, u} o _ f (@IsFundamentalSequence.monotone _ _ f hf)] · exact hf.2.2 · exact hg.2.2 #align ordinal.is_fundamental_sequence.trans Ordinal.IsFundamentalSequence.trans end IsFundamentalSequence /-- Every ordinal has a fundamental sequence. -/ theorem exists_fundamental_sequence (a : Ordinal.{u}) : ∃ f, IsFundamentalSequence a a.cof.ord f := by suffices h : ∃ o f, IsFundamentalSequence a o f by rcases h with ⟨o, f, hf⟩ exact ⟨_, hf.ord_cof⟩ rcases exists_lsub_cof a with ⟨ι, f, hf, hι⟩ rcases ord_eq ι with ⟨r, wo, hr⟩ haveI := wo let r' := Subrel r { i | ∀ j, r j i → f j < f i } let hrr' : r' ↪r r := Subrel.relEmbedding _ _ haveI := hrr'.isWellOrder refine ⟨_, _, hrr'.ordinal_type_le.trans ?_, @fun i j _ h _ => (enum r' j h).prop _ ?_, le_antisymm (blsub_le fun i hi => lsub_le_iff.1 hf.le _) ?_⟩ · rw [← hι, hr] · change r (hrr'.1 _) (hrr'.1 _) rwa [hrr'.2, @enum_lt_enum _ r'] · rw [← hf, lsub_le_iff] intro i suffices h : ∃ i' hi', f i ≤ bfamilyOfFamily' r' (fun i => f i) i' hi' by rcases h with ⟨i', hi', hfg⟩ exact hfg.trans_lt (lt_blsub _ _ _) by_cases h : ∀ j, r j i → f j < f i · refine ⟨typein r' ⟨i, h⟩, typein_lt_type _ _, ?_⟩ rw [bfamilyOfFamily'_typein] · push_neg at h cases' wo.wf.min_mem _ h with hji hij refine ⟨typein r' ⟨_, fun k hkj => lt_of_lt_of_le ?_ hij⟩, typein_lt_type _ _, ?_⟩ · by_contra! H exact (wo.wf.not_lt_min _ h ⟨IsTrans.trans _ _ _ hkj hji, H⟩) hkj · rwa [bfamilyOfFamily'_typein] #align ordinal.exists_fundamental_sequence Ordinal.exists_fundamental_sequence @[simp] theorem cof_cof (a : Ordinal.{u}) : cof (cof a).ord = cof a := by cases' exists_fundamental_sequence a with f hf cases' exists_fundamental_sequence a.cof.ord with g hg exact ord_injective (hf.trans hg).cof_eq.symm #align ordinal.cof_cof Ordinal.cof_cof protected theorem IsNormal.isFundamentalSequence {f : Ordinal.{u} → Ordinal.{u}} (hf : IsNormal f) {a o} (ha : IsLimit a) {g} (hg : IsFundamentalSequence a o g) : IsFundamentalSequence (f a) o fun b hb => f (g b hb) := by refine ⟨?_, @fun i j _ _ h => hf.strictMono (hg.2.1 _ _ h), ?_⟩ · rcases exists_lsub_cof (f a) with ⟨ι, f', hf', hι⟩ rw [← hg.cof_eq, ord_le_ord, ← hι] suffices (lsub.{u, u} fun i => sInf { b : Ordinal | f' i ≤ f b }) = a by rw [← this] apply cof_lsub_le have H : ∀ i, ∃ b < a, f' i ≤ f b := fun i => by have := lt_lsub.{u, u} f' i rw [hf', ← IsNormal.blsub_eq.{u, u} hf ha, lt_blsub_iff] at this simpa using this refine (lsub_le fun i => ?_).antisymm (le_of_forall_lt fun b hb => ?_) · rcases H i with ⟨b, hb, hb'⟩ exact lt_of_le_of_lt (csInf_le' hb') hb · have := hf.strictMono hb rw [← hf', lt_lsub_iff] at this cases' this with i hi rcases H i with ⟨b, _, hb⟩ exact ((le_csInf_iff'' ⟨b, by exact hb⟩).2 fun c hc => hf.strictMono.le_iff_le.1 (hi.trans hc)).trans_lt (lt_lsub _ i) · rw [@blsub_comp.{u, u, u} a _ (fun b _ => f b) (@fun i j _ _ h => hf.strictMono.monotone h) g hg.2.2] exact IsNormal.blsub_eq.{u, u} hf ha #align ordinal.is_normal.is_fundamental_sequence Ordinal.IsNormal.isFundamentalSequence theorem IsNormal.cof_eq {f} (hf : IsNormal f) {a} (ha : IsLimit a) : cof (f a) = cof a := let ⟨_, hg⟩ := exists_fundamental_sequence a ord_injective (hf.isFundamentalSequence ha hg).cof_eq #align ordinal.is_normal.cof_eq Ordinal.IsNormal.cof_eq theorem IsNormal.cof_le {f} (hf : IsNormal f) (a) : cof a ≤ cof (f a) := by rcases zero_or_succ_or_limit a with (rfl | ⟨b, rfl⟩ | ha) · rw [cof_zero] exact zero_le _ · rw [cof_succ, Cardinal.one_le_iff_ne_zero, cof_ne_zero, ← Ordinal.pos_iff_ne_zero] exact (Ordinal.zero_le (f b)).trans_lt (hf.1 b) · rw [hf.cof_eq ha] #align ordinal.is_normal.cof_le Ordinal.IsNormal.cof_le @[simp] theorem cof_add (a b : Ordinal) : b ≠ 0 → cof (a + b) = cof b := fun h => by rcases zero_or_succ_or_limit b with (rfl | ⟨c, rfl⟩ | hb) · contradiction · rw [add_succ, cof_succ, cof_succ] · exact (add_isNormal a).cof_eq hb #align ordinal.cof_add Ordinal.cof_add theorem aleph0_le_cof {o} : ℵ₀ ≤ cof o ↔ IsLimit o := by rcases zero_or_succ_or_limit o with (rfl | ⟨o, rfl⟩ | l) · simp [not_zero_isLimit, Cardinal.aleph0_ne_zero] · simp [not_succ_isLimit, Cardinal.one_lt_aleph0] · simp [l] refine le_of_not_lt fun h => ?_ cases' Cardinal.lt_aleph0.1 h with n e have := cof_cof o rw [e, ord_nat] at this cases n · simp at e simp [e, not_zero_isLimit] at l · rw [natCast_succ, cof_succ] at this rw [← this, cof_eq_one_iff_is_succ] at e rcases e with ⟨a, rfl⟩ exact not_succ_isLimit _ l #align ordinal.aleph_0_le_cof Ordinal.aleph0_le_cof @[simp] theorem aleph'_cof {o : Ordinal} (ho : o.IsLimit) : (aleph' o).ord.cof = o.cof := aleph'_isNormal.cof_eq ho #align ordinal.aleph'_cof Ordinal.aleph'_cof @[simp] theorem aleph_cof {o : Ordinal} (ho : o.IsLimit) : (aleph o).ord.cof = o.cof := aleph_isNormal.cof_eq ho #align ordinal.aleph_cof Ordinal.aleph_cof @[simp] theorem cof_omega : cof ω = ℵ₀ := (aleph0_le_cof.2 omega_isLimit).antisymm' <| by rw [← card_omega] apply cof_le_card #align ordinal.cof_omega Ordinal.cof_omega theorem cof_eq' (r : α → α → Prop) [IsWellOrder α r] (h : IsLimit (type r)) : ∃ S : Set α, (∀ a, ∃ b ∈ S, r a b) ∧ #S = cof (type r) := let ⟨S, H, e⟩ := cof_eq r ⟨S, fun a => let a' := enum r _ (h.2 _ (typein_lt_type r a)) let ⟨b, h, ab⟩ := H a' ⟨b, h, (IsOrderConnected.conn a b a' <| (typein_lt_typein r).1 (by rw [typein_enum] exact lt_succ (typein _ _))).resolve_right ab⟩, e⟩ #align ordinal.cof_eq' Ordinal.cof_eq' @[simp] theorem cof_univ : cof univ.{u, v} = Cardinal.univ.{u, v} := le_antisymm (cof_le_card _) (by refine le_of_forall_lt fun c h => ?_ rcases lt_univ'.1 h with ⟨c, rfl⟩ rcases @cof_eq Ordinal.{u} (· < ·) _ with ⟨S, H, Se⟩ rw [univ, ← lift_cof, ← Cardinal.lift_lift.{u+1, v, u}, Cardinal.lift_lt, ← Se] refine lt_of_not_ge fun h => ?_ cases' Cardinal.lift_down h with a e refine Quotient.inductionOn a (fun α e => ?_) e cases' Quotient.exact e with f have f := Equiv.ulift.symm.trans f let g a := (f a).1 let o := succ (sup.{u, u} g) rcases H o with ⟨b, h, l⟩ refine l (lt_succ_iff.2 ?_) rw [← show g (f.symm ⟨b, h⟩) = b by simp [g]] apply le_sup) #align ordinal.cof_univ Ordinal.cof_univ /-! ### Infinite pigeonhole principle -/ /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_sUnion (r : α → α → Prop) [wo : IsWellOrder α r] {s : Set (Set α)} (h₁ : Unbounded r <| ⋃₀ s) (h₂ : #s < StrictOrder.cof r) : ∃ x ∈ s, Unbounded r x := by by_contra! h simp_rw [not_unbounded_iff] at h let f : s → α := fun x : s => wo.wf.sup x (h x.1 x.2) refine h₂.not_le (le_trans (csInf_le' ⟨range f, fun x => ?_, rfl⟩) mk_range_le) rcases h₁ x with ⟨y, ⟨c, hc, hy⟩, hxy⟩ exact ⟨f ⟨c, hc⟩, mem_range_self _, fun hxz => hxy (Trans.trans (wo.wf.lt_sup _ hy) hxz)⟩ #align ordinal.unbounded_of_unbounded_sUnion Ordinal.unbounded_of_unbounded_sUnion /-- If the union of s is unbounded and s is smaller than the cofinality, then s has an unbounded member -/ theorem unbounded_of_unbounded_iUnion {α β : Type u} (r : α → α → Prop) [wo : IsWellOrder α r] (s : β → Set α) (h₁ : Unbounded r <| ⋃ x, s x) (h₂ : #β < StrictOrder.cof r) : ∃ x : β, Unbounded r (s x) := by rw [← sUnion_range] at h₁ rcases unbounded_of_unbounded_sUnion r h₁ (mk_range_le.trans_lt h₂) with ⟨_, ⟨x, rfl⟩, u⟩ exact ⟨x, u⟩ #align ordinal.unbounded_of_unbounded_Union Ordinal.unbounded_of_unbounded_iUnion /-- The infinite pigeonhole principle -/ theorem infinite_pigeonhole {β α : Type u} (f : β → α) (h₁ : ℵ₀ ≤ #β) (h₂ : #α < (#β).ord.cof) : ∃ a : α, #(f ⁻¹' {a}) = #β := by have : ∃ a, #β ≤ #(f ⁻¹' {a}) := by by_contra! h apply mk_univ.not_lt rw [← preimage_univ, ← iUnion_of_singleton, preimage_iUnion] exact mk_iUnion_le_sum_mk.trans_lt ((sum_le_iSup _).trans_lt <| mul_lt_of_lt h₁ (h₂.trans_le <| cof_ord_le _) (iSup_lt h₂ h)) cases' this with x h refine ⟨x, h.antisymm' ?_⟩ rw [le_mk_iff_exists_set] exact ⟨_, rfl⟩ #align ordinal.infinite_pigeonhole Ordinal.infinite_pigeonhole /-- Pigeonhole principle for a cardinality below the cardinality of the domain -/ theorem infinite_pigeonhole_card {β α : Type u} (f : β → α) (θ : Cardinal) (hθ : θ ≤ #β) (h₁ : ℵ₀ ≤ θ) (h₂ : #α < θ.ord.cof) : ∃ a : α, θ ≤ #(f ⁻¹' {a}) := by rcases le_mk_iff_exists_set.1 hθ with ⟨s, rfl⟩ cases' infinite_pigeonhole (f ∘ Subtype.val : s → α) h₁ h₂ with a ha use a; rw [← ha, @preimage_comp _ _ _ Subtype.val f] exact mk_preimage_of_injective _ _ Subtype.val_injective #align ordinal.infinite_pigeonhole_card Ordinal.infinite_pigeonhole_card theorem infinite_pigeonhole_set {β α : Type u} {s : Set β} (f : s → α) (θ : Cardinal) (hθ : θ ≤ #s) (h₁ : ℵ₀ ≤ θ) (h₂ : #α < θ.ord.cof) : ∃ (a : α) (t : Set β) (h : t ⊆ s), θ ≤ #t ∧ ∀ ⦃x⦄ (hx : x ∈ t), f ⟨x, h hx⟩ = a := by cases' infinite_pigeonhole_card f θ hθ h₁ h₂ with a ha refine ⟨a, { x | ∃ h, f ⟨x, h⟩ = a }, ?_, ?_, ?_⟩ · rintro x ⟨hx, _⟩ exact hx · refine ha.trans (ge_of_eq <| Quotient.sound ⟨Equiv.trans ?_ (Equiv.subtypeSubtypeEquivSubtypeExists _ _).symm⟩) simp only [coe_eq_subtype, mem_singleton_iff, mem_preimage, mem_setOf_eq] rfl rintro x ⟨_, hx'⟩; exact hx' #align ordinal.infinite_pigeonhole_set Ordinal.infinite_pigeonhole_set end Ordinal /-! ### Regular and inaccessible cardinals -/ namespace Cardinal open Ordinal /-- A cardinal is a strong limit if it is not zero and it is closed under powersets. Note that `ℵ₀` is a strong limit by this definition. -/ def IsStrongLimit (c : Cardinal) : Prop := c ≠ 0 ∧ ∀ x < c, (2^x) < c #align cardinal.is_strong_limit Cardinal.IsStrongLimit theorem IsStrongLimit.ne_zero {c} (h : IsStrongLimit c) : c ≠ 0 := h.1 #align cardinal.is_strong_limit.ne_zero Cardinal.IsStrongLimit.ne_zero theorem IsStrongLimit.two_power_lt {x c} (h : IsStrongLimit c) : x < c → (2^x) < c := h.2 x #align cardinal.is_strong_limit.two_power_lt Cardinal.IsStrongLimit.two_power_lt theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ := ⟨aleph0_ne_zero, fun x hx => by rcases lt_aleph0.1 hx with ⟨n, rfl⟩ exact mod_cast nat_lt_aleph0 (2 ^ n)⟩ #align cardinal.is_strong_limit_aleph_0 Cardinal.isStrongLimit_aleph0 protected theorem IsStrongLimit.isSuccLimit {c} (H : IsStrongLimit c) : IsSuccLimit c := isSuccLimit_of_succ_lt fun x h => (succ_le_of_lt <| cantor x).trans_lt (H.two_power_lt h) #align cardinal.is_strong_limit.is_succ_limit Cardinal.IsStrongLimit.isSuccLimit theorem IsStrongLimit.isLimit {c} (H : IsStrongLimit c) : IsLimit c := ⟨H.ne_zero, H.isSuccLimit⟩ #align cardinal.is_strong_limit.is_limit Cardinal.IsStrongLimit.isLimit theorem isStrongLimit_beth {o : Ordinal} (H : IsSuccLimit o) : IsStrongLimit (beth o) := by rcases eq_or_ne o 0 with (rfl | h) · rw [beth_zero] exact isStrongLimit_aleph0 · refine ⟨beth_ne_zero o, fun a ha => ?_⟩ rw [beth_limit ⟨h, isSuccLimit_iff_succ_lt.1 H⟩] at ha rcases exists_lt_of_lt_ciSup' ha with ⟨⟨i, hi⟩, ha⟩ have := power_le_power_left two_ne_zero ha.le rw [← beth_succ] at this exact this.trans_lt (beth_lt.2 (H.succ_lt hi)) #align cardinal.is_strong_limit_beth Cardinal.isStrongLimit_beth theorem mk_bounded_subset {α : Type*} (h : ∀ x < #α, (2^x) < #α) {r : α → α → Prop} [IsWellOrder α r] (hr : (#α).ord = type r) : #{ s : Set α // Bounded r s } = #α := by rcases eq_or_ne #α 0 with (ha | ha) · rw [ha] haveI := mk_eq_zero_iff.1 ha rw [mk_eq_zero_iff] constructor rintro ⟨s, hs⟩ exact (not_unbounded_iff s).2 hs (unbounded_of_isEmpty s) have h' : IsStrongLimit #α := ⟨ha, h⟩ have ha := h'.isLimit.aleph0_le apply le_antisymm · have : { s : Set α | Bounded r s } = ⋃ i, 𝒫{ j | r j i } := setOf_exists _ rw [← coe_setOf, this] refine mk_iUnion_le_sum_mk.trans ((sum_le_iSup (fun i => #(𝒫{ j | r j i }))).trans ((mul_le_max_of_aleph0_le_left ha).trans ?_)) rw [max_eq_left] apply ciSup_le' _ intro i rw [mk_powerset] apply (h'.two_power_lt _).le rw [coe_setOf, card_typein, ← lt_ord, hr] apply typein_lt_type · refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_ · apply bounded_singleton rw [← hr] apply ord_isLimit ha · intro a b hab simpa [singleton_eq_singleton_iff] using hab #align cardinal.mk_bounded_subset Cardinal.mk_bounded_subset theorem mk_subset_mk_lt_cof {α : Type*} (h : ∀ x < #α, (2^x) < #α) : #{ s : Set α // #s < cof (#α).ord } = #α := by rcases eq_or_ne #α 0 with (ha | ha) · simp [ha] have h' : IsStrongLimit #α := ⟨ha, h⟩ rcases ord_eq α with ⟨r, wo, hr⟩ haveI := wo apply le_antisymm · conv_rhs => rw [← mk_bounded_subset h hr] apply mk_le_mk_of_subset intro s hs rw [hr] at hs exact lt_cof_type hs · refine @mk_le_of_injective α _ (fun x => Subtype.mk {x} ?_) ?_ · rw [mk_singleton] exact one_lt_aleph0.trans_le (aleph0_le_cof.2 (ord_isLimit h'.isLimit.aleph0_le)) · intro a b hab simpa [singleton_eq_singleton_iff] using hab #align cardinal.mk_subset_mk_lt_cof Cardinal.mk_subset_mk_lt_cof /-- A cardinal is regular if it is infinite and it equals its own cofinality. -/ def IsRegular (c : Cardinal) : Prop := ℵ₀ ≤ c ∧ c ≤ c.ord.cof #align cardinal.is_regular Cardinal.IsRegular theorem IsRegular.aleph0_le {c : Cardinal} (H : c.IsRegular) : ℵ₀ ≤ c := H.1 #align cardinal.is_regular.aleph_0_le Cardinal.IsRegular.aleph0_le theorem IsRegular.cof_eq {c : Cardinal} (H : c.IsRegular) : c.ord.cof = c := (cof_ord_le c).antisymm H.2 #align cardinal.is_regular.cof_eq Cardinal.IsRegular.cof_eq theorem IsRegular.pos {c : Cardinal} (H : c.IsRegular) : 0 < c := aleph0_pos.trans_le H.1 #align cardinal.is_regular.pos Cardinal.IsRegular.pos theorem IsRegular.nat_lt {c : Cardinal} (H : c.IsRegular) (n : ℕ) : n < c := lt_of_lt_of_le (nat_lt_aleph0 n) H.aleph0_le theorem IsRegular.ord_pos {c : Cardinal} (H : c.IsRegular) : 0 < c.ord := by rw [Cardinal.lt_ord, card_zero] exact H.pos #align cardinal.is_regular.ord_pos Cardinal.IsRegular.ord_pos theorem isRegular_cof {o : Ordinal} (h : o.IsLimit) : IsRegular o.cof := ⟨aleph0_le_cof.2 h, (cof_cof o).ge⟩ #align cardinal.is_regular_cof Cardinal.isRegular_cof theorem isRegular_aleph0 : IsRegular ℵ₀ := ⟨le_rfl, by simp⟩ #align cardinal.is_regular_aleph_0 Cardinal.isRegular_aleph0 theorem isRegular_succ {c : Cardinal.{u}} (h : ℵ₀ ≤ c) : IsRegular (succ c) := ⟨h.trans (le_succ c), succ_le_of_lt (by cases' Quotient.exists_rep (@succ Cardinal _ _ c) with α αe; simp at αe rcases ord_eq α with ⟨r, wo, re⟩ have := ord_isLimit (h.trans (le_succ _)) rw [← αe, re] at this ⊢ rcases cof_eq' r this with ⟨S, H, Se⟩ rw [← Se] apply lt_imp_lt_of_le_imp_le fun h => mul_le_mul_right' h c rw [mul_eq_self h, ← succ_le_iff, ← αe, ← sum_const'] refine le_trans ?_ (sum_le_sum (fun (x : S) => card (typein r (x : α))) _ fun i => ?_) · simp only [← card_typein, ← mk_sigma] exact ⟨Embedding.ofSurjective (fun x => x.2.1) fun a => let ⟨b, h, ab⟩ := H a ⟨⟨⟨_, h⟩, _, ab⟩, rfl⟩⟩ · rw [← lt_succ_iff, ← lt_ord, ← αe, re] apply typein_lt_type)⟩ #align cardinal.is_regular_succ Cardinal.isRegular_succ theorem isRegular_aleph_one : IsRegular (aleph 1) := by rw [← succ_aleph0] exact isRegular_succ le_rfl #align cardinal.is_regular_aleph_one Cardinal.isRegular_aleph_one
Mathlib/SetTheory/Cardinal/Cofinality.lean
1,002
1,004
theorem isRegular_aleph'_succ {o : Ordinal} (h : ω ≤ o) : IsRegular (aleph' (succ o)) := by
rw [aleph'_succ] exact isRegular_succ (aleph0_le_aleph'.2 h)
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Patrick Massot -/ import Mathlib.Topology.Basic #align_import topology.nhds_set from "leanprover-community/mathlib"@"f2ce6086713c78a7f880485f7917ea547a215982" /-! # Neighborhoods of a set In this file we define the filter `𝓝ˢ s` or `nhdsSet s` consisting of all neighborhoods of a set `s`. ## Main Properties There are a couple different notions equivalent to `s ∈ 𝓝ˢ t`: * `s ⊆ interior t` using `subset_interior_iff_mem_nhdsSet` * `∀ x : X, x ∈ t → s ∈ 𝓝 x` using `mem_nhdsSet_iff_forall` * `∃ U : Set X, IsOpen U ∧ t ⊆ U ∧ U ⊆ s` using `mem_nhdsSet_iff_exists` Furthermore, we have the following results: * `monotone_nhdsSet`: `𝓝ˢ` is monotone * In T₁-spaces, `𝓝ˢ`is strictly monotone and hence injective: `strict_mono_nhdsSet`/`injective_nhdsSet`. These results are in `Mathlib.Topology.Separation`. -/ open Set Filter Topology variable {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y] {f : Filter X} {s t s₁ s₂ t₁ t₂ : Set X} {x : X} theorem nhdsSet_diagonal (X) [TopologicalSpace (X × X)] : 𝓝ˢ (diagonal X) = ⨆ (x : X), 𝓝 (x, x) := by rw [nhdsSet, ← range_diag, ← range_comp] rfl #align nhds_set_diagonal nhdsSet_diagonal theorem mem_nhdsSet_iff_forall : s ∈ 𝓝ˢ t ↔ ∀ x : X, x ∈ t → s ∈ 𝓝 x := by simp_rw [nhdsSet, Filter.mem_sSup, forall_mem_image] #align mem_nhds_set_iff_forall mem_nhdsSet_iff_forall lemma nhdsSet_le : 𝓝ˢ s ≤ f ↔ ∀ x ∈ s, 𝓝 x ≤ f := by simp [nhdsSet] theorem bUnion_mem_nhdsSet {t : X → Set X} (h : ∀ x ∈ s, t x ∈ 𝓝 x) : (⋃ x ∈ s, t x) ∈ 𝓝ˢ s := mem_nhdsSet_iff_forall.2 fun x hx => mem_of_superset (h x hx) <| subset_iUnion₂ (s := fun x _ => t x) x hx -- Porting note: fails to find `s` #align bUnion_mem_nhds_set bUnion_mem_nhdsSet theorem subset_interior_iff_mem_nhdsSet : s ⊆ interior t ↔ t ∈ 𝓝ˢ s := by simp_rw [mem_nhdsSet_iff_forall, subset_interior_iff_nhds] #align subset_interior_iff_mem_nhds_set subset_interior_iff_mem_nhdsSet theorem disjoint_principal_nhdsSet : Disjoint (𝓟 s) (𝓝ˢ t) ↔ Disjoint (closure s) t := by rw [disjoint_principal_left, ← subset_interior_iff_mem_nhdsSet, interior_compl, subset_compl_iff_disjoint_left] theorem disjoint_nhdsSet_principal : Disjoint (𝓝ˢ s) (𝓟 t) ↔ Disjoint s (closure t) := by rw [disjoint_comm, disjoint_principal_nhdsSet, disjoint_comm] theorem mem_nhdsSet_iff_exists : s ∈ 𝓝ˢ t ↔ ∃ U : Set X, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := by rw [← subset_interior_iff_mem_nhdsSet, subset_interior_iff] #align mem_nhds_set_iff_exists mem_nhdsSet_iff_exists /-- A proposition is true on a set neighborhood of `s` iff it is true on a larger open set -/ theorem eventually_nhdsSet_iff_exists {p : X → Prop} : (∀ᶠ x in 𝓝ˢ s, p x) ↔ ∃ t, IsOpen t ∧ s ⊆ t ∧ ∀ x, x ∈ t → p x := mem_nhdsSet_iff_exists /-- A proposition is true on a set neighborhood of `s` iff it is eventually true near each point in the set. -/ theorem eventually_nhdsSet_iff_forall {p : X → Prop} : (∀ᶠ x in 𝓝ˢ s, p x) ↔ ∀ x, x ∈ s → ∀ᶠ y in 𝓝 x, p y := mem_nhdsSet_iff_forall theorem hasBasis_nhdsSet (s : Set X) : (𝓝ˢ s).HasBasis (fun U => IsOpen U ∧ s ⊆ U) fun U => U := ⟨fun t => by simp [mem_nhdsSet_iff_exists, and_assoc]⟩ #align has_basis_nhds_set hasBasis_nhdsSet @[simp] lemma lift'_nhdsSet_interior (s : Set X) : (𝓝ˢ s).lift' interior = 𝓝ˢ s := (hasBasis_nhdsSet s).lift'_interior_eq_self fun _ ↦ And.left lemma Filter.HasBasis.nhdsSet_interior {ι : Sort*} {p : ι → Prop} {s : ι → Set X} {t : Set X} (h : (𝓝ˢ t).HasBasis p s) : (𝓝ˢ t).HasBasis p (interior <| s ·) := lift'_nhdsSet_interior t ▸ h.lift'_interior theorem IsOpen.mem_nhdsSet (hU : IsOpen s) : s ∈ 𝓝ˢ t ↔ t ⊆ s := by rw [← subset_interior_iff_mem_nhdsSet, hU.interior_eq] #align is_open.mem_nhds_set IsOpen.mem_nhdsSet /-- An open set belongs to its own set neighborhoods filter. -/ theorem IsOpen.mem_nhdsSet_self (ho : IsOpen s) : s ∈ 𝓝ˢ s := ho.mem_nhdsSet.mpr Subset.rfl theorem principal_le_nhdsSet : 𝓟 s ≤ 𝓝ˢ s := fun _s hs => (subset_interior_iff_mem_nhdsSet.mpr hs).trans interior_subset #align principal_le_nhds_set principal_le_nhdsSet theorem subset_of_mem_nhdsSet (h : t ∈ 𝓝ˢ s) : s ⊆ t := principal_le_nhdsSet h theorem Filter.Eventually.self_of_nhdsSet {p : X → Prop} (h : ∀ᶠ x in 𝓝ˢ s, p x) : ∀ x ∈ s, p x := principal_le_nhdsSet h nonrec theorem Filter.EventuallyEq.self_of_nhdsSet {f g : X → Y} (h : f =ᶠ[𝓝ˢ s] g) : EqOn f g s := h.self_of_nhdsSet @[simp] theorem nhdsSet_eq_principal_iff : 𝓝ˢ s = 𝓟 s ↔ IsOpen s := by rw [← principal_le_nhdsSet.le_iff_eq, le_principal_iff, mem_nhdsSet_iff_forall, isOpen_iff_mem_nhds] #align nhds_set_eq_principal_iff nhdsSet_eq_principal_iff alias ⟨_, IsOpen.nhdsSet_eq⟩ := nhdsSet_eq_principal_iff #align is_open.nhds_set_eq IsOpen.nhdsSet_eq @[simp] theorem nhdsSet_interior : 𝓝ˢ (interior s) = 𝓟 (interior s) := isOpen_interior.nhdsSet_eq #align nhds_set_interior nhdsSet_interior @[simp]
Mathlib/Topology/NhdsSet.lean
124
124
theorem nhdsSet_singleton : 𝓝ˢ {x} = 𝓝 x := by
simp [nhdsSet]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Geometry.Euclidean.Angle.Oriented.Affine import Mathlib.Geometry.Euclidean.Angle.Unoriented.RightAngle #align_import geometry.euclidean.angle.oriented.right_angle from "leanprover-community/mathlib"@"46b633fd842bef9469441c0209906f6dddd2b4f5" /-! # Oriented angles in right-angled triangles. This file proves basic geometrical results about distances and oriented angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace Orientation open FiniteDimensional variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] variable [hd2 : Fact (finrank ℝ V = 2)] (o : Orientation ℝ V (Fin 2)) /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arccos (‖x‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arccos_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arccos (‖y‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arccos_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arccos_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arcsin (‖y‖ / ‖x + y‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arcsin_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arcsin (‖x‖ / ‖x + y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arcsin_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arcsin_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle x (x + y) = Real.arctan (‖y‖ / ‖x‖) := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_add_eq_arctan_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (o.left_ne_zero_of_oangle_eq_pi_div_two h)] #align orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle (x + y) y = Real.arctan (‖x‖ / ‖y‖) := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).oangle_add_right_eq_arctan_of_oangle_eq_pi_div_two h #align orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two Orientation.oangle_add_left_eq_arctan_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) = ‖x‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) = ‖y‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) = ‖y‖ / ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) = ‖x‖ / ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) = ‖y‖ / ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) = ‖x‖ / ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle x (x + y)) * ‖x + y‖ = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.cos_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.cos (o.oangle (x + y) y) * ‖x + y‖ = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).cos_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.cos_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle x (x + y)) * ‖x + y‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.sin_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h)] #align orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.sin (o.oangle (x + y) y) * ‖x + y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).sin_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.sin_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle x (x + y)) * ‖x‖ = ‖y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.tan_angle_add_mul_norm_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : Real.Angle.tan (o.oangle (x + y) y) * ‖y‖ = ‖x‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).tan_oangle_add_right_mul_norm_of_oangle_eq_pi_div_two h #align orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two Orientation.tan_oangle_add_left_mul_norm_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.cos (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.cos_coe, InnerProductGeometry.norm_div_cos_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inl (o.left_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.cos (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_cos_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_cos_oangle_add_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.sin (o.oangle x (x + y)) = ‖x + y‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.sin_coe, InnerProductGeometry.norm_div_sin_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.sin (o.oangle (x + y) y) = ‖x + y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_sin_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_sin_oangle_add_left_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖y‖ / Real.Angle.tan (o.oangle x (x + y)) = ‖x‖ := by have hs : (o.oangle x (x + y)).sign = 1 := by rw [oangle_sign_add_right, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, Real.Angle.tan_coe, InnerProductGeometry.norm_div_tan_angle_add_of_inner_eq_zero (o.inner_eq_zero_of_oangle_eq_pi_div_two h) (Or.inr (o.right_ne_zero_of_oangle_eq_pi_div_two h))] #align orientation.norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two Orientation.norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : ‖x‖ / Real.Angle.tan (o.oangle (x + y) y) = ‖y‖ := by rw [← neg_inj, oangle_rev, ← oangle_neg_orientation_eq_neg, neg_inj] at h ⊢ rw [add_comm] exact (-o).norm_div_tan_oangle_add_right_of_oangle_eq_pi_div_two h #align orientation.norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two Orientation.norm_div_tan_oangle_add_left_of_oangle_eq_pi_div_two /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/
Mathlib/Geometry/Euclidean/Angle/Oriented/RightAngle.lean
267
273
theorem oangle_sub_right_eq_arccos_of_oangle_eq_pi_div_two {x y : V} (h : o.oangle x y = ↑(π / 2)) : o.oangle y (y - x) = Real.arccos (‖y‖ / ‖y - x‖) := by
have hs : (o.oangle y (y - x)).sign = 1 := by rw [oangle_sign_sub_right_swap, h, Real.Angle.sign_coe_pi_div_two] rw [o.oangle_eq_angle_of_sign_eq_one hs, InnerProductGeometry.angle_sub_eq_arccos_of_inner_eq_zero (o.inner_rev_eq_zero_of_oangle_eq_pi_div_two h)]
/- Copyright (c) 2017 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Scott Morrison, Mario Carneiro, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.EpiMono import Mathlib.Topology.Category.TopCat.Limits.Basic import Mathlib.CategoryTheory.Limits.Shapes.Products import Mathlib.CategoryTheory.Limits.ConcreteCategory import Mathlib.Data.Set.Subsingleton import Mathlib.Tactic.CategoryTheory.Elementwise #align_import topology.category.Top.limits.products from "leanprover-community/mathlib"@"178a32653e369dce2da68dc6b2694e385d484ef1" /-! # Products and coproducts in the category of topological spaces -/ -- Porting note: every ML3 decl has an uppercase letter set_option linter.uppercaseLean3 false open TopologicalSpace open CategoryTheory open CategoryTheory.Limits universe v u w noncomputable section namespace TopCat variable {J : Type v} [SmallCategory J] /-- The projection from the product as a bundled continuous map. -/ abbrev piπ {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : TopCat.of (∀ i, α i) ⟶ α i := ⟨fun f => f i, continuous_apply i⟩ #align Top.pi_π TopCat.piπ /-- The explicit fan of a family of topological spaces given by the pi type. -/ @[simps! pt π_app] def piFan {ι : Type v} (α : ι → TopCat.{max v u}) : Fan α := Fan.mk (TopCat.of (∀ i, α i)) (piπ.{v,u} α) #align Top.pi_fan TopCat.piFan /-- The constructed fan is indeed a limit -/ def piFanIsLimit {ι : Type v} (α : ι → TopCat.{max v u}) : IsLimit (piFan α) where lift S := { toFun := fun s i => S.π.app ⟨i⟩ s continuous_toFun := continuous_pi (fun i => (S.π.app ⟨i⟩).2) } uniq := by intro S m h apply ContinuousMap.ext; intro x funext i set_option tactic.skipAssignedInstances false in dsimp rw [ContinuousMap.coe_mk, ← h ⟨i⟩] rfl fac s j := rfl #align Top.pi_fan_is_limit TopCat.piFanIsLimit /-- The product is homeomorphic to the product of the underlying spaces, equipped with the product topology. -/ def piIsoPi {ι : Type v} (α : ι → TopCat.{max v u}) : ∏ᶜ α ≅ TopCat.of (∀ i, α i) := (limit.isLimit _).conePointUniqueUpToIso (piFanIsLimit.{v, u} α) -- Specifying the universes in `piFanIsLimit` wasn't necessary when we had `TopCatMax`  #align Top.pi_iso_pi TopCat.piIsoPi @[reassoc (attr := simp)] theorem piIsoPi_inv_π {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : (piIsoPi α).inv ≫ Pi.π α i = piπ α i := by simp [piIsoPi] #align Top.pi_iso_pi_inv_π TopCat.piIsoPi_inv_π theorem piIsoPi_inv_π_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : ∀ i, α i) : (Pi.π α i : _) ((piIsoPi α).inv x) = x i := ConcreteCategory.congr_hom (piIsoPi_inv_π α i) x #align Top.pi_iso_pi_inv_π_apply TopCat.piIsoPi_inv_π_apply -- Porting note: needing the type ascription on `∏ᶜ α : TopCat.{max v u}` is unfortunate. theorem piIsoPi_hom_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : (∏ᶜ α : TopCat.{max v u})) : (piIsoPi α).hom x i = (Pi.π α i : _) x := by have := piIsoPi_inv_π α i rw [Iso.inv_comp_eq] at this exact ConcreteCategory.congr_hom this x #align Top.pi_iso_pi_hom_apply TopCat.piIsoPi_hom_apply -- Porting note: Lean doesn't automatically reduce TopCat.of X|>.α to X now /-- The inclusion to the coproduct as a bundled continuous map. -/ abbrev sigmaι {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : α i ⟶ TopCat.of (Σi, α i) := by refine ContinuousMap.mk ?_ ?_ · dsimp apply Sigma.mk i · dsimp; continuity #align Top.sigma_ι TopCat.sigmaι /-- The explicit cofan of a family of topological spaces given by the sigma type. -/ @[simps! pt ι_app] def sigmaCofan {ι : Type v} (α : ι → TopCat.{max v u}) : Cofan α := Cofan.mk (TopCat.of (Σi, α i)) (sigmaι α) #align Top.sigma_cofan TopCat.sigmaCofan /-- The constructed cofan is indeed a colimit -/ def sigmaCofanIsColimit {ι : Type v} (β : ι → TopCat.{max v u}) : IsColimit (sigmaCofan β) where desc S := { toFun := fun (s : of (Σ i, β i)) => S.ι.app ⟨s.1⟩ s.2 continuous_toFun := continuous_sigma fun i => (S.ι.app ⟨i⟩).continuous_toFun } uniq := by intro S m h ext ⟨i, x⟩ simp only [hom_apply, ← h] congr fac s j := by cases j aesop_cat #align Top.sigma_cofan_is_colimit TopCat.sigmaCofanIsColimit /-- The coproduct is homeomorphic to the disjoint union of the topological spaces. -/ def sigmaIsoSigma {ι : Type v} (α : ι → TopCat.{max v u}) : ∐ α ≅ TopCat.of (Σi, α i) := (colimit.isColimit _).coconePointUniqueUpToIso (sigmaCofanIsColimit.{v, u} α) -- Specifying the universes in `sigmaCofanIsColimit` wasn't necessary when we had `TopCatMax`  #align Top.sigma_iso_sigma TopCat.sigmaIsoSigma @[reassoc (attr := simp)] theorem sigmaIsoSigma_hom_ι {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) : Sigma.ι α i ≫ (sigmaIsoSigma α).hom = sigmaι α i := by simp [sigmaIsoSigma] #align Top.sigma_iso_sigma_hom_ι TopCat.sigmaIsoSigma_hom_ι theorem sigmaIsoSigma_hom_ι_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : α i) : (sigmaIsoSigma α).hom ((Sigma.ι α i : _) x) = Sigma.mk i x := ConcreteCategory.congr_hom (sigmaIsoSigma_hom_ι α i) x #align Top.sigma_iso_sigma_hom_ι_apply TopCat.sigmaIsoSigma_hom_ι_apply theorem sigmaIsoSigma_inv_apply {ι : Type v} (α : ι → TopCat.{max v u}) (i : ι) (x : α i) : (sigmaIsoSigma α).inv ⟨i, x⟩ = (Sigma.ι α i : _) x := by rw [← sigmaIsoSigma_hom_ι_apply, ← comp_app, ← comp_app, Iso.hom_inv_id, Category.comp_id] #align Top.sigma_iso_sigma_inv_apply TopCat.sigmaIsoSigma_inv_apply -- Porting note: cannot use .topologicalSpace in place .str theorem induced_of_isLimit {F : J ⥤ TopCat.{max v u}} (C : Cone F) (hC : IsLimit C) : C.pt.str = ⨅ j, (F.obj j).str.induced (C.π.app j) := by let homeo := homeoOfIso (hC.conePointUniqueUpToIso (limitConeInfiIsLimit F)) refine homeo.inducing.induced.trans ?_ change induced homeo (⨅ j : J, _) = _ simp [induced_iInf, induced_compose] rfl #align Top.induced_of_is_limit TopCat.induced_of_isLimit theorem limit_topology (F : J ⥤ TopCat.{max v u}) : (limit F).str = ⨅ j, (F.obj j).str.induced (limit.π F j) := induced_of_isLimit _ (limit.isLimit F) #align Top.limit_topology TopCat.limit_topology section Prod -- Porting note: why is autoParam not firing? /-- The first projection from the product. -/ abbrev prodFst {X Y : TopCat.{u}} : TopCat.of (X × Y) ⟶ X := ⟨Prod.fst, by continuity⟩ #align Top.prod_fst TopCat.prodFst /-- The second projection from the product. -/ abbrev prodSnd {X Y : TopCat.{u}} : TopCat.of (X × Y) ⟶ Y := ⟨Prod.snd, by continuity⟩ #align Top.prod_snd TopCat.prodSnd /-- The explicit binary cofan of `X, Y` given by `X × Y`. -/ def prodBinaryFan (X Y : TopCat.{u}) : BinaryFan X Y := BinaryFan.mk prodFst prodSnd #align Top.prod_binary_fan TopCat.prodBinaryFan /-- The constructed binary fan is indeed a limit -/ def prodBinaryFanIsLimit (X Y : TopCat.{u}) : IsLimit (prodBinaryFan X Y) where lift := fun S : BinaryFan X Y => { toFun := fun s => (S.fst s, S.snd s) -- Porting note: continuity failed again here. Lean cannot infer -- ContinuousMapClass (X ⟶ Y) X Y for X Y : TopCat which may be one of the problems continuous_toFun := Continuous.prod_mk (BinaryFan.fst S).continuous_toFun (BinaryFan.snd S).continuous_toFun } fac := by rintro S (_ | _) <;> {dsimp; ext; rfl} uniq := by intro S m h -- Porting note: used to be `ext x` refine ContinuousMap.ext (fun (x : ↥(S.pt)) => Prod.ext ?_ ?_) · specialize h ⟨WalkingPair.left⟩ apply_fun fun e => e x at h exact h · specialize h ⟨WalkingPair.right⟩ apply_fun fun e => e x at h exact h #align Top.prod_binary_fan_is_limit TopCat.prodBinaryFanIsLimit /-- The homeomorphism between `X ⨯ Y` and the set-theoretic product of `X` and `Y`, equipped with the product topology. -/ def prodIsoProd (X Y : TopCat.{u}) : X ⨯ Y ≅ TopCat.of (X × Y) := (limit.isLimit _).conePointUniqueUpToIso (prodBinaryFanIsLimit X Y) #align Top.prod_iso_prod TopCat.prodIsoProd @[reassoc (attr := simp)] theorem prodIsoProd_hom_fst (X Y : TopCat.{u}) : (prodIsoProd X Y).hom ≫ prodFst = Limits.prod.fst := by simp [← Iso.eq_inv_comp, prodIsoProd] rfl #align Top.prod_iso_prod_hom_fst TopCat.prodIsoProd_hom_fst @[reassoc (attr := simp)] theorem prodIsoProd_hom_snd (X Y : TopCat.{u}) : (prodIsoProd X Y).hom ≫ prodSnd = Limits.prod.snd := by simp [← Iso.eq_inv_comp, prodIsoProd] rfl #align Top.prod_iso_prod_hom_snd TopCat.prodIsoProd_hom_snd -- Porting note: need to force Lean to coerce X × Y to a type theorem prodIsoProd_hom_apply {X Y : TopCat.{u}} (x : ↑ (X ⨯ Y)) : (prodIsoProd X Y).hom x = ((Limits.prod.fst : X ⨯ Y ⟶ _) x, (Limits.prod.snd : X ⨯ Y ⟶ _) x) := by -- Porting note: ext didn't pick this up apply Prod.ext · exact ConcreteCategory.congr_hom (prodIsoProd_hom_fst X Y) x · exact ConcreteCategory.congr_hom (prodIsoProd_hom_snd X Y) x #align Top.prod_iso_prod_hom_apply TopCat.prodIsoProd_hom_apply @[reassoc (attr := simp), elementwise] theorem prodIsoProd_inv_fst (X Y : TopCat.{u}) : (prodIsoProd X Y).inv ≫ Limits.prod.fst = prodFst := by simp [Iso.inv_comp_eq] #align Top.prod_iso_prod_inv_fst TopCat.prodIsoProd_inv_fst @[reassoc (attr := simp), elementwise] theorem prodIsoProd_inv_snd (X Y : TopCat.{u}) : (prodIsoProd X Y).inv ≫ Limits.prod.snd = prodSnd := by simp [Iso.inv_comp_eq] #align Top.prod_iso_prod_inv_snd TopCat.prodIsoProd_inv_snd theorem prod_topology {X Y : TopCat.{u}} : (X ⨯ Y).str = induced (Limits.prod.fst : X ⨯ Y ⟶ _) X.str ⊓ induced (Limits.prod.snd : X ⨯ Y ⟶ _) Y.str := by let homeo := homeoOfIso (prodIsoProd X Y) refine homeo.inducing.induced.trans ?_ change induced homeo (_ ⊓ _) = _ simp [induced_compose] rfl #align Top.prod_topology TopCat.prod_topology
Mathlib/Topology/Category/TopCat/Limits/Products.lean
249
276
theorem range_prod_map {W X Y Z : TopCat.{u}} (f : W ⟶ Y) (g : X ⟶ Z) : Set.range (Limits.prod.map f g) = (Limits.prod.fst : Y ⨯ Z ⟶ _) ⁻¹' Set.range f ∩ (Limits.prod.snd : Y ⨯ Z ⟶ _) ⁻¹' Set.range g := by
ext x constructor · rintro ⟨y, rfl⟩ simp_rw [Set.mem_inter_iff, Set.mem_preimage, Set.mem_range] -- sizable changes in this proof after #13170 erw [← comp_apply, ← comp_apply] simp_rw [Limits.prod.map_fst, Limits.prod.map_snd, comp_apply] exact ⟨exists_apply_eq_apply _ _, exists_apply_eq_apply _ _⟩ · rintro ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩⟩ use (prodIsoProd W X).inv (x₁, x₂) change (forget TopCat).map _ _ = _ apply Concrete.limit_ext rintro ⟨⟨⟩⟩ · change limit.π (pair Y Z) _ ((prod.map f g) _) = _ erw [← comp_apply, Limits.prod.map_fst] change (_ ≫ _ ≫ f) _ = _ erw [TopCat.prodIsoProd_inv_fst_assoc,TopCat.comp_app] exact hx₁ · change limit.π (pair Y Z) _ ((prod.map f g) _) = _ erw [← comp_apply, Limits.prod.map_snd] change (_ ≫ _ ≫ g) _ = _ erw [TopCat.prodIsoProd_inv_snd_assoc,TopCat.comp_app] exact hx₂
/- Copyright (c) 2022 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Yaël Dillies -/ import Mathlib.LinearAlgebra.Ray import Mathlib.Analysis.NormedSpace.Real #align_import analysis.normed_space.ray from "leanprover-community/mathlib"@"92ca63f0fb391a9ca5f22d2409a6080e786d99f7" /-! # Rays in a real normed vector space In this file we prove some lemmas about the `SameRay` predicate in case of a real normed space. In this case, for two vectors `x y` in the same ray, the norm of their sum is equal to the sum of their norms and `‖y‖ • x = ‖x‖ • y`. -/ open Real variable {E : Type*} [SeminormedAddCommGroup E] [NormedSpace ℝ E] {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] namespace SameRay variable {x y : E} /-- If `x` and `y` are on the same ray, then the triangle inequality becomes the equality: the norm of `x + y` is the sum of the norms of `x` and `y`. The converse is true for a strictly convex space. -/ theorem norm_add (h : SameRay ℝ x y) : ‖x + y‖ = ‖x‖ + ‖y‖ := by rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩ rw [← add_smul, norm_smul_of_nonneg (add_nonneg ha hb), norm_smul_of_nonneg ha, norm_smul_of_nonneg hb, add_mul] #align same_ray.norm_add SameRay.norm_add
Mathlib/Analysis/NormedSpace/Ray.lean
38
46
theorem norm_sub (h : SameRay ℝ x y) : ‖x - y‖ = |‖x‖ - ‖y‖| := by
rcases h.exists_eq_smul with ⟨u, a, b, ha, hb, -, rfl, rfl⟩ wlog hab : b ≤ a generalizing a b with H · rw [SameRay.sameRay_comm] at h rw [norm_sub_rev, abs_sub_comm] exact H b a hb ha h (le_of_not_le hab) rw [← sub_nonneg] at hab rw [← sub_smul, norm_smul_of_nonneg hab, norm_smul_of_nonneg ha, norm_smul_of_nonneg hb, ← sub_mul, abs_of_nonneg (mul_nonneg hab (norm_nonneg _))]
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Group.Commute.Hom import Mathlib.Data.Fintype.Card #align_import data.finset.noncomm_prod from "leanprover-community/mathlib"@"509de852e1de55e1efa8eacfa11df0823f26f226" /-! # Products (respectively, sums) over a finset or a multiset. The regular `Finset.prod` and `Multiset.prod` require `[CommMonoid α]`. Often, there are collections `s : Finset α` where `[Monoid α]` and we know, in a dependent fashion, that for all the terms `∀ (x ∈ s) (y ∈ s), Commute x y`. This allows to still have a well-defined product over `s`. ## Main definitions - `Finset.noncommProd`, requiring a proof of commutativity of held terms - `Multiset.noncommProd`, requiring a proof of commutativity of held terms ## Implementation details While `List.prod` is defined via `List.foldl`, `noncommProd` is defined via `Multiset.foldr` for neater proofs and definitions. By the commutativity assumption, the two must be equal. TODO: Tidy up this file by using the fact that the submonoid generated by commuting elements is commutative and using the `Finset.prod` versions of lemmas to prove the `noncommProd` version. -/ variable {F ι α β γ : Type*} (f : α → β → β) (op : α → α → α) namespace Multiset /-- Fold of a `s : Multiset α` with `f : α → β → β`, given a proof that `LeftCommutative f` on all elements `x ∈ s`. -/ def noncommFoldr (s : Multiset α) (comm : { x | x ∈ s }.Pairwise fun x y => ∀ b, f x (f y b) = f y (f x b)) (b : β) : β := s.attach.foldr (f ∘ Subtype.val) (fun ⟨_, hx⟩ ⟨_, hy⟩ => haveI : IsRefl α fun x y => ∀ b, f x (f y b) = f y (f x b) := ⟨fun _ _ => rfl⟩ comm.of_refl hx hy) b #align multiset.noncomm_foldr Multiset.noncommFoldr @[simp] theorem noncommFoldr_coe (l : List α) (comm) (b : β) : noncommFoldr f (l : Multiset α) comm b = l.foldr f b := by simp only [noncommFoldr, coe_foldr, coe_attach, List.attach, List.attachWith, Function.comp] rw [← List.foldr_map] simp [List.map_pmap] #align multiset.noncomm_foldr_coe Multiset.noncommFoldr_coe @[simp] theorem noncommFoldr_empty (h) (b : β) : noncommFoldr f (0 : Multiset α) h b = b := rfl #align multiset.noncomm_foldr_empty Multiset.noncommFoldr_empty theorem noncommFoldr_cons (s : Multiset α) (a : α) (h h') (b : β) : noncommFoldr f (a ::ₘ s) h b = f a (noncommFoldr f s h' b) := by induction s using Quotient.inductionOn simp #align multiset.noncomm_foldr_cons Multiset.noncommFoldr_cons theorem noncommFoldr_eq_foldr (s : Multiset α) (h : LeftCommutative f) (b : β) : noncommFoldr f s (fun x _ y _ _ => h x y) b = foldr f h b s := by induction s using Quotient.inductionOn simp #align multiset.noncomm_foldr_eq_foldr Multiset.noncommFoldr_eq_foldr section assoc variable [assoc : Std.Associative op] /-- Fold of a `s : Multiset α` with an associative `op : α → α → α`, given a proofs that `op` is commutative on all elements `x ∈ s`. -/ def noncommFold (s : Multiset α) (comm : { x | x ∈ s }.Pairwise fun x y => op x y = op y x) : α → α := noncommFoldr op s fun x hx y hy h b => by rw [← assoc.assoc, comm hx hy h, assoc.assoc] #align multiset.noncomm_fold Multiset.noncommFold @[simp] theorem noncommFold_coe (l : List α) (comm) (a : α) : noncommFold op (l : Multiset α) comm a = l.foldr op a := by simp [noncommFold] #align multiset.noncomm_fold_coe Multiset.noncommFold_coe @[simp] theorem noncommFold_empty (h) (a : α) : noncommFold op (0 : Multiset α) h a = a := rfl #align multiset.noncomm_fold_empty Multiset.noncommFold_empty theorem noncommFold_cons (s : Multiset α) (a : α) (h h') (x : α) : noncommFold op (a ::ₘ s) h x = op a (noncommFold op s h' x) := by induction s using Quotient.inductionOn simp #align multiset.noncomm_fold_cons Multiset.noncommFold_cons theorem noncommFold_eq_fold (s : Multiset α) [Std.Commutative op] (a : α) : noncommFold op s (fun x _ y _ _ => Std.Commutative.comm x y) a = fold op a s := by induction s using Quotient.inductionOn simp #align multiset.noncomm_fold_eq_fold Multiset.noncommFold_eq_fold end assoc variable [Monoid α] [Monoid β] /-- Product of a `s : Multiset α` with `[Monoid α]`, given a proof that `*` commutes on all elements `x ∈ s`. -/ @[to_additive "Sum of a `s : Multiset α` with `[AddMonoid α]`, given a proof that `+` commutes on all elements `x ∈ s`."] def noncommProd (s : Multiset α) (comm : { x | x ∈ s }.Pairwise Commute) : α := s.noncommFold (· * ·) comm 1 #align multiset.noncomm_prod Multiset.noncommProd #align multiset.noncomm_sum Multiset.noncommSum @[to_additive (attr := simp)] theorem noncommProd_coe (l : List α) (comm) : noncommProd (l : Multiset α) comm = l.prod := by rw [noncommProd] simp only [noncommFold_coe] induction' l with hd tl hl · simp · rw [List.prod_cons, List.foldr, hl] intro x hx y hy exact comm (List.mem_cons_of_mem _ hx) (List.mem_cons_of_mem _ hy) #align multiset.noncomm_prod_coe Multiset.noncommProd_coe #align multiset.noncomm_sum_coe Multiset.noncommSum_coe @[to_additive (attr := simp)] theorem noncommProd_empty (h) : noncommProd (0 : Multiset α) h = 1 := rfl #align multiset.noncomm_prod_empty Multiset.noncommProd_empty #align multiset.noncomm_sum_empty Multiset.noncommSum_empty @[to_additive (attr := simp)] theorem noncommProd_cons (s : Multiset α) (a : α) (comm) : noncommProd (a ::ₘ s) comm = a * noncommProd s (comm.mono fun _ => mem_cons_of_mem) := by induction s using Quotient.inductionOn simp #align multiset.noncomm_prod_cons Multiset.noncommProd_cons #align multiset.noncomm_sum_cons Multiset.noncommSum_cons @[to_additive] theorem noncommProd_cons' (s : Multiset α) (a : α) (comm) : noncommProd (a ::ₘ s) comm = noncommProd s (comm.mono fun _ => mem_cons_of_mem) * a := by induction' s using Quotient.inductionOn with s simp only [quot_mk_to_coe, cons_coe, noncommProd_coe, List.prod_cons] induction' s with hd tl IH · simp · rw [List.prod_cons, mul_assoc, ← IH, ← mul_assoc, ← mul_assoc] · congr 1 apply comm.of_refl <;> simp · intro x hx y hy simp only [quot_mk_to_coe, List.mem_cons, mem_coe, cons_coe] at hx hy apply comm · cases hx <;> simp [*] · cases hy <;> simp [*] #align multiset.noncomm_prod_cons' Multiset.noncommProd_cons' #align multiset.noncomm_sum_cons' Multiset.noncommSum_cons' @[to_additive] theorem noncommProd_add (s t : Multiset α) (comm) : noncommProd (s + t) comm = noncommProd s (comm.mono <| subset_of_le <| s.le_add_right t) * noncommProd t (comm.mono <| subset_of_le <| t.le_add_left s) := by rcases s with ⟨⟩ rcases t with ⟨⟩ simp #align multiset.noncomm_prod_add Multiset.noncommProd_add #align multiset.noncomm_sum_add Multiset.noncommSum_add @[to_additive] lemma noncommProd_induction (s : Multiset α) (comm) (p : α → Prop) (hom : ∀ a b, p a → p b → p (a * b)) (unit : p 1) (base : ∀ x ∈ s, p x) : p (s.noncommProd comm) := by induction' s using Quotient.inductionOn with l simp only [quot_mk_to_coe, noncommProd_coe, mem_coe] at base ⊢ exact l.prod_induction p hom unit base variable [FunLike F α β] @[to_additive] protected theorem noncommProd_map_aux [MonoidHomClass F α β] (s : Multiset α) (comm : { x | x ∈ s }.Pairwise Commute) (f : F) : { x | x ∈ s.map f }.Pairwise Commute := by simp only [Multiset.mem_map] rintro _ ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩ _ exact (comm.of_refl hx hy).map f #align multiset.noncomm_prod_map_aux Multiset.noncommProd_map_aux #align multiset.noncomm_sum_map_aux Multiset.noncommSum_map_aux @[to_additive] theorem noncommProd_map [MonoidHomClass F α β] (s : Multiset α) (comm) (f : F) : f (s.noncommProd comm) = (s.map f).noncommProd (Multiset.noncommProd_map_aux s comm f) := by induction s using Quotient.inductionOn simpa using map_list_prod f _ #align multiset.noncomm_prod_map Multiset.noncommProd_map #align multiset.noncomm_sum_map Multiset.noncommSum_map @[to_additive noncommSum_eq_card_nsmul] theorem noncommProd_eq_pow_card (s : Multiset α) (comm) (m : α) (h : ∀ x ∈ s, x = m) : s.noncommProd comm = m ^ Multiset.card s := by induction s using Quotient.inductionOn simp only [quot_mk_to_coe, noncommProd_coe, coe_card, mem_coe] at * exact List.prod_eq_pow_card _ m h #align multiset.noncomm_prod_eq_pow_card Multiset.noncommProd_eq_pow_card #align multiset.noncomm_sum_eq_card_nsmul Multiset.noncommSum_eq_card_nsmul @[to_additive] theorem noncommProd_eq_prod {α : Type*} [CommMonoid α] (s : Multiset α) : (noncommProd s fun _ _ _ _ _ => Commute.all _ _) = prod s := by induction s using Quotient.inductionOn simp #align multiset.noncomm_prod_eq_prod Multiset.noncommProd_eq_prod #align multiset.noncomm_sum_eq_sum Multiset.noncommSum_eq_sum @[to_additive]
Mathlib/Data/Finset/NoncommProd.lean
223
227
theorem noncommProd_commute (s : Multiset α) (comm) (y : α) (h : ∀ x ∈ s, Commute y x) : Commute y (s.noncommProd comm) := by
induction s using Quotient.inductionOn simp only [quot_mk_to_coe, noncommProd_coe] exact Commute.list_prod_right _ _ h
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Image import Mathlib.Data.List.FinRange #align_import data.fintype.basic from "leanprover-community/mathlib"@"d78597269638367c3863d40d45108f52207e03cf" /-! # Finite types This file defines a typeclass to state that a type is finite. ## Main declarations * `Fintype α`: Typeclass saying that a type is finite. It takes as fields a `Finset` and a proof that all terms of type `α` are in it. * `Finset.univ`: The finset of all elements of a fintype. See `Data.Fintype.Card` for the cardinality of a fintype, the equivalence with `Fin (Fintype.card α)`, and pigeonhole principles. ## Instances Instances for `Fintype` for * `{x // p x}` are in this file as `Fintype.subtype` * `Option α` are in `Data.Fintype.Option` * `α × β` are in `Data.Fintype.Prod` * `α ⊕ β` are in `Data.Fintype.Sum` * `Σ (a : α), β a` are in `Data.Fintype.Sigma` These files also contain appropriate `Infinite` instances for these types. `Infinite` instances for `ℕ`, `ℤ`, `Multiset α`, and `List α` are in `Data.Fintype.Lattice`. Types which have a surjection from/an injection to a `Fintype` are themselves fintypes. See `Fintype.ofInjective` and `Fintype.ofSurjective`. -/ assert_not_exists MonoidWithZero assert_not_exists MulAction open Function open Nat universe u v variable {α β γ : Type*} /-- `Fintype α` means that `α` is finite, i.e. there are only finitely many distinct elements of type `α`. The evidence of this is a finset `elems` (a list up to permutation without duplicates), together with a proof that everything of type `α` is in the list. -/ class Fintype (α : Type*) where /-- The `Finset` containing all elements of a `Fintype` -/ elems : Finset α /-- A proof that `elems` contains every element of the type -/ complete : ∀ x : α, x ∈ elems #align fintype Fintype namespace Finset variable [Fintype α] {s t : Finset α} /-- `univ` is the universal finite set of type `Finset α` implied from the assumption `Fintype α`. -/ def univ : Finset α := @Fintype.elems α _ #align finset.univ Finset.univ @[simp] theorem mem_univ (x : α) : x ∈ (univ : Finset α) := Fintype.complete x #align finset.mem_univ Finset.mem_univ -- Porting note: removing @[simp], simp can prove it theorem mem_univ_val : ∀ x, x ∈ (univ : Finset α).1 := mem_univ #align finset.mem_univ_val Finset.mem_univ_val theorem eq_univ_iff_forall : s = univ ↔ ∀ x, x ∈ s := by simp [ext_iff] #align finset.eq_univ_iff_forall Finset.eq_univ_iff_forall theorem eq_univ_of_forall : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 #align finset.eq_univ_of_forall Finset.eq_univ_of_forall @[simp, norm_cast] theorem coe_univ : ↑(univ : Finset α) = (Set.univ : Set α) := by ext; simp #align finset.coe_univ Finset.coe_univ @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = Set.univ ↔ s = univ := by rw [← coe_univ, coe_inj] #align finset.coe_eq_univ Finset.coe_eq_univ
Mathlib/Data/Fintype/Basic.lean
99
101
theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by
rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x]
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne, Sébastien Gouëzel -/ import Mathlib.Analysis.NormedSpace.BoundedLinearMaps import Mathlib.MeasureTheory.Measure.WithDensity import Mathlib.MeasureTheory.Function.SimpleFuncDense import Mathlib.Topology.Algebra.Module.FiniteDimension #align_import measure_theory.function.strongly_measurable.basic from "leanprover-community/mathlib"@"3b52265189f3fb43aa631edffce5d060fafaf82f" /-! # Strongly measurable and finitely strongly measurable functions A function `f` is said to be strongly measurable if `f` is the sequential limit of simple functions. It is said to be finitely strongly measurable with respect to a measure `μ` if the supports of those simple functions have finite measure. We also provide almost everywhere versions of these notions. Almost everywhere strongly measurable functions form the largest class of functions that can be integrated using the Bochner integral. If the target space has a second countable topology, strongly measurable and measurable are equivalent. If the measure is sigma-finite, strongly measurable and finitely strongly measurable are equivalent. The main property of finitely strongly measurable functions is `FinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that the function is supported on `t` and `μ.restrict t` is sigma-finite. As a consequence, we can prove some results for those functions as if the measure was sigma-finite. ## Main definitions * `StronglyMeasurable f`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β`. * `FinStronglyMeasurable f μ`: `f : α → β` is the limit of a sequence `fs : ℕ → SimpleFunc α β` such that for all `n ∈ ℕ`, the measure of the support of `fs n` is finite. * `AEStronglyMeasurable f μ`: `f` is almost everywhere equal to a `StronglyMeasurable` function. * `AEFinStronglyMeasurable f μ`: `f` is almost everywhere equal to a `FinStronglyMeasurable` function. * `AEFinStronglyMeasurable.sigmaFiniteSet`: a measurable set `t` such that `f =ᵐ[μ.restrict tᶜ] 0` and `μ.restrict t` is sigma-finite. ## Main statements * `AEFinStronglyMeasurable.exists_set_sigmaFinite`: there exists a measurable set `t` such that `f =ᵐ[μ.restrict tᶜ] 0` and `μ.restrict t` is sigma-finite. We provide a solid API for strongly measurable functions, and for almost everywhere strongly measurable functions, as a basis for the Bochner integral. ## References * Hytönen, Tuomas, Jan Van Neerven, Mark Veraar, and Lutz Weis. Analysis in Banach spaces. Springer, 2016. -/ open MeasureTheory Filter TopologicalSpace Function Set MeasureTheory.Measure open ENNReal Topology MeasureTheory NNReal variable {α β γ ι : Type*} [Countable ι] namespace MeasureTheory local infixr:25 " →ₛ " => SimpleFunc section Definitions variable [TopologicalSpace β] /-- A function is `StronglyMeasurable` if it is the limit of simple functions. -/ def StronglyMeasurable [MeasurableSpace α] (f : α → β) : Prop := ∃ fs : ℕ → α →ₛ β, ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) #align measure_theory.strongly_measurable MeasureTheory.StronglyMeasurable /-- The notation for StronglyMeasurable giving the measurable space instance explicitly. -/ scoped notation "StronglyMeasurable[" m "]" => @MeasureTheory.StronglyMeasurable _ _ _ m /-- A function is `FinStronglyMeasurable` with respect to a measure if it is the limit of simple functions with support with finite measure. -/ def FinStronglyMeasurable [Zero β] {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ fs : ℕ → α →ₛ β, (∀ n, μ (support (fs n)) < ∞) ∧ ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) #align measure_theory.fin_strongly_measurable MeasureTheory.FinStronglyMeasurable /-- A function is `AEStronglyMeasurable` with respect to a measure `μ` if it is almost everywhere equal to the limit of a sequence of simple functions. -/ def AEStronglyMeasurable {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ g, StronglyMeasurable g ∧ f =ᵐ[μ] g #align measure_theory.ae_strongly_measurable MeasureTheory.AEStronglyMeasurable /-- A function is `AEFinStronglyMeasurable` with respect to a measure if it is almost everywhere equal to the limit of a sequence of simple functions with support with finite measure. -/ def AEFinStronglyMeasurable [Zero β] {_ : MeasurableSpace α} (f : α → β) (μ : Measure α := by volume_tac) : Prop := ∃ g, FinStronglyMeasurable g μ ∧ f =ᵐ[μ] g #align measure_theory.ae_fin_strongly_measurable MeasureTheory.AEFinStronglyMeasurable end Definitions open MeasureTheory /-! ## Strongly measurable functions -/ @[aesop 30% apply (rule_sets := [Measurable])] protected theorem StronglyMeasurable.aestronglyMeasurable {α β} {_ : MeasurableSpace α} [TopologicalSpace β] {f : α → β} {μ : Measure α} (hf : StronglyMeasurable f) : AEStronglyMeasurable f μ := ⟨f, hf, EventuallyEq.refl _ _⟩ #align measure_theory.strongly_measurable.ae_strongly_measurable MeasureTheory.StronglyMeasurable.aestronglyMeasurable @[simp] theorem Subsingleton.stronglyMeasurable {α β} [MeasurableSpace α] [TopologicalSpace β] [Subsingleton β] (f : α → β) : StronglyMeasurable f := by let f_sf : α →ₛ β := ⟨f, fun x => ?_, Set.Subsingleton.finite Set.subsingleton_of_subsingleton⟩ · exact ⟨fun _ => f_sf, fun x => tendsto_const_nhds⟩ · have h_univ : f ⁻¹' {x} = Set.univ := by ext1 y simp [eq_iff_true_of_subsingleton] rw [h_univ] exact MeasurableSet.univ #align measure_theory.subsingleton.strongly_measurable MeasureTheory.Subsingleton.stronglyMeasurable theorem SimpleFunc.stronglyMeasurable {α β} {_ : MeasurableSpace α} [TopologicalSpace β] (f : α →ₛ β) : StronglyMeasurable f := ⟨fun _ => f, fun _ => tendsto_const_nhds⟩ #align measure_theory.simple_func.strongly_measurable MeasureTheory.SimpleFunc.stronglyMeasurable @[nontriviality] theorem StronglyMeasurable.of_finite [Finite α] {_ : MeasurableSpace α} [MeasurableSingletonClass α] [TopologicalSpace β] (f : α → β) : StronglyMeasurable f := ⟨fun _ => SimpleFunc.ofFinite f, fun _ => tendsto_const_nhds⟩ @[deprecated (since := "2024-02-05")] alias stronglyMeasurable_of_fintype := StronglyMeasurable.of_finite @[deprecated StronglyMeasurable.of_finite (since := "2024-02-06")] theorem stronglyMeasurable_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} [TopologicalSpace β] (f : α → β) : StronglyMeasurable f := .of_finite f #align measure_theory.strongly_measurable_of_is_empty MeasureTheory.StronglyMeasurable.of_finite theorem stronglyMeasurable_const {α β} {_ : MeasurableSpace α} [TopologicalSpace β] {b : β} : StronglyMeasurable fun _ : α => b := ⟨fun _ => SimpleFunc.const α b, fun _ => tendsto_const_nhds⟩ #align measure_theory.strongly_measurable_const MeasureTheory.stronglyMeasurable_const @[to_additive] theorem stronglyMeasurable_one {α β} {_ : MeasurableSpace α} [TopologicalSpace β] [One β] : StronglyMeasurable (1 : α → β) := stronglyMeasurable_const #align measure_theory.strongly_measurable_one MeasureTheory.stronglyMeasurable_one #align measure_theory.strongly_measurable_zero MeasureTheory.stronglyMeasurable_zero /-- A version of `stronglyMeasurable_const` that assumes `f x = f y` for all `x, y`. This version works for functions between empty types. -/ theorem stronglyMeasurable_const' {α β} {m : MeasurableSpace α} [TopologicalSpace β] {f : α → β} (hf : ∀ x y, f x = f y) : StronglyMeasurable f := by nontriviality α inhabit α convert stronglyMeasurable_const (β := β) using 1 exact funext fun x => hf x default #align measure_theory.strongly_measurable_const' MeasureTheory.stronglyMeasurable_const' -- Porting note: changed binding type of `MeasurableSpace α`. @[simp] theorem Subsingleton.stronglyMeasurable' {α β} [MeasurableSpace α] [TopologicalSpace β] [Subsingleton α] (f : α → β) : StronglyMeasurable f := stronglyMeasurable_const' fun x y => by rw [Subsingleton.elim x y] #align measure_theory.subsingleton.strongly_measurable' MeasureTheory.Subsingleton.stronglyMeasurable' namespace StronglyMeasurable variable {f g : α → β} section BasicPropertiesInAnyTopologicalSpace variable [TopologicalSpace β] /-- A sequence of simple functions such that `∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x))`. That property is given by `stronglyMeasurable.tendsto_approx`. -/ protected noncomputable def approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ℕ → α →ₛ β := hf.choose #align measure_theory.strongly_measurable.approx MeasureTheory.StronglyMeasurable.approx protected theorem tendsto_approx {_ : MeasurableSpace α} (hf : StronglyMeasurable f) : ∀ x, Tendsto (fun n => hf.approx n x) atTop (𝓝 (f x)) := hf.choose_spec #align measure_theory.strongly_measurable.tendsto_approx MeasureTheory.StronglyMeasurable.tendsto_approx /-- Similar to `stronglyMeasurable.approx`, but enforces that the norm of every function in the sequence is less than `c` everywhere. If `‖f x‖ ≤ c` this sequence of simple functions verifies `Tendsto (fun n => hf.approxBounded n x) atTop (𝓝 (f x))`. -/ noncomputable def approxBounded {_ : MeasurableSpace α} [Norm β] [SMul ℝ β] (hf : StronglyMeasurable f) (c : ℝ) : ℕ → SimpleFunc α β := fun n => (hf.approx n).map fun x => min 1 (c / ‖x‖) • x #align measure_theory.strongly_measurable.approx_bounded MeasureTheory.StronglyMeasurable.approxBounded theorem tendsto_approxBounded_of_norm_le {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} (hf : StronglyMeasurable[m] f) {c : ℝ} {x : α} (hfx : ‖f x‖ ≤ c) : Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by have h_tendsto := hf.tendsto_approx x simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] by_cases hfx0 : ‖f x‖ = 0 · rw [norm_eq_zero] at hfx0 rw [hfx0] at h_tendsto ⊢ have h_tendsto_norm : Tendsto (fun n => ‖hf.approx n x‖) atTop (𝓝 0) := by convert h_tendsto.norm rw [norm_zero] refine squeeze_zero_norm (fun n => ?_) h_tendsto_norm calc ‖min 1 (c / ‖hf.approx n x‖) • hf.approx n x‖ = ‖min 1 (c / ‖hf.approx n x‖)‖ * ‖hf.approx n x‖ := norm_smul _ _ _ ≤ ‖(1 : ℝ)‖ * ‖hf.approx n x‖ := by refine mul_le_mul_of_nonneg_right ?_ (norm_nonneg _) rw [norm_one, Real.norm_of_nonneg] · exact min_le_left _ _ · exact le_min zero_le_one (div_nonneg ((norm_nonneg _).trans hfx) (norm_nonneg _)) _ = ‖hf.approx n x‖ := by rw [norm_one, one_mul] rw [← one_smul ℝ (f x)] refine Tendsto.smul ?_ h_tendsto have : min 1 (c / ‖f x‖) = 1 := by rw [min_eq_left_iff, one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm hfx0))] exact hfx nth_rw 2 [this.symm] refine Tendsto.min tendsto_const_nhds ?_ exact Tendsto.div tendsto_const_nhds h_tendsto.norm hfx0 #align measure_theory.strongly_measurable.tendsto_approx_bounded_of_norm_le MeasureTheory.StronglyMeasurable.tendsto_approxBounded_of_norm_le theorem tendsto_approxBounded_ae {β} {f : α → β} [NormedAddCommGroup β] [NormedSpace ℝ β] {m m0 : MeasurableSpace α} {μ : Measure α} (hf : StronglyMeasurable[m] f) {c : ℝ} (hf_bound : ∀ᵐ x ∂μ, ‖f x‖ ≤ c) : ∀ᵐ x ∂μ, Tendsto (fun n => hf.approxBounded c n x) atTop (𝓝 (f x)) := by filter_upwards [hf_bound] with x hfx using tendsto_approxBounded_of_norm_le hf hfx #align measure_theory.strongly_measurable.tendsto_approx_bounded_ae MeasureTheory.StronglyMeasurable.tendsto_approxBounded_ae theorem norm_approxBounded_le {β} {f : α → β} [SeminormedAddCommGroup β] [NormedSpace ℝ β] {m : MeasurableSpace α} {c : ℝ} (hf : StronglyMeasurable[m] f) (hc : 0 ≤ c) (n : ℕ) (x : α) : ‖hf.approxBounded c n x‖ ≤ c := by simp only [StronglyMeasurable.approxBounded, SimpleFunc.coe_map, Function.comp_apply] refine (norm_smul_le _ _).trans ?_ by_cases h0 : ‖hf.approx n x‖ = 0 · simp only [h0, _root_.div_zero, min_eq_right, zero_le_one, norm_zero, mul_zero] exact hc rcases le_total ‖hf.approx n x‖ c with h | h · rw [min_eq_left _] · simpa only [norm_one, one_mul] using h · rwa [one_le_div (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] · rw [min_eq_right _] · rw [norm_div, norm_norm, mul_comm, mul_div, div_eq_mul_inv, mul_comm, ← mul_assoc, inv_mul_cancel h0, one_mul, Real.norm_of_nonneg hc] · rwa [div_le_one (lt_of_le_of_ne (norm_nonneg _) (Ne.symm h0))] #align measure_theory.strongly_measurable.norm_approx_bounded_le MeasureTheory.StronglyMeasurable.norm_approxBounded_le theorem _root_.stronglyMeasurable_bot_iff [Nonempty β] [T2Space β] : StronglyMeasurable[⊥] f ↔ ∃ c, f = fun _ => c := by cases' isEmpty_or_nonempty α with hα hα · simp only [@Subsingleton.stronglyMeasurable' _ _ ⊥ _ _ f, eq_iff_true_of_subsingleton, exists_const] refine ⟨fun hf => ?_, fun hf_eq => ?_⟩ · refine ⟨f hα.some, ?_⟩ let fs := hf.approx have h_fs_tendsto : ∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x)) := hf.tendsto_approx have : ∀ n, ∃ c, ∀ x, fs n x = c := fun n => SimpleFunc.simpleFunc_bot (fs n) let cs n := (this n).choose have h_cs_eq : ∀ n, ⇑(fs n) = fun _ => cs n := fun n => funext (this n).choose_spec conv at h_fs_tendsto => enter [x, 1, n]; rw [h_cs_eq] have h_tendsto : Tendsto cs atTop (𝓝 (f hα.some)) := h_fs_tendsto hα.some ext1 x exact tendsto_nhds_unique (h_fs_tendsto x) h_tendsto · obtain ⟨c, rfl⟩ := hf_eq exact stronglyMeasurable_const #align strongly_measurable_bot_iff stronglyMeasurable_bot_iff end BasicPropertiesInAnyTopologicalSpace theorem finStronglyMeasurable_of_set_sigmaFinite [TopologicalSpace β] [Zero β] {m : MeasurableSpace α} {μ : Measure α} (hf_meas : StronglyMeasurable f) {t : Set α} (ht : MeasurableSet t) (hft_zero : ∀ x ∈ tᶜ, f x = 0) (htμ : SigmaFinite (μ.restrict t)) : FinStronglyMeasurable f μ := by haveI : SigmaFinite (μ.restrict t) := htμ let S := spanningSets (μ.restrict t) have hS_meas : ∀ n, MeasurableSet (S n) := measurable_spanningSets (μ.restrict t) let f_approx := hf_meas.approx let fs n := SimpleFunc.restrict (f_approx n) (S n ∩ t) have h_fs_t_compl : ∀ n, ∀ x, x ∉ t → fs n x = 0 := by intro n x hxt rw [SimpleFunc.restrict_apply _ ((hS_meas n).inter ht)] refine Set.indicator_of_not_mem ?_ _ simp [hxt] refine ⟨fs, ?_, fun x => ?_⟩ · simp_rw [SimpleFunc.support_eq] refine fun n => (measure_biUnion_finset_le _ _).trans_lt ?_ refine ENNReal.sum_lt_top_iff.mpr fun y hy => ?_ rw [SimpleFunc.restrict_preimage_singleton _ ((hS_meas n).inter ht)] swap · letI : (y : β) → Decidable (y = 0) := fun y => Classical.propDecidable _ rw [Finset.mem_filter] at hy exact hy.2 refine (measure_mono Set.inter_subset_left).trans_lt ?_ have h_lt_top := measure_spanningSets_lt_top (μ.restrict t) n rwa [Measure.restrict_apply' ht] at h_lt_top · by_cases hxt : x ∈ t swap · rw [funext fun n => h_fs_t_compl n x hxt, hft_zero x hxt] exact tendsto_const_nhds have h : Tendsto (fun n => (f_approx n) x) atTop (𝓝 (f x)) := hf_meas.tendsto_approx x obtain ⟨n₁, hn₁⟩ : ∃ n, ∀ m, n ≤ m → fs m x = f_approx m x := by obtain ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m ∩ t := by rsuffices ⟨n, hn⟩ : ∃ n, ∀ m, n ≤ m → x ∈ S m · exact ⟨n, fun m hnm => Set.mem_inter (hn m hnm) hxt⟩ rsuffices ⟨n, hn⟩ : ∃ n, x ∈ S n · exact ⟨n, fun m hnm => monotone_spanningSets (μ.restrict t) hnm hn⟩ rw [← Set.mem_iUnion, iUnion_spanningSets (μ.restrict t)] trivial refine ⟨n, fun m hnm => ?_⟩ simp_rw [fs, SimpleFunc.restrict_apply _ ((hS_meas m).inter ht), Set.indicator_of_mem (hn m hnm)] rw [tendsto_atTop'] at h ⊢ intro s hs obtain ⟨n₂, hn₂⟩ := h s hs refine ⟨max n₁ n₂, fun m hm => ?_⟩ rw [hn₁ m ((le_max_left _ _).trans hm.le)] exact hn₂ m ((le_max_right _ _).trans hm.le) #align measure_theory.strongly_measurable.fin_strongly_measurable_of_set_sigma_finite MeasureTheory.StronglyMeasurable.finStronglyMeasurable_of_set_sigmaFinite /-- If the measure is sigma-finite, all strongly measurable functions are `FinStronglyMeasurable`. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem finStronglyMeasurable [TopologicalSpace β] [Zero β] {m0 : MeasurableSpace α} (hf : StronglyMeasurable f) (μ : Measure α) [SigmaFinite μ] : FinStronglyMeasurable f μ := hf.finStronglyMeasurable_of_set_sigmaFinite MeasurableSet.univ (by simp) (by rwa [Measure.restrict_univ]) #align measure_theory.strongly_measurable.fin_strongly_measurable MeasureTheory.StronglyMeasurable.finStronglyMeasurable /-- A strongly measurable function is measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem measurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf : StronglyMeasurable f) : Measurable f := measurable_of_tendsto_metrizable (fun n => (hf.approx n).measurable) (tendsto_pi_nhds.mpr hf.tendsto_approx) #align measure_theory.strongly_measurable.measurable MeasureTheory.StronglyMeasurable.measurable /-- A strongly measurable function is almost everywhere measurable. -/ @[aesop 5% apply (rule_sets := [Measurable])] protected theorem aemeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] {μ : Measure α} (hf : StronglyMeasurable f) : AEMeasurable f μ := hf.measurable.aemeasurable #align measure_theory.strongly_measurable.ae_measurable MeasureTheory.StronglyMeasurable.aemeasurable theorem _root_.Continuous.comp_stronglyMeasurable {_ : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {g : β → γ} {f : α → β} (hg : Continuous g) (hf : StronglyMeasurable f) : StronglyMeasurable fun x => g (f x) := ⟨fun n => SimpleFunc.map g (hf.approx n), fun x => (hg.tendsto _).comp (hf.tendsto_approx x)⟩ #align continuous.comp_strongly_measurable Continuous.comp_stronglyMeasurable @[to_additive] nonrec theorem measurableSet_mulSupport {m : MeasurableSpace α} [One β] [TopologicalSpace β] [MetrizableSpace β] (hf : StronglyMeasurable f) : MeasurableSet (mulSupport f) := by borelize β exact measurableSet_mulSupport hf.measurable #align measure_theory.strongly_measurable.measurable_set_mul_support MeasureTheory.StronglyMeasurable.measurableSet_mulSupport #align measure_theory.strongly_measurable.measurable_set_support MeasureTheory.StronglyMeasurable.measurableSet_support protected theorem mono {m m' : MeasurableSpace α} [TopologicalSpace β] (hf : StronglyMeasurable[m'] f) (h_mono : m' ≤ m) : StronglyMeasurable[m] f := by let f_approx : ℕ → @SimpleFunc α m β := fun n => @SimpleFunc.mk α m β (hf.approx n) (fun x => h_mono _ (SimpleFunc.measurableSet_fiber' _ x)) (SimpleFunc.finite_range (hf.approx n)) exact ⟨f_approx, hf.tendsto_approx⟩ #align measure_theory.strongly_measurable.mono MeasureTheory.StronglyMeasurable.mono protected theorem prod_mk {m : MeasurableSpace α} [TopologicalSpace β] [TopologicalSpace γ] {f : α → β} {g : α → γ} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => (f x, g x) := by refine ⟨fun n => SimpleFunc.pair (hf.approx n) (hg.approx n), fun x => ?_⟩ rw [nhds_prod_eq] exact Tendsto.prod_mk (hf.tendsto_approx x) (hg.tendsto_approx x) #align measure_theory.strongly_measurable.prod_mk MeasureTheory.StronglyMeasurable.prod_mk theorem comp_measurable [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → β} {g : γ → α} (hf : StronglyMeasurable f) (hg : Measurable g) : StronglyMeasurable (f ∘ g) := ⟨fun n => SimpleFunc.comp (hf.approx n) g hg, fun x => hf.tendsto_approx (g x)⟩ #align measure_theory.strongly_measurable.comp_measurable MeasureTheory.StronglyMeasurable.comp_measurable theorem of_uncurry_left [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {x : α} : StronglyMeasurable (f x) := hf.comp_measurable measurable_prod_mk_left #align measure_theory.strongly_measurable.of_uncurry_left MeasureTheory.StronglyMeasurable.of_uncurry_left theorem of_uncurry_right [TopologicalSpace β] {_ : MeasurableSpace α} {_ : MeasurableSpace γ} {f : α → γ → β} (hf : StronglyMeasurable (uncurry f)) {y : γ} : StronglyMeasurable fun x => f x y := hf.comp_measurable measurable_prod_mk_right #align measure_theory.strongly_measurable.of_uncurry_right MeasureTheory.StronglyMeasurable.of_uncurry_right section Arithmetic variable {mα : MeasurableSpace α} [TopologicalSpace β] @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f * g) := ⟨fun n => hf.approx n * hg.approx n, fun x => (hf.tendsto_approx x).mul (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.mul MeasureTheory.StronglyMeasurable.mul #align measure_theory.strongly_measurable.add MeasureTheory.StronglyMeasurable.add @[to_additive (attr := measurability)] theorem mul_const [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x * c := hf.mul stronglyMeasurable_const #align measure_theory.strongly_measurable.mul_const MeasureTheory.StronglyMeasurable.mul_const #align measure_theory.strongly_measurable.add_const MeasureTheory.StronglyMeasurable.add_const @[to_additive (attr := measurability)] theorem const_mul [Mul β] [ContinuousMul β] (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => c * f x := stronglyMeasurable_const.mul hf #align measure_theory.strongly_measurable.const_mul MeasureTheory.StronglyMeasurable.const_mul #align measure_theory.strongly_measurable.const_add MeasureTheory.StronglyMeasurable.const_add @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable])) const_nsmul] protected theorem pow [Monoid β] [ContinuousMul β] (hf : StronglyMeasurable f) (n : ℕ) : StronglyMeasurable (f ^ n) := ⟨fun k => hf.approx k ^ n, fun x => (hf.tendsto_approx x).pow n⟩ @[to_additive (attr := measurability)] protected theorem inv [Inv β] [ContinuousInv β] (hf : StronglyMeasurable f) : StronglyMeasurable f⁻¹ := ⟨fun n => (hf.approx n)⁻¹, fun x => (hf.tendsto_approx x).inv⟩ #align measure_theory.strongly_measurable.inv MeasureTheory.StronglyMeasurable.inv #align measure_theory.strongly_measurable.neg MeasureTheory.StronglyMeasurable.neg @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem div [Div β] [ContinuousDiv β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f / g) := ⟨fun n => hf.approx n / hg.approx n, fun x => (hf.tendsto_approx x).div' (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.div MeasureTheory.StronglyMeasurable.div #align measure_theory.strongly_measurable.sub MeasureTheory.StronglyMeasurable.sub @[to_additive] theorem mul_iff_right [CommGroup β] [TopologicalGroup β] (hf : StronglyMeasurable f) : StronglyMeasurable (f * g) ↔ StronglyMeasurable g := ⟨fun h ↦ show g = f * g * f⁻¹ by simp only [mul_inv_cancel_comm] ▸ h.mul hf.inv, fun h ↦ hf.mul h⟩ @[to_additive] theorem mul_iff_left [CommGroup β] [TopologicalGroup β] (hf : StronglyMeasurable f) : StronglyMeasurable (g * f) ↔ StronglyMeasurable g := mul_comm g f ▸ mul_iff_right hf @[to_additive (attr := aesop safe 20 apply (rule_sets := [Measurable]))] protected theorem smul {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} {g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => f x • g x := continuous_smul.comp_stronglyMeasurable (hf.prod_mk hg) #align measure_theory.strongly_measurable.smul MeasureTheory.StronglyMeasurable.smul #align measure_theory.strongly_measurable.vadd MeasureTheory.StronglyMeasurable.vadd @[to_additive (attr := measurability)] protected theorem const_smul {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f) (c : 𝕜) : StronglyMeasurable (c • f) := ⟨fun n => c • hf.approx n, fun x => (hf.tendsto_approx x).const_smul c⟩ #align measure_theory.strongly_measurable.const_smul MeasureTheory.StronglyMeasurable.const_smul @[to_additive (attr := measurability)] protected theorem const_smul' {𝕜} [SMul 𝕜 β] [ContinuousConstSMul 𝕜 β] (hf : StronglyMeasurable f) (c : 𝕜) : StronglyMeasurable fun x => c • f x := hf.const_smul c #align measure_theory.strongly_measurable.const_smul' MeasureTheory.StronglyMeasurable.const_smul' @[to_additive (attr := measurability)] protected theorem smul_const {𝕜} [TopologicalSpace 𝕜] [SMul 𝕜 β] [ContinuousSMul 𝕜 β] {f : α → 𝕜} (hf : StronglyMeasurable f) (c : β) : StronglyMeasurable fun x => f x • c := continuous_smul.comp_stronglyMeasurable (hf.prod_mk stronglyMeasurable_const) #align measure_theory.strongly_measurable.smul_const MeasureTheory.StronglyMeasurable.smul_const #align measure_theory.strongly_measurable.vadd_const MeasureTheory.StronglyMeasurable.vadd_const /-- In a normed vector space, the addition of a measurable function and a strongly measurable function is measurable. Note that this is not true without further second-countability assumptions for the addition of two measurable functions. -/ theorem _root_.Measurable.add_stronglyMeasurable {α E : Type*} {_ : MeasurableSpace α} [AddGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (g + f) := by rcases hf with ⟨φ, hφ⟩ have : Tendsto (fun n x ↦ g x + φ n x) atTop (𝓝 (g + f)) := tendsto_pi_nhds.2 (fun x ↦ tendsto_const_nhds.add (hφ x)) apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this exact hg.add_simpleFunc _ /-- In a normed vector space, the subtraction of a measurable function and a strongly measurable function is measurable. Note that this is not true without further second-countability assumptions for the subtraction of two measurable functions. -/ theorem _root_.Measurable.sub_stronglyMeasurable {α E : Type*} {_ : MeasurableSpace α} [AddCommGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [ContinuousNeg E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (g - f) := by rw [sub_eq_add_neg] exact hg.add_stronglyMeasurable hf.neg /-- In a normed vector space, the addition of a strongly measurable function and a measurable function is measurable. Note that this is not true without further second-countability assumptions for the addition of two measurable functions. -/ theorem _root_.Measurable.stronglyMeasurable_add {α E : Type*} {_ : MeasurableSpace α} [AddGroup E] [TopologicalSpace E] [MeasurableSpace E] [BorelSpace E] [ContinuousAdd E] [PseudoMetrizableSpace E] {g f : α → E} (hg : Measurable g) (hf : StronglyMeasurable f) : Measurable (f + g) := by rcases hf with ⟨φ, hφ⟩ have : Tendsto (fun n x ↦ φ n x + g x) atTop (𝓝 (f + g)) := tendsto_pi_nhds.2 (fun x ↦ (hφ x).add tendsto_const_nhds) apply measurable_of_tendsto_metrizable (fun n ↦ ?_) this exact hg.simpleFunc_add _ end Arithmetic section MulAction variable {M G G₀ : Type*} variable [TopologicalSpace β] variable [Monoid M] [MulAction M β] [ContinuousConstSMul M β] variable [Group G] [MulAction G β] [ContinuousConstSMul G β] variable [GroupWithZero G₀] [MulAction G₀ β] [ContinuousConstSMul G₀ β] theorem _root_.stronglyMeasurable_const_smul_iff {m : MeasurableSpace α} (c : G) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := ⟨fun h => by simpa only [inv_smul_smul] using h.const_smul' c⁻¹, fun h => h.const_smul c⟩ #align strongly_measurable_const_smul_iff stronglyMeasurable_const_smul_iff nonrec theorem _root_.IsUnit.stronglyMeasurable_const_smul_iff {_ : MeasurableSpace α} {c : M} (hc : IsUnit c) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := let ⟨u, hu⟩ := hc hu ▸ stronglyMeasurable_const_smul_iff u #align is_unit.strongly_measurable_const_smul_iff IsUnit.stronglyMeasurable_const_smul_iff theorem _root_.stronglyMeasurable_const_smul_iff₀ {_ : MeasurableSpace α} {c : G₀} (hc : c ≠ 0) : (StronglyMeasurable fun x => c • f x) ↔ StronglyMeasurable f := (IsUnit.mk0 _ hc).stronglyMeasurable_const_smul_iff #align strongly_measurable_const_smul_iff₀ stronglyMeasurable_const_smul_iff₀ end MulAction section Order variable [MeasurableSpace α] [TopologicalSpace β] open Filter open Filter @[aesop safe 20 (rule_sets := [Measurable])] protected theorem sup [Sup β] [ContinuousSup β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f ⊔ g) := ⟨fun n => hf.approx n ⊔ hg.approx n, fun x => (hf.tendsto_approx x).sup_nhds (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.sup MeasureTheory.StronglyMeasurable.sup @[aesop safe 20 (rule_sets := [Measurable])] protected theorem inf [Inf β] [ContinuousInf β] (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (f ⊓ g) := ⟨fun n => hf.approx n ⊓ hg.approx n, fun x => (hf.tendsto_approx x).inf_nhds (hg.tendsto_approx x)⟩ #align measure_theory.strongly_measurable.inf MeasureTheory.StronglyMeasurable.inf end Order /-! ### Big operators: `∏` and `∑` -/ section Monoid variable {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α} @[to_additive (attr := measurability)] theorem _root_.List.stronglyMeasurable_prod' (l : List (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by induction' l with f l ihl; · exact stronglyMeasurable_one rw [List.forall_mem_cons] at hl rw [List.prod_cons] exact hl.1.mul (ihl hl.2) #align list.strongly_measurable_prod' List.stronglyMeasurable_prod' #align list.strongly_measurable_sum' List.stronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.List.stronglyMeasurable_prod (l : List (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable fun x => (l.map fun f : α → M => f x).prod := by simpa only [← Pi.list_prod_apply] using l.stronglyMeasurable_prod' hl #align list.strongly_measurable_prod List.stronglyMeasurable_prod #align list.strongly_measurable_sum List.stronglyMeasurable_sum end Monoid section CommMonoid variable {M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] {m : MeasurableSpace α} @[to_additive (attr := measurability)] theorem _root_.Multiset.stronglyMeasurable_prod' (l : Multiset (α → M)) (hl : ∀ f ∈ l, StronglyMeasurable f) : StronglyMeasurable l.prod := by rcases l with ⟨l⟩ simpa using l.stronglyMeasurable_prod' (by simpa using hl) #align multiset.strongly_measurable_prod' Multiset.stronglyMeasurable_prod' #align multiset.strongly_measurable_sum' Multiset.stronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.Multiset.stronglyMeasurable_prod (s : Multiset (α → M)) (hs : ∀ f ∈ s, StronglyMeasurable f) : StronglyMeasurable fun x => (s.map fun f : α → M => f x).prod := by simpa only [← Pi.multiset_prod_apply] using s.stronglyMeasurable_prod' hs #align multiset.strongly_measurable_prod Multiset.stronglyMeasurable_prod #align multiset.strongly_measurable_sum Multiset.stronglyMeasurable_sum @[to_additive (attr := measurability)] theorem _root_.Finset.stronglyMeasurable_prod' {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable (∏ i ∈ s, f i) := Finset.prod_induction _ _ (fun _a _b ha hb => ha.mul hb) (@stronglyMeasurable_one α M _ _ _) hf #align finset.strongly_measurable_prod' Finset.stronglyMeasurable_prod' #align finset.strongly_measurable_sum' Finset.stronglyMeasurable_sum' @[to_additive (attr := measurability)] theorem _root_.Finset.stronglyMeasurable_prod {ι : Type*} {f : ι → α → M} (s : Finset ι) (hf : ∀ i ∈ s, StronglyMeasurable (f i)) : StronglyMeasurable fun a => ∏ i ∈ s, f i a := by simpa only [← Finset.prod_apply] using s.stronglyMeasurable_prod' hf #align finset.strongly_measurable_prod Finset.stronglyMeasurable_prod #align finset.strongly_measurable_sum Finset.stronglyMeasurable_sum end CommMonoid /-- The range of a strongly measurable function is separable. -/ protected theorem isSeparable_range {m : MeasurableSpace α} [TopologicalSpace β] (hf : StronglyMeasurable f) : TopologicalSpace.IsSeparable (range f) := by have : IsSeparable (closure (⋃ n, range (hf.approx n))) := .closure <| .iUnion fun n => (hf.approx n).finite_range.isSeparable apply this.mono rintro _ ⟨x, rfl⟩ apply mem_closure_of_tendsto (hf.tendsto_approx x) filter_upwards with n apply mem_iUnion_of_mem n exact mem_range_self _ #align measure_theory.strongly_measurable.is_separable_range MeasureTheory.StronglyMeasurable.isSeparable_range theorem separableSpace_range_union_singleton {_ : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] (hf : StronglyMeasurable f) {b : β} : SeparableSpace (range f ∪ {b} : Set β) := letI := pseudoMetrizableSpacePseudoMetric β (hf.isSeparable_range.union (finite_singleton _).isSeparable).separableSpace #align measure_theory.strongly_measurable.separable_space_range_union_singleton MeasureTheory.StronglyMeasurable.separableSpace_range_union_singleton section SecondCountableStronglyMeasurable variable {mα : MeasurableSpace α} [MeasurableSpace β] /-- In a space with second countable topology, measurable implies strongly measurable. -/ @[aesop 90% apply (rule_sets := [Measurable])] theorem _root_.Measurable.stronglyMeasurable [TopologicalSpace β] [PseudoMetrizableSpace β] [SecondCountableTopology β] [OpensMeasurableSpace β] (hf : Measurable f) : StronglyMeasurable f := by letI := pseudoMetrizableSpacePseudoMetric β nontriviality β; inhabit β exact ⟨SimpleFunc.approxOn f hf Set.univ default (Set.mem_univ _), fun x ↦ SimpleFunc.tendsto_approxOn hf (Set.mem_univ _) (by rw [closure_univ]; simp)⟩ #align measurable.strongly_measurable Measurable.stronglyMeasurable /-- In a space with second countable topology, strongly measurable and measurable are equivalent. -/ theorem _root_.stronglyMeasurable_iff_measurable [TopologicalSpace β] [MetrizableSpace β] [BorelSpace β] [SecondCountableTopology β] : StronglyMeasurable f ↔ Measurable f := ⟨fun h => h.measurable, fun h => Measurable.stronglyMeasurable h⟩ #align strongly_measurable_iff_measurable stronglyMeasurable_iff_measurable @[measurability] theorem _root_.stronglyMeasurable_id [TopologicalSpace α] [PseudoMetrizableSpace α] [OpensMeasurableSpace α] [SecondCountableTopology α] : StronglyMeasurable (id : α → α) := measurable_id.stronglyMeasurable #align strongly_measurable_id stronglyMeasurable_id end SecondCountableStronglyMeasurable /-- A function is strongly measurable if and only if it is measurable and has separable range. -/ theorem _root_.stronglyMeasurable_iff_measurable_separable {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [MeasurableSpace β] [BorelSpace β] : StronglyMeasurable f ↔ Measurable f ∧ IsSeparable (range f) := by refine ⟨fun H ↦ ⟨H.measurable, H.isSeparable_range⟩, fun ⟨Hm, Hsep⟩ ↦ ?_⟩ have := Hsep.secondCountableTopology have Hm' : StronglyMeasurable (rangeFactorization f) := Hm.subtype_mk.stronglyMeasurable exact continuous_subtype_val.comp_stronglyMeasurable Hm' #align strongly_measurable_iff_measurable_separable stronglyMeasurable_iff_measurable_separable /-- A continuous function is strongly measurable when either the source space or the target space is second-countable. -/ theorem _root_.Continuous.stronglyMeasurable [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [TopologicalSpace β] [PseudoMetrizableSpace β] [h : SecondCountableTopologyEither α β] {f : α → β} (hf : Continuous f) : StronglyMeasurable f := by borelize β cases h.out · rw [stronglyMeasurable_iff_measurable_separable] refine ⟨hf.measurable, ?_⟩ exact isSeparable_range hf · exact hf.measurable.stronglyMeasurable #align continuous.strongly_measurable Continuous.stronglyMeasurable /-- A continuous function whose support is contained in a compact set is strongly measurable. -/ @[to_additive] theorem _root_.Continuous.stronglyMeasurable_of_mulSupport_subset_isCompact [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β} (hf : Continuous f) {k : Set α} (hk : IsCompact k) (h'f : mulSupport f ⊆ k) : StronglyMeasurable f := by letI : PseudoMetricSpace β := pseudoMetrizableSpacePseudoMetric β rw [stronglyMeasurable_iff_measurable_separable] exact ⟨hf.measurable, (isCompact_range_of_mulSupport_subset_isCompact hf hk h'f).isSeparable⟩ /-- A continuous function with compact support is strongly measurable. -/ @[to_additive] theorem _root_.Continuous.stronglyMeasurable_of_hasCompactMulSupport [MeasurableSpace α] [TopologicalSpace α] [OpensMeasurableSpace α] [MeasurableSpace β] [TopologicalSpace β] [PseudoMetrizableSpace β] [BorelSpace β] [One β] {f : α → β} (hf : Continuous f) (h'f : HasCompactMulSupport f) : StronglyMeasurable f := hf.stronglyMeasurable_of_mulSupport_subset_isCompact h'f (subset_mulTSupport f) /-- A continuous function with compact support on a product space is strongly measurable for the product sigma-algebra. The subtlety is that we do not assume that the spaces are separable, so the product of the Borel sigma algebras might not contain all open sets, but still it contains enough of them to approximate compactly supported continuous functions. -/ lemma _root_.HasCompactSupport.stronglyMeasurable_of_prod {X Y : Type*} [Zero α] [TopologicalSpace X] [TopologicalSpace Y] [MeasurableSpace X] [MeasurableSpace Y] [OpensMeasurableSpace X] [OpensMeasurableSpace Y] [TopologicalSpace α] [PseudoMetrizableSpace α] {f : X × Y → α} (hf : Continuous f) (h'f : HasCompactSupport f) : StronglyMeasurable f := by borelize α apply stronglyMeasurable_iff_measurable_separable.2 ⟨h'f.measurable_of_prod hf, ?_⟩ letI : PseudoMetricSpace α := pseudoMetrizableSpacePseudoMetric α exact IsCompact.isSeparable (s := range f) (h'f.isCompact_range hf) /-- If `g` is a topological embedding, then `f` is strongly measurable iff `g ∘ f` is. -/ theorem _root_.Embedding.comp_stronglyMeasurable_iff {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] [TopologicalSpace γ] [PseudoMetrizableSpace γ] {g : β → γ} {f : α → β} (hg : Embedding g) : (StronglyMeasurable fun x => g (f x)) ↔ StronglyMeasurable f := by letI := pseudoMetrizableSpacePseudoMetric γ borelize β γ refine ⟨fun H => stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩, fun H => hg.continuous.comp_stronglyMeasurable H⟩ · let G : β → range g := rangeFactorization g have hG : ClosedEmbedding G := { hg.codRestrict _ _ with isClosed_range := by rw [surjective_onto_range.range_eq] exact isClosed_univ } have : Measurable (G ∘ f) := Measurable.subtype_mk H.measurable exact hG.measurableEmbedding.measurable_comp_iff.1 this · have : IsSeparable (g ⁻¹' range (g ∘ f)) := hg.isSeparable_preimage H.isSeparable_range rwa [range_comp, hg.inj.preimage_image] at this #align embedding.comp_strongly_measurable_iff Embedding.comp_stronglyMeasurable_iff /-- A sequential limit of strongly measurable functions is strongly measurable. -/ theorem _root_.stronglyMeasurable_of_tendsto {ι : Type*} {m : MeasurableSpace α} [TopologicalSpace β] [PseudoMetrizableSpace β] (u : Filter ι) [NeBot u] [IsCountablyGenerated u] {f : ι → α → β} {g : α → β} (hf : ∀ i, StronglyMeasurable (f i)) (lim : Tendsto f u (𝓝 g)) : StronglyMeasurable g := by borelize β refine stronglyMeasurable_iff_measurable_separable.2 ⟨?_, ?_⟩ · exact measurable_of_tendsto_metrizable' u (fun i => (hf i).measurable) lim · rcases u.exists_seq_tendsto with ⟨v, hv⟩ have : IsSeparable (closure (⋃ i, range (f (v i)))) := .closure <| .iUnion fun i => (hf (v i)).isSeparable_range apply this.mono rintro _ ⟨x, rfl⟩ rw [tendsto_pi_nhds] at lim apply mem_closure_of_tendsto ((lim x).comp hv) filter_upwards with n apply mem_iUnion_of_mem n exact mem_range_self _ #align strongly_measurable_of_tendsto stronglyMeasurable_of_tendsto protected theorem piecewise {m : MeasurableSpace α} [TopologicalSpace β] {s : Set α} {_ : DecidablePred (· ∈ s)} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable (Set.piecewise s f g) := by refine ⟨fun n => SimpleFunc.piecewise s hs (hf.approx n) (hg.approx n), fun x => ?_⟩ by_cases hx : x ∈ s · simpa [@Set.piecewise_eq_of_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx, hx] using hf.tendsto_approx x · simpa [@Set.piecewise_eq_of_not_mem _ _ _ _ _ (fun _ => Classical.propDecidable _) _ hx, hx] using hg.tendsto_approx x #align measure_theory.strongly_measurable.piecewise MeasureTheory.StronglyMeasurable.piecewise /-- this is slightly different from `StronglyMeasurable.piecewise`. It can be used to show `StronglyMeasurable (ite (x=0) 0 1)` by `exact StronglyMeasurable.ite (measurableSet_singleton 0) stronglyMeasurable_const stronglyMeasurable_const`, but replacing `StronglyMeasurable.ite` by `StronglyMeasurable.piecewise` in that example proof does not work. -/ protected theorem ite {_ : MeasurableSpace α} [TopologicalSpace β] {p : α → Prop} {_ : DecidablePred p} (hp : MeasurableSet { a : α | p a }) (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => ite (p x) (f x) (g x) := StronglyMeasurable.piecewise hp hf hg #align measure_theory.strongly_measurable.ite MeasureTheory.StronglyMeasurable.ite @[measurability] theorem _root_.MeasurableEmbedding.stronglyMeasurable_extend {f : α → β} {g : α → γ} {g' : γ → β} {mα : MeasurableSpace α} {mγ : MeasurableSpace γ} [TopologicalSpace β] (hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hg' : StronglyMeasurable g') : StronglyMeasurable (Function.extend g f g') := by refine ⟨fun n => SimpleFunc.extend (hf.approx n) g hg (hg'.approx n), ?_⟩ intro x by_cases hx : ∃ y, g y = x · rcases hx with ⟨y, rfl⟩ simpa only [SimpleFunc.extend_apply, hg.injective, Injective.extend_apply] using hf.tendsto_approx y · simpa only [hx, SimpleFunc.extend_apply', not_false_iff, extend_apply'] using hg'.tendsto_approx x #align measurable_embedding.strongly_measurable_extend MeasurableEmbedding.stronglyMeasurable_extend theorem _root_.MeasurableEmbedding.exists_stronglyMeasurable_extend {f : α → β} {g : α → γ} {_ : MeasurableSpace α} {_ : MeasurableSpace γ} [TopologicalSpace β] (hg : MeasurableEmbedding g) (hf : StronglyMeasurable f) (hne : γ → Nonempty β) : ∃ f' : γ → β, StronglyMeasurable f' ∧ f' ∘ g = f := ⟨Function.extend g f fun x => Classical.choice (hne x), hg.stronglyMeasurable_extend hf (stronglyMeasurable_const' fun _ _ => rfl), funext fun _ => hg.injective.extend_apply _ _ _⟩ #align measurable_embedding.exists_strongly_measurable_extend MeasurableEmbedding.exists_stronglyMeasurable_extend theorem _root_.stronglyMeasurable_of_stronglyMeasurable_union_cover {m : MeasurableSpace α} [TopologicalSpace β] {f : α → β} (s t : Set α) (hs : MeasurableSet s) (ht : MeasurableSet t) (h : univ ⊆ s ∪ t) (hc : StronglyMeasurable fun a : s => f a) (hd : StronglyMeasurable fun a : t => f a) : StronglyMeasurable f := by nontriviality β; inhabit β suffices Function.extend Subtype.val (fun x : s ↦ f x) (Function.extend (↑) (fun x : t ↦ f x) fun _ ↦ default) = f from this ▸ (MeasurableEmbedding.subtype_coe hs).stronglyMeasurable_extend hc <| (MeasurableEmbedding.subtype_coe ht).stronglyMeasurable_extend hd stronglyMeasurable_const ext x by_cases hxs : x ∈ s · lift x to s using hxs simp [Subtype.coe_injective.extend_apply] · lift x to t using (h trivial).resolve_left hxs rw [extend_apply', Subtype.coe_injective.extend_apply] exact fun ⟨y, hy⟩ ↦ hxs <| hy ▸ y.2 #align strongly_measurable_of_strongly_measurable_union_cover stronglyMeasurable_of_stronglyMeasurable_union_cover theorem _root_.stronglyMeasurable_of_restrict_of_restrict_compl {_ : MeasurableSpace α} [TopologicalSpace β] {f : α → β} {s : Set α} (hs : MeasurableSet s) (h₁ : StronglyMeasurable (s.restrict f)) (h₂ : StronglyMeasurable (sᶜ.restrict f)) : StronglyMeasurable f := stronglyMeasurable_of_stronglyMeasurable_union_cover s sᶜ hs hs.compl (union_compl_self s).ge h₁ h₂ #align strongly_measurable_of_restrict_of_restrict_compl stronglyMeasurable_of_restrict_of_restrict_compl @[measurability] protected theorem indicator {_ : MeasurableSpace α} [TopologicalSpace β] [Zero β] (hf : StronglyMeasurable f) {s : Set α} (hs : MeasurableSet s) : StronglyMeasurable (s.indicator f) := hf.piecewise hs stronglyMeasurable_const #align measure_theory.strongly_measurable.indicator MeasureTheory.StronglyMeasurable.indicator @[aesop safe 20 apply (rule_sets := [Measurable])] protected theorem dist {_ : MeasurableSpace α} {β : Type*} [PseudoMetricSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : StronglyMeasurable fun x => dist (f x) (g x) := continuous_dist.comp_stronglyMeasurable (hf.prod_mk hg) #align measure_theory.strongly_measurable.dist MeasureTheory.StronglyMeasurable.dist @[measurability] protected theorem norm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖ := continuous_norm.comp_stronglyMeasurable hf #align measure_theory.strongly_measurable.norm MeasureTheory.StronglyMeasurable.norm @[measurability] protected theorem nnnorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => ‖f x‖₊ := continuous_nnnorm.comp_stronglyMeasurable hf #align measure_theory.strongly_measurable.nnnorm MeasureTheory.StronglyMeasurable.nnnorm @[measurability] protected theorem ennnorm {_ : MeasurableSpace α} {β : Type*} [SeminormedAddCommGroup β] {f : α → β} (hf : StronglyMeasurable f) : Measurable fun a => (‖f a‖₊ : ℝ≥0∞) := (ENNReal.continuous_coe.comp_stronglyMeasurable hf.nnnorm).measurable #align measure_theory.strongly_measurable.ennnorm MeasureTheory.StronglyMeasurable.ennnorm @[measurability] protected theorem real_toNNReal {_ : MeasurableSpace α} {f : α → ℝ} (hf : StronglyMeasurable f) : StronglyMeasurable fun x => (f x).toNNReal := continuous_real_toNNReal.comp_stronglyMeasurable hf #align measure_theory.strongly_measurable.real_to_nnreal MeasureTheory.StronglyMeasurable.real_toNNReal theorem measurableSet_eq_fun {m : MeasurableSpace α} {E} [TopologicalSpace E] [MetrizableSpace E] {f g : α → E} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : MeasurableSet { x | f x = g x } := by borelize (E × E) exact (hf.prod_mk hg).measurable isClosed_diagonal.measurableSet #align measure_theory.strongly_measurable.measurable_set_eq_fun MeasureTheory.StronglyMeasurable.measurableSet_eq_fun theorem measurableSet_lt {m : MeasurableSpace α} [TopologicalSpace β] [LinearOrder β] [OrderClosedTopology β] [PseudoMetrizableSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : MeasurableSet { a | f a < g a } := by borelize (β × β) exact (hf.prod_mk hg).measurable isOpen_lt_prod.measurableSet #align measure_theory.strongly_measurable.measurable_set_lt MeasureTheory.StronglyMeasurable.measurableSet_lt theorem measurableSet_le {m : MeasurableSpace α} [TopologicalSpace β] [Preorder β] [OrderClosedTopology β] [PseudoMetrizableSpace β] {f g : α → β} (hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : MeasurableSet { a | f a ≤ g a } := by borelize (β × β) exact (hf.prod_mk hg).measurable isClosed_le_prod.measurableSet #align measure_theory.strongly_measurable.measurable_set_le MeasureTheory.StronglyMeasurable.measurableSet_le theorem stronglyMeasurable_in_set {m : MeasurableSpace α} [TopologicalSpace β] [Zero β] {s : Set α} {f : α → β} (hs : MeasurableSet s) (hf : StronglyMeasurable f) (hf_zero : ∀ x, x ∉ s → f x = 0) : ∃ fs : ℕ → α →ₛ β, (∀ x, Tendsto (fun n => fs n x) atTop (𝓝 (f x))) ∧ ∀ x ∉ s, ∀ n, fs n x = 0 := by let g_seq_s : ℕ → @SimpleFunc α m β := fun n => (hf.approx n).restrict s have hg_eq : ∀ x ∈ s, ∀ n, g_seq_s n x = hf.approx n x := by intro x hx n rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_mem hx] have hg_zero : ∀ x ∉ s, ∀ n, g_seq_s n x = 0 := by intro x hx n rw [SimpleFunc.coe_restrict _ hs, Set.indicator_of_not_mem hx] refine ⟨g_seq_s, fun x => ?_, hg_zero⟩ by_cases hx : x ∈ s · simp_rw [hg_eq x hx] exact hf.tendsto_approx x · simp_rw [hg_zero x hx, hf_zero x hx] exact tendsto_const_nhds #align measure_theory.strongly_measurable.strongly_measurable_in_set MeasureTheory.StronglyMeasurable.stronglyMeasurable_in_set /-- If the restriction to a set `s` of a σ-algebra `m` is included in the restriction to `s` of another σ-algebra `m₂` (hypothesis `hs`), the set `s` is `m` measurable and a function `f` supported on `s` is `m`-strongly-measurable, then `f` is also `m₂`-strongly-measurable. -/ theorem stronglyMeasurable_of_measurableSpace_le_on {α E} {m m₂ : MeasurableSpace α} [TopologicalSpace E] [Zero E] {s : Set α} {f : α → E} (hs_m : MeasurableSet[m] s) (hs : ∀ t, MeasurableSet[m] (s ∩ t) → MeasurableSet[m₂] (s ∩ t)) (hf : StronglyMeasurable[m] f) (hf_zero : ∀ x ∉ s, f x = 0) : StronglyMeasurable[m₂] f := by have hs_m₂ : MeasurableSet[m₂] s := by rw [← Set.inter_univ s] refine hs Set.univ ?_ rwa [Set.inter_univ] obtain ⟨g_seq_s, hg_seq_tendsto, hg_seq_zero⟩ := stronglyMeasurable_in_set hs_m hf hf_zero let g_seq_s₂ : ℕ → @SimpleFunc α m₂ E := fun n => { toFun := g_seq_s n measurableSet_fiber' := fun x => by rw [← Set.inter_univ (g_seq_s n ⁻¹' {x}), ← Set.union_compl_self s, Set.inter_union_distrib_left, Set.inter_comm (g_seq_s n ⁻¹' {x})] refine MeasurableSet.union (hs _ (hs_m.inter ?_)) ?_ · exact @SimpleFunc.measurableSet_fiber _ _ m _ _ by_cases hx : x = 0 · suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = sᶜ by rw [this] exact hs_m₂.compl ext1 y rw [hx, Set.mem_inter_iff, Set.mem_preimage, Set.mem_singleton_iff] exact ⟨fun h => h.2, fun h => ⟨hg_seq_zero y h n, h⟩⟩ · suffices g_seq_s n ⁻¹' {x} ∩ sᶜ = ∅ by rw [this] exact MeasurableSet.empty ext1 y simp only [mem_inter_iff, mem_preimage, mem_singleton_iff, mem_compl_iff, mem_empty_iff_false, iff_false_iff, not_and, not_not_mem] refine Function.mtr fun hys => ?_ rw [hg_seq_zero y hys n] exact Ne.symm hx finite_range' := @SimpleFunc.finite_range _ _ m (g_seq_s n) } exact ⟨g_seq_s₂, hg_seq_tendsto⟩ #align measure_theory.strongly_measurable.strongly_measurable_of_measurable_space_le_on MeasureTheory.StronglyMeasurable.stronglyMeasurable_of_measurableSpace_le_on /-- If a function `f` is strongly measurable w.r.t. a sub-σ-algebra `m` and the measure is σ-finite on `m`, then there exists spanning measurable sets with finite measure on which `f` has bounded norm. In particular, `f` is integrable on each of those sets. -/
Mathlib/MeasureTheory/Function/StronglyMeasurable/Basic.lean
992
1,001
theorem exists_spanning_measurableSet_norm_le [SeminormedAddCommGroup β] {m m0 : MeasurableSpace α} (hm : m ≤ m0) (hf : StronglyMeasurable[m] f) (μ : Measure α) [SigmaFinite (μ.trim hm)] : ∃ s : ℕ → Set α, (∀ n, MeasurableSet[m] (s n) ∧ μ (s n) < ∞ ∧ ∀ x ∈ s n, ‖f x‖ ≤ n) ∧ ⋃ i, s i = Set.univ := by
obtain ⟨s, hs, hs_univ⟩ := exists_spanning_measurableSet_le hf.nnnorm.measurable (μ.trim hm) refine ⟨s, fun n ↦ ⟨(hs n).1, (le_trim hm).trans_lt (hs n).2.1, fun x hx ↦ ?_⟩, hs_univ⟩ have hx_nnnorm : ‖f x‖₊ ≤ n := (hs n).2.2 x hx rw [← coe_nnnorm] norm_cast
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Data.Option.Defs import Mathlib.Control.Functor #align_import control.traversable.basic from "leanprover-community/mathlib"@"1fc36cc9c8264e6e81253f88be7fb2cb6c92d76a" /-! # Traversable type class Type classes for traversing collections. The concepts and laws are taken from <http://hackage.haskell.org/package/base-4.11.1.0/docs/Data-Traversable.html> Traversable collections are a generalization of functors. Whereas functors (such as `List`) allow us to apply a function to every element, it does not allow functions which external effects encoded in a monad. Consider for instance a functor `invite : email → IO response` that takes an email address, sends an email and waits for a response. If we have a list `guests : List email`, using calling `invite` using `map` gives us the following: `map invite guests : List (IO response)`. It is not what we need. We need something of type `IO (List response)`. Instead of using `map`, we can use `traverse` to send all the invites: `traverse invite guests : IO (List response)`. `traverse` applies `invite` to every element of `guests` and combines all the resulting effects. In the example, the effect is encoded in the monad `IO` but any applicative functor is accepted by `traverse`. For more on how to use traversable, consider the Haskell tutorial: <https://en.wikibooks.org/wiki/Haskell/Traversable> ## Main definitions * `Traversable` type class - exposes the `traverse` function * `sequence` - based on `traverse`, turns a collection of effects into an effect returning a collection * `LawfulTraversable` - laws for a traversable functor * `ApplicativeTransformation` - the notion of a natural transformation for applicative functors ## Tags traversable iterator functor applicative ## References * "Applicative Programming with Effects", by Conor McBride and Ross Paterson, Journal of Functional Programming 18:1 (2008) 1-13, online at <http://www.soi.city.ac.uk/~ross/papers/Applicative.html> * "The Essence of the Iterator Pattern", by Jeremy Gibbons and Bruno Oliveira, in Mathematically-Structured Functional Programming, 2006, online at <http://web.comlab.ox.ac.uk/oucl/work/jeremy.gibbons/publications/#iterator> * "An Investigation of the Laws of Traversals", by Mauro Jaskelioff and Ondrej Rypacek, in Mathematically-Structured Functional Programming, 2012, online at <http://arxiv.org/pdf/1202.2919> -/ open Function hiding comp universe u v w section ApplicativeTransformation variable (F : Type u → Type v) [Applicative F] [LawfulApplicative F] variable (G : Type u → Type w) [Applicative G] [LawfulApplicative G] /-- A transformation between applicative functors. It is a natural transformation such that `app` preserves the `Pure.pure` and `Functor.map` (`<*>`) operations. See `ApplicativeTransformation.preserves_map` for naturality. -/ structure ApplicativeTransformation : Type max (u + 1) v w where /-- The function on objects defined by an `ApplicativeTransformation`. -/ app : ∀ α : Type u, F α → G α /-- An `ApplicativeTransformation` preserves `pure`. -/ preserves_pure' : ∀ {α : Type u} (x : α), app _ (pure x) = pure x /-- An `ApplicativeTransformation` intertwines `seq`. -/ preserves_seq' : ∀ {α β : Type u} (x : F (α → β)) (y : F α), app _ (x <*> y) = app _ x <*> app _ y #align applicative_transformation ApplicativeTransformation end ApplicativeTransformation namespace ApplicativeTransformation variable (F : Type u → Type v) [Applicative F] [LawfulApplicative F] variable (G : Type u → Type w) [Applicative G] [LawfulApplicative G] instance : CoeFun (ApplicativeTransformation F G) fun _ => ∀ {α}, F α → G α := ⟨fun η ↦ η.app _⟩ variable {F G} -- This cannot be a `simp` lemma, as the RHS is a coercion which contains `η.app`. theorem app_eq_coe (η : ApplicativeTransformation F G) : η.app = η := rfl #align applicative_transformation.app_eq_coe ApplicativeTransformation.app_eq_coe @[simp] theorem coe_mk (f : ∀ α : Type u, F α → G α) (pp ps) : (ApplicativeTransformation.mk f @pp @ps) = f := rfl #align applicative_transformation.coe_mk ApplicativeTransformation.coe_mk protected theorem congr_fun (η η' : ApplicativeTransformation F G) (h : η = η') {α : Type u} (x : F α) : η x = η' x := congrArg (fun η'' : ApplicativeTransformation F G => η'' x) h #align applicative_transformation.congr_fun ApplicativeTransformation.congr_fun protected theorem congr_arg (η : ApplicativeTransformation F G) {α : Type u} {x y : F α} (h : x = y) : η x = η y := congrArg (fun z : F α => η z) h #align applicative_transformation.congr_arg ApplicativeTransformation.congr_arg theorem coe_inj ⦃η η' : ApplicativeTransformation F G⦄ (h : (η : ∀ α, F α → G α) = η') : η = η' := by cases η cases η' congr #align applicative_transformation.coe_inj ApplicativeTransformation.coe_inj @[ext]
Mathlib/Control/Traversable/Basic.lean
121
125
theorem ext ⦃η η' : ApplicativeTransformation F G⦄ (h : ∀ (α : Type u) (x : F α), η x = η' x) : η = η' := by
apply coe_inj ext1 α exact funext (h α)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import Mathlib.Order.Filter.Lift import Mathlib.Topology.Defs.Filter #align_import topology.basic from "leanprover-community/mathlib"@"e354e865255654389cc46e6032160238df2e0f40" /-! # Basic theory of topological spaces. The main definition is the type class `TopologicalSpace X` which endows a type `X` with a topology. Then `Set X` gets predicates `IsOpen`, `IsClosed` and functions `interior`, `closure` and `frontier`. Each point `x` of `X` gets a neighborhood filter `𝓝 x`. A filter `F` on `X` has `x` as a cluster point if `ClusterPt x F : 𝓝 x ⊓ F ≠ ⊥`. A map `f : α → X` clusters at `x` along `F : Filter α` if `MapClusterPt x F f : ClusterPt x (map f F)`. In particular the notion of cluster point of a sequence `u` is `MapClusterPt x atTop u`. For topological spaces `X` and `Y`, a function `f : X → Y` and a point `x : X`, `ContinuousAt f x` means `f` is continuous at `x`, and global continuity is `Continuous f`. There is also a version of continuity `PContinuous` for partially defined functions. ## Notation The following notation is introduced elsewhere and it heavily used in this file. * `𝓝 x`: the filter `nhds x` of neighborhoods of a point `x`; * `𝓟 s`: the principal filter of a set `s`; * `𝓝[s] x`: the filter `nhdsWithin x s` of neighborhoods of a point `x` within a set `s`; * `𝓝[≠] x`: the filter `nhdsWithin x {x}ᶜ` of punctured neighborhoods of `x`. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space, interior, closure, frontier, neighborhood, continuity, continuous function -/ noncomputable section open Set Filter universe u v w x /-! ### Topological spaces -/ /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy #align topological_space.of_closed TopologicalSpace.ofClosed section TopologicalSpace variable {X : Type u} {Y : Type v} {ι : Sort w} {α β : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} open Topology lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl #align is_open_mk isOpen_mk @[ext] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl #align topological_space_eq TopologicalSpace.ext section variable [TopologicalSpace X] end protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h s => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ #align topological_space_eq_iff TopologicalSpace.ext_iff theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl #align is_open_fold isOpen_fold variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) #align is_open_Union isOpen_iUnion theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi #align is_open_bUnion isOpen_biUnion theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) #align is_open.union IsOpen.union lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim #align is_open_empty isOpen_empty theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) : (∀ t ∈ s, IsOpen t) → IsOpen (⋂₀ s) := Finite.induction_on hs (fun _ => by rw [sInter_empty]; exact isOpen_univ) fun _ _ ih h => by simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) #align is_open_sInter Set.Finite.isOpen_sInter theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) #align is_open_bInter Set.Finite.isOpen_biInter theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) #align is_open_Inter isOpen_iInter_of_finite theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h #align is_open_bInter_finset isOpen_biInter_finset @[simp] -- Porting note: added `simp` theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] #align is_open_const isOpen_const theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter #align is_open.and IsOpen.and @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ #align is_open_compl_iff isOpen_compl_iff theorem TopologicalSpace.ext_iff_isClosed {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed -- Porting note (#10756): new lemma theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const #align is_closed_empty isClosed_empty @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const #align is_closed_univ isClosed_univ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter #align is_closed.union IsClosed.union theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion #align is_closed_sInter isClosed_sInter theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) := isClosed_sInter <| forall_mem_range.2 h #align is_closed_Inter isClosed_iInter theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋂ i ∈ s, f i) := isClosed_iInter fun i => isClosed_iInter <| h i #align is_closed_bInter isClosed_biInter @[simp] theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by rw [← isOpen_compl_iff, compl_compl] #align is_closed_compl_iff isClosed_compl_iff alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff #align is_open.is_closed_compl IsOpen.isClosed_compl theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) := IsOpen.inter h₁ h₂.isOpen_compl #align is_open.sdiff IsOpen.sdiff theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by rw [← isOpen_compl_iff] at * rw [compl_inter] exact IsOpen.union h₁ h₂ #align is_closed.inter IsClosed.inter theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) := IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂) #align is_closed.sdiff IsClosed.sdiff theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact hs.isOpen_biInter h #align is_closed_bUnion Set.Finite.isClosed_biUnion lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := s.finite_toSet.isClosed_biUnion h theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) : IsClosed (⋃ i, s i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact isOpen_iInter_of_finite h #align is_closed_Union isClosed_iUnion_of_finite theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) : IsClosed { x | p x → q x } := by simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq #align is_closed_imp isClosed_imp theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } := isOpen_compl_iff.mpr #align is_closed.not IsClosed.not /-! ### Interior of a set -/ theorem mem_interior : x ∈ interior s ↔ ∃ t ⊆ s, IsOpen t ∧ x ∈ t := by simp only [interior, mem_sUnion, mem_setOf_eq, and_assoc, and_left_comm] #align mem_interior mem_interiorₓ @[simp] theorem isOpen_interior : IsOpen (interior s) := isOpen_sUnion fun _ => And.left #align is_open_interior isOpen_interior theorem interior_subset : interior s ⊆ s := sUnion_subset fun _ => And.right #align interior_subset interior_subset theorem interior_maximal (h₁ : t ⊆ s) (h₂ : IsOpen t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ #align interior_maximal interior_maximal theorem IsOpen.interior_eq (h : IsOpen s) : interior s = s := interior_subset.antisymm (interior_maximal (Subset.refl s) h) #align is_open.interior_eq IsOpen.interior_eq theorem interior_eq_iff_isOpen : interior s = s ↔ IsOpen s := ⟨fun h => h ▸ isOpen_interior, IsOpen.interior_eq⟩ #align interior_eq_iff_is_open interior_eq_iff_isOpen theorem subset_interior_iff_isOpen : s ⊆ interior s ↔ IsOpen s := by simp only [interior_eq_iff_isOpen.symm, Subset.antisymm_iff, interior_subset, true_and] #align subset_interior_iff_is_open subset_interior_iff_isOpen theorem IsOpen.subset_interior_iff (h₁ : IsOpen s) : s ⊆ interior t ↔ s ⊆ t := ⟨fun h => Subset.trans h interior_subset, fun h₂ => interior_maximal h₂ h₁⟩ #align is_open.subset_interior_iff IsOpen.subset_interior_iff theorem subset_interior_iff : t ⊆ interior s ↔ ∃ U, IsOpen U ∧ t ⊆ U ∧ U ⊆ s := ⟨fun h => ⟨interior s, isOpen_interior, h, interior_subset⟩, fun ⟨_U, hU, htU, hUs⟩ => htU.trans (interior_maximal hUs hU)⟩ #align subset_interior_iff subset_interior_iff lemma interior_subset_iff : interior s ⊆ t ↔ ∀ U, IsOpen U → U ⊆ s → U ⊆ t := by simp [interior] @[mono, gcongr] theorem interior_mono (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (Subset.trans interior_subset h) isOpen_interior #align interior_mono interior_mono @[simp] theorem interior_empty : interior (∅ : Set X) = ∅ := isOpen_empty.interior_eq #align interior_empty interior_empty @[simp] theorem interior_univ : interior (univ : Set X) = univ := isOpen_univ.interior_eq #align interior_univ interior_univ @[simp] theorem interior_eq_univ : interior s = univ ↔ s = univ := ⟨fun h => univ_subset_iff.mp <| h.symm.trans_le interior_subset, fun h => h.symm ▸ interior_univ⟩ #align interior_eq_univ interior_eq_univ @[simp] theorem interior_interior : interior (interior s) = interior s := isOpen_interior.interior_eq #align interior_interior interior_interior @[simp] theorem interior_inter : interior (s ∩ t) = interior s ∩ interior t := (Monotone.map_inf_le (fun _ _ ↦ interior_mono) s t).antisymm <| interior_maximal (inter_subset_inter interior_subset interior_subset) <| isOpen_interior.inter isOpen_interior #align interior_inter interior_inter theorem Set.Finite.interior_biInter {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := hs.induction_on (by simp) <| by intros; simp [*] theorem Set.Finite.interior_sInter {S : Set (Set X)} (hS : S.Finite) : interior (⋂₀ S) = ⋂ s ∈ S, interior s := by rw [sInter_eq_biInter, hS.interior_biInter] @[simp] theorem Finset.interior_iInter {ι : Type*} (s : Finset ι) (f : ι → Set X) : interior (⋂ i ∈ s, f i) = ⋂ i ∈ s, interior (f i) := s.finite_toSet.interior_biInter f #align finset.interior_Inter Finset.interior_iInter @[simp] theorem interior_iInter_of_finite [Finite ι] (f : ι → Set X) : interior (⋂ i, f i) = ⋂ i, interior (f i) := by rw [← sInter_range, (finite_range f).interior_sInter, biInter_range] #align interior_Inter interior_iInter_of_finite theorem interior_union_isClosed_of_interior_empty (h₁ : IsClosed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have : interior (s ∪ t) ⊆ s := fun x ⟨u, ⟨(hu₁ : IsOpen u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩ => by_contradiction fun hx₂ : x ∉ s => have : u \ s ⊆ t := fun x ⟨h₁, h₂⟩ => Or.resolve_left (hu₂ h₁) h₂ have : u \ s ⊆ interior t := by rwa [(IsOpen.sdiff hu₁ h₁).subset_interior_iff] have : u \ s ⊆ ∅ := by rwa [h₂] at this this ⟨hx₁, hx₂⟩ Subset.antisymm (interior_maximal this isOpen_interior) (interior_mono subset_union_left) #align interior_union_is_closed_of_interior_empty interior_union_isClosed_of_interior_empty theorem isOpen_iff_forall_mem_open : IsOpen s ↔ ∀ x ∈ s, ∃ t, t ⊆ s ∧ IsOpen t ∧ x ∈ t := by rw [← subset_interior_iff_isOpen] simp only [subset_def, mem_interior] #align is_open_iff_forall_mem_open isOpen_iff_forall_mem_open theorem interior_iInter_subset (s : ι → Set X) : interior (⋂ i, s i) ⊆ ⋂ i, interior (s i) := subset_iInter fun _ => interior_mono <| iInter_subset _ _ #align interior_Inter_subset interior_iInter_subset theorem interior_iInter₂_subset (p : ι → Sort*) (s : ∀ i, p i → Set X) : interior (⋂ (i) (j), s i j) ⊆ ⋂ (i) (j), interior (s i j) := (interior_iInter_subset _).trans <| iInter_mono fun _ => interior_iInter_subset _ #align interior_Inter₂_subset interior_iInter₂_subset theorem interior_sInter_subset (S : Set (Set X)) : interior (⋂₀ S) ⊆ ⋂ s ∈ S, interior s := calc interior (⋂₀ S) = interior (⋂ s ∈ S, s) := by rw [sInter_eq_biInter] _ ⊆ ⋂ s ∈ S, interior s := interior_iInter₂_subset _ _ #align interior_sInter_subset interior_sInter_subset theorem Filter.HasBasis.lift'_interior {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' interior).HasBasis p fun i => interior (s i) := h.lift' fun _ _ ↦ interior_mono theorem Filter.lift'_interior_le (l : Filter X) : l.lift' interior ≤ l := fun _s hs ↦ mem_of_superset (mem_lift' hs) interior_subset theorem Filter.HasBasis.lift'_interior_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (ho : ∀ i, p i → IsOpen (s i)) : l.lift' interior = l := le_antisymm l.lift'_interior_le <| h.lift'_interior.ge_iff.2 fun i hi ↦ by simpa only [(ho i hi).interior_eq] using h.mem_of_mem hi /-! ### Closure of a set -/ @[simp] theorem isClosed_closure : IsClosed (closure s) := isClosed_sInter fun _ => And.left #align is_closed_closure isClosed_closure theorem subset_closure : s ⊆ closure s := subset_sInter fun _ => And.right #align subset_closure subset_closure theorem not_mem_of_not_mem_closure {P : X} (hP : P ∉ closure s) : P ∉ s := fun h => hP (subset_closure h) #align not_mem_of_not_mem_closure not_mem_of_not_mem_closure theorem closure_minimal (h₁ : s ⊆ t) (h₂ : IsClosed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ #align closure_minimal closure_minimal theorem Disjoint.closure_left (hd : Disjoint s t) (ht : IsOpen t) : Disjoint (closure s) t := disjoint_compl_left.mono_left <| closure_minimal hd.subset_compl_right ht.isClosed_compl #align disjoint.closure_left Disjoint.closure_left theorem Disjoint.closure_right (hd : Disjoint s t) (hs : IsOpen s) : Disjoint s (closure t) := (hd.symm.closure_left hs).symm #align disjoint.closure_right Disjoint.closure_right theorem IsClosed.closure_eq (h : IsClosed s) : closure s = s := Subset.antisymm (closure_minimal (Subset.refl s) h) subset_closure #align is_closed.closure_eq IsClosed.closure_eq theorem IsClosed.closure_subset (hs : IsClosed s) : closure s ⊆ s := closure_minimal (Subset.refl _) hs #align is_closed.closure_subset IsClosed.closure_subset theorem IsClosed.closure_subset_iff (h₁ : IsClosed t) : closure s ⊆ t ↔ s ⊆ t := ⟨Subset.trans subset_closure, fun h => closure_minimal h h₁⟩ #align is_closed.closure_subset_iff IsClosed.closure_subset_iff theorem IsClosed.mem_iff_closure_subset (hs : IsClosed s) : x ∈ s ↔ closure ({x} : Set X) ⊆ s := (hs.closure_subset_iff.trans Set.singleton_subset_iff).symm #align is_closed.mem_iff_closure_subset IsClosed.mem_iff_closure_subset @[mono, gcongr] theorem closure_mono (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (Subset.trans h subset_closure) isClosed_closure #align closure_mono closure_mono theorem monotone_closure (X : Type*) [TopologicalSpace X] : Monotone (@closure X _) := fun _ _ => closure_mono #align monotone_closure monotone_closure theorem diff_subset_closure_iff : s \ t ⊆ closure t ↔ s ⊆ closure t := by rw [diff_subset_iff, union_eq_self_of_subset_left subset_closure] #align diff_subset_closure_iff diff_subset_closure_iff theorem closure_inter_subset_inter_closure (s t : Set X) : closure (s ∩ t) ⊆ closure s ∩ closure t := (monotone_closure X).map_inf_le s t #align closure_inter_subset_inter_closure closure_inter_subset_inter_closure theorem isClosed_of_closure_subset (h : closure s ⊆ s) : IsClosed s := by rw [subset_closure.antisymm h]; exact isClosed_closure #align is_closed_of_closure_subset isClosed_of_closure_subset theorem closure_eq_iff_isClosed : closure s = s ↔ IsClosed s := ⟨fun h => h ▸ isClosed_closure, IsClosed.closure_eq⟩ #align closure_eq_iff_is_closed closure_eq_iff_isClosed theorem closure_subset_iff_isClosed : closure s ⊆ s ↔ IsClosed s := ⟨isClosed_of_closure_subset, IsClosed.closure_subset⟩ #align closure_subset_iff_is_closed closure_subset_iff_isClosed @[simp] theorem closure_empty : closure (∅ : Set X) = ∅ := isClosed_empty.closure_eq #align closure_empty closure_empty @[simp] theorem closure_empty_iff (s : Set X) : closure s = ∅ ↔ s = ∅ := ⟨subset_eq_empty subset_closure, fun h => h.symm ▸ closure_empty⟩ #align closure_empty_iff closure_empty_iff @[simp] theorem closure_nonempty_iff : (closure s).Nonempty ↔ s.Nonempty := by simp only [nonempty_iff_ne_empty, Ne, closure_empty_iff] #align closure_nonempty_iff closure_nonempty_iff alias ⟨Set.Nonempty.of_closure, Set.Nonempty.closure⟩ := closure_nonempty_iff #align set.nonempty.of_closure Set.Nonempty.of_closure #align set.nonempty.closure Set.Nonempty.closure @[simp] theorem closure_univ : closure (univ : Set X) = univ := isClosed_univ.closure_eq #align closure_univ closure_univ @[simp] theorem closure_closure : closure (closure s) = closure s := isClosed_closure.closure_eq #align closure_closure closure_closure theorem closure_eq_compl_interior_compl : closure s = (interior sᶜ)ᶜ := by rw [interior, closure, compl_sUnion, compl_image_set_of] simp only [compl_subset_compl, isOpen_compl_iff] #align closure_eq_compl_interior_compl closure_eq_compl_interior_compl @[simp] theorem closure_union : closure (s ∪ t) = closure s ∪ closure t := by simp [closure_eq_compl_interior_compl, compl_inter] #align closure_union closure_union theorem Set.Finite.closure_biUnion {ι : Type*} {s : Set ι} (hs : s.Finite) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := by simp [closure_eq_compl_interior_compl, hs.interior_biInter] theorem Set.Finite.closure_sUnion {S : Set (Set X)} (hS : S.Finite) : closure (⋃₀ S) = ⋃ s ∈ S, closure s := by rw [sUnion_eq_biUnion, hS.closure_biUnion] @[simp] theorem Finset.closure_biUnion {ι : Type*} (s : Finset ι) (f : ι → Set X) : closure (⋃ i ∈ s, f i) = ⋃ i ∈ s, closure (f i) := s.finite_toSet.closure_biUnion f #align finset.closure_bUnion Finset.closure_biUnion @[simp] theorem closure_iUnion_of_finite [Finite ι] (f : ι → Set X) : closure (⋃ i, f i) = ⋃ i, closure (f i) := by rw [← sUnion_range, (finite_range _).closure_sUnion, biUnion_range] #align closure_Union closure_iUnion_of_finite theorem interior_subset_closure : interior s ⊆ closure s := Subset.trans interior_subset subset_closure #align interior_subset_closure interior_subset_closure @[simp] theorem interior_compl : interior sᶜ = (closure s)ᶜ := by simp [closure_eq_compl_interior_compl] #align interior_compl interior_compl @[simp] theorem closure_compl : closure sᶜ = (interior s)ᶜ := by simp [closure_eq_compl_interior_compl] #align closure_compl closure_compl theorem mem_closure_iff : x ∈ closure s ↔ ∀ o, IsOpen o → x ∈ o → (o ∩ s).Nonempty := ⟨fun h o oo ao => by_contradiction fun os => have : s ⊆ oᶜ := fun x xs xo => os ⟨x, xo, xs⟩ closure_minimal this (isClosed_compl_iff.2 oo) h ao, fun H _ ⟨h₁, h₂⟩ => by_contradiction fun nc => let ⟨_, hc, hs⟩ := H _ h₁.isOpen_compl nc hc (h₂ hs)⟩ #align mem_closure_iff mem_closure_iff theorem closure_inter_open_nonempty_iff (h : IsOpen t) : (closure s ∩ t).Nonempty ↔ (s ∩ t).Nonempty := ⟨fun ⟨_x, hxcs, hxt⟩ => inter_comm t s ▸ mem_closure_iff.1 hxcs t h hxt, fun h => h.mono <| inf_le_inf_right t subset_closure⟩ #align closure_inter_open_nonempty_iff closure_inter_open_nonempty_iff theorem Filter.le_lift'_closure (l : Filter X) : l ≤ l.lift' closure := le_lift'.2 fun _ h => mem_of_superset h subset_closure #align filter.le_lift'_closure Filter.le_lift'_closure theorem Filter.HasBasis.lift'_closure {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) : (l.lift' closure).HasBasis p fun i => closure (s i) := h.lift' (monotone_closure X) #align filter.has_basis.lift'_closure Filter.HasBasis.lift'_closure theorem Filter.HasBasis.lift'_closure_eq_self {l : Filter X} {p : ι → Prop} {s : ι → Set X} (h : l.HasBasis p s) (hc : ∀ i, p i → IsClosed (s i)) : l.lift' closure = l := le_antisymm (h.ge_iff.2 fun i hi => (hc i hi).closure_eq ▸ mem_lift' (h.mem_of_mem hi)) l.le_lift'_closure #align filter.has_basis.lift'_closure_eq_self Filter.HasBasis.lift'_closure_eq_self @[simp] theorem Filter.lift'_closure_eq_bot {l : Filter X} : l.lift' closure = ⊥ ↔ l = ⊥ := ⟨fun h => bot_unique <| h ▸ l.le_lift'_closure, fun h => h.symm ▸ by rw [lift'_bot (monotone_closure _), closure_empty, principal_empty]⟩ #align filter.lift'_closure_eq_bot Filter.lift'_closure_eq_bot theorem dense_iff_closure_eq : Dense s ↔ closure s = univ := eq_univ_iff_forall.symm #align dense_iff_closure_eq dense_iff_closure_eq alias ⟨Dense.closure_eq, _⟩ := dense_iff_closure_eq #align dense.closure_eq Dense.closure_eq theorem interior_eq_empty_iff_dense_compl : interior s = ∅ ↔ Dense sᶜ := by rw [dense_iff_closure_eq, closure_compl, compl_univ_iff] #align interior_eq_empty_iff_dense_compl interior_eq_empty_iff_dense_compl theorem Dense.interior_compl (h : Dense s) : interior sᶜ = ∅ := interior_eq_empty_iff_dense_compl.2 <| by rwa [compl_compl] #align dense.interior_compl Dense.interior_compl /-- The closure of a set `s` is dense if and only if `s` is dense. -/ @[simp] theorem dense_closure : Dense (closure s) ↔ Dense s := by rw [Dense, Dense, closure_closure] #align dense_closure dense_closure protected alias ⟨_, Dense.closure⟩ := dense_closure alias ⟨Dense.of_closure, _⟩ := dense_closure #align dense.of_closure Dense.of_closure #align dense.closure Dense.closure @[simp] theorem dense_univ : Dense (univ : Set X) := fun _ => subset_closure trivial #align dense_univ dense_univ /-- A set is dense if and only if it has a nonempty intersection with each nonempty open set. -/ theorem dense_iff_inter_open : Dense s ↔ ∀ U, IsOpen U → U.Nonempty → (U ∩ s).Nonempty := by constructor <;> intro h · rintro U U_op ⟨x, x_in⟩ exact mem_closure_iff.1 (h _) U U_op x_in · intro x rw [mem_closure_iff] intro U U_op x_in exact h U U_op ⟨_, x_in⟩ #align dense_iff_inter_open dense_iff_inter_open alias ⟨Dense.inter_open_nonempty, _⟩ := dense_iff_inter_open #align dense.inter_open_nonempty Dense.inter_open_nonempty theorem Dense.exists_mem_open (hs : Dense s) {U : Set X} (ho : IsOpen U) (hne : U.Nonempty) : ∃ x ∈ s, x ∈ U := let ⟨x, hx⟩ := hs.inter_open_nonempty U ho hne ⟨x, hx.2, hx.1⟩ #align dense.exists_mem_open Dense.exists_mem_open theorem Dense.nonempty_iff (hs : Dense s) : s.Nonempty ↔ Nonempty X := ⟨fun ⟨x, _⟩ => ⟨x⟩, fun ⟨x⟩ => let ⟨y, hy⟩ := hs.inter_open_nonempty _ isOpen_univ ⟨x, trivial⟩ ⟨y, hy.2⟩⟩ #align dense.nonempty_iff Dense.nonempty_iff theorem Dense.nonempty [h : Nonempty X] (hs : Dense s) : s.Nonempty := hs.nonempty_iff.2 h #align dense.nonempty Dense.nonempty @[mono] theorem Dense.mono (h : s₁ ⊆ s₂) (hd : Dense s₁) : Dense s₂ := fun x => closure_mono h (hd x) #align dense.mono Dense.mono /-- Complement to a singleton is dense if and only if the singleton is not an open set. -/ theorem dense_compl_singleton_iff_not_open : Dense ({x}ᶜ : Set X) ↔ ¬IsOpen ({x} : Set X) := by constructor · intro hd ho exact (hd.inter_open_nonempty _ ho (singleton_nonempty _)).ne_empty (inter_compl_self _) · refine fun ho => dense_iff_inter_open.2 fun U hU hne => inter_compl_nonempty_iff.2 fun hUx => ?_ obtain rfl : U = {x} := eq_singleton_iff_nonempty_unique_mem.2 ⟨hne, hUx⟩ exact ho hU #align dense_compl_singleton_iff_not_open dense_compl_singleton_iff_not_open /-! ### Frontier of a set -/ @[simp] theorem closure_diff_interior (s : Set X) : closure s \ interior s = frontier s := rfl #align closure_diff_interior closure_diff_interior /-- Interior and frontier are disjoint. -/ lemma disjoint_interior_frontier : Disjoint (interior s) (frontier s) := by rw [disjoint_iff_inter_eq_empty, ← closure_diff_interior, diff_eq, ← inter_assoc, inter_comm, ← inter_assoc, compl_inter_self, empty_inter] @[simp]
Mathlib/Topology/Basic.lean
667
668
theorem closure_diff_frontier (s : Set X) : closure s \ frontier s = interior s := by
rw [frontier, diff_diff_right_self, inter_eq_self_of_subset_right interior_subset_closure]
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Mathlib.Init.Logic import Mathlib.Tactic.AdaptationNote import Mathlib.Tactic.Coe /-! # Lemmas about booleans These are the lemmas about booleans which were present in core Lean 3. See also the file Mathlib.Data.Bool.Basic which contains lemmas about booleans from mathlib 3. -/ set_option autoImplicit true -- We align Lean 3 lemmas with lemmas in `Init.SimpLemmas` in Lean 4. #align band_self Bool.and_self #align band_tt Bool.and_true #align band_ff Bool.and_false #align tt_band Bool.true_and #align ff_band Bool.false_and #align bor_self Bool.or_self #align bor_tt Bool.or_true #align bor_ff Bool.or_false #align tt_bor Bool.true_or #align ff_bor Bool.false_or #align bnot_bnot Bool.not_not namespace Bool #align bool.cond_tt Bool.cond_true #align bool.cond_ff Bool.cond_false #align cond_a_a Bool.cond_self attribute [simp] xor_self #align bxor_self Bool.xor_self #align bxor_tt Bool.xor_true #align bxor_ff Bool.xor_false #align tt_bxor Bool.true_xor #align ff_bxor Bool.false_xor theorem true_eq_false_eq_False : ¬true = false := by decide #align tt_eq_ff_eq_false Bool.true_eq_false_eq_False theorem false_eq_true_eq_False : ¬false = true := by decide #align ff_eq_tt_eq_false Bool.false_eq_true_eq_False theorem eq_false_eq_not_eq_true (b : Bool) : (¬b = true) = (b = false) := by simp #align eq_ff_eq_not_eq_tt Bool.eq_false_eq_not_eq_true theorem eq_true_eq_not_eq_false (b : Bool) : (¬b = false) = (b = true) := by simp #align eq_tt_eq_not_eq_ft Bool.eq_true_eq_not_eq_false theorem eq_false_of_not_eq_true {b : Bool} : ¬b = true → b = false := Eq.mp (eq_false_eq_not_eq_true b) #align eq_ff_of_not_eq_tt Bool.eq_false_of_not_eq_true theorem eq_true_of_not_eq_false {b : Bool} : ¬b = false → b = true := Eq.mp (eq_true_eq_not_eq_false b) #align eq_tt_of_not_eq_ff Bool.eq_true_of_not_eq_false theorem and_eq_true_eq_eq_true_and_eq_true (a b : Bool) : ((a && b) = true) = (a = true ∧ b = true) := by simp #align band_eq_true_eq_eq_tt_and_eq_tt Bool.and_eq_true_eq_eq_true_and_eq_true theorem or_eq_true_eq_eq_true_or_eq_true (a b : Bool) : ((a || b) = true) = (a = true ∨ b = true) := by simp #align bor_eq_true_eq_eq_tt_or_eq_tt Bool.or_eq_true_eq_eq_true_or_eq_true theorem not_eq_true_eq_eq_false (a : Bool) : (not a = true) = (a = false) := by cases a <;> simp #align bnot_eq_true_eq_eq_ff Bool.not_eq_true_eq_eq_false #adaptation_note /-- this is no longer a simp lemma, as after nightly-2024-03-05 the LHS simplifies. -/ theorem and_eq_false_eq_eq_false_or_eq_false (a b : Bool) : ((a && b) = false) = (a = false ∨ b = false) := by cases a <;> cases b <;> simp #align band_eq_false_eq_eq_ff_or_eq_ff Bool.and_eq_false_eq_eq_false_or_eq_false theorem or_eq_false_eq_eq_false_and_eq_false (a b : Bool) : ((a || b) = false) = (a = false ∧ b = false) := by cases a <;> cases b <;> simp #align bor_eq_false_eq_eq_ff_and_eq_ff Bool.or_eq_false_eq_eq_false_and_eq_false
Mathlib/Init/Data/Bool/Lemmas.lean
91
91
theorem not_eq_false_eq_eq_true (a : Bool) : (not a = false) = (a = true) := by
cases a <;> simp
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Order.LiminfLimsup import Mathlib.Topology.Instances.Rat import Mathlib.Topology.MetricSpace.Algebra import Mathlib.Topology.MetricSpace.IsometricSMul import Mathlib.Topology.Sequences #align_import analysis.normed.group.basic from "leanprover-community/mathlib"@"41bef4ae1254365bc190aee63b947674d2977f01" /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## TODO This file is huge; move material into separate files, such as `Mathlib/Analysis/Normed/Group/Lemmas.lean`. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 𝕜 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ #align has_norm Norm /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 #align has_nnnorm NNNorm export Norm (norm) export NNNorm (nnnorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_group SeminormedAddGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_group SeminormedGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_group NormedAddGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_group NormedGroup /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align seminormed_add_comm_group SeminormedAddCommGroup /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align seminormed_comm_group SeminormedCommGroup /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop #align normed_add_comm_group NormedAddCommGroup /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop #align normed_comm_group NormedCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } #align normed_group.to_seminormed_group NormedGroup.toSeminormedGroup #align normed_add_group.to_seminormed_add_group NormedAddGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_seminormed_comm_group NormedCommGroup.toSeminormedCommGroup #align normed_add_comm_group.to_seminormed_add_comm_group NormedAddCommGroup.toSeminormedAddCommGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } #align seminormed_comm_group.to_seminormed_group SeminormedCommGroup.toSeminormedGroup #align seminormed_add_comm_group.to_seminormed_add_group SeminormedAddCommGroup.toSeminormedAddGroup -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } #align normed_comm_group.to_normed_group NormedCommGroup.toNormedGroup #align normed_add_comm_group.to_normed_add_group NormedAddCommGroup.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] def NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| by exact (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- Porting note: the `rwa` no longer worked, but it was easy enough to provide the term. -- however, notice that if you make `x` and `y` accessible, then the following does work: -- `have := ‹SeminormedGroup E›.dist_eq x y; rwa [← this]`, so I'm not sure why the `rwa` -- was broken. #align normed_group.of_separation NormedGroup.ofSeparation #align normed_add_group.of_separation NormedAddGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive (attr := reducible) "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] def NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } #align normed_comm_group.of_separation NormedCommGroup.ofSeparation #align normed_add_comm_group.of_separation NormedAddCommGroup.ofSeparation -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant distance."] def SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y #align seminormed_group.of_mul_dist SeminormedGroup.ofMulDist #align seminormed_add_group.of_add_dist SeminormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_right_inv y] using h₂ _ _ _ #align seminormed_group.of_mul_dist' SeminormedGroup.ofMulDist' #align seminormed_add_group.of_add_dist' SeminormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist SeminormedCommGroup.ofMulDist #align seminormed_add_comm_group.of_add_dist SeminormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a seminormed group from a translation-invariant pseudodistance."] def SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align seminormed_comm_group.of_mul_dist' SeminormedCommGroup.ofMulDist' #align seminormed_add_comm_group.of_add_dist' SeminormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant distance."] def NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist NormedGroup.ofMulDist #align normed_add_group.of_add_dist NormedAddGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } #align normed_group.of_mul_dist' NormedGroup.ofMulDist' #align normed_add_group.of_add_dist' NormedAddGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist NormedCommGroup.ofMulDist #align normed_add_comm_group.of_add_dist NormedAddCommGroup.ofAddDist -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive (attr := reducible) "Construct a normed group from a translation-invariant pseudodistance."] def NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } #align normed_comm_group.of_mul_dist' NormedCommGroup.ofMulDist' #align normed_add_comm_group.of_add_dist' NormedAddCommGroup.ofAddDist' -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq x y := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f edist_dist x y := by exact ENNReal.coe_nnreal_eq _ -- Porting note: how did `mathlib3` solve this automatically? #align group_seminorm.to_seminormed_group GroupSeminorm.toSeminormedGroup #align add_group_seminorm.to_seminormed_add_group AddGroupSeminorm.toSeminormedAddGroup -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } #align group_seminorm.to_seminormed_comm_group GroupSeminorm.toSeminormedCommGroup #align add_group_seminorm.to_seminormed_add_comm_group AddGroupSeminorm.toSeminormedAddCommGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } #align group_norm.to_normed_group GroupNorm.toNormedGroup #align add_group_norm.to_normed_add_group AddGroupNorm.toNormedAddGroup -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive (attr := reducible) "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] def GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } #align group_norm.to_normed_comm_group GroupNorm.toNormedCommGroup #align add_group_norm.to_normed_add_comm_group AddGroupNorm.toNormedAddCommGroup instance PUnit.normedAddCommGroup : NormedAddCommGroup PUnit where norm := Function.const _ 0 dist_eq _ _ := rfl @[simp] theorem PUnit.norm_eq_zero (r : PUnit) : ‖r‖ = 0 := rfl #align punit.norm_eq_zero PUnit.norm_eq_zero section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ #align dist_eq_norm_div dist_eq_norm_div #align dist_eq_norm_sub dist_eq_norm_sub @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] #align dist_eq_norm_div' dist_eq_norm_div' #align dist_eq_norm_sub' dist_eq_norm_sub' alias dist_eq_norm := dist_eq_norm_sub #align dist_eq_norm dist_eq_norm alias dist_eq_norm' := dist_eq_norm_sub' #align dist_eq_norm' dist_eq_norm' @[to_additive] instance NormedGroup.to_isometricSMul_right : IsometricSMul Eᵐᵒᵖ E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_right NormedGroup.to_isometricSMul_right #align normed_add_group.to_has_isometric_vadd_right NormedAddGroup.to_isometricVAdd_right @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] #align dist_one_right dist_one_right #align dist_zero_right dist_zero_right @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive (attr := simp)] theorem dist_one_left : dist (1 : E) = norm := funext fun a => by rw [dist_comm, dist_one_right] #align dist_one_left dist_one_left #align dist_zero_left dist_zero_left @[to_additive] theorem Isometry.norm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖ = ‖x‖ := by rw [← dist_one_right, ← h₁, hi.dist_eq, dist_one_right] #align isometry.norm_map_of_map_one Isometry.norm_map_of_map_one #align isometry.norm_map_of_map_zero Isometry.norm_map_of_map_zero @[to_additive (attr := simp) comap_norm_atTop] theorem comap_norm_atTop' : comap norm atTop = cobounded E := by simpa only [dist_one_right] using comap_dist_right_atTop (1 : E) @[to_additive Filter.HasBasis.cobounded_of_norm] lemma Filter.HasBasis.cobounded_of_norm' {ι : Sort*} {p : ι → Prop} {s : ι → Set ℝ} (h : HasBasis atTop p s) : HasBasis (cobounded E) p fun i ↦ norm ⁻¹' s i := comap_norm_atTop' (E := E) ▸ h.comap _ @[to_additive Filter.hasBasis_cobounded_norm] lemma Filter.hasBasis_cobounded_norm' : HasBasis (cobounded E) (fun _ ↦ True) ({x | · ≤ ‖x‖}) := atTop_basis.cobounded_of_norm' @[to_additive (attr := simp) tendsto_norm_atTop_iff_cobounded] theorem tendsto_norm_atTop_iff_cobounded' {f : α → E} {l : Filter α} : Tendsto (‖f ·‖) l atTop ↔ Tendsto f l (cobounded E) := by rw [← comap_norm_atTop', tendsto_comap_iff]; rfl @[to_additive tendsto_norm_cobounded_atTop] theorem tendsto_norm_cobounded_atTop' : Tendsto norm (cobounded E) atTop := tendsto_norm_atTop_iff_cobounded'.2 tendsto_id @[to_additive eventually_cobounded_le_norm] lemma eventually_cobounded_le_norm' (a : ℝ) : ∀ᶠ x in cobounded E, a ≤ ‖x‖ := tendsto_norm_cobounded_atTop'.eventually_ge_atTop a @[to_additive tendsto_norm_cocompact_atTop] theorem tendsto_norm_cocompact_atTop' [ProperSpace E] : Tendsto norm (cocompact E) atTop := cobounded_eq_cocompact (α := E) ▸ tendsto_norm_cobounded_atTop' #align tendsto_norm_cocompact_at_top' tendsto_norm_cocompact_atTop' #align tendsto_norm_cocompact_at_top tendsto_norm_cocompact_atTop @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b #align norm_div_rev norm_div_rev #align norm_sub_rev norm_sub_rev @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a #align norm_inv' norm_inv' #align norm_neg norm_neg open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] @[to_additive (attr := simp)] theorem dist_mul_self_right (a b : E) : dist b (a * b) = ‖a‖ := by rw [← dist_one_left, ← dist_mul_right 1 a b, one_mul] #align dist_mul_self_right dist_mul_self_right #align dist_add_self_right dist_add_self_right @[to_additive (attr := simp)] theorem dist_mul_self_left (a b : E) : dist (a * b) b = ‖a‖ := by rw [dist_comm, dist_mul_self_right] #align dist_mul_self_left dist_mul_self_left #align dist_add_self_left dist_add_self_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_left (a b c : E) : dist (a / b) c = dist a (c * b) := by rw [← dist_mul_right _ _ b, div_mul_cancel] #align dist_div_eq_dist_mul_left dist_div_eq_dist_mul_left #align dist_sub_eq_dist_add_left dist_sub_eq_dist_add_left @[to_additive (attr := simp)] theorem dist_div_eq_dist_mul_right (a b c : E) : dist a (b / c) = dist (a * c) b := by rw [← dist_mul_right _ _ c, div_mul_cancel] #align dist_div_eq_dist_mul_right dist_div_eq_dist_mul_right #align dist_sub_eq_dist_add_right dist_sub_eq_dist_add_right @[to_additive (attr := simp)] lemma Filter.inv_cobounded : (cobounded E)⁻¹ = cobounded E := by simp only [← comap_norm_atTop', ← Filter.comap_inv, comap_comap, (· ∘ ·), norm_inv'] /-- In a (semi)normed group, inversion `x ↦ x⁻¹` tends to infinity at infinity. -/ @[to_additive "In a (semi)normed group, negation `x ↦ -x` tends to infinity at infinity."] theorem Filter.tendsto_inv_cobounded : Tendsto Inv.inv (cobounded E) (cobounded E) := inv_cobounded.le #align filter.tendsto_inv_cobounded Filter.tendsto_inv_cobounded #align filter.tendsto_neg_cobounded Filter.tendsto_neg_cobounded /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ #align norm_mul_le' norm_mul_le' #align norm_add_le norm_add_le @[to_additive] theorem norm_mul_le_of_le (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ #align norm_mul_le_of_le norm_mul_le_of_le #align norm_add_le_of_le norm_add_le_of_le @[to_additive norm_add₃_le] theorem norm_mul₃_le (a b c : E) : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le (norm_mul_le' _ _) le_rfl #align norm_mul₃_le norm_mul₃_le #align norm_add₃_le norm_add₃_le @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg #align norm_nonneg' norm_nonneg' #align norm_nonneg norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ #align abs_norm abs_norm namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are nonnegative, via `norm_nonneg'`. -/ @[positivity Norm.norm _] def evalMulNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg' $a)) | _, _, _ => throwError "not ‖ · ‖" /-- Extension for the `positivity` tactic: additive norms are nonnegative, via `norm_nonneg`. -/ @[positivity Norm.norm _] def evalAddNorm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $β $instDist $a) => let _inst ← synthInstanceQ q(SeminormedAddGroup $β) assertInstancesCommute pure (.nonnegative q(norm_nonneg $a)) | _, _, _ => throwError "not ‖ · ‖" end Mathlib.Meta.Positivity @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] #align norm_one' norm_one' #align norm_zero norm_zero @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' #align ne_one_of_norm_ne_zero ne_one_of_norm_ne_zero #align ne_zero_of_norm_ne_zero ne_zero_of_norm_ne_zero @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] #align norm_of_subsingleton' norm_of_subsingleton' #align norm_of_subsingleton norm_of_subsingleton @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity #align zero_lt_one_add_norm_sq' zero_lt_one_add_norm_sq' #align zero_lt_one_add_norm_sq zero_lt_one_add_norm_sq @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b #align norm_div_le norm_div_le #align norm_sub_le norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ #align norm_div_le_of_le norm_div_le_of_le #align norm_sub_le_of_le norm_sub_le_of_le @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le #align dist_le_norm_add_norm' dist_le_norm_add_norm' #align dist_le_norm_add_norm dist_le_norm_add_norm @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 #align abs_norm_sub_norm_le' abs_norm_sub_norm_le' #align abs_norm_sub_norm_le abs_norm_sub_norm_le @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) #align norm_sub_norm_le' norm_sub_norm_le' #align norm_sub_norm_le norm_sub_norm_le @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b #align dist_norm_norm_le' dist_norm_norm_le' #align dist_norm_norm_le dist_norm_norm_le @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] #align norm_le_norm_add_norm_div' norm_le_norm_add_norm_div' #align norm_le_norm_add_norm_sub' norm_le_norm_add_norm_sub' @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u #align norm_le_norm_add_norm_div norm_le_norm_add_norm_div #align norm_le_norm_add_norm_sub norm_le_norm_add_norm_sub alias norm_le_insert' := norm_le_norm_add_norm_sub' #align norm_le_insert' norm_le_insert' alias norm_le_insert := norm_le_norm_add_norm_sub #align norm_le_insert norm_le_insert @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ #align norm_le_mul_norm_add norm_le_mul_norm_add #align norm_le_add_norm_add norm_le_add_norm_add @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] #align ball_eq' ball_eq' #align ball_eq ball_eq @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp #align ball_one_eq ball_one_eq #align ball_zero_eq ball_zero_eq @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] #align mem_ball_iff_norm'' mem_ball_iff_norm'' #align mem_ball_iff_norm mem_ball_iff_norm @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] #align mem_ball_iff_norm''' mem_ball_iff_norm''' #align mem_ball_iff_norm' mem_ball_iff_norm' @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] #align mem_ball_one_iff mem_ball_one_iff #align mem_ball_zero_iff mem_ball_zero_iff @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] #align mem_closed_ball_iff_norm'' mem_closedBall_iff_norm'' #align mem_closed_ball_iff_norm mem_closedBall_iff_norm @[to_additive] -- Porting note (#10618): `simp` can prove it theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] #align mem_closed_ball_one_iff mem_closedBall_one_iff #align mem_closed_ball_zero_iff mem_closedBall_zero_iff @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] #align mem_closed_ball_iff_norm''' mem_closedBall_iff_norm''' #align mem_closed_ball_iff_norm' mem_closedBall_iff_norm' @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_le_of_mem_closed_ball' norm_le_of_mem_closedBall' #align norm_le_of_mem_closed_ball norm_le_of_mem_closedBall @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' #align norm_le_norm_add_const_of_dist_le' norm_le_norm_add_const_of_dist_le' #align norm_le_norm_add_const_of_dist_le norm_le_norm_add_const_of_dist_le @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ #align norm_lt_of_mem_ball' norm_lt_of_mem_ball' #align norm_lt_of_mem_ball norm_lt_of_mem_ball @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right'] using norm_sub_norm_le' (u / w) (v / w) #align norm_div_sub_norm_div_le_norm_div norm_div_sub_norm_div_le_norm_div #align norm_sub_sub_norm_sub_le_norm_sub norm_sub_sub_norm_sub_le_norm_sub @[to_additive isBounded_iff_forall_norm_le] theorem isBounded_iff_forall_norm_le' : Bornology.IsBounded s ↔ ∃ C, ∀ x ∈ s, ‖x‖ ≤ C := by simpa only [Set.subset_def, mem_closedBall_one_iff] using isBounded_iff_subset_closedBall (1 : E) #align bounded_iff_forall_norm_le' isBounded_iff_forall_norm_le' #align bounded_iff_forall_norm_le isBounded_iff_forall_norm_le alias ⟨Bornology.IsBounded.exists_norm_le', _⟩ := isBounded_iff_forall_norm_le' #align metric.bounded.exists_norm_le' Bornology.IsBounded.exists_norm_le' alias ⟨Bornology.IsBounded.exists_norm_le, _⟩ := isBounded_iff_forall_norm_le #align metric.bounded.exists_norm_le Bornology.IsBounded.exists_norm_le attribute [to_additive existing exists_norm_le] Bornology.IsBounded.exists_norm_le' @[to_additive exists_pos_norm_le] theorem Bornology.IsBounded.exists_pos_norm_le' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ ≤ R := let ⟨R₀, hR₀⟩ := hs.exists_norm_le' ⟨max R₀ 1, by positivity, fun x hx => (hR₀ x hx).trans <| le_max_left _ _⟩ #align metric.bounded.exists_pos_norm_le' Bornology.IsBounded.exists_pos_norm_le' #align metric.bounded.exists_pos_norm_le Bornology.IsBounded.exists_pos_norm_le @[to_additive Bornology.IsBounded.exists_pos_norm_lt] theorem Bornology.IsBounded.exists_pos_norm_lt' (hs : IsBounded s) : ∃ R > 0, ∀ x ∈ s, ‖x‖ < R := let ⟨R, hR₀, hR⟩ := hs.exists_pos_norm_le' ⟨R + 1, by positivity, fun x hx ↦ (hR x hx).trans_lt (lt_add_one _)⟩ @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_iff_norm' mem_sphere_iff_norm' #align mem_sphere_iff_norm mem_sphere_iff_norm @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] #align mem_sphere_one_iff_norm mem_sphere_one_iff_norm #align mem_sphere_zero_iff_norm mem_sphere_zero_iff_norm @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 #align norm_eq_of_mem_sphere' norm_eq_of_mem_sphere' #align norm_eq_of_mem_sphere norm_eq_of_mem_sphere @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] #align ne_one_of_mem_sphere ne_one_of_mem_sphere #align ne_zero_of_mem_sphere ne_zero_of_mem_sphere @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ #align ne_one_of_mem_unit_sphere ne_one_of_mem_unit_sphere #align ne_zero_of_mem_unit_sphere ne_zero_of_mem_unit_sphere variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ #align norm_group_seminorm normGroupSeminorm #align norm_add_group_seminorm normAddGroupSeminorm @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl #align coe_norm_group_seminorm coe_normGroupSeminorm #align coe_norm_add_group_seminorm coe_normAddGroupSeminorm variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] #align normed_comm_group.tendsto_nhds_one NormedCommGroup.tendsto_nhds_one #align normed_add_comm_group.tendsto_nhds_zero NormedAddCommGroup.tendsto_nhds_zero @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] #align normed_comm_group.tendsto_nhds_nhds NormedCommGroup.tendsto_nhds_nhds #align normed_add_comm_group.tendsto_nhds_nhds NormedAddCommGroup.tendsto_nhds_nhds @[to_additive] theorem NormedCommGroup.cauchySeq_iff [Nonempty α] [SemilatticeSup α] {u : α → E} : CauchySeq u ↔ ∀ ε > 0, ∃ N, ∀ m, N ≤ m → ∀ n, N ≤ n → ‖u m / u n‖ < ε := by simp [Metric.cauchySeq_iff, dist_eq_norm_div] #align normed_comm_group.cauchy_seq_iff NormedCommGroup.cauchySeq_iff #align normed_add_comm_group.cauchy_seq_iff NormedAddCommGroup.cauchySeq_iff @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball #align normed_comm_group.nhds_basis_norm_lt NormedCommGroup.nhds_basis_norm_lt #align normed_add_comm_group.nhds_basis_norm_lt NormedAddCommGroup.nhds_basis_norm_lt @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp #align normed_comm_group.nhds_one_basis_norm_lt NormedCommGroup.nhds_one_basis_norm_lt #align normed_add_comm_group.nhds_zero_basis_norm_lt NormedAddCommGroup.nhds_zero_basis_norm_lt @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] #align normed_comm_group.uniformity_basis_dist NormedCommGroup.uniformity_basis_dist #align normed_add_comm_group.uniformity_basis_dist NormedAddCommGroup.uniformity_basis_dist open Finset variable [FunLike 𝓕 E F] /-- A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`. -/ @[to_additive "A homomorphism `f` of seminormed groups is Lipschitz, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. The analogous condition for a linear map of (semi)normed spaces is in `Mathlib/Analysis/NormedSpace/OperatorNorm.lean`."] theorem MonoidHomClass.lipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : LipschitzWith (Real.toNNReal C) f := LipschitzWith.of_dist_le' fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.lipschitz_of_bound MonoidHomClass.lipschitz_of_bound #align add_monoid_hom_class.lipschitz_of_bound AddMonoidHomClass.lipschitz_of_bound @[to_additive] theorem lipschitzOnWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzOnWith C f s ↔ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzOnWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_on_with_iff_norm_div_le lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with_iff_norm_sub_le lipschitzOnWith_iff_norm_sub_le alias ⟨LipschitzOnWith.norm_div_le, _⟩ := lipschitzOnWith_iff_norm_div_le #align lipschitz_on_with.norm_div_le LipschitzOnWith.norm_div_le attribute [to_additive] LipschitzOnWith.norm_div_le @[to_additive] theorem LipschitzOnWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzOnWith C f s) (ha : a ∈ s) (hb : b ∈ s) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le ha hb).trans <| by gcongr #align lipschitz_on_with.norm_div_le_of_le LipschitzOnWith.norm_div_le_of_le #align lipschitz_on_with.norm_sub_le_of_le LipschitzOnWith.norm_sub_le_of_le @[to_additive] theorem lipschitzWith_iff_norm_div_le {f : E → F} {C : ℝ≥0} : LipschitzWith C f ↔ ∀ x y, ‖f x / f y‖ ≤ C * ‖x / y‖ := by simp only [lipschitzWith_iff_dist_le_mul, dist_eq_norm_div] #align lipschitz_with_iff_norm_div_le lipschitzWith_iff_norm_div_le #align lipschitz_with_iff_norm_sub_le lipschitzWith_iff_norm_sub_le alias ⟨LipschitzWith.norm_div_le, _⟩ := lipschitzWith_iff_norm_div_le #align lipschitz_with.norm_div_le LipschitzWith.norm_div_le attribute [to_additive] LipschitzWith.norm_div_le @[to_additive] theorem LipschitzWith.norm_div_le_of_le {f : E → F} {C : ℝ≥0} (h : LipschitzWith C f) (hr : ‖a / b‖ ≤ r) : ‖f a / f b‖ ≤ C * r := (h.norm_div_le _ _).trans <| by gcongr #align lipschitz_with.norm_div_le_of_le LipschitzWith.norm_div_le_of_le #align lipschitz_with.norm_sub_le_of_le LipschitzWith.norm_sub_le_of_le /-- A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`. -/ @[to_additive "A homomorphism `f` of seminormed groups is continuous, if there exists a constant `C` such that for all `x`, one has `‖f x‖ ≤ C * ‖x‖`"] theorem MonoidHomClass.continuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : Continuous f := (MonoidHomClass.lipschitz_of_bound f C h).continuous #align monoid_hom_class.continuous_of_bound MonoidHomClass.continuous_of_bound #align add_monoid_hom_class.continuous_of_bound AddMonoidHomClass.continuous_of_bound @[to_additive] theorem MonoidHomClass.uniformContinuous_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ) (h : ∀ x, ‖f x‖ ≤ C * ‖x‖) : UniformContinuous f := (MonoidHomClass.lipschitz_of_bound f C h).uniformContinuous #align monoid_hom_class.uniform_continuous_of_bound MonoidHomClass.uniformContinuous_of_bound #align add_monoid_hom_class.uniform_continuous_of_bound AddMonoidHomClass.uniformContinuous_of_bound @[to_additive IsCompact.exists_bound_of_continuousOn] theorem IsCompact.exists_bound_of_continuousOn' [TopologicalSpace α] {s : Set α} (hs : IsCompact s) {f : α → E} (hf : ContinuousOn f s) : ∃ C, ∀ x ∈ s, ‖f x‖ ≤ C := (isBounded_iff_forall_norm_le'.1 (hs.image_of_continuousOn hf).isBounded).imp fun _C hC _x hx => hC _ <| Set.mem_image_of_mem _ hx #align is_compact.exists_bound_of_continuous_on' IsCompact.exists_bound_of_continuousOn' #align is_compact.exists_bound_of_continuous_on IsCompact.exists_bound_of_continuousOn @[to_additive] theorem HasCompactMulSupport.exists_bound_of_continuous [TopologicalSpace α] {f : α → E} (hf : HasCompactMulSupport f) (h'f : Continuous f) : ∃ C, ∀ x, ‖f x‖ ≤ C := by simpa using (hf.isCompact_range h'f).isBounded.exists_norm_le' @[to_additive] theorem MonoidHomClass.isometry_iff_norm [MonoidHomClass 𝓕 E F] (f : 𝓕) : Isometry f ↔ ∀ x, ‖f x‖ = ‖x‖ := by simp only [isometry_iff_dist_eq, dist_eq_norm_div, ← map_div] refine ⟨fun h x => ?_, fun h x y => h _⟩ simpa using h x 1 #align monoid_hom_class.isometry_iff_norm MonoidHomClass.isometry_iff_norm #align add_monoid_hom_class.isometry_iff_norm AddMonoidHomClass.isometry_iff_norm alias ⟨_, MonoidHomClass.isometry_of_norm⟩ := MonoidHomClass.isometry_iff_norm #align monoid_hom_class.isometry_of_norm MonoidHomClass.isometry_of_norm attribute [to_additive] MonoidHomClass.isometry_of_norm section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ #align seminormed_group.to_has_nnnorm SeminormedGroup.toNNNorm #align seminormed_add_group.to_has_nnnorm SeminormedAddGroup.toNNNorm @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl #align coe_nnnorm' coe_nnnorm' #align coe_nnnorm coe_nnnorm @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl #align coe_comp_nnnorm' coe_comp_nnnorm' #align coe_comp_nnnorm coe_comp_nnnorm @[to_additive norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ #align norm_to_nnreal' norm_toNNReal' #align norm_to_nnreal norm_toNNReal @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ #align nndist_eq_nnnorm_div nndist_eq_nnnorm_div #align nndist_eq_nnnorm_sub nndist_eq_nnnorm_sub alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub #align nndist_eq_nnnorm nndist_eq_nnnorm @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' #align nnnorm_one' nnnorm_one' #align nnnorm_zero nnnorm_zero @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' #align ne_one_of_nnnorm_ne_zero ne_one_of_nnnorm_ne_zero #align ne_zero_of_nnnorm_ne_zero ne_zero_of_nnnorm_ne_zero @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b #align nnnorm_mul_le' nnnorm_mul_le' #align nnnorm_add_le nnnorm_add_le @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a #align nnnorm_inv' nnnorm_inv' #align nnnorm_neg nnnorm_neg open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ #align nnnorm_div_le nnnorm_div_le #align nnnorm_sub_le nnnorm_sub_le @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b #align nndist_nnnorm_nnnorm_le' nndist_nnnorm_nnnorm_le' #align nndist_nnnorm_nnnorm_le nndist_nnnorm_nnnorm_le @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ #align nnnorm_le_nnnorm_add_nnnorm_div nnnorm_le_nnnorm_add_nnnorm_div #align nnnorm_le_nnnorm_add_nnnorm_sub nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ #align nnnorm_le_nnnorm_add_nnnorm_div' nnnorm_le_nnnorm_add_nnnorm_div' #align nnnorm_le_nnnorm_add_nnnorm_sub' nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' #align nnnorm_le_insert' nnnorm_le_insert' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub #align nnnorm_le_insert nnnorm_le_insert @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ #align nnnorm_le_mul_nnnorm_add nnnorm_le_mul_nnnorm_add #align nnnorm_le_add_nnnorm_add nnnorm_le_add_nnnorm_add @[to_additive ofReal_norm_eq_coe_nnnorm] theorem ofReal_norm_eq_coe_nnnorm' (a : E) : ENNReal.ofReal ‖a‖ = ‖a‖₊ := ENNReal.ofReal_eq_coe_nnreal _ #align of_real_norm_eq_coe_nnnorm' ofReal_norm_eq_coe_nnnorm' #align of_real_norm_eq_coe_nnnorm ofReal_norm_eq_coe_nnnorm /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl @[to_additive] theorem edist_eq_coe_nnnorm_div (a b : E) : edist a b = ‖a / b‖₊ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_coe_nnnorm'] #align edist_eq_coe_nnnorm_div edist_eq_coe_nnnorm_div #align edist_eq_coe_nnnorm_sub edist_eq_coe_nnnorm_sub @[to_additive edist_eq_coe_nnnorm] theorem edist_eq_coe_nnnorm' (x : E) : edist x 1 = (‖x‖₊ : ℝ≥0∞) := by rw [edist_eq_coe_nnnorm_div, div_one] #align edist_eq_coe_nnnorm' edist_eq_coe_nnnorm' #align edist_eq_coe_nnnorm edist_eq_coe_nnnorm open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball (1 : E) r ↔ ↑‖a‖₊ < r := by rw [EMetric.mem_ball, edist_eq_coe_nnnorm'] #align mem_emetric_ball_one_iff mem_emetric_ball_one_iff #align mem_emetric_ball_zero_iff mem_emetric_ball_zero_iff @[to_additive] theorem MonoidHomClass.lipschitz_of_bound_nnnorm [MonoidHomClass 𝓕 E F] (f : 𝓕) (C : ℝ≥0) (h : ∀ x, ‖f x‖₊ ≤ C * ‖x‖₊) : LipschitzWith C f := @Real.toNNReal_coe C ▸ MonoidHomClass.lipschitz_of_bound f C h #align monoid_hom_class.lipschitz_of_bound_nnnorm MonoidHomClass.lipschitz_of_bound_nnnorm #align add_monoid_hom_class.lipschitz_of_bound_nnnorm AddMonoidHomClass.lipschitz_of_bound_nnnorm @[to_additive] theorem MonoidHomClass.antilipschitz_of_bound [MonoidHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : ∀ x, ‖x‖ ≤ K * ‖f x‖) : AntilipschitzWith K f := AntilipschitzWith.of_le_mul_dist fun x y => by simpa only [dist_eq_norm_div, map_div] using h (x / y) #align monoid_hom_class.antilipschitz_of_bound MonoidHomClass.antilipschitz_of_bound #align add_monoid_hom_class.antilipschitz_of_bound AddMonoidHomClass.antilipschitz_of_bound @[to_additive LipschitzWith.norm_le_mul] theorem LipschitzWith.norm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖ ≤ K * ‖x‖ := by simpa only [dist_one_right, hf] using h.dist_le_mul x 1 #align lipschitz_with.norm_le_mul' LipschitzWith.norm_le_mul' #align lipschitz_with.norm_le_mul LipschitzWith.norm_le_mul @[to_additive LipschitzWith.nnorm_le_mul] theorem LipschitzWith.nnorm_le_mul' {f : E → F} {K : ℝ≥0} (h : LipschitzWith K f) (hf : f 1 = 1) (x) : ‖f x‖₊ ≤ K * ‖x‖₊ := h.norm_le_mul' hf x #align lipschitz_with.nnorm_le_mul' LipschitzWith.nnorm_le_mul' #align lipschitz_with.nnorm_le_mul LipschitzWith.nnorm_le_mul @[to_additive AntilipschitzWith.le_mul_norm] theorem AntilipschitzWith.le_mul_norm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖ ≤ K * ‖f x‖ := by simpa only [dist_one_right, hf] using h.le_mul_dist x 1 #align antilipschitz_with.le_mul_norm' AntilipschitzWith.le_mul_norm' #align antilipschitz_with.le_mul_norm AntilipschitzWith.le_mul_norm @[to_additive AntilipschitzWith.le_mul_nnnorm] theorem AntilipschitzWith.le_mul_nnnorm' {f : E → F} {K : ℝ≥0} (h : AntilipschitzWith K f) (hf : f 1 = 1) (x) : ‖x‖₊ ≤ K * ‖f x‖₊ := h.le_mul_norm' hf x #align antilipschitz_with.le_mul_nnnorm' AntilipschitzWith.le_mul_nnnorm' #align antilipschitz_with.le_mul_nnnorm AntilipschitzWith.le_mul_nnnorm @[to_additive] theorem OneHomClass.bound_of_antilipschitz [OneHomClass 𝓕 E F] (f : 𝓕) {K : ℝ≥0} (h : AntilipschitzWith K f) (x) : ‖x‖ ≤ K * ‖f x‖ := h.le_mul_nnnorm' (map_one f) x #align one_hom_class.bound_of_antilipschitz OneHomClass.bound_of_antilipschitz #align zero_hom_class.bound_of_antilipschitz ZeroHomClass.bound_of_antilipschitz @[to_additive] theorem Isometry.nnnorm_map_of_map_one {f : E → F} (hi : Isometry f) (h₁ : f 1 = 1) (x : E) : ‖f x‖₊ = ‖x‖₊ := Subtype.ext <| hi.norm_map_of_map_one h₁ x end NNNorm @[to_additive] theorem tendsto_iff_norm_div_tendsto_zero {f : α → E} {a : Filter α} {b : E} : Tendsto f a (𝓝 b) ↔ Tendsto (fun e => ‖f e / b‖) a (𝓝 0) := by simp only [← dist_eq_norm_div, ← tendsto_iff_dist_tendsto_zero] #align tendsto_iff_norm_tendsto_one tendsto_iff_norm_div_tendsto_zero #align tendsto_iff_norm_tendsto_zero tendsto_iff_norm_sub_tendsto_zero @[to_additive] theorem tendsto_one_iff_norm_tendsto_zero {f : α → E} {a : Filter α} : Tendsto f a (𝓝 1) ↔ Tendsto (‖f ·‖) a (𝓝 0) := tendsto_iff_norm_div_tendsto_zero.trans <| by simp only [div_one] #align tendsto_one_iff_norm_tendsto_one tendsto_one_iff_norm_tendsto_zero #align tendsto_zero_iff_norm_tendsto_zero tendsto_zero_iff_norm_tendsto_zero @[to_additive] theorem comap_norm_nhds_one : comap norm (𝓝 0) = 𝓝 (1 : E) := by simpa only [dist_one_right] using nhds_comap_dist (1 : E) #align comap_norm_nhds_one comap_norm_nhds_one #align comap_norm_nhds_zero comap_norm_nhds_zero /-- Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `1` (neutral element of `SeminormedGroup`). In this pair of lemmas (`squeeze_one_norm'` and `squeeze_one_norm`), following a convention of similar lemmas in `Topology.MetricSpace.Basic` and `Topology.Algebra.Order`, the `'` version is phrased using "eventually" and the non-`'` version is phrased absolutely. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is eventually bounded by a real function `a` which tends to `0`, then `f` tends to `0`. In this pair of lemmas (`squeeze_zero_norm'` and `squeeze_zero_norm`), following a convention of similar lemmas in `Topology.MetricSpace.PseudoMetric` and `Topology.Algebra.Order`, the `'` version is phrased using \"eventually\" and the non-`'` version is phrased absolutely."] theorem squeeze_one_norm' {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ᶠ n in t₀, ‖f n‖ ≤ a n) (h' : Tendsto a t₀ (𝓝 0)) : Tendsto f t₀ (𝓝 1) := tendsto_one_iff_norm_tendsto_zero.2 <| squeeze_zero' (eventually_of_forall fun _n => norm_nonneg' _) h h' #align squeeze_one_norm' squeeze_one_norm' #align squeeze_zero_norm' squeeze_zero_norm' /-- Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `1`. -/ @[to_additive "Special case of the sandwich theorem: if the norm of `f` is bounded by a real function `a` which tends to `0`, then `f` tends to `0`."] theorem squeeze_one_norm {f : α → E} {a : α → ℝ} {t₀ : Filter α} (h : ∀ n, ‖f n‖ ≤ a n) : Tendsto a t₀ (𝓝 0) → Tendsto f t₀ (𝓝 1) := squeeze_one_norm' <| eventually_of_forall h #align squeeze_one_norm squeeze_one_norm #align squeeze_zero_norm squeeze_zero_norm @[to_additive] theorem tendsto_norm_div_self (x : E) : Tendsto (fun a => ‖a / x‖) (𝓝 x) (𝓝 0) := by simpa [dist_eq_norm_div] using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (x : E)) (𝓝 x) _) #align tendsto_norm_div_self tendsto_norm_div_self #align tendsto_norm_sub_self tendsto_norm_sub_self @[to_additive tendsto_norm] theorem tendsto_norm' {x : E} : Tendsto (fun a => ‖a‖) (𝓝 x) (𝓝 ‖x‖) := by simpa using tendsto_id.dist (tendsto_const_nhds : Tendsto (fun _a => (1 : E)) _ _) #align tendsto_norm' tendsto_norm' #align tendsto_norm tendsto_norm @[to_additive] theorem tendsto_norm_one : Tendsto (fun a : E => ‖a‖) (𝓝 1) (𝓝 0) := by simpa using tendsto_norm_div_self (1 : E) #align tendsto_norm_one tendsto_norm_one #align tendsto_norm_zero tendsto_norm_zero @[to_additive (attr := continuity) continuous_norm] theorem continuous_norm' : Continuous fun a : E => ‖a‖ := by simpa using continuous_id.dist (continuous_const : Continuous fun _a => (1 : E)) #align continuous_norm' continuous_norm' #align continuous_norm continuous_norm @[to_additive (attr := continuity) continuous_nnnorm] theorem continuous_nnnorm' : Continuous fun a : E => ‖a‖₊ := continuous_norm'.subtype_mk _ #align continuous_nnnorm' continuous_nnnorm' #align continuous_nnnorm continuous_nnnorm @[to_additive lipschitzWith_one_norm] theorem lipschitzWith_one_norm' : LipschitzWith 1 (norm : E → ℝ) := by simpa only [dist_one_left] using LipschitzWith.dist_right (1 : E) #align lipschitz_with_one_norm' lipschitzWith_one_norm' #align lipschitz_with_one_norm lipschitzWith_one_norm @[to_additive lipschitzWith_one_nnnorm] theorem lipschitzWith_one_nnnorm' : LipschitzWith 1 (NNNorm.nnnorm : E → ℝ≥0) := lipschitzWith_one_norm' #align lipschitz_with_one_nnnorm' lipschitzWith_one_nnnorm' #align lipschitz_with_one_nnnorm lipschitzWith_one_nnnorm @[to_additive uniformContinuous_norm] theorem uniformContinuous_norm' : UniformContinuous (norm : E → ℝ) := lipschitzWith_one_norm'.uniformContinuous #align uniform_continuous_norm' uniformContinuous_norm' #align uniform_continuous_norm uniformContinuous_norm @[to_additive uniformContinuous_nnnorm] theorem uniformContinuous_nnnorm' : UniformContinuous fun a : E => ‖a‖₊ := uniformContinuous_norm'.subtype_mk _ #align uniform_continuous_nnnorm' uniformContinuous_nnnorm' #align uniform_continuous_nnnorm uniformContinuous_nnnorm @[to_additive] theorem mem_closure_one_iff_norm {x : E} : x ∈ closure ({1} : Set E) ↔ ‖x‖ = 0 := by rw [← closedBall_zero', mem_closedBall_one_iff, (norm_nonneg' x).le_iff_eq] #align mem_closure_one_iff_norm mem_closure_one_iff_norm #align mem_closure_zero_iff_norm mem_closure_zero_iff_norm @[to_additive] theorem closure_one_eq : closure ({1} : Set E) = { x | ‖x‖ = 0 } := Set.ext fun _x => mem_closure_one_iff_norm #align closure_one_eq closure_one_eq #align closure_zero_eq closure_zero_eq /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ A * ‖x‖ * ‖y‖` for some constant A instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le' {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∃ A, ∀ x y, ‖op x y‖ ≤ A * ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := by cases' h_op with A h_op rcases hg with ⟨C, hC⟩; rw [eventually_map] at hC rw [NormedCommGroup.tendsto_nhds_one] at hf ⊢ intro ε ε₀ rcases exists_pos_mul_lt ε₀ (A * C) with ⟨δ, δ₀, hδ⟩ filter_upwards [hf δ δ₀, hC] with i hf hg refine (h_op _ _).trans_lt ?_ rcases le_total A 0 with hA | hA · exact (mul_nonpos_of_nonpos_of_nonneg (mul_nonpos_of_nonpos_of_nonneg hA <| norm_nonneg' _) <| norm_nonneg' _).trans_lt ε₀ calc A * ‖f i‖ * ‖g i‖ ≤ A * δ * C := by gcongr; exact hg _ = A * C * δ := mul_right_comm _ _ _ _ < ε := hδ #align filter.tendsto.op_one_is_bounded_under_le' Filter.Tendsto.op_one_isBoundedUnder_le' #align filter.tendsto.op_zero_is_bounded_under_le' Filter.Tendsto.op_zero_isBoundedUnder_le' /-- A helper lemma used to prove that the (scalar or usual) product of a function that tends to one and a bounded function tends to one. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`. -/ @[to_additive "A helper lemma used to prove that the (scalar or usual) product of a function that tends to zero and a bounded function tends to zero. This lemma is formulated for any binary operation `op : E → F → G` with an estimate `‖op x y‖ ≤ ‖x‖ * ‖y‖` instead of multiplication so that it can be applied to `(*)`, `flip (*)`, `(•)`, and `flip (•)`."] theorem Filter.Tendsto.op_one_isBoundedUnder_le {f : α → E} {g : α → F} {l : Filter α} (hf : Tendsto f l (𝓝 1)) (hg : IsBoundedUnder (· ≤ ·) l (norm ∘ g)) (op : E → F → G) (h_op : ∀ x y, ‖op x y‖ ≤ ‖x‖ * ‖y‖) : Tendsto (fun x => op (f x) (g x)) l (𝓝 1) := hf.op_one_isBoundedUnder_le' hg op ⟨1, fun x y => (one_mul ‖x‖).symm ▸ h_op x y⟩ #align filter.tendsto.op_one_is_bounded_under_le Filter.Tendsto.op_one_isBoundedUnder_le #align filter.tendsto.op_zero_is_bounded_under_le Filter.Tendsto.op_zero_isBoundedUnder_le section variable {l : Filter α} {f : α → E} @[to_additive Filter.Tendsto.norm] theorem Filter.Tendsto.norm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖) l (𝓝 ‖a‖) := tendsto_norm'.comp h #align filter.tendsto.norm' Filter.Tendsto.norm' #align filter.tendsto.norm Filter.Tendsto.norm @[to_additive Filter.Tendsto.nnnorm] theorem Filter.Tendsto.nnnorm' (h : Tendsto f l (𝓝 a)) : Tendsto (fun x => ‖f x‖₊) l (𝓝 ‖a‖₊) := Tendsto.comp continuous_nnnorm'.continuousAt h #align filter.tendsto.nnnorm' Filter.Tendsto.nnnorm' #align filter.tendsto.nnnorm Filter.Tendsto.nnnorm end section variable [TopologicalSpace α] {f : α → E} @[to_additive (attr := fun_prop) Continuous.norm] theorem Continuous.norm' : Continuous f → Continuous fun x => ‖f x‖ := continuous_norm'.comp #align continuous.norm' Continuous.norm' #align continuous.norm Continuous.norm @[to_additive (attr := fun_prop) Continuous.nnnorm] theorem Continuous.nnnorm' : Continuous f → Continuous fun x => ‖f x‖₊ := continuous_nnnorm'.comp #align continuous.nnnorm' Continuous.nnnorm' #align continuous.nnnorm Continuous.nnnorm @[to_additive (attr := fun_prop) ContinuousAt.norm] theorem ContinuousAt.norm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖) a := Tendsto.norm' h #align continuous_at.norm' ContinuousAt.norm' #align continuous_at.norm ContinuousAt.norm @[to_additive (attr := fun_prop) ContinuousAt.nnnorm] theorem ContinuousAt.nnnorm' {a : α} (h : ContinuousAt f a) : ContinuousAt (fun x => ‖f x‖₊) a := Tendsto.nnnorm' h #align continuous_at.nnnorm' ContinuousAt.nnnorm' #align continuous_at.nnnorm ContinuousAt.nnnorm @[to_additive ContinuousWithinAt.norm] theorem ContinuousWithinAt.norm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖) s a := Tendsto.norm' h #align continuous_within_at.norm' ContinuousWithinAt.norm' #align continuous_within_at.norm ContinuousWithinAt.norm @[to_additive ContinuousWithinAt.nnnorm] theorem ContinuousWithinAt.nnnorm' {s : Set α} {a : α} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x => ‖f x‖₊) s a := Tendsto.nnnorm' h #align continuous_within_at.nnnorm' ContinuousWithinAt.nnnorm' #align continuous_within_at.nnnorm ContinuousWithinAt.nnnorm @[to_additive (attr := fun_prop) ContinuousOn.norm] theorem ContinuousOn.norm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖) s := fun x hx => (h x hx).norm' #align continuous_on.norm' ContinuousOn.norm' #align continuous_on.norm ContinuousOn.norm @[to_additive (attr := fun_prop) ContinuousOn.nnnorm] theorem ContinuousOn.nnnorm' {s : Set α} (h : ContinuousOn f s) : ContinuousOn (fun x => ‖f x‖₊) s := fun x hx => (h x hx).nnnorm' #align continuous_on.nnnorm' ContinuousOn.nnnorm' #align continuous_on.nnnorm ContinuousOn.nnnorm end /-- If `‖y‖ → ∞`, then we can assume `y ≠ x` for any fixed `x`. -/ @[to_additive eventually_ne_of_tendsto_norm_atTop "If `‖y‖→∞`, then we can assume `y≠x` for any fixed `x`"] theorem eventually_ne_of_tendsto_norm_atTop' {l : Filter α} {f : α → E} (h : Tendsto (fun y => ‖f y‖) l atTop) (x : E) : ∀ᶠ y in l, f y ≠ x := (h.eventually_ne_atTop _).mono fun _x => ne_of_apply_ne norm #align eventually_ne_of_tendsto_norm_at_top' eventually_ne_of_tendsto_norm_atTop' #align eventually_ne_of_tendsto_norm_at_top eventually_ne_of_tendsto_norm_atTop @[to_additive] theorem SeminormedCommGroup.mem_closure_iff : a ∈ closure s ↔ ∀ ε, 0 < ε → ∃ b ∈ s, ‖a / b‖ < ε := by simp [Metric.mem_closure_iff, dist_eq_norm_div] #align seminormed_comm_group.mem_closure_iff SeminormedCommGroup.mem_closure_iff #align seminormed_add_comm_group.mem_closure_iff SeminormedAddCommGroup.mem_closure_iff @[to_additive norm_le_zero_iff'] theorem norm_le_zero_iff''' [T0Space E] {a : E} : ‖a‖ ≤ 0 ↔ a = 1 := by letI : NormedGroup E := { ‹SeminormedGroup E› with toMetricSpace := MetricSpace.ofT0PseudoMetricSpace E } rw [← dist_one_right, dist_le_zero] #align norm_le_zero_iff''' norm_le_zero_iff''' #align norm_le_zero_iff' norm_le_zero_iff' @[to_additive norm_eq_zero'] theorem norm_eq_zero''' [T0Space E] {a : E} : ‖a‖ = 0 ↔ a = 1 := (norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff''' #align norm_eq_zero''' norm_eq_zero''' #align norm_eq_zero' norm_eq_zero' @[to_additive norm_pos_iff'] theorem norm_pos_iff''' [T0Space E] {a : E} : 0 < ‖a‖ ↔ a ≠ 1 := by rw [← not_le, norm_le_zero_iff'''] #align norm_pos_iff''' norm_pos_iff''' #align norm_pos_iff' norm_pos_iff' @[to_additive] theorem SeminormedGroup.tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : TendstoUniformlyOn f 1 l s ↔ ∀ ε > 0, ∀ᶠ i in l, ∀ x ∈ s, ‖f i x‖ < ε := by #adaptation_note /-- nightly-2024-03-11. Originally this was `simp_rw` instead of `simp only`, but this creates a bad proof term with nested `OfNat.ofNat` that trips up `@[to_additive]`. -/ simp only [tendstoUniformlyOn_iff, Pi.one_apply, dist_one_left] #align seminormed_group.tendsto_uniformly_on_one SeminormedGroup.tendstoUniformlyOn_one #align seminormed_add_group.tendsto_uniformly_on_zero SeminormedAddGroup.tendstoUniformlyOn_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one {f : ι → κ → G} {l : Filter ι} {l' : Filter κ} : UniformCauchySeqOnFilter f l l' ↔ TendstoUniformlyOnFilter (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) l' := by refine ⟨fun hf u hu => ?_, fun hf u hu => ?_⟩ · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H 1 (f x.fst.fst x.snd / f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx · obtain ⟨ε, hε, H⟩ := uniformity_basis_dist.mem_uniformity_iff.mp hu refine (hf { p : G × G | dist p.fst p.snd < ε } <| dist_mem_uniformity hε).mono fun x hx => H (f x.fst.fst x.snd) (f x.fst.snd x.snd) ?_ simpa [dist_eq_norm_div, norm_div_rev] using hx #align seminormed_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_one SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one #align seminormed_add_group.uniform_cauchy_seq_on_filter_iff_tendsto_uniformly_on_filter_zero SeminormedAddGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_zero @[to_additive] theorem SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one {f : ι → κ → G} {s : Set κ} {l : Filter ι} : UniformCauchySeqOn f l s ↔ TendstoUniformlyOn (fun n : ι × ι => fun z => f n.fst z / f n.snd z) 1 (l ×ˢ l) s := by rw [tendstoUniformlyOn_iff_tendstoUniformlyOnFilter, uniformCauchySeqOn_iff_uniformCauchySeqOnFilter, SeminormedGroup.uniformCauchySeqOnFilter_iff_tendstoUniformlyOnFilter_one] #align seminormed_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_one SeminormedGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_one #align seminormed_add_group.uniform_cauchy_seq_on_iff_tendsto_uniformly_on_zero SeminormedAddGroup.uniformCauchySeqOn_iff_tendstoUniformlyOn_zero end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] def SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with -- Porting note: needed to add the instance explicitly, and `‹PseudoMetricSpace F›` failed norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } #align seminormed_group.induced SeminormedGroup.induced #align seminormed_add_group.induced SeminormedAddGroup.induced -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] def SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } #align seminormed_comm_group.induced SeminormedCommGroup.induced #align seminormed_add_comm_group.induced SeminormedAddCommGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] def NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } #align normed_group.induced NormedGroup.induced #align normed_add_group.induced NormedAddGroup.induced -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive (attr := reducible) "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] def NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } #align normed_comm_group.induced NormedCommGroup.induced #align normed_add_comm_group.induced NormedAddCommGroup.induced end Induced section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a a₁ a₂ b b₁ b₂ : E} {r r₁ r₂ : ℝ} @[to_additive] instance NormedGroup.to_isometricSMul_left : IsometricSMul E E := ⟨fun a => Isometry.of_dist_eq fun b c => by simp [dist_eq_norm_div]⟩ #align normed_group.to_has_isometric_smul_left NormedGroup.to_isometricSMul_left #align normed_add_group.to_has_isometric_vadd_left NormedAddGroup.to_isometricVAdd_left @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] #align dist_inv dist_inv #align dist_neg dist_neg @[to_additive (attr := simp)] theorem dist_self_mul_right (a b : E) : dist a (a * b) = ‖b‖ := by rw [← dist_one_left, ← dist_mul_left a 1 b, mul_one] #align dist_self_mul_right dist_self_mul_right #align dist_self_add_right dist_self_add_right @[to_additive (attr := simp)] theorem dist_self_mul_left (a b : E) : dist (a * b) a = ‖b‖ := by rw [dist_comm, dist_self_mul_right] #align dist_self_mul_left dist_self_mul_left #align dist_self_add_left dist_self_add_left @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_right (a b : E) : dist a (a / b) = ‖b‖ := by rw [div_eq_mul_inv, dist_self_mul_right, norm_inv'] #align dist_self_div_right dist_self_div_right #align dist_self_sub_right dist_self_sub_right @[to_additive (attr := simp 1001)] -- porting note (#10618): increase priority because `simp` can prove this theorem dist_self_div_left (a b : E) : dist (a / b) a = ‖b‖ := by rw [dist_comm, dist_self_div_right] #align dist_self_div_left dist_self_div_left #align dist_self_sub_left dist_self_sub_left @[to_additive] theorem dist_mul_mul_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ * a₂) (b₁ * b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [dist_mul_left, dist_mul_right] using dist_triangle (a₁ * a₂) (b₁ * a₂) (b₁ * b₂) #align dist_mul_mul_le dist_mul_mul_le #align dist_add_add_le dist_add_add_le @[to_additive] theorem dist_mul_mul_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ * a₂) (b₁ * b₂) ≤ r₁ + r₂ := (dist_mul_mul_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_mul_mul_le_of_le dist_mul_mul_le_of_le #align dist_add_add_le_of_le dist_add_add_le_of_le @[to_additive] theorem dist_div_div_le (a₁ a₂ b₁ b₂ : E) : dist (a₁ / a₂) (b₁ / b₂) ≤ dist a₁ b₁ + dist a₂ b₂ := by simpa only [div_eq_mul_inv, dist_inv_inv] using dist_mul_mul_le a₁ a₂⁻¹ b₁ b₂⁻¹ #align dist_div_div_le dist_div_div_le #align dist_sub_sub_le dist_sub_sub_le @[to_additive] theorem dist_div_div_le_of_le (h₁ : dist a₁ b₁ ≤ r₁) (h₂ : dist a₂ b₂ ≤ r₂) : dist (a₁ / a₂) (b₁ / b₂) ≤ r₁ + r₂ := (dist_div_div_le a₁ a₂ b₁ b₂).trans <| add_le_add h₁ h₂ #align dist_div_div_le_of_le dist_div_div_le_of_le #align dist_sub_sub_le_of_le dist_sub_sub_le_of_le @[to_additive] theorem abs_dist_sub_le_dist_mul_mul (a₁ a₂ b₁ b₂ : E) : |dist a₁ b₁ - dist a₂ b₂| ≤ dist (a₁ * a₂) (b₁ * b₂) := by simpa only [dist_mul_left, dist_mul_right, dist_comm b₂] using abs_dist_sub_le (a₁ * a₂) (b₁ * b₂) (b₁ * a₂) #align abs_dist_sub_le_dist_mul_mul abs_dist_sub_le_dist_mul_mul #align abs_dist_sub_le_dist_add_add abs_dist_sub_le_dist_add_add theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≤ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le #align norm_multiset_sum_le norm_multiset_sum_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≤ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_multiset_prod_le norm_multiset_prod_le -- Porting note: had to add `ι` here because otherwise the universe order gets switched compared to -- `norm_prod_le` below theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f #align norm_sum_le norm_sum_le @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y #align norm_prod_le norm_prod_le @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≤ n b) : ‖∏ b ∈ s, f b‖ ≤ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h #align norm_prod_le_of_le norm_prod_le_of_le #align norm_sum_le_of_le norm_sum_le_of_le @[to_additive] theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≤ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, d b := by simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h #align dist_prod_prod_le_of_le dist_prod_prod_le_of_le #align dist_sum_sum_le_of_le dist_sum_sum_le_of_le @[to_additive] theorem dist_prod_prod_le (s : Finset ι) (f a : ι → E) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, dist (f b) (a b) := dist_prod_prod_le_of_le s fun _ _ => le_rfl #align dist_prod_prod_le dist_prod_prod_le #align dist_sum_sum_le dist_sum_sum_le @[to_additive] theorem mul_mem_ball_iff_norm : a * b ∈ ball a r ↔ ‖b‖ < r := by rw [mem_ball_iff_norm'', mul_div_cancel_left] #align mul_mem_ball_iff_norm mul_mem_ball_iff_norm #align add_mem_ball_iff_norm add_mem_ball_iff_norm @[to_additive] theorem mul_mem_closedBall_iff_norm : a * b ∈ closedBall a r ↔ ‖b‖ ≤ r := by rw [mem_closedBall_iff_norm'', mul_div_cancel_left] #align mul_mem_closed_ball_iff_norm mul_mem_closedBall_iff_norm #align add_mem_closed_ball_iff_norm add_mem_closedBall_iff_norm @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_ball (a b : E) (r : ℝ) : (b * ·) ⁻¹' ball a r = ball (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] #align preimage_mul_ball preimage_mul_ball #align preimage_add_ball preimage_add_ball @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_closedBall (a b : E) (r : ℝ) : (b * ·) ⁻¹' closedBall a r = closedBall (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_closedBall, div_div_eq_mul_div, mul_comm] #align preimage_mul_closed_ball preimage_mul_closedBall #align preimage_add_closed_ball preimage_add_closedBall @[to_additive (attr := simp)] theorem preimage_mul_sphere (a b : E) (r : ℝ) : (b * ·) ⁻¹' sphere a r = sphere (a / b) r := by ext c simp only [Set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] #align preimage_mul_sphere preimage_mul_sphere #align preimage_add_sphere preimage_add_sphere @[to_additive norm_nsmul_le] theorem norm_pow_le_mul_norm (n : ℕ) (a : E) : ‖a ^ n‖ ≤ n * ‖a‖ := by induction' n with n ih; · simp simpa only [pow_succ, Nat.cast_succ, add_mul, one_mul] using norm_mul_le_of_le ih le_rfl #align norm_pow_le_mul_norm norm_pow_le_mul_norm #align norm_nsmul_le norm_nsmul_le @[to_additive nnnorm_nsmul_le] theorem nnnorm_pow_le_mul_norm (n : ℕ) (a : E) : ‖a ^ n‖₊ ≤ n * ‖a‖₊ := by simpa only [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_natCast] using norm_pow_le_mul_norm n a #align nnnorm_pow_le_mul_norm nnnorm_pow_le_mul_norm #align nnnorm_nsmul_le nnnorm_nsmul_le @[to_additive] theorem pow_mem_closedBall {n : ℕ} (h : a ∈ closedBall b r) : a ^ n ∈ closedBall (b ^ n) (n • r) := by simp only [mem_closedBall, dist_eq_norm_div, ← div_pow] at h ⊢ refine (norm_pow_le_mul_norm n (a / b)).trans ?_ simpa only [nsmul_eq_mul] using mul_le_mul_of_nonneg_left h n.cast_nonneg #align pow_mem_closed_ball pow_mem_closedBall #align nsmul_mem_closed_ball nsmul_mem_closedBall @[to_additive]
Mathlib/Analysis/Normed/Group/Basic.lean
1,713
1,718
theorem pow_mem_ball {n : ℕ} (hn : 0 < n) (h : a ∈ ball b r) : a ^ n ∈ ball (b ^ n) (n • r) := by
simp only [mem_ball, dist_eq_norm_div, ← div_pow] at h ⊢ refine lt_of_le_of_lt (norm_pow_le_mul_norm n (a / b)) ?_ replace hn : 0 < (n : ℝ) := by norm_cast rw [nsmul_eq_mul] nlinarith
/- Copyright (c) 2022 Christopher Hoskin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christopher Hoskin -/ import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.Group.Commute.Defs import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Subtype import Mathlib.Order.Notation #align_import algebra.ring.idempotents from "leanprover-community/mathlib"@"655994e298904d7e5bbd1e18c95defd7b543eb94" /-! # Idempotents This file defines idempotents for an arbitrary multiplication and proves some basic results, including: * `IsIdempotentElem.mul_of_commute`: In a semigroup, the product of two commuting idempotents is an idempotent; * `IsIdempotentElem.one_sub_iff`: In a (non-associative) ring, `p` is an idempotent if and only if `1-p` is an idempotent. * `IsIdempotentElem.pow_succ_eq`: In a monoid `p ^ (n+1) = p` for `p` an idempotent and `n` a natural number. ## Tags projection, idempotent -/ variable {M N S M₀ M₁ R G G₀ : Type*} variable [Mul M] [Monoid N] [Semigroup S] [MulZeroClass M₀] [MulOneClass M₁] [NonAssocRing R] [Group G] [CancelMonoidWithZero G₀] /-- An element `p` is said to be idempotent if `p * p = p` -/ def IsIdempotentElem (p : M) : Prop := p * p = p #align is_idempotent_elem IsIdempotentElem namespace IsIdempotentElem theorem of_isIdempotent [Std.IdempotentOp (α := M) (· * ·)] (a : M) : IsIdempotentElem a := Std.IdempotentOp.idempotent a #align is_idempotent_elem.of_is_idempotent IsIdempotentElem.of_isIdempotent theorem eq {p : M} (h : IsIdempotentElem p) : p * p = p := h #align is_idempotent_elem.eq IsIdempotentElem.eq theorem mul_of_commute {p q : S} (h : Commute p q) (h₁ : IsIdempotentElem p) (h₂ : IsIdempotentElem q) : IsIdempotentElem (p * q) := by rw [IsIdempotentElem, mul_assoc, ← mul_assoc q, ← h.eq, mul_assoc p, h₂.eq, ← mul_assoc, h₁.eq] #align is_idempotent_elem.mul_of_commute IsIdempotentElem.mul_of_commute theorem zero : IsIdempotentElem (0 : M₀) := mul_zero _ #align is_idempotent_elem.zero IsIdempotentElem.zero theorem one : IsIdempotentElem (1 : M₁) := mul_one _ #align is_idempotent_elem.one IsIdempotentElem.one theorem one_sub {p : R} (h : IsIdempotentElem p) : IsIdempotentElem (1 - p) := by rw [IsIdempotentElem, mul_sub, mul_one, sub_mul, one_mul, h.eq, sub_self, sub_zero] #align is_idempotent_elem.one_sub IsIdempotentElem.one_sub @[simp] theorem one_sub_iff {p : R} : IsIdempotentElem (1 - p) ↔ IsIdempotentElem p := ⟨fun h => sub_sub_cancel 1 p ▸ h.one_sub, IsIdempotentElem.one_sub⟩ #align is_idempotent_elem.one_sub_iff IsIdempotentElem.one_sub_iff theorem pow {p : N} (n : ℕ) (h : IsIdempotentElem p) : IsIdempotentElem (p ^ n) := Nat.recOn n ((pow_zero p).symm ▸ one) fun n _ => show p ^ n.succ * p ^ n.succ = p ^ n.succ by conv_rhs => rw [← h.eq] -- Porting note: was `nth_rw 3 [← h.eq]` rw [← sq, ← sq, ← pow_mul, ← pow_mul'] #align is_idempotent_elem.pow IsIdempotentElem.pow theorem pow_succ_eq {p : N} (n : ℕ) (h : IsIdempotentElem p) : p ^ (n + 1) = p := Nat.recOn n ((Nat.zero_add 1).symm ▸ pow_one p) fun n ih => by rw [pow_succ, ih, h.eq] #align is_idempotent_elem.pow_succ_eq IsIdempotentElem.pow_succ_eq @[simp] theorem iff_eq_one {p : G} : IsIdempotentElem p ↔ p = 1 := Iff.intro (fun h => mul_left_cancel ((mul_one p).symm ▸ h.eq : p * p = p * 1)) fun h => h.symm ▸ one #align is_idempotent_elem.iff_eq_one IsIdempotentElem.iff_eq_one @[simp]
Mathlib/Algebra/Ring/Idempotents.lean
93
97
theorem iff_eq_zero_or_one {p : G₀} : IsIdempotentElem p ↔ p = 0 ∨ p = 1 := by
refine Iff.intro (fun h => or_iff_not_imp_left.mpr fun hp => ?_) fun h => h.elim (fun hp => hp.symm ▸ zero) fun hp => hp.symm ▸ one exact mul_left_cancel₀ hp (h.trans (mul_one p).symm)
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Devon Tuma -/ import Mathlib.Topology.Instances.ENNReal import Mathlib.MeasureTheory.Measure.Dirac #align_import probability.probability_mass_function.basic from "leanprover-community/mathlib"@"4ac69b290818724c159de091daa3acd31da0ee6d" /-! # Probability mass functions This file is about probability mass functions or discrete probability measures: a function `α → ℝ≥0∞` such that the values have (infinite) sum `1`. Construction of monadic `pure` and `bind` is found in `ProbabilityMassFunction/Monad.lean`, other constructions of `PMF`s are found in `ProbabilityMassFunction/Constructions.lean`. Given `p : PMF α`, `PMF.toOuterMeasure` constructs an `OuterMeasure` on `α`, by assigning each set the sum of the probabilities of each of its elements. Under this outer measure, every set is Carathéodory-measurable, so we can further extend this to a `Measure` on `α`, see `PMF.toMeasure`. `PMF.toMeasure.isProbabilityMeasure` shows this associated measure is a probability measure. Conversely, given a probability measure `μ` on a measurable space `α` with all singleton sets measurable, `μ.toPMF` constructs a `PMF` on `α`, setting the probability mass of a point `x` to be the measure of the singleton set `{x}`. ## Tags probability mass function, discrete probability measure -/ noncomputable section variable {α β γ : Type*} open scoped Classical open NNReal ENNReal MeasureTheory /-- A probability mass function, or discrete probability measures is a function `α → ℝ≥0∞` such that the values have (infinite) sum `1`. -/ def PMF.{u} (α : Type u) : Type u := { f : α → ℝ≥0∞ // HasSum f 1 } #align pmf PMF namespace PMF instance instFunLike : FunLike (PMF α) α ℝ≥0∞ where coe p a := p.1 a coe_injective' _ _ h := Subtype.eq h #align pmf.fun_like PMF.instFunLike @[ext] protected theorem ext {p q : PMF α} (h : ∀ x, p x = q x) : p = q := DFunLike.ext p q h #align pmf.ext PMF.ext theorem ext_iff {p q : PMF α} : p = q ↔ ∀ x, p x = q x := DFunLike.ext_iff #align pmf.ext_iff PMF.ext_iff theorem hasSum_coe_one (p : PMF α) : HasSum p 1 := p.2 #align pmf.has_sum_coe_one PMF.hasSum_coe_one @[simp] theorem tsum_coe (p : PMF α) : ∑' a, p a = 1 := p.hasSum_coe_one.tsum_eq #align pmf.tsum_coe PMF.tsum_coe theorem tsum_coe_ne_top (p : PMF α) : ∑' a, p a ≠ ∞ := p.tsum_coe.symm ▸ ENNReal.one_ne_top #align pmf.tsum_coe_ne_top PMF.tsum_coe_ne_top theorem tsum_coe_indicator_ne_top (p : PMF α) (s : Set α) : ∑' a, s.indicator p a ≠ ∞ := ne_of_lt (lt_of_le_of_lt (tsum_le_tsum (fun _ => Set.indicator_apply_le fun _ => le_rfl) ENNReal.summable ENNReal.summable) (lt_of_le_of_ne le_top p.tsum_coe_ne_top)) #align pmf.tsum_coe_indicator_ne_top PMF.tsum_coe_indicator_ne_top @[simp] theorem coe_ne_zero (p : PMF α) : ⇑p ≠ 0 := fun hp => zero_ne_one ((tsum_zero.symm.trans (tsum_congr fun x => symm (congr_fun hp x))).trans p.tsum_coe) #align pmf.coe_ne_zero PMF.coe_ne_zero /-- The support of a `PMF` is the set where it is nonzero. -/ def support (p : PMF α) : Set α := Function.support p #align pmf.support PMF.support @[simp] theorem mem_support_iff (p : PMF α) (a : α) : a ∈ p.support ↔ p a ≠ 0 := Iff.rfl #align pmf.mem_support_iff PMF.mem_support_iff @[simp] theorem support_nonempty (p : PMF α) : p.support.Nonempty := Function.support_nonempty_iff.2 p.coe_ne_zero #align pmf.support_nonempty PMF.support_nonempty @[simp] theorem support_countable (p : PMF α) : p.support.Countable := Summable.countable_support_ennreal (tsum_coe_ne_top p) theorem apply_eq_zero_iff (p : PMF α) (a : α) : p a = 0 ↔ a ∉ p.support := by rw [mem_support_iff, Classical.not_not] #align pmf.apply_eq_zero_iff PMF.apply_eq_zero_iff theorem apply_pos_iff (p : PMF α) (a : α) : 0 < p a ↔ a ∈ p.support := pos_iff_ne_zero.trans (p.mem_support_iff a).symm #align pmf.apply_pos_iff PMF.apply_pos_iff theorem apply_eq_one_iff (p : PMF α) (a : α) : p a = 1 ↔ p.support = {a} := by refine ⟨fun h => Set.Subset.antisymm (fun a' ha' => by_contra fun ha => ?_) fun a' ha' => ha'.symm ▸ (p.mem_support_iff a).2 fun ha => zero_ne_one <| ha.symm.trans h, fun h => _root_.trans (symm <| tsum_eq_single a fun a' ha' => (p.apply_eq_zero_iff a').2 (h.symm ▸ ha')) p.tsum_coe⟩ suffices 1 < ∑' a, p a from ne_of_lt this p.tsum_coe.symm have : 0 < ∑' b, ite (b = a) 0 (p b) := lt_of_le_of_ne' zero_le' ((tsum_ne_zero_iff ENNReal.summable).2 ⟨a', ite_ne_left_iff.2 ⟨ha, Ne.symm <| (p.mem_support_iff a').2 ha'⟩⟩) calc 1 = 1 + 0 := (add_zero 1).symm _ < p a + ∑' b, ite (b = a) 0 (p b) := (ENNReal.add_lt_add_of_le_of_lt ENNReal.one_ne_top (le_of_eq h.symm) this) _ = ite (a = a) (p a) 0 + ∑' b, ite (b = a) 0 (p b) := by rw [eq_self_iff_true, if_true] _ = (∑' b, ite (b = a) (p b) 0) + ∑' b, ite (b = a) 0 (p b) := by congr exact symm (tsum_eq_single a fun b hb => if_neg hb) _ = ∑' b, (ite (b = a) (p b) 0 + ite (b = a) 0 (p b)) := ENNReal.tsum_add.symm _ = ∑' b, p b := tsum_congr fun b => by split_ifs <;> simp only [zero_add, add_zero, le_rfl] #align pmf.apply_eq_one_iff PMF.apply_eq_one_iff theorem coe_le_one (p : PMF α) (a : α) : p a ≤ 1 := by refine hasSum_le (fun b => ?_) (hasSum_ite_eq a (p a)) (hasSum_coe_one p) split_ifs with h <;> simp only [h, zero_le', le_rfl] #align pmf.coe_le_one PMF.coe_le_one theorem apply_ne_top (p : PMF α) (a : α) : p a ≠ ∞ := ne_of_lt (lt_of_le_of_lt (p.coe_le_one a) ENNReal.one_lt_top) #align pmf.apply_ne_top PMF.apply_ne_top theorem apply_lt_top (p : PMF α) (a : α) : p a < ∞ := lt_of_le_of_ne le_top (p.apply_ne_top a) #align pmf.apply_lt_top PMF.apply_lt_top section OuterMeasure open MeasureTheory MeasureTheory.OuterMeasure /-- Construct an `OuterMeasure` from a `PMF`, by assigning measure to each set `s : Set α` equal to the sum of `p x` for each `x ∈ α`. -/ def toOuterMeasure (p : PMF α) : OuterMeasure α := OuterMeasure.sum fun x : α => p x • dirac x #align pmf.to_outer_measure PMF.toOuterMeasure variable (p : PMF α) (s t : Set α) theorem toOuterMeasure_apply : p.toOuterMeasure s = ∑' x, s.indicator p x := tsum_congr fun x => smul_dirac_apply (p x) x s #align pmf.to_outer_measure_apply PMF.toOuterMeasure_apply @[simp] theorem toOuterMeasure_caratheodory : p.toOuterMeasure.caratheodory = ⊤ := by refine eq_top_iff.2 <| le_trans (le_sInf fun x hx => ?_) (le_sum_caratheodory _) have ⟨y, hy⟩ := hx exact ((le_of_eq (dirac_caratheodory y).symm).trans (le_smul_caratheodory _ _)).trans (le_of_eq hy) #align pmf.to_outer_measure_caratheodory PMF.toOuterMeasure_caratheodory @[simp] theorem toOuterMeasure_apply_finset (s : Finset α) : p.toOuterMeasure s = ∑ x ∈ s, p x := by refine (toOuterMeasure_apply p s).trans ((tsum_eq_sum (s := s) ?_).trans ?_) · exact fun x hx => Set.indicator_of_not_mem (Finset.mem_coe.not.2 hx) _ · exact Finset.sum_congr rfl fun x hx => Set.indicator_of_mem (Finset.mem_coe.2 hx) _ #align pmf.to_outer_measure_apply_finset PMF.toOuterMeasure_apply_finset theorem toOuterMeasure_apply_singleton (a : α) : p.toOuterMeasure {a} = p a := by refine (p.toOuterMeasure_apply {a}).trans ((tsum_eq_single a fun b hb => ?_).trans ?_) · exact ite_eq_right_iff.2 fun hb' => False.elim <| hb hb' · exact ite_eq_left_iff.2 fun ha' => False.elim <| ha' rfl #align pmf.to_outer_measure_apply_singleton PMF.toOuterMeasure_apply_singleton theorem toOuterMeasure_injective : (toOuterMeasure : PMF α → OuterMeasure α).Injective := fun p q h => PMF.ext fun x => (p.toOuterMeasure_apply_singleton x).symm.trans ((congr_fun (congr_arg _ h) _).trans <| q.toOuterMeasure_apply_singleton x) #align pmf.to_outer_measure_injective PMF.toOuterMeasure_injective @[simp] theorem toOuterMeasure_inj {p q : PMF α} : p.toOuterMeasure = q.toOuterMeasure ↔ p = q := toOuterMeasure_injective.eq_iff #align pmf.to_outer_measure_inj PMF.toOuterMeasure_inj theorem toOuterMeasure_apply_eq_zero_iff : p.toOuterMeasure s = 0 ↔ Disjoint p.support s := by rw [toOuterMeasure_apply, ENNReal.tsum_eq_zero] exact Function.funext_iff.symm.trans Set.indicator_eq_zero' #align pmf.to_outer_measure_apply_eq_zero_iff PMF.toOuterMeasure_apply_eq_zero_iff theorem toOuterMeasure_apply_eq_one_iff : p.toOuterMeasure s = 1 ↔ p.support ⊆ s := by refine (p.toOuterMeasure_apply s).symm ▸ ⟨fun h a hap => ?_, fun h => ?_⟩ · refine by_contra fun hs => ne_of_lt ?_ (h.trans p.tsum_coe.symm) have hs' : s.indicator p a = 0 := Set.indicator_apply_eq_zero.2 fun hs' => False.elim <| hs hs' have hsa : s.indicator p a < p a := hs'.symm ▸ (p.apply_pos_iff a).2 hap exact ENNReal.tsum_lt_tsum (p.tsum_coe_indicator_ne_top s) (fun x => Set.indicator_apply_le fun _ => le_rfl) hsa · suffices ∀ (x) (_ : x ∉ s), p x = 0 from _root_.trans (tsum_congr fun a => (Set.indicator_apply s p a).trans (ite_eq_left_iff.2 <| symm ∘ this a)) p.tsum_coe exact fun a ha => (p.apply_eq_zero_iff a).2 <| Set.not_mem_subset h ha #align pmf.to_outer_measure_apply_eq_one_iff PMF.toOuterMeasure_apply_eq_one_iff @[simp] theorem toOuterMeasure_apply_inter_support : p.toOuterMeasure (s ∩ p.support) = p.toOuterMeasure s := by simp only [toOuterMeasure_apply, PMF.support, Set.indicator_inter_support] #align pmf.to_outer_measure_apply_inter_support PMF.toOuterMeasure_apply_inter_support /-- Slightly stronger than `OuterMeasure.mono` having an intersection with `p.support`. -/ theorem toOuterMeasure_mono {s t : Set α} (h : s ∩ p.support ⊆ t) : p.toOuterMeasure s ≤ p.toOuterMeasure t := le_trans (le_of_eq (toOuterMeasure_apply_inter_support p s).symm) (p.toOuterMeasure.mono h) #align pmf.to_outer_measure_mono PMF.toOuterMeasure_mono theorem toOuterMeasure_apply_eq_of_inter_support_eq {s t : Set α} (h : s ∩ p.support = t ∩ p.support) : p.toOuterMeasure s = p.toOuterMeasure t := le_antisymm (p.toOuterMeasure_mono (h.symm ▸ Set.inter_subset_left)) (p.toOuterMeasure_mono (h ▸ Set.inter_subset_left)) #align pmf.to_outer_measure_apply_eq_of_inter_support_eq PMF.toOuterMeasure_apply_eq_of_inter_support_eq @[simp] theorem toOuterMeasure_apply_fintype [Fintype α] : p.toOuterMeasure s = ∑ x, s.indicator p x := (p.toOuterMeasure_apply s).trans (tsum_eq_sum fun x h => absurd (Finset.mem_univ x) h) #align pmf.to_outer_measure_apply_fintype PMF.toOuterMeasure_apply_fintype end OuterMeasure section Measure open MeasureTheory /-- Since every set is Carathéodory-measurable under `PMF.toOuterMeasure`, we can further extend this `OuterMeasure` to a `Measure` on `α`. -/ def toMeasure [MeasurableSpace α] (p : PMF α) : Measure α := p.toOuterMeasure.toMeasure ((toOuterMeasure_caratheodory p).symm ▸ le_top) #align pmf.to_measure PMF.toMeasure variable [MeasurableSpace α] (p : PMF α) (s t : Set α) theorem toOuterMeasure_apply_le_toMeasure_apply : p.toOuterMeasure s ≤ p.toMeasure s := le_toMeasure_apply p.toOuterMeasure _ s #align pmf.to_outer_measure_apply_le_to_measure_apply PMF.toOuterMeasure_apply_le_toMeasure_apply theorem toMeasure_apply_eq_toOuterMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = p.toOuterMeasure s := toMeasure_apply p.toOuterMeasure _ hs #align pmf.to_measure_apply_eq_to_outer_measure_apply PMF.toMeasure_apply_eq_toOuterMeasure_apply theorem toMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = ∑' x, s.indicator p x := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs).trans (p.toOuterMeasure_apply s) #align pmf.to_measure_apply PMF.toMeasure_apply theorem toMeasure_apply_singleton (a : α) (h : MeasurableSet ({a} : Set α)) : p.toMeasure {a} = p a := by simp [toMeasure_apply_eq_toOuterMeasure_apply _ _ h, toOuterMeasure_apply_singleton] #align pmf.to_measure_apply_singleton PMF.toMeasure_apply_singleton theorem toMeasure_apply_eq_zero_iff (hs : MeasurableSet s) : p.toMeasure s = 0 ↔ Disjoint p.support s := by rw [toMeasure_apply_eq_toOuterMeasure_apply p s hs, toOuterMeasure_apply_eq_zero_iff] #align pmf.to_measure_apply_eq_zero_iff PMF.toMeasure_apply_eq_zero_iff theorem toMeasure_apply_eq_one_iff (hs : MeasurableSet s) : p.toMeasure s = 1 ↔ p.support ⊆ s := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs).symm ▸ p.toOuterMeasure_apply_eq_one_iff s #align pmf.to_measure_apply_eq_one_iff PMF.toMeasure_apply_eq_one_iff @[simp] theorem toMeasure_apply_inter_support (hs : MeasurableSet s) (hp : MeasurableSet p.support) : p.toMeasure (s ∩ p.support) = p.toMeasure s := by simp [p.toMeasure_apply_eq_toOuterMeasure_apply s hs, p.toMeasure_apply_eq_toOuterMeasure_apply _ (hs.inter hp)] #align pmf.to_measure_apply_inter_support PMF.toMeasure_apply_inter_support @[simp] theorem restrict_toMeasure_support [MeasurableSingletonClass α] (p : PMF α) : Measure.restrict (toMeasure p) (support p) = toMeasure p := by ext s hs apply (MeasureTheory.Measure.restrict_apply hs).trans apply toMeasure_apply_inter_support p s hs p.support_countable.measurableSet theorem toMeasure_mono {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : s ∩ p.support ⊆ t) : p.toMeasure s ≤ p.toMeasure t := by simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using toOuterMeasure_mono p h #align pmf.to_measure_mono PMF.toMeasure_mono
Mathlib/Probability/ProbabilityMassFunction/Basic.lean
297
300
theorem toMeasure_apply_eq_of_inter_support_eq {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : s ∩ p.support = t ∩ p.support) : p.toMeasure s = p.toMeasure t := by
simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using toOuterMeasure_apply_eq_of_inter_support_eq p h
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Nat.Choose.Basic import Mathlib.Data.List.Perm import Mathlib.Data.List.Range #align_import data.list.sublists from "leanprover-community/mathlib"@"ccad6d5093bd2f5c6ca621fc74674cce51355af6" /-! # sublists `List.Sublists` gives a list of all (not necessarily contiguous) sublists of a list. This file contains basic results on this function. -/ /- Porting note: various auxiliary definitions such as `sublists'_aux` were left out of the port because they were only used to prove properties of `sublists`, and these proofs have changed. -/ universe u v w variable {α : Type u} {β : Type v} {γ : Type w} open Nat namespace List /-! ### sublists -/ @[simp] theorem sublists'_nil : sublists' (@nil α) = [[]] := rfl #align list.sublists'_nil List.sublists'_nil @[simp] theorem sublists'_singleton (a : α) : sublists' [a] = [[], [a]] := rfl #align list.sublists'_singleton List.sublists'_singleton #noalign list.map_sublists'_aux #noalign list.sublists'_aux_append #noalign list.sublists'_aux_eq_sublists' -- Porting note: Not the same as `sublists'_aux` from Lean3 /-- Auxiliary helper definition for `sublists'` -/ def sublists'Aux (a : α) (r₁ r₂ : List (List α)) : List (List α) := r₁.foldl (init := r₂) fun r l => r ++ [a :: l] #align list.sublists'_aux List.sublists'Aux theorem sublists'Aux_eq_array_foldl (a : α) : ∀ (r₁ r₂ : List (List α)), sublists'Aux a r₁ r₂ = ((r₁.toArray).foldl (init := r₂.toArray) (fun r l => r.push (a :: l))).toList := by intro r₁ r₂ rw [sublists'Aux, Array.foldl_eq_foldl_data] have := List.foldl_hom Array.toList (fun r l => r.push (a :: l)) (fun r l => r ++ [a :: l]) r₁ r₂.toArray (by simp) simpa using this theorem sublists'_eq_sublists'Aux (l : List α) : sublists' l = l.foldr (fun a r => sublists'Aux a r r) [[]] := by simp only [sublists', sublists'Aux_eq_array_foldl] rw [← List.foldr_hom Array.toList] · rfl · intros _ _; congr <;> simp theorem sublists'Aux_eq_map (a : α) (r₁ : List (List α)) : ∀ (r₂ : List (List α)), sublists'Aux a r₁ r₂ = r₂ ++ map (cons a) r₁ := List.reverseRecOn r₁ (fun _ => by simp [sublists'Aux]) fun r₁ l ih r₂ => by rw [map_append, map_singleton, ← append_assoc, ← ih, sublists'Aux, foldl_append, foldl] simp [sublists'Aux] -- Porting note: simp can prove `sublists'_singleton` @[simp 900] theorem sublists'_cons (a : α) (l : List α) : sublists' (a :: l) = sublists' l ++ map (cons a) (sublists' l) := by simp [sublists'_eq_sublists'Aux, foldr_cons, sublists'Aux_eq_map] #align list.sublists'_cons List.sublists'_cons @[simp] theorem mem_sublists' {s t : List α} : s ∈ sublists' t ↔ s <+ t := by induction' t with a t IH generalizing s · simp only [sublists'_nil, mem_singleton] exact ⟨fun h => by rw [h], eq_nil_of_sublist_nil⟩ simp only [sublists'_cons, mem_append, IH, mem_map] constructor <;> intro h · rcases h with (h | ⟨s, h, rfl⟩) · exact sublist_cons_of_sublist _ h · exact h.cons_cons _ · cases' h with _ _ _ h s _ _ h · exact Or.inl h · exact Or.inr ⟨s, h, rfl⟩ #align list.mem_sublists' List.mem_sublists' @[simp] theorem length_sublists' : ∀ l : List α, length (sublists' l) = 2 ^ length l | [] => rfl | a :: l => by simp_arith only [sublists'_cons, length_append, length_sublists' l, length_map, length, Nat.pow_succ'] #align list.length_sublists' List.length_sublists' @[simp] theorem sublists_nil : sublists (@nil α) = [[]] := rfl #align list.sublists_nil List.sublists_nil @[simp] theorem sublists_singleton (a : α) : sublists [a] = [[], [a]] := rfl #align list.sublists_singleton List.sublists_singleton -- Porting note: Not the same as `sublists_aux` from Lean3 /-- Auxiliary helper function for `sublists` -/ def sublistsAux (a : α) (r : List (List α)) : List (List α) := r.foldl (init := []) fun r l => r ++ [l, a :: l] #align list.sublists_aux List.sublistsAux theorem sublistsAux_eq_array_foldl : sublistsAux = fun (a : α) (r : List (List α)) => (r.toArray.foldl (init := #[]) fun r l => (r.push l).push (a :: l)).toList := by funext a r simp only [sublistsAux, Array.foldl_eq_foldl_data, Array.mkEmpty] have := foldl_hom Array.toList (fun r l => (r.push l).push (a :: l)) (fun (r : List (List α)) l => r ++ [l, a :: l]) r #[] (by simp) simpa using this theorem sublistsAux_eq_bind : sublistsAux = fun (a : α) (r : List (List α)) => r.bind fun l => [l, a :: l] := funext fun a => funext fun r => List.reverseRecOn r (by simp [sublistsAux]) (fun r l ih => by rw [append_bind, ← ih, bind_singleton, sublistsAux, foldl_append] simp [sublistsAux]) @[csimp] theorem sublists_eq_sublistsFast : @sublists = @sublistsFast := by ext α l : 2 trans l.foldr sublistsAux [[]] · rw [sublistsAux_eq_bind, sublists] · simp only [sublistsFast, sublistsAux_eq_array_foldl, Array.foldr_eq_foldr_data] rw [← foldr_hom Array.toList] · rfl · intros _ _; congr <;> simp #noalign list.sublists_aux₁_eq_sublists_aux #noalign list.sublists_aux_cons_eq_sublists_aux₁ #noalign list.sublists_aux_eq_foldr.aux #noalign list.sublists_aux_eq_foldr #noalign list.sublists_aux_cons_cons #noalign list.sublists_aux₁_append #noalign list.sublists_aux₁_concat #noalign list.sublists_aux₁_bind #noalign list.sublists_aux_cons_append theorem sublists_append (l₁ l₂ : List α) : sublists (l₁ ++ l₂) = (sublists l₂) >>= (fun x => (sublists l₁).map (· ++ x)) := by simp only [sublists, foldr_append] induction l₁ with | nil => simp | cons a l₁ ih => rw [foldr_cons, ih] simp [List.bind, join_join, Function.comp] #align list.sublists_append List.sublists_append -- Porting note (#10756): new theorem theorem sublists_cons (a : α) (l : List α) : sublists (a :: l) = sublists l >>= (fun x => [x, a :: x]) := show sublists ([a] ++ l) = _ by rw [sublists_append] simp only [sublists_singleton, map_cons, bind_eq_bind, nil_append, cons_append, map_nil] @[simp] theorem sublists_concat (l : List α) (a : α) : sublists (l ++ [a]) = sublists l ++ map (fun x => x ++ [a]) (sublists l) := by rw [sublists_append, sublists_singleton, bind_eq_bind, cons_bind, cons_bind, nil_bind, map_id'' append_nil, append_nil] #align list.sublists_concat List.sublists_concat theorem sublists_reverse (l : List α) : sublists (reverse l) = map reverse (sublists' l) := by induction' l with hd tl ih <;> [rfl; simp only [reverse_cons, sublists_append, sublists'_cons, map_append, ih, sublists_singleton, map_eq_map, bind_eq_bind, map_map, cons_bind, append_nil, nil_bind, (· ∘ ·)]] #align list.sublists_reverse List.sublists_reverse theorem sublists_eq_sublists' (l : List α) : sublists l = map reverse (sublists' (reverse l)) := by rw [← sublists_reverse, reverse_reverse] #align list.sublists_eq_sublists' List.sublists_eq_sublists' theorem sublists'_reverse (l : List α) : sublists' (reverse l) = map reverse (sublists l) := by simp only [sublists_eq_sublists', map_map, map_id'' reverse_reverse, Function.comp] #align list.sublists'_reverse List.sublists'_reverse theorem sublists'_eq_sublists (l : List α) : sublists' l = map reverse (sublists (reverse l)) := by rw [← sublists'_reverse, reverse_reverse] #align list.sublists'_eq_sublists List.sublists'_eq_sublists #noalign list.sublists_aux_ne_nil @[simp] theorem mem_sublists {s t : List α} : s ∈ sublists t ↔ s <+ t := by rw [← reverse_sublist, ← mem_sublists', sublists'_reverse, mem_map_of_injective reverse_injective] #align list.mem_sublists List.mem_sublists @[simp]
Mathlib/Data/List/Sublists.lean
210
211
theorem length_sublists (l : List α) : length (sublists l) = 2 ^ length l := by
simp only [sublists_eq_sublists', length_map, length_sublists', length_reverse]
/- Copyright (c) 2021 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.Algebra.MvPolynomial.Supported import Mathlib.LinearAlgebra.LinearIndependent import Mathlib.RingTheory.Adjoin.Basic import Mathlib.RingTheory.Algebraic import Mathlib.RingTheory.MvPolynomial.Basic #align_import ring_theory.algebraic_independent from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69" /-! # Algebraic Independence This file defines algebraic independence of a family of element of an `R` algebra. ## Main definitions * `AlgebraicIndependent` - `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. * `AlgebraicIndependent.repr` - The canonical map from the subalgebra generated by an algebraic independent family into the polynomial ring. ## References * [Stacks: Transcendence](https://stacks.math.columbia.edu/tag/030D) ## TODO Define the transcendence degree and show it is independent of the choice of a transcendence basis. ## Tags transcendence basis, transcendence degree, transcendence -/ noncomputable section open Function Set Subalgebra MvPolynomial Algebra open scoped Classical universe x u v w variable {ι : Type*} {ι' : Type*} (R : Type*) {K : Type*} variable {A : Type*} {A' A'' : Type*} {V : Type u} {V' : Type*} variable (x : ι → A) variable [CommRing R] [CommRing A] [CommRing A'] [CommRing A''] variable [Algebra R A] [Algebra R A'] [Algebra R A''] variable {a b : R} /-- `AlgebraicIndependent R x` states the family of elements `x` is algebraically independent over `R`, meaning that the canonical map out of the multivariable polynomial ring is injective. -/ def AlgebraicIndependent : Prop := Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) #align algebraic_independent AlgebraicIndependent variable {R} {x} theorem algebraicIndependent_iff_ker_eq_bot : AlgebraicIndependent R x ↔ RingHom.ker (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom = ⊥ := RingHom.injective_iff_ker_eq_bot _ #align algebraic_independent_iff_ker_eq_bot algebraicIndependent_iff_ker_eq_bot theorem algebraicIndependent_iff : AlgebraicIndependent R x ↔ ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := injective_iff_map_eq_zero _ #align algebraic_independent_iff algebraicIndependent_iff theorem AlgebraicIndependent.eq_zero_of_aeval_eq_zero (h : AlgebraicIndependent R x) : ∀ p : MvPolynomial ι R, MvPolynomial.aeval (x : ι → A) p = 0 → p = 0 := algebraicIndependent_iff.1 h #align algebraic_independent.eq_zero_of_aeval_eq_zero AlgebraicIndependent.eq_zero_of_aeval_eq_zero theorem algebraicIndependent_iff_injective_aeval : AlgebraicIndependent R x ↔ Injective (MvPolynomial.aeval x : MvPolynomial ι R →ₐ[R] A) := Iff.rfl #align algebraic_independent_iff_injective_aeval algebraicIndependent_iff_injective_aeval @[simp] theorem algebraicIndependent_empty_type_iff [IsEmpty ι] : AlgebraicIndependent R x ↔ Injective (algebraMap R A) := by have : aeval x = (Algebra.ofId R A).comp (@isEmptyAlgEquiv R ι _ _).toAlgHom := by ext i exact IsEmpty.elim' ‹IsEmpty ι› i rw [AlgebraicIndependent, this, ← Injective.of_comp_iff' _ (@isEmptyAlgEquiv R ι _ _).bijective] rfl #align algebraic_independent_empty_type_iff algebraicIndependent_empty_type_iff namespace AlgebraicIndependent variable (hx : AlgebraicIndependent R x) theorem algebraMap_injective : Injective (algebraMap R A) := by simpa [Function.comp] using (Injective.of_comp_iff (algebraicIndependent_iff_injective_aeval.1 hx) MvPolynomial.C).2 (MvPolynomial.C_injective _ _) #align algebraic_independent.algebra_map_injective AlgebraicIndependent.algebraMap_injective theorem linearIndependent : LinearIndependent R x := by rw [linearIndependent_iff_injective_total] have : Finsupp.total ι A R x = (MvPolynomial.aeval x).toLinearMap.comp (Finsupp.total ι _ R X) := by ext simp rw [this] refine hx.comp ?_ rw [← linearIndependent_iff_injective_total] exact linearIndependent_X _ _ #align algebraic_independent.linear_independent AlgebraicIndependent.linearIndependent protected theorem injective [Nontrivial R] : Injective x := hx.linearIndependent.injective #align algebraic_independent.injective AlgebraicIndependent.injective theorem ne_zero [Nontrivial R] (i : ι) : x i ≠ 0 := hx.linearIndependent.ne_zero i #align algebraic_independent.ne_zero AlgebraicIndependent.ne_zero theorem comp (f : ι' → ι) (hf : Function.Injective f) : AlgebraicIndependent R (x ∘ f) := by intro p q simpa [aeval_rename, (rename_injective f hf).eq_iff] using @hx (rename f p) (rename f q) #align algebraic_independent.comp AlgebraicIndependent.comp theorem coe_range : AlgebraicIndependent R ((↑) : range x → A) := by simpa using hx.comp _ (rangeSplitting_injective x) #align algebraic_independent.coe_range AlgebraicIndependent.coe_range theorem map {f : A →ₐ[R] A'} (hf_inj : Set.InjOn f (adjoin R (range x))) : AlgebraicIndependent R (f ∘ x) := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp have h : ∀ p : MvPolynomial ι R, aeval x p ∈ (@aeval R _ _ _ _ _ ((↑) : range x → A)).range := by intro p rw [AlgHom.mem_range] refine ⟨MvPolynomial.rename (codRestrict x (range x) mem_range_self) p, ?_⟩ simp [Function.comp, aeval_rename] intro x y hxy rw [this] at hxy rw [adjoin_eq_range] at hf_inj exact hx (hf_inj (h x) (h y) hxy) #align algebraic_independent.map AlgebraicIndependent.map theorem map' {f : A →ₐ[R] A'} (hf_inj : Injective f) : AlgebraicIndependent R (f ∘ x) := hx.map hf_inj.injOn #align algebraic_independent.map' AlgebraicIndependent.map' theorem of_comp (f : A →ₐ[R] A') (hfv : AlgebraicIndependent R (f ∘ x)) : AlgebraicIndependent R x := by have : aeval (f ∘ x) = f.comp (aeval x) := by ext; simp rw [AlgebraicIndependent, this, AlgHom.coe_comp] at hfv exact hfv.of_comp #align algebraic_independent.of_comp AlgebraicIndependent.of_comp end AlgebraicIndependent open AlgebraicIndependent theorem AlgHom.algebraicIndependent_iff (f : A →ₐ[R] A') (hf : Injective f) : AlgebraicIndependent R (f ∘ x) ↔ AlgebraicIndependent R x := ⟨fun h => h.of_comp f, fun h => h.map hf.injOn⟩ #align alg_hom.algebraic_independent_iff AlgHom.algebraicIndependent_iff @[nontriviality] theorem algebraicIndependent_of_subsingleton [Subsingleton R] : AlgebraicIndependent R x := algebraicIndependent_iff.2 fun _ _ => Subsingleton.elim _ _ #align algebraic_independent_of_subsingleton algebraicIndependent_of_subsingleton theorem algebraicIndependent_equiv (e : ι ≃ ι') {f : ι' → A} : AlgebraicIndependent R (f ∘ e) ↔ AlgebraicIndependent R f := ⟨fun h => Function.comp_id f ▸ e.self_comp_symm ▸ h.comp _ e.symm.injective, fun h => h.comp _ e.injective⟩ #align algebraic_independent_equiv algebraicIndependent_equiv theorem algebraicIndependent_equiv' (e : ι ≃ ι') {f : ι' → A} {g : ι → A} (h : f ∘ e = g) : AlgebraicIndependent R g ↔ AlgebraicIndependent R f := h ▸ algebraicIndependent_equiv e #align algebraic_independent_equiv' algebraicIndependent_equiv' theorem algebraicIndependent_subtype_range {ι} {f : ι → A} (hf : Injective f) : AlgebraicIndependent R ((↑) : range f → A) ↔ AlgebraicIndependent R f := Iff.symm <| algebraicIndependent_equiv' (Equiv.ofInjective f hf) rfl #align algebraic_independent_subtype_range algebraicIndependent_subtype_range alias ⟨AlgebraicIndependent.of_subtype_range, _⟩ := algebraicIndependent_subtype_range #align algebraic_independent.of_subtype_range AlgebraicIndependent.of_subtype_range theorem algebraicIndependent_image {ι} {s : Set ι} {f : ι → A} (hf : Set.InjOn f s) : (AlgebraicIndependent R fun x : s => f x) ↔ AlgebraicIndependent R fun x : f '' s => (x : A) := algebraicIndependent_equiv' (Equiv.Set.imageOfInjOn _ _ hf) rfl #align algebraic_independent_image algebraicIndependent_image theorem algebraicIndependent_adjoin (hs : AlgebraicIndependent R x) : @AlgebraicIndependent ι R (adjoin R (range x)) (fun i : ι => ⟨x i, subset_adjoin (mem_range_self i)⟩) _ _ _ := AlgebraicIndependent.of_comp (adjoin R (range x)).val hs #align algebraic_independent_adjoin algebraicIndependent_adjoin /-- A set of algebraically independent elements in an algebra `A` over a ring `K` is also algebraically independent over a subring `R` of `K`. -/ theorem AlgebraicIndependent.restrictScalars {K : Type*} [CommRing K] [Algebra R K] [Algebra K A] [IsScalarTower R K A] (hinj : Function.Injective (algebraMap R K)) (ai : AlgebraicIndependent K x) : AlgebraicIndependent R x := by have : (aeval x : MvPolynomial ι K →ₐ[K] A).toRingHom.comp (MvPolynomial.map (algebraMap R K)) = (aeval x : MvPolynomial ι R →ₐ[R] A).toRingHom := by ext <;> simp [algebraMap_eq_smul_one] show Injective (aeval x).toRingHom rw [← this, RingHom.coe_comp] exact Injective.comp ai (MvPolynomial.map_injective _ hinj) #align algebraic_independent.restrict_scalars AlgebraicIndependent.restrictScalars /-- Every finite subset of an algebraically independent set is algebraically independent. -/ theorem algebraicIndependent_finset_map_embedding_subtype (s : Set A) (li : AlgebraicIndependent R ((↑) : s → A)) (t : Finset s) : AlgebraicIndependent R ((↑) : Finset.map (Embedding.subtype s) t → A) := by let f : t.map (Embedding.subtype s) → s := fun x => ⟨x.1, by obtain ⟨x, h⟩ := x rw [Finset.mem_map] at h obtain ⟨a, _, rfl⟩ := h simp only [Subtype.coe_prop, Embedding.coe_subtype]⟩ convert AlgebraicIndependent.comp li f _ rintro ⟨x, hx⟩ ⟨y, hy⟩ rw [Finset.mem_map] at hx hy obtain ⟨a, _, rfl⟩ := hx obtain ⟨b, _, rfl⟩ := hy simp only [f, imp_self, Subtype.mk_eq_mk] #align algebraic_independent_finset_map_embedding_subtype algebraicIndependent_finset_map_embedding_subtype /-- If every finite set of algebraically independent element has cardinality at most `n`, then the same is true for arbitrary sets of algebraically independent elements. -/
Mathlib/RingTheory/AlgebraicIndependent.lean
240
248
theorem algebraicIndependent_bounded_of_finset_algebraicIndependent_bounded {n : ℕ} (H : ∀ s : Finset A, (AlgebraicIndependent R fun i : s => (i : A)) → s.card ≤ n) : ∀ s : Set A, AlgebraicIndependent R ((↑) : s → A) → Cardinal.mk s ≤ n := by
intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply algebraicIndependent_finset_map_embedding_subtype _ li
/- Copyright (c) 2022 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Oleksandr Manzyuk -/ import Mathlib.CategoryTheory.Bicategory.Basic import Mathlib.CategoryTheory.Monoidal.Mon_ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers #align_import category_theory.monoidal.Bimod from "leanprover-community/mathlib"@"4698e35ca56a0d4fa53aa5639c3364e0a77f4eba" /-! # The category of bimodule objects over a pair of monoid objects. -/ universe v₁ v₂ u₁ u₂ open CategoryTheory open CategoryTheory.MonoidalCategory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory.{v₁} C] section open CategoryTheory.Limits variable [HasCoequalizers C] section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] theorem id_tensor_π_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Z ⊗ Y ⟶ W) (wh : (Z ◁ f) ≫ h = (Z ◁ g) ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorLeft Z) f g h wh #align id_tensor_π_preserves_coequalizer_inv_desc id_tensor_π_preserves_coequalizer_inv_desc theorem id_tensor_π_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : Z ⊗ X ⟶ X') (q : Z ⊗ Y ⟶ Y') (wf : (Z ◁ f) ≫ q = p ≫ f') (wg : (Z ◁ g) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (Z ◁ coequalizer.π f g) ≫ (PreservesCoequalizer.iso (tensorLeft Z) f g).inv ≫ colimMap (parallelPairHom (Z ◁ f) (Z ◁ g) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorLeft Z) f g f' g' p q wf wg h wh #align id_tensor_π_preserves_coequalizer_inv_colim_map_desc id_tensor_π_preserves_coequalizer_inv_colimMap_desc end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem π_tensor_id_preserves_coequalizer_inv_desc {W X Y Z : C} (f g : X ⟶ Y) (h : Y ⊗ Z ⟶ W) (wh : (f ▷ Z) ≫ h = (g ▷ Z) ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ coequalizer.desc h wh = h := map_π_preserves_coequalizer_inv_desc (tensorRight Z) f g h wh #align π_tensor_id_preserves_coequalizer_inv_desc π_tensor_id_preserves_coequalizer_inv_desc theorem π_tensor_id_preserves_coequalizer_inv_colimMap_desc {X Y Z X' Y' Z' : C} (f g : X ⟶ Y) (f' g' : X' ⟶ Y') (p : X ⊗ Z ⟶ X') (q : Y ⊗ Z ⟶ Y') (wf : (f ▷ Z) ≫ q = p ≫ f') (wg : (g ▷ Z) ≫ q = p ≫ g') (h : Y' ⟶ Z') (wh : f' ≫ h = g' ≫ h) : (coequalizer.π f g ▷ Z) ≫ (PreservesCoequalizer.iso (tensorRight Z) f g).inv ≫ colimMap (parallelPairHom (f ▷ Z) (g ▷ Z) f' g' p q wf wg) ≫ coequalizer.desc h wh = q ≫ h := map_π_preserves_coequalizer_inv_colimMap_desc (tensorRight Z) f g f' g' p q wf wg h wh #align π_tensor_id_preserves_coequalizer_inv_colim_map_desc π_tensor_id_preserves_coequalizer_inv_colimMap_desc end end /-- A bimodule object for a pair of monoid objects, all internal to some monoidal category. -/ structure Bimod (A B : Mon_ C) where X : C actLeft : A.X ⊗ X ⟶ X one_actLeft : (A.one ▷ X) ≫ actLeft = (λ_ X).hom := by aesop_cat left_assoc : (A.mul ▷ X) ≫ actLeft = (α_ A.X A.X X).hom ≫ (A.X ◁ actLeft) ≫ actLeft := by aesop_cat actRight : X ⊗ B.X ⟶ X actRight_one : (X ◁ B.one) ≫ actRight = (ρ_ X).hom := by aesop_cat right_assoc : (X ◁ B.mul) ≫ actRight = (α_ X B.X B.X).inv ≫ (actRight ▷ B.X) ≫ actRight := by aesop_cat middle_assoc : (actLeft ▷ B.X) ≫ actRight = (α_ A.X X B.X).hom ≫ (A.X ◁ actRight) ≫ actLeft := by aesop_cat set_option linter.uppercaseLean3 false in #align Bimod Bimod attribute [reassoc (attr := simp)] Bimod.one_actLeft Bimod.actRight_one Bimod.left_assoc Bimod.right_assoc Bimod.middle_assoc namespace Bimod variable {A B : Mon_ C} (M : Bimod A B) /-- A morphism of bimodule objects. -/ @[ext] structure Hom (M N : Bimod A B) where hom : M.X ⟶ N.X left_act_hom : M.actLeft ≫ hom = (A.X ◁ hom) ≫ N.actLeft := by aesop_cat right_act_hom : M.actRight ≫ hom = (hom ▷ B.X) ≫ N.actRight := by aesop_cat set_option linter.uppercaseLean3 false in #align Bimod.hom Bimod.Hom attribute [reassoc (attr := simp)] Hom.left_act_hom Hom.right_act_hom /-- The identity morphism on a bimodule object. -/ @[simps] def id' (M : Bimod A B) : Hom M M where hom := 𝟙 M.X set_option linter.uppercaseLean3 false in #align Bimod.id' Bimod.id' instance homInhabited (M : Bimod A B) : Inhabited (Hom M M) := ⟨id' M⟩ set_option linter.uppercaseLean3 false in #align Bimod.hom_inhabited Bimod.homInhabited /-- Composition of bimodule object morphisms. -/ @[simps] def comp {M N O : Bimod A B} (f : Hom M N) (g : Hom N O) : Hom M O where hom := f.hom ≫ g.hom set_option linter.uppercaseLean3 false in #align Bimod.comp Bimod.comp instance : Category (Bimod A B) where Hom M N := Hom M N id := id' comp f g := comp f g -- Porting note: added because `Hom.ext` is not triggered automatically @[ext] lemma hom_ext {M N : Bimod A B} (f g : M ⟶ N) (h : f.hom = g.hom) : f = g := Hom.ext _ _ h @[simp] theorem id_hom' (M : Bimod A B) : (𝟙 M : Hom M M).hom = 𝟙 M.X := rfl set_option linter.uppercaseLean3 false in #align Bimod.id_hom' Bimod.id_hom' @[simp] theorem comp_hom' {M N K : Bimod A B} (f : M ⟶ N) (g : N ⟶ K) : (f ≫ g : Hom M K).hom = f.hom ≫ g.hom := rfl set_option linter.uppercaseLean3 false in #align Bimod.comp_hom' Bimod.comp_hom' /-- Construct an isomorphism of bimodules by giving an isomorphism between the underlying objects and checking compatibility with left and right actions only in the forward direction. -/ @[simps] def isoOfIso {X Y : Mon_ C} {P Q : Bimod X Y} (f : P.X ≅ Q.X) (f_left_act_hom : P.actLeft ≫ f.hom = (X.X ◁ f.hom) ≫ Q.actLeft) (f_right_act_hom : P.actRight ≫ f.hom = (f.hom ▷ Y.X) ≫ Q.actRight) : P ≅ Q where hom := { hom := f.hom } inv := { hom := f.inv left_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_left_act_hom, ← Category.assoc, ← MonoidalCategory.whiskerLeft_comp, Iso.inv_hom_id, MonoidalCategory.whiskerLeft_id, Category.id_comp] right_act_hom := by rw [← cancel_mono f.hom, Category.assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id, f_right_act_hom, ← Category.assoc, ← comp_whiskerRight, Iso.inv_hom_id, MonoidalCategory.id_whiskerRight, Category.id_comp] } hom_inv_id := by ext; dsimp; rw [Iso.hom_inv_id] inv_hom_id := by ext; dsimp; rw [Iso.inv_hom_id] set_option linter.uppercaseLean3 false in #align Bimod.iso_of_iso Bimod.isoOfIso variable (A) /-- A monoid object as a bimodule over itself. -/ @[simps] def regular : Bimod A A where X := A.X actLeft := A.mul actRight := A.mul set_option linter.uppercaseLean3 false in #align Bimod.regular Bimod.regular instance : Inhabited (Bimod A A) := ⟨regular A⟩ /-- The forgetful functor from bimodule objects to the ambient category. -/ def forget : Bimod A B ⥤ C where obj A := A.X map f := f.hom set_option linter.uppercaseLean3 false in #align Bimod.forget Bimod.forget open CategoryTheory.Limits variable [HasCoequalizers C] namespace TensorBimod variable {R S T : Mon_ C} (P : Bimod R S) (Q : Bimod S T) /-- The underlying object of the tensor product of two bimodules. -/ noncomputable def X : C := coequalizer (P.actRight ▷ Q.X) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actLeft)) set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.X Bimod.TensorBimod.X section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] /-- Left action for the tensor product of two bimodules. -/ noncomputable def actLeft : R.X ⊗ X P Q ⟶ X P Q := (PreservesCoequalizer.iso (tensorLeft R.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).inv ≫ ((α_ _ _ _).inv ▷ _) ≫ (P.actLeft ▷ S.X ▷ Q.X)) ((α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X)) (by dsimp simp only [Category.assoc] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_rhs 3 4 => rw [← comp_whiskerRight, middle_assoc, comp_whiskerRight] coherence) (by dsimp slice_lhs 1 1 => rw [MonoidalCategory.whiskerLeft_comp] slice_lhs 2 3 => rw [associator_inv_naturality_right] slice_lhs 3 4 => rw [whisker_exchange] coherence)) set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.act_left Bimod.TensorBimod.actLeft theorem whiskerLeft_π_actLeft : (R.X ◁ coequalizer.π _ _) ≫ actLeft P Q = (α_ _ _ _).inv ≫ (P.actLeft ▷ Q.X) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorLeft _)] simp only [Category.assoc] set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.id_tensor_π_act_left Bimod.TensorBimod.whiskerLeft_π_actLeft theorem one_act_left' : (R.one ▷ _) ≫ actLeft P Q = (λ_ _).hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 => erw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, one_actLeft] slice_rhs 1 2 => rw [leftUnitor_naturality] coherence set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.one_act_left' Bimod.TensorBimod.one_act_left' theorem left_assoc' : (R.mul ▷ _) ≫ actLeft P Q = (α_ R.X R.X _).hom ≫ (R.X ◁ actLeft P Q) ≫ actLeft P Q := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [X] slice_lhs 1 2 => rw [whisker_exchange] slice_lhs 2 3 => rw [whiskerLeft_π_actLeft] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, left_assoc, comp_whiskerRight, comp_whiskerRight] slice_rhs 1 2 => rw [associator_naturality_right] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 5 => rw [whiskerLeft_π_actLeft] slice_rhs 3 4 => rw [associator_inv_naturality_middle] coherence set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.left_assoc' Bimod.TensorBimod.left_assoc' end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- Right action for the tensor product of two bimodules. -/ noncomputable def actRight : X P Q ⊗ T.X ⟶ X P Q := (PreservesCoequalizer.iso (tensorRight T.X) _ _).inv ≫ colimMap (parallelPairHom _ _ _ _ ((α_ _ _ _).hom ≫ (α_ _ _ _).hom ≫ (P.X ◁ S.X ◁ Q.actRight) ≫ (α_ _ _ _).inv) ((α_ _ _ _).hom ≫ (P.X ◁ Q.actRight)) (by dsimp slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] simp) (by dsimp simp only [comp_whiskerRight, whisker_assoc, Category.assoc, Iso.inv_hom_id_assoc] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, middle_assoc, MonoidalCategory.whiskerLeft_comp] simp)) set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.act_right Bimod.TensorBimod.actRight theorem π_tensor_id_actRight : (coequalizer.π _ _ ▷ T.X) ≫ actRight P Q = (α_ _ _ _).hom ≫ (P.X ◁ Q.actRight) ≫ coequalizer.π _ _ := by erw [map_π_preserves_coequalizer_inv_colimMap (tensorRight _)] simp only [Category.assoc] set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.π_tensor_id_act_right Bimod.TensorBimod.π_tensor_id_actRight theorem actRight_one' : (_ ◁ T.one) ≫ actRight P Q = (ρ_ _).hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace `rw` by `erw` slice_lhs 1 2 =>erw [← whisker_exchange] slice_lhs 2 3 => rw [π_tensor_id_actRight] slice_lhs 1 2 => rw [associator_naturality_right] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, actRight_one] simp set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.act_right_one' Bimod.TensorBimod.actRight_one' theorem right_assoc' : (_ ◁ T.mul) ≫ actRight P Q = (α_ _ T.X T.X).inv ≫ (actRight P Q ▷ T.X) ≫ actRight P Q := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] -- Porting note: had to replace some `rw` by `erw` slice_lhs 1 2 => rw [← whisker_exchange] slice_lhs 2 3 => rw [π_tensor_id_actRight] slice_lhs 1 2 => rw [associator_naturality_right] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, right_assoc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_inv_naturality_left] slice_rhs 2 3 => rw [← comp_whiskerRight, π_tensor_id_actRight, comp_whiskerRight, comp_whiskerRight] slice_rhs 4 5 => rw [π_tensor_id_actRight] simp set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.right_assoc' Bimod.TensorBimod.right_assoc' end section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem middle_assoc' : (actLeft P Q ▷ T.X) ≫ actRight P Q = (α_ R.X _ T.X).hom ≫ (R.X ◁ actRight P Q) ≫ actLeft P Q := by refine (cancel_epi ((tensorLeft _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [X] slice_lhs 1 2 => rw [← comp_whiskerRight, whiskerLeft_π_actLeft, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 4 => rw [π_tensor_id_actRight] slice_lhs 2 3 => rw [associator_naturality_left] -- Porting note: had to replace `rw` by `erw` slice_rhs 1 2 => rw [associator_naturality_middle] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, π_tensor_id_actRight, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 5 => rw [whiskerLeft_π_actLeft] slice_rhs 3 4 => rw [associator_inv_naturality_right] slice_rhs 4 5 => rw [whisker_exchange] simp set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod.middle_assoc' Bimod.TensorBimod.middle_assoc' end end TensorBimod section variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] /-- Tensor product of two bimodule objects as a bimodule object. -/ @[simps] noncomputable def tensorBimod {X Y Z : Mon_ C} (M : Bimod X Y) (N : Bimod Y Z) : Bimod X Z where X := TensorBimod.X M N actLeft := TensorBimod.actLeft M N actRight := TensorBimod.actRight M N one_actLeft := TensorBimod.one_act_left' M N actRight_one := TensorBimod.actRight_one' M N left_assoc := TensorBimod.left_assoc' M N right_assoc := TensorBimod.right_assoc' M N middle_assoc := TensorBimod.middle_assoc' M N set_option linter.uppercaseLean3 false in #align Bimod.tensor_Bimod Bimod.tensorBimod /-- Left whiskering for morphisms of bimodule objects. -/ @[simps] noncomputable def whiskerLeft {X Y Z : Mon_ C} (M : Bimod X Y) {N₁ N₂ : Bimod Y Z} (f : N₁ ⟶ N₂) : M.tensorBimod N₁ ⟶ M.tensorBimod N₂ where hom := colimMap (parallelPairHom _ _ _ _ (_ ◁ f.hom) (_ ◁ f.hom) (by rw [whisker_exchange]) (by simp only [Category.assoc, tensor_whiskerLeft, Iso.inv_hom_id_assoc, Iso.cancel_iso_hom_left] slice_lhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.left_act_hom] simp)) left_act_hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one, MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_rhs 1 2 => rw [associator_inv_naturality_right] slice_rhs 2 3 => rw [whisker_exchange] simp right_act_hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, Hom.right_act_hom] slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight] slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight] simp /-- Right whiskering for morphisms of bimodule objects. -/ @[simps] noncomputable def whiskerRight {X Y Z : Mon_ C} {M₁ M₂ : Bimod X Y} (f : M₁ ⟶ M₂) (N : Bimod Y Z) : M₁.tensorBimod N ⟶ M₂.tensorBimod N where hom := colimMap (parallelPairHom _ _ _ _ (f.hom ▷ _ ▷ _) (f.hom ▷ _) (by rw [← comp_whiskerRight, Hom.right_act_hom, comp_whiskerRight]) (by slice_lhs 2 3 => rw [whisker_exchange] simp)) left_act_hom := by refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [← comp_whiskerRight, Hom.left_act_hom] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, ι_colimMap, parallelPairHom_app_one, MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_rhs 1 2 => rw [associator_inv_naturality_middle] simp right_act_hom := by refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [ι_colimMap, parallelPairHom_app_one] slice_lhs 2 3 => rw [whisker_exchange] slice_rhs 1 2 => rw [← comp_whiskerRight, ι_colimMap, parallelPairHom_app_one, comp_whiskerRight] slice_rhs 2 3 => rw [TensorBimod.π_tensor_id_actRight] simp end namespace AssociatorBimod variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] variable {R S T U : Mon_ C} (P : Bimod R S) (Q : Bimod S T) (L : Bimod T U) /-- An auxiliary morphism for the definition of the underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def homAux : (P.tensorBimod Q).X ⊗ L.X ⟶ (P.tensorBimod (Q.tensorBimod L)).X := (PreservesCoequalizer.iso (tensorRight L.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).hom ≫ (P.X ◁ coequalizer.π _ _) ≫ coequalizer.π _ _) (by dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 4 => rw [coequalizer.condition] slice_lhs 2 3 => rw [associator_naturality_right] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp] simp) set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.hom_aux Bimod.AssociatorBimod.homAux /-- The underlying morphism of the forward component of the associator isomorphism. -/ noncomputable def hom : ((P.tensorBimod Q).tensorBimod L).X ⟶ (P.tensorBimod (Q.tensorBimod L)).X := coequalizer.desc (homAux P Q L) (by dsimp [homAux] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp [TensorBimod.X] slice_lhs 1 2 => rw [← comp_whiskerRight, TensorBimod.π_tensor_id_actRight, comp_whiskerRight, comp_whiskerRight] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 2 3 => rw [associator_naturality_middle] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.condition, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 1 2 => rw [associator_naturality_left] slice_rhs 2 3 => rw [← whisker_exchange] slice_rhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] simp) set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.hom Bimod.AssociatorBimod.hom theorem hom_left_act_hom' : ((P.tensorBimod Q).tensorBimod L).actLeft ≫ hom P Q L = (R.X ◁ hom P Q L) ≫ (P.tensorBimod (Q.tensorBimod L)).actLeft := by dsimp; dsimp [hom, homAux] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_lhs 1 2 => rw [TensorBimod.whiskerLeft_π_actLeft] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc, MonoidalCategory.whiskerLeft_comp] refine (cancel_epi ((tensorRight _ ⋙ tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_inv_naturality_middle] slice_lhs 2 3 => rw [← comp_whiskerRight, TensorBimod.whiskerLeft_π_actLeft, comp_whiskerRight, comp_whiskerRight] slice_lhs 4 6 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [associator_naturality_left] slice_rhs 1 3 => rw [← MonoidalCategory.whiskerLeft_comp, ← MonoidalCategory.whiskerLeft_comp, π_tensor_id_preserves_coequalizer_inv_desc, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 3 4 => erw [TensorBimod.whiskerLeft_π_actLeft P (Q.tensorBimod L)] slice_rhs 2 3 => erw [associator_inv_naturality_right] slice_rhs 3 4 => erw [whisker_exchange] coherence set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.hom_left_act_hom' Bimod.AssociatorBimod.hom_left_act_hom' theorem hom_right_act_hom' : ((P.tensorBimod Q).tensorBimod L).actRight ≫ hom P Q L = (hom P Q L ▷ U.X) ≫ (P.tensorBimod (Q.tensorBimod L)).actRight := by dsimp; dsimp [hom, homAux] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 2 => rw [TensorBimod.π_tensor_id_actRight] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc, comp_whiskerRight] refine (cancel_epi ((tensorRight _ ⋙ tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_naturality_left] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 5 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 2 3 => rw [associator_naturality_right] slice_rhs 1 3 => rw [← comp_whiskerRight, ← comp_whiskerRight, π_tensor_id_preserves_coequalizer_inv_desc, comp_whiskerRight, comp_whiskerRight] slice_rhs 3 4 => erw [TensorBimod.π_tensor_id_actRight P (Q.tensorBimod L)] slice_rhs 2 3 => erw [associator_naturality_middle] dsimp slice_rhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.π_tensor_id_actRight, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] coherence set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.hom_right_act_hom' Bimod.AssociatorBimod.hom_right_act_hom' /-- An auxiliary morphism for the definition of the underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def invAux : P.X ⊗ (Q.tensorBimod L).X ⟶ ((P.tensorBimod Q).tensorBimod L).X := (PreservesCoequalizer.iso (tensorLeft P.X) _ _).inv ≫ coequalizer.desc ((α_ _ _ _).inv ≫ (coequalizer.π _ _ ▷ L.X) ≫ coequalizer.π _ _) (by dsimp; dsimp [TensorBimod.X] slice_lhs 1 2 => rw [associator_inv_naturality_middle] rw [← Iso.inv_hom_id_assoc (α_ _ _ _) (P.X ◁ Q.actRight), comp_whiskerRight] slice_lhs 3 4 => rw [← comp_whiskerRight, Category.assoc, ← TensorBimod.π_tensor_id_actRight, comp_whiskerRight] slice_lhs 4 5 => rw [coequalizer.condition] slice_lhs 3 4 => rw [associator_naturality_left] slice_rhs 1 2 => rw [MonoidalCategory.whiskerLeft_comp] slice_rhs 2 3 => rw [associator_inv_naturality_right] slice_rhs 3 4 => rw [whisker_exchange] coherence) set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.inv_aux Bimod.AssociatorBimod.invAux /-- The underlying morphism of the inverse component of the associator isomorphism. -/ noncomputable def inv : (P.tensorBimod (Q.tensorBimod L)).X ⟶ ((P.tensorBimod Q).tensorBimod L).X := coequalizer.desc (invAux P Q L) (by dsimp [invAux] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp [TensorBimod.X] slice_lhs 1 2 => rw [whisker_exchange] slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 1 2 => rw [associator_inv_naturality_left] slice_lhs 2 3 => rw [← comp_whiskerRight, coequalizer.condition, comp_whiskerRight, comp_whiskerRight] slice_rhs 1 2 => rw [associator_naturality_right] slice_rhs 2 3 => rw [← MonoidalCategory.whiskerLeft_comp, TensorBimod.whiskerLeft_π_actLeft, MonoidalCategory.whiskerLeft_comp, MonoidalCategory.whiskerLeft_comp] slice_rhs 4 6 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_rhs 3 4 => rw [associator_inv_naturality_middle] coherence) set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.inv Bimod.AssociatorBimod.inv theorem hom_inv_id : hom P Q L ≫ inv P Q L = 𝟙 _ := by dsimp [hom, homAux, inv, invAux] apply coequalizer.hom_ext slice_lhs 1 2 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ rw [tensorRight_map] slice_lhs 1 3 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_lhs 2 4 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 1 3 => rw [Iso.hom_inv_id_assoc] dsimp only [TensorBimod.X] slice_rhs 2 3 => rw [Category.comp_id] rfl set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.hom_inv_id Bimod.AssociatorBimod.hom_inv_id theorem inv_hom_id : inv P Q L ≫ hom P Q L = 𝟙 _ := by dsimp [hom, homAux, inv, invAux] apply coequalizer.hom_ext slice_lhs 1 2 => rw [coequalizer.π_desc] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ rw [tensorLeft_map] slice_lhs 1 3 => rw [id_tensor_π_preserves_coequalizer_inv_desc] slice_lhs 3 4 => rw [coequalizer.π_desc] slice_lhs 2 4 => rw [π_tensor_id_preserves_coequalizer_inv_desc] slice_lhs 1 3 => rw [Iso.inv_hom_id_assoc] dsimp only [TensorBimod.X] slice_rhs 2 3 => rw [Category.comp_id] rfl set_option linter.uppercaseLean3 false in #align Bimod.associator_Bimod.inv_hom_id Bimod.AssociatorBimod.inv_hom_id end AssociatorBimod namespace LeftUnitorBimod variable {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the left unitor isomorphism. -/ noncomputable def hom : TensorBimod.X (regular R) P ⟶ P.X := coequalizer.desc P.actLeft (by dsimp; rw [Category.assoc, left_assoc]) set_option linter.uppercaseLean3 false in #align Bimod.left_unitor_Bimod.hom Bimod.LeftUnitorBimod.hom /-- The underlying morphism of the inverse component of the left unitor isomorphism. -/ noncomputable def inv : P.X ⟶ TensorBimod.X (regular R) P := (λ_ P.X).inv ≫ (R.one ▷ _) ≫ coequalizer.π _ _ set_option linter.uppercaseLean3 false in #align Bimod.left_unitor_Bimod.inv Bimod.LeftUnitorBimod.inv theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by dsimp only [hom, inv, TensorBimod.X] ext; dsimp slice_lhs 1 2 => rw [coequalizer.π_desc] slice_lhs 1 2 => rw [leftUnitor_inv_naturality] slice_lhs 2 3 => rw [whisker_exchange] slice_lhs 3 3 => rw [← Iso.inv_hom_id_assoc (α_ R.X R.X P.X) (R.X ◁ P.actLeft)] slice_lhs 4 6 => rw [← Category.assoc, ← coequalizer.condition] slice_lhs 2 3 => rw [associator_inv_naturality_left] slice_lhs 3 4 => rw [← comp_whiskerRight, Mon_.one_mul] slice_rhs 1 2 => rw [Category.comp_id] coherence set_option linter.uppercaseLean3 false in #align Bimod.left_unitor_Bimod.hom_inv_id Bimod.LeftUnitorBimod.hom_inv_id theorem inv_hom_id : inv P ≫ hom P = 𝟙 _ := by dsimp [hom, inv] slice_lhs 3 4 => rw [coequalizer.π_desc] rw [one_actLeft, Iso.inv_hom_id] set_option linter.uppercaseLean3 false in #align Bimod.left_unitor_Bimod.inv_hom_id Bimod.LeftUnitorBimod.inv_hom_id variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorLeft X)] variable [∀ X : C, PreservesColimitsOfSize.{0, 0} (tensorRight X)] theorem hom_left_act_hom' : ((regular R).tensorBimod P).actLeft ≫ hom P = (R.X ◁ hom P) ≫ P.actLeft := by dsimp; dsimp [hom, TensorBimod.actLeft, regular] refine (cancel_epi ((tensorLeft _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [id_tensor_π_preserves_coequalizer_inv_colimMap_desc] slice_lhs 2 3 => rw [left_assoc] slice_rhs 1 2 => rw [← MonoidalCategory.whiskerLeft_comp, coequalizer.π_desc] rw [Iso.inv_hom_id_assoc] set_option linter.uppercaseLean3 false in #align Bimod.left_unitor_Bimod.hom_left_act_hom' Bimod.LeftUnitorBimod.hom_left_act_hom' theorem hom_right_act_hom' : ((regular R).tensorBimod P).actRight ≫ hom P = (hom P ▷ S.X) ≫ P.actRight := by dsimp; dsimp [hom, TensorBimod.actRight, regular] refine (cancel_epi ((tensorRight _).map (coequalizer.π _ _))).1 ?_ dsimp slice_lhs 1 4 => rw [π_tensor_id_preserves_coequalizer_inv_colimMap_desc] slice_rhs 1 2 => rw [← comp_whiskerRight, coequalizer.π_desc] slice_rhs 1 2 => rw [middle_assoc] simp only [Category.assoc] set_option linter.uppercaseLean3 false in #align Bimod.left_unitor_Bimod.hom_right_act_hom' Bimod.LeftUnitorBimod.hom_right_act_hom' end LeftUnitorBimod namespace RightUnitorBimod variable {R S : Mon_ C} (P : Bimod R S) /-- The underlying morphism of the forward component of the right unitor isomorphism. -/ noncomputable def hom : TensorBimod.X P (regular S) ⟶ P.X := coequalizer.desc P.actRight (by dsimp; rw [Category.assoc, right_assoc, Iso.hom_inv_id_assoc]) set_option linter.uppercaseLean3 false in #align Bimod.right_unitor_Bimod.hom Bimod.RightUnitorBimod.hom /-- The underlying morphism of the inverse component of the right unitor isomorphism. -/ noncomputable def inv : P.X ⟶ TensorBimod.X P (regular S) := (ρ_ P.X).inv ≫ (_ ◁ S.one) ≫ coequalizer.π _ _ set_option linter.uppercaseLean3 false in #align Bimod.right_unitor_Bimod.inv Bimod.RightUnitorBimod.inv
Mathlib/CategoryTheory/Monoidal/Bimod.lean
732
742
theorem hom_inv_id : hom P ≫ inv P = 𝟙 _ := by
dsimp only [hom, inv, TensorBimod.X] ext; dsimp slice_lhs 1 2 => rw [coequalizer.π_desc] slice_lhs 1 2 => rw [rightUnitor_inv_naturality] slice_lhs 2 3 => rw [← whisker_exchange] slice_lhs 3 4 => rw [coequalizer.condition] slice_lhs 2 3 => rw [associator_naturality_right] slice_lhs 3 4 => rw [← MonoidalCategory.whiskerLeft_comp, Mon_.mul_one] slice_rhs 1 2 => rw [Category.comp_id] coherence
/- Copyright (c) 2022 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Integral.IntegrableOn #align_import measure_theory.function.locally_integrable from "leanprover-community/mathlib"@"08a4542bec7242a5c60f179e4e49de8c0d677b1b" /-! # Locally integrable functions A function is called *locally integrable* (`MeasureTheory.LocallyIntegrable`) if it is integrable on a neighborhood of every point. More generally, it is *locally integrable on `s`* if it is locally integrable on a neighbourhood within `s` of any point of `s`. This file contains properties of locally integrable functions, and integrability results on compact sets. ## Main statements * `Continuous.locallyIntegrable`: A continuous function is locally integrable. * `ContinuousOn.locallyIntegrableOn`: A function which is continuous on `s` is locally integrable on `s`. -/ open MeasureTheory MeasureTheory.Measure Set Function TopologicalSpace Bornology open scoped Topology Interval ENNReal variable {X Y E F R : Type*} [MeasurableSpace X] [TopologicalSpace X] variable [MeasurableSpace Y] [TopologicalSpace Y] variable [NormedAddCommGroup E] [NormedAddCommGroup F] {f g : X → E} {μ : Measure X} {s : Set X} namespace MeasureTheory section LocallyIntegrableOn /-- A function `f : X → E` is *locally integrable on s*, for `s ⊆ X`, if for every `x ∈ s` there is a neighbourhood of `x` within `s` on which `f` is integrable. (Note this is, in general, strictly weaker than local integrability with respect to `μ.restrict s`.) -/ def LocallyIntegrableOn (f : X → E) (s : Set X) (μ : Measure X := by volume_tac) : Prop := ∀ x : X, x ∈ s → IntegrableAtFilter f (𝓝[s] x) μ #align measure_theory.locally_integrable_on MeasureTheory.LocallyIntegrableOn theorem LocallyIntegrableOn.mono_set (hf : LocallyIntegrableOn f s μ) {t : Set X} (hst : t ⊆ s) : LocallyIntegrableOn f t μ := fun x hx => (hf x <| hst hx).filter_mono (nhdsWithin_mono x hst) #align measure_theory.locally_integrable_on.mono MeasureTheory.LocallyIntegrableOn.mono_set theorem LocallyIntegrableOn.norm (hf : LocallyIntegrableOn f s μ) : LocallyIntegrableOn (fun x => ‖f x‖) s μ := fun t ht => let ⟨U, hU_nhd, hU_int⟩ := hf t ht ⟨U, hU_nhd, hU_int.norm⟩ #align measure_theory.locally_integrable_on.norm MeasureTheory.LocallyIntegrableOn.norm theorem LocallyIntegrableOn.mono (hf : LocallyIntegrableOn f s μ) {g : X → F} (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ x ∂μ, ‖g x‖ ≤ ‖f x‖) : LocallyIntegrableOn g s μ := by intro x hx rcases hf x hx with ⟨t, t_mem, ht⟩ exact ⟨t, t_mem, Integrable.mono ht hg.restrict (ae_restrict_of_ae h)⟩ theorem IntegrableOn.locallyIntegrableOn (hf : IntegrableOn f s μ) : LocallyIntegrableOn f s μ := fun _ _ => ⟨s, self_mem_nhdsWithin, hf⟩ #align measure_theory.integrable_on.locally_integrable_on MeasureTheory.IntegrableOn.locallyIntegrableOn /-- If a function is locally integrable on a compact set, then it is integrable on that set. -/ theorem LocallyIntegrableOn.integrableOn_isCompact (hf : LocallyIntegrableOn f s μ) (hs : IsCompact s) : IntegrableOn f s μ := IsCompact.induction_on hs integrableOn_empty (fun _u _v huv hv => hv.mono_set huv) (fun _u _v hu hv => integrableOn_union.mpr ⟨hu, hv⟩) hf #align measure_theory.locally_integrable_on.integrable_on_is_compact MeasureTheory.LocallyIntegrableOn.integrableOn_isCompact theorem LocallyIntegrableOn.integrableOn_compact_subset (hf : LocallyIntegrableOn f s μ) {t : Set X} (hst : t ⊆ s) (ht : IsCompact t) : IntegrableOn f t μ := (hf.mono_set hst).integrableOn_isCompact ht #align measure_theory.locally_integrable_on.integrable_on_compact_subset MeasureTheory.LocallyIntegrableOn.integrableOn_compact_subset /-- If a function `f` is locally integrable on a set `s` in a second countable topological space, then there exist countably many open sets `u` covering `s` such that `f` is integrable on each set `u ∩ s`. -/ theorem LocallyIntegrableOn.exists_countable_integrableOn [SecondCountableTopology X] (hf : LocallyIntegrableOn f s μ) : ∃ T : Set (Set X), T.Countable ∧ (∀ u ∈ T, IsOpen u) ∧ (s ⊆ ⋃ u ∈ T, u) ∧ (∀ u ∈ T, IntegrableOn f (u ∩ s) μ) := by have : ∀ x : s, ∃ u, IsOpen u ∧ x.1 ∈ u ∧ IntegrableOn f (u ∩ s) μ := by rintro ⟨x, hx⟩ rcases hf x hx with ⟨t, ht, h't⟩ rcases mem_nhdsWithin.1 ht with ⟨u, u_open, x_mem, u_sub⟩ exact ⟨u, u_open, x_mem, h't.mono_set u_sub⟩ choose u u_open xu hu using this obtain ⟨T, T_count, hT⟩ : ∃ T : Set s, T.Countable ∧ s ⊆ ⋃ i ∈ T, u i := by have : s ⊆ ⋃ x : s, u x := fun y hy => mem_iUnion_of_mem ⟨y, hy⟩ (xu ⟨y, hy⟩) obtain ⟨T, hT_count, hT_un⟩ := isOpen_iUnion_countable u u_open exact ⟨T, hT_count, by rwa [hT_un]⟩ refine ⟨u '' T, T_count.image _, ?_, by rwa [biUnion_image], ?_⟩ · rintro v ⟨w, -, rfl⟩ exact u_open _ · rintro v ⟨w, -, rfl⟩ exact hu _ /-- If a function `f` is locally integrable on a set `s` in a second countable topological space, then there exists a sequence of open sets `u n` covering `s` such that `f` is integrable on each set `u n ∩ s`. -/ theorem LocallyIntegrableOn.exists_nat_integrableOn [SecondCountableTopology X] (hf : LocallyIntegrableOn f s μ) : ∃ u : ℕ → Set X, (∀ n, IsOpen (u n)) ∧ (s ⊆ ⋃ n, u n) ∧ (∀ n, IntegrableOn f (u n ∩ s) μ) := by rcases hf.exists_countable_integrableOn with ⟨T, T_count, T_open, sT, hT⟩ let T' : Set (Set X) := insert ∅ T have T'_count : T'.Countable := Countable.insert ∅ T_count have T'_ne : T'.Nonempty := by simp only [T', insert_nonempty] rcases T'_count.exists_eq_range T'_ne with ⟨u, hu⟩ refine ⟨u, ?_, ?_, ?_⟩ · intro n have : u n ∈ T' := by rw [hu]; exact mem_range_self n rcases mem_insert_iff.1 this with h|h · rw [h] exact isOpen_empty · exact T_open _ h · intro x hx obtain ⟨v, hv, h'v⟩ : ∃ v, v ∈ T ∧ x ∈ v := by simpa only [mem_iUnion, exists_prop] using sT hx have : v ∈ range u := by rw [← hu]; exact subset_insert ∅ T hv obtain ⟨n, rfl⟩ : ∃ n, u n = v := by simpa only [mem_range] using this exact mem_iUnion_of_mem _ h'v · intro n have : u n ∈ T' := by rw [hu]; exact mem_range_self n rcases mem_insert_iff.1 this with h|h · simp only [h, empty_inter, integrableOn_empty] · exact hT _ h theorem LocallyIntegrableOn.aestronglyMeasurable [SecondCountableTopology X] (hf : LocallyIntegrableOn f s μ) : AEStronglyMeasurable f (μ.restrict s) := by rcases hf.exists_nat_integrableOn with ⟨u, -, su, hu⟩ have : s = ⋃ n, u n ∩ s := by rw [← iUnion_inter]; exact (inter_eq_right.mpr su).symm rw [this, aestronglyMeasurable_iUnion_iff] exact fun i : ℕ => (hu i).aestronglyMeasurable #align measure_theory.locally_integrable_on.ae_strongly_measurable MeasureTheory.LocallyIntegrableOn.aestronglyMeasurable /-- If `s` is either open, or closed, then `f` is locally integrable on `s` iff it is integrable on every compact subset contained in `s`. -/ theorem locallyIntegrableOn_iff [LocallyCompactSpace X] [T2Space X] (hs : IsClosed s ∨ IsOpen s) : LocallyIntegrableOn f s μ ↔ ∀ (k : Set X), k ⊆ s → (IsCompact k → IntegrableOn f k μ) := by -- The correct condition is that `s` be *locally closed*, i.e. for every `x ∈ s` there is some -- `U ∈ 𝓝 x` such that `U ∩ s` is closed. But mathlib doesn't have locally closed sets yet. refine ⟨fun hf k hk => hf.integrableOn_compact_subset hk, fun hf x hx => ?_⟩ cases hs with | inl hs => exact let ⟨K, hK, h2K⟩ := exists_compact_mem_nhds x ⟨_, inter_mem_nhdsWithin s h2K, hf _ inter_subset_left (hK.of_isClosed_subset (hs.inter hK.isClosed) inter_subset_right)⟩ | inr hs => obtain ⟨K, hK, h2K, h3K⟩ := exists_compact_subset hs hx refine ⟨K, ?_, hf K h3K hK⟩ simpa only [IsOpen.nhdsWithin_eq hs hx, interior_eq_nhds'] using h2K #align measure_theory.locally_integrable_on_iff MeasureTheory.locallyIntegrableOn_iff protected theorem LocallyIntegrableOn.add (hf : LocallyIntegrableOn f s μ) (hg : LocallyIntegrableOn g s μ) : LocallyIntegrableOn (f + g) s μ := fun x hx ↦ (hf x hx).add (hg x hx) protected theorem LocallyIntegrableOn.sub (hf : LocallyIntegrableOn f s μ) (hg : LocallyIntegrableOn g s μ) : LocallyIntegrableOn (f - g) s μ := fun x hx ↦ (hf x hx).sub (hg x hx) protected theorem LocallyIntegrableOn.neg (hf : LocallyIntegrableOn f s μ) : LocallyIntegrableOn (-f) s μ := fun x hx ↦ (hf x hx).neg end LocallyIntegrableOn /-- A function `f : X → E` is *locally integrable* if it is integrable on a neighborhood of every point. In particular, it is integrable on all compact sets, see `LocallyIntegrable.integrableOn_isCompact`. -/ def LocallyIntegrable (f : X → E) (μ : Measure X := by volume_tac) : Prop := ∀ x : X, IntegrableAtFilter f (𝓝 x) μ #align measure_theory.locally_integrable MeasureTheory.LocallyIntegrable theorem locallyIntegrable_comap (hs : MeasurableSet s) : LocallyIntegrable (fun x : s ↦ f x) (μ.comap Subtype.val) ↔ LocallyIntegrableOn f s μ := by simp_rw [LocallyIntegrableOn, Subtype.forall', ← map_nhds_subtype_val] exact forall_congr' fun _ ↦ (MeasurableEmbedding.subtype_coe hs).integrableAtFilter_iff_comap.symm theorem locallyIntegrableOn_univ : LocallyIntegrableOn f univ μ ↔ LocallyIntegrable f μ := by simp only [LocallyIntegrableOn, nhdsWithin_univ, mem_univ, true_imp_iff]; rfl #align measure_theory.locally_integrable_on_univ MeasureTheory.locallyIntegrableOn_univ theorem LocallyIntegrable.locallyIntegrableOn (hf : LocallyIntegrable f μ) (s : Set X) : LocallyIntegrableOn f s μ := fun x _ => (hf x).filter_mono nhdsWithin_le_nhds #align measure_theory.locally_integrable.locally_integrable_on MeasureTheory.LocallyIntegrable.locallyIntegrableOn theorem Integrable.locallyIntegrable (hf : Integrable f μ) : LocallyIntegrable f μ := fun _ => hf.integrableAtFilter _ #align measure_theory.integrable.locally_integrable MeasureTheory.Integrable.locallyIntegrable theorem LocallyIntegrable.mono (hf : LocallyIntegrable f μ) {g : X → F} (hg : AEStronglyMeasurable g μ) (h : ∀ᵐ x ∂μ, ‖g x‖ ≤ ‖f x‖) : LocallyIntegrable g μ := by rw [← locallyIntegrableOn_univ] at hf ⊢ exact hf.mono hg h /-- If `f` is locally integrable with respect to `μ.restrict s`, it is locally integrable on `s`. (See `locallyIntegrableOn_iff_locallyIntegrable_restrict` for an iff statement when `s` is closed.) -/ theorem locallyIntegrableOn_of_locallyIntegrable_restrict [OpensMeasurableSpace X] (hf : LocallyIntegrable f (μ.restrict s)) : LocallyIntegrableOn f s μ := by intro x _ obtain ⟨t, ht_mem, ht_int⟩ := hf x obtain ⟨u, hu_sub, hu_o, hu_mem⟩ := mem_nhds_iff.mp ht_mem refine ⟨_, inter_mem_nhdsWithin s (hu_o.mem_nhds hu_mem), ?_⟩ simpa only [IntegrableOn, Measure.restrict_restrict hu_o.measurableSet, inter_comm] using ht_int.mono_set hu_sub #align measure_theory.locally_integrable_on_of_locally_integrable_restrict MeasureTheory.locallyIntegrableOn_of_locallyIntegrable_restrict /-- If `s` is closed, being locally integrable on `s` wrt `μ` is equivalent to being locally integrable with respect to `μ.restrict s`. For the one-way implication without assuming `s` closed, see `locallyIntegrableOn_of_locallyIntegrable_restrict`. -/ theorem locallyIntegrableOn_iff_locallyIntegrable_restrict [OpensMeasurableSpace X] (hs : IsClosed s) : LocallyIntegrableOn f s μ ↔ LocallyIntegrable f (μ.restrict s) := by refine ⟨fun hf x => ?_, locallyIntegrableOn_of_locallyIntegrable_restrict⟩ by_cases h : x ∈ s · obtain ⟨t, ht_nhds, ht_int⟩ := hf x h obtain ⟨u, hu_o, hu_x, hu_sub⟩ := mem_nhdsWithin.mp ht_nhds refine ⟨u, hu_o.mem_nhds hu_x, ?_⟩ rw [IntegrableOn, restrict_restrict hu_o.measurableSet] exact ht_int.mono_set hu_sub · rw [← isOpen_compl_iff] at hs refine ⟨sᶜ, hs.mem_nhds h, ?_⟩ rw [IntegrableOn, restrict_restrict, inter_comm, inter_compl_self, ← IntegrableOn] exacts [integrableOn_empty, hs.measurableSet] #align measure_theory.locally_integrable_on_iff_locally_integrable_restrict MeasureTheory.locallyIntegrableOn_iff_locallyIntegrable_restrict /-- If a function is locally integrable, then it is integrable on any compact set. -/ theorem LocallyIntegrable.integrableOn_isCompact {k : Set X} (hf : LocallyIntegrable f μ) (hk : IsCompact k) : IntegrableOn f k μ := (hf.locallyIntegrableOn k).integrableOn_isCompact hk #align measure_theory.locally_integrable.integrable_on_is_compact MeasureTheory.LocallyIntegrable.integrableOn_isCompact /-- If a function is locally integrable, then it is integrable on an open neighborhood of any compact set. -/ theorem LocallyIntegrable.integrableOn_nhds_isCompact (hf : LocallyIntegrable f μ) {k : Set X} (hk : IsCompact k) : ∃ u, IsOpen u ∧ k ⊆ u ∧ IntegrableOn f u μ := by refine IsCompact.induction_on hk ?_ ?_ ?_ ?_ · refine ⟨∅, isOpen_empty, Subset.rfl, integrableOn_empty⟩ · rintro s t hst ⟨u, u_open, tu, hu⟩ exact ⟨u, u_open, hst.trans tu, hu⟩ · rintro s t ⟨u, u_open, su, hu⟩ ⟨v, v_open, tv, hv⟩ exact ⟨u ∪ v, u_open.union v_open, union_subset_union su tv, hu.union hv⟩ · intro x _ rcases hf x with ⟨u, ux, hu⟩ rcases mem_nhds_iff.1 ux with ⟨v, vu, v_open, xv⟩ exact ⟨v, nhdsWithin_le_nhds (v_open.mem_nhds xv), v, v_open, Subset.rfl, hu.mono_set vu⟩ #align measure_theory.locally_integrable.integrable_on_nhds_is_compact MeasureTheory.LocallyIntegrable.integrableOn_nhds_isCompact theorem locallyIntegrable_iff [LocallyCompactSpace X] : LocallyIntegrable f μ ↔ ∀ k : Set X, IsCompact k → IntegrableOn f k μ := ⟨fun hf _k hk => hf.integrableOn_isCompact hk, fun hf x => let ⟨K, hK, h2K⟩ := exists_compact_mem_nhds x ⟨K, h2K, hf K hK⟩⟩ #align measure_theory.locally_integrable_iff MeasureTheory.locallyIntegrable_iff theorem LocallyIntegrable.aestronglyMeasurable [SecondCountableTopology X] (hf : LocallyIntegrable f μ) : AEStronglyMeasurable f μ := by simpa only [restrict_univ] using (locallyIntegrableOn_univ.mpr hf).aestronglyMeasurable #align measure_theory.locally_integrable.ae_strongly_measurable MeasureTheory.LocallyIntegrable.aestronglyMeasurable /-- If a function is locally integrable in a second countable topological space, then there exists a sequence of open sets covering the space on which it is integrable. -/ theorem LocallyIntegrable.exists_nat_integrableOn [SecondCountableTopology X] (hf : LocallyIntegrable f μ) : ∃ u : ℕ → Set X, (∀ n, IsOpen (u n)) ∧ ((⋃ n, u n) = univ) ∧ (∀ n, IntegrableOn f (u n) μ) := by rcases (hf.locallyIntegrableOn univ).exists_nat_integrableOn with ⟨u, u_open, u_union, hu⟩ refine ⟨u, u_open, eq_univ_of_univ_subset u_union, fun n ↦ ?_⟩ simpa only [inter_univ] using hu n theorem Memℒp.locallyIntegrable [IsLocallyFiniteMeasure μ] {f : X → E} {p : ℝ≥0∞} (hf : Memℒp f p μ) (hp : 1 ≤ p) : LocallyIntegrable f μ := by intro x rcases μ.finiteAt_nhds x with ⟨U, hU, h'U⟩ have : Fact (μ U < ⊤) := ⟨h'U⟩ refine ⟨U, hU, ?_⟩ rw [IntegrableOn, ← memℒp_one_iff_integrable] apply (hf.restrict U).memℒp_of_exponent_le hp theorem locallyIntegrable_const [IsLocallyFiniteMeasure μ] (c : E) : LocallyIntegrable (fun _ => c) μ := (memℒp_top_const c).locallyIntegrable le_top #align measure_theory.locally_integrable_const MeasureTheory.locallyIntegrable_const theorem locallyIntegrableOn_const [IsLocallyFiniteMeasure μ] (c : E) : LocallyIntegrableOn (fun _ => c) s μ := (locallyIntegrable_const c).locallyIntegrableOn s #align measure_theory.locally_integrable_on_const MeasureTheory.locallyIntegrableOn_const theorem locallyIntegrable_zero : LocallyIntegrable (fun _ ↦ (0 : E)) μ := (integrable_zero X E μ).locallyIntegrable theorem locallyIntegrableOn_zero : LocallyIntegrableOn (fun _ ↦ (0 : E)) s μ := locallyIntegrable_zero.locallyIntegrableOn s theorem LocallyIntegrable.indicator (hf : LocallyIntegrable f μ) {s : Set X} (hs : MeasurableSet s) : LocallyIntegrable (s.indicator f) μ := by intro x rcases hf x with ⟨U, hU, h'U⟩ exact ⟨U, hU, h'U.indicator hs⟩ #align measure_theory.locally_integrable.indicator MeasureTheory.LocallyIntegrable.indicator theorem locallyIntegrable_map_homeomorph [BorelSpace X] [BorelSpace Y] (e : X ≃ₜ Y) {f : Y → E} {μ : Measure X} : LocallyIntegrable f (Measure.map e μ) ↔ LocallyIntegrable (f ∘ e) μ := by refine ⟨fun h x => ?_, fun h x => ?_⟩ · rcases h (e x) with ⟨U, hU, h'U⟩ refine ⟨e ⁻¹' U, e.continuous.continuousAt.preimage_mem_nhds hU, ?_⟩ exact (integrableOn_map_equiv e.toMeasurableEquiv).1 h'U · rcases h (e.symm x) with ⟨U, hU, h'U⟩ refine ⟨e.symm ⁻¹' U, e.symm.continuous.continuousAt.preimage_mem_nhds hU, ?_⟩ apply (integrableOn_map_equiv e.toMeasurableEquiv).2 simp only [Homeomorph.toMeasurableEquiv_coe] convert h'U ext x simp only [mem_preimage, Homeomorph.symm_apply_apply] #align measure_theory.locally_integrable_map_homeomorph MeasureTheory.locallyIntegrable_map_homeomorph protected theorem LocallyIntegrable.add (hf : LocallyIntegrable f μ) (hg : LocallyIntegrable g μ) : LocallyIntegrable (f + g) μ := fun x ↦ (hf x).add (hg x) protected theorem LocallyIntegrable.sub (hf : LocallyIntegrable f μ) (hg : LocallyIntegrable g μ) : LocallyIntegrable (f - g) μ := fun x ↦ (hf x).sub (hg x) protected theorem LocallyIntegrable.neg (hf : LocallyIntegrable f μ) : LocallyIntegrable (-f) μ := fun x ↦ (hf x).neg protected theorem LocallyIntegrable.smul {𝕜 : Type*} [NormedAddCommGroup 𝕜] [SMulZeroClass 𝕜 E] [BoundedSMul 𝕜 E] (hf : LocallyIntegrable f μ) (c : 𝕜) : LocallyIntegrable (c • f) μ := fun x ↦ (hf x).smul c theorem locallyIntegrable_finset_sum' {ι} (s : Finset ι) {f : ι → X → E} (hf : ∀ i ∈ s, LocallyIntegrable (f i) μ) : LocallyIntegrable (∑ i ∈ s, f i) μ := Finset.sum_induction f (fun g => LocallyIntegrable g μ) (fun _ _ => LocallyIntegrable.add) locallyIntegrable_zero hf theorem locallyIntegrable_finset_sum {ι} (s : Finset ι) {f : ι → X → E} (hf : ∀ i ∈ s, LocallyIntegrable (f i) μ) : LocallyIntegrable (fun a ↦ ∑ i ∈ s, f i a) μ := by simpa only [← Finset.sum_apply] using locallyIntegrable_finset_sum' s hf /-- If `f` is locally integrable and `g` is continuous with compact support, then `g • f` is integrable. -/ theorem LocallyIntegrable.integrable_smul_left_of_hasCompactSupport [NormedSpace ℝ E] [OpensMeasurableSpace X] [T2Space X] (hf : LocallyIntegrable f μ) {g : X → ℝ} (hg : Continuous g) (h'g : HasCompactSupport g) : Integrable (fun x ↦ g x • f x) μ := by let K := tsupport g have hK : IsCompact K := h'g have : K.indicator (fun x ↦ g x • f x) = (fun x ↦ g x • f x) := by apply indicator_eq_self.2 apply support_subset_iff'.2 intros x hx simp [image_eq_zero_of_nmem_tsupport hx] rw [← this, indicator_smul] apply Integrable.smul_of_top_right · rw [integrable_indicator_iff hK.measurableSet] exact hf.integrableOn_isCompact hK · exact hg.memℒp_top_of_hasCompactSupport h'g μ /-- If `f` is locally integrable and `g` is continuous with compact support, then `f • g` is integrable. -/ theorem LocallyIntegrable.integrable_smul_right_of_hasCompactSupport [NormedSpace ℝ E] [OpensMeasurableSpace X] [T2Space X] {f : X → ℝ} (hf : LocallyIntegrable f μ) {g : X → E} (hg : Continuous g) (h'g : HasCompactSupport g) : Integrable (fun x ↦ f x • g x) μ := by let K := tsupport g have hK : IsCompact K := h'g have : K.indicator (fun x ↦ f x • g x) = (fun x ↦ f x • g x) := by apply indicator_eq_self.2 apply support_subset_iff'.2 intros x hx simp [image_eq_zero_of_nmem_tsupport hx] rw [← this, indicator_smul_left] apply Integrable.smul_of_top_left · rw [integrable_indicator_iff hK.measurableSet] exact hf.integrableOn_isCompact hK · exact hg.memℒp_top_of_hasCompactSupport h'g μ open Filter theorem integrable_iff_integrableAtFilter_cocompact : Integrable f μ ↔ (IntegrableAtFilter f (cocompact X) μ ∧ LocallyIntegrable f μ) := by refine ⟨fun hf ↦ ⟨hf.integrableAtFilter _, hf.locallyIntegrable⟩, fun ⟨⟨s, hsc, hs⟩, hloc⟩ ↦ ?_⟩ obtain ⟨t, htc, ht⟩ := mem_cocompact'.mp hsc rewrite [← integrableOn_univ, ← compl_union_self s, integrableOn_union] exact ⟨(hloc.integrableOn_isCompact htc).mono ht le_rfl, hs⟩ theorem integrable_iff_integrableAtFilter_atBot_atTop [LinearOrder X] [CompactIccSpace X] : Integrable f μ ↔ (IntegrableAtFilter f atBot μ ∧ IntegrableAtFilter f atTop μ) ∧ LocallyIntegrable f μ := by constructor · exact fun hf ↦ ⟨⟨hf.integrableAtFilter _, hf.integrableAtFilter _⟩, hf.locallyIntegrable⟩ · refine fun h ↦ integrable_iff_integrableAtFilter_cocompact.mpr ⟨?_, h.2⟩ exact (IntegrableAtFilter.sup_iff.mpr h.1).filter_mono cocompact_le_atBot_atTop theorem integrable_iff_integrableAtFilter_atBot [LinearOrder X] [OrderTop X] [CompactIccSpace X] : Integrable f μ ↔ IntegrableAtFilter f atBot μ ∧ LocallyIntegrable f μ := by constructor · exact fun hf ↦ ⟨hf.integrableAtFilter _, hf.locallyIntegrable⟩ · refine fun h ↦ integrable_iff_integrableAtFilter_cocompact.mpr ⟨?_, h.2⟩ exact h.1.filter_mono cocompact_le_atBot theorem integrable_iff_integrableAtFilter_atTop [LinearOrder X] [OrderBot X] [CompactIccSpace X] : Integrable f μ ↔ IntegrableAtFilter f atTop μ ∧ LocallyIntegrable f μ := integrable_iff_integrableAtFilter_atBot (X := Xᵒᵈ) variable {a : X} theorem integrableOn_Iic_iff_integrableAtFilter_atBot [LinearOrder X] [CompactIccSpace X] : IntegrableOn f (Iic a) μ ↔ IntegrableAtFilter f atBot μ ∧ LocallyIntegrableOn f (Iic a) μ := by refine ⟨fun h ↦ ⟨⟨Iic a, Iic_mem_atBot a, h⟩, h.locallyIntegrableOn⟩, fun ⟨⟨s, hsl, hs⟩, h⟩ ↦ ?_⟩ haveI : Nonempty X := Nonempty.intro a obtain ⟨a', ha'⟩ := mem_atBot_sets.mp hsl refine (integrableOn_union.mpr ⟨hs.mono ha' le_rfl, ?_⟩).mono Iic_subset_Iic_union_Icc le_rfl exact h.integrableOn_compact_subset Icc_subset_Iic_self isCompact_Icc theorem integrableOn_Ici_iff_integrableAtFilter_atTop [LinearOrder X] [CompactIccSpace X] : IntegrableOn f (Ici a) μ ↔ IntegrableAtFilter f atTop μ ∧ LocallyIntegrableOn f (Ici a) μ := integrableOn_Iic_iff_integrableAtFilter_atBot (X := Xᵒᵈ) theorem integrableOn_Iio_iff_integrableAtFilter_atBot_nhdsWithin [LinearOrder X] [CompactIccSpace X] [NoMinOrder X] [OrderTopology X] : IntegrableOn f (Iio a) μ ↔ IntegrableAtFilter f atBot μ ∧ IntegrableAtFilter f (𝓝[<] a) μ ∧ LocallyIntegrableOn f (Iio a) μ := by constructor · intro h exact ⟨⟨Iio a, Iio_mem_atBot a, h⟩, ⟨Iio a, self_mem_nhdsWithin, h⟩, h.locallyIntegrableOn⟩ · intro ⟨hbot, ⟨s, hsl, hs⟩, hlocal⟩ obtain ⟨s', ⟨hs'_mono, hs'⟩⟩ := mem_nhdsWithin_Iio_iff_exists_Ioo_subset.mp hsl refine (integrableOn_union.mpr ⟨?_, hs.mono hs' le_rfl⟩).mono Iio_subset_Iic_union_Ioo le_rfl exact integrableOn_Iic_iff_integrableAtFilter_atBot.mpr ⟨hbot, hlocal.mono_set (Iic_subset_Iio.mpr hs'_mono)⟩ theorem integrableOn_Ioi_iff_integrableAtFilter_atTop_nhdsWithin [LinearOrder X] [CompactIccSpace X] [NoMaxOrder X] [OrderTopology X] : IntegrableOn f (Ioi a) μ ↔ IntegrableAtFilter f atTop μ ∧ IntegrableAtFilter f (𝓝[>] a) μ ∧ LocallyIntegrableOn f (Ioi a) μ := integrableOn_Iio_iff_integrableAtFilter_atBot_nhdsWithin (X := Xᵒᵈ) end MeasureTheory open MeasureTheory section borel variable [OpensMeasurableSpace X] variable {K : Set X} {a b : X} /-- A continuous function `f` is locally integrable with respect to any locally finite measure. -/ theorem Continuous.locallyIntegrable [IsLocallyFiniteMeasure μ] [SecondCountableTopologyEither X E] (hf : Continuous f) : LocallyIntegrable f μ := hf.integrableAt_nhds #align continuous.locally_integrable Continuous.locallyIntegrable /-- A function `f` continuous on a set `K` is locally integrable on this set with respect to any locally finite measure. -/ theorem ContinuousOn.locallyIntegrableOn [IsLocallyFiniteMeasure μ] [SecondCountableTopologyEither X E] (hf : ContinuousOn f K) (hK : MeasurableSet K) : LocallyIntegrableOn f K μ := fun _x hx => hf.integrableAt_nhdsWithin hK hx #align continuous_on.locally_integrable_on ContinuousOn.locallyIntegrableOn variable [IsFiniteMeasureOnCompacts μ] /-- A function `f` continuous on a compact set `K` is integrable on this set with respect to any locally finite measure. -/ theorem ContinuousOn.integrableOn_compact' (hK : IsCompact K) (h'K : MeasurableSet K) (hf : ContinuousOn f K) : IntegrableOn f K μ := by refine ⟨ContinuousOn.aestronglyMeasurable_of_isCompact hf hK h'K, ?_⟩ have : Fact (μ K < ∞) := ⟨hK.measure_lt_top⟩ obtain ⟨C, hC⟩ : ∃ C, ∀ x ∈ f '' K, ‖x‖ ≤ C := IsBounded.exists_norm_le (hK.image_of_continuousOn hf).isBounded apply hasFiniteIntegral_of_bounded (C := C) filter_upwards [ae_restrict_mem h'K] with x hx using hC _ (mem_image_of_mem f hx) theorem ContinuousOn.integrableOn_compact [T2Space X] (hK : IsCompact K) (hf : ContinuousOn f K) : IntegrableOn f K μ := hf.integrableOn_compact' hK hK.measurableSet #align continuous_on.integrable_on_compact ContinuousOn.integrableOn_compact theorem ContinuousOn.integrableOn_Icc [Preorder X] [CompactIccSpace X] [T2Space X] (hf : ContinuousOn f (Icc a b)) : IntegrableOn f (Icc a b) μ := hf.integrableOn_compact isCompact_Icc #align continuous_on.integrable_on_Icc ContinuousOn.integrableOn_Icc theorem Continuous.integrableOn_Icc [Preorder X] [CompactIccSpace X] [T2Space X] (hf : Continuous f) : IntegrableOn f (Icc a b) μ := hf.continuousOn.integrableOn_Icc #align continuous.integrable_on_Icc Continuous.integrableOn_Icc theorem Continuous.integrableOn_Ioc [Preorder X] [CompactIccSpace X] [T2Space X] (hf : Continuous f) : IntegrableOn f (Ioc a b) μ := hf.integrableOn_Icc.mono_set Ioc_subset_Icc_self #align continuous.integrable_on_Ioc Continuous.integrableOn_Ioc theorem ContinuousOn.integrableOn_uIcc [LinearOrder X] [CompactIccSpace X] [T2Space X] (hf : ContinuousOn f [[a, b]]) : IntegrableOn f [[a, b]] μ := hf.integrableOn_Icc #align continuous_on.integrable_on_uIcc ContinuousOn.integrableOn_uIcc theorem Continuous.integrableOn_uIcc [LinearOrder X] [CompactIccSpace X] [T2Space X] (hf : Continuous f) : IntegrableOn f [[a, b]] μ := hf.integrableOn_Icc #align continuous.integrable_on_uIcc Continuous.integrableOn_uIcc theorem Continuous.integrableOn_uIoc [LinearOrder X] [CompactIccSpace X] [T2Space X] (hf : Continuous f) : IntegrableOn f (Ι a b) μ := hf.integrableOn_Ioc #align continuous.integrable_on_uIoc Continuous.integrableOn_uIoc /-- A continuous function with compact support is integrable on the whole space. -/ theorem Continuous.integrable_of_hasCompactSupport (hf : Continuous f) (hcf : HasCompactSupport f) : Integrable f μ := (integrableOn_iff_integrable_of_support_subset (subset_tsupport f)).mp <| hf.continuousOn.integrableOn_compact' hcf (isClosed_tsupport _).measurableSet #align continuous.integrable_of_has_compact_support Continuous.integrable_of_hasCompactSupport end borel open scoped ENNReal section Monotone variable [BorelSpace X] [ConditionallyCompleteLinearOrder X] [ConditionallyCompleteLinearOrder E] [OrderTopology X] [OrderTopology E] [SecondCountableTopology E] theorem MonotoneOn.integrableOn_of_measure_ne_top (hmono : MonotoneOn f s) {a b : X} (ha : IsLeast s a) (hb : IsGreatest s b) (hs : μ s ≠ ∞) (h's : MeasurableSet s) : IntegrableOn f s μ := by borelize E obtain rfl | _ := s.eq_empty_or_nonempty · exact integrableOn_empty have hbelow : BddBelow (f '' s) := ⟨f a, fun x ⟨y, hy, hyx⟩ => hyx ▸ hmono ha.1 hy (ha.2 hy)⟩ have habove : BddAbove (f '' s) := ⟨f b, fun x ⟨y, hy, hyx⟩ => hyx ▸ hmono hy hb.1 (hb.2 hy)⟩ have : IsBounded (f '' s) := Metric.isBounded_of_bddAbove_of_bddBelow habove hbelow rcases isBounded_iff_forall_norm_le.mp this with ⟨C, hC⟩ have A : IntegrableOn (fun _ => C) s μ := by simp only [hs.lt_top, integrableOn_const, or_true_iff] exact Integrable.mono' A (aemeasurable_restrict_of_monotoneOn h's hmono).aestronglyMeasurable ((ae_restrict_iff' h's).mpr <| ae_of_all _ fun y hy => hC (f y) (mem_image_of_mem f hy)) #align monotone_on.integrable_on_of_measure_ne_top MonotoneOn.integrableOn_of_measure_ne_top theorem MonotoneOn.integrableOn_isCompact [IsFiniteMeasureOnCompacts μ] (hs : IsCompact s) (hmono : MonotoneOn f s) : IntegrableOn f s μ := by obtain rfl | h := s.eq_empty_or_nonempty · exact integrableOn_empty · exact hmono.integrableOn_of_measure_ne_top (hs.isLeast_sInf h) (hs.isGreatest_sSup h) hs.measure_lt_top.ne hs.measurableSet #align monotone_on.integrable_on_is_compact MonotoneOn.integrableOn_isCompact theorem AntitoneOn.integrableOn_of_measure_ne_top (hanti : AntitoneOn f s) {a b : X} (ha : IsLeast s a) (hb : IsGreatest s b) (hs : μ s ≠ ∞) (h's : MeasurableSet s) : IntegrableOn f s μ := hanti.dual_right.integrableOn_of_measure_ne_top ha hb hs h's #align antitone_on.integrable_on_of_measure_ne_top AntitoneOn.integrableOn_of_measure_ne_top theorem AntioneOn.integrableOn_isCompact [IsFiniteMeasureOnCompacts μ] (hs : IsCompact s) (hanti : AntitoneOn f s) : IntegrableOn f s μ := hanti.dual_right.integrableOn_isCompact (E := Eᵒᵈ) hs #align antione_on.integrable_on_is_compact AntioneOn.integrableOn_isCompact theorem Monotone.locallyIntegrable [IsLocallyFiniteMeasure μ] (hmono : Monotone f) : LocallyIntegrable f μ := by intro x rcases μ.finiteAt_nhds x with ⟨U, hU, h'U⟩ obtain ⟨a, b, xab, hab, abU⟩ : ∃ a b : X, x ∈ Icc a b ∧ Icc a b ∈ 𝓝 x ∧ Icc a b ⊆ U := exists_Icc_mem_subset_of_mem_nhds hU have ab : a ≤ b := xab.1.trans xab.2 refine ⟨Icc a b, hab, ?_⟩ exact (hmono.monotoneOn _).integrableOn_of_measure_ne_top (isLeast_Icc ab) (isGreatest_Icc ab) ((measure_mono abU).trans_lt h'U).ne measurableSet_Icc #align monotone.locally_integrable Monotone.locallyIntegrable theorem Antitone.locallyIntegrable [IsLocallyFiniteMeasure μ] (hanti : Antitone f) : LocallyIntegrable f μ := hanti.dual_right.locallyIntegrable #align antitone.locally_integrable Antitone.locallyIntegrable end Monotone namespace MeasureTheory variable [OpensMeasurableSpace X] {A K : Set X} section Mul variable [NormedRing R] [SecondCountableTopologyEither X R] {g g' : X → R} theorem IntegrableOn.mul_continuousOn_of_subset (hg : IntegrableOn g A μ) (hg' : ContinuousOn g' K) (hA : MeasurableSet A) (hK : IsCompact K) (hAK : A ⊆ K) : IntegrableOn (fun x => g x * g' x) A μ := by rcases IsCompact.exists_bound_of_continuousOn hK hg' with ⟨C, hC⟩ rw [IntegrableOn, ← memℒp_one_iff_integrable] at hg ⊢ have : ∀ᵐ x ∂μ.restrict A, ‖g x * g' x‖ ≤ C * ‖g x‖ := by filter_upwards [ae_restrict_mem hA] with x hx refine (norm_mul_le _ _).trans ?_ rw [mul_comm] gcongr exact hC x (hAK hx) exact Memℒp.of_le_mul hg (hg.aestronglyMeasurable.mul <| (hg'.mono hAK).aestronglyMeasurable hA) this #align measure_theory.integrable_on.mul_continuous_on_of_subset MeasureTheory.IntegrableOn.mul_continuousOn_of_subset theorem IntegrableOn.mul_continuousOn [T2Space X] (hg : IntegrableOn g K μ) (hg' : ContinuousOn g' K) (hK : IsCompact K) : IntegrableOn (fun x => g x * g' x) K μ := hg.mul_continuousOn_of_subset hg' hK.measurableSet hK (Subset.refl _) #align measure_theory.integrable_on.mul_continuous_on MeasureTheory.IntegrableOn.mul_continuousOn theorem IntegrableOn.continuousOn_mul_of_subset (hg : ContinuousOn g K) (hg' : IntegrableOn g' A μ) (hK : IsCompact K) (hA : MeasurableSet A) (hAK : A ⊆ K) : IntegrableOn (fun x => g x * g' x) A μ := by rcases IsCompact.exists_bound_of_continuousOn hK hg with ⟨C, hC⟩ rw [IntegrableOn, ← memℒp_one_iff_integrable] at hg' ⊢ have : ∀ᵐ x ∂μ.restrict A, ‖g x * g' x‖ ≤ C * ‖g' x‖ := by filter_upwards [ae_restrict_mem hA] with x hx refine (norm_mul_le _ _).trans ?_ gcongr exact hC x (hAK hx) exact Memℒp.of_le_mul hg' (((hg.mono hAK).aestronglyMeasurable hA).mul hg'.aestronglyMeasurable) this #align measure_theory.integrable_on.continuous_on_mul_of_subset MeasureTheory.IntegrableOn.continuousOn_mul_of_subset theorem IntegrableOn.continuousOn_mul [T2Space X] (hg : ContinuousOn g K) (hg' : IntegrableOn g' K μ) (hK : IsCompact K) : IntegrableOn (fun x => g x * g' x) K μ := hg'.continuousOn_mul_of_subset hg hK hK.measurableSet Subset.rfl #align measure_theory.integrable_on.continuous_on_mul MeasureTheory.IntegrableOn.continuousOn_mul end Mul section SMul variable {𝕜 : Type*} [NormedField 𝕜] [NormedSpace 𝕜 E] theorem IntegrableOn.continuousOn_smul [T2Space X] [SecondCountableTopologyEither X 𝕜] {g : X → E} (hg : IntegrableOn g K μ) {f : X → 𝕜} (hf : ContinuousOn f K) (hK : IsCompact K) : IntegrableOn (fun x => f x • g x) K μ := by rw [IntegrableOn, ← integrable_norm_iff] · simp_rw [norm_smul] refine IntegrableOn.continuousOn_mul ?_ hg.norm hK exact continuous_norm.comp_continuousOn hf · exact (hf.aestronglyMeasurable hK.measurableSet).smul hg.1 #align measure_theory.integrable_on.continuous_on_smul MeasureTheory.IntegrableOn.continuousOn_smul theorem IntegrableOn.smul_continuousOn [T2Space X] [SecondCountableTopologyEither X E] {f : X → 𝕜} (hf : IntegrableOn f K μ) {g : X → E} (hg : ContinuousOn g K) (hK : IsCompact K) : IntegrableOn (fun x => f x • g x) K μ := by rw [IntegrableOn, ← integrable_norm_iff] · simp_rw [norm_smul] refine IntegrableOn.mul_continuousOn hf.norm ?_ hK exact continuous_norm.comp_continuousOn hg · exact hf.1.smul (hg.aestronglyMeasurable hK.measurableSet) #align measure_theory.integrable_on.smul_continuous_on MeasureTheory.IntegrableOn.smul_continuousOn end SMul namespace LocallyIntegrableOn theorem continuousOn_mul [LocallyCompactSpace X] [T2Space X] [NormedRing R] [SecondCountableTopologyEither X R] {f g : X → R} {s : Set X} (hf : LocallyIntegrableOn f s μ) (hg : ContinuousOn g s) (hs : IsOpen s) : LocallyIntegrableOn (fun x => g x * f x) s μ := by rw [MeasureTheory.locallyIntegrableOn_iff (Or.inr hs)] at hf ⊢ exact fun k hk_sub hk_c => (hf k hk_sub hk_c).continuousOn_mul (hg.mono hk_sub) hk_c #align measure_theory.locally_integrable_on.continuous_on_mul MeasureTheory.LocallyIntegrableOn.continuousOn_mul theorem mul_continuousOn [LocallyCompactSpace X] [T2Space X] [NormedRing R] [SecondCountableTopologyEither X R] {f g : X → R} {s : Set X} (hf : LocallyIntegrableOn f s μ) (hg : ContinuousOn g s) (hs : IsOpen s) : LocallyIntegrableOn (fun x => f x * g x) s μ := by rw [MeasureTheory.locallyIntegrableOn_iff (Or.inr hs)] at hf ⊢ exact fun k hk_sub hk_c => (hf k hk_sub hk_c).mul_continuousOn (hg.mono hk_sub) hk_c #align measure_theory.locally_integrable_on.mul_continuous_on MeasureTheory.LocallyIntegrableOn.mul_continuousOn
Mathlib/MeasureTheory/Function/LocallyIntegrable.lean
680
685
theorem continuousOn_smul [LocallyCompactSpace X] [T2Space X] {𝕜 : Type*} [NormedField 𝕜] [SecondCountableTopologyEither X 𝕜] [NormedSpace 𝕜 E] {f : X → E} {g : X → 𝕜} {s : Set X} (hs : IsOpen s) (hf : LocallyIntegrableOn f s μ) (hg : ContinuousOn g s) : LocallyIntegrableOn (fun x => g x • f x) s μ := by
rw [MeasureTheory.locallyIntegrableOn_iff (Or.inr hs)] at hf ⊢ exact fun k hk_sub hk_c => (hf k hk_sub hk_c).continuousOn_smul (hg.mono hk_sub) hk_c
/- Copyright (c) 2019 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton, Mario Carneiro, Isabel Longbottom, Scott Morrison -/ import Mathlib.Algebra.Order.ZeroLEOne import Mathlib.Data.List.InsertNth import Mathlib.Logic.Relation import Mathlib.Logic.Small.Defs import Mathlib.Order.GameAdd #align_import set_theory.game.pgame from "leanprover-community/mathlib"@"8900d545017cd21961daa2a1734bb658ef52c618" /-! # Combinatorial (pre-)games. The basic theory of combinatorial games, following Conway's book `On Numbers and Games`. We construct "pregames", define an ordering and arithmetic operations on them, then show that the operations descend to "games", defined via the equivalence relation `p ≈ q ↔ p ≤ q ∧ q ≤ p`. The surreal numbers will be built as a quotient of a subtype of pregames. A pregame (`SetTheory.PGame` below) is axiomatised via an inductive type, whose sole constructor takes two types (thought of as indexing the possible moves for the players Left and Right), and a pair of functions out of these types to `SetTheory.PGame` (thought of as describing the resulting game after making a move). Combinatorial games themselves, as a quotient of pregames, are constructed in `Game.lean`. ## Conway induction By construction, the induction principle for pregames is exactly "Conway induction". That is, to prove some predicate `SetTheory.PGame → Prop` holds for all pregames, it suffices to prove that for every pregame `g`, if the predicate holds for every game resulting from making a move, then it also holds for `g`. While it is often convenient to work "by induction" on pregames, in some situations this becomes awkward, so we also define accessor functions `SetTheory.PGame.LeftMoves`, `SetTheory.PGame.RightMoves`, `SetTheory.PGame.moveLeft` and `SetTheory.PGame.moveRight`. There is a relation `PGame.Subsequent p q`, saying that `p` can be reached by playing some non-empty sequence of moves starting from `q`, an instance `WellFounded Subsequent`, and a local tactic `pgame_wf_tac` which is helpful for discharging proof obligations in inductive proofs relying on this relation. ## Order properties Pregames have both a `≤` and a `<` relation, satisfying the usual properties of a `Preorder`. The relation `0 < x` means that `x` can always be won by Left, while `0 ≤ x` means that `x` can be won by Left as the second player. It turns out to be quite convenient to define various relations on top of these. We define the "less or fuzzy" relation `x ⧏ y` as `¬ y ≤ x`, the equivalence relation `x ≈ y` as `x ≤ y ∧ y ≤ x`, and the fuzzy relation `x ‖ y` as `x ⧏ y ∧ y ⧏ x`. If `0 ⧏ x`, then `x` can be won by Left as the first player. If `x ≈ 0`, then `x` can be won by the second player. If `x ‖ 0`, then `x` can be won by the first player. Statements like `zero_le_lf`, `zero_lf_le`, etc. unfold these definitions. The theorems `le_def` and `lf_def` give a recursive characterisation of each relation in terms of themselves two moves later. The theorems `zero_le`, `zero_lf`, etc. also take into account that `0` has no moves. Later, games will be defined as the quotient by the `≈` relation; that is to say, the `Antisymmetrization` of `SetTheory.PGame`. ## Algebraic structures We next turn to defining the operations necessary to make games into a commutative additive group. Addition is defined for $x = \{xL | xR\}$ and $y = \{yL | yR\}$ by $x + y = \{xL + y, x + yL | xR + y, x + yR\}$. Negation is defined by $\{xL | xR\} = \{-xR | -xL\}$. The order structures interact in the expected way with addition, so we have ``` theorem le_iff_sub_nonneg {x y : PGame} : x ≤ y ↔ 0 ≤ y - x := sorry theorem lt_iff_sub_pos {x y : PGame} : x < y ↔ 0 < y - x := sorry ``` We show that these operations respect the equivalence relation, and hence descend to games. At the level of games, these operations satisfy all the laws of a commutative group. To prove the necessary equivalence relations at the level of pregames, we introduce the notion of a `Relabelling` of a game, and show, for example, that there is a relabelling between `x + (y + z)` and `(x + y) + z`. ## Future work * The theory of dominated and reversible positions, and unique normal form for short games. * Analysis of basic domineering positions. * Hex. * Temperature. * The development of surreal numbers, based on this development of combinatorial games, is still quite incomplete. ## References The material here is all drawn from * [Conway, *On numbers and games*][conway2001] An interested reader may like to formalise some of the material from * [Andreas Blass, *A game semantics for linear logic*][MR1167694] * [André Joyal, *Remarques sur la théorie des jeux à deux personnes*][joyal1997] -/ set_option autoImplicit true namespace SetTheory open Function Relation -- We'd like to be able to use multi-character auto-implicits in this file. set_option relaxedAutoImplicit true /-! ### Pre-game moves -/ /-- The type of pre-games, before we have quotiented by equivalence (`PGame.Setoid`). In ZFC, a combinatorial game is constructed from two sets of combinatorial games that have been constructed at an earlier stage. To do this in type theory, we say that a pre-game is built inductively from two families of pre-games indexed over any type in Type u. The resulting type `PGame.{u}` lives in `Type (u+1)`, reflecting that it is a proper class in ZFC. -/ inductive PGame : Type (u + 1) | mk : ∀ α β : Type u, (α → PGame) → (β → PGame) → PGame #align pgame SetTheory.PGame compile_inductive% PGame namespace PGame /-- The indexing type for allowable moves by Left. -/ def LeftMoves : PGame → Type u | mk l _ _ _ => l #align pgame.left_moves SetTheory.PGame.LeftMoves /-- The indexing type for allowable moves by Right. -/ def RightMoves : PGame → Type u | mk _ r _ _ => r #align pgame.right_moves SetTheory.PGame.RightMoves /-- The new game after Left makes an allowed move. -/ def moveLeft : ∀ g : PGame, LeftMoves g → PGame | mk _l _ L _ => L #align pgame.move_left SetTheory.PGame.moveLeft /-- The new game after Right makes an allowed move. -/ def moveRight : ∀ g : PGame, RightMoves g → PGame | mk _ _r _ R => R #align pgame.move_right SetTheory.PGame.moveRight @[simp] theorem leftMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).LeftMoves = xl := rfl #align pgame.left_moves_mk SetTheory.PGame.leftMoves_mk @[simp] theorem moveLeft_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveLeft = xL := rfl #align pgame.move_left_mk SetTheory.PGame.moveLeft_mk @[simp] theorem rightMoves_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).RightMoves = xr := rfl #align pgame.right_moves_mk SetTheory.PGame.rightMoves_mk @[simp] theorem moveRight_mk {xl xr xL xR} : (⟨xl, xr, xL, xR⟩ : PGame).moveRight = xR := rfl #align pgame.move_right_mk SetTheory.PGame.moveRight_mk -- TODO define this at the level of games, as well, and perhaps also for finsets of games. /-- Construct a pre-game from list of pre-games describing the available moves for Left and Right. -/ def ofLists (L R : List PGame.{u}) : PGame.{u} := mk (ULift (Fin L.length)) (ULift (Fin R.length)) (fun i => L.get i.down) fun j ↦ R.get j.down #align pgame.of_lists SetTheory.PGame.ofLists theorem leftMoves_ofLists (L R : List PGame) : (ofLists L R).LeftMoves = ULift (Fin L.length) := rfl #align pgame.left_moves_of_lists SetTheory.PGame.leftMoves_ofLists theorem rightMoves_ofLists (L R : List PGame) : (ofLists L R).RightMoves = ULift (Fin R.length) := rfl #align pgame.right_moves_of_lists SetTheory.PGame.rightMoves_ofLists /-- Converts a number into a left move for `ofLists`. -/ def toOfListsLeftMoves {L R : List PGame} : Fin L.length ≃ (ofLists L R).LeftMoves := ((Equiv.cast (leftMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_left_moves SetTheory.PGame.toOfListsLeftMoves /-- Converts a number into a right move for `ofLists`. -/ def toOfListsRightMoves {L R : List PGame} : Fin R.length ≃ (ofLists L R).RightMoves := ((Equiv.cast (rightMoves_ofLists L R).symm).trans Equiv.ulift).symm #align pgame.to_of_lists_right_moves SetTheory.PGame.toOfListsRightMoves theorem ofLists_moveLeft {L R : List PGame} (i : Fin L.length) : (ofLists L R).moveLeft (toOfListsLeftMoves i) = L.get i := rfl #align pgame.of_lists_move_left SetTheory.PGame.ofLists_moveLeft @[simp] theorem ofLists_moveLeft' {L R : List PGame} (i : (ofLists L R).LeftMoves) : (ofLists L R).moveLeft i = L.get (toOfListsLeftMoves.symm i) := rfl #align pgame.of_lists_move_left' SetTheory.PGame.ofLists_moveLeft' theorem ofLists_moveRight {L R : List PGame} (i : Fin R.length) : (ofLists L R).moveRight (toOfListsRightMoves i) = R.get i := rfl #align pgame.of_lists_move_right SetTheory.PGame.ofLists_moveRight @[simp] theorem ofLists_moveRight' {L R : List PGame} (i : (ofLists L R).RightMoves) : (ofLists L R).moveRight i = R.get (toOfListsRightMoves.symm i) := rfl #align pgame.of_lists_move_right' SetTheory.PGame.ofLists_moveRight' /-- A variant of `PGame.recOn` expressed in terms of `PGame.moveLeft` and `PGame.moveRight`. Both this and `PGame.recOn` describe Conway induction on games. -/ @[elab_as_elim] def moveRecOn {C : PGame → Sort*} (x : PGame) (IH : ∀ y : PGame, (∀ i, C (y.moveLeft i)) → (∀ j, C (y.moveRight j)) → C y) : C x := x.recOn fun yl yr yL yR => IH (mk yl yr yL yR) #align pgame.move_rec_on SetTheory.PGame.moveRecOn /-- `IsOption x y` means that `x` is either a left or right option for `y`. -/ @[mk_iff] inductive IsOption : PGame → PGame → Prop | moveLeft {x : PGame} (i : x.LeftMoves) : IsOption (x.moveLeft i) x | moveRight {x : PGame} (i : x.RightMoves) : IsOption (x.moveRight i) x #align pgame.is_option SetTheory.PGame.IsOption theorem IsOption.mk_left {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : (xL i).IsOption (mk xl xr xL xR) := @IsOption.moveLeft (mk _ _ _ _) i #align pgame.is_option.mk_left SetTheory.PGame.IsOption.mk_left theorem IsOption.mk_right {xl xr : Type u} (xL : xl → PGame) (xR : xr → PGame) (i : xr) : (xR i).IsOption (mk xl xr xL xR) := @IsOption.moveRight (mk _ _ _ _) i #align pgame.is_option.mk_right SetTheory.PGame.IsOption.mk_right theorem wf_isOption : WellFounded IsOption := ⟨fun x => moveRecOn x fun x IHl IHr => Acc.intro x fun y h => by induction' h with _ i _ j · exact IHl i · exact IHr j⟩ #align pgame.wf_is_option SetTheory.PGame.wf_isOption /-- `Subsequent x y` says that `x` can be obtained by playing some nonempty sequence of moves from `y`. It is the transitive closure of `IsOption`. -/ def Subsequent : PGame → PGame → Prop := TransGen IsOption #align pgame.subsequent SetTheory.PGame.Subsequent instance : IsTrans _ Subsequent := inferInstanceAs <| IsTrans _ (TransGen _) @[trans] theorem Subsequent.trans {x y z} : Subsequent x y → Subsequent y z → Subsequent x z := TransGen.trans #align pgame.subsequent.trans SetTheory.PGame.Subsequent.trans theorem wf_subsequent : WellFounded Subsequent := wf_isOption.transGen #align pgame.wf_subsequent SetTheory.PGame.wf_subsequent instance : WellFoundedRelation PGame := ⟨_, wf_subsequent⟩ @[simp] theorem Subsequent.moveLeft {x : PGame} (i : x.LeftMoves) : Subsequent (x.moveLeft i) x := TransGen.single (IsOption.moveLeft i) #align pgame.subsequent.move_left SetTheory.PGame.Subsequent.moveLeft @[simp] theorem Subsequent.moveRight {x : PGame} (j : x.RightMoves) : Subsequent (x.moveRight j) x := TransGen.single (IsOption.moveRight j) #align pgame.subsequent.move_right SetTheory.PGame.Subsequent.moveRight @[simp] theorem Subsequent.mk_left {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i : xl) : Subsequent (xL i) (mk xl xr xL xR) := @Subsequent.moveLeft (mk _ _ _ _) i #align pgame.subsequent.mk_left SetTheory.PGame.Subsequent.mk_left @[simp] theorem Subsequent.mk_right {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j : xr) : Subsequent (xR j) (mk xl xr xL xR) := @Subsequent.moveRight (mk _ _ _ _) j #align pgame.subsequent.mk_right SetTheory.PGame.Subsequent.mk_right /-- Discharges proof obligations of the form `⊢ Subsequent ..` arising in termination proofs of definitions using well-founded recursion on `PGame`. -/ macro "pgame_wf_tac" : tactic => `(tactic| solve_by_elim (config := { maxDepth := 8 }) [Prod.Lex.left, Prod.Lex.right, PSigma.Lex.left, PSigma.Lex.right, Subsequent.moveLeft, Subsequent.moveRight, Subsequent.mk_left, Subsequent.mk_right, Subsequent.trans] ) -- Register some consequences of pgame_wf_tac as simp-lemmas for convenience -- (which are applied by default for WF goals) -- This is different from mk_right from the POV of the simplifier, -- because the unifier can't solve `xr =?= RightMoves (mk xl xr xL xR)` at reducible transparency. @[simp] theorem Subsequent.mk_right' (xL : xl → PGame) (xR : xr → PGame) (j : RightMoves (mk xl xr xL xR)) : Subsequent (xR j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveRight_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveRight j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_left (xL : xl → PGame) (j) : Subsequent ((xL i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac @[simp] theorem Subsequent.moveLeft_mk_right (xR : xr → PGame) (j) : Subsequent ((xR i).moveLeft j) (mk xl xr xL xR) := by pgame_wf_tac -- Porting note: linter claims these lemmas don't simplify? open Subsequent in attribute [nolint simpNF] mk_left mk_right mk_right' moveRight_mk_left moveRight_mk_right moveLeft_mk_left moveLeft_mk_right /-! ### Basic pre-games -/ /-- The pre-game `Zero` is defined by `0 = { | }`. -/ instance : Zero PGame := ⟨⟨PEmpty, PEmpty, PEmpty.elim, PEmpty.elim⟩⟩ @[simp] theorem zero_leftMoves : LeftMoves 0 = PEmpty := rfl #align pgame.zero_left_moves SetTheory.PGame.zero_leftMoves @[simp] theorem zero_rightMoves : RightMoves 0 = PEmpty := rfl #align pgame.zero_right_moves SetTheory.PGame.zero_rightMoves instance isEmpty_zero_leftMoves : IsEmpty (LeftMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_left_moves SetTheory.PGame.isEmpty_zero_leftMoves instance isEmpty_zero_rightMoves : IsEmpty (RightMoves 0) := instIsEmptyPEmpty #align pgame.is_empty_zero_right_moves SetTheory.PGame.isEmpty_zero_rightMoves instance : Inhabited PGame := ⟨0⟩ /-- The pre-game `One` is defined by `1 = { 0 | }`. -/ instance instOnePGame : One PGame := ⟨⟨PUnit, PEmpty, fun _ => 0, PEmpty.elim⟩⟩ @[simp] theorem one_leftMoves : LeftMoves 1 = PUnit := rfl #align pgame.one_left_moves SetTheory.PGame.one_leftMoves @[simp] theorem one_moveLeft (x) : moveLeft 1 x = 0 := rfl #align pgame.one_move_left SetTheory.PGame.one_moveLeft @[simp] theorem one_rightMoves : RightMoves 1 = PEmpty := rfl #align pgame.one_right_moves SetTheory.PGame.one_rightMoves instance uniqueOneLeftMoves : Unique (LeftMoves 1) := PUnit.unique #align pgame.unique_one_left_moves SetTheory.PGame.uniqueOneLeftMoves instance isEmpty_one_rightMoves : IsEmpty (RightMoves 1) := instIsEmptyPEmpty #align pgame.is_empty_one_right_moves SetTheory.PGame.isEmpty_one_rightMoves /-! ### Pre-game order relations -/ /-- The less or equal relation on pre-games. If `0 ≤ x`, then Left can win `x` as the second player. -/ instance le : LE PGame := ⟨Sym2.GameAdd.fix wf_isOption fun x y le => (∀ i, ¬le y (x.moveLeft i) (Sym2.GameAdd.snd_fst <| IsOption.moveLeft i)) ∧ ∀ j, ¬le (y.moveRight j) x (Sym2.GameAdd.fst_snd <| IsOption.moveRight j)⟩ /-- The less or fuzzy relation on pre-games. If `0 ⧏ x`, then Left can win `x` as the first player. -/ def LF (x y : PGame) : Prop := ¬y ≤ x #align pgame.lf SetTheory.PGame.LF @[inherit_doc] scoped infixl:50 " ⧏ " => PGame.LF @[simp] protected theorem not_le {x y : PGame} : ¬x ≤ y ↔ y ⧏ x := Iff.rfl #align pgame.not_le SetTheory.PGame.not_le @[simp] theorem not_lf {x y : PGame} : ¬x ⧏ y ↔ y ≤ x := Classical.not_not #align pgame.not_lf SetTheory.PGame.not_lf theorem _root_.LE.le.not_gf {x y : PGame} : x ≤ y → ¬y ⧏ x := not_lf.2 #align has_le.le.not_gf LE.le.not_gf theorem LF.not_ge {x y : PGame} : x ⧏ y → ¬y ≤ x := id #align pgame.lf.not_ge SetTheory.PGame.LF.not_ge /-- Definition of `x ≤ y` on pre-games, in terms of `⧏`. The ordering here is chosen so that `And.left` refer to moves by Left, and `And.right` refer to moves by Right. -/ theorem le_iff_forall_lf {x y : PGame} : x ≤ y ↔ (∀ i, x.moveLeft i ⧏ y) ∧ ∀ j, x ⧏ y.moveRight j := by unfold LE.le le simp only rw [Sym2.GameAdd.fix_eq] rfl #align pgame.le_iff_forall_lf SetTheory.PGame.le_iff_forall_lf /-- Definition of `x ≤ y` on pre-games built using the constructor. -/ @[simp] theorem mk_le_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ≤ mk yl yr yL yR ↔ (∀ i, xL i ⧏ mk yl yr yL yR) ∧ ∀ j, mk xl xr xL xR ⧏ yR j := le_iff_forall_lf #align pgame.mk_le_mk SetTheory.PGame.mk_le_mk theorem le_of_forall_lf {x y : PGame} (h₁ : ∀ i, x.moveLeft i ⧏ y) (h₂ : ∀ j, x ⧏ y.moveRight j) : x ≤ y := le_iff_forall_lf.2 ⟨h₁, h₂⟩ #align pgame.le_of_forall_lf SetTheory.PGame.le_of_forall_lf /-- Definition of `x ⧏ y` on pre-games, in terms of `≤`. The ordering here is chosen so that `or.inl` refer to moves by Left, and `or.inr` refer to moves by Right. -/ theorem lf_iff_exists_le {x y : PGame} : x ⧏ y ↔ (∃ i, x ≤ y.moveLeft i) ∨ ∃ j, x.moveRight j ≤ y := by rw [LF, le_iff_forall_lf, not_and_or] simp #align pgame.lf_iff_exists_le SetTheory.PGame.lf_iff_exists_le /-- Definition of `x ⧏ y` on pre-games built using the constructor. -/ @[simp] theorem mk_lf_mk {xl xr xL xR yl yr yL yR} : mk xl xr xL xR ⧏ mk yl yr yL yR ↔ (∃ i, mk xl xr xL xR ≤ yL i) ∨ ∃ j, xR j ≤ mk yl yr yL yR := lf_iff_exists_le #align pgame.mk_lf_mk SetTheory.PGame.mk_lf_mk theorem le_or_gf (x y : PGame) : x ≤ y ∨ y ⧏ x := by rw [← PGame.not_le] apply em #align pgame.le_or_gf SetTheory.PGame.le_or_gf theorem moveLeft_lf_of_le {x y : PGame} (h : x ≤ y) (i) : x.moveLeft i ⧏ y := (le_iff_forall_lf.1 h).1 i #align pgame.move_left_lf_of_le SetTheory.PGame.moveLeft_lf_of_le alias _root_.LE.le.moveLeft_lf := moveLeft_lf_of_le #align has_le.le.move_left_lf LE.le.moveLeft_lf theorem lf_moveRight_of_le {x y : PGame} (h : x ≤ y) (j) : x ⧏ y.moveRight j := (le_iff_forall_lf.1 h).2 j #align pgame.lf_move_right_of_le SetTheory.PGame.lf_moveRight_of_le alias _root_.LE.le.lf_moveRight := lf_moveRight_of_le #align has_le.le.lf_move_right LE.le.lf_moveRight theorem lf_of_moveRight_le {x y : PGame} {j} (h : x.moveRight j ≤ y) : x ⧏ y := lf_iff_exists_le.2 <| Or.inr ⟨j, h⟩ #align pgame.lf_of_move_right_le SetTheory.PGame.lf_of_moveRight_le theorem lf_of_le_moveLeft {x y : PGame} {i} (h : x ≤ y.moveLeft i) : x ⧏ y := lf_iff_exists_le.2 <| Or.inl ⟨i, h⟩ #align pgame.lf_of_le_move_left SetTheory.PGame.lf_of_le_moveLeft theorem lf_of_le_mk {xl xr xL xR y} : mk xl xr xL xR ≤ y → ∀ i, xL i ⧏ y := moveLeft_lf_of_le #align pgame.lf_of_le_mk SetTheory.PGame.lf_of_le_mk theorem lf_of_mk_le {x yl yr yL yR} : x ≤ mk yl yr yL yR → ∀ j, x ⧏ yR j := lf_moveRight_of_le #align pgame.lf_of_mk_le SetTheory.PGame.lf_of_mk_le theorem mk_lf_of_le {xl xr y j} (xL) {xR : xr → PGame} : xR j ≤ y → mk xl xr xL xR ⧏ y := @lf_of_moveRight_le (mk _ _ _ _) y j #align pgame.mk_lf_of_le SetTheory.PGame.mk_lf_of_le theorem lf_mk_of_le {x yl yr} {yL : yl → PGame} (yR) {i} : x ≤ yL i → x ⧏ mk yl yr yL yR := @lf_of_le_moveLeft x (mk _ _ _ _) i #align pgame.lf_mk_of_le SetTheory.PGame.lf_mk_of_le /- We prove that `x ≤ y → y ≤ z → x ≤ z` inductively, by also simultaneously proving its cyclic reorderings. This auxiliary lemma is used during said induction. -/ private theorem le_trans_aux {x y z : PGame} (h₁ : ∀ {i}, y ≤ z → z ≤ x.moveLeft i → y ≤ x.moveLeft i) (h₂ : ∀ {j}, z.moveRight j ≤ x → x ≤ y → z.moveRight j ≤ y) (hxy : x ≤ y) (hyz : y ≤ z) : x ≤ z := le_of_forall_lf (fun i => PGame.not_le.1 fun h => (h₁ hyz h).not_gf <| hxy.moveLeft_lf i) fun j => PGame.not_le.1 fun h => (h₂ h hxy).not_gf <| hyz.lf_moveRight j instance : Preorder PGame := { PGame.le with le_refl := fun x => by induction' x with _ _ _ _ IHl IHr exact le_of_forall_lf (fun i => lf_of_le_moveLeft (IHl i)) fun i => lf_of_moveRight_le (IHr i) le_trans := by suffices ∀ {x y z : PGame}, (x ≤ y → y ≤ z → x ≤ z) ∧ (y ≤ z → z ≤ x → y ≤ x) ∧ (z ≤ x → x ≤ y → z ≤ y) from fun x y z => this.1 intro x y z induction' x with xl xr xL xR IHxl IHxr generalizing y z induction' y with yl yr yL yR IHyl IHyr generalizing z induction' z with zl zr zL zR IHzl IHzr exact ⟨le_trans_aux (fun {i} => (IHxl i).2.1) fun {j} => (IHzr j).2.2, le_trans_aux (fun {i} => (IHyl i).2.2) fun {j} => (IHxr j).1, le_trans_aux (fun {i} => (IHzl i).1) fun {j} => (IHyr j).2.1⟩ lt := fun x y => x ≤ y ∧ x ⧏ y } theorem lt_iff_le_and_lf {x y : PGame} : x < y ↔ x ≤ y ∧ x ⧏ y := Iff.rfl #align pgame.lt_iff_le_and_lf SetTheory.PGame.lt_iff_le_and_lf theorem lt_of_le_of_lf {x y : PGame} (h₁ : x ≤ y) (h₂ : x ⧏ y) : x < y := ⟨h₁, h₂⟩ #align pgame.lt_of_le_of_lf SetTheory.PGame.lt_of_le_of_lf theorem lf_of_lt {x y : PGame} (h : x < y) : x ⧏ y := h.2 #align pgame.lf_of_lt SetTheory.PGame.lf_of_lt alias _root_.LT.lt.lf := lf_of_lt #align has_lt.lt.lf LT.lt.lf theorem lf_irrefl (x : PGame) : ¬x ⧏ x := le_rfl.not_gf #align pgame.lf_irrefl SetTheory.PGame.lf_irrefl instance : IsIrrefl _ (· ⧏ ·) := ⟨lf_irrefl⟩ @[trans] theorem lf_of_le_of_lf {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ⧏ z) : x ⧏ z := by rw [← PGame.not_le] at h₂ ⊢ exact fun h₃ => h₂ (h₃.trans h₁) #align pgame.lf_of_le_of_lf SetTheory.PGame.lf_of_le_of_lf -- Porting note (#10754): added instance instance : Trans (· ≤ ·) (· ⧏ ·) (· ⧏ ·) := ⟨lf_of_le_of_lf⟩ @[trans] theorem lf_of_lf_of_le {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≤ z) : x ⧏ z := by rw [← PGame.not_le] at h₁ ⊢ exact fun h₃ => h₁ (h₂.trans h₃) #align pgame.lf_of_lf_of_le SetTheory.PGame.lf_of_lf_of_le -- Porting note (#10754): added instance instance : Trans (· ⧏ ·) (· ≤ ·) (· ⧏ ·) := ⟨lf_of_lf_of_le⟩ alias _root_.LE.le.trans_lf := lf_of_le_of_lf #align has_le.le.trans_lf LE.le.trans_lf alias LF.trans_le := lf_of_lf_of_le #align pgame.lf.trans_le SetTheory.PGame.LF.trans_le @[trans] theorem lf_of_lt_of_lf {x y z : PGame} (h₁ : x < y) (h₂ : y ⧏ z) : x ⧏ z := h₁.le.trans_lf h₂ #align pgame.lf_of_lt_of_lf SetTheory.PGame.lf_of_lt_of_lf @[trans] theorem lf_of_lf_of_lt {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y < z) : x ⧏ z := h₁.trans_le h₂.le #align pgame.lf_of_lf_of_lt SetTheory.PGame.lf_of_lf_of_lt alias _root_.LT.lt.trans_lf := lf_of_lt_of_lf #align has_lt.lt.trans_lf LT.lt.trans_lf alias LF.trans_lt := lf_of_lf_of_lt #align pgame.lf.trans_lt SetTheory.PGame.LF.trans_lt theorem moveLeft_lf {x : PGame} : ∀ i, x.moveLeft i ⧏ x := le_rfl.moveLeft_lf #align pgame.move_left_lf SetTheory.PGame.moveLeft_lf theorem lf_moveRight {x : PGame} : ∀ j, x ⧏ x.moveRight j := le_rfl.lf_moveRight #align pgame.lf_move_right SetTheory.PGame.lf_moveRight theorem lf_mk {xl xr} (xL : xl → PGame) (xR : xr → PGame) (i) : xL i ⧏ mk xl xr xL xR := @moveLeft_lf (mk _ _ _ _) i #align pgame.lf_mk SetTheory.PGame.lf_mk theorem mk_lf {xl xr} (xL : xl → PGame) (xR : xr → PGame) (j) : mk xl xr xL xR ⧏ xR j := @lf_moveRight (mk _ _ _ _) j #align pgame.mk_lf SetTheory.PGame.mk_lf /-- This special case of `PGame.le_of_forall_lf` is useful when dealing with surreals, where `<` is preferred over `⧏`. -/ theorem le_of_forall_lt {x y : PGame} (h₁ : ∀ i, x.moveLeft i < y) (h₂ : ∀ j, x < y.moveRight j) : x ≤ y := le_of_forall_lf (fun i => (h₁ i).lf) fun i => (h₂ i).lf #align pgame.le_of_forall_lt SetTheory.PGame.le_of_forall_lt /-- The definition of `x ≤ y` on pre-games, in terms of `≤` two moves later. -/ theorem le_def {x y : PGame} : x ≤ y ↔ (∀ i, (∃ i', x.moveLeft i ≤ y.moveLeft i') ∨ ∃ j, (x.moveLeft i).moveRight j ≤ y) ∧ ∀ j, (∃ i, x ≤ (y.moveRight j).moveLeft i) ∨ ∃ j', x.moveRight j' ≤ y.moveRight j := by rw [le_iff_forall_lf] conv => lhs simp only [lf_iff_exists_le] #align pgame.le_def SetTheory.PGame.le_def /-- The definition of `x ⧏ y` on pre-games, in terms of `⧏` two moves later. -/ theorem lf_def {x y : PGame} : x ⧏ y ↔ (∃ i, (∀ i', x.moveLeft i' ⧏ y.moveLeft i) ∧ ∀ j, x ⧏ (y.moveLeft i).moveRight j) ∨ ∃ j, (∀ i, (x.moveRight j).moveLeft i ⧏ y) ∧ ∀ j', x.moveRight j ⧏ y.moveRight j' := by rw [lf_iff_exists_le] conv => lhs simp only [le_iff_forall_lf] #align pgame.lf_def SetTheory.PGame.lf_def /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ⧏`. -/ theorem zero_le_lf {x : PGame} : 0 ≤ x ↔ ∀ j, 0 ⧏ x.moveRight j := by rw [le_iff_forall_lf] simp #align pgame.zero_le_lf SetTheory.PGame.zero_le_lf /-- The definition of `x ≤ 0` on pre-games, in terms of `⧏ 0`. -/ theorem le_zero_lf {x : PGame} : x ≤ 0 ↔ ∀ i, x.moveLeft i ⧏ 0 := by rw [le_iff_forall_lf] simp #align pgame.le_zero_lf SetTheory.PGame.le_zero_lf /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ≤`. -/ theorem zero_lf_le {x : PGame} : 0 ⧏ x ↔ ∃ i, 0 ≤ x.moveLeft i := by rw [lf_iff_exists_le] simp #align pgame.zero_lf_le SetTheory.PGame.zero_lf_le /-- The definition of `x ⧏ 0` on pre-games, in terms of `≤ 0`. -/ theorem lf_zero_le {x : PGame} : x ⧏ 0 ↔ ∃ j, x.moveRight j ≤ 0 := by rw [lf_iff_exists_le] simp #align pgame.lf_zero_le SetTheory.PGame.lf_zero_le /-- The definition of `0 ≤ x` on pre-games, in terms of `0 ≤` two moves later. -/ theorem zero_le {x : PGame} : 0 ≤ x ↔ ∀ j, ∃ i, 0 ≤ (x.moveRight j).moveLeft i := by rw [le_def] simp #align pgame.zero_le SetTheory.PGame.zero_le /-- The definition of `x ≤ 0` on pre-games, in terms of `≤ 0` two moves later. -/ theorem le_zero {x : PGame} : x ≤ 0 ↔ ∀ i, ∃ j, (x.moveLeft i).moveRight j ≤ 0 := by rw [le_def] simp #align pgame.le_zero SetTheory.PGame.le_zero /-- The definition of `0 ⧏ x` on pre-games, in terms of `0 ⧏` two moves later. -/ theorem zero_lf {x : PGame} : 0 ⧏ x ↔ ∃ i, ∀ j, 0 ⧏ (x.moveLeft i).moveRight j := by rw [lf_def] simp #align pgame.zero_lf SetTheory.PGame.zero_lf /-- The definition of `x ⧏ 0` on pre-games, in terms of `⧏ 0` two moves later. -/ theorem lf_zero {x : PGame} : x ⧏ 0 ↔ ∃ j, ∀ i, (x.moveRight j).moveLeft i ⧏ 0 := by rw [lf_def] simp #align pgame.lf_zero SetTheory.PGame.lf_zero @[simp] theorem zero_le_of_isEmpty_rightMoves (x : PGame) [IsEmpty x.RightMoves] : 0 ≤ x := zero_le.2 isEmptyElim #align pgame.zero_le_of_is_empty_right_moves SetTheory.PGame.zero_le_of_isEmpty_rightMoves @[simp] theorem le_zero_of_isEmpty_leftMoves (x : PGame) [IsEmpty x.LeftMoves] : x ≤ 0 := le_zero.2 isEmptyElim #align pgame.le_zero_of_is_empty_left_moves SetTheory.PGame.le_zero_of_isEmpty_leftMoves /-- Given a game won by the right player when they play second, provide a response to any move by left. -/ noncomputable def rightResponse {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).RightMoves := Classical.choose <| (le_zero.1 h) i #align pgame.right_response SetTheory.PGame.rightResponse /-- Show that the response for right provided by `rightResponse` preserves the right-player-wins condition. -/ theorem rightResponse_spec {x : PGame} (h : x ≤ 0) (i : x.LeftMoves) : (x.moveLeft i).moveRight (rightResponse h i) ≤ 0 := Classical.choose_spec <| (le_zero.1 h) i #align pgame.right_response_spec SetTheory.PGame.rightResponse_spec /-- Given a game won by the left player when they play second, provide a response to any move by right. -/ noncomputable def leftResponse {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : (x.moveRight j).LeftMoves := Classical.choose <| (zero_le.1 h) j #align pgame.left_response SetTheory.PGame.leftResponse /-- Show that the response for left provided by `leftResponse` preserves the left-player-wins condition. -/ theorem leftResponse_spec {x : PGame} (h : 0 ≤ x) (j : x.RightMoves) : 0 ≤ (x.moveRight j).moveLeft (leftResponse h j) := Classical.choose_spec <| (zero_le.1 h) j #align pgame.left_response_spec SetTheory.PGame.leftResponse_spec #noalign pgame.upper_bound #noalign pgame.upper_bound_right_moves_empty #noalign pgame.le_upper_bound #noalign pgame.upper_bound_mem_upper_bounds /-- A small family of pre-games is bounded above. -/ lemma bddAbove_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddAbove (Set.range f) := by let x : PGame.{u} := ⟨Σ i, (f $ (equivShrink.{u} ι).symm i).LeftMoves, PEmpty, fun x ↦ moveLeft _ x.2, PEmpty.elim⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @moveLeft_lf x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded above. -/ lemma bddAbove_of_small (s : Set PGame.{u}) [Small.{u} s] : BddAbove s := by simpa using bddAbove_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_above_of_small SetTheory.PGame.bddAbove_of_small #noalign pgame.lower_bound #noalign pgame.lower_bound_left_moves_empty #noalign pgame.lower_bound_le #noalign pgame.lower_bound_mem_lower_bounds /-- A small family of pre-games is bounded below. -/ lemma bddBelow_range_of_small [Small.{u} ι] (f : ι → PGame.{u}) : BddBelow (Set.range f) := by let x : PGame.{u} := ⟨PEmpty, Σ i, (f $ (equivShrink.{u} ι).symm i).RightMoves, PEmpty.elim, fun x ↦ moveRight _ x.2⟩ refine ⟨x, Set.forall_mem_range.2 fun i ↦ ?_⟩ rw [← (equivShrink ι).symm_apply_apply i, le_iff_forall_lf] simpa [x] using fun j ↦ @lf_moveRight x ⟨equivShrink ι i, j⟩ /-- A small set of pre-games is bounded below. -/ lemma bddBelow_of_small (s : Set PGame.{u}) [Small.{u} s] : BddBelow s := by simpa using bddBelow_range_of_small (Subtype.val : s → PGame.{u}) #align pgame.bdd_below_of_small SetTheory.PGame.bddBelow_of_small /-- The equivalence relation on pre-games. Two pre-games `x`, `y` are equivalent if `x ≤ y` and `y ≤ x`. If `x ≈ 0`, then the second player can always win `x`. -/ def Equiv (x y : PGame) : Prop := x ≤ y ∧ y ≤ x #align pgame.equiv SetTheory.PGame.Equiv -- Porting note: deleted the scoped notation due to notation overloading with the setoid -- instance and this causes the PGame.equiv docstring to not show up on hover. instance : IsEquiv _ PGame.Equiv where refl _ := ⟨le_rfl, le_rfl⟩ trans := fun _ _ _ ⟨xy, yx⟩ ⟨yz, zy⟩ => ⟨xy.trans yz, zy.trans yx⟩ symm _ _ := And.symm -- Porting note: moved the setoid instance from Basic.lean to here instance setoid : Setoid PGame := ⟨Equiv, refl, symm, Trans.trans⟩ #align pgame.setoid SetTheory.PGame.setoid theorem Equiv.le {x y : PGame} (h : x ≈ y) : x ≤ y := h.1 #align pgame.equiv.le SetTheory.PGame.Equiv.le theorem Equiv.ge {x y : PGame} (h : x ≈ y) : y ≤ x := h.2 #align pgame.equiv.ge SetTheory.PGame.Equiv.ge @[refl, simp] theorem equiv_rfl {x : PGame} : x ≈ x := refl x #align pgame.equiv_rfl SetTheory.PGame.equiv_rfl theorem equiv_refl (x : PGame) : x ≈ x := refl x #align pgame.equiv_refl SetTheory.PGame.equiv_refl @[symm] protected theorem Equiv.symm {x y : PGame} : (x ≈ y) → (y ≈ x) := symm #align pgame.equiv.symm SetTheory.PGame.Equiv.symm @[trans] protected theorem Equiv.trans {x y z : PGame} : (x ≈ y) → (y ≈ z) → (x ≈ z) := _root_.trans #align pgame.equiv.trans SetTheory.PGame.Equiv.trans protected theorem equiv_comm {x y : PGame} : (x ≈ y) ↔ (y ≈ x) := comm #align pgame.equiv_comm SetTheory.PGame.equiv_comm theorem equiv_of_eq {x y : PGame} (h : x = y) : x ≈ y := by subst h; rfl #align pgame.equiv_of_eq SetTheory.PGame.equiv_of_eq @[trans] theorem le_of_le_of_equiv {x y z : PGame} (h₁ : x ≤ y) (h₂ : y ≈ z) : x ≤ z := h₁.trans h₂.1 #align pgame.le_of_le_of_equiv SetTheory.PGame.le_of_le_of_equiv instance : Trans ((· ≤ ·) : PGame → PGame → Prop) ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_le_of_equiv @[trans] theorem le_of_equiv_of_le {x y z : PGame} (h₁ : x ≈ y) : y ≤ z → x ≤ z := h₁.1.trans #align pgame.le_of_equiv_of_le SetTheory.PGame.le_of_equiv_of_le instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) ((· ≤ ·) : PGame → PGame → Prop) where trans := le_of_equiv_of_le theorem LF.not_equiv {x y : PGame} (h : x ⧏ y) : ¬(x ≈ y) := fun h' => h.not_ge h'.2 #align pgame.lf.not_equiv SetTheory.PGame.LF.not_equiv theorem LF.not_equiv' {x y : PGame} (h : x ⧏ y) : ¬(y ≈ x) := fun h' => h.not_ge h'.1 #align pgame.lf.not_equiv' SetTheory.PGame.LF.not_equiv' theorem LF.not_gt {x y : PGame} (h : x ⧏ y) : ¬y < x := fun h' => h.not_ge h'.le #align pgame.lf.not_gt SetTheory.PGame.LF.not_gt theorem le_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ ≤ y₁) : x₂ ≤ y₂ := hx.2.trans (h.trans hy.1) #align pgame.le_congr_imp SetTheory.PGame.le_congr_imp theorem le_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ≤ y₁ ↔ x₂ ≤ y₂ := ⟨le_congr_imp hx hy, le_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.le_congr SetTheory.PGame.le_congr theorem le_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ≤ y ↔ x₂ ≤ y := le_congr hx equiv_rfl #align pgame.le_congr_left SetTheory.PGame.le_congr_left theorem le_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ≤ y₁ ↔ x ≤ y₂ := le_congr equiv_rfl hy #align pgame.le_congr_right SetTheory.PGame.le_congr_right theorem lf_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ ↔ x₂ ⧏ y₂ := PGame.not_le.symm.trans <| (not_congr (le_congr hy hx)).trans PGame.not_le #align pgame.lf_congr SetTheory.PGame.lf_congr theorem lf_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ⧏ y₁ → x₂ ⧏ y₂ := (lf_congr hx hy).1 #align pgame.lf_congr_imp SetTheory.PGame.lf_congr_imp theorem lf_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ⧏ y ↔ x₂ ⧏ y := lf_congr hx equiv_rfl #align pgame.lf_congr_left SetTheory.PGame.lf_congr_left theorem lf_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ⧏ y₁ ↔ x ⧏ y₂ := lf_congr equiv_rfl hy #align pgame.lf_congr_right SetTheory.PGame.lf_congr_right @[trans] theorem lf_of_lf_of_equiv {x y z : PGame} (h₁ : x ⧏ y) (h₂ : y ≈ z) : x ⧏ z := lf_congr_imp equiv_rfl h₂ h₁ #align pgame.lf_of_lf_of_equiv SetTheory.PGame.lf_of_lf_of_equiv @[trans] theorem lf_of_equiv_of_lf {x y z : PGame} (h₁ : x ≈ y) : y ⧏ z → x ⧏ z := lf_congr_imp (Equiv.symm h₁) equiv_rfl #align pgame.lf_of_equiv_of_lf SetTheory.PGame.lf_of_equiv_of_lf @[trans] theorem lt_of_lt_of_equiv {x y z : PGame} (h₁ : x < y) (h₂ : y ≈ z) : x < z := h₁.trans_le h₂.1 #align pgame.lt_of_lt_of_equiv SetTheory.PGame.lt_of_lt_of_equiv @[trans] theorem lt_of_equiv_of_lt {x y z : PGame} (h₁ : x ≈ y) : y < z → x < z := h₁.1.trans_lt #align pgame.lt_of_equiv_of_lt SetTheory.PGame.lt_of_equiv_of_lt instance : Trans ((· ≈ ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) ((· < ·) : PGame → PGame → Prop) where trans := lt_of_equiv_of_lt theorem lt_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) (h : x₁ < y₁) : x₂ < y₂ := hx.2.trans_lt (h.trans_le hy.1) #align pgame.lt_congr_imp SetTheory.PGame.lt_congr_imp theorem lt_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ < y₁ ↔ x₂ < y₂ := ⟨lt_congr_imp hx hy, lt_congr_imp (Equiv.symm hx) (Equiv.symm hy)⟩ #align pgame.lt_congr SetTheory.PGame.lt_congr theorem lt_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ < y ↔ x₂ < y := lt_congr hx equiv_rfl #align pgame.lt_congr_left SetTheory.PGame.lt_congr_left theorem lt_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x < y₁ ↔ x < y₂ := lt_congr equiv_rfl hy #align pgame.lt_congr_right SetTheory.PGame.lt_congr_right theorem lt_or_equiv_of_le {x y : PGame} (h : x ≤ y) : x < y ∨ (x ≈ y) := and_or_left.mp ⟨h, (em <| y ≤ x).symm.imp_left PGame.not_le.1⟩ #align pgame.lt_or_equiv_of_le SetTheory.PGame.lt_or_equiv_of_le theorem lf_or_equiv_or_gf (x y : PGame) : x ⧏ y ∨ (x ≈ y) ∨ y ⧏ x := by by_cases h : x ⧏ y · exact Or.inl h · right cases' lt_or_equiv_of_le (PGame.not_lf.1 h) with h' h' · exact Or.inr h'.lf · exact Or.inl (Equiv.symm h') #align pgame.lf_or_equiv_or_gf SetTheory.PGame.lf_or_equiv_or_gf theorem equiv_congr_left {y₁ y₂ : PGame} : (y₁ ≈ y₂) ↔ ∀ x₁, (x₁ ≈ y₁) ↔ (x₁ ≈ y₂) := ⟨fun h _ => ⟨fun h' => Equiv.trans h' h, fun h' => Equiv.trans h' (Equiv.symm h)⟩, fun h => (h y₁).1 <| equiv_rfl⟩ #align pgame.equiv_congr_left SetTheory.PGame.equiv_congr_left theorem equiv_congr_right {x₁ x₂ : PGame} : (x₁ ≈ x₂) ↔ ∀ y₁, (x₁ ≈ y₁) ↔ (x₂ ≈ y₁) := ⟨fun h _ => ⟨fun h' => Equiv.trans (Equiv.symm h) h', fun h' => Equiv.trans h h'⟩, fun h => (h x₂).2 <| equiv_rfl⟩ #align pgame.equiv_congr_right SetTheory.PGame.equiv_congr_right theorem equiv_of_mk_equiv {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves) (hl : ∀ i, x.moveLeft i ≈ y.moveLeft (L i)) (hr : ∀ j, x.moveRight j ≈ y.moveRight (R j)) : x ≈ y := by constructor <;> rw [le_def] · exact ⟨fun i => Or.inl ⟨_, (hl i).1⟩, fun j => Or.inr ⟨_, by simpa using (hr (R.symm j)).1⟩⟩ · exact ⟨fun i => Or.inl ⟨_, by simpa using (hl (L.symm i)).2⟩, fun j => Or.inr ⟨_, (hr j).2⟩⟩ #align pgame.equiv_of_mk_equiv SetTheory.PGame.equiv_of_mk_equiv /-- The fuzzy, confused, or incomparable relation on pre-games. If `x ‖ 0`, then the first player can always win `x`. -/ def Fuzzy (x y : PGame) : Prop := x ⧏ y ∧ y ⧏ x #align pgame.fuzzy SetTheory.PGame.Fuzzy @[inherit_doc] scoped infixl:50 " ‖ " => PGame.Fuzzy @[symm] theorem Fuzzy.swap {x y : PGame} : x ‖ y → y ‖ x := And.symm #align pgame.fuzzy.swap SetTheory.PGame.Fuzzy.swap instance : IsSymm _ (· ‖ ·) := ⟨fun _ _ => Fuzzy.swap⟩ theorem Fuzzy.swap_iff {x y : PGame} : x ‖ y ↔ y ‖ x := ⟨Fuzzy.swap, Fuzzy.swap⟩ #align pgame.fuzzy.swap_iff SetTheory.PGame.Fuzzy.swap_iff theorem fuzzy_irrefl (x : PGame) : ¬x ‖ x := fun h => lf_irrefl x h.1 #align pgame.fuzzy_irrefl SetTheory.PGame.fuzzy_irrefl instance : IsIrrefl _ (· ‖ ·) := ⟨fuzzy_irrefl⟩ theorem lf_iff_lt_or_fuzzy {x y : PGame} : x ⧏ y ↔ x < y ∨ x ‖ y := by simp only [lt_iff_le_and_lf, Fuzzy, ← PGame.not_le] tauto #align pgame.lf_iff_lt_or_fuzzy SetTheory.PGame.lf_iff_lt_or_fuzzy theorem lf_of_fuzzy {x y : PGame} (h : x ‖ y) : x ⧏ y := lf_iff_lt_or_fuzzy.2 (Or.inr h) #align pgame.lf_of_fuzzy SetTheory.PGame.lf_of_fuzzy alias Fuzzy.lf := lf_of_fuzzy #align pgame.fuzzy.lf SetTheory.PGame.Fuzzy.lf theorem lt_or_fuzzy_of_lf {x y : PGame} : x ⧏ y → x < y ∨ x ‖ y := lf_iff_lt_or_fuzzy.1 #align pgame.lt_or_fuzzy_of_lf SetTheory.PGame.lt_or_fuzzy_of_lf theorem Fuzzy.not_equiv {x y : PGame} (h : x ‖ y) : ¬(x ≈ y) := fun h' => h'.1.not_gf h.2 #align pgame.fuzzy.not_equiv SetTheory.PGame.Fuzzy.not_equiv theorem Fuzzy.not_equiv' {x y : PGame} (h : x ‖ y) : ¬(y ≈ x) := fun h' => h'.2.not_gf h.2 #align pgame.fuzzy.not_equiv' SetTheory.PGame.Fuzzy.not_equiv' theorem not_fuzzy_of_le {x y : PGame} (h : x ≤ y) : ¬x ‖ y := fun h' => h'.2.not_ge h #align pgame.not_fuzzy_of_le SetTheory.PGame.not_fuzzy_of_le theorem not_fuzzy_of_ge {x y : PGame} (h : y ≤ x) : ¬x ‖ y := fun h' => h'.1.not_ge h #align pgame.not_fuzzy_of_ge SetTheory.PGame.not_fuzzy_of_ge theorem Equiv.not_fuzzy {x y : PGame} (h : x ≈ y) : ¬x ‖ y := not_fuzzy_of_le h.1 #align pgame.equiv.not_fuzzy SetTheory.PGame.Equiv.not_fuzzy theorem Equiv.not_fuzzy' {x y : PGame} (h : x ≈ y) : ¬y ‖ x := not_fuzzy_of_le h.2 #align pgame.equiv.not_fuzzy' SetTheory.PGame.Equiv.not_fuzzy' theorem fuzzy_congr {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ ↔ x₂ ‖ y₂ := show _ ∧ _ ↔ _ ∧ _ by rw [lf_congr hx hy, lf_congr hy hx] #align pgame.fuzzy_congr SetTheory.PGame.fuzzy_congr theorem fuzzy_congr_imp {x₁ y₁ x₂ y₂ : PGame} (hx : x₁ ≈ x₂) (hy : y₁ ≈ y₂) : x₁ ‖ y₁ → x₂ ‖ y₂ := (fuzzy_congr hx hy).1 #align pgame.fuzzy_congr_imp SetTheory.PGame.fuzzy_congr_imp theorem fuzzy_congr_left {x₁ x₂ y : PGame} (hx : x₁ ≈ x₂) : x₁ ‖ y ↔ x₂ ‖ y := fuzzy_congr hx equiv_rfl #align pgame.fuzzy_congr_left SetTheory.PGame.fuzzy_congr_left theorem fuzzy_congr_right {x y₁ y₂ : PGame} (hy : y₁ ≈ y₂) : x ‖ y₁ ↔ x ‖ y₂ := fuzzy_congr equiv_rfl hy #align pgame.fuzzy_congr_right SetTheory.PGame.fuzzy_congr_right @[trans] theorem fuzzy_of_fuzzy_of_equiv {x y z : PGame} (h₁ : x ‖ y) (h₂ : y ≈ z) : x ‖ z := (fuzzy_congr_right h₂).1 h₁ #align pgame.fuzzy_of_fuzzy_of_equiv SetTheory.PGame.fuzzy_of_fuzzy_of_equiv @[trans] theorem fuzzy_of_equiv_of_fuzzy {x y z : PGame} (h₁ : x ≈ y) (h₂ : y ‖ z) : x ‖ z := (fuzzy_congr_left h₁).2 h₂ #align pgame.fuzzy_of_equiv_of_fuzzy SetTheory.PGame.fuzzy_of_equiv_of_fuzzy /-- Exactly one of the following is true (although we don't prove this here). -/ theorem lt_or_equiv_or_gt_or_fuzzy (x y : PGame) : x < y ∨ (x ≈ y) ∨ y < x ∨ x ‖ y := by cases' le_or_gf x y with h₁ h₁ <;> cases' le_or_gf y x with h₂ h₂ · right left exact ⟨h₁, h₂⟩ · left exact ⟨h₁, h₂⟩ · right right left exact ⟨h₂, h₁⟩ · right right right exact ⟨h₂, h₁⟩ #align pgame.lt_or_equiv_or_gt_or_fuzzy SetTheory.PGame.lt_or_equiv_or_gt_or_fuzzy theorem lt_or_equiv_or_gf (x y : PGame) : x < y ∨ (x ≈ y) ∨ y ⧏ x := by rw [lf_iff_lt_or_fuzzy, Fuzzy.swap_iff] exact lt_or_equiv_or_gt_or_fuzzy x y #align pgame.lt_or_equiv_or_gf SetTheory.PGame.lt_or_equiv_or_gf /-! ### Relabellings -/ /-- `Relabelling x y` says that `x` and `y` are really the same game, just dressed up differently. Specifically, there is a bijection between the moves for Left in `x` and in `y`, and similarly for Right, and under these bijections we inductively have `Relabelling`s for the consequent games. -/ inductive Relabelling : PGame.{u} → PGame.{u} → Type (u + 1) | mk : ∀ {x y : PGame} (L : x.LeftMoves ≃ y.LeftMoves) (R : x.RightMoves ≃ y.RightMoves), (∀ i, Relabelling (x.moveLeft i) (y.moveLeft (L i))) → (∀ j, Relabelling (x.moveRight j) (y.moveRight (R j))) → Relabelling x y #align pgame.relabelling SetTheory.PGame.Relabelling @[inherit_doc] scoped infixl:50 " ≡r " => PGame.Relabelling namespace Relabelling variable {x y : PGame.{u}} /-- A constructor for relabellings swapping the equivalences. -/ def mk' (L : y.LeftMoves ≃ x.LeftMoves) (R : y.RightMoves ≃ x.RightMoves) (hL : ∀ i, x.moveLeft (L i) ≡r y.moveLeft i) (hR : ∀ j, x.moveRight (R j) ≡r y.moveRight j) : x ≡r y := ⟨L.symm, R.symm, fun i => by simpa using hL (L.symm i), fun j => by simpa using hR (R.symm j)⟩ #align pgame.relabelling.mk' SetTheory.PGame.Relabelling.mk' /-- The equivalence between left moves of `x` and `y` given by the relabelling. -/ def leftMovesEquiv : x ≡r y → x.LeftMoves ≃ y.LeftMoves | ⟨L,_, _,_⟩ => L #align pgame.relabelling.left_moves_equiv SetTheory.PGame.Relabelling.leftMovesEquiv @[simp] theorem mk_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).leftMovesEquiv = L := rfl #align pgame.relabelling.mk_left_moves_equiv SetTheory.PGame.Relabelling.mk_leftMovesEquiv @[simp] theorem mk'_leftMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).leftMovesEquiv = L.symm := rfl #align pgame.relabelling.mk'_left_moves_equiv SetTheory.PGame.Relabelling.mk'_leftMovesEquiv /-- The equivalence between right moves of `x` and `y` given by the relabelling. -/ def rightMovesEquiv : x ≡r y → x.RightMoves ≃ y.RightMoves | ⟨_, R, _, _⟩ => R #align pgame.relabelling.right_moves_equiv SetTheory.PGame.Relabelling.rightMovesEquiv @[simp] theorem mk_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk x y L R hL hR).rightMovesEquiv = R := rfl #align pgame.relabelling.mk_right_moves_equiv SetTheory.PGame.Relabelling.mk_rightMovesEquiv @[simp] theorem mk'_rightMovesEquiv {x y L R hL hR} : (@Relabelling.mk' x y L R hL hR).rightMovesEquiv = R.symm := rfl #align pgame.relabelling.mk'_right_moves_equiv SetTheory.PGame.Relabelling.mk'_rightMovesEquiv /-- A left move of `x` is a relabelling of a left move of `y`. -/ def moveLeft : ∀ (r : x ≡r y) (i : x.LeftMoves), x.moveLeft i ≡r y.moveLeft (r.leftMovesEquiv i) | ⟨_, _, hL, _⟩ => hL #align pgame.relabelling.move_left SetTheory.PGame.Relabelling.moveLeft /-- A left move of `y` is a relabelling of a left move of `x`. -/ def moveLeftSymm : ∀ (r : x ≡r y) (i : y.LeftMoves), x.moveLeft (r.leftMovesEquiv.symm i) ≡r y.moveLeft i | ⟨L, R, hL, hR⟩, i => by simpa using hL (L.symm i) #align pgame.relabelling.move_left_symm SetTheory.PGame.Relabelling.moveLeftSymm /-- A right move of `x` is a relabelling of a right move of `y`. -/ def moveRight : ∀ (r : x ≡r y) (i : x.RightMoves), x.moveRight i ≡r y.moveRight (r.rightMovesEquiv i) | ⟨_, _, _, hR⟩ => hR #align pgame.relabelling.move_right SetTheory.PGame.Relabelling.moveRight /-- A right move of `y` is a relabelling of a right move of `x`. -/ def moveRightSymm : ∀ (r : x ≡r y) (i : y.RightMoves), x.moveRight (r.rightMovesEquiv.symm i) ≡r y.moveRight i | ⟨L, R, hL, hR⟩, i => by simpa using hR (R.symm i) #align pgame.relabelling.move_right_symm SetTheory.PGame.Relabelling.moveRightSymm /-- The identity relabelling. -/ @[refl] def refl (x : PGame) : x ≡r x := ⟨Equiv.refl _, Equiv.refl _, fun i => refl _, fun j => refl _⟩ termination_by x #align pgame.relabelling.refl SetTheory.PGame.Relabelling.refl instance (x : PGame) : Inhabited (x ≡r x) := ⟨refl _⟩ /-- Flip a relabelling. -/ @[symm] def symm : ∀ {x y : PGame}, x ≡r y → y ≡r x | _, _, ⟨L, R, hL, hR⟩ => mk' L R (fun i => (hL i).symm) fun j => (hR j).symm #align pgame.relabelling.symm SetTheory.PGame.Relabelling.symm theorem le {x y : PGame} (r : x ≡r y) : x ≤ y := le_def.2 ⟨fun i => Or.inl ⟨_, (r.moveLeft i).le⟩, fun j => Or.inr ⟨_, (r.moveRightSymm j).le⟩⟩ termination_by x #align pgame.relabelling.le SetTheory.PGame.Relabelling.le theorem ge {x y : PGame} (r : x ≡r y) : y ≤ x := r.symm.le #align pgame.relabelling.ge SetTheory.PGame.Relabelling.ge /-- A relabelling lets us prove equivalence of games. -/ theorem equiv (r : x ≡r y) : x ≈ y := ⟨r.le, r.ge⟩ #align pgame.relabelling.equiv SetTheory.PGame.Relabelling.equiv /-- Transitivity of relabelling. -/ @[trans] def trans : ∀ {x y z : PGame}, x ≡r y → y ≡r z → x ≡r z | _, _, _, ⟨L₁, R₁, hL₁, hR₁⟩, ⟨L₂, R₂, hL₂, hR₂⟩ => ⟨L₁.trans L₂, R₁.trans R₂, fun i => (hL₁ i).trans (hL₂ _), fun j => (hR₁ j).trans (hR₂ _)⟩ #align pgame.relabelling.trans SetTheory.PGame.Relabelling.trans /-- Any game without left or right moves is a relabelling of 0. -/ def isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≡r 0 := ⟨Equiv.equivPEmpty _, Equiv.equivOfIsEmpty _ _, isEmptyElim, isEmptyElim⟩ #align pgame.relabelling.is_empty SetTheory.PGame.Relabelling.isEmpty end Relabelling theorem Equiv.isEmpty (x : PGame) [IsEmpty x.LeftMoves] [IsEmpty x.RightMoves] : x ≈ 0 := (Relabelling.isEmpty x).equiv #align pgame.equiv.is_empty SetTheory.PGame.Equiv.isEmpty instance {x y : PGame} : Coe (x ≡r y) (x ≈ y) := ⟨Relabelling.equiv⟩ /-- Replace the types indexing the next moves for Left and Right by equivalent types. -/ def relabel {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) : PGame := ⟨xl', xr', x.moveLeft ∘ el, x.moveRight ∘ er⟩ #align pgame.relabel SetTheory.PGame.relabel @[simp] theorem relabel_moveLeft' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : xl') : moveLeft (relabel el er) i = x.moveLeft (el i) := rfl #align pgame.relabel_move_left' SetTheory.PGame.relabel_moveLeft' theorem relabel_moveLeft {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (i : x.LeftMoves) : moveLeft (relabel el er) (el.symm i) = x.moveLeft i := by simp #align pgame.relabel_move_left SetTheory.PGame.relabel_moveLeft @[simp] theorem relabel_moveRight' {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : xr') : moveRight (relabel el er) j = x.moveRight (er j) := rfl #align pgame.relabel_move_right' SetTheory.PGame.relabel_moveRight'
Mathlib/SetTheory/Game/PGame.lean
1,231
1,232
theorem relabel_moveRight {x : PGame} {xl' xr'} (el : xl' ≃ x.LeftMoves) (er : xr' ≃ x.RightMoves) (j : x.RightMoves) : moveRight (relabel el er) (er.symm j) = x.moveRight j := by
simp
/- Copyright (c) 2021 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp -/ import Mathlib.Analysis.Convex.Cone.Basic import Mathlib.Analysis.InnerProductSpace.Projection #align_import analysis.convex.cone.dual from "leanprover-community/mathlib"@"915591b2bb3ea303648db07284a161a7f2a9e3d4" /-! # Convex cones in inner product spaces We define `Set.innerDualCone` to be the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. ## Main statements We prove the following theorems: * `ConvexCone.innerDualCone_of_innerDualCone_eq_self`: The `innerDualCone` of the `innerDualCone` of a nonempty, closed, convex cone is itself. * `ConvexCone.hyperplane_separation_of_nonempty_of_isClosed_of_nmem`: This variant of the [hyperplane separation theorem](https://en.wikipedia.org/wiki/Hyperplane_separation_theorem) states that given a nonempty, closed, convex cone `K` in a complete, real inner product space `H` and a point `b` disjoint from it, there is a vector `y` which separates `b` from `K` in the sense that for all points `x` in `K`, `0 ≤ ⟪x, y⟫_ℝ` and `⟪y, b⟫_ℝ < 0`. This is also a geometric interpretation of the [Farkas lemma](https://en.wikipedia.org/wiki/Farkas%27_lemma#Geometric_interpretation). -/ open Set LinearMap open scoped Classical open Pointwise variable {𝕜 E F G : Type*} /-! ### The dual cone -/ section Dual variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] (s t : Set H) open RealInnerProductSpace /-- The dual cone is the cone consisting of all points `y` such that for all points `x` in a given set `0 ≤ ⟪ x, y ⟫`. -/ def Set.innerDualCone (s : Set H) : ConvexCone ℝ H where carrier := { y | ∀ x ∈ s, 0 ≤ ⟪x, y⟫ } smul_mem' c hc y hy x hx := by rw [real_inner_smul_right] exact mul_nonneg hc.le (hy x hx) add_mem' u hu v hv x hx := by rw [inner_add_right] exact add_nonneg (hu x hx) (hv x hx) #align set.inner_dual_cone Set.innerDualCone @[simp] theorem mem_innerDualCone (y : H) (s : Set H) : y ∈ s.innerDualCone ↔ ∀ x ∈ s, 0 ≤ ⟪x, y⟫ := Iff.rfl #align mem_inner_dual_cone mem_innerDualCone @[simp] theorem innerDualCone_empty : (∅ : Set H).innerDualCone = ⊤ := eq_top_iff.mpr fun _ _ _ => False.elim #align inner_dual_cone_empty innerDualCone_empty /-- Dual cone of the convex cone {0} is the total space. -/ @[simp] theorem innerDualCone_zero : (0 : Set H).innerDualCone = ⊤ := eq_top_iff.mpr fun _ _ y (hy : y = 0) => hy.symm ▸ (inner_zero_left _).ge #align inner_dual_cone_zero innerDualCone_zero /-- Dual cone of the total space is the convex cone {0}. -/ @[simp] theorem innerDualCone_univ : (univ : Set H).innerDualCone = 0 := by suffices ∀ x : H, x ∈ (univ : Set H).innerDualCone → x = 0 by apply SetLike.coe_injective exact eq_singleton_iff_unique_mem.mpr ⟨fun x _ => (inner_zero_right _).ge, this⟩ exact fun x hx => by simpa [← real_inner_self_nonpos] using hx (-x) (mem_univ _) #align inner_dual_cone_univ innerDualCone_univ theorem innerDualCone_le_innerDualCone (h : t ⊆ s) : s.innerDualCone ≤ t.innerDualCone := fun _ hy x hx => hy x (h hx) #align inner_dual_cone_le_inner_dual_cone innerDualCone_le_innerDualCone theorem pointed_innerDualCone : s.innerDualCone.Pointed := fun x _ => by rw [inner_zero_right] #align pointed_inner_dual_cone pointed_innerDualCone /-- The inner dual cone of a singleton is given by the preimage of the positive cone under the linear map `fun y ↦ ⟪x, y⟫`. -/ theorem innerDualCone_singleton (x : H) : ({x} : Set H).innerDualCone = (ConvexCone.positive ℝ ℝ).comap (innerₛₗ ℝ x) := ConvexCone.ext fun _ => forall_eq #align inner_dual_cone_singleton innerDualCone_singleton theorem innerDualCone_union (s t : Set H) : (s ∪ t).innerDualCone = s.innerDualCone ⊓ t.innerDualCone := le_antisymm (le_inf (fun _ hx _ hy => hx _ <| Or.inl hy) fun _ hx _ hy => hx _ <| Or.inr hy) fun _ hx _ => Or.rec (hx.1 _) (hx.2 _) #align inner_dual_cone_union innerDualCone_union
Mathlib/Analysis/Convex/Cone/InnerDual.lean
105
107
theorem innerDualCone_insert (x : H) (s : Set H) : (insert x s).innerDualCone = Set.innerDualCone {x} ⊓ s.innerDualCone := by
rw [insert_eq, innerDualCone_union]
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä -/ import Mathlib.Analysis.RCLike.Basic import Mathlib.Analysis.NormedSpace.OperatorNorm.Basic import Mathlib.Analysis.NormedSpace.Pointwise #align_import analysis.normed_space.is_R_or_C from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Normed spaces over R or C This file is about results on normed spaces over the fields `ℝ` and `ℂ`. ## Main definitions None. ## Main theorems * `ContinuousLinearMap.opNorm_bound_of_ball_bound`: A bound on the norms of values of a linear map in a ball yields a bound on the operator norm. ## Notes This file exists mainly to avoid importing `RCLike` in the main normed space theory files. -/ open Metric variable {𝕜 : Type*} [RCLike 𝕜] {E : Type*} [NormedAddCommGroup E] theorem RCLike.norm_coe_norm {z : E} : ‖(‖z‖ : 𝕜)‖ = ‖z‖ := by simp #align is_R_or_C.norm_coe_norm RCLike.norm_coe_norm variable [NormedSpace 𝕜 E] /-- Lemma to normalize a vector in a normed space `E` over either `ℂ` or `ℝ` to unit length. -/ @[simp] theorem norm_smul_inv_norm {x : E} (hx : x ≠ 0) : ‖(‖x‖⁻¹ : 𝕜) • x‖ = 1 := by have : ‖x‖ ≠ 0 := by simp [hx] field_simp [norm_smul] #align norm_smul_inv_norm norm_smul_inv_norm /-- Lemma to normalize a vector in a normed space `E` over either `ℂ` or `ℝ` to length `r`. -/
Mathlib/Analysis/NormedSpace/RCLike.lean
49
52
theorem norm_smul_inv_norm' {r : ℝ} (r_nonneg : 0 ≤ r) {x : E} (hx : x ≠ 0) : ‖((r : 𝕜) * (‖x‖ : 𝕜)⁻¹) • x‖ = r := by
have : ‖x‖ ≠ 0 := by simp [hx] field_simp [norm_smul, r_nonneg, rclike_simps]
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Mario Carneiro, Sean Leather -/ import Mathlib.Data.Finset.Card #align_import data.finset.option from "leanprover-community/mathlib"@"c227d107bbada5d0d9d20287e3282c0a7f1651a0" /-! # Finite sets in `Option α` In this file we define * `Option.toFinset`: construct an empty or singleton `Finset α` from an `Option α`; * `Finset.insertNone`: given `s : Finset α`, lift it to a finset on `Option α` using `Option.some` and then insert `Option.none`; * `Finset.eraseNone`: given `s : Finset (Option α)`, returns `t : Finset α` such that `x ∈ t ↔ some x ∈ s`. Then we prove some basic lemmas about these definitions. ## Tags finset, option -/ variable {α β : Type*} open Function namespace Option /-- Construct an empty or singleton finset from an `Option` -/ def toFinset (o : Option α) : Finset α := o.elim ∅ singleton #align option.to_finset Option.toFinset @[simp] theorem toFinset_none : none.toFinset = (∅ : Finset α) := rfl #align option.to_finset_none Option.toFinset_none @[simp] theorem toFinset_some {a : α} : (some a).toFinset = {a} := rfl #align option.to_finset_some Option.toFinset_some @[simp] theorem mem_toFinset {a : α} {o : Option α} : a ∈ o.toFinset ↔ a ∈ o := by cases o <;> simp [eq_comm] #align option.mem_to_finset Option.mem_toFinset theorem card_toFinset (o : Option α) : o.toFinset.card = o.elim 0 1 := by cases o <;> rfl #align option.card_to_finset Option.card_toFinset end Option namespace Finset /-- Given a finset on `α`, lift it to being a finset on `Option α` using `Option.some` and then insert `Option.none`. -/ def insertNone : Finset α ↪o Finset (Option α) := (OrderEmbedding.ofMapLEIff fun s => cons none (s.map Embedding.some) <| by simp) fun s t => by rw [le_iff_subset, cons_subset_cons, map_subset_map, le_iff_subset] #align finset.insert_none Finset.insertNone @[simp] theorem mem_insertNone {s : Finset α} : ∀ {o : Option α}, o ∈ insertNone s ↔ ∀ a ∈ o, a ∈ s | none => iff_of_true (Multiset.mem_cons_self _ _) fun a h => by cases h | some a => Multiset.mem_cons.trans <| by simp #align finset.mem_insert_none Finset.mem_insertNone lemma forall_mem_insertNone {s : Finset α} {p : Option α → Prop} : (∀ a ∈ insertNone s, p a) ↔ p none ∧ ∀ a ∈ s, p a := by simp [Option.forall] theorem some_mem_insertNone {s : Finset α} {a : α} : some a ∈ insertNone s ↔ a ∈ s := by simp #align finset.some_mem_insert_none Finset.some_mem_insertNone lemma none_mem_insertNone {s : Finset α} : none ∈ insertNone s := by simp @[aesop safe apply (rule_sets := [finsetNonempty])] lemma insertNone_nonempty {s : Finset α} : insertNone s |>.Nonempty := ⟨none, none_mem_insertNone⟩ @[simp] theorem card_insertNone (s : Finset α) : s.insertNone.card = s.card + 1 := by simp [insertNone] #align finset.card_insert_none Finset.card_insertNone /-- Given `s : Finset (Option α)`, `eraseNone s : Finset α` is the set of `x : α` such that `some x ∈ s`. -/ def eraseNone : Finset (Option α) →o Finset α := (Finset.mapEmbedding (Equiv.optionIsSomeEquiv α).toEmbedding).toOrderHom.comp ⟨Finset.subtype _, subtype_mono⟩ #align finset.erase_none Finset.eraseNone @[simp] theorem mem_eraseNone {s : Finset (Option α)} {x : α} : x ∈ eraseNone s ↔ some x ∈ s := by simp [eraseNone] #align finset.mem_erase_none Finset.mem_eraseNone lemma forall_mem_eraseNone {s : Finset (Option α)} {p : Option α → Prop} : (∀ a ∈ eraseNone s, p a) ↔ ∀ a : α, (a : Option α) ∈ s → p a := by simp [Option.forall] theorem eraseNone_eq_biUnion [DecidableEq α] (s : Finset (Option α)) : eraseNone s = s.biUnion Option.toFinset := by ext simp #align finset.erase_none_eq_bUnion Finset.eraseNone_eq_biUnion @[simp] theorem eraseNone_map_some (s : Finset α) : eraseNone (s.map Embedding.some) = s := by ext simp #align finset.erase_none_map_some Finset.eraseNone_map_some @[simp]
Mathlib/Data/Finset/Option.lean
118
119
theorem eraseNone_image_some [DecidableEq (Option α)] (s : Finset α) : eraseNone (s.image some) = s := by
simpa only [map_eq_image] using eraseNone_map_some s
/- Copyright (c) 2021 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying, Rémy Degenne -/ import Mathlib.Probability.Process.Adapted import Mathlib.MeasureTheory.Constructions.BorelSpace.Order #align_import probability.process.stopping from "leanprover-community/mathlib"@"ba074af83b6cf54c3104e59402b39410ddbd6dca" /-! # Stopping times, stopped processes and stopped values Definition and properties of stopping times. ## Main definitions * `MeasureTheory.IsStoppingTime`: a stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is `f i`-measurable * `MeasureTheory.IsStoppingTime.measurableSpace`: the σ-algebra associated with a stopping time ## Main results * `ProgMeasurable.stoppedProcess`: the stopped process of a progressively measurable process is progressively measurable. * `memℒp_stoppedProcess`: if a process belongs to `ℒp` at every time in `ℕ`, then its stopped process belongs to `ℒp` as well. ## Tags stopping time, stochastic process -/ open Filter Order TopologicalSpace open scoped Classical MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} /-! ### Stopping times -/ /-- A stopping time with respect to some filtration `f` is a function `τ` such that for all `i`, the preimage of `{j | j ≤ i}` along `τ` is measurable with respect to `f i`. Intuitively, the stopping time `τ` describes some stopping rule such that at time `i`, we may determine it with the information we have at time `i`. -/ def IsStoppingTime [Preorder ι] (f : Filtration ι m) (τ : Ω → ι) := ∀ i : ι, MeasurableSet[f i] <| {ω | τ ω ≤ i} #align measure_theory.is_stopping_time MeasureTheory.IsStoppingTime theorem isStoppingTime_const [Preorder ι] (f : Filtration ι m) (i : ι) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.const] #align measure_theory.is_stopping_time_const MeasureTheory.isStoppingTime_const section MeasurableSet section Preorder variable [Preorder ι] {f : Filtration ι m} {τ : Ω → ι} protected theorem IsStoppingTime.measurableSet_le (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω ≤ i} := hτ i #align measure_theory.is_stopping_time.measurable_set_le MeasureTheory.IsStoppingTime.measurableSet_le theorem IsStoppingTime.measurableSet_lt_of_pred [PredOrder ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω : Ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] rw [isMin_iff_forall_not_lt] at hi_min exact hi_min (τ ω) have : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iic (pred i) := by ext; simp [Iic_pred_of_not_isMin hi_min] rw [this] exact f.mono (pred_le i) _ (hτ.measurableSet_le <| pred i) #align measure_theory.is_stopping_time.measurable_set_lt_of_pred MeasureTheory.IsStoppingTime.measurableSet_lt_of_pred end Preorder section CountableStoppingTime namespace IsStoppingTime variable [PartialOrder ι] {τ : Ω → ι} {f : Filtration ι m} protected theorem measurableSet_eq_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} \ ⋃ (j ∈ Set.range τ) (_ : j < i), {ω | τ ω ≤ j} := by ext1 a simp only [Set.mem_setOf_eq, Set.mem_range, Set.iUnion_exists, Set.iUnion_iUnion_eq', Set.mem_diff, Set.mem_iUnion, exists_prop, not_exists, not_and, not_le] constructor <;> intro h · simp only [h, lt_iff_le_not_le, le_refl, and_imp, imp_self, imp_true_iff, and_self_iff] · exact h.1.eq_or_lt.resolve_right fun h_lt => h.2 a h_lt le_rfl rw [this] refine (hτ.measurableSet_le i).diff ?_ refine MeasurableSet.biUnion h_countable fun j _ => ?_ rw [Set.iUnion_eq_if] split_ifs with hji · exact f.mono hji.le _ (hτ.measurableSet_le j) · exact @MeasurableSet.empty _ (f i) #align measure_theory.is_stopping_time.measurable_set_eq_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable_range protected theorem measurableSet_eq_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable protected theorem measurableSet_lt_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω; simp [lt_iff_le_and_ne] rw [this] exact (hτ.measurableSet_le i).diff (hτ.measurableSet_eq_of_countable_range h_countable i) #align measure_theory.is_stopping_time.measurable_set_lt_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable_range protected theorem measurableSet_lt_of_countable [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_lt_of_countable MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable protected theorem measurableSet_ge_of_countable_range {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt_of_countable_range h_countable i).compl #align measure_theory.is_stopping_time.measurable_set_ge_of_countable_range MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable_range protected theorem measurableSet_ge_of_countable {ι} [LinearOrder ι] {τ : Ω → ι} {f : Filtration ι m} [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_ge_of_countable MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable end IsStoppingTime end CountableStoppingTime section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} theorem IsStoppingTime.measurableSet_gt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i < τ ω} := by have : {ω | i < τ ω} = {ω | τ ω ≤ i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_le] rw [this] exact (hτ.measurableSet_le i).compl #align measure_theory.is_stopping_time.measurable_set_gt MeasureTheory.IsStoppingTime.measurableSet_gt section TopologicalSpace variable [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] /-- Auxiliary lemma for `MeasureTheory.IsStoppingTime.measurableSet_lt`. -/ theorem IsStoppingTime.measurableSet_lt_of_isLUB (hτ : IsStoppingTime f τ) (i : ι) (h_lub : IsLUB (Set.Iio i) i) : MeasurableSet[f i] {ω | τ ω < i} := by by_cases hi_min : IsMin i · suffices {ω | τ ω < i} = ∅ by rw [this]; exact @MeasurableSet.empty _ (f i) ext1 ω simp only [Set.mem_setOf_eq, Set.mem_empty_iff_false, iff_false_iff] exact isMin_iff_forall_not_lt.mp hi_min (τ ω) obtain ⟨seq, -, -, h_tendsto, h_bound⟩ : ∃ seq : ℕ → ι, Monotone seq ∧ (∀ j, seq j ≤ i) ∧ Tendsto seq atTop (𝓝 i) ∧ ∀ j, seq j < i := h_lub.exists_seq_monotone_tendsto (not_isMin_iff.mp hi_min) have h_Ioi_eq_Union : Set.Iio i = ⋃ j, {k | k ≤ seq j} := by ext1 k simp only [Set.mem_Iio, Set.mem_iUnion, Set.mem_setOf_eq] refine ⟨fun hk_lt_i => ?_, fun h_exists_k_le_seq => ?_⟩ · rw [tendsto_atTop'] at h_tendsto have h_nhds : Set.Ici k ∈ 𝓝 i := mem_nhds_iff.mpr ⟨Set.Ioi k, Set.Ioi_subset_Ici le_rfl, isOpen_Ioi, hk_lt_i⟩ obtain ⟨a, ha⟩ : ∃ a : ℕ, ∀ b : ℕ, b ≥ a → k ≤ seq b := h_tendsto (Set.Ici k) h_nhds exact ⟨a, ha a le_rfl⟩ · obtain ⟨j, hk_seq_j⟩ := h_exists_k_le_seq exact hk_seq_j.trans_lt (h_bound j) have h_lt_eq_preimage : {ω | τ ω < i} = τ ⁻¹' Set.Iio i := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_preimage, Set.mem_Iio] rw [h_lt_eq_preimage, h_Ioi_eq_Union] simp only [Set.preimage_iUnion, Set.preimage_setOf_eq] exact MeasurableSet.iUnion fun n => f.mono (h_bound n).le _ (hτ.measurableSet_le (seq n)) #align measure_theory.is_stopping_time.measurable_set_lt_of_is_lub MeasureTheory.IsStoppingTime.measurableSet_lt_of_isLUB theorem IsStoppingTime.measurableSet_lt (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω < i} := by obtain ⟨i', hi'_lub⟩ : ∃ i', IsLUB (Set.Iio i) i' := exists_lub_Iio i cases' lub_Iio_eq_self_or_Iio_eq_Iic i hi'_lub with hi'_eq_i h_Iio_eq_Iic · rw [← hi'_eq_i] at hi'_lub ⊢ exact hτ.measurableSet_lt_of_isLUB i' hi'_lub · have h_lt_eq_preimage : {ω : Ω | τ ω < i} = τ ⁻¹' Set.Iio i := rfl rw [h_lt_eq_preimage, h_Iio_eq_Iic] exact f.mono (lub_Iio_le i hi'_lub) _ (hτ.measurableSet_le i') #align measure_theory.is_stopping_time.measurable_set_lt MeasureTheory.IsStoppingTime.measurableSet_lt theorem IsStoppingTime.measurableSet_ge (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω < i}ᶜ := by ext1 ω; simp only [Set.mem_setOf_eq, Set.mem_compl_iff, not_lt] rw [this] exact (hτ.measurableSet_lt i).compl #align measure_theory.is_stopping_time.measurable_set_ge MeasureTheory.IsStoppingTime.measurableSet_ge theorem IsStoppingTime.measurableSet_eq (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[f i] {ω | τ ω = i} := by have : {ω | τ ω = i} = {ω | τ ω ≤ i} ∩ {ω | τ ω ≥ i} := by ext1 ω; simp only [Set.mem_setOf_eq, ge_iff_le, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hτ.measurableSet_le i).inter (hτ.measurableSet_ge i) #align measure_theory.is_stopping_time.measurable_set_eq MeasureTheory.IsStoppingTime.measurableSet_eq theorem IsStoppingTime.measurableSet_eq_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω = i} := f.mono hle _ <| hτ.measurableSet_eq i #align measure_theory.is_stopping_time.measurable_set_eq_le MeasureTheory.IsStoppingTime.measurableSet_eq_le theorem IsStoppingTime.measurableSet_lt_le (hτ : IsStoppingTime f τ) {i j : ι} (hle : i ≤ j) : MeasurableSet[f j] {ω | τ ω < i} := f.mono hle _ <| hτ.measurableSet_lt i #align measure_theory.is_stopping_time.measurable_set_lt_le MeasureTheory.IsStoppingTime.measurableSet_lt_le end TopologicalSpace end LinearOrder section Countable theorem isStoppingTime_of_measurableSet_eq [Preorder ι] [Countable ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : ∀ i, MeasurableSet[f i] {ω | τ ω = i}) : IsStoppingTime f τ := by intro i rw [show {ω | τ ω ≤ i} = ⋃ k ≤ i, {ω | τ ω = k} by ext; simp] refine MeasurableSet.biUnion (Set.to_countable _) fun k hk => ?_ exact f.mono hk _ (hτ k) #align measure_theory.is_stopping_time_of_measurable_set_eq MeasureTheory.isStoppingTime_of_measurableSet_eq end Countable end MeasurableSet namespace IsStoppingTime protected theorem max [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => max (τ ω) (π ω) := by intro i simp_rw [max_le_iff, Set.setOf_and] exact (hτ i).inter (hπ i) #align measure_theory.is_stopping_time.max MeasureTheory.IsStoppingTime.max protected theorem max_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => max (τ ω) i := hτ.max (isStoppingTime_const f i) #align measure_theory.is_stopping_time.max_const MeasureTheory.IsStoppingTime.max_const protected theorem min [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f fun ω => min (τ ω) (π ω) := by intro i simp_rw [min_le_iff, Set.setOf_or] exact (hτ i).union (hπ i) #align measure_theory.is_stopping_time.min MeasureTheory.IsStoppingTime.min protected theorem min_const [LinearOrder ι] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) (i : ι) : IsStoppingTime f fun ω => min (τ ω) i := hτ.min (isStoppingTime_const f i) #align measure_theory.is_stopping_time.min_const MeasureTheory.IsStoppingTime.min_const theorem add_const [AddGroup ι] [Preorder ι] [CovariantClass ι ι (Function.swap (· + ·)) (· ≤ ·)] [CovariantClass ι ι (· + ·) (· ≤ ·)] {f : Filtration ι m} {τ : Ω → ι} (hτ : IsStoppingTime f τ) {i : ι} (hi : 0 ≤ i) : IsStoppingTime f fun ω => τ ω + i := by intro j simp_rw [← le_sub_iff_add_le] exact f.mono (sub_le_self j hi) _ (hτ (j - i)) #align measure_theory.is_stopping_time.add_const MeasureTheory.IsStoppingTime.add_const theorem add_const_nat {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) {i : ℕ} : IsStoppingTime f fun ω => τ ω + i := by refine isStoppingTime_of_measurableSet_eq fun j => ?_ by_cases hij : i ≤ j · simp_rw [eq_comm, ← Nat.sub_eq_iff_eq_add hij, eq_comm] exact f.mono (j.sub_le i) _ (hτ.measurableSet_eq (j - i)) · rw [not_le] at hij convert @MeasurableSet.empty _ (f.1 j) ext ω simp only [Set.mem_empty_iff_false, iff_false_iff, Set.mem_setOf] omega #align measure_theory.is_stopping_time.add_const_nat MeasureTheory.IsStoppingTime.add_const_nat -- generalize to certain countable type? theorem add {f : Filtration ℕ m} {τ π : Ω → ℕ} (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : IsStoppingTime f (τ + π) := by intro i rw [(_ : {ω | (τ + π) ω ≤ i} = ⋃ k ≤ i, {ω | π ω = k} ∩ {ω | τ ω + k ≤ i})] · exact MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun hk => (hπ.measurableSet_eq_le hk).inter (hτ.add_const_nat i) ext ω simp only [Pi.add_apply, Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_prop] refine ⟨fun h => ⟨π ω, by omega, rfl, h⟩, ?_⟩ rintro ⟨j, hj, rfl, h⟩ assumption #align measure_theory.is_stopping_time.add MeasureTheory.IsStoppingTime.add section Preorder variable [Preorder ι] {f : Filtration ι m} {τ π : Ω → ι} /-- The associated σ-algebra with a stopping time. -/ protected def measurableSpace (hτ : IsStoppingTime f τ) : MeasurableSpace Ω where MeasurableSet' s := ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) measurableSet_empty i := (Set.empty_inter {ω | τ ω ≤ i}).symm ▸ @MeasurableSet.empty _ (f i) measurableSet_compl s hs i := by rw [(_ : sᶜ ∩ {ω | τ ω ≤ i} = (sᶜ ∪ {ω | τ ω ≤ i}ᶜ) ∩ {ω | τ ω ≤ i})] · refine MeasurableSet.inter ?_ ?_ · rw [← Set.compl_inter] exact (hs i).compl · exact hτ i · rw [Set.union_inter_distrib_right] simp only [Set.compl_inter_self, Set.union_empty] measurableSet_iUnion s hs i := by rw [forall_swap] at hs rw [Set.iUnion_inter] exact MeasurableSet.iUnion (hs i) #align measure_theory.is_stopping_time.measurable_space MeasureTheory.IsStoppingTime.measurableSpace protected theorem measurableSet (hτ : IsStoppingTime f τ) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] s ↔ ∀ i : ι, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) := Iff.rfl #align measure_theory.is_stopping_time.measurable_set MeasureTheory.IsStoppingTime.measurableSet theorem measurableSpace_mono (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (hle : τ ≤ π) : hτ.measurableSpace ≤ hπ.measurableSpace := by intro s hs i rw [(_ : s ∩ {ω | π ω ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | π ω ≤ i})] · exact (hs i).inter (hπ i) · ext simp only [Set.mem_inter_iff, iff_self_and, and_congr_left_iff, Set.mem_setOf_eq] intro hle' _ exact le_trans (hle _) hle' #align measure_theory.is_stopping_time.measurable_space_mono MeasureTheory.IsStoppingTime.measurableSpace_mono theorem measurableSpace_le_of_countable [Countable ι] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.iUnion fun i => f.le i _ (hs i) · ext ω; constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, hx, le_rfl⟩ · rintro ⟨_, hx, _⟩ exact hx #align measure_theory.is_stopping_time.measurable_space_le_of_countable MeasureTheory.IsStoppingTime.measurableSpace_le_of_countable theorem measurableSpace_le' [IsCountablyGenerated (atTop : Filter ι)] [(atTop : Filter ι).NeBot] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs obtain ⟨seq : ℕ → ι, h_seq_tendsto⟩ := (atTop : Filter ι).exists_seq_tendsto rw [(_ : s = ⋃ n, s ∩ {ω | τ ω ≤ seq n})] · exact MeasurableSet.iUnion fun i => f.le (seq i) _ (hs (seq i)) · ext ω; constructor <;> rw [Set.mem_iUnion] · intro hx suffices ∃ i, τ ω ≤ seq i from ⟨this.choose, hx, this.choose_spec⟩ rw [tendsto_atTop] at h_seq_tendsto exact (h_seq_tendsto (τ ω)).exists · rintro ⟨_, hx, _⟩ exact hx #align measure_theory.is_stopping_time.measurable_space_le' MeasureTheory.IsStoppingTime.measurableSpace_le' theorem measurableSpace_le {ι} [SemilatticeSup ι] {f : Filtration ι m} {τ : Ω → ι} [IsCountablyGenerated (atTop : Filter ι)] (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := by cases isEmpty_or_nonempty ι · haveI : IsEmpty Ω := ⟨fun ω => IsEmpty.false (τ ω)⟩ intro s _ suffices hs : s = ∅ by rw [hs]; exact MeasurableSet.empty haveI : Unique (Set Ω) := Set.uniqueEmpty rw [Unique.eq_default s, Unique.eq_default ∅] exact measurableSpace_le' hτ #align measure_theory.is_stopping_time.measurable_space_le MeasureTheory.IsStoppingTime.measurableSpace_le example {f : Filtration ℕ m} {τ : Ω → ℕ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le example {f : Filtration ℝ m} {τ : Ω → ℝ} (hτ : IsStoppingTime f τ) : hτ.measurableSpace ≤ m := hτ.measurableSpace_le @[simp] theorem measurableSpace_const (f : Filtration ι m) (i : ι) : (isStoppingTime_const f i).measurableSpace = f i := by ext1 s change MeasurableSet[(isStoppingTime_const f i).measurableSpace] s ↔ MeasurableSet[f i] s rw [IsStoppingTime.measurableSet] constructor <;> intro h · specialize h i simpa only [le_refl, Set.setOf_true, Set.inter_univ] using h · intro j by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · simp only [hij, Set.setOf_false, Set.inter_empty, @MeasurableSet.empty _ (f.1 j)] #align measure_theory.is_stopping_time.measurable_space_const MeasureTheory.IsStoppingTime.measurableSpace_const theorem measurableSet_inter_eq_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω = i}) ↔ MeasurableSet[f i] (s ∩ {ω | τ ω = i}) := by have : ∀ j, {ω : Ω | τ ω = i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω = i} ∩ {_ω | i ≤ j} := by intro j ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] intro hxi rw [hxi] constructor <;> intro h · specialize h i simpa only [Set.inter_assoc, this, le_refl, Set.setOf_true, Set.inter_univ] using h · intro j rw [Set.inter_assoc, this] by_cases hij : i ≤ j · simp only [hij, Set.setOf_true, Set.inter_univ] exact f.mono hij _ h · set_option tactic.skipAssignedInstances false in simp [hij] convert @MeasurableSet.empty _ (Filtration.seq f j) #align measure_theory.is_stopping_time.measurable_set_inter_eq_iff MeasureTheory.IsStoppingTime.measurableSet_inter_eq_iff theorem measurableSpace_le_of_le_const (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : hτ.measurableSpace ≤ f i := (measurableSpace_mono hτ _ hτ_le).trans (measurableSpace_const _ _).le #align measure_theory.is_stopping_time.measurable_space_le_of_le_const MeasureTheory.IsStoppingTime.measurableSpace_le_of_le_const theorem measurableSpace_le_of_le (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : hτ.measurableSpace ≤ m := (hτ.measurableSpace_le_of_le_const hτ_le).trans (f.le n) #align measure_theory.is_stopping_time.measurable_space_le_of_le MeasureTheory.IsStoppingTime.measurableSpace_le_of_le theorem le_measurableSpace_of_const_le (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, i ≤ τ ω) : f i ≤ hτ.measurableSpace := (measurableSpace_const _ _).symm.le.trans (measurableSpace_mono _ hτ hτ_le) #align measure_theory.is_stopping_time.le_measurable_space_of_const_le MeasureTheory.IsStoppingTime.le_measurableSpace_of_const_le end Preorder instance sigmaFinite_stopping_time {ι} [SemilatticeSup ι] [OrderBot ι] [(Filter.atTop : Filter ι).IsCountablyGenerated] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) : SigmaFinite (μ.trim hτ.measurableSpace_le) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance #align measure_theory.is_stopping_time.sigma_finite_stopping_time MeasureTheory.IsStoppingTime.sigmaFinite_stopping_time instance sigmaFinite_stopping_time_of_le {ι} [SemilatticeSup ι] [OrderBot ι] {μ : Measure Ω} {f : Filtration ι m} {τ : Ω → ι} [SigmaFiniteFiltration μ f] (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : SigmaFinite (μ.trim (hτ.measurableSpace_le_of_le hτ_le)) := by refine @sigmaFiniteTrim_mono _ _ ?_ _ _ _ ?_ ?_ · exact f ⊥ · exact hτ.le_measurableSpace_of_const_le fun _ => bot_le · infer_instance #align measure_theory.is_stopping_time.sigma_finite_stopping_time_of_le MeasureTheory.IsStoppingTime.sigmaFinite_stopping_time_of_le section LinearOrder variable [LinearOrder ι] {f : Filtration ι m} {τ π : Ω → ι} protected theorem measurableSet_le' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ i} := by intro j have : {ω : Ω | τ ω ≤ i} ∩ {ω : Ω | τ ω ≤ j} = {ω : Ω | τ ω ≤ min i j} := by ext1 ω; simp only [Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff] rw [this] exact f.mono (min_le_right i j) _ (hτ _) #align measure_theory.is_stopping_time.measurable_set_le' MeasureTheory.IsStoppingTime.measurableSet_le' protected theorem measurableSet_gt' (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i < τ ω} := by have : {ω : Ω | i < τ ω} = {ω : Ω | τ ω ≤ i}ᶜ := by ext1 ω; simp rw [this] exact (hτ.measurableSet_le' i).compl #align measure_theory.is_stopping_time.measurable_set_gt' MeasureTheory.IsStoppingTime.measurableSet_gt' protected theorem measurableSet_eq' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq i #align measure_theory.is_stopping_time.measurable_set_eq' MeasureTheory.IsStoppingTime.measurableSet_eq' protected theorem measurableSet_ge' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq' i).union (hτ.measurableSet_gt' i) #align measure_theory.is_stopping_time.measurable_set_ge' MeasureTheory.IsStoppingTime.measurableSet_ge' protected theorem measurableSet_lt' [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq' i) #align measure_theory.is_stopping_time.measurable_set_lt' MeasureTheory.IsStoppingTime.measurableSet_lt' section Countable protected theorem measurableSet_eq_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := by rw [← Set.univ_inter {ω | τ ω = i}, measurableSet_inter_eq_iff, Set.univ_inter] exact hτ.measurableSet_eq_of_countable_range h_countable i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable_range' protected theorem measurableSet_eq_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = i} := hτ.measurableSet_eq_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_eq_of_countable' MeasureTheory.IsStoppingTime.measurableSet_eq_of_countable' protected theorem measurableSet_ge_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := by have : {ω | i ≤ τ ω} = {ω | τ ω = i} ∪ {ω | i < τ ω} := by ext1 ω simp only [le_iff_lt_or_eq, Set.mem_setOf_eq, Set.mem_union] rw [@eq_comm _ i, or_comm] rw [this] exact (hτ.measurableSet_eq_of_countable_range' h_countable i).union (hτ.measurableSet_gt' i) #align measure_theory.is_stopping_time.measurable_set_ge_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable_range' protected theorem measurableSet_ge_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | i ≤ τ ω} := hτ.measurableSet_ge_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_ge_of_countable' MeasureTheory.IsStoppingTime.measurableSet_ge_of_countable' protected theorem measurableSet_lt_of_countable_range' (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := by have : {ω | τ ω < i} = {ω | τ ω ≤ i} \ {ω | τ ω = i} := by ext1 ω simp only [lt_iff_le_and_ne, Set.mem_setOf_eq, Set.mem_diff] rw [this] exact (hτ.measurableSet_le' i).diff (hτ.measurableSet_eq_of_countable_range' h_countable i) #align measure_theory.is_stopping_time.measurable_set_lt_of_countable_range' MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable_range' protected theorem measurableSet_lt_of_countable' [Countable ι] (hτ : IsStoppingTime f τ) (i : ι) : MeasurableSet[hτ.measurableSpace] {ω | τ ω < i} := hτ.measurableSet_lt_of_countable_range' (Set.to_countable _) i #align measure_theory.is_stopping_time.measurable_set_lt_of_countable' MeasureTheory.IsStoppingTime.measurableSet_lt_of_countable' protected theorem measurableSpace_le_of_countable_range (hτ : IsStoppingTime f τ) (h_countable : (Set.range τ).Countable) : hτ.measurableSpace ≤ m := by intro s hs change ∀ i, MeasurableSet[f i] (s ∩ {ω | τ ω ≤ i}) at hs rw [(_ : s = ⋃ i ∈ Set.range τ, s ∩ {ω | τ ω ≤ i})] · exact MeasurableSet.biUnion h_countable fun i _ => f.le i _ (hs i) · ext ω constructor <;> rw [Set.mem_iUnion] · exact fun hx => ⟨τ ω, by simpa using hx⟩ · rintro ⟨i, hx⟩ simp only [Set.mem_range, Set.iUnion_exists, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_setOf_eq, exists_prop, exists_and_right] at hx exact hx.2.1 #align measure_theory.is_stopping_time.measurable_space_le_of_countable_range MeasureTheory.IsStoppingTime.measurableSpace_le_of_countable_range end Countable protected theorem measurable [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] τ := @measurable_of_Iic ι Ω _ _ _ hτ.measurableSpace _ _ _ _ fun i => hτ.measurableSet_le' i #align measure_theory.is_stopping_time.measurable MeasureTheory.IsStoppingTime.measurable protected theorem measurable_of_le [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) {i : ι} (hτ_le : ∀ ω, τ ω ≤ i) : Measurable[f i] τ := hτ.measurable.mono (measurableSpace_le_of_le_const _ hτ_le) le_rfl #align measure_theory.is_stopping_time.measurable_of_le MeasureTheory.IsStoppingTime.measurable_of_le theorem measurableSpace_min (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : (hτ.min hπ).measurableSpace = hτ.measurableSpace ⊓ hπ.measurableSpace := by refine le_antisymm ?_ ?_ · exact le_inf (measurableSpace_mono _ hτ fun _ => min_le_left _ _) (measurableSpace_mono _ hπ fun _ => min_le_right _ _) · intro s change MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s → MeasurableSet[(hτ.min hπ).measurableSpace] s simp_rw [IsStoppingTime.measurableSet] have : ∀ i, {ω | min (τ ω) (π ω) ≤ i} = {ω | τ ω ≤ i} ∪ {ω | π ω ≤ i} := by intro i; ext1 ω; simp simp_rw [this, Set.inter_union_distrib_left] exact fun h i => (h.left i).union (h.right i) #align measure_theory.is_stopping_time.measurable_space_min MeasureTheory.IsStoppingTime.measurableSpace_min theorem measurableSet_min_iff (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[(hτ.min hπ).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[hπ.measurableSpace] s := by rw [measurableSpace_min hτ hπ]; rfl #align measure_theory.is_stopping_time.measurable_set_min_iff MeasureTheory.IsStoppingTime.measurableSet_min_iff theorem measurableSpace_min_const (hτ : IsStoppingTime f τ) {i : ι} : (hτ.min_const i).measurableSpace = hτ.measurableSpace ⊓ f i := by rw [hτ.measurableSpace_min (isStoppingTime_const _ i), measurableSpace_const] #align measure_theory.is_stopping_time.measurable_space_min_const MeasureTheory.IsStoppingTime.measurableSpace_min_const theorem measurableSet_min_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) {i : ι} : MeasurableSet[(hτ.min_const i).measurableSpace] s ↔ MeasurableSet[hτ.measurableSpace] s ∧ MeasurableSet[f i] s := by rw [measurableSpace_min_const hτ]; apply MeasurableSpace.measurableSet_inf #align measure_theory.is_stopping_time.measurable_set_min_const_iff MeasureTheory.IsStoppingTime.measurableSet_min_const_iff theorem measurableSet_inter_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) (hs : MeasurableSet[hτ.measurableSpace] s) : MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by simp_rw [IsStoppingTime.measurableSet] at hs ⊢ intro i have : s ∩ {ω | τ ω ≤ π ω} ∩ {ω | min (τ ω) (π ω) ≤ i} = s ∩ {ω | τ ω ≤ i} ∩ {ω | min (τ ω) (π ω) ≤ i} ∩ {ω | min (τ ω) i ≤ min (min (τ ω) (π ω)) i} := by ext1 ω simp only [min_le_iff, Set.mem_inter_iff, Set.mem_setOf_eq, le_min_iff, le_refl, true_and_iff, and_true_iff, true_or_iff, or_true_iff] by_cases hτi : τ ω ≤ i · simp only [hτi, true_or_iff, and_true_iff, and_congr_right_iff] intro constructor <;> intro h · exact Or.inl h · cases' h with h h · exact h · exact hτi.trans h simp only [hτi, false_or_iff, and_false_iff, false_and_iff, iff_false_iff, not_and, not_le, and_imp] refine fun _ hτ_le_π => lt_of_lt_of_le ?_ hτ_le_π rw [← not_le] exact hτi rw [this] refine ((hs i).inter ((hτ.min hπ) i)).inter ?_ apply @measurableSet_le _ _ _ _ _ (Filtration.seq f i) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const i).measurable_of_le fun _ => min_le_right _ _ · exact ((hτ.min hπ).min_const i).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_inter_le MeasureTheory.IsStoppingTime.measurableSet_inter_le theorem measurableSet_inter_le_iff [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) (s : Set Ω) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) ↔ MeasurableSet[(hτ.min hπ).measurableSpace] (s ∩ {ω | τ ω ≤ π ω}) := by constructor <;> intro h · have : s ∩ {ω | τ ω ≤ π ω} = s ∩ {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ π ω} := by rw [Set.inter_assoc, Set.inter_self] rw [this] exact measurableSet_inter_le _ hπ _ h · rw [measurableSet_min_iff hτ hπ] at h exact h.1 #align measure_theory.is_stopping_time.measurable_set_inter_le_iff MeasureTheory.IsStoppingTime.measurableSet_inter_le_iff theorem measurableSet_inter_le_const_iff (hτ : IsStoppingTime f τ) (s : Set Ω) (i : ι) : MeasurableSet[hτ.measurableSpace] (s ∩ {ω | τ ω ≤ i}) ↔ MeasurableSet[(hτ.min_const i).measurableSpace] (s ∩ {ω | τ ω ≤ i}) := by rw [IsStoppingTime.measurableSet_min_iff hτ (isStoppingTime_const _ i), IsStoppingTime.measurableSpace_const, IsStoppingTime.measurableSet] refine ⟨fun h => ⟨h, ?_⟩, fun h j => h.1 j⟩ specialize h i rwa [Set.inter_assoc, Set.inter_self] at h #align measure_theory.is_stopping_time.measurable_set_inter_le_const_iff MeasureTheory.IsStoppingTime.measurableSet_inter_le_const_iff theorem measurableSet_le_stopping_time [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω ≤ π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω ≤ π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j ≤ min (π ω) j} ∩ {ω | τ ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq, min_le_iff, le_min_iff, le_refl, and_true_iff, and_congr_left_iff] intro h simp only [h, or_self_iff, and_true_iff] rw [Iff.comm, or_iff_left_iff_imp] exact h.trans rw [this] refine MeasurableSet.inter ?_ (hτ.measurableSet_le j) apply @measurableSet_le _ _ _ _ _ (Filtration.seq f j) _ _ _ _ _ ?_ ?_ · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_le_stopping_time MeasureTheory.IsStoppingTime.measurableSet_le_stopping_time theorem measurableSet_stopping_time_le [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hπ.measurableSpace] {ω | τ ω ≤ π ω} := by suffices MeasurableSet[(hτ.min hπ).measurableSpace] {ω : Ω | τ ω ≤ π ω} by rw [measurableSet_min_iff hτ hπ] at this; exact this.2 rw [← Set.univ_inter {ω : Ω | τ ω ≤ π ω}, ← hτ.measurableSet_inter_le_iff hπ, Set.univ_inter] exact measurableSet_le_stopping_time hτ hπ #align measure_theory.is_stopping_time.measurable_set_stopping_time_le MeasureTheory.IsStoppingTime.measurableSet_stopping_time_le theorem measurableSet_eq_stopping_time [AddGroup ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] [MeasurableSub₂ ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · cases' h with h' hσ_le cases' h' with h_eq hτ_le rwa [min_eq_left hτ_le, min_eq_left hσ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_eq_stopping_time MeasureTheory.IsStoppingTime.measurableSet_eq_stopping_time theorem measurableSet_eq_stopping_time_of_countable [Countable ι] [TopologicalSpace ι] [MeasurableSpace ι] [BorelSpace ι] [OrderTopology ι] [MeasurableSingletonClass ι] [SecondCountableTopology ι] (hτ : IsStoppingTime f τ) (hπ : IsStoppingTime f π) : MeasurableSet[hτ.measurableSpace] {ω | τ ω = π ω} := by rw [hτ.measurableSet] intro j have : {ω | τ ω = π ω} ∩ {ω | τ ω ≤ j} = {ω | min (τ ω) j = min (π ω) j} ∩ {ω | τ ω ≤ j} ∩ {ω | π ω ≤ j} := by ext1 ω simp only [Set.mem_inter_iff, Set.mem_setOf_eq] refine ⟨fun h => ⟨⟨?_, h.2⟩, ?_⟩, fun h => ⟨?_, h.1.2⟩⟩ · rw [h.1] · rw [← h.1]; exact h.2 · cases' h with h' hπ_le cases' h' with h_eq hτ_le rwa [min_eq_left hτ_le, min_eq_left hπ_le] at h_eq rw [this] refine MeasurableSet.inter (MeasurableSet.inter ?_ (hτ.measurableSet_le j)) (hπ.measurableSet_le j) apply measurableSet_eq_fun_of_countable · exact (hτ.min_const j).measurable_of_le fun _ => min_le_right _ _ · exact (hπ.min_const j).measurable_of_le fun _ => min_le_right _ _ #align measure_theory.is_stopping_time.measurable_set_eq_stopping_time_of_countable MeasureTheory.IsStoppingTime.measurableSet_eq_stopping_time_of_countable end LinearOrder end IsStoppingTime section LinearOrder /-! ## Stopped value and stopped process -/ /-- Given a map `u : ι → Ω → E`, its stopped value with respect to the stopping time `τ` is the map `x ↦ u (τ ω) ω`. -/ def stoppedValue (u : ι → Ω → β) (τ : Ω → ι) : Ω → β := fun ω => u (τ ω) ω #align measure_theory.stopped_value MeasureTheory.stoppedValue theorem stoppedValue_const (u : ι → Ω → β) (i : ι) : (stoppedValue u fun _ => i) = u i := rfl #align measure_theory.stopped_value_const MeasureTheory.stoppedValue_const variable [LinearOrder ι] /-- Given a map `u : ι → Ω → E`, the stopped process with respect to `τ` is `u i ω` if `i ≤ τ ω`, and `u (τ ω) ω` otherwise. Intuitively, the stopped process stops evolving once the stopping time has occured. -/ def stoppedProcess (u : ι → Ω → β) (τ : Ω → ι) : ι → Ω → β := fun i ω => u (min i (τ ω)) ω #align measure_theory.stopped_process MeasureTheory.stoppedProcess theorem stoppedProcess_eq_stoppedValue {u : ι → Ω → β} {τ : Ω → ι} : stoppedProcess u τ = fun i => stoppedValue u fun ω => min i (τ ω) := rfl #align measure_theory.stopped_process_eq_stopped_value MeasureTheory.stoppedProcess_eq_stoppedValue theorem stoppedValue_stoppedProcess {u : ι → Ω → β} {τ σ : Ω → ι} : stoppedValue (stoppedProcess u τ) σ = stoppedValue u fun ω => min (σ ω) (τ ω) := rfl #align measure_theory.stopped_value_stopped_process MeasureTheory.stoppedValue_stoppedProcess theorem stoppedProcess_eq_of_le {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : i ≤ τ ω) : stoppedProcess u τ i ω = u i ω := by simp [stoppedProcess, min_eq_left h] #align measure_theory.stopped_process_eq_of_le MeasureTheory.stoppedProcess_eq_of_le theorem stoppedProcess_eq_of_ge {u : ι → Ω → β} {τ : Ω → ι} {i : ι} {ω : Ω} (h : τ ω ≤ i) : stoppedProcess u τ i ω = u (τ ω) ω := by simp [stoppedProcess, min_eq_right h] #align measure_theory.stopped_process_eq_of_ge MeasureTheory.stoppedProcess_eq_of_ge section ProgMeasurable variable [MeasurableSpace ι] [TopologicalSpace ι] [OrderTopology ι] [SecondCountableTopology ι] [BorelSpace ι] [TopologicalSpace β] {u : ι → Ω → β} {τ : Ω → ι} {f : Filtration ι m} theorem progMeasurable_min_stopping_time [MetrizableSpace ι] (hτ : IsStoppingTime f τ) : ProgMeasurable f fun i ω => min i (τ ω) := by intro i let m_prod : MeasurableSpace (Set.Iic i × Ω) := Subtype.instMeasurableSpace.prod (f i) let m_set : ∀ t : Set (Set.Iic i × Ω), MeasurableSpace t := fun _ => @Subtype.instMeasurableSpace (Set.Iic i × Ω) _ m_prod let s := {p : Set.Iic i × Ω | τ p.2 ≤ i} have hs : MeasurableSet[m_prod] s := @measurable_snd (Set.Iic i) Ω _ (f i) _ (hτ i) have h_meas_fst : ∀ t : Set (Set.Iic i × Ω), Measurable[m_set t] fun x : t => ((x : Set.Iic i × Ω).fst : ι) := fun t => (@measurable_subtype_coe (Set.Iic i × Ω) m_prod _).fst.subtype_val apply Measurable.stronglyMeasurable refine measurable_of_restrict_of_restrict_compl hs ?_ ?_ · refine @Measurable.min _ _ _ _ _ (m_set s) _ _ _ _ _ (h_meas_fst s) ?_ refine @measurable_of_Iic ι s _ _ _ (m_set s) _ _ _ _ fun j => ?_ have h_set_eq : (fun x : s => τ (x : Set.Iic i × Ω).snd) ⁻¹' Set.Iic j = (fun x : s => (x : Set.Iic i × Ω).snd) ⁻¹' {ω | τ ω ≤ min i j} := by ext1 ω simp only [Set.mem_preimage, Set.mem_Iic, iff_and_self, le_min_iff, Set.mem_setOf_eq] exact fun _ => ω.prop rw [h_set_eq] suffices h_meas : @Measurable _ _ (m_set s) (f i) fun x : s ↦ (x : Set.Iic i × Ω).snd from h_meas (f.mono (min_le_left _ _) _ (hτ.measurableSet_le (min i j))) exact measurable_snd.comp (@measurable_subtype_coe _ m_prod _) · letI sc := sᶜ suffices h_min_eq_left : (fun x : sc => min (↑(x : Set.Iic i × Ω).fst) (τ (x : Set.Iic i × Ω).snd)) = fun x : sc => ↑(x : Set.Iic i × Ω).fst by simp (config := { unfoldPartialApp := true }) only [Set.restrict, h_min_eq_left] exact h_meas_fst _ ext1 ω rw [min_eq_left] have hx_fst_le : ↑(ω : Set.Iic i × Ω).fst ≤ i := (ω : Set.Iic i × Ω).fst.prop refine hx_fst_le.trans (le_of_lt ?_) convert ω.prop simp only [sc, s, not_le, Set.mem_compl_iff, Set.mem_setOf_eq] #align measure_theory.prog_measurable_min_stopping_time MeasureTheory.progMeasurable_min_stopping_time theorem ProgMeasurable.stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : ProgMeasurable f (stoppedProcess u τ) := h.comp (progMeasurable_min_stopping_time hτ) fun _ _ => min_le_left _ _ #align measure_theory.prog_measurable.stopped_process MeasureTheory.ProgMeasurable.stoppedProcess theorem ProgMeasurable.adapted_stoppedProcess [MetrizableSpace ι] (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (h.stoppedProcess hτ).adapted #align measure_theory.prog_measurable.adapted_stopped_process MeasureTheory.ProgMeasurable.adapted_stoppedProcess theorem ProgMeasurable.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : ProgMeasurable f u) (hτ : IsStoppingTime f τ) (i : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ i) := (hu.adapted_stoppedProcess hτ i).mono (f.le _) #align measure_theory.prog_measurable.strongly_measurable_stopped_process MeasureTheory.ProgMeasurable.stronglyMeasurable_stoppedProcess theorem stronglyMeasurable_stoppedValue_of_le (h : ProgMeasurable f u) (hτ : IsStoppingTime f τ) {n : ι} (hτ_le : ∀ ω, τ ω ≤ n) : StronglyMeasurable[f n] (stoppedValue u τ) := by have : stoppedValue u τ = (fun p : Set.Iic n × Ω => u (↑p.fst) p.snd) ∘ fun ω => (⟨τ ω, hτ_le ω⟩, ω) := by ext1 ω; simp only [stoppedValue, Function.comp_apply, Subtype.coe_mk] rw [this] refine StronglyMeasurable.comp_measurable (h n) ?_ exact (hτ.measurable_of_le hτ_le).subtype_mk.prod_mk measurable_id #align measure_theory.strongly_measurable_stopped_value_of_le MeasureTheory.stronglyMeasurable_stoppedValue_of_le theorem measurable_stoppedValue [MetrizableSpace β] [MeasurableSpace β] [BorelSpace β] (hf_prog : ProgMeasurable f u) (hτ : IsStoppingTime f τ) : Measurable[hτ.measurableSpace] (stoppedValue u τ) := by have h_str_meas : ∀ i, StronglyMeasurable[f i] (stoppedValue u fun ω => min (τ ω) i) := fun i => stronglyMeasurable_stoppedValue_of_le hf_prog (hτ.min_const i) fun _ => min_le_right _ _ intro t ht i suffices stoppedValue u τ ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} = (stoppedValue u fun ω => min (τ ω) i) ⁻¹' t ∩ {ω : Ω | τ ω ≤ i} by rw [this]; exact ((h_str_meas i).measurable ht).inter (hτ.measurableSet_le i) ext1 ω simp only [stoppedValue, Set.mem_inter_iff, Set.mem_preimage, Set.mem_setOf_eq, and_congr_left_iff] intro h rw [min_eq_left h] #align measure_theory.measurable_stopped_value MeasureTheory.measurable_stoppedValue end ProgMeasurable end LinearOrder section StoppedValueOfMemFinset variable {μ : Measure Ω} {τ σ : Ω → ι} {E : Type*} {p : ℝ≥0∞} {u : ι → Ω → E} theorem stoppedValue_eq_of_mem_finset [AddCommMonoid E] {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : stoppedValue u τ = ∑ i ∈ s, Set.indicator {ω | τ ω = i} (u i) := by ext y rw [stoppedValue, Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] suffices Finset.filter (fun i => y ∈ {ω : Ω | τ ω = i}) s = ({τ y} : Finset ι) by rw [this, Finset.sum_singleton] ext1 ω simp only [Set.mem_setOf_eq, Finset.mem_filter, Finset.mem_singleton] constructor <;> intro h · exact h.2.symm · refine ⟨?_, h.symm⟩; rw [h]; exact hbdd y #align measure_theory.stopped_value_eq_of_mem_finset MeasureTheory.stoppedValue_eq_of_mem_finset theorem stoppedValue_eq' [Preorder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = ∑ i ∈ Finset.Iic N, Set.indicator {ω | τ ω = i} (u i) := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_Iic.mpr (hbdd ω) #align measure_theory.stopped_value_eq' MeasureTheory.stoppedValue_eq' theorem stoppedProcess_eq_of_mem_finset [LinearOrder ι] [AddCommMonoid E] {s : Finset ι} (n : ι) (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ s.filter (· < n), Set.indicator {ω | τ ω = i} (u i) := by ext ω rw [Pi.add_apply, Finset.sum_apply] rcases le_or_lt n (τ ω) with h | h · rw [stoppedProcess_eq_of_le h, Set.indicator_of_mem, Finset.sum_eq_zero, add_zero] · intro m hm refine Set.indicator_of_not_mem ?_ _ rw [Finset.mem_filter] at hm exact (hm.2.trans_le h).ne' · exact h · rw [stoppedProcess_eq_of_ge (le_of_lt h), Finset.sum_eq_single_of_mem (τ ω)] · rw [Set.indicator_of_not_mem, zero_add, Set.indicator_of_mem] <;> rw [Set.mem_setOf] exact not_le.2 h · rw [Finset.mem_filter] exact ⟨hbdd ω h, h⟩ · intro b _ hneq rw [Set.indicator_of_not_mem] rw [Set.mem_setOf] exact hneq.symm #align measure_theory.stopped_process_eq_of_mem_finset MeasureTheory.stoppedProcess_eq_of_mem_finset theorem stoppedProcess_eq'' [LinearOrder ι] [LocallyFiniteOrderBot ι] [AddCommMonoid E] (n : ι) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.Iio n, Set.indicator {ω | τ ω = i} (u i) := by have h_mem : ∀ ω, τ ω < n → τ ω ∈ Finset.Iio n := fun ω h => Finset.mem_Iio.mpr h rw [stoppedProcess_eq_of_mem_finset n h_mem] congr with i simp #align measure_theory.stopped_process_eq'' MeasureTheory.stoppedProcess_eq'' section StoppedValue variable [PartialOrder ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memℒp_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Memℒp (stoppedValue u τ) p μ := by rw [stoppedValue_eq_of_mem_finset hbdd] refine memℒp_finset_sum' _ fun i _ => Memℒp.indicator ?_ (hu i) refine ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq_of_countable_range ?_ i) refine ((Finset.finite_toSet s).subset fun ω hω => ?_).countable obtain ⟨y, rfl⟩ := hω exact hbdd y #align measure_theory.mem_ℒp_stopped_value_of_mem_finset MeasureTheory.memℒp_stoppedValue_of_mem_finset theorem memℒp_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Memℒp (stoppedValue u τ) p μ := memℒp_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) #align measure_theory.mem_ℒp_stopped_value MeasureTheory.memℒp_stoppedValue theorem integrable_stoppedValue_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {s : Finset ι} (hbdd : ∀ ω, τ ω ∈ s) : Integrable (stoppedValue u τ) μ := by simp_rw [← memℒp_one_iff_integrable] at hu ⊢ exact memℒp_stoppedValue_of_mem_finset hτ hu hbdd #align measure_theory.integrable_stopped_value_of_mem_finset MeasureTheory.integrable_stoppedValue_of_mem_finset variable (ι) theorem integrable_stoppedValue [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) {N : ι} (hbdd : ∀ ω, τ ω ≤ N) : Integrable (stoppedValue u τ) μ := integrable_stoppedValue_of_mem_finset hτ hu fun ω => Finset.mem_Iic.mpr (hbdd ω) #align measure_theory.integrable_stopped_value MeasureTheory.integrable_stoppedValue end StoppedValue section StoppedProcess variable [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [FirstCountableTopology ι] {ℱ : Filtration ι m} [NormedAddCommGroup E] theorem memℒp_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Memℒp (stoppedProcess u τ n) p μ := by rw [stoppedProcess_eq_of_mem_finset n hbdd] refine Memℒp.add ?_ ?_ · exact Memℒp.indicator (ℱ.le n {a : Ω | n ≤ τ a} (hτ.measurableSet_ge n)) (hu n) · suffices Memℒp (fun ω => ∑ i ∈ s.filter (· < n), {a : Ω | τ a = i}.indicator (u i) ω) p μ by convert this using 1; ext1 ω; simp only [Finset.sum_apply] refine memℒp_finset_sum _ fun i _ => Memℒp.indicator ?_ (hu i) exact ℱ.le i {a : Ω | τ a = i} (hτ.measurableSet_eq i) #align measure_theory.mem_ℒp_stopped_process_of_mem_finset MeasureTheory.memℒp_stoppedProcess_of_mem_finset theorem memℒp_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Memℒp (u n) p μ) (n : ι) : Memℒp (stoppedProcess u τ n) p μ := memℒp_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h #align measure_theory.mem_ℒp_stopped_process MeasureTheory.memℒp_stoppedProcess theorem integrable_stoppedProcess_of_mem_finset (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) {s : Finset ι} (hbdd : ∀ ω, τ ω < n → τ ω ∈ s) : Integrable (stoppedProcess u τ n) μ := by simp_rw [← memℒp_one_iff_integrable] at hu ⊢ exact memℒp_stoppedProcess_of_mem_finset hτ hu n hbdd #align measure_theory.integrable_stopped_process_of_mem_finset MeasureTheory.integrable_stoppedProcess_of_mem_finset theorem integrable_stoppedProcess [LocallyFiniteOrderBot ι] (hτ : IsStoppingTime ℱ τ) (hu : ∀ n, Integrable (u n) μ) (n : ι) : Integrable (stoppedProcess u τ n) μ := integrable_stoppedProcess_of_mem_finset hτ hu n fun _ h => Finset.mem_Iio.mpr h #align measure_theory.integrable_stopped_process MeasureTheory.integrable_stoppedProcess end StoppedProcess end StoppedValueOfMemFinset section AdaptedStoppedProcess variable [TopologicalSpace β] [PseudoMetrizableSpace β] [LinearOrder ι] [TopologicalSpace ι] [SecondCountableTopology ι] [OrderTopology ι] [MeasurableSpace ι] [BorelSpace ι] {f : Filtration ι m} {u : ι → Ω → β} {τ : Ω → ι} /-- The stopped process of an adapted process with continuous paths is adapted. -/ theorem Adapted.stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) : Adapted f (stoppedProcess u τ) := ((hu.progMeasurable_of_continuous hu_cont).stoppedProcess hτ).adapted #align measure_theory.adapted.stopped_process MeasureTheory.Adapted.stoppedProcess /-- If the indexing order has the discrete topology, then the stopped process of an adapted process is adapted. -/ theorem Adapted.stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) : Adapted f (MeasureTheory.stoppedProcess u τ) := (hu.progMeasurable_of_discrete.stoppedProcess hτ).adapted #align measure_theory.adapted.stopped_process_of_discrete MeasureTheory.Adapted.stoppedProcess_of_discrete theorem Adapted.stronglyMeasurable_stoppedProcess [MetrizableSpace ι] (hu : Adapted f u) (hu_cont : ∀ ω, Continuous fun i => u i ω) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := (hu.progMeasurable_of_continuous hu_cont).stronglyMeasurable_stoppedProcess hτ n #align measure_theory.adapted.strongly_measurable_stopped_process MeasureTheory.Adapted.stronglyMeasurable_stoppedProcess theorem Adapted.stronglyMeasurable_stoppedProcess_of_discrete [DiscreteTopology ι] (hu : Adapted f u) (hτ : IsStoppingTime f τ) (n : ι) : StronglyMeasurable (MeasureTheory.stoppedProcess u τ n) := hu.progMeasurable_of_discrete.stronglyMeasurable_stoppedProcess hτ n #align measure_theory.adapted.strongly_measurable_stopped_process_of_discrete MeasureTheory.Adapted.stronglyMeasurable_stoppedProcess_of_discrete end AdaptedStoppedProcess section Nat /-! ### Filtrations indexed by `ℕ` -/ open Filtration variable {f : Filtration ℕ m} {u : ℕ → Ω → β} {τ π : Ω → ℕ} theorem stoppedValue_sub_eq_sum [AddCommGroup β] (hle : τ ≤ π) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.Ico (τ ω) (π ω), (u (i + 1) - u i)) ω := by ext ω rw [Finset.sum_Ico_eq_sub _ (hle ω), Finset.sum_range_sub, Finset.sum_range_sub] simp [stoppedValue] #align measure_theory.stopped_value_sub_eq_sum MeasureTheory.stoppedValue_sub_eq_sum theorem stoppedValue_sub_eq_sum' [AddCommGroup β] (hle : τ ≤ π) {N : ℕ} (hbdd : ∀ ω, π ω ≤ N) : stoppedValue u π - stoppedValue u τ = fun ω => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω ≤ i ∧ i < π ω} (u (i + 1) - u i)) ω := by rw [stoppedValue_sub_eq_sum hle] ext ω simp only [Finset.sum_apply, Finset.sum_indicator_eq_sum_filter] refine Finset.sum_congr ?_ fun _ _ => rfl ext i simp only [Finset.mem_filter, Set.mem_setOf_eq, Finset.mem_range, Finset.mem_Ico] exact ⟨fun h => ⟨lt_trans h.2 (Nat.lt_succ_iff.2 <| hbdd _), h⟩, fun h => h.2⟩ #align measure_theory.stopped_value_sub_eq_sum' MeasureTheory.stoppedValue_sub_eq_sum' section AddCommMonoid variable [AddCommMonoid β] theorem stoppedValue_eq {N : ℕ} (hbdd : ∀ ω, τ ω ≤ N) : stoppedValue u τ = fun x => (∑ i ∈ Finset.range (N + 1), Set.indicator {ω | τ ω = i} (u i)) x := stoppedValue_eq_of_mem_finset fun ω => Finset.mem_range_succ_iff.mpr (hbdd ω) #align measure_theory.stopped_value_eq MeasureTheory.stoppedValue_eq theorem stoppedProcess_eq (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n ≤ τ a} (u n) + ∑ i ∈ Finset.range n, Set.indicator {ω | τ ω = i} (u i) := by rw [stoppedProcess_eq'' n] congr with i rw [Finset.mem_Iio, Finset.mem_range] #align measure_theory.stopped_process_eq MeasureTheory.stoppedProcess_eq theorem stoppedProcess_eq' (n : ℕ) : stoppedProcess u τ n = Set.indicator {a | n + 1 ≤ τ a} (u n) + ∑ i ∈ Finset.range (n + 1), Set.indicator {a | τ a = i} (u i) := by have : {a | n ≤ τ a}.indicator (u n) = {a | n + 1 ≤ τ a}.indicator (u n) + {a | τ a = n}.indicator (u n) := by ext x rw [add_comm, Pi.add_apply, ← Set.indicator_union_of_not_mem_inter] · simp_rw [@eq_comm _ _ n, @le_iff_eq_or_lt _ _ n, Nat.succ_le_iff, Set.setOf_or] · rintro ⟨h₁, h₂⟩ rw [Set.mem_setOf] at h₁ h₂ exact (Nat.succ_le_iff.1 h₂).ne h₁.symm rw [stoppedProcess_eq, this, Finset.sum_range_succ_comm, ← add_assoc] #align measure_theory.stopped_process_eq' MeasureTheory.stoppedProcess_eq' end AddCommMonoid end Nat section PiecewiseConst variable [Preorder ι] {𝒢 : Filtration ι m} {τ η : Ω → ι} {i j : ι} {s : Set Ω} [DecidablePred (· ∈ s)] /-- Given stopping times `τ` and `η` which are bounded below, `Set.piecewise s τ η` is also a stopping time with respect to the same filtration. -/ theorem IsStoppingTime.piecewise_of_le (hτ_st : IsStoppingTime 𝒢 τ) (hη_st : IsStoppingTime 𝒢 η) (hτ : ∀ ω, i ≤ τ ω) (hη : ∀ ω, i ≤ η ω) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise τ η) := by intro n have : {ω | s.piecewise τ η ω ≤ n} = s ∩ {ω | τ ω ≤ n} ∪ sᶜ ∩ {ω | η ω ≤ n} := by ext1 ω simp only [Set.piecewise, Set.mem_inter_iff, Set.mem_setOf_eq, and_congr_right_iff] by_cases hx : ω ∈ s <;> simp [hx] rw [this] by_cases hin : i ≤ n · have hs_n : MeasurableSet[𝒢 n] s := 𝒢.mono hin _ hs exact (hs_n.inter (hτ_st n)).union (hs_n.compl.inter (hη_st n)) · have hτn : ∀ ω, ¬τ ω ≤ n := fun ω hτn => hin ((hτ ω).trans hτn) have hηn : ∀ ω, ¬η ω ≤ n := fun ω hηn => hin ((hη ω).trans hηn) simp [hτn, hηn, @MeasurableSet.empty _ _] #align measure_theory.is_stopping_time.piecewise_of_le MeasureTheory.IsStoppingTime.piecewise_of_le theorem isStoppingTime_piecewise_const (hij : i ≤ j) (hs : MeasurableSet[𝒢 i] s) : IsStoppingTime 𝒢 (s.piecewise (fun _ => i) fun _ => j) := (isStoppingTime_const 𝒢 i).piecewise_of_le (isStoppingTime_const 𝒢 j) (fun _ => le_rfl) (fun _ => hij) hs #align measure_theory.is_stopping_time_piecewise_const MeasureTheory.isStoppingTime_piecewise_const theorem stoppedValue_piecewise_const {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.piecewise (f i) (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] #align measure_theory.stopped_value_piecewise_const MeasureTheory.stoppedValue_piecewise_const theorem stoppedValue_piecewise_const' {ι' : Type*} {i j : ι'} {f : ι' → Ω → ℝ} : stoppedValue f (s.piecewise (fun _ => i) fun _ => j) = s.indicator (f i) + sᶜ.indicator (f j) := by ext ω; rw [stoppedValue]; by_cases hx : ω ∈ s <;> simp [hx] #align measure_theory.stopped_value_piecewise_const' MeasureTheory.stoppedValue_piecewise_const' end PiecewiseConst section Condexp /-! ### Conditional expectation with respect to the σ-algebra generated by a stopping time -/ variable [LinearOrder ι] {μ : Measure Ω} {ℱ : Filtration ι m} {τ σ : Ω → ι} {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] {f : Ω → E} theorem condexp_stopping_time_ae_eq_restrict_eq_of_countable_range [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) (h_countable : (Set.range τ).Countable) [SigmaFinite (μ.trim (hτ.measurableSpace_le_of_countable_range h_countable))] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := by refine condexp_ae_eq_restrict_of_measurableSpace_eq_on (hτ.measurableSpace_le_of_countable_range h_countable) (ℱ.le i) (hτ.measurableSet_eq_of_countable_range' h_countable i) fun t => ?_ rw [Set.inter_comm _ t, IsStoppingTime.measurableSet_inter_eq_iff] #align measure_theory.condexp_stopping_time_ae_eq_restrict_eq_of_countable_range MeasureTheory.condexp_stopping_time_ae_eq_restrict_eq_of_countable_range theorem condexp_stopping_time_ae_eq_restrict_eq_of_countable [Countable ι] [SigmaFiniteFiltration μ ℱ] (hτ : IsStoppingTime ℱ τ) [SigmaFinite (μ.trim hτ.measurableSpace_le_of_countable)] (i : ι) : μ[f|hτ.measurableSpace] =ᵐ[μ.restrict {x | τ x = i}] μ[f|ℱ i] := condexp_stopping_time_ae_eq_restrict_eq_of_countable_range hτ (Set.to_countable _) i #align measure_theory.condexp_stopping_time_ae_eq_restrict_eq_of_countable MeasureTheory.condexp_stopping_time_ae_eq_restrict_eq_of_countable variable [(Filter.atTop : Filter ι).IsCountablyGenerated]
Mathlib/Probability/Process/Stopping.lean
1,179
1,189
theorem condexp_min_stopping_time_ae_eq_restrict_le_const (hτ : IsStoppingTime ℱ τ) (i : ι) [SigmaFinite (μ.trim (hτ.min_const i).measurableSpace_le)] : μ[f|(hτ.min_const i).measurableSpace] =ᵐ[μ.restrict {x | τ x ≤ i}] μ[f|hτ.measurableSpace] := by
have : SigmaFinite (μ.trim hτ.measurableSpace_le) := haveI h_le : (hτ.min_const i).measurableSpace ≤ hτ.measurableSpace := by rw [IsStoppingTime.measurableSpace_min_const] exact inf_le_left sigmaFiniteTrim_mono _ h_le refine (condexp_ae_eq_restrict_of_measurableSpace_eq_on hτ.measurableSpace_le (hτ.min_const i).measurableSpace_le (hτ.measurableSet_le' i) fun t => ?_).symm rw [Set.inter_comm _ t, hτ.measurableSet_inter_le_const_iff]
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Simon Hudon -/ import Mathlib.CategoryTheory.Monoidal.Braided.Basic import Mathlib.CategoryTheory.Monoidal.OfChosenFiniteProducts.Basic #align_import category_theory.monoidal.of_chosen_finite_products.symmetric from "leanprover-community/mathlib"@"95a87616d63b3cb49d3fe678d416fbe9c4217bf4" /-! # The symmetric monoidal structure on a category with chosen finite products. -/ universe v u namespace CategoryTheory variable {C : Type u} [Category.{v} C] {X Y : C} open CategoryTheory.Limits variable (𝒯 : LimitCone (Functor.empty.{0} C)) variable (ℬ : ∀ X Y : C, LimitCone (pair X Y)) open MonoidalOfChosenFiniteProducts namespace MonoidalOfChosenFiniteProducts open MonoidalCategory theorem braiding_naturality {X X' Y Y' : C} (f : X ⟶ Y) (g : X' ⟶ Y') : tensorHom ℬ f g ≫ (Limits.BinaryFan.braiding (ℬ Y Y').isLimit (ℬ Y' Y).isLimit).hom = (Limits.BinaryFan.braiding (ℬ X X').isLimit (ℬ X' X).isLimit).hom ≫ tensorHom ℬ g f := by dsimp [tensorHom, Limits.BinaryFan.braiding] apply (ℬ _ _).isLimit.hom_ext rintro ⟨⟨⟩⟩ <;> · dsimp [Limits.IsLimit.conePointUniqueUpToIso]; simp #align category_theory.monoidal_of_chosen_finite_products.braiding_naturality CategoryTheory.MonoidalOfChosenFiniteProducts.braiding_naturality theorem hexagon_forward (X Y Z : C) : (BinaryFan.associatorOfLimitCone ℬ X Y Z).hom ≫ (Limits.BinaryFan.braiding (ℬ X (tensorObj ℬ Y Z)).isLimit (ℬ (tensorObj ℬ Y Z) X).isLimit).hom ≫ (BinaryFan.associatorOfLimitCone ℬ Y Z X).hom = tensorHom ℬ (Limits.BinaryFan.braiding (ℬ X Y).isLimit (ℬ Y X).isLimit).hom (𝟙 Z) ≫ (BinaryFan.associatorOfLimitCone ℬ Y X Z).hom ≫ tensorHom ℬ (𝟙 Y) (Limits.BinaryFan.braiding (ℬ X Z).isLimit (ℬ Z X).isLimit).hom := by dsimp [tensorHom, Limits.BinaryFan.braiding] apply (ℬ _ _).isLimit.hom_ext; rintro ⟨⟨⟩⟩ · dsimp [Limits.IsLimit.conePointUniqueUpToIso]; simp · apply (ℬ _ _).isLimit.hom_ext rintro ⟨⟨⟩⟩ <;> · dsimp [Limits.IsLimit.conePointUniqueUpToIso]; simp #align category_theory.monoidal_of_chosen_finite_products.hexagon_forward CategoryTheory.MonoidalOfChosenFiniteProducts.hexagon_forward
Mathlib/CategoryTheory/Monoidal/OfChosenFiniteProducts/Symmetric.lean
57
74
theorem hexagon_reverse (X Y Z : C) : (BinaryFan.associatorOfLimitCone ℬ X Y Z).inv ≫ (Limits.BinaryFan.braiding (ℬ (tensorObj ℬ X Y) Z).isLimit (ℬ Z (tensorObj ℬ X Y)).isLimit).hom ≫ (BinaryFan.associatorOfLimitCone ℬ Z X Y).inv = tensorHom ℬ (𝟙 X) (Limits.BinaryFan.braiding (ℬ Y Z).isLimit (ℬ Z Y).isLimit).hom ≫ (BinaryFan.associatorOfLimitCone ℬ X Z Y).inv ≫ tensorHom ℬ (Limits.BinaryFan.braiding (ℬ X Z).isLimit (ℬ Z X).isLimit).hom (𝟙 Y) := by
dsimp [tensorHom, Limits.BinaryFan.braiding] apply (ℬ _ _).isLimit.hom_ext; rintro ⟨⟨⟩⟩ · apply (ℬ _ _).isLimit.hom_ext rintro ⟨⟨⟩⟩ <;> · dsimp [BinaryFan.associatorOfLimitCone, BinaryFan.associator, Limits.IsLimit.conePointUniqueUpToIso] simp · dsimp [BinaryFan.associatorOfLimitCone, BinaryFan.associator, Limits.IsLimit.conePointUniqueUpToIso] simp
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Data.Option.Basic import Mathlib.Data.Set.Basic #align_import data.pequiv from "leanprover-community/mathlib"@"7c3269ca3fa4c0c19e4d127cd7151edbdbf99ed4" /-! # Partial Equivalences In this file, we define partial equivalences `PEquiv`, which are a bijection between a subset of `α` and a subset of `β`. Notationally, a `PEquiv` is denoted by "`≃.`" (note that the full stop is part of the notation). The way we store these internally is with two functions `f : α → Option β` and the reverse function `g : β → Option α`, with the condition that if `f a` is `some b`, then `g b` is `some a`. ## Main results - `PEquiv.ofSet`: creates a `PEquiv` from a set `s`, which sends an element to itself if it is in `s`. - `PEquiv.single`: given two elements `a : α` and `b : β`, create a `PEquiv` that sends them to each other, and ignores all other elements. - `PEquiv.injective_of_forall_ne_isSome`/`injective_of_forall_isSome`: If the domain of a `PEquiv` is all of `α` (except possibly one point), its `toFun` is injective. ## Canonical order `PEquiv` is canonically ordered by inclusion; that is, if a function `f` defined on a subset `s` is equal to `g` on that subset, but `g` is also defined on a larger set, then `f ≤ g`. We also have a definition of `⊥`, which is the empty `PEquiv` (sends all to `none`), which in the end gives us a `SemilatticeInf` with an `OrderBot` instance. ## Tags pequiv, partial equivalence -/ universe u v w x /-- A `PEquiv` is a partial equivalence, a representation of a bijection between a subset of `α` and a subset of `β`. See also `PartialEquiv` for a version that requires `toFun` and `invFun` to be globally defined functions and has `source` and `target` sets as extra fields. -/ structure PEquiv (α : Type u) (β : Type v) where /-- The underlying partial function of a `PEquiv` -/ toFun : α → Option β /-- The partial inverse of `toFun` -/ invFun : β → Option α /-- `invFun` is the partial inverse of `toFun` -/ inv : ∀ (a : α) (b : β), a ∈ invFun b ↔ b ∈ toFun a #align pequiv PEquiv /-- A `PEquiv` is a partial equivalence, a representation of a bijection between a subset of `α` and a subset of `β`. See also `PartialEquiv` for a version that requires `toFun` and `invFun` to be globally defined functions and has `source` and `target` sets as extra fields. -/ infixr:25 " ≃. " => PEquiv namespace PEquiv variable {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} open Function Option instance : FunLike (α ≃. β) α (Option β) := { coe := toFun coe_injective' := by rintro ⟨f₁, f₂, hf⟩ ⟨g₁, g₂, hg⟩ (rfl : f₁ = g₁) congr with y x simp only [hf, hg] } @[simp] theorem coe_mk (f₁ : α → Option β) (f₂ h) : (mk f₁ f₂ h : α → Option β) = f₁ := rfl theorem coe_mk_apply (f₁ : α → Option β) (f₂ : β → Option α) (h) (x : α) : (PEquiv.mk f₁ f₂ h : α → Option β) x = f₁ x := rfl #align pequiv.coe_mk_apply PEquiv.coe_mk_apply @[ext] theorem ext {f g : α ≃. β} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h #align pequiv.ext PEquiv.ext theorem ext_iff {f g : α ≃. β} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align pequiv.ext_iff PEquiv.ext_iff /-- The identity map as a partial equivalence. -/ @[refl] protected def refl (α : Type*) : α ≃. α where toFun := some invFun := some inv _ _ := eq_comm #align pequiv.refl PEquiv.refl /-- The inverse partial equivalence. -/ @[symm] protected def symm (f : α ≃. β) : β ≃. α where toFun := f.2 invFun := f.1 inv _ _ := (f.inv _ _).symm #align pequiv.symm PEquiv.symm theorem mem_iff_mem (f : α ≃. β) : ∀ {a : α} {b : β}, a ∈ f.symm b ↔ b ∈ f a := f.3 _ _ #align pequiv.mem_iff_mem PEquiv.mem_iff_mem theorem eq_some_iff (f : α ≃. β) : ∀ {a : α} {b : β}, f.symm b = some a ↔ f a = some b := f.3 _ _ #align pequiv.eq_some_iff PEquiv.eq_some_iff /-- Composition of partial equivalences `f : α ≃. β` and `g : β ≃. γ`. -/ @[trans] protected def trans (f : α ≃. β) (g : β ≃. γ) : α ≃. γ where toFun a := (f a).bind g invFun a := (g.symm a).bind f.symm inv a b := by simp_all [and_comm, eq_some_iff f, eq_some_iff g, bind_eq_some] #align pequiv.trans PEquiv.trans @[simp] theorem refl_apply (a : α) : PEquiv.refl α a = some a := rfl #align pequiv.refl_apply PEquiv.refl_apply @[simp] theorem symm_refl : (PEquiv.refl α).symm = PEquiv.refl α := rfl #align pequiv.symm_refl PEquiv.symm_refl @[simp] theorem symm_symm (f : α ≃. β) : f.symm.symm = f := by cases f; rfl #align pequiv.symm_symm PEquiv.symm_symm theorem symm_bijective : Function.Bijective (PEquiv.symm : (α ≃. β) → β ≃. α) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ theorem symm_injective : Function.Injective (@PEquiv.symm α β) := symm_bijective.injective #align pequiv.symm_injective PEquiv.symm_injective theorem trans_assoc (f : α ≃. β) (g : β ≃. γ) (h : γ ≃. δ) : (f.trans g).trans h = f.trans (g.trans h) := ext fun _ => Option.bind_assoc _ _ _ #align pequiv.trans_assoc PEquiv.trans_assoc theorem mem_trans (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) : c ∈ f.trans g a ↔ ∃ b, b ∈ f a ∧ c ∈ g b := Option.bind_eq_some' #align pequiv.mem_trans PEquiv.mem_trans theorem trans_eq_some (f : α ≃. β) (g : β ≃. γ) (a : α) (c : γ) : f.trans g a = some c ↔ ∃ b, f a = some b ∧ g b = some c := Option.bind_eq_some' #align pequiv.trans_eq_some PEquiv.trans_eq_some theorem trans_eq_none (f : α ≃. β) (g : β ≃. γ) (a : α) : f.trans g a = none ↔ ∀ b c, b ∉ f a ∨ c ∉ g b := by simp only [eq_none_iff_forall_not_mem, mem_trans, imp_iff_not_or.symm] push_neg exact forall_swap #align pequiv.trans_eq_none PEquiv.trans_eq_none @[simp] theorem refl_trans (f : α ≃. β) : (PEquiv.refl α).trans f = f := by ext; dsimp [PEquiv.trans]; rfl #align pequiv.refl_trans PEquiv.refl_trans @[simp] theorem trans_refl (f : α ≃. β) : f.trans (PEquiv.refl β) = f := by ext; dsimp [PEquiv.trans]; simp #align pequiv.trans_refl PEquiv.trans_refl protected theorem inj (f : α ≃. β) {a₁ a₂ : α} {b : β} (h₁ : b ∈ f a₁) (h₂ : b ∈ f a₂) : a₁ = a₂ := by rw [← mem_iff_mem] at *; cases h : f.symm b <;> simp_all #align pequiv.inj PEquiv.inj /-- If the domain of a `PEquiv` is `α` except a point, its forward direction is injective. -/ theorem injective_of_forall_ne_isSome (f : α ≃. β) (a₂ : α) (h : ∀ a₁ : α, a₁ ≠ a₂ → isSome (f a₁)) : Injective f := HasLeftInverse.injective ⟨fun b => Option.recOn b a₂ fun b' => Option.recOn (f.symm b') a₂ id, fun x => by classical cases hfx : f x · have : x = a₂ := not_imp_comm.1 (h x) (hfx.symm ▸ by simp) simp [this] · dsimp only rw [(eq_some_iff f).2 hfx] rfl⟩ #align pequiv.injective_of_forall_ne_is_some PEquiv.injective_of_forall_ne_isSome /-- If the domain of a `PEquiv` is all of `α`, its forward direction is injective. -/ theorem injective_of_forall_isSome {f : α ≃. β} (h : ∀ a : α, isSome (f a)) : Injective f := (Classical.em (Nonempty α)).elim (fun hn => injective_of_forall_ne_isSome f (Classical.choice hn) fun a _ => h a) fun hn x => (hn ⟨x⟩).elim #align pequiv.injective_of_forall_is_some PEquiv.injective_of_forall_isSome section OfSet variable (s : Set α) [DecidablePred (· ∈ s)] /-- Creates a `PEquiv` that is the identity on `s`, and `none` outside of it. -/ def ofSet (s : Set α) [DecidablePred (· ∈ s)] : α ≃. α where toFun a := if a ∈ s then some a else none invFun a := if a ∈ s then some a else none inv a b := by dsimp only split_ifs with hb ha ha · simp [eq_comm] · simp [ne_of_mem_of_not_mem hb ha] · simp [ne_of_mem_of_not_mem ha hb] · simp #align pequiv.of_set PEquiv.ofSet theorem mem_ofSet_self_iff {s : Set α} [DecidablePred (· ∈ s)] {a : α} : a ∈ ofSet s a ↔ a ∈ s := by dsimp [ofSet]; split_ifs <;> simp [*] #align pequiv.mem_of_set_self_iff PEquiv.mem_ofSet_self_iff theorem mem_ofSet_iff {s : Set α} [DecidablePred (· ∈ s)] {a b : α} : a ∈ ofSet s b ↔ a = b ∧ a ∈ s := by dsimp [ofSet] split_ifs with h · simp only [mem_def, eq_comm, some.injEq, iff_self_and] rintro rfl exact h · simp only [mem_def, false_iff, not_and] rintro rfl exact h #align pequiv.mem_of_set_iff PEquiv.mem_ofSet_iff @[simp] theorem ofSet_eq_some_iff {s : Set α} {_ : DecidablePred (· ∈ s)} {a b : α} : ofSet s b = some a ↔ a = b ∧ a ∈ s := mem_ofSet_iff #align pequiv.of_set_eq_some_iff PEquiv.ofSet_eq_some_iff theorem ofSet_eq_some_self_iff {s : Set α} {_ : DecidablePred (· ∈ s)} {a : α} : ofSet s a = some a ↔ a ∈ s := mem_ofSet_self_iff #align pequiv.of_set_eq_some_self_iff PEquiv.ofSet_eq_some_self_iff @[simp] theorem ofSet_symm : (ofSet s).symm = ofSet s := rfl #align pequiv.of_set_symm PEquiv.ofSet_symm @[simp] theorem ofSet_univ : ofSet Set.univ = PEquiv.refl α := rfl #align pequiv.of_set_univ PEquiv.ofSet_univ @[simp] theorem ofSet_eq_refl {s : Set α} [DecidablePred (· ∈ s)] : ofSet s = PEquiv.refl α ↔ s = Set.univ := ⟨fun h => by rw [Set.eq_univ_iff_forall] intro rw [← mem_ofSet_self_iff, h] exact rfl, fun h => by simp only [← ofSet_univ, h]⟩ #align pequiv.of_set_eq_refl PEquiv.ofSet_eq_refl end OfSet theorem symm_trans_rev (f : α ≃. β) (g : β ≃. γ) : (f.trans g).symm = g.symm.trans f.symm := rfl #align pequiv.symm_trans_rev PEquiv.symm_trans_rev
Mathlib/Data/PEquiv.lean
274
282
theorem self_trans_symm (f : α ≃. β) : f.trans f.symm = ofSet { a | (f a).isSome } := by
ext dsimp [PEquiv.trans] simp only [eq_some_iff f, Option.isSome_iff_exists, Option.mem_def, bind_eq_some', ofSet_eq_some_iff] constructor · rintro ⟨b, hb₁, hb₂⟩ exact ⟨PEquiv.inj _ hb₂ hb₁, b, hb₂⟩ · simp (config := { contextual := true })
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon -/ import Mathlib.Control.Traversable.Equiv import Mathlib.Control.Traversable.Instances import Batteries.Data.LazyList import Mathlib.Lean.Thunk #align_import data.lazy_list.basic from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! ## Definitions on lazy lists This file contains various definitions and proofs on lazy lists. TODO: move the `LazyList.lean` file from core to mathlib. -/ universe u namespace LazyList open Function /-- Isomorphism between strict and lazy lists. -/ def listEquivLazyList (α : Type*) : List α ≃ LazyList α where toFun := LazyList.ofList invFun := LazyList.toList right_inv := by intro xs induction xs using toList.induct · simp [toList, ofList] · simp [toList, ofList, *]; rfl left_inv := by intro xs induction xs · simp [toList, ofList] · simpa [ofList, toList] #align lazy_list.list_equiv_lazy_list LazyList.listEquivLazyList -- Porting note: Added a name to make the recursion work. instance decidableEq {α : Type u} [DecidableEq α] : DecidableEq (LazyList α) | nil, nil => isTrue rfl | cons x xs, cons y ys => if h : x = y then match decidableEq xs.get ys.get with | isFalse h2 => by apply isFalse; simp only [cons.injEq, not_and]; intro _ xs_ys; apply h2; rw [xs_ys] | isTrue h2 => by apply isTrue; congr; ext; exact h2 else by apply isFalse; simp only [cons.injEq, not_and]; intro; contradiction | nil, cons _ _ => by apply isFalse; simp | cons _ _, nil => by apply isFalse; simp /-- Traversal of lazy lists using an applicative effect. -/ protected def traverse {m : Type u → Type u} [Applicative m] {α β : Type u} (f : α → m β) : LazyList α → m (LazyList β) | LazyList.nil => pure LazyList.nil | LazyList.cons x xs => LazyList.cons <$> f x <*> Thunk.pure <$> xs.get.traverse f #align lazy_list.traverse LazyList.traverse instance : Traversable LazyList where map := @LazyList.traverse Id _ traverse := @LazyList.traverse instance : LawfulTraversable LazyList := by apply Equiv.isLawfulTraversable' listEquivLazyList <;> intros <;> ext <;> rename_i f xs · induction' xs using LazyList.rec with _ _ _ _ ih · simp only [Functor.map, LazyList.traverse, pure, Equiv.map, listEquivLazyList, Equiv.coe_fn_symm_mk, toList, Equiv.coe_fn_mk, ofList] · simpa only [Equiv.map, Functor.map, listEquivLazyList, Equiv.coe_fn_symm_mk, Equiv.coe_fn_mk, LazyList.traverse, Seq.seq, toList, ofList, cons.injEq, true_and] · ext; apply ih · simp only [Equiv.map, listEquivLazyList, Equiv.coe_fn_symm_mk, Equiv.coe_fn_mk, comp, Functor.mapConst] induction' xs using LazyList.rec with _ _ _ _ ih · simp only [LazyList.traverse, pure, Functor.map, toList, ofList] · simpa only [toList, ofList, LazyList.traverse, Seq.seq, Functor.map, cons.injEq, true_and] · congr; apply ih · simp only [traverse, Equiv.traverse, listEquivLazyList, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk] induction' xs using LazyList.rec with _ tl ih _ ih · simp only [LazyList.traverse, toList, List.traverse, map_pure, ofList] · replace ih : tl.get.traverse f = ofList <$> tl.get.toList.traverse f := ih simp [traverse.eq_2, ih, Functor.map_map, seq_map_assoc, toList, List.traverse, map_seq, Function.comp, Thunk.pure, ofList] · apply ih /-- `init xs`, if `xs` non-empty, drops the last element of the list. Otherwise, return the empty list. -/ def init {α} : LazyList α → LazyList α | LazyList.nil => LazyList.nil | LazyList.cons x xs => let xs' := xs.get match xs' with | LazyList.nil => LazyList.nil | LazyList.cons _ _ => LazyList.cons x (init xs') #align lazy_list.init LazyList.init /-- Return the first object contained in the list that satisfies predicate `p` -/ def find {α} (p : α → Prop) [DecidablePred p] : LazyList α → Option α | nil => none | cons h t => if p h then some h else t.get.find p #align lazy_list.find LazyList.find /-- `interleave xs ys` creates a list where elements of `xs` and `ys` alternate. -/ def interleave {α} : LazyList α → LazyList α → LazyList α | LazyList.nil, xs => xs | a@(LazyList.cons _ _), LazyList.nil => a | LazyList.cons x xs, LazyList.cons y ys => LazyList.cons x (LazyList.cons y (interleave xs.get ys.get)) #align lazy_list.interleave LazyList.interleave /-- `interleaveAll (xs::ys::zs::xss)` creates a list where elements of `xs`, `ys` and `zs` and the rest alternate. Every other element of the resulting list is taken from `xs`, every fourth is taken from `ys`, every eighth is taken from `zs` and so on. -/ def interleaveAll {α} : List (LazyList α) → LazyList α | [] => LazyList.nil | x :: xs => interleave x (interleaveAll xs) #align lazy_list.interleave_all LazyList.interleaveAll /-- Monadic bind operation for `LazyList`. -/ protected def bind {α β} : LazyList α → (α → LazyList β) → LazyList β | LazyList.nil, _ => LazyList.nil | LazyList.cons x xs, f => (f x).append (xs.get.bind f) #align lazy_list.bind LazyList.bind /-- Reverse the order of a `LazyList`. It is done by converting to a `List` first because reversal involves evaluating all the list and if the list is all evaluated, `List` is a better representation for it than a series of thunks. -/ def reverse {α} (xs : LazyList α) : LazyList α := ofList xs.toList.reverse #align lazy_list.reverse LazyList.reverse instance : Monad LazyList where pure := @LazyList.singleton bind := @LazyList.bind -- Porting note: Added `Thunk.pure` to definition. theorem append_nil {α} (xs : LazyList α) : xs.append (Thunk.pure LazyList.nil) = xs := by induction' xs using LazyList.rec with _ _ _ _ ih · simp only [Thunk.pure, append, Thunk.get] · simpa only [append, cons.injEq, true_and] · ext; apply ih #align lazy_list.append_nil LazyList.append_nil
Mathlib/Data/LazyList/Basic.lean
150
155
theorem append_assoc {α} (xs ys zs : LazyList α) : (xs.append ys).append zs = xs.append (ys.append zs) := by
induction' xs using LazyList.rec with _ _ _ _ ih · simp only [append, Thunk.get] · simpa only [append, cons.injEq, true_and] · ext; apply ih
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Oliver Nash -/ import Mathlib.Data.Finset.Card #align_import data.finset.prod from "leanprover-community/mathlib"@"9003f28797c0664a49e4179487267c494477d853" /-! # Finsets in product types This file defines finset constructions on the product type `α × β`. Beware not to confuse with the `Finset.prod` operation which computes the multiplicative product. ## Main declarations * `Finset.product`: Turns `s : Finset α`, `t : Finset β` into their product in `Finset (α × β)`. * `Finset.diag`: For `s : Finset α`, `s.diag` is the `Finset (α × α)` of pairs `(a, a)` with `a ∈ s`. * `Finset.offDiag`: For `s : Finset α`, `s.offDiag` is the `Finset (α × α)` of pairs `(a, b)` with `a, b ∈ s` and `a ≠ b`. -/ assert_not_exists MonoidWithZero open Multiset variable {α β γ : Type*} namespace Finset /-! ### prod -/ section Prod variable {s s' : Finset α} {t t' : Finset β} {a : α} {b : β} /-- `product s t` is the set of pairs `(a, b)` such that `a ∈ s` and `b ∈ t`. -/ protected def product (s : Finset α) (t : Finset β) : Finset (α × β) := ⟨_, s.nodup.product t.nodup⟩ #align finset.product Finset.product instance instSProd : SProd (Finset α) (Finset β) (Finset (α × β)) where sprod := Finset.product @[simp] theorem product_val : (s ×ˢ t).1 = s.1 ×ˢ t.1 := rfl #align finset.product_val Finset.product_val @[simp] theorem mem_product {p : α × β} : p ∈ s ×ˢ t ↔ p.1 ∈ s ∧ p.2 ∈ t := Multiset.mem_product #align finset.mem_product Finset.mem_product theorem mk_mem_product (ha : a ∈ s) (hb : b ∈ t) : (a, b) ∈ s ×ˢ t := mem_product.2 ⟨ha, hb⟩ #align finset.mk_mem_product Finset.mk_mem_product @[simp, norm_cast] theorem coe_product (s : Finset α) (t : Finset β) : (↑(s ×ˢ t) : Set (α × β)) = (s : Set α) ×ˢ t := Set.ext fun _ => Finset.mem_product #align finset.coe_product Finset.coe_product theorem subset_product_image_fst [DecidableEq α] : (s ×ˢ t).image Prod.fst ⊆ s := fun i => by simp (config := { contextual := true }) [mem_image] #align finset.subset_product_image_fst Finset.subset_product_image_fst theorem subset_product_image_snd [DecidableEq β] : (s ×ˢ t).image Prod.snd ⊆ t := fun i => by simp (config := { contextual := true }) [mem_image] #align finset.subset_product_image_snd Finset.subset_product_image_snd theorem product_image_fst [DecidableEq α] (ht : t.Nonempty) : (s ×ˢ t).image Prod.fst = s := by ext i simp [mem_image, ht.exists_mem] #align finset.product_image_fst Finset.product_image_fst theorem product_image_snd [DecidableEq β] (ht : s.Nonempty) : (s ×ˢ t).image Prod.snd = t := by ext i simp [mem_image, ht.exists_mem] #align finset.product_image_snd Finset.product_image_snd theorem subset_product [DecidableEq α] [DecidableEq β] {s : Finset (α × β)} : s ⊆ s.image Prod.fst ×ˢ s.image Prod.snd := fun _ hp => mem_product.2 ⟨mem_image_of_mem _ hp, mem_image_of_mem _ hp⟩ #align finset.subset_product Finset.subset_product @[gcongr] theorem product_subset_product (hs : s ⊆ s') (ht : t ⊆ t') : s ×ˢ t ⊆ s' ×ˢ t' := fun ⟨_, _⟩ h => mem_product.2 ⟨hs (mem_product.1 h).1, ht (mem_product.1 h).2⟩ #align finset.product_subset_product Finset.product_subset_product @[gcongr] theorem product_subset_product_left (hs : s ⊆ s') : s ×ˢ t ⊆ s' ×ˢ t := product_subset_product hs (Subset.refl _) #align finset.product_subset_product_left Finset.product_subset_product_left @[gcongr] theorem product_subset_product_right (ht : t ⊆ t') : s ×ˢ t ⊆ s ×ˢ t' := product_subset_product (Subset.refl _) ht #align finset.product_subset_product_right Finset.product_subset_product_right theorem map_swap_product (s : Finset α) (t : Finset β) : (t ×ˢ s).map ⟨Prod.swap, Prod.swap_injective⟩ = s ×ˢ t := coe_injective <| by push_cast exact Set.image_swap_prod _ _ #align finset.map_swap_product Finset.map_swap_product @[simp] theorem image_swap_product [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : (t ×ˢ s).image Prod.swap = s ×ˢ t := coe_injective <| by push_cast exact Set.image_swap_prod _ _ #align finset.image_swap_product Finset.image_swap_product theorem product_eq_biUnion [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : s ×ˢ t = s.biUnion fun a => t.image fun b => (a, b) := ext fun ⟨x, y⟩ => by simp only [mem_product, mem_biUnion, mem_image, exists_prop, Prod.mk.inj_iff, and_left_comm, exists_and_left, exists_eq_right, exists_eq_left] #align finset.product_eq_bUnion Finset.product_eq_biUnion theorem product_eq_biUnion_right [DecidableEq (α × β)] (s : Finset α) (t : Finset β) : s ×ˢ t = t.biUnion fun b => s.image fun a => (a, b) := ext fun ⟨x, y⟩ => by simp only [mem_product, mem_biUnion, mem_image, exists_prop, Prod.mk.inj_iff, and_left_comm, exists_and_left, exists_eq_right, exists_eq_left] #align finset.product_eq_bUnion_right Finset.product_eq_biUnion_right /-- See also `Finset.sup_product_left`. -/ @[simp] theorem product_biUnion [DecidableEq γ] (s : Finset α) (t : Finset β) (f : α × β → Finset γ) : (s ×ˢ t).biUnion f = s.biUnion fun a => t.biUnion fun b => f (a, b) := by classical simp_rw [product_eq_biUnion, biUnion_biUnion, image_biUnion] #align finset.product_bUnion Finset.product_biUnion @[simp] theorem card_product (s : Finset α) (t : Finset β) : card (s ×ˢ t) = card s * card t := Multiset.card_product _ _ #align finset.card_product Finset.card_product /-- The product of two Finsets is nontrivial iff both are nonempty at least one of them is nontrivial. -/ lemma nontrivial_prod_iff : (s ×ˢ t).Nontrivial ↔ s.Nonempty ∧ t.Nonempty ∧ (s.Nontrivial ∨ t.Nontrivial) := by simp_rw [← card_pos, ← one_lt_card_iff_nontrivial, card_product]; apply Nat.one_lt_mul_iff theorem filter_product (p : α → Prop) (q : β → Prop) [DecidablePred p] [DecidablePred q] : ((s ×ˢ t).filter fun x : α × β => p x.1 ∧ q x.2) = s.filter p ×ˢ t.filter q := by ext ⟨a, b⟩ simp [mem_filter, mem_product, decide_eq_true_eq, and_comm, and_left_comm, and_assoc] #align finset.filter_product Finset.filter_product
Mathlib/Data/Finset/Prod.lean
159
161
theorem filter_product_left (p : α → Prop) [DecidablePred p] : ((s ×ˢ t).filter fun x : α × β => p x.1) = s.filter p ×ˢ t := by
simpa using filter_product p fun _ => true
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Ring import Mathlib.Algebra.Module.BigOperators import Mathlib.NumberTheory.Divisors import Mathlib.Data.Nat.Squarefree import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.Factorization.Basic import Mathlib.Tactic.ArithMult #align_import number_theory.arithmetic_function from "leanprover-community/mathlib"@"e8638a0fcaf73e4500469f368ef9494e495099b3" /-! # Arithmetic Functions and Dirichlet Convolution This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition, to form the Dirichlet ring. ## Main Definitions * `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`. * An arithmetic function `f` `IsMultiplicative` when `x.coprime y → f (x * y) = f x * f y`. * The pointwise operations `pmul` and `ppow` differ from the multiplication and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication. * `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`. * `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`. * `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`. * `id` is the identity arithmetic function on `ℕ`. * `ω n` is the number of distinct prime factors of `n`. * `Ω n` is the number of prime factors of `n` counted with multiplicity. * `μ` is the Möbius function (spelled `moebius` in code). ## Main Results * Several forms of Möbius inversion: * `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero` * And variants that apply when the equalities only hold on a set `S : Set ℕ` such that `m ∣ n → n ∈ S → m ∈ S`: * `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero` ## Notation All notation is localized in the namespace `ArithmeticFunction`. The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names. In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`, `ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`, `ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`, to allow for selective access to these notations. The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation `∏ᵖ p ∣ n, f p` when applied to `n`. ## Tags arithmetic functions, dirichlet convolution, divisors -/ open Finset open Nat variable (R : Type*) /-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by Dirichlet convolution. -/ def ArithmeticFunction [Zero R] := ZeroHom ℕ R #align nat.arithmetic_function ArithmeticFunction instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) := inferInstanceAs (Zero (ZeroHom ℕ R)) instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R)) variable {R} namespace ArithmeticFunction section Zero variable [Zero R] -- porting note: used to be `CoeFun` instance : FunLike (ArithmeticFunction R) ℕ R := inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R) @[simp] theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl #align nat.arithmetic_function.to_fun_eq ArithmeticFunction.toFun_eq @[simp] theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _ (ZeroHom.mk f hf) = f := rfl @[simp] theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 := ZeroHom.map_zero' f #align nat.arithmetic_function.map_zero ArithmeticFunction.map_zero theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g := DFunLike.coe_fn_eq #align nat.arithmetic_function.coe_inj ArithmeticFunction.coe_inj @[simp] theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 := ZeroHom.zero_apply x #align nat.arithmetic_function.zero_apply ArithmeticFunction.zero_apply @[ext] theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g := ZeroHom.ext h #align nat.arithmetic_function.ext ArithmeticFunction.ext theorem ext_iff {f g : ArithmeticFunction R} : f = g ↔ ∀ x, f x = g x := DFunLike.ext_iff #align nat.arithmetic_function.ext_iff ArithmeticFunction.ext_iff section One variable [One R] instance one : One (ArithmeticFunction R) := ⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩ theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 := rfl #align nat.arithmetic_function.one_apply ArithmeticFunction.one_apply @[simp] theorem one_one : (1 : ArithmeticFunction R) 1 = 1 := rfl #align nat.arithmetic_function.one_one ArithmeticFunction.one_one @[simp] theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 := if_neg h #align nat.arithmetic_function.one_apply_ne ArithmeticFunction.one_apply_ne end One end Zero /-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline this in `natCoe` because it gets unfolded too much. -/ @[coe] -- Porting note: added `coe` tag. def natToArithmeticFunction [AddMonoidWithOne R] : (ArithmeticFunction ℕ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) := ⟨natToArithmeticFunction⟩ #align nat.arithmetic_function.nat_coe ArithmeticFunction.natCoe @[simp] theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f := ext fun _ => cast_id _ #align nat.arithmetic_function.nat_coe_nat ArithmeticFunction.natCoe_nat @[simp] theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl #align nat.arithmetic_function.nat_coe_apply ArithmeticFunction.natCoe_apply /-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline this in `intCoe` because it gets unfolded too much. -/ @[coe] def ofInt [AddGroupWithOne R] : (ArithmeticFunction ℤ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) := ⟨ofInt⟩ #align nat.arithmetic_function.int_coe ArithmeticFunction.intCoe @[simp] theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f := ext fun _ => Int.cast_id #align nat.arithmetic_function.int_coe_int ArithmeticFunction.intCoe_int @[simp] theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl #align nat.arithmetic_function.int_coe_apply ArithmeticFunction.intCoe_apply @[simp] theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} : ((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by ext simp #align nat.arithmetic_function.coe_coe ArithmeticFunction.coe_coe @[simp] theorem natCoe_one [AddMonoidWithOne R] : ((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] #align nat.arithmetic_function.nat_coe_one ArithmeticFunction.natCoe_one @[simp] theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] #align nat.arithmetic_function.int_coe_one ArithmeticFunction.intCoe_one section AddMonoid variable [AddMonoid R] instance add : Add (ArithmeticFunction R) := ⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩ @[simp] theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n := rfl #align nat.arithmetic_function.add_apply ArithmeticFunction.add_apply instance instAddMonoid : AddMonoid (ArithmeticFunction R) := { ArithmeticFunction.zero R, ArithmeticFunction.add with add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _ zero_add := fun _ => ext fun _ => zero_add _ add_zero := fun _ => ext fun _ => add_zero _ nsmul := nsmulRec } #align nat.arithmetic_function.add_monoid ArithmeticFunction.instAddMonoid end AddMonoid instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid, ArithmeticFunction.one with natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩ natCast_zero := by ext; simp natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] } #align nat.arithmetic_function.add_monoid_with_one ArithmeticFunction.instAddMonoidWithOne instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ } instance [NegZeroClass R] : Neg (ArithmeticFunction R) where neg f := ⟨fun n => -f n, by simp⟩ instance [AddGroup R] : AddGroup (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with add_left_neg := fun _ => ext fun _ => add_left_neg _ zsmul := zsmulRec } instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) := { show AddGroup (ArithmeticFunction R) by infer_instance with add_comm := fun _ _ ↦ add_comm _ _ } section SMul variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M] /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) := ⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩ @[simp] theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} : (f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd := rfl #align nat.arithmetic_function.smul_apply ArithmeticFunction.smul_apply end SMul /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance [Semiring R] : Mul (ArithmeticFunction R) := ⟨(· • ·)⟩ @[simp] theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} : (f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd := rfl #align nat.arithmetic_function.mul_apply ArithmeticFunction.mul_apply theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp #align nat.arithmetic_function.mul_apply_one ArithmeticFunction.mul_apply_one @[simp, norm_cast] theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} : (↑(f * g) : ArithmeticFunction R) = f * g := by ext n simp #align nat.arithmetic_function.nat_coe_mul ArithmeticFunction.natCoe_mul @[simp, norm_cast] theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} : (↑(f * g) : ArithmeticFunction R) = ↑f * g := by ext n simp #align nat.arithmetic_function.int_coe_mul ArithmeticFunction.intCoe_mul section Module variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) : (f * g) • h = f • g • h := by ext n simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc) #align nat.arithmetic_function.mul_smul' ArithmeticFunction.mul_smul' theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by ext x rw [smul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro y ymem ynmem have y1ne : y.fst ≠ 1 := by intro con simp only [Con, mem_divisorsAntidiagonal, one_mul, Ne] at ymem simp only [mem_singleton, Prod.ext_iff] at ynmem -- Porting note: `tauto` worked from here. cases y subst con simp only [true_and, one_mul, x0, not_false_eq_true, and_true] at ynmem ymem tauto simp [y1ne] #align nat.arithmetic_function.one_smul' ArithmeticFunction.one_smul' end Module section Semiring variable [Semiring R] instance instMonoid : Monoid (ArithmeticFunction R) := { one := One.one mul := Mul.mul one_mul := one_smul' mul_one := fun f => by ext x rw [mul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro y ymem ynmem have y2ne : y.snd ≠ 1 := by intro con cases y; subst con -- Porting note: added simp only [Con, mem_divisorsAntidiagonal, mul_one, Ne] at ymem simp only [mem_singleton, Prod.ext_iff] at ynmem tauto simp [y2ne] mul_assoc := mul_smul' } #align nat.arithmetic_function.monoid ArithmeticFunction.instMonoid instance instSemiring : Semiring (ArithmeticFunction R) := -- Porting note: I reorganized this instance { ArithmeticFunction.instAddMonoidWithOne, ArithmeticFunction.instMonoid, ArithmeticFunction.instAddCommMonoid with zero_mul := fun f => by ext simp only [mul_apply, zero_mul, sum_const_zero, zero_apply] mul_zero := fun f => by ext simp only [mul_apply, sum_const_zero, mul_zero, zero_apply] left_distrib := fun a b c => by ext simp only [← sum_add_distrib, mul_add, mul_apply, add_apply] right_distrib := fun a b c => by ext simp only [← sum_add_distrib, add_mul, mul_apply, add_apply] } #align nat.arithmetic_function.semiring ArithmeticFunction.instSemiring end Semiring instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with mul_comm := fun f g => by ext rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map] simp [mul_comm] } instance [CommRing R] : CommRing (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with add_left_neg := add_left_neg mul_comm := mul_comm zsmul := (· • ·) } instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] : Module (ArithmeticFunction R) (ArithmeticFunction M) where one_smul := one_smul' mul_smul := mul_smul' smul_add r x y := by ext simp only [sum_add_distrib, smul_add, smul_apply, add_apply] smul_zero r := by ext simp only [smul_apply, sum_const_zero, smul_zero, zero_apply] add_smul r s x := by ext simp only [add_smul, sum_add_distrib, smul_apply, add_apply] zero_smul r := by ext simp only [smul_apply, sum_const_zero, zero_smul, zero_apply] section Zeta /-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/ def zeta : ArithmeticFunction ℕ := ⟨fun x => ite (x = 0) 0 1, rfl⟩ #align nat.arithmetic_function.zeta ArithmeticFunction.zeta @[inherit_doc] scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta @[inherit_doc] scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta @[simp] theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 := rfl #align nat.arithmetic_function.zeta_apply ArithmeticFunction.zeta_apply theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 := if_neg h #align nat.arithmetic_function.zeta_apply_ne ArithmeticFunction.zeta_apply_ne -- Porting note: removed `@[simp]`, LHS not in normal form theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [Module R M] {f : ArithmeticFunction M} {x : ℕ} : ((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by rw [smul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.snd · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul] · rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk] #align nat.arithmetic_function.coe_zeta_smul_apply ArithmeticFunction.coe_zeta_smul_apply -- Porting note: removed `@[simp]` to make the linter happy. theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (↑ζ * f) x = ∑ i ∈ divisors x, f i := coe_zeta_smul_apply #align nat.arithmetic_function.coe_zeta_mul_apply ArithmeticFunction.coe_zeta_mul_apply -- Porting note: removed `@[simp]` to make the linter happy. theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by rw [mul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.1 · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one] · rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk] #align nat.arithmetic_function.coe_mul_zeta_apply ArithmeticFunction.coe_mul_zeta_apply theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := coe_zeta_mul_apply -- Porting note: was `by rw [← nat_coe_nat ζ, coe_zeta_mul_apply]`. Is this `theorem` obsolete? #align nat.arithmetic_function.zeta_mul_apply ArithmeticFunction.zeta_mul_apply theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := coe_mul_zeta_apply -- Porting note: was `by rw [← natCoe_nat ζ, coe_mul_zeta_apply]`. Is this `theorem` obsolete= #align nat.arithmetic_function.mul_zeta_apply ArithmeticFunction.mul_zeta_apply end Zeta open ArithmeticFunction section Pmul /-- This is the pointwise product of `ArithmeticFunction`s. -/ def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun x => f x * g x, by simp⟩ #align nat.arithmetic_function.pmul ArithmeticFunction.pmul @[simp] theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x := rfl #align nat.arithmetic_function.pmul_apply ArithmeticFunction.pmul_apply theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by ext simp [mul_comm] #align nat.arithmetic_function.pmul_comm ArithmeticFunction.pmul_comm lemma pmul_assoc [CommMonoidWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) : pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by ext simp only [pmul_apply, mul_assoc] section NonAssocSemiring variable [NonAssocSemiring R] @[simp] theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by ext x cases x <;> simp [Nat.succ_ne_zero] #align nat.arithmetic_function.pmul_zeta ArithmeticFunction.pmul_zeta @[simp] theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by ext x cases x <;> simp [Nat.succ_ne_zero] #align nat.arithmetic_function.zeta_pmul ArithmeticFunction.zeta_pmul end NonAssocSemiring variable [Semiring R] /-- This is the pointwise power of `ArithmeticFunction`s. -/ def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R := if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩ #align nat.arithmetic_function.ppow ArithmeticFunction.ppow @[simp] theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl] #align nat.arithmetic_function.ppow_zero ArithmeticFunction.ppow_zero @[simp] theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by rw [ppow, dif_neg (Nat.ne_of_gt kpos)] rfl #align nat.arithmetic_function.ppow_apply ArithmeticFunction.ppow_apply theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ'] induction k <;> simp #align nat.arithmetic_function.ppow_succ ArithmeticFunction.ppow_succ' theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} : f.ppow (k + 1) = (f.ppow k).pmul f := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ] induction k <;> simp #align nat.arithmetic_function.ppow_succ' ArithmeticFunction.ppow_succ end Pmul section Pdiv /-- This is the pointwise division of `ArithmeticFunction`s. -/ def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩ @[simp] theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) : pdiv f g n = f n / g n := rfl /-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/ @[simp] theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) : pdiv f zeta = f := by ext n cases n <;> simp [succ_ne_zero] end Pdiv section ProdPrimeFactors /-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/ def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p map_zero' := if_pos rfl open Batteries.ExtendedBinder /-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/ scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term scoped macro_rules (kind := bigproddvd) | `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n) @[simp] theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f: ℕ → R} {n : ℕ} (hn : n ≠ 0) : ∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p := if_neg hn end ProdPrimeFactors /-- Multiplicative functions -/ def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop := f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n #align nat.arithmetic_function.is_multiplicative ArithmeticFunction.IsMultiplicative namespace IsMultiplicative section MonoidWithZero variable [MonoidWithZero R] @[simp, arith_mult] theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 := h.1 #align nat.arithmetic_function.is_multiplicative.map_one ArithmeticFunction.IsMultiplicative.map_one @[simp] theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ} (h : m.Coprime n) : f (m * n) = f m * f n := hf.2 h #align nat.arithmetic_function.is_multiplicative.map_mul_of_coprime ArithmeticFunction.IsMultiplicative.map_mul_of_coprime end MonoidWithZero theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) : f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by classical induction' s using Finset.induction_on with a s has ih hs · simp [hf] rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1] exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm #align nat.arithmetic_function.is_multiplicative.map_prod ArithmeticFunction.IsMultiplicative.map_prod theorem map_prod_of_prime [CommSemiring R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy theorem map_prod_of_subset_primeFactors [CommSemiring R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ) (t : Finset ℕ) (ht : t ⊆ l.primeFactors) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a) @[arith_mult] theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := -- Porting note: was `by simp [cop, h]` ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ #align nat.arithmetic_function.is_multiplicative.nat_cast ArithmeticFunction.IsMultiplicative.natCast @[deprecated (since := "2024-04-17")] alias nat_cast := natCast @[arith_mult] theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := -- Porting note: was `by simp [cop, h]` ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ #align nat.arithmetic_function.is_multiplicative.int_cast ArithmeticFunction.IsMultiplicative.intCast @[deprecated (since := "2024-04-17")] alias int_cast := intCast @[arith_mult] theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by refine ⟨by simp [hf.1, hg.1], ?_⟩ simp only [mul_apply] intro m n cop rw [sum_mul_sum, ← sum_product'] symm apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l) · rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne] constructor · ring rw [Nat.mul_eq_zero] at * apply not_or_of_not ha hb · simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk.inj_iff] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h simp only [Prod.mk.inj_iff] at h ext <;> dsimp only · trans Nat.gcd (a1 * a2) (a1 * b1) · rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.1, Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · trans Nat.gcd (a1 * a2) (a2 * b2) · rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a1 * b1) · rw [mul_comm, Nat.gcd_mul_right, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a2 * b2) · rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.2, Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Set.mem_image, exists_prop, Prod.mk.inj_iff] rintro ⟨b1, b2⟩ h dsimp at h use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)) rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _] · rw [Nat.mul_eq_zero, not_or] at h simp [h.2.1, h.2.2] rw [mul_comm n m, h.1] · simp only [mem_divisorsAntidiagonal, Ne, mem_product] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ dsimp only rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right, hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right] ring #align nat.arithmetic_function.is_multiplicative.mul ArithmeticFunction.IsMultiplicative.mul @[arith_mult] theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) := ⟨by simp [hf, hg], fun {m n} cop => by simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop] ring⟩ #align nat.arithmetic_function.is_multiplicative.pmul ArithmeticFunction.IsMultiplicative.pmul @[arith_mult] theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) := ⟨ by simp [hf, hg], fun {m n} cop => by simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop, div_eq_mul_inv, mul_inv] apply mul_mul_mul_comm ⟩ /-- For any multiplicative function `f` and any `n > 0`, we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/ nonrec -- Porting note: added theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) : f n = n.factorization.prod fun p k => f (p ^ k) := multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn #align nat.arithmetic_function.is_multiplicative.multiplicative_factorization ArithmeticFunction.IsMultiplicative.multiplicative_factorization /-- A recapitulation of the definition of multiplicative that is simpler for proofs -/ theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} : IsMultiplicative f ↔ f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩) rcases eq_or_ne m 0 with (rfl | hm) · simp rcases eq_or_ne n 0 with (rfl | hn) · simp exact h hm hn hmn #align nat.arithmetic_function.is_multiplicative.iff_ne_zero ArithmeticFunction.IsMultiplicative.iff_ne_zero /-- Two multiplicative functions `f` and `g` are equal if and only if they agree on prime powers -/ theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) : f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by constructor · intro h p i _ rw [h] intro h ext n by_cases hn : n = 0 · rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero] rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn] exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp) #align nat.arithmetic_function.is_multiplicative.eq_iff_eq_on_prime_powers ArithmeticFunction.IsMultiplicative.eq_iff_eq_on_prime_powers @[arith_mult] theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : IsMultiplicative (prodPrimeFactors f) := by rw [iff_ne_zero] simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one, prod_empty, true_and] intro x y hx hy hxy have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy, Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors] theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) : ∏ᵖ p ∣ n, (f + g) p = (f * g) n := by rw [prodPrimeFactors_apply hn.ne_zero] simp_rw [add_apply (f:=f) (g:=g)] rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·), ← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero, factors_eq] apply Finset.sum_congr rfl intro t ht rw [t.prod_val, Function.id_def, ← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht), hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht), ← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset] theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} : f (x.lcm y) * f (x.gcd y) = f x * f y := by by_cases hx : x = 0 · simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left] by_cases hy : y = 0 · simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul] have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by intro i; rw [Nat.pow_zero, hf.1] iterate 4 rw [hf.multiplicative_factorization f (by assumption), Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero) (s := (x.primeFactors ⊔ y.primeFactors))] · rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib] apply Finset.prod_congr rfl intro p _ rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;> simp only [factorization_lcm hx hy, ge_iff_le, Finsupp.sup_apply, h, sup_of_le_right, sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply, inf_of_le_left, mul_comm] · apply Finset.subset_union_right · apply Finset.subset_union_left · rw [factorization_gcd hx hy, Finsupp.support_inf, Finset.sup_eq_union] apply Finset.inter_subset_union · simp [factorization_lcm hx hy] end IsMultiplicative section SpecialFunctions /-- The identity on `ℕ` as an `ArithmeticFunction`. -/ nonrec -- Porting note (#11445): added def id : ArithmeticFunction ℕ := ⟨id, rfl⟩ #align nat.arithmetic_function.id ArithmeticFunction.id @[simp] theorem id_apply {x : ℕ} : id x = x := rfl #align nat.arithmetic_function.id_apply ArithmeticFunction.id_apply /-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/ def pow (k : ℕ) : ArithmeticFunction ℕ := id.ppow k #align nat.arithmetic_function.pow ArithmeticFunction.pow @[simp] theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by cases k · simp [pow] rename_i k -- Porting note: added simp [pow, k.succ_pos.ne'] #align nat.arithmetic_function.pow_apply ArithmeticFunction.pow_apply theorem pow_zero_eq_zeta : pow 0 = ζ := by ext n simp #align nat.arithmetic_function.pow_zero_eq_zeta ArithmeticFunction.pow_zero_eq_zeta /-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/ def sigma (k : ℕ) : ArithmeticFunction ℕ := ⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩ #align nat.arithmetic_function.sigma ArithmeticFunction.sigma @[inherit_doc] scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma @[inherit_doc] scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k := rfl #align nat.arithmetic_function.sigma_apply ArithmeticFunction.sigma_apply theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply] #align nat.arithmetic_function.sigma_one_apply ArithmeticFunction.sigma_one_apply theorem sigma_zero_apply (n : ℕ) : σ 0 n = (divisors n).card := by simp [sigma_apply] #align nat.arithmetic_function.sigma_zero_apply ArithmeticFunction.sigma_zero_apply theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by rw [sigma_zero_apply, divisors_prime_pow hp, card_map, card_range] #align nat.arithmetic_function.sigma_zero_apply_prime_pow ArithmeticFunction.sigma_zero_apply_prime_pow theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by ext rw [sigma, zeta_mul_apply] apply sum_congr rfl intro x hx rw [pow_apply, if_neg (not_and_of_not_right _ _)] contrapose! hx simp [hx] #align nat.arithmetic_function.zeta_mul_pow_eq_sigma ArithmeticFunction.zeta_mul_pow_eq_sigma @[arith_mult] theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by intro m n hm _hn hmn rcases eq_or_ne m 1 with (rfl | hm') · simp rw [one_apply_ne, one_apply_ne hm', zero_mul] rw [Ne, mul_eq_one, not_and_or] exact Or.inl hm'⟩ #align nat.arithmetic_function.is_multiplicative_one ArithmeticFunction.isMultiplicative_one @[arith_mult] theorem isMultiplicative_zeta : IsMultiplicative ζ := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp (config := { contextual := true })⟩ #align nat.arithmetic_function.is_multiplicative_zeta ArithmeticFunction.isMultiplicative_zeta @[arith_mult] theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id := ⟨rfl, fun {_ _} _ => rfl⟩ #align nat.arithmetic_function.is_multiplicative_id ArithmeticFunction.isMultiplicative_id @[arith_mult] theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {k : ℕ} : IsMultiplicative (f.ppow k) := by induction' k with k hi · exact isMultiplicative_zeta.natCast · rw [ppow_succ'] apply hf.pmul hi #align nat.arithmetic_function.is_multiplicative.ppow ArithmeticFunction.IsMultiplicative.ppow @[arith_mult] theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) := isMultiplicative_id.ppow #align nat.arithmetic_function.is_multiplicative_pow ArithmeticFunction.isMultiplicative_pow @[arith_mult] theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by rw [← zeta_mul_pow_eq_sigma] apply isMultiplicative_zeta.mul isMultiplicative_pow #align nat.arithmetic_function.is_multiplicative_sigma ArithmeticFunction.isMultiplicative_sigma /-- `Ω n` is the number of prime factors of `n`. -/ def cardFactors : ArithmeticFunction ℕ := ⟨fun n => n.factors.length, by simp⟩ #align nat.arithmetic_function.card_factors ArithmeticFunction.cardFactors @[inherit_doc] scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors @[inherit_doc] scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors theorem cardFactors_apply {n : ℕ} : Ω n = n.factors.length := rfl #align nat.arithmetic_function.card_factors_apply ArithmeticFunction.cardFactors_apply lemma cardFactors_zero : Ω 0 = 0 := by simp @[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply] #align nat.arithmetic_function.card_factors_one ArithmeticFunction.cardFactors_one @[simp] theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by refine ⟨fun h => ?_, fun h => List.length_eq_one.2 ⟨n, factors_prime h⟩⟩ cases' n with n · simp at h rcases List.length_eq_one.1 h with ⟨x, hx⟩ rw [← prod_factors n.add_one_ne_zero, hx, List.prod_singleton] apply prime_of_mem_factors rw [hx, List.mem_singleton] #align nat.arithmetic_function.card_factors_eq_one_iff_prime ArithmeticFunction.cardFactors_eq_one_iff_prime theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq, UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq, Multiset.card_add, Multiset.coe_card, Multiset.coe_card] #align nat.arithmetic_function.card_factors_mul ArithmeticFunction.cardFactors_mul theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) : Ω s.prod = (Multiset.map Ω s).sum := by induction s using Multiset.induction_on with | empty => simp | cons ih => simp_all [cardFactors_mul, not_or] #align nat.arithmetic_function.card_factors_multiset_prod ArithmeticFunction.cardFactors_multiset_prod @[simp] theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 := cardFactors_eq_one_iff_prime.2 hp #align nat.arithmetic_function.card_factors_apply_prime ArithmeticFunction.cardFactors_apply_prime @[simp] theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by rw [cardFactors_apply, hp.factors_pow, List.length_replicate] #align nat.arithmetic_function.card_factors_apply_prime_pow ArithmeticFunction.cardFactors_apply_prime_pow /-- `ω n` is the number of distinct prime factors of `n`. -/ def cardDistinctFactors : ArithmeticFunction ℕ := ⟨fun n => n.factors.dedup.length, by simp⟩ #align nat.arithmetic_function.card_distinct_factors ArithmeticFunction.cardDistinctFactors @[inherit_doc] scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors @[inherit_doc] scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors theorem cardDistinctFactors_zero : ω 0 = 0 := by simp #align nat.arithmetic_function.card_distinct_factors_zero ArithmeticFunction.cardDistinctFactors_zero @[simp] theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors] #align nat.arithmetic_function.card_distinct_factors_one ArithmeticFunction.cardDistinctFactors_one theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.factors.dedup.length := rfl #align nat.arithmetic_function.card_distinct_factors_apply ArithmeticFunction.cardDistinctFactors_apply theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) : ω n = Ω n ↔ Squarefree n := by rw [squarefree_iff_nodup_factors h0, cardDistinctFactors_apply] constructor <;> intro h · rw [← n.factors.dedup_sublist.eq_of_length h] apply List.nodup_dedup · rw [h.dedup] rfl #align nat.arithmetic_function.card_distinct_factors_eq_card_factors_iff_squarefree ArithmeticFunction.cardDistinctFactors_eq_cardFactors_iff_squarefree @[simp] theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) : ω (p ^ k) = 1 := by rw [cardDistinctFactors_apply, hp.factors_pow, List.replicate_dedup hk, List.length_singleton] #align nat.arithmetic_function.card_distinct_factors_apply_prime_pow ArithmeticFunction.cardDistinctFactors_apply_prime_pow @[simp] theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero] #align nat.arithmetic_function.card_distinct_factors_apply_prime ArithmeticFunction.cardDistinctFactors_apply_prime /-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors, `μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`. If `n` is not squarefree, `μ n = 0`. -/ def moebius : ArithmeticFunction ℤ := ⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩ #align nat.arithmetic_function.moebius ArithmeticFunction.moebius @[inherit_doc] scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius @[inherit_doc] scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius @[simp] theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n := if_pos h #align nat.arithmetic_function.moebius_apply_of_squarefree ArithmeticFunction.moebius_apply_of_squarefree @[simp] theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 := if_neg h #align nat.arithmetic_function.moebius_eq_zero_of_not_squarefree ArithmeticFunction.moebius_eq_zero_of_not_squarefree theorem moebius_apply_one : μ 1 = 1 := by simp #align nat.arithmetic_function.moebius_apply_one ArithmeticFunction.moebius_apply_one theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by constructor <;> intro h · contrapose! h simp [h] · simp [h, pow_ne_zero] #align nat.arithmetic_function.moebius_ne_zero_iff_squarefree ArithmeticFunction.moebius_ne_zero_iff_squarefree theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by simp only [moebius, coe_mk] split_ifs · right exact neg_one_pow_eq_or .. · left rfl theorem moebius_ne_zero_iff_eq_or {n : ℕ} : μ n ≠ 0 ↔ μ n = 1 ∨ μ n = -1 := by have := moebius_eq_or n aesop #align nat.arithmetic_function.moebius_ne_zero_iff_eq_or ArithmeticFunction.moebius_ne_zero_iff_eq_or theorem moebius_sq_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : μ l ^ 2 = 1 := by rw [moebius_apply_of_squarefree hl, ← pow_mul, mul_comm, pow_mul, neg_one_sq, one_pow] theorem abs_moebius_eq_one_of_squarefree {l : ℕ} (hl : Squarefree l) : |μ l| = 1 := by simp only [moebius_apply_of_squarefree hl, abs_pow, abs_neg, abs_one, one_pow] theorem moebius_sq {n : ℕ} : μ n ^ 2 = if Squarefree n then 1 else 0 := by split_ifs with h · exact moebius_sq_eq_one_of_squarefree h · simp only [pow_eq_zero_iff, moebius_eq_zero_of_not_squarefree h, zero_pow (show 2 ≠ 0 by norm_num)] theorem abs_moebius {n : ℕ} : |μ n| = if Squarefree n then 1 else 0 := by split_ifs with h · exact abs_moebius_eq_one_of_squarefree h · simp only [moebius_eq_zero_of_not_squarefree h, abs_zero] theorem abs_moebius_le_one {n : ℕ} : |μ n| ≤ 1 := by rw [abs_moebius, apply_ite (· ≤ 1)] simp theorem moebius_apply_prime {p : ℕ} (hp : p.Prime) : μ p = -1 := by rw [moebius_apply_of_squarefree hp.squarefree, cardFactors_apply_prime hp, pow_one] #align nat.arithmetic_function.moebius_apply_prime ArithmeticFunction.moebius_apply_prime theorem moebius_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) : μ (p ^ k) = if k = 1 then -1 else 0 := by split_ifs with h · rw [h, pow_one, moebius_apply_prime hp] rw [moebius_eq_zero_of_not_squarefree] rw [squarefree_pow_iff hp.ne_one hk, not_and_or] exact Or.inr h #align nat.arithmetic_function.moebius_apply_prime_pow ArithmeticFunction.moebius_apply_prime_pow theorem moebius_apply_isPrimePow_not_prime {n : ℕ} (hn : IsPrimePow n) (hn' : ¬n.Prime) : μ n = 0 := by obtain ⟨p, k, hp, hk, rfl⟩ := (isPrimePow_nat_iff _).1 hn rw [moebius_apply_prime_pow hp hk.ne', if_neg] rintro rfl exact hn' (by simpa) #align nat.arithmetic_function.moebius_apply_is_prime_pow_not_prime ArithmeticFunction.moebius_apply_isPrimePow_not_prime @[arith_mult] theorem isMultiplicative_moebius : IsMultiplicative μ := by rw [IsMultiplicative.iff_ne_zero] refine ⟨by simp, fun {n m} hn hm hnm => ?_⟩ simp only [moebius, ZeroHom.coe_mk, coe_mk, ZeroHom.toFun_eq_coe, Eq.ndrec, ZeroHom.coe_mk, IsUnit.mul_iff, Nat.isUnit_iff, squarefree_mul hnm, ite_zero_mul_ite_zero, cardFactors_mul hn hm, pow_add] #align nat.arithmetic_function.is_multiplicative_moebius ArithmeticFunction.isMultiplicative_moebius theorem IsMultiplicative.prodPrimeFactors_one_add_of_squarefree [CommSemiring R] {f : ArithmeticFunction R} (h_mult : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) : ∏ p ∈ n.primeFactors, (1 + f p) = ∑ d ∈ n.divisors, f d := by trans (∏ᵖ p ∣ n, ((ζ:ArithmeticFunction R) + f) p) · simp_rw [prodPrimeFactors_apply hn.ne_zero, add_apply, natCoe_apply] apply Finset.prod_congr rfl; intro p hp; rw [zeta_apply_ne (prime_of_mem_factors <| List.mem_toFinset.mp hp).ne_zero, cast_one] rw [isMultiplicative_zeta.natCast.prodPrimeFactors_add_of_squarefree h_mult hn, coe_zeta_mul_apply] theorem IsMultiplicative.prodPrimeFactors_one_sub_of_squarefree [CommRing R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : Squarefree n) : ∏ p ∈ n.primeFactors, (1 - f p) = ∑ d ∈ n.divisors, μ d * f d := by trans (∏ p ∈ n.primeFactors, (1 + (ArithmeticFunction.pmul (μ:ArithmeticFunction R) f) p)) · apply Finset.prod_congr rfl; intro p hp rw [pmul_apply, intCoe_apply, ArithmeticFunction.moebius_apply_prime (prime_of_mem_factors (List.mem_toFinset.mp hp))] ring · rw [(isMultiplicative_moebius.intCast.pmul hf).prodPrimeFactors_one_add_of_squarefree hn] simp_rw [pmul_apply, intCoe_apply] open UniqueFactorizationMonoid @[simp]
Mathlib/NumberTheory/ArithmeticFunction.lean
1,170
1,187
theorem moebius_mul_coe_zeta : (μ * ζ : ArithmeticFunction ℤ) = 1 := by
ext n refine recOnPosPrimePosCoprime ?_ ?_ ?_ ?_ n · intro p n hp hn rw [coe_mul_zeta_apply, sum_divisors_prime_pow hp, sum_range_succ'] simp_rw [Nat.pow_zero, moebius_apply_one, moebius_apply_prime_pow hp (Nat.succ_ne_zero _), Nat.succ_inj', sum_ite_eq', mem_range, if_pos hn, add_left_neg] rw [one_apply_ne] rw [Ne, pow_eq_one_iff] · exact hp.ne_one · exact hn.ne' · rw [ZeroHom.map_zero, ZeroHom.map_zero] · simp · intro a b _ha _hb hab ha' hb' rw [IsMultiplicative.map_mul_of_coprime _ hab, ha', hb', IsMultiplicative.map_mul_of_coprime isMultiplicative_one hab] exact isMultiplicative_moebius.mul isMultiplicative_zeta.natCast
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Bundle import Mathlib.Data.Set.Image import Mathlib.Topology.PartialHomeomorph import Mathlib.Topology.Order.Basic #align_import topology.fiber_bundle.trivialization from "leanprover-community/mathlib"@"e473c3198bb41f68560cab68a0529c854b618833" /-! # Trivializations ## Main definitions ### Basic definitions * `Trivialization F p` : structure extending partial homeomorphisms, defining a local trivialization of a topological space `Z` with projection `p` and fiber `F`. * `Pretrivialization F proj` : trivialization as a partial equivalence, mainly used when the topology on the total space has not yet been defined. ### Operations on bundles We provide the following operations on `Trivialization`s. * `Trivialization.compHomeomorph`: given a local trivialization `e` of a fiber bundle `p : Z → B` and a homeomorphism `h : Z' ≃ₜ Z`, returns a local trivialization of the fiber bundle `p ∘ h`. ## Implementation notes Previously, in mathlib, there was a structure `topological_vector_bundle.trivialization` which extended another structure `topological_fiber_bundle.trivialization` by a linearity hypothesis. As of PR leanprover-community/mathlib#17359, we have changed this to a single structure `Trivialization` (no namespace), together with a mixin class `Trivialization.IsLinear`. This permits all the *data* of a vector bundle to be held at the level of fiber bundles, so that the same trivializations can underlie an object's structure as (say) a vector bundle over `ℂ` and as a vector bundle over `ℝ`, as well as its structure simply as a fiber bundle. This might be a little surprising, given the general trend of the library to ever-increased bundling. But in this case the typical motivation for more bundling does not apply: there is no algebraic or order structure on the whole type of linear (say) trivializations of a bundle. Indeed, since trivializations only have meaning on their base sets (taking junk values outside), the type of linear trivializations is not even particularly well-behaved. -/ open TopologicalSpace Filter Set Bundle Function open scoped Topology Classical Bundle variable {ι : Type*} {B : Type*} {F : Type*} {E : B → Type*} variable (F) {Z : Type*} [TopologicalSpace B] [TopologicalSpace F] {proj : Z → B} /-- This structure contains the information left for a local trivialization (which is implemented below as `Trivialization F proj`) if the total space has not been given a topology, but we have a topology on both the fiber and the base space. Through the construction `topological_fiber_prebundle F proj` it will be possible to promote a `Pretrivialization F proj` to a `Trivialization F proj`. -/ structure Pretrivialization (proj : Z → B) extends PartialEquiv Z (B × F) where open_target : IsOpen target baseSet : Set B open_baseSet : IsOpen baseSet source_eq : source = proj ⁻¹' baseSet target_eq : target = baseSet ×ˢ univ proj_toFun : ∀ p ∈ source, (toFun p).1 = proj p #align pretrivialization Pretrivialization namespace Pretrivialization variable {F} variable (e : Pretrivialization F proj) {x : Z} /-- Coercion of a pretrivialization to a function. We don't use `e.toFun` in the `CoeFun` instance because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/ @[coe] def toFun' : Z → (B × F) := e.toFun instance : CoeFun (Pretrivialization F proj) fun _ => Z → B × F := ⟨toFun'⟩ @[ext] lemma ext' (e e' : Pretrivialization F proj) (h₁ : e.toPartialEquiv = e'.toPartialEquiv) (h₂ : e.baseSet = e'.baseSet) : e = e' := by cases e; cases e'; congr #align pretrivialization.ext Pretrivialization.ext' -- Porting note (#11215): TODO: move `ext` here? lemma ext {e e' : Pretrivialization F proj} (h₁ : ∀ x, e x = e' x) (h₂ : ∀ x, e.toPartialEquiv.symm x = e'.toPartialEquiv.symm x) (h₃ : e.baseSet = e'.baseSet) : e = e' := by ext1 <;> [ext1; exact h₃] · apply h₁ · apply h₂ · rw [e.source_eq, e'.source_eq, h₃] /-- If the fiber is nonempty, then the projection also is. -/ lemma toPartialEquiv_injective [Nonempty F] : Injective (toPartialEquiv : Pretrivialization F proj → PartialEquiv Z (B × F)) := by refine fun e e' h ↦ ext' _ _ h ?_ simpa only [fst_image_prod, univ_nonempty, target_eq] using congr_arg (Prod.fst '' PartialEquiv.target ·) h @[simp, mfld_simps] theorem coe_coe : ⇑e.toPartialEquiv = e := rfl #align pretrivialization.coe_coe Pretrivialization.coe_coe @[simp, mfld_simps] theorem coe_fst (ex : x ∈ e.source) : (e x).1 = proj x := e.proj_toFun x ex #align pretrivialization.coe_fst Pretrivialization.coe_fst theorem mem_source : x ∈ e.source ↔ proj x ∈ e.baseSet := by rw [e.source_eq, mem_preimage] #align pretrivialization.mem_source Pretrivialization.mem_source theorem coe_fst' (ex : proj x ∈ e.baseSet) : (e x).1 = proj x := e.coe_fst (e.mem_source.2 ex) #align pretrivialization.coe_fst' Pretrivialization.coe_fst' protected theorem eqOn : EqOn (Prod.fst ∘ e) proj e.source := fun _ hx => e.coe_fst hx #align pretrivialization.eq_on Pretrivialization.eqOn theorem mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x := Prod.ext (e.coe_fst ex).symm rfl #align pretrivialization.mk_proj_snd Pretrivialization.mk_proj_snd theorem mk_proj_snd' (ex : proj x ∈ e.baseSet) : (proj x, (e x).2) = e x := Prod.ext (e.coe_fst' ex).symm rfl #align pretrivialization.mk_proj_snd' Pretrivialization.mk_proj_snd' /-- Composition of inverse and coercion from the subtype of the target. -/ def setSymm : e.target → Z := e.target.restrict e.toPartialEquiv.symm #align pretrivialization.set_symm Pretrivialization.setSymm theorem mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.baseSet := by rw [e.target_eq, prod_univ, mem_preimage] #align pretrivialization.mem_target Pretrivialization.mem_target theorem proj_symm_apply {x : B × F} (hx : x ∈ e.target) : proj (e.toPartialEquiv.symm x) = x.1 := by have := (e.coe_fst (e.map_target hx)).symm rwa [← e.coe_coe, e.right_inv hx] at this #align pretrivialization.proj_symm_apply Pretrivialization.proj_symm_apply theorem proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) : proj (e.toPartialEquiv.symm (b, x)) = b := e.proj_symm_apply (e.mem_target.2 hx) #align pretrivialization.proj_symm_apply' Pretrivialization.proj_symm_apply' theorem proj_surjOn_baseSet [Nonempty F] : Set.SurjOn proj e.source e.baseSet := fun b hb => let ⟨y⟩ := ‹Nonempty F› ⟨e.toPartialEquiv.symm (b, y), e.toPartialEquiv.map_target <| e.mem_target.2 hb, e.proj_symm_apply' hb⟩ #align pretrivialization.proj_surj_on_base_set Pretrivialization.proj_surjOn_baseSet theorem apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.toPartialEquiv.symm x) = x := e.toPartialEquiv.right_inv hx #align pretrivialization.apply_symm_apply Pretrivialization.apply_symm_apply theorem apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) : e (e.toPartialEquiv.symm (b, x)) = (b, x) := e.apply_symm_apply (e.mem_target.2 hx) #align pretrivialization.apply_symm_apply' Pretrivialization.apply_symm_apply' theorem symm_apply_apply {x : Z} (hx : x ∈ e.source) : e.toPartialEquiv.symm (e x) = x := e.toPartialEquiv.left_inv hx #align pretrivialization.symm_apply_apply Pretrivialization.symm_apply_apply @[simp, mfld_simps] theorem symm_apply_mk_proj {x : Z} (ex : x ∈ e.source) : e.toPartialEquiv.symm (proj x, (e x).2) = x := by rw [← e.coe_fst ex, ← e.coe_coe, e.left_inv ex] #align pretrivialization.symm_apply_mk_proj Pretrivialization.symm_apply_mk_proj @[simp, mfld_simps] theorem preimage_symm_proj_baseSet : e.toPartialEquiv.symm ⁻¹' (proj ⁻¹' e.baseSet) ∩ e.target = e.target := by refine inter_eq_right.mpr fun x hx => ?_ simp only [mem_preimage, PartialEquiv.invFun_as_coe, e.proj_symm_apply hx] exact e.mem_target.mp hx #align pretrivialization.preimage_symm_proj_base_set Pretrivialization.preimage_symm_proj_baseSet @[simp, mfld_simps] theorem preimage_symm_proj_inter (s : Set B) : e.toPartialEquiv.symm ⁻¹' (proj ⁻¹' s) ∩ e.baseSet ×ˢ univ = (s ∩ e.baseSet) ×ˢ univ := by ext ⟨x, y⟩ suffices x ∈ e.baseSet → (proj (e.toPartialEquiv.symm (x, y)) ∈ s ↔ x ∈ s) by simpa only [prod_mk_mem_set_prod_eq, mem_inter_iff, and_true_iff, mem_univ, and_congr_left_iff] intro h rw [e.proj_symm_apply' h] #align pretrivialization.preimage_symm_proj_inter Pretrivialization.preimage_symm_proj_inter theorem target_inter_preimage_symm_source_eq (e f : Pretrivialization F proj) : f.target ∩ f.toPartialEquiv.symm ⁻¹' e.source = (e.baseSet ∩ f.baseSet) ×ˢ univ := by rw [inter_comm, f.target_eq, e.source_eq, f.preimage_symm_proj_inter] #align pretrivialization.target_inter_preimage_symm_source_eq Pretrivialization.target_inter_preimage_symm_source_eq theorem trans_source (e f : Pretrivialization F proj) : (f.toPartialEquiv.symm.trans e.toPartialEquiv).source = (e.baseSet ∩ f.baseSet) ×ˢ univ := by rw [PartialEquiv.trans_source, PartialEquiv.symm_source, e.target_inter_preimage_symm_source_eq] #align pretrivialization.trans_source Pretrivialization.trans_source theorem symm_trans_symm (e e' : Pretrivialization F proj) : (e.toPartialEquiv.symm.trans e'.toPartialEquiv).symm = e'.toPartialEquiv.symm.trans e.toPartialEquiv := by rw [PartialEquiv.trans_symm_eq_symm_trans_symm, PartialEquiv.symm_symm] #align pretrivialization.symm_trans_symm Pretrivialization.symm_trans_symm theorem symm_trans_source_eq (e e' : Pretrivialization F proj) : (e.toPartialEquiv.symm.trans e'.toPartialEquiv).source = (e.baseSet ∩ e'.baseSet) ×ˢ univ := by rw [PartialEquiv.trans_source, e'.source_eq, PartialEquiv.symm_source, e.target_eq, inter_comm, e.preimage_symm_proj_inter, inter_comm] #align pretrivialization.symm_trans_source_eq Pretrivialization.symm_trans_source_eq theorem symm_trans_target_eq (e e' : Pretrivialization F proj) : (e.toPartialEquiv.symm.trans e'.toPartialEquiv).target = (e.baseSet ∩ e'.baseSet) ×ˢ univ := by rw [← PartialEquiv.symm_source, symm_trans_symm, symm_trans_source_eq, inter_comm] #align pretrivialization.symm_trans_target_eq Pretrivialization.symm_trans_target_eq variable (e' : Pretrivialization F (π F E)) {x' : TotalSpace F E} {b : B} {y : E b} @[simp] theorem coe_mem_source : ↑y ∈ e'.source ↔ b ∈ e'.baseSet := e'.mem_source #align pretrivialization.coe_mem_source Pretrivialization.coe_mem_source @[simp, mfld_simps] theorem coe_coe_fst (hb : b ∈ e'.baseSet) : (e' y).1 = b := e'.coe_fst (e'.mem_source.2 hb) #align pretrivialization.coe_coe_fst Pretrivialization.coe_coe_fst theorem mk_mem_target {x : B} {y : F} : (x, y) ∈ e'.target ↔ x ∈ e'.baseSet := e'.mem_target #align pretrivialization.mk_mem_target Pretrivialization.mk_mem_target theorem symm_coe_proj {x : B} {y : F} (e' : Pretrivialization F (π F E)) (h : x ∈ e'.baseSet) : (e'.toPartialEquiv.symm (x, y)).1 = x := e'.proj_symm_apply' h #align pretrivialization.symm_coe_proj Pretrivialization.symm_coe_proj section Zero variable [∀ x, Zero (E x)] /-- A fiberwise inverse to `e`. This is the function `F → E b` that induces a local inverse `B × F → TotalSpace F E` of `e` on `e.baseSet`. It is defined to be `0` outside `e.baseSet`. -/ protected noncomputable def symm (e : Pretrivialization F (π F E)) (b : B) (y : F) : E b := if hb : b ∈ e.baseSet then cast (congr_arg E (e.proj_symm_apply' hb)) (e.toPartialEquiv.symm (b, y)).2 else 0 #align pretrivialization.symm Pretrivialization.symm theorem symm_apply (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) : e.symm b y = cast (congr_arg E (e.symm_coe_proj hb)) (e.toPartialEquiv.symm (b, y)).2 := dif_pos hb #align pretrivialization.symm_apply Pretrivialization.symm_apply theorem symm_apply_of_not_mem (e : Pretrivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet) (y : F) : e.symm b y = 0 := dif_neg hb #align pretrivialization.symm_apply_of_not_mem Pretrivialization.symm_apply_of_not_mem theorem coe_symm_of_not_mem (e : Pretrivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet) : (e.symm b : F → E b) = 0 := funext fun _ => dif_neg hb #align pretrivialization.coe_symm_of_not_mem Pretrivialization.coe_symm_of_not_mem theorem mk_symm (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) : TotalSpace.mk b (e.symm b y) = e.toPartialEquiv.symm (b, y) := by simp only [e.symm_apply hb, TotalSpace.mk_cast (e.proj_symm_apply' hb), TotalSpace.eta] #align pretrivialization.mk_symm Pretrivialization.mk_symm theorem symm_proj_apply (e : Pretrivialization F (π F E)) (z : TotalSpace F E) (hz : z.proj ∈ e.baseSet) : e.symm z.proj (e z).2 = z.2 := by rw [e.symm_apply hz, cast_eq_iff_heq, e.mk_proj_snd' hz, e.symm_apply_apply (e.mem_source.mpr hz)] #align pretrivialization.symm_proj_apply Pretrivialization.symm_proj_apply theorem symm_apply_apply_mk (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symm b (e ⟨b, y⟩).2 = y := e.symm_proj_apply ⟨b, y⟩ hb #align pretrivialization.symm_apply_apply_mk Pretrivialization.symm_apply_apply_mk theorem apply_mk_symm (e : Pretrivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) : e ⟨b, e.symm b y⟩ = (b, y) := by rw [e.mk_symm hb, e.apply_symm_apply (e.mk_mem_target.mpr hb)] #align pretrivialization.apply_mk_symm Pretrivialization.apply_mk_symm end Zero end Pretrivialization variable [TopologicalSpace Z] [TopologicalSpace (TotalSpace F E)] /-- A structure extending partial homeomorphisms, defining a local trivialization of a projection `proj : Z → B` with fiber `F`, as a partial homeomorphism between `Z` and `B × F` defined between two sets of the form `proj ⁻¹' baseSet` and `baseSet × F`, acting trivially on the first coordinate. -/ -- Porting note (#5171): was @[nolint has_nonempty_instance] structure Trivialization (proj : Z → B) extends PartialHomeomorph Z (B × F) where baseSet : Set B open_baseSet : IsOpen baseSet source_eq : source = proj ⁻¹' baseSet target_eq : target = baseSet ×ˢ univ proj_toFun : ∀ p ∈ source, (toPartialHomeomorph p).1 = proj p #align trivialization Trivialization namespace Trivialization variable {F} variable (e : Trivialization F proj) {x : Z} @[ext] lemma ext' (e e' : Trivialization F proj) (h₁ : e.toPartialHomeomorph = e'.toPartialHomeomorph) (h₂ : e.baseSet = e'.baseSet) : e = e' := by cases e; cases e'; congr #align trivialization.ext Trivialization.ext' /-- Coercion of a trivialization to a function. We don't use `e.toFun` in the `CoeFun` instance because it is actually `e.toPartialEquiv.toFun`, so `simp` will apply lemmas about `toPartialEquiv`. While we may want to switch to this behavior later, doing it mid-port will break a lot of proofs. -/ @[coe] def toFun' : Z → (B × F) := e.toFun /-- Natural identification as a `Pretrivialization`. -/ def toPretrivialization : Pretrivialization F proj := { e with } #align trivialization.to_pretrivialization Trivialization.toPretrivialization instance : CoeFun (Trivialization F proj) fun _ => Z → B × F := ⟨toFun'⟩ instance : Coe (Trivialization F proj) (Pretrivialization F proj) := ⟨toPretrivialization⟩ theorem toPretrivialization_injective : Function.Injective fun e : Trivialization F proj => e.toPretrivialization := fun e e' h => by ext1 exacts [PartialHomeomorph.toPartialEquiv_injective (congr_arg Pretrivialization.toPartialEquiv h), congr_arg Pretrivialization.baseSet h] #align trivialization.to_pretrivialization_injective Trivialization.toPretrivialization_injective @[simp, mfld_simps] theorem coe_coe : ⇑e.toPartialHomeomorph = e := rfl #align trivialization.coe_coe Trivialization.coe_coe @[simp, mfld_simps] theorem coe_fst (ex : x ∈ e.source) : (e x).1 = proj x := e.proj_toFun x ex #align trivialization.coe_fst Trivialization.coe_fst protected theorem eqOn : EqOn (Prod.fst ∘ e) proj e.source := fun _x hx => e.coe_fst hx #align trivialization.eq_on Trivialization.eqOn theorem mem_source : x ∈ e.source ↔ proj x ∈ e.baseSet := by rw [e.source_eq, mem_preimage] #align trivialization.mem_source Trivialization.mem_source theorem coe_fst' (ex : proj x ∈ e.baseSet) : (e x).1 = proj x := e.coe_fst (e.mem_source.2 ex) #align trivialization.coe_fst' Trivialization.coe_fst' theorem mk_proj_snd (ex : x ∈ e.source) : (proj x, (e x).2) = e x := Prod.ext (e.coe_fst ex).symm rfl #align trivialization.mk_proj_snd Trivialization.mk_proj_snd theorem mk_proj_snd' (ex : proj x ∈ e.baseSet) : (proj x, (e x).2) = e x := Prod.ext (e.coe_fst' ex).symm rfl #align trivialization.mk_proj_snd' Trivialization.mk_proj_snd' theorem source_inter_preimage_target_inter (s : Set (B × F)) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.toPartialHomeomorph.source_inter_preimage_target_inter s #align trivialization.source_inter_preimage_target_inter Trivialization.source_inter_preimage_target_inter @[simp, mfld_simps] theorem coe_mk (e : PartialHomeomorph Z (B × F)) (i j k l m) (x : Z) : (Trivialization.mk e i j k l m : Trivialization F proj) x = e x := rfl #align trivialization.coe_mk Trivialization.coe_mk theorem mem_target {x : B × F} : x ∈ e.target ↔ x.1 ∈ e.baseSet := e.toPretrivialization.mem_target #align trivialization.mem_target Trivialization.mem_target theorem map_target {x : B × F} (hx : x ∈ e.target) : e.toPartialHomeomorph.symm x ∈ e.source := e.toPartialHomeomorph.map_target hx #align trivialization.map_target Trivialization.map_target theorem proj_symm_apply {x : B × F} (hx : x ∈ e.target) : proj (e.toPartialHomeomorph.symm x) = x.1 := e.toPretrivialization.proj_symm_apply hx #align trivialization.proj_symm_apply Trivialization.proj_symm_apply theorem proj_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) : proj (e.toPartialHomeomorph.symm (b, x)) = b := e.toPretrivialization.proj_symm_apply' hx #align trivialization.proj_symm_apply' Trivialization.proj_symm_apply' theorem proj_surjOn_baseSet [Nonempty F] : Set.SurjOn proj e.source e.baseSet := e.toPretrivialization.proj_surjOn_baseSet #align trivialization.proj_surj_on_base_set Trivialization.proj_surjOn_baseSet theorem apply_symm_apply {x : B × F} (hx : x ∈ e.target) : e (e.toPartialHomeomorph.symm x) = x := e.toPartialHomeomorph.right_inv hx #align trivialization.apply_symm_apply Trivialization.apply_symm_apply theorem apply_symm_apply' {b : B} {x : F} (hx : b ∈ e.baseSet) : e (e.toPartialHomeomorph.symm (b, x)) = (b, x) := e.toPretrivialization.apply_symm_apply' hx #align trivialization.apply_symm_apply' Trivialization.apply_symm_apply' @[simp, mfld_simps] theorem symm_apply_mk_proj (ex : x ∈ e.source) : e.toPartialHomeomorph.symm (proj x, (e x).2) = x := e.toPretrivialization.symm_apply_mk_proj ex #align trivialization.symm_apply_mk_proj Trivialization.symm_apply_mk_proj theorem symm_trans_source_eq (e e' : Trivialization F proj) : (e.toPartialEquiv.symm.trans e'.toPartialEquiv).source = (e.baseSet ∩ e'.baseSet) ×ˢ univ := Pretrivialization.symm_trans_source_eq e.toPretrivialization e' #align trivialization.symm_trans_source_eq Trivialization.symm_trans_source_eq theorem symm_trans_target_eq (e e' : Trivialization F proj) : (e.toPartialEquiv.symm.trans e'.toPartialEquiv).target = (e.baseSet ∩ e'.baseSet) ×ˢ univ := Pretrivialization.symm_trans_target_eq e.toPretrivialization e' #align trivialization.symm_trans_target_eq Trivialization.symm_trans_target_eq theorem coe_fst_eventuallyEq_proj (ex : x ∈ e.source) : Prod.fst ∘ e =ᶠ[𝓝 x] proj := mem_nhds_iff.2 ⟨e.source, fun _y hy => e.coe_fst hy, e.open_source, ex⟩ #align trivialization.coe_fst_eventually_eq_proj Trivialization.coe_fst_eventuallyEq_proj theorem coe_fst_eventuallyEq_proj' (ex : proj x ∈ e.baseSet) : Prod.fst ∘ e =ᶠ[𝓝 x] proj := e.coe_fst_eventuallyEq_proj (e.mem_source.2 ex) #align trivialization.coe_fst_eventually_eq_proj' Trivialization.coe_fst_eventuallyEq_proj' theorem map_proj_nhds (ex : x ∈ e.source) : map proj (𝓝 x) = 𝓝 (proj x) := by rw [← e.coe_fst ex, ← map_congr (e.coe_fst_eventuallyEq_proj ex), ← map_map, ← e.coe_coe, e.map_nhds_eq ex, map_fst_nhds] #align trivialization.map_proj_nhds Trivialization.map_proj_nhds theorem preimage_subset_source {s : Set B} (hb : s ⊆ e.baseSet) : proj ⁻¹' s ⊆ e.source := fun _p hp => e.mem_source.mpr (hb hp) #align trivialization.preimage_subset_source Trivialization.preimage_subset_source theorem image_preimage_eq_prod_univ {s : Set B} (hb : s ⊆ e.baseSet) : e '' (proj ⁻¹' s) = s ×ˢ univ := Subset.antisymm (image_subset_iff.mpr fun p hp => ⟨(e.proj_toFun p (e.preimage_subset_source hb hp)).symm ▸ hp, trivial⟩) fun p hp => let hp' : p ∈ e.target := e.mem_target.mpr (hb hp.1) ⟨e.invFun p, mem_preimage.mpr ((e.proj_symm_apply hp').symm ▸ hp.1), e.apply_symm_apply hp'⟩ #align trivialization.image_preimage_eq_prod_univ Trivialization.image_preimage_eq_prod_univ theorem tendsto_nhds_iff {α : Type*} {l : Filter α} {f : α → Z} {z : Z} (hz : z ∈ e.source) : Tendsto f l (𝓝 z) ↔ Tendsto (proj ∘ f) l (𝓝 (proj z)) ∧ Tendsto (fun x ↦ (e (f x)).2) l (𝓝 (e z).2) := by rw [e.nhds_eq_comap_inf_principal hz, tendsto_inf, tendsto_comap_iff, Prod.tendsto_iff, coe_coe, tendsto_principal, coe_fst _ hz] by_cases hl : ∀ᶠ x in l, f x ∈ e.source · simp only [hl, and_true] refine (tendsto_congr' ?_).and Iff.rfl exact hl.mono fun x ↦ e.coe_fst · simp only [hl, and_false, false_iff, not_and] rw [e.source_eq] at hl hz exact fun h _ ↦ hl <| h <| e.open_baseSet.mem_nhds hz theorem nhds_eq_inf_comap {z : Z} (hz : z ∈ e.source) : 𝓝 z = comap proj (𝓝 (proj z)) ⊓ comap (Prod.snd ∘ e) (𝓝 (e z).2) := by refine eq_of_forall_le_iff fun l ↦ ?_ rw [le_inf_iff, ← tendsto_iff_comap, ← tendsto_iff_comap] exact e.tendsto_nhds_iff hz /-- The preimage of a subset of the base set is homeomorphic to the product with the fiber. -/ def preimageHomeomorph {s : Set B} (hb : s ⊆ e.baseSet) : proj ⁻¹' s ≃ₜ s × F := (e.toPartialHomeomorph.homeomorphOfImageSubsetSource (e.preimage_subset_source hb) (e.image_preimage_eq_prod_univ hb)).trans ((Homeomorph.Set.prod s univ).trans ((Homeomorph.refl s).prodCongr (Homeomorph.Set.univ F))) #align trivialization.preimage_homeomorph Trivialization.preimageHomeomorph @[simp] theorem preimageHomeomorph_apply {s : Set B} (hb : s ⊆ e.baseSet) (p : proj ⁻¹' s) : e.preimageHomeomorph hb p = (⟨proj p, p.2⟩, (e p).2) := Prod.ext (Subtype.ext (e.proj_toFun p (e.mem_source.mpr (hb p.2)))) rfl #align trivialization.preimage_homeomorph_apply Trivialization.preimageHomeomorph_apply @[simp] theorem preimageHomeomorph_symm_apply {s : Set B} (hb : s ⊆ e.baseSet) (p : s × F) : (e.preimageHomeomorph hb).symm p = ⟨e.symm (p.1, p.2), ((e.preimageHomeomorph hb).symm p).2⟩ := rfl #align trivialization.preimage_homeomorph_symm_apply Trivialization.preimageHomeomorph_symm_apply /-- The source is homeomorphic to the product of the base set with the fiber. -/ def sourceHomeomorphBaseSetProd : e.source ≃ₜ e.baseSet × F := (Homeomorph.setCongr e.source_eq).trans (e.preimageHomeomorph subset_rfl) #align trivialization.source_homeomorph_base_set_prod Trivialization.sourceHomeomorphBaseSetProd @[simp] theorem sourceHomeomorphBaseSetProd_apply (p : e.source) : e.sourceHomeomorphBaseSetProd p = (⟨proj p, e.mem_source.mp p.2⟩, (e p).2) := e.preimageHomeomorph_apply subset_rfl ⟨p, e.mem_source.mp p.2⟩ #align trivialization.source_homeomorph_base_set_prod_apply Trivialization.sourceHomeomorphBaseSetProd_apply @[simp] theorem sourceHomeomorphBaseSetProd_symm_apply (p : e.baseSet × F) : e.sourceHomeomorphBaseSetProd.symm p = ⟨e.symm (p.1, p.2), (e.sourceHomeomorphBaseSetProd.symm p).2⟩ := rfl #align trivialization.source_homeomorph_base_set_prod_symm_apply Trivialization.sourceHomeomorphBaseSetProd_symm_apply /-- Each fiber of a trivialization is homeomorphic to the specified fiber. -/ def preimageSingletonHomeomorph {b : B} (hb : b ∈ e.baseSet) : proj ⁻¹' {b} ≃ₜ F := .trans (e.preimageHomeomorph (Set.singleton_subset_iff.mpr hb)) <| .trans (.prodCongr (Homeomorph.homeomorphOfUnique ({b} : Set B) PUnit.{1}) (Homeomorph.refl F)) (Homeomorph.punitProd F) #align trivialization.preimage_singleton_homeomorph Trivialization.preimageSingletonHomeomorph @[simp] theorem preimageSingletonHomeomorph_apply {b : B} (hb : b ∈ e.baseSet) (p : proj ⁻¹' {b}) : e.preimageSingletonHomeomorph hb p = (e p).2 := rfl #align trivialization.preimage_singleton_homeomorph_apply Trivialization.preimageSingletonHomeomorph_apply @[simp] theorem preimageSingletonHomeomorph_symm_apply {b : B} (hb : b ∈ e.baseSet) (p : F) : (e.preimageSingletonHomeomorph hb).symm p = ⟨e.symm (b, p), by rw [mem_preimage, e.proj_symm_apply' hb, mem_singleton_iff]⟩ := rfl #align trivialization.preimage_singleton_homeomorph_symm_apply Trivialization.preimageSingletonHomeomorph_symm_apply /-- In the domain of a bundle trivialization, the projection is continuous-/ theorem continuousAt_proj (ex : x ∈ e.source) : ContinuousAt proj x := (e.map_proj_nhds ex).le #align trivialization.continuous_at_proj Trivialization.continuousAt_proj /-- Composition of a `Trivialization` and a `Homeomorph`. -/ protected def compHomeomorph {Z' : Type*} [TopologicalSpace Z'] (h : Z' ≃ₜ Z) : Trivialization F (proj ∘ h) where toPartialHomeomorph := h.toPartialHomeomorph.trans e.toPartialHomeomorph baseSet := e.baseSet open_baseSet := e.open_baseSet source_eq := by simp [source_eq, preimage_preimage, (· ∘ ·)] target_eq := by simp [target_eq] proj_toFun p hp := by have hp : h p ∈ e.source := by simpa using hp simp [hp] #align trivialization.comp_homeomorph Trivialization.compHomeomorph /-- Read off the continuity of a function `f : Z → X` at `z : Z` by transferring via a trivialization of `Z` containing `z`. -/ theorem continuousAt_of_comp_right {X : Type*} [TopologicalSpace X] {f : Z → X} {z : Z} (e : Trivialization F proj) (he : proj z ∈ e.baseSet) (hf : ContinuousAt (f ∘ e.toPartialEquiv.symm) (e z)) : ContinuousAt f z := by have hez : z ∈ e.toPartialEquiv.symm.target := by rw [PartialEquiv.symm_target, e.mem_source] exact he rwa [e.toPartialHomeomorph.symm.continuousAt_iff_continuousAt_comp_right hez, PartialHomeomorph.symm_symm] #align trivialization.continuous_at_of_comp_right Trivialization.continuousAt_of_comp_right /-- Read off the continuity of a function `f : X → Z` at `x : X` by transferring via a trivialization of `Z` containing `f x`. -/ theorem continuousAt_of_comp_left {X : Type*} [TopologicalSpace X] {f : X → Z} {x : X} (e : Trivialization F proj) (hf_proj : ContinuousAt (proj ∘ f) x) (he : proj (f x) ∈ e.baseSet) (hf : ContinuousAt (e ∘ f) x) : ContinuousAt f x := by rw [e.continuousAt_iff_continuousAt_comp_left] · exact hf rw [e.source_eq, ← preimage_comp] exact hf_proj.preimage_mem_nhds (e.open_baseSet.mem_nhds he) #align trivialization.continuous_at_of_comp_left Trivialization.continuousAt_of_comp_left variable (e' : Trivialization F (π F E)) {x' : TotalSpace F E} {b : B} {y : E b} protected theorem continuousOn : ContinuousOn e' e'.source := e'.continuousOn_toFun #align trivialization.continuous_on Trivialization.continuousOn theorem coe_mem_source : ↑y ∈ e'.source ↔ b ∈ e'.baseSet := e'.mem_source #align trivialization.coe_mem_source Trivialization.coe_mem_source @[deprecated PartialHomeomorph.open_target] theorem open_target' : IsOpen e'.target := e'.open_target #align trivialization.open_target Trivialization.open_target' @[simp, mfld_simps] theorem coe_coe_fst (hb : b ∈ e'.baseSet) : (e' y).1 = b := e'.coe_fst (e'.mem_source.2 hb) #align trivialization.coe_coe_fst Trivialization.coe_coe_fst theorem mk_mem_target {y : F} : (b, y) ∈ e'.target ↔ b ∈ e'.baseSet := e'.toPretrivialization.mem_target #align trivialization.mk_mem_target Trivialization.mk_mem_target theorem symm_apply_apply {x : TotalSpace F E} (hx : x ∈ e'.source) : e'.toPartialHomeomorph.symm (e' x) = x := e'.toPartialEquiv.left_inv hx #align trivialization.symm_apply_apply Trivialization.symm_apply_apply @[simp, mfld_simps] theorem symm_coe_proj {x : B} {y : F} (e : Trivialization F (π F E)) (h : x ∈ e.baseSet) : (e.toPartialHomeomorph.symm (x, y)).1 = x := e.proj_symm_apply' h #align trivialization.symm_coe_proj Trivialization.symm_coe_proj section Zero variable [∀ x, Zero (E x)] /-- A fiberwise inverse to `e'`. The function `F → E x` that induces a local inverse `B × F → TotalSpace F E` of `e'` on `e'.baseSet`. It is defined to be `0` outside `e'.baseSet`. -/ protected noncomputable def symm (e : Trivialization F (π F E)) (b : B) (y : F) : E b := e.toPretrivialization.symm b y #align trivialization.symm Trivialization.symm theorem symm_apply (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) : e.symm b y = cast (congr_arg E (e.symm_coe_proj hb)) (e.toPartialHomeomorph.symm (b, y)).2 := dif_pos hb #align trivialization.symm_apply Trivialization.symm_apply theorem symm_apply_of_not_mem (e : Trivialization F (π F E)) {b : B} (hb : b ∉ e.baseSet) (y : F) : e.symm b y = 0 := dif_neg hb #align trivialization.symm_apply_of_not_mem Trivialization.symm_apply_of_not_mem theorem mk_symm (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) : TotalSpace.mk b (e.symm b y) = e.toPartialHomeomorph.symm (b, y) := e.toPretrivialization.mk_symm hb y #align trivialization.mk_symm Trivialization.mk_symm theorem symm_proj_apply (e : Trivialization F (π F E)) (z : TotalSpace F E) (hz : z.proj ∈ e.baseSet) : e.symm z.proj (e z).2 = z.2 := e.toPretrivialization.symm_proj_apply z hz #align trivialization.symm_proj_apply Trivialization.symm_proj_apply theorem symm_apply_apply_mk (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : E b) : e.symm b (e ⟨b, y⟩).2 = y := e.symm_proj_apply ⟨b, y⟩ hb #align trivialization.symm_apply_apply_mk Trivialization.symm_apply_apply_mk theorem apply_mk_symm (e : Trivialization F (π F E)) {b : B} (hb : b ∈ e.baseSet) (y : F) : e ⟨b, e.symm b y⟩ = (b, y) := e.toPretrivialization.apply_mk_symm hb y #align trivialization.apply_mk_symm Trivialization.apply_mk_symm theorem continuousOn_symm (e : Trivialization F (π F E)) : ContinuousOn (fun z : B × F => TotalSpace.mk' F z.1 (e.symm z.1 z.2)) (e.baseSet ×ˢ univ) := by have : ∀ z ∈ e.baseSet ×ˢ (univ : Set F), TotalSpace.mk z.1 (e.symm z.1 z.2) = e.toPartialHomeomorph.symm z := by rintro x ⟨hx : x.1 ∈ e.baseSet, _⟩ rw [e.mk_symm hx] refine ContinuousOn.congr ?_ this rw [← e.target_eq] exact e.toPartialHomeomorph.continuousOn_symm #align trivialization.continuous_on_symm Trivialization.continuousOn_symm end Zero /-- If `e` is a `Trivialization` of `proj : Z → B` with fiber `F` and `h` is a homeomorphism `F ≃ₜ F'`, then `e.trans_fiber_homeomorph h` is the trivialization of `proj` with the fiber `F'` that sends `p : Z` to `((e p).1, h (e p).2)`. -/ def transFiberHomeomorph {F' : Type*} [TopologicalSpace F'] (e : Trivialization F proj) (h : F ≃ₜ F') : Trivialization F' proj where toPartialHomeomorph := e.toPartialHomeomorph.transHomeomorph <| (Homeomorph.refl _).prodCongr h baseSet := e.baseSet open_baseSet := e.open_baseSet source_eq := e.source_eq target_eq := by simp [target_eq, prod_univ, preimage_preimage] proj_toFun := e.proj_toFun #align trivialization.trans_fiber_homeomorph Trivialization.transFiberHomeomorph @[simp] theorem transFiberHomeomorph_apply {F' : Type*} [TopologicalSpace F'] (e : Trivialization F proj) (h : F ≃ₜ F') (x : Z) : e.transFiberHomeomorph h x = ((e x).1, h (e x).2) := rfl #align trivialization.trans_fiber_homeomorph_apply Trivialization.transFiberHomeomorph_apply /-- Coordinate transformation in the fiber induced by a pair of bundle trivializations. See also `Trivialization.coordChangeHomeomorph` for a version bundled as `F ≃ₜ F`. -/ def coordChange (e₁ e₂ : Trivialization F proj) (b : B) (x : F) : F := (e₂ <| e₁.toPartialHomeomorph.symm (b, x)).2 #align trivialization.coord_change Trivialization.coordChange theorem mk_coordChange (e₁ e₂ : Trivialization F proj) {b : B} (h₁ : b ∈ e₁.baseSet) (h₂ : b ∈ e₂.baseSet) (x : F) : (b, e₁.coordChange e₂ b x) = e₂ (e₁.toPartialHomeomorph.symm (b, x)) := by refine Prod.ext ?_ rfl rw [e₂.coe_fst', ← e₁.coe_fst', e₁.apply_symm_apply' h₁] · rwa [e₁.proj_symm_apply' h₁] · rwa [e₁.proj_symm_apply' h₁] #align trivialization.mk_coord_change Trivialization.mk_coordChange
Mathlib/Topology/FiberBundle/Trivialization.lean
696
698
theorem coordChange_apply_snd (e₁ e₂ : Trivialization F proj) {p : Z} (h : proj p ∈ e₁.baseSet) : e₁.coordChange e₂ (proj p) (e₁ p).snd = (e₂ p).snd := by
rw [coordChange, e₁.symm_apply_mk_proj (e₁.mem_source.2 h)]
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.NumberTheory.Zsqrtd.Basic import Mathlib.RingTheory.PrincipalIdealDomain import Mathlib.Data.Complex.Basic import Mathlib.Data.Real.Archimedean #align_import number_theory.zsqrtd.gaussian_int from "leanprover-community/mathlib"@"5b2fe80501ff327b9109fb09b7cc8c325cd0d7d9" /-! # Gaussian integers The Gaussian integers are complex integer, complex numbers whose real and imaginary parts are both integers. ## Main definitions The Euclidean domain structure on `ℤ[i]` is defined in this file. The homomorphism `GaussianInt.toComplex` into the complex numbers is also defined in this file. ## See also See `NumberTheory.Zsqrtd.QuadraticReciprocity` for: * `prime_iff_mod_four_eq_three_of_nat_prime`: A prime natural number is prime in `ℤ[i]` if and only if it is `3` mod `4` ## Notations This file uses the local notation `ℤ[i]` for `GaussianInt` ## Implementation notes Gaussian integers are implemented using the more general definition `Zsqrtd`, the type of integers adjoined a square root of `d`, in this case `-1`. The definition is reducible, so that properties and definitions about `Zsqrtd` can easily be used. -/ open Zsqrtd Complex open scoped ComplexConjugate /-- The Gaussian integers, defined as `ℤ√(-1)`. -/ abbrev GaussianInt : Type := Zsqrtd (-1) #align gaussian_int GaussianInt local notation "ℤ[i]" => GaussianInt namespace GaussianInt instance : Repr ℤ[i] := ⟨fun x _ => "⟨" ++ repr x.re ++ ", " ++ repr x.im ++ "⟩"⟩ instance instCommRing : CommRing ℤ[i] := Zsqrtd.commRing #align gaussian_int.comm_ring GaussianInt.instCommRing section attribute [-instance] Complex.instField -- Avoid making things noncomputable unnecessarily. /-- The embedding of the Gaussian integers into the complex numbers, as a ring homomorphism. -/ def toComplex : ℤ[i] →+* ℂ := Zsqrtd.lift ⟨I, by simp⟩ #align gaussian_int.to_complex GaussianInt.toComplex end instance : Coe ℤ[i] ℂ := ⟨toComplex⟩ theorem toComplex_def (x : ℤ[i]) : (x : ℂ) = x.re + x.im * I := rfl #align gaussian_int.to_complex_def GaussianInt.toComplex_def theorem toComplex_def' (x y : ℤ) : ((⟨x, y⟩ : ℤ[i]) : ℂ) = x + y * I := by simp [toComplex_def] #align gaussian_int.to_complex_def' GaussianInt.toComplex_def' theorem toComplex_def₂ (x : ℤ[i]) : (x : ℂ) = ⟨x.re, x.im⟩ := by apply Complex.ext <;> simp [toComplex_def] #align gaussian_int.to_complex_def₂ GaussianInt.toComplex_def₂ @[simp] theorem to_real_re (x : ℤ[i]) : ((x.re : ℤ) : ℝ) = (x : ℂ).re := by simp [toComplex_def] #align gaussian_int.to_real_re GaussianInt.to_real_re @[simp]
Mathlib/NumberTheory/Zsqrtd/GaussianInt.lean
93
93
theorem to_real_im (x : ℤ[i]) : ((x.im : ℤ) : ℝ) = (x : ℂ).im := by
simp [toComplex_def]
/- Copyright (c) 2022 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Batteries.Data.RBMap.Basic import Batteries.Tactic.SeqFocus /-! # Lemmas for Red-black trees The main theorem in this file is `WF_def`, which shows that the `RBNode.WF.mk` constructor subsumes the others, by showing that `insert` and `erase` satisfy the red-black invariants. -/ namespace Batteries namespace RBNode open RBColor attribute [simp] All theorem All.trivial (H : ∀ {x : α}, p x) : ∀ {t : RBNode α}, t.All p | nil => _root_.trivial | node .. => ⟨H, All.trivial H, All.trivial H⟩ theorem All_and {t : RBNode α} : t.All (fun a => p a ∧ q a) ↔ t.All p ∧ t.All q := by induction t <;> simp [*, and_assoc, and_left_comm] protected theorem cmpLT.flip (h₁ : cmpLT cmp x y) : cmpLT (flip cmp) y x := ⟨have : TransCmp cmp := inferInstanceAs (TransCmp (flip (flip cmp))); h₁.1⟩ theorem cmpLT.trans (h₁ : cmpLT cmp x y) (h₂ : cmpLT cmp y z) : cmpLT cmp x z := ⟨TransCmp.lt_trans h₁.1 h₂.1⟩ theorem cmpLT.trans_l {cmp x y} (H : cmpLT cmp x y) {t : RBNode α} (h : t.All (cmpLT cmp y ·)) : t.All (cmpLT cmp x ·) := h.imp fun h => H.trans h theorem cmpLT.trans_r {cmp x y} (H : cmpLT cmp x y) {a : RBNode α} (h : a.All (cmpLT cmp · x)) : a.All (cmpLT cmp · y) := h.imp fun h => h.trans H theorem cmpEq.lt_congr_left (H : cmpEq cmp x y) : cmpLT cmp x z ↔ cmpLT cmp y z := ⟨fun ⟨h⟩ => ⟨TransCmp.cmp_congr_left H.1 ▸ h⟩, fun ⟨h⟩ => ⟨TransCmp.cmp_congr_left H.1 ▸ h⟩⟩ theorem cmpEq.lt_congr_right (H : cmpEq cmp y z) : cmpLT cmp x y ↔ cmpLT cmp x z := ⟨fun ⟨h⟩ => ⟨TransCmp.cmp_congr_right H.1 ▸ h⟩, fun ⟨h⟩ => ⟨TransCmp.cmp_congr_right H.1 ▸ h⟩⟩ @[simp] theorem reverse_reverse (t : RBNode α) : t.reverse.reverse = t := by induction t <;> simp [*] theorem reverse_eq_iff {t t' : RBNode α} : t.reverse = t' ↔ t = t'.reverse := by constructor <;> rintro rfl <;> simp @[simp] theorem reverse_balance1 (l : RBNode α) (v : α) (r : RBNode α) : (balance1 l v r).reverse = balance2 r.reverse v l.reverse := by unfold balance1 balance2; split <;> simp · rw [balance2.match_1.eq_2]; simp [reverse_eq_iff]; intros; solve_by_elim · rw [balance2.match_1.eq_3] <;> (simp [reverse_eq_iff]; intros; solve_by_elim) @[simp] theorem reverse_balance2 (l : RBNode α) (v : α) (r : RBNode α) : (balance2 l v r).reverse = balance1 r.reverse v l.reverse := by refine Eq.trans ?_ (reverse_reverse _); rw [reverse_balance1]; simp @[simp] theorem All.reverse {t : RBNode α} : t.reverse.All p ↔ t.All p := by induction t <;> simp [*, and_comm] /-- The `reverse` function reverses the ordering invariants. -/ protected theorem Ordered.reverse : ∀ {t : RBNode α}, t.Ordered cmp → t.reverse.Ordered (flip cmp) | .nil, _ => ⟨⟩ | .node .., ⟨lv, vr, hl, hr⟩ => ⟨(All.reverse.2 vr).imp cmpLT.flip, (All.reverse.2 lv).imp cmpLT.flip, hr.reverse, hl.reverse⟩ protected theorem Balanced.reverse {t : RBNode α} : t.Balanced c n → t.reverse.Balanced c n | .nil => .nil | .black hl hr => .black hr.reverse hl.reverse | .red hl hr => .red hr.reverse hl.reverse /-- The `balance1` function preserves the ordering invariants. -/ protected theorem Ordered.balance1 {l : RBNode α} {v : α} {r : RBNode α} (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·)) (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balance1 l v r).Ordered cmp := by unfold balance1; split · next a x b y c => have ⟨yv, _, cv⟩ := lv; have ⟨xy, yc, hx, hc⟩ := hl exact ⟨xy, ⟨yv, yc, yv.trans_l vr⟩, hx, cv, vr, hc, hr⟩ · next a x b y c _ => have ⟨_, _, yv, _, cv⟩ := lv; have ⟨ax, ⟨xy, xb, _⟩, ha, by_, yc, hb, hc⟩ := hl exact ⟨⟨xy, xy.trans_r ax, by_⟩, ⟨yv, yc, yv.trans_l vr⟩, ⟨ax, xb, ha, hb⟩, cv, vr, hc, hr⟩ · exact ⟨lv, vr, hl, hr⟩ @[simp] theorem balance1_All {l : RBNode α} {v : α} {r : RBNode α} : (balance1 l v r).All p ↔ p v ∧ l.All p ∧ r.All p := by unfold balance1; split <;> simp [and_assoc, and_left_comm] /-- The `balance2` function preserves the ordering invariants. -/ protected theorem Ordered.balance2 {l : RBNode α} {v : α} {r : RBNode α} (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·)) (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balance2 l v r).Ordered cmp := by rw [← reverse_reverse (balance2 ..), reverse_balance2] exact .reverse <| hr.reverse.balance1 ((All.reverse.2 vr).imp cmpLT.flip) ((All.reverse.2 lv).imp cmpLT.flip) hl.reverse @[simp] theorem balance2_All {l : RBNode α} {v : α} {r : RBNode α} : (balance2 l v r).All p ↔ p v ∧ l.All p ∧ r.All p := by unfold balance2; split <;> simp [and_assoc, and_left_comm] @[simp] theorem reverse_setBlack {t : RBNode α} : (setBlack t).reverse = setBlack t.reverse := by unfold setBlack; split <;> simp protected theorem Ordered.setBlack {t : RBNode α} : (setBlack t).Ordered cmp ↔ t.Ordered cmp := by unfold setBlack; split <;> simp [Ordered] protected theorem Balanced.setBlack : t.Balanced c n → ∃ n', (setBlack t).Balanced black n' | .nil => ⟨_, .nil⟩ | .black hl hr | .red hl hr => ⟨_, hl.black hr⟩ theorem setBlack_idem {t : RBNode α} : t.setBlack.setBlack = t.setBlack := by cases t <;> rfl @[simp] theorem reverse_ins [inst : @OrientedCmp α cmp] {t : RBNode α} : (ins cmp x t).reverse = ins (flip cmp) x t.reverse := by induction t <;> [skip; (rename_i c a y b iha ihb; cases c)] <;> simp [ins, flip] <;> rw [← inst.symm x y] <;> split <;> simp [*, Ordering.swap, iha, ihb] protected theorem All.ins {x : α} {t : RBNode α} (h₁ : p x) (h₂ : t.All p) : (ins cmp x t).All p := by induction t <;> unfold ins <;> try simp [*] split <;> cases ‹_=_› <;> split <;> simp at h₂ <;> simp [*] /-- The `ins` function preserves the ordering invariants. -/ protected theorem Ordered.ins : ∀ {t : RBNode α}, t.Ordered cmp → (ins cmp x t).Ordered cmp | nil, _ => ⟨⟨⟩, ⟨⟩, ⟨⟩, ⟨⟩⟩ | node red a y b, ⟨ay, yb, ha, hb⟩ => by unfold ins; split · next h => exact ⟨ay.ins ⟨h⟩, yb, ha.ins, hb⟩ · next h => exact ⟨ay, yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩, ha, hb.ins⟩ · next h => exact (⟨ ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩, yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩) | node black a y b, ⟨ay, yb, ha, hb⟩ => by unfold ins; split · next h => exact ha.ins.balance1 (ay.ins ⟨h⟩) yb hb · next h => exact ha.balance2 ay (yb.ins ⟨OrientedCmp.cmp_eq_gt.1 h⟩) hb.ins · next h => exact (⟨ ay.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_right h).trans h'⟩, yb.imp fun ⟨h'⟩ => ⟨(TransCmp.cmp_congr_left h).trans h'⟩, ha, hb⟩) @[simp] theorem isRed_reverse {t : RBNode α} : t.reverse.isRed = t.isRed := by cases t <;> simp [isRed] @[simp] theorem reverse_insert [inst : @OrientedCmp α cmp] {t : RBNode α} : (insert cmp t x).reverse = insert (flip cmp) t.reverse x := by simp [insert] <;> split <;> simp theorem insert_setBlack {t : RBNode α} : (t.insert cmp v).setBlack = (t.ins cmp v).setBlack := by unfold insert; split <;> simp [setBlack_idem] /-- The `insert` function preserves the ordering invariants. -/ protected theorem Ordered.insert (h : t.Ordered cmp) : (insert cmp t v).Ordered cmp := by unfold RBNode.insert; split <;> simp [Ordered.setBlack, h.ins (x := v)] /-- The red-red invariant is a weakening of the red-black balance invariant which allows the root to be red with red children, but does not allow any other violations. It occurs as a temporary condition in the `insert` and `erase` functions. The `p` parameter allows the `.redred` case to be dependent on an additional condition. If it is false, then this is equivalent to the usual red-black invariant. -/ inductive RedRed (p : Prop) : RBNode α → Nat → Prop where /-- A balanced tree has the red-red invariant. -/ | balanced : Balanced t c n → RedRed p t n /-- A red node with balanced red children has the red-red invariant (if `p` is true). -/ | redred : p → Balanced a c₁ n → Balanced b c₂ n → RedRed p (node red a x b) n /-- When `p` is false, the red-red case is impossible so the tree is balanced. -/ protected theorem RedRed.of_false (h : ¬p) : RedRed p t n → ∃ c, Balanced t c n | .balanced h => ⟨_, h⟩ | .redred hp .. => nomatch h hp /-- A `red` node with the red-red invariant has balanced children. -/ protected theorem RedRed.of_red : RedRed p (node red a x b) n → ∃ c₁ c₂, Balanced a c₁ n ∧ Balanced b c₂ n | .balanced (.red ha hb) | .redred _ ha hb => ⟨_, _, ha, hb⟩ /-- The red-red invariant is monotonic in `p`. -/ protected theorem RedRed.imp (h : p → q) : RedRed p t n → RedRed q t n | .balanced h => .balanced h | .redred hp ha hb => .redred (h hp) ha hb protected theorem RedRed.reverse : RedRed p t n → RedRed p t.reverse n | .balanced h => .balanced h.reverse | .redred hp ha hb => .redred hp hb.reverse ha.reverse /-- If `t` has the red-red invariant, then setting the root to black yields a balanced tree. -/ protected theorem RedRed.setBlack : t.RedRed p n → ∃ n', (setBlack t).Balanced black n' | .balanced h => h.setBlack | .redred _ hl hr => ⟨_, hl.black hr⟩ /-- The `balance1` function repairs the balance invariant when the first argument is red-red. -/ protected theorem RedRed.balance1 {l : RBNode α} {v : α} {r : RBNode α} (hl : l.RedRed p n) (hr : r.Balanced c n) : ∃ c, (balance1 l v r).Balanced c (n + 1) := by unfold balance1; split · have .redred _ (.red ha hb) hc := hl; exact ⟨_, .red (.black ha hb) (.black hc hr)⟩ · have .redred _ ha (.red hb hc) := hl; exact ⟨_, .red (.black ha hb) (.black hc hr)⟩ · next H1 H2 => match hl with | .balanced hl => exact ⟨_, .black hl hr⟩ | .redred _ (c₁ := black) (c₂ := black) ha hb => exact ⟨_, .black (.red ha hb) hr⟩ | .redred _ (c₁ := red) (.red ..) _ => cases H1 _ _ _ _ _ rfl | .redred _ (c₂ := red) _ (.red ..) => cases H2 _ _ _ _ _ rfl /-- The `balance2` function repairs the balance invariant when the second argument is red-red. -/ protected theorem RedRed.balance2 {l : RBNode α} {v : α} {r : RBNode α} (hl : l.Balanced c n) (hr : r.RedRed p n) : ∃ c, (balance2 l v r).Balanced c (n + 1) := (hr.reverse.balance1 hl.reverse (v := v)).imp fun _ h => by simpa using h.reverse /-- The `balance1` function does nothing if the first argument is already balanced. -/ theorem balance1_eq {l : RBNode α} {v : α} {r : RBNode α} (hl : l.Balanced c n) : balance1 l v r = node black l v r := by unfold balance1; split <;> first | rfl | nomatch hl /-- The `balance2` function does nothing if the second argument is already balanced. -/ theorem balance2_eq {l : RBNode α} {v : α} {r : RBNode α} (hr : r.Balanced c n) : balance2 l v r = node black l v r := (reverse_reverse _).symm.trans <| by simp [balance1_eq hr.reverse] /-! ## insert -/ /-- The balance invariant of the `ins` function. The result of inserting into the tree either yields a balanced tree, or a tree which is almost balanced except that it has a red-red violation at the root. -/ protected theorem Balanced.ins (cmp v) {t : RBNode α} (h : t.Balanced c n) : (ins cmp v t).RedRed (t.isRed = red) n := by induction h with | nil => exact .balanced (.red .nil .nil) | @red a n b x hl hr ihl ihr => unfold ins; split · match ins cmp v a, ihl with | _, .balanced .nil => exact .balanced (.red .nil hr) | _, .balanced (.red ha hb) => exact .redred rfl (.red ha hb) hr | _, .balanced (.black ha hb) => exact .balanced (.red (.black ha hb) hr) | _, .redred h .. => cases hl <;> cases h · match ins cmp v b, ihr with | _, .balanced .nil => exact .balanced (.red hl .nil) | _, .balanced (.red ha hb) => exact .redred rfl hl (.red ha hb) | _, .balanced (.black ha hb) => exact .balanced (.red hl (.black ha hb)) | _, .redred h .. => cases hr <;> cases h · exact .balanced (.red hl hr) | @black a ca n b cb x hl hr ihl ihr => unfold ins; split · exact have ⟨c, h⟩ := ihl.balance1 hr; .balanced h · exact have ⟨c, h⟩ := ihr.balance2 hl; .balanced h · exact .balanced (.black hl hr) /-- The `insert` function is balanced if the input is balanced. (We lose track of both the color and the black-height of the result, so this is only suitable for use on the root of the tree.) -/ theorem Balanced.insert {t : RBNode α} (h : t.Balanced c n) : ∃ c' n', (insert cmp t v).Balanced c' n' := by unfold insert; match ins cmp v t, h.ins cmp v with | _, .balanced h => split <;> [exact ⟨_, h.setBlack⟩; exact ⟨_, _, h⟩] | _, .redred _ ha hb => have .node red .. := t; exact ⟨_, _, .black ha hb⟩ @[simp] theorem reverse_setRed {t : RBNode α} : (setRed t).reverse = setRed t.reverse := by unfold setRed; split <;> simp protected theorem All.setRed {t : RBNode α} (h : t.All p) : (setRed t).All p := by unfold setRed; split <;> simp_all /-- The `setRed` function preserves the ordering invariants. -/ protected theorem Ordered.setRed {t : RBNode α} : (setRed t).Ordered cmp ↔ t.Ordered cmp := by unfold setRed; split <;> simp [Ordered] @[simp] theorem reverse_balLeft (l : RBNode α) (v : α) (r : RBNode α) : (balLeft l v r).reverse = balRight r.reverse v l.reverse := by unfold balLeft balRight; split · simp · rw [balLeft.match_2.eq_2 _ _ _ _ (by simp [reverse_eq_iff]; intros; solve_by_elim)] split <;> simp rw [balRight.match_1.eq_3] <;> (simp [reverse_eq_iff]; intros; solve_by_elim) @[simp] theorem reverse_balRight (l : RBNode α) (v : α) (r : RBNode α) : (balRight l v r).reverse = balLeft r.reverse v l.reverse := by rw [← reverse_reverse (balLeft ..)]; simp protected theorem All.balLeft (hl : l.All p) (hv : p v) (hr : r.All p) : (balLeft l v r).All p := by unfold balLeft; split <;> (try simp_all); split <;> simp_all [All.setRed] /-- The `balLeft` function preserves the ordering invariants. -/ protected theorem Ordered.balLeft {l : RBNode α} {v : α} {r : RBNode α} (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·)) (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balLeft l v r).Ordered cmp := by unfold balLeft; split · exact ⟨lv, vr, hl, hr⟩ split · exact hl.balance2 lv vr hr · have ⟨vy, va, _⟩ := vr.2.1; have ⟨⟨yz, _, bz⟩, zc, ⟨ay, yb, ha, hb⟩, hc⟩ := hr exact ⟨⟨vy, vy.trans_r lv, ay⟩, balance2_All.2 ⟨yz, yb, (yz.trans_l zc).setRed⟩, ⟨lv, va, hl, ha⟩, hb.balance2 bz zc.setRed (Ordered.setRed.2 hc)⟩ · exact ⟨lv, vr, hl, hr⟩ /-- The balancing properties of the `balLeft` function. -/ protected theorem Balanced.balLeft (hl : l.RedRed True n) (hr : r.Balanced cr (n + 1)) : (balLeft l v r).RedRed (cr = red) (n + 1) := by unfold balLeft; split · next a x b => exact let ⟨ca, cb, ha, hb⟩ := hl.of_red match cr with | red => .redred rfl (.black ha hb) hr | black => .balanced (.red (.black ha hb) hr) · next H => exact match hl with | .redred .. => nomatch H _ _ _ rfl | .balanced hl => match hr with | .black ha hb => let ⟨c, h⟩ := RedRed.balance2 hl (.redred trivial ha hb); .balanced h | .red (.black ha hb) (.black hc hd) => let ⟨c, h⟩ := RedRed.balance2 hb (.redred trivial hc hd); .redred rfl (.black hl ha) h protected theorem All.balRight (hl : l.All p) (hv : p v) (hr : r.All p) : (balRight l v r).All p := All.reverse.1 <| reverse_balRight .. ▸ (All.reverse.2 hr).balLeft hv (All.reverse.2 hl) /-- The `balRight` function preserves the ordering invariants. -/ protected theorem Ordered.balRight {l : RBNode α} {v : α} {r : RBNode α} (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·)) (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (balRight l v r).Ordered cmp := by rw [← reverse_reverse (balRight ..), reverse_balRight] exact .reverse <| hr.reverse.balLeft ((All.reverse.2 vr).imp cmpLT.flip) ((All.reverse.2 lv).imp cmpLT.flip) hl.reverse /-- The balancing properties of the `balRight` function. -/ protected theorem Balanced.balRight (hl : l.Balanced cl (n + 1)) (hr : r.RedRed True n) : (balRight l v r).RedRed (cl = red) (n + 1) := by rw [← reverse_reverse (balRight ..), reverse_balRight] exact .reverse <| hl.reverse.balLeft hr.reverse -- note: reverse_append is false! protected theorem All.append (hl : l.All p) (hr : r.All p) : (append l r).All p := by unfold append; split <;> try simp [*] · have ⟨hx, ha, hb⟩ := hl; have ⟨hy, hc, hd⟩ := hr have := hb.append hc; split <;> simp_all · have ⟨hx, ha, hb⟩ := hl; have ⟨hy, hc, hd⟩ := hr have := hb.append hc; split <;> simp_all [All.balLeft] · simp_all [hl.append hr.2.1] · simp_all [hl.2.2.append hr] termination_by l.size + r.size /-- The `append` function preserves the ordering invariants. -/ protected theorem Ordered.append {l : RBNode α} {v : α} {r : RBNode α} (lv : l.All (cmpLT cmp · v)) (vr : r.All (cmpLT cmp v ·)) (hl : l.Ordered cmp) (hr : r.Ordered cmp) : (append l r).Ordered cmp := by unfold append; split · exact hr · exact hl · have ⟨xv, _, bv⟩ := lv; have ⟨ax, xb, ha, hb⟩ := hl have ⟨vy, vc, _⟩ := vr; have ⟨cy, yd, hc, hd⟩ := hr have : _ ∧ _ ∧ _ := ⟨hb.append bv vc hc, xb.append (xv.trans_l vc), (vy.trans_r bv).append cy⟩ split · next H => have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this have az := xz.trans_r ax; have zd := zy.trans_l yd exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩ · have ⟨hbc, xbc, bcy⟩ := this; have xy := xv.trans vy exact ⟨ax, ⟨xy, xbc, xy.trans_l yd⟩, ha, bcy, yd, hbc, hd⟩ · have ⟨xv, _, bv⟩ := lv; have ⟨ax, xb, ha, hb⟩ := hl have ⟨vy, vc, _⟩ := vr; have ⟨cy, yd, hc, hd⟩ := hr have : _ ∧ _ ∧ _ := ⟨hb.append bv vc hc, xb.append (xv.trans_l vc), (vy.trans_r bv).append cy⟩ split · next H => have ⟨⟨b'z, c'z, hb', hc'⟩, ⟨xz, xb', _⟩, zy, _, c'y⟩ := H ▸ this have az := xz.trans_r ax; have zd := zy.trans_l yd exact ⟨⟨xz, az, b'z⟩, ⟨zy, c'z, zd⟩, ⟨ax, xb', ha, hb'⟩, c'y, yd, hc', hd⟩ · have ⟨hbc, xbc, bcy⟩ := this; have xy := xv.trans vy exact ha.balLeft ax ⟨xy, xbc, xy.trans_l yd⟩ ⟨bcy, yd, hbc, hd⟩ · have ⟨vx, vb, _⟩ := vr; have ⟨bx, yc, hb, hc⟩ := hr exact ⟨(vx.trans_r lv).append bx, yc, hl.append lv vb hb, hc⟩ · have ⟨xv, _, bv⟩ := lv; have ⟨ax, xb, ha, hb⟩ := hl exact ⟨ax, xb.append (xv.trans_l vr), ha, hb.append bv vr hr⟩ termination_by l.size + r.size /-- The balance properties of the `append` function. -/ protected theorem Balanced.append {l r : RBNode α} (hl : l.Balanced c₁ n) (hr : r.Balanced c₂ n) : (l.append r).RedRed (c₁ = black → c₂ ≠ black) n := by unfold append; split · exact .balanced hr · exact .balanced hl · next b c _ _ => have .red ha hb := hl; have .red hc hd := hr have ⟨_, IH⟩ := (hb.append hc).of_false (· rfl rfl); split · next e => have .red hb' hc' := e ▸ IH exact .redred nofun (.red ha hb') (.red hc' hd) · next bcc _ H => match bcc, append b c, IH, H with | black, _, IH, _ => exact .redred nofun ha (.red IH hd) | red, _, .red .., H => cases H _ _ _ rfl · next b c _ _ => have .black ha hb := hl; have .black hc hd := hr have IH := hb.append hc; split · next e => match e ▸ IH with | .balanced (.red hb' hc') | .redred _ hb' hc' => exact .balanced (.red (.black ha hb') (.black hc' hd)) · next H => match append b c, IH, H with | bc, .balanced hbc, _ => unfold balLeft; split · have .red ha' hb' := ha exact .balanced (.red (.black ha' hb') (.black hbc hd)) · exact have ⟨c, h⟩ := RedRed.balance2 ha (.redred trivial hbc hd); .balanced h | _, .redred .., H => cases H _ _ _ rfl · have .red hc hd := hr; have IH := hl.append hc have .black ha hb := hl; have ⟨c, IH⟩ := IH.of_false (· rfl rfl) exact .redred nofun IH hd · have .red ha hb := hl; have IH := hb.append hr have .black hc hd := hr; have ⟨c, IH⟩ := IH.of_false (· rfl rfl) exact .redred nofun ha IH termination_by l.size + r.size /-! ## erase -/ /-- The invariant of the `del` function. * If the input tree is black, then the result of deletion is a red-red tree with black-height lowered by 1. * If the input tree is red or nil, then the result of deletion is a balanced tree with some color and the same black-height. -/ def DelProp (p : RBColor) (t : RBNode α) (n : Nat) : Prop := match p with | black => ∃ n', n = n' + 1 ∧ RedRed True t n' | red => ∃ c, Balanced t c n /-- The `DelProp` property is a strengthened version of the red-red invariant. -/
.lake/packages/batteries/Batteries/Data/RBMap/WF.lean
441
445
theorem DelProp.redred (h : DelProp c t n) : ∃ n', RedRed (c = black) t n' := by
unfold DelProp at h exact match c, h with | red, ⟨_, h⟩ => ⟨_, .balanced h⟩ | black, ⟨_, _, h⟩ => ⟨_, h.imp fun _ => rfl⟩
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.LatticeIntervals import Mathlib.Order.Interval.Set.OrdConnected #align_import order.complete_lattice_intervals from "leanprover-community/mathlib"@"207cfac9fcd06138865b5d04f7091e46d9320432" /-! # Subtypes of conditionally complete linear orders In this file we give conditions on a subset of a conditionally complete linear order, to ensure that the subtype is itself conditionally complete. We check that an `OrdConnected` set satisfies these conditions. ## TODO Add appropriate instances for all `Set.Ixx`. This requires a refactor that will allow different default values for `sSup` and `sInf`. -/ open scoped Classical open Set variable {ι : Sort*} {α : Type*} (s : Set α) section SupSet variable [Preorder α] [SupSet α] /-- `SupSet` structure on a nonempty subset `s` of a preorder with `SupSet`. This definition is non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the construction of the `ConditionallyCompleteLinearOrder` structure. -/ noncomputable def subsetSupSet [Inhabited s] : SupSet s where sSup t := if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩ else default #align subset_has_Sup subsetSupSet attribute [local instance] subsetSupSet @[simp] theorem subset_sSup_def [Inhabited s] : @sSup s _ = fun t => if ht : t.Nonempty ∧ BddAbove t ∧ sSup ((↑) '' t : Set α) ∈ s then ⟨sSup ((↑) '' t : Set α), ht.2.2⟩ else default := rfl #align subset_Sup_def subset_sSup_def theorem subset_sSup_of_within [Inhabited s] {t : Set s} (h' : t.Nonempty) (h'' : BddAbove t) (h : sSup ((↑) '' t : Set α) ∈ s) : sSup ((↑) '' t : Set α) = (@sSup s _ t : α) := by simp [dif_pos, h, h', h''] #align subset_Sup_of_within subset_sSup_of_within theorem subset_sSup_emptyset [Inhabited s] : sSup (∅ : Set s) = default := by simp [sSup] theorem subset_sSup_of_not_bddAbove [Inhabited s] {t : Set s} (ht : ¬BddAbove t) : sSup t = default := by simp [sSup, ht] end SupSet section InfSet variable [Preorder α] [InfSet α] /-- `InfSet` structure on a nonempty subset `s` of a preorder with `InfSet`. This definition is non-canonical (it uses `default s`); it should be used only as here, as an auxiliary instance in the construction of the `ConditionallyCompleteLinearOrder` structure. -/ noncomputable def subsetInfSet [Inhabited s] : InfSet s where sInf t := if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩ else default #align subset_has_Inf subsetInfSet attribute [local instance] subsetInfSet @[simp] theorem subset_sInf_def [Inhabited s] : @sInf s _ = fun t => if ht : t.Nonempty ∧ BddBelow t ∧ sInf ((↑) '' t : Set α) ∈ s then ⟨sInf ((↑) '' t : Set α), ht.2.2⟩ else default := rfl #align subset_Inf_def subset_sInf_def theorem subset_sInf_of_within [Inhabited s] {t : Set s} (h' : t.Nonempty) (h'' : BddBelow t) (h : sInf ((↑) '' t : Set α) ∈ s) : sInf ((↑) '' t : Set α) = (@sInf s _ t : α) := by simp [dif_pos, h, h', h''] #align subset_Inf_of_within subset_sInf_of_within theorem subset_sInf_emptyset [Inhabited s] : sInf (∅ : Set s) = default := by simp [sInf] theorem subset_sInf_of_not_bddBelow [Inhabited s] {t : Set s} (ht : ¬BddBelow t) : sInf t = default := by simp [sInf, ht] end InfSet section OrdConnected variable [ConditionallyCompleteLinearOrder α] attribute [local instance] subsetSupSet attribute [local instance] subsetInfSet /-- For a nonempty subset of a conditionally complete linear order to be a conditionally complete linear order, it suffices that it contain the `sSup` of all its nonempty bounded-above subsets, and the `sInf` of all its nonempty bounded-below subsets. See note [reducible non-instances]. -/ noncomputable abbrev subsetConditionallyCompleteLinearOrder [Inhabited s] (h_Sup : ∀ {t : Set s} (_ : t.Nonempty) (_h_bdd : BddAbove t), sSup ((↑) '' t : Set α) ∈ s) (h_Inf : ∀ {t : Set s} (_ : t.Nonempty) (_h_bdd : BddBelow t), sInf ((↑) '' t : Set α) ∈ s) : ConditionallyCompleteLinearOrder s := { subsetSupSet s, subsetInfSet s, DistribLattice.toLattice, (inferInstance : LinearOrder s) with le_csSup := by rintro t c h_bdd hct rw [← Subtype.coe_le_coe, ← subset_sSup_of_within s ⟨c, hct⟩ h_bdd (h_Sup ⟨c, hct⟩ h_bdd)] exact (Subtype.mono_coe _).le_csSup_image hct h_bdd csSup_le := by rintro t B ht hB rw [← Subtype.coe_le_coe, ← subset_sSup_of_within s ht ⟨B, hB⟩ (h_Sup ht ⟨B, hB⟩)] exact (Subtype.mono_coe s).csSup_image_le ht hB le_csInf := by intro t B ht hB rw [← Subtype.coe_le_coe, ← subset_sInf_of_within s ht ⟨B, hB⟩ (h_Inf ht ⟨B, hB⟩)] exact (Subtype.mono_coe s).le_csInf_image ht hB csInf_le := by rintro t c h_bdd hct rw [← Subtype.coe_le_coe, ← subset_sInf_of_within s ⟨c, hct⟩ h_bdd (h_Inf ⟨c, hct⟩ h_bdd)] exact (Subtype.mono_coe s).csInf_image_le hct h_bdd csSup_of_not_bddAbove := fun t ht ↦ by simp [ht] csInf_of_not_bddBelow := fun t ht ↦ by simp [ht] } #align subset_conditionally_complete_linear_order subsetConditionallyCompleteLinearOrder /-- The `sSup` function on a nonempty `OrdConnected` set `s` in a conditionally complete linear order takes values within `s`, for all nonempty bounded-above subsets of `s`. -/ theorem sSup_within_of_ordConnected {s : Set α} [hs : OrdConnected s] ⦃t : Set s⦄ (ht : t.Nonempty) (h_bdd : BddAbove t) : sSup ((↑) '' t : Set α) ∈ s := by obtain ⟨c, hct⟩ : ∃ c, c ∈ t := ht obtain ⟨B, hB⟩ : ∃ B, B ∈ upperBounds t := h_bdd refine hs.out c.2 B.2 ⟨?_, ?_⟩ · exact (Subtype.mono_coe s).le_csSup_image hct ⟨B, hB⟩ · exact (Subtype.mono_coe s).csSup_image_le ⟨c, hct⟩ hB #align Sup_within_of_ord_connected sSup_within_of_ordConnected /-- The `sInf` function on a nonempty `OrdConnected` set `s` in a conditionally complete linear order takes values within `s`, for all nonempty bounded-below subsets of `s`. -/ theorem sInf_within_of_ordConnected {s : Set α} [hs : OrdConnected s] ⦃t : Set s⦄ (ht : t.Nonempty) (h_bdd : BddBelow t) : sInf ((↑) '' t : Set α) ∈ s := by obtain ⟨c, hct⟩ : ∃ c, c ∈ t := ht obtain ⟨B, hB⟩ : ∃ B, B ∈ lowerBounds t := h_bdd refine hs.out B.2 c.2 ⟨?_, ?_⟩ · exact (Subtype.mono_coe s).le_csInf_image ⟨c, hct⟩ hB · exact (Subtype.mono_coe s).csInf_image_le hct ⟨B, hB⟩ #align Inf_within_of_ord_connected sInf_within_of_ordConnected /-- A nonempty `OrdConnected` set in a conditionally complete linear order is naturally a conditionally complete linear order. -/ noncomputable instance ordConnectedSubsetConditionallyCompleteLinearOrder [Inhabited s] [OrdConnected s] : ConditionallyCompleteLinearOrder s := subsetConditionallyCompleteLinearOrder s (fun h => sSup_within_of_ordConnected h) (fun h => sInf_within_of_ordConnected h) #align ord_connected_subset_conditionally_complete_linear_order ordConnectedSubsetConditionallyCompleteLinearOrder end OrdConnected section Icc /-- Complete lattice structure on `Set.Icc` -/ noncomputable def Set.Icc.completeLattice [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b) : CompleteLattice (Set.Icc a b) where __ := Set.Icc.boundedOrder h sSup S := if hS : S = ∅ then ⟨a, le_rfl, h⟩ else ⟨sSup ((↑) '' S), by rw [← Set.not_nonempty_iff_eq_empty, not_not] at hS refine ⟨?_, csSup_le (hS.image (↑)) (fun _ ⟨c, _, hc⟩ ↦ hc ▸ c.2.2)⟩ obtain ⟨c, hc⟩ := hS exact c.2.1.trans (le_csSup ⟨b, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.2⟩ ⟨c, hc, rfl⟩)⟩ le_sSup S c hc := by by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false] · simp [hS] at hc · exact le_csSup ⟨b, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.2⟩ ⟨c, hc, rfl⟩ sSup_le S c hc := by by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false] · exact c.2.1 · exact csSup_le ((Set.nonempty_iff_ne_empty.mpr hS).image (↑)) (fun _ ⟨d, h, hd⟩ ↦ hd ▸ hc d h) sInf S := if hS : S = ∅ then ⟨b, h, le_rfl⟩ else ⟨sInf ((↑) '' S), by rw [← Set.not_nonempty_iff_eq_empty, not_not] at hS refine ⟨le_csInf (hS.image (↑)) (fun _ ⟨c, _, hc⟩ ↦ hc ▸ c.2.1), ?_⟩ obtain ⟨c, hc⟩ := hS exact le_trans (csInf_le ⟨a, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.1⟩ ⟨c, hc, rfl⟩) c.2.2⟩ sInf_le S c hc := by by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false] · simp [hS] at hc · exact csInf_le ⟨a, fun _ ⟨d, _, hd⟩ ↦ hd ▸ d.2.1⟩ ⟨c, hc, rfl⟩ le_sInf S c hc := by by_cases hS : S = ∅ <;> simp only [hS, dite_true, dite_false] · exact c.2.2 · exact le_csInf ((Set.nonempty_iff_ne_empty.mpr hS).image (↑)) (fun _ ⟨d, h, hd⟩ ↦ hd ▸ hc d h) /-- Complete linear order structure on `Set.Icc` -/ noncomputable def Set.Icc.completeLinearOrder [ConditionallyCompleteLinearOrder α] {a b : α} (h : a ≤ b) : CompleteLinearOrder (Set.Icc a b) := { Set.Icc.completeLattice h, Subtype.instLinearOrder _ with } lemma Set.Icc.coe_sSup [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b) {S : Set (Set.Icc a b)} (hS : S.Nonempty) : letI := Set.Icc.completeLattice h ↑(sSup S) = sSup ((↑) '' S : Set α) := congrArg Subtype.val (dif_neg hS.ne_empty) lemma Set.Icc.coe_sInf [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b) {S : Set (Set.Icc a b)} (hS : S.Nonempty) : letI := Set.Icc.completeLattice h ↑(sInf S) = sInf ((↑) '' S : Set α) := congrArg Subtype.val (dif_neg hS.ne_empty) lemma Set.Icc.coe_iSup [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b) [Nonempty ι] {S : ι → Set.Icc a b} : letI := Set.Icc.completeLattice h ↑(iSup S) = (⨆ i, S i : α) := (Set.Icc.coe_sSup h (range_nonempty S)).trans (congrArg sSup (range_comp Subtype.val S).symm) lemma Set.Icc.coe_iInf [ConditionallyCompleteLattice α] {a b : α} (h : a ≤ b) [Nonempty ι] {S : ι → Set.Icc a b} : letI := Set.Icc.completeLattice h ↑(iInf S) = (⨅ i, S i : α) := (Set.Icc.coe_sInf h (range_nonempty S)).trans (congrArg sInf (range_comp Subtype.val S).symm) end Icc namespace Set.Iic variable [CompleteLattice α] {a : α} instance instCompleteLattice : CompleteLattice (Iic a) where sSup S := ⟨sSup ((↑) '' S), by simpa using fun b hb _ ↦ hb⟩ sInf S := ⟨a ⊓ sInf ((↑) '' S), by simp⟩ le_sSup S b hb := le_sSup <| mem_image_of_mem Subtype.val hb sSup_le S b hb := sSup_le <| fun c' ⟨c, hc, hc'⟩ ↦ hc' ▸ hb c hc sInf_le S b hb := inf_le_of_right_le <| sInf_le <| mem_image_of_mem Subtype.val hb le_sInf S b hb := le_inf_iff.mpr ⟨b.property, le_sInf fun d' ⟨d, hd, hd'⟩ ↦ hd' ▸ hb d hd⟩ le_top := by simp bot_le := by simp variable (S : Set <| Iic a) (f : ι → Iic a) (p : ι → Prop) @[simp] theorem coe_sSup : (↑(sSup S) : α) = sSup ((↑) '' S) := rfl @[simp] theorem coe_iSup : (↑(⨆ i, f i) : α) = ⨆ i, (f i : α) := by rw [iSup, coe_sSup]; congr; ext; simp
Mathlib/Order/CompleteLatticeIntervals.lean
265
265
theorem coe_biSup : (↑(⨆ i, ⨆ (_ : p i), f i) : α) = ⨆ i, ⨆ (_ : p i), (f i : α) := by
simp
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Topology.MetricSpace.IsometricSMul #align_import topology.metric_space.hausdorff_distance from "leanprover-community/mathlib"@"bc91ed7093bf098d253401e69df601fc33dde156" /-! # Hausdorff distance The Hausdorff distance on subsets of a metric (or emetric) space. Given two subsets `s` and `t` of a metric space, their Hausdorff distance is the smallest `d` such that any point `s` is within `d` of a point in `t`, and conversely. This quantity is often infinite (think of `s` bounded and `t` unbounded), and therefore better expressed in the setting of emetric spaces. ## Main definitions This files introduces: * `EMetric.infEdist x s`, the infimum edistance of a point `x` to a set `s` in an emetric space * `EMetric.hausdorffEdist s t`, the Hausdorff edistance of two sets in an emetric space * Versions of these notions on metric spaces, called respectively `Metric.infDist` and `Metric.hausdorffDist` ## Main results * `infEdist_closure`: the edistance to a set and its closure coincide * `EMetric.mem_closure_iff_infEdist_zero`: a point `x` belongs to the closure of `s` iff `infEdist x s = 0` * `IsCompact.exists_infEdist_eq_edist`: if `s` is compact and non-empty, there exists a point `y` which attains this edistance * `IsOpen.exists_iUnion_isClosed`: every open set `U` can be written as the increasing union of countably many closed subsets of `U` * `hausdorffEdist_closure`: replacing a set by its closure does not change the Hausdorff edistance * `hausdorffEdist_zero_iff_closure_eq_closure`: two sets have Hausdorff edistance zero iff their closures coincide * the Hausdorff edistance is symmetric and satisfies the triangle inequality * in particular, closed sets in an emetric space are an emetric space (this is shown in `EMetricSpace.closeds.emetricspace`) * versions of these notions on metric spaces * `hausdorffEdist_ne_top_of_nonempty_of_bounded`: if two sets in a metric space are nonempty and bounded in a metric space, they are at finite Hausdorff edistance. ## Tags metric space, Hausdorff distance -/ noncomputable section open NNReal ENNReal Topology Set Filter Pointwise Bornology universe u v w variable {ι : Sort*} {α : Type u} {β : Type v} namespace EMetric section InfEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t : Set α} {Φ : α → β} /-! ### Distance of a point to a set as a function into `ℝ≥0∞`. -/ /-- The minimal edistance of a point to a set -/ def infEdist (x : α) (s : Set α) : ℝ≥0∞ := ⨅ y ∈ s, edist x y #align emetric.inf_edist EMetric.infEdist @[simp] theorem infEdist_empty : infEdist x ∅ = ∞ := iInf_emptyset #align emetric.inf_edist_empty EMetric.infEdist_empty theorem le_infEdist {d} : d ≤ infEdist x s ↔ ∀ y ∈ s, d ≤ edist x y := by simp only [infEdist, le_iInf_iff] #align emetric.le_inf_edist EMetric.le_infEdist /-- The edist to a union is the minimum of the edists -/ @[simp] theorem infEdist_union : infEdist x (s ∪ t) = infEdist x s ⊓ infEdist x t := iInf_union #align emetric.inf_edist_union EMetric.infEdist_union @[simp] theorem infEdist_iUnion (f : ι → Set α) (x : α) : infEdist x (⋃ i, f i) = ⨅ i, infEdist x (f i) := iInf_iUnion f _ #align emetric.inf_edist_Union EMetric.infEdist_iUnion lemma infEdist_biUnion {ι : Type*} (f : ι → Set α) (I : Set ι) (x : α) : infEdist x (⋃ i ∈ I, f i) = ⨅ i ∈ I, infEdist x (f i) := by simp only [infEdist_iUnion] /-- The edist to a singleton is the edistance to the single point of this singleton -/ @[simp] theorem infEdist_singleton : infEdist x {y} = edist x y := iInf_singleton #align emetric.inf_edist_singleton EMetric.infEdist_singleton /-- The edist to a set is bounded above by the edist to any of its points -/ theorem infEdist_le_edist_of_mem (h : y ∈ s) : infEdist x s ≤ edist x y := iInf₂_le y h #align emetric.inf_edist_le_edist_of_mem EMetric.infEdist_le_edist_of_mem /-- If a point `x` belongs to `s`, then its edist to `s` vanishes -/ theorem infEdist_zero_of_mem (h : x ∈ s) : infEdist x s = 0 := nonpos_iff_eq_zero.1 <| @edist_self _ _ x ▸ infEdist_le_edist_of_mem h #align emetric.inf_edist_zero_of_mem EMetric.infEdist_zero_of_mem /-- The edist is antitone with respect to inclusion. -/ theorem infEdist_anti (h : s ⊆ t) : infEdist x t ≤ infEdist x s := iInf_le_iInf_of_subset h #align emetric.inf_edist_anti EMetric.infEdist_anti /-- The edist to a set is `< r` iff there exists a point in the set at edistance `< r` -/ theorem infEdist_lt_iff {r : ℝ≥0∞} : infEdist x s < r ↔ ∃ y ∈ s, edist x y < r := by simp_rw [infEdist, iInf_lt_iff, exists_prop] #align emetric.inf_edist_lt_iff EMetric.infEdist_lt_iff /-- The edist of `x` to `s` is bounded by the sum of the edist of `y` to `s` and the edist from `x` to `y` -/ theorem infEdist_le_infEdist_add_edist : infEdist x s ≤ infEdist y s + edist x y := calc ⨅ z ∈ s, edist x z ≤ ⨅ z ∈ s, edist y z + edist x y := iInf₂_mono fun z _ => (edist_triangle _ _ _).trans_eq (add_comm _ _) _ = (⨅ z ∈ s, edist y z) + edist x y := by simp only [ENNReal.iInf_add] #align emetric.inf_edist_le_inf_edist_add_edist EMetric.infEdist_le_infEdist_add_edist theorem infEdist_le_edist_add_infEdist : infEdist x s ≤ edist x y + infEdist y s := by rw [add_comm] exact infEdist_le_infEdist_add_edist #align emetric.inf_edist_le_edist_add_inf_edist EMetric.infEdist_le_edist_add_infEdist theorem edist_le_infEdist_add_ediam (hy : y ∈ s) : edist x y ≤ infEdist x s + diam s := by simp_rw [infEdist, ENNReal.iInf_add] refine le_iInf₂ fun i hi => ?_ calc edist x y ≤ edist x i + edist i y := edist_triangle _ _ _ _ ≤ edist x i + diam s := add_le_add le_rfl (edist_le_diam_of_mem hi hy) #align emetric.edist_le_inf_edist_add_ediam EMetric.edist_le_infEdist_add_ediam /-- The edist to a set depends continuously on the point -/ @[continuity] theorem continuous_infEdist : Continuous fun x => infEdist x s := continuous_of_le_add_edist 1 (by simp) <| by simp only [one_mul, infEdist_le_infEdist_add_edist, forall₂_true_iff] #align emetric.continuous_inf_edist EMetric.continuous_infEdist /-- The edist to a set and to its closure coincide -/ theorem infEdist_closure : infEdist x (closure s) = infEdist x s := by refine le_antisymm (infEdist_anti subset_closure) ?_ refine ENNReal.le_of_forall_pos_le_add fun ε εpos h => ?_ have ε0 : 0 < (ε / 2 : ℝ≥0∞) := by simpa [pos_iff_ne_zero] using εpos have : infEdist x (closure s) < infEdist x (closure s) + ε / 2 := ENNReal.lt_add_right h.ne ε0.ne' obtain ⟨y : α, ycs : y ∈ closure s, hy : edist x y < infEdist x (closure s) + ↑ε / 2⟩ := infEdist_lt_iff.mp this obtain ⟨z : α, zs : z ∈ s, dyz : edist y z < ↑ε / 2⟩ := EMetric.mem_closure_iff.1 ycs (ε / 2) ε0 calc infEdist x s ≤ edist x z := infEdist_le_edist_of_mem zs _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x (closure s) + ε / 2 + ε / 2 := add_le_add (le_of_lt hy) (le_of_lt dyz) _ = infEdist x (closure s) + ↑ε := by rw [add_assoc, ENNReal.add_halves] #align emetric.inf_edist_closure EMetric.infEdist_closure /-- A point belongs to the closure of `s` iff its infimum edistance to this set vanishes -/ theorem mem_closure_iff_infEdist_zero : x ∈ closure s ↔ infEdist x s = 0 := ⟨fun h => by rw [← infEdist_closure] exact infEdist_zero_of_mem h, fun h => EMetric.mem_closure_iff.2 fun ε εpos => infEdist_lt_iff.mp <| by rwa [h]⟩ #align emetric.mem_closure_iff_inf_edist_zero EMetric.mem_closure_iff_infEdist_zero /-- Given a closed set `s`, a point belongs to `s` iff its infimum edistance to this set vanishes -/ theorem mem_iff_infEdist_zero_of_closed (h : IsClosed s) : x ∈ s ↔ infEdist x s = 0 := by rw [← mem_closure_iff_infEdist_zero, h.closure_eq] #align emetric.mem_iff_inf_edist_zero_of_closed EMetric.mem_iff_infEdist_zero_of_closed /-- The infimum edistance of a point to a set is positive if and only if the point is not in the closure of the set. -/ theorem infEdist_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x E ↔ x ∉ closure E := by rw [mem_closure_iff_infEdist_zero, pos_iff_ne_zero] #align emetric.inf_edist_pos_iff_not_mem_closure EMetric.infEdist_pos_iff_not_mem_closure theorem infEdist_closure_pos_iff_not_mem_closure {x : α} {E : Set α} : 0 < infEdist x (closure E) ↔ x ∉ closure E := by rw [infEdist_closure, infEdist_pos_iff_not_mem_closure] #align emetric.inf_edist_closure_pos_iff_not_mem_closure EMetric.infEdist_closure_pos_iff_not_mem_closure theorem exists_real_pos_lt_infEdist_of_not_mem_closure {x : α} {E : Set α} (h : x ∉ closure E) : ∃ ε : ℝ, 0 < ε ∧ ENNReal.ofReal ε < infEdist x E := by rw [← infEdist_pos_iff_not_mem_closure, ENNReal.lt_iff_exists_real_btwn] at h rcases h with ⟨ε, ⟨_, ⟨ε_pos, ε_lt⟩⟩⟩ exact ⟨ε, ⟨ENNReal.ofReal_pos.mp ε_pos, ε_lt⟩⟩ #align emetric.exists_real_pos_lt_inf_edist_of_not_mem_closure EMetric.exists_real_pos_lt_infEdist_of_not_mem_closure theorem disjoint_closedBall_of_lt_infEdist {r : ℝ≥0∞} (h : r < infEdist x s) : Disjoint (closedBall x r) s := by rw [disjoint_left] intro y hy h'y apply lt_irrefl (infEdist x s) calc infEdist x s ≤ edist x y := infEdist_le_edist_of_mem h'y _ ≤ r := by rwa [mem_closedBall, edist_comm] at hy _ < infEdist x s := h #align emetric.disjoint_closed_ball_of_lt_inf_edist EMetric.disjoint_closedBall_of_lt_infEdist /-- The infimum edistance is invariant under isometries -/ theorem infEdist_image (hΦ : Isometry Φ) : infEdist (Φ x) (Φ '' t) = infEdist x t := by simp only [infEdist, iInf_image, hΦ.edist_eq] #align emetric.inf_edist_image EMetric.infEdist_image @[to_additive (attr := simp)] theorem infEdist_smul {M} [SMul M α] [IsometricSMul M α] (c : M) (x : α) (s : Set α) : infEdist (c • x) (c • s) = infEdist x s := infEdist_image (isometry_smul _ _) #align emetric.inf_edist_smul EMetric.infEdist_smul #align emetric.inf_edist_vadd EMetric.infEdist_vadd theorem _root_.IsOpen.exists_iUnion_isClosed {U : Set α} (hU : IsOpen U) : ∃ F : ℕ → Set α, (∀ n, IsClosed (F n)) ∧ (∀ n, F n ⊆ U) ∧ ⋃ n, F n = U ∧ Monotone F := by obtain ⟨a, a_pos, a_lt_one⟩ : ∃ a : ℝ≥0∞, 0 < a ∧ a < 1 := exists_between zero_lt_one let F := fun n : ℕ => (fun x => infEdist x Uᶜ) ⁻¹' Ici (a ^ n) have F_subset : ∀ n, F n ⊆ U := fun n x hx ↦ by by_contra h have : infEdist x Uᶜ ≠ 0 := ((ENNReal.pow_pos a_pos _).trans_le hx).ne' exact this (infEdist_zero_of_mem h) refine ⟨F, fun n => IsClosed.preimage continuous_infEdist isClosed_Ici, F_subset, ?_, ?_⟩ · show ⋃ n, F n = U refine Subset.antisymm (by simp only [iUnion_subset_iff, F_subset, forall_const]) fun x hx => ?_ have : ¬x ∈ Uᶜ := by simpa using hx rw [mem_iff_infEdist_zero_of_closed hU.isClosed_compl] at this have B : 0 < infEdist x Uᶜ := by simpa [pos_iff_ne_zero] using this have : Filter.Tendsto (fun n => a ^ n) atTop (𝓝 0) := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one a_lt_one rcases ((tendsto_order.1 this).2 _ B).exists with ⟨n, hn⟩ simp only [mem_iUnion, mem_Ici, mem_preimage] exact ⟨n, hn.le⟩ show Monotone F intro m n hmn x hx simp only [F, mem_Ici, mem_preimage] at hx ⊢ apply le_trans (pow_le_pow_right_of_le_one' a_lt_one.le hmn) hx #align is_open.exists_Union_is_closed IsOpen.exists_iUnion_isClosed theorem _root_.IsCompact.exists_infEdist_eq_edist (hs : IsCompact s) (hne : s.Nonempty) (x : α) : ∃ y ∈ s, infEdist x s = edist x y := by have A : Continuous fun y => edist x y := continuous_const.edist continuous_id obtain ⟨y, ys, hy⟩ := hs.exists_isMinOn hne A.continuousOn exact ⟨y, ys, le_antisymm (infEdist_le_edist_of_mem ys) (by rwa [le_infEdist])⟩ #align is_compact.exists_inf_edist_eq_edist IsCompact.exists_infEdist_eq_edist theorem exists_pos_forall_lt_edist (hs : IsCompact s) (ht : IsClosed t) (hst : Disjoint s t) : ∃ r : ℝ≥0, 0 < r ∧ ∀ x ∈ s, ∀ y ∈ t, (r : ℝ≥0∞) < edist x y := by rcases s.eq_empty_or_nonempty with (rfl | hne) · use 1 simp obtain ⟨x, hx, h⟩ := hs.exists_isMinOn hne continuous_infEdist.continuousOn have : 0 < infEdist x t := pos_iff_ne_zero.2 fun H => hst.le_bot ⟨hx, (mem_iff_infEdist_zero_of_closed ht).mpr H⟩ rcases ENNReal.lt_iff_exists_nnreal_btwn.1 this with ⟨r, h₀, hr⟩ exact ⟨r, ENNReal.coe_pos.mp h₀, fun y hy z hz => hr.trans_le <| le_infEdist.1 (h hy) z hz⟩ #align emetric.exists_pos_forall_lt_edist EMetric.exists_pos_forall_lt_edist end InfEdist /-! ### The Hausdorff distance as a function into `ℝ≥0∞`. -/ /-- The Hausdorff edistance between two sets is the smallest `r` such that each set is contained in the `r`-neighborhood of the other one -/ irreducible_def hausdorffEdist {α : Type u} [PseudoEMetricSpace α] (s t : Set α) : ℝ≥0∞ := (⨆ x ∈ s, infEdist x t) ⊔ ⨆ y ∈ t, infEdist y s #align emetric.Hausdorff_edist EMetric.hausdorffEdist #align emetric.Hausdorff_edist_def EMetric.hausdorffEdist_def section HausdorffEdist variable [PseudoEMetricSpace α] [PseudoEMetricSpace β] {x y : α} {s t u : Set α} {Φ : α → β} /-- The Hausdorff edistance of a set to itself vanishes. -/ @[simp] theorem hausdorffEdist_self : hausdorffEdist s s = 0 := by simp only [hausdorffEdist_def, sup_idem, ENNReal.iSup_eq_zero] exact fun x hx => infEdist_zero_of_mem hx #align emetric.Hausdorff_edist_self EMetric.hausdorffEdist_self /-- The Haudorff edistances of `s` to `t` and of `t` to `s` coincide. -/ theorem hausdorffEdist_comm : hausdorffEdist s t = hausdorffEdist t s := by simp only [hausdorffEdist_def]; apply sup_comm set_option linter.uppercaseLean3 false in #align emetric.Hausdorff_edist_comm EMetric.hausdorffEdist_comm /-- Bounding the Hausdorff edistance by bounding the edistance of any point in each set to the other set -/ theorem hausdorffEdist_le_of_infEdist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, infEdist x t ≤ r) (H2 : ∀ x ∈ t, infEdist x s ≤ r) : hausdorffEdist s t ≤ r := by simp only [hausdorffEdist_def, sup_le_iff, iSup_le_iff] exact ⟨H1, H2⟩ #align emetric.Hausdorff_edist_le_of_inf_edist EMetric.hausdorffEdist_le_of_infEdist /-- Bounding the Hausdorff edistance by exhibiting, for any point in each set, another point in the other set at controlled distance -/ theorem hausdorffEdist_le_of_mem_edist {r : ℝ≥0∞} (H1 : ∀ x ∈ s, ∃ y ∈ t, edist x y ≤ r) (H2 : ∀ x ∈ t, ∃ y ∈ s, edist x y ≤ r) : hausdorffEdist s t ≤ r := by refine hausdorffEdist_le_of_infEdist (fun x xs ↦ ?_) (fun x xt ↦ ?_) · rcases H1 x xs with ⟨y, yt, hy⟩ exact le_trans (infEdist_le_edist_of_mem yt) hy · rcases H2 x xt with ⟨y, ys, hy⟩ exact le_trans (infEdist_le_edist_of_mem ys) hy #align emetric.Hausdorff_edist_le_of_mem_edist EMetric.hausdorffEdist_le_of_mem_edist /-- The distance to a set is controlled by the Hausdorff distance. -/ theorem infEdist_le_hausdorffEdist_of_mem (h : x ∈ s) : infEdist x t ≤ hausdorffEdist s t := by rw [hausdorffEdist_def] refine le_trans ?_ le_sup_left exact le_iSup₂ (α := ℝ≥0∞) x h #align emetric.inf_edist_le_Hausdorff_edist_of_mem EMetric.infEdist_le_hausdorffEdist_of_mem /-- If the Hausdorff distance is `< r`, then any point in one of the sets has a corresponding point at distance `< r` in the other set. -/ theorem exists_edist_lt_of_hausdorffEdist_lt {r : ℝ≥0∞} (h : x ∈ s) (H : hausdorffEdist s t < r) : ∃ y ∈ t, edist x y < r := infEdist_lt_iff.mp <| calc infEdist x t ≤ hausdorffEdist s t := infEdist_le_hausdorffEdist_of_mem h _ < r := H #align emetric.exists_edist_lt_of_Hausdorff_edist_lt EMetric.exists_edist_lt_of_hausdorffEdist_lt /-- The distance from `x` to `s` or `t` is controlled in terms of the Hausdorff distance between `s` and `t`. -/ theorem infEdist_le_infEdist_add_hausdorffEdist : infEdist x t ≤ infEdist x s + hausdorffEdist s t := ENNReal.le_of_forall_pos_le_add fun ε εpos h => by have ε0 : (ε / 2 : ℝ≥0∞) ≠ 0 := by simpa [pos_iff_ne_zero] using εpos have : infEdist x s < infEdist x s + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).1.ne ε0 obtain ⟨y : α, ys : y ∈ s, dxy : edist x y < infEdist x s + ↑ε / 2⟩ := infEdist_lt_iff.mp this have : hausdorffEdist s t < hausdorffEdist s t + ε / 2 := ENNReal.lt_add_right (ENNReal.add_lt_top.1 h).2.ne ε0 obtain ⟨z : α, zt : z ∈ t, dyz : edist y z < hausdorffEdist s t + ↑ε / 2⟩ := exists_edist_lt_of_hausdorffEdist_lt ys this calc infEdist x t ≤ edist x z := infEdist_le_edist_of_mem zt _ ≤ edist x y + edist y z := edist_triangle _ _ _ _ ≤ infEdist x s + ε / 2 + (hausdorffEdist s t + ε / 2) := add_le_add dxy.le dyz.le _ = infEdist x s + hausdorffEdist s t + ε := by simp [ENNReal.add_halves, add_comm, add_left_comm] #align emetric.inf_edist_le_inf_edist_add_Hausdorff_edist EMetric.infEdist_le_infEdist_add_hausdorffEdist /-- The Hausdorff edistance is invariant under isometries. -/ theorem hausdorffEdist_image (h : Isometry Φ) : hausdorffEdist (Φ '' s) (Φ '' t) = hausdorffEdist s t := by simp only [hausdorffEdist_def, iSup_image, infEdist_image h] #align emetric.Hausdorff_edist_image EMetric.hausdorffEdist_image /-- The Hausdorff distance is controlled by the diameter of the union. -/ theorem hausdorffEdist_le_ediam (hs : s.Nonempty) (ht : t.Nonempty) : hausdorffEdist s t ≤ diam (s ∪ t) := by rcases hs with ⟨x, xs⟩ rcases ht with ⟨y, yt⟩ refine hausdorffEdist_le_of_mem_edist ?_ ?_ · intro z hz exact ⟨y, yt, edist_le_diam_of_mem (subset_union_left hz) (subset_union_right yt)⟩ · intro z hz exact ⟨x, xs, edist_le_diam_of_mem (subset_union_right hz) (subset_union_left xs)⟩ #align emetric.Hausdorff_edist_le_ediam EMetric.hausdorffEdist_le_ediam /-- The Hausdorff distance satisfies the triangle inequality. -/ theorem hausdorffEdist_triangle : hausdorffEdist s u ≤ hausdorffEdist s t + hausdorffEdist t u := by rw [hausdorffEdist_def] simp only [sup_le_iff, iSup_le_iff] constructor · show ∀ x ∈ s, infEdist x u ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xs => calc infEdist x u ≤ infEdist x t + hausdorffEdist t u := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist s t + hausdorffEdist t u := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xs) _ · show ∀ x ∈ u, infEdist x s ≤ hausdorffEdist s t + hausdorffEdist t u exact fun x xu => calc infEdist x s ≤ infEdist x t + hausdorffEdist t s := infEdist_le_infEdist_add_hausdorffEdist _ ≤ hausdorffEdist u t + hausdorffEdist t s := add_le_add_right (infEdist_le_hausdorffEdist_of_mem xu) _ _ = hausdorffEdist s t + hausdorffEdist t u := by simp [hausdorffEdist_comm, add_comm] #align emetric.Hausdorff_edist_triangle EMetric.hausdorffEdist_triangle /-- Two sets are at zero Hausdorff edistance if and only if they have the same closure. -/ theorem hausdorffEdist_zero_iff_closure_eq_closure : hausdorffEdist s t = 0 ↔ closure s = closure t := by simp only [hausdorffEdist_def, ENNReal.sup_eq_zero, ENNReal.iSup_eq_zero, ← subset_def, ← mem_closure_iff_infEdist_zero, subset_antisymm_iff, isClosed_closure.closure_subset_iff] #align emetric.Hausdorff_edist_zero_iff_closure_eq_closure EMetric.hausdorffEdist_zero_iff_closure_eq_closure /-- The Hausdorff edistance between a set and its closure vanishes. -/ @[simp] theorem hausdorffEdist_self_closure : hausdorffEdist s (closure s) = 0 := by rw [hausdorffEdist_zero_iff_closure_eq_closure, closure_closure] #align emetric.Hausdorff_edist_self_closure EMetric.hausdorffEdist_self_closure /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₁ : hausdorffEdist (closure s) t = hausdorffEdist s t := by refine le_antisymm ?_ ?_ · calc _ ≤ hausdorffEdist (closure s) s + hausdorffEdist s t := hausdorffEdist_triangle _ = hausdorffEdist s t := by simp [hausdorffEdist_comm] · calc _ ≤ hausdorffEdist s (closure s) + hausdorffEdist (closure s) t := hausdorffEdist_triangle _ = hausdorffEdist (closure s) t := by simp #align emetric.Hausdorff_edist_closure₁ EMetric.hausdorffEdist_closure₁ /-- Replacing a set by its closure does not change the Hausdorff edistance. -/ @[simp] theorem hausdorffEdist_closure₂ : hausdorffEdist s (closure t) = hausdorffEdist s t := by simp [@hausdorffEdist_comm _ _ s _] #align emetric.Hausdorff_edist_closure₂ EMetric.hausdorffEdist_closure₂ /-- The Hausdorff edistance between sets or their closures is the same. -/ -- @[simp] -- Porting note (#10618): simp can prove this theorem hausdorffEdist_closure : hausdorffEdist (closure s) (closure t) = hausdorffEdist s t := by simp #align emetric.Hausdorff_edist_closure EMetric.hausdorffEdist_closure /-- Two closed sets are at zero Hausdorff edistance if and only if they coincide. -/
Mathlib/Topology/MetricSpace/HausdorffDistance.lean
433
435
theorem hausdorffEdist_zero_iff_eq_of_closed (hs : IsClosed s) (ht : IsClosed t) : hausdorffEdist s t = 0 ↔ s = t := by
rw [hausdorffEdist_zero_iff_closure_eq_closure, hs.closure_eq, ht.closure_eq]
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Order.Archimedean import Mathlib.Algebra.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.GroupTheory.QuotientGroup import Mathlib.Order.Circular import Mathlib.Data.List.TFAE import Mathlib.Data.Set.Lattice #align_import algebra.order.to_interval_mod from "leanprover-community/mathlib"@"213b0cff7bc5ab6696ee07cceec80829ce42efec" /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [LinearOrderedAddCommGroup α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose #align to_Ico_div toIcoDiv theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 #align sub_to_Ico_div_zsmul_mem_Ico sub_toIcoDiv_zsmul_mem_Ico theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm #align to_Ico_div_eq_of_sub_zsmul_mem_Ico toIcoDiv_eq_of_sub_zsmul_mem_Ico /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose #align to_Ioc_div toIocDiv theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 #align sub_to_Ioc_div_zsmul_mem_Ioc sub_toIocDiv_zsmul_mem_Ioc theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm #align to_Ioc_div_eq_of_sub_zsmul_mem_Ioc toIocDiv_eq_of_sub_zsmul_mem_Ioc /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p #align to_Ico_mod toIcoMod /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p #align to_Ioc_mod toIocMod theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_mod_mem_Ico toIcoMod_mem_Ico theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm #align to_Ico_mod_mem_Ico' toIcoMod_mem_Ico' theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_mod_mem_Ioc toIocMod_mem_Ioc theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 #align left_le_to_Ico_mod left_le_toIcoMod theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 #align left_lt_to_Ioc_mod left_lt_toIocMod theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 #align to_Ico_mod_lt_right toIcoMod_lt_right theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 #align to_Ioc_mod_le_right toIocMod_le_right @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl #align self_sub_to_Ico_div_zsmul self_sub_toIcoDiv_zsmul @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl #align self_sub_to_Ioc_div_zsmul self_sub_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] #align to_Ico_div_zsmul_sub_self toIcoDiv_zsmul_sub_self @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] #align to_Ioc_div_zsmul_sub_self toIocDiv_zsmul_sub_self @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] #align to_Ico_mod_sub_self toIcoMod_sub_self @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] #align to_Ioc_mod_sub_self toIocMod_sub_self @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] #align self_sub_to_Ico_mod self_sub_toIcoMod @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] #align self_sub_to_Ioc_mod self_sub_toIocMod @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] #align to_Ico_mod_add_to_Ico_div_zsmul toIcoMod_add_toIcoDiv_zsmul @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] #align to_Ioc_mod_add_to_Ioc_div_zsmul toIocMod_add_toIocDiv_zsmul @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] #align to_Ico_div_zsmul_sub_to_Ico_mod toIcoDiv_zsmul_sub_toIcoMod @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] #align to_Ioc_div_zsmul_sub_to_Ioc_mod toIocDiv_zsmul_sub_toIocMod theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] #align to_Ico_mod_eq_iff toIcoMod_eq_iff theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] #align to_Ioc_mod_eq_iff toIocMod_eq_iff @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_left toIcoDiv_apply_left @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_left toIocDiv_apply_left @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ico_mod_apply_left toIcoMod_apply_left @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ #align to_Ioc_mod_apply_left toIocMod_apply_left theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] #align to_Ico_div_apply_right toIcoDiv_apply_right theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] #align to_Ioc_div_apply_right toIocDiv_apply_right theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ #align to_Ico_mod_apply_right toIcoMod_apply_right theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ #align to_Ioc_mod_apply_right toIocMod_apply_right @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul toIcoDiv_add_zsmul @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b #align to_Ico_div_add_zsmul' toIcoDiv_add_zsmul' @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul toIocDiv_add_zsmul @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b #align to_Ioc_div_add_zsmul' toIocDiv_add_zsmul' @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] #align to_Ico_div_zsmul_add toIcoDiv_zsmul_add /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] #align to_Ioc_div_zsmul_add toIocDiv_zsmul_add /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] #align to_Ico_div_sub_zsmul toIcoDiv_sub_zsmul @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] #align to_Ico_div_sub_zsmul' toIcoDiv_sub_zsmul' @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] #align to_Ioc_div_sub_zsmul toIocDiv_sub_zsmul @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] #align to_Ioc_div_sub_zsmul' toIocDiv_sub_zsmul' @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 #align to_Ico_div_add_right toIcoDiv_add_right @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 #align to_Ico_div_add_right' toIcoDiv_add_right' @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 #align to_Ioc_div_add_right toIocDiv_add_right @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 #align to_Ioc_div_add_right' toIocDiv_add_right' @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] #align to_Ico_div_add_left toIcoDiv_add_left @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] #align to_Ico_div_add_left' toIcoDiv_add_left' @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] #align to_Ioc_div_add_left toIocDiv_add_left @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] #align to_Ioc_div_add_left' toIocDiv_add_left' @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 #align to_Ico_div_sub toIcoDiv_sub @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 #align to_Ico_div_sub' toIcoDiv_sub' @[simp] theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 #align to_Ioc_div_sub toIocDiv_sub @[simp] theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 #align to_Ioc_div_sub' toIocDiv_sub' theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b #align to_Ico_div_sub_eq_to_Ico_div_add toIcoDiv_sub_eq_toIcoDiv_add theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b #align to_Ioc_div_sub_eq_to_Ioc_div_add toIocDiv_sub_eq_toIocDiv_add theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] #align to_Ico_div_sub_eq_to_Ico_div_add' toIcoDiv_sub_eq_toIcoDiv_add' theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] #align to_Ioc_div_sub_eq_to_Ioc_div_add' toIocDiv_sub_eq_toIocDiv_add' theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] #align to_Ico_div_neg toIcoDiv_neg theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) #align to_Ico_div_neg' toIcoDiv_neg' theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] #align to_Ioc_div_neg toIocDiv_neg theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) #align to_Ioc_div_neg' toIocDiv_neg' @[simp] theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel #align to_Ico_mod_add_zsmul toIcoMod_add_zsmul @[simp] theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] #align to_Ico_mod_add_zsmul' toIcoMod_add_zsmul' @[simp] theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel #align to_Ioc_mod_add_zsmul toIocMod_add_zsmul @[simp] theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] #align to_Ioc_mod_add_zsmul' toIocMod_add_zsmul' @[simp] theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] #align to_Ico_mod_zsmul_add toIcoMod_zsmul_add @[simp] theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) : toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] #align to_Ico_mod_zsmul_add' toIcoMod_zsmul_add' @[simp] theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] #align to_Ioc_mod_zsmul_add toIocMod_zsmul_add @[simp] theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) : toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] #align to_Ioc_mod_zsmul_add' toIocMod_zsmul_add' @[simp] theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] #align to_Ico_mod_sub_zsmul toIcoMod_sub_zsmul @[simp] theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] #align to_Ico_mod_sub_zsmul' toIcoMod_sub_zsmul' @[simp] theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] #align to_Ioc_mod_sub_zsmul toIocMod_sub_zsmul @[simp] theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] #align to_Ioc_mod_sub_zsmul' toIocMod_sub_zsmul' @[simp] theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 #align to_Ico_mod_add_right toIcoMod_add_right @[simp] theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 #align to_Ico_mod_add_right' toIcoMod_add_right' @[simp] theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 #align to_Ioc_mod_add_right toIocMod_add_right @[simp] theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 #align to_Ioc_mod_add_right' toIocMod_add_right' @[simp] theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] #align to_Ico_mod_add_left toIcoMod_add_left @[simp] theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] #align to_Ico_mod_add_left' toIcoMod_add_left' @[simp] theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] #align to_Ioc_mod_add_left toIocMod_add_left @[simp] theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] #align to_Ioc_mod_add_left' toIocMod_add_left' @[simp] theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 #align to_Ico_mod_sub toIcoMod_sub @[simp] theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 #align to_Ico_mod_sub' toIcoMod_sub' @[simp] theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 #align to_Ioc_mod_sub toIocMod_sub @[simp] theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 #align to_Ioc_mod_sub' toIocMod_sub' theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] #align to_Ico_mod_sub_eq_sub toIcoMod_sub_eq_sub theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] #align to_Ioc_mod_sub_eq_sub toIocMod_sub_eq_sub theorem toIcoMod_add_right_eq_add (a b c : α) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] #align to_Ico_mod_add_right_eq_add toIcoMod_add_right_eq_add theorem toIocMod_add_right_eq_add (a b c : α) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] #align to_Ioc_mod_add_right_eq_add toIocMod_add_right_eq_add theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel #align to_Ico_mod_neg toIcoMod_neg theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) #align to_Ico_mod_neg' toIcoMod_neg' theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel #align to_Ioc_mod_neg toIocMod_neg theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) #align to_Ioc_mod_neg' toIocMod_neg' theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] #align to_Ico_mod_eq_to_Ico_mod toIcoMod_eq_toIcoMod theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] #align to_Ioc_mod_eq_to_Ioc_mod toIocMod_eq_toIocMod /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ #align add_comm_group.modeq_iff_to_Ico_mod_eq_left AddCommGroup.modEq_iff_toIcoMod_eq_left theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ · rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] · rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] #align add_comm_group.modeq_iff_to_Ioc_mod_eq_right AddCommGroup.modEq_iff_toIocMod_eq_right alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left #align add_comm_group.modeq.to_Ico_mod_eq_left AddCommGroup.ModEq.toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right #align add_comm_group.modeq.to_Ico_mod_eq_right AddCommGroup.ModEq.toIcoMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 → 2 · rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 → 3 · intro h rw [← h, Ne, eq_comm, add_right_eq_self] exact hp.ne' tfae_have 1 → 4 · intro h rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_right_neg, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 → 1 · rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish #align add_comm_group.tfae_modeq AddCommGroup.tfae_modEq variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 #align add_comm_group.modeq_iff_not_forall_mem_Ioo_mod AddCommGroup.modEq_iff_not_forall_mem_Ioo_mod theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b := (tfae_modEq hp a b).out 0 2 #align add_comm_group.modeq_iff_to_Ico_mod_ne_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_ne_toIocMod theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 #align add_comm_group.modeq_iff_to_Ico_mod_add_period_eq_to_Ioc_mod AddCommGroup.modEq_iff_toIcoMod_add_period_eq_toIocMod theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left #align add_comm_group.not_modeq_iff_to_Ico_mod_eq_to_Ioc_mod AddCommGroup.not_modEq_iff_toIcoMod_eq_toIocMod theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, (zsmul_strictMono_left hp).injective.eq_iff] #align add_comm_group.not_modeq_iff_to_Ico_div_eq_to_Ioc_div AddCommGroup.not_modEq_iff_toIcoDiv_eq_toIocDiv theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, (zsmul_strictMono_left hp).injective.eq_iff] #align add_comm_group.modeq_iff_to_Ico_div_eq_to_Ioc_div_add_one AddCommGroup.modEq_iff_toIcoDiv_eq_toIocDiv_add_one end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] #align to_Ico_mod_inj toIcoMod_inj alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj #align add_comm_group.modeq.to_Ico_mod_eq_to_Ico_mod AddCommGroup.ModEq.toIcoMod_eq_toIcoMod theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by ext1; simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] #align Ico_eq_locus_Ioc_eq_Union_Ioo Ico_eq_locus_Ioc_eq_iUnion_Ioo theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] exact em' _ #align to_Ioc_div_wcovby_to_Ico_div toIocDiv_wcovBy_toIcoDiv theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by rw [toIcoMod, toIocMod, sub_le_sub_iff_left] exact zsmul_mono_left hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le #align to_Ico_mod_le_to_Ioc_mod toIcoMod_le_toIocMod theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_strictMono_left hp).le_iff_le] apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ #align to_Ioc_mod_le_to_Ico_mod_add toIocMod_le_toIcoMod_add end IcoIoc open AddCommGroup theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by rw [toIcoMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ #align to_Ico_mod_eq_self toIcoMod_eq_self theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by rw [toIocMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ #align to_Ioc_mod_eq_self toIocMod_eq_self @[simp] theorem toIcoMod_toIcoMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIcoMod hp a₂ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩ #align to_Ico_mod_to_Ico_mod toIcoMod_toIcoMod @[simp] theorem toIcoMod_toIocMod (a₁ a₂ b : α) : toIcoMod hp a₁ (toIocMod hp a₂ b) = toIcoMod hp a₁ b := (toIcoMod_eq_toIcoMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩ #align to_Ico_mod_to_Ioc_mod toIcoMod_toIocMod @[simp] theorem toIocMod_toIocMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIocMod hp a₂ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIocDiv hp a₂ b, self_sub_toIocMod hp a₂ b⟩ #align to_Ioc_mod_to_Ioc_mod toIocMod_toIocMod @[simp] theorem toIocMod_toIcoMod (a₁ a₂ b : α) : toIocMod hp a₁ (toIcoMod hp a₂ b) = toIocMod hp a₁ b := (toIocMod_eq_toIocMod _).2 ⟨toIcoDiv hp a₂ b, self_sub_toIcoMod hp a₂ b⟩ #align to_Ioc_mod_to_Ico_mod toIocMod_toIcoMod theorem toIcoMod_periodic (a : α) : Function.Periodic (toIcoMod hp a) p := toIcoMod_add_right hp a #align to_Ico_mod_periodic toIcoMod_periodic theorem toIocMod_periodic (a : α) : Function.Periodic (toIocMod hp a) p := toIocMod_add_right hp a #align to_Ioc_mod_periodic toIocMod_periodic -- helper lemmas for when `a = 0` section Zero theorem toIcoMod_zero_sub_comm (a b : α) : toIcoMod hp 0 (a - b) = p - toIocMod hp 0 (b - a) := by rw [← neg_sub, toIcoMod_neg, neg_zero] #align to_Ico_mod_zero_sub_comm toIcoMod_zero_sub_comm theorem toIocMod_zero_sub_comm (a b : α) : toIocMod hp 0 (a - b) = p - toIcoMod hp 0 (b - a) := by rw [← neg_sub, toIocMod_neg, neg_zero] #align to_Ioc_mod_zero_sub_comm toIocMod_zero_sub_comm theorem toIcoDiv_eq_sub (a b : α) : toIcoDiv hp a b = toIcoDiv hp 0 (b - a) := by rw [toIcoDiv_sub_eq_toIcoDiv_add, zero_add] #align to_Ico_div_eq_sub toIcoDiv_eq_sub theorem toIocDiv_eq_sub (a b : α) : toIocDiv hp a b = toIocDiv hp 0 (b - a) := by rw [toIocDiv_sub_eq_toIocDiv_add, zero_add] #align to_Ioc_div_eq_sub toIocDiv_eq_sub theorem toIcoMod_eq_sub (a b : α) : toIcoMod hp a b = toIcoMod hp 0 (b - a) + a := by rw [toIcoMod_sub_eq_sub, zero_add, sub_add_cancel] #align to_Ico_mod_eq_sub toIcoMod_eq_sub
Mathlib/Algebra/Order/ToIntervalMod.lean
784
785
theorem toIocMod_eq_sub (a b : α) : toIocMod hp a b = toIocMod hp 0 (b - a) + a := by
rw [toIocMod_sub_eq_sub, zero_add, sub_add_cancel]
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jeremy Avigad, Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.Order.Field.Defs import Mathlib.Algebra.Order.Group.Instances import Mathlib.Algebra.Order.Group.MinMax import Mathlib.Algebra.Order.Ring.Basic import Mathlib.Data.Finset.Preimage import Mathlib.Order.Interval.Set.Disjoint import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Order.ConditionallyCompleteLattice.Basic import Mathlib.Order.Filter.Bases #align_import order.filter.at_top_bot from "leanprover-community/mathlib"@"1f0096e6caa61e9c849ec2adbd227e960e9dff58" /-! # `Filter.atTop` and `Filter.atBot` filters on preorders, monoids and groups. In this file we define the filters * `Filter.atTop`: corresponds to `n → +∞`; * `Filter.atBot`: corresponds to `n → -∞`. Then we prove many lemmas like “if `f → +∞`, then `f ± c → +∞`”. -/ set_option autoImplicit true variable {ι ι' α β γ : Type*} open Set namespace Filter /-- `atTop` is the filter representing the limit `→ ∞` on an ordered set. It is generated by the collection of up-sets `{b | a ≤ b}`. (The preorder need not have a top element for this to be well defined, and indeed is trivial when a top element exists.) -/ def atTop [Preorder α] : Filter α := ⨅ a, 𝓟 (Ici a) #align filter.at_top Filter.atTop /-- `atBot` is the filter representing the limit `→ -∞` on an ordered set. It is generated by the collection of down-sets `{b | b ≤ a}`. (The preorder need not have a bottom element for this to be well defined, and indeed is trivial when a bottom element exists.) -/ def atBot [Preorder α] : Filter α := ⨅ a, 𝓟 (Iic a) #align filter.at_bot Filter.atBot theorem mem_atTop [Preorder α] (a : α) : { b : α | a ≤ b } ∈ @atTop α _ := mem_iInf_of_mem a <| Subset.refl _ #align filter.mem_at_top Filter.mem_atTop theorem Ici_mem_atTop [Preorder α] (a : α) : Ici a ∈ (atTop : Filter α) := mem_atTop a #align filter.Ici_mem_at_top Filter.Ici_mem_atTop theorem Ioi_mem_atTop [Preorder α] [NoMaxOrder α] (x : α) : Ioi x ∈ (atTop : Filter α) := let ⟨z, hz⟩ := exists_gt x mem_of_superset (mem_atTop z) fun _ h => lt_of_lt_of_le hz h #align filter.Ioi_mem_at_top Filter.Ioi_mem_atTop theorem mem_atBot [Preorder α] (a : α) : { b : α | b ≤ a } ∈ @atBot α _ := mem_iInf_of_mem a <| Subset.refl _ #align filter.mem_at_bot Filter.mem_atBot theorem Iic_mem_atBot [Preorder α] (a : α) : Iic a ∈ (atBot : Filter α) := mem_atBot a #align filter.Iic_mem_at_bot Filter.Iic_mem_atBot theorem Iio_mem_atBot [Preorder α] [NoMinOrder α] (x : α) : Iio x ∈ (atBot : Filter α) := let ⟨z, hz⟩ := exists_lt x mem_of_superset (mem_atBot z) fun _ h => lt_of_le_of_lt h hz #align filter.Iio_mem_at_bot Filter.Iio_mem_atBot theorem disjoint_atBot_principal_Ioi [Preorder α] (x : α) : Disjoint atBot (𝓟 (Ioi x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl) (Iic_mem_atBot x) (mem_principal_self _) #align filter.disjoint_at_bot_principal_Ioi Filter.disjoint_atBot_principal_Ioi theorem disjoint_atTop_principal_Iio [Preorder α] (x : α) : Disjoint atTop (𝓟 (Iio x)) := @disjoint_atBot_principal_Ioi αᵒᵈ _ _ #align filter.disjoint_at_top_principal_Iio Filter.disjoint_atTop_principal_Iio theorem disjoint_atTop_principal_Iic [Preorder α] [NoMaxOrder α] (x : α) : Disjoint atTop (𝓟 (Iic x)) := disjoint_of_disjoint_of_mem (Iic_disjoint_Ioi le_rfl).symm (Ioi_mem_atTop x) (mem_principal_self _) #align filter.disjoint_at_top_principal_Iic Filter.disjoint_atTop_principal_Iic theorem disjoint_atBot_principal_Ici [Preorder α] [NoMinOrder α] (x : α) : Disjoint atBot (𝓟 (Ici x)) := @disjoint_atTop_principal_Iic αᵒᵈ _ _ _ #align filter.disjoint_at_bot_principal_Ici Filter.disjoint_atBot_principal_Ici theorem disjoint_pure_atTop [Preorder α] [NoMaxOrder α] (x : α) : Disjoint (pure x) atTop := Disjoint.symm <| (disjoint_atTop_principal_Iic x).mono_right <| le_principal_iff.2 <| mem_pure.2 right_mem_Iic #align filter.disjoint_pure_at_top Filter.disjoint_pure_atTop theorem disjoint_pure_atBot [Preorder α] [NoMinOrder α] (x : α) : Disjoint (pure x) atBot := @disjoint_pure_atTop αᵒᵈ _ _ _ #align filter.disjoint_pure_at_bot Filter.disjoint_pure_atBot theorem not_tendsto_const_atTop [Preorder α] [NoMaxOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atTop := tendsto_const_pure.not_tendsto (disjoint_pure_atTop x) #align filter.not_tendsto_const_at_top Filter.not_tendsto_const_atTop theorem not_tendsto_const_atBot [Preorder α] [NoMinOrder α] (x : α) (l : Filter β) [l.NeBot] : ¬Tendsto (fun _ => x) l atBot := tendsto_const_pure.not_tendsto (disjoint_pure_atBot x) #align filter.not_tendsto_const_at_bot Filter.not_tendsto_const_atBot theorem disjoint_atBot_atTop [PartialOrder α] [Nontrivial α] : Disjoint (atBot : Filter α) atTop := by rcases exists_pair_ne α with ⟨x, y, hne⟩ by_cases hle : x ≤ y · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot x) (Ici_mem_atTop y) exact Iic_disjoint_Ici.2 (hle.lt_of_ne hne).not_le · refine disjoint_of_disjoint_of_mem ?_ (Iic_mem_atBot y) (Ici_mem_atTop x) exact Iic_disjoint_Ici.2 hle #align filter.disjoint_at_bot_at_top Filter.disjoint_atBot_atTop theorem disjoint_atTop_atBot [PartialOrder α] [Nontrivial α] : Disjoint (atTop : Filter α) atBot := disjoint_atBot_atTop.symm #align filter.disjoint_at_top_at_bot Filter.disjoint_atTop_atBot theorem hasAntitoneBasis_atTop [Nonempty α] [Preorder α] [IsDirected α (· ≤ ·)] : (@atTop α _).HasAntitoneBasis Ici := .iInf_principal fun _ _ ↦ Ici_subset_Ici.2 theorem atTop_basis [Nonempty α] [SemilatticeSup α] : (@atTop α _).HasBasis (fun _ => True) Ici := hasAntitoneBasis_atTop.1 #align filter.at_top_basis Filter.atTop_basis theorem atTop_eq_generate_Ici [SemilatticeSup α] : atTop = generate (range (Ici (α := α))) := by rcases isEmpty_or_nonempty α with hα|hα · simp only [eq_iff_true_of_subsingleton] · simp [(atTop_basis (α := α)).eq_generate, range] theorem atTop_basis' [SemilatticeSup α] (a : α) : (@atTop α _).HasBasis (fun x => a ≤ x) Ici := ⟨fun _ => (@atTop_basis α ⟨a⟩ _).mem_iff.trans ⟨fun ⟨x, _, hx⟩ => ⟨x ⊔ a, le_sup_right, fun _y hy => hx (le_trans le_sup_left hy)⟩, fun ⟨x, _, hx⟩ => ⟨x, trivial, hx⟩⟩⟩ #align filter.at_top_basis' Filter.atTop_basis' theorem atBot_basis [Nonempty α] [SemilatticeInf α] : (@atBot α _).HasBasis (fun _ => True) Iic := @atTop_basis αᵒᵈ _ _ #align filter.at_bot_basis Filter.atBot_basis theorem atBot_basis' [SemilatticeInf α] (a : α) : (@atBot α _).HasBasis (fun x => x ≤ a) Iic := @atTop_basis' αᵒᵈ _ _ #align filter.at_bot_basis' Filter.atBot_basis' @[instance] theorem atTop_neBot [Nonempty α] [SemilatticeSup α] : NeBot (atTop : Filter α) := atTop_basis.neBot_iff.2 fun _ => nonempty_Ici #align filter.at_top_ne_bot Filter.atTop_neBot @[instance] theorem atBot_neBot [Nonempty α] [SemilatticeInf α] : NeBot (atBot : Filter α) := @atTop_neBot αᵒᵈ _ _ #align filter.at_bot_ne_bot Filter.atBot_neBot @[simp] theorem mem_atTop_sets [Nonempty α] [SemilatticeSup α] {s : Set α} : s ∈ (atTop : Filter α) ↔ ∃ a : α, ∀ b ≥ a, b ∈ s := atTop_basis.mem_iff.trans <| exists_congr fun _ => true_and_iff _ #align filter.mem_at_top_sets Filter.mem_atTop_sets @[simp] theorem mem_atBot_sets [Nonempty α] [SemilatticeInf α] {s : Set α} : s ∈ (atBot : Filter α) ↔ ∃ a : α, ∀ b ≤ a, b ∈ s := @mem_atTop_sets αᵒᵈ _ _ _ #align filter.mem_at_bot_sets Filter.mem_atBot_sets @[simp] theorem eventually_atTop [SemilatticeSup α] [Nonempty α] {p : α → Prop} : (∀ᶠ x in atTop, p x) ↔ ∃ a, ∀ b ≥ a, p b := mem_atTop_sets #align filter.eventually_at_top Filter.eventually_atTop @[simp] theorem eventually_atBot [SemilatticeInf α] [Nonempty α] {p : α → Prop} : (∀ᶠ x in atBot, p x) ↔ ∃ a, ∀ b ≤ a, p b := mem_atBot_sets #align filter.eventually_at_bot Filter.eventually_atBot theorem eventually_ge_atTop [Preorder α] (a : α) : ∀ᶠ x in atTop, a ≤ x := mem_atTop a #align filter.eventually_ge_at_top Filter.eventually_ge_atTop theorem eventually_le_atBot [Preorder α] (a : α) : ∀ᶠ x in atBot, x ≤ a := mem_atBot a #align filter.eventually_le_at_bot Filter.eventually_le_atBot theorem eventually_gt_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, a < x := Ioi_mem_atTop a #align filter.eventually_gt_at_top Filter.eventually_gt_atTop theorem eventually_ne_atTop [Preorder α] [NoMaxOrder α] (a : α) : ∀ᶠ x in atTop, x ≠ a := (eventually_gt_atTop a).mono fun _ => ne_of_gt #align filter.eventually_ne_at_top Filter.eventually_ne_atTop protected theorem Tendsto.eventually_gt_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c < f x := hf.eventually (eventually_gt_atTop c) #align filter.tendsto.eventually_gt_at_top Filter.Tendsto.eventually_gt_atTop protected theorem Tendsto.eventually_ge_atTop [Preorder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, c ≤ f x := hf.eventually (eventually_ge_atTop c) #align filter.tendsto.eventually_ge_at_top Filter.Tendsto.eventually_ge_atTop protected theorem Tendsto.eventually_ne_atTop [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : β) : ∀ᶠ x in l, f x ≠ c := hf.eventually (eventually_ne_atTop c) #align filter.tendsto.eventually_ne_at_top Filter.Tendsto.eventually_ne_atTop protected theorem Tendsto.eventually_ne_atTop' [Preorder β] [NoMaxOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atTop) (c : α) : ∀ᶠ x in l, x ≠ c := (hf.eventually_ne_atTop (f c)).mono fun _ => ne_of_apply_ne f #align filter.tendsto.eventually_ne_at_top' Filter.Tendsto.eventually_ne_atTop' theorem eventually_lt_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x < a := Iio_mem_atBot a #align filter.eventually_lt_at_bot Filter.eventually_lt_atBot theorem eventually_ne_atBot [Preorder α] [NoMinOrder α] (a : α) : ∀ᶠ x in atBot, x ≠ a := (eventually_lt_atBot a).mono fun _ => ne_of_lt #align filter.eventually_ne_at_bot Filter.eventually_ne_atBot protected theorem Tendsto.eventually_lt_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x < c := hf.eventually (eventually_lt_atBot c) #align filter.tendsto.eventually_lt_at_bot Filter.Tendsto.eventually_lt_atBot protected theorem Tendsto.eventually_le_atBot [Preorder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≤ c := hf.eventually (eventually_le_atBot c) #align filter.tendsto.eventually_le_at_bot Filter.Tendsto.eventually_le_atBot protected theorem Tendsto.eventually_ne_atBot [Preorder β] [NoMinOrder β] {f : α → β} {l : Filter α} (hf : Tendsto f l atBot) (c : β) : ∀ᶠ x in l, f x ≠ c := hf.eventually (eventually_ne_atBot c) #align filter.tendsto.eventually_ne_at_bot Filter.Tendsto.eventually_ne_atBot
Mathlib/Order/Filter/AtTopBot.lean
253
259
theorem eventually_forall_ge_atTop [Preorder α] {p : α → Prop} : (∀ᶠ x in atTop, ∀ y, x ≤ y → p y) ↔ ∀ᶠ x in atTop, p x := by
refine ⟨fun h ↦ h.mono fun x hx ↦ hx x le_rfl, fun h ↦ ?_⟩ rcases (hasBasis_iInf_principal_finite _).eventually_iff.1 h with ⟨S, hSf, hS⟩ refine mem_iInf_of_iInter hSf (V := fun x ↦ Ici x.1) (fun _ ↦ Subset.rfl) fun x hx y hy ↦ ?_ simp only [mem_iInter] at hS hx exact hS fun z hz ↦ le_trans (hx ⟨z, hz⟩) hy
/- Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Sara Rousta -/ import Mathlib.Data.SetLike.Basic import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Interval.Set.OrderIso import Mathlib.Data.Set.Lattice #align_import order.upper_lower.basic from "leanprover-community/mathlib"@"c0c52abb75074ed8b73a948341f50521fbf43b4c" /-! # Up-sets and down-sets This file defines upper and lower sets in an order. ## Main declarations * `IsUpperSet`: Predicate for a set to be an upper set. This means every element greater than a member of the set is in the set itself. * `IsLowerSet`: Predicate for a set to be a lower set. This means every element less than a member of the set is in the set itself. * `UpperSet`: The type of upper sets. * `LowerSet`: The type of lower sets. * `upperClosure`: The greatest upper set containing a set. * `lowerClosure`: The least lower set containing a set. * `UpperSet.Ici`: Principal upper set. `Set.Ici` as an upper set. * `UpperSet.Ioi`: Strict principal upper set. `Set.Ioi` as an upper set. * `LowerSet.Iic`: Principal lower set. `Set.Iic` as a lower set. * `LowerSet.Iio`: Strict principal lower set. `Set.Iio` as a lower set. ## Notation * `×ˢ` is notation for `UpperSet.prod` / `LowerSet.prod`. ## Notes Upper sets are ordered by **reverse** inclusion. This convention is motivated by the fact that this makes them order-isomorphic to lower sets and antichains, and matches the convention on `Filter`. ## TODO Lattice structure on antichains. Order equivalence between upper/lower sets and antichains. -/ open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} {κ : ι → Sort*} /-! ### Unbundled upper/lower sets -/ section LE variable [LE α] [LE β] {s t : Set α} {a : α} /-- An upper set in an order `α` is a set such that any element greater than one of its members is also a member. Also called up-set, upward-closed set. -/ @[aesop norm unfold] def IsUpperSet (s : Set α) : Prop := ∀ ⦃a b : α⦄, a ≤ b → a ∈ s → b ∈ s #align is_upper_set IsUpperSet /-- A lower set in an order `α` is a set such that any element less than one of its members is also a member. Also called down-set, downward-closed set. -/ @[aesop norm unfold] def IsLowerSet (s : Set α) : Prop := ∀ ⦃a b : α⦄, b ≤ a → a ∈ s → b ∈ s #align is_lower_set IsLowerSet theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id #align is_upper_set_empty isUpperSet_empty theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id #align is_lower_set_empty isLowerSet_empty theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id #align is_upper_set_univ isUpperSet_univ theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id #align is_lower_set_univ isLowerSet_univ theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha #align is_upper_set.compl IsUpperSet.compl theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha #align is_lower_set.compl IsLowerSet.compl @[simp] theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsLowerSet.compl⟩ #align is_upper_set_compl isUpperSet_compl @[simp] theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsUpperSet.compl⟩ #align is_lower_set_compl isLowerSet_compl theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) #align is_upper_set.union IsUpperSet.union theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) #align is_lower_set.union IsLowerSet.union theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) #align is_upper_set.inter IsUpperSet.inter theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) #align is_lower_set.inter IsLowerSet.inter theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ #align is_upper_set_sUnion isUpperSet_sUnion theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ #align is_lower_set_sUnion isLowerSet_sUnion theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) := isUpperSet_sUnion <| forall_mem_range.2 hf #align is_upper_set_Union isUpperSet_iUnion theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) := isLowerSet_sUnion <| forall_mem_range.2 hf #align is_lower_set_Union isLowerSet_iUnion theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋃ (i) (j), f i j) := isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i #align is_upper_set_Union₂ isUpperSet_iUnion₂ theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋃ (i) (j), f i j) := isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i #align is_lower_set_Union₂ isLowerSet_iUnion₂ theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h #align is_upper_set_sInter isUpperSet_sInter theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h #align is_lower_set_sInter isLowerSet_sInter theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) := isUpperSet_sInter <| forall_mem_range.2 hf #align is_upper_set_Inter isUpperSet_iInter theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) := isLowerSet_sInter <| forall_mem_range.2 hf #align is_lower_set_Inter isLowerSet_iInter theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋂ (i) (j), f i j) := isUpperSet_iInter fun i => isUpperSet_iInter <| hf i #align is_upper_set_Inter₂ isUpperSet_iInter₂ theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋂ (i) (j), f i j) := isLowerSet_iInter fun i => isLowerSet_iInter <| hf i #align is_lower_set_Inter₂ isLowerSet_iInter₂ @[simp] theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl #align is_lower_set_preimage_of_dual_iff isLowerSet_preimage_ofDual_iff @[simp] theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl #align is_upper_set_preimage_of_dual_iff isUpperSet_preimage_ofDual_iff @[simp] theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl #align is_lower_set_preimage_to_dual_iff isLowerSet_preimage_toDual_iff @[simp] theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl #align is_upper_set_preimage_to_dual_iff isUpperSet_preimage_toDual_iff alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff #align is_upper_set.to_dual IsUpperSet.toDual alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff #align is_lower_set.to_dual IsLowerSet.toDual alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff #align is_upper_set.of_dual IsUpperSet.ofDual alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff #align is_lower_set.of_dual IsLowerSet.ofDual lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) : IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) : IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : IsUpperSet (s \ t) := fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩ lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : IsLowerSet (s \ t) := fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩ lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) := hs.sdiff <| by aesop lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) := hs.sdiff <| by aesop lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) := hs.sdiff <| by simpa using has lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) := hs.sdiff <| by simpa using has end LE section Preorder variable [Preorder α] [Preorder β] {s : Set α} {p : α → Prop} (a : α) theorem isUpperSet_Ici : IsUpperSet (Ici a) := fun _ _ => ge_trans #align is_upper_set_Ici isUpperSet_Ici theorem isLowerSet_Iic : IsLowerSet (Iic a) := fun _ _ => le_trans #align is_lower_set_Iic isLowerSet_Iic theorem isUpperSet_Ioi : IsUpperSet (Ioi a) := fun _ _ => flip lt_of_lt_of_le #align is_upper_set_Ioi isUpperSet_Ioi theorem isLowerSet_Iio : IsLowerSet (Iio a) := fun _ _ => lt_of_le_of_lt #align is_lower_set_Iio isLowerSet_Iio theorem isUpperSet_iff_Ici_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ici a ⊆ s := by simp [IsUpperSet, subset_def, @forall_swap (_ ∈ s)] #align is_upper_set_iff_Ici_subset isUpperSet_iff_Ici_subset theorem isLowerSet_iff_Iic_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iic a ⊆ s := by simp [IsLowerSet, subset_def, @forall_swap (_ ∈ s)] #align is_lower_set_iff_Iic_subset isLowerSet_iff_Iic_subset alias ⟨IsUpperSet.Ici_subset, _⟩ := isUpperSet_iff_Ici_subset #align is_upper_set.Ici_subset IsUpperSet.Ici_subset alias ⟨IsLowerSet.Iic_subset, _⟩ := isLowerSet_iff_Iic_subset #align is_lower_set.Iic_subset IsLowerSet.Iic_subset theorem IsUpperSet.Ioi_subset (h : IsUpperSet s) ⦃a⦄ (ha : a ∈ s) : Ioi a ⊆ s := Ioi_subset_Ici_self.trans <| h.Ici_subset ha #align is_upper_set.Ioi_subset IsUpperSet.Ioi_subset theorem IsLowerSet.Iio_subset (h : IsLowerSet s) ⦃a⦄ (ha : a ∈ s) : Iio a ⊆ s := h.toDual.Ioi_subset ha #align is_lower_set.Iio_subset IsLowerSet.Iio_subset theorem IsUpperSet.ordConnected (h : IsUpperSet s) : s.OrdConnected := ⟨fun _ ha _ _ => Icc_subset_Ici_self.trans <| h.Ici_subset ha⟩ #align is_upper_set.ord_connected IsUpperSet.ordConnected theorem IsLowerSet.ordConnected (h : IsLowerSet s) : s.OrdConnected := ⟨fun _ _ _ hb => Icc_subset_Iic_self.trans <| h.Iic_subset hb⟩ #align is_lower_set.ord_connected IsLowerSet.ordConnected theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f) : IsUpperSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h #align is_upper_set.preimage IsUpperSet.preimage theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) : IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h #align is_lower_set.preimage IsLowerSet.preimage theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by change IsUpperSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone #align is_upper_set.image IsUpperSet.image theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by change IsLowerSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone #align is_lower_set.image IsLowerSet.image theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ici a = Ici (e a) := by rw [← e.preimage_Ici, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ici_subset (mem_range_self _)] theorem OrderEmbedding.image_Iic (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iic a = Iic (e a) := e.dual.image_Ici he a theorem OrderEmbedding.image_Ioi (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ioi a = Ioi (e a) := by rw [← e.preimage_Ioi, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ioi_subset (mem_range_self _)] theorem OrderEmbedding.image_Iio (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iio a = Iio (e a) := e.dual.image_Ioi he a @[simp] theorem Set.monotone_mem : Monotone (· ∈ s) ↔ IsUpperSet s := Iff.rfl #align set.monotone_mem Set.monotone_mem @[simp] theorem Set.antitone_mem : Antitone (· ∈ s) ↔ IsLowerSet s := forall_swap #align set.antitone_mem Set.antitone_mem @[simp] theorem isUpperSet_setOf : IsUpperSet { a | p a } ↔ Monotone p := Iff.rfl #align is_upper_set_set_of isUpperSet_setOf @[simp] theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p := forall_swap #align is_lower_set_set_of isLowerSet_setOf lemma IsUpperSet.upperBounds_subset (hs : IsUpperSet s) : s.Nonempty → upperBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha lemma IsLowerSet.lowerBounds_subset (hs : IsLowerSet s) : s.Nonempty → lowerBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha section OrderTop variable [OrderTop α] theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩ #align is_lower_set.top_mem IsLowerSet.top_mem theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩ #align is_upper_set.top_mem IsUpperSet.top_mem theorem IsUpperSet.not_top_mem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ := hs.top_mem.not.trans not_nonempty_iff_eq_empty #align is_upper_set.not_top_mem IsUpperSet.not_top_mem end OrderTop section OrderBot variable [OrderBot α] theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩ #align is_upper_set.bot_mem IsUpperSet.bot_mem theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩ #align is_lower_set.bot_mem IsLowerSet.bot_mem theorem IsLowerSet.not_bot_mem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ := hs.bot_mem.not.trans not_nonempty_iff_eq_empty #align is_lower_set.not_bot_mem IsLowerSet.not_bot_mem end OrderBot section NoMaxOrder variable [NoMaxOrder α] theorem IsUpperSet.not_bddAbove (hs : IsUpperSet s) : s.Nonempty → ¬BddAbove s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_gt b exact hc.not_le (hb <| hs ((hb ha).trans hc.le) ha) #align is_upper_set.not_bdd_above IsUpperSet.not_bddAbove theorem not_bddAbove_Ici : ¬BddAbove (Ici a) := (isUpperSet_Ici _).not_bddAbove nonempty_Ici #align not_bdd_above_Ici not_bddAbove_Ici theorem not_bddAbove_Ioi : ¬BddAbove (Ioi a) := (isUpperSet_Ioi _).not_bddAbove nonempty_Ioi #align not_bdd_above_Ioi not_bddAbove_Ioi end NoMaxOrder section NoMinOrder variable [NoMinOrder α] theorem IsLowerSet.not_bddBelow (hs : IsLowerSet s) : s.Nonempty → ¬BddBelow s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_lt b exact hc.not_le (hb <| hs (hc.le.trans <| hb ha) ha) #align is_lower_set.not_bdd_below IsLowerSet.not_bddBelow theorem not_bddBelow_Iic : ¬BddBelow (Iic a) := (isLowerSet_Iic _).not_bddBelow nonempty_Iic #align not_bdd_below_Iic not_bddBelow_Iic theorem not_bddBelow_Iio : ¬BddBelow (Iio a) := (isLowerSet_Iio _).not_bddBelow nonempty_Iio #align not_bdd_below_Iio not_bddBelow_Iio end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] #align is_upper_set_iff_forall_lt isUpperSet_iff_forall_lt theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] #align is_lower_set_iff_forall_lt isLowerSet_iff_forall_lt theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] #align is_upper_set_iff_Ioi_subset isUpperSet_iff_Ioi_subset theorem isLowerSet_iff_Iio_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iio a ⊆ s := by simp [isLowerSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] #align is_lower_set_iff_Iio_subset isLowerSet_iff_Iio_subset end PartialOrder section LinearOrder variable [LinearOrder α] {s t : Set α} theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by by_contra! h simp_rw [Set.not_subset] at h obtain ⟨⟨a, has, hat⟩, b, hbt, hbs⟩ := h obtain hab | hba := le_total a b · exact hbs (hs hab has) · exact hat (ht hba hbt) #align is_upper_set.total IsUpperSet.total theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s := hs.toDual.total ht.toDual #align is_lower_set.total IsLowerSet.total end LinearOrder /-! ### Bundled upper/lower sets -/ section LE variable [LE α] /-- The type of upper sets of an order. -/ structure UpperSet (α : Type*) [LE α] where /-- The carrier of an `UpperSet`. -/ carrier : Set α /-- The carrier of an `UpperSet` is an upper set. -/ upper' : IsUpperSet carrier #align upper_set UpperSet /-- The type of lower sets of an order. -/ structure LowerSet (α : Type*) [LE α] where /-- The carrier of a `LowerSet`. -/ carrier : Set α /-- The carrier of a `LowerSet` is a lower set. -/ lower' : IsLowerSet carrier #align lower_set LowerSet namespace UpperSet instance : SetLike (UpperSet α) α where coe := UpperSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : UpperSet α) : Set α := s initialize_simps_projections UpperSet (carrier → coe) @[ext] theorem ext {s t : UpperSet α} : (s : Set α) = t → s = t := SetLike.ext' #align upper_set.ext UpperSet.ext @[simp] theorem carrier_eq_coe (s : UpperSet α) : s.carrier = s := rfl #align upper_set.carrier_eq_coe UpperSet.carrier_eq_coe @[simp] protected lemma upper (s : UpperSet α) : IsUpperSet (s : Set α) := s.upper' #align upper_set.upper UpperSet.upper @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl #align upper_set.mem_mk UpperSet.mem_mk end UpperSet namespace LowerSet instance : SetLike (LowerSet α) α where coe := LowerSet.carrier coe_injective' s t h := by cases s; cases t; congr /-- See Note [custom simps projection]. -/ def Simps.coe (s : LowerSet α) : Set α := s initialize_simps_projections LowerSet (carrier → coe) @[ext] theorem ext {s t : LowerSet α} : (s : Set α) = t → s = t := SetLike.ext' #align lower_set.ext LowerSet.ext @[simp] theorem carrier_eq_coe (s : LowerSet α) : s.carrier = s := rfl #align lower_set.carrier_eq_coe LowerSet.carrier_eq_coe @[simp] protected lemma lower (s : LowerSet α) : IsLowerSet (s : Set α) := s.lower' #align lower_set.lower LowerSet.lower @[simp, norm_cast] lemma coe_mk (s : Set α) (hs) : mk s hs = s := rfl @[simp] lemma mem_mk {s : Set α} (hs) {a : α} : a ∈ mk s hs ↔ a ∈ s := Iff.rfl #align lower_set.mem_mk LowerSet.mem_mk end LowerSet /-! #### Order -/ namespace UpperSet variable {S : Set (UpperSet α)} {s t : UpperSet α} {a : α} instance : Sup (UpperSet α) := ⟨fun s t => ⟨s ∩ t, s.upper.inter t.upper⟩⟩ instance : Inf (UpperSet α) := ⟨fun s t => ⟨s ∪ t, s.upper.union t.upper⟩⟩ instance : Top (UpperSet α) := ⟨⟨∅, isUpperSet_empty⟩⟩ instance : Bot (UpperSet α) := ⟨⟨univ, isUpperSet_univ⟩⟩ instance : SupSet (UpperSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isUpperSet_iInter₂ fun s _ => s.upper⟩⟩ instance : InfSet (UpperSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isUpperSet_iUnion₂ fun s _ => s.upper⟩⟩ instance completelyDistribLattice : CompletelyDistribLattice (UpperSet α) := (toDual.injective.comp SetLike.coe_injective).completelyDistribLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (UpperSet α) := ⟨⊥⟩ @[simp 1100, norm_cast] theorem coe_subset_coe : (s : Set α) ⊆ t ↔ t ≤ s := Iff.rfl #align upper_set.coe_subset_coe UpperSet.coe_subset_coe @[simp 1100, norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ t < s := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : UpperSet α) : Set α) = ∅ := rfl #align upper_set.coe_top UpperSet.coe_top @[simp, norm_cast] theorem coe_bot : ((⊥ : UpperSet α) : Set α) = univ := rfl #align upper_set.coe_bot UpperSet.coe_bot @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊥ := by simp [SetLike.ext'_iff] #align upper_set.coe_eq_univ UpperSet.coe_eq_univ @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊤ := by simp [SetLike.ext'_iff] #align upper_set.coe_eq_empty UpperSet.coe_eq_empty @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊤ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : UpperSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∩ t := rfl #align upper_set.coe_sup UpperSet.coe_sup @[simp, norm_cast] theorem coe_inf (s t : UpperSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∪ t := rfl #align upper_set.coe_inf UpperSet.coe_inf @[simp, norm_cast] theorem coe_sSup (S : Set (UpperSet α)) : (↑(sSup S) : Set α) = ⋂ s ∈ S, ↑s := rfl #align upper_set.coe_Sup UpperSet.coe_sSup @[simp, norm_cast] theorem coe_sInf (S : Set (UpperSet α)) : (↑(sInf S) : Set α) = ⋃ s ∈ S, ↑s := rfl #align upper_set.coe_Inf UpperSet.coe_sInf @[simp, norm_cast] theorem coe_iSup (f : ι → UpperSet α) : (↑(⨆ i, f i) : Set α) = ⋂ i, f i := by simp [iSup] #align upper_set.coe_supr UpperSet.coe_iSup @[simp, norm_cast] theorem coe_iInf (f : ι → UpperSet α) : (↑(⨅ i, f i) : Set α) = ⋃ i, f i := by simp [iInf] #align upper_set.coe_infi UpperSet.coe_iInf @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iSup₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iSup] #align upper_set.coe_supr₂ UpperSet.coe_iSup₂ @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iInf₂ (f : ∀ i, κ i → UpperSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iInf] #align upper_set.coe_infi₂ UpperSet.coe_iInf₂ @[simp] theorem not_mem_top : a ∉ (⊤ : UpperSet α) := id #align upper_set.not_mem_top UpperSet.not_mem_top @[simp] theorem mem_bot : a ∈ (⊥ : UpperSet α) := trivial #align upper_set.mem_bot UpperSet.mem_bot @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl #align upper_set.mem_sup_iff UpperSet.mem_sup_iff @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl #align upper_set.mem_inf_iff UpperSet.mem_inf_iff @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ #align upper_set.mem_Sup_iff UpperSet.mem_sSup_iff @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] #align upper_set.mem_Inf_iff UpperSet.mem_sInf_iff @[simp] theorem mem_iSup_iff {f : ι → UpperSet α} : (a ∈ ⨆ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iInter #align upper_set.mem_supr_iff UpperSet.mem_iSup_iff @[simp] theorem mem_iInf_iff {f : ι → UpperSet α} : (a ∈ ⨅ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iUnion #align upper_set.mem_infi_iff UpperSet.mem_iInf_iff -- Porting note: no longer a @[simp] theorem mem_iSup₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp_rw [mem_iSup_iff] #align upper_set.mem_supr₂_iff UpperSet.mem_iSup₂_iff -- Porting note: no longer a @[simp] theorem mem_iInf₂_iff {f : ∀ i, κ i → UpperSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp_rw [mem_iInf_iff] #align upper_set.mem_infi₂_iff UpperSet.mem_iInf₂_iff @[simp, norm_cast] theorem codisjoint_coe : Codisjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, codisjoint_iff, SetLike.ext'_iff] #align upper_set.codisjoint_coe UpperSet.codisjoint_coe end UpperSet namespace LowerSet variable {S : Set (LowerSet α)} {s t : LowerSet α} {a : α} instance : Sup (LowerSet α) := ⟨fun s t => ⟨s ∪ t, fun _ _ h => Or.imp (s.lower h) (t.lower h)⟩⟩ instance : Inf (LowerSet α) := ⟨fun s t => ⟨s ∩ t, fun _ _ h => And.imp (s.lower h) (t.lower h)⟩⟩ instance : Top (LowerSet α) := ⟨⟨univ, fun _ _ _ => id⟩⟩ instance : Bot (LowerSet α) := ⟨⟨∅, fun _ _ _ => id⟩⟩ instance : SupSet (LowerSet α) := ⟨fun S => ⟨⋃ s ∈ S, ↑s, isLowerSet_iUnion₂ fun s _ => s.lower⟩⟩ instance : InfSet (LowerSet α) := ⟨fun S => ⟨⋂ s ∈ S, ↑s, isLowerSet_iInter₂ fun s _ => s.lower⟩⟩ instance completelyDistribLattice : CompletelyDistribLattice (LowerSet α) := SetLike.coe_injective.completelyDistribLattice _ (fun _ _ => rfl) (fun _ _ => rfl) (fun _ => rfl) (fun _ => rfl) rfl rfl instance : Inhabited (LowerSet α) := ⟨⊥⟩ @[norm_cast] lemma coe_subset_coe : (s : Set α) ⊆ t ↔ s ≤ t := Iff.rfl #align lower_set.coe_subset_coe LowerSet.coe_subset_coe @[norm_cast] lemma coe_ssubset_coe : (s : Set α) ⊂ t ↔ s < t := Iff.rfl @[simp, norm_cast] theorem coe_top : ((⊤ : LowerSet α) : Set α) = univ := rfl #align lower_set.coe_top LowerSet.coe_top @[simp, norm_cast] theorem coe_bot : ((⊥ : LowerSet α) : Set α) = ∅ := rfl #align lower_set.coe_bot LowerSet.coe_bot @[simp, norm_cast] theorem coe_eq_univ : (s : Set α) = univ ↔ s = ⊤ := by simp [SetLike.ext'_iff] #align lower_set.coe_eq_univ LowerSet.coe_eq_univ @[simp, norm_cast] theorem coe_eq_empty : (s : Set α) = ∅ ↔ s = ⊥ := by simp [SetLike.ext'_iff] #align lower_set.coe_eq_empty LowerSet.coe_eq_empty @[simp, norm_cast] lemma coe_nonempty : (s : Set α).Nonempty ↔ s ≠ ⊥ := nonempty_iff_ne_empty.trans coe_eq_empty.not @[simp, norm_cast] theorem coe_sup (s t : LowerSet α) : (↑(s ⊔ t) : Set α) = (s : Set α) ∪ t := rfl #align lower_set.coe_sup LowerSet.coe_sup @[simp, norm_cast] theorem coe_inf (s t : LowerSet α) : (↑(s ⊓ t) : Set α) = (s : Set α) ∩ t := rfl #align lower_set.coe_inf LowerSet.coe_inf @[simp, norm_cast] theorem coe_sSup (S : Set (LowerSet α)) : (↑(sSup S) : Set α) = ⋃ s ∈ S, ↑s := rfl #align lower_set.coe_Sup LowerSet.coe_sSup @[simp, norm_cast] theorem coe_sInf (S : Set (LowerSet α)) : (↑(sInf S) : Set α) = ⋂ s ∈ S, ↑s := rfl #align lower_set.coe_Inf LowerSet.coe_sInf @[simp, norm_cast] theorem coe_iSup (f : ι → LowerSet α) : (↑(⨆ i, f i) : Set α) = ⋃ i, f i := by simp_rw [iSup, coe_sSup, mem_range, iUnion_exists, iUnion_iUnion_eq'] #align lower_set.coe_supr LowerSet.coe_iSup @[simp, norm_cast] theorem coe_iInf (f : ι → LowerSet α) : (↑(⨅ i, f i) : Set α) = ⋂ i, f i := by simp_rw [iInf, coe_sInf, mem_range, iInter_exists, iInter_iInter_eq'] #align lower_set.coe_infi LowerSet.coe_iInf @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iSup₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨆ (i) (j), f i j) : Set α) = ⋃ (i) (j), f i j := by simp_rw [coe_iSup] #align lower_set.coe_supr₂ LowerSet.coe_iSup₂ @[norm_cast] -- Porting note: no longer a `simp` theorem coe_iInf₂ (f : ∀ i, κ i → LowerSet α) : (↑(⨅ (i) (j), f i j) : Set α) = ⋂ (i) (j), f i j := by simp_rw [coe_iInf] #align lower_set.coe_infi₂ LowerSet.coe_iInf₂ @[simp] theorem mem_top : a ∈ (⊤ : LowerSet α) := trivial #align lower_set.mem_top LowerSet.mem_top @[simp] theorem not_mem_bot : a ∉ (⊥ : LowerSet α) := id #align lower_set.not_mem_bot LowerSet.not_mem_bot @[simp] theorem mem_sup_iff : a ∈ s ⊔ t ↔ a ∈ s ∨ a ∈ t := Iff.rfl #align lower_set.mem_sup_iff LowerSet.mem_sup_iff @[simp] theorem mem_inf_iff : a ∈ s ⊓ t ↔ a ∈ s ∧ a ∈ t := Iff.rfl #align lower_set.mem_inf_iff LowerSet.mem_inf_iff @[simp] theorem mem_sSup_iff : a ∈ sSup S ↔ ∃ s ∈ S, a ∈ s := mem_iUnion₂.trans <| by simp only [exists_prop, SetLike.mem_coe] #align lower_set.mem_Sup_iff LowerSet.mem_sSup_iff @[simp] theorem mem_sInf_iff : a ∈ sInf S ↔ ∀ s ∈ S, a ∈ s := mem_iInter₂ #align lower_set.mem_Inf_iff LowerSet.mem_sInf_iff @[simp] theorem mem_iSup_iff {f : ι → LowerSet α} : (a ∈ ⨆ i, f i) ↔ ∃ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iSup] exact mem_iUnion #align lower_set.mem_supr_iff LowerSet.mem_iSup_iff @[simp] theorem mem_iInf_iff {f : ι → LowerSet α} : (a ∈ ⨅ i, f i) ↔ ∀ i, a ∈ f i := by rw [← SetLike.mem_coe, coe_iInf] exact mem_iInter #align lower_set.mem_infi_iff LowerSet.mem_iInf_iff -- Porting note: no longer a @[simp] theorem mem_iSup₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨆ (i) (j), f i j) ↔ ∃ i j, a ∈ f i j := by simp_rw [mem_iSup_iff] #align lower_set.mem_supr₂_iff LowerSet.mem_iSup₂_iff -- Porting note: no longer a @[simp] theorem mem_iInf₂_iff {f : ∀ i, κ i → LowerSet α} : (a ∈ ⨅ (i) (j), f i j) ↔ ∀ i j, a ∈ f i j := by simp_rw [mem_iInf_iff] #align lower_set.mem_infi₂_iff LowerSet.mem_iInf₂_iff @[simp, norm_cast] theorem disjoint_coe : Disjoint (s : Set α) t ↔ Disjoint s t := by simp [disjoint_iff, SetLike.ext'_iff] #align lower_set.disjoint_coe LowerSet.disjoint_coe end LowerSet /-! #### Complement -/ /-- The complement of a lower set as an upper set. -/ def UpperSet.compl (s : UpperSet α) : LowerSet α := ⟨sᶜ, s.upper.compl⟩ #align upper_set.compl UpperSet.compl /-- The complement of a lower set as an upper set. -/ def LowerSet.compl (s : LowerSet α) : UpperSet α := ⟨sᶜ, s.lower.compl⟩ #align lower_set.compl LowerSet.compl namespace UpperSet variable {s t : UpperSet α} {a : α} @[simp] theorem coe_compl (s : UpperSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl #align upper_set.coe_compl UpperSet.coe_compl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl #align upper_set.mem_compl_iff UpperSet.mem_compl_iff @[simp] nonrec theorem compl_compl (s : UpperSet α) : s.compl.compl = s := UpperSet.ext <| compl_compl _ #align upper_set.compl_compl UpperSet.compl_compl @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl #align upper_set.compl_le_compl UpperSet.compl_le_compl @[simp] protected theorem compl_sup (s t : UpperSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := LowerSet.ext compl_inf #align upper_set.compl_sup UpperSet.compl_sup @[simp] protected theorem compl_inf (s t : UpperSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := LowerSet.ext compl_sup #align upper_set.compl_inf UpperSet.compl_inf @[simp] protected theorem compl_top : (⊤ : UpperSet α).compl = ⊤ := LowerSet.ext compl_empty #align upper_set.compl_top UpperSet.compl_top @[simp] protected theorem compl_bot : (⊥ : UpperSet α).compl = ⊥ := LowerSet.ext compl_univ #align upper_set.compl_bot UpperSet.compl_bot @[simp] protected theorem compl_sSup (S : Set (UpperSet α)) : (sSup S).compl = ⨆ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sSup, compl_iInter₂, LowerSet.coe_iSup₂] #align upper_set.compl_Sup UpperSet.compl_sSup @[simp] protected theorem compl_sInf (S : Set (UpperSet α)) : (sInf S).compl = ⨅ s ∈ S, UpperSet.compl s := LowerSet.ext <| by simp only [coe_compl, coe_sInf, compl_iUnion₂, LowerSet.coe_iInf₂] #align upper_set.compl_Inf UpperSet.compl_sInf @[simp] protected theorem compl_iSup (f : ι → UpperSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iSup, compl_iInter, LowerSet.coe_iSup] #align upper_set.compl_supr UpperSet.compl_iSup @[simp] protected theorem compl_iInf (f : ι → UpperSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := LowerSet.ext <| by simp only [coe_compl, coe_iInf, compl_iUnion, LowerSet.coe_iInf] #align upper_set.compl_infi UpperSet.compl_iInf -- Porting note: no longer a @[simp] theorem compl_iSup₂ (f : ∀ i, κ i → UpperSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by simp_rw [UpperSet.compl_iSup] #align upper_set.compl_supr₂ UpperSet.compl_iSup₂ -- Porting note: no longer a @[simp] theorem compl_iInf₂ (f : ∀ i, κ i → UpperSet α) : (⨅ (i) (j), f i j).compl = ⨅ (i) (j), (f i j).compl := by simp_rw [UpperSet.compl_iInf] #align upper_set.compl_infi₂ UpperSet.compl_iInf₂ end UpperSet namespace LowerSet variable {s t : LowerSet α} {a : α} @[simp] theorem coe_compl (s : LowerSet α) : (s.compl : Set α) = (↑s)ᶜ := rfl #align lower_set.coe_compl LowerSet.coe_compl @[simp] theorem mem_compl_iff : a ∈ s.compl ↔ a ∉ s := Iff.rfl #align lower_set.mem_compl_iff LowerSet.mem_compl_iff @[simp] nonrec theorem compl_compl (s : LowerSet α) : s.compl.compl = s := LowerSet.ext <| compl_compl _ #align lower_set.compl_compl LowerSet.compl_compl @[simp] theorem compl_le_compl : s.compl ≤ t.compl ↔ s ≤ t := compl_subset_compl #align lower_set.compl_le_compl LowerSet.compl_le_compl protected theorem compl_sup (s t : LowerSet α) : (s ⊔ t).compl = s.compl ⊔ t.compl := UpperSet.ext compl_sup #align lower_set.compl_sup LowerSet.compl_sup protected theorem compl_inf (s t : LowerSet α) : (s ⊓ t).compl = s.compl ⊓ t.compl := UpperSet.ext compl_inf #align lower_set.compl_inf LowerSet.compl_inf protected theorem compl_top : (⊤ : LowerSet α).compl = ⊤ := UpperSet.ext compl_univ #align lower_set.compl_top LowerSet.compl_top protected theorem compl_bot : (⊥ : LowerSet α).compl = ⊥ := UpperSet.ext compl_empty #align lower_set.compl_bot LowerSet.compl_bot protected theorem compl_sSup (S : Set (LowerSet α)) : (sSup S).compl = ⨆ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sSup, compl_iUnion₂, UpperSet.coe_iSup₂] #align lower_set.compl_Sup LowerSet.compl_sSup protected theorem compl_sInf (S : Set (LowerSet α)) : (sInf S).compl = ⨅ s ∈ S, LowerSet.compl s := UpperSet.ext <| by simp only [coe_compl, coe_sInf, compl_iInter₂, UpperSet.coe_iInf₂] #align lower_set.compl_Inf LowerSet.compl_sInf protected theorem compl_iSup (f : ι → LowerSet α) : (⨆ i, f i).compl = ⨆ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iSup, compl_iUnion, UpperSet.coe_iSup] #align lower_set.compl_supr LowerSet.compl_iSup protected theorem compl_iInf (f : ι → LowerSet α) : (⨅ i, f i).compl = ⨅ i, (f i).compl := UpperSet.ext <| by simp only [coe_compl, coe_iInf, compl_iInter, UpperSet.coe_iInf] #align lower_set.compl_infi LowerSet.compl_iInf @[simp]
Mathlib/Order/UpperLower/Basic.lean
998
999
theorem compl_iSup₂ (f : ∀ i, κ i → LowerSet α) : (⨆ (i) (j), f i j).compl = ⨆ (i) (j), (f i j).compl := by
simp_rw [LowerSet.compl_iSup]
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Jens Wagemaker -/ import Mathlib.Algebra.Group.Even import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.GroupWithZero.Hom import Mathlib.Algebra.Group.Commute.Units import Mathlib.Algebra.Group.Units.Hom import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Ring.Units #align_import algebra.associated from "leanprover-community/mathlib"@"2f3994e1b117b1e1da49bcfb67334f33460c3ce4" /-! # Associated, prime, and irreducible elements. In this file we define the predicate `Prime p` saying that an element of a commutative monoid with zero is prime. Namely, `Prime p` means that `p` isn't zero, it isn't a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`; In decomposition monoids (e.g., `ℕ`, `ℤ`), this predicate is equivalent to `Irreducible`, however this is not true in general. We also define an equivalence relation `Associated` saying that two elements of a monoid differ by a multiplication by a unit. Then we show that the quotient type `Associates` is a monoid and prove basic properties of this quotient. -/ variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} section Prime variable [CommMonoidWithZero α] /-- An element `p` of a commutative monoid with zero (e.g., a ring) is called *prime*, if it's not zero, not a unit, and `p ∣ a * b → p ∣ a ∨ p ∣ b` for all `a`, `b`. -/ def Prime (p : α) : Prop := p ≠ 0 ∧ ¬IsUnit p ∧ ∀ a b, p ∣ a * b → p ∣ a ∨ p ∣ b #align prime Prime namespace Prime variable {p : α} (hp : Prime p) theorem ne_zero : p ≠ 0 := hp.1 #align prime.ne_zero Prime.ne_zero theorem not_unit : ¬IsUnit p := hp.2.1 #align prime.not_unit Prime.not_unit theorem not_dvd_one : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align prime.not_dvd_one Prime.not_dvd_one theorem ne_one : p ≠ 1 := fun h => hp.2.1 (h.symm ▸ isUnit_one) #align prime.ne_one Prime.ne_one theorem dvd_or_dvd (hp : Prime p) {a b : α} (h : p ∣ a * b) : p ∣ a ∨ p ∣ b := hp.2.2 a b h #align prime.dvd_or_dvd Prime.dvd_or_dvd theorem dvd_mul {a b : α} : p ∣ a * b ↔ p ∣ a ∨ p ∣ b := ⟨hp.dvd_or_dvd, (Or.elim · (dvd_mul_of_dvd_left · _) (dvd_mul_of_dvd_right · _))⟩ theorem isPrimal (hp : Prime p) : IsPrimal p := fun _a _b dvd ↦ (hp.dvd_or_dvd dvd).elim (fun h ↦ ⟨p, 1, h, one_dvd _, (mul_one p).symm⟩) fun h ↦ ⟨1, p, one_dvd _, h, (one_mul p).symm⟩ theorem not_dvd_mul {a b : α} (ha : ¬ p ∣ a) (hb : ¬ p ∣ b) : ¬ p ∣ a * b := hp.dvd_mul.not.mpr <| not_or.mpr ⟨ha, hb⟩ theorem dvd_of_dvd_pow (hp : Prime p) {a : α} {n : ℕ} (h : p ∣ a ^ n) : p ∣ a := by induction' n with n ih · rw [pow_zero] at h have := isUnit_of_dvd_one h have := not_unit hp contradiction rw [pow_succ'] at h cases' dvd_or_dvd hp h with dvd_a dvd_pow · assumption exact ih dvd_pow #align prime.dvd_of_dvd_pow Prime.dvd_of_dvd_pow theorem dvd_pow_iff_dvd {a : α} {n : ℕ} (hn : n ≠ 0) : p ∣ a ^ n ↔ p ∣ a := ⟨hp.dvd_of_dvd_pow, (dvd_pow · hn)⟩ end Prime @[simp] theorem not_prime_zero : ¬Prime (0 : α) := fun h => h.ne_zero rfl #align not_prime_zero not_prime_zero @[simp] theorem not_prime_one : ¬Prime (1 : α) := fun h => h.not_unit isUnit_one #align not_prime_one not_prime_one section Map variable [CommMonoidWithZero β] {F : Type*} {G : Type*} [FunLike F α β] variable [MonoidWithZeroHomClass F α β] [FunLike G β α] [MulHomClass G β α] variable (f : F) (g : G) {p : α} theorem comap_prime (hinv : ∀ a, g (f a : β) = a) (hp : Prime (f p)) : Prime p := ⟨fun h => hp.1 <| by simp [h], fun h => hp.2.1 <| h.map f, fun a b h => by refine (hp.2.2 (f a) (f b) <| by convert map_dvd f h simp).imp ?_ ?_ <;> · intro h convert ← map_dvd g h <;> apply hinv⟩ #align comap_prime comap_prime theorem MulEquiv.prime_iff (e : α ≃* β) : Prime p ↔ Prime (e p) := ⟨fun h => (comap_prime e.symm e fun a => by simp) <| (e.symm_apply_apply p).substr h, comap_prime e e.symm fun a => by simp⟩ #align mul_equiv.prime_iff MulEquiv.prime_iff end Map end Prime theorem Prime.left_dvd_or_dvd_right_of_dvd_mul [CancelCommMonoidWithZero α] {p : α} (hp : Prime p) {a b : α} : a ∣ p * b → p ∣ a ∨ a ∣ b := by rintro ⟨c, hc⟩ rcases hp.2.2 a c (hc ▸ dvd_mul_right _ _) with (h | ⟨x, rfl⟩) · exact Or.inl h · rw [mul_left_comm, mul_right_inj' hp.ne_zero] at hc exact Or.inr (hc.symm ▸ dvd_mul_right _ _) #align prime.left_dvd_or_dvd_right_of_dvd_mul Prime.left_dvd_or_dvd_right_of_dvd_mul theorem Prime.pow_dvd_of_dvd_mul_left [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ a) (h' : p ^ n ∣ a * b) : p ^ n ∣ b := by induction' n with n ih · rw [pow_zero] exact one_dvd b · obtain ⟨c, rfl⟩ := ih (dvd_trans (pow_dvd_pow p n.le_succ) h') rw [pow_succ] apply mul_dvd_mul_left _ ((hp.dvd_or_dvd _).resolve_left h) rwa [← mul_dvd_mul_iff_left (pow_ne_zero n hp.ne_zero), ← pow_succ, mul_left_comm] #align prime.pow_dvd_of_dvd_mul_left Prime.pow_dvd_of_dvd_mul_left theorem Prime.pow_dvd_of_dvd_mul_right [CancelCommMonoidWithZero α] {p a b : α} (hp : Prime p) (n : ℕ) (h : ¬p ∣ b) (h' : p ^ n ∣ a * b) : p ^ n ∣ a := by rw [mul_comm] at h' exact hp.pow_dvd_of_dvd_mul_left n h h' #align prime.pow_dvd_of_dvd_mul_right Prime.pow_dvd_of_dvd_mul_right theorem Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd [CancelCommMonoidWithZero α] {p a b : α} {n : ℕ} (hp : Prime p) (hpow : p ^ n.succ ∣ a ^ n.succ * b ^ n) (hb : ¬p ^ 2 ∣ b) : p ∣ a := by -- Suppose `p ∣ b`, write `b = p * x` and `hy : a ^ n.succ * b ^ n = p ^ n.succ * y`. cases' hp.dvd_or_dvd ((dvd_pow_self p (Nat.succ_ne_zero n)).trans hpow) with H hbdiv · exact hp.dvd_of_dvd_pow H obtain ⟨x, rfl⟩ := hp.dvd_of_dvd_pow hbdiv obtain ⟨y, hy⟩ := hpow -- Then we can divide out a common factor of `p ^ n` from the equation `hy`. have : a ^ n.succ * x ^ n = p * y := by refine mul_left_cancel₀ (pow_ne_zero n hp.ne_zero) ?_ rw [← mul_assoc _ p, ← pow_succ, ← hy, mul_pow, ← mul_assoc (a ^ n.succ), mul_comm _ (p ^ n), mul_assoc] -- So `p ∣ a` (and we're done) or `p ∣ x`, which can't be the case since it implies `p^2 ∣ b`. refine hp.dvd_of_dvd_pow ((hp.dvd_or_dvd ⟨_, this⟩).resolve_right fun hdvdx => hb ?_) obtain ⟨z, rfl⟩ := hp.dvd_of_dvd_pow hdvdx rw [pow_two, ← mul_assoc] exact dvd_mul_right _ _ #align prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd Prime.dvd_of_pow_dvd_pow_mul_pow_of_square_not_dvd theorem prime_pow_succ_dvd_mul {α : Type*} [CancelCommMonoidWithZero α] {p x y : α} (h : Prime p) {i : ℕ} (hxy : p ^ (i + 1) ∣ x * y) : p ^ (i + 1) ∣ x ∨ p ∣ y := by rw [or_iff_not_imp_right] intro hy induction' i with i ih generalizing x · rw [pow_one] at hxy ⊢ exact (h.dvd_or_dvd hxy).resolve_right hy rw [pow_succ'] at hxy ⊢ obtain ⟨x', rfl⟩ := (h.dvd_or_dvd (dvd_of_mul_right_dvd hxy)).resolve_right hy rw [mul_assoc] at hxy exact mul_dvd_mul_left p (ih ((mul_dvd_mul_iff_left h.ne_zero).mp hxy)) #align prime_pow_succ_dvd_mul prime_pow_succ_dvd_mul /-- `Irreducible p` states that `p` is non-unit and only factors into units. We explicitly avoid stating that `p` is non-zero, this would require a semiring. Assuming only a monoid allows us to reuse irreducible for associated elements. -/ structure Irreducible [Monoid α] (p : α) : Prop where /-- `p` is not a unit -/ not_unit : ¬IsUnit p /-- if `p` factors then one factor is a unit -/ isUnit_or_isUnit' : ∀ a b, p = a * b → IsUnit a ∨ IsUnit b #align irreducible Irreducible namespace Irreducible theorem not_dvd_one [CommMonoid α] {p : α} (hp : Irreducible p) : ¬p ∣ 1 := mt (isUnit_of_dvd_one ·) hp.not_unit #align irreducible.not_dvd_one Irreducible.not_dvd_one theorem isUnit_or_isUnit [Monoid α] {p : α} (hp : Irreducible p) {a b : α} (h : p = a * b) : IsUnit a ∨ IsUnit b := hp.isUnit_or_isUnit' a b h #align irreducible.is_unit_or_is_unit Irreducible.isUnit_or_isUnit end Irreducible theorem irreducible_iff [Monoid α] {p : α} : Irreducible p ↔ ¬IsUnit p ∧ ∀ a b, p = a * b → IsUnit a ∨ IsUnit b := ⟨fun h => ⟨h.1, h.2⟩, fun h => ⟨h.1, h.2⟩⟩ #align irreducible_iff irreducible_iff @[simp] theorem not_irreducible_one [Monoid α] : ¬Irreducible (1 : α) := by simp [irreducible_iff] #align not_irreducible_one not_irreducible_one theorem Irreducible.ne_one [Monoid α] : ∀ {p : α}, Irreducible p → p ≠ 1 | _, hp, rfl => not_irreducible_one hp #align irreducible.ne_one Irreducible.ne_one @[simp] theorem not_irreducible_zero [MonoidWithZero α] : ¬Irreducible (0 : α) | ⟨hn0, h⟩ => have : IsUnit (0 : α) ∨ IsUnit (0 : α) := h 0 0 (mul_zero 0).symm this.elim hn0 hn0 #align not_irreducible_zero not_irreducible_zero theorem Irreducible.ne_zero [MonoidWithZero α] : ∀ {p : α}, Irreducible p → p ≠ 0 | _, hp, rfl => not_irreducible_zero hp #align irreducible.ne_zero Irreducible.ne_zero theorem of_irreducible_mul {α} [Monoid α] {x y : α} : Irreducible (x * y) → IsUnit x ∨ IsUnit y | ⟨_, h⟩ => h _ _ rfl #align of_irreducible_mul of_irreducible_mul theorem not_irreducible_pow {α} [Monoid α] {x : α} {n : ℕ} (hn : n ≠ 1) : ¬ Irreducible (x ^ n) := by cases n with | zero => simp | succ n => intro ⟨h₁, h₂⟩ have := h₂ _ _ (pow_succ _ _) rw [isUnit_pow_iff (Nat.succ_ne_succ.mp hn), or_self] at this exact h₁ (this.pow _) #noalign of_irreducible_pow theorem irreducible_or_factor {α} [Monoid α] (x : α) (h : ¬IsUnit x) : Irreducible x ∨ ∃ a b, ¬IsUnit a ∧ ¬IsUnit b ∧ a * b = x := by haveI := Classical.dec refine or_iff_not_imp_right.2 fun H => ?_ simp? [h, irreducible_iff] at H ⊢ says simp only [exists_and_left, not_exists, not_and, irreducible_iff, h, not_false_eq_true, true_and] at H ⊢ refine fun a b h => by_contradiction fun o => ?_ simp? [not_or] at o says simp only [not_or] at o exact H _ o.1 _ o.2 h.symm #align irreducible_or_factor irreducible_or_factor /-- If `p` and `q` are irreducible, then `p ∣ q` implies `q ∣ p`. -/ theorem Irreducible.dvd_symm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) : p ∣ q → q ∣ p := by rintro ⟨q', rfl⟩ rw [IsUnit.mul_right_dvd (Or.resolve_left (of_irreducible_mul hq) hp.not_unit)] #align irreducible.dvd_symm Irreducible.dvd_symm theorem Irreducible.dvd_comm [Monoid α] {p q : α} (hp : Irreducible p) (hq : Irreducible q) : p ∣ q ↔ q ∣ p := ⟨hp.dvd_symm hq, hq.dvd_symm hp⟩ #align irreducible.dvd_comm Irreducible.dvd_comm section variable [Monoid α] theorem irreducible_units_mul (a : αˣ) (b : α) : Irreducible (↑a * b) ↔ Irreducible b := by simp only [irreducible_iff, Units.isUnit_units_mul, and_congr_right_iff] refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩ · rw [← a.isUnit_units_mul] apply h rw [mul_assoc, ← HAB] · rw [← a⁻¹.isUnit_units_mul] apply h rw [mul_assoc, ← HAB, Units.inv_mul_cancel_left] #align irreducible_units_mul irreducible_units_mul theorem irreducible_isUnit_mul {a b : α} (h : IsUnit a) : Irreducible (a * b) ↔ Irreducible b := let ⟨a, ha⟩ := h ha ▸ irreducible_units_mul a b #align irreducible_is_unit_mul irreducible_isUnit_mul theorem irreducible_mul_units (a : αˣ) (b : α) : Irreducible (b * ↑a) ↔ Irreducible b := by simp only [irreducible_iff, Units.isUnit_mul_units, and_congr_right_iff] refine fun _ => ⟨fun h A B HAB => ?_, fun h A B HAB => ?_⟩ · rw [← Units.isUnit_mul_units B a] apply h rw [← mul_assoc, ← HAB] · rw [← Units.isUnit_mul_units B a⁻¹] apply h rw [← mul_assoc, ← HAB, Units.mul_inv_cancel_right] #align irreducible_mul_units irreducible_mul_units theorem irreducible_mul_isUnit {a b : α} (h : IsUnit a) : Irreducible (b * a) ↔ Irreducible b := let ⟨a, ha⟩ := h ha ▸ irreducible_mul_units a b #align irreducible_mul_is_unit irreducible_mul_isUnit theorem irreducible_mul_iff {a b : α} : Irreducible (a * b) ↔ Irreducible a ∧ IsUnit b ∨ Irreducible b ∧ IsUnit a := by constructor · refine fun h => Or.imp (fun h' => ⟨?_, h'⟩) (fun h' => ⟨?_, h'⟩) (h.isUnit_or_isUnit rfl).symm · rwa [irreducible_mul_isUnit h'] at h · rwa [irreducible_isUnit_mul h'] at h · rintro (⟨ha, hb⟩ | ⟨hb, ha⟩) · rwa [irreducible_mul_isUnit hb] · rwa [irreducible_isUnit_mul ha] #align irreducible_mul_iff irreducible_mul_iff end section CommMonoid variable [CommMonoid α] {a : α} theorem Irreducible.not_square (ha : Irreducible a) : ¬IsSquare a := by rw [isSquare_iff_exists_sq] rintro ⟨b, rfl⟩ exact not_irreducible_pow (by decide) ha #align irreducible.not_square Irreducible.not_square theorem IsSquare.not_irreducible (ha : IsSquare a) : ¬Irreducible a := fun h => h.not_square ha #align is_square.not_irreducible IsSquare.not_irreducible end CommMonoid section CommMonoidWithZero variable [CommMonoidWithZero α] theorem Irreducible.prime_of_isPrimal {a : α} (irr : Irreducible a) (primal : IsPrimal a) : Prime a := ⟨irr.ne_zero, irr.not_unit, fun a b dvd ↦ by obtain ⟨d₁, d₂, h₁, h₂, rfl⟩ := primal dvd exact (of_irreducible_mul irr).symm.imp (·.mul_right_dvd.mpr h₁) (·.mul_left_dvd.mpr h₂)⟩ theorem Irreducible.prime [DecompositionMonoid α] {a : α} (irr : Irreducible a) : Prime a := irr.prime_of_isPrimal (DecompositionMonoid.primal a) end CommMonoidWithZero section CancelCommMonoidWithZero variable [CancelCommMonoidWithZero α] {a p : α} protected theorem Prime.irreducible (hp : Prime p) : Irreducible p := ⟨hp.not_unit, fun a b ↦ by rintro rfl exact (hp.dvd_or_dvd dvd_rfl).symm.imp (isUnit_of_dvd_one <| (mul_dvd_mul_iff_right <| right_ne_zero_of_mul hp.ne_zero).mp <| dvd_mul_of_dvd_right · _) (isUnit_of_dvd_one <| (mul_dvd_mul_iff_left <| left_ne_zero_of_mul hp.ne_zero).mp <| dvd_mul_of_dvd_left · _)⟩ #align prime.irreducible Prime.irreducible theorem irreducible_iff_prime [DecompositionMonoid α] {a : α} : Irreducible a ↔ Prime a := ⟨Irreducible.prime, Prime.irreducible⟩ theorem succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul (hp : Prime p) {a b : α} {k l : ℕ} : p ^ k ∣ a → p ^ l ∣ b → p ^ (k + l + 1) ∣ a * b → p ^ (k + 1) ∣ a ∨ p ^ (l + 1) ∣ b := fun ⟨x, hx⟩ ⟨y, hy⟩ ⟨z, hz⟩ => have h : p ^ (k + l) * (x * y) = p ^ (k + l) * (p * z) := by simpa [mul_comm, pow_add, hx, hy, mul_assoc, mul_left_comm] using hz have hp0 : p ^ (k + l) ≠ 0 := pow_ne_zero _ hp.ne_zero have hpd : p ∣ x * y := ⟨z, by rwa [mul_right_inj' hp0] at h⟩ (hp.dvd_or_dvd hpd).elim (fun ⟨d, hd⟩ => Or.inl ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩) fun ⟨d, hd⟩ => Or.inr ⟨d, by simp [*, pow_succ, mul_comm, mul_left_comm, mul_assoc]⟩ #align succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul theorem Prime.not_square (hp : Prime p) : ¬IsSquare p := hp.irreducible.not_square #align prime.not_square Prime.not_square theorem IsSquare.not_prime (ha : IsSquare a) : ¬Prime a := fun h => h.not_square ha #align is_square.not_prime IsSquare.not_prime theorem not_prime_pow {n : ℕ} (hn : n ≠ 1) : ¬Prime (a ^ n) := fun hp => not_irreducible_pow hn hp.irreducible #align pow_not_prime not_prime_pow end CancelCommMonoidWithZero /-- Two elements of a `Monoid` are `Associated` if one of them is another one multiplied by a unit on the right. -/ def Associated [Monoid α] (x y : α) : Prop := ∃ u : αˣ, x * u = y #align associated Associated /-- Notation for two elements of a monoid are associated, i.e. if one of them is another one multiplied by a unit on the right. -/ local infixl:50 " ~ᵤ " => Associated namespace Associated @[refl] protected theorem refl [Monoid α] (x : α) : x ~ᵤ x := ⟨1, by simp⟩ #align associated.refl Associated.refl protected theorem rfl [Monoid α] {x : α} : x ~ᵤ x := .refl x instance [Monoid α] : IsRefl α Associated := ⟨Associated.refl⟩ @[symm] protected theorem symm [Monoid α] : ∀ {x y : α}, x ~ᵤ y → y ~ᵤ x | x, _, ⟨u, rfl⟩ => ⟨u⁻¹, by rw [mul_assoc, Units.mul_inv, mul_one]⟩ #align associated.symm Associated.symm instance [Monoid α] : IsSymm α Associated := ⟨fun _ _ => Associated.symm⟩ protected theorem comm [Monoid α] {x y : α} : x ~ᵤ y ↔ y ~ᵤ x := ⟨Associated.symm, Associated.symm⟩ #align associated.comm Associated.comm @[trans] protected theorem trans [Monoid α] : ∀ {x y z : α}, x ~ᵤ y → y ~ᵤ z → x ~ᵤ z | x, _, _, ⟨u, rfl⟩, ⟨v, rfl⟩ => ⟨u * v, by rw [Units.val_mul, mul_assoc]⟩ #align associated.trans Associated.trans instance [Monoid α] : IsTrans α Associated := ⟨fun _ _ _ => Associated.trans⟩ /-- The setoid of the relation `x ~ᵤ y` iff there is a unit `u` such that `x * u = y` -/ protected def setoid (α : Type*) [Monoid α] : Setoid α where r := Associated iseqv := ⟨Associated.refl, Associated.symm, Associated.trans⟩ #align associated.setoid Associated.setoid theorem map {M N : Type*} [Monoid M] [Monoid N] {F : Type*} [FunLike F M N] [MonoidHomClass F M N] (f : F) {x y : M} (ha : Associated x y) : Associated (f x) (f y) := by obtain ⟨u, ha⟩ := ha exact ⟨Units.map f u, by rw [← ha, map_mul, Units.coe_map, MonoidHom.coe_coe]⟩ end Associated attribute [local instance] Associated.setoid theorem unit_associated_one [Monoid α] {u : αˣ} : (u : α) ~ᵤ 1 := ⟨u⁻¹, Units.mul_inv u⟩ #align unit_associated_one unit_associated_one @[simp] theorem associated_one_iff_isUnit [Monoid α] {a : α} : (a : α) ~ᵤ 1 ↔ IsUnit a := Iff.intro (fun h => let ⟨c, h⟩ := h.symm h ▸ ⟨c, (one_mul _).symm⟩) fun ⟨c, h⟩ => Associated.symm ⟨c, by simp [h]⟩ #align associated_one_iff_is_unit associated_one_iff_isUnit @[simp] theorem associated_zero_iff_eq_zero [MonoidWithZero α] (a : α) : a ~ᵤ 0 ↔ a = 0 := Iff.intro (fun h => by let ⟨u, h⟩ := h.symm simpa using h.symm) fun h => h ▸ Associated.refl a #align associated_zero_iff_eq_zero associated_zero_iff_eq_zero theorem associated_one_of_mul_eq_one [CommMonoid α] {a : α} (b : α) (hab : a * b = 1) : a ~ᵤ 1 := show (Units.mkOfMulEqOne a b hab : α) ~ᵤ 1 from unit_associated_one #align associated_one_of_mul_eq_one associated_one_of_mul_eq_one theorem associated_one_of_associated_mul_one [CommMonoid α] {a b : α} : a * b ~ᵤ 1 → a ~ᵤ 1 | ⟨u, h⟩ => associated_one_of_mul_eq_one (b * u) <| by simpa [mul_assoc] using h #align associated_one_of_associated_mul_one associated_one_of_associated_mul_one theorem associated_mul_unit_left {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) : Associated (a * u) a := let ⟨u', hu⟩ := hu ⟨u'⁻¹, hu ▸ Units.mul_inv_cancel_right _ _⟩ #align associated_mul_unit_left associated_mul_unit_left theorem associated_unit_mul_left {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) : Associated (u * a) a := by rw [mul_comm] exact associated_mul_unit_left _ _ hu #align associated_unit_mul_left associated_unit_mul_left theorem associated_mul_unit_right {β : Type*} [Monoid β] (a u : β) (hu : IsUnit u) : Associated a (a * u) := (associated_mul_unit_left a u hu).symm #align associated_mul_unit_right associated_mul_unit_right theorem associated_unit_mul_right {β : Type*} [CommMonoid β] (a u : β) (hu : IsUnit u) : Associated a (u * a) := (associated_unit_mul_left a u hu).symm #align associated_unit_mul_right associated_unit_mul_right theorem associated_mul_isUnit_left_iff {β : Type*} [Monoid β] {a u b : β} (hu : IsUnit u) : Associated (a * u) b ↔ Associated a b := ⟨(associated_mul_unit_right _ _ hu).trans, (associated_mul_unit_left _ _ hu).trans⟩ #align associated_mul_is_unit_left_iff associated_mul_isUnit_left_iff theorem associated_isUnit_mul_left_iff {β : Type*} [CommMonoid β] {u a b : β} (hu : IsUnit u) : Associated (u * a) b ↔ Associated a b := by rw [mul_comm] exact associated_mul_isUnit_left_iff hu #align associated_is_unit_mul_left_iff associated_isUnit_mul_left_iff theorem associated_mul_isUnit_right_iff {β : Type*} [Monoid β] {a b u : β} (hu : IsUnit u) : Associated a (b * u) ↔ Associated a b := Associated.comm.trans <| (associated_mul_isUnit_left_iff hu).trans Associated.comm #align associated_mul_is_unit_right_iff associated_mul_isUnit_right_iff theorem associated_isUnit_mul_right_iff {β : Type*} [CommMonoid β] {a u b : β} (hu : IsUnit u) : Associated a (u * b) ↔ Associated a b := Associated.comm.trans <| (associated_isUnit_mul_left_iff hu).trans Associated.comm #align associated_is_unit_mul_right_iff associated_isUnit_mul_right_iff @[simp] theorem associated_mul_unit_left_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} : Associated (a * u) b ↔ Associated a b := associated_mul_isUnit_left_iff u.isUnit #align associated_mul_unit_left_iff associated_mul_unit_left_iff @[simp] theorem associated_unit_mul_left_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} : Associated (↑u * a) b ↔ Associated a b := associated_isUnit_mul_left_iff u.isUnit #align associated_unit_mul_left_iff associated_unit_mul_left_iff @[simp] theorem associated_mul_unit_right_iff {β : Type*} [Monoid β] {a b : β} {u : Units β} : Associated a (b * u) ↔ Associated a b := associated_mul_isUnit_right_iff u.isUnit #align associated_mul_unit_right_iff associated_mul_unit_right_iff @[simp] theorem associated_unit_mul_right_iff {β : Type*} [CommMonoid β] {a b : β} {u : Units β} : Associated a (↑u * b) ↔ Associated a b := associated_isUnit_mul_right_iff u.isUnit #align associated_unit_mul_right_iff associated_unit_mul_right_iff theorem Associated.mul_left [Monoid α] (a : α) {b c : α} (h : b ~ᵤ c) : a * b ~ᵤ a * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_assoc _ _ _⟩ #align associated.mul_left Associated.mul_left theorem Associated.mul_right [CommMonoid α] {a b : α} (h : a ~ᵤ b) (c : α) : a * c ~ᵤ b * c := by obtain ⟨d, rfl⟩ := h; exact ⟨d, mul_right_comm _ _ _⟩ #align associated.mul_right Associated.mul_right theorem Associated.mul_mul [CommMonoid α] {a₁ a₂ b₁ b₂ : α} (h₁ : a₁ ~ᵤ b₁) (h₂ : a₂ ~ᵤ b₂) : a₁ * a₂ ~ᵤ b₁ * b₂ := (h₁.mul_right _).trans (h₂.mul_left _) #align associated.mul_mul Associated.mul_mul theorem Associated.pow_pow [CommMonoid α] {a b : α} {n : ℕ} (h : a ~ᵤ b) : a ^ n ~ᵤ b ^ n := by induction' n with n ih · simp [Associated.refl] convert h.mul_mul ih <;> rw [pow_succ'] #align associated.pow_pow Associated.pow_pow protected theorem Associated.dvd [Monoid α] {a b : α} : a ~ᵤ b → a ∣ b := fun ⟨u, hu⟩ => ⟨u, hu.symm⟩ #align associated.dvd Associated.dvd protected theorem Associated.dvd' [Monoid α] {a b : α} (h : a ~ᵤ b) : b ∣ a := h.symm.dvd protected theorem Associated.dvd_dvd [Monoid α] {a b : α} (h : a ~ᵤ b) : a ∣ b ∧ b ∣ a := ⟨h.dvd, h.symm.dvd⟩ #align associated.dvd_dvd Associated.dvd_dvd theorem associated_of_dvd_dvd [CancelMonoidWithZero α] {a b : α} (hab : a ∣ b) (hba : b ∣ a) : a ~ᵤ b := by rcases hab with ⟨c, rfl⟩ rcases hba with ⟨d, a_eq⟩ by_cases ha0 : a = 0 · simp_all have hac0 : a * c ≠ 0 := by intro con rw [con, zero_mul] at a_eq apply ha0 a_eq have : a * (c * d) = a * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hcd : c * d = 1 := mul_left_cancel₀ ha0 this have : a * c * (d * c) = a * c * 1 := by rw [← mul_assoc, ← a_eq, mul_one] have hdc : d * c = 1 := mul_left_cancel₀ hac0 this exact ⟨⟨c, d, hcd, hdc⟩, rfl⟩ #align associated_of_dvd_dvd associated_of_dvd_dvd theorem dvd_dvd_iff_associated [CancelMonoidWithZero α] {a b : α} : a ∣ b ∧ b ∣ a ↔ a ~ᵤ b := ⟨fun ⟨h1, h2⟩ => associated_of_dvd_dvd h1 h2, Associated.dvd_dvd⟩ #align dvd_dvd_iff_associated dvd_dvd_iff_associated instance [CancelMonoidWithZero α] [DecidableRel ((· ∣ ·) : α → α → Prop)] : DecidableRel ((· ~ᵤ ·) : α → α → Prop) := fun _ _ => decidable_of_iff _ dvd_dvd_iff_associated theorem Associated.dvd_iff_dvd_left [Monoid α] {a b c : α} (h : a ~ᵤ b) : a ∣ c ↔ b ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.mul_right_dvd.symm #align associated.dvd_iff_dvd_left Associated.dvd_iff_dvd_left theorem Associated.dvd_iff_dvd_right [Monoid α] {a b c : α} (h : b ~ᵤ c) : a ∣ b ↔ a ∣ c := let ⟨_, hu⟩ := h hu ▸ Units.dvd_mul_right.symm #align associated.dvd_iff_dvd_right Associated.dvd_iff_dvd_right theorem Associated.eq_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a = 0 ↔ b = 0 := by obtain ⟨u, rfl⟩ := h rw [← Units.eq_mul_inv_iff_mul_eq, zero_mul] #align associated.eq_zero_iff Associated.eq_zero_iff theorem Associated.ne_zero_iff [MonoidWithZero α] {a b : α} (h : a ~ᵤ b) : a ≠ 0 ↔ b ≠ 0 := not_congr h.eq_zero_iff #align associated.ne_zero_iff Associated.ne_zero_iff theorem Associated.neg_left [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated (-a) b := let ⟨u, hu⟩ := h; ⟨-u, by simp [hu]⟩ theorem Associated.neg_right [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated a (-b) := h.symm.neg_left.symm theorem Associated.neg_neg [Monoid α] [HasDistribNeg α] {a b : α} (h : Associated a b) : Associated (-a) (-b) := h.neg_left.neg_right protected theorem Associated.prime [CommMonoidWithZero α] {p q : α} (h : p ~ᵤ q) (hp : Prime p) : Prime q := ⟨h.ne_zero_iff.1 hp.ne_zero, let ⟨u, hu⟩ := h ⟨fun ⟨v, hv⟩ => hp.not_unit ⟨v * u⁻¹, by simp [hv, hu.symm]⟩, hu ▸ by simp only [IsUnit.mul_iff, Units.isUnit, and_true, IsUnit.mul_right_dvd] intro a b exact hp.dvd_or_dvd⟩⟩ #align associated.prime Associated.prime theorem prime_mul_iff [CancelCommMonoidWithZero α] {x y : α} : Prime (x * y) ↔ (Prime x ∧ IsUnit y) ∨ (IsUnit x ∧ Prime y) := by refine ⟨fun h ↦ ?_, ?_⟩ · rcases of_irreducible_mul h.irreducible with hx | hy · exact Or.inr ⟨hx, (associated_unit_mul_left y x hx).prime h⟩ · exact Or.inl ⟨(associated_mul_unit_left x y hy).prime h, hy⟩ · rintro (⟨hx, hy⟩ | ⟨hx, hy⟩) · exact (associated_mul_unit_left x y hy).symm.prime hx · exact (associated_unit_mul_right y x hx).prime hy @[simp] lemma prime_pow_iff [CancelCommMonoidWithZero α] {p : α} {n : ℕ} : Prime (p ^ n) ↔ Prime p ∧ n = 1 := by refine ⟨fun hp ↦ ?_, fun ⟨hp, hn⟩ ↦ by simpa [hn]⟩ suffices n = 1 by aesop cases' n with n · simp at hp · rw [Nat.succ.injEq] rw [pow_succ', prime_mul_iff] at hp rcases hp with ⟨hp, hpn⟩ | ⟨hp, hpn⟩ · by_contra contra rw [isUnit_pow_iff contra] at hpn exact hp.not_unit hpn · exfalso exact hpn.not_unit (hp.pow n)
Mathlib/Algebra/Associated.lean
672
682
theorem Irreducible.dvd_iff [Monoid α] {x y : α} (hx : Irreducible x) : y ∣ x ↔ IsUnit y ∨ Associated x y := by
constructor · rintro ⟨z, hz⟩ obtain (h|h) := hx.isUnit_or_isUnit hz · exact Or.inl h · rw [hz] exact Or.inr (associated_mul_unit_left _ _ h) · rintro (hy|h) · exact hy.dvd · exact h.symm.dvd
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Eval #align_import data.polynomial.degree.lemmas from "leanprover-community/mathlib"@"728baa2f54e6062c5879a3e397ac6bac323e506f" /-! # Theory of degrees of polynomials Some of the main results include - `natDegree_comp_le` : The degree of the composition is at most the product of degrees -/ noncomputable section open Polynomial open Finsupp Finset namespace Polynomial universe u v w variable {R : Type u} {S : Type v} {ι : Type w} {a b : R} {m n : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} section Degree theorem natDegree_comp_le : natDegree (p.comp q) ≤ natDegree p * natDegree q := letI := Classical.decEq R if h0 : p.comp q = 0 then by rw [h0, natDegree_zero]; exact Nat.zero_le _ else WithBot.coe_le_coe.1 <| calc ↑(natDegree (p.comp q)) = degree (p.comp q) := (degree_eq_natDegree h0).symm _ = _ := congr_arg degree comp_eq_sum_left _ ≤ _ := degree_sum_le _ _ _ ≤ _ := Finset.sup_le fun n hn => calc degree (C (coeff p n) * q ^ n) ≤ degree (C (coeff p n)) + degree (q ^ n) := degree_mul_le _ _ _ ≤ natDegree (C (coeff p n)) + n • degree q := (add_le_add degree_le_natDegree (degree_pow_le _ _)) _ ≤ natDegree (C (coeff p n)) + n • ↑(natDegree q) := (add_le_add_left (nsmul_le_nsmul_right (@degree_le_natDegree _ _ q) n) _) _ = (n * natDegree q : ℕ) := by rw [natDegree_C, Nat.cast_zero, zero_add, nsmul_eq_mul]; simp _ ≤ (natDegree p * natDegree q : ℕ) := WithBot.coe_le_coe.2 <| mul_le_mul_of_nonneg_right (le_natDegree_of_ne_zero (mem_support_iff.1 hn)) (Nat.zero_le _) #align polynomial.nat_degree_comp_le Polynomial.natDegree_comp_le theorem degree_pos_of_root {p : R[X]} (hp : p ≠ 0) (h : IsRoot p a) : 0 < degree p := lt_of_not_ge fun hlt => by have := eq_C_of_degree_le_zero hlt rw [IsRoot, this, eval_C] at h simp only [h, RingHom.map_zero] at this exact hp this #align polynomial.degree_pos_of_root Polynomial.degree_pos_of_root theorem natDegree_le_iff_coeff_eq_zero : p.natDegree ≤ n ↔ ∀ N : ℕ, n < N → p.coeff N = 0 := by simp_rw [natDegree_le_iff_degree_le, degree_le_iff_coeff_zero, Nat.cast_lt] #align polynomial.nat_degree_le_iff_coeff_eq_zero Polynomial.natDegree_le_iff_coeff_eq_zero theorem natDegree_add_le_iff_left {n : ℕ} (p q : R[X]) (qn : q.natDegree ≤ n) : (p + q).natDegree ≤ n ↔ p.natDegree ≤ n := by refine ⟨fun h => ?_, fun h => natDegree_add_le_of_degree_le h qn⟩ refine natDegree_le_iff_coeff_eq_zero.mpr fun m hm => ?_ convert natDegree_le_iff_coeff_eq_zero.mp h m hm using 1 rw [coeff_add, natDegree_le_iff_coeff_eq_zero.mp qn _ hm, add_zero] #align polynomial.nat_degree_add_le_iff_left Polynomial.natDegree_add_le_iff_left theorem natDegree_add_le_iff_right {n : ℕ} (p q : R[X]) (pn : p.natDegree ≤ n) : (p + q).natDegree ≤ n ↔ q.natDegree ≤ n := by rw [add_comm] exact natDegree_add_le_iff_left _ _ pn #align polynomial.nat_degree_add_le_iff_right Polynomial.natDegree_add_le_iff_right theorem natDegree_C_mul_le (a : R) (f : R[X]) : (C a * f).natDegree ≤ f.natDegree := calc (C a * f).natDegree ≤ (C a).natDegree + f.natDegree := natDegree_mul_le _ = 0 + f.natDegree := by rw [natDegree_C a] _ = f.natDegree := zero_add _ set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul_le Polynomial.natDegree_C_mul_le theorem natDegree_mul_C_le (f : R[X]) (a : R) : (f * C a).natDegree ≤ f.natDegree := calc (f * C a).natDegree ≤ f.natDegree + (C a).natDegree := natDegree_mul_le _ = f.natDegree + 0 := by rw [natDegree_C a] _ = f.natDegree := add_zero _ set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_mul_C_le Polynomial.natDegree_mul_C_le theorem eq_natDegree_of_le_mem_support (pn : p.natDegree ≤ n) (ns : n ∈ p.support) : p.natDegree = n := le_antisymm pn (le_natDegree_of_mem_supp _ ns) #align polynomial.eq_nat_degree_of_le_mem_support Polynomial.eq_natDegree_of_le_mem_support theorem natDegree_C_mul_eq_of_mul_eq_one {ai : R} (au : ai * a = 1) : (C a * p).natDegree = p.natDegree := le_antisymm (natDegree_C_mul_le a p) (calc p.natDegree = (1 * p).natDegree := by nth_rw 1 [← one_mul p] _ = (C ai * (C a * p)).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc] _ ≤ (C a * p).natDegree := natDegree_C_mul_le ai (C a * p)) set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul_eq_of_mul_eq_one Polynomial.natDegree_C_mul_eq_of_mul_eq_one theorem natDegree_mul_C_eq_of_mul_eq_one {ai : R} (au : a * ai = 1) : (p * C a).natDegree = p.natDegree := le_antisymm (natDegree_mul_C_le p a) (calc p.natDegree = (p * 1).natDegree := by nth_rw 1 [← mul_one p] _ = (p * C a * C ai).natDegree := by rw [← C_1, ← au, RingHom.map_mul, ← mul_assoc] _ ≤ (p * C a).natDegree := natDegree_mul_C_le (p * C a) ai) set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_mul_C_eq_of_mul_eq_one Polynomial.natDegree_mul_C_eq_of_mul_eq_one /-- Although not explicitly stated, the assumptions of lemma `nat_degree_mul_C_eq_of_mul_ne_zero` force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`. -/ theorem natDegree_mul_C_eq_of_mul_ne_zero (h : p.leadingCoeff * a ≠ 0) : (p * C a).natDegree = p.natDegree := by refine eq_natDegree_of_le_mem_support (natDegree_mul_C_le p a) ?_ refine mem_support_iff.mpr ?_ rwa [coeff_mul_C] set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_mul_C_eq_of_mul_ne_zero Polynomial.natDegree_mul_C_eq_of_mul_ne_zero /-- Although not explicitly stated, the assumptions of lemma `nat_degree_C_mul_eq_of_mul_ne_zero` force the polynomial `p` to be non-zero, via `p.leading_coeff ≠ 0`. -/ theorem natDegree_C_mul_eq_of_mul_ne_zero (h : a * p.leadingCoeff ≠ 0) : (C a * p).natDegree = p.natDegree := by refine eq_natDegree_of_le_mem_support (natDegree_C_mul_le a p) ?_ refine mem_support_iff.mpr ?_ rwa [coeff_C_mul] set_option linter.uppercaseLean3 false in #align polynomial.nat_degree_C_mul_eq_of_mul_ne_zero Polynomial.natDegree_C_mul_eq_of_mul_ne_zero theorem natDegree_add_coeff_mul (f g : R[X]) : (f * g).coeff (f.natDegree + g.natDegree) = f.coeff f.natDegree * g.coeff g.natDegree := by simp only [coeff_natDegree, coeff_mul_degree_add_degree] #align polynomial.nat_degree_add_coeff_mul Polynomial.natDegree_add_coeff_mul theorem natDegree_lt_coeff_mul (h : p.natDegree + q.natDegree < m + n) : (p * q).coeff (m + n) = 0 := coeff_eq_zero_of_natDegree_lt (natDegree_mul_le.trans_lt h) #align polynomial.nat_degree_lt_coeff_mul Polynomial.natDegree_lt_coeff_mul theorem coeff_mul_of_natDegree_le (pm : p.natDegree ≤ m) (qn : q.natDegree ≤ n) : (p * q).coeff (m + n) = p.coeff m * q.coeff n := by simp_rw [← Polynomial.toFinsupp_apply, toFinsupp_mul] refine AddMonoidAlgebra.apply_add_of_supDegree_le ?_ Function.injective_id ?_ ?_ · simp · rwa [supDegree_eq_natDegree, id_eq] · rwa [supDegree_eq_natDegree, id_eq] #align polynomial.coeff_mul_of_nat_degree_le Polynomial.coeff_mul_of_natDegree_le theorem coeff_pow_of_natDegree_le (pn : p.natDegree ≤ n) : (p ^ m).coeff (m * n) = p.coeff n ^ m := by induction' m with m hm · simp · rw [pow_succ, pow_succ, ← hm, Nat.succ_mul, coeff_mul_of_natDegree_le _ pn] refine natDegree_pow_le.trans (le_trans ?_ (le_refl _)) exact mul_le_mul_of_nonneg_left pn m.zero_le #align polynomial.coeff_pow_of_nat_degree_le Polynomial.coeff_pow_of_natDegree_le theorem coeff_pow_eq_ite_of_natDegree_le_of_le {o : ℕ} (pn : natDegree p ≤ n) (mno : m * n ≤ o) : coeff (p ^ m) o = if o = m * n then (coeff p n) ^ m else 0 := by rcases eq_or_ne o (m * n) with rfl | h · simpa only [ite_true] using coeff_pow_of_natDegree_le pn · simpa only [h, ite_false] using coeff_eq_zero_of_natDegree_lt <| lt_of_le_of_lt (natDegree_pow_le_of_le m pn) (lt_of_le_of_ne mno h.symm) theorem coeff_add_eq_left_of_lt (qn : q.natDegree < n) : (p + q).coeff n = p.coeff n := (coeff_add _ _ _).trans <| (congr_arg _ <| coeff_eq_zero_of_natDegree_lt <| qn).trans <| add_zero _ #align polynomial.coeff_add_eq_left_of_lt Polynomial.coeff_add_eq_left_of_lt theorem coeff_add_eq_right_of_lt (pn : p.natDegree < n) : (p + q).coeff n = q.coeff n := by rw [add_comm] exact coeff_add_eq_left_of_lt pn #align polynomial.coeff_add_eq_right_of_lt Polynomial.coeff_add_eq_right_of_lt theorem degree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S) (h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on degree ∘ f)) : degree (s.sum f) = s.sup fun i => degree (f i) := by classical induction' s using Finset.induction_on with x s hx IH · simp · simp only [hx, Finset.sum_insert, not_false_iff, Finset.sup_insert] specialize IH (h.mono fun _ => by simp (config := { contextual := true })) rcases lt_trichotomy (degree (f x)) (degree (s.sum f)) with (H | H | H) · rw [← IH, sup_eq_right.mpr H.le, degree_add_eq_right_of_degree_lt H] · rcases s.eq_empty_or_nonempty with (rfl | hs) · simp obtain ⟨y, hy, hy'⟩ := Finset.exists_mem_eq_sup s hs fun i => degree (f i) rw [IH, hy'] at H by_cases hx0 : f x = 0 · simp [hx0, IH] have hy0 : f y ≠ 0 := by contrapose! H simpa [H, degree_eq_bot] using hx0 refine absurd H (h ?_ ?_ fun H => hx ?_) · simp [hx0] · simp [hy, hy0] · exact H.symm ▸ hy · rw [← IH, sup_eq_left.mpr H.le, degree_add_eq_left_of_degree_lt H] #align polynomial.degree_sum_eq_of_disjoint Polynomial.degree_sum_eq_of_disjoint theorem natDegree_sum_eq_of_disjoint (f : S → R[X]) (s : Finset S) (h : Set.Pairwise { i | i ∈ s ∧ f i ≠ 0 } (Ne on natDegree ∘ f)) : natDegree (s.sum f) = s.sup fun i => natDegree (f i) := by by_cases H : ∃ x ∈ s, f x ≠ 0 · obtain ⟨x, hx, hx'⟩ := H have hs : s.Nonempty := ⟨x, hx⟩ refine natDegree_eq_of_degree_eq_some ?_ rw [degree_sum_eq_of_disjoint] · rw [← Finset.sup'_eq_sup hs, ← Finset.sup'_eq_sup hs, Nat.cast_withBot, Finset.coe_sup' hs, ← Finset.sup'_eq_sup hs] refine le_antisymm ?_ ?_ · rw [Finset.sup'_le_iff] intro b hb by_cases hb' : f b = 0 · simpa [hb'] using hs rw [degree_eq_natDegree hb', Nat.cast_withBot] exact Finset.le_sup' (fun i : S => (natDegree (f i) : WithBot ℕ)) hb · rw [Finset.sup'_le_iff] intro b hb simp only [Finset.le_sup'_iff, exists_prop, Function.comp_apply] by_cases hb' : f b = 0 · refine ⟨x, hx, ?_⟩ contrapose! hx' simpa [← Nat.cast_withBot, hb', degree_eq_bot] using hx' exact ⟨b, hb, (degree_eq_natDegree hb').ge⟩ · exact h.imp fun x y hxy hxy' => hxy (natDegree_eq_of_degree_eq hxy') · push_neg at H rw [Finset.sum_eq_zero H, natDegree_zero, eq_comm, show 0 = ⊥ from rfl, Finset.sup_eq_bot_iff] intro x hx simp [H x hx] #align polynomial.nat_degree_sum_eq_of_disjoint Polynomial.natDegree_sum_eq_of_disjoint set_option linter.deprecated false in theorem natDegree_bit0 (a : R[X]) : (bit0 a).natDegree ≤ a.natDegree := (natDegree_add_le _ _).trans (max_self _).le #align polynomial.nat_degree_bit0 Polynomial.natDegree_bit0 set_option linter.deprecated false in theorem natDegree_bit1 (a : R[X]) : (bit1 a).natDegree ≤ a.natDegree := (natDegree_add_le _ _).trans (by simp [natDegree_bit0]) #align polynomial.nat_degree_bit1 Polynomial.natDegree_bit1 variable [Semiring S] theorem natDegree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < natDegree p := lt_of_not_ge fun hlt => by have A : p = C (p.coeff 0) := eq_C_of_natDegree_le_zero hlt rw [A, eval₂_C] at hz simp only [inj (p.coeff 0) hz, RingHom.map_zero] at A exact hp A #align polynomial.nat_degree_pos_of_eval₂_root Polynomial.natDegree_pos_of_eval₂_root theorem degree_pos_of_eval₂_root {p : R[X]} (hp : p ≠ 0) (f : R →+* S) {z : S} (hz : eval₂ f z p = 0) (inj : ∀ x : R, f x = 0 → x = 0) : 0 < degree p := natDegree_pos_iff_degree_pos.mp (natDegree_pos_of_eval₂_root hp f hz inj) #align polynomial.degree_pos_of_eval₂_root Polynomial.degree_pos_of_eval₂_root @[simp] theorem coe_lt_degree {p : R[X]} {n : ℕ} : (n : WithBot ℕ) < degree p ↔ n < natDegree p := by by_cases h : p = 0 · simp [h] simp [degree_eq_natDegree h, Nat.cast_lt] #align polynomial.coe_lt_degree Polynomial.coe_lt_degree @[simp] theorem degree_map_eq_iff {f : R →+* S} {p : Polynomial R} : degree (map f p) = degree p ↔ f (leadingCoeff p) ≠ 0 ∨ p = 0 := by rcases eq_or_ne p 0 with h|h · simp [h] simp only [h, or_false] refine ⟨fun h2 ↦ ?_, degree_map_eq_of_leadingCoeff_ne_zero f⟩ have h3 : natDegree (map f p) = natDegree p := by simp_rw [natDegree, h2] have h4 : map f p ≠ 0 := by rwa [ne_eq, ← degree_eq_bot, h2, degree_eq_bot] rwa [← coeff_natDegree, ← coeff_map, ← h3, coeff_natDegree, ne_eq, leadingCoeff_eq_zero] @[simp] theorem natDegree_map_eq_iff {f : R →+* S} {p : Polynomial R} : natDegree (map f p) = natDegree p ↔ f (p.leadingCoeff) ≠ 0 ∨ natDegree p = 0 := by rcases eq_or_ne (natDegree p) 0 with h|h · simp_rw [h, ne_eq, or_true, iff_true, ← Nat.le_zero, ← h, natDegree_map_le f p] have h2 : p ≠ 0 := by rintro rfl; simp at h have h3 : degree p ≠ (0 : ℕ) := degree_ne_of_natDegree_ne h simp_rw [h, or_false, natDegree, WithBot.unbot'_eq_unbot'_iff, degree_map_eq_iff] simp [h, h2, h3] -- simp doesn't rewrite in the hypothesis for some reason tauto theorem natDegree_pos_of_nextCoeff_ne_zero (h : p.nextCoeff ≠ 0) : 0 < p.natDegree := by rw [nextCoeff] at h by_cases hpz : p.natDegree = 0 · simp_all only [ne_eq, zero_le, ite_true, not_true_eq_false] · apply Nat.zero_lt_of_ne_zero hpz end Degree end Semiring section Ring variable [Ring R] {p q : R[X]} theorem natDegree_sub : (p - q).natDegree = (q - p).natDegree := by rw [← natDegree_neg, neg_sub] #align polynomial.nat_degree_sub Polynomial.natDegree_sub theorem natDegree_sub_le_iff_left (qn : q.natDegree ≤ n) : (p - q).natDegree ≤ n ↔ p.natDegree ≤ n := by rw [← natDegree_neg] at qn rw [sub_eq_add_neg, natDegree_add_le_iff_left _ _ qn] #align polynomial.nat_degree_sub_le_iff_left Polynomial.natDegree_sub_le_iff_left theorem natDegree_sub_le_iff_right (pn : p.natDegree ≤ n) : (p - q).natDegree ≤ n ↔ q.natDegree ≤ n := by rwa [natDegree_sub, natDegree_sub_le_iff_left] #align polynomial.nat_degree_sub_le_iff_right Polynomial.natDegree_sub_le_iff_right theorem coeff_sub_eq_left_of_lt (dg : q.natDegree < n) : (p - q).coeff n = p.coeff n := by rw [← natDegree_neg] at dg rw [sub_eq_add_neg, coeff_add_eq_left_of_lt dg] #align polynomial.coeff_sub_eq_left_of_lt Polynomial.coeff_sub_eq_left_of_lt
Mathlib/Algebra/Polynomial/Degree/Lemmas.lean
346
347
theorem coeff_sub_eq_neg_right_of_lt (df : p.natDegree < n) : (p - q).coeff n = -q.coeff n := by
rwa [sub_eq_add_neg, coeff_add_eq_right_of_lt, coeff_neg]
/- Copyright (c) 2018 Kevin Buzzard, Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Patrick Massot This file is to a certain extent based on `quotient_module.lean` by Johannes Hölzl. -/ import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Group.Subgroup.Pointwise import Mathlib.GroupTheory.Congruence.Basic import Mathlib.GroupTheory.Coset #align_import group_theory.quotient_group from "leanprover-community/mathlib"@"59694bd07f0a39c5beccba34bd9f413a160782bf" /-! # Quotients of groups by normal subgroups This files develops the basic theory of quotients of groups by normal subgroups. In particular it proves Noether's first and second isomorphism theorems. ## Main definitions * `mk'`: the canonical group homomorphism `G →* G/N` given a normal subgroup `N` of `G`. * `lift φ`: the group homomorphism `G/N →* H` given a group homomorphism `φ : G →* H` such that `N ⊆ ker φ`. * `map f`: the group homomorphism `G/N →* H/M` given a group homomorphism `f : G →* H` such that `N ⊆ f⁻¹(M)`. ## Main statements * `QuotientGroup.quotientKerEquivRange`: Noether's first isomorphism theorem, an explicit isomorphism `G/ker φ → range φ` for every group homomorphism `φ : G →* H`. * `QuotientGroup.quotientInfEquivProdNormalQuotient`: Noether's second isomorphism theorem, an explicit isomorphism between `H/(H ∩ N)` and `(HN)/N` given a subgroup `H` and a normal subgroup `N` of a group `G`. * `QuotientGroup.quotientQuotientEquivQuotient`: Noether's third isomorphism theorem, the canonical isomorphism between `(G / N) / (M / N)` and `G / M`, where `N ≤ M`. ## Tags isomorphism theorems, quotient groups -/ open Function open scoped Pointwise universe u v w x namespace QuotientGroup variable {G : Type u} [Group G] (N : Subgroup G) [nN : N.Normal] {H : Type v} [Group H] {M : Type x} [Monoid M] /-- The congruence relation generated by a normal subgroup. -/ @[to_additive "The additive congruence relation generated by a normal additive subgroup."] protected def con : Con G where toSetoid := leftRel N mul' := @fun a b c d hab hcd => by rw [leftRel_eq] at hab hcd ⊢ dsimp only calc (a * c)⁻¹ * (b * d) = c⁻¹ * (a⁻¹ * b) * c⁻¹⁻¹ * (c⁻¹ * d) := by simp only [mul_inv_rev, mul_assoc, inv_mul_cancel_left] _ ∈ N := N.mul_mem (nN.conj_mem _ hab _) hcd #align quotient_group.con QuotientGroup.con #align quotient_add_group.con QuotientAddGroup.con @[to_additive] instance Quotient.group : Group (G ⧸ N) := (QuotientGroup.con N).group #align quotient_group.quotient.group QuotientGroup.Quotient.group #align quotient_add_group.quotient.add_group QuotientAddGroup.Quotient.addGroup /-- The group homomorphism from `G` to `G/N`. -/ @[to_additive "The additive group homomorphism from `G` to `G/N`."] def mk' : G →* G ⧸ N := MonoidHom.mk' QuotientGroup.mk fun _ _ => rfl #align quotient_group.mk' QuotientGroup.mk' #align quotient_add_group.mk' QuotientAddGroup.mk' @[to_additive (attr := simp)] theorem coe_mk' : (mk' N : G → G ⧸ N) = mk := rfl #align quotient_group.coe_mk' QuotientGroup.coe_mk' #align quotient_add_group.coe_mk' QuotientAddGroup.coe_mk' @[to_additive (attr := simp)] theorem mk'_apply (x : G) : mk' N x = x := rfl #align quotient_group.mk'_apply QuotientGroup.mk'_apply #align quotient_add_group.mk'_apply QuotientAddGroup.mk'_apply @[to_additive] theorem mk'_surjective : Surjective <| mk' N := @mk_surjective _ _ N #align quotient_group.mk'_surjective QuotientGroup.mk'_surjective #align quotient_add_group.mk'_surjective QuotientAddGroup.mk'_surjective @[to_additive] theorem mk'_eq_mk' {x y : G} : mk' N x = mk' N y ↔ ∃ z ∈ N, x * z = y := QuotientGroup.eq'.trans <| by simp only [← _root_.eq_inv_mul_iff_mul_eq, exists_prop, exists_eq_right] #align quotient_group.mk'_eq_mk' QuotientGroup.mk'_eq_mk' #align quotient_add_group.mk'_eq_mk' QuotientAddGroup.mk'_eq_mk' open scoped Pointwise in @[to_additive] theorem sound (U : Set (G ⧸ N)) (g : N.op) : g • (mk' N) ⁻¹' U = (mk' N) ⁻¹' U := by ext x simp only [Set.mem_preimage, Set.mem_smul_set_iff_inv_smul_mem] congr! 1 exact Quotient.sound ⟨g⁻¹, rfl⟩ /-- Two `MonoidHom`s from a quotient group are equal if their compositions with `QuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. -/ @[to_additive (attr := ext 1100) "Two `AddMonoidHom`s from an additive quotient group are equal if their compositions with `AddQuotientGroup.mk'` are equal. See note [partially-applied ext lemmas]. "] theorem monoidHom_ext ⦃f g : G ⧸ N →* M⦄ (h : f.comp (mk' N) = g.comp (mk' N)) : f = g := MonoidHom.ext fun x => QuotientGroup.induction_on x <| (DFunLike.congr_fun h : _) #align quotient_group.monoid_hom_ext QuotientGroup.monoidHom_ext #align quotient_add_group.add_monoid_hom_ext QuotientAddGroup.addMonoidHom_ext @[to_additive (attr := simp)] theorem eq_one_iff {N : Subgroup G} [nN : N.Normal] (x : G) : (x : G ⧸ N) = 1 ↔ x ∈ N := by refine QuotientGroup.eq.trans ?_ rw [mul_one, Subgroup.inv_mem_iff] #align quotient_group.eq_one_iff QuotientGroup.eq_one_iff #align quotient_add_group.eq_zero_iff QuotientAddGroup.eq_zero_iff @[to_additive] theorem ker_le_range_iff {I : Type w} [Group I] (f : G →* H) [f.range.Normal] (g : H →* I) : g.ker ≤ f.range ↔ (mk' f.range).comp g.ker.subtype = 1 := ⟨fun h => MonoidHom.ext fun ⟨_, hx⟩ => (eq_one_iff _).mpr <| h hx, fun h x hx => (eq_one_iff _).mp <| by exact DFunLike.congr_fun h ⟨x, hx⟩⟩ @[to_additive (attr := simp)] theorem ker_mk' : MonoidHom.ker (QuotientGroup.mk' N : G →* G ⧸ N) = N := Subgroup.ext eq_one_iff #align quotient_group.ker_mk QuotientGroup.ker_mk' #align quotient_add_group.ker_mk QuotientAddGroup.ker_mk' -- Porting note: I think this is misnamed without the prime @[to_additive] theorem eq_iff_div_mem {N : Subgroup G} [nN : N.Normal] {x y : G} : (x : G ⧸ N) = y ↔ x / y ∈ N := by refine eq_comm.trans (QuotientGroup.eq.trans ?_) rw [nN.mem_comm_iff, div_eq_mul_inv] #align quotient_group.eq_iff_div_mem QuotientGroup.eq_iff_div_mem #align quotient_add_group.eq_iff_sub_mem QuotientAddGroup.eq_iff_sub_mem -- for commutative groups we don't need normality assumption @[to_additive] instance Quotient.commGroup {G : Type*} [CommGroup G] (N : Subgroup G) : CommGroup (G ⧸ N) := { toGroup := @QuotientGroup.Quotient.group _ _ N N.normal_of_comm mul_comm := fun a b => Quotient.inductionOn₂' a b fun a b => congr_arg mk (mul_comm a b) } #align quotient_group.quotient.comm_group QuotientGroup.Quotient.commGroup #align quotient_add_group.quotient.add_comm_group QuotientAddGroup.Quotient.addCommGroup local notation " Q " => G ⧸ N @[to_additive (attr := simp)] theorem mk_one : ((1 : G) : Q) = 1 := rfl #align quotient_group.coe_one QuotientGroup.mk_one #align quotient_add_group.coe_zero QuotientAddGroup.mk_zero @[to_additive (attr := simp)] theorem mk_mul (a b : G) : ((a * b : G) : Q) = a * b := rfl #align quotient_group.coe_mul QuotientGroup.mk_mul #align quotient_add_group.coe_add QuotientAddGroup.mk_add @[to_additive (attr := simp)] theorem mk_inv (a : G) : ((a⁻¹ : G) : Q) = (a : Q)⁻¹ := rfl #align quotient_group.coe_inv QuotientGroup.mk_inv #align quotient_add_group.coe_neg QuotientAddGroup.mk_neg @[to_additive (attr := simp)] theorem mk_div (a b : G) : ((a / b : G) : Q) = a / b := rfl #align quotient_group.coe_div QuotientGroup.mk_div #align quotient_add_group.coe_sub QuotientAddGroup.mk_sub @[to_additive (attr := simp)] theorem mk_pow (a : G) (n : ℕ) : ((a ^ n : G) : Q) = (a : Q) ^ n := rfl #align quotient_group.coe_pow QuotientGroup.mk_pow #align quotient_add_group.coe_nsmul QuotientAddGroup.mk_nsmul @[to_additive (attr := simp)] theorem mk_zpow (a : G) (n : ℤ) : ((a ^ n : G) : Q) = (a : Q) ^ n := rfl #align quotient_group.coe_zpow QuotientGroup.mk_zpow #align quotient_add_group.coe_zsmul QuotientAddGroup.mk_zsmul @[to_additive (attr := simp)] theorem mk_prod {G ι : Type*} [CommGroup G] (N : Subgroup G) (s : Finset ι) {f : ι → G} : ((Finset.prod s f : G) : G ⧸ N) = Finset.prod s (fun i => (f i : G ⧸ N)) := map_prod (QuotientGroup.mk' N) _ _ @[to_additive (attr := simp)] lemma map_mk'_self : N.map (mk' N) = ⊥ := by aesop /-- A group homomorphism `φ : G →* M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a group homomorphism `G/N →* M`. -/ @[to_additive "An `AddGroup` homomorphism `φ : G →+ M` with `N ⊆ ker(φ)` descends (i.e. `lift`s) to a group homomorphism `G/N →* M`."] def lift (φ : G →* M) (HN : N ≤ φ.ker) : Q →* M := (QuotientGroup.con N).lift φ fun x y h => by simp only [QuotientGroup.con, leftRel_apply, Con.rel_mk] at h rw [Con.ker_rel] calc φ x = φ (y * (x⁻¹ * y)⁻¹) := by rw [mul_inv_rev, inv_inv, mul_inv_cancel_left] _ = φ y := by rw [φ.map_mul, HN (N.inv_mem h), mul_one] #align quotient_group.lift QuotientGroup.lift #align quotient_add_group.lift QuotientAddGroup.lift @[to_additive (attr := simp)] theorem lift_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (g : Q) = φ g := rfl #align quotient_group.lift_mk QuotientGroup.lift_mk #align quotient_add_group.lift_mk QuotientAddGroup.lift_mk @[to_additive (attr := simp)] theorem lift_mk' {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (mk g : Q) = φ g := rfl -- TODO: replace `mk` with `mk'`) #align quotient_group.lift_mk' QuotientGroup.lift_mk' #align quotient_add_group.lift_mk' QuotientAddGroup.lift_mk' @[to_additive (attr := simp)] theorem lift_quot_mk {φ : G →* M} (HN : N ≤ φ.ker) (g : G) : lift N φ HN (Quot.mk _ g : Q) = φ g := rfl #align quotient_group.lift_quot_mk QuotientGroup.lift_quot_mk #align quotient_add_group.lift_quot_mk QuotientAddGroup.lift_quot_mk /-- A group homomorphism `f : G →* H` induces a map `G/N →* H/M` if `N ⊆ f⁻¹(M)`. -/ @[to_additive "An `AddGroup` homomorphism `f : G →+ H` induces a map `G/N →+ H/M` if `N ⊆ f⁻¹(M)`."] def map (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) : G ⧸ N →* H ⧸ M := by refine QuotientGroup.lift N ((mk' M).comp f) ?_ intro x hx refine QuotientGroup.eq.2 ?_ rw [mul_one, Subgroup.inv_mem_iff] exact h hx #align quotient_group.map QuotientGroup.map #align quotient_add_group.map QuotientAddGroup.map @[to_additive (attr := simp)] theorem map_mk (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) : map N M f h ↑x = ↑(f x) := rfl #align quotient_group.map_coe QuotientGroup.map_mk #align quotient_add_group.map_coe QuotientAddGroup.map_mk @[to_additive] theorem map_mk' (M : Subgroup H) [M.Normal] (f : G →* H) (h : N ≤ M.comap f) (x : G) : map N M f h (mk' _ x) = ↑(f x) := rfl #align quotient_group.map_mk' QuotientGroup.map_mk' #align quotient_add_group.map_mk' QuotientAddGroup.map_mk' @[to_additive] theorem map_id_apply (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) (x) : map N N (MonoidHom.id _) h x = x := induction_on' x fun _x => rfl #align quotient_group.map_id_apply QuotientGroup.map_id_apply #align quotient_add_group.map_id_apply QuotientAddGroup.map_id_apply @[to_additive (attr := simp)] theorem map_id (h : N ≤ Subgroup.comap (MonoidHom.id _) N := (Subgroup.comap_id N).le) : map N N (MonoidHom.id _) h = MonoidHom.id _ := MonoidHom.ext (map_id_apply N h) #align quotient_group.map_id QuotientGroup.map_id #align quotient_add_group.map_id QuotientAddGroup.map_id @[to_additive (attr := simp)]
Mathlib/GroupTheory/QuotientGroup.lean
285
291
theorem map_map {I : Type*} [Group I] (M : Subgroup H) (O : Subgroup I) [M.Normal] [O.Normal] (f : G →* H) (g : H →* I) (hf : N ≤ Subgroup.comap f M) (hg : M ≤ Subgroup.comap g O) (hgf : N ≤ Subgroup.comap (g.comp f) O := hf.trans ((Subgroup.comap_mono hg).trans_eq (Subgroup.comap_comap _ _ _))) (x : G ⧸ N) : map M O g hg (map N M f hf x) = map N O (g.comp f) hgf x := by
refine induction_on' x fun x => ?_ simp only [map_mk, MonoidHom.comp_apply]
/- Copyright (c) 2019 Zhouhang Zhou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis -/ import Mathlib.Algebra.DirectSum.Module import Mathlib.Analysis.Complex.Basic import Mathlib.Analysis.Convex.Uniform import Mathlib.Analysis.NormedSpace.Completion import Mathlib.Analysis.NormedSpace.BoundedLinearMaps #align_import analysis.inner_product_space.basic from "leanprover-community/mathlib"@"3f655f5297b030a87d641ad4e825af8d9679eb0b" /-! # Inner product space This file defines inner product spaces and proves the basic properties. We do not formally define Hilbert spaces, but they can be obtained using the set of assumptions `[NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E]`. An inner product space is a vector space endowed with an inner product. It generalizes the notion of dot product in `ℝ^n` and provides the means of defining the length of a vector and the angle between two vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero. We define both the real and complex cases at the same time using the `RCLike` typeclass. This file proves general results on inner product spaces. For the specific construction of an inner product structure on `n → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `EuclideanSpace` in `Analysis.InnerProductSpace.PiL2`. ## Main results - We define the class `InnerProductSpace 𝕜 E` extending `NormedSpace 𝕜 E` with a number of basic properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ` or `ℂ`, through the `RCLike` typeclass. - We show that the inner product is continuous, `continuous_inner`, and bundle it as the continuous sesquilinear map `innerSL` (see also `innerₛₗ` for the non-continuous version). - We define `Orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a maximal orthonormal set, `exists_maximal_orthonormal`. Bessel's inequality, `Orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`, the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of `x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file `Analysis.InnerProductSpace.projection`. ## Notation We globally denote the real and complex inner products by `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively. We also provide two notation namespaces: `RealInnerProductSpace`, `ComplexInnerProductSpace`, which respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product. ## Implementation notes We choose the convention that inner products are conjugate linear in the first argument and linear in the second. ## Tags inner product space, Hilbert space, norm ## References * [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*] * [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*] The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html> -/ noncomputable section open RCLike Real Filter open Topology ComplexConjugate open LinearMap (BilinForm) variable {𝕜 E F : Type*} [RCLike 𝕜] /-- Syntactic typeclass for types endowed with an inner product -/ class Inner (𝕜 E : Type*) where /-- The inner product function. -/ inner : E → E → 𝕜 #align has_inner Inner export Inner (inner) /-- The inner product with values in `𝕜`. -/ notation3:max "⟪" x ", " y "⟫_" 𝕜:max => @inner 𝕜 _ _ x y section Notations /-- The inner product with values in `ℝ`. -/ scoped[RealInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℝ _ _ x y /-- The inner product with values in `ℂ`. -/ scoped[ComplexInnerProductSpace] notation "⟪" x ", " y "⟫" => @inner ℂ _ _ x y end Notations /-- An inner product space is a vector space with an additional operation called inner product. The norm could be derived from the inner product, instead we require the existence of a norm and the fact that `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product spaces. To construct a norm from an inner product, see `InnerProductSpace.ofCore`. -/ class InnerProductSpace (𝕜 : Type*) (E : Type*) [RCLike 𝕜] [NormedAddCommGroup E] extends NormedSpace 𝕜 E, Inner 𝕜 E where /-- The inner product induces the norm. -/ norm_sq_eq_inner : ∀ x : E, ‖x‖ ^ 2 = re (inner x x) /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space InnerProductSpace /-! ### Constructing a normed space structure from an inner product In the definition of an inner product space, we require the existence of a norm, which is equal (but maybe not defeq) to the square root of the scalar product. This makes it possible to put an inner product space structure on spaces with a preexisting norm (for instance `ℝ`), with good properties. However, sometimes, one would like to define the norm starting only from a well-behaved scalar product. This is what we implement in this paragraph, starting from a structure `InnerProductSpace.Core` stating that we have a nice scalar product. Our goal here is not to develop a whole theory with all the supporting API, as this will be done below for `InnerProductSpace`. Instead, we implement the bare minimum to go as directly as possible to the construction of the norm and the proof of the triangular inequality. Warning: Do not use this `Core` structure if the space you are interested in already has a norm instance defined on it, otherwise this will create a second non-defeq norm instance! -/ /-- A structure requiring that a scalar product is positive definite and symmetric, from which one can construct an `InnerProductSpace` instance in `InnerProductSpace.ofCore`. -/ -- @[nolint HasNonemptyInstance] porting note: I don't think we have this linter anymore structure InnerProductSpace.Core (𝕜 : Type*) (F : Type*) [RCLike 𝕜] [AddCommGroup F] [Module 𝕜 F] extends Inner 𝕜 F where /-- The inner product is *hermitian*, taking the `conj` swaps the arguments. -/ conj_symm : ∀ x y, conj (inner y x) = inner x y /-- The inner product is positive (semi)definite. -/ nonneg_re : ∀ x, 0 ≤ re (inner x x) /-- The inner product is positive definite. -/ definite : ∀ x, inner x x = 0 → x = 0 /-- The inner product is additive in the first coordinate. -/ add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z /-- The inner product is conjugate linear in the first coordinate. -/ smul_left : ∀ x y r, inner (r • x) y = conj r * inner x y #align inner_product_space.core InnerProductSpace.Core /- We set `InnerProductSpace.Core` to be a class as we will use it as such in the construction of the normed space structure that it produces. However, all the instances we will use will be local to this proof. -/ attribute [class] InnerProductSpace.Core /-- Define `InnerProductSpace.Core` from `InnerProductSpace`. Defined to reuse lemmas about `InnerProductSpace.Core` for `InnerProductSpace`s. Note that the `Norm` instance provided by `InnerProductSpace.Core.norm` is propositionally but not definitionally equal to the original norm. -/ def InnerProductSpace.toCore [NormedAddCommGroup E] [c : InnerProductSpace 𝕜 E] : InnerProductSpace.Core 𝕜 E := { c with nonneg_re := fun x => by rw [← InnerProductSpace.norm_sq_eq_inner] apply sq_nonneg definite := fun x hx => norm_eq_zero.1 <| pow_eq_zero (n := 2) <| by rw [InnerProductSpace.norm_sq_eq_inner (𝕜 := 𝕜) x, hx, map_zero] } #align inner_product_space.to_core InnerProductSpace.toCore namespace InnerProductSpace.Core variable [AddCommGroup F] [Module 𝕜 F] [c : InnerProductSpace.Core 𝕜 F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 F _ x y local notation "normSqK" => @RCLike.normSq 𝕜 _ local notation "reK" => @RCLike.re 𝕜 _ local notation "ext_iff" => @RCLike.ext_iff 𝕜 _ local postfix:90 "†" => starRingEnd _ /-- Inner product defined by the `InnerProductSpace.Core` structure. We can't reuse `InnerProductSpace.Core.toInner` because it takes `InnerProductSpace.Core` as an explicit argument. -/ def toInner' : Inner 𝕜 F := c.toInner #align inner_product_space.core.to_has_inner' InnerProductSpace.Core.toInner' attribute [local instance] toInner' /-- The norm squared function for `InnerProductSpace.Core` structure. -/ def normSq (x : F) := reK ⟪x, x⟫ #align inner_product_space.core.norm_sq InnerProductSpace.Core.normSq local notation "normSqF" => @normSq 𝕜 F _ _ _ _ theorem inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_symm x y #align inner_product_space.core.inner_conj_symm InnerProductSpace.Core.inner_conj_symm theorem inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _ #align inner_product_space.core.inner_self_nonneg InnerProductSpace.Core.inner_self_nonneg theorem inner_self_im (x : F) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub] simp [inner_conj_symm] #align inner_product_space.core.inner_self_im InnerProductSpace.Core.inner_self_im theorem inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := c.add_left _ _ _ #align inner_product_space.core.inner_add_left InnerProductSpace.Core.inner_add_left theorem inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add]; simp only [inner_conj_symm] #align inner_product_space.core.inner_add_right InnerProductSpace.Core.inner_add_right theorem ofReal_normSq_eq_inner_self (x : F) : (normSqF x : 𝕜) = ⟪x, x⟫ := by rw [ext_iff] exact ⟨by simp only [ofReal_re]; rfl, by simp only [inner_self_im, ofReal_im]⟩ #align inner_product_space.core.coe_norm_sq_eq_inner_self InnerProductSpace.Core.ofReal_normSq_eq_inner_self theorem inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_product_space.core.inner_re_symm InnerProductSpace.Core.inner_re_symm theorem inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_product_space.core.inner_im_symm InnerProductSpace.Core.inner_im_symm theorem inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := c.smul_left _ _ _ #align inner_product_space.core.inner_smul_left InnerProductSpace.Core.inner_smul_left theorem inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, RingHom.map_mul] #align inner_product_space.core.inner_smul_right InnerProductSpace.Core.inner_smul_right theorem inner_zero_left (x : F) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, RingHom.map_zero] #align inner_product_space.core.inner_zero_left InnerProductSpace.Core.inner_zero_left theorem inner_zero_right (x : F) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left]; simp only [RingHom.map_zero] #align inner_product_space.core.inner_zero_right InnerProductSpace.Core.inner_zero_right theorem inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 := ⟨c.definite _, by rintro rfl exact inner_zero_left _⟩ #align inner_product_space.core.inner_self_eq_zero InnerProductSpace.Core.inner_self_eq_zero theorem normSq_eq_zero {x : F} : normSqF x = 0 ↔ x = 0 := Iff.trans (by simp only [normSq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true_iff]) (@inner_self_eq_zero 𝕜 _ _ _ _ _ x) #align inner_product_space.core.norm_sq_eq_zero InnerProductSpace.Core.normSq_eq_zero theorem inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_product_space.core.inner_self_ne_zero InnerProductSpace.Core.inner_self_ne_zero theorem inner_self_ofReal_re (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := by norm_num [ext_iff, inner_self_im] set_option linter.uppercaseLean3 false in #align inner_product_space.core.inner_self_re_to_K InnerProductSpace.Core.inner_self_ofReal_re theorem norm_inner_symm (x y : F) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align inner_product_space.core.norm_inner_symm InnerProductSpace.Core.norm_inner_symm theorem inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_product_space.core.inner_neg_left InnerProductSpace.Core.inner_neg_left theorem inner_neg_right (x y : F) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_product_space.core.inner_neg_right InnerProductSpace.Core.inner_neg_right theorem inner_sub_left (x y z : F) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left, inner_neg_left] #align inner_product_space.core.inner_sub_left InnerProductSpace.Core.inner_sub_left theorem inner_sub_right (x y z : F) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right, inner_neg_right] #align inner_product_space.core.inner_sub_right InnerProductSpace.Core.inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : F) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_product_space.core.inner_mul_symm_re_eq_norm InnerProductSpace.Core.inner_mul_symm_re_eq_norm /-- Expand `inner (x + y) (x + y)` -/ theorem inner_add_add_self (x y : F) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_product_space.core.inner_add_add_self InnerProductSpace.Core.inner_add_add_self -- Expand `inner (x - y) (x - y)` theorem inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_product_space.core.inner_sub_sub_self InnerProductSpace.Core.inner_sub_sub_self /-- An auxiliary equality useful to prove the **Cauchy–Schwarz inequality**: the square of the norm of `⟪x, y⟫ • x - ⟪x, x⟫ • y` is equal to `‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2 - ‖⟪x, y⟫‖ ^ 2)`. We use `InnerProductSpace.ofCore.normSq x` etc (defeq to `is_R_or_C.re ⟪x, x⟫`) instead of `‖x‖ ^ 2` etc to avoid extra rewrites when applying it to an `InnerProductSpace`. -/ theorem cauchy_schwarz_aux (x y : F) : normSqF (⟪x, y⟫ • x - ⟪x, x⟫ • y) = normSqF x * (normSqF x * normSqF y - ‖⟪x, y⟫‖ ^ 2) := by rw [← @ofReal_inj 𝕜, ofReal_normSq_eq_inner_self] simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, conj_ofReal, mul_sub, ← ofReal_normSq_eq_inner_self x, ← ofReal_normSq_eq_inner_self y] rw [← mul_assoc, mul_conj, RCLike.conj_mul, mul_left_comm, ← inner_conj_symm y, mul_conj] push_cast ring #align inner_product_space.core.cauchy_schwarz_aux InnerProductSpace.Core.cauchy_schwarz_aux /-- **Cauchy–Schwarz inequality**. We need this for the `Core` structure to prove the triangle inequality below when showing the core is a normed group. -/ theorem inner_mul_inner_self_le (x y : F) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := by rcases eq_or_ne x 0 with (rfl | hx) · simpa only [inner_zero_left, map_zero, zero_mul, norm_zero] using le_rfl · have hx' : 0 < normSqF x := inner_self_nonneg.lt_of_ne' (mt normSq_eq_zero.1 hx) rw [← sub_nonneg, ← mul_nonneg_iff_right_nonneg_of_pos hx', ← normSq, ← normSq, norm_inner_symm y, ← sq, ← cauchy_schwarz_aux] exact inner_self_nonneg #align inner_product_space.core.inner_mul_inner_self_le InnerProductSpace.Core.inner_mul_inner_self_le /-- Norm constructed from an `InnerProductSpace.Core` structure, defined to be the square root of the scalar product. -/ def toNorm : Norm F where norm x := √(re ⟪x, x⟫) #align inner_product_space.core.to_has_norm InnerProductSpace.Core.toNorm attribute [local instance] toNorm theorem norm_eq_sqrt_inner (x : F) : ‖x‖ = √(re ⟪x, x⟫) := rfl #align inner_product_space.core.norm_eq_sqrt_inner InnerProductSpace.Core.norm_eq_sqrt_inner theorem inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by rw [norm_eq_sqrt_inner, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] #align inner_product_space.core.inner_self_eq_norm_mul_norm InnerProductSpace.Core.inner_self_eq_norm_mul_norm theorem sqrt_normSq_eq_norm (x : F) : √(normSqF x) = ‖x‖ := rfl #align inner_product_space.core.sqrt_norm_sq_eq_norm InnerProductSpace.Core.sqrt_normSq_eq_norm /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : F) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) <| calc ‖⟪x, y⟫‖ * ‖⟪x, y⟫‖ = ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ := by rw [norm_inner_symm] _ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := inner_mul_inner_self_le x y _ = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) := by simp only [inner_self_eq_norm_mul_norm]; ring #align inner_product_space.core.norm_inner_le_norm InnerProductSpace.Core.norm_inner_le_norm /-- Normed group structure constructed from an `InnerProductSpace.Core` structure -/ def toNormedAddCommGroup : NormedAddCommGroup F := AddGroupNorm.toNormedAddCommGroup { toFun := fun x => √(re ⟪x, x⟫) map_zero' := by simp only [sqrt_zero, inner_zero_right, map_zero] neg' := fun x => by simp only [inner_neg_left, neg_neg, inner_neg_right] add_le' := fun x y => by have h₁ : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := norm_inner_le_norm _ _ have h₂ : re ⟪x, y⟫ ≤ ‖⟪x, y⟫‖ := re_le_norm _ have h₃ : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := h₂.trans h₁ have h₄ : re ⟪y, x⟫ ≤ ‖x‖ * ‖y‖ := by rwa [← inner_conj_symm, conj_re] have : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖) := by simp only [← inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add] linarith exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this eq_zero_of_map_eq_zero' := fun x hx => normSq_eq_zero.1 <| (sqrt_eq_zero inner_self_nonneg).1 hx } #align inner_product_space.core.to_normed_add_comm_group InnerProductSpace.Core.toNormedAddCommGroup attribute [local instance] toNormedAddCommGroup /-- Normed space structure constructed from an `InnerProductSpace.Core` structure -/ def toNormedSpace : NormedSpace 𝕜 F where norm_smul_le r x := by rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ← mul_assoc] rw [RCLike.conj_mul, ← ofReal_pow, re_ofReal_mul, sqrt_mul, ← ofReal_normSq_eq_inner_self, ofReal_re] · simp [sqrt_normSq_eq_norm, RCLike.sqrt_normSq_eq_norm] · positivity #align inner_product_space.core.to_normed_space InnerProductSpace.Core.toNormedSpace end InnerProductSpace.Core section attribute [local instance] InnerProductSpace.Core.toNormedAddCommGroup /-- Given an `InnerProductSpace.Core` structure on a space, one can use it to turn the space into an inner product space. The `NormedAddCommGroup` structure is expected to already be defined with `InnerProductSpace.ofCore.toNormedAddCommGroup`. -/ def InnerProductSpace.ofCore [AddCommGroup F] [Module 𝕜 F] (c : InnerProductSpace.Core 𝕜 F) : InnerProductSpace 𝕜 F := letI : NormedSpace 𝕜 F := @InnerProductSpace.Core.toNormedSpace 𝕜 F _ _ _ c { c with norm_sq_eq_inner := fun x => by have h₁ : ‖x‖ ^ 2 = √(re (c.inner x x)) ^ 2 := rfl have h₂ : 0 ≤ re (c.inner x x) := InnerProductSpace.Core.inner_self_nonneg simp [h₁, sq_sqrt, h₂] } #align inner_product_space.of_core InnerProductSpace.ofCore end /-! ### Properties of inner product spaces -/ variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable [NormedAddCommGroup F] [InnerProductSpace ℝ F] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y local notation "IK" => @RCLike.I 𝕜 _ local postfix:90 "†" => starRingEnd _ export InnerProductSpace (norm_sq_eq_inner) section BasicProperties @[simp] theorem inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ := InnerProductSpace.conj_symm _ _ #align inner_conj_symm inner_conj_symm theorem real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := @inner_conj_symm ℝ _ _ _ _ x y #align real_inner_comm real_inner_comm theorem inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 := by rw [← inner_conj_symm] exact star_eq_zero #align inner_eq_zero_symm inner_eq_zero_symm @[simp] theorem inner_self_im (x : E) : im ⟪x, x⟫ = 0 := by rw [← @ofReal_inj 𝕜, im_eq_conj_sub]; simp #align inner_self_im inner_self_im theorem inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ := InnerProductSpace.add_left _ _ _ #align inner_add_left inner_add_left theorem inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ := by rw [← inner_conj_symm, inner_add_left, RingHom.map_add] simp only [inner_conj_symm] #align inner_add_right inner_add_right theorem inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ := by rw [← inner_conj_symm, conj_re] #align inner_re_symm inner_re_symm theorem inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ := by rw [← inner_conj_symm, conj_im] #align inner_im_symm inner_im_symm theorem inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ := InnerProductSpace.smul_left _ _ _ #align inner_smul_left inner_smul_left theorem real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_left _ _ _ #align real_inner_smul_left real_inner_smul_left theorem inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_left, conj_ofReal, Algebra.smul_def] rfl #align inner_smul_real_left inner_smul_real_left theorem inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ := by rw [← inner_conj_symm, inner_smul_left, RingHom.map_mul, conj_conj, inner_conj_symm] #align inner_smul_right inner_smul_right theorem real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_right _ _ _ #align real_inner_smul_right real_inner_smul_right theorem inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ := by rw [inner_smul_right, Algebra.smul_def] rfl #align inner_smul_real_right inner_smul_real_right /-- The inner product as a sesquilinear form. Note that in the case `𝕜 = ℝ` this is a bilinear form. -/ @[simps!] def sesqFormOfInner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 := LinearMap.mk₂'ₛₗ (RingHom.id 𝕜) (starRingEnd _) (fun x y => ⟪y, x⟫) (fun _x _y _z => inner_add_right _ _ _) (fun _r _x _y => inner_smul_right _ _ _) (fun _x _y _z => inner_add_left _ _ _) fun _r _x _y => inner_smul_left _ _ _ #align sesq_form_of_inner sesqFormOfInner /-- The real inner product as a bilinear form. Note that unlike `sesqFormOfInner`, this does not reverse the order of the arguments. -/ @[simps!] def bilinFormOfRealInner : BilinForm ℝ F := sesqFormOfInner.flip #align bilin_form_of_real_inner bilinFormOfRealInner /-- An inner product with a sum on the left. -/ theorem sum_inner {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪∑ i ∈ s, f i, x⟫ = ∑ i ∈ s, ⟪f i, x⟫ := map_sum (sesqFormOfInner (𝕜 := 𝕜) (E := E) x) _ _ #align sum_inner sum_inner /-- An inner product with a sum on the right. -/ theorem inner_sum {ι : Type*} (s : Finset ι) (f : ι → E) (x : E) : ⟪x, ∑ i ∈ s, f i⟫ = ∑ i ∈ s, ⟪x, f i⟫ := map_sum (LinearMap.flip sesqFormOfInner x) _ _ #align inner_sum inner_sum /-- An inner product with a sum on the left, `Finsupp` version. -/ theorem Finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪l.sum fun (i : ι) (a : 𝕜) => a • v i, x⟫ = l.sum fun (i : ι) (a : 𝕜) => conj a • ⟪v i, x⟫ := by convert _root_.sum_inner (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_left, Finsupp.sum, smul_eq_mul] #align finsupp.sum_inner Finsupp.sum_inner /-- An inner product with a sum on the right, `Finsupp` version. -/ theorem Finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) : ⟪x, l.sum fun (i : ι) (a : 𝕜) => a • v i⟫ = l.sum fun (i : ι) (a : 𝕜) => a • ⟪x, v i⟫ := by convert _root_.inner_sum (𝕜 := 𝕜) l.support (fun a => l a • v a) x simp only [inner_smul_right, Finsupp.sum, smul_eq_mul] #align finsupp.inner_sum Finsupp.inner_sum theorem DFinsupp.sum_inner {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪l.sum f, x⟫ = l.sum fun i a => ⟪f i a, x⟫ := by simp (config := { contextual := true }) only [DFinsupp.sum, _root_.sum_inner, smul_eq_mul] #align dfinsupp.sum_inner DFinsupp.sum_inner theorem DFinsupp.inner_sum {ι : Type*} [DecidableEq ι] {α : ι → Type*} [∀ i, AddZeroClass (α i)] [∀ (i) (x : α i), Decidable (x ≠ 0)] (f : ∀ i, α i → E) (l : Π₀ i, α i) (x : E) : ⟪x, l.sum f⟫ = l.sum fun i a => ⟪x, f i a⟫ := by simp (config := { contextual := true }) only [DFinsupp.sum, _root_.inner_sum, smul_eq_mul] #align dfinsupp.inner_sum DFinsupp.inner_sum @[simp] theorem inner_zero_left (x : E) : ⟪0, x⟫ = 0 := by rw [← zero_smul 𝕜 (0 : E), inner_smul_left, RingHom.map_zero, zero_mul] #align inner_zero_left inner_zero_left theorem inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 := by simp only [inner_zero_left, AddMonoidHom.map_zero] #align inner_re_zero_left inner_re_zero_left @[simp] theorem inner_zero_right (x : E) : ⟪x, 0⟫ = 0 := by rw [← inner_conj_symm, inner_zero_left, RingHom.map_zero] #align inner_zero_right inner_zero_right theorem inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 := by simp only [inner_zero_right, AddMonoidHom.map_zero] #align inner_re_zero_right inner_re_zero_right theorem inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ := InnerProductSpace.toCore.nonneg_re x #align inner_self_nonneg inner_self_nonneg theorem real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ _ x #align real_inner_self_nonneg real_inner_self_nonneg @[simp] theorem inner_self_ofReal_re (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ := ((RCLike.is_real_TFAE (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im _) set_option linter.uppercaseLean3 false in #align inner_self_re_to_K inner_self_ofReal_re theorem inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ : 𝕜) ^ 2 := by rw [← inner_self_ofReal_re, ← norm_sq_eq_inner, ofReal_pow] set_option linter.uppercaseLean3 false in #align inner_self_eq_norm_sq_to_K inner_self_eq_norm_sq_to_K theorem inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ := by conv_rhs => rw [← inner_self_ofReal_re] symm exact norm_of_nonneg inner_self_nonneg #align inner_self_re_eq_norm inner_self_re_eq_norm theorem inner_self_ofReal_norm (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ := by rw [← inner_self_re_eq_norm] exact inner_self_ofReal_re _ set_option linter.uppercaseLean3 false in #align inner_self_norm_to_K inner_self_ofReal_norm theorem real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ := @inner_self_ofReal_norm ℝ F _ _ _ x #align real_inner_self_abs real_inner_self_abs @[simp] theorem inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 := by rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, ofReal_eq_zero, norm_eq_zero] #align inner_self_eq_zero inner_self_eq_zero theorem inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 := inner_self_eq_zero.not #align inner_self_ne_zero inner_self_ne_zero @[simp] theorem inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 := by rw [← norm_sq_eq_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero] #align inner_self_nonpos inner_self_nonpos theorem real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 := @inner_self_nonpos ℝ F _ _ _ x #align real_inner_self_nonpos real_inner_self_nonpos theorem norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ := by rw [← inner_conj_symm, norm_conj] #align norm_inner_symm norm_inner_symm @[simp] theorem inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ := by rw [← neg_one_smul 𝕜 x, inner_smul_left] simp #align inner_neg_left inner_neg_left @[simp] theorem inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ := by rw [← inner_conj_symm, inner_neg_left]; simp only [RingHom.map_neg, inner_conj_symm] #align inner_neg_right inner_neg_right theorem inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp #align inner_neg_neg inner_neg_neg -- Porting note: removed `simp` because it can prove it using `inner_conj_symm` theorem inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ := inner_conj_symm _ _ #align inner_self_conj inner_self_conj theorem inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ := by simp [sub_eq_add_neg, inner_add_left] #align inner_sub_left inner_sub_left theorem inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ := by simp [sub_eq_add_neg, inner_add_right] #align inner_sub_right inner_sub_right theorem inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ := by rw [← inner_conj_symm, mul_comm] exact re_eq_norm_of_mul_conj (inner y x) #align inner_mul_symm_re_eq_norm inner_mul_symm_re_eq_norm /-- Expand `⟪x + y, x + y⟫` -/ theorem inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_add_left, inner_add_right]; ring #align inner_add_add_self inner_add_add_self /-- Expand `⟪x + y, x + y⟫_ℝ` -/ theorem real_inner_add_add_self (x y : F) : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_add_add_self, this, add_left_inj] ring #align real_inner_add_add_self real_inner_add_add_self -- Expand `⟪x - y, x - y⟫` theorem inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ := by simp only [inner_sub_left, inner_sub_right]; ring #align inner_sub_sub_self inner_sub_sub_self /-- Expand `⟪x - y, x - y⟫_ℝ` -/ theorem real_inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ := by have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [← inner_conj_symm]; rfl simp only [inner_sub_sub_self, this, add_left_inj] ring #align real_inner_sub_sub_self real_inner_sub_sub_self variable (𝕜) theorem ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)] #align ext_inner_left ext_inner_left theorem ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y := by rw [← sub_eq_zero, ← @inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)] #align ext_inner_right ext_inner_right variable {𝕜} /-- Parallelogram law -/ theorem parallelogram_law {x y : E} : ⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) := by simp only [inner_add_add_self, inner_sub_sub_self] ring #align parallelogram_law parallelogram_law /-- **Cauchy–Schwarz inequality**. -/ theorem inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ := letI c : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore InnerProductSpace.Core.inner_mul_inner_self_le x y #align inner_mul_inner_self_le inner_mul_inner_self_le /-- Cauchy–Schwarz inequality for real inner products. -/ theorem real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := calc ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ := by rw [real_inner_comm y, ← norm_mul] exact le_abs_self _ _ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ := @inner_mul_inner_self_le ℝ _ _ _ _ x y #align real_inner_mul_inner_self_le real_inner_mul_inner_self_le /-- A family of vectors is linearly independent if they are nonzero and orthogonal. -/ theorem linearIndependent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E} (hz : ∀ i, v i ≠ 0) (ho : Pairwise fun i j => ⟪v i, v j⟫ = 0) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff'] intro s g hg i hi have h' : g i * inner (v i) (v i) = inner (v i) (∑ j ∈ s, g j • v j) := by rw [inner_sum] symm convert Finset.sum_eq_single (β := 𝕜) i ?_ ?_ · rw [inner_smul_right] · intro j _hj hji rw [inner_smul_right, ho hji.symm, mul_zero] · exact fun h => False.elim (h hi) simpa [hg, hz] using h' #align linear_independent_of_ne_zero_of_inner_eq_zero linearIndependent_of_ne_zero_of_inner_eq_zero end BasicProperties section OrthonormalSets variable {ι : Type*} (𝕜) /-- An orthonormal set of vectors in an `InnerProductSpace` -/ def Orthonormal (v : ι → E) : Prop := (∀ i, ‖v i‖ = 1) ∧ Pairwise fun i j => ⟪v i, v j⟫ = 0 #align orthonormal Orthonormal variable {𝕜} /-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_iff_ite [DecidableEq ι] {v : ι → E} : Orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1 : 𝕜) else (0 : 𝕜) := by constructor · intro hv i j split_ifs with h · simp [h, inner_self_eq_norm_sq_to_K, hv.1] · exact hv.2 h · intro h constructor · intro i have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner 𝕜, h i i] have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _ have h₂ : (0 : ℝ) ≤ 1 := zero_le_one rwa [sq_eq_sq h₁ h₂] at h' · intro i j hij simpa [hij] using h i j #align orthonormal_iff_ite orthonormal_iff_ite /-- `if ... then ... else` characterization of a set of vectors being orthonormal. (Inner product equals Kronecker delta.) -/ theorem orthonormal_subtype_iff_ite [DecidableEq E] {s : Set E} : Orthonormal 𝕜 (Subtype.val : s → E) ↔ ∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = if v = w then 1 else 0 := by rw [orthonormal_iff_ite] constructor · intro h v hv w hw convert h ⟨v, hv⟩ ⟨w, hw⟩ using 1 simp · rintro h ⟨v, hv⟩ ⟨w, hw⟩ convert h v hv w hw using 1 simp #align orthonormal_subtype_iff_ite orthonormal_subtype_iff_ite /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = l i := by classical simpa [Finsupp.total_apply, Finsupp.inner_sum, orthonormal_iff_ite.mp hv] using Eq.symm #align orthonormal.inner_right_finsupp Orthonormal.inner_right_finsupp /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι} {i : ι} (hi : i ∈ s) : ⟪v i, ∑ i ∈ s, l i • v i⟫ = l i := by classical simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi] #align orthonormal.inner_right_sum Orthonormal.inner_right_sum /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_right_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) : ⟪v i, ∑ i : ι, l i • v i⟫ = l i := hv.inner_right_sum l (Finset.mem_univ _) #align orthonormal.inner_right_fintype Orthonormal.inner_right_fintype /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_finsupp {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) : ⟪Finsupp.total ι E 𝕜 v l, v i⟫ = conj (l i) := by rw [← inner_conj_symm, hv.inner_right_finsupp] #align orthonormal.inner_left_finsupp Orthonormal.inner_left_finsupp /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) {s : Finset ι} {i : ι} (hi : i ∈ s) : ⟪∑ i ∈ s, l i • v i, v i⟫ = conj (l i) := by classical simp only [sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole, Finset.sum_ite_eq', if_true] #align orthonormal.inner_left_sum Orthonormal.inner_left_sum /-- The inner product of a linear combination of a set of orthonormal vectors with one of those vectors picks out the coefficient of that vector. -/ theorem Orthonormal.inner_left_fintype [Fintype ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) : ⟪∑ i : ι, l i • v i, v i⟫ = conj (l i) := hv.inner_left_sum l (Finset.mem_univ _) #align orthonormal.inner_left_fintype Orthonormal.inner_left_fintype /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum over the first `Finsupp`. -/ theorem Orthonormal.inner_finsupp_eq_sum_left {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) : ⟪Finsupp.total ι E 𝕜 v l₁, Finsupp.total ι E 𝕜 v l₂⟫ = l₁.sum fun i y => conj y * l₂ i := by simp only [l₁.total_apply _, Finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul] #align orthonormal.inner_finsupp_eq_sum_left Orthonormal.inner_finsupp_eq_sum_left /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum over the second `Finsupp`. -/ theorem Orthonormal.inner_finsupp_eq_sum_right {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) : ⟪Finsupp.total ι E 𝕜 v l₁, Finsupp.total ι E 𝕜 v l₂⟫ = l₂.sum fun i y => conj (l₁ i) * y := by simp only [l₂.total_apply _, Finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul] #align orthonormal.inner_finsupp_eq_sum_right Orthonormal.inner_finsupp_eq_sum_right /-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as a sum. -/ theorem Orthonormal.inner_sum {v : ι → E} (hv : Orthonormal 𝕜 v) (l₁ l₂ : ι → 𝕜) (s : Finset ι) : ⟪∑ i ∈ s, l₁ i • v i, ∑ i ∈ s, l₂ i • v i⟫ = ∑ i ∈ s, conj (l₁ i) * l₂ i := by simp_rw [sum_inner, inner_smul_left] refine Finset.sum_congr rfl fun i hi => ?_ rw [hv.inner_right_sum l₂ hi] #align orthonormal.inner_sum Orthonormal.inner_sum /-- The double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the sum of the weights. -/ theorem Orthonormal.inner_left_right_finset {s : Finset ι} {v : ι → E} (hv : Orthonormal 𝕜 v) {a : ι → ι → 𝕜} : (∑ i ∈ s, ∑ j ∈ s, a i j • ⟪v j, v i⟫) = ∑ k ∈ s, a k k := by classical simp [orthonormal_iff_ite.mp hv, Finset.sum_ite_of_true] #align orthonormal.inner_left_right_finset Orthonormal.inner_left_right_finset /-- An orthonormal set is linearly independent. -/ theorem Orthonormal.linearIndependent {v : ι → E} (hv : Orthonormal 𝕜 v) : LinearIndependent 𝕜 v := by rw [linearIndependent_iff] intro l hl ext i have key : ⟪v i, Finsupp.total ι E 𝕜 v l⟫ = ⟪v i, 0⟫ := by rw [hl] simpa only [hv.inner_right_finsupp, inner_zero_right] using key #align orthonormal.linear_independent Orthonormal.linearIndependent /-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an orthonormal family. -/ theorem Orthonormal.comp {ι' : Type*} {v : ι → E} (hv : Orthonormal 𝕜 v) (f : ι' → ι) (hf : Function.Injective f) : Orthonormal 𝕜 (v ∘ f) := by classical rw [orthonormal_iff_ite] at hv ⊢ intro i j convert hv (f i) (f j) using 1 simp [hf.eq_iff] #align orthonormal.comp Orthonormal.comp /-- An injective family `v : ι → E` is orthonormal if and only if `Subtype.val : (range v) → E` is orthonormal. -/ theorem orthonormal_subtype_range {v : ι → E} (hv : Function.Injective v) : Orthonormal 𝕜 (Subtype.val : Set.range v → E) ↔ Orthonormal 𝕜 v := by let f : ι ≃ Set.range v := Equiv.ofInjective v hv refine ⟨fun h => h.comp f f.injective, fun h => ?_⟩ rw [← Equiv.self_comp_ofInjective_symm hv] exact h.comp f.symm f.symm.injective #align orthonormal_subtype_range orthonormal_subtype_range /-- If `v : ι → E` is an orthonormal family, then `Subtype.val : (range v) → E` is an orthonormal family. -/ theorem Orthonormal.toSubtypeRange {v : ι → E} (hv : Orthonormal 𝕜 v) : Orthonormal 𝕜 (Subtype.val : Set.range v → E) := (orthonormal_subtype_range hv.linearIndependent.injective).2 hv #align orthonormal.to_subtype_range Orthonormal.toSubtypeRange /-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the set. -/ theorem Orthonormal.inner_finsupp_eq_zero {v : ι → E} (hv : Orthonormal 𝕜 v) {s : Set ι} {i : ι} (hi : i ∉ s) {l : ι →₀ 𝕜} (hl : l ∈ Finsupp.supported 𝕜 𝕜 s) : ⟪Finsupp.total ι E 𝕜 v l, v i⟫ = 0 := by rw [Finsupp.mem_supported'] at hl simp only [hv.inner_left_finsupp, hl i hi, map_zero] #align orthonormal.inner_finsupp_eq_zero Orthonormal.inner_finsupp_eq_zero /-- Given an orthonormal family, a second family of vectors is orthonormal if every vector equals the corresponding vector in the original family or its negation. -/ theorem Orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : ι → E} (hv : Orthonormal 𝕜 v) (hw : ∀ i, w i = v i ∨ w i = -v i) : Orthonormal 𝕜 w := by classical rw [orthonormal_iff_ite] at * intro i j cases' hw i with hi hi <;> cases' hw j with hj hj <;> replace hv := hv i j <;> split_ifs at hv ⊢ with h <;> simpa only [hi, hj, h, inner_neg_right, inner_neg_left, neg_neg, eq_self_iff_true, neg_eq_zero] using hv #align orthonormal.orthonormal_of_forall_eq_or_eq_neg Orthonormal.orthonormal_of_forall_eq_or_eq_neg /- The material that follows, culminating in the existence of a maximal orthonormal subset, is adapted from the corresponding development of the theory of linearly independents sets. See `exists_linearIndependent` in particular. -/ variable (𝕜 E) theorem orthonormal_empty : Orthonormal 𝕜 (fun x => x : (∅ : Set E) → E) := by classical simp [orthonormal_subtype_iff_ite] #align orthonormal_empty orthonormal_empty variable {𝕜 E} theorem orthonormal_iUnion_of_directed {η : Type*} {s : η → Set E} (hs : Directed (· ⊆ ·) s) (h : ∀ i, Orthonormal 𝕜 (fun x => x : s i → E)) : Orthonormal 𝕜 (fun x => x : (⋃ i, s i) → E) := by classical rw [orthonormal_subtype_iff_ite] rintro x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩ obtain ⟨k, hik, hjk⟩ := hs i j have h_orth : Orthonormal 𝕜 (fun x => x : s k → E) := h k rw [orthonormal_subtype_iff_ite] at h_orth exact h_orth x (hik hxi) y (hjk hyj) #align orthonormal_Union_of_directed orthonormal_iUnion_of_directed theorem orthonormal_sUnion_of_directed {s : Set (Set E)} (hs : DirectedOn (· ⊆ ·) s) (h : ∀ a ∈ s, Orthonormal 𝕜 (fun x => ((x : a) : E))) : Orthonormal 𝕜 (fun x => x : ⋃₀ s → E) := by rw [Set.sUnion_eq_iUnion]; exact orthonormal_iUnion_of_directed hs.directed_val (by simpa using h) #align orthonormal_sUnion_of_directed orthonormal_sUnion_of_directed /-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set containing it. -/ theorem exists_maximal_orthonormal {s : Set E} (hs : Orthonormal 𝕜 (Subtype.val : s → E)) : ∃ w ⊇ s, Orthonormal 𝕜 (Subtype.val : w → E) ∧ ∀ u ⊇ w, Orthonormal 𝕜 (Subtype.val : u → E) → u = w := by have := zorn_subset_nonempty { b | Orthonormal 𝕜 (Subtype.val : b → E) } ?_ _ hs · obtain ⟨b, bi, sb, h⟩ := this refine ⟨b, sb, bi, ?_⟩ exact fun u hus hu => h u hu hus · refine fun c hc cc _c0 => ⟨⋃₀ c, ?_, ?_⟩ · exact orthonormal_sUnion_of_directed cc.directedOn fun x xc => hc xc · exact fun _ => Set.subset_sUnion_of_mem #align exists_maximal_orthonormal exists_maximal_orthonormal theorem Orthonormal.ne_zero {v : ι → E} (hv : Orthonormal 𝕜 v) (i : ι) : v i ≠ 0 := by have : ‖v i‖ ≠ 0 := by rw [hv.1 i] norm_num simpa using this #align orthonormal.ne_zero Orthonormal.ne_zero open FiniteDimensional /-- A family of orthonormal vectors with the correct cardinality forms a basis. -/ def basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) : Basis ι 𝕜 E := basisOfLinearIndependentOfCardEqFinrank hv.linearIndependent card_eq #align basis_of_orthonormal_of_card_eq_finrank basisOfOrthonormalOfCardEqFinrank @[simp] theorem coe_basisOfOrthonormalOfCardEqFinrank [Fintype ι] [Nonempty ι] {v : ι → E} (hv : Orthonormal 𝕜 v) (card_eq : Fintype.card ι = finrank 𝕜 E) : (basisOfOrthonormalOfCardEqFinrank hv card_eq : ι → E) = v := coe_basisOfLinearIndependentOfCardEqFinrank _ _ #align coe_basis_of_orthonormal_of_card_eq_finrank coe_basisOfOrthonormalOfCardEqFinrank end OrthonormalSets section Norm theorem norm_eq_sqrt_inner (x : E) : ‖x‖ = √(re ⟪x, x⟫) := calc ‖x‖ = √(‖x‖ ^ 2) := (sqrt_sq (norm_nonneg _)).symm _ = √(re ⟪x, x⟫) := congr_arg _ (norm_sq_eq_inner _) #align norm_eq_sqrt_inner norm_eq_sqrt_inner theorem norm_eq_sqrt_real_inner (x : F) : ‖x‖ = √⟪x, x⟫_ℝ := @norm_eq_sqrt_inner ℝ _ _ _ _ x #align norm_eq_sqrt_real_inner norm_eq_sqrt_real_inner theorem inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ := by rw [@norm_eq_sqrt_inner 𝕜, ← sqrt_mul inner_self_nonneg (re ⟪x, x⟫), sqrt_mul_self inner_self_nonneg] #align inner_self_eq_norm_mul_norm inner_self_eq_norm_mul_norm theorem inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖ ^ 2 := by rw [pow_two, inner_self_eq_norm_mul_norm] #align inner_self_eq_norm_sq inner_self_eq_norm_sq theorem real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ := by have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x simpa using h #align real_inner_self_eq_norm_mul_norm real_inner_self_eq_norm_mul_norm theorem real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖ ^ 2 := by rw [pow_two, real_inner_self_eq_norm_mul_norm] #align real_inner_self_eq_norm_sq real_inner_self_eq_norm_sq -- Porting note: this was present in mathlib3 but seemingly didn't do anything. -- variable (𝕜) /-- Expand the square -/ theorem norm_add_sq (x y : E) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by repeat' rw [sq (M := ℝ), ← @inner_self_eq_norm_mul_norm 𝕜] rw [inner_add_add_self, two_mul] simp only [add_assoc, add_left_inj, add_right_inj, AddMonoidHom.map_add] rw [← inner_conj_symm, conj_re] #align norm_add_sq norm_add_sq alias norm_add_pow_two := norm_add_sq #align norm_add_pow_two norm_add_pow_two /-- Expand the square -/ theorem norm_add_sq_real (x y : F) : ‖x + y‖ ^ 2 = ‖x‖ ^ 2 + 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := by have h := @norm_add_sq ℝ _ _ _ _ x y simpa using h #align norm_add_sq_real norm_add_sq_real alias norm_add_pow_two_real := norm_add_sq_real #align norm_add_pow_two_real norm_add_pow_two_real /-- Expand the square -/ theorem norm_add_mul_self (x y : E) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by repeat' rw [← sq (M := ℝ)] exact norm_add_sq _ _ #align norm_add_mul_self norm_add_mul_self /-- Expand the square -/ theorem norm_add_mul_self_real (x y : F) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by have h := @norm_add_mul_self ℝ _ _ _ _ x y simpa using h #align norm_add_mul_self_real norm_add_mul_self_real /-- Expand the square -/ theorem norm_sub_sq (x y : E) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * re ⟪x, y⟫ + ‖y‖ ^ 2 := by rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg, sub_eq_add_neg] #align norm_sub_sq norm_sub_sq alias norm_sub_pow_two := norm_sub_sq #align norm_sub_pow_two norm_sub_pow_two /-- Expand the square -/ theorem norm_sub_sq_real (x y : F) : ‖x - y‖ ^ 2 = ‖x‖ ^ 2 - 2 * ⟪x, y⟫_ℝ + ‖y‖ ^ 2 := @norm_sub_sq ℝ _ _ _ _ _ _ #align norm_sub_sq_real norm_sub_sq_real alias norm_sub_pow_two_real := norm_sub_sq_real #align norm_sub_pow_two_real norm_sub_pow_two_real /-- Expand the square -/ theorem norm_sub_mul_self (x y : E) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ := by repeat' rw [← sq (M := ℝ)] exact norm_sub_sq _ _ #align norm_sub_mul_self norm_sub_mul_self /-- Expand the square -/ theorem norm_sub_mul_self_real (x y : F) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ := by have h := @norm_sub_mul_self ℝ _ _ _ _ x y simpa using h #align norm_sub_mul_self_real norm_sub_mul_self_real /-- Cauchy–Schwarz inequality with norm -/ theorem norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := by rw [norm_eq_sqrt_inner (𝕜 := 𝕜) x, norm_eq_sqrt_inner (𝕜 := 𝕜) y] letI : InnerProductSpace.Core 𝕜 E := InnerProductSpace.toCore exact InnerProductSpace.Core.norm_inner_le_norm x y #align norm_inner_le_norm norm_inner_le_norm theorem nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ := norm_inner_le_norm x y #align nnnorm_inner_le_nnnorm nnnorm_inner_le_nnnorm theorem re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y) #align re_inner_le_norm re_inner_le_norm /-- Cauchy–Schwarz inequality with norm -/ theorem abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ := (Real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y) #align abs_real_inner_le_norm abs_real_inner_le_norm /-- Cauchy–Schwarz inequality with norm -/ theorem real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ := le_trans (le_abs_self _) (abs_real_inner_le_norm _ _) #align real_inner_le_norm real_inner_le_norm variable (𝕜) theorem parallelogram_law_with_norm (x y : E) : ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) := by simp only [← @inner_self_eq_norm_mul_norm 𝕜] rw [← re.map_add, parallelogram_law, two_mul, two_mul] simp only [re.map_add] #align parallelogram_law_with_norm parallelogram_law_with_norm theorem parallelogram_law_with_nnnorm (x y : E) : ‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) := Subtype.ext <| parallelogram_law_with_norm 𝕜 x y #align parallelogram_law_with_nnnorm parallelogram_law_with_nnnorm variable {𝕜} /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) : re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := by rw [@norm_add_mul_self 𝕜] ring #align re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) : re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := by rw [@norm_sub_mul_self 𝕜] ring #align re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two /-- Polarization identity: The real part of the inner product, in terms of the norm. -/ theorem re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) : re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 := by rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜] ring #align re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four /-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/ theorem im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four (x y : E) : im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 := by simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re] ring set_option linter.uppercaseLean3 false in #align im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four /-- Polarization identity: The inner product, in terms of the norm. -/ theorem inner_eq_sum_norm_sq_div_four (x y : E) : ⟪x, y⟫ = ((‖x + y‖ : 𝕜) ^ 2 - (‖x - y‖ : 𝕜) ^ 2 + ((‖x - IK • y‖ : 𝕜) ^ 2 - (‖x + IK • y‖ : 𝕜) ^ 2) * IK) / 4 := by rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four, im_inner_eq_norm_sub_i_smul_mul_self_sub_norm_add_i_smul_mul_self_div_four] push_cast simp only [sq, ← mul_div_right_comm, ← add_div] #align inner_eq_sum_norm_sq_div_four inner_eq_sum_norm_sq_div_four /-- Formula for the distance between the images of two nonzero points under an inversion with center zero. See also `EuclideanGeometry.dist_inversion_inversion` for inversions around a general point. -/ theorem dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) : dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := have hx' : ‖x‖ ≠ 0 := norm_ne_zero_iff.2 hx have hy' : ‖y‖ ≠ 0 := norm_ne_zero_iff.2 hy calc dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = √(‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖ ^ 2) := by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)] _ = √((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) := congr_arg sqrt <| by field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left, inner_smul_right, Real.norm_of_nonneg (mul_self_nonneg _)] ring _ = R ^ 2 / (‖x‖ * ‖y‖) * dist x y := by rw [sqrt_mul, sqrt_sq, sqrt_sq, dist_eq_norm] <;> positivity #align dist_div_norm_sq_smul dist_div_norm_sq_smul -- See note [lower instance priority] instance (priority := 100) InnerProductSpace.toUniformConvexSpace : UniformConvexSpace F := ⟨fun ε hε => by refine ⟨2 - √(4 - ε ^ 2), sub_pos_of_lt <| (sqrt_lt' zero_lt_two).2 ?_, fun x hx y hy hxy => ?_⟩ · norm_num exact pow_pos hε _ rw [sub_sub_cancel] refine le_sqrt_of_sq_le ?_ rw [sq, eq_sub_iff_add_eq.2 (parallelogram_law_with_norm ℝ x y), ← sq ‖x - y‖, hx, hy] ring_nf exact sub_le_sub_left (pow_le_pow_left hε.le hxy _) 4⟩ #align inner_product_space.to_uniform_convex_space InnerProductSpace.toUniformConvexSpace section Complex variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℂ V] /-- A complex polarization identity, with a linear map -/ theorem inner_map_polarization (T : V →ₗ[ℂ] V) (x y : V) : ⟪T y, x⟫_ℂ = (⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ + Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ - Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) / 4 := by simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left, inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right, mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub] ring #align inner_map_polarization inner_map_polarization theorem inner_map_polarization' (T : V →ₗ[ℂ] V) (x y : V) : ⟪T x, y⟫_ℂ = (⟪T (x + y), x + y⟫_ℂ - ⟪T (x - y), x - y⟫_ℂ - Complex.I * ⟪T (x + Complex.I • y), x + Complex.I • y⟫_ℂ + Complex.I * ⟪T (x - Complex.I • y), x - Complex.I • y⟫_ℂ) / 4 := by simp only [map_add, map_sub, inner_add_left, inner_add_right, LinearMap.map_smul, inner_smul_left, inner_smul_right, Complex.conj_I, ← pow_two, Complex.I_sq, inner_sub_left, inner_sub_right, mul_add, ← mul_assoc, mul_neg, neg_neg, sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub] ring #align inner_map_polarization' inner_map_polarization' /-- A linear map `T` is zero, if and only if the identity `⟪T x, x⟫_ℂ = 0` holds for all `x`. -/ theorem inner_map_self_eq_zero (T : V →ₗ[ℂ] V) : (∀ x : V, ⟪T x, x⟫_ℂ = 0) ↔ T = 0 := by constructor · intro hT ext x rw [LinearMap.zero_apply, ← @inner_self_eq_zero ℂ V, inner_map_polarization] simp only [hT] norm_num · rintro rfl x simp only [LinearMap.zero_apply, inner_zero_left] #align inner_map_self_eq_zero inner_map_self_eq_zero /-- Two linear maps `S` and `T` are equal, if and only if the identity `⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ` holds for all `x`. -/ theorem ext_inner_map (S T : V →ₗ[ℂ] V) : (∀ x : V, ⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ) ↔ S = T := by rw [← sub_eq_zero, ← inner_map_self_eq_zero] refine forall_congr' fun x => ?_ rw [LinearMap.sub_apply, inner_sub_left, sub_eq_zero] #align ext_inner_map ext_inner_map end Complex section variable {ι : Type*} {ι' : Type*} {ι'' : Type*} variable {E' : Type*} [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] variable {E'' : Type*} [NormedAddCommGroup E''] [InnerProductSpace 𝕜 E''] /-- A linear isometry preserves the inner product. -/ @[simp] theorem LinearIsometry.inner_map_map (f : E →ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ := by simp [inner_eq_sum_norm_sq_div_four, ← f.norm_map] #align linear_isometry.inner_map_map LinearIsometry.inner_map_map /-- A linear isometric equivalence preserves the inner product. -/ @[simp] theorem LinearIsometryEquiv.inner_map_map (f : E ≃ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ := f.toLinearIsometry.inner_map_map x y #align linear_isometry_equiv.inner_map_map LinearIsometryEquiv.inner_map_map /-- The adjoint of a linear isometric equivalence is its inverse. -/ theorem LinearIsometryEquiv.inner_map_eq_flip (f : E ≃ₗᵢ[𝕜] E') (x : E) (y : E') : ⟪f x, y⟫_𝕜 = ⟪x, f.symm y⟫_𝕜 := by conv_lhs => rw [← f.apply_symm_apply y, f.inner_map_map] /-- A linear map that preserves the inner product is a linear isometry. -/ def LinearMap.isometryOfInner (f : E →ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E →ₗᵢ[𝕜] E' := ⟨f, fun x => by simp only [@norm_eq_sqrt_inner 𝕜, h]⟩ #align linear_map.isometry_of_inner LinearMap.isometryOfInner @[simp] theorem LinearMap.coe_isometryOfInner (f : E →ₗ[𝕜] E') (h) : ⇑(f.isometryOfInner h) = f := rfl #align linear_map.coe_isometry_of_inner LinearMap.coe_isometryOfInner @[simp] theorem LinearMap.isometryOfInner_toLinearMap (f : E →ₗ[𝕜] E') (h) : (f.isometryOfInner h).toLinearMap = f := rfl #align linear_map.isometry_of_inner_to_linear_map LinearMap.isometryOfInner_toLinearMap /-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/ def LinearEquiv.isometryOfInner (f : E ≃ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E ≃ₗᵢ[𝕜] E' := ⟨f, ((f : E →ₗ[𝕜] E').isometryOfInner h).norm_map⟩ #align linear_equiv.isometry_of_inner LinearEquiv.isometryOfInner @[simp] theorem LinearEquiv.coe_isometryOfInner (f : E ≃ₗ[𝕜] E') (h) : ⇑(f.isometryOfInner h) = f := rfl #align linear_equiv.coe_isometry_of_inner LinearEquiv.coe_isometryOfInner @[simp] theorem LinearEquiv.isometryOfInner_toLinearEquiv (f : E ≃ₗ[𝕜] E') (h) : (f.isometryOfInner h).toLinearEquiv = f := rfl #align linear_equiv.isometry_of_inner_to_linear_equiv LinearEquiv.isometryOfInner_toLinearEquiv /-- A linear map is an isometry if and it preserves the inner product. -/ theorem LinearMap.norm_map_iff_inner_map_map {F : Type*} [FunLike F E E'] [LinearMapClass F 𝕜 E E'] (f : F) : (∀ x, ‖f x‖ = ‖x‖) ↔ (∀ x y, ⟪f x, f y⟫_𝕜 = ⟪x, y⟫_𝕜) := ⟨({ toLinearMap := LinearMapClass.linearMap f, norm_map' := · : E →ₗᵢ[𝕜] E' }.inner_map_map), (LinearMapClass.linearMap f |>.isometryOfInner · |>.norm_map)⟩ /-- A linear isometry preserves the property of being orthonormal. -/ theorem LinearIsometry.orthonormal_comp_iff {v : ι → E} (f : E →ₗᵢ[𝕜] E') : Orthonormal 𝕜 (f ∘ v) ↔ Orthonormal 𝕜 v := by classical simp_rw [orthonormal_iff_ite, Function.comp_apply, LinearIsometry.inner_map_map] #align linear_isometry.orthonormal_comp_iff LinearIsometry.orthonormal_comp_iff /-- A linear isometry preserves the property of being orthonormal. -/ theorem Orthonormal.comp_linearIsometry {v : ι → E} (hv : Orthonormal 𝕜 v) (f : E →ₗᵢ[𝕜] E') : Orthonormal 𝕜 (f ∘ v) := by rwa [f.orthonormal_comp_iff] #align orthonormal.comp_linear_isometry Orthonormal.comp_linearIsometry /-- A linear isometric equivalence preserves the property of being orthonormal. -/ theorem Orthonormal.comp_linearIsometryEquiv {v : ι → E} (hv : Orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') : Orthonormal 𝕜 (f ∘ v) := hv.comp_linearIsometry f.toLinearIsometry #align orthonormal.comp_linear_isometry_equiv Orthonormal.comp_linearIsometryEquiv /-- A linear isometric equivalence, applied with `Basis.map`, preserves the property of being orthonormal. -/ theorem Orthonormal.mapLinearIsometryEquiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') : Orthonormal 𝕜 (v.map f.toLinearEquiv) := hv.comp_linearIsometryEquiv f #align orthonormal.map_linear_isometry_equiv Orthonormal.mapLinearIsometryEquiv /-- A linear map that sends an orthonormal basis to orthonormal vectors is a linear isometry. -/ def LinearMap.isometryOfOrthonormal (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : E →ₗᵢ[𝕜] E' := f.isometryOfInner fun x y => by classical rw [← v.total_repr x, ← v.total_repr y, Finsupp.apply_total, Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] #align linear_map.isometry_of_orthonormal LinearMap.isometryOfOrthonormal @[simp] theorem LinearMap.coe_isometryOfOrthonormal (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : ⇑(f.isometryOfOrthonormal hv hf) = f := rfl #align linear_map.coe_isometry_of_orthonormal LinearMap.coe_isometryOfOrthonormal @[simp] theorem LinearMap.isometryOfOrthonormal_toLinearMap (f : E →ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : (f.isometryOfOrthonormal hv hf).toLinearMap = f := rfl #align linear_map.isometry_of_orthonormal_to_linear_map LinearMap.isometryOfOrthonormal_toLinearMap /-- A linear equivalence that sends an orthonormal basis to orthonormal vectors is a linear isometric equivalence. -/ def LinearEquiv.isometryOfOrthonormal (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : E ≃ₗᵢ[𝕜] E' := f.isometryOfInner fun x y => by rw [← LinearEquiv.coe_coe] at hf classical rw [← v.total_repr x, ← v.total_repr y, ← LinearEquiv.coe_coe f, Finsupp.apply_total, Finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left] #align linear_equiv.isometry_of_orthonormal LinearEquiv.isometryOfOrthonormal @[simp] theorem LinearEquiv.coe_isometryOfOrthonormal (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : ⇑(f.isometryOfOrthonormal hv hf) = f := rfl #align linear_equiv.coe_isometry_of_orthonormal LinearEquiv.coe_isometryOfOrthonormal @[simp] theorem LinearEquiv.isometryOfOrthonormal_toLinearEquiv (f : E ≃ₗ[𝕜] E') {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) (hf : Orthonormal 𝕜 (f ∘ v)) : (f.isometryOfOrthonormal hv hf).toLinearEquiv = f := rfl #align linear_equiv.isometry_of_orthonormal_to_linear_equiv LinearEquiv.isometryOfOrthonormal_toLinearEquiv /-- A linear isometric equivalence that sends an orthonormal basis to a given orthonormal basis. -/ def Orthonormal.equiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : E ≃ₗᵢ[𝕜] E' := (v.equiv v' e).isometryOfOrthonormal hv (by have h : v.equiv v' e ∘ v = v' ∘ e := by ext i simp rw [h] classical exact hv'.comp _ e.injective) #align orthonormal.equiv Orthonormal.equiv @[simp] theorem Orthonormal.equiv_toLinearEquiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.equiv hv' e).toLinearEquiv = v.equiv v' e := rfl #align orthonormal.equiv_to_linear_equiv Orthonormal.equiv_toLinearEquiv @[simp] theorem Orthonormal.equiv_apply {ι' : Type*} {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') (i : ι) : hv.equiv hv' e (v i) = v' (e i) := Basis.equiv_apply _ _ _ _ #align orthonormal.equiv_apply Orthonormal.equiv_apply @[simp] theorem Orthonormal.equiv_refl {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) : hv.equiv hv (Equiv.refl ι) = LinearIsometryEquiv.refl 𝕜 E := v.ext_linearIsometryEquiv fun i => by simp only [Orthonormal.equiv_apply, Equiv.coe_refl, id, LinearIsometryEquiv.coe_refl] #align orthonormal.equiv_refl Orthonormal.equiv_refl @[simp] theorem Orthonormal.equiv_symm {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.equiv hv' e).symm = hv'.equiv hv e.symm := v'.ext_linearIsometryEquiv fun i => (hv.equiv hv' e).injective <| by simp only [LinearIsometryEquiv.apply_symm_apply, Orthonormal.equiv_apply, e.apply_symm_apply] #align orthonormal.equiv_symm Orthonormal.equiv_symm @[simp] theorem Orthonormal.equiv_trans {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') {v'' : Basis ι'' 𝕜 E''} (hv'' : Orthonormal 𝕜 v'') (e' : ι' ≃ ι'') : (hv.equiv hv' e).trans (hv'.equiv hv'' e') = hv.equiv hv'' (e.trans e') := v.ext_linearIsometryEquiv fun i => by simp only [LinearIsometryEquiv.trans_apply, Orthonormal.equiv_apply, e.coe_trans, Function.comp_apply] #align orthonormal.equiv_trans Orthonormal.equiv_trans theorem Orthonormal.map_equiv {v : Basis ι 𝕜 E} (hv : Orthonormal 𝕜 v) {v' : Basis ι' 𝕜 E'} (hv' : Orthonormal 𝕜 v') (e : ι ≃ ι') : v.map (hv.equiv hv' e).toLinearEquiv = v'.reindex e.symm := v.map_equiv _ _ #align orthonormal.map_equiv Orthonormal.map_equiv end /-- Polarization identity: The real inner product, in terms of the norm. -/ theorem real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) : ⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 := re_to_real.symm.trans <| re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y #align real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two /-- Polarization identity: The real inner product, in terms of the norm. -/ theorem real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) : ⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 := re_to_real.symm.trans <| re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y #align real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two /-- Pythagorean theorem, if-and-only-if vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_right_eq_self, mul_eq_zero] norm_num #align norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero /-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/ theorem norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} : ‖x + y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by rw [← norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)] #align norm_add_eq_sqrt_iff_real_inner_eq_zero norm_add_eq_sqrt_iff_real_inner_eq_zero /-- Pythagorean theorem, vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := by rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_right_eq_self, mul_eq_zero] apply Or.inr simp only [h, zero_re'] #align norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero /-- Pythagorean theorem, vector inner product form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h #align norm_add_sq_eq_norm_sq_add_norm_sq_real norm_add_sq_eq_norm_sq_add_norm_sq_real /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector inner product form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 := by rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero, mul_eq_zero] norm_num #align norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero /-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square roots. -/ theorem norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} : ‖x - y‖ = √(‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 := by rw [← norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm, sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)] #align norm_sub_eq_sqrt_iff_real_inner_eq_zero norm_sub_eq_sqrt_iff_real_inner_eq_zero /-- Pythagorean theorem, subtracting vectors, vector inner product form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h #align norm_sub_sq_eq_norm_sq_add_norm_sq_real norm_sub_sq_eq_norm_sq_add_norm_sq_real /-- The sum and difference of two vectors are orthogonal if and only if they have the same norm. -/ theorem real_inner_add_sub_eq_zero_iff (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ := by conv_rhs => rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] simp only [← @inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right, real_inner_comm y x, sub_eq_zero, re_to_real] constructor · intro h rw [add_comm] at h linarith · intro h linarith #align real_inner_add_sub_eq_zero_iff real_inner_add_sub_eq_zero_iff /-- Given two orthogonal vectors, their sum and difference have equal norms. -/
Mathlib/Analysis/InnerProductSpace/Basic.lean
1,515
1,519
theorem norm_sub_eq_norm_add {v w : E} (h : ⟪v, w⟫ = 0) : ‖w - v‖ = ‖w + v‖ := by
rw [← mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _)] simp only [h, ← @inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re', zero_sub, add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm, zero_add]