Context
stringlengths
295
65.3k
file_name
stringlengths
21
74
start
int64
14
1.41k
end
int64
20
1.41k
theorem
stringlengths
27
1.42k
proof
stringlengths
0
4.57k
/- 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.Logic.Equiv.PartialEquiv import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.Sets.Opens /-! # Partial homeomorphisms This file defines homeomorphisms between open subsets of topological spaces. An element `e` of `PartialHomeomorph X Y` is an extension of `PartialEquiv X Y`, i.e., it is a pair of functions `e.toFun` and `e.invFun`, inverse of each other on the sets `e.source` and `e.target`. Additionally, we require that these sets are open, and that the functions are continuous on them. Equivalently, they are homeomorphisms there. As in equivs, we register a coercion to functions, and we use `e x` and `e.symm x` throughout instead of `e.toFun x` and `e.invFun x`. ## Main definitions * `Homeomorph.toPartialHomeomorph`: associating a partial homeomorphism to a homeomorphism, with `source = target = Set.univ`; * `PartialHomeomorph.symm`: the inverse of a partial homeomorphism * `PartialHomeomorph.trans`: the composition of two partial homeomorphisms * `PartialHomeomorph.refl`: the identity partial homeomorphism * `PartialHomeomorph.const`: a partial homeomorphism which is a constant map, whose source and target are necessarily singleton sets * `PartialHomeomorph.ofSet`: the identity on a set `s` * `PartialHomeomorph.restr s`: restrict a partial homeomorphism `e` to `e.source ∩ interior s` * `PartialHomeomorph.EqOnSource`: equivalence relation describing the "right" notion of equality for partial homeomorphisms * `PartialHomeomorph.prod`: the product of two partial homeomorphisms, as a partial homeomorphism on the product space * `PartialHomeomorph.pi`: the product of a finite family of partial homeomorphisms * `PartialHomeomorph.disjointUnion`: combine two partial homeomorphisms with disjoint sources and disjoint targets * `PartialHomeomorph.lift_openEmbedding`: extend a partial homeomorphism `X β†’ Y` under an open embedding `X β†’ X'`, to a partial homeomorphism `X' β†’ Z`. (This is used to define the disjoint union of charted spaces.) ## Implementation notes Most statements are copied from their `PartialEquiv` versions, although some care is required especially when restricting to subsets, as these should be open subsets. For design notes, see `PartialEquiv.lean`. ### Local coding conventions If a lemma deals with the intersection of a set with either source or target of a `PartialEquiv`, then it should use `e.source ∩ s` or `e.target ∩ t`, not `s ∩ e.source` or `t ∩ e.target`. -/ open Function Set Filter Topology variable {X X' : Type*} {Y Y' : Type*} {Z Z' : Type*} [TopologicalSpace X] [TopologicalSpace X'] [TopologicalSpace Y] [TopologicalSpace Y'] [TopologicalSpace Z] [TopologicalSpace Z'] /-- Partial homeomorphisms, defined on open subsets of the space -/ structure PartialHomeomorph (X : Type*) (Y : Type*) [TopologicalSpace X] [TopologicalSpace Y] extends PartialEquiv X Y where open_source : IsOpen source open_target : IsOpen target continuousOn_toFun : ContinuousOn toFun source continuousOn_invFun : ContinuousOn invFun target namespace PartialHomeomorph variable (e : PartialHomeomorph X Y) /-! Basic properties; inverse (symm instance) -/ section Basic /-- Coercion of a partial homeomorphisms to a function. We don't use `e.toFun` 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' : X β†’ Y := e.toFun /-- Coercion of a `PartialHomeomorph` to function. Note that a `PartialHomeomorph` is not `DFunLike`. -/ instance : CoeFun (PartialHomeomorph X Y) fun _ => X β†’ Y := ⟨fun e => e.toFun'⟩ /-- The inverse of a partial homeomorphism -/ @[symm] protected def symm : PartialHomeomorph Y X where toPartialEquiv := e.toPartialEquiv.symm open_source := e.open_target open_target := e.open_source continuousOn_toFun := e.continuousOn_invFun continuousOn_invFun := e.continuousOn_toFun /-- See Note [custom simps projection]. We need to specify this projection explicitly in this case, because it is a composition of multiple projections. -/ def Simps.apply (e : PartialHomeomorph X Y) : X β†’ Y := e /-- See Note [custom simps projection] -/ def Simps.symm_apply (e : PartialHomeomorph X Y) : Y β†’ X := e.symm initialize_simps_projections PartialHomeomorph (toFun β†’ apply, invFun β†’ symm_apply) protected theorem continuousOn : ContinuousOn e e.source := e.continuousOn_toFun theorem continuousOn_symm : ContinuousOn e.symm e.target := e.continuousOn_invFun @[simp, mfld_simps] theorem mk_coe (e : PartialEquiv X Y) (a b c d) : (PartialHomeomorph.mk e a b c d : X β†’ Y) = e := rfl @[simp, mfld_simps] theorem mk_coe_symm (e : PartialEquiv X Y) (a b c d) : ((PartialHomeomorph.mk e a b c d).symm : Y β†’ X) = e.symm := rfl theorem toPartialEquiv_injective : Injective (toPartialEquiv : PartialHomeomorph X Y β†’ PartialEquiv X Y) | ⟨_, _, _, _, _⟩, ⟨_, _, _, _, _⟩, rfl => rfl /- Register a few simp lemmas to make sure that `simp` puts the application of a local homeomorphism in its normal form, i.e., in terms of its coercion to a function. -/ @[simp, mfld_simps] theorem toFun_eq_coe (e : PartialHomeomorph X Y) : e.toFun = e := rfl @[simp, mfld_simps] theorem invFun_eq_coe (e : PartialHomeomorph X Y) : e.invFun = e.symm := rfl @[simp, mfld_simps] theorem coe_coe : (e.toPartialEquiv : X β†’ Y) = e := rfl @[simp, mfld_simps] theorem coe_coe_symm : (e.toPartialEquiv.symm : Y β†’ X) = e.symm := rfl @[simp, mfld_simps] theorem map_source {x : X} (h : x ∈ e.source) : e x ∈ e.target := e.map_source' h /-- Variant of `map_source`, stated for images of subsets of `source`. -/ lemma map_source'' : e '' e.source βŠ† e.target := fun _ ⟨_, hx, hex⟩ ↦ mem_of_eq_of_mem (id hex.symm) (e.map_source' hx) @[simp, mfld_simps] theorem map_target {x : Y} (h : x ∈ e.target) : e.symm x ∈ e.source := e.map_target' h @[simp, mfld_simps] theorem left_inv {x : X} (h : x ∈ e.source) : e.symm (e x) = x := e.left_inv' h @[simp, mfld_simps] theorem right_inv {x : Y} (h : x ∈ e.target) : e (e.symm x) = x := e.right_inv' h theorem eq_symm_apply {x : X} {y : Y} (hx : x ∈ e.source) (hy : y ∈ e.target) : x = e.symm y ↔ e x = y := e.toPartialEquiv.eq_symm_apply hx hy protected theorem mapsTo : MapsTo e e.source e.target := fun _ => e.map_source protected theorem symm_mapsTo : MapsTo e.symm e.target e.source := e.symm.mapsTo protected theorem leftInvOn : LeftInvOn e.symm e e.source := fun _ => e.left_inv protected theorem rightInvOn : RightInvOn e.symm e e.target := fun _ => e.right_inv protected theorem invOn : InvOn e.symm e e.source e.target := ⟨e.leftInvOn, e.rightInvOn⟩ protected theorem injOn : InjOn e e.source := e.leftInvOn.injOn protected theorem bijOn : BijOn e e.source e.target := e.invOn.bijOn e.mapsTo e.symm_mapsTo protected theorem surjOn : SurjOn e e.source e.target := e.bijOn.surjOn end Basic /-- Interpret a `Homeomorph` as a `PartialHomeomorph` by restricting it to an open set `s` in the domain and to `t` in the codomain. -/ @[simps! -fullyApplied apply symm_apply toPartialEquiv, simps! -isSimp source target] def _root_.Homeomorph.toPartialHomeomorphOfImageEq (e : X β‰ƒβ‚œ Y) (s : Set X) (hs : IsOpen s) (t : Set Y) (h : e '' s = t) : PartialHomeomorph X Y where toPartialEquiv := e.toPartialEquivOfImageEq s t h open_source := hs open_target := by simpa [← h] continuousOn_toFun := e.continuous.continuousOn continuousOn_invFun := e.symm.continuous.continuousOn /-- A homeomorphism induces a partial homeomorphism on the whole space -/ @[simps! (config := mfld_cfg)] def _root_.Homeomorph.toPartialHomeomorph (e : X β‰ƒβ‚œ Y) : PartialHomeomorph X Y := e.toPartialHomeomorphOfImageEq univ isOpen_univ univ <| by rw [image_univ, e.surjective.range_eq] /-- Replace `toPartialEquiv` field to provide better definitional equalities. -/ def replaceEquiv (e : PartialHomeomorph X Y) (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : PartialHomeomorph X Y where toPartialEquiv := e' open_source := h β–Έ e.open_source open_target := h β–Έ e.open_target continuousOn_toFun := h β–Έ e.continuousOn_toFun continuousOn_invFun := h β–Έ e.continuousOn_invFun theorem replaceEquiv_eq_self (e' : PartialEquiv X Y) (h : e.toPartialEquiv = e') : e.replaceEquiv e' h = e := by cases e subst e' rfl theorem source_preimage_target : e.source βŠ† e ⁻¹' e.target := e.mapsTo theorem eventually_left_inverse {x} (hx : x ∈ e.source) : βˆ€αΆ  y in 𝓝 x, e.symm (e y) = y := (e.open_source.eventually_mem hx).mono e.left_inv' theorem eventually_left_inverse' {x} (hx : x ∈ e.target) : βˆ€αΆ  y in 𝓝 (e.symm x), e.symm (e y) = y := e.eventually_left_inverse (e.map_target hx) theorem eventually_right_inverse {x} (hx : x ∈ e.target) : βˆ€αΆ  y in 𝓝 x, e (e.symm y) = y := (e.open_target.eventually_mem hx).mono e.right_inv' theorem eventually_right_inverse' {x} (hx : x ∈ e.source) : βˆ€αΆ  y in 𝓝 (e x), e (e.symm y) = y := e.eventually_right_inverse (e.map_source hx) theorem eventually_ne_nhdsWithin {x} (hx : x ∈ e.source) : βˆ€αΆ  x' in 𝓝[β‰ ] x, e x' β‰  e x := eventually_nhdsWithin_iff.2 <| (e.eventually_left_inverse hx).mono fun x' hx' => mt fun h => by rw [mem_singleton_iff, ← e.left_inv hx, ← h, hx'] theorem nhdsWithin_source_inter {x} (hx : x ∈ e.source) (s : Set X) : 𝓝[e.source ∩ s] x = 𝓝[s] x := nhdsWithin_inter_of_mem (mem_nhdsWithin_of_mem_nhds <| IsOpen.mem_nhds e.open_source hx) theorem nhdsWithin_target_inter {x} (hx : x ∈ e.target) (s : Set Y) : 𝓝[e.target ∩ s] x = 𝓝[s] x := e.symm.nhdsWithin_source_inter hx s theorem image_eq_target_inter_inv_preimage {s : Set X} (h : s βŠ† e.source) : e '' s = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_eq_target_inter_inv_preimage h theorem image_source_inter_eq' (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' s := e.toPartialEquiv.image_source_inter_eq' s theorem image_source_inter_eq (s : Set X) : e '' (e.source ∩ s) = e.target ∩ e.symm ⁻¹' (e.source ∩ s) := e.toPartialEquiv.image_source_inter_eq s theorem symm_image_eq_source_inter_preimage {s : Set Y} (h : s βŠ† e.target) : e.symm '' s = e.source ∩ e ⁻¹' s := e.symm.image_eq_target_inter_inv_preimage h theorem symm_image_target_inter_eq (s : Set Y) : e.symm '' (e.target ∩ s) = e.source ∩ e ⁻¹' (e.target ∩ s) := e.symm.image_source_inter_eq _ theorem source_inter_preimage_inv_preimage (s : Set X) : e.source ∩ e ⁻¹' (e.symm ⁻¹' s) = e.source ∩ s := e.toPartialEquiv.source_inter_preimage_inv_preimage s theorem target_inter_inv_preimage_preimage (s : Set Y) : e.target ∩ e.symm ⁻¹' (e ⁻¹' s) = e.target ∩ s := e.symm.source_inter_preimage_inv_preimage _ theorem source_inter_preimage_target_inter (s : Set Y) : e.source ∩ e ⁻¹' (e.target ∩ s) = e.source ∩ e ⁻¹' s := e.toPartialEquiv.source_inter_preimage_target_inter s theorem image_source_eq_target : e '' e.source = e.target := e.toPartialEquiv.image_source_eq_target theorem symm_image_target_eq_source : e.symm '' e.target = e.source := e.symm.image_source_eq_target /-- Two partial homeomorphisms are equal when they have equal `toFun`, `invFun` and `source`. It is not sufficient to have equal `toFun` and `source`, as this only determines `invFun` on the target. This would only be true for a weaker notion of equality, arguably the right one, called `EqOnSource`. -/ @[ext] protected theorem ext (e' : PartialHomeomorph X Y) (h : βˆ€ x, e x = e' x) (hinv : βˆ€ x, e.symm x = e'.symm x) (hs : e.source = e'.source) : e = e' := toPartialEquiv_injective (PartialEquiv.ext h hinv hs) @[simp, mfld_simps] theorem symm_toPartialEquiv : e.symm.toPartialEquiv = e.toPartialEquiv.symm := rfl -- The following lemmas are already simp via `PartialEquiv` theorem symm_source : e.symm.source = e.target := rfl theorem symm_target : e.symm.target = e.source := rfl @[simp, mfld_simps] theorem symm_symm : e.symm.symm = e := rfl theorem symm_bijective : Function.Bijective (PartialHomeomorph.symm : PartialHomeomorph X Y β†’ PartialHomeomorph Y X) := Function.bijective_iff_has_inverse.mpr ⟨_, symm_symm, symm_symm⟩ /-- A partial homeomorphism is continuous at any point of its source -/ protected theorem continuousAt {x : X} (h : x ∈ e.source) : ContinuousAt e x := (e.continuousOn x h).continuousAt (e.open_source.mem_nhds h) /-- A partial homeomorphism inverse is continuous at any point of its target -/ theorem continuousAt_symm {x : Y} (h : x ∈ e.target) : ContinuousAt e.symm x := e.symm.continuousAt h theorem tendsto_symm {x} (hx : x ∈ e.source) : Tendsto e.symm (𝓝 (e x)) (𝓝 x) := by simpa only [ContinuousAt, e.left_inv hx] using e.continuousAt_symm (e.map_source hx) theorem map_nhds_eq {x} (hx : x ∈ e.source) : map e (𝓝 x) = 𝓝 (e x) := le_antisymm (e.continuousAt hx) <| le_map_of_right_inverse (e.eventually_right_inverse' hx) (e.tendsto_symm hx) theorem symm_map_nhds_eq {x} (hx : x ∈ e.source) : map e.symm (𝓝 (e x)) = 𝓝 x := (e.symm.map_nhds_eq <| e.map_source hx).trans <| by rw [e.left_inv hx] theorem image_mem_nhds {x} (hx : x ∈ e.source) {s : Set X} (hs : s ∈ 𝓝 x) : e '' s ∈ 𝓝 (e x) := e.map_nhds_eq hx β–Έ Filter.image_mem_map hs theorem map_nhdsWithin_eq {x} (hx : x ∈ e.source) (s : Set X) : map e (𝓝[s] x) = 𝓝[e '' (e.source ∩ s)] e x := calc map e (𝓝[s] x) = map e (𝓝[e.source ∩ s] x) := congr_arg (map e) (e.nhdsWithin_source_inter hx _).symm _ = 𝓝[e '' (e.source ∩ s)] e x := (e.leftInvOn.mono inter_subset_left).map_nhdsWithin_eq (e.left_inv hx) (e.continuousAt_symm (e.map_source hx)).continuousWithinAt (e.continuousAt hx).continuousWithinAt theorem map_nhdsWithin_preimage_eq {x} (hx : x ∈ e.source) (s : Set Y) : map e (𝓝[e ⁻¹' s] x) = 𝓝[s] e x := by rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.target_inter_inv_preimage_preimage, e.nhdsWithin_target_inter (e.map_source hx)] theorem eventually_nhds {x : X} (p : Y β†’ Prop) (hx : x ∈ e.source) : (βˆ€αΆ  y in 𝓝 (e x), p y) ↔ βˆ€αΆ  x in 𝓝 x, p (e x) := Iff.trans (by rw [e.map_nhds_eq hx]) eventually_map theorem eventually_nhds' {x : X} (p : X β†’ Prop) (hx : x ∈ e.source) : (βˆ€αΆ  y in 𝓝 (e x), p (e.symm y)) ↔ βˆ€αΆ  x in 𝓝 x, p x := by rw [e.eventually_nhds _ hx] refine eventually_congr ((e.eventually_left_inverse hx).mono fun y hy => ?_) rw [hy] theorem eventually_nhdsWithin {x : X} (p : Y β†’ Prop) {s : Set X} (hx : x ∈ e.source) : (βˆ€αΆ  y in 𝓝[e.symm ⁻¹' s] e x, p y) ↔ βˆ€αΆ  x in 𝓝[s] x, p (e x) := by refine Iff.trans ?_ eventually_map rw [e.map_nhdsWithin_eq hx, e.image_source_inter_eq', e.nhdsWithin_target_inter (e.mapsTo hx)] theorem eventually_nhdsWithin' {x : X} (p : X β†’ Prop) {s : Set X} (hx : x ∈ e.source) : (βˆ€αΆ  y in 𝓝[e.symm ⁻¹' s] e x, p (e.symm y)) ↔ βˆ€αΆ  x in 𝓝[s] x, p x := by rw [e.eventually_nhdsWithin _ hx] refine eventually_congr <| (eventually_nhdsWithin_of_eventually_nhds <| e.eventually_left_inverse hx).mono fun y hy => ?_ rw [hy] /-- This lemma is useful in the manifold library in the case that `e` is a chart. It states that locally around `e x` the set `e.symm ⁻¹' s` is the same as the set intersected with the target of `e` and some other neighborhood of `f x` (which will be the source of a chart on `Z`). -/ theorem preimage_eventuallyEq_target_inter_preimage_inter {e : PartialHomeomorph X Y} {s : Set X} {t : Set Z} {x : X} {f : X β†’ Z} (hf : ContinuousWithinAt f s x) (hxe : x ∈ e.source) (ht : t ∈ 𝓝 (f x)) : e.symm ⁻¹' s =αΆ [𝓝 (e x)] (e.target ∩ e.symm ⁻¹' (s ∩ f ⁻¹' t) : Set Y) := by rw [eventuallyEq_set, e.eventually_nhds _ hxe] filter_upwards [e.open_source.mem_nhds hxe, mem_nhdsWithin_iff_eventually.mp (hf.preimage_mem_nhdsWithin ht)] intro y hy hyu simp_rw [mem_inter_iff, mem_preimage, mem_inter_iff, e.mapsTo hy, true_and, iff_self_and, e.left_inv hy, iff_true_intro hyu] theorem isOpen_inter_preimage {s : Set Y} (hs : IsOpen s) : IsOpen (e.source ∩ e ⁻¹' s) := e.continuousOn.isOpen_inter_preimage e.open_source hs theorem isOpen_inter_preimage_symm {s : Set X} (hs : IsOpen s) : IsOpen (e.target ∩ e.symm ⁻¹' s) := e.symm.continuousOn.isOpen_inter_preimage e.open_target hs /-- A partial homeomorphism is an open map on its source: the image of an open subset of the source is open. -/ lemma isOpen_image_of_subset_source {s : Set X} (hs : IsOpen s) (hse : s βŠ† e.source) : IsOpen (e '' s) := by rw [(image_eq_target_inter_inv_preimage (e := e) hse)] exact e.continuousOn_invFun.isOpen_inter_preimage e.open_target hs /-- The image of the restriction of an open set to the source is open. -/ theorem isOpen_image_source_inter {s : Set X} (hs : IsOpen s) : IsOpen (e '' (e.source ∩ s)) := e.isOpen_image_of_subset_source (e.open_source.inter hs) inter_subset_left /-- The inverse of a partial homeomorphism `e` is an open map on `e.target`. -/ lemma isOpen_image_symm_of_subset_target {t : Set Y} (ht : IsOpen t) (hte : t βŠ† e.target) : IsOpen (e.symm '' t) := isOpen_image_of_subset_source e.symm ht (e.symm_source β–Έ hte) lemma isOpen_symm_image_iff_of_subset_target {t : Set Y} (hs : t βŠ† e.target) : IsOpen (e.symm '' t) ↔ IsOpen t := by refine ⟨fun h ↦ ?_, fun h ↦ e.symm.isOpen_image_of_subset_source h hs⟩ have hs' : e.symm '' t βŠ† e.source := by rw [e.symm_image_eq_source_inter_preimage hs] apply Set.inter_subset_left rw [← e.image_symm_image_of_subset_target hs] exact e.isOpen_image_of_subset_source h hs' theorem isOpen_image_iff_of_subset_source {s : Set X} (hs : s βŠ† e.source) : IsOpen (e '' s) ↔ IsOpen s := by rw [← e.symm.isOpen_symm_image_iff_of_subset_target hs, e.symm_symm] section IsImage /-! ### `PartialHomeomorph.IsImage` relation We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `βˆ€ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). This definition is a restatement of `PartialEquiv.IsImage` for partial homeomorphisms. In this section we transfer API about `PartialEquiv.IsImage` to partial homeomorphisms and add a few `PartialHomeomorph`-specific lemmas like `PartialHomeomorph.IsImage.closure`. -/ /-- We say that `t : Set Y` is an image of `s : Set X` under a partial homeomorphism `e` if any of the following equivalent conditions hold: * `e '' (e.source ∩ s) = e.target ∩ t`; * `e.source ∩ e ⁻¹ t = e.source ∩ s`; * `βˆ€ x ∈ e.source, e x ∈ t ↔ x ∈ s` (this one is used in the definition). -/ def IsImage (s : Set X) (t : Set Y) : Prop := βˆ€ ⦃x⦄, x ∈ e.source β†’ (e x ∈ t ↔ x ∈ s) namespace IsImage variable {e} {s : Set X} {t : Set Y} {x : X} {y : Y} theorem toPartialEquiv (h : e.IsImage s t) : e.toPartialEquiv.IsImage s t := h theorem apply_mem_iff (h : e.IsImage s t) (hx : x ∈ e.source) : e x ∈ t ↔ x ∈ s := h hx protected theorem symm (h : e.IsImage s t) : e.symm.IsImage t s := h.toPartialEquiv.symm theorem symm_apply_mem_iff (h : e.IsImage s t) (hy : y ∈ e.target) : e.symm y ∈ s ↔ y ∈ t := h.symm hy @[simp] theorem symm_iff : e.symm.IsImage t s ↔ e.IsImage s t := ⟨fun h => h.symm, fun h => h.symm⟩ protected theorem mapsTo (h : e.IsImage s t) : MapsTo e (e.source ∩ s) (e.target ∩ t) := h.toPartialEquiv.mapsTo theorem symm_mapsTo (h : e.IsImage s t) : MapsTo e.symm (e.target ∩ t) (e.source ∩ s) := h.symm.mapsTo theorem image_eq (h : e.IsImage s t) : e '' (e.source ∩ s) = e.target ∩ t := h.toPartialEquiv.image_eq theorem symm_image_eq (h : e.IsImage s t) : e.symm '' (e.target ∩ t) = e.source ∩ s := h.symm.image_eq theorem iff_preimage_eq : e.IsImage s t ↔ e.source ∩ e ⁻¹' t = e.source ∩ s := PartialEquiv.IsImage.iff_preimage_eq alias ⟨preimage_eq, of_preimage_eq⟩ := iff_preimage_eq theorem iff_symm_preimage_eq : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' s = e.target ∩ t := symm_iff.symm.trans iff_preimage_eq alias ⟨symm_preimage_eq, of_symm_preimage_eq⟩ := iff_symm_preimage_eq
Mathlib/Topology/PartialHomeomorph.lean
492
494
theorem iff_symm_preimage_eq' : e.IsImage s t ↔ e.target ∩ e.symm ⁻¹' (e.source ∩ s) = e.target ∩ t := by
rw [iff_symm_preimage_eq, ← image_source_inter_eq, ← image_source_inter_eq']
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Kim Morrison, Bhavik Mehta, Jakob von Raumer -/ import Mathlib.CategoryTheory.EqToHom import Mathlib.CategoryTheory.Functor.Trifunctor import Mathlib.CategoryTheory.Products.Basic /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensorObj : C β†’ C β†’ C` * `tensorHom : (X₁ ⟢ Y₁) β†’ (Xβ‚‚ ⟢ Yβ‚‚) β†’ ((X₁ βŠ— Xβ‚‚) ⟢ (Y₁ βŠ— Yβ‚‚))` and allow use of the overloaded notation `βŠ—` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C Γ— C β₯€ C`. The unitors and associator are gathered together as natural isomorphisms in `leftUnitor_nat_iso`, `rightUnitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files after proving the coherence theorem, e.g. `(Ξ»_ (πŸ™_ C)).hom = (ρ_ (πŸ™_ C)).hom` in `CategoryTheory.Monoidal.CoherenceLemmas`. ## Implementation notes In the definition of monoidal categories, we also provide the whiskering operators: * `whiskerLeft (X : C) {Y₁ Yβ‚‚ : C} (f : Y₁ ⟢ Yβ‚‚) : X βŠ— Y₁ ⟢ X βŠ— Yβ‚‚`, denoted by `X ◁ f`, * `whiskerRight {X₁ Xβ‚‚ : C} (f : X₁ ⟢ Xβ‚‚) (Y : C) : X₁ βŠ— Y ⟢ Xβ‚‚ βŠ— Y`, denoted by `f β–· Y`. These are products of an object and a morphism (the terminology "whiskering" is borrowed from 2-category theory). The tensor product of morphisms `tensorHom` can be defined in terms of the whiskerings. There are two possible such definitions, which are related by the exchange property of the whiskerings. These two definitions are accessed by `tensorHom_def` and `tensorHom_def'`. By default, `tensorHom` is defined so that `tensorHom_def` holds definitionally. If you want to provide `tensorHom` and define `whiskerLeft` and `whiskerRight` in terms of it, you can use the alternative constructor `CategoryTheory.MonoidalCategory.ofTensorHom`. The whiskerings are useful when considering simp-normal forms of morphisms in monoidal categories. ### Simp-normal form for morphisms Rewriting involving associators and unitors could be very complicated. We try to ease this complexity by putting carefully chosen simp lemmas that rewrite any morphisms into the simp-normal form defined below. Rewriting into simp-normal form is especially useful in preprocessing performed by the `coherence` tactic. The simp-normal form of morphisms is defined to be an expression that has the minimal number of parentheses. More precisely, 1. it is a composition of morphisms like `f₁ ≫ fβ‚‚ ≫ f₃ ≫ fβ‚„ ≫ fβ‚…` such that each `fα΅’` is either a structural morphisms (morphisms made up only of identities, associators, unitors) or non-structural morphisms, and 2. each non-structural morphism in the composition is of the form `X₁ ◁ Xβ‚‚ ◁ X₃ ◁ f β–· Xβ‚„ β–· Xβ‚…`, where each `Xα΅’` is a object that is not the identity or a tensor and `f` is a non-structural morphisms that is not the identity or a composite. Note that `X₁ ◁ Xβ‚‚ ◁ X₃ ◁ f β–· Xβ‚„ β–· Xβ‚…` is actually `X₁ ◁ (Xβ‚‚ ◁ (X₃ ◁ ((f β–· Xβ‚„) β–· Xβ‚…)))`. Currently, the simp lemmas don't rewrite `πŸ™ X βŠ— f` and `f βŠ— πŸ™ Y` into `X ◁ f` and `f β–· Y`, respectively, since it requires a huge refactoring. We hope to add these simp lemmas soon. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ universe v u open CategoryTheory.Category open CategoryTheory.Iso namespace CategoryTheory /-- Auxiliary structure to carry only the data fields of (and provide notation for) `MonoidalCategory`. -/ class MonoidalCategoryStruct (C : Type u) [π’ž : Category.{v} C] where /-- curried tensor product of objects -/ tensorObj : C β†’ C β†’ C /-- left whiskering for morphisms -/ whiskerLeft (X : C) {Y₁ Yβ‚‚ : C} (f : Y₁ ⟢ Yβ‚‚) : tensorObj X Y₁ ⟢ tensorObj X Yβ‚‚ /-- right whiskering for morphisms -/ whiskerRight {X₁ Xβ‚‚ : C} (f : X₁ ⟢ Xβ‚‚) (Y : C) : tensorObj X₁ Y ⟢ tensorObj Xβ‚‚ Y /-- Tensor product of identity maps is the identity: `(πŸ™ X₁ βŠ— πŸ™ Xβ‚‚) = πŸ™ (X₁ βŠ— Xβ‚‚)` -/ -- By default, it is defined in terms of whiskerings. tensorHom {X₁ Y₁ Xβ‚‚ Yβ‚‚ : C} (f : X₁ ⟢ Y₁) (g : Xβ‚‚ ⟢ Yβ‚‚) : (tensorObj X₁ Xβ‚‚ ⟢ tensorObj Y₁ Yβ‚‚) := whiskerRight f Xβ‚‚ ≫ whiskerLeft Y₁ g /-- The tensor unity in the monoidal structure `πŸ™_ C` -/ tensorUnit (C) : C /-- The associator isomorphism `(X βŠ— Y) βŠ— Z ≃ X βŠ— (Y βŠ— Z)` -/ associator : βˆ€ X Y Z : C, tensorObj (tensorObj X Y) Z β‰… tensorObj X (tensorObj Y Z) /-- The left unitor: `πŸ™_ C βŠ— X ≃ X` -/ leftUnitor : βˆ€ X : C, tensorObj tensorUnit X β‰… X /-- The right unitor: `X βŠ— πŸ™_ C ≃ X` -/ rightUnitor : βˆ€ X : C, tensorObj X tensorUnit β‰… X namespace MonoidalCategory export MonoidalCategoryStruct (tensorObj whiskerLeft whiskerRight tensorHom tensorUnit associator leftUnitor rightUnitor) end MonoidalCategory namespace MonoidalCategory /-- Notation for `tensorObj`, the tensor product of objects in a monoidal category -/ scoped infixr:70 " βŠ— " => MonoidalCategoryStruct.tensorObj /-- Notation for the `whiskerLeft` operator of monoidal categories -/ scoped infixr:81 " ◁ " => MonoidalCategoryStruct.whiskerLeft /-- Notation for the `whiskerRight` operator of monoidal categories -/ scoped infixl:81 " β–· " => MonoidalCategoryStruct.whiskerRight /-- Notation for `tensorHom`, the tensor product of morphisms in a monoidal category -/ scoped infixr:70 " βŠ— " => MonoidalCategoryStruct.tensorHom /-- Notation for `tensorUnit`, the two-sided identity of `βŠ—` -/ scoped notation "πŸ™_ " C:arg => MonoidalCategoryStruct.tensorUnit C /-- Notation for the monoidal `associator`: `(X βŠ— Y) βŠ— Z ≃ X βŠ— (Y βŠ— Z)` -/ scoped notation "Ξ±_" => MonoidalCategoryStruct.associator /-- Notation for the `leftUnitor`: `πŸ™_C βŠ— X ≃ X` -/ scoped notation "Ξ»_" => MonoidalCategoryStruct.leftUnitor /-- Notation for the `rightUnitor`: `X βŠ— πŸ™_C ≃ X` -/ scoped notation "ρ_" => MonoidalCategoryStruct.rightUnitor /-- The property that the pentagon relation is satisfied by four objects in a category equipped with a `MonoidalCategoryStruct`. -/ def Pentagon {C : Type u} [Category.{v} C] [MonoidalCategoryStruct C] (Y₁ Yβ‚‚ Y₃ Yβ‚„ : C) : Prop := (Ξ±_ Y₁ Yβ‚‚ Y₃).hom β–· Yβ‚„ ≫ (Ξ±_ Y₁ (Yβ‚‚ βŠ— Y₃) Yβ‚„).hom ≫ Y₁ ◁ (Ξ±_ Yβ‚‚ Y₃ Yβ‚„).hom = (Ξ±_ (Y₁ βŠ— Yβ‚‚) Y₃ Yβ‚„).hom ≫ (Ξ±_ Y₁ Yβ‚‚ (Y₃ βŠ— Yβ‚„)).hom end MonoidalCategory open MonoidalCategory /-- In a monoidal category, we can take the tensor product of objects, `X βŠ— Y` and of morphisms `f βŠ— g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `Ξ±_ X Y Z : (X βŠ— Y) βŠ— Z β‰… X βŠ— (Y βŠ— Z)`. There is a tensor unit `πŸ™_ C`, with specified left and right unitor isomorphisms `Ξ»_ X : πŸ™_ C βŠ— X β‰… X` and `ρ_ X : X βŠ— πŸ™_ C β‰… X`. These associators and unitors satisfy the pentagon and triangle equations. -/ @[stacks 0FFK] -- Porting note: The Mathport did not translate the temporary notation class MonoidalCategory (C : Type u) [π’ž : Category.{v} C] extends MonoidalCategoryStruct C where tensorHom_def {X₁ Y₁ Xβ‚‚ Yβ‚‚ : C} (f : X₁ ⟢ Y₁) (g : Xβ‚‚ ⟢ Yβ‚‚) : f βŠ— g = (f β–· Xβ‚‚) ≫ (Y₁ ◁ g) := by aesop_cat /-- Tensor product of identity maps is the identity: `(πŸ™ X₁ βŠ— πŸ™ Xβ‚‚) = πŸ™ (X₁ βŠ— Xβ‚‚)` -/ tensor_id : βˆ€ X₁ Xβ‚‚ : C, πŸ™ X₁ βŠ— πŸ™ Xβ‚‚ = πŸ™ (X₁ βŠ— Xβ‚‚) := by aesop_cat /-- Tensor product of compositions is composition of tensor products: `(f₁ ≫ g₁) βŠ— (fβ‚‚ ≫ gβ‚‚) = (f₁ βŠ— fβ‚‚) ≫ (g₁ βŠ— gβ‚‚)` -/ tensor_comp : βˆ€ {X₁ Y₁ Z₁ Xβ‚‚ Yβ‚‚ Zβ‚‚ : C} (f₁ : X₁ ⟢ Y₁) (fβ‚‚ : Xβ‚‚ ⟢ Yβ‚‚) (g₁ : Y₁ ⟢ Z₁) (gβ‚‚ : Yβ‚‚ ⟢ Zβ‚‚), (f₁ ≫ g₁) βŠ— (fβ‚‚ ≫ gβ‚‚) = (f₁ βŠ— fβ‚‚) ≫ (g₁ βŠ— gβ‚‚) := by aesop_cat whiskerLeft_id : βˆ€ (X Y : C), X ◁ πŸ™ Y = πŸ™ (X βŠ— Y) := by aesop_cat id_whiskerRight : βˆ€ (X Y : C), πŸ™ X β–· Y = πŸ™ (X βŠ— Y) := by aesop_cat /-- Naturality of the associator isomorphism: `(f₁ βŠ— fβ‚‚) βŠ— f₃ ≃ f₁ βŠ— (fβ‚‚ βŠ— f₃)` -/ associator_naturality : βˆ€ {X₁ Xβ‚‚ X₃ Y₁ Yβ‚‚ Y₃ : C} (f₁ : X₁ ⟢ Y₁) (fβ‚‚ : Xβ‚‚ ⟢ Yβ‚‚) (f₃ : X₃ ⟢ Y₃), ((f₁ βŠ— fβ‚‚) βŠ— f₃) ≫ (Ξ±_ Y₁ Yβ‚‚ Y₃).hom = (Ξ±_ X₁ Xβ‚‚ X₃).hom ≫ (f₁ βŠ— (fβ‚‚ βŠ— f₃)) := by aesop_cat /-- Naturality of the left unitor, commutativity of `πŸ™_ C βŠ— X ⟢ πŸ™_ C βŠ— Y ⟢ Y` and `πŸ™_ C βŠ— X ⟢ X ⟢ Y` -/ leftUnitor_naturality : βˆ€ {X Y : C} (f : X ⟢ Y), πŸ™_ _ ◁ f ≫ (Ξ»_ Y).hom = (Ξ»_ X).hom ≫ f := by aesop_cat /-- Naturality of the right unitor: commutativity of `X βŠ— πŸ™_ C ⟢ Y βŠ— πŸ™_ C ⟢ Y` and `X βŠ— πŸ™_ C ⟢ X ⟢ Y` -/ rightUnitor_naturality : βˆ€ {X Y : C} (f : X ⟢ Y), f β–· πŸ™_ _ ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f := by aesop_cat /-- The pentagon identity relating the isomorphism between `X βŠ— (Y βŠ— (Z βŠ— W))` and `((X βŠ— Y) βŠ— Z) βŠ— W` -/ pentagon : βˆ€ W X Y Z : C, (Ξ±_ W X Y).hom β–· Z ≫ (Ξ±_ W (X βŠ— Y) Z).hom ≫ W ◁ (Ξ±_ X Y Z).hom = (Ξ±_ (W βŠ— X) Y Z).hom ≫ (Ξ±_ W X (Y βŠ— Z)).hom := by aesop_cat /-- The identity relating the isomorphisms between `X βŠ— (πŸ™_ C βŠ— Y)`, `(X βŠ— πŸ™_ C) βŠ— Y` and `X βŠ— Y` -/ triangle : βˆ€ X Y : C, (Ξ±_ X (πŸ™_ _) Y).hom ≫ X ◁ (Ξ»_ Y).hom = (ρ_ X).hom β–· Y := by aesop_cat attribute [reassoc] MonoidalCategory.tensorHom_def attribute [reassoc, simp] MonoidalCategory.whiskerLeft_id attribute [reassoc, simp] MonoidalCategory.id_whiskerRight attribute [reassoc] MonoidalCategory.tensor_comp attribute [simp] MonoidalCategory.tensor_comp attribute [reassoc] MonoidalCategory.associator_naturality attribute [reassoc] MonoidalCategory.leftUnitor_naturality attribute [reassoc] MonoidalCategory.rightUnitor_naturality attribute [reassoc (attr := simp)] MonoidalCategory.pentagon attribute [reassoc (attr := simp)] MonoidalCategory.triangle namespace MonoidalCategory variable {C : Type u} [π’ž : Category.{v} C] [MonoidalCategory C] @[simp] theorem id_tensorHom (X : C) {Y₁ Yβ‚‚ : C} (f : Y₁ ⟢ Yβ‚‚) : πŸ™ X βŠ— f = X ◁ f := by simp [tensorHom_def] @[simp] theorem tensorHom_id {X₁ Xβ‚‚ : C} (f : X₁ ⟢ Xβ‚‚) (Y : C) : f βŠ— πŸ™ Y = f β–· Y := by simp [tensorHom_def] @[reassoc, simp] theorem whiskerLeft_comp (W : C) {X Y Z : C} (f : X ⟢ Y) (g : Y ⟢ Z) : W ◁ (f ≫ g) = W ◁ f ≫ W ◁ g := by simp only [← id_tensorHom, ← tensor_comp, comp_id] @[reassoc, simp] theorem id_whiskerLeft {X Y : C} (f : X ⟢ Y) : πŸ™_ C ◁ f = (Ξ»_ X).hom ≫ f ≫ (Ξ»_ Y).inv := by rw [← assoc, ← leftUnitor_naturality]; simp [id_tensorHom] @[reassoc, simp] theorem tensor_whiskerLeft (X Y : C) {Z Z' : C} (f : Z ⟢ Z') : (X βŠ— Y) ◁ f = (Ξ±_ X Y Z).hom ≫ X ◁ Y ◁ f ≫ (Ξ±_ X Y Z').inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc, simp] theorem comp_whiskerRight {W X Y : C} (f : W ⟢ X) (g : X ⟢ Y) (Z : C) : (f ≫ g) β–· Z = f β–· Z ≫ g β–· Z := by simp only [← tensorHom_id, ← tensor_comp, id_comp] @[reassoc, simp] theorem whiskerRight_id {X Y : C} (f : X ⟢ Y) : f β–· πŸ™_ C = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [← assoc, ← rightUnitor_naturality]; simp [tensorHom_id] @[reassoc, simp] theorem whiskerRight_tensor {X X' : C} (f : X ⟢ X') (Y Z : C) : f β–· (Y βŠ— Z) = (Ξ±_ X Y Z).inv ≫ f β–· Y β–· Z ≫ (Ξ±_ X' Y Z).hom := by simp only [← id_tensorHom, ← tensorHom_id] rw [associator_naturality] simp [tensor_id] @[reassoc, simp] theorem whisker_assoc (X : C) {Y Y' : C} (f : Y ⟢ Y') (Z : C) : (X ◁ f) β–· Z = (Ξ±_ X Y Z).hom ≫ X ◁ f β–· Z ≫ (Ξ±_ X Y' Z).inv := by simp only [← id_tensorHom, ← tensorHom_id] rw [← assoc, ← associator_naturality] simp @[reassoc] theorem whisker_exchange {W X Y Z : C} (f : W ⟢ X) (g : Y ⟢ Z) : W ◁ g ≫ f β–· Z = f β–· Y ≫ X ◁ g := by simp only [← id_tensorHom, ← tensorHom_id, ← tensor_comp, id_comp, comp_id] @[reassoc] theorem tensorHom_def' {X₁ Y₁ Xβ‚‚ Yβ‚‚ : C} (f : X₁ ⟢ Y₁) (g : Xβ‚‚ ⟢ Yβ‚‚) : f βŠ— g = X₁ ◁ g ≫ f β–· Yβ‚‚ := whisker_exchange f g β–Έ tensorHom_def f g @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv (X : C) {Y Z : C} (f : Y β‰… Z) : X ◁ f.hom ≫ X ◁ f.inv = πŸ™ (X βŠ— Y) := by rw [← whiskerLeft_comp, hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight {X Y : C} (f : X β‰… Y) (Z : C) : f.hom β–· Z ≫ f.inv β–· Z = πŸ™ (X βŠ— Z) := by rw [← comp_whiskerRight, hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom (X : C) {Y Z : C} (f : Y β‰… Z) : X ◁ f.inv ≫ X ◁ f.hom = πŸ™ (X βŠ— Z) := by rw [← whiskerLeft_comp, inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight {X Y : C} (f : X β‰… Y) (Z : C) : f.inv β–· Z ≫ f.hom β–· Z = πŸ™ (Y βŠ— Z) := by rw [← comp_whiskerRight, inv_hom_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_hom_inv' (X : C) {Y Z : C} (f : Y ⟢ Z) [IsIso f] : X ◁ f ≫ X ◁ inv f = πŸ™ (X βŠ— Y) := by rw [← whiskerLeft_comp, IsIso.hom_inv_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem hom_inv_whiskerRight' {X Y : C} (f : X ⟢ Y) [IsIso f] (Z : C) : f β–· Z ≫ inv f β–· Z = πŸ™ (X βŠ— Z) := by rw [← comp_whiskerRight, IsIso.hom_inv_id, id_whiskerRight] @[reassoc (attr := simp)] theorem whiskerLeft_inv_hom' (X : C) {Y Z : C} (f : Y ⟢ Z) [IsIso f] : X ◁ inv f ≫ X ◁ f = πŸ™ (X βŠ— Z) := by rw [← whiskerLeft_comp, IsIso.inv_hom_id, whiskerLeft_id] @[reassoc (attr := simp)] theorem inv_hom_whiskerRight' {X Y : C} (f : X ⟢ Y) [IsIso f] (Z : C) : inv f β–· Z ≫ f β–· Z = πŸ™ (Y βŠ— Z) := by rw [← comp_whiskerRight, IsIso.inv_hom_id, id_whiskerRight] /-- The left whiskering of an isomorphism is an isomorphism. -/ @[simps] def whiskerLeftIso (X : C) {Y Z : C} (f : Y β‰… Z) : X βŠ— Y β‰… X βŠ— Z where hom := X ◁ f.hom inv := X ◁ f.inv instance whiskerLeft_isIso (X : C) {Y Z : C} (f : Y ⟢ Z) [IsIso f] : IsIso (X ◁ f) := (whiskerLeftIso X (asIso f)).isIso_hom @[simp] theorem inv_whiskerLeft (X : C) {Y Z : C} (f : Y ⟢ Z) [IsIso f] : inv (X ◁ f) = X ◁ inv f := by aesop_cat @[simp] lemma whiskerLeftIso_refl (W X : C) : whiskerLeftIso W (Iso.refl X) = Iso.refl (W βŠ— X) := Iso.ext (whiskerLeft_id W X) @[simp] lemma whiskerLeftIso_trans (W : C) {X Y Z : C} (f : X β‰… Y) (g : Y β‰… Z) : whiskerLeftIso W (f β‰ͺ≫ g) = whiskerLeftIso W f β‰ͺ≫ whiskerLeftIso W g := Iso.ext (whiskerLeft_comp W f.hom g.hom) @[simp] lemma whiskerLeftIso_symm (W : C) {X Y : C} (f : X β‰… Y) : (whiskerLeftIso W f).symm = whiskerLeftIso W f.symm := rfl /-- The right whiskering of an isomorphism is an isomorphism. -/ @[simps!] def whiskerRightIso {X Y : C} (f : X β‰… Y) (Z : C) : X βŠ— Z β‰… Y βŠ— Z where hom := f.hom β–· Z inv := f.inv β–· Z instance whiskerRight_isIso {X Y : C} (f : X ⟢ Y) (Z : C) [IsIso f] : IsIso (f β–· Z) := (whiskerRightIso (asIso f) Z).isIso_hom @[simp] theorem inv_whiskerRight {X Y : C} (f : X ⟢ Y) (Z : C) [IsIso f] : inv (f β–· Z) = inv f β–· Z := by aesop_cat @[simp] lemma whiskerRightIso_refl (X W : C) : whiskerRightIso (Iso.refl X) W = Iso.refl (X βŠ— W) := Iso.ext (id_whiskerRight X W) @[simp] lemma whiskerRightIso_trans {X Y Z : C} (f : X β‰… Y) (g : Y β‰… Z) (W : C) : whiskerRightIso (f β‰ͺ≫ g) W = whiskerRightIso f W β‰ͺ≫ whiskerRightIso g W := Iso.ext (comp_whiskerRight f.hom g.hom W) @[simp] lemma whiskerRightIso_symm {X Y : C} (f : X β‰… Y) (W : C) : (whiskerRightIso f W).symm = whiskerRightIso f.symm W := rfl /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensorIso {X Y X' Y' : C} (f : X β‰… Y) (g : X' β‰… Y') : X βŠ— X' β‰… Y βŠ— Y' where hom := f.hom βŠ— g.hom inv := f.inv βŠ— g.inv hom_inv_id := by rw [← tensor_comp, Iso.hom_inv_id, Iso.hom_inv_id, ← tensor_id] inv_hom_id := by rw [← tensor_comp, Iso.inv_hom_id, Iso.inv_hom_id, ← tensor_id] /-- Notation for `tensorIso`, the tensor product of isomorphisms -/ scoped infixr:70 " βŠ— " => tensorIso theorem tensorIso_def {X Y X' Y' : C} (f : X β‰… Y) (g : X' β‰… Y') : f βŠ— g = whiskerRightIso f X' β‰ͺ≫ whiskerLeftIso Y g := Iso.ext (tensorHom_def f.hom g.hom) theorem tensorIso_def' {X Y X' Y' : C} (f : X β‰… Y) (g : X' β‰… Y') : f βŠ— g = whiskerLeftIso X g β‰ͺ≫ whiskerRightIso f Y' := Iso.ext (tensorHom_def' f.hom g.hom) instance tensor_isIso {W X Y Z : C} (f : W ⟢ X) [IsIso f] (g : Y ⟢ Z) [IsIso g] : IsIso (f βŠ— g) := (asIso f βŠ— asIso g).isIso_hom @[simp] theorem inv_tensor {W X Y Z : C} (f : W ⟢ X) [IsIso f] (g : Y ⟢ Z) [IsIso g] : inv (f βŠ— g) = inv f βŠ— inv g := by simp [tensorHom_def ,whisker_exchange] variable {W X Y Z : C} theorem whiskerLeft_dite {P : Prop} [Decidable P] (X : C) {Y Z : C} (f : P β†’ (Y ⟢ Z)) (f' : Β¬P β†’ (Y ⟢ Z)) : X ◁ (if h : P then f h else f' h) = if h : P then X ◁ f h else X ◁ f' h := by split_ifs <;> rfl theorem dite_whiskerRight {P : Prop} [Decidable P] {X Y : C} (f : P β†’ (X ⟢ Y)) (f' : Β¬P β†’ (X ⟢ Y)) (Z : C) : (if h : P then f h else f' h) β–· Z = if h : P then f h β–· Z else f' h β–· Z := by split_ifs <;> rfl theorem tensor_dite {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟢ X) (g : P β†’ (Y ⟢ Z)) (g' : Β¬P β†’ (Y ⟢ Z)) : (f βŠ— if h : P then g h else g' h) = if h : P then f βŠ— g h else f βŠ— g' h := by split_ifs <;> rfl theorem dite_tensor {P : Prop} [Decidable P] {W X Y Z : C} (f : W ⟢ X) (g : P β†’ (Y ⟢ Z)) (g' : Β¬P β†’ (Y ⟢ Z)) : (if h : P then g h else g' h) βŠ— f = if h : P then g h βŠ— f else g' h βŠ— f := by split_ifs <;> rfl @[simp] theorem whiskerLeft_eqToHom (X : C) {Y Z : C} (f : Y = Z) : X ◁ eqToHom f = eqToHom (congr_argβ‚‚ tensorObj rfl f) := by cases f simp only [whiskerLeft_id, eqToHom_refl] @[simp] theorem eqToHom_whiskerRight {X Y : C} (f : X = Y) (Z : C) : eqToHom f β–· Z = eqToHom (congr_argβ‚‚ tensorObj f rfl) := by cases f simp only [id_whiskerRight, eqToHom_refl] @[reassoc] theorem associator_naturality_left {X X' : C} (f : X ⟢ X') (Y Z : C) : f β–· Y β–· Z ≫ (Ξ±_ X' Y Z).hom = (Ξ±_ X Y Z).hom ≫ f β–· (Y βŠ— Z) := by simp @[reassoc] theorem associator_inv_naturality_left {X X' : C} (f : X ⟢ X') (Y Z : C) : f β–· (Y βŠ— Z) ≫ (Ξ±_ X' Y Z).inv = (Ξ±_ X Y Z).inv ≫ f β–· Y β–· Z := by simp @[reassoc] theorem whiskerRight_tensor_symm {X X' : C} (f : X ⟢ X') (Y Z : C) : f β–· Y β–· Z = (Ξ±_ X Y Z).hom ≫ f β–· (Y βŠ— Z) ≫ (Ξ±_ X' Y Z).inv := by simp @[reassoc] theorem associator_naturality_middle (X : C) {Y Y' : C} (f : Y ⟢ Y') (Z : C) : (X ◁ f) β–· Z ≫ (Ξ±_ X Y' Z).hom = (Ξ±_ X Y Z).hom ≫ X ◁ f β–· Z := by simp @[reassoc] theorem associator_inv_naturality_middle (X : C) {Y Y' : C} (f : Y ⟢ Y') (Z : C) : X ◁ f β–· Z ≫ (Ξ±_ X Y' Z).inv = (Ξ±_ X Y Z).inv ≫ (X ◁ f) β–· Z := by simp @[reassoc] theorem whisker_assoc_symm (X : C) {Y Y' : C} (f : Y ⟢ Y') (Z : C) : X ◁ f β–· Z = (Ξ±_ X Y Z).inv ≫ (X ◁ f) β–· Z ≫ (Ξ±_ X Y' Z).hom := by simp @[reassoc] theorem associator_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟢ Z') : (X βŠ— Y) ◁ f ≫ (Ξ±_ X Y Z').hom = (Ξ±_ X Y Z).hom ≫ X ◁ Y ◁ f := by simp @[reassoc] theorem associator_inv_naturality_right (X Y : C) {Z Z' : C} (f : Z ⟢ Z') : X ◁ Y ◁ f ≫ (Ξ±_ X Y Z').inv = (Ξ±_ X Y Z).inv ≫ (X βŠ— Y) ◁ f := by simp @[reassoc] theorem tensor_whiskerLeft_symm (X Y : C) {Z Z' : C} (f : Z ⟢ Z') : X ◁ Y ◁ f = (Ξ±_ X Y Z).inv ≫ (X βŠ— Y) ◁ f ≫ (Ξ±_ X Y Z').hom := by simp @[reassoc] theorem leftUnitor_inv_naturality {X Y : C} (f : X ⟢ Y) : f ≫ (Ξ»_ Y).inv = (Ξ»_ X).inv ≫ _ ◁ f := by simp @[reassoc] theorem id_whiskerLeft_symm {X X' : C} (f : X ⟢ X') : f = (Ξ»_ X).inv ≫ πŸ™_ C ◁ f ≫ (Ξ»_ X').hom := by simp only [id_whiskerLeft, assoc, inv_hom_id, comp_id, inv_hom_id_assoc] @[reassoc] theorem rightUnitor_inv_naturality {X X' : C} (f : X ⟢ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ f β–· _ := by simp @[reassoc] theorem whiskerRight_id_symm {X Y : C} (f : X ⟢ Y) : f = (ρ_ X).inv ≫ f β–· πŸ™_ C ≫ (ρ_ Y).hom := by simp theorem whiskerLeft_iff {X Y : C} (f g : X ⟢ Y) : πŸ™_ C ◁ f = πŸ™_ C ◁ g ↔ f = g := by simp theorem whiskerRight_iff {X Y : C} (f g : X ⟢ Y) : f β–· πŸ™_ C = g β–· πŸ™_ C ↔ f = g := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc (attr := simp)] theorem pentagon_inv : W ◁ (Ξ±_ X Y Z).inv ≫ (Ξ±_ W (X βŠ— Y) Z).inv ≫ (Ξ±_ W X Y).inv β–· Z = (Ξ±_ W X (Y βŠ— Z)).inv ≫ (Ξ±_ (W βŠ— X) Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_inv_inv_hom_hom_inv : (Ξ±_ W (X βŠ— Y) Z).inv ≫ (Ξ±_ W X Y).inv β–· Z ≫ (Ξ±_ (W βŠ— X) Y Z).hom = W ◁ (Ξ±_ X Y Z).hom ≫ (Ξ±_ W X (Y βŠ— Z)).inv := by rw [← cancel_epi (W ◁ (Ξ±_ X Y Z).inv), ← cancel_mono (Ξ±_ (W βŠ— X) Y Z).inv] simp @[reassoc (attr := simp)] theorem pentagon_inv_hom_hom_hom_inv : (Ξ±_ (W βŠ— X) Y Z).inv ≫ (Ξ±_ W X Y).hom β–· Z ≫ (Ξ±_ W (X βŠ— Y) Z).hom = (Ξ±_ W X (Y βŠ— Z)).hom ≫ W ◁ (Ξ±_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_inv : W ◁ (Ξ±_ X Y Z).hom ≫ (Ξ±_ W X (Y βŠ— Z)).inv ≫ (Ξ±_ (W βŠ— X) Y Z).inv = (Ξ±_ W (X βŠ— Y) Z).inv ≫ (Ξ±_ W X Y).inv β–· Z := by simp [← cancel_epi (W ◁ (Ξ±_ X Y Z).inv)] @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_hom_hom : (Ξ±_ (W βŠ— X) Y Z).hom ≫ (Ξ±_ W X (Y βŠ— Z)).hom ≫ W ◁ (Ξ±_ X Y Z).inv = (Ξ±_ W X Y).hom β–· Z ≫ (Ξ±_ W (X βŠ— Y) Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem pentagon_hom_inv_inv_inv_hom : (Ξ±_ W X (Y βŠ— Z)).hom ≫ W ◁ (Ξ±_ X Y Z).inv ≫ (Ξ±_ W (X βŠ— Y) Z).inv = (Ξ±_ (W βŠ— X) Y Z).inv ≫ (Ξ±_ W X Y).hom β–· Z := by rw [← cancel_epi (Ξ±_ W X (Y βŠ— Z)).inv, ← cancel_mono ((Ξ±_ W X Y).inv β–· Z)] simp @[reassoc (attr := simp)] theorem pentagon_hom_hom_inv_inv_hom : (Ξ±_ W (X βŠ— Y) Z).hom ≫ W ◁ (Ξ±_ X Y Z).hom ≫ (Ξ±_ W X (Y βŠ— Z)).inv = (Ξ±_ W X Y).inv β–· Z ≫ (Ξ±_ (W βŠ— X) Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/Category.lean
543
546
theorem pentagon_inv_hom_hom_hom_hom : (Ξ±_ W X Y).inv β–· Z ≫ (Ξ±_ (W βŠ— X) Y Z).hom ≫ (Ξ±_ W X (Y βŠ— Z)).hom = (Ξ±_ W (X βŠ— Y) Z).hom ≫ W ◁ (Ξ±_ X Y Z).hom := by
simp [← cancel_epi ((Ξ±_ W X Y).hom β–· Z)]
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bryan Gin-ge Chen, YaΓ«l Dillies -/ import Mathlib.Order.BooleanAlgebra import Mathlib.Logic.Equiv.Basic /-! # Symmetric difference and bi-implication This file defines the symmetric difference and bi-implication operators in (co-)Heyting algebras. ## Examples Some examples are * The symmetric difference of two sets is the set of elements that are in either but not both. * The symmetric difference on propositions is `Xor'`. * The symmetric difference on `Bool` is `Bool.xor`. * The equivalence of propositions. Two propositions are equivalent if they imply each other. * The symmetric difference translates to addition when considering a Boolean algebra as a Boolean ring. ## Main declarations * `symmDiff`: The symmetric difference operator, defined as `(a \ b) βŠ” (b \ a)` * `bihimp`: The bi-implication operator, defined as `(b ⇨ a) βŠ“ (a ⇨ b)` In generalized Boolean algebras, the symmetric difference operator is: * `symmDiff_comm`: commutative, and * `symmDiff_assoc`: associative. ## Notations * `a βˆ† b`: `symmDiff a b` * `a ⇔ b`: `bihimp a b` ## References The proof of associativity follows the note "Associativity of the Symmetric Difference of Sets: A Proof from the Book" by John McCuan: * <https://people.math.gatech.edu/~mccuan/courses/4317/symmetricdifference.pdf> ## Tags boolean ring, generalized boolean algebra, boolean algebra, symmetric difference, bi-implication, Heyting -/ assert_not_exists RelIso open Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} {Ο€ : ΞΉ β†’ Type*} /-- The symmetric difference operator on a type with `βŠ”` and `\` is `(A \ B) βŠ” (B \ A)`. -/ def symmDiff [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : Ξ± := a \ b βŠ” b \ a /-- The Heyting bi-implication is `(b ⇨ a) βŠ“ (a ⇨ b)`. This generalizes equivalence of propositions. -/ def bihimp [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : Ξ± := (b ⇨ a) βŠ“ (a ⇨ b) /-- Notation for symmDiff -/ scoped[symmDiff] infixl:100 " βˆ† " => symmDiff /-- Notation for bihimp -/ scoped[symmDiff] infixl:100 " ⇔ " => bihimp open scoped symmDiff theorem symmDiff_def [Max Ξ±] [SDiff Ξ±] (a b : Ξ±) : a βˆ† b = a \ b βŠ” b \ a := rfl theorem bihimp_def [Min Ξ±] [HImp Ξ±] (a b : Ξ±) : a ⇔ b = (b ⇨ a) βŠ“ (a ⇨ b) := rfl theorem symmDiff_eq_Xor' (p q : Prop) : p βˆ† q = Xor' p q := rfl @[simp] theorem bihimp_iff_iff {p q : Prop} : p ⇔ q ↔ (p ↔ q) := iff_iff_implies_and_implies.symm.trans Iff.comm @[simp] theorem Bool.symmDiff_eq_xor : βˆ€ p q : Bool, p βˆ† q = xor p q := by decide section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra Ξ±] (a b c : Ξ±) @[simp] theorem toDual_symmDiff : toDual (a βˆ† b) = toDual a ⇔ toDual b := rfl @[simp] theorem ofDual_bihimp (a b : Ξ±α΅’α΅ˆ) : ofDual (a ⇔ b) = ofDual a βˆ† ofDual b := rfl theorem symmDiff_comm : a βˆ† b = b βˆ† a := by simp only [symmDiff, sup_comm] instance symmDiff_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· βˆ† Β·) := ⟨symmDiff_comm⟩ @[simp] theorem symmDiff_self : a βˆ† a = βŠ₯ := by rw [symmDiff, sup_idem, sdiff_self] @[simp] theorem symmDiff_bot : a βˆ† βŠ₯ = a := by rw [symmDiff, sdiff_bot, bot_sdiff, sup_bot_eq] @[simp] theorem bot_symmDiff : βŠ₯ βˆ† a = a := by rw [symmDiff_comm, symmDiff_bot] @[simp] theorem symmDiff_eq_bot {a b : Ξ±} : a βˆ† b = βŠ₯ ↔ a = b := by simp_rw [symmDiff, sup_eq_bot_iff, sdiff_eq_bot_iff, le_antisymm_iff] theorem symmDiff_of_le {a b : Ξ±} (h : a ≀ b) : a βˆ† b = b \ a := by rw [symmDiff, sdiff_eq_bot_iff.2 h, bot_sup_eq] theorem symmDiff_of_ge {a b : Ξ±} (h : b ≀ a) : a βˆ† b = a \ b := by rw [symmDiff, sdiff_eq_bot_iff.2 h, sup_bot_eq] theorem symmDiff_le {a b c : Ξ±} (ha : a ≀ b βŠ” c) (hb : b ≀ a βŠ” c) : a βˆ† b ≀ c := sup_le (sdiff_le_iff.2 ha) <| sdiff_le_iff.2 hb theorem symmDiff_le_iff {a b c : Ξ±} : a βˆ† b ≀ c ↔ a ≀ b βŠ” c ∧ b ≀ a βŠ” c := by simp_rw [symmDiff, sup_le_iff, sdiff_le_iff] @[simp] theorem symmDiff_le_sup {a b : Ξ±} : a βˆ† b ≀ a βŠ” b := sup_le_sup sdiff_le sdiff_le theorem symmDiff_eq_sup_sdiff_inf : a βˆ† b = (a βŠ” b) \ (a βŠ“ b) := by simp [sup_sdiff, symmDiff] theorem Disjoint.symmDiff_eq_sup {a b : Ξ±} (h : Disjoint a b) : a βˆ† b = a βŠ” b := by rw [symmDiff, h.sdiff_eq_left, h.sdiff_eq_right] theorem symmDiff_sdiff : a βˆ† b \ c = a \ (b βŠ” c) βŠ” b \ (a βŠ” c) := by rw [symmDiff, sup_sdiff_distrib, sdiff_sdiff_left, sdiff_sdiff_left] @[simp] theorem symmDiff_sdiff_inf : a βˆ† b \ (a βŠ“ b) = a βˆ† b := by rw [symmDiff_sdiff] simp [symmDiff] @[simp] theorem symmDiff_sdiff_eq_sup : a βˆ† (b \ a) = a βŠ” b := by rw [symmDiff, sdiff_idem] exact le_antisymm (sup_le_sup sdiff_le sdiff_le) (sup_le le_sdiff_sup <| le_sdiff_sup.trans <| sup_le le_sup_right le_sdiff_sup) @[simp] theorem sdiff_symmDiff_eq_sup : (a \ b) βˆ† b = a βŠ” b := by rw [symmDiff_comm, symmDiff_sdiff_eq_sup, sup_comm] @[simp] theorem symmDiff_sup_inf : a βˆ† b βŠ” a βŠ“ b = a βŠ” b := by refine le_antisymm (sup_le symmDiff_le_sup inf_le_sup) ?_ rw [sup_inf_left, symmDiff] refine sup_le (le_inf le_sup_right ?_) (le_inf ?_ le_sup_right) Β· rw [sup_right_comm] exact le_sup_of_le_left le_sdiff_sup Β· rw [sup_assoc] exact le_sup_of_le_right le_sdiff_sup @[simp] theorem inf_sup_symmDiff : a βŠ“ b βŠ” a βˆ† b = a βŠ” b := by rw [sup_comm, symmDiff_sup_inf] @[simp] theorem symmDiff_symmDiff_inf : a βˆ† b βˆ† (a βŠ“ b) = a βŠ” b := by rw [← symmDiff_sdiff_inf a, sdiff_symmDiff_eq_sup, symmDiff_sup_inf] @[simp] theorem inf_symmDiff_symmDiff : (a βŠ“ b) βˆ† (a βˆ† b) = a βŠ” b := by rw [symmDiff_comm, symmDiff_symmDiff_inf] theorem symmDiff_triangle : a βˆ† c ≀ a βˆ† b βŠ” b βˆ† c := by refine (sup_le_sup (sdiff_triangle a b c) <| sdiff_triangle _ b _).trans_eq ?_ rw [sup_comm (c \ b), sup_sup_sup_comm, symmDiff, symmDiff] theorem le_symmDiff_sup_right (a b : Ξ±) : a ≀ (a βˆ† b) βŠ” b := by convert symmDiff_triangle a b βŠ₯ <;> rw [symmDiff_bot] theorem le_symmDiff_sup_left (a b : Ξ±) : b ≀ (a βˆ† b) βŠ” a := symmDiff_comm a b β–Έ le_symmDiff_sup_right .. end GeneralizedCoheytingAlgebra section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra Ξ±] (a b c : Ξ±) @[simp] theorem toDual_bihimp : toDual (a ⇔ b) = toDual a βˆ† toDual b := rfl @[simp] theorem ofDual_symmDiff (a b : Ξ±α΅’α΅ˆ) : ofDual (a βˆ† b) = ofDual a ⇔ ofDual b := rfl theorem bihimp_comm : a ⇔ b = b ⇔ a := by simp only [(Β· ⇔ Β·), inf_comm] instance bihimp_isCommutative : Std.Commutative (Ξ± := Ξ±) (Β· ⇔ Β·) := ⟨bihimp_comm⟩ @[simp] theorem bihimp_self : a ⇔ a = ⊀ := by rw [bihimp, inf_idem, himp_self] @[simp] theorem bihimp_top : a ⇔ ⊀ = a := by rw [bihimp, himp_top, top_himp, inf_top_eq] @[simp]
Mathlib/Order/SymmDiff.lean
218
219
theorem top_bihimp : ⊀ ⇔ a = a := by
rw [bihimp_comm, bihimp_top]
/- Copyright (c) 2021 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Quaternion import Mathlib.Tactic.Ring /-! # Basis on a quaternion-like algebra ## Main definitions * `QuaternionAlgebra.Basis A c₁ cβ‚‚ c₃`: a basis for a subspace of an `R`-algebra `A` that has the same algebra structure as `ℍ[R,c₁,cβ‚‚,c₃]`. * `QuaternionAlgebra.Basis.self R`: the canonical basis for `ℍ[R,c₁,cβ‚‚,c₃]`. * `QuaternionAlgebra.Basis.compHom b f`: transform a basis `b` by an AlgHom `f`. * `QuaternionAlgebra.lift`: Define an `AlgHom` out of `ℍ[R,c₁,cβ‚‚,c₃]` by its action on the basis elements `i`, `j`, and `k`. In essence, this is a universal property. Analogous to `Complex.lift`, but takes a bundled `QuaternionAlgebra.Basis` instead of just a `Subtype` as the amount of data / proves is non-negligible. -/ open Quaternion namespace QuaternionAlgebra /-- A quaternion basis contains the information both sufficient and necessary to construct an `R`-algebra homomorphism from `ℍ[R,c₁,cβ‚‚,c₃]` to `A`; or equivalently, a surjective `R`-algebra homomorphism from `ℍ[R,c₁,cβ‚‚,c₃]` to an `R`-subalgebra of `A`. Note that for definitional convenience, `k` is provided as a field even though `i_mul_j` fully determines it. -/ structure Basis {R : Type*} (A : Type*) [CommRing R] [Ring A] [Algebra R A] (c₁ cβ‚‚ c₃ : R) where /-- The first imaginary unit -/ i : A /-- The second imaginary unit -/ j : A /-- The third imaginary unit -/ k : A i_mul_i : i * i = c₁ β€’ (1 : A) + cβ‚‚ β€’ i j_mul_j : j * j = c₃ β€’ (1 : A) i_mul_j : i * j = k j_mul_i : j * i = cβ‚‚ β€’ j - k variable {R : Type*} {A B : Type*} [CommRing R] [Ring A] [Ring B] [Algebra R A] [Algebra R B] variable {c₁ cβ‚‚ c₃ : R} namespace Basis /-- Since `k` is redundant, it is not necessary to show `q₁.k = qβ‚‚.k` when showing `q₁ = qβ‚‚`. -/ @[ext] protected theorem ext ⦃q₁ qβ‚‚ : Basis A c₁ cβ‚‚ c₃⦄ (hi : q₁.i = qβ‚‚.i) (hj : q₁.j = qβ‚‚.j) : q₁ = qβ‚‚ := by cases q₁; rename_i q₁_i_mul_j _ cases qβ‚‚; rename_i qβ‚‚_i_mul_j _ congr rw [← q₁_i_mul_j, ← qβ‚‚_i_mul_j] congr variable (R) in /-- There is a natural quaternionic basis for the `QuaternionAlgebra`. -/ @[simps i j k] protected def self : Basis ℍ[R,c₁,cβ‚‚,c₃] c₁ cβ‚‚ c₃ where i := ⟨0, 1, 0, 0⟩ i_mul_i := by ext <;> simp j := ⟨0, 0, 1, 0⟩ j_mul_j := by ext <;> simp k := ⟨0, 0, 0, 1⟩ i_mul_j := by ext <;> simp j_mul_i := by ext <;> simp instance : Inhabited (Basis ℍ[R,c₁,cβ‚‚,c₃] c₁ cβ‚‚ c₃) := ⟨Basis.self R⟩ variable (q : Basis A c₁ cβ‚‚ c₃) attribute [simp] i_mul_i j_mul_j i_mul_j j_mul_i @[simp] theorem i_mul_k : q.i * q.k = c₁ β€’ q.j + cβ‚‚ β€’ q.k := by rw [← i_mul_j, ← mul_assoc, i_mul_i, add_mul, smul_mul_assoc, one_mul, smul_mul_assoc] @[simp] theorem k_mul_i : q.k * q.i = -c₁ β€’ q.j := by rw [← i_mul_j, mul_assoc, j_mul_i, mul_sub, i_mul_k, neg_smul, mul_smul_comm, i_mul_j] linear_combination (norm := module) @[simp] theorem k_mul_j : q.k * q.j = c₃ β€’ q.i := by rw [← i_mul_j, mul_assoc, j_mul_j, mul_smul_comm, mul_one] @[simp] theorem j_mul_k : q.j * q.k = (cβ‚‚ * c₃) β€’ 1 - c₃ β€’ q.i := by rw [← i_mul_j, ← mul_assoc, j_mul_i, sub_mul, smul_mul_assoc, j_mul_j, ← smul_assoc, k_mul_j] rfl @[simp] theorem k_mul_k : q.k * q.k = -((c₁ * c₃) β€’ (1 : A)) := by rw [← i_mul_j, mul_assoc, ← mul_assoc q.j _ _, j_mul_i, ← i_mul_j, ← mul_assoc, mul_sub, ← mul_assoc, i_mul_i, add_mul, smul_mul_assoc, one_mul, sub_mul, smul_mul_assoc, mul_smul_comm, smul_mul_assoc, mul_assoc, j_mul_j, add_mul, smul_mul_assoc, j_mul_j, smul_smul, smul_mul_assoc, mul_assoc, j_mul_j] linear_combination (norm := module) /-- Intermediate result used to define `QuaternionAlgebra.Basis.liftHom`. -/ def lift (x : ℍ[R,c₁,cβ‚‚,c₃]) : A := algebraMap R _ x.re + x.imI β€’ q.i + x.imJ β€’ q.j + x.imK β€’ q.k theorem lift_zero : q.lift (0 : ℍ[R,c₁,cβ‚‚,c₃]) = 0 := by simp [lift]
Mathlib/Algebra/QuaternionBasis.lean
114
114
theorem lift_one : q.lift (1 : ℍ[R,c₁,cβ‚‚,c₃]) = 1 := by
simp [lift]
/- Copyright (c) 2021 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies, Eric Wieser -/ import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Algebra.Order.Module.Pointwise import Mathlib.Data.Real.Archimedean /-! # Pointwise operations on sets of reals This file relates `sInf (a β€’ s)`/`sSup (a β€’ s)` with `a β€’ sInf s`/`a β€’ sSup s` for `s : Set ℝ`. From these, it relates `β¨… i, a β€’ f i` / `⨆ i, a β€’ f i` with `a β€’ (β¨… i, f i)` / `a β€’ (⨆ i, f i)`, and provides lemmas about distributing `*` over `β¨…` and `⨆`. ## TODO This is true more generally for conditionally complete linear order whose default value is `0`. We don't have those yet. -/ assert_not_exists Finset open Set open Pointwise variable {ΞΉ : Sort*} {Ξ± : Type*} [Field Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] section MulActionWithZero variable [MulActionWithZero Ξ± ℝ] [OrderedSMul Ξ± ℝ] {a : Ξ±}
Mathlib/Data/Real/Pointwise.lean
37
46
theorem Real.sInf_smul_of_nonneg (ha : 0 ≀ a) (s : Set ℝ) : sInf (a β€’ s) = a β€’ sInf s := by
obtain rfl | hs := s.eq_empty_or_nonempty Β· rw [smul_set_empty, Real.sInf_empty, smul_zero] obtain rfl | ha' := ha.eq_or_lt Β· rw [zero_smul_set hs, zero_smul] exact csInf_singleton 0 by_cases h : BddBelow s Β· exact ((OrderIso.smulRight ha').map_csInf' hs h).symm Β· rw [Real.sInf_of_not_bddBelow (mt (bddBelow_smul_iff_of_pos ha').1 h), Real.sInf_of_not_bddBelow h, smul_zero]
/- Copyright (c) 2024 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.MeasureTheory.Integral.PeakFunction import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform /-! # Fourier inversion formula In a finite-dimensional real inner product space, we show the Fourier inversion formula, i.e., `𝓕⁻ (𝓕 f) v = f v` if `f` and `𝓕 f` are integrable, and `f` is continuous at `v`. This is proved in `MeasureTheory.Integrable.fourier_inversion`. See also `Continuous.fourier_inversion` giving `𝓕⁻ (𝓕 f) = f` under an additional continuity assumption for `f`. We use the following proof. A naΓ―ve computation gives `𝓕⁻ (𝓕 f) v = ∫_w exp (2 I Ο€ βŸͺw, v⟫) 𝓕 f (w) dw = ∫_w exp (2 I Ο€ βŸͺw, v⟫) ∫_x, exp (-2 I Ο€ βŸͺw, x⟫) f x dx) dw = ∫_x (∫_ w, exp (2 I Ο€ βŸͺw, v - x⟫ dw) f x dx ` However, the Fubini step does not make sense for lack of integrability, and the middle integral `∫_ w, exp (2 I Ο€ βŸͺw, v - x⟫ dw` (which one would like to be a Dirac at `v - x`) is not defined. To gain integrability, one multiplies with a Gaussian function `exp (-c⁻¹ β€–wβ€–^2)`, with a large (but finite) `c`. As this function converges pointwise to `1` when `c β†’ ∞`, we get `∫_w exp (2 I Ο€ βŸͺw, v⟫) 𝓕 f (w) dw = lim_c ∫_w exp (-c⁻¹ β€–wβ€–^2 + 2 I Ο€ βŸͺw, v⟫) 𝓕 f (w) dw`. One can perform Fubini on the right hand side for fixed `c`, writing the integral as `∫_x (∫_w exp (-c⁻¹‖wβ€–^2 + 2 I Ο€ βŸͺw, v - x⟫ dw)) f x dx`. The middle factor is the Fourier transform of a more and more flat function (converging to the constant `1`), hence it becomes more and more concentrated, around the point `v`. (Morally, it converges to the Dirac at `v`). Moreover, it has integral one. Therefore, multiplying by `f` and integrating, one gets a term converging to `f v` as `c β†’ ∞`. Since it also converges to `𝓕⁻ (𝓕 f) v`, this proves the result. To check the concentration property of the middle factor and the fact that it has integral one, we rely on the explicit computation of the Fourier transform of Gaussians. -/ open Filter MeasureTheory Complex Module Metric Real Bornology open scoped Topology FourierTransform RealInnerProductSpace Complex variable {V E : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MeasurableSpace V] [BorelSpace V] [FiniteDimensional ℝ V] [NormedAddCommGroup E] [NormedSpace β„‚ E] {f : V β†’ E} namespace Real lemma tendsto_integral_cexp_sq_smul (hf : Integrable f) : Tendsto (fun (c : ℝ) ↦ (∫ v : V, cexp (- c⁻¹ * β€–vβ€–^2) β€’ f v)) atTop (𝓝 (∫ v : V, f v)) := by apply tendsto_integral_filter_of_dominated_convergence _ _ _ hf.norm Β· filter_upwards with v nth_rewrite 2 [show f v = cexp (- (0 : ℝ) * β€–vβ€–^2) β€’ f v by simp] apply (Tendsto.cexp _).smul_const exact tendsto_inv_atTop_zero.ofReal.neg.mul_const _ Β· filter_upwards with c using AEStronglyMeasurable.smul (Continuous.aestronglyMeasurable (by fun_prop)) hf.1 Β· filter_upwards [Ici_mem_atTop (0 : ℝ)] with c (hc : 0 ≀ c) filter_upwards with v simp only [ofReal_inv, neg_mul, norm_smul] norm_cast conv_rhs => rw [← one_mul (β€–f vβ€–)] gcongr simp only [norm_eq_abs, abs_exp, exp_le_one_iff, Left.neg_nonpos_iff] positivity variable [CompleteSpace E] lemma tendsto_integral_gaussian_smul (hf : Integrable f) (h'f : Integrable (𝓕 f)) (v : V) : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((Ο€ * c) ^ (finrank ℝ V / 2 : β„‚) * cexp (-Ο€ ^ 2 * c * β€–v - wβ€– ^ 2)) β€’ f w) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by have A : Tendsto (fun (c : ℝ) ↦ (∫ w : V, cexp (- c⁻¹ * β€–wβ€–^2 + 2 * Ο€ * I * βŸͺv, w⟫) β€’ (𝓕 f) w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by have : Integrable (fun w ↦ 𝐞 βŸͺw, v⟫ β€’ (𝓕 f) w) := by have B : Continuous fun p : V Γ— V => (- innerβ‚— V) p.1 p.2 := continuous_inner.neg simpa using (VectorFourier.fourierIntegral_convergent_iff Real.continuous_fourierChar B v).2 h'f convert tendsto_integral_cexp_sq_smul this using 4 with c w Β· rw [Submonoid.smul_def, Real.fourierChar_apply, smul_smul, ← Complex.exp_add, real_inner_comm] congr 3 simp only [ofReal_mul, ofReal_ofNat] ring Β· simp [fourierIntegralInv_eq] have B : Tendsto (fun (c : ℝ) ↦ (∫ w : V, 𝓕 (fun w ↦ cexp (- c⁻¹ * β€–wβ€–^2 + 2 * Ο€ * I * βŸͺv, w⟫)) w β€’ f w)) atTop (𝓝 (𝓕⁻ (𝓕 f) v)) := by apply A.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) have J : Integrable (fun w ↦ cexp (- c⁻¹ * β€–wβ€–^2 + 2 * Ο€ * I * βŸͺv, w⟫)) := GaussianFourier.integrable_cexp_neg_mul_sq_norm_add (by simpa) _ _ simpa using (VectorFourier.integral_fourierIntegral_smul_eq_flip (L := innerβ‚— V) Real.continuous_fourierChar continuous_inner J hf).symm apply B.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) congr with w rw [fourierIntegral_gaussian_innerProductSpace' (by simpa)] congr Β· simp Β· simp; ring lemma tendsto_integral_gaussian_smul' (hf : Integrable f) {v : V} (h'f : ContinuousAt f v) : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((Ο€ * c : β„‚) ^ (finrank ℝ V / 2 : β„‚) * cexp (-Ο€ ^ 2 * c * β€–v - wβ€– ^ 2)) β€’ f w) atTop (𝓝 (f v)) := by let Ο† : V β†’ ℝ := fun w ↦ Ο€ ^ (finrank ℝ V / 2 : ℝ) * Real.exp (-Ο€^2 * β€–wβ€–^2) have A : Tendsto (fun (c : ℝ) ↦ ∫ w : V, (c ^ finrank ℝ V * Ο† (c β€’ (v - w))) β€’ f w) atTop (𝓝 (f v)) := by apply tendsto_integral_comp_smul_smul_of_integrable' Β· exact fun x ↦ by positivity Β· rw [integral_const_mul, GaussianFourier.integral_rexp_neg_mul_sq_norm (by positivity)] nth_rewrite 2 [← pow_one Ο€] rw [← rpow_natCast, ← rpow_natCast, ← rpow_sub pi_pos, ← rpow_mul pi_nonneg, ← rpow_add pi_pos] ring_nf exact rpow_zero _ Β· have A : Tendsto (fun (w : V) ↦ Ο€^2 * β€–wβ€–^2) (cobounded V) atTop := by rw [tendsto_const_mul_atTop_of_pos (by positivity)] apply (tendsto_pow_atTop two_ne_zero).comp tendsto_norm_cobounded_atTop have B := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (finrank ℝ V / 2) 1 zero_lt_one |>.comp A |>.const_mul (Ο€ ^ (-finrank ℝ V / 2 : ℝ)) rw [mul_zero] at B convert B using 2 with x simp only [neg_mul, one_mul, Function.comp_apply, ← mul_assoc, ← rpow_natCast, Ο†] congr 1 rw [mul_rpow (by positivity) (by positivity), ← rpow_mul pi_nonneg, ← rpow_mul (norm_nonneg _), ← mul_assoc, ← rpow_add pi_pos, mul_comm] congr <;> ring Β· exact hf Β· exact h'f have B : Tendsto (fun (c : ℝ) ↦ ∫ w : V, ((c^(1/2 : ℝ)) ^ finrank ℝ V * Ο† ((c^(1/2 : ℝ)) β€’ (v - w))) β€’ f w) atTop (𝓝 (f v)) := A.comp (tendsto_rpow_atTop (by norm_num)) apply B.congr' filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c) congr with w rw [← coe_smul] congr rw [ofReal_mul, ofReal_mul, ofReal_exp, ← mul_assoc] congr Β· rw [mul_cpow_ofReal_nonneg pi_nonneg hc.le, ← rpow_natCast, ← rpow_mul hc.le, mul_comm, ofReal_cpow pi_nonneg, ofReal_cpow hc.le] simp [div_eq_inv_mul] Β· norm_cast simp only [one_div, norm_smul, Real.norm_eq_abs, mul_pow, sq_abs, neg_mul, neg_inj, ← rpow_natCast, ← rpow_mul hc.le, mul_assoc] norm_num end Real variable [CompleteSpace E] /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f` at continuity points of `f`. -/ theorem MeasureTheory.Integrable.fourier_inversion (hf : Integrable f) (h'f : Integrable (𝓕 f)) {v : V} (hv : ContinuousAt f v) : 𝓕⁻ (𝓕 f) v = f v := tendsto_nhds_unique (Real.tendsto_integral_gaussian_smul hf h'f v) (Real.tendsto_integral_gaussian_smul' hf hv) /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is continuous, integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕⁻ (𝓕 f) = f`. -/ theorem Continuous.fourier_inversion (h : Continuous f) (hf : Integrable f) (h'f : Integrable (𝓕 f)) : 𝓕⁻ (𝓕 f) = f := by ext v exact hf.fourier_inversion h'f h.continuousAt /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕 (𝓕⁻ f) = f` at continuity points of `f`. -/ theorem MeasureTheory.Integrable.fourier_inversion_inv (hf : Integrable f) (h'f : Integrable (𝓕 f)) {v : V} (hv : ContinuousAt f v) : 𝓕 (𝓕⁻ f) v = f v := by rw [fourierIntegralInv_comm] exact fourier_inversion hf h'f hv /-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product space is continuous, integrable, and its Fourier transform `𝓕 f` is also integrable, then `𝓕 (𝓕⁻ f) = f`. -/
Mathlib/Analysis/Fourier/Inversion.lean
186
190
theorem Continuous.fourier_inversion_inv (h : Continuous f) (hf : Integrable f) (h'f : Integrable (𝓕 f)) : 𝓕 (𝓕⁻ f) = f := by
ext v exact hf.fourier_inversion_inv h'f h.continuousAt
/- 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.Probability.Independence.Integrable import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.Analysis.SpecificLimits.FloorPow import Mathlib.Analysis.PSeries import Mathlib.Analysis.Asymptotics.SpecificAsymptotics /-! # 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 open scoped Function -- required for scoped `on` notation 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 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 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] @[simp] theorem truncation_zero (f : Ξ± β†’ ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl 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] 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] 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] by_cases h'x : f x ≀ A Β· have : -A < f x := by linarith [h x] simp only [this, true_and] Β· simp only [h'x, and_false] Β· simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self] theorem truncation_nonneg {f : Ξ± β†’ ℝ} (A : ℝ) {x : Ξ±} (h : 0 ≀ f x) : 0 ≀ truncation f A x := Set.indicator_apply_nonneg fun _ => h theorem _root_.MeasureTheory.AEStronglyMeasurable.memLp_truncation [IsFiniteMeasure ΞΌ] (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} {p : ℝβ‰₯0∞} : MemLp (truncation f A) p ΞΌ := MemLp.of_bound hf.truncation |A| (Eventually.of_forall fun _ => abs_truncation_le_bound _ _ _) theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure ΞΌ] (hf : AEStronglyMeasurable f ΞΌ) {A : ℝ} : Integrable (truncation f A) ΞΌ := by rw [← memLp_one_iff_integrable]; exact hf.memLp_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 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 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 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 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) /-- 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 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) 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_const_mul] 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, measureReal_restrict_apply', measurableSet_Ioc, Set.univ_inter, Algebra.id.smul_eq_mul, mul_one] rw [← ENNReal.toReal_one] 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 simp [ENNReal.ofReal_sum_of_nonneg] _ = 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 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 +contextual only [Set.mem_Ioc, Set.mem_Ioi, Set.iUnion_subset_iff, Set.setOf_subset_setOf, imp_true_iff] rw [this] apply tendsto_measure_iUnion_atTop 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 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 end MomentEstimates /-! Proof of the strong law of large numbers (almost sure version, assuming only pairwise independence) for nonnegative random variables, following Etemadi's proof. -/ section StrongLawNonneg variable (X : β„• β†’ Ξ© β†’ ℝ) (hint : Integrable (X 0)) (hindep : Pairwise (IndepFun on X)) (hident : βˆ€ i, IdentDistrib (X i) (X 0)) (hnonneg : βˆ€ i Ο‰, 0 ≀ X i Ο‰) include hint hindep hident hnonneg in /-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`, up to a given `Ξ΅ > 0`. This follows from a variance control. -/ theorem strong_law_aux1 {c : ℝ} (c_one : 1 < c) {Ξ΅ : ℝ} (Ξ΅pos : 0 < Ξ΅) : βˆ€α΅ Ο‰, βˆ€αΆ  n : β„• in atTop, |βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i Ο‰ - 𝔼[βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i]| < Ξ΅ * ⌊c ^ nβŒ‹β‚Š := by /- Let `S n = βˆ‘ i ∈ range n, Y i` where `Y i = truncation (X i) i`. We should show that `|S k - 𝔼[S k]| / k ≀ Ξ΅` along the sequence of powers of `c`. For this, we apply Borel-Cantelli: it suffices to show that the converse probabilities are summable. From Chebyshev inequality, this will follow from a variance control `βˆ‘' Var[S (c^i)] / (c^i)^2 < ∞`. This is checked in `I2` using pairwise independence to expand the variance of the sum as the sum of the variances, and then a straightforward but tedious computation (essentially boiling down to the fact that the sum of `1/(c ^ i)^2` beyond a threshold `j` is comparable to `1/j^2`). Note that we have written `c^i` in the above proof sketch, but rigorously one should put integer parts everywhere, making things more painful. We write `u i = ⌊c^iβŒ‹β‚Š` for brevity. -/ have c_pos : 0 < c := zero_lt_one.trans c_one have hX : βˆ€ i, AEStronglyMeasurable (X i) β„™ := fun i => (hident i).symm.aestronglyMeasurable_snd hint.1 have A : βˆ€ i, StronglyMeasurable (indicator (Set.Ioc (-i : ℝ) i) id) := fun i => stronglyMeasurable_id.indicator measurableSet_Ioc set Y := fun n : β„• => truncation (X n) n set S := fun n => βˆ‘ i ∈ range n, Y i with hS let u : β„• β†’ β„• := fun n => ⌊c ^ nβŒ‹β‚Š have u_mono : Monotone u := fun i j hij => Nat.floor_mono (pow_right_monoβ‚€ c_one.le hij) have I1 : βˆ€ K, βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≀ 2 * 𝔼[X 0] := by intro K calc βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * Var[Y j] ≀ βˆ‘ j ∈ range K, ((j : ℝ) ^ 2)⁻¹ * 𝔼[truncation (X 0) j ^ 2] := by apply sum_le_sum fun j _ => ?_ refine mul_le_mul_of_nonneg_left ?_ (inv_nonneg.2 (sq_nonneg _)) rw [(hident j).truncation.variance_eq] exact variance_le_expectation_sq (hX 0).truncation _ ≀ 2 * 𝔼[X 0] := sum_variance_truncation_le hint (hnonneg 0) K let C := c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) have I2 : βˆ€ N, βˆ‘ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] ≀ C := by intro N calc βˆ‘ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * Var[S (u i)] = βˆ‘ i ∈ range N, ((u i : ℝ) ^ 2)⁻¹ * βˆ‘ j ∈ range (u i), Var[Y j] := by congr 1 with i congr 1 rw [hS, IndepFun.variance_sum] Β· intro j _ exact (hident j).aestronglyMeasurable_fst.memLp_truncation Β· intro k _ l _ hkl exact (hindep hkl).comp (A k).measurable (A l).measurable _ = βˆ‘ j ∈ range (u (N - 1)), (βˆ‘ i ∈ range N with j < u i, ((u i : ℝ) ^ 2)⁻¹) * Var[Y j] := by simp_rw [mul_sum, sum_mul, sum_sigma'] refine sum_nbij' (fun p ↦ ⟨p.2, p.1⟩) (fun p ↦ ⟨p.2, p.1⟩) ?_ ?_ ?_ ?_ ?_ Β· simp only [mem_sigma, mem_range, filter_congr_decidable, mem_filter, and_imp, Sigma.forall] exact fun a b haN hb ↦ ⟨hb.trans_le <| u_mono <| Nat.le_pred_of_lt haN, haN, hb⟩ all_goals simp _ ≀ βˆ‘ j ∈ range (u (N - 1)), c ^ 5 * (c - 1)⁻¹ ^ 3 / ↑j ^ 2 * Var[Y j] := by apply sum_le_sum fun j hj => ?_ rcases eq_zero_or_pos j with (rfl | hj) Β· simp only [Nat.cast_zero, zero_pow, Ne, Nat.one_ne_zero, not_false_iff, div_zero, zero_mul] simp only [Y, Nat.cast_zero, truncation_zero, variance_zero, mul_zero, le_rfl] apply mul_le_mul_of_nonneg_right _ (variance_nonneg _ _) convert sum_div_nat_floor_pow_sq_le_div_sq N (Nat.cast_pos.2 hj) c_one using 2 Β· simp only [u, Nat.cast_lt] Β· simp only [Y, S, u, C, one_div] _ = c ^ 5 * (c - 1)⁻¹ ^ 3 * βˆ‘ j ∈ range (u (N - 1)), ((j : ℝ) ^ 2)⁻¹ * Var[Y j] := by simp_rw [mul_sum, div_eq_mul_inv, mul_assoc] _ ≀ c ^ 5 * (c - 1)⁻¹ ^ 3 * (2 * 𝔼[X 0]) := by apply mul_le_mul_of_nonneg_left (I1 _) apply mul_nonneg (pow_nonneg c_pos.le _) exact pow_nonneg (inv_nonneg.2 (sub_nonneg.2 c_one.le)) _ have I3 : βˆ€ N, βˆ‘ i ∈ range N, β„™ {Ο‰ | (u i * Ξ΅ : ℝ) ≀ |S (u i) Ο‰ - 𝔼[S (u i)]|} ≀ ENNReal.ofReal (Ρ⁻¹ ^ 2 * C) := by intro N calc βˆ‘ i ∈ range N, β„™ {Ο‰ | (u i * Ξ΅ : ℝ) ≀ |S (u i) Ο‰ - 𝔼[S (u i)]|} ≀ βˆ‘ i ∈ range N, ENNReal.ofReal (Var[S (u i)] / (u i * Ξ΅) ^ 2) := by refine sum_le_sum fun i _ => ?_ apply meas_ge_le_variance_div_sq Β· exact memLp_finset_sum' _ fun j _ => (hident j).aestronglyMeasurable_fst.memLp_truncation Β· apply mul_pos (Nat.cast_pos.2 _) Ξ΅pos refine zero_lt_one.trans_le ?_ apply Nat.le_floor rw [Nat.cast_one] apply one_le_powβ‚€ c_one.le _ = ENNReal.ofReal (βˆ‘ i ∈ range N, Var[S (u i)] / (u i * Ξ΅) ^ 2) := by rw [ENNReal.ofReal_sum_of_nonneg fun i _ => ?_] exact div_nonneg (variance_nonneg _ _) (sq_nonneg _) _ ≀ ENNReal.ofReal (Ρ⁻¹ ^ 2 * C) := by apply ENNReal.ofReal_le_ofReal -- Porting note: do most of the rewrites under `conv` so as not to expand `variance` conv_lhs => enter [2, i] rw [div_eq_inv_mul, ← inv_pow, mul_inv, mul_comm _ Ρ⁻¹, mul_pow, mul_assoc] rw [← mul_sum] refine mul_le_mul_of_nonneg_left ?_ (sq_nonneg _) conv_lhs => enter [2, i]; rw [inv_pow] exact I2 N have I4 : (βˆ‘' i, β„™ {Ο‰ | (u i * Ξ΅ : ℝ) ≀ |S (u i) Ο‰ - 𝔼[S (u i)]|}) < ∞ := (le_of_tendsto_of_tendsto' (ENNReal.tendsto_nat_tsum _) tendsto_const_nhds I3).trans_lt ENNReal.ofReal_lt_top filter_upwards [ae_eventually_not_mem I4.ne] with Ο‰ hΟ‰ simp_rw [S, not_le, mul_comm, sum_apply] at hΟ‰ convert hΟ‰; simp only [Y, S, u, C, sum_apply] include hint hindep hident hnonneg in /-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to the truncated expectation) along the sequence `c^n`, for any `c > 1`. This follows from `strong_law_aux1` by varying `Ξ΅`. -/ theorem strong_law_aux2 {c : ℝ} (c_one : 1 < c) : βˆ€α΅ Ο‰, (fun n : β„• => βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i Ο‰ - 𝔼[βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i]) =o[atTop] fun n : β„• => (⌊c ^ nβŒ‹β‚Š : ℝ) := by obtain ⟨v, -, v_pos, v_lim⟩ : βˆƒ v : β„• β†’ ℝ, StrictAnti v ∧ (βˆ€ n : β„•, 0 < v n) ∧ Tendsto v atTop (𝓝 0) := exists_seq_strictAnti_tendsto (0 : ℝ) have := fun i => strong_law_aux1 X hint hindep hident hnonneg c_one (v_pos i) filter_upwards [ae_all_iff.2 this] with Ο‰ hΟ‰ apply Asymptotics.isLittleO_iff.2 fun Ξ΅ Ξ΅pos => ?_ obtain ⟨i, hi⟩ : βˆƒ i, v i < Ξ΅ := ((tendsto_order.1 v_lim).2 Ξ΅ Ξ΅pos).exists filter_upwards [hΟ‰ i] with n hn simp only [Real.norm_eq_abs, abs_abs, Nat.abs_cast] exact hn.le.trans (mul_le_mul_of_nonneg_right hi.le (Nat.cast_nonneg _)) include hint hident in /-- The expectation of the truncated version of `Xα΅’` behaves asymptotically like the whole expectation. This follows from convergence and CesΓ ro averaging. -/ theorem strong_law_aux3 : (fun n => 𝔼[βˆ‘ i ∈ range n, truncation (X i) i] - n * 𝔼[X 0]) =o[atTop] ((↑) : β„• β†’ ℝ) := by have A : Tendsto (fun i => 𝔼[truncation (X i) i]) atTop (𝓝 𝔼[X 0]) := by convert (tendsto_integral_truncation hint).comp tendsto_natCast_atTop_atTop using 1 ext i exact (hident i).truncation.integral_eq convert Asymptotics.isLittleO_sum_range_of_tendsto_zero (tendsto_sub_nhds_zero_iff.2 A) using 1 ext1 n simp only [sum_sub_distrib, sum_const, card_range, nsmul_eq_mul, sum_apply, sub_left_inj] rw [integral_finset_sum _ fun i _ => ?_] exact ((hident i).symm.integrable_snd hint).1.integrable_truncation include hint hindep hident hnonneg in /-- The truncation of `Xα΅’` up to `i` satisfies the strong law of large numbers (with respect to the original expectation) along the sequence `c^n`, for any `c > 1`. This follows from the version from the truncated expectation, and the fact that the truncated and the original expectations have the same asymptotic behavior. -/ theorem strong_law_aux4 {c : ℝ} (c_one : 1 < c) : βˆ€α΅ Ο‰, (fun n : β„• => βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, truncation (X i) i Ο‰ - ⌊c ^ nβŒ‹β‚Š * 𝔼[X 0]) =o[atTop] fun n : β„• => (⌊c ^ nβŒ‹β‚Š : ℝ) := by filter_upwards [strong_law_aux2 X hint hindep hident hnonneg c_one] with Ο‰ hΟ‰ have A : Tendsto (fun n : β„• => ⌊c ^ nβŒ‹β‚Š) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hΟ‰.add ((strong_law_aux3 X hint hident).comp_tendsto A) using 1 ext1 n simp include hint hident hnonneg in /-- The truncated and non-truncated versions of `Xα΅’` have the same asymptotic behavior, as they almost surely coincide at all but finitely many steps. This follows from a probability computation and Borel-Cantelli. -/ theorem strong_law_aux5 : βˆ€α΅ Ο‰, (fun n : β„• => βˆ‘ i ∈ range n, truncation (X i) i Ο‰ - βˆ‘ i ∈ range n, X i Ο‰) =o[atTop] fun n : β„• => (n : ℝ) := by have A : (βˆ‘' j : β„•, β„™ {Ο‰ | X j Ο‰ ∈ Set.Ioi (j : ℝ)}) < ∞ := by convert tsum_prob_mem_Ioi_lt_top hint (hnonneg 0) using 2 ext1 j exact (hident j).measure_mem_eq measurableSet_Ioi have B : βˆ€α΅ Ο‰, Tendsto (fun n : β„• => truncation (X n) n Ο‰ - X n Ο‰) atTop (𝓝 0) := by filter_upwards [ae_eventually_not_mem A.ne] with Ο‰ hΟ‰ apply tendsto_const_nhds.congr' _ filter_upwards [hΟ‰, Ioi_mem_atTop 0] with n hn npos simp only [truncation, indicator, Set.mem_Ioc, id, Function.comp_apply] split_ifs with h Β· exact (sub_self _).symm Β· have : -(n : ℝ) < X n Ο‰ := by apply lt_of_lt_of_le _ (hnonneg n Ο‰) simpa only [Right.neg_neg_iff, Nat.cast_pos] using npos simp only [this, true_and, not_le] at h exact (hn h).elim filter_upwards [B] with Ο‰ hΟ‰ convert isLittleO_sum_range_of_tendsto_zero hΟ‰ using 1 ext n rw [sum_sub_distrib] include hint hindep hident hnonneg in /-- `Xα΅’` satisfies the strong law of large numbers along the sequence `c^n`, for any `c > 1`. This follows from the version for the truncated `Xα΅’`, and the fact that `Xα΅’` and its truncated version have the same asymptotic behavior. -/ theorem strong_law_aux6 {c : ℝ} (c_one : 1 < c) : βˆ€α΅ Ο‰, Tendsto (fun n : β„• => (βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, X i Ο‰) / ⌊c ^ nβŒ‹β‚Š) atTop (𝓝 𝔼[X 0]) := by have H : βˆ€ n : β„•, (0 : ℝ) < ⌊c ^ nβŒ‹β‚Š := by intro n refine zero_lt_one.trans_le ?_ simp only [Nat.one_le_cast, Nat.one_le_floor_iff, one_le_powβ‚€ c_one.le] filter_upwards [strong_law_aux4 X hint hindep hident hnonneg c_one, strong_law_aux5 X hint hident hnonneg] with Ο‰ hΟ‰ h'Ο‰ rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ] have L : (fun n : β„• => βˆ‘ i ∈ range ⌊c ^ nβŒ‹β‚Š, X i Ο‰ - ⌊c ^ nβŒ‹β‚Š * 𝔼[X 0]) =o[atTop] fun n => (⌊c ^ nβŒ‹β‚Š : ℝ) := by have A : Tendsto (fun n : β„• => ⌊c ^ nβŒ‹β‚Š) atTop atTop := tendsto_nat_floor_atTop.comp (tendsto_pow_atTop_atTop_of_one_lt c_one) convert hΟ‰.sub (h'Ο‰.comp_tendsto A) using 1 ext1 n simp only [Function.comp_apply, sub_sub_sub_cancel_left] convert L.mul_isBigO (isBigO_refl (fun n : β„• => (⌊c ^ nβŒ‹β‚Š : ℝ)⁻¹) atTop) using 1 <;> (ext1 n; field_simp [(H n).ne']) include hint hindep hident hnonneg in /-- `Xα΅’` satisfies the strong law of large numbers along all integers. This follows from the corresponding fact along the sequences `c^n`, and the fact that any integer can be sandwiched between `c^n` and `c^(n+1)` with comparably small error if `c` is close enough to `1` (which is formalized in `tendsto_div_of_monotone_of_tendsto_div_floor_pow`). -/ theorem strong_law_aux7 : βˆ€α΅ Ο‰, Tendsto (fun n : β„• => (βˆ‘ i ∈ range n, X i Ο‰) / n) atTop (𝓝 𝔼[X 0]) := by obtain ⟨c, -, cone, clim⟩ : βˆƒ c : β„• β†’ ℝ, StrictAnti c ∧ (βˆ€ n : β„•, 1 < c n) ∧ Tendsto c atTop (𝓝 1) := exists_seq_strictAnti_tendsto (1 : ℝ) have : βˆ€ k, βˆ€α΅ Ο‰, Tendsto (fun n : β„• => (βˆ‘ i ∈ range ⌊c k ^ nβŒ‹β‚Š, X i Ο‰) / ⌊c k ^ nβŒ‹β‚Š) atTop (𝓝 𝔼[X 0]) := fun k => strong_law_aux6 X hint hindep hident hnonneg (cone k) filter_upwards [ae_all_iff.2 this] with Ο‰ hΟ‰ apply tendsto_div_of_monotone_of_tendsto_div_floor_pow _ _ _ c cone clim _ Β· intro m n hmn exact sum_le_sum_of_subset_of_nonneg (range_mono hmn) fun i _ _ => hnonneg i Ο‰ Β· exact hΟ‰ end StrongLawNonneg /-- **Strong law of large numbers**, almost sure version: if `X n` is a sequence of independent identically distributed integrable real-valued 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. Superseded by `strong_law_ae`, which works for random variables taking values in any Banach space. -/
Mathlib/Probability/StrongLaw.lean
605
617
theorem strong_law_ae_real {Ξ© : Type*} {m : MeasurableSpace Ξ©} {ΞΌ : Measure Ξ©} (X : β„• β†’ Ξ© β†’ ℝ) (hint : Integrable (X 0) ΞΌ) (hindep : Pairwise ((IndepFun Β· Β· ΞΌ) on X)) (hident : βˆ€ i, IdentDistrib (X i) (X 0) ΞΌ ΞΌ) : βˆ€α΅ Ο‰ βˆ‚ΞΌ, Tendsto (fun n : β„• => (βˆ‘ i ∈ range n, X i Ο‰) / n) atTop (𝓝 ΞΌ[X 0]) := by
let mΞ© : MeasureSpace Ξ© := ⟨μ⟩ -- first get rid of the trivial case where the space is not a probability space by_cases h : βˆ€α΅ Ο‰, X 0 Ο‰ = 0 Β· have I : βˆ€α΅ Ο‰, βˆ€ i, X i Ο‰ = 0 := by rw [ae_all_iff] intro i exact (hident i).symm.ae_snd (p := fun x ↦ x = 0) measurableSet_eq h filter_upwards [I] with Ο‰ hΟ‰
/- Copyright (c) 2018 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.Fintype.Lattice import Mathlib.Data.Fintype.Sum import Mathlib.Topology.Homeomorph.Lemmas import Mathlib.Topology.MetricSpace.Antilipschitz /-! # Isometries We define isometries, i.e., maps between emetric spaces that preserve the edistance (on metric spaces, these are exactly the maps that preserve distances), and prove their basic properties. We also introduce isometric bijections. Since a lot of elementary properties don't require `eq_of_dist_eq_zero` we start setting up the theory for `PseudoMetricSpace` and we specialize to `MetricSpace` when needed. -/ open Topology noncomputable section universe u v w variable {ΞΉ : Type*} {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} open Function Set open scoped Topology ENNReal /-- An isometry (also known as isometric embedding) is a map preserving the edistance between pseudoemetric spaces, or equivalently the distance between pseudometric space. -/ def Isometry [PseudoEMetricSpace Ξ±] [PseudoEMetricSpace Ξ²] (f : Ξ± β†’ Ξ²) : Prop := βˆ€ x1 x2 : Ξ±, edist (f x1) (f x2) = edist x1 x2 /-- On pseudometric spaces, a map is an isometry if and only if it preserves nonnegative distances. -/ theorem isometry_iff_nndist_eq [PseudoMetricSpace Ξ±] [PseudoMetricSpace Ξ²] {f : Ξ± β†’ Ξ²} : Isometry f ↔ βˆ€ x y, nndist (f x) (f y) = nndist x y := by simp only [Isometry, edist_nndist, ENNReal.coe_inj] /-- On pseudometric spaces, a map is an isometry if and only if it preserves distances. -/
Mathlib/Topology/MetricSpace/Isometry.lean
46
48
theorem isometry_iff_dist_eq [PseudoMetricSpace Ξ±] [PseudoMetricSpace Ξ²] {f : Ξ± β†’ Ξ²} : Isometry f ↔ βˆ€ x y, dist (f x) (f y) = dist x y := by
simp only [isometry_iff_nndist_eq, ← coe_nndist, NNReal.coe_inj]
/- Copyright (c) 2022 MarΓ­a InΓ©s de Frutos-FernΓ‘ndez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: MarΓ­a InΓ©s de Frutos-FernΓ‘ndez -/ import Mathlib.Order.Filter.Cofinite import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.UniqueFactorizationDomain.Finite /-! # Factorization of ideals and fractional ideals of Dedekind domains Every nonzero ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are natural numbers. Similarly, every nonzero fractional ideal `I` of a Dedekind domain `R` can be factored as a product `∏_v v^{n_v}` over the maximal ideals of `R`, where the exponents `n_v` are integers. We define `FractionalIdeal.count K v I` (abbreviated as `val_v(I)` in the documentation) to be `n_v`, and we prove some of its properties. If `I = 0`, we define `val_v(I) = 0`. ## Main definitions - `FractionalIdeal.count` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. ## Main results - `Ideal.finite_factors` : Only finitely many maximal ideals of `R` divide a given nonzero ideal. - `Ideal.finprod_heightOneSpectrum_factorization` : The ideal `I` equals the finprod `∏_v v^(val_v(I))`, where `val_v(I)` denotes the multiplicity of `v` in the factorization of `I` and `v` runs over the maximal ideals of `R`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization` : If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization'` : If `I` is a nonzero fractional ideal, then `I` is equal to the product `∏_v v^(val_v(I))`. - `FractionalIdeal.finprod_heightOneSpectrum_factorization_principal` : For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. - `FractionalIdeal.finite_factors` : If `I β‰  0`, then `val_v(I) = 0` for all but finitely many maximal ideals of `R`. ## Implementation notes Since we are only interested in the factorization of nonzero fractional ideals, we define `val_v(0) = 0` so that every `val_v` is in `β„€` and we can avoid having to use `WithTop β„€`. ## Tags dedekind domain, fractional ideal, ideal, factorization -/ noncomputable section open scoped nonZeroDivisors open Set Function UniqueFactorizationMonoid IsDedekindDomain IsDedekindDomain.HeightOneSpectrum variable {R : Type*} [CommRing R] {K : Type*} [Field K] [Algebra R K] [IsFractionRing R K] /-! ### Factorization of ideals of Dedekind domains -/ variable [IsDedekindDomain R] (v : HeightOneSpectrum R) open scoped Classical in /-- Given a maximal ideal `v` and an ideal `I` of `R`, `maxPowDividing` returns the maximal power of `v` dividing `I`. -/ def IsDedekindDomain.HeightOneSpectrum.maxPowDividing (I : Ideal R) : Ideal R := v.asIdeal ^ (Associates.mk v.asIdeal).count (Associates.mk I).factors /-- Only finitely many maximal ideals of `R` divide a given nonzero ideal. -/ theorem Ideal.finite_factors {I : Ideal R} (hI : I β‰  0) : {v : HeightOneSpectrum R | v.asIdeal ∣ I}.Finite := by rw [← Set.finite_coe_iff, Set.coe_setOf] haveI h_fin := fintypeSubtypeDvd I hI refine Finite.of_injective (fun v => (⟨(v : HeightOneSpectrum R).asIdeal, v.2⟩ : { x // x ∣ I })) ?_ intro v w hvw simp? at hvw says simp only [Subtype.mk.injEq] at hvw exact Subtype.coe_injective (HeightOneSpectrum.ext hvw) open scoped Classical in /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that the multiplicity of `v` in the factorization of `I`, denoted `val_v(I)`, is nonzero. -/ theorem Associates.finite_factors {I : Ideal R} (hI : I β‰  0) : βˆ€αΆ  v : HeightOneSpectrum R in Filter.cofinite, ((Associates.mk v.asIdeal).count (Associates.mk I).factors : β„€) = 0 := by have h_supp : {v : HeightOneSpectrum R | Β¬((Associates.mk v.asIdeal).count (Associates.mk I).factors : β„€) = 0} = {v : HeightOneSpectrum R | v.asIdeal ∣ I} := by ext v simp_rw [Int.natCast_eq_zero] exact Associates.count_ne_zero_iff_dvd hI v.irreducible rw [Filter.eventually_cofinite, h_supp] exact Ideal.finite_factors hI namespace Ideal open scoped Classical in /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport {I : Ideal R} (hI : I β‰  0) : (mulSupport fun v : HeightOneSpectrum R => v.maxPowDividing I).Finite := haveI h_subset : {v : HeightOneSpectrum R | v.maxPowDividing I β‰  1} βŠ† {v : HeightOneSpectrum R | ((Associates.mk v.asIdeal).count (Associates.mk I).factors : β„€) β‰  0} := by intro v hv h_zero have hv' : v.maxPowDividing I = 1 := by rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, Int.natCast_eq_zero.mp h_zero, pow_zero _] exact hv hv' Finite.subset (Filter.eventually_cofinite.mp (Associates.finite_factors hI)) h_subset open scoped Classical in /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^(val_v(I))`, regarded as a fractional ideal, is not `(1)`. -/ theorem finite_mulSupport_coe {I : Ideal R} (hI : I β‰  0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : β„€)).Finite := by rw [mulSupport] simp_rw [Ne, zpow_natCast, ← FractionalIdeal.coeIdeal_pow, FractionalIdeal.coeIdeal_eq_one] exact finite_mulSupport hI open scoped Classical in /-- For every nonzero ideal `I` of `v`, there are finitely many maximal ideals `v` such that `v^-(val_v(I))` is not the unit ideal. -/ theorem finite_mulSupport_inv {I : Ideal R} (hI : I β‰  0) : (mulSupport fun v : HeightOneSpectrum R => (v.asIdeal : FractionalIdeal R⁰ K) ^ (-((Associates.mk v.asIdeal).count (Associates.mk I).factors : β„€))).Finite := by rw [mulSupport] simp_rw [zpow_neg, Ne, inv_eq_one] exact finite_mulSupport_coe hI open scoped Classical in /-- For every nonzero ideal `I` of `v`, `v^(val_v(I) + 1)` does not divide `∏_v v^(val_v(I))`. -/ theorem finprod_not_dvd (I : Ideal R) (hI : I β‰  0) : Β¬v.asIdeal ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors + 1) ∣ ∏ᢠ v : HeightOneSpectrum R, v.maxPowDividing I := by have hf := finite_mulSupport hI have h_ne_zero : v.maxPowDividing I β‰  0 := pow_ne_zero _ v.ne_bot rw [← mul_finprod_cond_ne v hf, pow_add, pow_one, finprod_cond_ne _ _ hf] intro h_contr have hv_prime : Prime v.asIdeal := Ideal.prime_of_isPrime v.ne_bot v.isPrime obtain ⟨w, hw, hvw'⟩ := Prime.exists_mem_finset_dvd hv_prime ((mul_dvd_mul_iff_left h_ne_zero).mp h_contr) have hw_prime : Prime w.asIdeal := Ideal.prime_of_isPrime w.ne_bot w.isPrime have hvw := Prime.dvd_of_dvd_pow hv_prime hvw' rw [Prime.dvd_prime_iff_associated hv_prime hw_prime, associated_iff_eq] at hvw exact (Finset.mem_erase.mp hw).1 (HeightOneSpectrum.ext hvw.symm) end Ideal theorem Associates.finprod_ne_zero (I : Ideal R) : Associates.mk (∏ᢠ v : HeightOneSpectrum R, v.maxPowDividing I) β‰  0 := by classical rw [Associates.mk_ne_zero, finprod_def] split_ifs Β· rw [Finset.prod_ne_zero_iff] intro v _ apply pow_ne_zero _ v.ne_bot Β· exact one_ne_zero namespace Ideal open scoped Classical in /-- The multiplicity of `v` in `∏_v v^(val_v(I))` equals `val_v(I)`. -/ theorem finprod_count (I : Ideal R) (hI : I β‰  0) : (Associates.mk v.asIdeal).count (Associates.mk (∏ᢠ v : HeightOneSpectrum R, v.maxPowDividing I)).factors = (Associates.mk v.asIdeal).count (Associates.mk I).factors := by have h_ne_zero := Associates.finprod_ne_zero I have hv : Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible have h_dvd := finprod_mem_dvd v (Ideal.finite_mulSupport hI) have h_not_dvd := Ideal.finprod_not_dvd v I hI simp only [IsDedekindDomain.HeightOneSpectrum.maxPowDividing] at h_dvd h_ne_zero h_not_dvd rw [← Associates.mk_dvd_mk] at h_dvd h_not_dvd simp only [Associates.dvd_eq_le] at h_dvd h_not_dvd rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le h_ne_zero hv] at h_dvd h_not_dvd rw [not_le] at h_not_dvd apply Nat.eq_of_le_of_lt_succ h_dvd h_not_dvd /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`. -/ theorem finprod_heightOneSpectrum_factorization {I : Ideal R} (hI : I β‰  0) : ∏ᢠ v : HeightOneSpectrum R, v.maxPowDividing I = I := by rw [← associated_iff_eq, ← Associates.mk_eq_mk_iff_associated] classical apply Associates.eq_of_eq_counts Β· apply Associates.finprod_ne_zero I Β· apply Associates.mk_ne_zero.mpr hI intro v hv obtain ⟨J, hJv⟩ := Associates.exists_rep v rw [← hJv, Associates.irreducible_mk] at hv rw [← hJv] apply Ideal.finprod_count ⟨J, Ideal.isPrime_of_prime (irreducible_iff_prime.mp hv), Irreducible.ne_zero hv⟩ I hI variable (K) open scoped Classical in /-- The ideal `I` equals the finprod `∏_v v^(val_v(I))`, when both sides are regarded as fractional ideals of `R`. -/ theorem finprod_heightOneSpectrum_factorization_coe {I : Ideal R} (hI : I β‰  0) : (∏ᢠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk I).factors : β„€)) = I := by conv_rhs => rw [← Ideal.finprod_heightOneSpectrum_factorization hI] rw [FractionalIdeal.coeIdeal_finprod R⁰ K (le_refl _)] simp_rw [IsDedekindDomain.HeightOneSpectrum.maxPowDividing, FractionalIdeal.coeIdeal_pow, zpow_natCast] end Ideal /-! ### Factorization of fractional ideals of Dedekind domains -/ namespace FractionalIdeal open Int IsLocalization open scoped Classical in /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then `I` is equal to the product `∏_v v^(val_v(J) - val_v(a))`. -/ theorem finprod_heightOneSpectrum_factorization {I : FractionalIdeal R⁰ K} (hI : I β‰  0) {a : R} {J : Ideal R} (haJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : ∏ᢠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : β„€) = I := by have hJ_ne_zero : J β‰  0 := ideal_factor_ne_zero hI haJ have hJ := Ideal.finprod_heightOneSpectrum_factorization_coe K hJ_ne_zero have ha_ne_zero : Ideal.span {a} β‰  0 := constant_factor_ne_zero hI haJ have ha := Ideal.finprod_heightOneSpectrum_factorization_coe K ha_ne_zero rw [haJ, ← div_spanSingleton, div_eq_mul_inv, ← coeIdeal_span_singleton, ← hJ, ← ha, ← finprod_inv_distrib] simp_rw [← zpow_neg] rw [← finprod_mul_distrib (Ideal.finite_mulSupport_coe hJ_ne_zero) (Ideal.finite_mulSupport_inv ha_ne_zero)] apply finprod_congr intro v rw [← zpow_addβ‚€ ((@coeIdeal_ne_zero R _ K _ _ _ _).mpr v.ne_bot), sub_eq_add_neg] open scoped Classical in /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal_fraction {n : R} (hn : n β‰  0) (d : β†₯R⁰) : ∏ᢠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {n} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑d : R)}) : Ideal R)).factors : β„€) = spanSingleton R⁰ (mk' K n d) := by have hd_ne_zero : (algebraMap R K) (d : R) β‰  0 := map_ne_zero_of_mem_nonZeroDivisors _ (IsFractionRing.injective R K) d.property have h0 : spanSingleton R⁰ (mk' K n d) β‰  0 := by rw [spanSingleton_ne_zero_iff, IsFractionRing.mk'_eq_div, ne_eq, div_eq_zero_iff, not_or] exact ⟨(map_ne_zero_iff (algebraMap R K) (IsFractionRing.injective R K)).mpr hn, hd_ne_zero⟩ have hI : spanSingleton R⁰ (mk' K n d) = spanSingleton R⁰ ((algebraMap R K) d)⁻¹ * ↑(Ideal.span {n} : Ideal R) := by rw [coeIdeal_span_singleton, spanSingleton_mul_spanSingleton] apply congr_arg rw [IsFractionRing.mk'_eq_div, div_eq_mul_inv, mul_comm] exact finprod_heightOneSpectrum_factorization h0 hI open Classical in /-- For a nonzero `k = r/s ∈ K`, the fractional ideal `(k)` is equal to the product `∏_v v^(val_v(r) - val_v(s))`. -/ theorem finprod_heightOneSpectrum_factorization_principal {I : FractionalIdeal R⁰ K} (hI : I β‰  0) (k : K) (hk : I = spanSingleton R⁰ k) : ∏ᢠ v : HeightOneSpectrum R, (v.asIdeal : FractionalIdeal R⁰ K) ^ ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (mk'_surjective R⁰ k)} : Ideal R)).factors - (Associates.mk v.asIdeal).count (Associates.mk ((Ideal.span {(↑(choose (choose_spec (mk'_surjective R⁰ k)) : β†₯R⁰) : R)}) : Ideal R)).factors : β„€) = I := by set n : R := choose (mk'_surjective R⁰ k) set d : β†₯R⁰ := choose (choose_spec (mk'_surjective R⁰ k)) have hnd : mk' K n d = k := choose_spec (choose_spec (mk'_surjective R⁰ k)) have hn0 : n β‰  0 := by by_contra h rw [← hnd, h, IsFractionRing.mk'_eq_div, map_zero, zero_div, spanSingleton_zero] at hk exact hI hk rw [finprod_heightOneSpectrum_factorization_principal_fraction hn0 d, hk, hnd] variable (K) open Classical in /-- If `I` is a nonzero fractional ideal, `a ∈ R`, and `J` is an ideal of `R` such that `I = a⁻¹J`, then we define `val_v(I)` as `(val_v(J) - val_v(a))`. If `I = 0`, we set `val_v(I) = 0`. -/ def count (I : FractionalIdeal R⁰ K) : β„€ := dite (I = 0) (fun _ : I = 0 => 0) fun _ : Β¬I = 0 => let a := choose (exists_eq_spanSingleton_mul I) let J := choose (choose_spec (exists_eq_spanSingleton_mul I)) ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : β„€) /-- val_v(0) = 0. -/ lemma count_zero : count K v (0 : FractionalIdeal R⁰ K) = 0 := by simp only [count, dif_pos] open Classical in lemma count_ne_zero {I : FractionalIdeal R⁰ K} (hI : I β‰  0) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk (choose (choose_spec (exists_eq_spanSingleton_mul I)))).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {choose (exists_eq_spanSingleton_mul I)})).factors : β„€) := by simp only [count, dif_neg hI] open Classical in /-- `val_v(I)` does not depend on the choice of `a` and `J` used to represent `I`. -/ theorem count_well_defined {I : FractionalIdeal R⁰ K} (hI : I β‰  0) {a : R} {J : Ideal R} (h_aJ : I = spanSingleton R⁰ ((algebraMap R K) a)⁻¹ * ↑J) : count K v I = ((Associates.mk v.asIdeal).count (Associates.mk J).factors - (Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {a})).factors : β„€) := by set a₁ := choose (exists_eq_spanSingleton_mul I) set J₁ := choose (choose_spec (exists_eq_spanSingleton_mul I)) have h_a₁J₁ : I = spanSingleton R⁰ ((algebraMap R K) a₁)⁻¹ * ↑J₁ := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).2 have h_a₁_ne_zero : a₁ β‰  0 := (choose_spec (choose_spec (exists_eq_spanSingleton_mul I))).1 have h_J₁_ne_zero : J₁ β‰  0 := ideal_factor_ne_zero hI h_a₁J₁ have h_a_ne_zero : Ideal.span {a} β‰  0 := constant_factor_ne_zero hI h_aJ have h_J_ne_zero : J β‰  0 := ideal_factor_ne_zero hI h_aJ have h_a₁' : spanSingleton R⁰ ((algebraMap R K) a₁) β‰  0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] exact h_a₁_ne_zero have h_a' : spanSingleton R⁰ ((algebraMap R K) a) β‰  0 := by rw [ne_eq, spanSingleton_eq_zero_iff, ← (algebraMap R K).map_zero, Injective.eq_iff (IsLocalization.injective K (le_refl R⁰))] rw [ne_eq, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] at h_a_ne_zero exact h_a_ne_zero have hv : Irreducible (Associates.mk v.asIdeal) := by exact Associates.irreducible_mk.mpr v.irreducible rw [h_a₁J₁, ← div_spanSingleton, ← div_spanSingleton, div_eq_div_iff h_a₁' h_a', ← coeIdeal_span_singleton, ← coeIdeal_span_singleton, ← coeIdeal_mul, ← coeIdeal_mul] at h_aJ rw [count, dif_neg hI, sub_eq_sub_iff_add_eq_add, ← Int.natCast_add, ← Int.natCast_add, natCast_inj, ← Associates.count_mul _ _ hv, ← Associates.count_mul _ _ hv, Associates.mk_mul_mk, Associates.mk_mul_mk, coeIdeal_injective h_aJ] Β· rw [ne_eq, Associates.mk_eq_zero]; exact h_J_ne_zero Β· rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] exact h_a₁_ne_zero Β· rw [ne_eq, Associates.mk_eq_zero]; exact h_J₁_ne_zero Β· rw [ne_eq, Associates.mk_eq_zero]; exact h_a_ne_zero /-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. -/ theorem count_mul {I I' : FractionalIdeal R⁰ K} (hI : I β‰  0) (hI' : I' β‰  0) : count K v (I * I') = count K v I + count K v I' := by classical have hv : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible obtain ⟨a, J, ha, haJ⟩ := exists_eq_spanSingleton_mul I have ha_ne_zero : Associates.mk (Ideal.span {a} : Ideal R) β‰  0 := by rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha have hJ_ne_zero : Associates.mk J β‰  0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI haJ) obtain ⟨a', J', ha', haJ'⟩ := exists_eq_spanSingleton_mul I' have ha'_ne_zero : Associates.mk (Ideal.span {a'} : Ideal R) β‰  0 := by rw [ne_eq, Associates.mk_eq_zero, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot]; exact ha' have hJ'_ne_zero : Associates.mk J' β‰  0 := Associates.mk_ne_zero.mpr (ideal_factor_ne_zero hI' haJ') have h_prod : I * I' = spanSingleton R⁰ ((algebraMap R K) (a * a'))⁻¹ * ↑(J * J') := by rw [haJ, haJ', mul_assoc, mul_comm (J : FractionalIdeal R⁰ K), mul_assoc, ← mul_assoc, spanSingleton_mul_spanSingleton, coeIdeal_mul, RingHom.map_mul, mul_inv, mul_comm (J : FractionalIdeal R⁰ K)] rw [count_well_defined K v hI haJ, count_well_defined K v hI' haJ', count_well_defined K v (mul_ne_zero hI hI') h_prod, ← Associates.mk_mul_mk, Associates.count_mul hJ_ne_zero hJ'_ne_zero hv, ← Ideal.span_singleton_mul_span_singleton, ← Associates.mk_mul_mk, Associates.count_mul ha_ne_zero ha'_ne_zero hv] push_cast ring /-- For nonzero `I, I'`, `val_v(I*I') = val_v(I) + val_v(I')`. If `I` or `I'` is zero, then `val_v(I*I') = 0`. -/ theorem count_mul' (I I' : FractionalIdeal R⁰ K) [Decidable (I β‰  0 ∧ I' β‰  0)] : count K v (I * I') = if I β‰  0 ∧ I' β‰  0 then count K v I + count K v I' else 0 := by split_ifs with h Β· exact count_mul K v h.1 h.2 Β· push_neg at h by_cases hI : I = 0 Β· rw [hI, MulZeroClass.zero_mul, count, dif_pos (Eq.refl _)] Β· rw [h hI, MulZeroClass.mul_zero, count, dif_pos (Eq.refl _)] /-- val_v(1) = 0. -/ theorem count_one : count K v (1 : FractionalIdeal R⁰ K) = 0 := by have h1 : (1 : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑(1 : Ideal R) := by rw [(algebraMap R K).map_one, Ideal.one_eq_top, coeIdeal_top, mul_one, inv_one, spanSingleton_one] rw [count_well_defined K v one_ne_zero h1, Ideal.span_singleton_one, Ideal.one_eq_top, sub_self] theorem count_prod {ΞΉ} (s : Finset ΞΉ) (I : ΞΉ β†’ FractionalIdeal R⁰ K) (hS : βˆ€ i ∈ s, I i β‰  0) : count K v (∏ i ∈ s, I i) = βˆ‘ i ∈ s, count K v (I i) := by classical induction' s using Finset.induction with i s hi hrec Β· rw [Finset.prod_empty, Finset.sum_empty, count_one] Β· have hS' : βˆ€ i ∈ s, I i β‰  0 := fun j hj => hS j (Finset.mem_insert_of_mem hj) have hS0 : ∏ i ∈ s, I i β‰  0 := Finset.prod_ne_zero_iff.mpr hS' have hi0 : I i β‰  0 := hS i (Finset.mem_insert_self i s) rw [Finset.prod_insert hi, Finset.sum_insert hi, count_mul K v hi0 hS0, hrec hS'] /-- For every `n ∈ β„•` and every ideal `I`, `val_v(I^n) = n*val_v(I)`. -/ theorem count_pow (n : β„•) (I : FractionalIdeal R⁰ K) : count K v (I ^ n) = n * count K v I := by induction' n with n h Β· rw [pow_zero, ofNat_zero, MulZeroClass.zero_mul, count_one] Β· classical rw [pow_succ, count_mul'] by_cases hI : I = 0 Β· have h_neg : Β¬(I ^ n β‰  0 ∧ I β‰  0) := by rw [not_and', not_not, ne_eq] intro h exact absurd hI h rw [if_neg h_neg, hI, count_zero, MulZeroClass.mul_zero] Β· rw [if_pos (And.intro (pow_ne_zero n hI) hI), h, Nat.cast_add, Nat.cast_one] ring /-- `val_v(v) = 1`, when `v` is regarded as a fractional ideal. -/ theorem count_self : count K v (v.asIdeal : FractionalIdeal R⁰ K) = 1 := by have hv : (v.asIdeal : FractionalIdeal R⁰ K) β‰  0 := coeIdeal_ne_zero.mpr v.ne_bot have h_self : (v.asIdeal : FractionalIdeal R⁰ K) = spanSingleton R⁰ ((algebraMap R K) 1)⁻¹ * ↑v.asIdeal := by rw [(algebraMap R K).map_one, inv_one, spanSingleton_one, one_mul] have hv_irred : Irreducible (Associates.mk v.asIdeal) := by apply v.associates_irreducible classical rw [count_well_defined K v hv h_self, Associates.count_self hv_irred, Ideal.span_singleton_one, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero hv_irred, ofNat_zero, sub_zero, ofNat_one] /-- `val_v(v^n) = n` for every `n ∈ β„•`. -/
Mathlib/RingTheory/DedekindDomain/Factorization.lean
412
420
theorem count_pow_self (n : β„•) : count K v ((v.asIdeal : FractionalIdeal R⁰ K) ^ n) = n := by
rw [count_pow, count_self, mul_one] /-- `val_v(I⁻ⁿ) = -val_v(Iⁿ)` for every `n ∈ β„€`. -/ theorem count_neg_zpow (n : β„€) (I : FractionalIdeal R⁰ K) : count K v (I ^ (-n)) = - count K v (I ^ n) := by by_cases hI : I = 0 Β· by_cases hn : n = 0
/- Copyright (c) 2022 Damiano Testa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Damiano Testa -/ import Mathlib.Algebra.Group.Embedding import Mathlib.Algebra.MonoidAlgebra.Defs import Mathlib.LinearAlgebra.Finsupp.Supported import Mathlib.Algebra.Group.Pointwise.Finset.Basic /-! # Lemmas about the support of a finitely supported function -/ open scoped Pointwise universe u₁ uβ‚‚ u₃ namespace MonoidAlgebra open Finset Finsupp variable {k : Type u₁} {G : Type uβ‚‚} [Semiring k]
Mathlib/Algebra/MonoidAlgebra/Support.lean
25
30
theorem support_mul [Mul G] [DecidableEq G] (a b : MonoidAlgebra k G) : (a * b).support βŠ† a.support * b.support := by
rw [MonoidAlgebra.mul_def] exact support_sum.trans <| biUnion_subset.2 fun _x hx ↦ support_sum.trans <| biUnion_subset.2 fun _y hy ↦ support_single_subset.trans <| singleton_subset_iff.2 <| mem_imageβ‚‚_of_mem hx hy
/- Copyright (c) 2021 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Data.Nat.Factorial.Basic import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Set.Finite.Range import Mathlib.Logic.Equiv.Embedding /-! # Number of embeddings This file establishes the cardinality of `Ξ± β†ͺ Ξ²` in full generality. -/ local notation "|" x "|" => Finset.card x local notation "β€–" x "β€–" => Fintype.card x open Function open Nat namespace Fintype theorem card_embedding_eq_of_unique {Ξ± Ξ² : Type*} [Unique Ξ±] [Fintype Ξ²] [Fintype (Ξ± β†ͺ Ξ²)] : β€–Ξ± β†ͺ Ξ²β€– = β€–Ξ²β€– := card_congr Equiv.uniqueEmbeddingEquivResult -- Establishes the cardinality of the type of all injections between two finite types. -- Porting note: `induction Ξ± using Fintype.induction_empty_option` can't work with the `Fintype Ξ±` -- instance so instead we make an ugly refine and `dsimp` a lot. @[simp]
Mathlib/Data/Fintype/CardEmbedding.lean
36
50
theorem card_embedding_eq {Ξ± Ξ² : Type*} [Fintype Ξ±] [Fintype Ξ²] [emb : Fintype (Ξ± β†ͺ Ξ²)] : β€–Ξ± β†ͺ Ξ²β€– = β€–Ξ²β€–.descFactorial β€–Ξ±β€– := by
rw [Subsingleton.elim emb Embedding.fintype] refine Fintype.induction_empty_option (P := fun t ↦ β€–t β†ͺ Ξ²β€– = β€–Ξ²β€–.descFactorial β€–tβ€–) (fun α₁ Ξ±β‚‚ hβ‚‚ e ih ↦ ?_) (?_) (fun Ξ³ h ih ↦ ?_) Ξ± <;> dsimp only at * <;> clear! Ξ± Β· letI := Fintype.ofEquiv _ e.symm rw [← card_congr (Equiv.embeddingCongr e (Equiv.refl Ξ²)), ih, card_congr e] Β· rw [card_pempty, Nat.descFactorial_zero, card_eq_one_iff] exact ⟨Embedding.ofIsEmpty, fun x ↦ DFunLike.ext _ _ isEmptyElim⟩ Β· classical rw [card_option, Nat.descFactorial_succ, card_congr (Embedding.optionEmbeddingEquiv Ξ³ Ξ²), card_sigma, ← ih] simp only [Fintype.card_compl_set, Fintype.card_range, Finset.sum_const, Finset.card_univ, Nat.nsmul_eq_mul, mul_comm]
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.BigOperators.Group.Finset.Indicator import Mathlib.Algebra.Module.BigOperators import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Basic import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.Tactic.FinCases /-! # Affine combinations of points This file defines affine combinations of points. ## Main definitions * `weightedVSubOfPoint` is a general weighted combination of subtractions with an explicit base point, yielding a vector. * `weightedVSub` uses an arbitrary choice of base point and is intended to be used when the sum of weights is 0, in which case the result is independent of the choice of base point. * `affineCombination` adds the weighted combination to the arbitrary base point, yielding a point rather than a vector, and is intended to be used when the sum of weights is 1, in which case the result is independent of the choice of base point. These definitions are for sums over a `Finset`; versions for a `Fintype` may be obtained using `Finset.univ`, while versions for a `Finsupp` may be obtained using `Finsupp.support`. ## References * https://en.wikipedia.org/wiki/Affine_space -/ noncomputable section open Affine namespace Finset theorem univ_fin2 : (univ : Finset (Fin 2)) = {0, 1} := by ext x fin_cases x <;> simp variable {k : Type*} {V : Type*} {P : Type*} [Ring k] [AddCommGroup V] [Module k V] variable [S : AffineSpace V P] variable {ΞΉ : Type*} (s : Finset ΞΉ) variable {ΞΉβ‚‚ : Type*} (sβ‚‚ : Finset ΞΉβ‚‚) /-- A weighted sum of the results of subtracting a base point from the given points, as a linear map on the weights. The main cases of interest are where the sum of the weights is 0, in which case the sum is independent of the choice of base point, and where the sum of the weights is 1, in which case the sum added to the base point is independent of the choice of base point. -/ def weightedVSubOfPoint (p : ΞΉ β†’ P) (b : P) : (ΞΉ β†’ k) β†’β‚—[k] V := βˆ‘ i ∈ s, (LinearMap.proj i : (ΞΉ β†’ k) β†’β‚—[k] k).smulRight (p i -α΅₯ b) @[simp] theorem weightedVSubOfPoint_apply (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) : s.weightedVSubOfPoint p b w = βˆ‘ i ∈ s, w i β€’ (p i -α΅₯ b) := by simp [weightedVSubOfPoint, LinearMap.sum_apply] /-- The value of `weightedVSubOfPoint`, where the given points are equal. -/ @[simp (high)] theorem weightedVSubOfPoint_apply_const (w : ΞΉ β†’ k) (p : P) (b : P) : s.weightedVSubOfPoint (fun _ => p) b w = (βˆ‘ i ∈ s, w i) β€’ (p -α΅₯ b) := by rw [weightedVSubOfPoint_apply, sum_smul] lemma weightedVSubOfPoint_vadd (s : Finset ΞΉ) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) (v : V) : s.weightedVSubOfPoint (v +α΅₯ p) b w = s.weightedVSubOfPoint p (-v +α΅₯ b) w := by simp [vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, add_comm] lemma weightedVSubOfPoint_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] (s : Finset ΞΉ) (w : ΞΉ β†’ k) (p : ΞΉ β†’ V) (b : V) (a : G) : s.weightedVSubOfPoint (a β€’ p) b w = a β€’ s.weightedVSubOfPoint p (a⁻¹ β€’ b) w := by simp [smul_sum, smul_sub, smul_comm a (w _)] /-- `weightedVSubOfPoint` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSubOfPoint_congr {w₁ wβ‚‚ : ΞΉ β†’ k} (hw : βˆ€ i ∈ s, w₁ i = wβ‚‚ i) {p₁ pβ‚‚ : ΞΉ β†’ P} (hp : βˆ€ i ∈ s, p₁ i = pβ‚‚ i) (b : P) : s.weightedVSubOfPoint p₁ b w₁ = s.weightedVSubOfPoint pβ‚‚ b wβ‚‚ := by simp_rw [weightedVSubOfPoint_apply] refine sum_congr rfl fun i hi => ?_ rw [hw i hi, hp i hi] /-- Given a family of points, if we use a member of the family as a base point, the `weightedVSubOfPoint` does not depend on the value of the weights at this point. -/ theorem weightedVSubOfPoint_eq_of_weights_eq (p : ΞΉ β†’ P) (j : ΞΉ) (w₁ wβ‚‚ : ΞΉ β†’ k) (hw : βˆ€ i, i β‰  j β†’ w₁ i = wβ‚‚ i) : s.weightedVSubOfPoint p (p j) w₁ = s.weightedVSubOfPoint p (p j) wβ‚‚ := by simp only [Finset.weightedVSubOfPoint_apply] congr ext i rcases eq_or_ne i j with h | h Β· simp [h] Β· simp [hw i h] /-- The weighted sum is independent of the base point when the sum of the weights is 0. -/ theorem weightedVSubOfPoint_eq_of_sum_eq_zero (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (h : βˆ‘ i ∈ s, w i = 0) (b₁ bβ‚‚ : P) : s.weightedVSubOfPoint p b₁ w = s.weightedVSubOfPoint p bβ‚‚ w := by apply eq_of_sub_eq_zero rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_sub_distrib] conv_lhs => congr Β· skip Β· ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, zero_smul] /-- The weighted sum, added to the base point, is independent of the base point when the sum of the weights is 1. -/ theorem weightedVSubOfPoint_vadd_eq_of_sum_eq_one (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (h : βˆ‘ i ∈ s, w i = 1) (b₁ bβ‚‚ : P) : s.weightedVSubOfPoint p b₁ w +α΅₯ b₁ = s.weightedVSubOfPoint p bβ‚‚ w +α΅₯ bβ‚‚ := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← @vsub_eq_zero_iff_eq V, vadd_vsub_assoc, vsub_vadd_eq_vsub_sub, ← add_sub_assoc, add_comm, add_sub_assoc, ← sum_sub_distrib] conv_lhs => congr Β· skip Β· congr Β· skip Β· ext rw [← smul_sub, vsub_sub_vsub_cancel_left] rw [← sum_smul, h, one_smul, vsub_add_vsub_cancel, vsub_self] /-- The weighted sum is unaffected by removing the base point, if present, from the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_erase [DecidableEq ΞΉ] (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (i : ΞΉ) : (s.erase i).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_erase rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by adding the base point, whether or not present, to the set of points. -/ @[simp (high)] theorem weightedVSubOfPoint_insert [DecidableEq ΞΉ] (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (i : ΞΉ) : (insert i s).weightedVSubOfPoint p (p i) w = s.weightedVSubOfPoint p (p i) w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] apply sum_insert_zero rw [vsub_self, smul_zero] /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSubOfPoint_indicator_subset (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) {s₁ sβ‚‚ : Finset ΞΉ} (h : s₁ βŠ† sβ‚‚) : s₁.weightedVSubOfPoint p b w = sβ‚‚.weightedVSubOfPoint p b (Set.indicator (↑s₁) w) := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply] exact Eq.symm <| sum_indicator_subset_of_eq_zero w (fun i wi => wi β€’ (p i -α΅₯ b : V)) h fun i => zero_smul k _ /-- A weighted sum, over the image of an embedding, equals a weighted sum with the same points and weights over the original `Finset`. -/ theorem weightedVSubOfPoint_map (e : ΞΉβ‚‚ β†ͺ ΞΉ) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) : (sβ‚‚.map e).weightedVSubOfPoint p b w = sβ‚‚.weightedVSubOfPoint (p ∘ e) b (w ∘ e) := by simp_rw [weightedVSubOfPoint_apply] exact Finset.sum_map _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSubOfPoint` expressions. -/ theorem sum_smul_vsub_eq_weightedVSubOfPoint_sub (w : ΞΉ β†’ k) (p₁ pβ‚‚ : ΞΉ β†’ P) (b : P) : (βˆ‘ i ∈ s, w i β€’ (p₁ i -α΅₯ pβ‚‚ i)) = s.weightedVSubOfPoint p₁ b w - s.weightedVSubOfPoint pβ‚‚ b w := by simp_rw [weightedVSubOfPoint_apply, ← sum_sub_distrib, ← smul_sub, vsub_sub_vsub_cancel_right] /-- A weighted sum of pairwise subtractions, where the point on the right is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_vsub_const_eq_weightedVSubOfPoint_sub (w : ΞΉ β†’ k) (p₁ : ΞΉ β†’ P) (pβ‚‚ b : P) : (βˆ‘ i ∈ s, w i β€’ (p₁ i -α΅₯ pβ‚‚)) = s.weightedVSubOfPoint p₁ b w - (βˆ‘ i ∈ s, w i) β€’ (pβ‚‚ -α΅₯ b) := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum of pairwise subtractions, where the point on the left is constant, expressed as a subtraction involving a `weightedVSubOfPoint` expression. -/ theorem sum_smul_const_vsub_eq_sub_weightedVSubOfPoint (w : ΞΉ β†’ k) (pβ‚‚ : ΞΉ β†’ P) (p₁ b : P) : (βˆ‘ i ∈ s, w i β€’ (p₁ -α΅₯ pβ‚‚ i)) = (βˆ‘ i ∈ s, w i) β€’ (p₁ -α΅₯ b) - s.weightedVSubOfPoint pβ‚‚ b w := by rw [sum_smul_vsub_eq_weightedVSubOfPoint_sub, weightedVSubOfPoint_apply_const] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff [DecidableEq ΞΉ] {sβ‚‚ : Finset ΞΉ} (h : sβ‚‚ βŠ† s) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) : (s \ sβ‚‚).weightedVSubOfPoint p b w + sβ‚‚.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, sum_sdiff h] /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSubOfPoint_sdiff_sub [DecidableEq ΞΉ] {sβ‚‚ : Finset ΞΉ} (h : sβ‚‚ βŠ† s) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) : (s \ sβ‚‚).weightedVSubOfPoint p b w - sβ‚‚.weightedVSubOfPoint p b (-w) = s.weightedVSubOfPoint p b w := by rw [map_neg, sub_neg_eq_add, s.weightedVSubOfPoint_sdiff h] /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSubOfPoint_subtype_eq_filter (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) (pred : ΞΉ β†’ Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSubOfPoint (fun i => p i) b fun i => w i) = {x ∈ s | pred x}.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, ← sum_subtype_eq_sum_filter] /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSubOfPoint_filter_of_ne (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) {pred : ΞΉ β†’ Prop} [DecidablePred pred] (h : βˆ€ i ∈ s, w i β‰  0 β†’ pred i) : {x ∈ s | pred x}.weightedVSubOfPoint p b w = s.weightedVSubOfPoint p b w := by rw [weightedVSubOfPoint_apply, weightedVSubOfPoint_apply, sum_filter_of_ne] intro i hi hne refine h i hi ?_ intro hw simp [hw] at hne /-- A constant multiplier of the weights in `weightedVSubOfPoint` may be moved outside the sum. -/ theorem weightedVSubOfPoint_const_smul (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (b : P) (c : k) : s.weightedVSubOfPoint p b (c β€’ w) = c β€’ s.weightedVSubOfPoint p b w := by simp_rw [weightedVSubOfPoint_apply, smul_sum, Pi.smul_apply, smul_smul, smul_eq_mul] /-- A weighted sum of the results of subtracting a default base point from the given points, as a linear map on the weights. This is intended to be used when the sum of the weights is 0; that condition is specified as a hypothesis on those lemmas that require it. -/ def weightedVSub (p : ΞΉ β†’ P) : (ΞΉ β†’ k) β†’β‚—[k] V := s.weightedVSubOfPoint p (Classical.choice S.nonempty) /-- Applying `weightedVSub` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `weightedVSub` would involve selecting a preferred base point with `weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero` and then using `weightedVSubOfPoint_apply`. -/ theorem weightedVSub_apply (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : s.weightedVSub p w = βˆ‘ i ∈ s, w i β€’ (p i -α΅₯ Classical.choice S.nonempty) := by simp [weightedVSub, LinearMap.sum_apply] /-- `weightedVSub` gives the sum of the results of subtracting any base point, when the sum of the weights is 0. -/ theorem weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (h : βˆ‘ i ∈ s, w i = 0) (b : P) : s.weightedVSub p w = s.weightedVSubOfPoint p b w := s.weightedVSubOfPoint_eq_of_sum_eq_zero w p h _ _ /-- The value of `weightedVSub`, where the given points are equal and the sum of the weights is 0. -/ @[simp] theorem weightedVSub_apply_const (w : ΞΉ β†’ k) (p : P) (h : βˆ‘ i ∈ s, w i = 0) : s.weightedVSub (fun _ => p) w = 0 := by rw [weightedVSub, weightedVSubOfPoint_apply_const, h, zero_smul] /-- The `weightedVSub` for an empty set is 0. -/ @[simp] theorem weightedVSub_empty (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (βˆ… : Finset ΞΉ).weightedVSub p w = (0 : V) := by simp [weightedVSub_apply] lemma weightedVSub_vadd {s : Finset ΞΉ} {w : ΞΉ β†’ k} (h : βˆ‘ i ∈ s, w i = 0) (p : ΞΉ β†’ P) (v : V) : s.weightedVSub (v +α΅₯ p) w = s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_vadd, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] lemma weightedVSub_smul {G : Type*} [Group G] [DistribMulAction G V] [SMulCommClass G k V] {s : Finset ΞΉ} {w : ΞΉ β†’ k} (h : βˆ‘ i ∈ s, w i = 0) (p : ΞΉ β†’ V) (a : G) : s.weightedVSub (a β€’ p) w = a β€’ s.weightedVSub p w := by rw [weightedVSub, weightedVSubOfPoint_smul, weightedVSub_eq_weightedVSubOfPoint_of_sum_eq_zero _ _ _ h] /-- `weightedVSub` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem weightedVSub_congr {w₁ wβ‚‚ : ΞΉ β†’ k} (hw : βˆ€ i ∈ s, w₁ i = wβ‚‚ i) {p₁ pβ‚‚ : ΞΉ β†’ P} (hp : βˆ€ i ∈ s, p₁ i = pβ‚‚ i) : s.weightedVSub p₁ w₁ = s.weightedVSub pβ‚‚ wβ‚‚ := s.weightedVSubOfPoint_congr hw hp _ /-- The weighted sum is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem weightedVSub_indicator_subset (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) {s₁ sβ‚‚ : Finset ΞΉ} (h : s₁ βŠ† sβ‚‚) : s₁.weightedVSub p w = sβ‚‚.weightedVSub p (Set.indicator (↑s₁) w) := weightedVSubOfPoint_indicator_subset _ _ _ h /-- A weighted subtraction, over the image of an embedding, equals a weighted subtraction with the same points and weights over the original `Finset`. -/ theorem weightedVSub_map (e : ΞΉβ‚‚ β†ͺ ΞΉ) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (sβ‚‚.map e).weightedVSub p w = sβ‚‚.weightedVSub (p ∘ e) (w ∘ e) := sβ‚‚.weightedVSubOfPoint_map _ _ _ _ /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `weightedVSub` expressions. -/ theorem sum_smul_vsub_eq_weightedVSub_sub (w : ΞΉ β†’ k) (p₁ pβ‚‚ : ΞΉ β†’ P) : (βˆ‘ i ∈ s, w i β€’ (p₁ i -α΅₯ pβ‚‚ i)) = s.weightedVSub p₁ w - s.weightedVSub pβ‚‚ w := s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 0. -/ theorem sum_smul_vsub_const_eq_weightedVSub (w : ΞΉ β†’ k) (p₁ : ΞΉ β†’ P) (pβ‚‚ : P) (h : βˆ‘ i ∈ s, w i = 0) : (βˆ‘ i ∈ s, w i β€’ (p₁ i -α΅₯ pβ‚‚)) = s.weightedVSub p₁ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, sub_zero] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 0. -/ theorem sum_smul_const_vsub_eq_neg_weightedVSub (w : ΞΉ β†’ k) (pβ‚‚ : ΞΉ β†’ P) (p₁ : P) (h : βˆ‘ i ∈ s, w i = 0) : (βˆ‘ i ∈ s, w i β€’ (p₁ -α΅₯ pβ‚‚ i)) = -s.weightedVSub pβ‚‚ w := by rw [sum_smul_vsub_eq_weightedVSub_sub, s.weightedVSub_apply_const _ _ h, zero_sub] /-- A weighted sum may be split into such sums over two subsets. -/ theorem weightedVSub_sdiff [DecidableEq ΞΉ] {sβ‚‚ : Finset ΞΉ} (h : sβ‚‚ βŠ† s) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (s \ sβ‚‚).weightedVSub p w + sβ‚‚.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff h _ _ _ /-- A weighted sum may be split into a subtraction of such sums over two subsets. -/ theorem weightedVSub_sdiff_sub [DecidableEq ΞΉ] {sβ‚‚ : Finset ΞΉ} (h : sβ‚‚ βŠ† s) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (s \ sβ‚‚).weightedVSub p w - sβ‚‚.weightedVSub p (-w) = s.weightedVSub p w := s.weightedVSubOfPoint_sdiff_sub h _ _ _ /-- A weighted sum over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem weightedVSub_subtype_eq_filter (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (pred : ΞΉ β†’ Prop) [DecidablePred pred] : ((s.subtype pred).weightedVSub (fun i => p i) fun i => w i) = {x ∈ s | pred x}.weightedVSub p w := s.weightedVSubOfPoint_subtype_eq_filter _ _ _ _ /-- A weighted sum over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem weightedVSub_filter_of_ne (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) {pred : ΞΉ β†’ Prop} [DecidablePred pred] (h : βˆ€ i ∈ s, w i β‰  0 β†’ pred i) : {x ∈ s | pred x}.weightedVSub p w = s.weightedVSub p w := s.weightedVSubOfPoint_filter_of_ne _ _ _ h /-- A constant multiplier of the weights in `weightedVSub_of` may be moved outside the sum. -/ theorem weightedVSub_const_smul (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (c : k) : s.weightedVSub p (c β€’ w) = c β€’ s.weightedVSub p w := s.weightedVSubOfPoint_const_smul _ _ _ _ instance : AffineSpace (ΞΉ β†’ k) (ΞΉ β†’ k) := Pi.instAddTorsor variable (k) /-- A weighted sum of the results of subtracting a default base point from the given points, added to that base point, as an affine map on the weights. This is intended to be used when the sum of the weights is 1, in which case it is an affine combination (barycenter) of the points with the given weights; that condition is specified as a hypothesis on those lemmas that require it. -/ def affineCombination (p : ΞΉ β†’ P) : (ΞΉ β†’ k) →ᡃ[k] P where toFun w := s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +α΅₯ Classical.choice S.nonempty linear := s.weightedVSub p map_vadd' w₁ wβ‚‚ := by simp_rw [vadd_vadd, weightedVSub, vadd_eq_add, LinearMap.map_add] /-- The linear map corresponding to `affineCombination` is `weightedVSub`. -/ @[simp] theorem affineCombination_linear (p : ΞΉ β†’ P) : (s.affineCombination k p).linear = s.weightedVSub p := rfl variable {k} /-- Applying `affineCombination` with given weights. This is for the case where a result involving a default base point is OK (for example, when that base point will cancel out later); a more typical use case for `affineCombination` would involve selecting a preferred base point with `affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one` and then using `weightedVSubOfPoint_apply`. -/ theorem affineCombination_apply (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (s.affineCombination k p) w = s.weightedVSubOfPoint p (Classical.choice S.nonempty) w +α΅₯ Classical.choice S.nonempty := rfl /-- The value of `affineCombination`, where the given points are equal. -/ @[simp] theorem affineCombination_apply_const (w : ΞΉ β†’ k) (p : P) (h : βˆ‘ i ∈ s, w i = 1) : s.affineCombination k (fun _ => p) w = p := by rw [affineCombination_apply, s.weightedVSubOfPoint_apply_const, h, one_smul, vsub_vadd] /-- `affineCombination` gives equal results for two families of weights and two families of points that are equal on `s`. -/ theorem affineCombination_congr {w₁ wβ‚‚ : ΞΉ β†’ k} (hw : βˆ€ i ∈ s, w₁ i = wβ‚‚ i) {p₁ pβ‚‚ : ΞΉ β†’ P} (hp : βˆ€ i ∈ s, p₁ i = pβ‚‚ i) : s.affineCombination k p₁ w₁ = s.affineCombination k pβ‚‚ wβ‚‚ := by simp_rw [affineCombination_apply, s.weightedVSubOfPoint_congr hw hp] /-- `affineCombination` gives the sum with any base point, when the sum of the weights is 1. -/ theorem affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (h : βˆ‘ i ∈ s, w i = 1) (b : P) : s.affineCombination k p w = s.weightedVSubOfPoint p b w +α΅₯ b := s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w p h _ _ /-- Adding a `weightedVSub` to an `affineCombination`. -/ theorem weightedVSub_vadd_affineCombination (w₁ wβ‚‚ : ΞΉ β†’ k) (p : ΞΉ β†’ P) : s.weightedVSub p w₁ +α΅₯ s.affineCombination k p wβ‚‚ = s.affineCombination k p (w₁ + wβ‚‚) := by rw [← vadd_eq_add, AffineMap.map_vadd, affineCombination_linear] /-- Subtracting two `affineCombination`s. -/ theorem affineCombination_vsub (w₁ wβ‚‚ : ΞΉ β†’ k) (p : ΞΉ β†’ P) : s.affineCombination k p w₁ -α΅₯ s.affineCombination k p wβ‚‚ = s.weightedVSub p (w₁ - wβ‚‚) := by rw [← AffineMap.linearMap_vsub, affineCombination_linear, vsub_eq_sub] theorem attach_affineCombination_of_injective [DecidableEq P] (s : Finset P) (w : P β†’ k) (f : s β†’ P) (hf : Function.Injective f) : s.attach.affineCombination k f (w ∘ f) = (image f univ).affineCombination k id w := by simp only [affineCombination, weightedVSubOfPoint_apply, id, vadd_right_cancel_iff, Function.comp_apply, AffineMap.coe_mk] let g₁ : s β†’ V := fun i => w (f i) β€’ (f i -α΅₯ Classical.choice S.nonempty) let gβ‚‚ : P β†’ V := fun i => w i β€’ (i -α΅₯ Classical.choice S.nonempty) change univ.sum g₁ = (image f univ).sum gβ‚‚ have hgf : g₁ = gβ‚‚ ∘ f := by ext simp [g₁, gβ‚‚] rw [hgf, sum_image] Β· simp only [g₁, gβ‚‚,Function.comp_apply] Β· exact fun _ _ _ _ hxy => hf hxy theorem attach_affineCombination_coe (s : Finset P) (w : P β†’ k) : s.attach.affineCombination k ((↑) : s β†’ P) (w ∘ (↑)) = s.affineCombination k id w := by classical rw [attach_affineCombination_of_injective s w ((↑) : s β†’ P) Subtype.coe_injective, univ_eq_attach, attach_image_val] /-- Viewing a module as an affine space modelled on itself, a `weightedVSub` is just a linear combination. -/ @[simp] theorem weightedVSub_eq_linear_combination {ΞΉ} (s : Finset ΞΉ) {w : ΞΉ β†’ k} {p : ΞΉ β†’ V} (hw : s.sum w = 0) : s.weightedVSub p w = βˆ‘ i ∈ s, w i β€’ p i := by simp [s.weightedVSub_apply, vsub_eq_sub, smul_sub, ← Finset.sum_smul, hw] /-- Viewing a module as an affine space modelled on itself, affine combinations are just linear combinations. -/ @[simp] theorem affineCombination_eq_linear_combination (s : Finset ΞΉ) (p : ΞΉ β†’ V) (w : ΞΉ β†’ k) (hw : βˆ‘ i ∈ s, w i = 1) : s.affineCombination k p w = βˆ‘ i ∈ s, w i β€’ p i := by simp [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw 0] /-- An `affineCombination` equals a point if that point is in the set and has weight 1 and the other points in the set have weight 0. -/ @[simp] theorem affineCombination_of_eq_one_of_eq_zero (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) {i : ΞΉ} (his : i ∈ s) (hwi : w i = 1) (hw0 : βˆ€ i2 ∈ s, i2 β‰  i β†’ w i2 = 0) : s.affineCombination k p w = p i := by have h1 : βˆ‘ i ∈ s, w i = 1 := hwi β–Έ sum_eq_single i hw0 fun h => False.elim (h his) rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h1 (p i), weightedVSubOfPoint_apply] convert zero_vadd V (p i) refine sum_eq_zero ?_ intro i2 hi2 by_cases h : i2 = i Β· simp [h] Β· simp [hw0 i2 hi2 h] /-- An affine combination is unaffected by changing the weights to the corresponding indicator function and adding points to the set. -/ theorem affineCombination_indicator_subset (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) {s₁ sβ‚‚ : Finset ΞΉ} (h : s₁ βŠ† sβ‚‚) : s₁.affineCombination k p w = sβ‚‚.affineCombination k p (Set.indicator (↑s₁) w) := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_indicator_subset _ _ _ h] /-- An affine combination, over the image of an embedding, equals an affine combination with the same points and weights over the original `Finset`. -/ theorem affineCombination_map (e : ΞΉβ‚‚ β†ͺ ΞΉ) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (sβ‚‚.map e).affineCombination k p w = sβ‚‚.affineCombination k (p ∘ e) (w ∘ e) := by simp_rw [affineCombination_apply, weightedVSubOfPoint_map] /-- A weighted sum of pairwise subtractions, expressed as a subtraction of two `affineCombination` expressions. -/ theorem sum_smul_vsub_eq_affineCombination_vsub (w : ΞΉ β†’ k) (p₁ pβ‚‚ : ΞΉ β†’ P) : (βˆ‘ i ∈ s, w i β€’ (p₁ i -α΅₯ pβ‚‚ i)) = s.affineCombination k p₁ w -α΅₯ s.affineCombination k pβ‚‚ w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.sum_smul_vsub_eq_weightedVSubOfPoint_sub _ _ _ _ /-- A weighted sum of pairwise subtractions, where the point on the right is constant and the sum of the weights is 1. -/ theorem sum_smul_vsub_const_eq_affineCombination_vsub (w : ΞΉ β†’ k) (p₁ : ΞΉ β†’ P) (pβ‚‚ : P) (h : βˆ‘ i ∈ s, w i = 1) : (βˆ‘ i ∈ s, w i β€’ (p₁ i -α΅₯ pβ‚‚)) = s.affineCombination k p₁ w -α΅₯ pβ‚‚ := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum of pairwise subtractions, where the point on the left is constant and the sum of the weights is 1. -/ theorem sum_smul_const_vsub_eq_vsub_affineCombination (w : ΞΉ β†’ k) (pβ‚‚ : ΞΉ β†’ P) (p₁ : P) (h : βˆ‘ i ∈ s, w i = 1) : (βˆ‘ i ∈ s, w i β€’ (p₁ -α΅₯ pβ‚‚ i)) = p₁ -α΅₯ s.affineCombination k pβ‚‚ w := by rw [sum_smul_vsub_eq_affineCombination_vsub, affineCombination_apply_const _ _ _ h] /-- A weighted sum may be split into a subtraction of affine combinations over two subsets. -/ theorem affineCombination_sdiff_sub [DecidableEq ΞΉ] {sβ‚‚ : Finset ΞΉ} (h : sβ‚‚ βŠ† s) (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) : (s \ sβ‚‚).affineCombination k p w -α΅₯ sβ‚‚.affineCombination k p (-w) = s.weightedVSub p w := by simp_rw [affineCombination_apply, vadd_vsub_vadd_cancel_right] exact s.weightedVSub_sdiff_sub h _ _ /-- If a weighted sum is zero and one of the weights is `-1`, the corresponding point is the affine combination of the other points with the given weights. -/ theorem affineCombination_eq_of_weightedVSub_eq_zero_of_eq_neg_one {w : ΞΉ β†’ k} {p : ΞΉ β†’ P} (hw : s.weightedVSub p w = (0 : V)) {i : ΞΉ} [DecidablePred (Β· β‰  i)] (his : i ∈ s) (hwi : w i = -1) : {x ∈ s | x β‰  i}.affineCombination k p w = p i := by classical rw [← @vsub_eq_zero_iff_eq V, ← hw, ← s.affineCombination_sdiff_sub (singleton_subset_iff.2 his), sdiff_singleton_eq_erase, ← filter_ne'] congr refine (affineCombination_of_eq_one_of_eq_zero _ _ _ (mem_singleton_self _) ?_ ?_).symm Β· simp [hwi] Β· simp /-- An affine combination over `s.subtype pred` equals one over `{x ∈ s | pred x}`. -/ theorem affineCombination_subtype_eq_filter (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (pred : ΞΉ β†’ Prop) [DecidablePred pred] : ((s.subtype pred).affineCombination k (fun i => p i) fun i => w i) = {x ∈ s | pred x}.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, weightedVSubOfPoint_subtype_eq_filter] /-- An affine combination over `{x ∈ s | pred x}` equals one over `s` if all the weights at indices in `s` not satisfying `pred` are zero. -/ theorem affineCombination_filter_of_ne (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) {pred : ΞΉ β†’ Prop} [DecidablePred pred] (h : βˆ€ i ∈ s, w i β‰  0 β†’ pred i) : {x ∈ s | pred x}.affineCombination k p w = s.affineCombination k p w := by rw [affineCombination_apply, affineCombination_apply, s.weightedVSubOfPoint_filter_of_ne _ _ _ h] /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSubOfPoint` using a `Finset` lying within that subset and with a given sum of weights if and only if it can be expressed as `weightedVSubOfPoint` with that sum of weights for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype {v : V} {x : k} {s : Set ΞΉ} {p : ΞΉ β†’ P} {b : P} : (βˆƒ fs : Finset ΞΉ, ↑fs βŠ† s ∧ βˆƒ w : ΞΉ β†’ k, βˆ‘ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint p b w) ↔ βˆƒ (fs : Finset s) (w : s β†’ k), βˆ‘ i ∈ fs, w i = x ∧ v = fs.weightedVSubOfPoint (fun i : s => p i) b w := by classical simp_rw [weightedVSubOfPoint_apply] constructor Β· rintro ⟨fs, hfs, w, rfl, rfl⟩ exact ⟨fs.subtype s, fun i => w i, sum_subtype_of_mem _ hfs, (sum_subtype_of_mem _ hfs).symm⟩ Β· rintro ⟨fs, w, rfl, rfl⟩ refine ⟨fs.map (Function.Embedding.subtype _), map_subtype_subset _, fun i => if h : i ∈ s then w ⟨i, h⟩ else 0, ?_, ?_⟩ <;> simp variable (k) /-- Suppose an indexed family of points is given, along with a subset of the index type. A vector can be expressed as `weightedVSub` using a `Finset` lying within that subset and with sum of weights 0 if and only if it can be expressed as `weightedVSub` with sum of weights 0 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_weightedVSub_subset_iff_eq_weightedVSub_subtype {v : V} {s : Set ΞΉ} {p : ΞΉ β†’ P} : (βˆƒ fs : Finset ΞΉ, ↑fs βŠ† s ∧ βˆƒ w : ΞΉ β†’ k, βˆ‘ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub p w) ↔ βˆƒ (fs : Finset s) (w : s β†’ k), βˆ‘ i ∈ fs, w i = 0 ∧ v = fs.weightedVSub (fun i : s => p i) w := eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable (V) /-- Suppose an indexed family of points is given, along with a subset of the index type. A point can be expressed as an `affineCombination` using a `Finset` lying within that subset and with sum of weights 1 if and only if it can be expressed an `affineCombination` with sum of weights 1 for the corresponding indexed family whose index type is the subtype corresponding to that subset. -/ theorem eq_affineCombination_subset_iff_eq_affineCombination_subtype {p0 : P} {s : Set ΞΉ} {p : ΞΉ β†’ P} : (βˆƒ fs : Finset ΞΉ, ↑fs βŠ† s ∧ βˆƒ w : ΞΉ β†’ k, βˆ‘ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k p w) ↔ βˆƒ (fs : Finset s) (w : s β†’ k), βˆ‘ i ∈ fs, w i = 1 ∧ p0 = fs.affineCombination k (fun i : s => p i) w := by simp_rw [affineCombination_apply, eq_vadd_iff_vsub_eq] exact eq_weightedVSubOfPoint_subset_iff_eq_weightedVSubOfPoint_subtype variable {k V} /-- Affine maps commute with affine combinations. -/ theorem map_affineCombination {Vβ‚‚ Pβ‚‚ : Type*} [AddCommGroup Vβ‚‚] [Module k Vβ‚‚] [AffineSpace Vβ‚‚ Pβ‚‚] (p : ΞΉ β†’ P) (w : ΞΉ β†’ k) (hw : s.sum w = 1) (f : P →ᡃ[k] Pβ‚‚) : f (s.affineCombination k p w) = s.affineCombination k (f ∘ p) w := by have b := Classical.choice (inferInstance : AffineSpace V P).nonempty have bβ‚‚ := Classical.choice (inferInstance : AffineSpace Vβ‚‚ Pβ‚‚).nonempty rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p hw b, s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w (f ∘ p) hw bβ‚‚, ← s.weightedVSubOfPoint_vadd_eq_of_sum_eq_one w (f ∘ p) hw (f b) bβ‚‚] simp only [weightedVSubOfPoint_apply, RingHom.id_apply, AffineMap.map_vadd, LinearMap.map_smulβ‚›β‚—, AffineMap.linearMap_vsub, map_sum, Function.comp_apply] /-- The value of `affineCombination`, where the given points take only two values. -/ lemma affineCombination_apply_eq_lineMap_sum [DecidableEq ΞΉ] (w : ΞΉ β†’ k) (p : ΞΉ β†’ P) (p₁ pβ‚‚ : P) (s' : Finset ΞΉ) (h : βˆ‘ i ∈ s, w i = 1) (hpβ‚‚ : βˆ€ i ∈ s ∩ s', p i = pβ‚‚) (hp₁ : βˆ€ i ∈ s \ s', p i = p₁) : s.affineCombination k p w = AffineMap.lineMap p₁ pβ‚‚ (βˆ‘ i ∈ s ∩ s', w i) := by rw [s.affineCombination_eq_weightedVSubOfPoint_vadd_of_sum_eq_one w p h p₁, weightedVSubOfPoint_apply, ← s.sum_inter_add_sum_diff s', AffineMap.lineMap_apply, vadd_right_cancel_iff, sum_smul] convert add_zero _ with i hi Β· convert Finset.sum_const_zero with i hi simp [hp₁ i hi] Β· exact (hpβ‚‚ i hi).symm variable (k) /-- Weights for expressing a single point as an affine combination. -/ def affineCombinationSingleWeights [DecidableEq ΞΉ] (i : ΞΉ) : ΞΉ β†’ k := Pi.single i 1 @[simp] theorem affineCombinationSingleWeights_apply_self [DecidableEq ΞΉ] (i : ΞΉ) : affineCombinationSingleWeights k i i = 1 := Pi.single_eq_same _ _ @[simp] theorem affineCombinationSingleWeights_apply_of_ne [DecidableEq ΞΉ] {i j : ΞΉ} (h : j β‰  i) : affineCombinationSingleWeights k i j = 0 := Pi.single_eq_of_ne h _ @[simp] theorem sum_affineCombinationSingleWeights [DecidableEq ΞΉ] {i : ΞΉ} (h : i ∈ s) : βˆ‘ j ∈ s, affineCombinationSingleWeights k i j = 1 := by rw [← affineCombinationSingleWeights_apply_self k i] exact sum_eq_single_of_mem i h fun j _ hj => affineCombinationSingleWeights_apply_of_ne k hj /-- Weights for expressing the subtraction of two points as a `weightedVSub`. -/ def weightedVSubVSubWeights [DecidableEq ΞΉ] (i j : ΞΉ) : ΞΉ β†’ k := affineCombinationSingleWeights k i - affineCombinationSingleWeights k j @[simp] theorem weightedVSubVSubWeights_self [DecidableEq ΞΉ] (i : ΞΉ) : weightedVSubVSubWeights k i i = 0 := by simp [weightedVSubVSubWeights] @[simp] theorem weightedVSubVSubWeights_apply_left [DecidableEq ΞΉ] {i j : ΞΉ} (h : i β‰  j) : weightedVSubVSubWeights k i j i = 1 := by simp [weightedVSubVSubWeights, h] @[simp] theorem weightedVSubVSubWeights_apply_right [DecidableEq ΞΉ] {i j : ΞΉ} (h : i β‰  j) : weightedVSubVSubWeights k i j j = -1 := by simp [weightedVSubVSubWeights, h.symm] @[simp] theorem weightedVSubVSubWeights_apply_of_ne [DecidableEq ΞΉ] {i j t : ΞΉ} (hi : t β‰  i) (hj : t β‰  j) : weightedVSubVSubWeights k i j t = 0 := by simp [weightedVSubVSubWeights, hi, hj] @[simp] theorem sum_weightedVSubVSubWeights [DecidableEq ΞΉ] {i j : ΞΉ} (hi : i ∈ s) (hj : j ∈ s) : βˆ‘ t ∈ s, weightedVSubVSubWeights k i j t = 0 := by simp_rw [weightedVSubVSubWeights, Pi.sub_apply, sum_sub_distrib] simp [hi, hj] variable {k} /-- Weights for expressing `lineMap` as an affine combination. -/ def affineCombinationLineMapWeights [DecidableEq ΞΉ] (i j : ΞΉ) (c : k) : ΞΉ β†’ k := c β€’ weightedVSubVSubWeights k j i + affineCombinationSingleWeights k i @[simp] theorem affineCombinationLineMapWeights_self [DecidableEq ΞΉ] (i : ΞΉ) (c : k) : affineCombinationLineMapWeights i i c = affineCombinationSingleWeights k i := by simp [affineCombinationLineMapWeights] @[simp] theorem affineCombinationLineMapWeights_apply_left [DecidableEq ΞΉ] {i j : ΞΉ} (h : i β‰  j) (c : k) : affineCombinationLineMapWeights i j c i = 1 - c := by simp [affineCombinationLineMapWeights, h.symm, sub_eq_neg_add] @[simp] theorem affineCombinationLineMapWeights_apply_right [DecidableEq ΞΉ] {i j : ΞΉ} (h : i β‰  j) (c : k) : affineCombinationLineMapWeights i j c j = c := by simp [affineCombinationLineMapWeights, h.symm] @[simp] theorem affineCombinationLineMapWeights_apply_of_ne [DecidableEq ΞΉ] {i j t : ΞΉ} (hi : t β‰  i) (hj : t β‰  j) (c : k) : affineCombinationLineMapWeights i j c t = 0 := by simp [affineCombinationLineMapWeights, hi, hj] @[simp] theorem sum_affineCombinationLineMapWeights [DecidableEq ΞΉ] {i j : ΞΉ} (hi : i ∈ s) (hj : j ∈ s) (c : k) : βˆ‘ t ∈ s, affineCombinationLineMapWeights i j c t = 1 := by simp_rw [affineCombinationLineMapWeights, Pi.add_apply, sum_add_distrib] simp [hi, hj, ← mul_sum] variable (k) /-- An affine combination with `affineCombinationSingleWeights` gives the specified point. -/ @[simp]
Mathlib/LinearAlgebra/AffineSpace/Combination.lean
690
693
theorem affineCombination_affineCombinationSingleWeights [DecidableEq ΞΉ] (p : ΞΉ β†’ P) {i : ΞΉ} (hi : i ∈ s) : s.affineCombination k p (affineCombinationSingleWeights k i) = p i := by
refine s.affineCombination_of_eq_one_of_eq_zero _ _ hi (by simp) ?_ rintro j - hj
/- 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 Batteries.Tactic.Congr import Mathlib.Data.Option.Basic import Mathlib.Data.Prod.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Data.Set.SymmDiff import Mathlib.Data.Set.Inclusion /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set Ξ±` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of Ξ². * `range f : Set Ξ²` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p β†’ Ξ±)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ assert_not_exists WithTop OrderIso universe u v open Function Set namespace Set variable {Ξ± Ξ² Ξ³ : Type*} {ΞΉ : Sort*} /-! ### Inverse image -/ section Preimage variable {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ³} @[simp] theorem preimage_empty : f ⁻¹' βˆ… = βˆ… := rfl theorem preimage_congr {f g : Ξ± β†’ Ξ²} {s : Set Ξ²} (h : βˆ€ x : Ξ±, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] @[gcongr] theorem preimage_mono {s t : Set Ξ²} (h : s βŠ† t) : f ⁻¹' s βŠ† f ⁻¹' t := fun _ hx => h hx @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl theorem subset_preimage_univ {s : Set Ξ±} : s βŠ† f ⁻¹' univ := subset_univ _ @[simp, mfld_simps] theorem preimage_inter {s t : Set Ξ²} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl @[simp] theorem preimage_union {s t : Set Ξ²} : f ⁻¹' (s βˆͺ t) = f ⁻¹' s βˆͺ f ⁻¹' t := rfl @[simp] theorem preimage_compl {s : Set Ξ²} : f ⁻¹' sᢜ = (f ⁻¹' s)ᢜ := rfl @[simp] theorem preimage_diff (f : Ξ± β†’ Ξ²) (s t : Set Ξ²) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : Ξ± β†’ Ξ²} (s t : Set Ξ²) : f ⁻¹' (s βˆ† t) = (f ⁻¹' s) βˆ† (f ⁻¹' t) := rfl @[simp] theorem preimage_ite (f : Ξ± β†’ Ξ²) (s t₁ tβ‚‚ : Set Ξ²) : f ⁻¹' s.ite t₁ tβ‚‚ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' tβ‚‚) := rfl @[simp] theorem preimage_setOf_eq {p : Ξ± β†’ Prop} {f : Ξ² β†’ Ξ±} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl @[simp] theorem preimage_id_eq : preimage (id : Ξ± β†’ Ξ±) = id := rfl @[mfld_simps] theorem preimage_id {s : Set Ξ±} : id ⁻¹' s = s := rfl @[simp, mfld_simps] theorem preimage_id' {s : Set Ξ±} : (fun x => x) ⁻¹' s = s := rfl @[simp] theorem preimage_const_of_mem {b : Ξ²} {s : Set Ξ²} (h : b ∈ s) : (fun _ : Ξ± => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h @[simp] theorem preimage_const_of_not_mem {b : Ξ²} {s : Set Ξ²} (h : b βˆ‰ s) : (fun _ : Ξ± => b) ⁻¹' s = βˆ… := eq_empty_of_subset_empty fun _ hx => h hx theorem preimage_const (b : Ξ²) (s : Set Ξ²) [Decidable (b ∈ s)] : (fun _ : Ξ± => b) ⁻¹' s = if b ∈ s then univ else βˆ… := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] /-- If preimage of each singleton under `f : Ξ± β†’ Ξ²` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty Ξ²] {f : Ξ± β†’ Ξ²} (hf : βˆ€ b : Ξ², f ⁻¹' {b} = βˆ… ∨ f ⁻¹' {b} = univ) : βˆƒ b, f = const Ξ± b := by rcases em (βˆƒ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' Β· exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ Β· have : βˆ€ x b, f x β‰  b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary Ξ², funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set Ξ³} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl theorem preimage_iterate_eq {f : Ξ± β†’ Ξ±} {n : β„•} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] theorem preimage_preimage {g : Ξ² β†’ Ξ³} {f : Ξ± β†’ Ξ²} {s : Set Ξ³} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm theorem eq_preimage_subtype_val_iff {p : Ξ± β†’ Prop} {s : Set (Subtype p)} {t : Set Ξ±} : s = Subtype.val ⁻¹' t ↔ βˆ€ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ theorem nonempty_of_nonempty_preimage {s : Set Ξ²} {f : Ξ± β†’ Ξ²} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ @[simp] theorem preimage_singleton_true (p : Ξ± β†’ Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp @[simp] theorem preimage_singleton_false (p : Ξ± β†’ Prop) : p ⁻¹' {False} = {a | Β¬p a} := by ext; simp theorem preimage_subtype_coe_eq_compl {s u v : Set Ξ±} (hsuv : s βŠ† u βˆͺ v) (H : s ∩ (u ∩ v) = βˆ…) : ((↑) : s β†’ Ξ±) ⁻¹' u = ((↑) ⁻¹' v)ᢜ := by ext ⟨x, x_in_s⟩ constructor Β· intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ Β· intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' lemma preimage_subset {s t} (hs : s βŠ† f '' t) (hf : Set.InjOn f (f ⁻¹' s)) : f ⁻¹' s βŠ† t := by rintro a ha obtain ⟨b, hb, hba⟩ := hs ha rwa [hf ha _ hba.symm] simpa [hba] end Preimage /-! ### Image of a set under a function -/ section Image variable {f : Ξ± β†’ Ξ²} {s t : Set Ξ±} theorem image_eta (f : Ξ± β†’ Ξ²) : f '' s = (fun x => f x) '' s := rfl theorem _root_.Function.Injective.mem_set_image {f : Ξ± β†’ Ξ²} (hf : Injective f) {s : Set Ξ±} {a : Ξ±} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq β–Έ hb, mem_image_of_mem f⟩ lemma preimage_subset_of_surjOn {t : Set Ξ²} (hf : Injective f) (h : SurjOn f s t) : f ⁻¹' t βŠ† s := fun _ hx ↦ hf.mem_set_image.1 <| h hx theorem forall_mem_image {f : Ξ± β†’ Ξ²} {s : Set Ξ±} {p : Ξ² β†’ Prop} : (βˆ€ y ∈ f '' s, p y) ↔ βˆ€ ⦃x⦄, x ∈ s β†’ p (f x) := by simp theorem exists_mem_image {f : Ξ± β†’ Ξ²} {s : Set Ξ±} {p : Ξ² β†’ Prop} : (βˆƒ y ∈ f '' s, p y) ↔ βˆƒ x ∈ s, p (f x) := by simp @[congr] theorem image_congr {f g : Ξ± β†’ Ξ²} {s : Set Ξ±} (h : βˆ€ a ∈ s, f a = g a) : f '' s = g '' s := by aesop /-- A common special case of `image_congr` -/ theorem image_congr' {f g : Ξ± β†’ Ξ²} {s : Set Ξ±} (h : βˆ€ x : Ξ±, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x @[gcongr] lemma image_mono (h : s βŠ† t) : f '' s βŠ† f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ²) (a : Set Ξ±) : f ∘ g '' a = f '' (g '' a) := by aesop theorem image_comp_eq {g : Ξ² β†’ Ξ³} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : Ξ² β†’ Ξ³) (f : Ξ± β†’ Ξ²) (s : Set Ξ±) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm theorem image_comm {Ξ²'} {f : Ξ² β†’ Ξ³} {g : Ξ± β†’ Ξ²} {f' : Ξ± β†’ Ξ²'} {g' : Ξ²' β†’ Ξ³} (h_comm : βˆ€ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] theorem _root_.Function.Semiconj.set_image {f : Ξ± β†’ Ξ²} {ga : Ξ± β†’ Ξ±} {gb : Ξ² β†’ Ξ²} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h theorem _root_.Function.Commute.set_image {f g : Ξ± β†’ Ξ±} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h /-- Image is monotone with respect to `βŠ†`. See `Set.monotone_image` for the statement in terms of `≀`. -/ @[gcongr] theorem image_subset {a b : Set Ξ±} (f : Ξ± β†’ Ξ²) (h : a βŠ† b) : f '' a βŠ† f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `βŠ†`. -/ lemma monotone_image {f : Ξ± β†’ Ξ²} : Monotone (image f) := fun _ _ => image_subset _ theorem image_union (f : Ξ± β†’ Ξ²) (s t : Set Ξ±) : f '' (s βˆͺ t) = f '' s βˆͺ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ Β· exact mem_union_left t h Β· exact mem_union_right s h⟩ @[simp] theorem image_empty (f : Ξ± β†’ Ξ²) : f '' βˆ… = βˆ… := by ext simp theorem image_inter_subset (f : Ξ± β†’ Ξ²) (s t : Set Ξ±) : f '' (s ∩ t) βŠ† f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) theorem image_inter_on {f : Ξ± β†’ Ξ²} {s t : Set Ξ±} (h : βˆ€ x ∈ t, βˆ€ y ∈ s, f x = f y β†’ x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, hβ‚βŸ©, ⟨aβ‚‚, haβ‚‚, hβ‚‚βŸ©βŸ© ↦ have : aβ‚‚ = a₁ := h _ haβ‚‚ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this β–Έ haβ‚‚βŸ©, hβ‚βŸ© theorem image_inter {f : Ξ± β†’ Ξ²} {s t : Set Ξ±} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h theorem image_univ_of_surjective {ΞΉ : Type*} {f : ΞΉ β†’ Ξ²} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] @[simp] theorem image_singleton {f : Ξ± β†’ Ξ²} {a : Ξ±} : f '' {a} = {f a} := by ext simp [image, eq_comm] @[simp] theorem Nonempty.image_const {s : Set Ξ±} (hs : s.Nonempty) (a : Ξ²) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h β–Έ mem_singleton _, fun h => (eq_of_mem_singleton h).symm β–Έ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ @[simp, mfld_simps] theorem image_eq_empty {Ξ± Ξ²} {f : Ξ± β†’ Ξ²} {s : Set Ξ±} : f '' s = βˆ… ↔ s = βˆ… := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ theorem preimage_compl_eq_image_compl [BooleanAlgebra Ξ±] (S : Set Ξ±) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᢜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ theorem mem_compl_image [BooleanAlgebra Ξ±] (t : Ξ±) (S : Set Ξ±) : t ∈ HasCompl.compl '' S ↔ tᢜ ∈ S := by simp [← preimage_compl_eq_image_compl] @[simp] theorem image_id_eq : image (id : Ξ± β†’ Ξ±) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set Ξ±) : (fun x => x) '' s = s := by ext simp theorem image_id (s : Set Ξ±) : id '' s = s := by simp lemma image_iterate_eq {f : Ξ± β†’ Ξ±} {n : β„•} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq]
Mathlib/Data/Set/Image.lean
318
323
theorem compl_compl_image [BooleanAlgebra Ξ±] (S : Set Ξ±) : HasCompl.compl '' (HasCompl.compl '' S) = S := by
rw [← image_comp, compl_comp_compl, image_id] theorem image_insert_eq {f : Ξ± β†’ Ξ²} {a : Ξ±} {s : Set Ξ±} : f '' insert a s = insert (f a) (f '' s) := by
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.RCLike.Basic import Mathlib.Dynamics.BirkhoffSum.Average /-! # Birkhoff average in a normed space In this file we prove some lemmas about the Birkhoff average (`birkhoffAverage`) of a function which takes values in a normed space over `ℝ` or `β„‚`. At the time of writing, all lemmas in this file are motivated by the proof of the von Neumann Mean Ergodic Theorem, see `LinearIsometry.tendsto_birkhoffAverage_orthogonalProjection`. -/ open Function Set Filter open scoped Topology ENNReal Uniformity section variable {Ξ± E : Type*} /-- The Birkhoff averages of a function `g` over the orbit of a fixed point `x` of `f` tend to `g x` as `N β†’ ∞`. In fact, they are equal to `g x` for all `N β‰  0`, see `Function.IsFixedPt.birkhoffAverage_eq`. TODO: add a version for a periodic orbit. -/ theorem Function.IsFixedPt.tendsto_birkhoffAverage (R : Type*) [DivisionSemiring R] [CharZero R] [AddCommMonoid E] [TopologicalSpace E] [Module R E] {f : Ξ± β†’ Ξ±} {x : Ξ±} (h : f.IsFixedPt x) (g : Ξ± β†’ E) : Tendsto (birkhoffAverage R f g Β· x) atTop (𝓝 (g x)) := tendsto_const_nhds.congr' <| (eventually_ne_atTop 0).mono fun _n hn ↦ (h.birkhoffAverage_eq R g hn).symm variable [NormedAddCommGroup E] theorem dist_birkhoffSum_apply_birkhoffSum (f : Ξ± β†’ Ξ±) (g : Ξ± β†’ E) (n : β„•) (x : Ξ±) : dist (birkhoffSum f g n (f x)) (birkhoffSum f g n x) = dist (g (f^[n] x)) (g x) := by simp only [dist_eq_norm, birkhoffSum_apply_sub_birkhoffSum] theorem dist_birkhoffSum_birkhoffSum_le (f : Ξ± β†’ Ξ±) (g : Ξ± β†’ E) (n : β„•) (x y : Ξ±) : dist (birkhoffSum f g n x) (birkhoffSum f g n y) ≀ βˆ‘ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y)) := dist_sum_sum_le _ _ _ variable (π•œ : Type*) [RCLike π•œ] [Module π•œ E] [IsBoundedSMul π•œ E] theorem dist_birkhoffAverage_birkhoffAverage (f : Ξ± β†’ Ξ±) (g : Ξ± β†’ E) (n : β„•) (x y : Ξ±) : dist (birkhoffAverage π•œ f g n x) (birkhoffAverage π•œ f g n y) = dist (birkhoffSum f g n x) (birkhoffSum f g n y) / n := by simp [birkhoffAverage, dist_smulβ‚€, div_eq_inv_mul] theorem dist_birkhoffAverage_birkhoffAverage_le (f : Ξ± β†’ Ξ±) (g : Ξ± β†’ E) (n : β„•) (x y : Ξ±) : dist (birkhoffAverage π•œ f g n x) (birkhoffAverage π•œ f g n y) ≀ (βˆ‘ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y))) / n := (dist_birkhoffAverage_birkhoffAverage _ _ _ _ _ _).trans_le <| by gcongr; apply dist_birkhoffSum_birkhoffSum_le theorem dist_birkhoffAverage_apply_birkhoffAverage (f : Ξ± β†’ Ξ±) (g : Ξ± β†’ E) (n : β„•) (x : Ξ±) : dist (birkhoffAverage π•œ f g n (f x)) (birkhoffAverage π•œ f g n x) = dist (g (f^[n] x)) (g x) / n := by simp [dist_birkhoffAverage_birkhoffAverage, dist_birkhoffSum_apply_birkhoffSum] /-- If a function `g` is bounded along the positive orbit of `x` under `f`, then the difference between Birkhoff averages of `g` along the orbit of `f x` and along the orbit of `x` tends to zero. See also `tendsto_birkhoffAverage_apply_sub_birkhoffAverage'`. -/ theorem tendsto_birkhoffAverage_apply_sub_birkhoffAverage {f : Ξ± β†’ Ξ±} {g : Ξ± β†’ E} {x : Ξ±} (h : Bornology.IsBounded (range (g <| f^[Β·] x))) : Tendsto (fun n ↦ birkhoffAverage π•œ f g n (f x) - birkhoffAverage π•œ f g n x) atTop (𝓝 0) := by rcases Metric.isBounded_range_iff.1 h with ⟨C, hC⟩ have : Tendsto (fun n : β„• ↦ C / n) atTop (𝓝 0) := tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop refine squeeze_zero_norm (fun n ↦ ?_) this rw [← dist_eq_norm, dist_birkhoffAverage_apply_birkhoffAverage] gcongr exact hC n 0 /-- If a function `g` is bounded, then the difference between Birkhoff averages of `g` along the orbit of `f x` and along the orbit of `x` tends to zero. See also `tendsto_birkhoffAverage_apply_sub_birkhoffAverage`. -/ theorem tendsto_birkhoffAverage_apply_sub_birkhoffAverage' {g : Ξ± β†’ E} (h : Bornology.IsBounded (range g)) (f : Ξ± β†’ Ξ±) (x : Ξ±) : Tendsto (fun n ↦ birkhoffAverage π•œ f g n (f x) - birkhoffAverage π•œ f g n x) atTop (𝓝 0) := tendsto_birkhoffAverage_apply_sub_birkhoffAverage _ <| h.subset <| range_comp_subset_range _ _ end variable (π•œ : Type*) {X E : Type*} [PseudoEMetricSpace X] [RCLike π•œ] [NormedAddCommGroup E] [NormedSpace π•œ E] {f : X β†’ X} {g : X β†’ E} {l : X β†’ E} /-- If `f` is a non-strictly contracting map (i.e., it is Lipschitz with constant `1`) and `g` is a uniformly continuous, then the Birkhoff averages of `g` along orbits of `f` is a uniformly equicontinuous family of functions. -/
Mathlib/Dynamics/BirkhoffSum/NormedSpace.lean
106
122
theorem uniformEquicontinuous_birkhoffAverage (hf : LipschitzWith 1 f) (hg : UniformContinuous g) : UniformEquicontinuous (birkhoffAverage π•œ f g) := by
refine Metric.uniformity_basis_dist_le.uniformEquicontinuous_iff_right.2 fun Ξ΅ hΞ΅ ↦ ?_ rcases (uniformity_basis_edist_le.uniformContinuous_iff Metric.uniformity_basis_dist_le).1 hg Ξ΅ hΞ΅ with ⟨δ, hΞ΄β‚€, hδΡ⟩ refine mem_uniformity_edist.2 ⟨δ, hΞ΄β‚€, fun {x y} h n ↦ ?_⟩ calc dist (birkhoffAverage π•œ f g n x) (birkhoffAverage π•œ f g n y) ≀ (βˆ‘ k ∈ Finset.range n, dist (g (f^[k] x)) (g (f^[k] y))) / n := dist_birkhoffAverage_birkhoffAverage_le .. _ ≀ (βˆ‘ _k ∈ Finset.range n, Ξ΅) / n := by gcongr refine hδΡ _ _ ?_ simpa using (hf.iterate _).edist_le_mul_of_le h.le _ = n * Ξ΅ / n := by simp _ ≀ Ξ΅ := by rcases eq_or_ne n 0 with hn | hn <;> field_simp [hn, hΞ΅.le, mul_div_cancel_leftβ‚€]
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Comma.Over.Pullback import Mathlib.CategoryTheory.Limits.Shapes.KernelPair import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Assoc /-! # The diagonal object of a morphism. We provide various API and isomorphisms considering the diagonal object `Ξ”_{Y/X} := pullback f f` of a morphism `f : X ⟢ Y`. -/ open CategoryTheory noncomputable section namespace CategoryTheory.Limits variable {C : Type*} [Category C] {X Y Z : C} namespace pullback section Diagonal variable (f : X ⟢ Y) [HasPullback f f] /-- The diagonal object of a morphism `f : X ⟢ Y` is `Ξ”_{X/Y} := pullback f f`. -/ abbrev diagonalObj : C := pullback f f /-- The diagonal morphism `X ⟢ Ξ”_{X/Y}` for a morphism `f : X ⟢ Y`. -/ def diagonal : X ⟢ diagonalObj f := pullback.lift (πŸ™ _) (πŸ™ _) rfl @[reassoc (attr := simp)] theorem diagonal_fst : diagonal f ≫ pullback.fst _ _ = πŸ™ _ := pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem diagonal_snd : diagonal f ≫ pullback.snd _ _ = πŸ™ _ := pullback.lift_snd _ _ _ instance : IsSplitMono (diagonal f) := ⟨⟨⟨pullback.fst _ _, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.fst f f) := ⟨⟨⟨diagonal f, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.snd f f) := ⟨⟨⟨diagonal f, diagonal_snd f⟩⟩⟩ instance [Mono f] : IsIso (diagonal f) := by rw [(IsIso.inv_eq_of_inv_hom_id (diagonal_fst f)).symm] infer_instance lemma isIso_diagonal_iff : IsIso (diagonal f) ↔ Mono f := ⟨fun H ↦ ⟨fun _ _ e ↦ by rw [← lift_fst _ _ e, (cancel_epi (g := fst f f) (h := snd f f) (diagonal f)).mp (by simp), lift_snd]⟩, fun _ ↦ inferInstance⟩ /-- The two projections `Ξ”_{X/Y} ⟢ X` form a kernel pair for `f : X ⟢ Y`. -/ theorem diagonal_isKernelPair : IsKernelPair f (pullback.fst f f) (pullback.snd f f) := IsPullback.of_hasPullback f f end Diagonal end pullback variable [HasPullbacks C] open pullback section variable {U V₁ Vβ‚‚ : C} (f : X ⟢ Y) (i : U ⟢ Y) variable (i₁ : V₁ ⟢ pullback f i) (iβ‚‚ : Vβ‚‚ ⟢ pullback f i) @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_fst_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (iβ‚‚ ≫ snd f i) f f (i₁ ≫ fst f i) (iβ‚‚ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ fst _ _ ≫ i₁ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_fst f, pullback.condition_assoc, pullback.lift_fst] @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_snd_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (iβ‚‚ ≫ snd f i) f f (i₁ ≫ fst f i) (iβ‚‚ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ snd _ _ ≫ iβ‚‚ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_snd f, pullback.condition_assoc, pullback.lift_snd] variable [HasPullback i₁ iβ‚‚] /-- The underlying map of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.hom : pullback (diagonal f) (map (i₁ ≫ snd _ _) (iβ‚‚ ≫ snd _ _) f f (i₁ ≫ fst _ _) (iβ‚‚ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) ⟢ pullback i₁ iβ‚‚ := pullback.lift (pullback.snd _ _ ≫ pullback.fst _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by ext Β· simp only [Category.assoc, pullback_diagonal_map_snd_fst_fst, pullback_diagonal_map_snd_snd_fst] Β· simp only [Category.assoc, condition]) /-- The underlying inverse of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.inv : pullback i₁ iβ‚‚ ⟢ pullback (diagonal f) (map (i₁ ≫ snd _ _) (iβ‚‚ ≫ snd _ _) f f (i₁ ≫ fst _ _) (iβ‚‚ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) := pullback.lift (pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _) (pullback.map _ _ _ _ (πŸ™ _) (πŸ™ _) (pullback.snd _ _) (Category.id_comp _).symm (Category.id_comp _).symm) (by ext Β· simp only [Category.assoc, diagonal_fst, Category.comp_id, limit.lift_Ο€, PullbackCone.mk_pt, PullbackCone.mk_Ο€_app, limit.lift_Ο€_assoc, cospan_left] Β· simp only [condition_assoc, Category.assoc, diagonal_snd, Category.comp_id, limit.lift_Ο€, PullbackCone.mk_pt, PullbackCone.mk_Ο€_app, limit.lift_Ο€_assoc, cospan_right]) /-- This iso witnesses the fact that given `f : X ⟢ Y`, `i : U ⟢ Y`, and `i₁ : V₁ ⟢ X Γ—[Y] U`, `iβ‚‚ : Vβ‚‚ ⟢ X Γ—[Y] U`, the diagram ``` V₁ Γ—[X Γ—[Y] U] Vβ‚‚ ⟢ V₁ Γ—[U] Vβ‚‚ | | | | ↓ ↓ X ⟢ X Γ—[Y] X ``` is a pullback square. Also see `pullback_fst_map_snd_isPullback`. -/ def pullbackDiagonalMapIso : pullback (diagonal f) (map (i₁ ≫ snd _ _) (iβ‚‚ ≫ snd _ _) f f (i₁ ≫ fst _ _) (iβ‚‚ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) β‰… pullback i₁ iβ‚‚ where hom := pullbackDiagonalMapIso.hom f i i₁ iβ‚‚ inv := pullbackDiagonalMapIso.inv f i i₁ iβ‚‚ @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Shapes/Diagonal.lean
158
161
theorem pullbackDiagonalMapIso.hom_fst : (pullbackDiagonalMapIso f i i₁ iβ‚‚).hom ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by
delta pullbackDiagonalMapIso
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Function.AEEqFun.DomAct import Mathlib.MeasureTheory.Function.LpSpace.Indicator /-! # Action of `Mα΅ˆα΅α΅ƒ` on `Lα΅–` spaces In this file we define action of `Mα΅ˆα΅α΅ƒ` on `MeasureTheory.Lp E p ΞΌ` If `f : Ξ± β†’ E` is a function representing an equivalence class in `Lα΅–(Ξ±, E)`, `M` acts on `Ξ±`, and `c : M`, then `(.mk c : Mα΅ˆα΅α΅ƒ) β€’ [f]` is represented by the function `a ↦ f (c β€’ a)`. We also prove basic properties of this action. -/ open MeasureTheory Filter open scoped ENNReal namespace DomMulAct variable {M N Ξ± E : Type*} [MeasurableSpace M] [MeasurableSpace N] [MeasurableSpace Ξ±] [NormedAddCommGroup E] {ΞΌ : MeasureTheory.Measure Ξ±} {p : ℝβ‰₯0∞} section SMul variable [SMul M Ξ±] [SMulInvariantMeasure M Ξ± ΞΌ] [MeasurableSMul M Ξ±] @[to_additive] instance : SMul Mα΅ˆα΅α΅ƒ (Lp E p ΞΌ) where smul c f := Lp.compMeasurePreserving (mk.symm c β€’ Β·) (measurePreserving_smul _ _) f @[to_additive (attr := simp)] theorem smul_Lp_val (c : Mα΅ˆα΅α΅ƒ) (f : Lp E p ΞΌ) : (c β€’ f).1 = c β€’ f.1 := rfl @[to_additive] theorem smul_Lp_ae_eq (c : Mα΅ˆα΅α΅ƒ) (f : Lp E p ΞΌ) : c β€’ f =ᡐ[ΞΌ] (f <| mk.symm c β€’ Β·) := Lp.coeFn_compMeasurePreserving _ _ @[to_additive] theorem mk_smul_toLp (c : M) {f : Ξ± β†’ E} (hf : MemLp f p ΞΌ) : mk c β€’ hf.toLp f = (hf.comp_measurePreserving <| measurePreserving_smul c ΞΌ).toLp (f <| c β€’ Β·) := rfl @[to_additive (attr := simp)] theorem smul_Lp_const [IsFiniteMeasure ΞΌ] (c : Mα΅ˆα΅α΅ƒ) (a : E) : c β€’ Lp.const p ΞΌ a = Lp.const p ΞΌ a := rfl @[to_additive] theorem mk_smul_indicatorConstLp (c : M) {s : Set Ξ±} (hs : MeasurableSet s) (hΞΌs : ΞΌ s β‰  ∞) (b : E) : mk c β€’ indicatorConstLp p hs hΞΌs b = indicatorConstLp p (hs.preimage <| measurable_const_smul c) (by rwa [SMulInvariantMeasure.measure_preimage_smul c hs]) b := rfl instance [SMul N Ξ±] [SMulCommClass M N Ξ±] [SMulInvariantMeasure N Ξ± ΞΌ] [MeasurableSMul N Ξ±] : SMulCommClass Mα΅ˆα΅α΅ƒ Nα΅ˆα΅α΅ƒ (Lp E p ΞΌ) := Subtype.val_injective.smulCommClass (fun _ _ ↦ rfl) fun _ _ ↦ rfl instance {π•œ : Type*} [NormedRing π•œ] [Module π•œ E] [IsBoundedSMul π•œ E] : SMulCommClass Mα΅ˆα΅α΅ƒ π•œ (Lp E p ΞΌ) := Subtype.val_injective.smulCommClass (fun _ _ ↦ rfl) fun _ _ ↦ rfl instance {π•œ : Type*} [NormedRing π•œ] [Module π•œ E] [IsBoundedSMul π•œ E] : SMulCommClass π•œ Mα΅ˆα΅α΅ƒ (Lp E p ΞΌ) := .symm _ _ _ -- We don't have a typeclass for additive versions of the next few lemmas -- Should we add `AddDistribAddAction` with `to_additive` both from `MulDistribMulAction` -- and `DistribMulAction`? @[to_additive]
Mathlib/MeasureTheory/Function/LpSpace/DomAct/Basic.lean
78
79
theorem smul_Lp_add (c : Mα΅ˆα΅α΅ƒ) : βˆ€ f g : Lp E p ΞΌ, c β€’ (f + g) = c β€’ f + c β€’ g := by
rintro ⟨⟨⟩, _⟩ ⟨⟨⟩, _⟩; rfl
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.Algebra.Algebra.Basic import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Polynomial.Degree.Lemmas import Mathlib.Algebra.Polynomial.Eval.Algebra import Mathlib.Tactic.Abel /-! # The Pochhammer polynomials We define and prove some basic relations about `ascPochhammer S n : S[X] := X * (X + 1) * ... * (X + n - 1)` which is also known as the rising factorial and about `descPochhammer R n : R[X] := X * (X - 1) * ... * (X - n + 1)` which is also known as the falling factorial. Versions of this definition that are focused on `Nat` can be found in `Data.Nat.Factorial` as `Nat.ascFactorial` and `Nat.descFactorial`. ## Implementation As with many other families of polynomials, even though the coefficients are always in `β„•` or `β„€` , we define the polynomial with coefficients in any `[Semiring S]` or `[Ring R]`. In an integral domain `S`, we show that `ascPochhammer S n` is zero iff `n` is a sufficiently large non-positive integer. ## TODO There is lots more in this direction: * q-factorials, q-binomials, q-Pochhammer. -/ universe u v open Polynomial section Semiring variable (S : Type u) [Semiring S] /-- `ascPochhammer S n` is the polynomial `X * (X + 1) * ... * (X + n - 1)`, with coefficients in the semiring `S`. -/ noncomputable def ascPochhammer : β„• β†’ S[X] | 0 => 1 | n + 1 => X * (ascPochhammer n).comp (X + 1) @[simp] theorem ascPochhammer_zero : ascPochhammer S 0 = 1 := rfl @[simp] theorem ascPochhammer_one : ascPochhammer S 1 = X := by simp [ascPochhammer] theorem ascPochhammer_succ_left (n : β„•) : ascPochhammer S (n + 1) = X * (ascPochhammer S n).comp (X + 1) := by rw [ascPochhammer] theorem monic_ascPochhammer (n : β„•) [Nontrivial S] [NoZeroDivisors S] : Monic <| ascPochhammer S n := by induction' n with n hn Β· simp Β· have : leadingCoeff (X + 1 : S[X]) = 1 := leadingCoeff_X_add_C 1 rw [ascPochhammer_succ_left, Monic.def, leadingCoeff_mul, leadingCoeff_comp (ne_zero_of_eq_one <| natDegree_X_add_C 1 : natDegree (X + 1) β‰  0), hn, monic_X, one_mul, one_mul, this, one_pow] section variable {S} {T : Type v} [Semiring T] @[simp] theorem ascPochhammer_map (f : S β†’+* T) (n : β„•) : (ascPochhammer S n).map f = ascPochhammer T n := by induction n with | zero => simp | succ n ih => simp [ih, ascPochhammer_succ_left, map_comp] theorem ascPochhammer_evalβ‚‚ (f : S β†’+* T) (n : β„•) (t : T) : (ascPochhammer T n).eval t = (ascPochhammer S n).evalβ‚‚ f t := by rw [← ascPochhammer_map f] exact eval_map f t theorem ascPochhammer_eval_comp {R : Type*} [CommSemiring R] (n : β„•) (p : R[X]) [Algebra R S] (x : S) : ((ascPochhammer S n).comp (p.map (algebraMap R S))).eval x = (ascPochhammer S n).eval (p.evalβ‚‚ (algebraMap R S) x) := by rw [ascPochhammer_evalβ‚‚ (algebraMap R S), ← evalβ‚‚_comp', ← ascPochhammer_map (algebraMap R S), ← map_comp, eval_map] end @[simp, norm_cast] theorem ascPochhammer_eval_cast (n k : β„•) : (((ascPochhammer β„• n).eval k : β„•) : S) = ((ascPochhammer S n).eval k : S) := by rw [← ascPochhammer_map (algebraMap β„• S), eval_map, ← eq_natCast (algebraMap β„• S), evalβ‚‚_at_natCast,Nat.cast_id] theorem ascPochhammer_eval_zero {n : β„•} : (ascPochhammer S n).eval 0 = if n = 0 then 1 else 0 := by cases n Β· simp Β· simp [X_mul, Nat.succ_ne_zero, ascPochhammer_succ_left] theorem ascPochhammer_zero_eval_zero : (ascPochhammer S 0).eval 0 = 1 := by simp @[simp]
Mathlib/RingTheory/Polynomial/Pochhammer.lean
110
113
theorem ascPochhammer_ne_zero_eval_zero {n : β„•} (h : n β‰  0) : (ascPochhammer S n).eval 0 = 0 := by
simp [ascPochhammer_eval_zero, h] theorem ascPochhammer_succ_right (n : β„•) :
/- Copyright (c) 2022 Violeta HernΓ‘ndez Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta HernΓ‘ndez Palacios -/ import Mathlib.SetTheory.Ordinal.Family import Mathlib.Tactic.Abel /-! # Natural operations on ordinals The goal of this file is to define natural addition and multiplication on ordinals, also known as the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals `a β™― b` is recursively defined as the least ordinal greater than `a' β™― b` and `a β™― b'` for `a' < a` and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least ordinal such that `a ⨳ b β™― a' ⨳ b'` is greater than `a' ⨳ b β™― a ⨳ b'` for any `a' < a` and `b' < b`. These operations form a rich algebraic structure: they're commutative, associative, preserve order, have the usual `0` and `1` from ordinals, and distribute over one another. Moreover, these operations are the addition and multiplication of ordinals when viewed as combinatorial `Game`s. This makes them particularly useful for game theory. Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form. The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were polynomials in `Ο‰`. Likewise, their natural multiplication corresponds to multiplying the Cantor normal forms as polynomials. ## Implementation notes Given the rich algebraic structure of these two operations, we choose to create a type synonym `NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth between both types, we attempt to prove and state most results on `Ordinal`. ## Todo - Prove the characterizations of natural addition and multiplication in terms of the Cantor normal form. -/ universe u v open Function Order Set noncomputable section /-! ### Basic casts between `Ordinal` and `NatOrdinal` -/ /-- A type synonym for ordinals with natural addition and multiplication. -/ def NatOrdinal : Type _ := Ordinal deriving Zero, Inhabited, One, WellFoundedRelation -- The `LinearOrder, `SuccOrder` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance NatOrdinal.instLinearOrder : LinearOrder NatOrdinal := Ordinal.instLinearOrder instance NatOrdinal.instSuccOrder : SuccOrder NatOrdinal := Ordinal.instSuccOrder instance NatOrdinal.instOrderBot : OrderBot NatOrdinal := Ordinal.instOrderBot instance NatOrdinal.instNoMaxOrder : NoMaxOrder NatOrdinal := Ordinal.instNoMaxOrder instance NatOrdinal.instZeroLEOneClass : ZeroLEOneClass NatOrdinal := Ordinal.instZeroLEOneClass instance NatOrdinal.instNeZeroOne : NeZero (1 : NatOrdinal) := Ordinal.instNeZeroOne instance NatOrdinal.uncountable : Uncountable NatOrdinal := Ordinal.uncountable /-- The identity function between `Ordinal` and `NatOrdinal`. -/ @[match_pattern] def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal := OrderIso.refl _ /-- The identity function between `NatOrdinal` and `Ordinal`. -/ @[match_pattern] def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal := OrderIso.refl _ namespace NatOrdinal open Ordinal @[simp] theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal := rfl @[simp] theorem toOrdinal_toNatOrdinal (a : NatOrdinal) : a.toOrdinal.toNatOrdinal = a := rfl theorem lt_wf : @WellFounded NatOrdinal (Β· < Β·) := Ordinal.lt_wf instance : WellFoundedLT NatOrdinal := Ordinal.wellFoundedLT instance : ConditionallyCompleteLinearOrderBot NatOrdinal := WellFoundedLT.conditionallyCompleteLinearOrderBot _ @[simp] theorem bot_eq_zero : (βŠ₯ : NatOrdinal) = 0 := rfl @[simp] theorem toOrdinal_zero : toOrdinal 0 = 0 := rfl @[simp] theorem toOrdinal_one : toOrdinal 1 = 1 := rfl @[simp] theorem toOrdinal_eq_zero {a} : toOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toOrdinal_eq_one {a} : toOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toOrdinal_max (a b : NatOrdinal) : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) := rfl @[simp] theorem toOrdinal_min (a b : NatOrdinal) : toOrdinal (min a b) = min (toOrdinal a) (toOrdinal b) := rfl theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) := rfl @[simp] theorem zero_le (o : NatOrdinal) : 0 ≀ o := Ordinal.zero_le o theorem not_lt_zero (o : NatOrdinal) : Β¬ o < 0 := Ordinal.not_lt_zero o @[simp] theorem lt_one_iff_zero {o : NatOrdinal} : o < 1 ↔ o = 0 := Ordinal.lt_one_iff_zero /-- A recursor for `NatOrdinal`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {Ξ² : NatOrdinal β†’ Sort*} (h : βˆ€ a, Ξ² (toNatOrdinal a)) : βˆ€ a, Ξ² a := fun a => h (toOrdinal a) /-- `Ordinal.induction` but for `NatOrdinal`. -/ theorem induction {p : NatOrdinal β†’ Prop} : βˆ€ (i) (_ : βˆ€ j, (βˆ€ k, k < j β†’ p k) β†’ p j), p i := Ordinal.induction instance small_Iio (a : NatOrdinal.{u}) : Small.{u} (Set.Iio a) := Ordinal.small_Iio a instance small_Iic (a : NatOrdinal.{u}) : Small.{u} (Set.Iic a) := Ordinal.small_Iic a instance small_Ico (a b : NatOrdinal.{u}) : Small.{u} (Set.Ico a b) := Ordinal.small_Ico a b instance small_Icc (a b : NatOrdinal.{u}) : Small.{u} (Set.Icc a b) := Ordinal.small_Icc a b instance small_Ioo (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioo a b) := Ordinal.small_Ioo a b instance small_Ioc (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioc a b) := Ordinal.small_Ioc a b end NatOrdinal namespace Ordinal variable {a b c : Ordinal.{u}} @[simp] theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal := rfl @[simp] theorem toNatOrdinal_toOrdinal (a : Ordinal) : a.toNatOrdinal.toOrdinal = a := rfl @[simp] theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 := rfl @[simp] theorem toNatOrdinal_one : toNatOrdinal 1 = 1 := rfl @[simp] theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toNatOrdinal_max (a b : Ordinal) : toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) := rfl @[simp] theorem toNatOrdinal_min (a b : Ordinal) : toNatOrdinal (min a b) = min (toNatOrdinal a) (toNatOrdinal b) := rfl /-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this guarantees we only need to open the `NaturalOps` locale once. -/ /-- Natural addition on ordinals `a β™― b`, also known as the Hessenberg sum, is recursively defined as the least ordinal greater than `a' β™― b` and `a β™― b'` for all `a' < a` and `b' < b`. In contrast to normal ordinal addition, it is commutative. Natural addition can equivalently be characterized as the ordinal resulting from adding up corresponding coefficients in the Cantor normal forms of `a` and `b`. -/ noncomputable def nadd (a b : Ordinal.{u}) : Ordinal.{u} := max (⨆ x : Iio a, succ (nadd x.1 b)) (⨆ x : Iio b, succ (nadd a x.1)) termination_by (a, b) decreasing_by all_goals cases x; decreasing_tactic @[inherit_doc] scoped[NaturalOps] infixl:65 " β™― " => Ordinal.nadd open NaturalOps /-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively defined as the least ordinal such that `a ⨳ b β™― a' ⨳ b'` is greater than `a' ⨳ b β™― a ⨳ b'` for all `a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and distributive (over natural addition). Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying the Cantor normal forms of `a` and `b` as if they were polynomials in `Ο‰`. Addition of exponents is done via natural addition. -/ noncomputable def nmul (a b : Ordinal.{u}) : Ordinal.{u} := sInf {c | βˆ€ a' < a, βˆ€ b' < b, nmul a' b β™― nmul a b' < c β™― nmul a' b'} termination_by (a, b) @[inherit_doc] scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul /-! ### Natural addition -/ theorem lt_nadd_iff : a < b β™― c ↔ (βˆƒ b' < b, a ≀ b' β™― c) ∨ βˆƒ c' < c, a ≀ b β™― c' := by rw [nadd] simp [Ordinal.lt_iSup_iff] theorem nadd_le_iff : b β™― c ≀ a ↔ (βˆ€ b' < b, b' β™― c < a) ∧ βˆ€ c' < c, b β™― c' < a := by rw [← not_lt, lt_nadd_iff] simp theorem nadd_lt_nadd_left (h : b < c) (a) : a β™― b < a β™― c := lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩) theorem nadd_lt_nadd_right (h : b < c) (a) : b β™― a < c β™― a := lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩) theorem nadd_le_nadd_left (h : b ≀ c) (a) : a β™― b ≀ a β™― c := by rcases lt_or_eq_of_le h with (h | rfl) Β· exact (nadd_lt_nadd_left h a).le Β· exact le_rfl theorem nadd_le_nadd_right (h : b ≀ c) (a) : b β™― a ≀ c β™― a := by rcases lt_or_eq_of_le h with (h | rfl) Β· exact (nadd_lt_nadd_right h a).le Β· exact le_rfl variable (a b) theorem nadd_comm (a b) : a β™― b = b β™― a := by rw [nadd, nadd, max_comm] congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_comm _ _) termination_by (a, b) @[deprecated "blsub will soon be deprecated" (since := "2024-11-18")] theorem blsub_nadd_of_mono {f : βˆ€ c < a β™― b, Ordinal.{max u v}} (hf : βˆ€ {i j} (hi hj), i ≀ j β†’ f i hi ≀ f j hj) : blsub.{u,v} _ f = max (blsub.{u, v} a fun a' ha' => f (a' β™― b) <| nadd_lt_nadd_right ha' b) (blsub.{u, v} b fun b' hb' => f (a β™― b') <| nadd_lt_nadd_left hb' a) := by apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _) Β· intro i h rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩) Β· exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha')) Β· exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb')) all_goals apply blsub_le_of_brange_subset.{u, u, v} rintro c ⟨d, hd, rfl⟩ apply mem_brange_self private theorem iSup_nadd_of_monotone {a b} (f : Ordinal.{u} β†’ Ordinal.{u}) (h : Monotone f) : ⨆ x : Iio (a β™― b), f x = max (⨆ a' : Iio a, f (a'.1 β™― b)) (⨆ b' : Iio b, f (a β™― b'.1)) := by apply (max_le _ _).antisymm' Β· rw [Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ obtain ⟨x, hx, hi⟩ | ⟨x, hx, hi⟩ := lt_nadd_iff.1 hi Β· exact le_max_of_le_left ((h hi).trans <| Ordinal.le_iSup (fun x : Iio a ↦ _) ⟨x, hx⟩) Β· exact le_max_of_le_right ((h hi).trans <| Ordinal.le_iSup (fun x : Iio b ↦ _) ⟨x, hx⟩) all_goals apply csSup_le_csSup' (bddAbove_of_small _) rintro _ ⟨⟨c, hc⟩, rfl⟩ refine mem_range_self (⟨_, ?_⟩ : Iio _) apply_rules [nadd_lt_nadd_left, nadd_lt_nadd_right] theorem nadd_assoc (a b c) : a β™― b β™― c = a β™― (b β™― c) := by unfold nadd rw [iSup_nadd_of_monotone fun a' ↦ succ (a' β™― c), iSup_nadd_of_monotone fun b' ↦ succ (a β™― b'), max_assoc] Β· congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_assoc _ _ _) Β· exact succ_mono.comp fun x y h ↦ nadd_le_nadd_left h _ Β· exact succ_mono.comp fun x y h ↦ nadd_le_nadd_right h _ termination_by (a, b, c) @[simp] theorem nadd_zero (a : Ordinal) : a β™― 0 = a := by rw [nadd, ciSup_of_empty fun _ : Iio 0 ↦ _, sup_bot_eq] convert iSup_succ a rename_i x cases x exact nadd_zero _ termination_by a @[simp] theorem zero_nadd : 0 β™― a = a := by rw [nadd_comm, nadd_zero] @[simp] theorem nadd_one (a : Ordinal) : a β™― 1 = succ a := by rw [nadd, ciSup_unique (s := fun _ : Iio 1 ↦ _), Iio_one_default_eq, nadd_zero, max_eq_right_iff, Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ rwa [nadd_one, succ_le_succ_iff, succ_le_iff] termination_by a @[simp] theorem one_nadd : 1 β™― a = succ a := by rw [nadd_comm, nadd_one] theorem nadd_succ : a β™― succ b = succ (a β™― b) := by rw [← nadd_one (a β™― b), nadd_assoc, nadd_one]
Mathlib/SetTheory/Ordinal/NaturalOps.lean
300
305
theorem succ_nadd : succ a β™― b = succ (a β™― b) := by
rw [← one_nadd (a β™― b), ← nadd_assoc, one_nadd] @[simp] theorem nadd_nat (n : β„•) : a β™― n = a + n := by induction' n with n hn Β· simp
/- 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.Countable import Mathlib.MeasureTheory.Measure.Decomposition.Exhaustion import Mathlib.MeasureTheory.Measure.Prod /-! # 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 _ hs hd => lintegral_iUnion hs hd _ @[simp] theorem withDensity_apply (f : Ξ± β†’ ℝβ‰₯0∞) {s : Set Ξ±} (hs : MeasurableSet s) : ΞΌ.withDensity f s = ∫⁻ a in s, f a βˆ‚ΞΌ := Measure.ofMeasurable_apply s hs 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) 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 setLIntegral_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] 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 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] 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] 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] 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] theorem withDensity_smul_measure (r : ℝβ‰₯0∞) (f : Ξ± β†’ ℝβ‰₯0∞) : (r β€’ ΞΌ).withDensity f = r β€’ ΞΌ.withDensity f := by ext s hs simp [withDensity_apply, hs] 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] } theorem withDensity_absolutelyContinuous {m : MeasurableSpace Ξ±} (ΞΌ : Measure Ξ±) (f : Ξ± β†’ ℝβ‰₯0∞) : ΞΌ.withDensity f β‰ͺ ΞΌ := by refine AbsolutelyContinuous.mk fun s hs₁ hsβ‚‚ => ?_ rw [withDensity_apply _ hs₁] exact setLIntegral_measure_zero _ _ hsβ‚‚ @[simp] theorem withDensity_zero : ΞΌ.withDensity 0 = 0 := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_one : ΞΌ.withDensity 1 = ΞΌ := by ext1 s hs simp [withDensity_apply _ hs] @[simp] theorem withDensity_const (c : ℝβ‰₯0∞) : ΞΌ.withDensity (fun _ ↦ c) = c β€’ ΞΌ := by ext1 s hs simp [withDensity_apply _ hs] theorem withDensity_tsum {ΞΉ : Type*} [Countable ΞΉ] {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)
Mathlib/MeasureTheory/Measure/WithDensity.lean
170
172
theorem withDensity_indicator {s : Set Ξ±} (hs : MeasurableSet s) (f : Ξ± β†’ ℝβ‰₯0∞) : ΞΌ.withDensity (s.indicator f) = (ΞΌ.restrict s).withDensity f := by
ext1 t ht
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, SΓ©bastien GouΓ«zel, RΓ©my Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y β‰  0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (Ο€ y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : β„‚) ^ (y : β„‚)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : β„‚) ^ (y : β„‚)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : β„€) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : β„•) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : β„•) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≀ x) : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y β‰  0 ↔ x β‰  0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * Ο€) := by rw [rpow_def, Complex.cpow_def, if_neg] Β· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * Ο€) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring Β· rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * Ο€) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor Β· intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 Β· subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ Β· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ Β· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) Β· exact zero_rpow h Β· exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
131
131
theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≀ 1 := by
/- 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, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Polynomial.Reverse import Mathlib.Algebra.Regular.SMul /-! # Theory of monic polynomials We give several tools for proving that polynomials are monic, e.g. `Monic.mul`, `Monic.map`, `Monic.pow`. -/ noncomputable section open Finset open Polynomial namespace Polynomial universe u v y variable {R : Type u} {S : Type v} {a b : R} {m n : β„•} {ΞΉ : Type y} section Semiring variable [Semiring R] {p q r : R[X]} theorem monic_zero_iff_subsingleton : Monic (0 : R[X]) ↔ Subsingleton R := subsingleton_iff_zero_eq_one theorem not_monic_zero_iff : Β¬Monic (0 : R[X]) ↔ (0 : R) β‰  1 := (monic_zero_iff_subsingleton.trans subsingleton_iff_zero_eq_one.symm).not theorem monic_zero_iff_subsingleton' : Monic (0 : R[X]) ↔ (βˆ€ f g : R[X], f = g) ∧ βˆ€ a b : R, a = b := Polynomial.monic_zero_iff_subsingleton.trans ⟨by intro simp [eq_iff_true_of_subsingleton], fun h => subsingleton_iff.mpr h.2⟩ theorem Monic.as_sum (hp : p.Monic) : p = X ^ p.natDegree + βˆ‘ i ∈ range p.natDegree, C (p.coeff i) * X ^ i := by conv_lhs => rw [p.as_sum_range_C_mul_X_pow, sum_range_succ_comm] suffices C (p.coeff p.natDegree) = 1 by rw [this, one_mul] exact congr_arg C hp theorem ne_zero_of_ne_zero_of_monic (hp : p β‰  0) (hq : Monic q) : q β‰  0 := by rintro rfl rw [Monic.def, leadingCoeff_zero] at hq rw [← mul_one p, ← C_1, ← hq, C_0, mul_zero] at hp exact hp rfl theorem Monic.map [Semiring S] (f : R β†’+* S) (hp : Monic p) : Monic (p.map f) := by unfold Monic nontriviality have : f p.leadingCoeff β‰  0 := by rw [show _ = _ from hp, f.map_one] exact one_ne_zero rw [Polynomial.leadingCoeff, coeff_map] suffices p.coeff (p.map f).natDegree = 1 by simp [this] rwa [natDegree_eq_of_degree_eq (degree_map_eq_of_leadingCoeff_ne_zero f this)] theorem monic_C_mul_of_mul_leadingCoeff_eq_one {b : R} (hp : b * p.leadingCoeff = 1) : Monic (C b * p) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_mul_C_of_leadingCoeff_mul_eq_one {b : R} (hp : p.leadingCoeff * b = 1) : Monic (p * C b) := by unfold Monic nontriviality rw [leadingCoeff_mul' _] <;> simp [leadingCoeff_C b, hp] theorem monic_of_degree_le (n : β„•) (H1 : degree p ≀ n) (H2 : coeff p n = 1) : Monic p := Decidable.byCases (fun H : degree p < n => eq_of_zero_eq_one (H2 β–Έ (coeff_eq_zero_of_degree_lt H).symm) _ _) fun H : Β¬degree p < n => by rwa [Monic, Polynomial.leadingCoeff, natDegree, (lt_or_eq_of_le H1).resolve_left H] theorem monic_X_pow_add {n : β„•} (H : degree p < n) : Monic (X ^ n + p) := monic_of_degree_le n (le_trans (degree_add_le _ _) (max_le (degree_X_pow_le _) (le_of_lt H))) (by rw [coeff_add, coeff_X_pow, if_pos rfl, coeff_eq_zero_of_degree_lt H, add_zero]) variable (a) in theorem monic_X_pow_add_C {n : β„•} (h : n β‰  0) : (X ^ n + C a).Monic := monic_X_pow_add <| (lt_of_le_of_lt degree_C_le (by simp only [Nat.cast_pos, Nat.pos_iff_ne_zero, ne_eq, h, not_false_eq_true])) theorem monic_X_add_C (x : R) : Monic (X + C x) := pow_one (X : R[X]) β–Έ monic_X_pow_add_C x one_ne_zero theorem Monic.mul (hp : Monic p) (hq : Monic q) : Monic (p * q) := letI := Classical.decEq R if h0 : (0 : R) = 1 then haveI := subsingleton_of_zero_eq_one h0 Subsingleton.elim _ _ else by have : p.leadingCoeff * q.leadingCoeff β‰  0 := by simp [Monic.def.1 hp, Monic.def.1 hq, Ne.symm h0] rw [Monic.def, leadingCoeff_mul' this, Monic.def.1 hp, Monic.def.1 hq, one_mul] theorem Monic.pow (hp : Monic p) : βˆ€ n : β„•, Monic (p ^ n) | 0 => monic_one | n + 1 => by rw [pow_succ] exact (Monic.pow hp n).mul hp theorem Monic.add_of_left (hp : Monic p) (hpq : degree q < degree p) : Monic (p + q) := by rwa [Monic, add_comm, leadingCoeff_add_of_degree_lt hpq] theorem Monic.add_of_right (hq : Monic q) (hpq : degree p < degree q) : Monic (p + q) := by rwa [Monic, leadingCoeff_add_of_degree_lt hpq] theorem Monic.of_mul_monic_left (hp : p.Monic) (hpq : (p * q).Monic) : q.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊒ rwa [leadingCoeff_monic_mul hp] theorem Monic.of_mul_monic_right (hq : q.Monic) (hpq : (p * q).Monic) : p.Monic := by contrapose! hpq rw [Monic.def] at hpq ⊒ rwa [leadingCoeff_mul_monic hq] namespace Monic lemma comp (hp : p.Monic) (hq : q.Monic) (h : q.natDegree β‰  0) : (p.comp q).Monic := by nontriviality R have : (p.comp q).natDegree = p.natDegree * q.natDegree := natDegree_comp_eq_of_mul_ne_zero <| by simp [hp.leadingCoeff, hq.leadingCoeff] rw [Monic.def, Polynomial.leadingCoeff, this, coeff_comp_degree_mul_degree h, hp.leadingCoeff, hq.leadingCoeff, one_pow, mul_one] lemma comp_X_add_C (hp : p.Monic) (r : R) : (p.comp (X + C r)).Monic := by nontriviality R refine hp.comp (monic_X_add_C _) fun ha ↦ ?_ rw [natDegree_X_add_C] at ha exact one_ne_zero ha @[simp] theorem natDegree_eq_zero_iff_eq_one (hp : p.Monic) : p.natDegree = 0 ↔ p = 1 := by constructor <;> intro h swap Β· rw [h] exact natDegree_one have : p = C (p.coeff 0) := by rw [← Polynomial.degree_le_zero_iff] rwa [Polynomial.natDegree_eq_zero_iff_degree_le_zero] at h rw [this] rw [← h, ← Polynomial.leadingCoeff, Monic.def.1 hp, C_1] @[simp] theorem degree_le_zero_iff_eq_one (hp : p.Monic) : p.degree ≀ 0 ↔ p = 1 := by rw [← hp.natDegree_eq_zero_iff_eq_one, natDegree_eq_zero_iff_degree_le_zero] theorem natDegree_mul (hp : p.Monic) (hq : q.Monic) : (p * q).natDegree = p.natDegree + q.natDegree := by nontriviality R apply natDegree_mul' simp [hp.leadingCoeff, hq.leadingCoeff] theorem degree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).degree = (q * p).degree := by by_cases h : q = 0 Β· simp [h] rw [degree_mul', hp.degree_mul] Β· exact add_comm _ _ Β· rwa [hp.leadingCoeff, one_mul, leadingCoeff_ne_zero] nonrec theorem natDegree_mul' (hp : p.Monic) (hq : q β‰  0) : (p * q).natDegree = p.natDegree + q.natDegree := by rw [natDegree_mul'] simpa [hp.leadingCoeff, leadingCoeff_ne_zero] theorem natDegree_mul_comm (hp : p.Monic) (q : R[X]) : (p * q).natDegree = (q * p).natDegree := by by_cases h : q = 0 Β· simp [h] rw [hp.natDegree_mul' h, Polynomial.natDegree_mul', add_comm] simpa [hp.leadingCoeff, leadingCoeff_ne_zero] theorem not_dvd_of_natDegree_lt (hp : Monic p) (h0 : q β‰  0) (hl : natDegree q < natDegree p) : Β¬p ∣ q := by rintro ⟨r, rfl⟩ rw [hp.natDegree_mul' <| right_ne_zero_of_mul h0] at hl exact hl.not_le (Nat.le_add_right _ _) theorem not_dvd_of_degree_lt (hp : Monic p) (h0 : q β‰  0) (hl : degree q < degree p) : Β¬p ∣ q := Monic.not_dvd_of_natDegree_lt hp h0 <| natDegree_lt_natDegree h0 hl theorem nextCoeff_mul (hp : Monic p) (hq : Monic q) : nextCoeff (p * q) = nextCoeff p + nextCoeff q := by nontriviality simp only [← coeff_one_reverse] rw [reverse_mul] <;> simp [hp.leadingCoeff, hq.leadingCoeff, mul_coeff_one, add_comm] theorem nextCoeff_pow (hp : p.Monic) (n : β„•) : (p ^ n).nextCoeff = n β€’ p.nextCoeff := by induction n with | zero => rw [pow_zero, zero_smul, ← map_one (f := C), nextCoeff_C_eq_zero] | succ n ih => rw [pow_succ, (hp.pow n).nextCoeff_mul hp, ih, succ_nsmul] theorem eq_one_of_map_eq_one {S : Type*} [Semiring S] [Nontrivial S] (f : R β†’+* S) (hp : p.Monic) (map_eq : p.map f = 1) : p = 1 := by nontriviality R have hdeg : p.degree = 0 := by rw [← degree_map_eq_of_leadingCoeff_ne_zero f _, map_eq, degree_one] Β· rw [hp.leadingCoeff, f.map_one] exact one_ne_zero have hndeg : p.natDegree = 0 := WithBot.coe_eq_coe.mp ((degree_eq_natDegree hp.ne_zero).symm.trans hdeg) convert eq_C_of_degree_eq_zero hdeg rw [← hndeg, ← Polynomial.leadingCoeff, hp.leadingCoeff, C.map_one] theorem natDegree_pow (hp : p.Monic) (n : β„•) : (p ^ n).natDegree = n * p.natDegree := by induction n with | zero => simp | succ n hn => rw [pow_succ, (hp.pow n).natDegree_mul hp, hn, Nat.succ_mul, add_comm] end Monic @[simp] theorem natDegree_pow_X_add_C [Nontrivial R] (n : β„•) (r : R) : ((X + C r) ^ n).natDegree = n := by rw [(monic_X_add_C r).natDegree_pow, natDegree_X_add_C, mul_one] theorem Monic.eq_one_of_isUnit (hm : Monic p) (hpu : IsUnit p) : p = 1 := by nontriviality R obtain ⟨q, h⟩ := hpu.exists_right_inv have := hm.natDegree_mul' (right_ne_zero_of_mul_eq_one h) rw [h, natDegree_one, eq_comm, add_eq_zero] at this exact hm.natDegree_eq_zero_iff_eq_one.mp this.1 theorem Monic.isUnit_iff (hm : p.Monic) : IsUnit p ↔ p = 1 := ⟨hm.eq_one_of_isUnit, fun h => h.symm β–Έ isUnit_one⟩ theorem eq_of_monic_of_associated (hp : p.Monic) (hq : q.Monic) (hpq : Associated p q) : p = q := by obtain ⟨u, rfl⟩ := hpq rw [(hp.of_mul_monic_left hq).eq_one_of_isUnit u.isUnit, mul_one] end Semiring section CommSemiring variable [CommSemiring R] {p : R[X]} theorem monic_multiset_prod_of_monic (t : Multiset ΞΉ) (f : ΞΉ β†’ R[X]) (ht : βˆ€ i ∈ t, Monic (f i)) : Monic (t.map f).prod := by revert ht refine t.induction_on ?_ ?_; Β· simp intro a t ih ht rw [Multiset.map_cons, Multiset.prod_cons] exact (ht _ (Multiset.mem_cons_self _ _)).mul (ih fun _ hi => ht _ (Multiset.mem_cons_of_mem hi)) theorem monic_prod_of_monic (s : Finset ΞΉ) (f : ΞΉ β†’ R[X]) (hs : βˆ€ i ∈ s, Monic (f i)) : Monic (∏ i ∈ s, f i) := monic_multiset_prod_of_monic s.1 f hs theorem monic_finprod_of_monic (Ξ± : Type*) (f : Ξ± β†’ R[X]) (hf : βˆ€ i ∈ Function.mulSupport f, Monic (f i)) : Monic (finprod f) := by classical rw [finprod_def] split_ifs Β· exact monic_prod_of_monic _ _ fun a ha => hf a ((Set.Finite.mem_toFinset _).mp ha) Β· exact monic_one theorem Monic.nextCoeff_multiset_prod (t : Multiset ΞΉ) (f : ΞΉ β†’ R[X]) (h : βˆ€ i ∈ t, Monic (f i)) : nextCoeff (t.map f).prod = (t.map fun i => nextCoeff (f i)).sum := by revert h refine Multiset.induction_on t ?_ fun a t ih ht => ?_ Β· simp only [Multiset.not_mem_zero, forall_prop_of_true, forall_prop_of_false, Multiset.map_zero, Multiset.prod_zero, Multiset.sum_zero, not_false_iff, forall_true_iff] rw [← C_1] rw [nextCoeff_C_eq_zero] Β· rw [Multiset.map_cons, Multiset.prod_cons, Multiset.map_cons, Multiset.sum_cons, Monic.nextCoeff_mul, ih] exacts [fun i hi => ht i (Multiset.mem_cons_of_mem hi), ht a (Multiset.mem_cons_self _ _), monic_multiset_prod_of_monic _ _ fun b bs => ht _ (Multiset.mem_cons_of_mem bs)] theorem Monic.nextCoeff_prod (s : Finset ΞΉ) (f : ΞΉ β†’ R[X]) (h : βˆ€ i ∈ s, Monic (f i)) : nextCoeff (∏ i ∈ s, f i) = βˆ‘ i ∈ s, nextCoeff (f i) := Monic.nextCoeff_multiset_prod s.1 f h variable [NoZeroDivisors R] {p q : R[X]} lemma irreducible_of_monic (hp : p.Monic) (hp1 : p β‰  1) : Irreducible p ↔ βˆ€ f g : R[X], f.Monic β†’ g.Monic β†’ f * g = p β†’ f = 1 ∨ g = 1 := by refine ⟨fun h f g hf hg hp => (h.2 hp.symm).imp hf.eq_one_of_isUnit hg.eq_one_of_isUnit, fun h => ⟨hp1 ∘ hp.eq_one_of_isUnit, fun f g hfg => (h (g * C f.leadingCoeff) (f * C g.leadingCoeff) ?_ ?_ ?_).symm.imp (isUnit_of_mul_eq_one f _) (isUnit_of_mul_eq_one g _)⟩⟩ Β· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, mul_comm, ← hfg, ← Monic] Β· rwa [Monic, leadingCoeff_mul, leadingCoeff_C, ← leadingCoeff_mul, ← hfg, ← Monic] Β· rw [mul_mul_mul_comm, ← C_mul, ← leadingCoeff_mul, ← hfg, hp.leadingCoeff, C_1, mul_one, mul_comm, ← hfg] lemma Monic.irreducible_iff_natDegree (hp : p.Monic) : Irreducible p ↔ p β‰  1 ∧ βˆ€ f g : R[X], f.Monic β†’ g.Monic β†’ f * g = p β†’ f.natDegree = 0 ∨ g.natDegree = 0 := by by_cases hp1 : p = 1; Β· simp [hp1] rw [irreducible_of_monic hp hp1, and_iff_right hp1] refine forallβ‚„_congr fun a b ha hb => ?_ rw [ha.natDegree_eq_zero_iff_eq_one, hb.natDegree_eq_zero_iff_eq_one] lemma Monic.irreducible_iff_natDegree' (hp : p.Monic) : Irreducible p ↔ p β‰  1 ∧ βˆ€ f g : R[X], f.Monic β†’ g.Monic β†’ f * g = p β†’ g.natDegree βˆ‰ Ioc 0 (p.natDegree / 2) := by simp_rw [hp.irreducible_iff_natDegree, mem_Ioc, Nat.le_div_iff_mul_le zero_lt_two, mul_two] apply and_congr_right' constructor <;> intro h f g hf hg he <;> subst he Β· rw [hf.natDegree_mul hg, add_le_add_iff_right] exact fun ha => (h f g hf hg rfl).elim (ha.1.trans_le ha.2).ne' ha.1.ne' Β· simp_rw [hf.natDegree_mul hg, pos_iff_ne_zero] at h contrapose! h obtain hl | hl := le_total f.natDegree g.natDegree Β· exact ⟨g, f, hg, hf, mul_comm g f, h.1, add_le_add_left hl _⟩ Β· exact ⟨f, g, hf, hg, rfl, h.2, add_le_add_right hl _⟩ /-- Alternate phrasing of `Polynomial.Monic.irreducible_iff_natDegree'` where we only have to check one divisor at a time. -/ lemma Monic.irreducible_iff_lt_natDegree_lt {p : R[X]} (hp : p.Monic) (hp1 : p β‰  1) : Irreducible p ↔ βˆ€ q, Monic q β†’ natDegree q ∈ Finset.Ioc 0 (natDegree p / 2) β†’ Β¬ q ∣ p := by rw [hp.irreducible_iff_natDegree', and_iff_right hp1] constructor Β· rintro h g hg hdg ⟨f, rfl⟩ exact h f g (hg.of_mul_monic_left hp) hg (mul_comm f g) hdg Β· rintro h f g - hg rfl hdg exact h g hg hdg (dvd_mul_left g f) lemma Monic.not_irreducible_iff_exists_add_mul_eq_coeff (hm : p.Monic) (hnd : p.natDegree = 2) : Β¬Irreducible p ↔ βˆƒ c₁ cβ‚‚, p.coeff 0 = c₁ * cβ‚‚ ∧ p.coeff 1 = c₁ + cβ‚‚ := by cases subsingleton_or_nontrivial R Β· simp [natDegree_of_subsingleton] at hnd rw [hm.irreducible_iff_natDegree', and_iff_right, hnd] Β· push_neg constructor Β· rintro ⟨a, b, ha, hb, rfl, hdb⟩ simp only [zero_lt_two, Nat.div_self, Nat.Ioc_succ_singleton, zero_add, mem_singleton] at hdb have hda := hnd rw [ha.natDegree_mul hb, hdb] at hda use a.coeff 0, b.coeff 0, mul_coeff_zero a b simpa only [nextCoeff, hnd, add_right_cancel hda, hdb] using ha.nextCoeff_mul hb Β· rintro ⟨c₁, cβ‚‚, hmul, hadd⟩ refine ⟨X + C c₁, X + C cβ‚‚, monic_X_add_C _, monic_X_add_C _, ?_, ?_⟩ Β· rw [p.as_sum_range_C_mul_X_pow, hnd, Finset.sum_range_succ, Finset.sum_range_succ, Finset.sum_range_one, ← hnd, hm.coeff_natDegree, hnd, hmul, hadd, C_mul, C_add, C_1] ring Β· rw [mem_Ioc, natDegree_X_add_C _] simp Β· rintro rfl simp [natDegree_one] at hnd end CommSemiring section Semiring variable [Semiring R] @[simp] theorem Monic.natDegree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R β†’+* S) : (P.map f).natDegree = P.natDegree := by refine le_antisymm natDegree_map_le (le_natDegree_of_ne_zero ?_) rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one] exact one_ne_zero @[simp] theorem Monic.degree_map [Semiring S] [Nontrivial S] {P : R[X]} (hmo : P.Monic) (f : R β†’+* S) : (P.map f).degree = P.degree := by by_cases hP : P = 0 Β· simp [hP] Β· refine le_antisymm degree_map_le ?_ rw [degree_eq_natDegree hP] refine le_degree_of_ne_zero ?_ rw [coeff_map, Monic.coeff_natDegree hmo, RingHom.map_one] exact one_ne_zero section Injective open Function variable [Semiring S] {f : R β†’+* S} theorem degree_map_eq_of_injective (hf : Injective f) (p : R[X]) : degree (p.map f) = degree p := letI := Classical.decEq R if h : p = 0 then by simp [h] else degree_map_eq_of_leadingCoeff_ne_zero _ (by rw [← f.map_zero]; exact mt hf.eq_iff.1 (mt leadingCoeff_eq_zero.1 h)) theorem natDegree_map_eq_of_injective (hf : Injective f) (p : R[X]) : natDegree (p.map f) = natDegree p := natDegree_eq_of_degree_eq (degree_map_eq_of_injective hf p) theorem leadingCoeff_map' (hf : Injective f) (p : R[X]) : leadingCoeff (p.map f) = f (leadingCoeff p) := by unfold leadingCoeff rw [coeff_map, natDegree_map_eq_of_injective hf p]
Mathlib/Algebra/Polynomial/Monic.lean
405
411
theorem nextCoeff_map (hf : Injective f) (p : R[X]) : (p.map f).nextCoeff = f p.nextCoeff := by
unfold nextCoeff rw [natDegree_map_eq_of_injective hf] split_ifs <;> simp [*] theorem leadingCoeff_of_injective (hf : Injective f) (p : R[X]) : leadingCoeff (p.map f) = f (leadingCoeff p) := by
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # LindelΓΆf sets and LindelΓΆf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is LindelΓΆf if it is LindelΓΆf as a set. * `NonLindelofSpace`: a space that is not a LindΓ«lof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is LindelΓΆf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ΞΉ : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is LindelΓΆf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := βˆ€ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≀ π“Ÿ s β†’ βˆƒ x ∈ s, ClusterPt x f /-- The complement to a LindelΓΆf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x βŠ“ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : βˆ€ x ∈ s, sᢜ ∈ 𝓝 x βŠ“ f) : sᢜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊒ exact hs inf_le_right /-- The complement to a LindelΓΆf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᢜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : βˆ€ x ∈ s, βˆƒ t ∈ 𝓝[s] x, tᢜ ∈ f) : sᢜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X β†’ Prop` is stable under restriction and union, and each point `x` of a LindelΓΆf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X β†’ Prop} (hmono : βˆ€ ⦃s t⦄, s βŠ† t β†’ p t β†’ p s) (hcountable_union : βˆ€ (S : Set (Set X)), S.Countable β†’ (βˆ€ s ∈ S, p s) β†’ p (⋃₀ S)) (hnhds : βˆ€ x ∈ s, βˆƒ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᢜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a LindelΓΆf set and a closed set is a LindelΓΆf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : βˆƒ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a LindelΓΆf set is a LindelΓΆf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s β–Έ ht.inter_right hs /-- The set difference of a LindelΓΆf set and an open set is a LindelΓΆf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a LindelΓΆf set is a LindelΓΆf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t βŠ† s) : IsLindelof t := inter_eq_self_of_subset_right h β–Έ hs.inter_right ht /-- A continuous image of a LindelΓΆf set is a LindelΓΆf set. -/ theorem IsLindelof.image_of_continuousOn {f : X β†’ Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f βŠ“ π“Ÿ s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : βˆƒ x ∈ s, ClusterPt x (l.comap f βŠ“ π“Ÿ s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x βŠ“ (comap f l βŠ“ π“Ÿ s)) (𝓝 (f x) βŠ“ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a LindelΓΆf set is a LindelΓΆf set within the codomain. -/ theorem IsLindelof.image {f : X β†’ Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a LindelΓΆf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hfβ‚‚ : f ≀ π“Ÿ s) (ht₁ : IsOpen t) (htβ‚‚ : βˆ€ x ∈ s, ClusterPt x f β†’ x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f βŠ“ π“Ÿ tᢜ) _ _ <| inf_le_of_left_le hfβ‚‚ have : x ∈ t := htβ‚‚ x hx hfx.of_inf_left have : tᢜ ∩ t ∈ 𝓝[tᢜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᢜ] x = βŠ₯ := empty_mem_iff_bot.1 <| compl_inter_self t β–Έ this have : 𝓝[tᢜ] x β‰  βŠ₯ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a LindelΓΆf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ΞΉ : Type v} (hs : IsLindelof s) (U : ΞΉ β†’ Set X) (hUo : βˆ€ i, IsOpen (U i)) (hsU : s βŠ† ⋃ i, U i) : βˆƒ r : Set ΞΉ, r.Countable ∧ (s βŠ† ⋃ i ∈ r, U i) := by have hmono : βˆ€ ⦃s t : Set X⦄, s βŠ† t β†’ (βˆƒ r : Set ΞΉ, r.Countable ∧ t βŠ† ⋃ i ∈ r, U i) β†’ (βˆƒ r : Set ΞΉ, r.Countable ∧ s βŠ† ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : βˆ€ (S : Set (Set X)), S.Countable β†’ (βˆ€ s ∈ S, βˆƒ r : Set ΞΉ, r.Countable ∧ (s βŠ† ⋃ i ∈ r, U i)) β†’ βˆƒ r : Set ΞΉ, r.Countable ∧ (⋃₀ S βŠ† ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine βŸ¨β‹ƒ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : βˆ€ x ∈ s, βˆƒ t ∈ 𝓝[s] x, βˆƒ r : Set ΞΉ, r.Countable ∧ (t βŠ† ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : βˆ€ x ∈ s, Set X) (hU : βˆ€ x (hx : x ∈ s), U x β€Ήx ∈ sβ€Ί ∈ 𝓝 x) : βˆƒ t : Set s, t.Countable ∧ s βŠ† ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnionβ‚‚_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X β†’ Set X) (hU : βˆ€ x ∈ s, U x ∈ 𝓝 x) : βˆƒ t : Set X, t.Countable ∧ (βˆ€ x ∈ t, x ∈ s) ∧ s βŠ† ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine βŸ¨β†‘t, Countable.image htc Subtype.val, ?_⟩ constructor Β· intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto Β· have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- For every nonempty open cover of a LindelΓΆf set, there exists a subcover indexed by β„•. -/ theorem IsLindelof.indexed_countable_subcover {ΞΉ : Type v} [Nonempty ΞΉ] (hs : IsLindelof s) (U : ΞΉ β†’ Set X) (hUo : βˆ€ i, IsOpen (U i)) (hsU : s βŠ† ⋃ i, U i) : βˆƒ f : β„• β†’ ΞΉ, s βŠ† ⋃ n, U (f n) := by obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU rcases c.eq_empty_or_nonempty with rfl | c_nonempty Β· simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const] obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count refine ⟨fun x ↦ f x, c_cov.trans <| iUnionβ‚‚_subset_iff.mpr (?_ : βˆ€ i ∈ c, U i βŠ† ⋃ n, U (f n))⟩ intro x hx obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩ exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn]) /-- The neighborhood filter of a LindelΓΆf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝˒ s) l ↔ βˆ€ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 βŸ¨β‹ƒ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnionβ‚‚] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi)) /-- A filter `l` with the countable intersection property is disjoint with the neighborhood filter of a LindelΓΆf set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint l (𝓝˒ s) ↔ βˆ€ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left /-- For every family of closed sets whose intersection avoids a LindelΓΆ set, there exists a countable subfamily whose intersection avoids this LindelΓΆf set. -/ theorem IsLindelof.elim_countable_subfamily_closed {ΞΉ : Type v} (hs : IsLindelof s) (t : ΞΉ β†’ Set X) (htc : βˆ€ i, IsClosed (t i)) (hst : (s ∩ β‹‚ i, t i) = βˆ…) : βˆƒ u : Set ΞΉ, u.Countable ∧ (s ∩ β‹‚ i ∈ u, t i) = βˆ… := by let U := tᢜ have hUo : βˆ€ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc have hsU : s βŠ† ⋃ i, U i := by simp only [U, Pi.compl_apply] rw [← compl_iInter] apply disjoint_compl_left_iff_subset.mp simp only [compl_iInter, compl_iUnion, compl_compl] apply Disjoint.symm exact disjoint_iff_inter_eq_empty.mpr hst rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩ use u, hucount rw [← disjoint_compl_left_iff_subset] at husub simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub) /-- To show that a LindelΓΆf set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every countable subfamily. -/ theorem IsLindelof.inter_iInter_nonempty {ΞΉ : Type v} (hs : IsLindelof s) (t : ΞΉ β†’ Set X) (htc : βˆ€ i, IsClosed (t i)) (hst : βˆ€ u : Set ΞΉ, u.Countable ∧ (s ∩ β‹‚ i ∈ u, t i).Nonempty) : (s ∩ β‹‚ i, t i).Nonempty := by contrapose! hst rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩ exact ⟨u, fun _ ↦ husub⟩ /-- For every open cover of a LindelΓΆf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover_image {b : Set ΞΉ} {c : ΞΉ β†’ Set X} (hs : IsLindelof s) (hc₁ : βˆ€ i ∈ b, IsOpen (c i)) (hcβ‚‚ : s βŠ† ⋃ i ∈ b, c i) : βˆƒ b', b' βŠ† b ∧ Set.Countable b' ∧ s βŠ† ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hcβ‚‚ rcases hs.elim_countable_subcover (fun i ↦ c i : b β†’ Set X) hc₁ hcβ‚‚ with ⟨d, hd⟩ refine ⟨Subtype.val '' d, by simp, Countable.image hd.1 Subtype.val, ?_⟩ rw [biUnion_image] exact hd.2 /-- A set `s` is LindelΓΆf if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_of_countable_subcover (h : βˆ€ {ΞΉ : Type u} (U : ΞΉ β†’ Set X), (βˆ€ i, IsOpen (U i)) β†’ (s βŠ† ⋃ i, U i) β†’ βˆƒ t : Set ΞΉ, t.Countable ∧ s βŠ† ⋃ i ∈ t, U i) : IsLindelof s := fun f hf hfs ↦ by contrapose! h simp only [ClusterPt, not_neBot, ← disjoint_iff, SetCoe.forall', (nhds_basis_opens _).disjoint_iff_left] at h choose fsub U hU hUf using h refine ⟨s, U, fun x ↦ (hU x).2, fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1 ⟩, ?_⟩ intro t ht h have uinf := f.sets_of_superset (le_principal_iff.1 fsub) h have uninf : β‹‚ i ∈ t, (U i)ᢜ ∈ f := (countable_bInter_mem ht).mpr (fun _ _ ↦ hUf _) rw [← compl_iUnionβ‚‚] at uninf have uninf := compl_not_mem uninf simp only [compl_compl] at uninf contradiction /-- A set `s` is LindelΓΆf if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_of_countable_subfamily_closed (h : βˆ€ {ΞΉ : Type u} (t : ΞΉ β†’ Set X), (βˆ€ i, IsClosed (t i)) β†’ (s ∩ β‹‚ i, t i) = βˆ… β†’ βˆƒ u : Set ΞΉ, u.Countable ∧ (s ∩ β‹‚ i ∈ u, t i) = βˆ…) : IsLindelof s := isLindelof_of_countable_subcover fun U hUo hsU ↦ by rw [← disjoint_compl_right_iff_subset, compl_iUnion, disjoint_iff] at hsU rcases h (fun i ↦ (U i)ᢜ) (fun i ↦ (hUo _).isClosed_compl) hsU with ⟨t, ht⟩ refine ⟨t, ?_⟩ rwa [← disjoint_compl_right_iff_subset, compl_iUnionβ‚‚, disjoint_iff] /-- A set `s` is LindelΓΆf if and only if for every open cover of `s`, there exists a countable subcover. -/ theorem isLindelof_iff_countable_subcover : IsLindelof s ↔ βˆ€ {ΞΉ : Type u} (U : ΞΉ β†’ Set X), (βˆ€ i, IsOpen (U i)) β†’ (s βŠ† ⋃ i, U i) β†’ βˆƒ t : Set ΞΉ, t.Countable ∧ s βŠ† ⋃ i ∈ t, U i := ⟨fun hs ↦ hs.elim_countable_subcover, isLindelof_of_countable_subcover⟩ /-- A set `s` is LindelΓΆf if and only if for every family of closed sets whose intersection avoids `s`, there exists a countable subfamily whose intersection avoids `s`. -/ theorem isLindelof_iff_countable_subfamily_closed : IsLindelof s ↔ βˆ€ {ΞΉ : Type u} (t : ΞΉ β†’ Set X), (βˆ€ i, IsClosed (t i)) β†’ (s ∩ β‹‚ i, t i) = βˆ… β†’ βˆƒ u : Set ΞΉ, u.Countable ∧ (s ∩ β‹‚ i ∈ u, t i) = βˆ… := ⟨fun hs ↦ hs.elim_countable_subfamily_closed, isLindelof_of_countable_subfamily_closed⟩ /-- The empty set is a Lindelof set. -/ @[simp] theorem isLindelof_empty : IsLindelof (βˆ… : Set X) := fun _f hnf _ hsf ↦ Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf /-- A singleton set is a Lindelof set. -/ @[simp] theorem isLindelof_singleton {x : X} : IsLindelof ({x} : Set X) := fun _ hf _ hfa ↦ ⟨x, rfl, ClusterPt.of_le_nhds' (hfa.trans <| by simpa only [principal_singleton] using pure_le_nhds x) hf⟩ theorem Set.Subsingleton.isLindelof (hs : s.Subsingleton) : IsLindelof s := Subsingleton.induction_on hs isLindelof_empty fun _ ↦ isLindelof_singleton theorem Set.Countable.isLindelof_biUnion {s : Set ΞΉ} {f : ΞΉ β†’ Set X} (hs : s.Countable) (hf : βˆ€ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := by apply isLindelof_of_countable_subcover intro i U hU hUcover have hiU : βˆ€ i ∈ s, f i βŠ† ⋃ i, U i := fun _ is ↦ _root_.subset_trans (subset_biUnion_of_mem is) hUcover have iSets := fun i is ↦ (hf i is).elim_countable_subcover U hU (hiU i is) choose! r hr using iSets use ⋃ i ∈ s, r i constructor Β· refine (Countable.biUnion_iff hs).mpr ?h.left.a exact fun s hs ↦ (hr s hs).1 Β· refine iUnionβ‚‚_subset ?h.right.h intro i is simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] intro x hx exact mem_biUnion is ((hr i is).2 hx) theorem Set.Finite.isLindelof_biUnion {s : Set ΞΉ} {f : ΞΉ β†’ Set X} (hs : s.Finite) (hf : βˆ€ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := Set.Countable.isLindelof_biUnion (countable hs) hf theorem Finset.isLindelof_biUnion (s : Finset ΞΉ) {f : ΞΉ β†’ Set X} (hf : βˆ€ i ∈ s, IsLindelof (f i)) : IsLindelof (⋃ i ∈ s, f i) := s.finite_toSet.isLindelof_biUnion hf theorem isLindelof_accumulate {K : β„• β†’ Set X} (hK : βˆ€ n, IsLindelof (K n)) (n : β„•) : IsLindelof (Accumulate K n) := (finite_le_nat n).isLindelof_biUnion fun k _ => hK k theorem Set.Countable.isLindelof_sUnion {S : Set (Set X)} (hf : S.Countable) (hc : βˆ€ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem Set.Finite.isLindelof_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : βˆ€ s ∈ S, IsLindelof s) : IsLindelof (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isLindelof_biUnion hc theorem isLindelof_iUnion {ΞΉ : Sort*} {f : ΞΉ β†’ Set X} [Countable ΞΉ] (h : βˆ€ i, IsLindelof (f i)) : IsLindelof (⋃ i, f i) := (countable_range f).isLindelof_sUnion <| forall_mem_range.2 h theorem Set.Countable.isLindelof (hs : s.Countable) : IsLindelof s := biUnion_of_singleton s β–Έ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton theorem Set.Finite.isLindelof (hs : s.Finite) : IsLindelof s := biUnion_of_singleton s β–Έ hs.isLindelof_biUnion fun _ _ => isLindelof_singleton
Mathlib/Topology/Compactness/Lindelof.lean
364
369
theorem IsLindelof.countable_of_discrete [DiscreteTopology X] (hs : IsLindelof s) : s.Countable := by
have : βˆ€ x : X, ({x} : Set X) ∈ 𝓝 x := by simp [nhds_discrete] rcases hs.elim_nhds_subcover (fun x => {x}) fun x _ => this x with ⟨t, ht, _, hssubt⟩ rw [biUnion_of_singleton] at hssubt exact ht.mono hssubt
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.CategoryTheory.Closed.Cartesian import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Adjunction.FullyFaithful /-! # Cartesian closed functors Define the exponential comparison morphisms for a functor which preserves binary products, and use them to define a cartesian closed functor: one which (naturally) preserves exponentials. Define the Frobenius morphism, and show it is an isomorphism iff the exponential comparison is an isomorphism. ## TODO Some of the results here are true more generally for closed objects and for closed monoidal categories, and these could be generalised. ## References https://ncatlab.org/nlab/show/cartesian+closed+functor https://ncatlab.org/nlab/show/Frobenius+reciprocity ## Tags Frobenius reciprocity, cartesian closed functor -/ noncomputable section namespace CategoryTheory open Category CartesianClosed MonoidalCategory ChosenFiniteProducts TwoSquare universe v u u' variable {C : Type u} [Category.{v} C] variable {D : Type u'} [Category.{v} D] variable [ChosenFiniteProducts C] [ChosenFiniteProducts D] variable (F : C β₯€ D) {L : D β₯€ C} /-- The Frobenius morphism for an adjunction `L ⊣ F` at `A` is given by the morphism L(FA β¨― B) ⟢ LFA β¨― LB ⟢ A β¨― LB natural in `B`, where the first morphism is the product comparison and the latter uses the counit of the adjunction. We will show that if `C` and `D` are cartesian closed, then this morphism is an isomorphism for all `A` iff `F` is a cartesian closed functor, i.e. it preserves exponentials. -/ def frobeniusMorphism (h : L ⊣ F) (A : C) : TwoSquare (tensorLeft (F.obj A)) L L (tensorLeft A) := prodComparisonNatTrans L (F.obj A) ≫ whiskerLeft _ ((curriedTensor C).map (h.counit.app _)) /-- If `F` is full and faithful and has a left adjoint `L` which preserves binary products, then the Frobenius morphism is an isomorphism. -/ instance frobeniusMorphism_iso_of_preserves_binary_products (h : L ⊣ F) (A : C) [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) L] [F.Full] [F.Faithful] : IsIso (frobeniusMorphism F h A).natTrans := suffices βˆ€ (X : D), IsIso ((frobeniusMorphism F h A).natTrans.app X) from NatIso.isIso_of_isIso_app _ fun B ↦ by dsimp [frobeniusMorphism]; infer_instance variable [CartesianClosed C] [CartesianClosed D] variable [Limits.PreservesLimitsOfShape (Discrete Limits.WalkingPair) F] /-- The exponential comparison map. `F` is a cartesian closed functor if this is an iso for all `A`. -/ def expComparison (A : C) : TwoSquare (exp A) F F (exp (F.obj A)) := mateEquiv (exp.adjunction A) (exp.adjunction (F.obj A)) (prodComparisonNatIso F A).inv theorem expComparison_ev (A B : C) : F.obj A ◁ ((expComparison F A).natTrans.app B) ≫ (exp.ev (F.obj A)).app (F.obj B) = inv (prodComparison F _ _) ≫ F.map ((exp.ev _).app _) := by convert mateEquiv_counit _ _ (prodComparisonNatIso F A).inv B using 2 apply IsIso.inv_eq_of_hom_inv_id -- Porting note: was `ext` simp only [prodComparisonNatTrans_app, prodComparisonNatIso_inv, asIso_inv, NatIso.isIso_inv_app, IsIso.hom_inv_id] theorem coev_expComparison (A B : C) : F.map ((exp.coev A).app B) ≫ (expComparison F A).natTrans.app (A βŠ— B) = (exp.coev _).app (F.obj B) ≫ (exp (F.obj A)).map (inv (prodComparison F A B)) := by convert unit_mateEquiv _ _ (prodComparisonNatIso F A).inv B using 3 apply IsIso.inv_eq_of_hom_inv_id -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): was `ext` dsimp simp theorem uncurry_expComparison (A B : C) : CartesianClosed.uncurry ((expComparison F A).natTrans.app B) = inv (prodComparison F _ _) ≫ F.map ((exp.ev _).app _) := by rw [uncurry_eq, expComparison_ev] /-- The exponential comparison map is natural in `A`. -/ theorem expComparison_whiskerLeft {A A' : C} (f : A' ⟢ A) : (expComparison F A).whiskerBottom (pre (F.map f)) = (expComparison F A').whiskerTop (pre f) := by unfold expComparison pre have vcomp1 := mateEquiv_conjugateEquiv_vcomp (exp.adjunction A) (exp.adjunction (F.obj A)) (exp.adjunction (F.obj A')) ((prodComparisonNatIso F A).inv) (((curriedTensor D).map (F.map f))) have vcomp2 := conjugateEquiv_mateEquiv_vcomp (exp.adjunction A) (exp.adjunction A') (exp.adjunction (F.obj A')) (((curriedTensor C).map f)) ((prodComparisonNatIso F A').inv) rw [← vcomp1, ← vcomp2] unfold TwoSquare.whiskerLeft TwoSquare.whiskerRight congr 1 apply congr_arg ext B simp only [Functor.comp_obj, tensorLeft_obj, prodComparisonNatIso_inv, asIso_inv, NatTrans.comp_app, whiskerLeft_app, curriedTensor_map_app, NatIso.isIso_inv_app, whiskerRight_app, IsIso.eq_inv_comp, prodComparisonNatTrans_app] rw [← prodComparison_inv_natural_whiskerRight F f] simp /-- The functor `F` is cartesian closed (ie preserves exponentials) if each natural transformation `exp_comparison F A` is an isomorphism -/ class CartesianClosedFunctor : Prop where comparison_iso : βˆ€ A, IsIso (expComparison F A).natTrans attribute [instance] CartesianClosedFunctor.comparison_iso theorem frobeniusMorphism_mate (h : L ⊣ F) (A : C) : conjugateEquiv (h.comp (exp.adjunction A)) ((exp.adjunction (F.obj A)).comp h) (frobeniusMorphism F h A).natTrans = (expComparison F A).natTrans := by unfold expComparison frobeniusMorphism have conjeq := iterated_mateEquiv_conjugateEquiv h h (exp.adjunction (F.obj A)) (exp.adjunction A) (prodComparisonNatTrans L (F.obj A) ≫ whiskerLeft L ((curriedTensor C).map (h.counit.app A))) rw [← conjeq] congr 1 apply congr_arg ext B unfold mateEquiv simp only [Functor.comp_obj, tensorLeft_obj, Functor.id_obj, Equiv.coe_fn_mk, whiskerLeft_comp, whiskerLeft_twice, whiskerRight_comp, assoc, NatTrans.comp_app, whiskerLeft_app, curriedTensor_obj_obj, whiskerRight_app, prodComparisonNatTrans_app, curriedTensor_map_app, Functor.comp_map, tensorLeft_map, prodComparisonNatIso_inv, asIso_inv, NatIso.isIso_inv_app] rw [← F.map_comp, ← F.map_comp] simp only [Functor.map_comp] apply IsIso.eq_inv_of_inv_hom_id simp only [assoc, Functor.associator_inv_app, Functor.associator_hom_app, Functor.comp_obj, curriedTensor_obj_obj, tensorLeft_obj, Functor.map_id, id_comp] rw [prodComparison_natural_whiskerLeft, prodComparison_natural_whiskerRight_assoc] slice_lhs 2 3 => rw [← prodComparison_comp] simp only [assoc] unfold prodComparison have Ξ·lemma : (h.unit.app (F.obj A βŠ— F.obj B) ≫ lift ((L β‹™ F).map (fst _ _)) ((L β‹™ F).map (snd _ _))) = (h.unit.app (F.obj A)) βŠ— (h.unit.app (F.obj B)) := by ext <;> simp slice_lhs 1 2 => rw [Ξ·lemma] simp only [Functor.id_obj, Functor.comp_obj, assoc, ← whisker_exchange, ← tensorHom_def'] ext <;> simp /-- If the exponential comparison transformation (at `A`) is an isomorphism, then the Frobenius morphism at `A` is an isomorphism. -/
Mathlib/CategoryTheory/Closed/Functor.lean
166
168
theorem frobeniusMorphism_iso_of_expComparison_iso (h : L ⊣ F) (A : C) [i : IsIso (expComparison F A).natTrans] : IsIso (frobeniusMorphism F h A).natTrans := by
rw [← frobeniusMorphism_mate F h] at i
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Patrick Stevens -/ import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Algebra.BigOperators.NatAntidiagonal import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Tactic.Linarith import Mathlib.Tactic.Ring /-! # Sums of binomial coefficients This file includes variants of the binomial theorem and other results on sums of binomial coefficients. Theorems whose proofs depend on such sums may also go in this file for import reasons. -/ open Nat Finset variable {R : Type*} namespace Commute variable [Semiring R] {x y : R} /-- A version of the **binomial theorem** for commuting elements in noncommutative semirings. -/ theorem add_pow (h : Commute x y) (n : β„•) : (x + y) ^ n = βˆ‘ m ∈ range (n + 1), x ^ m * y ^ (n - m) * n.choose m := by let t : β„• β†’ β„• β†’ R := fun n m ↦ x ^ m * y ^ (n - m) * n.choose m change (x + y) ^ n = βˆ‘ m ∈ range (n + 1), t n m have h_first : βˆ€ n, t n 0 = y ^ n := fun n ↦ by simp only [t, choose_zero_right, pow_zero, cast_one, mul_one, one_mul, tsub_zero] have h_last : βˆ€ n, t n n.succ = 0 := fun n ↦ by simp only [t, choose_succ_self, cast_zero, mul_zero] have h_middle : βˆ€ n i : β„•, i ∈ range n.succ β†’ (t n.succ i.succ) = x * t n i + y * t n i.succ := by intro n i h_mem have h_le : i ≀ n := le_of_lt_succ (mem_range.mp h_mem) dsimp only [t] rw [choose_succ_succ, cast_add, mul_add] congr 1 Β· rw [pow_succ' x, succ_sub_succ, mul_assoc, mul_assoc, mul_assoc] Β· rw [← mul_assoc y, ← mul_assoc y, (h.symm.pow_right i.succ).eq] by_cases h_eq : i = n Β· rw [h_eq, choose_succ_self, cast_zero, mul_zero, mul_zero] Β· rw [succ_sub (lt_of_le_of_ne h_le h_eq)] rw [pow_succ' y, mul_assoc, mul_assoc, mul_assoc, mul_assoc] induction n with | zero => rw [pow_zero, sum_range_succ, range_zero, sum_empty, zero_add] dsimp only [t] rw [pow_zero, pow_zero, choose_self, cast_one, mul_one, mul_one] | succ n ih => rw [sum_range_succ', h_first, sum_congr rfl (h_middle n), sum_add_distrib, add_assoc, pow_succ' (x + y), ih, add_mul, mul_sum, mul_sum] congr 1 rw [sum_range_succ', sum_range_succ, h_first, h_last, mul_zero, add_zero, _root_.pow_succ'] /-- A version of `Commute.add_pow` that avoids β„•-subtraction by summing over the antidiagonal and also with the binomial coefficient applied via scalar action of β„•. -/ theorem add_pow' (h : Commute x y) (n : β„•) : (x + y) ^ n = βˆ‘ m ∈ antidiagonal n, n.choose m.1 β€’ (x ^ m.1 * y ^ m.2) := by simp_rw [Nat.sum_antidiagonal_eq_sum_range_succ fun m p ↦ n.choose m β€’ (x ^ m * y ^ p), nsmul_eq_mul, cast_comm, h.add_pow] end Commute /-- The **binomial theorem** -/ theorem add_pow [CommSemiring R] (x y : R) (n : β„•) : (x + y) ^ n = βˆ‘ m ∈ range (n + 1), x ^ m * y ^ (n - m) * n.choose m := (Commute.all x y).add_pow n /-- A special case of the **binomial theorem** -/ theorem sub_pow [CommRing R] (x y : R) (n : β„•) : (x - y) ^ n = βˆ‘ m ∈ range (n + 1), (-1) ^ (m + n) * x ^ m * y ^ (n - m) * n.choose m := by rw [sub_eq_add_neg, add_pow] congr! 1 with m hm have : (-1 : R) ^ (n - m) = (-1) ^ (n + m) := by rw [mem_range] at hm simp [show n + m = n - m + 2 * m by omega, pow_add] rw [neg_pow, this] ring namespace Nat /-- The sum of entries in a row of Pascal's triangle -/ theorem sum_range_choose (n : β„•) : (βˆ‘ m ∈ range (n + 1), n.choose m) = 2 ^ n := by have := (add_pow 1 1 n).symm simpa [one_add_one_eq_two] using this
Mathlib/Data/Nat/Choose/Sum.lean
94
115
theorem sum_range_choose_halfway (m : β„•) : (βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose i) = 4 ^ m := have : (βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose (2 * m + 1 - i)) = βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose i := sum_congr rfl fun i hi ↦ choose_symm <| by linarith [mem_range.1 hi] mul_right_injectiveβ‚€ two_ne_zero <| calc (2 * βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose i) = (βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose i) + βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose (2 * m + 1 - i) := by
rw [two_mul, this] _ = (βˆ‘ i ∈ range (m + 1), (2 * m + 1).choose i) + βˆ‘ i ∈ Ico (m + 1) (2 * m + 2), (2 * m + 1).choose i := by rw [range_eq_Ico, sum_Ico_reflect _ _ (by omega)] congr omega _ = βˆ‘ i ∈ range (2 * m + 2), (2 * m + 1).choose i := sum_range_add_sum_Ico _ (by omega) _ = 2 ^ (2 * m + 1) := sum_range_choose (2 * m + 1) _ = 2 * 4 ^ m := by rw [pow_succ, pow_mul, mul_comm]; rfl theorem choose_middle_le_pow (n : β„•) : (2 * n + 1).choose n ≀ 4 ^ n := by have t : (2 * n + 1).choose n ≀ βˆ‘ i ∈ range (n + 1), (2 * n + 1).choose i := single_le_sum (fun x _ ↦ by omega) (self_mem_range_succ n) simpa [sum_range_choose_halfway n] using t
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Rodriguez -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.Group.ConjFinite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Data.Set.Card import Mathlib.GroupTheory.Subgroup.Center /-! # Class Equation This file establishes the class equation for finite groups. ## Main statements * `Group.card_center_add_sum_card_noncenter_eq_card`: The **class equation** for finite groups. The cardinality of a group is equal to the size of its center plus the sum of the size of all its nontrivial conjugacy classes. Also `Group.nat_card_center_add_sum_card_noncenter_eq_card`. -/ open MulAction ConjClasses variable (G : Type*) [Group G] /-- Conjugacy classes form a partition of G, stated in terms of cardinality. -/ theorem sum_conjClasses_card_eq_card [Fintype <| ConjClasses G] [Fintype G] [βˆ€ x : ConjClasses G, Fintype x.carrier] : βˆ‘ x : ConjClasses G, x.carrier.toFinset.card = Fintype.card G := by suffices (Ξ£ x : ConjClasses G, x.carrier) ≃ G by simpa using (Fintype.card_congr this) simpa [carrier_eq_preimage_mk] using Equiv.sigmaFiberEquiv ConjClasses.mk /-- Conjugacy classes form a partition of G, stated in terms of cardinality. -/ theorem Group.sum_card_conj_classes_eq_card [Finite G] : βˆ‘αΆ  x : ConjClasses G, x.carrier.ncard = Nat.card G := by classical cases nonempty_fintype G rw [Nat.card_eq_fintype_card, ← sum_conjClasses_card_eq_card, finsum_eq_sum_of_fintype] simp [Set.ncard_eq_toFinset_card'] /-- The **class equation** for finite groups. The cardinality of a group is equal to the size of its center plus the sum of the size of all its nontrivial conjugacy classes. -/
Mathlib/GroupTheory/ClassEquation.lean
47
70
theorem Group.nat_card_center_add_sum_card_noncenter_eq_card [Finite G] : Nat.card (Subgroup.center G) + βˆ‘αΆ  x ∈ noncenter G, Nat.card x.carrier = Nat.card G := by
classical cases nonempty_fintype G rw [@Nat.card_eq_fintype_card G, ← sum_conjClasses_card_eq_card, ← Finset.sum_sdiff (ConjClasses.noncenter G).toFinset.subset_univ] simp only [Nat.card_eq_fintype_card, Set.toFinset_card] congr 1 swap Β· convert finsum_cond_eq_sum_of_cond_iff _ _ simp [Set.mem_toFinset] calc Fintype.card (Subgroup.center G) = Fintype.card ((noncenter G)ᢜ : Set _) := Fintype.card_congr ((mk_bijOn G).equiv _) _ = Finset.card (Finset.univ \ (noncenter G).toFinset) := by rw [← Set.toFinset_card, Set.toFinset_compl, Finset.compl_eq_univ_sdiff] _ = _ := ?_ rw [Finset.card_eq_sum_ones] refine Finset.sum_congr rfl ?_ rintro ⟨g⟩ hg simp only [noncenter, Set.not_subsingleton_iff, Set.toFinset_setOf, Finset.mem_univ, true_and, forall_true_left, Finset.mem_sdiff, Finset.mem_filter, Set.not_nontrivial_iff] at hg rw [eq_comm, ← Set.toFinset_card, Finset.card_eq_one] exact ⟨g, Finset.coe_injective <| by simpa using hg.eq_singleton_of_mem mem_carrier_mk⟩
/- 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.Group.Basic import Mathlib.Algebra.Notation.Pi import Mathlib.Data.Set.Lattice import Mathlib.Order.Filter.Defs /-! # Theory of filters on sets A *filter* on a type `Ξ±` is a collection of sets of `Ξ±` which contains the whole `Ξ±`, is upwards-closed, and is stable under intersection. 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... ## Main definitions In this file, we endow `Filter Ξ±` 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 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). ## 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. -/ assert_not_exists OrderedSemiring Fintype open Function Set Order open scoped symmDiff universe u v w x y namespace Filter variable {Ξ± : Type u} {f g : Filter Ξ±} {s t : Set Ξ±} instance inhabitedMem : Inhabited { s : Set Ξ± // s ∈ f } := ⟨⟨univ, f.univ_sets⟩⟩ theorem filter_eq_iff : f = g ↔ f.sets = g.sets := ⟨congr_arg _, filter_eq⟩ @[simp] theorem sets_subset_sets : f.sets βŠ† g.sets ↔ g ≀ f := .rfl @[simp] theorem sets_ssubset_sets : f.sets βŠ‚ g.sets ↔ g < f := .rfl /-- 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 instance : Trans (Β· βŠ‡ Β·) ((Β· ∈ Β·) : Set Ξ± β†’ Filter Ξ± β†’ Prop) (Β· ∈ Β·) where trans h₁ hβ‚‚ := mem_of_superset hβ‚‚ h₁ instance : Trans Membership.mem (Β· βŠ† Β·) (Membership.mem : Filter Ξ± β†’ Set Ξ± β†’ Prop) where trans h₁ hβ‚‚ := mem_of_superset h₁ hβ‚‚ @[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⟩ theorem diff_mem {s t : Set Ξ±} (hs : s ∈ f) (ht : tᢜ ∈ f) : s \ t ∈ f := inter_mem hs ht 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)⟩ lemma copy_eq {S} (hmem : βˆ€ s, s ∈ S ↔ s ∈ f) : f.copy S hmem = f := Filter.ext hmem /-- Weaker version of `Filter.biInter_mem` that assumes `Subsingleton Ξ²` rather than `Finite Ξ²`. -/ theorem biInter_mem' {Ξ² : Type v} {s : Ξ² β†’ Set Ξ±} {is : Set Ξ²} (hf : is.Subsingleton) : (β‹‚ i ∈ is, s i) ∈ f ↔ βˆ€ i ∈ is, s i ∈ f := by apply Subsingleton.induction_on hf <;> simp /-- Weaker version of `Filter.iInter_mem` that assumes `Subsingleton Ξ²` rather than `Finite Ξ²`. -/ theorem iInter_mem' {Ξ² : Sort v} {s : Ξ² β†’ Set Ξ±} [Subsingleton Ξ²] : (β‹‚ i, s i) ∈ f ↔ βˆ€ i, s i ∈ f := by rw [← sInter_range, sInter_eq_biInter, biInter_mem' (subsingleton_range s), forall_mem_range] 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⟩⟩ theorem monotone_mem {f : Filter Ξ±} : Monotone fun s => s ∈ f := fun _ _ hst h => mem_of_superset h hst 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⟩ theorem forall_in_swap {Ξ² : Type*} {p : Set Ξ± β†’ Ξ² β†’ Prop} : (βˆ€ a ∈ f, βˆ€ (b), p a b) ↔ βˆ€ (b), βˆ€ a ∈ f, p a b := Set.forall_in_swap end Filter namespace Filter variable {Ξ± : Type u} {Ξ² : Type v} {Ξ³ : Type w} {Ξ΄ : Type*} {ΞΉ : Sort x} theorem mem_principal_self (s : Set Ξ±) : s ∈ π“Ÿ s := Subset.rfl section Lattice variable {f g : Filter Ξ±} {s t : Set Ξ±} protected theorem not_le : Β¬f ≀ g ↔ βˆƒ s ∈ g, s βˆ‰ f := by simp_rw [le_def, not_forall, exists_prop] /-- `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) /-- `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 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 @[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 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 /-- 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 theorem mem_inf_iff {f g : Filter Ξ±} {s : Set Ξ±} : s ∈ f βŠ“ g ↔ βˆƒ t₁ ∈ f, βˆƒ tβ‚‚ ∈ g, s = t₁ ∩ tβ‚‚ := Iff.rfl 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⟩ 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⟩ 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⟩ 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 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⟩ section CompleteLattice /-- Complete lattice structure on `Filter Ξ±`. -/ instance instCompleteLatticeFilter : CompleteLattice (Filter Ξ±) where inf a b := min a b sup a b := max a b le_sup_left _ _ _ h := h.1 le_sup_right _ _ _ h := h.2 sup_le _ _ _ h₁ hβ‚‚ _ h := ⟨h₁ h, hβ‚‚ h⟩ inf_le_left _ _ _ := mem_inf_of_left inf_le_right _ _ _ := mem_inf_of_right le_inf := fun _ _ _ h₁ hβ‚‚ _s ⟨_a, ha, _b, hb, hs⟩ => hs.symm β–Έ inter_mem (h₁ ha) (hβ‚‚ hb) le_sSup _ _ h₁ _ hβ‚‚ := hβ‚‚ h₁ sSup_le _ _ h₁ _ hβ‚‚ _ h₃ := h₁ _ h₃ hβ‚‚ sInf_le _ _ h₁ _ hβ‚‚ := by rw [← Filter.sSup_lowerBounds]; exact fun _ h₃ ↦ h₃ h₁ hβ‚‚ le_sInf _ _ h₁ _ hβ‚‚ := by rw [← Filter.sSup_lowerBounds] at hβ‚‚; exact hβ‚‚ h₁ le_top _ _ := univ_mem' bot_le _ _ _ := trivial instance : Inhabited (Filter Ξ±) := ⟨βŠ₯⟩ end CompleteLattice theorem NeBot.ne {f : Filter Ξ±} (hf : NeBot f) : f β‰  βŠ₯ := hf.ne' @[simp] theorem not_neBot {f : Filter Ξ±} : Β¬f.NeBot ↔ f = βŠ₯ := neBot_iff.not_left theorem NeBot.mono {f g : Filter Ξ±} (hf : NeBot f) (hg : f ≀ g) : NeBot g := ⟨ne_bot_of_le_ne_bot hf.1 hg⟩ theorem neBot_of_le {f g : Filter Ξ±} [hf : NeBot f] (hg : f ≀ g) : NeBot g := hf.mono hg @[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] theorem not_disjoint_self_iff : Β¬Disjoint f f ↔ f.NeBot := by rw [disjoint_self, neBot_iff] theorem bot_sets_eq : (βŠ₯ : Filter Ξ±).sets = univ := rfl /-- 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 theorem sSup_sets_eq {s : Set (Filter Ξ±)} : (sSup s).sets = β‹‚ f ∈ s, (f : Filter Ξ±).sets := (giGenerate Ξ±).gc.u_sInf theorem iSup_sets_eq {f : ΞΉ β†’ Filter Ξ±} : (iSup f).sets = β‹‚ i, (f i).sets := (giGenerate Ξ±).gc.u_iInf theorem generate_empty : Filter.generate βˆ… = (⊀ : Filter Ξ±) := (giGenerate Ξ±).gc.l_bot theorem generate_univ : Filter.generate univ = (βŠ₯ : Filter Ξ±) := bot_unique fun _ _ => GenerateSets.basic (mem_univ _) theorem generate_union {s t : Set (Set Ξ±)} : Filter.generate (s βˆͺ t) = Filter.generate s βŠ“ Filter.generate t := (giGenerate Ξ±).gc.l_sup theorem generate_iUnion {s : ΞΉ β†’ Set (Set Ξ±)} : Filter.generate (⋃ i, s i) = β¨… i, Filter.generate (s i) := (giGenerate Ξ±).gc.l_iSup @[simp] theorem mem_sup {f g : Filter Ξ±} {s : Set Ξ±} : s ∈ f βŠ” g ↔ s ∈ f ∧ s ∈ g := Iff.rfl 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⟩ @[simp] theorem mem_iSup {x : Set Ξ±} {f : ΞΉ β†’ Filter Ξ±} : x ∈ iSup f ↔ βˆ€ i, x ∈ f i := by simp only [← Filter.mem_sets, iSup_sets_eq, mem_iInter] @[simp] theorem iSup_neBot {f : ΞΉ β†’ Filter Ξ±} : (⨆ i, f i).NeBot ↔ βˆƒ i, (f i).NeBot := by simp [neBot_iff] theorem iInf_eq_generate (s : ΞΉ β†’ Filter Ξ±) : iInf s = generate (⋃ i, (s i).sets) := eq_of_forall_le_iff fun _ ↦ by simp [le_generate_iff] theorem mem_iInf_of_mem {f : ΞΉ β†’ Filter Ξ±} (i : ΞΉ) {s} (hs : s ∈ f i) : s ∈ β¨… i, f i := iInf_le f i hs @[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⟩ theorem Iic_principal (s : Set Ξ±) : Iic (π“Ÿ s) = { l | s ∈ l } := Set.ext fun _ => le_principal_iff theorem principal_mono {s t : Set Ξ±} : π“Ÿ s ≀ π“Ÿ t ↔ s βŠ† t := by simp only [le_principal_iff, mem_principal] @[gcongr] alias ⟨_, _root_.GCongr.filter_principal_mono⟩ := principal_mono @[mono] theorem monotone_principal : Monotone (π“Ÿ : Set Ξ± β†’ Filter Ξ±) := fun _ _ => principal_mono.2 @[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 @[simp] theorem join_principal_eq_sSup {s : Set (Filter Ξ±)} : join (π“Ÿ s) = sSup s := rfl @[simp] theorem principal_univ : π“Ÿ (univ : Set Ξ±) = ⊀ := top_unique <| by simp only [le_principal_iff, mem_top, eq_self_iff_true] @[simp] theorem principal_empty : π“Ÿ (βˆ… : Set Ξ±) = βŠ₯ := bot_unique fun _ _ => empty_subset _ 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] /-! ### 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⟩ 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 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 @[simp] theorem empty_not_mem (f : Filter Ξ±) [NeBot f] : Β¬βˆ… ∈ f := fun h => (nonempty_of_mem h).ne_empty rfl theorem nonempty_of_neBot (f : Filter Ξ±) [NeBot f] : Nonempty Ξ± := nonempty_of_exists <| nonempty_of_mem (univ_mem : univ ∈ f) 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 theorem filter_eq_bot_of_isEmpty [IsEmpty Ξ±] (f : Filter Ξ±) : f = βŠ₯ := empty_mem_iff_bot.mp <| univ_mem' isEmptyElim 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 _ βˆ…] 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⟩ 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⟩ 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] /-- There is exactly one filter on an empty type. -/ instance unique [IsEmpty Ξ±] : Unique (Filter Ξ±) where default := βŠ₯ uniq := filter_eq_bot_of_isEmpty 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 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 _ _⟩ instance instNeBotTop [Nonempty Ξ±] : NeBot (⊀ : Filter Ξ±) := forall_mem_nonempty_iff_neBot.1 fun s hs => by rwa [mem_top.1 hs, ← nonempty_iff_univ_nonempty] instance instNontrivialFilter [Nonempty Ξ±] : Nontrivial (Filter Ξ±) := ⟨⟨⊀, βŠ₯, instNeBotTop.ne⟩⟩ theorem nontrivial_iff_nonempty : Nontrivial (Filter Ξ±) ↔ Nonempty Ξ± := ⟨fun _ => by_contra fun h' => haveI := not_nonempty_iff.1 h' not_subsingleton (Filter Ξ±) inferInstance, @Filter.instNontrivialFilter α⟩ 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 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 (p := (_ ∈ Β·))).symm 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] 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 congr_arg Filter.sets this.symm 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] 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] 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] @[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] @[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] 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⟩ } /-- 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 /-- 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 Ξ±`. -/
Mathlib/Order/Filter/Basic.lean
479
480
theorem iInf_neBot_of_directed {f : ΞΉ β†’ Filter Ξ±} [hn : Nonempty Ξ±] (hd : Directed (Β· β‰₯ Β·) f) (hb : βˆ€ i, NeBot (f i)) : NeBot (iInf f) := by
/- 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, Yury Kudryashov -/ import Mathlib.MeasureTheory.Constructions.BorelSpace.Order import Mathlib.MeasureTheory.MeasurableSpace.Prod import Mathlib.MeasureTheory.Measure.Typeclasses.NoAtoms import Mathlib.Topology.Instances.Real.Lemmas /-! # Borel (measurable) spaces ℝ, ℝβ‰₯0, ℝβ‰₯0∞ ## Main statements * `borel_eq_generateFrom_Ixx_rat` (where Ixx is one of {Ioo, Ioi, Iio, Ici, Iic): the Borel sigma algebra on ℝ is generated by intervals with rational endpoints; * `isPiSystem_Ixx_rat` (where Ixx is one of {Ioo, Ioi, Iio, Ici, Iic): intervals with rational endpoints form a pi system on ℝ; * `measurable_real_toNNReal`, `measurable_coe_nnreal_real`, `measurable_coe_nnreal_ennreal`, `ENNReal.measurable_ofReal`, `ENNReal.measurable_toReal`: measurability of various coercions between ℝ, ℝβ‰₯0, and ℝβ‰₯0∞; * `Measurable.real_toNNReal`, `Measurable.coe_nnreal_real`, `Measurable.coe_nnreal_ennreal`, `Measurable.ennreal_ofReal`, `Measurable.ennreal_toNNReal`, `Measurable.ennreal_toReal`: measurability of functions composed with various coercions between ℝ, ℝβ‰₯0, and ℝβ‰₯0∞ (also similar results for a.e.-measurability); * `Measurable.ennreal*` : measurability of special cases for arithmetic operations on `ℝβ‰₯0∞`. -/ open Set Filter MeasureTheory MeasurableSpace open scoped Topology NNReal ENNReal universe u v w x y variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} {ΞΉ : Sort y} {s t u : Set Ξ±} namespace Real theorem borel_eq_generateFrom_Ioo_rat : borel ℝ = .generateFrom (⋃ (a : β„š) (b : β„š) (_ : a < b), {Ioo (a : ℝ) (b : ℝ)}) := isTopologicalBasis_Ioo_rat.borel_eq_generateFrom
Mathlib/MeasureTheory/Constructions/BorelSpace/Real.lean
44
54
theorem borel_eq_generateFrom_Iio_rat : borel ℝ = .generateFrom (⋃ a : β„š, {Iio (a : ℝ)}) := by
rw [borel_eq_generateFrom_Iio] refine le_antisymm (generateFrom_le ?_) (generateFrom_mono <| iUnion_subset fun q ↦ singleton_subset_iff.mpr <| mem_range_self _) rintro _ ⟨a, rfl⟩ have : IsLUB (range ((↑) : β„š β†’ ℝ) ∩ Iio a) a := by simp [isLUB_iff_le_iff, mem_upperBounds, ← le_iff_forall_rat_lt_imp_le] rw [← this.biUnion_Iio_eq, ← image_univ, ← image_inter_preimage, univ_inter, biUnion_image] exact MeasurableSet.biUnion (to_countable _) fun b _ => GenerateMeasurable.basic (Iio (b : ℝ)) (by simp)
/- Copyright (c) 2024 Ira Fesefeldt. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Ira Fesefeldt -/ import Mathlib.SetTheory.Ordinal.Arithmetic /-! # Ordinal Approximants for the Fixed points on complete lattices This file sets up the ordinal-indexed approximation theory of fixed points of a monotone function in a complete lattice [Cousot1979]. The proof follows loosely the one from [Echenique2005]. However, the proof given here is not constructive as we use the non-constructive axiomatization of ordinals from mathlib. It still allows an approximation scheme indexed over the ordinals. ## Main definitions * `OrdinalApprox.lfpApprox`: The ordinal-indexed approximation of the least fixed point greater or equal than an initial value of a bundled monotone function. * `OrdinalApprox.gfpApprox`: The ordinal-indexed approximation of the greatest fixed point less or equal than an initial value of a bundled monotone function. ## Main theorems * `OrdinalApprox.lfp_mem_range_lfpApprox`: The ordinal-indexed approximation of the least fixed point eventually reaches the least fixed point * `OrdinalApprox.gfp_mem_range_gfpApprox`: The ordinal-indexed approximation of the greatest fixed point eventually reaches the greatest fixed point ## References * [F. Echenique, *A short and constructive proof of Tarski’s fixed-point theorem*][Echenique2005] * [P. Cousot & R. Cousot, *Constructive Versions of Tarski's Fixed Point Theorems*][Cousot1979] ## Tags fixed point, complete lattice, monotone function, ordinals, approximation -/ namespace Cardinal universe u variable {Ξ± : Type u} variable (g : Ordinal β†’ Ξ±) open Cardinal Ordinal SuccOrder Function Set theorem not_injective_limitation_set : Β¬ InjOn g (Iio (ord <| succ #Ξ±)) := by intro h_inj have h := lift_mk_le_lift_mk_of_injective <| injOn_iff_injective.1 h_inj have mk_initialSeg_subtype : #(Iio (ord <| succ #Ξ±)) = lift.{u + 1} (succ #Ξ±) := by simpa only [coe_setOf, card_typein, card_ord] using mk_Iio_ordinal (ord <| succ #Ξ±) rw [mk_initialSeg_subtype, lift_lift, lift_le] at h exact not_le_of_lt (Order.lt_succ #Ξ±) h end Cardinal namespace OrdinalApprox universe u variable {Ξ± : Type u} variable [CompleteLattice Ξ±] (f : Ξ± β†’o Ξ±) (x : Ξ±) open Function fixedPoints Cardinal Order OrderHom set_option linter.unusedVariables false in /-- The ordinal-indexed sequence approximating the least fixed point greater than an initial value `x`. It is defined in such a way that we have `lfpApprox 0 x = x` and `lfpApprox a x = ⨆ b < a, f (lfpApprox b x)`. -/ def lfpApprox (a : Ordinal.{u}) : Ξ± := sSup ({ f (lfpApprox b) | (b : Ordinal) (h : b < a) } βˆͺ {x}) termination_by a decreasing_by exact h theorem lfpApprox_monotone : Monotone (lfpApprox f x) := by intros a b h rw [lfpApprox, lfpApprox] refine sSup_le_sSup ?h apply sup_le_sup_right simp only [exists_prop, Set.le_eq_subset, Set.setOf_subset_setOf, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] intros a' h' use a' exact ⟨lt_of_lt_of_le h' h, rfl⟩ theorem le_lfpApprox {a : Ordinal} : x ≀ lfpApprox f x a := by rw [lfpApprox] apply le_sSup simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, true_or] theorem lfpApprox_add_one (h : x ≀ f x) (a : Ordinal) : lfpApprox f x (a+1) = f (lfpApprox f x a) := by apply le_antisymm Β· conv => left; rw [lfpApprox] apply sSup_le simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] apply And.intro Β· apply le_trans h apply Monotone.imp f.monotone exact le_lfpApprox f x Β· intros a' h apply f.2; apply lfpApprox_monotone; exact h Β· conv => right; rw [lfpApprox] apply le_sSup simp only [Ordinal.add_one_eq_succ, lt_succ_iff, exists_prop] rw [Set.mem_union] apply Or.inl simp only [Set.mem_setOf_eq] use a theorem lfpApprox_mono_left : Monotone (lfpApprox : (Ξ± β†’o Ξ±) β†’ _) := by intro f g h x a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, le_sup_left, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚, true_and] intro i' h_lt apply le_sup_of_le_right apply le_sSup_of_le Β· use i' Β· apply le_trans (h _) simp only [OrderHom.toFun_eq_coe] exact g.monotone (ih i' h_lt) theorem lfpApprox_mono_mid : Monotone (lfpApprox f) := by intro x₁ xβ‚‚ h a induction a using Ordinal.induction with | h i ih => rw [lfpApprox, lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, sSup_insert, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] constructor Β· exact le_sup_of_le_left h Β· intro i' h_i' apply le_sup_of_le_right apply le_sSup_of_le Β· use i' Β· exact f.monotone (ih i' h_i') /-- The approximations of the least fixed point stabilize at a fixed point of `f` -/
Mathlib/SetTheory/Ordinal/FixedPointApproximants.lean
148
161
theorem lfpApprox_eq_of_mem_fixedPoints {a b : Ordinal} (h_init : x ≀ f x) (h_ab : a ≀ b) (h : lfpApprox f x a ∈ fixedPoints f) : lfpApprox f x b = lfpApprox f x a := by
rw [mem_fixedPoints_iff] at h induction b using Ordinal.induction with | h b IH => apply le_antisymm Β· conv => left; rw [lfpApprox] apply sSup_le simp only [exists_prop, Set.union_singleton, Set.mem_insert_iff, Set.mem_setOf_eq, forall_eq_or_imp, forall_exists_index, and_imp, forall_apply_eq_imp_iffβ‚‚] apply And.intro (le_lfpApprox f x) intro a' ha'b by_cases haa : a' < a Β· rw [← lfpApprox_add_one f x h_init] apply lfpApprox_monotone
/- 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.Data.List.Nodup import Mathlib.Data.List.Lattice import Batteries.Data.List.Pairwise /-! # Erasure of duplicates in a list This file proves basic results about `List.dedup` (definition in `Data.List.Defs`). `dedup l` returns `l` without its duplicates. It keeps the earliest (that is, rightmost) occurrence of each. ## Tags duplicate, multiplicity, nodup, `nub` -/ universe u namespace List variable {Ξ± Ξ² : Type*} [DecidableEq Ξ±] @[simp] theorem dedup_nil : dedup [] = ([] : List Ξ±) := rfl theorem dedup_cons_of_mem' {a : Ξ±} {l : List Ξ±} (h : a ∈ dedup l) : dedup (a :: l) = dedup l := pwFilter_cons_of_neg <| by simpa only [forall_mem_ne, not_not] using h theorem dedup_cons_of_not_mem' {a : Ξ±} {l : List Ξ±} (h : a βˆ‰ dedup l) : dedup (a :: l) = a :: dedup l := pwFilter_cons_of_pos <| by simpa only [forall_mem_ne] using h @[simp] theorem mem_dedup {a : Ξ±} {l : List Ξ±} : a ∈ dedup l ↔ a ∈ l := by have := not_congr (@forall_mem_pwFilter Ξ± (Β· β‰  Β·) _ ?_ a l) Β· simpa only [dedup, forall_mem_ne, not_not] using this Β· intros x y z xz exact not_and_or.1 <| mt (fun h ↦ h.1.trans h.2) xz @[simp] theorem dedup_cons_of_mem {a : Ξ±} {l : List Ξ±} (h : a ∈ l) : dedup (a :: l) = dedup l := dedup_cons_of_mem' <| mem_dedup.2 h @[simp] theorem dedup_cons_of_not_mem {a : Ξ±} {l : List Ξ±} (h : a βˆ‰ l) : dedup (a :: l) = a :: dedup l := dedup_cons_of_not_mem' <| mt mem_dedup.1 h theorem dedup_sublist : βˆ€ l : List Ξ±, dedup l <+ l := pwFilter_sublist theorem dedup_subset : βˆ€ l : List Ξ±, dedup l βŠ† l := pwFilter_subset theorem subset_dedup (l : List Ξ±) : l βŠ† dedup l := fun _ => mem_dedup.2 theorem nodup_dedup : βˆ€ l : List Ξ±, Nodup (dedup l) := pairwise_pwFilter theorem headI_dedup [Inhabited Ξ±] (l : List Ξ±) : l.dedup.headI = if l.headI ∈ l.tail then l.tail.dedup.headI else l.headI := match l with | [] => rfl | a :: l => by by_cases ha : a ∈ l <;> simp [ha, List.dedup_cons_of_mem] theorem tail_dedup [Inhabited Ξ±] (l : List Ξ±) : l.dedup.tail = if l.headI ∈ l.tail then l.tail.dedup.tail else l.tail.dedup := match l with | [] => rfl | a :: l => by by_cases ha : a ∈ l <;> simp [ha, List.dedup_cons_of_mem] theorem dedup_eq_self {l : List Ξ±} : dedup l = l ↔ Nodup l := pwFilter_eq_self theorem dedup_eq_cons (l : List Ξ±) (a : Ξ±) (l' : List Ξ±) : l.dedup = a :: l' ↔ a ∈ l ∧ a βˆ‰ l' ∧ l.dedup.tail = l' := by refine ⟨fun h => ?_, fun h => ?_⟩ Β· refine ⟨mem_dedup.1 (h.symm β–Έ mem_cons_self), fun ha => ?_, by rw [h, tail_cons]⟩ have := count_pos_iff.2 ha have : count a l.dedup ≀ 1 := nodup_iff_count_le_one.1 (nodup_dedup l) a rw [h, count_cons_self] at this omega Β· have := @List.cons_head!_tail Ξ± ⟨a⟩ _ (ne_nil_of_mem (mem_dedup.2 h.1)) have hal : a ∈ l.dedup := mem_dedup.2 h.1 rw [← this, mem_cons, or_iff_not_imp_right] at hal exact this β–Έ h.2.2.symm β–Έ cons_eq_cons.2 ⟨(hal (h.2.2.symm β–Έ h.2.1)).symm, rfl⟩ @[simp] theorem dedup_eq_nil (l : List Ξ±) : l.dedup = [] ↔ l = [] := by induction l with | nil => exact Iff.rfl | cons a l hl => by_cases h : a ∈ l Β· simp only [List.dedup_cons_of_mem h, hl, List.ne_nil_of_mem h, reduceCtorEq] Β· simp only [List.dedup_cons_of_not_mem h, List.cons_ne_nil] protected theorem Nodup.dedup {l : List Ξ±} (h : l.Nodup) : l.dedup = l := List.dedup_eq_self.2 h @[simp] theorem dedup_idem {l : List Ξ±} : dedup (dedup l) = dedup l := pwFilter_idem theorem dedup_append (l₁ lβ‚‚ : List Ξ±) : dedup (l₁ ++ lβ‚‚) = l₁ βˆͺ dedup lβ‚‚ := by induction l₁ with | nil => rfl | cons a l₁ IH => ?_ simp only [cons_union] at * rw [← IH, cons_append] by_cases h : a ∈ dedup (l₁ ++ lβ‚‚) Β· rw [dedup_cons_of_mem' h, insert_of_mem h] Β· rw [dedup_cons_of_not_mem' h, insert_of_not_mem h] theorem dedup_map_of_injective [DecidableEq Ξ²] {f : Ξ± β†’ Ξ²} (hf : Function.Injective f) (xs : List Ξ±) : (xs.map f).dedup = xs.dedup.map f := by induction xs with | nil => simp | cons x xs ih => rw [map_cons] by_cases h : x ∈ xs Β· rw [dedup_cons_of_mem h, dedup_cons_of_mem (mem_map_of_mem h), ih] Β· rw [dedup_cons_of_not_mem h, dedup_cons_of_not_mem <| (mem_map_of_injective hf).not.mpr h, ih, map_cons] /-- Note that the weaker `List.Subset.dedup_append_left` is proved later. -/ theorem Subset.dedup_append_right {xs ys : List Ξ±} (h : xs βŠ† ys) : dedup (xs ++ ys) = dedup ys := by rw [List.dedup_append, Subset.union_eq_right (List.Subset.trans h <| subset_dedup _)]
Mathlib/Data/List/Dedup.lean
135
140
theorem Disjoint.union_eq {xs ys : List Ξ±} (h : Disjoint xs ys) : xs βˆͺ ys = xs.dedup ++ ys := by
induction xs with | nil => simp | cons x xs ih => rw [cons_union]
/- Copyright (c) 2022 MarΓ­a InΓ©s de Frutos-FernΓ‘ndez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: MarΓ­a InΓ©s de Frutos-FernΓ‘ndez -/ import Mathlib.RingTheory.DedekindDomain.Ideal import Mathlib.RingTheory.Valuation.ExtendToLocalization import Mathlib.Topology.Algebra.Valued.ValuedField import Mathlib.Topology.Algebra.Valued.WithVal /-! # Adic valuations on Dedekind domains Given a Dedekind domain `R` of Krull dimension 1 and a maximal ideal `v` of `R`, we define the `v`-adic valuation on `R` and its extension to the field of fractions `K` of `R`. We prove several properties of this valuation, including the existence of uniformizers. We define the completion of `K` with respect to the `v`-adic valuation, denoted `v.adicCompletion`, and its ring of integers, denoted `v.adicCompletionIntegers`. ## Main definitions - `IsDedekindDomain.HeightOneSpectrum.intValuation v` is the `v`-adic valuation on `R`. - `IsDedekindDomain.HeightOneSpectrum.valuation v` is the `v`-adic valuation on `K`. - `IsDedekindDomain.HeightOneSpectrum.adicCompletion v` is the completion of `K` with respect to its `v`-adic valuation. - `IsDedekindDomain.HeightOneSpectrum.adicCompletionIntegers v` is the ring of integers of `v.adicCompletion`. ## Main results - `IsDedekindDomain.HeightOneSpectrum.intValuation_le_one` : The `v`-adic valuation on `R` is bounded above by 1. - `IsDedekindDomain.HeightOneSpectrum.intValuation_lt_one_iff_dvd` : The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. - `IsDedekindDomain.HeightOneSpectrum.intValuation_le_pow_iff_dvd` : The `v`-adic valuation of `r ∈ R` is less than or equal to `Multiplicative.ofAdd (-n)` if and only if `vⁿ` divides the ideal `(r)`. - `IsDedekindDomain.HeightOneSpectrum.intValuation_exists_uniformizer` : There exists `Ο€ ∈ R` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. - `IsDedekindDomain.HeightOneSpectrum.valuation_of_mk'` : The `v`-adic valuation of `r/s ∈ K` is the valuation of `r` divided by the valuation of `s`. - `IsDedekindDomain.HeightOneSpectrum.valuation_of_algebraMap` : The `v`-adic valuation on `K` extends the `v`-adic valuation on `R`. - `IsDedekindDomain.HeightOneSpectrum.valuation_exists_uniformizer` : There exists `Ο€ ∈ K` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. ## Implementation notes We are only interested in Dedekind domains with Krull dimension 1. ## References * [G. J. Janusz, *Algebraic Number Fields*][janusz1996] * [J.W.S. Cassels, A. FrΓΆhlich, *Algebraic Number Theory*][cassels1967algebraic] * [J. Neukirch, *Algebraic Number Theory*][Neukirch1992] ## Tags dedekind domain, dedekind ring, adic valuation -/ noncomputable section open scoped Multiplicative open Multiplicative IsDedekindDomain variable {R : Type*} [CommRing R] [IsDedekindDomain R] {K S : Type*} [Field K] [CommSemiring S] [Algebra R K] [IsFractionRing R K] (v : HeightOneSpectrum R) namespace IsDedekindDomain.HeightOneSpectrum /-! ### Adic valuations on the Dedekind domain R -/ open scoped Classical in /-- The additive `v`-adic valuation of `r ∈ R` is the exponent of `v` in the factorization of the ideal `(r)`, if `r` is nonzero, or infinity, if `r = 0`. `intValuationDef` is the corresponding multiplicative valuation. -/ def intValuationDef (r : R) : β„€β‚˜β‚€ := if r = 0 then 0 else ↑(Multiplicative.ofAdd (-(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {r} : Ideal R)).factors : β„€)) theorem intValuationDef_if_pos {r : R} (hr : r = 0) : v.intValuationDef r = 0 := if_pos hr @[simp] theorem intValuationDef_zero : v.intValuationDef 0 = 0 := if_pos rfl open scoped Classical in theorem intValuationDef_if_neg {r : R} (hr : r β‰  0) : v.intValuationDef r = Multiplicative.ofAdd (-(Associates.mk v.asIdeal).count (Associates.mk (Ideal.span {r} : Ideal R)).factors : β„€) := if_neg hr /-- Nonzero elements have nonzero adic valuation. -/ theorem intValuation_ne_zero (x : R) (hx : x β‰  0) : v.intValuationDef x β‰  0 := by rw [intValuationDef, if_neg hx] exact WithZero.coe_ne_zero /-- Nonzero divisors have nonzero valuation. -/ theorem intValuation_ne_zero' (x : nonZeroDivisors R) : v.intValuationDef x β‰  0 := v.intValuation_ne_zero x (nonZeroDivisors.coe_ne_zero x) /-- Nonzero divisors have valuation greater than zero. -/ theorem intValuation_zero_le (x : nonZeroDivisors R) : 0 < v.intValuationDef x := by rw [v.intValuationDef_if_neg (nonZeroDivisors.coe_ne_zero x)] exact WithZero.zero_lt_coe _ /-- The `v`-adic valuation on `R` is bounded above by 1. -/ theorem intValuation_le_one (x : R) : v.intValuationDef x ≀ 1 := by rw [intValuationDef] by_cases hx : x = 0 Β· rw [if_pos hx]; exact WithZero.zero_le 1 Β· rw [if_neg hx, ← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_le_coe, ofAdd_le, Right.neg_nonpos_iff] exact Int.natCast_nonneg _ /-- The `v`-adic valuation of `r ∈ R` is less than 1 if and only if `v` divides the ideal `(r)`. -/ theorem intValuation_lt_one_iff_dvd (r : R) : v.intValuationDef r < 1 ↔ v.asIdeal ∣ Ideal.span {r} := by classical rw [intValuationDef] split_ifs with hr Β· simp [hr] Β· rw [← WithZero.coe_one, ← ofAdd_zero, WithZero.coe_lt_coe, ofAdd_lt, neg_lt_zero, ← Int.ofNat_zero, Int.ofNat_lt, zero_lt_iff] have h : (Ideal.span {r} : Ideal R) β‰  0 := by rw [Ne, Ideal.zero_eq_bot, Ideal.span_singleton_eq_bot] exact hr apply Associates.count_ne_zero_iff_dvd h (by apply v.irreducible) /-- The `v`-adic valuation of `r ∈ R` is less than `Multiplicative.ofAdd (-n)` if and only if `vⁿ` divides the ideal `(r)`. -/ theorem intValuation_le_pow_iff_dvd (r : R) (n : β„•) : v.intValuationDef r ≀ Multiplicative.ofAdd (-(n : β„€)) ↔ v.asIdeal ^ n ∣ Ideal.span {r} := by classical rw [intValuationDef] split_ifs with hr Β· simp_rw [hr, Ideal.dvd_span_singleton, zero_le', Submodule.zero_mem] Β· rw [WithZero.coe_le_coe, ofAdd_le, neg_le_neg_iff, Int.ofNat_le, Ideal.dvd_span_singleton, ← Associates.le_singleton_iff, Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hr) (by apply v.associates_irreducible)] /-- The `v`-adic valuation of `0 : R` equals 0. -/ theorem intValuation.map_zero' : v.intValuationDef 0 = 0 := v.intValuationDef_if_pos (Eq.refl 0) /-- The `v`-adic valuation of `1 : R` equals 1. -/ theorem intValuation.map_one' : v.intValuationDef 1 = 1 := by classical rw [v.intValuationDef_if_neg (zero_ne_one.symm : (1 : R) β‰  0), Ideal.span_singleton_one, ← Ideal.one_eq_top, Associates.mk_one, Associates.factors_one, Associates.count_zero (by apply v.associates_irreducible), Int.ofNat_zero, neg_zero, ofAdd_zero, WithZero.coe_one] /-- The `v`-adic valuation of a product equals the product of the valuations. -/ theorem intValuation.map_mul' (x y : R) : v.intValuationDef (x * y) = v.intValuationDef x * v.intValuationDef y := by classical simp only [intValuationDef] by_cases hx : x = 0 Β· rw [hx, zero_mul, if_pos (Eq.refl _), zero_mul] Β· by_cases hy : y = 0 Β· rw [hy, mul_zero, if_pos (Eq.refl _), mul_zero] Β· rw [if_neg hx, if_neg hy, if_neg (mul_ne_zero hx hy), ← WithZero.coe_mul, WithZero.coe_inj, ← ofAdd_add, ← Ideal.span_singleton_mul_span_singleton, ← Associates.mk_mul_mk, ← neg_add, Associates.count_mul (by apply Associates.mk_ne_zero'.mpr hx) (by apply Associates.mk_ne_zero'.mpr hy) (by apply v.associates_irreducible)] rfl theorem intValuation.le_max_iff_min_le {a b c : β„•} : Multiplicative.ofAdd (-c : β„€) ≀ max (Multiplicative.ofAdd (-a : β„€)) (Multiplicative.ofAdd (-b : β„€)) ↔ min a b ≀ c := by rw [le_max_iff, ofAdd_le, ofAdd_le, neg_le_neg_iff, neg_le_neg_iff, Int.ofNat_le, Int.ofNat_le, ← min_le_iff] /-- The `v`-adic valuation of a sum is bounded above by the maximum of the valuations. -/ theorem intValuation.map_add_le_max' (x y : R) : v.intValuationDef (x + y) ≀ max (v.intValuationDef x) (v.intValuationDef y) := by classical by_cases hx : x = 0 Β· rw [hx, zero_add] conv_rhs => rw [intValuationDef, if_pos (Eq.refl _)] rw [max_eq_right (WithZero.zero_le (v.intValuationDef y))] Β· by_cases hy : y = 0 Β· rw [hy, add_zero] conv_rhs => rw [max_comm, intValuationDef, if_pos (Eq.refl _)] rw [max_eq_right (WithZero.zero_le (v.intValuationDef x))] Β· by_cases hxy : x + y = 0 Β· rw [intValuationDef, if_pos hxy]; exact zero_le' Β· rw [v.intValuationDef_if_neg hxy, v.intValuationDef_if_neg hx, v.intValuationDef_if_neg hy, WithZero.le_max_iff, intValuation.le_max_iff_min_le] set nmin := min ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span { x })).factors) ((Associates.mk v.asIdeal).count (Associates.mk (Ideal.span { y })).factors) have h_dvd_x : x ∈ v.asIdeal ^ nmin := by rw [← Associates.le_singleton_iff x nmin _, Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hx) _] Β· exact min_le_left _ _ apply v.associates_irreducible have h_dvd_y : y ∈ v.asIdeal ^ nmin := by rw [← Associates.le_singleton_iff y nmin _, Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hy) _] Β· exact min_le_right _ _ apply v.associates_irreducible have h_dvd_xy : Associates.mk v.asIdeal ^ nmin ≀ Associates.mk (Ideal.span {x + y}) := by rw [Associates.le_singleton_iff] exact Ideal.add_mem (v.asIdeal ^ nmin) h_dvd_x h_dvd_y rw [Associates.prime_pow_dvd_iff_le (Associates.mk_ne_zero'.mpr hxy) _] at h_dvd_xy Β· exact h_dvd_xy apply v.associates_irreducible /-- The `v`-adic valuation on `R`. -/ @[simps] def intValuation : Valuation R β„€β‚˜β‚€ where toFun := v.intValuationDef map_zero' := intValuation.map_zero' v map_one' := intValuation.map_one' v map_mul' := intValuation.map_mul' v map_add_le_max' := intValuation.map_add_le_max' v theorem intValuation_apply {r : R} (v : IsDedekindDomain.HeightOneSpectrum R) : intValuation v r = intValuationDef v r := rfl /-- There exists `Ο€ ∈ R` with `v`-adic valuation `Multiplicative.ofAdd (-1)`. -/ theorem intValuation_exists_uniformizer : βˆƒ Ο€ : R, v.intValuationDef Ο€ = Multiplicative.ofAdd (-1 : β„€) := by classical have hv : _root_.Irreducible (Associates.mk v.asIdeal) := v.associates_irreducible have hlt : v.asIdeal ^ 2 < v.asIdeal := by rw [← Ideal.dvdNotUnit_iff_lt] exact ⟨v.ne_bot, v.asIdeal, (not_congr Ideal.isUnit_iff).mpr (Ideal.IsPrime.ne_top v.isPrime), sq v.asIdeal⟩ obtain βŸ¨Ο€, mem, nmem⟩ := SetLike.exists_of_lt hlt have hΟ€ : Associates.mk (Ideal.span {Ο€}) β‰  0 := by rw [Associates.mk_ne_zero'] intro h rw [h] at nmem exact nmem (Submodule.zero_mem (v.asIdeal ^ 2)) use Ο€ rw [intValuationDef, if_neg (Associates.mk_ne_zero'.mp hΟ€), WithZero.coe_inj] apply congr_arg rw [neg_inj, ← Int.ofNat_one, Int.natCast_inj] rw [← Ideal.dvd_span_singleton, ← Associates.mk_le_mk_iff_dvd] at mem nmem rw [← pow_one (Associates.mk v.asIdeal), Associates.prime_pow_dvd_iff_le hΟ€ hv] at mem rw [Associates.mk_pow, Associates.prime_pow_dvd_iff_le hΟ€ hv, not_le] at nmem exact Nat.eq_of_le_of_lt_succ mem nmem /-- The `I`-adic valuation of a generator of `I` equals `(-1 : β„€β‚˜β‚€)` -/ theorem intValuation_singleton {r : R} (hr : r β‰  0) (hv : v.asIdeal = Ideal.span {r}) : v.intValuation r = Multiplicative.ofAdd (-1 : β„€) := by classical rw [intValuation_apply, v.intValuationDef_if_neg hr, ← hv, Associates.count_self, Int.ofNat_one, ofAdd_neg, WithZero.coe_inv] apply v.associates_irreducible /-! ### Adic valuations on the field of fractions `K` -/ variable (K) in /-- The `v`-adic valuation of `x ∈ K` is the valuation of `r` divided by the valuation of `s`, where `r` and `s` are chosen so that `x = r/s`. -/ def valuation (v : HeightOneSpectrum R) : Valuation K β„€β‚˜β‚€ := v.intValuation.extendToLocalization (fun r hr => Set.mem_compl <| v.intValuation_ne_zero' ⟨r, hr⟩) K theorem valuation_def (x : K) : v.valuation K x = v.intValuation.extendToLocalization (fun r hr => Set.mem_compl (v.intValuation_ne_zero' ⟨r, hr⟩)) K x := rfl /-- The `v`-adic valuation of `r/s ∈ K` is the valuation of `r` divided by the valuation of `s`. -/ theorem valuation_of_mk' {r : R} {s : nonZeroDivisors R} : v.valuation K (IsLocalization.mk' K r s) = v.intValuation r / v.intValuation s := by rw [valuation_def, Valuation.extendToLocalization_mk', div_eq_mul_inv] open scoped algebraMap in /-- The `v`-adic valuation on `K` extends the `v`-adic valuation on `R`. -/ theorem valuation_of_algebraMap (r : R) : v.valuation K r = v.intValuation r := by rw [valuation_def, Valuation.extendToLocalization_apply_map_apply] open scoped algebraMap in lemma valuation_eq_intValuationDef (r : R) : v.valuation K r = v.intValuationDef r := Valuation.extendToLocalization_apply_map_apply .. open scoped algebraMap in /-- The `v`-adic valuation on `R` is bounded above by 1. -/
Mathlib/RingTheory/DedekindDomain/AdicValuation.lean
290
291
theorem valuation_le_one (r : R) : v.valuation K r ≀ 1 := by
rw [valuation_of_algebraMap]; exact v.intValuation_le_one r
/- Copyright (c) 2019 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Module.Submodule.Equiv import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Rat import Mathlib.Data.Bracket import Mathlib.Tactic.Abel /-! # Lie algebras This file defines Lie rings and Lie algebras over a commutative ring together with their modules, morphisms and equivalences, as well as various lemmas to make these definitions usable. ## Main definitions * `LieRing` * `LieAlgebra` * `LieRingModule` * `LieModule` * `LieHom` * `LieEquiv` * `LieModuleHom` * `LieModuleEquiv` ## Notation Working over a fixed commutative ring `R`, we introduce the notations: * `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras, * `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras, * `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`, * `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`. ## Implementation notes Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules, are partially unbundled. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) ## Tags lie bracket, jacobi identity, lie ring, lie algebra, lie module -/ universe u v w w₁ wβ‚‚ open Function /-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the Jacobi identity. -/ class LieRing (L : Type v) extends AddCommGroup L, Bracket L L where /-- A Lie ring bracket is additive in its first component. -/ protected add_lie : βˆ€ x y z : L, ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ /-- A Lie ring bracket is additive in its second component. -/ protected lie_add : βˆ€ x y z : L, ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆ /-- A Lie ring bracket vanishes on the diagonal in L Γ— L. -/ protected lie_self : βˆ€ x : L, ⁅x, x⁆ = 0 /-- A Lie ring bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : βˆ€ x y z : L, ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ /-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/ @[ext] class LieAlgebra (R : Type u) (L : Type v) [CommRing R] [LieRing L] extends Module R L where /-- A Lie algebra bracket is compatible with scalar multiplication in its second argument. The compatibility in the first argument is not a class property, but follows since every Lie algebra has a natural Lie module action on itself, see `LieModule`. -/ protected lie_smul : βˆ€ (t : R) (x y : L), ⁅x, t β€’ y⁆ = t β€’ ⁅x, y⁆ /-- A Lie ring module is an additive group, together with an additive action of a Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms. (For representations of Lie *algebras* see `LieModule`.) -/ class LieRingModule (L : Type v) (M : Type w) [LieRing L] [AddCommGroup M] extends Bracket L M where /-- A Lie ring module bracket is additive in its first component. -/ protected add_lie : βˆ€ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ /-- A Lie ring module bracket is additive in its second component. -/ protected lie_add : βˆ€ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ /-- A Lie ring module bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : βˆ€ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ /-- A Lie module is a module over a commutative ring, together with a linear action of a Lie algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/ class LieModule (R : Type u) (L : Type v) (M : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] : Prop where /-- A Lie module bracket is compatible with scalar multiplication in its first argument. -/ protected smul_lie : βˆ€ (t : R) (x : L) (m : M), ⁅t β€’ x, m⁆ = t β€’ ⁅x, m⁆ /-- A Lie module bracket is compatible with scalar multiplication in its second argument. -/ protected lie_smul : βˆ€ (t : R) (x : L) (m : M), ⁅x, t β€’ m⁆ = t β€’ ⁅x, m⁆ /-- A tower of Lie bracket actions encapsulates the Leibniz rule for Lie bracket actions. More precisely, it does so in a relative setting: Let `L₁` and `Lβ‚‚` be two types with Lie bracket actions on a type `M` endowed with an addition, and additionally assume a Lie bracket action of `L₁` on `Lβ‚‚`. Then the Leibniz rule asserts for all `x : L₁`, `y : Lβ‚‚`, and `m : M` that `⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆` holds. Common examples include the case where `L₁` is a Lie subalgebra of `Lβ‚‚` and the case where `Lβ‚‚` is a Lie ideal of `L₁`. -/ class IsLieTower (L₁ Lβ‚‚ M : Type*) [Bracket L₁ Lβ‚‚] [Bracket L₁ M] [Bracket Lβ‚‚ M] [Add M] where protected leibniz_lie (x : L₁) (y : Lβ‚‚) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ section IsLieTower variable {L₁ Lβ‚‚ M : Type*} [Bracket L₁ Lβ‚‚] [Bracket L₁ M] [Bracket Lβ‚‚ M] lemma leibniz_lie [Add M] [IsLieTower L₁ Lβ‚‚ M] (x : L₁) (y : Lβ‚‚) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := IsLieTower.leibniz_lie x y m lemma lie_swap_lie [Bracket Lβ‚‚ L₁] [AddCommGroup M] [IsLieTower L₁ Lβ‚‚ M] [IsLieTower Lβ‚‚ L₁ M] (x : L₁) (y : Lβ‚‚) (m : M) : ⁅⁅x, y⁆, m⁆ = -⁅⁅y, x⁆, m⁆ := by have h1 := leibniz_lie x y m have h2 := leibniz_lie y x m convert congr($h1.symm - $h2) using 1 <;> simp only [add_sub_cancel_right, sub_add_cancel_right] end IsLieTower section BasicProperties theorem LieAlgebra.toModule_injective (L : Type*) [LieRing L] : Function.Injective (@LieAlgebra.toModule _ _ _ _ : LieAlgebra β„š L β†’ Module β„š L) := by rintro ⟨hβ‚βŸ© ⟨hβ‚‚βŸ© heq congr instance (L : Type*) [LieRing L] : Subsingleton (LieAlgebra β„š L) := LieAlgebra.toModule_injective L |>.subsingleton variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] variable (t : R) (x y z : L) (m n : M) @[simp] theorem add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := LieRingModule.add_lie x y m @[simp] theorem lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := LieRingModule.lie_add x m n @[simp] theorem smul_lie : ⁅t β€’ x, m⁆ = t β€’ ⁅x, m⁆ := LieModule.smul_lie t x m @[simp] theorem lie_smul : ⁅x, t β€’ m⁆ = t β€’ ⁅x, m⁆ := LieModule.lie_smul t x m instance : IsLieTower L L M where leibniz_lie x y m := LieRingModule.leibniz_lie x y m @[simp] theorem lie_zero : ⁅x, 0⁆ = (0 : M) := (AddMonoidHom.mk' _ (lie_add x)).map_zero @[simp] theorem zero_lie : ⁅(0 : L), m⁆ = 0 := (AddMonoidHom.mk' (fun x : L => ⁅x, m⁆) fun x y => add_lie x y m).map_zero @[simp] theorem lie_self : ⁅x, x⁆ = 0 := LieRing.lie_self x instance lieRingSelfModule : LieRingModule L L := { (inferInstance : LieRing L) with } @[simp] theorem lie_skew : -⁅y, x⁆ = ⁅x, y⁆ := by have h : ⁅x + y, x⁆ + ⁅x + y, y⁆ = 0 := by rw [← lie_add]; apply lie_self simpa [neg_eq_iff_add_eq_zero] using h /-- Every Lie algebra is a module over itself. -/ instance lieAlgebraSelfModule : LieModule R L L where smul_lie t x m := by rw [← lie_skew, ← lie_skew x m, LieAlgebra.lie_smul, smul_neg] lie_smul := by apply LieAlgebra.lie_smul @[simp] theorem neg_lie : ⁅-x, m⁆ = -⁅x, m⁆ := by rw [← sub_eq_zero, sub_neg_eq_add, ← add_lie] simp @[simp] theorem lie_neg : ⁅x, -m⁆ = -⁅x, m⁆ := by rw [← sub_eq_zero, sub_neg_eq_add, ← lie_add] simp @[simp] theorem sub_lie : ⁅x - y, m⁆ = ⁅x, m⁆ - ⁅y, m⁆ := by simp [sub_eq_add_neg] @[simp] theorem lie_sub : ⁅x, m - n⁆ = ⁅x, m⁆ - ⁅x, n⁆ := by simp [sub_eq_add_neg] @[simp] theorem nsmul_lie (n : β„•) : ⁅n β€’ x, m⁆ = n β€’ ⁅x, m⁆ := AddMonoidHom.map_nsmul { toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ } _ _ @[simp] theorem lie_nsmul (n : β„•) : ⁅x, n β€’ m⁆ = n β€’ ⁅x, m⁆ := AddMonoidHom.map_nsmul { toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _} _ _ theorem zsmul_lie (a : β„€) : ⁅a β€’ x, m⁆ = a β€’ ⁅x, m⁆ := AddMonoidHom.map_zsmul { toFun := fun x : L => ⁅x, m⁆, map_zero' := zero_lie m, map_add' := fun _ _ => add_lie _ _ _ } _ _ theorem lie_zsmul (a : β„€) : ⁅x, a β€’ m⁆ = a β€’ ⁅x, m⁆ := AddMonoidHom.map_zsmul { toFun := fun m : M => ⁅x, m⁆, map_zero' := lie_zero x, map_add' := fun _ _ => lie_add _ _ _ } _ _ @[simp] lemma lie_lie : ⁅⁅x, y⁆, m⁆ = ⁅x, ⁅y, m⁆⁆ - ⁅y, ⁅x, m⁆⁆ := by rw [leibniz_lie, add_sub_cancel_right] theorem lie_jacobi : ⁅x, ⁅y, z⁆⁆ + ⁅y, ⁅z, x⁆⁆ + ⁅z, ⁅x, y⁆⁆ = 0 := by rw [← neg_neg ⁅x, y⁆, lie_neg z, lie_skew y x, ← lie_skew, lie_lie] abel instance LieRing.instLieAlgebra : LieAlgebra β„€ L where lie_smul n x y := lie_zsmul x y n instance : LieModule β„€ L M where smul_lie n x m := zsmul_lie x m n lie_smul n x m := lie_zsmul x m n instance LinearMap.instLieRingModule : LieRingModule L (M β†’β‚—[R] N) where bracket x f := { toFun := fun m => ⁅x, f m⁆ - f ⁅x, m⁆ map_add' := fun m n => by simp only [lie_add, LinearMap.map_add] abel map_smul' := fun t m => by simp only [smul_sub, LinearMap.map_smul, lie_smul, RingHom.id_apply] } add_lie x y f := by ext n simp only [add_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.add_apply, LinearMap.map_add] abel lie_add x f g := by ext n simp only [LinearMap.coe_mk, AddHom.coe_mk, lie_add, LinearMap.add_apply] abel leibniz_lie x y f := by ext n simp only [lie_lie, LinearMap.coe_mk, AddHom.coe_mk, LinearMap.map_sub, LinearMap.add_apply, lie_sub] abel @[simp] theorem LieHom.lie_apply (f : M β†’β‚—[R] N) (x : L) (m : M) : ⁅x, f⁆ m = ⁅x, f m⁆ - f ⁅x, m⁆ := rfl instance LinearMap.instLieModule : LieModule R L (M β†’β‚—[R] N) where smul_lie t x f := by ext n simp only [smul_sub, smul_lie, LinearMap.smul_apply, LieHom.lie_apply, LinearMap.map_smul] lie_smul t x f := by ext n simp only [smul_sub, LinearMap.smul_apply, LieHom.lie_apply, lie_smul] /-- We could avoid defining this by instead defining a `LieRingModule L R` instance with a zero bracket and relying on `LinearMap.instLieRingModule`. We do not do this because in the case that `L = R` we would have a non-defeq diamond via `Ring.instBracket`. -/ instance Module.Dual.instLieRingModule : LieRingModule L (M β†’β‚—[R] R) where bracket := fun x f ↦ { toFun := fun m ↦ - f ⁅x, m⁆ map_add' := by simp [-neg_add_rev, neg_add] map_smul' := by simp } add_lie := fun x y m ↦ by ext n; simp [-neg_add_rev, neg_add] lie_add := fun x m n ↦ by ext p; simp [-neg_add_rev, neg_add] leibniz_lie := fun x m n ↦ by ext p; simp @[simp] lemma Module.Dual.lie_apply (f : M β†’β‚—[R] R) : ⁅x, f⁆ m = - f ⁅x, m⁆ := rfl instance Module.Dual.instLieModule : LieModule R L (M β†’β‚—[R] R) where smul_lie := fun t x m ↦ by ext n; simp lie_smul := fun t x m ↦ by ext n; simp variable (L) in /-- It is sometimes useful to regard a `LieRing` as a `NonUnitalNonAssocRing`. -/ def LieRing.toNonUnitalNonAssocRing : NonUnitalNonAssocRing L := { mul := Bracket.bracket left_distrib := lie_add right_distrib := add_lie zero_mul := zero_lie mul_zero := lie_zero } variable {ΞΉ ΞΊ : Type*} theorem sum_lie (s : Finset ΞΉ) (f : ΞΉ β†’ L) (a : L) : β…βˆ‘ i ∈ s, f i, a⁆ = βˆ‘ i ∈ s, ⁅f i, a⁆ := let _i := LieRing.toNonUnitalNonAssocRing L s.sum_mul f a theorem lie_sum (s : Finset ΞΉ) (f : ΞΉ β†’ L) (a : L) : ⁅a, βˆ‘ i ∈ s, f i⁆ = βˆ‘ i ∈ s, ⁅a, f i⁆ := let _i := LieRing.toNonUnitalNonAssocRing L s.mul_sum f a theorem sum_lie_sum {ΞΊ : Type*} (s : Finset ΞΉ) (t : Finset ΞΊ) (f : ΞΉ β†’ L) (g : ΞΊ β†’ L) : ⁅(βˆ‘ i ∈ s, f i), βˆ‘ j ∈ t, g j⁆ = βˆ‘ i ∈ s, βˆ‘ j ∈ t, ⁅f i, g j⁆ := let _i := LieRing.toNonUnitalNonAssocRing L s.sum_mul_sum t f g end BasicProperties /-- A morphism of Lie algebras (denoted as `L₁ →ₗ⁅R⁆ Lβ‚‚`) is a linear map respecting the bracket operations. -/ structure LieHom (R L L' : Type*) [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] extends L β†’β‚—[R] L' where /-- A morphism of Lie algebras is compatible with brackets. -/ map_lie' : βˆ€ {x y : L}, toFun ⁅x, y⁆ = ⁅toFun x, toFun y⁆ @[inherit_doc] notation:25 L " →ₗ⁅" R:25 "⁆ " L':0 => LieHom R L L' namespace LieHom variable {R : Type u} {L₁ : Type v} {Lβ‚‚ : Type w} {L₃ : Type w₁} variable [CommRing R] variable [LieRing L₁] [LieAlgebra R L₁] variable [LieRing Lβ‚‚] [LieAlgebra R Lβ‚‚] variable [LieRing L₃] [LieAlgebra R L₃] attribute [coe] LieHom.toLinearMap instance : Coe (L₁ →ₗ⁅R⁆ Lβ‚‚) (L₁ β†’β‚—[R] Lβ‚‚) := ⟨LieHom.toLinearMap⟩ instance : FunLike (L₁ →ₗ⁅R⁆ Lβ‚‚) L₁ Lβ‚‚ where coe f := f.toFun coe_injective' x y h := by cases x; cases y; simp at h; simp [h] initialize_simps_projections LieHom (toFun β†’ apply) @[simp, norm_cast] theorem coe_toLinearMap (f : L₁ →ₗ⁅R⁆ Lβ‚‚) : ⇑(f : L₁ β†’β‚—[R] Lβ‚‚) = f := rfl @[simp] theorem toFun_eq_coe (f : L₁ →ₗ⁅R⁆ Lβ‚‚) : f.toFun = ⇑f := rfl @[simp] theorem map_smul (f : L₁ →ₗ⁅R⁆ Lβ‚‚) (c : R) (x : L₁) : f (c β€’ x) = c β€’ f x := LinearMap.map_smul (f : L₁ β†’β‚—[R] Lβ‚‚) c x @[simp] theorem map_add (f : L₁ →ₗ⁅R⁆ Lβ‚‚) (x y : L₁) : f (x + y) = f x + f y := LinearMap.map_add (f : L₁ β†’β‚—[R] Lβ‚‚) x y @[simp] theorem map_sub (f : L₁ →ₗ⁅R⁆ Lβ‚‚) (x y : L₁) : f (x - y) = f x - f y := LinearMap.map_sub (f : L₁ β†’β‚—[R] Lβ‚‚) x y @[simp] theorem map_neg (f : L₁ →ₗ⁅R⁆ Lβ‚‚) (x : L₁) : f (-x) = -f x := LinearMap.map_neg (f : L₁ β†’β‚—[R] Lβ‚‚) x @[simp] theorem map_lie (f : L₁ →ₗ⁅R⁆ Lβ‚‚) (x y : L₁) : f ⁅x, y⁆ = ⁅f x, f y⁆ := LieHom.map_lie' f @[simp] theorem map_zero (f : L₁ →ₗ⁅R⁆ Lβ‚‚) : f 0 = 0 := (f : L₁ β†’β‚—[R] Lβ‚‚).map_zero /-- The identity map is a morphism of Lie algebras. -/ def id : L₁ →ₗ⁅R⁆ L₁ := { (LinearMap.id : L₁ β†’β‚—[R] L₁) with map_lie' := rfl } @[simp, norm_cast] theorem coe_id : ⇑(id : L₁ →ₗ⁅R⁆ L₁) = _root_.id := rfl theorem id_apply (x : L₁) : (id : L₁ →ₗ⁅R⁆ L₁) x = x := rfl /-- The constant 0 map is a Lie algebra morphism. -/ instance : Zero (L₁ →ₗ⁅R⁆ Lβ‚‚) := ⟨{ (0 : L₁ β†’β‚—[R] Lβ‚‚) with map_lie' := by simp }⟩ @[norm_cast, simp] theorem coe_zero : ((0 : L₁ →ₗ⁅R⁆ Lβ‚‚) : L₁ β†’ Lβ‚‚) = 0 := rfl theorem zero_apply (x : L₁) : (0 : L₁ →ₗ⁅R⁆ Lβ‚‚) x = 0 := rfl /-- The identity map is a Lie algebra morphism. -/ instance : One (L₁ →ₗ⁅R⁆ L₁) := ⟨id⟩ @[simp] theorem coe_one : ((1 : L₁ →ₗ⁅R⁆ L₁) : L₁ β†’ L₁) = _root_.id := rfl theorem one_apply (x : L₁) : (1 : L₁ →ₗ⁅R⁆ L₁) x = x := rfl instance : Inhabited (L₁ →ₗ⁅R⁆ Lβ‚‚) := ⟨0⟩
Mathlib/Algebra/Lie/Basic.lean
412
414
theorem coe_injective : @Function.Injective (L₁ →ₗ⁅R⁆ Lβ‚‚) (L₁ β†’ Lβ‚‚) (↑) := by
rintro ⟨⟨⟨f, _⟩, _⟩, _⟩ ⟨⟨⟨g, _⟩, _⟩, _⟩ h congr
/- Copyright (c) 2023 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Heather Macbeth -/ import Mathlib.MeasureTheory.Constructions.Pi /-! # Marginals of multivariate functions In this file, we define a convenient way to compute integrals of multivariate functions, especially if you want to write expressions where you integrate only over some of the variables that the function depends on. This is common in induction arguments involving integrals of multivariate functions. This constructions allows working with iterated integrals and applying Tonelli's theorem and Fubini's theorem, without using measurable equivalences by changing the representation of your space (e.g. `((ΞΉ βŠ• ΞΉ') β†’ ℝ) ≃ (ΞΉ β†’ ℝ) Γ— (ΞΉ' β†’ ℝ)`). ## Main Definitions * Assume that `βˆ€ i : ΞΉ, X i` is a product of measurable spaces with measures `ΞΌ i` on `X i`, `f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞` is a function and `s : Finset ΞΉ`. Then `lmarginal ΞΌ s f` or `βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ` is the function that integrates `f` over all variables in `s`. It returns a function that still takes the same variables as `f`, but is constant in the variables in `s`. Mathematically, if `s = {i₁, ..., iβ‚–}`, then `lmarginal ΞΌ s f` is the expression $$ \vec{x}\mapsto \int\!\!\cdots\!\!\int f(\vec{x}[\vec{y}])dy_{i_1}\cdots dy_{i_k}. $$ where $\vec{x}[\vec{y}]$ is the vector $\vec{x}$ with $x_{i_j}$ replaced by $y_{i_j}$ for all $1 \le j \le k$. If `f` is the distribution of a random variable, this is the marginal distribution of all variables not in `s` (but not the most general notion, since we only consider product measures here). Note that the notation `βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ` is not a binder, and returns a function. ## Main Results * `lmarginal_union` is the analogue of Tonelli's theorem for iterated integrals. It states that for measurable functions `f` and disjoint finsets `s` and `t` we have `βˆ«β‹―βˆ«β»_s βˆͺ t, f βˆ‚ΞΌ = βˆ«β‹―βˆ«β»_s, βˆ«β‹―βˆ«β»_t, f βˆ‚ΞΌ βˆ‚ΞΌ`. ## Implementation notes The function `f` can have an arbitrary product as its domain (even infinite products), but the set `s` of integration variables is a `Finset`. We are assuming that the function `f` is measurable for most of this file. Note that asking whether it is `AEMeasurable` is not even well-posed, since there is no well-behaved measure on the domain of `f`. ## TODO * Define the marginal function for functions taking values in a Banach space. -/ open scoped ENNReal open Set Function Equiv Finset noncomputable section namespace MeasureTheory section LMarginal variable {Ξ΄ Ξ΄' : Type*} {X : Ξ΄ β†’ Type*} [βˆ€ i, MeasurableSpace (X i)] variable {ΞΌ : βˆ€ i, Measure (X i)} [DecidableEq Ξ΄] variable {s t : Finset Ξ΄} {f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞} {x : βˆ€ i, X i} /-- Integrate `f(x₁,…,xβ‚™)` over all variables `xα΅’` where `i ∈ s`. Return a function in the remaining variables (it will be constant in the `xα΅’` for `i ∈ s`). This is the marginal distribution of all variables not in `s` when the considered measure is the product measure. -/ def lmarginal (ΞΌ : βˆ€ i, Measure (X i)) (s : Finset Ξ΄) (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (x : βˆ€ i, X i) : ℝβ‰₯0∞ := ∫⁻ y : βˆ€ i : s, X i, f (updateFinset x s y) βˆ‚Measure.pi fun i : s => ΞΌ i -- Note: this notation is not a binder. This is more convenient since it returns a function. @[inherit_doc] notation "βˆ«β‹―βˆ«β»_" s ", " f " βˆ‚" ΞΌ:70 => lmarginal ΞΌ s f @[inherit_doc] notation "βˆ«β‹―βˆ«β»_" s ", " f => lmarginal (fun _ ↦ volume) s f variable (ΞΌ) theorem _root_.Measurable.lmarginal [βˆ€ i, SigmaFinite (ΞΌ i)] (hf : Measurable f) : Measurable (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) := by refine Measurable.lintegral_prod_right ?_ refine hf.comp ?_ rw [measurable_pi_iff]; intro i by_cases hi : i ∈ s Β· simpa [hi, updateFinset] using measurable_pi_iff.1 measurable_snd _ Β· simpa [hi, updateFinset] using measurable_pi_iff.1 measurable_fst _ @[simp] theorem lmarginal_empty (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) : βˆ«β‹―βˆ«β»_βˆ…, f βˆ‚ΞΌ = f := by ext1 x simp_rw [lmarginal, Measure.pi_of_empty fun i : (βˆ… : Finset Ξ΄) => ΞΌ i] apply lintegral_dirac' exact Subsingleton.measurable /-- The marginal distribution is independent of the variables in `s`. -/ theorem lmarginal_congr {x y : βˆ€ i, X i} (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (h : βˆ€ i βˆ‰ s, x i = y i) : (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) x = (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) y := by dsimp [lmarginal, updateFinset_def]; rcongr; exact h _ β€Ή_β€Ί theorem lmarginal_update_of_mem {i : Ξ΄} (hi : i ∈ s) (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (x : βˆ€ i, X i) (y : X i) : (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) (Function.update x i y) = (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) x := by apply lmarginal_congr intro j hj have : j β‰  i := by rintro rfl; exact hj hi apply update_of_ne this variable {ΞΌ} in theorem lmarginal_singleton (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (i : Ξ΄) : βˆ«β‹―βˆ«β»_{i}, f βˆ‚ΞΌ = fun x => ∫⁻ xα΅’, f (Function.update x i xα΅’) βˆ‚ΞΌ i := by let Ξ± : Type _ := ({i} : Finset Ξ΄) let e := (MeasurableEquiv.piUnique fun j : Ξ± ↦ X j).symm ext1 x calc (βˆ«β‹―βˆ«β»_{i}, f βˆ‚ΞΌ) x = ∫⁻ (y : X (default : Ξ±)), f (updateFinset x {i} (e y)) βˆ‚ΞΌ (default : Ξ±) := by simp_rw [lmarginal, measurePreserving_piUnique (fun j : ({i} : Finset Ξ΄) ↦ ΞΌ j) |>.symm _ |>.lintegral_map_equiv, e, Ξ±] _ = ∫⁻ xα΅’, f (Function.update x i xα΅’) βˆ‚ΞΌ i := by simp [update_eq_updateFinset]; rfl variable {ΞΌ} in @[gcongr] theorem lmarginal_mono {f g : (βˆ€ i, X i) β†’ ℝβ‰₯0∞} (hfg : f ≀ g) : βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ ≀ βˆ«β‹―βˆ«β»_s, g βˆ‚ΞΌ := fun _ => lintegral_mono fun _ => hfg _ variable [βˆ€ i, SigmaFinite (ΞΌ i)] theorem lmarginal_union (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (hf : Measurable f) (hst : Disjoint s t) : βˆ«β‹―βˆ«β»_s βˆͺ t, f βˆ‚ΞΌ = βˆ«β‹―βˆ«β»_s, βˆ«β‹―βˆ«β»_t, f βˆ‚ΞΌ βˆ‚ΞΌ := by ext1 x let e := MeasurableEquiv.piFinsetUnion X hst calc (βˆ«β‹―βˆ«β»_s βˆͺ t, f βˆ‚ΞΌ) x = ∫⁻ (y : (i : β†₯(s βˆͺ t)) β†’ X i), f (updateFinset x (s βˆͺ t) y) βˆ‚.pi fun i' : β†₯(s βˆͺ t) ↦ ΞΌ i' := rfl _ = ∫⁻ (y : ((i : s) β†’ X i) Γ— ((j : t) β†’ X j)), f (updateFinset x (s βˆͺ t) _) βˆ‚(Measure.pi fun i : s ↦ ΞΌ i).prod (.pi fun j : t ↦ ΞΌ j) := by rw [measurePreserving_piFinsetUnion hst ΞΌ |>.lintegral_map_equiv] _ = ∫⁻ (y : (i : s) β†’ X i), ∫⁻ (z : (j : t) β†’ X j), f (updateFinset x (s βˆͺ t) (e (y, z))) βˆ‚.pi fun j : t ↦ ΞΌ j βˆ‚.pi fun i : s ↦ ΞΌ i := by apply lintegral_prod apply Measurable.aemeasurable exact hf.comp <| measurable_updateFinset.comp e.measurable _ = (βˆ«β‹―βˆ«β»_s, βˆ«β‹―βˆ«β»_t, f βˆ‚ΞΌ βˆ‚ΞΌ) x := by simp_rw [lmarginal, updateFinset_updateFinset hst] rfl theorem lmarginal_union' (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (hf : Measurable f) {s t : Finset Ξ΄} (hst : Disjoint s t) : βˆ«β‹―βˆ«β»_s βˆͺ t, f βˆ‚ΞΌ = βˆ«β‹―βˆ«β»_t, βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ βˆ‚ΞΌ := by rw [Finset.union_comm, lmarginal_union ΞΌ f hf hst.symm] variable {ΞΌ} /-- Peel off a single integral from a `lmarginal` integral at the beginning (compare with `lmarginal_insert'`, which peels off an integral at the end). -/ theorem lmarginal_insert (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (hf : Measurable f) {i : Ξ΄} (hi : i βˆ‰ s) (x : βˆ€ i, X i) : (βˆ«β‹―βˆ«β»_insert i s, f βˆ‚ΞΌ) x = ∫⁻ xα΅’, (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) (Function.update x i xα΅’) βˆ‚ΞΌ i := by rw [Finset.insert_eq, lmarginal_union ΞΌ f hf (Finset.disjoint_singleton_left.mpr hi), lmarginal_singleton] /-- Peel off a single integral from a `lmarginal` integral at the beginning (compare with `lmarginal_erase'`, which peels off an integral at the end). -/
Mathlib/MeasureTheory/Integral/Marginal.lean
171
175
theorem lmarginal_erase (f : (βˆ€ i, X i) β†’ ℝβ‰₯0∞) (hf : Measurable f) {i : Ξ΄} (hi : i ∈ s) (x : βˆ€ i, X i) : (βˆ«β‹―βˆ«β»_s, f βˆ‚ΞΌ) x = ∫⁻ xα΅’, (βˆ«β‹―βˆ«β»_(erase s i), f βˆ‚ΞΌ) (Function.update x i xα΅’) βˆ‚ΞΌ i := by
simpa [insert_erase hi] using lmarginal_insert _ hf (not_mem_erase i s) x
/- Copyright (c) 2022 Mantas BakΕ‘ys. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mantas BakΕ‘ys -/ import Mathlib.Algebra.Order.Module.OrderedSMul import Mathlib.Algebra.Order.Module.Synonym import Mathlib.Data.Prod.Lex import Mathlib.Data.Set.Image import Mathlib.Data.Finset.Max import Mathlib.GroupTheory.Perm.Support import Mathlib.Order.Monotone.Monovary import Mathlib.Tactic.Abel /-! # Rearrangement inequality This file proves the rearrangement inequality and deduces the conditions for equality and strict inequality. The rearrangement inequality tells you that for two functions `f g : ΞΉ β†’ Ξ±`, the sum `βˆ‘ i, f i * g (Οƒ i)` is maximized over all `Οƒ : Perm ΞΉ` when `g ∘ Οƒ` monovaries with `f` and minimized when `g ∘ Οƒ` antivaries with `f`. The inequality also tells you that `βˆ‘ i, f i * g (Οƒ i) = βˆ‘ i, f i * g i` if and only if `g ∘ Οƒ` monovaries with `f` when `g` monovaries with `f`. The above equality also holds if and only if `g ∘ Οƒ` antivaries with `f` when `g` antivaries with `f`. From the above two statements, we deduce that the inequality is strict if and only if `g ∘ Οƒ` does not monovary with `f` when `g` monovaries with `f`. Analogously, the inequality is strict if and only if `g ∘ Οƒ` does not antivary with `f` when `g` antivaries with `f`. ## Implementation notes In fact, we don't need much compatibility between the addition and multiplication of `Ξ±`, so we can actually decouple them by replacing multiplication with scalar multiplication and making `f` and `g` land in different types. As a bonus, this makes the dual statement trivial. The multiplication versions are provided for convenience. The case for `Monotone`/`Antitone` pairs of functions over a `LinearOrder` is not deduced in this file because it is easily deducible from the `Monovary` API. ## TODO Add equality cases for when the permute function is injective. This comes from the following fact: If `Monovary f g`, `Injective g` and `Οƒ` is a permutation, then `Monovary f (g ∘ Οƒ) ↔ Οƒ = 1`. -/ open Equiv Equiv.Perm Finset Function OrderDual variable {ΞΉ Ξ± Ξ² : Type*} [Semiring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] [ExistsAddOfLE Ξ±] [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²] [Module Ξ± Ξ²] /-! ### Scalar multiplication versions -/ section SMul /-! #### Weak rearrangement inequality -/ section weak_inequality variable [PosSMulMono Ξ± Ξ²] {s : Finset ΞΉ} {Οƒ : Perm ΞΉ} {f : ΞΉ β†’ Ξ±} {g : ΞΉ β†’ Ξ²} /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when `f` and `g` monovary together on `s`. Stated by permuting the entries of `g`. -/ theorem MonovaryOn.sum_smul_comp_perm_le_sum_smul (hfg : MonovaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f i β€’ g (Οƒ i) ≀ βˆ‘ i ∈ s, f i β€’ g i := by classical revert hΟƒ Οƒ hfg apply Finset.induction_on_max_value (fun i ↦ toLex (g i, f i)) (p := fun t ↦ βˆ€ {Οƒ : Perm ΞΉ}, MonovaryOn f g t β†’ {x | Οƒ x β‰  x} βŠ† t β†’ βˆ‘ i ∈ t, f i β€’ g (Οƒ i) ≀ βˆ‘ i ∈ t, f i β€’ g i) s Β· simp only [le_rfl, Finset.sum_empty, imp_true_iff] intro a s has hamax hind Οƒ hfg hΟƒ set Ο„ : Perm ΞΉ := Οƒ.trans (swap a (Οƒ a)) with hΟ„ have hΟ„s : {x | Ο„ x β‰  x} βŠ† s := by intro x hx simp only [Ο„, Ne, Set.mem_setOf_eq, Equiv.coe_trans, Equiv.swap_comp_apply] at hx split_ifs at hx with h₁ hβ‚‚ Β· obtain rfl | hax := eq_or_ne x a Β· contradiction Β· exact mem_of_mem_insert_of_ne (hΟƒ fun h ↦ hax <| h.symm.trans h₁) hax Β· exact (hx <| Οƒ.injective hβ‚‚.symm).elim Β· exact mem_of_mem_insert_of_ne (hΟƒ hx) (ne_of_apply_ne _ hβ‚‚) specialize hind (hfg.subset <| subset_insert _ _) hΟ„s simp_rw [sum_insert has] refine le_trans ?_ (add_le_add_left hind _) obtain hΟƒa | hΟƒa := eq_or_ne a (Οƒ a) Β· rw [hΟ„, ← hΟƒa, swap_self, trans_refl] have h1s : σ⁻¹ a ∈ s := by rw [Ne, ← inv_eq_iff_eq] at hΟƒa refine mem_of_mem_insert_of_ne (hΟƒ fun h ↦ hΟƒa ?_) hΟƒa rwa [apply_inv_self, eq_comm] at h simp only [← s.sum_erase_add _ h1s, add_comm] rw [← add_assoc, ← add_assoc] simp only [hΟ„, swap_apply_left, Function.comp_apply, Equiv.coe_trans, apply_inv_self] refine add_le_add (smul_add_smul_le_smul_add_smul' ?_ ?_) (sum_congr rfl fun x hx ↦ ?_).le Β· specialize hamax (σ⁻¹ a) h1s rw [Prod.Lex.toLex_le_toLex] at hamax rcases hamax with hamax | hamax Β· exact hfg (mem_insert_of_mem h1s) (mem_insert_self _ _) hamax Β· exact hamax.2 Β· specialize hamax (Οƒ a) (mem_of_mem_insert_of_ne (hΟƒ <| Οƒ.injective.ne hΟƒa.symm) hΟƒa.symm) rw [Prod.Lex.toLex_le_toLex] at hamax rcases hamax with hamax | hamax Β· exact hamax.le Β· exact hamax.1.le Β· rw [mem_erase, Ne, eq_inv_iff_eq] at hx rw [swap_apply_of_ne_of_ne hx.1 (Οƒ.injective.ne _)] rintro rfl exact has hx.2 /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when `f` and `g` antivary together on `s`. Stated by permuting the entries of `g`. -/ theorem AntivaryOn.sum_smul_le_sum_smul_comp_perm (hfg : AntivaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f i β€’ g i ≀ βˆ‘ i ∈ s, f i β€’ g (Οƒ i) := hfg.dual_right.sum_smul_comp_perm_le_sum_smul hΟƒ /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when `f` and `g` monovary together on `s`. Stated by permuting the entries of `f`. -/ theorem MonovaryOn.sum_comp_perm_smul_le_sum_smul (hfg : MonovaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f (Οƒ i) β€’ g i ≀ βˆ‘ i ∈ s, f i β€’ g i := by convert hfg.sum_smul_comp_perm_le_sum_smul (show { x | σ⁻¹ x β‰  x } βŠ† s by simp only [set_support_inv_eq, hΟƒ]) using 1 exact Οƒ.sum_comp' s (fun i j ↦ f i β€’ g j) hΟƒ /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when `f` and `g` antivary together on `s`. Stated by permuting the entries of `f`. -/ theorem AntivaryOn.sum_smul_le_sum_comp_perm_smul (hfg : AntivaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f i β€’ g i ≀ βˆ‘ i ∈ s, f (Οƒ i) β€’ g i := hfg.dual_right.sum_comp_perm_smul_le_sum_smul hΟƒ variable [Fintype ΞΉ] /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when `f` and `g` monovary together. Stated by permuting the entries of `g`. -/ theorem Monovary.sum_smul_comp_perm_le_sum_smul (hfg : Monovary f g) : βˆ‘ i, f i β€’ g (Οƒ i) ≀ βˆ‘ i, f i β€’ g i := (hfg.monovaryOn _).sum_smul_comp_perm_le_sum_smul fun _ _ ↦ mem_univ _ /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when `f` and `g` antivary together. Stated by permuting the entries of `g`. -/ theorem Antivary.sum_smul_le_sum_smul_comp_perm (hfg : Antivary f g) : βˆ‘ i, f i β€’ g i ≀ βˆ‘ i, f i β€’ g (Οƒ i) := (hfg.antivaryOn _).sum_smul_le_sum_smul_comp_perm fun _ _ ↦ mem_univ _ /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is maximized when `f` and `g` monovary together. Stated by permuting the entries of `f`. -/ theorem Monovary.sum_comp_perm_smul_le_sum_smul (hfg : Monovary f g) : βˆ‘ i, f (Οƒ i) β€’ g i ≀ βˆ‘ i, f i β€’ g i := (hfg.monovaryOn _).sum_comp_perm_smul_le_sum_smul fun _ _ ↦ mem_univ _ /-- **Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g` is minimized when `f` and `g` antivary together. Stated by permuting the entries of `f`. -/ theorem Antivary.sum_smul_le_sum_comp_perm_smul (hfg : Antivary f g) : βˆ‘ i, f i β€’ g i ≀ βˆ‘ i, f (Οƒ i) β€’ g i := (hfg.antivaryOn _).sum_smul_le_sum_comp_perm_smul fun _ _ ↦ mem_univ _ end weak_inequality /-! #### Equality case of the rearrangement inequality -/ section equality_case variable [PosSMulStrictMono Ξ± Ξ²] {s : Finset ΞΉ} {Οƒ : Perm ΞΉ} {f : ΞΉ β†’ Ξ±} {g : ΞΉ β†’ Ξ²} /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g`, which monovary together on `s`, is unchanged by a permutation if and only if `f` and `g ∘ Οƒ` monovary together on `s`. Stated by permuting the entries of `g`. -/ theorem MonovaryOn.sum_smul_comp_perm_eq_sum_smul_iff (hfg : MonovaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f i β€’ g (Οƒ i) = βˆ‘ i ∈ s, f i β€’ g i ↔ MonovaryOn f (g ∘ Οƒ) s := by classical refine ⟨not_imp_not.1 fun h ↦ ?_, fun h ↦ (hfg.sum_smul_comp_perm_le_sum_smul hΟƒ).antisymm ?_⟩ Β· rw [MonovaryOn] at h push_neg at h obtain ⟨x, hx, y, hy, hgxy, hfxy⟩ := h set Ο„ : Perm ΞΉ := (Equiv.swap x y).trans Οƒ have hΟ„s : {x | Ο„ x β‰  x} βŠ† s := by refine (set_support_mul_subset Οƒ <| swap x y).trans (Set.union_subset hΟƒ fun z hz ↦ ?_) obtain ⟨_, rfl | rfl⟩ := swap_apply_ne_self_iff.1 hz <;> assumption refine ((hfg.sum_smul_comp_perm_le_sum_smul hΟ„s).trans_lt' ?_).ne obtain rfl | hxy := eq_or_ne x y Β· cases lt_irrefl _ hfxy simp only [Ο„, ← s.sum_erase_add _ hx, ← (s.erase x).sum_erase_add _ (mem_erase.2 ⟨hxy.symm, hy⟩), add_assoc, Equiv.coe_trans, Function.comp_apply, swap_apply_right, swap_apply_left] refine add_lt_add_of_le_of_lt (Finset.sum_congr rfl fun z hz ↦ ?_).le (smul_add_smul_lt_smul_add_smul hfxy hgxy) simp_rw [mem_erase] at hz rw [swap_apply_of_ne_of_ne hz.2.1 hz.1] Β· convert h.sum_smul_comp_perm_le_sum_smul ((set_support_inv_eq _).subset.trans hΟƒ) using 1 simp_rw [Function.comp_apply, apply_inv_self] /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g`, which antivary together on `s`, is unchanged by a permutation if and only if `f` and `g ∘ Οƒ` antivary together on `s`. Stated by permuting the entries of `g`. -/ theorem AntivaryOn.sum_smul_comp_perm_eq_sum_smul_iff (hfg : AntivaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f i β€’ g (Οƒ i) = βˆ‘ i ∈ s, f i β€’ g i ↔ AntivaryOn f (g ∘ Οƒ) s := (hfg.dual_right.sum_smul_comp_perm_eq_sum_smul_iff hΟƒ).trans monovaryOn_toDual_right /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g`, which monovary together on `s`, is unchanged by a permutation if and only if `f ∘ Οƒ` and `g` monovary together on `s`. Stated by permuting the entries of `f`. -/ theorem MonovaryOn.sum_comp_perm_smul_eq_sum_smul_iff (hfg : MonovaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f (Οƒ i) β€’ g i = βˆ‘ i ∈ s, f i β€’ g i ↔ MonovaryOn (f ∘ Οƒ) g s := by have hΟƒinv : { x | σ⁻¹ x β‰  x } βŠ† s := (set_support_inv_eq _).subset.trans hΟƒ refine (Iff.trans ?_ <| hfg.sum_smul_comp_perm_eq_sum_smul_iff hΟƒinv).trans ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· apply eq_iff_eq_cancel_right.2 rw [Οƒ.sum_comp' s (fun i j ↦ f i β€’ g j) hΟƒ] congr Β· convert h.comp_right Οƒ Β· rw [comp_assoc, inv_def, symm_comp_self, comp_id] Β· rw [Οƒ.eq_preimage_iff_image_eq, Set.image_perm hΟƒ] Β· convert h.comp_right Οƒ.symm Β· rw [comp_assoc, self_comp_symm, comp_id] Β· rw [Οƒ.symm.eq_preimage_iff_image_eq] exact Set.image_perm hΟƒinv /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g`, which antivary together on `s`, is unchanged by a permutation if and only if `f ∘ Οƒ` and `g` antivary together on `s`. Stated by permuting the entries of `f`. -/ theorem AntivaryOn.sum_comp_perm_smul_eq_sum_smul_iff (hfg : AntivaryOn f g s) (hΟƒ : {x | Οƒ x β‰  x} βŠ† s) : βˆ‘ i ∈ s, f (Οƒ i) β€’ g i = βˆ‘ i ∈ s, f i β€’ g i ↔ AntivaryOn (f ∘ Οƒ) g s := (hfg.dual_right.sum_comp_perm_smul_eq_sum_smul_iff hΟƒ).trans monovaryOn_toDual_right variable [Fintype ΞΉ] /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g`, which monovary together, is unchanged by a permutation if and only if `f` and `g ∘ Οƒ` monovary together. Stated by permuting the entries of `g`. -/ theorem Monovary.sum_smul_comp_perm_eq_sum_smul_iff (hfg : Monovary f g) : βˆ‘ i, f i β€’ g (Οƒ i) = βˆ‘ i, f i β€’ g i ↔ Monovary f (g ∘ Οƒ) := by simp [(hfg.monovaryOn _).sum_smul_comp_perm_eq_sum_smul_iff fun _ _ ↦ mem_univ _] /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and `g`, which monovary together, is unchanged by a permutation if and only if `f ∘ Οƒ` and `g` monovary together. Stated by permuting the entries of `g`. -/
Mathlib/Algebra/Order/Rearrangement.lean
243
247
theorem Monovary.sum_comp_perm_smul_eq_sum_smul_iff (hfg : Monovary f g) : βˆ‘ i, f (Οƒ i) β€’ g i = βˆ‘ i, f i β€’ g i ↔ Monovary (f ∘ Οƒ) g := by
simp [(hfg.monovaryOn _).sum_comp_perm_smul_eq_sum_smul_iff fun _ _ ↦ mem_univ _] /-- **Equality case of the Rearrangement Inequality**: Pointwise scalar multiplication of `f` and
/- 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.Data.Nat.Choose.Central import Mathlib.Tactic.FieldSimp import Mathlib.Tactic.GCongr import Mathlib.Tactic.Positivity /-! # 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)`. * `treesOfNumNodesEq_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) @[simp] theorem catalan_zero : catalan 0 = 1 := by rw [catalan] theorem catalan_succ (n : β„•) : catalan (n + 1) = βˆ‘ i : Fin n.succ, catalan i * catalan (n - i) := by rw [catalan] 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] @[simp] theorem catalan_one : catalan 1 = 1 := by simp [catalan_succ] /-- A helper sequence that can be used to prove the equality of the recursive and the explicit definition using a telescoping sum argument. -/ private def gosperCatalan (n j : β„•) : β„š := Nat.centralBinom j * Nat.centralBinom (n - j) * (2 * j - n) / (2 * n * (n + 1)) private theorem gosper_trick {n i : β„•} (h : i ≀ n) : gosperCatalan (n + 1) (i + 1) - gosperCatalan (n + 1) i = Nat.centralBinom i / (i + 1) * Nat.centralBinom (n - i) / (n - i + 1) := by have l₁ : (i : β„š) + 1 β‰  0 := by norm_cast have lβ‚‚ : (n : β„š) - i + 1 β‰  0 := by norm_cast have h₁ := (mul_div_cancel_leftβ‚€ (↑(Nat.centralBinom (i + 1))) l₁).symm have hβ‚‚ := (mul_div_cancel_leftβ‚€ (↑(Nat.centralBinom (n - i + 1))) lβ‚‚).symm have h₃ : ((i : β„š) + 1) * (i + 1).centralBinom = 2 * (2 * i + 1) * i.centralBinom := mod_cast Nat.succ_mul_centralBinom_succ i have hβ‚„ : ((n : β„š) - i + 1) * (n - i + 1).centralBinom = 2 * (2 * (n - i) + 1) * (n - i).centralBinom := mod_cast Nat.succ_mul_centralBinom_succ (n - i) simp only [gosperCatalan] push_cast rw [show n + 1 - i = n - i + 1 by rw [Nat.add_comm (n - i) 1, ← (Nat.add_sub_assoc h 1), add_comm]] rw [h₁, hβ‚‚, h₃, hβ‚„] field_simp ring private theorem gosper_catalan_sub_eq_central_binom_div (n : β„•) : gosperCatalan (n + 1) (n + 1) - gosperCatalan (n + 1) 0 = Nat.centralBinom (n + 1) / (n + 2) := by have : (n : β„š) + 1 β‰  0 := by norm_cast have : (n : β„š) + 1 + 1 β‰  0 := by norm_cast have h : (n : β„š) + 2 β‰  0 := by norm_cast simp only [gosperCatalan, Nat.sub_zero, Nat.centralBinom_zero, Nat.sub_self] field_simp ring theorem catalan_eq_centralBinom_div (n : β„•) : catalan n = n.centralBinom / (n + 1) := by suffices (catalan n : β„š) = Nat.centralBinom n / (n + 1) by have h := Nat.succ_dvd_centralBinom n exact mod_cast this induction n using Nat.caseStrongRecOn with | zero => simp | ind d hd => simp_rw [catalan_succ, Nat.cast_sum, Nat.cast_mul] trans (βˆ‘ i : Fin d.succ, Nat.centralBinom i / (i + 1) * (Nat.centralBinom (d - i) / (d - i + 1)) : β„š) Β· congr ext1 x have m_le_d : x.val ≀ d := by omega have d_minus_x_le_d : (d - x.val) ≀ d := tsub_le_self rw [hd _ m_le_d, hd _ d_minus_x_le_d] norm_cast Β· trans (βˆ‘ i : Fin d.succ, (gosperCatalan (d + 1) (i + 1) - gosperCatalan (d + 1) i)) Β· refine sum_congr rfl fun i _ => ?_ rw [gosper_trick i.is_le, mul_div] Β· rw [← sum_range fun i => gosperCatalan (d + 1) (i + 1) - gosperCatalan (d + 1) i, sum_range_sub, Nat.succ_eq_add_one] rw [gosper_catalan_sub_eq_central_binom_div d] norm_cast theorem succ_mul_catalan_eq_centralBinom (n : β„•) : (n + 1) * catalan n = n.centralBinom := (Nat.eq_mul_of_div_eq_right n.succ_dvd_centralBinom (catalan_eq_centralBinom_div n).symm).symm theorem catalan_two : catalan 2 = 2 := by norm_num [catalan_eq_centralBinom_div, Nat.centralBinom, Nat.choose] theorem catalan_three : catalan 3 = 5 := by norm_num [catalan_eq_centralBinom_div, Nat.centralBinom, Nat.choose] namespace Tree /-- Given two finsets, find all trees that can be formed with left child in `a` and right child in `b` -/ abbrev pairwiseNode (a b : Finset (Tree Unit)) : Finset (Tree Unit) := (a Γ—Λ’ b).map ⟨fun x => x.1 β–³ x.2, fun ⟨x₁, xβ‚‚βŸ© ⟨y₁, yβ‚‚βŸ© => fun h => by simpa using h⟩ /-- A Finset of all trees with `n` nodes. See `mem_treesOfNodesEq` -/ def treesOfNumNodesEq : β„• β†’ Finset (Tree Unit) | 0 => {nil} | n + 1 => (antidiagonal n).attach.biUnion fun ijh => pairwiseNode (treesOfNumNodesEq ijh.1.1) (treesOfNumNodesEq ijh.1.2) decreasing_by Β· simp_wf; have := fst_le ijh.2; omega Β· simp_wf; have := snd_le ijh.2; omega @[simp] theorem treesOfNumNodesEq_zero : treesOfNumNodesEq 0 = {nil} := by rw [treesOfNumNodesEq] theorem treesOfNumNodesEq_succ (n : β„•) : treesOfNumNodesEq (n + 1) = (antidiagonal n).biUnion fun ij => pairwiseNode (treesOfNumNodesEq ij.1) (treesOfNumNodesEq ij.2) := by rw [treesOfNumNodesEq] ext simp @[simp] theorem mem_treesOfNumNodesEq {x : Tree Unit} {n : β„•} : x ∈ treesOfNumNodesEq n ↔ x.numNodes = n := by induction x using Tree.unitRecOn generalizing n <;> cases n <;> simp [treesOfNumNodesEq_succ, *] theorem mem_treesOfNumNodesEq_numNodes (x : Tree Unit) : x ∈ treesOfNumNodesEq x.numNodes := mem_treesOfNumNodesEq.mpr rfl @[simp, norm_cast] theorem coe_treesOfNumNodesEq (n : β„•) : ↑(treesOfNumNodesEq n) = { x : Tree Unit | x.numNodes = n } := Set.ext (by simp)
Mathlib/Combinatorics/Enumerative/Catalan.lean
181
187
theorem treesOfNumNodesEq_card_eq_catalan (n : β„•) : #(treesOfNumNodesEq n) = catalan n := by
induction n using Nat.case_strong_induction_on with | hz => simp | hi n ih => rw [treesOfNumNodesEq_succ, card_biUnion, catalan_succ'] · apply sum_congr rfl rintro ⟨i, j⟩ H
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, Benjamin Davidson -/ import Mathlib.Analysis.SpecialFunctions.Complex.Arg import Mathlib.Analysis.SpecialFunctions.Log.Basic /-! # The complex `log` function Basic properties, relationship with `exp`. -/ noncomputable section namespace Complex open Set Filter Bornology open scoped Real Topology ComplexConjugate /-- Inverse of the `exp` function. Returns values such that `(log x).im > - Ο€` and `(log x).im ≀ Ο€`. `log 0 = 0` -/ @[pp_nodot] noncomputable def log (x : β„‚) : β„‚ := Real.log β€–xβ€– + arg x * I theorem log_re (x : β„‚) : x.log.re = Real.log β€–xβ€– := by simp [log] theorem log_im (x : β„‚) : x.log.im = x.arg := by simp [log] theorem neg_pi_lt_log_im (x : β„‚) : -Ο€ < (log x).im := by simp only [log_im, neg_pi_lt_arg] theorem log_im_le_pi (x : β„‚) : (log x).im ≀ Ο€ := by simp only [log_im, arg_le_pi] theorem exp_log {x : β„‚} (hx : x β‰  0) : exp (log x) = x := by rw [log, exp_add_mul_I, ← ofReal_sin, sin_arg, ← ofReal_cos, cos_arg hx, ← ofReal_exp, Real.exp_log (norm_pos_iff.mpr hx), mul_add, ofReal_div, ofReal_div, mul_div_cancelβ‚€ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), ← mul_assoc, mul_div_cancelβ‚€ _ (ofReal_ne_zero.2 <| norm_ne_zero_iff.mpr hx), re_add_im] @[simp] theorem range_exp : Set.range exp = {0}ᢜ := Set.ext fun x => ⟨by rintro ⟨x, rfl⟩ exact exp_ne_zero x, fun hx => ⟨log x, exp_log hx⟩⟩ theorem log_exp {x : β„‚} (hx₁ : -Ο€ < x.im) (hxβ‚‚ : x.im ≀ Ο€) : log (exp x) = x := by rw [log, norm_exp, Real.log_exp, exp_eq_exp_re_mul_sin_add_cos, ← ofReal_exp, arg_mul_cos_add_sin_mul_I (Real.exp_pos _) ⟨hx₁, hxβ‚‚βŸ©, re_add_im] theorem exp_inj_of_neg_pi_lt_of_le_pi {x y : β„‚} (hx₁ : -Ο€ < x.im) (hxβ‚‚ : x.im ≀ Ο€) (hy₁ : -Ο€ < y.im) (hyβ‚‚ : y.im ≀ Ο€) (hxy : exp x = exp y) : x = y := by rw [← log_exp hx₁ hxβ‚‚, ← log_exp hy₁ hyβ‚‚, hxy] theorem ofReal_log {x : ℝ} (hx : 0 ≀ x) : (x.log : β„‚) = log x := Complex.ext (by rw [log_re, ofReal_re, Complex.norm_of_nonneg hx]) (by rw [ofReal_im, log_im, arg_ofReal_of_nonneg hx]) @[simp, norm_cast] lemma natCast_log {n : β„•} : Real.log n = log n := ofReal_natCast n β–Έ ofReal_log n.cast_nonneg @[simp] lemma ofNat_log {n : β„•} [n.AtLeastTwo] : Real.log ofNat(n) = log (OfNat.ofNat n) := natCast_log theorem log_ofReal_re (x : ℝ) : (log (x : β„‚)).re = Real.log x := by simp [log_re] theorem log_ofReal_mul {r : ℝ} (hr : 0 < r) {x : β„‚} (hx : x β‰  0) : log (r * x) = Real.log r + log x := by replace hx := norm_ne_zero_iff.mpr hx simp_rw [log, norm_mul, norm_real, arg_real_mul _ hr, Real.norm_of_nonneg hr.le, Real.log_mul hr.ne' hx, ofReal_add, add_assoc] theorem log_mul_ofReal (r : ℝ) (hr : 0 < r) (x : β„‚) (hx : x β‰  0) : log (x * r) = Real.log r + log x := by rw [mul_comm, log_ofReal_mul hr hx] lemma log_mul_eq_add_log_iff {x y : β„‚} (hxβ‚€ : x β‰  0) (hyβ‚€ : y β‰  0) : log (x * y) = log x + log y ↔ arg x + arg y ∈ Set.Ioc (-Ο€) Ο€ := by refine Complex.ext_iff.trans <| Iff.trans ?_ <| arg_mul_eq_add_arg_iff hxβ‚€ hyβ‚€ simp_rw [add_re, add_im, log_re, log_im, norm_mul, Real.log_mul (norm_ne_zero_iff.mpr hxβ‚€) (norm_ne_zero_iff.mpr hyβ‚€), true_and] alias ⟨_, log_mul⟩ := log_mul_eq_add_log_iff @[simp] theorem log_zero : log 0 = 0 := by simp [log] @[simp]
Mathlib/Analysis/SpecialFunctions/Complex/Log.lean
93
94
theorem log_one : log 1 = 0 := by
simp [log]
/- Copyright (c) 2019 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Module.Submodule.Equiv import Mathlib.Algebra.Module.Equiv.Basic import Mathlib.Algebra.Module.Rat import Mathlib.Data.Bracket import Mathlib.Tactic.Abel /-! # Lie algebras This file defines Lie rings and Lie algebras over a commutative ring together with their modules, morphisms and equivalences, as well as various lemmas to make these definitions usable. ## Main definitions * `LieRing` * `LieAlgebra` * `LieRingModule` * `LieModule` * `LieHom` * `LieEquiv` * `LieModuleHom` * `LieModuleEquiv` ## Notation Working over a fixed commutative ring `R`, we introduce the notations: * `L →ₗ⁅R⁆ L'` for a morphism of Lie algebras, * `L ≃ₗ⁅R⁆ L'` for an equivalence of Lie algebras, * `M →ₗ⁅R,L⁆ N` for a morphism of Lie algebra modules `M`, `N` over a Lie algebra `L`, * `M ≃ₗ⁅R,L⁆ N` for an equivalence of Lie algebra modules `M`, `N` over a Lie algebra `L`. ## Implementation notes Lie algebras are defined as modules with a compatible Lie ring structure and thus, like modules, are partially unbundled. ## References * [N. Bourbaki, *Lie Groups and Lie Algebras, Chapters 1--3*](bourbaki1975) ## Tags lie bracket, jacobi identity, lie ring, lie algebra, lie module -/ universe u v w w₁ wβ‚‚ open Function /-- A Lie ring is an additive group with compatible product, known as the bracket, satisfying the Jacobi identity. -/ class LieRing (L : Type v) extends AddCommGroup L, Bracket L L where /-- A Lie ring bracket is additive in its first component. -/ protected add_lie : βˆ€ x y z : L, ⁅x + y, z⁆ = ⁅x, z⁆ + ⁅y, z⁆ /-- A Lie ring bracket is additive in its second component. -/ protected lie_add : βˆ€ x y z : L, ⁅x, y + z⁆ = ⁅x, y⁆ + ⁅x, z⁆ /-- A Lie ring bracket vanishes on the diagonal in L Γ— L. -/ protected lie_self : βˆ€ x : L, ⁅x, x⁆ = 0 /-- A Lie ring bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : βˆ€ x y z : L, ⁅x, ⁅y, z⁆⁆ = ⁅⁅x, y⁆, z⁆ + ⁅y, ⁅x, z⁆⁆ /-- A Lie algebra is a module with compatible product, known as the bracket, satisfying the Jacobi identity. Forgetting the scalar multiplication, every Lie algebra is a Lie ring. -/ @[ext] class LieAlgebra (R : Type u) (L : Type v) [CommRing R] [LieRing L] extends Module R L where /-- A Lie algebra bracket is compatible with scalar multiplication in its second argument. The compatibility in the first argument is not a class property, but follows since every Lie algebra has a natural Lie module action on itself, see `LieModule`. -/ protected lie_smul : βˆ€ (t : R) (x y : L), ⁅x, t β€’ y⁆ = t β€’ ⁅x, y⁆ /-- A Lie ring module is an additive group, together with an additive action of a Lie ring on this group, such that the Lie bracket acts as the commutator of endomorphisms. (For representations of Lie *algebras* see `LieModule`.) -/ class LieRingModule (L : Type v) (M : Type w) [LieRing L] [AddCommGroup M] extends Bracket L M where /-- A Lie ring module bracket is additive in its first component. -/ protected add_lie : βˆ€ (x y : L) (m : M), ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ /-- A Lie ring module bracket is additive in its second component. -/ protected lie_add : βˆ€ (x : L) (m n : M), ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ /-- A Lie ring module bracket satisfies a Leibniz / Jacobi identity. -/ protected leibniz_lie : βˆ€ (x y : L) (m : M), ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ /-- A Lie module is a module over a commutative ring, together with a linear action of a Lie algebra on this module, such that the Lie bracket acts as the commutator of endomorphisms. -/ class LieModule (R : Type u) (L : Type v) (M : Type w) [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] [LieRingModule L M] : Prop where /-- A Lie module bracket is compatible with scalar multiplication in its first argument. -/ protected smul_lie : βˆ€ (t : R) (x : L) (m : M), ⁅t β€’ x, m⁆ = t β€’ ⁅x, m⁆ /-- A Lie module bracket is compatible with scalar multiplication in its second argument. -/ protected lie_smul : βˆ€ (t : R) (x : L) (m : M), ⁅x, t β€’ m⁆ = t β€’ ⁅x, m⁆ /-- A tower of Lie bracket actions encapsulates the Leibniz rule for Lie bracket actions. More precisely, it does so in a relative setting: Let `L₁` and `Lβ‚‚` be two types with Lie bracket actions on a type `M` endowed with an addition, and additionally assume a Lie bracket action of `L₁` on `Lβ‚‚`. Then the Leibniz rule asserts for all `x : L₁`, `y : Lβ‚‚`, and `m : M` that `⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆` holds. Common examples include the case where `L₁` is a Lie subalgebra of `Lβ‚‚` and the case where `Lβ‚‚` is a Lie ideal of `L₁`. -/ class IsLieTower (L₁ Lβ‚‚ M : Type*) [Bracket L₁ Lβ‚‚] [Bracket L₁ M] [Bracket Lβ‚‚ M] [Add M] where protected leibniz_lie (x : L₁) (y : Lβ‚‚) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ section IsLieTower variable {L₁ Lβ‚‚ M : Type*} [Bracket L₁ Lβ‚‚] [Bracket L₁ M] [Bracket Lβ‚‚ M] lemma leibniz_lie [Add M] [IsLieTower L₁ Lβ‚‚ M] (x : L₁) (y : Lβ‚‚) (m : M) : ⁅x, ⁅y, m⁆⁆ = ⁅⁅x, y⁆, m⁆ + ⁅y, ⁅x, m⁆⁆ := IsLieTower.leibniz_lie x y m lemma lie_swap_lie [Bracket Lβ‚‚ L₁] [AddCommGroup M] [IsLieTower L₁ Lβ‚‚ M] [IsLieTower Lβ‚‚ L₁ M] (x : L₁) (y : Lβ‚‚) (m : M) : ⁅⁅x, y⁆, m⁆ = -⁅⁅y, x⁆, m⁆ := by have h1 := leibniz_lie x y m have h2 := leibniz_lie y x m convert congr($h1.symm - $h2) using 1 <;> simp only [add_sub_cancel_right, sub_add_cancel_right] end IsLieTower section BasicProperties theorem LieAlgebra.toModule_injective (L : Type*) [LieRing L] : Function.Injective (@LieAlgebra.toModule _ _ _ _ : LieAlgebra β„š L β†’ Module β„š L) := by rintro ⟨hβ‚βŸ© ⟨hβ‚‚βŸ© heq congr instance (L : Type*) [LieRing L] : Subsingleton (LieAlgebra β„š L) := LieAlgebra.toModule_injective L |>.subsingleton variable {R : Type u} {L : Type v} {M : Type w} {N : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] [LieModule R L M] variable [AddCommGroup N] [Module R N] [LieRingModule L N] [LieModule R L N] variable (t : R) (x y z : L) (m n : M) @[simp] theorem add_lie : ⁅x + y, m⁆ = ⁅x, m⁆ + ⁅y, m⁆ := LieRingModule.add_lie x y m @[simp] theorem lie_add : ⁅x, m + n⁆ = ⁅x, m⁆ + ⁅x, n⁆ := LieRingModule.lie_add x m n @[simp] theorem smul_lie : ⁅t β€’ x, m⁆ = t β€’ ⁅x, m⁆ := LieModule.smul_lie t x m @[simp] theorem lie_smul : ⁅x, t β€’ m⁆ = t β€’ ⁅x, m⁆ := LieModule.lie_smul t x m instance : IsLieTower L L M where leibniz_lie x y m := LieRingModule.leibniz_lie x y m @[simp] theorem lie_zero : ⁅x, 0⁆ = (0 : M) := (AddMonoidHom.mk' _ (lie_add x)).map_zero @[simp] theorem zero_lie : ⁅(0 : L), m⁆ = 0 := (AddMonoidHom.mk' (fun x : L => ⁅x, m⁆) fun x y => add_lie x y m).map_zero @[simp] theorem lie_self : ⁅x, x⁆ = 0 := LieRing.lie_self x instance lieRingSelfModule : LieRingModule L L := { (inferInstance : LieRing L) with } @[simp]
Mathlib/Algebra/Lie/Basic.lean
176
176
theorem lie_skew : -⁅y, x⁆ = ⁅x, y⁆ := by
/- 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.Data.Sigma.Basic import Mathlib.Algebra.Order.Ring.Nat /-! # A computable model of ZFA without infinity In this file we define finite hereditary lists. This is useful for calculations in naive set theory. We distinguish two kinds of ZFA lists: * Atoms. Directly correspond to an element of the original type. * Proper ZFA lists. Can be thought of (but aren't implemented) as a list of ZFA lists (not necessarily proper). For example, `Lists β„•` contains stuff like `23`, `[]`, `[37]`, `[1, [[2], 3], 4]`. ## Implementation note As we want to be able to append both atoms and proper ZFA lists to proper ZFA lists, it's handy that atoms and proper ZFA lists belong to the same type, even though atoms of `Ξ±` could be modelled as `Ξ±` directly. But we don't want to be able to append anything to atoms. This calls for a two-steps definition of ZFA lists: * First, define ZFA prelists as atoms and proper ZFA prelists. Those proper ZFA prelists are defined by inductive appending of (not necessarily proper) ZFA lists. * Second, define ZFA lists by rubbing out the distinction between atoms and proper lists. ## Main declarations * `Lists' Ξ± false`: Atoms as ZFA prelists. Basically a copy of `Ξ±`. * `Lists' Ξ± true`: Proper ZFA prelists. Defined inductively from the empty ZFA prelist (`Lists'.nil`) and from appending a ZFA prelist to a proper ZFA prelist (`Lists'.cons a l`). * `Lists Ξ±`: ZFA lists. Sum of the atoms and proper ZFA prelists. * `Finsets Ξ±`: ZFA sets. Defined as `Lists` quotiented by `Lists.Equiv`, the extensional equivalence. -/ variable {Ξ± : Type*} /-- Prelists, helper type to define `Lists`. `Lists' Ξ± false` are the "atoms", a copy of `Ξ±`. `Lists' Ξ± true` are the "proper" ZFA prelists, inductively defined from the empty ZFA prelist and from appending a ZFA prelist to a proper ZFA prelist. It is made so that you can't append anything to an atom while having only one appending function for appending both atoms and proper ZFC prelists to a proper ZFA prelist. -/ inductive Lists'.{u} (Ξ± : Type u) : Bool β†’ Type u | atom : Ξ± β†’ Lists' Ξ± false | nil : Lists' Ξ± true | cons' {b} : Lists' Ξ± b β†’ Lists' Ξ± true β†’ Lists' Ξ± true deriving DecidableEq compile_inductive% Lists' /-- Hereditarily finite list, aka ZFA list. A ZFA list is either an "atom" (`b = false`), corresponding to an element of `Ξ±`, or a "proper" ZFA list, inductively defined from the empty ZFA list and from appending a ZFA list to a proper ZFA list. -/ def Lists (Ξ± : Type*) := Ξ£b, Lists' Ξ± b namespace Lists' instance [Inhabited Ξ±] : βˆ€ b, Inhabited (Lists' Ξ± b) | true => ⟨nil⟩ | false => ⟨atom default⟩ /-- Appending a ZFA list to a proper ZFA prelist. -/ def cons : Lists Ξ± β†’ Lists' Ξ± true β†’ Lists' Ξ± true | ⟨_, a⟩, l => cons' a l /-- Converts a ZFA prelist to a `List` of ZFA lists. Atoms are sent to `[]`. -/ @[simp] def toList : βˆ€ {b}, Lists' Ξ± b β†’ List (Lists Ξ±) | _, atom _ => [] | _, nil => [] | _, cons' a l => ⟨_, a⟩ :: l.toList @[simp] theorem toList_cons (a : Lists Ξ±) (l) : toList (cons a l) = a :: l.toList := rfl /-- Converts a `List` of ZFA lists to a proper ZFA prelist. -/ @[simp] def ofList : List (Lists Ξ±) β†’ Lists' Ξ± true | [] => nil | a :: l => cons a (ofList l) @[simp] theorem to_ofList (l : List (Lists Ξ±)) : toList (ofList l) = l := by induction l <;> simp [*] @[simp] theorem of_toList : βˆ€ l : Lists' Ξ± true, ofList (toList l) = l := suffices βˆ€ (b) (h : true = b) (l : Lists' Ξ± b), let l' : Lists' Ξ± true := by rw [h]; exact l ofList (toList l') = l' from this _ rfl fun b h l => by induction l with | atom => cases h | nil => simp | cons' b a _ IH => simpa [cons] using IH rfl end Lists' mutual /-- Equivalence of ZFA lists. Defined inductively. -/ inductive Lists.Equiv : Lists Ξ± β†’ Lists Ξ± β†’ Prop | refl (l) : Lists.Equiv l l | antisymm {l₁ lβ‚‚ : Lists' Ξ± true} : Lists'.Subset l₁ lβ‚‚ β†’ Lists'.Subset lβ‚‚ l₁ β†’ Lists.Equiv ⟨_, lβ‚βŸ© ⟨_, lβ‚‚βŸ© /-- Subset relation for ZFA lists. Defined inductively. -/ inductive Lists'.Subset : Lists' Ξ± true β†’ Lists' Ξ± true β†’ Prop | nil {l} : Lists'.Subset Lists'.nil l | cons {a a' l l'} : Lists.Equiv a a' β†’ a' ∈ Lists'.toList l' β†’ Lists'.Subset l l' β†’ Lists'.Subset (Lists'.cons a l) l' end local infixl:50 " ~ " => Lists.Equiv namespace Lists' instance : HasSubset (Lists' Ξ± true) := ⟨Lists'.Subset⟩ /-- ZFA prelist membership. A ZFA list is in a ZFA prelist if some element of this ZFA prelist is equivalent as a ZFA list to this ZFA list. -/ instance {b} : Membership (Lists Ξ±) (Lists' Ξ± b) := ⟨fun l a => βˆƒ a' ∈ l.toList, a ~ a'⟩ theorem mem_def {b a} {l : Lists' Ξ± b} : a ∈ l ↔ βˆƒ a' ∈ l.toList, a ~ a' := Iff.rfl @[simp] theorem mem_cons {a y l} : a ∈ @cons Ξ± y l ↔ a ~ y ∨ a ∈ l := by simp [mem_def, or_and_right, exists_or] theorem cons_subset {a} {l₁ lβ‚‚ : Lists' Ξ± true} : Lists'.cons a l₁ βŠ† lβ‚‚ ↔ a ∈ lβ‚‚ ∧ l₁ βŠ† lβ‚‚ := by refine ⟨fun h => ?_, fun ⟨⟨a', m, e⟩, s⟩ => Subset.cons e m s⟩ generalize h' : Lists'.cons a l₁ = l₁' at h obtain - | @⟨a', _, _, _, e, m, s⟩ := h Β· cases a cases h' cases a; cases a'; cases h'; exact ⟨⟨_, m, e⟩, s⟩ theorem ofList_subset {l₁ lβ‚‚ : List (Lists Ξ±)} (h : l₁ βŠ† lβ‚‚) : Lists'.ofList l₁ βŠ† Lists'.ofList lβ‚‚ := by induction l₁ with | nil => exact Subset.nil | cons _ _ l₁_ih => refine Subset.cons (Lists.Equiv.refl _) ?_ (l₁_ih (List.subset_of_cons_subset h)) simp only [List.cons_subset] at h; simp [h] @[refl] theorem Subset.refl {l : Lists' Ξ± true} : l βŠ† l := by rw [← Lists'.of_toList l]; exact ofList_subset (List.Subset.refl _) theorem subset_nil {l : Lists' Ξ± true} : l βŠ† Lists'.nil β†’ l = Lists'.nil := by rw [← of_toList l] induction toList l <;> intro h Β· rfl Β· rcases cons_subset.1 h with ⟨⟨_, ⟨⟩, _⟩, _⟩ theorem mem_of_subset' {a} : βˆ€ {l₁ lβ‚‚ : Lists' Ξ± true} (_ : l₁ βŠ† lβ‚‚) (_ : a ∈ l₁.toList), a ∈ lβ‚‚ | nil, _, Lists'.Subset.nil, h => by cases h | cons' a0 l0, lβ‚‚, s, h => by obtain - | ⟨e, m, s⟩ := s simp only [toList, Sigma.eta, List.find?, List.mem_cons] at h rcases h with (rfl | h) Β· exact ⟨_, m, e⟩ Β· exact mem_of_subset' s h theorem subset_def {l₁ lβ‚‚ : Lists' Ξ± true} : l₁ βŠ† lβ‚‚ ↔ βˆ€ a ∈ l₁.toList, a ∈ lβ‚‚ := ⟨fun H _ => mem_of_subset' H, fun H => by rw [← of_toList l₁] revert H; induction' toList l₁ with h t t_ih <;> intro H Β· exact Subset.nil Β· simp only [ofList, List.find?, List.mem_cons, forall_eq_or_imp] at * exact cons_subset.2 ⟨H.1, t_ih H.2⟩⟩ end Lists' namespace Lists /-- Sends `a : Ξ±` to the corresponding atom in `Lists Ξ±`. -/ @[match_pattern] def atom (a : Ξ±) : Lists Ξ± := ⟨_, Lists'.atom a⟩ /-- Converts a proper ZFA prelist to a ZFA list. -/ @[match_pattern] def of' (l : Lists' Ξ± true) : Lists Ξ± := ⟨_, l⟩ /-- Converts a ZFA list to a `List` of ZFA lists. Atoms are sent to `[]`. -/ @[simp] def toList : Lists Ξ± β†’ List (Lists Ξ±) | ⟨_, l⟩ => l.toList /-- Predicate stating that a ZFA list is proper. -/ def IsList (l : Lists Ξ±) : Prop := l.1 /-- Converts a `List` of ZFA lists to a ZFA list. -/ def ofList (l : List (Lists Ξ±)) : Lists Ξ± := of' (Lists'.ofList l) theorem isList_toList (l : List (Lists Ξ±)) : IsList (ofList l) := Eq.refl _ theorem to_ofList (l : List (Lists Ξ±)) : toList (ofList l) = l := by simp [ofList, of'] theorem of_toList : βˆ€ {l : Lists Ξ±}, IsList l β†’ ofList (toList l) = l | ⟨true, l⟩, _ => by simp_all [ofList, of'] instance : Inhabited (Lists Ξ±) := ⟨of' Lists'.nil⟩ instance [DecidableEq Ξ±] : DecidableEq (Lists Ξ±) := by unfold Lists; infer_instance instance [SizeOf Ξ±] : SizeOf (Lists Ξ±) := by unfold Lists; infer_instance /-- A recursion principle for pairs of ZFA lists and proper ZFA prelists. -/ def inductionMut (C : Lists Ξ± β†’ Sort*) (D : Lists' Ξ± true β†’ Sort*) (C0 : βˆ€ a, C (atom a)) (C1 : βˆ€ l, D l β†’ C (of' l)) (D0 : D Lists'.nil) (D1 : βˆ€ a l, C a β†’ D l β†’ D (Lists'.cons a l)) : PProd (βˆ€ l, C l) (βˆ€ l, D l) := by suffices βˆ€ {b} (l : Lists' Ξ± b), PProd (C ⟨_, l⟩) (match b, l with | true, l => D l | false, _ => PUnit) by exact ⟨fun ⟨b, l⟩ => (this _).1, fun l => (this l).2⟩ intros b l induction' l with a b a l IH₁ IH Β· exact ⟨C0 _, ⟨⟩⟩ Β· exact ⟨C1 _ D0, D0⟩ Β· have : D (Lists'.cons' a l) := D1 ⟨_, _⟩ _ IH₁.1 IH.2 exact ⟨C1 _ this, this⟩ /-- Membership of ZFA list. A ZFA list belongs to a proper ZFA list if it belongs to the latter as a proper ZFA prelist. An atom has no members. -/ def mem (a : Lists Ξ±) : Lists Ξ± β†’ Prop | ⟨false, _⟩ => False | ⟨_, l⟩ => a ∈ l instance : Membership (Lists Ξ±) (Lists Ξ±) where mem ls l := mem l ls theorem isList_of_mem {a : Lists Ξ±} : βˆ€ {l : Lists Ξ±}, a ∈ l β†’ IsList l | ⟨_, Lists'.nil⟩, _ => rfl | ⟨_, Lists'.cons' _ _⟩, _ => rfl theorem Equiv.antisymm_iff {l₁ lβ‚‚ : Lists' Ξ± true} : of' l₁ ~ of' lβ‚‚ ↔ l₁ βŠ† lβ‚‚ ∧ lβ‚‚ βŠ† l₁ := by refine ⟨fun h => ?_, fun ⟨h₁, hβ‚‚βŸ© => Equiv.antisymm h₁ hβ‚‚βŸ© obtain - | ⟨h₁, hβ‚‚βŸ© := h Β· simp [Lists'.Subset.refl] Β· exact ⟨h₁, hβ‚‚βŸ© attribute [refl] Equiv.refl theorem equiv_atom {a} {l : Lists Ξ±} : atom a ~ l ↔ atom a = l := ⟨fun h => by cases h; rfl, fun h => h β–Έ Equiv.refl _⟩ @[symm] theorem Equiv.symm {l₁ lβ‚‚ : Lists Ξ±} (h : l₁ ~ lβ‚‚) : lβ‚‚ ~ l₁ := by obtain - | ⟨h₁, hβ‚‚βŸ© := h <;> [rfl; exact Equiv.antisymm hβ‚‚ h₁] theorem Equiv.trans : βˆ€ {l₁ lβ‚‚ l₃ : Lists Ξ±}, l₁ ~ lβ‚‚ β†’ lβ‚‚ ~ l₃ β†’ l₁ ~ l₃ := by let trans := fun l₁ : Lists Ξ± => βˆ€ ⦃lβ‚‚ l₃⦄, l₁ ~ lβ‚‚ β†’ lβ‚‚ ~ l₃ β†’ l₁ ~ l₃ suffices PProd (βˆ€ l₁, trans l₁) (βˆ€ (l : Lists' Ξ± true), βˆ€ l' ∈ l.toList, trans l') by exact this.1 apply inductionMut Β· intro a lβ‚‚ l₃ h₁ hβ‚‚ rwa [← equiv_atom.1 h₁] at hβ‚‚ Β· intro l₁ IH lβ‚‚ l₃ h₁ hβ‚‚ obtain - | lβ‚‚ := id h₁ Β· exact hβ‚‚ obtain - | l₃ := id hβ‚‚ Β· exact h₁ obtain ⟨hl₁, hrβ‚βŸ© := Equiv.antisymm_iff.1 h₁ obtain ⟨hlβ‚‚, hrβ‚‚βŸ© := Equiv.antisymm_iff.1 hβ‚‚ apply Equiv.antisymm_iff.2; constructor <;> apply Lists'.subset_def.2 Β· intro a₁ m₁ rcases Lists'.mem_of_subset' hl₁ m₁ with ⟨aβ‚‚, mβ‚‚, eβ‚β‚‚βŸ© rcases Lists'.mem_of_subset' hlβ‚‚ mβ‚‚ with ⟨a₃, m₃, eβ‚‚β‚ƒβŸ© exact ⟨a₃, m₃, IH _ m₁ e₁₂ eβ‚‚β‚ƒβŸ© Β· intro a₃ m₃ rcases Lists'.mem_of_subset' hrβ‚‚ m₃ with ⟨aβ‚‚, mβ‚‚, eβ‚ƒβ‚‚βŸ© rcases Lists'.mem_of_subset' hr₁ mβ‚‚ with ⟨a₁, m₁, eβ‚‚β‚βŸ© exact ⟨a₁, m₁, (IH _ m₁ e₂₁.symm e₃₂.symm).symm⟩ Β· rintro _ ⟨⟩ Β· intro a l IH₁ IHβ‚‚ simpa using ⟨IH₁, IHβ‚‚βŸ© instance instSetoidLists : Setoid (Lists Ξ±) := ⟨(Β· ~ Β·), Equiv.refl, @Equiv.symm _, @Equiv.trans _⟩ section Decidable
Mathlib/SetTheory/Lists.lean
304
305
theorem sizeof_pos {b} (l : Lists' Ξ± b) : 0 < SizeOf.sizeOf l := by
cases l <;> simp only [Lists'.atom.sizeOf_spec, Lists'.nil.sizeOf_spec, Lists'.cons'.sizeOf_spec,
/- Copyright (c) 2019 Calle SΓΆnne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Calle SΓΆnne -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic import Mathlib.Analysis.Normed.Group.AddCircle import Mathlib.Algebra.CharZero.Quotient import Mathlib.Topology.Instances.Sign /-! # The type of angles In this file we define `Real.Angle` to be the quotient group `ℝ/2Ο€β„€` and prove a few simple lemmas about trigonometric functions and angles. -/ open Real noncomputable section namespace Real /-- The type of angles -/ def Angle : Type := AddCircle (2 * Ο€) -- The `NormedAddCommGroup, Inhabited` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 namespace Angle instance : NormedAddCommGroup Angle := inferInstanceAs (NormedAddCommGroup (AddCircle (2 * Ο€))) instance : Inhabited Angle := inferInstanceAs (Inhabited (AddCircle (2 * Ο€))) /-- The canonical map from `ℝ` to the quotient `Angle`. -/ @[coe] protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r instance : Coe ℝ Angle := ⟨Angle.coe⟩ instance : CircularOrder Real.Angle := QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩) @[continuity] theorem continuous_coe : Continuous ((↑) : ℝ β†’ Angle) := continuous_quotient_mk' /-- Coercion `ℝ β†’ Angle` as an additive homomorphism. -/ def coeHom : ℝ β†’+ Angle := QuotientAddGroup.mk' _ @[simp] theorem coe_coeHom : (coeHom : ℝ β†’ Angle) = ((↑) : ℝ β†’ Angle) := rfl /-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with `induction ΞΈ using Real.Angle.induction_on`. -/ @[elab_as_elim] protected theorem induction_on {p : Angle β†’ Prop} (ΞΈ : Angle) (h : βˆ€ x : ℝ, p x) : p ΞΈ := Quotient.inductionOn' ΞΈ h @[simp] theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) := rfl @[simp] theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) := rfl @[simp] theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) := rfl @[simp] theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) := rfl theorem coe_nsmul (n : β„•) (x : ℝ) : ↑(n β€’ x : ℝ) = n β€’ (↑x : Angle) := rfl theorem coe_zsmul (z : β„€) (x : ℝ) : ↑(z β€’ x : ℝ) = z β€’ (↑x : Angle) := rfl theorem coe_eq_zero_iff {x : ℝ} : (x : Angle) = 0 ↔ βˆƒ n : β„€, n β€’ (2 * Ο€) = x := AddCircle.coe_eq_zero_iff (2 * Ο€) @[simp, norm_cast] theorem natCast_mul_eq_nsmul (x : ℝ) (n : β„•) : ↑((n : ℝ) * x) = n β€’ (↑x : Angle) := by simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n @[simp, norm_cast] theorem intCast_mul_eq_zsmul (x : ℝ) (n : β„€) : ↑((n : ℝ) * x : ℝ) = n β€’ (↑x : Angle) := by simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n theorem angle_eq_iff_two_pi_dvd_sub {ψ ΞΈ : ℝ} : (ΞΈ : Angle) = ψ ↔ βˆƒ k : β„€, ΞΈ - ψ = 2 * Ο€ * k := by simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] rw [Angle.coe, Angle.coe, QuotientAddGroup.eq] simp only [AddSubgroup.zmultiples_eq_closure, AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm] @[simp] theorem coe_two_pi : ↑(2 * Ο€ : ℝ) = (0 : Angle) := angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩ @[simp] theorem neg_coe_pi : -(Ο€ : Angle) = Ο€ := by rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub] use -1 simp [two_mul, sub_eq_add_neg] @[simp] theorem two_nsmul_coe_div_two (ΞΈ : ℝ) : (2 : β„•) β€’ (↑(ΞΈ / 2) : Angle) = ΞΈ := by rw [← coe_nsmul, two_nsmul, add_halves] @[simp] theorem two_zsmul_coe_div_two (ΞΈ : ℝ) : (2 : β„€) β€’ (↑(ΞΈ / 2) : Angle) = ΞΈ := by rw [← coe_zsmul, two_zsmul, add_halves] theorem two_nsmul_neg_pi_div_two : (2 : β„•) β€’ (↑(-Ο€ / 2) : Angle) = Ο€ := by rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi] theorem two_zsmul_neg_pi_div_two : (2 : β„€) β€’ (↑(-Ο€ / 2) : Angle) = Ο€ := by rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two] theorem sub_coe_pi_eq_add_coe_pi (ΞΈ : Angle) : ΞΈ - Ο€ = ΞΈ + Ο€ := by rw [sub_eq_add_neg, neg_coe_pi] @[simp] theorem two_nsmul_coe_pi : (2 : β„•) β€’ (Ο€ : Angle) = 0 := by simp [← natCast_mul_eq_nsmul] @[simp] theorem two_zsmul_coe_pi : (2 : β„€) β€’ (Ο€ : Angle) = 0 := by simp [← intCast_mul_eq_zsmul] @[simp] theorem coe_pi_add_coe_pi : (Ο€ : Real.Angle) + Ο€ = 0 := by rw [← two_nsmul, two_nsmul_coe_pi] theorem zsmul_eq_iff {ψ ΞΈ : Angle} {z : β„€} (hz : z β‰  0) : z β€’ ψ = z β€’ ΞΈ ↔ βˆƒ k : Fin z.natAbs, ψ = ΞΈ + (k : β„•) β€’ (2 * Ο€ / z : ℝ) := QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz theorem nsmul_eq_iff {ψ ΞΈ : Angle} {n : β„•} (hz : n β‰  0) : n β€’ ψ = n β€’ ΞΈ ↔ βˆƒ k : Fin n, ψ = ΞΈ + (k : β„•) β€’ (2 * Ο€ / n : ℝ) := QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz theorem two_zsmul_eq_iff {ψ ΞΈ : Angle} : (2 : β„€) β€’ ψ = (2 : β„€) β€’ ΞΈ ↔ ψ = ΞΈ ∨ ψ = ΞΈ + ↑π := by have : Int.natAbs 2 = 2 := rfl rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero, Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two, mul_div_cancel_leftβ‚€ (_ : ℝ) two_ne_zero] theorem two_nsmul_eq_iff {ψ ΞΈ : Angle} : (2 : β„•) β€’ ψ = (2 : β„•) β€’ ΞΈ ↔ ψ = ΞΈ ∨ ψ = ΞΈ + ↑π := by simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff] theorem two_nsmul_eq_zero_iff {ΞΈ : Angle} : (2 : β„•) β€’ ΞΈ = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by convert two_nsmul_eq_iff <;> simp theorem two_nsmul_ne_zero_iff {ΞΈ : Angle} : (2 : β„•) β€’ ΞΈ β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← two_nsmul_eq_zero_iff] theorem two_zsmul_eq_zero_iff {ΞΈ : Angle} : (2 : β„€) β€’ ΞΈ = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff] theorem two_zsmul_ne_zero_iff {ΞΈ : Angle} : (2 : β„€) β€’ ΞΈ β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← two_zsmul_eq_zero_iff] theorem eq_neg_self_iff {ΞΈ : Angle} : ΞΈ = -ΞΈ ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff] theorem ne_neg_self_iff {ΞΈ : Angle} : ΞΈ β‰  -ΞΈ ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← eq_neg_self_iff.not] theorem neg_eq_self_iff {ΞΈ : Angle} : -ΞΈ = ΞΈ ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by rw [eq_comm, eq_neg_self_iff] theorem neg_ne_self_iff {ΞΈ : Angle} : -ΞΈ β‰  ΞΈ ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← neg_eq_self_iff.not] theorem two_nsmul_eq_pi_iff {ΞΈ : Angle} : (2 : β„•) β€’ ΞΈ = Ο€ ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by have h : (Ο€ : Angle) = ((2 : β„•) β€’ (Ο€ / 2 : ℝ):) := by rw [two_nsmul, add_halves] nth_rw 1 [h] rw [coe_nsmul, two_nsmul_eq_iff] -- Porting note: `congr` didn't simplify the goal of iff of `Or`s convert Iff.rfl rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc, add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero] theorem two_zsmul_eq_pi_iff {ΞΈ : Angle} : (2 : β„€) β€’ ΞΈ = Ο€ ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff] theorem cos_eq_iff_coe_eq_or_eq_neg {ΞΈ ψ : ℝ} : cos ΞΈ = cos ψ ↔ (ΞΈ : Angle) = ψ ∨ (ΞΈ : Angle) = -ψ := by constructor Β· intro Hcos rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero, eq_false (two_ne_zero' ℝ), false_or, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩) Β· right rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero] Β· left rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero, zero_add] Β· rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) Β· rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 Ο€ k, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), mul_comm Ο€ _, sin_int_mul_pi, mul_zero] rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 Ο€ k, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), mul_comm Ο€ _, sin_int_mul_pi, mul_zero, zero_mul] theorem sin_eq_iff_coe_eq_or_add_eq_pi {ΞΈ ψ : ℝ} : sin ΞΈ = sin ψ ↔ (ΞΈ : Angle) = ψ ∨ (ΞΈ : Angle) + ψ = Ο€ := by constructor Β· intro Hsin rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h | h Β· left rw [coe_sub, coe_sub] at h exact sub_right_inj.1 h right rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add, add_halves, sub_sub, sub_eq_zero] at h exact h.symm Β· rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub] rintro (⟨k, H⟩ | ⟨k, H⟩) Β· rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 Ο€ k, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), mul_comm Ο€ _, sin_int_mul_pi, mul_zero, zero_mul] have H' : ΞΈ + ψ = 2 * k * Ο€ + Ο€ := by rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm Ο€ _, ← mul_assoc] at H rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ Ο€, mul_div_cancel_leftβ‚€ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero, mul_zero] theorem cos_sin_inj {ΞΈ ψ : ℝ} (Hcos : cos ΞΈ = cos ψ) (Hsin : sin ΞΈ = sin ψ) : (ΞΈ : Angle) = ψ := by rcases cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc | hc; Β· exact hc rcases sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs | hs; Β· exact hs rw [eq_neg_iff_add_eq_zero, hs] at hc obtain ⟨n, hn⟩ : βˆƒ n, n β€’ _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc) rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero, eq_false (ne_of_gt pi_pos), or_false, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one, ← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn have : (n * 2 + 1) % (2 : β„€) = 0 % (2 : β„€) := congr_arg (Β· % (2 : β„€)) hn rw [add_comm, Int.add_mul_emod_self_right] at this exact absurd this one_ne_zero /-- The sine of a `Real.Angle`. -/ def sin (ΞΈ : Angle) : ℝ := sin_periodic.lift ΞΈ @[simp] theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x := rfl @[continuity] theorem continuous_sin : Continuous sin := Real.continuous_sin.quotient_liftOn' _ /-- The cosine of a `Real.Angle`. -/ def cos (ΞΈ : Angle) : ℝ := cos_periodic.lift ΞΈ @[simp] theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x := rfl @[continuity] theorem continuous_cos : Continuous cos := Real.continuous_cos.quotient_liftOn' _ theorem cos_eq_real_cos_iff_eq_or_eq_neg {ΞΈ : Angle} {ψ : ℝ} : cos ΞΈ = Real.cos ψ ↔ ΞΈ = ψ ∨ ΞΈ = -ψ := by induction ΞΈ using Real.Angle.induction_on exact cos_eq_iff_coe_eq_or_eq_neg theorem cos_eq_iff_eq_or_eq_neg {ΞΈ ψ : Angle} : cos ΞΈ = cos ψ ↔ ΞΈ = ψ ∨ ΞΈ = -ψ := by induction ψ using Real.Angle.induction_on exact cos_eq_real_cos_iff_eq_or_eq_neg theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {ΞΈ : Angle} {ψ : ℝ} : sin ΞΈ = Real.sin ψ ↔ ΞΈ = ψ ∨ ΞΈ + ψ = Ο€ := by induction ΞΈ using Real.Angle.induction_on exact sin_eq_iff_coe_eq_or_add_eq_pi theorem sin_eq_iff_eq_or_add_eq_pi {ΞΈ ψ : Angle} : sin ΞΈ = sin ψ ↔ ΞΈ = ψ ∨ ΞΈ + ψ = Ο€ := by induction ψ using Real.Angle.induction_on exact sin_eq_real_sin_iff_eq_or_add_eq_pi @[simp] theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero] theorem sin_coe_pi : sin (Ο€ : Angle) = 0 := by rw [sin_coe, Real.sin_pi] theorem sin_eq_zero_iff {ΞΈ : Angle} : sin ΞΈ = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by nth_rw 1 [← sin_zero] rw [sin_eq_iff_eq_or_add_eq_pi] simp theorem sin_ne_zero_iff {ΞΈ : Angle} : sin ΞΈ β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← sin_eq_zero_iff] @[simp] theorem sin_neg (ΞΈ : Angle) : sin (-ΞΈ) = -sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_neg _ theorem sin_antiperiodic : Function.Antiperiodic sin (Ο€ : Angle) := by intro ΞΈ induction ΞΈ using Real.Angle.induction_on exact Real.sin_antiperiodic _ @[simp] theorem sin_add_pi (ΞΈ : Angle) : sin (ΞΈ + Ο€) = -sin ΞΈ := sin_antiperiodic ΞΈ @[simp] theorem sin_sub_pi (ΞΈ : Angle) : sin (ΞΈ - Ο€) = -sin ΞΈ := sin_antiperiodic.sub_eq ΞΈ @[simp] theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero] theorem cos_coe_pi : cos (Ο€ : Angle) = -1 := by rw [cos_coe, Real.cos_pi] @[simp] theorem cos_neg (ΞΈ : Angle) : cos (-ΞΈ) = cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_neg _ theorem cos_antiperiodic : Function.Antiperiodic cos (Ο€ : Angle) := by intro ΞΈ induction ΞΈ using Real.Angle.induction_on exact Real.cos_antiperiodic _ @[simp] theorem cos_add_pi (ΞΈ : Angle) : cos (ΞΈ + Ο€) = -cos ΞΈ := cos_antiperiodic ΞΈ @[simp] theorem cos_sub_pi (ΞΈ : Angle) : cos (ΞΈ - Ο€) = -cos ΞΈ := cos_antiperiodic.sub_eq ΞΈ theorem cos_eq_zero_iff {ΞΈ : Angle} : cos ΞΈ = 0 ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div] theorem sin_add (θ₁ ΞΈβ‚‚ : Real.Angle) : sin (θ₁ + ΞΈβ‚‚) = sin θ₁ * cos ΞΈβ‚‚ + cos θ₁ * sin ΞΈβ‚‚ := by induction θ₁ using Real.Angle.induction_on induction ΞΈβ‚‚ using Real.Angle.induction_on exact Real.sin_add _ _ theorem cos_add (θ₁ ΞΈβ‚‚ : Real.Angle) : cos (θ₁ + ΞΈβ‚‚) = cos θ₁ * cos ΞΈβ‚‚ - sin θ₁ * sin ΞΈβ‚‚ := by induction ΞΈβ‚‚ using Real.Angle.induction_on induction θ₁ using Real.Angle.induction_on exact Real.cos_add _ _ @[simp] theorem cos_sq_add_sin_sq (ΞΈ : Real.Angle) : cos ΞΈ ^ 2 + sin ΞΈ ^ 2 = 1 := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_sq_add_sin_sq _ theorem sin_add_pi_div_two (ΞΈ : Angle) : sin (ΞΈ + ↑(Ο€ / 2)) = cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_add_pi_div_two _ theorem sin_sub_pi_div_two (ΞΈ : Angle) : sin (ΞΈ - ↑(Ο€ / 2)) = -cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_sub_pi_div_two _ theorem sin_pi_div_two_sub (ΞΈ : Angle) : sin (↑(Ο€ / 2) - ΞΈ) = cos ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.sin_pi_div_two_sub _ theorem cos_add_pi_div_two (ΞΈ : Angle) : cos (ΞΈ + ↑(Ο€ / 2)) = -sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_add_pi_div_two _ theorem cos_sub_pi_div_two (ΞΈ : Angle) : cos (ΞΈ - ↑(Ο€ / 2)) = sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_sub_pi_div_two _ theorem cos_pi_div_two_sub (ΞΈ : Angle) : cos (↑(Ο€ / 2) - ΞΈ) = sin ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact Real.cos_pi_div_two_sub _ theorem abs_sin_eq_of_two_nsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ) : |sin ΞΈ| = |sin ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) Β· rfl Β· rw [sin_add_pi, abs_neg] theorem abs_sin_eq_of_two_zsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ) : |sin ΞΈ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_sin_eq_of_two_nsmul_eq h theorem abs_cos_eq_of_two_nsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ) : |cos ΞΈ| = |cos ψ| := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) Β· rfl Β· rw [cos_add_pi, abs_neg] theorem abs_cos_eq_of_two_zsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ) : |cos ΞΈ| = |cos ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_of_two_nsmul_eq h @[simp] theorem coe_toIcoMod (ΞΈ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ ΞΈ) = (ΞΈ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIcoDiv two_pi_pos ψ ΞΈ, ?_⟩ rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm] @[simp] theorem coe_toIocMod (ΞΈ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ ΞΈ) = (ΞΈ : Angle) := by rw [angle_eq_iff_two_pi_dvd_sub] refine ⟨-toIocDiv two_pi_pos ψ ΞΈ, ?_⟩ rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm] /-- Convert a `Real.Angle` to a real number in the interval `Ioc (-Ο€) Ο€`. -/ def toReal (ΞΈ : Angle) : ℝ := (toIocMod_periodic two_pi_pos (-Ο€)).lift ΞΈ theorem toReal_coe (ΞΈ : ℝ) : (ΞΈ : Angle).toReal = toIocMod two_pi_pos (-Ο€) ΞΈ := rfl theorem toReal_coe_eq_self_iff {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ ↔ -Ο€ < ΞΈ ∧ ΞΈ ≀ Ο€ := by rw [toReal_coe, toIocMod_eq_self two_pi_pos] ring_nf rfl theorem toReal_coe_eq_self_iff_mem_Ioc {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ ↔ ΞΈ ∈ Set.Ioc (-Ο€) Ο€ := by rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc] theorem toReal_injective : Function.Injective toReal := by intro ΞΈ ψ h induction ΞΈ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * Ο€), ← angle_eq_iff_two_pi_dvd_sub, eq_comm] using h @[simp] theorem toReal_inj {ΞΈ ψ : Angle} : ΞΈ.toReal = ψ.toReal ↔ ΞΈ = ψ := toReal_injective.eq_iff @[simp] theorem coe_toReal (ΞΈ : Angle) : (ΞΈ.toReal : Angle) = ΞΈ := by induction ΞΈ using Real.Angle.induction_on exact coe_toIocMod _ _ theorem neg_pi_lt_toReal (ΞΈ : Angle) : -Ο€ < ΞΈ.toReal := by induction ΞΈ using Real.Angle.induction_on exact left_lt_toIocMod _ _ _ theorem toReal_le_pi (ΞΈ : Angle) : ΞΈ.toReal ≀ Ο€ := by induction ΞΈ using Real.Angle.induction_on convert toIocMod_le_right two_pi_pos _ _ ring theorem abs_toReal_le_pi (ΞΈ : Angle) : |ΞΈ.toReal| ≀ Ο€ := abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩ theorem toReal_mem_Ioc (ΞΈ : Angle) : ΞΈ.toReal ∈ Set.Ioc (-Ο€) Ο€ := ⟨neg_pi_lt_toReal _, toReal_le_pi _⟩ @[simp] theorem toIocMod_toReal (ΞΈ : Angle) : toIocMod two_pi_pos (-Ο€) ΞΈ.toReal = ΞΈ.toReal := by induction ΞΈ using Real.Angle.induction_on rw [toReal_coe] exact toIocMod_toIocMod _ _ _ _ @[simp] theorem toReal_zero : (0 : Angle).toReal = 0 := by rw [← coe_zero, toReal_coe_eq_self_iff] exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩ @[simp] theorem toReal_eq_zero_iff {ΞΈ : Angle} : ΞΈ.toReal = 0 ↔ ΞΈ = 0 := by nth_rw 1 [← toReal_zero] exact toReal_inj @[simp] theorem toReal_pi : (Ο€ : Angle).toReal = Ο€ := by rw [toReal_coe_eq_self_iff] exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩ @[simp] theorem toReal_eq_pi_iff {ΞΈ : Angle} : ΞΈ.toReal = Ο€ ↔ ΞΈ = Ο€ := by rw [← toReal_inj, toReal_pi] theorem pi_ne_zero : (Ο€ : Angle) β‰  0 := by rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero] exact Real.pi_ne_zero @[simp] theorem toReal_pi_div_two : ((Ο€ / 2 : ℝ) : Angle).toReal = Ο€ / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_pi_div_two_iff {ΞΈ : Angle} : ΞΈ.toReal = Ο€ / 2 ↔ ΞΈ = (Ο€ / 2 : ℝ) := by rw [← toReal_inj, toReal_pi_div_two] @[simp] theorem toReal_neg_pi_div_two : ((-Ο€ / 2 : ℝ) : Angle).toReal = -Ο€ / 2 := toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos] @[simp] theorem toReal_eq_neg_pi_div_two_iff {ΞΈ : Angle} : ΞΈ.toReal = -Ο€ / 2 ↔ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [← toReal_inj, toReal_neg_pi_div_two] theorem pi_div_two_ne_zero : ((Ο€ / 2 : ℝ) : Angle) β‰  0 := by rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero] exact div_ne_zero Real.pi_ne_zero two_ne_zero theorem neg_pi_div_two_ne_zero : ((-Ο€ / 2 : ℝ) : Angle) β‰  0 := by rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero] exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero theorem abs_toReal_coe_eq_self_iff {ΞΈ : ℝ} : |(ΞΈ : Angle).toReal| = ΞΈ ↔ 0 ≀ ΞΈ ∧ ΞΈ ≀ Ο€ := ⟨fun h => h β–Έ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => (toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm β–Έ abs_eq_self.2 h.1⟩ theorem abs_toReal_neg_coe_eq_self_iff {ΞΈ : ℝ} : |(-ΞΈ : Angle).toReal| = ΞΈ ↔ 0 ≀ ΞΈ ∧ ΞΈ ≀ Ο€ := by refine ⟨fun h => h β–Έ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩ by_cases hnegpi : ΞΈ = Ο€; Β· simp [hnegpi, Real.pi_pos.le] rw [← coe_neg, toReal_coe_eq_self_iff.2 ⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩, abs_neg, abs_eq_self.2 h.1] theorem abs_toReal_eq_pi_div_two_iff {ΞΈ : Angle} : |ΞΈ.toReal| = Ο€ / 2 ↔ ΞΈ = (Ο€ / 2 : ℝ) ∨ ΞΈ = (-Ο€ / 2 : ℝ) := by rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff, toReal_eq_neg_pi_div_two_iff] theorem nsmul_toReal_eq_mul {n : β„•} (h : n β‰  0) {ΞΈ : Angle} : (n β€’ ΞΈ).toReal = n * ΞΈ.toReal ↔ ΞΈ.toReal ∈ Set.Ioc (-Ο€ / n) (Ο€ / n) := by nth_rw 1 [← coe_toReal ΞΈ] have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iffβ‚€' h', le_div_iffβ‚€' h'] theorem two_nsmul_toReal_eq_two_mul {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal ↔ ΞΈ.toReal ∈ Set.Ioc (-Ο€ / 2) (Ο€ / 2) := mod_cast nsmul_toReal_eq_mul two_ne_zero theorem two_zsmul_toReal_eq_two_mul {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal ↔ ΞΈ.toReal ∈ Set.Ioc (-Ο€ / 2) (Ο€ / 2) := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul] theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {ΞΈ : ℝ} {k : β„€} : (ΞΈ : Angle).toReal = ΞΈ - 2 * k * Ο€ ↔ ΞΈ ∈ Set.Ioc ((2 * k - 1 : ℝ) * Ο€) ((2 * k + 1) * Ο€) := by rw [← sub_zero (ΞΈ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ← mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc] exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩ theorem toReal_coe_eq_self_sub_two_pi_iff {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ - 2 * Ο€ ↔ ΞΈ ∈ Set.Ioc Ο€ (3 * Ο€) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff ΞΈ 1 <;> norm_num theorem toReal_coe_eq_self_add_two_pi_iff {ΞΈ : ℝ} : (ΞΈ : Angle).toReal = ΞΈ + 2 * Ο€ ↔ ΞΈ ∈ Set.Ioc (-3 * Ο€) (-Ο€) := by convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff ΞΈ (-1) using 2 <;> norm_num theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal - 2 * Ο€ ↔ Ο€ / 2 < ΞΈ.toReal := by nth_rw 1 [← coe_toReal ΞΈ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc] exact ⟨fun h => by linarith, fun h => ⟨(div_lt_iffβ‚€' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi ΞΈ]⟩⟩ theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal - 2 * Ο€ ↔ Ο€ / 2 < ΞΈ.toReal := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_sub_two_pi] theorem two_nsmul_toReal_eq_two_mul_add_two_pi {ΞΈ : Angle} : ((2 : β„•) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal + 2 * Ο€ ↔ ΞΈ.toReal ≀ -Ο€ / 2 := by nth_rw 1 [← coe_toReal ΞΈ] rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc] refine ⟨fun h => by linarith, fun h => ⟨by linarith [pi_pos, neg_pi_lt_toReal ΞΈ], (le_div_iffβ‚€' (zero_lt_two' ℝ)).1 h⟩⟩ theorem two_zsmul_toReal_eq_two_mul_add_two_pi {ΞΈ : Angle} : ((2 : β„€) β€’ ΞΈ).toReal = 2 * ΞΈ.toReal + 2 * Ο€ ↔ ΞΈ.toReal ≀ -Ο€ / 2 := by rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_add_two_pi] @[simp] theorem sin_toReal (ΞΈ : Angle) : Real.sin ΞΈ.toReal = sin ΞΈ := by conv_rhs => rw [← coe_toReal ΞΈ, sin_coe] @[simp] theorem cos_toReal (ΞΈ : Angle) : Real.cos ΞΈ.toReal = cos ΞΈ := by conv_rhs => rw [← coe_toReal ΞΈ, cos_coe] theorem cos_nonneg_iff_abs_toReal_le_pi_div_two {ΞΈ : Angle} : 0 ≀ cos ΞΈ ↔ |ΞΈ.toReal| ≀ Ο€ / 2 := by nth_rw 1 [← coe_toReal ΞΈ] rw [abs_le, cos_coe] refine ⟨fun h => ?_, cos_nonneg_of_mem_Icc⟩ by_contra hn rw [not_and_or, not_le, not_le] at hn refine (not_lt.2 h) ?_ rcases hn with (hn | hn) Β· rw [← Real.cos_neg] refine cos_neg_of_pi_div_two_lt_of_lt (by linarith) ?_ linarith [neg_pi_lt_toReal ΞΈ] Β· refine cos_neg_of_pi_div_two_lt_of_lt hn ?_ linarith [toReal_le_pi ΞΈ] theorem cos_pos_iff_abs_toReal_lt_pi_div_two {ΞΈ : Angle} : 0 < cos ΞΈ ↔ |ΞΈ.toReal| < Ο€ / 2 := by rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ← and_congr_right] rintro - rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff] theorem cos_neg_iff_pi_div_two_lt_abs_toReal {ΞΈ : Angle} : cos ΞΈ < 0 ↔ Ο€ / 2 < |ΞΈ.toReal| := by rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two] theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ + (2 : β„•) β€’ ψ = Ο€) : |cos ΞΈ| = |sin ψ| := by rw [← eq_sub_iff_add_eq, ← two_nsmul_coe_div_two, ← nsmul_sub, two_nsmul_eq_iff] at h rcases h with (rfl | rfl) <;> simp [cos_pi_div_two_sub] theorem abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ + (2 : β„€) β€’ ψ = Ο€) : |cos ΞΈ| = |sin ψ| := by simp_rw [two_zsmul, ← two_nsmul] at h exact abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi h /-- The tangent of a `Real.Angle`. -/ def tan (ΞΈ : Angle) : ℝ := sin ΞΈ / cos ΞΈ theorem tan_eq_sin_div_cos (ΞΈ : Angle) : tan ΞΈ = sin ΞΈ / cos ΞΈ := rfl @[simp] theorem tan_coe (x : ℝ) : tan (x : Angle) = Real.tan x := by rw [tan, sin_coe, cos_coe, Real.tan_eq_sin_div_cos] @[simp] theorem tan_zero : tan (0 : Angle) = 0 := by rw [← coe_zero, tan_coe, Real.tan_zero] theorem tan_coe_pi : tan (Ο€ : Angle) = 0 := by rw [tan_coe, Real.tan_pi] theorem tan_periodic : Function.Periodic tan (Ο€ : Angle) := by intro ΞΈ induction ΞΈ using Real.Angle.induction_on rw [← coe_add, tan_coe, tan_coe] exact Real.tan_periodic _ @[simp] theorem tan_add_pi (ΞΈ : Angle) : tan (ΞΈ + Ο€) = tan ΞΈ := tan_periodic ΞΈ @[simp] theorem tan_sub_pi (ΞΈ : Angle) : tan (ΞΈ - Ο€) = tan ΞΈ := tan_periodic.sub_eq ΞΈ @[simp] theorem tan_toReal (ΞΈ : Angle) : Real.tan ΞΈ.toReal = tan ΞΈ := by conv_rhs => rw [← coe_toReal ΞΈ, tan_coe] theorem tan_eq_of_two_nsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ = (2 : β„•) β€’ ψ) : tan ΞΈ = tan ψ := by rw [two_nsmul_eq_iff] at h rcases h with (rfl | rfl) Β· rfl Β· exact tan_add_pi _ theorem tan_eq_of_two_zsmul_eq {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ = (2 : β„€) β€’ ψ) : tan ΞΈ = tan ψ := by simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_of_two_nsmul_eq h theorem tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„•) β€’ ΞΈ + (2 : β„•) β€’ ψ = Ο€) : tan ψ = (tan ΞΈ)⁻¹ := by induction ΞΈ using Real.Angle.induction_on induction ψ using Real.Angle.induction_on rw [← smul_add, ← coe_add, ← coe_nsmul, two_nsmul, ← two_mul, angle_eq_iff_two_pi_dvd_sub] at h rcases h with ⟨k, h⟩ rw [sub_eq_iff_eq_add, ← mul_inv_cancel_leftβ‚€ two_ne_zero Ο€, mul_assoc, ← mul_add, mul_right_inj' (two_ne_zero' ℝ), ← eq_sub_iff_add_eq', mul_inv_cancel_leftβ‚€ two_ne_zero Ο€, inv_mul_eq_div, mul_comm] at h rw [tan_coe, tan_coe, ← tan_pi_div_two_sub, h, add_sub_assoc, add_comm] exact Real.tan_periodic.int_mul _ _ theorem tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi {ΞΈ ψ : Angle} (h : (2 : β„€) β€’ ΞΈ + (2 : β„€) β€’ ψ = Ο€) : tan ψ = (tan ΞΈ)⁻¹ := by simp_rw [two_zsmul, ← two_nsmul] at h exact tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi h /-- The sign of a `Real.Angle` is `0` if the angle is `0` or `Ο€`, `1` if the angle is strictly between `0` and `Ο€` and `-1` is the angle is strictly between `-Ο€` and `0`. It is defined as the sign of the sine of the angle. -/ def sign (ΞΈ : Angle) : SignType := SignType.sign (sin ΞΈ) @[simp] theorem sign_zero : (0 : Angle).sign = 0 := by rw [sign, sin_zero, _root_.sign_zero] @[simp] theorem sign_coe_pi : (Ο€ : Angle).sign = 0 := by rw [sign, sin_coe_pi, _root_.sign_zero] @[simp] theorem sign_neg (ΞΈ : Angle) : (-ΞΈ).sign = -ΞΈ.sign := by simp_rw [sign, sin_neg, Left.sign_neg] theorem sign_antiperiodic : Function.Antiperiodic sign (Ο€ : Angle) := fun ΞΈ => by rw [sign, sign, sin_add_pi, Left.sign_neg] @[simp] theorem sign_add_pi (ΞΈ : Angle) : (ΞΈ + Ο€).sign = -ΞΈ.sign := sign_antiperiodic ΞΈ @[simp] theorem sign_pi_add (ΞΈ : Angle) : ((Ο€ : Angle) + ΞΈ).sign = -ΞΈ.sign := by rw [add_comm, sign_add_pi] @[simp] theorem sign_sub_pi (ΞΈ : Angle) : (ΞΈ - Ο€).sign = -ΞΈ.sign := sign_antiperiodic.sub_eq ΞΈ @[simp] theorem sign_pi_sub (ΞΈ : Angle) : ((Ο€ : Angle) - ΞΈ).sign = ΞΈ.sign := by simp [sign_antiperiodic.sub_eq'] theorem sign_eq_zero_iff {ΞΈ : Angle} : ΞΈ.sign = 0 ↔ ΞΈ = 0 ∨ ΞΈ = Ο€ := by rw [sign, _root_.sign_eq_zero_iff, sin_eq_zero_iff] theorem sign_ne_zero_iff {ΞΈ : Angle} : ΞΈ.sign β‰  0 ↔ ΞΈ β‰  0 ∧ ΞΈ β‰  Ο€ := by rw [← not_or, ← sign_eq_zero_iff] theorem toReal_neg_iff_sign_neg {ΞΈ : Angle} : ΞΈ.toReal < 0 ↔ ΞΈ.sign = -1 := by rw [sign, ← sin_toReal, sign_eq_neg_one_iff] rcases lt_trichotomy ΞΈ.toReal 0 with (h | h | h) Β· exact ⟨fun _ => Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_toReal ΞΈ), fun _ => h⟩ Β· simp [h] Β· exact ⟨fun hn => False.elim (h.asymm hn), fun hn => False.elim (hn.not_le (sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi ΞΈ)))⟩ theorem toReal_nonneg_iff_sign_nonneg {ΞΈ : Angle} : 0 ≀ ΞΈ.toReal ↔ 0 ≀ ΞΈ.sign := by rcases lt_trichotomy ΞΈ.toReal 0 with (h | h | h) Β· refine ⟨fun hn => False.elim (h.not_le hn), fun hn => ?_⟩ rw [toReal_neg_iff_sign_neg.1 h] at hn exact False.elim (hn.not_lt (by decide)) Β· simp [h, sign, ← sin_toReal] Β· refine ⟨fun _ => ?_, fun _ => h.le⟩ rw [sign, ← sin_toReal, sign_nonneg_iff] exact sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi ΞΈ) @[simp] theorem sign_toReal {ΞΈ : Angle} (h : ΞΈ β‰  Ο€) : SignType.sign ΞΈ.toReal = ΞΈ.sign := by rcases lt_trichotomy ΞΈ.toReal 0 with (ht | ht | ht) Β· simp [ht, toReal_neg_iff_sign_neg.1 ht] Β· simp [sign, ht, ← sin_toReal] Β· rw [sign, ← sin_toReal, sign_pos ht, sign_pos (sin_pos_of_pos_of_lt_pi ht ((toReal_le_pi ΞΈ).lt_of_ne (toReal_eq_pi_iff.not.2 h)))]
Mathlib/Analysis/SpecialFunctions/Trigonometric/Angle.lean
768
771
theorem coe_abs_toReal_of_sign_nonneg {ΞΈ : Angle} (h : 0 ≀ ΞΈ.sign) : ↑|ΞΈ.toReal| = ΞΈ := by
rw [abs_eq_self.2 (toReal_nonneg_iff_sign_nonneg.2 h), coe_toReal] theorem neg_coe_abs_toReal_of_sign_nonpos {ΞΈ : Angle} (h : ΞΈ.sign ≀ 0) : -↑|ΞΈ.toReal| = ΞΈ := by
/- Copyright (c) 2023 Jon Eugster. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Dagur Asgeirsson, Boris Bolvig KjΓ¦r, Jon Eugster, Sina Hazratpour -/ import Mathlib.CategoryTheory.Sites.Coherent.ReflectsPreregular import Mathlib.Topology.Category.CompHaus.EffectiveEpi import Mathlib.Topology.Category.Profinite.Limits import Mathlib.Topology.Category.Stonean.Basic /-! # Effective epimorphisms in `Profinite` This file proves that `EffectiveEpi`, `Epi` and `Surjective` are all equivalent in `Profinite`. As a consequence we deduce from the material in `Mathlib.Topology.Category.CompHausLike.EffectiveEpi` that `Profinite` is `Preregular` and `Precoherent`. We also prove that for a finite family of morphisms in `Profinite` with fixed target, the conditions jointly surjective, jointly epimorphic and effective epimorphic are all equivalent. -/ universe u open CategoryTheory Limits namespace Profinite open List in theorem effectiveEpi_tfae {B X : Profinite.{u}} (Ο€ : X ⟢ B) : TFAE [ EffectiveEpi Ο€ , Epi Ο€ , Function.Surjective Ο€ ] := by tfae_have 1 β†’ 2 := fun _ ↦ inferInstance tfae_have 2 ↔ 3 := epi_iff_surjective Ο€ tfae_have 3 β†’ 1 := fun hΟ€ ↦ ⟨⟨CompHausLike.effectiveEpiStruct Ο€ hΟ€βŸ©βŸ© tfae_finish instance : profiniteToCompHaus.PreservesEffectiveEpis where preserves f h := ((CompHaus.effectiveEpi_tfae _).out 0 2).mpr (((Profinite.effectiveEpi_tfae _).out 0 2).mp h) instance : profiniteToCompHaus.ReflectsEffectiveEpis where reflects f h := ((Profinite.effectiveEpi_tfae f).out 0 2).mpr (((CompHaus.effectiveEpi_tfae _).out 0 2).mp h) /-- An effective presentation of an `X : Profinite` with respect to the inclusion functor from `Stonean` -/ noncomputable def profiniteToCompHausEffectivePresentation (X : CompHaus) : profiniteToCompHaus.EffectivePresentation X where p := Stonean.toProfinite.obj X.presentation f := CompHaus.presentation.Ο€ X effectiveEpi := ((CompHaus.effectiveEpi_tfae _).out 0 1).mpr (inferInstance : Epi _) instance : profiniteToCompHaus.EffectivelyEnough where presentation X := ⟨profiniteToCompHausEffectivePresentation X⟩ instance : Preregular Profinite.{u} := profiniteToCompHaus.reflects_preregular example : Precoherent Profinite.{u} := inferInstance -- TODO: prove this for `Type*` open List in
Mathlib/Topology/Category/Profinite/EffectiveEpi.lean
69
82
theorem effectiveEpiFamily_tfae {Ξ± : Type} [Finite Ξ±] {B : Profinite.{u}} (X : Ξ± β†’ Profinite.{u}) (Ο€ : (a : Ξ±) β†’ (X a ⟢ B)) : TFAE [ EffectiveEpiFamily X Ο€ , Epi (Sigma.desc Ο€) , βˆ€ b : B, βˆƒ (a : Ξ±) (x : X a), Ο€ a x = b ] := by
tfae_have 2 β†’ 1 | _ => by simpa [← effectiveEpi_desc_iff_effectiveEpiFamily, (effectiveEpi_tfae (Sigma.desc Ο€)).out 0 1] tfae_have 1 β†’ 2 := fun _ ↦ inferInstance tfae_have 3 ↔ 1 := by erw [((CompHaus.effectiveEpiFamily_tfae
/- Copyright (c) 2022 Violeta HernΓ‘ndez Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta HernΓ‘ndez Palacios -/ import Mathlib.SetTheory.Ordinal.Family import Mathlib.Tactic.Abel /-! # Natural operations on ordinals The goal of this file is to define natural addition and multiplication on ordinals, also known as the Hessenberg sum and product, and provide a basic API. The natural addition of two ordinals `a β™― b` is recursively defined as the least ordinal greater than `a' β™― b` and `a β™― b'` for `a' < a` and `b' < b`. The natural multiplication `a ⨳ b` is likewise recursively defined as the least ordinal such that `a ⨳ b β™― a' ⨳ b'` is greater than `a' ⨳ b β™― a ⨳ b'` for any `a' < a` and `b' < b`. These operations form a rich algebraic structure: they're commutative, associative, preserve order, have the usual `0` and `1` from ordinals, and distribute over one another. Moreover, these operations are the addition and multiplication of ordinals when viewed as combinatorial `Game`s. This makes them particularly useful for game theory. Finally, both operations admit simple, intuitive descriptions in terms of the Cantor normal form. The natural addition of two ordinals corresponds to adding their Cantor normal forms as if they were polynomials in `Ο‰`. Likewise, their natural multiplication corresponds to multiplying the Cantor normal forms as polynomials. ## Implementation notes Given the rich algebraic structure of these two operations, we choose to create a type synonym `NatOrdinal`, where we provide the appropriate instances. However, to avoid casting back and forth between both types, we attempt to prove and state most results on `Ordinal`. ## Todo - Prove the characterizations of natural addition and multiplication in terms of the Cantor normal form. -/ universe u v open Function Order Set noncomputable section /-! ### Basic casts between `Ordinal` and `NatOrdinal` -/ /-- A type synonym for ordinals with natural addition and multiplication. -/ def NatOrdinal : Type _ := Ordinal deriving Zero, Inhabited, One, WellFoundedRelation -- The `LinearOrder, `SuccOrder` instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance NatOrdinal.instLinearOrder : LinearOrder NatOrdinal := Ordinal.instLinearOrder instance NatOrdinal.instSuccOrder : SuccOrder NatOrdinal := Ordinal.instSuccOrder instance NatOrdinal.instOrderBot : OrderBot NatOrdinal := Ordinal.instOrderBot instance NatOrdinal.instNoMaxOrder : NoMaxOrder NatOrdinal := Ordinal.instNoMaxOrder instance NatOrdinal.instZeroLEOneClass : ZeroLEOneClass NatOrdinal := Ordinal.instZeroLEOneClass instance NatOrdinal.instNeZeroOne : NeZero (1 : NatOrdinal) := Ordinal.instNeZeroOne instance NatOrdinal.uncountable : Uncountable NatOrdinal := Ordinal.uncountable /-- The identity function between `Ordinal` and `NatOrdinal`. -/ @[match_pattern] def Ordinal.toNatOrdinal : Ordinal ≃o NatOrdinal := OrderIso.refl _ /-- The identity function between `NatOrdinal` and `Ordinal`. -/ @[match_pattern] def NatOrdinal.toOrdinal : NatOrdinal ≃o Ordinal := OrderIso.refl _ namespace NatOrdinal open Ordinal @[simp] theorem toOrdinal_symm_eq : NatOrdinal.toOrdinal.symm = Ordinal.toNatOrdinal := rfl @[simp] theorem toOrdinal_toNatOrdinal (a : NatOrdinal) : a.toOrdinal.toNatOrdinal = a := rfl theorem lt_wf : @WellFounded NatOrdinal (Β· < Β·) := Ordinal.lt_wf instance : WellFoundedLT NatOrdinal := Ordinal.wellFoundedLT instance : ConditionallyCompleteLinearOrderBot NatOrdinal := WellFoundedLT.conditionallyCompleteLinearOrderBot _ @[simp] theorem bot_eq_zero : (βŠ₯ : NatOrdinal) = 0 := rfl @[simp] theorem toOrdinal_zero : toOrdinal 0 = 0 := rfl @[simp] theorem toOrdinal_one : toOrdinal 1 = 1 := rfl @[simp] theorem toOrdinal_eq_zero {a} : toOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toOrdinal_eq_one {a} : toOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toOrdinal_max (a b : NatOrdinal) : toOrdinal (max a b) = max (toOrdinal a) (toOrdinal b) := rfl @[simp] theorem toOrdinal_min (a b : NatOrdinal) : toOrdinal (min a b) = min (toOrdinal a) (toOrdinal b) := rfl theorem succ_def (a : NatOrdinal) : succ a = toNatOrdinal (toOrdinal a + 1) := rfl @[simp] theorem zero_le (o : NatOrdinal) : 0 ≀ o := Ordinal.zero_le o theorem not_lt_zero (o : NatOrdinal) : Β¬ o < 0 := Ordinal.not_lt_zero o @[simp] theorem lt_one_iff_zero {o : NatOrdinal} : o < 1 ↔ o = 0 := Ordinal.lt_one_iff_zero /-- A recursor for `NatOrdinal`. Use as `induction x`. -/ @[elab_as_elim, cases_eliminator, induction_eliminator] protected def rec {Ξ² : NatOrdinal β†’ Sort*} (h : βˆ€ a, Ξ² (toNatOrdinal a)) : βˆ€ a, Ξ² a := fun a => h (toOrdinal a) /-- `Ordinal.induction` but for `NatOrdinal`. -/ theorem induction {p : NatOrdinal β†’ Prop} : βˆ€ (i) (_ : βˆ€ j, (βˆ€ k, k < j β†’ p k) β†’ p j), p i := Ordinal.induction instance small_Iio (a : NatOrdinal.{u}) : Small.{u} (Set.Iio a) := Ordinal.small_Iio a instance small_Iic (a : NatOrdinal.{u}) : Small.{u} (Set.Iic a) := Ordinal.small_Iic a instance small_Ico (a b : NatOrdinal.{u}) : Small.{u} (Set.Ico a b) := Ordinal.small_Ico a b instance small_Icc (a b : NatOrdinal.{u}) : Small.{u} (Set.Icc a b) := Ordinal.small_Icc a b instance small_Ioo (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioo a b) := Ordinal.small_Ioo a b instance small_Ioc (a b : NatOrdinal.{u}) : Small.{u} (Set.Ioc a b) := Ordinal.small_Ioc a b end NatOrdinal namespace Ordinal variable {a b c : Ordinal.{u}} @[simp] theorem toNatOrdinal_symm_eq : toNatOrdinal.symm = NatOrdinal.toOrdinal := rfl @[simp] theorem toNatOrdinal_toOrdinal (a : Ordinal) : a.toNatOrdinal.toOrdinal = a := rfl @[simp] theorem toNatOrdinal_zero : toNatOrdinal 0 = 0 := rfl @[simp] theorem toNatOrdinal_one : toNatOrdinal 1 = 1 := rfl @[simp] theorem toNatOrdinal_eq_zero (a) : toNatOrdinal a = 0 ↔ a = 0 := Iff.rfl @[simp] theorem toNatOrdinal_eq_one (a) : toNatOrdinal a = 1 ↔ a = 1 := Iff.rfl @[simp] theorem toNatOrdinal_max (a b : Ordinal) : toNatOrdinal (max a b) = max (toNatOrdinal a) (toNatOrdinal b) := rfl @[simp] theorem toNatOrdinal_min (a b : Ordinal) : toNatOrdinal (min a b) = min (toNatOrdinal a) (toNatOrdinal b) := rfl /-! We place the definitions of `nadd` and `nmul` before actually developing their API, as this guarantees we only need to open the `NaturalOps` locale once. -/ /-- Natural addition on ordinals `a β™― b`, also known as the Hessenberg sum, is recursively defined as the least ordinal greater than `a' β™― b` and `a β™― b'` for all `a' < a` and `b' < b`. In contrast to normal ordinal addition, it is commutative. Natural addition can equivalently be characterized as the ordinal resulting from adding up corresponding coefficients in the Cantor normal forms of `a` and `b`. -/ noncomputable def nadd (a b : Ordinal.{u}) : Ordinal.{u} := max (⨆ x : Iio a, succ (nadd x.1 b)) (⨆ x : Iio b, succ (nadd a x.1)) termination_by (a, b) decreasing_by all_goals cases x; decreasing_tactic @[inherit_doc] scoped[NaturalOps] infixl:65 " β™― " => Ordinal.nadd open NaturalOps /-- Natural multiplication on ordinals `a ⨳ b`, also known as the Hessenberg product, is recursively defined as the least ordinal such that `a ⨳ b β™― a' ⨳ b'` is greater than `a' ⨳ b β™― a ⨳ b'` for all `a' < a` and `b < b'`. In contrast to normal ordinal multiplication, it is commutative and distributive (over natural addition). Natural multiplication can equivalently be characterized as the ordinal resulting from multiplying the Cantor normal forms of `a` and `b` as if they were polynomials in `Ο‰`. Addition of exponents is done via natural addition. -/ noncomputable def nmul (a b : Ordinal.{u}) : Ordinal.{u} := sInf {c | βˆ€ a' < a, βˆ€ b' < b, nmul a' b β™― nmul a b' < c β™― nmul a' b'} termination_by (a, b) @[inherit_doc] scoped[NaturalOps] infixl:70 " ⨳ " => Ordinal.nmul /-! ### Natural addition -/ theorem lt_nadd_iff : a < b β™― c ↔ (βˆƒ b' < b, a ≀ b' β™― c) ∨ βˆƒ c' < c, a ≀ b β™― c' := by rw [nadd] simp [Ordinal.lt_iSup_iff] theorem nadd_le_iff : b β™― c ≀ a ↔ (βˆ€ b' < b, b' β™― c < a) ∧ βˆ€ c' < c, b β™― c' < a := by rw [← not_lt, lt_nadd_iff] simp theorem nadd_lt_nadd_left (h : b < c) (a) : a β™― b < a β™― c := lt_nadd_iff.2 (Or.inr ⟨b, h, le_rfl⟩) theorem nadd_lt_nadd_right (h : b < c) (a) : b β™― a < c β™― a := lt_nadd_iff.2 (Or.inl ⟨b, h, le_rfl⟩) theorem nadd_le_nadd_left (h : b ≀ c) (a) : a β™― b ≀ a β™― c := by rcases lt_or_eq_of_le h with (h | rfl) Β· exact (nadd_lt_nadd_left h a).le Β· exact le_rfl theorem nadd_le_nadd_right (h : b ≀ c) (a) : b β™― a ≀ c β™― a := by rcases lt_or_eq_of_le h with (h | rfl) Β· exact (nadd_lt_nadd_right h a).le Β· exact le_rfl variable (a b) theorem nadd_comm (a b) : a β™― b = b β™― a := by rw [nadd, nadd, max_comm] congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_comm _ _) termination_by (a, b) @[deprecated "blsub will soon be deprecated" (since := "2024-11-18")] theorem blsub_nadd_of_mono {f : βˆ€ c < a β™― b, Ordinal.{max u v}} (hf : βˆ€ {i j} (hi hj), i ≀ j β†’ f i hi ≀ f j hj) : blsub.{u,v} _ f = max (blsub.{u, v} a fun a' ha' => f (a' β™― b) <| nadd_lt_nadd_right ha' b) (blsub.{u, v} b fun b' hb' => f (a β™― b') <| nadd_lt_nadd_left hb' a) := by apply (blsub_le_iff.2 fun i h => _).antisymm (max_le _ _) Β· intro i h rcases lt_nadd_iff.1 h with (⟨a', ha', hi⟩ | ⟨b', hb', hi⟩) Β· exact lt_max_of_lt_left ((hf h (nadd_lt_nadd_right ha' b) hi).trans_lt (lt_blsub _ _ ha')) Β· exact lt_max_of_lt_right ((hf h (nadd_lt_nadd_left hb' a) hi).trans_lt (lt_blsub _ _ hb')) all_goals apply blsub_le_of_brange_subset.{u, u, v} rintro c ⟨d, hd, rfl⟩ apply mem_brange_self private theorem iSup_nadd_of_monotone {a b} (f : Ordinal.{u} β†’ Ordinal.{u}) (h : Monotone f) : ⨆ x : Iio (a β™― b), f x = max (⨆ a' : Iio a, f (a'.1 β™― b)) (⨆ b' : Iio b, f (a β™― b'.1)) := by apply (max_le _ _).antisymm' Β· rw [Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ obtain ⟨x, hx, hi⟩ | ⟨x, hx, hi⟩ := lt_nadd_iff.1 hi Β· exact le_max_of_le_left ((h hi).trans <| Ordinal.le_iSup (fun x : Iio a ↦ _) ⟨x, hx⟩) Β· exact le_max_of_le_right ((h hi).trans <| Ordinal.le_iSup (fun x : Iio b ↦ _) ⟨x, hx⟩) all_goals apply csSup_le_csSup' (bddAbove_of_small _) rintro _ ⟨⟨c, hc⟩, rfl⟩ refine mem_range_self (⟨_, ?_⟩ : Iio _) apply_rules [nadd_lt_nadd_left, nadd_lt_nadd_right] theorem nadd_assoc (a b c) : a β™― b β™― c = a β™― (b β™― c) := by unfold nadd rw [iSup_nadd_of_monotone fun a' ↦ succ (a' β™― c), iSup_nadd_of_monotone fun b' ↦ succ (a β™― b'), max_assoc] Β· congr <;> ext x <;> cases x <;> apply congr_arg _ (nadd_assoc _ _ _) Β· exact succ_mono.comp fun x y h ↦ nadd_le_nadd_left h _ Β· exact succ_mono.comp fun x y h ↦ nadd_le_nadd_right h _ termination_by (a, b, c) @[simp] theorem nadd_zero (a : Ordinal) : a β™― 0 = a := by rw [nadd, ciSup_of_empty fun _ : Iio 0 ↦ _, sup_bot_eq] convert iSup_succ a rename_i x cases x exact nadd_zero _ termination_by a @[simp] theorem zero_nadd : 0 β™― a = a := by rw [nadd_comm, nadd_zero] @[simp] theorem nadd_one (a : Ordinal) : a β™― 1 = succ a := by rw [nadd, ciSup_unique (s := fun _ : Iio 1 ↦ _), Iio_one_default_eq, nadd_zero, max_eq_right_iff, Ordinal.iSup_le_iff] rintro ⟨i, hi⟩ rwa [nadd_one, succ_le_succ_iff, succ_le_iff] termination_by a @[simp] theorem one_nadd : 1 β™― a = succ a := by rw [nadd_comm, nadd_one] theorem nadd_succ : a β™― succ b = succ (a β™― b) := by rw [← nadd_one (a β™― b), nadd_assoc, nadd_one] theorem succ_nadd : succ a β™― b = succ (a β™― b) := by rw [← one_nadd (a β™― b), ← nadd_assoc, one_nadd] @[simp] theorem nadd_nat (n : β„•) : a β™― n = a + n := by induction' n with n hn Β· simp Β· rw [Nat.cast_succ, add_one_eq_succ, nadd_succ, add_succ, hn] @[simp]
Mathlib/SetTheory/Ordinal/NaturalOps.lean
309
309
theorem nat_nadd (n : β„•) : ↑n β™― a = a + n := by
rw [nadd_comm, nadd_nat]
/- Copyright (c) 2019 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen, Lu-Ming Zhang -/ import Mathlib.Data.Matrix.Invertible import Mathlib.Data.Matrix.Kronecker import Mathlib.LinearAlgebra.FiniteDimensional.Basic import Mathlib.LinearAlgebra.Matrix.Adjugate import Mathlib.LinearAlgebra.Matrix.SemiringInverse import Mathlib.LinearAlgebra.Matrix.ToLin import Mathlib.LinearAlgebra.Matrix.Trace /-! # Nonsingular inverses In this file, we define an inverse for square matrices of invertible determinant. For matrices that are not square or not of full rank, there is a more general notion of pseudoinverses which we do not consider here. The definition of inverse used in this file is the adjugate divided by the determinant. We show that dividing the adjugate by `det A` (if possible), giving a matrix `A⁻¹` (`nonsing_inv`), will result in a multiplicative inverse to `A`. Note that there are at least three different inverses in mathlib: * `A⁻¹` (`Inv.inv`): alone, this satisfies no properties, although it is usually used in conjunction with `Group` or `GroupWithZero`. On matrices, this is defined to be zero when no inverse exists. * `β…ŸA` (`invOf`): this is only available in the presence of `[Invertible A]`, which guarantees an inverse exists. * `Ring.inverse A`: this is defined on any `MonoidWithZero`, and just like `⁻¹` on matrices, is defined to be zero when no inverse exists. We start by working with `Invertible`, and show the main results: * `Matrix.invertibleOfDetInvertible` * `Matrix.detInvertibleOfInvertible` * `Matrix.isUnit_iff_isUnit_det` * `Matrix.mul_eq_one_comm` After this we define `Matrix.inv` and show it matches `β…ŸA` and `Ring.inverse A`. The rest of the results in the file are then about `A⁻¹` ## References * https://en.wikipedia.org/wiki/Cramer's_rule#Finding_inverse_matrix ## Tags matrix inverse, cramer, cramer's rule, adjugate -/ namespace Matrix universe u u' v variable {l : Type*} {m : Type u} {n : Type u'} {Ξ± : Type v} open Matrix Equiv Equiv.Perm Finset /-! ### Matrices are `Invertible` iff their determinants are -/ section Invertible variable [Fintype n] [DecidableEq n] [CommRing Ξ±] variable (A : Matrix n n Ξ±) (B : Matrix n n Ξ±) /-- If `A.det` has a constructive inverse, produce one for `A`. -/ def invertibleOfDetInvertible [Invertible A.det] : Invertible A where invOf := β…Ÿ A.det β€’ A.adjugate mul_invOf_self := by rw [mul_smul_comm, mul_adjugate, smul_smul, invOf_mul_self, one_smul] invOf_mul_self := by rw [smul_mul_assoc, adjugate_mul, smul_smul, invOf_mul_self, one_smul] theorem invOf_eq [Invertible A.det] [Invertible A] : β…Ÿ A = β…Ÿ A.det β€’ A.adjugate := by letI := invertibleOfDetInvertible A convert (rfl : β…Ÿ A = _) /-- `A.det` is invertible if `A` has a left inverse. -/ def detInvertibleOfLeftInverse (h : B * A = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [mul_comm, ← det_mul, h, det_one] invOf_mul_self := by rw [← det_mul, h, det_one] /-- `A.det` is invertible if `A` has a right inverse. -/ def detInvertibleOfRightInverse (h : A * B = 1) : Invertible A.det where invOf := B.det mul_invOf_self := by rw [← det_mul, h, det_one] invOf_mul_self := by rw [mul_comm, ← det_mul, h, det_one] /-- If `A` has a constructive inverse, produce one for `A.det`. -/ def detInvertibleOfInvertible [Invertible A] : Invertible A.det := detInvertibleOfLeftInverse A (β…Ÿ A) (invOf_mul_self _) theorem det_invOf [Invertible A] [Invertible A.det] : (β…Ÿ A).det = β…Ÿ A.det := by letI := detInvertibleOfInvertible A convert (rfl : _ = β…Ÿ A.det) /-- Together `Matrix.detInvertibleOfInvertible` and `Matrix.invertibleOfDetInvertible` form an equivalence, although both sides of the equiv are subsingleton anyway. -/ @[simps] def invertibleEquivDetInvertible : Invertible A ≃ Invertible A.det where toFun := @detInvertibleOfInvertible _ _ _ _ _ A invFun := @invertibleOfDetInvertible _ _ _ _ _ A left_inv _ := Subsingleton.elim _ _ right_inv _ := Subsingleton.elim _ _ /-- Given a proof that `A.det` has a constructive inverse, lift `A` to `(Matrix n n Ξ±)Λ£` -/ def unitOfDetInvertible [Invertible A.det] : (Matrix n n Ξ±)Λ£ := @unitOfInvertible _ _ A (invertibleOfDetInvertible A) /-- When lowered to a prop, `Matrix.invertibleEquivDetInvertible` forms an `iff`. -/ theorem isUnit_iff_isUnit_det : IsUnit A ↔ IsUnit A.det := by simp only [← nonempty_invertible_iff_isUnit, (invertibleEquivDetInvertible A).nonempty_congr] @[simp] theorem isUnits_det_units (A : (Matrix n n Ξ±)Λ£) : IsUnit (A : Matrix n n Ξ±).det := isUnit_iff_isUnit_det _ |>.mp A.isUnit /-! #### Variants of the statements above with `IsUnit` -/ theorem isUnit_det_of_invertible [Invertible A] : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfInvertible A) variable {A B} theorem isUnit_det_of_left_inverse (h : B * A = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfLeftInverse _ _ h) theorem isUnit_det_of_right_inverse (h : A * B = 1) : IsUnit A.det := @isUnit_of_invertible _ _ _ (detInvertibleOfRightInverse _ _ h) theorem det_ne_zero_of_left_inverse [Nontrivial Ξ±] (h : B * A = 1) : A.det β‰  0 := (isUnit_det_of_left_inverse h).ne_zero theorem det_ne_zero_of_right_inverse [Nontrivial Ξ±] (h : A * B = 1) : A.det β‰  0 := (isUnit_det_of_right_inverse h).ne_zero end Invertible section Inv variable [Fintype n] [DecidableEq n] [CommRing Ξ±] variable (A : Matrix n n Ξ±) (B : Matrix n n Ξ±) theorem isUnit_det_transpose (h : IsUnit A.det) : IsUnit Aα΅€.det := by rw [det_transpose] exact h /-! ### A noncomputable `Inv` instance -/ /-- The inverse of a square matrix, when it is invertible (and zero otherwise). -/ noncomputable instance inv : Inv (Matrix n n Ξ±) := ⟨fun A => Ring.inverse A.det β€’ A.adjugate⟩ theorem inv_def (A : Matrix n n Ξ±) : A⁻¹ = Ring.inverse A.det β€’ A.adjugate := rfl theorem nonsing_inv_apply_not_isUnit (h : Β¬IsUnit A.det) : A⁻¹ = 0 := by rw [inv_def, Ring.inverse_non_unit _ h, zero_smul] theorem nonsing_inv_apply (h : IsUnit A.det) : A⁻¹ = (↑h.unit⁻¹ : Ξ±) β€’ A.adjugate := by rw [inv_def, ← Ring.inverse_unit h.unit, IsUnit.unit_spec] /-- The nonsingular inverse is the same as `invOf` when `A` is invertible. -/ @[simp] theorem invOf_eq_nonsing_inv [Invertible A] : β…Ÿ A = A⁻¹ := by letI := detInvertibleOfInvertible A rw [inv_def, Ring.inverse_invertible, invOf_eq] /-- Coercing the result of `Units.instInv` is the same as coercing first and applying the nonsingular inverse. -/ @[simp, norm_cast] theorem coe_units_inv (A : (Matrix n n Ξ±)Λ£) : ↑A⁻¹ = (A⁻¹ : Matrix n n Ξ±) := by letI := A.invertible rw [← invOf_eq_nonsing_inv, invOf_units] /-- The nonsingular inverse is the same as the general `Ring.inverse`. -/ theorem nonsing_inv_eq_ringInverse : A⁻¹ = Ring.inverse A := by by_cases h_det : IsUnit A.det Β· cases (A.isUnit_iff_isUnit_det.mpr h_det).nonempty_invertible rw [← invOf_eq_nonsing_inv, Ring.inverse_invertible] Β· have h := mt A.isUnit_iff_isUnit_det.mp h_det rw [Ring.inverse_non_unit _ h, nonsing_inv_apply_not_isUnit A h_det] @[deprecated (since := "2025-04-22")] alias nonsing_inv_eq_ring_inverse := nonsing_inv_eq_ringInverse theorem transpose_nonsing_inv : A⁻¹ᡀ = Aᡀ⁻¹ := by rw [inv_def, inv_def, transpose_smul, det_transpose, adjugate_transpose] theorem conjTranspose_nonsing_inv [StarRing Ξ±] : A⁻¹ᴴ = Aᴴ⁻¹ := by rw [inv_def, inv_def, conjTranspose_smul, det_conjTranspose, adjugate_conjTranspose, Ring.inverse_star] /-- The `nonsing_inv` of `A` is a right inverse. -/ @[simp] theorem mul_nonsing_inv (h : IsUnit A.det) : A * A⁻¹ = 1 := by cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible rw [← invOf_eq_nonsing_inv, mul_invOf_self] /-- The `nonsing_inv` of `A` is a left inverse. -/ @[simp] theorem nonsing_inv_mul (h : IsUnit A.det) : A⁻¹ * A = 1 := by cases (A.isUnit_iff_isUnit_det.mpr h).nonempty_invertible rw [← invOf_eq_nonsing_inv, invOf_mul_self] instance [Invertible A] : Invertible A⁻¹ := by rw [← invOf_eq_nonsing_inv] infer_instance @[simp] theorem inv_inv_of_invertible [Invertible A] : A⁻¹⁻¹ = A := by simp only [← invOf_eq_nonsing_inv, invOf_invOf] @[simp] theorem mul_nonsing_inv_cancel_right (B : Matrix m n Ξ±) (h : IsUnit A.det) : B * A * A⁻¹ = B := by simp [Matrix.mul_assoc, mul_nonsing_inv A h] @[simp] theorem mul_nonsing_inv_cancel_left (B : Matrix n m Ξ±) (h : IsUnit A.det) : A * (A⁻¹ * B) = B := by simp [← Matrix.mul_assoc, mul_nonsing_inv A h] @[simp] theorem nonsing_inv_mul_cancel_right (B : Matrix m n Ξ±) (h : IsUnit A.det) : B * A⁻¹ * A = B := by simp [Matrix.mul_assoc, nonsing_inv_mul A h] @[simp] theorem nonsing_inv_mul_cancel_left (B : Matrix n m Ξ±) (h : IsUnit A.det) : A⁻¹ * (A * B) = B := by simp [← Matrix.mul_assoc, nonsing_inv_mul A h] @[simp] theorem mul_inv_of_invertible [Invertible A] : A * A⁻¹ = 1 := mul_nonsing_inv A (isUnit_det_of_invertible A) @[simp] theorem inv_mul_of_invertible [Invertible A] : A⁻¹ * A = 1 := nonsing_inv_mul A (isUnit_det_of_invertible A) @[simp] theorem mul_inv_cancel_right_of_invertible (B : Matrix m n Ξ±) [Invertible A] : B * A * A⁻¹ = B := mul_nonsing_inv_cancel_right A B (isUnit_det_of_invertible A) @[simp] theorem mul_inv_cancel_left_of_invertible (B : Matrix n m Ξ±) [Invertible A] : A * (A⁻¹ * B) = B := mul_nonsing_inv_cancel_left A B (isUnit_det_of_invertible A) @[simp] theorem inv_mul_cancel_right_of_invertible (B : Matrix m n Ξ±) [Invertible A] : B * A⁻¹ * A = B := nonsing_inv_mul_cancel_right A B (isUnit_det_of_invertible A) @[simp] theorem inv_mul_cancel_left_of_invertible (B : Matrix n m Ξ±) [Invertible A] : A⁻¹ * (A * B) = B := nonsing_inv_mul_cancel_left A B (isUnit_det_of_invertible A) theorem inv_mul_eq_iff_eq_mul_of_invertible (A B C : Matrix n n Ξ±) [Invertible A] : A⁻¹ * B = C ↔ B = A * C := ⟨fun h => by rw [← h, mul_inv_cancel_left_of_invertible], fun h => by rw [h, inv_mul_cancel_left_of_invertible]⟩ theorem mul_inv_eq_iff_eq_mul_of_invertible (A B C : Matrix n n Ξ±) [Invertible A] : B * A⁻¹ = C ↔ B = C * A := ⟨fun h => by rw [← h, inv_mul_cancel_right_of_invertible], fun h => by rw [h, mul_inv_cancel_right_of_invertible]⟩ lemma inv_mulVec_eq_vec {A : Matrix n n Ξ±} [Invertible A] {u v : n β†’ Ξ±} (hM : u = A.mulVec v) : A⁻¹.mulVec u = v := by rw [hM, Matrix.mulVec_mulVec, Matrix.inv_mul_of_invertible, Matrix.one_mulVec] lemma mul_right_injective_of_invertible [Invertible A] : Function.Injective (fun (x : Matrix n m Ξ±) => A * x) := fun _ _ h => by simpa only [inv_mul_cancel_left_of_invertible] using congr_arg (A⁻¹ * Β·) h lemma mul_left_injective_of_invertible [Invertible A] : Function.Injective (fun (x : Matrix m n Ξ±) => x * A) := fun a x hax => by simpa only [mul_inv_cancel_right_of_invertible] using congr_arg (Β· * A⁻¹) hax lemma mul_right_inj_of_invertible [Invertible A] {x y : Matrix n m Ξ±} : A * x = A * y ↔ x = y := (mul_right_injective_of_invertible A).eq_iff lemma mul_left_inj_of_invertible [Invertible A] {x y : Matrix m n Ξ±} : x * A = y * A ↔ x = y := (mul_left_injective_of_invertible A).eq_iff end Inv section InjectiveMul variable [Fintype n] [Fintype m] [DecidableEq m] [CommRing Ξ±] lemma mul_left_injective_of_inv (A : Matrix m n Ξ±) (B : Matrix n m Ξ±) (h : A * B = 1) : Function.Injective (fun x : Matrix l m Ξ± => x * A) := fun _ _ g => by simpa only [Matrix.mul_assoc, Matrix.mul_one, h] using congr_arg (Β· * B) g lemma mul_right_injective_of_inv (A : Matrix m n Ξ±) (B : Matrix n m Ξ±) (h : A * B = 1) : Function.Injective (fun x : Matrix m l Ξ± => B * x) := fun _ _ g => by simpa only [← Matrix.mul_assoc, Matrix.one_mul, h] using congr_arg (A * Β·) g end InjectiveMul section vecMul section Semiring variable {R : Type*} [Semiring R] theorem vecMul_surjective_iff_exists_left_inverse [DecidableEq n] [Fintype m] [Finite n] {A : Matrix m n R} : Function.Surjective A.vecMul ↔ βˆƒ B : Matrix n m R, B * A = 1 := by cases nonempty_fintype n refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨y α΅₯* B, by simp [hBA]⟩⟩ choose rows hrows using (h <| Pi.single Β· 1) refine ⟨Matrix.of rows, Matrix.ext fun i j => ?_⟩ rw [mul_apply_eq_vecMul, one_eq_pi_single, ← hrows] rfl theorem mulVec_surjective_iff_exists_right_inverse [DecidableEq m] [Finite m] [Fintype n] {A : Matrix m n R} : Function.Surjective A.mulVec ↔ βˆƒ B : Matrix n m R, A * B = 1 := by cases nonempty_fintype m refine ⟨fun h ↦ ?_, fun ⟨B, hBA⟩ y ↦ ⟨B *α΅₯ y, by simp [hBA]⟩⟩ choose cols hcols using (h <| Pi.single Β· 1) refine ⟨(Matrix.of cols)α΅€, Matrix.ext fun i j ↦ ?_⟩ rw [one_eq_pi_single, Pi.single_comm, ← hcols j] rfl end Semiring variable [DecidableEq m] {R K : Type*} [CommRing R] [Field K] [Fintype m] theorem vecMul_surjective_iff_isUnit {A : Matrix m m R} : Function.Surjective A.vecMul ↔ IsUnit A := by rw [vecMul_surjective_iff_exists_left_inverse, exists_left_inverse_iff_isUnit] theorem mulVec_surjective_iff_isUnit {A : Matrix m m R} : Function.Surjective A.mulVec ↔ IsUnit A := by rw [mulVec_surjective_iff_exists_right_inverse, exists_right_inverse_iff_isUnit] theorem vecMul_injective_iff_isUnit {A : Matrix m m K} : Function.Injective A.vecMul ↔ IsUnit A := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ Β· rw [← vecMul_surjective_iff_isUnit] exact LinearMap.surjective_of_injective (f := A.vecMulLinear) h change Function.Injective A.vecMulLinear rw [← LinearMap.ker_eq_bot, LinearMap.ker_eq_bot'] intro c hc replace h := h.invertible simpa using congr_arg A⁻¹.vecMulLinear hc theorem mulVec_injective_iff_isUnit {A : Matrix m m K} : Function.Injective A.mulVec ↔ IsUnit A := by rw [← isUnit_transpose, ← vecMul_injective_iff_isUnit] simp_rw [vecMul_transpose] theorem linearIndependent_rows_iff_isUnit {A : Matrix m m K} : LinearIndependent K A.row ↔ IsUnit A := by rw [← col_transpose, ← mulVec_injective_iff, ← coe_mulVecLin, mulVecLin_transpose, ← vecMul_injective_iff_isUnit, coe_vecMulLinear] theorem linearIndependent_cols_iff_isUnit {A : Matrix m m K} : LinearIndependent K A.col ↔ IsUnit A := by rw [← row_transpose, linearIndependent_rows_iff_isUnit, isUnit_transpose] theorem vecMul_surjective_of_invertible (A : Matrix m m R) [Invertible A] : Function.Surjective A.vecMul := vecMul_surjective_iff_isUnit.2 <| isUnit_of_invertible A theorem mulVec_surjective_of_invertible (A : Matrix m m R) [Invertible A] : Function.Surjective A.mulVec := mulVec_surjective_iff_isUnit.2 <| isUnit_of_invertible A theorem vecMul_injective_of_invertible (A : Matrix m m K) [Invertible A] : Function.Injective A.vecMul := vecMul_injective_iff_isUnit.2 <| isUnit_of_invertible A theorem mulVec_injective_of_invertible (A : Matrix m m K) [Invertible A] : Function.Injective A.mulVec := mulVec_injective_iff_isUnit.2 <| isUnit_of_invertible A theorem linearIndependent_rows_of_invertible (A : Matrix m m K) [Invertible A] : LinearIndependent K A.row := linearIndependent_rows_iff_isUnit.2 <| isUnit_of_invertible A theorem linearIndependent_cols_of_invertible (A : Matrix m m K) [Invertible A] : LinearIndependent K A.col := linearIndependent_cols_iff_isUnit.2 <| isUnit_of_invertible A end vecMul variable [Fintype n] [DecidableEq n] [CommRing Ξ±] variable (A : Matrix n n Ξ±) (B : Matrix n n Ξ±) theorem nonsing_inv_cancel_or_zero : A⁻¹ * A = 1 ∧ A * A⁻¹ = 1 ∨ A⁻¹ = 0 := by by_cases h : IsUnit A.det Β· exact Or.inl ⟨nonsing_inv_mul _ h, mul_nonsing_inv _ h⟩ Β· exact Or.inr (nonsing_inv_apply_not_isUnit _ h) theorem det_nonsing_inv_mul_det (h : IsUnit A.det) : A⁻¹.det * A.det = 1 := by rw [← det_mul, A.nonsing_inv_mul h, det_one] @[simp]
Mathlib/LinearAlgebra/Matrix/NonsingularInverse.lean
407
409
theorem det_nonsing_inv : A⁻¹.det = Ring.inverse A.det := by
by_cases h : IsUnit A.det Β· cases h.nonempty_invertible
/- Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.MvPolynomial.Rename import Mathlib.Algebra.MvPolynomial.Variables /-! # Monad operations on `MvPolynomial` This file defines two monadic operations on `MvPolynomial`. Given `p : MvPolynomial Οƒ R`, * `MvPolynomial.bind₁` and `MvPolynomial.join₁` operate on the variable type `Οƒ`. * `MvPolynomial.bindβ‚‚` and `MvPolynomial.joinβ‚‚` operate on the coefficient type `R`. - `MvPolynomial.bind₁ f Ο†` with `f : Οƒ β†’ MvPolynomial Ο„ R` and `Ο† : MvPolynomial Οƒ R`, is the polynomial `Ο†(f 1, ..., f i, ...) : MvPolynomial Ο„ R`. - `MvPolynomial.join₁ Ο†` with `Ο† : MvPolynomial (MvPolynomial Οƒ R) R` collapses `Ο†` to a `MvPolynomial Οƒ R`, by evaluating `Ο†` under the map `X f ↦ f` for `f : MvPolynomial Οƒ R`. In other words, if you have a polynomial `Ο†` in a set of variables indexed by a polynomial ring, you evaluate the polynomial in these indexing polynomials. - `MvPolynomial.bindβ‚‚ f Ο†` with `f : R β†’+* MvPolynomial Οƒ S` and `Ο† : MvPolynomial Οƒ R` is the `MvPolynomial Οƒ S` obtained from `Ο†` by mapping the coefficients of `Ο†` through `f` and considering the resulting polynomial as polynomial expression in `MvPolynomial Οƒ R`. - `MvPolynomial.joinβ‚‚ Ο†` with `Ο† : MvPolynomial Οƒ (MvPolynomial Οƒ R)` collapses `Ο†` to a `MvPolynomial Οƒ R`, by considering `Ο†` as polynomial expression in `MvPolynomial Οƒ R`. These operations themselves have algebraic structure: `MvPolynomial.bind₁` and `MvPolynomial.join₁` are algebra homs and `MvPolynomial.bindβ‚‚` and `MvPolynomial.joinβ‚‚` are ring homs. They interact in convenient ways with `MvPolynomial.rename`, `MvPolynomial.map`, `MvPolynomial.vars`, and other polynomial operations. Indeed, `MvPolynomial.rename` is the "map" operation for the (`bind₁`, `join₁`) pair, whereas `MvPolynomial.map` is the "map" operation for the other pair. ## Implementation notes We add a `LawfulMonad` instance for the (`bind₁`, `join₁`) pair. The second pair cannot be instantiated as a `Monad`, since it is not a monad in `Type` but in `CommRingCat` (or rather `CommSemiRingCat`). -/ noncomputable section namespace MvPolynomial open Finsupp variable {Οƒ : Type*} {Ο„ : Type*} variable {R S T : Type*} [CommSemiring R] [CommSemiring S] [CommSemiring T] /-- `bind₁` is the "left hand side" bind operation on `MvPolynomial`, operating on the variable type. Given a polynomial `p : MvPolynomial Οƒ R` and a map `f : Οƒ β†’ MvPolynomial Ο„ R` taking variables in `p` to polynomials in the variable type `Ο„`, `bind₁ f p` replaces each variable in `p` with its value under `f`, producing a new polynomial in `Ο„`. The coefficient type remains the same. This operation is an algebra hom. -/ def bind₁ (f : Οƒ β†’ MvPolynomial Ο„ R) : MvPolynomial Οƒ R →ₐ[R] MvPolynomial Ο„ R := aeval f /-- `bindβ‚‚` is the "right hand side" bind operation on `MvPolynomial`, operating on the coefficient type. Given a polynomial `p : MvPolynomial Οƒ R` and a map `f : R β†’ MvPolynomial Οƒ S` taking coefficients in `p` to polynomials over a new ring `S`, `bindβ‚‚ f p` replaces each coefficient in `p` with its value under `f`, producing a new polynomial over `S`. The variable type remains the same. This operation is a ring hom. -/ def bindβ‚‚ (f : R β†’+* MvPolynomial Οƒ S) : MvPolynomial Οƒ R β†’+* MvPolynomial Οƒ S := evalβ‚‚Hom f X /-- `join₁` is the monadic join operation corresponding to `MvPolynomial.bind₁`. Given a polynomial `p` with coefficients in `R` whose variables are polynomials in `Οƒ` with coefficients in `R`, `join₁ p` collapses `p` to a polynomial with variables in `Οƒ` and coefficients in `R`. This operation is an algebra hom. -/ def join₁ : MvPolynomial (MvPolynomial Οƒ R) R →ₐ[R] MvPolynomial Οƒ R := aeval id /-- `joinβ‚‚` is the monadic join operation corresponding to `MvPolynomial.bindβ‚‚`. Given a polynomial `p` with variables in `Οƒ` whose coefficients are polynomials in `Οƒ` with coefficients in `R`, `joinβ‚‚ p` collapses `p` to a polynomial with variables in `Οƒ` and coefficients in `R`. This operation is a ring hom. -/ def joinβ‚‚ : MvPolynomial Οƒ (MvPolynomial Οƒ R) β†’+* MvPolynomial Οƒ R := evalβ‚‚Hom (RingHom.id _) X @[simp] theorem aeval_eq_bind₁ (f : Οƒ β†’ MvPolynomial Ο„ R) : aeval f = bind₁ f := rfl @[simp] theorem evalβ‚‚Hom_C_eq_bind₁ (f : Οƒ β†’ MvPolynomial Ο„ R) : evalβ‚‚Hom C f = bind₁ f := rfl @[simp] theorem evalβ‚‚Hom_eq_bindβ‚‚ (f : R β†’+* MvPolynomial Οƒ S) : evalβ‚‚Hom f X = bindβ‚‚ f := rfl section variable (Οƒ R) @[simp] theorem aeval_id_eq_join₁ : aeval id = @join₁ Οƒ R _ := rfl theorem evalβ‚‚Hom_C_id_eq_join₁ (Ο† : MvPolynomial (MvPolynomial Οƒ R) R) : evalβ‚‚Hom C id Ο† = join₁ Ο† := rfl @[simp] theorem evalβ‚‚Hom_id_X_eq_joinβ‚‚ : evalβ‚‚Hom (RingHom.id _) X = @joinβ‚‚ Οƒ R _ := rfl end -- In this file, we don't want to use these simp lemmas, -- because we first need to show how these new definitions interact -- and the proofs fall back on unfolding the definitions and call simp afterwards attribute [-simp] aeval_eq_bind₁ evalβ‚‚Hom_C_eq_bind₁ evalβ‚‚Hom_eq_bindβ‚‚ aeval_id_eq_join₁ evalβ‚‚Hom_id_X_eq_joinβ‚‚ @[simp] theorem bind₁_X_right (f : Οƒ β†’ MvPolynomial Ο„ R) (i : Οƒ) : bind₁ f (X i) = f i := aeval_X f i @[simp] theorem bindβ‚‚_X_right (f : R β†’+* MvPolynomial Οƒ S) (i : Οƒ) : bindβ‚‚ f (X i) = X i := evalβ‚‚Hom_X' f X i @[simp] theorem bind₁_X_left : bind₁ (X : Οƒ β†’ MvPolynomial Οƒ R) = AlgHom.id R _ := by ext1 i simp variable (f : Οƒ β†’ MvPolynomial Ο„ R) theorem bind₁_C_right (f : Οƒ β†’ MvPolynomial Ο„ R) (x) : bind₁ f (C x) = C x := algHom_C _ _ @[simp] theorem bindβ‚‚_C_right (f : R β†’+* MvPolynomial Οƒ S) (r : R) : bindβ‚‚ f (C r) = f r := evalβ‚‚Hom_C f X r @[simp] theorem bindβ‚‚_C_left : bindβ‚‚ (C : R β†’+* MvPolynomial Οƒ R) = RingHom.id _ := by ext : 2 <;> simp @[simp] theorem bindβ‚‚_comp_C (f : R β†’+* MvPolynomial Οƒ S) : (bindβ‚‚ f).comp C = f := RingHom.ext <| bindβ‚‚_C_right _ @[simp] theorem joinβ‚‚_map (f : R β†’+* MvPolynomial Οƒ S) (Ο† : MvPolynomial Οƒ R) : joinβ‚‚ (map f Ο†) = bindβ‚‚ f Ο† := by simp only [joinβ‚‚, bindβ‚‚, evalβ‚‚Hom_map_hom, RingHom.id_comp] @[simp] theorem joinβ‚‚_comp_map (f : R β†’+* MvPolynomial Οƒ S) : joinβ‚‚.comp (map f) = bindβ‚‚ f := RingHom.ext <| joinβ‚‚_map _ theorem aeval_id_rename (f : Οƒ β†’ MvPolynomial Ο„ R) (p : MvPolynomial Οƒ R) : aeval id (rename f p) = aeval f p := by rw [aeval_rename, Function.id_comp] @[simp] theorem join₁_rename (f : Οƒ β†’ MvPolynomial Ο„ R) (Ο† : MvPolynomial Οƒ R) : join₁ (rename f Ο†) = bind₁ f Ο† := aeval_id_rename _ _ @[simp] theorem bind₁_id : bind₁ (@id (MvPolynomial Οƒ R)) = join₁ := rfl @[simp] theorem bindβ‚‚_id : bindβ‚‚ (RingHom.id (MvPolynomial Οƒ R)) = joinβ‚‚ := rfl theorem bind₁_bind₁ {Ο… : Type*} (f : Οƒ β†’ MvPolynomial Ο„ R) (g : Ο„ β†’ MvPolynomial Ο… R) (Ο† : MvPolynomial Οƒ R) : (bind₁ g) (bind₁ f Ο†) = bind₁ (fun i => bind₁ g (f i)) Ο† := by simp [bind₁, ← comp_aeval] theorem bind₁_comp_bind₁ {Ο… : Type*} (f : Οƒ β†’ MvPolynomial Ο„ R) (g : Ο„ β†’ MvPolynomial Ο… R) : (bind₁ g).comp (bind₁ f) = bind₁ fun i => bind₁ g (f i) := by ext1 apply bind₁_bind₁ theorem bindβ‚‚_comp_bindβ‚‚ (f : R β†’+* MvPolynomial Οƒ S) (g : S β†’+* MvPolynomial Οƒ T) : (bindβ‚‚ g).comp (bindβ‚‚ f) = bindβ‚‚ ((bindβ‚‚ g).comp f) := by ext : 2 <;> simp theorem bindβ‚‚_bindβ‚‚ (f : R β†’+* MvPolynomial Οƒ S) (g : S β†’+* MvPolynomial Οƒ T) (Ο† : MvPolynomial Οƒ R) : (bindβ‚‚ g) (bindβ‚‚ f Ο†) = bindβ‚‚ ((bindβ‚‚ g).comp f) Ο† := RingHom.congr_fun (bindβ‚‚_comp_bindβ‚‚ f g) Ο† theorem rename_comp_bind₁ {Ο… : Type*} (f : Οƒ β†’ MvPolynomial Ο„ R) (g : Ο„ β†’ Ο…) : (rename g).comp (bind₁ f) = bind₁ fun i => rename g <| f i := by ext1 i simp theorem rename_bind₁ {Ο… : Type*} (f : Οƒ β†’ MvPolynomial Ο„ R) (g : Ο„ β†’ Ο…) (Ο† : MvPolynomial Οƒ R) : rename g (bind₁ f Ο†) = bind₁ (fun i => rename g <| f i) Ο† := AlgHom.congr_fun (rename_comp_bind₁ f g) Ο† theorem map_bindβ‚‚ (f : R β†’+* MvPolynomial Οƒ S) (g : S β†’+* T) (Ο† : MvPolynomial Οƒ R) : map g (bindβ‚‚ f Ο†) = bindβ‚‚ ((map g).comp f) Ο† := by simp only [bindβ‚‚, evalβ‚‚_comp_right, coe_evalβ‚‚Hom, evalβ‚‚_map] congr 1 with : 1 simp only [Function.comp_apply, map_X] theorem bind₁_comp_rename {Ο… : Type*} (f : Ο„ β†’ MvPolynomial Ο… R) (g : Οƒ β†’ Ο„) : (bind₁ f).comp (rename g) = bind₁ (f ∘ g) := by ext1 i simp theorem bind₁_rename {Ο… : Type*} (f : Ο„ β†’ MvPolynomial Ο… R) (g : Οƒ β†’ Ο„) (Ο† : MvPolynomial Οƒ R) : bind₁ f (rename g Ο†) = bind₁ (f ∘ g) Ο† := AlgHom.congr_fun (bind₁_comp_rename f g) Ο† theorem bindβ‚‚_map (f : S β†’+* MvPolynomial Οƒ T) (g : R β†’+* S) (Ο† : MvPolynomial Οƒ R) : bindβ‚‚ f (map g Ο†) = bindβ‚‚ (f.comp g) Ο† := by simp [bindβ‚‚] @[simp] theorem map_comp_C (f : R β†’+* S) : (map f).comp (C : R β†’+* MvPolynomial Οƒ R) = C.comp f := by ext1 apply map_C -- mixing the two monad structures theorem hom_bind₁ (f : MvPolynomial Ο„ R β†’+* S) (g : Οƒ β†’ MvPolynomial Ο„ R) (Ο† : MvPolynomial Οƒ R) : f (bind₁ g Ο†) = evalβ‚‚Hom (f.comp C) (fun i => f (g i)) Ο† := by rw [bind₁, map_aeval, algebraMap_eq] theorem map_bind₁ (f : R β†’+* S) (g : Οƒ β†’ MvPolynomial Ο„ R) (Ο† : MvPolynomial Οƒ R) : map f (bind₁ g Ο†) = bind₁ (fun i : Οƒ => (map f) (g i)) (map f Ο†) := by rw [hom_bind₁, map_comp_C, ← evalβ‚‚Hom_map_hom] rfl @[simp] theorem evalβ‚‚Hom_comp_C (f : R β†’+* S) (g : Οƒ β†’ S) : (evalβ‚‚Hom f g).comp C = f := by ext1 r exact evalβ‚‚_C f g r theorem evalβ‚‚Hom_bind₁ (f : R β†’+* S) (g : Ο„ β†’ S) (h : Οƒ β†’ MvPolynomial Ο„ R) (Ο† : MvPolynomial Οƒ R) : evalβ‚‚Hom f g (bind₁ h Ο†) = evalβ‚‚Hom f (fun i => evalβ‚‚Hom f g (h i)) Ο† := by rw [hom_bind₁, evalβ‚‚Hom_comp_C] theorem aeval_bind₁ [Algebra R S] (f : Ο„ β†’ S) (g : Οƒ β†’ MvPolynomial Ο„ R) (Ο† : MvPolynomial Οƒ R) : aeval f (bind₁ g Ο†) = aeval (fun i => aeval f (g i)) Ο† := evalβ‚‚Hom_bind₁ _ _ _ _ theorem aeval_comp_bind₁ [Algebra R S] (f : Ο„ β†’ S) (g : Οƒ β†’ MvPolynomial Ο„ R) : (aeval f).comp (bind₁ g) = aeval fun i => aeval f (g i) := by ext1 apply aeval_bind₁ theorem evalβ‚‚Hom_comp_bindβ‚‚ (f : S β†’+* T) (g : Οƒ β†’ T) (h : R β†’+* MvPolynomial Οƒ S) : (evalβ‚‚Hom f g).comp (bindβ‚‚ h) = evalβ‚‚Hom ((evalβ‚‚Hom f g).comp h) g := by ext : 2 <;> simp theorem evalβ‚‚Hom_bindβ‚‚ (f : S β†’+* T) (g : Οƒ β†’ T) (h : R β†’+* MvPolynomial Οƒ S) (Ο† : MvPolynomial Οƒ R) : evalβ‚‚Hom f g (bindβ‚‚ h Ο†) = evalβ‚‚Hom ((evalβ‚‚Hom f g).comp h) g Ο† := RingHom.congr_fun (evalβ‚‚Hom_comp_bindβ‚‚ f g h) Ο† theorem aeval_bindβ‚‚ [Algebra S T] (f : Οƒ β†’ T) (g : R β†’+* MvPolynomial Οƒ S) (Ο† : MvPolynomial Οƒ R) : aeval f (bindβ‚‚ g Ο†) = evalβ‚‚Hom ((↑(aeval f : _ →ₐ[S] _) : _ β†’+* _).comp g) f Ο† := evalβ‚‚Hom_bindβ‚‚ _ _ _ _ alias evalβ‚‚Hom_C_left := evalβ‚‚Hom_C_eq_bind₁
Mathlib/Algebra/MvPolynomial/Monad.lean
273
275
theorem bind₁_monomial (f : Οƒ β†’ MvPolynomial Ο„ R) (d : Οƒ β†’β‚€ β„•) (r : R) : bind₁ f (monomial d r) = C r * ∏ i ∈ d.support, f i ^ d i := by
simp only [monomial_eq, map_mul, bind₁_C_right, Finsupp.prod, map_prod,
/- Copyright (c) 2020 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca, Johan Commelin -/ import Mathlib.Algebra.GCDMonoid.IntegrallyClosed import Mathlib.FieldTheory.Finite.Basic import Mathlib.FieldTheory.Minpoly.IsIntegrallyClosed import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.RingTheory.UniqueFactorizationDomain.Nat /-! # Minimal polynomial of roots of unity We gather several results about minimal polynomial of root of unity. ## Main results * `IsPrimitiveRoot.totient_le_degree_minpoly`: The degree of the minimal polynomial of an `n`-th primitive root of unity is at least `totient n`. -/ open minpoly Polynomial open scoped Polynomial namespace IsPrimitiveRoot section CommRing variable {n : β„•} {K : Type*} [CommRing K] {ΞΌ : K} (h : IsPrimitiveRoot ΞΌ n) include h /-- `ΞΌ` is integral over `β„€`. -/ -- Porting note: `hpos` was in the `variable` line, with an `omit` in mathlib3 just after this -- declaration. For some reason, in Lean4, `hpos` gets included also in the declarations below, -- even if it is not used in the proof.
Mathlib/RingTheory/RootsOfUnity/Minpoly.lean
40
45
theorem isIntegral (hpos : 0 < n) : IsIntegral β„€ ΞΌ := by
use X ^ n - 1 constructor Β· exact monic_X_pow_sub_C 1 (ne_of_lt hpos).symm Β· simp only [((IsPrimitiveRoot.iff_def ΞΌ n).mp h).left, evalβ‚‚_one, evalβ‚‚_X_pow, evalβ‚‚_sub, sub_self]
/- Copyright (c) 2022 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.Basic import Mathlib.RingTheory.PrincipalIdealDomain /-! # Coprimality and vanishing We show that for prime `p`, the image of an integer `a` in `ZMod p` vanishes if and only if `a` and `p` are not coprime. -/ assert_not_exists TwoSidedIdeal namespace ZMod /-- If `p` is a prime and `a` is an integer, then `a : ZMod p` is zero if and only if `gcd a p β‰  1`. -/
Mathlib/Data/ZMod/Coprime.lean
24
28
theorem eq_zero_iff_gcd_ne_one {a : β„€} {p : β„•} [pp : Fact p.Prime] : (a : ZMod p) = 0 ↔ a.gcd p β‰  1 := by
rw [Ne, Int.gcd_comm, ← Int.isCoprime_iff_gcd_eq_one, (Nat.prime_iff_prime_int.1 pp.1).coprime_iff_not_dvd, Classical.not_not, intCast_zmod_eq_zero_iff_dvd]
/- 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 /-! # 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. * `memLp_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 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} theorem isStoppingTime_const [Preorder ΞΉ] (f : Filtration ΞΉ m) (i : ΞΉ) : IsStoppingTime f fun _ => i := fun j => by simp only [MeasurableSet.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 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] 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) 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 _ => ?_ classical rw [Set.iUnion_eq_if] split_ifs with hji Β· exact f.mono hji.le _ (hΟ„.measurableSet_le j) Β· exact @MeasurableSet.empty _ (f i) 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 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) 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 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 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 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 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] 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)) 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 rcases 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') 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 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, Set.mem_inter_iff, le_antisymm_iff] rw [this] exact (hΟ„.measurableSet_le i).inter (hΟ„.measurableSet_ge i) theorem IsStoppingTime.measurableSet_eq_le (hΟ„ : IsStoppingTime f Ο„) {i j : ΞΉ} (hle : i ≀ j) : MeasurableSet[f j] {Ο‰ | Ο„ Ο‰ = i} := f.mono hle _ <| hΟ„.measurableSet_eq i theorem IsStoppingTime.measurableSet_lt_le (hΟ„ : IsStoppingTime f Ο„) {i j : ΞΉ} (hle : i ≀ j) : MeasurableSet[f j] {Ο‰ | Ο„ Ο‰ < i} := f.mono hle _ <| hΟ„.measurableSet_lt i 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) 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) protected theorem max_const [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : IsStoppingTime f fun Ο‰ => max (Ο„ Ο‰) i := hΟ„.max (isStoppingTime_const f i) 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) protected theorem min_const [LinearOrder ΞΉ] {f : Filtration ΞΉ m} {Ο„ : Ξ© β†’ ΞΉ} (hΟ„ : IsStoppingTime f Ο„) (i : ΞΉ) : IsStoppingTime f fun Ο‰ => min (Ο„ Ο‰) i := hΟ„.min (isStoppingTime_const f i) theorem add_const [AddGroup ΞΉ] [Preorder ΞΉ] [AddRightMono ΞΉ] [AddLeftMono ΞΉ] {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)) 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, Set.mem_setOf] omega -- 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 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) protected theorem measurableSet (hΟ„ : IsStoppingTime f Ο„) (s : Set Ξ©) : MeasurableSet[hΟ„.measurableSpace] s ↔ βˆ€ i : ΞΉ, MeasurableSet[f i] (s ∩ {Ο‰ | Ο„ Ο‰ ≀ i}) := Iff.rfl 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' 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 theorem measurableSpace_le [IsCountablyGenerated (atTop : Filter ΞΉ)] [IsDirected ΞΉ (Β· ≀ Β·)] (hΟ„ : IsStoppingTime f Ο„) : hΟ„.measurableSpace ≀ m := by intro s hs cases isEmpty_or_nonempty ΞΉ Β· haveI : IsEmpty Ξ© := ⟨fun Ο‰ => IsEmpty.false (Ο„ Ο‰)⟩ apply Subsingleton.measurableSet Β· 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 @[deprecated (since := "2024-12-25")] alias measurableSpace_le' := 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)] 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 Β· simp [hij] 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 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) 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) 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 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 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Ο„ _) 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 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 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) 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) 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 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 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) 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 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) 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 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 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 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 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) 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 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] 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 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, true_or] by_cases hΟ„i : Ο„ Ο‰ ≀ i Β· simp only [hΟ„i, true_or, and_true, and_congr_right_iff] intro constructor <;> intro h Β· exact Or.inl h Β· rcases h with h | h Β· exact h Β· exact hΟ„i.trans h simp only [hΟ„i, false_or, and_false, false_and, iff_false, 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 _ _ 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 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 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_congr_left_iff] intro h simp only [h, or_self_iff, and_true] 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 _ _ 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Ο€ 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 Β· obtain ⟨h', hΟƒ_le⟩ := h obtain ⟨h_eq, hΟ„_le⟩ := h' 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 _ _ 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 Β· obtain ⟨h', hΟ€_le⟩ := h obtain ⟨h_eq, hΟ„_le⟩ := h' 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 _ _ 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 (Ο„ Ο‰) Ο‰ theorem stoppedValue_const (u : ΞΉ β†’ Ξ© β†’ Ξ²) (i : ΞΉ) : (stoppedValue u fun _ => i) = u i := rfl 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 occurred. -/ def stoppedProcess (u : ΞΉ β†’ Ξ© β†’ Ξ²) (Ο„ : Ξ© β†’ ΞΉ) : ΞΉ β†’ Ξ© β†’ Ξ² := fun i Ο‰ => u (min i (Ο„ Ο‰)) Ο‰
Mathlib/Probability/Process/Stopping.lean
703
724
theorem stoppedProcess_eq_stoppedValue {u : ΞΉ β†’ Ξ© β†’ Ξ²} {Ο„ : Ξ© β†’ ΞΉ} : stoppedProcess u Ο„ = fun i => stoppedValue u fun Ο‰ => min i (Ο„ Ο‰) := rfl theorem stoppedValue_stoppedProcess {u : ΞΉ β†’ Ξ© β†’ Ξ²} {Ο„ Οƒ : Ξ© β†’ ΞΉ} : stoppedValue (stoppedProcess u Ο„) Οƒ = stoppedValue u fun Ο‰ => min (Οƒ Ο‰) (Ο„ Ο‰) := rfl theorem stoppedProcess_eq_of_le {u : ΞΉ β†’ Ξ© β†’ Ξ²} {Ο„ : Ξ© β†’ ΞΉ} {i : ΞΉ} {Ο‰ : Ξ©} (h : i ≀ Ο„ Ο‰) : stoppedProcess u Ο„ i Ο‰ = u i Ο‰ := by
simp [stoppedProcess, min_eq_left h] theorem stoppedProcess_eq_of_ge {u : ΞΉ β†’ Ξ© β†’ Ξ²} {Ο„ : Ξ© β†’ ΞΉ} {i : ΞΉ} {Ο‰ : Ξ©} (h : Ο„ Ο‰ ≀ i) : stoppedProcess u Ο„ i Ο‰ = u (Ο„ Ο‰) Ο‰ := by simp [stoppedProcess, min_eq_right h] 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
/- Copyright (c) 2023 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.Comp import Mathlib.Analysis.Calculus.Deriv.Add import Mathlib.Analysis.Calculus.Deriv.Mul import Mathlib.Analysis.Calculus.Deriv.Slope /-! # Line derivatives We define the line derivative of a function `f : E β†’ F`, at a point `x : E` along a vector `v : E`, as the element `f' : F` such that `f (x + t β€’ v) = f x + t β€’ f' + o (t)` as `t` tends to `0` in the scalar field `π•œ`, if it exists. It is denoted by `lineDeriv π•œ f x v`. This notion is generally less well behaved than the full FrΓ©chet derivative (for instance, the composition of functions which are line-differentiable is not line-differentiable in general). The FrΓ©chet derivative should therefore be favored over this one in general, although the line derivative may sometimes prove handy. The line derivative in direction `v` is also called the Gateaux derivative in direction `v`, although the term "Gateaux derivative" is sometimes reserved for the situation where there is such a derivative in all directions, for the map `v ↦ lineDeriv π•œ f x v` (which doesn't have to be linear in general). ## Main definition and results We mimic the definitions and statements for the FrΓ©chet derivative and the one-dimensional derivative. We define in particular the following objects: * `LineDifferentiableWithinAt π•œ f s x v` * `LineDifferentiableAt π•œ f x v` * `HasLineDerivWithinAt π•œ f f' s x v` * `HasLineDerivAt π•œ f s x v` * `lineDerivWithin π•œ f s x v` * `lineDeriv π•œ f x v` and develop about them a basic API inspired by the one for the FrΓ©chet derivative. We depart from the FrΓ©chet derivative in two places, as the dependence of the following predicates on the direction would make them barely usable: * We do not define an analogue of the predicate `UniqueDiffOn`; * We do not define `LineDifferentiableOn` nor `LineDifferentiable`. -/ noncomputable section open scoped Topology Filter ENNReal NNReal open Filter Asymptotics Set variable {π•œ : Type*} [NontriviallyNormedField π•œ] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace π•œ F] section Module /-! Results that do not rely on a topological structure on `E` -/ variable (π•œ) variable {E : Type*} [AddCommGroup E] [Module π•œ E] /-- `f` has the derivative `f'` at the point `x` along the direction `v` in the set `s`. That is, `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. Note that this definition is less well behaved than the total FrΓ©chet derivative, which should generally be favored over this one. -/ def HasLineDerivWithinAt (f : E β†’ F) (f' : F) (s : Set E) (x : E) (v : E) := HasDerivWithinAt (fun t ↦ f (x + t β€’ v)) f' ((fun t ↦ x + t β€’ v) ⁻¹' s) (0 : π•œ) /-- `f` has the derivative `f'` at the point `x` along the direction `v`. That is, `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0`. Note that this definition is less well behaved than the total FrΓ©chet derivative, which should generally be favored over this one. -/ def HasLineDerivAt (f : E β†’ F) (f' : F) (x : E) (v : E) := HasDerivAt (fun t ↦ f (x + t β€’ v)) f' (0 : π•œ) /-- `f` is line-differentiable at the point `x` in the direction `v` in the set `s` if there exists `f'` such that `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def LineDifferentiableWithinAt (f : E β†’ F) (s : Set E) (x : E) (v : E) : Prop := DifferentiableWithinAt π•œ (fun t ↦ f (x + t β€’ v)) ((fun t ↦ x + t β€’ v) ⁻¹' s) (0 : π•œ) /-- `f` is line-differentiable at the point `x` in the direction `v` if there exists `f'` such that `f (x + t v) = f x + t β€’ f' + o (t)` when `t` tends to `0`. -/ def LineDifferentiableAt (f : E β†’ F) (x : E) (v : E) : Prop := DifferentiableAt π•œ (fun t ↦ f (x + t β€’ v)) (0 : π•œ) /-- Line derivative of `f` at the point `x` in the direction `v` within the set `s`, if it exists. Zero otherwise. If the line derivative exists (i.e., `βˆƒ f', HasLineDerivWithinAt π•œ f f' s x v`), then `f (x + t v) = f x + t lineDerivWithin π•œ f s x v + o (t)` when `t` tends to `0` and `x + t v ∈ s`. -/ def lineDerivWithin (f : E β†’ F) (s : Set E) (x : E) (v : E) : F := derivWithin (fun t ↦ f (x + t β€’ v)) ((fun t ↦ x + t β€’ v) ⁻¹' s) (0 : π•œ) /-- Line derivative of `f` at the point `x` in the direction `v`, if it exists. Zero otherwise. If the line derivative exists (i.e., `βˆƒ f', HasLineDerivAt π•œ f f' x v`), then `f (x + t v) = f x + t lineDeriv π•œ f x v + o (t)` when `t` tends to `0`. -/ def lineDeriv (f : E β†’ F) (x : E) (v : E) : F := deriv (fun t ↦ f (x + t β€’ v)) (0 : π•œ) variable {π•œ} variable {f f₁ : E β†’ F} {f' fβ‚€' f₁' : F} {s t : Set E} {x v : E} lemma HasLineDerivWithinAt.mono (hf : HasLineDerivWithinAt π•œ f f' s x v) (hst : t βŠ† s) : HasLineDerivWithinAt π•œ f f' t x v := HasDerivWithinAt.mono hf (preimage_mono hst) lemma HasLineDerivAt.hasLineDerivWithinAt (hf : HasLineDerivAt π•œ f f' x v) (s : Set E) : HasLineDerivWithinAt π•œ f f' s x v := HasDerivAt.hasDerivWithinAt hf lemma HasLineDerivWithinAt.lineDifferentiableWithinAt (hf : HasLineDerivWithinAt π•œ f f' s x v) : LineDifferentiableWithinAt π•œ f s x v := HasDerivWithinAt.differentiableWithinAt hf theorem HasLineDerivAt.lineDifferentiableAt (hf : HasLineDerivAt π•œ f f' x v) : LineDifferentiableAt π•œ f x v := HasDerivAt.differentiableAt hf theorem LineDifferentiableWithinAt.hasLineDerivWithinAt (h : LineDifferentiableWithinAt π•œ f s x v) : HasLineDerivWithinAt π•œ f (lineDerivWithin π•œ f s x v) s x v := DifferentiableWithinAt.hasDerivWithinAt h theorem LineDifferentiableAt.hasLineDerivAt (h : LineDifferentiableAt π•œ f x v) : HasLineDerivAt π•œ f (lineDeriv π•œ f x v) x v := DifferentiableAt.hasDerivAt h @[simp] lemma hasLineDerivWithinAt_univ : HasLineDerivWithinAt π•œ f f' univ x v ↔ HasLineDerivAt π•œ f f' x v := by simp only [HasLineDerivWithinAt, HasLineDerivAt, preimage_univ, hasDerivWithinAt_univ] theorem lineDerivWithin_zero_of_not_lineDifferentiableWithinAt (h : Β¬LineDifferentiableWithinAt π•œ f s x v) : lineDerivWithin π•œ f s x v = 0 := derivWithin_zero_of_not_differentiableWithinAt h theorem lineDeriv_zero_of_not_lineDifferentiableAt (h : Β¬LineDifferentiableAt π•œ f x v) : lineDeriv π•œ f x v = 0 := deriv_zero_of_not_differentiableAt h theorem hasLineDerivAt_iff_isLittleO_nhds_zero : HasLineDerivAt π•œ f f' x v ↔ (fun t : π•œ => f (x + t β€’ v) - f x - t β€’ f') =o[𝓝 0] fun t => t := by simp only [HasLineDerivAt, hasDerivAt_iff_isLittleO_nhds_zero, zero_add, zero_smul, add_zero] theorem HasLineDerivAt.unique (hβ‚€ : HasLineDerivAt π•œ f fβ‚€' x v) (h₁ : HasLineDerivAt π•œ f f₁' x v) : fβ‚€' = f₁' := HasDerivAt.unique hβ‚€ h₁ protected theorem HasLineDerivAt.lineDeriv (h : HasLineDerivAt π•œ f f' x v) : lineDeriv π•œ f x v = f' := by rw [h.unique h.lineDifferentiableAt.hasLineDerivAt] theorem lineDifferentiableWithinAt_univ : LineDifferentiableWithinAt π•œ f univ x v ↔ LineDifferentiableAt π•œ f x v := by simp only [LineDifferentiableWithinAt, LineDifferentiableAt, preimage_univ, differentiableWithinAt_univ] theorem LineDifferentiableAt.lineDifferentiableWithinAt (h : LineDifferentiableAt π•œ f x v) : LineDifferentiableWithinAt π•œ f s x v := (differentiableWithinAt_univ.2 h).mono (subset_univ _) @[simp]
Mathlib/Analysis/Calculus/LineDeriv/Basic.lean
170
171
theorem lineDerivWithin_univ : lineDerivWithin π•œ f univ x v = lineDeriv π•œ f x v := by
simp [lineDerivWithin, lineDeriv]
/- Copyright (c) 2023 RΓ©my Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: RΓ©my Degenne -/ import Mathlib.Probability.ConditionalProbability import Mathlib.Probability.Kernel.Basic import Mathlib.Probability.Kernel.Composition.MeasureComp import Mathlib.Tactic.Peel import Mathlib.MeasureTheory.MeasurableSpace.Pi /-! # Independence with respect to a kernel and a measure A family of sets of sets `Ο€ : ΞΉ β†’ Set (Set Ξ©)` is independent with respect to a kernel `ΞΊ : Kernel Ξ± Ξ©` and a measure `ΞΌ` on `Ξ±` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ Ο€ i_1, ..., f i_n ∈ Ο€ i_n`, then for `ΞΌ`-almost every `a : Ξ±`, `ΞΊ a (β‹‚ i in s, f i) = ∏ i ∈ s, ΞΊ a (f i)`. This notion of independence is a generalization of both independence and conditional independence. For conditional independence, `ΞΊ` is the conditional kernel `ProbabilityTheory.condExpKernel` and `ΞΌ` is the ambient measure. For (non-conditional) independence, `ΞΊ = Kernel.const Unit ΞΌ` and the measure is the Dirac measure on `Unit`. The main purpose of this file is to prove only once the properties that hold for both conditional and non-conditional independence. ## Main definitions * `ProbabilityTheory.Kernel.iIndepSets`: independence of a family of sets of sets. Variant for two sets of sets: `ProbabilityTheory.Kernel.IndepSets`. * `ProbabilityTheory.Kernel.iIndep`: independence of a family of Οƒ-algebras. Variant for two Οƒ-algebras: `Indep`. * `ProbabilityTheory.Kernel.iIndepSet`: independence of a family of sets. Variant for two sets: `ProbabilityTheory.Kernel.IndepSet`. * `ProbabilityTheory.Kernel.iIndepFun`: independence of a family of functions (random variables). Variant for two functions: `ProbabilityTheory.Kernel.IndepFun`. See the file `Mathlib/Probability/Kernel/Basic.lean` for a more detailed discussion of these definitions in the particular case of the usual independence notion. ## Main statements * `ProbabilityTheory.Kernel.iIndepSets.iIndep`: if Ο€-systems are independent as sets of sets, then the measurable space structures they generate are independent. * `ProbabilityTheory.Kernel.IndepSets.Indep`: variant with two Ο€-systems. -/ open Set MeasureTheory MeasurableSpace open scoped MeasureTheory ENNReal namespace ProbabilityTheory.Kernel variable {Ξ± Ξ© ΞΉ : Type*} section Definitions variable {_mΞ± : MeasurableSpace Ξ±} /-- A family of sets of sets `Ο€ : ΞΉ β†’ Set (Set Ξ©)` is independent with respect to a kernel `ΞΊ` and a measure `ΞΌ` if for any finite set of indices `s = {i_1, ..., i_n}`, for any sets `f i_1 ∈ Ο€ i_1, ..., f i_n ∈ Ο€ i_n`, then `βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i in s, f i) = ∏ i ∈ s, ΞΊ a (f i)`. It will be used for families of pi_systems. -/ def iIndepSets {_mΞ© : MeasurableSpace Ξ©} (Ο€ : ΞΉ β†’ Set (Set Ξ©)) (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := βˆ€ (s : Finset ΞΉ) {f : ΞΉ β†’ Set Ξ©} (_H : βˆ€ i, i ∈ s β†’ f i ∈ Ο€ i), βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i ∈ s, f i) = ∏ i ∈ s, ΞΊ a (f i) /-- Two sets of sets `s₁, sβ‚‚` are independent with respect to a kernel `ΞΊ` and a measure `ΞΌ` if for any sets `t₁ ∈ s₁, tβ‚‚ ∈ sβ‚‚`, then `βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (t₁ ∩ tβ‚‚) = ΞΊ a (t₁) * ΞΊ a (tβ‚‚)` -/ def IndepSets {_mΞ© : MeasurableSpace Ξ©} (s1 s2 : Set (Set Ξ©)) (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := βˆ€ t1 t2 : Set Ξ©, t1 ∈ s1 β†’ t2 ∈ s2 β†’ (βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (t1 ∩ t2) = ΞΊ a t1 * ΞΊ a t2) /-- A family of measurable space structures (i.e. of Οƒ-algebras) is independent with respect to a kernel `ΞΊ` and a measure `ΞΌ` if the family of sets of measurable sets they define is independent. -/ def iIndep (m : ΞΉ β†’ MeasurableSpace Ξ©) {_mΞ© : MeasurableSpace Ξ©} (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) ΞΊ ΞΌ /-- Two measurable space structures (or Οƒ-algebras) `m₁, mβ‚‚` are independent with respect to a kernel `ΞΊ` and a measure `ΞΌ` if for any sets `t₁ ∈ m₁, tβ‚‚ ∈ mβ‚‚`, `βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (t₁ ∩ tβ‚‚) = ΞΊ a (t₁) * ΞΊ a (tβ‚‚)` -/ def Indep (m₁ mβ‚‚ : MeasurableSpace Ξ©) {_mΞ© : MeasurableSpace Ξ©} (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := IndepSets {s | MeasurableSet[m₁] s} {s | MeasurableSet[mβ‚‚] s} ΞΊ ΞΌ /-- A family of sets is independent if the family of measurable space structures they generate is independent. For a set `s`, the generated measurable space has measurable sets `βˆ…, s, sᢜ, univ`. -/ def iIndepSet {_mΞ© : MeasurableSpace Ξ©} (s : ΞΉ β†’ Set Ξ©) (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := iIndep (m := fun i ↦ generateFrom {s i}) ΞΊ ΞΌ /-- Two sets are independent if the two measurable space structures they generate are independent. For a set `s`, the generated measurable space structure has measurable sets `βˆ…, s, sᢜ, univ`. -/ def IndepSet {_mΞ© : MeasurableSpace Ξ©} (s t : Set Ξ©) (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := Indep (generateFrom {s}) (generateFrom {t}) ΞΊ ΞΌ /-- A family of functions defined on the same space `Ξ©` and taking values in possibly different spaces, each with a measurable space structure, is independent if the family of measurable space structures they generate on `Ξ©` is independent. For a function `g` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap g m`. -/ def iIndepFun {_mΞ© : MeasurableSpace Ξ©} {Ξ² : ΞΉ β†’ Type*} [m : βˆ€ x : ΞΉ, MeasurableSpace (Ξ² x)] (f : βˆ€ x : ΞΉ, Ξ© β†’ Ξ² x) (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := iIndep (m := fun x ↦ MeasurableSpace.comap (f x) (m x)) ΞΊ ΞΌ /-- Two functions are independent if the two measurable space structures they generate are independent. For a function `f` with codomain having measurable space structure `m`, the generated measurable space structure is `MeasurableSpace.comap f m`. -/ def IndepFun {Ξ² Ξ³} {_mΞ© : MeasurableSpace Ξ©} [mΞ² : MeasurableSpace Ξ²] [mΞ³ : MeasurableSpace Ξ³] (f : Ξ© β†’ Ξ²) (g : Ξ© β†’ Ξ³) (ΞΊ : Kernel Ξ± Ξ©) (ΞΌ : Measure Ξ± := by volume_tac) : Prop := Indep (MeasurableSpace.comap f mΞ²) (MeasurableSpace.comap g mΞ³) ΞΊ ΞΌ end Definitions section ByDefinition variable {Ξ² : ΞΉ β†’ Type*} {mΞ² : βˆ€ i, MeasurableSpace (Ξ² i)} {_mΞ± : MeasurableSpace Ξ±} {m : ΞΉ β†’ MeasurableSpace Ξ©} {_mΞ© : MeasurableSpace Ξ©} {ΞΊ Ξ· : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} {Ο€ : ΞΉ β†’ Set (Set Ξ©)} {s : ΞΉ β†’ Set Ξ©} {S : Finset ΞΉ} {f : βˆ€ x : ΞΉ, Ξ© β†’ Ξ² x} {s1 s2 : Set (Set Ξ©)} @[simp] lemma iIndepSets_zero_right : iIndepSets Ο€ ΞΊ 0 := by simp [iIndepSets] @[simp] lemma indepSets_zero_right : IndepSets s1 s2 ΞΊ 0 := by simp [IndepSets] @[simp] lemma indepSets_zero_left : IndepSets s1 s2 (0 : Kernel Ξ± Ξ©) ΞΌ := by simp [IndepSets] @[simp] lemma iIndep_zero_right : iIndep m ΞΊ 0 := by simp [iIndep] @[simp] lemma indep_zero_right {m₁ mβ‚‚ : MeasurableSpace Ξ©} {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} : Indep m₁ mβ‚‚ ΞΊ 0 := by simp [Indep] @[simp] lemma indep_zero_left {m₁ mβ‚‚ : MeasurableSpace Ξ©} {_mΞ© : MeasurableSpace Ξ©} : Indep m₁ mβ‚‚ (0 : Kernel Ξ± Ξ©) ΞΌ := by simp [Indep] @[simp] lemma iIndepSet_zero_right : iIndepSet s ΞΊ 0 := by simp [iIndepSet] @[simp] lemma indepSet_zero_right {s t : Set Ξ©} : IndepSet s t ΞΊ 0 := by simp [IndepSet] @[simp] lemma indepSet_zero_left {s t : Set Ξ©} : IndepSet s t (0 : Kernel Ξ± Ξ©) ΞΌ := by simp [IndepSet] @[simp] lemma iIndepFun_zero_right {Ξ² : ΞΉ β†’ Type*} {m : βˆ€ x : ΞΉ, MeasurableSpace (Ξ² x)} {f : βˆ€ x : ΞΉ, Ξ© β†’ Ξ² x} : iIndepFun f ΞΊ 0 := by simp [iIndepFun] @[simp] lemma indepFun_zero_right {Ξ² Ξ³} [MeasurableSpace Ξ²] [MeasurableSpace Ξ³] {f : Ξ© β†’ Ξ²} {g : Ξ© β†’ Ξ³} : IndepFun f g ΞΊ 0 := by simp [IndepFun] @[simp] lemma indepFun_zero_left {Ξ² Ξ³} [MeasurableSpace Ξ²] [MeasurableSpace Ξ³] {f : Ξ© β†’ Ξ²} {g : Ξ© β†’ Ξ³} : IndepFun f g (0 : Kernel Ξ± Ξ©) ΞΌ := by simp [IndepFun] lemma iIndepSets_congr (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : iIndepSets Ο€ ΞΊ ΞΌ ↔ iIndepSets Ο€ Ξ· ΞΌ := by peel 3 refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;> Β· filter_upwards [h, h'] with a ha h'a simpa [ha] using h'a alias ⟨iIndepSets.congr, _⟩ := iIndepSets_congr lemma indepSets_congr (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : IndepSets s1 s2 ΞΊ ΞΌ ↔ IndepSets s1 s2 Ξ· ΞΌ := by peel 4 refine ⟨fun h' ↦ ?_, fun h' ↦ ?_⟩ <;> Β· filter_upwards [h, h'] with a ha h'a simpa [ha] using h'a alias ⟨IndepSets.congr, _⟩ := indepSets_congr lemma iIndep_congr (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : iIndep m ΞΊ ΞΌ ↔ iIndep m Ξ· ΞΌ := iIndepSets_congr h alias ⟨iIndep.congr, _⟩ := iIndep_congr lemma indep_congr {m₁ mβ‚‚ : MeasurableSpace Ξ©} {_mΞ© : MeasurableSpace Ξ©} {ΞΊ Ξ· : Kernel Ξ± Ξ©} (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : Indep m₁ mβ‚‚ ΞΊ ΞΌ ↔ Indep m₁ mβ‚‚ Ξ· ΞΌ := indepSets_congr h alias ⟨Indep.congr, _⟩ := indep_congr lemma iIndepSet_congr (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : iIndepSet s ΞΊ ΞΌ ↔ iIndepSet s Ξ· ΞΌ := iIndep_congr h alias ⟨iIndepSet.congr, _⟩ := iIndepSet_congr lemma indepSet_congr {s t : Set Ξ©} (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : IndepSet s t ΞΊ ΞΌ ↔ IndepSet s t Ξ· ΞΌ := indep_congr h alias ⟨indepSet.congr, _⟩ := indepSet_congr lemma iIndepFun_congr {Ξ² : ΞΉ β†’ Type*} {m : βˆ€ x : ΞΉ, MeasurableSpace (Ξ² x)} {f : βˆ€ x : ΞΉ, Ξ© β†’ Ξ² x} (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : iIndepFun f ΞΊ ΞΌ ↔ iIndepFun f Ξ· ΞΌ := iIndep_congr h alias ⟨iIndepFun.congr, _⟩ := iIndepFun_congr lemma indepFun_congr {Ξ² Ξ³} [MeasurableSpace Ξ²] [MeasurableSpace Ξ³] {f : Ξ© β†’ Ξ²} {g : Ξ© β†’ Ξ³} (h : ΞΊ =ᡐ[ΞΌ] Ξ·) : IndepFun f g ΞΊ ΞΌ ↔ IndepFun f g Ξ· ΞΌ := indep_congr h alias ⟨IndepFun.congr, _⟩ := indepFun_congr lemma iIndepSets.meas_biInter (h : iIndepSets Ο€ ΞΊ ΞΌ) (s : Finset ΞΉ) {f : ΞΉ β†’ Set Ξ©} (hf : βˆ€ i, i ∈ s β†’ f i ∈ Ο€ i) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i ∈ s, f i) = ∏ i ∈ s, ΞΊ a (f i) := h s hf lemma iIndepSets.ae_isProbabilityMeasure (h : iIndepSets Ο€ ΞΊ ΞΌ) : βˆ€α΅ a βˆ‚ΞΌ, IsProbabilityMeasure (ΞΊ a) := by filter_upwards [h.meas_biInter βˆ… (f := fun _ ↦ Set.univ) (by simp)] with a ha exact ⟨by simpa using ha⟩ lemma iIndepSets.meas_iInter [Fintype ΞΉ] (h : iIndepSets Ο€ ΞΊ ΞΌ) (hs : βˆ€ i, s i ∈ Ο€ i) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i, s i) = ∏ i, ΞΊ a (s i) := by filter_upwards [h.meas_biInter Finset.univ (fun _i _ ↦ hs _)] with a ha using by simp [← ha] lemma iIndep.iIndepSets' (hΞΌ : iIndep m ΞΊ ΞΌ) : iIndepSets (fun x ↦ {s | MeasurableSet[m x] s}) ΞΊ ΞΌ := hΞΌ lemma iIndep.ae_isProbabilityMeasure (h : iIndep m ΞΊ ΞΌ) : βˆ€α΅ a βˆ‚ΞΌ, IsProbabilityMeasure (ΞΊ a) := h.iIndepSets'.ae_isProbabilityMeasure lemma iIndep.meas_biInter (hΞΌ : iIndep m ΞΊ ΞΌ) (hs : βˆ€ i, i ∈ S β†’ MeasurableSet[m i] (s i)) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i ∈ S, s i) = ∏ i ∈ S, ΞΊ a (s i) := hΞΌ _ hs lemma iIndep.meas_iInter [Fintype ΞΉ] (h : iIndep m ΞΊ ΞΌ) (hs : βˆ€ i, MeasurableSet[m i] (s i)) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i, s i) = ∏ i, ΞΊ a (s i) := by filter_upwards [h.meas_biInter (fun i (_ : i ∈ Finset.univ) ↦ hs _)] with a ha simp [← ha] @[nontriviality, simp] lemma iIndepSets.of_subsingleton [Subsingleton ΞΉ] {m : ΞΉ β†’ Set (Set Ξ©)} {ΞΊ : Kernel Ξ± Ξ©} [IsMarkovKernel ΞΊ] : iIndepSets m ΞΊ ΞΌ := by rintro s f hf obtain rfl | ⟨i, rfl⟩ : s = βˆ… ∨ βˆƒ i, s = {i} := by simpa using (subsingleton_of_subsingleton (s := s.toSet)).eq_empty_or_singleton all_goals simp @[nontriviality, simp] lemma iIndep.of_subsingleton [Subsingleton ΞΉ] {m : ΞΉ β†’ MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} [IsMarkovKernel ΞΊ] : iIndep m ΞΊ ΞΌ := by simp [iIndep] @[nontriviality, simp] lemma iIndepFun.of_subsingleton [Subsingleton ΞΉ] {Ξ² : ΞΉ β†’ Type*} {m : βˆ€ i, MeasurableSpace (Ξ² i)} {f : βˆ€ i, Ξ© β†’ Ξ² i} [IsMarkovKernel ΞΊ] : iIndepFun f ΞΊ ΞΌ := by simp [iIndepFun] protected lemma iIndepFun.iIndep (hf : iIndepFun f ΞΊ ΞΌ) : iIndep (fun x ↦ (mΞ² x).comap (f x)) ΞΊ ΞΌ := hf lemma iIndepFun.ae_isProbabilityMeasure (h : iIndepFun f ΞΊ ΞΌ) : βˆ€α΅ a βˆ‚ΞΌ, IsProbabilityMeasure (ΞΊ a) := h.iIndep.ae_isProbabilityMeasure lemma iIndepFun.meas_biInter (hf : iIndepFun f ΞΊ ΞΌ) (hs : βˆ€ i, i ∈ S β†’ MeasurableSet[(mΞ² i).comap (f i)] (s i)) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i ∈ S, s i) = ∏ i ∈ S, ΞΊ a (s i) := hf.iIndep.meas_biInter hs lemma iIndepFun.meas_iInter [Fintype ΞΉ] (hf : iIndepFun f ΞΊ ΞΌ) (hs : βˆ€ i, MeasurableSet[(mΞ² i).comap (f i)] (s i)) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (β‹‚ i, s i) = ∏ i, ΞΊ a (s i) := hf.iIndep.meas_iInter hs lemma IndepFun.meas_inter {Ξ² Ξ³ : Type*} [mΞ² : MeasurableSpace Ξ²] [mΞ³ : MeasurableSpace Ξ³] {f : Ξ© β†’ Ξ²} {g : Ξ© β†’ Ξ³} (hfg : IndepFun f g ΞΊ ΞΌ) {s t : Set Ξ©} (hs : MeasurableSet[mΞ².comap f] s) (ht : MeasurableSet[mΞ³.comap g] t) : βˆ€α΅ a βˆ‚ΞΌ, ΞΊ a (s ∩ t) = ΞΊ a s * ΞΊ a t := hfg _ _ hs ht end ByDefinition section Indep variable {_mΞ± : MeasurableSpace Ξ±} @[symm] theorem IndepSets.symm {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} {s₁ sβ‚‚ : Set (Set Ξ©)} (h : IndepSets s₁ sβ‚‚ ΞΊ ΞΌ) : IndepSets sβ‚‚ s₁ ΞΊ ΞΌ := by intros t1 t2 ht1 ht2 filter_upwards [h t2 t1 ht2 ht1] with a ha rwa [Set.inter_comm, mul_comm] @[symm] theorem Indep.symm {m₁ mβ‚‚ : MeasurableSpace Ξ©} {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} (h : Indep m₁ mβ‚‚ ΞΊ ΞΌ) : Indep mβ‚‚ m₁ ΞΊ ΞΌ := IndepSets.symm h theorem indep_bot_right (m' : MeasurableSpace Ξ©) {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} [IsZeroOrMarkovKernel ΞΊ] : Indep m' βŠ₯ ΞΊ ΞΌ := by intros s t _ ht rw [Set.mem_setOf_eq, MeasurableSpace.measurableSet_bot_iff] at ht rcases eq_zero_or_isMarkovKernel ΞΊ with rfl| h Β· simp refine Filter.Eventually.of_forall (fun a ↦ ?_) rcases ht with ht | ht Β· rw [ht, Set.inter_empty, measure_empty, mul_zero] Β· rw [ht, Set.inter_univ, measure_univ, mul_one]
Mathlib/Probability/Independence/Kernel.lean
304
327
theorem indep_bot_left (m' : MeasurableSpace Ξ©) {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} [IsZeroOrMarkovKernel ΞΊ] : Indep βŠ₯ m' ΞΊ ΞΌ := (indep_bot_right m').symm theorem indepSet_empty_right {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} [IsZeroOrMarkovKernel ΞΊ] (s : Set Ξ©) : IndepSet s βˆ… ΞΊ ΞΌ := by
simp only [IndepSet, generateFrom_singleton_empty] exact indep_bot_right _ theorem indepSet_empty_left {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} [IsZeroOrMarkovKernel ΞΊ] (s : Set Ξ©) : IndepSet βˆ… s ΞΊ ΞΌ := (indepSet_empty_right s).symm theorem indepSets_of_indepSets_of_le_left {s₁ sβ‚‚ s₃ : Set (Set Ξ©)} {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} (h_indep : IndepSets s₁ sβ‚‚ ΞΊ ΞΌ) (h31 : s₃ βŠ† s₁) : IndepSets s₃ sβ‚‚ ΞΊ ΞΌ := fun t1 t2 ht1 ht2 => h_indep t1 t2 (Set.mem_of_subset_of_mem h31 ht1) ht2 theorem indepSets_of_indepSets_of_le_right {s₁ sβ‚‚ s₃ : Set (Set Ξ©)} {_mΞ© : MeasurableSpace Ξ©} {ΞΊ : Kernel Ξ± Ξ©} {ΞΌ : Measure Ξ±} (h_indep : IndepSets s₁ sβ‚‚ ΞΊ ΞΌ) (h32 : s₃ βŠ† sβ‚‚) : IndepSets s₁ s₃ ΞΊ ΞΌ := fun t1 t2 ht1 ht2 => h_indep t1 t2 ht1 (Set.mem_of_subset_of_mem h32 ht2)
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison, Ainsley Pahljina -/ import Mathlib.RingTheory.Fintype import Mathlib.Tactic.NormNum import Mathlib.Tactic.Ring import Mathlib.Tactic.Zify /-! # The Lucas-Lehmer test for Mersenne primes. We define `lucasLehmerResidue : Ξ  p : β„•, ZMod (2^p - 1)`, and prove `lucasLehmerResidue p = 0 β†’ Prime (mersenne p)`. We construct a `norm_num` extension to calculate this residue to certify primality of Mersenne primes using `lucas_lehmer_sufficiency`. ## TODO - Show reverse implication. - Speed up the calculations using `n ≑ (n % 2^p) + (n / 2^p) [MOD 2^p - 1]`. - Find some bigger primes! ## History This development began as a student project by Ainsley Pahljina, and was then cleaned up for mathlib by Kim Morrison. The tactic for certified computation of Lucas-Lehmer residues was provided by Mario Carneiro. This tactic was ported by Thomas Murrills to Lean 4, and then it was converted to a `norm_num` extension and made to use kernel reductions by Kyle Miller. -/ assert_not_exists TwoSidedIdeal /-- The Mersenne numbers, 2^p - 1. -/ def mersenne (p : β„•) : β„• := 2 ^ p - 1 theorem strictMono_mersenne : StrictMono mersenne := fun m n h ↦ (Nat.sub_lt_sub_iff_right <| Nat.one_le_pow _ _ two_pos).2 <| by gcongr; norm_num1 @[simp] theorem mersenne_lt_mersenne {p q : β„•} : mersenne p < mersenne q ↔ p < q := strictMono_mersenne.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.mersenne_lt_mersenne⟩ := mersenne_lt_mersenne @[simp] theorem mersenne_le_mersenne {p q : β„•} : mersenne p ≀ mersenne q ↔ p ≀ q := strictMono_mersenne.le_iff_le @[gcongr] protected alias ⟨_, GCongr.mersenne_le_mersenne⟩ := mersenne_le_mersenne @[simp] theorem mersenne_zero : mersenne 0 = 0 := rfl @[simp] lemma mersenne_odd : βˆ€ {p : β„•}, Odd (mersenne p) ↔ p β‰  0 | 0 => by simp | p + 1 => by simpa using Nat.Even.sub_odd (one_le_powβ‚€ one_le_two) (even_two.pow_of_ne_zero p.succ_ne_zero) odd_one @[simp] theorem mersenne_pos {p : β„•} : 0 < mersenne p ↔ 0 < p := mersenne_lt_mersenne (p := 0) namespace Mathlib.Meta.Positivity open Lean Meta Qq Function alias ⟨_, mersenne_pos_of_pos⟩ := mersenne_pos /-- Extension for the `positivity` tactic: `mersenne`. -/ @[positivity mersenne _] def evalMersenne : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(β„•), ~q(mersenne $a) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(mersenne_pos_of_pos $pa)) | _ => pure (.nonnegative q(Nat.zero_le (mersenne $a))) | _, _, _ => throwError "not mersenne" end Mathlib.Meta.Positivity @[simp] theorem one_lt_mersenne {p : β„•} : 1 < mersenne p ↔ 1 < p := mersenne_lt_mersenne (p := 1) @[simp] theorem succ_mersenne (k : β„•) : mersenne k + 1 = 2 ^ k := by rw [mersenne, tsub_add_cancel_of_le] exact one_le_powβ‚€ (by norm_num) namespace LucasLehmer open Nat /-! We now define three(!) different versions of the recurrence `s (i+1) = (s i)^2 - 2`. These versions take values either in `β„€`, in `ZMod (2^p - 1)`, or in `β„€` but applying `% (2^p - 1)` at each step. They are each useful at different points in the proof, so we take a moment setting up the lemmas relating them. -/ /-- The recurrence `s (i+1) = (s i)^2 - 2` in `β„€`. -/ def s : β„• β†’ β„€ | 0 => 4 | i + 1 => s i ^ 2 - 2 /-- The recurrence `s (i+1) = (s i)^2 - 2` in `ZMod (2^p - 1)`. -/ def sZMod (p : β„•) : β„• β†’ ZMod (2 ^ p - 1) | 0 => 4 | i + 1 => sZMod p i ^ 2 - 2 /-- The recurrence `s (i+1) = ((s i)^2 - 2) % (2^p - 1)` in `β„€`. -/ def sMod (p : β„•) : β„• β†’ β„€ | 0 => 4 % (2 ^ p - 1) | i + 1 => (sMod p i ^ 2 - 2) % (2 ^ p - 1) theorem mersenne_int_pos {p : β„•} (hp : p β‰  0) : (0 : β„€) < 2 ^ p - 1 := sub_pos.2 <| mod_cast Nat.one_lt_two_pow hp theorem mersenne_int_ne_zero (p : β„•) (hp : p β‰  0) : (2 ^ p - 1 : β„€) β‰  0 := (mersenne_int_pos hp).ne' theorem sMod_nonneg (p : β„•) (hp : p β‰  0) (i : β„•) : 0 ≀ sMod p i := by cases i <;> dsimp [sMod] Β· exact sup_eq_right.mp rfl Β· apply Int.emod_nonneg exact mersenne_int_ne_zero p hp theorem sMod_mod (p i : β„•) : sMod p i % (2 ^ p - 1) = sMod p i := by cases i <;> simp [sMod] theorem sMod_lt (p : β„•) (hp : p β‰  0) (i : β„•) : sMod p i < 2 ^ p - 1 := by rw [← sMod_mod] refine (Int.emod_lt_abs _ (mersenne_int_ne_zero p hp)).trans_eq ?_ exact abs_of_nonneg (mersenne_int_pos hp).le
Mathlib/NumberTheory/LucasLehmer.lean
145
145
theorem sZMod_eq_s (p' : β„•) (i : β„•) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by
/- Copyright (c) 2021 Filippo A. E. Nuccio. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Filippo A. E. Nuccio, Eric Wieser -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Block import Mathlib.LinearAlgebra.Matrix.Determinant.Basic import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.LinearAlgebra.TensorProduct.Basic import Mathlib.LinearAlgebra.TensorProduct.Associator import Mathlib.RingTheory.TensorProduct.Basic /-! # Kronecker product of matrices This defines the [Kronecker product](https://en.wikipedia.org/wiki/Kronecker_product). ## Main definitions * `Matrix.kroneckerMap`: A generalization of the Kronecker product: given a map `f : Ξ± β†’ Ξ² β†’ Ξ³` and matrices `A` and `B` with coefficients in `Ξ±` and `Ξ²`, respectively, it is defined as the matrix with coefficients in `Ξ³` such that `kroneckerMap f A B (i₁, iβ‚‚) (j₁, jβ‚‚) = f (A i₁ j₁) (B i₁ jβ‚‚)`. * `Matrix.kroneckerMapBilinear`: when `f` is bilinear, so is `kroneckerMap f`. ## Specializations * `Matrix.kronecker`: An alias of `kroneckerMap (*)`. Prefer using the notation. * `Matrix.kroneckerBilinear`: `Matrix.kronecker` is bilinear * `Matrix.kroneckerTMul`: An alias of `kroneckerMap (βŠ—β‚œ)`. Prefer using the notation. * `Matrix.kroneckerTMulBilinear`: `Matrix.kroneckerTMul` is bilinear ## Notations These require `open Kronecker`: * `A βŠ—β‚– B` for `kroneckerMap (*) A B`. Lemmas about this notation use the token `kronecker`. * `A βŠ—β‚–β‚œ B` and `A βŠ—β‚–β‚œ[R] B` for `kroneckerMap (βŠ—β‚œ) A B`. Lemmas about this notation use the token `kroneckerTMul`. -/ namespace Matrix open scoped RightActions variable {R Ξ± Ξ±' Ξ² Ξ²' Ξ³ Ξ³' : Type*} variable {l m n p : Type*} {q r : Type*} {l' m' n' p' : Type*} section KroneckerMap /-- Produce a matrix with `f` applied to every pair of elements from `A` and `B`. -/ def kroneckerMap (f : Ξ± β†’ Ξ² β†’ Ξ³) (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : Matrix (l Γ— n) (m Γ— p) Ξ³ := of fun (i : l Γ— n) (j : m Γ— p) => f (A i.1 j.1) (B i.2 j.2) -- TODO: set as an equation lemma for `kroneckerMap`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem kroneckerMap_apply (f : Ξ± β†’ Ξ² β†’ Ξ³) (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) (i j) : kroneckerMap f A B i j = f (A i.1 j.1) (B i.2 j.2) := rfl theorem kroneckerMap_transpose (f : Ξ± β†’ Ξ² β†’ Ξ³) (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : kroneckerMap f Aα΅€ Bα΅€ = (kroneckerMap f A B)α΅€ := ext fun _ _ => rfl theorem kroneckerMap_map_left (f : Ξ±' β†’ Ξ² β†’ Ξ³) (g : Ξ± β†’ Ξ±') (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : kroneckerMap f (A.map g) B = kroneckerMap (fun a b => f (g a) b) A B := ext fun _ _ => rfl theorem kroneckerMap_map_right (f : Ξ± β†’ Ξ²' β†’ Ξ³) (g : Ξ² β†’ Ξ²') (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : kroneckerMap f A (B.map g) = kroneckerMap (fun a b => f a (g b)) A B := ext fun _ _ => rfl theorem kroneckerMap_map (f : Ξ± β†’ Ξ² β†’ Ξ³) (g : Ξ³ β†’ Ξ³') (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : (kroneckerMap f A B).map g = kroneckerMap (fun a b => g (f a b)) A B := ext fun _ _ => rfl @[simp] theorem kroneckerMap_zero_left [Zero Ξ±] [Zero Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf : βˆ€ b, f 0 b = 0) (B : Matrix n p Ξ²) : kroneckerMap f (0 : Matrix l m Ξ±) B = 0 := ext fun _ _ => hf _ @[simp] theorem kroneckerMap_zero_right [Zero Ξ²] [Zero Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf : βˆ€ a, f a 0 = 0) (A : Matrix l m Ξ±) : kroneckerMap f A (0 : Matrix n p Ξ²) = 0 := ext fun _ _ => hf _ theorem kroneckerMap_add_left [Add Ξ±] [Add Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf : βˆ€ a₁ aβ‚‚ b, f (a₁ + aβ‚‚) b = f a₁ b + f aβ‚‚ b) (A₁ Aβ‚‚ : Matrix l m Ξ±) (B : Matrix n p Ξ²) : kroneckerMap f (A₁ + Aβ‚‚) B = kroneckerMap f A₁ B + kroneckerMap f Aβ‚‚ B := ext fun _ _ => hf _ _ _ theorem kroneckerMap_add_right [Add Ξ²] [Add Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf : βˆ€ a b₁ bβ‚‚, f a (b₁ + bβ‚‚) = f a b₁ + f a bβ‚‚) (A : Matrix l m Ξ±) (B₁ Bβ‚‚ : Matrix n p Ξ²) : kroneckerMap f A (B₁ + Bβ‚‚) = kroneckerMap f A B₁ + kroneckerMap f A Bβ‚‚ := ext fun _ _ => hf _ _ _ theorem kroneckerMap_smul_left [SMul R Ξ±] [SMul R Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (r : R) (hf : βˆ€ a b, f (r β€’ a) b = r β€’ f a b) (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : kroneckerMap f (r β€’ A) B = r β€’ kroneckerMap f A B := ext fun _ _ => hf _ _ theorem kroneckerMap_smul_right [SMul R Ξ²] [SMul R Ξ³] (f : Ξ± β†’ Ξ² β†’ Ξ³) (r : R) (hf : βˆ€ a b, f a (r β€’ b) = r β€’ f a b) (A : Matrix l m Ξ±) (B : Matrix n p Ξ²) : kroneckerMap f A (r β€’ B) = r β€’ kroneckerMap f A B := ext fun _ _ => hf _ _ theorem kroneckerMap_stdBasisMatrix_stdBasisMatrix [Zero Ξ±] [Zero Ξ²] [Zero Ξ³] [DecidableEq l] [DecidableEq m] [DecidableEq n] [DecidableEq p] (i₁ : l) (j₁ : m) (iβ‚‚ : n) (jβ‚‚ : p) (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf₁ : βˆ€ b, f 0 b = 0) (hfβ‚‚ : βˆ€ a, f a 0 = 0) (a : Ξ±) (b : Ξ²) : kroneckerMap f (stdBasisMatrix i₁ j₁ a) (stdBasisMatrix iβ‚‚ jβ‚‚ b) = stdBasisMatrix (i₁, iβ‚‚) (j₁, jβ‚‚) (f a b) := by ext ⟨i₁', iβ‚‚'⟩ ⟨j₁', jβ‚‚'⟩ dsimp [stdBasisMatrix] aesop theorem kroneckerMap_diagonal_diagonal [Zero Ξ±] [Zero Ξ²] [Zero Ξ³] [DecidableEq m] [DecidableEq n] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf₁ : βˆ€ b, f 0 b = 0) (hfβ‚‚ : βˆ€ a, f a 0 = 0) (a : m β†’ Ξ±) (b : n β†’ Ξ²) : kroneckerMap f (diagonal a) (diagonal b) = diagonal fun mn => f (a mn.1) (b mn.2) := by ext ⟨i₁, iβ‚‚βŸ© ⟨j₁, jβ‚‚βŸ© simp [diagonal, apply_ite f, ite_and, ite_apply, apply_ite (f (a i₁)), hf₁, hfβ‚‚] theorem kroneckerMap_diagonal_right [Zero Ξ²] [Zero Ξ³] [DecidableEq n] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf : βˆ€ a, f a 0 = 0) (A : Matrix l m Ξ±) (b : n β†’ Ξ²) : kroneckerMap f A (diagonal b) = blockDiagonal fun i => A.map fun a => f a (b i) := by ext ⟨i₁, iβ‚‚βŸ© ⟨j₁, jβ‚‚βŸ© simp [diagonal, blockDiagonal, apply_ite (f (A i₁ j₁)), hf]
Mathlib/Data/Matrix/Kronecker.lean
132
136
theorem kroneckerMap_diagonal_left [Zero Ξ±] [Zero Ξ³] [DecidableEq l] (f : Ξ± β†’ Ξ² β†’ Ξ³) (hf : βˆ€ b, f 0 b = 0) (a : l β†’ Ξ±) (B : Matrix m n Ξ²) : kroneckerMap f (diagonal a) B = Matrix.reindex (Equiv.prodComm _ _) (Equiv.prodComm _ _) (blockDiagonal fun i => B.map fun b => f (a i) b) := by
/- Copyright (c) 2023 RΓ©my Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: RΓ©my Degenne -/ import Mathlib.Probability.Kernel.Composition.MeasureComp import Mathlib.Probability.Kernel.CondDistrib import Mathlib.Probability.ConditionalProbability /-! # Kernel associated with a conditional expectation We define `condExpKernel ΞΌ m`, a kernel from `Ξ©` to `Ξ©` such that for all integrable functions `f`, `ΞΌ[f | m] =ᡐ[ΞΌ] fun Ο‰ => ∫ y, f y βˆ‚(condExpKernel ΞΌ m Ο‰)`. This kernel is defined if `Ξ©` is a standard Borel space. In general, `μ⟦s | m⟧` maps a measurable set `s` to a function `Ξ© β†’ ℝβ‰₯0∞`, and for all `s` that map is unique up to a `ΞΌ`-null set. For all `a`, the map from sets to `ℝβ‰₯0∞` that we obtain that way verifies some of the properties of a measure, but the fact that the `ΞΌ`-null set depends on `s` can prevent us from finding versions of the conditional expectation that combine into a true measure. The standard Borel space assumption on `Ξ©` allows us to do so. ## Main definitions * `condExpKernel ΞΌ m`: kernel such that `ΞΌ[f | m] =ᡐ[ΞΌ] fun Ο‰ => ∫ y, f y βˆ‚(condExpKernel ΞΌ m Ο‰)`. ## Main statements * `condExp_ae_eq_integral_condExpKernel`: `ΞΌ[f | m] =ᡐ[ΞΌ] fun Ο‰ => ∫ y, f y βˆ‚(condExpKernel ΞΌ m Ο‰)`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped ENNReal MeasureTheory ProbabilityTheory namespace ProbabilityTheory section AuxLemmas variable {Ξ© F : Type*} {m mΞ© : MeasurableSpace Ξ©} {ΞΌ : Measure Ξ©} {f : Ξ© β†’ F}
Mathlib/Probability/Kernel/Condexp.lean
44
49
theorem _root_.MeasureTheory.AEStronglyMeasurable.comp_snd_map_prod_id [TopologicalSpace F] (hm : m ≀ mΞ©) (hf : AEStronglyMeasurable f ΞΌ) : AEStronglyMeasurable[m.prod mΞ©] (fun x : Ξ© Γ— Ξ© => f x.2) (@Measure.map Ξ© (Ξ© Γ— Ξ©) mΞ© (m.prod mΞ©) (fun Ο‰ => (id Ο‰, id Ο‰)) ΞΌ) := by
rw [← aestronglyMeasurable_comp_snd_map_prodMk_iff (measurable_id'' hm)] at hf simp_rw [id] at hf ⊒
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.LocalProperties.Basic /-! # The meta properties of surjective ring homomorphisms. ## Main results Let `R` be a commutative ring, `M` be a submonoid of `R`. * `surjective_localizationPreserves` : `M⁻¹R β†’+* M⁻¹S` is surjective if `R β†’+* S` is surjective. * `surjective_ofLocalizationSpan` : `R β†’+* S` is surjective if there exists a set `{ r }` that spans `R` such that `Rα΅£ β†’+* Sα΅£` is surjective. * `surjective_localRingHom_of_surjective` : A surjective ring homomorphism `R β†’+* S` induces a surjective homomorphism `R_{f⁻¹(P)} β†’+* S_P` for every prime ideal `P` of `S`. -/ namespace RingHom open scoped TensorProduct open TensorProduct Algebra.TensorProduct universe u local notation "surjective" => fun {X Y : Type _} [CommRing X] [CommRing Y] => fun f : X β†’+* Y => Function.Surjective f
Mathlib/RingTheory/RingHom/Surjective.lean
36
45
theorem surjective_stableUnderComposition : StableUnderComposition surjective := by
introv R hf hg; exact hg.comp hf theorem surjective_respectsIso : RespectsIso surjective := by apply surjective_stableUnderComposition.respectsIso intros _ _ _ _ e exact e.surjective theorem surjective_isStableUnderBaseChange : IsStableUnderBaseChange surjective := by refine IsStableUnderBaseChange.mk _ surjective_respectsIso ?_
/- Copyright (c) 2023 Richard M. Hill. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Richard M. Hill -/ import Mathlib.RingTheory.PowerSeries.Trunc import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.Derivation.Basic /-! # Definitions In this file we define an operation `derivative` (formal differentiation) on the ring of formal power series in one variable (over an arbitrary commutative semiring). Under suitable assumptions, we prove that two power series are equal if their derivatives are equal and their constant terms are equal. This will give us a simple tool for proving power series identities. For example, one can easily prove the power series identity $\exp ( \log (1+X)) = 1+X$ by differentiating twice. ## Main Definition - `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation. This is abbreviated `d⁄dX R`. -/ namespace PowerSeries open Polynomial Derivation Nat section CommutativeSemiring variable {R} [CommSemiring R] /-- The formal derivative of a power series in one variable. This is defined here as a function, but will be packaged as a derivation `derivative` on `R⟦X⟧`. -/ noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff R (n + 1) f * (n + 1) theorem coeff_derivativeFun (f : R⟦X⟧) (n : β„•) : coeff R n f.derivativeFun = coeff R (n + 1) f * (n + 1) := by rw [derivativeFun, coeff_mk]
Mathlib/RingTheory/PowerSeries/Derivative.lean
45
47
theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by
ext rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative]
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez, Eric Wieser -/ import Mathlib.Data.List.Chain /-! # Destuttering of Lists This file proves theorems about `List.destutter` (in `Data.List.Defs`), which greedily removes all non-related items that are adjacent in a list, e.g. `[2, 2, 3, 3, 2].destutter (β‰ ) = [2, 3, 2]`. Note that we make no guarantees of being the longest sublist with this property; e.g., `[123, 1, 2, 5, 543, 1000].destutter (<) = [123, 543, 1000]`, but a longer ascending chain could be `[1, 2, 5, 543, 1000]`. ## Main statements * `List.destutter_sublist`: `l.destutter` is a sublist of `l`. * `List.destutter_is_chain'`: `l.destutter` satisfies `Chain' R`. * Analogies of these theorems for `List.destutter'`, which is the `destutter` equivalent of `Chain`. ## Tags adjacent, chain, duplicates, remove, list, stutter, destutter -/ open Function variable {Ξ± Ξ² : Type*} (l l₁ lβ‚‚ : List Ξ±) (R : Ξ± β†’ Ξ± β†’ Prop) [DecidableRel R] {a b : Ξ±} variable {Rβ‚‚ : Ξ² β†’ Ξ² β†’ Prop} [DecidableRel Rβ‚‚] namespace List @[simp] theorem destutter'_nil : destutter' R a [] = [a] := rfl theorem destutter'_cons : (b :: l).destutter' R a = if R a b then a :: destutter' R b l else destutter' R a l := rfl variable {R} @[simp] theorem destutter'_cons_pos (h : R b a) : (a :: l).destutter' R b = b :: l.destutter' R a := by rw [destutter', if_pos h] @[simp] theorem destutter'_cons_neg (h : Β¬R b a) : (a :: l).destutter' R b = l.destutter' R b := by rw [destutter', if_neg h] variable (R) @[simp] theorem destutter'_singleton : [b].destutter' R a = if R a b then [a, b] else [a] := by split_ifs with h <;> simp! [h]
Mathlib/Data/List/Destutter.lean
60
61
theorem destutter'_sublist (a) : l.destutter' R a <+ a :: l := by
induction' l with b l hl generalizing a
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson, Jalex Stark, Kyle Miller, Lu-Ming Zhang -/ import Mathlib.Combinatorics.SimpleGraph.Basic import Mathlib.Combinatorics.SimpleGraph.Connectivity.WalkCounting import Mathlib.LinearAlgebra.Matrix.Trace import Mathlib.LinearAlgebra.Matrix.Symmetric /-! # Adjacency Matrices This module defines the adjacency matrix of a graph, and provides theorems connecting graph properties to computational properties of the matrix. ## Main definitions * `Matrix.IsAdjMatrix`: `A : Matrix V V Ξ±` is qualified as an "adjacency matrix" if (1) every entry of `A` is `0` or `1`, (2) `A` is symmetric, (3) every diagonal entry of `A` is `0`. * `Matrix.IsAdjMatrix.to_graph`: for `A : Matrix V V Ξ±` and `h : A.IsAdjMatrix`, `h.to_graph` is the simple graph induced by `A`. * `Matrix.compl`: for `A : Matrix V V Ξ±`, `A.compl` is supposed to be the adjacency matrix of the complement graph of the graph induced by `A`. * `SimpleGraph.adjMatrix`: the adjacency matrix of a `SimpleGraph`. * `SimpleGraph.adjMatrix_pow_apply_eq_card_walk`: each entry of the `n`th power of a graph's adjacency matrix counts the number of length-`n` walks between the corresponding pair of vertices. -/ open Matrix open Finset Matrix SimpleGraph variable {V Ξ± : Type*} namespace Matrix /-- `A : Matrix V V Ξ±` is qualified as an "adjacency matrix" if (1) every entry of `A` is `0` or `1`, (2) `A` is symmetric, (3) every diagonal entry of `A` is `0`. -/ structure IsAdjMatrix [Zero Ξ±] [One Ξ±] (A : Matrix V V Ξ±) : Prop where zero_or_one : βˆ€ i j, A i j = 0 ∨ A i j = 1 := by aesop symm : A.IsSymm := by aesop apply_diag : βˆ€ i, A i i = 0 := by aesop namespace IsAdjMatrix variable {A : Matrix V V Ξ±} @[simp] theorem apply_diag_ne [MulZeroOneClass Ξ±] [Nontrivial Ξ±] (h : IsAdjMatrix A) (i : V) : Β¬A i i = 1 := by simp [h.apply_diag i] @[simp] theorem apply_ne_one_iff [MulZeroOneClass Ξ±] [Nontrivial Ξ±] (h : IsAdjMatrix A) (i j : V) : Β¬A i j = 1 ↔ A i j = 0 := by obtain h | h := h.zero_or_one i j <;> simp [h] @[simp] theorem apply_ne_zero_iff [MulZeroOneClass Ξ±] [Nontrivial Ξ±] (h : IsAdjMatrix A) (i j : V) : Β¬A i j = 0 ↔ A i j = 1 := by rw [← apply_ne_one_iff h, Classical.not_not] /-- For `A : Matrix V V Ξ±` and `h : IsAdjMatrix A`, `h.toGraph` is the simple graph whose adjacency matrix is `A`. -/ @[simps] def toGraph [MulZeroOneClass Ξ±] [Nontrivial Ξ±] (h : IsAdjMatrix A) : SimpleGraph V where Adj i j := A i j = 1 symm i j hij := by simp only; rwa [h.symm.apply i j] loopless i := by simp [h] instance [MulZeroOneClass Ξ±] [Nontrivial Ξ±] [DecidableEq Ξ±] (h : IsAdjMatrix A) : DecidableRel h.toGraph.Adj := by simp only [toGraph] infer_instance end IsAdjMatrix /-- For `A : Matrix V V Ξ±`, `A.compl` is supposed to be the adjacency matrix of the complement graph of the graph induced by `A.adjMatrix`. -/ def compl [Zero Ξ±] [One Ξ±] [DecidableEq Ξ±] [DecidableEq V] (A : Matrix V V Ξ±) : Matrix V V Ξ± := fun i j => ite (i = j) 0 (ite (A i j = 0) 1 0) section Compl variable [DecidableEq Ξ±] [DecidableEq V] (A : Matrix V V Ξ±) @[simp] theorem compl_apply_diag [Zero Ξ±] [One Ξ±] (i : V) : A.compl i i = 0 := by simp [compl] @[simp] theorem compl_apply [Zero Ξ±] [One Ξ±] (i j : V) : A.compl i j = 0 ∨ A.compl i j = 1 := by unfold compl split_ifs <;> simp @[simp] theorem isSymm_compl [Zero Ξ±] [One Ξ±] (h : A.IsSymm) : A.compl.IsSymm := by ext simp [compl, h.apply, eq_comm] @[simp] theorem isAdjMatrix_compl [Zero Ξ±] [One Ξ±] (h : A.IsSymm) : IsAdjMatrix A.compl := { symm := by simp [h] } namespace IsAdjMatrix variable {A} @[simp] theorem compl [Zero Ξ±] [One Ξ±] (h : IsAdjMatrix A) : IsAdjMatrix A.compl := isAdjMatrix_compl A h.symm theorem toGraph_compl_eq [MulZeroOneClass Ξ±] [Nontrivial Ξ±] (h : IsAdjMatrix A) : h.compl.toGraph = h.toGraphᢜ := by ext v w rcases h.zero_or_one v w with h | h <;> by_cases hvw : v = w <;> simp [Matrix.compl, h, hvw] end IsAdjMatrix end Compl end Matrix open Matrix namespace SimpleGraph variable (G : SimpleGraph V) [DecidableRel G.Adj] variable (Ξ±) in /-- `adjMatrix G Ξ±` is the matrix `A` such that `A i j = (1 : Ξ±)` if `i` and `j` are adjacent in the simple graph `G`, and otherwise `A i j = 0`. -/ def adjMatrix [Zero Ξ±] [One Ξ±] : Matrix V V Ξ± := of fun i j => if G.Adj i j then (1 : Ξ±) else 0 -- TODO: set as an equation lemma for `adjMatrix`, see https://github.com/leanprover-community/mathlib4/pull/3024 @[simp] theorem adjMatrix_apply (v w : V) [Zero Ξ±] [One Ξ±] : G.adjMatrix Ξ± v w = if G.Adj v w then 1 else 0 := rfl @[simp] theorem transpose_adjMatrix [Zero Ξ±] [One Ξ±] : (G.adjMatrix Ξ±)α΅€ = G.adjMatrix Ξ± := by ext simp [adj_comm] @[simp] theorem isSymm_adjMatrix [Zero Ξ±] [One Ξ±] : (G.adjMatrix Ξ±).IsSymm := transpose_adjMatrix G variable (Ξ±) /-- The adjacency matrix of `G` is an adjacency matrix. -/ @[simp] theorem isAdjMatrix_adjMatrix [Zero Ξ±] [One Ξ±] : (G.adjMatrix Ξ±).IsAdjMatrix := { zero_or_one := fun i j => by by_cases h : G.Adj i j <;> simp [h] } /-- The graph induced by the adjacency matrix of `G` is `G` itself. -/ theorem toGraph_adjMatrix_eq [MulZeroOneClass Ξ±] [Nontrivial Ξ±] : (G.isAdjMatrix_adjMatrix Ξ±).toGraph = G := by ext simp only [IsAdjMatrix.toGraph_adj, adjMatrix_apply, ite_eq_left_iff, zero_ne_one] apply Classical.not_not variable {Ξ±} /-- The sum of the identity, the adjacency matrix, and its complement is the all-ones matrix. -/ theorem one_add_adjMatrix_add_compl_adjMatrix_eq_allOnes [DecidableEq V] [DecidableEq Ξ±] [AddMonoidWithOne Ξ±] : 1 + G.adjMatrix Ξ± + (G.adjMatrix Ξ±).compl = Matrix.of fun _ _ ↦ 1 := by ext i j unfold Matrix.compl rw [of_apply, add_apply, adjMatrix_apply, add_apply, adjMatrix_apply, one_apply] by_cases h : G.Adj i j Β· aesop Β· split_ifs <;> simp_all variable [Fintype V] @[simp] theorem adjMatrix_dotProduct [NonAssocSemiring Ξ±] (v : V) (vec : V β†’ Ξ±) : dotProduct (G.adjMatrix Ξ± v) vec = βˆ‘ u ∈ G.neighborFinset v, vec u := by simp [neighborFinset_eq_filter, dotProduct, sum_filter] @[simp] theorem dotProduct_adjMatrix [NonAssocSemiring Ξ±] (v : V) (vec : V β†’ Ξ±) : dotProduct vec (G.adjMatrix Ξ± v) = βˆ‘ u ∈ G.neighborFinset v, vec u := by simp [neighborFinset_eq_filter, dotProduct, sum_filter, Finset.sum_apply] @[simp] theorem adjMatrix_mulVec_apply [NonAssocSemiring Ξ±] (v : V) (vec : V β†’ Ξ±) : (G.adjMatrix Ξ± *α΅₯ vec) v = βˆ‘ u ∈ G.neighborFinset v, vec u := by rw [mulVec, adjMatrix_dotProduct] @[simp] theorem adjMatrix_vecMul_apply [NonAssocSemiring Ξ±] (v : V) (vec : V β†’ Ξ±) : (vec α΅₯* G.adjMatrix Ξ±) v = βˆ‘ u ∈ G.neighborFinset v, vec u := by simp only [← dotProduct_adjMatrix, vecMul] refine congr rfl ?_; ext x rw [← transpose_apply (adjMatrix Ξ± G) x v, transpose_adjMatrix] @[simp]
Mathlib/Combinatorics/SimpleGraph/AdjMatrix.lean
210
212
theorem adjMatrix_mul_apply [NonAssocSemiring Ξ±] (M : Matrix V V Ξ±) (v w : V) : (G.adjMatrix Ξ± * M) v w = βˆ‘ u ∈ G.neighborFinset v, M u w := by
simp [mul_apply, neighborFinset_eq_filter, sum_filter]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, SΓ©bastien GouΓ«zel, RΓ©my Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Complex import Qq /-! # Power function on `ℝ` We construct the power functions `x ^ y`, where `x` and `y` are real numbers. -/ noncomputable section open Real ComplexConjugate Finset Set /- ## Definitions -/ namespace Real variable {x y z : ℝ} /-- The real power function `x ^ y`, defined as the real part of the complex power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0=1` and `0 ^ y=0` for `y β‰  0`. For `x < 0`, the definition is somewhat arbitrary as it depends on the choice of a complex determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (Ο€ y)`. -/ noncomputable def rpow (x y : ℝ) := ((x : β„‚) ^ (y : β„‚)).re noncomputable instance : Pow ℝ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl theorem rpow_def (x y : ℝ) : x ^ y = ((x : β„‚) ^ (y : β„‚)).re := rfl theorem rpow_def_of_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := by simp only [rpow_def, Complex.cpow_def]; split_ifs <;> simp_all [(Complex.ofReal_log hx).symm, -Complex.ofReal_mul, (Complex.ofReal_mul _ _).symm, Complex.exp_ofReal_re, Complex.ofReal_eq_zero] theorem rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) := by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)] theorem exp_mul (x y : ℝ) : exp (x * y) = exp x ^ y := by rw [rpow_def_of_pos (exp_pos _), log_exp] @[simp, norm_cast] theorem rpow_intCast (x : ℝ) (n : β„€) : x ^ (n : ℝ) = x ^ n := by simp only [rpow_def, ← Complex.ofReal_zpow, Complex.cpow_intCast, Complex.ofReal_intCast, Complex.ofReal_re] @[simp, norm_cast] theorem rpow_natCast (x : ℝ) (n : β„•) : x ^ (n : ℝ) = x ^ n := by simpa using rpow_intCast x n @[simp] theorem exp_one_rpow (x : ℝ) : exp 1 ^ x = exp x := by rw [← exp_mul, one_mul] @[simp] lemma exp_one_pow (n : β„•) : exp 1 ^ n = exp n := by rw [← rpow_natCast, exp_one_rpow] theorem rpow_eq_zero_iff_of_nonneg (hx : 0 ≀ x) : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by simp only [rpow_def_of_nonneg hx] split_ifs <;> simp [*, exp_ne_zero] @[simp] lemma rpow_eq_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [rpow_eq_zero_iff_of_nonneg, *] @[simp] lemma rpow_ne_zero (hx : 0 ≀ x) (hy : y β‰  0) : x ^ y β‰  0 ↔ x β‰  0 := Real.rpow_eq_zero hx hy |>.not open Real theorem rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * Ο€) := by rw [rpow_def, Complex.cpow_def, if_neg] Β· have : Complex.log x * y = ↑(log (-x) * y) + ↑(y * Ο€) * Complex.I := by simp only [Complex.log, Complex.norm_real, norm_eq_abs, abs_of_neg hx, log_neg_eq_log, Complex.arg_ofReal_of_neg hx, Complex.ofReal_mul] ring rw [this, Complex.exp_add_mul_I, ← Complex.ofReal_exp, ← Complex.ofReal_cos, ← Complex.ofReal_sin, mul_add, ← Complex.ofReal_mul, ← mul_assoc, ← Complex.ofReal_mul, Complex.add_re, Complex.ofReal_re, Complex.mul_re, Complex.I_re, Complex.ofReal_im, Real.log_neg_eq_log] ring Β· rw [Complex.ofReal_eq_zero] exact ne_of_lt hx theorem rpow_def_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : ℝ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) * cos (y * Ο€) := by split_ifs with h <;> simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _ @[bound] theorem rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y := by rw [rpow_def_of_pos hx]; apply exp_pos @[simp] theorem rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def] theorem rpow_zero_pos (x : ℝ) : 0 < x ^ (0 : ℝ) := by simp @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝ) ^ x = 0 := by simp [rpow_def, *] theorem zero_rpow_eq_iff {x : ℝ} {a : ℝ} : 0 ^ x = a ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor Β· intro hyp simp only [rpow_def, Complex.ofReal_zero] at hyp by_cases h : x = 0 Β· subst h simp only [Complex.one_re, Complex.ofReal_zero, Complex.cpow_zero] at hyp exact Or.inr ⟨rfl, hyp.symm⟩ Β· rw [Complex.zero_cpow (Complex.ofReal_ne_zero.mpr h)] at hyp exact Or.inl ⟨h, hyp.symm⟩ Β· rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) Β· exact zero_rpow h Β· exact rpow_zero _ theorem eq_zero_rpow_iff {x : ℝ} {a : ℝ} : a = 0 ^ x ↔ x β‰  0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_rpow_eq_iff, eq_comm] @[simp] theorem rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def] theorem zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≀ 1 := by by_cases h : x = 0 <;> simp [h, zero_le_one] theorem zero_rpow_nonneg (x : ℝ) : 0 ≀ (0 : ℝ) ^ x := by by_cases h : x = 0 <;> simp [h, zero_le_one] @[bound] theorem rpow_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : 0 ≀ x ^ y := by rw [rpow_def_of_nonneg hx]; split_ifs <;> simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)] theorem abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : |x ^ y| = |x| ^ y := by have h_rpow_nonneg : 0 ≀ x ^ y := Real.rpow_nonneg hx_nonneg _ rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg] @[bound] theorem abs_rpow_le_abs_rpow (x y : ℝ) : |x ^ y| ≀ |x| ^ y := by rcases le_or_lt 0 x with hx | hx Β· rw [abs_rpow_of_nonneg hx] Β· rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log, abs_mul, abs_of_pos (exp_pos _)] exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) theorem abs_rpow_le_exp_log_mul (x y : ℝ) : |x ^ y| ≀ exp (log x * y) := by refine (abs_rpow_le_abs_rpow x y).trans ?_ by_cases hx : x = 0 Β· by_cases hy : y = 0 <;> simp [hx, hy, zero_le_one] Β· rw [rpow_def_of_pos (abs_pos.2 hx), log_abs] lemma rpow_inv_log (hxβ‚€ : 0 < x) (hx₁ : x β‰  1) : x ^ (log x)⁻¹ = exp 1 := by rw [rpow_def_of_pos hxβ‚€, mul_inv_cancelβ‚€] exact log_ne_zero.2 ⟨hxβ‚€.ne', hx₁, (hxβ‚€.trans' <| by norm_num).ne'⟩ /-- See `Real.rpow_inv_log` for the equality when `x β‰  1` is strictly positive. -/ lemma rpow_inv_log_le_exp_one : x ^ (log x)⁻¹ ≀ exp 1 := by calc _ ≀ |x ^ (log x)⁻¹| := le_abs_self _ _ ≀ |x| ^ (log x)⁻¹ := abs_rpow_le_abs_rpow .. rw [← log_abs] obtain hx | hx := (abs_nonneg x).eq_or_gt Β· simp [hx] Β· rw [rpow_def_of_pos hx] gcongr exact mul_inv_le_one theorem norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≀ x) : β€–x ^ yβ€– = β€–xβ€– ^ y := by simp_rw [Real.norm_eq_abs] exact abs_rpow_of_nonneg hx_nonneg variable {w x y z : ℝ} theorem rpow_add (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := by simp only [rpow_def_of_pos hx, mul_add, exp_add] theorem rpow_add' (hx : 0 ≀ x) (h : y + z β‰  0) : x ^ (y + z) = x ^ y * x ^ z := by rcases hx.eq_or_lt with (rfl | pos) Β· rw [zero_rpow h, zero_eq_mul] have : y β‰  0 ∨ z β‰  0 := not_and_or.1 fun ⟨hy, hz⟩ => h <| hy.symm β–Έ hz.symm β–Έ zero_add 0 exact this.imp zero_rpow zero_rpow Β· exact rpow_add pos _ _ /-- Variant of `Real.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (hx : 0 ≀ x) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add' hx]; rwa [h] theorem rpow_add_of_nonneg (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by rcases hy.eq_or_lt with (rfl | hy) Β· rw [zero_add, rpow_zero, one_mul] exact rpow_add' hx (ne_of_gt <| add_pos_of_pos_of_nonneg hy hz) /-- For `0 ≀ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for `x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish. The inequality is always true, though, and given in this lemma. -/ theorem le_rpow_add {x : ℝ} (hx : 0 ≀ x) (y z : ℝ) : x ^ y * x ^ z ≀ x ^ (y + z) := by rcases le_iff_eq_or_lt.1 hx with (H | pos) Β· by_cases h : y + z = 0 Β· simp only [H.symm, h, rpow_zero] calc (0 : ℝ) ^ y * 0 ^ z ≀ 1 * 1 := mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one _ = 1 := by simp Β· simp [rpow_add', ← H, h] Β· simp [rpow_add pos] theorem rpow_sum_of_pos {ΞΉ : Type*} {a : ℝ} (ha : 0 < a) (f : ΞΉ β†’ ℝ) (s : Finset ΞΉ) : (a ^ βˆ‘ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := map_sum (⟨⟨fun (x : ℝ) => (a ^ x : ℝ), rpow_zero a⟩, rpow_add ha⟩ : ℝ β†’+ (Additive ℝ)) f s theorem rpow_sum_of_nonneg {ΞΉ : Type*} {a : ℝ} (ha : 0 ≀ a) {s : Finset ΞΉ} {f : ΞΉ β†’ ℝ} (h : βˆ€ x ∈ s, 0 ≀ f x) : (a ^ βˆ‘ x ∈ s, f x) = ∏ x ∈ s, a ^ f x := by induction' s using Finset.cons_induction with i s hi ihs Β· rw [sum_empty, Finset.prod_empty, rpow_zero] Β· rw [forall_mem_cons] at h rw [sum_cons, prod_cons, ← ihs h.2, rpow_add_of_nonneg ha h.1 (sum_nonneg h.2)] theorem rpow_neg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [rpow_def_of_nonneg hx]; split_ifs <;> simp_all [exp_neg] theorem rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv] theorem rpow_sub' {x : ℝ} (hx : 0 ≀ x) {y z : ℝ} (h : y - z β‰  0) : x ^ (y - z) = x ^ y / x ^ z := by simp only [sub_eq_add_neg] at h ⊒ simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] protected theorem _root_.HasCompactSupport.rpow_const {Ξ± : Type*} [TopologicalSpace Ξ±] {f : Ξ± β†’ ℝ} (hf : HasCompactSupport f) {r : ℝ} (hr : r β‰  0) : HasCompactSupport (fun x ↦ f x ^ r) := hf.comp_left (g := (Β· ^ r)) (Real.zero_rpow hr) end Real /-! ## Comparing real and complex powers -/ namespace Complex theorem ofReal_cpow {x : ℝ} (hx : 0 ≀ x) (y : ℝ) : ((x ^ y : ℝ) : β„‚) = (x : β„‚) ^ (y : β„‚) := by simp only [Real.rpow_def_of_nonneg hx, Complex.cpow_def, ofReal_eq_zero]; split_ifs <;> simp [Complex.ofReal_log hx] theorem ofReal_cpow_of_nonpos {x : ℝ} (hx : x ≀ 0) (y : β„‚) : (x : β„‚) ^ y = (-x : β„‚) ^ y * exp (Ο€ * I * y) := by rcases hx.eq_or_lt with (rfl | hlt) Β· rcases eq_or_ne y 0 with (rfl | hy) <;> simp [*] have hne : (x : β„‚) β‰  0 := ofReal_ne_zero.mpr hlt.ne rw [cpow_def_of_ne_zero hne, cpow_def_of_ne_zero (neg_ne_zero.2 hne), ← exp_add, ← add_mul, log, log, norm_neg, arg_ofReal_of_neg hlt, ← ofReal_neg, arg_ofReal_of_nonneg (neg_nonneg.2 hx), ofReal_zero, zero_mul, add_zero] lemma cpow_ofReal (x : β„‚) (y : ℝ) : x ^ (y : β„‚) = ↑(β€–xβ€– ^ y) * (Real.cos (arg x * y) + Real.sin (arg x * y) * I) := by rcases eq_or_ne x 0 with rfl | hx Β· simp [ofReal_cpow le_rfl] Β· rw [cpow_def_of_ne_zero hx, exp_eq_exp_re_mul_sin_add_cos, mul_comm (log x)] norm_cast rw [re_ofReal_mul, im_ofReal_mul, log_re, log_im, mul_comm y, mul_comm y, Real.exp_mul, Real.exp_log] rwa [norm_pos_iff] lemma cpow_ofReal_re (x : β„‚) (y : ℝ) : (x ^ (y : β„‚)).re = β€–xβ€– ^ y * Real.cos (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.cos] lemma cpow_ofReal_im (x : β„‚) (y : ℝ) : (x ^ (y : β„‚)).im = β€–xβ€– ^ y * Real.sin (arg x * y) := by rw [cpow_ofReal]; generalize arg x * y = z; simp [Real.sin] theorem norm_cpow_of_ne_zero {z : β„‚} (hz : z β‰  0) (w : β„‚) : β€–z ^ wβ€– = β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by rw [cpow_def_of_ne_zero hz, norm_exp, mul_re, log_re, log_im, Real.exp_sub, Real.rpow_def_of_pos (norm_pos_iff.mpr hz)] theorem norm_cpow_of_imp {z w : β„‚} (h : z = 0 β†’ w.re = 0 β†’ w = 0) : β€–z ^ wβ€– = β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by rcases ne_or_eq z 0 with (hz | rfl) <;> [exact norm_cpow_of_ne_zero hz w; rw [norm_zero]] rcases eq_or_ne w.re 0 with hw | hw Β· simp [hw, h rfl hw] Β· rw [Real.zero_rpow hw, zero_div, zero_cpow, norm_zero] exact ne_of_apply_ne re hw theorem norm_cpow_le (z w : β„‚) : β€–z ^ wβ€– ≀ β€–zβ€– ^ w.re / Real.exp (arg z * im w) := by by_cases h : z = 0 β†’ w.re = 0 β†’ w = 0 Β· exact (norm_cpow_of_imp h).le Β· push_neg at h simp [h] @[simp] theorem norm_cpow_real (x : β„‚) (y : ℝ) : β€–x ^ (y : β„‚)β€– = β€–xβ€– ^ y := by rw [norm_cpow_of_imp] <;> simp @[simp] theorem norm_cpow_inv_nat (x : β„‚) (n : β„•) : β€–x ^ (n⁻¹ : β„‚)β€– = β€–xβ€– ^ (n⁻¹ : ℝ) := by rw [← norm_cpow_real]; simp theorem norm_cpow_eq_rpow_re_of_pos {x : ℝ} (hx : 0 < x) (y : β„‚) : β€–(x : β„‚) ^ yβ€– = x ^ y.re := by rw [norm_cpow_of_ne_zero (ofReal_ne_zero.mpr hx.ne'), arg_ofReal_of_nonneg hx.le, zero_mul, Real.exp_zero, div_one, Complex.norm_of_nonneg hx.le] theorem norm_cpow_eq_rpow_re_of_nonneg {x : ℝ} (hx : 0 ≀ x) {y : β„‚} (hy : re y β‰  0) : β€–(x : β„‚) ^ yβ€– = x ^ re y := by rw [norm_cpow_of_imp] <;> simp [*, arg_ofReal_of_nonneg, abs_of_nonneg] @[deprecated (since := "2025-02-17")] alias abs_cpow_of_ne_zero := norm_cpow_of_ne_zero @[deprecated (since := "2025-02-17")] alias abs_cpow_of_imp := norm_cpow_of_imp @[deprecated (since := "2025-02-17")] alias abs_cpow_le := norm_cpow_le @[deprecated (since := "2025-02-17")] alias abs_cpow_real := norm_cpow_real @[deprecated (since := "2025-02-17")] alias abs_cpow_inv_nat := norm_cpow_inv_nat @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_pos := norm_cpow_eq_rpow_re_of_pos @[deprecated (since := "2025-02-17")] alias abs_cpow_eq_rpow_re_of_nonneg := norm_cpow_eq_rpow_re_of_nonneg open Filter in lemma norm_ofReal_cpow_eventually_eq_atTop (c : β„‚) : (fun t : ℝ ↦ β€–(t : β„‚) ^ cβ€–) =αΆ [atTop] fun t ↦ t ^ c.re := by filter_upwards [eventually_gt_atTop 0] with t ht rw [norm_cpow_eq_rpow_re_of_pos ht] lemma norm_natCast_cpow_of_re_ne_zero (n : β„•) {s : β„‚} (hs : s.re β‰  0) : β€–(n : β„‚) ^ sβ€– = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_nonneg n.cast_nonneg hs] lemma norm_natCast_cpow_of_pos {n : β„•} (hn : 0 < n) (s : β„‚) : β€–(n : β„‚) ^ sβ€– = (n : ℝ) ^ (s.re) := by rw [← ofReal_natCast, norm_cpow_eq_rpow_re_of_pos (Nat.cast_pos.mpr hn) _] lemma norm_natCast_cpow_pos_of_pos {n : β„•} (hn : 0 < n) (s : β„‚) : 0 < β€–(n : β„‚) ^ sβ€– := (norm_natCast_cpow_of_pos hn _).symm β–Έ Real.rpow_pos_of_pos (Nat.cast_pos.mpr hn) _ theorem cpow_mul_ofReal_nonneg {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (z : β„‚) : (x : β„‚) ^ (↑y * z) = (↑(x ^ y) : β„‚) ^ z := by rw [cpow_mul, ofReal_cpow hx] Β· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im, neg_lt_zero]; exact Real.pi_pos Β· rw [← ofReal_log hx, ← ofReal_mul, ofReal_im]; exact Real.pi_pos.le end Complex /-! ### Positivity extension -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: exponentiation by a real number is positive (namely 1) when the exponent is zero. The other cases are done in `evalRpow`. -/ @[positivity (_ : ℝ) ^ (0 : ℝ)] def evalRpowZero : PositivityExt where eval {u Ξ±} _ _ e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q($a ^ (0 : ℝ)) => assertInstancesCommute pure (.positive q(Real.rpow_zero_pos $a)) | _, _, _ => throwError "not Real.rpow" /-- Extension for the `positivity` tactic: exponentiation by a real number is nonnegative when the base is nonnegative and positive when the base is positive. -/ @[positivity (_ : ℝ) ^ (_ : ℝ)] def evalRpow : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q($a ^ ($b : ℝ)) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure (.positive q(Real.rpow_pos_of_pos $pa $b)) | .nonnegative pa => pure (.nonnegative q(Real.rpow_nonneg $pa $b)) | _ => pure .none | _, _, _ => throwError "not Real.rpow" end Mathlib.Meta.Positivity /-! ## Further algebraic properties of `rpow` -/ namespace Real variable {x y z : ℝ} {n : β„•} theorem rpow_mul {x : ℝ} (hx : 0 ≀ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by rw [← Complex.ofReal_inj, Complex.ofReal_cpow (rpow_nonneg hx _), Complex.ofReal_cpow hx, Complex.ofReal_mul, Complex.cpow_mul, Complex.ofReal_cpow hx] <;> simp only [(Complex.ofReal_mul _ _).symm, (Complex.ofReal_log hx).symm, Complex.ofReal_im, neg_lt_zero, pi_pos, le_of_lt pi_pos] lemma rpow_pow_comm {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (n : β„•) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_natCast, ← rpow_mul hx, mul_comm y] lemma rpow_zpow_comm {x : ℝ} (hx : 0 ≀ x) (y : ℝ) (n : β„€) : (x ^ y) ^ n = (x ^ n) ^ y := by simp_rw [← rpow_intCast, ← rpow_mul hx, mul_comm y] lemma rpow_add_intCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_def, rpow_def, Complex.ofReal_add, Complex.cpow_add _ _ (Complex.ofReal_ne_zero.mpr hx), Complex.ofReal_intCast, Complex.cpow_intCast, ← Complex.ofReal_zpow, mul_comm, Complex.re_ofReal_mul, mul_comm] lemma rpow_add_natCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by simpa using rpow_add_intCast hx y n lemma rpow_sub_intCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_add_intCast hx y (-n) lemma rpow_sub_natCast {x : ℝ} (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by simpa using rpow_sub_intCast hx y n lemma rpow_add_intCast' (hx : 0 ≀ x) {n : β„€} (h : y + n β‰  0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_intCast] lemma rpow_add_natCast' (hx : 0 ≀ x) (h : y + n β‰  0) : x ^ (y + n) = x ^ y * x ^ n := by rw [rpow_add' hx h, rpow_natCast] lemma rpow_sub_intCast' (hx : 0 ≀ x) {n : β„€} (h : y - n β‰  0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_intCast] lemma rpow_sub_natCast' (hx : 0 ≀ x) (h : y - n β‰  0) : x ^ (y - n) = x ^ y / x ^ n := by rw [rpow_sub' hx h, rpow_natCast] theorem rpow_add_one {x : ℝ} (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 theorem rpow_sub_one {x : ℝ} (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (hx : 0 ≀ x) (h : y + 1 β‰  0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' hx h, rpow_one] lemma rpow_one_add' (hx : 0 ≀ x) (h : 1 + y β‰  0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' hx h, rpow_one] lemma rpow_sub_one' (hx : 0 ≀ x) (h : y - 1 β‰  0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' hx h, rpow_one] lemma rpow_one_sub' (hx : 0 ≀ x) (h : 1 - y β‰  0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' hx h, rpow_one] @[simp] theorem rpow_two (x : ℝ) : x ^ (2 : ℝ) = x ^ 2 := by rw [← rpow_natCast] simp only [Nat.cast_ofNat] theorem rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ := by suffices H : x ^ ((-1 : β„€) : ℝ) = x⁻¹ by rwa [Int.cast_neg, Int.cast_one] at H simp only [rpow_intCast, zpow_one, zpow_neg] theorem mul_rpow (hx : 0 ≀ x) (hy : 0 ≀ y) : (x * y) ^ z = x ^ z * y ^ z := by iterate 2 rw [Real.rpow_def_of_nonneg]; split_ifs with h_ifs <;> simp_all Β· rw [log_mul β€Ή_β€Ί β€Ή_β€Ί, add_mul, exp_add, rpow_def_of_pos (hy.lt_of_ne' β€Ή_β€Ί)] all_goals positivity theorem inv_rpow (hx : 0 ≀ x) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by simp only [← rpow_neg_one, ← rpow_mul hx, mul_comm] theorem div_rpow (hx : 0 ≀ x) (hy : 0 ≀ y) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy] theorem log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x ^ y) = y * log x := by apply exp_injective rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y] theorem mul_log_eq_log_iff {x y z : ℝ} (hx : 0 < x) (hz : 0 < z) : y * log x = log z ↔ x ^ y = z := ⟨fun h ↦ log_injOn_pos (rpow_pos_of_pos hx _) hz <| log_rpow hx _ |>.trans h, by rintro rfl; rw [log_rpow hx]⟩ @[simp] lemma rpow_rpow_inv (hx : 0 ≀ x) (hy : y β‰  0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul hx, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow (hx : 0 ≀ x) (hy : y β‰  0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul hx, inv_mul_cancelβ‚€ hy, rpow_one] theorem pow_rpow_inv_natCast (hx : 0 ≀ x) (hn : n β‰  0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by have hn0 : (n : ℝ) β‰  0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, mul_inv_cancelβ‚€ hn0, rpow_one] theorem rpow_inv_natCast_pow (hx : 0 ≀ x) (hn : n β‰  0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by have hn0 : (n : ℝ) β‰  0 := Nat.cast_ne_zero.2 hn rw [← rpow_natCast, ← rpow_mul hx, inv_mul_cancelβ‚€ hn0, rpow_one] lemma rpow_natCast_mul (hx : 0 ≀ x) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_natCast] lemma rpow_mul_natCast (hx : 0 ≀ x) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_natCast] lemma rpow_intCast_mul (hx : 0 ≀ x) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul hx, rpow_intCast] lemma rpow_mul_intCast (hx : 0 ≀ x) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul hx, rpow_intCast] /-! Note: lemmas about `(∏ i ∈ s, f i ^ r)` such as `Real.finset_prod_rpow` are proved in `Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean` instead. -/ /-! ## Order and monotonicity -/ @[gcongr, bound] theorem rpow_lt_rpow (hx : 0 ≀ x) (hxy : x < y) (hz : 0 < z) : x ^ z < y ^ z := by rw [le_iff_eq_or_lt] at hx; rcases hx with hx | hx Β· rw [← hx, zero_rpow (ne_of_gt hz)] exact rpow_pos_of_pos (by rwa [← hx] at hxy) _ Β· rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp] exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz theorem strictMonoOn_rpow_Ici_of_exponent_pos {r : ℝ} (hr : 0 < r) : StrictMonoOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_lt_rpow ha hab hr @[gcongr, bound] theorem rpow_le_rpow {x y z : ℝ} (h : 0 ≀ x) (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := by rcases eq_or_lt_of_le h₁ with (rfl | h₁'); Β· rfl rcases eq_or_lt_of_le hβ‚‚ with (rfl | hβ‚‚'); Β· simp exact le_of_lt (rpow_lt_rpow h h₁' hβ‚‚') theorem monotoneOn_rpow_Ici_of_exponent_nonneg {r : ℝ} (hr : 0 ≀ r) : MonotoneOn (fun (x : ℝ) => x ^ r) (Set.Ici 0) := fun _ ha _ _ hab => rpow_le_rpow ha hab hr lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := by have := hx.trans hxy rw [← inv_lt_invβ‚€, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_lt_rpow ?_ hxy (neg_pos.2 hz) all_goals positivity lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := by have := hx.trans_le hxy rw [← inv_le_invβ‚€, ← rpow_neg, ← rpow_neg] on_goal 1 => refine rpow_le_rpow ?_ hxy (neg_nonneg.2 hz) all_goals positivity theorem rpow_lt_rpow_iff (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := ⟨lt_imp_lt_of_le_imp_le fun h => rpow_le_rpow hy h (le_of_lt hz), fun h => rpow_lt_rpow hx h hz⟩ theorem rpow_le_rpow_iff (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff hy hx hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := ⟨lt_imp_lt_of_le_imp_le fun h ↦ rpow_le_rpow_of_nonpos hx h hz.le, fun h ↦ rpow_lt_rpow_of_neg hy h hz⟩ lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := le_iff_le_iff_lt_iff_lt.2 <| rpow_lt_rpow_iff_of_neg hy hx hz lemma le_rpow_inv_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hx _ hz, rpow_inv_rpow] <;> positivity lemma rpow_inv_le_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff _ hy hz, rpow_inv_rpow] <;> positivity lemma lt_rpow_inv_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := lt_iff_lt_of_le_iff_le <| rpow_inv_le_iff_of_pos hy hx hz lemma rpow_inv_lt_iff_of_pos (hx : 0 ≀ x) (hy : 0 ≀ y) (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := lt_iff_lt_of_le_iff_le <| le_rpow_inv_iff_of_pos hy hx hz theorem le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := by rw [← rpow_le_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := by rw [← rpow_lt_rpow_iff_of_neg _ hx hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := by rw [← rpow_lt_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := by rw [← rpow_le_rpow_iff_of_neg hy _ hz, rpow_inv_rpow _ hz.ne] <;> positivity theorem rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos (lt_trans zero_lt_one hx)] rw [exp_lt_exp]; exact mul_lt_mul_of_pos_left hyz (log_pos hx) @[gcongr] theorem rpow_le_rpow_of_exponent_le (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := by repeat' rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)] rw [exp_le_exp]; exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx) theorem rpow_lt_rpow_of_exponent_neg {x y z : ℝ} (hy : 0 < y) (hxy : y < x) (hz : z < 0) : x ^ z < y ^ z := by have hx : 0 < x := hy.trans hxy rw [← neg_neg z, Real.rpow_neg (le_of_lt hx) (-z), Real.rpow_neg (le_of_lt hy) (-z), inv_lt_invβ‚€ (rpow_pos_of_pos hx _) (rpow_pos_of_pos hy _)] exact Real.rpow_lt_rpow (by positivity) hxy <| neg_pos_of_neg hz theorem strictAntiOn_rpow_Ioi_of_exponent_neg {r : ℝ} (hr : r < 0) : StrictAntiOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_lt_rpow_of_exponent_neg ha hab hr theorem rpow_le_rpow_of_exponent_nonpos {x y : ℝ} (hy : 0 < y) (hxy : y ≀ x) (hz : z ≀ 0) : x ^ z ≀ y ^ z := by rcases ne_or_eq z 0 with hz_zero | rfl case inl => rcases ne_or_eq x y with hxy' | rfl case inl => exact le_of_lt <| rpow_lt_rpow_of_exponent_neg hy (Ne.lt_of_le (id (Ne.symm hxy')) hxy) (Ne.lt_of_le hz_zero hz) case inr => simp case inr => simp theorem antitoneOn_rpow_Ioi_of_exponent_nonpos {r : ℝ} (hr : r ≀ 0) : AntitoneOn (fun (x : ℝ) => x ^ r) (Set.Ioi 0) := fun _ ha _ _ hab => rpow_le_rpow_of_exponent_nonpos ha hab hr @[simp] theorem rpow_le_rpow_left_iff (hx : 1 < x) : x ^ y ≀ x ^ z ↔ y ≀ z := by have x_pos : 0 < x := lt_trans zero_lt_one hx rw [← log_le_log_iff (rpow_pos_of_pos x_pos y) (rpow_pos_of_pos x_pos z), log_rpow x_pos, log_rpow x_pos, mul_le_mul_right (log_pos hx)] @[simp] theorem rpow_lt_rpow_left_iff (hx : 1 < x) : x ^ y < x ^ z ↔ y < z := by rw [lt_iff_not_le, rpow_le_rpow_left_iff hx, lt_iff_not_le] theorem rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_lt_exp]; exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1) theorem rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := by repeat' rw [rpow_def_of_pos hx0] rw [exp_le_exp]; exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1) @[simp] theorem rpow_le_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y ≀ x ^ z ↔ z ≀ y := by rw [← log_le_log_iff (rpow_pos_of_pos hx0 y) (rpow_pos_of_pos hx0 z), log_rpow hx0, log_rpow hx0, mul_le_mul_right_of_neg (log_neg hx0 hx1)] @[simp] theorem rpow_lt_rpow_left_iff_of_base_lt_one (hx0 : 0 < x) (hx1 : x < 1) : x ^ y < x ^ z ↔ z < y := by rw [lt_iff_not_le, rpow_le_rpow_left_iff_of_base_lt_one hx0 hx1, lt_iff_not_le] theorem rpow_lt_one {x z : ℝ} (hx1 : 0 ≀ x) (hx2 : x < 1) (hz : 0 < z) : x ^ z < 1 := by rw [← one_rpow z] exact rpow_lt_rpow hx1 hx2 hz theorem rpow_le_one {x z : ℝ} (hx1 : 0 ≀ x) (hx2 : x ≀ 1) (hz : 0 ≀ z) : x ^ z ≀ 1 := by rw [← one_rpow z] exact rpow_le_rpow hx1 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := by convert rpow_lt_rpow_of_exponent_lt hx hz exact (rpow_zero x).symm
Mathlib/Analysis/SpecialFunctions/Pow/Real.lean
663
666
theorem rpow_le_one_of_one_le_of_nonpos {x z : ℝ} (hx : 1 ≀ x) (hz : z ≀ 0) : x ^ z ≀ 1 := by
convert rpow_le_rpow_of_exponent_le hx hz exact (rpow_zero x).symm
/- 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.SetTheory.Cardinal.Finite import Mathlib.Data.Set.Finite.Powerset /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : β„•βˆž` and a term `Set.ncard s : β„•`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `Ξ±` with `[Finite Ξ±]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊀` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set Ξ±` where there is a `Finite Ξ±` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {Ξ± Ξ² : Type*} {s t : Set Ξ±} /-- The cardinality of a set as a term in `β„•βˆž` -/ noncomputable def encard (s : Set Ξ±) : β„•βˆž := ENat.card s @[simp] theorem encard_univ_coe (s : Set Ξ±) : encard (univ : Set s) = encard s := by rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (Ξ± : Type*) : encard (univ : Set Ξ±) = ENat.card Ξ± := by rw [encard, ENat.card_congr (Equiv.Set.univ Ξ±)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set Ξ±) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] @[simp] theorem toENat_cardinalMk (s : Set Ξ±) : (Cardinal.mk s).toENat = s.encard := rfl theorem toENat_cardinalMk_subtype (P : Ξ± β†’ Prop) : (Cardinal.mk {x // P x}).toENat = {x | P x}.encard := rfl @[simp] theorem coe_fintypeCard (s : Set Ξ±) [Fintype s] : Fintype.card s = s.encard := by simp [encard_eq_coe_toFinset_card] @[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset Ξ±) : encard (s : Set Ξ±) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp @[simp] theorem Infinite.encard_eq {s : Set Ξ±} (h : s.Infinite) : s.encard = ⊀ := by have := h.to_subtype rw [encard, ENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = βˆ… := by rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (βˆ… : Set Ξ±).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard β‰  0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard β‰  0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos @[simp] theorem encard_singleton (e : Ξ±) : ({e} : Set Ξ±).encard = 1 := by rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one] theorem encard_union_eq (h : Disjoint s t) : (s βˆͺ t).encard = s.encard + t.encard := by classical simp [encard, ENat.card_congr (Equiv.Set.union h)] theorem encard_insert_of_not_mem {a : Ξ±} (has : a βˆ‰ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊀ := by induction s, h using Set.Finite.induction_on with | empty => simp | insert hat _ ht' => rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : βˆƒ (n : β„•), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊀ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊀ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff theorem encard_ne_top_iff : s.encard β‰  ⊀ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : β„•} (h : s.encard ≀ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : β„•} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : β„•} : s.encard ≀ k ↔ s.Finite ∧ βˆƒ (nβ‚€ : β„•), s.encard = nβ‚€ ∧ nβ‚€ ≀ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨nβ‚€,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ @[simp] theorem encard_prod : (s Γ—Λ’ t).encard = s.encard * t.encard := by simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)] section Lattice theorem encard_le_encard (h : s βŠ† t) : s.encard ≀ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add @[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard theorem encard_mono {Ξ± : Type*} : Monotone (encard : Set Ξ± β†’ β„•βˆž) := fun _ _ ↦ encard_le_encard theorem encard_diff_add_encard_of_subset (h : s βŠ† t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≀ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set Ξ±) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set Ξ±) : (s βˆͺ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_inj h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≀ t.encard ↔ (s \ t).encard ≀ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set Ξ±) : (s βˆͺ t).encard ≀ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set Ξ±} {t : Set Ξ²} (hs : s.Finite) (h : t.encard ≀ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s βŠ† t) (hts : t.encard ≀ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s βŠ† t) (hts : t.encard ≀ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts theorem Finite.encard_lt_encard (hs : s.Finite) (h : s βŠ‚ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le) theorem encard_strictMono [Finite Ξ±] : StrictMono (encard : Set Ξ± β†’ β„•βˆž) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set Ξ±) : (s \ t).encard + t.encard = (s βˆͺ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set Ξ±) : s.encard ≀ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set Ξ±) : s.encard - t.encard ≀ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set Ξ±) : s.encard + sᢜ.encard = (univ : Set Ξ±).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : Ξ±} theorem encard_insert_le (s : Set Ξ±) (x : Ξ±) : (insert x s).encard ≀ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set Ξ±) (x : Ξ±) : ({x} ∩ s).encard ≀ 1 := by rw [← encard_singleton x]; exact encard_le_encard inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set Ξ±) (x : Ξ±) : s.encard - 1 ≀ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a βˆ‰ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a βˆ‰ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : β„•βˆž} : s.encard = k + 1 ↔ (βˆƒ a t, Β¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ Β· obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set Ξ±) : s = βˆ… ∨ s.encard = ⊀ ∨ βˆƒ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : Ξ±} (hne : x β‰  y) : ({x, y} : Set Ξ±).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_inj WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ βˆƒ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≀ 1 ↔ s = βˆ… ∨ βˆƒ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≀ 1 ↔ βˆ€ a b, a ∈ s β†’ b ∈ s β†’ a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem encard_le_one_iff_subsingleton : s.encard ≀ 1 ↔ s.Subsingleton := by rw [encard_le_one_iff, Set.Subsingleton] tauto theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton] theorem one_lt_encard_iff : 1 < s.encard ↔ βˆƒ a b, a ∈ s ∧ b ∈ s ∧ a β‰  b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : Ξ±) : βˆƒ b ∈ s, b β‰  a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ βˆƒ x y, x β‰  y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {Ξ± : Type u_1} {s : Set Ξ±} : encard s = 3 ↔ βˆƒ x y z, x β‰  y ∧ x β‰  z ∧ y β‰  z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ Β· obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : β„•βˆž) = 2 + 1), WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ Β· rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl Β· rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : β„•) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 Β· rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s βŠ† t) (hst : t.encard = s.encard + 1) : βˆƒ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : β„•βˆž} (hk : k ≀ s.encard) : βˆƒ t, t βŠ† s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ βŸ¨βˆ…, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ Β· obtain ⟨tβ‚€, htβ‚€s, htβ‚€βŸ© := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : tβ‚€ β‰  s := by rintro rfl; rw [htβ‚€, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (htβ‚€s.ssubset_of_ne hne) exact ⟨insert x tβ‚€, insert_subset hx.1 htβ‚€s, by rw [encard_insert_of_not_mem hx.2, htβ‚€]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : β„•βˆž} (hst : s βŠ† t) (hsk : s.encard ≀ k) (hkt : k ≀ t.encard) : βˆƒ r, s βŠ† r ∧ r βŠ† t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊀ Β· rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≀ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s βˆͺ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set Ξ±} {t : Set Ξ²} {f : Ξ± β†’ Ξ²} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, ENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set Ξ±) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.encard_le (e : s β†ͺ t) : s.encard ≀ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : Ξ± β†’ Ξ²) (s : Set Ξ±) : (f '' s).encard ≀ s.encard := by obtain (h | h) := isEmpty_or_nonempty Ξ± Β· rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_encard exact f.invFunOn_image_image_subset s theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by obtain (h' | hne) := isEmpty_or_nonempty Ξ± Β· rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t βŠ† range f) : (f ⁻¹' t).encard = t.encard := by rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht] lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set Ξ²) : (f ⁻¹' t).encard = t.encard := encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq]) theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) : s.encard ≀ t.encard := by rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx theorem Finite.exists_injOn_of_encard_le [Nonempty Ξ²] {s : Set Ξ±} {t : Set Ξ²} (hs : s.Finite) (hle : s.encard ≀ t.encard) : βˆƒ (f : Ξ± β†’ Ξ²), s βŠ† f ⁻¹' t ∧ InjOn f s := by classical obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt Β· simp Β· exact (encard_ne_top_iff.mpr hs h).elim obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle) have hle' : (s \ {a}).encard ≀ (t \ {b}).encard := by rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top, encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt] obtain ⟨fβ‚€, hfβ‚€s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle' simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hfβ‚€s use Function.update fβ‚€ a b rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)] simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def, mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp, mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt] refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hfβ‚€s x hxs hxa).2⟩⟩ Β· rintro x hx; split_ifs with h Β· assumption Β· exact (hfβ‚€s x hx h).1 exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne]) termination_by encard s theorem Finite.exists_bijOn_of_encard_eq [Nonempty Ξ²] (hs : s.Finite) (h : s.encard = t.encard) : βˆƒ (f : Ξ± β†’ Ξ²), BijOn f s t := by obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f convert hinj.bijOn_image rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf) (h.symm.trans hinj.encard_image.symm).le] end Function section ncard open Nat /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite` term. -/ syntax "toFinite_tac" : tactic macro_rules | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite) /-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/ syntax "to_encard_tac" : tactic macro_rules | `(tactic| to_encard_tac) => `(tactic| simp only [← Nat.cast_le (Ξ± := β„•βˆž), ← Nat.cast_inj (R := β„•βˆž), Nat.cast_add, Nat.cast_one]) /-- The cardinality of `s : Set Ξ±` . Has the junk value `0` if `s` is infinite -/ noncomputable def ncard (s : Set Ξ±) : β„• := ENat.toNat s.encard theorem ncard_def (s : Set Ξ±) : s.ncard = ENat.toNat s.encard := rfl theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not] lemma ncard_le_encard (s : Set Ξ±) : s.ncard ≀ s.encard := ENat.coe_toNat_le_self _ theorem Nat.card_coe_set_eq (s : Set Ξ±) : Nat.card s = s.ncard := by obtain (h | h) := s.finite_or_infinite Β· have := h.fintype rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card, toFinite_toFinset, toFinset_card, ENat.toNat_coe] have := infinite_coe_iff.2 h rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top] theorem ncard_eq_toFinset_card (s : Set Ξ±) (hs : s.Finite := by toFinite_tac) : s.ncard = hs.toFinset.card := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype, @Finite.card_toFinset _ _ hs.fintype hs] theorem ncard_eq_toFinset_card' (s : Set Ξ±) [Fintype s] : s.ncard = s.toFinset.card := by simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card] lemma cast_ncard {s : Set Ξ±} (hs : s.Finite) : (s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs theorem encard_le_coe_iff_finite_ncard_le {k : β„•} : s.encard ≀ k ↔ s.Finite ∧ s.ncard ≀ k := by rw [encard_le_coe_iff, and_congr_right_iff] exact fun hfin ↦ ⟨fun ⟨nβ‚€, hnβ‚€, hle⟩ ↦ by rwa [ncard_def, hnβ‚€, ENat.toNat_coe], fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩ theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype] @[gcongr] theorem ncard_le_ncard (hst : s βŠ† t) (ht : t.Finite := by toFinite_tac) : s.ncard ≀ t.ncard := by rw [← Nat.cast_le (Ξ± := β„•βˆž), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq] exact encard_mono hst theorem ncard_mono [Finite Ξ±] : @Monotone (Set Ξ±) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) : s.ncard = 0 ↔ s = βˆ… := by rw [← Nat.cast_inj (R := β„•βˆž), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero] @[simp, norm_cast] theorem ncard_coe_Finset (s : Finset Ξ±) : (s : Set Ξ±).ncard = s.card := by rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset] theorem ncard_univ (Ξ± : Type*) : (univ : Set Ξ±).ncard = Nat.card Ξ± := by rcases finite_or_infinite Ξ± with h | h Β· have hft := Fintype.ofFinite Ξ± rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card] rw [Nat.card_eq_zero_of_infinite, Infinite.ncard] exact infinite_univ @[simp] theorem ncard_empty (Ξ± : Type*) : (βˆ… : Set Ξ±).ncard = 0 := by rw [ncard_eq_zero] theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty] protected alias ⟨_, Nonempty.ncard_pos⟩ := ncard_pos theorem ncard_ne_zero_of_mem {a : Ξ±} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard β‰  0 := ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm theorem finite_of_ncard_ne_zero (hs : s.ncard β‰  0) : s.Finite := s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite := finite_of_ncard_ne_zero hs.ne.symm theorem nonempty_of_ncard_ne_zero (hs : s.ncard β‰  0) : s.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs @[simp] theorem ncard_singleton (a : Ξ±) : ({a} : Set Ξ±).ncard = 1 := by simp [ncard]
Mathlib/Data/Set/Card.lean
580
584
theorem ncard_singleton_inter (a : Ξ±) (s : Set Ξ±) : ({a} ∩ s).ncard ≀ 1 := by
rw [← Nat.cast_le (Ξ± := β„•βˆž), (toFinite _).cast_ncard_eq, Nat.cast_one] apply encard_singleton_inter @[simp]
/- 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.Ordinal.Family /-! # Ordinal exponential In this file we define the power function and the logarithm function on ordinals. The two are related by the lemma `Ordinal.opow_le_iff_le_log : b ^ c ≀ x ↔ c ≀ log b x` for nontrivial inputs `b`, `c`. -/ noncomputable section open Function Set Equiv Order open scoped Cardinal Ordinal universe u v w namespace Ordinal /-- The ordinal exponential, defined by transfinite recursion. We call this `opow` in theorems in order to disambiguate from other exponentials. -/ instance instPow : Pow Ordinal Ordinal := ⟨fun a b ↦ if a = 0 then 1 - b else limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2⟩ private theorem opow_of_ne_zero {a b : Ordinal} (h : a β‰  0) : a ^ b = limitRecOn b 1 (fun _ x ↦ x * a) fun o _ f ↦ ⨆ x : Iio o, f x.1 x.2 := if_neg h /-- `0 ^ a = 1` if `a = 0` and `0 ^ a = 0` otherwise. -/ theorem zero_opow' (a : Ordinal) : 0 ^ a = 1 - a := if_pos rfl theorem zero_opow_le (a : Ordinal) : (0 : Ordinal) ^ a ≀ 1 := by rw [zero_opow'] exact sub_le_self 1 a @[simp] theorem zero_opow {a : Ordinal} (a0 : a β‰  0) : (0 : Ordinal) ^ a = 0 := by rwa [zero_opow', Ordinal.sub_eq_zero_iff_le, one_le_iff_ne_zero] @[simp] theorem opow_zero (a : Ordinal) : a ^ (0 : Ordinal) = 1 := by obtain rfl | h := eq_or_ne a 0 Β· rw [zero_opow', Ordinal.sub_zero] Β· rw [opow_of_ne_zero h, limitRecOn_zero] @[simp] theorem opow_succ (a b : Ordinal) : a ^ succ b = a ^ b * a := by obtain rfl | h := eq_or_ne a 0 Β· rw [zero_opow (succ_ne_zero b), mul_zero] Β· rw [opow_of_ne_zero h, opow_of_ne_zero h, limitRecOn_succ] theorem opow_limit {a b : Ordinal} (ha : a β‰  0) (hb : IsLimit b) : a ^ b = ⨆ x : Iio b, a ^ x.1 := by simp_rw [opow_of_ne_zero ha, limitRecOn_limit _ _ _ _ hb] theorem opow_le_of_limit {a b c : Ordinal} (a0 : a β‰  0) (h : IsLimit b) : a ^ b ≀ c ↔ βˆ€ b' < b, a ^ b' ≀ c := by rw [opow_limit a0 h, Ordinal.iSup_le_iff, Subtype.forall] rfl theorem lt_opow_of_limit {a b c : Ordinal} (b0 : b β‰  0) (h : IsLimit c) : a < b ^ c ↔ βˆƒ c' < c, a < b ^ c' := by rw [← not_iff_not, not_exists] simp only [not_lt, opow_le_of_limit b0 h, exists_prop, not_and] @[simp] theorem opow_one (a : Ordinal) : a ^ (1 : Ordinal) = a := by rw [← succ_zero, opow_succ] simp only [opow_zero, one_mul] @[simp] theorem one_opow (a : Ordinal) : (1 : Ordinal) ^ a = 1 := by induction a using limitRecOn with | zero => simp only [opow_zero] | succ _ ih => simp only [opow_succ, ih, mul_one] | isLimit b l IH => refine eq_of_forall_ge_iff fun c => ?_ rw [opow_le_of_limit Ordinal.one_ne_zero l] exact ⟨fun H => by simpa only [opow_zero] using H 0 l.pos, fun H b' h => by rwa [IH _ h]⟩ theorem opow_pos {a : Ordinal} (b : Ordinal) (a0 : 0 < a) : 0 < a ^ b := by have h0 : 0 < a ^ (0 : Ordinal) := by simp only [opow_zero, zero_lt_one] induction b using limitRecOn with | zero => exact h0 | succ b IH => rw [opow_succ] exact mul_pos IH a0 | isLimit b l _ => exact (lt_opow_of_limit (Ordinal.pos_iff_ne_zero.1 a0) l).2 ⟨0, l.pos, h0⟩ theorem opow_ne_zero {a : Ordinal} (b : Ordinal) (a0 : a β‰  0) : a ^ b β‰  0 := Ordinal.pos_iff_ne_zero.1 <| opow_pos b <| Ordinal.pos_iff_ne_zero.2 a0 @[simp] theorem opow_eq_zero {a b : Ordinal} : a ^ b = 0 ↔ a = 0 ∧ b β‰  0 := by obtain rfl | ha := eq_or_ne a 0 Β· obtain rfl | hb := eq_or_ne b 0 Β· simp Β· simp [hb] Β· simp [opow_ne_zero b ha, ha] @[simp, norm_cast] theorem opow_natCast (a : Ordinal) (n : β„•) : a ^ (n : Ordinal) = a ^ n := by induction n with | zero => rw [Nat.cast_zero, opow_zero, pow_zero] | succ n IH => rw [Nat.cast_succ, add_one_eq_succ, opow_succ, pow_succ, IH] theorem isNormal_opow {a : Ordinal} (h : 1 < a) : IsNormal (a ^ Β·) := have a0 : 0 < a := zero_lt_one.trans h ⟨fun b => by simpa only [mul_one, opow_succ] using (mul_lt_mul_iff_left (opow_pos b a0)).2 h, fun _ l _ => opow_le_of_limit (ne_of_gt a0) l⟩ theorem opow_lt_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b < a ^ c ↔ b < c := (isNormal_opow a1).lt_iff theorem opow_le_opow_iff_right {a b c : Ordinal} (a1 : 1 < a) : a ^ b ≀ a ^ c ↔ b ≀ c := (isNormal_opow a1).le_iff theorem opow_right_inj {a b c : Ordinal} (a1 : 1 < a) : a ^ b = a ^ c ↔ b = c := (isNormal_opow a1).inj theorem isLimit_opow {a b : Ordinal} (a1 : 1 < a) : IsLimit b β†’ IsLimit (a ^ b) := (isNormal_opow a1).isLimit theorem isLimit_opow_left {a b : Ordinal} (l : IsLimit a) (hb : b β‰  0) : IsLimit (a ^ b) := by rcases zero_or_succ_or_limit b with (e | ⟨b, rfl⟩ | l') Β· exact absurd e hb Β· rw [opow_succ] exact isLimit_mul (opow_pos _ l.pos) l Β· exact isLimit_opow l.one_lt l' theorem opow_le_opow_right {a b c : Ordinal} (h₁ : 0 < a) (hβ‚‚ : b ≀ c) : a ^ b ≀ a ^ c := by rcases lt_or_eq_of_le (one_le_iff_pos.2 h₁) with h₁ | h₁ Β· exact (opow_le_opow_iff_right h₁).2 hβ‚‚ Β· subst a -- Porting note: `le_refl` is required. simp only [one_opow, le_refl] theorem opow_le_opow_left {a b : Ordinal} (c : Ordinal) (ab : a ≀ b) : a ^ c ≀ b ^ c := by by_cases a0 : a = 0 -- Porting note: `le_refl` is required. Β· subst a by_cases c0 : c = 0 Β· subst c simp only [opow_zero, le_refl] Β· simp only [zero_opow c0, Ordinal.zero_le] Β· induction c using limitRecOn with | zero => simp only [opow_zero, le_refl] | succ c IH => simpa only [opow_succ] using mul_le_mul' IH ab | isLimit c l IH => exact (opow_le_of_limit a0 l).2 fun b' h => (IH _ h).trans (opow_le_opow_right ((Ordinal.pos_iff_ne_zero.2 a0).trans_le ab) h.le) theorem opow_le_opow {a b c d : Ordinal} (hac : a ≀ c) (hbd : b ≀ d) (hc : 0 < c) : a ^ b ≀ c ^ d := (opow_le_opow_left b hac).trans (opow_le_opow_right hc hbd) theorem left_le_opow (a : Ordinal) {b : Ordinal} (b1 : 0 < b) : a ≀ a ^ b := by nth_rw 1 [← opow_one a] rcases le_or_gt a 1 with a1 | a1 Β· rcases lt_or_eq_of_le a1 with a0 | a1 Β· rw [lt_one_iff_zero] at a0 rw [a0, zero_opow Ordinal.one_ne_zero] exact Ordinal.zero_le _ rw [a1, one_opow, one_opow] rwa [opow_le_opow_iff_right a1, one_le_iff_pos] theorem left_lt_opow {a b : Ordinal} (ha : 1 < a) (hb : 1 < b) : a < a ^ b := by conv_lhs => rw [← opow_one a] rwa [opow_lt_opow_iff_right ha] theorem right_le_opow {a : Ordinal} (b : Ordinal) (a1 : 1 < a) : b ≀ a ^ b := (isNormal_opow a1).le_apply theorem opow_lt_opow_left_of_succ {a b c : Ordinal} (ab : a < b) : a ^ succ c < b ^ succ c := by rw [opow_succ, opow_succ] exact (mul_le_mul_right' (opow_le_opow_left c ab.le) a).trans_lt (mul_lt_mul_of_pos_left ab (opow_pos c ((Ordinal.zero_le a).trans_lt ab))) theorem opow_add (a b c : Ordinal) : a ^ (b + c) = a ^ b * a ^ c := by rcases eq_or_ne a 0 with (rfl | a0) Β· rcases eq_or_ne c 0 with (rfl | c0) Β· simp have : b + c β‰  0 := ((Ordinal.pos_iff_ne_zero.2 c0).trans_le (le_add_left _ _)).ne' simp only [zero_opow c0, zero_opow this, mul_zero] rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with (rfl | a1) Β· simp only [one_opow, mul_one] induction c using limitRecOn with | zero => simp | succ c IH => rw [add_succ, opow_succ, IH, opow_succ, mul_assoc] | isLimit c l IH => refine eq_of_forall_ge_iff fun d => (((isNormal_opow a1).trans (isNormal_add_right b)).limit_le l).trans ?_ dsimp only [Function.comp_def] simp +contextual only [IH] exact (((isNormal_mul_right <| opow_pos b (Ordinal.pos_iff_ne_zero.2 a0)).trans (isNormal_opow a1)).limit_le l).symm theorem opow_one_add (a b : Ordinal) : a ^ (1 + b) = a * a ^ b := by rw [opow_add, opow_one] theorem opow_dvd_opow (a : Ordinal) {b c : Ordinal} (h : b ≀ c) : a ^ b ∣ a ^ c := ⟨a ^ (c - b), by rw [← opow_add, Ordinal.add_sub_cancel_of_le h]⟩ theorem opow_dvd_opow_iff {a b c : Ordinal} (a1 : 1 < a) : a ^ b ∣ a ^ c ↔ b ≀ c := ⟨fun h => le_of_not_lt fun hn => not_le_of_lt ((opow_lt_opow_iff_right a1).2 hn) <| le_of_dvd (opow_ne_zero _ <| one_le_iff_ne_zero.1 <| a1.le) h, opow_dvd_opow _⟩ theorem opow_mul (a b c : Ordinal) : a ^ (b * c) = (a ^ b) ^ c := by by_cases b0 : b = 0; Β· simp only [b0, zero_mul, opow_zero, one_opow] by_cases a0 : a = 0 Β· subst a by_cases c0 : c = 0 Β· simp only [c0, mul_zero, opow_zero] simp only [zero_opow b0, zero_opow c0, zero_opow (mul_ne_zero b0 c0)] rcases eq_or_lt_of_le (one_le_iff_ne_zero.2 a0) with a1 | a1 Β· subst a1 simp only [one_opow] induction c using limitRecOn with | zero => simp only [mul_zero, opow_zero] | succ c IH => rw [mul_succ, opow_add, IH, opow_succ] | isLimit c l IH => refine eq_of_forall_ge_iff fun d => (((isNormal_opow a1).trans (isNormal_mul_right (Ordinal.pos_iff_ne_zero.2 b0))).limit_le l).trans ?_ dsimp only [Function.comp_def] simp +contextual only [IH] exact (opow_le_of_limit (opow_ne_zero _ a0) l).symm theorem opow_mul_add_pos {b v : Ordinal} (hb : b β‰  0) (u : Ordinal) (hv : v β‰  0) (w : Ordinal) : 0 < b ^ u * v + w := (opow_pos u <| Ordinal.pos_iff_ne_zero.2 hb).trans_le <| (le_mul_left _ <| Ordinal.pos_iff_ne_zero.2 hv).trans <| le_add_right _ _ theorem opow_mul_add_lt_opow_mul_succ {b u w : Ordinal} (v : Ordinal) (hw : w < b ^ u) : b ^ u * v + w < b ^ u * succ v := by rwa [mul_succ, add_lt_add_iff_left] theorem opow_mul_add_lt_opow_succ {b u v w : Ordinal} (hvb : v < b) (hw : w < b ^ u) : b ^ u * v + w < b ^ succ u := by convert (opow_mul_add_lt_opow_mul_succ v hw).trans_le (mul_le_mul_left' (succ_le_of_lt hvb) _) using 1 exact opow_succ b u /-! ### Ordinal logarithm -/ /-- The ordinal logarithm is the solution `u` to the equation `x = b ^ u * v + w` where `v < b` and `w < b ^ u`. -/ @[pp_nodot] def log (b : Ordinal) (x : Ordinal) : Ordinal := if 1 < b then pred (sInf { o | x < b ^ o }) else 0 /-- The set in the definition of `log` is nonempty. -/ private theorem log_nonempty {b x : Ordinal} (h : 1 < b) : { o : Ordinal | x < b ^ o }.Nonempty := ⟨_, succ_le_iff.1 (right_le_opow _ h)⟩ theorem log_def {b : Ordinal} (h : 1 < b) (x : Ordinal) : log b x = pred (sInf { o | x < b ^ o }) := if_pos h theorem log_of_left_le_one {b : Ordinal} (h : b ≀ 1) (x : Ordinal) : log b x = 0 := if_neg h.not_lt @[simp]
Mathlib/SetTheory/Ordinal/Exponential.lean
284
291
theorem log_zero_left : βˆ€ b, log 0 b = 0 := log_of_left_le_one zero_le_one @[simp] theorem log_zero_right (b : Ordinal) : log b 0 = 0 := by
obtain hb | hb := lt_or_le 1 b Β· rw [log_def hb, ← Ordinal.le_zero, pred_le, succ_zero] apply csInf_le'
/- 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, Anne Baanen -/ import Mathlib.Algebra.BigOperators.Finsupp.Basic import Mathlib.Algebra.Group.Submonoid.Membership import Mathlib.Algebra.GroupWithZero.Associated /-! # Products of associated, prime, and irreducible elements. This file contains some theorems relating definitions in `Algebra.Associated` and products of multisets, finsets, and finsupps. -/ assert_not_exists Field variable {Ξ± Ξ² Ξ³ Ξ΄ : Type*} -- the same local notation used in `Algebra.Associated` local infixl:50 " ~α΅€ " => Associated namespace Prime variable [CommMonoidWithZero Ξ±] {p : Ξ±} theorem exists_mem_multiset_dvd (hp : Prime p) {s : Multiset Ξ±} : p ∣ s.prod β†’ βˆƒ a ∈ s, p ∣ a := Multiset.induction_on s (fun h => (hp.not_dvd_one h).elim) fun a s ih h => have : p ∣ a * s.prod := by simpa using h match hp.dvd_or_dvd this with | Or.inl h => ⟨a, Multiset.mem_cons_self a s, h⟩ | Or.inr h => let ⟨a, has, h⟩ := ih h ⟨a, Multiset.mem_cons_of_mem has, h⟩ theorem exists_mem_multiset_map_dvd (hp : Prime p) {s : Multiset Ξ²} {f : Ξ² β†’ Ξ±} : p ∣ (s.map f).prod β†’ βˆƒ a ∈ s, p ∣ f a := fun h => by simpa only [exists_prop, Multiset.mem_map, exists_exists_and_eq_and] using hp.exists_mem_multiset_dvd h theorem exists_mem_finset_dvd (hp : Prime p) {s : Finset Ξ²} {f : Ξ² β†’ Ξ±} : p ∣ s.prod f β†’ βˆƒ i ∈ s, p ∣ f i := hp.exists_mem_multiset_map_dvd end Prime theorem Prod.associated_iff {M N : Type*} [Monoid M] [Monoid N] {x z : M Γ— N} : x ~α΅€ z ↔ x.1 ~α΅€ z.1 ∧ x.2 ~α΅€ z.2 := ⟨fun ⟨u, hu⟩ => ⟨⟨(MulEquiv.prodUnits.toFun u).1, (Prod.eq_iff_fst_eq_snd_eq.1 hu).1⟩, ⟨(MulEquiv.prodUnits.toFun u).2, (Prod.eq_iff_fst_eq_snd_eq.1 hu).2⟩⟩, fun ⟨⟨u₁, hβ‚βŸ©, ⟨uβ‚‚, hβ‚‚βŸ©βŸ© => ⟨MulEquiv.prodUnits.invFun (u₁, uβ‚‚), Prod.eq_iff_fst_eq_snd_eq.2 ⟨h₁, hβ‚‚βŸ©βŸ©βŸ© theorem Associated.prod {M : Type*} [CommMonoid M] {ΞΉ : Type*} (s : Finset ΞΉ) (f : ΞΉ β†’ M) (g : ΞΉ β†’ M) (h : βˆ€ i, i ∈ s β†’ (f i) ~α΅€ (g i)) : (∏ i ∈ s, f i) ~α΅€ (∏ i ∈ s, g i) := by induction s using Finset.induction with | empty => simp only [Finset.prod_empty] rfl | insert j s hjs IH => classical convert_to (∏ i ∈ insert j s, f i) ~α΅€ (∏ i ∈ insert j s, g i) rw [Finset.prod_insert hjs, Finset.prod_insert hjs] exact Associated.mul_mul (h j (Finset.mem_insert_self j s)) (IH (fun i hi ↦ h i (Finset.mem_insert_of_mem hi))) theorem exists_associated_mem_of_dvd_prod [CancelCommMonoidWithZero Ξ±] {p : Ξ±} (hp : Prime p) {s : Multiset Ξ±} : (βˆ€ r ∈ s, Prime r) β†’ p ∣ s.prod β†’ βˆƒ q ∈ s, p ~α΅€ q := Multiset.induction_on s (by simp [mt isUnit_iff_dvd_one.2 hp.not_unit]) fun a s ih hs hps => by rw [Multiset.prod_cons] at hps rcases hp.dvd_or_dvd hps with h | h Β· have hap := hs a (Multiset.mem_cons.2 (Or.inl rfl)) exact ⟨a, Multiset.mem_cons_self a _, hp.associated_of_dvd hap h⟩ Β· rcases ih (fun r hr => hs _ (Multiset.mem_cons.2 (Or.inr hr))) h with ⟨q, hq₁, hqβ‚‚βŸ© exact ⟨q, Multiset.mem_cons.2 (Or.inr hq₁), hqβ‚‚βŸ© open Submonoid in /-- Let x, y ∈ Ξ±. If x * y can be written as a product of units and prime elements, then x can be written as a product of units and prime elements. -/
Mathlib/Algebra/BigOperators/Associated.lean
82
100
theorem divisor_closure_eq_closure [CancelCommMonoidWithZero α] (x y : α) (hxy : x * y ∈ closure { r : α | IsUnit r ∨ Prime r}) : x ∈ closure { r : α | IsUnit r ∨ Prime r} := by
obtain ⟨m, hm, hprod⟩ := exists_multiset_of_mem_closure hxy induction m using Multiset.induction generalizing x y with | empty => apply subset_closure simp only [Set.mem_setOf] simp only [Multiset.prod_zero] at hprod left; exact isUnit_of_mul_eq_one _ _ hprod.symm | cons c s hind => simp only [Multiset.mem_cons, forall_eq_or_imp, Set.mem_setOf] at hm simp only [Multiset.prod_cons] at hprod simp only [Set.mem_setOf_eq] at hind obtain ⟨ha₁ | haβ‚‚, hs⟩ := hm Β· rcases ha₁.exists_right_inv with ⟨k, hk⟩ refine hind x (y*k) ?_ hs ?_ Β· simp only [← mul_assoc, ← hprod, ← Multiset.prod_cons, mul_comm] refine multiset_prod_mem _ _ (Multiset.forall_mem_cons.2 ⟨subset_closure (Set.mem_def.2 ?_),
/- 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, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.Polynomial.Inductions import Mathlib.Algebra.Polynomial.Monic import Mathlib.Algebra.Ring.Regular import Mathlib.RingTheory.Multiplicity import Mathlib.Data.Nat.Lattice /-! # Division of univariate polynomials The main defs are `divByMonic` and `modByMonic`. The compatibility between these is given by `modByMonic_add_div`. We also define `rootMultiplicity`. -/ 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] theorem X_dvd_iff {f : R[X]} : X ∣ f ↔ f.coeff 0 = 0 := ⟨fun ⟨g, hfg⟩ => by rw [hfg, coeff_X_mul_zero], fun hf => ⟨f.divX, by rw [← add_zero (X * f.divX), ← C_0, ← hf, X_mul_divX_add]⟩⟩ theorem X_pow_dvd_iff {f : R[X]} {n : β„•} : X ^ n ∣ f ↔ βˆ€ d < n, f.coeff d = 0 := ⟨fun ⟨g, hgf⟩ d hd => by simp only [hgf, coeff_X_pow_mul', ite_eq_right_iff, not_le_of_lt hd, IsEmpty.forall_iff], fun hd => by induction n with | zero => simp [pow_zero, one_dvd] | succ n hn => obtain ⟨g, hgf⟩ := hn fun d : β„• => fun H : d < n => hd _ (Nat.lt_succ_of_lt H) have := coeff_X_pow_mul g n 0 rw [zero_add, ← hgf, hd n (Nat.lt_succ_self n)] at this obtain ⟨k, hgk⟩ := Polynomial.X_dvd_iff.mpr this.symm use k rwa [pow_succ, mul_assoc, ← hgk]⟩ variable {p q : R[X]} theorem finiteMultiplicity_of_degree_pos_of_monic (hp : (0 : WithBot β„•) < degree p) (hmp : Monic p) (hq : q β‰  0) : FiniteMultiplicity p q := have zn0 : (0 : R) β‰  1 := haveI := Nontrivial.of_polynomial_ne hq zero_ne_one ⟨natDegree q, fun ⟨r, hr⟩ => by have hp0 : p β‰  0 := fun hp0 => by simp [hp0] at hp have hr0 : r β‰  0 := fun hr0 => by subst hr0; simp [hq] at hr have hpn1 : leadingCoeff p ^ (natDegree q + 1) = 1 := by simp [show _ = _ from hmp] have hpn0' : leadingCoeff p ^ (natDegree q + 1) β‰  0 := hpn1.symm β–Έ zn0.symm have hpnr0 : leadingCoeff (p ^ (natDegree q + 1)) * leadingCoeff r β‰  0 := by simp only [leadingCoeff_pow' hpn0', leadingCoeff_eq_zero, hpn1, one_pow, one_mul, Ne, hr0, not_false_eq_true] have hnp : 0 < natDegree p := Nat.cast_lt.1 <| by rw [← degree_eq_natDegree hp0]; exact hp have := congr_arg natDegree hr rw [natDegree_mul' hpnr0, natDegree_pow' hpn0', add_mul, add_assoc] at this exact ne_of_lt (lt_add_of_le_of_pos (le_mul_of_one_le_right (Nat.zero_le _) hnp) (add_pos_of_pos_of_nonneg (by rwa [one_mul]) (Nat.zero_le _))) this⟩ @[deprecated (since := "2024-11-30")] alias multiplicity_finite_of_degree_pos_of_monic := finiteMultiplicity_of_degree_pos_of_monic end Semiring section Ring variable [Ring R] {p q : R[X]} theorem div_wf_lemma (h : degree q ≀ degree p ∧ p β‰  0) (hq : Monic q) : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p := have hp : leadingCoeff p β‰  0 := mt leadingCoeff_eq_zero.1 h.2 have hq0 : q β‰  0 := hq.ne_zero_of_polynomial_ne h.2 have hlt : natDegree q ≀ natDegree p := (Nat.cast_le (Ξ± := WithBot β„•)).1 (by rw [← degree_eq_natDegree h.2, ← degree_eq_natDegree hq0]; exact h.1) degree_sub_lt (by rw [hq.degree_mul_comm, hq.degree_mul, degree_C_mul_X_pow _ hp, degree_eq_natDegree h.2, degree_eq_natDegree hq0, ← Nat.cast_add, tsub_add_cancel_of_le hlt]) h.2 (by rw [leadingCoeff_monic_mul hq, leadingCoeff_mul_X_pow, leadingCoeff_C]) /-- See `divByMonic`. -/ noncomputable def divModByMonicAux : βˆ€ (_p : R[X]) {q : R[X]}, Monic q β†’ R[X] Γ— R[X] | p, q, hq => letI := Classical.decEq R if h : degree q ≀ degree p ∧ p β‰  0 then let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q) have _wf := div_wf_lemma h hq let dm := divModByMonicAux (p - q * z) hq ⟨z + dm.1, dm.2⟩ else ⟨0, p⟩ termination_by p => p /-- `divByMonic`, denoted as `p /β‚˜ q`, gives the quotient of `p` by a monic polynomial `q`. -/ def divByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).1 else 0 /-- `modByMonic`, denoted as `p %β‚˜ q`, gives the remainder of `p` by a monic polynomial `q`. -/ def modByMonic (p q : R[X]) : R[X] := letI := Classical.decEq R if hq : Monic q then (divModByMonicAux p hq).2 else p @[inherit_doc] infixl:70 " /β‚˜ " => divByMonic @[inherit_doc] infixl:70 " %β‚˜ " => modByMonic theorem degree_modByMonic_lt [Nontrivial R] : βˆ€ (p : R[X]) {q : R[X]} (_hq : Monic q), degree (p %β‚˜ q) < degree q | p, q, hq => letI := Classical.decEq R if h : degree q ≀ degree p ∧ p β‰  0 then by have _wf := div_wf_lemma ⟨h.1, h.2⟩ hq have := degree_modByMonic_lt (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic at this ⊒ unfold divModByMonicAux dsimp rw [dif_pos hq] at this ⊒ rw [if_pos h] exact this else Or.casesOn (not_and_or.1 h) (by unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h] exact lt_of_not_ge) (by intro hp unfold modByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, Classical.not_not.1 hp] exact lt_of_le_of_ne bot_le (Ne.symm (mt degree_eq_bot.1 hq.ne_zero))) termination_by p => p theorem natDegree_modByMonic_lt (p : R[X]) {q : R[X]} (hmq : Monic q) (hq : q β‰  1) : natDegree (p %β‚˜ q) < q.natDegree := by by_cases hpq : p %β‚˜ q = 0 Β· rw [hpq, natDegree_zero, Nat.pos_iff_ne_zero] contrapose! hq exact eq_one_of_monic_natDegree_zero hmq hq Β· haveI := Nontrivial.of_polynomial_ne hpq exact natDegree_lt_natDegree hpq (degree_modByMonic_lt p hmq) @[simp] theorem zero_modByMonic (p : R[X]) : 0 %β‚˜ p = 0 := by classical unfold modByMonic divModByMonicAux dsimp by_cases hp : Monic p Β· rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.snd_zero] Β· rw [dif_neg hp] @[simp] theorem zero_divByMonic (p : R[X]) : 0 /β‚˜ p = 0 := by classical unfold divByMonic divModByMonicAux dsimp by_cases hp : Monic p Β· rw [dif_pos hp, if_neg (mt And.right (not_not_intro rfl)), Prod.fst_zero] Β· rw [dif_neg hp] @[simp] theorem modByMonic_zero (p : R[X]) : p %β‚˜ 0 = p := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold modByMonic divModByMonicAux; rw [dif_neg h] @[simp] theorem divByMonic_zero (p : R[X]) : p /β‚˜ 0 = 0 := letI := Classical.decEq R if h : Monic (0 : R[X]) then by haveI := monic_zero_iff_subsingleton.mp h simp [eq_iff_true_of_subsingleton] else by unfold divByMonic divModByMonicAux; rw [dif_neg h] theorem divByMonic_eq_of_not_monic (p : R[X]) (hq : Β¬Monic q) : p /β‚˜ q = 0 := dif_neg hq theorem modByMonic_eq_of_not_monic (p : R[X]) (hq : Β¬Monic q) : p %β‚˜ q = p := dif_neg hq theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %β‚˜ q = p ↔ degree p < degree q := ⟨fun h => h β–Έ degree_modByMonic_lt _ hq, fun h => by classical have : Β¬degree q ≀ degree p := not_le_of_gt h unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %β‚˜ q) ≀ degree q := by nontriviality R exact (degree_modByMonic_lt _ hq).le theorem degree_modByMonic_le_left : degree (p %β‚˜ q) ≀ degree p := by nontriviality R by_cases hq : q.Monic Β· cases lt_or_ge (degree p) (degree q) Β· rw [(modByMonic_eq_self_iff hq).mpr β€Ή_β€Ί] Β· exact (degree_modByMonic_le p hq).trans β€Ή_β€Ί Β· rw [modByMonic_eq_of_not_monic p hq] theorem natDegree_modByMonic_le (p : Polynomial R) {g : Polynomial R} (hg : g.Monic) : natDegree (p %β‚˜ g) ≀ g.natDegree := natDegree_le_natDegree (degree_modByMonic_le p hg) theorem natDegree_modByMonic_le_left : natDegree (p %β‚˜ q) ≀ natDegree p := natDegree_le_natDegree degree_modByMonic_le_left theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by simp [X_dvd_iff, coeff_C] theorem modByMonic_eq_sub_mul_div : βˆ€ (p : R[X]) {q : R[X]} (_hq : Monic q), p %β‚˜ q = p - q * (p /β‚˜ q) | p, q, hq => letI := Classical.decEq R if h : degree q ≀ degree p ∧ p β‰  0 then by have _wf := div_wf_lemma h hq have ih := modByMonic_eq_sub_mul_div (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_pos h] rw [modByMonic, dif_pos hq] at ih refine ih.trans ?_ unfold divByMonic rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub] else by unfold modByMonic divByMonic divModByMonicAux dsimp rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero] termination_by p => p theorem modByMonic_add_div (p : R[X]) {q : R[X]} (hq : Monic q) : p %β‚˜ q + q * (p /β‚˜ q) = p := eq_sub_iff_add_eq.1 (modByMonic_eq_sub_mul_div p hq) theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /β‚˜ q = 0 ↔ degree p < degree q := ⟨fun h => by have := modByMonic_add_div p hq rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this, fun h => by classical have : Β¬degree q ≀ degree p := not_le_of_gt h unfold divByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]⟩ theorem degree_add_divByMonic (hq : Monic q) (h : degree q ≀ degree p) : degree q + degree (p /β‚˜ q) = degree p := by nontriviality R have hdiv0 : p /β‚˜ q β‰  0 := by rwa [Ne, divByMonic_eq_zero_iff hq, not_lt] have hlc : leadingCoeff q * leadingCoeff (p /β‚˜ q) β‰  0 := by rwa [Monic.def.1 hq, one_mul, Ne, leadingCoeff_eq_zero] have hmod : degree (p %β‚˜ q) < degree (q * (p /β‚˜ q)) := calc degree (p %β‚˜ q) < degree q := degree_modByMonic_lt _ hq _ ≀ _ := by rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree hdiv0, ← Nat.cast_add, Nat.cast_le] exact Nat.le_add_right _ _ calc degree q + degree (p /β‚˜ q) = degree (q * (p /β‚˜ q)) := Eq.symm (degree_mul' hlc) _ = degree (p %β‚˜ q + q * (p /β‚˜ q)) := (degree_add_eq_right_of_degree_lt hmod).symm _ = _ := congr_arg _ (modByMonic_add_div _ hq) theorem degree_divByMonic_le (p q : R[X]) : degree (p /β‚˜ q) ≀ degree p := letI := Classical.decEq R if hp0 : p = 0 then by simp only [hp0, zero_divByMonic, le_refl] else if hq : Monic q then if h : degree q ≀ degree p then by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq h, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 (not_lt.2 h))] exact WithBot.coe_le_coe.2 (Nat.le_add_left _ _) else by unfold divByMonic divModByMonicAux simp [dif_pos hq, h, if_false, degree_zero, bot_le] else (divByMonic_eq_of_not_monic p hq).symm β–Έ bot_le theorem degree_divByMonic_lt (p : R[X]) {q : R[X]} (hq : Monic q) (hp0 : p β‰  0) (h0q : 0 < degree q) : degree (p /β‚˜ q) < degree p := if hpq : degree p < degree q then by haveI := Nontrivial.of_polynomial_ne hp0 rw [(divByMonic_eq_zero_iff hq).2 hpq, degree_eq_natDegree hp0] exact WithBot.bot_lt_coe _ else by haveI := Nontrivial.of_polynomial_ne hp0 rw [← degree_add_divByMonic hq (not_lt.1 hpq), degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt (divByMonic_eq_zero_iff hq).1 hpq)] exact Nat.cast_lt.2 (Nat.lt_add_of_pos_left (Nat.cast_lt.1 <| by simpa [degree_eq_natDegree hq.ne_zero] using h0q)) theorem natDegree_divByMonic (f : R[X]) {g : R[X]} (hg : g.Monic) : natDegree (f /β‚˜ g) = natDegree f - natDegree g := by nontriviality R by_cases hfg : f /β‚˜ g = 0 Β· rw [hfg, natDegree_zero] rw [divByMonic_eq_zero_iff hg] at hfg rw [tsub_eq_zero_iff_le.mpr (natDegree_le_natDegree <| le_of_lt hfg)] have hgf := hfg rw [divByMonic_eq_zero_iff hg] at hgf push_neg at hgf have := degree_add_divByMonic hg hgf have hf : f β‰  0 := by intro hf apply hfg rw [hf, zero_divByMonic] rw [degree_eq_natDegree hf, degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hfg, ← Nat.cast_add, Nat.cast_inj] at this rw [← this, add_tsub_cancel_left] theorem div_modByMonic_unique {f g} (q r : R[X]) (hg : Monic g) (h : r + g * q = f ∧ degree r < degree g) : f /β‚˜ g = q ∧ f %β‚˜ g = r := by nontriviality R have h₁ : r - f %β‚˜ g = -g * (q - f /β‚˜ g) := eq_of_sub_eq_zero (by rw [← sub_eq_zero_of_eq (h.1.trans (modByMonic_add_div f hg).symm)] simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]) have hβ‚‚ : degree (r - f %β‚˜ g) = degree (g * (q - f /β‚˜ g)) := by simp [h₁] have hβ‚„ : degree (r - f %β‚˜ g) < degree g := calc degree (r - f %β‚˜ g) ≀ max (degree r) (degree (f %β‚˜ g)) := degree_sub_le _ _ _ < degree g := max_lt_iff.2 ⟨h.2, degree_modByMonic_lt _ hg⟩ have hβ‚… : q - f /β‚˜ g = 0 := _root_.by_contradiction fun hqf => not_le_of_gt hβ‚„ <| calc degree g ≀ degree g + degree (q - f /β‚˜ g) := by rw [degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hqf] norm_cast exact Nat.le_add_right _ _ _ = degree (r - f %β‚˜ g) := by rw [hβ‚‚, degree_mul']; simpa [Monic.def.1 hg] exact ⟨Eq.symm <| eq_of_sub_eq_zero hβ‚…, Eq.symm <| eq_of_sub_eq_zero <| by simpa [hβ‚…] using hβ‚βŸ© theorem map_mod_divByMonic [Ring S] (f : R β†’+* S) (hq : Monic q) : (p /β‚˜ q).map f = p.map f /β‚˜ q.map f ∧ (p %β‚˜ q).map f = p.map f %β‚˜ q.map f := by nontriviality S haveI : Nontrivial R := f.domain_nontrivial have : map f p /β‚˜ map f q = map f (p /β‚˜ q) ∧ map f p %β‚˜ map f q = map f (p %β‚˜ q) := div_modByMonic_unique ((p /β‚˜ q).map f) _ (hq.map f) ⟨Eq.symm <| by rw [← Polynomial.map_mul, ← Polynomial.map_add, modByMonic_add_div _ hq], calc _ ≀ degree (p %β‚˜ q) := degree_map_le _ < degree q := degree_modByMonic_lt _ hq _ = _ := Eq.symm <| degree_map_eq_of_leadingCoeff_ne_zero _ (by rw [Monic.def.1 hq, f.map_one]; exact one_ne_zero)⟩ exact ⟨this.1.symm, this.2.symm⟩ theorem map_divByMonic [Ring S] (f : R β†’+* S) (hq : Monic q) : (p /β‚˜ q).map f = p.map f /β‚˜ q.map f := (map_mod_divByMonic f hq).1 theorem map_modByMonic [Ring S] (f : R β†’+* S) (hq : Monic q) : (p %β‚˜ q).map f = p.map f %β‚˜ q.map f := (map_mod_divByMonic f hq).2 theorem modByMonic_eq_zero_iff_dvd (hq : Monic q) : p %β‚˜ q = 0 ↔ q ∣ p := ⟨fun h => by rw [← modByMonic_add_div p hq, h, zero_add]; exact dvd_mul_right _ _, fun h => by nontriviality R obtain ⟨r, hr⟩ := exists_eq_mul_right_of_dvd h by_contra hpq0 have hmod : p %β‚˜ q = q * (r - p /β‚˜ q) := by rw [modByMonic_eq_sub_mul_div _ hq, mul_sub, ← hr] have : degree (q * (r - p /β‚˜ q)) < degree q := hmod β–Έ degree_modByMonic_lt _ hq have hrpq0 : leadingCoeff (r - p /β‚˜ q) β‰  0 := fun h => hpq0 <| leadingCoeff_eq_zero.1 (by rw [hmod, leadingCoeff_eq_zero.1 h, mul_zero, leadingCoeff_zero]) have hlc : leadingCoeff q * leadingCoeff (r - p /β‚˜ q) β‰  0 := by rwa [Monic.def.1 hq, one_mul] rw [degree_mul' hlc, degree_eq_natDegree hq.ne_zero, degree_eq_natDegree (mt leadingCoeff_eq_zero.2 hrpq0)] at this exact not_lt_of_ge (Nat.le_add_right _ _) (WithBot.coe_lt_coe.1 this)⟩ /-- See `Polynomial.mul_self_modByMonic` for the other multiplication order. That version, unlike this one, requires commutativity. -/ @[simp] lemma self_mul_modByMonic (hq : q.Monic) : (q * p) %β‚˜ q = 0 := by rw [modByMonic_eq_zero_iff_dvd hq] exact dvd_mul_right q p theorem map_dvd_map [Ring S] (f : R β†’+* S) (hf : Function.Injective f) {x y : R[X]} (hx : x.Monic) : x.map f ∣ y.map f ↔ x ∣ y := by rw [← modByMonic_eq_zero_iff_dvd hx, ← modByMonic_eq_zero_iff_dvd (hx.map f), ← map_modByMonic f hx] exact ⟨fun H => map_injective f hf <| by rw [H, Polynomial.map_zero], fun H => by rw [H, Polynomial.map_zero]⟩ @[simp]
Mathlib/Algebra/Polynomial/Div.lean
417
422
theorem modByMonic_one (p : R[X]) : p %β‚˜ 1 = 0 := (modByMonic_eq_zero_iff_dvd (by convert monic_one (R := R))).2 (one_dvd _) @[simp] theorem divByMonic_one (p : R[X]) : p /β‚˜ 1 = p := by
conv_rhs => rw [← modByMonic_add_div p monic_one]; simp
/- Copyright (c) 2022 Violeta HernΓ‘ndez Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta HernΓ‘ndez Palacios -/ import Mathlib.Algebra.Polynomial.Cardinal import Mathlib.RingTheory.Algebraic.Basic /-! ### Cardinality of algebraic numbers In this file, we prove variants of the following result: the cardinality of algebraic numbers under an R-algebra is at most `#R[X] * β„΅β‚€`. Although this can be used to prove that real or complex transcendental numbers exist, a more direct proof is given by `Liouville.transcendental`. -/ universe u v open Cardinal Polynomial Set open Cardinal Polynomial namespace Algebraic theorem infinite_of_charZero (R A : Type*) [CommRing R] [Ring A] [Algebra R A] [CharZero A] : { x : A | IsAlgebraic R x }.Infinite := by letI := MulActionWithZero.nontrivial R A exact infinite_of_injective_forall_mem Nat.cast_injective isAlgebraic_nat theorem aleph0_le_cardinalMk_of_charZero (R A : Type*) [CommRing R] [Ring A] [Algebra R A] [CharZero A] : β„΅β‚€ ≀ #{ x : A // IsAlgebraic R x } := infinite_iff.1 (Set.infinite_coe_iff.2 <| infinite_of_charZero R A) @[deprecated (since := "2024-11-10")] alias aleph0_le_cardinal_mk_of_charZero := aleph0_le_cardinalMk_of_charZero section lift variable (R : Type u) (A : Type v) [CommRing R] [CommRing A] [IsDomain A] [Algebra R A] [NoZeroSMulDivisors R A]
Mathlib/Algebra/AlgebraicCard.lean
45
54
theorem cardinalMk_lift_le_mul : Cardinal.lift.{u} #{ x : A // IsAlgebraic R x } ≀ Cardinal.lift.{v} #R[X] * β„΅β‚€ := by
rw [← mk_uLift, ← mk_uLift] choose g hg₁ hgβ‚‚ using fun x : { x : A | IsAlgebraic R x } => x.coe_prop refine lift_mk_le_lift_mk_mul_of_lift_mk_preimage_le g fun f => ?_ rw [lift_le_aleph0, le_aleph0_iff_set_countable] suffices MapsTo (↑) (g ⁻¹' {f}) (f.rootSet A) from this.countable_of_injOn Subtype.coe_injective.injOn (f.rootSet_finite A).countable rintro x (rfl : g x = f) exact mem_rootSet.2 ⟨hg₁ x, hgβ‚‚ x⟩
/- Copyright (c) 2023 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Topology.Order.Basic /-! # Set neighborhoods of intervals In this file we prove basic theorems about `𝓝˒ s`, where `s` is one of the intervals `Set.Ici`, `Set.Iic`, `Set.Ioi`, `Set.Iio`, `Set.Ico`, `Set.Ioc`, `Set.Ioo`, and `Set.Icc`. First, we prove lemmas in terms of filter equalities. Then we prove lemmas about `s ∈ 𝓝˒ t`, where both `s` and `t` are intervals. Finally, we prove a few lemmas about filter bases of `𝓝˒ (Iic a)` and `𝓝˒ (Ici a)`. -/ open Set Filter OrderDual open scoped Topology section OrderClosedTopology variable {Ξ± : Type*} [LinearOrder Ξ±] [TopologicalSpace Ξ±] [OrderClosedTopology Ξ±] {a b c d : Ξ±} /-! # Formulae for `𝓝˒` of intervals -/ @[simp] theorem nhdsSet_Ioi : 𝓝˒ (Ioi a) = π“Ÿ (Ioi a) := isOpen_Ioi.nhdsSet_eq @[simp] theorem nhdsSet_Iio : 𝓝˒ (Iio a) = π“Ÿ (Iio a) := isOpen_Iio.nhdsSet_eq @[simp] theorem nhdsSet_Ioo : 𝓝˒ (Ioo a b) = π“Ÿ (Ioo a b) := isOpen_Ioo.nhdsSet_eq theorem nhdsSet_Ici : 𝓝˒ (Ici a) = 𝓝 a βŠ” π“Ÿ (Ioi a) := by rw [← Ioi_insert, nhdsSet_insert, nhdsSet_Ioi] theorem nhdsSet_Iic : 𝓝˒ (Iic a) = 𝓝 a βŠ” π“Ÿ (Iio a) := nhdsSet_Ici (Ξ± := Ξ±α΅’α΅ˆ) theorem nhdsSet_Ico (h : a < b) : 𝓝˒ (Ico a b) = 𝓝 a βŠ” π“Ÿ (Ioo a b) := by rw [← Ioo_insert_left h, nhdsSet_insert, nhdsSet_Ioo]
Mathlib/Topology/Order/NhdsSet.lean
44
45
theorem nhdsSet_Ioc (h : a < b) : 𝓝˒ (Ioc a b) = 𝓝 b βŠ” π“Ÿ (Ioo a b) := by
rw [← Ioo_insert_right h, nhdsSet_insert, nhdsSet_Ioo]
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import Mathlib.Algebra.Order.Floor.Semiring import Mathlib.Data.Nat.Log /-! # Integer logarithms in a field with respect to a natural base This file defines two `β„€`-valued analogs of the logarithm of `r : R` with base `b : β„•`: * `Int.log b r`: Lower logarithm, or floor **log**. Greatest `k` such that `↑b^k ≀ r`. * `Int.clog b r`: Upper logarithm, or **c**eil **log**. Least `k` such that `r ≀ ↑b^k`. Note that `Int.log` gives the position of the left-most non-zero digit: ```lean #eval (Int.log 10 (0.09 : β„š), Int.log 10 (0.10 : β„š), Int.log 10 (0.11 : β„š)) -- (-2, -1, -1) #eval (Int.log 10 (9 : β„š), Int.log 10 (10 : β„š), Int.log 10 (11 : β„š)) -- (0, 1, 1) ``` which means it can be used for computing digit expansions ```lean import Data.Fin.VecNotation import Mathlib.Data.Rat.Floor def digits (b : β„•) (q : β„š) (n : β„•) : β„• := ⌊q * ((b : β„š) ^ (n - Int.log b q))βŒ‹β‚Š % b #eval digits 10 (1/7) ∘ ((↑) : Fin 8 β†’ β„•) -- ![1, 4, 2, 8, 5, 7, 1, 4] ``` ## Main results * For `Int.log`: * `Int.zpow_log_le_self`, `Int.lt_zpow_succ_log_self`: the bounds formed by `Int.log`, `(b : R) ^ log b r ≀ r < (b : R) ^ (log b r + 1)`. * `Int.zpow_log_gi`: the galois coinsertion between `zpow` and `Int.log`. * For `Int.clog`: * `Int.zpow_pred_clog_lt_self`, `Int.self_le_zpow_clog`: the bounds formed by `Int.clog`, `(b : R) ^ (clog b r - 1) < r ≀ (b : R) ^ clog b r`. * `Int.clog_zpow_gi`: the galois insertion between `Int.clog` and `zpow`. * `Int.neg_log_inv_eq_clog`, `Int.neg_clog_inv_eq_log`: the link between the two definitions. -/ assert_not_exists Finset variable {R : Type*} [Semifield R] [LinearOrder R] [IsStrictOrderedRing R] [FloorSemiring R] namespace Int /-- The greatest power of `b` such that `b ^ log b r ≀ r`. -/ def log (b : β„•) (r : R) : β„€ := if 1 ≀ r then Nat.log b ⌊rβŒ‹β‚Š else -Nat.clog b ⌈rβ»ΒΉβŒ‰β‚Š omit [IsStrictOrderedRing R] in theorem log_of_one_le_right (b : β„•) {r : R} (hr : 1 ≀ r) : log b r = Nat.log b ⌊rβŒ‹β‚Š := if_pos hr theorem log_of_right_le_one (b : β„•) {r : R} (hr : r ≀ 1) : log b r = -Nat.clog b ⌈rβ»ΒΉβŒ‰β‚Š := by obtain rfl | hr := hr.eq_or_lt Β· rw [log, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] Β· exact if_neg hr.not_le @[simp, norm_cast] theorem log_natCast (b : β„•) (n : β„•) : log b (n : R) = Nat.log b n := by cases n Β· simp [log_of_right_le_one] Β· rw [log_of_one_le_right, Nat.floor_natCast] simp @[simp] theorem log_ofNat (b : β„•) (n : β„•) [n.AtLeastTwo] : log b (ofNat(n) : R) = Nat.log b ofNat(n) := log_natCast b n theorem log_of_left_le_one {b : β„•} (hb : b ≀ 1) (r : R) : log b r = 0 := by rcases le_total 1 r with h | h Β· rw [log_of_one_le_right _ h, Nat.log_of_left_le_one hb, Int.ofNat_zero] Β· rw [log_of_right_le_one _ h, Nat.clog_of_left_le_one hb, Int.ofNat_zero, neg_zero] theorem log_of_right_le_zero (b : β„•) {r : R} (hr : r ≀ 0) : log b r = 0 := by rw [log_of_right_le_one _ (hr.trans zero_le_one), Nat.clog_of_right_le_one ((Nat.ceil_eq_zero.mpr <| inv_nonpos.2 hr).trans_le zero_le_one), Int.ofNat_zero, neg_zero] theorem zpow_log_le_self {b : β„•} {r : R} (hb : 1 < b) (hr : 0 < r) : (b : R) ^ log b r ≀ r := by rcases le_total 1 r with hr1 | hr1 Β· rw [log_of_one_le_right _ hr1] rw [zpow_natCast, ← Nat.cast_pow, ← Nat.le_floor_iff hr.le] exact Nat.pow_log_le_self b (Nat.floor_pos.mpr hr1).ne' Β· rw [log_of_right_le_one _ hr1, zpow_neg, zpow_natCast, ← Nat.cast_pow] exact inv_le_of_inv_leβ‚€ hr (Nat.ceil_le.1 <| Nat.le_pow_clog hb _) theorem lt_zpow_succ_log_self {b : β„•} (hb : 1 < b) (r : R) : r < (b : R) ^ (log b r + 1) := by rcases le_or_lt r 0 with hr | hr Β· rw [log_of_right_le_zero _ hr, zero_add, zpow_one] exact hr.trans_lt (zero_lt_one.trans_le <| mod_cast hb.le) rcases le_or_lt 1 r with hr1 | hr1 Β· rw [log_of_one_le_right _ hr1] rw [Int.ofNat_add_one_out, zpow_natCast, ← Nat.cast_pow] apply Nat.lt_of_floor_lt exact Nat.lt_pow_succ_log_self hb _ Β· rw [log_of_right_le_one _ hr1.le] have hcri : 1 < r⁻¹ := (one_lt_invβ‚€ hr).2 hr1 have : 1 ≀ Nat.clog b ⌈rβ»ΒΉβŒ‰β‚Š := Nat.succ_le_of_lt (Nat.clog_pos hb <| Nat.one_lt_cast.1 <| hcri.trans_le (Nat.le_ceil _)) rw [neg_add_eq_sub, ← neg_sub, ← Int.ofNat_one, ← Int.ofNat_sub this, zpow_neg, zpow_natCast, lt_inv_commβ‚€ hr (pow_pos (Nat.cast_pos.mpr <| zero_lt_one.trans hb) _), ← Nat.cast_pow] refine Nat.lt_ceil.1 ?_ exact Nat.pow_pred_clog_lt_self hb <| Nat.one_lt_cast.1 <| hcri.trans_le <| Nat.le_ceil _ @[simp] theorem log_zero_right (b : β„•) : log b (0 : R) = 0 := log_of_right_le_zero b le_rfl @[simp] theorem log_one_right (b : β„•) : log b (1 : R) = 0 := by rw [log_of_one_le_right _ le_rfl, Nat.floor_one, Nat.log_one_right, Int.ofNat_zero] omit [IsStrictOrderedRing R] in @[simp] theorem log_zero_left (r : R) : log 0 r = 0 := by simp only [log, Nat.log_zero_left, Nat.cast_zero, Nat.clog_zero_left, neg_zero, ite_self] omit [IsStrictOrderedRing R] in @[simp] theorem log_one_left (r : R) : log 1 r = 0 := by by_cases hr : 1 ≀ r Β· simp_all only [log, ↓reduceIte, Nat.log_one_left, Nat.cast_zero] Β· simp only [log, Nat.log_one_left, Nat.cast_zero, Nat.clog_one_left, neg_zero, ite_self] theorem log_zpow {b : β„•} (hb : 1 < b) (z : β„€) : log b (b ^ z : R) = z := by obtain ⟨n, rfl | rfl⟩ := Int.eq_nat_or_neg z Β· rw [log_of_one_le_right _ (one_le_zpowβ‚€ (mod_cast hb.le) <| Int.natCast_nonneg _), zpow_natCast, ← Nat.cast_pow, Nat.floor_natCast, Nat.log_pow hb] Β· rw [log_of_right_le_one _ (zpow_le_one_of_nonposβ‚€ (mod_cast hb.le) <| neg_nonpos.2 (Int.natCast_nonneg _)), zpow_neg, inv_inv, zpow_natCast, ← Nat.cast_pow, Nat.ceil_natCast, Nat.clog_pow _ _ hb] @[mono] theorem log_mono_right {b : β„•} {r₁ rβ‚‚ : R} (hβ‚€ : 0 < r₁) (h : r₁ ≀ rβ‚‚) : log b r₁ ≀ log b rβ‚‚ := by rcases le_total r₁ 1 with h₁ | h₁ <;> rcases le_total rβ‚‚ 1 with hβ‚‚ | hβ‚‚ Β· rw [log_of_right_le_one _ h₁, log_of_right_le_one _ hβ‚‚, neg_le_neg_iff, Int.ofNat_le] exact Nat.clog_mono_right _ (Nat.ceil_mono <| inv_antiβ‚€ hβ‚€ h) Β· rw [log_of_right_le_one _ h₁, log_of_one_le_right _ hβ‚‚] exact (neg_nonpos.mpr (Int.natCast_nonneg _)).trans (Int.natCast_nonneg _) Β· obtain rfl := le_antisymm h (hβ‚‚.trans h₁) rfl Β· rw [log_of_one_le_right _ h₁, log_of_one_le_right _ hβ‚‚, Int.ofNat_le] exact Nat.log_mono_right (Nat.floor_mono h) variable (R) in /-- Over suitable subtypes, `zpow` and `Int.log` form a galois coinsertion -/ def zpowLogGi {b : β„•} (hb : 1 < b) : GaloisCoinsertion (fun z : β„€ => Subtype.mk ((b : R) ^ z) <| zpow_pos (mod_cast zero_lt_one.trans hb) z) fun r : Set.Ioi (0 : R) => Int.log b (r : R) := GaloisCoinsertion.monotoneIntro (fun r₁ _ => log_mono_right r₁.2) (fun _ _ hz => Subtype.coe_le_coe.mp <| (zpow_right_strictMonoβ‚€ <| mod_cast hb).monotone hz) (fun r => Subtype.coe_le_coe.mp <| zpow_log_le_self hb r.2) fun _ => log_zpow (R := R) hb _ /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem lt_zpow_iff_log_lt {b : β„•} (hb : 1 < b) {x : β„€} {r : R} (hr : 0 < r) : r < (b : R) ^ x ↔ log b r < x := @GaloisConnection.lt_iff_lt _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ /-- `zpow b` and `Int.log b` (almost) form a Galois connection. -/ theorem zpow_le_iff_le_log {b : β„•} (hb : 1 < b) {x : β„€} {r : R} (hr : 0 < r) : (b : R) ^ x ≀ r ↔ x ≀ log b r := @GaloisConnection.le_iff_le _ _ _ _ _ _ (zpowLogGi R hb).gc x ⟨r, hr⟩ /-- The least power of `b` such that `r ≀ b ^ log b r`. -/ def clog (b : β„•) (r : R) : β„€ := if 1 ≀ r then Nat.clog b ⌈rβŒ‰β‚Š else -Nat.log b ⌊rβ»ΒΉβŒ‹β‚Š omit [IsStrictOrderedRing R] in theorem clog_of_one_le_right (b : β„•) {r : R} (hr : 1 ≀ r) : clog b r = Nat.clog b ⌈rβŒ‰β‚Š := if_pos hr theorem clog_of_right_le_one (b : β„•) {r : R} (hr : r ≀ 1) : clog b r = -Nat.log b ⌊rβ»ΒΉβŒ‹β‚Š := by obtain rfl | hr := hr.eq_or_lt Β· rw [clog, if_pos hr, inv_one, Nat.ceil_one, Nat.floor_one, Nat.log_one_right, Nat.clog_one_right, Int.ofNat_zero, neg_zero] Β· exact if_neg hr.not_le theorem clog_of_right_le_zero (b : β„•) {r : R} (hr : r ≀ 0) : clog b r = 0 := by rw [clog, if_neg (hr.trans_lt zero_lt_one).not_le, neg_eq_zero, Int.natCast_eq_zero, Nat.log_eq_zero_iff] rcases le_or_lt b 1 with hb | hb Β· exact Or.inr hb Β· refine Or.inl (lt_of_le_of_lt ?_ hb) exact Nat.floor_le_one_of_le_one ((inv_nonpos.2 hr).trans zero_le_one) @[simp] theorem clog_inv (b : β„•) (r : R) : clog b r⁻¹ = -log b r := by rcases lt_or_le 0 r with hrp | hrp Β· obtain hr | hr := le_total 1 r Β· rw [clog_of_right_le_one _ (inv_le_one_of_one_leβ‚€ hr), log_of_one_le_right _ hr, inv_inv] Β· rw [clog_of_one_le_right _ ((one_le_invβ‚€ hrp).2 hr), log_of_right_le_one _ hr, neg_neg] Β· rw [clog_of_right_le_zero _ (inv_nonpos.mpr hrp), log_of_right_le_zero _ hrp, neg_zero] @[simp] theorem log_inv (b : β„•) (r : R) : log b r⁻¹ = -clog b r := by rw [← inv_inv r, clog_inv, neg_neg, inv_inv] -- note this is useful for writing in reverse theorem neg_log_inv_eq_clog (b : β„•) (r : R) : -log b r⁻¹ = clog b r := by rw [log_inv, neg_neg] theorem neg_clog_inv_eq_log (b : β„•) (r : R) : -clog b r⁻¹ = log b r := by rw [clog_inv, neg_neg] @[simp, norm_cast] theorem clog_natCast (b : β„•) (n : β„•) : clog b (n : R) = Nat.clog b n := by rcases n with - | n Β· simp [clog_of_right_le_one] Β· rw [clog_of_one_le_right, (Nat.ceil_eq_iff (Nat.succ_ne_zero n)).mpr] <;> simp @[simp] theorem clog_ofNat (b : β„•) (n : β„•) [n.AtLeastTwo] : clog b (ofNat(n) : R) = Nat.clog b ofNat(n) := clog_natCast b n
Mathlib/Data/Int/Log.lean
228
228
theorem clog_of_left_le_one {b : β„•} (hb : b ≀ 1) (r : R) : clog b r = 0 := by
/- 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.Lemmas import Mathlib.MeasureTheory.Measure.Dirac /-! # 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 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 } namespace PMF instance instFunLike : FunLike (PMF Ξ±) Ξ± ℝβ‰₯0∞ where coe p a := p.1 a coe_injective' _ _ h := Subtype.eq h @[ext] protected theorem ext {p q : PMF Ξ±} (h : βˆ€ x, p x = q x) : p = q := DFunLike.ext p q h theorem hasSum_coe_one (p : PMF Ξ±) : HasSum p 1 := p.2 @[simp] theorem tsum_coe (p : PMF Ξ±) : βˆ‘' a, p a = 1 := p.hasSum_coe_one.tsum_eq theorem tsum_coe_ne_top (p : PMF Ξ±) : βˆ‘' a, p a β‰  ∞ := p.tsum_coe.symm β–Έ ENNReal.one_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 (ENNReal.tsum_le_tsum (fun _ => Set.indicator_apply_le fun _ => le_rfl)) (lt_of_le_of_ne le_top p.tsum_coe_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) /-- The support of a `PMF` is the set where it is nonzero. -/ def support (p : PMF Ξ±) : Set Ξ± := Function.support p @[simp] theorem mem_support_iff (p : PMF Ξ±) (a : Ξ±) : a ∈ p.support ↔ p a β‰  0 := Iff.rfl @[simp] theorem support_nonempty (p : PMF Ξ±) : p.support.Nonempty := Function.support_nonempty_iff.2 p.coe_ne_zero @[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] theorem apply_pos_iff (p : PMF Ξ±) (a : Ξ±) : 0 < p a ↔ a ∈ p.support := pos_iff_ne_zero.trans (p.mem_support_iff a).symm 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 classical have : 0 < βˆ‘' b, ite (b = a) 0 (p b) := lt_of_le_of_ne' zero_le' (ENNReal.summable.tsum_ne_zero_iff.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] theorem coe_le_one (p : PMF Ξ±) (a : Ξ±) : p a ≀ 1 := by classical 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] 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) theorem apply_lt_top (p : PMF Ξ±) (a : Ξ±) : p a < ∞ := lt_of_le_of_ne le_top (p.apply_ne_top a) 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 variable (p : PMF Ξ±) (s : Set Ξ±) theorem toOuterMeasure_apply : p.toOuterMeasure s = βˆ‘' x, s.indicator p x := tsum_congr fun x => smul_dirac_apply (p x) x s @[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) @[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) _ 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 ?_) Β· classical exact ite_eq_right_iff.2 fun hb' => False.elim <| hb hb' Β· classical exact ite_eq_left_iff.2 fun ha' => False.elim <| ha' rfl 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) @[simp] theorem toOuterMeasure_inj {p q : PMF Ξ±} : p.toOuterMeasure = q.toOuterMeasure ↔ p = q := toOuterMeasure_injective.eq_iff
Mathlib/Probability/ProbabilityMassFunction/Basic.lean
166
170
theorem toOuterMeasure_apply_eq_zero_iff : p.toOuterMeasure s = 0 ↔ Disjoint p.support s := by
rw [toOuterMeasure_apply, ENNReal.tsum_eq_zero] exact funext_iff.symm.trans Set.indicator_eq_zero' theorem toOuterMeasure_apply_eq_one_iff : p.toOuterMeasure s = 1 ↔ p.support βŠ† s := by
/- 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 -/ import Mathlib.Topology.Continuous import Mathlib.Topology.Defs.Induced /-! # Ordering on topologies and (co)induced topologies Topologies on a fixed type `Ξ±` are ordered, by reverse inclusion. That is, for topologies `t₁` and `tβ‚‚` on `Ξ±`, we write `t₁ ≀ tβ‚‚` if every set open in `tβ‚‚` is also open in `t₁`. (One also calls `t₁` *finer* than `tβ‚‚`, and `tβ‚‚` *coarser* than `t₁`.) Any function `f : Ξ± β†’ Ξ²` induces * `TopologicalSpace.induced f : TopologicalSpace Ξ² β†’ TopologicalSpace Ξ±`; * `TopologicalSpace.coinduced f : TopologicalSpace Ξ± β†’ TopologicalSpace Ξ²`. Continuity, the ordering on topologies and (co)induced topologies are related as follows: * The identity map `(Ξ±, t₁) β†’ (Ξ±, tβ‚‚)` is continuous iff `t₁ ≀ tβ‚‚`. * A map `f : (Ξ±, t) β†’ (Ξ², u)` is continuous * iff `t ≀ TopologicalSpace.induced f u` (`continuous_iff_le_induced`) * iff `TopologicalSpace.coinduced f t ≀ u` (`continuous_iff_coinduced_le`). Topologies on `Ξ±` form a complete lattice, with `βŠ₯` the discrete topology and `⊀` the indiscrete topology. For a function `f : Ξ± β†’ Ξ²`, `(TopologicalSpace.coinduced f, TopologicalSpace.induced f)` is a Galois connection between topologies on `Ξ±` and topologies on `Ξ²`. ## Implementation notes There is a Galois insertion between topologies on `Ξ±` (with the inclusion ordering) and all collections of sets in `Ξ±`. The complete lattice structure on topologies on `Ξ±` is defined as the reverse of the one obtained via this Galois insertion. More precisely, we use the corresponding Galois coinsertion between topologies on `Ξ±` (with the reversed inclusion ordering) and collections of sets in `Ξ±` (with the reversed inclusion ordering). ## Tags finer, coarser, induced topology, coinduced topology -/ open Function Set Filter Topology universe u v w namespace TopologicalSpace variable {Ξ± : Type u} /-- The open sets of the least topology containing a collection of basic sets. -/ inductive GenerateOpen (g : Set (Set Ξ±)) : Set Ξ± β†’ Prop | basic : βˆ€ s ∈ g, GenerateOpen g s | univ : GenerateOpen g univ | inter : βˆ€ s t, GenerateOpen g s β†’ GenerateOpen g t β†’ GenerateOpen g (s ∩ t) | sUnion : βˆ€ S : Set (Set Ξ±), (βˆ€ s ∈ S, GenerateOpen g s) β†’ GenerateOpen g (⋃₀ S) /-- The smallest topological space containing the collection `g` of basic sets -/ def generateFrom (g : Set (Set Ξ±)) : TopologicalSpace Ξ± where IsOpen := GenerateOpen g isOpen_univ := GenerateOpen.univ isOpen_inter := GenerateOpen.inter isOpen_sUnion := GenerateOpen.sUnion theorem isOpen_generateFrom_of_mem {g : Set (Set Ξ±)} {s : Set Ξ±} (hs : s ∈ g) : IsOpen[generateFrom g] s := GenerateOpen.basic s hs theorem nhds_generateFrom {g : Set (Set Ξ±)} {a : Ξ±} : @nhds Ξ± (generateFrom g) a = β¨… s ∈ { s | a ∈ s ∧ s ∈ g }, π“Ÿ s := by letI := generateFrom g rw [nhds_def] refine le_antisymm (biInf_mono fun s ⟨as, sg⟩ => ⟨as, .basic _ sg⟩) <| le_iInfβ‚‚ ?_ rintro s ⟨ha, hs⟩ induction hs with | basic _ hs => exact iInfβ‚‚_le _ ⟨ha, hs⟩ | univ => exact le_top.trans_eq principal_univ.symm | inter _ _ _ _ hs ht => exact (le_inf (hs ha.1) (ht ha.2)).trans_eq inf_principal | sUnion _ _ hS => let ⟨t, htS, hat⟩ := ha exact (hS t htS hat).trans (principal_mono.2 <| subset_sUnion_of_mem htS) lemma tendsto_nhds_generateFrom_iff {Ξ² : Type*} {m : Ξ± β†’ Ξ²} {f : Filter Ξ±} {g : Set (Set Ξ²)} {b : Ξ²} : Tendsto m f (@nhds Ξ² (generateFrom g) b) ↔ βˆ€ s ∈ g, b ∈ s β†’ m ⁻¹' s ∈ f := by simp only [nhds_generateFrom, @forall_swap (b ∈ _), tendsto_iInf, mem_setOf_eq, and_imp, tendsto_principal]; rfl /-- Construct a topology on Ξ± given the filter of neighborhoods of each point of Ξ±. -/ protected def mkOfNhds (n : Ξ± β†’ Filter Ξ±) : TopologicalSpace Ξ± where IsOpen s := βˆ€ a ∈ s, s ∈ n a isOpen_univ _ _ := univ_mem isOpen_inter := fun _s _t hs ht x ⟨hxs, hxt⟩ => inter_mem (hs x hxs) (ht x hxt) isOpen_sUnion := fun _s hs _a ⟨x, hx, hxa⟩ => mem_of_superset (hs x hx _ hxa) (subset_sUnion_of_mem hx) theorem nhds_mkOfNhds_of_hasBasis {n : Ξ± β†’ Filter Ξ±} {ΞΉ : Ξ± β†’ Sort*} {p : βˆ€ a, ΞΉ a β†’ Prop} {s : βˆ€ a, ΞΉ a β†’ Set Ξ±} (hb : βˆ€ a, (n a).HasBasis (p a) (s a)) (hpure : βˆ€ a i, p a i β†’ a ∈ s a i) (hopen : βˆ€ a i, p a i β†’ βˆ€αΆ  x in n a, s a i ∈ n x) (a : Ξ±) : @nhds Ξ± (.mkOfNhds n) a = n a := by let t : TopologicalSpace Ξ± := .mkOfNhds n apply le_antisymm Β· intro U hU replace hpure : pure ≀ n := fun x ↦ (hb x).ge_iff.2 (hpure x) refine mem_nhds_iff.2 ⟨{x | U ∈ n x}, fun x hx ↦ hpure x hx, fun x hx ↦ ?_, hU⟩ rcases (hb x).mem_iff.1 hx with ⟨i, hpi, hi⟩ exact (hopen x i hpi).mono fun y hy ↦ mem_of_superset hy hi Β· exact (nhds_basis_opens a).ge_iff.2 fun U ⟨haU, hUo⟩ ↦ hUo a haU theorem nhds_mkOfNhds (n : Ξ± β†’ Filter Ξ±) (a : Ξ±) (hβ‚€ : pure ≀ n) (h₁ : βˆ€ a, βˆ€ s ∈ n a, βˆ€αΆ  y in n a, s ∈ n y) : @nhds Ξ± (TopologicalSpace.mkOfNhds n) a = n a := nhds_mkOfNhds_of_hasBasis (fun a ↦ (n a).basis_sets) hβ‚€ h₁ _ theorem nhds_mkOfNhds_single [DecidableEq Ξ±] {aβ‚€ : Ξ±} {l : Filter Ξ±} (h : pure aβ‚€ ≀ l) (b : Ξ±) : @nhds Ξ± (TopologicalSpace.mkOfNhds (update pure aβ‚€ l)) b = (update pure aβ‚€ l : Ξ± β†’ Filter Ξ±) b := by refine nhds_mkOfNhds _ _ (le_update_iff.mpr ⟨h, fun _ _ => le_rfl⟩) fun a s hs => ?_ rcases eq_or_ne a aβ‚€ with (rfl | ha) Β· filter_upwards [hs] with b hb rcases eq_or_ne b a with (rfl | hb) Β· exact hs Β· rwa [update_of_ne hb] Β· simpa only [update_of_ne ha, mem_pure, eventually_pure] using hs theorem nhds_mkOfNhds_filterBasis (B : Ξ± β†’ FilterBasis Ξ±) (a : Ξ±) (hβ‚€ : βˆ€ x, βˆ€ n ∈ B x, x ∈ n) (h₁ : βˆ€ x, βˆ€ n ∈ B x, βˆƒ n₁ ∈ B x, βˆ€ x' ∈ n₁, βˆƒ nβ‚‚ ∈ B x', nβ‚‚ βŠ† n) : @nhds Ξ± (TopologicalSpace.mkOfNhds fun x => (B x).filter) a = (B a).filter := nhds_mkOfNhds_of_hasBasis (fun a ↦ (B a).hasBasis) hβ‚€ h₁ a section Lattice variable {Ξ± : Type u} {Ξ² : Type v} /-- The ordering on topologies on the type `Ξ±`. `t ≀ s` if every set open in `s` is also open in `t` (`t` is finer than `s`). -/ instance : PartialOrder (TopologicalSpace Ξ±) := { PartialOrder.lift (fun t => OrderDual.toDual IsOpen[t]) (fun _ _ => TopologicalSpace.ext) with le := fun s t => βˆ€ U, IsOpen[t] U β†’ IsOpen[s] U } protected theorem le_def {Ξ±} {t s : TopologicalSpace Ξ±} : t ≀ s ↔ IsOpen[s] ≀ IsOpen[t] := Iff.rfl theorem le_generateFrom_iff_subset_isOpen {g : Set (Set Ξ±)} {t : TopologicalSpace Ξ±} : t ≀ generateFrom g ↔ g βŠ† { s | IsOpen[t] s } := ⟨fun ht s hs => ht _ <| .basic s hs, fun hg _s hs => hs.recOn (fun _ h => hg h) isOpen_univ (fun _ _ _ _ => IsOpen.inter) fun _ _ => isOpen_sUnion⟩ /-- If `s` equals the collection of open sets in the topology it generates, then `s` defines a topology. -/ protected def mkOfClosure (s : Set (Set Ξ±)) (hs : { u | GenerateOpen s u } = s) : TopologicalSpace Ξ± where IsOpen u := u ∈ s isOpen_univ := hs β–Έ TopologicalSpace.GenerateOpen.univ isOpen_inter := hs β–Έ TopologicalSpace.GenerateOpen.inter isOpen_sUnion := hs β–Έ TopologicalSpace.GenerateOpen.sUnion theorem mkOfClosure_sets {s : Set (Set Ξ±)} {hs : { u | GenerateOpen s u } = s} : TopologicalSpace.mkOfClosure s hs = generateFrom s := TopologicalSpace.ext hs.symm theorem gc_generateFrom (Ξ±) : GaloisConnection (fun t : TopologicalSpace Ξ± => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) := fun _ _ => le_generateFrom_iff_subset_isOpen.symm /-- The Galois coinsertion between `TopologicalSpace Ξ±` and `(Set (Set Ξ±))α΅’α΅ˆ` whose lower part sends a topology to its collection of open subsets, and whose upper part sends a collection of subsets of `Ξ±` to the topology they generate. -/ def gciGenerateFrom (Ξ± : Type*) : GaloisCoinsertion (fun t : TopologicalSpace Ξ± => OrderDual.toDual { s | IsOpen[t] s }) (generateFrom ∘ OrderDual.ofDual) where gc := gc_generateFrom Ξ± u_l_le _ s hs := TopologicalSpace.GenerateOpen.basic s hs choice g hg := TopologicalSpace.mkOfClosure g (Subset.antisymm hg <| le_generateFrom_iff_subset_isOpen.1 <| le_rfl) choice_eq _ _ := mkOfClosure_sets /-- Topologies on `Ξ±` form a complete lattice, with `βŠ₯` the discrete topology and `⊀` the indiscrete topology. The infimum of a collection of topologies is the topology generated by all their open sets, while the supremum is the topology whose open sets are those sets open in every member of the collection. -/ instance : CompleteLattice (TopologicalSpace Ξ±) := (gciGenerateFrom Ξ±).liftCompleteLattice @[mono, gcongr] theorem generateFrom_anti {Ξ±} {g₁ gβ‚‚ : Set (Set Ξ±)} (h : g₁ βŠ† gβ‚‚) : generateFrom gβ‚‚ ≀ generateFrom g₁ := (gc_generateFrom _).monotone_u h theorem generateFrom_setOf_isOpen (t : TopologicalSpace Ξ±) : generateFrom { s | IsOpen[t] s } = t := (gciGenerateFrom Ξ±).u_l_eq t theorem leftInverse_generateFrom : LeftInverse generateFrom fun t : TopologicalSpace Ξ± => { s | IsOpen[t] s } := (gciGenerateFrom Ξ±).u_l_leftInverse theorem generateFrom_surjective : Surjective (generateFrom : Set (Set Ξ±) β†’ TopologicalSpace Ξ±) := (gciGenerateFrom Ξ±).u_surjective theorem setOf_isOpen_injective : Injective fun t : TopologicalSpace Ξ± => { s | IsOpen[t] s } := (gciGenerateFrom Ξ±).l_injective end Lattice end TopologicalSpace section Lattice variable {Ξ± : Type*} {t t₁ tβ‚‚ : TopologicalSpace Ξ±} {s : Set Ξ±} theorem IsOpen.mono (hs : IsOpen[tβ‚‚] s) (h : t₁ ≀ tβ‚‚) : IsOpen[t₁] s := h s hs theorem IsClosed.mono (hs : IsClosed[tβ‚‚] s) (h : t₁ ≀ tβ‚‚) : IsClosed[t₁] s := (@isOpen_compl_iff Ξ± s t₁).mp <| hs.isOpen_compl.mono h theorem closure.mono (h : t₁ ≀ tβ‚‚) : closure[t₁] s βŠ† closure[tβ‚‚] s := @closure_minimal _ t₁ s (@closure _ tβ‚‚ s) subset_closure (IsClosed.mono isClosed_closure h) theorem isOpen_implies_isOpen_iff : (βˆ€ s, IsOpen[t₁] s β†’ IsOpen[tβ‚‚] s) ↔ tβ‚‚ ≀ t₁ := Iff.rfl /-- The only open sets in the indiscrete topology are the empty set and the whole space. -/ theorem TopologicalSpace.isOpen_top_iff {Ξ±} (U : Set Ξ±) : IsOpen[⊀] U ↔ U = βˆ… ∨ U = univ := ⟨fun h => by induction h with | basic _ h => exact False.elim h | univ => exact .inr rfl | inter _ _ _ _ h₁ hβ‚‚ => rcases h₁ with (rfl | rfl) <;> rcases hβ‚‚ with (rfl | rfl) <;> simp | sUnion _ _ ih => exact sUnion_mem_empty_univ ih, by rintro (rfl | rfl) exacts [@isOpen_empty _ ⊀, @isOpen_univ _ ⊀]⟩ /-- A topological space is discrete if every set is open, that is, its topology equals the discrete topology `βŠ₯`. -/ class DiscreteTopology (Ξ± : Type*) [t : TopologicalSpace Ξ±] : Prop where /-- The `TopologicalSpace` structure on a type with discrete topology is equal to `βŠ₯`. -/ eq_bot : t = βŠ₯ theorem discreteTopology_bot (Ξ± : Type*) : @DiscreteTopology Ξ± βŠ₯ := @DiscreteTopology.mk Ξ± βŠ₯ rfl section DiscreteTopology variable [TopologicalSpace Ξ±] [DiscreteTopology Ξ±] {Ξ² : Type*} @[simp] theorem isOpen_discrete (s : Set Ξ±) : IsOpen s := (@DiscreteTopology.eq_bot Ξ± _).symm β–Έ trivial @[simp] theorem isClosed_discrete (s : Set Ξ±) : IsClosed s := ⟨isOpen_discrete _⟩ theorem closure_discrete (s : Set Ξ±) : closure s = s := (isClosed_discrete _).closure_eq @[simp] theorem dense_discrete {s : Set Ξ±} : Dense s ↔ s = univ := by simp [dense_iff_closure_eq] @[simp] theorem denseRange_discrete {ΞΉ : Type*} {f : ΞΉ β†’ Ξ±} : DenseRange f ↔ Surjective f := by rw [DenseRange, dense_discrete, range_eq_univ] @[nontriviality, continuity, fun_prop] theorem continuous_of_discreteTopology [TopologicalSpace Ξ²] {f : Ξ± β†’ Ξ²} : Continuous f := continuous_def.2 fun _ _ => isOpen_discrete _ /-- A function to a discrete topological space is continuous if and only if the preimage of every singleton is open. -/ theorem continuous_discrete_rng {Ξ±} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [DiscreteTopology Ξ²] {f : Ξ± β†’ Ξ²} : Continuous f ↔ βˆ€ b : Ξ², IsOpen (f ⁻¹' {b}) := ⟨fun h _ => (isOpen_discrete _).preimage h, fun h => ⟨fun s _ => by rw [← biUnion_of_singleton s, preimage_iUnionβ‚‚] exact isOpen_biUnion fun _ _ => h _⟩⟩ @[simp] theorem nhds_discrete (Ξ± : Type*) [TopologicalSpace Ξ±] [DiscreteTopology Ξ±] : @nhds Ξ± _ = pure := le_antisymm (fun _ s hs => (isOpen_discrete s).mem_nhds hs) pure_le_nhds theorem mem_nhds_discrete {x : Ξ±} {s : Set Ξ±} : s ∈ 𝓝 x ↔ x ∈ s := by rw [nhds_discrete, mem_pure] end DiscreteTopology theorem le_of_nhds_le_nhds (h : βˆ€ x, @nhds Ξ± t₁ x ≀ @nhds Ξ± tβ‚‚ x) : t₁ ≀ tβ‚‚ := fun s => by rw [@isOpen_iff_mem_nhds _ t₁, @isOpen_iff_mem_nhds _ tβ‚‚] exact fun hs a ha => h _ (hs _ ha) theorem eq_bot_of_singletons_open {t : TopologicalSpace Ξ±} (h : βˆ€ x, IsOpen[t] {x}) : t = βŠ₯ := bot_unique fun s _ => biUnion_of_singleton s β–Έ isOpen_biUnion fun x _ => h x theorem forall_open_iff_discrete {X : Type*} [TopologicalSpace X] : (βˆ€ s : Set X, IsOpen s) ↔ DiscreteTopology X := ⟨fun h => ⟨eq_bot_of_singletons_open fun _ => h _⟩, @isOpen_discrete _ _⟩ theorem discreteTopology_iff_forall_isClosed [TopologicalSpace Ξ±] : DiscreteTopology Ξ± ↔ βˆ€ s : Set Ξ±, IsClosed s := forall_open_iff_discrete.symm.trans <| compl_surjective.forall.trans <| forall_congr' fun _ ↦ isOpen_compl_iff theorem singletons_open_iff_discrete {X : Type*} [TopologicalSpace X] : (βˆ€ a : X, IsOpen ({a} : Set X)) ↔ DiscreteTopology X := ⟨fun h => ⟨eq_bot_of_singletons_open h⟩, fun a _ => @isOpen_discrete _ _ a _⟩ theorem DiscreteTopology.of_finite_of_isClosed_singleton [TopologicalSpace Ξ±] [Finite Ξ±] (h : βˆ€ a : Ξ±, IsClosed {a}) : DiscreteTopology Ξ± := discreteTopology_iff_forall_isClosed.mpr fun s ↦ s.iUnion_of_singleton_coe β–Έ isClosed_iUnion_of_finite fun _ ↦ h _ theorem discreteTopology_iff_singleton_mem_nhds [TopologicalSpace Ξ±] : DiscreteTopology Ξ± ↔ βˆ€ x : Ξ±, {x} ∈ 𝓝 x := by simp only [← singletons_open_iff_discrete, isOpen_iff_mem_nhds, mem_singleton_iff, forall_eq] /-- This lemma characterizes discrete topological spaces as those whose singletons are neighbourhoods. -/ theorem discreteTopology_iff_nhds [TopologicalSpace Ξ±] : DiscreteTopology Ξ± ↔ βˆ€ x : Ξ±, 𝓝 x = pure x := by simp [discreteTopology_iff_singleton_mem_nhds, le_pure_iff] apply forall_congr' (fun x ↦ ?_) simp [le_antisymm_iff, pure_le_nhds x] theorem discreteTopology_iff_nhds_ne [TopologicalSpace Ξ±] : DiscreteTopology Ξ± ↔ βˆ€ x : Ξ±, 𝓝[β‰ ] x = βŠ₯ := by simp only [discreteTopology_iff_singleton_mem_nhds, nhdsWithin, inf_principal_eq_bot, compl_compl] /-- If the codomain of a continuous injective function has discrete topology, then so does the domain. See also `Embedding.discreteTopology` for an important special case. -/ theorem DiscreteTopology.of_continuous_injective {Ξ² : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [DiscreteTopology Ξ²] {f : Ξ± β†’ Ξ²} (hc : Continuous f) (hinj : Injective f) : DiscreteTopology Ξ± := forall_open_iff_discrete.1 fun s ↦ hinj.preimage_image s β–Έ (isOpen_discrete _).preimage hc end Lattice section GaloisConnection variable {Ξ± Ξ² Ξ³ : Type*} theorem isOpen_induced_iff [t : TopologicalSpace Ξ²] {s : Set Ξ±} {f : Ξ± β†’ Ξ²} : IsOpen[t.induced f] s ↔ βˆƒ t, IsOpen t ∧ f ⁻¹' t = s := Iff.rfl theorem isClosed_induced_iff [t : TopologicalSpace Ξ²] {s : Set Ξ±} {f : Ξ± β†’ Ξ²} : IsClosed[t.induced f] s ↔ βˆƒ t, IsClosed t ∧ f ⁻¹' t = s := by letI := t.induced f simp only [← isOpen_compl_iff, isOpen_induced_iff] exact compl_surjective.exists.trans (by simp only [preimage_compl, compl_inj_iff]) theorem isOpen_coinduced {t : TopologicalSpace Ξ±} {s : Set Ξ²} {f : Ξ± β†’ Ξ²} : IsOpen[t.coinduced f] s ↔ IsOpen (f ⁻¹' s) := Iff.rfl theorem isClosed_coinduced {t : TopologicalSpace Ξ±} {s : Set Ξ²} {f : Ξ± β†’ Ξ²} : IsClosed[t.coinduced f] s ↔ IsClosed (f ⁻¹' s) := by simp only [← isOpen_compl_iff, isOpen_coinduced (f := f), preimage_compl] theorem preimage_nhds_coinduced [TopologicalSpace Ξ±] {Ο€ : Ξ± β†’ Ξ²} {s : Set Ξ²} {a : Ξ±} (hs : s ∈ @nhds Ξ² (TopologicalSpace.coinduced Ο€ β€Ή_β€Ί) (Ο€ a)) : Ο€ ⁻¹' s ∈ 𝓝 a := by letI := TopologicalSpace.coinduced Ο€ β€Ή_β€Ί rcases mem_nhds_iff.mp hs with ⟨V, hVs, V_op, mem_V⟩ exact mem_nhds_iff.mpr βŸ¨Ο€ ⁻¹' V, Set.preimage_mono hVs, V_op, mem_V⟩ variable {t t₁ tβ‚‚ : TopologicalSpace Ξ±} {t' : TopologicalSpace Ξ²} {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ±} theorem Continuous.coinduced_le (h : Continuous[t, t'] f) : t.coinduced f ≀ t' := (@continuous_def Ξ± Ξ² t t').1 h theorem coinduced_le_iff_le_induced {f : Ξ± β†’ Ξ²} {tΞ± : TopologicalSpace Ξ±} {tΞ² : TopologicalSpace Ξ²} : tΞ±.coinduced f ≀ tΞ² ↔ tΞ± ≀ tΞ².induced f := ⟨fun h _s ⟨_t, ht, hst⟩ => hst β–Έ h _ ht, fun h s hs => h _ ⟨s, hs, rfl⟩⟩ theorem Continuous.le_induced (h : Continuous[t, t'] f) : t ≀ t'.induced f := coinduced_le_iff_le_induced.1 h.coinduced_le theorem gc_coinduced_induced (f : Ξ± β†’ Ξ²) : GaloisConnection (TopologicalSpace.coinduced f) (TopologicalSpace.induced f) := fun _ _ => coinduced_le_iff_le_induced theorem induced_mono (h : t₁ ≀ tβ‚‚) : t₁.induced g ≀ tβ‚‚.induced g := (gc_coinduced_induced g).monotone_u h theorem coinduced_mono (h : t₁ ≀ tβ‚‚) : t₁.coinduced f ≀ tβ‚‚.coinduced f := (gc_coinduced_induced f).monotone_l h @[simp] theorem induced_top : (⊀ : TopologicalSpace Ξ±).induced g = ⊀ := (gc_coinduced_induced g).u_top @[simp] theorem induced_inf : (t₁ βŠ“ tβ‚‚).induced g = t₁.induced g βŠ“ tβ‚‚.induced g := (gc_coinduced_induced g).u_inf @[simp] theorem induced_iInf {ΞΉ : Sort w} {t : ΞΉ β†’ TopologicalSpace Ξ±} : (β¨… i, t i).induced g = β¨… i, (t i).induced g := (gc_coinduced_induced g).u_iInf @[simp] theorem induced_sInf {s : Set (TopologicalSpace Ξ±)} : TopologicalSpace.induced g (sInf s) = sInf (TopologicalSpace.induced g '' s) := by rw [sInf_eq_iInf', sInf_image', induced_iInf] @[simp] theorem coinduced_bot : (βŠ₯ : TopologicalSpace Ξ±).coinduced f = βŠ₯ := (gc_coinduced_induced f).l_bot @[simp] theorem coinduced_sup : (t₁ βŠ” tβ‚‚).coinduced f = t₁.coinduced f βŠ” tβ‚‚.coinduced f := (gc_coinduced_induced f).l_sup @[simp] theorem coinduced_iSup {ΞΉ : Sort w} {t : ΞΉ β†’ TopologicalSpace Ξ±} : (⨆ i, t i).coinduced f = ⨆ i, (t i).coinduced f := (gc_coinduced_induced f).l_iSup @[simp] theorem coinduced_sSup {s : Set (TopologicalSpace Ξ±)} : TopologicalSpace.coinduced f (sSup s) = sSup ((TopologicalSpace.coinduced f) '' s) := by rw [sSup_eq_iSup', sSup_image', coinduced_iSup] theorem induced_id [t : TopologicalSpace Ξ±] : t.induced id = t := TopologicalSpace.ext <| funext fun s => propext <| ⟨fun ⟨_, hs, h⟩ => h β–Έ hs, fun hs => ⟨s, hs, rfl⟩⟩ theorem induced_compose {tΞ³ : TopologicalSpace Ξ³} {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ³} : (tΞ³.induced g).induced f = tΞ³.induced (g ∘ f) := TopologicalSpace.ext <| funext fun _ => propext ⟨fun ⟨_, ⟨s, hs, hβ‚‚βŸ©, hβ‚βŸ© => h₁ β–Έ hβ‚‚ β–Έ ⟨s, hs, rfl⟩, fun ⟨s, hs, h⟩ => ⟨preimage g s, ⟨s, hs, rfl⟩, h β–Έ rfl⟩⟩ theorem induced_const [t : TopologicalSpace Ξ±] {x : Ξ±} : (t.induced fun _ : Ξ² => x) = ⊀ := le_antisymm le_top (@continuous_const Ξ² Ξ± ⊀ t x).le_induced theorem coinduced_id [t : TopologicalSpace Ξ±] : t.coinduced id = t := TopologicalSpace.ext rfl theorem coinduced_compose [tΞ± : TopologicalSpace Ξ±] {f : Ξ± β†’ Ξ²} {g : Ξ² β†’ Ξ³} : (tΞ±.coinduced f).coinduced g = tΞ±.coinduced (g ∘ f) := TopologicalSpace.ext rfl theorem Equiv.induced_symm {Ξ± Ξ² : Type*} (e : Ξ± ≃ Ξ²) : TopologicalSpace.induced e.symm = TopologicalSpace.coinduced e := by ext t U rw [isOpen_induced_iff, isOpen_coinduced] simp only [e.symm.preimage_eq_iff_eq_image, exists_eq_right, ← preimage_equiv_eq_image_symm] theorem Equiv.coinduced_symm {Ξ± Ξ² : Type*} (e : Ξ± ≃ Ξ²) : TopologicalSpace.coinduced e.symm = TopologicalSpace.induced e := e.symm.induced_symm.symm end GaloisConnection -- constructions using the complete lattice structure section Constructions open TopologicalSpace variable {Ξ± : Type u} {Ξ² : Type v} instance inhabitedTopologicalSpace {Ξ± : Type u} : Inhabited (TopologicalSpace Ξ±) := ⟨βŠ₯⟩ instance (priority := 100) Subsingleton.uniqueTopologicalSpace [Subsingleton Ξ±] : Unique (TopologicalSpace Ξ±) where default := βŠ₯ uniq t := eq_bot_of_singletons_open fun x => Subsingleton.set_cases (@isOpen_empty _ t) (@isOpen_univ _ t) ({x} : Set Ξ±) instance (priority := 100) Subsingleton.discreteTopology [t : TopologicalSpace Ξ±] [Subsingleton Ξ±] : DiscreteTopology Ξ± := ⟨Unique.eq_default t⟩ instance : TopologicalSpace Empty := βŠ₯ instance : DiscreteTopology Empty := ⟨rfl⟩ instance : TopologicalSpace PEmpty := βŠ₯ instance : DiscreteTopology PEmpty := ⟨rfl⟩ instance : TopologicalSpace PUnit := βŠ₯ instance : DiscreteTopology PUnit := ⟨rfl⟩ instance : TopologicalSpace Bool := βŠ₯ instance : DiscreteTopology Bool := ⟨rfl⟩ instance : TopologicalSpace β„• := βŠ₯ instance : DiscreteTopology β„• := ⟨rfl⟩ instance : TopologicalSpace β„€ := βŠ₯ instance : DiscreteTopology β„€ := ⟨rfl⟩ instance {n} : TopologicalSpace (Fin n) := βŠ₯ instance {n} : DiscreteTopology (Fin n) := ⟨rfl⟩ instance sierpinskiSpace : TopologicalSpace Prop := generateFrom {{True}} /-- See also `continuous_of_discreteTopology`, which works for `IsEmpty Ξ±`. -/ theorem continuous_empty_function [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] [IsEmpty Ξ²] (f : Ξ± β†’ Ξ²) : Continuous f := letI := Function.isEmpty f continuous_of_discreteTopology theorem le_generateFrom {t : TopologicalSpace Ξ±} {g : Set (Set Ξ±)} (h : βˆ€ s ∈ g, IsOpen s) : t ≀ generateFrom g := le_generateFrom_iff_subset_isOpen.2 h theorem induced_generateFrom_eq {Ξ± Ξ²} {b : Set (Set Ξ²)} {f : Ξ± β†’ Ξ²} : (generateFrom b).induced f = generateFrom (preimage f '' b) := le_antisymm (le_generateFrom <| forall_mem_image.2 fun s hs => ⟨s, GenerateOpen.basic _ hs, rfl⟩) (coinduced_le_iff_le_induced.1 <| le_generateFrom fun _s hs => .basic _ (mem_image_of_mem _ hs)) theorem le_induced_generateFrom {Ξ± Ξ²} [t : TopologicalSpace Ξ±] {b : Set (Set Ξ²)} {f : Ξ± β†’ Ξ²} (h : βˆ€ a : Set Ξ², a ∈ b β†’ IsOpen (f ⁻¹' a)) : t ≀ induced f (generateFrom b) := by rw [induced_generateFrom_eq] apply le_generateFrom simp only [mem_image, and_imp, forall_apply_eq_imp_iffβ‚‚, exists_imp] exact h lemma generateFrom_insert_of_generateOpen {Ξ± : Type*} {s : Set (Set Ξ±)} {t : Set Ξ±} (ht : GenerateOpen s t) : generateFrom (insert t s) = generateFrom s := by refine le_antisymm (generateFrom_anti <| subset_insert t s) (le_generateFrom ?_) rintro t (rfl | h) Β· exact ht Β· exact isOpen_generateFrom_of_mem h @[simp] lemma generateFrom_insert_univ {Ξ± : Type*} {s : Set (Set Ξ±)} : generateFrom (insert univ s) = generateFrom s := generateFrom_insert_of_generateOpen .univ @[simp] lemma generateFrom_insert_empty {Ξ± : Type*} {s : Set (Set Ξ±)} : generateFrom (insert βˆ… s) = generateFrom s := by rw [← sUnion_empty] exact generateFrom_insert_of_generateOpen (.sUnion βˆ… (fun s_1 a ↦ False.elim a)) /-- This construction is left adjoint to the operation sending a topology on `Ξ±` to its neighborhood filter at a fixed point `a : Ξ±`. -/ def nhdsAdjoint (a : Ξ±) (f : Filter Ξ±) : TopologicalSpace Ξ± where IsOpen s := a ∈ s β†’ s ∈ f isOpen_univ _ := univ_mem isOpen_inter := fun _s _t hs ht ⟨has, hat⟩ => inter_mem (hs has) (ht hat) isOpen_sUnion := fun _k hk ⟨u, hu, hau⟩ => mem_of_superset (hk u hu hau) (subset_sUnion_of_mem hu) theorem gc_nhds (a : Ξ±) : GaloisConnection (nhdsAdjoint a) fun t => @nhds Ξ± t a := fun f t => by rw [le_nhds_iff] exact ⟨fun H s hs has => H _ has hs, fun H s has hs => H _ hs has⟩ theorem nhds_mono {t₁ tβ‚‚ : TopologicalSpace Ξ±} {a : Ξ±} (h : t₁ ≀ tβ‚‚) : @nhds Ξ± t₁ a ≀ @nhds Ξ± tβ‚‚ a := (gc_nhds a).monotone_u h theorem le_iff_nhds {Ξ± : Type*} (t t' : TopologicalSpace Ξ±) : t ≀ t' ↔ βˆ€ x, @nhds Ξ± t x ≀ @nhds Ξ± t' x := ⟨fun h _ => nhds_mono h, le_of_nhds_le_nhds⟩ theorem isOpen_singleton_nhdsAdjoint {Ξ± : Type*} {a b : Ξ±} (f : Filter Ξ±) (hb : b β‰  a) : IsOpen[nhdsAdjoint a f] {b} := fun h ↦ absurd h hb.symm theorem nhds_nhdsAdjoint_same (a : Ξ±) (f : Filter Ξ±) : @nhds Ξ± (nhdsAdjoint a f) a = pure a βŠ” f := by let _ := nhdsAdjoint a f apply le_antisymm Β· rintro t ⟨hat : a ∈ t, htf : t ∈ f⟩ exact IsOpen.mem_nhds (fun _ ↦ htf) hat Β· exact sup_le (pure_le_nhds _) ((gc_nhds a).le_u_l f) theorem nhds_nhdsAdjoint_of_ne {a b : Ξ±} (f : Filter Ξ±) (h : b β‰  a) : @nhds Ξ± (nhdsAdjoint a f) b = pure b := let _ := nhdsAdjoint a f (isOpen_singleton_iff_nhds_eq_pure _).1 <| isOpen_singleton_nhdsAdjoint f h theorem nhds_nhdsAdjoint [DecidableEq Ξ±] (a : Ξ±) (f : Filter Ξ±) : @nhds Ξ± (nhdsAdjoint a f) = update pure a (pure a βŠ” f) := eq_update_iff.2 ⟨nhds_nhdsAdjoint_same .., fun _ ↦ nhds_nhdsAdjoint_of_ne _⟩ theorem le_nhdsAdjoint_iff' {a : Ξ±} {f : Filter Ξ±} {t : TopologicalSpace Ξ±} : t ≀ nhdsAdjoint a f ↔ @nhds Ξ± t a ≀ pure a βŠ” f ∧ βˆ€ b β‰  a, @nhds Ξ± t b = pure b := by classical simp_rw [le_iff_nhds, nhds_nhdsAdjoint, forall_update_iff, (pure_le_nhds _).le_iff_eq] theorem le_nhdsAdjoint_iff {Ξ± : Type*} (a : Ξ±) (f : Filter Ξ±) (t : TopologicalSpace Ξ±) : t ≀ nhdsAdjoint a f ↔ @nhds Ξ± t a ≀ pure a βŠ” f ∧ βˆ€ b β‰  a, IsOpen[t] {b} := by simp only [le_nhdsAdjoint_iff', @isOpen_singleton_iff_nhds_eq_pure Ξ± t] theorem nhds_iInf {ΞΉ : Sort*} {t : ΞΉ β†’ TopologicalSpace Ξ±} {a : Ξ±} : @nhds Ξ± (iInf t) a = β¨… i, @nhds Ξ± (t i) a := (gc_nhds a).u_iInf theorem nhds_sInf {s : Set (TopologicalSpace Ξ±)} {a : Ξ±} : @nhds Ξ± (sInf s) a = β¨… t ∈ s, @nhds Ξ± t a := (gc_nhds a).u_sInf -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: timeouts without `b₁ := t₁` theorem nhds_inf {t₁ tβ‚‚ : TopologicalSpace Ξ±} {a : Ξ±} : @nhds Ξ± (t₁ βŠ“ tβ‚‚) a = @nhds Ξ± t₁ a βŠ“ @nhds Ξ± tβ‚‚ a := (gc_nhds a).u_inf (b₁ := t₁) theorem nhds_top {a : Ξ±} : @nhds Ξ± ⊀ a = ⊀ := (gc_nhds a).u_top theorem isOpen_sup {t₁ tβ‚‚ : TopologicalSpace Ξ±} {s : Set Ξ±} : IsOpen[t₁ βŠ” tβ‚‚] s ↔ IsOpen[t₁] s ∧ IsOpen[tβ‚‚] s := Iff.rfl open TopologicalSpace variable {Ξ³ : Type*} {f : Ξ± β†’ Ξ²} {ΞΉ : Sort*} theorem continuous_iff_coinduced_le {t₁ : TopologicalSpace Ξ±} {tβ‚‚ : TopologicalSpace Ξ²} : Continuous[t₁, tβ‚‚] f ↔ coinduced f t₁ ≀ tβ‚‚ := continuous_def theorem continuous_iff_le_induced {t₁ : TopologicalSpace Ξ±} {tβ‚‚ : TopologicalSpace Ξ²} : Continuous[t₁, tβ‚‚] f ↔ t₁ ≀ induced f tβ‚‚ := Iff.trans continuous_iff_coinduced_le (gc_coinduced_induced f _ _) lemma continuous_generateFrom_iff {t : TopologicalSpace Ξ±} {b : Set (Set Ξ²)} : Continuous[t, generateFrom b] f ↔ βˆ€ s ∈ b, IsOpen (f ⁻¹' s) := by rw [continuous_iff_coinduced_le, le_generateFrom_iff_subset_isOpen] simp only [isOpen_coinduced, preimage_id', subset_def, mem_setOf] @[continuity, fun_prop] theorem continuous_induced_dom {t : TopologicalSpace Ξ²} : Continuous[induced f t, t] f := continuous_iff_le_induced.2 le_rfl theorem continuous_induced_rng {g : Ξ³ β†’ Ξ±} {tβ‚‚ : TopologicalSpace Ξ²} {t₁ : TopologicalSpace Ξ³} : Continuous[t₁, induced f tβ‚‚] g ↔ Continuous[t₁, tβ‚‚] (f ∘ g) := by simp only [continuous_iff_le_induced, induced_compose] theorem continuous_coinduced_rng {t : TopologicalSpace Ξ±} : Continuous[t, coinduced f t] f := continuous_iff_coinduced_le.2 le_rfl theorem continuous_coinduced_dom {g : Ξ² β†’ Ξ³} {t₁ : TopologicalSpace Ξ±} {tβ‚‚ : TopologicalSpace Ξ³} : Continuous[coinduced f t₁, tβ‚‚] g ↔ Continuous[t₁, tβ‚‚] (g ∘ f) := by simp only [continuous_iff_coinduced_le, coinduced_compose]
Mathlib/Topology/Order.lean
644
646
theorem continuous_le_dom {t₁ tβ‚‚ : TopologicalSpace Ξ±} {t₃ : TopologicalSpace Ξ²} (h₁ : tβ‚‚ ≀ t₁) (hβ‚‚ : Continuous[t₁, t₃] f) : Continuous[tβ‚‚, t₃] f := by
rw [continuous_iff_le_induced] at hβ‚‚ ⊒
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, SΓ©bastien GouΓ«zel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.FDeriv.Linear import Mathlib.Analysis.Calculus.FDeriv.Comp /-! # Additive operations on derivatives For detailed documentation of the FrΓ©chet derivative, see the module docstring of `Analysis/Calculus/FDeriv/Basic.lean`. This file contains the usual formulas (and existence assertions) for the derivative of * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions -/ open Filter Asymptotics ContinuousLinearMap noncomputable section section variable {π•œ : Type*} [NontriviallyNormedField π•œ] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace π•œ E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace π•œ F] variable {f g : E β†’ F} variable {f' g' : E β†’L[π•œ] F} variable {x : E} variable {s : Set E} variable {L : Filter E} section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass π•œ R F] [ContinuousConstSMul R F] /-! ### Derivative of a function multiplied by a constant -/ @[fun_prop] theorem HasStrictFDerivAt.const_smul (h : HasStrictFDerivAt f f' x) (c : R) : HasStrictFDerivAt (fun x => c β€’ f x) (c β€’ f') x := (c β€’ (1 : F β†’L[π•œ] F)).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.const_smul (h : HasFDerivAtFilter f f' x L) (c : R) : HasFDerivAtFilter (fun x => c β€’ f x) (c β€’ f') x L := (c β€’ (1 : F β†’L[π•œ] F)).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.const_smul (h : HasFDerivWithinAt f f' s x) (c : R) : HasFDerivWithinAt (fun x => c β€’ f x) (c β€’ f') s x := h.const_smul c @[fun_prop] nonrec theorem HasFDerivAt.const_smul (h : HasFDerivAt f f' x) (c : R) : HasFDerivAt (fun x => c β€’ f x) (c β€’ f') x := h.const_smul c @[fun_prop] theorem DifferentiableWithinAt.const_smul (h : DifferentiableWithinAt π•œ f s x) (c : R) : DifferentiableWithinAt π•œ (fun y => c β€’ f y) s x := (h.hasFDerivWithinAt.const_smul c).differentiableWithinAt @[fun_prop] theorem DifferentiableAt.const_smul (h : DifferentiableAt π•œ f x) (c : R) : DifferentiableAt π•œ (fun y => c β€’ f y) x := (h.hasFDerivAt.const_smul c).differentiableAt @[fun_prop] theorem DifferentiableOn.const_smul (h : DifferentiableOn π•œ f s) (c : R) : DifferentiableOn π•œ (fun y => c β€’ f y) s := fun x hx => (h x hx).const_smul c @[fun_prop] theorem Differentiable.const_smul (h : Differentiable π•œ f) (c : R) : Differentiable π•œ fun y => c β€’ f y := fun x => (h x).const_smul c theorem fderivWithin_const_smul (hxs : UniqueDiffWithinAt π•œ s x) (h : DifferentiableWithinAt π•œ f s x) (c : R) : fderivWithin π•œ (fun y => c β€’ f y) s x = c β€’ fderivWithin π•œ f s x := (h.hasFDerivWithinAt.const_smul c).fderivWithin hxs /-- Version of `fderivWithin_const_smul` written with `c β€’ f` instead of `fun y ↦ c β€’ f y`. -/ theorem fderivWithin_const_smul' (hxs : UniqueDiffWithinAt π•œ s x) (h : DifferentiableWithinAt π•œ f s x) (c : R) : fderivWithin π•œ (c β€’ f) s x = c β€’ fderivWithin π•œ f s x := fderivWithin_const_smul hxs h c theorem fderiv_const_smul (h : DifferentiableAt π•œ f x) (c : R) : fderiv π•œ (fun y => c β€’ f y) x = c β€’ fderiv π•œ f x := (h.hasFDerivAt.const_smul c).fderiv /-- Version of `fderiv_const_smul` written with `c β€’ f` instead of `fun y ↦ c β€’ f y`. -/ theorem fderiv_const_smul' (h : DifferentiableAt π•œ f x) (c : R) : fderiv π•œ (c β€’ f) x = c β€’ fderiv π•œ f x := (h.hasFDerivAt.const_smul c).fderiv end ConstSMul section Add /-! ### Derivative of the sum of two functions -/ @[fun_prop] nonrec theorem HasStrictFDerivAt.add (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun y => f y + g y) (f' + g') x := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun y => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel theorem HasFDerivAtFilter.add (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun y => f y + g y) (f' + g') x L := .of_isLittleO <| (hf.isLittleO.add hg.isLittleO).congr_left fun _ => by simp only [LinearMap.sub_apply, LinearMap.add_apply, map_sub, map_add, add_apply] abel @[fun_prop] nonrec theorem HasFDerivWithinAt.add (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun y => f y + g y) (f' + g') s x := hf.add hg @[fun_prop] nonrec theorem HasFDerivAt.add (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x + g x) (f' + g') x := hf.add hg @[fun_prop] theorem DifferentiableWithinAt.add (hf : DifferentiableWithinAt π•œ f s x) (hg : DifferentiableWithinAt π•œ g s x) : DifferentiableWithinAt π•œ (fun y => f y + g y) s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.add (hf : DifferentiableAt π•œ f x) (hg : DifferentiableAt π•œ g x) : DifferentiableAt π•œ (fun y => f y + g y) x := (hf.hasFDerivAt.add hg.hasFDerivAt).differentiableAt @[fun_prop] theorem DifferentiableOn.add (hf : DifferentiableOn π•œ f s) (hg : DifferentiableOn π•œ g s) : DifferentiableOn π•œ (fun y => f y + g y) s := fun x hx => (hf x hx).add (hg x hx) @[simp, fun_prop] theorem Differentiable.add (hf : Differentiable π•œ f) (hg : Differentiable π•œ g) : Differentiable π•œ fun y => f y + g y := fun x => (hf x).add (hg x) theorem fderivWithin_add (hxs : UniqueDiffWithinAt π•œ s x) (hf : DifferentiableWithinAt π•œ f s x) (hg : DifferentiableWithinAt π•œ g s x) : fderivWithin π•œ (fun y => f y + g y) s x = fderivWithin π•œ f s x + fderivWithin π•œ g s x := (hf.hasFDerivWithinAt.add hg.hasFDerivWithinAt).fderivWithin hxs /-- Version of `fderivWithin_add` where the function is written as `f + g` instead of `fun y ↦ f y + g y`. -/ theorem fderivWithin_add' (hxs : UniqueDiffWithinAt π•œ s x) (hf : DifferentiableWithinAt π•œ f s x) (hg : DifferentiableWithinAt π•œ g s x) : fderivWithin π•œ (f + g) s x = fderivWithin π•œ f s x + fderivWithin π•œ g s x := fderivWithin_add hxs hf hg theorem fderiv_add (hf : DifferentiableAt π•œ f x) (hg : DifferentiableAt π•œ g x) : fderiv π•œ (fun y => f y + g y) x = fderiv π•œ f x + fderiv π•œ g x := (hf.hasFDerivAt.add hg.hasFDerivAt).fderiv /-- Version of `fderiv_add` where the function is written as `f + g` instead of `fun y ↦ f y + g y`. -/ theorem fderiv_add' (hf : DifferentiableAt π•œ f x) (hg : DifferentiableAt π•œ g x) : fderiv π•œ (f + g) x = fderiv π•œ f x + fderiv π•œ g x := fderiv_add hf hg @[simp] theorem hasFDerivAtFilter_add_const_iff (c : F) : HasFDerivAtFilter (f Β· + c) f' x L ↔ HasFDerivAtFilter f f' x L := by simp [hasFDerivAtFilter_iff_isLittleOTVS] alias ⟨_, HasFDerivAtFilter.add_const⟩ := hasFDerivAtFilter_add_const_iff @[simp] theorem hasStrictFDerivAt_add_const_iff (c : F) : HasStrictFDerivAt (f Β· + c) f' x ↔ HasStrictFDerivAt f f' x := by simp [hasStrictFDerivAt_iff_isLittleO] @[fun_prop] alias ⟨_, HasStrictFDerivAt.add_const⟩ := hasStrictFDerivAt_add_const_iff @[simp] theorem hasFDerivWithinAt_add_const_iff (c : F) : HasFDerivWithinAt (f Β· + c) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟨_, HasFDerivWithinAt.add_const⟩ := hasFDerivWithinAt_add_const_iff @[simp] theorem hasFDerivAt_add_const_iff (c : F) : HasFDerivAt (f Β· + c) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_add_const_iff c @[fun_prop] alias ⟨_, HasFDerivAt.add_const⟩ := hasFDerivAt_add_const_iff @[simp] theorem differentiableWithinAt_add_const_iff (c : F) : DifferentiableWithinAt π•œ (fun y => f y + c) s x ↔ DifferentiableWithinAt π•œ f s x := exists_congr fun _ ↦ hasFDerivWithinAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableWithinAt.add_const⟩ := differentiableWithinAt_add_const_iff @[simp] theorem differentiableAt_add_const_iff (c : F) : DifferentiableAt π•œ (fun y => f y + c) x ↔ DifferentiableAt π•œ f x := exists_congr fun _ ↦ hasFDerivAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableAt.add_const⟩ := differentiableAt_add_const_iff @[simp] theorem differentiableOn_add_const_iff (c : F) : DifferentiableOn π•œ (fun y => f y + c) s ↔ DifferentiableOn π•œ f s := forallβ‚‚_congr fun _ _ ↦ differentiableWithinAt_add_const_iff c @[fun_prop] alias ⟨_, DifferentiableOn.add_const⟩ := differentiableOn_add_const_iff @[simp] theorem differentiable_add_const_iff (c : F) : (Differentiable π•œ fun y => f y + c) ↔ Differentiable π•œ f := forall_congr' fun _ ↦ differentiableAt_add_const_iff c @[fun_prop] alias ⟨_, Differentiable.add_const⟩ := differentiable_add_const_iff @[simp] theorem fderivWithin_add_const (c : F) : fderivWithin π•œ (fun y => f y + c) s x = fderivWithin π•œ f s x := by classical simp [fderivWithin] @[simp]
Mathlib/Analysis/Calculus/FDeriv/Add.lean
240
242
theorem fderiv_add_const (c : F) : fderiv π•œ (fun y => f y + c) x = fderiv π•œ f x := by
simp only [← fderivWithin_univ, fderivWithin_add_const]
/- 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 /-! # 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 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 row of `M` to its `i`-th row. 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 @[simp] theorem transvection_zero : transvection i j (0 : R) = 1 := by simp [transvection] 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 [ha, updateRow_self, Pi.add_apply, one_apply, Pi.smul_apply, hb, ↓reduceIte, smul_eq_mul, mul_one, transvection, add_apply, StdBasisMatrix.apply_same] Β· simp only [ha, updateRow_self, Pi.add_apply, one_apply, Pi.smul_apply, hb, ↓reduceIte, smul_eq_mul, mul_zero, add_zero, transvection, add_apply, and_false, not_false_eq_true, StdBasisMatrix.apply_of_ne] Β· 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, add_apply] 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] @[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] @[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] @[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] @[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] @[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] 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. -/ structure TransvectionStruct where (i j : n) hij : i β‰  j c : R 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 @[simp] theorem toMatrix_mk (i j : n) (hij : i β‰  j) (c : R) : TransvectionStruct.toMatrix ⟨i, j, hij, c⟩ = transvection i j c := rfl @[simp] protected theorem det [Fintype n] (t : TransvectionStruct n R) : det t.toMatrix = 1 := det_transvection_of_ne _ _ t.hij _ @[simp] theorem det_toMatrix_prod [Fintype n] (L : List (TransvectionStruct n π•œ)) : det (L.map toMatrix).prod = 1 := by induction L with | nil => simp | cons _ _ IH => simp [IH] /-- 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 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] 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] 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 | nil => simp | cons t L IH => 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 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 | nil => simp | cons t L IH => 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] /-- `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 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] end open Sum /-- Given a `TransvectionStruct` on `n`, define the corresponding `TransvectionStruct` on `n βŠ• p` using the identity on `p`. -/ def sumInl (t : TransvectionStruct n R) : TransvectionStruct (n βŠ• p) R where i := inl t.i j := inl t.j hij := by simp [t.hij] c := t.c theorem toMatrix_sumInl (t : TransvectionStruct n R) : (t.sumInl p).toMatrix = fromBlocks t.toMatrix 0 0 1 := by cases t ext a b rcases a with a | a <;> rcases b with b | b Β· by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h, stdBasisMatrix] Β· simp [TransvectionStruct.sumInl, transvection] Β· simp [TransvectionStruct.sumInl, transvection] Β· by_cases h : a = b <;> simp [TransvectionStruct.sumInl, transvection, h] @[simp] theorem sumInl_toMatrix_prod_mul [Fintype n] [Fintype p] (M : Matrix n n R) (L : List (TransvectionStruct n R)) (N : Matrix p p R) : (L.map (toMatrix ∘ sumInl p)).prod * fromBlocks M 0 0 N = fromBlocks ((L.map toMatrix).prod * M) 0 0 N := by induction L with | nil => simp | cons t L IH => simp [Matrix.mul_assoc, IH, toMatrix_sumInl, fromBlocks_multiply] @[simp] theorem mul_sumInl_toMatrix_prod [Fintype n] [Fintype p] (M : Matrix n n R) (L : List (TransvectionStruct n R)) (N : Matrix p p R) : fromBlocks M 0 0 N * (L.map (toMatrix ∘ sumInl p)).prod = fromBlocks (M * (L.map toMatrix).prod) 0 0 N := by induction L generalizing M N with | nil => simp | cons t L IH => simp [IH, toMatrix_sumInl, fromBlocks_multiply] variable {p} /-- Given a `TransvectionStruct` on `n` and an equivalence between `n` and `p`, define the corresponding `TransvectionStruct` on `p`. -/ def reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : TransvectionStruct p R where i := e t.i j := e t.j hij := by simp [t.hij] c := t.c variable [Fintype n] [Fintype p] theorem toMatrix_reindexEquiv (e : n ≃ p) (t : TransvectionStruct n R) : (t.reindexEquiv e).toMatrix = reindexAlgEquiv R _ e t.toMatrix := by rcases t with ⟨t_i, t_j, _⟩ ext a b simp only [reindexEquiv, transvection, mul_boole, Algebra.id.smul_eq_mul, toMatrix_mk, submatrix_apply, reindex_apply, DMatrix.add_apply, Pi.smul_apply, reindexAlgEquiv_apply] by_cases ha : e t_i = a <;> by_cases hb : e t_j = b <;> by_cases hab : a = b <;> simp [ha, hb, hab, ← e.apply_eq_iff_eq_symm_apply, stdBasisMatrix] theorem toMatrix_reindexEquiv_prod (e : n ≃ p) (L : List (TransvectionStruct n R)) : (L.map (toMatrix ∘ reindexEquiv e)).prod = reindexAlgEquiv R _ e (L.map toMatrix).prod := by induction L with | nil => simp | cons t L IH => simp only [toMatrix_reindexEquiv, IH, Function.comp_apply, List.prod_cons, reindexAlgEquiv_apply, List.map] exact (reindexAlgEquiv_mul R _ _ _ _).symm end TransvectionStruct end Transvection /-! # Reducing matrices by left and right multiplication by transvections In this section, we show that any matrix can be reduced to diagonal form by left and right multiplication by transvections (or, equivalently, by elementary operations on lines and columns). The main step is to kill the last row and column of a matrix in `Fin r βŠ• Unit` with nonzero last coefficient, by subtracting this coefficient from the other ones. The list of these operations is recorded in `list_transvec_col M` and `list_transvec_row M`. We have to analyze inductively how these operations affect the coefficients in the last row and the last column to conclude that they have the desired effect. Once this is done, one concludes the reduction by induction on the size of the matrices, through a suitable reindexing to identify any fintype with `Fin r βŠ• Unit`. -/ namespace Pivot variable {R} {r : β„•} (M : Matrix (Fin r βŠ• Unit) (Fin r βŠ• Unit) π•œ) open Unit Sum Fin TransvectionStruct /-- A list of transvections such that multiplying on the left with these transvections will replace the last column with zeroes. -/ def listTransvecCol : List (Matrix (Fin r βŠ• Unit) (Fin r βŠ• Unit) π•œ) := List.ofFn fun i : Fin r => transvection (inl i) (inr unit) <| -M (inl i) (inr unit) / M (inr unit) (inr unit) /-- A list of transvections such that multiplying on the right with these transvections will replace the last row with zeroes. -/ def listTransvecRow : List (Matrix (Fin r βŠ• Unit) (Fin r βŠ• Unit) π•œ) := List.ofFn fun i : Fin r => transvection (inr unit) (inl i) <| -M (inr unit) (inl i) / M (inr unit) (inr unit) @[simp] theorem length_listTransvecCol : (listTransvecCol M).length = r := by simp [listTransvecCol] theorem listTransvecCol_getElem {i : β„•} (h : i < (listTransvecCol M).length) : (listTransvecCol M)[i] = letI i' : Fin r := ⟨i, length_listTransvecCol M β–Έ h⟩ transvection (inl i') (inr unit) <| -M (inl i') (inr unit) / M (inr unit) (inr unit) := by simp [listTransvecCol] @[simp] theorem length_listTransvecRow : (listTransvecRow M).length = r := by simp [listTransvecRow] theorem listTransvecRow_getElem {i : β„•} (h : i < (listTransvecRow M).length) : (listTransvecRow M)[i] = letI i' : Fin r := ⟨i, length_listTransvecRow M β–Έ h⟩ transvection (inr unit) (inl i') <| -M (inr unit) (inl i') / M (inr unit) (inr unit) := by simp [listTransvecRow, Fin.cast] /-- Multiplying by some of the matrices in `listTransvecCol M` does not change the last row. -/ theorem listTransvecCol_mul_last_row_drop (i : Fin r βŠ• Unit) {k : β„•} (hk : k ≀ r) : (((listTransvecCol M).drop k).prod * M) (inr unit) i = M (inr unit) i := by induction hk using Nat.decreasingInduction with | of_succ n hn IH => have hn' : n < (listTransvecCol M).length := by simpa [listTransvecCol] using hn rw [List.drop_eq_getElem_cons hn'] simpa [listTransvecCol, Matrix.mul_assoc] | self => simp only [length_listTransvecCol, le_refl, List.drop_eq_nil_of_le, List.prod_nil, Matrix.one_mul] /-- Multiplying by all the matrices in `listTransvecCol M` does not change the last row. -/
Mathlib/LinearAlgebra/Matrix/Transvection.lean
371
380
theorem listTransvecCol_mul_last_row (i : Fin r βŠ• Unit) : ((listTransvecCol M).prod * M) (inr unit) i = M (inr unit) i := by
simpa using listTransvecCol_mul_last_row_drop M i (zero_le _) /-- Multiplying by all the matrices in `listTransvecCol M` kills all the coefficients in the last column but the last one. -/ theorem listTransvecCol_mul_last_col (hM : M (inr unit) (inr unit) β‰  0) (i : Fin r) : ((listTransvecCol M).prod * M) (inl i) (inr unit) = 0 := by suffices H : βˆ€ k : β„•,
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, YaΓ«l Dillies -/ import Mathlib.Order.Interval.Set.Defs import Mathlib.Order.Monotone.Basic import Mathlib.Tactic.Bound.Attribute import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Monotonicity.Attr /-! # Natural number logarithms This file defines two `β„•`-valued analogs of the logarithm of `n` with base `b`: * `log b n`: Lower logarithm, or floor **log**. Greatest `k` such that `b^k ≀ n`. * `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n ≀ b^k`. These are interesting because, for `1 < b`, `Nat.log b` and `Nat.clog b` are respectively right and left adjoints of `Nat.pow b`. See `pow_le_iff_le_log` and `le_pow_iff_clog_le`. -/ assert_not_exists OrderTop namespace Nat /-! ### Floor logarithm -/ /-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : β„•` such that `b^k ≀ n`, so if `b^k = n`, it returns exactly `k`. -/ @[pp_nodot] def log (b : β„•) : β„• β†’ β„• | n => if h : b ≀ n ∧ 1 < b then log b (n / b) + 1 else 0 decreasing_by -- putting this in the def triggers the `unusedHavesSuffices` linter: -- https://github.com/leanprover-community/batteries/issues/428 have : n / b < n := div_lt_self ((Nat.zero_lt_one.trans h.2).trans_le h.1) h.2 decreasing_trivial @[simp] theorem log_eq_zero_iff {b n : β„•} : log b n = 0 ↔ n < b ∨ b ≀ 1 := by rw [log, dite_eq_right_iff] simp only [Nat.add_eq_zero_iff, Nat.one_ne_zero, and_false, imp_false, not_and_or, not_le, not_lt] theorem log_of_lt {b n : β„•} (hb : n < b) : log b n = 0 := log_eq_zero_iff.2 (Or.inl hb) theorem log_of_left_le_one {b : β„•} (hb : b ≀ 1) (n) : log b n = 0 := log_eq_zero_iff.2 (Or.inr hb) @[simp] theorem log_pos_iff {b n : β„•} : 0 < log b n ↔ b ≀ n ∧ 1 < b := by rw [Nat.pos_iff_ne_zero, Ne, log_eq_zero_iff, not_or, not_lt, not_le] @[bound] theorem log_pos {b n : β„•} (hb : 1 < b) (hbn : b ≀ n) : 0 < log b n := log_pos_iff.2 ⟨hbn, hb⟩ theorem log_of_one_lt_of_le {b n : β„•} (h : 1 < b) (hn : b ≀ n) : log b n = log b (n / b) + 1 := by rw [log] exact if_pos ⟨hn, h⟩ @[simp] lemma log_zero_left : βˆ€ n, log 0 n = 0 := log_of_left_le_one <| Nat.zero_le _ @[simp] theorem log_zero_right (b : β„•) : log b 0 = 0 := log_eq_zero_iff.2 (le_total 1 b) @[simp] theorem log_one_left : βˆ€ n, log 1 n = 0 := log_of_left_le_one le_rfl @[simp] theorem log_one_right (b : β„•) : log b 1 = 0 := log_eq_zero_iff.2 (lt_or_le _ _) /-- `pow b` and `log b` (almost) form a Galois connection. See also `Nat.pow_le_of_le_log` and `Nat.le_log_of_pow_le` for individual implications under weaker assumptions. -/ theorem pow_le_iff_le_log {b : β„•} (hb : 1 < b) {x y : β„•} (hy : y β‰  0) : b ^ x ≀ y ↔ x ≀ log b y := by induction y using Nat.strong_induction_on generalizing x with | h y ih => ?_ cases x with | zero => dsimp; omega | succ x => rw [log]; split_ifs with h Β· have b_pos : 0 < b := lt_of_succ_lt hb rw [Nat.add_le_add_iff_right, ← ih (y / b) (div_lt_self (Nat.pos_iff_ne_zero.2 hy) hb) (Nat.div_pos h.1 b_pos).ne', le_div_iff_mul_le b_pos, pow_succ', Nat.mul_comm] Β· exact iff_of_false (fun hby => h ⟨(le_self_pow x.succ_ne_zero _).trans hby, hb⟩) (not_succ_le_zero _) theorem lt_pow_iff_log_lt {b : β„•} (hb : 1 < b) {x y : β„•} (hy : y β‰  0) : y < b ^ x ↔ log b y < x := lt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy) theorem pow_le_of_le_log {b x y : β„•} (hy : y β‰  0) (h : x ≀ log b y) : b ^ x ≀ y := by refine (le_or_lt b 1).elim (fun hb => ?_) fun hb => (pow_le_iff_le_log hb hy).2 h rw [log_of_left_le_one hb, Nat.le_zero] at h rwa [h, Nat.pow_zero, one_le_iff_ne_zero] theorem le_log_of_pow_le {b x y : β„•} (hb : 1 < b) (h : b ^ x ≀ y) : x ≀ log b y := by rcases ne_or_eq y 0 with (hy | rfl) exacts [(pow_le_iff_le_log hb hy).1 h, (h.not_lt (Nat.pow_pos (Nat.zero_lt_one.trans hb))).elim] theorem pow_log_le_self (b : β„•) {x : β„•} (hx : x β‰  0) : b ^ log b x ≀ x := pow_le_of_le_log hx le_rfl theorem log_lt_of_lt_pow {b x y : β„•} (hy : y β‰  0) : y < b ^ x β†’ log b y < x := lt_imp_lt_of_le_imp_le (pow_le_of_le_log hy) theorem lt_pow_of_log_lt {b x y : β„•} (hb : 1 < b) : log b y < x β†’ y < b ^ x := lt_imp_lt_of_le_imp_le (le_log_of_pow_le hb) lemma log_lt_self (b : β„•) {x : β„•} (hx : x β‰  0) : log b x < x := match le_or_lt b 1 with | .inl h => log_of_left_le_one h x β–Έ Nat.pos_iff_ne_zero.2 hx | .inr h => log_lt_of_lt_pow hx <| Nat.lt_pow_self h lemma log_le_self (b x : β„•) : log b x ≀ x := if hx : x = 0 then by simp [hx] else (log_lt_self b hx).le theorem lt_pow_succ_log_self {b : β„•} (hb : 1 < b) (x : β„•) : x < b ^ (log b x).succ := lt_pow_of_log_lt hb (lt_succ_self _) theorem log_eq_iff {b m n : β„•} (h : m β‰  0 ∨ 1 < b ∧ n β‰  0) : log b n = m ↔ b ^ m ≀ n ∧ n < b ^ (m + 1) := by rcases em (1 < b ∧ n β‰  0) with (⟨hb, hn⟩ | hbn) Β· rw [le_antisymm_iff, ← Nat.lt_succ_iff, ← pow_le_iff_le_log, ← lt_pow_iff_log_lt, and_comm] <;> assumption have hm : m β‰  0 := h.resolve_right hbn rw [not_and_or, not_lt, Ne, not_not] at hbn rcases hbn with (hb | rfl) Β· obtain rfl | rfl := le_one_iff_eq_zero_or_eq_one.1 hb any_goals simp only [ne_eq, zero_eq, reduceSucc, lt_self_iff_false, not_lt_zero, false_and, or_false] at h simp [h, eq_comm (a := 0), Nat.zero_pow (Nat.pos_iff_ne_zero.2 _)] <;> omega Β· simp [@eq_comm _ 0, hm] theorem log_eq_of_pow_le_of_lt_pow {b m n : β„•} (h₁ : b ^ m ≀ n) (hβ‚‚ : n < b ^ (m + 1)) : log b n = m := by rcases eq_or_ne m 0 with (rfl | hm) Β· rw [Nat.pow_one] at hβ‚‚ exact log_of_lt hβ‚‚ Β· exact (log_eq_iff (Or.inl hm)).2 ⟨h₁, hβ‚‚βŸ© theorem log_pow {b : β„•} (hb : 1 < b) (x : β„•) : log b (b ^ x) = x := log_eq_of_pow_le_of_lt_pow le_rfl (Nat.pow_lt_pow_right hb x.lt_succ_self) theorem log_eq_one_iff' {b n : β„•} : log b n = 1 ↔ b ≀ n ∧ n < b * b := by rw [log_eq_iff (Or.inl Nat.one_ne_zero), Nat.pow_add, Nat.pow_one] theorem log_eq_one_iff {b n : β„•} : log b n = 1 ↔ n < b * b ∧ 1 < b ∧ b ≀ n := log_eq_one_iff'.trans ⟨fun h => ⟨h.2, lt_mul_self_iff.1 (h.1.trans_lt h.2), h.1⟩, fun h => ⟨h.2.2, h.1⟩⟩ theorem log_mul_base {b n : β„•} (hb : 1 < b) (hn : n β‰  0) : log b (n * b) = log b n + 1 := by apply log_eq_of_pow_le_of_lt_pow <;> rw [pow_succ', Nat.mul_comm b] exacts [Nat.mul_le_mul_right _ (pow_log_le_self _ hn), (Nat.mul_lt_mul_right (Nat.zero_lt_one.trans hb)).2 (lt_pow_succ_log_self hb _)] theorem pow_log_le_add_one (b : β„•) : βˆ€ x, b ^ log b x ≀ x + 1 | 0 => by rw [log_zero_right, Nat.pow_zero] | x + 1 => (pow_log_le_self b x.succ_ne_zero).trans (x + 1).le_succ theorem log_monotone {b : β„•} : Monotone (log b) := by refine monotone_nat_of_le_succ fun n => ?_ rcases le_or_lt b 1 with hb | hb Β· rw [log_of_left_le_one hb] exact zero_le _ Β· exact le_log_of_pow_le hb (pow_log_le_add_one _ _) @[mono] theorem log_mono_right {b n m : β„•} (h : n ≀ m) : log b n ≀ log b m := log_monotone h @[mono] theorem log_anti_left {b c n : β„•} (hc : 1 < c) (hb : c ≀ b) : log b n ≀ log c n := by rcases eq_or_ne n 0 with (rfl | hn); Β· rw [log_zero_right, log_zero_right] apply le_log_of_pow_le hc calc c ^ log b n ≀ b ^ log b n := Nat.pow_le_pow_left hb _ _ ≀ n := pow_log_le_self _ hn theorem log_antitone_left {n : β„•} : AntitoneOn (fun b => log b n) (Set.Ioi 1) := fun _ hc _ _ hb => log_anti_left (Set.mem_Iio.1 hc) hb @[simp] theorem log_div_base (b n : β„•) : log b (n / b) = log b n - 1 := by rcases le_or_lt b 1 with hb | hb Β· rw [log_of_left_le_one hb, log_of_left_le_one hb, Nat.zero_sub] rcases lt_or_le n b with h | h Β· rw [div_eq_of_lt h, log_of_lt h, log_zero_right] rw [log_of_one_lt_of_le hb h, Nat.add_sub_cancel_right] @[simp] theorem log_div_mul_self (b n : β„•) : log b (n / b * b) = log b n := by rcases le_or_lt b 1 with hb | hb Β· rw [log_of_left_le_one hb, log_of_left_le_one hb] rcases lt_or_le n b with h | h Β· rw [div_eq_of_lt h, Nat.zero_mul, log_zero_right, log_of_lt h] rw [log_mul_base hb (Nat.div_pos h (by omega)).ne', log_div_base, Nat.sub_add_cancel (succ_le_iff.2 <| log_pos hb h)] theorem add_pred_div_lt {b n : β„•} (hb : 1 < b) (hn : 2 ≀ n) : (n + b - 1) / b < n := by rw [div_lt_iff_lt_mul (by omega), ← succ_le_iff, ← pred_eq_sub_one, succ_pred_eq_of_pos (by omega)] exact Nat.add_le_mul hn hb lemma log2_eq_log_two {n : β„•} : Nat.log2 n = Nat.log 2 n := by rcases eq_or_ne n 0 with rfl | hn Β· rw [log2_zero, log_zero_right] apply eq_of_forall_le_iff intro m rw [Nat.le_log2 hn, ← Nat.pow_le_iff_le_log Nat.one_lt_two hn] /-! ### Ceil logarithm -/ /-- `clog b n`, is the upper logarithm of natural number `n` in base `b`. It returns the smallest `k : β„•` such that `n ≀ b^k`, so if `b^k = n`, it returns exactly `k`. -/ @[pp_nodot] def clog (b : β„•) : β„• β†’ β„• | n => if h : 1 < b ∧ 1 < n then clog b ((n + b - 1) / b) + 1 else 0 decreasing_by -- putting this in the def triggers the `unusedHavesSuffices` linter: -- https://github.com/leanprover-community/batteries/issues/428 have : (n + b - 1) / b < n := add_pred_div_lt h.1 h.2 decreasing_trivial theorem clog_of_left_le_one {b : β„•} (hb : b ≀ 1) (n : β„•) : clog b n = 0 := by rw [clog, dif_neg fun h : 1 < b ∧ 1 < n => h.1.not_le hb] theorem clog_of_right_le_one {n : β„•} (hn : n ≀ 1) (b : β„•) : clog b n = 0 := by rw [clog, dif_neg fun h : 1 < b ∧ 1 < n => h.2.not_le hn] @[simp] lemma clog_zero_left (n : β„•) : clog 0 n = 0 := clog_of_left_le_one (Nat.zero_le _) _ @[simp] lemma clog_zero_right (b : β„•) : clog b 0 = 0 := clog_of_right_le_one (Nat.zero_le _) _ @[simp] theorem clog_one_left (n : β„•) : clog 1 n = 0 := clog_of_left_le_one le_rfl _ @[simp] theorem clog_one_right (b : β„•) : clog b 1 = 0 := clog_of_right_le_one le_rfl _
Mathlib/Data/Nat/Log.lean
251
252
theorem clog_of_two_le {b n : β„•} (hb : 1 < b) (hn : 2 ≀ n) : clog b n = clog b ((n + b - 1) / b) + 1 := by
rw [clog, dif_pos (⟨hb, hn⟩ : 1 < b ∧ 1 < n)]
/- Copyright (c) 2023 Josha Dekker. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Josha Dekker -/ import Mathlib.Topology.Bases import Mathlib.Order.Filter.CountableInter import Mathlib.Topology.Compactness.SigmaCompact /-! # LindelΓΆf sets and LindelΓΆf spaces ## Main definitions We define the following properties for sets in a topological space: * `IsLindelof s`: Two definitions are possible here. The more standard definition is that every open cover that contains `s` contains a countable subcover. We choose for the equivalent definition where we require that every nontrivial filter on `s` with the countable intersection property has a clusterpoint. Equivalence is established in `isLindelof_iff_countable_subcover`. * `LindelofSpace X`: `X` is LindelΓΆf if it is LindelΓΆf as a set. * `NonLindelofSpace`: a space that is not a LindΓ«lof space, e.g. the Long Line. ## Main results * `isLindelof_iff_countable_subcover`: A set is LindelΓΆf iff every open cover has a countable subcover. ## Implementation details * This API is mainly based on the API for IsCompact and follows notation and style as much as possible. -/ open Set Filter Topology TopologicalSpace universe u v variable {X : Type u} {Y : Type v} {ΞΉ : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} section Lindelof /-- A set `s` is LindelΓΆf if every nontrivial filter `f` with the countable intersection property that contains `s`, has a clusterpoint in `s`. The filter-free definition is given by `isLindelof_iff_countable_subcover`. -/ def IsLindelof (s : Set X) := βˆ€ ⦃f⦄ [NeBot f] [CountableInterFilter f], f ≀ π“Ÿ s β†’ βˆƒ x ∈ s, ClusterPt x f /-- The complement to a LindelΓΆf set belongs to a filter `f` with the countable intersection property if it belongs to each filter `𝓝 x βŠ“ f`, `x ∈ s`. -/ theorem IsLindelof.compl_mem_sets (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : βˆ€ x ∈ s, sᢜ ∈ 𝓝 x βŠ“ f) : sᢜ ∈ f := by contrapose! hf simp only [not_mem_iff_inf_principal_compl, compl_compl, inf_assoc] at hf ⊒ exact hs inf_le_right /-- The complement to a LindelΓΆf set belongs to a filter `f` with the countable intersection property if each `x ∈ s` has a neighborhood `t` within `s` such that `tᢜ` belongs to `f`. -/ theorem IsLindelof.compl_mem_sets_of_nhdsWithin (hs : IsLindelof s) {f : Filter X} [CountableInterFilter f] (hf : βˆ€ x ∈ s, βˆƒ t ∈ 𝓝[s] x, tᢜ ∈ f) : sᢜ ∈ f := by refine hs.compl_mem_sets fun x hx ↦ ?_ rw [← disjoint_principal_right, disjoint_right_comm, (basis_sets _).disjoint_iff_left] exact hf x hx /-- If `p : Set X β†’ Prop` is stable under restriction and union, and each point `x` of a LindelΓΆf set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsLindelof.induction_on (hs : IsLindelof s) {p : Set X β†’ Prop} (hmono : βˆ€ ⦃s t⦄, s βŠ† t β†’ p t β†’ p s) (hcountable_union : βˆ€ (S : Set (Set X)), S.Countable β†’ (βˆ€ s ∈ S, p s) β†’ p (⋃₀ S)) (hnhds : βˆ€ x ∈ s, βˆƒ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := ofCountableUnion p hcountable_union (fun t ht _ hsub ↦ hmono hsub ht) have : sᢜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a LindelΓΆf set and a closed set is a LindelΓΆf set. -/ theorem IsLindelof.inter_right (hs : IsLindelof s) (ht : IsClosed t) : IsLindelof (s ∩ t) := by intro f hnf _ hstf rw [← inf_principal, le_inf_iff] at hstf obtain ⟨x, hsx, hx⟩ : βˆƒ x ∈ s, ClusterPt x f := hs hstf.1 have hxt : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono hstf.2 exact ⟨x, ⟨hsx, hxt⟩, hx⟩ /-- The intersection of a closed set and a LindelΓΆf set is a LindelΓΆf set. -/ theorem IsLindelof.inter_left (ht : IsLindelof t) (hs : IsClosed s) : IsLindelof (s ∩ t) := inter_comm t s β–Έ ht.inter_right hs /-- The set difference of a LindelΓΆf set and an open set is a LindelΓΆf set. -/ theorem IsLindelof.diff (hs : IsLindelof s) (ht : IsOpen t) : IsLindelof (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a LindelΓΆf set is a LindelΓΆf set. -/ theorem IsLindelof.of_isClosed_subset (hs : IsLindelof s) (ht : IsClosed t) (h : t βŠ† s) : IsLindelof t := inter_eq_self_of_subset_right h β–Έ hs.inter_right ht /-- A continuous image of a LindelΓΆf set is a LindelΓΆf set. -/ theorem IsLindelof.image_of_continuousOn {f : X β†’ Y} (hs : IsLindelof s) (hf : ContinuousOn f s) : IsLindelof (f '' s) := by intro l lne _ ls have : NeBot (l.comap f βŠ“ π“Ÿ s) := comap_inf_principal_neBot_of_image_mem lne (le_principal_iff.1 ls) obtain ⟨x, hxs, hx⟩ : βˆƒ x ∈ s, ClusterPt x (l.comap f βŠ“ π“Ÿ s) := @hs _ this _ inf_le_right haveI := hx.neBot use f x, mem_image_of_mem f hxs have : Tendsto f (𝓝 x βŠ“ (comap f l βŠ“ π“Ÿ s)) (𝓝 (f x) βŠ“ l) := by convert (hf x hxs).inf (@tendsto_comap _ _ f l) using 1 rw [nhdsWithin] ac_rfl exact this.neBot /-- A continuous image of a LindelΓΆf set is a LindelΓΆf set within the codomain. -/ theorem IsLindelof.image {f : X β†’ Y} (hs : IsLindelof s) (hf : Continuous f) : IsLindelof (f '' s) := hs.image_of_continuousOn hf.continuousOn /-- A filter with the countable intersection property that is finer than the principal filter on a LindelΓΆf set `s` contains any open set that contains all clusterpoints of `s`. -/ theorem IsLindelof.adherence_nhdset {f : Filter X} [CountableInterFilter f] (hs : IsLindelof s) (hfβ‚‚ : f ≀ π“Ÿ s) (ht₁ : IsOpen t) (htβ‚‚ : βˆ€ x ∈ s, ClusterPt x f β†’ x ∈ t) : t ∈ f := (eq_or_neBot _).casesOn mem_of_eq_bot fun _ ↦ let ⟨x, hx, hfx⟩ := @hs (f βŠ“ π“Ÿ tᢜ) _ _ <| inf_le_of_left_le hfβ‚‚ have : x ∈ t := htβ‚‚ x hx hfx.of_inf_left have : tᢜ ∩ t ∈ 𝓝[tᢜ] x := inter_mem_nhdsWithin _ (ht₁.mem_nhds this) have A : 𝓝[tᢜ] x = βŠ₯ := empty_mem_iff_bot.1 <| compl_inter_self t β–Έ this have : 𝓝[tᢜ] x β‰  βŠ₯ := hfx.of_inf_right.ne absurd A this /-- For every open cover of a LindelΓΆf set, there exists a countable subcover. -/ theorem IsLindelof.elim_countable_subcover {ΞΉ : Type v} (hs : IsLindelof s) (U : ΞΉ β†’ Set X) (hUo : βˆ€ i, IsOpen (U i)) (hsU : s βŠ† ⋃ i, U i) : βˆƒ r : Set ΞΉ, r.Countable ∧ (s βŠ† ⋃ i ∈ r, U i) := by have hmono : βˆ€ ⦃s t : Set X⦄, s βŠ† t β†’ (βˆƒ r : Set ΞΉ, r.Countable ∧ t βŠ† ⋃ i ∈ r, U i) β†’ (βˆƒ r : Set ΞΉ, r.Countable ∧ s βŠ† ⋃ i ∈ r, U i) := by intro _ _ hst ⟨r, ⟨hrcountable, hsub⟩⟩ exact ⟨r, hrcountable, Subset.trans hst hsub⟩ have hcountable_union : βˆ€ (S : Set (Set X)), S.Countable β†’ (βˆ€ s ∈ S, βˆƒ r : Set ΞΉ, r.Countable ∧ (s βŠ† ⋃ i ∈ r, U i)) β†’ βˆƒ r : Set ΞΉ, r.Countable ∧ (⋃₀ S βŠ† ⋃ i ∈ r, U i) := by intro S hS hsr choose! r hr using hsr refine βŸ¨β‹ƒ s ∈ S, r s, hS.biUnion_iff.mpr (fun s hs ↦ (hr s hs).1), ?_⟩ refine sUnion_subset ?h.right.h simp only [mem_iUnion, exists_prop, iUnion_exists, biUnion_and'] exact fun i is x hx ↦ mem_biUnion is ((hr i is).2 hx) have h_nhds : βˆ€ x ∈ s, βˆƒ t ∈ 𝓝[s] x, βˆƒ r : Set ΞΉ, r.Countable ∧ (t βŠ† ⋃ i ∈ r, U i) := by intro x hx let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) refine ⟨U i, mem_nhdsWithin_of_mem_nhds ((hUo i).mem_nhds hi), {i}, by simp, ?_⟩ simp only [mem_singleton_iff, iUnion_iUnion_eq_left] exact Subset.refl _ exact hs.induction_on hmono hcountable_union h_nhds theorem IsLindelof.elim_nhds_subcover' (hs : IsLindelof s) (U : βˆ€ x ∈ s, Set X) (hU : βˆ€ x (hx : x ∈ s), U x β€Ήx ∈ sβ€Ί ∈ 𝓝 x) : βˆƒ t : Set s, t.Countable ∧ s βŠ† ⋃ x ∈ t, U (x : s) x.2 := by have := hs.elim_countable_subcover (fun x : s ↦ interior (U x x.2)) (fun _ ↦ isOpen_interior) fun x hx ↦ mem_iUnion.2 ⟨⟨x, hx⟩, mem_interior_iff_mem_nhds.2 <| hU _ _⟩ rcases this with ⟨r, ⟨hr, hs⟩⟩ use r, hr apply Subset.trans hs apply iUnionβ‚‚_subset intro i hi apply Subset.trans interior_subset exact subset_iUnion_of_subset i (subset_iUnion_of_subset hi (Subset.refl _)) theorem IsLindelof.elim_nhds_subcover (hs : IsLindelof s) (U : X β†’ Set X) (hU : βˆ€ x ∈ s, U x ∈ 𝓝 x) : βˆƒ t : Set X, t.Countable ∧ (βˆ€ x ∈ t, x ∈ s) ∧ s βŠ† ⋃ x ∈ t, U x := by let ⟨t, ⟨htc, htsub⟩⟩ := hs.elim_nhds_subcover' (fun x _ ↦ U x) hU refine βŸ¨β†‘t, Countable.image htc Subtype.val, ?_⟩ constructor Β· intro _ simp only [mem_image, Subtype.exists, exists_and_right, exists_eq_right, forall_exists_index] tauto Β· have : ⋃ x ∈ t, U ↑x = ⋃ x ∈ Subtype.val '' t, U x := biUnion_image.symm rwa [← this] /-- For every nonempty open cover of a LindelΓΆf set, there exists a subcover indexed by β„•. -/ theorem IsLindelof.indexed_countable_subcover {ΞΉ : Type v} [Nonempty ΞΉ] (hs : IsLindelof s) (U : ΞΉ β†’ Set X) (hUo : βˆ€ i, IsOpen (U i)) (hsU : s βŠ† ⋃ i, U i) : βˆƒ f : β„• β†’ ΞΉ, s βŠ† ⋃ n, U (f n) := by obtain ⟨c, ⟨c_count, c_cov⟩⟩ := hs.elim_countable_subcover U hUo hsU rcases c.eq_empty_or_nonempty with rfl | c_nonempty Β· simp only [mem_empty_iff_false, iUnion_of_empty, iUnion_empty] at c_cov simp only [subset_eq_empty c_cov rfl, empty_subset, exists_const] obtain ⟨f, f_surj⟩ := (Set.countable_iff_exists_surjective c_nonempty).mp c_count refine ⟨fun x ↦ f x, c_cov.trans <| iUnionβ‚‚_subset_iff.mpr (?_ : βˆ€ i ∈ c, U i βŠ† ⋃ n, U (f n))⟩ intro x hx obtain ⟨n, hn⟩ := f_surj ⟨x, hx⟩ exact subset_iUnion_of_subset n <| subset_of_eq (by rw [hn]) /-- The neighborhood filter of a LindelΓΆf set is disjoint with a filter `l` with the countable intersection property if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsLindelof.disjoint_nhdsSet_left {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint (𝓝˒ s) l ↔ βˆ€ x ∈ s, Disjoint (𝓝 x) l := by refine ⟨fun h x hx ↦ h.mono_left <| nhds_le_nhdsSet hx, fun H ↦ ?_⟩ choose! U hxU hUl using fun x hx ↦ (nhds_basis_opens x).disjoint_iff_left.1 (H x hx) choose hxU hUo using hxU rcases hs.elim_nhds_subcover U fun x hx ↦ (hUo x hx).mem_nhds (hxU x hx) with ⟨t, htc, hts, hst⟩ refine (hasBasis_nhdsSet _).disjoint_iff_left.2 βŸ¨β‹ƒ x ∈ t, U x, ⟨isOpen_biUnion fun x hx ↦ hUo x (hts x hx), hst⟩, ?_⟩ rw [compl_iUnionβ‚‚] exact (countable_bInter_mem htc).mpr (fun i hi ↦ hUl _ (hts _ hi)) /-- A filter `l` with the countable intersection property is disjoint with the neighborhood filter of a LindelΓΆf set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsLindelof.disjoint_nhdsSet_right {l : Filter X} [CountableInterFilter l] (hs : IsLindelof s) : Disjoint l (𝓝˒ s) ↔ βˆ€ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left /-- For every family of closed sets whose intersection avoids a LindelΓΆ set, there exists a countable subfamily whose intersection avoids this LindelΓΆf set. -/ theorem IsLindelof.elim_countable_subfamily_closed {ΞΉ : Type v} (hs : IsLindelof s) (t : ΞΉ β†’ Set X) (htc : βˆ€ i, IsClosed (t i)) (hst : (s ∩ β‹‚ i, t i) = βˆ…) : βˆƒ u : Set ΞΉ, u.Countable ∧ (s ∩ β‹‚ i ∈ u, t i) = βˆ… := by let U := tᢜ have hUo : βˆ€ i, IsOpen (U i) := by simp only [U, Pi.compl_apply, isOpen_compl_iff]; exact htc have hsU : s βŠ† ⋃ i, U i := by simp only [U, Pi.compl_apply] rw [← compl_iInter] apply disjoint_compl_left_iff_subset.mp simp only [compl_iInter, compl_iUnion, compl_compl] apply Disjoint.symm exact disjoint_iff_inter_eq_empty.mpr hst rcases hs.elim_countable_subcover U hUo hsU with ⟨u, ⟨hucount, husub⟩⟩ use u, hucount rw [← disjoint_compl_left_iff_subset] at husub simp only [U, Pi.compl_apply, compl_iUnion, compl_compl] at husub exact disjoint_iff_inter_eq_empty.mp (Disjoint.symm husub) /-- To show that a LindelΓΆf set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every countable subfamily. -/
Mathlib/Topology/Compactness/Lindelof.lean
237
242
theorem IsLindelof.inter_iInter_nonempty {ΞΉ : Type v} (hs : IsLindelof s) (t : ΞΉ β†’ Set X) (htc : βˆ€ i, IsClosed (t i)) (hst : βˆ€ u : Set ΞΉ, u.Countable ∧ (s ∩ β‹‚ i ∈ u, t i).Nonempty) : (s ∩ β‹‚ i, t i).Nonempty := by
contrapose! hst rcases hs.elim_countable_subfamily_closed t htc hst with ⟨u, ⟨_, husub⟩⟩ exact ⟨u, fun _ ↦ husub⟩
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, SΓ©bastien GouΓ«zel, RΓ©my Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Power function on `ℝβ‰₯0` and `ℝβ‰₯0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝβ‰₯0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open Real NNReal ENNReal ComplexConjugate Finset Function Set namespace NNReal variable {x : ℝβ‰₯0} {w y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝβ‰₯0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y β‰  0`. -/ noncomputable def rpow (x : ℝβ‰₯0) (y : ℝ) : ℝβ‰₯0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ noncomputable instance : Pow ℝβ‰₯0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0) (y : ℝ) : rpow x y = x ^ y := rfl @[simp, norm_cast] theorem coe_rpow (x : ℝβ‰₯0) (y : ℝ) : ((x ^ y : ℝβ‰₯0) : ℝ) = (x : ℝ) ^ y := rfl @[simp] theorem rpow_zero (x : ℝβ‰₯0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 lemma rpow_eq_zero (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [hy] @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝβ‰₯0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h @[simp] theorem rpow_one (x : ℝβ‰₯0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ lemma rpow_neg (x : ℝβ‰₯0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ @[simp, norm_cast] lemma rpow_natCast (x : ℝβ‰₯0) (n : β„•) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝβ‰₯0) (n : β„€) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ theorem rpow_add {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _ theorem rpow_add' (h : y + z β‰  0) (x : ℝβ‰₯0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h lemma rpow_add_intCast (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast (mod_cast hx) _ _ lemma rpow_add_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast (mod_cast hx) _ _ lemma rpow_sub_intCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _ lemma rpow_sub_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _ lemma rpow_add_intCast' {n : β„€} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast' (mod_cast x.2) h lemma rpow_add_natCast' {n : β„•} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast' (mod_cast x.2) h lemma rpow_sub_intCast' {n : β„€} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h lemma rpow_sub_natCast' {n : β„•} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h lemma rpow_add_one (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 lemma rpow_sub_one (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (h : y + 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' h, rpow_one] lemma rpow_one_add' (h : 1 + y β‰  0) (x : ℝβ‰₯0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' h, rpow_one] theorem rpow_add_of_nonneg (x : ℝβ‰₯0) {y z : ℝ} (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by ext; exact Real.rpow_add_of_nonneg x.2 hy hz /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝβ‰₯0) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝβ‰₯0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z lemma rpow_natCast_mul (x : ℝβ‰₯0) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_natCast] lemma rpow_mul_natCast (x : ℝβ‰₯0) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_natCast] lemma rpow_intCast_mul (x : ℝβ‰₯0) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_intCast] lemma rpow_mul_intCast (x : ℝβ‰₯0) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_intCast] theorem rpow_neg_one (x : ℝβ‰₯0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_sub {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z theorem rpow_sub' (h : y - z β‰  0) (x : ℝβ‰₯0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h lemma rpow_sub_one' (h : y - 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' h, rpow_one] lemma rpow_one_sub' (h : 1 - y β‰  0) (x : ℝβ‰₯0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' h, rpow_one] theorem rpow_inv_rpow_self {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] theorem rpow_self_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] theorem inv_rpow (x : ℝβ‰₯0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y theorem div_rpow (x y : ℝβ‰₯0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z theorem sqrt_eq_rpow (x : ℝβ‰₯0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 @[simp] lemma rpow_ofNat (x : ℝβ‰₯0) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : β„•) := rpow_natCast x n theorem rpow_two (x : ℝβ‰₯0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow {x y : ℝβ‰₯0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 /-- `rpow` as a `MonoidHom` -/ @[simps] def rpowMonoidHom (r : ℝ) : ℝβ‰₯0 β†’* ℝβ‰₯0 where toFun := (Β· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝβ‰₯0` -/ theorem list_prod_map_rpow (l : List ℝβ‰₯0) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝβ‰₯0`. -/ lemma multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝβ‰₯0`. -/ lemma finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : βˆ€ x ∈ l, (0 : ℝ) ≀ x) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := by lift l to List ℝβ‰₯0 using hl have := congr_arg ((↑) : ℝβ‰₯0 β†’ ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊒ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝ) (hl : βˆ€ i ∈ l, (0 : ℝ) ≀ f i) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] Β· rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, (0 : ℝ) ≀ f i) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, 0 ≀ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := Real.rpow_le_rpow x.2 h₁ hβ‚‚ @[gcongr] theorem rpow_lt_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x < y) (hβ‚‚ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ hβ‚‚ theorem rpow_lt_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz theorem rpow_le_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := Real.rpow_le_rpow_iff x.2 y.2 hz theorem le_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem rpow_inv_le_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem lt_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by simp only [← not_le, rpow_inv_le_iff hz] theorem rpow_inv_lt_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] section variable {y : ℝβ‰₯0} lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := Real.rpow_lt_rpow_of_neg hx hxy hz lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := Real.rpow_le_rpow_of_nonpos hx hxy hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := Real.rpow_lt_rpow_iff_of_neg hx hy hz lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := Real.rpow_le_rpow_iff_of_neg hx hy hz lemma le_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := Real.le_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_le_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := Real.rpow_inv_le_iff_of_pos x.2 hy hz lemma lt_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x < y ^ z⁻¹ ↔ x ^ z < y := Real.lt_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_lt_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ < y ↔ x < y ^ z := Real.rpow_inv_lt_iff_of_pos x.2 hy hz lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := Real.le_rpow_inv_iff_of_neg hx hy hz lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := Real.lt_rpow_inv_iff_of_neg hx hy hz lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := Real.rpow_inv_lt_iff_of_neg hx hy hz lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := Real.rpow_inv_le_iff_of_neg hx hy hz end @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz theorem rpow_lt_rpow_of_exponent_gt {x : ℝβ‰₯0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz theorem rpow_le_rpow_of_exponent_ge {x : ℝβ‰₯0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz theorem rpow_pos {p : ℝ} {x : ℝβ‰₯0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : βˆ€ {p : ℝ}, 0 < p β†’ 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) Β· exact rpow_pos_of_nonneg hp_pos Β· simp only [zero_lt_one, rpow_zero] Β· rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) theorem rpow_lt_one {x : ℝβ‰₯0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz theorem rpow_le_one {x : ℝβ‰₯0} {z : ℝ} (hx2 : x ≀ 1) (hz : 0 ≀ z) : x ^ z ≀ 1 := Real.rpow_le_one x.2 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x : ℝβ‰₯0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz theorem rpow_le_one_of_one_le_of_nonpos {x : ℝβ‰₯0} {z : ℝ} (hx : 1 ≀ x) (hz : z ≀ 0) : x ^ z ≀ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz theorem one_lt_rpow {x : ℝβ‰₯0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz theorem one_le_rpow {x : ℝβ‰₯0} {z : ℝ} (h : 1 ≀ x) (h₁ : 0 ≀ z) : 1 ≀ x ^ z := Real.one_le_rpow h h₁ theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝβ‰₯0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝβ‰₯0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≀ 1) (hz : z ≀ 0) : 1 ≀ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz theorem rpow_le_self_of_le_one {x : ℝβ‰₯0} {z : ℝ} (hx : x ≀ 1) (h_one_le : 1 ≀ z) : x ^ z ≀ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) Β· have : z β‰  0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le theorem rpow_left_injective {x : ℝ} (hx : x β‰  0) : Function.Injective fun y : ℝβ‰₯0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz theorem rpow_eq_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff theorem rpow_left_surjective {x : ℝ} (hx : x β‰  0) : Function.Surjective fun y : ℝβ‰₯0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancelβ‚€ hx, rpow_one]⟩ theorem rpow_left_bijective {x : ℝ} (hx : x β‰  0) : Function.Bijective fun y : ℝβ‰₯0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ theorem eq_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] theorem rpow_inv_eq_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x ^ z⁻¹ = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancelβ‚€ hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝβ‰₯0) {n : β„•} (hn : n β‰  0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn theorem rpow_inv_natCast_pow (x : ℝβ‰₯0) {n : β„•} (hn : n β‰  0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝβ‰₯0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≀ z) : Monotone fun x : ℝβ‰₯0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 β–Έ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝβ‰₯0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝβ‰₯0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝβ‰₯0 ≃o ℝβ‰₯0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) : β€–x ^ yβ€–β‚Š = β€–xβ€–β‚Š ^ y := by ext; exact Real.norm_rpow_of_nonneg hx end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝβ‰₯0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊀`, and with the natural values for `0` and `⊀` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊀` for `x < 0`, and `⊀ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝβ‰₯0∞ β†’ ℝ β†’ ℝβ‰₯0∞ | some x, y => if x = 0 ∧ y < 0 then ⊀ else (x ^ y : ℝβ‰₯0) | none, y => if 0 < y then ⊀ else if y = 0 then 1 else 0 noncomputable instance : Pow ℝβ‰₯0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0∞) (y : ℝ) : rpow x y = x ^ y := rfl @[simp] theorem rpow_zero {x : ℝβ‰₯0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> Β· dsimp only [(Β· ^ Β·), Pow.pow, rpow] simp [lt_irrefl] theorem top_rpow_def (y : ℝ) : (⊀ : ℝβ‰₯0∞) ^ y = if 0 < y then ⊀ else if y = 0 then 1 else 0 := rfl @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊀ : ℝβ‰₯0∞) ^ y = ⊀ := by simp [top_rpow_def, h] @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊀ : ℝβ‰₯0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝβ‰₯0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), rpow, Pow.pow] simp [h, asymm h, ne_of_gt h] @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝβ‰₯0∞) ^ y = ⊀ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), rpow, Pow.pow] simp [h, ne_of_gt h] theorem zero_rpow_def (y : ℝ) : (0 : ℝβ‰₯0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊀ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) Β· simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] Β· simp [lt_irrefl] Β· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝβ‰₯0∞) ^ y * (0 : ℝβ‰₯0∞) ^ y = (0 : ℝβ‰₯0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝβ‰₯0} (h : x β‰  0) (y : ℝ) : (↑(x ^ y) : ℝβ‰₯0∞) = x ^ y := by rw [← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), Pow.pow, rpow] simp [h] @[norm_cast] theorem coe_rpow_of_nonneg (x : ℝβ‰₯0) {y : ℝ} (h : 0 ≀ y) : ↑(x ^ y) = (x : ℝβ‰₯0∞) ^ y := by by_cases hx : x = 0 Β· rcases le_iff_eq_or_lt.1 h with (H | H) Β· simp [hx, H.symm] Β· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] Β· exact coe_rpow_of_ne_zero hx _ theorem coe_rpow_def (x : ℝβ‰₯0) (y : ℝ) : (x : ℝβ‰₯0∞) ^ y = if x = 0 ∧ y < 0 then ⊀ else ↑(x ^ y) := rfl theorem rpow_ofNNReal {M : ℝβ‰₯0} {P : ℝ} (hP : 0 ≀ P) : (M : ℝβ‰₯0∞) ^ P = ↑(M ^ P) := by rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow] @[simp] theorem rpow_one (x : ℝβ‰₯0∞) : x ^ (1 : ℝ) = x := by cases x Β· exact dif_pos zero_lt_one Β· change ite _ _ _ = _ simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp] exact fun _ => zero_le_one.not_lt @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0∞) ^ x = 1 := by rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero] simp @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊀ ∧ y < 0 := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] Β· simp [← coe_rpow_of_ne_zero h, h] lemma rpow_eq_zero_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by simp [hy, hy.not_lt] @[simp] theorem rpow_eq_top_iff {x : ℝβ‰₯0∞} {y : ℝ} : x ^ y = ⊀ ↔ x = 0 ∧ y < 0 ∨ x = ⊀ ∧ 0 < y := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] Β· simp [← coe_rpow_of_ne_zero h, h] theorem rpow_eq_top_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊀ ↔ x = ⊀ := by simp [rpow_eq_top_iff, hy, asymm hy] lemma rpow_lt_top_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy] theorem rpow_eq_top_of_nonneg (x : ℝβ‰₯0∞) {y : ℝ} (hy0 : 0 ≀ y) : x ^ y = ⊀ β†’ x = ⊀ := by rw [ENNReal.rpow_eq_top_iff] rintro (h|h) Β· exfalso rw [lt_iff_not_ge] at h exact h.right hy0 Β· exact h.left theorem rpow_ne_top_of_nonneg {x : ℝβ‰₯0∞} {y : ℝ} (hy0 : 0 ≀ y) (h : x β‰  ⊀) : x ^ y β‰  ⊀ := mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h theorem rpow_lt_top_of_nonneg {x : ℝβ‰₯0∞} {y : ℝ} (hy0 : 0 ≀ y) (h : x β‰  ⊀) : x ^ y < ⊀ := lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h) theorem rpow_add {x : ℝβ‰₯0∞} (y z : ℝ) (hx : x β‰  0) (h'x : x β‰  ⊀) : x ^ (y + z) = x ^ y * x ^ z := by cases x with | top => exact (h'x rfl).elim | coe x => have : x β‰  0 := fun h => by simp [h] at hx simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this] theorem rpow_add_of_nonneg {x : ℝβ‰₯0∞} (y z : ℝ) (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by induction x using recTopCoe Β· rcases hy.eq_or_lt with rfl|hy Β· rw [rpow_zero, one_mul, zero_add] rcases hz.eq_or_lt with rfl|hz Β· rw [rpow_zero, mul_one, add_zero] simp [top_rpow_of_pos, hy, hz, add_pos hy hz] simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz]
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
587
590
theorem rpow_neg (x : ℝβ‰₯0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by
cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;>
/- Copyright (c) 2022 Eric Rodriguez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Rodriguez -/ import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Algebra.Order.BigOperators.Group.Finset import Mathlib.Algebra.Order.Ring.Cast import Mathlib.Data.Fintype.BigOperators import Mathlib.Tactic.DeriveFintype /-! # Sign function This file defines the sign function for types with zero and a decidable less-than relation, and proves some basic theorems about it. -/ -- Don't generate unnecessary `sizeOf_spec` lemmas which the `simpNF` linter will complain about. set_option genSizeOfSpec false in /-- The type of signs. -/ inductive SignType | zero | neg | pos deriving DecidableEq, Inhabited, Fintype namespace SignType instance : Zero SignType := ⟨zero⟩ instance : One SignType := ⟨pos⟩ instance : Neg SignType := ⟨fun s => match s with | neg => pos | zero => zero | pos => neg⟩ @[simp] theorem zero_eq_zero : zero = 0 := rfl @[simp] theorem neg_eq_neg_one : neg = -1 := rfl @[simp] theorem pos_eq_one : pos = 1 := rfl instance : Mul SignType := ⟨fun x y => match x with | neg => -y | zero => zero | pos => y⟩ /-- The less-than-or-equal relation on signs. -/ protected inductive LE : SignType β†’ SignType β†’ Prop | of_neg (a) : SignType.LE neg a | zero : SignType.LE zero zero | of_pos (a) : SignType.LE a pos instance : LE SignType := ⟨SignType.LE⟩ instance LE.decidableRel : DecidableRel SignType.LE := fun a b => by cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩) instance decidableEq : DecidableEq SignType := fun a b => by cases a <;> cases b <;> first | exact isTrue (by constructor)| exact isFalse (by rintro ⟨_⟩) private lemma mul_comm : βˆ€ (a b : SignType), a * b = b * a := by rintro ⟨⟩ ⟨⟩ <;> rfl private lemma mul_assoc : βˆ€ (a b c : SignType), (a * b) * c = a * (b * c) := by rintro ⟨⟩ ⟨⟩ ⟨⟩ <;> rfl /- We can define a `Field` instance on `SignType`, but it's not mathematically sensible, so we only define the `CommGroupWithZero`. -/ instance : CommGroupWithZero SignType where zero := 0 one := 1 mul := (Β· * Β·) inv := id mul_zero a := by cases a <;> rfl zero_mul a := by cases a <;> rfl mul_one a := by cases a <;> rfl one_mul a := by cases a <;> rfl mul_inv_cancel a ha := by cases a <;> trivial mul_comm := mul_comm mul_assoc := mul_assoc exists_pair_ne := ⟨0, 1, by rintro ⟨_⟩⟩ inv_zero := rfl private lemma le_antisymm (a b : SignType) (_ : a ≀ b) (_ : b ≀ a) : a = b := by cases a <;> cases b <;> trivial private lemma le_trans (a b c : SignType) (_ : a ≀ b) (_ : b ≀ c) : a ≀ c := by cases a <;> cases b <;> cases c <;> tauto instance : LinearOrder SignType where le := (Β· ≀ Β·) le_refl a := by cases a <;> constructor le_total a b := by cases a <;> cases b <;> first | left; constructor | right; constructor le_antisymm := le_antisymm le_trans := le_trans toDecidableLE := LE.decidableRel toDecidableEq := SignType.decidableEq instance : BoundedOrder SignType where top := 1 le_top := LE.of_pos bot := -1 bot_le := #adaptation_note /-- https://github.com/leanprover/lean4/pull/6053 Added `by exact`, but don't understand why it was needed. -/ by exact LE.of_neg instance : HasDistribNeg SignType := { neg_neg := fun x => by cases x <;> rfl neg_mul := fun x y => by cases x <;> cases y <;> rfl mul_neg := fun x y => by cases x <;> cases y <;> rfl } /-- `SignType` is equivalent to `Fin 3`. -/ def fin3Equiv : SignType ≃* Fin 3 where toFun a := match a with | 0 => ⟨0, by simp⟩ | 1 => ⟨1, by simp⟩ | -1 => ⟨2, by simp⟩ invFun a := match a with | ⟨0, _⟩ => 0 | ⟨1, _⟩ => 1 | ⟨2, _⟩ => -1 left_inv a := by cases a <;> rfl right_inv a := match a with | ⟨0, _⟩ => by simp | ⟨1, _⟩ => by simp | ⟨2, _⟩ => by simp map_mul' a b := by cases a <;> cases b <;> rfl section CaseBashing theorem nonneg_iff {a : SignType} : 0 ≀ a ↔ a = 0 ∨ a = 1 := by decide +revert theorem nonneg_iff_ne_neg_one {a : SignType} : 0 ≀ a ↔ a β‰  -1 := by decide +revert theorem neg_one_lt_iff {a : SignType} : -1 < a ↔ 0 ≀ a := by decide +revert theorem nonpos_iff {a : SignType} : a ≀ 0 ↔ a = -1 ∨ a = 0 := by decide +revert theorem nonpos_iff_ne_one {a : SignType} : a ≀ 0 ↔ a β‰  1 := by decide +revert theorem lt_one_iff {a : SignType} : a < 1 ↔ a ≀ 0 := by decide +revert @[simp] theorem neg_iff {a : SignType} : a < 0 ↔ a = -1 := by decide +revert @[simp] theorem le_neg_one_iff {a : SignType} : a ≀ -1 ↔ a = -1 := le_bot_iff @[simp] theorem pos_iff {a : SignType} : 0 < a ↔ a = 1 := by decide +revert @[simp] theorem one_le_iff {a : SignType} : 1 ≀ a ↔ a = 1 := top_le_iff @[simp] theorem neg_one_le (a : SignType) : -1 ≀ a := bot_le @[simp] theorem le_one (a : SignType) : a ≀ 1 := le_top @[simp] theorem not_lt_neg_one (a : SignType) : Β¬a < -1 := not_lt_bot @[simp] theorem not_one_lt (a : SignType) : Β¬1 < a := not_top_lt @[simp] theorem self_eq_neg_iff (a : SignType) : a = -a ↔ a = 0 := by decide +revert @[simp] theorem neg_eq_self_iff (a : SignType) : -a = a ↔ a = 0 := by decide +revert @[simp] theorem neg_one_lt_one : (-1 : SignType) < 1 := bot_lt_top end CaseBashing section cast variable {Ξ± : Type*} [Zero Ξ±] [One Ξ±] [Neg Ξ±] /-- Turn a `SignType` into zero, one, or minus one. This is a coercion instance. -/ @[coe] def cast : SignType β†’ Ξ± | zero => 0 | pos => 1 | neg => -1 /-- This is a `CoeTail` since the type on the right (trivially) determines the type on the left. `outParam`-wise it could be a `Coe`, but we don't want to try applying this instance for a coercion to any `Ξ±`. -/ instance : CoeTail SignType Ξ± := ⟨cast⟩ /-- Casting out of `SignType` respects composition with functions preserving `0, 1, -1`. -/ lemma map_cast' {Ξ² : Type*} [One Ξ²] [Neg Ξ²] [Zero Ξ²] (f : Ξ± β†’ Ξ²) (h₁ : f 1 = 1) (hβ‚‚ : f 0 = 0) (h₃ : f (-1) = -1) (s : SignType) : f s = s := by cases s <;> simp only [SignType.cast, h₁, hβ‚‚, h₃] /-- Casting out of `SignType` respects composition with suitable bundled homomorphism types. -/ lemma map_cast {Ξ± Ξ² F : Type*} [AddGroupWithOne Ξ±] [One Ξ²] [SubtractionMonoid Ξ²] [FunLike F Ξ± Ξ²] [AddMonoidHomClass F Ξ± Ξ²] [OneHomClass F Ξ± Ξ²] (f : F) (s : SignType) : f s = s := by apply map_cast' <;> simp @[simp] theorem coe_zero : ↑(0 : SignType) = (0 : Ξ±) := rfl @[simp] theorem coe_one : ↑(1 : SignType) = (1 : Ξ±) := rfl @[simp] theorem coe_neg_one : ↑(-1 : SignType) = (-1 : Ξ±) := rfl @[simp, norm_cast] lemma coe_neg {Ξ± : Type*} [One Ξ±] [SubtractionMonoid Ξ±] (s : SignType) : (↑(-s) : Ξ±) = -↑s := by cases s <;> simp /-- Casting `SignType β†’ β„€ β†’ Ξ±` is the same as casting directly `SignType β†’ Ξ±`. -/ @[simp, norm_cast] lemma intCast_cast {Ξ± : Type*} [AddGroupWithOne Ξ±] (s : SignType) : ((s : β„€) : Ξ±) = s := map_cast' _ Int.cast_one Int.cast_zero (@Int.cast_one Ξ± _ β–Έ Int.cast_neg 1) _ end cast /-- `SignType.cast` as a `MulWithZeroHom`. -/ @[simps] def castHom {Ξ±} [MulZeroOneClass Ξ±] [HasDistribNeg Ξ±] : SignType β†’*β‚€ Ξ± where toFun := cast map_zero' := rfl map_one' := rfl map_mul' x y := by cases x <;> cases y <;> simp [zero_eq_zero, pos_eq_one, neg_eq_neg_one] theorem univ_eq : (Finset.univ : Finset SignType) = {0, -1, 1} := by decide theorem range_eq {Ξ±} (f : SignType β†’ Ξ±) : Set.range f = {f zero, f neg, f pos} := by classical rw [← Fintype.coe_image_univ, univ_eq] classical simp [Finset.coe_insert] @[simp, norm_cast] lemma coe_mul {Ξ±} [MulZeroOneClass Ξ±] [HasDistribNeg Ξ±] (a b : SignType) : ↑(a * b) = (a : Ξ±) * b := map_mul SignType.castHom _ _ @[simp, norm_cast] lemma coe_pow {Ξ±} [MonoidWithZero Ξ±] [HasDistribNeg Ξ±] (a : SignType) (k : β„•) : ↑(a ^ k) = (a : Ξ±) ^ k := map_pow SignType.castHom _ _ @[simp, norm_cast] lemma coe_zpow {Ξ±} [GroupWithZero Ξ±] [HasDistribNeg Ξ±] (a : SignType) (k : β„€) : ↑(a ^ k) = (a : Ξ±) ^ k := map_zpowβ‚€ SignType.castHom _ _ end SignType -- The lemma `exists_signed_sum` needs explicit universe handling in its statement. universe u variable {Ξ± : Type u} open SignType section Preorder variable [Zero Ξ±] [Preorder Ξ±] [DecidableLT Ξ±] {a : Ξ±} /-- The sign of an element is 1 if it's positive, -1 if negative, 0 otherwise. -/ def SignType.sign : Ξ± β†’o SignType := ⟨fun a => if 0 < a then 1 else if a < 0 then -1 else 0, fun a b h => by dsimp split_ifs with h₁ hβ‚‚ h₃ hβ‚„ _ _ hβ‚‚ h₃ <;> try constructor Β· cases lt_irrefl 0 (h₁.trans <| h.trans_lt h₃) Β· cases hβ‚‚ (h₁.trans_le h) Β· cases hβ‚„ (h.trans_lt h₃)⟩ theorem sign_apply : sign a = ite (0 < a) 1 (ite (a < 0) (-1) 0) := rfl @[simp] theorem sign_zero : sign (0 : Ξ±) = 0 := by simp [sign_apply] @[simp] theorem sign_pos (ha : 0 < a) : sign a = 1 := by rwa [sign_apply, if_pos] @[simp] theorem sign_neg (ha : a < 0) : sign a = -1 := by rwa [sign_apply, if_neg <| asymm ha, if_pos] theorem sign_eq_one_iff : sign a = 1 ↔ 0 < a := by refine ⟨fun h => ?_, fun h => sign_pos h⟩ by_contra hn rw [sign_apply, if_neg hn] at h split_ifs at h theorem sign_eq_neg_one_iff : sign a = -1 ↔ a < 0 := by refine ⟨fun h => ?_, fun h => sign_neg h⟩ rw [sign_apply] at h split_ifs at h assumption end Preorder section LinearOrder variable [Zero Ξ±] [LinearOrder Ξ±] {a : Ξ±} /-- `SignType.sign` respects strictly monotone zero-preserving maps. -/ lemma StrictMono.sign_comp {Ξ² F : Type*} [Zero Ξ²] [Preorder Ξ²] [DecidableLT Ξ²] [FunLike F Ξ± Ξ²] [ZeroHomClass F Ξ± Ξ²] {f : F} (hf : StrictMono f) (a : Ξ±) : sign (f a) = sign a := by simp only [sign_apply, ← map_zero f, hf.lt_iff_lt] @[simp] theorem sign_eq_zero_iff : sign a = 0 ↔ a = 0 := by refine ⟨fun h => ?_, fun h => h.symm β–Έ sign_zero⟩ rw [sign_apply] at h split_ifs at h with h_1 h_2 cases h exact (le_of_not_lt h_1).eq_of_not_lt h_2 theorem sign_ne_zero : sign a β‰  0 ↔ a β‰  0 := sign_eq_zero_iff.not @[simp] theorem sign_nonneg_iff : 0 ≀ sign a ↔ 0 ≀ a := by rcases lt_trichotomy 0 a with (h | h | h) Β· simp [h, h.le] Β· simp [← h] Β· simp [h, h.not_le] @[simp] theorem sign_nonpos_iff : sign a ≀ 0 ↔ a ≀ 0 := by rcases lt_trichotomy 0 a with (h | h | h) Β· simp [h, h.not_le] Β· simp [← h] Β· simp [h, h.le] end LinearOrder section OrderedSemiring variable [Semiring Ξ±] [PartialOrder Ξ±] [IsOrderedRing Ξ±] [DecidableLT Ξ±] [Nontrivial Ξ±] theorem sign_one : sign (1 : Ξ±) = 1 := sign_pos zero_lt_one end OrderedSemiring section OrderedRing @[simp] lemma sign_intCast {Ξ± : Type*} [Ring Ξ±] [PartialOrder Ξ±] [IsOrderedRing Ξ±] [Nontrivial Ξ±] [DecidableLT Ξ±] (n : β„€) : sign (n : Ξ±) = sign n := by simp only [sign_apply, Int.cast_pos, Int.cast_lt_zero] end OrderedRing section LinearOrderedRing variable [Ring Ξ±] [LinearOrder Ξ±] [IsStrictOrderedRing Ξ±] theorem sign_mul (x y : Ξ±) : sign (x * y) = sign x * sign y := by rcases lt_trichotomy x 0 with (hx | hx | hx) <;> rcases lt_trichotomy y 0 with (hy | hy | hy) <;> simp [hx, hy, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] @[simp] theorem sign_mul_abs (x : Ξ±) : (sign x * |x| : Ξ±) = x := by rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg] @[simp] theorem abs_mul_sign (x : Ξ±) : (|x| * sign x : Ξ±) = x := by rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg] @[simp]
Mathlib/Data/Sign.lean
405
409
theorem sign_mul_self (x : Ξ±) : sign x * x = |x| := by
rcases lt_trichotomy x 0 with hx | rfl | hx <;> simp [*, abs_of_pos, abs_of_neg] @[simp] theorem self_mul_sign (x : Ξ±) : x * sign x = |x| := by
/- Copyright (c) 2023 Richard M. Hill. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Richard M. Hill -/ import Mathlib.RingTheory.PowerSeries.Trunc import Mathlib.RingTheory.PowerSeries.Inverse import Mathlib.RingTheory.Derivation.Basic /-! # Definitions In this file we define an operation `derivative` (formal differentiation) on the ring of formal power series in one variable (over an arbitrary commutative semiring). Under suitable assumptions, we prove that two power series are equal if their derivatives are equal and their constant terms are equal. This will give us a simple tool for proving power series identities. For example, one can easily prove the power series identity $\exp ( \log (1+X)) = 1+X$ by differentiating twice. ## Main Definition - `PowerSeries.derivative R : Derivation R R⟦X⟧ R⟦X⟧` the formal derivative operation. This is abbreviated `d⁄dX R`. -/ namespace PowerSeries open Polynomial Derivation Nat section CommutativeSemiring variable {R} [CommSemiring R] /-- The formal derivative of a power series in one variable. This is defined here as a function, but will be packaged as a derivation `derivative` on `R⟦X⟧`. -/ noncomputable def derivativeFun (f : R⟦X⟧) : R⟦X⟧ := mk fun n ↦ coeff R (n + 1) f * (n + 1) theorem coeff_derivativeFun (f : R⟦X⟧) (n : β„•) : coeff R n f.derivativeFun = coeff R (n + 1) f * (n + 1) := by rw [derivativeFun, coeff_mk] theorem derivativeFun_coe (f : R[X]) : (f : R⟦X⟧).derivativeFun = derivative f := by ext rw [coeff_derivativeFun, coeff_coe, coeff_coe, coeff_derivative] theorem derivativeFun_add (f g : R⟦X⟧) : derivativeFun (f + g) = derivativeFun f + derivativeFun g := by ext rw [coeff_derivativeFun, map_add, map_add, coeff_derivativeFun, coeff_derivativeFun, add_mul]
Mathlib/RingTheory/PowerSeries/Derivative.lean
55
58
theorem derivativeFun_C (r : R) : derivativeFun (C R r) = 0 := by
ext n -- Note that `map_zero` didn't get picked up, apparently due to a missing `FunLike.coe` rw [coeff_derivativeFun, coeff_succ_C, zero_mul, (coeff R n).map_zero]
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Chris Hughes, Mario Carneiro -/ import Mathlib.Algebra.Field.IsField import Mathlib.Data.Fin.VecNotation import Mathlib.Data.Nat.Choose.Sum import Mathlib.LinearAlgebra.Finsupp.LinearCombination import Mathlib.RingTheory.Ideal.Maximal import Mathlib.Tactic.FinCases /-! # Ideals over a ring This file contains an assortment of definitions and results for `Ideal R`, the type of (left) ideals over a ring `R`. Note that over commutative rings, left ideals and two-sided ideals are equivalent. ## Implementation notes `Ideal R` is implemented using `Submodule R R`, where `β€’` is interpreted as `*`. ## TODO Support right ideals, and two-sided ideals over non-commutative rings. -/ variable {ΞΉ Ξ± Ξ² F : Type*} open Set Function open Pointwise section Semiring namespace Ideal variable {Ξ± : ΞΉ β†’ Type*} [Ξ  i, Semiring (Ξ± i)] (I : Ξ  i, Ideal (Ξ± i)) section Pi /-- `Ξ α΅’ Iα΅’` as an ideal of `Ξ α΅’ Rα΅’`. -/ def pi : Ideal (Ξ  i, Ξ± i) where carrier := { x | βˆ€ i, x i ∈ I i } zero_mem' i := (I i).zero_mem add_mem' ha hb i := (I i).add_mem (ha i) (hb i) smul_mem' a _b hb i := (I i).mul_mem_left (a i) (hb i) theorem mem_pi (x : Ξ  i, Ξ± i) : x ∈ pi I ↔ βˆ€ i, x i ∈ I i := Iff.rfl instance (priority := low) [βˆ€ i, (I i).IsTwoSided] : (pi I).IsTwoSided := ⟨fun _b hb i ↦ mul_mem_right _ _ (hb i)⟩ end Pi section Commute variable {Ξ± : Type*} [Semiring Ξ±] (I : Ideal Ξ±) {a b : Ξ±} theorem add_pow_mem_of_pow_mem_of_le_of_commute {m n k : β„•} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≀ k + 1) (hab : Commute a b) : (a + b) ^ k ∈ I := by simp_rw [hab.add_pow, ← Nat.cast_comm] apply I.sum_mem intro c _ apply mul_mem_left by_cases h : m ≀ c Β· rw [hab.pow_pow] exact I.mul_mem_left _ (I.pow_mem_of_pow_mem ha h) Β· refine I.mul_mem_left _ (I.pow_mem_of_pow_mem hb ?_) omega theorem add_pow_add_pred_mem_of_pow_mem_of_commute {m n : β„•} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hab : Commute a b) : (a + b) ^ (m + n - 1) ∈ I := I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb (by rw [← Nat.sub_le_iff_le_add]) hab end Commute end Ideal end Semiring section CommSemiring variable {a b : Ξ±} -- A separate namespace definition is needed because the variables were historically in a different -- order. namespace Ideal variable [CommSemiring Ξ±] (I : Ideal Ξ±) theorem add_pow_mem_of_pow_mem_of_le {m n k : β„•} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) (hk : m + n ≀ k + 1) : (a + b) ^ k ∈ I := I.add_pow_mem_of_pow_mem_of_le_of_commute ha hb hk (Commute.all ..) theorem add_pow_add_pred_mem_of_pow_mem {m n : β„•} (ha : a ^ m ∈ I) (hb : b ^ n ∈ I) : (a + b) ^ (m + n - 1) ∈ I := I.add_pow_add_pred_mem_of_pow_mem_of_commute ha hb (Commute.all ..) theorem pow_multiset_sum_mem_span_pow [DecidableEq Ξ±] (s : Multiset Ξ±) (n : β„•) : s.sum ^ (Multiset.card s * n + 1) ∈ span ((s.map fun (x : Ξ±) ↦ x ^ (n + 1)).toFinset : Set Ξ±) := by induction' s using Multiset.induction_on with a s hs Β· simp simp only [Finset.coe_insert, Multiset.map_cons, Multiset.toFinset_cons, Multiset.sum_cons, Multiset.card_cons, add_pow] refine Submodule.sum_mem _ ?_ intro c _hc rw [mem_span_insert] by_cases h : n + 1 ≀ c Β· refine ⟨a ^ (c - (n + 1)) * s.sum ^ ((Multiset.card s + 1) * n + 1 - c) * ((Multiset.card s + 1) * n + 1).choose c, 0, Submodule.zero_mem _, ?_⟩ rw [mul_comm _ (a ^ (n + 1))] simp_rw [← mul_assoc] rw [← pow_add, add_zero, add_tsub_cancel_of_le h] Β· use 0 simp_rw [zero_mul, zero_add] refine ⟨_, ?_, rfl⟩ replace h : c ≀ n := Nat.lt_succ_iff.mp (not_le.mp h) have : (Multiset.card s + 1) * n + 1 - c = Multiset.card s * n + 1 + (n - c) := by rw [add_mul, one_mul, add_assoc, add_comm n 1, ← add_assoc, add_tsub_assoc_of_le h] rw [this, pow_add] simp_rw [mul_assoc, mul_comm (s.sum ^ (Multiset.card s * n + 1)), ← mul_assoc] exact mul_mem_left _ _ hs theorem sum_pow_mem_span_pow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ Ξ±) (n : β„•) : (βˆ‘ i ∈ s, f i) ^ (s.card * n + 1) ∈ span ((fun i => f i ^ (n + 1)) '' s) := by classical simpa only [Multiset.card_map, Multiset.map_map, comp_apply, Multiset.toFinset_map, Finset.coe_image, Finset.val_toFinset] using pow_multiset_sum_mem_span_pow (s.1.map f) n theorem span_pow_eq_top (s : Set Ξ±) (hs : span s = ⊀) (n : β„•) : span ((fun (x : Ξ±) => x ^ n) '' s) = ⊀ := by rw [eq_top_iff_one] rcases n with - | n Β· obtain rfl | ⟨x, hx⟩ := eq_empty_or_nonempty s Β· rw [Set.image_empty, hs] trivial Β· exact subset_span ⟨_, hx, pow_zero _⟩ rw [eq_top_iff_one, span, Finsupp.mem_span_iff_linearCombination] at hs rcases hs with ⟨f, hf⟩ have hf : (f.support.sum fun a => f a * a) = 1 := hf -- Porting note: was `change ... at hf` have := sum_pow_mem_span_pow f.support (fun a => f a * a) n rw [hf, one_pow] at this refine span_le.mpr ?_ this rintro _ hx simp_rw [Set.mem_image] at hx rcases hx with ⟨x, _, rfl⟩ have : span ({(x : Ξ±) ^ (n + 1)} : Set Ξ±) ≀ span ((fun x : Ξ± => x ^ (n + 1)) '' s) := by rw [span_le, Set.singleton_subset_iff] exact subset_span ⟨x, x.prop, rfl⟩ refine this ?_ rw [mul_pow, mem_span_singleton] exact ⟨f x ^ (n + 1), mul_comm _ _⟩ theorem span_range_pow_eq_top (s : Set Ξ±) (hs : span s = ⊀) (n : s β†’ β„•) : span (Set.range fun x ↦ x.1 ^ n x) = ⊀ := by have ⟨t, hts, mem⟩ := Submodule.mem_span_finite_of_mem_span ((eq_top_iff_one _).mp hs) refine top_unique ((span_pow_eq_top _ ((eq_top_iff_one _).mpr mem) <| t.attach.sup fun x ↦ n ⟨x, hts x.2⟩).ge.trans <| span_le.mpr ?_) rintro _ ⟨x, hxt, rfl⟩ rw [← Nat.sub_add_cancel (Finset.le_sup <| t.mem_attach ⟨x, hxt⟩)] simp_rw [pow_add] exact mul_mem_left _ _ (subset_span ⟨_, rfl⟩) theorem prod_mem {ΞΉ : Type*} {f : ΞΉ β†’ Ξ±} {s : Finset ΞΉ} (I : Ideal Ξ±) {i : ΞΉ} (hi : i ∈ s) (hfi : f i ∈ I) : ∏ i ∈ s, f i ∈ I := by classical rw [Finset.prod_eq_prod_diff_singleton_mul hi] exact Ideal.mul_mem_left _ _ hfi end Ideal end CommSemiring section DivisionSemiring variable {K : Type*} [DivisionSemiring K] (I : Ideal K) namespace Ideal variable (K) in /-- A bijection between (left) ideals of a division ring and `{0, 1}`, sending `βŠ₯` to `0` and `⊀` to `1`. -/ def equivFinTwo [DecidableEq (Ideal K)] : Ideal K ≃ Fin 2 where toFun := fun I ↦ if I = βŠ₯ then 0 else 1 invFun := ![βŠ₯, ⊀] left_inv := fun I ↦ by rcases eq_bot_or_top I with rfl | rfl <;> simp right_inv := fun i ↦ by fin_cases i <;> simp instance : Finite (Ideal K) := let _i := Classical.decEq (Ideal K); ⟨equivFinTwo K⟩ /-- Ideals of a `DivisionSemiring` are a simple order. Thanks to the way abbreviations work, this automatically gives an `IsSimpleModule K` instance. -/ instance isSimpleOrder : IsSimpleOrder (Ideal K) := ⟨eq_bot_or_top⟩ end Ideal end DivisionSemiring -- TODO: consider moving the lemmas below out of the `Ring` namespace since they are -- about `CommSemiring`s. namespace Ring variable {R : Type*} [CommSemiring R]
Mathlib/RingTheory/Ideal/Basic.lean
218
221
theorem exists_not_isUnit_of_not_isField [Nontrivial R] (hf : Β¬IsField R) : βˆƒ (x : R) (_hx : x β‰  (0 : R)), Β¬IsUnit x := by
have : ¬_ := fun h => hf ⟨exists_pair_ne R, mul_comm, h⟩ simp_rw [isUnit_iff_exists_inv]
/- 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.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Analysis.Normed.Module.Convex /-! # Sides of affine subspaces This file defines notions of two points being on the same or opposite sides of an affine subspace. ## Main definitions * `s.WSameSide x y`: The points `x` and `y` are weakly on the same side of the affine subspace `s`. * `s.SSameSide x y`: The points `x` and `y` are strictly on the same side of the affine subspace `s`. * `s.WOppSide x y`: The points `x` and `y` are weakly on opposite sides of the affine subspace `s`. * `s.SOppSide x y`: The points `x` and `y` are strictly on opposite sides of the affine subspace `s`. -/ variable {R V V' P P' : Type*} open AffineEquiv AffineMap namespace AffineSubspace section StrictOrderedCommRing variable [CommRing R] [PartialOrder R] [IsStrictOrderedRing R] [AddCommGroup V] [Module R V] [AddTorsor V P] variable [AddCommGroup V'] [Module R V'] [AddTorsor V' P'] /-- The points `x` and `y` are weakly on the same side of `s`. -/ def WSameSide (s : AffineSubspace R P) (x y : P) : Prop := βˆƒα΅‰ (p₁ ∈ s) (pβ‚‚ ∈ s), SameRay R (x -α΅₯ p₁) (y -α΅₯ pβ‚‚) /-- The points `x` and `y` are strictly on the same side of `s`. -/ def SSameSide (s : AffineSubspace R P) (x y : P) : Prop := s.WSameSide x y ∧ x βˆ‰ s ∧ y βˆ‰ s /-- The points `x` and `y` are weakly on opposite sides of `s`. -/ def WOppSide (s : AffineSubspace R P) (x y : P) : Prop := βˆƒα΅‰ (p₁ ∈ s) (pβ‚‚ ∈ s), SameRay R (x -α΅₯ p₁) (pβ‚‚ -α΅₯ y) /-- The points `x` and `y` are strictly on opposite sides of `s`. -/ def SOppSide (s : AffineSubspace R P) (x y : P) : Prop := s.WOppSide x y ∧ x βˆ‰ s ∧ y βˆ‰ s theorem WSameSide.map {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) (f : P →ᡃ[R] P') : (s.map f).WSameSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f pβ‚‚, mem_map_of_mem f hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).WSameSide (f x) (f y) ↔ s.WSameSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fpβ‚‚, hfpβ‚‚, h⟩ rw [mem_map] at hfp₁ hfpβ‚‚ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfpβ‚‚ with ⟨pβ‚‚, hpβ‚‚, rfl⟩ refine ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).SSameSide (f x) (f y) ↔ s.SSameSide x y := by simp_rw [SSameSide, hf.wSameSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᡃ[R] P') : (s.map ↑f).WSameSide (f x) (f y) ↔ s.WSameSide x y := (show Function.Injective f.toAffineMap from f.injective).wSameSide_map_iff @[simp] theorem _root_.AffineEquiv.sSameSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᡃ[R] P') : (s.map ↑f).SSameSide (f x) (f y) ↔ s.SSameSide x y := (show Function.Injective f.toAffineMap from f.injective).sSameSide_map_iff theorem WOppSide.map {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) (f : P →ᡃ[R] P') : (s.map f).WOppSide (f x) (f y) := by rcases h with ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨f p₁, mem_map_of_mem f hp₁, f pβ‚‚, mem_map_of_mem f hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub] exact h.map f.linear theorem _root_.Function.Injective.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).WOppSide (f x) (f y) ↔ s.WOppSide x y := by refine ⟨fun h => ?_, fun h => h.map _⟩ rcases h with ⟨fp₁, hfp₁, fpβ‚‚, hfpβ‚‚, h⟩ rw [mem_map] at hfp₁ hfpβ‚‚ rcases hfp₁ with ⟨p₁, hp₁, rfl⟩ rcases hfpβ‚‚ with ⟨pβ‚‚, hpβ‚‚, rfl⟩ refine ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, ?_⟩ simp_rw [← linearMap_vsub, (f.linear_injective_iff.2 hf).sameRay_map_iff] at h exact h theorem _root_.Function.Injective.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} {f : P →ᡃ[R] P'} (hf : Function.Injective f) : (s.map f).SOppSide (f x) (f y) ↔ s.SOppSide x y := by simp_rw [SOppSide, hf.wOppSide_map_iff, mem_map_iff_mem_of_injective hf] @[simp] theorem _root_.AffineEquiv.wOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᡃ[R] P') : (s.map ↑f).WOppSide (f x) (f y) ↔ s.WOppSide x y := (show Function.Injective f.toAffineMap from f.injective).wOppSide_map_iff @[simp] theorem _root_.AffineEquiv.sOppSide_map_iff {s : AffineSubspace R P} {x y : P} (f : P ≃ᡃ[R] P') : (s.map ↑f).SOppSide (f x) (f y) ↔ s.SOppSide x y := (show Function.Injective f.toAffineMap from f.injective).sOppSide_map_iff theorem WSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WSameSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SSameSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem WOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.WOppSide x y) : (s : Set P).Nonempty := ⟨h.choose, h.choose_spec.left⟩ theorem SOppSide.nonempty {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : (s : Set P).Nonempty := ⟨h.1.choose, h.1.choose_spec.left⟩ theorem SSameSide.wSameSide {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : s.WSameSide x y := h.1 theorem SSameSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : x βˆ‰ s := h.2.1 theorem SSameSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SSameSide x y) : y βˆ‰ s := h.2.2 theorem SOppSide.wOppSide {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : s.WOppSide x y := h.1 theorem SOppSide.left_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : x βˆ‰ s := h.2.1 theorem SOppSide.right_not_mem {s : AffineSubspace R P} {x y : P} (h : s.SOppSide x y) : y βˆ‰ s := h.2.2 theorem wSameSide_comm {s : AffineSubspace R P} {x y : P} : s.WSameSide x y ↔ s.WSameSide y x := ⟨fun ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ => ⟨pβ‚‚, hpβ‚‚, p₁, hp₁, h.symm⟩, fun ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ => ⟨pβ‚‚, hpβ‚‚, p₁, hp₁, h.symm⟩⟩ alias ⟨WSameSide.symm, _⟩ := wSameSide_comm theorem sSameSide_comm {s : AffineSubspace R P} {x y : P} : s.SSameSide x y ↔ s.SSameSide y x := by rw [SSameSide, SSameSide, wSameSide_comm, and_comm (b := x βˆ‰ s)] alias ⟨SSameSide.symm, _⟩ := sSameSide_comm theorem wOppSide_comm {s : AffineSubspace R P} {x y : P} : s.WOppSide x y ↔ s.WOppSide y x := by constructor Β· rintro ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨pβ‚‚, hpβ‚‚, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] Β· rintro ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨pβ‚‚, hpβ‚‚, p₁, hp₁, ?_⟩ rwa [SameRay.sameRay_comm, ← sameRay_neg_iff, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev] alias ⟨WOppSide.symm, _⟩ := wOppSide_comm theorem sOppSide_comm {s : AffineSubspace R P} {x y : P} : s.SOppSide x y ↔ s.SOppSide y x := by rw [SOppSide, SOppSide, wOppSide_comm, and_comm (b := x βˆ‰ s)] alias ⟨SOppSide.symm, _⟩ := sOppSide_comm theorem not_wSameSide_bot (x y : P) : Β¬(βŠ₯ : AffineSubspace R P).WSameSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sSameSide_bot (x y : P) : Β¬(βŠ₯ : AffineSubspace R P).SSameSide x y := fun h => not_wSameSide_bot x y h.wSameSide theorem not_wOppSide_bot (x y : P) : Β¬(βŠ₯ : AffineSubspace R P).WOppSide x y := fun ⟨_, h, _⟩ => h.elim theorem not_sOppSide_bot (x y : P) : Β¬(βŠ₯ : AffineSubspace R P).SOppSide x y := fun h => not_wOppSide_bot x y h.wOppSide @[simp] theorem wSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.WSameSide x x ↔ (s : Set P).Nonempty := ⟨fun h => h.nonempty, fun ⟨p, hp⟩ => ⟨p, hp, p, hp, SameRay.rfl⟩⟩ theorem sSameSide_self_iff {s : AffineSubspace R P} {x : P} : s.SSameSide x x ↔ (s : Set P).Nonempty ∧ x βˆ‰ s := ⟨fun ⟨h, hx, _⟩ => ⟨wSameSide_self_iff.1 h, hx⟩, fun ⟨h, hx⟩ => ⟨wSameSide_self_iff.2 h, hx, hx⟩⟩ theorem wSameSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WSameSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left theorem wSameSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WSameSide x y := (wSameSide_of_left_mem x hy).symm theorem wOppSide_of_left_mem {s : AffineSubspace R P} {x : P} (y : P) (hx : x ∈ s) : s.WOppSide x y := by refine ⟨x, hx, x, hx, ?_⟩ rw [vsub_self] apply SameRay.zero_left theorem wOppSide_of_right_mem {s : AffineSubspace R P} (x : P) {y : P} (hy : y ∈ s) : s.WOppSide x y := (wOppSide_of_left_mem x hy).symm theorem wSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide (v +α΅₯ x) y ↔ s.WSameSide x y := by constructor Β· rintro ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨-v +α΅₯ p₁, AffineSubspace.vadd_mem_of_mem_direction (Submodule.neg_mem _ hv) hp₁, pβ‚‚, hpβ‚‚, ?_⟩ rwa [vsub_vadd_eq_vsub_sub, sub_neg_eq_add, add_comm, ← vadd_vsub_assoc] Β· rintro ⟨p₁, hp₁, pβ‚‚, hpβ‚‚, h⟩ refine ⟨v +α΅₯ p₁, AffineSubspace.vadd_mem_of_mem_direction hv hp₁, pβ‚‚, hpβ‚‚, ?_⟩ rwa [vadd_vsub_vadd_cancel_left] theorem wSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.WSameSide x (v +α΅₯ y) ↔ s.WSameSide x y := by rw [wSameSide_comm, wSameSide_vadd_left_iff hv, wSameSide_comm] theorem sSameSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide (v +α΅₯ x) y ↔ s.SSameSide x y := by rw [SSameSide, SSameSide, wSameSide_vadd_left_iff hv, vadd_mem_iff_mem_of_mem_direction hv]
Mathlib/Analysis/Convex/Side.lean
248
252
theorem sSameSide_vadd_right_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) : s.SSameSide x (v +α΅₯ y) ↔ s.SSameSide x y := by
rw [sSameSide_comm, sSameSide_vadd_left_iff hv, sSameSide_comm] theorem wOppSide_vadd_left_iff {s : AffineSubspace R P} {x y : P} {v : V} (hv : v ∈ s.direction) :
/- Copyright (c) 2015, 2017 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Robert Y. Lewis, Johannes HΓΆlzl, Mario Carneiro, SΓ©bastien GouΓ«zel -/ import Mathlib.Topology.Order.Compact import Mathlib.Topology.MetricSpace.ProperSpace import Mathlib.Topology.MetricSpace.Cauchy import Mathlib.Topology.EMetricSpace.Diam /-! ## Boundedness in (pseudo)-metric spaces This file contains one definition, and various results on boundedness in pseudo-metric spaces. * `Metric.diam s` : The `iSup` of the distances of members of `s`. Defined in terms of `EMetric.diam`, for better handling of the case when it should be infinite. * `isBounded_iff_subset_closedBall`: a non-empty set is bounded if and only if it is included in some closed ball * describing the cobounded filter, relating to the cocompact filter * `IsCompact.isBounded`: compact sets are bounded * `TotallyBounded.isBounded`: totally bounded sets are bounded * `isCompact_iff_isClosed_bounded`, the **Heine–Borel theorem**: in a proper space, a set is compact if and only if it is closed and bounded. * `cobounded_eq_cocompact`: in a proper space, cobounded and compact sets are the same diameter of a subset, and its relation to boundedness ## Tags metric, pseudo_metric, bounded, diameter, Heine-Borel theorem -/ assert_not_exists Basis open Set Filter Bornology open scoped ENNReal Uniformity Topology Pointwise universe u v w variable {Ξ± : Type u} {Ξ² : Type v} {X ΞΉ : Type*} variable [PseudoMetricSpace Ξ±] namespace Metric section Bounded variable {x : Ξ±} {s t : Set Ξ±} {r : ℝ} /-- Closed balls are bounded -/ theorem isBounded_closedBall : IsBounded (closedBall x r) := isBounded_iff.2 ⟨r + r, fun y hy z hz => calc dist y z ≀ dist y x + dist z x := dist_triangle_right _ _ _ _ ≀ r + r := add_le_add hy hz⟩ /-- Open balls are bounded -/ theorem isBounded_ball : IsBounded (ball x r) := isBounded_closedBall.subset ball_subset_closedBall /-- Spheres are bounded -/ theorem isBounded_sphere : IsBounded (sphere x r) := isBounded_closedBall.subset sphere_subset_closedBall /-- Given a point, a bounded subset is included in some ball around this point -/ theorem isBounded_iff_subset_closedBall (c : Ξ±) : IsBounded s ↔ βˆƒ r, s βŠ† closedBall c r := ⟨fun h ↦ (isBounded_iff.1 (h.insert c)).imp fun _r hr _x hx ↦ hr (.inr hx) (mem_insert _ _), fun ⟨_r, hr⟩ ↦ isBounded_closedBall.subset hr⟩ theorem _root_.Bornology.IsBounded.subset_closedBall (h : IsBounded s) (c : Ξ±) : βˆƒ r, s βŠ† closedBall c r := (isBounded_iff_subset_closedBall c).1 h theorem _root_.Bornology.IsBounded.subset_ball_lt (h : IsBounded s) (a : ℝ) (c : Ξ±) : βˆƒ r, a < r ∧ s βŠ† ball c r := let ⟨r, hr⟩ := h.subset_closedBall c ⟨max r a + 1, (le_max_right _ _).trans_lt (lt_add_one _), hr.trans <| closedBall_subset_ball <| (le_max_left _ _).trans_lt (lt_add_one _)⟩ theorem _root_.Bornology.IsBounded.subset_ball (h : IsBounded s) (c : Ξ±) : βˆƒ r, s βŠ† ball c r := (h.subset_ball_lt 0 c).imp fun _ ↦ And.right theorem isBounded_iff_subset_ball (c : Ξ±) : IsBounded s ↔ βˆƒ r, s βŠ† ball c r := ⟨(IsBounded.subset_ball Β· c), fun ⟨_r, hr⟩ ↦ isBounded_ball.subset hr⟩ theorem _root_.Bornology.IsBounded.subset_closedBall_lt (h : IsBounded s) (a : ℝ) (c : Ξ±) : βˆƒ r, a < r ∧ s βŠ† closedBall c r := let ⟨r, har, hr⟩ := h.subset_ball_lt a c ⟨r, har, hr.trans ball_subset_closedBall⟩ theorem isBounded_closure_of_isBounded (h : IsBounded s) : IsBounded (closure s) := let ⟨C, h⟩ := isBounded_iff.1 h isBounded_iff.2 ⟨C, fun _a ha _b hb => isClosed_Iic.closure_subset <| map_mem_closureβ‚‚ continuous_dist ha hb h⟩ protected theorem _root_.Bornology.IsBounded.closure (h : IsBounded s) : IsBounded (closure s) := isBounded_closure_of_isBounded h @[simp] theorem isBounded_closure_iff : IsBounded (closure s) ↔ IsBounded s := ⟨fun h => h.subset subset_closure, fun h => h.closure⟩ theorem hasBasis_cobounded_compl_closedBall (c : Ξ±) : (cobounded Ξ±).HasBasis (fun _ ↦ True) (fun r ↦ (closedBall c r)ᢜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_closedBall c).trans <| by simp⟩ theorem hasAntitoneBasis_cobounded_compl_closedBall (c : Ξ±) : (cobounded Ξ±).HasAntitoneBasis (fun r ↦ (closedBall c r)ᢜ) := ⟨Metric.hasBasis_cobounded_compl_closedBall _, fun _ _ hr _ ↦ by simpa using hr.trans_lt⟩ theorem hasBasis_cobounded_compl_ball (c : Ξ±) : (cobounded Ξ±).HasBasis (fun _ ↦ True) (fun r ↦ (ball c r)ᢜ) := ⟨compl_surjective.forall.2 fun _ ↦ (isBounded_iff_subset_ball c).trans <| by simp⟩ theorem hasAntitoneBasis_cobounded_compl_ball (c : Ξ±) : (cobounded Ξ±).HasAntitoneBasis (fun r ↦ (ball c r)ᢜ) := ⟨Metric.hasBasis_cobounded_compl_ball _, fun _ _ hr _ ↦ by simpa using hr.trans⟩ @[simp] theorem comap_dist_right_atTop (c : Ξ±) : comap (dist Β· c) atTop = cobounded Ξ± := (atTop_basis.comap _).eq_of_same_basis <| by simpa only [compl_def, mem_ball, not_lt] using hasBasis_cobounded_compl_ball c @[simp] theorem comap_dist_left_atTop (c : Ξ±) : comap (dist c) atTop = cobounded Ξ± := by simpa only [dist_comm _ c] using comap_dist_right_atTop c @[simp] theorem tendsto_dist_right_atTop_iff (c : Ξ±) {f : Ξ² β†’ Ξ±} {l : Filter Ξ²} : Tendsto (fun x ↦ dist (f x) c) l atTop ↔ Tendsto f l (cobounded Ξ±) := by rw [← comap_dist_right_atTop c, tendsto_comap_iff, Function.comp_def] @[simp] theorem tendsto_dist_left_atTop_iff (c : Ξ±) {f : Ξ² β†’ Ξ±} {l : Filter Ξ²} : Tendsto (fun x ↦ dist c (f x)) l atTop ↔ Tendsto f l (cobounded Ξ±) := by simp only [dist_comm c, tendsto_dist_right_atTop_iff] theorem tendsto_dist_right_cobounded_atTop (c : Ξ±) : Tendsto (dist Β· c) (cobounded Ξ±) atTop := tendsto_iff_comap.2 (comap_dist_right_atTop c).ge theorem tendsto_dist_left_cobounded_atTop (c : Ξ±) : Tendsto (dist c) (cobounded Ξ±) atTop := tendsto_iff_comap.2 (comap_dist_left_atTop c).ge /-- A totally bounded set is bounded -/ theorem _root_.TotallyBounded.isBounded {s : Set Ξ±} (h : TotallyBounded s) : IsBounded s := -- We cover the totally bounded set by finitely many balls of radius 1, -- and then argue that a finite union of bounded sets is bounded let ⟨_t, fint, subs⟩ := (totallyBounded_iff.mp h) 1 zero_lt_one ((isBounded_biUnion fint).2 fun _ _ => isBounded_ball).subset subs /-- A compact set is bounded -/ theorem _root_.IsCompact.isBounded {s : Set Ξ±} (h : IsCompact s) : IsBounded s := -- A compact set is totally bounded, thus bounded h.totallyBounded.isBounded theorem cobounded_le_cocompact : cobounded Ξ± ≀ cocompact Ξ± := hasBasis_cocompact.ge_iff.2 fun _s hs ↦ hs.isBounded theorem isCobounded_iff_closedBall_compl_subset {s : Set Ξ±} (c : Ξ±) : IsCobounded s ↔ βˆƒ (r : ℝ), (Metric.closedBall c r)ᢜ βŠ† s := by rw [← isBounded_compl_iff, isBounded_iff_subset_closedBall c] apply exists_congr intro r rw [compl_subset_comm] theorem _root_.Bornology.IsCobounded.closedBall_compl_subset {s : Set Ξ±} (hs : IsCobounded s) (c : Ξ±) : βˆƒ (r : ℝ), (Metric.closedBall c r)ᢜ βŠ† s := (isCobounded_iff_closedBall_compl_subset c).mp hs theorem closedBall_compl_subset_of_mem_cocompact {s : Set Ξ±} (hs : s ∈ cocompact Ξ±) (c : Ξ±) : βˆƒ (r : ℝ), (Metric.closedBall c r)ᢜ βŠ† s := IsCobounded.closedBall_compl_subset (cobounded_le_cocompact hs) c theorem mem_cocompact_of_closedBall_compl_subset [ProperSpace Ξ±] (c : Ξ±) (h : βˆƒ r, (closedBall c r)ᢜ βŠ† s) : s ∈ cocompact Ξ± := by rcases h with ⟨r, h⟩ rw [Filter.mem_cocompact] exact ⟨closedBall c r, isCompact_closedBall c r, h⟩ theorem mem_cocompact_iff_closedBall_compl_subset [ProperSpace Ξ±] (c : Ξ±) : s ∈ cocompact Ξ± ↔ βˆƒ r, (closedBall c r)ᢜ βŠ† s := ⟨(closedBall_compl_subset_of_mem_cocompact Β· _), mem_cocompact_of_closedBall_compl_subset _⟩ /-- Characterization of the boundedness of the range of a function -/ theorem isBounded_range_iff {f : Ξ² β†’ Ξ±} : IsBounded (range f) ↔ βˆƒ C, βˆ€ x y, dist (f x) (f y) ≀ C := isBounded_iff.trans <| by simp only [forall_mem_range] theorem isBounded_image_iff {f : Ξ² β†’ Ξ±} {s : Set Ξ²} : IsBounded (f '' s) ↔ βˆƒ C, βˆ€ x ∈ s, βˆ€ y ∈ s, dist (f x) (f y) ≀ C := isBounded_iff.trans <| by simp only [forall_mem_image] theorem isBounded_range_of_tendsto_cofinite_uniformity {f : Ξ² β†’ Ξ±} (hf : Tendsto (Prod.map f f) (.cofinite Γ—Λ’ .cofinite) (𝓀 Ξ±)) : IsBounded (range f) := by rcases (hasBasis_cofinite.prod_self.tendsto_iff uniformity_basis_dist).1 hf 1 zero_lt_one with ⟨s, hsf, hs1⟩ rw [← image_union_image_compl_eq_range] refine (hsf.image f).isBounded.union (isBounded_image_iff.2 ⟨1, fun x hx y hy ↦ ?_⟩) exact le_of_lt (hs1 (x, y) ⟨hx, hy⟩) theorem isBounded_range_of_cauchy_map_cofinite {f : Ξ² β†’ Ξ±} (hf : Cauchy (map f cofinite)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (cauchy_map_iff.1 hf).2 theorem _root_.CauchySeq.isBounded_range {f : β„• β†’ Ξ±} (hf : CauchySeq f) : IsBounded (range f) := isBounded_range_of_cauchy_map_cofinite <| by rwa [Nat.cofinite_eq_atTop] theorem isBounded_range_of_tendsto_cofinite {f : Ξ² β†’ Ξ±} {a : Ξ±} (hf : Tendsto f cofinite (𝓝 a)) : IsBounded (range f) := isBounded_range_of_tendsto_cofinite_uniformity <| (hf.prodMap hf).mono_right <| nhds_prod_eq.symm.trans_le (nhds_le_uniformity a) /-- In a compact space, all sets are bounded -/ theorem isBounded_of_compactSpace [CompactSpace Ξ±] : IsBounded s := isCompact_univ.isBounded.subset (subset_univ _) theorem isBounded_range_of_tendsto (u : β„• β†’ Ξ±) {x : Ξ±} (hu : Tendsto u atTop (𝓝 x)) : IsBounded (range u) := hu.cauchySeq.isBounded_range theorem disjoint_nhds_cobounded (x : Ξ±) : Disjoint (𝓝 x) (cobounded Ξ±) := disjoint_of_disjoint_of_mem disjoint_compl_right (ball_mem_nhds _ one_pos) isBounded_ball theorem disjoint_cobounded_nhds (x : Ξ±) : Disjoint (cobounded Ξ±) (𝓝 x) := (disjoint_nhds_cobounded x).symm theorem disjoint_nhdsSet_cobounded {s : Set Ξ±} (hs : IsCompact s) : Disjoint (𝓝˒ s) (cobounded Ξ±) := hs.disjoint_nhdsSet_left.2 fun _ _ ↦ disjoint_nhds_cobounded _ theorem disjoint_cobounded_nhdsSet {s : Set Ξ±} (hs : IsCompact s) : Disjoint (cobounded Ξ±) (𝓝˒ s) := (disjoint_nhdsSet_cobounded hs).symm theorem exists_isBounded_image_of_tendsto {Ξ± Ξ² : Type*} [PseudoMetricSpace Ξ²] {l : Filter Ξ±} {f : Ξ± β†’ Ξ²} {x : Ξ²} (hf : Tendsto f l (𝓝 x)) : βˆƒ s ∈ l, IsBounded (f '' s) := (l.basis_sets.map f).disjoint_iff_left.mp <| (disjoint_nhds_cobounded x).mono_left hf /-- If a function is continuous within a set `s` at every point of a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt [TopologicalSpace Ξ²] {k s : Set Ξ²} {f : Ξ² β†’ Ξ±} (hk : IsCompact k) (hf : βˆ€ x ∈ k, ContinuousWithinAt f s x) : βˆƒ t, k βŠ† t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := by have : Disjoint (𝓝˒ k βŠ“ π“Ÿ s) (comap f (cobounded Ξ±)) := by rw [disjoint_assoc, inf_comm, hk.disjoint_nhdsSet_left] exact fun x hx ↦ disjoint_left_comm.2 <| tendsto_comap.disjoint (disjoint_cobounded_nhds _) (hf x hx) rcases ((((hasBasis_nhdsSet _).inf_principal _)).disjoint_iff ((basis_sets _).comap _)).1 this with ⟨U, ⟨hUo, hkU⟩, t, ht, hd⟩ refine ⟨U, hkU, hUo, (isBounded_compl_iff.2 ht).subset ?_⟩ rwa [image_subset_iff, preimage_compl, subset_compl_iff_disjoint_right] /-- If a function is continuous at every point of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/ theorem exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt [TopologicalSpace Ξ²] {k : Set Ξ²} {f : Ξ² β†’ Ξ±} (hk : IsCompact k) (hf : βˆ€ x ∈ k, ContinuousAt f x) : βˆƒ t, k βŠ† t ∧ IsOpen t ∧ IsBounded (f '' t) := by simp_rw [← continuousWithinAt_univ] at hf simpa only [inter_univ] using exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk hf /-- If a function is continuous on a set `s` containing a compact set `k`, then it is bounded on some open neighborhood of `k` in `s`. -/ theorem exists_isOpen_isBounded_image_inter_of_isCompact_of_continuousOn [TopologicalSpace Ξ²] {k s : Set Ξ²} {f : Ξ² β†’ Ξ±} (hk : IsCompact k) (hks : k βŠ† s) (hf : ContinuousOn f s) : βˆƒ t, k βŠ† t ∧ IsOpen t ∧ IsBounded (f '' (t ∩ s)) := exists_isOpen_isBounded_image_inter_of_isCompact_of_forall_continuousWithinAt hk fun x hx => hf x (hks hx) /-- If a function is continuous on a neighborhood of a compact set `k`, then it is bounded on some open neighborhood of `k`. -/ theorem exists_isOpen_isBounded_image_of_isCompact_of_continuousOn [TopologicalSpace Ξ²] {k s : Set Ξ²} {f : Ξ² β†’ Ξ±} (hk : IsCompact k) (hs : IsOpen s) (hks : k βŠ† s) (hf : ContinuousOn f s) : βˆƒ t, k βŠ† t ∧ IsOpen t ∧ IsBounded (f '' t) := exists_isOpen_isBounded_image_of_isCompact_of_forall_continuousAt hk fun _x hx => hf.continuousAt (hs.mem_nhds (hks hx)) /-- The **Heine–Borel theorem**: In a proper space, a closed bounded set is compact. -/ theorem isCompact_of_isClosed_isBounded [ProperSpace Ξ±] (hc : IsClosed s) (hb : IsBounded s) : IsCompact s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, -⟩) Β· exact isCompact_empty Β· rcases hb.subset_closedBall x with ⟨r, hr⟩ exact (isCompact_closedBall x r).of_isClosed_subset hc hr /-- The **Heine–Borel theorem**: In a proper space, the closure of a bounded set is compact. -/ theorem _root_.Bornology.IsBounded.isCompact_closure [ProperSpace Ξ±] (h : IsBounded s) : IsCompact (closure s) := isCompact_of_isClosed_isBounded isClosed_closure h.closure -- TODO: assume `[MetricSpace Ξ±]` instead of `[PseudoMetricSpace Ξ±] [T2Space Ξ±]` /-- The **Heine–Borel theorem**: In a proper Hausdorff space, a set is compact if and only if it is closed and bounded. -/ theorem isCompact_iff_isClosed_bounded [T2Space Ξ±] [ProperSpace Ξ±] : IsCompact s ↔ IsClosed s ∧ IsBounded s := ⟨fun h => ⟨h.isClosed, h.isBounded⟩, fun h => isCompact_of_isClosed_isBounded h.1 h.2⟩ theorem compactSpace_iff_isBounded_univ [ProperSpace Ξ±] : CompactSpace Ξ± ↔ IsBounded (univ : Set Ξ±) := ⟨@isBounded_of_compactSpace Ξ± _ _, fun hb => ⟨isCompact_of_isClosed_isBounded isClosed_univ hb⟩⟩ section CompactIccSpace variable [Preorder Ξ±] [CompactIccSpace Ξ±] theorem _root_.totallyBounded_Icc (a b : Ξ±) : TotallyBounded (Icc a b) := isCompact_Icc.totallyBounded theorem _root_.totallyBounded_Ico (a b : Ξ±) : TotallyBounded (Ico a b) := (totallyBounded_Icc a b).subset Ico_subset_Icc_self theorem _root_.totallyBounded_Ioc (a b : Ξ±) : TotallyBounded (Ioc a b) := (totallyBounded_Icc a b).subset Ioc_subset_Icc_self theorem _root_.totallyBounded_Ioo (a b : Ξ±) : TotallyBounded (Ioo a b) := (totallyBounded_Icc a b).subset Ioo_subset_Icc_self theorem isBounded_Icc (a b : Ξ±) : IsBounded (Icc a b) := (totallyBounded_Icc a b).isBounded theorem isBounded_Ico (a b : Ξ±) : IsBounded (Ico a b) := (totallyBounded_Ico a b).isBounded theorem isBounded_Ioc (a b : Ξ±) : IsBounded (Ioc a b) := (totallyBounded_Ioc a b).isBounded theorem isBounded_Ioo (a b : Ξ±) : IsBounded (Ioo a b) := (totallyBounded_Ioo a b).isBounded /-- In a pseudo metric space with a conditionally complete linear order such that the order and the metric structure give the same topology, any order-bounded set is metric-bounded. -/ theorem isBounded_of_bddAbove_of_bddBelow {s : Set Ξ±} (h₁ : BddAbove s) (hβ‚‚ : BddBelow s) : IsBounded s := let ⟨u, hu⟩ := h₁ let ⟨l, hl⟩ := hβ‚‚ (isBounded_Icc l u).subset (fun _x hx => mem_Icc.mpr ⟨hl hx, hu hx⟩) end CompactIccSpace end Bounded section Diam variable {s : Set Ξ±} {x y z : Ξ±} /-- The diameter of a set in a metric space. To get controllable behavior even when the diameter should be infinite, we express it in terms of the `EMetric.diam` -/ noncomputable def diam (s : Set Ξ±) : ℝ := ENNReal.toReal (EMetric.diam s) /-- The diameter of a set is always nonnegative -/ theorem diam_nonneg : 0 ≀ diam s := ENNReal.toReal_nonneg theorem diam_subsingleton (hs : s.Subsingleton) : diam s = 0 := by simp only [diam, EMetric.diam_subsingleton hs, ENNReal.toReal_zero] /-- The empty set has zero diameter -/ @[simp] theorem diam_empty : diam (βˆ… : Set Ξ±) = 0 := diam_subsingleton subsingleton_empty /-- A singleton has zero diameter -/ @[simp] theorem diam_singleton : diam ({x} : Set Ξ±) = 0 := diam_subsingleton subsingleton_singleton @[to_additive (attr := simp)] theorem diam_one [One Ξ±] : diam (1 : Set Ξ±) = 0 := diam_singleton -- Does not work as a simp-lemma, since {x, y} reduces to (insert y {x}) theorem diam_pair : diam ({x, y} : Set Ξ±) = dist x y := by simp only [diam, EMetric.diam_pair, dist_edist] -- Does not work as a simp-lemma, since {x, y, z} reduces to (insert z (insert y {x})) theorem diam_triple : Metric.diam ({x, y, z} : Set Ξ±) = max (max (dist x y) (dist x z)) (dist y z) := by simp only [Metric.diam, EMetric.diam_triple, dist_edist] rw [ENNReal.toReal_max, ENNReal.toReal_max] <;> apply_rules [ne_of_lt, edist_lt_top, max_lt] /-- If the distance between any two points in a set is bounded by some constant `C`, then `ENNReal.ofReal C` bounds the emetric diameter of this set. -/ theorem ediam_le_of_forall_dist_le {C : ℝ} (h : βˆ€ x ∈ s, βˆ€ y ∈ s, dist x y ≀ C) : EMetric.diam s ≀ ENNReal.ofReal C := EMetric.diam_le fun x hx y hy => (edist_dist x y).symm β–Έ ENNReal.ofReal_le_ofReal (h x hx y hy) /-- If the distance between any two points in a set is bounded by some non-negative constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le {C : ℝ} (hβ‚€ : 0 ≀ C) (h : βˆ€ x ∈ s, βˆ€ y ∈ s, dist x y ≀ C) : diam s ≀ C := ENNReal.toReal_le_of_le_ofReal hβ‚€ (ediam_le_of_forall_dist_le h) /-- If the distance between any two points in a nonempty set is bounded by some constant, this constant bounds the diameter. -/ theorem diam_le_of_forall_dist_le_of_nonempty (hs : s.Nonempty) {C : ℝ} (h : βˆ€ x ∈ s, βˆ€ y ∈ s, dist x y ≀ C) : diam s ≀ C := have hβ‚€ : 0 ≀ C := let ⟨x, hx⟩ := hs le_trans dist_nonneg (h x hx x hx) diam_le_of_forall_dist_le hβ‚€ h /-- The distance between two points in a set is controlled by the diameter of the set. -/ theorem dist_le_diam_of_mem' (h : EMetric.diam s β‰  ⊀) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≀ diam s := by rw [diam, dist_edist] exact ENNReal.toReal_mono h <| EMetric.edist_le_diam_of_mem hx hy /-- Characterize the boundedness of a set in terms of the finiteness of its emetric.diameter. -/ theorem isBounded_iff_ediam_ne_top : IsBounded s ↔ EMetric.diam s β‰  ⊀ := isBounded_iff.trans <| Iff.intro (fun ⟨_C, hC⟩ => ne_top_of_le_ne_top ENNReal.ofReal_ne_top <| ediam_le_of_forall_dist_le hC) fun h => ⟨diam s, fun _x hx _y hy => dist_le_diam_of_mem' h hx hy⟩ alias ⟨_root_.Bornology.IsBounded.ediam_ne_top, _⟩ := isBounded_iff_ediam_ne_top theorem ediam_eq_top_iff_unbounded : EMetric.diam s = ⊀ ↔ Β¬IsBounded s := isBounded_iff_ediam_ne_top.not_left.symm theorem ediam_univ_eq_top_iff_noncompact [ProperSpace Ξ±] : EMetric.diam (univ : Set Ξ±) = ∞ ↔ NoncompactSpace Ξ± := by rw [← not_compactSpace_iff, compactSpace_iff_isBounded_univ, isBounded_iff_ediam_ne_top, Classical.not_not] @[simp] theorem ediam_univ_of_noncompact [ProperSpace Ξ±] [NoncompactSpace Ξ±] : EMetric.diam (univ : Set Ξ±) = ∞ := ediam_univ_eq_top_iff_noncompact.mpr β€Ή_β€Ί @[simp] theorem diam_univ_of_noncompact [ProperSpace Ξ±] [NoncompactSpace Ξ±] : diam (univ : Set Ξ±) = 0 := by simp [diam] /-- The distance between two points in a set is controlled by the diameter of the set. -/ theorem dist_le_diam_of_mem (h : IsBounded s) (hx : x ∈ s) (hy : y ∈ s) : dist x y ≀ diam s := dist_le_diam_of_mem' h.ediam_ne_top hx hy theorem ediam_of_unbounded (h : Β¬IsBounded s) : EMetric.diam s = ∞ := ediam_eq_top_iff_unbounded.2 h /-- An unbounded set has zero diameter. If you would prefer to get the value ∞, use `EMetric.diam`. This lemma makes it possible to avoid side conditions in some situations -/ theorem diam_eq_zero_of_unbounded (h : Β¬IsBounded s) : diam s = 0 := by rw [diam, ediam_of_unbounded h, ENNReal.toReal_top] /-- If `s βŠ† t`, then the diameter of `s` is bounded by that of `t`, provided `t` is bounded. -/ theorem diam_mono {s t : Set Ξ±} (h : s βŠ† t) (ht : IsBounded t) : diam s ≀ diam t := ENNReal.toReal_mono ht.ediam_ne_top <| EMetric.diam_mono h /-- The diameter of a union is controlled by the sum of the diameters, and the distance between any two points in each of the sets. This lemma is true without any side condition, since it is obviously true if `s βˆͺ t` is unbounded. -/ theorem diam_union {t : Set Ξ±} (xs : x ∈ s) (yt : y ∈ t) : diam (s βˆͺ t) ≀ diam s + dist x y + diam t := by simp only [diam, dist_edist] refine (ENNReal.toReal_le_add' (EMetric.diam_union xs yt) ?_ ?_).trans (add_le_add_right ENNReal.toReal_add_le _) Β· simp only [ENNReal.add_eq_top, edist_ne_top, or_false] exact fun h ↦ top_unique <| h β–Έ EMetric.diam_mono subset_union_left Β· exact fun h ↦ top_unique <| h β–Έ EMetric.diam_mono subset_union_right /-- If two sets intersect, the diameter of the union is bounded by the sum of the diameters. -/ theorem diam_union' {t : Set Ξ±} (h : (s ∩ t).Nonempty) : diam (s βˆͺ t) ≀ diam s + diam t := by rcases h with ⟨x, ⟨xs, xt⟩⟩ simpa using diam_union xs xt theorem diam_le_of_subset_closedBall {r : ℝ} (hr : 0 ≀ r) (h : s βŠ† closedBall x r) : diam s ≀ 2 * r := diam_le_of_forall_dist_le (mul_nonneg zero_le_two hr) fun a ha b hb => calc dist a b ≀ dist a x + dist b x := dist_triangle_right _ _ _ _ ≀ r + r := add_le_add (h ha) (h hb) _ = 2 * r := by simp [mul_two, mul_comm] /-- The diameter of a closed ball of radius `r` is at most `2 r`. -/ theorem diam_closedBall {r : ℝ} (h : 0 ≀ r) : diam (closedBall x r) ≀ 2 * r := diam_le_of_subset_closedBall h Subset.rfl /-- The diameter of a ball of radius `r` is at most `2 r`. -/ theorem diam_ball {r : ℝ} (h : 0 ≀ r) : diam (ball x r) ≀ 2 * r := diam_le_of_subset_closedBall h ball_subset_closedBall /-- If a family of complete sets with diameter tending to `0` is such that each finite intersection is nonempty, then the total intersection is also nonempty. -/ theorem _root_.IsComplete.nonempty_iInter_of_nonempty_biInter {s : β„• β†’ Set Ξ±} (h0 : IsComplete (s 0)) (hs : βˆ€ n, IsClosed (s n)) (h's : βˆ€ n, IsBounded (s n)) (h : βˆ€ N, (β‹‚ n ≀ N, s n).Nonempty) (h' : Tendsto (fun n => diam (s n)) atTop (𝓝 0)) : (β‹‚ n, s n).Nonempty := by let u N := (h N).some have I : βˆ€ n N, n ≀ N β†’ u N ∈ s n := by intro n N hn apply mem_of_subset_of_mem _ (h N).choose_spec intro x hx simp only [mem_iInter] at hx exact hx n hn have : CauchySeq u := by apply cauchySeq_of_le_tendsto_0 _ _ h' intro m n N hm hn exact dist_le_diam_of_mem (h's N) (I _ _ hm) (I _ _ hn) obtain ⟨x, -, xlim⟩ : βˆƒ x ∈ s 0, Tendsto (fun n : β„• => u n) atTop (𝓝 x) := cauchySeq_tendsto_of_isComplete h0 (fun n => I 0 n (zero_le _)) this refine ⟨x, mem_iInter.2 fun n => ?_⟩ apply (hs n).mem_of_tendsto xlim filter_upwards [Ici_mem_atTop n] with p hp exact I n p hp /-- In a complete space, if a family of closed sets with diameter tending to `0` is such that each finite intersection is nonempty, then the total intersection is also nonempty. -/ theorem nonempty_iInter_of_nonempty_biInter [CompleteSpace Ξ±] {s : β„• β†’ Set Ξ±} (hs : βˆ€ n, IsClosed (s n)) (h's : βˆ€ n, IsBounded (s n)) (h : βˆ€ N, (β‹‚ n ≀ N, s n).Nonempty) (h' : Tendsto (fun n => diam (s n)) atTop (𝓝 0)) : (β‹‚ n, s n).Nonempty := (hs 0).isComplete.nonempty_iInter_of_nonempty_biInter hs h's h h' end Diam end Metric namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: the diameter of a set is always nonnegative. -/ @[positivity Metric.diam _] def evalDiam : PositivityExt where eval {u Ξ±} _zΞ± _pΞ± e := do match u, Ξ±, e with | 0, ~q(ℝ), ~q(@Metric.diam _ $inst $s) => assertInstancesCommute pure (.nonnegative q(Metric.diam_nonneg)) | _, _, _ => throwError "not β€– Β· β€–" end Mathlib.Meta.Positivity open Metric
Mathlib/Topology/MetricSpace/Bounded.lean
531
537
theorem Metric.cobounded_eq_cocompact [ProperSpace Ξ±] : cobounded Ξ± = cocompact Ξ± := by
nontriviality Ξ±; inhabit Ξ± exact cobounded_le_cocompact.antisymm <| (hasBasis_cobounded_compl_closedBall default).ge_iff.2 fun _ _ ↦ (isCompact_closedBall _ _).compl_mem_cocompact theorem tendsto_dist_right_cocompact_atTop [ProperSpace Ξ±] (x : Ξ±) : Tendsto (dist Β· x) (cocompact Ξ±) atTop :=
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Algebra.CharP.Reduced import Mathlib.Algebra.Field.ZMod import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.ValMinAbs import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix import Mathlib.FieldTheory.Finiteness import Mathlib.FieldTheory.Perfect import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype KΛ£` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype KΛ£` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≀ natDegree p * #(univ.image fun x => eval x p) := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = #(p - C a).roots.toFinset := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≀ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≀ _ := card_roots_sub_C' hp) /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : βˆƒ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices Β¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_cancel]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * #((univ.image fun x : R => eval x f) βˆͺ univ.image fun x : R => eval x (-g))) <| calc 2 * #((univ.image fun x : R => eval x f) βˆͺ univ.image fun x : R => eval x (-g)) ≀ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * #(univ.image fun x : R => eval x f) + natDegree (-g) * #(univ.image fun x : R => eval x (-g)) := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (Β· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * #((univ.image fun x : R => eval x f) βˆͺ univ.image fun x : R => eval x (-g)) := by rw [card_union_of_disjoint hd] simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype KΛ£] : ∏ x : KΛ£, x = (-1 : KΛ£) := by classical have : (∏ x ∈ (@univ KΛ£ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp +contextual [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : KΛ£)), prod_insert (not_mem_erase _ _), this, mul_one] theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup KΛ£) [Fintype G] : (Fintype.card G : K) β‰  0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero β–Έ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : KΛ£) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup KΛ£} [Fintype G] (hg : G β‰  βŠ₯) : βˆ‘ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G β†ͺ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : KΛ£) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Ξ£ G, x = βˆ‘ G, a x = a βˆ‘ G, x simp only [h_unchanged, mulLeftEmbedding_apply, Subgroup.coe_mul, Units.val_mul, ← mul_sum, a_mul_emb] at h_sum_map -- thus one of (a - 1) or βˆ‘ G, x is zero have hzero : (((a : KΛ£) : K) - 1) = 0 ∨ βˆ‘ x : β†₯G, ((x : KΛ£) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup KΛ£} [Fintype G] [Decidable (G = βŠ₯)] : βˆ‘ x : G, (x.val : K) = if G = βŠ₯ then 1 else 0 := by by_cases G_bot : G = βŠ₯ Β· subst G_bot simp only [univ_unique, sum_singleton, ↓reduceIte, Units.val_eq_one, OneMemClass.coe_eq_one] rw [Set.default_coe_singleton] rfl Β· simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup KΛ£} [Fintype G] {k : β„•} (k_pos : k β‰  0) (k_lt_card_G : k < Fintype.card G) : βˆ‘ x : G, ((x : KΛ£) : K) ^ k = 0 := by rw [← Nat.card_eq_fintype_card] at k_lt_card_G nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : KΛ£) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : KΛ£) : K) ^ k * ((a : KΛ£) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : β†₯G => (((x : KΛ£) : K) * ((a : KΛ£) : K)) ^ k) = (fun x : β†₯G => ((x : KΛ£) : K) ^ k) ∘ fun x : β†₯G => x * a := by funext x simp only [Function.comp_apply, Subgroup.coe_mul, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : KΛ£) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : KΛ£) : K) ^ k * ((a : KΛ£) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : KΛ£) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K] theorem pow_card_sub_one_eq_one (a : K) (ha : a β‰  0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : KΛ£).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one] rfl
Mathlib/FieldTheory/Finite/Basic.lean
225
228
theorem pow_card (a : K) : a ^ q = a := by
by_cases h : a = 0; Β· rw [h]; apply zero_pow Fintype.card_ne_zero rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one, pow_card_sub_one_eq_one a h, one_mul]
/- 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, Floris van Doorn -/ import Mathlib.Analysis.Calculus.ContDiff.Operations import Mathlib.Data.Finset.Sym import Mathlib.Data.Nat.Choose.Cast import Mathlib.Data.Nat.Choose.Multinomial /-! # Bounds on higher derivatives `norm_iteratedFDeriv_comp_le` gives the bound `n! * C * D ^ n` for the `n`-th derivative of `g ∘ f` assuming that the derivatives of `g` are bounded by `C` and the `i`-th derivative of `f` is bounded by `D ^ i`. -/ noncomputable section open scoped NNReal Nat universe u uD uE uF uG open Set Fin Filter Function variable {π•œ : Type*} [NontriviallyNormedField π•œ] {D : Type uD} [NormedAddCommGroup D] [NormedSpace π•œ D] {E : Type uE} [NormedAddCommGroup E] [NormedSpace π•œ E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace π•œ F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace π•œ G] {s s₁ t u : Set E} /-!## Quantitative bounds -/ /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` within a set in terms of the iterated derivatives of `f` and `g` when `B` is bilinear. This lemma is an auxiliary version assuming all spaces live in the same universe, to enable an induction. Use instead `ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear` that removes this assumption. -/ theorem ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear_aux {Du Eu Fu Gu : Type u} [NormedAddCommGroup Du] [NormedSpace π•œ Du] [NormedAddCommGroup Eu] [NormedSpace π•œ Eu] [NormedAddCommGroup Fu] [NormedSpace π•œ Fu] [NormedAddCommGroup Gu] [NormedSpace π•œ Gu] (B : Eu β†’L[π•œ] Fu β†’L[π•œ] Gu) {f : Du β†’ Eu} {g : Du β†’ Fu} {n : β„•} {s : Set Du} {x : Du} (hf : ContDiffOn π•œ n f s) (hg : ContDiffOn π•œ n g s) (hs : UniqueDiffOn π•œ s) (hx : x ∈ s) : β€–iteratedFDerivWithin π•œ n (fun y => B (f y) (g y)) s xβ€– ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := by /- We argue by induction on `n`. The bound is trivial for `n = 0`. For `n + 1`, we write the `(n+1)`-th derivative as the `n`-th derivative of the derivative `B f g' + B f' g`, and apply the inductive assumption to each of those two terms. For this induction to make sense, the spaces of linear maps that appear in the induction should be in the same universe as the original spaces, which explains why we assume in the lemma that all spaces live in the same universe. -/ induction' n with n IH generalizing Eu Fu Gu Β· simp only [norm_iteratedFDerivWithin_zero, zero_add, Finset.range_one, Finset.sum_singleton, Nat.choose_self, Nat.cast_one, one_mul, Nat.sub_zero, ← mul_assoc] apply B.le_opNormβ‚‚ Β· have In : (n : WithTop β„•βˆž) + 1 ≀ n.succ := by simp only [Nat.cast_succ, le_refl] -- Porting note: the next line is a hack allowing Lean to find the operator norm instance. let norm := @ContinuousLinearMap.hasOpNorm _ _ Eu ((Du β†’L[π•œ] Fu) β†’L[π•œ] Du β†’L[π•œ] Gu) _ _ _ _ _ _ (RingHom.id π•œ) have I1 : β€–iteratedFDerivWithin π•œ n (fun y : Du => B.precompR Du (f y) (fderivWithin π•œ g s y)) s xβ€– ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), n.choose i * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n + 1 - i) g s xβ€– := by calc β€–iteratedFDerivWithin π•œ n (fun y : Du => B.precompR Du (f y) (fderivWithin π•œ g s y)) s xβ€– ≀ β€–B.precompR Duβ€– * βˆ‘ i ∈ Finset.range (n + 1), n.choose i * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) (fderivWithin π•œ g s) s xβ€– := IH _ (hf.of_le (Nat.cast_le.2 (Nat.le_succ n))) (hg.fderivWithin hs In) _ ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), n.choose i * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) (fderivWithin π•œ g s) s xβ€– := mul_le_mul_of_nonneg_right (B.norm_precompR_le Du) (by positivity) _ = _ := by congr 1 apply Finset.sum_congr rfl fun i hi => ?_ rw [Nat.succ_sub (Nat.lt_succ_iff.1 (Finset.mem_range.1 hi)), ← norm_iteratedFDerivWithin_fderivWithin hs hx] -- Porting note: the next line is a hack allowing Lean to find the operator norm instance. let norm := @ContinuousLinearMap.hasOpNorm _ _ (Du β†’L[π•œ] Eu) (Fu β†’L[π•œ] Du β†’L[π•œ] Gu) _ _ _ _ _ _ (RingHom.id π•œ) have I2 : β€–iteratedFDerivWithin π•œ n (fun y : Du => B.precompL Du (fderivWithin π•œ f s y) (g y)) s xβ€– ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), n.choose i * β€–iteratedFDerivWithin π•œ (i + 1) f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := calc β€–iteratedFDerivWithin π•œ n (fun y : Du => B.precompL Du (fderivWithin π•œ f s y) (g y)) s xβ€– ≀ β€–B.precompL Duβ€– * βˆ‘ i ∈ Finset.range (n + 1), n.choose i * β€–iteratedFDerivWithin π•œ i (fderivWithin π•œ f s) s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := IH _ (hf.fderivWithin hs In) (hg.of_le (Nat.cast_le.2 (Nat.le_succ n))) _ ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), n.choose i * β€–iteratedFDerivWithin π•œ i (fderivWithin π•œ f s) s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := mul_le_mul_of_nonneg_right (B.norm_precompL_le Du) (by positivity) _ = _ := by congr 1 apply Finset.sum_congr rfl fun i _ => ?_ rw [← norm_iteratedFDerivWithin_fderivWithin hs hx] have J : iteratedFDerivWithin π•œ n (fun y : Du => fderivWithin π•œ (fun y : Du => B (f y) (g y)) s y) s x = iteratedFDerivWithin π•œ n (fun y => B.precompR Du (f y) (fderivWithin π•œ g s y) + B.precompL Du (fderivWithin π•œ f s y) (g y)) s x := by apply iteratedFDerivWithin_congr (fun y hy => ?_) hx have L : (1 : WithTop β„•βˆž) ≀ n.succ := by simpa only [ENat.coe_one, Nat.one_le_cast] using Nat.succ_pos n exact B.fderivWithin_of_bilinear (hf.differentiableOn L y hy) (hg.differentiableOn L y hy) (hs y hy) rw [← norm_iteratedFDerivWithin_fderivWithin hs hx, J] have A : ContDiffOn π•œ n (fun y => B.precompR Du (f y) (fderivWithin π•œ g s y)) s := (B.precompR Du).isBoundedBilinearMap.contDiff.compβ‚‚_contDiffOn (hf.of_le (Nat.cast_le.2 (Nat.le_succ n))) (hg.fderivWithin hs In) have A' : ContDiffOn π•œ n (fun y => B.precompL Du (fderivWithin π•œ f s y) (g y)) s := (B.precompL Du).isBoundedBilinearMap.contDiff.compβ‚‚_contDiffOn (hf.fderivWithin hs In) (hg.of_le (Nat.cast_le.2 (Nat.le_succ n))) rw [iteratedFDerivWithin_add_apply' (A.contDiffWithinAt hx) (A'.contDiffWithinAt hx) hs hx] apply (norm_add_le _ _).trans ((add_le_add I1 I2).trans (le_of_eq ?_)) simp_rw [← mul_add, mul_assoc] congr 1 exact (Finset.sum_choose_succ_mul (fun i j => β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ j g s xβ€–) n).symm /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` within a set in terms of the iterated derivatives of `f` and `g` when `B` is bilinear: `β€–D^n (x ↦ B (f x) (g x))β€– ≀ β€–Bβ€– βˆ‘_{k ≀ n} n.choose k β€–D^k fβ€– β€–D^{n-k} gβ€–` -/ theorem ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear (B : E β†’L[π•œ] F β†’L[π•œ] G) {f : D β†’ E} {g : D β†’ F} {N : WithTop β„•βˆž} {s : Set D} {x : D} (hf : ContDiffOn π•œ N f s) (hg : ContDiffOn π•œ N g s) (hs : UniqueDiffOn π•œ s) (hx : x ∈ s) {n : β„•} (hn : n ≀ N) : β€–iteratedFDerivWithin π•œ n (fun y => B (f y) (g y)) s xβ€– ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := by /- We reduce the bound to the case where all spaces live in the same universe (in which we already have proved the result), by using linear isometries between the spaces and their `ULift` to a common universe. These linear isometries preserve the norm of the iterated derivative. -/ let Du : Type max uD uE uF uG := ULift.{max uE uF uG, uD} D let Eu : Type max uD uE uF uG := ULift.{max uD uF uG, uE} E let Fu : Type max uD uE uF uG := ULift.{max uD uE uG, uF} F let Gu : Type max uD uE uF uG := ULift.{max uD uE uF, uG} G have isoD : Du ≃ₗᡒ[π•œ] D := LinearIsometryEquiv.ulift π•œ D have isoE : Eu ≃ₗᡒ[π•œ] E := LinearIsometryEquiv.ulift π•œ E have isoF : Fu ≃ₗᡒ[π•œ] F := LinearIsometryEquiv.ulift π•œ F have isoG : Gu ≃ₗᡒ[π•œ] G := LinearIsometryEquiv.ulift π•œ G -- lift `f` and `g` to versions `fu` and `gu` on the lifted spaces. let fu : Du β†’ Eu := isoE.symm ∘ f ∘ isoD let gu : Du β†’ Fu := isoF.symm ∘ g ∘ isoD -- lift the bilinear map `B` to a bilinear map `Bu` on the lifted spaces. let Buβ‚€ : Eu β†’L[π•œ] Fu β†’L[π•œ] G := ((B.comp (isoE : Eu β†’L[π•œ] E)).flip.comp (isoF : Fu β†’L[π•œ] F)).flip let Bu : Eu β†’L[π•œ] Fu β†’L[π•œ] Gu := ContinuousLinearMap.compL π•œ Eu (Fu β†’L[π•œ] G) (Fu β†’L[π•œ] Gu) (ContinuousLinearMap.compL π•œ Fu G Gu (isoG.symm : G β†’L[π•œ] Gu)) Buβ‚€ have hBu : Bu = ContinuousLinearMap.compL π•œ Eu (Fu β†’L[π•œ] G) (Fu β†’L[π•œ] Gu) (ContinuousLinearMap.compL π•œ Fu G Gu (isoG.symm : G β†’L[π•œ] Gu)) Buβ‚€ := rfl have Bu_eq : (fun y => Bu (fu y) (gu y)) = isoG.symm ∘ (fun y => B (f y) (g y)) ∘ isoD := by ext1 y simp [Du, Eu, Fu, Gu, hBu, Buβ‚€, fu, gu] -- All norms are preserved by the lifting process. have Bu_le : β€–Buβ€– ≀ β€–Bβ€– := by refine ContinuousLinearMap.opNorm_le_bound _ (norm_nonneg B) fun y => ?_ refine ContinuousLinearMap.opNorm_le_bound _ (by positivity) fun x => ?_ simp only [Du, Eu, Fu, Gu, hBu, Buβ‚€, compL_apply, coe_comp', Function.comp_apply, ContinuousLinearEquiv.coe_coe, LinearIsometryEquiv.coe_coe, flip_apply, LinearIsometryEquiv.norm_map] calc β€–B (isoE y) (isoF x)β€– ≀ β€–B (isoE y)β€– * β€–isoF xβ€– := ContinuousLinearMap.le_opNorm _ _ _ ≀ β€–Bβ€– * β€–isoE yβ€– * β€–isoF xβ€– := by gcongr; apply ContinuousLinearMap.le_opNorm _ = β€–Bβ€– * β€–yβ€– * β€–xβ€– := by simp only [LinearIsometryEquiv.norm_map] let su := isoD ⁻¹' s have hsu : UniqueDiffOn π•œ su := isoD.toContinuousLinearEquiv.uniqueDiffOn_preimage_iff.2 hs let xu := isoD.symm x have hxu : xu ∈ su := by simpa only [xu, su, Set.mem_preimage, LinearIsometryEquiv.apply_symm_apply] using hx have xu_x : isoD xu = x := by simp only [xu, LinearIsometryEquiv.apply_symm_apply] have hfu : ContDiffOn π•œ n fu su := isoE.symm.contDiff.comp_contDiffOn ((hf.of_le hn).comp_continuousLinearMap (isoD : Du β†’L[π•œ] D)) have hgu : ContDiffOn π•œ n gu su := isoF.symm.contDiff.comp_contDiffOn ((hg.of_le hn).comp_continuousLinearMap (isoD : Du β†’L[π•œ] D)) have Nfu : βˆ€ i, β€–iteratedFDerivWithin π•œ i fu su xuβ€– = β€–iteratedFDerivWithin π•œ i f s xβ€– := by intro i rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hsu hxu] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ hs, xu_x] rwa [← xu_x] at hx have Ngu : βˆ€ i, β€–iteratedFDerivWithin π•œ i gu su xuβ€– = β€–iteratedFDerivWithin π•œ i g s xβ€– := by intro i rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hsu hxu] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ hs, xu_x] rwa [← xu_x] at hx have NBu : β€–iteratedFDerivWithin π•œ n (fun y => Bu (fu y) (gu y)) su xuβ€– = β€–iteratedFDerivWithin π•œ n (fun y => B (f y) (g y)) s xβ€– := by rw [Bu_eq] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hsu hxu] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ hs, xu_x] rwa [← xu_x] at hx -- state the bound for the lifted objects, and deduce the original bound from it. have : β€–iteratedFDerivWithin π•œ n (fun y => Bu (fu y) (gu y)) su xuβ€– ≀ β€–Buβ€– * βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i fu su xuβ€– * β€–iteratedFDerivWithin π•œ (n - i) gu su xuβ€– := Bu.norm_iteratedFDerivWithin_le_of_bilinear_aux hfu hgu hsu hxu simp only [Nfu, Ngu, NBu] at this exact this.trans (mul_le_mul_of_nonneg_right Bu_le (by positivity)) /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` in terms of the iterated derivatives of `f` and `g` when `B` is bilinear: `β€–D^n (x ↦ B (f x) (g x))β€– ≀ β€–Bβ€– βˆ‘_{k ≀ n} n.choose k β€–D^k fβ€– β€–D^{n-k} gβ€–` -/ theorem ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear (B : E β†’L[π•œ] F β†’L[π•œ] G) {f : D β†’ E} {g : D β†’ F} {N : WithTop β„•βˆž} (hf : ContDiff π•œ N f) (hg : ContDiff π•œ N g) (x : D) {n : β„•} (hn : n ≀ N) : β€–iteratedFDeriv π•œ n (fun y => B (f y) (g y)) xβ€– ≀ β€–Bβ€– * βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDeriv π•œ i f xβ€– * β€–iteratedFDeriv π•œ (n - i) g xβ€– := by simp_rw [← iteratedFDerivWithin_univ] exact B.norm_iteratedFDerivWithin_le_of_bilinear hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (mem_univ x) hn /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` within a set in terms of the iterated derivatives of `f` and `g` when `B` is bilinear of norm at most `1`: `β€–D^n (x ↦ B (f x) (g x))β€– ≀ βˆ‘_{k ≀ n} n.choose k β€–D^k fβ€– β€–D^{n-k} gβ€–` -/ theorem ContinuousLinearMap.norm_iteratedFDerivWithin_le_of_bilinear_of_le_one (B : E β†’L[π•œ] F β†’L[π•œ] G) {f : D β†’ E} {g : D β†’ F} {N : WithTop β„•βˆž} {s : Set D} {x : D} (hf : ContDiffOn π•œ N f s) (hg : ContDiffOn π•œ N g s) (hs : UniqueDiffOn π•œ s) (hx : x ∈ s) {n : β„•} (hn : n ≀ N) (hB : β€–Bβ€– ≀ 1) : β€–iteratedFDerivWithin π•œ n (fun y => B (f y) (g y)) s xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := by apply (B.norm_iteratedFDerivWithin_le_of_bilinear hf hg hs hx hn).trans exact mul_le_of_le_one_left (by positivity) hB /-- Bounding the norm of the iterated derivative of `B (f x) (g x)` in terms of the iterated derivatives of `f` and `g` when `B` is bilinear of norm at most `1`: `β€–D^n (x ↦ B (f x) (g x))β€– ≀ βˆ‘_{k ≀ n} n.choose k β€–D^k fβ€– β€–D^{n-k} gβ€–` -/ theorem ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear_of_le_one (B : E β†’L[π•œ] F β†’L[π•œ] G) {f : D β†’ E} {g : D β†’ F} {N : WithTop β„•βˆž} (hf : ContDiff π•œ N f) (hg : ContDiff π•œ N g) (x : D) {n : β„•} (hn : n ≀ N) (hB : β€–Bβ€– ≀ 1) : β€–iteratedFDeriv π•œ n (fun y => B (f y) (g y)) xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDeriv π•œ i f xβ€– * β€–iteratedFDeriv π•œ (n - i) g xβ€– := by simp_rw [← iteratedFDerivWithin_univ] exact B.norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (mem_univ x) hn hB section variable {π•œ' : Type*} [NormedField π•œ'] [NormedAlgebra π•œ π•œ'] [NormedSpace π•œ' F] [IsScalarTower π•œ π•œ' F] theorem norm_iteratedFDerivWithin_smul_le {f : E β†’ π•œ'} {g : E β†’ F} {N : WithTop β„•βˆž} (hf : ContDiffOn π•œ N f s) (hg : ContDiffOn π•œ N g s) (hs : UniqueDiffOn π•œ s) {x : E} (hx : x ∈ s) {n : β„•} (hn : n ≀ N) : β€–iteratedFDerivWithin π•œ n (fun y => f y β€’ g y) s xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := (ContinuousLinearMap.lsmul π•œ π•œ' : π•œ' β†’L[π•œ] F β†’L[π•œ] F).norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf hg hs hx hn ContinuousLinearMap.opNorm_lsmul_le theorem norm_iteratedFDeriv_smul_le {f : E β†’ π•œ'} {g : E β†’ F} {N : WithTop β„•βˆž} (hf : ContDiff π•œ N f) (hg : ContDiff π•œ N g) (x : E) {n : β„•} (hn : n ≀ N) : β€–iteratedFDeriv π•œ n (fun y => f y β€’ g y) xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDeriv π•œ i f xβ€– * β€–iteratedFDeriv π•œ (n - i) g xβ€– := (ContinuousLinearMap.lsmul π•œ π•œ' : π•œ' β†’L[π•œ] F β†’L[π•œ] F).norm_iteratedFDeriv_le_of_bilinear_of_le_one hf hg x hn ContinuousLinearMap.opNorm_lsmul_le end section variable {ΞΉ : Type*} {A : Type*} [NormedRing A] [NormedAlgebra π•œ A] {A' : Type*} [NormedCommRing A'] [NormedAlgebra π•œ A'] theorem norm_iteratedFDerivWithin_mul_le {f : E β†’ A} {g : E β†’ A} {N : WithTop β„•βˆž} (hf : ContDiffOn π•œ N f s) (hg : ContDiffOn π•œ N g s) (hs : UniqueDiffOn π•œ s) {x : E} (hx : x ∈ s) {n : β„•} (hn : n ≀ N) : β€–iteratedFDerivWithin π•œ n (fun y => f y * g y) s xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := (ContinuousLinearMap.mul π•œ A : A β†’L[π•œ] A β†’L[π•œ] A).norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf hg hs hx hn (ContinuousLinearMap.opNorm_mul_le _ _) theorem norm_iteratedFDeriv_mul_le {f : E β†’ A} {g : E β†’ A} {N : WithTop β„•βˆž} (hf : ContDiff π•œ N f) (hg : ContDiff π•œ N g) (x : E) {n : β„•} (hn : n ≀ N) : β€–iteratedFDeriv π•œ n (fun y => f y * g y) xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDeriv π•œ i f xβ€– * β€–iteratedFDeriv π•œ (n - i) g xβ€– := by simp_rw [← iteratedFDerivWithin_univ] exact norm_iteratedFDerivWithin_mul_le hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (mem_univ x) hn -- TODO: Add `norm_iteratedFDeriv[Within]_list_prod_le` for non-commutative `NormedRing A`. theorem norm_iteratedFDerivWithin_prod_le [DecidableEq ΞΉ] [NormOneClass A'] {u : Finset ΞΉ} {f : ΞΉ β†’ E β†’ A'} {N : WithTop β„•βˆž} (hf : βˆ€ i ∈ u, ContDiffOn π•œ N (f i) s) (hs : UniqueDiffOn π•œ s) {x : E} (hx : x ∈ s) {n : β„•} (hn : n ≀ N) : β€–iteratedFDerivWithin π•œ n (∏ j ∈ u, f j Β·) s xβ€– ≀ βˆ‘ p ∈ u.sym n, (p : Multiset ΞΉ).multinomial * ∏ j ∈ u, β€–iteratedFDerivWithin π•œ (Multiset.count j p) (f j) s xβ€– := by induction u using Finset.induction generalizing n with | empty => cases n with | zero => simp [Sym.eq_nil_of_card_zero] | succ n => simp [iteratedFDerivWithin_succ_const] | insert i u hi IH => conv => lhs; simp only [Finset.prod_insert hi] simp only [Finset.mem_insert, forall_eq_or_imp] at hf refine le_trans (norm_iteratedFDerivWithin_mul_le hf.1 (contDiffOn_prod hf.2) hs hx hn) ?_ rw [← Finset.sum_coe_sort (Finset.sym _ _)] rw [Finset.sum_equiv (Finset.symInsertEquiv hi) (t := Finset.univ) (g := (fun v ↦ v.multinomial * ∏ j ∈ insert i u, β€–iteratedFDerivWithin π•œ (v.count j) (f j) s xβ€–) ∘ Sym.toMultiset ∘ Subtype.val ∘ (Finset.symInsertEquiv hi).symm) (by simp) (by simp only [← comp_apply (g := Finset.symInsertEquiv hi), comp_assoc]; simp)] rw [← Finset.univ_sigma_univ, Finset.sum_sigma, Finset.sum_range] simp only [comp_apply, Finset.symInsertEquiv_symm_apply_coe] refine Finset.sum_le_sum ?_ intro m _ specialize IH hf.2 (n := n - m) (le_trans (by exact_mod_cast n.sub_le m) hn) refine le_trans (mul_le_mul_of_nonneg_left IH (by simp [mul_nonneg])) ?_ rw [Finset.mul_sum, ← Finset.sum_coe_sort] refine Finset.sum_le_sum ?_ simp only [Finset.mem_univ, forall_true_left, Subtype.forall, Finset.mem_sym_iff] intro p hp refine le_of_eq ?_ rw [Finset.prod_insert hi] have hip : i βˆ‰ p := mt (hp i) hi rw [Sym.count_coe_fill_self_of_not_mem hip, Sym.multinomial_coe_fill_of_not_mem hip] suffices ∏ j ∈ u, β€–iteratedFDerivWithin π•œ (Multiset.count j p) (f j) s xβ€– = ∏ j ∈ u, β€–iteratedFDerivWithin π•œ (Multiset.count j (Sym.fill i m p)) (f j) s xβ€– by rw [this, Nat.cast_mul] ring refine Finset.prod_congr rfl ?_ intro j hj have hji : j β‰  i := mt (Β· β–Έ hj) hi rw [Sym.count_coe_fill_of_ne hji] theorem norm_iteratedFDeriv_prod_le [DecidableEq ΞΉ] [NormOneClass A'] {u : Finset ΞΉ} {f : ΞΉ β†’ E β†’ A'} {N : WithTop β„•βˆž} (hf : βˆ€ i ∈ u, ContDiff π•œ N (f i)) {x : E} {n : β„•} (hn : n ≀ N) : β€–iteratedFDeriv π•œ n (∏ j ∈ u, f j Β·) xβ€– ≀ βˆ‘ p ∈ u.sym n, (p : Multiset ΞΉ).multinomial * ∏ j ∈ u, β€–iteratedFDeriv π•œ ((p : Multiset ΞΉ).count j) (f j) xβ€– := by simpa [iteratedFDerivWithin_univ] using norm_iteratedFDerivWithin_prod_le (fun i hi ↦ (hf i hi).contDiffOn) uniqueDiffOn_univ (mem_univ x) hn end /-- If the derivatives within a set of `g` at `f x` are bounded by `C`, and the `i`-th derivative within a set of `f` at `x` is bounded by `D^i` for all `1 ≀ i ≀ n`, then the `n`-th derivative of `g ∘ f` is bounded by `n! * C * D^n`. This lemma proves this estimate assuming additionally that two of the spaces live in the same universe, to make an induction possible. Use instead `norm_iteratedFDerivWithin_comp_le` that removes this assumption. -/ theorem norm_iteratedFDerivWithin_comp_le_aux {Fu Gu : Type u} [NormedAddCommGroup Fu] [NormedSpace π•œ Fu] [NormedAddCommGroup Gu] [NormedSpace π•œ Gu] {g : Fu β†’ Gu} {f : E β†’ Fu} {n : β„•} {s : Set E} {t : Set Fu} {x : E} (hg : ContDiffOn π•œ n g t) (hf : ContDiffOn π•œ n f s) (ht : UniqueDiffOn π•œ t) (hs : UniqueDiffOn π•œ s) (hst : MapsTo f s t) (hx : x ∈ s) {C : ℝ} {D : ℝ} (hC : βˆ€ i, i ≀ n β†’ β€–iteratedFDerivWithin π•œ i g t (f x)β€– ≀ C) (hD : βˆ€ i, 1 ≀ i β†’ i ≀ n β†’ β€–iteratedFDerivWithin π•œ i f s xβ€– ≀ D ^ i) : β€–iteratedFDerivWithin π•œ n (g ∘ f) s xβ€– ≀ n ! * C * D ^ n := by /- We argue by induction on `n`, using that `D^(n+1) (g ∘ f) = D^n (g ' ∘ f ⬝ f')`. The successive derivatives of `g' ∘ f` are controlled thanks to the inductive assumption, and those of `f'` are controlled by assumption. As composition of linear maps is a bilinear map, one may use `ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear_of_le_one` to get from these a bound on `D^n (g ' ∘ f ⬝ f')`. -/ induction' n using Nat.case_strong_induction_on with n IH generalizing Gu Β· simpa [norm_iteratedFDerivWithin_zero, Nat.factorial_zero, algebraMap.coe_one, one_mul, pow_zero, mul_one, comp_apply] using hC 0 le_rfl have M : (n : WithTop β„•βˆž) < n.succ := Nat.cast_lt.2 n.lt_succ_self have Cnonneg : 0 ≀ C := (norm_nonneg _).trans (hC 0 bot_le) have Dnonneg : 0 ≀ D := by have : 1 ≀ n + 1 := by simp only [le_add_iff_nonneg_left, zero_le'] simpa only [pow_one] using (norm_nonneg _).trans (hD 1 le_rfl this) -- use the inductive assumption to bound the derivatives of `g' ∘ f`. have I : βˆ€ i ∈ Finset.range (n + 1), β€–iteratedFDerivWithin π•œ i (fderivWithin π•œ g t ∘ f) s xβ€– ≀ i ! * C * D ^ i := by intro i hi simp only [Finset.mem_range_succ_iff] at hi apply IH i hi Β· apply hg.fderivWithin ht simp only [Nat.cast_succ] exact add_le_add_right (Nat.cast_le.2 hi) _ Β· apply hf.of_le (Nat.cast_le.2 (hi.trans n.le_succ)) Β· intro j hj have : β€–iteratedFDerivWithin π•œ j (fderivWithin π•œ g t) t (f x)β€– = β€–iteratedFDerivWithin π•œ (j + 1) g t (f x)β€– := by rw [iteratedFDerivWithin_succ_eq_comp_right ht (hst hx), comp_apply, LinearIsometryEquiv.norm_map] rw [this] exact hC (j + 1) (add_le_add (hj.trans hi) le_rfl) Β· intro j hj h'j exact hD j hj (h'j.trans (hi.trans n.le_succ)) -- reformulate `hD` as a bound for the derivatives of `f'`. have J : βˆ€ i, β€–iteratedFDerivWithin π•œ (n - i) (fderivWithin π•œ f s) s xβ€– ≀ D ^ (n - i + 1) := by intro i have : β€–iteratedFDerivWithin π•œ (n - i) (fderivWithin π•œ f s) s xβ€– = β€–iteratedFDerivWithin π•œ (n - i + 1) f s xβ€– := by rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] rw [this] apply hD Β· simp only [le_add_iff_nonneg_left, zero_le'] Β· apply Nat.succ_le_succ tsub_le_self -- Now put these together: first, notice that we have to bound `D^n (g' ∘ f ⬝ f')`. calc β€–iteratedFDerivWithin π•œ (n + 1) (g ∘ f) s xβ€– = β€–iteratedFDerivWithin π•œ n (fun y : E => fderivWithin π•œ (g ∘ f) s y) s xβ€– := by rw [iteratedFDerivWithin_succ_eq_comp_right hs hx, comp_apply, LinearIsometryEquiv.norm_map] _ = β€–iteratedFDerivWithin π•œ n (fun y : E => ContinuousLinearMap.compL π•œ E Fu Gu (fderivWithin π•œ g t (f y)) (fderivWithin π•œ f s y)) s xβ€– := by have L : (1 : WithTop β„•βˆž) ≀ n.succ := by simpa only [ENat.coe_one, Nat.one_le_cast] using n.succ_pos congr 1 refine iteratedFDerivWithin_congr (fun y hy => ?_) hx _ apply fderivWithin_comp _ _ _ hst (hs y hy) Β· exact hg.differentiableOn L _ (hst hy) Β· exact hf.differentiableOn L _ hy -- bound it using the fact that the composition of linear maps is a bilinear operation, -- for which we have bounds for the`n`-th derivative. _ ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * β€–iteratedFDerivWithin π•œ i (fderivWithin π•œ g t ∘ f) s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) (fderivWithin π•œ f s) s xβ€– := by have A : ContDiffOn π•œ n (fderivWithin π•œ g t ∘ f) s := by apply ContDiffOn.comp _ (hf.of_le M.le) hst apply hg.fderivWithin ht simp only [Nat.cast_succ, le_refl] have B : ContDiffOn π•œ n (fderivWithin π•œ f s) s := by apply hf.fderivWithin hs simp only [Nat.cast_succ, le_refl] exact (ContinuousLinearMap.compL π•œ E Fu Gu).norm_iteratedFDerivWithin_le_of_bilinear_of_le_one A B hs hx le_rfl (ContinuousLinearMap.norm_compL_le π•œ E Fu Gu) -- bound each of the terms using the estimates on previous derivatives (that use the inductive -- assumption for `g' ∘ f`). _ ≀ βˆ‘ i ∈ Finset.range (n + 1), (n.choose i : ℝ) * (i ! * C * D ^ i) * D ^ (n - i + 1) := by gcongr with i hi Β· exact I i hi Β· exact J i -- We are left with trivial algebraic manipulations to see that this is smaller than -- the claimed bound. _ = βˆ‘ i ∈ Finset.range (n + 1), (n ! : ℝ) * ((i ! : ℝ)⁻¹ * i !) * C * (D ^ i * D ^ (n - i + 1)) * ((n - i)! : ℝ)⁻¹ := by congr! 1 with i hi simp only [Nat.cast_choose ℝ (Finset.mem_range_succ_iff.1 hi), div_eq_inv_mul, mul_inv] ring _ = βˆ‘ i ∈ Finset.range (n + 1), (n ! : ℝ) * 1 * C * D ^ (n + 1) * ((n - i)! : ℝ)⁻¹ := by congr! with i hi Β· apply inv_mul_cancelβ‚€ simpa only [Ne, Nat.cast_eq_zero] using i.factorial_ne_zero Β· rw [← pow_add] congr 1 rw [Nat.add_succ, Nat.succ_inj] exact Nat.add_sub_of_le (Finset.mem_range_succ_iff.1 hi) _ ≀ βˆ‘ i ∈ Finset.range (n + 1), (n ! : ℝ) * 1 * C * D ^ (n + 1) * 1 := by gcongr with i apply inv_le_one_of_one_leβ‚€ simpa only [Nat.one_le_cast] using (n - i).factorial_pos _ = (n + 1)! * C * D ^ (n + 1) := by simp only [mul_assoc, mul_one, Finset.sum_const, Finset.card_range, nsmul_eq_mul, Nat.factorial_succ, Nat.cast_mul] /-- If the derivatives within a set of `g` at `f x` are bounded by `C`, and the `i`-th derivative within a set of `f` at `x` is bounded by `D^i` for all `1 ≀ i ≀ n`, then the `n`-th derivative of `g ∘ f` is bounded by `n! * C * D^n`. -/ theorem norm_iteratedFDerivWithin_comp_le {g : F β†’ G} {f : E β†’ F} {n : β„•} {s : Set E} {t : Set F} {x : E} {N : WithTop β„•βˆž} (hg : ContDiffOn π•œ N g t) (hf : ContDiffOn π•œ N f s) (hn : n ≀ N) (ht : UniqueDiffOn π•œ t) (hs : UniqueDiffOn π•œ s) (hst : MapsTo f s t) (hx : x ∈ s) {C : ℝ} {D : ℝ} (hC : βˆ€ i, i ≀ n β†’ β€–iteratedFDerivWithin π•œ i g t (f x)β€– ≀ C) (hD : βˆ€ i, 1 ≀ i β†’ i ≀ n β†’ β€–iteratedFDerivWithin π•œ i f s xβ€– ≀ D ^ i) : β€–iteratedFDerivWithin π•œ n (g ∘ f) s xβ€– ≀ n ! * C * D ^ n := by /- We reduce the bound to the case where all spaces live in the same universe (in which we already have proved the result), by using linear isometries between the spaces and their `ULift` to a common universe. These linear isometries preserve the norm of the iterated derivative. -/ let Fu : Type max uF uG := ULift.{uG, uF} F let Gu : Type max uF uG := ULift.{uF, uG} G have isoF : Fu ≃ₗᡒ[π•œ] F := LinearIsometryEquiv.ulift π•œ F have isoG : Gu ≃ₗᡒ[π•œ] G := LinearIsometryEquiv.ulift π•œ G -- lift `f` and `g` to versions `fu` and `gu` on the lifted spaces. let fu : E β†’ Fu := isoF.symm ∘ f let gu : Fu β†’ Gu := isoG.symm ∘ g ∘ isoF let tu := isoF ⁻¹' t have htu : UniqueDiffOn π•œ tu := isoF.toContinuousLinearEquiv.uniqueDiffOn_preimage_iff.2 ht have hstu : MapsTo fu s tu := fun y hy ↦ by simpa only [fu, tu, mem_preimage, comp_apply, LinearIsometryEquiv.apply_symm_apply] using hst hy have Ffu : isoF (fu x) = f x := by simp only [fu, comp_apply, LinearIsometryEquiv.apply_symm_apply] -- All norms are preserved by the lifting process. have hfu : ContDiffOn π•œ n fu s := isoF.symm.contDiff.comp_contDiffOn (hf.of_le hn) have hgu : ContDiffOn π•œ n gu tu := isoG.symm.contDiff.comp_contDiffOn ((hg.of_le hn).comp_continuousLinearMap (isoF : Fu β†’L[π•œ] F)) have Nfu : βˆ€ i, β€–iteratedFDerivWithin π•œ i fu s xβ€– = β€–iteratedFDerivWithin π•œ i f s xβ€– := fun i ↦ by rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hs hx] simp_rw [← Nfu] at hD have Ngu : βˆ€ i, β€–iteratedFDerivWithin π•œ i gu tu (fu x)β€– = β€–iteratedFDerivWithin π•œ i g t (f x)β€– := fun i ↦ by rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ htu (hstu hx)] rw [LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_right _ _ ht, Ffu] rw [Ffu] exact hst hx simp_rw [← Ngu] at hC have Nfgu : β€–iteratedFDerivWithin π•œ n (g ∘ f) s xβ€– = β€–iteratedFDerivWithin π•œ n (gu ∘ fu) s xβ€– := by have : gu ∘ fu = isoG.symm ∘ g ∘ f := by ext x simp only [fu, gu, comp_apply, LinearIsometryEquiv.map_eq_iff, LinearIsometryEquiv.apply_symm_apply] rw [this, LinearIsometryEquiv.norm_iteratedFDerivWithin_comp_left _ _ hs hx] -- deduce the required bound from the one for `gu ∘ fu`. rw [Nfgu] exact norm_iteratedFDerivWithin_comp_le_aux hgu hfu htu hs hstu hx hC hD /-- If the derivatives of `g` at `f x` are bounded by `C`, and the `i`-th derivative of `f` at `x` is bounded by `D^i` for all `1 ≀ i ≀ n`, then the `n`-th derivative of `g ∘ f` is bounded by `n! * C * D^n`. -/ theorem norm_iteratedFDeriv_comp_le {g : F β†’ G} {f : E β†’ F} {n : β„•} {N : WithTop β„•βˆž} (hg : ContDiff π•œ N g) (hf : ContDiff π•œ N f) (hn : n ≀ N) (x : E) {C : ℝ} {D : ℝ} (hC : βˆ€ i, i ≀ n β†’ β€–iteratedFDeriv π•œ i g (f x)β€– ≀ C) (hD : βˆ€ i, 1 ≀ i β†’ i ≀ n β†’ β€–iteratedFDeriv π•œ i f xβ€– ≀ D ^ i) : β€–iteratedFDeriv π•œ n (g ∘ f) xβ€– ≀ n ! * C * D ^ n := by simp_rw [← iteratedFDerivWithin_univ] at hC hD ⊒ exact norm_iteratedFDerivWithin_comp_le hg.contDiffOn hf.contDiffOn hn uniqueDiffOn_univ uniqueDiffOn_univ (mapsTo_univ _ _) (mem_univ x) hC hD section Apply theorem norm_iteratedFDerivWithin_clm_apply {f : E β†’ F β†’L[π•œ] G} {g : E β†’ F} {s : Set E} {x : E} {N : WithTop β„•βˆž} {n : β„•} (hf : ContDiffOn π•œ N f s) (hg : ContDiffOn π•œ N g s) (hs : UniqueDiffOn π•œ s) (hx : x ∈ s) (hn : n ≀ N) : β€–iteratedFDerivWithin π•œ n (fun y => (f y) (g y)) s xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), ↑(n.choose i) * β€–iteratedFDerivWithin π•œ i f s xβ€– * β€–iteratedFDerivWithin π•œ (n - i) g s xβ€– := by let B : (F β†’L[π•œ] G) β†’L[π•œ] F β†’L[π•œ] G := ContinuousLinearMap.flip (ContinuousLinearMap.apply π•œ G) have hB : β€–Bβ€– ≀ 1 := by simp only [B, ContinuousLinearMap.opNorm_flip, ContinuousLinearMap.apply] refine ContinuousLinearMap.opNorm_le_bound _ zero_le_one fun f => ?_ simp only [ContinuousLinearMap.coe_id', id, one_mul] rfl exact B.norm_iteratedFDerivWithin_le_of_bilinear_of_le_one hf hg hs hx hn hB
Mathlib/Analysis/Calculus/ContDiff/Bounds.lean
537
548
theorem norm_iteratedFDeriv_clm_apply {f : E β†’ F β†’L[π•œ] G} {g : E β†’ F} {N : WithTop β„•βˆž} {n : β„•} (hf : ContDiff π•œ N f) (hg : ContDiff π•œ N g) (x : E) (hn : n ≀ N) : β€–iteratedFDeriv π•œ n (fun y : E => (f y) (g y)) xβ€– ≀ βˆ‘ i ∈ Finset.range (n + 1), ↑(n.choose i) * β€–iteratedFDeriv π•œ i f xβ€– * β€–iteratedFDeriv π•œ (n - i) g xβ€– := by
simp only [← iteratedFDerivWithin_univ] exact norm_iteratedFDerivWithin_clm_apply hf.contDiffOn hg.contDiffOn uniqueDiffOn_univ (Set.mem_univ x) hn theorem norm_iteratedFDerivWithin_clm_apply_const {f : E β†’ F β†’L[π•œ] G} {c : F} {s : Set E} {x : E} {N : WithTop β„•βˆž} {n : β„•} (hf : ContDiffWithinAt π•œ N f s x) (hs : UniqueDiffOn π•œ s) (hx : x ∈ s) (hn : n ≀ N) : β€–iteratedFDerivWithin π•œ n (fun y : E => (f y) c) s xβ€– ≀
/- 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.Data.NNReal.Basic import Mathlib.Topology.Algebra.Support import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.Order.Real /-! # 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. ## 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 β†’ ℝ /-- 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 /-- Auxiliary class, endowing a type `Ξ±` with a function `enorm : Ξ± β†’ ℝβ‰₯0∞` with notation `β€–xβ€–β‚‘`. -/ @[notation_class] class ENorm (E : Type*) where /-- the `ℝβ‰₯0∞`-valued norm function. -/ enorm : E β†’ ℝβ‰₯0∞ export Norm (norm) export NNNorm (nnnorm) export ENorm (enorm) @[inherit_doc] notation "β€–" e "β€–" => norm e @[inherit_doc] notation "β€–" e "β€–β‚Š" => nnnorm e @[inherit_doc] notation "β€–" e "β€–β‚‘" => enorm e section ENorm variable {E : Type*} [NNNorm E] {x : E} {r : ℝβ‰₯0} instance NNNorm.toENorm : ENorm E where enorm := (β€–Β·β€–β‚Š : E β†’ ℝβ‰₯0∞) lemma enorm_eq_nnnorm (x : E) : β€–xβ€–β‚‘ = β€–xβ€–β‚Š := rfl @[simp] lemma toNNReal_enorm (x : E) : β€–xβ€–β‚‘.toNNReal = β€–xβ€–β‚Š := rfl @[simp, norm_cast] lemma coe_le_enorm : r ≀ β€–xβ€–β‚‘ ↔ r ≀ β€–xβ€–β‚Š := by simp [enorm] @[simp, norm_cast] lemma enorm_le_coe : β€–xβ€–β‚‘ ≀ r ↔ β€–xβ€–β‚Š ≀ r := by simp [enorm] @[simp, norm_cast] lemma coe_lt_enorm : r < β€–xβ€–β‚‘ ↔ r < β€–xβ€–β‚Š := by simp [enorm] @[simp, norm_cast] lemma enorm_lt_coe : β€–xβ€–β‚‘ < r ↔ β€–xβ€–β‚Š < r := by simp [enorm] @[simp] lemma enorm_ne_top : β€–xβ€–β‚‘ β‰  ∞ := by simp [enorm] @[simp] lemma enorm_lt_top : β€–xβ€–β‚‘ < ∞ := by simp [enorm] end ENorm /-- A type `E` equipped with a continuous map `β€–Β·β€–β‚‘ : E β†’ ℝβ‰₯0∞` NB. We do not demand that the topology is somehow defined by the enorm: for ℝβ‰₯0∞ (the motivating example behind this definition), this is not true. -/ class ContinuousENorm (E : Type*) [TopologicalSpace E] extends ENorm E where continuous_enorm : Continuous enorm /-- An enormed monoid is an additive monoid endowed with a continuous enorm. -/ class ENormedAddMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, AddMonoid E where enorm_eq_zero : βˆ€ x : E, β€–xβ€–β‚‘ = 0 ↔ x = 0 protected enorm_add_le : βˆ€ x y : E, β€–x + yβ€–β‚‘ ≀ β€–xβ€–β‚‘ + β€–yβ€–β‚‘ /-- An enormed monoid is a monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, Monoid E where enorm_eq_zero : βˆ€ x : E, β€–xβ€–β‚‘ = 0 ↔ x = 1 enorm_mul_le : βˆ€ x y : E, β€–x * yβ€–β‚‘ ≀ β€–xβ€–β‚‘ + β€–yβ€–β‚‘ /-- An enormed commutative monoid is an additive commutative monoid endowed with a continuous enorm. We don't have `ENormedAddCommMonoid` extend `EMetricSpace`, since the canonical instance `ℝβ‰₯0∞` is not an `EMetricSpace`. This is because `ℝβ‰₯0∞` carries the order topology, which is distinct from the topology coming from `edist`. -/ class ENormedAddCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedAddMonoid E, AddCommMonoid E where /-- An enormed commutative monoid is a commutative monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedMonoid E, CommMonoid E where /-- 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 /-- 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 /-- 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 /-- 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 /-- 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 /-- 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 /-- 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 /-- 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 -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { β€ΉNormedGroup Eβ€Ί with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { β€ΉNormedCommGroup Eβ€Ί with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { β€ΉSeminormedCommGroup Eβ€Ί with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { β€ΉNormedCommGroup Eβ€Ί with } -- 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 "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."] abbrev 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 _ <| (β€ΉSeminormedGroup Eβ€Ί.dist_eq _ _).symm.trans hxy } -- 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 "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."] abbrev NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : βˆ€ x : E, β€–xβ€– = 0 β†’ x = 1) : NormedCommGroup E := { β€ΉSeminormedCommGroup Eβ€Ί, NormedGroup.ofSeparation h with } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive "Construct a seminormed group from a translation-invariant distance."] abbrev 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_inv_cancel y] using hβ‚‚ _ _ _ Β· simpa only [div_mul_cancel, one_mul] using hβ‚‚ (x / y) 1 y -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev 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_inv_cancel y] using hβ‚‚ _ _ _ -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev 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 } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev 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 } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive "Construct a normed group from a translation-invariant distance."] abbrev 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 } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev 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 } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev 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 } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev 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 } -- 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 "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`)."] abbrev GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq _ _ := 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 -- 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 "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`)."] abbrev GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } -- 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 "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`)."] abbrev 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 } -- 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 "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`)."] abbrev GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ aβ‚‚ b c : E} {r r₁ rβ‚‚ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = β€–a / bβ€– := SeminormedGroup.dist_eq _ _ @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = β€–b / aβ€– := by rw [dist_comm, dist_eq_norm_div] alias dist_eq_norm := dist_eq_norm_sub alias dist_eq_norm' := dist_eq_norm_sub' @[to_additive of_forall_le_norm] lemma DiscreteTopology.of_forall_le_norm' (hpos : 0 < r) (hr : βˆ€ x : E, x β‰  1 β†’ r ≀ β€–xβ€–) : DiscreteTopology E := .of_forall_le_dist hpos fun x y hne ↦ by simp only [dist_eq_norm_div] exact hr _ (div_ne_one.2 hne) @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = β€–aβ€– := by rw [dist_eq_norm_div, div_one] @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ β€–aβ€– = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive] lemma dist_one_left (a : E) : dist 1 a = β€–aβ€– := by rw [dist_comm, dist_one_right] @[to_additive (attr := simp)] lemma dist_one : dist (1 : E) = norm := funext dist_one_left @[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 @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : β€–a⁻¹‖ = β€–aβ€– := by simpa using norm_div_rev 1 a @[to_additive (attr := simp) norm_abs_zsmul] theorem norm_zpow_abs (a : E) (n : β„€) : β€–a ^ |n|β€– = β€–a ^ nβ€– := by rcases le_total 0 n with hn | hn <;> simp [hn, abs_of_nonneg, abs_of_nonpos] @[to_additive (attr := simp) norm_natAbs_smul] theorem norm_pow_natAbs (a : E) (n : β„€) : β€–a ^ n.natAbsβ€– = β€–a ^ nβ€– := by rw [← zpow_natCast, ← Int.abs_eq_natAbs, norm_zpow_abs] @[to_additive norm_isUnit_zsmul] theorem norm_zpow_isUnit (a : E) {n : β„€} (hn : IsUnit n) : β€–a ^ nβ€– = β€–aβ€– := by rw [← norm_pow_natAbs, Int.isUnit_iff_natAbs_eq.mp hn, pow_one] @[simp] theorem norm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : β„€Λ£) (a : E) : β€–n β€’ aβ€– = β€–aβ€– := norm_isUnit_zsmul a n.isUnit 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'] /-- **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⁻¹ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le_of_le "**Triangle inequality** for the norm."] 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β‚‚ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add₃_le "**Triangle inequality** for the norm."] lemma norm_mul₃_le' : β€–a * b * cβ€– ≀ β€–aβ€– + β€–bβ€– + β€–cβ€– := norm_mul_le_of_le' (norm_mul_le' _ _) le_rfl @[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 attribute [bound] norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |β€–zβ€–| = β€–zβ€– := abs_of_nonneg <| norm_nonneg' _ @[to_additive (attr := simp) norm_zero] theorem norm_one' : β€–(1 : E)β€– = 0 := by rw [← dist_one_right, dist_self] @[to_additive] theorem ne_one_of_norm_ne_zero : β€–aβ€– β‰  0 β†’ a β‰  1 := mt <| by rintro rfl exact norm_one' @[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'] @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + β€–xβ€– ^ 2 := by positivity @[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 attribute [bound] 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β‚‚ @[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 @[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 @[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) @[to_additive (attr := bound)] theorem norm_sub_le_norm_mul (a b : E) : β€–aβ€– - β€–bβ€– ≀ β€–a * bβ€– := by simpa using norm_mul_le' (a * b) (b⁻¹) @[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 @[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] @[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 alias norm_le_insert' := norm_le_norm_add_norm_sub' alias norm_le_insert := norm_le_norm_add_norm_sub @[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 _ _ /-- An analogue of `norm_le_mul_norm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `norm_le_add_norm_add` for the addition from the left."] theorem norm_le_mul_norm_add' (u v : E) : β€–vβ€– ≀ β€–u * vβ€– + β€–uβ€– := calc β€–vβ€– = β€–u⁻¹ * (u * v)β€– := by rw [← mul_assoc, inv_mul_cancel, one_mul] _ ≀ β€–u⁻¹‖ + β€–u * vβ€– := norm_mul_le' u⁻¹ (u * v) _ = β€–u * vβ€– + β€–uβ€– := by rw [norm_inv', add_comm] @[to_additive] lemma norm_mul_eq_norm_right {x : E} (y : E) (h : β€–xβ€– = 0) : β€–x * yβ€– = β€–yβ€– := by apply le_antisymm ?_ ?_ Β· simpa [h] using norm_mul_le' x y Β· simpa [h] using norm_le_mul_norm_add' x y @[to_additive] lemma norm_mul_eq_norm_left (x : E) {y : E} (h : β€–yβ€– = 0) : β€–x * yβ€– = β€–xβ€– := by apply le_antisymm ?_ ?_ Β· simpa [h] using norm_mul_le' x y Β· simpa [h] using norm_le_mul_norm_add x y @[to_additive] lemma norm_div_eq_norm_right {x : E} (y : E) (h : β€–xβ€– = 0) : β€–x / yβ€– = β€–yβ€– := by apply le_antisymm ?_ ?_ Β· simpa [h] using norm_div_le x y Β· simpa [h, norm_div_rev x y] using norm_sub_norm_le' y x @[to_additive] lemma norm_div_eq_norm_left (x : E) {y : E} (h : β€–yβ€– = 0) : β€–x / yβ€– = β€–xβ€– := by apply le_antisymm ?_ ?_ Β· simpa [h] using norm_div_le x y Β· simpa [h] using norm_sub_norm_le' x y @[to_additive ball_eq] theorem ball_eq' (y : E) (Ξ΅ : ℝ) : ball y Ξ΅ = { x | β€–x / yβ€– < Ξ΅ } := Set.ext fun a => by simp [dist_eq_norm_div] @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | β€–xβ€– < r } := Set.ext fun a => by simp @[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] @[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] @[to_additive] theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ β€–aβ€– < r := by rw [mem_ball, dist_one_right] @[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] @[to_additive] theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ β€–aβ€– ≀ r := by rw [mem_closedBall, dist_one_right] @[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] @[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]) _ @[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' @[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]) _ @[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) @[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] @[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] @[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 @[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] @[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 _ 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'⟩ @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl 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] @[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] @[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 @[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 @[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] open Finset variable [FunLike 𝓕 E F] section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => βŸ¨β€–aβ€–, norm_nonneg' a⟩⟩ @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (β€–aβ€–β‚Š : ℝ) = β€–aβ€– := rfl @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝβ‰₯0 β†’ ℝ) ∘ (nnnorm : E β†’ ℝβ‰₯0) = norm := rfl @[to_additive (attr := simp) norm_toNNReal] theorem norm_toNNReal' : β€–aβ€–.toNNReal = β€–aβ€–β‚Š := @Real.toNNReal_coe β€–aβ€–β‚Š @[to_additive (attr := simp) toReal_enorm] lemma toReal_enorm' (x : E) : β€–xβ€–β‚‘.toReal = β€–xβ€– := by simp [enorm] @[to_additive (attr := simp) ofReal_norm] lemma ofReal_norm' (x : E) : .ofReal β€–xβ€– = β€–xβ€–β‚‘ := by simp [enorm, ENNReal.ofReal, Real.toNNReal, nnnorm] @[to_additive enorm_eq_iff_norm_eq] theorem enorm'_eq_iff_norm_eq {x : E} {y : F} : β€–xβ€–β‚‘ = β€–yβ€–β‚‘ ↔ β€–xβ€– = β€–yβ€– := by simp only [← ofReal_norm'] refine ⟨fun h ↦ ?_, fun h ↦ by congr⟩ exact (Real.toNNReal_eq_toNNReal_iff (norm_nonneg' _) (norm_nonneg' _)).mp (ENNReal.coe_inj.mp h) @[to_additive enorm_le_iff_norm_le]
Mathlib/Analysis/Normed/Group/Basic.lean
714
716
theorem enorm'_le_iff_norm_le {x : E} {y : F} : β€–xβ€–β‚‘ ≀ β€–yβ€–β‚‘ ↔ β€–xβ€– ≀ β€–yβ€– := by
simp only [← ofReal_norm'] refine ⟨fun h ↦ ?_, fun h ↦ by gcongr⟩
/- Copyright (c) 2021 YaΓ«l Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: YaΓ«l Dillies, Violeta HernΓ‘ndez Palacios, Grayson Burton, Floris van Doorn -/ import Mathlib.Order.Antisymmetrization import Mathlib.Order.Hom.WithTopBot import Mathlib.Order.Interval.Set.OrdConnected import Mathlib.Order.Interval.Set.WithBotTop /-! # The covering relation This file proves properties of the covering relation in an order. We say that `b` *covers* `a` if `a < b` and there is no element in between. We say that `b` *weakly covers* `a` if `a ≀ b` and there is no element between `a` and `b`. In a partial order this is equivalent to `a β‹– b ∨ a = b`, in a preorder this is equivalent to `a β‹– b ∨ (a ≀ b ∧ b ≀ a)` ## Notation * `a β‹– b` means that `b` covers `a`. * `a β©Ώ b` means that `b` weakly covers `a`. -/ open Set OrderDual variable {Ξ± Ξ² : Type*} section WeaklyCovers section Preorder variable [Preorder Ξ±] [Preorder Ξ²] {a b c : Ξ±} theorem WCovBy.le (h : a β©Ώ b) : a ≀ b := h.1 theorem WCovBy.refl (a : Ξ±) : a β©Ώ a := ⟨le_rfl, fun _ hc => hc.not_lt⟩ @[simp] lemma WCovBy.rfl : a β©Ώ a := WCovBy.refl a protected theorem Eq.wcovBy (h : a = b) : a β©Ώ b := h β–Έ WCovBy.rfl theorem wcovBy_of_le_of_le (h1 : a ≀ b) (h2 : b ≀ a) : a β©Ώ b := ⟨h1, fun _ hac hcb => (hac.trans hcb).not_le h2⟩ alias LE.le.wcovBy_of_le := wcovBy_of_le_of_le theorem AntisymmRel.wcovBy (h : AntisymmRel (Β· ≀ Β·) a b) : a β©Ώ b := wcovBy_of_le_of_le h.1 h.2 theorem WCovBy.wcovBy_iff_le (hab : a β©Ώ b) : b β©Ώ a ↔ b ≀ a := ⟨fun h => h.le, fun h => h.wcovBy_of_le hab.le⟩ theorem wcovBy_of_eq_or_eq (hab : a ≀ b) (h : βˆ€ c, a ≀ c β†’ c ≀ b β†’ c = a ∨ c = b) : a β©Ώ b := ⟨hab, fun c ha hb => (h c ha.le hb.le).elim ha.ne' hb.ne⟩ theorem AntisymmRel.trans_wcovBy (hab : AntisymmRel (Β· ≀ Β·) a b) (hbc : b β©Ώ c) : a β©Ώ c := ⟨hab.1.trans hbc.le, fun _ had hdc => hbc.2 (hab.2.trans_lt had) hdc⟩ theorem wcovBy_congr_left (hab : AntisymmRel (Β· ≀ Β·) a b) : a β©Ώ c ↔ b β©Ώ c := ⟨hab.symm.trans_wcovBy, hab.trans_wcovBy⟩ theorem WCovBy.trans_antisymm_rel (hab : a β©Ώ b) (hbc : AntisymmRel (Β· ≀ Β·) b c) : a β©Ώ c := ⟨hab.le.trans hbc.1, fun _ had hdc => hab.2 had <| hdc.trans_le hbc.2⟩ theorem wcovBy_congr_right (hab : AntisymmRel (Β· ≀ Β·) a b) : c β©Ώ a ↔ c β©Ώ b := ⟨fun h => h.trans_antisymm_rel hab, fun h => h.trans_antisymm_rel hab.symm⟩ /-- If `a ≀ b`, then `b` does not cover `a` iff there's an element in between. -/ theorem not_wcovBy_iff (h : a ≀ b) : Β¬a β©Ώ b ↔ βˆƒ c, a < c ∧ c < b := by simp_rw [WCovBy, h, true_and, not_forall, exists_prop, not_not] instance WCovBy.isRefl : IsRefl Ξ± (Β· β©Ώ Β·) := ⟨WCovBy.refl⟩ theorem WCovBy.Ioo_eq (h : a β©Ώ b) : Ioo a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ hx => h.2 hx.1 hx.2 theorem wcovBy_iff_Ioo_eq : a β©Ώ b ↔ a ≀ b ∧ Ioo a b = βˆ… := and_congr_right' <| by simp [eq_empty_iff_forall_not_mem] lemma WCovBy.of_le_of_le (hac : a β©Ώ c) (hab : a ≀ b) (hbc : b ≀ c) : b β©Ώ c := ⟨hbc, fun _x hbx hxc ↦ hac.2 (hab.trans_lt hbx) hxc⟩ lemma WCovBy.of_le_of_le' (hac : a β©Ώ c) (hab : a ≀ b) (hbc : b ≀ c) : a β©Ώ b := ⟨hab, fun _x hax hxb ↦ hac.2 hax <| hxb.trans_le hbc⟩ theorem WCovBy.of_image (f : Ξ± β†ͺo Ξ²) (h : f a β©Ώ f b) : a β©Ώ b := ⟨f.le_iff_le.mp h.le, fun _ hac hcb => h.2 (f.lt_iff_lt.mpr hac) (f.lt_iff_lt.mpr hcb)⟩ theorem WCovBy.image (f : Ξ± β†ͺo Ξ²) (hab : a β©Ώ b) (h : (range f).OrdConnected) : f a β©Ώ f b := by refine ⟨f.monotone hab.le, fun c ha hb => ?_⟩ obtain ⟨c, rfl⟩ := h.out (mem_range_self _) (mem_range_self _) ⟨ha.le, hb.le⟩ rw [f.lt_iff_lt] at ha hb exact hab.2 ha hb theorem Set.OrdConnected.apply_wcovBy_apply_iff (f : Ξ± β†ͺo Ξ²) (h : (range f).OrdConnected) : f a β©Ώ f b ↔ a β©Ώ b := ⟨fun h2 => h2.of_image f, fun hab => hab.image f h⟩ @[simp] theorem apply_wcovBy_apply_iff {E : Type*} [EquivLike E Ξ± Ξ²] [OrderIsoClass E Ξ± Ξ²] (e : E) : e a β©Ώ e b ↔ a β©Ώ b := (ordConnected_range (e : Ξ± ≃o Ξ²)).apply_wcovBy_apply_iff ((e : Ξ± ≃o Ξ²) : Ξ± β†ͺo Ξ²) @[simp] theorem toDual_wcovBy_toDual_iff : toDual b β©Ώ toDual a ↔ a β©Ώ b := and_congr_right' <| forall_congr' fun _ => forall_swap @[simp] theorem ofDual_wcovBy_ofDual_iff {a b : Ξ±α΅’α΅ˆ} : ofDual a β©Ώ ofDual b ↔ b β©Ώ a := and_congr_right' <| forall_congr' fun _ => forall_swap alias ⟨_, WCovBy.toDual⟩ := toDual_wcovBy_toDual_iff alias ⟨_, WCovBy.ofDual⟩ := ofDual_wcovBy_ofDual_iff theorem OrderEmbedding.wcovBy_of_apply {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] (f : Ξ± β†ͺo Ξ²) {x y : Ξ±} (h : f x β©Ώ f y) : x β©Ώ y := by use f.le_iff_le.1 h.1 intro a rw [← f.lt_iff_lt, ← f.lt_iff_lt] apply h.2 theorem OrderIso.map_wcovBy {Ξ± Ξ² : Type*} [Preorder Ξ±] [Preorder Ξ²] (f : Ξ± ≃o Ξ²) {x y : Ξ±} : f x β©Ώ f y ↔ x β©Ώ y := by use f.toOrderEmbedding.wcovBy_of_apply conv_lhs => rw [← f.symm_apply_apply x, ← f.symm_apply_apply y] exact f.symm.toOrderEmbedding.wcovBy_of_apply end Preorder section PartialOrder variable [PartialOrder Ξ±] {a b c : Ξ±} theorem WCovBy.eq_or_eq (h : a β©Ώ b) (h2 : a ≀ c) (h3 : c ≀ b) : c = a ∨ c = b := by rcases h2.eq_or_lt with (h2 | h2); Β· exact Or.inl h2.symm rcases h3.eq_or_lt with (h3 | h3); Β· exact Or.inr h3 exact (h.2 h2 h3).elim /-- An `iff` version of `WCovBy.eq_or_eq` and `wcovBy_of_eq_or_eq`. -/ theorem wcovBy_iff_le_and_eq_or_eq : a β©Ώ b ↔ a ≀ b ∧ βˆ€ c, a ≀ c β†’ c ≀ b β†’ c = a ∨ c = b := ⟨fun h => ⟨h.le, fun _ => h.eq_or_eq⟩, And.rec wcovBy_of_eq_or_eq⟩ theorem WCovBy.le_and_le_iff (h : a β©Ώ b) : a ≀ c ∧ c ≀ b ↔ c = a ∨ c = b := by refine ⟨fun h2 => h.eq_or_eq h2.1 h2.2, ?_⟩; rintro (rfl | rfl) exacts [⟨le_rfl, h.le⟩, ⟨h.le, le_rfl⟩] theorem WCovBy.Icc_eq (h : a β©Ώ b) : Icc a b = {a, b} := by ext c exact h.le_and_le_iff theorem WCovBy.Ico_subset (h : a β©Ώ b) : Ico a b βŠ† {a} := by rw [← Icc_diff_right, h.Icc_eq, diff_singleton_subset_iff, pair_comm]
Mathlib/Order/Cover.lean
162
165
theorem WCovBy.Ioc_subset (h : a β©Ώ b) : Ioc a b βŠ† {b} := by
rw [← Icc_diff_left, h.Icc_eq, diff_singleton_subset_iff] end PartialOrder
/- Copyright (c) 2022 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.CategoryTheory.Comma.Over.Pullback import Mathlib.CategoryTheory.Limits.Shapes.KernelPair import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq import Mathlib.CategoryTheory.Limits.Shapes.Pullback.Assoc /-! # The diagonal object of a morphism. We provide various API and isomorphisms considering the diagonal object `Ξ”_{Y/X} := pullback f f` of a morphism `f : X ⟢ Y`. -/ open CategoryTheory noncomputable section namespace CategoryTheory.Limits variable {C : Type*} [Category C] {X Y Z : C} namespace pullback section Diagonal variable (f : X ⟢ Y) [HasPullback f f] /-- The diagonal object of a morphism `f : X ⟢ Y` is `Ξ”_{X/Y} := pullback f f`. -/ abbrev diagonalObj : C := pullback f f /-- The diagonal morphism `X ⟢ Ξ”_{X/Y}` for a morphism `f : X ⟢ Y`. -/ def diagonal : X ⟢ diagonalObj f := pullback.lift (πŸ™ _) (πŸ™ _) rfl @[reassoc (attr := simp)] theorem diagonal_fst : diagonal f ≫ pullback.fst _ _ = πŸ™ _ := pullback.lift_fst _ _ _ @[reassoc (attr := simp)] theorem diagonal_snd : diagonal f ≫ pullback.snd _ _ = πŸ™ _ := pullback.lift_snd _ _ _ instance : IsSplitMono (diagonal f) := ⟨⟨⟨pullback.fst _ _, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.fst f f) := ⟨⟨⟨diagonal f, diagonal_fst f⟩⟩⟩ instance : IsSplitEpi (pullback.snd f f) := ⟨⟨⟨diagonal f, diagonal_snd f⟩⟩⟩ instance [Mono f] : IsIso (diagonal f) := by rw [(IsIso.inv_eq_of_inv_hom_id (diagonal_fst f)).symm] infer_instance lemma isIso_diagonal_iff : IsIso (diagonal f) ↔ Mono f := ⟨fun H ↦ ⟨fun _ _ e ↦ by rw [← lift_fst _ _ e, (cancel_epi (g := fst f f) (h := snd f f) (diagonal f)).mp (by simp), lift_snd]⟩, fun _ ↦ inferInstance⟩ /-- The two projections `Ξ”_{X/Y} ⟢ X` form a kernel pair for `f : X ⟢ Y`. -/ theorem diagonal_isKernelPair : IsKernelPair f (pullback.fst f f) (pullback.snd f f) := IsPullback.of_hasPullback f f end Diagonal end pullback variable [HasPullbacks C] open pullback section variable {U V₁ Vβ‚‚ : C} (f : X ⟢ Y) (i : U ⟢ Y) variable (i₁ : V₁ ⟢ pullback f i) (iβ‚‚ : Vβ‚‚ ⟢ pullback f i) @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_fst_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (iβ‚‚ ≫ snd f i) f f (i₁ ≫ fst f i) (iβ‚‚ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ fst _ _ ≫ i₁ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_fst f, pullback.condition_assoc, pullback.lift_fst] @[reassoc (attr := simp)] theorem pullback_diagonal_map_snd_snd_fst : (pullback.snd (diagonal f) (map (i₁ ≫ snd f i) (iβ‚‚ ≫ snd f i) f f (i₁ ≫ fst f i) (iβ‚‚ ≫ fst f i) i (by simp [condition]) (by simp [condition]))) ≫ snd _ _ ≫ iβ‚‚ ≫ fst _ _ = pullback.fst _ _ := by conv_rhs => rw [← Category.comp_id (pullback.fst _ _)] rw [← diagonal_snd f, pullback.condition_assoc, pullback.lift_snd] variable [HasPullback i₁ iβ‚‚] /-- The underlying map of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.hom : pullback (diagonal f) (map (i₁ ≫ snd _ _) (iβ‚‚ ≫ snd _ _) f f (i₁ ≫ fst _ _) (iβ‚‚ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) ⟢ pullback i₁ iβ‚‚ := pullback.lift (pullback.snd _ _ ≫ pullback.fst _ _) (pullback.snd _ _ ≫ pullback.snd _ _) (by ext Β· simp only [Category.assoc, pullback_diagonal_map_snd_fst_fst, pullback_diagonal_map_snd_snd_fst] Β· simp only [Category.assoc, condition]) /-- The underlying inverse of `pullbackDiagonalIso` -/ abbrev pullbackDiagonalMapIso.inv : pullback i₁ iβ‚‚ ⟢ pullback (diagonal f) (map (i₁ ≫ snd _ _) (iβ‚‚ ≫ snd _ _) f f (i₁ ≫ fst _ _) (iβ‚‚ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) := pullback.lift (pullback.fst _ _ ≫ i₁ ≫ pullback.fst _ _) (pullback.map _ _ _ _ (πŸ™ _) (πŸ™ _) (pullback.snd _ _) (Category.id_comp _).symm (Category.id_comp _).symm) (by ext Β· simp only [Category.assoc, diagonal_fst, Category.comp_id, limit.lift_Ο€, PullbackCone.mk_pt, PullbackCone.mk_Ο€_app, limit.lift_Ο€_assoc, cospan_left] Β· simp only [condition_assoc, Category.assoc, diagonal_snd, Category.comp_id, limit.lift_Ο€, PullbackCone.mk_pt, PullbackCone.mk_Ο€_app, limit.lift_Ο€_assoc, cospan_right]) /-- This iso witnesses the fact that given `f : X ⟢ Y`, `i : U ⟢ Y`, and `i₁ : V₁ ⟢ X Γ—[Y] U`, `iβ‚‚ : Vβ‚‚ ⟢ X Γ—[Y] U`, the diagram ``` V₁ Γ—[X Γ—[Y] U] Vβ‚‚ ⟢ V₁ Γ—[U] Vβ‚‚ | | | | ↓ ↓ X ⟢ X Γ—[Y] X ``` is a pullback square. Also see `pullback_fst_map_snd_isPullback`. -/ def pullbackDiagonalMapIso : pullback (diagonal f) (map (i₁ ≫ snd _ _) (iβ‚‚ ≫ snd _ _) f f (i₁ ≫ fst _ _) (iβ‚‚ ≫ fst _ _) i (by simp only [Category.assoc, condition]) (by simp only [Category.assoc, condition])) β‰… pullback i₁ iβ‚‚ where hom := pullbackDiagonalMapIso.hom f i i₁ iβ‚‚ inv := pullbackDiagonalMapIso.inv f i i₁ iβ‚‚ @[reassoc (attr := simp)] theorem pullbackDiagonalMapIso.hom_fst : (pullbackDiagonalMapIso f i i₁ iβ‚‚).hom ≫ pullback.fst _ _ = pullback.snd _ _ ≫ pullback.fst _ _ := by delta pullbackDiagonalMapIso simp only [limit.lift_Ο€, PullbackCone.mk_pt, PullbackCone.mk_Ο€_app] @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Limits/Shapes/Diagonal.lean
165
168
theorem pullbackDiagonalMapIso.hom_snd : (pullbackDiagonalMapIso f i i₁ iβ‚‚).hom ≫ pullback.snd _ _ = pullback.snd _ _ ≫ pullback.snd _ _ := by
delta pullbackDiagonalMapIso
/- 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.MeasureTheory.Integral.Bochner.ContinuousLinearMap /-! # Integral average of a function In this file we define `MeasureTheory.average ΞΌ f` (notation: `⨍ x, f x βˆ‚ΞΌ`) to be the average value of `f` with respect to measure `ΞΌ`. It is defined as `∫ x, f x βˆ‚((ΞΌ univ)⁻¹ β€’ ΞΌ)`, so it is equal to zero if `f` is not integrable or if `ΞΌ` is an infinite measure. If `ΞΌ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, we use `⨍ x in s, f x βˆ‚ΞΌ` (notation for `⨍ x, f x βˆ‚(ΞΌ.restrict s)`). For average w.r.t. the volume, one can omit `βˆ‚volume`. Both have a version for the Lebesgue integral rather than Bochner. We prove several version of the first moment method: An integrable function is below/above its average on a set of positive measure: * `measure_le_setLAverage_pos` for the Lebesgue integral * `measure_le_setAverage_pos` for the Bochner integral ## Implementation notes The average is defined as an integral over `(ΞΌ univ)⁻¹ β€’ ΞΌ` so that all theorems about Bochner integrals work for the average without modifications. For theorems that require integrability of a function, we provide a convenience lemma `MeasureTheory.Integrable.to_average`. ## Tags integral, center mass, average value -/ open ENNReal MeasureTheory MeasureTheory.Measure Metric Set Filter TopologicalSpace Function open scoped Topology ENNReal Convex variable {Ξ± E F : Type*} {m0 : MeasurableSpace Ξ±} [NormedAddCommGroup E] [NormedSpace ℝ E] [NormedAddCommGroup F] [NormedSpace ℝ F] [CompleteSpace F] {ΞΌ Ξ½ : Measure Ξ±} {s t : Set Ξ±} /-! ### Average value of a function w.r.t. a measure The (Bochner, Lebesgue) average value of a function `f` w.r.t. a measure `ΞΌ` (notation: `⨍ x, f x βˆ‚ΞΌ`, `⨍⁻ x, f x βˆ‚ΞΌ`) is defined as the (Bochner, Lebesgue) integral divided by the total measure, so it is equal to zero if `ΞΌ` is an infinite measure, and (typically) equal to infinity if `f` is not integrable. If `ΞΌ` is a probability measure, then the average of any function is equal to its integral. -/ namespace MeasureTheory section ENNReal variable (ΞΌ) {f g : Ξ± β†’ ℝβ‰₯0∞} /-- Average value of an `ℝβ‰₯0∞`-valued function `f` w.r.t. a measure `ΞΌ`, denoted `⨍⁻ x, f x βˆ‚ΞΌ`. It is equal to `(ΞΌ univ)⁻¹ * ∫⁻ x, f x βˆ‚ΞΌ`, so it takes value zero if `ΞΌ` is an infinite measure. If `ΞΌ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x βˆ‚ΞΌ`, defined as `⨍⁻ x, f x βˆ‚(ΞΌ.restrict s)`. For the average w.r.t. the volume, one can omit `βˆ‚volume`. -/ noncomputable def laverage (f : Ξ± β†’ ℝβ‰₯0∞) := ∫⁻ x, f x βˆ‚(ΞΌ univ)⁻¹ β€’ ΞΌ /-- Average value of an `ℝβ‰₯0∞`-valued function `f` w.r.t. a measure `ΞΌ`. It is equal to `(ΞΌ univ)⁻¹ * ∫⁻ x, f x βˆ‚ΞΌ`, so it takes value zero if `ΞΌ` is an infinite measure. If `ΞΌ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x βˆ‚ΞΌ`, defined as `⨍⁻ x, f x βˆ‚(ΞΌ.restrict s)`. For the average w.r.t. the volume, one can omit `βˆ‚volume`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => f)" βˆ‚"ΞΌ:70 => laverage ΞΌ r /-- Average value of an `ℝβ‰₯0∞`-valued function `f` w.r.t. to the standard measure. It is equal to `(volume univ)⁻¹ * ∫⁻ x, f x`, so it takes value zero if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍⁻ x in s, f x`, defined as `⨍⁻ x, f x βˆ‚(volume.restrict s)`. -/ notation3 "⨍⁻ "(...)", "r:60:(scoped f => laverage volume f) => r /-- Average value of an `ℝβ‰₯0∞`-valued function `f` w.r.t. a measure `ΞΌ` on a set `s`. It is equal to `(ΞΌ s)⁻¹ * ∫⁻ x, f x βˆ‚ΞΌ`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `βˆ‚volume`. -/ notation3 "⨍⁻ "(...)" in "s", "r:60:(scoped f => f)" βˆ‚"ΞΌ:70 => laverage (Measure.restrict ΞΌ s) r /-- Average value of an `ℝβ‰₯0∞`-valued function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume s)⁻¹ * ∫⁻ x, f x`, so it takes value zero if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 (prettyPrint := false) "⨍⁻ "(...)" in "s", "r:60:(scoped f => laverage Measure.restrict volume s f) => r @[simp] theorem laverage_zero : ⨍⁻ _x, (0 : ℝβ‰₯0∞) βˆ‚ΞΌ = 0 := by rw [laverage, lintegral_zero] @[simp] theorem laverage_zero_measure (f : Ξ± β†’ ℝβ‰₯0∞) : ⨍⁻ x, f x βˆ‚(0 : Measure Ξ±) = 0 := by simp [laverage] theorem laverage_eq' (f : Ξ± β†’ ℝβ‰₯0∞) : ⨍⁻ x, f x βˆ‚ΞΌ = ∫⁻ x, f x βˆ‚(ΞΌ univ)⁻¹ β€’ ΞΌ := rfl theorem laverage_eq (f : Ξ± β†’ ℝβ‰₯0∞) : ⨍⁻ x, f x βˆ‚ΞΌ = (∫⁻ x, f x βˆ‚ΞΌ) / ΞΌ univ := by rw [laverage_eq', lintegral_smul_measure, ENNReal.div_eq_inv_mul, smul_eq_mul] theorem laverage_eq_lintegral [IsProbabilityMeasure ΞΌ] (f : Ξ± β†’ ℝβ‰₯0∞) : ⨍⁻ x, f x βˆ‚ΞΌ = ∫⁻ x, f x βˆ‚ΞΌ := by rw [laverage, measure_univ, inv_one, one_smul] @[simp] theorem measure_mul_laverage [IsFiniteMeasure ΞΌ] (f : Ξ± β†’ ℝβ‰₯0∞) : ΞΌ univ * ⨍⁻ x, f x βˆ‚ΞΌ = ∫⁻ x, f x βˆ‚ΞΌ := by rcases eq_or_ne ΞΌ 0 with hΞΌ | hΞΌ Β· rw [hΞΌ, lintegral_zero_measure, laverage_zero_measure, mul_zero] Β· rw [laverage_eq, ENNReal.mul_div_cancel (measure_univ_ne_zero.2 hΞΌ) (measure_ne_top _ _)] theorem setLAverage_eq (f : Ξ± β†’ ℝβ‰₯0∞) (s : Set Ξ±) : ⨍⁻ x in s, f x βˆ‚ΞΌ = (∫⁻ x in s, f x βˆ‚ΞΌ) / ΞΌ s := by rw [laverage_eq, restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias setLaverage_eq := setLAverage_eq theorem setLAverage_eq' (f : Ξ± β†’ ℝβ‰₯0∞) (s : Set Ξ±) : ⨍⁻ x in s, f x βˆ‚ΞΌ = ∫⁻ x, f x βˆ‚(ΞΌ s)⁻¹ β€’ ΞΌ.restrict s := by simp only [laverage_eq', restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias setLaverage_eq' := setLAverage_eq' variable {ΞΌ} theorem laverage_congr {f g : Ξ± β†’ ℝβ‰₯0∞} (h : f =ᡐ[ΞΌ] g) : ⨍⁻ x, f x βˆ‚ΞΌ = ⨍⁻ x, g x βˆ‚ΞΌ := by simp only [laverage_eq, lintegral_congr_ae h] theorem setLAverage_congr (h : s =ᡐ[ΞΌ] t) : ⨍⁻ x in s, f x βˆ‚ΞΌ = ⨍⁻ x in t, f x βˆ‚ΞΌ := by simp only [setLAverage_eq, setLIntegral_congr h, measure_congr h] @[deprecated (since := "2025-04-22")] alias setLaverage_congr := setLAverage_congr theorem setLAverage_congr_fun (hs : MeasurableSet s) (h : βˆ€α΅ x βˆ‚ΞΌ, x ∈ s β†’ f x = g x) : ⨍⁻ x in s, f x βˆ‚ΞΌ = ⨍⁻ x in s, g x βˆ‚ΞΌ := by simp only [laverage_eq, setLIntegral_congr_fun hs h] @[deprecated (since := "2025-04-22")] alias setLaverage_congr_fun := setLAverage_congr_fun theorem laverage_lt_top (hf : ∫⁻ x, f x βˆ‚ΞΌ β‰  ∞) : ⨍⁻ x, f x βˆ‚ΞΌ < ∞ := by obtain rfl | hΞΌ := eq_or_ne ΞΌ 0 Β· simp Β· rw [laverage_eq] exact div_lt_top hf (measure_univ_ne_zero.2 hΞΌ) theorem setLAverage_lt_top : ∫⁻ x in s, f x βˆ‚ΞΌ β‰  ∞ β†’ ⨍⁻ x in s, f x βˆ‚ΞΌ < ∞ := laverage_lt_top @[deprecated (since := "2025-04-22")] alias setLaverage_lt_top := setLAverage_lt_top theorem laverage_add_measure : ⨍⁻ x, f x βˆ‚(ΞΌ + Ξ½) = ΞΌ univ / (ΞΌ univ + Ξ½ univ) * ⨍⁻ x, f x βˆ‚ΞΌ + Ξ½ univ / (ΞΌ univ + Ξ½ univ) * ⨍⁻ x, f x βˆ‚Ξ½ := by by_cases hΞΌ : IsFiniteMeasure ΞΌ; swap Β· rw [not_isFiniteMeasure_iff] at hΞΌ simp [laverage_eq, hΞΌ] by_cases hΞ½ : IsFiniteMeasure Ξ½; swap Β· rw [not_isFiniteMeasure_iff] at hΞ½ simp [laverage_eq, hΞ½] haveI := hΞΌ; haveI := hΞ½ simp only [← ENNReal.mul_div_right_comm, measure_mul_laverage, ← ENNReal.add_div, ← lintegral_add_measure, ← Measure.add_apply, ← laverage_eq] theorem measure_mul_setLAverage (f : Ξ± β†’ ℝβ‰₯0∞) (h : ΞΌ s β‰  ∞) : ΞΌ s * ⨍⁻ x in s, f x βˆ‚ΞΌ = ∫⁻ x in s, f x βˆ‚ΞΌ := by have := Fact.mk h.lt_top rw [← measure_mul_laverage, restrict_apply_univ] @[deprecated (since := "2025-04-22")] alias measure_mul_setLaverage := measure_mul_setLAverage theorem laverage_union (hd : AEDisjoint ΞΌ s t) (ht : NullMeasurableSet t ΞΌ) : ⨍⁻ x in s βˆͺ t, f x βˆ‚ΞΌ = ΞΌ s / (ΞΌ s + ΞΌ t) * ⨍⁻ x in s, f x βˆ‚ΞΌ + ΞΌ t / (ΞΌ s + ΞΌ t) * ⨍⁻ x in t, f x βˆ‚ΞΌ := by rw [restrict_unionβ‚€ hd ht, laverage_add_measure, restrict_apply_univ, restrict_apply_univ] theorem laverage_union_mem_openSegment (hd : AEDisjoint ΞΌ s t) (ht : NullMeasurableSet t ΞΌ) (hsβ‚€ : ΞΌ s β‰  0) (htβ‚€ : ΞΌ t β‰  0) (hsΞΌ : ΞΌ s β‰  ∞) (htΞΌ : ΞΌ t β‰  ∞) : ⨍⁻ x in s βˆͺ t, f x βˆ‚ΞΌ ∈ openSegment ℝβ‰₯0∞ (⨍⁻ x in s, f x βˆ‚ΞΌ) (⨍⁻ x in t, f x βˆ‚ΞΌ) := by refine ⟨μ s / (ΞΌ s + ΞΌ t), ΞΌ t / (ΞΌ s + ΞΌ t), ENNReal.div_pos hsβ‚€ <| add_ne_top.2 ⟨hsΞΌ, htμ⟩, ENNReal.div_pos htβ‚€ <| add_ne_top.2 ⟨hsΞΌ, htμ⟩, ?_, (laverage_union hd ht).symm⟩ rw [← ENNReal.add_div, ENNReal.div_self (add_eq_zero.not.2 fun h => hsβ‚€ h.1) (add_ne_top.2 ⟨hsΞΌ, htμ⟩)] theorem laverage_union_mem_segment (hd : AEDisjoint ΞΌ s t) (ht : NullMeasurableSet t ΞΌ) (hsΞΌ : ΞΌ s β‰  ∞) (htΞΌ : ΞΌ t β‰  ∞) : ⨍⁻ x in s βˆͺ t, f x βˆ‚ΞΌ ∈ [⨍⁻ x in s, f x βˆ‚ΞΌ -[ℝβ‰₯0∞] ⨍⁻ x in t, f x βˆ‚ΞΌ] := by by_cases hsβ‚€ : ΞΌ s = 0 Β· rw [← ae_eq_empty] at hsβ‚€ rw [restrict_congr_set (hsβ‚€.union EventuallyEq.rfl), empty_union] exact right_mem_segment _ _ _ Β· refine ⟨μ s / (ΞΌ s + ΞΌ t), ΞΌ t / (ΞΌ s + ΞΌ t), zero_le _, zero_le _, ?_, (laverage_union hd ht).symm⟩ rw [← ENNReal.add_div, ENNReal.div_self (add_eq_zero.not.2 fun h => hsβ‚€ h.1) (add_ne_top.2 ⟨hsΞΌ, htμ⟩)] theorem laverage_mem_openSegment_compl_self [IsFiniteMeasure ΞΌ] (hs : NullMeasurableSet s ΞΌ) (hsβ‚€ : ΞΌ s β‰  0) (hscβ‚€ : ΞΌ sᢜ β‰  0) : ⨍⁻ x, f x βˆ‚ΞΌ ∈ openSegment ℝβ‰₯0∞ (⨍⁻ x in s, f x βˆ‚ΞΌ) (⨍⁻ x in sᢜ, f x βˆ‚ΞΌ) := by simpa only [union_compl_self, restrict_univ] using laverage_union_mem_openSegment aedisjoint_compl_right hs.compl hsβ‚€ hscβ‚€ (measure_ne_top _ _) (measure_ne_top _ _) @[simp] theorem laverage_const (ΞΌ : Measure Ξ±) [IsFiniteMeasure ΞΌ] [h : NeZero ΞΌ] (c : ℝβ‰₯0∞) : ⨍⁻ _x, c βˆ‚ΞΌ = c := by simp only [laverage, lintegral_const, measure_univ, mul_one] theorem setLAverage_const (hsβ‚€ : ΞΌ s β‰  0) (hs : ΞΌ s β‰  ∞) (c : ℝβ‰₯0∞) : ⨍⁻ _x in s, c βˆ‚ΞΌ = c := by simp only [setLAverage_eq, lintegral_const, Measure.restrict_apply, MeasurableSet.univ, univ_inter, div_eq_mul_inv, mul_assoc, ENNReal.mul_inv_cancel hsβ‚€ hs, mul_one] @[deprecated (since := "2025-04-22")] alias setLaverage_const := setLAverage_const theorem laverage_one [IsFiniteMeasure ΞΌ] [NeZero ΞΌ] : ⨍⁻ _x, (1 : ℝβ‰₯0∞) βˆ‚ΞΌ = 1 := laverage_const _ _ theorem setLAverage_one (hsβ‚€ : ΞΌ s β‰  0) (hs : ΞΌ s β‰  ∞) : ⨍⁻ _x in s, (1 : ℝβ‰₯0∞) βˆ‚ΞΌ = 1 := setLAverage_const hsβ‚€ hs _ @[deprecated (since := "2025-04-22")] alias setLaverage_one := setLAverage_one @[simp] theorem laverage_mul_measure_univ (ΞΌ : Measure Ξ±) [IsFiniteMeasure ΞΌ] (f : Ξ± β†’ ℝβ‰₯0∞) : (⨍⁻ (a : Ξ±), f a βˆ‚ΞΌ) * ΞΌ univ = ∫⁻ x, f x βˆ‚ΞΌ := by obtain rfl | hΞΌ := eq_or_ne ΞΌ 0 Β· simp Β· rw [laverage_eq, ENNReal.div_mul_cancel (measure_univ_ne_zero.2 hΞΌ) (measure_ne_top _ _)] theorem lintegral_laverage (ΞΌ : Measure Ξ±) [IsFiniteMeasure ΞΌ] (f : Ξ± β†’ ℝβ‰₯0∞) : ∫⁻ _x, ⨍⁻ a, f a βˆ‚ΞΌ βˆ‚ΞΌ = ∫⁻ x, f x βˆ‚ΞΌ := by simp theorem setLIntegral_setLAverage (ΞΌ : Measure Ξ±) [IsFiniteMeasure ΞΌ] (f : Ξ± β†’ ℝβ‰₯0∞) (s : Set Ξ±) : ∫⁻ _x in s, ⨍⁻ a in s, f a βˆ‚ΞΌ βˆ‚ΞΌ = ∫⁻ x in s, f x βˆ‚ΞΌ := lintegral_laverage _ _ @[deprecated (since := "2025-04-22")] alias setLintegral_setLaverage := setLIntegral_setLAverage end ENNReal section NormedAddCommGroup variable (ΞΌ) variable {f g : Ξ± β†’ E} /-- Average value of a function `f` w.r.t. a measure `ΞΌ`, denoted `⨍ x, f x βˆ‚ΞΌ`. It is equal to `(ΞΌ.real univ)⁻¹ β€’ ∫ x, f x βˆ‚ΞΌ`, so it takes value zero if `f` is not integrable or if `ΞΌ` is an infinite measure. If `ΞΌ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍ x in s, f x βˆ‚ΞΌ`, defined as `⨍ x, f x βˆ‚(ΞΌ.restrict s)`. For the average w.r.t. the volume, one can omit `βˆ‚volume`. -/ noncomputable def average (f : Ξ± β†’ E) := ∫ x, f x βˆ‚(ΞΌ univ)⁻¹ β€’ ΞΌ /-- Average value of a function `f` w.r.t. a measure `ΞΌ`. It is equal to `(ΞΌ.real univ)⁻¹ β€’ ∫ x, f x βˆ‚ΞΌ`, so it takes value zero if `f` is not integrable or if `ΞΌ` is an infinite measure. If `ΞΌ` is a probability measure, then the average of any function is equal to its integral. For the average on a set, use `⨍ x in s, f x βˆ‚ΞΌ`, defined as `⨍ x, f x βˆ‚(ΞΌ.restrict s)`. For the average w.r.t. the volume, one can omit `βˆ‚volume`. -/ notation3 "⨍ "(...)", "r:60:(scoped f => f)" βˆ‚"ΞΌ:70 => average ΞΌ r /-- Average value of a function `f` w.r.t. to the standard measure. It is equal to `(volume.real univ)⁻¹ * ∫ x, f x`, so it takes value zero if `f` is not integrable or if the space has infinite measure. In a probability space, the average of any function is equal to its integral. For the average on a set, use `⨍ x in s, f x`, defined as `⨍ x, f x βˆ‚(volume.restrict s)`. -/ notation3 "⨍ "(...)", "r:60:(scoped f => average volume f) => r /-- Average value of a function `f` w.r.t. a measure `ΞΌ` on a set `s`. It is equal to `(ΞΌ.real s)⁻¹ * ∫ x, f x βˆ‚ΞΌ`, so it takes value zero if `f` is not integrable on `s` or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. For the average w.r.t. the volume, one can omit `βˆ‚volume`. -/ notation3 "⨍ "(...)" in "s", "r:60:(scoped f => f)" βˆ‚"ΞΌ:70 => average (Measure.restrict ΞΌ s) r /-- Average value of a function `f` w.r.t. to the standard measure on a set `s`. It is equal to `(volume.real s)⁻¹ * ∫ x, f x`, so it takes value zero `f` is not integrable on `s` or if `s` has infinite measure. If `s` has measure `1`, then the average of any function is equal to its integral. -/ notation3 "⨍ "(...)" in "s", "r:60:(scoped f => average (Measure.restrict volume s) f) => r @[simp] theorem average_zero : ⨍ _, (0 : E) βˆ‚ΞΌ = 0 := by rw [average, integral_zero] @[simp] theorem average_zero_measure (f : Ξ± β†’ E) : ⨍ x, f x βˆ‚(0 : Measure Ξ±) = 0 := by rw [average, smul_zero, integral_zero_measure] @[simp] theorem average_neg (f : Ξ± β†’ E) : ⨍ x, -f x βˆ‚ΞΌ = -⨍ x, f x βˆ‚ΞΌ := integral_neg f theorem average_eq' (f : Ξ± β†’ E) : ⨍ x, f x βˆ‚ΞΌ = ∫ x, f x βˆ‚(ΞΌ univ)⁻¹ β€’ ΞΌ := rfl theorem average_eq (f : Ξ± β†’ E) : ⨍ x, f x βˆ‚ΞΌ = (ΞΌ.real univ)⁻¹ β€’ ∫ x, f x βˆ‚ΞΌ := by rw [average_eq', integral_smul_measure, ENNReal.toReal_inv, measureReal_def] theorem average_eq_integral [IsProbabilityMeasure ΞΌ] (f : Ξ± β†’ E) : ⨍ x, f x βˆ‚ΞΌ = ∫ x, f x βˆ‚ΞΌ := by rw [average, measure_univ, inv_one, one_smul] @[simp] theorem measure_smul_average [IsFiniteMeasure ΞΌ] (f : Ξ± β†’ E) : ΞΌ.real univ β€’ ⨍ x, f x βˆ‚ΞΌ = ∫ x, f x βˆ‚ΞΌ := by rcases eq_or_ne ΞΌ 0 with hΞΌ | hΞΌ Β· rw [hΞΌ, integral_zero_measure, average_zero_measure, smul_zero] Β· rw [average_eq, smul_inv_smulβ‚€] refine (ENNReal.toReal_pos ?_ <| measure_ne_top _ _).ne' rwa [Ne, measure_univ_eq_zero] theorem setAverage_eq (f : Ξ± β†’ E) (s : Set Ξ±) : ⨍ x in s, f x βˆ‚ΞΌ = (ΞΌ.real s)⁻¹ β€’ ∫ x in s, f x βˆ‚ΞΌ := by rw [average_eq, measureReal_restrict_apply_univ] theorem setAverage_eq' (f : Ξ± β†’ E) (s : Set Ξ±) : ⨍ x in s, f x βˆ‚ΞΌ = ∫ x, f x βˆ‚(ΞΌ s)⁻¹ β€’ ΞΌ.restrict s := by simp only [average_eq', restrict_apply_univ] variable {ΞΌ}
Mathlib/MeasureTheory/Integral/Average.lean
341
347
theorem average_congr {f g : Ξ± β†’ E} (h : f =ᡐ[ΞΌ] g) : ⨍ x, f x βˆ‚ΞΌ = ⨍ x, g x βˆ‚ΞΌ := by
simp only [average_eq, integral_congr_ae h] theorem setAverage_congr (h : s =ᡐ[ΞΌ] t) : ⨍ x in s, f x βˆ‚ΞΌ = ⨍ x in t, f x βˆ‚ΞΌ := by simp only [setAverage_eq, setIntegral_congr_set h, measureReal_congr h] theorem setAverage_congr_fun (hs : MeasurableSet s) (h : βˆ€α΅ x βˆ‚ΞΌ, x ∈ s β†’ f x = g x) :
/- 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.Probability.ProbabilityMassFunction.Monad import Mathlib.Control.ULiftable /-! # Specific Constructions of Probability Mass Functions This file gives a number of different `PMF` constructions for common probability distributions. `map` and `seq` allow pushing a `PMF Ξ±` along a function `f : Ξ± β†’ Ξ²` (or distribution of functions `f : PMF (Ξ± β†’ Ξ²)`) to get a `PMF Ξ²`. `ofFinset` and `ofFintype` simplify the construction of a `PMF Ξ±` from a function `f : Ξ± β†’ ℝβ‰₯0∞`, by allowing the "sum equals 1" constraint to be in terms of `Finset.sum` instead of `tsum`. `normalize` constructs a `PMF Ξ±` by normalizing a function `f : Ξ± β†’ ℝβ‰₯0∞` by its sum, and `filter` uses this to filter the support of a `PMF` and re-normalize the new distribution. `bernoulli` represents the bernoulli distribution on `Bool`. -/ universe u v namespace PMF noncomputable section variable {Ξ± Ξ² Ξ³ : Type*} open NNReal ENNReal Finset MeasureTheory section Map /-- The functorial action of a function on a `PMF`. -/ def map (f : Ξ± β†’ Ξ²) (p : PMF Ξ±) : PMF Ξ² := bind p (pure ∘ f) variable (f : Ξ± β†’ Ξ²) (p : PMF Ξ±) (b : Ξ²) theorem monad_map_eq_map {Ξ± Ξ² : Type u} (f : Ξ± β†’ Ξ²) (p : PMF Ξ±) : f <$> p = p.map f := rfl open scoped Classical in @[simp] theorem map_apply : (map f p) b = βˆ‘' a, if b = f a then p a else 0 := by simp [map] @[simp] theorem support_map : (map f p).support = f '' p.support := Set.ext fun b => by simp [map, @eq_comm Ξ² b] theorem mem_support_map_iff : b ∈ (map f p).support ↔ βˆƒ a ∈ p.support, f a = b := by simp theorem bind_pure_comp : bind p (pure ∘ f) = map f p := rfl theorem map_id : map id p = p := bind_pure _ theorem map_comp (g : Ξ² β†’ Ξ³) : (p.map f).map g = p.map (g ∘ f) := by simp [map, Function.comp_def] theorem pure_map (a : Ξ±) : (pure a).map f = pure (f a) := pure_bind _ _ theorem map_bind (q : Ξ± β†’ PMF Ξ²) (f : Ξ² β†’ Ξ³) : (p.bind q).map f = p.bind fun a => (q a).map f := bind_bind _ _ _ @[simp] theorem bind_map (p : PMF Ξ±) (f : Ξ± β†’ Ξ²) (q : Ξ² β†’ PMF Ξ³) : (p.map f).bind q = p.bind (q ∘ f) := (bind_bind _ _ _).trans (congr_arg _ (funext fun _ => pure_bind _ _)) @[simp] theorem map_const : p.map (Function.const Ξ± b) = pure b := by simp only [map, Function.comp_def, bind_const, Function.const] section Measure variable (s : Set Ξ²) @[simp] theorem toOuterMeasure_map_apply : (p.map f).toOuterMeasure s = p.toOuterMeasure (f ⁻¹' s) := by simp [map, Set.indicator, toOuterMeasure_apply p (f ⁻¹' s)] rfl variable {mΞ± : MeasurableSpace Ξ±} {mΞ² : MeasurableSpace Ξ²} @[simp] theorem toMeasure_map_apply (hf : Measurable f) (hs : MeasurableSet s) : (p.map f).toMeasure s = p.toMeasure (f ⁻¹' s) := by rw [toMeasure_apply_eq_toOuterMeasure_apply _ s hs, toMeasure_apply_eq_toOuterMeasure_apply _ (f ⁻¹' s) (measurableSet_preimage hf hs)] exact toOuterMeasure_map_apply f p s @[simp] lemma toMeasure_map (p : PMF Ξ±) (hf : Measurable f) : p.toMeasure.map f = (p.map f).toMeasure := by ext s hs : 1; rw [PMF.toMeasure_map_apply _ _ _ hf hs, Measure.map_apply hf hs] end Measure end Map section Seq /-- The monadic sequencing operation for `PMF`. -/ def seq (q : PMF (Ξ± β†’ Ξ²)) (p : PMF Ξ±) : PMF Ξ² := q.bind fun m => p.bind fun a => pure (m a) variable (q : PMF (Ξ± β†’ Ξ²)) (p : PMF Ξ±) (b : Ξ²) theorem monad_seq_eq_seq {Ξ± Ξ² : Type u} (q : PMF (Ξ± β†’ Ξ²)) (p : PMF Ξ±) : q <*> p = q.seq p := rfl open scoped Classical in @[simp] theorem seq_apply : (seq q p) b = βˆ‘' (f : Ξ± β†’ Ξ²) (a : Ξ±), if b = f a then q f * p a else 0 := by simp only [seq, mul_boole, bind_apply, pure_apply] refine tsum_congr fun f => ENNReal.tsum_mul_left.symm.trans (tsum_congr fun a => ?_) simpa only [mul_zero] using mul_ite (b = f a) (q f) (p a) 0 @[simp] theorem support_seq : (seq q p).support = ⋃ f ∈ q.support, f '' p.support := Set.ext fun b => by simp [-mem_support_iff, seq, @eq_comm Ξ² b]
Mathlib/Probability/ProbabilityMassFunction/Constructions.lean
125
128
theorem mem_support_seq_iff : b ∈ (seq q p).support ↔ βˆƒ f ∈ q.support, b ∈ f '' p.support := by
simp end Seq
/- 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, Kim Morrison, Jens Wagemaker, Johan Commelin -/ import Mathlib.Algebra.Polynomial.BigOperators import Mathlib.Algebra.Polynomial.RingDivision import Mathlib.Data.Set.Finite.Lemmas import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Localization.FractionRing import Mathlib.SetTheory.Cardinal.Order /-! # Theory of univariate polynomials We define the multiset of roots of a polynomial, and prove basic results about it. ## Main definitions * `Polynomial.roots p`: The multiset containing all the roots of `p`, including their multiplicities. * `Polynomial.rootSet p E`: The set of distinct roots of `p` in an algebra `E`. ## Main statements * `Polynomial.C_leadingCoeff_mul_prod_multiset_X_sub_C`: If a polynomial has as many roots as its degree, it can be written as the product of its leading coefficient with `∏ (X - a)` where `a` ranges through its roots. -/ assert_not_exists Ideal open Multiset Finset noncomputable section namespace Polynomial universe u v w z variable {R : Type u} {S : Type v} {T : Type w} {a b : R} {n : β„•} section CommRing variable [CommRing R] [IsDomain R] {p q : R[X]} section Roots /-- `roots p` noncomputably gives a multiset containing all the roots of `p`, including their multiplicities. -/ noncomputable def roots (p : R[X]) : Multiset R := haveI := Classical.decEq R haveI := Classical.dec (p = 0) if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) theorem roots_def [DecidableEq R] (p : R[X]) [Decidable (p = 0)] : p.roots = if h : p = 0 then βˆ… else Classical.choose (exists_multiset_roots h) := by rename_i iR ip0 obtain rfl := Subsingleton.elim iR (Classical.decEq R) obtain rfl := Subsingleton.elim ip0 (Classical.dec (p = 0)) rfl @[simp] theorem roots_zero : (0 : R[X]).roots = 0 := dif_pos rfl theorem card_roots (hp0 : p β‰  0) : (Multiset.card (roots p) : WithBot β„•) ≀ degree p := by classical unfold roots rw [dif_neg hp0] exact (Classical.choose_spec (exists_multiset_roots hp0)).1 theorem card_roots' (p : R[X]) : Multiset.card p.roots ≀ natDegree p := by by_cases hp0 : p = 0 Β· simp [hp0] exact WithBot.coe_le_coe.1 (le_trans (card_roots hp0) (le_of_eq <| degree_eq_natDegree hp0)) theorem card_roots_sub_C {p : R[X]} {a : R} (hp0 : 0 < degree p) : (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree p := calc (Multiset.card (p - C a).roots : WithBot β„•) ≀ degree (p - C a) := card_roots <| mt sub_eq_zero.1 fun h => not_le_of_gt hp0 <| h.symm β–Έ degree_C_le _ = degree p := by rw [sub_eq_add_neg, ← C_neg]; exact degree_add_C hp0 theorem card_roots_sub_C' {p : R[X]} {a : R} (hp0 : 0 < degree p) : Multiset.card (p - C a).roots ≀ natDegree p := WithBot.coe_le_coe.1 (le_trans (card_roots_sub_C hp0) (le_of_eq <| degree_eq_natDegree fun h => by simp_all [lt_irrefl])) @[simp] theorem count_roots [DecidableEq R] (p : R[X]) : p.roots.count a = rootMultiplicity a p := by classical by_cases hp : p = 0 Β· simp [hp] rw [roots_def, dif_neg hp] exact (Classical.choose_spec (exists_multiset_roots hp)).2 a @[simp] theorem mem_roots' : a ∈ p.roots ↔ p β‰  0 ∧ IsRoot p a := by classical rw [← count_pos, count_roots p, rootMultiplicity_pos'] theorem mem_roots (hp : p β‰  0) : a ∈ p.roots ↔ IsRoot p a := mem_roots'.trans <| and_iff_right hp theorem ne_zero_of_mem_roots (h : a ∈ p.roots) : p β‰  0 := (mem_roots'.1 h).1 theorem isRoot_of_mem_roots (h : a ∈ p.roots) : IsRoot p a := (mem_roots'.1 h).2 theorem mem_roots_map_of_injective [Semiring S] {p : S[X]} {f : S β†’+* R} (hf : Function.Injective f) {x : R} (hp : p β‰  0) : x ∈ (p.map f).roots ↔ p.evalβ‚‚ f x = 0 := by rw [mem_roots ((Polynomial.map_ne_zero_iff hf).mpr hp), IsRoot, eval_map] lemma mem_roots_iff_aeval_eq_zero {x : R} (w : p β‰  0) : x ∈ roots p ↔ aeval x p = 0 := by rw [aeval_def, ← mem_roots_map_of_injective (FaithfulSMul.algebraMap_injective _ _) w, Algebra.id.map_eq_id, map_id] theorem card_le_degree_of_subset_roots {p : R[X]} {Z : Finset R} (h : Z.val βŠ† p.roots) : #Z ≀ p.natDegree := (Multiset.card_le_card (Finset.val_le_iff_val_subset.2 h)).trans (Polynomial.card_roots' p) theorem finite_setOf_isRoot {p : R[X]} (hp : p β‰  0) : Set.Finite { x | IsRoot p x } := by classical simpa only [← Finset.setOf_mem, Multiset.mem_toFinset, mem_roots hp] using p.roots.toFinset.finite_toSet theorem eq_zero_of_infinite_isRoot (p : R[X]) (h : Set.Infinite { x | IsRoot p x }) : p = 0 := not_imp_comm.mp finite_setOf_isRoot h theorem exists_max_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ x ≀ xβ‚€ := Set.exists_upper_bound_image _ _ <| finite_setOf_isRoot hp theorem exists_min_root [LinearOrder R] (p : R[X]) (hp : p β‰  0) : βˆƒ xβ‚€, βˆ€ x, p.IsRoot x β†’ xβ‚€ ≀ x := Set.exists_lower_bound_image _ _ <| finite_setOf_isRoot hp theorem eq_of_infinite_eval_eq (p q : R[X]) (h : Set.Infinite { x | eval x p = eval x q }) : p = q := by rw [← sub_eq_zero] apply eq_zero_of_infinite_isRoot simpa only [IsRoot, eval_sub, sub_eq_zero] theorem roots_mul {p q : R[X]} (hpq : p * q β‰  0) : (p * q).roots = p.roots + q.roots := by classical exact Multiset.ext.mpr fun r => by rw [count_add, count_roots, count_roots, count_roots, rootMultiplicity_mul hpq] theorem roots.le_of_dvd (h : q β‰  0) : p ∣ q β†’ roots p ≀ roots q := by rintro ⟨k, rfl⟩ exact Multiset.le_iff_exists_add.mpr ⟨k.roots, roots_mul h⟩ theorem mem_roots_sub_C' {p : R[X]} {a x : R} : x ∈ (p - C a).roots ↔ p β‰  C a ∧ p.eval x = a := by rw [mem_roots', IsRoot.def, sub_ne_zero, eval_sub, sub_eq_zero, eval_C] theorem mem_roots_sub_C {p : R[X]} {a x : R} (hp0 : 0 < degree p) : x ∈ (p - C a).roots ↔ p.eval x = a := mem_roots_sub_C'.trans <| and_iff_right fun hp => hp0.not_le <| hp.symm β–Έ degree_C_le @[simp] theorem roots_X_sub_C (r : R) : roots (X - C r) = {r} := by classical ext s rw [count_roots, rootMultiplicity_X_sub_C, count_singleton] @[simp] theorem roots_X_add_C (r : R) : roots (X + C r) = {-r} := by simpa using roots_X_sub_C (-r) @[simp] theorem roots_X : roots (X : R[X]) = {0} := by rw [← roots_X_sub_C, C_0, sub_zero] @[simp] theorem roots_C (x : R) : (C x).roots = 0 := by classical exact if H : x = 0 then by rw [H, C_0, roots_zero] else Multiset.ext.mpr fun r => (by rw [count_roots, count_zero, rootMultiplicity_eq_zero (not_isRoot_C _ _ H)]) @[simp] theorem roots_one : (1 : R[X]).roots = βˆ… := roots_C 1 @[simp] theorem roots_C_mul (p : R[X]) (ha : a β‰  0) : (C a * p).roots = p.roots := by by_cases hp : p = 0 <;> simp only [roots_mul, *, Ne, mul_eq_zero, C_eq_zero, or_self_iff, not_false_iff, roots_C, zero_add, mul_zero] @[simp] theorem roots_smul_nonzero (p : R[X]) (ha : a β‰  0) : (a β€’ p).roots = p.roots := by rw [smul_eq_C_mul, roots_C_mul _ ha] @[simp] lemma roots_neg (p : R[X]) : (-p).roots = p.roots := by rw [← neg_one_smul R p, roots_smul_nonzero p (neg_ne_zero.mpr one_ne_zero)] @[simp] theorem roots_C_mul_X_sub_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X - C b).roots = {a⁻¹ * b} := by rw [← roots_C_mul _ (Units.ne_zero a⁻¹), mul_sub, ← mul_assoc, ← C_mul, ← C_mul, Units.inv_mul, C_1, one_mul] exact roots_X_sub_C (a⁻¹ * b) @[simp] theorem roots_C_mul_X_add_C_of_IsUnit (b : R) (a : RΛ£) : (C (a : R) * X + C b).roots = {-(a⁻¹ * b)} := by rw [← sub_neg_eq_add, ← C_neg, roots_C_mul_X_sub_C_of_IsUnit, mul_neg] theorem roots_list_prod (L : List R[X]) : (0 : R[X]) βˆ‰ L β†’ L.prod.roots = (L : Multiset R[X]).bind roots := List.recOn L (fun _ => roots_one) fun hd tl ih H => by rw [List.mem_cons, not_or] at H rw [List.prod_cons, roots_mul (mul_ne_zero (Ne.symm H.1) <| List.prod_ne_zero H.2), ← Multiset.cons_coe, Multiset.cons_bind, ih H.2] theorem roots_multiset_prod (m : Multiset R[X]) : (0 : R[X]) βˆ‰ m β†’ m.prod.roots = m.bind roots := by rcases m with ⟨L⟩ simpa only [Multiset.prod_coe, quot_mk_to_coe''] using roots_list_prod L theorem roots_prod {ΞΉ : Type*} (f : ΞΉ β†’ R[X]) (s : Finset ΞΉ) : s.prod f β‰  0 β†’ (s.prod f).roots = s.val.bind fun i => roots (f i) := by rcases s with ⟨m, hm⟩ simpa [Multiset.prod_eq_zero_iff, Multiset.bind_map] using roots_multiset_prod (m.map f) @[simp] theorem roots_pow (p : R[X]) (n : β„•) : (p ^ n).roots = n β€’ p.roots := by induction n with | zero => rw [pow_zero, roots_one, zero_smul, empty_eq_zero] | succ n ihn => rcases eq_or_ne p 0 with (rfl | hp) Β· rw [zero_pow n.succ_ne_zero, roots_zero, smul_zero] Β· rw [pow_succ, roots_mul (mul_ne_zero (pow_ne_zero _ hp) hp), ihn, add_smul, one_smul] theorem roots_X_pow (n : β„•) : (X ^ n : R[X]).roots = n β€’ ({0} : Multiset R) := by rw [roots_pow, roots_X] theorem roots_C_mul_X_pow (ha : a β‰  0) (n : β„•) : Polynomial.roots (C a * X ^ n) = n β€’ ({0} : Multiset R) := by rw [roots_C_mul _ ha, roots_X_pow] @[simp] theorem roots_monomial (ha : a β‰  0) (n : β„•) : (monomial n a).roots = n β€’ ({0} : Multiset R) := by rw [← C_mul_X_pow_eq_monomial, roots_C_mul_X_pow ha] theorem roots_prod_X_sub_C (s : Finset R) : (s.prod fun a => X - C a).roots = s.val := by apply (roots_prod (fun a => X - C a) s ?_).trans Β· simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] Β· refine prod_ne_zero_iff.mpr (fun a _ => X_sub_C_ne_zero a) @[simp] theorem roots_multiset_prod_X_sub_C (s : Multiset R) : (s.map fun a => X - C a).prod.roots = s := by rw [roots_multiset_prod, Multiset.bind_map] Β· simp_rw [roots_X_sub_C] rw [Multiset.bind_singleton, Multiset.map_id'] Β· rw [Multiset.mem_map] rintro ⟨a, -, h⟩ exact X_sub_C_ne_zero a h theorem card_roots_X_pow_sub_C {n : β„•} (hn : 0 < n) (a : R) : Multiset.card (roots ((X : R[X]) ^ n - C a)) ≀ n := WithBot.coe_le_coe.1 <| calc (Multiset.card (roots ((X : R[X]) ^ n - C a)) : WithBot β„•) ≀ degree ((X : R[X]) ^ n - C a) := card_roots (X_pow_sub_C_ne_zero hn a) _ = n := degree_X_pow_sub_C hn a section NthRoots /-- `nthRoots n a` noncomputably returns the solutions to `x ^ n = a`. -/ def nthRoots (n : β„•) (a : R) : Multiset R := roots ((X : R[X]) ^ n - C a) @[simp] theorem mem_nthRoots {n : β„•} (hn : 0 < n) {a x : R} : x ∈ nthRoots n a ↔ x ^ n = a := by rw [nthRoots, mem_roots (X_pow_sub_C_ne_zero hn a), IsRoot.def, eval_sub, eval_C, eval_pow, eval_X, sub_eq_zero] @[simp] theorem nthRoots_zero (r : R) : nthRoots 0 r = 0 := by simp only [empty_eq_zero, pow_zero, nthRoots, ← C_1, ← C_sub, roots_C] @[simp] theorem nthRoots_zero_right {R} [CommRing R] [IsDomain R] (n : β„•) : nthRoots n (0 : R) = Multiset.replicate n 0 := by rw [nthRoots, C.map_zero, sub_zero, roots_pow, roots_X, Multiset.nsmul_singleton] theorem card_nthRoots (n : β„•) (a : R) : Multiset.card (nthRoots n a) ≀ n := by classical exact (if hn : n = 0 then if h : (X : R[X]) ^ n - C a = 0 then by simp [Nat.zero_le, nthRoots, roots, h, dif_pos rfl, empty_eq_zero, Multiset.card_zero] else WithBot.coe_le_coe.1 (le_trans (card_roots h) (by rw [hn, pow_zero, ← C_1, ← RingHom.map_sub] exact degree_C_le)) else by rw [← Nat.cast_le (Ξ± := WithBot β„•)] rw [← degree_X_pow_sub_C (Nat.pos_of_ne_zero hn) a] exact card_roots (X_pow_sub_C_ne_zero (Nat.pos_of_ne_zero hn) a)) @[simp] theorem nthRoots_two_eq_zero_iff {r : R} : nthRoots 2 r = 0 ↔ Β¬IsSquare r := by simp_rw [isSquare_iff_exists_sq, eq_zero_iff_forall_not_mem, mem_nthRoots (by norm_num : 0 < 2), ← not_exists, eq_comm] /-- The multiset `nthRoots ↑n a` as a Finset. Previously `nthRootsFinset n` was defined to be `nthRoots n (1 : R)` as a Finset. That situation can be recovered by setting `a` to be `(1 : R)` -/ def nthRootsFinset (n : β„•) {R : Type*} (a : R) [CommRing R] [IsDomain R] : Finset R := haveI := Classical.decEq R Multiset.toFinset (nthRoots n a) lemma nthRootsFinset_def (n : β„•) {R : Type*} (a : R) [CommRing R] [IsDomain R] [DecidableEq R] : nthRootsFinset n a = Multiset.toFinset (nthRoots n a) := by unfold nthRootsFinset convert rfl @[simp] theorem mem_nthRootsFinset {n : β„•} (h : 0 < n) (a : R) {x : R} : x ∈ nthRootsFinset n a ↔ x ^ (n : β„•) = a := by classical rw [nthRootsFinset_def, mem_toFinset, mem_nthRoots h] @[simp] theorem nthRootsFinset_zero (a : R) : nthRootsFinset 0 a = βˆ… := by classical simp [nthRootsFinset_def] theorem map_mem_nthRootsFinset {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S] [MonoidHomClass F R S] {a : R} {x : R} (hx : x ∈ nthRootsFinset n a) (f : F) : f x ∈ nthRootsFinset n (f a) := by by_cases hn : n = 0 Β· simp [hn] at hx Β· rw [mem_nthRootsFinset <| Nat.pos_of_ne_zero hn, ← map_pow, (mem_nthRootsFinset (Nat.pos_of_ne_zero hn) a).1 hx] theorem map_mem_nthRootsFinset_one {S F : Type*} [CommRing S] [IsDomain S] [FunLike F R S] [RingHomClass F R S] {x : R} (hx : x ∈ nthRootsFinset n 1) (f : F) : f x ∈ nthRootsFinset n 1 := by rw [← (map_one f)] exact map_mem_nthRootsFinset hx _ theorem mul_mem_nthRootsFinset {η₁ Ξ·β‚‚ : R} {a₁ aβ‚‚ : R} (hη₁ : η₁ ∈ nthRootsFinset n a₁) (hΞ·β‚‚ : Ξ·β‚‚ ∈ nthRootsFinset n aβ‚‚) : η₁ * Ξ·β‚‚ ∈ nthRootsFinset n (a₁ * aβ‚‚) := by cases n with | zero => simp only [nthRootsFinset_zero, not_mem_empty] at hη₁ | succ n => rw [mem_nthRootsFinset n.succ_pos] at hη₁ hΞ·β‚‚ ⊒ rw [mul_pow, hη₁, hΞ·β‚‚] theorem ne_zero_of_mem_nthRootsFinset {Ξ· : R} {a : R} (ha : a β‰  0) (hΞ· : Ξ· ∈ nthRootsFinset n a) : Ξ· β‰  0 := by nontriviality R rintro rfl cases n with | zero => simp only [nthRootsFinset_zero, not_mem_empty] at hΞ· | succ n => rw [mem_nthRootsFinset n.succ_pos, zero_pow n.succ_ne_zero] at hΞ· exact ha hΞ·.symm theorem one_mem_nthRootsFinset (hn : 0 < n) : 1 ∈ nthRootsFinset n (1 : R) := by rw [mem_nthRootsFinset hn, one_pow] end NthRoots theorem zero_of_eval_zero [Infinite R] (p : R[X]) (h : βˆ€ x, p.eval x = 0) : p = 0 := by classical by_contra hp refine @Fintype.false R _ ?_ exact ⟨p.roots.toFinset, fun x => Multiset.mem_toFinset.mpr ((mem_roots hp).mpr (h _))⟩ theorem funext [Infinite R] {p q : R[X]} (ext : βˆ€ r : R, p.eval r = q.eval r) : p = q := by rw [← sub_eq_zero] apply zero_of_eval_zero intro x rw [eval_sub, sub_eq_zero, ext] variable [CommRing T] /-- Given a polynomial `p` with coefficients in a ring `T` and a `T`-algebra `S`, `aroots p S` is the multiset of roots of `p` regarded as a polynomial over `S`. -/ noncomputable abbrev aroots (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : Multiset S := (p.map (algebraMap T S)).roots theorem aroots_def (p : T[X]) (S) [CommRing S] [IsDomain S] [Algebra T S] : p.aroots S = (p.map (algebraMap T S)).roots := rfl theorem mem_aroots' [CommRing S] [IsDomain S] [Algebra T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p.map (algebraMap T S) β‰  0 ∧ aeval a p = 0 := by rw [mem_roots', IsRoot.def, ← evalβ‚‚_eq_eval_map, aeval_def] theorem mem_aroots [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p : T[X]} {a : S} : a ∈ p.aroots S ↔ p β‰  0 ∧ aeval a p = 0 := by rw [mem_aroots', Polynomial.map_ne_zero_iff] exact FaithfulSMul.algebraMap_injective T S theorem aroots_mul [CommRing S] [IsDomain S] [Algebra T S] [NoZeroSMulDivisors T S] {p q : T[X]} (hpq : p * q β‰  0) : (p * q).aroots S = p.aroots S + q.aroots S := by suffices map (algebraMap T S) p * map (algebraMap T S) q β‰  0 by rw [aroots_def, Polynomial.map_mul, roots_mul this] rwa [← Polynomial.map_mul, Polynomial.map_ne_zero_iff (FaithfulSMul.algebraMap_injective T S)] @[simp] theorem aroots_X_sub_C [CommRing S] [IsDomain S] [Algebra T S] (r : T) : aroots (X - C r) S = {algebraMap T S r} := by rw [aroots_def, Polynomial.map_sub, map_X, map_C, roots_X_sub_C] @[simp] theorem aroots_X [CommRing S] [IsDomain S] [Algebra T S] : aroots (X : T[X]) S = {0} := by rw [aroots_def, map_X, roots_X] @[simp] theorem aroots_C [CommRing S] [IsDomain S] [Algebra T S] (a : T) : (C a).aroots S = 0 := by rw [aroots_def, map_C, roots_C] @[simp]
Mathlib/Algebra/Polynomial/Roots.lean
428
434
theorem aroots_zero (S) [CommRing S] [IsDomain S] [Algebra T S] : (0 : T[X]).aroots S = 0 := by
rw [← C_0, aroots_C] @[simp] theorem aroots_one [CommRing S] [IsDomain S] [Algebra T S] : (1 : T[X]).aroots S = 0 := aroots_C 1
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, YaΓ«l Dillies -/ import Mathlib.Order.Cover import Mathlib.Order.Interval.Finset.Defs /-! # Intervals as finsets This file provides basic results about all the `Finset.Ixx`, which are defined in `Order.Interval.Finset.Defs`. In addition, it shows that in a locally finite order `≀` and `<` are the transitive closures of, respectively, `β©Ώ` and `β‹–`, which then leads to a characterization of monotone and strictly functions whose domain is a locally finite order. In particular, this file proves: * `le_iff_transGen_wcovBy`: `≀` is the transitive closure of `β©Ώ` * `lt_iff_transGen_covBy`: `<` is the transitive closure of `β‹–` * `monotone_iff_forall_wcovBy`: Characterization of monotone functions * `strictMono_iff_forall_covBy`: Characterization of strictly monotone functions ## TODO This file was originally only about `Finset.Ico a b` where `a b : β„•`. No care has yet been taken to generalize these lemmas properly and many lemmas about `Icc`, `Ioc`, `Ioo` are missing. In general, what's to do is taking the lemmas in `Data.X.Intervals` and abstract away the concrete structure. Complete the API. See https://github.com/leanprover-community/mathlib/pull/14448#discussion_r906109235 for some ideas. -/ assert_not_exists MonoidWithZero Finset.sum open Function OrderDual open FinsetInterval variable {ΞΉ Ξ± : Type*} {a a₁ aβ‚‚ b b₁ bβ‚‚ c x : Ξ±} namespace Finset section Preorder variable [Preorder Ξ±] section LocallyFiniteOrder variable [LocallyFiniteOrder Ξ±] @[simp] theorem nonempty_Icc : (Icc a b).Nonempty ↔ a ≀ b := by rw [← coe_nonempty, coe_Icc, Set.nonempty_Icc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Icc_of_le⟩ := nonempty_Icc @[simp] theorem nonempty_Ico : (Ico a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ico, Set.nonempty_Ico] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ico_of_lt⟩ := nonempty_Ico @[simp] theorem nonempty_Ioc : (Ioc a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioc, Set.nonempty_Ioc] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioc_of_lt⟩ := nonempty_Ioc -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem nonempty_Ioo [DenselyOrdered Ξ±] : (Ioo a b).Nonempty ↔ a < b := by rw [← coe_nonempty, coe_Ioo, Set.nonempty_Ioo] @[simp] theorem Icc_eq_empty_iff : Icc a b = βˆ… ↔ Β¬a ≀ b := by rw [← coe_eq_empty, coe_Icc, Set.Icc_eq_empty_iff] @[simp] theorem Ico_eq_empty_iff : Ico a b = βˆ… ↔ Β¬a < b := by rw [← coe_eq_empty, coe_Ico, Set.Ico_eq_empty_iff] @[simp] theorem Ioc_eq_empty_iff : Ioc a b = βˆ… ↔ Β¬a < b := by rw [← coe_eq_empty, coe_Ioc, Set.Ioc_eq_empty_iff] -- TODO: This is nonsense. A locally finite order is never densely ordered @[simp] theorem Ioo_eq_empty_iff [DenselyOrdered Ξ±] : Ioo a b = βˆ… ↔ Β¬a < b := by rw [← coe_eq_empty, coe_Ioo, Set.Ioo_eq_empty_iff] alias ⟨_, Icc_eq_empty⟩ := Icc_eq_empty_iff alias ⟨_, Ico_eq_empty⟩ := Ico_eq_empty_iff alias ⟨_, Ioc_eq_empty⟩ := Ioc_eq_empty_iff @[simp] theorem Ioo_eq_empty (h : Β¬a < b) : Ioo a b = βˆ… := eq_empty_iff_forall_not_mem.2 fun _ hx => h ((mem_Ioo.1 hx).1.trans (mem_Ioo.1 hx).2) @[simp] theorem Icc_eq_empty_of_lt (h : b < a) : Icc a b = βˆ… := Icc_eq_empty h.not_le @[simp] theorem Ico_eq_empty_of_le (h : b ≀ a) : Ico a b = βˆ… := Ico_eq_empty h.not_lt @[simp] theorem Ioc_eq_empty_of_le (h : b ≀ a) : Ioc a b = βˆ… := Ioc_eq_empty h.not_lt @[simp] theorem Ioo_eq_empty_of_le (h : b ≀ a) : Ioo a b = βˆ… := Ioo_eq_empty h.not_lt theorem left_mem_Icc : a ∈ Icc a b ↔ a ≀ b := by simp only [mem_Icc, true_and, le_rfl] theorem left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp only [mem_Ico, true_and, le_refl] theorem right_mem_Icc : b ∈ Icc a b ↔ a ≀ b := by simp only [mem_Icc, and_true, le_rfl] theorem right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp only [mem_Ioc, and_true, le_rfl] theorem left_not_mem_Ioc : a βˆ‰ Ioc a b := fun h => lt_irrefl _ (mem_Ioc.1 h).1 theorem left_not_mem_Ioo : a βˆ‰ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).1 theorem right_not_mem_Ico : b βˆ‰ Ico a b := fun h => lt_irrefl _ (mem_Ico.1 h).2 theorem right_not_mem_Ioo : b βˆ‰ Ioo a b := fun h => lt_irrefl _ (mem_Ioo.1 h).2 @[gcongr] theorem Icc_subset_Icc (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Icc a₁ b₁ βŠ† Icc aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Icc_subset_Icc ha hb @[gcongr] theorem Ico_subset_Ico (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Ico a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Ico_subset_Ico ha hb @[gcongr] theorem Ioc_subset_Ioc (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Ioc a₁ b₁ βŠ† Ioc aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Ioc_subset_Ioc ha hb @[gcongr] theorem Ioo_subset_Ioo (ha : aβ‚‚ ≀ a₁) (hb : b₁ ≀ bβ‚‚) : Ioo a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ := by simpa [← coe_subset] using Set.Ioo_subset_Ioo ha hb @[gcongr] theorem Icc_subset_Icc_left (h : a₁ ≀ aβ‚‚) : Icc aβ‚‚ b βŠ† Icc a₁ b := Icc_subset_Icc h le_rfl @[gcongr] theorem Ico_subset_Ico_left (h : a₁ ≀ aβ‚‚) : Ico aβ‚‚ b βŠ† Ico a₁ b := Ico_subset_Ico h le_rfl @[gcongr] theorem Ioc_subset_Ioc_left (h : a₁ ≀ aβ‚‚) : Ioc aβ‚‚ b βŠ† Ioc a₁ b := Ioc_subset_Ioc h le_rfl @[gcongr] theorem Ioo_subset_Ioo_left (h : a₁ ≀ aβ‚‚) : Ioo aβ‚‚ b βŠ† Ioo a₁ b := Ioo_subset_Ioo h le_rfl @[gcongr] theorem Icc_subset_Icc_right (h : b₁ ≀ bβ‚‚) : Icc a b₁ βŠ† Icc a bβ‚‚ := Icc_subset_Icc le_rfl h @[gcongr] theorem Ico_subset_Ico_right (h : b₁ ≀ bβ‚‚) : Ico a b₁ βŠ† Ico a bβ‚‚ := Ico_subset_Ico le_rfl h @[gcongr] theorem Ioc_subset_Ioc_right (h : b₁ ≀ bβ‚‚) : Ioc a b₁ βŠ† Ioc a bβ‚‚ := Ioc_subset_Ioc le_rfl h @[gcongr] theorem Ioo_subset_Ioo_right (h : b₁ ≀ bβ‚‚) : Ioo a b₁ βŠ† Ioo a bβ‚‚ := Ioo_subset_Ioo le_rfl h theorem Ico_subset_Ioo_left (h : a₁ < aβ‚‚) : Ico aβ‚‚ b βŠ† Ioo a₁ b := by rw [← coe_subset, coe_Ico, coe_Ioo] exact Set.Ico_subset_Ioo_left h theorem Ioc_subset_Ioo_right (h : b₁ < bβ‚‚) : Ioc a b₁ βŠ† Ioo a bβ‚‚ := by rw [← coe_subset, coe_Ioc, coe_Ioo] exact Set.Ioc_subset_Ioo_right h theorem Icc_subset_Ico_right (h : b₁ < bβ‚‚) : Icc a b₁ βŠ† Ico a bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Ico] exact Set.Icc_subset_Ico_right h theorem Ioo_subset_Ico_self : Ioo a b βŠ† Ico a b := by rw [← coe_subset, coe_Ioo, coe_Ico] exact Set.Ioo_subset_Ico_self theorem Ioo_subset_Ioc_self : Ioo a b βŠ† Ioc a b := by rw [← coe_subset, coe_Ioo, coe_Ioc] exact Set.Ioo_subset_Ioc_self theorem Ico_subset_Icc_self : Ico a b βŠ† Icc a b := by rw [← coe_subset, coe_Ico, coe_Icc] exact Set.Ico_subset_Icc_self theorem Ioc_subset_Icc_self : Ioc a b βŠ† Icc a b := by rw [← coe_subset, coe_Ioc, coe_Icc] exact Set.Ioc_subset_Icc_self theorem Ioo_subset_Icc_self : Ioo a b βŠ† Icc a b := Ioo_subset_Ico_self.trans Ico_subset_Icc_self theorem Icc_subset_Icc_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Icc aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ ≀ bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Icc, Set.Icc_subset_Icc_iff h₁] theorem Icc_subset_Ioo_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioo aβ‚‚ bβ‚‚ ↔ aβ‚‚ < a₁ ∧ b₁ < bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Ioo, Set.Icc_subset_Ioo_iff h₁] theorem Icc_subset_Ico_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ < bβ‚‚ := by rw [← coe_subset, coe_Icc, coe_Ico, Set.Icc_subset_Ico_iff h₁] theorem Icc_subset_Ioc_iff (h₁ : a₁ ≀ b₁) : Icc a₁ b₁ βŠ† Ioc aβ‚‚ bβ‚‚ ↔ aβ‚‚ < a₁ ∧ b₁ ≀ bβ‚‚ := (Icc_subset_Ico_iff h₁.dual).trans and_comm --TODO: `Ico_subset_Ioo_iff`, `Ioc_subset_Ioo_iff` theorem Icc_ssubset_Icc_left (hI : aβ‚‚ ≀ bβ‚‚) (ha : aβ‚‚ < a₁) (hb : b₁ ≀ bβ‚‚) : Icc a₁ b₁ βŠ‚ Icc aβ‚‚ bβ‚‚ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_left hI ha hb theorem Icc_ssubset_Icc_right (hI : aβ‚‚ ≀ bβ‚‚) (ha : aβ‚‚ ≀ a₁) (hb : b₁ < bβ‚‚) : Icc a₁ b₁ βŠ‚ Icc aβ‚‚ bβ‚‚ := by rw [← coe_ssubset, coe_Icc, coe_Icc] exact Set.Icc_ssubset_Icc_right hI ha hb @[simp] theorem Ioc_disjoint_Ioc_of_le {d : Ξ±} (hbc : b ≀ c) : Disjoint (Ioc a b) (Ioc c d) := disjoint_left.2 fun _ h1 h2 ↦ not_and_of_not_left _ ((mem_Ioc.1 h1).2.trans hbc).not_lt (mem_Ioc.1 h2) variable (a) theorem Ico_self : Ico a a = βˆ… := Ico_eq_empty <| lt_irrefl _ theorem Ioc_self : Ioc a a = βˆ… := Ioc_eq_empty <| lt_irrefl _ theorem Ioo_self : Ioo a a = βˆ… := Ioo_eq_empty <| lt_irrefl _ variable {a} /-- A set with upper and lower bounds in a locally finite order is a fintype -/ def _root_.Set.fintypeOfMemBounds {s : Set Ξ±} [DecidablePred (Β· ∈ s)] (ha : a ∈ lowerBounds s) (hb : b ∈ upperBounds s) : Fintype s := Set.fintypeSubset (Set.Icc a b) fun _ hx => ⟨ha hx, hb hx⟩ section Filter theorem Ico_filter_lt_of_le_left [DecidablePred (Β· < c)] (hca : c ≀ a) : {x ∈ Ico a b | x < c} = βˆ… := filter_false_of_mem fun _ hx => (hca.trans (mem_Ico.1 hx).1).not_lt theorem Ico_filter_lt_of_right_le [DecidablePred (Β· < c)] (hbc : b ≀ c) : {x ∈ Ico a b | x < c} = Ico a b := filter_true_of_mem fun _ hx => (mem_Ico.1 hx).2.trans_le hbc theorem Ico_filter_lt_of_le_right [DecidablePred (Β· < c)] (hcb : c ≀ b) : {x ∈ Ico a b | x < c} = Ico a c := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_right_comm] exact and_iff_left_of_imp fun h => h.2.trans_le hcb theorem Ico_filter_le_of_le_left {a b c : Ξ±} [DecidablePred (c ≀ Β·)] (hca : c ≀ a) : {x ∈ Ico a b | c ≀ x} = Ico a b := filter_true_of_mem fun _ hx => hca.trans (mem_Ico.1 hx).1 theorem Ico_filter_le_of_right_le {a b : Ξ±} [DecidablePred (b ≀ Β·)] : {x ∈ Ico a b | b ≀ x} = βˆ… := filter_false_of_mem fun _ hx => (mem_Ico.1 hx).2.not_le theorem Ico_filter_le_of_left_le {a b c : Ξ±} [DecidablePred (c ≀ Β·)] (hac : a ≀ c) : {x ∈ Ico a b | c ≀ x} = Ico c b := by ext x rw [mem_filter, mem_Ico, mem_Ico, and_comm, and_left_comm] exact and_iff_right_of_imp fun h => hac.trans h.1 theorem Icc_filter_lt_of_lt_right {a b c : Ξ±} [DecidablePred (Β· < c)] (h : b < c) : {x ∈ Icc a b | x < c} = Icc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Icc.1 hx).2 h theorem Ioc_filter_lt_of_lt_right {a b c : Ξ±} [DecidablePred (Β· < c)] (h : b < c) : {x ∈ Ioc a b | x < c} = Ioc a b := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Ioc.1 hx).2 h theorem Iic_filter_lt_of_lt_right {Ξ±} [Preorder Ξ±] [LocallyFiniteOrderBot Ξ±] {a c : Ξ±} [DecidablePred (Β· < c)] (h : a < c) : {x ∈ Iic a | x < c} = Iic a := filter_true_of_mem fun _ hx => lt_of_le_of_lt (mem_Iic.1 hx) h variable (a b) [Fintype Ξ±] theorem filter_lt_lt_eq_Ioo [DecidablePred fun j => a < j ∧ j < b] : ({j | a < j ∧ j < b} : Finset _) = Ioo a b := by ext; simp theorem filter_lt_le_eq_Ioc [DecidablePred fun j => a < j ∧ j ≀ b] : ({j | a < j ∧ j ≀ b} : Finset _) = Ioc a b := by ext; simp theorem filter_le_lt_eq_Ico [DecidablePred fun j => a ≀ j ∧ j < b] : ({j | a ≀ j ∧ j < b} : Finset _) = Ico a b := by ext; simp theorem filter_le_le_eq_Icc [DecidablePred fun j => a ≀ j ∧ j ≀ b] : ({j | a ≀ j ∧ j ≀ b} : Finset _) = Icc a b := by ext; simp end Filter end LocallyFiniteOrder section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop Ξ±] @[simp] theorem Ioi_eq_empty : Ioi a = βˆ… ↔ IsMax a := by rw [← coe_eq_empty, coe_Ioi, Set.Ioi_eq_empty_iff] @[simp] alias ⟨_, _root_.IsMax.finsetIoi_eq⟩ := Ioi_eq_empty @[simp] lemma Ioi_nonempty : (Ioi a).Nonempty ↔ Β¬ IsMax a := by simp [nonempty_iff_ne_empty] theorem Ioi_top [OrderTop Ξ±] : Ioi (⊀ : Ξ±) = βˆ… := Ioi_eq_empty.mpr isMax_top @[simp] theorem Ici_bot [OrderBot Ξ±] [Fintype Ξ±] : Ici (βŠ₯ : Ξ±) = univ := by ext a; simp only [mem_Ici, bot_le, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Ici : (Ici a).Nonempty := ⟨a, mem_Ici.2 le_rfl⟩ lemma nonempty_Ioi : (Ioi a).Nonempty ↔ Β¬ IsMax a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Ioi_of_not_isMax⟩ := nonempty_Ioi @[simp] theorem Ici_subset_Ici : Ici a βŠ† Ici b ↔ b ≀ a := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_subset_Ici⟩ := Ici_subset_Ici @[simp] theorem Ici_ssubset_Ici : Ici a βŠ‚ Ici b ↔ b < a := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Ici_ssubset_Ici⟩ := Ici_ssubset_Ici @[gcongr] theorem Ioi_subset_Ioi (h : a ≀ b) : Ioi b βŠ† Ioi a := by simpa [← coe_subset] using Set.Ioi_subset_Ioi h @[gcongr] theorem Ioi_ssubset_Ioi (h : a < b) : Ioi b βŠ‚ Ioi a := by simpa [← coe_ssubset] using Set.Ioi_ssubset_Ioi h variable [LocallyFiniteOrder Ξ±] theorem Icc_subset_Ici_self : Icc a b βŠ† Ici a := by simpa [← coe_subset] using Set.Icc_subset_Ici_self theorem Ico_subset_Ici_self : Ico a b βŠ† Ici a := by simpa [← coe_subset] using Set.Ico_subset_Ici_self theorem Ioc_subset_Ioi_self : Ioc a b βŠ† Ioi a := by simpa [← coe_subset] using Set.Ioc_subset_Ioi_self theorem Ioo_subset_Ioi_self : Ioo a b βŠ† Ioi a := by simpa [← coe_subset] using Set.Ioo_subset_Ioi_self theorem Ioc_subset_Ici_self : Ioc a b βŠ† Ici a := Ioc_subset_Icc_self.trans Icc_subset_Ici_self theorem Ioo_subset_Ici_self : Ioo a b βŠ† Ici a := Ioo_subset_Ico_self.trans Ico_subset_Ici_self end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot Ξ±] @[simp] theorem Iio_eq_empty : Iio a = βˆ… ↔ IsMin a := Ioi_eq_empty (Ξ± := Ξ±α΅’α΅ˆ) @[simp] alias ⟨_, _root_.IsMin.finsetIio_eq⟩ := Iio_eq_empty @[simp] lemma Iio_nonempty : (Iio a).Nonempty ↔ Β¬ IsMin a := by simp [nonempty_iff_ne_empty] theorem Iio_bot [OrderBot Ξ±] : Iio (βŠ₯ : Ξ±) = βˆ… := Iio_eq_empty.mpr isMin_bot @[simp] theorem Iic_top [OrderTop Ξ±] [Fintype Ξ±] : Iic (⊀ : Ξ±) = univ := by ext a; simp only [mem_Iic, le_top, mem_univ] @[simp, aesop safe apply (rule_sets := [finsetNonempty])] lemma nonempty_Iic : (Iic a).Nonempty := ⟨a, mem_Iic.2 le_rfl⟩ lemma nonempty_Iio : (Iio a).Nonempty ↔ Β¬ IsMin a := by simp [Finset.Nonempty] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.nonempty_Iio_of_not_isMin⟩ := nonempty_Iio @[simp] theorem Iic_subset_Iic : Iic a βŠ† Iic b ↔ a ≀ b := by simp [← coe_subset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_subset_Iic⟩ := Iic_subset_Iic @[simp] theorem Iic_ssubset_Iic : Iic a βŠ‚ Iic b ↔ a < b := by simp [← coe_ssubset] @[gcongr] alias ⟨_, _root_.GCongr.Finset.Iic_ssubset_Iic⟩ := Iic_ssubset_Iic @[gcongr] theorem Iio_subset_Iio (h : a ≀ b) : Iio a βŠ† Iio b := by simpa [← coe_subset] using Set.Iio_subset_Iio h @[gcongr] theorem Iio_ssubset_Iio (h : a < b) : Iio a βŠ‚ Iio b := by simpa [← coe_ssubset] using Set.Iio_ssubset_Iio h variable [LocallyFiniteOrder Ξ±] theorem Icc_subset_Iic_self : Icc a b βŠ† Iic b := by simpa [← coe_subset] using Set.Icc_subset_Iic_self theorem Ioc_subset_Iic_self : Ioc a b βŠ† Iic b := by simpa [← coe_subset] using Set.Ioc_subset_Iic_self theorem Ico_subset_Iio_self : Ico a b βŠ† Iio b := by simpa [← coe_subset] using Set.Ico_subset_Iio_self theorem Ioo_subset_Iio_self : Ioo a b βŠ† Iio b := by simpa [← coe_subset] using Set.Ioo_subset_Iio_self theorem Ico_subset_Iic_self : Ico a b βŠ† Iic b := Ico_subset_Icc_self.trans Icc_subset_Iic_self theorem Ioo_subset_Iic_self : Ioo a b βŠ† Iic b := Ioo_subset_Ioc_self.trans Ioc_subset_Iic_self theorem Iic_disjoint_Ioc (h : a ≀ b) : Disjoint (Iic a) (Ioc b c) := disjoint_left.2 fun _ hax hbcx ↦ (mem_Iic.1 hax).not_lt <| lt_of_le_of_lt h (mem_Ioc.1 hbcx).1 /-- An equivalence between `Finset.Iic a` and `Set.Iic a`. -/ def _root_.Equiv.IicFinsetSet (a : Ξ±) : Iic a ≃ Set.Iic a where toFun b := ⟨b.1, coe_Iic a β–Έ mem_coe.2 b.2⟩ invFun b := ⟨b.1, by rw [← mem_coe, coe_Iic a]; exact b.2⟩ left_inv := fun _ ↦ rfl right_inv := fun _ ↦ rfl end LocallyFiniteOrderBot section LocallyFiniteOrderTop variable [LocallyFiniteOrderTop Ξ±] {a : Ξ±} theorem Ioi_subset_Ici_self : Ioi a βŠ† Ici a := by simpa [← coe_subset] using Set.Ioi_subset_Ici_self theorem _root_.BddBelow.finite {s : Set Ξ±} (hs : BddBelow s) : s.Finite := let ⟨a, ha⟩ := hs (Ici a).finite_toSet.subset fun _ hx => mem_Ici.2 <| ha hx theorem _root_.Set.Infinite.not_bddBelow {s : Set Ξ±} : s.Infinite β†’ Β¬BddBelow s := mt BddBelow.finite variable [Fintype Ξ±] theorem filter_lt_eq_Ioi [DecidablePred (a < Β·)] : ({x | a < x} : Finset _) = Ioi a := by ext; simp theorem filter_le_eq_Ici [DecidablePred (a ≀ Β·)] : ({x | a ≀ x} : Finset _) = Ici a := by ext; simp end LocallyFiniteOrderTop section LocallyFiniteOrderBot variable [LocallyFiniteOrderBot Ξ±] {a : Ξ±} theorem Iio_subset_Iic_self : Iio a βŠ† Iic a := by simpa [← coe_subset] using Set.Iio_subset_Iic_self theorem _root_.BddAbove.finite {s : Set Ξ±} (hs : BddAbove s) : s.Finite := hs.dual.finite theorem _root_.Set.Infinite.not_bddAbove {s : Set Ξ±} : s.Infinite β†’ Β¬BddAbove s := mt BddAbove.finite variable [Fintype Ξ±] theorem filter_gt_eq_Iio [DecidablePred (Β· < a)] : ({x | x < a} : Finset _) = Iio a := by ext; simp theorem filter_ge_eq_Iic [DecidablePred (Β· ≀ a)] : ({x | x ≀ a} : Finset _) = Iic a := by ext; simp end LocallyFiniteOrderBot section LocallyFiniteOrder variable [LocallyFiniteOrder Ξ±] @[simp] theorem Icc_bot [OrderBot Ξ±] : Icc (βŠ₯ : Ξ±) a = Iic a := rfl @[simp] theorem Icc_top [OrderTop Ξ±] : Icc a (⊀ : Ξ±) = Ici a := rfl @[simp] theorem Ico_bot [OrderBot Ξ±] : Ico (βŠ₯ : Ξ±) a = Iio a := rfl @[simp] theorem Ioc_top [OrderTop Ξ±] : Ioc a (⊀ : Ξ±) = Ioi a := rfl theorem Icc_bot_top [BoundedOrder Ξ±] [Fintype Ξ±] : Icc (βŠ₯ : Ξ±) (⊀ : Ξ±) = univ := by rw [Icc_bot, Iic_top] end LocallyFiniteOrder variable [LocallyFiniteOrderTop Ξ±] [LocallyFiniteOrderBot Ξ±] theorem disjoint_Ioi_Iio (a : Ξ±) : Disjoint (Ioi a) (Iio a) := disjoint_left.2 fun _ hab hba => (mem_Ioi.1 hab).not_lt <| mem_Iio.1 hba end Preorder section PartialOrder variable [PartialOrder Ξ±] [LocallyFiniteOrder Ξ±] {a b c : Ξ±} @[simp] theorem Icc_self (a : Ξ±) : Icc a a = {a} := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_self] @[simp] theorem Icc_eq_singleton_iff : Icc a b = {c} ↔ a = c ∧ b = c := by rw [← coe_eq_singleton, coe_Icc, Set.Icc_eq_singleton_iff] theorem Ico_disjoint_Ico_consecutive (a b c : Ξ±) : Disjoint (Ico a b) (Ico b c) := disjoint_left.2 fun _ hab hbc => (mem_Ico.mp hab).2.not_le (mem_Ico.mp hbc).1 @[simp] theorem Ici_top [OrderTop Ξ±] : Ici (⊀ : Ξ±) = {⊀} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ @[simp] theorem Iic_bot [OrderBot Ξ±] : Iic (βŠ₯ : Ξ±) = {βŠ₯} := Icc_eq_singleton_iff.2 ⟨rfl, rfl⟩ section DecidableEq variable [DecidableEq Ξ±] @[simp] theorem Icc_erase_left (a b : Ξ±) : (Icc a b).erase a = Ioc a b := by simp [← coe_inj] @[simp] theorem Icc_erase_right (a b : Ξ±) : (Icc a b).erase b = Ico a b := by simp [← coe_inj] @[simp] theorem Ico_erase_left (a b : Ξ±) : (Ico a b).erase a = Ioo a b := by simp [← coe_inj] @[simp] theorem Ioc_erase_right (a b : Ξ±) : (Ioc a b).erase b = Ioo a b := by simp [← coe_inj] @[simp] theorem Icc_diff_both (a b : Ξ±) : Icc a b \ {a, b} = Ioo a b := by simp [← coe_inj] @[simp] theorem Ico_insert_right (h : a ≀ b) : insert b (Ico a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Icc, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ico_union_right h] @[simp] theorem Ioc_insert_left (h : a ≀ b) : insert a (Ioc a b) = Icc a b := by rw [← coe_inj, coe_insert, coe_Ioc, coe_Icc, Set.insert_eq, Set.union_comm, Set.Ioc_union_left h] @[simp] theorem Ioo_insert_left (h : a < b) : insert a (Ioo a b) = Ico a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ico, Set.insert_eq, Set.union_comm, Set.Ioo_union_left h] @[simp] theorem Ioo_insert_right (h : a < b) : insert b (Ioo a b) = Ioc a b := by rw [← coe_inj, coe_insert, coe_Ioo, coe_Ioc, Set.insert_eq, Set.union_comm, Set.Ioo_union_right h] @[simp] theorem Icc_diff_Ico_self (h : a ≀ b) : Icc a b \ Ico a b = {b} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioc_self (h : a ≀ b) : Icc a b \ Ioc a b = {a} := by simp [← coe_inj, h] @[simp] theorem Icc_diff_Ioo_self (h : a ≀ b) : Icc a b \ Ioo a b = {a, b} := by simp [← coe_inj, h] @[simp] theorem Ico_diff_Ioo_self (h : a < b) : Ico a b \ Ioo a b = {a} := by simp [← coe_inj, h] @[simp] theorem Ioc_diff_Ioo_self (h : a < b) : Ioc a b \ Ioo a b = {b} := by simp [← coe_inj, h] @[simp] theorem Ico_inter_Ico_consecutive (a b c : Ξ±) : Ico a b ∩ Ico b c = βˆ… := (Ico_disjoint_Ico_consecutive a b c).eq_bot end DecidableEq -- Those lemmas are purposefully the other way around /-- `Finset.cons` version of `Finset.Ico_insert_right`. -/ theorem Icc_eq_cons_Ico (h : a ≀ b) : Icc a b = (Ico a b).cons b right_not_mem_Ico := by classical rw [cons_eq_insert, Ico_insert_right h] /-- `Finset.cons` version of `Finset.Ioc_insert_left`. -/ theorem Icc_eq_cons_Ioc (h : a ≀ b) : Icc a b = (Ioc a b).cons a left_not_mem_Ioc := by classical rw [cons_eq_insert, Ioc_insert_left h] /-- `Finset.cons` version of `Finset.Ioo_insert_right`. -/ theorem Ioc_eq_cons_Ioo (h : a < b) : Ioc a b = (Ioo a b).cons b right_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_right h] /-- `Finset.cons` version of `Finset.Ioo_insert_left`. -/ theorem Ico_eq_cons_Ioo (h : a < b) : Ico a b = (Ioo a b).cons a left_not_mem_Ioo := by classical rw [cons_eq_insert, Ioo_insert_left h] theorem Ico_filter_le_left {a b : Ξ±} [DecidablePred (Β· ≀ a)] (hab : a < b) : {x ∈ Ico a b | x ≀ a} = {a} := by ext x rw [mem_filter, mem_Ico, mem_singleton, and_right_comm, ← le_antisymm_iff, eq_comm] exact and_iff_left_of_imp fun h => h.le.trans_lt hab theorem card_Ico_eq_card_Icc_sub_one (a b : Ξ±) : #(Ico a b) = #(Icc a b) - 1 := by classical by_cases h : a ≀ b Β· rw [Icc_eq_cons_Ico h, card_cons] exact (Nat.add_sub_cancel _ _).symm Β· rw [Ico_eq_empty fun h' => h h'.le, Icc_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioc_eq_card_Icc_sub_one (a b : Ξ±) : #(Ioc a b) = #(Icc a b) - 1 := @card_Ico_eq_card_Icc_sub_one Ξ±α΅’α΅ˆ _ _ _ _ theorem card_Ioo_eq_card_Ico_sub_one (a b : Ξ±) : #(Ioo a b) = #(Ico a b) - 1 := by classical by_cases h : a < b Β· rw [Ico_eq_cons_Ioo h, card_cons] exact (Nat.add_sub_cancel _ _).symm Β· rw [Ioo_eq_empty h, Ico_eq_empty h, card_empty, Nat.zero_sub] theorem card_Ioo_eq_card_Ioc_sub_one (a b : Ξ±) : #(Ioo a b) = #(Ioc a b) - 1 := @card_Ioo_eq_card_Ico_sub_one Ξ±α΅’α΅ˆ _ _ _ _ theorem card_Ioo_eq_card_Icc_sub_two (a b : Ξ±) : #(Ioo a b) = #(Icc a b) - 2 := by rw [card_Ioo_eq_card_Ico_sub_one, card_Ico_eq_card_Icc_sub_one] rfl end PartialOrder section Prod variable {Ξ² : Type*} section sectL lemma uIcc_map_sectL [Lattice Ξ±] [Lattice Ξ²] [LocallyFiniteOrder Ξ±] [LocallyFiniteOrder Ξ²] [DecidableLE (Ξ± Γ— Ξ²)] (a b : Ξ±) (c : Ξ²) : (uIcc a b).map (.sectL _ c) = uIcc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) variable [Preorder Ξ±] [PartialOrder Ξ²] [LocallyFiniteOrder Ξ±] [LocallyFiniteOrder Ξ²] [DecidableLE (Ξ± Γ— Ξ²)] (a b : Ξ±) (c : Ξ²) lemma Icc_map_sectL : (Icc a b).map (.sectL _ c) = Icc (a, c) (b, c) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectL : (Ioc a b).map (.sectL _ c) = Ioc (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectL : (Ico a b).map (.sectL _ c) = Ico (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectL : (Ioo a b).map (.sectL _ c) = Ioo (a, c) (b, c) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectL section sectR lemma uIcc_map_sectR [Lattice Ξ±] [Lattice Ξ²] [LocallyFiniteOrder Ξ±] [LocallyFiniteOrder Ξ²] [DecidableLE (Ξ± Γ— Ξ²)] (c : Ξ±) (a b : Ξ²) : (uIcc a b).map (.sectR c _) = uIcc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) variable [PartialOrder Ξ±] [Preorder Ξ²] [LocallyFiniteOrder Ξ±] [LocallyFiniteOrder Ξ²] [DecidableLE (Ξ± Γ— Ξ²)] (c : Ξ±) (a b : Ξ²) lemma Icc_map_sectR : (Icc a b).map (.sectR c _) = Icc (c, a) (c, b) := by aesop (add safe forward [le_antisymm]) lemma Ioc_map_sectR : (Ioc a b).map (.sectR c _) = Ioc (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ico_map_sectR : (Ico a b).map (.sectR c _) = Ico (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) lemma Ioo_map_sectR : (Ioo a b).map (.sectR c _) = Ioo (c, a) (c, b) := by aesop (add safe forward [le_antisymm, le_of_lt]) end sectR end Prod section BoundedPartialOrder variable [PartialOrder Ξ±] section OrderTop variable [LocallyFiniteOrderTop Ξ±] @[simp] theorem Ici_erase [DecidableEq Ξ±] (a : Ξ±) : (Ici a).erase a = Ioi a := by ext simp_rw [Finset.mem_erase, mem_Ici, mem_Ioi, lt_iff_le_and_ne, and_comm, ne_comm] @[simp] theorem Ioi_insert [DecidableEq Ξ±] (a : Ξ±) : insert a (Ioi a) = Ici a := by ext simp_rw [Finset.mem_insert, mem_Ici, mem_Ioi, le_iff_lt_or_eq, or_comm, eq_comm] theorem not_mem_Ioi_self {b : Ξ±} : b βˆ‰ Ioi b := fun h => lt_irrefl _ (mem_Ioi.1 h) -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Ioi_insert`. -/ theorem Ici_eq_cons_Ioi (a : Ξ±) : Ici a = (Ioi a).cons a not_mem_Ioi_self := by classical rw [cons_eq_insert, Ioi_insert] theorem card_Ioi_eq_card_Ici_sub_one (a : Ξ±) : #(Ioi a) = #(Ici a) - 1 := by rw [Ici_eq_cons_Ioi, card_cons, Nat.add_sub_cancel_right] end OrderTop section OrderBot variable [LocallyFiniteOrderBot Ξ±] @[simp] theorem Iic_erase [DecidableEq Ξ±] (b : Ξ±) : (Iic b).erase b = Iio b := by ext simp_rw [Finset.mem_erase, mem_Iic, mem_Iio, lt_iff_le_and_ne, and_comm] @[simp] theorem Iio_insert [DecidableEq Ξ±] (b : Ξ±) : insert b (Iio b) = Iic b := by ext simp_rw [Finset.mem_insert, mem_Iic, mem_Iio, le_iff_lt_or_eq, or_comm] theorem not_mem_Iio_self {b : Ξ±} : b βˆ‰ Iio b := fun h => lt_irrefl _ (mem_Iio.1 h) -- Purposefully written the other way around /-- `Finset.cons` version of `Finset.Iio_insert`. -/ theorem Iic_eq_cons_Iio (b : Ξ±) : Iic b = (Iio b).cons b not_mem_Iio_self := by classical rw [cons_eq_insert, Iio_insert] theorem card_Iio_eq_card_Iic_sub_one (a : Ξ±) : #(Iio a) = #(Iic a) - 1 := by rw [Iic_eq_cons_Iio, card_cons, Nat.add_sub_cancel_right] end OrderBot end BoundedPartialOrder section SemilatticeSup variable [SemilatticeSup Ξ±] [LocallyFiniteOrderBot Ξ±] -- TODO: Why does `id_eq` simplify the LHS here but not the LHS of `Finset.sup_Iic`? lemma sup'_Iic (a : Ξ±) : (Iic a).sup' nonempty_Iic id = a := le_antisymm (sup'_le _ _ fun _ ↦ mem_Iic.1) <| le_sup' (f := id) <| mem_Iic.2 <| le_refl a @[simp] lemma sup_Iic [OrderBot Ξ±] (a : Ξ±) : (Iic a).sup id = a := le_antisymm (Finset.sup_le fun _ ↦ mem_Iic.1) <| le_sup (f := id) <| mem_Iic.2 <| le_refl a lemma image_subset_Iic_sup [OrderBot Ξ±] [DecidableEq Ξ±] (f : ΞΉ β†’ Ξ±) (s : Finset ΞΉ) : s.image f βŠ† Iic (s.sup f) := by refine fun i hi ↦ mem_Iic.2 ?_ obtain ⟨j, hj, rfl⟩ := mem_image.1 hi exact le_sup hj lemma subset_Iic_sup_id [OrderBot Ξ±] (s : Finset Ξ±) : s βŠ† Iic (s.sup id) := fun _ h ↦ mem_Iic.2 <| le_sup (f := id) h end SemilatticeSup section SemilatticeInf variable [SemilatticeInf Ξ±] [LocallyFiniteOrderTop Ξ±] lemma inf'_Ici (a : Ξ±) : (Ici a).inf' nonempty_Ici id = a := ge_antisymm (le_inf' _ _ fun _ ↦ mem_Ici.1) <| inf'_le (f := id) <| mem_Ici.2 <| le_refl a @[simp] lemma inf_Ici [OrderTop Ξ±] (a : Ξ±) : (Ici a).inf id = a := le_antisymm (inf_le (f := id) <| mem_Ici.2 <| le_refl a) <| Finset.le_inf fun _ ↦ mem_Ici.1 end SemilatticeInf section LinearOrder variable [LinearOrder Ξ±] section LocallyFiniteOrder variable [LocallyFiniteOrder Ξ±] theorem Ico_subset_Ico_iff {a₁ b₁ aβ‚‚ bβ‚‚ : Ξ±} (h : a₁ < b₁) : Ico a₁ b₁ βŠ† Ico aβ‚‚ bβ‚‚ ↔ aβ‚‚ ≀ a₁ ∧ b₁ ≀ bβ‚‚ := by rw [← coe_subset, coe_Ico, coe_Ico, Set.Ico_subset_Ico_iff h] theorem Ico_union_Ico_eq_Ico {a b c : Ξ±} (hab : a ≀ b) (hbc : b ≀ c) : Ico a b βˆͺ Ico b c = Ico a c := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico_eq_Ico hab hbc] @[simp] theorem Ioc_union_Ioc_eq_Ioc {a b c : Ξ±} (h₁ : a ≀ b) (hβ‚‚ : b ≀ c) : Ioc a b βˆͺ Ioc b c = Ioc a c := by rw [← coe_inj, coe_union, coe_Ioc, coe_Ioc, coe_Ioc, Set.Ioc_union_Ioc_eq_Ioc h₁ hβ‚‚] theorem Ico_subset_Ico_union_Ico {a b c : Ξ±} : Ico a c βŠ† Ico a b βˆͺ Ico b c := by rw [← coe_subset, coe_union, coe_Ico, coe_Ico, coe_Ico] exact Set.Ico_subset_Ico_union_Ico theorem Ico_union_Ico' {a b c d : Ξ±} (hcb : c ≀ b) (had : a ≀ d) : Ico a b βˆͺ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico' hcb had] theorem Ico_union_Ico {a b c d : Ξ±} (h₁ : min a b ≀ max c d) (hβ‚‚ : min c d ≀ max a b) : Ico a b βˆͺ Ico c d = Ico (min a c) (max b d) := by rw [← coe_inj, coe_union, coe_Ico, coe_Ico, coe_Ico, Set.Ico_union_Ico h₁ hβ‚‚]
Mathlib/Order/Interval/Finset/Basic.lean
842
845
theorem Ico_inter_Ico {a b c d : α} : Ico a b ∩ Ico c d = Ico (max a c) (min b d) := by
rw [← coe_inj, coe_inter, coe_Ico, coe_Ico, coe_Ico, Set.Ico_inter_Ico] theorem Ioc_inter_Ioc {a b c d : Ξ±} : Ioc a b ∩ Ioc c d = Ioc (max a c) (min b d) := by
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine /-! # Right-angled triangles This file proves basic geometrical results about distances and angles in (possibly degenerate) right-angled triangles in real inner product spaces and Euclidean affine spaces. ## Implementation notes Results in this file are generally given in a form with only those non-degeneracy conditions needed for the particular result, rather than requiring affine independence of the points of a triangle unnecessarily. ## References * https://en.wikipedia.org/wiki/Pythagorean_theorem -/ noncomputable section open scoped EuclideanGeometry open scoped Real open scoped RealInnerProductSpace namespace InnerProductGeometry variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] /-- Pythagorean theorem, if-and-only-if vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– ↔ angle x y = Ο€ / 2 := by rw [norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y /-- Pythagorean theorem, vector angle form. -/ theorem norm_add_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = Ο€ / 2) : β€–x + yβ€– * β€–x + yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– := (norm_add_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h /-- Pythagorean theorem, subtracting vectors, if-and-only-if vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two (x y : V) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– ↔ angle x y = Ο€ / 2 := by rw [norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero] exact inner_eq_zero_iff_angle_eq_pi_div_two x y /-- Pythagorean theorem, subtracting vectors, vector angle form. -/ theorem norm_sub_sq_eq_norm_sq_add_norm_sq' (x y : V) (h : angle x y = Ο€ / 2) : β€–x - yβ€– * β€–x - yβ€– = β€–xβ€– * β€–xβ€– + β€–yβ€– * β€–yβ€– := (norm_sub_sq_eq_norm_sq_add_norm_sq_iff_angle_eq_pi_div_two x y).2 h /-- An angle in a right-angled triangle expressed using `arccos`. -/ theorem angle_add_eq_arccos_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : angle x (x + y) = Real.arccos (β€–xβ€– / β€–x + yβ€–) := by rw [angle, inner_add_right, h, add_zero, real_inner_self_eq_norm_mul_norm] by_cases hx : β€–xβ€– = 0; Β· simp [hx] rw [div_mul_eq_div_div, mul_self_div_self] /-- An angle in a right-angled triangle expressed using `arcsin`. -/ theorem angle_add_eq_arcsin_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0 ∨ y β‰  0) : angle x (x + y) = Real.arcsin (β€–yβ€– / β€–x + yβ€–) := by have hxy : β€–x + yβ€– ^ 2 β‰  0 := by rw [pow_two, norm_add_sq_eq_norm_sq_add_norm_sq_real h, ne_comm] refine ne_of_lt ?_ rcases h0 with (h0 | h0) Β· exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) Β· exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_eq_arcsin (div_nonneg (norm_nonneg _) (norm_nonneg _)), div_pow, one_sub_div hxy] nth_rw 1 [pow_two] rw [norm_add_sq_eq_norm_sq_add_norm_sq_real h, pow_two, add_sub_cancel_left, ← pow_two, ← div_pow, Real.sqrt_sq (div_nonneg (norm_nonneg _) (norm_nonneg _))] /-- An angle in a right-angled triangle expressed using `arctan`. -/ theorem angle_add_eq_arctan_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0) : angle x (x + y) = Real.arctan (β€–yβ€– / β€–xβ€–) := by rw [angle_add_eq_arcsin_of_inner_eq_zero h (Or.inl h0), Real.arctan_eq_arcsin, ← div_mul_eq_div_div, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] nth_rw 3 [← Real.sqrt_sq (norm_nonneg x)] rw_mod_cast [← Real.sqrt_mul (sq_nonneg _), div_pow, pow_two, pow_two, mul_add, mul_one, mul_div, mul_comm (β€–xβ€– * β€–xβ€–), ← mul_div, div_self (mul_self_pos.2 (norm_ne_zero_iff.2 h0)).ne', mul_one] /-- An angle in a non-degenerate right-angled triangle is positive. -/ theorem angle_add_pos_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x = 0 ∨ y β‰  0) : 0 < angle x (x + y) := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_pos, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] by_cases hx : x = 0; Β· simp [hx] rw [div_lt_one (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 hx)) (mul_self_nonneg _))), Real.lt_sqrt (norm_nonneg _), pow_two] simpa [hx] using h0 /-- An angle in a right-angled triangle is at most `Ο€ / 2`. -/ theorem angle_add_le_pi_div_two_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : angle x (x + y) ≀ Ο€ / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_le_pi_div_two] exact div_nonneg (norm_nonneg _) (norm_nonneg _) /-- An angle in a non-degenerate right-angled triangle is less than `Ο€ / 2`. -/ theorem angle_add_lt_pi_div_two_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0) : angle x (x + y) < Ο€ / 2 := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.arccos_lt_pi_div_two, norm_add_eq_sqrt_iff_real_inner_eq_zero.2 h] exact div_pos (norm_pos_iff.2 h0) (Real.sqrt_pos.2 (Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _))) /-- The cosine of an angle in a right-angled triangle as a ratio of sides. -/ theorem cos_angle_add_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : Real.cos (angle x (x + y)) = β€–xβ€– / β€–x + yβ€– := by rw [angle_add_eq_arccos_of_inner_eq_zero h, Real.cos_arccos (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_leβ‚€ _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_right (mul_self_nonneg _) /-- The sine of an angle in a right-angled triangle as a ratio of sides. -/ theorem sin_angle_add_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0 ∨ y β‰  0) : Real.sin (angle x (x + y)) = β€–yβ€– / β€–x + yβ€– := by rw [angle_add_eq_arcsin_of_inner_eq_zero h h0, Real.sin_arcsin (le_trans (by norm_num) (div_nonneg (norm_nonneg _) (norm_nonneg _))) (div_le_one_of_leβ‚€ _ (norm_nonneg _))] rw [mul_self_le_mul_self_iff (norm_nonneg _) (norm_nonneg _), norm_add_sq_eq_norm_sq_add_norm_sq_real h] exact le_add_of_nonneg_left (mul_self_nonneg _) /-- The tangent of an angle in a right-angled triangle as a ratio of sides. -/ theorem tan_angle_add_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : Real.tan (angle x (x + y)) = β€–yβ€– / β€–xβ€– := by by_cases h0 : x = 0; Β· simp [h0] rw [angle_add_eq_arctan_of_inner_eq_zero h h0, Real.tan_arctan] /-- The cosine of an angle in a right-angled triangle multiplied by the hypotenuse equals the adjacent side. -/ theorem cos_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : Real.cos (angle x (x + y)) * β€–x + yβ€– = β€–xβ€– := by rw [cos_angle_add_of_inner_eq_zero h] by_cases hxy : β€–x + yβ€– = 0 Β· have h' := norm_add_sq_eq_norm_sq_add_norm_sq_real h rw [hxy, zero_mul, eq_comm, add_eq_zero_iff_of_nonneg (mul_self_nonneg β€–xβ€–) (mul_self_nonneg β€–yβ€–), mul_self_eq_zero] at h' simp [h'.1] Β· exact div_mul_cancelβ‚€ _ hxy /-- The sine of an angle in a right-angled triangle multiplied by the hypotenuse equals the opposite side. -/ theorem sin_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : Real.sin (angle x (x + y)) * β€–x + yβ€– = β€–yβ€– := by by_cases h0 : x = 0 ∧ y = 0; Β· simp [h0] rw [not_and_or] at h0 rw [sin_angle_add_of_inner_eq_zero h h0, div_mul_cancelβ‚€] rw [← mul_self_ne_zero, norm_add_sq_eq_norm_sq_add_norm_sq_real h] refine (ne_of_lt ?_).symm rcases h0 with (h0 | h0) Β· exact Left.add_pos_of_pos_of_nonneg (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) (mul_self_nonneg _) Β· exact Left.add_pos_of_nonneg_of_pos (mul_self_nonneg _) (mul_self_pos.2 (norm_ne_zero_iff.2 h0)) /-- The tangent of an angle in a right-angled triangle multiplied by the adjacent side equals the opposite side. -/ theorem tan_angle_add_mul_norm_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0 ∨ y = 0) : Real.tan (angle x (x + y)) * β€–xβ€– = β€–yβ€– := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) <;> simp [h0] /-- A side of a right-angled triangle divided by the cosine of the adjacent angle equals the hypotenuse. -/ theorem norm_div_cos_angle_add_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0 ∨ y = 0) : β€–xβ€– / Real.cos (angle x (x + y)) = β€–x + yβ€– := by rw [cos_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) Β· rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_rightβ‚€ (norm_ne_zero_iff.2 h0)] Β· simp [h0] /-- A side of a right-angled triangle divided by the sine of the opposite angle equals the hypotenuse. -/ theorem norm_div_sin_angle_add_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x = 0 ∨ y β‰  0) : β€–yβ€– / Real.sin (angle x (x + y)) = β€–x + yβ€– := by rcases h0 with (h0 | h0); Β· simp [h0] rw [sin_angle_add_of_inner_eq_zero h (Or.inr h0), div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_rightβ‚€ (norm_ne_zero_iff.2 h0)] /-- A side of a right-angled triangle divided by the tangent of the opposite angle equals the adjacent side. -/ theorem norm_div_tan_angle_add_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x = 0 ∨ y β‰  0) : β€–yβ€– / Real.tan (angle x (x + y)) = β€–xβ€– := by rw [tan_angle_add_of_inner_eq_zero h] rcases h0 with (h0 | h0) Β· simp [h0] Β· rw [div_div_eq_mul_div, mul_comm, div_eq_mul_inv, mul_inv_cancel_rightβ‚€ (norm_ne_zero_iff.2 h0)] /-- An angle in a right-angled triangle expressed using `arccos`, version subtracting vectors. -/ theorem angle_sub_eq_arccos_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : angle x (x - y) = Real.arccos (β€–xβ€– / β€–x - yβ€–) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arccos_of_inner_eq_zero h] /-- An angle in a right-angled triangle expressed using `arcsin`, version subtracting vectors. -/ theorem angle_sub_eq_arcsin_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0 ∨ y β‰  0) : angle x (x - y) = Real.arcsin (β€–yβ€– / β€–x - yβ€–) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [or_comm, ← neg_ne_zero, or_comm] at h0 rw [sub_eq_add_neg, angle_add_eq_arcsin_of_inner_eq_zero h h0, norm_neg] /-- An angle in a right-angled triangle expressed using `arctan`, version subtracting vectors. -/ theorem angle_sub_eq_arctan_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x β‰  0) : angle x (x - y) = Real.arctan (β€–yβ€– / β€–xβ€–) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg, angle_add_eq_arctan_of_inner_eq_zero h h0, norm_neg] /-- An angle in a non-degenerate right-angled triangle is positive, version subtracting vectors. -/ theorem angle_sub_pos_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) (h0 : x = 0 ∨ y β‰  0) : 0 < angle x (x - y) := by rw [← neg_eq_zero, ← inner_neg_right] at h rw [← neg_ne_zero] at h0 rw [sub_eq_add_neg] exact angle_add_pos_of_inner_eq_zero h h0 /-- An angle in a right-angled triangle is at most `Ο€ / 2`, version subtracting vectors. -/
Mathlib/Geometry/Euclidean/Angle/Unoriented/RightAngle.lean
232
236
theorem angle_sub_le_pi_div_two_of_inner_eq_zero {x y : V} (h : βŸͺx, y⟫ = 0) : angle x (x - y) ≀ Ο€ / 2 := by
rw [← neg_eq_zero, ← inner_neg_right] at h rw [sub_eq_add_neg] exact angle_add_le_pi_div_two_of_inner_eq_zero h
/- Copyright (c) 2024 Thomas Browning, Junyan Xu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning, Junyan Xu -/ import Mathlib.Algebra.Group.Subgroup.Ker import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.GroupTheory.GroupAction.FixedPoints import Mathlib.GroupTheory.Perm.Support import Mathlib.Data.Set.Finite.Basic /-! # Subgroups generated by transpositions This file studies subgroups generated by transpositions. ## Main results - `swap_mem_closure_isSwap` : If a subgroup is generated by transpositions, then a transposition `swap x y` lies in the subgroup if and only if `x` lies in the same orbit as `y`. - `mem_closure_isSwap` : If a subgroup is generated by transpositions, then a permutation `f` lies in the subgroup if and only if `f` has finite support and `f x` always lies in the same orbit as `x`. -/ open Equiv List MulAction Pointwise Set Subgroup variable {G Ξ± : Type*} [Group G] [MulAction G Ξ±] /-- If the support of each element in a generating set of a permutation group is finite, then the support of every element in the group is finite. -/ theorem finite_compl_fixedBy_closure_iff {S : Set G} : (βˆ€ g ∈ closure S, (fixedBy Ξ± g)ᢜ.Finite) ↔ βˆ€ g ∈ S, (fixedBy Ξ± g)ᢜ.Finite := ⟨fun h g hg ↦ h g (subset_closure hg), fun h g hg ↦ by refine closure_induction h (by simp) (fun g g' _ _ hg hg' ↦ (hg.union hg').subset ?_) (by simp) hg simp_rw [← compl_inter, compl_subset_compl, fixedBy_mul]⟩ /-- Given a symmetric generating set of a permutation group, if T is a nonempty proper subset of an orbit, then there exists a generator that sends some element of T into the complement of T. -/ theorem exists_smul_not_mem_of_subset_orbit_closure (S : Set G) (T : Set Ξ±) {a : Ξ±} (hS : βˆ€ g ∈ S, g⁻¹ ∈ S) (subset : T βŠ† orbit (closure S) a) (not_mem : a βˆ‰ T) (nonempty : T.Nonempty) : βˆƒ Οƒ ∈ S, βˆƒ a ∈ T, Οƒ β€’ a βˆ‰ T := by have key0 : Β¬ closure S ≀ stabilizer G T := by have ⟨b, hb⟩ := nonempty obtain βŸ¨Οƒ, rfl⟩ := subset hb contrapose! not_mem with h exact smul_mem_smul_set_iff.mp ((h Οƒ.2).symm β–Έ hb) contrapose! key0 refine (closure_le _).mpr fun Οƒ hΟƒ ↦ ?_ simp_rw [SetLike.mem_coe, mem_stabilizer_iff, Set.ext_iff, mem_smul_set_iff_inv_smul_mem] exact fun a ↦ ⟨fun h ↦ smul_inv_smul Οƒ a β–Έ key0 Οƒ hΟƒ (σ⁻¹ β€’ a) h, key0 σ⁻¹ (hS Οƒ hΟƒ) a⟩ variable [DecidableEq Ξ±] theorem finite_compl_fixedBy_swap {x y : Ξ±} : (fixedBy Ξ± (swap x y))ᢜ.Finite := Set.Finite.subset (s := {x, y}) (by simp) (compl_subset_comm.mp fun z h ↦ by apply swap_apply_of_ne_of_ne <;> rintro rfl <;> simp at h) theorem Equiv.Perm.IsSwap.finite_compl_fixedBy {Οƒ : Perm Ξ±} (h : Οƒ.IsSwap) : (fixedBy Ξ± Οƒ)ᢜ.Finite := by obtain ⟨x, y, -, rfl⟩ := h exact finite_compl_fixedBy_swap -- this result cannot be moved to Perm/Basic since Perm/Basic is not allowed to import Submonoid theorem SubmonoidClass.swap_mem_trans {a b c : Ξ±} {C} [SetLike C (Perm Ξ±)] [SubmonoidClass C (Perm Ξ±)] (M : C) (hab : swap a b ∈ M) (hbc : swap b c ∈ M) : swap a c ∈ M := by obtain rfl | hab' := eq_or_ne a b Β· exact hbc obtain rfl | hac := eq_or_ne a c Β· exact swap_self a β–Έ one_mem M rw [swap_comm, ← swap_mul_swap_mul_swap hab' hac] exact mul_mem (mul_mem hbc hab) hbc /-- If a subgroup is generated by transpositions, then a transposition `swap x y` lies in the subgroup if and only if `x` lies in the same orbit as `y`. -/ theorem swap_mem_closure_isSwap {S : Set (Perm Ξ±)} (hS : βˆ€ f ∈ S, f.IsSwap) {x y : Ξ±} : swap x y ∈ closure S ↔ x ∈ orbit (closure S) y := by refine ⟨fun h ↦ ⟨⟨swap x y, h⟩, swap_apply_right x y⟩, fun hf ↦ ?_⟩ by_contra h have := exists_smul_not_mem_of_subset_orbit_closure S {x | swap x y ∈ closure S} (fun f hf ↦ ?_) (fun z hz ↦ ?_) h ⟨y, ?_⟩ Β· obtain βŸ¨Οƒ, hΟƒ, a, ha, hΟƒa⟩ := this obtain ⟨z, w, hzw, rfl⟩ := hS Οƒ hΟƒ have := ne_of_mem_of_not_mem ha hΟƒa rw [Perm.smul_def, ne_comm, swap_apply_ne_self_iff, and_iff_right hzw] at this refine hΟƒa (SubmonoidClass.swap_mem_trans (closure S) ?_ ha) obtain rfl | rfl := this <;> simpa [swap_comm] using subset_closure hΟƒ Β· obtain ⟨x, y, -, rfl⟩ := hS f hf; rwa [swap_inv] Β· exact orbit_eq_iff.mpr hf β–Έ ⟨⟨swap z y, hz⟩, swap_apply_right z y⟩ Β· rw [mem_setOf, swap_self]; apply one_mem /-- If a subgroup is generated by transpositions, then a permutation `f` lies in the subgroup if and only if `f` has finite support and `f x` always lies in the same orbit as `x`. -/ theorem mem_closure_isSwap {S : Set (Perm Ξ±)} (hS : βˆ€ f ∈ S, f.IsSwap) {f : Perm Ξ±} : f ∈ closure S ↔ (fixedBy Ξ± f)ᢜ.Finite ∧ βˆ€ x, f x ∈ orbit (closure S) x := by refine ⟨fun hf ↦ ⟨?_, fun x ↦ mem_orbit_iff.mpr ⟨⟨f, hf⟩, rfl⟩⟩, ?_⟩ Β· exact finite_compl_fixedBy_closure_iff.mpr (fun f hf ↦ (hS f hf).finite_compl_fixedBy) _ hf rintro ⟨fin, hf⟩ set supp := (fixedBy Ξ± f)ᢜ with supp_eq suffices h : (fixedBy Ξ± f)ᢜ βŠ† supp β†’ f ∈ closure S from h supp_eq.symm.subset clear_value supp; clear supp_eq; revert f apply fin.induction_on .. Β· rintro f - emp; convert (closure S).one_mem; ext; by_contra h; exact emp h rintro a s - - ih f hf supp_subset refine (mul_mem_cancel_left ((swap_mem_closure_isSwap hS).2 (hf a))).1 (ih (fun b ↦ ?_) fun b hb ↦ ?_) Β· rw [Perm.mul_apply, swap_apply_def]; split_ifs with h1 h2 Β· rw [← orbit_eq_iff.mpr (hf b), h1, orbit_eq_iff.mpr (hf a)]; apply mem_orbit_self Β· rw [← orbit_eq_iff.mpr (hf b), h2]; apply hf Β· exact hf b Β· contrapose! hb simp_rw [not_mem_compl_iff, mem_fixedBy, Perm.smul_def, Perm.mul_apply, swap_apply_def, apply_eq_iff_eq] by_cases hb' : f b = b Β· rw [hb']; split_ifs with h <;> simp only [h] simp [show b = a by simpa [hb] using supp_subset hb'] /-- A permutation is a product of transpositions if and only if it has finite support. -/ theorem mem_closure_isSwap' {f : Perm Ξ±} : f ∈ closure {Οƒ : Perm Ξ± | Οƒ.IsSwap} ↔ (fixedBy Ξ± f)ᢜ.Finite := by refine (mem_closure_isSwap fun _ ↦ id).trans (and_iff_left fun x ↦ ⟨⟨swap x (f x), ?_⟩, swap_apply_left x (f x)⟩) by_cases h : x = f x Β· rw [← h, swap_self] apply Subgroup.one_mem Β· exact subset_closure ⟨x, f x, h, rfl⟩ /-- A transitive permutation group generated by transpositions must be the whole symmetric group -/
Mathlib/GroupTheory/Perm/ClosureSwap.lean
132
138
theorem closure_of_isSwap_of_isPretransitive [Finite Ξ±] {S : Set (Perm Ξ±)} (hS : βˆ€ Οƒ ∈ S, Οƒ.IsSwap) [MulAction.IsPretransitive (Subgroup.closure S) Ξ±] : Subgroup.closure S = ⊀ := by
simp [eq_top_iff', mem_closure_isSwap hS, orbit_eq_univ, Set.toFinite] /-- A transitive permutation group generated by transpositions must be the whole symmetric group -/ theorem surjective_of_isSwap_of_isPretransitive [Finite Ξ±] (S : Set G) (hS1 : βˆ€ Οƒ ∈ S, Perm.IsSwap (MulAction.toPermHom G Ξ± Οƒ)) (hS2 : Subgroup.closure S = ⊀)
/- Copyright (c) 2024 Miyahara Kō. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Miyahara Kō -/ import Mathlib.Algebra.Order.Group.Nat import Mathlib.Data.List.Defs import Mathlib.Data.Set.Function /-! # iterate Proves various lemmas about `List.iterate`. -/ variable {α : Type*} namespace List @[simp]
Mathlib/Data/List/Iterate.lean
21
22
theorem length_iterate (f : Ξ± β†’ Ξ±) (a : Ξ±) (n : β„•) : length (iterate f a n) = n := by
induction n generalizing a <;> simp [*]
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle SΓΆnne, SΓ©bastien GouΓ«zel, RΓ©my Degenne, David Loeffler -/ import Mathlib.Analysis.SpecialFunctions.Pow.Real /-! # Power function on `ℝβ‰₯0` and `ℝβ‰₯0∞` We construct the power functions `x ^ y` where * `x` is a nonnegative real number and `y` is a real number; * `x` is a number from `[0, +∞]` (a.k.a. `ℝβ‰₯0∞`) and `y` is a real number. We also prove basic properties of these functions. -/ noncomputable section open Real NNReal ENNReal ComplexConjugate Finset Function Set namespace NNReal variable {x : ℝβ‰₯0} {w y z : ℝ} /-- The nonnegative real power function `x^y`, defined for `x : ℝβ‰₯0` and `y : ℝ` as the restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`, one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y β‰  0`. -/ noncomputable def rpow (x : ℝβ‰₯0) (y : ℝ) : ℝβ‰₯0 := ⟨(x : ℝ) ^ y, Real.rpow_nonneg x.2 y⟩ noncomputable instance : Pow ℝβ‰₯0 ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0) (y : ℝ) : rpow x y = x ^ y := rfl @[simp, norm_cast] theorem coe_rpow (x : ℝβ‰₯0) (y : ℝ) : ((x ^ y : ℝβ‰₯0) : ℝ) = (x : ℝ) ^ y := rfl @[simp] theorem rpow_zero (x : ℝβ‰₯0) : x ^ (0 : ℝ) = 1 := NNReal.eq <| Real.rpow_zero _ @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y β‰  0 := by rw [← NNReal.coe_inj, coe_rpow, ← NNReal.coe_eq_zero] exact Real.rpow_eq_zero_iff_of_nonneg x.2 lemma rpow_eq_zero (hy : y β‰  0) : x ^ y = 0 ↔ x = 0 := by simp [hy] @[simp] theorem zero_rpow {x : ℝ} (h : x β‰  0) : (0 : ℝβ‰₯0) ^ x = 0 := NNReal.eq <| Real.zero_rpow h @[simp] theorem rpow_one (x : ℝβ‰₯0) : x ^ (1 : ℝ) = x := NNReal.eq <| Real.rpow_one _ lemma rpow_neg (x : ℝβ‰₯0) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := NNReal.eq <| Real.rpow_neg x.2 _ @[simp, norm_cast] lemma rpow_natCast (x : ℝβ‰₯0) (n : β„•) : x ^ (n : ℝ) = x ^ n := NNReal.eq <| by simpa only [coe_rpow, coe_pow] using Real.rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝβ‰₯0) (n : β„€) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0) ^ x = 1 := NNReal.eq <| Real.one_rpow _ theorem rpow_add {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) _ _ theorem rpow_add' (h : y + z β‰  0) (x : ℝβ‰₯0) : x ^ (y + z) = x ^ y * x ^ z := NNReal.eq <| Real.rpow_add' x.2 h lemma rpow_add_intCast (hx : x β‰  0) (y : ℝ) (n : β„€) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast (mod_cast hx) _ _ lemma rpow_add_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast (mod_cast hx) _ _ lemma rpow_sub_intCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast (mod_cast hx) _ _ lemma rpow_sub_natCast (hx : x β‰  0) (y : ℝ) (n : β„•) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast (mod_cast hx) _ _ lemma rpow_add_intCast' {n : β„€} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_intCast' (mod_cast x.2) h lemma rpow_add_natCast' {n : β„•} (h : y + n β‰  0) (x : ℝβ‰₯0) : x ^ (y + n) = x ^ y * x ^ n := by ext; exact Real.rpow_add_natCast' (mod_cast x.2) h lemma rpow_sub_intCast' {n : β„€} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_intCast' (mod_cast x.2) h lemma rpow_sub_natCast' {n : β„•} (h : y - n β‰  0) (x : ℝβ‰₯0) : x ^ (y - n) = x ^ y / x ^ n := by ext; exact Real.rpow_sub_natCast' (mod_cast x.2) h lemma rpow_add_one (hx : x β‰  0) (y : ℝ) : x ^ (y + 1) = x ^ y * x := by simpa using rpow_add_natCast hx y 1 lemma rpow_sub_one (hx : x β‰  0) (y : ℝ) : x ^ (y - 1) = x ^ y / x := by simpa using rpow_sub_natCast hx y 1 lemma rpow_add_one' (h : y + 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y + 1) = x ^ y * x := by rw [rpow_add' h, rpow_one] lemma rpow_one_add' (h : 1 + y β‰  0) (x : ℝβ‰₯0) : x ^ (1 + y) = x * x ^ y := by rw [rpow_add' h, rpow_one] theorem rpow_add_of_nonneg (x : ℝβ‰₯0) {y z : ℝ} (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by ext; exact Real.rpow_add_of_nonneg x.2 hy hz /-- Variant of `NNReal.rpow_add'` that avoids having to prove `y + z = w` twice. -/ lemma rpow_of_add_eq (x : ℝβ‰₯0) (hw : w β‰  0) (h : y + z = w) : x ^ w = x ^ y * x ^ z := by rw [← h, rpow_add']; rwa [h] theorem rpow_mul (x : ℝβ‰₯0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := NNReal.eq <| Real.rpow_mul x.2 y z lemma rpow_natCast_mul (x : ℝβ‰₯0) (n : β„•) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_natCast] lemma rpow_mul_natCast (x : ℝβ‰₯0) (y : ℝ) (n : β„•) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_natCast] lemma rpow_intCast_mul (x : ℝβ‰₯0) (n : β„€) (z : ℝ) : x ^ (n * z) = (x ^ n) ^ z := by rw [rpow_mul, rpow_intCast] lemma rpow_mul_intCast (x : ℝβ‰₯0) (y : ℝ) (n : β„€) : x ^ (y * n) = (x ^ y) ^ n := by rw [rpow_mul, rpow_intCast] theorem rpow_neg_one (x : ℝβ‰₯0) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_sub {x : ℝβ‰₯0} (hx : x β‰  0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub ((NNReal.coe_pos.trans pos_iff_ne_zero).mpr hx) y z theorem rpow_sub' (h : y - z β‰  0) (x : ℝβ‰₯0) : x ^ (y - z) = x ^ y / x ^ z := NNReal.eq <| Real.rpow_sub' x.2 h lemma rpow_sub_one' (h : y - 1 β‰  0) (x : ℝβ‰₯0) : x ^ (y - 1) = x ^ y / x := by rw [rpow_sub' h, rpow_one] lemma rpow_one_sub' (h : 1 - y β‰  0) (x : ℝβ‰₯0) : x ^ (1 - y) = x / x ^ y := by rw [rpow_sub' h, rpow_one] theorem rpow_inv_rpow_self {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ (1 / y) = x := by field_simp [← rpow_mul] theorem rpow_self_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ (1 / y)) ^ y = x := by field_simp [← rpow_mul] theorem inv_rpow (x : ℝβ‰₯0) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := NNReal.eq <| Real.inv_rpow x.2 y theorem div_rpow (x y : ℝβ‰₯0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z := NNReal.eq <| Real.div_rpow x.2 y.2 z theorem sqrt_eq_rpow (x : ℝβ‰₯0) : sqrt x = x ^ (1 / (2 : ℝ)) := by refine NNReal.eq ?_ push_cast exact Real.sqrt_eq_rpow x.1 @[simp] lemma rpow_ofNat (x : ℝβ‰₯0) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n : β„•) := rpow_natCast x n theorem rpow_two (x : ℝβ‰₯0) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow {x y : ℝβ‰₯0} {z : ℝ} : (x * y) ^ z = x ^ z * y ^ z := NNReal.eq <| Real.mul_rpow x.2 y.2 /-- `rpow` as a `MonoidHom` -/ @[simps] def rpowMonoidHom (r : ℝ) : ℝβ‰₯0 β†’* ℝβ‰₯0 where toFun := (Β· ^ r) map_one' := one_rpow _ map_mul' _x _y := mul_rpow /-- `rpow` variant of `List.prod_map_pow` for `ℝβ‰₯0` -/ theorem list_prod_map_rpow (l : List ℝβ‰₯0) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := l.prod_hom (rpowMonoidHom r) theorem list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← list_prod_map_rpow, List.map_map]; rfl /-- `rpow` version of `Multiset.prod_map_pow` for `ℝβ‰₯0`. -/ lemma multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := s.prod_hom' (rpowMonoidHom r) _ /-- `rpow` version of `Finset.prod_pow` for `ℝβ‰₯0`. -/ lemma finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := multiset_prod_map_rpow _ _ _ -- note: these don't really belong here, but they're much easier to prove in terms of the above section Real /-- `rpow` version of `List.prod_map_pow` for `Real`. -/ theorem _root_.Real.list_prod_map_rpow (l : List ℝ) (hl : βˆ€ x ∈ l, (0 : ℝ) ≀ x) (r : ℝ) : (l.map (Β· ^ r)).prod = l.prod ^ r := by lift l to List ℝβ‰₯0 using hl have := congr_arg ((↑) : ℝβ‰₯0 β†’ ℝ) (NNReal.list_prod_map_rpow l r) push_cast at this rw [List.map_map] at this ⊒ exact mod_cast this theorem _root_.Real.list_prod_map_rpow' {ΞΉ} (l : List ΞΉ) (f : ΞΉ β†’ ℝ) (hl : βˆ€ i ∈ l, (0 : ℝ) ≀ f i) (r : ℝ) : (l.map (f Β· ^ r)).prod = (l.map f).prod ^ r := by rw [← Real.list_prod_map_rpow (l.map f) _ r, List.map_map] Β· rfl simpa using hl /-- `rpow` version of `Multiset.prod_map_pow`. -/ theorem _root_.Real.multiset_prod_map_rpow {ΞΉ} (s : Multiset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, (0 : ℝ) ≀ f i) (r : ℝ) : (s.map (f Β· ^ r)).prod = (s.map f).prod ^ r := by induction' s using Quotient.inductionOn with l simpa using Real.list_prod_map_rpow' l f hs r /-- `rpow` version of `Finset.prod_pow`. -/ theorem _root_.Real.finset_prod_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝ) (hs : βˆ€ i ∈ s, 0 ≀ f i) (r : ℝ) : (∏ i ∈ s, f i ^ r) = (∏ i ∈ s, f i) ^ r := Real.multiset_prod_map_rpow s.val f hs r end Real @[gcongr] theorem rpow_le_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := Real.rpow_le_rpow x.2 h₁ hβ‚‚ @[gcongr] theorem rpow_lt_rpow {x y : ℝβ‰₯0} {z : ℝ} (h₁ : x < y) (hβ‚‚ : 0 < z) : x ^ z < y ^ z := Real.rpow_lt_rpow x.2 h₁ hβ‚‚ theorem rpow_lt_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := Real.rpow_lt_rpow_iff x.2 y.2 hz theorem rpow_le_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := Real.rpow_le_rpow_iff x.2 y.2 hz theorem le_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem rpow_inv_le_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by rw [← rpow_le_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz.ne'] theorem lt_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^z < y := by simp only [← not_le, rpow_inv_le_iff hz] theorem rpow_inv_lt_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] section variable {y : ℝβ‰₯0} lemma rpow_lt_rpow_of_neg (hx : 0 < x) (hxy : x < y) (hz : z < 0) : y ^ z < x ^ z := Real.rpow_lt_rpow_of_neg hx hxy hz lemma rpow_le_rpow_of_nonpos (hx : 0 < x) (hxy : x ≀ y) (hz : z ≀ 0) : y ^ z ≀ x ^ z := Real.rpow_le_rpow_of_nonpos hx hxy hz lemma rpow_lt_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z < y ^ z ↔ y < x := Real.rpow_lt_rpow_iff_of_neg hx hy hz lemma rpow_le_rpow_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z ≀ y ^ z ↔ y ≀ x := Real.rpow_le_rpow_iff_of_neg hx hy hz lemma le_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := Real.le_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_le_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := Real.rpow_inv_le_iff_of_pos x.2 hy hz lemma lt_rpow_inv_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x < y ^ z⁻¹ ↔ x ^ z < y := Real.lt_rpow_inv_iff_of_pos x.2 hy hz lemma rpow_inv_lt_iff_of_pos (hy : 0 ≀ y) (hz : 0 < z) (x : ℝβ‰₯0) : x ^ z⁻¹ < y ↔ x < y ^ z := Real.rpow_inv_lt_iff_of_pos x.2 hy hz lemma le_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ≀ y ^ z⁻¹ ↔ y ≀ x ^ z := Real.le_rpow_inv_iff_of_neg hx hy hz lemma lt_rpow_inv_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x < y ^ z⁻¹ ↔ y < x ^ z := Real.lt_rpow_inv_iff_of_neg hx hy hz lemma rpow_inv_lt_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ < y ↔ y ^ z < x := Real.rpow_inv_lt_iff_of_neg hx hy hz lemma rpow_inv_le_iff_of_neg (hx : 0 < x) (hy : 0 < y) (hz : z < 0) : x ^ z⁻¹ ≀ y ↔ y ^ z ≀ x := Real.rpow_inv_le_iff_of_neg hx hy hz end @[gcongr] theorem rpow_lt_rpow_of_exponent_lt {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_lt hx hyz @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝβ‰₯0} {y z : ℝ} (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := Real.rpow_le_rpow_of_exponent_le hx hyz theorem rpow_lt_rpow_of_exponent_gt {x : ℝβ‰₯0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := Real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz theorem rpow_le_rpow_of_exponent_ge {x : ℝβ‰₯0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := Real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz theorem rpow_pos {p : ℝ} {x : ℝβ‰₯0} (hx_pos : 0 < x) : 0 < x ^ p := by have rpow_pos_of_nonneg : βˆ€ {p : ℝ}, 0 < p β†’ 0 < x ^ p := by intro p hp_pos rw [← zero_rpow hp_pos.ne'] exact rpow_lt_rpow hx_pos hp_pos rcases lt_trichotomy (0 : ℝ) p with (hp_pos | rfl | hp_neg) Β· exact rpow_pos_of_nonneg hp_pos Β· simp only [zero_lt_one, rpow_zero] Β· rw [← neg_neg p, rpow_neg, inv_pos] exact rpow_pos_of_nonneg (neg_pos.mpr hp_neg) theorem rpow_lt_one {x : ℝβ‰₯0} {z : ℝ} (hx1 : x < 1) (hz : 0 < z) : x ^ z < 1 := Real.rpow_lt_one (coe_nonneg x) hx1 hz theorem rpow_le_one {x : ℝβ‰₯0} {z : ℝ} (hx2 : x ≀ 1) (hz : 0 ≀ z) : x ^ z ≀ 1 := Real.rpow_le_one x.2 hx2 hz theorem rpow_lt_one_of_one_lt_of_neg {x : ℝβ‰₯0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x ^ z < 1 := Real.rpow_lt_one_of_one_lt_of_neg hx hz theorem rpow_le_one_of_one_le_of_nonpos {x : ℝβ‰₯0} {z : ℝ} (hx : 1 ≀ x) (hz : z ≀ 0) : x ^ z ≀ 1 := Real.rpow_le_one_of_one_le_of_nonpos hx hz theorem one_lt_rpow {x : ℝβ‰₯0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x ^ z := Real.one_lt_rpow hx hz theorem one_le_rpow {x : ℝβ‰₯0} {z : ℝ} (h : 1 ≀ x) (h₁ : 0 ≀ z) : 1 ≀ x ^ z := Real.one_le_rpow h h₁ theorem one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝβ‰₯0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) : 1 < x ^ z := Real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz theorem one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝβ‰₯0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≀ 1) (hz : z ≀ 0) : 1 ≀ x ^ z := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz theorem rpow_le_self_of_le_one {x : ℝβ‰₯0} {z : ℝ} (hx : x ≀ 1) (h_one_le : 1 ≀ z) : x ^ z ≀ x := by rcases eq_bot_or_bot_lt x with (rfl | (h : 0 < x)) Β· have : z β‰  0 := by linarith simp [this] nth_rw 2 [← NNReal.rpow_one x] exact NNReal.rpow_le_rpow_of_exponent_ge h hx h_one_le theorem rpow_left_injective {x : ℝ} (hx : x β‰  0) : Function.Injective fun y : ℝβ‰₯0 => y ^ x := fun y z hyz => by simpa only [rpow_inv_rpow_self hx] using congr_arg (fun y => y ^ (1 / x)) hyz theorem rpow_eq_rpow_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x ^ z = y ^ z ↔ x = y := (rpow_left_injective hz).eq_iff theorem rpow_left_surjective {x : ℝ} (hx : x β‰  0) : Function.Surjective fun y : ℝβ‰₯0 => y ^ x := fun y => ⟨y ^ x⁻¹, by simp_rw [← rpow_mul, inv_mul_cancelβ‚€ hx, rpow_one]⟩ theorem rpow_left_bijective {x : ℝ} (hx : x β‰  0) : Function.Bijective fun y : ℝβ‰₯0 => y ^ x := ⟨rpow_left_injective hx, rpow_left_surjective hx⟩ theorem eq_rpow_inv_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x = y ^ z⁻¹ ↔ x ^ z = y := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] theorem rpow_inv_eq_iff {x y : ℝβ‰₯0} {z : ℝ} (hz : z β‰  0) : x ^ z⁻¹ = y ↔ x = y ^ z := by rw [← rpow_eq_rpow_iff hz, ← one_div, rpow_self_rpow_inv hz] @[simp] lemma rpow_rpow_inv {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y) ^ y⁻¹ = x := by rw [← rpow_mul, mul_inv_cancelβ‚€ hy, rpow_one] @[simp] lemma rpow_inv_rpow {y : ℝ} (hy : y β‰  0) (x : ℝβ‰₯0) : (x ^ y⁻¹) ^ y = x := by rw [← rpow_mul, inv_mul_cancelβ‚€ hy, rpow_one] theorem pow_rpow_inv_natCast (x : ℝβ‰₯0) {n : β„•} (hn : n β‰  0) : (x ^ n) ^ (n⁻¹ : ℝ) = x := by rw [← NNReal.coe_inj, coe_rpow, NNReal.coe_pow] exact Real.pow_rpow_inv_natCast x.2 hn theorem rpow_inv_natCast_pow (x : ℝβ‰₯0) {n : β„•} (hn : n β‰  0) : (x ^ (n⁻¹ : ℝ)) ^ n = x := by rw [← NNReal.coe_inj, NNReal.coe_pow, coe_rpow] exact Real.rpow_inv_natCast_pow x.2 hn theorem _root_.Real.toNNReal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) : Real.toNNReal (x ^ y) = Real.toNNReal x ^ y := by nth_rw 1 [← Real.coe_toNNReal x hx] rw [← NNReal.coe_rpow, Real.toNNReal_coe] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝβ‰₯0 => x ^ z := fun x y hxy => by simp only [NNReal.rpow_lt_rpow hxy h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≀ z) : Monotone fun x : ℝβ‰₯0 => x ^ z := h.eq_or_lt.elim (fun h0 => h0 β–Έ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝβ‰₯0 => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝβ‰₯0 => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝβ‰₯0 ≃o ℝβ‰₯0 := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_eq (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div]; rfl theorem _root_.Real.nnnorm_rpow_of_nonneg {x y : ℝ} (hx : 0 ≀ x) : β€–x ^ yβ€–β‚Š = β€–xβ€–β‚Š ^ y := by ext; exact Real.norm_rpow_of_nonneg hx end NNReal namespace ENNReal /-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝβ‰₯0∞` and `y : ℝ` as the restriction of the real power function if `0 < x < ⊀`, and with the natural values for `0` and `⊀` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊀` for `x < 0`, and `⊀ ^ x = 1 / 0 ^ x`). -/ noncomputable def rpow : ℝβ‰₯0∞ β†’ ℝ β†’ ℝβ‰₯0∞ | some x, y => if x = 0 ∧ y < 0 then ⊀ else (x ^ y : ℝβ‰₯0) | none, y => if 0 < y then ⊀ else if y = 0 then 1 else 0 noncomputable instance : Pow ℝβ‰₯0∞ ℝ := ⟨rpow⟩ @[simp] theorem rpow_eq_pow (x : ℝβ‰₯0∞) (y : ℝ) : rpow x y = x ^ y := rfl @[simp] theorem rpow_zero {x : ℝβ‰₯0∞} : x ^ (0 : ℝ) = 1 := by cases x <;> Β· dsimp only [(Β· ^ Β·), Pow.pow, rpow] simp [lt_irrefl] theorem top_rpow_def (y : ℝ) : (⊀ : ℝβ‰₯0∞) ^ y = if 0 < y then ⊀ else if y = 0 then 1 else 0 := rfl @[simp] theorem top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊀ : ℝβ‰₯0∞) ^ y = ⊀ := by simp [top_rpow_def, h] @[simp] theorem top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊀ : ℝβ‰₯0∞) ^ y = 0 := by simp [top_rpow_def, asymm h, ne_of_lt h] @[simp] theorem zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝβ‰₯0∞) ^ y = 0 := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), rpow, Pow.pow] simp [h, asymm h, ne_of_gt h] @[simp] theorem zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝβ‰₯0∞) ^ y = ⊀ := by rw [← ENNReal.coe_zero, ← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), rpow, Pow.pow] simp [h, ne_of_gt h] theorem zero_rpow_def (y : ℝ) : (0 : ℝβ‰₯0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊀ := by rcases lt_trichotomy (0 : ℝ) y with (H | rfl | H) Β· simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] Β· simp [lt_irrefl] Β· simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] @[simp] theorem zero_rpow_mul_self (y : ℝ) : (0 : ℝβ‰₯0∞) ^ y * (0 : ℝβ‰₯0∞) ^ y = (0 : ℝβ‰₯0∞) ^ y := by rw [zero_rpow_def] split_ifs exacts [zero_mul _, one_mul _, top_mul_top] @[norm_cast] theorem coe_rpow_of_ne_zero {x : ℝβ‰₯0} (h : x β‰  0) (y : ℝ) : (↑(x ^ y) : ℝβ‰₯0∞) = x ^ y := by rw [← ENNReal.some_eq_coe] dsimp only [(Β· ^ Β·), Pow.pow, rpow] simp [h] @[norm_cast] theorem coe_rpow_of_nonneg (x : ℝβ‰₯0) {y : ℝ} (h : 0 ≀ y) : ↑(x ^ y) = (x : ℝβ‰₯0∞) ^ y := by by_cases hx : x = 0 Β· rcases le_iff_eq_or_lt.1 h with (H | H) Β· simp [hx, H.symm] Β· simp [hx, zero_rpow_of_pos H, NNReal.zero_rpow (ne_of_gt H)] Β· exact coe_rpow_of_ne_zero hx _ theorem coe_rpow_def (x : ℝβ‰₯0) (y : ℝ) : (x : ℝβ‰₯0∞) ^ y = if x = 0 ∧ y < 0 then ⊀ else ↑(x ^ y) := rfl theorem rpow_ofNNReal {M : ℝβ‰₯0} {P : ℝ} (hP : 0 ≀ P) : (M : ℝβ‰₯0∞) ^ P = ↑(M ^ P) := by rw [ENNReal.coe_rpow_of_nonneg _ hP, ← ENNReal.rpow_eq_pow] @[simp] theorem rpow_one (x : ℝβ‰₯0∞) : x ^ (1 : ℝ) = x := by cases x Β· exact dif_pos zero_lt_one Β· change ite _ _ _ = _ simp only [NNReal.rpow_one, some_eq_coe, ite_eq_right_iff, top_ne_coe, and_imp] exact fun _ => zero_le_one.not_lt @[simp] theorem one_rpow (x : ℝ) : (1 : ℝβ‰₯0∞) ^ x = 1 := by rw [← coe_one, ← coe_rpow_of_ne_zero one_ne_zero] simp @[simp] theorem rpow_eq_zero_iff {x : ℝβ‰₯0∞} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ 0 < y ∨ x = ⊀ ∧ y < 0 := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] Β· simp [← coe_rpow_of_ne_zero h, h] lemma rpow_eq_zero_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y = 0 ↔ x = 0 := by simp [hy, hy.not_lt] @[simp] theorem rpow_eq_top_iff {x : ℝβ‰₯0∞} {y : ℝ} : x ^ y = ⊀ ↔ x = 0 ∧ y < 0 ∨ x = ⊀ ∧ 0 < y := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] Β· simp [← coe_rpow_of_ne_zero h, h] theorem rpow_eq_top_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊀ ↔ x = ⊀ := by simp [rpow_eq_top_iff, hy, asymm hy] lemma rpow_lt_top_iff_of_pos {x : ℝβ‰₯0∞} {y : ℝ} (hy : 0 < y) : x ^ y < ∞ ↔ x < ∞ := by simp only [lt_top_iff_ne_top, Ne, rpow_eq_top_iff_of_pos hy] theorem rpow_eq_top_of_nonneg (x : ℝβ‰₯0∞) {y : ℝ} (hy0 : 0 ≀ y) : x ^ y = ⊀ β†’ x = ⊀ := by rw [ENNReal.rpow_eq_top_iff] rintro (h|h) Β· exfalso rw [lt_iff_not_ge] at h exact h.right hy0 Β· exact h.left theorem rpow_ne_top_of_nonneg {x : ℝβ‰₯0∞} {y : ℝ} (hy0 : 0 ≀ y) (h : x β‰  ⊀) : x ^ y β‰  ⊀ := mt (ENNReal.rpow_eq_top_of_nonneg x hy0) h theorem rpow_lt_top_of_nonneg {x : ℝβ‰₯0∞} {y : ℝ} (hy0 : 0 ≀ y) (h : x β‰  ⊀) : x ^ y < ⊀ := lt_top_iff_ne_top.mpr (ENNReal.rpow_ne_top_of_nonneg hy0 h) theorem rpow_add {x : ℝβ‰₯0∞} (y z : ℝ) (hx : x β‰  0) (h'x : x β‰  ⊀) : x ^ (y + z) = x ^ y * x ^ z := by cases x with | top => exact (h'x rfl).elim | coe x => have : x β‰  0 := fun h => by simp [h] at hx simp [← coe_rpow_of_ne_zero this, NNReal.rpow_add this] theorem rpow_add_of_nonneg {x : ℝβ‰₯0∞} (y z : ℝ) (hy : 0 ≀ y) (hz : 0 ≀ z) : x ^ (y + z) = x ^ y * x ^ z := by induction x using recTopCoe Β· rcases hy.eq_or_lt with rfl|hy Β· rw [rpow_zero, one_mul, zero_add] rcases hz.eq_or_lt with rfl|hz Β· rw [rpow_zero, mul_one, add_zero] simp [top_rpow_of_pos, hy, hz, add_pos hy hz] simp [← coe_rpow_of_nonneg, hy, hz, add_nonneg hy hz, NNReal.rpow_add_of_nonneg _ hy hz] theorem rpow_neg (x : ℝβ‰₯0∞) (y : ℝ) : x ^ (-y) = (x ^ y)⁻¹ := by cases x with | top => rcases lt_trichotomy y 0 with (H | H | H) <;> simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (H | H | H) <;> simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] Β· have A : x ^ y β‰  0 := by simp [h] simp [← coe_rpow_of_ne_zero h, ← coe_inv A, NNReal.rpow_neg] theorem rpow_sub {x : ℝβ‰₯0∞} (y z : ℝ) (hx : x β‰  0) (h'x : x β‰  ⊀) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv] theorem rpow_neg_one (x : ℝβ‰₯0∞) : x ^ (-1 : ℝ) = x⁻¹ := by simp [rpow_neg] theorem rpow_mul (x : ℝβ‰₯0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z := by cases x with | top => rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] | coe x => by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos, mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] Β· have : x ^ y β‰  0 := by simp [h] simp [← coe_rpow_of_ne_zero, h, this, NNReal.rpow_mul] @[simp, norm_cast] theorem rpow_natCast (x : ℝβ‰₯0∞) (n : β„•) : x ^ (n : ℝ) = x ^ n := by cases x Β· cases n <;> simp [top_rpow_of_pos (Nat.cast_add_one_pos _), top_pow (Nat.succ_ne_zero _)] Β· simp [← coe_rpow_of_nonneg _ (Nat.cast_nonneg n)] @[simp] lemma rpow_ofNat (x : ℝβ‰₯0∞) (n : β„•) [n.AtLeastTwo] : x ^ (ofNat(n) : ℝ) = x ^ (OfNat.ofNat n) := rpow_natCast x n @[simp, norm_cast] lemma rpow_intCast (x : ℝβ‰₯0∞) (n : β„€) : x ^ (n : ℝ) = x ^ n := by cases n <;> simp only [Int.ofNat_eq_coe, Int.cast_natCast, rpow_natCast, zpow_natCast, Int.cast_negSucc, rpow_neg, zpow_negSucc] theorem rpow_two (x : ℝβ‰₯0∞) : x ^ (2 : ℝ) = x ^ 2 := rpow_ofNat x 2 theorem mul_rpow_eq_ite (x y : ℝβ‰₯0∞) (z : ℝ) : (x * y) ^ z = if (x = 0 ∧ y = ⊀ ∨ x = ⊀ ∧ y = 0) ∧ z < 0 then ⊀ else x ^ z * y ^ z := by rcases eq_or_ne z 0 with (rfl | hz); Β· simp replace hz := hz.lt_or_lt wlog hxy : x ≀ y Β· convert this y x z hz (le_of_not_le hxy) using 2 <;> simp only [mul_comm, and_comm, or_comm] rcases eq_or_ne x 0 with (rfl | hx0) Β· induction y <;> rcases hz with hz | hz <;> simp [*, hz.not_lt] rcases eq_or_ne y 0 with (rfl | hy0) Β· exact (hx0 (bot_unique hxy)).elim induction x Β· rcases hz with hz | hz <;> simp [hz, top_unique hxy] induction y Β· rw [ne_eq, coe_eq_zero] at hx0 rcases hz with hz | hz <;> simp [*] simp only [*, if_false] norm_cast at * rw [← coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), NNReal.mul_rpow] norm_cast theorem mul_rpow_of_ne_top {x y : ℝβ‰₯0∞} (hx : x β‰  ⊀) (hy : y β‰  ⊀) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] @[norm_cast] theorem coe_mul_rpow (x y : ℝβ‰₯0) (z : ℝ) : ((x : ℝβ‰₯0∞) * y) ^ z = (x : ℝβ‰₯0∞) ^ z * (y : ℝβ‰₯0∞) ^ z := mul_rpow_of_ne_top coe_ne_top coe_ne_top z theorem prod_coe_rpow {ΞΉ} (s : Finset ΞΉ) (f : ΞΉ β†’ ℝβ‰₯0) (r : ℝ) : ∏ i ∈ s, (f i : ℝβ‰₯0∞) ^ r = ((∏ i ∈ s, f i : ℝβ‰₯0) : ℝβ‰₯0∞) ^ r := by classical induction s using Finset.induction with | empty => simp | insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← coe_mul_rpow, coe_mul] theorem mul_rpow_of_ne_zero {x y : ℝβ‰₯0∞} (hx : x β‰  0) (hy : y β‰  0) (z : ℝ) : (x * y) ^ z = x ^ z * y ^ z := by simp [*, mul_rpow_eq_ite] theorem mul_rpow_of_nonneg (x y : ℝβ‰₯0∞) {z : ℝ} (hz : 0 ≀ z) : (x * y) ^ z = x ^ z * y ^ z := by simp [hz.not_lt, mul_rpow_eq_ite] theorem prod_rpow_of_ne_top {ΞΉ} {s : Finset ΞΉ} {f : ΞΉ β†’ ℝβ‰₯0∞} (hf : βˆ€ i ∈ s, f i β‰  ∞) (r : ℝ) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by classical induction s using Finset.induction with | empty => simp | insert i s hi ih => have h2f : βˆ€ i ∈ s, f i β‰  ∞ := fun i hi ↦ hf i <| mem_insert_of_mem hi rw [prod_insert hi, prod_insert hi, ih h2f, ← mul_rpow_of_ne_top <| hf i <| mem_insert_self ..] apply prod_ne_top h2f theorem prod_rpow_of_nonneg {ΞΉ} {s : Finset ΞΉ} {f : ΞΉ β†’ ℝβ‰₯0∞} {r : ℝ} (hr : 0 ≀ r) : ∏ i ∈ s, f i ^ r = (∏ i ∈ s, f i) ^ r := by classical induction s using Finset.induction with | empty => simp | insert _ _ hi ih => simp_rw [prod_insert hi, ih, ← mul_rpow_of_nonneg _ _ hr] theorem inv_rpow (x : ℝβ‰₯0∞) (y : ℝ) : x⁻¹ ^ y = (x ^ y)⁻¹ := by rcases eq_or_ne y 0 with (rfl | hy); Β· simp only [rpow_zero, inv_one] replace hy := hy.lt_or_lt rcases eq_or_ne x 0 with (rfl | h0); Β· cases hy <;> simp [*] rcases eq_or_ne x ⊀ with (rfl | h_top); Β· cases hy <;> simp [*] apply ENNReal.eq_inv_of_mul_eq_one_left rw [← mul_rpow_of_ne_zero (ENNReal.inv_ne_zero.2 h_top) h0, ENNReal.inv_mul_cancel h0 h_top, one_rpow] theorem div_rpow_of_nonneg (x y : ℝβ‰₯0∞) {z : ℝ} (hz : 0 ≀ z) : (x / y) ^ z = x ^ z / y ^ z := by rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv] theorem strictMono_rpow_of_pos {z : ℝ} (h : 0 < z) : StrictMono fun x : ℝβ‰₯0∞ => x ^ z := by intro x y hxy lift x to ℝβ‰₯0 using ne_top_of_lt hxy rcases eq_or_ne y ∞ with (rfl | hy) Β· simp only [top_rpow_of_pos h, ← coe_rpow_of_nonneg _ h.le, coe_lt_top] Β· lift y to ℝβ‰₯0 using hy simp only [← coe_rpow_of_nonneg _ h.le, NNReal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] theorem monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≀ z) : Monotone fun x : ℝβ‰₯0∞ => x ^ z := h.eq_or_lt.elim (fun h0 => h0 β–Έ by simp only [rpow_zero, monotone_const]) fun h0 => (strictMono_rpow_of_pos h0).monotone /-- Bundles `fun x : ℝβ‰₯0∞ => x ^ y` into an order isomorphism when `y : ℝ` is positive, where the inverse is `fun x : ℝβ‰₯0∞ => x ^ (1 / y)`. -/ @[simps! apply] def orderIsoRpow (y : ℝ) (hy : 0 < y) : ℝβ‰₯0∞ ≃o ℝβ‰₯0∞ := (strictMono_rpow_of_pos hy).orderIsoOfRightInverse (fun x => x ^ y) (fun x => x ^ (1 / y)) fun x => by dsimp rw [← rpow_mul, one_div_mul_cancel hy.ne.symm, rpow_one] theorem orderIsoRpow_symm_apply (y : ℝ) (hy : 0 < y) : (orderIsoRpow y hy).symm = orderIsoRpow (1 / y) (one_div_pos.2 hy) := by simp only [orderIsoRpow, one_div_one_div] rfl @[gcongr] theorem rpow_le_rpow {x y : ℝβ‰₯0∞} {z : ℝ} (h₁ : x ≀ y) (hβ‚‚ : 0 ≀ z) : x ^ z ≀ y ^ z := monotone_rpow_of_nonneg hβ‚‚ h₁ @[gcongr] theorem rpow_lt_rpow {x y : ℝβ‰₯0∞} {z : ℝ} (h₁ : x < y) (hβ‚‚ : 0 < z) : x ^ z < y ^ z := strictMono_rpow_of_pos hβ‚‚ h₁ theorem rpow_le_rpow_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≀ y ^ z ↔ x ≀ y := (strictMono_rpow_of_pos hz).le_iff_le theorem rpow_lt_rpow_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y := (strictMono_rpow_of_pos hz).lt_iff_lt theorem le_rpow_inv_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ≀ y ^ z⁻¹ ↔ x ^ z ≀ y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @mul_inv_cancelβ‚€ _ _ z hz.ne'] rw [rpow_mul, @rpow_le_rpow_iff _ _ z⁻¹ (by simp [hz])] theorem rpow_inv_lt_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ < y ↔ x < y ^ z := by simp only [← not_le, le_rpow_inv_iff hz] theorem lt_rpow_inv_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x < y ^ z⁻¹ ↔ x ^ z < y := by nth_rw 1 [← rpow_one x] nth_rw 1 [← @mul_inv_cancelβ‚€ _ _ z (ne_of_lt hz).symm] rw [rpow_mul, @rpow_lt_rpow_iff _ _ z⁻¹ (by simp [hz])] theorem rpow_inv_le_iff {x y : ℝβ‰₯0∞} {z : ℝ} (hz : 0 < z) : x ^ z⁻¹ ≀ y ↔ x ≀ y ^ z := by nth_rw 1 [← ENNReal.rpow_one y] nth_rw 1 [← @mul_inv_cancelβ‚€ _ _ z hz.ne.symm] rw [ENNReal.rpow_mul, ENNReal.rpow_le_rpow_iff (inv_pos.2 hz)] theorem rpow_lt_rpow_of_exponent_lt {x : ℝβ‰₯0∞} {y z : ℝ} (hx : 1 < x) (hx' : x β‰  ⊀) (hyz : y < z) : x ^ y < x ^ z := by lift x to ℝβ‰₯0 using hx' rw [one_lt_coe_iff] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)), NNReal.rpow_lt_rpow_of_exponent_lt hx hyz] @[gcongr] theorem rpow_le_rpow_of_exponent_le {x : ℝβ‰₯0∞} {y z : ℝ} (hx : 1 ≀ x) (hyz : y ≀ z) : x ^ y ≀ x ^ z := by cases x Β· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl] <;> linarith Β· simp only [one_le_coe_iff, some_eq_coe] at hx simp [← coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)), NNReal.rpow_le_rpow_of_exponent_le hx hyz] theorem rpow_lt_rpow_of_exponent_gt {x : ℝβ‰₯0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) : x ^ y < x ^ z := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_lt_of_le hx1 le_top) simp only [coe_lt_one_iff, coe_pos] at hx0 hx1 simp [← coe_rpow_of_ne_zero (ne_of_gt hx0), NNReal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz] theorem rpow_le_rpow_of_exponent_ge {x : ℝβ‰₯0∞} {y z : ℝ} (hx1 : x ≀ 1) (hyz : z ≀ y) : x ^ y ≀ x ^ z := by lift x to ℝβ‰₯0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top) by_cases h : x = 0 Β· rcases lt_trichotomy y 0 with (Hy | Hy | Hy) <;> rcases lt_trichotomy z 0 with (Hz | Hz | Hz) <;> simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl] <;> linarith Β· rw [coe_le_one_iff] at hx1 simp [← coe_rpow_of_ne_zero h, NNReal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] theorem rpow_le_self_of_le_one {x : ℝβ‰₯0∞} {z : ℝ} (hx : x ≀ 1) (h_one_le : 1 ≀ z) : x ^ z ≀ x := by nth_rw 2 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_ge hx h_one_le theorem le_rpow_self_of_one_le {x : ℝβ‰₯0∞} {z : ℝ} (hx : 1 ≀ x) (h_one_le : 1 ≀ z) : x ≀ x ^ z := by nth_rw 1 [← ENNReal.rpow_one x] exact ENNReal.rpow_le_rpow_of_exponent_le hx h_one_le theorem rpow_pos_of_nonneg {p : ℝ} {x : ℝβ‰₯0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≀ p) : 0 < x ^ p := by by_cases hp_zero : p = 0 Β· simp [hp_zero, zero_lt_one] Β· rw [← Ne] at hp_zero have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm rw [← zero_rpow_of_pos hp_pos] exact rpow_lt_rpow hx_pos hp_pos
Mathlib/Analysis/SpecialFunctions/Pow/NNReal.lean
815
818
theorem rpow_pos {p : ℝ} {x : ℝβ‰₯0∞} (hx_pos : 0 < x) (hx_ne_top : x β‰  ⊀) : 0 < x ^ p := by
rcases lt_or_le 0 p with hp_pos | hp_nonpos Β· exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos) Β· rw [← neg_neg p, rpow_neg, ENNReal.inv_pos]
/- 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 -/ import Aesop import Mathlib.Order.BoundedOrder.Lattice /-! # Disjointness and complements This file defines `Disjoint`, `Codisjoint`, and the `IsCompl` predicate. ## Main declarations * `Disjoint x y`: two elements of a lattice are disjoint if their `inf` is the bottom element. * `Codisjoint x y`: two elements of a lattice are codisjoint if their `join` is the top element. * `IsCompl x y`: In a bounded lattice, predicate for "`x` is a complement of `y`". Note that in a non distributive lattice, an element can have several complements. * `ComplementedLattice Ξ±`: Typeclass stating that any element of a lattice has a complement. -/ open Function variable {Ξ± : Type*} section Disjoint section PartialOrderBot variable [PartialOrder Ξ±] [OrderBot Ξ±] {a b c d : Ξ±} /-- Two elements of a lattice are disjoint if their inf is the bottom element. (This generalizes disjoint sets, viewed as members of the subset lattice.) Note that we define this without reference to `βŠ“`, as this allows us to talk about orders where the infimum is not unique, or where implementing `Inf` would require additional `Decidable` arguments. -/ def Disjoint (a b : Ξ±) : Prop := βˆ€ ⦃x⦄, x ≀ a β†’ x ≀ b β†’ x ≀ βŠ₯ @[simp] theorem disjoint_of_subsingleton [Subsingleton Ξ±] : Disjoint a b := fun x _ _ ↦ le_of_eq (Subsingleton.elim x βŠ₯) theorem disjoint_comm : Disjoint a b ↔ Disjoint b a := forall_congr' fun _ ↦ forall_swap @[symm] theorem Disjoint.symm ⦃a b : α⦄ : Disjoint a b β†’ Disjoint b a := disjoint_comm.1 theorem symmetric_disjoint : Symmetric (Disjoint : Ξ± β†’ Ξ± β†’ Prop) := Disjoint.symm @[simp] theorem disjoint_bot_left : Disjoint βŠ₯ a := fun _ hbot _ ↦ hbot @[simp] theorem disjoint_bot_right : Disjoint a βŠ₯ := fun _ _ hbot ↦ hbot theorem Disjoint.mono (h₁ : a ≀ b) (hβ‚‚ : c ≀ d) : Disjoint b d β†’ Disjoint a c := fun h _ ha hc ↦ h (ha.trans h₁) (hc.trans hβ‚‚) theorem Disjoint.mono_left (h : a ≀ b) : Disjoint b c β†’ Disjoint a c := Disjoint.mono h le_rfl theorem Disjoint.mono_right : b ≀ c β†’ Disjoint a c β†’ Disjoint a b := Disjoint.mono le_rfl @[simp] theorem disjoint_self : Disjoint a a ↔ a = βŠ₯ := ⟨fun hd ↦ bot_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ ha.trans_eq h⟩ /- TODO: Rename `Disjoint.eq_bot` to `Disjoint.inf_eq` and `Disjoint.eq_bot_of_self` to `Disjoint.eq_bot` -/ alias ⟨Disjoint.eq_bot_of_self, _⟩ := disjoint_self theorem Disjoint.ne (ha : a β‰  βŠ₯) (hab : Disjoint a b) : a β‰  b := fun h ↦ ha <| disjoint_self.1 <| by rwa [← h] at hab theorem Disjoint.eq_bot_of_le (hab : Disjoint a b) (h : a ≀ b) : a = βŠ₯ := eq_bot_iff.2 <| hab le_rfl h theorem Disjoint.eq_bot_of_ge (hab : Disjoint a b) : b ≀ a β†’ b = βŠ₯ := hab.symm.eq_bot_of_le lemma Disjoint.eq_iff (hab : Disjoint a b) : a = b ↔ a = βŠ₯ ∧ b = βŠ₯ := by aesop lemma Disjoint.ne_iff (hab : Disjoint a b) : a β‰  b ↔ a β‰  βŠ₯ ∨ b β‰  βŠ₯ := hab.eq_iff.not.trans not_and_or theorem disjoint_of_le_iff_left_eq_bot (h : a ≀ b) : Disjoint a b ↔ a = βŠ₯ := ⟨fun hd ↦ hd.eq_bot_of_le h, fun h ↦ h β–Έ disjoint_bot_left⟩ end PartialOrderBot section PartialBoundedOrder variable [PartialOrder Ξ±] [BoundedOrder Ξ±] {a : Ξ±} @[simp] theorem disjoint_top : Disjoint a ⊀ ↔ a = βŠ₯ := ⟨fun h ↦ bot_unique <| h le_rfl le_top, fun h _ ha _ ↦ ha.trans_eq h⟩ @[simp] theorem top_disjoint : Disjoint ⊀ a ↔ a = βŠ₯ := ⟨fun h ↦ bot_unique <| h le_top le_rfl, fun h _ _ ha ↦ ha.trans_eq h⟩ end PartialBoundedOrder section SemilatticeInfBot variable [SemilatticeInf Ξ±] [OrderBot Ξ±] {a b c : Ξ±} theorem disjoint_iff_inf_le : Disjoint a b ↔ a βŠ“ b ≀ βŠ₯ := ⟨fun hd ↦ hd inf_le_left inf_le_right, fun h _ ha hb ↦ (le_inf ha hb).trans h⟩ theorem disjoint_iff : Disjoint a b ↔ a βŠ“ b = βŠ₯ := disjoint_iff_inf_le.trans le_bot_iff theorem Disjoint.le_bot : Disjoint a b β†’ a βŠ“ b ≀ βŠ₯ := disjoint_iff_inf_le.mp theorem Disjoint.eq_bot : Disjoint a b β†’ a βŠ“ b = βŠ₯ := bot_unique ∘ Disjoint.le_bot theorem disjoint_assoc : Disjoint (a βŠ“ b) c ↔ Disjoint a (b βŠ“ c) := by rw [disjoint_iff_inf_le, disjoint_iff_inf_le, inf_assoc] theorem disjoint_left_comm : Disjoint a (b βŠ“ c) ↔ Disjoint b (a βŠ“ c) := by simp_rw [disjoint_iff_inf_le, inf_left_comm] theorem disjoint_right_comm : Disjoint (a βŠ“ b) c ↔ Disjoint (a βŠ“ c) b := by simp_rw [disjoint_iff_inf_le, inf_right_comm] variable (c) theorem Disjoint.inf_left (h : Disjoint a b) : Disjoint (a βŠ“ c) b := h.mono_left inf_le_left theorem Disjoint.inf_left' (h : Disjoint a b) : Disjoint (c βŠ“ a) b := h.mono_left inf_le_right theorem Disjoint.inf_right (h : Disjoint a b) : Disjoint a (b βŠ“ c) := h.mono_right inf_le_left theorem Disjoint.inf_right' (h : Disjoint a b) : Disjoint a (c βŠ“ b) := h.mono_right inf_le_right variable {c} theorem Disjoint.of_disjoint_inf_of_le (h : Disjoint (a βŠ“ b) c) (hle : a ≀ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_left_le hle theorem Disjoint.of_disjoint_inf_of_le' (h : Disjoint (a βŠ“ b) c) (hle : b ≀ c) : Disjoint a b := disjoint_iff.2 <| h.eq_bot_of_le <| inf_le_of_right_le hle end SemilatticeInfBot theorem Disjoint.right_lt_sup_of_left_ne_bot [SemilatticeSup Ξ±] [OrderBot Ξ±] {a b : Ξ±} (h : Disjoint a b) (ha : a β‰  βŠ₯) : b < a βŠ” b := le_sup_right.lt_of_ne fun eq ↦ ha (le_bot_iff.mp <| h le_rfl <| sup_eq_right.mp eq.symm) section DistribLatticeBot variable [DistribLattice Ξ±] [OrderBot Ξ±] {a b c : Ξ±} @[simp] theorem disjoint_sup_left : Disjoint (a βŠ” b) c ↔ Disjoint a c ∧ Disjoint b c := by simp only [disjoint_iff, inf_sup_right, sup_eq_bot_iff] @[simp] theorem disjoint_sup_right : Disjoint a (b βŠ” c) ↔ Disjoint a b ∧ Disjoint a c := by simp only [disjoint_iff, inf_sup_left, sup_eq_bot_iff] theorem Disjoint.sup_left (ha : Disjoint a c) (hb : Disjoint b c) : Disjoint (a βŠ” b) c := disjoint_sup_left.2 ⟨ha, hb⟩ theorem Disjoint.sup_right (hb : Disjoint a b) (hc : Disjoint a c) : Disjoint a (b βŠ” c) := disjoint_sup_right.2 ⟨hb, hc⟩ theorem Disjoint.left_le_of_le_sup_right (h : a ≀ b βŠ” c) (hd : Disjoint a c) : a ≀ b := le_of_inf_le_sup_le (le_trans hd.le_bot bot_le) <| sup_le h le_sup_right theorem Disjoint.left_le_of_le_sup_left (h : a ≀ c βŠ” b) (hd : Disjoint a c) : a ≀ b := hd.left_le_of_le_sup_right <| by rwa [sup_comm] end DistribLatticeBot end Disjoint section Codisjoint section PartialOrderTop variable [PartialOrder Ξ±] [OrderTop Ξ±] {a b c d : Ξ±} /-- Two elements of a lattice are codisjoint if their sup is the top element. Note that we define this without reference to `βŠ”`, as this allows us to talk about orders where the supremum is not unique, or where implement `Sup` would require additional `Decidable` arguments. -/ def Codisjoint (a b : Ξ±) : Prop := βˆ€ ⦃x⦄, a ≀ x β†’ b ≀ x β†’ ⊀ ≀ x theorem codisjoint_comm : Codisjoint a b ↔ Codisjoint b a := forall_congr' fun _ ↦ forall_swap @[deprecated (since := "2024-11-23")] alias Codisjoint_comm := codisjoint_comm @[symm] theorem Codisjoint.symm ⦃a b : α⦄ : Codisjoint a b β†’ Codisjoint b a := codisjoint_comm.1 theorem symmetric_codisjoint : Symmetric (Codisjoint : Ξ± β†’ Ξ± β†’ Prop) := Codisjoint.symm @[simp] theorem codisjoint_top_left : Codisjoint ⊀ a := fun _ htop _ ↦ htop @[simp] theorem codisjoint_top_right : Codisjoint a ⊀ := fun _ _ htop ↦ htop theorem Codisjoint.mono (h₁ : a ≀ b) (hβ‚‚ : c ≀ d) : Codisjoint a c β†’ Codisjoint b d := fun h _ ha hc ↦ h (h₁.trans ha) (hβ‚‚.trans hc) theorem Codisjoint.mono_left (h : a ≀ b) : Codisjoint a c β†’ Codisjoint b c := Codisjoint.mono h le_rfl theorem Codisjoint.mono_right : b ≀ c β†’ Codisjoint a b β†’ Codisjoint a c := Codisjoint.mono le_rfl @[simp] theorem codisjoint_self : Codisjoint a a ↔ a = ⊀ := ⟨fun hd ↦ top_unique <| hd le_rfl le_rfl, fun h _ ha _ ↦ h.symm.trans_le ha⟩ /- TODO: Rename `Codisjoint.eq_top` to `Codisjoint.sup_eq` and `Codisjoint.eq_top_of_self` to `Codisjoint.eq_top` -/ alias ⟨Codisjoint.eq_top_of_self, _⟩ := codisjoint_self theorem Codisjoint.ne (ha : a β‰  ⊀) (hab : Codisjoint a b) : a β‰  b := fun h ↦ ha <| codisjoint_self.1 <| by rwa [← h] at hab theorem Codisjoint.eq_top_of_le (hab : Codisjoint a b) (h : b ≀ a) : a = ⊀ := eq_top_iff.2 <| hab le_rfl h theorem Codisjoint.eq_top_of_ge (hab : Codisjoint a b) : a ≀ b β†’ b = ⊀ := hab.symm.eq_top_of_le lemma Codisjoint.eq_iff (hab : Codisjoint a b) : a = b ↔ a = ⊀ ∧ b = ⊀ := by aesop lemma Codisjoint.ne_iff (hab : Codisjoint a b) : a β‰  b ↔ a β‰  ⊀ ∨ b β‰  ⊀ := hab.eq_iff.not.trans not_and_or end PartialOrderTop section PartialBoundedOrder variable [PartialOrder Ξ±] [BoundedOrder Ξ±] {a b : Ξ±} @[simp] theorem codisjoint_bot : Codisjoint a βŠ₯ ↔ a = ⊀ := ⟨fun h ↦ top_unique <| h le_rfl bot_le, fun h _ ha _ ↦ h.symm.trans_le ha⟩ @[simp] theorem bot_codisjoint : Codisjoint βŠ₯ a ↔ a = ⊀ := ⟨fun h ↦ top_unique <| h bot_le le_rfl, fun h _ _ ha ↦ h.symm.trans_le ha⟩ lemma Codisjoint.ne_bot_of_ne_top (h : Codisjoint a b) (ha : a β‰  ⊀) : b β‰  βŠ₯ := by rintro rfl; exact ha <| by simpa using h lemma Codisjoint.ne_bot_of_ne_top' (h : Codisjoint a b) (hb : b β‰  ⊀) : a β‰  βŠ₯ := by rintro rfl; exact hb <| by simpa using h end PartialBoundedOrder section SemilatticeSupTop variable [SemilatticeSup Ξ±] [OrderTop Ξ±] {a b c : Ξ±} theorem codisjoint_iff_le_sup : Codisjoint a b ↔ ⊀ ≀ a βŠ” b := @disjoint_iff_inf_le Ξ±α΅’α΅ˆ _ _ _ _ theorem codisjoint_iff : Codisjoint a b ↔ a βŠ” b = ⊀ := @disjoint_iff Ξ±α΅’α΅ˆ _ _ _ _ theorem Codisjoint.top_le : Codisjoint a b β†’ ⊀ ≀ a βŠ” b := @Disjoint.le_bot Ξ±α΅’α΅ˆ _ _ _ _ theorem Codisjoint.eq_top : Codisjoint a b β†’ a βŠ” b = ⊀ := @Disjoint.eq_bot Ξ±α΅’α΅ˆ _ _ _ _ theorem codisjoint_assoc : Codisjoint (a βŠ” b) c ↔ Codisjoint a (b βŠ” c) := @disjoint_assoc Ξ±α΅’α΅ˆ _ _ _ _ _ theorem codisjoint_left_comm : Codisjoint a (b βŠ” c) ↔ Codisjoint b (a βŠ” c) := @disjoint_left_comm Ξ±α΅’α΅ˆ _ _ _ _ _ theorem codisjoint_right_comm : Codisjoint (a βŠ” b) c ↔ Codisjoint (a βŠ” c) b := @disjoint_right_comm Ξ±α΅’α΅ˆ _ _ _ _ _ variable (c) theorem Codisjoint.sup_left (h : Codisjoint a b) : Codisjoint (a βŠ” c) b := h.mono_left le_sup_left theorem Codisjoint.sup_left' (h : Codisjoint a b) : Codisjoint (c βŠ” a) b := h.mono_left le_sup_right theorem Codisjoint.sup_right (h : Codisjoint a b) : Codisjoint a (b βŠ” c) := h.mono_right le_sup_left theorem Codisjoint.sup_right' (h : Codisjoint a b) : Codisjoint a (c βŠ” b) := h.mono_right le_sup_right variable {c} theorem Codisjoint.of_codisjoint_sup_of_le (h : Codisjoint (a βŠ” b) c) (hle : c ≀ a) : Codisjoint a b := @Disjoint.of_disjoint_inf_of_le Ξ±α΅’α΅ˆ _ _ _ _ _ h hle theorem Codisjoint.of_codisjoint_sup_of_le' (h : Codisjoint (a βŠ” b) c) (hle : c ≀ b) : Codisjoint a b := @Disjoint.of_disjoint_inf_of_le' Ξ±α΅’α΅ˆ _ _ _ _ _ h hle end SemilatticeSupTop section DistribLatticeTop variable [DistribLattice Ξ±] [OrderTop Ξ±] {a b c : Ξ±} @[simp] theorem codisjoint_inf_left : Codisjoint (a βŠ“ b) c ↔ Codisjoint a c ∧ Codisjoint b c := by simp only [codisjoint_iff, sup_inf_right, inf_eq_top_iff] @[simp] theorem codisjoint_inf_right : Codisjoint a (b βŠ“ c) ↔ Codisjoint a b ∧ Codisjoint a c := by simp only [codisjoint_iff, sup_inf_left, inf_eq_top_iff] theorem Codisjoint.inf_left (ha : Codisjoint a c) (hb : Codisjoint b c) : Codisjoint (a βŠ“ b) c := codisjoint_inf_left.2 ⟨ha, hb⟩ theorem Codisjoint.inf_right (hb : Codisjoint a b) (hc : Codisjoint a c) : Codisjoint a (b βŠ“ c) := codisjoint_inf_right.2 ⟨hb, hc⟩ theorem Codisjoint.left_le_of_le_inf_right (h : a βŠ“ b ≀ c) (hd : Codisjoint b c) : a ≀ c := @Disjoint.left_le_of_le_sup_right Ξ±α΅’α΅ˆ _ _ _ _ _ h hd.symm theorem Codisjoint.left_le_of_le_inf_left (h : b βŠ“ a ≀ c) (hd : Codisjoint b c) : a ≀ c := hd.left_le_of_le_inf_right <| by rwa [inf_comm] end DistribLatticeTop end Codisjoint open OrderDual theorem Disjoint.dual [PartialOrder Ξ±] [OrderBot Ξ±] {a b : Ξ±} : Disjoint a b β†’ Codisjoint (toDual a) (toDual b) := id theorem Codisjoint.dual [PartialOrder Ξ±] [OrderTop Ξ±] {a b : Ξ±} : Codisjoint a b β†’ Disjoint (toDual a) (toDual b) := id @[simp] theorem disjoint_toDual_iff [PartialOrder Ξ±] [OrderTop Ξ±] {a b : Ξ±} : Disjoint (toDual a) (toDual b) ↔ Codisjoint a b := Iff.rfl @[simp] theorem disjoint_ofDual_iff [PartialOrder Ξ±] [OrderBot Ξ±] {a b : Ξ±α΅’α΅ˆ} : Disjoint (ofDual a) (ofDual b) ↔ Codisjoint a b := Iff.rfl @[simp] theorem codisjoint_toDual_iff [PartialOrder Ξ±] [OrderBot Ξ±] {a b : Ξ±} : Codisjoint (toDual a) (toDual b) ↔ Disjoint a b := Iff.rfl @[simp] theorem codisjoint_ofDual_iff [PartialOrder Ξ±] [OrderTop Ξ±] {a b : Ξ±α΅’α΅ˆ} : Codisjoint (ofDual a) (ofDual b) ↔ Disjoint a b := Iff.rfl section DistribLattice variable [DistribLattice Ξ±] [BoundedOrder Ξ±] {a b c : Ξ±} theorem Disjoint.le_of_codisjoint (hab : Disjoint a b) (hbc : Codisjoint b c) : a ≀ c := by rw [← @inf_top_eq _ _ _ a, ← @bot_sup_eq _ _ _ c, ← hab.eq_bot, ← hbc.eq_top, sup_inf_right] exact inf_le_inf_right _ le_sup_left end DistribLattice section IsCompl /-- Two elements `x` and `y` are complements of each other if `x βŠ” y = ⊀` and `x βŠ“ y = βŠ₯`. -/ structure IsCompl [PartialOrder Ξ±] [BoundedOrder Ξ±] (x y : Ξ±) : Prop where /-- If `x` and `y` are to be complementary in an order, they should be disjoint. -/ protected disjoint : Disjoint x y /-- If `x` and `y` are to be complementary in an order, they should be codisjoint. -/ protected codisjoint : Codisjoint x y theorem isCompl_iff [PartialOrder Ξ±] [BoundedOrder Ξ±] {a b : Ξ±} : IsCompl a b ↔ Disjoint a b ∧ Codisjoint a b := ⟨fun h ↦ ⟨h.1, h.2⟩, fun h ↦ ⟨h.1, h.2⟩⟩ namespace IsCompl section BoundedPartialOrder variable [PartialOrder Ξ±] [BoundedOrder Ξ±] {x y : Ξ±} @[symm] protected theorem symm (h : IsCompl x y) : IsCompl y x := ⟨h.1.symm, h.2.symm⟩ lemma _root_.isCompl_comm : IsCompl x y ↔ IsCompl y x := ⟨IsCompl.symm, IsCompl.symm⟩ theorem dual (h : IsCompl x y) : IsCompl (toDual x) (toDual y) := ⟨h.2, h.1⟩ theorem ofDual {a b : Ξ±α΅’α΅ˆ} (h : IsCompl a b) : IsCompl (ofDual a) (ofDual b) := ⟨h.2, h.1⟩ end BoundedPartialOrder section BoundedLattice variable [Lattice Ξ±] [BoundedOrder Ξ±] {x y : Ξ±} theorem of_le (h₁ : x βŠ“ y ≀ βŠ₯) (hβ‚‚ : ⊀ ≀ x βŠ” y) : IsCompl x y := ⟨disjoint_iff_inf_le.mpr h₁, codisjoint_iff_le_sup.mpr hβ‚‚βŸ© theorem of_eq (h₁ : x βŠ“ y = βŠ₯) (hβ‚‚ : x βŠ” y = ⊀) : IsCompl x y := ⟨disjoint_iff.mpr h₁, codisjoint_iff.mpr hβ‚‚βŸ© theorem inf_eq_bot (h : IsCompl x y) : x βŠ“ y = βŠ₯ := h.disjoint.eq_bot theorem sup_eq_top (h : IsCompl x y) : x βŠ” y = ⊀ := h.codisjoint.eq_top end BoundedLattice variable [DistribLattice Ξ±] [BoundedOrder Ξ±] {a b x y z : Ξ±} theorem inf_left_le_of_le_sup_right (h : IsCompl x y) (hle : a ≀ b βŠ” y) : a βŠ“ x ≀ b := calc a βŠ“ x ≀ (b βŠ” y) βŠ“ x := inf_le_inf hle le_rfl _ = b βŠ“ x βŠ” y βŠ“ x := inf_sup_right _ _ _ _ = b βŠ“ x := by rw [h.symm.inf_eq_bot, sup_bot_eq] _ ≀ b := inf_le_left theorem le_sup_right_iff_inf_left_le {a b} (h : IsCompl x y) : a ≀ b βŠ” y ↔ a βŠ“ x ≀ b := ⟨h.inf_left_le_of_le_sup_right, h.symm.dual.inf_left_le_of_le_sup_right⟩ theorem inf_left_eq_bot_iff (h : IsCompl y z) : x βŠ“ y = βŠ₯ ↔ x ≀ z := by rw [← le_bot_iff, ← h.le_sup_right_iff_inf_left_le, bot_sup_eq] theorem inf_right_eq_bot_iff (h : IsCompl y z) : x βŠ“ z = βŠ₯ ↔ x ≀ y := h.symm.inf_left_eq_bot_iff theorem disjoint_left_iff (h : IsCompl y z) : Disjoint x y ↔ x ≀ z := by rw [disjoint_iff] exact h.inf_left_eq_bot_iff theorem disjoint_right_iff (h : IsCompl y z) : Disjoint x z ↔ x ≀ y := h.symm.disjoint_left_iff theorem le_left_iff (h : IsCompl x y) : z ≀ x ↔ Disjoint z y := h.disjoint_right_iff.symm theorem le_right_iff (h : IsCompl x y) : z ≀ y ↔ Disjoint z x := h.symm.le_left_iff theorem left_le_iff (h : IsCompl x y) : x ≀ z ↔ Codisjoint z y := h.dual.le_left_iff theorem right_le_iff (h : IsCompl x y) : y ≀ z ↔ Codisjoint z x := h.symm.left_le_iff protected theorem Antitone {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') (hx : x ≀ x') : y' ≀ y := h'.right_le_iff.2 <| h.symm.codisjoint.mono_right hx theorem right_unique (hxy : IsCompl x y) (hxz : IsCompl x z) : y = z := le_antisymm (hxz.Antitone hxy <| le_refl x) (hxy.Antitone hxz <| le_refl x) theorem left_unique (hxz : IsCompl x z) (hyz : IsCompl y z) : x = y := hxz.symm.right_unique hyz.symm theorem sup_inf {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x βŠ” x') (y βŠ“ y') := of_eq (by rw [inf_sup_right, ← inf_assoc, h.inf_eq_bot, bot_inf_eq, bot_sup_eq, inf_left_comm, h'.inf_eq_bot, inf_bot_eq]) (by rw [sup_inf_left, sup_comm x, sup_assoc, h.sup_eq_top, sup_top_eq, top_inf_eq, sup_assoc, sup_left_comm, h'.sup_eq_top, sup_top_eq]) theorem inf_sup {x' y'} (h : IsCompl x y) (h' : IsCompl x' y') : IsCompl (x βŠ“ x') (y βŠ” y') := (h.symm.sup_inf h'.symm).symm end IsCompl namespace Prod variable {Ξ² : Type*} [PartialOrder Ξ±] [PartialOrder Ξ²] protected theorem disjoint_iff [OrderBot Ξ±] [OrderBot Ξ²] {x y : Ξ± Γ— Ξ²} : Disjoint x y ↔ Disjoint x.1 y.1 ∧ Disjoint x.2 y.2 := by constructor Β· intro h refine ⟨fun a hx hy ↦ (@h (a, βŠ₯) ⟨hx, ?_⟩ ⟨hy, ?_⟩).1, fun b hx hy ↦ (@h (βŠ₯, b) ⟨?_, hx⟩ ⟨?_, hy⟩).2⟩ all_goals exact bot_le Β· rintro ⟨ha, hb⟩ z hza hzb exact ⟨ha hza.1 hzb.1, hb hza.2 hzb.2⟩ protected theorem codisjoint_iff [OrderTop Ξ±] [OrderTop Ξ²] {x y : Ξ± Γ— Ξ²} : Codisjoint x y ↔ Codisjoint x.1 y.1 ∧ Codisjoint x.2 y.2 := @Prod.disjoint_iff Ξ±α΅’α΅ˆ Ξ²α΅’α΅ˆ _ _ _ _ _ _ protected theorem isCompl_iff [BoundedOrder Ξ±] [BoundedOrder Ξ²] {x y : Ξ± Γ— Ξ²} : IsCompl x y ↔ IsCompl x.1 y.1 ∧ IsCompl x.2 y.2 := by simp_rw [isCompl_iff, Prod.disjoint_iff, Prod.codisjoint_iff, and_and_and_comm] end Prod section variable [Lattice Ξ±] [BoundedOrder Ξ±] {a b x : Ξ±} @[simp] theorem isCompl_toDual_iff : IsCompl (toDual a) (toDual b) ↔ IsCompl a b := ⟨IsCompl.ofDual, IsCompl.dual⟩ @[simp] theorem isCompl_ofDual_iff {a b : Ξ±α΅’α΅ˆ} : IsCompl (ofDual a) (ofDual b) ↔ IsCompl a b := ⟨IsCompl.dual, IsCompl.ofDual⟩ theorem isCompl_bot_top : IsCompl (βŠ₯ : Ξ±) ⊀ := IsCompl.of_eq (bot_inf_eq _) (sup_top_eq _) theorem isCompl_top_bot : IsCompl (⊀ : Ξ±) βŠ₯ := IsCompl.of_eq (inf_bot_eq _) (top_sup_eq _)
Mathlib/Order/Disjoint.lean
548
550
theorem eq_top_of_isCompl_bot (h : IsCompl x βŠ₯) : x = ⊀ := by
rw [← sup_bot_eq x, h.sup_eq_top] theorem eq_top_of_bot_isCompl (h : IsCompl βŠ₯ x) : x = ⊀ :=
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Monoidal.Discrete import Mathlib.CategoryTheory.Monoidal.NaturalTransformation import Mathlib.CategoryTheory.Monoidal.Opposite import Mathlib.Tactic.CategoryTheory.Monoidal.Basic import Mathlib.CategoryTheory.CommSq /-! # Braided and symmetric monoidal categories The basic definitions of braided monoidal categories, and symmetric monoidal categories, as well as braided functors. ## Implementation note We make `BraidedCategory` another typeclass, but then have `SymmetricCategory` extend this. The rationale is that we are not carrying any additional data, just requiring a property. ## Future work * Construct the Drinfeld center of a monoidal category as a braided monoidal category. * Say something about pseudo-natural transformations. ## References * [Pavel Etingof, Shlomo Gelaki, Dmitri Nikshych, Victor Ostrik, *Tensor categories*][egno15] -/ universe v v₁ vβ‚‚ v₃ u u₁ uβ‚‚ u₃ namespace CategoryTheory open Category MonoidalCategory Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal /-- A braided monoidal category is a monoidal category equipped with a braiding isomorphism `Ξ²_ X Y : X βŠ— Y β‰… Y βŠ— X` which is natural in both arguments, and also satisfies the two hexagon identities. -/ class BraidedCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where /-- The braiding natural isomorphism. -/ braiding : βˆ€ X Y : C, X βŠ— Y β‰… Y βŠ— X braiding_naturality_right : βˆ€ (X : C) {Y Z : C} (f : Y ⟢ Z), X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f β–· X := by aesop_cat braiding_naturality_left : βˆ€ {X Y : C} (f : X ⟢ Y) (Z : C), f β–· Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by aesop_cat /-- The first hexagon identity. -/ hexagon_forward : βˆ€ X Y Z : C, (Ξ±_ X Y Z).hom ≫ (braiding X (Y βŠ— Z)).hom ≫ (Ξ±_ Y Z X).hom = ((braiding X Y).hom β–· Z) ≫ (Ξ±_ Y X Z).hom ≫ (Y ◁ (braiding X Z).hom) := by aesop_cat /-- The second hexagon identity. -/ hexagon_reverse : βˆ€ X Y Z : C, (Ξ±_ X Y Z).inv ≫ (braiding (X βŠ— Y) Z).hom ≫ (Ξ±_ Z X Y).inv = (X ◁ (braiding Y Z).hom) ≫ (Ξ±_ X Z Y).inv ≫ ((braiding X Z).hom β–· Y) := by aesop_cat attribute [reassoc (attr := simp)] BraidedCategory.braiding_naturality_left BraidedCategory.braiding_naturality_right attribute [reassoc] BraidedCategory.hexagon_forward BraidedCategory.hexagon_reverse open BraidedCategory @[inherit_doc] notation "Ξ²_" => BraidedCategory.braiding namespace BraidedCategory variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [BraidedCategory.{v} C] @[simp, reassoc] theorem braiding_tensor_left (X Y Z : C) : (Ξ²_ (X βŠ— Y) Z).hom = (Ξ±_ X Y Z).hom ≫ X ◁ (Ξ²_ Y Z).hom ≫ (Ξ±_ X Z Y).inv ≫ (Ξ²_ X Z).hom β–· Y ≫ (Ξ±_ Z X Y).hom := by apply (cancel_epi (Ξ±_ X Y Z).inv).1 apply (cancel_mono (Ξ±_ Z X Y).inv).1 simp [hexagon_reverse] @[simp, reassoc] theorem braiding_tensor_right (X Y Z : C) : (Ξ²_ X (Y βŠ— Z)).hom = (Ξ±_ X Y Z).inv ≫ (Ξ²_ X Y).hom β–· Z ≫ (Ξ±_ Y X Z).hom ≫ Y ◁ (Ξ²_ X Z).hom ≫ (Ξ±_ Y Z X).inv := by apply (cancel_epi (Ξ±_ X Y Z).hom).1 apply (cancel_mono (Ξ±_ Y Z X).hom).1 simp [hexagon_forward] @[simp, reassoc] theorem braiding_inv_tensor_left (X Y Z : C) : (Ξ²_ (X βŠ— Y) Z).inv = (Ξ±_ Z X Y).inv ≫ (Ξ²_ X Z).inv β–· Y ≫ (Ξ±_ X Z Y).hom ≫ X ◁ (Ξ²_ Y Z).inv ≫ (Ξ±_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[simp, reassoc] theorem braiding_inv_tensor_right (X Y Z : C) : (Ξ²_ X (Y βŠ— Z)).inv = (Ξ±_ Y Z X).hom ≫ Y ◁ (Ξ²_ X Z).inv ≫ (Ξ±_ Y X Z).inv ≫ (Ξ²_ X Y).inv β–· Z ≫ (Ξ±_ X Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)] theorem braiding_naturality {X X' Y Y' : C} (f : X ⟢ Y) (g : X' ⟢ Y') : (f βŠ— g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g βŠ— f) := by rw [tensorHom_def' f g, tensorHom_def g f] simp_rw [Category.assoc, braiding_naturality_left, braiding_naturality_right_assoc] @[reassoc (attr := simp)] theorem braiding_inv_naturality_right (X : C) {Y Z : C} (f : Y ⟢ Z) : X ◁ f ≫ (Ξ²_ Z X).inv = (Ξ²_ Y X).inv ≫ f β–· X := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_left f X @[reassoc (attr := simp)] theorem braiding_inv_naturality_left {X Y : C} (f : X ⟢ Y) (Z : C) : f β–· Z ≫ (Ξ²_ Z Y).inv = (Ξ²_ Z X).inv ≫ Z ◁ f := CommSq.w <| .vert_inv <| .mk <| braiding_naturality_right Z f @[reassoc (attr := simp)] theorem braiding_inv_naturality {X X' Y Y' : C} (f : X ⟢ Y) (g : X' ⟢ Y') : (f βŠ— g) ≫ (Ξ²_ Y' Y).inv = (Ξ²_ X' X).inv ≫ (g βŠ— f) := CommSq.w <| .vert_inv <| .mk <| braiding_naturality g f /-- In a braided monoidal category, the functors `tensorLeft X` and `tensorRight X` are isomorphic. -/ @[simps] def tensorLeftIsoTensorRight (X : C) : tensorLeft X β‰… tensorRight X where hom := { app Y := (Ξ²_ X Y).hom } inv := { app Y := (Ξ²_ X Y).inv } @[reassoc] theorem yang_baxter (X Y Z : C) : (Ξ±_ X Y Z).inv ≫ (Ξ²_ X Y).hom β–· Z ≫ (Ξ±_ Y X Z).hom ≫ Y ◁ (Ξ²_ X Z).hom ≫ (Ξ±_ Y Z X).inv ≫ (Ξ²_ Y Z).hom β–· X ≫ (Ξ±_ Z Y X).hom = X ◁ (Ξ²_ Y Z).hom ≫ (Ξ±_ X Z Y).inv ≫ (Ξ²_ X Z).hom β–· Y ≫ (Ξ±_ Z X Y).hom ≫ Z ◁ (Ξ²_ X Y).hom := by rw [← braiding_tensor_right_assoc X Y Z, ← cancel_mono (Ξ±_ Z Y X).inv] repeat rw [assoc] rw [Iso.hom_inv_id, comp_id, ← braiding_naturality_right, braiding_tensor_right] theorem yang_baxter' (X Y Z : C) : (Ξ²_ X Y).hom β–· Z βŠ—β‰« Y ◁ (Ξ²_ X Z).hom βŠ—β‰« (Ξ²_ Y Z).hom β–· X = πŸ™ _ βŠ—β‰« (X ◁ (Ξ²_ Y Z).hom βŠ—β‰« (Ξ²_ X Z).hom β–· Y βŠ—β‰« Z ◁ (Ξ²_ X Y).hom) βŠ—β‰« πŸ™ _ := by rw [← cancel_epi (Ξ±_ X Y Z).inv, ← cancel_mono (Ξ±_ Z Y X).hom] convert yang_baxter X Y Z using 1 all_goals monoidal theorem yang_baxter_iso (X Y Z : C) : (Ξ±_ X Y Z).symm β‰ͺ≫ whiskerRightIso (Ξ²_ X Y) Z β‰ͺ≫ Ξ±_ Y X Z β‰ͺ≫ whiskerLeftIso Y (Ξ²_ X Z) β‰ͺ≫ (Ξ±_ Y Z X).symm β‰ͺ≫ whiskerRightIso (Ξ²_ Y Z) X β‰ͺ≫ (Ξ±_ Z Y X) = whiskerLeftIso X (Ξ²_ Y Z) β‰ͺ≫ (Ξ±_ X Z Y).symm β‰ͺ≫ whiskerRightIso (Ξ²_ X Z) Y β‰ͺ≫ Ξ±_ Z X Y β‰ͺ≫ whiskerLeftIso Z (Ξ²_ X Y) := Iso.ext (yang_baxter X Y Z) theorem hexagon_forward_iso (X Y Z : C) : Ξ±_ X Y Z β‰ͺ≫ Ξ²_ X (Y βŠ— Z) β‰ͺ≫ Ξ±_ Y Z X = whiskerRightIso (Ξ²_ X Y) Z β‰ͺ≫ Ξ±_ Y X Z β‰ͺ≫ whiskerLeftIso Y (Ξ²_ X Z) := Iso.ext (hexagon_forward X Y Z) theorem hexagon_reverse_iso (X Y Z : C) : (Ξ±_ X Y Z).symm β‰ͺ≫ Ξ²_ (X βŠ— Y) Z β‰ͺ≫ (Ξ±_ Z X Y).symm = whiskerLeftIso X (Ξ²_ Y Z) β‰ͺ≫ (Ξ±_ X Z Y).symm β‰ͺ≫ whiskerRightIso (Ξ²_ X Z) Y := Iso.ext (hexagon_reverse X Y Z) @[reassoc] theorem hexagon_forward_inv (X Y Z : C) : (Ξ±_ Y Z X).inv ≫ (Ξ²_ X (Y βŠ— Z)).inv ≫ (Ξ±_ X Y Z).inv = Y ◁ (Ξ²_ X Z).inv ≫ (Ξ±_ Y X Z).inv ≫ (Ξ²_ X Y).inv β–· Z := by simp @[reassoc] theorem hexagon_reverse_inv (X Y Z : C) : (Ξ±_ Z X Y).hom ≫ (Ξ²_ (X βŠ— Y) Z).inv ≫ (Ξ±_ X Y Z).hom = (Ξ²_ X Z).inv β–· Y ≫ (Ξ±_ X Z Y).hom ≫ X ◁ (Ξ²_ Y Z).inv := by simp end BraidedCategory /-- Verifying the axioms for a braiding by checking that the candidate braiding is sent to a braiding by a faithful monoidal functor. -/ def braidedCategoryOfFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C β₯€ D) [F.Monoidal] [F.Faithful] [BraidedCategory D] (Ξ² : βˆ€ X Y : C, X βŠ— Y β‰… Y βŠ— X) (w : βˆ€ X Y, ΞΌ F _ _ ≫ F.map (Ξ² X Y).hom = (Ξ²_ _ _).hom ≫ ΞΌ F _ _) : BraidedCategory C where braiding := Ξ² braiding_naturality_left := by intros apply F.map_injective refine (cancel_epi (ΞΌ F ?_ ?_)).1 ?_ rw [Functor.map_comp, ← ΞΌ_natural_left_assoc, w, Functor.map_comp, reassoc_of% w, braiding_naturality_left_assoc, ΞΌ_natural_right] braiding_naturality_right := by intros apply F.map_injective refine (cancel_epi (ΞΌ F ?_ ?_)).1 ?_ rw [Functor.map_comp, ← ΞΌ_natural_right_assoc, w, Functor.map_comp, reassoc_of% w, braiding_naturality_right_assoc, ΞΌ_natural_left] hexagon_forward := by intros apply F.map_injective refine (cancel_epi (ΞΌ F _ _)).1 ?_ refine (cancel_epi (ΞΌ F _ _ β–· _)).1 ?_ rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← ΞΌ_natural_left_assoc, ← comp_whiskerRight_assoc, w, comp_whiskerRight_assoc, Functor.LaxMonoidal.associativity_assoc, Functor.LaxMonoidal.associativity_assoc, ← ΞΌ_natural_right, ← MonoidalCategory.whiskerLeft_comp_assoc, w, MonoidalCategory.whiskerLeft_comp_assoc, reassoc_of% w, braiding_naturality_right_assoc, Functor.LaxMonoidal.associativity, hexagon_forward_assoc] hexagon_reverse := by intros apply F.map_injective refine (cancel_epi (ΞΌ F _ _)).1 ?_ refine (cancel_epi (_ ◁ ΞΌ F _ _)).1 ?_ rw [Functor.map_comp, Functor.map_comp, Functor.map_comp, Functor.map_comp, ← ΞΌ_natural_right_assoc, ← MonoidalCategory.whiskerLeft_comp_assoc, w, MonoidalCategory.whiskerLeft_comp_assoc, Functor.LaxMonoidal.associativity_inv_assoc, Functor.LaxMonoidal.associativity_inv_assoc, ← ΞΌ_natural_left, ← comp_whiskerRight_assoc, w, comp_whiskerRight_assoc, reassoc_of% w, braiding_naturality_left_assoc, Functor.LaxMonoidal.associativity_inv, hexagon_reverse_assoc] /-- Pull back a braiding along a fully faithful monoidal functor. -/ noncomputable def braidedCategoryOfFullyFaithful {C D : Type*} [Category C] [Category D] [MonoidalCategory C] [MonoidalCategory D] (F : C β₯€ D) [F.Monoidal] [F.Full] [F.Faithful] [BraidedCategory D] : BraidedCategory C := braidedCategoryOfFaithful F (fun X Y => F.preimageIso ((ΞΌIso F _ _).symm β‰ͺ≫ Ξ²_ (F.obj X) (F.obj Y) β‰ͺ≫ (ΞΌIso F _ _))) (by simp) section /-! We now establish how the braiding interacts with the unitors. I couldn't find a detailed proof in print, but this is discussed in: * Proposition 1 of AndrΓ© Joyal and Ross Street, "Braided monoidal categories", Macquarie Math Reports 860081 (1986). * Proposition 2.1 of AndrΓ© Joyal and Ross Street, "Braided tensor categories" , Adv. Math. 102 (1993), 20–78. * Exercise 8.1.6 of Etingof, Gelaki, Nikshych, Ostrik, "Tensor categories", vol 25, Mathematical Surveys and Monographs (2015), AMS. -/ variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] [BraidedCategory C] theorem braiding_leftUnitor_aux₁ (X : C) : (Ξ±_ (πŸ™_ C) (πŸ™_ C) X).hom ≫ (πŸ™_ C ◁ (Ξ²_ X (πŸ™_ C)).inv) ≫ (Ξ±_ _ X _).inv ≫ ((Ξ»_ X).hom β–· _) = ((Ξ»_ _).hom β–· X) ≫ (Ξ²_ X (πŸ™_ C)).inv := by monoidal theorem braiding_leftUnitor_auxβ‚‚ (X : C) : ((Ξ²_ X (πŸ™_ C)).hom β–· πŸ™_ C) ≫ ((Ξ»_ X).hom β–· πŸ™_ C) = (ρ_ X).hom β–· πŸ™_ C := calc ((Ξ²_ X (πŸ™_ C)).hom β–· πŸ™_ C) ≫ ((Ξ»_ X).hom β–· πŸ™_ C) = ((Ξ²_ X (πŸ™_ C)).hom β–· πŸ™_ C) ≫ (Ξ±_ _ _ _).hom ≫ (Ξ±_ _ _ _).inv ≫ ((Ξ»_ X).hom β–· πŸ™_ C) := by monoidal _ = ((Ξ²_ X (πŸ™_ C)).hom β–· πŸ™_ C) ≫ (Ξ±_ _ _ _).hom ≫ (_ ◁ (Ξ²_ X _).hom) ≫ (_ ◁ (Ξ²_ X _).inv) ≫ (Ξ±_ _ _ _).inv ≫ ((Ξ»_ X).hom β–· πŸ™_ C) := by simp _ = (Ξ±_ _ _ _).hom ≫ (Ξ²_ _ _).hom ≫ (Ξ±_ _ _ _).hom ≫ (_ ◁ (Ξ²_ X _).inv) ≫ (Ξ±_ _ _ _).inv ≫ ((Ξ»_ X).hom β–· πŸ™_ C) := by simp _ = (Ξ±_ _ _ _).hom ≫ (Ξ²_ _ _).hom ≫ ((Ξ»_ _).hom β–· X) ≫ (Ξ²_ X _).inv := by rw [braiding_leftUnitor_aux₁] _ = (Ξ±_ _ _ _).hom ≫ (_ ◁ (Ξ»_ _).hom) ≫ (Ξ²_ _ _).hom ≫ (Ξ²_ X _).inv := by (slice_lhs 2 3 => rw [← braiding_naturality_right]); simp only [assoc] _ = (Ξ±_ _ _ _).hom ≫ (_ ◁ (Ξ»_ _).hom) := by rw [Iso.hom_inv_id, comp_id] _ = (ρ_ X).hom β–· πŸ™_ C := by rw [triangle] @[reassoc] theorem braiding_leftUnitor (X : C) : (Ξ²_ X (πŸ™_ C)).hom ≫ (Ξ»_ X).hom = (ρ_ X).hom := by rw [← whiskerRight_iff, comp_whiskerRight, braiding_leftUnitor_auxβ‚‚] theorem braiding_rightUnitor_aux₁ (X : C) : (Ξ±_ X (πŸ™_ C) (πŸ™_ C)).inv ≫ ((Ξ²_ (πŸ™_ C) X).inv β–· πŸ™_ C) ≫ (Ξ±_ _ X _).hom ≫ (_ ◁ (ρ_ X).hom) = (X ◁ (ρ_ _).hom) ≫ (Ξ²_ (πŸ™_ C) X).inv := by monoidal theorem braiding_rightUnitor_auxβ‚‚ (X : C) : (πŸ™_ C ◁ (Ξ²_ (πŸ™_ C) X).hom) ≫ (πŸ™_ C ◁ (ρ_ X).hom) = πŸ™_ C ◁ (Ξ»_ X).hom := calc (πŸ™_ C ◁ (Ξ²_ (πŸ™_ C) X).hom) ≫ (πŸ™_ C ◁ (ρ_ X).hom) = (πŸ™_ C ◁ (Ξ²_ (πŸ™_ C) X).hom) ≫ (Ξ±_ _ _ _).inv ≫ (Ξ±_ _ _ _).hom ≫ (πŸ™_ C ◁ (ρ_ X).hom) := by monoidal _ = (πŸ™_ C ◁ (Ξ²_ (πŸ™_ C) X).hom) ≫ (Ξ±_ _ _ _).inv ≫ ((Ξ²_ _ X).hom β–· _) ≫ ((Ξ²_ _ X).inv β–· _) ≫ (Ξ±_ _ _ _).hom ≫ (πŸ™_ C ◁ (ρ_ X).hom) := by simp _ = (Ξ±_ _ _ _).inv ≫ (Ξ²_ _ _).hom ≫ (Ξ±_ _ _ _).inv ≫ ((Ξ²_ _ X).inv β–· _) ≫ (Ξ±_ _ _ _).hom ≫ (πŸ™_ C ◁ (ρ_ X).hom) := by (slice_lhs 1 3 => rw [← hexagon_reverse]); simp only [assoc] _ = (Ξ±_ _ _ _).inv ≫ (Ξ²_ _ _).hom ≫ (X ◁ (ρ_ _).hom) ≫ (Ξ²_ _ X).inv := by simp _ = (Ξ±_ _ _ _).inv ≫ ((ρ_ _).hom β–· _) ≫ (Ξ²_ _ X).hom ≫ (Ξ²_ _ _).inv := by (slice_lhs 2 3 => rw [← braiding_naturality_left]); simp only [assoc] _ = (Ξ±_ _ _ _).inv ≫ ((ρ_ _).hom β–· _) := by rw [Iso.hom_inv_id, comp_id] _ = πŸ™_ C ◁ (Ξ»_ X).hom := by rw [triangle_assoc_comp_right] @[reassoc] theorem braiding_rightUnitor (X : C) : (Ξ²_ (πŸ™_ C) X).hom ≫ (ρ_ X).hom = (Ξ»_ X).hom := by rw [← whiskerLeft_iff, MonoidalCategory.whiskerLeft_comp, braiding_rightUnitor_auxβ‚‚] @[reassoc, simp] theorem braiding_tensorUnit_left (X : C) : (Ξ²_ (πŸ™_ C) X).hom = (Ξ»_ X).hom ≫ (ρ_ X).inv := by simp [← braiding_rightUnitor] @[reassoc, simp] theorem braiding_inv_tensorUnit_left (X : C) : (Ξ²_ (πŸ™_ C) X).inv = (ρ_ X).hom ≫ (Ξ»_ X).inv := by rw [Iso.inv_ext] rw [braiding_tensorUnit_left] monoidal @[reassoc]
Mathlib/CategoryTheory/Monoidal/Braided/Basic.lean
332
333
theorem leftUnitor_inv_braiding (X : C) : (Ξ»_ X).inv ≫ (Ξ²_ (πŸ™_ C) X).hom = (ρ_ X).inv := by
simp
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Jakob von Raumer -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Biproducts and binary biproducts We introduce the notion of (finite) biproducts. Binary biproducts are defined in `CategoryTheory.Limits.Shapes.BinaryBiproducts`. These are slightly unusual relative to the other shapes in the library, as they are simultaneously limits and colimits. (Zero objects are similar; they are "biterminal".) For results about biproducts in preadditive categories see `CategoryTheory.Preadditive.Biproducts`. For biproducts indexed by a `Fintype J`, a `bicone` consists of a cone point `X` and morphisms `Ο€ j : X ⟢ F j` and `ΞΉ j : F j ⟢ X` for each `j`, such that `ΞΉ j ≫ Ο€ j'` is the identity when `j = j'` and zero otherwise. ## Notation As `βŠ•` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for a binary biproduct. We introduce `⨁ f` for the indexed biproduct. ## Implementation notes Prior to https://github.com/leanprover-community/mathlib3/pull/14046, `HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type. As this had no pay-off (everything about limits is non-constructive in mathlib), and occasional cost (constructing decidability instances appropriate for constructions involving the indexing type), we made everything classical. -/ noncomputable section universe w w' v u open CategoryTheory Functor namespace CategoryTheory.Limits variable {J : Type w} universe uC' uC uD' uD variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] open scoped Classical in /-- A `c : Bicone F` is: * an object `c.pt` and * morphisms `Ο€ j : pt ⟢ F j` and `ΞΉ j : F j ⟢ pt` for each `j`, * such that `ΞΉ j ≫ Ο€ j'` is the identity when `j = j'` and zero otherwise. -/ structure Bicone (F : J β†’ C) where pt : C Ο€ : βˆ€ j, pt ⟢ F j ΞΉ : βˆ€ j, F j ⟢ pt ΞΉ_Ο€ : βˆ€ j j', ΞΉ j ≫ Ο€ j' = if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop attribute [inherit_doc Bicone] Bicone.pt Bicone.Ο€ Bicone.ΞΉ Bicone.ΞΉ_Ο€ @[reassoc (attr := simp)] theorem bicone_ΞΉ_Ο€_self {F : J β†’ C} (B : Bicone F) (j : J) : B.ΞΉ j ≫ B.Ο€ j = πŸ™ (F j) := by simpa using B.ΞΉ_Ο€ j j @[reassoc (attr := simp)] theorem bicone_ΞΉ_Ο€_ne {F : J β†’ C} (B : Bicone F) {j j' : J} (h : j β‰  j') : B.ΞΉ j ≫ B.Ο€ j' = 0 := by simpa [h] using B.ΞΉ_Ο€ j j' variable {F : J β†’ C} /-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points which commutes with the cone and cocone legs. -/ structure BiconeMorphism {F : J β†’ C} (A B : Bicone F) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟢ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wΟ€ : βˆ€ j : J, hom ≫ B.Ο€ j = A.Ο€ j := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wΞΉ : βˆ€ j : J, A.ΞΉ j ≫ hom = B.ΞΉ j := by aesop_cat attribute [reassoc (attr := simp)] BiconeMorphism.wΞΉ BiconeMorphism.wΟ€ /-- The category of bicones on a given diagram. -/ @[simps] instance Bicone.category : Category (Bicone F) where Hom A B := BiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := πŸ™ B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟢ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Bicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Bicone F} (Ο† : c.pt β‰… c'.pt) (wΞΉ : βˆ€ j, c.ΞΉ j ≫ Ο†.hom = c'.ΞΉ j := by aesop_cat) (wΟ€ : βˆ€ j, Ο†.hom ≫ c'.Ο€ j = c.Ο€ j := by aesop_cat) : c β‰… c' where hom := { hom := Ο†.hom } inv := { hom := Ο†.inv wΞΉ := fun j => Ο†.comp_inv_eq.mpr (wΞΉ j).symm wΟ€ := fun j => Ο†.inv_comp_eq.mpr (wΟ€ j).symm } variable (F) in /-- A functor `G : C β₯€ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/ @[simps] def functoriality (G : C β₯€ D) [Functor.PreservesZeroMorphisms G] : Bicone F β₯€ Bicone (G.obj ∘ F) where obj A := { pt := G.obj A.pt Ο€ := fun j => G.map (A.Ο€ j) ΞΉ := fun j => G.map (A.ΞΉ j) ΞΉ_Ο€ := fun i j => (Functor.map_comp _ _ _).symm.trans <| by rw [A.ΞΉ_Ο€] aesop_cat } map f := { hom := G.map f.hom wΟ€ := fun j => by simp [-BiconeMorphism.wΟ€, ← f.wΟ€ j] wΞΉ := fun j => by simp [-BiconeMorphism.wΞΉ, ← f.wΞΉ j] } variable (G : C β₯€ D) instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom wΞΉ := fun j => G.map_injective (by simpa using t.wΞΉ j) wΟ€ := fun j => G.map_injective (by simpa using t.wΟ€ j) }, by aesop_cat⟩ instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h end Bicones namespace Bicone attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- Extract the cone from a bicone. -/ def toConeFunctor : Bicone F β₯€ Cone (Discrete.functor F) where obj B := { pt := B.pt, Ο€ := { app := fun j => B.Ο€ j.as } } map {_ _} F := { hom := F.hom, w := fun _ => F.wΟ€ _ } /-- A shorthand for `toConeFunctor.obj` -/ abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B -- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`. @[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl @[simp] theorem toCone_Ο€_app (B : Bicone F) (j : Discrete J) : B.toCone.Ο€.app j = B.Ο€ j.as := rfl theorem toCone_Ο€_app_mk (B : Bicone F) (j : J) : B.toCone.Ο€.app ⟨j⟩ = B.Ο€ j := rfl @[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.Ο€ j := rfl /-- Extract the cocone from a bicone. -/ def toCoconeFunctor : Bicone F β₯€ Cocone (Discrete.functor F) where obj B := { pt := B.pt, ΞΉ := { app := fun j => B.ΞΉ j.as } } map {_ _} F := { hom := F.hom, w := fun _ => F.wΞΉ _ } /-- A shorthand for `toCoconeFunctor.obj` -/ abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B @[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl @[simp] theorem toCocone_ΞΉ_app (B : Bicone F) (j : Discrete J) : B.toCocone.ΞΉ.app j = B.ΞΉ j.as := rfl @[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ΞΉ j := rfl theorem toCocone_ΞΉ_app_mk (B : Bicone F) (j : J) : B.toCocone.ΞΉ.app ⟨j⟩ = B.ΞΉ j := rfl open scoped Classical in /-- We can turn any limit cone over a discrete collection of objects into a bicone. -/ @[simps] def ofLimitCone {f : J β†’ C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where pt := t.pt Ο€ j := t.Ο€.app ⟨j⟩ ΞΉ j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) ΞΉ_Ο€ j j' := by simp open scoped Classical in theorem ΞΉ_of_isLimit {f : J β†’ C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) : t.ΞΉ j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ΞΉ_Ο€] open scoped Classical in /-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/ @[simps] def ofColimitCocone {f : J β†’ C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : Bicone f where pt := t.pt Ο€ j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) ΞΉ j := t.ΞΉ.app ⟨j⟩ ΞΉ_Ο€ j j' := by simp open scoped Classical in theorem Ο€_of_isColimit {f : J β†’ C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) : t.Ο€ j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ΞΉ_Ο€] /-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/ structure IsBilimit {F : J β†’ C} (B : Bicone F) where isLimit : IsLimit B.toCone isColimit : IsColimit B.toCocone attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit attribute [simp] IsBilimit.mk.injEq attribute [local ext] Bicone.IsBilimit instance subsingleton_isBilimit {f : J β†’ C} {c : Bicone f} : Subsingleton c.IsBilimit := ⟨fun _ _ => Bicone.IsBilimit.ext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩ section Whisker variable {K : Type w'} /-- Whisker a bicone with an equivalence between the indexing types. -/ @[simps] def whisker {f : J β†’ C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where pt := c.pt Ο€ k := c.Ο€ (g k) ΞΉ k := c.ΞΉ (g k) ΞΉ_Ο€ k k' := by simp only [c.ΞΉ_Ο€] split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto /-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cone and postcomposing with a suitable isomorphism. -/ def whiskerToCone {f : J β†’ C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCone β‰… (Cones.postcompose (Discrete.functorComp f g).inv).obj (c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cones.ext (Iso.refl _) (by simp) /-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cocone and precomposing with a suitable isomorphism. -/ def whiskerToCocone {f : J β†’ C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCocone β‰… (Cocones.precompose (Discrete.functorComp f g).hom).obj (c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cocones.ext (Iso.refl _) (by simp) /-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/ noncomputable def whiskerIsBilimitIff {f : J β†’ C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).IsBilimit ≃ c.IsBilimit := by refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩ Β· let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g) let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this Β· let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g) let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this Β· apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _ exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g) Β· apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _ exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g) end Whisker end Bicone /-- A bicone over `F : J β†’ C`, which is both a limit cone and a colimit cocone. -/ structure LimitBicone (F : J β†’ C) where bicone : Bicone F isBilimit : bicone.IsBilimit attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit /-- `HasBiproduct F` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `F`. -/ class HasBiproduct (F : J β†’ C) : Prop where mk' :: exists_biproduct : Nonempty (LimitBicone F) attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct theorem HasBiproduct.mk {F : J β†’ C} (d : LimitBicone F) : HasBiproduct F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/ def getBiproductData (F : J β†’ C) [HasBiproduct F] : LimitBicone F := Classical.choice HasBiproduct.exists_biproduct /-- A bicone for `F` which is both a limit cone and a colimit cocone. -/ def biproduct.bicone (F : J β†’ C) [HasBiproduct F] : Bicone F := (getBiproductData F).bicone /-- `biproduct.bicone F` is a bilimit bicone. -/ def biproduct.isBilimit (F : J β†’ C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit := (getBiproductData F).isBilimit /-- `biproduct.bicone F` is a limit cone. -/ def biproduct.isLimit (F : J β†’ C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone := (getBiproductData F).isBilimit.isLimit /-- `biproduct.bicone F` is a colimit cocone. -/ def biproduct.isColimit (F : J β†’ C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone := (getBiproductData F).isBilimit.isColimit instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F := HasLimit.mk { cone := (biproduct.bicone F).toCone isLimit := biproduct.isLimit F } instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F := HasColimit.mk { cocone := (biproduct.bicone F).toCocone isColimit := biproduct.isColimit F } variable (J C) /-- `C` has biproducts of shape `J` if we have a limit and a colimit, with the same cone points, of every function `F : J β†’ C`. -/ class HasBiproductsOfShape : Prop where has_biproduct : βˆ€ F : J β†’ C, HasBiproduct F attribute [instance 100] HasBiproductsOfShape.has_biproduct /-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C` indexed by a finite type. -/ class HasFiniteBiproducts : Prop where out : βˆ€ n, HasBiproductsOfShape (Fin n) C attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out variable {J} theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) : HasBiproductsOfShape J C := ⟨fun F => let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm) let ⟨c, hc⟩ := h HasBiproduct.mk <| by simpa only [Function.comp_def, e.symm_apply_apply] using LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩ instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] : HasBiproductsOfShape J C := by rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩ haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n exact hasBiproductsOfShape_of_equiv C e instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteProducts C where out _ := ⟨fun _ => hasLimit_of_iso Discrete.natIsoFunctor.symm⟩ instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteCoproducts C where out _ := ⟨fun _ => hasColimit_of_iso Discrete.natIsoFunctor⟩ instance (priority := 100) hasProductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] : HasProductsOfShape J C where has_limit _ := hasLimit_of_iso Discrete.natIsoFunctor.symm instance (priority := 100) hasCoproductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] : HasCoproductsOfShape J C where has_colimit _ := hasColimit_of_iso Discrete.natIsoFunctor variable {C} /-- The isomorphism between the specified limit and the specified colimit for a functor with a bilimit. -/ def biproductIso (F : J β†’ C) [HasBiproduct F] : Limits.piObj F β‰… Limits.sigmaObj F := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <| IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _) variable {J : Type w} {K : Type*} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] /-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will just use general facts about limits and colimits.) -/ abbrev biproduct (f : J β†’ C) [HasBiproduct f] : C := (biproduct.bicone f).pt @[inherit_doc biproduct] notation "⨁ " f:20 => biproduct f /-- The projection onto a summand of a biproduct. -/ abbrev biproduct.Ο€ (f : J β†’ C) [HasBiproduct f] (b : J) : ⨁ f ⟢ f b := (biproduct.bicone f).Ο€ b @[simp] theorem biproduct.bicone_Ο€ (f : J β†’ C) [HasBiproduct f] (b : J) : (biproduct.bicone f).Ο€ b = biproduct.Ο€ f b := rfl /-- The inclusion into a summand of a biproduct. -/ abbrev biproduct.ΞΉ (f : J β†’ C) [HasBiproduct f] (b : J) : f b ⟢ ⨁ f := (biproduct.bicone f).ΞΉ b @[simp] theorem biproduct.bicone_ΞΉ (f : J β†’ C) [HasBiproduct f] (b : J) : (biproduct.bicone f).ΞΉ b = biproduct.ΞΉ f b := rfl /-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument. This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/ @[reassoc] theorem biproduct.ΞΉ_Ο€ [DecidableEq J] (f : J β†’ C) [HasBiproduct f] (j j' : J) : biproduct.ΞΉ f j ≫ biproduct.Ο€ f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by convert (biproduct.bicone f).ΞΉ_Ο€ j j' @[reassoc] -- Porting note: both versions proven by simp theorem biproduct.ΞΉ_Ο€_self (f : J β†’ C) [HasBiproduct f] (j : J) : biproduct.ΞΉ f j ≫ biproduct.Ο€ f j = πŸ™ _ := by simp [biproduct.ΞΉ_Ο€] @[reassoc (attr := simp)] theorem biproduct.ΞΉ_Ο€_ne (f : J β†’ C) [HasBiproduct f] {j j' : J} (h : j β‰  j') : biproduct.ΞΉ f j ≫ biproduct.Ο€ f j' = 0 := by simp [biproduct.ΞΉ_Ο€, h] -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.eqToHom_comp_ΞΉ (f : J β†’ C) [HasBiproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ biproduct.ΞΉ f j' = biproduct.ΞΉ f j := by cases w simp -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.Ο€_comp_eqToHom (f : J β†’ C) [HasBiproduct f] {j j' : J} (w : j = j') : biproduct.Ο€ f j ≫ eqToHom (by simp [w]) = biproduct.Ο€ f j' := by cases w simp /-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/ abbrev biproduct.lift {f : J β†’ C} [HasBiproduct f] {P : C} (p : βˆ€ b, P ⟢ f b) : P ⟢ ⨁ f := (biproduct.isLimit f).lift (Fan.mk P p) /-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/ abbrev biproduct.desc {f : J β†’ C} [HasBiproduct f] {P : C} (p : βˆ€ b, f b ⟢ P) : ⨁ f ⟢ P := (biproduct.isColimit f).desc (Cofan.mk P p) @[reassoc (attr := simp)] theorem biproduct.lift_Ο€ {f : J β†’ C} [HasBiproduct f] {P : C} (p : βˆ€ b, P ⟢ f b) (j : J) : biproduct.lift p ≫ biproduct.Ο€ f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩ @[reassoc (attr := simp)] theorem biproduct.ΞΉ_desc {f : J β†’ C} [HasBiproduct f] {P : C} (p : βˆ€ b, f b ⟢ P) (j : J) : biproduct.ΞΉ f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩ /-- Given a collection of maps between corresponding summands of a pair of biproducts indexed by the same type, we obtain a map between the biproducts. -/ abbrev biproduct.map {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ b, f b ⟢ g b) : ⨁ f ⟢ ⨁ g := IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g) (Discrete.natTrans (fun j => p j.as)) /-- An alternative to `biproduct.map` constructed via colimits. This construction only exists in order to show it is equal to `biproduct.map`. -/ abbrev biproduct.map' {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ b, f b ⟢ g b) : ⨁ f ⟢ ⨁ g := IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) -- We put this at slightly higher priority than `biproduct.hom_ext'`, -- to get the matrix indices in the "right" order. @[ext 1001] theorem biproduct.hom_ext {f : J β†’ C} [HasBiproduct f] {Z : C} (g h : Z ⟢ ⨁ f) (w : βˆ€ j, g ≫ biproduct.Ο€ f j = h ≫ biproduct.Ο€ f j) : g = h := (biproduct.isLimit f).hom_ext fun j => w j.as @[ext] theorem biproduct.hom_ext' {f : J β†’ C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟢ Z) (w : βˆ€ j, biproduct.ΞΉ f j ≫ g = biproduct.ΞΉ f j ≫ h) : g = h := (biproduct.isColimit f).hom_ext fun j => w j.as /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biproduct.isoProduct (f : J β†’ C) [HasBiproduct f] : ⨁ f β‰… ∏ᢜ f := IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _) @[simp] theorem biproduct.isoProduct_hom {f : J β†’ C} [HasBiproduct f] : (biproduct.isoProduct f).hom = Pi.lift (biproduct.Ο€ f) := limit.hom_ext fun j => by simp [biproduct.isoProduct] @[simp] theorem biproduct.isoProduct_inv {f : J β†’ C} [HasBiproduct f] : (biproduct.isoProduct f).inv = biproduct.lift (Pi.Ο€ f) := biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq] /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biproduct.isoCoproduct (f : J β†’ C) [HasBiproduct f] : ⨁ f β‰… ∐ f := IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _) @[simp] theorem biproduct.isoCoproduct_inv {f : J β†’ C} [HasBiproduct f] : (biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ΞΉ f) := colimit.hom_ext fun j => by simp [biproduct.isoCoproduct] @[simp] theorem biproduct.isoCoproduct_hom {f : J β†’ C} [HasBiproduct f] : (biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ΞΉ f) := biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv] /-- If a category has biproducts of a shape `J`, its `colim` and `lim` functor on diagrams over `J` are isomorphic. -/ @[simps!] def HasBiproductsOfShape.colimIsoLim [HasBiproductsOfShape J C] : colim (J := Discrete J) (C := C) β‰… lim := NatIso.ofComponents (fun F => (Sigma.isoColimit F).symm β‰ͺ≫ (biproduct.isoCoproduct _).symm β‰ͺ≫ biproduct.isoProduct _ β‰ͺ≫ Pi.isoLimit F) fun Ξ· => colimit.hom_ext fun ⟨i⟩ => limit.hom_ext fun ⟨j⟩ => by classical by_cases h : i = j <;> simp_all [h, Sigma.isoColimit, Pi.isoLimit, biproduct.ΞΉ_Ο€, biproduct.ΞΉ_Ο€_assoc] theorem biproduct.map_eq_map' {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ b, f b ⟢ g b) : biproduct.map p = biproduct.map' p := by classical ext dsimp simp only [Discrete.natTrans_app, Limits.IsColimit.ΞΉ_map_assoc, Limits.IsLimit.map_Ο€, Category.assoc, ← Bicone.toCone_Ο€_app_mk, ← biproduct.bicone_Ο€, ← Bicone.toCocone_ΞΉ_app_mk, ← biproduct.bicone_ΞΉ] dsimp rw [biproduct.ΞΉ_Ο€_assoc, biproduct.ΞΉ_Ο€] split_ifs with h Β· subst h; simp Β· simp @[reassoc (attr := simp)] theorem biproduct.map_Ο€ {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) (j : J) : biproduct.map p ≫ biproduct.Ο€ g j = biproduct.Ο€ f j ≫ p j := Limits.IsLimit.map_Ο€ _ _ _ (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.ΞΉ_map {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) (j : J) : biproduct.ΞΉ f j ≫ biproduct.map p = p j ≫ biproduct.ΞΉ g j := by rw [biproduct.map_eq_map'] apply Limits.IsColimit.ΞΉ_map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.map_desc {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) {P : C} (k : βˆ€ j, g j ⟢ P) : biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by ext; simp @[reassoc (attr := simp)] theorem biproduct.lift_map {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] {P : C} (k : βˆ€ j, P ⟢ f j) (p : βˆ€ j, f j ⟢ g j) : biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by ext; simp /-- Given a collection of isomorphisms between corresponding summands of a pair of biproducts indexed by the same type, we obtain an isomorphism between the biproducts. -/ @[simps] def biproduct.mapIso {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ b, f b β‰… g b) : ⨁ f β‰… ⨁ g where hom := biproduct.map fun b => (p b).hom inv := biproduct.map fun b => (p b).inv instance biproduct.map_epi {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) [βˆ€ j, Epi (p j)] : Epi (biproduct.map p) := by classical have : biproduct.map p = (biproduct.isoCoproduct _).hom ≫ Sigma.map p ≫ (biproduct.isoCoproduct _).inv := by ext simp only [map_Ο€, isoCoproduct_hom, isoCoproduct_inv, Category.assoc, ΞΉ_desc_assoc, ΞΉ_colimMap_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app, colimit.ΞΉ_desc_assoc, Cofan.mk_pt, Cofan.mk_ΞΉ_app, ΞΉ_Ο€, ΞΉ_Ο€_assoc] split all_goals simp_all rw [this] infer_instance instance Pi.map_epi {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) [βˆ€ j, Epi (p j)] : Epi (Pi.map p) := by rw [show Pi.map p = (biproduct.isoProduct _).inv ≫ biproduct.map p ≫ (biproduct.isoProduct _).hom by aesop] infer_instance instance biproduct.map_mono {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) [βˆ€ j, Mono (p j)] : Mono (biproduct.map p) := by rw [show biproduct.map p = (biproduct.isoProduct _).hom ≫ Pi.map p ≫ (biproduct.isoProduct _).inv by aesop] infer_instance instance Sigma.map_mono {f g : J β†’ C} [HasBiproduct f] [HasBiproduct g] (p : βˆ€ j, f j ⟢ g j) [βˆ€ j, Mono (p j)] : Mono (Sigma.map p) := by rw [show Sigma.map p = (biproduct.isoCoproduct _).inv ≫ biproduct.map p ≫ (biproduct.isoCoproduct _).hom by aesop] infer_instance /-- Two biproducts which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. Unfortunately there are two natural ways to define each direction of this isomorphism (because it is true for both products and coproducts separately). We give the alternative definitions as lemmas below. -/ @[simps] def biproduct.whiskerEquiv {f : J β†’ C} {g : K β†’ C} (e : J ≃ K) (w : βˆ€ j, g (e j) β‰… f j) [HasBiproduct f] [HasBiproduct g] : ⨁ f β‰… ⨁ g where hom := biproduct.desc fun j => (w j).inv ≫ biproduct.ΞΉ g (e j) inv := biproduct.desc fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom ≫ biproduct.ΞΉ f _ lemma biproduct.whiskerEquiv_hom_eq_lift {f : J β†’ C} {g : K β†’ C} (e : J ≃ K) (w : βˆ€ j, g (e j) β‰… f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).hom = biproduct.lift fun k => biproduct.Ο€ f (e.symm k) ≫ (w _).inv ≫ eqToHom (by simp) := by simp only [whiskerEquiv_hom] ext k j by_cases h : k = e j Β· subst h simp Β· simp only [ΞΉ_desc_assoc, Category.assoc, ne_eq, lift_Ο€] rw [biproduct.ΞΉ_Ο€_ne, biproduct.ΞΉ_Ο€_ne_assoc] Β· simp Β· rintro rfl simp at h Β· exact Ne.symm h lemma biproduct.whiskerEquiv_inv_eq_lift {f : J β†’ C} {g : K β†’ C} (e : J ≃ K) (w : βˆ€ j, g (e j) β‰… f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).inv = biproduct.lift fun j => biproduct.Ο€ g (e j) ≫ (w j).hom := by simp only [whiskerEquiv_inv] ext j k by_cases h : k = e j Β· subst h simp only [ΞΉ_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm, Equiv.symm_apply_apply, eqToHom_comp_ΞΉ, Category.assoc, bicone_ΞΉ_Ο€_self, Category.comp_id, lift_Ο€, bicone_ΞΉ_Ο€_self_assoc] Β· simp only [ΞΉ_desc_assoc, Category.assoc, ne_eq, lift_Ο€] rw [biproduct.ΞΉ_Ο€_ne, biproduct.ΞΉ_Ο€_ne_assoc] Β· simp Β· exact h Β· rintro rfl simp at h attribute [local simp] Sigma.forall in instance {ΞΉ} (f : ΞΉ β†’ Type*) (g : (i : ΞΉ) β†’ (f i) β†’ C) [βˆ€ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : HasBiproduct fun p : Ξ£ i, f i => g p.1 p.2 where exists_biproduct := Nonempty.intro { bicone := { pt := ⨁ fun i => ⨁ g i ΞΉ := fun X => biproduct.ΞΉ (g X.1) X.2 ≫ biproduct.ΞΉ (fun i => ⨁ g i) X.1 Ο€ := fun X => biproduct.Ο€ (fun i => ⨁ g i) X.1 ≫ biproduct.Ο€ (g X.1) X.2 ΞΉ_Ο€ := fun ⟨j, x⟩ ⟨j', y⟩ => by split_ifs with h Β· obtain ⟨rfl, rfl⟩ := h simp Β· simp only [Sigma.mk.inj_iff, not_and] at h by_cases w : j = j' Β· cases w simp only [heq_eq_eq, forall_true_left] at h simp [biproduct.ΞΉ_Ο€_ne _ h] Β· simp [biproduct.ΞΉ_Ο€_ne_assoc _ w] } isBilimit := { isLimit := mkFanLimit _ (fun s => biproduct.lift fun b => biproduct.lift fun c => s.proj ⟨b, c⟩) isColimit := mkCofanColimit _ (fun s => biproduct.desc fun b => biproduct.desc fun c => s.inj ⟨b, c⟩) } } /-- An iterated biproduct is a biproduct over a sigma type. -/ @[simps] def biproductBiproductIso {ΞΉ} (f : ΞΉ β†’ Type*) (g : (i : ΞΉ) β†’ (f i) β†’ C) [βˆ€ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : (⨁ fun i => ⨁ g i) β‰… (⨁ fun p : Ξ£ i, f i => g p.1 p.2) where hom := biproduct.lift fun ⟨i, x⟩ => biproduct.Ο€ _ i ≫ biproduct.Ο€ _ x inv := biproduct.lift fun i => biproduct.lift fun x => biproduct.Ο€ _ (⟨i, x⟩ : Ξ£ i, f i) section Ο€Kernel section variable (f : J β†’ C) [HasBiproduct f] variable (p : J β†’ Prop) [HasBiproduct (Subtype.restrict p f)] /-- The canonical morphism from the biproduct over a restricted index type to the biproduct of the full index type. -/ def biproduct.fromSubtype : ⨁ Subtype.restrict p f ⟢ ⨁ f := biproduct.desc fun j => biproduct.ΞΉ _ j.val /-- The canonical morphism from a biproduct to the biproduct over a restriction of its index type. -/ def biproduct.toSubtype : ⨁ f ⟢ ⨁ Subtype.restrict p f := biproduct.lift fun _ => biproduct.Ο€ _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_Ο€ [DecidablePred p] (j : J) : biproduct.fromSubtype f p ≫ biproduct.Ο€ f j = if h : p j then biproduct.Ο€ (Subtype.restrict p f) ⟨j, h⟩ else 0 := by classical ext i; dsimp rw [biproduct.fromSubtype, biproduct.ΞΉ_desc_assoc, biproduct.ΞΉ_Ο€] by_cases h : p j Β· rw [dif_pos h, biproduct.ΞΉ_Ο€] split_ifs with h₁ hβ‚‚ hβ‚‚ exacts [rfl, False.elim (hβ‚‚ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val hβ‚‚)), rfl] Β· rw [dif_neg h, dif_neg (show (i : J) β‰  j from fun hβ‚‚ => h (hβ‚‚ β–Έ i.2)), comp_zero] theorem biproduct.fromSubtype_eq_lift [DecidablePred p] : biproduct.fromSubtype f p = biproduct.lift fun j => if h : p j then biproduct.Ο€ (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext _ _ (by simp) @[reassoc] -- Porting note: both version solved using simp theorem biproduct.fromSubtype_Ο€_subtype (j : Subtype p) : biproduct.fromSubtype f p ≫ biproduct.Ο€ f j = biproduct.Ο€ (Subtype.restrict p f) j := by classical ext rw [biproduct.fromSubtype, biproduct.ΞΉ_desc_assoc, biproduct.ΞΉ_Ο€, biproduct.ΞΉ_Ο€] split_ifs with h₁ hβ‚‚ hβ‚‚ exacts [rfl, False.elim (hβ‚‚ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val hβ‚‚)), rfl] @[reassoc (attr := simp)] theorem biproduct.toSubtype_Ο€ (j : Subtype p) : biproduct.toSubtype f p ≫ biproduct.Ο€ (Subtype.restrict p f) j = biproduct.Ο€ f j := biproduct.lift_Ο€ _ _ @[reassoc (attr := simp)] theorem biproduct.ΞΉ_toSubtype [DecidablePred p] (j : J) : biproduct.ΞΉ f j ≫ biproduct.toSubtype f p = if h : p j then biproduct.ΞΉ (Subtype.restrict p f) ⟨j, h⟩ else 0 := by classical ext i rw [biproduct.toSubtype, Category.assoc, biproduct.lift_Ο€, biproduct.ΞΉ_Ο€] by_cases h : p j Β· rw [dif_pos h, biproduct.ΞΉ_Ο€] split_ifs with h₁ hβ‚‚ hβ‚‚ exacts [rfl, False.elim (hβ‚‚ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val hβ‚‚)), rfl] Β· rw [dif_neg h, dif_neg (show j β‰  i from fun hβ‚‚ => h (hβ‚‚.symm β–Έ i.2)), zero_comp] theorem biproduct.toSubtype_eq_desc [DecidablePred p] : biproduct.toSubtype f p = biproduct.desc fun j => if h : p j then biproduct.ΞΉ (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext' _ _ (by simp) @[reassoc]
Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean
770
779
theorem biproduct.ΞΉ_toSubtype_subtype (j : Subtype p) : biproduct.ΞΉ f j ≫ biproduct.toSubtype f p = biproduct.ΞΉ (Subtype.restrict p f) j := by
classical ext rw [biproduct.toSubtype, Category.assoc, biproduct.lift_Ο€, biproduct.ΞΉ_Ο€, biproduct.ΞΉ_Ο€] split_ifs with h₁ hβ‚‚ hβ‚‚ exacts [rfl, False.elim (hβ‚‚ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val hβ‚‚)), rfl] @[reassoc (attr := simp)] theorem biproduct.ΞΉ_fromSubtype (j : Subtype p) :
/- Copyright (c) 2024 MarΓ­a InΓ©s de Frutos-FernΓ‘ndez. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: MarΓ­a InΓ©s de Frutos-FernΓ‘ndez -/ import Mathlib.Data.NNReal.Defs import Mathlib.RingTheory.Valuation.Basic /-! # Rank one valuations We define rank one valuations. ## Main Definitions * `RankOne` : A valuation `v` has rank one if it is nontrivial and its image is contained in `ℝβ‰₯0`. Note that this class contains the data of the inclusion of the codomain of `v` into `ℝβ‰₯0`. ## Tags valuation, rank one -/ noncomputable section open Function Multiplicative open scoped NNReal variable {R : Type*} [Ring R] {Ξ“β‚€ : Type*} [LinearOrderedCommGroupWithZero Ξ“β‚€] namespace Valuation /-- A valuation has rank one if it is nontrivial and its image is contained in `ℝβ‰₯0`. Note that this class includes the data of an inclusion morphism `Ξ“β‚€ β†’ ℝβ‰₯0`. -/ class RankOne (v : Valuation R Ξ“β‚€) where /-- The inclusion morphism from `Ξ“β‚€` to `ℝβ‰₯0`. -/ hom : Ξ“β‚€ β†’*β‚€ ℝβ‰₯0 strictMono' : StrictMono hom nontrivial' : βˆƒ r : R, v r β‰  0 ∧ v r β‰  1 namespace RankOne variable (v : Valuation R Ξ“β‚€) [RankOne v] lemma strictMono : StrictMono (hom v) := strictMono' lemma nontrivial : βˆƒ r : R, v r β‰  0 ∧ v r β‰  1 := nontrivial' /-- If `v` is a rank one valuation and `x : Ξ“β‚€` has image `0` under `RankOne.hom v`, then `x = 0`. -/
Mathlib/RingTheory/Valuation/RankOne.lean
51
55
theorem zero_of_hom_zero {x : Ξ“β‚€} (hx : hom v x = 0) : x = 0 := by
refine (eq_of_le_of_not_lt (zero_le' (a := x)) fun h_lt ↦ ?_).symm have hs := strictMono v h_lt rw [map_zero, hx] at hs exact hs.false
/- Copyright (c) 2021 Bryan Gin-ge Chen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bryan Gin-ge Chen, YaΓ«l Dillies -/ import Mathlib.Algebra.Group.Idempotent import Mathlib.Algebra.Ring.Equiv import Mathlib.Algebra.Ring.PUnit import Mathlib.Order.Hom.BoundedLattice import Mathlib.Tactic.Abel import Mathlib.Tactic.Ring /-! # Boolean rings A Boolean ring is a ring where multiplication is idempotent. They are equivalent to Boolean algebras. ## Main declarations * `BooleanRing`: a typeclass for rings where multiplication is idempotent. * `BooleanRing.toBooleanAlgebra`: Turn a Boolean ring into a Boolean algebra. * `BooleanAlgebra.toBooleanRing`: Turn a Boolean algebra into a Boolean ring. * `AsBoolAlg`: Type-synonym for the Boolean algebra associated to a Boolean ring. * `AsBoolRing`: Type-synonym for the Boolean ring associated to a Boolean algebra. ## Implementation notes We provide two ways of turning a Boolean algebra/ring into a Boolean ring/algebra: * Instances on the same type accessible in locales `BooleanAlgebraOfBooleanRing` and `BooleanRingOfBooleanAlgebra`. * Type-synonyms `AsBoolAlg` and `AsBoolRing`. At this point in time, it is not clear the first way is useful, but we keep it for educational purposes and because it is easier than dealing with `ofBoolAlg`/`toBoolAlg`/`ofBoolRing`/`toBoolRing` explicitly. ## Tags boolean ring, boolean algebra -/ open scoped symmDiff variable {Ξ± Ξ² Ξ³ : Type*} /-- A Boolean ring is a ring where multiplication is idempotent. -/ class BooleanRing (Ξ±) extends Ring Ξ± where /-- Multiplication in a boolean ring is idempotent. -/ isIdempotentElem (a : Ξ±) : IsIdempotentElem a namespace BooleanRing variable [BooleanRing Ξ±] (a b : Ξ±) @[scoped simp] lemma mul_self : a * a = a := IsIdempotentElem.eq (isIdempotentElem a) instance : Std.IdempotentOp (Ξ± := Ξ±) (Β· * Β·) := ⟨BooleanRing.mul_self⟩ @[scoped simp] theorem add_self : a + a = 0 := by have : a + a = a + a + (a + a) := calc a + a = (a + a) * (a + a) := by rw [mul_self] _ = a * a + a * a + (a * a + a * a) := by rw [add_mul, mul_add] _ = a + a + (a + a) := by rw [mul_self] rwa [right_eq_add] at this @[scoped simp] theorem neg_eq : -a = a := calc -a = -a + 0 := by rw [add_zero] _ = -a + -a + a := by rw [← neg_add_cancel, add_assoc] _ = a := by rw [add_self, zero_add] theorem add_eq_zero' : a + b = 0 ↔ a = b := calc a + b = 0 ↔ a = -b := add_eq_zero_iff_eq_neg _ ↔ a = b := by rw [neg_eq] @[simp]
Mathlib/Algebra/Ring/BooleanRing.lean
84
87
theorem mul_add_mul : a * b + b * a = 0 := by
have : a + b = a + b + (a * b + b * a) := calc a + b = (a + b) * (a + b) := by rw [mul_self]
/- Copyright (c) 2019 Johannes HΓΆlzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes HΓΆlzl, Patrick Massot, Casper Putz, Anne Baanen -/ import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.Data.Finite.Sum import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Fin import Mathlib.LinearAlgebra.Basis.Prod import Mathlib.LinearAlgebra.Basis.SMul import Mathlib.LinearAlgebra.Matrix.StdBasis import Mathlib.RingTheory.AlgebraTower import Mathlib.RingTheory.Ideal.Span /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. ## Main definitions In the list below, and in all this file, `R` is a commutative ring (semiring is sometimes enough), `M` and its variations are `R`-modules, `ΞΉ`, `ΞΊ`, `n` and `m` are finite types used for indexing. * `LinearMap.toMatrix`: given bases `v₁ : ΞΉ β†’ M₁` and `vβ‚‚ : ΞΊ β†’ Mβ‚‚`, the `R`-linear equivalence from `M₁ β†’β‚—[R] Mβ‚‚` to `Matrix ΞΊ ΞΉ R` * `Matrix.toLin`: the inverse of `LinearMap.toMatrix` * `LinearMap.toMatrix'`: the `R`-linear equivalence from `(m β†’ R) β†’β‚—[R] (n β†’ R)` to `Matrix m n R` (with the standard basis on `m β†’ R` and `n β†’ R`) * `Matrix.toLin'`: the inverse of `LinearMap.toMatrix'` * `algEquivMatrix`: given a basis indexed by `n`, the `R`-algebra equivalence between `R`-endomorphisms of `M` and `Matrix n n R` ## Issues This file was originally written without attention to non-commutative rings, and so mostly only works in the commutative setting. This should be fixed. In particular, `Matrix.mulVec` gives us a linear equivalence `Matrix m n R ≃ₗ[R] (n β†’ R) β†’β‚—[Rᡐᡒᡖ] (m β†’ R)` while `Matrix.vecMul` gives us a linear equivalence `Matrix m n R ≃ₗ[Rᡐᡒᡖ] (m β†’ R) β†’β‚—[R] (n β†’ R)`. At present, the first equivalence is developed in detail but only for commutative rings (and we omit the distinction between `Rᡐᡒᡖ` and `R`), while the second equivalence is developed only in brief, but for not-necessarily-commutative rings. Naming is slightly inconsistent between the two developments. In the original (commutative) development `linear` is abbreviated to `lin`, although this is not consistent with the rest of mathlib. In the new (non-commutative) development `linear` is not abbreviated, and declarations use `_right` to indicate they use the right action of matrices on vectors (via `Matrix.vecMul`). When the two developments are made uniform, the names should be made uniform, too, by choosing between `linear` and `lin` consistently, and (presumably) adding `_left` where necessary. ## Tags linear_map, matrix, linear_equiv, diagonal, det, trace -/ noncomputable section open LinearMap Matrix Set Submodule section ToMatrixRight variable {R : Type*} [Semiring R] variable {l m n : Type*} /-- `Matrix.vecMul M` is a linear map. -/ def Matrix.vecMulLinear [Fintype m] (M : Matrix m n R) : (m β†’ R) β†’β‚—[R] n β†’ R where toFun x := x α΅₯* M map_add' _ _ := funext fun _ ↦ add_dotProduct _ _ _ map_smul' _ _ := funext fun _ ↦ smul_dotProduct _ _ _ @[simp] theorem Matrix.vecMulLinear_apply [Fintype m] (M : Matrix m n R) (x : m β†’ R) : M.vecMulLinear x = x α΅₯* M := rfl theorem Matrix.coe_vecMulLinear [Fintype m] (M : Matrix m n R) : (M.vecMulLinear : _ β†’ _) = M.vecMul := rfl variable [Fintype m] theorem range_vecMulLinear (M : Matrix m n R) : LinearMap.range M.vecMulLinear = span R (range M.row) := by letI := Classical.decEq m simp_rw [range_eq_map, ← iSup_range_single, Submodule.map_iSup, range_eq_map, ← Ideal.span_singleton_one, Ideal.span, Submodule.map_span, image_image, image_singleton, Matrix.vecMulLinear_apply, iSup_span, range_eq_iUnion, iUnion_singleton_eq_range, LinearMap.single, LinearMap.coe_mk, AddHom.coe_mk, row_def] unfold vecMul simp_rw [single_dotProduct, one_mul] theorem Matrix.vecMul_injective_iff {R : Type*} [Ring R] {M : Matrix m n R} : Function.Injective M.vecMul ↔ LinearIndependent R M.row := by rw [← coe_vecMulLinear] simp only [← LinearMap.ker_eq_bot, Fintype.linearIndependent_iff, Submodule.eq_bot_iff, LinearMap.mem_ker, vecMulLinear_apply, row_def] refine ⟨fun h c h0 ↦ congr_fun <| h c ?_, fun h c h0 ↦ funext <| h c ?_⟩ Β· rw [← h0] ext i simp [vecMul, dotProduct] Β· rw [← h0] ext j simp [vecMul, dotProduct] lemma Matrix.linearIndependent_rows_of_isUnit {R : Type*} [Ring R] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.row := by rw [← Matrix.vecMul_injective_iff] exact Matrix.vecMul_injective_of_isUnit ha section variable [DecidableEq m] /-- Linear maps `(m β†’ R) β†’β‚—[R] (n β†’ R)` are linearly equivalent over `Rᡐᡒᡖ` to `Matrix m n R`, by having matrices act by right multiplication. -/ def LinearMap.toMatrixRight' : ((m β†’ R) β†’β‚—[R] n β†’ R) ≃ₗ[Rᡐᡒᡖ] Matrix m n R where toFun f i j := f (single R (fun _ ↦ R) i 1) j invFun := Matrix.vecMulLinear right_inv M := by ext i j simp left_inv f := by apply (Pi.basisFun R m).ext intro j; ext i simp map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent over `Rᡐᡒᡖ` to a linear map `(m β†’ R) β†’β‚—[R] (n β†’ R)`, by having matrices act by right multiplication. -/ abbrev Matrix.toLinearMapRight' [DecidableEq m] : Matrix m n R ≃ₗ[Rᡐᡒᡖ] (m β†’ R) β†’β‚—[R] n β†’ R := LinearEquiv.symm LinearMap.toMatrixRight' @[simp] theorem Matrix.toLinearMapRight'_apply (M : Matrix m n R) (v : m β†’ R) : (Matrix.toLinearMapRight') M v = v α΅₯* M := rfl @[simp] theorem Matrix.toLinearMapRight'_mul [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLinearMapRight' (M * N) = (Matrix.toLinearMapRight' N).comp (Matrix.toLinearMapRight' M) := LinearMap.ext fun _x ↦ (vecMul_vecMul _ M N).symm theorem Matrix.toLinearMapRight'_mul_apply [Fintype l] [DecidableEq l] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLinearMapRight' (M * N) x = Matrix.toLinearMapRight' N (Matrix.toLinearMapRight' M x) := (vecMul_vecMul _ M N).symm @[simp] theorem Matrix.toLinearMapRight'_one : Matrix.toLinearMapRight' (1 : Matrix m m R) = LinearMap.id := by ext simp [Module.End.one_apply] /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `n β†’ A` and `m β†’ A` corresponding to `M.vecMul` and `M'.vecMul`. -/ @[simps] def Matrix.toLinearEquivRight'OfInv [Fintype n] [DecidableEq n] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (n β†’ R) ≃ₗ[R] m β†’ R := { LinearMap.toMatrixRight'.symm M' with toFun := Matrix.toLinearMapRight' M' invFun := Matrix.toLinearMapRight' M left_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hM'M, Matrix.toLinearMapRight'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLinearMapRight'_mul_apply, hMM', Matrix.toLinearMapRight'_one, id_apply] } end end ToMatrixRight /-! From this point on, we only work with commutative rings, and fail to distinguish between `Rᡐᡒᡖ` and `R`. This should eventually be remedied. -/ section mulVec variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} /-- `Matrix.mulVec M` is a linear map. -/ def Matrix.mulVecLin [Fintype n] (M : Matrix m n R) : (n β†’ R) β†’β‚—[R] m β†’ R where toFun := M.mulVec map_add' _ _ := funext fun _ ↦ dotProduct_add _ _ _ map_smul' _ _ := funext fun _ ↦ dotProduct_smul _ _ _ theorem Matrix.coe_mulVecLin [Fintype n] (M : Matrix m n R) : (M.mulVecLin : _ β†’ _) = M.mulVec := rfl @[simp] theorem Matrix.mulVecLin_apply [Fintype n] (M : Matrix m n R) (v : n β†’ R) : M.mulVecLin v = M *α΅₯ v := rfl @[simp] theorem Matrix.mulVecLin_zero [Fintype n] : Matrix.mulVecLin (0 : Matrix m n R) = 0 := LinearMap.ext zero_mulVec @[simp] theorem Matrix.mulVecLin_add [Fintype n] (M N : Matrix m n R) : (M + N).mulVecLin = M.mulVecLin + N.mulVecLin := LinearMap.ext fun _ ↦ add_mulVec _ _ _ @[simp] theorem Matrix.mulVecLin_transpose [Fintype m] (M : Matrix m n R) : Mα΅€.mulVecLin = M.vecMulLinear := by ext; simp [mulVec_transpose] @[simp] theorem Matrix.vecMulLinear_transpose [Fintype n] (M : Matrix m n R) : Mα΅€.vecMulLinear = M.mulVecLin := by ext; simp [vecMul_transpose] theorem Matrix.mulVecLin_submatrix [Fintype n] [Fintype l] (f₁ : m β†’ k) (eβ‚‚ : n ≃ l) (M : Matrix k l R) : (M.submatrix f₁ eβ‚‚).mulVecLin = funLeft R R f₁ βˆ˜β‚— M.mulVecLin βˆ˜β‚— funLeft _ _ eβ‚‚.symm := LinearMap.ext fun _ ↦ submatrix_mulVec_equiv _ _ _ _ /-- A variant of `Matrix.mulVecLin_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.mulVecLin_reindex [Fintype n] [Fintype l] (e₁ : k ≃ m) (eβ‚‚ : l ≃ n) (M : Matrix k l R) : (reindex e₁ eβ‚‚ M).mulVecLin = ↑(LinearEquiv.funCongrLeft R R e₁.symm) βˆ˜β‚— M.mulVecLin βˆ˜β‚— ↑(LinearEquiv.funCongrLeft R R eβ‚‚) := Matrix.mulVecLin_submatrix _ _ _ variable [Fintype n] @[simp] theorem Matrix.mulVecLin_one [DecidableEq n] : Matrix.mulVecLin (1 : Matrix n n R) = LinearMap.id := by ext; simp [Matrix.one_apply, Pi.single_apply, eq_comm] @[simp] theorem Matrix.mulVecLin_mul [Fintype m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.mulVecLin (M * N) = (Matrix.mulVecLin M).comp (Matrix.mulVecLin N) := LinearMap.ext fun _ ↦ (mulVec_mulVec _ _ _).symm theorem Matrix.ker_mulVecLin_eq_bot_iff {M : Matrix m n R} : (LinearMap.ker M.mulVecLin) = βŠ₯ ↔ βˆ€ v, M *α΅₯ v = 0 β†’ v = 0 := by simp only [Submodule.eq_bot_iff, LinearMap.mem_ker, Matrix.mulVecLin_apply] theorem Matrix.range_mulVecLin (M : Matrix m n R) : LinearMap.range M.mulVecLin = span R (range M.col) := by rw [← vecMulLinear_transpose, range_vecMulLinear, row_transpose] theorem Matrix.mulVec_injective_iff {R : Type*} [CommRing R] {M : Matrix m n R} : Function.Injective M.mulVec ↔ LinearIndependent R M.col := by change Function.Injective (fun x ↦ _) ↔ _ simp_rw [← M.vecMul_transpose, vecMul_injective_iff, row_transpose] lemma Matrix.linearIndependent_cols_of_isUnit {R : Type*} [CommRing R] [Fintype m] {A : Matrix m m R} [DecidableEq m] (ha : IsUnit A) : LinearIndependent R A.col := by rw [← Matrix.mulVec_injective_iff] exact Matrix.mulVec_injective_of_isUnit ha end mulVec section ToMatrix' variable {R : Type*} [CommSemiring R] variable {k l m n : Type*} [DecidableEq n] [Fintype n] /-- Linear maps `(n β†’ R) β†’β‚—[R] (m β†’ R)` are linearly equivalent to `Matrix m n R`. -/ def LinearMap.toMatrix' : ((n β†’ R) β†’β‚—[R] m β†’ R) ≃ₗ[R] Matrix m n R where toFun f := of fun i j ↦ f (Pi.single j 1) i invFun := Matrix.mulVecLin right_inv M := by ext i j simp only [Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply] left_inv f := by apply (Pi.basisFun R n).ext intro j; ext i simp only [Pi.basisFun_apply, Matrix.mulVec_single_one, Matrix.mulVecLin_apply, of_apply, transpose_apply] map_add' f g := by ext i j simp only [Pi.add_apply, LinearMap.add_apply, of_apply, Matrix.add_apply] map_smul' c f := by ext i j simp only [Pi.smul_apply, LinearMap.smul_apply, RingHom.id_apply, of_apply, Matrix.smul_apply] /-- A `Matrix m n R` is linearly equivalent to a linear map `(n β†’ R) β†’β‚—[R] (m β†’ R)`. Note that the forward-direction does not require `DecidableEq` and is `Matrix.vecMulLin`. -/ def Matrix.toLin' : Matrix m n R ≃ₗ[R] (n β†’ R) β†’β‚—[R] m β†’ R := LinearMap.toMatrix'.symm theorem Matrix.toLin'_apply' (M : Matrix m n R) : Matrix.toLin' M = M.mulVecLin := rfl @[simp] theorem LinearMap.toMatrix'_symm : (LinearMap.toMatrix'.symm : Matrix m n R ≃ₗ[R] _) = Matrix.toLin' := rfl @[simp] theorem Matrix.toLin'_symm : (Matrix.toLin'.symm : ((n β†’ R) β†’β‚—[R] m β†’ R) ≃ₗ[R] _) = LinearMap.toMatrix' := rfl @[simp] theorem LinearMap.toMatrix'_toLin' (M : Matrix m n R) : LinearMap.toMatrix' (Matrix.toLin' M) = M := LinearMap.toMatrix'.apply_symm_apply M @[simp] theorem Matrix.toLin'_toMatrix' (f : (n β†’ R) β†’β‚—[R] m β†’ R) : Matrix.toLin' (LinearMap.toMatrix' f) = f := Matrix.toLin'.apply_symm_apply f @[simp] theorem LinearMap.toMatrix'_apply (f : (n β†’ R) β†’β‚—[R] m β†’ R) (i j) : LinearMap.toMatrix' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp only [LinearMap.toMatrix', LinearEquiv.coe_mk, of_apply] congr! with i split_ifs with h Β· rw [h, Pi.single_eq_same] apply Pi.single_eq_of_ne h @[simp] theorem Matrix.toLin'_apply (M : Matrix m n R) (v : n β†’ R) : Matrix.toLin' M v = M *α΅₯ v := rfl @[simp] theorem Matrix.toLin'_one : Matrix.toLin' (1 : Matrix n n R) = LinearMap.id := Matrix.mulVecLin_one @[simp] theorem LinearMap.toMatrix'_id : LinearMap.toMatrix' (LinearMap.id : (n β†’ R) β†’β‚—[R] n β†’ R) = 1 := by ext rw [Matrix.one_apply, LinearMap.toMatrix'_apply, id_apply] @[simp] theorem LinearMap.toMatrix'_one : LinearMap.toMatrix' (1 : (n β†’ R) β†’β‚—[R] n β†’ R) = 1 := LinearMap.toMatrix'_id @[simp] theorem Matrix.toLin'_mul [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) : Matrix.toLin' (M * N) = (Matrix.toLin' M).comp (Matrix.toLin' N) := Matrix.mulVecLin_mul _ _ @[simp] theorem Matrix.toLin'_submatrix [Fintype l] [DecidableEq l] (f₁ : m β†’ k) (eβ‚‚ : n ≃ l) (M : Matrix k l R) : Matrix.toLin' (M.submatrix f₁ eβ‚‚) = funLeft R R f₁ βˆ˜β‚— (Matrix.toLin' M) βˆ˜β‚— funLeft _ _ eβ‚‚.symm := Matrix.mulVecLin_submatrix _ _ _ /-- A variant of `Matrix.toLin'_submatrix` that keeps around `LinearEquiv`s. -/ theorem Matrix.toLin'_reindex [Fintype l] [DecidableEq l] (e₁ : k ≃ m) (eβ‚‚ : l ≃ n) (M : Matrix k l R) : Matrix.toLin' (reindex e₁ eβ‚‚ M) = ↑(LinearEquiv.funCongrLeft R R e₁.symm) βˆ˜β‚— (Matrix.toLin' M) βˆ˜β‚— ↑(LinearEquiv.funCongrLeft R R eβ‚‚) := Matrix.mulVecLin_reindex _ _ _ /-- Shortcut lemma for `Matrix.toLin'_mul` and `LinearMap.comp_apply` -/ theorem Matrix.toLin'_mul_apply [Fintype m] [DecidableEq m] (M : Matrix l m R) (N : Matrix m n R) (x) : Matrix.toLin' (M * N) x = Matrix.toLin' M (Matrix.toLin' N x) := by rw [Matrix.toLin'_mul, LinearMap.comp_apply] theorem LinearMap.toMatrix'_comp [Fintype l] [DecidableEq l] (f : (n β†’ R) β†’β‚—[R] m β†’ R) (g : (l β†’ R) β†’β‚—[R] n β†’ R) : LinearMap.toMatrix' (f.comp g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := by suffices f.comp g = Matrix.toLin' (LinearMap.toMatrix' f * LinearMap.toMatrix' g) by rw [this, LinearMap.toMatrix'_toLin'] rw [Matrix.toLin'_mul, Matrix.toLin'_toMatrix', Matrix.toLin'_toMatrix'] theorem LinearMap.toMatrix'_mul [Fintype m] [DecidableEq m] (f g : (m β†’ R) β†’β‚—[R] m β†’ R) : LinearMap.toMatrix' (f * g) = LinearMap.toMatrix' f * LinearMap.toMatrix' g := LinearMap.toMatrix'_comp f g @[simp] theorem LinearMap.toMatrix'_algebraMap (x : R) : LinearMap.toMatrix' (algebraMap R (Module.End R (n β†’ R)) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, smul_eq_diagonal_mul] theorem Matrix.ker_toLin'_eq_bot_iff {M : Matrix n n R} : LinearMap.ker (Matrix.toLin' M) = βŠ₯ ↔ βˆ€ v, M *α΅₯ v = 0 β†’ v = 0 := Matrix.ker_mulVecLin_eq_bot_iff theorem Matrix.range_toLin' (M : Matrix m n R) : LinearMap.range (Matrix.toLin' M) = span R (range M.col) := Matrix.range_mulVecLin _ /-- If `M` and `M'` are each other's inverse matrices, they provide an equivalence between `m β†’ A` and `n β†’ A` corresponding to `M.mulVec` and `M'.mulVec`. -/ @[simps] def Matrix.toLin'OfInv [Fintype m] [DecidableEq m] {M : Matrix m n R} {M' : Matrix n m R} (hMM' : M * M' = 1) (hM'M : M' * M = 1) : (m β†’ R) ≃ₗ[R] n β†’ R := { Matrix.toLin' M' with toFun := Matrix.toLin' M' invFun := Matrix.toLin' M left_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hMM', Matrix.toLin'_one, id_apply] right_inv := fun x ↦ by rw [← Matrix.toLin'_mul_apply, hM'M, Matrix.toLin'_one, id_apply] } /-- Linear maps `(n β†’ R) β†’β‚—[R] (n β†’ R)` are algebra equivalent to `Matrix n n R`. -/ def LinearMap.toMatrixAlgEquiv' : ((n β†’ R) β†’β‚—[R] n β†’ R) ≃ₐ[R] Matrix n n R := AlgEquiv.ofLinearEquiv LinearMap.toMatrix' LinearMap.toMatrix'_one LinearMap.toMatrix'_mul /-- A `Matrix n n R` is algebra equivalent to a linear map `(n β†’ R) β†’β‚—[R] (n β†’ R)`. -/ def Matrix.toLinAlgEquiv' : Matrix n n R ≃ₐ[R] (n β†’ R) β†’β‚—[R] n β†’ R := LinearMap.toMatrixAlgEquiv'.symm @[simp] theorem LinearMap.toMatrixAlgEquiv'_symm : (LinearMap.toMatrixAlgEquiv'.symm : Matrix n n R ≃ₐ[R] _) = Matrix.toLinAlgEquiv' := rfl @[simp] theorem Matrix.toLinAlgEquiv'_symm : (Matrix.toLinAlgEquiv'.symm : ((n β†’ R) β†’β‚—[R] n β†’ R) ≃ₐ[R] _) = LinearMap.toMatrixAlgEquiv' := rfl @[simp] theorem LinearMap.toMatrixAlgEquiv'_toLinAlgEquiv' (M : Matrix n n R) : LinearMap.toMatrixAlgEquiv' (Matrix.toLinAlgEquiv' M) = M := LinearMap.toMatrixAlgEquiv'.apply_symm_apply M @[simp] theorem Matrix.toLinAlgEquiv'_toMatrixAlgEquiv' (f : (n β†’ R) β†’β‚—[R] n β†’ R) : Matrix.toLinAlgEquiv' (LinearMap.toMatrixAlgEquiv' f) = f := Matrix.toLinAlgEquiv'.apply_symm_apply f @[simp] theorem LinearMap.toMatrixAlgEquiv'_apply (f : (n β†’ R) β†’β‚—[R] n β†’ R) (i j) : LinearMap.toMatrixAlgEquiv' f i j = f (fun j' ↦ if j' = j then 1 else 0) i := by simp [LinearMap.toMatrixAlgEquiv'] @[simp] theorem Matrix.toLinAlgEquiv'_apply (M : Matrix n n R) (v : n β†’ R) : Matrix.toLinAlgEquiv' M v = M *α΅₯ v := rfl theorem Matrix.toLinAlgEquiv'_one : Matrix.toLinAlgEquiv' (1 : Matrix n n R) = LinearMap.id := Matrix.toLin'_one @[simp] theorem LinearMap.toMatrixAlgEquiv'_id : LinearMap.toMatrixAlgEquiv' (LinearMap.id : (n β†’ R) β†’β‚—[R] n β†’ R) = 1 := LinearMap.toMatrix'_id theorem LinearMap.toMatrixAlgEquiv'_comp (f g : (n β†’ R) β†’β‚—[R] n β†’ R) : LinearMap.toMatrixAlgEquiv' (f.comp g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrix'_comp _ _ theorem LinearMap.toMatrixAlgEquiv'_mul (f g : (n β†’ R) β†’β‚—[R] n β†’ R) : LinearMap.toMatrixAlgEquiv' (f * g) = LinearMap.toMatrixAlgEquiv' f * LinearMap.toMatrixAlgEquiv' g := LinearMap.toMatrixAlgEquiv'_comp f g end ToMatrix' section ToMatrix section Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Finite m] [DecidableEq n] variable {M₁ Mβ‚‚ : Type*} [AddCommMonoid M₁] [AddCommMonoid Mβ‚‚] [Module R M₁] [Module R Mβ‚‚] variable (v₁ : Basis n R M₁) (vβ‚‚ : Basis m R Mβ‚‚) /-- Given bases of two modules `M₁` and `Mβ‚‚` over a commutative ring `R`, we get a linear equivalence between linear maps `M₁ β†’β‚— Mβ‚‚` and matrices over `R` indexed by the bases. -/ def LinearMap.toMatrix : (M₁ β†’β‚—[R] Mβ‚‚) ≃ₗ[R] Matrix m n R := LinearEquiv.trans (LinearEquiv.arrowCongr v₁.equivFun vβ‚‚.equivFun) LinearMap.toMatrix' /-- `LinearMap.toMatrix'` is a particular case of `LinearMap.toMatrix`, for the standard basis `Pi.basisFun R n`. -/ theorem LinearMap.toMatrix_eq_toMatrix' : LinearMap.toMatrix (Pi.basisFun R n) (Pi.basisFun R n) = LinearMap.toMatrix' := rfl /-- Given bases of two modules `M₁` and `Mβ‚‚` over a commutative ring `R`, we get a linear equivalence between matrices over `R` indexed by the bases and linear maps `M₁ β†’β‚— Mβ‚‚`. -/ def Matrix.toLin : Matrix m n R ≃ₗ[R] M₁ β†’β‚—[R] Mβ‚‚ := (LinearMap.toMatrix v₁ vβ‚‚).symm /-- `Matrix.toLin'` is a particular case of `Matrix.toLin`, for the standard basis `Pi.basisFun R n`. -/ theorem Matrix.toLin_eq_toLin' : Matrix.toLin (Pi.basisFun R n) (Pi.basisFun R m) = Matrix.toLin' := rfl @[simp] theorem LinearMap.toMatrix_symm : (LinearMap.toMatrix v₁ vβ‚‚).symm = Matrix.toLin v₁ vβ‚‚ := rfl @[simp] theorem Matrix.toLin_symm : (Matrix.toLin v₁ vβ‚‚).symm = LinearMap.toMatrix v₁ vβ‚‚ := rfl @[simp] theorem Matrix.toLin_toMatrix (f : M₁ β†’β‚—[R] Mβ‚‚) : Matrix.toLin v₁ vβ‚‚ (LinearMap.toMatrix v₁ vβ‚‚ f) = f := by rw [← Matrix.toLin_symm, LinearEquiv.apply_symm_apply] @[simp] theorem LinearMap.toMatrix_toLin (M : Matrix m n R) : LinearMap.toMatrix v₁ vβ‚‚ (Matrix.toLin v₁ vβ‚‚ M) = M := by rw [← Matrix.toLin_symm, LinearEquiv.symm_apply_apply] theorem LinearMap.toMatrix_apply (f : M₁ β†’β‚—[R] Mβ‚‚) (i : m) (j : n) : LinearMap.toMatrix v₁ vβ‚‚ f i j = vβ‚‚.repr (f (v₁ j)) i := by rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearMap.toMatrix'_apply, LinearEquiv.arrowCongr_apply, Basis.equivFun_symm_apply, Finset.sum_eq_single j, if_pos rfl, one_smul, Basis.equivFun_apply] Β· intro j' _ hj' rw [if_neg hj', zero_smul] Β· intro hj have := Finset.mem_univ j contradiction theorem LinearMap.toMatrix_transpose_apply (f : M₁ β†’β‚—[R] Mβ‚‚) (j : n) : (LinearMap.toMatrix v₁ vβ‚‚ f)α΅€ j = vβ‚‚.repr (f (v₁ j)) := funext fun i ↦ f.toMatrix_apply _ _ i j theorem LinearMap.toMatrix_apply' (f : M₁ β†’β‚—[R] Mβ‚‚) (i : m) (j : n) : LinearMap.toMatrix v₁ vβ‚‚ f i j = vβ‚‚.repr (f (v₁ j)) i := LinearMap.toMatrix_apply v₁ vβ‚‚ f i j theorem LinearMap.toMatrix_transpose_apply' (f : M₁ β†’β‚—[R] Mβ‚‚) (j : n) : (LinearMap.toMatrix v₁ vβ‚‚ f)α΅€ j = vβ‚‚.repr (f (v₁ j)) := LinearMap.toMatrix_transpose_apply v₁ vβ‚‚ f j /-- This will be a special case of `LinearMap.toMatrix_id_eq_basis_toMatrix`. -/ theorem LinearMap.toMatrix_id : LinearMap.toMatrix v₁ v₁ id = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] @[simp] theorem LinearMap.toMatrix_one : LinearMap.toMatrix v₁ v₁ 1 = 1 := LinearMap.toMatrix_id v₁ @[simp] lemma LinearMap.toMatrix_singleton {ΞΉ : Type*} [Unique ΞΉ] (f : R β†’β‚—[R] R) (i j : ΞΉ) : f.toMatrix (.singleton ΞΉ R) (.singleton ΞΉ R) i j = f 1 := by simp [toMatrix, Subsingleton.elim j default] @[simp] theorem Matrix.toLin_one : Matrix.toLin v₁ v₁ 1 = LinearMap.id := by rw [← LinearMap.toMatrix_id v₁, Matrix.toLin_toMatrix] theorem LinearMap.toMatrix_reindexRange [DecidableEq M₁] (f : M₁ β†’β‚—[R] Mβ‚‚) (k : m) (i : n) : LinearMap.toMatrix v₁.reindexRange vβ‚‚.reindexRange f ⟨vβ‚‚ k, Set.mem_range_self k⟩ ⟨v₁ i, Set.mem_range_self i⟩ = LinearMap.toMatrix v₁ vβ‚‚ f k i := by simp_rw [LinearMap.toMatrix_apply, Basis.reindexRange_self, Basis.reindexRange_repr] @[simp] theorem LinearMap.toMatrix_algebraMap (x : R) : LinearMap.toMatrix v₁ v₁ (algebraMap R (Module.End R M₁) x) = scalar n x := by simp [Module.algebraMap_end_eq_smul_id, LinearMap.toMatrix_id, smul_eq_diagonal_mul] theorem LinearMap.toMatrix_mulVec_repr (f : M₁ β†’β‚—[R] Mβ‚‚) (x : M₁) : LinearMap.toMatrix v₁ vβ‚‚ f *α΅₯ v₁.repr x = vβ‚‚.repr (f x) := by ext i rw [← Matrix.toLin'_apply, LinearMap.toMatrix, LinearEquiv.trans_apply, Matrix.toLin'_toMatrix', LinearEquiv.arrowCongr_apply, vβ‚‚.equivFun_apply] congr exact v₁.equivFun.symm_apply_apply x @[simp] theorem LinearMap.toMatrix_basis_equiv [Fintype l] [DecidableEq l] (b : Basis l R M₁) (b' : Basis l R Mβ‚‚) : LinearMap.toMatrix b' b (b'.equiv b (Equiv.refl l) : Mβ‚‚ β†’β‚—[R] M₁) = 1 := by ext i j simp [LinearMap.toMatrix_apply, Matrix.one_apply, Finsupp.single_apply, eq_comm] theorem LinearMap.toMatrix_smulBasis_left {G} [Group G] [DistribMulAction G M₁] [SMulCommClass G R M₁] (g : G) (f : M₁ β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrix (g β€’ v₁) vβ‚‚ f = LinearMap.toMatrix v₁ vβ‚‚ (f βˆ˜β‚— DistribMulAction.toLinearMap _ _ g) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp theorem LinearMap.toMatrix_smulBasis_right {G} [Group G] [DistribMulAction G Mβ‚‚] [SMulCommClass G R Mβ‚‚] (g : G) (f : M₁ β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrix v₁ (g β€’ vβ‚‚) f = LinearMap.toMatrix v₁ vβ‚‚ (DistribMulAction.toLinearMap _ _ g⁻¹ βˆ˜β‚— f) := by ext rw [LinearMap.toMatrix_apply, LinearMap.toMatrix_apply] dsimp end Finite variable {R : Type*} [CommSemiring R] variable {l m n : Type*} [Fintype n] [Fintype m] [DecidableEq n] variable {M₁ Mβ‚‚ : Type*} [AddCommMonoid M₁] [AddCommMonoid Mβ‚‚] [Module R M₁] [Module R Mβ‚‚] variable (v₁ : Basis n R M₁) (vβ‚‚ : Basis m R Mβ‚‚) theorem Matrix.toLin_apply (M : Matrix m n R) (v : M₁) : Matrix.toLin v₁ vβ‚‚ M v = βˆ‘ j, (M *α΅₯ v₁.repr v) j β€’ vβ‚‚ j := show vβ‚‚.equivFun.symm (Matrix.toLin' M (v₁.repr v)) = _ by rw [Matrix.toLin'_apply, vβ‚‚.equivFun_symm_apply] @[simp] theorem Matrix.toLin_self (M : Matrix m n R) (i : n) : Matrix.toLin v₁ vβ‚‚ M (v₁ i) = βˆ‘ j, M j i β€’ vβ‚‚ j := by rw [Matrix.toLin_apply, Finset.sum_congr rfl fun j _hj ↦ ?_] rw [Basis.repr_self, Matrix.mulVec, dotProduct, Finset.sum_eq_single i, Finsupp.single_eq_same, mul_one] Β· intro i' _ i'_ne rw [Finsupp.single_eq_of_ne i'_ne.symm, mul_zero] Β· intros have := Finset.mem_univ i contradiction variable {M₃ : Type*} [AddCommMonoid M₃] [Module R M₃] (v₃ : Basis l R M₃) theorem LinearMap.toMatrix_comp [Finite l] [DecidableEq m] (f : Mβ‚‚ β†’β‚—[R] M₃) (g : M₁ β†’β‚—[R] Mβ‚‚) : LinearMap.toMatrix v₁ v₃ (f.comp g) = LinearMap.toMatrix vβ‚‚ v₃ f * LinearMap.toMatrix v₁ vβ‚‚ g := by simp_rw [LinearMap.toMatrix, LinearEquiv.trans_apply, LinearEquiv.arrowCongr_comp _ vβ‚‚.equivFun, LinearMap.toMatrix'_comp]
Mathlib/LinearAlgebra/Matrix/ToLin.lean
636
640
theorem LinearMap.toMatrix_mul (f g : M₁ β†’β‚—[R] M₁) : LinearMap.toMatrix v₁ v₁ (f * g) = LinearMap.toMatrix v₁ v₁ f * LinearMap.toMatrix v₁ v₁ g := by
rw [Module.End.mul_eq_comp, LinearMap.toMatrix_comp v₁ v₁ v₁ f g] lemma LinearMap.toMatrix_pow (f : M₁ β†’β‚—[R] M₁) (k : β„•) :
/- 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, Kenny Lau, Johan Commelin, Mario Carneiro, Kevin Buzzard, Amelia Livingston, Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Group.Multiset.Defs import Mathlib.Algebra.FreeMonoid.Basic import Mathlib.Algebra.Group.Idempotent import Mathlib.Algebra.Group.Nat.Hom import Mathlib.Algebra.Group.Submonoid.MulOpposite import Mathlib.Algebra.Group.Submonoid.Operations import Mathlib.Data.Fintype.EquivFin import Mathlib.Data.Int.Basic /-! # Submonoids: membership criteria In this file we prove various facts about membership in a submonoid: * `pow_mem`, `nsmul_mem`: if `x ∈ S` where `S` is a multiplicative (resp., additive) submonoid and `n` is a natural number, then `x^n` (resp., `n β€’ x`) belongs to `S`; * `mem_iSup_of_directed`, `coe_iSup_of_directed`, `mem_sSup_of_directedOn`, `coe_sSup_of_directedOn`: the supremum of a directed collection of submonoid is their union. * `sup_eq_range`, `mem_sup`: supremum of two submonoids `S`, `T` of a commutative monoid is the set of products; * `closure_singleton_eq`, `mem_closure_singleton`, `mem_closure_pair`: the multiplicative (resp., additive) closure of `{x}` consists of powers (resp., natural multiples) of `x`, and a similar result holds for the closure of `{x, y}`. ## Tags submonoid, submonoids -/ assert_not_exists MonoidWithZero variable {M A B : Type*} section Assoc variable [Monoid M] [SetLike B M] [SubmonoidClass B M] {S : B} end Assoc section NonAssoc variable [MulOneClass M] open Set namespace Submonoid -- TODO: this section can be generalized to `[SubmonoidClass B M] [CompleteLattice B]` -- such that `CompleteLattice.LE` coincides with `SetLike.LE` @[to_additive] theorem mem_iSup_of_directed {ΞΉ} [hΞΉ : Nonempty ΞΉ] {S : ΞΉ β†’ Submonoid M} (hS : Directed (Β· ≀ Β·) S) {x : M} : (x ∈ ⨆ i, S i) ↔ βˆƒ i, x ∈ S i := by refine ⟨?_, fun ⟨i, hi⟩ ↦ le_iSup S i hi⟩ suffices x ∈ closure (⋃ i, (S i : Set M)) β†’ βˆƒ i, x ∈ S i by simpa only [closure_iUnion, closure_eq (S _)] using this refine closure_induction (fun _ ↦ mem_iUnion.1) ?_ ?_ Β· exact hΞΉ.elim fun i ↦ ⟨i, (S i).one_mem⟩ Β· rintro x y - - ⟨i, hi⟩ ⟨j, hj⟩ rcases hS i j with ⟨k, hki, hkj⟩ exact ⟨k, (S k).mul_mem (hki hi) (hkj hj)⟩ @[to_additive] theorem coe_iSup_of_directed {ΞΉ} [Nonempty ΞΉ] {S : ΞΉ β†’ Submonoid M} (hS : Directed (Β· ≀ Β·) S) : ((⨆ i, S i : Submonoid M) : Set M) = ⋃ i, S i := Set.ext fun x ↦ by simp [mem_iSup_of_directed hS] @[to_additive] theorem mem_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty) (hS : DirectedOn (Β· ≀ Β·) S) {x : M} : x ∈ sSup S ↔ βˆƒ s ∈ S, x ∈ s := by haveI : Nonempty S := Sne.to_subtype simp [sSup_eq_iSup', mem_iSup_of_directed hS.directed_val, SetCoe.exists, Subtype.coe_mk] @[to_additive] theorem coe_sSup_of_directedOn {S : Set (Submonoid M)} (Sne : S.Nonempty) (hS : DirectedOn (Β· ≀ Β·) S) : (↑(sSup S) : Set M) = ⋃ s ∈ S, ↑s := Set.ext fun x => by simp [mem_sSup_of_directedOn Sne hS] @[to_additive]
Mathlib/Algebra/Group/Submonoid/Membership.lean
84
88
theorem mem_sup_left {S T : Submonoid M} : βˆ€ {x : M}, x ∈ S β†’ x ∈ S βŠ” T := by
rw [← SetLike.le_def] exact le_sup_left @[to_additive]
/- 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 -/ import Mathlib.Data.Set.Function import Mathlib.Logic.Pairwise import Mathlib.Logic.Relation /-! # Relations holding pairwise This file develops pairwise relations and defines pairwise disjoint indexed sets. We also prove many basic facts about `Pairwise`. It is possible that an intermediate file, with more imports than `Logic.Pairwise` but not importing `Data.Set.Function` would be appropriate to hold many of these basic facts. ## Main declarations * `Set.PairwiseDisjoint`: `s.PairwiseDisjoint f` states that images under `f` of distinct elements of `s` are either equal or `Disjoint`. ## Notes The spelling `s.PairwiseDisjoint id` is preferred over `s.Pairwise Disjoint` to permit dot notation on `Set.PairwiseDisjoint`, even though the latter unfolds to something nicer. -/ open Function Order Set variable {Ξ± Ξ² Ξ³ ΞΉ ΞΉ' : Type*} {r p : Ξ± β†’ Ξ± β†’ Prop} section Pairwise variable {f g : ΞΉ β†’ Ξ±} {s t : Set Ξ±} {a b : Ξ±} theorem pairwise_on_bool (hr : Symmetric r) {a b : Ξ±} : Pairwise (r on fun c => cond c a b) ↔ r a b := by simpa [Pairwise, Function.onFun] using @hr a b theorem pairwise_disjoint_on_bool [PartialOrder Ξ±] [OrderBot Ξ±] {a b : Ξ±} : Pairwise (Disjoint on fun c => cond c a b) ↔ Disjoint a b := pairwise_on_bool Disjoint.symm theorem Symmetric.pairwise_on [LinearOrder ΞΉ] (hr : Symmetric r) (f : ΞΉ β†’ Ξ±) : Pairwise (r on f) ↔ βˆ€ ⦃m n⦄, m < n β†’ r (f m) (f n) := ⟨fun h _m _n hmn => h hmn.ne, fun h _m _n hmn => hmn.lt_or_lt.elim (@h _ _) fun h' => hr (h h')⟩ theorem pairwise_disjoint_on [PartialOrder Ξ±] [OrderBot Ξ±] [LinearOrder ΞΉ] (f : ΞΉ β†’ Ξ±) : Pairwise (Disjoint on f) ↔ βˆ€ ⦃m n⦄, m < n β†’ Disjoint (f m) (f n) := Symmetric.pairwise_on Disjoint.symm f theorem pairwise_disjoint_mono [PartialOrder Ξ±] [OrderBot Ξ±] (hs : Pairwise (Disjoint on f)) (h : g ≀ f) : Pairwise (Disjoint on g) := hs.mono fun i j hij => Disjoint.mono (h i) (h j) hij theorem Pairwise.disjoint_extend_bot [PartialOrder Ξ³] [OrderBot Ξ³] {e : Ξ± β†’ Ξ²} {f : Ξ± β†’ Ξ³} (hf : Pairwise (Disjoint on f)) (he : FactorsThrough f e) : Pairwise (Disjoint on extend e f βŠ₯) := by intro b₁ bβ‚‚ hne rcases em (βˆƒ a₁, e a₁ = b₁) with ⟨a₁, rfl⟩ | hb₁ Β· rcases em (βˆƒ aβ‚‚, e aβ‚‚ = bβ‚‚) with ⟨aβ‚‚, rfl⟩ | hbβ‚‚ Β· simpa only [onFun, he.extend_apply] using hf (ne_of_apply_ne e hne) Β· simpa only [onFun, extend_apply' _ _ _ hbβ‚‚] using disjoint_bot_right Β· simpa only [onFun, extend_apply' _ _ _ hb₁] using disjoint_bot_left namespace Set theorem Pairwise.mono (h : t βŠ† s) (hs : s.Pairwise r) : t.Pairwise r := fun _x xt _y yt => hs (h xt) (h yt) theorem Pairwise.mono' (H : r ≀ p) (hr : s.Pairwise r) : s.Pairwise p := hr.imp H theorem pairwise_top (s : Set Ξ±) : s.Pairwise ⊀ := pairwise_of_forall s _ fun _ _ => trivial protected theorem Subsingleton.pairwise (h : s.Subsingleton) (r : Ξ± β†’ Ξ± β†’ Prop) : s.Pairwise r := fun _x hx _y hy hne => (hne (h hx hy)).elim @[simp] theorem pairwise_empty (r : Ξ± β†’ Ξ± β†’ Prop) : (βˆ… : Set Ξ±).Pairwise r := subsingleton_empty.pairwise r @[simp] theorem pairwise_singleton (a : Ξ±) (r : Ξ± β†’ Ξ± β†’ Prop) : Set.Pairwise {a} r := subsingleton_singleton.pairwise r theorem pairwise_iff_of_refl [IsRefl Ξ± r] : s.Pairwise r ↔ βˆ€ ⦃a⦄, a ∈ s β†’ βˆ€ ⦃b⦄, b ∈ s β†’ r a b := forallβ‚„_congr fun _ _ _ _ => or_iff_not_imp_left.symm.trans <| or_iff_right_of_imp of_eq alias ⟨Pairwise.of_refl, _⟩ := pairwise_iff_of_refl theorem Nonempty.pairwise_iff_exists_forall [IsEquiv Ξ± r] {s : Set ΞΉ} (hs : s.Nonempty) : s.Pairwise (r on f) ↔ βˆƒ z, βˆ€ x ∈ s, r (f x) z := by constructor Β· rcases hs with ⟨y, hy⟩ refine fun H => ⟨f y, fun x hx => ?_⟩ rcases eq_or_ne x y with (rfl | hne) Β· apply IsRefl.refl Β· exact H hx hy hne Β· rintro ⟨z, hz⟩ x hx y hy _ exact @IsTrans.trans Ξ± r _ (f x) z (f y) (hz _ hx) (IsSymm.symm _ _ <| hz _ hy) /-- For a nonempty set `s`, a function `f` takes pairwise equal values on `s` if and only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also `Set.pairwise_eq_iff_exists_eq` for a version that assumes `[Nonempty ΞΉ]` instead of `Set.Nonempty s`. -/ theorem Nonempty.pairwise_eq_iff_exists_eq {s : Set Ξ±} (hs : s.Nonempty) {f : Ξ± β†’ ΞΉ} : (s.Pairwise fun x y => f x = f y) ↔ βˆƒ z, βˆ€ x ∈ s, f x = z := hs.pairwise_iff_exists_forall theorem pairwise_iff_exists_forall [Nonempty ΞΉ] (s : Set Ξ±) (f : Ξ± β†’ ΞΉ) {r : ΞΉ β†’ ΞΉ β†’ Prop} [IsEquiv ΞΉ r] : s.Pairwise (r on f) ↔ βˆƒ z, βˆ€ x ∈ s, r (f x) z := by rcases s.eq_empty_or_nonempty with (rfl | hne) Β· simp Β· exact hne.pairwise_iff_exists_forall /-- A function `f : Ξ± β†’ ΞΉ` with nonempty codomain takes pairwise equal values on a set `s` if and only if for some `z` in the codomain, `f` takes value `z` on all `x ∈ s`. See also `Set.Nonempty.pairwise_eq_iff_exists_eq` for a version that assumes `Set.Nonempty s` instead of `[Nonempty ΞΉ]`. -/ theorem pairwise_eq_iff_exists_eq [Nonempty ΞΉ] (s : Set Ξ±) (f : Ξ± β†’ ΞΉ) : (s.Pairwise fun x y => f x = f y) ↔ βˆƒ z, βˆ€ x ∈ s, f x = z := pairwise_iff_exists_forall s f theorem pairwise_union : (s βˆͺ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ βˆ€ a ∈ s, βˆ€ b ∈ t, a β‰  b β†’ r a b ∧ r b a := by simp only [Set.Pairwise, mem_union, or_imp, forall_and] aesop theorem pairwise_union_of_symmetric (hr : Symmetric r) : (s βˆͺ t).Pairwise r ↔ s.Pairwise r ∧ t.Pairwise r ∧ βˆ€ a ∈ s, βˆ€ b ∈ t, a β‰  b β†’ r a b := pairwise_union.trans <| by simp only [hr.iff, and_self_iff] theorem pairwise_insert : (insert a s).Pairwise r ↔ s.Pairwise r ∧ βˆ€ b ∈ s, a β‰  b β†’ r a b ∧ r b a := by simp only [insert_eq, pairwise_union, pairwise_singleton, true_and, mem_singleton_iff, forall_eq] theorem pairwise_insert_of_not_mem (ha : a βˆ‰ s) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ βˆ€ b ∈ s, r a b ∧ r b a := pairwise_insert.trans <| and_congr_right' <| forallβ‚‚_congr fun b hb => by simp [(ne_of_mem_of_not_mem hb ha).symm] protected theorem Pairwise.insert (hs : s.Pairwise r) (h : βˆ€ b ∈ s, a β‰  b β†’ r a b ∧ r b a) : (insert a s).Pairwise r := pairwise_insert.2 ⟨hs, h⟩ theorem Pairwise.insert_of_not_mem (ha : a βˆ‰ s) (hs : s.Pairwise r) (h : βˆ€ b ∈ s, r a b ∧ r b a) : (insert a s).Pairwise r := (pairwise_insert_of_not_mem ha).2 ⟨hs, h⟩ theorem pairwise_insert_of_symmetric (hr : Symmetric r) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ βˆ€ b ∈ s, a β‰  b β†’ r a b := by simp only [pairwise_insert, hr.iff a, and_self_iff] theorem pairwise_insert_of_symmetric_of_not_mem (hr : Symmetric r) (ha : a βˆ‰ s) : (insert a s).Pairwise r ↔ s.Pairwise r ∧ βˆ€ b ∈ s, r a b := by simp only [pairwise_insert_of_not_mem ha, hr.iff a, and_self_iff] theorem Pairwise.insert_of_symmetric (hs : s.Pairwise r) (hr : Symmetric r) (h : βˆ€ b ∈ s, a β‰  b β†’ r a b) : (insert a s).Pairwise r := (pairwise_insert_of_symmetric hr).2 ⟨hs, h⟩ @[deprecated Pairwise.insert_of_symmetric (since := "2025-03-19")] theorem Pairwise.insert_of_symmetric_of_not_mem (hs : s.Pairwise r) (hr : Symmetric r) (ha : a βˆ‰ s) (h : βˆ€ b ∈ s, r a b) : (insert a s).Pairwise r := (pairwise_insert_of_symmetric_of_not_mem hr ha).2 ⟨hs, h⟩ theorem pairwise_pair : Set.Pairwise {a, b} r ↔ a β‰  b β†’ r a b ∧ r b a := by simp [pairwise_insert] theorem pairwise_pair_of_symmetric (hr : Symmetric r) : Set.Pairwise {a, b} r ↔ a β‰  b β†’ r a b := by simp [pairwise_insert_of_symmetric hr] theorem pairwise_univ : (univ : Set Ξ±).Pairwise r ↔ Pairwise r := by simp only [Set.Pairwise, Pairwise, mem_univ, forall_const] @[simp] theorem pairwise_bot_iff : s.Pairwise (βŠ₯ : Ξ± β†’ Ξ± β†’ Prop) ↔ (s : Set Ξ±).Subsingleton := ⟨fun h _a ha _b hb => h.eq ha hb id, fun h => h.pairwise _⟩ alias ⟨Pairwise.subsingleton, _⟩ := pairwise_bot_iff /-- See also `Function.injective_iff_pairwise_ne` -/ lemma injOn_iff_pairwise_ne {s : Set ΞΉ} : InjOn f s ↔ s.Pairwise (f Β· β‰  f Β·) := by simp only [InjOn, Set.Pairwise, not_imp_not] alias ⟨InjOn.pairwise_ne, _⟩ := injOn_iff_pairwise_ne protected theorem Pairwise.image {s : Set ΞΉ} (h : s.Pairwise (r on f)) : (f '' s).Pairwise r := forall_mem_image.2 fun _x hx ↦ forall_mem_image.2 fun _y hy hne ↦ h hx hy <| ne_of_apply_ne _ hne /-- See also `Set.Pairwise.image`. -/
Mathlib/Data/Set/Pairwise/Basic.lean
196
197
theorem InjOn.pairwise_image {s : Set ΞΉ} (h : s.InjOn f) : (f '' s).Pairwise r ↔ s.Pairwise (r on f) := by
/- Copyright (c) 2021 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Basis.Submodule import Mathlib.LinearAlgebra.Dimension.Finrank import Mathlib.LinearAlgebra.InvariantBasisNumber /-! # Lemmas about rank and finrank in rings satisfying strong rank condition. ## Main statements For modules over rings satisfying the rank condition * `Basis.le_span`: the cardinality of a basis is bounded by the cardinality of any spanning set For modules over rings satisfying the strong rank condition * `linearIndependent_le_span`: For any linearly independent family `v : ΞΉ β†’ M` and any finite spanning set `w : Set M`, the cardinality of `ΞΉ` is bounded by the cardinality of `w`. * `linearIndependent_le_basis`: If `b` is a basis for a module `M`, and `s` is a linearly independent set, then the cardinality of `s` is bounded by the cardinality of `b`. For modules over rings with invariant basis number (including all commutative rings and all noetherian rings) * `mk_eq_mk_of_basis`: the dimension theorem, any two bases of the same vector space have the same cardinality. ## Additional definition * `Algebra.IsQuadraticExtension`: An extension of rings `R βŠ† S` is quadratic if `S` is a free `R`-algebra of rank `2`. -/ noncomputable section universe u v w w' variable {R : Type u} {M : Type v} [Semiring R] [AddCommMonoid M] [Module R M] variable {ΞΉ : Type w} {ΞΉ' : Type w'} open Cardinal Basis Submodule Function Set Module attribute [local instance] nontrivial_of_invariantBasisNumber section InvariantBasisNumber variable [InvariantBasisNumber R] /-- The dimension theorem: if `v` and `v'` are two bases, their index types have the same cardinalities. -/ theorem mk_eq_mk_of_basis (v : Basis ΞΉ R M) (v' : Basis ΞΉ' R M) : Cardinal.lift.{w'} #ΞΉ = Cardinal.lift.{w} #ΞΉ' := by classical haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite ΞΉ Β· -- `v` is a finite basis, so by `basis_finite_of_finite_spans` so is `v'`. -- haveI : Finite (range v) := Set.finite_range v haveI := basis_finite_of_finite_spans (Set.finite_range v) v.span_eq v' cases nonempty_fintype ΞΉ' -- We clean up a little: rw [Cardinal.mk_fintype, Cardinal.mk_fintype] simp only [Cardinal.lift_natCast, Nat.cast_inj] -- Now we can use invariant basis number to show they have the same cardinality. apply card_eq_of_linearEquiv R exact (Finsupp.linearEquivFunOnFinite R R ΞΉ).symm.trans v.repr.symm β‰ͺ≫ₗ v'.repr β‰ͺ≫ₗ Finsupp.linearEquivFunOnFinite R R ΞΉ' Β· -- `v` is an infinite basis, -- so by `infinite_basis_le_maximal_linearIndependent`, `v'` is at least as big, -- and then applying `infinite_basis_le_maximal_linearIndependent` again -- we see they have the same cardinality. have w₁ := infinite_basis_le_maximal_linearIndependent' v _ v'.linearIndependent v'.maximal rcases Cardinal.lift_mk_le'.mp w₁ with ⟨f⟩ haveI : Infinite ΞΉ' := Infinite.of_injective f f.2 have wβ‚‚ := infinite_basis_le_maximal_linearIndependent' v' _ v.linearIndependent v.maximal exact le_antisymm w₁ wβ‚‚ /-- Given two bases indexed by `ΞΉ` and `ΞΉ'` of an `R`-module, where `R` satisfies the invariant basis number property, an equiv `ΞΉ ≃ ΞΉ'`. -/ def Basis.indexEquiv (v : Basis ΞΉ R M) (v' : Basis ΞΉ' R M) : ΞΉ ≃ ΞΉ' := (Cardinal.lift_mk_eq'.1 <| mk_eq_mk_of_basis v v').some theorem mk_eq_mk_of_basis' {ΞΉ' : Type w} (v : Basis ΞΉ R M) (v' : Basis ΞΉ' R M) : #ΞΉ = #ΞΉ' := Cardinal.lift_inj.1 <| mk_eq_mk_of_basis v v' end InvariantBasisNumber section RankCondition variable [RankCondition R] /-- An auxiliary lemma for `Basis.le_span`. If `R` satisfies the rank condition, then for any finite basis `b : Basis ΞΉ R M`, and any finite spanning set `w : Set M`, the cardinality of `ΞΉ` is bounded by the cardinality of `w`. -/ theorem Basis.le_span'' {ΞΉ : Type*} [Fintype ΞΉ] (b : Basis ΞΉ R M) {w : Set M} [Fintype w] (s : span R w = ⊀) : Fintype.card ΞΉ ≀ Fintype.card w := by -- We construct a surjective linear map `(w β†’ R) β†’β‚—[R] (ΞΉ β†’ R)`, -- by expressing a linear combination in `w` as a linear combination in `ΞΉ`. fapply card_le_of_surjective' R Β· exact b.repr.toLinearMap.comp (Finsupp.linearCombination R (↑)) Β· apply Surjective.comp (g := b.repr.toLinearMap) Β· apply LinearEquiv.surjective rw [← LinearMap.range_eq_top, Finsupp.range_linearCombination] simpa using s /-- Another auxiliary lemma for `Basis.le_span`, which does not require assuming the basis is finite, but still assumes we have a finite spanning set. -/ theorem basis_le_span' {ΞΉ : Type*} (b : Basis ΞΉ R M) {w : Set M} [Fintype w] (s : span R w = ⊀) : #ΞΉ ≀ Fintype.card w := by haveI := nontrivial_of_invariantBasisNumber R haveI := basis_finite_of_finite_spans w.toFinite s b cases nonempty_fintype ΞΉ rw [Cardinal.mk_fintype ΞΉ] simp only [Nat.cast_le] exact Basis.le_span'' b s -- Note that if `R` satisfies the strong rank condition, -- this also follows from `linearIndependent_le_span` below. /-- If `R` satisfies the rank condition, then the cardinality of any basis is bounded by the cardinality of any spanning set. -/
Mathlib/LinearAlgebra/Dimension/StrongRankCondition.lean
140
164
theorem Basis.le_span {J : Set M} (v : Basis ΞΉ R M) (hJ : span R J = ⊀) : #(range v) ≀ #J := by
haveI := nontrivial_of_invariantBasisNumber R cases fintypeOrInfinite J Β· rw [← Cardinal.lift_le, Cardinal.mk_range_eq_of_injective v.injective, Cardinal.mk_fintype J] convert Cardinal.lift_le.{v}.2 (basis_le_span' v hJ) simp Β· let S : J β†’ Set ΞΉ := fun j => ↑(v.repr j).support let S' : J β†’ Set M := fun j => v '' S j have hs : range v βŠ† ⋃ j, S' j := by intro b hb rcases mem_range.1 hb with ⟨i, hi⟩ have : span R J ≀ comap v.repr.toLinearMap (Finsupp.supported R R (⋃ j, S j)) := span_le.2 fun j hj x hx => ⟨_, ⟨⟨j, hj⟩, rfl⟩, hx⟩ rw [hJ] at this replace : v.repr (v i) ∈ Finsupp.supported R R (⋃ j, S j) := this trivial rw [v.repr_self, Finsupp.mem_supported, Finsupp.support_single_ne_zero _ one_ne_zero] at this Β· subst b rcases mem_iUnion.1 (this (Finset.mem_singleton_self _)) with ⟨j, hj⟩ exact mem_iUnion.2 ⟨j, (mem_image _ _ _).2 ⟨i, hj, rfl⟩⟩ refine le_of_not_lt fun IJ => ?_ suffices #(⋃ j, S' j) < #(range v) by exact not_le_of_lt this ⟨Set.embeddingOfSubset _ _ hs⟩ refine lt_of_le_of_lt (le_trans Cardinal.mk_iUnion_le_sum_mk (Cardinal.sum_le_sum _ (fun _ => β„΅β‚€) ?_)) ?_ Β· exact fun j => (Cardinal.lt_aleph0_of_finite _).le Β· simpa
/- Copyright (c) 2021 Andrew Yang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.Topology.Sets.Closeds import Mathlib.Topology.Sets.OpenCover /-! # Sober spaces A quasi-sober space is a topological space where every irreducible closed subset has a generic point. A sober space is a quasi-sober space where every irreducible closed subset has a *unique* generic point. This is if and only if the space is T0, and thus sober spaces can be stated via `[QuasiSober Ξ±] [T0Space Ξ±]`. ## Main definition * `IsGenericPoint` : `x` is the generic point of `S` if `S` is the closure of `x`. * `QuasiSober` : A space is quasi-sober if every irreducible closed subset has a generic point. * `genericPoints` : The set of generic points of irreducible components. -/ open Set variable {Ξ± Ξ² : Type*} [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] section genericPoint /-- `x` is a generic point of `S` if `S` is the closure of `x`. -/ def IsGenericPoint (x : Ξ±) (S : Set Ξ±) : Prop := closure ({x} : Set Ξ±) = S theorem isGenericPoint_def {x : Ξ±} {S : Set Ξ±} : IsGenericPoint x S ↔ closure ({x} : Set Ξ±) = S := Iff.rfl theorem IsGenericPoint.def {x : Ξ±} {S : Set Ξ±} (h : IsGenericPoint x S) : closure ({x} : Set Ξ±) = S := h theorem isGenericPoint_closure {x : Ξ±} : IsGenericPoint x (closure ({x} : Set Ξ±)) := refl _ variable {x y : Ξ±} {S U Z : Set Ξ±} theorem isGenericPoint_iff_specializes : IsGenericPoint x S ↔ βˆ€ y, x β€³ y ↔ y ∈ S := by simp only [specializes_iff_mem_closure, IsGenericPoint, Set.ext_iff] namespace IsGenericPoint theorem specializes_iff_mem (h : IsGenericPoint x S) : x β€³ y ↔ y ∈ S := isGenericPoint_iff_specializes.1 h y protected theorem specializes (h : IsGenericPoint x S) (h' : y ∈ S) : x β€³ y := h.specializes_iff_mem.2 h' protected theorem mem (h : IsGenericPoint x S) : x ∈ S := h.specializes_iff_mem.1 specializes_rfl protected theorem isClosed (h : IsGenericPoint x S) : IsClosed S := h.def β–Έ isClosed_closure protected theorem isIrreducible (h : IsGenericPoint x S) : IsIrreducible S := h.def β–Έ isIrreducible_singleton.closure protected theorem inseparable (h : IsGenericPoint x S) (h' : IsGenericPoint y S) : Inseparable x y := (h.specializes h'.mem).antisymm (h'.specializes h.mem) /-- In a Tβ‚€ space, each set has at most one generic point. -/ protected theorem eq [T0Space Ξ±] (h : IsGenericPoint x S) (h' : IsGenericPoint y S) : x = y := (h.inseparable h').eq theorem mem_open_set_iff (h : IsGenericPoint x S) (hU : IsOpen U) : x ∈ U ↔ (S ∩ U).Nonempty := ⟨fun h' => ⟨x, h.mem, h'⟩, fun ⟨_y, hyS, hyU⟩ => (h.specializes hyS).mem_open hU hyU⟩ theorem disjoint_iff (h : IsGenericPoint x S) (hU : IsOpen U) : Disjoint S U ↔ x βˆ‰ U := by rw [h.mem_open_set_iff hU, ← not_disjoint_iff_nonempty_inter, Classical.not_not] theorem mem_closed_set_iff (h : IsGenericPoint x S) (hZ : IsClosed Z) : x ∈ Z ↔ S βŠ† Z := by rw [← h.def, hZ.closure_subset_iff, singleton_subset_iff] protected theorem image (h : IsGenericPoint x S) {f : Ξ± β†’ Ξ²} (hf : Continuous f) : IsGenericPoint (f x) (closure (f '' S)) := by rw [isGenericPoint_def, ← h.def, ← image_singleton, closure_image_closure hf] end IsGenericPoint
Mathlib/Topology/Sober.lean
92
93
theorem isGenericPoint_iff_forall_closed (hS : IsClosed S) (hxS : x ∈ S) : IsGenericPoint x S ↔ βˆ€ Z : Set Ξ±, IsClosed Z β†’ x ∈ Z β†’ S βŠ† Z := by
/- Copyright (c) 2020 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison -/ import Mathlib.CategoryTheory.Monoidal.Discrete import Mathlib.CategoryTheory.Monoidal.NaturalTransformation import Mathlib.CategoryTheory.Monoidal.Opposite import Mathlib.Tactic.CategoryTheory.Monoidal.Basic import Mathlib.CategoryTheory.CommSq /-! # Braided and symmetric monoidal categories The basic definitions of braided monoidal categories, and symmetric monoidal categories, as well as braided functors. ## Implementation note We make `BraidedCategory` another typeclass, but then have `SymmetricCategory` extend this. The rationale is that we are not carrying any additional data, just requiring a property. ## Future work * Construct the Drinfeld center of a monoidal category as a braided monoidal category. * Say something about pseudo-natural transformations. ## References * [Pavel Etingof, Shlomo Gelaki, Dmitri Nikshych, Victor Ostrik, *Tensor categories*][egno15] -/ universe v v₁ vβ‚‚ v₃ u u₁ uβ‚‚ u₃ namespace CategoryTheory open Category MonoidalCategory Functor.LaxMonoidal Functor.OplaxMonoidal Functor.Monoidal /-- A braided monoidal category is a monoidal category equipped with a braiding isomorphism `Ξ²_ X Y : X βŠ— Y β‰… Y βŠ— X` which is natural in both arguments, and also satisfies the two hexagon identities. -/ class BraidedCategory (C : Type u) [Category.{v} C] [MonoidalCategory.{v} C] where /-- The braiding natural isomorphism. -/ braiding : βˆ€ X Y : C, X βŠ— Y β‰… Y βŠ— X braiding_naturality_right : βˆ€ (X : C) {Y Z : C} (f : Y ⟢ Z), X ◁ f ≫ (braiding X Z).hom = (braiding X Y).hom ≫ f β–· X := by aesop_cat braiding_naturality_left : βˆ€ {X Y : C} (f : X ⟢ Y) (Z : C), f β–· Z ≫ (braiding Y Z).hom = (braiding X Z).hom ≫ Z ◁ f := by aesop_cat /-- The first hexagon identity. -/ hexagon_forward : βˆ€ X Y Z : C, (Ξ±_ X Y Z).hom ≫ (braiding X (Y βŠ— Z)).hom ≫ (Ξ±_ Y Z X).hom = ((braiding X Y).hom β–· Z) ≫ (Ξ±_ Y X Z).hom ≫ (Y ◁ (braiding X Z).hom) := by aesop_cat /-- The second hexagon identity. -/ hexagon_reverse : βˆ€ X Y Z : C, (Ξ±_ X Y Z).inv ≫ (braiding (X βŠ— Y) Z).hom ≫ (Ξ±_ Z X Y).inv = (X ◁ (braiding Y Z).hom) ≫ (Ξ±_ X Z Y).inv ≫ ((braiding X Z).hom β–· Y) := by aesop_cat attribute [reassoc (attr := simp)] BraidedCategory.braiding_naturality_left BraidedCategory.braiding_naturality_right attribute [reassoc] BraidedCategory.hexagon_forward BraidedCategory.hexagon_reverse open BraidedCategory @[inherit_doc] notation "Ξ²_" => BraidedCategory.braiding namespace BraidedCategory variable {C : Type u} [Category.{v} C] [MonoidalCategory.{v} C] [BraidedCategory.{v} C] @[simp, reassoc] theorem braiding_tensor_left (X Y Z : C) : (Ξ²_ (X βŠ— Y) Z).hom = (Ξ±_ X Y Z).hom ≫ X ◁ (Ξ²_ Y Z).hom ≫ (Ξ±_ X Z Y).inv ≫ (Ξ²_ X Z).hom β–· Y ≫ (Ξ±_ Z X Y).hom := by apply (cancel_epi (Ξ±_ X Y Z).inv).1 apply (cancel_mono (Ξ±_ Z X Y).inv).1 simp [hexagon_reverse] @[simp, reassoc] theorem braiding_tensor_right (X Y Z : C) : (Ξ²_ X (Y βŠ— Z)).hom = (Ξ±_ X Y Z).inv ≫ (Ξ²_ X Y).hom β–· Z ≫ (Ξ±_ Y X Z).hom ≫ Y ◁ (Ξ²_ X Z).hom ≫ (Ξ±_ Y Z X).inv := by apply (cancel_epi (Ξ±_ X Y Z).hom).1 apply (cancel_mono (Ξ±_ Y Z X).hom).1 simp [hexagon_forward] @[simp, reassoc] theorem braiding_inv_tensor_left (X Y Z : C) : (Ξ²_ (X βŠ— Y) Z).inv = (Ξ±_ Z X Y).inv ≫ (Ξ²_ X Z).inv β–· Y ≫ (Ξ±_ X Z Y).hom ≫ X ◁ (Ξ²_ Y Z).inv ≫ (Ξ±_ X Y Z).inv := eq_of_inv_eq_inv (by simp) @[simp, reassoc] theorem braiding_inv_tensor_right (X Y Z : C) : (Ξ²_ X (Y βŠ— Z)).inv = (Ξ±_ Y Z X).hom ≫ Y ◁ (Ξ²_ X Z).inv ≫ (Ξ±_ Y X Z).inv ≫ (Ξ²_ X Y).inv β–· Z ≫ (Ξ±_ X Y Z).hom := eq_of_inv_eq_inv (by simp) @[reassoc (attr := simp)]
Mathlib/CategoryTheory/Monoidal/Braided/Basic.lean
118
122
theorem braiding_naturality {X X' Y Y' : C} (f : X ⟢ Y) (g : X' ⟢ Y') : (f βŠ— g) ≫ (braiding Y Y').hom = (braiding X X').hom ≫ (g βŠ— f) := by
rw [tensorHom_def' f g, tensorHom_def g f] simp_rw [Category.assoc, braiding_naturality_left, braiding_naturality_right_assoc]
/- 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.Data.Fin.Tuple.Basic /-! # Lists from functions Theorems and lemmas for dealing with `List.ofFn`, which converts a function on `Fin n` to a list of length `n`. ## Main Statements The main statements pertain to lists generated using `List.ofFn` - `List.get?_ofFn`, which tells us the nth element of such a list - `List.equivSigmaTuple`, which is an `Equiv` between lists and the functions that generate them via `List.ofFn`. -/ assert_not_exists Monoid universe u variable {Ξ± : Type u} open Nat namespace List theorem get_ofFn {n} (f : Fin n β†’ Ξ±) (i) : get (ofFn f) i = f (Fin.cast (by simp) i) := by simp; congr @[deprecated (since := "2025-02-15")] alias get?_ofFn := List.getElem?_ofFn @[simp] theorem map_ofFn {Ξ² : Type*} {n : β„•} (f : Fin n β†’ Ξ±) (g : Ξ± β†’ Ξ²) : map g (ofFn f) = ofFn (g ∘ f) := ext_get (by simp) fun i h h' => by simp @[congr] theorem ofFn_congr {m n : β„•} (h : m = n) (f : Fin m β†’ Ξ±) : ofFn f = ofFn fun i : Fin n => f (Fin.cast h.symm i) := by subst h simp_rw [Fin.cast_refl, id] theorem ofFn_succ' {n} (f : Fin (succ n) β†’ Ξ±) : ofFn f = (ofFn fun i => f (Fin.castSucc i)).concat (f (Fin.last _)) := by induction' n with n IH Β· rw [ofFn_zero, concat_nil, ofFn_succ, ofFn_zero] rfl Β· rw [ofFn_succ, IH, ofFn_succ, concat_cons, Fin.castSucc_zero] congr /-- Note this matches the convention of `List.ofFn_succ'`, putting the `Fin m` elements first. -/ theorem ofFn_add {m n} (f : Fin (m + n) β†’ Ξ±) : List.ofFn f = (List.ofFn fun i => f (Fin.castAdd n i)) ++ List.ofFn fun j => f (Fin.natAdd m j) := by induction' n with n IH Β· rw [ofFn_zero, append_nil, Fin.castAdd_zero, Fin.cast_refl] rfl Β· rw [ofFn_succ', ofFn_succ', IH, append_concat] rfl @[simp] theorem ofFn_fin_append {m n} (a : Fin m β†’ Ξ±) (b : Fin n β†’ Ξ±) : List.ofFn (Fin.append a b) = List.ofFn a ++ List.ofFn b := by simp_rw [ofFn_add, Fin.append_left, Fin.append_right] /-- This breaks a list of `m*n` items into `m` groups each containing `n` elements. -/ theorem ofFn_mul {m n} (f : Fin (m * n) β†’ Ξ±) : List.ofFn f = List.flatten (List.ofFn fun i : Fin m => List.ofFn fun j : Fin n => f ⟨i * n + j, calc ↑i * n + j < (i + 1) * n := (Nat.add_lt_add_left j.prop _).trans_eq (by rw [Nat.add_mul, Nat.one_mul]) _ ≀ _ := Nat.mul_le_mul_right _ i.prop⟩) := by induction' m with m IH Β· simp [ofFn_zero, Nat.zero_mul, ofFn_zero, flatten] Β· simp_rw [ofFn_succ', succ_mul] simp [flatten_concat, ofFn_add, IH] rfl /-- This breaks a list of `m*n` items into `n` groups each containing `m` elements. -/ theorem ofFn_mul' {m n} (f : Fin (m * n) β†’ Ξ±) : List.ofFn f = List.flatten (List.ofFn fun i : Fin n => List.ofFn fun j : Fin m => f ⟨m * i + j, calc m * i + j < m * (i + 1) := (Nat.add_lt_add_left j.prop _).trans_eq (by rw [Nat.mul_add, Nat.mul_one]) _ ≀ _ := Nat.mul_le_mul_left _ i.prop⟩) := by simp_rw [m.mul_comm, ofFn_mul, Fin.cast_mk] @[simp] theorem ofFn_get : βˆ€ l : List Ξ±, (ofFn (get l)) = l | [] => by rw [ofFn_zero] | a :: l => by rw [ofFn_succ] congr exact ofFn_get l @[simp] theorem ofFn_getElem : βˆ€ l : List Ξ±, (ofFn (fun i : Fin l.length => l[(i : Nat)])) = l | [] => by rw [ofFn_zero] | a :: l => by rw [ofFn_succ] congr exact ofFn_get l @[simp] theorem ofFn_getElem_eq_map {Ξ² : Type*} (l : List Ξ±) (f : Ξ± β†’ Ξ²) : ofFn (fun i : Fin l.length => f <| l[(i : Nat)]) = l.map f := by rw [← Function.comp_def, ← map_ofFn, ofFn_getElem] -- Note there is a now another `mem_ofFn` defined in Lean, with an existential on the RHS, -- which is marked as a simp lemma.
Mathlib/Data/List/OfFn.lean
116
119
theorem mem_ofFn' {n} (f : Fin n β†’ Ξ±) (a : Ξ±) : a ∈ ofFn f ↔ a ∈ Set.range f := by
simp only [mem_iff_get, Set.mem_range, get_ofFn] exact ⟨fun ⟨i, hi⟩ => ⟨Fin.cast (by simp) i, hi⟩, fun ⟨i, hi⟩ => ⟨Fin.cast (by simp) i, hi⟩⟩
/- 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, Mitchell Lee -/ import Mathlib.Algebra.BigOperators.Finprod import Mathlib.Algebra.BigOperators.Pi import Mathlib.Algebra.Group.Submonoid.Basic import Mathlib.Algebra.Group.ULift import Mathlib.Order.Filter.Pointwise import Mathlib.Topology.Algebra.MulAction import Mathlib.Topology.ContinuousMap.Defs import Mathlib.Topology.Algebra.Monoid.Defs /-! # Theory of topological monoids In this file we define mixin classes `ContinuousMul` and `ContinuousAdd`. While in many applications the underlying type is a monoid (multiplicative or additive), we do not require this in the definitions. -/ universe u v open Set Filter TopologicalSpace Topology open scoped Topology Pointwise variable {ΞΉ Ξ± M N X : Type*} [TopologicalSpace X] @[to_additive (attr := continuity, fun_prop)] theorem continuous_one [TopologicalSpace M] [One M] : Continuous (1 : X β†’ M) := @continuous_const _ _ _ _ 1 section ContinuousMul variable [TopologicalSpace M] [Mul M] [ContinuousMul M] @[to_additive] instance : ContinuousMul Mα΅’α΅ˆ := β€ΉContinuousMul Mβ€Ί @[to_additive] instance : ContinuousMul (ULift.{u} M) := by constructor apply continuous_uliftUp.comp exact continuous_mul.compβ‚‚ (continuous_uliftDown.comp continuous_fst) (continuous_uliftDown.comp continuous_snd) @[to_additive] instance ContinuousMul.to_continuousSMul : ContinuousSMul M M := ⟨continuous_mul⟩ @[to_additive] instance ContinuousMul.to_continuousSMul_op : ContinuousSMul Mᡐᡒᡖ M := ⟨show Continuous ((fun p : M Γ— M => p.1 * p.2) ∘ Prod.swap ∘ Prod.map MulOpposite.unop id) from continuous_mul.comp <| continuous_swap.comp <| Continuous.prodMap MulOpposite.continuous_unop continuous_id⟩ @[to_additive] theorem ContinuousMul.induced {Ξ± : Type*} {Ξ² : Type*} {F : Type*} [FunLike F Ξ± Ξ²] [Mul Ξ±] [Mul Ξ²] [MulHomClass F Ξ± Ξ²] [tΞ² : TopologicalSpace Ξ²] [ContinuousMul Ξ²] (f : F) : @ContinuousMul Ξ± (tΞ².induced f) _ := by let tΞ± := tΞ².induced f refine ⟨continuous_induced_rng.2 ?_⟩ simp only [Function.comp_def, map_mul] fun_prop @[to_additive (attr := continuity)] theorem continuous_mul_left (a : M) : Continuous fun b : M => a * b := continuous_const.mul continuous_id @[to_additive (attr := continuity)] theorem continuous_mul_right (a : M) : Continuous fun b : M => b * a := continuous_id.mul continuous_const @[to_additive] theorem tendsto_mul {a b : M} : Tendsto (fun p : M Γ— M => p.fst * p.snd) (𝓝 (a, b)) (𝓝 (a * b)) := continuous_iff_continuousAt.mp ContinuousMul.continuous_mul (a, b) @[to_additive] theorem Filter.Tendsto.const_mul (b : M) {c : M} {f : Ξ± β†’ M} {l : Filter Ξ±} (h : Tendsto (fun k : Ξ± => f k) l (𝓝 c)) : Tendsto (fun k : Ξ± => b * f k) l (𝓝 (b * c)) := tendsto_const_nhds.mul h @[to_additive] theorem Filter.Tendsto.mul_const (b : M) {c : M} {f : Ξ± β†’ M} {l : Filter Ξ±} (h : Tendsto (fun k : Ξ± => f k) l (𝓝 c)) : Tendsto (fun k : Ξ± => f k * b) l (𝓝 (c * b)) := h.mul tendsto_const_nhds @[to_additive] theorem le_nhds_mul (a b : M) : 𝓝 a * 𝓝 b ≀ 𝓝 (a * b) := by rw [← mapβ‚‚_mul, ← map_uncurry_prod, ← nhds_prod_eq] exact continuous_mul.tendsto _ @[to_additive (attr := simp)] theorem nhds_one_mul_nhds {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : 𝓝 (1 : M) * 𝓝 a = 𝓝 a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (one_mul a)).antisymm <| le_mul_of_one_le_left' <| pure_le_nhds 1 @[to_additive (attr := simp)] theorem nhds_mul_nhds_one {M} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] (a : M) : 𝓝 a * 𝓝 1 = 𝓝 a := ((le_nhds_mul _ _).trans_eq <| congr_arg _ (mul_one a)).antisymm <| le_mul_of_one_le_right' <| pure_le_nhds 1 section tendsto_nhds variable {π•œ : Type*} [Preorder π•œ] [Zero π•œ] [Mul π•œ] [TopologicalSpace π•œ] [ContinuousMul π•œ] {l : Filter Ξ±} {f : Ξ± β†’ π•œ} {b c : π•œ} (hb : 0 < b) include hb theorem Filter.TendstoNhdsWithinIoi.const_mul [PosMulStrictMono π•œ] [PosMulReflectLT π•œ] (h : Tendsto f l (𝓝[>] c)) : Tendsto (fun a => b * f a) l (𝓝[>] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr theorem Filter.TendstoNhdsWithinIio.const_mul [PosMulStrictMono π•œ] [PosMulReflectLT π•œ] (h : Tendsto f l (𝓝[<] c)) : Tendsto (fun a => b * f a) l (𝓝[<] (b * c)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).const_mul b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_left hb).mpr theorem Filter.TendstoNhdsWithinIoi.mul_const [MulPosStrictMono π•œ] [MulPosReflectLT π•œ] (h : Tendsto f l (𝓝[>] c)) : Tendsto (fun a => f a * b) l (𝓝[>] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr theorem Filter.TendstoNhdsWithinIio.mul_const [MulPosStrictMono π•œ] [MulPosReflectLT π•œ] (h : Tendsto f l (𝓝[<] c)) : Tendsto (fun a => f a * b) l (𝓝[<] (c * b)) := tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within _ ((tendsto_nhds_of_tendsto_nhdsWithin h).mul_const b) <| (tendsto_nhdsWithin_iff.mp h).2.mono fun _ => (mul_lt_mul_right hb).mpr end tendsto_nhds @[to_additive] protected theorem Specializes.mul {a b c d : M} (hab : a β€³ b) (hcd : c β€³ d) : (a * c) β€³ (b * d) := hab.smul hcd @[to_additive] protected theorem Inseparable.mul {a b c d : M} (hab : Inseparable a b) (hcd : Inseparable c d) : Inseparable (a * c) (b * d) := hab.smul hcd @[to_additive] protected theorem Specializes.pow {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {a b : M} (h : a β€³ b) (n : β„•) : (a ^ n) β€³ (b ^ n) := Nat.recOn n (by simp only [pow_zero, specializes_rfl]) fun _ ihn ↦ by simpa only [pow_succ] using ihn.mul h @[to_additive] protected theorem Inseparable.pow {M : Type*} [Monoid M] [TopologicalSpace M] [ContinuousMul M] {a b : M} (h : Inseparable a b) (n : β„•) : Inseparable (a ^ n) (b ^ n) := (h.specializes.pow n).antisymm (h.specializes'.pow n) /-- Construct a unit from limits of units and their inverses. -/ @[to_additive (attr := simps) "Construct an additive unit from limits of additive units and their negatives."] def Filter.Tendsto.units [TopologicalSpace N] [Monoid N] [ContinuousMul N] [T2Space N] {f : ΞΉ β†’ NΛ£} {r₁ rβ‚‚ : N} {l : Filter ΞΉ} [l.NeBot] (h₁ : Tendsto (fun x => ↑(f x)) l (𝓝 r₁)) (hβ‚‚ : Tendsto (fun x => ↑(f x)⁻¹) l (𝓝 rβ‚‚)) : NΛ£ where val := r₁ inv := rβ‚‚ val_inv := by symm simpa using h₁.mul hβ‚‚ inv_val := by symm simpa using hβ‚‚.mul h₁ @[to_additive] instance Prod.continuousMul [TopologicalSpace N] [Mul N] [ContinuousMul N] : ContinuousMul (M Γ— N) := ⟨by apply Continuous.prodMk <;> fun_prop⟩ @[to_additive] instance Pi.continuousMul {C : ΞΉ β†’ Type*} [βˆ€ i, TopologicalSpace (C i)] [βˆ€ i, Mul (C i)] [βˆ€ i, ContinuousMul (C i)] : ContinuousMul (βˆ€ i, C i) where continuous_mul := continuous_pi fun i => (continuous_apply i).fst'.mul (continuous_apply i).snd' /-- A version of `Pi.continuousMul` for non-dependent functions. It is needed because sometimes Lean 3 fails to use `Pi.continuousMul` for non-dependent functions. -/ @[to_additive "A version of `Pi.continuousAdd` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousAdd` for non-dependent functions."] instance Pi.continuousMul' : ContinuousMul (ΞΉ β†’ M) := Pi.continuousMul @[to_additive] instance (priority := 100) continuousMul_of_discreteTopology [TopologicalSpace N] [Mul N] [DiscreteTopology N] : ContinuousMul N := ⟨continuous_of_discreteTopology⟩ open Filter open Function @[to_additive] theorem ContinuousMul.of_nhds_one {M : Type u} [Monoid M] [TopologicalSpace M] (hmul : Tendsto (uncurry ((Β· * Β·) : M β†’ M β†’ M)) (𝓝 1 Γ—Λ’ 𝓝 1) <| 𝓝 1) (hleft : βˆ€ xβ‚€ : M, 𝓝 xβ‚€ = map (fun x => xβ‚€ * x) (𝓝 1)) (hright : βˆ€ xβ‚€ : M, 𝓝 xβ‚€ = map (fun x => x * xβ‚€) (𝓝 1)) : ContinuousMul M := ⟨by rw [continuous_iff_continuousAt] rintro ⟨xβ‚€, yβ‚€βŸ© have key : (fun p : M Γ— M => xβ‚€ * p.1 * (p.2 * yβ‚€)) = ((fun x => xβ‚€ * x) ∘ fun x => x * yβ‚€) ∘ uncurry (Β· * Β·) := by ext p simp [uncurry, mul_assoc] have keyβ‚‚ : ((fun x => xβ‚€ * x) ∘ fun x => yβ‚€ * x) = fun x => xβ‚€ * yβ‚€ * x := by ext x simp [mul_assoc] calc map (uncurry (Β· * Β·)) (𝓝 (xβ‚€, yβ‚€)) = map (uncurry (Β· * Β·)) (𝓝 xβ‚€ Γ—Λ’ 𝓝 yβ‚€) := by rw [nhds_prod_eq] _ = map (fun p : M Γ— M => xβ‚€ * p.1 * (p.2 * yβ‚€)) (𝓝 1 Γ—Λ’ 𝓝 1) := by -- Porting note: `rw` was able to prove this -- Now it fails with `failed to rewrite using equation theorems for 'Function.uncurry'` -- and `failed to rewrite using equation theorems for 'Function.comp'`. -- Removing those two lemmas, the `rw` would succeed, but then needs a `rfl`. simp +unfoldPartialApp only [uncurry] simp_rw [hleft xβ‚€, hright yβ‚€, prod_map_map_eq, Filter.map_map, Function.comp_def] _ = map ((fun x => xβ‚€ * x) ∘ fun x => x * yβ‚€) (map (uncurry (Β· * Β·)) (𝓝 1 Γ—Λ’ 𝓝 1)) := by rw [key, ← Filter.map_map] _ ≀ map ((fun x : M => xβ‚€ * x) ∘ fun x => x * yβ‚€) (𝓝 1) := map_mono hmul _ = 𝓝 (xβ‚€ * yβ‚€) := by rw [← Filter.map_map, ← hright, hleft yβ‚€, Filter.map_map, keyβ‚‚, ← hleft]⟩ @[to_additive] theorem continuousMul_of_comm_of_nhds_one (M : Type u) [CommMonoid M] [TopologicalSpace M] (hmul : Tendsto (uncurry ((Β· * Β·) : M β†’ M β†’ M)) (𝓝 1 Γ—Λ’ 𝓝 1) (𝓝 1)) (hleft : βˆ€ xβ‚€ : M, 𝓝 xβ‚€ = map (fun x => xβ‚€ * x) (𝓝 1)) : ContinuousMul M := by apply ContinuousMul.of_nhds_one hmul hleft intro xβ‚€ simp_rw [mul_comm, hleft xβ‚€] end ContinuousMul section PointwiseLimits variable (M₁ Mβ‚‚ : Type*) [TopologicalSpace Mβ‚‚] [T2Space Mβ‚‚] @[to_additive] theorem isClosed_setOf_map_one [One M₁] [One Mβ‚‚] : IsClosed { f : M₁ β†’ Mβ‚‚ | f 1 = 1 } := isClosed_eq (continuous_apply 1) continuous_const @[to_additive] theorem isClosed_setOf_map_mul [Mul M₁] [Mul Mβ‚‚] [ContinuousMul Mβ‚‚] : IsClosed { f : M₁ β†’ Mβ‚‚ | βˆ€ x y, f (x * y) = f x * f y } := by simp only [setOf_forall] exact isClosed_iInter fun x ↦ isClosed_iInter fun y ↦ isClosed_eq (continuous_apply _) (by fun_prop) section Semigroup variable {M₁ Mβ‚‚} [Mul M₁] [Mul Mβ‚‚] [ContinuousMul Mβ‚‚] {F : Type*} [FunLike F M₁ Mβ‚‚] [MulHomClass F M₁ Mβ‚‚] {l : Filter Ξ±} /-- Construct a bundled semigroup homomorphism `M₁ β†’β‚™* Mβ‚‚` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ β†’β‚™* Mβ‚‚` (or another type of bundled homomorphisms that has a `MulHomClass` instance) to `M₁ β†’ Mβ‚‚`. -/ @[to_additive (attr := simps -fullyApplied) "Construct a bundled additive semigroup homomorphism `M₁ β†’β‚™+ Mβ‚‚` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ β†’β‚™+ Mβ‚‚` (or another type of bundled homomorphisms that has an `AddHomClass` instance) to `M₁ β†’ Mβ‚‚`."] def mulHomOfMemClosureRangeCoe (f : M₁ β†’ Mβ‚‚) (hf : f ∈ closure (range fun (f : F) (x : M₁) => f x)) : M₁ β†’β‚™* Mβ‚‚ where toFun := f map_mul' := (isClosed_setOf_map_mul M₁ Mβ‚‚).closure_subset_iff.2 (range_subset_iff.2 map_mul) hf /-- Construct a bundled semigroup homomorphism from a pointwise limit of semigroup homomorphisms. -/ @[to_additive (attr := simps! -fullyApplied) "Construct a bundled additive semigroup homomorphism from a pointwise limit of additive semigroup homomorphisms"] def mulHomOfTendsto (f : M₁ β†’ Mβ‚‚) (g : Ξ± β†’ F) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ β†’β‚™* Mβ‚‚ := mulHomOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| Eventually.of_forall fun _ => mem_range_self _ variable (M₁ Mβ‚‚) @[to_additive] theorem MulHom.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ β†’β‚™* Mβ‚‚) β†’ M₁ β†’ Mβ‚‚)) := isClosed_of_closure_subset fun f hf => ⟨mulHomOfMemClosureRangeCoe f hf, rfl⟩ end Semigroup section Monoid variable {M₁ Mβ‚‚} [MulOneClass M₁] [MulOneClass Mβ‚‚] [ContinuousMul Mβ‚‚] {F : Type*} [FunLike F M₁ Mβ‚‚] [MonoidHomClass F M₁ Mβ‚‚] {l : Filter Ξ±} /-- Construct a bundled monoid homomorphism `M₁ β†’* Mβ‚‚` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ β†’* Mβ‚‚` (or another type of bundled homomorphisms that has a `MonoidHomClass` instance) to `M₁ β†’ Mβ‚‚`. -/ @[to_additive (attr := simps -fullyApplied) "Construct a bundled additive monoid homomorphism `M₁ β†’+ Mβ‚‚` from a function `f` and a proof that it belongs to the closure of the range of the coercion from `M₁ β†’+ Mβ‚‚` (or another type of bundled homomorphisms that has an `AddMonoidHomClass` instance) to `M₁ β†’ Mβ‚‚`."] def monoidHomOfMemClosureRangeCoe (f : M₁ β†’ Mβ‚‚) (hf : f ∈ closure (range fun (f : F) (x : M₁) => f x)) : M₁ β†’* Mβ‚‚ where toFun := f map_one' := (isClosed_setOf_map_one M₁ Mβ‚‚).closure_subset_iff.2 (range_subset_iff.2 map_one) hf map_mul' := (isClosed_setOf_map_mul M₁ Mβ‚‚).closure_subset_iff.2 (range_subset_iff.2 map_mul) hf /-- Construct a bundled monoid homomorphism from a pointwise limit of monoid homomorphisms. -/ @[to_additive (attr := simps! -fullyApplied) "Construct a bundled additive monoid homomorphism from a pointwise limit of additive monoid homomorphisms"] def monoidHomOfTendsto (f : M₁ β†’ Mβ‚‚) (g : Ξ± β†’ F) [l.NeBot] (h : Tendsto (fun a x => g a x) l (𝓝 f)) : M₁ β†’* Mβ‚‚ := monoidHomOfMemClosureRangeCoe f <| mem_closure_of_tendsto h <| Eventually.of_forall fun _ => mem_range_self _ variable (M₁ Mβ‚‚) @[to_additive] theorem MonoidHom.isClosed_range_coe : IsClosed (Set.range ((↑) : (M₁ β†’* Mβ‚‚) β†’ M₁ β†’ Mβ‚‚)) := isClosed_of_closure_subset fun f hf => ⟨monoidHomOfMemClosureRangeCoe f hf, rfl⟩ end Monoid end PointwiseLimits @[to_additive] theorem Topology.IsInducing.continuousMul {M N F : Type*} [Mul M] [Mul N] [FunLike F M N] [MulHomClass F M N] [TopologicalSpace M] [TopologicalSpace N] [ContinuousMul N] (f : F) (hf : IsInducing f) : ContinuousMul M := ⟨(hf.continuousSMul hf.continuous (map_mul f _ _)).1⟩ @[deprecated (since := "2024-10-28")] alias Inducing.continuousMul := IsInducing.continuousMul @[to_additive] theorem continuousMul_induced {M N F : Type*} [Mul M] [Mul N] [FunLike F M N] [MulHomClass F M N] [TopologicalSpace N] [ContinuousMul N] (f : F) : @ContinuousMul M (induced f β€Ή_β€Ί) _ := letI := induced f β€Ή_β€Ί IsInducing.continuousMul f ⟨rfl⟩ @[to_additive] instance Subsemigroup.continuousMul [TopologicalSpace M] [Semigroup M] [ContinuousMul M] (S : Subsemigroup M) : ContinuousMul S := IsInducing.continuousMul ({ toFun := (↑), map_mul' := fun _ _ => rfl} : MulHom S M) ⟨rfl⟩ @[to_additive] instance Submonoid.continuousMul [TopologicalSpace M] [Monoid M] [ContinuousMul M] (S : Submonoid M) : ContinuousMul S := S.toSubsemigroup.continuousMul section MulZeroClass open Filter variable {Ξ± Ξ² : Type*} variable [TopologicalSpace M] [MulZeroClass M] [ContinuousMul M] theorem exists_mem_nhds_zero_mul_subset {K U : Set M} (hK : IsCompact K) (hU : U ∈ 𝓝 0) : βˆƒ V ∈ 𝓝 0, K * V βŠ† U := by refine hK.induction_on ?_ ?_ ?_ ?_ Β· exact ⟨univ, by simp⟩ Β· rintro s t hst ⟨V, hV, hV'⟩ exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ Β· rintro s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩ use V ∩ W, inter_mem V_in W_in rw [union_mul] exact union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV') ((mul_subset_mul_left V.inter_subset_right).trans hW') Β· intro x hx have := tendsto_mul (show U ∈ 𝓝 (x * 0) by simpa using hU) rw [nhds_prod_eq, mem_map, mem_prod_iff] at this rcases this with ⟨t, ht, s, hs, h⟩ rw [← image_subset_iff, image_mul_prod] at h exact ⟨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, h⟩ /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M` which is disjoint from the cocompact filter. Then, the multiplication map `M Γ— M β†’ M` tends to zero on the filter product `𝓝 0 Γ—Λ’ l`. -/ theorem tendsto_mul_nhds_zero_prod_of_disjoint_cocompact {l : Filter M} (hl : Disjoint l (cocompact M)) : Tendsto (fun x : M Γ— M ↦ x.1 * x.2) (𝓝 0 Γ—Λ’ l) (𝓝 0) := calc map (fun x : M Γ— M ↦ x.1 * x.2) (𝓝 0 Γ—Λ’ l) _ ≀ map (fun x : M Γ— M ↦ x.1 * x.2) (𝓝˒ ({0} Γ—Λ’ Set.univ)) := map_mono <| nhds_prod_le_of_disjoint_cocompact 0 hl _ ≀ 𝓝 0 := continuous_mul.tendsto_nhdsSet_nhds fun _ ⟨hx, _⟩ ↦ mul_eq_zero_of_left hx _ /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M` which is disjoint from the cocompact filter. Then, the multiplication map `M Γ— M β†’ M` tends to zero on the filter product `l Γ—Λ’ 𝓝 0`. -/ theorem tendsto_mul_prod_nhds_zero_of_disjoint_cocompact {l : Filter M} (hl : Disjoint l (cocompact M)) : Tendsto (fun x : M Γ— M ↦ x.1 * x.2) (l Γ—Λ’ 𝓝 0) (𝓝 0) := calc map (fun x : M Γ— M ↦ x.1 * x.2) (l Γ—Λ’ 𝓝 0) _ ≀ map (fun x : M Γ— M ↦ x.1 * x.2) (𝓝˒ (Set.univ Γ—Λ’ {0})) := map_mono <| prod_nhds_le_of_disjoint_cocompact 0 hl _ ≀ 𝓝 0 := continuous_mul.tendsto_nhdsSet_nhds fun _ ⟨_, hx⟩ ↦ mul_eq_zero_of_right _ hx /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M Γ— M` which is disjoint from the cocompact filter. Then, the multiplication map `M Γ— M β†’ M` tends to zero on `(𝓝 0).coprod (𝓝 0) βŠ“ l`. -/ theorem tendsto_mul_coprod_nhds_zero_inf_of_disjoint_cocompact {l : Filter (M Γ— M)} (hl : Disjoint l (cocompact (M Γ— M))) : Tendsto (fun x : M Γ— M ↦ x.1 * x.2) ((𝓝 0).coprod (𝓝 0) βŠ“ l) (𝓝 0) := by have := calc (𝓝 0).coprod (𝓝 0) βŠ“ l _ ≀ (𝓝 0).coprod (𝓝 0) βŠ“ map Prod.fst l Γ—Λ’ map Prod.snd l := inf_le_inf_left _ le_prod_map_fst_snd _ ≀ 𝓝 0 Γ—Λ’ map Prod.snd l βŠ” map Prod.fst l Γ—Λ’ 𝓝 0 := coprod_inf_prod_le _ _ _ _ apply (Tendsto.sup _ _).mono_left this Β· apply tendsto_mul_nhds_zero_prod_of_disjoint_cocompact exact disjoint_map_cocompact continuous_snd hl Β· apply tendsto_mul_prod_nhds_zero_of_disjoint_cocompact exact disjoint_map_cocompact continuous_fst hl /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `l` be a filter on `M Γ— M` which is both disjoint from the cocompact filter and less than or equal to `(𝓝 0).coprod (𝓝 0)`. Then the multiplication map `M Γ— M β†’ M` tends to zero on `l`. -/ theorem tendsto_mul_nhds_zero_of_disjoint_cocompact {l : Filter (M Γ— M)} (hl : Disjoint l (cocompact (M Γ— M))) (h'l : l ≀ (𝓝 0).coprod (𝓝 0)) : Tendsto (fun x : M Γ— M ↦ x.1 * x.2) l (𝓝 0) := by simpa [inf_eq_right.mpr h'l] using tendsto_mul_coprod_nhds_zero_inf_of_disjoint_cocompact hl /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `f : Ξ± β†’ M` and `g : Ξ± β†’ M` be functions. If `f` tends to zero on a filter `l` and the image of `l` under `g` is disjoint from the cocompact filter on `M`, then `fun x : Ξ± ↦ f x * g x` also tends to zero on `l`. -/ theorem Tendsto.tendsto_mul_zero_of_disjoint_cocompact_right {f g : Ξ± β†’ M} {l : Filter Ξ±} (hf : Tendsto f l (𝓝 0)) (hg : Disjoint (map g l) (cocompact M)) : Tendsto (fun x ↦ f x * g x) l (𝓝 0) := tendsto_mul_nhds_zero_prod_of_disjoint_cocompact hg |>.comp (hf.prodMk tendsto_map) /-- Let `M` be a topological space with a continuous multiplication operation and a `0`. Let `f : Ξ± β†’ M` and `g : Ξ± β†’ M` be functions. If `g` tends to zero on a filter `l` and the image of `l` under `f` is disjoint from the cocompact filter on `M`, then `fun x : Ξ± ↦ f x * g x` also tends to zero on `l`. -/ theorem Tendsto.tendsto_mul_zero_of_disjoint_cocompact_left {f g : Ξ± β†’ M} {l : Filter Ξ±} (hf : Disjoint (map f l) (cocompact M)) (hg : Tendsto g l (𝓝 0)): Tendsto (fun x ↦ f x * g x) l (𝓝 0) := tendsto_mul_prod_nhds_zero_of_disjoint_cocompact hf |>.comp (tendsto_map.prodMk hg) /-- If `f : Ξ± β†’ M` and `g : Ξ² β†’ M` are continuous and both tend to zero on the cocompact filter, then `fun i : Ξ± Γ— Ξ² ↦ f i.1 * g i.2` also tends to zero on the cocompact filter. -/ theorem tendsto_mul_cocompact_nhds_zero [TopologicalSpace Ξ±] [TopologicalSpace Ξ²] {f : Ξ± β†’ M} {g : Ξ² β†’ M} (f_cont : Continuous f) (g_cont : Continuous g) (hf : Tendsto f (cocompact Ξ±) (𝓝 0)) (hg : Tendsto g (cocompact Ξ²) (𝓝 0)) : Tendsto (fun i : Ξ± Γ— Ξ² ↦ f i.1 * g i.2) (cocompact (Ξ± Γ— Ξ²)) (𝓝 0) := by set l : Filter (M Γ— M) := map (Prod.map f g) (cocompact (Ξ± Γ— Ξ²)) with l_def set K : Set (M Γ— M) := (insert 0 (range f)) Γ—Λ’ (insert 0 (range g)) have K_compact : IsCompact K := .prod (hf.isCompact_insert_range_of_cocompact f_cont) (hg.isCompact_insert_range_of_cocompact g_cont) have K_mem_l : K ∈ l := eventually_map.mpr <| .of_forall fun ⟨x, y⟩ ↦ ⟨mem_insert_of_mem _ (mem_range_self _), mem_insert_of_mem _ (mem_range_self _)⟩ have l_compact : Disjoint l (cocompact (M Γ— M)) := by rw [disjoint_cocompact_right] exact ⟨K, K_mem_l, K_compact⟩ have l_le_coprod : l ≀ (𝓝 0).coprod (𝓝 0) := by rw [l_def, ← coprod_cocompact] exact hf.prodMap_coprod hg exact tendsto_mul_nhds_zero_of_disjoint_cocompact l_compact l_le_coprod |>.comp tendsto_map /-- If `f : Ξ± β†’ M` and `g : Ξ² β†’ M` both tend to zero on the cofinite filter, then so does `fun i : Ξ± Γ— Ξ² ↦ f i.1 * g i.2`. -/ theorem tendsto_mul_cofinite_nhds_zero {f : Ξ± β†’ M} {g : Ξ² β†’ M} (hf : Tendsto f cofinite (𝓝 0)) (hg : Tendsto g cofinite (𝓝 0)) : Tendsto (fun i : Ξ± Γ— Ξ² ↦ f i.1 * g i.2) cofinite (𝓝 0) := by letI : TopologicalSpace Ξ± := βŠ₯ haveI : DiscreteTopology Ξ± := discreteTopology_bot Ξ± letI : TopologicalSpace Ξ² := βŠ₯ haveI : DiscreteTopology Ξ² := discreteTopology_bot Ξ² rw [← cocompact_eq_cofinite] at * exact tendsto_mul_cocompact_nhds_zero continuous_of_discreteTopology continuous_of_discreteTopology hf hg end MulZeroClass section GroupWithZero lemma GroupWithZero.isOpen_singleton_zero [GroupWithZero M] [TopologicalSpace M] [ContinuousMul M] [CompactSpace M] [T1Space M] : IsOpen {(0 : M)} := by obtain ⟨U, hU, h0U, h1U⟩ := t1Space_iff_exists_open.mp β€Ή_β€Ί zero_ne_one obtain ⟨W, hW, hW'⟩ := exists_mem_nhds_zero_mul_subset isCompact_univ (hU.mem_nhds h0U) by_cases H : βˆƒ x β‰  0, x ∈ W Β· obtain ⟨x, hx, hxW⟩ := H cases h1U (hW' (by simpa [hx] using Set.mul_mem_mul (Set.mem_univ x⁻¹) hxW)) Β· obtain rfl : W = {0} := subset_antisymm (by simpa [not_imp_not] using H) (by simpa using mem_of_mem_nhds hW) simpa [isOpen_iff_mem_nhds] end GroupWithZero section MulOneClass variable [TopologicalSpace M] [MulOneClass M] [ContinuousMul M] @[to_additive exists_open_nhds_zero_half] theorem exists_open_nhds_one_split {s : Set M} (hs : s ∈ 𝓝 (1 : M)) : βˆƒ V : Set M, IsOpen V ∧ (1 : M) ∈ V ∧ βˆ€ v ∈ V, βˆ€ w ∈ V, v * w ∈ s := by have : (fun a : M Γ— M => a.1 * a.2) ⁻¹' s ∈ 𝓝 ((1, 1) : M Γ— M) := tendsto_mul (by simpa only [one_mul] using hs) simpa only [prod_subset_iff] using exists_nhds_square this @[to_additive exists_nhds_zero_half] theorem exists_nhds_one_split {s : Set M} (hs : s ∈ 𝓝 (1 : M)) : βˆƒ V ∈ 𝓝 (1 : M), βˆ€ v ∈ V, βˆ€ w ∈ V, v * w ∈ s := let ⟨V, Vo, V1, hV⟩ := exists_open_nhds_one_split hs ⟨V, IsOpen.mem_nhds Vo V1, hV⟩ /-- Given a neighborhood `U` of `1` there is an open neighborhood `V` of `1` such that `V * V βŠ† U`. -/ @[to_additive "Given an open neighborhood `U` of `0` there is an open neighborhood `V` of `0` such that `V + V βŠ† U`."] theorem exists_open_nhds_one_mul_subset {U : Set M} (hU : U ∈ 𝓝 (1 : M)) : βˆƒ V : Set M, IsOpen V ∧ (1 : M) ∈ V ∧ V * V βŠ† U := by simpa only [mul_subset_iff] using exists_open_nhds_one_split hU @[to_additive] theorem Filter.HasBasis.mul_self {p : ΞΉ β†’ Prop} {s : ΞΉ β†’ Set M} (h : (𝓝 1).HasBasis p s) : (𝓝 1).HasBasis p fun i => s i * s i := by rw [← nhds_mul_nhds_one, ← mapβ‚‚_mul, ← map_uncurry_prod] simpa only [← image_mul_prod] using h.prod_self.map _ end MulOneClass section ContinuousMul section Semigroup variable [TopologicalSpace M] [Semigroup M] [ContinuousMul M] @[to_additive] theorem Subsemigroup.top_closure_mul_self_subset (s : Subsemigroup M) : _root_.closure (s : Set M) * _root_.closure s βŠ† _root_.closure s := image2_subset_iff.2 fun _ hx _ hy => map_mem_closureβ‚‚ continuous_mul hx hy fun _ ha _ hb => s.mul_mem ha hb /-- The (topological-space) closure of a subsemigroup of a space `M` with `ContinuousMul` is itself a subsemigroup. -/ @[to_additive "The (topological-space) closure of an additive submonoid of a space `M` with `ContinuousAdd` is itself an additive submonoid."] def Subsemigroup.topologicalClosure (s : Subsemigroup M) : Subsemigroup M where carrier := _root_.closure (s : Set M) mul_mem' ha hb := s.top_closure_mul_self_subset ⟨_, ha, _, hb, rfl⟩ @[to_additive] theorem Subsemigroup.coe_topologicalClosure (s : Subsemigroup M) : (s.topologicalClosure : Set M) = _root_.closure (s : Set M) := rfl @[to_additive] theorem Subsemigroup.le_topologicalClosure (s : Subsemigroup M) : s ≀ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Subsemigroup.isClosed_topologicalClosure (s : Subsemigroup M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure @[to_additive] theorem Subsemigroup.topologicalClosure_minimal (s : Subsemigroup M) {t : Subsemigroup M} (h : s ≀ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≀ t := closure_minimal h ht /-- If a subsemigroup of a topological semigroup is commutative, then so is its topological closure. See note [reducible non-instances] -/ @[to_additive "If a submonoid of an additive topological monoid is commutative, then so is its topological closure. See note [reducible non-instances]"] abbrev Subsemigroup.commSemigroupTopologicalClosure [T2Space M] (s : Subsemigroup M) (hs : βˆ€ x y : s, x * y = y * x) : CommSemigroup s.topologicalClosure := { MulMemClass.toSemigroup s.topologicalClosure with mul_comm := have : βˆ€ x ∈ s, βˆ€ y ∈ s, x * y = y * x := fun x hx y hy => congr_arg Subtype.val (hs ⟨x, hx⟩ ⟨y, hy⟩) fun ⟨x, hx⟩ ⟨y, hy⟩ => Subtype.ext <| eqOn_closureβ‚‚ this continuous_mul (continuous_snd.mul continuous_fst) x hx y hy } @[to_additive] theorem IsCompact.mul {s t : Set M} (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s * t) := by rw [← image_mul_prod] exact (hs.prod ht).image continuous_mul end Semigroup variable [TopologicalSpace M] [Monoid M] [ContinuousMul M] @[to_additive] theorem Submonoid.top_closure_mul_self_subset (s : Submonoid M) : _root_.closure (s : Set M) * _root_.closure s βŠ† _root_.closure s := image2_subset_iff.2 fun _ hx _ hy => map_mem_closureβ‚‚ continuous_mul hx hy fun _ ha _ hb => s.mul_mem ha hb @[to_additive] theorem Submonoid.top_closure_mul_self_eq (s : Submonoid M) : _root_.closure (s : Set M) * _root_.closure s = _root_.closure s := Subset.antisymm s.top_closure_mul_self_subset fun x hx => ⟨x, hx, 1, _root_.subset_closure s.one_mem, mul_one _⟩ /-- The (topological-space) closure of a submonoid of a space `M` with `ContinuousMul` is itself a submonoid. -/ @[to_additive "The (topological-space) closure of an additive submonoid of a space `M` with `ContinuousAdd` is itself an additive submonoid."] def Submonoid.topologicalClosure (s : Submonoid M) : Submonoid M where carrier := _root_.closure (s : Set M) one_mem' := _root_.subset_closure s.one_mem mul_mem' ha hb := s.top_closure_mul_self_subset ⟨_, ha, _, hb, rfl⟩ @[to_additive] theorem Submonoid.coe_topologicalClosure (s : Submonoid M) : (s.topologicalClosure : Set M) = _root_.closure (s : Set M) := rfl @[to_additive] theorem Submonoid.le_topologicalClosure (s : Submonoid M) : s ≀ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Submonoid.isClosed_topologicalClosure (s : Submonoid M) : IsClosed (s.topologicalClosure : Set M) := isClosed_closure @[to_additive] theorem Submonoid.topologicalClosure_minimal (s : Submonoid M) {t : Submonoid M} (h : s ≀ t) (ht : IsClosed (t : Set M)) : s.topologicalClosure ≀ t := closure_minimal h ht /-- If a submonoid of a topological monoid is commutative, then so is its topological closure. -/ @[to_additive "If a submonoid of an additive topological monoid is commutative, then so is its topological closure. See note [reducible non-instances]."] abbrev Submonoid.commMonoidTopologicalClosure [T2Space M] (s : Submonoid M) (hs : βˆ€ x y : s, x * y = y * x) : CommMonoid s.topologicalClosure := { s.topologicalClosure.toMonoid, s.toSubsemigroup.commSemigroupTopologicalClosure hs with } @[to_additive exists_nhds_zero_quarter] theorem exists_nhds_one_split4 {u : Set M} (hu : u ∈ 𝓝 (1 : M)) : βˆƒ V ∈ 𝓝 (1 : M), βˆ€ {v w s t}, v ∈ V β†’ w ∈ V β†’ s ∈ V β†’ t ∈ V β†’ v * w * s * t ∈ u := by rcases exists_nhds_one_split hu with ⟨W, W1, h⟩ rcases exists_nhds_one_split W1 with ⟨V, V1, h'⟩ use V, V1 intro v w s t v_in w_in s_in t_in simpa only [mul_assoc] using h _ (h' v v_in w w_in) _ (h' s s_in t t_in) @[to_additive] theorem tendsto_list_prod {f : ΞΉ β†’ Ξ± β†’ M} {x : Filter Ξ±} {a : ΞΉ β†’ M} : βˆ€ l : List ΞΉ, (βˆ€ i ∈ l, Tendsto (f i) x (𝓝 (a i))) β†’ Tendsto (fun b => (l.map fun c => f c b).prod) x (𝓝 (l.map a).prod) | [], _ => by simp [tendsto_const_nhds] | f::l, h => by simp only [List.map_cons, List.prod_cons] exact (h f List.mem_cons_self).mul (tendsto_list_prod l fun c hc => h c (List.mem_cons_of_mem _ hc)) @[to_additive (attr := continuity)] theorem continuous_list_prod {f : ΞΉ β†’ X β†’ M} (l : List ΞΉ) (h : βˆ€ i ∈ l, Continuous (f i)) : Continuous fun a => (l.map fun i => f i a).prod := continuous_iff_continuousAt.2 fun x => tendsto_list_prod l fun c hc => continuous_iff_continuousAt.1 (h c hc) x @[to_additive] theorem continuousOn_list_prod {f : ΞΉ β†’ X β†’ M} (l : List ΞΉ) {t : Set X} (h : βˆ€ i ∈ l, ContinuousOn (f i) t) : ContinuousOn (fun a => (l.map fun i => f i a).prod) t := by intro x hx rw [continuousWithinAt_iff_continuousAt_restrict _ hx] refine tendsto_list_prod _ fun i hi => ?_ specialize h i hi x hx rw [continuousWithinAt_iff_continuousAt_restrict _ hx] at h exact h @[to_additive (attr := continuity)] theorem continuous_pow : βˆ€ n : β„•, Continuous fun a : M => a ^ n | 0 => by simpa using continuous_const | k + 1 => by simp only [pow_succ'] exact continuous_id.mul (continuous_pow _) instance AddMonoid.continuousConstSMul_nat {A} [AddMonoid A] [TopologicalSpace A] [ContinuousAdd A] : ContinuousConstSMul β„• A := ⟨continuous_nsmul⟩ instance AddMonoid.continuousSMul_nat {A} [AddMonoid A] [TopologicalSpace A] [ContinuousAdd A] : ContinuousSMul β„• A := ⟨continuous_prod_of_discrete_left.mpr continuous_nsmul⟩ -- We register `Continuous.pow` as a `continuity` lemma with low penalty (so -- `continuity` will try it before other `continuity` lemmas). This is a -- workaround for goals of the form `Continuous fun x => x ^ 2`, where -- `continuity` applies `Continuous.mul` since the goal is defeq to -- `Continuous fun x => x * x`. -- -- To properly fix this, we should make sure that `continuity` applies its -- lemmas with reducible transparency, preventing the unfolding of `^`. But this -- is quite an invasive change. @[to_additive (attr := aesop safe -100 (rule_sets := [Continuous]), fun_prop)] theorem Continuous.pow {f : X β†’ M} (h : Continuous f) (n : β„•) : Continuous fun b => f b ^ n := (continuous_pow n).comp h @[to_additive] theorem continuousOn_pow {s : Set M} (n : β„•) : ContinuousOn (fun (x : M) => x ^ n) s := (continuous_pow n).continuousOn @[to_additive] theorem continuousAt_pow (x : M) (n : β„•) : ContinuousAt (fun (x : M) => x ^ n) x := (continuous_pow n).continuousAt @[to_additive] theorem Filter.Tendsto.pow {l : Filter Ξ±} {f : Ξ± β†’ M} {x : M} (hf : Tendsto f l (𝓝 x)) (n : β„•) : Tendsto (fun x => f x ^ n) l (𝓝 (x ^ n)) := (continuousAt_pow _ _).tendsto.comp hf @[to_additive] theorem ContinuousWithinAt.pow {f : X β†’ M} {x : X} {s : Set X} (hf : ContinuousWithinAt f s x) (n : β„•) : ContinuousWithinAt (fun x => f x ^ n) s x := Filter.Tendsto.pow hf n @[to_additive (attr := fun_prop)] theorem ContinuousAt.pow {f : X β†’ M} {x : X} (hf : ContinuousAt f x) (n : β„•) : ContinuousAt (fun x => f x ^ n) x := Filter.Tendsto.pow hf n @[to_additive (attr := fun_prop)] theorem ContinuousOn.pow {f : X β†’ M} {s : Set X} (hf : ContinuousOn f s) (n : β„•) : ContinuousOn (fun x => f x ^ n) s := fun x hx => (hf x hx).pow n /-- Left-multiplication by a left-invertible element of a topological monoid is proper, i.e., inverse images of compact sets are compact. -/ theorem Filter.tendsto_cocompact_mul_left {a b : M} (ha : b * a = 1) : Filter.Tendsto (fun x : M => a * x) (Filter.cocompact M) (Filter.cocompact M) := by refine Filter.Tendsto.of_tendsto_comp ?_ (Filter.comap_cocompact_le (continuous_mul_left b)) convert Filter.tendsto_id ext x simp [← mul_assoc, ha] /-- Right-multiplication by a right-invertible element of a topological monoid is proper, i.e., inverse images of compact sets are compact. -/ theorem Filter.tendsto_cocompact_mul_right {a b : M} (ha : a * b = 1) : Filter.Tendsto (fun x : M => x * a) (Filter.cocompact M) (Filter.cocompact M) := by refine Filter.Tendsto.of_tendsto_comp ?_ (Filter.comap_cocompact_le (continuous_mul_right b)) simp only [comp_mul_right, ha, mul_one] exact Filter.tendsto_id /-- If `R` acts on `A` via `A`, then continuous multiplication implies continuous scalar multiplication by constants. Notably, this instances applies when `R = A`, or when `[Algebra R A]` is available. -/ @[to_additive "If `R` acts on `A` via `A`, then continuous addition implies continuous affine addition by constants."] instance (priority := 100) IsScalarTower.continuousConstSMul {R A : Type*} [Monoid A] [SMul R A] [IsScalarTower R A A] [TopologicalSpace A] [ContinuousMul A] : ContinuousConstSMul R A where continuous_const_smul q := by simp +singlePass only [← smul_one_mul q (_ : A)] exact continuous_const.mul continuous_id /-- If the action of `R` on `A` commutes with left-multiplication, then continuous multiplication implies continuous scalar multiplication by constants. Notably, this instances applies when `R = Aᡐᡒᡖ`. -/ @[to_additive "If the action of `R` on `A` commutes with left-addition, then continuous addition implies continuous affine addition by constants. Notably, this instances applies when `R = Aᡃᡒᡖ`."] instance (priority := 100) SMulCommClass.continuousConstSMul {R A : Type*} [Monoid A] [SMul R A] [SMulCommClass R A A] [TopologicalSpace A] [ContinuousMul A] : ContinuousConstSMul R A where continuous_const_smul q := by simp +singlePass only [← mul_smul_one q (_ : A)] exact continuous_id.mul continuous_const end ContinuousMul namespace MulOpposite /-- If multiplication is continuous in `Ξ±`, then it also is in `αᡐᡒᡖ`. -/ @[to_additive "If addition is continuous in `Ξ±`, then it also is in `αᡃᡒᡖ`."] instance [TopologicalSpace Ξ±] [Mul Ξ±] [ContinuousMul Ξ±] : ContinuousMul αᡐᡒᡖ := ⟨continuous_op.comp (continuous_unop.snd'.mul continuous_unop.fst')⟩ end MulOpposite namespace Units open MulOpposite variable [TopologicalSpace Ξ±] [Monoid Ξ±] [ContinuousMul Ξ±] /-- If multiplication on a monoid is continuous, then multiplication on the units of the monoid, with respect to the induced topology, is continuous. Inversion is also continuous, but we register this in a later file, `Topology.Algebra.Group`, because the predicate `ContinuousInv` has not yet been defined. -/ @[to_additive "If addition on an additive monoid is continuous, then addition on the additive units of the monoid, with respect to the induced topology, is continuous. Negation is also continuous, but we register this in a later file, `Topology.Algebra.Group`, because the predicate `ContinuousNeg` has not yet been defined."] instance : ContinuousMul Ξ±Λ£ := isInducing_embedProduct.continuousMul (embedProduct Ξ±) end Units @[to_additive (attr := fun_prop)] theorem Continuous.units_map [Monoid M] [Monoid N] [TopologicalSpace M] [TopologicalSpace N] (f : M β†’* N) (hf : Continuous f) : Continuous (Units.map f) := Units.continuous_iff.2 ⟨hf.comp Units.continuous_val, hf.comp Units.continuous_coe_inv⟩ section variable [TopologicalSpace M] [CommMonoid M] @[to_additive] theorem Submonoid.mem_nhds_one (S : Submonoid M) (oS : IsOpen (S : Set M)) : (S : Set M) ∈ 𝓝 (1 : M) := IsOpen.mem_nhds oS S.one_mem variable [ContinuousMul M] @[to_additive]
Mathlib/Topology/Algebra/Monoid.lean
821
827
theorem tendsto_multiset_prod {f : ΞΉ β†’ Ξ± β†’ M} {x : Filter Ξ±} {a : ΞΉ β†’ M} (s : Multiset ΞΉ) : (βˆ€ i ∈ s, Tendsto (f i) x (𝓝 (a i))) β†’ Tendsto (fun b => (s.map fun c => f c b).prod) x (𝓝 (s.map a).prod) := by
rcases s with ⟨l⟩ simpa using tendsto_list_prod l @[to_additive]