Context
stringlengths
227
76.5k
target
stringlengths
0
11.6k
file_name
stringlengths
21
79
start
int64
14
3.67k
end
int64
16
3.69k
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Markus Himmel -/ import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero /-! # Kernels and cokernels In a category with zero morphisms, the kernel of a morphism `f : X ⟶ Y` is the equalizer of `f` and `0 : X ⟶ Y`. (Similarly the cokernel is the coequalizer.) The basic definitions are * `kernel : (X ⟶ Y) → C` * `kernel.ι : kernel f ⟶ X` * `kernel.condition : kernel.ι f ≫ f = 0` and * `kernel.lift (k : W ⟶ X) (h : k ≫ f = 0) : W ⟶ kernel f` (as well as the dual versions) ## Main statements Besides the definition and lifts, we prove * `kernel.ιZeroIsIso`: a kernel map of a zero morphism is an isomorphism * `kernel.eq_zero_of_epi_kernel`: if `kernel.ι f` is an epimorphism, then `f = 0` * `kernel.ofMono`: the kernel of a monomorphism is the zero object * `kernel.liftMono`: the lift of a monomorphism `k : W ⟶ X` such that `k ≫ f = 0` is still a monomorphism * `kernel.isLimitConeZeroCone`: if our category has a zero object, then the map from the zero object is a kernel map of any monomorphism * `kernel.ιOfZero`: `kernel.ι (0 : X ⟶ Y)` is an isomorphism and the corresponding dual statements. ## Future work * TODO: connect this with existing work in the group theory and ring theory libraries. ## Implementation notes As with the other special shapes in the limits library, all the definitions here are given as `abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about general limits can be used. ## References * [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2] -/ noncomputable section universe v v₂ u u' u₂ open CategoryTheory open CategoryTheory.Limits.WalkingParallelPair namespace CategoryTheory.Limits variable {C : Type u} [Category.{v} C] variable [HasZeroMorphisms C] /-- A morphism `f` has a kernel if the functor `ParallelPair f 0` has a limit. -/ abbrev HasKernel {X Y : C} (f : X ⟶ Y) : Prop := HasLimit (parallelPair f 0) /-- A morphism `f` has a cokernel if the functor `ParallelPair f 0` has a colimit. -/ abbrev HasCokernel {X Y : C} (f : X ⟶ Y) : Prop := HasColimit (parallelPair f 0) variable {X Y : C} (f : X ⟶ Y) section /-- A kernel fork is just a fork where the second morphism is a zero morphism. -/ abbrev KernelFork := Fork f 0 variable {f} @[reassoc (attr := simp)] theorem KernelFork.condition (s : KernelFork f) : Fork.ι s ≫ f = 0 := by rw [Fork.condition, HasZeroMorphisms.comp_zero] theorem KernelFork.app_one (s : KernelFork f) : s.π.app one = 0 := by simp [Fork.app_one_eq_ι_comp_right] /-- A morphism `ι` satisfying `ι ≫ f = 0` determines a kernel fork over `f`. -/ abbrev KernelFork.ofι {Z : C} (ι : Z ⟶ X) (w : ι ≫ f = 0) : KernelFork f := Fork.ofι ι <| by rw [w, HasZeroMorphisms.comp_zero] @[simp] theorem KernelFork.ι_ofι {X Y P : C} (f : X ⟶ Y) (ι : P ⟶ X) (w : ι ≫ f = 0) : Fork.ι (KernelFork.ofι ι w) = ι := rfl section -- attribute [local tidy] tactic.case_bash Porting note: no tidy nor case_bash /-- Every kernel fork `s` is isomorphic (actually, equal) to `fork.ofι (fork.ι s) _`. -/ def isoOfι (s : Fork f 0) : s ≅ Fork.ofι (Fork.ι s) (Fork.condition s) := Cones.ext (Iso.refl _) <| by rintro ⟨j⟩ <;> simp /-- If `ι = ι'`, then `fork.ofι ι _` and `fork.ofι ι' _` are isomorphic. -/ def ofιCongr {P : C} {ι ι' : P ⟶ X} {w : ι ≫ f = 0} (h : ι = ι') : KernelFork.ofι ι w ≅ KernelFork.ofι ι' (by rw [← h, w]) := Cones.ext (Iso.refl _) /-- If `F` is an equivalence, then applying `F` to a diagram indexing a (co)kernel of `f` yields the diagram indexing the (co)kernel of `F.map f`. -/ def compNatIso {D : Type u'} [Category.{v} D] [HasZeroMorphisms D] (F : C ⥤ D) [F.IsEquivalence] : parallelPair f 0 ⋙ F ≅ parallelPair (F.map f) 0 := let app (j : WalkingParallelPair) : (parallelPair f 0 ⋙ F).obj j ≅ (parallelPair (F.map f) 0).obj j := match j with | zero => Iso.refl _ | one => Iso.refl _ NatIso.ofComponents app <| by rintro ⟨i⟩ ⟨j⟩ <;> intro g <;> cases g <;> simp [app] end /-- If `s` is a limit kernel fork and `k : W ⟶ X` satisfies `k ≫ f = 0`, then there is some `l : W ⟶ s.X` such that `l ≫ fork.ι s = k`. -/ def KernelFork.IsLimit.lift' {s : KernelFork f} (hs : IsLimit s) {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : { l : W ⟶ s.pt // l ≫ Fork.ι s = k } := ⟨hs.lift <| KernelFork.ofι _ h, hs.fac _ _⟩ /-- This is a slightly more convenient method to verify that a kernel fork is a limit cone. It only asks for a proof of facts that carry any mathematical content -/ def isLimitAux (t : KernelFork f) (lift : ∀ s : KernelFork f, s.pt ⟶ t.pt) (fac : ∀ s : KernelFork f, lift s ≫ t.ι = s.ι) (uniq : ∀ (s : KernelFork f) (m : s.pt ⟶ t.pt) (_ : m ≫ t.ι = s.ι), m = lift s) : IsLimit t := { lift fac := fun s j => by cases j · exact fac s · simp uniq := fun s m w => uniq s m (w Limits.WalkingParallelPair.zero) } /-- This is a more convenient formulation to show that a `KernelFork` constructed using `KernelFork.ofι` is a limit cone. -/ def KernelFork.IsLimit.ofι {W : C} (g : W ⟶ X) (eq : g ≫ f = 0) (lift : ∀ {W' : C} (g' : W' ⟶ X) (_ : g' ≫ f = 0), W' ⟶ W) (fac : ∀ {W' : C} (g' : W' ⟶ X) (eq' : g' ≫ f = 0), lift g' eq' ≫ g = g') (uniq : ∀ {W' : C} (g' : W' ⟶ X) (eq' : g' ≫ f = 0) (m : W' ⟶ W) (_ : m ≫ g = g'), m = lift g' eq') : IsLimit (KernelFork.ofι g eq) := isLimitAux _ (fun s => lift s.ι s.condition) (fun s => fac s.ι s.condition) fun s => uniq s.ι s.condition /-- This is a more convenient formulation to show that a `KernelFork` of the form `KernelFork.ofι i _` is a limit cone when we know that `i` is a monomorphism. -/ def KernelFork.IsLimit.ofι' {X Y K : C} {f : X ⟶ Y} (i : K ⟶ X) (w : i ≫ f = 0) (h : ∀ {A : C} (k : A ⟶ X) (_ : k ≫ f = 0), { l : A ⟶ K // l ≫ i = k}) [hi : Mono i] : IsLimit (KernelFork.ofι i w) := ofι _ _ (fun {_} k hk => (h k hk).1) (fun {_} k hk => (h k hk).2) (fun {A} k hk m hm => by rw [← cancel_mono i, (h k hk).2, hm]) /-- Every kernel of `f` induces a kernel of `f ≫ g` if `g` is mono. -/ def isKernelCompMono {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟶ Z) [hg : Mono g] {h : X ⟶ Z} (hh : h = f ≫ g) : IsLimit (KernelFork.ofι c.ι (by simp [hh]) : KernelFork h) := Fork.IsLimit.mk' _ fun s => let s' : KernelFork f := Fork.ofι s.ι (by rw [← cancel_mono g]; simp [← hh, s.condition]) let l := KernelFork.IsLimit.lift' i s'.ι s'.condition ⟨l.1, l.2, fun hm => by apply Fork.IsLimit.hom_ext i; rw [Fork.ι_ofι] at hm; rw [hm]; exact l.2.symm⟩ theorem isKernelCompMono_lift {c : KernelFork f} (i : IsLimit c) {Z} (g : Y ⟶ Z) [hg : Mono g] {h : X ⟶ Z} (hh : h = f ≫ g) (s : KernelFork h) : (isKernelCompMono i g hh).lift s = i.lift (Fork.ofι s.ι (by rw [← cancel_mono g, Category.assoc, ← hh] simp)) := rfl /-- Every kernel of `f ≫ g` is also a kernel of `f`, as long as `c.ι ≫ f` vanishes. -/ def isKernelOfComp {W : C} (g : Y ⟶ W) (h : X ⟶ W) {c : KernelFork h} (i : IsLimit c) (hf : c.ι ≫ f = 0) (hfg : f ≫ g = h) : IsLimit (KernelFork.ofι c.ι hf) := Fork.IsLimit.mk _ (fun s => i.lift (KernelFork.ofι s.ι (by simp [← hfg]))) (fun s => by simp only [KernelFork.ι_ofι, Fork.IsLimit.lift_ι]) fun s m h => by apply Fork.IsLimit.hom_ext i; simpa using h /-- `X` identifies to the kernel of a zero map `X ⟶ Y`. -/ def KernelFork.IsLimit.ofId {X Y : C} (f : X ⟶ Y) (hf : f = 0) : IsLimit (KernelFork.ofι (𝟙 X) (show 𝟙 X ≫ f = 0 by rw [hf, comp_zero])) := KernelFork.IsLimit.ofι _ _ (fun x _ => x) (fun _ _ => Category.comp_id _) (fun _ _ _ hb => by simp only [← hb, Category.comp_id]) /-- Any zero object identifies to the kernel of a given monomorphisms. -/ def KernelFork.IsLimit.ofMonoOfIsZero {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hf : Mono f) (h : IsZero c.pt) : IsLimit c := isLimitAux _ (fun _ => 0) (fun s => by rw [zero_comp, ← cancel_mono f, zero_comp, s.condition]) (fun _ _ _ => h.eq_of_tgt _ _) lemma KernelFork.IsLimit.isIso_ι {X Y : C} {f : X ⟶ Y} (c : KernelFork f) (hc : IsLimit c) (hf : f = 0) : IsIso c.ι := by let e : c.pt ≅ X := IsLimit.conePointUniqueUpToIso hc (KernelFork.IsLimit.ofId (f : X ⟶ Y) hf) have eq : e.inv ≫ c.ι = 𝟙 X := Fork.IsLimit.lift_ι hc haveI : IsIso (e.inv ≫ c.ι) := by rw [eq] infer_instance exact IsIso.of_isIso_comp_left e.inv c.ι /-- If `c` is a limit kernel fork for `g : X ⟶ Y`, `e : X ≅ X'` and `g' : X' ⟶ Y` is a morphism, then there is a limit kernel fork for `g'` with the same point as `c` if for any morphism `φ : W ⟶ X`, there is an equivalence `φ ≫ g = 0 ↔ φ ≫ e.hom ≫ g' = 0`. -/ def KernelFork.isLimitOfIsLimitOfIff {X Y : C} {g : X ⟶ Y} {c : KernelFork g} (hc : IsLimit c) {X' Y' : C} (g' : X' ⟶ Y') (e : X ≅ X') (iff : ∀ ⦃W : C⦄ (φ : W ⟶ X), φ ≫ g = 0 ↔ φ ≫ e.hom ≫ g' = 0) : IsLimit (KernelFork.ofι (f := g') (c.ι ≫ e.hom) (by simp [← iff])) := KernelFork.IsLimit.ofι _ _ (fun s hs ↦ hc.lift (KernelFork.ofι (ι := s ≫ e.inv) (by rw [iff, Category.assoc, Iso.inv_hom_id_assoc, hs]))) (fun s hs ↦ by simp [← cancel_mono e.inv]) (fun s hs m hm ↦ Fork.IsLimit.hom_ext hc (by simpa [← cancel_mono e.hom] using hm)) /-- If `c` is a limit kernel fork for `g : X ⟶ Y`, and `g' : X ⟶ Y'` is a another morphism, then there is a limit kernel fork for `g'` with the same point as `c` if for any morphism `φ : W ⟶ X`, there is an equivalence `φ ≫ g = 0 ↔ φ ≫ g' = 0`. -/ def KernelFork.isLimitOfIsLimitOfIff' {X Y : C} {g : X ⟶ Y} {c : KernelFork g} (hc : IsLimit c) {Y' : C} (g' : X ⟶ Y') (iff : ∀ ⦃W : C⦄ (φ : W ⟶ X), φ ≫ g = 0 ↔ φ ≫ g' = 0) : IsLimit (KernelFork.ofι (f := g') c.ι (by simp [← iff])) := IsLimit.ofIsoLimit (isLimitOfIsLimitOfIff hc g' (Iso.refl _) (by simpa using iff)) (Fork.ext (Iso.refl _)) end namespace KernelFork variable {f} {X' Y' : C} {f' : X' ⟶ Y'} /-- The morphism between points of kernel forks induced by a morphism in the category of arrows. -/ def mapOfIsLimit (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (φ : Arrow.mk f ⟶ Arrow.mk f') : kf.pt ⟶ kf'.pt := hf'.lift (KernelFork.ofι (kf.ι ≫ φ.left) (by simp)) @[reassoc (attr := simp)] lemma mapOfIsLimit_ι (kf : KernelFork f) {kf' : KernelFork f'} (hf' : IsLimit kf') (φ : Arrow.mk f ⟶ Arrow.mk f') : kf.mapOfIsLimit hf' φ ≫ kf'.ι = kf.ι ≫ φ.left := hf'.fac _ _ /-- The isomorphism between points of limit kernel forks induced by an isomorphism in the category of arrows. -/ @[simps] def mapIsoOfIsLimit {kf : KernelFork f} {kf' : KernelFork f'} (hf : IsLimit kf) (hf' : IsLimit kf') (φ : Arrow.mk f ≅ Arrow.mk f') : kf.pt ≅ kf'.pt where hom := kf.mapOfIsLimit hf' φ.hom inv := kf'.mapOfIsLimit hf φ.inv hom_inv_id := Fork.IsLimit.hom_ext hf (by simp) inv_hom_id := Fork.IsLimit.hom_ext hf' (by simp) end KernelFork section variable [HasKernel f] /-- The kernel of a morphism, expressed as the equalizer with the 0 morphism. -/ abbrev kernel (f : X ⟶ Y) [HasKernel f] : C := equalizer f 0 /-- The map from `kernel f` into the source of `f`. -/ abbrev kernel.ι : kernel f ⟶ X := equalizer.ι f 0 @[simp] theorem equalizer_as_kernel : equalizer.ι f 0 = kernel.ι f := rfl @[reassoc (attr := simp)] theorem kernel.condition : kernel.ι f ≫ f = 0 := KernelFork.condition _ /-- The kernel built from `kernel.ι f` is limiting. -/ def kernelIsKernel : IsLimit (Fork.ofι (kernel.ι f) ((kernel.condition f).trans comp_zero.symm)) := IsLimit.ofIsoLimit (limit.isLimit _) (Fork.ext (Iso.refl _) (by simp)) /-- Given any morphism `k : W ⟶ X` satisfying `k ≫ f = 0`, `k` factors through `kernel.ι f` via `kernel.lift : W ⟶ kernel f`. -/ abbrev kernel.lift {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : W ⟶ kernel f := (kernelIsKernel f).lift (KernelFork.ofι k h) @[reassoc (attr := simp)] theorem kernel.lift_ι {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : kernel.lift f k h ≫ kernel.ι f = k := (kernelIsKernel f).fac (KernelFork.ofι k h) WalkingParallelPair.zero @[simp] theorem kernel.lift_zero {W : C} {h} : kernel.lift f (0 : W ⟶ X) h = 0 := by ext; simp instance kernel.lift_mono {W : C} (k : W ⟶ X) (h : k ≫ f = 0) [Mono k] : Mono (kernel.lift f k h) := ⟨fun {Z} g g' w => by replace w := w =≫ kernel.ι f simp only [Category.assoc, kernel.lift_ι] at w exact (cancel_mono k).1 w⟩ /-- Any morphism `k : W ⟶ X` satisfying `k ≫ f = 0` induces a morphism `l : W ⟶ kernel f` such that `l ≫ kernel.ι f = k`. -/ def kernel.lift' {W : C} (k : W ⟶ X) (h : k ≫ f = 0) : { l : W ⟶ kernel f // l ≫ kernel.ι f = k } := ⟨kernel.lift f k h, kernel.lift_ι _ _ _⟩ /-- A commuting square induces a morphism of kernels. -/ abbrev kernel.map {X' Y' : C} (f' : X' ⟶ Y') [HasKernel f'] (p : X ⟶ X') (q : Y ⟶ Y') (w : f ≫ q = p ≫ f') : kernel f ⟶ kernel f' := kernel.lift f' (kernel.ι f ≫ p) (by simp [← w]) /-- Given a commutative diagram X --f--> Y --g--> Z | | | | | | v v v X' -f'-> Y' -g'-> Z' with horizontal arrows composing to zero, then we obtain a commutative square X ---> kernel g | | | | kernel.map | | v v X' --> kernel g' -/ theorem kernel.lift_map {X Y Z X' Y' Z' : C} (f : X ⟶ Y) (g : Y ⟶ Z) [HasKernel g] (w : f ≫ g = 0) (f' : X' ⟶ Y') (g' : Y' ⟶ Z') [HasKernel g'] (w' : f' ≫ g' = 0) (p : X ⟶ X') (q : Y ⟶ Y') (r : Z ⟶ Z') (h₁ : f ≫ q = p ≫ f') (h₂ : g ≫ r = q ≫ g') : kernel.lift g f w ≫ kernel.map g g' q r h₂ = p ≫ kernel.lift g' f' w' := by ext; simp [h₁] /-- A commuting square of isomorphisms induces an isomorphism of kernels. -/ @[simps] def kernel.mapIso {X' Y' : C} (f' : X' ⟶ Y') [HasKernel f'] (p : X ≅ X') (q : Y ≅ Y') (w : f ≫ q.hom = p.hom ≫ f') : kernel f ≅ kernel f' where hom := kernel.map f f' p.hom q.hom w inv := kernel.map f' f p.inv q.inv (by refine (cancel_mono q.hom).1 ?_ simp [w]) /-- Every kernel of the zero morphism is an isomorphism -/ instance kernel.ι_zero_isIso : IsIso (kernel.ι (0 : X ⟶ Y)) := equalizer.ι_of_self _ theorem eq_zero_of_epi_kernel [Epi (kernel.ι f)] : f = 0 := (cancel_epi (kernel.ι f)).1 (by simp) /-- The kernel of a zero morphism is isomorphic to the source. -/ def kernelZeroIsoSource : kernel (0 : X ⟶ Y) ≅ X := equalizer.isoSourceOfSelf 0 @[simp] theorem kernelZeroIsoSource_hom : kernelZeroIsoSource.hom = kernel.ι (0 : X ⟶ Y) := rfl @[simp] theorem kernelZeroIsoSource_inv : kernelZeroIsoSource.inv = kernel.lift (0 : X ⟶ Y) (𝟙 X) (by simp) := by ext simp [kernelZeroIsoSource] /-- If two morphisms are known to be equal, then their kernels are isomorphic. -/ def kernelIsoOfEq {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : kernel f ≅ kernel g := HasLimit.isoOfNatIso (by rw [h]) @[simp] theorem kernelIsoOfEq_refl {h : f = f} : kernelIsoOfEq h = Iso.refl (kernel f) := by ext simp [kernelIsoOfEq] /- Porting note: induction on Eq is trying instantiate another g... -/ @[reassoc (attr := simp)] theorem kernelIsoOfEq_hom_comp_ι {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).hom ≫ kernel.ι g = kernel.ι f := by cases h; simp @[reassoc (attr := simp)] theorem kernelIsoOfEq_inv_comp_ι {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) : (kernelIsoOfEq h).inv ≫ kernel.ι _ = kernel.ι _ := by cases h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_hom {Z} {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟶ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).hom = kernel.lift _ e (by simp [← h, he]) := by cases h; simp @[reassoc (attr := simp)] theorem lift_comp_kernelIsoOfEq_inv {Z} {f g : X ⟶ Y} [HasKernel f] [HasKernel g] (h : f = g) (e : Z ⟶ X) (he) : kernel.lift _ e he ≫ (kernelIsoOfEq h).inv = kernel.lift _ e (by simp [h, he]) := by cases h; simp @[simp] theorem kernelIsoOfEq_trans {f g h : X ⟶ Y} [HasKernel f] [HasKernel g] [HasKernel h] (w₁ : f = g) (w₂ : g = h) : kernelIsoOfEq w₁ ≪≫ kernelIsoOfEq w₂ = kernelIsoOfEq (w₁.trans w₂) := by cases w₁; cases w₂; ext; simp [kernelIsoOfEq] variable {f}
theorem kernel_not_epi_of_nonzero (w : f ≠ 0) : ¬Epi (kernel.ι f) := fun _ => w (eq_zero_of_epi_kernel f) theorem kernel_not_iso_of_nonzero (w : f ≠ 0) : IsIso (kernel.ι f) → False := fun _ =>
Mathlib/CategoryTheory/Limits/Shapes/Kernels.lean
400
403
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Group.Measure import Mathlib.MeasureTheory.Measure.Prod /-! # Measure theory in the product of groups In this file we show properties about measure theory in products of measurable groups and properties of iterated integrals in measurable groups. These lemmas show the uniqueness of left invariant measures on measurable groups, up to scaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos. The idea of the proof is to use the translation invariance of measures to prove `μ(t) = c * μ(s)` for two sets `s` and `t`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be the characteristic functions of `s` and `t`. Assume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)` preserves the measure `μ × ν`, which means that ``` ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ ``` If we apply this to `h x y := e x * f y⁻¹ / ν ((fun h ↦ h * y⁻¹) ⁻¹' s)`, we can rewrite the RHS to `μ(t)`, and the LHS to `c * μ(s)`, where `c = c(ν)` does not depend on `μ`. Applying this to `μ` and to `ν` gives `μ (t) / μ (s) = ν (t) / ν (s)`, which is the uniqueness up to scalar multiplication. The proof in [Halmos] seems to contain an omission in §60 Th. A, see `MeasureTheory.measure_lintegral_div_measure`. Note that this theory only applies in measurable groups, i.e., when multiplication and inversion are measurable. This is not the case in general in locally compact groups, or even in compact groups, when the topology is not second-countable. For arguments along the same line, but using continuous functions instead of measurable sets and working in the general locally compact setting, see the file `Mathlib/MeasureTheory/Measure/Haar/Unique.lean`. -/ noncomputable section open Set hiding prod_eq open Function MeasureTheory open Filter hiding map open scoped ENNReal Pointwise MeasureTheory variable (G : Type*) [MeasurableSpace G] variable [Group G] [MeasurableMul₂ G] variable (μ ν : Measure G) [SFinite ν] [SFinite μ] {s : Set G} /-- The map `(x, y) ↦ (x, xy)` as a `MeasurableEquiv`. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a `MeasurableEquiv`."] protected def MeasurableEquiv.shearMulRight [MeasurableInv G] : G × G ≃ᵐ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with measurable_toFun := measurable_fst.prodMk measurable_mul measurable_invFun := measurable_fst.prodMk <| measurable_fst.inv.mul measurable_snd } /-- The map `(x, y) ↦ (x, y / x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, yx)` -/ @[to_additive "The map `(x, y) ↦ (x, y - x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, y + x)`."] protected def MeasurableEquiv.shearDivRight [MeasurableInv G] : G × G ≃ᵐ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.divRight with measurable_toFun := measurable_fst.prodMk <| measurable_snd.div measurable_fst measurable_invFun := measurable_fst.prodMk <| measurable_snd.mul measurable_fst } variable {G} namespace MeasureTheory open Measure section LeftInvariant /-- The multiplicative shear mapping `(x, y) ↦ (x, xy)` preserves the measure `μ × ν`. This condition is part of the definition of a measurable group in [Halmos, §59]. There, the map in this lemma is called `S`. -/ @[to_additive measurePreserving_prod_add " The shear mapping `(x, y) ↦ (x, x + y)` preserves the measure `μ × ν`. "] theorem measurePreserving_prod_mul [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.1, z.1 * z.2)) (μ.prod ν) (μ.prod ν) := (MeasurePreserving.id μ).skew_product measurable_mul <| Filter.Eventually.of_forall <| map_mul_left_eq_self ν /-- The map `(x, y) ↦ (y, yx)` sends the measure `μ × ν` to `ν × μ`. This is the map `SR` in [Halmos, §59]. `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_prod_add_swap " The map `(x, y) ↦ (y, y + x)` sends the measure `μ × ν` to `ν × μ`. "] theorem measurePreserving_prod_mul_swap [IsMulLeftInvariant μ] : MeasurePreserving (fun z : G × G => (z.2, z.2 * z.1)) (μ.prod ν) (ν.prod μ) := (measurePreserving_prod_mul ν μ).comp measurePreserving_swap @[to_additive] theorem measurable_measure_mul_right (hs : MeasurableSet s) : Measurable fun x => μ ((fun y => y * x) ⁻¹' s) := by suffices Measurable fun y => μ ((fun x => (x, y)) ⁻¹' ((fun z : G × G => ((1 : G), z.1 * z.2)) ⁻¹' univ ×ˢ s)) by convert this using 1; ext1 x; congr 1 with y : 1; simp apply measurable_measure_prodMk_right apply measurable_const.prodMk measurable_mul (MeasurableSet.univ.prod hs) infer_instance variable [MeasurableInv G] /-- The map `(x, y) ↦ (x, x⁻¹y)` is measure-preserving. This is the function `S⁻¹` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)`. -/ @[to_additive measurePreserving_prod_neg_add "The map `(x, y) ↦ (x, - x + y)` is measure-preserving."] theorem measurePreserving_prod_inv_mul [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.1, z.1⁻¹ * z.2)) (μ.prod ν) (μ.prod ν) := (measurePreserving_prod_mul μ ν).symm <| MeasurableEquiv.shearMulRight G variable [IsMulLeftInvariant μ] /-- The map `(x, y) ↦ (y, y⁻¹x)` sends `μ × ν` to `ν × μ`. This is the function `S⁻¹R` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_prod_neg_add_swap "The map `(x, y) ↦ (y, - y + x)` sends `μ × ν` to `ν × μ`."] theorem measurePreserving_prod_inv_mul_swap : MeasurePreserving (fun z : G × G => (z.2, z.2⁻¹ * z.1)) (μ.prod ν) (ν.prod μ) := (measurePreserving_prod_inv_mul ν μ).comp measurePreserving_swap /-- The map `(x, y) ↦ (yx, x⁻¹)` is measure-preserving. This is the function `S⁻¹RSR` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_add_prod_neg "The map `(x, y) ↦ (y + x, - x)` is measure-preserving."] theorem measurePreserving_mul_prod_inv [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod ν) (μ.prod ν) := by convert (measurePreserving_prod_inv_mul_swap ν μ).comp (measurePreserving_prod_mul_swap μ ν) using 1 ext1 ⟨x, y⟩ simp_rw [Function.comp_apply, mul_inv_rev, inv_mul_cancel_right] @[to_additive] theorem quasiMeasurePreserving_inv : QuasiMeasurePreserving (Inv.inv : G → G) μ μ := by refine ⟨measurable_inv, AbsolutelyContinuous.mk fun s hsm hμs => ?_⟩ rw [map_apply measurable_inv hsm, inv_preimage] have hf : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) := (measurable_snd.mul measurable_fst).prodMk measurable_fst.inv suffices map (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (s⁻¹ ×ˢ s⁻¹) = 0 by simpa only [(measurePreserving_mul_prod_inv μ μ).map_eq, prod_prod, mul_eq_zero (M₀ := ℝ≥0∞), or_self_iff] using this have hsm' : MeasurableSet (s⁻¹ ×ˢ s⁻¹) := hsm.inv.prod hsm.inv simp_rw [map_apply hf hsm', prod_apply_symm (μ := μ) (ν := μ) (hf hsm'), preimage_preimage, mk_preimage_prod, inv_preimage, inv_inv, measure_mono_null inter_subset_right hμs, lintegral_zero] @[to_additive (attr := simp)] theorem measure_inv_null : μ s⁻¹ = 0 ↔ μ s = 0 := by refine ⟨fun hs => ?_, (quasiMeasurePreserving_inv μ).preimage_null⟩ rw [← inv_inv s] exact (quasiMeasurePreserving_inv μ).preimage_null hs @[to_additive (attr := simp)] theorem inv_ae : (ae μ)⁻¹ = ae μ := by refine le_antisymm (quasiMeasurePreserving_inv μ).tendsto_ae ?_ nth_rewrite 1 [← inv_inv (ae μ)] exact Filter.map_mono (quasiMeasurePreserving_inv μ).tendsto_ae @[to_additive (attr := simp)] theorem eventuallyConst_inv_set_ae : EventuallyConst (s⁻¹ : Set G) (ae μ) ↔ EventuallyConst s (ae μ) := by rw [← inv_preimage, eventuallyConst_preimage, Filter.map_inv, inv_ae] @[to_additive] theorem inv_absolutelyContinuous : μ.inv ≪ μ := (quasiMeasurePreserving_inv μ).absolutelyContinuous @[to_additive] theorem absolutelyContinuous_inv : μ ≪ μ.inv := by refine AbsolutelyContinuous.mk fun s _ => ?_ simp_rw [inv_apply μ s, measure_inv_null, imp_self] @[to_additive] theorem lintegral_lintegral_mul_inv [IsMulLeftInvariant ν] (f : G → G → ℝ≥0∞) (hf : AEMeasurable (uncurry f) (μ.prod ν)) : (∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ) = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ := by have h : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) := (measurable_snd.mul measurable_fst).prodMk measurable_fst.inv have h2f : AEMeasurable (uncurry fun x y => f (y * x) x⁻¹) (μ.prod ν) := hf.comp_quasiMeasurePreserving (measurePreserving_mul_prod_inv μ ν).quasiMeasurePreserving simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf] conv_rhs => rw [← (measurePreserving_mul_prod_inv μ ν).map_eq] symm exact lintegral_map' (hf.mono' (measurePreserving_mul_prod_inv μ ν).map_eq.absolutelyContinuous) h.aemeasurable @[to_additive] theorem measure_mul_right_null (y : G) : μ ((fun x => x * y) ⁻¹' s) = 0 ↔ μ s = 0 := calc μ ((fun x => x * y) ⁻¹' s) = 0 ↔ μ ((fun x => y⁻¹ * x) ⁻¹' s⁻¹)⁻¹ = 0 := by simp_rw [← inv_preimage, preimage_preimage, mul_inv_rev, inv_inv] _ ↔ μ s = 0 := by simp only [measure_inv_null μ, measure_preimage_mul] @[to_additive] theorem measure_mul_right_ne_zero (h2s : μ s ≠ 0) (y : G) : μ ((fun x => x * y) ⁻¹' s) ≠ 0 := (not_congr (measure_mul_right_null μ y)).mpr h2s @[to_additive] theorem absolutelyContinuous_map_mul_right (g : G) : μ ≪ map (· * g) μ := by refine AbsolutelyContinuous.mk fun s hs => ?_ rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null]; exact id @[to_additive] theorem absolutelyContinuous_map_div_left (g : G) : μ ≪ map (fun h => g / h) μ := by simp_rw [div_eq_mul_inv] have := map_map (μ := μ) (measurable_const_mul g) measurable_inv simp only [Function.comp_def] at this rw [← this] conv_lhs => rw [← map_mul_left_eq_self μ g] exact (absolutelyContinuous_inv μ).map (measurable_const_mul g) /-- This is the computation performed in the proof of [Halmos, §60 Th. A]. -/ @[to_additive "This is the computation performed in the proof of [Halmos, §60 Th. A]."] theorem measure_mul_lintegral_eq [IsMulLeftInvariant ν] (sm : MeasurableSet s) (f : G → ℝ≥0∞) (hf : Measurable f) : (μ s * ∫⁻ y, f y ∂ν) = ∫⁻ x, ν ((fun z => z * x) ⁻¹' s) * f x⁻¹ ∂μ := by rw [← setLIntegral_one, ← lintegral_indicator sm, ← lintegral_lintegral_mul (measurable_const.indicator sm).aemeasurable hf.aemeasurable, ← lintegral_lintegral_mul_inv μ ν] swap
· exact (((measurable_const.indicator sm).comp measurable_fst).mul (hf.comp measurable_snd)).aemeasurable have ms :
Mathlib/MeasureTheory/Group/Prod.lean
230
232
/- Copyright (c) 2022 Xavier Roblot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex J. Best, Xavier Roblot -/ import Mathlib.Algebra.Algebra.Hom.Rat import Mathlib.Analysis.Complex.Polynomial.Basic import Mathlib.NumberTheory.NumberField.Norm import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.Topology.Instances.Complex /-! # Embeddings of number fields This file defines the embeddings of a number field into an algebraic closed field. ## Main Definitions and Results * `NumberField.Embeddings.range_eval_eq_rootSet_minpoly`: let `x ∈ K` with `K` number field and let `A` be an algebraic closed field of char. 0, then the images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`. * `NumberField.Embeddings.pow_eq_one_of_norm_eq_one`: an algebraic integer whose conjugates are all of norm one is a root of unity. * `NumberField.InfinitePlace`: the type of infinite places of a number field `K`. * `NumberField.InfinitePlace.mk_eq_iff`: two complex embeddings define the same infinite place iff they are equal or complex conjugates. * `NumberField.InfinitePlace.prod_eq_abs_norm`: the infinite part of the product formula, that is for `x ∈ K`, we have `Π_w ‖x‖_w = |norm(x)|` where the product is over the infinite place `w` and `‖·‖_w` is the normalized absolute value for `w`. ## Tags number field, embeddings, places, infinite places -/ open scoped Finset namespace NumberField.Embeddings section Fintype open Module variable (K : Type*) [Field K] [NumberField K] variable (A : Type*) [Field A] [CharZero A] /-- There are finitely many embeddings of a number field. -/ noncomputable instance : Fintype (K →+* A) := Fintype.ofEquiv (K →ₐ[ℚ] A) RingHom.equivRatAlgHom.symm variable [IsAlgClosed A] /-- The number of embeddings of a number field is equal to its finrank. -/ theorem card : Fintype.card (K →+* A) = finrank ℚ K := by rw [Fintype.ofEquiv_card RingHom.equivRatAlgHom.symm, AlgHom.card] instance : Nonempty (K →+* A) := by rw [← Fintype.card_pos_iff, NumberField.Embeddings.card K A] exact Module.finrank_pos end Fintype section Roots open Set Polynomial variable (K A : Type*) [Field K] [NumberField K] [Field A] [Algebra ℚ A] [IsAlgClosed A] (x : K) /-- Let `A` be an algebraically closed field and let `x ∈ K`, with `K` a number field. The images of `x` by the embeddings of `K` in `A` are exactly the roots in `A` of the minimal polynomial of `x` over `ℚ`. -/ theorem range_eval_eq_rootSet_minpoly : (range fun φ : K →+* A => φ x) = (minpoly ℚ x).rootSet A := by convert (NumberField.isAlgebraic K).range_eval_eq_rootSet_minpoly A x using 1 ext a exact ⟨fun ⟨φ, hφ⟩ => ⟨φ.toRatAlgHom, hφ⟩, fun ⟨φ, hφ⟩ => ⟨φ.toRingHom, hφ⟩⟩ end Roots section Bounded open Module Polynomial Set variable {K : Type*} [Field K] [NumberField K] variable {A : Type*} [NormedField A] [IsAlgClosed A] [NormedAlgebra ℚ A] theorem coeff_bdd_of_norm_le {B : ℝ} {x : K} (h : ∀ φ : K →+* A, ‖φ x‖ ≤ B) (i : ℕ) : ‖(minpoly ℚ x).coeff i‖ ≤ max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2) := by have hx := Algebra.IsSeparable.isIntegral ℚ x rw [← norm_algebraMap' A, ← coeff_map (algebraMap ℚ A)] refine coeff_bdd_of_roots_le _ (minpoly.monic hx) (IsAlgClosed.splits_codomain _) (minpoly.natDegree_le x) (fun z hz => ?_) i classical rw [← Multiset.mem_toFinset] at hz obtain ⟨φ, rfl⟩ := (range_eval_eq_rootSet_minpoly K A x).symm.subset hz exact h φ variable (K A) /-- Let `B` be a real number. The set of algebraic integers in `K` whose conjugates are all smaller in norm than `B` is finite. -/ theorem finite_of_norm_le (B : ℝ) : {x : K | IsIntegral ℤ x ∧ ∀ φ : K →+* A, ‖φ x‖ ≤ B}.Finite := by classical let C := Nat.ceil (max B 1 ^ finrank ℚ K * (finrank ℚ K).choose (finrank ℚ K / 2)) have := bUnion_roots_finite (algebraMap ℤ K) (finrank ℚ K) (finite_Icc (-C : ℤ) C) refine this.subset fun x hx => ?_; simp_rw [mem_iUnion] have h_map_ℚ_minpoly := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hx.1 refine ⟨_, ⟨?_, fun i => ?_⟩, mem_rootSet.2 ⟨minpoly.ne_zero hx.1, minpoly.aeval ℤ x⟩⟩ · rw [← (minpoly.monic hx.1).natDegree_map (algebraMap ℤ ℚ), ← h_map_ℚ_minpoly] exact minpoly.natDegree_le x rw [mem_Icc, ← abs_le, ← @Int.cast_le ℝ] refine (Eq.trans_le ?_ <| coeff_bdd_of_norm_le hx.2 i).trans (Nat.le_ceil _) rw [h_map_ℚ_minpoly, coeff_map, eq_intCast, Int.norm_cast_rat, Int.norm_eq_abs, Int.cast_abs] /-- An algebraic integer whose conjugates are all of norm one is a root of unity. -/ theorem pow_eq_one_of_norm_eq_one {x : K} (hxi : IsIntegral ℤ x) (hx : ∀ φ : K →+* A, ‖φ x‖ = 1) : ∃ (n : ℕ) (_ : 0 < n), x ^ n = 1 := by obtain ⟨a, -, b, -, habne, h⟩ := @Set.Infinite.exists_ne_map_eq_of_mapsTo _ _ _ _ (x ^ · : ℕ → K) Set.infinite_univ (by exact fun a _ => ⟨hxi.pow a, fun φ => by simp [hx φ]⟩) (finite_of_norm_le K A (1 : ℝ)) wlog hlt : b < a · exact this K A hxi hx b a habne.symm h.symm (habne.lt_or_lt.resolve_right hlt) refine ⟨a - b, tsub_pos_of_lt hlt, ?_⟩ rw [← Nat.sub_add_cancel hlt.le, pow_add, mul_left_eq_self₀] at h refine h.resolve_right fun hp => ?_ specialize hx (IsAlgClosed.lift (R := ℚ)).toRingHom rw [pow_eq_zero hp, map_zero, norm_zero] at hx; norm_num at hx end Bounded end NumberField.Embeddings section Place variable {K : Type*} [Field K] {A : Type*} [NormedDivisionRing A] [Nontrivial A] (φ : K →+* A) /-- An embedding into a normed division ring defines a place of `K` -/ def NumberField.place : AbsoluteValue K ℝ := (IsAbsoluteValue.toAbsoluteValue (norm : A → ℝ)).comp φ.injective @[simp] theorem NumberField.place_apply (x : K) : (NumberField.place φ) x = norm (φ x) := rfl end Place namespace NumberField.ComplexEmbedding open Complex NumberField open scoped ComplexConjugate variable {K : Type*} [Field K] {k : Type*} [Field k] variable (K) in /-- A (random) lift of the complex embedding `φ : k →+* ℂ` to an extension `K` of `k`. -/ noncomputable def lift [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : K →+* ℂ := by letI := φ.toAlgebra exact (IsAlgClosed.lift (R := k)).toRingHom @[simp] theorem lift_comp_algebraMap [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) : (lift K φ).comp (algebraMap k K) = φ := by unfold lift letI := φ.toAlgebra rw [AlgHom.toRingHom_eq_coe, AlgHom.comp_algebraMap_of_tower, RingHom.algebraMap_toAlgebra'] @[simp] theorem lift_algebraMap_apply [Algebra k K] [Algebra.IsAlgebraic k K] (φ : k →+* ℂ) (x : k) : lift K φ (algebraMap k K x) = φ x := RingHom.congr_fun (lift_comp_algebraMap φ) x /-- The conjugate of a complex embedding as a complex embedding. -/ abbrev conjugate (φ : K →+* ℂ) : K →+* ℂ := star φ @[simp] theorem conjugate_coe_eq (φ : K →+* ℂ) (x : K) : (conjugate φ) x = conj (φ x) := rfl theorem place_conjugate (φ : K →+* ℂ) : place (conjugate φ) = place φ := by ext; simp only [place_apply, norm_conj, conjugate_coe_eq] /-- An embedding into `ℂ` is real if it is fixed by complex conjugation. -/ abbrev IsReal (φ : K →+* ℂ) : Prop := IsSelfAdjoint φ theorem isReal_iff {φ : K →+* ℂ} : IsReal φ ↔ conjugate φ = φ := isSelfAdjoint_iff theorem isReal_conjugate_iff {φ : K →+* ℂ} : IsReal (conjugate φ) ↔ IsReal φ := IsSelfAdjoint.star_iff /-- A real embedding as a ring homomorphism from `K` to `ℝ` . -/ def IsReal.embedding {φ : K →+* ℂ} (hφ : IsReal φ) : K →+* ℝ where toFun x := (φ x).re map_one' := by simp only [map_one, one_re] map_mul' := by simp only [Complex.conj_eq_iff_im.mp (RingHom.congr_fun hφ _), map_mul, mul_re, mul_zero, tsub_zero, eq_self_iff_true, forall_const] map_zero' := by simp only [map_zero, zero_re] map_add' := by simp only [map_add, add_re, eq_self_iff_true, forall_const] @[simp] theorem IsReal.coe_embedding_apply {φ : K →+* ℂ} (hφ : IsReal φ) (x : K) : (hφ.embedding x : ℂ) = φ x := by apply Complex.ext · rfl · rw [ofReal_im, eq_comm, ← Complex.conj_eq_iff_im] exact RingHom.congr_fun hφ x lemma IsReal.comp (f : k →+* K) {φ : K →+* ℂ} (hφ : IsReal φ) : IsReal (φ.comp f) := by ext1 x; simpa using RingHom.congr_fun hφ (f x) lemma isReal_comp_iff {f : k ≃+* K} {φ : K →+* ℂ} : IsReal (φ.comp (f : k →+* K)) ↔ IsReal φ := ⟨fun H ↦ by convert H.comp f.symm.toRingHom; ext1; simp, IsReal.comp _⟩ lemma exists_comp_symm_eq_of_comp_eq [Algebra k K] [IsGalois k K] (φ ψ : K →+* ℂ) (h : φ.comp (algebraMap k K) = ψ.comp (algebraMap k K)) : ∃ σ : K ≃ₐ[k] K, φ.comp σ.symm = ψ := by letI := (φ.comp (algebraMap k K)).toAlgebra letI := φ.toAlgebra have : IsScalarTower k K ℂ := IsScalarTower.of_algebraMap_eq' rfl let ψ' : K →ₐ[k] ℂ := { ψ with commutes' := fun r ↦ (RingHom.congr_fun h r).symm } use (AlgHom.restrictNormal' ψ' K).symm ext1 x exact AlgHom.restrictNormal_commutes ψ' K x variable [Algebra k K] (φ : K →+* ℂ) (σ : K ≃ₐ[k] K) /-- `IsConj φ σ` states that `σ : K ≃ₐ[k] K` is the conjugation under the embedding `φ : K →+* ℂ`. -/ def IsConj : Prop := conjugate φ = φ.comp σ variable {φ σ} lemma IsConj.eq (h : IsConj φ σ) (x) : φ (σ x) = star (φ x) := RingHom.congr_fun h.symm x lemma IsConj.ext {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) (h₂ : IsConj φ σ₂) : σ₁ = σ₂ := AlgEquiv.ext fun x ↦ φ.injective ((h₁.eq x).trans (h₂.eq x).symm) lemma IsConj.ext_iff {σ₁ σ₂ : K ≃ₐ[k] K} (h₁ : IsConj φ σ₁) : σ₁ = σ₂ ↔ IsConj φ σ₂ := ⟨fun e ↦ e ▸ h₁, h₁.ext⟩ lemma IsConj.isReal_comp (h : IsConj φ σ) : IsReal (φ.comp (algebraMap k K)) := by ext1 x simp only [conjugate_coe_eq, RingHom.coe_comp, Function.comp_apply, ← h.eq, starRingEnd_apply, AlgEquiv.commutes] lemma isConj_one_iff : IsConj φ (1 : K ≃ₐ[k] K) ↔ IsReal φ := Iff.rfl
alias ⟨_, IsReal.isConjGal_one⟩ := ComplexEmbedding.isConj_one_iff
Mathlib/NumberTheory/NumberField/Embeddings.lean
247
248
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau, Mario Carneiro, Johan Commelin, Amelia Livingston, Anne Baanen -/ import Mathlib.Algebra.Algebra.Tower import Mathlib.Algebra.Field.IsField import Mathlib.Algebra.GroupWithZero.NonZeroDivisors import Mathlib.GroupTheory.MonoidLocalization.MonoidWithZero import Mathlib.RingTheory.Localization.Defs import Mathlib.RingTheory.OreLocalization.Ring /-! # Localizations of commutative rings This file contains various basic results on localizations. We characterize the localization of a commutative ring `R` at a submonoid `M` up to isomorphism; that is, a commutative ring `S` is the localization of `R` at `M` iff we can find a ring homomorphism `f : R →+* S` satisfying 3 properties: 1. For all `y ∈ M`, `f y` is a unit; 2. For all `z : S`, there exists `(x, y) : R × M` such that `z * f y = f x`; 3. For all `x, y : R` such that `f x = f y`, there exists `c ∈ M` such that `x * c = y * c`. (The converse is a consequence of 1.) In the following, let `R, P` be commutative rings, `S, Q` be `R`- and `P`-algebras and `M, T` be submonoids of `R` and `P` respectively, e.g.: ``` variable (R S P Q : Type*) [CommRing R] [CommRing S] [CommRing P] [CommRing Q] variable [Algebra R S] [Algebra P Q] (M : Submonoid R) (T : Submonoid P) ``` ## Main definitions * `IsLocalization.algEquiv`: if `Q` is another localization of `R` at `M`, then `S` and `Q` are isomorphic as `R`-algebras ## Implementation notes In maths it is natural to reason up to isomorphism, but in Lean we cannot naturally `rewrite` one structure with an isomorphic one; one way around this is to isolate a predicate characterizing a structure up to isomorphism, and reason about things that satisfy the predicate. A previous version of this file used a fully bundled type of ring localization maps, then used a type synonym `f.codomain` for `f : LocalizationMap M S` to instantiate the `R`-algebra structure on `S`. This results in defining ad-hoc copies for everything already defined on `S`. By making `IsLocalization` a predicate on the `algebraMap R S`, we can ensure the localization map commutes nicely with other `algebraMap`s. To prove most lemmas about a localization map `algebraMap R S` in this file we invoke the corresponding proof for the underlying `CommMonoid` localization map `IsLocalization.toLocalizationMap M S`, which can be found in `GroupTheory.MonoidLocalization` and the namespace `Submonoid.LocalizationMap`. To reason about the localization as a quotient type, use `mk_eq_of_mk'` and associated lemmas. These show the quotient map `mk : R → M → Localization M` equals the surjection `LocalizationMap.mk'` induced by the map `algebraMap : R →+* Localization M`. The lemma `mk_eq_of_mk'` hence gives you access to the results in the rest of the file, which are about the `LocalizationMap.mk'` induced by any localization map. The proof that "a `CommRing` `K` which is the localization of an integral domain `R` at `R \ {0}` is a field" is a `def` rather than an `instance`, so if you want to reason about a field of fractions `K`, assume `[Field K]` instead of just `[CommRing K]`. ## Tags localization, ring localization, commutative ring localization, characteristic predicate, commutative ring, field of fractions -/ assert_not_exists Ideal open Function namespace Localization open IsLocalization variable {ι : Type*} {R : ι → Type*} [∀ i, CommSemiring (R i)] variable {i : ι} (S : Submonoid (R i)) /-- `IsLocalization.map` applied to a projection homomorphism from a product ring. -/ noncomputable abbrev mapPiEvalRingHom : Localization (S.comap <| Pi.evalRingHom R i) →+* Localization S := map (T := S) _ (Pi.evalRingHom R i) le_rfl open Function in theorem mapPiEvalRingHom_bijective : Bijective (mapPiEvalRingHom S) := by let T := S.comap (Pi.evalRingHom R i) classical refine ⟨fun x₁ x₂ eq ↦ ?_, fun x ↦ ?_⟩ · obtain ⟨r₁, s₁, rfl⟩ := mk'_surjective T x₁ obtain ⟨r₂, s₂, rfl⟩ := mk'_surjective T x₂ simp_rw [map_mk'] at eq rw [IsLocalization.eq] at eq ⊢ obtain ⟨s, hs⟩ := eq refine ⟨⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, funext fun j ↦ ?_⟩ obtain rfl | ne := eq_or_ne j i · simpa using hs · simp [update_of_ne ne] · obtain ⟨r, s, rfl⟩ := mk'_surjective S x exact ⟨mk' (M := T) _ (update 0 i r) ⟨update 0 i s, by apply update_self i s.1 0 ▸ s.2⟩, by simp [map_mk']⟩ end Localization section CommSemiring variable {R : Type*} [CommSemiring R] {M N : Submonoid R} {S : Type*} [CommSemiring S] variable [Algebra R S] {P : Type*} [CommSemiring P] namespace IsLocalization section IsLocalization variable [IsLocalization M S] variable (M S) in include M in theorem linearMap_compatibleSMul (N₁ N₂) [AddCommMonoid N₁] [AddCommMonoid N₂] [Module R N₁] [Module S N₁] [Module R N₂] [Module S N₂] [IsScalarTower R S N₁] [IsScalarTower R S N₂] : LinearMap.CompatibleSMul N₁ N₂ S R where map_smul f s s' := by obtain ⟨r, m, rfl⟩ := mk'_surjective M s rw [← (map_units S m).smul_left_cancel] simp_rw [algebraMap_smul, ← map_smul, ← smul_assoc, smul_mk'_self, algebraMap_smul, map_smul] variable {g : R →+* P} (hg : ∀ y : M, IsUnit (g y)) variable (M) in include M in -- This is not an instance since the submonoid `M` would become a metavariable in typeclass search. theorem algHom_subsingleton [Algebra R P] : Subsingleton (S →ₐ[R] P) := ⟨fun f g => AlgHom.coe_ringHom_injective <| IsLocalization.ringHom_ext M <| by rw [f.comp_algebraMap, g.comp_algebraMap]⟩ section AlgEquiv variable {Q : Type*} [CommSemiring Q] [Algebra R Q] [IsLocalization M Q] section variable (M S Q) /-- If `S`, `Q` are localizations of `R` at the submonoid `M` respectively, there is an isomorphism of localizations `S ≃ₐ[R] Q`. -/ @[simps!] noncomputable def algEquiv : S ≃ₐ[R] Q := { ringEquivOfRingEquiv S Q (RingEquiv.refl R) M.map_id with commutes' := ringEquivOfRingEquiv_eq _ } end theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S Q (mk' S x y) = mk' Q x y := by simp theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S Q).symm (mk' Q x y) = mk' S x y := by simp variable (M) in include M in protected lemma bijective (f : S →+* Q) (hf : f.comp (algebraMap R S) = algebraMap R Q) : Function.Bijective f := (show f = IsLocalization.algEquiv M S Q by apply IsLocalization.ringHom_ext M; rw [hf]; ext; simp) ▸ (IsLocalization.algEquiv M S Q).toEquiv.bijective end AlgEquiv section liftAlgHom variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} {S : Type*} [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] {P : Type*} [CommSemiring P] [Algebra A P] [IsLocalization M S] {f : R →ₐ[A] P} (hf : ∀ y : M, IsUnit (f y)) (x : S) include hf /-- `AlgHom` version of `IsLocalization.lift`. -/ noncomputable def liftAlgHom : S →ₐ[A] P where __ := lift hf commutes' r := show lift hf (algebraMap A S r) = _ by simp [IsScalarTower.algebraMap_apply A R S] theorem liftAlgHom_toRingHom : (liftAlgHom hf : S →ₐ[A] P).toRingHom = lift hf := rfl @[simp] theorem coe_liftAlgHom : ⇑(liftAlgHom hf : S →ₐ[A] P) = lift hf := rfl theorem liftAlgHom_apply : liftAlgHom hf x = lift hf x := rfl end liftAlgHom section AlgEquivOfAlgEquiv variable {A : Type*} [CommSemiring A] {R : Type*} [CommSemiring R] [Algebra A R] {M : Submonoid R} (S : Type*) [CommSemiring S] [Algebra A S] [Algebra R S] [IsScalarTower A R S] [IsLocalization M S] {P : Type*} [CommSemiring P] [Algebra A P] {T : Submonoid P} (Q : Type*) [CommSemiring Q] [Algebra A Q] [Algebra P Q] [IsScalarTower A P Q] [IsLocalization T Q] (h : R ≃ₐ[A] P) (H : Submonoid.map h M = T) include H /-- If `S`, `Q` are localizations of `R` and `P` at submonoids `M`, `T` respectively, an isomorphism `h : R ≃ₐ[A] P` such that `h(M) = T` induces an isomorphism of localizations `S ≃ₐ[A] Q`. -/ @[simps!] noncomputable def algEquivOfAlgEquiv : S ≃ₐ[A] Q where __ := ringEquivOfRingEquiv S Q h.toRingEquiv H commutes' _ := by dsimp; rw [IsScalarTower.algebraMap_apply A R S, map_eq, RingHom.coe_coe, AlgEquiv.commutes, IsScalarTower.algebraMap_apply A P Q] variable {S Q h} theorem algEquivOfAlgEquiv_eq_map : (algEquivOfAlgEquiv S Q h H : S →+* Q) = map Q (h : R →+* P) (M.le_comap_of_map_le (le_of_eq H)) := rfl theorem algEquivOfAlgEquiv_eq (x : R) : algEquivOfAlgEquiv S Q h H ((algebraMap R S) x) = algebraMap P Q (h x) := by simp set_option linter.docPrime false in theorem algEquivOfAlgEquiv_mk' (x : R) (y : M) : algEquivOfAlgEquiv S Q h H (mk' S x y) = mk' Q (h x) ⟨h y, show h y ∈ T from H ▸ Set.mem_image_of_mem h y.2⟩ := by simp [map_mk'] theorem algEquivOfAlgEquiv_symm : (algEquivOfAlgEquiv S Q h H).symm = algEquivOfAlgEquiv Q S h.symm (show Submonoid.map h.symm T = M by rw [← H, ← Submonoid.map_coe_toMulEquiv, AlgEquiv.symm_toMulEquiv, ← Submonoid.comap_equiv_eq_map_symm, ← Submonoid.map_coe_toMulEquiv, Submonoid.comap_map_eq_of_injective (h : R ≃* P).injective]) := rfl end AlgEquivOfAlgEquiv section at_units variable (R M) /-- The localization at a module of units is isomorphic to the ring. -/ noncomputable def atUnits (H : M ≤ IsUnit.submonoid R) : R ≃ₐ[R] S := by refine AlgEquiv.ofBijective (Algebra.ofId R S) ⟨?_, ?_⟩ · intro x y hxy obtain ⟨c, eq⟩ := (IsLocalization.eq_iff_exists M S).mp hxy obtain ⟨u, hu⟩ := H c.prop rwa [← hu, Units.mul_right_inj] at eq · intro y obtain ⟨⟨x, s⟩, eq⟩ := IsLocalization.surj M y obtain ⟨u, hu⟩ := H s.prop use x * u.inv dsimp [Algebra.ofId, RingHom.toFun_eq_coe, AlgHom.coe_mks] rw [RingHom.map_mul, ← eq, ← hu, mul_assoc, ← RingHom.map_mul] simp end at_units end IsLocalization section variable (M N) theorem isLocalization_of_algEquiv [Algebra R P] [IsLocalization M S] (h : S ≃ₐ[R] P) : IsLocalization M P := by constructor · intro y convert (IsLocalization.map_units S y).map h.toAlgHom.toRingHom.toMonoidHom exact (h.commutes y).symm · intro y obtain ⟨⟨x, s⟩, e⟩ := IsLocalization.surj M (h.symm y) apply_fun (show S → P from h) at e simp only [map_mul, h.apply_symm_apply, h.commutes] at e exact ⟨⟨x, s⟩, e⟩ · intro x y rw [← h.symm.toEquiv.injective.eq_iff, ← IsLocalization.eq_iff_exists M S, ← h.symm.commutes, ← h.symm.commutes] exact id theorem isLocalization_iff_of_algEquiv [Algebra R P] (h : S ≃ₐ[R] P) : IsLocalization M S ↔ IsLocalization M P := ⟨fun _ => isLocalization_of_algEquiv M h, fun _ => isLocalization_of_algEquiv M h.symm⟩ theorem isLocalization_iff_of_ringEquiv (h : S ≃+* P) : IsLocalization M S ↔ haveI := (h.toRingHom.comp <| algebraMap R S).toAlgebra; IsLocalization M P := letI := (h.toRingHom.comp <| algebraMap R S).toAlgebra isLocalization_iff_of_algEquiv M { h with commutes' := fun _ => rfl } variable (S) in /-- If an algebra is simultaneously localizations for two submonoids, then an arbitrary algebra is a localization of one submonoid iff it is a localization of the other. -/ theorem isLocalization_iff_of_isLocalization [IsLocalization M S] [IsLocalization N S] [Algebra R P] : IsLocalization M P ↔ IsLocalization N P := ⟨fun _ ↦ isLocalization_of_algEquiv N (algEquiv M S P), fun _ ↦ isLocalization_of_algEquiv M (algEquiv N S P)⟩ theorem iff_of_le_of_exists_dvd (N : Submonoid R) (h₁ : M ≤ N) (h₂ : ∀ n ∈ N, ∃ m ∈ M, n ∣ m) : IsLocalization M S ↔ IsLocalization N S := have : IsLocalization N (Localization M) := of_le_of_exists_dvd _ _ h₁ h₂ isLocalization_iff_of_isLocalization _ _ (Localization M) end variable (M) /-- If `S₁` is the localization of `R` at `M₁` and `S₂` is the localization of `R` at `M₂`, then every localization `T` of `S₂` at `M₁` is also a localization of `S₁` at `M₂`, in other words `M₁⁻¹M₂⁻¹R` can be identified with `M₂⁻¹M₁⁻¹R`. -/ lemma commutes (S₁ S₂ T : Type*) [CommSemiring S₁] [CommSemiring S₂] [CommSemiring T] [Algebra R S₁] [Algebra R S₂] [Algebra R T] [Algebra S₁ T] [Algebra S₂ T] [IsScalarTower R S₁ T] [IsScalarTower R S₂ T] (M₁ M₂ : Submonoid R) [IsLocalization M₁ S₁] [IsLocalization M₂ S₂] [IsLocalization (Algebra.algebraMapSubmonoid S₂ M₁) T] : IsLocalization (Algebra.algebraMapSubmonoid S₁ M₂) T where map_units' := by rintro ⟨m, ⟨a, ha, rfl⟩⟩ rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] exact IsUnit.map _ (IsLocalization.map_units' ⟨a, ha⟩) surj' a := by obtain ⟨⟨y, -, m, hm, rfl⟩, hy⟩ := surj (M := Algebra.algebraMapSubmonoid S₂ M₁) a rw [← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₁ T] at hy obtain ⟨⟨z, n, hn⟩, hz⟩ := IsLocalization.surj (M := M₂) y have hunit : IsUnit (algebraMap R S₁ m) := map_units' ⟨m, hm⟩ use ⟨algebraMap R S₁ z * hunit.unit⁻¹, ⟨algebraMap R S₁ n, n, hn, rfl⟩⟩ rw [map_mul, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] conv_rhs => rw [← IsScalarTower.algebraMap_apply] rw [IsScalarTower.algebraMap_apply R S₂ T, ← hz, map_mul, ← hy] convert_to _ = a * (algebraMap S₂ T) ((algebraMap R S₂) n) * (algebraMap S₁ T) (((algebraMap R S₁) m) * hunit.unit⁻¹.val) · rw [map_mul] ring simp exists_of_eq {x y} hxy := by obtain ⟨r, s, d, hr, hs⟩ := IsLocalization.surj₂ M₁ S₁ x y apply_fun (· * algebraMap S₁ T (algebraMap R S₁ d)) at hxy simp_rw [← map_mul, hr, hs, ← IsScalarTower.algebraMap_apply, IsScalarTower.algebraMap_apply R S₂ T] at hxy obtain ⟨⟨-, c, hmc, rfl⟩, hc⟩ := exists_of_eq (M := Algebra.algebraMapSubmonoid S₂ M₁) hxy simp_rw [← map_mul] at hc obtain ⟨a, ha⟩ := IsLocalization.exists_of_eq (M := M₂) hc use ⟨algebraMap R S₁ a, a, a.property, rfl⟩ apply (map_units S₁ d).mul_right_cancel rw [mul_assoc, hr, mul_assoc, hs] apply (map_units S₁ ⟨c, hmc⟩).mul_right_cancel rw [← map_mul, ← map_mul, mul_assoc, mul_comm _ c, ha, map_mul, map_mul] ring end IsLocalization namespace Localization open IsLocalization theorem mk_natCast (m : ℕ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℕ) _ variable [IsLocalization M S] section variable (S) (M) /-- The localization of `R` at `M` as a quotient type is isomorphic to any other localization. -/ @[simps!] noncomputable def algEquiv : Localization M ≃ₐ[R] S := IsLocalization.algEquiv M _ _ /-- The localization of a singleton is a singleton. Cannot be an instance due to metavariables. -/ noncomputable def _root_.IsLocalization.unique (R Rₘ) [CommSemiring R] [CommSemiring Rₘ] (M : Submonoid R) [Subsingleton R] [Algebra R Rₘ] [IsLocalization M Rₘ] : Unique Rₘ := have : Inhabited Rₘ := ⟨1⟩ (algEquiv M Rₘ).symm.injective.unique end nonrec theorem algEquiv_mk' (x : R) (y : M) : algEquiv M S (mk' (Localization M) x y) = mk' S x y := algEquiv_mk' _ _ nonrec theorem algEquiv_symm_mk' (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk' (Localization M) x y := algEquiv_symm_mk' _ _ theorem algEquiv_mk (x y) : algEquiv M S (mk x y) = mk' S x y := by rw [mk_eq_mk', algEquiv_mk'] theorem algEquiv_symm_mk (x : R) (y : M) : (algEquiv M S).symm (mk' S x y) = mk x y := by rw [mk_eq_mk', algEquiv_symm_mk'] lemma coe_algEquiv : (Localization.algEquiv M S : Localization M →+* S) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl lemma coe_algEquiv_symm : ((Localization.algEquiv M S).symm : S →+* Localization M) = IsLocalization.map (M := M) (T := M) _ (RingHom.id R) le_rfl := rfl end Localization end CommSemiring section CommRing variable {R : Type*} [CommRing R] {M : Submonoid R} (S : Type*) [CommRing S] variable [Algebra R S] {P : Type*} [CommRing P] namespace Localization theorem mk_intCast (m : ℤ) : (mk m 1 : Localization M) = m := by simpa using mk_algebraMap (R := R) (A := ℤ) _ end Localization open IsLocalization /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem IsField.localization_map_bijective {R Rₘ : Type*} [CommRing R] [CommRing Rₘ] {M : Submonoid R} (hM : (0 : R) ∉ M) (hR : IsField R) [Algebra R Rₘ] [IsLocalization M Rₘ] : Function.Bijective (algebraMap R Rₘ) := by letI := hR.toField replace hM := le_nonZeroDivisors_of_noZeroDivisors hM refine ⟨IsLocalization.injective _ hM, fun x => ?_⟩ obtain ⟨r, ⟨m, hm⟩, rfl⟩ := mk'_surjective M x obtain ⟨n, hn⟩ := hR.mul_inv_cancel (nonZeroDivisors.ne_zero <| hM hm) exact ⟨r * n, by rw [eq_mk'_iff_mul_eq, ← map_mul, mul_assoc, _root_.mul_comm n, hn, mul_one]⟩ /-- If `R` is a field, then localizing at a submonoid not containing `0` adds no new elements. -/ theorem Field.localization_map_bijective {K Kₘ : Type*} [Field K] [CommRing Kₘ] {M : Submonoid K} (hM : (0 : K) ∉ M) [Algebra K Kₘ] [IsLocalization M Kₘ] : Function.Bijective (algebraMap K Kₘ) := (Field.toIsField K).localization_map_bijective hM -- this looks weird due to the `letI` inside the above lemma, but trying to do it the other -- way round causes issues with defeq of instances, so this is actually easier. section Algebra variable {S} {Rₘ Sₘ : Type*} [CommRing Rₘ] [CommRing Sₘ]
variable [Algebra R Rₘ] [IsLocalization M Rₘ] variable [Algebra S Sₘ] [i : IsLocalization (Algebra.algebraMapSubmonoid S M) Sₘ] include S
Mathlib/RingTheory/Localization/Basic.lean
438
440
/- Copyright (c) 2024 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Measure.GiryMonad import Mathlib.MeasureTheory.Measure.Stieltjes import Mathlib.Analysis.Normed.Order.Lattice import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Measurable parametric Stieltjes functions We provide tools to build a measurable function `α → StieltjesFunction` with limits 0 at -∞ and 1 at +∞ for all `a : α` from a measurable function `f : α → ℚ → ℝ`. These measurable parametric Stieltjes functions are cumulative distribution functions (CDF) of transition kernels. The reason for going through `ℚ` instead of defining directly a Stieltjes function is that since `ℚ` is countable, building a measurable function is easier and we can obtain properties of the form `∀ᵐ (a : α) ∂μ, ∀ (q : ℚ), ...` (for some measure `μ` on `α`) by proving the weaker `∀ (q : ℚ), ∀ᵐ (a : α) ∂μ, ...`. This construction will be possible if `f a : ℚ → ℝ` satisfies a package of properties for all `a`: monotonicity, limits at +-∞ and a continuity property. We define `IsRatStieltjesPoint f a` to state that this is the case at `a` and define the property `IsMeasurableRatCDF f` that `f` is measurable and `IsRatStieltjesPoint f a` for all `a`. The function `α → StieltjesFunction` obtained by extending `f` by continuity from the right is then called `IsMeasurableRatCDF.stieltjesFunction`. In applications, we will often only have `IsRatStieltjesPoint f a` almost surely with respect to some measure. In order to turn that almost everywhere property into an everywhere property we define `toRatCDF (f : α → ℚ → ℝ) := fun a q ↦ if IsRatStieltjesPoint f a then f a q else defaultRatCDF q`, which satisfies the property `IsMeasurableRatCDF (toRatCDF f)`. Finally, we define `stieltjesOfMeasurableRat`, composition of `toRatCDF` and `IsMeasurableRatCDF.stieltjesFunction`. ## Main definitions * `stieltjesOfMeasurableRat`: turn a measurable function `f : α → ℚ → ℝ` into a measurable function `α → StieltjesFunction`. -/ open MeasureTheory Set Filter TopologicalSpace open scoped NNReal ENNReal MeasureTheory Topology /-- A measurable function `α → StieltjesFunction` with limits 0 at -∞ and 1 at +∞ gives a measurable function `α → Measure ℝ` by taking `StieltjesFunction.measure` at each point. -/ lemma StieltjesFunction.measurable_measure {α : Type*} {_ : MeasurableSpace α} {f : α → StieltjesFunction} (hf : ∀ q, Measurable fun a ↦ f a q) (hf_bot : ∀ a, Tendsto (f a) atBot (𝓝 0)) (hf_top : ∀ a, Tendsto (f a) atTop (𝓝 1)) : Measurable fun a ↦ (f a).measure := have : ∀ a, IsProbabilityMeasure (f a).measure := fun a ↦ (f a).isProbabilityMeasure (hf_bot a) (hf_top a) .measure_of_isPiSystem_of_isProbabilityMeasure (borel_eq_generateFrom_Iic ℝ) isPiSystem_Iic <| by simp_rw [forall_mem_range, StieltjesFunction.measure_Iic (f _) (hf_bot _), sub_zero] exact fun _ ↦ (hf _).ennreal_ofReal namespace ProbabilityTheory variable {α : Type*} section IsMeasurableRatCDF variable {f : α → ℚ → ℝ} /-- `a : α` is a Stieltjes point for `f : α → ℚ → ℝ` if `f a` is monotone with limit 0 at -∞ and 1 at +∞ and satisfies a continuity property. -/ structure IsRatStieltjesPoint (f : α → ℚ → ℝ) (a : α) : Prop where mono : Monotone (f a) tendsto_atTop_one : Tendsto (f a) atTop (𝓝 1) tendsto_atBot_zero : Tendsto (f a) atBot (𝓝 0) iInf_rat_gt_eq : ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t lemma isRatStieltjesPoint_unit_prod_iff (f : α → ℚ → ℝ) (a : α) : IsRatStieltjesPoint (fun p : Unit × α ↦ f p.2) ((), a) ↔ IsRatStieltjesPoint f a := by constructor <;> exact fun h ↦ ⟨h.mono, h.tendsto_atTop_one, h.tendsto_atBot_zero, h.iInf_rat_gt_eq⟩ lemma measurableSet_isRatStieltjesPoint [MeasurableSpace α] (hf : Measurable f) : MeasurableSet {a | IsRatStieltjesPoint f a} := by have h1 : MeasurableSet {a | Monotone (f a)} := by change MeasurableSet {a | ∀ q r (_ : q ≤ r), f a q ≤ f a r} simp_rw [Set.setOf_forall] refine MeasurableSet.iInter (fun q ↦ ?_) refine MeasurableSet.iInter (fun r ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) exact measurableSet_le hf.eval hf.eval have h2 : MeasurableSet {a | Tendsto (f a) atTop (𝓝 1)} := measurableSet_tendsto _ (fun q ↦ hf.eval) have h3 : MeasurableSet {a | Tendsto (f a) atBot (𝓝 0)} := measurableSet_tendsto _ (fun q ↦ hf.eval) have h4 : MeasurableSet {a | ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t} := by rw [Set.setOf_forall] refine MeasurableSet.iInter (fun q ↦ ?_) exact measurableSet_eq_fun (.iInf fun _ ↦ hf.eval) hf.eval suffices {a | IsRatStieltjesPoint f a} = ({a | Monotone (f a)} ∩ {a | Tendsto (f a) atTop (𝓝 1)} ∩ {a | Tendsto (f a) atBot (𝓝 0)} ∩ {a | ∀ t : ℚ, ⨅ r : Ioi t, f a r = f a t}) by rw [this] exact (((h1.inter h2).inter h3).inter h4) ext a simp only [mem_setOf_eq, mem_inter_iff] refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · exact ⟨⟨⟨h.mono, h.tendsto_atTop_one⟩, h.tendsto_atBot_zero⟩, h.iInf_rat_gt_eq⟩ · exact ⟨h.1.1.1, h.1.1.2, h.1.2, h.2⟩ lemma IsRatStieltjesPoint.ite {f g : α → ℚ → ℝ} {a : α} (p : α → Prop) [DecidablePred p] (hf : p a → IsRatStieltjesPoint f a) (hg : ¬ p a → IsRatStieltjesPoint g a) : IsRatStieltjesPoint (fun a ↦ if p a then f a else g a) a where mono := by split_ifs with h; exacts [(hf h).mono, (hg h).mono] tendsto_atTop_one := by split_ifs with h; exacts [(hf h).tendsto_atTop_one, (hg h).tendsto_atTop_one] tendsto_atBot_zero := by split_ifs with h; exacts [(hf h).tendsto_atBot_zero, (hg h).tendsto_atBot_zero] iInf_rat_gt_eq := by split_ifs with h; exacts [(hf h).iInf_rat_gt_eq, (hg h).iInf_rat_gt_eq] variable [MeasurableSpace α] /-- A function `f : α → ℚ → ℝ` is a (kernel) rational cumulative distribution function if it is measurable in the first argument and if `f a` satisfies a list of properties for all `a : α`: monotonicity between 0 at -∞ and 1 at +∞ and a form of continuity. A function with these properties can be extended to a measurable function `α → StieltjesFunction`. See `ProbabilityTheory.IsMeasurableRatCDF.stieltjesFunction`. -/ structure IsMeasurableRatCDF (f : α → ℚ → ℝ) : Prop where isRatStieltjesPoint : ∀ a, IsRatStieltjesPoint f a measurable : Measurable f lemma IsMeasurableRatCDF.nonneg {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) : 0 ≤ f a q := Monotone.le_of_tendsto (hf.isRatStieltjesPoint a).mono (hf.isRatStieltjesPoint a).tendsto_atBot_zero q lemma IsMeasurableRatCDF.le_one {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) : f a q ≤ 1 := Monotone.ge_of_tendsto (hf.isRatStieltjesPoint a).mono (hf.isRatStieltjesPoint a).tendsto_atTop_one q lemma IsMeasurableRatCDF.tendsto_atTop_one {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) : Tendsto (f a) atTop (𝓝 1) := (hf.isRatStieltjesPoint a).tendsto_atTop_one lemma IsMeasurableRatCDF.tendsto_atBot_zero {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) : Tendsto (f a) atBot (𝓝 0) := (hf.isRatStieltjesPoint a).tendsto_atBot_zero lemma IsMeasurableRatCDF.iInf_rat_gt_eq {f : α → ℚ → ℝ} (hf : IsMeasurableRatCDF f) (a : α) (q : ℚ) : ⨅ r : Ioi q, f a r = f a q := (hf.isRatStieltjesPoint a).iInf_rat_gt_eq q end IsMeasurableRatCDF section DefaultRatCDF /-- A function with the property `IsMeasurableRatCDF`. Used in a piecewise construction to convert a function which only satisfies the properties defining `IsMeasurableRatCDF` on some set into a true `IsMeasurableRatCDF`. -/ def defaultRatCDF (q : ℚ) := if q < 0 then (0 : ℝ) else 1 lemma monotone_defaultRatCDF : Monotone defaultRatCDF := by unfold defaultRatCDF intro x y hxy dsimp only split_ifs with h_1 h_2 h_2 exacts [le_rfl, zero_le_one, absurd (hxy.trans_lt h_2) h_1, le_rfl] lemma defaultRatCDF_nonneg (q : ℚ) : 0 ≤ defaultRatCDF q := by unfold defaultRatCDF split_ifs exacts [le_rfl, zero_le_one] lemma defaultRatCDF_le_one (q : ℚ) : defaultRatCDF q ≤ 1 := by unfold defaultRatCDF split_ifs <;> simp lemma tendsto_defaultRatCDF_atTop : Tendsto defaultRatCDF atTop (𝓝 1) := by refine (tendsto_congr' ?_).mp tendsto_const_nhds rw [EventuallyEq, eventually_atTop] exact ⟨0, fun q hq => (if_neg (not_lt.mpr hq)).symm⟩ lemma tendsto_defaultRatCDF_atBot : Tendsto defaultRatCDF atBot (𝓝 0) := by refine (tendsto_congr' ?_).mp tendsto_const_nhds rw [EventuallyEq, eventually_atBot] refine ⟨-1, fun q hq => (if_pos (hq.trans_lt ?_)).symm⟩ linarith lemma iInf_rat_gt_defaultRatCDF (t : ℚ) : ⨅ r : Ioi t, defaultRatCDF r = defaultRatCDF t := by simp only [defaultRatCDF] have h_bdd : BddBelow (range fun r : ↥(Ioi t) ↦ ite ((r : ℚ) < 0) (0 : ℝ) 1) := by refine ⟨0, fun x hx ↦ ?_⟩ obtain ⟨y, rfl⟩ := mem_range.mpr hx dsimp only split_ifs exacts [le_rfl, zero_le_one] split_ifs with h · refine le_antisymm ?_ (le_ciInf fun x ↦ ?_) · obtain ⟨q, htq, hq_neg⟩ : ∃ q, t < q ∧ q < 0 := ⟨t / 2, by linarith, by linarith⟩ refine (ciInf_le h_bdd ⟨q, htq⟩).trans ?_ rw [if_pos] rwa [Subtype.coe_mk] · split_ifs exacts [le_rfl, zero_le_one] · refine le_antisymm ?_ ?_ · refine (ciInf_le h_bdd ⟨t + 1, lt_add_one t⟩).trans ?_ split_ifs exacts [zero_le_one, le_rfl] · refine le_ciInf fun x ↦ ?_ rw [if_neg] rw [not_lt] at h ⊢ exact h.trans (mem_Ioi.mp x.prop).le lemma isRatStieltjesPoint_defaultRatCDF (a : α) : IsRatStieltjesPoint (fun (_ : α) ↦ defaultRatCDF) a where mono := monotone_defaultRatCDF tendsto_atTop_one := tendsto_defaultRatCDF_atTop tendsto_atBot_zero := tendsto_defaultRatCDF_atBot iInf_rat_gt_eq := iInf_rat_gt_defaultRatCDF lemma IsMeasurableRatCDF_defaultRatCDF (α : Type*) [MeasurableSpace α] : IsMeasurableRatCDF (fun (_ : α) (q : ℚ) ↦ defaultRatCDF q) where isRatStieltjesPoint := isRatStieltjesPoint_defaultRatCDF measurable := measurable_const end DefaultRatCDF section ToRatCDF variable {f : α → ℚ → ℝ} open scoped Classical in /-- Turn a function `f : α → ℚ → ℝ` into another with the property `IsRatStieltjesPoint f a` everywhere. At `a` that does not satisfy that property, `f a` is replaced by an arbitrary suitable function. Mainly useful when `f` satisfies the property `IsRatStieltjesPoint f a` almost everywhere with respect to some measure. -/ noncomputable def toRatCDF (f : α → ℚ → ℝ) : α → ℚ → ℝ := fun a ↦ if IsRatStieltjesPoint f a then f a else defaultRatCDF lemma toRatCDF_of_isRatStieltjesPoint {a : α} (h : IsRatStieltjesPoint f a) (q : ℚ) : toRatCDF f a q = f a q := by rw [toRatCDF, if_pos h] lemma toRatCDF_unit_prod (a : α) : toRatCDF (fun (p : Unit × α) ↦ f p.2) ((), a) = toRatCDF f a := by unfold toRatCDF rw [isRatStieltjesPoint_unit_prod_iff] variable [MeasurableSpace α] lemma measurable_toRatCDF (hf : Measurable f) : Measurable (toRatCDF f) := Measurable.ite (measurableSet_isRatStieltjesPoint hf) hf measurable_const lemma isMeasurableRatCDF_toRatCDF (hf : Measurable f) : IsMeasurableRatCDF (toRatCDF f) where isRatStieltjesPoint a := by classical exact IsRatStieltjesPoint.ite (IsRatStieltjesPoint f) id (fun _ ↦ isRatStieltjesPoint_defaultRatCDF a) measurable := measurable_toRatCDF hf end ToRatCDF section IsMeasurableRatCDF.stieltjesFunction /-- Auxiliary definition for `IsMeasurableRatCDF.stieltjesFunction`: turn `f : α → ℚ → ℝ` into a function `α → ℝ → ℝ` by assigning to `f a x` the infimum of `f a q` over `q : ℚ` with `x < q`. -/ noncomputable irreducible_def IsMeasurableRatCDF.stieltjesFunctionAux (f : α → ℚ → ℝ) : α → ℝ → ℝ := fun a x ↦ ⨅ q : { q' : ℚ // x < q' }, f a q lemma IsMeasurableRatCDF.stieltjesFunctionAux_def' (f : α → ℚ → ℝ) (a : α) : IsMeasurableRatCDF.stieltjesFunctionAux f a = fun (t : ℝ) ↦ ⨅ r : { r' : ℚ // t < r' }, f a r := by ext t; exact IsMeasurableRatCDF.stieltjesFunctionAux_def f a t lemma IsMeasurableRatCDF.stieltjesFunctionAux_unit_prod {f : α → ℚ → ℝ} (a : α) : IsMeasurableRatCDF.stieltjesFunctionAux (fun (p : Unit × α) ↦ f p.2) ((), a) = IsMeasurableRatCDF.stieltjesFunctionAux f a := by simp_rw [IsMeasurableRatCDF.stieltjesFunctionAux_def'] variable {f : α → ℚ → ℝ} [MeasurableSpace α] (hf : IsMeasurableRatCDF f) include hf lemma IsMeasurableRatCDF.stieltjesFunctionAux_eq (a : α) (r : ℚ) : IsMeasurableRatCDF.stieltjesFunctionAux f a r = f a r := by rw [← hf.iInf_rat_gt_eq a r, IsMeasurableRatCDF.stieltjesFunctionAux] refine Equiv.iInf_congr ?_ ?_ · exact { toFun := fun t ↦ ⟨t.1, mod_cast t.2⟩ invFun := fun t ↦ ⟨t.1, mod_cast t.2⟩ left_inv := fun t ↦ by simp only [Subtype.coe_eta] right_inv := fun t ↦ by simp only [Subtype.coe_eta] } · intro t simp only [Equiv.coe_fn_mk, Subtype.coe_mk] lemma IsMeasurableRatCDF.stieltjesFunctionAux_nonneg (a : α) (r : ℝ) : 0 ≤ IsMeasurableRatCDF.stieltjesFunctionAux f a r := by have : Nonempty { r' : ℚ // r < ↑r' } := by obtain ⟨r, hrx⟩ := exists_rat_gt r exact ⟨⟨r, hrx⟩⟩ rw [IsMeasurableRatCDF.stieltjesFunctionAux_def] exact le_ciInf fun r' ↦ hf.nonneg a _ lemma IsMeasurableRatCDF.monotone_stieltjesFunctionAux (a : α) : Monotone (IsMeasurableRatCDF.stieltjesFunctionAux f a) := by intro x y hxy have : Nonempty { r' : ℚ // y < ↑r' } := by obtain ⟨r, hrx⟩ := exists_rat_gt y exact ⟨⟨r, hrx⟩⟩ simp_rw [IsMeasurableRatCDF.stieltjesFunctionAux_def] refine le_ciInf fun r ↦ (ciInf_le ?_ ?_).trans_eq ?_ · refine ⟨0, fun z ↦ ?_⟩; rintro ⟨u, rfl⟩; exact hf.nonneg a _ · exact ⟨r.1, hxy.trans_lt r.prop⟩ · rfl lemma IsMeasurableRatCDF.continuousWithinAt_stieltjesFunctionAux_Ici (a : α) (x : ℝ) : ContinuousWithinAt (IsMeasurableRatCDF.stieltjesFunctionAux f a) (Ici x) x := by rw [← continuousWithinAt_Ioi_iff_Ici] convert Monotone.tendsto_nhdsGT (monotone_stieltjesFunctionAux hf a) x rw [sInf_image'] have h' : ⨅ r : Ioi x, stieltjesFunctionAux f a r = ⨅ r : { r' : ℚ // x < r' }, stieltjesFunctionAux f a r := by refine Real.iInf_Ioi_eq_iInf_rat_gt x ?_ (monotone_stieltjesFunctionAux hf a) refine ⟨0, fun z ↦ ?_⟩ rintro ⟨u, -, rfl⟩ exact stieltjesFunctionAux_nonneg hf a u have h'' : ⨅ r : { r' : ℚ // x < r' }, stieltjesFunctionAux f a r = ⨅ r : { r' : ℚ // x < r' }, f a r := by congr with r exact stieltjesFunctionAux_eq hf a r rw [h', h'', ContinuousWithinAt] congr! rw [stieltjesFunctionAux_def] /-- Extend a function `f : α → ℚ → ℝ` with property `IsMeasurableRatCDF` from `ℚ` to `ℝ`, to a function `α → StieltjesFunction`. -/ noncomputable def IsMeasurableRatCDF.stieltjesFunction (a : α) : StieltjesFunction where toFun := stieltjesFunctionAux f a mono' := monotone_stieltjesFunctionAux hf a right_continuous' x := continuousWithinAt_stieltjesFunctionAux_Ici hf a x lemma IsMeasurableRatCDF.stieltjesFunction_eq (a : α) (r : ℚ) : hf.stieltjesFunction a r = f a r := stieltjesFunctionAux_eq hf a r lemma IsMeasurableRatCDF.stieltjesFunction_nonneg (a : α) (r : ℝ) : 0 ≤ hf.stieltjesFunction a r := stieltjesFunctionAux_nonneg hf a r lemma IsMeasurableRatCDF.stieltjesFunction_le_one (a : α) (x : ℝ) : hf.stieltjesFunction a x ≤ 1 := by obtain ⟨r, hrx⟩ := exists_rat_gt x rw [← StieltjesFunction.iInf_rat_gt_eq] simp_rw [IsMeasurableRatCDF.stieltjesFunction_eq] refine ciInf_le_of_le ?_ ?_ (hf.le_one _ _) · refine ⟨0, fun z ↦ ?_⟩; rintro ⟨u, rfl⟩; exact hf.nonneg a _ · exact ⟨r, hrx⟩ lemma IsMeasurableRatCDF.tendsto_stieltjesFunction_atBot (a : α) : Tendsto (hf.stieltjesFunction a) atBot (𝓝 0) := by have h_exists : ∀ x : ℝ, ∃ q : ℚ, x < q ∧ ↑q < x + 1 := fun x ↦ exists_rat_btwn (lt_add_one x) let qs : ℝ → ℚ := fun x ↦ (h_exists x).choose have hqs_tendsto : Tendsto qs atBot atBot := by rw [tendsto_atBot_atBot] refine fun q ↦ ⟨q - 1, fun y hy ↦ ?_⟩ have h_le : ↑(qs y) ≤ (q : ℝ) - 1 + 1 := (h_exists y).choose_spec.2.le.trans (add_le_add hy le_rfl) rw [sub_add_cancel] at h_le exact mod_cast h_le refine tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds ((hf.tendsto_atBot_zero a).comp hqs_tendsto) (stieltjesFunction_nonneg hf a) fun x ↦ ?_ rw [Function.comp_apply, ← stieltjesFunction_eq hf] exact (hf.stieltjesFunction a).mono (h_exists x).choose_spec.1.le lemma IsMeasurableRatCDF.tendsto_stieltjesFunction_atTop (a : α) : Tendsto (hf.stieltjesFunction a) atTop (𝓝 1) := by have h_exists : ∀ x : ℝ, ∃ q : ℚ, x - 1 < q ∧ ↑q < x := fun x ↦ exists_rat_btwn (sub_one_lt x) let qs : ℝ → ℚ := fun x ↦ (h_exists x).choose have hqs_tendsto : Tendsto qs atTop atTop := by rw [tendsto_atTop_atTop] refine fun q ↦ ⟨q + 1, fun y hy ↦ ?_⟩ have h_le : y - 1 ≤ qs y := (h_exists y).choose_spec.1.le rw [sub_le_iff_le_add] at h_le exact_mod_cast le_of_add_le_add_right (hy.trans h_le) refine tendsto_of_tendsto_of_tendsto_of_le_of_le ((hf.tendsto_atTop_one a).comp hqs_tendsto) tendsto_const_nhds ?_ (stieltjesFunction_le_one hf a) intro x rw [Function.comp_apply, ← stieltjesFunction_eq hf] exact (hf.stieltjesFunction a).mono (le_of_lt (h_exists x).choose_spec.2) lemma IsMeasurableRatCDF.measurable_stieltjesFunction (x : ℝ) : Measurable fun a ↦ hf.stieltjesFunction a x := by have : (fun a ↦ hf.stieltjesFunction a x) = fun a ↦ ⨅ r : { r' : ℚ // x < r' }, f a ↑r := by ext1 a rw [← StieltjesFunction.iInf_rat_gt_eq] congr with q rw [stieltjesFunction_eq] rw [this] exact .iInf (fun q ↦ hf.measurable.eval) lemma IsMeasurableRatCDF.stronglyMeasurable_stieltjesFunction (x : ℝ) : StronglyMeasurable fun a ↦ hf.stieltjesFunction a x := (measurable_stieltjesFunction hf x).stronglyMeasurable section Measure lemma IsMeasurableRatCDF.measure_stieltjesFunction_Iic (a : α) (x : ℝ) : (hf.stieltjesFunction a).measure (Iic x) = ENNReal.ofReal (hf.stieltjesFunction a x) := by rw [← sub_zero (hf.stieltjesFunction a x)] exact (hf.stieltjesFunction a).measure_Iic (tendsto_stieltjesFunction_atBot hf a) _ lemma IsMeasurableRatCDF.measure_stieltjesFunction_univ (a : α) : (hf.stieltjesFunction a).measure univ = 1 := by rw [← ENNReal.ofReal_one, ← sub_zero (1 : ℝ)] exact StieltjesFunction.measure_univ _ (tendsto_stieltjesFunction_atBot hf a) (tendsto_stieltjesFunction_atTop hf a) instance IsMeasurableRatCDF.instIsProbabilityMeasure_stieltjesFunction (a : α) : IsProbabilityMeasure (hf.stieltjesFunction a).measure := ⟨measure_stieltjesFunction_univ hf a⟩ lemma IsMeasurableRatCDF.measurable_measure_stieltjesFunction : Measurable fun a ↦ (hf.stieltjesFunction a).measure := by apply_rules [StieltjesFunction.measurable_measure, measurable_stieltjesFunction, tendsto_stieltjesFunction_atBot, tendsto_stieltjesFunction_atTop] end Measure end IsMeasurableRatCDF.stieltjesFunction section stieltjesOfMeasurableRat variable {f : α → ℚ → ℝ} [MeasurableSpace α] /-- Turn a measurable function `f : α → ℚ → ℝ` into a measurable function `α → StieltjesFunction`. Composition of `toRatCDF` and `IsMeasurableRatCDF.stieltjesFunction`. -/ noncomputable def stieltjesOfMeasurableRat (f : α → ℚ → ℝ) (hf : Measurable f) : α → StieltjesFunction := (isMeasurableRatCDF_toRatCDF hf).stieltjesFunction lemma stieltjesOfMeasurableRat_eq (hf : Measurable f) (a : α) (r : ℚ) : stieltjesOfMeasurableRat f hf a r = toRatCDF f a r := IsMeasurableRatCDF.stieltjesFunction_eq _ a r lemma stieltjesOfMeasurableRat_unit_prod (hf : Measurable f) (a : α) : stieltjesOfMeasurableRat (fun (p : Unit × α) ↦ f p.2) (hf.comp measurable_snd) ((), a)
= stieltjesOfMeasurableRat f hf a := by simp_rw [stieltjesOfMeasurableRat,IsMeasurableRatCDF.stieltjesFunction, ← IsMeasurableRatCDF.stieltjesFunctionAux_unit_prod a] congr with x congr 1 with p : 1 cases p with | mk _ b => rw [← toRatCDF_unit_prod b] lemma stieltjesOfMeasurableRat_nonneg (hf : Measurable f) (a : α) (r : ℝ) :
Mathlib/Probability/Kernel/Disintegration/MeasurableStieltjes.lean
451
459
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Kim Morrison, Mario Carneiro, Andrew Yang -/ import Mathlib.Topology.Category.TopCat.Limits.Products /-! # Pullbacks and pushouts in the category of topological spaces -/ open TopologicalSpace Topology open CategoryTheory open CategoryTheory.Limits universe v u w noncomputable section namespace TopCat variable {J : Type v} [Category.{w} J] section Pullback variable {X Y Z : TopCat.{u}} /-- The first projection from the pullback. -/ abbrev pullbackFst (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ X := ofHom ⟨Prod.fst ∘ Subtype.val, by fun_prop⟩ lemma pullbackFst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackFst f g x = x.1.1 := rfl /-- The second projection from the pullback. -/ abbrev pullbackSnd (f : X ⟶ Z) (g : Y ⟶ Z) : TopCat.of { p : X × Y // f p.1 = g p.2 } ⟶ Y := ofHom ⟨Prod.snd ∘ Subtype.val, by fun_prop⟩ lemma pullbackSnd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x) : pullbackSnd f g x = x.1.2 := rfl /-- The explicit pullback cone of `X, Y` given by `{ p : X × Y // f p.1 = g p.2 }`. -/ def pullbackCone (f : X ⟶ Z) (g : Y ⟶ Z) : PullbackCone f g := PullbackCone.mk (pullbackFst f g) (pullbackSnd f g) (by dsimp [pullbackFst, pullbackSnd, Function.comp_def] ext ⟨x, h⟩ simpa) /-- The constructed cone is a limit. -/ def pullbackConeIsLimit (f : X ⟶ Z) (g : Y ⟶ Z) : IsLimit (pullbackCone f g) := PullbackCone.isLimitAux' _ (by intro S constructor; swap · exact ofHom { toFun := fun x => ⟨⟨S.fst x, S.snd x⟩, by simpa using ConcreteCategory.congr_hom S.condition x⟩ continuous_toFun := by fun_prop } refine ⟨?_, ?_, ?_⟩ · delta pullbackCone ext a dsimp · delta pullbackCone ext a dsimp · intro m h₁ h₂ ext x -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): used to be `ext x`. apply Subtype.ext apply Prod.ext · simpa using ConcreteCategory.congr_hom h₁ x · simpa using ConcreteCategory.congr_hom h₂ x) /-- The pullback of two maps can be identified as a subspace of `X × Y`. -/ def pullbackIsoProdSubtype (f : X ⟶ Z) (g : Y ⟶ Z) : pullback f g ≅ TopCat.of { p : X × Y // f p.1 = g p.2 } := (limit.isLimit _).conePointUniqueUpToIso (pullbackConeIsLimit f g) @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.fst _ _ = pullbackFst f g := by simp [pullbackCone, pullbackIsoProdSubtype] theorem pullbackIsoProdSubtype_inv_fst_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : pullback.fst f g ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).fst := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_fst f g) x @[reassoc (attr := simp)] theorem pullbackIsoProdSubtype_inv_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).inv ≫ pullback.snd _ _ = pullbackSnd f g := by simp [pullbackCone, pullbackIsoProdSubtype] theorem pullbackIsoProdSubtype_inv_snd_apply (f : X ⟶ Z) (g : Y ⟶ Z) (x : { p : X × Y // f p.1 = g p.2 }) : pullback.snd f g ((pullbackIsoProdSubtype f g).inv x) = (x : X × Y).snd := ConcreteCategory.congr_hom (pullbackIsoProdSubtype_inv_snd f g) x theorem pullbackIsoProdSubtype_hom_fst (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackFst f g = pullback.fst _ _ := by rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_fst] theorem pullbackIsoProdSubtype_hom_snd (f : X ⟶ Z) (g : Y ⟶ Z) : (pullbackIsoProdSubtype f g).hom ≫ pullbackSnd f g = pullback.snd _ _ := by rw [← Iso.eq_inv_comp, pullbackIsoProdSubtype_inv_snd] theorem pullbackIsoProdSubtype_hom_apply {f : X ⟶ Z} {g : Y ⟶ Z} (x : ↑(pullback f g)) : (pullbackIsoProdSubtype f g).hom x = ⟨⟨pullback.fst f g x, pullback.snd f g x⟩, by simpa using CategoryTheory.congr_fun pullback.condition x⟩ := by apply Subtype.ext; apply Prod.ext exacts [ConcreteCategory.congr_hom (pullbackIsoProdSubtype_hom_fst f g) x, ConcreteCategory.congr_hom (pullbackIsoProdSubtype_hom_snd f g) x] theorem pullback_topology {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : (pullback f g).str = induced (pullback.fst f g) X.str ⊓ induced (pullback.snd f g) Y.str := by let homeo := homeoOfIso (pullbackIsoProdSubtype f g) refine homeo.isInducing.eq_induced.trans ?_ change induced homeo (induced _ ( (induced Prod.fst X.str) ⊓ (induced Prod.snd Y.str))) = _ simp only [induced_compose, induced_inf] congr theorem range_pullback_to_prod {X Y Z : TopCat} (f : X ⟶ Z) (g : Y ⟶ Z) : Set.range (prod.lift (pullback.fst f g) (pullback.snd f g)) = { x | (Limits.prod.fst ≫ f) x = (Limits.prod.snd ≫ g) x } := by ext x constructor · rintro ⟨y, rfl⟩ simp only [← ConcreteCategory.comp_apply, Set.mem_setOf_eq] simp [pullback.condition] · rintro (h : f (_, _).1 = g (_, _).2) use (pullbackIsoProdSubtype f g).inv ⟨⟨_, _⟩, h⟩ apply Concrete.limit_ext rintro ⟨⟨⟩⟩ <;> rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply, limit.lift_π] <;> -- This used to be `simp` before https://github.com/leanprover/lean4/pull/2644 aesop_cat /-- The pullback along an embedding is (isomorphic to) the preimage. -/ noncomputable def pullbackHomeoPreimage {X Y Z : Type*} [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] (f : X → Z) (hf : Continuous f) (g : Y → Z) (hg : IsEmbedding g) : { p : X × Y // f p.1 = g p.2 } ≃ₜ f ⁻¹' Set.range g where toFun := fun x ↦ ⟨x.1.1, _, x.2.symm⟩ invFun := fun x ↦ ⟨⟨x.1, Exists.choose x.2⟩, (Exists.choose_spec x.2).symm⟩ left_inv := by intro x ext <;> dsimp apply hg.injective convert x.prop exact Exists.choose_spec (p := fun y ↦ g y = f (↑x : X × Y).1) _ right_inv := fun _ ↦ rfl continuous_toFun := by fun_prop continuous_invFun := by apply Continuous.subtype_mk refine continuous_subtype_val.prodMk <| hg.isInducing.continuous_iff.mpr ?_ convert hf.comp continuous_subtype_val ext x exact Exists.choose_spec x.2 theorem isInducing_pullback_to_prod {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : IsInducing <| ⇑(prod.lift (pullback.fst f g) (pullback.snd f g)) := ⟨by simp [prod_topology, pullback_topology, induced_compose, ← coe_comp]⟩ @[deprecated (since := "2024-10-28")] alias inducing_pullback_to_prod := isInducing_pullback_to_prod theorem isEmbedding_pullback_to_prod {X Y Z : TopCat.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) : IsEmbedding <| ⇑(prod.lift (pullback.fst f g) (pullback.snd f g)) := ⟨isInducing_pullback_to_prod f g, (TopCat.mono_iff_injective _).mp inferInstance⟩ @[deprecated (since := "2024-10-26")] alias embedding_pullback_to_prod := isEmbedding_pullback_to_prod /-- If the map `S ⟶ T` is mono, then there is a description of the image of `W ×ₛ X ⟶ Y ×ₜ Z`. -/ theorem range_pullback_map {W X Y Z S T : TopCat} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) [H₃ : Mono i₃] (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : Set.range (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) = (pullback.fst g₁ g₂) ⁻¹' Set.range i₁ ∩ (pullback.snd g₁ g₂) ⁻¹' Set.range i₂ := by ext constructor · rintro ⟨y, rfl⟩ simp only [Set.mem_inter_iff, Set.mem_preimage, Set.mem_range] rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] simp only [limit.lift_π, PullbackCone.mk_pt, PullbackCone.mk_π_app] exact ⟨exists_apply_eq_apply _ _, exists_apply_eq_apply _ _⟩ rintro ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩⟩ have : f₁ x₁ = f₂ x₂ := by apply (TopCat.mono_iff_injective _).mp H₃ rw [← ConcreteCategory.comp_apply, eq₁, ← ConcreteCategory.comp_apply, eq₂, ConcreteCategory.comp_apply, ConcreteCategory.comp_apply, hx₁, hx₂, ← ConcreteCategory.comp_apply, pullback.condition, ConcreteCategory.comp_apply] use (pullbackIsoProdSubtype f₁ f₂).inv ⟨⟨x₁, x₂⟩, this⟩ apply Concrete.limit_ext rintro (_ | _ | _) <;> rw [← ConcreteCategory.comp_apply, ← ConcreteCategory.comp_apply] · simp [hx₁, ← limit.w _ WalkingCospan.Hom.inl] · simp [hx₁] · simp [hx₂] theorem pullback_fst_range {X Y S : TopCat} (f : X ⟶ S) (g : Y ⟶ S) : Set.range (pullback.fst f g) = { x : X | ∃ y : Y, f x = g y } := by ext x constructor · rintro ⟨y, rfl⟩ use pullback.snd f g y exact CategoryTheory.congr_fun pullback.condition y · rintro ⟨y, eq⟩ use (TopCat.pullbackIsoProdSubtype f g).inv ⟨⟨x, y⟩, eq⟩ rw [pullbackIsoProdSubtype_inv_fst_apply] theorem pullback_snd_range {X Y S : TopCat} (f : X ⟶ S) (g : Y ⟶ S) : Set.range (pullback.snd f g) = { y : Y | ∃ x : X, f x = g y } := by ext y constructor · rintro ⟨x, rfl⟩ use pullback.fst f g x exact CategoryTheory.congr_fun pullback.condition x · rintro ⟨x, eq⟩ use (TopCat.pullbackIsoProdSubtype f g).inv ⟨⟨x, y⟩, eq⟩ rw [pullbackIsoProdSubtype_inv_snd_apply] /-- If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are embeddings, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an embedding. ``` W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z ``` -/ theorem pullback_map_isEmbedding {W X Y Z S T : TopCat.{u}} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z} (H₁ : IsEmbedding i₁) (H₂ : IsEmbedding i₂) (i₃ : S ⟶ T) (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : IsEmbedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by refine .of_comp (ContinuousMap.continuous_toFun _) (show Continuous (prod.lift (pullback.fst g₁ g₂) (pullback.snd g₁ g₂)) from ContinuousMap.continuous_toFun _) ?_ suffices IsEmbedding (prod.lift (pullback.fst f₁ f₂) (pullback.snd f₁ f₂) ≫ Limits.prod.map i₁ i₂) by simpa [← coe_comp] using this rw [coe_comp] exact (isEmbedding_prodMap H₁ H₂).comp (isEmbedding_pullback_to_prod _ _) @[deprecated (since := "2024-10-26")] alias pullback_map_embedding_of_embeddings := pullback_map_isEmbedding /-- If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are open embeddings, and `S ⟶ T` is mono, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an open embedding. ``` W ⟶ Y ↘ ↘ S ⟶ T ↗ ↗ X ⟶ Z ``` -/ theorem pullback_map_isOpenEmbedding {W X Y Z S T : TopCat.{u}} (f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z} (H₁ : IsOpenEmbedding i₁) (H₂ : IsOpenEmbedding i₂) (i₃ : S ⟶ T) [H₃ : Mono i₃] (eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) : IsOpenEmbedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) := by constructor · apply pullback_map_isEmbedding f₁ f₂ g₁ g₂ H₁.isEmbedding H₂.isEmbedding i₃ eq₁ eq₂ · rw [range_pullback_map] apply IsOpen.inter <;> apply Continuous.isOpen_preimage · apply ContinuousMap.continuous_toFun · exact H₁.isOpen_range · apply ContinuousMap.continuous_toFun · exact H₂.isOpen_range lemma snd_isEmbedding_of_left {X Y S : TopCat} {f : X ⟶ S} (H : IsEmbedding f) (g : Y ⟶ S) : IsEmbedding <| ⇑(pullback.snd f g) := by convert (homeoOfIso (asIso (pullback.snd (𝟙 S) g))).isEmbedding.comp (pullback_map_isEmbedding (i₂ := 𝟙 Y) f g (𝟙 S) g H (homeoOfIso (Iso.refl _)).isEmbedding (𝟙 _) rfl (by simp)) simp [homeoOfIso, ← coe_comp] @[deprecated (since := "2024-10-26")] alias snd_embedding_of_left_embedding := snd_isEmbedding_of_left theorem fst_isEmbedding_of_right {X Y S : TopCat} (f : X ⟶ S) {g : Y ⟶ S} (H : IsEmbedding g) : IsEmbedding <| ⇑(pullback.fst f g) := by convert (homeoOfIso (asIso (pullback.fst f (𝟙 S)))).isEmbedding.comp (pullback_map_isEmbedding (i₁ := 𝟙 X) f g f (𝟙 _) (homeoOfIso (Iso.refl _)).isEmbedding H (𝟙 _) rfl (by simp)) simp [homeoOfIso, ← coe_comp] @[deprecated (since := "2024-10-26")] alias fst_embedding_of_right_embedding := fst_isEmbedding_of_right theorem isEmbedding_of_pullback {X Y S : TopCat} {f : X ⟶ S} {g : Y ⟶ S} (H₁ : IsEmbedding f) (H₂ : IsEmbedding g) : IsEmbedding (limit.π (cospan f g) WalkingCospan.one) := by convert H₂.comp (snd_isEmbedding_of_left H₁ g) rw [← coe_comp, ← limit.w _ WalkingCospan.Hom.inr] rfl @[deprecated (since := "2024-10-26")] alias embedding_of_pullback_embeddings := isEmbedding_of_pullback theorem snd_isOpenEmbedding_of_left {X Y S : TopCat} {f : X ⟶ S} (H : IsOpenEmbedding f) (g : Y ⟶ S) : IsOpenEmbedding <| ⇑(pullback.snd f g) := by convert (homeoOfIso (asIso (pullback.snd (𝟙 S) g))).isOpenEmbedding.comp (pullback_map_isOpenEmbedding (i₂ := 𝟙 Y) f g (𝟙 _) g H (homeoOfIso (Iso.refl _)).isOpenEmbedding (𝟙 _) rfl (by simp)) simp [homeoOfIso, ← coe_comp] theorem fst_isOpenEmbedding_of_right {X Y S : TopCat} (f : X ⟶ S) {g : Y ⟶ S} (H : IsOpenEmbedding g) : IsOpenEmbedding <| ⇑(pullback.fst f g) := by convert (homeoOfIso (asIso (pullback.fst f (𝟙 S)))).isOpenEmbedding.comp (pullback_map_isOpenEmbedding (i₁ := 𝟙 X) f g f (𝟙 _) (homeoOfIso (Iso.refl _)).isOpenEmbedding H (𝟙 _) rfl (by simp)) simp [homeoOfIso, ← coe_comp] /-- If `X ⟶ S`, `Y ⟶ S` are open embeddings, then so is `X ×ₛ Y ⟶ S`. -/ theorem isOpenEmbedding_of_pullback {X Y S : TopCat} {f : X ⟶ S} {g : Y ⟶ S} (H₁ : IsOpenEmbedding f) (H₂ : IsOpenEmbedding g) : IsOpenEmbedding (limit.π (cospan f g) WalkingCospan.one) := by convert H₂.comp (snd_isOpenEmbedding_of_left H₁ g) rw [← coe_comp, ← limit.w _ WalkingCospan.Hom.inr]
rfl @[deprecated (since := "2024-10-30")] alias isOpenEmbedding_of_pullback_open_embeddings := isOpenEmbedding_of_pullback theorem fst_iso_of_right_embedding_range_subset {X Y S : TopCat} (f : X ⟶ S) {g : Y ⟶ S} (hg : IsEmbedding g) (H : Set.range f ⊆ Set.range g) :
Mathlib/Topology/Category/TopCat/Limits/Pullbacks.lean
331
337
/- 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.Side import Mathlib.Geometry.Euclidean.Angle.Oriented.Rotation import Mathlib.Geometry.Euclidean.Angle.Unoriented.Affine /-! # Oriented angles. This file defines oriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.oangle`, with notation `∡`, is the oriented angle determined by three points. -/ noncomputable section open Module Complex open scoped Affine EuclideanGeometry Real RealInnerProductSpace ComplexConjugate namespace EuclideanGeometry variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] [hd2 : Fact (finrank ℝ V = 2)] [Module.Oriented ℝ V (Fin 2)] /-- A fixed choice of positive orientation of Euclidean space `ℝ²` -/ abbrev o := @Module.Oriented.positiveOrientation /-- The oriented angle at `p₂` between the line segments to `p₁` and `p₃`, modulo `2 * π`. If either of those points equals `p₂`, this is 0. See `EuclideanGeometry.angle` for the corresponding unoriented angle definition. -/ def oangle (p₁ p₂ p₃ : P) : Real.Angle := o.oangle (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) @[inherit_doc] scoped notation "∡" => EuclideanGeometry.oangle /-- Oriented angles are continuous when neither end point equals the middle point. -/ theorem continuousAt_oangle {x : P × P × P} (hx12 : x.1 ≠ x.2.1) (hx32 : x.2.2 ≠ x.2.1) : ContinuousAt (fun y : P × P × P => ∡ y.1 y.2.1 y.2.2) x := by unfold oangle fun_prop (disch := simp [*]) /-- The angle ∡AAB at a point. -/ @[simp] theorem oangle_self_left (p₁ p₂ : P) : ∡ p₁ p₁ p₂ = 0 := by simp [oangle] /-- The angle ∡ABB at a point. -/ @[simp] theorem oangle_self_right (p₁ p₂ : P) : ∡ p₁ p₂ p₂ = 0 := by simp [oangle] /-- The angle ∡ABA at a point. -/ @[simp] theorem oangle_self_left_right (p₁ p₂ : P) : ∡ p₁ p₂ p₁ = 0 := o.oangle_self _ /-- If the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.left_ne_zero_of_oangle_ne_zero h /-- If the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₃ ≠ p₂ := by rw [← @vsub_ne_zero V]; exact o.right_ne_zero_of_oangle_ne_zero h /-- If the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_ne_zero {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ ≠ 0) : p₁ ≠ p₃ := by rw [← (vsub_left_injective p₂).ne_iff]; exact o.ne_of_oangle_ne_zero h /-- If the angle between three points is `π`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = π) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the first two points are not equal. -/ theorem left_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the last two points are not equal. -/ theorem right_ne_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the angle between three points is `-π / 2`, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = (-π / 2 : ℝ)) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (h.symm ▸ Real.Angle.neg_pi_div_two_ne_zero : ∡ p₁ p₂ p₃ ≠ 0) /-- If the sign of the angle between three points is nonzero, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₂ := left_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is nonzero, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₃ ≠ p₂ := right_ne_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is nonzero, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_ne_zero {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign ≠ 0) : p₁ ≠ p₃ := left_ne_right_of_oangle_ne_zero (Real.Angle.sign_ne_zero_iff.1 h).1 /-- If the sign of the angle between three points is positive, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is positive, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is positive, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the first two points are not equal. -/ theorem left_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₂ := left_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the last two points are not equal. -/ theorem right_ne_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₃ ≠ p₂ := right_ne_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- If the sign of the angle between three points is negative, the first and third points are not equal. -/ theorem left_ne_right_of_oangle_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : p₁ ≠ p₃ := left_ne_right_of_oangle_sign_ne_zero (h.symm ▸ by decide : (∡ p₁ p₂ p₃).sign ≠ 0) /-- Reversing the order of the points passed to `oangle` negates the angle. -/ theorem oangle_rev (p₁ p₂ p₃ : P) : ∡ p₃ p₂ p₁ = -∡ p₁ p₂ p₃ := o.oangle_rev _ _ /-- Adding an angle to that with the order of the points reversed results in 0. -/ @[simp] theorem oangle_add_oangle_rev (p₁ p₂ p₃ : P) : ∡ p₁ p₂ p₃ + ∡ p₃ p₂ p₁ = 0 := o.oangle_add_oangle_rev _ _ /-- An oriented angle is zero if and only if the angle with the order of the points reversed is zero. -/ theorem oangle_eq_zero_iff_oangle_rev_eq_zero {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ ∡ p₃ p₂ p₁ = 0 := o.oangle_eq_zero_iff_oangle_rev_eq_zero /-- An oriented angle is `π` if and only if the angle with the order of the points reversed is `π`. -/ theorem oangle_eq_pi_iff_oangle_rev_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∡ p₃ p₂ p₁ = π := o.oangle_eq_pi_iff_oangle_rev_eq_pi /-- An oriented angle is not zero or `π` if and only if the three points are affinely independent. -/ theorem oangle_ne_zero_and_ne_pi_iff_affineIndependent {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ ≠ 0 ∧ ∡ p₁ p₂ p₃ ≠ π ↔ AffineIndependent ℝ ![p₁, p₂, p₃] := by rw [oangle, o.oangle_ne_zero_and_ne_pi_iff_linearIndependent, affineIndependent_iff_linearIndependent_vsub ℝ _ (1 : Fin 3), ← linearIndependent_equiv (finSuccAboveEquiv (1 : Fin 3))] convert Iff.rfl ext i fin_cases i <;> rfl /-- An oriented angle is zero or `π` if and only if the three points are collinear. -/ theorem oangle_eq_zero_or_eq_pi_iff_collinear {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ∨ ∡ p₁ p₂ p₃ = π ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [← not_iff_not, not_or, oangle_ne_zero_and_ne_pi_iff_affineIndependent, affineIndependent_iff_not_collinear_set] /-- An oriented angle has a sign zero if and only if the three points are collinear. -/ theorem oangle_sign_eq_zero_iff_collinear {p₁ p₂ p₃ : P} : (∡ p₁ p₂ p₃).sign = 0 ↔ Collinear ℝ ({p₁, p₂, p₃} : Set P) := by rw [Real.Angle.sign_eq_zero_iff, oangle_eq_zero_or_eq_pi_iff_collinear] /-- If twice the oriented angles between two triples of points are equal, one triple is affinely independent if and only if the other is. -/ theorem affineIndependent_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : AffineIndependent ℝ ![p₁, p₂, p₃] ↔ AffineIndependent ℝ ![p₄, p₅, p₆] := by simp_rw [← oangle_ne_zero_and_ne_pi_iff_affineIndependent, ← Real.Angle.two_zsmul_ne_zero_iff, h] /-- If twice the oriented angles between two triples of points are equal, one triple is collinear if and only if the other is. -/ theorem collinear_iff_of_two_zsmul_oangle_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆) : Collinear ℝ ({p₁, p₂, p₃} : Set P) ↔ Collinear ℝ ({p₄, p₅, p₆} : Set P) := by simp_rw [← oangle_eq_zero_or_eq_pi_iff_collinear, ← Real.Angle.two_zsmul_eq_zero_iff, h] /-- If corresponding pairs of points in two angles have the same vector span, twice those angles are equal. -/ theorem two_zsmul_oangle_of_vectorSpan_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : vectorSpan ℝ ({p₁, p₂} : Set P) = vectorSpan ℝ ({p₄, p₅} : Set P)) (h₃₂₆₅ : vectorSpan ℝ ({p₃, p₂} : Set P) = vectorSpan ℝ ({p₆, p₅} : Set P)) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by simp_rw [vectorSpan_pair] at h₁₂₄₅ h₃₂₆₅ exact o.two_zsmul_oangle_of_span_eq_of_span_eq h₁₂₄₅ h₃₂₆₅ /-- If the lines determined by corresponding pairs of points in two angles are parallel, twice those angles are equal. -/ theorem two_zsmul_oangle_of_parallel {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h₁₂₄₅ : line[ℝ, p₁, p₂] ∥ line[ℝ, p₄, p₅]) (h₃₂₆₅ : line[ℝ, p₃, p₂] ∥ line[ℝ, p₆, p₅]) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₄ p₅ p₆ := by rw [AffineSubspace.affineSpan_pair_parallel_iff_vectorSpan_eq] at h₁₂₄₅ h₃₂₆₅ exact two_zsmul_oangle_of_vectorSpan_eq h₁₂₄₅ h₃₂₆₅ /-- Given three points not equal to `p`, the angle between the first and the second at `p` plus the angle between the second and the third equals the angle between the first and the third. -/ @[simp] theorem oangle_add {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ = ∡ p₁ p p₃ := o.oangle_add (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the second and the third at `p` plus the angle between the first and the second equals the angle between the first and the third. -/ @[simp] theorem oangle_add_swap {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₂ p p₃ + ∡ p₁ p p₂ = ∡ p₁ p p₃ := o.oangle_add_swap (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the first and the second equals the angle between the second and the third. -/ @[simp] theorem oangle_sub_left {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₁ p p₂ = ∡ p₂ p p₃ := o.oangle_sub_left (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, the angle between the first and the third at `p` minus the angle between the second and the third equals the angle between the first and the second. -/ @[simp] theorem oangle_sub_right {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₃ - ∡ p₂ p p₃ = ∡ p₁ p p₂ := o.oangle_sub_right (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Given three points not equal to `p`, adding the angles between them at `p` in cyclic order results in 0. -/ @[simp] theorem oangle_add_cyc3 {p p₁ p₂ p₃ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) (hp₃ : p₃ ≠ p) : ∡ p₁ p p₂ + ∡ p₂ p p₃ + ∡ p₃ p p₁ = 0 := o.oangle_add_cyc3 (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) (vsub_ne_zero.2 hp₃) /-- Pons asinorum, oriented angle-at-point form. -/ theorem oangle_eq_oangle_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₁ p₂ p₃ = ∡ p₂ p₃ p₁ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁, ← vsub_sub_vsub_cancel_left p₂ p₃ p₁, o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h] /-- The angle at the apex of an isosceles triangle is `π` minus twice a base angle, oriented angle-at-point form. -/ theorem oangle_eq_pi_sub_two_zsmul_oangle_of_dist_eq {p₁ p₂ p₃ : P} (hn : p₂ ≠ p₃) (h : dist p₁ p₂ = dist p₁ p₃) : ∡ p₃ p₁ p₂ = π - (2 : ℤ) • ∡ p₁ p₂ p₃ := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, oangle] convert o.oangle_eq_pi_sub_two_zsmul_oangle_sub_of_norm_eq _ h using 1 · rw [← neg_vsub_eq_vsub_rev p₁ p₃, ← neg_vsub_eq_vsub_rev p₁ p₂, o.oangle_neg_neg] · rw [← o.oangle_sub_eq_oangle_sub_rev_of_norm_eq h]; simp · simpa using hn /-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/ theorem abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₁ p₂ p₃).toReal| < π / 2 := by simp_rw [dist_eq_norm_vsub V] at h rw [oangle, ← vsub_sub_vsub_cancel_left p₃ p₂ p₁] exact o.abs_oangle_sub_right_toReal_lt_pi_div_two h /-- A base angle of an isosceles triangle is acute, oriented angle-at-point form. -/ theorem abs_oangle_left_toReal_lt_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₁ p₂ = dist p₁ p₃) : |(∡ p₂ p₃ p₁).toReal| < π / 2 := oangle_eq_oangle_of_dist_eq h ▸ abs_oangle_right_toReal_lt_pi_div_two_of_dist_eq h /-- The cosine of the oriented angle at `p` between two points not equal to `p` equals that of the unoriented angle. -/ theorem cos_oangle_eq_cos_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : Real.Angle.cos (∡ p₁ p p₂) = Real.cos (∠ p₁ p p₂) := o.cos_oangle_eq_cos_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The oriented angle at `p` between two points not equal to `p` is plus or minus the unoriented angle. -/ theorem oangle_eq_angle_or_eq_neg_angle {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∡ p₁ p p₂ = ∠ p₁ p p₂ ∨ ∡ p₁ p p₂ = -∠ p₁ p p₂ := o.oangle_eq_angle_or_eq_neg_angle (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The unoriented angle at `p` between two points not equal to `p` is the absolute value of the oriented angle. -/ theorem angle_eq_abs_oangle_toReal {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∠ p₁ p p₂ = |(∡ p₁ p p₂).toReal| := o.angle_eq_abs_oangle_toReal (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- If the sign of the oriented angle at `p` between two points is zero, either one of the points equals `p` or the unoriented angle is 0 or π. -/ theorem eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero {p p₁ p₂ : P} (h : (∡ p₁ p p₂).sign = 0) : p₁ = p ∨ p₂ = p ∨ ∠ p₁ p p₂ = 0 ∨ ∠ p₁ p p₂ = π := by convert o.eq_zero_or_angle_eq_zero_or_pi_of_sign_oangle_eq_zero h <;> simp /-- If two unoriented angles are equal, and the signs of the corresponding oriented angles are equal, then the oriented angles are equal (even in degenerate cases). -/ theorem oangle_eq_of_angle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (h : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ := o.oangle_eq_of_angle_eq_of_sign_eq h hs /-- If the signs of two nondegenerate oriented angles between points are equal, the oriented angles are equal if and only if the unoriented angles are equal. -/ theorem angle_eq_iff_oangle_eq_of_sign_eq {p₁ p₂ p₃ p₄ p₅ p₆ : P} (hp₁ : p₁ ≠ p₂) (hp₃ : p₃ ≠ p₂) (hp₄ : p₄ ≠ p₅) (hp₆ : p₆ ≠ p₅) (hs : (∡ p₁ p₂ p₃).sign = (∡ p₄ p₅ p₆).sign) : ∠ p₁ p₂ p₃ = ∠ p₄ p₅ p₆ ↔ ∡ p₁ p₂ p₃ = ∡ p₄ p₅ p₆ := o.angle_eq_iff_oangle_eq_of_sign_eq (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₃) (vsub_ne_zero.2 hp₄) (vsub_ne_zero.2 hp₆) hs /-- The oriented angle between three points equals the unoriented angle if the sign is positive. -/ theorem oangle_eq_angle_of_sign_eq_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = 1) : ∡ p₁ p₂ p₃ = ∠ p₁ p₂ p₃ := o.oangle_eq_angle_of_sign_eq_one h /-- The oriented angle between three points equals minus the unoriented angle if the sign is negative. -/ theorem oangle_eq_neg_angle_of_sign_eq_neg_one {p₁ p₂ p₃ : P} (h : (∡ p₁ p₂ p₃).sign = -1) : ∡ p₁ p₂ p₃ = -∠ p₁ p₂ p₃ := o.oangle_eq_neg_angle_of_sign_eq_neg_one h /-- The unoriented angle at `p` between two points not equal to `p` is zero if and only if the unoriented angle is zero. -/ theorem oangle_eq_zero_iff_angle_eq_zero {p p₁ p₂ : P} (hp₁ : p₁ ≠ p) (hp₂ : p₂ ≠ p) : ∡ p₁ p p₂ = 0 ↔ ∠ p₁ p p₂ = 0 := o.oangle_eq_zero_iff_angle_eq_zero (vsub_ne_zero.2 hp₁) (vsub_ne_zero.2 hp₂) /-- The oriented angle between three points is `π` if and only if the unoriented angle is `π`. -/ theorem oangle_eq_pi_iff_angle_eq_pi {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ ∠ p₁ p₂ p₃ = π := o.oangle_eq_pi_iff_angle_eq_pi /-- If the oriented angle between three points is `π / 2`, so is the unoriented angle. -/ theorem angle_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact o.inner_eq_zero_of_oangle_eq_pi_div_two h /-- If the oriented angle between three points is `π / 2`, so is the unoriented angle (reversed). -/ theorem angle_rev_eq_pi_div_two_of_oangle_eq_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by rw [angle_comm] exact angle_eq_pi_div_two_of_oangle_eq_pi_div_two h /-- If the oriented angle between three points is `-π / 2`, the unoriented angle is `π / 2`. -/ theorem angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₁ p₂ p₃ = π / 2 := by rw [angle, ← InnerProductGeometry.inner_eq_zero_iff_angle_eq_pi_div_two] exact o.inner_eq_zero_of_oangle_eq_neg_pi_div_two h /-- If the oriented angle between three points is `-π / 2`, the unoriented angle (reversed) is `π / 2`. -/ theorem angle_rev_eq_pi_div_two_of_oangle_eq_neg_pi_div_two {p₁ p₂ p₃ : P} (h : ∡ p₁ p₂ p₃ = ↑(-π / 2)) : ∠ p₃ p₂ p₁ = π / 2 := by rw [angle_comm] exact angle_eq_pi_div_two_of_oangle_eq_neg_pi_div_two h /-- Swapping the first and second points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₁₂_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₂ p₁ p₃).sign := by rw [eq_comm, oangle, oangle, ← o.oangle_neg_neg, neg_vsub_eq_vsub_rev, neg_vsub_eq_vsub_rev, ← vsub_sub_vsub_cancel_left p₁ p₃ p₂, ← neg_vsub_eq_vsub_rev p₃ p₂, sub_eq_add_neg, neg_vsub_eq_vsub_rev p₂ p₁, add_comm, ← @neg_one_smul ℝ] nth_rw 2 [← one_smul ℝ (p₁ -ᵥ p₂)] rw [o.oangle_sign_smul_add_smul_right] simp /-- Swapping the first and third points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₁₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₃ p₂ p₁).sign := by rw [oangle_rev, Real.Angle.sign_neg, neg_neg] /-- Swapping the second and third points in an oriented angle negates the sign of that angle. -/ theorem oangle_swap₂₃_sign (p₁ p₂ p₃ : P) : -(∡ p₁ p₂ p₃).sign = (∡ p₁ p₃ p₂).sign := by rw [oangle_swap₁₃_sign, ← oangle_swap₁₂_sign, oangle_swap₁₃_sign] /-- Rotating the points in an oriented angle does not change the sign of that angle. -/ theorem oangle_rotate_sign (p₁ p₂ p₃ : P) : (∡ p₂ p₃ p₁).sign = (∡ p₁ p₂ p₃).sign := by rw [← oangle_swap₁₂_sign, oangle_swap₁₃_sign] /-- The oriented angle between three points is π if and only if the second point is strictly between the other two. -/ theorem oangle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by rw [oangle_eq_pi_iff_angle_eq_pi, angle_eq_pi_iff_sbtw] /-- If the second of three points is strictly between the other two, the oriented angle at that point is π. -/ theorem _root_.Sbtw.oangle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₂ p₃ = π := oangle_eq_pi_iff_sbtw.2 h /-- If the second of three points is strictly between the other two, the oriented angle at that point (reversed) is π. -/ theorem _root_.Sbtw.oangle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₂ p₁ = π := by rw [oangle_eq_pi_iff_oangle_rev_eq_pi, ← h.oangle₁₂₃_eq_pi] /-- If the second of three points is weakly between the other two, the oriented angle at the first point is zero. -/ theorem _root_.Wbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := by by_cases hp₂p₁ : p₂ = p₁; · simp [hp₂p₁] by_cases hp₃p₁ : p₃ = p₁; · simp [hp₃p₁] rw [oangle_eq_zero_iff_angle_eq_zero hp₂p₁ hp₃p₁] exact h.angle₂₁₃_eq_zero_of_ne hp₂p₁ /-- If the second of three points is strictly between the other two, the oriented angle at the first point is zero. -/ theorem _root_.Sbtw.oangle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₁ p₃ = 0 := h.wbtw.oangle₂₁₃_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the first point (reversed) is zero. -/ theorem _root_.Wbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := by rw [oangle_eq_zero_iff_oangle_rev_eq_zero, h.oangle₂₁₃_eq_zero] /-- If the second of three points is strictly between the other two, the oriented angle at the first point (reversed) is zero. -/ theorem _root_.Sbtw.oangle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₃ p₁ p₂ = 0 := h.wbtw.oangle₃₁₂_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the third point is zero. -/ theorem _root_.Wbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 := h.symm.oangle₂₁₃_eq_zero /-- If the second of three points is strictly between the other two, the oriented angle at the third point is zero. -/ theorem _root_.Sbtw.oangle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₂ p₃ p₁ = 0 := h.wbtw.oangle₂₃₁_eq_zero /-- If the second of three points is weakly between the other two, the oriented angle at the third point (reversed) is zero. -/ theorem _root_.Wbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 := h.symm.oangle₃₁₂_eq_zero /-- If the second of three points is strictly between the other two, the oriented angle at the third point (reversed) is zero. -/ theorem _root_.Sbtw.oangle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∡ p₁ p₃ p₂ = 0 := h.wbtw.oangle₁₃₂_eq_zero /-- The oriented angle between three points is zero if and only if one of the first and third points is weakly between the other two. -/ theorem oangle_eq_zero_iff_wbtw {p₁ p₂ p₃ : P} : ∡ p₁ p₂ p₃ = 0 ↔ Wbtw ℝ p₂ p₁ p₃ ∨ Wbtw ℝ p₂ p₃ p₁ := by by_cases hp₁p₂ : p₁ = p₂; · simp [hp₁p₂] by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] rw [oangle_eq_zero_iff_angle_eq_zero hp₁p₂ hp₃p₂, angle_eq_zero_iff_ne_and_wbtw] simp [hp₁p₂, hp₃p₂] /-- An oriented angle is unchanged by replacing the first point by one weakly further away on the same ray. -/ theorem _root_.Wbtw.oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Wbtw ℝ p₂ p₁ p₁') (hp₁p₂ : p₁ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ := by by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] by_cases hp₁'p₂ : p₁' = p₂; · rw [hp₁'p₂, wbtw_self_iff] at h; exact False.elim (hp₁p₂ h) rw [← oangle_add hp₁'p₂ hp₁p₂ hp₃p₂, h.oangle₃₁₂_eq_zero, zero_add] /-- An oriented angle is unchanged by replacing the first point by one strictly further away on the same ray. -/ theorem _root_.Sbtw.oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Sbtw ℝ p₂ p₁ p₁') : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ := h.wbtw.oangle_eq_left h.ne_left /-- An oriented angle is unchanged by replacing the third point by one weakly further away on the same ray. -/ theorem _root_.Wbtw.oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Wbtw ℝ p₂ p₃ p₃') (hp₃p₂ : p₃ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' := by rw [oangle_rev, h.oangle_eq_left hp₃p₂, ← oangle_rev] /-- An oriented angle is unchanged by replacing the third point by one strictly further away on the same ray. -/ theorem _root_.Sbtw.oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Sbtw ℝ p₂ p₃ p₃') : ∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' := h.wbtw.oangle_eq_right h.ne_left /-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment between it and the second point. -/ @[simp] theorem oangle_midpoint_left (p₁ p₂ p₃ : P) : ∡ (midpoint ℝ p₁ p₂) p₂ p₃ = ∡ p₁ p₂ p₃ := by by_cases h : p₁ = p₂; · simp [h] exact (sbtw_midpoint_of_ne ℝ h).symm.oangle_eq_left /-- An oriented angle is unchanged by replacing the first point with the midpoint of the segment between the second point and that point. -/ @[simp] theorem oangle_midpoint_rev_left (p₁ p₂ p₃ : P) : ∡ (midpoint ℝ p₂ p₁) p₂ p₃ = ∡ p₁ p₂ p₃ := by rw [midpoint_comm, oangle_midpoint_left] /-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment between it and the second point. -/ @[simp] theorem oangle_midpoint_right (p₁ p₂ p₃ : P) : ∡ p₁ p₂ (midpoint ℝ p₃ p₂) = ∡ p₁ p₂ p₃ := by by_cases h : p₃ = p₂; · simp [h] exact (sbtw_midpoint_of_ne ℝ h).symm.oangle_eq_right /-- An oriented angle is unchanged by replacing the third point with the midpoint of the segment between the second point and that point. -/ @[simp] theorem oangle_midpoint_rev_right (p₁ p₂ p₃ : P) : ∡ p₁ p₂ (midpoint ℝ p₂ p₃) = ∡ p₁ p₂ p₃ := by rw [midpoint_comm, oangle_midpoint_right] /-- Replacing the first point by one on the same line but the opposite ray adds π to the oriented angle. -/ theorem _root_.Sbtw.oangle_eq_add_pi_left {p₁ p₁' p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₁') (hp₃p₂ : p₃ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃ + π := by rw [← h.oangle₁₂₃_eq_pi, oangle_add_swap h.left_ne h.right_ne hp₃p₂] /-- Replacing the third point by one on the same line but the opposite ray adds π to the oriented angle. -/ theorem _root_.Sbtw.oangle_eq_add_pi_right {p₁ p₂ p₃ p₃' : P} (h : Sbtw ℝ p₃ p₂ p₃') (hp₁p₂ : p₁ ≠ p₂) : ∡ p₁ p₂ p₃ = ∡ p₁ p₂ p₃' + π := by rw [← h.oangle₃₂₁_eq_pi, oangle_add hp₁p₂ h.right_ne h.left_ne] /-- Replacing both the first and third points by ones on the same lines but the opposite rays does not change the oriented angle (vertically opposite angles). -/ theorem _root_.Sbtw.oangle_eq_left_right {p₁ p₁' p₂ p₃ p₃' : P} (h₁ : Sbtw ℝ p₁ p₂ p₁') (h₃ : Sbtw ℝ p₃ p₂ p₃') : ∡ p₁ p₂ p₃ = ∡ p₁' p₂ p₃' := by rw [h₁.oangle_eq_add_pi_left h₃.left_ne, h₃.oangle_eq_add_pi_right h₁.right_ne, add_assoc, Real.Angle.coe_pi_add_coe_pi, add_zero] /-- Replacing the first point by one on the same line does not change twice the oriented angle. -/ theorem _root_.Collinear.two_zsmul_oangle_eq_left {p₁ p₁' p₂ p₃ : P} (h : Collinear ℝ ({p₁, p₂, p₁'} : Set P)) (hp₁p₂ : p₁ ≠ p₂) (hp₁'p₂ : p₁' ≠ p₂) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₁' p₂ p₃ := by by_cases hp₃p₂ : p₃ = p₂; · simp [hp₃p₂] rcases h.wbtw_or_wbtw_or_wbtw with (hw | hw | hw) · have hw' : Sbtw ℝ p₁ p₂ p₁' := ⟨hw, hp₁p₂.symm, hp₁'p₂.symm⟩ rw [hw'.oangle_eq_add_pi_left hp₃p₂, smul_add, Real.Angle.two_zsmul_coe_pi, add_zero] · rw [hw.oangle_eq_left hp₁'p₂] · rw [hw.symm.oangle_eq_left hp₁p₂] /-- Replacing the third point by one on the same line does not change twice the oriented angle. -/ theorem _root_.Collinear.two_zsmul_oangle_eq_right {p₁ p₂ p₃ p₃' : P} (h : Collinear ℝ ({p₃, p₂, p₃'} : Set P)) (hp₃p₂ : p₃ ≠ p₂) (hp₃'p₂ : p₃' ≠ p₂) : (2 : ℤ) • ∡ p₁ p₂ p₃ = (2 : ℤ) • ∡ p₁ p₂ p₃' := by rw [oangle_rev, smul_neg, h.two_zsmul_oangle_eq_left hp₃p₂ hp₃'p₂, ← smul_neg, ← oangle_rev] /-- Two different points are equidistant from a third point if and only if that third point equals some multiple of a `π / 2` rotation of the vector between those points, plus the midpoint of those points. -/ theorem dist_eq_iff_eq_smul_rotation_pi_div_two_vadd_midpoint {p₁ p₂ p : P} (h : p₁ ≠ p₂) : dist p₁ p = dist p₂ p ↔ ∃ r : ℝ, r • o.rotation (π / 2 : ℝ) (p₂ -ᵥ p₁) +ᵥ midpoint ℝ p₁ p₂ = p := by refine ⟨fun hd => ?_, fun hr => ?_⟩ · have hi : ⟪p₂ -ᵥ p₁, p -ᵥ midpoint ℝ p₁ p₂⟫ = 0 := by rw [@dist_eq_norm_vsub' V, @dist_eq_norm_vsub' V, ← mul_self_inj (norm_nonneg _) (norm_nonneg _), ← real_inner_self_eq_norm_mul_norm, ← real_inner_self_eq_norm_mul_norm] at hd simp_rw [vsub_midpoint, ← vsub_sub_vsub_cancel_left p₂ p₁ p, inner_sub_left, inner_add_right, inner_smul_right, hd, real_inner_comm (p -ᵥ p₁)] abel rw [@Orientation.inner_eq_zero_iff_eq_zero_or_eq_smul_rotation_pi_div_two V _ _ _ o, or_iff_right (vsub_ne_zero.2 h.symm)] at hi rcases hi with ⟨r, hr⟩ rw [eq_comm, ← eq_vadd_iff_vsub_eq] at hr exact ⟨r, hr.symm⟩ · rcases hr with ⟨r, rfl⟩ simp_rw [@dist_eq_norm_vsub V, vsub_vadd_eq_vsub_sub, left_vsub_midpoint, right_vsub_midpoint, invOf_eq_inv, ← neg_vsub_eq_vsub_rev p₂ p₁, ← mul_self_inj (norm_nonneg _) (norm_nonneg _), ← real_inner_self_eq_norm_mul_norm, inner_sub_sub_self] simp [-neg_vsub_eq_vsub_rev] open AffineSubspace /-- Given two pairs of distinct points on the same line, such that the vectors between those pairs of points are on the same ray (oriented in the same direction on that line), and a fifth point, the angles at the fifth point between each of those two pairs of points have the same sign. -/ theorem _root_.Collinear.oangle_sign_of_sameRay_vsub {p₁ p₂ p₃ p₄ : P} (p₅ : P) (hp₁p₂ : p₁ ≠ p₂) (hp₃p₄ : p₃ ≠ p₄) (hc : Collinear ℝ ({p₁, p₂, p₃, p₄} : Set P)) (hr : SameRay ℝ (p₂ -ᵥ p₁) (p₄ -ᵥ p₃)) : (∡ p₁ p₅ p₂).sign = (∡ p₃ p₅ p₄).sign := by by_cases hc₅₁₂ : Collinear ℝ ({p₅, p₁, p₂} : Set P) · have hc₅₁₂₃₄ : Collinear ℝ ({p₅, p₁, p₂, p₃, p₄} : Set P) := (hc.collinear_insert_iff_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) hp₁p₂).2 hc₅₁₂ have hc₅₃₄ : Collinear ℝ ({p₅, p₃, p₄} : Set P) := (hc.collinear_insert_iff_of_ne (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _))) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_singleton _)))) hp₃p₄).1 hc₅₁₂₃₄ rw [Set.insert_comm] at hc₅₁₂ hc₅₃₄ have hs₁₅₂ := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc₅₁₂ have hs₃₅₄ := oangle_eq_zero_or_eq_pi_iff_collinear.2 hc₅₃₄ rw [← Real.Angle.sign_eq_zero_iff] at hs₁₅₂ hs₃₅₄ rw [hs₁₅₂, hs₃₅₄] · let s : Set (P × P × P) := (fun x : line[ℝ, p₁, p₂] × V => (x.1, p₅, x.2 +ᵥ (x.1 : P))) '' Set.univ ×ˢ {v | SameRay ℝ (p₂ -ᵥ p₁) v ∧ v ≠ 0} have hco : IsConnected s := haveI : ConnectedSpace line[ℝ, p₁, p₂] := AddTorsor.connectedSpace _ _ (isConnected_univ.prod (isConnected_setOf_sameRay_and_ne_zero (vsub_ne_zero.2 hp₁p₂.symm))).image _ (by fun_prop) have hf : ContinuousOn (fun p : P × P × P => ∡ p.1 p.2.1 p.2.2) s := by refine continuousOn_of_forall_continuousAt fun p hp => continuousAt_oangle ?_ ?_ all_goals simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_univ, true_and, Prod.ext_iff] at hp obtain ⟨q₁, q₅, q₂⟩ := p dsimp only at hp ⊢ obtain ⟨⟨⟨q, hq⟩, v⟩, hv, rfl, rfl, rfl⟩ := hp dsimp only [Subtype.coe_mk, Set.mem_setOf] at hv ⊢ obtain ⟨hvr, -⟩ := hv rintro rfl refine hc₅₁₂ ((collinear_insert_iff_of_mem_affineSpan ?_).2 (collinear_pair _ _ _)) · exact hq · refine vadd_mem_of_mem_direction ?_ hq rw [← exists_nonneg_left_iff_sameRay (vsub_ne_zero.2 hp₁p₂.symm)] at hvr obtain ⟨r, -, rfl⟩ := hvr rw [direction_affineSpan] exact smul_vsub_rev_mem_vectorSpan_pair _ _ _ have hsp : ∀ p : P × P × P, p ∈ s → ∡ p.1 p.2.1 p.2.2 ≠ 0 ∧ ∡ p.1 p.2.1 p.2.2 ≠ π := by intro p hp simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and, Prod.ext_iff] at hp obtain ⟨q₁, q₅, q₂⟩ := p dsimp only at hp ⊢ obtain ⟨⟨⟨q, hq⟩, v⟩, hv, rfl, rfl, rfl⟩ := hp dsimp only [Subtype.coe_mk, Set.mem_setOf] at hv ⊢ obtain ⟨hvr, hv0⟩ := hv rw [← exists_nonneg_left_iff_sameRay (vsub_ne_zero.2 hp₁p₂.symm)] at hvr obtain ⟨r, -, rfl⟩ := hvr change q ∈ line[ℝ, p₁, p₂] at hq rw [oangle_ne_zero_and_ne_pi_iff_affineIndependent] refine affineIndependent_of_ne_of_mem_of_not_mem_of_mem ?_ hq (fun h => hc₅₁₂ ((collinear_insert_iff_of_mem_affineSpan h).2 (collinear_pair _ _ _))) ?_ · rwa [← @vsub_ne_zero V, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, neg_ne_zero] · refine vadd_mem_of_mem_direction ?_ hq rw [direction_affineSpan] exact smul_vsub_rev_mem_vectorSpan_pair _ _ _ have hp₁p₂s : (p₁, p₅, p₂) ∈ s := by simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and, Prod.ext_iff] refine ⟨⟨⟨p₁, left_mem_affineSpan_pair ℝ _ _⟩, p₂ -ᵥ p₁⟩, ⟨SameRay.rfl, vsub_ne_zero.2 hp₁p₂.symm⟩, ?_⟩ simp have hp₃p₄s : (p₃, p₅, p₄) ∈ s := by simp_rw [s, Set.mem_image, Set.mem_prod, Set.mem_setOf, Set.mem_univ, true_and, Prod.ext_iff] refine ⟨⟨⟨p₃, hc.mem_affineSpan_of_mem_of_ne (Set.mem_insert _ _) (Set.mem_insert_of_mem _ (Set.mem_insert _ _)) (Set.mem_insert_of_mem _ (Set.mem_insert_of_mem _ (Set.mem_insert _ _))) hp₁p₂⟩, p₄ -ᵥ p₃⟩, ⟨hr, vsub_ne_zero.2 hp₃p₄.symm⟩, ?_⟩ simp convert Real.Angle.sign_eq_of_continuousOn hco hf hsp hp₃p₄s hp₁p₂s /-- Given three points in strict order on the same line, and a fourth point, the angles at the fourth point between the first and second or second and third points have the same sign. -/ theorem _root_.Sbtw.oangle_sign_eq {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) : (∡ p₁ p₄ p₂).sign = (∡ p₂ p₄ p₃).sign := haveI hc : Collinear ℝ ({p₁, p₂, p₂, p₃} : Set P) := by simpa using h.wbtw.collinear hc.oangle_sign_of_sameRay_vsub _ h.left_ne h.ne_right h.wbtw.sameRay_vsub /-- Given three points in weak order on the same line, with the first not equal to the second, and a fourth point, the angles at the fourth point between the first and second or first and third points have the same sign. -/ theorem _root_.Wbtw.oangle_sign_eq_of_ne_left {p₁ p₂ p₃ : P} (p₄ : P) (h : Wbtw ℝ p₁ p₂ p₃) (hne : p₁ ≠ p₂) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₄ p₃).sign := haveI hc : Collinear ℝ ({p₁, p₂, p₁, p₃} : Set P) := by simpa [Set.insert_comm p₂] using h.collinear hc.oangle_sign_of_sameRay_vsub _ hne (h.left_ne_right_of_ne_left hne.symm) h.sameRay_vsub_left /-- Given three points in strict order on the same line, and a fourth point, the angles at the fourth point between the first and second or first and third points have the same sign. -/ theorem _root_.Sbtw.oangle_sign_eq_left {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₄ p₃).sign := h.wbtw.oangle_sign_eq_of_ne_left _ h.left_ne /-- Given three points in weak order on the same line, with the second not equal to the third, and a fourth point, the angles at the fourth point between the second and third or first and third points have the same sign. -/ theorem _root_.Wbtw.oangle_sign_eq_of_ne_right {p₁ p₂ p₃ : P} (p₄ : P) (h : Wbtw ℝ p₁ p₂ p₃) (hne : p₂ ≠ p₃) : (∡ p₂ p₄ p₃).sign = (∡ p₁ p₄ p₃).sign := by simp_rw [oangle_rev p₃, Real.Angle.sign_neg, h.symm.oangle_sign_eq_of_ne_left _ hne.symm] /-- Given three points in strict order on the same line, and a fourth point, the angles at the fourth point between the second and third or first and third points have the same sign. -/ theorem _root_.Sbtw.oangle_sign_eq_right {p₁ p₂ p₃ : P} (p₄ : P) (h : Sbtw ℝ p₁ p₂ p₃) : (∡ p₂ p₄ p₃).sign = (∡ p₁ p₄ p₃).sign := h.wbtw.oangle_sign_eq_of_ne_right _ h.ne_right /-- Given two points in an affine subspace, the angles between those two points at two other points on the same side of that subspace have the same sign. -/ theorem _root_.AffineSubspace.SSameSide.oangle_sign_eq {s : AffineSubspace ℝ P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃p₄ : s.SSameSide p₃ p₄) : (∡ p₁ p₄ p₂).sign = (∡ p₁ p₃ p₂).sign := by by_cases h : p₁ = p₂; · simp [h] let sp : Set (P × P × P) := (fun p : P => (p₁, p, p₂)) '' {p | s.SSameSide p₃ p} have hc : IsConnected sp := (isConnected_setOf_sSameSide hp₃p₄.2.1 hp₃p₄.nonempty).image _ (by fun_prop) have hf : ContinuousOn (fun p : P × P × P => ∡ p.1 p.2.1 p.2.2) sp := by refine continuousOn_of_forall_continuousAt fun p hp => continuousAt_oangle ?_ ?_ all_goals simp_rw [sp, Set.mem_image, Set.mem_setOf] at hp obtain ⟨p', hp', rfl⟩ := hp dsimp only rintro rfl · exact hp'.2.2 hp₁ · exact hp'.2.2 hp₂ have hsp : ∀ p : P × P × P, p ∈ sp → ∡ p.1 p.2.1 p.2.2 ≠ 0 ∧ ∡ p.1 p.2.1 p.2.2 ≠ π := by intro p hp simp_rw [sp, Set.mem_image, Set.mem_setOf] at hp obtain ⟨p', hp', rfl⟩ := hp dsimp only rw [oangle_ne_zero_and_ne_pi_iff_affineIndependent] exact affineIndependent_of_ne_of_mem_of_not_mem_of_mem h hp₁ hp'.2.2 hp₂ have hp₃ : (p₁, p₃, p₂) ∈ sp := Set.mem_image_of_mem _ (sSameSide_self_iff.2 ⟨hp₃p₄.nonempty, hp₃p₄.2.1⟩) have hp₄ : (p₁, p₄, p₂) ∈ sp := Set.mem_image_of_mem _ hp₃p₄ convert Real.Angle.sign_eq_of_continuousOn hc hf hsp hp₃ hp₄ /-- Given two points in an affine subspace, the angles between those two points at two other points on opposite sides of that subspace have opposite signs. -/ theorem _root_.AffineSubspace.SOppSide.oangle_sign_eq_neg {s : AffineSubspace ℝ P} {p₁ p₂ p₃ p₄ : P} (hp₁ : p₁ ∈ s) (hp₂ : p₂ ∈ s) (hp₃p₄ : s.SOppSide p₃ p₄) : (∡ p₁ p₄ p₂).sign = -(∡ p₁ p₃ p₂).sign := by have hp₁p₃ : p₁ ≠ p₃ := by rintro rfl; exact hp₃p₄.left_not_mem hp₁ rw [← (hp₃p₄.symm.trans (sOppSide_pointReflection hp₁ hp₃p₄.left_not_mem)).oangle_sign_eq hp₁ hp₂, ← oangle_rotate_sign p₁, ← oangle_rotate_sign p₁, oangle_swap₁₃_sign, (sbtw_pointReflection_of_ne ℝ hp₁p₃).symm.oangle_sign_eq _] end EuclideanGeometry
Mathlib/Geometry/Euclidean/Angle/Oriented/Affine.lean
768
771
/- Copyright (c) 2017 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Stephen Morgan, Kim Morrison, Johannes Hölzl, Reid Barton -/ import Mathlib.CategoryTheory.Category.Init import Mathlib.Combinatorics.Quiver.Basic import Mathlib.Tactic.PPWithUniv import Mathlib.Tactic.Common import Mathlib.Tactic.StacksAttribute import Mathlib.Tactic.TryThis /-! # Categories Defines a category, as a type class parametrised by the type of objects. ## Notations Introduces notations in the `CategoryTheory` scope * `X ⟶ Y` for the morphism spaces (type as `\hom`), * `𝟙 X` for the identity morphism on `X` (type as `\b1`), * `f ≫ g` for composition in the 'arrows' convention (type as `\gg`). Users may like to add `g ⊚ f` for composition in the standard convention, using ```lean local notation:80 g " ⊚ " f:80 => CategoryTheory.CategoryStruct.comp f g -- type as \oo ``` -/ library_note "CategoryTheory universes" /-- The typeclass `Category C` describes morphisms associated to objects of type `C : Type u`. The universe levels of the objects and morphisms are independent, and will often need to be specified explicitly, as `Category.{v} C`. Typically any concrete example will either be a `SmallCategory`, where `v = u`, which can be introduced as ``` universe u variable {C : Type u} [SmallCategory C] ``` or a `LargeCategory`, where `u = v+1`, which can be introduced as ``` universe u variable {C : Type (u+1)} [LargeCategory C] ``` In order for the library to handle these cases uniformly, we generally work with the unconstrained `Category.{v u}`, for which objects live in `Type u` and morphisms live in `Type v`. Because the universe parameter `u` for the objects can be inferred from `C` when we write `Category C`, while the universe parameter `v` for the morphisms can not be automatically inferred, through the category theory library we introduce universe parameters with morphism levels listed first, as in ``` universe v u ``` or ``` universe v₁ v₂ u₁ u₂ ``` when multiple independent universes are needed. This has the effect that we can simply write `Category.{v} C` (that is, only specifying a single parameter) while `u` will be inferred. Often, however, it's not even necessary to include the `.{v}`. (Although it was in earlier versions of Lean.) If it is omitted a "free" universe will be used. -/ universe v u namespace CategoryTheory /-- A preliminary structure on the way to defining a category, containing the data, but none of the axioms. -/ @[pp_with_univ] class CategoryStruct (obj : Type u) : Type max u (v + 1) extends Quiver.{v + 1} obj where /-- The identity morphism on an object. -/ id : ∀ X : obj, Hom X X /-- Composition of morphisms in a category, written `f ≫ g`. -/ comp : ∀ {X Y Z : obj}, (X ⟶ Y) → (Y ⟶ Z) → (X ⟶ Z) initialize_simps_projections CategoryStruct (-toQuiver_Hom) /-- Notation for the identity morphism in a category. -/ scoped notation "𝟙" => CategoryStruct.id -- type as \b1 /-- Notation for composition of morphisms in a category. -/ scoped infixr:80 " ≫ " => CategoryStruct.comp -- type as \gg /-- Close the main goal with `sorry` if its type contains `sorry`, and fail otherwise. -/ syntax (name := sorryIfSorry) "sorry_if_sorry" : tactic open Lean Meta Elab.Tactic in @[tactic sorryIfSorry, inherit_doc sorryIfSorry] def evalSorryIfSorry : Tactic := fun _ => do let goalType ← getMainTarget if goalType.hasSorry then closeMainGoal `sorry_if_sorry (← mkSorry goalType true) else throwError "The goal does not contain `sorry`" /-- `rfl_cat` is a macro for `intros; rfl` which is attempted in `aesop_cat` before doing the more expensive `aesop` tactic. This gives a speedup because `simp` (called by `aesop`) is too slow. There is a fix for this slowness in https://github.com/leanprover/lean4/pull/7428. So, when that is resolved, the performance impact of `rfl_cat` should be measured again. Implementation notes: * `refine id ?_`: In some cases it is important that the type of the proof matches the expected type exactly. e.g. if the goal is `2 = 1 + 1`, the `rfl` tactic will give a proof of type `2 = 2`. Starting a proof with `refine id ?_` is a trick to make sure that the proof has exactly the expected type, in this case `2 = 1 + 1`. See also https://leanprover.zulipchat.com/#narrow/channel/270676-lean4/topic/changing.20a.20proof.20can.20break.20a.20later.20proof * `apply_rfl`: `rfl` is a macro that attempts both `eq_refl` and `apply_rfl`. Since `apply_rfl` subsumes `eq_refl`, we can use `apply_rfl` instead. This fails twice as fast as `rfl`. -/ macro (name := rfl_cat) "rfl_cat" : tactic => do `(tactic| (refine id ?_; intros; apply_rfl)) /-- A thin wrapper for `aesop` which adds the `CategoryTheory` rule set and allows `aesop` to look through semireducible definitions when calling `intros`. This tactic fails when it is unable to solve the goal, making it suitable for use in auto-params. -/ macro (name := aesop_cat) "aesop_cat" c:Aesop.tactic_clause* : tactic => `(tactic| first | sorry_if_sorry | rfl_cat | aesop $c* (config := { introsTransparency? := some .default, terminal := true }) (rule_sets := [$(Lean.mkIdent `CategoryTheory):ident])) /-- We also use `aesop_cat?` to pass along a `Try this` suggestion when using `aesop_cat` -/ macro (name := aesop_cat?) "aesop_cat?" c:Aesop.tactic_clause* : tactic => `(tactic| first | sorry_if_sorry | try_this rfl_cat | aesop? $c* (config := { introsTransparency? := some .default, terminal := true }) (rule_sets := [$(Lean.mkIdent `CategoryTheory):ident])) /-- A variant of `aesop_cat` which does not fail when it is unable to solve the goal. Use this only for exploration! Nonterminal `aesop` is even worse than nonterminal `simp`. -/ macro (name := aesop_cat_nonterminal) "aesop_cat_nonterminal" c:Aesop.tactic_clause* : tactic => `(tactic| aesop $c* (config := { introsTransparency? := some .default, warnOnNonterminal := false }) (rule_sets := [$(Lean.mkIdent `CategoryTheory):ident])) attribute [aesop safe (rule_sets := [CategoryTheory])] Subsingleton.elim /-- The typeclass `Category C` describes morphisms associated to objects of type `C`. The universe levels of the objects and morphisms are unconstrained, and will often need to be specified explicitly, as `Category.{v} C`. (See also `LargeCategory` and `SmallCategory`.) -/ @[pp_with_univ, stacks 0014] class Category (obj : Type u) : Type max u (v + 1) extends CategoryStruct.{v} obj where /-- Identity morphisms are left identities for composition. -/ id_comp : ∀ {X Y : obj} (f : X ⟶ Y), 𝟙 X ≫ f = f := by aesop_cat /-- Identity morphisms are right identities for composition. -/ comp_id : ∀ {X Y : obj} (f : X ⟶ Y), f ≫ 𝟙 Y = f := by aesop_cat /-- Composition in a category is associative. -/ assoc : ∀ {W X Y Z : obj} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z), (f ≫ g) ≫ h = f ≫ g ≫ h := by aesop_cat attribute [simp] Category.id_comp Category.comp_id Category.assoc attribute [trans] CategoryStruct.comp example {C} [Category C] {X Y : C} (f : X ⟶ Y) : 𝟙 X ≫ f = f := by simp example {C} [Category C] {X Y : C} (f : X ⟶ Y) : f ≫ 𝟙 Y = f := by simp /-- A `LargeCategory` has objects in one universe level higher than the universe level of the morphisms. It is useful for examples such as the category of types, or the category of groups, etc. -/ abbrev LargeCategory (C : Type (u + 1)) : Type (u + 1) := Category.{u} C /-- A `SmallCategory` has objects and morphisms in the same universe level. -/ abbrev SmallCategory (C : Type u) : Type (u + 1) := Category.{u} C section variable {C : Type u} [Category.{v} C] {X Y Z : C} initialize_simps_projections Category (-Hom) /-- postcompose an equation between morphisms by another morphism -/ theorem eq_whisker {f g : X ⟶ Y} (w : f = g) (h : Y ⟶ Z) : f ≫ h = g ≫ h := by rw [w] /-- precompose an equation between morphisms by another morphism -/ theorem whisker_eq (f : X ⟶ Y) {g h : Y ⟶ Z} (w : g = h) : f ≫ g = f ≫ h := by rw [w] /-- Notation for whiskering an equation by a morphism (on the right). If `f g : X ⟶ Y` and `w : f = g` and `h : Y ⟶ Z`, then `w =≫ h : f ≫ h = g ≫ h`. -/ scoped infixr:80 " =≫ " => eq_whisker /-- Notation for whiskering an equation by a morphism (on the left). If `g h : Y ⟶ Z` and `w : g = h` and `f : X ⟶ Y`, then `f ≫= w : f ≫ g = f ≫ h`. -/ scoped infixr:80 " ≫= " => whisker_eq theorem eq_of_comp_left_eq {f g : X ⟶ Y} (w : ∀ {Z : C} (h : Y ⟶ Z), f ≫ h = g ≫ h) : f = g := by convert w (𝟙 Y) <;> simp theorem eq_of_comp_right_eq {f g : Y ⟶ Z} (w : ∀ {X : C} (h : X ⟶ Y), h ≫ f = h ≫ g) : f = g := by convert w (𝟙 Y) <;> simp theorem eq_of_comp_left_eq' (f g : X ⟶ Y) (w : (fun {Z} (h : Y ⟶ Z) => f ≫ h) = fun {Z} (h : Y ⟶ Z) => g ≫ h) : f = g := eq_of_comp_left_eq @fun Z h => by convert congr_fun (congr_fun w Z) h theorem eq_of_comp_right_eq' (f g : Y ⟶ Z) (w : (fun {X} (h : X ⟶ Y) => h ≫ f) = fun {X} (h : X ⟶ Y) => h ≫ g) : f = g := eq_of_comp_right_eq @fun X h => by convert congr_fun (congr_fun w X) h theorem id_of_comp_left_id (f : X ⟶ X) (w : ∀ {Y : C} (g : X ⟶ Y), f ≫ g = g) : f = 𝟙 X := by convert w (𝟙 X) simp theorem id_of_comp_right_id (f : X ⟶ X) (w : ∀ {Y : C} (g : Y ⟶ X), g ≫ f = g) : f = 𝟙 X := by convert w (𝟙 X) simp theorem comp_ite {P : Prop} [Decidable P] {X Y Z : C} (f : X ⟶ Y) (g g' : Y ⟶ Z) : (f ≫ if P then g else g') = if P then f ≫ g else f ≫ g' := by aesop theorem ite_comp {P : Prop} [Decidable P] {X Y Z : C} (f f' : X ⟶ Y) (g : Y ⟶ Z) : (if P then f else f') ≫ g = if P then f ≫ g else f' ≫ g := by aesop theorem comp_dite {P : Prop} [Decidable P] {X Y Z : C} (f : X ⟶ Y) (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 aesop theorem dite_comp {P : Prop} [Decidable P] {X Y Z : C} (f : P → (X ⟶ Y)) (f' : ¬P → (X ⟶ Y)) (g : Y ⟶ Z) : (if h : P then f h else f' h) ≫ g = if h : P then f h ≫ g else f' h ≫ g := by aesop /-- A morphism `f` is an epimorphism if it can be cancelled when precomposed: `f ≫ g = f ≫ h` implies `g = h`. -/ @[stacks 003B] class Epi (f : X ⟶ Y) : Prop where /-- A morphism `f` is an epimorphism if it can be cancelled when precomposed. -/ left_cancellation : ∀ {Z : C} (g h : Y ⟶ Z), f ≫ g = f ≫ h → g = h /-- A morphism `f` is a monomorphism if it can be cancelled when postcomposed: `g ≫ f = h ≫ f` implies `g = h`. -/ @[stacks 003B] class Mono (f : X ⟶ Y) : Prop where /-- A morphism `f` is a monomorphism if it can be cancelled when postcomposed. -/ right_cancellation : ∀ {Z : C} (g h : Z ⟶ X), g ≫ f = h ≫ f → g = h instance (X : C) : Epi (𝟙 X) := ⟨fun g h w => by aesop⟩ instance (X : C) : Mono (𝟙 X) := ⟨fun g h w => by aesop⟩ theorem cancel_epi (f : X ⟶ Y) [Epi f] {g h : Y ⟶ Z} : f ≫ g = f ≫ h ↔ g = h := ⟨fun p => Epi.left_cancellation g h p, congr_arg _⟩ theorem cancel_epi_assoc_iff (f : X ⟶ Y) [Epi f] {g h : Y ⟶ Z} {W : C} {k l : Z ⟶ W} : (f ≫ g) ≫ k = (f ≫ h) ≫ l ↔ g ≫ k = h ≫ l := ⟨fun p => (cancel_epi f).1 <| by simpa using p, fun p => by simp only [Category.assoc, p]⟩ theorem cancel_mono (f : X ⟶ Y) [Mono f] {g h : Z ⟶ X} : g ≫ f = h ≫ f ↔ g = h := -- Porting note: in Lean 3 we could just write `congr_arg _` here. ⟨fun p => Mono.right_cancellation g h p, congr_arg (fun k => k ≫ f)⟩ theorem cancel_mono_assoc_iff (f : X ⟶ Y) [Mono f] {g h : Z ⟶ X} {W : C} {k l : W ⟶ Z} : k ≫ (g ≫ f) = l ≫ (h ≫ f) ↔ k ≫ g = l ≫ h := ⟨fun p => (cancel_mono f).1 <| by simpa using p, fun p => by simp only [← Category.assoc, p]⟩ theorem cancel_epi_id (f : X ⟶ Y) [Epi f] {h : Y ⟶ Y} : f ≫ h = f ↔ h = 𝟙 Y := by convert cancel_epi f simp theorem cancel_mono_id (f : X ⟶ Y) [Mono f] {g : X ⟶ X} : g ≫ f = f ↔ g = 𝟙 X := by convert cancel_mono f simp /-- The composition of epimorphisms is again an epimorphism. This version takes `Epi f` and `Epi g` as typeclass arguments. For a version taking them as explicit arguments, see `epi_comp'`. -/ instance epi_comp {X Y Z : C} (f : X ⟶ Y) [Epi f] (g : Y ⟶ Z) [Epi g] : Epi (f ≫ g) := ⟨fun _ _ w => (cancel_epi g).1 <| (cancel_epi_assoc_iff f).1 w⟩ /-- The composition of epimorphisms is again an epimorphism. This version takes `Epi f` and `Epi g` as explicit arguments. For a version taking them as typeclass arguments, see `epi_comp`. -/ theorem epi_comp' {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} (hf : Epi f) (hg : Epi g) : Epi (f ≫ g) := inferInstance /-- The composition of monomorphisms is again a monomorphism. This version takes `Mono f` and `Mono g` as typeclass arguments. For a version taking them as explicit arguments, see `mono_comp'`. -/ instance mono_comp {X Y Z : C} (f : X ⟶ Y) [Mono f] (g : Y ⟶ Z) [Mono g] : Mono (f ≫ g) := ⟨fun _ _ w => (cancel_mono f).1 <| (cancel_mono_assoc_iff g).1 w⟩ /-- The composition of monomorphisms is again a monomorphism. This version takes `Mono f` and `Mono g` as explicit arguments. For a version taking them as typeclass arguments, see `mono_comp`. -/ theorem mono_comp' {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} (hf : Mono f) (hg : Mono g) : Mono (f ≫ g) := inferInstance theorem mono_of_mono {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Mono (f ≫ g)] : Mono f := ⟨fun _ _ w => (cancel_mono (f ≫ g)).1 <| by simp only [← Category.assoc, w]⟩ theorem mono_of_mono_fac {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [Mono h] (w : f ≫ g = h) : Mono f := by subst h; exact mono_of_mono f g theorem epi_of_epi {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [Epi (f ≫ g)] : Epi g := ⟨fun _ _ w => (cancel_epi (f ≫ g)).1 <| by simp only [Category.assoc, w]⟩ theorem epi_of_epi_fac {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [Epi h] (w : f ≫ g = h) : Epi g := by subst h; exact epi_of_epi f g
section variable [Quiver.IsThin C] (f : X ⟶ Y) instance : Mono f where
Mathlib/CategoryTheory/Category/Basic.lean
333
338
/- Copyright (c) 2020 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.Geometry.Manifold.MFDeriv.Defs import Mathlib.Geometry.Manifold.ContMDiff.Defs /-! # Basic properties of the manifold Fréchet derivative In this file, we show various properties of the manifold Fréchet derivative, mimicking the API for Fréchet derivatives. - basic properties of unique differentiability sets - various general lemmas about the manifold Fréchet derivative - deducing differentiability from smoothness, - deriving continuity from differentiability on manifolds, - congruence lemmas for derivatives on manifolds - composition lemmas and the chain rule -/ noncomputable section assert_not_exists tangentBundleCore open scoped Topology Manifold open Set Bundle ChartedSpace section DerivativesProperties /-! ### Unique differentiability sets in manifolds -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {H : Type*} [TopologicalSpace H] (I : ModelWithCorners 𝕜 E H) {M : Type*} [TopologicalSpace M] [ChartedSpace H M] {E' : Type*} [NormedAddCommGroup E'] [NormedSpace 𝕜 E'] {H' : Type*} [TopologicalSpace H'] {I' : ModelWithCorners 𝕜 E' H'} {M' : Type*} [TopologicalSpace M'] [ChartedSpace H' M'] {E'' : Type*} [NormedAddCommGroup E''] [NormedSpace 𝕜 E''] {H'' : Type*} [TopologicalSpace H''] {I'' : ModelWithCorners 𝕜 E'' H''} {M'' : Type*} [TopologicalSpace M''] [ChartedSpace H'' M''] {f f₁ : M → M'} {x : M} {s t : Set M} {g : M' → M''} {u : Set M'} theorem uniqueMDiffWithinAt_univ : UniqueMDiffWithinAt I univ x := by unfold UniqueMDiffWithinAt simp only [preimage_univ, univ_inter] exact I.uniqueDiffOn _ (mem_range_self _) variable {I} theorem uniqueMDiffWithinAt_iff_inter_range {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := Iff.rfl theorem uniqueMDiffWithinAt_iff {s : Set M} {x : M} : UniqueMDiffWithinAt I s x ↔ UniqueDiffWithinAt 𝕜 ((extChartAt I x).symm ⁻¹' s ∩ (extChartAt I x).target) ((extChartAt I x) x) := by apply uniqueDiffWithinAt_congr rw [nhdsWithin_inter, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] nonrec theorem UniqueMDiffWithinAt.mono_nhds {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : 𝓝[s] x ≤ 𝓝[t] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds <| by simpa only [← map_extChartAt_nhdsWithin] using Filter.map_mono ht theorem UniqueMDiffWithinAt.mono_of_mem_nhdsWithin {s t : Set M} {x : M} (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I t x := hs.mono_nhds (nhdsWithin_le_iff.2 ht) @[deprecated (since := "2024-10-31")] alias UniqueMDiffWithinAt.mono_of_mem := UniqueMDiffWithinAt.mono_of_mem_nhdsWithin theorem UniqueMDiffWithinAt.mono (h : UniqueMDiffWithinAt I s x) (st : s ⊆ t) : UniqueMDiffWithinAt I t x := UniqueDiffWithinAt.mono h <| inter_subset_inter (preimage_mono st) (Subset.refl _) theorem UniqueMDiffWithinAt.inter' (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝[s] x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.mono_of_mem_nhdsWithin (Filter.inter_mem self_mem_nhdsWithin ht) theorem UniqueMDiffWithinAt.inter (hs : UniqueMDiffWithinAt I s x) (ht : t ∈ 𝓝 x) : UniqueMDiffWithinAt I (s ∩ t) x := hs.inter' (nhdsWithin_le_nhds ht) theorem IsOpen.uniqueMDiffWithinAt (hs : IsOpen s) (xs : x ∈ s) : UniqueMDiffWithinAt I s x := (uniqueMDiffWithinAt_univ I).mono_of_mem_nhdsWithin <| nhdsWithin_le_nhds <| hs.mem_nhds xs theorem UniqueMDiffOn.inter (hs : UniqueMDiffOn I s) (ht : IsOpen t) : UniqueMDiffOn I (s ∩ t) := fun _x hx => UniqueMDiffWithinAt.inter (hs _ hx.1) (ht.mem_nhds hx.2) theorem IsOpen.uniqueMDiffOn (hs : IsOpen s) : UniqueMDiffOn I s := fun _x hx => hs.uniqueMDiffWithinAt hx theorem uniqueMDiffOn_univ : UniqueMDiffOn I (univ : Set M) := isOpen_univ.uniqueMDiffOn nonrec theorem UniqueMDiffWithinAt.prod {x : M} {y : M'} {s t} (hs : UniqueMDiffWithinAt I s x) (ht : UniqueMDiffWithinAt I' t y) : UniqueMDiffWithinAt (I.prod I') (s ×ˢ t) (x, y) := by refine (hs.prod ht).mono ?_ rw [ModelWithCorners.range_prod, ← prod_inter_prod] rfl theorem UniqueMDiffOn.prod {s : Set M} {t : Set M'} (hs : UniqueMDiffOn I s) (ht : UniqueMDiffOn I' t) : UniqueMDiffOn (I.prod I') (s ×ˢ t) := fun x h ↦ (hs x.1 h.1).prod (ht x.2 h.2) theorem MDifferentiableWithinAt.mono (hst : s ⊆ t) (h : MDifferentiableWithinAt I I' f t x) : MDifferentiableWithinAt I I' f s x := ⟨ContinuousWithinAt.mono h.1 hst, DifferentiableWithinAt.mono h.differentiableWithinAt_writtenInExtChartAt (inter_subset_inter_left _ (preimage_mono hst))⟩ theorem mdifferentiableWithinAt_univ : MDifferentiableWithinAt I I' f univ x ↔ MDifferentiableAt I I' f x := by simp_rw [MDifferentiableWithinAt, MDifferentiableAt, ChartedSpace.LiftPropAt] theorem mdifferentiableWithinAt_inter (ht : t ∈ 𝓝 x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter ht] theorem mdifferentiableWithinAt_inter' (ht : t ∈ 𝓝[s] x) : MDifferentiableWithinAt I I' f (s ∩ t) x ↔ MDifferentiableWithinAt I I' f s x := by rw [MDifferentiableWithinAt, MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_inter' ht] theorem MDifferentiableAt.mdifferentiableWithinAt (h : MDifferentiableAt I I' f x) : MDifferentiableWithinAt I I' f s x := MDifferentiableWithinAt.mono (subset_univ _) (mdifferentiableWithinAt_univ.2 h) theorem MDifferentiableWithinAt.mdifferentiableAt (h : MDifferentiableWithinAt I I' f s x) (hs : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := by have : s = univ ∩ s := by rw [univ_inter] rwa [this, mdifferentiableWithinAt_inter hs, mdifferentiableWithinAt_univ] at h theorem MDifferentiableOn.mono (h : MDifferentiableOn I I' f t) (st : s ⊆ t) : MDifferentiableOn I I' f s := fun x hx => (h x (st hx)).mono st theorem mdifferentiableOn_univ : MDifferentiableOn I I' f univ ↔ MDifferentiable I I' f := by simp only [MDifferentiableOn, mdifferentiableWithinAt_univ, mfld_simps]; rfl theorem MDifferentiableOn.mdifferentiableAt (h : MDifferentiableOn I I' f s) (hx : s ∈ 𝓝 x) : MDifferentiableAt I I' f x := (h x (mem_of_mem_nhds hx)).mdifferentiableAt hx theorem MDifferentiable.mdifferentiableOn (h : MDifferentiable I I' f) : MDifferentiableOn I I' f s := (mdifferentiableOn_univ.2 h).mono (subset_univ _) theorem mdifferentiableOn_of_locally_mdifferentiableOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ MDifferentiableOn I I' f (s ∩ u)) : MDifferentiableOn I I' f s := by intro x xs rcases h x xs with ⟨t, t_open, xt, ht⟩ exact (mdifferentiableWithinAt_inter (t_open.mem_nhds xt)).1 (ht x ⟨xs, xt⟩) theorem MDifferentiable.mdifferentiableAt (hf : MDifferentiable I I' f) : MDifferentiableAt I I' f x := hf x /-! ### Relating differentiability in a manifold and differentiability in the model space through extended charts -/ theorem mdifferentiableWithinAt_iff_target_inter {f : M → M'} {s : Set M} {x : M} : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (writtenInExtChartAt I I' x f) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' s) ((extChartAt I x) x) := by rw [mdifferentiableWithinAt_iff'] refine and_congr Iff.rfl (exists_congr fun f' => ?_) rw [inter_comm] simp only [HasFDerivWithinAt, nhdsWithin_inter, nhdsWithin_extChartAt_target_eq] /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. -/ theorem mdifferentiableWithinAt_iff : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x) := by simp_rw [MDifferentiableWithinAt, ChartedSpace.liftPropWithinAt_iff']; rfl /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart. This form states smoothness of `f` written in such a way that the set is restricted to lie within the domain/codomain of the corresponding charts. Even though this expression is more complicated than the one in `mdifferentiableWithinAt_iff`, it is a smaller set, but their germs at `extChartAt I x x` are equal. It is sometimes useful to rewrite using this in the goal. -/ theorem mdifferentiableWithinAt_iff_target_inter' : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (extChartAt I' (f x) ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' (f x)).source)) (extChartAt I x x) := by simp only [MDifferentiableWithinAt, liftPropWithinAt_iff'] exact and_congr_right fun hc => differentiableWithinAt_congr_nhds <| hc.nhdsWithin_extChartAt_symm_preimage_inter_range /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in the corresponding extended chart in the target. -/ theorem mdifferentiableWithinAt_iff_target : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) s x := by simp_rw [MDifferentiableWithinAt, liftPropWithinAt_iff', ← and_assoc] have cont : ContinuousWithinAt f s x ∧ ContinuousWithinAt (extChartAt I' (f x) ∘ f) s x ↔ ContinuousWithinAt f s x := and_iff_left_of_imp <| (continuousAt_extChartAt _).comp_continuousWithinAt simp_rw [cont, DifferentiableWithinAtProp, extChartAt, PartialHomeomorph.extend, PartialEquiv.coe_trans, ModelWithCorners.toPartialEquiv_coe, PartialHomeomorph.coe_coe, modelWithCornersSelf_coe, chartAt_self_eq, PartialHomeomorph.refl_apply] rfl theorem mdifferentiableAt_iff_target {x : M} : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' (f x) ∘ f) x := by rw [← mdifferentiableWithinAt_univ, ← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target, continuousWithinAt_univ] section IsManifold variable {e : PartialHomeomorph M H} {e' : PartialHomeomorph M' H'} open IsManifold theorem mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas [IsManifold I 1 M] (he : e ∈ maximalAtlas I 1 M) (hx : x ∈ e.source) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := by have h2x := hx; rw [← e.extend_source (I := I)] at h2x simp_rw [MDifferentiableWithinAt, differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_source he hx, StructureGroupoid.liftPropWithinAt_self_source, e.extend_symm_continuousWithinAt_comp_right_iff, differentiableWithinAtProp_self_source, DifferentiableWithinAtProp, Function.comp, e.left_inv hx, (e.extend I).left_inv h2x] rfl theorem mdifferentiableWithinAt_iff_source_of_mem_source [IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : MDifferentiableWithinAt I I' f s x' ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := mdifferentiableWithinAt_iff_source_of_mem_maximalAtlas (chart_mem_maximalAtlas x) hx' theorem mdifferentiableAt_iff_source_of_mem_source [IsManifold I 1 M] {x' : M} (hx' : x' ∈ (chartAt H x).source) : MDifferentiableAt I I' f x' ↔ MDifferentiableWithinAt 𝓘(𝕜, E) I' (f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := by simp_rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_source_of_mem_source hx', preimage_univ, univ_inter] theorem mdifferentiableWithinAt_iff_target_of_mem_source [IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ MDifferentiableWithinAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) s x := by simp_rw [MDifferentiableWithinAt] rw [differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart_target (chart_mem_maximalAtlas y) hy, and_congr_right] intro hf simp_rw [StructureGroupoid.liftPropWithinAt_self_target] simp_rw [((chartAt H' y).continuousAt hy).comp_continuousWithinAt hf] rw [← extChartAt_source I'] at hy simp_rw [(continuousAt_extChartAt' hy).comp_continuousWithinAt hf] rfl theorem mdifferentiableAt_iff_target_of_mem_source [IsManifold I' 1 M'] {x : M} {y : M'} (hy : f x ∈ (chartAt H' y).source) : MDifferentiableAt I I' f x ↔ ContinuousAt f x ∧ MDifferentiableAt I 𝓘(𝕜, E') (extChartAt I' y ∘ f) x := by rw [← mdifferentiableWithinAt_univ, mdifferentiableWithinAt_iff_target_of_mem_source hy, continuousWithinAt_univ, ← mdifferentiableWithinAt_univ] variable [IsManifold I 1 M] [IsManifold I' 1 M'] theorem mdifferentiableWithinAt_iff_of_mem_maximalAtlas {x : M} (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hx : x ∈ e.source) (hy : f x ∈ e'.source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) ((e.extend I).symm ⁻¹' s ∩ range I) (e.extend I x) := differentiableWithinAt_localInvariantProp.liftPropWithinAt_indep_chart he hx he' hy /-- An alternative formulation of `mdifferentiableWithinAt_iff_of_mem_maximalAtlas` if the set if `s` lies in `e.source`. -/ theorem mdifferentiableWithinAt_iff_image {x : M} (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (hx : x ∈ e.source) (hy : f x ∈ e'.source) : MDifferentiableWithinAt I I' f s x ↔ ContinuousWithinAt f s x ∧ DifferentiableWithinAt 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) (e.extend I x) := by rw [mdifferentiableWithinAt_iff_of_mem_maximalAtlas he he' hx hy, and_congr_right_iff] refine fun _ => differentiableWithinAt_congr_nhds ?_ simp_rw [nhdsWithin_eq_iff_eventuallyEq, e.extend_symm_preimage_inter_range_eventuallyEq hs hx] /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in any chart containing that point. -/ theorem mdifferentiableWithinAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x' ↔ ContinuousWithinAt f s x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).symm ⁻¹' s ∩ range I) (extChartAt I x x') := mdifferentiableWithinAt_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hx hy /-- One can reformulate smoothness within a set at a point as continuity within this set at this point, and smoothness in any chart containing that point. Version requiring differentiability in the target instead of `range I`. -/ theorem mdifferentiableWithinAt_iff_of_mem_source' {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableWithinAt I I' f s x' ↔ ContinuousWithinAt f s x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) (extChartAt I x x') := by refine (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans ?_ rw [← extChartAt_source I] at hx rw [← extChartAt_source I'] at hy rw [and_congr_right_iff] set e := extChartAt I x; set e' := extChartAt I' (f x) refine fun hc => differentiableWithinAt_congr_nhds ?_ rw [← e.image_source_inter_eq', ← map_extChartAt_nhdsWithin_eq_image' hx, ← map_extChartAt_nhdsWithin' hx, inter_comm, nhdsWithin_inter_of_mem] exact hc (extChartAt_source_mem_nhds' hy) theorem mdifferentiableAt_iff_of_mem_source {x' : M} {y : M'} (hx : x' ∈ (chartAt H x).source) (hy : f x' ∈ (chartAt H' y).source) : MDifferentiableAt I I' f x' ↔ ContinuousAt f x' ∧ DifferentiableWithinAt 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (range I) (extChartAt I x x') := (mdifferentiableWithinAt_iff_of_mem_source hx hy).trans <| by rw [continuousWithinAt_univ, preimage_univ, univ_inter] theorem mdifferentiableOn_iff_of_mem_maximalAtlas (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := by simp_rw [ContinuousOn, DifferentiableOn, Set.forall_mem_image, ← forall_and, MDifferentiableOn] exact forall₂_congr fun x hx => mdifferentiableWithinAt_iff_image he he' hs (hs hx) (h2s hx) /-- Differentiability on a set is equivalent to differentiability in the extended charts. -/ theorem mdifferentiableOn_iff_of_mem_maximalAtlas' (he : e ∈ maximalAtlas I 1 M) (he' : e' ∈ maximalAtlas I' 1 M') (hs : s ⊆ e.source) (h2s : MapsTo f s e'.source) : MDifferentiableOn I I' f s ↔ DifferentiableOn 𝕜 (e'.extend I' ∘ f ∘ (e.extend I).symm) (e.extend I '' s) := (mdifferentiableOn_iff_of_mem_maximalAtlas he he' hs h2s).trans <| and_iff_right_of_imp fun h ↦ (e.continuousOn_writtenInExtend_iff hs h2s).1 h.continuousOn /-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it into a single chart, the smoothness of `f` on that set can be expressed by purely looking in these charts. Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure that this set lies in `(extChartAt I x).target`. -/ theorem mdifferentiableOn_iff_of_subset_source {x : M} {y : M'} (hs : s ⊆ (chartAt H x).source) (h2s : MapsTo f s (chartAt H' y).source) : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := mdifferentiableOn_iff_of_mem_maximalAtlas (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hs h2s /-- If the set where you want `f` to be smooth lies entirely in a single chart, and `f` maps it into a single chart, the smoothness of `f` on that set can be expressed by purely looking in these charts. Note: this lemma uses `extChartAt I x '' s` instead of `(extChartAt I x).symm ⁻¹' s` to ensure that this set lies in `(extChartAt I x).target`. -/ theorem mdifferentiableOn_iff_of_subset_source' {x : M} {y : M'} (hs : s ⊆ (extChartAt I x).source) (h2s : MapsTo f s (extChartAt I' y).source) : MDifferentiableOn I I' f s ↔ DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) (extChartAt I x '' s) := by rw [extChartAt_source] at hs h2s exact mdifferentiableOn_iff_of_mem_maximalAtlas' (chart_mem_maximalAtlas x) (chart_mem_maximalAtlas y) hs h2s /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart. -/ theorem mdifferentiableOn_iff : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ ∀ (x : M) (y : M'), DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (s ∩ f ⁻¹' (extChartAt I' y).source)) := by constructor · intro h refine ⟨fun x hx => (h x hx).1, fun x y z hz => ?_⟩ simp only [mfld_simps] at hz let w := (extChartAt I x).symm z have : w ∈ s := by simp only [w, hz, mfld_simps] specialize h w this have w1 : w ∈ (chartAt H x).source := by simp only [w, hz, mfld_simps] have w2 : f w ∈ (chartAt H' y).source := by simp only [w, hz, mfld_simps] convert ((mdifferentiableWithinAt_iff_of_mem_source w1 w2).mp h).2.mono _ · simp only [w, hz, mfld_simps] · mfld_set_tac · rintro ⟨hcont, hdiff⟩ x hx refine differentiableWithinAt_localInvariantProp.liftPropWithinAt_iff.mpr ?_ refine ⟨hcont x hx, ?_⟩ dsimp [DifferentiableWithinAtProp] convert hdiff x (f x) (extChartAt I x x) (by simp only [hx, mfld_simps]) using 1 mfld_set_tac /-- One can reformulate smoothness on a set as continuity on this set, and smoothness in any extended chart in the target. -/ theorem mdifferentiableOn_iff_target : MDifferentiableOn I I' f s ↔ ContinuousOn f s ∧ ∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (s ∩ f ⁻¹' (extChartAt I' y).source) := by simp only [mdifferentiableOn_iff, ModelWithCorners.source_eq, chartAt_self_eq, PartialHomeomorph.refl_partialEquiv, PartialEquiv.refl_trans, extChartAt, PartialHomeomorph.extend, Set.preimage_univ, Set.inter_univ, and_congr_right_iff] intro h constructor · refine fun h' y => ⟨?_, fun x _ => h' x y⟩ have h'' : ContinuousOn _ univ := (ModelWithCorners.continuous I').continuousOn convert (h''.comp_inter (chartAt H' y).continuousOn_toFun).comp_inter h simp · exact fun h' x y => (h' y).2 x 0 /-- One can reformulate smoothness as continuity and smoothness in any extended chart. -/ theorem mdifferentiable_iff : MDifferentiable I I' f ↔ Continuous f ∧ ∀ (x : M) (y : M'), DifferentiableOn 𝕜 (extChartAt I' y ∘ f ∘ (extChartAt I x).symm) ((extChartAt I x).target ∩ (extChartAt I x).symm ⁻¹' (f ⁻¹' (extChartAt I' y).source)) := by simp [← mdifferentiableOn_univ, mdifferentiableOn_iff, continuous_iff_continuousOn_univ] /-- One can reformulate smoothness as continuity and smoothness in any extended chart in the target. -/ theorem mdifferentiable_iff_target : MDifferentiable I I' f ↔ Continuous f ∧ ∀ y : M', MDifferentiableOn I 𝓘(𝕜, E') (extChartAt I' y ∘ f) (f ⁻¹' (extChartAt I' y).source) := by rw [← mdifferentiableOn_univ, mdifferentiableOn_iff_target] simp [continuous_iff_continuousOn_univ] end IsManifold /-! ### Deducing differentiability from smoothness -/ variable {n : WithTop ℕ∞} theorem ContMDiffWithinAt.mdifferentiableWithinAt (hf : ContMDiffWithinAt I I' n f s x) (hn : 1 ≤ n) : MDifferentiableWithinAt I I' f s x := by suffices h : MDifferentiableWithinAt I I' f (s ∩ f ⁻¹' (extChartAt I' (f x)).source) x by rwa [mdifferentiableWithinAt_inter'] at h apply hf.1.preimage_mem_nhdsWithin exact extChartAt_source_mem_nhds (f x) rw [mdifferentiableWithinAt_iff] exact ⟨hf.1.mono inter_subset_left, (hf.2.differentiableWithinAt (mod_cast hn)).mono (by mfld_set_tac)⟩ theorem ContMDiffAt.mdifferentiableAt (hf : ContMDiffAt I I' n f x) (hn : 1 ≤ n) : MDifferentiableAt I I' f x := mdifferentiableWithinAt_univ.1 <| ContMDiffWithinAt.mdifferentiableWithinAt hf hn theorem ContMDiff.mdifferentiableAt (hf : ContMDiff I I' n f) (hn : 1 ≤ n) : MDifferentiableAt I I' f x := hf.contMDiffAt.mdifferentiableAt hn theorem ContMDiff.mdifferentiableWithinAt (hf : ContMDiff I I' n f) (hn : 1 ≤ n) : MDifferentiableWithinAt I I' f s x := (hf.contMDiffAt.mdifferentiableAt hn).mdifferentiableWithinAt theorem ContMDiffOn.mdifferentiableOn (hf : ContMDiffOn I I' n f s) (hn : 1 ≤ n) : MDifferentiableOn I I' f s := fun x hx => (hf x hx).mdifferentiableWithinAt hn @[deprecated (since := "2024-11-20")] alias SmoothWithinAt.mdifferentiableWithinAt := ContMDiffWithinAt.mdifferentiableWithinAt theorem ContMDiff.mdifferentiable (hf : ContMDiff I I' n f) (hn : 1 ≤ n) : MDifferentiable I I' f := fun x => (hf x).mdifferentiableAt hn @[deprecated (since := "2024-11-20")] alias SmoothAt.mdifferentiableAt := ContMDiffAt.mdifferentiableAt @[deprecated (since := "2024-11-20")] alias SmoothOn.mdifferentiableOn := ContMDiffOn.mdifferentiableOn @[deprecated (since := "2024-11-20")] alias Smooth.mdifferentiable := ContMDiff.mdifferentiable @[deprecated (since := "2024-11-20")] alias Smooth.mdifferentiableAt := ContMDiff.mdifferentiableAt theorem MDifferentiableOn.continuousOn (h : MDifferentiableOn I I' f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem MDifferentiable.continuous (h : MDifferentiable I I' f) : Continuous f := continuous_iff_continuousAt.2 fun x => (h x).continuousAt @[deprecated (since := "2024-11-20")] alias Smooth.mdifferentiableWithinAt := ContMDiff.mdifferentiableWithinAt /-! ### Deriving continuity from differentiability on manifolds -/ theorem MDifferentiableWithinAt.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableWithinAt I I' f s x) (hg : MDifferentiableWithinAt I I'' g s x) : MDifferentiableWithinAt I (I'.prod I'') (fun x => (f x, g x)) s x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ @[deprecated (since := "2025-03-08")] alias MDifferentiableWithinAt.prod_mk := MDifferentiableWithinAt.prodMk theorem MDifferentiableAt.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableAt I I' f x) (hg : MDifferentiableAt I I'' g x) : MDifferentiableAt I (I'.prod I'') (fun x => (f x, g x)) x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ @[deprecated (since := "2025-03-08")] alias MDifferentiableAt.prod_mk := MDifferentiableAt.prodMk theorem MDifferentiableWithinAt.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiableWithinAt I 𝓘(𝕜, E') f s x) (hg : MDifferentiableWithinAt I 𝓘(𝕜, E'') g s x) : MDifferentiableWithinAt I 𝓘(𝕜, E' × E'') (fun x => (f x, g x)) s x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ @[deprecated (since := "2025-03-08")] alias MDifferentiableWithinAt.prod_mk_space := MDifferentiableWithinAt.prodMk_space theorem MDifferentiableAt.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiableAt I 𝓘(𝕜, E') f x) (hg : MDifferentiableAt I 𝓘(𝕜, E'') g x) : MDifferentiableAt I 𝓘(𝕜, E' × E'') (fun x => (f x, g x)) x := ⟨hf.1.prodMk hg.1, hf.2.prodMk hg.2⟩ @[deprecated (since := "2025-03-08")] alias MDifferentiableAt.prod_mk_space := MDifferentiableAt.prodMk_space theorem MDifferentiableOn.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiableOn I I' f s) (hg : MDifferentiableOn I I'' g s) : MDifferentiableOn I (I'.prod I'') (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk (hg x hx) @[deprecated (since := "2025-03-08")] alias MDifferentiableOn.prod_mk := MDifferentiableOn.prodMk theorem MDifferentiable.prodMk {f : M → M'} {g : M → M''} (hf : MDifferentiable I I' f) (hg : MDifferentiable I I'' g) : MDifferentiable I (I'.prod I'') fun x => (f x, g x) := fun x => (hf x).prodMk (hg x) @[deprecated (since := "2025-03-08")] alias MDifferentiable.prod_mk := MDifferentiable.prodMk theorem MDifferentiableOn.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiableOn I 𝓘(𝕜, E') f s) (hg : MDifferentiableOn I 𝓘(𝕜, E'') g s) : MDifferentiableOn I 𝓘(𝕜, E' × E'') (fun x => (f x, g x)) s := fun x hx => (hf x hx).prodMk_space (hg x hx) @[deprecated (since := "2025-03-08")] alias MDifferentiableOn.prod_mk_space := MDifferentiableOn.prodMk_space theorem MDifferentiable.prodMk_space {f : M → E'} {g : M → E''} (hf : MDifferentiable I 𝓘(𝕜, E') f) (hg : MDifferentiable I 𝓘(𝕜, E'') g) : MDifferentiable I 𝓘(𝕜, E' × E'') fun x => (f x, g x) := fun x => (hf x).prodMk_space (hg x) @[deprecated (since := "2025-03-08")] alias MDifferentiable.prod_mk_space := MDifferentiable.prodMk_space theorem writtenInExtChartAt_comp (h : ContinuousWithinAt f s x) : {y | writtenInExtChartAt I I'' x (g ∘ f) y = (writtenInExtChartAt I' I'' (f x) g ∘ writtenInExtChartAt I I' x f) y} ∈ 𝓝[(extChartAt I x).symm ⁻¹' s ∩ range I] (extChartAt I x) x := by apply @Filter.mem_of_superset _ _ (f ∘ (extChartAt I x).symm ⁻¹' (extChartAt I' (f x)).source) _ (extChartAt_preimage_mem_nhdsWithin (h.preimage_mem_nhdsWithin (extChartAt_source_mem_nhds _))) mfld_set_tac variable {f' f₀' f₁' : TangentSpace I x →L[𝕜] TangentSpace I' (f x)} {g' : TangentSpace I' (f x) →L[𝕜] TangentSpace I'' (g (f x))} /-- `UniqueMDiffWithinAt` achieves its goal: it implies the uniqueness of the derivative. -/ protected nonrec theorem UniqueMDiffWithinAt.eq (U : UniqueMDiffWithinAt I s x) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := by -- Porting note: didn't need `convert` because of finding instances by unification convert U.eq h.2 h₁.2 protected theorem UniqueMDiffOn.eq (U : UniqueMDiffOn I s) (hx : x ∈ s) (h : HasMFDerivWithinAt I I' f s x f') (h₁ : HasMFDerivWithinAt I I' f s x f₁') : f' = f₁' := UniqueMDiffWithinAt.eq (U _ hx) h h₁ /-! ### General lemmas on derivatives of functions between manifolds We mimic the API for functions between vector spaces -/ @[simp, mfld_simps] theorem mfderivWithin_univ : mfderivWithin I I' f univ = mfderiv I I' f := by ext x : 1 simp only [mfderivWithin, mfderiv, mfld_simps] rw [mdifferentiableWithinAt_univ] theorem mfderivWithin_zero_of_not_mdifferentiableWithinAt (h : ¬MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = 0 := by simp only [mfderivWithin, h, if_neg, not_false_iff] theorem mfderiv_zero_of_not_mdifferentiableAt (h : ¬MDifferentiableAt I I' f x) : mfderiv I I' f x = 0 := by simp only [mfderiv, h, if_neg, not_false_iff] theorem mdifferentiable_of_subsingleton [Subsingleton E] : MDifferentiable I I' f := by intro x have : Subsingleton H := I.injective.subsingleton have : DiscreteTopology M := discreteTopology H M simp only [mdifferentiableAt_iff, continuous_of_discreteTopology.continuousAt, true_and] exact (hasFDerivAt_of_subsingleton _ _).differentiableAt.differentiableWithinAt theorem mdifferentiableWithinAt_of_isInvertible_mfderivWithin (hf : (mfderivWithin I I' f s x).IsInvertible) : MDifferentiableWithinAt I I' f s x := by contrapose hf rw [mfderivWithin_zero_of_not_mdifferentiableWithinAt hf] contrapose! hf rcases ContinuousLinearMap.isInvertible_zero_iff.1 hf with ⟨hE, hF⟩ have : Subsingleton E := hE exact mdifferentiable_of_subsingleton.mdifferentiableAt.mdifferentiableWithinAt theorem mdifferentiableAt_of_isInvertible_mfderiv (hf : (mfderiv I I' f x).IsInvertible) : MDifferentiableAt I I' f x := by simp only [← mdifferentiableWithinAt_univ, ← mfderivWithin_univ] at hf ⊢ exact mdifferentiableWithinAt_of_isInvertible_mfderivWithin hf theorem HasMFDerivWithinAt.mono (h : HasMFDerivWithinAt I I' f t x f') (hst : s ⊆ t) : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousWithinAt.mono h.1 hst, HasFDerivWithinAt.mono h.2 (inter_subset_inter (preimage_mono hst) (Subset.refl _))⟩ theorem HasMFDerivAt.hasMFDerivWithinAt (h : HasMFDerivAt I I' f x f') : HasMFDerivWithinAt I I' f s x f' := ⟨ContinuousAt.continuousWithinAt h.1, HasFDerivWithinAt.mono h.2 inter_subset_right⟩ theorem HasMFDerivWithinAt.mdifferentiableWithinAt (h : HasMFDerivWithinAt I I' f s x f') : MDifferentiableWithinAt I I' f s x := ⟨h.1, ⟨f', h.2⟩⟩ theorem HasMFDerivAt.mdifferentiableAt (h : HasMFDerivAt I I' f x f') : MDifferentiableAt I I' f x := by rw [mdifferentiableAt_iff] exact ⟨h.1, ⟨f', h.2⟩⟩ @[simp, mfld_simps] theorem hasMFDerivWithinAt_univ : HasMFDerivWithinAt I I' f univ x f' ↔ HasMFDerivAt I I' f x f' := by simp only [HasMFDerivWithinAt, HasMFDerivAt, continuousWithinAt_univ, mfld_simps] theorem hasMFDerivAt_unique (h₀ : HasMFDerivAt I I' f x f₀') (h₁ : HasMFDerivAt I I' f x f₁') : f₀' = f₁' := by rw [← hasMFDerivWithinAt_univ] at h₀ h₁ exact (uniqueMDiffWithinAt_univ I).eq h₀ h₁ theorem hasMFDerivWithinAt_inter' (h : t ∈ 𝓝[s] x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter', continuousWithinAt_inter' h] exact extChartAt_preimage_mem_nhdsWithin h theorem hasMFDerivWithinAt_inter (h : t ∈ 𝓝 x) : HasMFDerivWithinAt I I' f (s ∩ t) x f' ↔ HasMFDerivWithinAt I I' f s x f' := by rw [HasMFDerivWithinAt, HasMFDerivWithinAt, extChartAt_preimage_inter_eq, hasFDerivWithinAt_inter, continuousWithinAt_inter h] exact extChartAt_preimage_mem_nhds h theorem HasMFDerivWithinAt.union (hs : HasMFDerivWithinAt I I' f s x f') (ht : HasMFDerivWithinAt I I' f t x f') : HasMFDerivWithinAt I I' f (s ∪ t) x f' := by constructor · exact ContinuousWithinAt.union hs.1 ht.1 · convert HasFDerivWithinAt.union hs.2 ht.2 using 1 simp only [union_inter_distrib_right, preimage_union] theorem HasMFDerivWithinAt.mono_of_mem_nhdsWithin (h : HasMFDerivWithinAt I I' f s x f') (ht : s ∈ 𝓝[t] x) : HasMFDerivWithinAt I I' f t x f' := (hasMFDerivWithinAt_inter' ht).1 (h.mono inter_subset_right) @[deprecated (since := "2024-10-31")] alias HasMFDerivWithinAt.mono_of_mem := HasMFDerivWithinAt.mono_of_mem_nhdsWithin theorem HasMFDerivWithinAt.hasMFDerivAt (h : HasMFDerivWithinAt I I' f s x f') (hs : s ∈ 𝓝 x) : HasMFDerivAt I I' f x f' := by rwa [← univ_inter s, hasMFDerivWithinAt_inter hs, hasMFDerivWithinAt_univ] at h theorem MDifferentiableWithinAt.hasMFDerivWithinAt (h : MDifferentiableWithinAt I I' f s x) : HasMFDerivWithinAt I I' f s x (mfderivWithin I I' f s x) := by refine ⟨h.1, ?_⟩ simp only [mfderivWithin, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.2 theorem mdifferentiableWithinAt_iff_exists_hasMFDerivWithinAt : MDifferentiableWithinAt I I' f s x ↔ ∃ f', HasMFDerivWithinAt I I' f s x f' := by refine ⟨fun h ↦ ⟨mfderivWithin I I' f s x, h.hasMFDerivWithinAt⟩, ?_⟩ rintro ⟨f', hf'⟩ exact hf'.mdifferentiableWithinAt theorem MDifferentiableWithinAt.mono_of_mem_nhdsWithin (h : MDifferentiableWithinAt I I' f s x) {t : Set M} (hst : s ∈ 𝓝[t] x) : MDifferentiableWithinAt I I' f t x := (h.hasMFDerivWithinAt.mono_of_mem_nhdsWithin hst).mdifferentiableWithinAt theorem MDifferentiableWithinAt.congr_nhds (h : MDifferentiableWithinAt I I' f s x) {t : Set M} (hst : 𝓝[s] x = 𝓝[t] x) : MDifferentiableWithinAt I I' f t x := h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin theorem mdifferentiableWithinAt_congr_nhds {t : Set M} (hst : 𝓝[s] x = 𝓝[t] x) : MDifferentiableWithinAt I I' f s x ↔ MDifferentiableWithinAt I I' f t x := ⟨fun h => h.congr_nhds hst, fun h => h.congr_nhds hst.symm⟩ protected theorem MDifferentiableWithinAt.mfderivWithin (h : MDifferentiableWithinAt I I' f s x) : mfderivWithin I I' f s x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f :) ((extChartAt I x).symm ⁻¹' s ∩ range I) ((extChartAt I x) x) := by simp only [mfderivWithin, h, if_pos] theorem MDifferentiableAt.hasMFDerivAt (h : MDifferentiableAt I I' f x) : HasMFDerivAt I I' f x (mfderiv I I' f x) := by refine ⟨h.continuousAt, ?_⟩ simp only [mfderiv, h, if_pos, mfld_simps] exact DifferentiableWithinAt.hasFDerivWithinAt h.differentiableWithinAt_writtenInExtChartAt protected theorem MDifferentiableAt.mfderiv (h : MDifferentiableAt I I' f x) : mfderiv I I' f x = fderivWithin 𝕜 (writtenInExtChartAt I I' x f :) (range I) ((extChartAt I x) x) := by simp only [mfderiv, h, if_pos] protected theorem HasMFDerivAt.mfderiv (h : HasMFDerivAt I I' f x f') : mfderiv I I' f x = f' := (hasMFDerivAt_unique h h.mdifferentiableAt.hasMFDerivAt).symm protected theorem HasMFDerivWithinAt.mfderivWithin (h : HasMFDerivWithinAt I I' f s x f') (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = f' := by ext rw [hxs.eq h h.mdifferentiableWithinAt.hasMFDerivWithinAt] theorem HasMFDerivWithinAt.mfderivWithin_eq_zero (h : HasMFDerivWithinAt I I' f s x 0) : mfderivWithin I I' f s x = 0 := by
simp only [mfld_simps, mfderivWithin, h.mdifferentiableWithinAt, ↓reduceIte] simp only [HasMFDerivWithinAt, mfld_simps] at h rw [fderivWithin, if_pos] exact h.2 theorem MDifferentiable.mfderivWithin (h : MDifferentiableAt I I' f x) (hxs : UniqueMDiffWithinAt I s x) : mfderivWithin I I' f s x = mfderiv I I' f x := by apply HasMFDerivWithinAt.mfderivWithin _ hxs
Mathlib/Geometry/Manifold/MFDeriv/Basic.lean
755
762
/- Copyright (c) 2021 Alena Gusakov, Bhavik Mehta, Kyle Miller. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alena Gusakov, Bhavik Mehta, Kyle Miller -/ import Mathlib.Combinatorics.Hall.Finite import Mathlib.CategoryTheory.CofilteredSystem import Mathlib.Data.Rel /-! # Hall's Marriage Theorem Given a list of finite subsets $X_1, X_2, \dots, X_n$ of some given set $S$, P. Hall in [Hall1935] gave a necessary and sufficient condition for there to be a list of distinct elements $x_1, x_2, \dots, x_n$ with $x_i\in X_i$ for each $i$: it is when for each $k$, the union of every $k$ of these subsets has at least $k$ elements. Rather than a list of finite subsets, one may consider indexed families `t : ι → Finset α` of finite subsets with `ι` a `Fintype`, and then the list of distinct representatives is given by an injective function `f : ι → α` such that `∀ i, f i ∈ t i`, called a *matching*. This version is formalized as `Finset.all_card_le_biUnion_card_iff_exists_injective'` in a separate module. The theorem can be generalized to remove the constraint that `ι` be a `Fintype`. As observed in [Halpern1966], one may use the constrained version of the theorem in a compactness argument to remove this constraint. The formulation of compactness we use is that inverse limits of nonempty finite sets are nonempty (`nonempty_sections_of_finite_inverse_system`), which uses the Tychonoff theorem. The core of this module is constructing the inverse system: for every finite subset `ι'` of `ι`, we can consider the matchings on the restriction of the indexed family `t` to `ι'`. ## Main statements * `Finset.all_card_le_biUnion_card_iff_exists_injective` is in terms of `t : ι → Finset α`. * `Fintype.all_card_le_rel_image_card_iff_exists_injective` is in terms of a relation `r : α → β → Prop` such that `Rel.image r {a}` is a finite set for all `a : α`. * `Fintype.all_card_le_filter_rel_iff_exists_injective` is in terms of a relation `r : α → β → Prop` on finite types, with the Hall condition given in terms of `finset.univ.filter`. ## TODO * The statement of the theorem in terms of bipartite graphs is in preparation. ## Tags Hall's Marriage Theorem, indexed families -/ open Finset Function CategoryTheory universe u v /-- The set of matchings for `t` when restricted to a `Finset` of `ι`. -/ def hallMatchingsOn {ι : Type u} {α : Type v} (t : ι → Finset α) (ι' : Finset ι) := { f : ι' → α | Function.Injective f ∧ ∀ (x : {x // x ∈ ι'}), f x ∈ t x } /-- Given a matching on a finset, construct the restriction of that matching to a subset. -/ def hallMatchingsOn.restrict {ι : Type u} {α : Type v} (t : ι → Finset α) {ι' ι'' : Finset ι} (h : ι' ⊆ ι'') (f : hallMatchingsOn t ι'') : hallMatchingsOn t ι' := by refine ⟨fun i => f.val ⟨i, h i.property⟩, ?_⟩ obtain ⟨hinj, hc⟩ := f.property refine ⟨?_, fun i => hc ⟨i, h i.property⟩⟩ rintro ⟨i, hi⟩ ⟨j, hj⟩ hh simpa only [Subtype.mk_eq_mk] using hinj hh /-- When the Hall condition is satisfied, the set of matchings on a finite set is nonempty. This is where `Finset.all_card_le_biUnion_card_iff_existsInjective'` comes into the argument. -/ theorem hallMatchingsOn.nonempty {ι : Type u} {α : Type v} [DecidableEq α] (t : ι → Finset α) (h : ∀ s : Finset ι, #s ≤ #(s.biUnion t)) (ι' : Finset ι) : Nonempty (hallMatchingsOn t ι') := by classical refine ⟨Classical.indefiniteDescription _ ?_⟩ apply (all_card_le_biUnion_card_iff_existsInjective' fun i : ι' => t i).mp intro s' convert h (s'.image (↑)) using 1 · simp only [card_image_of_injective s' Subtype.coe_injective] · rw [image_biUnion] /-- This is the `hallMatchingsOn` sets assembled into a directed system. -/ def hallMatchingsFunctor {ι : Type u} {α : Type v} (t : ι → Finset α) : (Finset ι)ᵒᵖ ⥤ Type max u v where obj ι' := hallMatchingsOn t ι'.unop map {_ _} g f := hallMatchingsOn.restrict t (CategoryTheory.leOfHom g.unop) f instance hallMatchingsOn.finite {ι : Type u} {α : Type v} (t : ι → Finset α) (ι' : Finset ι) : Finite (hallMatchingsOn t ι') := by classical rw [hallMatchingsOn] let g : hallMatchingsOn t ι' → ι' → ι'.biUnion t := by rintro f i refine ⟨f.val i, ?_⟩ rw [mem_biUnion] exact ⟨i, i.property, f.property.2 i⟩ apply Finite.of_injective g intro f f' h ext a rw [funext_iff] at h simpa [g] using h a /-- This is the version of **Hall's Marriage Theorem** in terms of indexed families of finite sets `t : ι → Finset α`. It states that there is a set of distinct representatives if and only if every union of `k` of the sets has at least `k` elements. Recall that `s.biUnion t` is the union of all the sets `t i` for `i ∈ s`. This theorem is bootstrapped from `Finset.all_card_le_biUnion_card_iff_exists_injective'`, which has the additional constraint that `ι` is a `Fintype`. -/ theorem Finset.all_card_le_biUnion_card_iff_exists_injective {ι : Type u} {α : Type v} [DecidableEq α] (t : ι → Finset α) : (∀ s : Finset ι, #s ≤ #(s.biUnion t)) ↔ ∃ f : ι → α, Function.Injective f ∧ ∀ x, f x ∈ t x := by constructor · intro h -- Set up the functor haveI : ∀ ι' : (Finset ι)ᵒᵖ, Nonempty ((hallMatchingsFunctor t).obj ι') := fun ι' => hallMatchingsOn.nonempty t h ι'.unop classical haveI : ∀ ι' : (Finset ι)ᵒᵖ, Finite ((hallMatchingsFunctor t).obj ι') := by intro ι' rw [hallMatchingsFunctor] infer_instance -- Apply the compactness argument obtain ⟨u, hu⟩ := nonempty_sections_of_finite_inverse_system (hallMatchingsFunctor t) -- Interpret the resulting section of the inverse limit refine ⟨?_, ?_, ?_⟩ ·-- Build the matching function from the section exact fun i => (u (Opposite.op ({i} : Finset ι))).val ⟨i, by simp only [Opposite.unop_op, mem_singleton]⟩ · -- Show that it is injective intro i i' have subi : ({i} : Finset ι) ⊆ {i, i'} := by simp have subi' : ({i'} : Finset ι) ⊆ {i, i'} := by simp rw [← Finset.le_iff_subset] at subi subi' simp only rw [← hu (CategoryTheory.homOfLE subi).op, ← hu (CategoryTheory.homOfLE subi').op] let uii' := u (Opposite.op ({i, i'} : Finset ι)) exact fun h => Subtype.mk_eq_mk.mp (uii'.property.1 h) · -- Show that it maps each index to the corresponding finite set intro i apply (u (Opposite.op ({i} : Finset ι))).property.2 · -- The reverse direction is a straightforward cardinality argument rintro ⟨f, hf₁, hf₂⟩ s rw [← Finset.card_image_of_injective s hf₁] apply Finset.card_le_card intro rw [Finset.mem_image, Finset.mem_biUnion] rintro ⟨x, hx, rfl⟩ exact ⟨x, hx, hf₂ x⟩ /-- Given a relation such that the image of every singleton set is finite, then the image of every finite set is finite. -/ instance {α : Type u} {β : Type v} [DecidableEq β] (r : α → β → Prop) [∀ a : α, Fintype (Rel.image r {a})] (A : Finset α) : Fintype (Rel.image r A) := by have h : Rel.image r A = (A.biUnion fun a => (Rel.image r {a}).toFinset : Set β) := by ext simp [Rel.image] rw [h] apply FinsetCoe.fintype /-- This is a version of **Hall's Marriage Theorem** in terms of a relation between types `α` and `β` such that `α` is finite and the image of each `x : α` is finite (it suffices for `β` to be finite; see `Fintype.all_card_le_filter_rel_iff_exists_injective`). There is a transversal of the relation (an injective function `α → β` whose graph is a subrelation of the relation) iff every subset of `k` terms of `α` is related to at least `k` terms of `β`. Note: if `[Fintype β]`, then there exist instances for `[∀ (a : α), Fintype (Rel.image r {a})]`. -/ theorem Fintype.all_card_le_rel_image_card_iff_exists_injective {α : Type u} {β : Type v} [DecidableEq β] (r : α → β → Prop) [∀ a : α, Fintype (Rel.image r {a})] : (∀ A : Finset α, #A ≤ Fintype.card (Rel.image r A)) ↔ ∃ f : α → β, Function.Injective f ∧ ∀ x, r x (f x) := by let r' a := (Rel.image r {a}).toFinset have h : ∀ A : Finset α, Fintype.card (Rel.image r A) = #(A.biUnion r') := by intro A rw [← Set.toFinset_card] apply congr_arg ext b simp [r', Rel.image] have h' : ∀ (f : α → β) (x), r x (f x) ↔ f x ∈ r' x := by simp [r', Rel.image] simp only [h, h'] apply Finset.all_card_le_biUnion_card_iff_exists_injective -- TODO: decidable_pred makes Yael sad. When an appropriate decidable_rel-like exists, fix it. /-- This is a version of **Hall's Marriage Theorem** in terms of a relation to a finite type. There is a transversal of the relation (an injective function `α → β` whose graph is a subrelation of the relation) iff every subset of `k` terms of `α` is related to at least `k` terms of `β`. It is like `Fintype.all_card_le_rel_image_card_iff_exists_injective` but uses `Finset.filter` rather than `Rel.image`. -/ theorem Fintype.all_card_le_filter_rel_iff_exists_injective {α : Type u} {β : Type v} [Fintype β] (r : α → β → Prop) [∀ a, DecidablePred (r a)] : (∀ A : Finset α, #A ≤ #{b | ∃ a ∈ A, r a b}) ↔ ∃ f : α → β, Injective f ∧ ∀ x, r x (f x) := by haveI := Classical.decEq β let r' a : Finset β := {b | r a b} have h : ∀ A : Finset α, ({b | ∃ a ∈ A, r a b} : Finset _) = A.biUnion r' := by intro A ext b simp [r'] have h' : ∀ (f : α → β) (x), r x (f x) ↔ f x ∈ r' x := by simp [r'] simp_rw [h, h'] apply Finset.all_card_le_biUnion_card_iff_exists_injective
Mathlib/Combinatorics/Hall/Basic.lean
213
225
/- Copyright (c) 2021 Kalle Kytölä. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kalle Kytölä, Moritz Doll -/ import Mathlib.LinearAlgebra.BilinearMap import Mathlib.Topology.Algebra.Module.LinearMap import Mathlib.Topology.Algebra.Module.WeakBilin /-! # Weak dual topology We continue in the setting of `Mathlib.Topology.Algebra.Module.WeakBilin`, which defines the weak topology given two vector spaces `E` and `F` over a commutative semiring `𝕜` and a bilinear form `B : E →ₗ[𝕜] F →ₗ[𝕜] 𝕜`. The weak topology on `E` is the coarsest topology such that for all `y : F` every map `fun x => B x y` is continuous. In this file, we consider two special cases. In the case that `F = E →L[𝕜] 𝕜` and `B` being the canonical pairing, we obtain the weak-* topology, `WeakDual 𝕜 E := (E →L[𝕜] 𝕜)`. Interchanging the arguments in the bilinear form yields the weak topology `WeakSpace 𝕜 E := E`. ## Main definitions The main definitions are the types `WeakDual 𝕜 E` and `WeakSpace 𝕜 E`, with the respective topology instances on it. * `WeakDual 𝕜 E` is a type synonym for `Dual 𝕜 E` (when the latter is defined): both are equal to the type `E →L[𝕜] 𝕜` of continuous linear maps from a module `E` over `𝕜` to the ring `𝕜`. * The instance `WeakDual.instTopologicalSpace` is the weak-* topology on `WeakDual 𝕜 E`, i.e., the coarsest topology making the evaluation maps at all `z : E` continuous. * `WeakSpace 𝕜 E` is a type synonym for `E` (when the latter is defined). * The instance `WeakSpace.instTopologicalSpace` is the weak topology on `E`, i.e., the coarsest topology such that all `v : dual 𝕜 E` remain continuous. ## Notations No new notation is introduced. ## References * [H. H. Schaefer, *Topological Vector Spaces*][schaefer1966] ## Tags weak-star, weak dual, duality -/ noncomputable section open Filter open Topology variable {α 𝕜 𝕝 E F : Type*} /-- The canonical pairing of a vector space and its topological dual. -/ def topDualPairing (𝕜 E) [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] [ContinuousConstSMul 𝕜 𝕜] : (E →L[𝕜] 𝕜) →ₗ[𝕜] E →ₗ[𝕜] 𝕜 := ContinuousLinearMap.coeLM 𝕜 theorem topDualPairing_apply [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] [ContinuousConstSMul 𝕜 𝕜] (v : E →L[𝕜] 𝕜) (x : E) : topDualPairing 𝕜 E v x = v x := rfl /-- The weak star topology is the topology coarsest topology on `E →L[𝕜] 𝕜` such that all functionals `fun v => v x` are continuous. -/ def WeakDual (𝕜 E : Type*) [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] [ContinuousConstSMul 𝕜 𝕜] [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] := WeakBilin (topDualPairing 𝕜 E) namespace WeakDual section Semiring variable [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] variable [ContinuousConstSMul 𝕜 𝕜] variable [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] -- The following instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance instAddCommMonoid : AddCommMonoid (WeakDual 𝕜 E) := WeakBilin.instAddCommMonoid (topDualPairing 𝕜 E) instance instModule : Module 𝕜 (WeakDual 𝕜 E) := WeakBilin.instModule (topDualPairing 𝕜 E) instance instTopologicalSpace : TopologicalSpace (WeakDual 𝕜 E) := WeakBilin.instTopologicalSpace (topDualPairing 𝕜 E) instance instContinuousAdd : ContinuousAdd (WeakDual 𝕜 E) := WeakBilin.instContinuousAdd (topDualPairing 𝕜 E) instance instInhabited : Inhabited (WeakDual 𝕜 E) := ContinuousLinearMap.inhabited instance instFunLike : FunLike (WeakDual 𝕜 E) E 𝕜 := ContinuousLinearMap.funLike instance instContinuousLinearMapClass : ContinuousLinearMapClass (WeakDual 𝕜 E) 𝕜 E 𝕜 := ContinuousLinearMap.continuousSemilinearMapClass /-- If a monoid `M` distributively continuously acts on `𝕜` and this action commutes with multiplication on `𝕜`, then it acts on `WeakDual 𝕜 E`. -/ instance instMulAction (M) [Monoid M] [DistribMulAction M 𝕜] [SMulCommClass 𝕜 M 𝕜] [ContinuousConstSMul M 𝕜] : MulAction M (WeakDual 𝕜 E) := ContinuousLinearMap.mulAction /-- If a monoid `M` distributively continuously acts on `𝕜` and this action commutes with multiplication on `𝕜`, then it acts distributively on `WeakDual 𝕜 E`. -/ instance instDistribMulAction (M) [Monoid M] [DistribMulAction M 𝕜] [SMulCommClass 𝕜 M 𝕜] [ContinuousConstSMul M 𝕜] : DistribMulAction M (WeakDual 𝕜 E) := ContinuousLinearMap.distribMulAction /-- If `𝕜` is a topological module over a semiring `R` and scalar multiplication commutes with the multiplication on `𝕜`, then `WeakDual 𝕜 E` is a module over `R`. -/ instance instModule' (R) [Semiring R] [Module R 𝕜] [SMulCommClass 𝕜 R 𝕜] [ContinuousConstSMul R 𝕜] : Module R (WeakDual 𝕜 E) := ContinuousLinearMap.module instance instContinuousConstSMul (M) [Monoid M] [DistribMulAction M 𝕜] [SMulCommClass 𝕜 M 𝕜] [ContinuousConstSMul M 𝕜] : ContinuousConstSMul M (WeakDual 𝕜 E) := ⟨fun m => continuous_induced_rng.2 <| (WeakBilin.coeFn_continuous (topDualPairing 𝕜 E)).const_smul m⟩ /-- If a monoid `M` distributively continuously acts on `𝕜` and this action commutes with multiplication on `𝕜`, then it continuously acts on `WeakDual 𝕜 E`. -/ instance instContinuousSMul (M) [Monoid M] [DistribMulAction M 𝕜] [SMulCommClass 𝕜 M 𝕜] [TopologicalSpace M] [ContinuousSMul M 𝕜] : ContinuousSMul M (WeakDual 𝕜 E) := ⟨continuous_induced_rng.2 <| continuous_fst.smul ((WeakBilin.coeFn_continuous (topDualPairing 𝕜 E)).comp continuous_snd)⟩ theorem coeFn_continuous : Continuous fun (x : WeakDual 𝕜 E) y => x y := continuous_induced_dom theorem eval_continuous (y : E) : Continuous fun x : WeakDual 𝕜 E => x y := continuous_pi_iff.mp coeFn_continuous y theorem continuous_of_continuous_eval [TopologicalSpace α] {g : α → WeakDual 𝕜 E} (h : ∀ y, Continuous fun a => (g a) y) : Continuous g := continuous_induced_rng.2 (continuous_pi_iff.mpr h) instance instT2Space [T2Space 𝕜] : T2Space (WeakDual 𝕜 E) := (WeakBilin.isEmbedding ContinuousLinearMap.coe_injective).t2Space end Semiring section Ring variable [CommRing 𝕜] [TopologicalSpace 𝕜] [IsTopologicalAddGroup 𝕜] [ContinuousConstSMul 𝕜 𝕜] variable [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] instance instAddCommGroup : AddCommGroup (WeakDual 𝕜 E) := WeakBilin.instAddCommGroup (topDualPairing 𝕜 E) instance instIsTopologicalAddGroup : IsTopologicalAddGroup (WeakDual 𝕜 E) := WeakBilin.instIsTopologicalAddGroup (topDualPairing 𝕜 E) end Ring end WeakDual /-- The weak topology is the topology coarsest topology on `E` such that all functionals `fun x => v x` are continuous. -/ def WeakSpace (𝕜 E) [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] [ContinuousConstSMul 𝕜 𝕜] [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] := WeakBilin (topDualPairing 𝕜 E).flip section Semiring variable [CommSemiring 𝕜] [TopologicalSpace 𝕜] [ContinuousAdd 𝕜] variable [ContinuousConstSMul 𝕜 𝕜] variable [AddCommMonoid E] [Module 𝕜 E] [TopologicalSpace E] namespace WeakSpace -- The following instances should be constructed by a deriving handler. -- https://github.com/leanprover-community/mathlib4/issues/380 instance instAddCommMonoid : AddCommMonoid (WeakSpace 𝕜 E) := WeakBilin.instAddCommMonoid (topDualPairing 𝕜 E).flip instance instModule : Module 𝕜 (WeakSpace 𝕜 E) := WeakBilin.instModule (topDualPairing 𝕜 E).flip instance instTopologicalSpace : TopologicalSpace (WeakSpace 𝕜 E) := WeakBilin.instTopologicalSpace (topDualPairing 𝕜 E).flip instance instContinuousAdd : ContinuousAdd (WeakSpace 𝕜 E) := WeakBilin.instContinuousAdd (topDualPairing 𝕜 E).flip instance instModule' [CommSemiring 𝕝] [Module 𝕝 E] : Module 𝕝 (WeakSpace 𝕜 E) := WeakBilin.instModule' (topDualPairing 𝕜 E).flip instance instIsScalarTower [CommSemiring 𝕝] [Module 𝕝 𝕜] [Module 𝕝 E] [IsScalarTower 𝕝 𝕜 E] : IsScalarTower 𝕝 𝕜 (WeakSpace 𝕜 E) := WeakBilin.instIsScalarTower (topDualPairing 𝕜 E).flip variable [AddCommMonoid F] [Module 𝕜 F] [TopologicalSpace F] /-- A continuous linear map from `E` to `F` is still continuous when `E` and `F` are equipped with their weak topologies. -/ def map (f : E →L[𝕜] F) : WeakSpace 𝕜 E →L[𝕜] WeakSpace 𝕜 F := { f with cont := WeakBilin.continuous_of_continuous_eval _ fun l => WeakBilin.eval_continuous _ (l ∘L f) } theorem map_apply (f : E →L[𝕜] F) (x : E) : WeakSpace.map f x = f x := rfl @[simp] theorem coe_map (f : E →L[𝕜] F) : (WeakSpace.map f : E → F) = f := rfl end WeakSpace variable (𝕜 E) in /-- There is a canonical map `E → WeakSpace 𝕜 E` (the "identity" mapping). It is a linear equivalence. -/ def toWeakSpace : E ≃ₗ[𝕜] WeakSpace 𝕜 E := LinearEquiv.refl 𝕜 E variable (𝕜 E) in /-- For a topological vector space `E`, "identity mapping" `E → WeakSpace 𝕜 E` is continuous. This definition implements it as a continuous linear map. -/ def toWeakSpaceCLM : E →L[𝕜] WeakSpace 𝕜 E where __ := toWeakSpace 𝕜 E cont := by apply WeakBilin.continuous_of_continuous_eval exact ContinuousLinearMap.continuous variable (𝕜 E) in @[simp] theorem toWeakSpaceCLM_eq_toWeakSpace (x : E) : toWeakSpaceCLM 𝕜 E x = toWeakSpace 𝕜 E x := by rfl theorem toWeakSpaceCLM_bijective : Function.Bijective (toWeakSpaceCLM 𝕜 E) := (toWeakSpace 𝕜 E).bijective /-- The canonical map from `WeakSpace 𝕜 E` to `E` is an open map. -/ theorem isOpenMap_toWeakSpace_symm : IsOpenMap (toWeakSpace 𝕜 E).symm := IsOpenMap.of_inverse (toWeakSpaceCLM 𝕜 E).cont (toWeakSpace 𝕜 E).left_inv (toWeakSpace 𝕜 E).right_inv /-- A set in `E` which is open in the weak topology is open. -/ theorem WeakSpace.isOpen_of_isOpen (V : Set E) (hV : IsOpen ((toWeakSpaceCLM 𝕜 E) '' V : Set (WeakSpace 𝕜 E))) : IsOpen V := by simpa [Set.image_image] using isOpenMap_toWeakSpace_symm _ hV theorem tendsto_iff_forall_eval_tendsto_topDualPairing {l : Filter α} {f : α → WeakDual 𝕜 E} {x : WeakDual 𝕜 E} : Tendsto f l (𝓝 x) ↔ ∀ y, Tendsto (fun i => topDualPairing 𝕜 E (f i) y) l (𝓝 (topDualPairing 𝕜 E x y)) := WeakBilin.tendsto_iff_forall_eval_tendsto _ ContinuousLinearMap.coe_injective end Semiring section Ring namespace WeakSpace variable [CommRing 𝕜] [TopologicalSpace 𝕜] [IsTopologicalAddGroup 𝕜] [ContinuousConstSMul 𝕜 𝕜] variable [AddCommGroup E] [Module 𝕜 E] [TopologicalSpace E] [IsTopologicalAddGroup E] instance instAddCommGroup : AddCommGroup (WeakSpace 𝕜 E) := WeakBilin.instAddCommGroup (topDualPairing 𝕜 E).flip instance instIsTopologicalAddGroup : IsTopologicalAddGroup (WeakSpace 𝕜 E) := WeakBilin.instIsTopologicalAddGroup (topDualPairing 𝕜 E).flip end WeakSpace end Ring
Mathlib/Topology/Algebra/Module/WeakDual.lean
360
362
/- Copyright (c) 2018 Reid Barton. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Reid Barton -/ import Mathlib.Topology.Hom.ContinuousEval import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Topology.Separation.Regular /-! # The compact-open topology In this file, we define the compact-open topology on the set of continuous maps between two topological spaces. ## Main definitions * `ContinuousMap.compactOpen` is the compact-open topology on `C(X, Y)`. It is declared as an instance. * `ContinuousMap.coev` is the coevaluation map `Y → C(X, Y × X)`. It is always continuous. * `ContinuousMap.curry` is the currying map `C(X × Y, Z) → C(X, C(Y, Z))`. This map always exists and it is continuous as long as `X × Y` is locally compact. * `ContinuousMap.uncurry` is the uncurrying map `C(X, C(Y, Z)) → C(X × Y, Z)`. For this map to exist, we need `Y` to be locally compact. If `X` is also locally compact, then this map is continuous. * `Homeomorph.curry` combines the currying and uncurrying operations into a homeomorphism `C(X × Y, Z) ≃ₜ C(X, C(Y, Z))`. This homeomorphism exists if `X` and `Y` are locally compact. ## Tags compact-open, curry, function space -/ open Set Filter TopologicalSpace Topology namespace ContinuousMap section CompactOpen variable {α X Y Z T : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] [TopologicalSpace T] variable {K : Set X} {U : Set Y} /-- The compact-open topology on the space of continuous maps `C(X, Y)`. -/ instance compactOpen : TopologicalSpace C(X, Y) := .generateFrom <| image2 (fun K U ↦ {f | MapsTo f K U}) {K | IsCompact K} {U | IsOpen U} /-- Definition of `ContinuousMap.compactOpen`. -/ theorem compactOpen_eq : @compactOpen X Y _ _ = .generateFrom (image2 (fun K U ↦ {f | MapsTo f K U}) {K | IsCompact K} {t | IsOpen t}) := rfl theorem isOpen_setOf_mapsTo (hK : IsCompact K) (hU : IsOpen U) : IsOpen {f : C(X, Y) | MapsTo f K U} := isOpen_generateFrom_of_mem <| mem_image2_of_mem hK hU lemma eventually_mapsTo {f : C(X, Y)} (hK : IsCompact K) (hU : IsOpen U) (h : MapsTo f K U) : ∀ᶠ g : C(X, Y) in 𝓝 f, MapsTo g K U := (isOpen_setOf_mapsTo hK hU).mem_nhds h lemma nhds_compactOpen (f : C(X, Y)) : 𝓝 f = ⨅ (K : Set X) (_ : IsCompact K) (U : Set Y) (_ : IsOpen U) (_ : MapsTo f K U), 𝓟 {g : C(X, Y) | MapsTo g K U} := by simp_rw [compactOpen_eq, nhds_generateFrom, mem_setOf_eq, @and_comm (f ∈ _), iInf_and, ← image_prod, iInf_image, biInf_prod, mem_setOf_eq] lemma tendsto_nhds_compactOpen {l : Filter α} {f : α → C(Y, Z)} {g : C(Y, Z)} : Tendsto f l (𝓝 g) ↔ ∀ K, IsCompact K → ∀ U, IsOpen U → MapsTo g K U → ∀ᶠ a in l, MapsTo (f a) K U := by simp [nhds_compactOpen] lemma continuous_compactOpen {f : X → C(Y, Z)} : Continuous f ↔ ∀ K, IsCompact K → ∀ U, IsOpen U → IsOpen {x | MapsTo (f x) K U} := continuous_generateFrom_iff.trans forall_mem_image2 protected lemma hasBasis_nhds (f : C(X, Y)) : (𝓝 f).HasBasis (fun S : Set (Set X × Set Y) ↦ S.Finite ∧ ∀ K U, (K, U) ∈ S → IsCompact K ∧ IsOpen U ∧ MapsTo f K U) (⋂ KU ∈ ·, {g : C(X, Y) | MapsTo g KU.1 KU.2}) := by refine ⟨fun s ↦ ?_⟩ simp_rw [nhds_compactOpen, iInf_comm.{_, 0, _ + 1}, iInf_prod', iInf_and'] simp [mem_biInf_principal, and_assoc] protected lemma mem_nhds_iff {f : C(X, Y)} {s : Set C(X, Y)} : s ∈ 𝓝 f ↔ ∃ S : Set (Set X × Set Y), S.Finite ∧ (∀ K U, (K, U) ∈ S → IsCompact K ∧ IsOpen U ∧ MapsTo f K U) ∧ {g : C(X, Y) | ∀ K U, (K, U) ∈ S → MapsTo g K U} ⊆ s := by simp [f.hasBasis_nhds.mem_iff, ← setOf_forall, and_assoc] section Functorial /-- `C(X, ·)` is a functor. -/ theorem continuous_postcomp (g : C(Y, Z)) : Continuous (ContinuousMap.comp g : C(X, Y) → C(X, Z)) := continuous_compactOpen.2 fun _K hK _U hU ↦ isOpen_setOf_mapsTo hK (hU.preimage g.2) /-- If `g : C(Y, Z)` is a topology inducing map, then the composition `ContinuousMap.comp g : C(X, Y) → C(X, Z)` is a topology inducing map too. -/ theorem isInducing_postcomp (g : C(Y, Z)) (hg : IsInducing g) : IsInducing (g.comp : C(X, Y) → C(X, Z)) where eq_induced := by simp only [compactOpen_eq, induced_generateFrom_eq, image_image2, hg.setOf_isOpen, image2_image_right, MapsTo, mem_preimage, preimage_setOf_eq, comp_apply] @[deprecated (since := "2024-10-28")] alias inducing_postcomp := isInducing_postcomp /-- If `g : C(Y, Z)` is a topological embedding, then the composition `ContinuousMap.comp g : C(X, Y) → C(X, Z)` is an embedding too. -/ theorem isEmbedding_postcomp (g : C(Y, Z)) (hg : IsEmbedding g) : IsEmbedding (g.comp : C(X, Y) → C(X, Z)) := ⟨isInducing_postcomp g hg.1, fun _ _ ↦ (cancel_left hg.2).1⟩ @[deprecated (since := "2024-10-26")] alias embedding_postcomp := isEmbedding_postcomp /-- `C(·, Z)` is a functor. -/ @[continuity, fun_prop] theorem continuous_precomp (f : C(X, Y)) : Continuous (fun g => g.comp f : C(Y, Z) → C(X, Z)) := continuous_compactOpen.2 fun K hK U hU ↦ by simpa only [mapsTo_image_iff] using isOpen_setOf_mapsTo (hK.image f.2) hU variable (Z) in /-- Precomposition by a continuous map is itself a continuous map between spaces of continuous maps. -/ @[simps apply] def compRightContinuousMap (f : C(X, Y)) : C(C(Y, Z), C(X, Z)) where toFun g := g.comp f /-- Any pair of homeomorphisms `X ≃ₜ Z` and `Y ≃ₜ T` gives rise to a homeomorphism `C(X, Y) ≃ₜ C(Z, T)`. -/ protected def _root_.Homeomorph.arrowCongr (φ : X ≃ₜ Z) (ψ : Y ≃ₜ T) : C(X, Y) ≃ₜ C(Z, T) where toFun f := .comp ψ <| f.comp φ.symm invFun f := .comp ψ.symm <| f.comp φ left_inv f := ext fun _ ↦ ψ.left_inv (f _) |>.trans <| congrArg f <| φ.left_inv _ right_inv f := ext fun _ ↦ ψ.right_inv (f _) |>.trans <| congrArg f <| φ.right_inv _ continuous_toFun := continuous_postcomp _ |>.comp <| continuous_precomp _ continuous_invFun := continuous_postcomp _ |>.comp <| continuous_precomp _ variable [LocallyCompactPair Y Z] /-- Composition is a continuous map from `C(X, Y) × C(Y, Z)` to `C(X, Z)`, provided that `Y` is locally compact. This is Prop. 9 of Chap. X, §3, №. 4 of Bourbaki's *Topologie Générale*. -/ theorem continuous_comp' : Continuous fun x : C(X, Y) × C(Y, Z) => x.2.comp x.1 := by simp_rw [continuous_iff_continuousAt, ContinuousAt, tendsto_nhds_compactOpen] intro ⟨f, g⟩ K hK U hU (hKU : MapsTo (g ∘ f) K U) obtain ⟨L, hKL, hLc, hLU⟩ : ∃ L ∈ 𝓝ˢ (f '' K), IsCompact L ∧ MapsTo g L U := exists_mem_nhdsSet_isCompact_mapsTo g.continuous (hK.image f.continuous) hU (mapsTo_image_iff.2 hKU) rw [← subset_interior_iff_mem_nhdsSet, ← mapsTo'] at hKL exact ((eventually_mapsTo hK isOpen_interior hKL).prod_nhds (eventually_mapsTo hLc hU hLU)).mono fun ⟨f', g'⟩ ⟨hf', hg'⟩ ↦ hg'.comp <| hf'.mono_right interior_subset lemma _root_.Filter.Tendsto.compCM {α : Type*} {l : Filter α} {g : α → C(Y, Z)} {g₀ : C(Y, Z)} {f : α → C(X, Y)} {f₀ : C(X, Y)} (hg : Tendsto g l (𝓝 g₀)) (hf : Tendsto f l (𝓝 f₀)) : Tendsto (fun a ↦ (g a).comp (f a)) l (𝓝 (g₀.comp f₀)) := (continuous_comp'.tendsto (f₀, g₀)).comp (hf.prodMk_nhds hg) variable {X' : Type*} [TopologicalSpace X'] {a : X'} {g : X' → C(Y, Z)} {f : X' → C(X, Y)} {s : Set X'} nonrec lemma _root_.ContinuousAt.compCM (hg : ContinuousAt g a) (hf : ContinuousAt f a) : ContinuousAt (fun x ↦ (g x).comp (f x)) a := hg.compCM hf nonrec lemma _root_.ContinuousWithinAt.compCM (hg : ContinuousWithinAt g s a) (hf : ContinuousWithinAt f s a) : ContinuousWithinAt (fun x ↦ (g x).comp (f x)) s a := hg.compCM hf lemma _root_.ContinuousOn.compCM (hg : ContinuousOn g s) (hf : ContinuousOn f s) : ContinuousOn (fun x ↦ (g x).comp (f x)) s := fun a ha ↦ (hg a ha).compCM (hf a ha) lemma _root_.Continuous.compCM (hg : Continuous g) (hf : Continuous f) : Continuous fun x => (g x).comp (f x) := continuous_comp'.comp (hf.prodMk hg) end Functorial section Ev /-- The evaluation map `C(X, Y) × X → Y` is continuous if `X, Y` is a locally compact pair of spaces. -/ instance [LocallyCompactPair X Y] : ContinuousEval C(X, Y) X Y where continuous_eval := by simp_rw [continuous_iff_continuousAt, ContinuousAt, (nhds_basis_opens _).tendsto_right_iff] rintro ⟨f, x⟩ U ⟨hx : f x ∈ U, hU : IsOpen U⟩ rcases exists_mem_nhds_isCompact_mapsTo f.continuous (hU.mem_nhds hx) with ⟨K, hxK, hK, hKU⟩ filter_upwards [prod_mem_nhds (eventually_mapsTo hK hU hKU) hxK] using fun _ h ↦ h.1 h.2 instance : ContinuousEvalConst C(X, Y) X Y where continuous_eval_const x := continuous_def.2 fun U hU ↦ by simpa using isOpen_setOf_mapsTo isCompact_singleton hU lemma isClosed_setOf_mapsTo {t : Set Y} (ht : IsClosed t) (s : Set X) : IsClosed {f : C(X, Y) | MapsTo f s t} := ht.setOf_mapsTo fun _ _ ↦ continuous_eval_const _ lemma isClopen_setOf_mapsTo (hK : IsCompact K) (hU : IsClopen U) : IsClopen {f : C(X, Y) | MapsTo f K U} := ⟨isClosed_setOf_mapsTo hU.isClosed K, isOpen_setOf_mapsTo hK hU.isOpen⟩ @[norm_cast] lemma specializes_coe {f g : C(X, Y)} : ⇑f ⤳ ⇑g ↔ f ⤳ g := by refine ⟨fun h ↦ ?_, fun h ↦ h.map continuous_coeFun⟩ suffices ∀ K, IsCompact K → ∀ U, IsOpen U → MapsTo g K U → MapsTo f K U by simpa [specializes_iff_pure, nhds_compactOpen] exact fun K _ U hU hg x hx ↦ (h.map (continuous_apply x)).mem_open hU (hg hx) @[norm_cast] lemma inseparable_coe {f g : C(X, Y)} : Inseparable (f : X → Y) g ↔ Inseparable f g := by simp only [inseparable_iff_specializes_and, specializes_coe] instance [T0Space Y] : T0Space C(X, Y) := t0Space_of_injective_of_continuous DFunLike.coe_injective continuous_coeFun instance [R0Space Y] : R0Space C(X, Y) where specializes_symmetric f g h := by rw [← specializes_coe] at h ⊢ exact h.symm instance [T1Space Y] : T1Space C(X, Y) := t1Space_of_injective_of_continuous DFunLike.coe_injective continuous_coeFun instance [R1Space Y] : R1Space C(X, Y) := .of_continuous_specializes_imp continuous_coeFun fun _ _ ↦ specializes_coe.1 instance [T2Space Y] : T2Space C(X, Y) := inferInstance instance [RegularSpace Y] : RegularSpace C(X, Y) := .of_lift'_closure_le fun f ↦ by rw [← tendsto_id', tendsto_nhds_compactOpen] intro K hK U hU hf rcases (hK.image f.continuous).exists_isOpen_closure_subset (hU.mem_nhdsSet.2 hf.image_subset) with ⟨V, hVo, hKV, hVU⟩ filter_upwards [mem_lift' (eventually_mapsTo hK hVo (mapsTo'.2 hKV))] with g hg refine ((isClosed_setOf_mapsTo isClosed_closure K).closure_subset ?_).mono_right hVU exact closure_mono (fun _ h ↦ h.mono_right subset_closure) hg instance [T3Space Y] : T3Space C(X, Y) := inferInstance end Ev section InfInduced /-- For any subset `s` of `X`, the restriction of continuous functions to `s` is continuous as a function from `C(X, Y)` to `C(s, Y)` with their respective compact-open topologies. -/ theorem continuous_restrict (s : Set X) : Continuous fun F : C(X, Y) => F.restrict s := continuous_precomp <| restrict s <| .id X theorem compactOpen_le_induced (s : Set X) : (ContinuousMap.compactOpen : TopologicalSpace C(X, Y)) ≤ .induced (restrict s) ContinuousMap.compactOpen := (continuous_restrict s).le_induced /-- The compact-open topology on `C(X, Y)` is equal to the infimum of the compact-open topologies on `C(s, Y)` for `s` a compact subset of `X`. The key point of the proof is that for every compact set `K`, the universal set `Set.univ : Set K` is a compact set as well. -/ theorem compactOpen_eq_iInf_induced : (ContinuousMap.compactOpen : TopologicalSpace C(X, Y)) = ⨅ (K : Set X) (_ : IsCompact K), .induced (.restrict K) ContinuousMap.compactOpen := by refine le_antisymm (le_iInf₂ fun s _ ↦ compactOpen_le_induced s) ?_ refine le_generateFrom <| forall_mem_image2.2 fun K (hK : IsCompact K) U hU ↦ ?_ refine TopologicalSpace.le_def.1 (iInf₂_le K hK) _ ?_ convert isOpen_induced (isOpen_setOf_mapsTo (isCompact_iff_isCompact_univ.1 hK) hU) simp [mapsTo_univ_iff, Subtype.forall, MapsTo] theorem nhds_compactOpen_eq_iInf_nhds_induced (f : C(X, Y)) : 𝓝 f = ⨅ (s) (_ : IsCompact s), (𝓝 (f.restrict s)).comap (ContinuousMap.restrict s) := by rw [compactOpen_eq_iInf_induced] simp only [nhds_iInf, nhds_induced] theorem tendsto_compactOpen_restrict {ι : Type*} {l : Filter ι} {F : ι → C(X, Y)} {f : C(X, Y)} (hFf : Filter.Tendsto F l (𝓝 f)) (s : Set X) : Tendsto (fun i => (F i).restrict s) l (𝓝 (f.restrict s)) := (continuous_restrict s).continuousAt.tendsto.comp hFf theorem tendsto_compactOpen_iff_forall {ι : Type*} {l : Filter ι} (F : ι → C(X, Y)) (f : C(X, Y)) : Tendsto F l (𝓝 f) ↔ ∀ K, IsCompact K → Tendsto (fun i => (F i).restrict K) l (𝓝 (f.restrict K)) := by rw [compactOpen_eq_iInf_induced] simp [nhds_iInf, nhds_induced, Filter.tendsto_comap_iff, Function.comp_def] /-- A family `F` of functions in `C(X, Y)` converges in the compact-open topology, if and only if it converges in the compact-open topology on each compact subset of `X`. -/ theorem exists_tendsto_compactOpen_iff_forall [WeaklyLocallyCompactSpace X] [T2Space Y] {ι : Type*} {l : Filter ι} [Filter.NeBot l] (F : ι → C(X, Y)) : (∃ f, Filter.Tendsto F l (𝓝 f)) ↔ ∀ s : Set X, IsCompact s → ∃ f, Filter.Tendsto (fun i => (F i).restrict s) l (𝓝 f) := by constructor · rintro ⟨f, hf⟩ s _ exact ⟨f.restrict s, tendsto_compactOpen_restrict hf s⟩ · intro h choose f hf using h -- By uniqueness of limits in a `T2Space`, since `fun i ↦ F i x` tends to both `f s₁ hs₁ x` and -- `f s₂ hs₂ x`, we have `f s₁ hs₁ x = f s₂ hs₂ x` have h : ∀ (s₁) (hs₁ : IsCompact s₁) (s₂) (hs₂ : IsCompact s₂) (x : X) (hxs₁ : x ∈ s₁) (hxs₂ : x ∈ s₂), f s₁ hs₁ ⟨x, hxs₁⟩ = f s₂ hs₂ ⟨x, hxs₂⟩ := by rintro s₁ hs₁ s₂ hs₂ x hxs₁ hxs₂ haveI := isCompact_iff_compactSpace.mp hs₁ haveI := isCompact_iff_compactSpace.mp hs₂ have h₁ := (continuous_eval_const (⟨x, hxs₁⟩ : s₁)).continuousAt.tendsto.comp (hf s₁ hs₁) have h₂ := (continuous_eval_const (⟨x, hxs₂⟩ : s₂)).continuousAt.tendsto.comp (hf s₂ hs₂) exact tendsto_nhds_unique h₁ h₂ -- So glue the `f s hs` together and prove that this glued function `f₀` is a limit on each -- compact set `s` refine ⟨liftCover' _ _ h exists_compact_mem_nhds, ?_⟩ rw [tendsto_compactOpen_iff_forall] intro s hs rw [liftCover_restrict'] exact hf s hs end InfInduced section Coev variable (X Y) /-- The coevaluation map `Y → C(X, Y × X)` sending a point `x : Y` to the continuous function on `X` sending `y` to `(x, y)`. -/ @[simps -fullyApplied] def coev (b : Y) : C(X, Y × X) := { toFun := Prod.mk b } variable {X Y} theorem image_coev {y : Y} (s : Set X) : coev X Y y '' s = {y} ×ˢ s := by simp [singleton_prod] /-- The coevaluation map `Y → C(X, Y × X)` is continuous (always). -/ theorem continuous_coev : Continuous (coev X Y) := by have : ∀ {a K U}, MapsTo (coev X Y a) K U ↔ {a} ×ˢ K ⊆ U := by simp [singleton_prod, mapsTo'] simp only [continuous_iff_continuousAt, ContinuousAt, tendsto_nhds_compactOpen, this] intro x K hK U hU hKU rcases generalized_tube_lemma isCompact_singleton hK hU hKU with ⟨V, W, hV, -, hxV, hKW, hVWU⟩ filter_upwards [hV.mem_nhds (hxV rfl)] with a ha exact (prod_mono (singleton_subset_iff.mpr ha) hKW).trans hVWU end Coev section Curry /-- The curried form of a continuous map `α × β → γ` as a continuous map `α → C(β, γ)`. If `a × β` is locally compact, this is continuous. If `α` and `β` are both locally compact, then this is a homeomorphism, see `Homeomorph.curry`. -/ def curry (f : C(X × Y, Z)) : C(X, C(Y, Z)) where toFun a := ⟨Function.curry f a, f.continuous.comp <| by fun_prop⟩ continuous_toFun := (continuous_postcomp f).comp continuous_coev
@[simp]
Mathlib/Topology/CompactOpen.lean
356
356
/- Copyright (c) 2023 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Analysis.Asymptotics.AsymptoticEquivalent import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Algebra.Order.ToIntervalMod import Mathlib.Analysis.SpecialFunctions.Log.Base /-! # Akra-Bazzi theorem: The polynomial growth condition This file defines and develops an API for the polynomial growth condition that appears in the statement of the Akra-Bazzi theorem: for the Akra-Bazzi theorem to hold, the function `g` must satisfy the condition that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for u between b*n and n for any constant `b ∈ (0,1)`. ## Implementation notes Our definition states that the condition must hold for any `b ∈ (0,1)`. This is equivalent to only requiring it for `b = 1/2` or any other particular value between 0 and 1. While this could in principle make it harder to prove that a particular function grows polynomially, this issue doesn't seem to arise in practice. -/ open Finset Real Filter Asymptotics open scoped Topology namespace AkraBazziRecurrence /-- The growth condition that the function `g` must satisfy for the Akra-Bazzi theorem to apply. It roughly states that `c₁ g(n) ≤ g(u) ≤ c₂ g(n)`, for `u` between `b*n` and `n` for any constant `b ∈ (0,1)`. -/ def GrowsPolynomially (f : ℝ → ℝ) : Prop := ∀ b ∈ Set.Ioo 0 1, ∃ c₁ > 0, ∃ c₂ > 0, ∀ᶠ x in atTop, ∀ u ∈ Set.Icc (b * x) x, f u ∈ Set.Icc (c₁ * (f x)) (c₂ * f x) namespace GrowsPolynomially lemma congr_of_eventuallyEq {f g : ℝ → ℝ} (hfg : f =ᶠ[atTop] g) (hg : GrowsPolynomially g) : GrowsPolynomially f := by intro b hb have hg' := hg b hb obtain ⟨c₁, hc₁_mem, c₂, hc₂_mem, hg'⟩ := hg' refine ⟨c₁, hc₁_mem, c₂, hc₂_mem, ?_⟩ filter_upwards [hg', (tendsto_id.const_mul_atTop hb.1).eventually_forall_ge_atTop hfg, hfg] with x hx₁ hx₂ hx₃ intro u hu rw [hx₂ u hu.1, hx₃] exact hx₁ u hu lemma iff_eventuallyEq {f g : ℝ → ℝ} (h : f =ᶠ[atTop] g) : GrowsPolynomially f ↔ GrowsPolynomially g := ⟨fun hf => congr_of_eventuallyEq h.symm hf, fun hg => congr_of_eventuallyEq h hg⟩ variable {f : ℝ → ℝ} lemma eventually_atTop_le {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) : ∃ c > 0, ∀ᶠ x in atTop, ∀ u ∈ Set.Icc (b * x) x, f u ≤ c * f x := by obtain ⟨c₁, _, c₂, hc₂, h⟩ := hf b hb refine ⟨c₂, hc₂, ?_⟩ filter_upwards [h] exact fun _ H u hu => (H u hu).2 lemma eventually_atTop_le_nat {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) : ∃ c > 0, ∀ᶠ (n : ℕ) in atTop, ∀ u ∈ Set.Icc (b * n) n, f u ≤ c * f n := by obtain ⟨c, hc_mem, hc⟩ := hf.eventually_atTop_le hb exact ⟨c, hc_mem, hc.natCast_atTop⟩
lemma eventually_atTop_ge {b : ℝ} (hb : b ∈ Set.Ioo 0 1) (hf : GrowsPolynomially f) : ∃ c > 0, ∀ᶠ x in atTop, ∀ u ∈ Set.Icc (b * x) x, c * f x ≤ f u := by obtain ⟨c₁, hc₁, c₂, _, h⟩ := hf b hb refine ⟨c₁, hc₁, ?_⟩ filter_upwards [h] exact fun _ H u hu => (H u hu).1
Mathlib/Computability/AkraBazzi/GrowsPolynomially.lean
73
78
/- Copyright (c) 2024 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Sites.LeftExact import Mathlib.CategoryTheory.Sites.PreservesSheafification import Mathlib.CategoryTheory.Sites.Subsheaf import Mathlib.CategoryTheory.Sites.Whiskering /-! # Locally injective morphisms of (pre)sheaves Let `C` be a category equipped with a Grothendieck topology `J`, and let `D` be a concrete category. In this file, we introduce the typeclass `Presheaf.IsLocallyInjective J φ` for a morphism `φ : F₁ ⟶ F₂` in the category `Cᵒᵖ ⥤ D`. This means that `φ` is locally injective. More precisely, if `x` and `y` are two elements of some `F₁.obj U` such the images of `x` and `y` in `F₂.obj U` coincide, then the equality `x = y` must hold locally, i.e. after restriction by the maps of a covering sieve. -/ universe w v' v u' u namespace CategoryTheory open Opposite Limits variable {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D] {FD : D → D → Type*} {CD : D → Type w} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{w} D FD] (J : GrothendieckTopology C) namespace Presheaf /-- If `F : Cᵒᵖ ⥤ D` is a presheaf with values in a concrete category, if `x` and `y` are elements in `F.obj X`, this is the sieve of `X.unop` consisting of morphisms `f` such that `F.map f.op x = F.map f.op y`. -/ @[simps] def equalizerSieve {F : Cᵒᵖ ⥤ D} {X : Cᵒᵖ} (x y : ToType (F.obj X)) : Sieve X.unop where arrows _ f := F.map f.op x = F.map f.op y downward_closed {X Y} f hf g := by dsimp at hf ⊢ simp [hf] @[simp] lemma equalizerSieve_self_eq_top {F : Cᵒᵖ ⥤ D} {X : Cᵒᵖ} (x : ToType (F.obj X)) : equalizerSieve x x = ⊤ := by aesop @[simp] lemma equalizerSieve_eq_top_iff {F : Cᵒᵖ ⥤ D} {X : Cᵒᵖ} (x y : ToType (F.obj X)) : equalizerSieve x y = ⊤ ↔ x = y := by constructor · intro h simpa using (show equalizerSieve x y (𝟙 _) by simp [h]) · rintro rfl apply equalizerSieve_self_eq_top variable {F₁ F₂ F₃ : Cᵒᵖ ⥤ D} (φ : F₁ ⟶ F₂) (ψ : F₂ ⟶ F₃) /-- A morphism `φ : F₁ ⟶ F₂` of presheaves `Cᵒᵖ ⥤ D` (with `D` a concrete category) is locally injective for a Grothendieck topology `J` on `C` if whenever two sections of `F₁` are sent to the same section of `F₂`, then these two sections coincide locally. -/ class IsLocallyInjective : Prop where equalizerSieve_mem {X : Cᵒᵖ} (x y : ToType (F₁.obj X)) (h : φ.app X x = φ.app X y) : equalizerSieve x y ∈ J X.unop lemma equalizerSieve_mem [IsLocallyInjective J φ] {X : Cᵒᵖ} (x y : ToType (F₁.obj X)) (h : φ.app X x = φ.app X y) : equalizerSieve x y ∈ J X.unop := IsLocallyInjective.equalizerSieve_mem x y h lemma isLocallyInjective_of_injective (hφ : ∀ (X : Cᵒᵖ), Function.Injective (φ.app X)) : IsLocallyInjective J φ where equalizerSieve_mem {X} x y h := by convert J.top_mem X.unop ext Y f simp only [equalizerSieve_apply, op_unop, Sieve.top_apply, iff_true] apply hφ simp [h] instance [IsIso φ] : IsLocallyInjective J φ := isLocallyInjective_of_injective J φ (fun X => Function.Bijective.injective (by rw [← isIso_iff_bijective] change IsIso ((forget D).map (φ.app X)) infer_instance)) attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallyInjective_forget [IsLocallyInjective J φ] : IsLocallyInjective J (whiskerRight φ (forget D)) where equalizerSieve_mem x y h := equalizerSieve_mem J φ x y h attribute [local instance] Types.instFunLike Types.instConcreteCategory in lemma isLocallyInjective_forget_iff : IsLocallyInjective J (whiskerRight φ (forget D)) ↔ IsLocallyInjective J φ := by constructor · intro exact ⟨fun x y h => equalizerSieve_mem J (whiskerRight φ (forget D)) x y h⟩ · intro infer_instance lemma isLocallyInjective_iff_equalizerSieve_mem_imp : IsLocallyInjective J φ ↔ ∀ ⦃X : Cᵒᵖ⦄ (x y : ToType (F₁.obj X)), equalizerSieve (φ.app _ x) (φ.app _ y) ∈ J X.unop → equalizerSieve x y ∈ J X.unop := by constructor · intro _ X x y h let S := equalizerSieve (φ.app _ x) (φ.app _ y) let T : ∀ ⦃Y : C⦄ ⦃f : Y ⟶ X.unop⦄ (_ : S f), Sieve Y := fun Y f _ => equalizerSieve (F₁.map f.op x) ((F₁.map f.op y)) refine J.superset_covering ?_ (J.transitive h (Sieve.bind S.1 T) ?_) · rintro Y f ⟨Z, a, g, hg, ha, rfl⟩ simpa using ha · intro Y f hf refine J.superset_covering (Sieve.le_pullback_bind S.1 T _ hf) (equalizerSieve_mem J φ _ _ ?_) rw [NatTrans.naturality_apply, NatTrans.naturality_apply] exact hf · intro hφ exact ⟨fun {X} x y h => hφ x y (by simp [h])⟩ lemma equalizerSieve_mem_of_equalizerSieve_app_mem {X : Cᵒᵖ} (x y : ToType (F₁.obj X)) (h : equalizerSieve (φ.app _ x) (φ.app _ y) ∈ J X.unop) [IsLocallyInjective J φ] : equalizerSieve x y ∈ J X.unop := (isLocallyInjective_iff_equalizerSieve_mem_imp J φ).1 inferInstance x y h instance isLocallyInjective_comp [IsLocallyInjective J φ] [IsLocallyInjective J ψ] : IsLocallyInjective J (φ ≫ ψ) where equalizerSieve_mem {X} x y h := by apply equalizerSieve_mem_of_equalizerSieve_app_mem J φ exact equalizerSieve_mem J ψ _ _ (by simpa using h) lemma isLocallyInjective_of_isLocallyInjective [IsLocallyInjective J (φ ≫ ψ)] : IsLocallyInjective J φ where equalizerSieve_mem {X} x y h := equalizerSieve_mem J (φ ≫ ψ) x y (by simp [h]) variable {φ ψ} lemma isLocallyInjective_of_isLocallyInjective_fac {φψ : F₁ ⟶ F₃} (fac : φ ≫ ψ = φψ) [IsLocallyInjective J φψ] : IsLocallyInjective J φ := by subst fac exact isLocallyInjective_of_isLocallyInjective J φ ψ lemma isLocallyInjective_iff_of_fac {φψ : F₁ ⟶ F₃} (fac : φ ≫ ψ = φψ) [IsLocallyInjective J ψ] : IsLocallyInjective J φψ ↔ IsLocallyInjective J φ := by constructor · intro exact isLocallyInjective_of_isLocallyInjective_fac J fac · intro rw [← fac] infer_instance variable (φ ψ) lemma isLocallyInjective_comp_iff [IsLocallyInjective J ψ] : IsLocallyInjective J (φ ≫ ψ) ↔ IsLocallyInjective J φ := isLocallyInjective_iff_of_fac J rfl lemma isLocallyInjective_iff_injective_of_separated (hsep : Presieve.IsSeparated J (F₁ ⋙ forget D)) : IsLocallyInjective J φ ↔ ∀ (X : Cᵒᵖ), Function.Injective (φ.app X) := by constructor · intro _ X x y h exact (hsep _ (equalizerSieve_mem J φ x y h)).ext (fun _ _ hf => hf) · apply isLocallyInjective_of_injective attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance (F : Cᵒᵖ ⥤ Type w) (G : Subpresheaf F) : IsLocallyInjective J G.ι := isLocallyInjective_of_injective _ _ (fun X => by intro ⟨x, _⟩ ⟨y, _⟩ h exact Subtype.ext h) section open GrothendieckTopology.Plus attribute [local instance] Types.instFunLike Types.instConcreteCategory instance isLocallyInjective_toPlus (P : Cᵒᵖ ⥤ Type max u v) : IsLocallyInjective J (J.toPlus P) where equalizerSieve_mem {X} x y h := by rw [toPlus_eq_mk, toPlus_eq_mk, eq_mk_iff_exists] at h obtain ⟨W, h₁, h₂, eq⟩ := h exact J.superset_covering (fun Y f hf => congr_fun (congr_arg Subtype.val eq) ⟨Y, f, hf⟩) W.2 instance isLocallyInjective_toSheafify (P : Cᵒᵖ ⥤ Type max u v) : IsLocallyInjective J (J.toSheafify P) := by dsimp [GrothendieckTopology.toSheafify] rw [GrothendieckTopology.plusMap_toPlus] infer_instance instance isLocallyInjective_toSheafify' {CD : D → Type (max u v)} [∀ X Y, FunLike (FD X Y) (CD X) (CD Y)] [ConcreteCategory.{max u v} D FD] (P : Cᵒᵖ ⥤ D) [HasWeakSheafify J D] [J.HasSheafCompose (forget D)] [J.PreservesSheafification (forget D)] : IsLocallyInjective J (toSheafify J P) := by rw [← isLocallyInjective_forget_iff, ← sheafComposeIso_hom_fac, ← toSheafify_plusPlusIsoSheafify_hom] infer_instance end end Presheaf namespace Sheaf variable {J} variable {F₁ F₂ : Sheaf J D} (φ : F₁ ⟶ F₂) /-- If `φ : F₁ ⟶ F₂` is a morphism of sheaves, this is an abbreviation for `Presheaf.IsLocallyInjective J φ.val`. Under suitable assumptions, it is equivalent to the injectivity of all maps `φ.val.app X`, see `isLocallyInjective_iff_injective`. -/ abbrev IsLocallyInjective := Presheaf.IsLocallyInjective J φ.val lemma isLocallyInjective_sheafToPresheaf_map_iff : Presheaf.IsLocallyInjective J ((sheafToPresheaf J D).map φ) ↔ IsLocallyInjective φ := by rfl instance isLocallyInjective_of_iso [IsIso φ] : IsLocallyInjective φ := by change Presheaf.IsLocallyInjective J ((sheafToPresheaf _ _).map φ) infer_instance lemma mono_of_injective (hφ : ∀ (X : Cᵒᵖ), Function.Injective (φ.val.app X)) : Mono φ := have : ∀ X, Mono (φ.val.app X) := fun X ↦ ConcreteCategory.mono_of_injective _ (hφ X) (sheafToPresheaf _ _).mono_of_mono_map (NatTrans.mono_of_mono_app φ.1) variable [J.HasSheafCompose (forget D)] attribute [local instance] Types.instFunLike Types.instConcreteCategory in instance isLocallyInjective_forget [IsLocallyInjective φ] : IsLocallyInjective ((sheafCompose J (forget D)).map φ) := Presheaf.isLocallyInjective_forget J φ.1 lemma isLocallyInjective_iff_injective :
IsLocallyInjective φ ↔ ∀ (X : Cᵒᵖ), Function.Injective (φ.val.app X) := Presheaf.isLocallyInjective_iff_injective_of_separated _ _ (by apply Presieve.isSeparated_of_isSheaf rw [← isSheaf_iff_isSheaf_of_type]
Mathlib/CategoryTheory/Sites/LocallyInjective.lean
240
243
/- Copyright (c) 2021 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.Tactic.CategoryTheory.Monoidal.Basic import Mathlib.CategoryTheory.Closed.Monoidal import Mathlib.Tactic.ApplyFun /-! # Rigid (autonomous) monoidal categories This file defines rigid (autonomous) monoidal categories and the necessary theory about exact pairings and duals. ## Main definitions * `ExactPairing` of two objects of a monoidal category * Type classes `HasLeftDual` and `HasRightDual` that capture that a pairing exists * The `rightAdjointMate f` as a morphism `fᘁ : Yᘁ ⟶ Xᘁ` for a morphism `f : X ⟶ Y` * The classes of `RightRigidCategory`, `LeftRigidCategory` and `RigidCategory` ## Main statements * `comp_rightAdjointMate`: The adjoint mates of the composition is the composition of adjoint mates. ## Notations * `η_` and `ε_` denote the coevaluation and evaluation morphism of an exact pairing. * `Xᘁ` and `ᘁX` denote the right and left dual of an object, as well as the adjoint mate of a morphism. ## Future work * Show that `X ⊗ Y` and `Yᘁ ⊗ Xᘁ` form an exact pairing. * Show that the left adjoint mate of the right adjoint mate of a morphism is the morphism itself. * Simplify constructions in the case where a symmetry or braiding is present. * Show that `ᘁ` gives an equivalence of categories `C ≅ (Cᵒᵖ)ᴹᵒᵖ`. * Define pivotal categories (rigid categories equipped with a natural isomorphism `ᘁᘁ ≅ 𝟙 C`). ## Notes Although we construct the adjunction `tensorLeft Y ⊣ tensorLeft X` from `ExactPairing X Y`, this is not a bijective correspondence. I think the correct statement is that `tensorLeft Y` and `tensorLeft X` are module endofunctors of `C` as a right `C` module category, and `ExactPairing X Y` is in bijection with adjunctions compatible with this right `C` action. ## References * <https://ncatlab.org/nlab/show/rigid+monoidal+category> ## Tags rigid category, monoidal category -/ open CategoryTheory MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- An exact pairing is a pair of objects `X Y : C` which admit a coevaluation and evaluation morphism which fulfill two triangle equalities. -/ class ExactPairing (X Y : C) where /-- Coevaluation of an exact pairing. Do not use directly. Use `ExactPairing.coevaluation` instead. -/ coevaluation' : 𝟙_ C ⟶ X ⊗ Y /-- Evaluation of an exact pairing. Do not use directly. Use `ExactPairing.evaluation` instead. -/ evaluation' : Y ⊗ X ⟶ 𝟙_ C coevaluation_evaluation' : Y ◁ coevaluation' ≫ (α_ _ _ _).inv ≫ evaluation' ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := by aesop_cat evaluation_coevaluation' : coevaluation' ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ evaluation' = (λ_ X).hom ≫ (ρ_ X).inv := by aesop_cat namespace ExactPairing -- Porting note: as there is no mechanism equivalent to `[]` in Lean 3 to make -- arguments for class fields explicit, -- we now repeat all the fields without primes. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Making.20variable.20in.20class.20field.20explicit variable (X Y : C) variable [ExactPairing X Y] /-- Coevaluation of an exact pairing. -/ def coevaluation : 𝟙_ C ⟶ X ⊗ Y := @coevaluation' _ _ _ X Y _ /-- Evaluation of an exact pairing. -/ def evaluation : Y ⊗ X ⟶ 𝟙_ C := @evaluation' _ _ _ X Y _ @[inherit_doc] notation "η_" => ExactPairing.coevaluation @[inherit_doc] notation "ε_" => ExactPairing.evaluation lemma coevaluation_evaluation : Y ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ ε_ X _ ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := coevaluation_evaluation' lemma evaluation_coevaluation : η_ _ _ ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ ε_ _ Y = (λ_ X).hom ≫ (ρ_ X).inv := evaluation_coevaluation' lemma coevaluation_evaluation'' : Y ◁ η_ X Y ⊗≫ ε_ X Y ▷ Y = ⊗𝟙.hom := by convert coevaluation_evaluation X Y <;> simp [monoidalComp] lemma evaluation_coevaluation'' : η_ X Y ▷ X ⊗≫ X ◁ ε_ X Y = ⊗𝟙.hom := by convert evaluation_coevaluation X Y <;> simp [monoidalComp] end ExactPairing attribute [reassoc (attr := simp)] ExactPairing.coevaluation_evaluation attribute [reassoc (attr := simp)] ExactPairing.evaluation_coevaluation instance exactPairingUnit : ExactPairing (𝟙_ C) (𝟙_ C) where coevaluation' := (ρ_ _).inv evaluation' := (ρ_ _).hom coevaluation_evaluation' := by monoidal_coherence evaluation_coevaluation' := by monoidal_coherence /-- A class of objects which have a right dual. -/ class HasRightDual (X : C) where /-- The right dual of the object `X`. -/ rightDual : C [exact : ExactPairing X rightDual] /-- A class of objects which have a left dual. -/ class HasLeftDual (Y : C) where /-- The left dual of the object `X`. -/ leftDual : C [exact : ExactPairing leftDual Y] attribute [instance] HasRightDual.exact attribute [instance] HasLeftDual.exact open ExactPairing HasRightDual HasLeftDual MonoidalCategory #adaptation_note /-- https://github.com/leanprover/lean4/pull/4596 The overlapping notation for `leftDual` and `leftAdjointMate` become more problematic in after https://github.com/leanprover/lean4/pull/4596, and we sometimes have to disambiguate with e.g. `(ᘁX : C)` where previously just `ᘁX` was enough. -/ @[inherit_doc] prefix:1024 "ᘁ" => leftDual @[inherit_doc] postfix:1024 "ᘁ" => rightDual instance hasRightDualUnit : HasRightDual (𝟙_ C) where rightDual := 𝟙_ C instance hasLeftDualUnit : HasLeftDual (𝟙_ C) where leftDual := 𝟙_ C instance hasRightDualLeftDual {X : C} [HasLeftDual X] : HasRightDual ᘁX where rightDual := X instance hasLeftDualRightDual {X : C} [HasRightDual X] : HasLeftDual Xᘁ where leftDual := X @[simp] theorem leftDual_rightDual {X : C} [HasRightDual X] : ᘁXᘁ = X := rfl @[simp] theorem rightDual_leftDual {X : C} [HasLeftDual X] : (ᘁX)ᘁ = X := rfl /-- The right adjoint mate `fᘁ : Xᘁ ⟶ Yᘁ` of a morphism `f : X ⟶ Y`. -/ def rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : Yᘁ ⟶ Xᘁ := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ _ ◁ f ▷ _ ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom /-- The left adjoint mate `ᘁf : ᘁY ⟶ ᘁX` of a morphism `f : X ⟶ Y`. -/ def leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : ᘁY ⟶ ᘁX := (λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (_ ◁ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom @[inherit_doc] notation f "ᘁ" => rightAdjointMate f @[inherit_doc] notation "ᘁ" f => leftAdjointMate f @[simp] theorem rightAdjointMate_id {X : C} [HasRightDual X] : (𝟙 X)ᘁ = 𝟙 (Xᘁ) := by simp [rightAdjointMate] @[simp] theorem leftAdjointMate_id {X : C} [HasLeftDual X] : (ᘁ(𝟙 X)) = 𝟙 (ᘁX) := by simp [leftAdjointMate] theorem rightAdjointMate_comp {X Y Z : C} [HasRightDual X] [HasRightDual Y] {f : X ⟶ Y} {g : Xᘁ ⟶ Z} : fᘁ ≫ g = (ρ_ (Yᘁ)).inv ≫ _ ◁ η_ X (Xᘁ) ≫ _ ◁ (f ⊗ g) ≫ (α_ (Yᘁ) Y Z).inv ≫ ε_ Y (Yᘁ) ▷ _ ≫ (λ_ Z).hom := calc _ = 𝟙 _ ⊗≫ (Yᘁ : C) ◁ η_ X Xᘁ ≫ Yᘁ ◁ f ▷ Xᘁ ⊗≫ (ε_ Y Yᘁ ▷ Xᘁ ≫ 𝟙_ C ◁ g) ⊗≫ 𝟙 _ := by dsimp only [rightAdjointMate]; monoidal
_ = _ := by rw [← whisker_exchange, tensorHom_def]; monoidal
Mathlib/CategoryTheory/Monoidal/Rigid/Basic.lean
206
207
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.LinearAlgebra.AffineSpace.Slope /-! # Derivative as the limit of the slope In this file we relate the derivative of a function with its definition from a standard undergraduate course as the limit of the slope `(f y - f x) / (y - x)` as `y` tends to `𝓝[≠] x`. Since we are talking about functions taking values in a normed space instead of the base field, we use `slope f x y = (y - x)⁻¹ • (f y - f x)` instead of division. We also prove some estimates on the upper/lower limits of the slope in terms of the derivative. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `analysis/calculus/deriv/basic`. ## Keywords derivative, slope -/ universe u v open scoped Topology open Filter TopologicalSpace Set section NormedField variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : 𝕜 → F} variable {f' : F} variable {x : 𝕜} variable {s : Set 𝕜} /-- If the domain has dimension one, then Fréchet derivative is equivalent to the classical definition with a limit. In this version we have to take the limit along the subset `-{x}`, because for `y=x` the slope equals zero due to the convention `0⁻¹=0`. -/ theorem hasDerivAtFilter_iff_tendsto_slope {x : 𝕜} {L : Filter 𝕜} : HasDerivAtFilter f f' x L ↔ Tendsto (slope f x) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') := calc HasDerivAtFilter f f' x L ↔ Tendsto (fun y ↦ slope f x y - (y - x)⁻¹ • (y - x) • f') L (𝓝 0) := by simp only [hasDerivAtFilter_iff_tendsto, ← norm_inv, ← norm_smul, ← tendsto_zero_iff_norm_tendsto_zero, slope_def_module, smul_sub] _ ↔ Tendsto (fun y ↦ slope f x y - (y - x)⁻¹ • (y - x) • f') (L ⊓ 𝓟 {x}ᶜ) (𝓝 0) := .symm <| tendsto_inf_principal_nhds_iff_of_forall_eq <| by simp _ ↔ Tendsto (fun y ↦ slope f x y - f') (L ⊓ 𝓟 {x}ᶜ) (𝓝 0) := tendsto_congr' <| by refine (EqOn.eventuallyEq fun y hy ↦ ?_).filter_mono inf_le_right rw [inv_smul_smul₀ (sub_ne_zero.2 hy) f'] _ ↔ Tendsto (slope f x) (L ⊓ 𝓟 {x}ᶜ) (𝓝 f') := by rw [← nhds_translation_sub f', tendsto_comap_iff]; rfl theorem hasDerivWithinAt_iff_tendsto_slope : HasDerivWithinAt f f' s x ↔ Tendsto (slope f x) (𝓝[s \ {x}] x) (𝓝 f') := by simp only [HasDerivWithinAt, nhdsWithin, diff_eq, ← inf_assoc, inf_principal.symm] exact hasDerivAtFilter_iff_tendsto_slope theorem hasDerivWithinAt_iff_tendsto_slope' (hs : x ∉ s) : HasDerivWithinAt f f' s x ↔ Tendsto (slope f x) (𝓝[s] x) (𝓝 f') := by rw [hasDerivWithinAt_iff_tendsto_slope, diff_singleton_eq_self hs] theorem hasDerivAt_iff_tendsto_slope : HasDerivAt f f' x ↔ Tendsto (slope f x) (𝓝[≠] x) (𝓝 f') := hasDerivAtFilter_iff_tendsto_slope theorem hasDerivAt_iff_tendsto_slope_zero : HasDerivAt f f' x ↔ Tendsto (fun t ↦ t⁻¹ • (f (x + t) - f x)) (𝓝[≠] 0) (𝓝 f') := by have : 𝓝[≠] x = Filter.map (fun t ↦ x + t) (𝓝[≠] 0) := by simp [nhdsWithin, map_add_left_nhds_zero x, Filter.map_inf, add_right_injective x] simp [hasDerivAt_iff_tendsto_slope, this, slope, Function.comp_def] alias ⟨HasDerivAt.tendsto_slope_zero, _⟩ := hasDerivAt_iff_tendsto_slope_zero theorem HasDerivAt.tendsto_slope_zero_right [Preorder 𝕜] (h : HasDerivAt f f' x) : Tendsto (fun t ↦ t⁻¹ • (f (x + t) - f x)) (𝓝[>] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhdsGT_le_nhdsNE 0) theorem HasDerivAt.tendsto_slope_zero_left [Preorder 𝕜] (h : HasDerivAt f f' x) : Tendsto (fun t ↦ t⁻¹ • (f (x + t) - f x)) (𝓝[<] 0) (𝓝 f') := h.tendsto_slope_zero.mono_left (nhdsLT_le_nhdsNE 0) /-- Given a set `t` such that `s ∩ t` is dense in `s`, then the range of `derivWithin f s` is contained in the closure of the submodule spanned by the image of `t`. -/ theorem range_derivWithin_subset_closure_span_image (f : 𝕜 → F) {s t : Set 𝕜} (h : s ⊆ closure (s ∩ t)) : range (derivWithin f s) ⊆ closure (Submodule.span 𝕜 (f '' t)) := by rintro - ⟨x, rfl⟩ by_cases H : UniqueDiffWithinAt 𝕜 s x; swap · simpa [derivWithin_zero_of_not_uniqueDiffWithinAt H] using subset_closure (zero_mem _) by_cases H' : DifferentiableWithinAt 𝕜 f s x; swap · rw [derivWithin_zero_of_not_differentiableWithinAt H'] exact subset_closure (zero_mem _) have I : (𝓝[(s ∩ t) \ {x}] x).NeBot := by rw [← accPt_principal_iff_nhdsWithin, ← uniqueDiffWithinAt_iff_accPt] exact H.mono_closure h have : Tendsto (slope f x) (𝓝[(s ∩ t) \ {x}] x) (𝓝 (derivWithin f s x)) := by apply Tendsto.mono_left (hasDerivWithinAt_iff_tendsto_slope.1 H'.hasDerivWithinAt) rw [inter_comm, inter_diff_assoc] exact nhdsWithin_mono _ inter_subset_right rw [← closure_closure, ← Submodule.topologicalClosure_coe] apply mem_closure_of_tendsto this filter_upwards [self_mem_nhdsWithin] with y hy simp only [slope, vsub_eq_sub, SetLike.mem_coe] refine Submodule.smul_mem _ _ (Submodule.sub_mem _ ?_ ?_) · apply Submodule.le_topologicalClosure apply Submodule.subset_span exact mem_image_of_mem _ hy.1.2 · apply Submodule.closure_subset_topologicalClosure_span suffices A : f x ∈ closure (f '' (s ∩ t)) from closure_mono (image_subset _ inter_subset_right) A apply ContinuousWithinAt.mem_closure_image · apply H'.continuousWithinAt.mono inter_subset_left rw [mem_closure_iff_nhdsWithin_neBot] exact I.mono (nhdsWithin_mono _ diff_subset) /-- Given a dense set `t`, then the range of `deriv f` is contained in the closure of the submodule spanned by the image of `t`. -/ theorem range_deriv_subset_closure_span_image (f : 𝕜 → F) {t : Set 𝕜} (h : Dense t) : range (deriv f) ⊆ closure (Submodule.span 𝕜 (f '' t)) := by rw [← derivWithin_univ] apply range_derivWithin_subset_closure_span_image simp [dense_iff_closure_eq.1 h] theorem isSeparable_range_derivWithin [SeparableSpace 𝕜] (f : 𝕜 → F) (s : Set 𝕜) : IsSeparable (range (derivWithin f s)) := by obtain ⟨t, ts, t_count, ht⟩ : ∃ t, t ⊆ s ∧ Set.Countable t ∧ s ⊆ closure t := (IsSeparable.of_separableSpace s).exists_countable_dense_subset have : s ⊆ closure (s ∩ t) := by rwa [inter_eq_self_of_subset_right ts] apply IsSeparable.mono _ (range_derivWithin_subset_closure_span_image f this) exact (Countable.image t_count f).isSeparable.span.closure theorem isSeparable_range_deriv [SeparableSpace 𝕜] (f : 𝕜 → F) : IsSeparable (range (deriv f)) := by rw [← derivWithin_univ] exact isSeparable_range_derivWithin _ _ lemma HasDerivAt.continuousAt_div [DecidableEq 𝕜] {f : 𝕜 → 𝕜} {c a : 𝕜} (hf : HasDerivAt f a c) : ContinuousAt (Function.update (fun x ↦ (f x - f c) / (x - c)) c a) c := by rw [← slope_fun_def_field] exact continuousAt_update_same.mpr <| hasDerivAt_iff_tendsto_slope.mp hf end NormedField /-! ### Upper estimates on liminf and limsup -/ section Real variable {f : ℝ → ℝ} {f' : ℝ} {s : Set ℝ} {x : ℝ} {r : ℝ} theorem HasDerivWithinAt.limsup_slope_le (hf : HasDerivWithinAt f f' s x) (hr : f' < r) : ∀ᶠ z in 𝓝[s \ {x}] x, slope f x z < r := hasDerivWithinAt_iff_tendsto_slope.1 hf (IsOpen.mem_nhds isOpen_Iio hr) theorem HasDerivWithinAt.limsup_slope_le' (hf : HasDerivWithinAt f f' s x) (hs : x ∉ s) (hr : f' < r) : ∀ᶠ z in 𝓝[s] x, slope f x z < r := (hasDerivWithinAt_iff_tendsto_slope' hs).1 hf (IsOpen.mem_nhds isOpen_Iio hr) theorem HasDerivWithinAt.liminf_right_slope_le (hf : HasDerivWithinAt f f' (Ici x) x) (hr : f' < r) : ∃ᶠ z in 𝓝[>] x, slope f x z < r := (hf.Ioi_of_Ici.limsup_slope_le' (lt_irrefl x) hr).frequently end Real section RealSpace open Metric variable {E : Type u} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : ℝ → E} {f' : E} {s : Set ℝ} {x r : ℝ} /-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ‖f'‖` the ratio `‖f z - f x‖ / ‖z - x‖` is less than `r` in some neighborhood of `x` within `s`. In other words, the limit superior of this ratio as `z` tends to `x` along `s` is less than or equal to `‖f'‖`. -/ theorem HasDerivWithinAt.limsup_norm_slope_le (hf : HasDerivWithinAt f f' s x) (hr : ‖f'‖ < r) : ∀ᶠ z in 𝓝[s] x, ‖z - x‖⁻¹ * ‖f z - f x‖ < r := by have hr₀ : 0 < r := lt_of_le_of_lt (norm_nonneg f') hr have A : ∀ᶠ z in 𝓝[s \ {x}] x, ‖(z - x)⁻¹ • (f z - f x)‖ ∈ Iio r := (hasDerivWithinAt_iff_tendsto_slope.1 hf).norm (IsOpen.mem_nhds isOpen_Iio hr) have B : ∀ᶠ z in 𝓝[{x}] x, ‖(z - x)⁻¹ • (f z - f x)‖ ∈ Iio r := mem_of_superset self_mem_nhdsWithin (singleton_subset_iff.2 <| by simp [hr₀]) have C := mem_sup.2 ⟨A, B⟩ rw [← nhdsWithin_union, diff_union_self, nhdsWithin_union, mem_sup] at C filter_upwards [C.1] simp only [norm_smul, mem_Iio, norm_inv] exact fun _ => id /-- If `f` has derivative `f'` within `s` at `x`, then for any `r > ‖f'‖` the ratio `(‖f z‖ - ‖f x‖) / ‖z - x‖` is less than `r` in some neighborhood of `x` within `s`. In other words, the limit superior of this ratio as `z` tends to `x` along `s` is less than or equal to `‖f'‖`. This lemma is a weaker version of `HasDerivWithinAt.limsup_norm_slope_le` where `‖f z‖ - ‖f x‖` is replaced by `‖f z - f x‖`. -/ theorem HasDerivWithinAt.limsup_slope_norm_le (hf : HasDerivWithinAt f f' s x) (hr : ‖f'‖ < r) : ∀ᶠ z in 𝓝[s] x, ‖z - x‖⁻¹ * (‖f z‖ - ‖f x‖) < r := by apply (hf.limsup_norm_slope_le hr).mono intro z hz refine lt_of_le_of_lt (mul_le_mul_of_nonneg_left (norm_sub_norm_le _ _) ?_) hz exact inv_nonneg.2 (norm_nonneg _) /-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ‖f'‖` the ratio `‖f z - f x‖ / ‖z - x‖` is frequently less than `r` as `z → x+0`. In other words, the limit inferior of this ratio as `z` tends to `x+0` is less than or equal to `‖f'‖`. See also `HasDerivWithinAt.limsup_norm_slope_le` for a stronger version using limit superior and any set `s`. -/ theorem HasDerivWithinAt.liminf_right_norm_slope_le (hf : HasDerivWithinAt f f' (Ici x) x)
(hr : ‖f'‖ < r) : ∃ᶠ z in 𝓝[>] x, ‖z - x‖⁻¹ * ‖f z - f x‖ < r := (hf.Ioi_of_Ici.limsup_norm_slope_le hr).frequently /-- If `f` has derivative `f'` within `(x, +∞)` at `x`, then for any `r > ‖f'‖` the ratio `(‖f z‖ - ‖f x‖) / (z - x)` is frequently less than `r` as `z → x+0`. In other words, the limit inferior of this ratio as `z` tends to `x+0`
Mathlib/Analysis/Calculus/Deriv/Slope.lean
215
220
/- 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, Johannes Hölzl, Rémy Degenne -/ import Mathlib.Order.ConditionallyCompleteLattice.Indexed import Mathlib.Order.Filter.IsBounded import Mathlib.Order.Hom.CompleteLattice /-! # liminfs and limsups of functions and filters Defines the liminf/limsup of a function taking values in a conditionally complete lattice, with respect to an arbitrary filter. We define `limsSup f` (`limsInf f`) where `f` is a filter taking values in a conditionally complete lattice. `limsSup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for `limsInf f`). To work with the Limsup along a function `u` use `limsSup (map u f)`. Usually, one defines the Limsup as `inf (sup s)` where the Inf is taken over all sets in the filter. For instance, in ℕ along a function `u`, this is `inf_n (sup_{k ≥ n} u k)` (and the latter quantity decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible that `u` is not bounded on the whole space, only eventually (think of `limsup (fun x ↦ 1/x)` on ℝ. Then there is no guarantee that the quantity above really decreases (the value of the `sup` beforehand is not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not use this `inf sup ...` definition in conditionally complete lattices, and one has to use a less tractable definition. In conditionally complete lattices, the definition is only useful for filters which are eventually bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the space either). We start with definitions of these concepts for arbitrary filters, before turning to the definitions of Limsup and Liminf. In complete lattices, however, it coincides with the `Inf Sup` definition. -/ open Filter Set Function variable {α β γ ι ι' : Type*} namespace Filter section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s : Set α} {u : β → α} /-- The `limsSup` of a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `x ≤ a`. -/ def limsSup (f : Filter α) : α := sInf { a | ∀ᶠ n in f, n ≤ a } /-- The `limsInf` of a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `x ≥ a`. -/ def limsInf (f : Filter α) : α := sSup { a | ∀ᶠ n in f, a ≤ n } /-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that, eventually for `f`, holds `u x ≤ a`. -/ def limsup (u : β → α) (f : Filter β) : α := limsSup (map u f) /-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that, eventually for `f`, holds `u x ≥ a`. -/ def liminf (u : β → α) (f : Filter β) : α := limsInf (map u f) /-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/ def blimsup (u : β → α) (f : Filter β) (p : β → Prop) := sInf { a | ∀ᶠ x in f, p x → u x ≤ a } /-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/ def bliminf (u : β → α) (f : Filter β) (p : β → Prop) := sSup { a | ∀ᶠ x in f, p x → a ≤ u x } section variable {f : Filter β} {u : β → α} {p : β → Prop} theorem limsup_eq : limsup u f = sInf { a | ∀ᶠ n in f, u n ≤ a } := rfl theorem liminf_eq : liminf u f = sSup { a | ∀ᶠ n in f, a ≤ u n } := rfl theorem blimsup_eq : blimsup u f p = sInf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl theorem bliminf_eq : bliminf u f p = sSup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl lemma liminf_comp (u : β → α) (v : γ → β) (f : Filter γ) : liminf (u ∘ v) f = liminf u (map v f) := rfl lemma limsup_comp (u : β → α) (v : γ → β) (f : Filter γ) : limsup (u ∘ v) f = limsup u (map v f) := rfl end @[simp] theorem blimsup_true (f : Filter β) (u : β → α) : (blimsup u f fun _ => True) = limsup u f := by simp [blimsup_eq, limsup_eq] @[simp] theorem bliminf_true (f : Filter β) (u : β → α) : (bliminf u f fun _ => True) = liminf u f := by simp [bliminf_eq, liminf_eq] lemma blimsup_eq_limsup {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup u (f ⊓ 𝓟 {x | p x}) := by simp only [blimsup_eq, limsup_eq, eventually_inf_principal, mem_setOf_eq] lemma bliminf_eq_liminf {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf u (f ⊓ 𝓟 {x | p x}) := blimsup_eq_limsup (α := αᵒᵈ) theorem blimsup_eq_limsup_subtype {f : Filter β} {u : β → α} {p : β → Prop} : blimsup u f p = limsup (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := by rw [blimsup_eq_limsup, limsup, limsup, ← map_map, map_comap_setCoe_val] theorem bliminf_eq_liminf_subtype {f : Filter β} {u : β → α} {p : β → Prop} : bliminf u f p = liminf (u ∘ ((↑) : { x | p x } → β)) (comap (↑) f) := blimsup_eq_limsup_subtype (α := αᵒᵈ) theorem limsSup_le_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, n ≤ a) : limsSup f ≤ a := csInf_le hf h theorem le_limsInf_of_le {f : Filter α} {a} (hf : f.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ n) : a ≤ limsInf f := le_csSup hf h theorem limsup_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, u n ≤ a) : limsup u f ≤ a := csInf_le hf h theorem le_liminf_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ᶠ n in f, a ≤ u n) : a ≤ liminf u f := le_csSup hf h theorem le_limsSup_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) : a ≤ limsSup f := le_csInf hf h theorem limsInf_le_of_le {f : Filter α} {a} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) : limsInf f ≤ a := csSup_le hf h theorem le_limsup_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) : a ≤ limsup u f := le_csInf hf h theorem liminf_le_of_le {f : Filter β} {u : β → α} {a} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) : liminf u f ≤ a := csSup_le hf h theorem limsInf_le_limsSup {f : Filter α} [NeBot f] (h₁ : f.IsBounded (· ≤ ·) := by isBoundedDefault) (h₂ : f.IsBounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsSup f := liminf_le_of_le h₂ fun a₀ ha₀ => le_limsup_of_le h₁ fun a₁ ha₁ => show a₀ ≤ a₁ from let ⟨_, hb₀, hb₁⟩ := (ha₀.and ha₁).exists le_trans hb₀ hb₁ theorem liminf_le_limsup {f : Filter β} [NeBot f] {u : β → α} (h : f.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) (h' : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ limsup u f := limsInf_le_limsSup h h' theorem limsSup_le_limsSup {f g : Filter α} (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : limsSup f ≤ limsSup g := csInf_le_csInf hf hg h theorem limsInf_le_limsInf {f g : Filter α} (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) (h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : limsInf f ≤ limsInf g := csSup_le_csSup hg hf h theorem limsup_le_limsup {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : u ≤ᶠ[f] v) (hu : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hv : f.IsBoundedUnder (· ≤ ·) v := by isBoundedDefault) : limsup u f ≤ limsup v f := limsSup_le_limsSup hu hv fun _ => h.trans theorem liminf_le_liminf {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a ≤ v a) (hu : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hv : f.IsCoboundedUnder (· ≥ ·) v := by isBoundedDefault) : liminf u f ≤ liminf v f := limsup_le_limsup (β := βᵒᵈ) h hv hu theorem limsSup_le_limsSup_of_le {f g : Filter α} (h : f ≤ g) (hf : f.IsCobounded (· ≤ ·) := by isBoundedDefault) (hg : g.IsBounded (· ≤ ·) := by isBoundedDefault) : limsSup f ≤ limsSup g := limsSup_le_limsSup hf hg fun _ ha => h ha theorem limsInf_le_limsInf_of_le {f g : Filter α} (h : g ≤ f) (hf : f.IsBounded (· ≥ ·) := by isBoundedDefault) (hg : g.IsCobounded (· ≥ ·) := by isBoundedDefault) : limsInf f ≤ limsInf g := limsInf_le_limsInf hf hg fun _ ha => h ha theorem limsup_le_limsup_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : f ≤ g) {u : α → β} (hf : f.IsCoboundedUnder (· ≤ ·) u := by isBoundedDefault) (hg : g.IsBoundedUnder (· ≤ ·) u := by isBoundedDefault) : limsup u f ≤ limsup u g := limsSup_le_limsSup_of_le (map_mono h) hf hg theorem liminf_le_liminf_of_le {α β} [ConditionallyCompleteLattice β] {f g : Filter α} (h : g ≤ f) {u : α → β} (hf : f.IsBoundedUnder (· ≥ ·) u := by isBoundedDefault) (hg : g.IsCoboundedUnder (· ≥ ·) u := by isBoundedDefault) : liminf u f ≤ liminf u g := limsInf_le_limsInf_of_le (map_mono h) hf hg lemma limsSup_principal_eq_csSup (h : BddAbove s) (hs : s.Nonempty) : limsSup (𝓟 s) = sSup s := by simp only [limsSup, eventually_principal]; exact csInf_upperBounds_eq_csSup h hs lemma limsInf_principal_eq_csSup (h : BddBelow s) (hs : s.Nonempty) : limsInf (𝓟 s) = sInf s := limsSup_principal_eq_csSup (α := αᵒᵈ) h hs lemma limsup_top_eq_ciSup [Nonempty β] (hu : BddAbove (range u)) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_csSup hu (range_nonempty _), sSup_range] lemma liminf_top_eq_ciInf [Nonempty β] (hu : BddBelow (range u)) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_csSup hu (range_nonempty _), sInf_range] theorem limsup_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f := by rw [limsup_eq] congr with b exact eventually_congr (h.mono fun x hx => by simp [hx]) theorem blimsup_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : blimsup u f p = blimsup v f p := by simpa only [blimsup_eq_limsup] using limsup_congr <| eventually_inf_principal.2 h theorem bliminf_congr {f : Filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) : bliminf u f p = bliminf v f p := blimsup_congr (α := αᵒᵈ) h theorem liminf_congr {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} {u v : α → β} (h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f := limsup_congr (β := βᵒᵈ) h @[simp] theorem limsup_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : limsup (fun _ => b) f = b := by simpa only [limsup_eq, eventually_const] using csInf_Ici @[simp] theorem liminf_const {α : Type*} [ConditionallyCompleteLattice β] {f : Filter α} [NeBot f] (b : β) : liminf (fun _ => b) f = b := limsup_const (β := βᵒᵈ) b theorem HasBasis.liminf_eq_sSup_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : liminf f v = sSup (⋃ (j : Subtype p), ⋂ (i : s j), Iic (f i)) := by simp_rw [liminf_eq, hv.eventually_iff] congr ext x simp only [mem_setOf_eq, iInter_coe_set, mem_iUnion, mem_iInter, mem_Iic, Subtype.exists, exists_prop] theorem HasBasis.liminf_eq_sSup_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : liminf f v = sSup univ := by simp [hv.eq_bot_iff.2 ⟨i, hi, h'i⟩, liminf_eq] theorem HasBasis.limsup_eq_sInf_iUnion_iInter {ι ι' : Type*} {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) : limsup f v = sInf (⋃ (j : Subtype p), ⋂ (i : s j), Ici (f i)) := HasBasis.liminf_eq_sSup_iUnion_iInter (α := αᵒᵈ) hv theorem HasBasis.limsup_eq_sInf_univ_of_empty {f : ι → α} {v : Filter ι} {p : ι' → Prop} {s : ι' → Set ι} (hv : v.HasBasis p s) (i : ι') (hi : p i) (h'i : s i = ∅) : limsup f v = sInf univ := HasBasis.liminf_eq_sSup_univ_of_empty (α := αᵒᵈ) hv i hi h'i @[simp] theorem liminf_nat_add (f : ℕ → α) (k : ℕ) : liminf (fun i => f (i + k)) atTop = liminf f atTop := by rw [← Function.comp_def, liminf, liminf, ← map_map, map_add_atTop_eq_nat] @[simp] theorem limsup_nat_add (f : ℕ → α) (k : ℕ) : limsup (fun i => f (i + k)) atTop = limsup f atTop := @liminf_nat_add αᵒᵈ _ f k end ConditionallyCompleteLattice section CompleteLattice variable [CompleteLattice α] @[simp] theorem limsSup_bot : limsSup (⊥ : Filter α) = ⊥ := bot_unique <| sInf_le <| by simp @[simp] theorem limsup_bot (f : β → α) : limsup f ⊥ = ⊥ := by simp [limsup] @[simp] theorem limsInf_bot : limsInf (⊥ : Filter α) = ⊤ := top_unique <| le_sSup <| by simp @[simp] theorem liminf_bot (f : β → α) : liminf f ⊥ = ⊤ := by simp [liminf] @[simp] theorem limsSup_top : limsSup (⊤ : Filter α) = ⊤ := top_unique <| le_sInf <| by simpa [eq_univ_iff_forall] using fun b hb => top_unique <| hb _ @[simp] theorem limsInf_top : limsInf (⊤ : Filter α) = ⊥ := bot_unique <| sSup_le <| by simpa [eq_univ_iff_forall] using fun b hb => bot_unique <| hb _ @[simp] theorem blimsup_false {f : Filter β} {u : β → α} : (blimsup u f fun _ => False) = ⊥ := by simp [blimsup_eq] @[simp] theorem bliminf_false {f : Filter β} {u : β → α} : (bliminf u f fun _ => False) = ⊤ := by simp [bliminf_eq] /-- Same as limsup_const applied to `⊥` but without the `NeBot f` assumption -/ @[simp] theorem limsup_const_bot {f : Filter β} : limsup (fun _ : β => (⊥ : α)) f = (⊥ : α) := by rw [limsup_eq, eq_bot_iff] exact sInf_le (Eventually.of_forall fun _ => le_rfl) /-- Same as limsup_const applied to `⊤` but without the `NeBot f` assumption -/ @[simp] theorem liminf_const_top {f : Filter β} : liminf (fun _ : β => (⊤ : α)) f = (⊤ : α) := limsup_const_bot (α := αᵒᵈ) theorem HasBasis.limsSup_eq_iInf_sSup {ι} {p : ι → Prop} {s} {f : Filter α} (h : f.HasBasis p s) : limsSup f = ⨅ (i) (_ : p i), sSup (s i) := le_antisymm (le_iInf₂ fun i hi => sInf_le <| h.eventually_iff.2 ⟨i, hi, fun _ => le_sSup⟩) (le_sInf fun _ ha => let ⟨_, hi, ha⟩ := h.eventually_iff.1 ha iInf₂_le_of_le _ hi <| sSup_le ha) theorem HasBasis.limsInf_eq_iSup_sInf {p : ι → Prop} {s : ι → Set α} {f : Filter α} (h : f.HasBasis p s) : limsInf f = ⨆ (i) (_ : p i), sInf (s i) := HasBasis.limsSup_eq_iInf_sSup (α := αᵒᵈ) h theorem limsSup_eq_iInf_sSup {f : Filter α} : limsSup f = ⨅ s ∈ f, sSup s := f.basis_sets.limsSup_eq_iInf_sSup theorem limsInf_eq_iSup_sInf {f : Filter α} : limsInf f = ⨆ s ∈ f, sInf s := limsSup_eq_iInf_sSup (α := αᵒᵈ) theorem limsup_le_iSup {f : Filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n := limsup_le_of_le (by isBoundedDefault) (Eventually.of_forall (le_iSup u)) theorem iInf_le_liminf {f : Filter β} {u : β → α} : ⨅ n, u n ≤ liminf u f := le_liminf_of_le (by isBoundedDefault) (Eventually.of_forall (iInf_le u)) /-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem limsup_eq_iInf_iSup {f : Filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a := (f.basis_sets.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] theorem limsup_eq_iInf_iSup_of_nat {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i ≥ n, u i := (atTop_basis.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, iInf_const]; rfl theorem limsup_eq_iInf_iSup_of_nat' {u : ℕ → α} : limsup u atTop = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) := by simp only [limsup_eq_iInf_iSup_of_nat, iSup_ge_eq_iSup_nat_add] theorem HasBasis.limsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : limsup u f = ⨅ (i) (_ : p i), ⨆ a ∈ s i, u a := (h.map u).limsSup_eq_iInf_sSup.trans <| by simp only [sSup_image, id] lemma limsSup_principal_eq_sSup (s : Set α) : limsSup (𝓟 s) = sSup s := by simpa only [limsSup, eventually_principal] using sInf_upperBounds_eq_csSup s lemma limsInf_principal_eq_sInf (s : Set α) : limsInf (𝓟 s) = sInf s := by simpa only [limsInf, eventually_principal] using sSup_lowerBounds_eq_sInf s @[simp] lemma limsup_top_eq_iSup (u : β → α) : limsup u ⊤ = ⨆ i, u i := by rw [limsup, map_top, limsSup_principal_eq_sSup, sSup_range] @[simp] lemma liminf_top_eq_iInf (u : β → α) : liminf u ⊤ = ⨅ i, u i := by rw [liminf, map_top, limsInf_principal_eq_sInf, sInf_range] theorem blimsup_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) : blimsup u f p = blimsup u f q := by simp only [blimsup_eq] congr with a refine eventually_congr (h.mono fun b hb => ?_) rcases eq_or_ne (u b) ⊥ with hu | hu; · simp [hu] rw [hb hu] theorem bliminf_congr' {f : Filter β} {p q : β → Prop} {u : β → α} (h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) : bliminf u f p = bliminf u f q := blimsup_congr' (α := αᵒᵈ) h lemma HasBasis.blimsup_eq_iInf_iSup {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (hf : f.HasBasis p s) {q : β → Prop} : blimsup u f q = ⨅ (i) (_ : p i), ⨆ a ∈ s i, ⨆ (_ : q a), u a := by simp only [blimsup_eq_limsup, (hf.inf_principal _).limsup_eq_iInf_iSup, mem_inter_iff, iSup_and, mem_setOf_eq] theorem blimsup_eq_iInf_biSup {f : Filter β} {p : β → Prop} {u : β → α} : blimsup u f p = ⨅ s ∈ f, ⨆ (b) (_ : p b ∧ b ∈ s), u b := by simp only [f.basis_sets.blimsup_eq_iInf_iSup, iSup_and', id, and_comm] theorem blimsup_eq_iInf_biSup_of_nat {p : ℕ → Prop} {u : ℕ → α} : blimsup u atTop p = ⨅ i, ⨆ (j) (_ : p j ∧ i ≤ j), u j := by simp only [atTop_basis.blimsup_eq_iInf_iSup, @and_comm (p _), iSup_and, mem_Ici, iInf_true] /-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter of the supremum of the function over `s` -/ theorem liminf_eq_iSup_iInf {f : Filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a := limsup_eq_iInf_iSup (α := αᵒᵈ) theorem liminf_eq_iSup_iInf_of_nat {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i ≥ n, u i := @limsup_eq_iInf_iSup_of_nat αᵒᵈ _ u theorem liminf_eq_iSup_iInf_of_nat' {u : ℕ → α} : liminf u atTop = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) := @limsup_eq_iInf_iSup_of_nat' αᵒᵈ _ _ theorem HasBasis.liminf_eq_iSup_iInf {p : ι → Prop} {s : ι → Set β} {f : Filter β} {u : β → α} (h : f.HasBasis p s) : liminf u f = ⨆ (i) (_ : p i), ⨅ a ∈ s i, u a := HasBasis.limsup_eq_iInf_iSup (α := αᵒᵈ) h theorem bliminf_eq_iSup_biInf {f : Filter β} {p : β → Prop} {u : β → α} : bliminf u f p = ⨆ s ∈ f, ⨅ (b) (_ : p b ∧ b ∈ s), u b := @blimsup_eq_iInf_biSup αᵒᵈ β _ f p u theorem bliminf_eq_iSup_biInf_of_nat {p : ℕ → Prop} {u : ℕ → α} : bliminf u atTop p = ⨆ i, ⨅ (j) (_ : p j ∧ i ≤ j), u j := @blimsup_eq_iInf_biSup_of_nat αᵒᵈ _ p u theorem limsup_eq_sInf_sSup {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : limsup a F = sInf ((fun I => sSup (a '' I)) '' F.sets) := by apply le_antisymm · rw [limsup_eq] refine sInf_le_sInf fun x hx => ?_ rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩ filter_upwards [I_mem_F] with i hi exact hI ▸ le_sSup (mem_image_of_mem _ hi) · refine le_sInf fun b hb => sInf_le_of_le (mem_image_of_mem _ hb) <| sSup_le ?_ rintro _ ⟨_, h, rfl⟩ exact h theorem liminf_eq_sSup_sInf {ι R : Type*} (F : Filter ι) [CompleteLattice R] (a : ι → R) : liminf a F = sSup ((fun I => sInf (a '' I)) '' F.sets) := @Filter.limsup_eq_sInf_sSup ι (OrderDual R) _ _ a theorem liminf_le_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) : liminf u f ≤ x := by rw [liminf_eq] refine sSup_le fun b hb => ?_ have hbx : ∃ᶠ _ in f, b ≤ x := by revert h rw [← not_imp_not, not_frequently, not_frequently] exact fun h => hb.mp (h.mono fun a hbx hba hax => hbx (hba.trans hax)) exact hbx.exists.choose_spec theorem le_limsup_of_frequently_le' {α β} [CompleteLattice β] {f : Filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) : x ≤ limsup u f := liminf_le_of_frequently_le' (β := βᵒᵈ) h /-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any `a : α` is a fixed point. -/ @[simp] theorem _root_.CompleteLatticeHom.apply_limsup_iterate (f : CompleteLatticeHom α α) (a : α) : f (limsup (fun n => f^[n] a) atTop) = limsup (fun n => f^[n] a) atTop := by rw [limsup_eq_iInf_iSup_of_nat', map_iInf] simp_rw [_root_.map_iSup, ← Function.comp_apply (f := f), ← Function.iterate_succ' f, ← Nat.add_succ] conv_rhs => rw [iInf_split _ (0 < ·)] simp only [not_lt, Nat.le_zero, iInf_iInf_eq_left, add_zero, iInf_nat_gt_zero_eq, left_eq_inf] refine (iInf_le (fun i => ⨆ j, f^[j + (i + 1)] a) 0).trans ?_ simp only [zero_add, Function.comp_apply, iSup_le_iff] exact fun i => le_iSup (fun i => f^[i] a) (i + 1) /-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any `a : α` is a fixed point. -/ theorem _root_.CompleteLatticeHom.apply_liminf_iterate (f : CompleteLatticeHom α α) (a : α) : f (liminf (fun n => f^[n] a) atTop) = liminf (fun n => f^[n] a) atTop := (CompleteLatticeHom.dual f).apply_limsup_iterate _ variable {f g : Filter β} {p q : β → Prop} {u v : β → α} theorem blimsup_mono (h : ∀ x, p x → q x) : blimsup u f p ≤ blimsup u f q := sInf_le_sInf fun a ha => ha.mono <| by tauto theorem bliminf_antitone (h : ∀ x, p x → q x) : bliminf u f q ≤ bliminf u f p := sSup_le_sSup fun a ha => ha.mono <| by tauto theorem mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := sInf_le_sInf fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.2 hx').trans (hx.1 hx') theorem mono_blimsup (h : ∀ x, p x → u x ≤ v x) : blimsup u f p ≤ blimsup v f p := mono_blimsup' <| Eventually.of_forall h
theorem mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) : bliminf u f p ≤ bliminf v f p := sSup_le_sSup fun _ ha => (ha.and h).mono fun _ hx hx' => (hx.1 hx').trans (hx.2 hx')
Mathlib/Order/LiminfLimsup.lean
515
517
/- Copyright (c) 2022 Jiale Miao. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jiale Miao, Kevin Buzzard, Alexander Bentkamp -/ import Mathlib.Analysis.InnerProductSpace.PiL2 import Mathlib.LinearAlgebra.Matrix.Block /-! # Gram-Schmidt Orthogonalization and Orthonormalization In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization. The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. ## Main results - `gramSchmidt` : the Gram-Schmidt process - `gramSchmidt_orthogonal` : `gramSchmidt` produces an orthogonal system of vectors. - `span_gramSchmidt` : `gramSchmidt` preserves span of vectors. - `gramSchmidt_ne_zero` : If the input vectors of `gramSchmidt` are linearly independent, then the output vectors are non-zero. - `gramSchmidt_basis` : The basis produced by the Gram-Schmidt process when given a basis as input. - `gramSchmidtNormed` : the normalized `gramSchmidt` (i.e each vector in `gramSchmidtNormed` has unit length.) - `gramSchmidt_orthonormal` : `gramSchmidtNormed` produces an orthornormal system of vectors. - `gramSchmidtOrthonormalBasis`: orthonormal basis constructed by the Gram-Schmidt process from an indexed set of vectors of the right size -/ open Finset Submodule Module variable (𝕜 : Type*) {E : Type*} [RCLike 𝕜] [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {ι : Type*} [LinearOrder ι] [LocallyFiniteOrderBot ι] [WellFoundedLT ι] attribute [local instance] IsWellOrder.toHasWellFounded local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- The Gram-Schmidt process takes a set of vectors as input and outputs a set of orthogonal vectors which have the same span. -/ noncomputable def gramSchmidt [WellFoundedLT ι] (f : ι → E) (n : ι) : E := f n - ∑ i : Iio n, (𝕜 ∙ gramSchmidt f i).orthogonalProjection (f n) termination_by n decreasing_by exact mem_Iio.1 i.2 /-- This lemma uses `∑ i in` instead of `∑ i :`. -/ theorem gramSchmidt_def (f : ι → E) (n : ι) : gramSchmidt 𝕜 f n = f n - ∑ i ∈ Iio n, (𝕜 ∙ gramSchmidt 𝕜 f i).orthogonalProjection (f n) := by rw [← sum_attach, attach_eq_univ, gramSchmidt] theorem gramSchmidt_def' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (𝕜 ∙ gramSchmidt 𝕜 f i).orthogonalProjection (f n) := by rw [gramSchmidt_def, sub_add_cancel] theorem gramSchmidt_def'' (f : ι → E) (n : ι) : f n = gramSchmidt 𝕜 f n + ∑ i ∈ Iio n, (⟪gramSchmidt 𝕜 f i, f n⟫ / (‖gramSchmidt 𝕜 f i‖ : 𝕜) ^ 2) • gramSchmidt 𝕜 f i := by convert gramSchmidt_def' 𝕜 f n rw [orthogonalProjection_singleton, RCLike.ofReal_pow] @[simp] theorem gramSchmidt_zero {ι : Type*} [LinearOrder ι] [LocallyFiniteOrder ι] [OrderBot ι] [WellFoundedLT ι] (f : ι → E) : gramSchmidt 𝕜 f ⊥ = f ⊥ := by rw [gramSchmidt_def, Iio_eq_Ico, Finset.Ico_self, Finset.sum_empty, sub_zero] /-- **Gram-Schmidt Orthogonalisation**: `gramSchmidt` produces an orthogonal system of vectors. -/ theorem gramSchmidt_orthogonal (f : ι → E) {a b : ι} (h₀ : a ≠ b) : ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := by suffices ∀ a b : ι, a < b → ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 by rcases h₀.lt_or_lt with ha | hb · exact this _ _ ha · rw [inner_eq_zero_symm] exact this _ _ hb clear h₀ a b intro a b h₀ revert a apply wellFounded_lt.induction b intro b ih a h₀ simp only [gramSchmidt_def 𝕜 f b, inner_sub_right, inner_sum, orthogonalProjection_singleton, inner_smul_right] rw [Finset.sum_eq_single_of_mem a (Finset.mem_Iio.mpr h₀)] · by_cases h : gramSchmidt 𝕜 f a = 0 · simp only [h, inner_zero_left, zero_div, zero_mul, sub_zero] · rw [RCLike.ofReal_pow, ← inner_self_eq_norm_sq_to_K, div_mul_cancel₀, sub_self] rwa [inner_self_ne_zero] intro i hi hia simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero] right rcases hia.lt_or_lt with hia₁ | hia₂ · rw [inner_eq_zero_symm] exact ih a h₀ i hia₁ · exact ih i (mem_Iio.1 hi) a hia₂ /-- This is another version of `gramSchmidt_orthogonal` using `Pairwise` instead. -/ theorem gramSchmidt_pairwise_orthogonal (f : ι → E) : Pairwise fun a b => ⟪gramSchmidt 𝕜 f a, gramSchmidt 𝕜 f b⟫ = 0 := fun _ _ => gramSchmidt_orthogonal 𝕜 f theorem gramSchmidt_inv_triangular (v : ι → E) {i j : ι} (hij : i < j) : ⟪gramSchmidt 𝕜 v j, v i⟫ = 0 := by rw [gramSchmidt_def'' 𝕜 v] simp only [inner_add_right, inner_sum, inner_smul_right] set b : ι → E := gramSchmidt 𝕜 v convert zero_add (0 : 𝕜) · exact gramSchmidt_orthogonal 𝕜 v hij.ne' apply Finset.sum_eq_zero rintro k hki' have hki : k < i := by simpa using hki' have : ⟪b j, b k⟫ = 0 := gramSchmidt_orthogonal 𝕜 v (hki.trans hij).ne' simp [this] open Submodule Set Order theorem mem_span_gramSchmidt (f : ι → E) {i j : ι} (hij : i ≤ j) : f i ∈ span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j) := by rw [gramSchmidt_def' 𝕜 f i] simp_rw [orthogonalProjection_singleton] exact Submodule.add_mem _ (subset_span <| mem_image_of_mem _ hij) (Submodule.sum_mem _ fun k hk => smul_mem (span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic j)) _ <| subset_span <| mem_image_of_mem (gramSchmidt 𝕜 f) <| (Finset.mem_Iio.1 hk).le.trans hij) theorem gramSchmidt_mem_span (f : ι → E) : ∀ {j i}, i ≤ j → gramSchmidt 𝕜 f i ∈ span 𝕜 (f '' Set.Iic j) := by intro j i hij rw [gramSchmidt_def 𝕜 f i] simp_rw [orthogonalProjection_singleton] refine Submodule.sub_mem _ (subset_span (mem_image_of_mem _ hij)) (Submodule.sum_mem _ fun k hk => ?_) let hkj : k < j := (Finset.mem_Iio.1 hk).trans_le hij exact smul_mem _ _ (span_mono (image_subset f <| Set.Iic_subset_Iic.2 hkj.le) <| gramSchmidt_mem_span _ le_rfl) termination_by j => j theorem span_gramSchmidt_Iic (f : ι → E) (c : ι) : span 𝕜 (gramSchmidt 𝕜 f '' Set.Iic c) = span 𝕜 (f '' Set.Iic c) := span_eq_span (Set.image_subset_iff.2 fun _ => gramSchmidt_mem_span _ _) <| Set.image_subset_iff.2 fun _ => mem_span_gramSchmidt _ _ theorem span_gramSchmidt_Iio (f : ι → E) (c : ι) : span 𝕜 (gramSchmidt 𝕜 f '' Set.Iio c) = span 𝕜 (f '' Set.Iio c) := span_eq_span (Set.image_subset_iff.2 fun _ hi => span_mono (image_subset _ <| Iic_subset_Iio.2 hi) <| gramSchmidt_mem_span _ _ le_rfl) <| Set.image_subset_iff.2 fun _ hi => span_mono (image_subset _ <| Iic_subset_Iio.2 hi) <| mem_span_gramSchmidt _ _ le_rfl /-- `gramSchmidt` preserves span of vectors. -/ theorem span_gramSchmidt (f : ι → E) : span 𝕜 (range (gramSchmidt 𝕜 f)) = span 𝕜 (range f) := span_eq_span (range_subset_iff.2 fun _ => span_mono (image_subset_range _ _) <| gramSchmidt_mem_span _ _ le_rfl) <| range_subset_iff.2 fun _ => span_mono (image_subset_range _ _) <| mem_span_gramSchmidt _ _ le_rfl theorem gramSchmidt_of_orthogonal {f : ι → E} (hf : Pairwise fun i j => ⟪f i, f j⟫ = 0) : gramSchmidt 𝕜 f = f := by ext i rw [gramSchmidt_def] trans f i - 0 · congr apply Finset.sum_eq_zero intro j hj rw [Submodule.coe_eq_zero] suffices span 𝕜 (f '' Set.Iic j) ⟂ 𝕜 ∙ f i by apply orthogonalProjection_mem_subspace_orthogonalComplement_eq_zero rw [mem_orthogonal_singleton_iff_inner_left] rw [← mem_orthogonal_singleton_iff_inner_right] exact this (gramSchmidt_mem_span 𝕜 f (le_refl j)) rw [isOrtho_span] rintro u ⟨k, hk, rfl⟩ v (rfl : v = f i) apply hf exact (lt_of_le_of_lt hk (Finset.mem_Iio.mp hj)).ne · simp variable {𝕜} theorem gramSchmidt_ne_zero_coe {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 (f ∘ ((↑) : Set.Iic n → ι))) : gramSchmidt 𝕜 f n ≠ 0 := by by_contra h have h₁ : f n ∈ span 𝕜 (f '' Set.Iio n) := by rw [← span_gramSchmidt_Iio 𝕜 f n, gramSchmidt_def' 𝕜 f, h, zero_add] apply Submodule.sum_mem _ _ intro a ha simp only [Set.mem_image, Set.mem_Iio, orthogonalProjection_singleton] apply Submodule.smul_mem _ _ _ rw [Finset.mem_Iio] at ha exact subset_span ⟨a, ha, by rfl⟩ have h₂ : (f ∘ ((↑) : Set.Iic n → ι)) ⟨n, le_refl n⟩ ∈ span 𝕜 (f ∘ ((↑) : Set.Iic n → ι) '' Set.Iio ⟨n, le_refl n⟩) := by rw [image_comp] simpa using h₁ apply LinearIndependent.not_mem_span_image h₀ _ h₂ simp only [Set.mem_Iio, lt_self_iff_false, not_false_iff] /-- If the input vectors of `gramSchmidt` are linearly independent, then the output vectors are non-zero. -/ theorem gramSchmidt_ne_zero {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 f) : gramSchmidt 𝕜 f n ≠ 0 := gramSchmidt_ne_zero_coe _ (LinearIndependent.comp h₀ _ Subtype.coe_injective) /-- `gramSchmidt` produces a triangular matrix of vectors when given a basis. -/ theorem gramSchmidt_triangular {i j : ι} (hij : i < j) (b : Basis ι 𝕜 E) : b.repr (gramSchmidt 𝕜 b i) j = 0 := by have : gramSchmidt 𝕜 b i ∈ span 𝕜 (gramSchmidt 𝕜 b '' Set.Iio j) := subset_span ((Set.mem_image _ _ _).2 ⟨i, hij, rfl⟩) have : gramSchmidt 𝕜 b i ∈ span 𝕜 (b '' Set.Iio j) := by rwa [← span_gramSchmidt_Iio 𝕜 b j] have : ↑(b.repr (gramSchmidt 𝕜 b i)).support ⊆ Set.Iio j := Basis.repr_support_subset_of_mem_span b (Set.Iio j) this exact (Finsupp.mem_supported' _ _).1 ((Finsupp.mem_supported 𝕜 _).2 this) j Set.not_mem_Iio_self /-- `gramSchmidt` produces linearly independent vectors when given linearly independent vectors. -/ theorem gramSchmidt_linearIndependent {f : ι → E} (h₀ : LinearIndependent 𝕜 f) : LinearIndependent 𝕜 (gramSchmidt 𝕜 f) := linearIndependent_of_ne_zero_of_inner_eq_zero (fun _ => gramSchmidt_ne_zero _ h₀) fun _ _ => gramSchmidt_orthogonal 𝕜 f /-- When given a basis, `gramSchmidt` produces a basis. -/ noncomputable def gramSchmidtBasis (b : Basis ι 𝕜 E) : Basis ι 𝕜 E := Basis.mk (gramSchmidt_linearIndependent b.linearIndependent) ((span_gramSchmidt 𝕜 b).trans b.span_eq).ge theorem coe_gramSchmidtBasis (b : Basis ι 𝕜 E) : (gramSchmidtBasis b : ι → E) = gramSchmidt 𝕜 b := Basis.coe_mk _ _ variable (𝕜) in /-- the normalized `gramSchmidt` (i.e each vector in `gramSchmidtNormed` has unit length.) -/ noncomputable def gramSchmidtNormed (f : ι → E) (n : ι) : E := (‖gramSchmidt 𝕜 f n‖ : 𝕜)⁻¹ • gramSchmidt 𝕜 f n theorem gramSchmidtNormed_unit_length_coe {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 (f ∘ ((↑) : Set.Iic n → ι))) : ‖gramSchmidtNormed 𝕜 f n‖ = 1 := by simp only [gramSchmidt_ne_zero_coe n h₀, gramSchmidtNormed, norm_smul_inv_norm, Ne, not_false_iff] theorem gramSchmidtNormed_unit_length {f : ι → E} (n : ι) (h₀ : LinearIndependent 𝕜 f) : ‖gramSchmidtNormed 𝕜 f n‖ = 1 := gramSchmidtNormed_unit_length_coe _ (LinearIndependent.comp h₀ _ Subtype.coe_injective) theorem gramSchmidtNormed_unit_length' {f : ι → E} {n : ι} (hn : gramSchmidtNormed 𝕜 f n ≠ 0) : ‖gramSchmidtNormed 𝕜 f n‖ = 1 := by rw [gramSchmidtNormed] at * rw [norm_smul_inv_norm] simpa using hn /-- **Gram-Schmidt Orthonormalization**: `gramSchmidtNormed` applied to a linearly independent set of vectors produces an orthornormal system of vectors. -/ theorem gramSchmidt_orthonormal {f : ι → E} (h₀ : LinearIndependent 𝕜 f) : Orthonormal 𝕜 (gramSchmidtNormed 𝕜 f) := by unfold Orthonormal constructor · simp only [gramSchmidtNormed_unit_length, h₀, eq_self_iff_true, imp_true_iff] · intro i j hij simp only [gramSchmidtNormed, inner_smul_left, inner_smul_right, RCLike.conj_inv, RCLike.conj_ofReal, mul_eq_zero, inv_eq_zero, RCLike.ofReal_eq_zero, norm_eq_zero] repeat' right exact gramSchmidt_orthogonal 𝕜 f hij /-- **Gram-Schmidt Orthonormalization**: `gramSchmidtNormed` produces an orthornormal system of vectors after removing the vectors which become zero in the process. -/ theorem gramSchmidt_orthonormal' (f : ι → E) : Orthonormal 𝕜 fun i : { i | gramSchmidtNormed 𝕜 f i ≠ 0 } => gramSchmidtNormed 𝕜 f i := by refine ⟨fun i => gramSchmidtNormed_unit_length' i.prop, ?_⟩ rintro i j (hij : ¬_) rw [Subtype.ext_iff] at hij simp [gramSchmidtNormed, inner_smul_left, inner_smul_right, gramSchmidt_orthogonal 𝕜 f hij] theorem span_gramSchmidtNormed (f : ι → E) (s : Set ι) : span 𝕜 (gramSchmidtNormed 𝕜 f '' s) = span 𝕜 (gramSchmidt 𝕜 f '' s) := by refine span_eq_span (Set.image_subset_iff.2 fun i hi => smul_mem _ _ <| subset_span <| mem_image_of_mem _ hi) (Set.image_subset_iff.2 fun i hi => span_mono (image_subset _ <| singleton_subset_set_iff.2 hi) ?_) simp only [coe_singleton, Set.image_singleton] by_cases h : gramSchmidt 𝕜 f i = 0 · simp [h] · refine mem_span_singleton.2 ⟨‖gramSchmidt 𝕜 f i‖, smul_inv_smul₀ ?_ _⟩ exact mod_cast norm_ne_zero_iff.2 h theorem span_gramSchmidtNormed_range (f : ι → E) : span 𝕜 (range (gramSchmidtNormed 𝕜 f)) = span 𝕜 (range (gramSchmidt 𝕜 f)) := by simpa only [image_univ.symm] using span_gramSchmidtNormed f univ section OrthonormalBasis variable [Fintype ι] [FiniteDimensional 𝕜 E] (h : finrank 𝕜 E = Fintype.card ι) (f : ι → E) /-- Given an indexed family `f : ι → E` of vectors in an inner product space `E`, for which the size of the index set is the dimension of `E`, produce an orthonormal basis for `E` which agrees with the orthonormal set produced by the Gram-Schmidt orthonormalization process on the elements of
`ι` for which this process gives a nonzero number. -/ noncomputable def gramSchmidtOrthonormalBasis : OrthonormalBasis ι 𝕜 E := ((gramSchmidt_orthonormal' f).exists_orthonormalBasis_extension_of_card_eq (v := gramSchmidtNormed 𝕜 f) h).choose theorem gramSchmidtOrthonormalBasis_apply {f : ι → E} {i : ι} (hi : gramSchmidtNormed 𝕜 f i ≠ 0) :
Mathlib/Analysis/InnerProductSpace/GramSchmidtOrtho.lean
300
305
/- 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] theorem fderiv_add_const (c : F) : fderiv 𝕜 (fun y => f y + c) x = fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_add_const] @[simp] theorem hasFDerivAtFilter_const_add_iff (c : F) : HasFDerivAtFilter (c + f ·) f' x L ↔ HasFDerivAtFilter f f' x L := by simpa only [add_comm] using hasFDerivAtFilter_add_const_iff c alias ⟨_, HasFDerivAtFilter.const_add⟩ := hasFDerivAtFilter_const_add_iff @[simp] theorem hasStrictFDerivAt_const_add_iff (c : F) : HasStrictFDerivAt (c + f ·) f' x ↔ HasStrictFDerivAt f f' x := by simpa only [add_comm] using hasStrictFDerivAt_add_const_iff c @[fun_prop] alias ⟨_, HasStrictFDerivAt.const_add⟩ := hasStrictFDerivAt_const_add_iff @[simp] theorem hasFDerivWithinAt_const_add_iff (c : F) : HasFDerivWithinAt (c + f ·) f' s x ↔ HasFDerivWithinAt f f' s x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟨_, HasFDerivWithinAt.const_add⟩ := hasFDerivWithinAt_const_add_iff @[simp] theorem hasFDerivAt_const_add_iff (c : F) : HasFDerivAt (c + f ·) f' x ↔ HasFDerivAt f f' x := hasFDerivAtFilter_const_add_iff c @[fun_prop] alias ⟨_, HasFDerivAt.const_add⟩ := hasFDerivAt_const_add_iff @[simp] theorem differentiableWithinAt_const_add_iff (c : F) : DifferentiableWithinAt 𝕜 (fun y => c + f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := exists_congr fun _ ↦ hasFDerivWithinAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableWithinAt.const_add⟩ := differentiableWithinAt_const_add_iff @[simp] theorem differentiableAt_const_add_iff (c : F) : DifferentiableAt 𝕜 (fun y => c + f y) x ↔ DifferentiableAt 𝕜 f x := exists_congr fun _ ↦ hasFDerivAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableAt.const_add⟩ := differentiableAt_const_add_iff @[simp] theorem differentiableOn_const_add_iff (c : F) : DifferentiableOn 𝕜 (fun y => c + f y) s ↔ DifferentiableOn 𝕜 f s := forall₂_congr fun _ _ ↦ differentiableWithinAt_const_add_iff c @[fun_prop] alias ⟨_, DifferentiableOn.const_add⟩ := differentiableOn_const_add_iff @[simp] theorem differentiable_const_add_iff (c : F) : (Differentiable 𝕜 fun y => c + f y) ↔ Differentiable 𝕜 f := forall_congr' fun _ ↦ differentiableAt_const_add_iff c @[fun_prop] alias ⟨_, Differentiable.const_add⟩ := differentiable_const_add_iff @[simp] theorem fderivWithin_const_add (c : F) : fderivWithin 𝕜 (fun y => c + f y) s x = fderivWithin 𝕜 f s x := by simpa only [add_comm] using fderivWithin_add_const c @[simp] theorem fderiv_const_add (c : F) : fderiv 𝕜 (fun y => c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] end Add section Sum /-! ### Derivative of a finite sum of functions -/ variable {ι : Type*} {u : Finset ι} {A : ι → E → F} {A' : ι → E →L[𝕜] F} @[fun_prop] theorem HasStrictFDerivAt.sum (h : ∀ i ∈ u, HasStrictFDerivAt (A i) (A' i) x) : HasStrictFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := by simp only [hasStrictFDerivAt_iff_isLittleO] at * convert IsLittleO.sum h simp [Finset.sum_sub_distrib, ContinuousLinearMap.sum_apply] theorem HasFDerivAtFilter.sum (h : ∀ i ∈ u, HasFDerivAtFilter (A i) (A' i) x L) : HasFDerivAtFilter (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x L := by simp only [hasFDerivAtFilter_iff_isLittleO] at * convert IsLittleO.sum h simp [ContinuousLinearMap.sum_apply] @[fun_prop] theorem HasFDerivWithinAt.sum (h : ∀ i ∈ u, HasFDerivWithinAt (A i) (A' i) s x) : HasFDerivWithinAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) s x := HasFDerivAtFilter.sum h @[fun_prop] theorem HasFDerivAt.sum (h : ∀ i ∈ u, HasFDerivAt (A i) (A' i) x) : HasFDerivAt (fun y => ∑ i ∈ u, A i y) (∑ i ∈ u, A' i) x := HasFDerivAtFilter.sum h @[fun_prop] theorem DifferentiableWithinAt.sum (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : DifferentiableWithinAt 𝕜 (fun y => ∑ i ∈ u, A i y) s x := HasFDerivWithinAt.differentiableWithinAt <| HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt @[simp, fun_prop] theorem DifferentiableAt.sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : DifferentiableAt 𝕜 (fun y => ∑ i ∈ u, A i y) x := HasFDerivAt.differentiableAt <| HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt @[fun_prop] theorem DifferentiableOn.sum (h : ∀ i ∈ u, DifferentiableOn 𝕜 (A i) s) : DifferentiableOn 𝕜 (fun y => ∑ i ∈ u, A i y) s := fun x hx => DifferentiableWithinAt.sum fun i hi => h i hi x hx @[simp, fun_prop] theorem Differentiable.sum (h : ∀ i ∈ u, Differentiable 𝕜 (A i)) : Differentiable 𝕜 fun y => ∑ i ∈ u, A i y := fun x => DifferentiableAt.sum fun i hi => h i hi x theorem fderivWithin_sum (hxs : UniqueDiffWithinAt 𝕜 s x) (h : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (A i) s x) : fderivWithin 𝕜 (fun y => ∑ i ∈ u, A i y) s x = ∑ i ∈ u, fderivWithin 𝕜 (A i) s x := (HasFDerivWithinAt.sum fun i hi => (h i hi).hasFDerivWithinAt).fderivWithin hxs theorem fderiv_sum (h : ∀ i ∈ u, DifferentiableAt 𝕜 (A i) x) : fderiv 𝕜 (fun y => ∑ i ∈ u, A i y) x = ∑ i ∈ u, fderiv 𝕜 (A i) x := (HasFDerivAt.sum fun i hi => (h i hi).hasFDerivAt).fderiv end Sum section Neg /-! ### Derivative of the negative of a function -/ @[fun_prop] theorem HasStrictFDerivAt.neg (h : HasStrictFDerivAt f f' x) : HasStrictFDerivAt (fun x => -f x) (-f') x := (-1 : F →L[𝕜] F).hasStrictFDerivAt.comp x h theorem HasFDerivAtFilter.neg (h : HasFDerivAtFilter f f' x L) : HasFDerivAtFilter (fun x => -f x) (-f') x L := (-1 : F →L[𝕜] F).hasFDerivAtFilter.comp x h tendsto_map @[fun_prop] nonrec theorem HasFDerivWithinAt.neg (h : HasFDerivWithinAt f f' s x) : HasFDerivWithinAt (fun x => -f x) (-f') s x := h.neg @[fun_prop] nonrec theorem HasFDerivAt.neg (h : HasFDerivAt f f' x) : HasFDerivAt (fun x => -f x) (-f') x := h.neg @[fun_prop] theorem DifferentiableWithinAt.neg (h : DifferentiableWithinAt 𝕜 f s x) : DifferentiableWithinAt 𝕜 (fun y => -f y) s x := h.hasFDerivWithinAt.neg.differentiableWithinAt @[simp] theorem differentiableWithinAt_neg_iff : DifferentiableWithinAt 𝕜 (fun y => -f y) s x ↔ DifferentiableWithinAt 𝕜 f s x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableAt.neg (h : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => -f y) x := h.hasFDerivAt.neg.differentiableAt @[simp] theorem differentiableAt_neg_iff : DifferentiableAt 𝕜 (fun y => -f y) x ↔ DifferentiableAt 𝕜 f x := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem DifferentiableOn.neg (h : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => -f y) s := fun x hx => (h x hx).neg @[simp] theorem differentiableOn_neg_iff : DifferentiableOn 𝕜 (fun y => -f y) s ↔ DifferentiableOn 𝕜 f s := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ @[fun_prop] theorem Differentiable.neg (h : Differentiable 𝕜 f) : Differentiable 𝕜 fun y => -f y := fun x => (h x).neg @[simp] theorem differentiable_neg_iff : (Differentiable 𝕜 fun y => -f y) ↔ Differentiable 𝕜 f := ⟨fun h => by simpa only [neg_neg] using h.neg, fun h => h.neg⟩ theorem fderivWithin_neg (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (fun y => -f y) s x = -fderivWithin 𝕜 f s x := by classical by_cases h : DifferentiableWithinAt 𝕜 f s x · exact h.hasFDerivWithinAt.neg.fderivWithin hxs · rw [fderivWithin_zero_of_not_differentiableWithinAt h, fderivWithin_zero_of_not_differentiableWithinAt, neg_zero] simpa /-- Version of `fderivWithin_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/ theorem fderivWithin_neg' (hxs : UniqueDiffWithinAt 𝕜 s x) : fderivWithin 𝕜 (-f) s x = -fderivWithin 𝕜 f s x := fderivWithin_neg hxs @[simp] theorem fderiv_neg : fderiv 𝕜 (fun y => -f y) x = -fderiv 𝕜 f x := by simp only [← fderivWithin_univ, fderivWithin_neg uniqueDiffWithinAt_univ] /-- Version of `fderiv_neg` where the function is written `-f` instead of `fun y ↦ - f y`. -/ theorem fderiv_neg' : fderiv 𝕜 (-f) x = -fderiv 𝕜 f x := fderiv_neg end Neg section Sub /-! ### Derivative of the difference of two functions -/ @[fun_prop] theorem HasStrictFDerivAt.sub (hf : HasStrictFDerivAt f f' x) (hg : HasStrictFDerivAt g g' x) : HasStrictFDerivAt (fun x => f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem HasFDerivAtFilter.sub (hf : HasFDerivAtFilter f f' x L) (hg : HasFDerivAtFilter g g' x L) : HasFDerivAtFilter (fun x => f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg @[fun_prop] nonrec theorem HasFDerivWithinAt.sub (hf : HasFDerivWithinAt f f' s x) (hg : HasFDerivWithinAt g g' s x) : HasFDerivWithinAt (fun x => f x - g x) (f' - g') s x := hf.sub hg @[fun_prop] nonrec theorem HasFDerivAt.sub (hf : HasFDerivAt f f' x) (hg : HasFDerivAt g g' x) : HasFDerivAt (fun x => f x - g x) (f' - g') x := hf.sub hg @[fun_prop] theorem DifferentiableWithinAt.sub (hf : DifferentiableWithinAt 𝕜 f s x) (hg : DifferentiableWithinAt 𝕜 g s x) : DifferentiableWithinAt 𝕜 (fun y => f y - g y) s x := (hf.hasFDerivWithinAt.sub hg.hasFDerivWithinAt).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.sub (hf : DifferentiableAt 𝕜 f x) (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x := (hf.hasFDerivAt.sub hg.hasFDerivAt).differentiableAt @[simp] lemma DifferentiableAt.add_iff_left (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y + g y) x ↔ DifferentiableAt 𝕜 f x := by refine ⟨fun h ↦ ?_, fun hf ↦ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma DifferentiableAt.add_iff_right (hg : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => f y + g y) x ↔ DifferentiableAt 𝕜 g x := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma DifferentiableAt.sub_iff_left (hg : DifferentiableAt 𝕜 g x) : DifferentiableAt 𝕜 (fun y => f y - g y) x ↔ DifferentiableAt 𝕜 f x := by simp only [sub_eq_add_neg, differentiableAt_neg_iff, hg, add_iff_left] @[simp] lemma DifferentiableAt.sub_iff_right (hg : DifferentiableAt 𝕜 f x) : DifferentiableAt 𝕜 (fun y => f y - g y) x ↔ DifferentiableAt 𝕜 g x := by simp only [sub_eq_add_neg, hg, add_iff_right, differentiableAt_neg_iff] @[fun_prop] theorem DifferentiableOn.sub (hf : DifferentiableOn 𝕜 f s) (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s := fun x hx => (hf x hx).sub (hg x hx) @[simp] lemma DifferentiableOn.add_iff_left (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y + g y) s ↔ DifferentiableOn 𝕜 f s := by refine ⟨fun h ↦ ?_, fun hf ↦ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma DifferentiableOn.add_iff_right (hg : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => f y + g y) s ↔ DifferentiableOn 𝕜 g s := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma DifferentiableOn.sub_iff_left (hg : DifferentiableOn 𝕜 g s) : DifferentiableOn 𝕜 (fun y => f y - g y) s ↔ DifferentiableOn 𝕜 f s := by simp only [sub_eq_add_neg, differentiableOn_neg_iff, hg, add_iff_left] @[simp] lemma DifferentiableOn.sub_iff_right (hg : DifferentiableOn 𝕜 f s) : DifferentiableOn 𝕜 (fun y => f y - g y) s ↔ DifferentiableOn 𝕜 g s := by simp only [sub_eq_add_neg, differentiableOn_neg_iff, hg, add_iff_right] @[simp, fun_prop] theorem Differentiable.sub (hf : Differentiable 𝕜 f) (hg : Differentiable 𝕜 g) : Differentiable 𝕜 fun y => f y - g y := fun x => (hf x).sub (hg x) @[simp] lemma Differentiable.add_iff_left (hg : Differentiable 𝕜 g) : Differentiable 𝕜 (fun y => f y + g y) ↔ Differentiable 𝕜 f := by refine ⟨fun h ↦ ?_, fun hf ↦ hf.add hg⟩ simpa only [add_sub_cancel_right] using h.sub hg @[simp] lemma Differentiable.add_iff_right (hg : Differentiable 𝕜 f) : Differentiable 𝕜 (fun y => f y + g y) ↔ Differentiable 𝕜 g := by simp only [add_comm (f _), hg.add_iff_left] @[simp] lemma Differentiable.sub_iff_left (hg : Differentiable 𝕜 g) : Differentiable 𝕜 (fun y => f y - g y) ↔ Differentiable 𝕜 f := by
simp only [sub_eq_add_neg, differentiable_neg_iff, hg, add_iff_left] @[simp]
Mathlib/Analysis/Calculus/FDeriv/Add.lean
556
558
/- 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.Bornology.Constructions import Mathlib.Topology.MetricSpace.Pseudo.Defs import Mathlib.Topology.UniformSpace.UniformEmbedding /-! # Products of pseudometric spaces and other constructions This file constructs the supremum distance on binary products of pseudometric spaces and provides instances for type synonyms. -/ open Bornology Filter Metric Set Topology open scoped NNReal variable {α β : Type*} [PseudoMetricSpace α] /-- Pseudometric space structure pulled back by a function. -/ abbrev PseudoMetricSpace.induced {α β} (f : α → β) (m : PseudoMetricSpace β) : PseudoMetricSpace α where dist x y := dist (f x) (f y) dist_self _ := dist_self _ dist_comm _ _ := dist_comm _ _ dist_triangle _ _ _ := dist_triangle _ _ _ edist x y := edist (f x) (f y) edist_dist _ _ := edist_dist _ _ toUniformSpace := UniformSpace.comap f m.toUniformSpace uniformity_dist := (uniformity_basis_dist.comap _).eq_biInf toBornology := Bornology.induced f cobounded_sets := Set.ext fun s => mem_comap_iff_compl.trans <| by simp only [← isBounded_def, isBounded_iff, forall_mem_image, mem_setOf] /-- Pull back a pseudometric space structure by an inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `TopologicalSpace` structure. -/ def Topology.IsInducing.comapPseudoMetricSpace {α β : Type*} [TopologicalSpace α] [m : PseudoMetricSpace β] {f : α → β} (hf : IsInducing f) : PseudoMetricSpace α := .replaceTopology (.induced f m) hf.eq_induced @[deprecated (since := "2024-10-28")] alias Inducing.comapPseudoMetricSpace := IsInducing.comapPseudoMetricSpace /-- Pull back a pseudometric space structure by a uniform inducing map. This is a version of `PseudoMetricSpace.induced` useful in case if the domain already has a `UniformSpace` structure. -/ def IsUniformInducing.comapPseudoMetricSpace {α β} [UniformSpace α] [m : PseudoMetricSpace β] (f : α → β) (h : IsUniformInducing f) : PseudoMetricSpace α := .replaceUniformity (.induced f m) h.comap_uniformity.symm instance Subtype.pseudoMetricSpace {p : α → Prop} : PseudoMetricSpace (Subtype p) := PseudoMetricSpace.induced Subtype.val ‹_› lemma Subtype.dist_eq {p : α → Prop} (x y : Subtype p) : dist x y = dist (x : α) y := rfl lemma Subtype.nndist_eq {p : α → Prop} (x y : Subtype p) : nndist x y = nndist (x : α) y := rfl namespace MulOpposite @[to_additive] instance instPseudoMetricSpace : PseudoMetricSpace αᵐᵒᵖ := PseudoMetricSpace.induced MulOpposite.unop ‹_› @[to_additive (attr := simp)] lemma dist_unop (x y : αᵐᵒᵖ) : dist (unop x) (unop y) = dist x y := rfl @[to_additive (attr := simp)] lemma dist_op (x y : α) : dist (op x) (op y) = dist x y := rfl @[to_additive (attr := simp)] lemma nndist_unop (x y : αᵐᵒᵖ) : nndist (unop x) (unop y) = nndist x y := rfl @[to_additive (attr := simp)] lemma nndist_op (x y : α) : nndist (op x) (op y) = nndist x y := rfl end MulOpposite section NNReal instance : PseudoMetricSpace ℝ≥0 := Subtype.pseudoMetricSpace lemma NNReal.dist_eq (a b : ℝ≥0) : dist a b = |(a : ℝ) - b| := rfl lemma NNReal.nndist_eq (a b : ℝ≥0) : nndist a b = max (a - b) (b - a) := eq_of_forall_ge_iff fun _ => by simp only [max_le_iff, tsub_le_iff_right (α := ℝ≥0)] simp only [← NNReal.coe_le_coe, coe_nndist, dist_eq, abs_sub_le_iff, tsub_le_iff_right, NNReal.coe_add] @[simp] lemma NNReal.nndist_zero_eq_val (z : ℝ≥0) : nndist 0 z = z := by simp only [NNReal.nndist_eq, max_eq_right, tsub_zero, zero_tsub, zero_le'] @[simp] lemma NNReal.nndist_zero_eq_val' (z : ℝ≥0) : nndist z 0 = z := by rw [nndist_comm] exact NNReal.nndist_zero_eq_val z lemma NNReal.le_add_nndist (a b : ℝ≥0) : a ≤ b + nndist a b := by suffices (a : ℝ) ≤ (b : ℝ) + dist a b by rwa [← NNReal.coe_le_coe, NNReal.coe_add, coe_nndist] rw [← sub_le_iff_le_add'] exact le_of_abs_le (dist_eq a b).ge lemma NNReal.ball_zero_eq_Ico' (c : ℝ≥0) : Metric.ball (0 : ℝ≥0) c.toReal = Set.Ico 0 c := by ext x; simp lemma NNReal.ball_zero_eq_Ico (c : ℝ) : Metric.ball (0 : ℝ≥0) c = Set.Ico 0 c.toNNReal := by by_cases c_pos : 0 < c · convert NNReal.ball_zero_eq_Ico' ⟨c, c_pos.le⟩ simp [Real.toNNReal, c_pos.le] simp [not_lt.mp c_pos] lemma NNReal.closedBall_zero_eq_Icc' (c : ℝ≥0) : Metric.closedBall (0 : ℝ≥0) c.toReal = Set.Icc 0 c := by ext x; simp lemma NNReal.closedBall_zero_eq_Icc {c : ℝ} (c_nn : 0 ≤ c) : Metric.closedBall (0 : ℝ≥0) c = Set.Icc 0 c.toNNReal := by convert NNReal.closedBall_zero_eq_Icc' ⟨c, c_nn⟩ simp [Real.toNNReal, c_nn] end NNReal namespace ULift variable [PseudoMetricSpace β] instance : PseudoMetricSpace (ULift β) := PseudoMetricSpace.induced ULift.down ‹_› lemma dist_eq (x y : ULift β) : dist x y = dist x.down y.down := rfl lemma nndist_eq (x y : ULift β) : nndist x y = nndist x.down y.down := rfl @[simp] lemma dist_up_up (x y : β) : dist (ULift.up x) (ULift.up y) = dist x y := rfl @[simp] lemma nndist_up_up (x y : β) : nndist (ULift.up x) (ULift.up y) = nndist x y := rfl end ULift section Prod variable [PseudoMetricSpace β] instance Prod.pseudoMetricSpaceMax : PseudoMetricSpace (α × β) := let i := PseudoEMetricSpace.toPseudoMetricSpaceOfDist (fun x y : α × β => dist x.1 y.1 ⊔ dist x.2 y.2) (fun _ _ => (max_lt (edist_lt_top _ _) (edist_lt_top _ _)).ne) fun x y => by simp only [dist_edist, ← ENNReal.toReal_max (edist_ne_top _ _) (edist_ne_top _ _), Prod.edist_eq] i.replaceBornology fun s => by simp only [← isBounded_image_fst_and_snd, isBounded_iff_eventually, forall_mem_image, ← eventually_and, ← forall_and, ← max_le_iff] rfl lemma Prod.dist_eq {x y : α × β} : dist x y = max (dist x.1 y.1) (dist x.2 y.2) := rfl @[simp] lemma dist_prod_same_left {x : α} {y₁ y₂ : β} : dist (x, y₁) (x, y₂) = dist y₁ y₂ := by simp [Prod.dist_eq, dist_nonneg] @[simp] lemma dist_prod_same_right {x₁ x₂ : α} {y : β} : dist (x₁, y) (x₂, y) = dist x₁ x₂ := by simp [Prod.dist_eq, dist_nonneg] lemma ball_prod_same (x : α) (y : β) (r : ℝ) : ball x r ×ˢ ball y r = ball (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma closedBall_prod_same (x : α) (y : β) (r : ℝ) : closedBall x r ×ˢ closedBall y r = closedBall (x, y) r := ext fun z => by simp [Prod.dist_eq] lemma sphere_prod (x : α × β) (r : ℝ) : sphere x r = sphere x.1 r ×ˢ closedBall x.2 r ∪ closedBall x.1 r ×ˢ sphere x.2 r := by obtain hr | rfl | hr := lt_trichotomy r 0 · simp [hr] · cases x simp_rw [← closedBall_eq_sphere_of_nonpos le_rfl, union_self, closedBall_prod_same] · ext ⟨x', y'⟩ simp_rw [Set.mem_union, Set.mem_prod, Metric.mem_closedBall, Metric.mem_sphere, Prod.dist_eq, max_eq_iff] refine or_congr (and_congr_right ?_) (and_comm.trans (and_congr_left ?_)) all_goals rintro rfl; rfl end Prod lemma uniformContinuous_dist : UniformContinuous fun p : α × α => dist p.1 p.2 := Metric.uniformContinuous_iff.2 fun ε ε0 => ⟨ε / 2, half_pos ε0, fun {a b} h => calc dist (dist a.1 a.2) (dist b.1 b.2) ≤ dist a.1 b.1 + dist a.2 b.2 := dist_dist_dist_le _ _ _ _ _ ≤ dist a b + dist a b := add_le_add (le_max_left _ _) (le_max_right _ _) _ < ε / 2 + ε / 2 := add_lt_add h h _ = ε := add_halves ε⟩
protected lemma UniformContinuous.dist [UniformSpace β] {f g : β → α} (hf : UniformContinuous f)
Mathlib/Topology/MetricSpace/Pseudo/Constructions.lean
195
196
/- Copyright (c) 2020 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Patrick Massot, Eric Wieser -/ import Mathlib.Algebra.Group.Defs import Mathlib.Algebra.Notation.Pi import Mathlib.Data.Sum.Basic import Mathlib.Logic.Unique import Mathlib.Tactic.Spread /-! # Instances and theorems on pi types This file provides instances for the typeclass defined in `Algebra.Group.Defs`. More sophisticated instances are defined in `Algebra.Group.Pi.Lemmas` files elsewhere. ## Porting note This file relied on the `pi_instance` tactic, which was not available at the time of porting. The comment `--pi_instance` is inserted before all fields which were previously derived by `pi_instance`. See this Zulip discussion: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/not.20porting.20pi_instance] -/ -- We enforce to only import `Algebra.Group.Defs` and basic logic assert_not_exists Set.range MonoidHom MonoidWithZero DenselyOrdered open Function universe u v₁ v₂ v₃ variable {I : Type u} -- The indexing type variable {α β γ : Type*} -- The families of types already equipped with instances variable {f : I → Type v₁} {g : I → Type v₂} {h : I → Type v₃} variable (x y : ∀ i, f i) (i : I) namespace Pi @[to_additive] instance semigroup [∀ i, Semigroup (f i)] : Semigroup (∀ i, f i) where mul_assoc := by intros; ext; exact mul_assoc _ _ _ @[to_additive] instance commSemigroup [∀ i, CommSemigroup (f i)] : CommSemigroup (∀ i, f i) where mul_comm := by intros; ext; exact mul_comm _ _ @[to_additive] instance mulOneClass [∀ i, MulOneClass (f i)] : MulOneClass (∀ i, f i) where one_mul := by intros; ext; exact one_mul _ mul_one := by intros; ext; exact mul_one _ @[to_additive] instance invOneClass [∀ i, InvOneClass (f i)] : InvOneClass (∀ i, f i) where inv_one := by ext; exact inv_one @[to_additive] instance monoid [∀ i, Monoid (f i)] : Monoid (∀ i, f i) where __ := semigroup __ := mulOneClass npow := fun n x i => x i ^ n npow_zero := by intros; ext; exact Monoid.npow_zero _ npow_succ := by intros; ext; exact Monoid.npow_succ _ _ @[to_additive] instance commMonoid [∀ i, CommMonoid (f i)] : CommMonoid (∀ i, f i) := { monoid, commSemigroup with } @[to_additive Pi.subNegMonoid] instance divInvMonoid [∀ i, DivInvMonoid (f i)] : DivInvMonoid (∀ i, f i) where zpow := fun z x i => x i ^ z div_eq_mul_inv := by intros; ext; exact div_eq_mul_inv _ _ zpow_zero' := by intros; ext; exact DivInvMonoid.zpow_zero' _ zpow_succ' := by intros; ext; exact DivInvMonoid.zpow_succ' _ _ zpow_neg' := by intros; ext; exact DivInvMonoid.zpow_neg' _ _ @[to_additive] instance divInvOneMonoid [∀ i, DivInvOneMonoid (f i)] : DivInvOneMonoid (∀ i, f i) where inv_one := by ext; exact inv_one @[to_additive] instance involutiveInv [∀ i, InvolutiveInv (f i)] : InvolutiveInv (∀ i, f i) where inv_inv := by intros; ext; exact inv_inv _ @[to_additive] instance divisionMonoid [∀ i, DivisionMonoid (f i)] : DivisionMonoid (∀ i, f i) where __ := divInvMonoid __ := involutiveInv mul_inv_rev := by intros; ext; exact mul_inv_rev _ _ inv_eq_of_mul := by intros _ _ h; ext; exact DivisionMonoid.inv_eq_of_mul _ _ (congrFun h _) @[to_additive instSubtractionCommMonoid] instance divisionCommMonoid [∀ i, DivisionCommMonoid (f i)] : DivisionCommMonoid (∀ i, f i) := { divisionMonoid, commSemigroup with } @[to_additive] instance group [∀ i, Group (f i)] : Group (∀ i, f i) where inv_mul_cancel := by intros; ext; exact inv_mul_cancel _ @[to_additive] instance commGroup [∀ i, CommGroup (f i)] : CommGroup (∀ i, f i) := { group, commMonoid with } @[to_additive] instance instIsLeftCancelMul [∀ i, Mul (f i)] [∀ i, IsLeftCancelMul (f i)] : IsLeftCancelMul (∀ i, f i) where mul_left_cancel _ _ _ h := funext fun _ ↦ mul_left_cancel (congr_fun h _) @[to_additive] instance instIsRightCancelMul [∀ i, Mul (f i)] [∀ i, IsRightCancelMul (f i)] : IsRightCancelMul (∀ i, f i) where mul_right_cancel _ _ _ h := funext fun _ ↦ mul_right_cancel (congr_fun h _) @[to_additive] instance instIsCancelMul [∀ i, Mul (f i)] [∀ i, IsCancelMul (f i)] : IsCancelMul (∀ i, f i) where @[to_additive] instance leftCancelSemigroup [∀ i, LeftCancelSemigroup (f i)] : LeftCancelSemigroup (∀ i, f i) := { semigroup with mul_left_cancel := fun _ _ _ => mul_left_cancel } @[to_additive] instance rightCancelSemigroup [∀ i, RightCancelSemigroup (f i)] : RightCancelSemigroup (∀ i, f i) := { semigroup with mul_right_cancel := fun _ _ _ => mul_right_cancel } @[to_additive] instance leftCancelMonoid [∀ i, LeftCancelMonoid (f i)] : LeftCancelMonoid (∀ i, f i) := { leftCancelSemigroup, monoid with } @[to_additive] instance rightCancelMonoid [∀ i, RightCancelMonoid (f i)] : RightCancelMonoid (∀ i, f i) := { rightCancelSemigroup, monoid with } @[to_additive] instance cancelMonoid [∀ i, CancelMonoid (f i)] : CancelMonoid (∀ i, f i) := { leftCancelMonoid, rightCancelMonoid with } @[to_additive] instance cancelCommMonoid [∀ i, CancelCommMonoid (f i)] : CancelCommMonoid (∀ i, f i) := { leftCancelMonoid, commMonoid with } section variable [DecidableEq I] variable [∀ i, One (f i)] [∀ i, One (g i)] [∀ i, One (h i)] /-- The function supported at `i`, with value `x` there, and `1` elsewhere. -/ @[to_additive "The function supported at `i`, with value `x` there, and `0` elsewhere."] def mulSingle (i : I) (x : f i) : ∀ (j : I), f j := Function.update 1 i x @[to_additive (attr := simp)] theorem mulSingle_eq_same (i : I) (x : f i) : mulSingle i x i = x := Function.update_self i x _ @[to_additive (attr := simp)] theorem mulSingle_eq_of_ne {i i' : I} (h : i' ≠ i) (x : f i) : mulSingle i x i' = 1 := Function.update_of_ne h x _ /-- Abbreviation for `mulSingle_eq_of_ne h.symm`, for ease of use by `simp`. -/ @[to_additive (attr := simp) "Abbreviation for `single_eq_of_ne h.symm`, for ease of use by `simp`."] theorem mulSingle_eq_of_ne' {i i' : I} (h : i ≠ i') (x : f i) : mulSingle i x i' = 1 := mulSingle_eq_of_ne h.symm x @[to_additive (attr := simp)] theorem mulSingle_one (i : I) : mulSingle i (1 : f i) = 1 := Function.update_eq_self _ _ @[to_additive (attr := simp)] theorem mulSingle_eq_one_iff {i : I} {x : f i} : mulSingle i x = 1 ↔ x = 1 := by refine ⟨fun h => ?_, fun h => h.symm ▸ mulSingle_one i⟩ rw [← mulSingle_eq_same i x, h, one_apply] @[to_additive] theorem mulSingle_ne_one_iff {i : I} {x : f i} : mulSingle i x ≠ 1 ↔ x ≠ 1 := mulSingle_eq_one_iff.ne -- Porting note: -- 1) Why do I have to specify the type of `mulSingle i x` explicitly? -- 2) Why do I have to specify the type of `(1 : I → β)`? -- 3) Removed `{β : Sort*}` as `[One β]` converts it to a type anyways. /-- On non-dependent functions, `Pi.mulSingle` can be expressed as an `ite` -/ @[to_additive "On non-dependent functions, `Pi.single` can be expressed as an `ite`"] theorem mulSingle_apply [One β] (i : I) (x : β) (i' : I) : (mulSingle i x : I → β) i' = if i' = i then x else 1 := Function.update_apply (1 : I → β) i x i' -- Porting note: Same as above. /-- On non-dependent functions, `Pi.mulSingle` is symmetric in the two indices. -/ @[to_additive "On non-dependent functions, `Pi.single` is symmetric in the two indices."] theorem mulSingle_comm [One β] (i : I) (x : β) (i' : I) : (mulSingle i x : I → β) i' = (mulSingle i' x : I → β) i := by simp [mulSingle_apply, eq_comm] @[to_additive] theorem apply_mulSingle (f' : ∀ i, f i → g i) (hf' : ∀ i, f' i 1 = 1) (i : I) (x : f i) (j : I) : f' j (mulSingle i x j) = mulSingle i (f' i x) j := by simpa only [Pi.one_apply, hf', mulSingle] using Function.apply_update f' 1 i x j @[to_additive apply_single₂] theorem apply_mulSingle₂ (f' : ∀ i, f i → g i → h i) (hf' : ∀ i, f' i 1 1 = 1) (i : I) (x : f i) (y : g i) (j : I) : f' j (mulSingle i x j) (mulSingle i y j) = mulSingle i (f' i x y) j := by by_cases h : j = i · subst h simp only [mulSingle_eq_same] · simp only [mulSingle_eq_of_ne h, hf'] @[to_additive] theorem mulSingle_op {g : I → Type*} [∀ i, One (g i)] (op : ∀ i, f i → g i) (h : ∀ i, op i 1 = 1) (i : I) (x : f i) : mulSingle i (op i x) = fun j => op j (mulSingle i x j) := Eq.symm <| funext <| apply_mulSingle op h i x @[to_additive] theorem mulSingle_op₂ {g₁ g₂ : I → Type*} [∀ i, One (g₁ i)] [∀ i, One (g₂ i)] (op : ∀ i, g₁ i → g₂ i → f i) (h : ∀ i, op i 1 1 = 1) (i : I) (x₁ : g₁ i) (x₂ : g₂ i) : mulSingle i (op i x₁ x₂) = fun j => op j (mulSingle i x₁ j) (mulSingle i x₂ j) := Eq.symm <| funext <| apply_mulSingle₂ op h i x₁ x₂ variable (f) @[to_additive] theorem mulSingle_injective (i : I) : Function.Injective (mulSingle i : f i → ∀ i, f i) := Function.update_injective _ i @[to_additive (attr := simp)] theorem mulSingle_inj (i : I) {x y : f i} : mulSingle i x = mulSingle i y ↔ x = y := (Pi.mulSingle_injective _ _).eq_iff end /-- The mapping into a product type built from maps into each component. -/ @[simp] protected def prod (f' : ∀ i, f i) (g' : ∀ i, g i) (i : I) : f i × g i := (f' i, g' i) -- Porting note: simp now unfolds the lhs, so we are not marking these as simp. -- @[simp] theorem prod_fst_snd : Pi.prod (Prod.fst : α × β → α) (Prod.snd : α × β → β) = id := rfl -- Porting note: simp now unfolds the lhs, so we are not marking these as simp. -- @[simp] theorem prod_snd_fst : Pi.prod (Prod.snd : α × β → β) (Prod.fst : α × β → α) = Prod.swap := rfl end Pi namespace Function section Extend @[to_additive] theorem extend_one [One γ] (f : α → β) : Function.extend f (1 : α → γ) (1 : β → γ) = 1 := funext fun _ => by apply ite_self @[to_additive] theorem extend_mul [Mul γ] (f : α → β) (g₁ g₂ : α → γ) (e₁ e₂ : β → γ) : Function.extend f (g₁ * g₂) (e₁ * e₂) = Function.extend f g₁ e₁ * Function.extend f g₂ e₂ := by classical funext x simp only [not_exists, extend_def, Pi.mul_apply, apply_dite₂, dite_eq_ite, ite_self] -- Porting note: The Lean3 statement was -- `funext <| λ _, by convert (apply_dite2 (*) _ _ _ _ _).symm` -- which converts to -- `funext fun _ => by convert (apply_dite₂ (· * ·) _ _ _ _ _).symm` -- However this does not work, and we're not sure why. @[to_additive] theorem extend_inv [Inv γ] (f : α → β) (g : α → γ) (e : β → γ) : Function.extend f g⁻¹ e⁻¹ = (Function.extend f g e)⁻¹ := by classical funext x simp only [not_exists, extend_def, Pi.inv_apply, apply_dite Inv.inv] -- Porting note: The Lean3 statement was -- `funext <| λ _, by convert (apply_dite has_inv.inv _ _ _).symm` -- which converts to -- `funext fun _ => by convert (apply_dite Inv.inv _ _ _).symm` -- However this does not work, and we're not sure why. @[to_additive] theorem extend_div [Div γ] (f : α → β) (g₁ g₂ : α → γ) (e₁ e₂ : β → γ) : Function.extend f (g₁ / g₂) (e₁ / e₂) = Function.extend f g₁ e₁ / Function.extend f g₂ e₂ := by classical funext x simp [Function.extend_def, apply_dite₂] -- Porting note: The Lean3 statement was -- `funext <| λ _, by convert (apply_dite2 (/) _ _ _ _ _).symm` -- which converts to -- `funext fun _ => by convert (apply_dite₂ (· / ·) _ _ _ _ _).symm` -- However this does not work, and we're not sure why. end Extend lemma comp_eq_const_iff (b : β) (f : α → β) {g : β → γ} (hg : Injective g) : g ∘ f = Function.const _ (g b) ↔ f = Function.const _ b := hg.comp_left.eq_iff' rfl @[to_additive] lemma comp_eq_one_iff [One β] [One γ] (f : α → β) {g : β → γ} (hg : Injective g) (hg0 : g 1 = 1) : g ∘ f = 1 ↔ f = 1 := by simpa [hg0, const_one] using comp_eq_const_iff 1 f hg @[to_additive] lemma comp_ne_one_iff [One β] [One γ] (f : α → β) {g : β → γ} (hg : Injective g) (hg0 : g 1 = 1) : g ∘ f ≠ 1 ↔ f ≠ 1 := (comp_eq_one_iff f hg hg0).ne end Function /-- If the one function is surjective, the codomain is trivial. -/ @[to_additive "If the zero function is surjective, the codomain is trivial."] def uniqueOfSurjectiveOne (α : Type*) {β : Type*} [One β] (h : Function.Surjective (1 : α → β)) : Unique β := h.uniqueOfSurjectiveConst α (1 : β) @[to_additive] theorem Subsingleton.pi_mulSingle_eq {α : Type*} [DecidableEq I] [Subsingleton I] [One α] (i : I) (x : α) : Pi.mulSingle i x = fun _ => x := funext fun j => by rw [Subsingleton.elim j i, Pi.mulSingle_eq_same] namespace Sum variable (a a' : α → γ) (b b' : β → γ) @[to_additive (attr := simp)] theorem elim_one_one [One γ] : Sum.elim (1 : α → γ) (1 : β → γ) = 1 := Sum.elim_const_const 1 @[to_additive (attr := simp)] theorem elim_mulSingle_one [DecidableEq α] [DecidableEq β] [One γ] (i : α) (c : γ) : Sum.elim (Pi.mulSingle i c) (1 : β → γ) = Pi.mulSingle (Sum.inl i) c := by simp only [Pi.mulSingle, Sum.elim_update_left, elim_one_one] @[to_additive (attr := simp)] theorem elim_one_mulSingle [DecidableEq α] [DecidableEq β] [One γ] (i : β) (c : γ) : Sum.elim (1 : α → γ) (Pi.mulSingle i c) = Pi.mulSingle (Sum.inr i) c := by simp only [Pi.mulSingle, Sum.elim_update_right, elim_one_one] @[to_additive] theorem elim_inv_inv [Inv γ] : Sum.elim a⁻¹ b⁻¹ = (Sum.elim a b)⁻¹ := (Sum.comp_elim Inv.inv a b).symm @[to_additive] theorem elim_mul_mul [Mul γ] : Sum.elim (a * a') (b * b') = Sum.elim a b * Sum.elim a' b' := by ext x cases x <;> rfl @[to_additive] theorem elim_div_div [Div γ] : Sum.elim (a / a') (b / b') = Sum.elim a b / Sum.elim a' b' := by ext x cases x <;> rfl end Sum
Mathlib/Algebra/Group/Pi/Basic.lean
602
604
/- Copyright (c) 2023 Kevin Buzzard. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kevin Buzzard, Yaël Dillies, Jineon Baek -/ import Mathlib.Algebra.EuclideanDomain.Int import Mathlib.Algebra.GCDMonoid.Finset import Mathlib.Algebra.GCDMonoid.Nat import Mathlib.Algebra.Order.Ring.Abs import Mathlib.RingTheory.PrincipalIdealDomain /-! # Statement of Fermat's Last Theorem This file states Fermat's Last Theorem. We provide a statement over a general semiring with specific exponent, along with the usual statement over the naturals. ## Main definitions * `FermatLastTheoremWith R n`: The statement that only solutions to the Fermat equation `a^n + b^n = c^n` in the semiring `R` have `a = 0`, `b = 0` or `c = 0`. Note that this statement can certainly be false for certain values of `R` and `n`. For example `FermatLastTheoremWith ℝ 3` is false as `1^3 + 1^3 = (2^{1/3})^3`, and `FermatLastTheoremWith ℕ 2` is false, as 3^2 + 4^2 = 5^2. * `FermatLastTheoremFor n` : The statement that the only solutions to `a^n + b^n = c^n` in `ℕ` have `a = 0`, `b = 0` or `c = 0`. Again, this statement is not always true, for example `FermatLastTheoremFor 1` is false because `2^1 + 2^1 = 4^1`. * `FermatLastTheorem` : The statement of Fermat's Last Theorem, namely that the only solutions to `a^n + b^n = c^n` in `ℕ` when `n ≥ 3` have `a = 0`, `b = 0` or `c = 0`. ## History Fermat's Last Theorem was an open problem in number theory for hundreds of years, until it was finally solved by Andrew Wiles, assisted by Richard Taylor, in 1994 (see [A. Wiles, *Modular elliptic curves and Fermat's last theorem*][Wiles-FLT] and [R. Taylor and A. Wiles, *Ring-theoretic properties of certain Hecke algebras*][Taylor-Wiles-FLT]). An ongoing Lean formalisation of the proof, using mathlib as a dependency, is taking place at https://github.com/ImperialCollegeLondon/FLT . -/ open List /-- Statement of Fermat's Last Theorem over a given semiring with a specific exponent. -/ def FermatLastTheoremWith (R : Type*) [Semiring R] (n : ℕ) : Prop := ∀ a b c : R, a ≠ 0 → b ≠ 0 → c ≠ 0 → a ^ n + b ^ n ≠ c ^ n /-- Statement of Fermat's Last Theorem over the naturals for a given exponent. -/ def FermatLastTheoremFor (n : ℕ) : Prop := FermatLastTheoremWith ℕ n /-- Statement of Fermat's Last Theorem: `a ^ n + b ^ n = c ^ n` has no nontrivial natural solution when `n ≥ 3`. This is now a theorem of Wiles and Taylor--Wiles; see https://github.com/ImperialCollegeLondon/FLT for an ongoing Lean formalisation of a proof. -/ def FermatLastTheorem : Prop := ∀ n ≥ 3, FermatLastTheoremFor n lemma fermatLastTheoremFor_zero : FermatLastTheoremFor 0 := fun _ _ _ _ _ _ ↦ by norm_num lemma not_fermatLastTheoremFor_one : ¬ FermatLastTheoremFor 1 := fun h ↦ h 1 1 2 (by norm_num) (by norm_num) (by norm_num) (by norm_num) lemma not_fermatLastTheoremFor_two : ¬ FermatLastTheoremFor 2 := fun h ↦ h 3 4 5 (by norm_num) (by norm_num) (by norm_num) (by norm_num) variable {R : Type*} [Semiring R] [NoZeroDivisors R] {m n : ℕ} lemma FermatLastTheoremWith.mono (hmn : m ∣ n) (hm : FermatLastTheoremWith R m) : FermatLastTheoremWith R n := by rintro a b c ha hb hc obtain ⟨k, rfl⟩ := hmn simp_rw [pow_mul'] refine hm _ _ _ ?_ ?_ ?_ <;> exact pow_ne_zero _ ‹_› lemma FermatLastTheoremFor.mono (hmn : m ∣ n) (hm : FermatLastTheoremFor m) : FermatLastTheoremFor n := by exact FermatLastTheoremWith.mono hmn hm lemma fermatLastTheoremWith_nat_int_rat_tfae (n : ℕ) : TFAE [FermatLastTheoremWith ℕ n, FermatLastTheoremWith ℤ n, FermatLastTheoremWith ℚ n] := by tfae_have 1 → 2 | h, a, b, c, ha, hb, hc, habc => by obtain hn | hn := n.even_or_odd · refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [hn.pow_abs, habc] obtain ha | ha := ha.lt_or_lt <;> obtain hb | hb := hb.lt_or_lt <;> obtain hc | hc := hc.lt_or_lt · refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_neg, neg_pow a, neg_pow b, neg_pow c, ← mul_add, habc, *] · exact (by positivity : 0 < c ^ n).not_lt <| habc.symm.trans_lt <| add_neg (hn.pow_neg ha) <| hn.pow_neg hb · refine h b.natAbs c.natAbs a.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, add_neg_eq_iff_eq_add, eq_neg_add_iff_add_eq, *] · refine h a.natAbs c.natAbs b.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, neg_add_eq_iff_eq_add, eq_neg_add_iff_add_eq, *] · refine h c.natAbs a.natAbs b.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, neg_add_eq_iff_eq_add, eq_add_neg_iff_add_eq, *] · refine h c.natAbs b.natAbs a.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, abs_of_neg, hn.neg_pow, habc, add_neg_eq_iff_eq_add, eq_add_neg_iff_add_eq, *] · exact (by positivity : 0 < a ^ n + b ^ n).not_lt <| habc.trans_lt <| hn.pow_neg hc · refine h a.natAbs b.natAbs c.natAbs (by positivity) (by positivity) (by positivity) (Int.natCast_inj.1 ?_) push_cast simp only [abs_of_pos, habc, *] tfae_have 2 → 3 | h, a, b, c, ha, hb, hc, habc => by rw [← Rat.num_ne_zero] at ha hb hc refine h (a.num * b.den * c.den) (a.den * b.num * c.den) (a.den * b.den * c.num) (by positivity) (by positivity) (by positivity) ?_ have : (a.den * b.den * c.den : ℚ) ^ n ≠ 0 := by positivity refine Int.cast_injective <| (div_left_inj' this).1 ?_ push_cast simp only [add_div, ← div_pow, mul_div_mul_comm, div_self (by positivity : (a.den : ℚ) ≠ 0), div_self (by positivity : (b.den : ℚ) ≠ 0), div_self (by positivity : (c.den : ℚ) ≠ 0), one_mul, mul_one, Rat.num_div_den, habc] tfae_have 3 → 1 | h, a, b, c => mod_cast h a b c tfae_finish lemma fermatLastTheoremFor_iff_nat {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℕ n := Iff.rfl lemma fermatLastTheoremFor_iff_int {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℤ n := (fermatLastTheoremWith_nat_int_rat_tfae n).out 0 1
lemma fermatLastTheoremFor_iff_rat {n : ℕ} : FermatLastTheoremFor n ↔ FermatLastTheoremWith ℚ n := (fermatLastTheoremWith_nat_int_rat_tfae n).out 0 2 /-- A relaxed variant of Fermat's Last Theorem over a given commutative semiring with a specific exponent, allowing nonzero solutions of units and their common multiples.
Mathlib/NumberTheory/FLT/Basic.lean
147
153
/- 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, Yury Kudryashov -/ import Mathlib.Data.Set.SymmDiff import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Irreducible /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : IsInducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (by fun_prop)).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (Continuous.prodMk_left _).continuousOn) theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ classical rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction I using Finset.induction_on with | empty => refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI | insert i I _ ihI => rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn /-- The connected component of a point is the maximal connected set that contains this point. -/ def connectedComponent (x : α) : Set α := ⋃₀ { s : Set α | IsPreconnected s ∧ x ∈ s } open Classical in /-- Given a set `F` in a topological space `α` and a point `x : α`, the connected component of `x` in `F` is the connected component of `x` in the subtype `F` seen as a set in `α`. This definition does not make sense if `x` is not in `F` so we return the empty set in this case. -/ def connectedComponentIn (F : Set α) (x : α) : Set α := if h : x ∈ F then (↑) '' connectedComponent (⟨x, h⟩ : F) else ∅ theorem connectedComponentIn_eq_image {F : Set α} {x : α} (h : x ∈ F) : connectedComponentIn F x = (↑) '' connectedComponent (⟨x, h⟩ : F) := dif_pos h theorem connectedComponentIn_eq_empty {F : Set α} {x : α} (h : x ∉ F) : connectedComponentIn F x = ∅ := dif_neg h theorem mem_connectedComponent {x : α} : x ∈ connectedComponent x := mem_sUnion_of_mem (mem_singleton x) ⟨isPreconnected_singleton, mem_singleton x⟩ theorem mem_connectedComponentIn {x : α} {F : Set α} (hx : x ∈ F) : x ∈ connectedComponentIn F x := by simp [connectedComponentIn_eq_image hx, mem_connectedComponent, hx] theorem connectedComponent_nonempty {x : α} : (connectedComponent x).Nonempty := ⟨x, mem_connectedComponent⟩ theorem connectedComponentIn_nonempty_iff {x : α} {F : Set α} : (connectedComponentIn F x).Nonempty ↔ x ∈ F := by rw [connectedComponentIn] split_ifs <;> simp [connectedComponent_nonempty, *] theorem connectedComponentIn_subset (F : Set α) (x : α) : connectedComponentIn F x ⊆ F := by rw [connectedComponentIn] split_ifs <;> simp theorem isPreconnected_connectedComponent {x : α} : IsPreconnected (connectedComponent x) := isPreconnected_sUnion x _ (fun _ => And.right) fun _ => And.left theorem isPreconnected_connectedComponentIn {x : α} {F : Set α} : IsPreconnected (connectedComponentIn F x) := by rw [connectedComponentIn]; split_ifs · exact IsInducing.subtypeVal.isPreconnected_image.mpr isPreconnected_connectedComponent · exact isPreconnected_empty theorem isConnected_connectedComponent {x : α} : IsConnected (connectedComponent x) := ⟨⟨x, mem_connectedComponent⟩, isPreconnected_connectedComponent⟩ theorem isConnected_connectedComponentIn_iff {x : α} {F : Set α} : IsConnected (connectedComponentIn F x) ↔ x ∈ F := by simp_rw [← connectedComponentIn_nonempty_iff, IsConnected, isPreconnected_connectedComponentIn, and_true] theorem IsPreconnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsPreconnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := fun _z hz => mem_sUnion_of_mem hz ⟨H1, H2⟩ theorem IsPreconnected.subset_connectedComponentIn {x : α} {F : Set α} (hs : IsPreconnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connectedComponentIn F x := by have : IsPreconnected (((↑) : F → α) ⁻¹' s) := by refine IsInducing.subtypeVal.isPreconnected_image.mp ?_ rwa [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] have h2xs : (⟨x, hsF hxs⟩ : F) ∈ (↑) ⁻¹' s := by rw [mem_preimage] exact hxs have := this.subset_connectedComponent h2xs rw [connectedComponentIn_eq_image (hsF hxs)] refine Subset.trans ?_ (image_subset _ this) rw [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] theorem IsConnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsConnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := H1.2.subset_connectedComponent H2 theorem IsPreconnected.connectedComponentIn {x : α} {F : Set α} (h : IsPreconnected F) (hx : x ∈ F) : connectedComponentIn F x = F := (connectedComponentIn_subset F x).antisymm (h.subset_connectedComponentIn hx subset_rfl) theorem connectedComponent_eq {x y : α} (h : y ∈ connectedComponent x) : connectedComponent x = connectedComponent y := eq_of_subset_of_subset (isConnected_connectedComponent.subset_connectedComponent h) (isConnected_connectedComponent.subset_connectedComponent (Set.mem_of_mem_of_subset mem_connectedComponent (isConnected_connectedComponent.subset_connectedComponent h))) theorem connectedComponent_eq_iff_mem {x y : α} : connectedComponent x = connectedComponent y ↔ x ∈ connectedComponent y := ⟨fun h => h ▸ mem_connectedComponent, fun h => (connectedComponent_eq h).symm⟩ theorem connectedComponentIn_eq {x y : α} {F : Set α} (h : y ∈ connectedComponentIn F x) : connectedComponentIn F x = connectedComponentIn F y := by have hx : x ∈ F := connectedComponentIn_nonempty_iff.mp ⟨y, h⟩ simp_rw [connectedComponentIn_eq_image hx] at h ⊢ obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h simp_rw [connectedComponentIn_eq_image hy, connectedComponent_eq h2y] theorem connectedComponentIn_univ (x : α) : connectedComponentIn univ x = connectedComponent x := subset_antisymm (isPreconnected_connectedComponentIn.subset_connectedComponent <| mem_connectedComponentIn trivial) (isPreconnected_connectedComponent.subset_connectedComponentIn mem_connectedComponent <| subset_univ _) theorem connectedComponent_disjoint {x y : α} (h : connectedComponent x ≠ connectedComponent y) : Disjoint (connectedComponent x) (connectedComponent y) := Set.disjoint_left.2 fun _ h1 h2 => h ((connectedComponent_eq h1).trans (connectedComponent_eq h2).symm) theorem isClosed_connectedComponent {x : α} : IsClosed (connectedComponent x) := closure_subset_iff_isClosed.1 <| isConnected_connectedComponent.closure.subset_connectedComponent <| subset_closure mem_connectedComponent theorem Continuous.image_connectedComponent_subset [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : f '' connectedComponent a ⊆ connectedComponent (f a) := (isConnected_connectedComponent.image f h.continuousOn).subset_connectedComponent ((mem_image f (connectedComponent a) (f a)).2 ⟨a, mem_connectedComponent, rfl⟩) theorem Continuous.image_connectedComponentIn_subset [TopologicalSpace β] {f : α → β} {s : Set α} {a : α} (hf : Continuous f) (hx : a ∈ s) : f '' connectedComponentIn s a ⊆ connectedComponentIn (f '' s) (f a) := (isPreconnected_connectedComponentIn.image _ hf.continuousOn).subset_connectedComponentIn (mem_image_of_mem _ <| mem_connectedComponentIn hx) (image_subset _ <| connectedComponentIn_subset _ _) theorem Continuous.mapsTo_connectedComponent [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : MapsTo f (connectedComponent a) (connectedComponent (f a)) := mapsTo'.2 <| h.image_connectedComponent_subset a theorem Continuous.mapsTo_connectedComponentIn [TopologicalSpace β] {f : α → β} {s : Set α} (h : Continuous f) {a : α} (hx : a ∈ s) : MapsTo f (connectedComponentIn s a) (connectedComponentIn (f '' s) (f a)) := mapsTo'.2 <| image_connectedComponentIn_subset h hx theorem irreducibleComponent_subset_connectedComponent {x : α} : irreducibleComponent x ⊆ connectedComponent x := isIrreducible_irreducibleComponent.isConnected.subset_connectedComponent mem_irreducibleComponent @[mono] theorem connectedComponentIn_mono (x : α) {F G : Set α} (h : F ⊆ G) : connectedComponentIn F x ⊆ connectedComponentIn G x := by by_cases hx : x ∈ F · rw [connectedComponentIn_eq_image hx, connectedComponentIn_eq_image (h hx), ← show ((↑) : G → α) ∘ inclusion h = (↑) from rfl, image_comp] exact image_subset _ ((continuous_inclusion h).image_connectedComponent_subset ⟨x, hx⟩) · rw [connectedComponentIn_eq_empty hx] exact Set.empty_subset _ /-- A preconnected space is one where there is no non-trivial open partition. -/ class PreconnectedSpace (α : Type u) [TopologicalSpace α] : Prop where /-- The universal set `Set.univ` in a preconnected space is a preconnected set. -/ isPreconnected_univ : IsPreconnected (univ : Set α) export PreconnectedSpace (isPreconnected_univ) /-- A connected space is a nonempty one where there is no non-trivial open partition. -/ class ConnectedSpace (α : Type u) [TopologicalSpace α] : Prop extends PreconnectedSpace α where /-- A connected space is nonempty. -/ toNonempty : Nonempty α attribute [instance 50] ConnectedSpace.toNonempty -- see Note [lower instance priority] -- see Note [lower instance priority] theorem isConnected_univ [ConnectedSpace α] : IsConnected (univ : Set α) := ⟨univ_nonempty, isPreconnected_univ⟩ lemma preconnectedSpace_iff_univ : PreconnectedSpace α ↔ IsPreconnected (univ : Set α) := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩ lemma connectedSpace_iff_univ : ConnectedSpace α ↔ IsConnected (univ : Set α) := ⟨fun h ↦ ⟨univ_nonempty, h.1.1⟩, fun h ↦ ConnectedSpace.mk (toPreconnectedSpace := ⟨h.2⟩) ⟨h.1.some⟩⟩ theorem isPreconnected_range [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (h : Continuous f) : IsPreconnected (range f) := @image_univ _ _ f ▸ isPreconnected_univ.image _ h.continuousOn theorem isConnected_range [TopologicalSpace β] [ConnectedSpace α] {f : α → β} (h : Continuous f) : IsConnected (range f) := ⟨range_nonempty f, isPreconnected_range h⟩ theorem Function.Surjective.connectedSpace [ConnectedSpace α] [TopologicalSpace β] {f : α → β} (hf : Surjective f) (hf' : Continuous f) : ConnectedSpace β := by rw [connectedSpace_iff_univ, ← hf.range_eq] exact isConnected_range hf' instance Quotient.instConnectedSpace {s : Setoid α} [ConnectedSpace α] : ConnectedSpace (Quotient s) := Quotient.mk'_surjective.connectedSpace continuous_coinduced_rng theorem DenseRange.preconnectedSpace [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (hf : DenseRange f) (hc : Continuous f) : PreconnectedSpace β := ⟨hf.closure_eq ▸ (isPreconnected_range hc).closure⟩ theorem connectedSpace_iff_connectedComponent : ConnectedSpace α ↔ ∃ x : α, connectedComponent x = univ := by constructor · rintro ⟨⟨x⟩⟩ exact ⟨x, eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x)⟩ · rintro ⟨x, h⟩ haveI : PreconnectedSpace α := ⟨by rw [← h]; exact isPreconnected_connectedComponent⟩ exact ⟨⟨x⟩⟩ theorem preconnectedSpace_iff_connectedComponent : PreconnectedSpace α ↔ ∀ x : α, connectedComponent x = univ := by constructor · intro h x exact eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x) · intro h rcases isEmpty_or_nonempty α with hα | hα · exact ⟨by rw [univ_eq_empty_iff.mpr hα]; exact isPreconnected_empty⟩ · exact ⟨by rw [← h (Classical.choice hα)]; exact isPreconnected_connectedComponent⟩ @[simp] theorem PreconnectedSpace.connectedComponent_eq_univ {X : Type*} [TopologicalSpace X] [h : PreconnectedSpace X] (x : X) : connectedComponent x = univ := preconnectedSpace_iff_connectedComponent.mp h x instance [TopologicalSpace β] [PreconnectedSpace α] [PreconnectedSpace β] : PreconnectedSpace (α × β) := ⟨by rw [← univ_prod_univ] exact isPreconnected_univ.prod isPreconnected_univ⟩ instance [TopologicalSpace β] [ConnectedSpace α] [ConnectedSpace β] : ConnectedSpace (α × β) := ⟨inferInstance⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, PreconnectedSpace (π i)] : PreconnectedSpace (∀ i, π i) := ⟨by rw [← pi_univ univ]; exact isPreconnected_univ_pi fun i => isPreconnected_univ⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, ConnectedSpace (π i)] : ConnectedSpace (∀ i, π i) := ⟨inferInstance⟩ -- see Note [lower instance priority] instance (priority := 100) PreirreducibleSpace.preconnectedSpace (α : Type u) [TopologicalSpace α] [PreirreducibleSpace α] : PreconnectedSpace α := ⟨isPreirreducible_univ.isPreconnected⟩ -- see Note [lower instance priority] instance (priority := 100) IrreducibleSpace.connectedSpace (α : Type u) [TopologicalSpace α] [IrreducibleSpace α] : ConnectedSpace α where toNonempty := IrreducibleSpace.toNonempty theorem Subtype.preconnectedSpace {s : Set α} (h : IsPreconnected s) : PreconnectedSpace s where isPreconnected_univ := by rwa [← IsInducing.subtypeVal.isPreconnected_image, image_univ, Subtype.range_val] theorem Subtype.connectedSpace {s : Set α} (h : IsConnected s) : ConnectedSpace s where toPreconnectedSpace := Subtype.preconnectedSpace h.isPreconnected toNonempty := h.nonempty.to_subtype theorem isPreconnected_iff_preconnectedSpace {s : Set α} : IsPreconnected s ↔ PreconnectedSpace s := ⟨Subtype.preconnectedSpace, fun h => by simpa using isPreconnected_univ.image ((↑) : s → α) continuous_subtype_val.continuousOn⟩ theorem isConnected_iff_connectedSpace {s : Set α} : IsConnected s ↔ ConnectedSpace s := ⟨Subtype.connectedSpace, fun h => ⟨nonempty_subtype.mp h.2, isPreconnected_iff_preconnectedSpace.mpr h.1⟩⟩ end Preconnected
Mathlib/Topology/Connected/Basic.lean
783
786
/- 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.BigOperators.Group.Finset.Piecewise import Mathlib.Algebra.Group.Ext import Mathlib.CategoryTheory.Limits.Preserves.Shapes.BinaryProducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Biproducts import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products import Mathlib.CategoryTheory.Preadditive.Basic import Mathlib.Tactic.Abel /-! # Basic facts about biproducts in preadditive categories. In (or between) preadditive categories, * Any biproduct satisfies the equality `total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)`, or, in the binary case, `total : fst ≫ inl + snd ≫ inr = 𝟙 X`. * Any (binary) `product` or (binary) `coproduct` is a (binary) `biproduct`. * In any category (with zero morphisms), if `biprod.map f g` is an isomorphism, then both `f` and `g` are isomorphisms. * If `f` is a morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, then we can construct isomorphisms `L : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂` and `R : Y₁ ⊞ Y₂ ≅ Y₁ ⊞ Y₂` so that `L.hom ≫ g ≫ R.hom` is diagonal (with `X₁ ⟶ Y₁` component still `f`), via Gaussian elimination. * As a corollary of the previous two facts, if we have an isomorphism `X₁ ⊞ X₂ ≅ Y₁ ⊞ Y₂` whose `X₁ ⟶ Y₁` entry is an isomorphism, we can construct an isomorphism `X₂ ≅ Y₂`. * If `f : W ⊞ X ⟶ Y ⊞ Z` is an isomorphism, either `𝟙 W = 0`, or at least one of the component maps `W ⟶ Y` and `W ⟶ Z` is nonzero. * If `f : ⨁ S ⟶ ⨁ T` is an isomorphism, then every column (corresponding to a nonzero summand in the domain) has some nonzero matrix entry. * A functor preserves a biproduct if and only if it preserves the corresponding product if and only if it preserves the corresponding coproduct. There are connections between this material and the special case of the category whose morphisms are matrices over a ring, in particular the Schur complement (see `Mathlib.LinearAlgebra.Matrix.SchurComplement`). In particular, the declarations `CategoryTheory.Biprod.isoElim`, `CategoryTheory.Biprod.gaussian` and `Matrix.invertibleOfFromBlocks₁₁Invertible` are all closely related. -/ open CategoryTheory open CategoryTheory.Preadditive open CategoryTheory.Limits open CategoryTheory.Functor open CategoryTheory.Preadditive universe v v' u u' noncomputable section namespace CategoryTheory variable {C : Type u} [Category.{v} C] [Preadditive C] namespace Limits section Fintype variable {J : Type} [Fintype J] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBilimitOfTotal {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => ∑ j : J, s.π.app ⟨j⟩ ≫ b.ι j uniq := fun s m h => by erw [← Category.comp_id m, ← total, comp_sum] apply Finset.sum_congr rfl intro j _ have reassoced : m ≫ Bicone.π b j ≫ Bicone.ι b j = s.π.app ⟨j⟩ ≫ Bicone.ι b j := by erw [← Category.assoc, eq_whisker (h ⟨j⟩)] rw [reassoced] fac := fun s j => by classical cases j simp only [sum_comp, Category.assoc, Bicone.toCone_π_app, b.ι_π, comp_dite] -- See note [dsimp, simp]. dsimp simp } isColimit := { desc := fun s => ∑ j : J, b.π j ≫ s.ι.app ⟨j⟩ uniq := fun s m h => by erw [← Category.id_comp m, ← total, sum_comp] apply Finset.sum_congr rfl intro j _ erw [Category.assoc, h ⟨j⟩] fac := fun s j => by classical cases j simp only [comp_sum, ← Category.assoc, Bicone.toCocone_ι_app, b.ι_π, dite_comp] dsimp; simp } theorem IsBilimit.total {f : J → C} {b : Bicone f} (i : b.IsBilimit) : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt := i.isLimit.hom_ext fun j => by classical cases j simp [sum_comp, b.ι_π, comp_dite] /-- In a preadditive category, we can construct a biproduct for `f : J → C` from any bicone `b` for `f` satisfying `total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBiproduct_of_total {f : J → C} (b : Bicone f) (total : ∑ j : J, b.π j ≫ b.ι j = 𝟙 b.pt) : HasBiproduct f := HasBiproduct.mk { bicone := b isBilimit := isBilimitOfTotal b total } /-- In a preadditive category, any finite bicone which is a limit cone is in fact a bilimit bicone. -/ def isBilimitOfIsLimit {f : J → C} (t : Bicone f) (ht : IsLimit t.toCone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by classical cases j simp [sum_comp, t.ι_π, dite_comp, comp_dite] /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfLimitConeOfIsLimit {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : (Bicone.ofLimitCone ht).IsBilimit := isBilimitOfIsLimit _ <| IsLimit.ofIsoLimit ht <| Cones.ext (Iso.refl _) (by simp) /-- In a preadditive category, any finite bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBilimitOfIsColimit {f : J → C} (t : Bicone f) (ht : IsColimit t.toCocone) : t.IsBilimit := isBilimitOfTotal _ <| ht.hom_ext fun j => by classical cases j simp_rw [Bicone.toCocone_ι_app, comp_sum, ← Category.assoc, t.ι_π, dite_comp] simp /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def biconeIsBilimitOfColimitCoconeOfIsColimit {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : (Bicone.ofColimitCocone ht).IsBilimit := isBilimitOfIsColimit _ <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) <| by rintro ⟨j⟩; simp end Fintype section Finite variable {J : Type} [Finite J] /-- In a preadditive category, if the product over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasProduct (f : J → C) [HasProduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } /-- In a preadditive category, if the coproduct over `f : J → C` exists, then the biproduct over `f` exists. -/ theorem HasBiproduct.of_hasCoproduct (f : J → C) [HasCoproduct f] : HasBiproduct f := by cases nonempty_fintype J exact HasBiproduct.mk { bicone := _ isBilimit := biconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } end Finite /-- A preadditive category with finite products has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteProducts [HasFiniteProducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasProduct _ }⟩ /-- A preadditive category with finite coproducts has finite biproducts. -/ theorem HasFiniteBiproducts.of_hasFiniteCoproducts [HasFiniteCoproducts C] : HasFiniteBiproducts C := ⟨fun _ => { has_biproduct := fun _ => HasBiproduct.of_hasCoproduct _ }⟩ section HasBiproduct variable {J : Type} [Fintype J] {f : J → C} [HasBiproduct f] /-- In any preadditive category, any biproduct satisfies `∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f)` -/ @[simp] theorem biproduct.total : ∑ j : J, biproduct.π f j ≫ biproduct.ι f j = 𝟙 (⨁ f) := IsBilimit.total (biproduct.isBilimit _) theorem biproduct.lift_eq {T : C} {g : ∀ j, T ⟶ f j} : biproduct.lift g = ∑ j, g j ≫ biproduct.ι f j := by classical ext j simp only [sum_comp, biproduct.ι_π, comp_dite, biproduct.lift_π, Category.assoc, comp_zero, Finset.sum_dite_eq', Finset.mem_univ, eqToHom_refl, Category.comp_id, if_true] theorem biproduct.desc_eq {T : C} {g : ∀ j, f j ⟶ T} : biproduct.desc g = ∑ j, biproduct.π f j ≫ g j := by classical ext j simp [comp_sum, biproduct.ι_π_assoc, dite_comp] @[reassoc] theorem biproduct.lift_desc {T U : C} {g : ∀ j, T ⟶ f j} {h : ∀ j, f j ⟶ U} : biproduct.lift g ≫ biproduct.desc h = ∑ j : J, g j ≫ h j := by classical simp [biproduct.lift_eq, biproduct.desc_eq, comp_sum, sum_comp, biproduct.ι_π_assoc, comp_dite, dite_comp] theorem biproduct.map_eq [HasFiniteBiproducts C] {f g : J → C} {h : ∀ j, f j ⟶ g j} : biproduct.map h = ∑ j : J, biproduct.π f j ≫ h j ≫ biproduct.ι g j := by classical ext simp [biproduct.ι_π, biproduct.ι_π_assoc, comp_sum, sum_comp, comp_dite, dite_comp] @[reassoc] theorem biproduct.lift_matrix {K : Type} [Finite K] [HasFiniteBiproducts C] {f : J → C} {g : K → C} {P} (x : ∀ j, P ⟶ f j) (m : ∀ j k, f j ⟶ g k) : biproduct.lift x ≫ biproduct.matrix m = biproduct.lift fun k => ∑ j, x j ≫ m j k := by ext simp [biproduct.lift_desc] end HasBiproduct section HasFiniteBiproducts variable {J K : Type} [Finite J] {f : J → C} [HasFiniteBiproducts C] @[reassoc] theorem biproduct.matrix_desc [Fintype K] {f : J → C} {g : K → C} (m : ∀ j k, f j ⟶ g k) {P} (x : ∀ k, g k ⟶ P) : biproduct.matrix m ≫ biproduct.desc x = biproduct.desc fun j => ∑ k, m j k ≫ x k := by ext simp [lift_desc] variable [Finite K] @[reassoc] theorem biproduct.matrix_map {f : J → C} {g : K → C} {h : K → C} (m : ∀ j k, f j ⟶ g k) (n : ∀ k, g k ⟶ h k) : biproduct.matrix m ≫ biproduct.map n = biproduct.matrix fun j k => m j k ≫ n k := by ext simp @[reassoc] theorem biproduct.map_matrix {f : J → C} {g : J → C} {h : K → C} (m : ∀ k, f k ⟶ g k) (n : ∀ j k, g j ⟶ h k) : biproduct.map m ≫ biproduct.matrix n = biproduct.matrix fun j k => m j ≫ n j k := by ext simp end HasFiniteBiproducts /-- Reindex a categorical biproduct via an equivalence of the index types. -/ @[simps] def biproduct.reindex {β γ : Type} [Finite β] (ε : β ≃ γ) (f : γ → C) [HasBiproduct f] [HasBiproduct (f ∘ ε)] : ⨁ f ∘ ε ≅ ⨁ f where hom := biproduct.desc fun b => biproduct.ι f (ε b) inv := biproduct.lift fun b => biproduct.π f (ε b) hom_inv_id := by ext b b' by_cases h : b' = b · subst h; simp · have : ε b' ≠ ε b := by simp [h] simp [biproduct.ι_π_ne _ h, biproduct.ι_π_ne _ this] inv_hom_id := by classical cases nonempty_fintype β ext g g' by_cases h : g' = g <;> simp [Preadditive.sum_comp, Preadditive.comp_sum, biproduct.lift_desc, biproduct.ι_π, biproduct.ι_π_assoc, comp_dite, Equiv.apply_eq_iff_eq_symm_apply, Finset.sum_dite_eq' Finset.univ (ε.symm g') _, h] /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ def isBinaryBilimitOfTotal {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : b.IsBilimit where isLimit := { lift := fun s => (BinaryFan.fst s ≫ b.inl : s.pt ⟶ b.pt) + (BinaryFan.snd s ≫ b.inr : s.pt ⟶ b.pt) uniq := fun s m h => by have reassoced (j : WalkingPair) {W : C} (h' : _ ⟶ W) : m ≫ b.toCone.π.app ⟨j⟩ ≫ h' = s.π.app ⟨j⟩ ≫ h' := by rw [← Category.assoc, eq_whisker (h ⟨j⟩)] erw [← Category.comp_id m, ← total, comp_add, reassoced WalkingPair.left, reassoced WalkingPair.right] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } isColimit := { desc := fun s => (b.fst ≫ BinaryCofan.inl s : b.pt ⟶ s.pt) + (b.snd ≫ BinaryCofan.inr s : b.pt ⟶ s.pt) uniq := fun s m h => by erw [← Category.id_comp m, ← total, add_comp, Category.assoc, Category.assoc, h ⟨WalkingPair.left⟩, h ⟨WalkingPair.right⟩] fac := fun s j => by rcases j with ⟨⟨⟩⟩ <;> simp } theorem IsBilimit.binary_total {X Y : C} {b : BinaryBicone X Y} (i : b.IsBilimit) : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt := i.isLimit.hom_ext fun j => by rcases j with ⟨⟨⟩⟩ <;> simp /-- In a preadditive category, we can construct a binary biproduct for `X Y : C` from any binary bicone `b` satisfying `total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.X`. (That is, such a bicone is a limit cone and a colimit cocone.) -/ theorem hasBinaryBiproduct_of_total {X Y : C} (b : BinaryBicone X Y) (total : b.fst ≫ b.inl + b.snd ≫ b.inr = 𝟙 b.pt) : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := b isBilimit := isBinaryBilimitOfTotal b total } /-- We can turn any limit cone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofLimitCone {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : BinaryBicone X Y where pt := t.pt fst := t.π.app ⟨WalkingPair.left⟩ snd := t.π.app ⟨WalkingPair.right⟩ inl := ht.lift (BinaryFan.mk (𝟙 X) 0) inr := ht.lift (BinaryFan.mk 0 (𝟙 Y)) theorem inl_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inl = ht.lift (BinaryFan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryFan.mk (𝟙 X) 0); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp theorem inr_of_isLimit {X Y : C} {t : BinaryBicone X Y} (ht : IsLimit t.toCone) : t.inr = ht.lift (BinaryFan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryFan.mk 0 (𝟙 Y)); rintro ⟨⟨⟩⟩ <;> dsimp <;> simp /-- In a preadditive category, any binary bicone which is a limit cone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsLimit {X Y : C} (t : BinaryBicone X Y) (ht : IsLimit t.toCone) : t.IsBilimit := isBinaryBilimitOfTotal _ (by refine BinaryFan.IsLimit.hom_ext ht ?_ ?_ <;> simp) /-- We can turn any limit cone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfLimitConeOfIsLimit {X Y : C} {t : Cone (pair X Y)} (ht : IsLimit t) : (BinaryBicone.ofLimitCone ht).IsBilimit := isBinaryBilimitOfTotal _ <| BinaryFan.IsLimit.hom_ext ht (by simp) (by simp) /-- In a preadditive category, if the product of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryProduct (X Y : C) [HasBinaryProduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfLimitConeOfIsLimit (limit.isLimit _) } /-- In a preadditive category, if all binary products exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryProducts [HasBinaryProducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryProduct X Y } /-- We can turn any colimit cocone over a pair into a bicone. -/ @[simps] def BinaryBicone.ofColimitCocone {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : BinaryBicone X Y where pt := t.pt fst := ht.desc (BinaryCofan.mk (𝟙 X) 0) snd := ht.desc (BinaryCofan.mk 0 (𝟙 Y)) inl := t.ι.app ⟨WalkingPair.left⟩ inr := t.ι.app ⟨WalkingPair.right⟩ theorem fst_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.fst = ht.desc (BinaryCofan.mk (𝟙 X) 0) := by apply ht.uniq (BinaryCofan.mk (𝟙 X) 0) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp theorem snd_of_isColimit {X Y : C} {t : BinaryBicone X Y} (ht : IsColimit t.toCocone) : t.snd = ht.desc (BinaryCofan.mk 0 (𝟙 Y)) := by apply ht.uniq (BinaryCofan.mk 0 (𝟙 Y)) rintro ⟨⟨⟩⟩ <;> dsimp <;> simp /-- In a preadditive category, any binary bicone which is a colimit cocone is in fact a bilimit bicone. -/ def isBinaryBilimitOfIsColimit {X Y : C} (t : BinaryBicone X Y) (ht : IsColimit t.toCocone) : t.IsBilimit := isBinaryBilimitOfTotal _ <| by refine BinaryCofan.IsColimit.hom_ext ht ?_ ?_ <;> simp /-- We can turn any colimit cocone over a pair into a bilimit bicone. -/ def binaryBiconeIsBilimitOfColimitCoconeOfIsColimit {X Y : C} {t : Cocone (pair X Y)} (ht : IsColimit t) : (BinaryBicone.ofColimitCocone ht).IsBilimit := isBinaryBilimitOfIsColimit (BinaryBicone.ofColimitCocone ht) <| IsColimit.ofIsoColimit ht <| Cocones.ext (Iso.refl _) fun j => by rcases j with ⟨⟨⟩⟩ <;> simp /-- In a preadditive category, if the coproduct of `X` and `Y` exists, then the binary biproduct of `X` and `Y` exists. -/ theorem HasBinaryBiproduct.of_hasBinaryCoproduct (X Y : C) [HasBinaryCoproduct X Y] : HasBinaryBiproduct X Y := HasBinaryBiproduct.mk { bicone := _ isBilimit := binaryBiconeIsBilimitOfColimitCoconeOfIsColimit (colimit.isColimit _) } /-- In a preadditive category, if all binary coproducts exist, then all binary biproducts exist. -/ theorem HasBinaryBiproducts.of_hasBinaryCoproducts [HasBinaryCoproducts C] : HasBinaryBiproducts C := { has_binary_biproduct := fun X Y => HasBinaryBiproduct.of_hasBinaryCoproduct X Y } section variable {X Y : C} [HasBinaryBiproduct X Y] /-- In any preadditive category, any binary biproduct satisfies `biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y)`. -/ @[simp] theorem biprod.total : biprod.fst ≫ biprod.inl + biprod.snd ≫ biprod.inr = 𝟙 (X ⊞ Y) := by ext <;> simp [add_comp] theorem biprod.lift_eq {T : C} {f : T ⟶ X} {g : T ⟶ Y} : biprod.lift f g = f ≫ biprod.inl + g ≫ biprod.inr := by ext <;> simp [add_comp] theorem biprod.desc_eq {T : C} {f : X ⟶ T} {g : Y ⟶ T} : biprod.desc f g = biprod.fst ≫ f + biprod.snd ≫ g := by ext <;> simp [add_comp] @[reassoc (attr := simp)] theorem biprod.lift_desc {T U : C} {f : T ⟶ X} {g : T ⟶ Y} {h : X ⟶ U} {i : Y ⟶ U} : biprod.lift f g ≫ biprod.desc h i = f ≫ h + g ≫ i := by simp [biprod.lift_eq, biprod.desc_eq] theorem biprod.map_eq [HasBinaryBiproducts C] {W X Y Z : C} {f : W ⟶ Y} {g : X ⟶ Z} : biprod.map f g = biprod.fst ≫ f ≫ biprod.inl + biprod.snd ≫ g ≫ biprod.inr := by ext <;> simp section variable {Z : C} lemma biprod.decomp_hom_to (f : Z ⟶ X ⊞ Y) : ∃ f₁ f₂, f = f₁ ≫ biprod.inl + f₂ ≫ biprod.inr := ⟨f ≫ biprod.fst, f ≫ biprod.snd, by aesop⟩ lemma biprod.ext_to_iff {f g : Z ⟶ X ⊞ Y} : f = g ↔ f ≫ biprod.fst = g ≫ biprod.fst ∧ f ≫ biprod.snd = g ≫ biprod.snd := by aesop lemma biprod.decomp_hom_from (f : X ⊞ Y ⟶ Z) : ∃ f₁ f₂, f = biprod.fst ≫ f₁ + biprod.snd ≫ f₂ := ⟨biprod.inl ≫ f, biprod.inr ≫ f, by aesop⟩ lemma biprod.ext_from_iff {f g : X ⊞ Y ⟶ Z} : f = g ↔ biprod.inl ≫ f = biprod.inl ≫ g ∧ biprod.inr ≫ f = biprod.inr ≫ g := by aesop end /-- Every split mono `f` with a cokernel induces a binary bicone with `f` as its `inl` and the cokernel map as its `snd`. We will show in `is_bilimit_binary_bicone_of_split_mono_of_cokernel` that this binary bicone is in fact already a biproduct. -/ @[simps] def binaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f} (i : IsColimit c) : BinaryBicone X c.pt where pt := Y fst := retraction f snd := c.π inl := f inr := let c' : CokernelCofork (𝟙 Y - (𝟙 Y - retraction f ≫ f)) := CokernelCofork.ofπ (Cofork.π c) (by simp) let i' : IsColimit c' := isCokernelEpiComp i (retraction f) (by simp) let i'' := isColimitCoforkOfCokernelCofork i' (splitEpiOfIdempotentOfIsColimitCofork C (by simp) i'').section_ inl_fst := by simp inl_snd := by simp inr_fst := by dsimp only rw [splitEpiOfIdempotentOfIsColimitCofork_section_, isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc] dsimp only [cokernelCoforkOfCofork_ofπ] letI := epi_of_isColimit_cofork i apply zero_of_epi_comp c.π simp only [sub_comp, comp_sub, Category.comp_id, Category.assoc, IsSplitMono.id, sub_self, Cofork.IsColimit.π_desc_assoc, CokernelCofork.π_ofπ, IsSplitMono.id_assoc] apply sub_eq_zero_of_eq apply Category.id_comp inr_snd := by apply SplitEpi.id /-- The bicone constructed in `binaryBiconeOfSplitMonoOfCokernel` is a bilimit. This is a version of the splitting lemma that holds in all preadditive categories. -/ def isBilimitBinaryBiconeOfIsSplitMonoOfCokernel {X Y : C} {f : X ⟶ Y} [IsSplitMono f] {c : CokernelCofork f} (i : IsColimit c) : (binaryBiconeOfIsSplitMonoOfCokernel i).IsBilimit := isBinaryBilimitOfTotal _ (by simp only [binaryBiconeOfIsSplitMonoOfCokernel_fst, binaryBiconeOfIsSplitMonoOfCokernel_inr, binaryBiconeOfIsSplitMonoOfCokernel_snd, splitEpiOfIdempotentOfIsColimitCofork_section_] dsimp only [binaryBiconeOfIsSplitMonoOfCokernel_pt] rw [isColimitCoforkOfCokernelCofork_desc, isCokernelEpiComp_desc] simp only [binaryBiconeOfIsSplitMonoOfCokernel_inl, Cofork.IsColimit.π_desc, cokernelCoforkOfCofork_π, Cofork.π_ofπ, add_sub_cancel]) /-- If `b` is a binary bicone such that `b.inl` is a kernel of `b.snd`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfKernelInl {X Y : C} (b : BinaryBicone X Y) (hb : IsLimit b.sndKernelFork) : b.IsBilimit := isBinaryBilimitOfIsLimit _ <| BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : ((m : T ⟶ b.pt) - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : T ⟶ X, hq : q ≫ b.inl = m - (f ≫ b.inl + g ≫ b.inr)⟩ := KernelFork.IsLimit.lift' hb _ h₂' rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inl_fst, ← Category.assoc, hq, h₁', zero_comp] /-- If `b` is a binary bicone such that `b.inr` is a kernel of `b.fst`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfKernelInr {X Y : C} (b : BinaryBicone X Y) (hb : IsLimit b.fstKernelFork) : b.IsBilimit := isBinaryBilimitOfIsLimit _ <| BinaryFan.IsLimit.mk _ (fun f g => f ≫ b.inl + g ≫ b.inr) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.fst = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : (m - (f ≫ b.inl + g ≫ b.inr)) ≫ b.snd = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : T ⟶ Y, hq : q ≫ b.inr = m - (f ≫ b.inl + g ≫ b.inr)⟩ := KernelFork.IsLimit.lift' hb _ h₁' rw [← sub_eq_zero, ← hq, ← Category.comp_id q, ← b.inr_snd, ← Category.assoc, hq, h₂', zero_comp] /-- If `b` is a binary bicone such that `b.fst` is a cokernel of `b.inr`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfCokernelFst {X Y : C} (b : BinaryBicone X Y) (hb : IsColimit b.inrCokernelCofork) : b.IsBilimit := isBinaryBilimitOfIsColimit _ <| BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : X ⟶ T, hq : b.fst ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ := CokernelCofork.IsColimit.desc' hb _ h₂' rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inl_fst, Category.assoc, hq, h₁', comp_zero] /-- If `b` is a binary bicone such that `b.snd` is a cokernel of `b.inl`, then `b` is a bilimit bicone. -/ def BinaryBicone.isBilimitOfCokernelSnd {X Y : C} (b : BinaryBicone X Y) (hb : IsColimit b.inlCokernelCofork) : b.IsBilimit := isBinaryBilimitOfIsColimit _ <| BinaryCofan.IsColimit.mk _ (fun f g => b.fst ≫ f + b.snd ≫ g) (fun f g => by simp) (fun f g => by simp) fun {T} f g m h₁ h₂ => by dsimp at m have h₁' : b.inl ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₁ have h₂' : b.inr ≫ (m - (b.fst ≫ f + b.snd ≫ g)) = 0 := by simpa using sub_eq_zero.2 h₂ obtain ⟨q : Y ⟶ T, hq : b.snd ≫ q = m - (b.fst ≫ f + b.snd ≫ g)⟩ := CokernelCofork.IsColimit.desc' hb _ h₁' rw [← sub_eq_zero, ← hq, ← Category.id_comp q, ← b.inr_snd, Category.assoc, hq, h₂', comp_zero] /-- Every split epi `f` with a kernel induces a binary bicone with `f` as its `snd` and the kernel map as its `inl`. We will show in `binary_bicone_of_is_split_mono_of_cokernel` that this binary bicone is in fact already a biproduct. -/ @[simps] def binaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f} (i : IsLimit c) : BinaryBicone c.pt Y := { pt := X fst := let c' : KernelFork (𝟙 X - (𝟙 X - f ≫ section_ f)) := KernelFork.ofι (Fork.ι c) (by simp) let i' : IsLimit c' := isKernelCompMono i (section_ f) (by simp) let i'' := isLimitForkOfKernelFork i' (splitMonoOfIdempotentOfIsLimitFork C (by simp) i'').retraction snd := f inl := c.ι inr := section_ f inl_fst := by apply SplitMono.id inl_snd := by simp inr_fst := by dsimp only rw [splitMonoOfIdempotentOfIsLimitFork_retraction, isLimitForkOfKernelFork_lift, isKernelCompMono_lift] dsimp only [kernelForkOfFork_ι] letI := mono_of_isLimit_fork i apply zero_of_comp_mono c.ι simp only [comp_sub, Category.comp_id, Category.assoc, sub_self, Fork.IsLimit.lift_ι, Fork.ι_ofι, IsSplitEpi.id_assoc] inr_snd := by simp } /-- The bicone constructed in `binaryBiconeOfIsSplitEpiOfKernel` is a bilimit. This is a version of the splitting lemma that holds in all preadditive categories. -/ def isBilimitBinaryBiconeOfIsSplitEpiOfKernel {X Y : C} {f : X ⟶ Y} [IsSplitEpi f] {c : KernelFork f} (i : IsLimit c) : (binaryBiconeOfIsSplitEpiOfKernel i).IsBilimit := BinaryBicone.isBilimitOfKernelInl _ <| i.ofIsoLimit <| Fork.ext (Iso.refl _) (by simp) end section variable {X Y : C} (f g : X ⟶ Y) /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ theorem biprod.add_eq_lift_id_desc [HasBinaryBiproduct X X] : f + g = biprod.lift (𝟙 X) (𝟙 X) ≫ biprod.desc f g := by simp /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ theorem biprod.add_eq_lift_desc_id [HasBinaryBiproduct Y Y] : f + g = biprod.lift f g ≫ biprod.desc (𝟙 Y) (𝟙 Y) := by simp end end Limits open CategoryTheory.Limits section attribute [local ext] Preadditive /-- The existence of binary biproducts implies that there is at most one preadditive structure. -/ instance subsingleton_preadditive_of_hasBinaryBiproducts {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasBinaryBiproducts C] : Subsingleton (Preadditive C) where allEq := fun a b => by apply Preadditive.ext; funext X Y; apply AddCommGroup.ext; funext f g have h₁ := @biprod.add_eq_lift_id_desc _ _ a _ _ f g (by convert (inferInstance : HasBinaryBiproduct X X); subsingleton) have h₂ := @biprod.add_eq_lift_id_desc _ _ b _ _ f g (by convert (inferInstance : HasBinaryBiproduct X X); subsingleton) refine h₁.trans (Eq.trans ?_ h₂.symm) congr! 2 <;> subsingleton end section variable [HasBinaryBiproducts.{v} C] variable {X₁ X₂ Y₁ Y₂ : C} variable (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) /-- The "matrix" morphism `X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂` with specified components. -/ def Biprod.ofComponents : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂ := biprod.fst ≫ f₁₁ ≫ biprod.inl + biprod.fst ≫ f₁₂ ≫ biprod.inr + biprod.snd ≫ f₂₁ ≫ biprod.inl + biprod.snd ≫ f₂₂ ≫ biprod.inr @[simp] theorem Biprod.inl_ofComponents : biprod.inl ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₁₁ ≫ biprod.inl + f₁₂ ≫ biprod.inr := by simp [Biprod.ofComponents] @[simp] theorem Biprod.inr_ofComponents : biprod.inr ≫ Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ = f₂₁ ≫ biprod.inl + f₂₂ ≫ biprod.inr := by simp [Biprod.ofComponents] @[simp] theorem Biprod.ofComponents_fst : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.fst = biprod.fst ≫ f₁₁ + biprod.snd ≫ f₂₁ := by simp [Biprod.ofComponents] @[simp] theorem Biprod.ofComponents_snd : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ biprod.snd = biprod.fst ≫ f₁₂ + biprod.snd ≫ f₂₂ := by simp [Biprod.ofComponents] @[simp] theorem Biprod.ofComponents_eq (f : X₁ ⊞ X₂ ⟶ Y₁ ⊞ Y₂) : Biprod.ofComponents (biprod.inl ≫ f ≫ biprod.fst) (biprod.inl ≫ f ≫ biprod.snd) (biprod.inr ≫ f ≫ biprod.fst) (biprod.inr ≫ f ≫ biprod.snd) = f := by ext <;> simp only [Category.comp_id, biprod.inr_fst, biprod.inr_snd, biprod.inl_snd, add_zero, zero_add, Biprod.inl_ofComponents, Biprod.inr_ofComponents, eq_self_iff_true, Category.assoc, comp_zero, biprod.inl_fst, Preadditive.add_comp] @[simp] theorem Biprod.ofComponents_comp {X₁ X₂ Y₁ Y₂ Z₁ Z₂ : C} (f₁₁ : X₁ ⟶ Y₁) (f₁₂ : X₁ ⟶ Y₂) (f₂₁ : X₂ ⟶ Y₁) (f₂₂ : X₂ ⟶ Y₂) (g₁₁ : Y₁ ⟶ Z₁) (g₁₂ : Y₁ ⟶ Z₂) (g₂₁ : Y₂ ⟶ Z₁) (g₂₂ : Y₂ ⟶ Z₂) : Biprod.ofComponents f₁₁ f₁₂ f₂₁ f₂₂ ≫ Biprod.ofComponents g₁₁ g₁₂ g₂₁ g₂₂ = Biprod.ofComponents (f₁₁ ≫ g₁₁ + f₁₂ ≫ g₂₁) (f₁₁ ≫ g₁₂ + f₁₂ ≫ g₂₂) (f₂₁ ≫ g₁₁ + f₂₂ ≫ g₂₁) (f₂₁ ≫ g₁₂ + f₂₂ ≫ g₂₂) := by dsimp [Biprod.ofComponents] ext <;> simp only [add_comp, comp_add, add_comp_assoc, add_zero, zero_add, biprod.inl_fst, biprod.inl_snd, biprod.inr_fst, biprod.inr_snd, biprod.inl_fst_assoc, biprod.inl_snd_assoc, biprod.inr_fst_assoc, biprod.inr_snd_assoc, comp_zero, zero_comp, Category.assoc] /-- The unipotent upper triangular matrix ``` (1 r) (0 1) ``` as an isomorphism. -/ @[simps] def Biprod.unipotentUpper {X₁ X₂ : C} (r : X₁ ⟶ X₂) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ where hom := Biprod.ofComponents (𝟙 _) r 0 (𝟙 _) inv := Biprod.ofComponents (𝟙 _) (-r) 0 (𝟙 _) /-- The unipotent lower triangular matrix ```
(1 0) (r 1) ``` as an isomorphism. -/ @[simps] def Biprod.unipotentLower {X₁ X₂ : C} (r : X₂ ⟶ X₁) : X₁ ⊞ X₂ ≅ X₁ ⊞ X₂ where hom := Biprod.ofComponents (𝟙 _) 0 r (𝟙 _)
Mathlib/CategoryTheory/Preadditive/Biproducts.lean
719
726
/- 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
Mathlib/Combinatorics/SimpleGraph/AdjMatrix.lean
204
206
/- 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 μ]
Mathlib/Probability/StrongLaw.lean
114
123
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Data.ENat.Lattice import Mathlib.Data.Part import Mathlib.Tactic.NormNum /-! # Natural numbers with infinity The natural numbers and an extra `top` element `⊤`. This implementation uses `Part ℕ` as an implementation. Use `ℕ∞` instead unless you care about computability. ## Main definitions The following instances are defined: * `OrderedAddCommMonoid PartENat` * `CanonicallyOrderedAdd PartENat` * `CompleteLinearOrder PartENat` There is no additive analogue of `MonoidWithZero`; if there were then `PartENat` could be an `AddMonoidWithTop`. * `toWithTop` : the map from `PartENat` to `ℕ∞`, with theorems that it plays well with `+` and `≤`. * `withTopAddEquiv : PartENat ≃+ ℕ∞` * `withTopOrderIso : PartENat ≃o ℕ∞` ## Implementation details `PartENat` is defined to be `Part ℕ`. `+` and `≤` are defined on `PartENat`, but there is an issue with `*` because it's not clear what `0 * ⊤` should be. `mul` is hence left undefined. Similarly `⊤ - ⊤` is ambiguous so there is no `-` defined on `PartENat`. Before the `open scoped Classical` line, various proofs are made with decidability assumptions. This can cause issues -- see for example the non-simp lemma `toWithTopZero` proved by `rfl`, followed by `@[simp] lemma toWithTopZero'` whose proof uses `convert`. ## Tags PartENat, ℕ∞ -/ open Part hiding some /-- Type of natural numbers with infinity (`⊤`) -/ def PartENat : Type := Part ℕ namespace PartENat /-- The computable embedding `ℕ → PartENat`. This coincides with the coercion `coe : ℕ → PartENat`, see `PartENat.some_eq_natCast`. -/ @[coe] def some : ℕ → PartENat := Part.some instance : Zero PartENat := ⟨some 0⟩ instance : Inhabited PartENat := ⟨0⟩ instance : One PartENat := ⟨some 1⟩ instance : Add PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => get x h.1 + get y h.2⟩⟩ instance (n : ℕ) : Decidable (some n).Dom := isTrue trivial @[simp] theorem dom_some (x : ℕ) : (some x).Dom := trivial instance addCommMonoid : AddCommMonoid PartENat where add := (· + ·) zero := 0 add_comm _ _ := Part.ext' and_comm fun _ _ => add_comm _ _ zero_add _ := Part.ext' (iff_of_eq (true_and _)) fun _ _ => zero_add _ add_zero _ := Part.ext' (iff_of_eq (and_true _)) fun _ _ => add_zero _ add_assoc _ _ _ := Part.ext' and_assoc fun _ _ => add_assoc _ _ _ nsmul := nsmulRec instance : AddCommMonoidWithOne PartENat := { PartENat.addCommMonoid with one := 1 natCast := some natCast_zero := rfl natCast_succ := fun _ => Part.ext' (iff_of_eq (true_and _)).symm fun _ _ => rfl } theorem some_eq_natCast (n : ℕ) : some n = n := rfl instance : CharZero PartENat where cast_injective := Part.some_injective /-- Alias of `Nat.cast_inj` specialized to `PartENat` -/ theorem natCast_inj {x y : ℕ} : (x : PartENat) = y ↔ x = y := Nat.cast_inj @[simp] theorem dom_natCast (x : ℕ) : (x : PartENat).Dom := trivial @[simp] theorem dom_ofNat (x : ℕ) [x.AtLeastTwo] : (ofNat(x) : PartENat).Dom := trivial @[simp] theorem dom_zero : (0 : PartENat).Dom := trivial @[simp] theorem dom_one : (1 : PartENat).Dom := trivial instance : CanLift PartENat ℕ (↑) Dom := ⟨fun n hn => ⟨n.get hn, Part.some_get _⟩⟩ instance : LE PartENat := ⟨fun x y => ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy⟩ instance : Top PartENat := ⟨none⟩ instance : Bot PartENat := ⟨0⟩ instance : Max PartENat := ⟨fun x y => ⟨x.Dom ∧ y.Dom, fun h => x.get h.1 ⊔ y.get h.2⟩⟩ theorem le_def (x y : PartENat) : x ≤ y ↔ ∃ h : y.Dom → x.Dom, ∀ hy : y.Dom, x.get (h hy) ≤ y.get hy := Iff.rfl @[elab_as_elim] protected theorem casesOn' {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P (some n)) → P a := Part.induction_on @[elab_as_elim] protected theorem casesOn {P : PartENat → Prop} : ∀ a : PartENat, P ⊤ → (∀ n : ℕ, P n) → P a := by exact PartENat.casesOn' -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem top_add (x : PartENat) : ⊤ + x = ⊤ := Part.ext' (iff_of_eq (false_and _)) fun h => h.left.elim -- not a simp lemma as we will provide a `LinearOrderedAddCommMonoidWithTop` instance later theorem add_top (x : PartENat) : x + ⊤ = ⊤ := by rw [add_comm, top_add] @[simp] theorem natCast_get {x : PartENat} (h : x.Dom) : (x.get h : PartENat) = x := by exact Part.ext' (iff_of_true trivial h) fun _ _ => rfl @[simp, norm_cast] theorem get_natCast' (x : ℕ) (h : (x : PartENat).Dom) : get (x : PartENat) h = x := by rw [← natCast_inj, natCast_get] theorem get_natCast {x : ℕ} : get (x : PartENat) (dom_natCast x) = x := get_natCast' _ _ theorem coe_add_get {x : ℕ} {y : PartENat} (h : ((x : PartENat) + y).Dom) : get ((x : PartENat) + y) h = x + get y h.2 := by rfl @[simp] theorem get_add {x y : PartENat} (h : (x + y).Dom) : get (x + y) h = x.get h.1 + y.get h.2 := rfl @[simp] theorem get_zero (h : (0 : PartENat).Dom) : (0 : PartENat).get h = 0 := rfl @[simp] theorem get_one (h : (1 : PartENat).Dom) : (1 : PartENat).get h = 1 := rfl @[simp] theorem get_ofNat' (x : ℕ) [x.AtLeastTwo] (h : (ofNat(x) : PartENat).Dom) : Part.get (ofNat(x) : PartENat) h = ofNat(x) := get_natCast' x h nonrec theorem get_eq_iff_eq_some {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = some b := get_eq_iff_eq_some theorem get_eq_iff_eq_coe {a : PartENat} {ha : a.Dom} {b : ℕ} : a.get ha = b ↔ a = b := by rw [get_eq_iff_eq_some] rfl theorem dom_of_le_of_dom {x y : PartENat} : x ≤ y → y.Dom → x.Dom := fun ⟨h, _⟩ => h theorem dom_of_le_some {x : PartENat} {y : ℕ} (h : x ≤ some y) : x.Dom := dom_of_le_of_dom h trivial theorem dom_of_le_natCast {x : PartENat} {y : ℕ} (h : x ≤ y) : x.Dom := by exact dom_of_le_some h instance decidableLe (x y : PartENat) [Decidable x.Dom] [Decidable y.Dom] : Decidable (x ≤ y) := if hx : x.Dom then decidable_of_decidable_of_iff (le_def x y).symm else if hy : y.Dom then isFalse fun h => hx <| dom_of_le_of_dom h hy else isTrue ⟨fun h => (hy h).elim, fun h => (hy h).elim⟩ instance partialOrder : PartialOrder PartENat where le := (· ≤ ·) le_refl _ := ⟨id, fun _ => le_rfl⟩ le_trans := fun _ _ _ ⟨hxy₁, hxy₂⟩ ⟨hyz₁, hyz₂⟩ => ⟨hxy₁ ∘ hyz₁, fun _ => le_trans (hxy₂ _) (hyz₂ _)⟩ lt_iff_le_not_le _ _ := Iff.rfl le_antisymm := fun _ _ ⟨hxy₁, hxy₂⟩ ⟨hyx₁, hyx₂⟩ => Part.ext' ⟨hyx₁, hxy₁⟩ fun _ _ => le_antisymm (hxy₂ _) (hyx₂ _) theorem lt_def (x y : PartENat) : x < y ↔ ∃ hx : x.Dom, ∀ hy : y.Dom, x.get hx < y.get hy := by rw [lt_iff_le_not_le, le_def, le_def, not_exists] constructor · rintro ⟨⟨hyx, H⟩, h⟩ by_cases hx : x.Dom · use hx intro hy specialize H hy specialize h fun _ => hy rw [not_forall] at h obtain ⟨hx', h⟩ := h rw [not_le] at h exact h · specialize h fun hx' => (hx hx').elim rw [not_forall] at h obtain ⟨hx', h⟩ := h exact (hx hx').elim · rintro ⟨hx, H⟩ exact ⟨⟨fun _ => hx, fun hy => (H hy).le⟩, fun hxy h => not_lt_of_le (h _) (H _)⟩ noncomputable instance isOrderedAddMonoid : IsOrderedAddMonoid PartENat := { add_le_add_left := fun a b ⟨h₁, h₂⟩ c => PartENat.casesOn c (by simp [top_add]) fun c => ⟨fun h => And.intro (dom_natCast _) (h₁ h.2), fun h => by simpa only [coe_add_get] using add_le_add_left (h₂ _) c⟩ } instance semilatticeSup : SemilatticeSup PartENat := { PartENat.partialOrder with sup := (· ⊔ ·) le_sup_left := fun _ _ => ⟨And.left, fun _ => le_sup_left⟩ le_sup_right := fun _ _ => ⟨And.right, fun _ => le_sup_right⟩ sup_le := fun _ _ _ ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ => ⟨fun hz => ⟨hx₁ hz, hy₁ hz⟩, fun _ => sup_le (hx₂ _) (hy₂ _)⟩ } instance orderBot : OrderBot PartENat where bot := ⊥ bot_le _ := ⟨fun _ => trivial, fun _ => Nat.zero_le _⟩ instance orderTop : OrderTop PartENat where top := ⊤ le_top _ := ⟨fun h => False.elim h, fun hy => False.elim hy⟩ instance : ZeroLEOneClass PartENat where zero_le_one := bot_le /-- Alias of `Nat.cast_le` specialized to `PartENat` -/ theorem coe_le_coe {x y : ℕ} : (x : PartENat) ≤ y ↔ x ≤ y := Nat.cast_le /-- Alias of `Nat.cast_lt` specialized to `PartENat` -/ theorem coe_lt_coe {x y : ℕ} : (x : PartENat) < y ↔ x < y := Nat.cast_lt @[simp] theorem get_le_get {x y : PartENat} {hx : x.Dom} {hy : y.Dom} : x.get hx ≤ y.get hy ↔ x ≤ y := by conv => lhs rw [← coe_le_coe, natCast_get, natCast_get] theorem le_coe_iff (x : PartENat) (n : ℕ) : x ≤ n ↔ ∃ h : x.Dom, x.get h ≤ n := by show (∃ h : True → x.Dom, _) ↔ ∃ h : x.Dom, x.get h ≤ n simp only [forall_prop_of_true, dom_natCast, get_natCast'] theorem lt_coe_iff (x : PartENat) (n : ℕ) : x < n ↔ ∃ h : x.Dom, x.get h < n := by simp only [lt_def, forall_prop_of_true, get_natCast', dom_natCast] theorem coe_le_iff (n : ℕ) (x : PartENat) : (n : PartENat) ≤ x ↔ ∀ h : x.Dom, n ≤ x.get h := by rw [← some_eq_natCast] simp only [le_def, exists_prop_of_true, dom_some, forall_true_iff] rfl theorem coe_lt_iff (n : ℕ) (x : PartENat) : (n : PartENat) < x ↔ ∀ h : x.Dom, n < x.get h := by rw [← some_eq_natCast] simp only [lt_def, exists_prop_of_true, dom_some, forall_true_iff] rfl nonrec theorem eq_zero_iff {x : PartENat} : x = 0 ↔ x ≤ 0 := eq_bot_iff theorem ne_zero_iff {x : PartENat} : x ≠ 0 ↔ ⊥ < x := bot_lt_iff_ne_bot.symm theorem dom_of_lt {x y : PartENat} : x < y → x.Dom := PartENat.casesOn x not_top_lt fun _ _ => dom_natCast _ theorem top_eq_none : (⊤ : PartENat) = Part.none := rfl @[simp] theorem natCast_lt_top (x : ℕ) : (x : PartENat) < ⊤ := Ne.lt_top fun h => absurd (congr_arg Dom h) <| by simp only [dom_natCast]; exact true_ne_false @[simp] theorem zero_lt_top : (0 : PartENat) < ⊤ := natCast_lt_top 0 @[simp] theorem one_lt_top : (1 : PartENat) < ⊤ := natCast_lt_top 1 @[simp] theorem ofNat_lt_top (x : ℕ) [x.AtLeastTwo] : (ofNat(x) : PartENat) < ⊤ := natCast_lt_top x @[simp] theorem natCast_ne_top (x : ℕ) : (x : PartENat) ≠ ⊤ := ne_of_lt (natCast_lt_top x) @[simp] theorem zero_ne_top : (0 : PartENat) ≠ ⊤ := natCast_ne_top 0 @[simp] theorem one_ne_top : (1 : PartENat) ≠ ⊤ := natCast_ne_top 1 @[simp] theorem ofNat_ne_top (x : ℕ) [x.AtLeastTwo] : (ofNat(x) : PartENat) ≠ ⊤ := natCast_ne_top x theorem not_isMax_natCast (x : ℕ) : ¬IsMax (x : PartENat) := not_isMax_of_lt (natCast_lt_top x) theorem ne_top_iff {x : PartENat} : x ≠ ⊤ ↔ ∃ n : ℕ, x = n := by simpa only [← some_eq_natCast] using Part.ne_none_iff theorem ne_top_iff_dom {x : PartENat} : x ≠ ⊤ ↔ x.Dom := by classical exact not_iff_comm.1 Part.eq_none_iff'.symm theorem not_dom_iff_eq_top {x : PartENat} : ¬x.Dom ↔ x = ⊤ := Iff.not_left ne_top_iff_dom.symm theorem ne_top_of_lt {x y : PartENat} (h : x < y) : x ≠ ⊤ := ne_of_lt <| lt_of_lt_of_le h le_top theorem eq_top_iff_forall_lt (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) < x := by constructor · rintro rfl n exact natCast_lt_top _ · contrapose! rw [ne_top_iff] rintro ⟨n, rfl⟩ exact ⟨n, irrefl _⟩ theorem eq_top_iff_forall_le (x : PartENat) : x = ⊤ ↔ ∀ n : ℕ, (n : PartENat) ≤ x := (eq_top_iff_forall_lt x).trans ⟨fun h n => (h n).le, fun h n => lt_of_lt_of_le (coe_lt_coe.mpr n.lt_succ_self) (h (n + 1))⟩ theorem pos_iff_one_le {x : PartENat} : 0 < x ↔ 1 ≤ x := PartENat.casesOn x (by simp only [le_top, natCast_lt_top, ← @Nat.cast_zero PartENat]) fun n => by rw [← Nat.cast_zero, ← Nat.cast_one, PartENat.coe_lt_coe, PartENat.coe_le_coe] rfl instance isTotal : IsTotal PartENat (· ≤ ·) where total x y := PartENat.casesOn (P := fun z => z ≤ y ∨ y ≤ z) x (Or.inr le_top) (PartENat.casesOn y (fun _ => Or.inl le_top) fun x y => (le_total x y).elim (Or.inr ∘ coe_le_coe.2) (Or.inl ∘ coe_le_coe.2)) noncomputable instance linearOrder : LinearOrder PartENat := { PartENat.partialOrder with le_total := IsTotal.total toDecidableLE := Classical.decRel _ max := (· ⊔ ·) max_def a b := congr_fun₂ (@sup_eq_maxDefault PartENat _ (_) _) _ _ } instance boundedOrder : BoundedOrder PartENat := { PartENat.orderTop, PartENat.orderBot with } noncomputable instance lattice : Lattice PartENat := { PartENat.semilatticeSup with inf := min inf_le_left := min_le_left inf_le_right := min_le_right le_inf := fun _ _ _ => le_min } instance : CanonicallyOrderedAdd PartENat := { le_self_add := fun a b => PartENat.casesOn b (le_top.trans_eq (add_top _).symm) fun _ => PartENat.casesOn a (top_add _).ge fun _ => (coe_le_coe.2 le_self_add).trans_eq (Nat.cast_add _ _) exists_add_of_le := fun {a b} => PartENat.casesOn b (fun _ => ⟨⊤, (add_top _).symm⟩) fun b => PartENat.casesOn a (fun h => ((natCast_lt_top _).not_le h).elim) fun a h => ⟨(b - a : ℕ), by rw [← Nat.cast_add, natCast_inj, add_comm, tsub_add_cancel_of_le (coe_le_coe.1 h)]⟩ } theorem eq_natCast_sub_of_add_eq_natCast {x y : PartENat} {n : ℕ} (h : x + y = n) : x = ↑(n - y.get (dom_of_le_natCast ((le_add_left le_rfl).trans_eq h))) := by lift x to ℕ using dom_of_le_natCast ((le_add_right le_rfl).trans_eq h) lift y to ℕ using dom_of_le_natCast ((le_add_left le_rfl).trans_eq h) rw [← Nat.cast_add, natCast_inj] at h rw [get_natCast, natCast_inj, eq_tsub_of_add_eq h] protected theorem add_lt_add_right {x y z : PartENat} (h : x < y) (hz : z ≠ ⊤) : x + z < y + z := by rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ rcases ne_top_iff.mp hz with ⟨k, rfl⟩ induction y using PartENat.casesOn · rw [top_add] exact_mod_cast natCast_lt_top _ norm_cast at h exact_mod_cast add_lt_add_right h _ protected theorem add_lt_add_iff_right {x y z : PartENat} (hz : z ≠ ⊤) : x + z < y + z ↔ x < y := ⟨lt_of_add_lt_add_right, fun h => PartENat.add_lt_add_right h hz⟩ protected theorem add_lt_add_iff_left {x y z : PartENat} (hz : z ≠ ⊤) : z + x < z + y ↔ x < y := by rw [add_comm z, add_comm z, PartENat.add_lt_add_iff_right hz] protected theorem lt_add_iff_pos_right {x y : PartENat} (hx : x ≠ ⊤) : x < x + y ↔ 0 < y := by conv_rhs => rw [← PartENat.add_lt_add_iff_left hx] rw [add_zero] theorem lt_add_one {x : PartENat} (hx : x ≠ ⊤) : x < x + 1 := by rw [PartENat.lt_add_iff_pos_right hx] norm_cast theorem le_of_lt_add_one {x y : PartENat} (h : x < y + 1) : x ≤ y := by induction y using PartENat.casesOn · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ exact_mod_cast Nat.le_of_lt_succ (by norm_cast at h) theorem add_one_le_of_lt {x y : PartENat} (h : x < y) : x + 1 ≤ y := by induction y using PartENat.casesOn · apply le_top rcases ne_top_iff.mp (ne_top_of_lt h) with ⟨m, rfl⟩ exact_mod_cast Nat.succ_le_of_lt (by norm_cast at h) theorem add_one_le_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x + 1 ≤ y ↔ x < y := by refine ⟨fun h => ?_, add_one_le_of_lt⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction y using PartENat.casesOn · apply natCast_lt_top exact_mod_cast Nat.lt_of_succ_le (by norm_cast at h) theorem coe_succ_le_iff {n : ℕ} {e : PartENat} : ↑n.succ ≤ e ↔ ↑n < e := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, add_one_le_iff_lt (natCast_ne_top n)] theorem lt_add_one_iff_lt {x y : PartENat} (hx : x ≠ ⊤) : x < y + 1 ↔ x ≤ y := by refine ⟨le_of_lt_add_one, fun h => ?_⟩ rcases ne_top_iff.mp hx with ⟨m, rfl⟩ induction y using PartENat.casesOn · rw [top_add] apply natCast_lt_top exact_mod_cast Nat.lt_succ_of_le (by norm_cast at h) lemma lt_coe_succ_iff_le {x : PartENat} {n : ℕ} (hx : x ≠ ⊤) : x < n.succ ↔ x ≤ n := by rw [Nat.succ_eq_add_one n, Nat.cast_add, Nat.cast_one, lt_add_one_iff_lt hx] theorem add_eq_top_iff {a b : PartENat} : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ := by refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [top_add, add_top] simp only [← Nat.cast_add, PartENat.natCast_ne_top, forall_const, not_false_eq_true] protected theorem add_right_cancel_iff {a b c : PartENat} (hc : c ≠ ⊤) : a + c = b + c ↔ a = b := by rcases ne_top_iff.1 hc with ⟨c, rfl⟩ refine PartENat.casesOn a ?_ ?_ <;> refine PartENat.casesOn b ?_ ?_ <;> simp [add_eq_top_iff, natCast_ne_top, @eq_comm _ (⊤ : PartENat), top_add] simp only [← Nat.cast_add, add_left_cancel_iff, PartENat.natCast_inj, add_comm, forall_const] protected theorem add_left_cancel_iff {a b c : PartENat} (ha : a ≠ ⊤) : a + b = a + c ↔ b = c := by rw [add_comm a, add_comm a, PartENat.add_right_cancel_iff ha] section WithTop /-- Computably converts a `PartENat` to a `ℕ∞`. -/ def toWithTop (x : PartENat) [Decidable x.Dom] : ℕ∞ := x.toOption theorem toWithTop_top : have : Decidable (⊤ : PartENat).Dom := Part.noneDecidable toWithTop ⊤ = ⊤ := rfl @[simp] theorem toWithTop_top' {h : Decidable (⊤ : PartENat).Dom} : toWithTop ⊤ = ⊤ := by convert toWithTop_top theorem toWithTop_zero : have : Decidable (0 : PartENat).Dom := someDecidable 0 toWithTop 0 = 0 := rfl @[simp] theorem toWithTop_zero' {h : Decidable (0 : PartENat).Dom} : toWithTop 0 = 0 := by convert toWithTop_zero theorem toWithTop_one : have : Decidable (1 : PartENat).Dom := someDecidable 1 toWithTop 1 = 1 := rfl @[simp] theorem toWithTop_one' {h : Decidable (1 : PartENat).Dom} : toWithTop 1 = 1 := by convert toWithTop_one theorem toWithTop_some (n : ℕ) : toWithTop (some n) = n := rfl theorem toWithTop_natCast (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop n = n := by simp only [← toWithTop_some] congr @[simp] theorem toWithTop_natCast' (n : ℕ) {_ : Decidable (n : PartENat).Dom} : toWithTop (n : PartENat) = n := by rw [toWithTop_natCast n] @[simp] theorem toWithTop_ofNat (n : ℕ) [n.AtLeastTwo] {_ : Decidable (OfNat.ofNat n : PartENat).Dom} : toWithTop (ofNat(n) : PartENat) = OfNat.ofNat n := toWithTop_natCast' n @[simp] theorem toWithTop_le {x y : PartENat} [hx : Decidable x.Dom] [hy : Decidable y.Dom] : toWithTop x ≤ toWithTop y ↔ x ≤ y := by induction y using PartENat.casesOn generalizing hy · simp induction x using PartENat.casesOn generalizing hx · simp · simp @[simp] theorem toWithTop_lt {x y : PartENat} [Decidable x.Dom] [Decidable y.Dom] : toWithTop x < toWithTop y ↔ x < y := lt_iff_lt_of_le_iff_le toWithTop_le end WithTop /-- Coercion from `ℕ∞` to `PartENat`. -/ @[coe] def ofENat : ℕ∞ → PartENat := fun x => match x with | Option.none => none | Option.some n => some n instance : Coe ℕ∞ PartENat := ⟨ofENat⟩ example (n : ℕ) : ((n : ℕ∞) : PartENat) = ↑n := rfl @[simp, norm_cast] lemma ofENat_top : ofENat ⊤ = ⊤ := rfl @[simp, norm_cast] lemma ofENat_coe (n : ℕ) : ofENat n = n := rfl @[simp, norm_cast] theorem ofENat_zero : ofENat 0 = 0 := rfl @[simp, norm_cast] theorem ofENat_one : ofENat 1 = 1 := rfl @[simp, norm_cast] theorem ofENat_ofNat (n : Nat) [n.AtLeastTwo] : ofENat ofNat(n) = OfNat.ofNat n := rfl @[simp, norm_cast] theorem toWithTop_ofENat (n : ℕ∞) {_ : Decidable (n : PartENat).Dom} : toWithTop (↑n) = n := by cases n with | top => simp | coe n => simp @[simp, norm_cast] theorem ofENat_toWithTop (x : PartENat) {_ : Decidable (x : PartENat).Dom} : toWithTop x = x := by induction x using PartENat.casesOn <;> simp @[simp, norm_cast] theorem ofENat_le {x y : ℕ∞} : ofENat x ≤ ofENat y ↔ x ≤ y := by classical rw [← toWithTop_le, toWithTop_ofENat, toWithTop_ofENat] @[simp, norm_cast] theorem ofENat_lt {x y : ℕ∞} : ofENat x < ofENat y ↔ x < y := by classical rw [← toWithTop_lt, toWithTop_ofENat, toWithTop_ofENat] section WithTopEquiv open scoped Classical in @[simp] theorem toWithTop_add {x y : PartENat} : toWithTop (x + y) = toWithTop x + toWithTop y := by refine PartENat.casesOn y ?_ ?_ <;> refine PartENat.casesOn x ?_ ?_ <;> simp [add_top, top_add, ← Nat.cast_add, ← ENat.coe_add] open scoped Classical in /-- `Equiv` between `PartENat` and `ℕ∞` (for the order isomorphism see `withTopOrderIso`). -/ @[simps] noncomputable def withTopEquiv : PartENat ≃ ℕ∞ where toFun x := toWithTop x invFun x := ↑x left_inv x := by simp right_inv x := by simp theorem withTopEquiv_top : withTopEquiv ⊤ = ⊤ := by simp theorem withTopEquiv_natCast (n : Nat) : withTopEquiv n = n := by simp theorem withTopEquiv_zero : withTopEquiv 0 = 0 := by simp theorem withTopEquiv_one : withTopEquiv 1 = 1 := by simp theorem withTopEquiv_ofNat (n : Nat) [n.AtLeastTwo] : withTopEquiv ofNat(n) = OfNat.ofNat n := by simp theorem withTopEquiv_le {x y : PartENat} : withTopEquiv x ≤ withTopEquiv y ↔ x ≤ y := by simp theorem withTopEquiv_lt {x y : PartENat} : withTopEquiv x < withTopEquiv y ↔ x < y := by simp theorem withTopEquiv_symm_top : withTopEquiv.symm ⊤ = ⊤ := by simp theorem withTopEquiv_symm_coe (n : Nat) : withTopEquiv.symm n = n := by simp theorem withTopEquiv_symm_zero : withTopEquiv.symm 0 = 0 := by simp theorem withTopEquiv_symm_one : withTopEquiv.symm 1 = 1 := by simp theorem withTopEquiv_symm_ofNat (n : Nat) [n.AtLeastTwo] : withTopEquiv.symm ofNat(n) = OfNat.ofNat n := by simp theorem withTopEquiv_symm_le {x y : ℕ∞} : withTopEquiv.symm x ≤ withTopEquiv.symm y ↔ x ≤ y := by simp theorem withTopEquiv_symm_lt {x y : ℕ∞} : withTopEquiv.symm x < withTopEquiv.symm y ↔ x < y := by simp /-- `toWithTop` induces an order isomorphism between `PartENat` and `ℕ∞`. -/ noncomputable def withTopOrderIso : PartENat ≃o ℕ∞ := { withTopEquiv with map_rel_iff' := @fun _ _ => withTopEquiv_le } /-- `toWithTop` induces an additive monoid isomorphism between `PartENat` and `ℕ∞`. -/ noncomputable def withTopAddEquiv : PartENat ≃+ ℕ∞ := { withTopEquiv with map_add' := fun x y => by simp only [withTopEquiv] exact toWithTop_add } end WithTopEquiv theorem lt_wf : @WellFounded PartENat (· < ·) := by classical change WellFounded fun a b : PartENat => a < b simp_rw [← withTopEquiv_lt] exact InvImage.wf _ wellFounded_lt instance : WellFoundedLT PartENat := ⟨lt_wf⟩ instance wellFoundedRelation : WellFoundedRelation PartENat := ⟨(· < ·), lt_wf⟩ section Find variable (P : ℕ → Prop) [DecidablePred P] /-- The smallest `PartENat` satisfying a (decidable) predicate `P : ℕ → Prop` -/ def find : PartENat := ⟨∃ n, P n, Nat.find⟩ @[simp] theorem find_get (h : (find P).Dom) : (find P).get h = Nat.find h := rfl theorem find_dom (h : ∃ n, P n) : (find P).Dom := h theorem lt_find (n : ℕ) (h : ∀ m ≤ n, ¬P m) : (n : PartENat) < find P := by rw [coe_lt_iff] intro h₁ rw [find_get] have h₂ := @Nat.find_spec P _ h₁ revert h₂ contrapose! exact h _ theorem lt_find_iff (n : ℕ) : (n : PartENat) < find P ↔ ∀ m ≤ n, ¬P m := by refine ⟨?_, lt_find P n⟩ intro h m hm by_cases H : (find P).Dom · apply Nat.find_min H rw [coe_lt_iff] at h specialize h H exact lt_of_le_of_lt hm h · exact not_exists.mp H m theorem find_le (n : ℕ) (h : P n) : find P ≤ n := by rw [le_coe_iff] exact ⟨⟨_, h⟩, @Nat.find_min' P _ _ _ h⟩ theorem find_eq_top_iff : find P = ⊤ ↔ ∀ n, ¬P n := (eq_top_iff_forall_lt _).trans ⟨fun h n => (lt_find_iff P n).mp (h n) _ le_rfl, fun h n => lt_find P n fun _ _ => h _⟩ end Find noncomputable instance : LinearOrderedAddCommMonoidWithTop PartENat := { PartENat.linearOrder, PartENat.isOrderedAddMonoid, PartENat.orderTop with top_add' := top_add } noncomputable instance : CompleteLinearOrder PartENat := { lattice, withTopOrderIso.symm.toGaloisInsertion.liftCompleteLattice, linearOrder, LinearOrder.toBiheytingAlgebra with } end PartENat
Mathlib/Data/Nat/PartENat.lean
872
874
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Ordmap.Invariants /-! # Verification of `Ordnode` This file uses the invariants defined in `Mathlib.Data.Ordmap.Invariants` to construct `Ordset α`, a wrapper around `Ordnode α` which includes the correctness invariant of the type. It exposes parallel operations like `insert` as functions on `Ordset` that do the same thing but bundle the correctness proofs. The advantage is that it is possible to, for example, prove that the result of `find` on `insert` will actually find the element, while `Ordnode` cannot guarantee this if the input tree did not satisfy the type invariants. ## Main definitions * `Ordnode.Valid`: The validity predicate for an `Ordnode` subtree. * `Ordset α`: A well formed set of values of type `α`. ## Implementation notes Because the `Ordnode` file was ported from Haskell, the correctness invariants of some of the functions have not been spelled out, and some theorems like `Ordnode.Valid'.balanceL_aux` show very intricate assumptions on the sizes, which may need to be revised if it turns out some operations violate these assumptions, because there is a decent amount of slop in the actual data structure invariants, so the theorem will go through with multiple choices of assumption. -/ variable {α : Type*} namespace Ordnode section Valid variable [Preorder α] /-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. This version of `Valid` also puts all elements in the tree in the interval `(lo, hi)`. -/ structure Valid' (lo : WithBot α) (t : Ordnode α) (hi : WithTop α) : Prop where ord : t.Bounded lo hi sz : t.Sized bal : t.Balanced /-- The validity predicate for an `Ordnode` subtree. This asserts that the `size` fields are correct, the tree is balanced, and the elements of the tree are organized according to the ordering. -/ def Valid (t : Ordnode α) : Prop := Valid' ⊥ t ⊤ theorem Valid'.mono_left {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' y t o) : Valid' x t o := ⟨h.1.mono_left xy, h.2, h.3⟩ theorem Valid'.mono_right {x y : α} (xy : x ≤ y) {t : Ordnode α} {o} (h : Valid' o t x) : Valid' o t y := ⟨h.1.mono_right xy, h.2, h.3⟩ theorem Valid'.trans_left {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (h : Bounded t₁ o₁ x) (H : Valid' x t₂ o₂) : Valid' o₁ t₂ o₂ := ⟨h.trans_left H.1, H.2, H.3⟩ theorem Valid'.trans_right {t₁ t₂ : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t₁ x) (h : Bounded t₂ x o₂) : Valid' o₁ t₁ o₂ := ⟨H.1.trans_right h, H.2, H.3⟩ theorem Valid'.of_lt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil o₁ x) (h₂ : All (· < x) t) : Valid' o₁ t x := ⟨H.1.of_lt h₁ h₂, H.2, H.3⟩ theorem Valid'.of_gt {t : Ordnode α} {x : α} {o₁ o₂} (H : Valid' o₁ t o₂) (h₁ : Bounded nil x o₂) (h₂ : All (· > x) t) : Valid' x t o₂ := ⟨H.1.of_gt h₁ h₂, H.2, H.3⟩ theorem Valid'.valid {t o₁ o₂} (h : @Valid' α _ o₁ t o₂) : Valid t := ⟨h.1.weak, h.2, h.3⟩ theorem valid'_nil {o₁ o₂} (h : Bounded nil o₁ o₂) : Valid' o₁ (@nil α) o₂ := ⟨h, ⟨⟩, ⟨⟩⟩ theorem valid_nil : Valid (@nil α) := valid'_nil ⟨⟩ theorem Valid'.node {s l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : BalancedSz (size l) (size r)) (hs : s = size l + size r + 1) : Valid' o₁ (@node α s l x r) o₂ := ⟨⟨hl.1, hr.1⟩, ⟨hs, hl.2, hr.2⟩, ⟨H, hl.3, hr.3⟩⟩ theorem Valid'.dual : ∀ {t : Ordnode α} {o₁ o₂}, Valid' o₁ t o₂ → @Valid' αᵒᵈ _ o₂ (dual t) o₁ | .nil, _, _, h => valid'_nil h.1.dual | .node _ l _ r, _, _, ⟨⟨ol, Or⟩, ⟨rfl, sl, sr⟩, ⟨b, bl, br⟩⟩ => let ⟨ol', sl', bl'⟩ := Valid'.dual ⟨ol, sl, bl⟩ let ⟨or', sr', br'⟩ := Valid'.dual ⟨Or, sr, br⟩ ⟨⟨or', ol'⟩, ⟨by simp [size_dual, add_comm], sr', sl'⟩, ⟨by rw [size_dual, size_dual]; exact b.symm, br', bl'⟩⟩ theorem Valid'.dual_iff {t : Ordnode α} {o₁ o₂} : Valid' o₁ t o₂ ↔ @Valid' αᵒᵈ _ o₂ (.dual t) o₁ := ⟨Valid'.dual, fun h => by have := Valid'.dual h; rwa [dual_dual, OrderDual.Preorder.dual_dual] at this⟩ theorem Valid.dual {t : Ordnode α} : Valid t → @Valid αᵒᵈ _ (.dual t) := Valid'.dual theorem Valid.dual_iff {t : Ordnode α} : Valid t ↔ @Valid αᵒᵈ _ (.dual t) := Valid'.dual_iff theorem Valid'.left {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' o₁ l x := ⟨H.1.1, H.2.2.1, H.3.2.1⟩ theorem Valid'.right {s l x r o₁ o₂} (H : Valid' o₁ (@Ordnode.node α s l x r) o₂) : Valid' x r o₂ := ⟨H.1.2, H.2.2.2, H.3.2.2⟩ nonrec theorem Valid.left {s l x r} (H : Valid (@node α s l x r)) : Valid l := H.left.valid nonrec theorem Valid.right {s l x r} (H : Valid (@node α s l x r)) : Valid r := H.right.valid theorem Valid.size_eq {s l x r} (H : Valid (@node α s l x r)) : size (@node α s l x r) = size l + size r + 1 := H.2.1 theorem Valid'.node' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : BalancedSz (size l) (size r)) : Valid' o₁ (@node' α l x r) o₂ := hl.node hr H rfl theorem valid'_singleton {x : α} {o₁ o₂} (h₁ : Bounded nil o₁ x) (h₂ : Bounded nil x o₂) : Valid' o₁ (singleton x : Ordnode α) o₂ := (valid'_nil h₁).node (valid'_nil h₂) (Or.inl zero_le_one) rfl theorem valid_singleton {x : α} : Valid (singleton x : Ordnode α) := valid'_singleton ⟨⟩ ⟨⟩ theorem Valid'.node3L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m)) (H2 : BalancedSz (size l + size m + 1) (size r)) : Valid' o₁ (@node3L α l x m y r) o₂ := (hl.node' hm H1).node' hr H2 theorem Valid'.node3R {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' y r o₂) (H1 : BalancedSz (size l) (size m + size r + 1)) (H2 : BalancedSz (size m) (size r)) : Valid' o₁ (@node3R α l x m y r) o₂ := hl.node' (hm.node' hr H2) H1 theorem Valid'.node4L_lemma₁ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : b < 3 * a + 1 := by omega theorem Valid'.node4L_lemma₂ {b c d : ℕ} (mr₂ : b + c + 1 ≤ 3 * d) : c ≤ 3 * d := by omega theorem Valid'.node4L_lemma₃ {b c d : ℕ} (mr₁ : 2 * d ≤ b + c + 1) (mm₁ : b ≤ 3 * c) : d ≤ 3 * c := by omega theorem Valid'.node4L_lemma₄ {a b c d : ℕ} (lr₁ : 3 * a ≤ b + c + 1 + d) (mr₂ : b + c + 1 ≤ 3 * d) (mm₁ : b ≤ 3 * c) : a + b + 1 ≤ 3 * (c + d + 1) := by omega theorem Valid'.node4L_lemma₅ {a b c d : ℕ} (lr₂ : 3 * (b + c + 1 + d) ≤ 16 * a + 9) (mr₁ : 2 * d ≤ b + c + 1) (mm₂ : c ≤ 3 * b) : c + d + 1 ≤ 3 * (a + b + 1) := by omega theorem Valid'.node4L {l} {x : α} {m} {y : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hm : Valid' x m y) (hr : Valid' (↑y) r o₂) (Hm : 0 < size m) (H : size l = 0 ∧ size m = 1 ∧ size r ≤ 1 ∨ 0 < size l ∧ ratio * size r ≤ size m ∧ delta * size l ≤ size m + size r ∧ 3 * (size m + size r) ≤ 16 * size l + 9 ∧ size m ≤ delta * size r) : Valid' o₁ (@node4L α l x m y r) o₂ := by obtain - | ⟨s, ml, z, mr⟩ := m; · cases Hm suffices BalancedSz (size l) (size ml) ∧ BalancedSz (size mr) (size r) ∧ BalancedSz (size l + size ml + 1) (size mr + size r + 1) from Valid'.node' (hl.node' hm.left this.1) (hm.right.node' hr this.2.1) this.2.2 rcases H with (⟨l0, m1, r0⟩ | ⟨l0, mr₁, lr₁, lr₂, mr₂⟩) · rw [hm.2.size_eq, Nat.succ_inj, add_eq_zero] at m1 rw [l0, m1.1, m1.2]; revert r0; rcases size r with (_ | _ | _) <;> [decide; decide; (intro r0; unfold BalancedSz delta; omega)] · rcases Nat.eq_zero_or_pos (size r) with r0 | r0 · rw [r0] at mr₂; cases not_le_of_lt Hm mr₂ rw [hm.2.size_eq] at lr₁ lr₂ mr₁ mr₂ by_cases mm : size ml + size mr ≤ 1 · have r1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans mr₁ (Nat.succ_le_succ mm) : _ ≤ ratio * 1)) r0 rw [r1, add_assoc] at lr₁ have l1 := le_antisymm ((mul_le_mul_left (by decide)).1 (le_trans lr₁ (add_le_add_right mm 2) : _ ≤ delta * 1)) l0 rw [l1, r1] revert mm; cases size ml <;> cases size mr <;> intro mm · decide · rw [zero_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩) decide · rcases mm with (_ | ⟨⟨⟩⟩); decide · rw [Nat.succ_add] at mm; rcases mm with (_ | ⟨⟨⟩⟩) rcases hm.3.1.resolve_left mm with ⟨mm₁, mm₂⟩ rcases Nat.eq_zero_or_pos (size ml) with ml0 | ml0 · rw [ml0, mul_zero, Nat.le_zero] at mm₂ rw [ml0, mm₂] at mm; cases mm (by decide) have : 2 * size l ≤ size ml + size mr + 1 := by have := Nat.mul_le_mul_left ratio lr₁ rw [mul_left_comm, mul_add] at this have := le_trans this (add_le_add_left mr₁ _) rw [← Nat.succ_mul] at this exact (mul_le_mul_left (by decide)).1 this refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩ · refine (mul_le_mul_left (by decide)).1 (le_trans this ?_) rw [two_mul, Nat.succ_le_iff] refine add_lt_add_of_lt_of_le ?_ mm₂ simpa using (mul_lt_mul_right ml0).2 (by decide : 1 < 3) · exact Nat.le_of_lt_succ (Valid'.node4L_lemma₁ lr₂ mr₂ mm₁) · exact Valid'.node4L_lemma₂ mr₂ · exact Valid'.node4L_lemma₃ mr₁ mm₁ · exact Valid'.node4L_lemma₄ lr₁ mr₂ mm₁ · exact Valid'.node4L_lemma₅ lr₂ mr₁ mm₂ theorem Valid'.rotateL_lemma₁ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (hb₂ : c ≤ 3 * b) : a ≤ 3 * b := by omega theorem Valid'.rotateL_lemma₂ {a b c : ℕ} (H3 : 2 * (b + c) ≤ 9 * a + 3) (h : b < 2 * c) : b < 3 * a + 1 := by omega theorem Valid'.rotateL_lemma₃ {a b c : ℕ} (H2 : 3 * a ≤ b + c) (h : b < 2 * c) : a + b < 3 * c := by omega theorem Valid'.rotateL_lemma₄ {a b : ℕ} (H3 : 2 * b ≤ 9 * a + 3) : 3 * b ≤ 16 * a + 9 := by omega theorem Valid'.rotateL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H1 : ¬size l + size r ≤ 1) (H2 : delta * size l < size r) (H3 : 2 * size r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@rotateL α l x r) o₂ := by obtain - | ⟨rs, rl, rx, rr⟩ := r; · cases H2 rw [hr.2.size_eq, Nat.lt_succ_iff] at H2 rw [hr.2.size_eq] at H3 replace H3 : 2 * (size rl + size rr) ≤ 9 * size l + 3 ∨ size rl + size rr ≤ 2 := H3.imp (@Nat.le_of_add_le_add_right _ 2 _) Nat.le_of_succ_le_succ have H3_0 : size l = 0 → size rl + size rr ≤ 2 := by intro l0; rw [l0] at H3 exact (or_iff_right_of_imp fun h => (mul_le_mul_left (by decide)).1 (le_trans h (by decide))).1 H3 have H3p : size l > 0 → 2 * (size rl + size rr) ≤ 9 * size l + 3 := fun l0 : 1 ≤ size l => (or_iff_left_of_imp <| by omega).1 H3 have ablem : ∀ {a b : ℕ}, 1 ≤ a → a + b ≤ 2 → b ≤ 1 := by omega have hlp : size l > 0 → ¬size rl + size rr ≤ 1 := fun l0 hb => absurd (le_trans (le_trans (Nat.mul_le_mul_left _ l0) H2) hb) (by decide) rw [Ordnode.rotateL_node]; split_ifs with h · have rr0 : size rr > 0 := (mul_lt_mul_left (by decide)).1 (lt_of_le_of_lt (Nat.zero_le _) h : ratio * 0 < _) suffices BalancedSz (size l) (size rl) ∧ BalancedSz (size l + size rl + 1) (size rr) by exact hl.node3L hr.left hr.right this.1 this.2 rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · rw [l0]; replace H3 := H3_0 l0 have := hr.3.1 rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0 · rw [rl0] at this ⊢ rw [le_antisymm (balancedSz_zero.1 this.symm) rr0] decide have rr1 : size rr = 1 := le_antisymm (ablem rl0 H3) rr0 rw [add_comm] at H3 rw [rr1, show size rl = 1 from le_antisymm (ablem rr0 H3) rl0] decide replace H3 := H3p l0 rcases hr.3.1.resolve_left (hlp l0) with ⟨_, hb₂⟩ refine ⟨Or.inr ⟨?_, ?_⟩, Or.inr ⟨?_, ?_⟩⟩ · exact Valid'.rotateL_lemma₁ H2 hb₂ · exact Nat.le_of_lt_succ (Valid'.rotateL_lemma₂ H3 h) · exact Valid'.rotateL_lemma₃ H2 h · exact le_trans hb₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.le_add_left _ _) (Nat.le_add_right _ _)) · rcases Nat.eq_zero_or_pos (size rl) with rl0 | rl0 · rw [rl0, not_lt, Nat.le_zero, Nat.mul_eq_zero] at h replace h := h.resolve_left (by decide) rw [rl0, h, Nat.le_zero, Nat.mul_eq_zero] at H2 rw [hr.2.size_eq, rl0, h, H2.resolve_left (by decide)] at H1 cases H1 (by decide) refine hl.node4L hr.left hr.right rl0 ?_ rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · replace H3 := H3_0 l0 rcases Nat.eq_zero_or_pos (size rr) with rr0 | rr0 · have := hr.3.1 rw [rr0] at this exact Or.inl ⟨l0, le_antisymm (balancedSz_zero.1 this) rl0, rr0.symm ▸ zero_le_one⟩ exact Or.inl ⟨l0, le_antisymm (ablem rr0 <| by rwa [add_comm]) rl0, ablem rl0 H3⟩ exact Or.inr ⟨l0, not_lt.1 h, H2, Valid'.rotateL_lemma₄ (H3p l0), (hr.3.1.resolve_left (hlp l0)).1⟩ theorem Valid'.rotateR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H1 : ¬size l + size r ≤ 1) (H2 : delta * size r < size l) (H3 : 2 * size l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@rotateR α l x r) o₂ := by refine Valid'.dual_iff.2 ?_ rw [dual_rotateR] refine hr.dual.rotateL hl.dual ?_ ?_ ?_ · rwa [size_dual, size_dual, add_comm] · rwa [size_dual, size_dual] · rwa [size_dual, size_dual] theorem Valid'.balance'_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) (H₂ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balance' α l x r) o₂ := by rw [balance']; split_ifs with h h_1 h_2 · exact hl.node' hr (Or.inl h) · exact hl.rotateL hr h h_1 H₁ · exact hl.rotateR hr h h_2 H₂ · exact hl.node' hr (Or.inr ⟨not_lt.1 h_2, not_lt.1 h_1⟩) theorem Valid'.balance'_lemma {α l l' r r'} (H1 : BalancedSz l' r') (H2 : Nat.dist (@size α l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l') : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3 := by suffices @size α r ≤ 3 * (size l + 1) by omega rcases H2 with (⟨hl, rfl⟩ | ⟨hr, rfl⟩) <;> rcases H1 with (h | ⟨_, h₂⟩) · exact le_trans (Nat.le_add_left _ _) (le_trans h (Nat.le_add_left _ _)) · exact le_trans h₂ (Nat.mul_le_mul_left _ <| le_trans (Nat.dist_tri_right _ _) (Nat.add_le_add_left hl _)) · exact le_trans (Nat.dist_tri_left' _ _) (le_trans (add_le_add hr (le_trans (Nat.le_add_left _ _) h)) (by omega)) · rw [Nat.mul_succ] exact le_trans (Nat.dist_tri_right' _ _) (add_le_add h₂ (le_trans hr (by decide))) theorem Valid'.balance' {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) : Valid' o₁ (@balance' α l x r) o₂ := let ⟨_, _, H1, H2⟩ := H Valid'.balance'_aux hl hr (Valid'.balance'_lemma H1 H2) (Valid'.balance'_lemma H1.symm H2.symm) theorem Valid'.balance {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : ∃ l' r', BalancedSz l' r' ∧ (Nat.dist (size l) l' ≤ 1 ∧ size r = r' ∨ Nat.dist (size r) r' ≤ 1 ∧ size l = l')) : Valid' o₁ (@balance α l x r) o₂ := by rw [balance_eq_balance' hl.3 hr.3 hl.2 hr.2]; exact hl.balance' hr H theorem Valid'.balanceL_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : size l = 0 → size r ≤ 1) (H₂ : 1 ≤ size l → 1 ≤ size r → size r ≤ delta * size l) (H₃ : 2 * @size α l ≤ 9 * size r + 5 ∨ size l ≤ 3) : Valid' o₁ (@balanceL α l x r) o₂ := by rw [balanceL_eq_balance hl.2 hr.2 H₁ H₂, balance_eq_balance' hl.3 hr.3 hl.2 hr.2] refine hl.balance'_aux hr (Or.inl ?_) H₃ rcases Nat.eq_zero_or_pos (size r) with r0 | r0 · rw [r0]; exact Nat.zero_le _ rcases Nat.eq_zero_or_pos (size l) with l0 | l0 · rw [l0]; exact le_trans (Nat.mul_le_mul_left _ (H₁ l0)) (by decide) replace H₂ : _ ≤ 3 * _ := H₂ l0 r0; omega theorem Valid'.balanceL {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : (∃ l', Raised l' (size l) ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised (size r) r' ∧ BalancedSz (size l) r') : Valid' o₁ (@balanceL α l x r) o₂ := by rw [balanceL_eq_balance' hl.3 hr.3 hl.2 hr.2 H] refine hl.balance' hr ?_ rcases H with (⟨l', e, H⟩ | ⟨r', e, H⟩) · exact ⟨_, _, H, Or.inl ⟨e.dist_le', rfl⟩⟩ · exact ⟨_, _, H, Or.inr ⟨e.dist_le, rfl⟩⟩ theorem Valid'.balanceR_aux {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H₁ : size r = 0 → size l ≤ 1) (H₂ : 1 ≤ size r → 1 ≤ size l → size l ≤ delta * size r) (H₃ : 2 * @size α r ≤ 9 * size l + 5 ∨ size r ≤ 3) : Valid' o₁ (@balanceR α l x r) o₂ := by rw [Valid'.dual_iff, dual_balanceR] have := hr.dual.balanceL_aux hl.dual rw [size_dual, size_dual] at this exact this H₁ H₂ H₃ theorem Valid'.balanceR {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) (H : (∃ l', Raised (size l) l' ∧ BalancedSz l' (size r)) ∨ ∃ r', Raised r' (size r) ∧ BalancedSz (size l) r') : Valid' o₁ (@balanceR α l x r) o₂ := by rw [Valid'.dual_iff, dual_balanceR]; exact hr.dual.balanceL hl.dual (balance_sz_dual H) theorem Valid'.eraseMax_aux {s l x r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) : Valid' o₁ (@eraseMax α (.node' l x r)) ↑(findMax' x r) ∧ size (.node' l x r) = size (eraseMax (.node' l x r)) + 1 := by have := H.2.eq_node'; rw [this] at H; clear this induction r generalizing l x o₁ with | nil => exact ⟨H.left, rfl⟩ | node rs rl rx rr _ IHrr => have := H.2.2.2.eq_node'; rw [this] at H ⊢ rcases IHrr H.right with ⟨h, e⟩ refine ⟨Valid'.balanceL H.left h (Or.inr ⟨_, Or.inr e, H.3.1⟩), ?_⟩ rw [eraseMax, size_balanceL H.3.2.1 h.3 H.2.2.1 h.2 (Or.inr ⟨_, Or.inr e, H.3.1⟩)] rw [size_node, e]; rfl theorem Valid'.eraseMin_aux {s l} {x : α} {r o₁ o₂} (H : Valid' o₁ (.node s l x r) o₂) : Valid' ↑(findMin' l x) (@eraseMin α (.node' l x r)) o₂ ∧ size (.node' l x r) = size (eraseMin (.node' l x r)) + 1 := by have := H.dual.eraseMax_aux rwa [← dual_node', size_dual, ← dual_eraseMin, size_dual, ← Valid'.dual_iff, findMax'_dual] at this theorem eraseMin.valid : ∀ {t}, @Valid α _ t → Valid (eraseMin t) | nil, _ => valid_nil | node _ l x r, h => by rw [h.2.eq_node']; exact h.eraseMin_aux.1.valid theorem eraseMax.valid {t} (h : @Valid α _ t) : Valid (eraseMax t) := by rw [Valid.dual_iff, dual_eraseMax]; exact eraseMin.valid h.dual theorem Valid'.glue_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂) (sep : l.All fun x => r.All fun y => x < y) (bal : BalancedSz (size l) (size r)) : Valid' o₁ (@glue α l r) o₂ ∧ size (glue l r) = size l + size r := by obtain - | ⟨ls, ll, lx, lr⟩ := l; · exact ⟨hr, (zero_add _).symm⟩ obtain - | ⟨rs, rl, rx, rr⟩ := r; · exact ⟨hl, rfl⟩ dsimp [glue]; split_ifs · rw [splitMax_eq] · obtain ⟨v, e⟩ := Valid'.eraseMax_aux hl suffices H : _ by refine ⟨Valid'.balanceR v (hr.of_gt ?_ ?_) H, ?_⟩ · refine findMax'_all (P := fun a : α => Bounded nil (a : WithTop α) o₂) lx lr hl.1.2.to_nil (sep.2.2.imp ?_) exact fun x h => hr.1.2.to_nil.mono_left (le_of_lt h.2.1) · exact @findMax'_all _ (fun a => All (· > a) (.node rs rl rx rr)) lx lr sep.2.1 sep.2.2 · rw [size_balanceR v.3 hr.3 v.2 hr.2 H, add_right_comm, ← e, hl.2.1]; rfl refine Or.inl ⟨_, Or.inr e, ?_⟩ rwa [hl.2.eq_node'] at bal · rw [splitMin_eq] · obtain ⟨v, e⟩ := Valid'.eraseMin_aux hr suffices H : _ by refine ⟨Valid'.balanceL (hl.of_lt ?_ ?_) v H, ?_⟩ · refine @findMin'_all (P := fun a : α => Bounded nil o₁ (a : WithBot α)) _ rl rx (sep.2.1.1.imp ?_) hr.1.1.to_nil exact fun y h => hl.1.1.to_nil.mono_right (le_of_lt h) · exact @findMin'_all _ (fun a => All (· < a) (.node ls ll lx lr)) rl rx (all_iff_forall.2 fun x hx => sep.imp fun y hy => all_iff_forall.1 hy.1 _ hx) (sep.imp fun y hy => hy.2.1) · rw [size_balanceL hl.3 v.3 hl.2 v.2 H, add_assoc, ← e, hr.2.1]; rfl refine Or.inr ⟨_, Or.inr e, ?_⟩ rwa [hr.2.eq_node'] at bal theorem Valid'.glue {l} {x : α} {r o₁ o₂} (hl : Valid' o₁ l x) (hr : Valid' x r o₂) : BalancedSz (size l) (size r) → Valid' o₁ (@glue α l r) o₂ ∧ size (@glue α l r) = size l + size r := Valid'.glue_aux (hl.trans_right hr.1) (hr.trans_left hl.1) (hl.1.to_sep hr.1) theorem Valid'.merge_lemma {a b c : ℕ} (h₁ : 3 * a < b + c + 1) (h₂ : b ≤ 3 * c) : 2 * (a + b) ≤ 9 * c + 5 := by omega theorem Valid'.merge_aux₁ {o₁ o₂ ls ll lx lr rs rl rx rr t} (hl : Valid' o₁ (@Ordnode.node α ls ll lx lr) o₂) (hr : Valid' o₁ (.node rs rl rx rr) o₂) (h : delta * ls < rs) (v : Valid' o₁ t rx) (e : size t = ls + size rl) : Valid' o₁ (.balanceL t rx rr) o₂ ∧ size (.balanceL t rx rr) = ls + rs := by rw [hl.2.1] at e rw [hl.2.1, hr.2.1, delta] at h rcases hr.3.1 with (H | ⟨hr₁, hr₂⟩); · omega suffices H₂ : _ by suffices H₁ : _ by refine ⟨Valid'.balanceL_aux v hr.right H₁ H₂ ?_, ?_⟩ · rw [e]; exact Or.inl (Valid'.merge_lemma h hr₁) · rw [balanceL_eq_balance v.2 hr.2.2.2 H₁ H₂, balance_eq_balance' v.3 hr.3.2.2 v.2 hr.2.2.2, size_balance' v.2 hr.2.2.2, e, hl.2.1, hr.2.1] abel · rw [e, add_right_comm]; rintro ⟨⟩ intro _ _; rw [e]; unfold delta at hr₂ ⊢; omega theorem Valid'.merge_aux {l r o₁ o₂} (hl : Valid' o₁ l o₂) (hr : Valid' o₁ r o₂) (sep : l.All fun x => r.All fun y => x < y) : Valid' o₁ (@merge α l r) o₂ ∧ size (merge l r) = size l + size r := by induction l generalizing o₁ o₂ r with | nil => exact ⟨hr, (zero_add _).symm⟩ | node ls ll lx lr _ IHlr => ?_ induction r generalizing o₁ o₂ with | nil => exact ⟨hl, rfl⟩ | node rs rl rx rr IHrl _ => ?_ rw [merge_node]; split_ifs with h h_1 · obtain ⟨v, e⟩ := IHrl (hl.of_lt hr.1.1.to_nil <| sep.imp fun x h => h.2.1) hr.left (sep.imp fun x h => h.1) exact Valid'.merge_aux₁ hl hr h v e · obtain ⟨v, e⟩ := IHlr hl.right (hr.of_gt hl.1.2.to_nil sep.2.1) sep.2.2 have := Valid'.merge_aux₁ hr.dual hl.dual h_1 v.dual rw [size_dual, add_comm, size_dual, ← dual_balanceR, ← Valid'.dual_iff, size_dual, add_comm rs] at this exact this e · refine Valid'.glue_aux hl hr sep (Or.inr ⟨not_lt.1 h_1, not_lt.1 h⟩) theorem Valid.merge {l r} (hl : Valid l) (hr : Valid r) (sep : l.All fun x => r.All fun y => x < y) : Valid (@merge α l r) := (Valid'.merge_aux hl hr sep).1 theorem insertWith.valid_aux [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) : ∀ {t o₁ o₂}, Valid' o₁ t o₂ → Bounded nil o₁ x → Bounded nil x o₂ → Valid' o₁ (insertWith f x t) o₂ ∧ Raised (size t) (size (insertWith f x t)) | nil, _, _, _, bl, br => ⟨valid'_singleton bl br, Or.inr rfl⟩ | node sz l y r, o₁, o₂, h, bl, br => by rw [insertWith, cmpLE] split_ifs with h_1 h_2 <;> dsimp only · rcases h with ⟨⟨lx, xr⟩, hs, hb⟩ rcases hf _ ⟨h_1, h_2⟩ with ⟨xf, fx⟩ refine ⟨⟨⟨lx.mono_right (le_trans h_2 xf), xr.mono_left (le_trans fx h_1)⟩, hs, hb⟩, Or.inl rfl⟩ · rcases insertWith.valid_aux f x hf h.left bl (lt_of_le_not_le h_1 h_2) with ⟨vl, e⟩ suffices H : _ by refine ⟨vl.balanceL h.right H, ?_⟩ rw [size_balanceL vl.3 h.3.2.2 vl.2 h.2.2.2 H, h.2.size_eq] exact (e.add_right _).add_right _ exact Or.inl ⟨_, e, h.3.1⟩ · have : y < x := lt_of_le_not_le ((total_of (· ≤ ·) _ _).resolve_left h_1) h_1 rcases insertWith.valid_aux f x hf h.right this br with ⟨vr, e⟩ suffices H : _ by refine ⟨h.left.balanceR vr H, ?_⟩ rw [size_balanceR h.3.2.1 vr.3 h.2.2.1 vr.2 H, h.2.size_eq] exact (e.add_left _).add_right _ exact Or.inr ⟨_, e, h.3.1⟩ theorem insertWith.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (f : α → α) (x : α) (hf : ∀ y, x ≤ y ∧ y ≤ x → x ≤ f y ∧ f y ≤ x) {t} (h : Valid t) : Valid (insertWith f x t) := (insertWith.valid_aux _ _ hf h ⟨⟩ ⟨⟩).1 theorem insert_eq_insertWith [DecidableLE α] (x : α) : ∀ t, Ordnode.insert x t = insertWith (fun _ => x) x t | nil => rfl | node _ l y r => by unfold Ordnode.insert insertWith; cases cmpLE x y <;> simp [insert_eq_insertWith] theorem insert.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (Ordnode.insert x t) := by rw [insert_eq_insertWith]; exact insertWith.valid _ _ (fun _ _ => ⟨le_rfl, le_rfl⟩) h theorem insert'_eq_insertWith [DecidableLE α] (x : α) : ∀ t, insert' x t = insertWith id x t | nil => rfl | node _ l y r => by unfold insert' insertWith; cases cmpLE x y <;> simp [insert'_eq_insertWith] theorem insert'.valid [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (insert' x t) := by rw [insert'_eq_insertWith]; exact insertWith.valid _ _ (fun _ => id) h theorem Valid'.map_aux {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t a₁ a₂} (h : Valid' a₁ t a₂) : Valid' (Option.map f a₁) (map f t) (Option.map f a₂) ∧ (map f t).size = t.size := by induction t generalizing a₁ a₂ with | nil => simp only [map, size_nil, and_true]; apply valid'_nil cases a₁; · trivial cases a₂; · trivial simp only [Option.map, Bounded] exact f_strict_mono h.ord | node _ _ _ _ t_ih_l t_ih_r => have t_ih_l' := t_ih_l h.left have t_ih_r' := t_ih_r h.right clear t_ih_l t_ih_r obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l' obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r' simp only [map, size_node, and_true] constructor · exact And.intro t_l_valid.ord t_r_valid.ord · constructor · rw [t_l_size, t_r_size]; exact h.sz.1 · constructor · exact t_l_valid.sz · exact t_r_valid.sz · constructor · rw [t_l_size, t_r_size]; exact h.bal.1 · constructor · exact t_l_valid.bal · exact t_r_valid.bal theorem map.valid {β} [Preorder β] {f : α → β} (f_strict_mono : StrictMono f) {t} (h : Valid t) : Valid (map f t) := (Valid'.map_aux f_strict_mono h).1 theorem Valid'.erase_aux [DecidableLE α] (x : α) {t a₁ a₂} (h : Valid' a₁ t a₂) : Valid' a₁ (erase x t) a₂ ∧ Raised (erase x t).size t.size := by induction t generalizing a₁ a₂ with | nil => simpa [erase, Raised] | node _ t_l t_x t_r t_ih_l t_ih_r => simp only [erase, size_node] have t_ih_l' := t_ih_l h.left have t_ih_r' := t_ih_r h.right clear t_ih_l t_ih_r obtain ⟨t_l_valid, t_l_size⟩ := t_ih_l' obtain ⟨t_r_valid, t_r_size⟩ := t_ih_r' cases cmpLE x t_x <;> rw [h.sz.1] · suffices h_balanceable : _ by constructor · exact Valid'.balanceR t_l_valid h.right h_balanceable · rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz h_balanceable] repeat apply Raised.add_right exact t_l_size left; exists t_l.size; exact And.intro t_l_size h.bal.1 · have h_glue := Valid'.glue h.left h.right h.bal.1 obtain ⟨h_glue_valid, h_glue_sized⟩ := h_glue constructor · exact h_glue_valid · right; rw [h_glue_sized] · suffices h_balanceable : _ by constructor · exact Valid'.balanceL h.left t_r_valid h_balanceable · rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz h_balanceable] apply Raised.add_right apply Raised.add_left exact t_r_size right; exists t_r.size; exact And.intro t_r_size h.bal.1 theorem erase.valid [DecidableLE α] (x : α) {t} (h : Valid t) : Valid (erase x t) := (Valid'.erase_aux x h).1 theorem size_erase_of_mem [DecidableLE α] {x : α} {t a₁ a₂} (h : Valid' a₁ t a₂) (h_mem : x ∈ t) : size (erase x t) = size t - 1 := by induction t generalizing a₁ a₂ with | nil => contradiction | node _ t_l t_x t_r t_ih_l t_ih_r => have t_ih_l' := t_ih_l h.left have t_ih_r' := t_ih_r h.right clear t_ih_l t_ih_r
dsimp only [Membership.mem, mem] at h_mem unfold erase revert h_mem; cases cmpLE x t_x <;> intro h_mem <;> dsimp only at h_mem ⊢ · have t_ih_l := t_ih_l' h_mem
Mathlib/Data/Ordmap/Ordset.lean
616
619
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.MeasureTheory.Function.ConditionalExpectation.Unique import Mathlib.MeasureTheory.Function.L2Space /-! # Conditional expectation in L2 This file contains one step of the construction of the conditional expectation, which is completed in `MeasureTheory.Function.ConditionalExpectation.Basic`. See that file for a description of the full process. We build the conditional expectation of an `L²` function, as an element of `L²`. This is the orthogonal projection on the subspace of almost everywhere `m`-measurable functions. ## Main definitions * `condExpL2`: Conditional expectation of a function in L2 with respect to a sigma-algebra: it is the orthogonal projection on the subspace `lpMeas`. ## Implementation notes Most of the results in this file are valid for a complete real normed space `F`. However, some lemmas also use `𝕜 : RCLike`: * `condExpL2` is defined only for an `InnerProductSpace` for now, and we use `𝕜` for its field. * results about scalar multiplication are stated not only for `ℝ` but also for `𝕜` if we happen to have `NormedSpace 𝕜 F`. -/ open TopologicalSpace Filter ContinuousLinearMap open scoped ENNReal Topology MeasureTheory namespace MeasureTheory variable {α E E' F G G' 𝕜 : Type*} [RCLike 𝕜] -- 𝕜 for ℝ or ℂ -- E for an inner product space [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] [CompleteSpace E] -- E' for an inner product space on which we compute integrals [NormedAddCommGroup E'] [InnerProductSpace 𝕜 E'] [CompleteSpace E'] [NormedSpace ℝ E'] -- F for a Lp submodule [NormedAddCommGroup F] [NormedSpace 𝕜 F] -- G for a Lp add_subgroup [NormedAddCommGroup G] -- G' for integrals on a Lp add_subgroup [NormedAddCommGroup G'] [NormedSpace ℝ G'] [CompleteSpace G'] variable {m m0 : MeasurableSpace α} {μ : Measure α} {s t : Set α} local notation "⟪" x ", " y "⟫" => @inner 𝕜 E _ x y local notation "⟪" x ", " y "⟫₂" => @inner 𝕜 (α →₂[μ] E) _ x y variable (E 𝕜) /-- Conditional expectation of a function in L2 with respect to a sigma-algebra -/ noncomputable def condExpL2 (hm : m ≤ m0) : (α →₂[μ] E) →L[𝕜] lpMeas E 𝕜 m 2 μ := haveI : Fact (m ≤ m0) := ⟨hm⟩ (lpMeas E 𝕜 m 2 μ).orthogonalProjection @[deprecated (since := "2025-01-21")] alias condexpL2 := condExpL2 variable {E 𝕜} theorem aestronglyMeasurable_condExpL2 (hm : m ≤ m0) (f : α →₂[μ] E) : AEStronglyMeasurable[m] (condExpL2 E 𝕜 hm f : α → E) μ := lpMeas.aestronglyMeasurable _ @[deprecated (since := "2025-01-24")] alias aeStronglyMeasurable'_condExpL2 := aestronglyMeasurable_condExpL2 @[deprecated (since := "2025-01-24")] alias aeStronglyMeasurable'_condexpL2 := aestronglyMeasurable_condExpL2 theorem integrableOn_condExpL2_of_measure_ne_top (hm : m ≤ m0) (hμs : μ s ≠ ∞) (f : α →₂[μ] E) : IntegrableOn (ε := E) (condExpL2 E 𝕜 hm f) s μ := integrableOn_Lp_of_measure_ne_top (condExpL2 E 𝕜 hm f : α →₂[μ] E) fact_one_le_two_ennreal.elim hμs @[deprecated (since := "2025-01-21")] alias integrableOn_condexpL2_of_measure_ne_top := integrableOn_condExpL2_of_measure_ne_top theorem integrable_condExpL2_of_isFiniteMeasure (hm : m ≤ m0) [IsFiniteMeasure μ] {f : α →₂[μ] E} : Integrable (ε := E) (condExpL2 E 𝕜 hm f) μ := integrableOn_univ.mp <| integrableOn_condExpL2_of_measure_ne_top hm (measure_ne_top _ _) f @[deprecated (since := "2025-01-21")] alias integrable_condexpL2_of_isFiniteMeasure := integrable_condExpL2_of_isFiniteMeasure theorem norm_condExpL2_le_one (hm : m ≤ m0) : ‖@condExpL2 α E 𝕜 _ _ _ _ _ _ μ hm‖ ≤ 1 := haveI : Fact (m ≤ m0) := ⟨hm⟩ Submodule.orthogonalProjection_norm_le _ @[deprecated (since := "2025-01-21")] alias norm_condexpL2_le_one := norm_condExpL2_le_one theorem norm_condExpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖condExpL2 E 𝕜 hm f‖ ≤ ‖f‖ := ((@condExpL2 _ E 𝕜 _ _ _ _ _ _ μ hm).le_opNorm f).trans (mul_le_of_le_one_left (norm_nonneg _) (norm_condExpL2_le_one hm)) @[deprecated (since := "2025-01-21")] alias norm_condexpL2_le := norm_condExpL2_le theorem eLpNorm_condExpL2_le (hm : m ≤ m0) (f : α →₂[μ] E) : eLpNorm (ε := E) (condExpL2 E 𝕜 hm f) 2 μ ≤ eLpNorm f 2 μ := by rw [← ENNReal.toReal_le_toReal (Lp.eLpNorm_ne_top _) (Lp.eLpNorm_ne_top _), ← Lp.norm_def, ← Lp.norm_def, Submodule.norm_coe] exact norm_condExpL2_le hm f @[deprecated (since := "2025-01-21")] alias eLpNorm_condexpL2_le := eLpNorm_condExpL2_le theorem norm_condExpL2_coe_le (hm : m ≤ m0) (f : α →₂[μ] E) : ‖(condExpL2 E 𝕜 hm f : α →₂[μ] E)‖ ≤ ‖f‖ := by rw [Lp.norm_def, Lp.norm_def] exact ENNReal.toReal_mono (Lp.eLpNorm_ne_top _) (eLpNorm_condExpL2_le hm f) @[deprecated (since := "2025-01-21")] alias norm_condexpL2_coe_le := norm_condExpL2_coe_le theorem inner_condExpL2_left_eq_right (hm : m ≤ m0) {f g : α →₂[μ] E} : ⟪(condExpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, (condExpL2 E 𝕜 hm g : α →₂[μ] E)⟫₂ := haveI : Fact (m ≤ m0) := ⟨hm⟩ Submodule.inner_orthogonalProjection_left_eq_right _ f g @[deprecated (since := "2025-01-21")] alias inner_condexpL2_left_eq_right := inner_condExpL2_left_eq_right theorem condExpL2_indicator_of_measurable (hm : m ≤ m0) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (c : E) : (condExpL2 E 𝕜 hm (indicatorConstLp 2 (hm s hs) hμs c) : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := by rw [condExpL2] haveI : Fact (m ≤ m0) := ⟨hm⟩ have h_mem : indicatorConstLp 2 (hm s hs) hμs c ∈ lpMeas E 𝕜 m 2 μ := mem_lpMeas_indicatorConstLp hm hs hμs let ind := (⟨indicatorConstLp 2 (hm s hs) hμs c, h_mem⟩ : lpMeas E 𝕜 m 2 μ) have h_coe_ind : (ind : α →₂[μ] E) = indicatorConstLp 2 (hm s hs) hμs c := rfl have h_orth_mem := Submodule.orthogonalProjection_mem_subspace_eq_self ind rw [← h_coe_ind, h_orth_mem] @[deprecated (since := "2025-01-21")] alias condexpL2_indicator_of_measurable := condExpL2_indicator_of_measurable theorem inner_condExpL2_eq_inner_fun (hm : m ≤ m0) (f g : α →₂[μ] E) (hg : AEStronglyMeasurable[m] g μ) : ⟪(condExpL2 E 𝕜 hm f : α →₂[μ] E), g⟫₂ = ⟪f, g⟫₂ := by symm rw [← sub_eq_zero, ← inner_sub_left, condExpL2] simp only [mem_lpMeas_iff_aestronglyMeasurable.mpr hg, Submodule.orthogonalProjection_inner_eq_zero f g] @[deprecated (since := "2025-01-21")] alias inner_condexpL2_eq_inner_fun := inner_condExpL2_eq_inner_fun section Real variable {hm : m ≤ m0} theorem integral_condExpL2_eq_of_fin_meas_real (f : Lp 𝕜 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condExpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = ∫ x in s, f x ∂μ := by rw [← L2.inner_indicatorConstLp_one (𝕜 := 𝕜) (hm s hs) hμs f] have h_eq_inner : ∫ x in s, (condExpL2 𝕜 𝕜 hm f : α → 𝕜) x ∂μ = inner (indicatorConstLp 2 (hm s hs) hμs (1 : 𝕜)) (condExpL2 𝕜 𝕜 hm f) := by rw [L2.inner_indicatorConstLp_one (hm s hs) hμs] rw [h_eq_inner, ← inner_condExpL2_left_eq_right, condExpL2_indicator_of_measurable hm hs hμs] @[deprecated (since := "2025-01-21")] alias integral_condexpL2_eq_of_fin_meas_real := integral_condExpL2_eq_of_fin_meas_real theorem lintegral_nnnorm_condExpL2_le (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) (f : Lp ℝ 2 μ) : ∫⁻ x in s, ‖(condExpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ ≤ ∫⁻ x in s, ‖f x‖₊ ∂μ := by let h_meas := lpMeas.aestronglyMeasurable (condExpL2 ℝ ℝ hm f) let g := h_meas.choose have hg_meas : StronglyMeasurable[m] g := h_meas.choose_spec.1 have hg_eq : g =ᵐ[μ] condExpL2 ℝ ℝ hm f := h_meas.choose_spec.2.symm have hg_eq_restrict : g =ᵐ[μ.restrict s] condExpL2 ℝ ℝ hm f := ae_restrict_of_ae hg_eq have hg_nnnorm_eq : (fun x => (‖g x‖₊ : ℝ≥0∞)) =ᵐ[μ.restrict s] fun x => (‖(condExpL2 ℝ ℝ hm f : α → ℝ) x‖₊ : ℝ≥0∞) := by refine hg_eq_restrict.mono fun x hx => ?_ dsimp only simp_rw [hx] rw [lintegral_congr_ae hg_nnnorm_eq.symm] refine lintegral_enorm_le_of_forall_fin_meas_integral_eq hm (Lp.stronglyMeasurable f) ?_ ?_ ?_ ?_ hs hμs · exact integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs · exact hg_meas · rw [IntegrableOn, integrable_congr hg_eq_restrict] exact integrableOn_condExpL2_of_measure_ne_top hm hμs f · intro t ht hμt rw [← integral_condExpL2_eq_of_fin_meas_real f ht hμt.ne] exact setIntegral_congr_ae (hm t ht) (hg_eq.mono fun x hx _ => hx) @[deprecated (since := "2025-01-21")] alias lintegral_nnnorm_condexpL2_le := lintegral_nnnorm_condExpL2_le theorem condExpL2_ae_eq_zero_of_ae_eq_zero (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) {f : Lp ℝ 2 μ} (hf : f =ᵐ[μ.restrict s] 0) : condExpL2 ℝ ℝ hm f =ᵐ[μ.restrict s] (0 : α → ℝ) := by suffices h_nnnorm_eq_zero : ∫⁻ x in s, ‖(condExpL2 ℝ ℝ hm f : α → ℝ) x‖₊ ∂μ = 0 by rw [lintegral_eq_zero_iff] at h_nnnorm_eq_zero · refine h_nnnorm_eq_zero.mono fun x hx => ?_ dsimp only at hx rw [Pi.zero_apply] at hx ⊢ · rwa [ENNReal.coe_eq_zero, nnnorm_eq_zero] at hx · refine Measurable.coe_nnreal_ennreal (Measurable.nnnorm ?_) exact (Lp.stronglyMeasurable _).measurable refine le_antisymm ?_ (zero_le _) refine (lintegral_nnnorm_condExpL2_le hs hμs f).trans (le_of_eq ?_) rw [lintegral_eq_zero_iff] · refine hf.mono fun x hx => ?_ dsimp only rw [hx] simp · exact (Lp.stronglyMeasurable _).enorm @[deprecated (since := "2025-01-21")] alias condexpL2_ae_eq_zero_of_ae_eq_zero := condExpL2_ae_eq_zero_of_ae_eq_zero theorem lintegral_nnnorm_condExpL2_indicator_le_real (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ ≤ μ (s ∩ t) := by refine (lintegral_nnnorm_condExpL2_le ht hμt _).trans (le_of_eq ?_) have h_eq : ∫⁻ x in t, ‖(indicatorConstLp 2 hs hμs (1 : ℝ)) x‖₊ ∂μ = ∫⁻ x in t, s.indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ := by refine lintegral_congr_ae (ae_restrict_of_ae ?_) refine (@indicatorConstLp_coeFn _ _ _ 2 _ _ _ hs hμs (1 : ℝ)).mono fun x hx => ?_ dsimp only rw [hx] classical simp_rw [Set.indicator_apply] split_ifs <;> simp rw [h_eq, lintegral_indicator hs, lintegral_const, Measure.restrict_restrict hs] simp only [one_mul, Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply] @[deprecated (since := "2025-01-21")] alias lintegral_nnnorm_condexpL2_indicator_le_real := lintegral_nnnorm_condExpL2_indicator_le_real end Real /-- `condExpL2` commutes with taking inner products with constants. See the lemma `condExpL2_comp_continuousLinearMap` for a more general result about commuting with continuous linear maps. -/ theorem condExpL2_const_inner (hm : m ≤ m0) (f : Lp E 2 μ) (c : E) : condExpL2 𝕜 𝕜 hm (((Lp.memLp f).const_inner c).toLp fun a => ⟪c, f a⟫) =ᵐ[μ] fun a => ⟪c, (condExpL2 E 𝕜 hm f : α → E) a⟫ := by have h_mem_Lp : MemLp (fun a => ⟪c, (condExpL2 E 𝕜 hm f : α → E) a⟫) 2 μ := by refine MemLp.const_inner _ ?_; exact Lp.memLp _ have h_eq : h_mem_Lp.toLp _ =ᵐ[μ] fun a => ⟪c, (condExpL2 E 𝕜 hm f : α → E) a⟫ := h_mem_Lp.coeFn_toLp refine EventuallyEq.trans ?_ h_eq refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜 hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condExpL2_of_measure_ne_top hm hμs.ne _) ?_ ?_ ?_ ?_ · intro s _ hμs rw [IntegrableOn, integrable_congr (ae_restrict_of_ae h_eq)] exact (integrableOn_condExpL2_of_measure_ne_top hm hμs.ne _).const_inner _ · intro s hs hμs rw [integral_condExpL2_eq_of_fin_meas_real _ hs hμs.ne, integral_congr_ae (ae_restrict_of_ae h_eq), ← L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 (↑(condExpL2 E 𝕜 hm f)) (hm s hs) c hμs.ne, ← inner_condExpL2_left_eq_right, condExpL2_indicator_of_measurable _ hs, L2.inner_indicatorConstLp_eq_setIntegral_inner 𝕜 f (hm s hs) c hμs.ne, setIntegral_congr_ae (hm s hs) ((MemLp.coeFn_toLp ((Lp.memLp f).const_inner c)).mono fun x hx _ => hx)] · exact lpMeas.aestronglyMeasurable _ · refine AEStronglyMeasurable.congr ?_ h_eq.symm exact (lpMeas.aestronglyMeasurable _).const_inner @[deprecated (since := "2025-01-21")] alias condexpL2_const_inner := condExpL2_const_inner /-- `condExpL2` verifies the equality of integrals defining the conditional expectation. -/ theorem integral_condExpL2_eq (hm : m ≤ m0) (f : Lp E' 2 μ) (hs : MeasurableSet[m] s) (hμs : μ s ≠ ∞) : ∫ x in s, (condExpL2 E' 𝕜 hm f : α → E') x ∂μ = ∫ x in s, f x ∂μ := by rw [← sub_eq_zero, ← integral_sub' (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs) (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs)] refine integral_eq_zero_of_forall_integral_inner_eq_zero 𝕜 _ ?_ ?_ · rw [integrable_congr (ae_restrict_of_ae (Lp.coeFn_sub (↑(condExpL2 E' 𝕜 hm f)) f).symm)] exact integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs intro c simp_rw [Pi.sub_apply, inner_sub_right] rw [integral_sub ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c) ((integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs).const_inner c)] have h_ae_eq_f := MemLp.coeFn_toLp (E := 𝕜) ((Lp.memLp f).const_inner c) rw [sub_eq_zero, ← setIntegral_congr_ae (hm s hs) ((condExpL2_const_inner hm f c).mono fun x hx _ => hx), ← setIntegral_congr_ae (hm s hs) (h_ae_eq_f.mono fun x hx _ => hx)] exact integral_condExpL2_eq_of_fin_meas_real _ hs hμs @[deprecated (since := "2025-01-21")] alias integral_condexpL2_eq := integral_condExpL2_eq variable {E'' 𝕜' : Type*} [RCLike 𝕜'] [NormedAddCommGroup E''] [InnerProductSpace 𝕜' E''] [CompleteSpace E''] [NormedSpace ℝ E''] variable (𝕜 𝕜') theorem condExpL2_comp_continuousLinearMap (hm : m ≤ m0) (T : E' →L[ℝ] E'') (f : α →₂[μ] E') : (condExpL2 E'' 𝕜' hm (T.compLp f) : α →₂[μ] E'') =ᵐ[μ] T.compLp (condExpL2 E' 𝕜 hm f : α →₂[μ] E') := by refine Lp.ae_eq_of_forall_setIntegral_eq' 𝕜' hm _ _ two_ne_zero ENNReal.coe_ne_top (fun s _ hμs => integrableOn_condExpL2_of_measure_ne_top hm hμs.ne _) (fun s _ hμs => integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne) ?_ ?_ ?_ · intro s hs hμs rw [T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top _ fact_one_le_two_ennreal.elim hμs.ne), integral_condExpL2_eq hm f hs hμs.ne, integral_condExpL2_eq hm (T.compLp f) hs hμs.ne, T.setIntegral_compLp _ (hm s hs), T.integral_comp_comm (integrableOn_Lp_of_measure_ne_top f fact_one_le_two_ennreal.elim hμs.ne)] · exact lpMeas.aestronglyMeasurable _ · have h_coe := T.coeFn_compLp (condExpL2 E' 𝕜 hm f : α →₂[μ] E') rw [← EventuallyEq] at h_coe refine AEStronglyMeasurable.congr ?_ h_coe.symm exact T.continuous.comp_aestronglyMeasurable (lpMeas.aestronglyMeasurable (condExpL2 E' 𝕜 hm f)) @[deprecated (since := "2025-01-21")] alias condexpL2_comp_continuousLinearMap := condExpL2_comp_continuousLinearMap variable {𝕜 𝕜'} section CondexpL2Indicator variable (𝕜) theorem condExpL2_indicator_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : condExpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) =ᵐ[μ] fun a => (condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ)) : α → ℝ) a • x := by rw [indicatorConstLp_eq_toSpanSingleton_compLp hs hμs x] have h_comp := condExpL2_comp_continuousLinearMap ℝ 𝕜 hm (toSpanSingleton ℝ x) (indicatorConstLp 2 hs hμs (1 : ℝ)) refine h_comp.trans ?_ exact (toSpanSingleton ℝ x).coeFn_compLp _ @[deprecated (since := "2025-01-21")] alias condexpL2_indicator_ae_eq_smul := condExpL2_indicator_ae_eq_smul theorem condExpL2_indicator_eq_toSpanSingleton_comp (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : (condExpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α →₂[μ] E') = (toSpanSingleton ℝ x).compLp (condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1)) := by ext1 refine (condExpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).trans ?_ have h_comp := (toSpanSingleton ℝ x).coeFn_compLp (condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α →₂[μ] ℝ) rw [← EventuallyEq] at h_comp refine EventuallyEq.trans ?_ h_comp.symm filter_upwards with y using rfl @[deprecated (since := "2025-01-21")] alias condexpL2_indicator_eq_toSpanSingleton_comp := condExpL2_indicator_eq_toSpanSingleton_comp variable {𝕜} theorem setLIntegral_nnnorm_condExpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : ∫⁻ a in t, ‖(condExpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖(condExpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ = ∫⁻ a in t, ‖(condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := setLIntegral_congr_fun (hm t ht) ((condExpL2_indicator_ae_eq_smul 𝕜 hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const] exact (Lp.stronglyMeasurable _).enorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condExpL2_indicator_le_real hs hμs ht hμt) _ @[deprecated (since := "2025-01-21")] alias setLIntegral_nnnorm_condexpL2_indicator_le := setLIntegral_nnnorm_condExpL2_indicator_le theorem lintegral_nnnorm_condExpL2_indicator_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖(condExpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x) : α → E') a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_trim_le hm (μ s * ‖x‖₊) fun t ht hμt => ?_ refine (setLIntegral_nnnorm_condExpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left @[deprecated (since := "2025-01-21")] alias lintegral_nnnorm_condexpL2_indicator_le := lintegral_nnnorm_condExpL2_indicator_le /-- If the measure `μ.trim hm` is sigma-finite, then the conditional expectation of a measurable set with finite measure is integrable. -/ theorem integrable_condExpL2_indicator (hm : m ≤ m0) [SigmaFinite (μ.trim hm)] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : E') : Integrable (ε := E') (condExpL2 E' 𝕜 hm (indicatorConstLp 2 hs hμs x)) μ := by refine integrable_of_forall_fin_meas_le' hm (μ s * ‖x‖₊) (ENNReal.mul_lt_top hμs.lt_top ENNReal.coe_lt_top) ?_ ?_ · exact Lp.aestronglyMeasurable _ · refine fun t ht hμt => (setLIntegral_nnnorm_condExpL2_indicator_le hm hs hμs x ht hμt).trans ?_ gcongr apply Set.inter_subset_left @[deprecated (since := "2025-01-21")] alias integrable_condexpL2_indicator := integrable_condExpL2_indicator end CondexpL2Indicator section CondexpIndSMul variable [NormedSpace ℝ G] {hm : m ≤ m0} /-- Conditional expectation of the indicator of a measurable set with finite measure, in L2. -/ noncomputable def condExpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : Lp G 2 μ := (toSpanSingleton ℝ x).compLpL 2 μ (condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs (1 : ℝ))) @[deprecated (since := "2025-01-21")] alias condexpIndSMul := condExpIndSMul theorem aestronglyMeasurable_condExpIndSMul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : AEStronglyMeasurable[m] (condExpIndSMul hm hs hμs x) μ := by have h : AEStronglyMeasurable[m] (condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) μ := aestronglyMeasurable_condExpL2 _ _ rw [condExpIndSMul] exact ((toSpanSingleton ℝ x).continuous.comp_aestronglyMeasurable h).congr (coeFn_compLpL _ _).symm @[deprecated (since := "2025-01-24")] alias aeStronglyMeasurable'_condExpIndSMul := aestronglyMeasurable_condExpIndSMul @[deprecated (since := "2025-01-21")] alias aestronglyMeasurable'_condexpIndSMul := aestronglyMeasurable_condExpIndSMul theorem condExpIndSMul_add (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x y : G) : condExpIndSMul hm hs hμs (x + y) = condExpIndSMul hm hs hμs x + condExpIndSMul hm hs hμs y := by simp_rw [condExpIndSMul]; rw [toSpanSingleton_add, add_compLpL, add_apply] @[deprecated (since := "2025-01-21")] alias condexpIndSMul_add := condExpIndSMul_add theorem condExpIndSMul_smul (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : ℝ) (x : G) : condExpIndSMul hm hs hμs (c • x) = c • condExpIndSMul hm hs hμs x := by simp_rw [condExpIndSMul]; rw [toSpanSingleton_smul, smul_compLpL, smul_apply] @[deprecated (since := "2025-01-21")] alias condexpIndSMul_smul := condExpIndSMul_smul theorem condExpIndSMul_smul' [NormedSpace ℝ F] [SMulCommClass ℝ 𝕜 F] (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : 𝕜) (x : F) : condExpIndSMul hm hs hμs (c • x) = c • condExpIndSMul hm hs hμs x := by rw [condExpIndSMul, condExpIndSMul, toSpanSingleton_smul', (toSpanSingleton ℝ x).smul_compLpL c, smul_apply] @[deprecated (since := "2025-01-21")] alias condexpIndSMul_smul' := condExpIndSMul_smul' theorem condExpIndSMul_ae_eq_smul (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) : condExpIndSMul hm hs hμs x =ᵐ[μ] fun a => (condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x := (toSpanSingleton ℝ x).coeFn_compLpL _ @[deprecated (since := "2025-01-21")] alias condexpIndSMul_ae_eq_smul := condExpIndSMul_ae_eq_smul theorem setLIntegral_nnnorm_condExpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) {t : Set α} (ht : MeasurableSet[m] t) (hμt : μ t ≠ ∞) : (∫⁻ a in t, ‖condExpIndSMul hm hs hμs x a‖₊ ∂μ) ≤ μ (s ∩ t) * ‖x‖₊ := calc ∫⁻ a in t, ‖condExpIndSMul hm hs hμs x a‖₊ ∂μ = ∫⁻ a in t, ‖(condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a • x‖₊ ∂μ := setLIntegral_congr_fun (hm t ht) ((condExpIndSMul_ae_eq_smul hm hs hμs x).mono fun a ha _ => by rw [ha]) _ = (∫⁻ a in t, ‖(condExpL2 ℝ ℝ hm (indicatorConstLp 2 hs hμs 1) : α → ℝ) a‖₊ ∂μ) * ‖x‖₊ := by simp_rw [nnnorm_smul, ENNReal.coe_mul] rw [lintegral_mul_const] exact (Lp.stronglyMeasurable _).enorm _ ≤ μ (s ∩ t) * ‖x‖₊ := mul_le_mul_right' (lintegral_nnnorm_condExpL2_indicator_le_real hs hμs ht hμt) _
@[deprecated (since := "2025-01-21")] alias setLIntegral_nnnorm_condexpIndSMul_le := setLIntegral_nnnorm_condExpIndSMul_le theorem lintegral_nnnorm_condExpIndSMul_le (hm : m ≤ m0) (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (x : G) [SigmaFinite (μ.trim hm)] : ∫⁻ a, ‖condExpIndSMul hm hs hμs x a‖₊ ∂μ ≤ μ s * ‖x‖₊ := by refine lintegral_le_of_forall_fin_meas_trim_le hm (μ s * ‖x‖₊) fun t ht hμt => ?_ refine (setLIntegral_nnnorm_condExpIndSMul_le hm hs hμs x ht hμt).trans ?_ gcongr
Mathlib/MeasureTheory/Function/ConditionalExpectation/CondexpL2.lean
477
485
/- Copyright (c) 2022 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.Stopping import Mathlib.Tactic.AdaptationNote /-! # Hitting time Given a stochastic process, the hitting time provides the first time the process "hits" some subset of the state space. The hitting time is a stopping time in the case that the time index is discrete and the process is adapted (this is true in a far more general setting however we have only proved it for the discrete case so far). ## Main definition * `MeasureTheory.hitting`: the hitting time of a stochastic process ## Main results * `MeasureTheory.hitting_isStoppingTime`: a discrete hitting time of an adapted process is a stopping time ## Implementation notes In the definition of the hitting time, we bound the hitting time by an upper and lower bound. This is to ensure that our result is meaningful in the case we are taking the infimum of an empty set or the infimum of a set which is unbounded from below. With this, we can talk about hitting times indexed by the natural numbers or the reals. By taking the bounds to be `⊤` and `⊥`, we obtain the standard definition in the case that the index is `ℕ∞` or `ℝ≥0∞`. -/ open Filter Order TopologicalSpace open scoped MeasureTheory NNReal ENNReal Topology namespace MeasureTheory variable {Ω β ι : Type*} {m : MeasurableSpace Ω} open scoped Classical in /-- Hitting time: given a stochastic process `u` and a set `s`, `hitting u s n m` is the first time `u` is in `s` after time `n` and before time `m` (if `u` does not hit `s` after time `n` and before `m` then the hitting time is simply `m`). The hitting time is a stopping time if the process is adapted and discrete. -/ noncomputable def hitting [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : Ω → ι := fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m open scoped Classical in theorem hitting_def [Preorder ι] [InfSet ι] (u : ι → Ω → β) (s : Set β) (n m : ι) : hitting u s n m = fun x => if ∃ j ∈ Set.Icc n m, u j x ∈ s then sInf (Set.Icc n m ∩ {i : ι | u i x ∈ s}) else m := rfl section Inequalities variable [ConditionallyCompleteLinearOrder ι] {u : ι → Ω → β} {s : Set β} {n i : ι} {ω : Ω} /-- This lemma is strictly weaker than `hitting_of_le`. -/ theorem hitting_of_lt {m : ι} (h : m < n) : hitting u s n m ω = m := by simp_rw [hitting] have h_not : ¬∃ (j : ι) (_ : j ∈ Set.Icc n m), u j ω ∈ s := by push_neg intro j rw [Set.Icc_eq_empty_of_lt h] simp only [Set.mem_empty_iff_false, IsEmpty.forall_iff] simp only [exists_prop] at h_not simp only [h_not, if_false] theorem hitting_le {m : ι} (ω : Ω) : hitting u s n m ω ≤ m := by simp only [hitting] split_ifs with h · obtain ⟨j, hj₁, hj₂⟩ := h change j ∈ {i | u i ω ∈ s} at hj₂ exact (csInf_le (BddBelow.inter_of_left bddBelow_Icc) (Set.mem_inter hj₁ hj₂)).trans hj₁.2 · exact le_rfl theorem not_mem_of_lt_hitting {m k : ι} (hk₁ : k < hitting u s n m ω) (hk₂ : n ≤ k) : u k ω ∉ s := by classical intro h have hexists : ∃ j ∈ Set.Icc n m, u j ω ∈ s := ⟨k, ⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ refine not_le.2 hk₁ ?_ simp_rw [hitting, if_pos hexists] exact csInf_le bddBelow_Icc.inter_of_left ⟨⟨hk₂, le_trans hk₁.le <| hitting_le _⟩, h⟩ theorem hitting_eq_end_iff {m : ι} : hitting u s n m ω = m ↔ (∃ j ∈ Set.Icc n m, u j ω ∈ s) → sInf (Set.Icc n m ∩ {i : ι | u i ω ∈ s}) = m := by classical rw [hitting, ite_eq_right_iff] theorem hitting_of_le {m : ι} (hmn : m ≤ n) : hitting u s n m ω = m := by obtain rfl | h := le_iff_eq_or_lt.1 hmn · classical
rw [hitting, ite_eq_right_iff, forall_exists_index] conv => intro; rw [Set.mem_Icc, Set.Icc_self, and_imp, and_imp] intro i hi₁ hi₂ hi rw [Set.inter_eq_left.2, csInf_singleton] exact Set.singleton_subset_iff.2 (le_antisymm hi₂ hi₁ ▸ hi) · exact hitting_of_lt h theorem le_hitting {m : ι} (hnm : n ≤ m) (ω : Ω) : n ≤ hitting u s n m ω := by
Mathlib/Probability/Process/HittingTime.lean
102
109
/- 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 -/ import Mathlib.Algebra.Order.Ring.Int import Mathlib.Data.Nat.SuccPred /-! # Successors and predecessors of integers In this file, we show that `ℤ` is both an archimedean `SuccOrder` and an archimedean `PredOrder`. -/ open Function Order namespace Int -- so that Lean reads `Int.succ` through `SuccOrder.succ` @[instance] abbrev instSuccOrder : SuccOrder ℤ := { SuccOrder.ofSuccLeIff succ fun {_ _} => Iff.rfl with succ := succ } instance instSuccAddOrder : SuccAddOrder ℤ := ⟨fun _ => rfl⟩ -- so that Lean reads `Int.pred` through `PredOrder.pred` @[instance] abbrev instPredOrder : PredOrder ℤ where pred := pred pred_le _ := (sub_one_lt_of_le le_rfl).le min_of_le_pred ha := ((sub_one_lt_of_le le_rfl).not_le ha).elim le_pred_of_lt {_ _} := le_sub_one_of_lt instance instPredSubOrder : PredSubOrder ℤ := ⟨fun _ => rfl⟩ @[simp] theorem succ_eq_succ : Order.succ = succ := rfl @[simp] theorem pred_eq_pred : Order.pred = pred := rfl instance : IsSuccArchimedean ℤ := ⟨fun {a b} h => ⟨(b - a).toNat, by rw [succ_iterate, toNat_sub_of_le h, ← add_sub_assoc, add_sub_cancel_left]⟩⟩ instance : IsPredArchimedean ℤ := ⟨fun {a b} h => ⟨(b - a).toNat, by rw [pred_iterate, toNat_sub_of_le h, sub_sub_cancel]⟩⟩ /-! ### Covering relation -/ @[simp, norm_cast] theorem natCast_covBy {a b : ℕ} : (a : ℤ) ⋖ b ↔ a ⋖ b := by rw [Order.covBy_iff_add_one_eq, Order.covBy_iff_add_one_eq] exact Int.natCast_inj end Int alias ⟨_, CovBy.intCast⟩ := Int.natCast_covBy
Mathlib/Data/Int/SuccPred.lean
88
90
/- 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, Anne Baanen -/ import Mathlib.Data.Matrix.Basic import Mathlib.Data.Matrix.Block import Mathlib.Data.Matrix.Notation import Mathlib.Data.Matrix.RowCol import Mathlib.GroupTheory.GroupAction.Ring import Mathlib.GroupTheory.Perm.Fin import Mathlib.LinearAlgebra.Alternating.Basic import Mathlib.LinearAlgebra.Matrix.SemiringInverse /-! # Determinant of a matrix This file defines the determinant of a matrix, `Matrix.det`, and its essential properties. ## Main definitions - `Matrix.det`: the determinant of a square matrix, as a sum over permutations - `Matrix.detRowAlternating`: the determinant, as an `AlternatingMap` in the rows of the matrix ## Main results - `det_mul`: the determinant of `A * B` is the product of determinants - `det_zero_of_row_eq`: the determinant is zero if there is a repeated row - `det_block_diagonal`: the determinant of a block diagonal matrix is a product of the blocks' determinants ## Implementation notes It is possible to configure `simp` to compute determinants. See the file `MathlibTest/matrix.lean` for some examples. -/ universe u v w z open Equiv Equiv.Perm Finset Function namespace Matrix variable {m n : Type*} [DecidableEq n] [Fintype n] [DecidableEq m] [Fintype m] variable {R : Type v} [CommRing R] local notation "ε " σ:arg => ((sign σ : ℤ) : R) /-- `det` is an `AlternatingMap` in the rows of the matrix. -/ def detRowAlternating : (n → R) [⋀^n]→ₗ[R] R := MultilinearMap.alternatization ((MultilinearMap.mkPiAlgebra R n R).compLinearMap LinearMap.proj) /-- The determinant of a matrix given by the Leibniz formula. -/ abbrev det (M : Matrix n n R) : R := detRowAlternating M theorem det_apply (M : Matrix n n R) : M.det = ∑ σ : Perm n, Equiv.Perm.sign σ • ∏ i, M (σ i) i := MultilinearMap.alternatization_apply _ M -- This is what the old definition was. We use it to avoid having to change the old proofs below theorem det_apply' (M : Matrix n n R) : M.det = ∑ σ : Perm n, ε σ * ∏ i, M (σ i) i := by simp [det_apply, Units.smul_def] theorem det_eq_detp_sub_detp (M : Matrix n n R) : M.det = M.detp 1 - M.detp (-1) := by rw [det_apply, ← Equiv.sum_comp (Equiv.inv (Perm n)), ← ofSign_disjUnion, sum_disjUnion] simp_rw [inv_apply, sign_inv, sub_eq_add_neg, detp, ← sum_neg_distrib] refine congr_arg₂ (· + ·) (sum_congr rfl fun σ hσ ↦ ?_) (sum_congr rfl fun σ hσ ↦ ?_) <;> rw [mem_ofSign.mp hσ, ← Equiv.prod_comp σ] <;> simp @[simp] theorem det_diagonal {d : n → R} : det (diagonal d) = ∏ i, d i := by rw [det_apply'] refine (Finset.sum_eq_single 1 ?_ ?_).trans ?_ · rintro σ - h2 obtain ⟨x, h3⟩ := not_forall.1 (mt Equiv.ext h2) convert mul_zero (ε σ) apply Finset.prod_eq_zero (mem_univ x) exact if_neg h3 · simp · simp theorem det_zero (_ : Nonempty n) : det (0 : Matrix n n R) = 0 := (detRowAlternating : (n → R) [⋀^n]→ₗ[R] R).map_zero @[simp] theorem det_one : det (1 : Matrix n n R) = 1 := by rw [← diagonal_one]; simp [-diagonal_one] theorem det_isEmpty [IsEmpty n] {A : Matrix n n R} : det A = 1 := by simp [det_apply] @[simp] theorem coe_det_isEmpty [IsEmpty n] : (det : Matrix n n R → R) = Function.const _ 1 := by ext exact det_isEmpty theorem det_eq_one_of_card_eq_zero {A : Matrix n n R} (h : Fintype.card n = 0) : det A = 1 := haveI : IsEmpty n := Fintype.card_eq_zero_iff.mp h det_isEmpty /-- If `n` has only one element, the determinant of an `n` by `n` matrix is just that element. Although `Unique` implies `DecidableEq` and `Fintype`, the instances might not be syntactically equal. Thus, we need to fill in the args explicitly. -/ @[simp] theorem det_unique {n : Type*} [Unique n] [DecidableEq n] [Fintype n] (A : Matrix n n R) : det A = A default default := by simp [det_apply, univ_unique] theorem det_eq_elem_of_subsingleton [Subsingleton n] (A : Matrix n n R) (k : n) : det A = A k k := by have := uniqueOfSubsingleton k convert det_unique A theorem det_eq_elem_of_card_eq_one {A : Matrix n n R} (h : Fintype.card n = 1) (k : n) : det A = A k k := haveI : Subsingleton n := Fintype.card_le_one_iff_subsingleton.mp h.le det_eq_elem_of_subsingleton _ _ theorem det_mul_aux {M N : Matrix n n R} {p : n → n} (H : ¬Bijective p) : (∑ σ : Perm n, ε σ * ∏ x, M (σ x) (p x) * N (p x) x) = 0 := by obtain ⟨i, j, hpij, hij⟩ : ∃ i j, p i = p j ∧ i ≠ j := by rw [← Finite.injective_iff_bijective, Injective] at H push_neg at H exact H exact sum_involution (fun σ _ => σ * Equiv.swap i j) (fun σ _ => by have : (∏ x, M (σ x) (p x)) = ∏ x, M ((σ * Equiv.swap i j) x) (p x) := Fintype.prod_equiv (swap i j) _ _ (by simp [apply_swap_eq_self hpij]) simp [this, sign_swap hij, -sign_swap', prod_mul_distrib]) (fun σ _ _ => (not_congr mul_swap_eq_iff).mpr hij) (fun _ _ => mem_univ _) fun σ _ => mul_swap_involutive i j σ @[simp] theorem det_mul (M N : Matrix n n R) : det (M * N) = det M * det N := calc det (M * N) = ∑ p : n → n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by simp only [det_apply', mul_apply, prod_univ_sum, mul_sum, Fintype.piFinset_univ] rw [Finset.sum_comm] _ = ∑ p : n → n with Bijective p, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (p i) * N (p i) i := by refine (sum_subset (filter_subset _ _) fun f _ hbij ↦ det_mul_aux ?_).symm simpa only [true_and, mem_filter, mem_univ] using hbij _ = ∑ τ : Perm n, ∑ σ : Perm n, ε σ * ∏ i, M (σ i) (τ i) * N (τ i) i := sum_bij (fun p h ↦ Equiv.ofBijective p (mem_filter.1 h).2) (fun _ _ ↦ mem_univ _) (fun _ _ _ _ h ↦ by injection h) (fun b _ ↦ ⟨b, mem_filter.2 ⟨mem_univ _, b.bijective⟩, coe_fn_injective rfl⟩) fun _ _ ↦ rfl _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * ε τ * ∏ j, M (τ j) (σ j) := by simp only [mul_comm, mul_left_comm, prod_mul_distrib, mul_assoc] _ = ∑ σ : Perm n, ∑ τ : Perm n, (∏ i, N (σ i) i) * (ε σ * ε τ) * ∏ i, M (τ i) i := (sum_congr rfl fun σ _ => Fintype.sum_equiv (Equiv.mulRight σ⁻¹) _ _ fun τ => by have : (∏ j, M (τ j) (σ j)) = ∏ j, M ((τ * σ⁻¹) j) j := by rw [← (σ⁻¹ : _ ≃ _).prod_comp] simp only [Equiv.Perm.coe_mul, apply_inv_self, Function.comp_apply] have h : ε σ * ε (τ * σ⁻¹) = ε τ := calc ε σ * ε (τ * σ⁻¹) = ε (τ * σ⁻¹ * σ) := by rw [mul_comm, sign_mul (τ * σ⁻¹)] simp only [Int.cast_mul, Units.val_mul] _ = ε τ := by simp only [inv_mul_cancel_right] simp_rw [Equiv.coe_mulRight, h] simp only [this]) _ = det M * det N := by simp only [det_apply', Finset.mul_sum, mul_comm, mul_left_comm, mul_assoc] /-- The determinant of a matrix, as a monoid homomorphism. -/ def detMonoidHom : Matrix n n R →* R where toFun := det map_one' := det_one map_mul' := det_mul @[simp] theorem coe_detMonoidHom : (detMonoidHom : Matrix n n R → R) = det := rfl /-- On square matrices, `mul_comm` applies under `det`. -/ theorem det_mul_comm (M N : Matrix m m R) : det (M * N) = det (N * M) := by rw [det_mul, det_mul, mul_comm] /-- On square matrices, `mul_left_comm` applies under `det`. -/ theorem det_mul_left_comm (M N P : Matrix m m R) : det (M * (N * P)) = det (N * (M * P)) := by rw [← Matrix.mul_assoc, ← Matrix.mul_assoc, det_mul, det_mul_comm M N, ← det_mul] /-- On square matrices, `mul_right_comm` applies under `det`. -/ theorem det_mul_right_comm (M N P : Matrix m m R) : det (M * N * P) = det (M * P * N) := by rw [Matrix.mul_assoc, Matrix.mul_assoc, det_mul, det_mul_comm N P, ← det_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M.val * N * M⁻¹.val) = det N := by rw [det_mul_right_comm, Units.mul_inv, one_mul] -- TODO(https://github.com/leanprover-community/mathlib4/issues/6607): fix elaboration so `val` isn't needed theorem det_units_conj' (M : (Matrix m m R)ˣ) (N : Matrix m m R) : det (M⁻¹.val * N * ↑M.val) = det N := det_units_conj M⁻¹ N /-- Transposing a matrix preserves the determinant. -/ @[simp] theorem det_transpose (M : Matrix n n R) : Mᵀ.det = M.det := by rw [det_apply', det_apply'] refine Fintype.sum_bijective _ inv_involutive.bijective _ _ ?_ intro σ
rw [sign_inv] congr 1
Mathlib/LinearAlgebra/Matrix/Determinant/Basic.lean
204
205
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.FreeAlgebra import Mathlib.RingTheory.Adjoin.Polynomial import Mathlib.RingTheory.Adjoin.Tower import Mathlib.RingTheory.Ideal.Quotient.Operations import Mathlib.RingTheory.Noetherian.Orzech /-! # Finiteness conditions in commutative algebra In this file we define a notion of finiteness that is common in commutative algebra. ## Main declarations - `Algebra.FiniteType`, `RingHom.FiniteType`, `AlgHom.FiniteType` all of these express that some object is finitely generated *as algebra* over some base ring. -/ open Function (Surjective) open Polynomial section ModuleAndAlgebra universe uR uS uA uB uM uN variable (R : Type uR) (S : Type uS) (A : Type uA) (B : Type uB) (M : Type uM) (N : Type uN) /-- An algebra over a commutative semiring is of `FiniteType` if it is finitely generated over the base ring as algebra. -/ class Algebra.FiniteType [CommSemiring R] [Semiring A] [Algebra R A] : Prop where out : (⊤ : Subalgebra R A).FG namespace Module variable [Semiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid N] [Module R N] namespace Finite open Submodule Set variable {R S M N} section Algebra -- see Note [lower instance priority] instance (priority := 100) finiteType {R : Type*} (A : Type*) [CommSemiring R] [Semiring A] [Algebra R A] [hRA : Module.Finite R A] : Algebra.FiniteType R A := ⟨Subalgebra.fg_of_submodule_fg hRA.1⟩ end Algebra end Finite end Module namespace Algebra variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra R B] variable [AddCommMonoid M] [Module R M] variable [AddCommMonoid N] [Module R N] namespace FiniteType theorem self : FiniteType R R := ⟨⟨{1}, Subsingleton.elim _ _⟩⟩ protected theorem polynomial : FiniteType R R[X] := ⟨⟨{Polynomial.X}, by rw [Finset.coe_singleton] exact Polynomial.adjoin_X⟩⟩ protected theorem freeAlgebra (ι : Type*) [Finite ι] : FiniteType R (FreeAlgebra R ι) := by cases nonempty_fintype ι classical exact ⟨⟨Finset.univ.image (FreeAlgebra.ι R), by rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact FreeAlgebra.adjoin_range_ι R ι⟩⟩ protected theorem mvPolynomial (ι : Type*) [Finite ι] : FiniteType R (MvPolynomial ι R) := by cases nonempty_fintype ι classical exact ⟨⟨Finset.univ.image MvPolynomial.X, by rw [Finset.coe_image, Finset.coe_univ, Set.image_univ] exact MvPolynomial.adjoin_range_X⟩⟩ theorem of_restrictScalars_finiteType [Algebra S A] [IsScalarTower R S A] [hA : FiniteType R A] : FiniteType S A := by obtain ⟨s, hS⟩ := hA.out refine ⟨⟨s, eq_top_iff.2 fun b => ?_⟩⟩ have le : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S s) := by apply (Algebra.adjoin_le _ : adjoin R (s : Set A) ≤ Subalgebra.restrictScalars R (adjoin S ↑s)) simp only [Subalgebra.coe_restrictScalars] exact Algebra.subset_adjoin exact le (eq_top_iff.1 hS b) variable {R S A B} theorem of_surjective (hRA : FiniteType R A) (f : A →ₐ[R] B) (hf : Surjective f) : FiniteType R B := ⟨by convert hRA.1.map f simpa only [map_top f, @eq_comm _ ⊤, eq_top_iff, AlgHom.mem_range] using hf⟩ theorem equiv (hRA : FiniteType R A) (e : A ≃ₐ[R] B) : FiniteType R B := hRA.of_surjective e e.surjective theorem trans [Algebra S A] [IsScalarTower R S A] (hRS : FiniteType R S) (hSA : FiniteType S A) : FiniteType R A := ⟨fg_trans' hRS.1 hSA.1⟩ instance quotient (R : Type*) {S : Type*} [CommSemiring R] [CommRing S] [Algebra R S] (I : Ideal S) [h : Algebra.FiniteType R S] : Algebra.FiniteType R (S ⧸ I) := Algebra.FiniteType.trans h inferInstance /-- An algebra is finitely generated if and only if it is a quotient of a free algebra whose variables are indexed by a finset. -/ theorem iff_quotient_freeAlgebra : FiniteType R A ↔ ∃ (s : Finset A) (f : FreeAlgebra R s →ₐ[R] A), Surjective f := by constructor · rintro ⟨s, hs⟩ refine ⟨s, FreeAlgebra.lift _ (↑), ?_⟩ rw [← Set.range_eq_univ, ← AlgHom.coe_range, ← adjoin_range_eq_range_freeAlgebra_lift, Subtype.range_coe_subtype, Finset.setOf_mem, hs, coe_top] · rintro ⟨s, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.freeAlgebra R s) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a finset. -/ theorem iff_quotient_mvPolynomial : FiniteType R S ↔ ∃ (s : Finset S) (f : MvPolynomial { x // x ∈ s } R →ₐ[R] S), Surjective f := by constructor · rintro ⟨s, hs⟩ use s, MvPolynomial.aeval (↑) intro x have hrw : (↑s : Set S) = fun x : S => x ∈ s.val := rfl rw [← Set.mem_range, ← AlgHom.coe_range, ← adjoin_eq_range] simp_rw [← hrw, hs] exact Set.mem_univ x · rintro ⟨s, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.mvPolynomial R { x // x ∈ s }) f hsur /-- An algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_freeAlgebra' : FiniteType R A ↔ ∃ (ι : Type uA) (_ : Fintype ι) (f : FreeAlgebra R ι →ₐ[R] A), Surjective f := by constructor · rw [iff_quotient_freeAlgebra] rintro ⟨s, ⟨f, hsur⟩⟩ use { x : A // x ∈ s }, inferInstance, f · rintro ⟨ι, ⟨hfintype, ⟨f, hsur⟩⟩⟩ letI : Fintype ι := hfintype exact FiniteType.of_surjective (FiniteType.freeAlgebra R ι) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring whose variables are indexed by a fintype. -/ theorem iff_quotient_mvPolynomial' : FiniteType R S ↔ ∃ (ι : Type uS) (_ : Fintype ι) (f : MvPolynomial ι R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial] rintro ⟨s, ⟨f, hsur⟩⟩ use { x : S // x ∈ s }, inferInstance, f · rintro ⟨ι, ⟨hfintype, ⟨f, hsur⟩⟩⟩ letI : Fintype ι := hfintype exact FiniteType.of_surjective (FiniteType.mvPolynomial R ι) f hsur /-- A commutative algebra is finitely generated if and only if it is a quotient of a polynomial ring in `n` variables. -/ theorem iff_quotient_mvPolynomial'' : FiniteType R S ↔ ∃ (n : ℕ) (f : MvPolynomial (Fin n) R →ₐ[R] S), Surjective f := by constructor · rw [iff_quotient_mvPolynomial'] rintro ⟨ι, hfintype, ⟨f, hsur⟩⟩ have equiv := MvPolynomial.renameEquiv R (Fintype.equivFin ι) exact ⟨Fintype.card ι, AlgHom.comp f equiv.symm.toAlgHom, by simpa using hsur⟩ · rintro ⟨n, ⟨f, hsur⟩⟩ exact FiniteType.of_surjective (FiniteType.mvPolynomial R (Fin n)) f hsur instance prod [hA : FiniteType R A] [hB : FiniteType R B] : FiniteType R (A × B) := ⟨by rw [← Subalgebra.prod_top]; exact hA.1.prod hB.1⟩ theorem isNoetherianRing (R S : Type*) [CommRing R] [CommRing S] [Algebra R S] [h : Algebra.FiniteType R S] [IsNoetherianRing R] : IsNoetherianRing S := by obtain ⟨s, hs⟩ := h.1 apply isNoetherianRing_of_surjective (MvPolynomial s R) S (MvPolynomial.aeval (↑) : MvPolynomial s R →ₐ[R] S).toRingHom rw [← Set.range_eq_univ, AlgHom.toRingHom_eq_coe, RingHom.coe_coe, ← AlgHom.coe_range, ← Algebra.adjoin_range_eq_range_aeval, Subtype.range_coe_subtype, Finset.setOf_mem, hs] rfl theorem _root_.Subalgebra.fg_iff_finiteType (S : Subalgebra R A) : S.FG ↔ Algebra.FiniteType R S := S.fg_top.symm.trans ⟨fun h => ⟨h⟩, fun h => h.out⟩ end FiniteType end Algebra end ModuleAndAlgebra namespace RingHom variable {A B C : Type*} [CommRing A] [CommRing B] [CommRing C] /-- A ring morphism `A →+* B` is of `FiniteType` if `B` is finitely generated as `A`-algebra. -/ @[algebraize] def FiniteType (f : A →+* B) : Prop := @Algebra.FiniteType A B _ _ f.toAlgebra namespace Finite theorem finiteType {f : A →+* B} (hf : f.Finite) : FiniteType f := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf end Finite namespace FiniteType variable (A) in theorem id : FiniteType (RingHom.id A) := Algebra.FiniteType.self A theorem comp_surjective {f : A →+* B} {g : B →+* C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := by algebraize_only [f, g.comp f] exact Algebra.FiniteType.of_surjective hf { g with toFun := g commutes' := fun a => rfl } hg theorem of_surjective (f : A →+* B) (hf : Surjective f) : f.FiniteType := by rw [← f.comp_id] exact (id A).comp_surjective hf theorem comp {g : B →+* C} {f : A →+* B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := by algebraize_only [f, g, g.comp f] exact Algebra.FiniteType.trans hf hg theorem of_finite {f : A →+* B} (hf : f.Finite) : f.FiniteType := @Module.Finite.finiteType _ _ _ _ f.toAlgebra hf alias _root_.RingHom.Finite.to_finiteType := of_finite theorem of_comp_finiteType {f : A →+* B} {g : B →+* C} (h : (g.comp f).FiniteType) : g.FiniteType := by algebraize [f, g, g.comp f] exact Algebra.FiniteType.of_restrictScalars_finiteType A B C end FiniteType end RingHom namespace AlgHom variable {R A B C : Type*} [CommRing R] variable [CommRing A] [CommRing B] [CommRing C] variable [Algebra R A] [Algebra R B] [Algebra R C] /-- An algebra morphism `A →ₐ[R] B` is of `FiniteType` if it is of finite type as ring morphism. In other words, if `B` is finitely generated as `A`-algebra. -/ def FiniteType (f : A →ₐ[R] B) : Prop := f.toRingHom.FiniteType namespace Finite theorem finiteType {f : A →ₐ[R] B} (hf : f.Finite) : FiniteType f := RingHom.Finite.finiteType hf end Finite namespace FiniteType variable (R A) theorem id : FiniteType (AlgHom.id R A) := RingHom.FiniteType.id A variable {R A} theorem comp {g : B →ₐ[R] C} {f : A →ₐ[R] B} (hg : g.FiniteType) (hf : f.FiniteType) : (g.comp f).FiniteType := RingHom.FiniteType.comp hg hf theorem comp_surjective {f : A →ₐ[R] B} {g : B →ₐ[R] C} (hf : f.FiniteType) (hg : Surjective g) : (g.comp f).FiniteType := RingHom.FiniteType.comp_surjective hf hg theorem of_surjective (f : A →ₐ[R] B) (hf : Surjective f) : f.FiniteType := RingHom.FiniteType.of_surjective f.toRingHom hf theorem of_comp_finiteType {f : A →ₐ[R] B} {g : B →ₐ[R] C} (h : (g.comp f).FiniteType) : g.FiniteType := RingHom.FiniteType.of_comp_finiteType h end FiniteType end AlgHom theorem algebraMap_finiteType_iff_algebra_finiteType {R A : Type*} [CommRing R] [CommRing A] [Algebra R A] : (algebraMap R A).FiniteType ↔ Algebra.FiniteType R A := by dsimp [RingHom.FiniteType] constructor <;> (intro h; convert h; apply Algebra.algebra_ext; exact congrFun rfl) section MonoidAlgebra variable {R : Type*} {M : Type*} namespace AddMonoidAlgebra open Algebra AddSubmonoid Submodule section Span section Semiring variable [CommSemiring R] [AddMonoid M] /-- An element of `R[M]` is in the subalgebra generated by its support. -/ theorem mem_adjoin_support (f : R[M]) : f ∈ adjoin R (of' R M '' f.support) := by suffices span R (of' R M '' f.support) ≤ Subalgebra.toSubmodule (adjoin R (of' R M '' f.support)) by exact this (mem_span_support f) rw [Submodule.span_le] exact subset_adjoin /-- If a set `S` generates, as algebra, `R[M]`, then the set of supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (⋃ f ∈ S, of' R M '' (f.support : Set M)) = ⊤ := by refine le_antisymm le_top ?_ rw [← hS, adjoin_le_iff] intro f hf have hincl : of' R M '' f.support ⊆ ⋃ (g : R[M]) (_ : g ∈ S), of' R M '' g.support := by intro s hs exact Set.mem_iUnion₂.2 ⟨f, ⟨hf, hs⟩⟩ exact adjoin_mono hincl (mem_adjoin_support f) /-- If a set `S` generates, as algebra, `R[M]`, then the image of the union of the supports of elements of `S` generates `R[M]`. -/ theorem support_gen_of_gen' {S : Set R[M]} (hS : Algebra.adjoin R S = ⊤) : Algebra.adjoin R (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⊤ := by suffices (of' R M '' ⋃ f ∈ S, (f.support : Set M)) = ⋃ f ∈ S, of' R M '' (f.support : Set M) by rw [this] exact support_gen_of_gen hS simp only [Set.image_iUnion] end Semiring section Ring variable [CommRing R] [AddMonoid M] /-- If `R[M]` is of finite type, then there is a `G : Finset M` such that its image generates, as algebra, `R[M]`. -/ theorem exists_finset_adjoin_eq_top [h : FiniteType R R[M]] : ∃ G : Finset M, Algebra.adjoin R (of' R M '' G) = ⊤ := by
obtain ⟨S, hS⟩ := h letI : DecidableEq M := Classical.decEq M use Finset.biUnion S fun f => f.support have : (Finset.biUnion S fun f => f.support : Set M) = ⋃ f ∈ S, (f.support : Set M) := by simp only [Finset.set_biUnion_coe, Finset.coe_biUnion] rw [this]
Mathlib/RingTheory/FiniteType.lean
369
374
/- 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.Complex.Log /-! # Power function on `ℂ` We construct the power functions `x ^ y`, where `x` and `y` are complex numbers. -/ open Real Topology Filter ComplexConjugate Finset Set namespace Complex /-- The complex power function `x ^ y`, given by `x ^ y = exp(y log x)` (where `log` is the principal determination of the logarithm), unless `x = 0` where one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/ noncomputable def cpow (x y : ℂ) : ℂ := if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) noncomputable instance : Pow ℂ ℂ := ⟨cpow⟩ @[simp] theorem cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y := rfl theorem cpow_def (x y : ℂ) : x ^ y = if x = 0 then if y = 0 then 1 else 0 else exp (log x * y) := rfl theorem cpow_def_of_ne_zero {x : ℂ} (hx : x ≠ 0) (y : ℂ) : x ^ y = exp (log x * y) := if_neg hx @[simp] theorem cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def] @[simp] theorem cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 := by simp only [cpow_def] split_ifs <;> simp [*, exp_ne_zero] theorem cpow_ne_zero_iff {x y : ℂ} : x ^ y ≠ 0 ↔ x ≠ 0 ∨ y = 0 := by rw [ne_eq, cpow_eq_zero_iff, not_and_or, ne_eq, not_not] theorem cpow_ne_zero_iff_of_exponent_ne_zero {x y : ℂ} (hy : y ≠ 0) : x ^ y ≠ 0 ↔ x ≠ 0 := by simp [hy] @[simp] theorem zero_cpow {x : ℂ} (h : x ≠ 0) : (0 : ℂ) ^ x = 0 := by simp [cpow_def, *] theorem zero_cpow_eq_iff {x : ℂ} {a : ℂ} : (0 : ℂ) ^ x = a ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by constructor · intro hyp simp only [cpow_def, eq_self_iff_true, if_true] at hyp by_cases h : x = 0 · subst h simp only [if_true, eq_self_iff_true] at hyp right exact ⟨rfl, hyp.symm⟩ · rw [if_neg h] at hyp left exact ⟨h, hyp.symm⟩ · rintro (⟨h, rfl⟩ | ⟨rfl, rfl⟩) · exact zero_cpow h · exact cpow_zero _ theorem eq_zero_cpow_iff {x : ℂ} {a : ℂ} : a = (0 : ℂ) ^ x ↔ x ≠ 0 ∧ a = 0 ∨ x = 0 ∧ a = 1 := by rw [← zero_cpow_eq_iff, eq_comm] @[simp] theorem cpow_one (x : ℂ) : x ^ (1 : ℂ) = x := if hx : x = 0 then by simp [hx, cpow_def] else by rw [cpow_def, if_neg (one_ne_zero : (1 : ℂ) ≠ 0), if_neg hx, mul_one, exp_log hx] @[simp] theorem one_cpow (x : ℂ) : (1 : ℂ) ^ x = 1 := by rw [cpow_def] split_ifs <;> simp_all [one_ne_zero] theorem cpow_add {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y + z) = x ^ y * x ^ z := by simp only [cpow_def, ite_mul, boole_mul, mul_ite, mul_boole] simp_all [exp_add, mul_add] theorem cpow_mul {x y : ℂ} (z : ℂ) (h₁ : -π < (log x * y).im) (h₂ : (log x * y).im ≤ π) : x ^ (y * z) = (x ^ y) ^ z := by simp only [cpow_def] split_ifs <;> simp_all [exp_ne_zero, log_exp h₁ h₂, mul_assoc] theorem cpow_neg (x y : ℂ) : x ^ (-y) = (x ^ y)⁻¹ := by simp only [cpow_def, neg_eq_zero, mul_neg] split_ifs <;> simp [exp_neg] theorem cpow_sub {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y - z) = x ^ y / x ^ z := by rw [sub_eq_add_neg, cpow_add _ _ hx, cpow_neg, div_eq_mul_inv] theorem cpow_neg_one (x : ℂ) : x ^ (-1 : ℂ) = x⁻¹ := by simpa using cpow_neg x 1 /-- See also `Complex.cpow_int_mul'`. -/ lemma cpow_int_mul (x : ℂ) (n : ℤ) (y : ℂ) : x ^ (n * y) = (x ^ y) ^ n := by rcases eq_or_ne x 0 with rfl | hx · rcases eq_or_ne n 0 with rfl | hn · simp · rcases eq_or_ne y 0 with rfl | hy <;> simp [*, zero_zpow] · rw [cpow_def_of_ne_zero hx, cpow_def_of_ne_zero hx, mul_left_comm, exp_int_mul] lemma cpow_mul_int (x y : ℂ) (n : ℤ) : x ^ (y * n) = (x ^ y) ^ n := by rw [mul_comm, cpow_int_mul] lemma cpow_nat_mul (x : ℂ) (n : ℕ) (y : ℂ) : x ^ (n * y) = (x ^ y) ^ n := mod_cast cpow_int_mul x n y lemma cpow_ofNat_mul (x : ℂ) (n : ℕ) [n.AtLeastTwo] (y : ℂ) : x ^ (ofNat(n) * y) = (x ^ y) ^ ofNat(n) := cpow_nat_mul x n y lemma cpow_mul_nat (x y : ℂ) (n : ℕ) : x ^ (y * n) = (x ^ y) ^ n := by rw [mul_comm, cpow_nat_mul] lemma cpow_mul_ofNat (x y : ℂ) (n : ℕ) [n.AtLeastTwo] : x ^ (y * ofNat(n)) = (x ^ y) ^ ofNat(n) := cpow_mul_nat x y n @[simp, norm_cast] theorem cpow_natCast (x : ℂ) (n : ℕ) : x ^ (n : ℂ) = x ^ n := by simpa using cpow_nat_mul x n 1 @[simp] lemma cpow_ofNat (x : ℂ) (n : ℕ) [n.AtLeastTwo] : x ^ (ofNat(n) : ℂ) = x ^ ofNat(n) := cpow_natCast x n theorem cpow_two (x : ℂ) : x ^ (2 : ℂ) = x ^ (2 : ℕ) := cpow_ofNat x 2 @[simp, norm_cast] theorem cpow_intCast (x : ℂ) (n : ℤ) : x ^ (n : ℂ) = x ^ n := by simpa using cpow_int_mul x n 1 @[simp] theorem cpow_nat_inv_pow (x : ℂ) {n : ℕ} (hn : n ≠ 0) : (x ^ (n⁻¹ : ℂ)) ^ n = x := by rw [← cpow_nat_mul, mul_inv_cancel₀, cpow_one] assumption_mod_cast @[simp] lemma cpow_ofNat_inv_pow (x : ℂ) (n : ℕ) [n.AtLeastTwo] : (x ^ ((ofNat(n) : ℂ)⁻¹)) ^ (ofNat(n) : ℕ) = x := cpow_nat_inv_pow _ (NeZero.ne n) /-- A version of `Complex.cpow_int_mul` with RHS that matches `Complex.cpow_mul`. The assumptions on the arguments are needed because the equality fails, e.g., for `x = -I`, `n = 2`, `y = 1/2`. -/ lemma cpow_int_mul' {x : ℂ} {n : ℤ} (hlt : -π < n * x.arg) (hle : n * x.arg ≤ π) (y : ℂ) : x ^ (n * y) = (x ^ n) ^ y := by rw [mul_comm] at hlt hle rw [cpow_mul, cpow_intCast] <;> simpa [log_im] /-- A version of `Complex.cpow_nat_mul` with RHS that matches `Complex.cpow_mul`. The assumptions on the arguments are needed because the equality fails, e.g., for `x = -I`, `n = 2`, `y = 1/2`. -/ lemma cpow_nat_mul' {x : ℂ} {n : ℕ} (hlt : -π < n * x.arg) (hle : n * x.arg ≤ π) (y : ℂ) : x ^ (n * y) = (x ^ n) ^ y := cpow_int_mul' hlt hle y lemma cpow_ofNat_mul' {x : ℂ} {n : ℕ} [n.AtLeastTwo] (hlt : -π < OfNat.ofNat n * x.arg) (hle : OfNat.ofNat n * x.arg ≤ π) (y : ℂ) : x ^ (OfNat.ofNat n * y) = (x ^ ofNat(n)) ^ y := cpow_nat_mul' hlt hle y lemma pow_cpow_nat_inv {x : ℂ} {n : ℕ} (h₀ : n ≠ 0) (hlt : -(π / n) < x.arg) (hle : x.arg ≤ π / n) : (x ^ n) ^ (n⁻¹ : ℂ) = x := by rw [← cpow_nat_mul', mul_inv_cancel₀ (Nat.cast_ne_zero.2 h₀), cpow_one] · rwa [← div_lt_iff₀' (Nat.cast_pos.2 h₀.bot_lt), neg_div] · rwa [← le_div_iff₀' (Nat.cast_pos.2 h₀.bot_lt)] lemma pow_cpow_ofNat_inv {x : ℂ} {n : ℕ} [n.AtLeastTwo] (hlt : -(π / OfNat.ofNat n) < x.arg) (hle : x.arg ≤ π / OfNat.ofNat n) : (x ^ ofNat(n)) ^ ((OfNat.ofNat n : ℂ)⁻¹) = x := pow_cpow_nat_inv (NeZero.ne n) hlt hle /-- See also `Complex.pow_cpow_ofNat_inv` for a version that also works for `x * I`, `0 ≤ x`. -/ lemma sq_cpow_two_inv {x : ℂ} (hx : 0 < x.re) : (x ^ (2 : ℕ)) ^ (2⁻¹ : ℂ) = x := pow_cpow_ofNat_inv (neg_pi_div_two_lt_arg_iff.2 <| .inl hx) (arg_le_pi_div_two_iff.2 <| .inl hx.le) theorem mul_cpow_ofReal_nonneg {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (r : ℂ) : ((a : ℂ) * (b : ℂ)) ^ r = (a : ℂ) ^ r * (b : ℂ) ^ r := by rcases eq_or_ne r 0 with (rfl | hr) · simp only [cpow_zero, mul_one] rcases eq_or_lt_of_le ha with (rfl | ha') · rw [ofReal_zero, zero_mul, zero_cpow hr, zero_mul] rcases eq_or_lt_of_le hb with (rfl | hb') · rw [ofReal_zero, mul_zero, zero_cpow hr, mul_zero] have ha'' : (a : ℂ) ≠ 0 := ofReal_ne_zero.mpr ha'.ne' have hb'' : (b : ℂ) ≠ 0 := ofReal_ne_zero.mpr hb'.ne' rw [cpow_def_of_ne_zero (mul_ne_zero ha'' hb''), log_ofReal_mul ha' hb'', ofReal_log ha, add_mul, exp_add, ← cpow_def_of_ne_zero ha'', ← cpow_def_of_ne_zero hb''] lemma natCast_mul_natCast_cpow (m n : ℕ) (s : ℂ) : (m * n : ℂ) ^ s = m ^ s * n ^ s := ofReal_natCast m ▸ ofReal_natCast n ▸ mul_cpow_ofReal_nonneg m.cast_nonneg n.cast_nonneg s lemma natCast_cpow_natCast_mul (n m : ℕ) (z : ℂ) : (n : ℂ) ^ (m * z) = ((n : ℂ) ^ m) ^ z := by refine cpow_nat_mul' (x := n) (n := m) ?_ ?_ z · simp only [natCast_arg, mul_zero, Left.neg_neg_iff, pi_pos] · simp only [natCast_arg, mul_zero, pi_pos.le] theorem inv_cpow_eq_ite (x : ℂ) (n : ℂ) : x⁻¹ ^ n = if x.arg = π then conj (x ^ conj n)⁻¹ else (x ^ n)⁻¹ := by simp_rw [Complex.cpow_def, log_inv_eq_ite, inv_eq_zero, map_eq_zero, ite_mul, neg_mul, RCLike.conj_inv, apply_ite conj, apply_ite exp, apply_ite Inv.inv, map_zero, map_one, exp_neg, inv_one, inv_zero, ← exp_conj, map_mul, conj_conj] split_ifs with hx hn ha ha <;> rfl theorem inv_cpow (x : ℂ) (n : ℂ) (hx : x.arg ≠ π) : x⁻¹ ^ n = (x ^ n)⁻¹ := by rw [inv_cpow_eq_ite, if_neg hx] /-- `Complex.inv_cpow_eq_ite` with the `ite` on the other side. -/ theorem inv_cpow_eq_ite' (x : ℂ) (n : ℂ) : (x ^ n)⁻¹ = if x.arg = π then conj (x⁻¹ ^ conj n) else x⁻¹ ^ n := by rw [inv_cpow_eq_ite, apply_ite conj, conj_conj, conj_conj] split_ifs with h · rfl · rw [inv_cpow _ _ h] theorem conj_cpow_eq_ite (x : ℂ) (n : ℂ) : conj x ^ n = if x.arg = π then x ^ n else conj (x ^ conj n) := by simp_rw [cpow_def, map_eq_zero, apply_ite conj, map_one, map_zero, ← exp_conj, map_mul, conj_conj, log_conj_eq_ite] split_ifs with hcx hn hx <;> rfl theorem conj_cpow (x : ℂ) (n : ℂ) (hx : x.arg ≠ π) : conj x ^ n = conj (x ^ conj n) := by rw [conj_cpow_eq_ite, if_neg hx] theorem cpow_conj (x : ℂ) (n : ℂ) (hx : x.arg ≠ π) : x ^ conj n = conj (conj x ^ n) := by rw [conj_cpow _ _ hx, conj_conj] lemma natCast_add_one_cpow_ne_zero (n : ℕ) (z : ℂ) : (n + 1 : ℂ) ^ z ≠ 0 := mt (cpow_eq_zero_iff ..).mp fun H ↦ by norm_cast at H; exact H.1 end Complex
-- section Tactics
Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean
243
244
/- 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.NNReal /-! # Limits and asymptotics of power functions at `+∞` This file contains results about the limiting behaviour of power functions at `+∞`. For convenience some results on asymptotics as `x → 0` (those which are not just continuity statements) are also located here. -/ noncomputable section open Real Topology NNReal ENNReal Filter ComplexConjugate Finset Set /-! ## Limits at `+∞` -/ section Limits open Real Filter /-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ y) atTop atTop := by rw [(atTop_basis' 0).tendsto_right_iff] intro b hb filter_upwards [eventually_ge_atTop 0, eventually_ge_atTop (b ^ (1 / y))] with x hx₀ hx simpa (disch := positivity) [Real.rpow_inv_le_iff_of_pos] using hx /-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/ theorem tendsto_rpow_neg_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ => x ^ (-y)) atTop (𝓝 0) := Tendsto.congr' (eventuallyEq_of_mem (Ioi_mem_atTop 0) fun _ hx => (rpow_neg (le_of_lt hx) y).symm) (tendsto_rpow_atTop hy).inv_tendsto_atTop open Asymptotics in lemma tendsto_rpow_atTop_of_base_lt_one (b : ℝ) (hb₀ : -1 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atTop (𝓝 (0 : ℝ)) := by rcases lt_trichotomy b 0 with hb|rfl|hb case inl => -- b < 0 simp_rw [Real.rpow_def_of_nonpos hb.le, hb.ne, ite_false] rw [← isLittleO_const_iff (c := (1 : ℝ)) one_ne_zero, (one_mul (1 : ℝ)).symm] refine IsLittleO.mul_isBigO ?exp ?cos case exp => rw [isLittleO_const_iff one_ne_zero] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id rw [← log_neg_eq_log, log_neg_iff (by linarith)] linarith case cos => rw [isBigO_iff] exact ⟨1, Eventually.of_forall fun x => by simp [Real.abs_cos_le_one]⟩ case inr.inl => -- b = 0 refine Tendsto.mono_right ?_ (Iff.mpr pure_le_nhds_iff rfl) rw [tendsto_pure] filter_upwards [eventually_ne_atTop 0] with _ hx simp [hx] case inr.inr => -- b > 0 simp_rw [Real.rpow_def_of_pos hb] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_neg ?_).mpr tendsto_id exact (log_neg_iff hb).mpr hb₁ lemma tendsto_rpow_atTop_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 (0 : ℝ)) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_of_pos ?_).mpr tendsto_id exact (log_pos_iff (by positivity)).mpr <| by aesop lemma tendsto_rpow_atBot_of_base_lt_one (b : ℝ) (hb₀ : 0 < b) (hb₁ : b < 1) : Tendsto (b ^ · : ℝ → ℝ) atBot atTop := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atTop.comp <| (tendsto_const_mul_atTop_iff_neg <| tendsto_id (α := ℝ)).mpr ?_ exact (log_neg_iff hb₀).mpr hb₁ lemma tendsto_rpow_atBot_of_base_gt_one (b : ℝ) (hb : 1 < b) : Tendsto (b ^ · : ℝ → ℝ) atBot (𝓝 0) := by simp_rw [Real.rpow_def_of_pos (by positivity : 0 < b)] refine tendsto_exp_atBot.comp <| (tendsto_const_mul_atBot_iff_pos <| tendsto_id (α := ℝ)).mpr ?_ exact (log_pos_iff (by positivity)).mpr <| by aesop /-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and `c` such that `b` is nonzero. -/ theorem tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 ≠ b) : Tendsto (fun x => x ^ (a / (b * x + c))) atTop (𝓝 1) := by refine Tendsto.congr' ?_ ((tendsto_exp_nhds_zero_nhds_one.comp (by simpa only [mul_zero, pow_one] using (tendsto_const_nhds (x := a)).mul (tendsto_div_pow_mul_exp_add_atTop b c 1 hb))).comp tendsto_log_atTop) apply eventuallyEq_of_mem (Ioi_mem_atTop (0 : ℝ)) intro x hx simp only [Set.mem_Ioi, Function.comp_apply] at hx ⊢ rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))] field_simp /-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_div : Tendsto (fun x => x ^ ((1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (1 : ℝ) _ (0 : ℝ) zero_ne_one ring /-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/ theorem tendsto_rpow_neg_div : Tendsto (fun x => x ^ (-(1 : ℝ) / x)) atTop (𝓝 1) := by convert tendsto_rpow_div_mul_add (-(1 : ℝ)) _ (0 : ℝ) zero_ne_one ring /-- The function `exp(x) / x ^ s` tends to `+∞` at `+∞`, for any real number `s`. -/ theorem tendsto_exp_div_rpow_atTop (s : ℝ) : Tendsto (fun x : ℝ => exp x / x ^ s) atTop atTop := by obtain ⟨n, hn⟩ := archimedean_iff_nat_lt.1 Real.instArchimedean s refine tendsto_atTop_mono' _ ?_ (tendsto_exp_div_pow_atTop n) filter_upwards [eventually_gt_atTop (0 : ℝ), eventually_ge_atTop (1 : ℝ)] with x hx₀ hx₁ gcongr simpa using rpow_le_rpow_of_exponent_le hx₁ hn.le /-- The function `exp (b * x) / x ^ s` tends to `+∞` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_exp_mul_div_rpow_atTop (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => exp (b * x) / x ^ s) atTop atTop := by refine ((tendsto_rpow_atTop hb).comp (tendsto_exp_div_rpow_atTop (s / b))).congr' ?_ filter_upwards [eventually_ge_atTop (0 : ℝ)] with x hx₀ simp [Real.div_rpow, (exp_pos x).le, rpow_nonneg, ← Real.rpow_mul, ← exp_mul, mul_comm x, hb.ne', *] /-- The function `x ^ s * exp (-b * x)` tends to `0` at `+∞`, for any real `s` and `b > 0`. -/ theorem tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (s : ℝ) (b : ℝ) (hb : 0 < b) : Tendsto (fun x : ℝ => x ^ s * exp (-b * x)) atTop (𝓝 0) := by refine (tendsto_exp_mul_div_rpow_atTop s b hb).inv_tendsto_atTop.congr' ?_ filter_upwards with x using by simp [exp_neg, inv_div, div_eq_mul_inv _ (exp _)] nonrec theorem NNReal.tendsto_rpow_atTop {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0 => x ^ y) atTop atTop := by rw [Filter.tendsto_atTop_atTop] intro b obtain ⟨c, hc⟩ := tendsto_atTop_atTop.mp (tendsto_rpow_atTop hy) b use c.toNNReal intro a ha exact mod_cast hc a (Real.toNNReal_le_iff_le_coe.mp ha) theorem ENNReal.tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) : Tendsto (fun x : ℝ≥0∞ => x ^ y) (𝓝 ⊤) (𝓝 ⊤) := by rw [ENNReal.tendsto_nhds_top_iff_nnreal] intro x obtain ⟨c, _, hc⟩ := (atTop_basis_Ioi.tendsto_iff atTop_basis_Ioi).mp (NNReal.tendsto_rpow_atTop hy) x trivial have hc' : Set.Ioi ↑c ∈ 𝓝 (⊤ : ℝ≥0∞) := Ioi_mem_nhds ENNReal.coe_lt_top filter_upwards [hc'] with a ha by_cases ha' : a = ⊤ · simp [ha', hy] lift a to ℝ≥0 using ha'
simp only [Set.mem_Ioi, coe_lt_coe] at ha hc rw [← ENNReal.coe_rpow_of_nonneg _ hy.le] exact mod_cast hc a ha end Limits /-! ## Asymptotic results: `IsBigO`, `IsLittleO` and `IsTheta`
Mathlib/Analysis/SpecialFunctions/Pow/Asymptotics.lean
158
165
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import Mathlib.Analysis.InnerProductSpace.Projection import Mathlib.Analysis.Normed.Lp.lpSpace import Mathlib.Analysis.InnerProductSpace.PiL2 /-! # Hilbert sum of a family of inner product spaces Given a family `(G : ι → Type*) [Π i, InnerProductSpace 𝕜 (G i)]` of inner product spaces, this file equips `lp G 2` with an inner product space structure, where `lp G 2` consists of those dependent functions `f : Π i, G i` for which `∑' i, ‖f i‖ ^ 2`, the sum of the norms-squared, is summable. This construction is sometimes called the *Hilbert sum* of the family `G`. By choosing `G` to be `ι → 𝕜`, the Hilbert space `ℓ²(ι, 𝕜)` may be seen as a special case of this construction. We also define a *predicate* `IsHilbertSum 𝕜 G V`, where `V : Π i, G i →ₗᵢ[𝕜] E`, expressing that `V` is an `OrthogonalFamily` and that the associated map `lp G 2 →ₗᵢ[𝕜] E` is surjective. ## Main definitions * `OrthogonalFamily.linearIsometry`: Given a Hilbert space `E`, a family `G` of inner product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal images, there is an induced isometric embedding of the Hilbert sum of `G` into `E`. * `IsHilbertSum`: Given a Hilbert space `E`, a family `G` of inner product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E`, `IsHilbertSum 𝕜 G V` means that `V` is an `OrthogonalFamily` and that the above linear isometry is surjective. * `IsHilbertSum.linearIsometryEquiv`: If a Hilbert space `E` is a Hilbert sum of the inner product spaces `G i` with respect to the family `V : Π i, G i →ₗᵢ[𝕜] E`, then the corresponding `OrthogonalFamily.linearIsometry` can be upgraded to a `LinearIsometryEquiv`. * `HilbertBasis`: We define a *Hilbert basis* of a Hilbert space `E` to be a structure whose single field `HilbertBasis.repr` is an isometric isomorphism of `E` with `ℓ²(ι, 𝕜)` (i.e., the Hilbert sum of `ι` copies of `𝕜`). This parallels the definition of `Basis`, in `LinearAlgebra.Basis`, as an isomorphism of an `R`-module with `ι →₀ R`. * `HilbertBasis.instCoeFun`: More conventionally a Hilbert basis is thought of as a family `ι → E` of vectors in `E` satisfying certain properties (orthonormality, completeness). We obtain this interpretation of a Hilbert basis `b` by defining `⇑b`, of type `ι → E`, to be the image under `b.repr` of `lp.single 2 i (1:𝕜)`. This parallels the definition `Basis.coeFun` in `LinearAlgebra.Basis`. * `HilbertBasis.mk`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors in `E` whose span is dense. This parallels the definition `Basis.mk` in `LinearAlgebra.Basis`. * `HilbertBasis.mkOfOrthogonalEqBot`: Make a Hilbert basis of `E` from an orthonormal family `v : ι → E` of vectors in `E` whose span has trivial orthogonal complement. ## Main results * `lp.instInnerProductSpace`: Construction of the inner product space instance on the Hilbert sum `lp G 2`. Note that from the file `Analysis.Normed.Lp.lpSpace`, the space `lp G 2` already held a normed space instance (`lp.normedSpace`), and if each `G i` is a Hilbert space (i.e., complete), then `lp G 2` was already known to be complete (`lp.completeSpace`). So the work here is to define the inner product and show it is compatible. * `OrthogonalFamily.range_linearIsometry`: Given a family `G` of inner product spaces and a family `V : Π i, G i →ₗᵢ[𝕜] E` of isometric embeddings of the `G i` into `E` with mutually-orthogonal images, the image of the embedding `OrthogonalFamily.linearIsometry` of the Hilbert sum of `G` into `E` is the closure of the span of the images of the `G i`. * `HilbertBasis.repr_apply_apply`: Given a Hilbert basis `b` of `E`, the entry `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)` is the inner product `⟪b i, x⟫`. * `HilbertBasis.hasSum_repr`: Given a Hilbert basis `b` of `E`, a vector `x` in `E` can be expressed as the "infinite linear combination" `∑' i, b.repr x i • b i` of the basis vectors `b i`, with coefficients given by the entries `b.repr x i` of `x`'s representation in `ℓ²(ι, 𝕜)`. * `exists_hilbertBasis`: A Hilbert space admits a Hilbert basis. ## Keywords Hilbert space, Hilbert sum, l2, Hilbert basis, unitary equivalence, isometric isomorphism -/ open RCLike Submodule Filter open scoped NNReal ENNReal ComplexConjugate Topology noncomputable section variable {ι 𝕜 : Type*} [RCLike 𝕜] {E : Type*} variable [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] variable {G : ι → Type*} [∀ i, NormedAddCommGroup (G i)] [∀ i, InnerProductSpace 𝕜 (G i)] local notation "⟪" x ", " y "⟫" => @inner 𝕜 _ _ x y /-- `ℓ²(ι, 𝕜)` is the Hilbert space of square-summable functions `ι → 𝕜`, herein implemented as `lp (fun i : ι => 𝕜) 2`. -/ notation "ℓ²(" ι ", " 𝕜 ")" => lp (fun i : ι => 𝕜) 2 /-! ### Inner product space structure on `lp G 2` -/ namespace lp theorem summable_inner (f g : lp G 2) : Summable fun i => ⟪f i, g i⟫ := by -- Apply the Direct Comparison Test, comparing with ∑' i, ‖f i‖ * ‖g i‖ (summable by Hölder) refine .of_norm_bounded (fun i => ‖f i‖ * ‖g i‖) (lp.summable_mul ?_ f g) ?_ · rw [Real.holderConjugate_iff]; norm_num intro i -- Then apply Cauchy-Schwarz pointwise exact norm_inner_le_norm (𝕜 := 𝕜) _ _ instance instInnerProductSpace : InnerProductSpace 𝕜 (lp G 2) := { lp.normedAddCommGroup (E := G) (p := 2) with inner := fun f g => ∑' i, ⟪f i, g i⟫ norm_sq_eq_re_inner := fun f => by calc ‖f‖ ^ 2 = ‖f‖ ^ (2 : ℝ≥0∞).toReal := by norm_cast _ = ∑' i, ‖f i‖ ^ (2 : ℝ≥0∞).toReal := lp.norm_rpow_eq_tsum ?_ f _ = ∑' i, ‖f i‖ ^ (2 : ℕ) := by norm_cast _ = ∑' i, re ⟪f i, f i⟫ := by simp [norm_sq_eq_re_inner (𝕜 := 𝕜)] _ = re (∑' i, ⟪f i, f i⟫) := (RCLike.reCLM.map_tsum ?_).symm · norm_num · exact summable_inner f f conj_inner_symm := fun f g => by calc conj _ = conj (∑' i, ⟪g i, f i⟫) := by congr _ = ∑' i, conj ⟪g i, f i⟫ := RCLike.conjCLE.map_tsum _ = ∑' i, ⟪f i, g i⟫ := by simp only [inner_conj_symm] _ = _ := by congr add_left := fun f₁ f₂ g => by calc _ = ∑' i, ⟪(f₁ + f₂) i, g i⟫ := ?_ _ = ∑' i, (⟪f₁ i, g i⟫ + ⟪f₂ i, g i⟫) := by simp only [inner_add_left, Pi.add_apply, coeFn_add] _ = (∑' i, ⟪f₁ i, g i⟫) + ∑' i, ⟪f₂ i, g i⟫ := Summable.tsum_add ?_ ?_ _ = _ := by congr · congr · exact summable_inner f₁ g · exact summable_inner f₂ g smul_left := fun f g c => by calc _ = ∑' i, ⟪c • f i, g i⟫ := ?_ _ = ∑' i, conj c * ⟪f i, g i⟫ := by simp only [inner_smul_left] _ = conj c * ∑' i, ⟪f i, g i⟫ := tsum_mul_left _ = _ := ?_ · simp only [coeFn_smul, Pi.smul_apply] · congr } theorem inner_eq_tsum (f g : lp G 2) : ⟪f, g⟫ = ∑' i, ⟪f i, g i⟫ := rfl theorem hasSum_inner (f g : lp G 2) : HasSum (fun i => ⟪f i, g i⟫) ⟪f, g⟫ := (summable_inner f g).hasSum theorem inner_single_left [DecidableEq ι] (i : ι) (a : G i) (f : lp G 2) : ⟪lp.single 2 i a, f⟫ = ⟪a, f i⟫ := by refine (hasSum_inner (lp.single 2 i a) f).unique ?_ simp_rw [lp.coeFn_single] convert hasSum_ite_eq i ⟪a, f i⟫ using 1 ext j split_ifs with h · subst h; rw [Pi.single_eq_same] · simp [Pi.single_eq_of_ne h] theorem inner_single_right [DecidableEq ι] (i : ι) (a : G i) (f : lp G 2) : ⟪f, lp.single 2 i a⟫ = ⟪f i, a⟫ := by simpa [inner_conj_symm] using congr_arg conj (inner_single_left (𝕜 := 𝕜) i a f) end lp /-! ### Identification of a general Hilbert space `E` with a Hilbert sum -/ namespace OrthogonalFamily variable [CompleteSpace E] {V : ∀ i, G i →ₗᵢ[𝕜] E} (hV : OrthogonalFamily 𝕜 G V) include hV protected theorem summable_of_lp (f : lp G 2) : Summable fun i => V i (f i) := by rw [hV.summable_iff_norm_sq_summable] convert (lp.memℓp f).summable _ · norm_cast · norm_num /-- A mutually orthogonal family of subspaces of `E` induce a linear isometry from `lp 2` of the subspaces into `E`. -/ protected def linearIsometry (hV : OrthogonalFamily 𝕜 G V) : lp G 2 →ₗᵢ[𝕜] E where toFun f := ∑' i, V i (f i) map_add' f g := by simp only [(hV.summable_of_lp f).tsum_add (hV.summable_of_lp g), lp.coeFn_add, Pi.add_apply, LinearIsometry.map_add] map_smul' c f := by simpa only [LinearIsometry.map_smul, Pi.smul_apply, lp.coeFn_smul] using (hV.summable_of_lp f).tsum_const_smul c norm_map' f := by classical -- needed for lattice instance on `Finset ι`, for `Filter.atTop_neBot` have H : 0 < (2 : ℝ≥0∞).toReal := by norm_num suffices ‖∑' i : ι, V i (f i)‖ ^ (2 : ℝ≥0∞).toReal = ‖f‖ ^ (2 : ℝ≥0∞).toReal by exact Real.rpow_left_injOn H.ne' (norm_nonneg _) (norm_nonneg _) this refine tendsto_nhds_unique ?_ (lp.hasSum_norm H f) convert (hV.summable_of_lp f).hasSum.norm.rpow_const (Or.inr H.le) using 1 ext s exact mod_cast (hV.norm_sum f s).symm protected theorem linearIsometry_apply (f : lp G 2) : hV.linearIsometry f = ∑' i, V i (f i) := rfl protected theorem hasSum_linearIsometry (f : lp G 2) : HasSum (fun i => V i (f i)) (hV.linearIsometry f) := (hV.summable_of_lp f).hasSum @[simp] protected theorem linearIsometry_apply_single [DecidableEq ι] {i : ι} (x : G i) : hV.linearIsometry (lp.single 2 i x) = V i x := by rw [hV.linearIsometry_apply, ← tsum_ite_eq i (V i x)] congr ext j rw [lp.single_apply] split_ifs with h · subst h; simp · simp [h] protected theorem linearIsometry_apply_dfinsupp_sum_single [DecidableEq ι] [∀ i, DecidableEq (G i)] (W₀ : Π₀ i : ι, G i) : hV.linearIsometry (W₀.sum (lp.single 2)) = W₀.sum fun i => V i := by simp /-- The canonical linear isometry from the `lp 2` of a mutually orthogonal family of subspaces of `E` into E, has range the closure of the span of the subspaces. -/ protected theorem range_linearIsometry [∀ i, CompleteSpace (G i)] : LinearMap.range hV.linearIsometry.toLinearMap = (⨆ i, LinearMap.range (V i).toLinearMap).topologicalClosure := by classical refine le_antisymm ?_ ?_ · rintro x ⟨f, rfl⟩ refine mem_closure_of_tendsto (hV.hasSum_linearIsometry f) (Eventually.of_forall ?_) intro s rw [SetLike.mem_coe] refine sum_mem ?_ intro i _ refine mem_iSup_of_mem i ?_ exact LinearMap.mem_range_self _ (f i) · apply topologicalClosure_minimal · refine iSup_le ?_ rintro i x ⟨x, rfl⟩ use lp.single 2 i x exact hV.linearIsometry_apply_single x exact hV.linearIsometry.isometry.isUniformInducing.isComplete_range.isClosed end OrthogonalFamily section IsHilbertSum variable (𝕜 G) variable [CompleteSpace E] (V : ∀ i, G i →ₗᵢ[𝕜] E) (F : ι → Submodule 𝕜 E) /-- Given a family of Hilbert spaces `G : ι → Type*`, a Hilbert sum of `G` consists of a Hilbert space `E` and an orthogonal family `V : Π i, G i →ₗᵢ[𝕜] E` such that the induced isometry `Φ : lp G 2 → E` is surjective. Keeping in mind that `lp G 2` is "the" external Hilbert sum of `G : ι → Type*`, this is analogous to `DirectSum.IsInternal`, except that we don't express it in terms of actual submodules. -/ structure IsHilbertSum : Prop where ofSurjective :: /-- The orthogonal family constituting the summands in the Hilbert sum. -/ protected OrthogonalFamily : OrthogonalFamily 𝕜 G V /-- The isometry `lp G 2 → E` induced by the orthogonal family is surjective. -/ protected surjective_isometry : Function.Surjective OrthogonalFamily.linearIsometry variable {𝕜 G V} /-- If `V : Π i, G i →ₗᵢ[𝕜] E` is an orthogonal family such that the supremum of the ranges of `V i` is dense, then `(E, V)` is a Hilbert sum of `G`. -/ theorem IsHilbertSum.mk [∀ i, CompleteSpace <| G i] (hVortho : OrthogonalFamily 𝕜 G V) (hVtotal : ⊤ ≤ (⨆ i, LinearMap.range (V i).toLinearMap).topologicalClosure) : IsHilbertSum 𝕜 G V := { OrthogonalFamily := hVortho surjective_isometry := by rw [← LinearIsometry.coe_toLinearMap] exact LinearMap.range_eq_top.mp (eq_top_iff.mpr <| hVtotal.trans_eq hVortho.range_linearIsometry.symm) } /-- This is `Orthonormal.isHilbertSum` in the case of actual inclusions from subspaces. -/ theorem IsHilbertSum.mkInternal [∀ i, CompleteSpace <| F i] (hFortho : OrthogonalFamily 𝕜 (fun i => F i) fun i => (F i).subtypeₗᵢ) (hFtotal : ⊤ ≤ (⨆ i, F i).topologicalClosure) : IsHilbertSum 𝕜 (fun i => F i) fun i => (F i).subtypeₗᵢ := IsHilbertSum.mk hFortho (by simpa [subtypeₗᵢ_toLinearMap, range_subtype] using hFtotal) /-- *A* Hilbert sum `(E, V)` of `G` is canonically isomorphic to *the* Hilbert sum of `G`,
i.e `lp G 2`. Note that this goes in the opposite direction from `OrthogonalFamily.linearIsometry`. -/ noncomputable def IsHilbertSum.linearIsometryEquiv (hV : IsHilbertSum 𝕜 G V) : E ≃ₗᵢ[𝕜] lp G 2 := LinearIsometryEquiv.symm <| LinearIsometryEquiv.ofSurjective hV.OrthogonalFamily.linearIsometry hV.surjective_isometry /-- In the canonical isometric isomorphism between a Hilbert sum `E` of `G` and `lp G 2`,
Mathlib/Analysis/InnerProductSpace/l2Space.lean
290
297
/- Copyright (c) 2016 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.Data.Set.Defs import Mathlib.Logic.Basic import Mathlib.Logic.ExistsUnique import Mathlib.Logic.Nonempty import Mathlib.Logic.Nontrivial.Defs import Batteries.Tactic.Init import Mathlib.Order.Defs.Unbundled /-! # Miscellaneous function constructions and lemmas -/ open Function universe u v w namespace Function section variable {α β γ : Sort*} {f : α → β} /-- Evaluate a function at an argument. Useful if you want to talk about the partially applied `Function.eval x : (∀ x, β x) → β x`. -/ @[reducible, simp] def eval {β : α → Sort*} (x : α) (f : ∀ x, β x) : β x := f x theorem eval_apply {β : α → Sort*} (x : α) (f : ∀ x, β x) : eval x f = f x := rfl theorem const_def {y : β} : (fun _ : α ↦ y) = const α y := rfl theorem const_injective [Nonempty α] : Injective (const α : β → α → β) := fun _ _ h ↦ let ⟨x⟩ := ‹Nonempty α› congr_fun h x @[simp] theorem const_inj [Nonempty α] {y₁ y₂ : β} : const α y₁ = const α y₂ ↔ y₁ = y₂ := ⟨fun h ↦ const_injective h, fun h ↦ h ▸ rfl⟩ theorem onFun_apply (f : β → β → γ) (g : α → β) (a b : α) : onFun f g a b = f (g a) (g b) := rfl lemma hfunext {α α' : Sort u} {β : α → Sort v} {β' : α' → Sort v} {f : ∀a, β a} {f' : ∀a, β' a} (hα : α = α') (h : ∀a a', HEq a a' → HEq (f a) (f' a')) : HEq f f' := by subst hα have : ∀a, HEq (f a) (f' a) := fun a ↦ h a a (HEq.refl a) have : β = β' := by funext a; exact type_eq_of_heq (this a) subst this apply heq_of_eq funext a exact eq_of_heq (this a) theorem ne_iff {β : α → Sort*} {f₁ f₂ : ∀ a, β a} : f₁ ≠ f₂ ↔ ∃ a, f₁ a ≠ f₂ a := funext_iff.not.trans not_forall lemma funext_iff_of_subsingleton [Subsingleton α] {g : α → β} (x y : α) : f x = g y ↔ f = g := by refine ⟨fun h ↦ funext fun z ↦ ?_, fun h ↦ ?_⟩ · rwa [Subsingleton.elim x z, Subsingleton.elim y z] at h · rw [h, Subsingleton.elim x y] theorem swap_lt {α} [LT α] : swap (· < · : α → α → _) = (· > ·) := rfl theorem swap_le {α} [LE α] : swap (· ≤ · : α → α → _) = (· ≥ ·) := rfl theorem swap_gt {α} [LT α] : swap (· > · : α → α → _) = (· < ·) := rfl theorem swap_ge {α} [LE α] : swap (· ≥ · : α → α → _) = (· ≤ ·) := rfl protected theorem Bijective.injective {f : α → β} (hf : Bijective f) : Injective f := hf.1 protected theorem Bijective.surjective {f : α → β} (hf : Bijective f) : Surjective f := hf.2 theorem not_injective_iff : ¬ Injective f ↔ ∃ a b, f a = f b ∧ a ≠ b := by simp only [Injective, not_forall, exists_prop] /-- If the co-domain `β` of an injective function `f : α → β` has decidable equality, then the domain `α` also has decidable equality. -/ protected def Injective.decidableEq [DecidableEq β] (I : Injective f) : DecidableEq α := fun _ _ ↦ decidable_of_iff _ I.eq_iff theorem Injective.of_comp {g : γ → α} (I : Injective (f ∘ g)) : Injective g := fun _ _ h ↦ I <| congr_arg f h @[simp] theorem Injective.of_comp_iff (hf : Injective f) (g : γ → α) : Injective (f ∘ g) ↔ Injective g := ⟨Injective.of_comp, hf.comp⟩ theorem Injective.of_comp_right {g : γ → α} (I : Injective (f ∘ g)) (hg : Surjective g) : Injective f := fun x y h ↦ by obtain ⟨x, rfl⟩ := hg x obtain ⟨y, rfl⟩ := hg y exact congr_arg g (I h) theorem Surjective.bijective₂_of_injective {g : γ → α} (hf : Surjective f) (hg : Surjective g) (I : Injective (f ∘ g)) : Bijective f ∧ Bijective g := ⟨⟨I.of_comp_right hg, hf⟩, I.of_comp, hg⟩ @[simp] theorem Injective.of_comp_iff' (f : α → β) {g : γ → α} (hg : Bijective g) : Injective (f ∘ g) ↔ Injective f := ⟨fun I ↦ I.of_comp_right hg.2, fun h ↦ h.comp hg.injective⟩ theorem Injective.piMap {ι : Sort*} {α β : ι → Sort*} {f : ∀ i, α i → β i} (hf : ∀ i, Injective (f i)) : Injective (Pi.map f) := fun _ _ h ↦ funext fun i ↦ hf i <| congrFun h _ /-- Composition by an injective function on the left is itself injective. -/ theorem Injective.comp_left {g : β → γ} (hg : Injective g) : Injective (g ∘ · : (α → β) → α → γ) := .piMap fun _ ↦ hg theorem injective_comp_left_iff [Nonempty α] {g : β → γ} : Injective (g ∘ · : (α → β) → α → γ) ↔ Injective g := ⟨fun h b₁ b₂ eq ↦ Nonempty.elim ‹_› (congr_fun <| h (a₁ := fun _ ↦ b₁) (a₂ := fun _ ↦ b₂) <| funext fun _ ↦ eq), (·.comp_left)⟩ @[nontriviality] theorem injective_of_subsingleton [Subsingleton α] (f : α → β) : Injective f := fun _ _ _ ↦ Subsingleton.elim _ _ @[nontriviality] theorem bijective_of_subsingleton [Subsingleton α] (f : α → α) : Bijective f := ⟨injective_of_subsingleton f, fun a ↦ ⟨a, Subsingleton.elim ..⟩⟩ lemma Injective.dite (p : α → Prop) [DecidablePred p] {f : {a : α // p a} → β} {f' : {a : α // ¬ p a} → β} (hf : Injective f) (hf' : Injective f') (im_disj : ∀ {x x' : α} {hx : p x} {hx' : ¬ p x'}, f ⟨x, hx⟩ ≠ f' ⟨x', hx'⟩) : Function.Injective (fun x ↦ if h : p x then f ⟨x, h⟩ else f' ⟨x, h⟩) := fun x₁ x₂ h => by dsimp only at h by_cases h₁ : p x₁ <;> by_cases h₂ : p x₂ · rw [dif_pos h₁, dif_pos h₂] at h; injection (hf h) · rw [dif_pos h₁, dif_neg h₂] at h; exact (im_disj h).elim · rw [dif_neg h₁, dif_pos h₂] at h; exact (im_disj h.symm).elim · rw [dif_neg h₁, dif_neg h₂] at h; injection (hf' h) theorem Surjective.of_comp {g : γ → α} (S : Surjective (f ∘ g)) : Surjective f := fun y ↦ let ⟨x, h⟩ := S y ⟨g x, h⟩ @[simp] theorem Surjective.of_comp_iff (f : α → β) {g : γ → α} (hg : Surjective g) : Surjective (f ∘ g) ↔ Surjective f := ⟨Surjective.of_comp, fun h ↦ h.comp hg⟩ theorem Surjective.of_comp_left {g : γ → α} (S : Surjective (f ∘ g)) (hf : Injective f) : Surjective g := fun a ↦ let ⟨c, hc⟩ := S (f a); ⟨c, hf hc⟩ theorem Injective.bijective₂_of_surjective {g : γ → α} (hf : Injective f) (hg : Injective g) (S : Surjective (f ∘ g)) : Bijective f ∧ Bijective g := ⟨⟨hf, S.of_comp⟩, hg, S.of_comp_left hf⟩ @[simp] theorem Surjective.of_comp_iff' (hf : Bijective f) (g : γ → α) : Surjective (f ∘ g) ↔ Surjective g := ⟨fun S ↦ S.of_comp_left hf.1, hf.surjective.comp⟩ instance decidableEqPFun (p : Prop) [Decidable p] (α : p → Type*) [∀ hp, DecidableEq (α hp)] : DecidableEq (∀ hp, α hp) | f, g => decidable_of_iff (∀ hp, f hp = g hp) funext_iff.symm protected theorem Surjective.forall (hf : Surjective f) {p : β → Prop} : (∀ y, p y) ↔ ∀ x, p (f x) := ⟨fun h x ↦ h (f x), fun h y ↦ let ⟨x, hx⟩ := hf y hx ▸ h x⟩ protected theorem Surjective.forall₂ (hf : Surjective f) {p : β → β → Prop} : (∀ y₁ y₂, p y₁ y₂) ↔ ∀ x₁ x₂, p (f x₁) (f x₂) := hf.forall.trans <| forall_congr' fun _ ↦ hf.forall protected theorem Surjective.forall₃ (hf : Surjective f) {p : β → β → β → Prop} : (∀ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∀ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) := hf.forall.trans <| forall_congr' fun _ ↦ hf.forall₂ protected theorem Surjective.exists (hf : Surjective f) {p : β → Prop} : (∃ y, p y) ↔ ∃ x, p (f x) := ⟨fun ⟨y, hy⟩ ↦ let ⟨x, hx⟩ := hf y ⟨x, hx.symm ▸ hy⟩, fun ⟨x, hx⟩ ↦ ⟨f x, hx⟩⟩ protected theorem Surjective.exists₂ (hf : Surjective f) {p : β → β → Prop} : (∃ y₁ y₂, p y₁ y₂) ↔ ∃ x₁ x₂, p (f x₁) (f x₂) := hf.exists.trans <| exists_congr fun _ ↦ hf.exists protected theorem Surjective.exists₃ (hf : Surjective f) {p : β → β → β → Prop} : (∃ y₁ y₂ y₃, p y₁ y₂ y₃) ↔ ∃ x₁ x₂ x₃, p (f x₁) (f x₂) (f x₃) := hf.exists.trans <| exists_congr fun _ ↦ hf.exists₂ theorem Surjective.injective_comp_right (hf : Surjective f) : Injective fun g : β → γ ↦ g ∘ f := fun _ _ h ↦ funext <| hf.forall.2 <| congr_fun h theorem injective_comp_right_iff_surjective {γ : Type*} [Nontrivial γ] : Injective (fun g : β → γ ↦ g ∘ f) ↔ Surjective f := by refine ⟨not_imp_not.mp fun not_surj inj ↦ not_subsingleton γ ⟨fun c c' ↦ ?_⟩, (·.injective_comp_right)⟩ have ⟨b₀, hb⟩ := not_forall.mp not_surj classical have := inj (a₁ := fun _ ↦ c) (a₂ := (if · = b₀ then c' else c)) ?_ · simpa using congr_fun this b₀ ext a; simp only [comp_apply, if_neg fun h ↦ hb ⟨a, h⟩] protected theorem Surjective.right_cancellable (hf : Surjective f) {g₁ g₂ : β → γ} : g₁ ∘ f = g₂ ∘ f ↔ g₁ = g₂ := hf.injective_comp_right.eq_iff theorem surjective_of_right_cancellable_Prop (h : ∀ g₁ g₂ : β → Prop, g₁ ∘ f = g₂ ∘ f → g₁ = g₂) : Surjective f := injective_comp_right_iff_surjective.mp h theorem bijective_iff_existsUnique (f : α → β) : Bijective f ↔ ∀ b : β, ∃! a : α, f a = b := ⟨fun hf b ↦ let ⟨a, ha⟩ := hf.surjective b ⟨a, ha, fun _ ha' ↦ hf.injective (ha'.trans ha.symm)⟩, fun he ↦ ⟨fun {_a a'} h ↦ (he (f a')).unique h rfl, fun b ↦ (he b).exists⟩⟩ /-- Shorthand for using projection notation with `Function.bijective_iff_existsUnique`. -/ protected theorem Bijective.existsUnique {f : α → β} (hf : Bijective f) (b : β) : ∃! a : α, f a = b := (bijective_iff_existsUnique f).mp hf b theorem Bijective.existsUnique_iff {f : α → β} (hf : Bijective f) {p : β → Prop} : (∃! y, p y) ↔ ∃! x, p (f x) := ⟨fun ⟨y, hpy, hy⟩ ↦ let ⟨x, hx⟩ := hf.surjective y ⟨x, by simpa [hx], fun z (hz : p (f z)) ↦ hf.injective <| hx.symm ▸ hy _ hz⟩, fun ⟨x, hpx, hx⟩ ↦ ⟨f x, hpx, fun y hy ↦ let ⟨z, hz⟩ := hf.surjective y hz ▸ congr_arg f (hx _ (by simpa [hz]))⟩⟩ theorem Bijective.of_comp_iff (f : α → β) {g : γ → α} (hg : Bijective g) : Bijective (f ∘ g) ↔ Bijective f := and_congr (Injective.of_comp_iff' _ hg) (Surjective.of_comp_iff _ hg.surjective) theorem Bijective.of_comp_iff' {f : α → β} (hf : Bijective f) (g : γ → α) : Function.Bijective (f ∘ g) ↔ Function.Bijective g := and_congr (Injective.of_comp_iff hf.injective _) (Surjective.of_comp_iff' hf _) /-- **Cantor's diagonal argument** implies that there are no surjective functions from `α` to `Set α`. -/ theorem cantor_surjective {α} (f : α → Set α) : ¬Surjective f | h => let ⟨D, e⟩ := h {a | ¬ f a a} @iff_not_self (D ∈ f D) <| iff_of_eq <| congr_arg (D ∈ ·) e /-- **Cantor's diagonal argument** implies that there are no injective functions from `Set α` to `α`. -/ theorem cantor_injective {α : Type*} (f : Set α → α) : ¬Injective f | i => cantor_surjective (fun a ↦ {b | ∀ U, a = f U → U b}) <| RightInverse.surjective (fun U ↦ Set.ext fun _ ↦ ⟨fun h ↦ h U rfl, fun h _ e ↦ i e ▸ h⟩) /-- There is no surjection from `α : Type u` into `Type (max u v)`. This theorem demonstrates why `Type : Type` would be inconsistent in Lean. -/ theorem not_surjective_Type {α : Type u} (f : α → Type max u v) : ¬Surjective f := by intro hf let T : Type max u v := Sigma f cases hf (Set T) with | intro U hU => let g : Set T → T := fun s ↦ ⟨U, cast hU.symm s⟩ have hg : Injective g := by intro s t h suffices cast hU (g s).2 = cast hU (g t).2 by simp only [g, cast_cast, cast_eq] at this assumption · congr exact cantor_injective g hg /-- `g` is a partial inverse to `f` (an injective but not necessarily surjective function) if `g y = some x` implies `f x = y`, and `g y = none` implies that `y` is not in the range of `f`. -/ def IsPartialInv {α β} (f : α → β) (g : β → Option α) : Prop := ∀ x y, g y = some x ↔ f x = y theorem isPartialInv_left {α β} {f : α → β} {g} (H : IsPartialInv f g) (x) : g (f x) = some x := (H _ _).2 rfl theorem injective_of_isPartialInv {α β} {f : α → β} {g} (H : IsPartialInv f g) : Injective f := fun _ _ h ↦ Option.some.inj <| ((H _ _).2 h).symm.trans ((H _ _).2 rfl) theorem injective_of_isPartialInv_right {α β} {f : α → β} {g} (H : IsPartialInv f g) (x y b) (h₁ : b ∈ g x) (h₂ : b ∈ g y) : x = y := ((H _ _).1 h₁).symm.trans ((H _ _).1 h₂) theorem LeftInverse.comp_eq_id {f : α → β} {g : β → α} (h : LeftInverse f g) : f ∘ g = id := funext h theorem leftInverse_iff_comp {f : α → β} {g : β → α} : LeftInverse f g ↔ f ∘ g = id := ⟨LeftInverse.comp_eq_id, congr_fun⟩ theorem RightInverse.comp_eq_id {f : α → β} {g : β → α} (h : RightInverse f g) : g ∘ f = id := funext h theorem rightInverse_iff_comp {f : α → β} {g : β → α} : RightInverse f g ↔ g ∘ f = id :=
⟨RightInverse.comp_eq_id, congr_fun⟩ theorem LeftInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : LeftInverse f g) (hh : LeftInverse h i) : LeftInverse (h ∘ f) (g ∘ i) := fun a ↦ show h (f (g (i a))) = a by rw [hf (i a), hh a] theorem RightInverse.comp {f : α → β} {g : β → α} {h : β → γ} {i : γ → β} (hf : RightInverse f g) (hh : RightInverse h i) : RightInverse (h ∘ f) (g ∘ i) := LeftInverse.comp hh hf theorem LeftInverse.rightInverse {f : α → β} {g : β → α} (h : LeftInverse g f) : RightInverse f g := h
Mathlib/Logic/Function/Basic.lean
295
306
/- Copyright (c) 2024 Christian Merten. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Christian Merten -/ import Mathlib.CategoryTheory.Galois.Basic import Mathlib.CategoryTheory.Limits.FintypeCat import Mathlib.CategoryTheory.Limits.Preserves.Limits import Mathlib.CategoryTheory.Limits.Shapes.SingleObj import Mathlib.GroupTheory.GroupAction.Basic import Mathlib.Algebra.Equiv.TransferInstance /-! # Galois objects in Galois categories We define when a connected object of a Galois category `C` is Galois in a fiber functor independent way and show equivalent characterisations. ## Main definitions * `IsGalois` : Connected object `X` of `C` such that `X / Aut X` is terminal. ## Main results * `galois_iff_pretransitive` : A connected object `X` is Galois if and only if `Aut X` acts transitively on `F.obj X` for a fiber functor `F`. -/ universe u₁ u₂ v₁ v₂ v w namespace CategoryTheory namespace PreGaloisCategory open Limits Functor noncomputable instance {G : Type v} [Group G] [Finite G] : PreservesColimitsOfShape (SingleObj G) FintypeCat.incl.{w} := by choose G' hg hf e using Finite.exists_type_univ_nonempty_mulEquiv G exact Limits.preservesColimitsOfShape_of_equiv (Classical.choice e).toSingleObjEquiv.symm _ /-- A connected object `X` of `C` is Galois if the quotient `X / Aut X` is terminal. -/ class IsGalois {C : Type u₁} [Category.{u₂, u₁} C] [GaloisCategory C] (X : C) : Prop extends IsConnected X where quotientByAutTerminal : Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) variable {C : Type u₁} [Category.{u₂, u₁} C] /-- The natural action of `Aut X` on `F.obj X`. -/ instance autMulFiber (F : C ⥤ FintypeCat.{w}) (X : C) : MulAction (Aut X) (F.obj X) where smul σ a := F.map σ.hom a one_smul a := by show F.map (𝟙 X) a = a simp only [map_id, FintypeCat.id_apply] mul_smul g h a := by show F.map (h.hom ≫ g.hom) a = (F.map h.hom ≫ F.map g.hom) a simp only [map_comp, FintypeCat.comp_apply] variable [GaloisCategory C] (F : C ⥤ FintypeCat.{w}) [FiberFunctor F] /-- For a connected object `X` of `C`, the quotient `X / Aut X` is terminal if and only if the quotient `F.obj X / Aut X` has exactly one element. -/ noncomputable def quotientByAutTerminalEquivUniqueQuotient (X : C) [IsConnected X] : IsTerminal (colimit <| SingleObj.functor <| Aut.toEnd X) ≃ Unique (MulAction.orbitRel.Quotient (Aut X) (F.obj X)) := by let J : SingleObj (Aut X) ⥤ C := SingleObj.functor (Aut.toEnd X) let e : (F ⋙ FintypeCat.incl).obj (colimit J) ≅ _ := preservesColimitIso (F ⋙ FintypeCat.incl) J ≪≫ (Equiv.toIso <| SingleObj.Types.colimitEquivQuotient (J ⋙ F ⋙ FintypeCat.incl)) apply Equiv.trans · apply (IsTerminal.isTerminalIffObj (F ⋙ FintypeCat.incl) _).trans (isLimitEmptyConeEquiv _ (asEmptyCone _) (asEmptyCone _) e) exact Types.isTerminalEquivUnique _ lemma isGalois_iff_aux (X : C) [IsConnected X] : IsGalois X ↔ Nonempty (IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X) := ⟨fun h ↦ h.quotientByAutTerminal, fun h ↦ ⟨h⟩⟩ /-- Given a fiber functor `F` and a connected object `X` of `C`. Then `X` is Galois if and only if the natural action of `Aut X` on `F.obj X` is transitive. -/ theorem isGalois_iff_pretransitive (X : C) [IsConnected X] : IsGalois X ↔ MulAction.IsPretransitive (Aut X) (F.obj X) := by rw [isGalois_iff_aux, Equiv.nonempty_congr <| quotientByAutTerminalEquivUniqueQuotient F X] exact (MulAction.pretransitive_iff_unique_quotient_of_nonempty (Aut X) (F.obj X)).symm /-- If `X` is Galois, the quotient `X / Aut X` is terminal. -/ noncomputable def isTerminalQuotientOfIsGalois (X : C) [IsGalois X] : IsTerminal <| colimit <| SingleObj.functor <| Aut.toEnd X := Nonempty.some IsGalois.quotientByAutTerminal /-- If `X` is Galois, then the action of `Aut X` on `F.obj X` is transitive for every fiber functor `F`. -/ instance isPretransitive_of_isGalois (X : C) [IsGalois X] : MulAction.IsPretransitive (Aut X) (F.obj X) := by rw [← isGalois_iff_pretransitive] infer_instance lemma stabilizer_normal_of_isGalois (X : C) [IsGalois X] (x : F.obj X) : Subgroup.Normal (MulAction.stabilizer (Aut F) x) where conj_mem n ninstab g := by rw [MulAction.mem_stabilizer_iff] show g • n • (g⁻¹ • x) = x have : ∃ (φ : Aut X), F.map φ.hom x = g⁻¹ • x := MulAction.IsPretransitive.exists_smul_eq x (g⁻¹ • x) obtain ⟨φ, h⟩ := this rw [← h, mulAction_naturality, ninstab, h] simp theorem evaluation_aut_surjective_of_isGalois (A : C) [IsGalois A] (a : F.obj A) : Function.Surjective (fun f : Aut A ↦ F.map f.hom a) := MulAction.IsPretransitive.exists_smul_eq a theorem evaluation_aut_bijective_of_isGalois (A : C) [IsGalois A] (a : F.obj A) : Function.Bijective (fun f : Aut A ↦ F.map f.hom a) := ⟨evaluation_aut_injective_of_isConnected F A a, evaluation_aut_surjective_of_isGalois F A a⟩ /-- For Galois `A` and a point `a` of the fiber of `A`, the evaluation at `A` as an equivalence. -/ noncomputable def evaluationEquivOfIsGalois (A : C) [IsGalois A] (a : F.obj A) : Aut A ≃ F.obj A := Equiv.ofBijective _ (evaluation_aut_bijective_of_isGalois F A a) @[simp] lemma evaluationEquivOfIsGalois_apply (A : C) [IsGalois A] (a : F.obj A) (φ : Aut A) : evaluationEquivOfIsGalois F A a φ = F.map φ.hom a := rfl @[simp] lemma evaluationEquivOfIsGalois_symm_fiber (A : C) [IsGalois A] (a b : F.obj A) : F.map ((evaluationEquivOfIsGalois F A a).symm b).hom a = b := by change (evaluationEquivOfIsGalois F A a) _ = _ simp section AutMap /-- For a morphism from a connected object `A` to a Galois object `B` and an automorphism of `A`, there exists a unique automorphism of `B` making the canonical diagram commute. -/ lemma exists_autMap {A B : C} (f : A ⟶ B) [IsConnected A] [IsGalois B] (σ : Aut A) : ∃! (τ : Aut B), f ≫ τ.hom = σ.hom ≫ f := by let F := GaloisCategory.getFiberFunctor C obtain ⟨a⟩ := nonempty_fiber_of_isConnected F A refine ⟨?_, ?_, ?_⟩ · exact (evaluationEquivOfIsGalois F B (F.map f a)).symm (F.map (σ.hom ≫ f) a) · apply evaluation_injective_of_isConnected F A B a simp · intro τ hτ apply evaluation_aut_injective_of_isConnected F B (F.map f a) simpa using congr_fun (F.congr_map hτ) a
/-- A morphism from a connected object to a Galois object induces a map on automorphism groups. This is a group homomorphism (see `autMapHom`). -/ noncomputable def autMap {A B : C} [IsConnected A] [IsGalois B] (f : A ⟶ B) (σ : Aut A) : Aut B :=
Mathlib/CategoryTheory/Galois/GaloisObjects.lean
148
152
/- Copyright (c) 2021 Hanting Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hanting Zhang -/ import Mathlib.Analysis.SpecialFunctions.Integrals /-! # The Wallis formula for Pi This file establishes the Wallis product for `π` (`Real.tendsto_prod_pi_div_two`). Our proof is largely about analyzing the behaviour of the sequence `∫ x in 0..π, sin x ^ n` as `n → ∞`. See: https://en.wikipedia.org/wiki/Wallis_product The proof can be broken down into two pieces. The first step (carried out in `Analysis.SpecialFunctions.Integrals`) is to use repeated integration by parts to obtain an explicit formula for this integral, which is rational if `n` is odd and a rational multiple of `π` if `n` is even. The second step, carried out here, is to estimate the ratio `∫ (x : ℝ) in 0..π, sin x ^ (2 * k + 1) / ∫ (x : ℝ) in 0..π, sin x ^ (2 * k)` and prove that it converges to one using the squeeze theorem. The final product for `π` is obtained after some algebraic manipulation. ## Main statements * `Real.Wallis.W`: the product of the first `k` terms in Wallis' formula for `π`. * `Real.Wallis.W_eq_integral_sin_pow_div_integral_sin_pow`: express `W n` as a ratio of integrals. * `Real.Wallis.W_le` and `Real.Wallis.le_W`: upper and lower bounds for `W n`. * `Real.tendsto_prod_pi_div_two`: the Wallis product formula. -/ open scoped Real Topology Nat open Filter Finset intervalIntegral namespace Real namespace Wallis /-- The product of the first `k` terms in Wallis' formula for `π`. -/ noncomputable def W (k : ℕ) : ℝ := ∏ i ∈ range k, (2 * i + 2) / (2 * i + 1) * ((2 * i + 2) / (2 * i + 3)) theorem W_succ (k : ℕ) : W (k + 1) = W k * ((2 * k + 2) / (2 * k + 1) * ((2 * k + 2) / (2 * k + 3))) := prod_range_succ _ _ theorem W_pos (k : ℕ) : 0 < W k := by induction' k with k hk · unfold W; simp · rw [W_succ] refine mul_pos hk (mul_pos (div_pos ?_ ?_) (div_pos ?_ ?_)) <;> positivity
theorem W_eq_factorial_ratio (n : ℕ) : W n = 2 ^ (4 * n) * n ! ^ 4 / ((2 * n)! ^ 2 * (2 * n + 1)) := by induction' n with n IH · simp only [W, prod_range_zero, Nat.factorial_zero, mul_zero, pow_zero,
Mathlib/Data/Real/Pi/Wallis.lean
55
59
/- 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 α`. -/ theorem iInf_neBot_of_directed {f : ι → Filter α} [hn : Nonempty α] (hd : Directed (· ≥ ·) f) (hb : ∀ i, NeBot (f i)) : NeBot (iInf f) := by cases isEmpty_or_nonempty ι · constructor simp [iInf_of_empty f, top_ne_bot] · exact iInf_neBot_of_directed' hd hb theorem sInf_neBot_of_directed' {s : Set (Filter α)} (hne : s.Nonempty) (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ @iInf_neBot_of_directed' _ _ _ hne.to_subtype hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem sInf_neBot_of_directed [Nonempty α] {s : Set (Filter α)} (hd : DirectedOn (· ≥ ·) s) (hbot : ⊥ ∉ s) : NeBot (sInf s) := (sInf_eq_iInf' s).symm ▸ iInf_neBot_of_directed hd.directed_val fun ⟨_, hf⟩ => ⟨ne_of_mem_of_not_mem hf hbot⟩ theorem iInf_neBot_iff_of_directed' {f : ι → Filter α} [Nonempty ι] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed' hd⟩ theorem iInf_neBot_iff_of_directed {f : ι → Filter α} [Nonempty α] (hd : Directed (· ≥ ·) f) : NeBot (iInf f) ↔ ∀ i, NeBot (f i) := ⟨fun H i => H.mono (iInf_le _ i), iInf_neBot_of_directed hd⟩ /-! #### `principal` equations -/ @[simp] theorem inf_principal {s t : Set α} : 𝓟 s ⊓ 𝓟 t = 𝓟 (s ∩ t) := le_antisymm (by simp only [le_principal_iff, mem_inf_iff]; exact ⟨s, Subset.rfl, t, Subset.rfl, rfl⟩) (by simp [le_inf_iff, inter_subset_left, inter_subset_right]) @[simp] theorem sup_principal {s t : Set α} : 𝓟 s ⊔ 𝓟 t = 𝓟 (s ∪ t) := Filter.ext fun u => by simp only [union_subset_iff, mem_sup, mem_principal] @[simp] theorem iSup_principal {ι : Sort w} {s : ι → Set α} : ⨆ x, 𝓟 (s x) = 𝓟 (⋃ i, s i) := Filter.ext fun x => by simp only [mem_iSup, mem_principal, iUnion_subset_iff] @[simp] theorem principal_eq_bot_iff {s : Set α} : 𝓟 s = ⊥ ↔ s = ∅ := empty_mem_iff_bot.symm.trans <| mem_principal.trans subset_empty_iff @[simp] theorem principal_neBot_iff {s : Set α} : NeBot (𝓟 s) ↔ s.Nonempty := neBot_iff.trans <| (not_congr principal_eq_bot_iff).trans nonempty_iff_ne_empty.symm alias ⟨_, _root_.Set.Nonempty.principal_neBot⟩ := principal_neBot_iff theorem isCompl_principal (s : Set α) : IsCompl (𝓟 s) (𝓟 sᶜ) := IsCompl.of_eq (by rw [inf_principal, inter_compl_self, principal_empty]) <| by rw [sup_principal, union_compl_self, principal_univ] theorem mem_inf_principal' {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ tᶜ ∪ s ∈ f := by simp only [← le_principal_iff, (isCompl_principal s).le_left_iff, disjoint_assoc, inf_principal, ← (isCompl_principal (t ∩ sᶜ)).le_right_iff, compl_inter, compl_compl] lemma mem_inf_principal {f : Filter α} {s t : Set α} : s ∈ f ⊓ 𝓟 t ↔ { x | x ∈ t → x ∈ s } ∈ f := by simp only [mem_inf_principal', imp_iff_not_or, setOf_or, compl_def, setOf_mem_eq] lemma iSup_inf_principal (f : ι → Filter α) (s : Set α) : ⨆ i, f i ⊓ 𝓟 s = (⨆ i, f i) ⊓ 𝓟 s := by ext simp only [mem_iSup, mem_inf_principal] theorem inf_principal_eq_bot {f : Filter α} {s : Set α} : f ⊓ 𝓟 s = ⊥ ↔ sᶜ ∈ f := by rw [← empty_mem_iff_bot, mem_inf_principal] simp only [mem_empty_iff_false, imp_false, compl_def] theorem mem_of_eq_bot {f : Filter α} {s : Set α} (h : f ⊓ 𝓟 sᶜ = ⊥) : s ∈ f := by rwa [inf_principal_eq_bot, compl_compl] at h theorem diff_mem_inf_principal_compl {f : Filter α} {s : Set α} (hs : s ∈ f) (t : Set α) : s \ t ∈ f ⊓ 𝓟 tᶜ := inter_mem_inf hs <| mem_principal_self tᶜ theorem principal_le_iff {s : Set α} {f : Filter α} : 𝓟 s ≤ f ↔ ∀ V ∈ f, s ⊆ V := by simp_rw [le_def, mem_principal] end Lattice @[mono, gcongr] theorem join_mono {f₁ f₂ : Filter (Filter α)} (h : f₁ ≤ f₂) : join f₁ ≤ join f₂ := fun _ hs => h hs /-! ### Eventually -/ theorem eventually_iff {f : Filter α} {P : α → Prop} : (∀ᶠ x in f, P x) ↔ { x | P x } ∈ f := Iff.rfl @[simp] theorem eventually_mem_set {s : Set α} {l : Filter α} : (∀ᶠ x in l, x ∈ s) ↔ s ∈ l := Iff.rfl protected theorem ext' {f₁ f₂ : Filter α} (h : ∀ p : α → Prop, (∀ᶠ x in f₁, p x) ↔ ∀ᶠ x in f₂, p x) : f₁ = f₂ := Filter.ext h theorem Eventually.filter_mono {f₁ f₂ : Filter α} (h : f₁ ≤ f₂) {p : α → Prop} (hp : ∀ᶠ x in f₂, p x) : ∀ᶠ x in f₁, p x := h hp theorem eventually_of_mem {f : Filter α} {P : α → Prop} {U : Set α} (hU : U ∈ f) (h : ∀ x ∈ U, P x) : ∀ᶠ x in f, P x := mem_of_superset hU h protected theorem Eventually.and {p q : α → Prop} {f : Filter α} : f.Eventually p → f.Eventually q → ∀ᶠ x in f, p x ∧ q x := inter_mem @[simp] theorem eventually_true (f : Filter α) : ∀ᶠ _ in f, True := univ_mem theorem Eventually.of_forall {p : α → Prop} {f : Filter α} (hp : ∀ x, p x) : ∀ᶠ x in f, p x := univ_mem' hp @[simp] theorem eventually_false_iff_eq_bot {f : Filter α} : (∀ᶠ _ in f, False) ↔ f = ⊥ := empty_mem_iff_bot @[simp] theorem eventually_const {f : Filter α} [t : NeBot f] {p : Prop} : (∀ᶠ _ in f, p) ↔ p := by by_cases h : p <;> simp [h, t.ne] theorem eventually_iff_exists_mem {p : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x) ↔ ∃ v ∈ f, ∀ y ∈ v, p y := exists_mem_subset_iff.symm theorem Eventually.exists_mem {p : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) : ∃ v ∈ f, ∀ y ∈ v, p y := eventually_iff_exists_mem.1 hp theorem Eventually.mp {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ᶠ x in f, p x → q x) : ∀ᶠ x in f, q x := mp_mem hp hq theorem Eventually.mono {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∀ x, p x → q x) : ∀ᶠ x in f, q x := hp.mp (Eventually.of_forall hq) theorem forall_eventually_of_eventually_forall {f : Filter α} {p : α → β → Prop} (h : ∀ᶠ x in f, ∀ y, p x y) : ∀ y, ∀ᶠ x in f, p x y := fun y => h.mono fun _ h => h y @[simp] theorem eventually_and {p q : α → Prop} {f : Filter α} : (∀ᶠ x in f, p x ∧ q x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in f, q x := inter_mem_iff theorem Eventually.congr {f : Filter α} {p q : α → Prop} (h' : ∀ᶠ x in f, p x) (h : ∀ᶠ x in f, p x ↔ q x) : ∀ᶠ x in f, q x := h'.mp (h.mono fun _ hx => hx.mp) theorem eventually_congr {f : Filter α} {p q : α → Prop} (h : ∀ᶠ x in f, p x ↔ q x) : (∀ᶠ x in f, p x) ↔ ∀ᶠ x in f, q x := ⟨fun hp => hp.congr h, fun hq => hq.congr <| by simpa only [Iff.comm] using h⟩ @[simp] theorem eventually_or_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p ∨ q x) ↔ p ∨ ∀ᶠ x in f, q x := by_cases (fun h : p => by simp [h]) fun h => by simp [h] @[simp] theorem eventually_or_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x ∨ q) ↔ (∀ᶠ x in f, p x) ∨ q := by simp only [@or_comm _ q, eventually_or_distrib_left] theorem eventually_imp_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∀ᶠ x in f, p → q x) ↔ p → ∀ᶠ x in f, q x := by simp only [imp_iff_not_or, eventually_or_distrib_left] @[simp] theorem eventually_bot {p : α → Prop} : ∀ᶠ x in ⊥, p x := ⟨⟩ @[simp] theorem eventually_top {p : α → Prop} : (∀ᶠ x in ⊤, p x) ↔ ∀ x, p x := Iff.rfl @[simp] theorem eventually_sup {p : α → Prop} {f g : Filter α} : (∀ᶠ x in f ⊔ g, p x) ↔ (∀ᶠ x in f, p x) ∧ ∀ᶠ x in g, p x := Iff.rfl @[simp] theorem eventually_sSup {p : α → Prop} {fs : Set (Filter α)} : (∀ᶠ x in sSup fs, p x) ↔ ∀ f ∈ fs, ∀ᶠ x in f, p x := Iff.rfl @[simp] theorem eventually_iSup {p : α → Prop} {fs : ι → Filter α} : (∀ᶠ x in ⨆ b, fs b, p x) ↔ ∀ b, ∀ᶠ x in fs b, p x := mem_iSup @[simp] theorem eventually_principal {a : Set α} {p : α → Prop} : (∀ᶠ x in 𝓟 a, p x) ↔ ∀ x ∈ a, p x := Iff.rfl theorem Eventually.forall_mem {α : Type*} {f : Filter α} {s : Set α} {P : α → Prop} (hP : ∀ᶠ x in f, P x) (hf : 𝓟 s ≤ f) : ∀ x ∈ s, P x := Filter.eventually_principal.mp (hP.filter_mono hf) theorem eventually_inf {f g : Filter α} {p : α → Prop} : (∀ᶠ x in f ⊓ g, p x) ↔ ∃ s ∈ f, ∃ t ∈ g, ∀ x ∈ s ∩ t, p x := mem_inf_iff_superset theorem eventually_inf_principal {f : Filter α} {p : α → Prop} {s : Set α} : (∀ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∀ᶠ x in f, x ∈ s → p x := mem_inf_principal theorem eventually_iff_all_subsets {f : Filter α} {p : α → Prop} : (∀ᶠ x in f, p x) ↔ ∀ (s : Set α), ∀ᶠ x in f, x ∈ s → p x where mp h _ := by filter_upwards [h] with _ pa _ using pa mpr h := by filter_upwards [h univ] with _ pa using pa (by simp) /-! ### Frequently -/ theorem Eventually.frequently {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ᶠ x in f, p x) : ∃ᶠ x in f, p x := compl_not_mem h theorem Frequently.of_forall {f : Filter α} [NeBot f] {p : α → Prop} (h : ∀ x, p x) : ∃ᶠ x in f, p x := Eventually.frequently (Eventually.of_forall h) theorem Frequently.mp {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ᶠ x in f, p x → q x) : ∃ᶠ x in f, q x := mt (fun hq => hq.mp <| hpq.mono fun _ => mt) h lemma frequently_congr {p q : α → Prop} {f : Filter α} (h : ∀ᶠ x in f, p x ↔ q x) : (∃ᶠ x in f, p x) ↔ ∃ᶠ x in f, q x := ⟨fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mp), fun h' ↦ h'.mp (h.mono fun _ ↦ Iff.mpr)⟩ theorem Frequently.filter_mono {p : α → Prop} {f g : Filter α} (h : ∃ᶠ x in f, p x) (hle : f ≤ g) : ∃ᶠ x in g, p x := mt (fun h' => h'.filter_mono hle) h theorem Frequently.mono {p q : α → Prop} {f : Filter α} (h : ∃ᶠ x in f, p x) (hpq : ∀ x, p x → q x) : ∃ᶠ x in f, q x := h.mp (Eventually.of_forall hpq) theorem Frequently.and_eventually {p q : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) (hq : ∀ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by refine mt (fun h => hq.mp <| h.mono ?_) hp exact fun x hpq hq hp => hpq ⟨hp, hq⟩ theorem Eventually.and_frequently {p q : α → Prop} {f : Filter α} (hp : ∀ᶠ x in f, p x) (hq : ∃ᶠ x in f, q x) : ∃ᶠ x in f, p x ∧ q x := by simpa only [and_comm] using hq.and_eventually hp theorem Frequently.exists {p : α → Prop} {f : Filter α} (hp : ∃ᶠ x in f, p x) : ∃ x, p x := by by_contra H replace H : ∀ᶠ x in f, ¬p x := Eventually.of_forall (not_exists.1 H) exact hp H theorem Eventually.exists {p : α → Prop} {f : Filter α} [NeBot f] (hp : ∀ᶠ x in f, p x) : ∃ x, p x := hp.frequently.exists lemma frequently_iff_neBot {l : Filter α} {p : α → Prop} : (∃ᶠ x in l, p x) ↔ NeBot (l ⊓ 𝓟 {x | p x}) := by rw [neBot_iff, Ne, inf_principal_eq_bot]; rfl lemma frequently_mem_iff_neBot {l : Filter α} {s : Set α} : (∃ᶠ x in l, x ∈ s) ↔ NeBot (l ⊓ 𝓟 s) := frequently_iff_neBot theorem frequently_iff_forall_eventually_exists_and {p : α → Prop} {f : Filter α} : (∃ᶠ x in f, p x) ↔ ∀ {q : α → Prop}, (∀ᶠ x in f, q x) → ∃ x, p x ∧ q x := ⟨fun hp _ hq => (hp.and_eventually hq).exists, fun H hp => by simpa only [and_not_self_iff, exists_false] using H hp⟩ theorem frequently_iff {f : Filter α} {P : α → Prop} : (∃ᶠ x in f, P x) ↔ ∀ {U}, U ∈ f → ∃ x ∈ U, P x := by simp only [frequently_iff_forall_eventually_exists_and, @and_comm (P _)] rfl @[simp] theorem not_eventually {p : α → Prop} {f : Filter α} : (¬∀ᶠ x in f, p x) ↔ ∃ᶠ x in f, ¬p x := by simp [Filter.Frequently] @[simp] theorem not_frequently {p : α → Prop} {f : Filter α} : (¬∃ᶠ x in f, p x) ↔ ∀ᶠ x in f, ¬p x := by simp only [Filter.Frequently, not_not] @[simp] theorem frequently_true_iff_neBot (f : Filter α) : (∃ᶠ _ in f, True) ↔ NeBot f := by simp [frequently_iff_neBot] @[simp] theorem frequently_false (f : Filter α) : ¬∃ᶠ _ in f, False := by simp @[simp] theorem frequently_const {f : Filter α} [NeBot f] {p : Prop} : (∃ᶠ _ in f, p) ↔ p := by by_cases p <;> simp [*] @[simp] theorem frequently_or_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x ∨ q x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, ← not_and_or, not_or, eventually_and] theorem frequently_or_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∨ q x) ↔ p ∨ ∃ᶠ x in f, q x := by simp theorem frequently_or_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∨ q) ↔ (∃ᶠ x in f, p x) ∨ q := by simp theorem frequently_imp_distrib {f : Filter α} {p q : α → Prop} : (∃ᶠ x in f, p x → q x) ↔ (∀ᶠ x in f, p x) → ∃ᶠ x in f, q x := by simp [imp_iff_not_or] theorem frequently_imp_distrib_left {f : Filter α} [NeBot f] {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p → q x) ↔ p → ∃ᶠ x in f, q x := by simp [frequently_imp_distrib] theorem frequently_imp_distrib_right {f : Filter α} [NeBot f] {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x → q) ↔ (∀ᶠ x in f, p x) → q := by simp only [frequently_imp_distrib, frequently_const] theorem eventually_imp_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∀ᶠ x in f, p x → q) ↔ (∃ᶠ x in f, p x) → q := by simp only [imp_iff_not_or, eventually_or_distrib_right, not_frequently] @[simp] theorem frequently_and_distrib_left {f : Filter α} {p : Prop} {q : α → Prop} : (∃ᶠ x in f, p ∧ q x) ↔ p ∧ ∃ᶠ x in f, q x := by simp only [Filter.Frequently, not_and, eventually_imp_distrib_left, Classical.not_imp] @[simp] theorem frequently_and_distrib_right {f : Filter α} {p : α → Prop} {q : Prop} : (∃ᶠ x in f, p x ∧ q) ↔ (∃ᶠ x in f, p x) ∧ q := by simp only [@and_comm _ q, frequently_and_distrib_left] @[simp] theorem frequently_bot {p : α → Prop} : ¬∃ᶠ x in ⊥, p x := by simp @[simp] theorem frequently_top {p : α → Prop} : (∃ᶠ x in ⊤, p x) ↔ ∃ x, p x := by simp [Filter.Frequently] @[simp] theorem frequently_principal {a : Set α} {p : α → Prop} : (∃ᶠ x in 𝓟 a, p x) ↔ ∃ x ∈ a, p x := by simp [Filter.Frequently, not_forall] theorem frequently_inf_principal {f : Filter α} {s : Set α} {p : α → Prop} : (∃ᶠ x in f ⊓ 𝓟 s, p x) ↔ ∃ᶠ x in f, x ∈ s ∧ p x := by simp only [Filter.Frequently, eventually_inf_principal, not_and] alias ⟨Frequently.of_inf_principal, Frequently.inf_principal⟩ := frequently_inf_principal theorem frequently_sup {p : α → Prop} {f g : Filter α} : (∃ᶠ x in f ⊔ g, p x) ↔ (∃ᶠ x in f, p x) ∨ ∃ᶠ x in g, p x := by simp only [Filter.Frequently, eventually_sup, not_and_or] @[simp] theorem frequently_sSup {p : α → Prop} {fs : Set (Filter α)} : (∃ᶠ x in sSup fs, p x) ↔ ∃ f ∈ fs, ∃ᶠ x in f, p x := by simp only [Filter.Frequently, not_forall, eventually_sSup, exists_prop] @[simp] theorem frequently_iSup {p : α → Prop} {fs : β → Filter α} : (∃ᶠ x in ⨆ b, fs b, p x) ↔ ∃ b, ∃ᶠ x in fs b, p x := by simp only [Filter.Frequently, eventually_iSup, not_forall] theorem Eventually.choice {r : α → β → Prop} {l : Filter α} [l.NeBot] (h : ∀ᶠ x in l, ∃ y, r x y) : ∃ f : α → β, ∀ᶠ x in l, r x (f x) := by haveI : Nonempty β := let ⟨_, hx⟩ := h.exists; hx.nonempty choose! f hf using fun x (hx : ∃ y, r x y) => hx exact ⟨f, h.mono hf⟩ lemma skolem {ι : Type*} {α : ι → Type*} [∀ i, Nonempty (α i)] {P : ∀ i : ι, α i → Prop} {F : Filter ι} : (∀ᶠ i in F, ∃ b, P i b) ↔ ∃ b : (Π i, α i), ∀ᶠ i in F, P i (b i) := by classical refine ⟨fun H ↦ ?_, fun ⟨b, hb⟩ ↦ hb.mp (.of_forall fun x a ↦ ⟨_, a⟩)⟩
refine ⟨fun i ↦ if h : ∃ b, P i b then h.choose else Nonempty.some inferInstance, ?_⟩ filter_upwards [H] with i hi exact dif_pos hi ▸ hi.choose_spec
Mathlib/Order/Filter/Basic.lean
851
854
/- 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.Trigonometric.Inverse import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv /-! # derivatives of the inverse trigonometric functions Derivatives of `arcsin` and `arccos`. -/ noncomputable section open scoped Topology Filter Real ContDiff open Set namespace Real section Arcsin theorem deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : HasStrictDerivAt arcsin (1 / √(1 - x ^ 2)) x ∧ ContDiffAt ℝ ω arcsin x := by rcases h₁.lt_or_lt with h₁ | h₁ · have : 1 - x ^ 2 < 0 := by nlinarith [h₁] rw [sqrt_eq_zero'.2 this.le, div_zero] have : arcsin =ᶠ[𝓝 x] fun _ => -(π / 2) := (gt_mem_nhds h₁).mono fun y hy => arcsin_of_le_neg_one hy.le exact ⟨(hasStrictDerivAt_const x _).congr_of_eventuallyEq this.symm, contDiffAt_const.congr_of_eventuallyEq this⟩ rcases h₂.lt_or_lt with h₂ | h₂ · have : 0 < √(1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂]) simp only [← cos_arcsin, one_div] at this ⊢ exact ⟨sinPartialHomeomorph.hasStrictDerivAt_symm ⟨h₁, h₂⟩ this.ne' (hasStrictDerivAt_sin _), sinPartialHomeomorph.contDiffAt_symm_deriv this.ne' ⟨h₁, h₂⟩ (hasDerivAt_sin _) contDiff_sin.contDiffAt⟩ · have : 1 - x ^ 2 < 0 := by nlinarith [h₂] rw [sqrt_eq_zero'.2 this.le, div_zero] have : arcsin =ᶠ[𝓝 x] fun _ => π / 2 := (lt_mem_nhds h₂).mono fun y hy => arcsin_of_one_le hy.le exact ⟨(hasStrictDerivAt_const x _).congr_of_eventuallyEq this.symm, contDiffAt_const.congr_of_eventuallyEq this⟩ theorem hasStrictDerivAt_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : HasStrictDerivAt arcsin (1 / √(1 - x ^ 2)) x := (deriv_arcsin_aux h₁ h₂).1 theorem hasDerivAt_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) : HasDerivAt arcsin (1 / √(1 - x ^ 2)) x := (hasStrictDerivAt_arcsin h₁ h₂).hasDerivAt theorem contDiffAt_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : WithTop ℕ∞} : ContDiffAt ℝ n arcsin x := (deriv_arcsin_aux h₁ h₂).2.of_le le_top theorem hasDerivWithinAt_arcsin_Ici {x : ℝ} (h : x ≠ -1) : HasDerivWithinAt arcsin (1 / √(1 - x ^ 2)) (Ici x) x := by rcases eq_or_ne x 1 with (rfl | h') · convert (hasDerivWithinAt_const (1 : ℝ) _ (π / 2)).congr _ _ <;> simp +contextual [arcsin_of_one_le] · exact (hasDerivAt_arcsin h h').hasDerivWithinAt theorem hasDerivWithinAt_arcsin_Iic {x : ℝ} (h : x ≠ 1) : HasDerivWithinAt arcsin (1 / √(1 - x ^ 2)) (Iic x) x := by rcases em (x = -1) with (rfl | h') · convert (hasDerivWithinAt_const (-1 : ℝ) _ (-(π / 2))).congr _ _ <;> simp +contextual [arcsin_of_le_neg_one] · exact (hasDerivAt_arcsin h' h).hasDerivWithinAt theorem differentiableWithinAt_arcsin_Ici {x : ℝ} : DifferentiableWithinAt ℝ arcsin (Ici x) x ↔ x ≠ -1 := by refine ⟨?_, fun h => (hasDerivWithinAt_arcsin_Ici h).differentiableWithinAt⟩ rintro h rfl have : sin ∘ arcsin =ᶠ[𝓝[≥] (-1 : ℝ)] id := by filter_upwards [Icc_mem_nhdsGE (neg_lt_self zero_lt_one)] with x using sin_arcsin' have := h.hasDerivWithinAt.sin.congr_of_eventuallyEq this.symm (by simp) simpa using (uniqueDiffOn_Ici _ _ left_mem_Ici).eq_deriv _ this (hasDerivWithinAt_id _ _) theorem differentiableWithinAt_arcsin_Iic {x : ℝ} : DifferentiableWithinAt ℝ arcsin (Iic x) x ↔ x ≠ 1 := by refine ⟨fun h => ?_, fun h => (hasDerivWithinAt_arcsin_Iic h).differentiableWithinAt⟩ rw [← neg_neg x, ← image_neg_Ici] at h have := (h.comp (-x) differentiableWithinAt_id.neg (mapsTo_image _ _)).neg simpa [(· ∘ ·), differentiableWithinAt_arcsin_Ici] using this theorem differentiableAt_arcsin {x : ℝ} : DifferentiableAt ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 := ⟨fun h => ⟨differentiableWithinAt_arcsin_Ici.1 h.differentiableWithinAt, differentiableWithinAt_arcsin_Iic.1 h.differentiableWithinAt⟩, fun h => (hasDerivAt_arcsin h.1 h.2).differentiableAt⟩ @[simp] theorem deriv_arcsin : deriv arcsin = fun x => 1 / √(1 - x ^ 2) := by funext x by_cases h : x ≠ -1 ∧ x ≠ 1 · exact (hasDerivAt_arcsin h.1 h.2).deriv · rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_arcsin.1 h)] simp only [not_and_or, Ne, Classical.not_not] at h rcases h with (rfl | rfl) <;> simp theorem differentiableOn_arcsin : DifferentiableOn ℝ arcsin {-1, 1}ᶜ := fun _x hx => (differentiableAt_arcsin.2 ⟨fun h => hx (Or.inl h), fun h => hx (Or.inr h)⟩).differentiableWithinAt theorem contDiffOn_arcsin {n : WithTop ℕ∞} : ContDiffOn ℝ n arcsin {-1, 1}ᶜ := fun _x hx => (contDiffAt_arcsin (mt Or.inl hx) (mt Or.inr hx)).contDiffWithinAt
theorem contDiffAt_arcsin_iff {x : ℝ} {n : WithTop ℕ∞} : ContDiffAt ℝ n arcsin x ↔ n = 0 ∨ x ≠ -1 ∧ x ≠ 1 := ⟨fun h => or_iff_not_imp_left.2 fun hn => differentiableAt_arcsin.1 <| h.differentiableAt <| ENat.one_le_iff_ne_zero_withTop.mpr hn, fun h => h.elim (fun hn => hn.symm ▸ (contDiff_zero.2 continuous_arcsin).contDiffAt) fun hx => contDiffAt_arcsin hx.1 hx.2⟩
Mathlib/Analysis/SpecialFunctions/Trigonometric/InverseDeriv.lean
108
114
/- 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, Floris van Doorn -/ import Mathlib.Data.Countable.Small import Mathlib.Data.Fintype.BigOperators import Mathlib.Data.Fintype.Powerset import Mathlib.Data.Nat.Cast.Order.Basic import Mathlib.Data.Set.Countable import Mathlib.Logic.Equiv.Fin.Basic import Mathlib.Logic.Small.Set import Mathlib.Logic.UnivLE import Mathlib.SetTheory.Cardinal.Order /-! # Basic results on cardinal numbers We provide a collection of basic results on cardinal numbers, in particular focussing on finite/countable/small types and sets. ## Main definitions * `Cardinal.powerlt a b` or `a ^< b` is defined as the supremum of `a ^ c` for `c < b`. ## References * <https://en.wikipedia.org/wiki/Cardinal_number> ## Tags cardinal number, cardinal arithmetic, cardinal exponentiation, aleph, Cantor's theorem, König's theorem, Konig's theorem -/ assert_not_exists Field open List (Vector) open Function Order Set noncomputable section universe u v w v' w' variable {α β : Type u} namespace Cardinal /-! ### Lifting cardinals to a higher universe -/ @[simp] lemma mk_preimage_down {s : Set α} : #(ULift.down.{v} ⁻¹' s) = lift.{v} (#s) := by rw [← mk_uLift, Cardinal.eq] constructor let f : ULift.down ⁻¹' s → ULift s := fun x ↦ ULift.up (restrictPreimage s ULift.down x) have : Function.Bijective f := ULift.up_bijective.comp (restrictPreimage_bijective _ (ULift.down_bijective)) exact Equiv.ofBijective f this -- `simp` can't figure out universe levels: normal form is `lift_mk_shrink'`. theorem lift_mk_shrink (α : Type u) [Small.{v} α] : Cardinal.lift.{max u w} #(Shrink.{v} α) = Cardinal.lift.{max v w} #α := lift_mk_eq.2 ⟨(equivShrink α).symm⟩ @[simp] theorem lift_mk_shrink' (α : Type u) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = Cardinal.lift.{v} #α := lift_mk_shrink.{u, v, 0} α @[simp] theorem lift_mk_shrink'' (α : Type max u v) [Small.{v} α] : Cardinal.lift.{u} #(Shrink.{v} α) = #α := by rw [← lift_umax, lift_mk_shrink.{max u v, v, 0} α, ← lift_umax, lift_id] theorem prod_eq_of_fintype {α : Type u} [h : Fintype α] (f : α → Cardinal.{v}) : prod f = Cardinal.lift.{u} (∏ i, f i) := by revert f refine Fintype.induction_empty_option ?_ ?_ ?_ α (h_fintype := h) · intro α β hβ e h f letI := Fintype.ofEquiv β e.symm rw [← e.prod_comp f, ← h] exact mk_congr (e.piCongrLeft _).symm · intro f rw [Fintype.univ_pempty, Finset.prod_empty, lift_one, Cardinal.prod, mk_eq_one] · intro α hα h f rw [Cardinal.prod, mk_congr Equiv.piOptionEquivProd, mk_prod, lift_umax.{v, u}, mk_out, ← Cardinal.prod, lift_prod, Fintype.prod_option, lift_mul, ← h fun a => f (some a)] simp only [lift_id] /-! ### Basic cardinals -/ theorem le_one_iff_subsingleton {α : Type u} : #α ≤ 1 ↔ Subsingleton α := ⟨fun ⟨f⟩ => ⟨fun _ _ => f.injective (Subsingleton.elim _ _)⟩, fun ⟨h⟩ => ⟨fun _ => ULift.up 0, fun _ _ _ => h _ _⟩⟩ @[simp] theorem mk_le_one_iff_set_subsingleton {s : Set α} : #s ≤ 1 ↔ s.Subsingleton := le_one_iff_subsingleton.trans s.subsingleton_coe alias ⟨_, _root_.Set.Subsingleton.cardinalMk_le_one⟩ := mk_le_one_iff_set_subsingleton @[deprecated (since := "2024-11-10")] alias _root_.Set.Subsingleton.cardinal_mk_le_one := Set.Subsingleton.cardinalMk_le_one private theorem cast_succ (n : ℕ) : ((n + 1 : ℕ) : Cardinal.{u}) = n + 1 := by change #(ULift.{u} _) = #(ULift.{u} _) + 1 rw [← mk_option] simp /-! ### Order properties -/ theorem one_lt_iff_nontrivial {α : Type u} : 1 < #α ↔ Nontrivial α := by rw [← not_le, le_one_iff_subsingleton, ← not_nontrivial_iff_subsingleton, Classical.not_not] lemma sInf_eq_zero_iff {s : Set Cardinal} : sInf s = 0 ↔ s = ∅ ∨ ∃ a ∈ s, a = 0 := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases s.eq_empty_or_nonempty with rfl | hne · exact Or.inl rfl · exact Or.inr ⟨sInf s, csInf_mem hne, h⟩ · rcases h with rfl | ⟨a, ha, rfl⟩ · exact Cardinal.sInf_empty · exact eq_bot_iff.2 (csInf_le' ha) lemma iInf_eq_zero_iff {ι : Sort*} {f : ι → Cardinal} : (⨅ i, f i) = 0 ↔ IsEmpty ι ∨ ∃ i, f i = 0 := by simp [iInf, sInf_eq_zero_iff] /-- A variant of `ciSup_of_empty` but with `0` on the RHS for convenience -/ protected theorem iSup_of_empty {ι} (f : ι → Cardinal) [IsEmpty ι] : iSup f = 0 := ciSup_of_empty f @[simp] theorem lift_sInf (s : Set Cardinal) : lift.{u, v} (sInf s) = sInf (lift.{u, v} '' s) := by rcases eq_empty_or_nonempty s with (rfl | hs) · simp · exact lift_monotone.map_csInf hs @[simp] theorem lift_iInf {ι} (f : ι → Cardinal) : lift.{u, v} (iInf f) = ⨅ i, lift.{u, v} (f i) := by unfold iInf convert lift_sInf (range f) simp_rw [← comp_apply (f := lift), range_comp] end Cardinal /-! ### Small sets of cardinals -/ namespace Cardinal instance small_Iic (a : Cardinal.{u}) : Small.{u} (Iic a) := by rw [← mk_out a] apply @small_of_surjective (Set a.out) (Iic #a.out) _ fun x => ⟨#x, mk_set_le x⟩ rintro ⟨x, hx⟩ simpa using le_mk_iff_exists_set.1 hx instance small_Iio (a : Cardinal.{u}) : Small.{u} (Iio a) := small_subset Iio_subset_Iic_self instance small_Icc (a b : Cardinal.{u}) : Small.{u} (Icc a b) := small_subset Icc_subset_Iic_self instance small_Ico (a b : Cardinal.{u}) : Small.{u} (Ico a b) := small_subset Ico_subset_Iio_self instance small_Ioc (a b : Cardinal.{u}) : Small.{u} (Ioc a b) := small_subset Ioc_subset_Iic_self instance small_Ioo (a b : Cardinal.{u}) : Small.{u} (Ioo a b) := small_subset Ioo_subset_Iio_self /-- A set of cardinals is bounded above iff it's small, i.e. it corresponds to a usual ZFC set. -/ theorem bddAbove_iff_small {s : Set Cardinal.{u}} : BddAbove s ↔ Small.{u} s := ⟨fun ⟨a, ha⟩ => @small_subset _ (Iic a) s (fun _ h => ha h) _, by rintro ⟨ι, ⟨e⟩⟩ use sum.{u, u} fun x ↦ e.symm x intro a ha simpa using le_sum (fun x ↦ e.symm x) (e ⟨a, ha⟩)⟩ theorem bddAbove_of_small (s : Set Cardinal.{u}) [h : Small.{u} s] : BddAbove s := bddAbove_iff_small.2 h theorem bddAbove_range {ι : Type*} [Small.{u} ι] (f : ι → Cardinal.{u}) : BddAbove (Set.range f) := bddAbove_of_small _ theorem bddAbove_image (f : Cardinal.{u} → Cardinal.{max u v}) {s : Set Cardinal.{u}} (hs : BddAbove s) : BddAbove (f '' s) := by rw [bddAbove_iff_small] at hs ⊢ exact small_lift _ theorem bddAbove_range_comp {ι : Type u} {f : ι → Cardinal.{v}} (hf : BddAbove (range f)) (g : Cardinal.{v} → Cardinal.{max v w}) : BddAbove (range (g ∘ f)) := by rw [range_comp] exact bddAbove_image g hf /-- The type of cardinals in universe `u` is not `Small.{u}`. This is a version of the Burali-Forti paradox. -/ theorem _root_.not_small_cardinal : ¬ Small.{u} Cardinal.{max u v} := by intro h have := small_lift.{_, v} Cardinal.{max u v} rw [← small_univ_iff, ← bddAbove_iff_small] at this exact not_bddAbove_univ this instance uncountable : Uncountable Cardinal.{u} := Uncountable.of_not_small not_small_cardinal.{u} /-! ### Bounds on suprema -/ theorem sum_le_iSup_lift {ι : Type u} (f : ι → Cardinal.{max u v}) : sum f ≤ Cardinal.lift #ι * iSup f := by rw [← (iSup f).lift_id, ← lift_umax, lift_umax.{max u v, u}, ← sum_const] exact sum_le_sum _ _ (le_ciSup <| bddAbove_of_small _) theorem sum_le_iSup {ι : Type u} (f : ι → Cardinal.{u}) : sum f ≤ #ι * iSup f := by rw [← lift_id #ι] exact sum_le_iSup_lift f /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_sSup {s : Set Cardinal} (hs : BddAbove s) : lift.{u} (sSup s) = sSup (lift.{u} '' s) := by apply ((le_csSup_iff' (bddAbove_image.{_,u} _ hs)).2 fun c hc => _).antisymm (csSup_le' _) · intro c hc by_contra h obtain ⟨d, rfl⟩ := Cardinal.mem_range_lift_of_le (not_le.1 h).le simp_rw [lift_le] at h hc rw [csSup_le_iff' hs] at h exact h fun a ha => lift_le.1 <| hc (mem_image_of_mem _ ha) · rintro i ⟨j, hj, rfl⟩ exact lift_le.2 (le_csSup hs hj) /-- The lift of a supremum is the supremum of the lifts. -/ theorem lift_iSup {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) : lift.{u} (iSup f) = ⨆ i, lift.{u} (f i) := by rw [iSup, iSup, lift_sSup hf, ← range_comp] simp [Function.comp_def] /-- To prove that the lift of a supremum is bounded by some cardinal `t`, it suffices to show that the lift of each cardinal is bounded by `t`. -/ theorem lift_iSup_le {ι : Type v} {f : ι → Cardinal.{w}} {t : Cardinal} (hf : BddAbove (range f)) (w : ∀ i, lift.{u} (f i) ≤ t) : lift.{u} (iSup f) ≤ t := by rw [lift_iSup hf] exact ciSup_le' w @[simp] theorem lift_iSup_le_iff {ι : Type v} {f : ι → Cardinal.{w}} (hf : BddAbove (range f)) {t : Cardinal} : lift.{u} (iSup f) ≤ t ↔ ∀ i, lift.{u} (f i) ≤ t := by rw [lift_iSup hf] exact ciSup_le_iff' (bddAbove_range_comp.{_,_,u} hf _) /-- To prove an inequality between the lifts to a common universe of two different supremums, it suffices to show that the lift of each cardinal from the smaller supremum if bounded by the lift of some cardinal from the larger supremum. -/ theorem lift_iSup_le_lift_iSup {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{w}} {f' : ι' → Cardinal.{w'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) {g : ι → ι'} (h : ∀ i, lift.{w'} (f i) ≤ lift.{w} (f' (g i))) : lift.{w'} (iSup f) ≤ lift.{w} (iSup f') := by rw [lift_iSup hf, lift_iSup hf'] exact ciSup_mono' (bddAbove_range_comp.{_,_,w} hf' _) fun i => ⟨_, h i⟩ /-- A variant of `lift_iSup_le_lift_iSup` with universes specialized via `w = v` and `w' = v'`. This is sometimes necessary to avoid universe unification issues. -/ theorem lift_iSup_le_lift_iSup' {ι : Type v} {ι' : Type v'} {f : ι → Cardinal.{v}} {f' : ι' → Cardinal.{v'}} (hf : BddAbove (range f)) (hf' : BddAbove (range f')) (g : ι → ι') (h : ∀ i, lift.{v'} (f i) ≤ lift.{v} (f' (g i))) : lift.{v'} (iSup f) ≤ lift.{v} (iSup f') := lift_iSup_le_lift_iSup hf hf' h /-! ### Properties about the cast from `ℕ` -/ theorem mk_finset_of_fintype [Fintype α] : #(Finset α) = 2 ^ Fintype.card α := by simp [Pow.pow] @[norm_cast] theorem nat_succ (n : ℕ) : (n.succ : Cardinal) = succ ↑n := by rw [Nat.cast_succ] refine (add_one_le_succ _).antisymm (succ_le_of_lt ?_) rw [← Nat.cast_succ] exact Nat.cast_lt.2 (Nat.lt_succ_self _) lemma succ_natCast (n : ℕ) : Order.succ (n : Cardinal) = n + 1 := by rw [← Cardinal.nat_succ] norm_cast lemma natCast_add_one_le_iff {n : ℕ} {c : Cardinal} : n + 1 ≤ c ↔ n < c := by rw [← Order.succ_le_iff, Cardinal.succ_natCast] lemma two_le_iff_one_lt {c : Cardinal} : 2 ≤ c ↔ 1 < c := by convert natCast_add_one_le_iff norm_cast @[simp] theorem succ_zero : succ (0 : Cardinal) = 1 := by norm_cast -- This works generally to prove inequalities between numeric cardinals. theorem one_lt_two : (1 : Cardinal) < 2 := by norm_cast theorem exists_finset_le_card (α : Type*) (n : ℕ) (h : n ≤ #α) : ∃ s : Finset α, n ≤ s.card := by obtain hα|hα := finite_or_infinite α · let hα := Fintype.ofFinite α use Finset.univ simpa only [mk_fintype, Nat.cast_le] using h · obtain ⟨s, hs⟩ := Infinite.exists_subset_card_eq α n exact ⟨s, hs.ge⟩ theorem card_le_of {α : Type u} {n : ℕ} (H : ∀ s : Finset α, s.card ≤ n) : #α ≤ n := by contrapose! H apply exists_finset_le_card α (n+1) simpa only [nat_succ, succ_le_iff] using H theorem cantor' (a) {b : Cardinal} (hb : 1 < b) : a < b ^ a := by rw [← succ_le_iff, (by norm_cast : succ (1 : Cardinal) = 2)] at hb exact (cantor a).trans_le (power_le_power_right hb) theorem one_le_iff_pos {c : Cardinal} : 1 ≤ c ↔ 0 < c := by rw [← succ_zero, succ_le_iff] theorem one_le_iff_ne_zero {c : Cardinal} : 1 ≤ c ↔ c ≠ 0 := by rw [one_le_iff_pos, pos_iff_ne_zero] @[simp] theorem lt_one_iff_zero {c : Cardinal} : c < 1 ↔ c = 0 := by simpa using lt_succ_bot_iff (a := c) /-! ### Properties about `aleph0` -/ theorem nat_lt_aleph0 (n : ℕ) : (n : Cardinal.{u}) < ℵ₀ := succ_le_iff.1 (by rw [← nat_succ, ← lift_mk_fin, aleph0, lift_mk_le.{u}] exact ⟨⟨(↑), fun a b => Fin.ext⟩⟩) @[simp] theorem one_lt_aleph0 : 1 < ℵ₀ := by simpa using nat_lt_aleph0 1 @[simp] theorem one_le_aleph0 : 1 ≤ ℵ₀ := one_lt_aleph0.le theorem lt_aleph0 {c : Cardinal} : c < ℵ₀ ↔ ∃ n : ℕ, c = n := ⟨fun h => by rcases lt_lift_iff.1 h with ⟨c, h', rfl⟩ rcases le_mk_iff_exists_set.1 h'.1 with ⟨S, rfl⟩ suffices S.Finite by lift S to Finset ℕ using this simp contrapose! h' haveI := Infinite.to_subtype h' exact ⟨Infinite.natEmbedding S⟩, fun ⟨_, e⟩ => e.symm ▸ nat_lt_aleph0 _⟩ lemma succ_eq_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : Order.succ c = c + 1 := by obtain ⟨n, hn⟩ := Cardinal.lt_aleph0.mp h rw [hn, succ_natCast] theorem aleph0_le {c : Cardinal} : ℵ₀ ≤ c ↔ ∀ n : ℕ, ↑n ≤ c := ⟨fun h _ => (nat_lt_aleph0 _).le.trans h, fun h => le_of_not_lt fun hn => by rcases lt_aleph0.1 hn with ⟨n, rfl⟩ exact (Nat.lt_succ_self _).not_le (Nat.cast_le.1 (h (n + 1)))⟩ theorem isSuccPrelimit_aleph0 : IsSuccPrelimit ℵ₀ := isSuccPrelimit_of_succ_lt fun a ha => by rcases lt_aleph0.1 ha with ⟨n, rfl⟩ rw [← nat_succ] apply nat_lt_aleph0 theorem isSuccLimit_aleph0 : IsSuccLimit ℵ₀ := by rw [Cardinal.isSuccLimit_iff] exact ⟨aleph0_ne_zero, isSuccPrelimit_aleph0⟩ lemma not_isSuccLimit_natCast : (n : ℕ) → ¬ IsSuccLimit (n : Cardinal.{u}) | 0, e => e.1 isMin_bot | Nat.succ n, e => Order.not_isSuccPrelimit_succ _ (nat_succ n ▸ e.2) theorem not_isSuccLimit_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ¬ IsSuccLimit c := by obtain ⟨n, rfl⟩ := lt_aleph0.1 h exact not_isSuccLimit_natCast n theorem aleph0_le_of_isSuccLimit {c : Cardinal} (h : IsSuccLimit c) : ℵ₀ ≤ c := by contrapose! h exact not_isSuccLimit_of_lt_aleph0 h theorem isStrongLimit_aleph0 : IsStrongLimit ℵ₀ := by refine ⟨aleph0_ne_zero, fun x hx ↦ ?_⟩ obtain ⟨n, rfl⟩ := lt_aleph0.1 hx exact_mod_cast nat_lt_aleph0 _ theorem IsStrongLimit.aleph0_le {c} (H : IsStrongLimit c) : ℵ₀ ≤ c := aleph0_le_of_isSuccLimit H.isSuccLimit lemma exists_eq_natCast_of_iSup_eq {ι : Type u} [Nonempty ι] (f : ι → Cardinal.{v}) (hf : BddAbove (range f)) (n : ℕ) (h : ⨆ i, f i = n) : ∃ i, f i = n := exists_eq_of_iSup_eq_of_not_isSuccLimit.{u, v} f hf (not_isSuccLimit_natCast n) h @[simp] theorem range_natCast : range ((↑) : ℕ → Cardinal) = Iio ℵ₀ := ext fun x => by simp only [mem_Iio, mem_range, eq_comm, lt_aleph0] theorem mk_eq_nat_iff {α : Type u} {n : ℕ} : #α = n ↔ Nonempty (α ≃ Fin n) := by rw [← lift_mk_fin, ← lift_uzero #α, lift_mk_eq'] theorem lt_aleph0_iff_finite {α : Type u} : #α < ℵ₀ ↔ Finite α := by simp only [lt_aleph0, mk_eq_nat_iff, finite_iff_exists_equiv_fin] theorem lt_aleph0_iff_fintype {α : Type u} : #α < ℵ₀ ↔ Nonempty (Fintype α) := lt_aleph0_iff_finite.trans (finite_iff_nonempty_fintype _) theorem lt_aleph0_of_finite (α : Type u) [Finite α] : #α < ℵ₀ := lt_aleph0_iff_finite.2 ‹_› theorem lt_aleph0_iff_set_finite {S : Set α} : #S < ℵ₀ ↔ S.Finite := lt_aleph0_iff_finite.trans finite_coe_iff alias ⟨_, _root_.Set.Finite.lt_aleph0⟩ := lt_aleph0_iff_set_finite @[simp] theorem lt_aleph0_iff_subtype_finite {p : α → Prop} : #{ x // p x } < ℵ₀ ↔ { x | p x }.Finite := lt_aleph0_iff_set_finite theorem mk_le_aleph0_iff : #α ≤ ℵ₀ ↔ Countable α := by rw [countable_iff_nonempty_embedding, aleph0, ← lift_uzero #α, lift_mk_le'] @[simp] theorem mk_le_aleph0 [Countable α] : #α ≤ ℵ₀ := mk_le_aleph0_iff.mpr ‹_› theorem le_aleph0_iff_set_countable {s : Set α} : #s ≤ ℵ₀ ↔ s.Countable := mk_le_aleph0_iff alias ⟨_, _root_.Set.Countable.le_aleph0⟩ := le_aleph0_iff_set_countable @[simp] theorem le_aleph0_iff_subtype_countable {p : α → Prop} : #{ x // p x } ≤ ℵ₀ ↔ { x | p x }.Countable := le_aleph0_iff_set_countable theorem aleph0_lt_mk_iff : ℵ₀ < #α ↔ Uncountable α := by rw [← not_le, ← not_countable_iff, not_iff_not, mk_le_aleph0_iff] @[simp] theorem aleph0_lt_mk [Uncountable α] : ℵ₀ < #α := aleph0_lt_mk_iff.mpr ‹_› instance canLiftCardinalNat : CanLift Cardinal ℕ (↑) fun x => x < ℵ₀ := ⟨fun _ hx => let ⟨n, hn⟩ := lt_aleph0.mp hx ⟨n, hn.symm⟩⟩ theorem add_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a + b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_add]; apply nat_lt_aleph0 theorem add_lt_aleph0_iff {a b : Cardinal} : a + b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := ⟨fun h => ⟨(self_le_add_right _ _).trans_lt h, (self_le_add_left _ _).trans_lt h⟩, fun ⟨h1, h2⟩ => add_lt_aleph0 h1 h2⟩ theorem aleph0_le_add_iff {a b : Cardinal} : ℵ₀ ≤ a + b ↔ ℵ₀ ≤ a ∨ ℵ₀ ≤ b := by simp only [← not_lt, add_lt_aleph0_iff, not_and_or] /-- See also `Cardinal.nsmul_lt_aleph0_iff_of_ne_zero` if you already have `n ≠ 0`. -/ theorem nsmul_lt_aleph0_iff {n : ℕ} {a : Cardinal} : n • a < ℵ₀ ↔ n = 0 ∨ a < ℵ₀ := by cases n with | zero => simpa using nat_lt_aleph0 0 | succ n => simp only [Nat.succ_ne_zero, false_or] induction' n with n ih · simp rw [succ_nsmul, add_lt_aleph0_iff, ih, and_self_iff] /-- See also `Cardinal.nsmul_lt_aleph0_iff` for a hypothesis-free version. -/ theorem nsmul_lt_aleph0_iff_of_ne_zero {n : ℕ} {a : Cardinal} (h : n ≠ 0) : n • a < ℵ₀ ↔ a < ℵ₀ := nsmul_lt_aleph0_iff.trans <| or_iff_right h theorem mul_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a * b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [← Nat.cast_mul]; apply nat_lt_aleph0 theorem mul_lt_aleph0_iff {a b : Cardinal} : a * b < ℵ₀ ↔ a = 0 ∨ b = 0 ∨ a < ℵ₀ ∧ b < ℵ₀ := by refine ⟨fun h => ?_, ?_⟩ · by_cases ha : a = 0 · exact Or.inl ha right by_cases hb : b = 0 · exact Or.inl hb right rw [← Ne, ← one_le_iff_ne_zero] at ha hb constructor · rw [← mul_one a] exact (mul_le_mul' le_rfl hb).trans_lt h · rw [← one_mul b] exact (mul_le_mul' ha le_rfl).trans_lt h rintro (rfl | rfl | ⟨ha, hb⟩) <;> simp only [*, mul_lt_aleph0, aleph0_pos, zero_mul, mul_zero] /-- See also `Cardinal.aleph0_le_mul_iff`. -/ theorem aleph0_le_mul_iff {a b : Cardinal} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ b ≠ 0 ∧ (ℵ₀ ≤ a ∨ ℵ₀ ≤ b) := by let h := (@mul_lt_aleph0_iff a b).not rwa [not_lt, not_or, not_or, not_and_or, not_lt, not_lt] at h /-- See also `Cardinal.aleph0_le_mul_iff'`. -/ theorem aleph0_le_mul_iff' {a b : Cardinal.{u}} : ℵ₀ ≤ a * b ↔ a ≠ 0 ∧ ℵ₀ ≤ b ∨ ℵ₀ ≤ a ∧ b ≠ 0 := by have : ∀ {a : Cardinal.{u}}, ℵ₀ ≤ a → a ≠ 0 := fun a => ne_bot_of_le_ne_bot aleph0_ne_zero a simp only [aleph0_le_mul_iff, and_or_left, and_iff_right_of_imp this, @and_left_comm (a ≠ 0)] simp only [and_comm, or_comm] theorem mul_lt_aleph0_iff_of_ne_zero {a b : Cardinal} (ha : a ≠ 0) (hb : b ≠ 0) : a * b < ℵ₀ ↔ a < ℵ₀ ∧ b < ℵ₀ := by simp [mul_lt_aleph0_iff, ha, hb] theorem power_lt_aleph0 {a b : Cardinal} (ha : a < ℵ₀) (hb : b < ℵ₀) : a ^ b < ℵ₀ := match a, b, lt_aleph0.1 ha, lt_aleph0.1 hb with | _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ => by rw [power_natCast, ← Nat.cast_pow]; apply nat_lt_aleph0 theorem eq_one_iff_unique {α : Type*} : #α = 1 ↔ Subsingleton α ∧ Nonempty α := calc #α = 1 ↔ #α ≤ 1 ∧ 1 ≤ #α := le_antisymm_iff _ ↔ Subsingleton α ∧ Nonempty α := le_one_iff_subsingleton.and (one_le_iff_ne_zero.trans mk_ne_zero_iff) theorem infinite_iff {α : Type u} : Infinite α ↔ ℵ₀ ≤ #α := by rw [← not_lt, lt_aleph0_iff_finite, not_finite_iff_infinite] lemma aleph0_le_mk_iff : ℵ₀ ≤ #α ↔ Infinite α := infinite_iff.symm lemma mk_lt_aleph0_iff : #α < ℵ₀ ↔ Finite α := by simp [← not_le, aleph0_le_mk_iff] @[simp] lemma mk_lt_aleph0 [Finite α] : #α < ℵ₀ := mk_lt_aleph0_iff.2 ‹_› @[simp] theorem aleph0_le_mk (α : Type u) [Infinite α] : ℵ₀ ≤ #α := infinite_iff.1 ‹_› @[simp] theorem mk_eq_aleph0 (α : Type*) [Countable α] [Infinite α] : #α = ℵ₀ := mk_le_aleph0.antisymm <| aleph0_le_mk _ theorem denumerable_iff {α : Type u} : Nonempty (Denumerable α) ↔ #α = ℵ₀ := ⟨fun ⟨h⟩ => mk_congr ((@Denumerable.eqv α h).trans Equiv.ulift.symm), fun h => by obtain ⟨f⟩ := Quotient.exact h exact ⟨Denumerable.mk' <| f.trans Equiv.ulift⟩⟩ theorem mk_denumerable (α : Type u) [Denumerable α] : #α = ℵ₀ := denumerable_iff.1 ⟨‹_›⟩ theorem _root_.Set.countable_infinite_iff_nonempty_denumerable {α : Type*} {s : Set α} : s.Countable ∧ s.Infinite ↔ Nonempty (Denumerable s) := by rw [nonempty_denumerable_iff, ← Set.infinite_coe_iff, countable_coe_iff] @[simp] theorem aleph0_add_aleph0 : ℵ₀ + ℵ₀ = ℵ₀ := mk_denumerable _ theorem aleph0_mul_aleph0 : ℵ₀ * ℵ₀ = ℵ₀ := mk_denumerable _ @[simp] theorem nat_mul_aleph0 {n : ℕ} (hn : n ≠ 0) : ↑n * ℵ₀ = ℵ₀ := le_antisymm (lift_mk_fin n ▸ mk_le_aleph0) <| le_mul_of_one_le_left (zero_le _) <| by rwa [← Nat.cast_one, Nat.cast_le, Nat.one_le_iff_ne_zero] @[simp] theorem aleph0_mul_nat {n : ℕ} (hn : n ≠ 0) : ℵ₀ * n = ℵ₀ := by rw [mul_comm, nat_mul_aleph0 hn] @[simp] theorem ofNat_mul_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) * ℵ₀ = ℵ₀ := nat_mul_aleph0 (NeZero.ne n) @[simp] theorem aleph0_mul_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ * ofNat(n) = ℵ₀ := aleph0_mul_nat (NeZero.ne n) @[simp] theorem add_le_aleph0 {c₁ c₂ : Cardinal} : c₁ + c₂ ≤ ℵ₀ ↔ c₁ ≤ ℵ₀ ∧ c₂ ≤ ℵ₀ := ⟨fun h => ⟨le_self_add.trans h, le_add_self.trans h⟩, fun h => aleph0_add_aleph0 ▸ add_le_add h.1 h.2⟩ @[simp] theorem aleph0_add_nat (n : ℕ) : ℵ₀ + n = ℵ₀ := (add_le_aleph0.2 ⟨le_rfl, (nat_lt_aleph0 n).le⟩).antisymm le_self_add @[simp] theorem nat_add_aleph0 (n : ℕ) : ↑n + ℵ₀ = ℵ₀ := by rw [add_comm, aleph0_add_nat] @[simp] theorem ofNat_add_aleph0 {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) + ℵ₀ = ℵ₀ := nat_add_aleph0 n @[simp] theorem aleph0_add_ofNat {n : ℕ} [Nat.AtLeastTwo n] : ℵ₀ + ofNat(n) = ℵ₀ := aleph0_add_nat n theorem exists_nat_eq_of_le_nat {c : Cardinal} {n : ℕ} (h : c ≤ n) : ∃ m, m ≤ n ∧ c = m := by lift c to ℕ using h.trans_lt (nat_lt_aleph0 _) exact ⟨c, mod_cast h, rfl⟩ theorem mk_int : #ℤ = ℵ₀ := mk_denumerable ℤ theorem mk_pnat : #ℕ+ = ℵ₀ := mk_denumerable ℕ+ @[deprecated (since := "2025-04-27")] alias mk_pNat := mk_pnat /-! ### Cardinalities of basic sets and types -/ @[simp] theorem mk_additive : #(Additive α) = #α := rfl @[simp] theorem mk_multiplicative : #(Multiplicative α) = #α := rfl @[to_additive (attr := simp)] theorem mk_mulOpposite : #(MulOpposite α) = #α := mk_congr MulOpposite.opEquiv.symm theorem mk_singleton {α : Type u} (x : α) : #({x} : Set α) = 1 := mk_eq_one _ @[simp] theorem mk_vector (α : Type u) (n : ℕ) : #(List.Vector α n) = #α ^ n := (mk_congr (Equiv.vectorEquivFin α n)).trans <| by simp theorem mk_list_eq_sum_pow (α : Type u) : #(List α) = sum fun n : ℕ => #α ^ n := calc #(List α) = #(Σn, List.Vector α n) := mk_congr (Equiv.sigmaFiberEquiv List.length).symm _ = sum fun n : ℕ => #α ^ n := by simp theorem mk_quot_le {α : Type u} {r : α → α → Prop} : #(Quot r) ≤ #α := mk_le_of_surjective Quot.exists_rep theorem mk_quotient_le {α : Type u} {s : Setoid α} : #(Quotient s) ≤ #α := mk_quot_le theorem mk_subtype_le_of_subset {α : Type u} {p q : α → Prop} (h : ∀ ⦃x⦄, p x → q x) : #(Subtype p) ≤ #(Subtype q) := ⟨Embedding.subtypeMap (Embedding.refl α) h⟩ theorem mk_emptyCollection (α : Type u) : #(∅ : Set α) = 0 := mk_eq_zero _ theorem mk_emptyCollection_iff {α : Type u} {s : Set α} : #s = 0 ↔ s = ∅ := by constructor · intro h rw [mk_eq_zero_iff] at h exact eq_empty_iff_forall_not_mem.2 fun x hx => h.elim' ⟨x, hx⟩ · rintro rfl exact mk_emptyCollection _ @[simp] theorem mk_univ {α : Type u} : #(@univ α) = #α := mk_congr (Equiv.Set.univ α) @[simp] lemma mk_setProd {α β : Type u} (s : Set α) (t : Set β) : #(s ×ˢ t) = #s * #t := by rw [mul_def, mk_congr (Equiv.Set.prod ..)] theorem mk_image_le {α β : Type u} {f : α → β} {s : Set α} : #(f '' s) ≤ #s := mk_le_of_surjective surjective_onto_image lemma mk_image2_le {α β γ : Type u} {f : α → β → γ} {s : Set α} {t : Set β} : #(image2 f s t) ≤ #s * #t := by rw [← image_uncurry_prod, ← mk_setProd] exact mk_image_le theorem mk_image_le_lift {α : Type u} {β : Type v} {f : α → β} {s : Set α} : lift.{u} #(f '' s) ≤ lift.{v} #s := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_image⟩ theorem mk_range_le {α β : Type u} {f : α → β} : #(range f) ≤ #α := mk_le_of_surjective surjective_onto_range theorem mk_range_le_lift {α : Type u} {β : Type v} {f : α → β} : lift.{u} #(range f) ≤ lift.{v} #α := lift_mk_le.{0}.mpr ⟨Embedding.ofSurjective _ surjective_onto_range⟩ theorem mk_range_eq (f : α → β) (h : Injective f) : #(range f) = #α := mk_congr (Equiv.ofInjective f h).symm theorem mk_range_eq_lift {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{max u w} #(range f) = lift.{max v w} #α := lift_mk_eq.{v,u,w}.mpr ⟨(Equiv.ofInjective f hf).symm⟩ theorem mk_range_eq_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : lift.{u} #(range f) = lift.{v} #α := lift_mk_eq'.mpr ⟨(Equiv.ofInjective f hf).symm⟩ lemma lift_mk_le_lift_mk_of_injective {α : Type u} {β : Type v} {f : α → β} (hf : Injective f) : Cardinal.lift.{v} (#α) ≤ Cardinal.lift.{u} (#β) := by rw [← Cardinal.mk_range_eq_of_injective hf] exact Cardinal.lift_le.2 (Cardinal.mk_set_le _) lemma lift_mk_le_lift_mk_of_surjective {α : Type u} {β : Type v} {f : α → β} (hf : Surjective f) : Cardinal.lift.{u} (#β) ≤ Cardinal.lift.{v} (#α) := lift_mk_le_lift_mk_of_injective (injective_surjInv hf) theorem mk_image_eq_of_injOn {α β : Type u} (f : α → β) (s : Set α) (h : InjOn f s) : #(f '' s) = #s := mk_congr (Equiv.Set.imageOfInjOn f s h).symm theorem mk_image_eq_of_injOn_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : InjOn f s) : lift.{u} #(f '' s) = lift.{v} #s := lift_mk_eq.{v, u, 0}.mpr ⟨(Equiv.Set.imageOfInjOn f s h).symm⟩ theorem mk_image_eq {α β : Type u} {f : α → β} {s : Set α} (hf : Injective f) : #(f '' s) = #s := mk_image_eq_of_injOn _ _ hf.injOn theorem mk_image_eq_lift {α : Type u} {β : Type v} (f : α → β) (s : Set α) (h : Injective f) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_of_injOn_lift _ _ h.injOn @[simp] theorem mk_image_embedding_lift {β : Type v} (f : α ↪ β) (s : Set α) : lift.{u} #(f '' s) = lift.{v} #s := mk_image_eq_lift _ _ f.injective @[simp] theorem mk_image_embedding (f : α ↪ β) (s : Set α) : #(f '' s) = #s := by simpa using mk_image_embedding_lift f s theorem mk_iUnion_le_sum_mk {α ι : Type u} {f : ι → Set α} : #(⋃ i, f i) ≤ sum fun i => #(f i) := calc #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} : lift.{v} #(⋃ i, f i) ≤ sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) ≤ #(Σi, f i) := mk_le_of_surjective <| ULift.up_surjective.comp (Set.sigmaToiUnion_surjective f) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk {α ι : Type u} {f : ι → Set α} (h : Pairwise (Disjoint on f)) : #(⋃ i, f i) = sum fun i => #(f i) := calc #(⋃ i, f i) = #(Σi, f i) := mk_congr (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_eq_sum_mk_lift {α : Type u} {ι : Type v} {f : ι → Set α} (h : Pairwise (Disjoint on f)) : lift.{v} #(⋃ i, f i) = sum fun i => #(f i) := calc lift.{v} #(⋃ i, f i) = #(Σi, f i) := mk_congr <| .trans Equiv.ulift (Set.unionEqSigmaOfDisjoint h) _ = sum fun i => #(f i) := mk_sigma _ theorem mk_iUnion_le {α ι : Type u} (f : ι → Set α) : #(⋃ i, f i) ≤ #ι * ⨆ i, #(f i) := mk_iUnion_le_sum_mk.trans (sum_le_iSup _) theorem mk_iUnion_le_lift {α : Type u} {ι : Type v} (f : ι → Set α) : lift.{v} #(⋃ i, f i) ≤ lift.{u} #ι * ⨆ i, lift.{v} #(f i) := by refine mk_iUnion_le_sum_mk_lift.trans <| Eq.trans_le ?_ (sum_le_iSup_lift _) rw [← lift_sum, lift_id'.{_,u}] theorem mk_sUnion_le {α : Type u} (A : Set (Set α)) : #(⋃₀ A) ≤ #A * ⨆ s : A, #s := by rw [sUnion_eq_iUnion] apply mk_iUnion_le theorem mk_biUnion_le {ι α : Type u} (A : ι → Set α) (s : Set ι) : #(⋃ x ∈ s, A x) ≤ #s * ⨆ x : s, #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le theorem mk_biUnion_le_lift {α : Type u} {ι : Type v} (A : ι → Set α) (s : Set ι) : lift.{v} #(⋃ x ∈ s, A x) ≤ lift.{u} #s * ⨆ x : s, lift.{v} #(A x.1) := by rw [biUnion_eq_iUnion] apply mk_iUnion_le_lift theorem finset_card_lt_aleph0 (s : Finset α) : #(↑s : Set α) < ℵ₀ := lt_aleph0_of_finite _ theorem mk_set_eq_nat_iff_finset {α} {s : Set α} {n : ℕ} : #s = n ↔ ∃ t : Finset α, (t : Set α) = s ∧ t.card = n := by constructor · intro h lift s to Finset α using lt_aleph0_iff_set_finite.1 (h.symm ▸ nat_lt_aleph0 n) simpa using h · rintro ⟨t, rfl, rfl⟩ exact mk_coe_finset theorem mk_eq_nat_iff_finset {n : ℕ} : #α = n ↔ ∃ t : Finset α, (t : Set α) = univ ∧ t.card = n := by rw [← mk_univ, mk_set_eq_nat_iff_finset] theorem mk_eq_nat_iff_fintype {n : ℕ} : #α = n ↔ ∃ h : Fintype α, @Fintype.card α h = n := by rw [mk_eq_nat_iff_finset] constructor · rintro ⟨t, ht, hn⟩ exact ⟨⟨t, eq_univ_iff_forall.1 ht⟩, hn⟩ · rintro ⟨⟨t, ht⟩, hn⟩ exact ⟨t, eq_univ_iff_forall.2 ht, hn⟩ theorem mk_union_add_mk_inter {α : Type u} {S T : Set α} : #(S ∪ T : Set α) + #(S ∩ T : Set α) = #S + #T := by classical exact Quot.sound ⟨Equiv.Set.unionSumInter S T⟩ /-- The cardinality of a union is at most the sum of the cardinalities of the two sets. -/ theorem mk_union_le {α : Type u} (S T : Set α) : #(S ∪ T : Set α) ≤ #S + #T := @mk_union_add_mk_inter α S T ▸ self_le_add_right #(S ∪ T : Set α) #(S ∩ T : Set α) theorem mk_union_of_disjoint {α : Type u} {S T : Set α} (H : Disjoint S T) : #(S ∪ T : Set α) = #S + #T := by classical exact Quot.sound ⟨Equiv.Set.union H⟩ theorem mk_insert {α : Type u} {s : Set α} {a : α} (h : a ∉ s) : #(insert a s : Set α) = #s + 1 := by rw [← union_singleton, mk_union_of_disjoint, mk_singleton] simpa theorem mk_insert_le {α : Type u} {s : Set α} {a : α} : #(insert a s : Set α) ≤ #s + 1 := by by_cases h : a ∈ s · simp only [insert_eq_of_mem h, self_le_add_right] · rw [mk_insert h] theorem mk_sum_compl {α} (s : Set α) : #s + #(sᶜ : Set α) = #α := by classical exact mk_congr (Equiv.Set.sumCompl s) theorem mk_le_mk_of_subset {α} {s t : Set α} (h : s ⊆ t) : #s ≤ #t := ⟨Set.embeddingOfSubset s t h⟩ theorem mk_le_iff_forall_finset_subset_card_le {α : Type u} {n : ℕ} {t : Set α} : #t ≤ n ↔ ∀ s : Finset α, (s : Set α) ⊆ t → s.card ≤ n := by refine ⟨fun H s hs ↦ by simpa using (mk_le_mk_of_subset hs).trans H, fun H ↦ ?_⟩ apply card_le_of (fun s ↦ ?_) classical let u : Finset α := s.image Subtype.val have : u.card = s.card := Finset.card_image_of_injOn Subtype.coe_injective.injOn rw [← this] apply H simp only [u, Finset.coe_image, image_subset_iff, Subtype.coe_preimage_self, subset_univ] theorem mk_subtype_mono {p q : α → Prop} (h : ∀ x, p x → q x) : #{ x // p x } ≤ #{ x // q x } := ⟨embeddingOfSubset _ _ h⟩ theorem le_mk_diff_add_mk (S T : Set α) : #S ≤ #(S \ T : Set α) + #T := (mk_le_mk_of_subset <| subset_diff_union _ _).trans <| mk_union_le _ _ theorem mk_diff_add_mk {S T : Set α} (h : T ⊆ S) : #(S \ T : Set α) + #T = #S := by refine (mk_union_of_disjoint <| ?_).symm.trans <| by rw [diff_union_of_subset h] exact disjoint_sdiff_self_left theorem mk_union_le_aleph0 {α} {P Q : Set α} : #(P ∪ Q : Set α) ≤ ℵ₀ ↔ #P ≤ ℵ₀ ∧ #Q ≤ ℵ₀ := by simp only [le_aleph0_iff_subtype_countable, mem_union, setOf_mem_eq, Set.union_def, ← countable_union] theorem mk_sep (s : Set α) (t : α → Prop) : #({ x ∈ s | t x } : Set α) = #{ x : s | t x.1 } := mk_congr (Equiv.Set.sep s t) theorem mk_preimage_of_injective_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β) (h : Injective f) : lift.{v} #(f ⁻¹' s) ≤ lift.{u} #s := by rw [lift_mk_le.{0}] -- Porting note: Needed to insert `mem_preimage.mp` below use Subtype.coind (fun x => f x.1) fun x => mem_preimage.mp x.2 apply Subtype.coind_injective; exact h.comp Subtype.val_injective theorem mk_preimage_of_subset_range_lift {α : Type u} {β : Type v} (f : α → β) (s : Set β) (h : s ⊆ range f) : lift.{u} #s ≤ lift.{v} #(f ⁻¹' s) := by rw [← image_preimage_eq_iff] at h nth_rewrite 1 [← h] apply mk_image_le_lift theorem mk_preimage_of_injective_of_subset_range_lift {β : Type v} (f : α → β) (s : Set β) (h : Injective f) (h2 : s ⊆ range f) : lift.{v} #(f ⁻¹' s) = lift.{u} #s := le_antisymm (mk_preimage_of_injective_lift f s h) (mk_preimage_of_subset_range_lift f s h2) theorem mk_preimage_of_injective_of_subset_range (f : α → β) (s : Set β) (h : Injective f) (h2 : s ⊆ range f) : #(f ⁻¹' s) = #s := by convert mk_preimage_of_injective_of_subset_range_lift.{u, u} f s h h2 using 1 <;> rw [lift_id] @[simp] theorem mk_preimage_equiv_lift {β : Type v} (f : α ≃ β) (s : Set β) : lift.{v} #(f ⁻¹' s) = lift.{u} #s := by apply mk_preimage_of_injective_of_subset_range_lift _ _ f.injective rw [f.range_eq_univ] exact fun _ _ ↦ ⟨⟩ @[simp] theorem mk_preimage_equiv (f : α ≃ β) (s : Set β) : #(f ⁻¹' s) = #s := by simpa using mk_preimage_equiv_lift f s theorem mk_preimage_of_injective (f : α → β) (s : Set β) (h : Injective f) : #(f ⁻¹' s) ≤ #s := by rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)] exact mk_preimage_of_injective_lift f s h theorem mk_preimage_of_subset_range (f : α → β) (s : Set β) (h : s ⊆ range f) : #s ≤ #(f ⁻¹' s) := by rw [← lift_id #(↑(f ⁻¹' s)), ← lift_id #(↑s)] exact mk_preimage_of_subset_range_lift f s h theorem mk_subset_ge_of_subset_image_lift {α : Type u} {β : Type v} (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) : lift.{u} #t ≤ lift.{v} #({ x ∈ s | f x ∈ t } : Set α) := by rw [image_eq_range] at h convert mk_preimage_of_subset_range_lift _ _ h using 1 rw [mk_sep] rfl theorem mk_subset_ge_of_subset_image (f : α → β) {s : Set α} {t : Set β} (h : t ⊆ f '' s) : #t ≤ #({ x ∈ s | f x ∈ t } : Set α) := by rw [image_eq_range] at h convert mk_preimage_of_subset_range _ _ h using 1 rw [mk_sep] rfl theorem le_mk_iff_exists_subset {c : Cardinal} {α : Type u} {s : Set α} : c ≤ #s ↔ ∃ p : Set α, p ⊆ s ∧ #p = c := by rw [le_mk_iff_exists_set, ← Subtype.exists_set_subtype] apply exists_congr; intro t; rw [mk_image_eq]; apply Subtype.val_injective @[simp] theorem mk_range_inl {α : Type u} {β : Type v} : #(range (@Sum.inl α β)) = lift.{v} #α := by rw [← lift_id'.{u, v} #_, (Equiv.Set.rangeInl α β).lift_cardinal_eq, lift_umax.{u, v}] @[simp] theorem mk_range_inr {α : Type u} {β : Type v} : #(range (@Sum.inr α β)) = lift.{u} #β := by rw [← lift_id'.{v, u} #_, (Equiv.Set.rangeInr α β).lift_cardinal_eq, lift_umax.{v, u}] theorem two_le_iff : (2 : Cardinal) ≤ #α ↔ ∃ x y : α, x ≠ y := by rw [← Nat.cast_two, nat_succ, succ_le_iff, Nat.cast_one, one_lt_iff_nontrivial, nontrivial_iff] theorem two_le_iff' (x : α) : (2 : Cardinal) ≤ #α ↔ ∃ y : α, y ≠ x := by rw [two_le_iff, ← nontrivial_iff, nontrivial_iff_exists_ne x] theorem mk_eq_two_iff : #α = 2 ↔ ∃ x y : α, x ≠ y ∧ ({x, y} : Set α) = univ := by classical simp only [← @Nat.cast_two Cardinal, mk_eq_nat_iff_finset, Finset.card_eq_two] constructor · rintro ⟨t, ht, x, y, hne, rfl⟩ exact ⟨x, y, hne, by simpa using ht⟩ · rintro ⟨x, y, hne, h⟩ exact ⟨{x, y}, by simpa using h, x, y, hne, rfl⟩ theorem mk_eq_two_iff' (x : α) : #α = 2 ↔ ∃! y, y ≠ x := by rw [mk_eq_two_iff]; constructor · rintro ⟨a, b, hne, h⟩ simp only [eq_univ_iff_forall, mem_insert_iff, mem_singleton_iff] at h rcases h x with (rfl | rfl) exacts [⟨b, hne.symm, fun z => (h z).resolve_left⟩, ⟨a, hne, fun z => (h z).resolve_right⟩] · rintro ⟨y, hne, hy⟩ exact ⟨x, y, hne.symm, eq_univ_of_forall fun z => or_iff_not_imp_left.2 (hy z)⟩ theorem exists_not_mem_of_length_lt {α : Type*} (l : List α) (h : ↑l.length < #α) : ∃ z : α, z ∉ l := by classical contrapose! h calc #α = #(Set.univ : Set α) := mk_univ.symm _ ≤ #l.toFinset := mk_le_mk_of_subset fun x _ => List.mem_toFinset.mpr (h x) _ = l.toFinset.card := Cardinal.mk_coe_finset _ ≤ l.length := Nat.cast_le.mpr (List.toFinset_card_le l) theorem three_le {α : Type*} (h : 3 ≤ #α) (x : α) (y : α) : ∃ z : α, z ≠ x ∧ z ≠ y := by have : ↑(3 : ℕ) ≤ #α := by simpa using h have : ↑(2 : ℕ) < #α := by rwa [← succ_le_iff, ← Cardinal.nat_succ] have := exists_not_mem_of_length_lt [x, y] this simpa [not_or] using this /-! ### `powerlt` operation -/ /-- The function `a ^< b`, defined as the supremum of `a ^ c` for `c < b`. -/ def powerlt (a b : Cardinal.{u}) : Cardinal.{u} := ⨆ c : Iio b, a ^ (c : Cardinal) @[inherit_doc] infixl:80 " ^< " => powerlt theorem le_powerlt {b c : Cardinal.{u}} (a) (h : c < b) : (a^c) ≤ a ^< b := by refine le_ciSup (f := fun y : Iio b => a ^ (y : Cardinal)) ?_ ⟨c, h⟩ rw [← image_eq_range] exact bddAbove_image.{u, u} _ bddAbove_Iio theorem powerlt_le {a b c : Cardinal.{u}} : a ^< b ≤ c ↔ ∀ x < b, a ^ x ≤ c := by rw [powerlt, ciSup_le_iff'] · simp · rw [← image_eq_range] exact bddAbove_image.{u, u} _ bddAbove_Iio theorem powerlt_le_powerlt_left {a b c : Cardinal} (h : b ≤ c) : a ^< b ≤ a ^< c := powerlt_le.2 fun _ hx => le_powerlt a <| hx.trans_le h theorem powerlt_mono_left (a) : Monotone fun c => a ^< c := fun _ _ => powerlt_le_powerlt_left theorem powerlt_succ {a b : Cardinal} (h : a ≠ 0) : a ^< succ b = a ^ b := (powerlt_le.2 fun _ h' => power_le_power_left h <| le_of_lt_succ h').antisymm <| le_powerlt a (lt_succ b) theorem powerlt_min {a b c : Cardinal} : a ^< min b c = min (a ^< b) (a ^< c) := (powerlt_mono_left a).map_min theorem powerlt_max {a b c : Cardinal} : a ^< max b c = max (a ^< b) (a ^< c) := (powerlt_mono_left a).map_max theorem zero_powerlt {a : Cardinal} (h : a ≠ 0) : 0 ^< a = 1 := by apply (powerlt_le.2 fun c _ => zero_power_le _).antisymm rw [← power_zero] exact le_powerlt 0 (pos_iff_ne_zero.2 h) @[simp] theorem powerlt_zero {a : Cardinal} : a ^< 0 = 0 := by convert Cardinal.iSup_of_empty _ exact Subtype.isEmpty_of_false fun x => mem_Iio.not.mpr (Cardinal.zero_le x).not_lt end Cardinal
Mathlib/SetTheory/Cardinal/Basic.lean
2,219
2,222
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Group.Abs import Mathlib.Algebra.Order.Ring.Int import Mathlib.Data.Nat.Cast.Order.Ring /-! # Order properties of cast of integers This file proves additional properties about the *canonical* homomorphism from the integers into an additive group with a one (`Int.cast`), particularly results involving algebraic homomorphisms or the order structure on `ℤ` which were not available in the import dependencies of `Mathlib.Data.Int.Cast.Basic`. ## TODO Move order lemmas about `Nat.cast`, `Rat.cast`, `NNRat.cast` here. -/ open Function Nat variable {R : Type*} namespace Int section OrderedAddCommGroupWithOne variable [AddCommGroupWithOne R] [PartialOrder R] [AddLeftMono R] variable [ZeroLEOneClass R] lemma cast_mono : Monotone (Int.cast : ℤ → R) := by intro m n h rw [← sub_nonneg] at h lift n - m to ℕ using h with k hk rw [← sub_nonneg, ← cast_sub, ← hk, cast_natCast] exact k.cast_nonneg' @[gcongr] protected lemma GCongr.intCast_mono {m n : ℤ} (hmn : m ≤ n) : (m : R) ≤ n := cast_mono hmn variable [NeZero (1 : R)] {m n : ℤ} @[simp] lemma cast_nonneg : ∀ {n : ℤ}, (0 : R) ≤ n ↔ 0 ≤ n | (n : ℕ) => by simp | -[n+1] => by have : -(n : R) < 1 := lt_of_le_of_lt (by simp) zero_lt_one simpa [(negSucc_lt_zero n).not_le, ← sub_eq_add_neg, le_neg] using this.not_le @[simp, norm_cast] lemma cast_le : (m : R) ≤ n ↔ m ≤ n := by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg] lemma cast_strictMono : StrictMono (fun x : ℤ => (x : R)) := strictMono_of_le_iff_le fun _ _ => cast_le.symm @[simp, norm_cast] lemma cast_lt : (m : R) < n ↔ m < n := cast_strictMono.lt_iff_lt @[gcongr] protected alias ⟨_, GCongr.intCast_strictMono⟩ := Int.cast_lt @[simp] lemma cast_nonpos : (n : R) ≤ 0 ↔ n ≤ 0 := by rw [← cast_zero, cast_le] @[simp] lemma cast_pos : (0 : R) < n ↔ 0 < n := by rw [← cast_zero, cast_lt] @[simp] lemma cast_lt_zero : (n : R) < 0 ↔ n < 0 := by rw [← cast_zero, cast_lt] end OrderedAddCommGroupWithOne section LinearOrderedRing variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] {a b n : ℤ} {x : R} @[simp, norm_cast] lemma cast_min : ↑(min a b) = (min a b : R) := Monotone.map_min cast_mono @[simp, norm_cast] lemma cast_max : (↑(max a b) : R) = max (a : R) (b : R) := Monotone.map_max cast_mono @[simp, norm_cast] lemma cast_abs : (↑|a| : R) = |(a : R)| := by simp [abs_eq_max_neg] lemma cast_one_le_of_pos (h : 0 < a) : (1 : R) ≤ a := mod_cast Int.add_one_le_of_lt h lemma cast_le_neg_one_of_neg (h : a < 0) : (a : R) ≤ -1 := by rw [← Int.cast_one, ← Int.cast_neg, cast_le] exact Int.le_sub_one_of_lt h variable (R) in lemma cast_le_neg_one_or_one_le_cast_of_ne_zero (hn : n ≠ 0) : (n : R) ≤ -1 ∨ 1 ≤ (n : R) := hn.lt_or_lt.imp cast_le_neg_one_of_neg cast_one_le_of_pos lemma nneg_mul_add_sq_of_abs_le_one (n : ℤ) (hx : |x| ≤ 1) : (0 : R) ≤ n * x + n * n := by have hnx : 0 < n → 0 ≤ x + n := fun hn => by have := _root_.add_le_add (neg_le_of_abs_le hx) (cast_one_le_of_pos hn) rwa [neg_add_cancel] at this have hnx' : n < 0 → x + n ≤ 0 := fun hn => by have := _root_.add_le_add (le_of_abs_le hx) (cast_le_neg_one_of_neg hn) rwa [add_neg_cancel] at this rw [← mul_add, mul_nonneg_iff] rcases lt_trichotomy n 0 with (h | rfl | h)
· exact Or.inr ⟨mod_cast h.le, hnx' h⟩ · simp [le_total 0 x] · exact Or.inl ⟨mod_cast h.le, hnx h⟩ -- TODO: move to a better place omit [LinearOrder R] [IsStrictOrderedRing R] in lemma cast_natAbs : (n.natAbs : R) = |n| := by cases n · simp · rw [abs_eq_natAbs, natAbs_negSucc, cast_succ, cast_natCast, cast_succ] end LinearOrderedRing
Mathlib/Algebra/Order/Ring/Cast.lean
99
110
/- Copyright (c) 2020 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import Mathlib.Algebra.GroupWithZero.Units.Basic import Mathlib.Algebra.Group.Semiconj.Units /-! # Lemmas about semiconjugate elements in a `GroupWithZero`. -/ assert_not_exists DenselyOrdered variable {G₀ : Type*} namespace SemiconjBy @[simp] theorem zero_right [MulZeroClass G₀] (a : G₀) : SemiconjBy a 0 0 := by simp only [SemiconjBy, mul_zero, zero_mul] @[simp] theorem zero_left [MulZeroClass G₀] (x y : G₀) : SemiconjBy 0 x y := by simp only [SemiconjBy, mul_zero, zero_mul] variable [GroupWithZero G₀] {a x y x' y' : G₀} @[simp] theorem inv_symm_left_iff₀ : SemiconjBy a⁻¹ x y ↔ SemiconjBy a y x := Classical.by_cases (fun ha : a = 0 => by simp only [ha, inv_zero, SemiconjBy.zero_left]) fun ha => @units_inv_symm_left_iff _ _ (Units.mk0 a ha) _ _ theorem inv_symm_left₀ (h : SemiconjBy a x y) : SemiconjBy a⁻¹ y x := SemiconjBy.inv_symm_left_iff₀.2 h theorem inv_right₀ (h : SemiconjBy a x y) : SemiconjBy a x⁻¹ y⁻¹ := by by_cases ha : a = 0 · simp only [ha, zero_left] by_cases hx : x = 0 · subst x simp only [SemiconjBy, mul_zero, @eq_comm _ _ (y * a), mul_eq_zero] at h simp [h.resolve_right ha] · have := mul_ne_zero ha hx rw [h.eq, mul_ne_zero_iff] at this exact @units_inv_right _ _ _ (Units.mk0 x hx) (Units.mk0 y this.1) h @[simp] theorem inv_right_iff₀ : SemiconjBy a x⁻¹ y⁻¹ ↔ SemiconjBy a x y := ⟨fun h => inv_inv x ▸ inv_inv y ▸ h.inv_right₀, inv_right₀⟩ theorem div_right (h : SemiconjBy a x y) (h' : SemiconjBy a x' y') : SemiconjBy a (x / x') (y / y') := by rw [div_eq_mul_inv, div_eq_mul_inv] exact h.mul_right h'.inv_right₀ lemma zpow_right₀ {a x y : G₀} (h : SemiconjBy a x y) : ∀ m : ℤ, SemiconjBy a (x ^ m) (y ^ m) | (n : ℕ) => by simp [h.pow_right n] | .negSucc n => by simp only [zpow_negSucc, (h.pow_right (n + 1)).inv_right₀]
end SemiconjBy namespace Commute variable [GroupWithZero G₀] {a b : G₀}
Mathlib/Algebra/GroupWithZero/Semiconj.lean
62
65
/- Copyright (c) 2017 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Keeley Hoek -/ import Mathlib.Algebra.NeZero import Mathlib.Data.Int.DivMod import Mathlib.Logic.Embedding.Basic import Mathlib.Logic.Equiv.Set import Mathlib.Tactic.Common import Mathlib.Tactic.Attr.Register /-! # The finite type with `n` elements `Fin n` is the type whose elements are natural numbers smaller than `n`. This file expands on the development in the core library. ## Main definitions ### Induction principles * `finZeroElim` : Elimination principle for the empty set `Fin 0`, generalizes `Fin.elim0`. Further definitions and eliminators can be found in `Init.Data.Fin.Lemmas` ### Embeddings and isomorphisms * `Fin.valEmbedding` : coercion to natural numbers as an `Embedding`; * `Fin.succEmb` : `Fin.succ` as an `Embedding`; * `Fin.castLEEmb h` : `Fin.castLE` as an `Embedding`, embed `Fin n` into `Fin m`, `h : n ≤ m`; * `finCongr` : `Fin.cast` as an `Equiv`, equivalence between `Fin n` and `Fin m` when `n = m`; * `Fin.castAddEmb m` : `Fin.castAdd` as an `Embedding`, embed `Fin n` into `Fin (n+m)`; * `Fin.castSuccEmb` : `Fin.castSucc` as an `Embedding`, embed `Fin n` into `Fin (n+1)`; * `Fin.addNatEmb m i` : `Fin.addNat` as an `Embedding`, add `m` on `i` on the right, generalizes `Fin.succ`; * `Fin.natAddEmb n i` : `Fin.natAdd` as an `Embedding`, adds `n` on `i` on the left; ### Other casts * `Fin.divNat i` : divides `i : Fin (m * n)` by `n`; * `Fin.modNat i` : takes the mod of `i : Fin (m * n)` by `n`; -/ assert_not_exists Monoid Finset open Fin Nat Function attribute [simp] Fin.succ_ne_zero Fin.castSucc_lt_last /-- Elimination principle for the empty set `Fin 0`, dependent version. -/ def finZeroElim {α : Fin 0 → Sort*} (x : Fin 0) : α x := x.elim0 namespace Fin @[simp] theorem mk_eq_one {n a : Nat} {ha : a < n + 2} : (⟨a, ha⟩ : Fin (n + 2)) = 1 ↔ a = 1 := mk.inj_iff @[simp] theorem one_eq_mk {n a : Nat} {ha : a < n + 2} : 1 = (⟨a, ha⟩ : Fin (n + 2)) ↔ a = 1 := by simp [eq_comm] instance {n : ℕ} : CanLift ℕ (Fin n) Fin.val (· < n) where prf k hk := ⟨⟨k, hk⟩, rfl⟩ /-- A dependent variant of `Fin.elim0`. -/ def rec0 {α : Fin 0 → Sort*} (i : Fin 0) : α i := absurd i.2 (Nat.not_lt_zero _) variable {n m : ℕ} --variable {a b : Fin n} -- this *really* breaks stuff theorem val_injective : Function.Injective (@Fin.val n) := @Fin.eq_of_val_eq n /-- If you actually have an element of `Fin n`, then the `n` is always positive -/ lemma size_positive : Fin n → 0 < n := Fin.pos lemma size_positive' [Nonempty (Fin n)] : 0 < n := ‹Nonempty (Fin n)›.elim Fin.pos protected theorem prop (a : Fin n) : a.val < n := a.2 lemma lt_last_iff_ne_last {a : Fin (n + 1)} : a < last n ↔ a ≠ last n := by simp [Fin.lt_iff_le_and_ne, le_last] lemma ne_zero_of_lt {a b : Fin (n + 1)} (hab : a < b) : b ≠ 0 := Fin.ne_of_gt <| Fin.lt_of_le_of_lt a.zero_le hab lemma ne_last_of_lt {a b : Fin (n + 1)} (hab : a < b) : a ≠ last n := Fin.ne_of_lt <| Fin.lt_of_lt_of_le hab b.le_last /-- Equivalence between `Fin n` and `{ i // i < n }`. -/ @[simps apply symm_apply] def equivSubtype : Fin n ≃ { i // i < n } where toFun a := ⟨a.1, a.2⟩ invFun a := ⟨a.1, a.2⟩ left_inv := fun ⟨_, _⟩ => rfl right_inv := fun ⟨_, _⟩ => rfl section coe /-! ### coercions and constructions -/ theorem val_eq_val (a b : Fin n) : (a : ℕ) = b ↔ a = b := Fin.ext_iff.symm theorem ne_iff_vne (a b : Fin n) : a ≠ b ↔ a.1 ≠ b.1 := Fin.ext_iff.not theorem mk_eq_mk {a h a' h'} : @mk n a h = @mk n a' h' ↔ a = a' := Fin.ext_iff -- syntactic tautologies now /-- Assume `k = l`. If two functions defined on `Fin k` and `Fin l` are equal on each element, then they coincide (in the heq sense). -/ protected theorem heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : Fin k → α} {g : Fin l → α} : HEq f g ↔ ∀ i : Fin k, f i = g ⟨(i : ℕ), h ▸ i.2⟩ := by subst h simp [funext_iff] /-- Assume `k = l` and `k' = l'`. If two functions `Fin k → Fin k' → α` and `Fin l → Fin l' → α` are equal on each pair, then they coincide (in the heq sense). -/ protected theorem heq_fun₂_iff {α : Sort*} {k l k' l' : ℕ} (h : k = l) (h' : k' = l') {f : Fin k → Fin k' → α} {g : Fin l → Fin l' → α} : HEq f g ↔ ∀ (i : Fin k) (j : Fin k'), f i j = g ⟨(i : ℕ), h ▸ i.2⟩ ⟨(j : ℕ), h' ▸ j.2⟩ := by subst h subst h' simp [funext_iff] /-- Two elements of `Fin k` and `Fin l` are heq iff their values in `ℕ` coincide. This requires `k = l`. For the left implication without this assumption, see `val_eq_val_of_heq`. -/ protected theorem heq_ext_iff {k l : ℕ} (h : k = l) {i : Fin k} {j : Fin l} : HEq i j ↔ (i : ℕ) = (j : ℕ) := by subst h simp [val_eq_val] end coe section Order /-! ### order -/ theorem le_iff_val_le_val {a b : Fin n} : a ≤ b ↔ (a : ℕ) ≤ b := Iff.rfl /-- `a < b` as natural numbers if and only if `a < b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_lt {n : ℕ} {a b : Fin n} : (a : ℕ) < (b : ℕ) ↔ a < b := Iff.rfl /-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `Fin n`. -/ @[norm_cast, simp] theorem val_fin_le {n : ℕ} {a b : Fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b := Iff.rfl theorem min_val {a : Fin n} : min (a : ℕ) n = a := by simp theorem max_val {a : Fin n} : max (a : ℕ) n = n := by simp /-- The inclusion map `Fin n → ℕ` is an embedding. -/ @[simps -fullyApplied apply] def valEmbedding : Fin n ↪ ℕ := ⟨val, val_injective⟩ @[simp] theorem equivSubtype_symm_trans_valEmbedding : equivSubtype.symm.toEmbedding.trans valEmbedding = Embedding.subtype (· < n) := rfl /-- Use the ordering on `Fin n` for checking recursive definitions. For example, the following definition is not accepted by the termination checker, unless we declare the `WellFoundedRelation` instance: ```lean def factorial {n : ℕ} : Fin n → ℕ | ⟨0, _⟩ := 1 | ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩ ``` -/ instance {n : ℕ} : WellFoundedRelation (Fin n) := measure (val : Fin n → ℕ) @[deprecated (since := "2025-02-24")] alias val_zero' := val_zero /-- `Fin.mk_zero` in `Lean` only applies in `Fin (n + 1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem mk_zero' (n : ℕ) [NeZero n] : (⟨0, pos_of_neZero n⟩ : Fin n) = 0 := rfl /-- The `Fin.zero_le` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] protected theorem zero_le' [NeZero n] (a : Fin n) : 0 ≤ a := Nat.zero_le a.val @[simp, norm_cast] theorem val_eq_zero_iff [NeZero n] {a : Fin n} : a.val = 0 ↔ a = 0 := by rw [Fin.ext_iff, val_zero] theorem val_ne_zero_iff [NeZero n] {a : Fin n} : a.val ≠ 0 ↔ a ≠ 0 := val_eq_zero_iff.not @[simp, norm_cast] theorem val_pos_iff [NeZero n] {a : Fin n} : 0 < a.val ↔ 0 < a := by rw [← val_fin_lt, val_zero] /-- The `Fin.pos_iff_ne_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem pos_iff_ne_zero' [NeZero n] (a : Fin n) : 0 < a ↔ a ≠ 0 := by rw [← val_pos_iff, Nat.pos_iff_ne_zero, val_ne_zero_iff] @[simp] lemma cast_eq_self (a : Fin n) : a.cast rfl = a := rfl @[simp] theorem cast_eq_zero {k l : ℕ} [NeZero k] [NeZero l] (h : k = l) (x : Fin k) : Fin.cast h x = 0 ↔ x = 0 := by simp [← val_eq_zero_iff] lemma cast_injective {k l : ℕ} (h : k = l) : Injective (Fin.cast h) := fun a b hab ↦ by simpa [← val_eq_val] using hab theorem last_pos' [NeZero n] : 0 < last n := n.pos_of_neZero theorem one_lt_last [NeZero n] : 1 < last (n + 1) := by rw [lt_iff_val_lt_val, val_one, val_last, Nat.lt_add_left_iff_pos, Nat.pos_iff_ne_zero] exact NeZero.ne n end Order /-! ### Coercions to `ℤ` and the `fin_omega` tactic. -/ open Int theorem coe_int_sub_eq_ite {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = if v ≤ u then (u - v : Int) else (u - v : Int) + n := by rw [Fin.sub_def] split · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_sub_eq_mod {n : Nat} (u v : Fin n) : ((u - v : Fin n) : Int) = ((u : Int) - (v : Int)) % n := by rw [coe_int_sub_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_add_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_ite {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = if (u + v : ℕ) < n then (u + v : Int) else (u + v : Int) - n := by rw [Fin.add_def] split · rw [natCast_emod, Int.emod_eq_of_lt] <;> omega · rw [natCast_emod, Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega theorem coe_int_add_eq_mod {n : Nat} (u v : Fin n) : ((u + v : Fin n) : Int) = ((u : Int) + (v : Int)) % n := by rw [coe_int_add_eq_ite] split · rw [Int.emod_eq_of_lt] <;> omega · rw [Int.emod_eq_sub_self_emod, Int.emod_eq_of_lt] <;> omega -- Write `a + b` as `if (a + b : ℕ) < n then (a + b : ℤ) else (a + b : ℤ) - n` and -- similarly `a - b` as `if (b : ℕ) ≤ a then (a - b : ℤ) else (a - b : ℤ) + n`. attribute [fin_omega] coe_int_sub_eq_ite coe_int_add_eq_ite -- Rewrite inequalities in `Fin` to inequalities in `ℕ` attribute [fin_omega] Fin.lt_iff_val_lt_val Fin.le_iff_val_le_val -- Rewrite `1 : Fin (n + 2)` to `1 : ℤ` attribute [fin_omega] val_one /-- Preprocessor for `omega` to handle inequalities in `Fin`. Note that this involves a lot of case splitting, so may be slow. -/ -- Further adjustment to the simp set can probably make this more powerful. -- Please experiment and PR updates! macro "fin_omega" : tactic => `(tactic| { try simp only [fin_omega, ← Int.ofNat_lt, ← Int.ofNat_le] at * omega }) section Add /-! ### addition, numerals, and coercion from Nat -/ @[simp] theorem val_one' (n : ℕ) [NeZero n] : ((1 : Fin n) : ℕ) = 1 % n := rfl @[deprecated val_one' (since := "2025-03-10")] theorem val_one'' {n : ℕ} : ((1 : Fin (n + 1)) : ℕ) = 1 % (n + 1) := rfl instance nontrivial {n : ℕ} : Nontrivial (Fin (n + 2)) where exists_pair_ne := ⟨0, 1, (ne_iff_vne 0 1).mpr (by simp [val_one, val_zero])⟩ theorem nontrivial_iff_two_le : Nontrivial (Fin n) ↔ 2 ≤ n := by rcases n with (_ | _ | n) <;> simp [Fin.nontrivial, not_nontrivial, Nat.succ_le_iff] section Monoid instance inhabitedFinOneAdd (n : ℕ) : Inhabited (Fin (1 + n)) := haveI : NeZero (1 + n) := by rw [Nat.add_comm]; infer_instance inferInstance @[simp] theorem default_eq_zero (n : ℕ) [NeZero n] : (default : Fin n) = 0 := rfl instance instNatCast [NeZero n] : NatCast (Fin n) where natCast i := Fin.ofNat' n i lemma natCast_def [NeZero n] (a : ℕ) : (a : Fin n) = ⟨a % n, mod_lt _ n.pos_of_neZero⟩ := rfl end Monoid theorem val_add_eq_ite {n : ℕ} (a b : Fin n) : (↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b := by rw [Fin.val_add, Nat.add_mod_eq_ite, Nat.mod_eq_of_lt (show ↑a < n from a.2), Nat.mod_eq_of_lt (show ↑b < n from b.2)] theorem val_add_eq_of_add_lt {n : ℕ} {a b : Fin n} (huv : a.val + b.val < n) : (a + b).val = a.val + b.val := by rw [val_add] simp [Nat.mod_eq_of_lt huv] lemma intCast_val_sub_eq_sub_add_ite {n : ℕ} (a b : Fin n) : ((a - b).val : ℤ) = a.val - b.val + if b ≤ a then 0 else n := by split <;> fin_omega lemma one_le_of_ne_zero {n : ℕ} [NeZero n] {k : Fin n} (hk : k ≠ 0) : 1 ≤ k := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) cases n with | zero => simp only [Nat.reduceAdd, Fin.isValue, Fin.zero_le] | succ n => rwa [Fin.le_iff_val_le_val, Fin.val_one, Nat.one_le_iff_ne_zero, val_ne_zero_iff] lemma val_sub_one_of_ne_zero [NeZero n] {i : Fin n} (hi : i ≠ 0) : (i - 1).val = i - 1 := by obtain ⟨n, rfl⟩ := Nat.exists_eq_succ_of_ne_zero (NeZero.ne n) rw [Fin.sub_val_of_le (one_le_of_ne_zero hi), Fin.val_one', Nat.mod_eq_of_lt (Nat.succ_le_iff.mpr (nontrivial_iff_two_le.mp <| nontrivial_of_ne i 0 hi))] section OfNatCoe @[simp] theorem ofNat'_eq_cast (n : ℕ) [NeZero n] (a : ℕ) : Fin.ofNat' n a = a := rfl @[simp] lemma val_natCast (a n : ℕ) [NeZero n] : (a : Fin n).val = a % n := rfl /-- Converting an in-range number to `Fin (n + 1)` produces a result whose value is the original number. -/ theorem val_cast_of_lt {n : ℕ} [NeZero n] {a : ℕ} (h : a < n) : (a : Fin n).val = a := Nat.mod_eq_of_lt h /-- If `n` is non-zero, converting the value of a `Fin n` to `Fin n` results in the same value. -/ @[simp, norm_cast] theorem cast_val_eq_self {n : ℕ} [NeZero n] (a : Fin n) : (a.val : Fin n) = a := Fin.ext <| val_cast_of_lt a.isLt -- This is a special case of `CharP.cast_eq_zero` that doesn't require typeclass search @[simp high] lemma natCast_self (n : ℕ) [NeZero n] : (n : Fin n) = 0 := by ext; simp @[simp] lemma natCast_eq_zero {a n : ℕ} [NeZero n] : (a : Fin n) = 0 ↔ n ∣ a := by simp [Fin.ext_iff, Nat.dvd_iff_mod_eq_zero] @[simp] theorem natCast_eq_last (n) : (n : Fin (n + 1)) = Fin.last n := by ext; simp theorem le_val_last (i : Fin (n + 1)) : i ≤ n := by rw [Fin.natCast_eq_last] exact Fin.le_last i variable {a b : ℕ} lemma natCast_le_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) ≤ b ↔ a ≤ b := by rw [← Nat.lt_succ_iff] at han hbn simp [le_iff_val_le_val, -val_fin_le, Nat.mod_eq_of_lt, han, hbn] lemma natCast_lt_natCast (han : a ≤ n) (hbn : b ≤ n) : (a : Fin (n + 1)) < b ↔ a < b := by rw [← Nat.lt_succ_iff] at han hbn; simp [lt_iff_val_lt_val, Nat.mod_eq_of_lt, han, hbn] lemma natCast_mono (hbn : b ≤ n) (hab : a ≤ b) : (a : Fin (n + 1)) ≤ b := (natCast_le_natCast (hab.trans hbn) hbn).2 hab lemma natCast_strictMono (hbn : b ≤ n) (hab : a < b) : (a : Fin (n + 1)) < b := (natCast_lt_natCast (hab.le.trans hbn) hbn).2 hab end OfNatCoe end Add section Succ /-! ### succ and casts into larger Fin types -/ lemma succ_injective (n : ℕ) : Injective (@Fin.succ n) := fun a b ↦ by simp [Fin.ext_iff] /-- `Fin.succ` as an `Embedding` -/ def succEmb (n : ℕ) : Fin n ↪ Fin (n + 1) where toFun := succ inj' := succ_injective _ @[simp] theorem coe_succEmb : ⇑(succEmb n) = Fin.succ := rfl @[deprecated (since := "2025-04-12")] alias val_succEmb := coe_succEmb @[simp] theorem exists_succ_eq {x : Fin (n + 1)} : (∃ y, Fin.succ y = x) ↔ x ≠ 0 := ⟨fun ⟨_, hy⟩ => hy ▸ succ_ne_zero _, x.cases (fun h => h.irrefl.elim) (fun _ _ => ⟨_, rfl⟩)⟩ theorem exists_succ_eq_of_ne_zero {x : Fin (n + 1)} (h : x ≠ 0) : ∃ y, Fin.succ y = x := exists_succ_eq.mpr h @[simp] theorem succ_zero_eq_one' [NeZero n] : Fin.succ (0 : Fin n) = 1 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl theorem one_pos' [NeZero n] : (0 : Fin (n + 1)) < 1 := succ_zero_eq_one' (n := n) ▸ succ_pos _ theorem zero_ne_one' [NeZero n] : (0 : Fin (n + 1)) ≠ 1 := Fin.ne_of_lt one_pos' /-- The `Fin.succ_one_eq_two` in `Lean` only applies in `Fin (n+2)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem succ_one_eq_two' [NeZero n] : Fin.succ (1 : Fin (n + 1)) = 2 := by cases n · exact (NeZero.ne 0 rfl).elim · rfl -- Version of `succ_one_eq_two` to be used by `dsimp`. -- Note the `'` swapped around due to a move to std4. /-- The `Fin.le_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem le_zero_iff' {n : ℕ} [NeZero n] {k : Fin n} : k ≤ 0 ↔ k = 0 := ⟨fun h => Fin.ext <| by rw [Nat.eq_zero_of_le_zero h]; rfl, by rintro rfl; exact Nat.le_refl _⟩ -- TODO: Move to Batteries @[simp] lemma castLE_inj {hmn : m ≤ n} {a b : Fin m} : castLE hmn a = castLE hmn b ↔ a = b := by simp [Fin.ext_iff] @[simp] lemma castAdd_inj {a b : Fin m} : castAdd n a = castAdd n b ↔ a = b := by simp [Fin.ext_iff] attribute [simp] castSucc_inj lemma castLE_injective (hmn : m ≤ n) : Injective (castLE hmn) := fun _ _ hab ↦ Fin.ext (congr_arg val hab :) lemma castAdd_injective (m n : ℕ) : Injective (@Fin.castAdd m n) := castLE_injective _ lemma castSucc_injective (n : ℕ) : Injective (@Fin.castSucc n) := castAdd_injective _ _ /-- `Fin.castLE` as an `Embedding`, `castLEEmb h i` embeds `i` into a larger `Fin` type. -/ @[simps apply] def castLEEmb (h : n ≤ m) : Fin n ↪ Fin m where toFun := castLE h inj' := castLE_injective _ @[simp, norm_cast] lemma coe_castLEEmb {m n} (hmn : m ≤ n) : castLEEmb hmn = castLE hmn := rfl /- The next proof can be golfed a lot using `Fintype.card`. It is written this way to define `ENat.card` and `Nat.card` without a `Fintype` dependency (not done yet). -/ lemma nonempty_embedding_iff : Nonempty (Fin n ↪ Fin m) ↔ n ≤ m := by refine ⟨fun h ↦ ?_, fun h ↦ ⟨castLEEmb h⟩⟩ induction n generalizing m with | zero => exact m.zero_le | succ n ihn => obtain ⟨e⟩ := h rcases exists_eq_succ_of_ne_zero (pos_iff_nonempty.2 (Nonempty.map e inferInstance)).ne' with ⟨m, rfl⟩ refine Nat.succ_le_succ <| ihn ⟨?_⟩ refine ⟨fun i ↦ (e.setValue 0 0 i.succ).pred (mt e.setValue_eq_iff.1 i.succ_ne_zero), fun i j h ↦ ?_⟩ simpa only [pred_inj, EmbeddingLike.apply_eq_iff_eq, succ_inj] using h lemma equiv_iff_eq : Nonempty (Fin m ≃ Fin n) ↔ m = n := ⟨fun ⟨e⟩ ↦ le_antisymm (nonempty_embedding_iff.1 ⟨e⟩) (nonempty_embedding_iff.1 ⟨e.symm⟩), fun h ↦ h ▸ ⟨.refl _⟩⟩ @[simp] lemma castLE_castSucc {n m} (i : Fin n) (h : n + 1 ≤ m) : i.castSucc.castLE h = i.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_comp_castSucc {n m} (h : n + 1 ≤ m) : Fin.castLE h ∘ Fin.castSucc = Fin.castLE (Nat.le_of_succ_le h) := rfl @[simp] lemma castLE_rfl (n : ℕ) : Fin.castLE (le_refl n) = id := rfl @[simp] theorem range_castLE {n k : ℕ} (h : n ≤ k) : Set.range (castLE h) = { i : Fin k | (i : ℕ) < n } := Set.ext fun x => ⟨fun ⟨y, hy⟩ => hy ▸ y.2, fun hx => ⟨⟨x, hx⟩, rfl⟩⟩ @[simp] theorem coe_of_injective_castLE_symm {n k : ℕ} (h : n ≤ k) (i : Fin k) (hi) : ((Equiv.ofInjective _ (castLE_injective h)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castLE h] exact congr_arg Fin.val (Equiv.apply_ofInjective_symm _ _) theorem leftInverse_cast (eq : n = m) : LeftInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl theorem rightInverse_cast (eq : n = m) : RightInverse (Fin.cast eq.symm) (Fin.cast eq) := fun _ => rfl @[simp] theorem cast_inj (eq : n = m) {a b : Fin n} : a.cast eq = b.cast eq ↔ a = b := by simp [← val_inj] @[simp] theorem cast_lt_cast (eq : n = m) {a b : Fin n} : a.cast eq < b.cast eq ↔ a < b := Iff.rfl @[simp] theorem cast_le_cast (eq : n = m) {a b : Fin n} : a.cast eq ≤ b.cast eq ↔ a ≤ b := Iff.rfl /-- The 'identity' equivalence between `Fin m` and `Fin n` when `m = n`. -/ @[simps] def _root_.finCongr (eq : n = m) : Fin n ≃ Fin m where toFun := Fin.cast eq invFun := Fin.cast eq.symm left_inv := leftInverse_cast eq right_inv := rightInverse_cast eq @[simp] lemma _root_.finCongr_apply_mk (h : m = n) (k : ℕ) (hk : k < m) : finCongr h ⟨k, hk⟩ = ⟨k, h ▸ hk⟩ := rfl @[simp] lemma _root_.finCongr_refl (h : n = n := rfl) : finCongr h = Equiv.refl (Fin n) := by ext; simp @[simp] lemma _root_.finCongr_symm (h : m = n) : (finCongr h).symm = finCongr h.symm := rfl @[simp] lemma _root_.finCongr_apply_coe (h : m = n) (k : Fin m) : (finCongr h k : ℕ) = k := rfl lemma _root_.finCongr_symm_apply_coe (h : m = n) (k : Fin n) : ((finCongr h).symm k : ℕ) = k := rfl /-- While in many cases `finCongr` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ lemma _root_.finCongr_eq_equivCast (h : n = m) : finCongr h = .cast (h ▸ rfl) := by subst h; simp /-- While in many cases `Fin.cast` is better than `Equiv.cast`/`cast`, sometimes we want to apply a generic theorem about `cast`. -/ theorem cast_eq_cast (h : n = m) : (Fin.cast h : Fin n → Fin m) = _root_.cast (h ▸ rfl) := by subst h ext rfl /-- `Fin.castAdd` as an `Embedding`, `castAddEmb m i` embeds `i : Fin n` in `Fin (n+m)`. See also `Fin.natAddEmb` and `Fin.addNatEmb`. -/ def castAddEmb (m) : Fin n ↪ Fin (n + m) := castLEEmb (le_add_right n m) @[simp] lemma coe_castAddEmb (m) : (castAddEmb m : Fin n → Fin (n + m)) = castAdd m := rfl lemma castAddEmb_apply (m) (i : Fin n) : castAddEmb m i = castAdd m i := rfl /-- `Fin.castSucc` as an `Embedding`, `castSuccEmb i` embeds `i : Fin n` in `Fin (n+1)`. -/ def castSuccEmb : Fin n ↪ Fin (n + 1) := castAddEmb _ @[simp, norm_cast] lemma coe_castSuccEmb : (castSuccEmb : Fin n → Fin (n + 1)) = Fin.castSucc := rfl lemma castSuccEmb_apply (i : Fin n) : castSuccEmb i = i.castSucc := rfl theorem castSucc_le_succ {n} (i : Fin n) : i.castSucc ≤ i.succ := Nat.le_succ i @[simp] theorem castSucc_le_castSucc_iff {a b : Fin n} : castSucc a ≤ castSucc b ↔ a ≤ b := .rfl @[simp] theorem succ_le_castSucc_iff {a b : Fin n} : succ a ≤ castSucc b ↔ a < b := by rw [le_castSucc_iff, succ_lt_succ_iff] @[simp] theorem castSucc_lt_succ_iff {a b : Fin n} : castSucc a < succ b ↔ a ≤ b := by rw [castSucc_lt_iff_succ_le, succ_le_succ_iff] theorem le_of_castSucc_lt_of_succ_lt {a b : Fin (n + 1)} {i : Fin n} (hl : castSucc i < a) (hu : b < succ i) : b < a := by simp [Fin.lt_def, -val_fin_lt] at *; omega theorem castSucc_lt_or_lt_succ (p : Fin (n + 1)) (i : Fin n) : castSucc i < p ∨ p < i.succ := by simp [Fin.lt_def, -val_fin_lt]; omega theorem succ_le_or_le_castSucc (p : Fin (n + 1)) (i : Fin n) : succ i ≤ p ∨ p ≤ i.castSucc := by rw [le_castSucc_iff, ← castSucc_lt_iff_succ_le] exact p.castSucc_lt_or_lt_succ i theorem eq_castSucc_of_ne_last {x : Fin (n + 1)} (h : x ≠ (last _)) : ∃ y, Fin.castSucc y = x := exists_castSucc_eq.mpr h @[deprecated (since := "2025-02-06")] alias exists_castSucc_eq_of_ne_last := eq_castSucc_of_ne_last theorem forall_fin_succ' {P : Fin (n + 1) → Prop} : (∀ i, P i) ↔ (∀ i : Fin n, P i.castSucc) ∧ P (.last _) := ⟨fun H => ⟨fun _ => H _, H _⟩, fun ⟨H0, H1⟩ i => Fin.lastCases H1 H0 i⟩ -- to match `Fin.eq_zero_or_eq_succ` theorem eq_castSucc_or_eq_last {n : Nat} (i : Fin (n + 1)) : (∃ j : Fin n, i = j.castSucc) ∨ i = last n := i.lastCases (Or.inr rfl) (Or.inl ⟨·, rfl⟩) @[simp] theorem castSucc_ne_last {n : ℕ} (i : Fin n) : i.castSucc ≠ .last n := Fin.ne_of_lt i.castSucc_lt_last theorem exists_fin_succ' {P : Fin (n + 1) → Prop} : (∃ i, P i) ↔ (∃ i : Fin n, P i.castSucc) ∨ P (.last _) := ⟨fun ⟨i, h⟩ => Fin.lastCases Or.inr (fun i hi => Or.inl ⟨i, hi⟩) i h, fun h => h.elim (fun ⟨i, hi⟩ => ⟨i.castSucc, hi⟩) (fun h => ⟨.last _, h⟩)⟩ /-- The `Fin.castSucc_zero` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_zero' [NeZero n] : castSucc (0 : Fin n) = 0 := rfl @[simp] theorem castSucc_pos_iff [NeZero n] {i : Fin n} : 0 < castSucc i ↔ 0 < i := by simp [← val_pos_iff] /-- `castSucc i` is positive when `i` is positive. The `Fin.castSucc_pos` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ alias ⟨_, castSucc_pos'⟩ := castSucc_pos_iff /-- The `Fin.castSucc_eq_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ @[simp] theorem castSucc_eq_zero_iff' [NeZero n] (a : Fin n) : castSucc a = 0 ↔ a = 0 := Fin.ext_iff.trans <| (Fin.ext_iff.trans <| by simp).symm /-- The `Fin.castSucc_ne_zero_iff` in `Lean` only applies in `Fin (n+1)`. This one instead uses a `NeZero n` typeclass hypothesis. -/ theorem castSucc_ne_zero_iff' [NeZero n] (a : Fin n) : castSucc a ≠ 0 ↔ a ≠ 0 := not_iff_not.mpr <| castSucc_eq_zero_iff' a theorem castSucc_ne_zero_of_lt {p i : Fin n} (h : p < i) : castSucc i ≠ 0 := by cases n · exact i.elim0 · rw [castSucc_ne_zero_iff', Ne, Fin.ext_iff] exact ((zero_le _).trans_lt h).ne' theorem succ_ne_last_iff (a : Fin (n + 1)) : succ a ≠ last (n + 1) ↔ a ≠ last n := not_iff_not.mpr <| succ_eq_last_succ theorem succ_ne_last_of_lt {p i : Fin n} (h : i < p) : succ i ≠ last n := by cases n · exact i.elim0 · rw [succ_ne_last_iff, Ne, Fin.ext_iff] exact ((le_last _).trans_lt' h).ne @[norm_cast, simp] theorem coe_eq_castSucc {a : Fin n} : (a : Fin (n + 1)) = castSucc a := by ext exact val_cast_of_lt (Nat.lt.step a.is_lt) theorem coe_succ_lt_iff_lt {n : ℕ} {j k : Fin n} : (j : Fin <| n + 1) < k ↔ j < k := by simp only [coe_eq_castSucc, castSucc_lt_castSucc_iff] @[simp] theorem range_castSucc {n : ℕ} : Set.range (castSucc : Fin n → Fin n.succ) = ({ i | (i : ℕ) < n } : Set (Fin n.succ)) := range_castLE (by omega) @[simp] theorem coe_of_injective_castSucc_symm {n : ℕ} (i : Fin n.succ) (hi) : ((Equiv.ofInjective castSucc (castSucc_injective _)).symm ⟨i, hi⟩ : ℕ) = i := by rw [← coe_castSucc] exact congr_arg val (Equiv.apply_ofInjective_symm _ _) /-- `Fin.addNat` as an `Embedding`, `addNatEmb m i` adds `m` to `i`, generalizes `Fin.succ`. -/ @[simps! apply] def addNatEmb (m) : Fin n ↪ Fin (n + m) where toFun := (addNat · m) inj' a b := by simp [Fin.ext_iff] /-- `Fin.natAdd` as an `Embedding`, `natAddEmb n i` adds `n` to `i` "on the left". -/ @[simps! apply] def natAddEmb (n) {m} : Fin m ↪ Fin (n + m) where toFun := natAdd n inj' a b := by simp [Fin.ext_iff] theorem castSucc_castAdd (i : Fin n) : castSucc (castAdd m i) = castAdd (m + 1) i := rfl theorem castSucc_natAdd (i : Fin m) : castSucc (natAdd n i) = natAdd n (castSucc i) := rfl theorem succ_castAdd (i : Fin n) : succ (castAdd m i) = if h : i.succ = last _ then natAdd n (0 : Fin (m + 1)) else castAdd (m + 1) ⟨i.1 + 1, lt_of_le_of_ne i.2 (Fin.val_ne_iff.mpr h)⟩ := by split_ifs with h exacts [Fin.ext (congr_arg Fin.val h :), rfl] theorem succ_natAdd (i : Fin m) : succ (natAdd n i) = natAdd n (succ i) := rfl end Succ section Pred /-! ### pred -/ theorem pred_one' [NeZero n] (h := (zero_ne_one' (n := n)).symm) : Fin.pred (1 : Fin (n + 1)) h = 0 := by simp_rw [Fin.ext_iff, coe_pred, val_one', val_zero, Nat.sub_eq_zero_iff_le, Nat.mod_le] theorem pred_last (h := Fin.ext_iff.not.2 last_pos'.ne') : pred (last (n + 1)) h = last n := by simp_rw [← succ_last, pred_succ] theorem pred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi < j ↔ i < succ j := by rw [← succ_lt_succ_iff, succ_pred] theorem lt_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j < pred i hi ↔ succ j < i := by rw [← succ_lt_succ_iff, succ_pred] theorem pred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : pred i hi ≤ j ↔ i ≤ succ j := by rw [← succ_le_succ_iff, succ_pred] theorem le_pred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ 0) : j ≤ pred i hi ↔ succ j ≤ i := by rw [← succ_le_succ_iff, succ_pred] theorem castSucc_pred_eq_pred_castSucc {a : Fin (n + 1)} (ha : a ≠ 0) (ha' := castSucc_ne_zero_iff.mpr ha) : (a.pred ha).castSucc = (castSucc a).pred ha' := rfl theorem castSucc_pred_add_one_eq {a : Fin (n + 1)} (ha : a ≠ 0) : (a.pred ha).castSucc + 1 = a := by cases a using cases · exact (ha rfl).elim · rw [pred_succ, coeSucc_eq_succ] theorem le_pred_castSucc_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : b ≤ (castSucc a).pred ha ↔ b < a := by rw [le_pred_iff, succ_le_castSucc_iff] theorem pred_castSucc_lt_iff {a b : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < b ↔ a ≤ b := by rw [pred_lt_iff, castSucc_lt_succ_iff] theorem pred_castSucc_lt {a : Fin (n + 1)} (ha : castSucc a ≠ 0) : (castSucc a).pred ha < a := by rw [pred_castSucc_lt_iff, le_def] theorem le_castSucc_pred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : b ≤ castSucc (a.pred ha) ↔ b < a := by rw [castSucc_pred_eq_pred_castSucc, le_pred_castSucc_iff] theorem castSucc_pred_lt_iff {a b : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < b ↔ a ≤ b := by rw [castSucc_pred_eq_pred_castSucc, pred_castSucc_lt_iff] theorem castSucc_pred_lt {a : Fin (n + 1)} (ha : a ≠ 0) : castSucc (a.pred ha) < a := by rw [castSucc_pred_lt_iff, le_def] end Pred section CastPred /-- `castPred i` sends `i : Fin (n + 1)` to `Fin n` as long as i ≠ last n. -/ @[inline] def castPred (i : Fin (n + 1)) (h : i ≠ last n) : Fin n := castLT i (val_lt_last h) @[simp] lemma castLT_eq_castPred (i : Fin (n + 1)) (h : i < last _) (h' := Fin.ext_iff.not.2 h.ne) : castLT i h = castPred i h' := rfl @[simp] lemma coe_castPred (i : Fin (n + 1)) (h : i ≠ last _) : (castPred i h : ℕ) = i := rfl @[simp] theorem castPred_castSucc {i : Fin n} (h' := Fin.ext_iff.not.2 (castSucc_lt_last i).ne) : castPred (castSucc i) h' = i := rfl @[simp] theorem castSucc_castPred (i : Fin (n + 1)) (h : i ≠ last n) : castSucc (i.castPred h) = i := by rcases exists_castSucc_eq.mpr h with ⟨y, rfl⟩ rw [castPred_castSucc] theorem castPred_eq_iff_eq_castSucc (i : Fin (n + 1)) (hi : i ≠ last _) (j : Fin n) : castPred i hi = j ↔ i = castSucc j := ⟨fun h => by rw [← h, castSucc_castPred], fun h => by simp_rw [h, castPred_castSucc]⟩ @[simp] theorem castPred_mk (i : ℕ) (h₁ : i < n) (h₂ := h₁.trans (Nat.lt_succ_self _)) (h₃ : ⟨i, h₂⟩ ≠ last _ := (ne_iff_vne _ _).mpr (val_last _ ▸ h₁.ne)) : castPred ⟨i, h₂⟩ h₃ = ⟨i, h₁⟩ := rfl @[simp] theorem castPred_le_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi ≤ castPred j hj ↔ i ≤ j := Iff.rfl /-- A version of the right-to-left implication of `castPred_le_castPred_iff` that deduces `i ≠ last n` from `i ≤ j` and `j ≠ last n`. -/ @[gcongr] theorem castPred_le_castPred {i j : Fin (n + 1)} (h : i ≤ j) (hj : j ≠ last n) : castPred i (by rw [← lt_last_iff_ne_last] at hj ⊢; exact Fin.lt_of_le_of_lt h hj) ≤ castPred j hj := h @[simp] theorem castPred_lt_castPred_iff {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi < castPred j hj ↔ i < j := Iff.rfl /-- A version of the right-to-left implication of `castPred_lt_castPred_iff` that deduces `i ≠ last n` from `i < j`. -/ @[gcongr] theorem castPred_lt_castPred {i j : Fin (n + 1)} (h : i < j) (hj : j ≠ last n) : castPred i (ne_last_of_lt h) < castPred j hj := h theorem castPred_lt_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi < j ↔ i < castSucc j := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem lt_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j < castPred i hi ↔ castSucc j < i := by rw [← castSucc_lt_castSucc_iff, castSucc_castPred] theorem castPred_le_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : castPred i hi ≤ j ↔ i ≤ castSucc j := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] theorem le_castPred_iff {j : Fin n} {i : Fin (n + 1)} (hi : i ≠ last n) : j ≤ castPred i hi ↔ castSucc j ≤ i := by rw [← castSucc_le_castSucc_iff, castSucc_castPred] @[simp] theorem castPred_inj {i j : Fin (n + 1)} {hi : i ≠ last n} {hj : j ≠ last n} : castPred i hi = castPred j hj ↔ i = j := by simp_rw [Fin.ext_iff, le_antisymm_iff, ← le_def, castPred_le_castPred_iff] theorem castPred_zero' [NeZero n] (h := Fin.ext_iff.not.2 last_pos'.ne) : castPred (0 : Fin (n + 1)) h = 0 := rfl theorem castPred_zero (h := Fin.ext_iff.not.2 last_pos.ne) : castPred (0 : Fin (n + 2)) h = 0 := rfl @[simp] theorem castPred_eq_zero [NeZero n] {i : Fin (n + 1)} (h : i ≠ last n) : Fin.castPred i h = 0 ↔ i = 0 := by rw [← castPred_zero', castPred_inj] @[simp] theorem castPred_one [NeZero n] (h := Fin.ext_iff.not.2 one_lt_last.ne) : castPred (1 : Fin (n + 2)) h = 1 := by cases n · exact subsingleton_one.elim _ 1 · rfl theorem succ_castPred_eq_castPred_succ {a : Fin (n + 1)} (ha : a ≠ last n) (ha' := a.succ_ne_last_iff.mpr ha) : (a.castPred ha).succ = (succ a).castPred ha' := rfl theorem succ_castPred_eq_add_one {a : Fin (n + 1)} (ha : a ≠ last n) : (a.castPred ha).succ = a + 1 := by cases a using lastCases · exact (ha rfl).elim · rw [castPred_castSucc, coeSucc_eq_succ] theorem castpred_succ_le_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : (succ a).castPred ha ≤ b ↔ a < b := by rw [castPred_le_iff, succ_le_castSucc_iff] theorem lt_castPred_succ_iff {a b : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : b < (succ a).castPred ha ↔ b ≤ a := by rw [lt_castPred_iff, castSucc_lt_succ_iff] theorem lt_castPred_succ {a : Fin (n + 1)} (ha : succ a ≠ last (n + 1)) : a < (succ a).castPred ha := by rw [lt_castPred_succ_iff, le_def] theorem succ_castPred_le_iff {a b : Fin (n + 1)} (ha : a ≠ last n) : succ (a.castPred ha) ≤ b ↔ a < b := by rw [succ_castPred_eq_castPred_succ ha, castpred_succ_le_iff] theorem lt_succ_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) : b < succ (a.castPred ha) ↔ b ≤ a := by rw [succ_castPred_eq_castPred_succ ha, lt_castPred_succ_iff] theorem lt_succ_castPred {a : Fin (n + 1)} (ha : a ≠ last n) : a < succ (a.castPred ha) := by rw [lt_succ_castPred_iff, le_def] theorem castPred_le_pred_iff {a b : Fin (n + 1)} (ha : a ≠ last n) (hb : b ≠ 0) : castPred a ha ≤ pred b hb ↔ a < b := by rw [le_pred_iff, succ_castPred_le_iff] theorem pred_lt_castPred_iff {a b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ last n) : pred a ha < castPred b hb ↔ a ≤ b := by rw [lt_castPred_iff, castSucc_pred_lt_iff ha] theorem pred_lt_castPred {a : Fin (n + 1)} (h₁ : a ≠ 0) (h₂ : a ≠ last n) : pred a h₁ < castPred a h₂ := by rw [pred_lt_castPred_iff, le_def] end CastPred section SuccAbove variable {p : Fin (n + 1)} {i j : Fin n} /-- `succAbove p i` embeds `Fin n` into `Fin (n + 1)` with a hole around `p`. -/ def succAbove (p : Fin (n + 1)) (i : Fin n) : Fin (n + 1) := if castSucc i < p then i.castSucc else i.succ /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` embeds `i` by `castSucc` when the resulting `i.castSucc < p`. -/ lemma succAbove_of_castSucc_lt (p : Fin (n + 1)) (i : Fin n) (h : castSucc i < p) : p.succAbove i = castSucc i := if_pos h lemma succAbove_of_succ_le (p : Fin (n + 1)) (i : Fin n) (h : succ i ≤ p) : p.succAbove i = castSucc i := succAbove_of_castSucc_lt _ _ (castSucc_lt_iff_succ_le.mpr h) /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` embeds `i` by `succ` when the resulting `p < i.succ`. -/ lemma succAbove_of_le_castSucc (p : Fin (n + 1)) (i : Fin n) (h : p ≤ castSucc i) : p.succAbove i = i.succ := if_neg (Fin.not_lt.2 h) lemma succAbove_of_lt_succ (p : Fin (n + 1)) (i : Fin n) (h : p < succ i) : p.succAbove i = succ i := succAbove_of_le_castSucc _ _ (le_castSucc_iff.mpr h) lemma succAbove_succ_of_lt (p i : Fin n) (h : p < i) : succAbove p.succ i = i.succ := succAbove_of_lt_succ _ _ (succ_lt_succ_iff.mpr h) lemma succAbove_succ_of_le (p i : Fin n) (h : i ≤ p) : succAbove p.succ i = i.castSucc := succAbove_of_succ_le _ _ (succ_le_succ_iff.mpr h) @[simp] lemma succAbove_succ_self (j : Fin n) : j.succ.succAbove j = j.castSucc := succAbove_succ_of_le _ _ Fin.le_rfl lemma succAbove_castSucc_of_lt (p i : Fin n) (h : i < p) : succAbove p.castSucc i = i.castSucc := succAbove_of_castSucc_lt _ _ (castSucc_lt_castSucc_iff.2 h) lemma succAbove_castSucc_of_le (p i : Fin n) (h : p ≤ i) : succAbove p.castSucc i = i.succ := succAbove_of_le_castSucc _ _ (castSucc_le_castSucc_iff.2 h) @[simp] lemma succAbove_castSucc_self (j : Fin n) : succAbove j.castSucc j = j.succ := succAbove_castSucc_of_le _ _ Fin.le_rfl lemma succAbove_pred_of_lt (p i : Fin (n + 1)) (h : p < i) (hi := Fin.ne_of_gt <| Fin.lt_of_le_of_lt p.zero_le h) : succAbove p (i.pred hi) = i := by rw [succAbove_of_lt_succ _ _ (succ_pred _ _ ▸ h), succ_pred] lemma succAbove_pred_of_le (p i : Fin (n + 1)) (h : i ≤ p) (hi : i ≠ 0) : succAbove p (i.pred hi) = (i.pred hi).castSucc := succAbove_of_succ_le _ _ (succ_pred _ _ ▸ h) @[simp] lemma succAbove_pred_self (p : Fin (n + 1)) (h : p ≠ 0) : succAbove p (p.pred h) = (p.pred h).castSucc := succAbove_pred_of_le _ _ Fin.le_rfl h lemma succAbove_castPred_of_lt (p i : Fin (n + 1)) (h : i < p) (hi := Fin.ne_of_lt <| Nat.lt_of_lt_of_le h p.le_last) : succAbove p (i.castPred hi) = i := by rw [succAbove_of_castSucc_lt _ _ (castSucc_castPred _ _ ▸ h), castSucc_castPred] lemma succAbove_castPred_of_le (p i : Fin (n + 1)) (h : p ≤ i) (hi : i ≠ last n) : succAbove p (i.castPred hi) = (i.castPred hi).succ := succAbove_of_le_castSucc _ _ (castSucc_castPred _ _ ▸ h) lemma succAbove_castPred_self (p : Fin (n + 1)) (h : p ≠ last n) : succAbove p (p.castPred h) = (p.castPred h).succ := succAbove_castPred_of_le _ _ Fin.le_rfl h /-- Embedding `i : Fin n` into `Fin (n + 1)` with a hole around `p : Fin (n + 1)` never results in `p` itself -/ @[simp] lemma succAbove_ne (p : Fin (n + 1)) (i : Fin n) : p.succAbove i ≠ p := by rcases p.castSucc_lt_or_lt_succ i with (h | h) · rw [succAbove_of_castSucc_lt _ _ h] exact Fin.ne_of_lt h · rw [succAbove_of_lt_succ _ _ h] exact Fin.ne_of_gt h @[simp] lemma ne_succAbove (p : Fin (n + 1)) (i : Fin n) : p ≠ p.succAbove i := (succAbove_ne _ _).symm /-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/ lemma succAbove_right_injective : Injective p.succAbove := by rintro i j hij unfold succAbove at hij split_ifs at hij with hi hj hj · exact castSucc_injective _ hij · rw [hij] at hi cases hj <| Nat.lt_trans j.castSucc_lt_succ hi · rw [← hij] at hj cases hi <| Nat.lt_trans i.castSucc_lt_succ hj · exact succ_injective _ hij /-- Given a fixed pivot `p : Fin (n + 1)`, `p.succAbove` is injective. -/ lemma succAbove_right_inj : p.succAbove i = p.succAbove j ↔ i = j := succAbove_right_injective.eq_iff /-- `Fin.succAbove p` as an `Embedding`. -/ @[simps!] def succAboveEmb (p : Fin (n + 1)) : Fin n ↪ Fin (n + 1) := ⟨p.succAbove, succAbove_right_injective⟩ @[simp, norm_cast] lemma coe_succAboveEmb (p : Fin (n + 1)) : p.succAboveEmb = p.succAbove := rfl @[simp] lemma succAbove_ne_zero_zero [NeZero n] {a : Fin (n + 1)} (ha : a ≠ 0) : a.succAbove 0 = 0 := by rw [Fin.succAbove_of_castSucc_lt] · exact castSucc_zero' · exact Fin.pos_iff_ne_zero.2 ha lemma succAbove_eq_zero_iff [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) : a.succAbove b = 0 ↔ b = 0 := by rw [← succAbove_ne_zero_zero ha, succAbove_right_inj] lemma succAbove_ne_zero [NeZero n] {a : Fin (n + 1)} {b : Fin n} (ha : a ≠ 0) (hb : b ≠ 0) : a.succAbove b ≠ 0 := mt (succAbove_eq_zero_iff ha).mp hb /-- Embedding `Fin n` into `Fin (n + 1)` with a hole around zero embeds by `succ`. -/ @[simp] lemma succAbove_zero : succAbove (0 : Fin (n + 1)) = Fin.succ := rfl lemma succAbove_zero_apply (i : Fin n) : succAbove 0 i = succ i := by rw [succAbove_zero] @[simp] lemma succAbove_ne_last_last {a : Fin (n + 2)} (h : a ≠ last (n + 1)) : a.succAbove (last n) = last (n + 1) := by rw [succAbove_of_lt_succ _ _ (succ_last _ ▸ lt_last_iff_ne_last.2 h), succ_last] lemma succAbove_eq_last_iff {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) : a.succAbove b = last _ ↔ b = last _ := by rw [← succAbove_ne_last_last ha, succAbove_right_inj] lemma succAbove_ne_last {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last _) (hb : b ≠ last _) : a.succAbove b ≠ last _ := mt (succAbove_eq_last_iff ha).mp hb /-- Embedding `Fin n` into `Fin (n + 1)` with a hole around `last n` embeds by `castSucc`. -/ @[simp] lemma succAbove_last : succAbove (last n) = castSucc := by ext; simp only [succAbove_of_castSucc_lt, castSucc_lt_last] lemma succAbove_last_apply (i : Fin n) : succAbove (last n) i = castSucc i := by rw [succAbove_last] /-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is greater results in a value that is less than `p`. -/ lemma succAbove_lt_iff_castSucc_lt (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ castSucc i < p := by rcases castSucc_lt_or_lt_succ p i with H | H · rwa [iff_true_right H, succAbove_of_castSucc_lt _ _ H] · rw [castSucc_lt_iff_succ_le, iff_false_right (Fin.not_le.2 H), succAbove_of_lt_succ _ _ H] exact Fin.not_lt.2 <| Fin.le_of_lt H lemma succAbove_lt_iff_succ_le (p : Fin (n + 1)) (i : Fin n) : p.succAbove i < p ↔ succ i ≤ p := by rw [succAbove_lt_iff_castSucc_lt, castSucc_lt_iff_succ_le] /-- Embedding `i : Fin n` into `Fin (n + 1)` using a pivot `p` that is lesser results in a value that is greater than `p`. -/ lemma lt_succAbove_iff_le_castSucc (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p ≤ castSucc i := by rcases castSucc_lt_or_lt_succ p i with H | H · rw [iff_false_right (Fin.not_le.2 H), succAbove_of_castSucc_lt _ _ H] exact Fin.not_lt.2 <| Fin.le_of_lt H · rwa [succAbove_of_lt_succ _ _ H, iff_true_left H, le_castSucc_iff] lemma lt_succAbove_iff_lt_castSucc (p : Fin (n + 1)) (i : Fin n) : p < p.succAbove i ↔ p < succ i := by rw [lt_succAbove_iff_le_castSucc, le_castSucc_iff] /-- Embedding a positive `Fin n` results in a positive `Fin (n + 1)` -/ lemma succAbove_pos [NeZero n] (p : Fin (n + 1)) (i : Fin n) (h : 0 < i) : 0 < p.succAbove i := by by_cases H : castSucc i < p · simpa [succAbove_of_castSucc_lt _ _ H] using castSucc_pos' h · simp [succAbove_of_le_castSucc _ _ (Fin.not_lt.1 H)] lemma castPred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : castSucc x < y) (h' := Fin.ne_last_of_lt <| (succAbove_lt_iff_castSucc_lt ..).2 h) : (y.succAbove x).castPred h' = x := by rw [castPred_eq_iff_eq_castSucc, succAbove_of_castSucc_lt _ _ h] lemma pred_succAbove (x : Fin n) (y : Fin (n + 1)) (h : y ≤ castSucc x) (h' := Fin.ne_zero_of_lt <| (lt_succAbove_iff_le_castSucc ..).2 h) : (y.succAbove x).pred h' = x := by simp only [succAbove_of_le_castSucc _ _ h, pred_succ] lemma exists_succAbove_eq {x y : Fin (n + 1)} (h : x ≠ y) : ∃ z, y.succAbove z = x := by obtain hxy | hyx := Fin.lt_or_lt_of_ne h exacts [⟨_, succAbove_castPred_of_lt _ _ hxy⟩, ⟨_, succAbove_pred_of_lt _ _ hyx⟩] @[simp] lemma exists_succAbove_eq_iff {x y : Fin (n + 1)} : (∃ z, x.succAbove z = y) ↔ y ≠ x := ⟨by rintro ⟨y, rfl⟩; exact succAbove_ne _ _, exists_succAbove_eq⟩ /-- The range of `p.succAbove` is everything except `p`. -/ @[simp] lemma range_succAbove (p : Fin (n + 1)) : Set.range p.succAbove = {p}ᶜ := Set.ext fun _ => exists_succAbove_eq_iff @[simp] lemma range_succ (n : ℕ) : Set.range (Fin.succ : Fin n → Fin (n + 1)) = {0}ᶜ := by rw [← succAbove_zero]; exact range_succAbove (0 : Fin (n + 1)) /-- `succAbove` is injective at the pivot -/ lemma succAbove_left_injective : Injective (@succAbove n) := fun _ _ h => by simpa [range_succAbove] using congr_arg (fun f : Fin n → Fin (n + 1) => (Set.range f)ᶜ) h /-- `succAbove` is injective at the pivot -/ @[simp] lemma succAbove_left_inj {x y : Fin (n + 1)} : x.succAbove = y.succAbove ↔ x = y := succAbove_left_injective.eq_iff @[simp] lemma zero_succAbove {n : ℕ} (i : Fin n) : (0 : Fin (n + 1)).succAbove i = i.succ := rfl lemma succ_succAbove_zero {n : ℕ} [NeZero n] (i : Fin n) : succAbove i.succ 0 = 0 := by simp /-- `succ` commutes with `succAbove`. -/ @[simp] lemma succ_succAbove_succ {n : ℕ} (i : Fin (n + 1)) (j : Fin n) : i.succ.succAbove j.succ = (i.succAbove j).succ := by obtain h | h := i.lt_or_le (succ j) · rw [succAbove_of_lt_succ _ _ h, succAbove_succ_of_lt _ _ h] · rwa [succAbove_of_castSucc_lt _ _ h, succAbove_succ_of_le, succ_castSucc] /-- `castSucc` commutes with `succAbove`. -/ @[simp] lemma castSucc_succAbove_castSucc {n : ℕ} {i : Fin (n + 1)} {j : Fin n} : i.castSucc.succAbove j.castSucc = (i.succAbove j).castSucc := by rcases i.le_or_lt (castSucc j) with (h | h) · rw [succAbove_of_le_castSucc _ _ h, succAbove_castSucc_of_le _ _ h, succ_castSucc] · rw [succAbove_of_castSucc_lt _ _ h, succAbove_castSucc_of_lt _ _ h] /-- `pred` commutes with `succAbove`. -/ lemma pred_succAbove_pred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0) (hk := succAbove_ne_zero ha hb) : (a.pred ha).succAbove (b.pred hb) = (a.succAbove b).pred hk := by simp_rw [← succ_inj (b := pred (succAbove a b) hk), ← succ_succAbove_succ, succ_pred] /-- `castPred` commutes with `succAbove`. -/ lemma castPred_succAbove_castPred {a : Fin (n + 2)} {b : Fin (n + 1)} (ha : a ≠ last (n + 1)) (hb : b ≠ last n) (hk := succAbove_ne_last ha hb) : (a.castPred ha).succAbove (b.castPred hb) = (a.succAbove b).castPred hk := by simp_rw [← castSucc_inj (b := (a.succAbove b).castPred hk), ← castSucc_succAbove_castSucc, castSucc_castPred] lemma one_succAbove_zero {n : ℕ} : (1 : Fin (n + 2)).succAbove 0 = 0 := by rfl /-- By moving `succ` to the outside of this expression, we create opportunities for further simplification using `succAbove_zero` or `succ_succAbove_zero`. -/
@[simp] lemma succ_succAbove_one {n : ℕ} [NeZero n] (i : Fin (n + 1)) : i.succ.succAbove 1 = (i.succAbove 0).succ := by
Mathlib/Data/Fin/Basic.lean
1,157
1,158
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.Deriv.Slope import Mathlib.Analysis.Normed.Operator.BoundedLinearMaps import Mathlib.Analysis.Normed.Module.FiniteDimension import Mathlib.MeasureTheory.Constructions.BorelSpace.ContinuousLinearMap import Mathlib.MeasureTheory.Function.StronglyMeasurable.AEStronglyMeasurable /-! # Derivative is measurable In this file we prove that the derivative of any function with complete codomain is a measurable function. Namely, we prove: * `measurableSet_of_differentiableAt`: the set `{x | DifferentiableAt 𝕜 f x}` is measurable; * `measurable_fderiv`: the function `fderiv 𝕜 f` is measurable; * `measurable_fderiv_apply_const`: for a fixed vector `y`, the function `fun x ↦ fderiv 𝕜 f x y` is measurable; * `measurable_deriv`: the function `deriv f` is measurable (for `f : 𝕜 → F`). We also show the same results for the right derivative on the real line (see `measurable_derivWithin_Ici` and `measurable_derivWithin_Ioi`), following the same proof strategy. We also prove measurability statements for functions depending on a parameter: for `f : α → E → F`, we show the measurability of `(p : α × E) ↦ fderiv 𝕜 (f p.1) p.2`. This requires additional assumptions. We give versions of the above statements (appending `with_param` to their names) when `f` is continuous and `E` is locally compact. ## Implementation We give a proof that avoids second-countability issues, by expressing the differentiability set as a function of open sets in the following way. Define `A (L, r, ε)` to be the set of points where, on a ball of radius roughly `r` around `x`, the function is uniformly approximated by the linear map `L`, up to `ε r`. It is an open set. Let also `B (L, r, s, ε) = A (L, r, ε) ∩ A (L, s, ε)`: we require that at two possibly different scales `r` and `s`, the function is well approximated by the linear map `L`. It is also open. We claim that the differentiability set of `f` is exactly `D = ⋂ ε > 0, ⋃ δ > 0, ⋂ r, s < δ, ⋃ L, B (L, r, s, ε)`. In other words, for any `ε > 0`, we require that there is a size `δ` such that, for any two scales below this size, the function is well approximated by a linear map, common to the two scales. The set `⋃ L, B (L, r, s, ε)` is open, as a union of open sets. Converting the intersections and unions to countable ones (using real numbers of the form `2 ^ (-n)`), it follows that the differentiability set is measurable. To prove the claim, there are two inclusions. One is trivial: if the function is differentiable at `x`, then `x` belongs to `D` (just take `L` to be the derivative, and use that the differentiability exactly says that the map is well approximated by `L`). This is proved in `mem_A_of_differentiable` and `differentiable_set_subset_D`. For the other direction, the difficulty is that `L` in the union may depend on `ε, r, s`. The key point is that, in fact, it doesn't depend too much on them. First, if `x` belongs both to `A (L, r, ε)` and `A (L', r, ε)`, then `L` and `L'` have to be close on a shell, and thus `‖L - L'‖` is bounded by `ε` (see `norm_sub_le_of_mem_A`). Assume now `x ∈ D`. If one has two maps `L` and `L'` such that `x` belongs to `A (L, r, ε)` and to `A (L', r', ε')`, one deduces that `L` is close to `L'` by arguing as follows. Consider another scale `s` smaller than `r` and `r'`. Take a linear map `L₁` that approximates `f` around `x` both at scales `r` and `s` w.r.t. `ε` (it exists as `x` belongs to `D`). Take also `L₂` that approximates `f` around `x` both at scales `r'` and `s` w.r.t. `ε'`. Then `L₁` is close to `L` (as they are close on a shell of radius `r`), and `L₂` is close to `L₁` (as they are close on a shell of radius `s`), and `L'` is close to `L₂` (as they are close on a shell of radius `r'`). It follows that `L` is close to `L'`, as we claimed. It follows that the different approximating linear maps that show up form a Cauchy sequence when `ε` tends to `0`. When the target space is complete, this sequence converges, to a limit `f'`. With the same kind of arguments, one checks that `f` is differentiable with derivative `f'`. To show that the derivative itself is measurable, add in the definition of `B` and `D` a set `K` of continuous linear maps to which `L` should belong. Then, when `K` is complete, the set `D K` is exactly the set of points where `f` is differentiable with a derivative in `K`. ## Tags derivative, measurable function, Borel σ-algebra -/ noncomputable section open Set Metric Asymptotics Filter ContinuousLinearMap MeasureTheory TopologicalSpace open scoped Topology namespace ContinuousLinearMap variable {𝕜 E F : Type*} [NontriviallyNormedField 𝕜] [NormedAddCommGroup E] [NormedSpace 𝕜 E] [NormedAddCommGroup F] [NormedSpace 𝕜 F] theorem measurable_apply₂ [MeasurableSpace E] [OpensMeasurableSpace E] [SecondCountableTopologyEither (E →L[𝕜] F) E] [MeasurableSpace F] [BorelSpace F] : Measurable fun p : (E →L[𝕜] F) × E => p.1 p.2 := isBoundedBilinearMap_apply.continuous.measurable end ContinuousLinearMap section fderiv variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] variable {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {f : E → F} (K : Set (E →L[𝕜] F)) namespace FDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `L`, up to an error `ε`. We tweak the definition to make sure that this is an open set. -/ def A (f : E → F) (L : E →L[𝕜] F) (r ε : ℝ) : Set E := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ y ∈ ball x r', ∀ z ∈ ball x r', ‖f z - f y - L (z - y)‖ < ε * r } /-- The set `B f K r s ε` is the set of points `x` around which there exists a continuous linear map `L` belonging to `K` (a given set of continuous linear maps) that approximates well the function `f` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : E → F) (K : Set (E →L[𝕜] F)) (r s ε : ℝ) : Set E := ⋃ L ∈ K, A f L r ε ∩ A f L s ε /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : E → F) (K : Set (E →L[𝕜] F)) : Set E := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) theorem isOpen_A (L : E →L[𝕜] F) (r ε : ℝ) : IsOpen (A f L r ε) := by rw [Metric.isOpen_iff] rintro x ⟨r', r'_mem, hr'⟩ obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between r'_mem.1 have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le r'_mem.2)⟩ refine ⟨r' - s, by linarith, fun x' hx' => ⟨s, this, ?_⟩⟩ have B : ball x' s ⊆ ball x r' := ball_subset (le_of_lt hx') intro y hy z hz exact hr' y (B hy) z (B hz) theorem isOpen_B {K : Set (E →L[𝕜] F)} {r s ε : ℝ} : IsOpen (B f K r s ε) := by simp [B, isOpen_biUnion, IsOpen.inter, isOpen_A] theorem A_mono (L : E →L[𝕜] F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by rintro x ⟨r', r'r, hr'⟩ refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans_le (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [mem_ball.1 hy, r'r.2, @dist_nonneg _ _ y x] theorem le_of_mem_A {r ε : ℝ} {L : E →L[𝕜] F} {x : E} (hx : x ∈ A f L r ε) {y z : E} (hy : y ∈ closedBall x (r / 2)) (hz : z ∈ closedBall x (r / 2)) : ‖f z - f y - L (z - y)‖ ≤ ε * r := by rcases hx with ⟨r', r'mem, hr'⟩ apply le_of_lt exact hr' _ ((mem_closedBall.1 hy).trans_lt r'mem.1) _ ((mem_closedBall.1 hz).trans_lt r'mem.1) theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : E} (hx : DifferentiableAt 𝕜 f x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (fderiv 𝕜 f x) r ε := by let δ := (ε / 2) / 2 obtain ⟨R, R_pos, hR⟩ : ∃ R > 0, ∀ y ∈ ball x R, ‖f y - f x - fderiv 𝕜 f x (y - x)‖ ≤ δ * ‖y - x‖ := eventually_nhds_iff_ball.1 <| hx.hasFDerivAt.isLittleO.bound <| by positivity refine ⟨R, R_pos, fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := right_mem_Ioc.2 <| half_lt_self hr.1 refine ⟨r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (fderiv 𝕜 f x) (z - y)‖ = ‖f z - f x - (fderiv 𝕜 f x) (z - x) - (f y - f x - (fderiv 𝕜 f x) (y - x))‖ := by simp only [map_sub]; abel_nf _ ≤ ‖f z - f x - (fderiv 𝕜 f x) (z - x)‖ + ‖f y - f x - (fderiv 𝕜 f x) (y - x)‖ := norm_sub_le _ _ _ ≤ δ * ‖z - x‖ + δ * ‖y - x‖ := add_le_add (hR _ (ball_subset_ball hr.2.le hz)) (hR _ (ball_subset_ball hr.2.le hy)) _ ≤ δ * r + δ * r := by rw [mem_ball_iff_norm] at hz hy; gcongr _ = (ε / 2) * r := by ring _ < ε * r := by gcongr; exacts [hr.1, half_lt_self hε] theorem norm_sub_le_of_mem_A {c : 𝕜} (hc : 1 < ‖c‖) {r ε : ℝ} (hε : 0 < ε) (hr : 0 < r) {x : E} {L₁ L₂ : E →L[𝕜] F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ‖c‖ * ε := by refine opNorm_le_of_shell (half_pos hr) (by positivity) hc ?_ intro y ley ylt rw [div_div, div_le_iff₀' (mul_pos (by norm_num : (0 : ℝ) < 2) (zero_lt_one.trans hc))] at ley calc ‖(L₁ - L₂) y‖ = ‖f (x + y) - f x - L₂ (x + y - x) - (f (x + y) - f x - L₁ (x + y - x))‖ := by simp _ ≤ ‖f (x + y) - f x - L₂ (x + y - x)‖ + ‖f (x + y) - f x - L₁ (x + y - x)‖ := norm_sub_le _ _ _ ≤ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] · apply le_of_mem_A h₁ · simp only [le_of_lt (half_pos hr), mem_closedBall, dist_self] · simp only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, ylt.le] _ = 2 * ε * r := by ring _ ≤ 2 * ε * (2 * ‖c‖ * ‖y‖) := by gcongr _ = 4 * ‖c‖ * ε * ‖y‖ := by ring /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := by positivity rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟨n, fun p hp q hq => ⟨fderiv 𝕜 f x, hx.2, ⟨?_, ?_⟩⟩⟩ <;> · refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n rcases NormedField.exists_one_lt_norm 𝕜 with ⟨c, hc⟩ intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟨n, hn⟩ refine ⟨n, fun p q hp hq => ?_⟩ simp only [mem_iInter] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩ exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≤ p → n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A hc P P I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A hc P P I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * ‖c‖ * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A hc P P (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := norm_add₃_le _ ≤ 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e + 4 * ‖c‖ * (1 / 2) ^ e := by gcongr _ = 12 * ‖c‖ * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → E →L[𝕜] F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (12 * ‖c‖) := exists_pow_lt_of_lt_one (by positivity) (by norm_num) refine ⟨e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * ‖c‖ * (ε / (12 * ‖c‖)) := by gcongr _ = ε := by field_simp -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * ‖c‖ * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has derivative `f'` at `x`. have : HasFDerivAt f f' x := by simp only [hasFDerivAt_iff_isLittleO_nhds_zero, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole ball of radius `(1/2)^(n e)`. -/ intro ε εpos have pos : 0 < 4 + 12 * ‖c‖ := by positivity obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / (4 + 12 * ‖c‖) := exists_pow_lt_of_lt_one (div_pos εpos pos) (by norm_num) rw [eventually_nhds_iff_ball] refine ⟨(1 / 2) ^ (n e + 1), P, fun y hy => ?_⟩ -- We need to show that `f (x + y) - f x - f' y` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y‖ ∼ 2 ^ (-k)`. by_cases y_pos : y = 0 · simp [y_pos] have yzero : 0 < ‖y‖ := norm_pos_iff.mpr y_pos have y_lt : ‖y‖ < (1 / 2) ^ (n e + 1) := by simpa using mem_ball_iff_norm.1 hy have yone : ‖y‖ ≤ 1 := le_trans y_lt.le (pow_le_one₀ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < ‖y‖ ∧ ‖y‖ ≤ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_trans hk y_lt rw [pow_lt_pow_iff_right_of_lt_one₀ (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J1 : ‖f (x + y) - f x - L e (n e) m (x + y - x)‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [mem_closedBall, dist_self] positivity · simpa only [dist_eq_norm, add_sub_cancel_left, mem_closedBall, pow_succ, mul_one_div] using h'k have J2 : ‖f (x + y) - f x - L e (n e) m y‖ ≤ 4 * (1 / 2) ^ e * ‖y‖ := calc ‖f (x + y) - f x - L e (n e) m y‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by simpa only [add_sub_cancel_left] using J1 _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≤ 4 * (1 / 2) ^ e * ‖y‖ := by gcongr -- use the previous estimates to see that `f (x + y) - f x - f' y` is small. calc ‖f (x + y) - f x - f' y‖ = ‖f (x + y) - f x - L e (n e) m y + (L e (n e) m - f') y‖ := congr_arg _ (by simp) _ ≤ 4 * (1 / 2) ^ e * ‖y‖ + 12 * ‖c‖ * (1 / 2) ^ e * ‖y‖ := norm_add_le_of_le J2 <| (le_opNorm _ _).trans <| by gcongr; exact Lf' _ _ m_ge _ = (4 + 12 * ‖c‖) * ‖y‖ * (1 / 2) ^ e := by ring _ ≤ (4 + 12 * ‖c‖) * ‖y‖ * (ε / (4 + 12 * ‖c‖)) := by gcongr _ = ε * ‖y‖ := by field_simp [ne_of_gt pos]; ring rw [← this.fderiv] at f'K exact ⟨this.differentiableAt, f'K⟩ theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) end FDerivMeasurableAux open FDerivMeasurableAux variable [MeasurableSpace E] [OpensMeasurableSpace E] variable (𝕜 f) /-- The set of differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_of_isComplete {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ K } := by -- Porting note: was -- simp [differentiable_set_eq_D K hK, D, isOpen_B.measurableSet, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [D, differentiable_set_eq_D K hK] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact isOpen_B.measurableSet variable [CompleteSpace F] /-- The set of differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt : MeasurableSet { x | DifferentiableAt 𝕜 f x } := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete 𝕜 f this simp @[measurability, fun_prop] theorem measurable_fderiv : Measurable (fderiv 𝕜 f) := by refine measurable_of_isClosed fun s hs => ?_ have : fderiv 𝕜 f ⁻¹' s = { x | DifferentiableAt 𝕜 f x ∧ fderiv 𝕜 f x ∈ s } ∪ { x | ¬DifferentiableAt 𝕜 f x } ∩ { _x | (0 : E →L[𝕜] F) ∈ s } := Set.ext fun x => mem_preimage.trans fderiv_mem_iff rw [this] exact (measurableSet_of_differentiableAt_of_isComplete _ _ hs.isComplete).union ((measurableSet_of_differentiableAt _ _).compl.inter (MeasurableSet.const _)) @[measurability, fun_prop] theorem measurable_fderiv_apply_const [MeasurableSpace F] [BorelSpace F] (y : E) : Measurable fun x => fderiv 𝕜 f x y := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv 𝕜 f) variable {𝕜} @[measurability, fun_prop] theorem measurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) : Measurable (deriv f) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const 𝕜 f 1 theorem stronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) : StronglyMeasurable (deriv f) := by borelize F rcases h.out with h𝕜|hF · exact stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_deriv f, isSeparable_range_deriv _⟩ · exact (measurable_deriv f).stronglyMeasurable theorem aemeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] (f : 𝕜 → F) (μ : Measure 𝕜) : AEMeasurable (deriv f) μ := (measurable_deriv f).aemeasurable theorem aestronglyMeasurable_deriv [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [SecondCountableTopologyEither 𝕜 F] (f : 𝕜 → F) (μ : Measure 𝕜) : AEStronglyMeasurable (deriv f) μ := (stronglyMeasurable_deriv f).aestronglyMeasurable end fderiv section RightDeriv variable {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] variable {f : ℝ → F} (K : Set F) namespace RightDerivMeasurableAux /-- The set `A f L r ε` is the set of points `x` around which the function `f` is well approximated at scale `r` by the linear map `h ↦ h • L`, up to an error `ε`. We tweak the definition to make sure that this is open on the right. -/ def A (f : ℝ → F) (L : F) (r ε : ℝ) : Set ℝ := { x | ∃ r' ∈ Ioc (r / 2) r, ∀ᵉ (y ∈ Icc x (x + r')) (z ∈ Icc x (x + r')), ‖f z - f y - (z - y) • L‖ ≤ ε * r } /-- The set `B f K r s ε` is the set of points `x` around which there exists a vector `L` belonging to `K` (a given set of vectors) such that `h • L` approximates well `f (x + h)` (up to an error `ε`), simultaneously at scales `r` and `s`. -/ def B (f : ℝ → F) (K : Set F) (r s ε : ℝ) : Set ℝ := ⋃ L ∈ K, A f L r ε ∩ A f L s ε /-- The set `D f K` is a complicated set constructed using countable intersections and unions. Its main use is that, when `K` is complete, it is exactly the set of points where `f` is differentiable, with a derivative in `K`. -/ def D (f : ℝ → F) (K : Set F) : Set ℝ := ⋂ e : ℕ, ⋃ n : ℕ, ⋂ (p ≥ n) (q ≥ n), B f K ((1 / 2) ^ p) ((1 / 2) ^ q) ((1 / 2) ^ e) theorem A_mem_nhdsGT {L : F} {r ε x : ℝ} (hx : x ∈ A f L r ε) : A f L r ε ∈ 𝓝[>] x := by rcases hx with ⟨r', rr', hr'⟩ obtain ⟨s, s_gt, s_lt⟩ : ∃ s : ℝ, r / 2 < s ∧ s < r' := exists_between rr'.1 have : s ∈ Ioc (r / 2) r := ⟨s_gt, le_of_lt (s_lt.trans_le rr'.2)⟩ filter_upwards [Ioo_mem_nhdsGT <| show x < x + r' - s by linarith] with x' hx' use s, this have A : Icc x' (x' + s) ⊆ Icc x (x + r') := by apply Icc_subset_Icc hx'.1.le linarith [hx'.2] intro y hy z hz exact hr' y (A hy) z (A hz) theorem B_mem_nhdsGT {K : Set F} {r s ε x : ℝ} (hx : x ∈ B f K r s ε) : B f K r s ε ∈ 𝓝[>] x := by obtain ⟨L, LK, hL₁, hL₂⟩ : ∃ L : F, L ∈ K ∧ x ∈ A f L r ε ∧ x ∈ A f L s ε := by simpa only [B, mem_iUnion, mem_inter_iff, exists_prop] using hx filter_upwards [A_mem_nhdsGT hL₁, A_mem_nhdsGT hL₂] with y hy₁ hy₂ simp only [B, mem_iUnion, mem_inter_iff, exists_prop] exact ⟨L, LK, hy₁, hy₂⟩ theorem measurableSet_B {K : Set F} {r s ε : ℝ} : MeasurableSet (B f K r s ε) := .of_mem_nhdsGT fun _ hx => B_mem_nhdsGT hx theorem A_mono (L : F) (r : ℝ) {ε δ : ℝ} (h : ε ≤ δ) : A f L r ε ⊆ A f L r δ := by rintro x ⟨r', r'r, hr'⟩ refine ⟨r', r'r, fun y hy z hz => (hr' y hy z hz).trans (mul_le_mul_of_nonneg_right h ?_)⟩ linarith [hy.1, hy.2, r'r.2] theorem le_of_mem_A {r ε : ℝ} {L : F} {x : ℝ} (hx : x ∈ A f L r ε) {y z : ℝ} (hy : y ∈ Icc x (x + r / 2)) (hz : z ∈ Icc x (x + r / 2)) : ‖f z - f y - (z - y) • L‖ ≤ ε * r := by rcases hx with ⟨r', r'mem, hr'⟩ have A : x + r / 2 ≤ x + r' := by linarith [r'mem.1] exact hr' _ ((Icc_subset_Icc le_rfl A) hy) _ ((Icc_subset_Icc le_rfl A) hz) theorem mem_A_of_differentiable {ε : ℝ} (hε : 0 < ε) {x : ℝ} (hx : DifferentiableWithinAt ℝ f (Ici x) x) : ∃ R > 0, ∀ r ∈ Ioo (0 : ℝ) R, x ∈ A f (derivWithin f (Ici x) x) r ε := by have := hx.hasDerivWithinAt simp_rw [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] at this rcases mem_nhdsGE_iff_exists_Ico_subset.1 (this (half_pos hε)) with ⟨m, xm, hm⟩ refine ⟨m - x, by linarith [show x < m from xm], fun r hr => ?_⟩ have : r ∈ Ioc (r / 2) r := ⟨half_lt_self hr.1, le_rfl⟩ refine ⟨r, this, fun y hy z hz => ?_⟩ calc ‖f z - f y - (z - y) • derivWithin f (Ici x) x‖ = ‖f z - f x - (z - x) • derivWithin f (Ici x) x - (f y - f x - (y - x) • derivWithin f (Ici x) x)‖ := by congr 1; simp only [sub_smul]; abel _ ≤ ‖f z - f x - (z - x) • derivWithin f (Ici x) x‖ + ‖f y - f x - (y - x) • derivWithin f (Ici x) x‖ := (norm_sub_le _ _) _ ≤ ε / 2 * ‖z - x‖ + ε / 2 * ‖y - x‖ := (add_le_add (hm ⟨hz.1, hz.2.trans_lt (by linarith [hr.2])⟩) (hm ⟨hy.1, hy.2.trans_lt (by linarith [hr.2])⟩)) _ ≤ ε / 2 * r + ε / 2 * r := by gcongr · rw [Real.norm_of_nonneg] <;> linarith [hz.1, hz.2] · rw [Real.norm_of_nonneg] <;> linarith [hy.1, hy.2] _ = ε * r := by ring theorem norm_sub_le_of_mem_A {r x : ℝ} (hr : 0 < r) (ε : ℝ) {L₁ L₂ : F} (h₁ : x ∈ A f L₁ r ε) (h₂ : x ∈ A f L₂ r ε) : ‖L₁ - L₂‖ ≤ 4 * ε := by suffices H : ‖(r / 2) • (L₁ - L₂)‖ ≤ r / 2 * (4 * ε) by rwa [norm_smul, Real.norm_of_nonneg (half_pos hr).le, mul_le_mul_left (half_pos hr)] at H calc ‖(r / 2) • (L₁ - L₂)‖ = ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂ - (f (x + r / 2) - f x - (x + r / 2 - x) • L₁)‖ := by simp [smul_sub] _ ≤ ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₂‖ + ‖f (x + r / 2) - f x - (x + r / 2 - x) • L₁‖ := norm_sub_le _ _ _ ≤ ε * r + ε * r := by apply add_le_add · apply le_of_mem_A h₂ <;> simp [(half_pos hr).le] · apply le_of_mem_A h₁ <;> simp [(half_pos hr).le] _ = r / 2 * (4 * ε) := by ring /-- Easy inclusion: a differentiability point with derivative in `K` belongs to `D f K`. -/ theorem differentiable_set_subset_D : { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } ⊆ D f K := by intro x hx rw [D, mem_iInter] intro e have : (0 : ℝ) < (1 / 2) ^ e := pow_pos (by norm_num) _ rcases mem_A_of_differentiable this hx.1 with ⟨R, R_pos, hR⟩ obtain ⟨n, hn⟩ : ∃ n : ℕ, (1 / 2) ^ n < R := exists_pow_lt_of_lt_one R_pos (by norm_num : (1 : ℝ) / 2 < 1) simp only [mem_iUnion, mem_iInter, B, mem_inter_iff] refine ⟨n, fun p hp q hq => ⟨derivWithin f (Ici x) x, hx.2, ⟨?_, ?_⟩⟩⟩ <;> · refine hR _ ⟨pow_pos (by norm_num) _, lt_of_le_of_lt ?_ hn⟩ exact pow_le_pow_of_le_one (by norm_num) (by norm_num) (by assumption) /-- Harder inclusion: at a point in `D f K`, the function `f` has a derivative, in `K`. -/ theorem D_subset_differentiable_set {K : Set F} (hK : IsComplete K) : D f K ⊆ { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by have P : ∀ {n : ℕ}, (0 : ℝ) < (1 / 2) ^ n := fun {n} => pow_pos (by norm_num) n intro x hx have : ∀ e : ℕ, ∃ n : ℕ, ∀ p q, n ≤ p → n ≤ q → ∃ L ∈ K, x ∈ A f L ((1 / 2) ^ p) ((1 / 2) ^ e) ∩ A f L ((1 / 2) ^ q) ((1 / 2) ^ e) := by intro e have := mem_iInter.1 hx e rcases mem_iUnion.1 this with ⟨n, hn⟩ refine ⟨n, fun p q hp hq => ?_⟩ simp only [mem_iInter] at hn rcases mem_iUnion.1 (hn p hp q hq) with ⟨L, hL⟩ exact ⟨L, exists_prop.mp <| mem_iUnion.1 hL⟩ /- Recast the assumptions: for each `e`, there exist `n e` and linear maps `L e p q` in `K` such that, for `p, q ≥ n e`, then `f` is well approximated by `L e p q` at scale `2 ^ (-p)` and `2 ^ (-q)`, with an error `2 ^ (-e)`. -/ choose! n L hn using this /- All the operators `L e p q` that show up are close to each other. To prove this, we argue that `L e p q` is close to `L e p r` (where `r` is large enough), as both approximate `f` at scale `2 ^(- p)`. And `L e p r` is close to `L e' p' r` as both approximate `f` at scale `2 ^ (- r)`. And `L e' p' r` is close to `L e' p' q'` as both approximate `f` at scale `2 ^ (- p')`. -/ have M : ∀ e p q e' p' q', n e ≤ p → n e ≤ q → n e' ≤ p' → n e' ≤ q' → e ≤ e' → ‖L e p q - L e' p' q'‖ ≤ 12 * (1 / 2) ^ e := by intro e p q e' p' q' hp hq hp' hq' he' let r := max (n e) (n e') have I : ((1 : ℝ) / 2) ^ e' ≤ (1 / 2) ^ e := pow_le_pow_of_le_one (by norm_num) (by norm_num) he' have J1 : ‖L e p q - L e p r‖ ≤ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p q) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p q hp hq).2.1 have I2 : x ∈ A f (L e p r) ((1 / 2) ^ p) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.1 exact norm_sub_le_of_mem_A P _ I1 I2 have J2 : ‖L e p r - L e' p' r‖ ≤ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e p r) ((1 / 2) ^ r) ((1 / 2) ^ e) := (hn e p r hp (le_max_left _ _)).2.2 have I2 : x ∈ A f (L e' p' r) ((1 / 2) ^ r) ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.2 exact norm_sub_le_of_mem_A P _ I1 (A_mono _ _ I I2) have J3 : ‖L e' p' r - L e' p' q'‖ ≤ 4 * (1 / 2) ^ e := by have I1 : x ∈ A f (L e' p' r) ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' r hp' (le_max_right _ _)).2.1 have I2 : x ∈ A f (L e' p' q') ((1 / 2) ^ p') ((1 / 2) ^ e') := (hn e' p' q' hp' hq').2.1 exact norm_sub_le_of_mem_A P _ (A_mono _ _ I I1) (A_mono _ _ I I2) calc ‖L e p q - L e' p' q'‖ = ‖L e p q - L e p r + (L e p r - L e' p' r) + (L e' p' r - L e' p' q')‖ := by congr 1; abel _ ≤ ‖L e p q - L e p r‖ + ‖L e p r - L e' p' r‖ + ‖L e' p' r - L e' p' q'‖ := (le_trans (norm_add_le _ _) (add_le_add_right (norm_add_le _ _) _)) _ ≤ 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e + 4 * (1 / 2) ^ e := by gcongr _ = 12 * (1 / 2) ^ e := by ring /- For definiteness, use `L0 e = L e (n e) (n e)`, to have a single sequence. We claim that this is a Cauchy sequence. -/ let L0 : ℕ → F := fun e => L e (n e) (n e) have : CauchySeq L0 := by rw [Metric.cauchySeq_iff'] intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 12 := exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num) refine ⟨e, fun e' he' => ?_⟩ rw [dist_comm, dist_eq_norm] calc ‖L0 e - L0 e'‖ ≤ 12 * (1 / 2) ^ e := M _ _ _ _ _ _ le_rfl le_rfl le_rfl le_rfl he' _ < 12 * (ε / 12) := mul_lt_mul' le_rfl he (le_of_lt P) (by norm_num) _ = ε := by field_simp [(by norm_num : (12 : ℝ) ≠ 0)] -- As it is Cauchy, the sequence `L0` converges, to a limit `f'` in `K`. obtain ⟨f', f'K, hf'⟩ : ∃ f' ∈ K, Tendsto L0 atTop (𝓝 f') := cauchySeq_tendsto_of_isComplete hK (fun e => (hn e (n e) (n e) le_rfl le_rfl).1) this have Lf' : ∀ e p, n e ≤ p → ‖L e (n e) p - f'‖ ≤ 12 * (1 / 2) ^ e := by intro e p hp apply le_of_tendsto (tendsto_const_nhds.sub hf').norm rw [eventually_atTop] exact ⟨e, fun e' he' => M _ _ _ _ _ _ le_rfl hp le_rfl le_rfl he'⟩ -- Let us show that `f` has right derivative `f'` at `x`. have : HasDerivWithinAt f f' (Ici x) x := by simp only [hasDerivWithinAt_iff_isLittleO, isLittleO_iff] /- to get an approximation with a precision `ε`, we will replace `f` with `L e (n e) m` for some large enough `e` (yielding a small error by uniform approximation). As one can vary `m`, this makes it possible to cover all scales, and thus to obtain a good linear approximation in the whole interval of length `(1/2)^(n e)`. -/ intro ε εpos obtain ⟨e, he⟩ : ∃ e : ℕ, (1 / 2) ^ e < ε / 16 := exists_pow_lt_of_lt_one (div_pos εpos (by norm_num)) (by norm_num) filter_upwards [Icc_mem_nhdsGE <| show x < x + (1 / 2) ^ (n e + 1) by simp] with y hy -- We need to show that `f y - f x - f' (y - x)` is small. For this, we will work at scale -- `k` where `k` is chosen with `‖y - x‖ ∼ 2 ^ (-k)`. rcases eq_or_lt_of_le hy.1 with (rfl | xy) · simp only [sub_self, zero_smul, norm_zero, mul_zero, le_rfl] have yzero : 0 < y - x := sub_pos.2 xy have y_le : y - x ≤ (1 / 2) ^ (n e + 1) := by linarith [hy.2] have yone : y - x ≤ 1 := le_trans y_le (pow_le_one₀ (by norm_num) (by norm_num)) -- define the scale `k`. obtain ⟨k, hk, h'k⟩ : ∃ k : ℕ, (1 / 2) ^ (k + 1) < y - x ∧ y - x ≤ (1 / 2) ^ k := exists_nat_pow_near_of_lt_one yzero yone (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 : ℝ) / 2 < 1) -- the scale is large enough (as `y - x` is small enough) have k_gt : n e < k := by have : ((1 : ℝ) / 2) ^ (k + 1) < (1 / 2) ^ (n e + 1) := lt_of_lt_of_le hk y_le rw [pow_lt_pow_iff_right_of_lt_one₀ (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num)] at this omega set m := k - 1 have m_ge : n e ≤ m := Nat.le_sub_one_of_lt k_gt have km : k = m + 1 := (Nat.succ_pred_eq_of_pos (lt_of_le_of_lt (zero_le _) k_gt)).symm rw [km] at hk h'k -- `f` is well approximated by `L e (n e) k` at the relevant scale -- (in fact, we use `m = k - 1` instead of `k` because of the precise definition of `A`). have J : ‖f y - f x - (y - x) • L e (n e) m‖ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ := calc ‖f y - f x - (y - x) • L e (n e) m‖ ≤ (1 / 2) ^ e * (1 / 2) ^ m := by apply le_of_mem_A (hn e (n e) m le_rfl m_ge).2.2 · simp only [one_div, inv_pow, left_mem_Icc, le_add_iff_nonneg_right] positivity · simp only [pow_add, tsub_le_iff_left] at h'k simpa only [hy.1, mem_Icc, true_and, one_div, pow_one] using h'k _ = 4 * (1 / 2) ^ e * (1 / 2) ^ (m + 2) := by field_simp; ring _ ≤ 4 * (1 / 2) ^ e * (y - x) := by gcongr _ = 4 * (1 / 2) ^ e * ‖y - x‖ := by rw [Real.norm_of_nonneg yzero.le] calc ‖f y - f x - (y - x) • f'‖ = ‖f y - f x - (y - x) • L e (n e) m + (y - x) • (L e (n e) m - f')‖ := by simp only [smul_sub, sub_add_sub_cancel] _ ≤ 4 * (1 / 2) ^ e * ‖y - x‖ + ‖y - x‖ * (12 * (1 / 2) ^ e) := norm_add_le_of_le J <| by rw [norm_smul]; gcongr; exact Lf' _ _ m_ge _ = 16 * ‖y - x‖ * (1 / 2) ^ e := by ring _ ≤ 16 * ‖y - x‖ * (ε / 16) := by gcongr _ = ε * ‖y - x‖ := by ring rw [← this.derivWithin (uniqueDiffOn_Ici x x Set.left_mem_Ici)] at f'K exact ⟨this.differentiableWithinAt, f'K⟩ theorem differentiable_set_eq_D (hK : IsComplete K) : { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } = D f K := Subset.antisymm (differentiable_set_subset_D _) (D_subset_differentiable_set hK) end RightDerivMeasurableAux open RightDerivMeasurableAux variable (f) /-- The set of right differentiability points of a function, with derivative in a given complete set, is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ici_of_isComplete {K : Set F} (hK : IsComplete K) : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ K } := by -- simp [differentiable_set_eq_d K hK, D, measurableSet_b, MeasurableSet.iInter, -- MeasurableSet.iUnion] simp only [differentiable_set_eq_D K hK, D] repeat apply_rules [MeasurableSet.iUnion, MeasurableSet.iInter] <;> intro exact measurableSet_B variable [CompleteSpace F] /-- The set of right differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ici : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ici x) x } := by have : IsComplete (univ : Set F) := complete_univ convert measurableSet_of_differentiableWithinAt_Ici_of_isComplete f this simp @[measurability, fun_prop] theorem measurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] : Measurable fun x => derivWithin f (Ici x) x := by refine measurable_of_isClosed fun s hs => ?_ have : (fun x => derivWithin f (Ici x) x) ⁻¹' s = { x | DifferentiableWithinAt ℝ f (Ici x) x ∧ derivWithin f (Ici x) x ∈ s } ∪ { x | ¬DifferentiableWithinAt ℝ f (Ici x) x } ∩ { _x | (0 : F) ∈ s } := Set.ext fun x => mem_preimage.trans derivWithin_mem_iff rw [this] exact (measurableSet_of_differentiableWithinAt_Ici_of_isComplete _ hs.isComplete).union ((measurableSet_of_differentiableWithinAt_Ici _).compl.inter (MeasurableSet.const _)) theorem stronglyMeasurable_derivWithin_Ici : StronglyMeasurable (fun x ↦ derivWithin f (Ici x) x) := by borelize F apply stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_derivWithin_Ici f, ?_⟩ obtain ⟨t, t_count, ht⟩ : ∃ t : Set ℝ, t.Countable ∧ Dense t := exists_countable_dense ℝ suffices H : range (fun x ↦ derivWithin f (Ici x) x) ⊆ closure (Submodule.span ℝ (f '' t)) from IsSeparable.mono (t_count.image f).isSeparable.span.closure H rintro - ⟨x, rfl⟩ suffices H' : range (fun y ↦ derivWithin f (Ici x) y) ⊆ closure (Submodule.span ℝ (f '' t)) from H' (mem_range_self _) apply range_derivWithin_subset_closure_span_image calc Ici x = closure (Ioi x ∩ closure t) := by simp [dense_iff_closure_eq.1 ht] _ ⊆ closure (closure (Ioi x ∩ t)) := by apply closure_mono simpa [inter_comm] using (isOpen_Ioi (a := x)).closure_inter (s := t) _ ⊆ closure (Ici x ∩ t) := by rw [closure_closure] exact closure_mono (inter_subset_inter_left _ Ioi_subset_Ici_self) theorem aemeasurable_derivWithin_Ici [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) : AEMeasurable (fun x => derivWithin f (Ici x) x) μ := (measurable_derivWithin_Ici f).aemeasurable theorem aestronglyMeasurable_derivWithin_Ici (μ : Measure ℝ) : AEStronglyMeasurable (fun x => derivWithin f (Ici x) x) μ := (stronglyMeasurable_derivWithin_Ici f).aestronglyMeasurable /-- The set of right differentiability points of a function taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableWithinAt_Ioi : MeasurableSet { x | DifferentiableWithinAt ℝ f (Ioi x) x } := by simpa [differentiableWithinAt_Ioi_iff_Ici] using measurableSet_of_differentiableWithinAt_Ici f @[measurability, fun_prop] theorem measurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] : Measurable fun x => derivWithin f (Ioi x) x := by simpa [derivWithin_Ioi_eq_Ici] using measurable_derivWithin_Ici f theorem stronglyMeasurable_derivWithin_Ioi : StronglyMeasurable (fun x ↦ derivWithin f (Ioi x) x) := by simpa [derivWithin_Ioi_eq_Ici] using stronglyMeasurable_derivWithin_Ici f theorem aemeasurable_derivWithin_Ioi [MeasurableSpace F] [BorelSpace F] (μ : Measure ℝ) : AEMeasurable (fun x => derivWithin f (Ioi x) x) μ := (measurable_derivWithin_Ioi f).aemeasurable theorem aestronglyMeasurable_derivWithin_Ioi (μ : Measure ℝ) : AEStronglyMeasurable (fun x => derivWithin f (Ioi x) x) μ := (stronglyMeasurable_derivWithin_Ioi f).aestronglyMeasurable end RightDeriv section WithParam /- In this section, we prove the measurability of the derivative in a context with parameters: given `f : α → E → F`, we want to show that `p ↦ fderiv 𝕜 (f p.1) p.2` is measurable. Contrary to the previous sections, some assumptions are needed for this: if `f p.1` depends arbitrarily on `p.1`, this is obviously false. We require that `f` is continuous and `E` is locally compact -- then the proofs in the previous sections adapt readily, as the set `A` defined above is open, so that the differentiability set `D` is measurable. -/ variable {𝕜 : Type*} [NontriviallyNormedField 𝕜] {E : Type*} [NormedAddCommGroup E] [NormedSpace 𝕜 E] [LocallyCompactSpace E] {F : Type*} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {α : Type*} [TopologicalSpace α] {f : α → E → F} namespace FDerivMeasurableAux open Uniformity lemma isOpen_A_with_param {r s : ℝ} (hf : Continuous f.uncurry) (L : E →L[𝕜] F) : IsOpen {p : α × E | p.2 ∈ A (f p.1) L r s} := by have : ProperSpace E := .of_locallyCompactSpace 𝕜 simp only [A, half_lt_self_iff, not_lt, mem_Ioc, mem_ball, map_sub, mem_setOf_eq] apply isOpen_iff_mem_nhds.2 rintro ⟨a, x⟩ ⟨r', ⟨Irr', Ir'r⟩, hr⟩ have ha : Continuous (f a) := hf.uncurry_left a rcases exists_between Irr' with ⟨t, hrt, htr'⟩ rcases exists_between hrt with ⟨t', hrt', ht't⟩ obtain ⟨b, b_lt, hb⟩ : ∃ b, b < s * r ∧ ∀ y ∈ closedBall x t, ∀ z ∈ closedBall x t, ‖f a z - f a y - (L z - L y)‖ ≤ b := by have B : Continuous (fun (p : E × E) ↦ ‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖) := by fun_prop have C : (closedBall x t ×ˢ closedBall x t).Nonempty := by simp; linarith rcases ((isCompact_closedBall x t).prod (isCompact_closedBall x t)).exists_isMaxOn C B.continuousOn with ⟨p, pt, hp⟩ simp only [mem_prod, mem_closedBall] at pt refine ⟨‖f a p.2 - f a p.1 - (L p.2 - L p.1)‖, hr p.1 (pt.1.trans_lt htr') p.2 (pt.2.trans_lt htr'), fun y hy z hz ↦ ?_⟩ have D : (y, z) ∈ closedBall x t ×ˢ closedBall x t := mem_prod.2 ⟨hy, hz⟩ exact hp D obtain ⟨ε, εpos, hε⟩ : ∃ ε, 0 < ε ∧ b + 2 * ε < s * r := ⟨(s * r - b) / 3, by linarith, by linarith⟩ obtain ⟨u, u_open, au, hu⟩ : ∃ u, IsOpen u ∧ a ∈ u ∧ ∀ (p : α × E), p.1 ∈ u → p.2 ∈ closedBall x t → dist (f.uncurry p) (f.uncurry (a, p.2)) < ε := by have C : Continuous (fun (p : α × E) ↦ f a p.2) := by fun_prop have D : ({a} ×ˢ closedBall x t).EqOn f.uncurry (fun p ↦ f a p.2) := by rintro ⟨b, y⟩ ⟨hb, -⟩ simp only [mem_singleton_iff] at hb simp [hb] obtain ⟨v, v_open, sub_v, hv⟩ : ∃ v, IsOpen v ∧ {a} ×ˢ closedBall x t ⊆ v ∧ ∀ p ∈ v, dist (Function.uncurry f p) (f a p.2) < ε := Uniform.exists_is_open_mem_uniformity_of_forall_mem_eq (s := {a} ×ˢ closedBall x t) (fun p _ ↦ hf.continuousAt) (fun p _ ↦ C.continuousAt) D (dist_mem_uniformity εpos) obtain ⟨w, w', w_open, -, sub_w, sub_w', hww'⟩ : ∃ (w : Set α) (w' : Set E), IsOpen w ∧ IsOpen w' ∧ {a} ⊆ w ∧ closedBall x t ⊆ w' ∧ w ×ˢ w' ⊆ v := generalized_tube_lemma isCompact_singleton (isCompact_closedBall x t) v_open sub_v refine ⟨w, w_open, sub_w rfl, ?_⟩ rintro ⟨b, y⟩ h hby exact hv _ (hww' ⟨h, sub_w' hby⟩) have : u ×ˢ ball x (t - t') ∈ 𝓝 (a, x) := prod_mem_nhds (u_open.mem_nhds au) (ball_mem_nhds _ (sub_pos.2 ht't)) filter_upwards [this] rintro ⟨a', x'⟩ ha'x' simp only [mem_prod, mem_ball] at ha'x' refine ⟨t', ⟨hrt', ht't.le.trans (htr'.le.trans Ir'r)⟩, fun y hy z hz ↦ ?_⟩ have dyx : dist y x ≤ t := by linarith [dist_triangle y x' x] have dzx : dist z x ≤ t := by linarith [dist_triangle z x' x] calc ‖f a' z - f a' y - (L z - L y)‖ = ‖(f a' z - f a z) + (f a y - f a' y) + (f a z - f a y - (L z - L y))‖ := by congr; abel _ ≤ ‖f a' z - f a z‖ + ‖f a y - f a' y‖ + ‖f a z - f a y - (L z - L y)‖ := norm_add₃_le _ ≤ ε + ε + b := by gcongr · rw [← dist_eq_norm] change dist (f.uncurry (a', z)) (f.uncurry (a, z)) ≤ ε apply (hu _ _ _).le · exact ha'x'.1 · simp [dzx] · rw [← dist_eq_norm'] change dist (f.uncurry (a', y)) (f.uncurry (a, y)) ≤ ε apply (hu _ _ _).le · exact ha'x'.1 · simp [dyx] · simp [hb, dyx, dzx] _ < s * r := by linarith lemma isOpen_B_with_param {r s t : ℝ} (hf : Continuous f.uncurry) (K : Set (E →L[𝕜] F)) : IsOpen {p : α × E | p.2 ∈ B (f p.1) K r s t} := by suffices H : IsOpen (⋃ L ∈ K, {p : α × E | p.2 ∈ A (f p.1) L r t ∧ p.2 ∈ A (f p.1) L s t}) by convert H; ext p; simp [B] refine isOpen_biUnion (fun L _ ↦ ?_) exact (isOpen_A_with_param hf L).inter (isOpen_A_with_param hf L) end FDerivMeasurableAux open FDerivMeasurableAux variable [MeasurableSpace α] [OpensMeasurableSpace α] [MeasurableSpace E] [OpensMeasurableSpace E] theorem measurableSet_of_differentiableAt_of_isComplete_with_param (hf : Continuous f.uncurry) {K : Set (E →L[𝕜] F)} (hK : IsComplete K) : MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} := by have : {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ K} = {p : α × E | p.2 ∈ D (f p.1) K} := by simp [← differentiable_set_eq_D K hK] rw [this] simp only [D, mem_iInter, mem_iUnion] simp only [setOf_forall, setOf_exists] refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iUnion (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) refine MeasurableSet.iInter (fun _ ↦ ?_) have : ProperSpace E := .of_locallyCompactSpace 𝕜 exact (isOpen_B_with_param hf K).measurableSet variable (𝕜) variable [CompleteSpace F] /-- The set of differentiability points of a continuous function depending on a parameter taking values in a complete space is Borel-measurable. -/ theorem measurableSet_of_differentiableAt_with_param (hf : Continuous f.uncurry) : MeasurableSet {p : α × E | DifferentiableAt 𝕜 (f p.1) p.2} := by have : IsComplete (univ : Set (E →L[𝕜] F)) := complete_univ convert measurableSet_of_differentiableAt_of_isComplete_with_param hf this simp theorem measurable_fderiv_with_param (hf : Continuous f.uncurry) : Measurable (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2) := by refine measurable_of_isClosed (fun s hs ↦ ?_) have : (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2) ⁻¹' s = {p | DifferentiableAt 𝕜 (f p.1) p.2 ∧ fderiv 𝕜 (f p.1) p.2 ∈ s } ∪ { p | ¬DifferentiableAt 𝕜 (f p.1) p.2} ∩ { _p | (0 : E →L[𝕜] F) ∈ s} := Set.ext (fun x ↦ mem_preimage.trans fderiv_mem_iff) rw [this] exact (measurableSet_of_differentiableAt_of_isComplete_with_param hf hs.isComplete).union ((measurableSet_of_differentiableAt_with_param _ hf).compl.inter (MeasurableSet.const _)) theorem measurable_fderiv_apply_const_with_param [MeasurableSpace F] [BorelSpace F] (hf : Continuous f.uncurry) (y : E) : Measurable (fun (p : α × E) ↦ fderiv 𝕜 (f p.1) p.2 y) := (ContinuousLinearMap.measurable_apply y).comp (measurable_fderiv_with_param 𝕜 hf) variable {𝕜} theorem measurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [MeasurableSpace F] [BorelSpace F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) :
Measurable (fun (p : α × 𝕜) ↦ deriv (f p.1) p.2) := by simpa only [fderiv_deriv] using measurable_fderiv_apply_const_with_param 𝕜 hf 1 theorem stronglyMeasurable_deriv_with_param [LocallyCompactSpace 𝕜] [MeasurableSpace 𝕜] [OpensMeasurableSpace 𝕜] [h : SecondCountableTopologyEither α F] {f : α → 𝕜 → F} (hf : Continuous f.uncurry) : StronglyMeasurable (fun (p : α × 𝕜) ↦ deriv (f p.1) p.2) := by borelize F rcases h.out with hα|hF · have : ProperSpace 𝕜 := .of_locallyCompactSpace 𝕜 apply stronglyMeasurable_iff_measurable_separable.2 ⟨measurable_deriv_with_param hf, ?_⟩ have : range (fun (p : α × 𝕜) ↦ deriv (f p.1) p.2) ⊆ closure (Submodule.span 𝕜 (range f.uncurry)) := by rintro - ⟨p, rfl⟩ have A : deriv (f p.1) p.2 ∈ closure (Submodule.span 𝕜 (range (f p.1))) := by rw [← image_univ]
Mathlib/Analysis/Calculus/FDeriv/Measurable.lean
924
939
/- 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, Sander Dahmen, Kim Morrison -/ import Mathlib.SetTheory.Cardinal.Cofinality import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.Dimension.StrongRankCondition import Mathlib.LinearAlgebra.Dimension.Constructions /-! # Conditions for rank to be finite Also contains characterization for when rank equals zero or rank equals one. -/ noncomputable section universe u v v' w variable {R : Type u} {M M₁ : Type v} {M' : Type v'} {ι : Type w} variable [Ring R] [AddCommGroup M] [AddCommGroup M'] [AddCommGroup M₁] variable [Module R M] [Module R M'] [Module R M₁] attribute [local instance] nontrivial_of_invariantBasisNumber open Basis Cardinal Function Module Set Submodule /-- If every finite set of linearly independent vectors has cardinality at most `n`, then the same is true for arbitrary sets of linearly independent vectors. -/ theorem linearIndependent_bounded_of_finset_linearIndependent_bounded {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : ∀ s : Set M, LinearIndependent R ((↑) : s → M) → #s ≤ n := by intro s li apply Cardinal.card_le_of intro t rw [← Finset.card_map (Embedding.subtype s)] apply H apply linearIndependent_finset_map_embedding_subtype _ li theorem rank_le {n : ℕ} (H : ∀ s : Finset M, (LinearIndependent R fun i : s => (i : M)) → s.card ≤ n) : Module.rank R M ≤ n := by rw [Module.rank_def] apply ciSup_le' rintro ⟨s, li⟩ exact linearIndependent_bounded_of_finset_linearIndependent_bounded H _ li section RankZero /-- See `rank_zero_iff` for a stronger version with `NoZeroSMulDivisor R M`. -/ lemma rank_eq_zero_iff : Module.rank R M = 0 ↔ ∀ x : M, ∃ a : R, a ≠ 0 ∧ a • x = 0 := by nontriviality R constructor · contrapose! rintro ⟨x, hx⟩ rw [← Cardinal.one_le_iff_ne_zero] have : LinearIndependent R (fun _ : Unit ↦ x) := linearIndependent_iff.mpr (fun l hl ↦ Finsupp.unique_ext <| not_not.mp fun H ↦ hx _ H ((Finsupp.linearCombination_unique _ _ _).symm.trans hl)) simpa using this.cardinal_lift_le_rank · intro h rw [← le_zero_iff, Module.rank_def] apply ciSup_le' intro ⟨s, hs⟩ rw [nonpos_iff_eq_zero, Cardinal.mk_eq_zero_iff, ← not_nonempty_iff] rintro ⟨i : s⟩ obtain ⟨a, ha, ha'⟩ := h i apply ha simpa using DFunLike.congr_fun (linearIndependent_iff.mp hs (Finsupp.single i a) (by simpa)) i theorem rank_pos_of_free [Module.Free R M] [Nontrivial M] : 0 < Module.rank R M := have := Module.nontrivial R M (pos_of_ne_zero <| Cardinal.mk_ne_zero _).trans_le (Free.chooseBasis R M).linearIndependent.cardinal_le_rank variable [Nontrivial R] section variable [NoZeroSMulDivisors R M] theorem rank_zero_iff_forall_zero : Module.rank R M = 0 ↔ ∀ x : M, x = 0 := by simp_rw [rank_eq_zero_iff, smul_eq_zero, and_or_left, not_and_self_iff, false_or, exists_and_right, and_iff_right (exists_ne (0 : R))] /-- See `rank_subsingleton` for the reason that `Nontrivial R` is needed. Also see `rank_eq_zero_iff` for the version without `NoZeroSMulDivisor R M`. -/ theorem rank_zero_iff : Module.rank R M = 0 ↔ Subsingleton M := rank_zero_iff_forall_zero.trans (subsingleton_iff_forall_eq 0).symm theorem rank_pos_iff_exists_ne_zero : 0 < Module.rank R M ↔ ∃ x : M, x ≠ 0 := by rw [← not_iff_not] simpa using rank_zero_iff_forall_zero theorem rank_pos_iff_nontrivial : 0 < Module.rank R M ↔ Nontrivial M := rank_pos_iff_exists_ne_zero.trans (nontrivial_iff_exists_ne 0).symm theorem rank_pos [Nontrivial M] : 0 < Module.rank R M := rank_pos_iff_nontrivial.mpr ‹_› end variable (R M) /-- See `rank_subsingleton` that assumes `Subsingleton R` instead. -/ @[nontriviality] theorem rank_subsingleton' [Subsingleton M] : Module.rank R M = 0 := rank_eq_zero_iff.mpr fun _ ↦ ⟨1, one_ne_zero, Subsingleton.elim _ _⟩ @[simp] theorem rank_punit : Module.rank R PUnit = 0 := rank_subsingleton' _ _ @[simp] theorem rank_bot : Module.rank R (⊥ : Submodule R M) = 0 := rank_subsingleton' _ _ variable {R M} theorem exists_mem_ne_zero_of_rank_pos {s : Submodule R M} (h : 0 < Module.rank R s) : ∃ b : M, b ∈ s ∧ b ≠ 0 := exists_mem_ne_zero_of_ne_bot fun eq => by rw [eq, rank_bot] at h; exact lt_irrefl _ h end RankZero section Finite theorem Module.finite_of_rank_eq_nat [Module.Free R M] {n : ℕ} (h : Module.rank R M = n) : Module.Finite R M := by nontriviality R obtain ⟨⟨ι, b⟩⟩ := Module.Free.exists_basis (R := R) (M := M) have := mk_lt_aleph0_iff.mp <| b.linearIndependent.cardinal_le_rank |>.trans_eq h |>.trans_lt <| nat_lt_aleph0 n exact Module.Finite.of_basis b theorem Module.finite_of_rank_eq_zero [NoZeroSMulDivisors R M] (h : Module.rank R M = 0) : Module.Finite R M := by nontriviality R rw [rank_zero_iff] at h infer_instance theorem Module.finite_of_rank_eq_one [Module.Free R M] (h : Module.rank R M = 1) : Module.Finite R M := Module.finite_of_rank_eq_nat <| h.trans Nat.cast_one.symm section variable [StrongRankCondition R] /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ theorem Basis.nonempty_fintype_index_of_rank_lt_aleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Nonempty (Fintype ι) := by rwa [← Cardinal.lift_lt, ← b.mk_eq_rank, Cardinal.lift_aleph0, Cardinal.lift_lt_aleph0, Cardinal.lt_aleph0_iff_fintype] at h /-- If a module has a finite dimension, all bases are indexed by a finite type. -/ noncomputable def Basis.fintypeIndexOfRankLtAleph0 {ι : Type*} (b : Basis ι R M) (h : Module.rank R M < ℵ₀) : Fintype ι := Classical.choice (b.nonempty_fintype_index_of_rank_lt_aleph0 h) /-- If a module has a finite dimension, all bases are indexed by a finite set. -/ theorem Basis.finite_index_of_rank_lt_aleph0 {ι : Type*} {s : Set ι} (b : Basis s R M) (h : Module.rank R M < ℵ₀) : s.Finite := finite_def.2 (b.nonempty_fintype_index_of_rank_lt_aleph0 h) end namespace LinearIndependent variable [StrongRankCondition R] theorem cardinalMk_le_finrank [Module.Finite R M] {ι : Type w} {b : ι → M} (h : LinearIndependent R b) : #ι ≤ finrank R M := by rw [← lift_le.{max v w}] simpa only [← finrank_eq_rank, lift_natCast, lift_le_nat_iff] using h.cardinal_lift_le_rank
@[deprecated (since := "2024-11-10")] alias cardinal_mk_le_finrank := cardinalMk_le_finrank theorem fintype_card_le_finrank [Module.Finite R M] {ι : Type*} [Fintype ι] {b : ι → M} (h : LinearIndependent R b) : Fintype.card ι ≤ finrank R M := by
Mathlib/LinearAlgebra/Dimension/Finite.lean
179
183
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot -/ import Mathlib.Order.Filter.SmallSets import Mathlib.Topology.UniformSpace.Defs import Mathlib.Topology.ContinuousOn /-! # Basic results on uniform spaces Uniform spaces are a generalization of metric spaces and topological groups. ## Main definitions In this file we define a complete lattice structure on the type `UniformSpace X` of uniform structures on `X`, as well as the pullback (`UniformSpace.comap`) of uniform structures coming from the pullback of filters. Like distance functions, uniform structures cannot be pushed forward in general. ## Notations Localized in `Uniformity`, we have the notation `𝓤 X` for the uniformity on a uniform space `X`, and `○` for composition of relations, seen as terms with type `Set (X × X)`. ## References The formalization uses the books: * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] But it makes a more systematic use of the filter library. -/ open Set Filter Topology universe u v ua ub uc ud /-! ### Relations, seen as `Set (α × α)` -/ variable {α : Type ua} {β : Type ub} {γ : Type uc} {δ : Type ud} {ι : Sort*} open Uniformity section UniformSpace variable [UniformSpace α] /-- If `s ∈ 𝓤 α`, then for any natural `n`, for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ○ ... ○ t ⊆ s` (`n` compositions). -/ theorem eventually_uniformity_iterate_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) (n : ℕ) : ∀ᶠ t in (𝓤 α).smallSets, (t ○ ·)^[n] t ⊆ s := by suffices ∀ᶠ t in (𝓤 α).smallSets, t ⊆ s ∧ (t ○ ·)^[n] t ⊆ s from (eventually_and.1 this).2 induction n generalizing s with | zero => simpa | succ _ ihn => rcases comp_mem_uniformity_sets hs with ⟨t, htU, hts⟩ refine (ihn htU).mono fun U hU => ?_ rw [Function.iterate_succ_apply'] exact ⟨hU.1.trans <| (subset_comp_self <| refl_le_uniformity htU).trans hts, (compRel_mono hU.1 hU.2).trans hts⟩ /-- If `s ∈ 𝓤 α`, then for a subset `t` of a sufficiently small set in `𝓤 α`, we have `t ○ t ⊆ s`. -/ theorem eventually_uniformity_comp_subset {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∀ᶠ t in (𝓤 α).smallSets, t ○ t ⊆ s := eventually_uniformity_iterate_comp_subset hs 1 /-! ### Balls in uniform spaces -/ namespace UniformSpace open UniformSpace (ball) lemma isOpen_ball (x : α) {V : Set (α × α)} (hV : IsOpen V) : IsOpen (ball x V) := hV.preimage <| .prodMk_right _ lemma isClosed_ball (x : α) {V : Set (α × α)} (hV : IsClosed V) : IsClosed (ball x V) := hV.preimage <| .prodMk_right _ /-! ### Neighborhoods in uniform spaces -/ theorem hasBasis_nhds_prod (x y : α) : HasBasis (𝓝 (x, y)) (fun s => s ∈ 𝓤 α ∧ IsSymmetricRel s) fun s => ball x s ×ˢ ball y s := by rw [nhds_prod_eq] apply (hasBasis_nhds x).prod_same_index (hasBasis_nhds y) rintro U V ⟨U_in, U_symm⟩ ⟨V_in, V_symm⟩ exact ⟨U ∩ V, ⟨(𝓤 α).inter_sets U_in V_in, U_symm.inter V_symm⟩, ball_inter_left x U V, ball_inter_right y U V⟩ end UniformSpace open UniformSpace theorem nhds_eq_uniformity_prod {a b : α} : 𝓝 (a, b) = (𝓤 α).lift' fun s : Set (α × α) => { y : α | (y, a) ∈ s } ×ˢ { y : α | (b, y) ∈ s } := by rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'] · exact fun s => monotone_const.set_prod monotone_preimage · refine fun t => Monotone.set_prod ?_ monotone_const exact monotone_preimage (f := fun y => (y, a)) theorem nhdset_of_mem_uniformity {d : Set (α × α)} (s : Set (α × α)) (hd : d ∈ 𝓤 α) : ∃ t : Set (α × α), IsOpen t ∧ s ⊆ t ∧ t ⊆ { p | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } := by let cl_d := { p : α × α | ∃ x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d } have : ∀ p ∈ s, ∃ t, t ⊆ cl_d ∧ IsOpen t ∧ p ∈ t := fun ⟨x, y⟩ hp => mem_nhds_iff.mp <| show cl_d ∈ 𝓝 (x, y) by rw [nhds_eq_uniformity_prod, mem_lift'_sets] · exact ⟨d, hd, fun ⟨a, b⟩ ⟨ha, hb⟩ => ⟨x, y, ha, hp, hb⟩⟩ · exact fun _ _ h _ h' => ⟨h h'.1, h h'.2⟩ choose t ht using this exact ⟨(⋃ p : α × α, ⋃ h : p ∈ s, t p h : Set (α × α)), isOpen_iUnion fun p : α × α => isOpen_iUnion fun hp => (ht p hp).right.left, fun ⟨a, b⟩ hp => by simp only [mem_iUnion, Prod.exists]; exact ⟨a, b, hp, (ht (a, b) hp).right.right⟩, iUnion_subset fun p => iUnion_subset fun hp => (ht p hp).left⟩ /-- Entourages are neighborhoods of the diagonal. -/ theorem nhds_le_uniformity (x : α) : 𝓝 (x, x) ≤ 𝓤 α := by intro V V_in rcases comp_symm_mem_uniformity_sets V_in with ⟨w, w_in, w_symm, w_sub⟩ have : ball x w ×ˢ ball x w ∈ 𝓝 (x, x) := by rw [nhds_prod_eq] exact prod_mem_prod (ball_mem_nhds x w_in) (ball_mem_nhds x w_in) apply mem_of_superset this rintro ⟨u, v⟩ ⟨u_in, v_in⟩ exact w_sub (mem_comp_of_mem_ball w_symm u_in v_in) /-- Entourages are neighborhoods of the diagonal. -/ theorem iSup_nhds_le_uniformity : ⨆ x : α, 𝓝 (x, x) ≤ 𝓤 α := iSup_le nhds_le_uniformity /-- Entourages are neighborhoods of the diagonal. -/ theorem nhdsSet_diagonal_le_uniformity : 𝓝ˢ (diagonal α) ≤ 𝓤 α := (nhdsSet_diagonal α).trans_le iSup_nhds_le_uniformity section variable (α) theorem UniformSpace.has_seq_basis [IsCountablyGenerated <| 𝓤 α] : ∃ V : ℕ → Set (α × α), HasAntitoneBasis (𝓤 α) V ∧ ∀ n, IsSymmetricRel (V n) := let ⟨U, hsym, hbasis⟩ := (@UniformSpace.hasBasis_symmetric α _).exists_antitone_subbasis ⟨U, hbasis, fun n => (hsym n).2⟩ end /-! ### Closure and interior in uniform spaces -/ theorem closure_eq_uniformity (s : Set <| α × α) : closure s = ⋂ V ∈ { V | V ∈ 𝓤 α ∧ IsSymmetricRel V }, V ○ s ○ V := by ext ⟨x, y⟩ simp +contextual only [mem_closure_iff_nhds_basis (UniformSpace.hasBasis_nhds_prod x y), mem_iInter, mem_setOf_eq, and_imp, mem_comp_comp, exists_prop, ← mem_inter_iff, inter_comm, Set.Nonempty] theorem uniformity_hasBasis_closed : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsClosed V) id := by refine Filter.hasBasis_self.2 fun t h => ?_ rcases comp_comp_symm_mem_uniformity_sets h with ⟨w, w_in, w_symm, r⟩ refine ⟨closure w, mem_of_superset w_in subset_closure, isClosed_closure, ?_⟩ refine Subset.trans ?_ r rw [closure_eq_uniformity] apply iInter_subset_of_subset apply iInter_subset exact ⟨w_in, w_symm⟩ theorem uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := Eq.symm <| uniformity_hasBasis_closed.lift'_closure_eq_self fun _ => And.right theorem Filter.HasBasis.uniformity_closure {p : ι → Prop} {U : ι → Set (α × α)} (h : (𝓤 α).HasBasis p U) : (𝓤 α).HasBasis p fun i => closure (U i) := (@uniformity_eq_uniformity_closure α _).symm ▸ h.lift'_closure /-- Closed entourages form a basis of the uniformity filter. -/ theorem uniformity_hasBasis_closure : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α) closure := (𝓤 α).basis_sets.uniformity_closure theorem closure_eq_inter_uniformity {t : Set (α × α)} : closure t = ⋂ d ∈ 𝓤 α, d ○ (t ○ d) := calc closure t = ⋂ (V) (_ : V ∈ 𝓤 α ∧ IsSymmetricRel V), V ○ t ○ V := closure_eq_uniformity t _ = ⋂ V ∈ 𝓤 α, V ○ t ○ V := Eq.symm <| UniformSpace.hasBasis_symmetric.biInter_mem fun _ _ hV => compRel_mono (compRel_mono hV Subset.rfl) hV _ = ⋂ V ∈ 𝓤 α, V ○ (t ○ V) := by simp only [compRel_assoc] theorem uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_iInf₂ fun d hd => by let ⟨s, hs, hs_comp⟩ := comp3_mem_uniformity hd let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs have : s ⊆ interior d := calc s ⊆ t := hst _ ⊆ interior d := ht.subset_interior_iff.mpr fun x (hx : x ∈ t) => let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp hx hs_comp ⟨x, h₁, y, h₂, h₃⟩ have : interior d ∈ 𝓤 α := by filter_upwards [hs] using this simp [this]) fun _ hs => ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset theorem interior_mem_uniformity {s : Set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs theorem mem_uniformity_isClosed {s : Set (α × α)} (h : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsClosed t ∧ t ⊆ s := let ⟨t, ⟨ht_mem, htc⟩, hts⟩ := uniformity_hasBasis_closed.mem_iff.1 h ⟨t, ht_mem, htc, hts⟩ theorem isOpen_iff_isOpen_ball_subset {s : Set α} : IsOpen s ↔ ∀ x ∈ s, ∃ V ∈ 𝓤 α, IsOpen V ∧ ball x V ⊆ s := by rw [isOpen_iff_ball_subset] constructor <;> intro h x hx · obtain ⟨V, hV, hV'⟩ := h x hx exact ⟨interior V, interior_mem_uniformity hV, isOpen_interior, (ball_mono interior_subset x).trans hV'⟩ · obtain ⟨V, hV, -, hV'⟩ := h x hx exact ⟨V, hV, hV'⟩ @[deprecated (since := "2024-11-18")] alias isOpen_iff_open_ball_subset := isOpen_iff_isOpen_ball_subset /-- The uniform neighborhoods of all points of a dense set cover the whole space. -/ theorem Dense.biUnion_uniformity_ball {s : Set α} {U : Set (α × α)} (hs : Dense s) (hU : U ∈ 𝓤 α) : ⋃ x ∈ s, ball x U = univ := by refine iUnion₂_eq_univ_iff.2 fun y => ?_ rcases hs.inter_nhds_nonempty (mem_nhds_right y hU) with ⟨x, hxs, hxy : (x, y) ∈ U⟩ exact ⟨x, hxs, hxy⟩ /-- The uniform neighborhoods of all points of a dense indexed collection cover the whole space. -/ lemma DenseRange.iUnion_uniformity_ball {ι : Type*} {xs : ι → α} (xs_dense : DenseRange xs) {U : Set (α × α)} (hU : U ∈ uniformity α) : ⋃ i, UniformSpace.ball (xs i) U = univ := by rw [← biUnion_range (f := xs) (g := fun x ↦ UniformSpace.ball x U)] exact Dense.biUnion_uniformity_ball xs_dense hU /-! ### Uniformity bases -/ /-- Open elements of `𝓤 α` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V) id := hasBasis_self.2 fun s hs => ⟨interior s, interior_mem_uniformity hs, isOpen_interior, interior_subset⟩ theorem Filter.HasBasis.mem_uniformity_iff {p : β → Prop} {s : β → Set (α × α)} (h : (𝓤 α).HasBasis p s) {t : Set (α × α)} : t ∈ 𝓤 α ↔ ∃ i, p i ∧ ∀ a b, (a, b) ∈ s i → (a, b) ∈ t := h.mem_iff.trans <| by simp only [Prod.forall, subset_def] /-- Open elements `s : Set (α × α)` of `𝓤 α` such that `(x, y) ∈ s ↔ (y, x) ∈ s` form a basis of `𝓤 α`. -/ theorem uniformity_hasBasis_open_symmetric : HasBasis (𝓤 α) (fun V : Set (α × α) => V ∈ 𝓤 α ∧ IsOpen V ∧ IsSymmetricRel V) id := by simp only [← and_assoc] refine uniformity_hasBasis_open.restrict fun s hs => ⟨symmetrizeRel s, ?_⟩ exact ⟨⟨symmetrize_mem_uniformity hs.1, IsOpen.inter hs.2 (hs.2.preimage continuous_swap)⟩, symmetric_symmetrizeRel s, symmetrizeRel_subset_self s⟩ theorem comp_open_symm_mem_uniformity_sets {s : Set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, IsOpen t ∧ IsSymmetricRel t ∧ t ○ t ⊆ s := by obtain ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs obtain ⟨u, ⟨hu₁, hu₂, hu₃⟩, hu₄ : u ⊆ t⟩ := uniformity_hasBasis_open_symmetric.mem_iff.mp ht₁ exact ⟨u, hu₁, hu₂, hu₃, (compRel_mono hu₄ hu₄).trans ht₂⟩ end UniformSpace open uniformity section Constructions instance : PartialOrder (UniformSpace α) := PartialOrder.lift (fun u => 𝓤[u]) fun _ _ => UniformSpace.ext protected theorem UniformSpace.le_def {u₁ u₂ : UniformSpace α} : u₁ ≤ u₂ ↔ 𝓤[u₁] ≤ 𝓤[u₂] := Iff.rfl instance : InfSet (UniformSpace α) := ⟨fun s => UniformSpace.ofCore { uniformity := ⨅ u ∈ s, 𝓤[u] refl := le_iInf fun u => le_iInf fun _ => u.toCore.refl symm := le_iInf₂ fun u hu => le_trans (map_mono <| iInf_le_of_le _ <| iInf_le _ hu) u.symm comp := le_iInf₂ fun u hu => le_trans (lift'_mono (iInf_le_of_le _ <| iInf_le _ hu) <| le_rfl) u.comp }⟩ protected theorem UniformSpace.sInf_le {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : t ∈ tt) : sInf tt ≤ t := show ⨅ u ∈ tt, 𝓤[u] ≤ 𝓤[t] from iInf₂_le t h protected theorem UniformSpace.le_sInf {tt : Set (UniformSpace α)} {t : UniformSpace α} (h : ∀ t' ∈ tt, t ≤ t') : t ≤ sInf tt := show 𝓤[t] ≤ ⨅ u ∈ tt, 𝓤[u] from le_iInf₂ h instance : Top (UniformSpace α) := ⟨@UniformSpace.mk α ⊤ ⊤ le_top le_top fun x ↦ by simp only [nhds_top, comap_top]⟩ instance : Bot (UniformSpace α) := ⟨{ toTopologicalSpace := ⊥ uniformity := 𝓟 idRel symm := by simp [Tendsto] comp := lift'_le (mem_principal_self _) <| principal_mono.2 id_compRel.subset nhds_eq_comap_uniformity := fun s => by let _ : TopologicalSpace α := ⊥; have := discreteTopology_bot α simp [idRel] }⟩ instance : Min (UniformSpace α) := ⟨fun u₁ u₂ => { uniformity := 𝓤[u₁] ⊓ 𝓤[u₂] symm := u₁.symm.inf u₂.symm comp := (lift'_inf_le _ _ _).trans <| inf_le_inf u₁.comp u₂.comp toTopologicalSpace := u₁.toTopologicalSpace ⊓ u₂.toTopologicalSpace nhds_eq_comap_uniformity := fun _ ↦ by rw [@nhds_inf _ u₁.toTopologicalSpace _, @nhds_eq_comap_uniformity _ u₁, @nhds_eq_comap_uniformity _ u₂, comap_inf] }⟩ instance : CompleteLattice (UniformSpace α) := { inferInstanceAs (PartialOrder (UniformSpace α)) with sup := fun a b => sInf { x | a ≤ x ∧ b ≤ x } le_sup_left := fun _ _ => UniformSpace.le_sInf fun _ ⟨h, _⟩ => h le_sup_right := fun _ _ => UniformSpace.le_sInf fun _ ⟨_, h⟩ => h sup_le := fun _ _ _ h₁ h₂ => UniformSpace.sInf_le ⟨h₁, h₂⟩ inf := (· ⊓ ·) le_inf := fun a _ _ h₁ h₂ => show a.uniformity ≤ _ from le_inf h₁ h₂ inf_le_left := fun a _ => show _ ≤ a.uniformity from inf_le_left inf_le_right := fun _ b => show _ ≤ b.uniformity from inf_le_right top := ⊤ le_top := fun a => show a.uniformity ≤ ⊤ from le_top bot := ⊥ bot_le := fun u => u.toCore.refl sSup := fun tt => sInf { t | ∀ t' ∈ tt, t' ≤ t } le_sSup := fun _ _ h => UniformSpace.le_sInf fun _ h' => h' _ h sSup_le := fun _ _ h => UniformSpace.sInf_le h sInf := sInf le_sInf := fun _ _ hs => UniformSpace.le_sInf hs sInf_le := fun _ _ ha => UniformSpace.sInf_le ha } theorem iInf_uniformity {ι : Sort*} {u : ι → UniformSpace α} : 𝓤[iInf u] = ⨅ i, 𝓤[u i] := iInf_range theorem inf_uniformity {u v : UniformSpace α} : 𝓤[u ⊓ v] = 𝓤[u] ⊓ 𝓤[v] := rfl lemma bot_uniformity : 𝓤[(⊥ : UniformSpace α)] = 𝓟 idRel := rfl lemma top_uniformity : 𝓤[(⊤ : UniformSpace α)] = ⊤ := rfl instance inhabitedUniformSpace : Inhabited (UniformSpace α) := ⟨⊥⟩ instance inhabitedUniformSpaceCore : Inhabited (UniformSpace.Core α) := ⟨@UniformSpace.toCore _ default⟩ instance [Subsingleton α] : Unique (UniformSpace α) where uniq u := bot_unique <| le_principal_iff.2 <| by rw [idRel, ← diagonal, diagonal_eq_univ]; exact univ_mem /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. See note [reducible non-instances]. -/ abbrev UniformSpace.comap (f : α → β) (u : UniformSpace β) : UniformSpace α where uniformity := 𝓤[u].comap fun p : α × α => (f p.1, f p.2) symm := by simp only [tendsto_comap_iff, Prod.swap, (· ∘ ·)] exact tendsto_swap_uniformity.comp tendsto_comap comp := le_trans (by rw [comap_lift'_eq, comap_lift'_eq2] · exact lift'_mono' fun s _ ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩ => ⟨f x, h₁, h₂⟩ · exact monotone_id.compRel monotone_id) (comap_mono u.comp) toTopologicalSpace := u.toTopologicalSpace.induced f nhds_eq_comap_uniformity x := by simp only [nhds_induced, nhds_eq_comap_uniformity, comap_comap, Function.comp_def] theorem uniformity_comap {_ : UniformSpace β} (f : α → β) : 𝓤[UniformSpace.comap f ‹_›] = comap (Prod.map f f) (𝓤 β) := rfl lemma ball_preimage {f : α → β} {U : Set (β × β)} {x : α} : UniformSpace.ball x (Prod.map f f ⁻¹' U) = f ⁻¹' UniformSpace.ball (f x) U := by ext : 1 simp only [UniformSpace.ball, mem_preimage, Prod.map_apply] @[simp] theorem uniformSpace_comap_id {α : Type*} : UniformSpace.comap (id : α → α) = id := by ext : 2 rw [uniformity_comap, Prod.map_id, comap_id] theorem UniformSpace.comap_comap {α β γ} {uγ : UniformSpace γ} {f : α → β} {g : β → γ} : UniformSpace.comap (g ∘ f) uγ = UniformSpace.comap f (UniformSpace.comap g uγ) := by ext1 simp only [uniformity_comap, Filter.comap_comap, Prod.map_comp_map] theorem UniformSpace.comap_inf {α γ} {u₁ u₂ : UniformSpace γ} {f : α → γ} : (u₁ ⊓ u₂).comap f = u₁.comap f ⊓ u₂.comap f := UniformSpace.ext Filter.comap_inf theorem UniformSpace.comap_iInf {ι α γ} {u : ι → UniformSpace γ} {f : α → γ} : (⨅ i, u i).comap f = ⨅ i, (u i).comap f := by ext : 1 simp [uniformity_comap, iInf_uniformity] theorem UniformSpace.comap_mono {α γ} {f : α → γ} : Monotone fun u : UniformSpace γ => u.comap f := fun _ _ hu => Filter.comap_mono hu theorem uniformContinuous_iff {α β} {uα : UniformSpace α} {uβ : UniformSpace β} {f : α → β} : UniformContinuous f ↔ uα ≤ uβ.comap f := Filter.map_le_iff_le_comap theorem le_iff_uniformContinuous_id {u v : UniformSpace α} : u ≤ v ↔ @UniformContinuous _ _ u v id := by rw [uniformContinuous_iff, uniformSpace_comap_id, id] theorem uniformContinuous_comap {f : α → β} [u : UniformSpace β] : @UniformContinuous α β (UniformSpace.comap f u) u f := tendsto_comap theorem uniformContinuous_comap' {f : γ → β} {g : α → γ} [v : UniformSpace β] [u : UniformSpace α] (h : UniformContinuous (f ∘ g)) : @UniformContinuous α γ u (UniformSpace.comap f v) g := tendsto_comap_iff.2 h namespace UniformSpace theorem to_nhds_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) (a : α) : @nhds _ (@UniformSpace.toTopologicalSpace _ u₁) a ≤ @nhds _ (@UniformSpace.toTopologicalSpace _ u₂) a := by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact lift'_mono h le_rfl theorem toTopologicalSpace_mono {u₁ u₂ : UniformSpace α} (h : u₁ ≤ u₂) : @UniformSpace.toTopologicalSpace _ u₁ ≤ @UniformSpace.toTopologicalSpace _ u₂ := le_of_nhds_le_nhds <| to_nhds_mono h theorem toTopologicalSpace_comap {f : α → β} {u : UniformSpace β} : @UniformSpace.toTopologicalSpace _ (UniformSpace.comap f u) = TopologicalSpace.induced f (@UniformSpace.toTopologicalSpace β u) := rfl lemma uniformSpace_eq_bot {u : UniformSpace α} : u = ⊥ ↔ idRel ∈ 𝓤[u] := le_bot_iff.symm.trans le_principal_iff protected lemma _root_.Filter.HasBasis.uniformSpace_eq_bot {ι p} {s : ι → Set (α × α)} {u : UniformSpace α} (h : 𝓤[u].HasBasis p s) : u = ⊥ ↔ ∃ i, p i ∧ Pairwise fun x y : α ↦ (x, y) ∉ s i := by simp [uniformSpace_eq_bot, h.mem_iff, subset_def, Pairwise, not_imp_not] theorem toTopologicalSpace_bot : @UniformSpace.toTopologicalSpace α ⊥ = ⊥ := rfl theorem toTopologicalSpace_top : @UniformSpace.toTopologicalSpace α ⊤ = ⊤ := rfl theorem toTopologicalSpace_iInf {ι : Sort*} {u : ι → UniformSpace α} : (iInf u).toTopologicalSpace = ⨅ i, (u i).toTopologicalSpace := TopologicalSpace.ext_nhds fun a ↦ by simp only [@nhds_eq_comap_uniformity _ (iInf u), nhds_iInf, iInf_uniformity, @nhds_eq_comap_uniformity _ (u _), Filter.comap_iInf] theorem toTopologicalSpace_sInf {s : Set (UniformSpace α)} : (sInf s).toTopologicalSpace = ⨅ i ∈ s, @UniformSpace.toTopologicalSpace α i := by rw [sInf_eq_iInf] simp only [← toTopologicalSpace_iInf] theorem toTopologicalSpace_inf {u v : UniformSpace α} : (u ⊓ v).toTopologicalSpace = u.toTopologicalSpace ⊓ v.toTopologicalSpace := rfl end UniformSpace theorem UniformContinuous.continuous [UniformSpace α] [UniformSpace β] {f : α → β} (hf : UniformContinuous f) : Continuous f := continuous_iff_le_induced.mpr <| UniformSpace.toTopologicalSpace_mono <| uniformContinuous_iff.1 hf /-- Uniform space structure on `ULift α`. -/ instance ULift.uniformSpace [UniformSpace α] : UniformSpace (ULift α) := UniformSpace.comap ULift.down ‹_› /-- Uniform space structure on `αᵒᵈ`. -/ instance OrderDual.instUniformSpace [UniformSpace α] : UniformSpace (αᵒᵈ) := ‹UniformSpace α› section UniformContinuousInfi -- TODO: add an `iff` lemma? theorem UniformContinuous.inf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ u₃ : UniformSpace β} (h₁ : UniformContinuous[u₁, u₂] f) (h₂ : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁, u₂ ⊓ u₃] f := tendsto_inf.mpr ⟨h₁, h₂⟩ theorem UniformContinuous.inf_dom_left {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₁, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_left hf theorem UniformContinuous.inf_dom_right {f : α → β} {u₁ u₂ : UniformSpace α} {u₃ : UniformSpace β} (hf : UniformContinuous[u₂, u₃] f) : UniformContinuous[u₁ ⊓ u₂, u₃] f := tendsto_inf_right hf theorem uniformContinuous_sInf_dom {f : α → β} {u₁ : Set (UniformSpace α)} {u₂ : UniformSpace β} {u : UniformSpace α} (h₁ : u ∈ u₁) (hf : UniformContinuous[u, u₂] f) : UniformContinuous[sInf u₁, u₂] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity] exact tendsto_iInf' ⟨u, h₁⟩ hf theorem uniformContinuous_sInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : Set (UniformSpace β)} : UniformContinuous[u₁, sInf u₂] f ↔ ∀ u ∈ u₂, UniformContinuous[u₁, u] f := by delta UniformContinuous rw [sInf_eq_iInf', iInf_uniformity, tendsto_iInf, SetCoe.forall] theorem uniformContinuous_iInf_dom {f : α → β} {u₁ : ι → UniformSpace α} {u₂ : UniformSpace β} {i : ι} (hf : UniformContinuous[u₁ i, u₂] f) : UniformContinuous[iInf u₁, u₂] f := by delta UniformContinuous rw [iInf_uniformity] exact tendsto_iInf' i hf theorem uniformContinuous_iInf_rng {f : α → β} {u₁ : UniformSpace α} {u₂ : ι → UniformSpace β} : UniformContinuous[u₁, iInf u₂] f ↔ ∀ i, UniformContinuous[u₁, u₂ i] f := by delta UniformContinuous rw [iInf_uniformity, tendsto_iInf] end UniformContinuousInfi /-- A uniform space with the discrete uniformity has the discrete topology. -/ theorem discreteTopology_of_discrete_uniformity [hα : UniformSpace α] (h : uniformity α = 𝓟 idRel) : DiscreteTopology α := ⟨(UniformSpace.ext h.symm : ⊥ = hα) ▸ rfl⟩ instance : UniformSpace Empty := ⊥ instance : UniformSpace PUnit := ⊥ instance : UniformSpace Bool := ⊥ instance : UniformSpace ℕ := ⊥ instance : UniformSpace ℤ := ⊥ section variable [UniformSpace α] open Additive Multiplicative instance : UniformSpace (Additive α) := ‹UniformSpace α› instance : UniformSpace (Multiplicative α) := ‹UniformSpace α› theorem uniformContinuous_ofMul : UniformContinuous (ofMul : α → Additive α) := uniformContinuous_id theorem uniformContinuous_toMul : UniformContinuous (toMul : Additive α → α) := uniformContinuous_id theorem uniformContinuous_ofAdd : UniformContinuous (ofAdd : α → Multiplicative α) := uniformContinuous_id theorem uniformContinuous_toAdd : UniformContinuous (toAdd : Multiplicative α → α) := uniformContinuous_id theorem uniformity_additive : 𝓤 (Additive α) = (𝓤 α).map (Prod.map ofMul ofMul) := rfl theorem uniformity_multiplicative : 𝓤 (Multiplicative α) = (𝓤 α).map (Prod.map ofAdd ofAdd) := rfl end instance instUniformSpaceSubtype {p : α → Prop} [t : UniformSpace α] : UniformSpace (Subtype p) := UniformSpace.comap Subtype.val t theorem uniformity_subtype {p : α → Prop} [UniformSpace α] : 𝓤 (Subtype p) = comap (fun q : Subtype p × Subtype p => (q.1.1, q.2.1)) (𝓤 α) := rfl theorem uniformity_setCoe {s : Set α} [UniformSpace α] : 𝓤 s = comap (Prod.map ((↑) : s → α) ((↑) : s → α)) (𝓤 α) := rfl theorem map_uniformity_set_coe {s : Set α} [UniformSpace α] : map (Prod.map (↑) (↑)) (𝓤 s) = 𝓤 α ⊓ 𝓟 (s ×ˢ s) := by rw [uniformity_setCoe, map_comap, range_prodMap, Subtype.range_val] theorem uniformContinuous_subtype_val {p : α → Prop} [UniformSpace α] : UniformContinuous (Subtype.val : { a : α // p a } → α) := uniformContinuous_comap theorem UniformContinuous.subtype_mk {p : α → Prop} [UniformSpace α] [UniformSpace β] {f : β → α} (hf : UniformContinuous f) (h : ∀ x, p (f x)) : UniformContinuous (fun x => ⟨f x, h x⟩ : β → Subtype p) := uniformContinuous_comap' hf theorem uniformContinuousOn_iff_restrict [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} : UniformContinuousOn f s ↔ UniformContinuous (s.restrict f) := by delta UniformContinuousOn UniformContinuous rw [← map_uniformity_set_coe, tendsto_map'_iff]; rfl theorem tendsto_of_uniformContinuous_subtype [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} {a : α} (hf : UniformContinuous fun x : s => f x.val) (ha : s ∈ 𝓝 a) : Tendsto f (𝓝 a) (𝓝 (f a)) := by rw [(@map_nhds_subtype_coe_eq_nhds α _ s a (mem_of_mem_nhds ha) ha).symm] exact tendsto_map' hf.continuous.continuousAt theorem UniformContinuousOn.continuousOn [UniformSpace α] [UniformSpace β] {f : α → β} {s : Set α} (h : UniformContinuousOn f s) : ContinuousOn f s := by rw [uniformContinuousOn_iff_restrict] at h rw [continuousOn_iff_continuous_restrict] exact h.continuous @[to_additive] instance [UniformSpace α] : UniformSpace αᵐᵒᵖ := UniformSpace.comap MulOpposite.unop ‹_› @[to_additive] theorem uniformity_mulOpposite [UniformSpace α] : 𝓤 αᵐᵒᵖ = comap (fun q : αᵐᵒᵖ × αᵐᵒᵖ => (q.1.unop, q.2.unop)) (𝓤 α) := rfl @[to_additive (attr := simp)] theorem comap_uniformity_mulOpposite [UniformSpace α] : comap (fun p : α × α => (MulOpposite.op p.1, MulOpposite.op p.2)) (𝓤 αᵐᵒᵖ) = 𝓤 α := by simpa [uniformity_mulOpposite, comap_comap, (· ∘ ·)] using comap_id namespace MulOpposite @[to_additive] theorem uniformContinuous_unop [UniformSpace α] : UniformContinuous (unop : αᵐᵒᵖ → α) := uniformContinuous_comap @[to_additive] theorem uniformContinuous_op [UniformSpace α] : UniformContinuous (op : α → αᵐᵒᵖ) := uniformContinuous_comap' uniformContinuous_id end MulOpposite section Prod open UniformSpace /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance instUniformSpaceProd [u₁ : UniformSpace α] [u₂ : UniformSpace β] : UniformSpace (α × β) := u₁.comap Prod.fst ⊓ u₂.comap Prod.snd -- check the above produces no diamond for `simp` and typeclass search example [UniformSpace α] [UniformSpace β] : (instTopologicalSpaceProd : TopologicalSpace (α × β)) = UniformSpace.toTopologicalSpace := by with_reducible_and_instances rfl theorem uniformity_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = ((𝓤 α).comap fun p : (α × β) × α × β => (p.1.1, p.2.1)) ⊓ (𝓤 β).comap fun p : (α × β) × α × β => (p.1.2, p.2.2) := rfl instance [UniformSpace α] [IsCountablyGenerated (𝓤 α)] [UniformSpace β] [IsCountablyGenerated (𝓤 β)] : IsCountablyGenerated (𝓤 (α × β)) := by rw [uniformity_prod] infer_instance theorem uniformity_prod_eq_comap_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = comap (fun p : (α × β) × α × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by simp_rw [uniformity_prod, prod_eq_inf, Filter.comap_inf, Filter.comap_comap, Function.comp_def] theorem uniformity_prod_eq_prod [UniformSpace α] [UniformSpace β] : 𝓤 (α × β) = map (fun p : (α × α) × β × β => ((p.1.1, p.2.1), (p.1.2, p.2.2))) (𝓤 α ×ˢ 𝓤 β) := by rw [map_swap4_eq_comap, uniformity_prod_eq_comap_prod] theorem mem_uniformity_of_uniformContinuous_invariant [UniformSpace α] [UniformSpace β] {s : Set (β × β)} {f : α → α → β} (hf : UniformContinuous fun p : α × α => f p.1 p.2) (hs : s ∈ 𝓤 β) : ∃ u ∈ 𝓤 α, ∀ a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := by rw [UniformContinuous, uniformity_prod_eq_prod, tendsto_map'_iff] at hf rcases mem_prod_iff.1 (mem_map.1 <| hf hs) with ⟨u, hu, v, hv, huvt⟩ exact ⟨u, hu, fun a b c hab => @huvt ((_, _), (_, _)) ⟨hab, refl_mem_uniformity hv⟩⟩ /-- An entourage of the diagonal in `α` and an entourage in `β` yield an entourage in `α × β` once we permute coordinates. -/ def entourageProd (u : Set (α × α)) (v : Set (β × β)) : Set ((α × β) × α × β) := {((a₁, b₁),(a₂, b₂)) | (a₁, a₂) ∈ u ∧ (b₁, b₂) ∈ v} theorem mem_entourageProd {u : Set (α × α)} {v : Set (β × β)} {p : (α × β) × α × β} : p ∈ entourageProd u v ↔ (p.1.1, p.2.1) ∈ u ∧ (p.1.2, p.2.2) ∈ v := Iff.rfl theorem entourageProd_mem_uniformity [t₁ : UniformSpace α] [t₂ : UniformSpace β] {u : Set (α × α)} {v : Set (β × β)} (hu : u ∈ 𝓤 α) (hv : v ∈ 𝓤 β) : entourageProd u v ∈ 𝓤 (α × β) := by rw [uniformity_prod]; exact inter_mem_inf (preimage_mem_comap hu) (preimage_mem_comap hv) theorem ball_entourageProd (u : Set (α × α)) (v : Set (β × β)) (x : α × β) : ball x (entourageProd u v) = ball x.1 u ×ˢ ball x.2 v := by ext p; simp only [ball, entourageProd, Set.mem_setOf_eq, Set.mem_prod, Set.mem_preimage] lemma IsSymmetricRel.entourageProd {u : Set (α × α)} {v : Set (β × β)} (hu : IsSymmetricRel u) (hv : IsSymmetricRel v) : IsSymmetricRel (entourageProd u v) := Set.ext fun _ ↦ and_congr hu.mk_mem_comm hv.mk_mem_comm theorem Filter.HasBasis.uniformity_prod {ιa ιb : Type*} [UniformSpace α] [UniformSpace β]
{pa : ιa → Prop} {pb : ιb → Prop} {sa : ιa → Set (α × α)} {sb : ιb → Set (β × β)} (ha : (𝓤 α).HasBasis pa sa) (hb : (𝓤 β).HasBasis pb sb) : (𝓤 (α × β)).HasBasis (fun i : ιa × ιb ↦ pa i.1 ∧ pb i.2) (fun i ↦ entourageProd (sa i.1) (sb i.2)) := (ha.comap _).inf (hb.comap _) theorem entourageProd_subset [UniformSpace α] [UniformSpace β] {s : Set ((α × β) × α × β)} (h : s ∈ 𝓤 (α × β)) : ∃ u ∈ 𝓤 α, ∃ v ∈ 𝓤 β, entourageProd u v ⊆ s := by
Mathlib/Topology/UniformSpace/Basic.lean
706
714
/- Copyright (c) 2024 Raghuram Sundararajan. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Raghuram Sundararajan -/ import Mathlib.Algebra.Ring.Defs import Mathlib.Algebra.Group.Ext /-! # Extensionality lemmas for rings and similar structures In this file we prove extensionality lemmas for the ring-like structures defined in `Mathlib/Algebra/Ring/Defs.lean`, ranging from `NonUnitalNonAssocSemiring` to `CommRing`. These extensionality lemmas take the form of asserting that two algebraic structures on a type are equal whenever the addition and multiplication defined by them are both the same. ## Implementation details We follow `Mathlib/Algebra/Group/Ext.lean` in using the term `(letI := i; HMul.hMul : R → R → R)` to refer to the multiplication specified by a typeclass instance `i` on a type `R` (and similarly for addition). We abbreviate these using some local notations. Since `Mathlib/Algebra/Group/Ext.lean` proved several injectivity lemmas, we do so as well — even if sometimes we don't need them to prove extensionality. ## Tags semiring, ring, extensionality -/ local macro:max "local_hAdd[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HAdd.hAdd : $type → $type → $type)) local macro:max "local_hMul[" type:term ", " inst:term "]" : term => `(term| (letI := $inst; HMul.hMul : $type → $type → $type)) universe u variable {R : Type u} /-! ### Distrib -/ namespace Distrib @[ext] theorem ext ⦃inst₁ inst₂ : Distrib R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `add` and `mul` functions and properties. rcases inst₁ with @⟨⟨⟩, ⟨⟩⟩ rcases inst₂ with @⟨⟨⟩, ⟨⟩⟩ -- Prove equality of parts using function extensionality. congr end Distrib /-! ### NonUnitalNonAssocSemiring -/ namespace NonUnitalNonAssocSemiring @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddMonoid` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩ rcases inst₂ with @⟨_, ⟨⟩⟩ -- Prove equality of parts using already-proved extensionality lemmas. congr; ext : 1; assumption theorem toDistrib_injective : Function.Injective (@toDistrib R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocSemiring /-! ### NonUnitalSemiring -/ namespace NonUnitalSemiring theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := toNonUnitalNonAssocSemiring_injective <| NonUnitalNonAssocSemiring.ext h_add h_mul end NonUnitalSemiring /-! ### NonAssocSemiring and its ancestors This section also includes results for `AddMonoidWithOne`, `AddCommMonoidWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ /- TODO consider relocating these lemmas. -/ @[ext] theorem AddMonoidWithOne.ext ⦃inst₁ inst₂ : AddMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := by have h_monoid : inst₁.toAddMonoid = inst₂.toAddMonoid := by ext : 1; exact h_add have h_zero' : inst₁.toZero = inst₂.toZero := congrArg (·.toZero) h_monoid have h_one' : inst₁.toOne = inst₂.toOne := congrArg One.mk h_one have h_natCast : inst₁.toNatCast.natCast = inst₂.toNatCast.natCast := by funext n; induction n with | zero => rewrite [inst₁.natCast_zero, inst₂.natCast_zero] exact congrArg (@Zero.zero R) h_zero' | succ n h => rw [inst₁.natCast_succ, inst₂.natCast_succ, h_add] exact congrArg₂ _ h h_one rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr theorem AddCommMonoidWithOne.toAddMonoidWithOne_injective : Function.Injective (@AddCommMonoidWithOne.toAddMonoidWithOne R) := by rintro ⟨⟩ ⟨⟩ _; congr @[ext] theorem AddCommMonoidWithOne.ext ⦃inst₁ inst₂ : AddCommMonoidWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one : R)) : inst₁ = inst₂ := AddCommMonoidWithOne.toAddMonoidWithOne_injective <| AddMonoidWithOne.ext h_add h_one namespace NonAssocSemiring /- The best place to prove that the `NatCast` is determined by the other operations is probably in an extensionality lemma for `AddMonoidWithOne`, in which case we may as well do the typeclasses defined in `Mathlib/Algebra/GroupWithZero/Defs.lean` as well. -/ @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocSemiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h : inst₁.toNonUnitalNonAssocSemiring = inst₂.toNonUnitalNonAssocSemiring := by ext : 1 <;> assumption have h_zero : (inst₁.toMulZeroClass).toZero.zero = (inst₂.toMulZeroClass).toZero.zero := congrArg (fun inst => (inst.toMulZeroClass).toZero.zero) h have h_one' : (inst₁.toMulZeroOneClass).toMulOneClass.toOne = (inst₂.toMulZeroOneClass).toMulOneClass.toOne := congrArg (@MulOneClass.toOne R) <| by ext : 1; exact h_mul have h_one : (inst₁.toMulZeroOneClass).toMulOneClass.toOne.one = (inst₂.toMulZeroOneClass).toMulOneClass.toOne.one := congrArg (@One.one R) h_one' have : inst₁.toAddCommMonoidWithOne = inst₂.toAddCommMonoidWithOne := by ext : 1 <;> assumption have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this -- Split into `NonUnitalNonAssocSemiring`, `One` and `natCast` instances. cases inst₁; cases inst₂ congr theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ _ ext <;> congr end NonAssocSemiring /-! ### NonUnitalNonAssocRing -/ namespace NonUnitalNonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalNonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by -- Split into `AddCommGroup` instance, `mul` function and properties. rcases inst₁ with @⟨_, ⟨⟩⟩; rcases inst₂ with @⟨_, ⟨⟩⟩ congr; (ext : 1; assumption) theorem toNonUnitalNonAssocSemiring_injective : Function.Injective (@toNonUnitalNonAssocSemiring R) := by intro _ _ h -- Use above extensionality lemma to prove injectivity by showing that `h_add` and `h_mul` hold. ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h end NonUnitalNonAssocRing /-! ### NonUnitalRing -/ namespace NonUnitalRing @[ext] theorem ext ⦃inst₁ inst₂ : NonUnitalRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption -- Split into fields and prove they are equal using the above. cases inst₁; cases inst₂ congr theorem toNonUnitalSemiring_injective : Function.Injective (@toNonUnitalSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective : Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonUnitalRing /-! ### NonAssocRing and its ancestors This section also includes results for `AddGroupWithOne`, `AddCommGroupWithOne`, etc. as these are considered implementation detail of the ring classes. TODO consider relocating these lemmas. -/ @[ext] theorem AddGroupWithOne.ext ⦃inst₁ inst₂ : AddGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddMonoidWithOne = inst₂.toAddMonoidWithOne := AddMonoidWithOne.ext h_add h_one have : inst₁.toNatCast = inst₂.toNatCast := congrArg (·.toNatCast) this have h_group : inst₁.toAddGroup = inst₂.toAddGroup := by ext : 1; exact h_add -- Extract equality of necessary substructures from h_group injection h_group with h_group; injection h_group have : inst₁.toIntCast.intCast = inst₂.toIntCast.intCast := by funext n; cases n with | ofNat n => rewrite [Int.ofNat_eq_coe, inst₁.intCast_ofNat, inst₂.intCast_ofNat]; congr | negSucc n => rewrite [inst₁.intCast_negSucc, inst₂.intCast_negSucc]; congr rcases inst₁ with @⟨⟨⟩⟩; rcases inst₂ with @⟨⟨⟩⟩ congr @[ext] theorem AddCommGroupWithOne.ext ⦃inst₁ inst₂ : AddCommGroupWithOne R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_one : (letI := inst₁; One.one : R) = (letI := inst₂; One.one)) : inst₁ = inst₂ := by have : inst₁.toAddCommGroup = inst₂.toAddCommGroup := AddCommGroup.ext h_add have : inst₁.toAddGroupWithOne = inst₂.toAddGroupWithOne := AddGroupWithOne.ext h_add h_one injection this with _ h_addMonoidWithOne; injection h_addMonoidWithOne cases inst₁; cases inst₂ congr namespace NonAssocRing @[ext] theorem ext ⦃inst₁ inst₂ : NonAssocRing R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂]) (h_mul : local_hMul[R, inst₁] = local_hMul[R, inst₂]) : inst₁ = inst₂ := by have h₁ : inst₁.toNonUnitalNonAssocRing = inst₂.toNonUnitalNonAssocRing := by ext : 1 <;> assumption have h₂ : inst₁.toNonAssocSemiring = inst₂.toNonAssocSemiring := by ext : 1 <;> assumption -- Mathematically non-trivial fact: `intCast` is determined by the rest. have h₃ : inst₁.toAddCommGroupWithOne = inst₂.toAddCommGroupWithOne := AddCommGroupWithOne.ext h_add (congrArg (·.toOne.one) h₂) cases inst₁; cases inst₂ congr <;> solve| injection h₁ | injection h₂ | injection h₃ theorem toNonAssocSemiring_injective : Function.Injective (@toNonAssocSemiring R) := by intro _ _ h ext x y · exact congrArg (·.toAdd.add x y) h · exact congrArg (·.toMul.mul x y) h theorem toNonUnitalNonAssocring_injective :
Function.Injective (@toNonUnitalNonAssocRing R) := by intro _ _ _ ext <;> congr end NonAssocRing /-! ### Semiring -/ namespace Semiring @[ext] theorem ext ⦃inst₁ inst₂ : Semiring R⦄ (h_add : local_hAdd[R, inst₁] = local_hAdd[R, inst₂])
Mathlib/Algebra/Ring/Ext.lean
266
276
/- 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, Yury Kudryashov -/ import Mathlib.Data.Set.SymmDiff import Mathlib.Order.SuccPred.Relation import Mathlib.Topology.Irreducible /-! # Connected subsets of topological spaces In this file we define connected subsets of a topological spaces and various other properties and classes related to connectivity. ## Main definitions We define the following properties for sets in a topological space: * `IsConnected`: a nonempty set that has no non-trivial open partition. See also the section below in the module doc. * `connectedComponent` is the connected component of an element in the space. We also have a class stating that the whole space satisfies that property: `ConnectedSpace` ## On the definition of connected sets/spaces In informal mathematics, connected spaces are assumed to be nonempty. We formalise the predicate without that assumption as `IsPreconnected`. In other words, the only difference is whether the empty space counts as connected. There are good reasons to consider the empty space to be “too simple to be simple” See also https://ncatlab.org/nlab/show/too+simple+to+be+simple, and in particular https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions. -/ open Set Function Topology TopologicalSpace Relation universe u v variable {α : Type u} {β : Type v} {ι : Type*} {π : ι → Type*} [TopologicalSpace α] {s t u v : Set α} section Preconnected /-- A preconnected set is one where there is no non-trivial open partition. -/ def IsPreconnected (s : Set α) : Prop := ∀ u v : Set α, IsOpen u → IsOpen v → s ⊆ u ∪ v → (s ∩ u).Nonempty → (s ∩ v).Nonempty → (s ∩ (u ∩ v)).Nonempty /-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/ def IsConnected (s : Set α) : Prop := s.Nonempty ∧ IsPreconnected s theorem IsConnected.nonempty {s : Set α} (h : IsConnected s) : s.Nonempty := h.1 theorem IsConnected.isPreconnected {s : Set α} (h : IsConnected s) : IsPreconnected s := h.2 theorem IsPreirreducible.isPreconnected {s : Set α} (H : IsPreirreducible s) : IsPreconnected s := fun _ _ hu hv _ => H _ _ hu hv theorem IsIrreducible.isConnected {s : Set α} (H : IsIrreducible s) : IsConnected s := ⟨H.nonempty, H.isPreirreducible.isPreconnected⟩ theorem isPreconnected_empty : IsPreconnected (∅ : Set α) := isPreirreducible_empty.isPreconnected theorem isConnected_singleton {x} : IsConnected ({x} : Set α) := isIrreducible_singleton.isConnected theorem isPreconnected_singleton {x} : IsPreconnected ({x} : Set α) := isConnected_singleton.isPreconnected theorem Set.Subsingleton.isPreconnected {s : Set α} (hs : s.Subsingleton) : IsPreconnected s := hs.induction_on isPreconnected_empty fun _ => isPreconnected_singleton /-- If any point of a set is joined to a fixed point by a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall {s : Set α} (x : α) (H : ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rintro u v hu hv hs ⟨z, zs, zu⟩ ⟨y, ys, yv⟩ have xs : x ∈ s := by rcases H y ys with ⟨t, ts, xt, -, -⟩ exact ts xt -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `wlog xu : x ∈ u := hs xs using u v y z, v u z y` cases hs xs with | inl xu => rcases H y ys with ⟨t, ts, xt, yt, ht⟩ have := ht u v hu hv (ts.trans hs) ⟨x, xt, xu⟩ ⟨y, yt, yv⟩ exact this.imp fun z hz => ⟨ts hz.1, hz.2⟩ | inr xv => rcases H z zs with ⟨t, ts, xt, zt, ht⟩ have := ht v u hv hu (ts.trans <| by rwa [union_comm]) ⟨x, xt, xv⟩ ⟨z, zt, zu⟩ exact this.imp fun _ h => ⟨ts h.1, h.2.2, h.2.1⟩ /-- If any two points of a set are contained in a preconnected subset, then the original set is preconnected as well. -/ theorem isPreconnected_of_forall_pair {s : Set α} (H : ∀ x ∈ s, ∀ y ∈ s, ∃ t, t ⊆ s ∧ x ∈ t ∧ y ∈ t ∧ IsPreconnected t) : IsPreconnected s := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) exacts [isPreconnected_empty, isPreconnected_of_forall x fun y => H x hx y] /-- A union of a family of preconnected sets with a common point is preconnected as well. -/ theorem isPreconnected_sUnion (x : α) (c : Set (Set α)) (H1 : ∀ s ∈ c, x ∈ s) (H2 : ∀ s ∈ c, IsPreconnected s) : IsPreconnected (⋃₀ c) := by apply isPreconnected_of_forall x rintro y ⟨s, sc, ys⟩ exact ⟨s, subset_sUnion_of_mem sc, H1 s sc, ys, H2 s sc⟩ theorem isPreconnected_iUnion {ι : Sort*} {s : ι → Set α} (h₁ : (⋂ i, s i).Nonempty) (h₂ : ∀ i, IsPreconnected (s i)) : IsPreconnected (⋃ i, s i) := Exists.elim h₁ fun f hf => isPreconnected_sUnion f _ hf (forall_mem_range.2 h₂) theorem IsPreconnected.union (x : α) {s t : Set α} (H1 : x ∈ s) (H2 : x ∈ t) (H3 : IsPreconnected s) (H4 : IsPreconnected t) : IsPreconnected (s ∪ t) := sUnion_pair s t ▸ isPreconnected_sUnion x {s, t} (by rintro r (rfl | rfl | h) <;> assumption) (by rintro r (rfl | rfl | h) <;> assumption) theorem IsPreconnected.union' {s t : Set α} (H : (s ∩ t).Nonempty) (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ∪ t) := by rcases H with ⟨x, hxs, hxt⟩ exact hs.union x hxs hxt ht theorem IsConnected.union {s t : Set α} (H : (s ∩ t).Nonempty) (Hs : IsConnected s) (Ht : IsConnected t) : IsConnected (s ∪ t) := by rcases H with ⟨x, hx⟩ refine ⟨⟨x, mem_union_left t (mem_of_mem_inter_left hx)⟩, ?_⟩ exact Hs.isPreconnected.union x (mem_of_mem_inter_left hx) (mem_of_mem_inter_right hx) Ht.isPreconnected /-- The directed sUnion of a set S of preconnected subsets is preconnected. -/ theorem IsPreconnected.sUnion_directed {S : Set (Set α)} (K : DirectedOn (· ⊆ ·) S) (H : ∀ s ∈ S, IsPreconnected s) : IsPreconnected (⋃₀ S) := by rintro u v hu hv Huv ⟨a, ⟨s, hsS, has⟩, hau⟩ ⟨b, ⟨t, htS, hbt⟩, hbv⟩ obtain ⟨r, hrS, hsr, htr⟩ : ∃ r ∈ S, s ⊆ r ∧ t ⊆ r := K s hsS t htS have Hnuv : (r ∩ (u ∩ v)).Nonempty := H _ hrS u v hu hv ((subset_sUnion_of_mem hrS).trans Huv) ⟨a, hsr has, hau⟩ ⟨b, htr hbt, hbv⟩ have Kruv : r ∩ (u ∩ v) ⊆ ⋃₀ S ∩ (u ∩ v) := inter_subset_inter_left _ (subset_sUnion_of_mem hrS) exact Hnuv.mono Kruv /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsPreconnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (H : ∀ i ∈ t, IsPreconnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsPreconnected (⋃ n ∈ t, s n) := by let R := fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t have P : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen R i j → ∃ p, p ⊆ t ∧ i ∈ p ∧ j ∈ p ∧ IsPreconnected (⋃ j ∈ p, s j) := fun i hi j hj h => by induction h with | refl => refine ⟨{i}, singleton_subset_iff.mpr hi, mem_singleton i, mem_singleton i, ?_⟩ rw [biUnion_singleton] exact H i hi | @tail j k _ hjk ih => obtain ⟨p, hpt, hip, hjp, hp⟩ := ih hjk.2 refine ⟨insert k p, insert_subset_iff.mpr ⟨hj, hpt⟩, mem_insert_of_mem k hip, mem_insert k p, ?_⟩ rw [biUnion_insert] refine (H k hj).union' (hjk.1.mono ?_) hp rw [inter_comm] exact inter_subset_inter_right _ (subset_biUnion_of_mem hjp) refine isPreconnected_of_forall_pair ?_ intro x hx y hy obtain ⟨i : ι, hi : i ∈ t, hxi : x ∈ s i⟩ := mem_iUnion₂.1 hx obtain ⟨j : ι, hj : j ∈ t, hyj : y ∈ s j⟩ := mem_iUnion₂.1 hy obtain ⟨p, hpt, hip, hjp, hp⟩ := P i hi j hj (K i hi j hj) exact ⟨⋃ j ∈ p, s j, biUnion_subset_biUnion_left hpt, mem_biUnion hip hxi, mem_biUnion hjp hyj, hp⟩ /-- The biUnion of a family of preconnected sets is preconnected if the graph determined by whether two sets intersect is preconnected. -/ theorem IsConnected.biUnion_of_reflTransGen {ι : Type*} {t : Set ι} {s : ι → Set α} (ht : t.Nonempty) (H : ∀ i ∈ t, IsConnected (s i)) (K : ∀ i, i ∈ t → ∀ j, j ∈ t → ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty ∧ i ∈ t) i j) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨ht.some, ht.some_mem, (H _ ht.some_mem).nonempty⟩, IsPreconnected.biUnion_of_reflTransGen (fun i hi => (H i hi).isPreconnected) K⟩ /-- Preconnectedness of the iUnion of a family of preconnected sets indexed by the vertices of a preconnected graph, where two vertices are joined when the corresponding sets intersect. -/ theorem IsPreconnected.iUnion_of_reflTransGen {ι : Type*} {s : ι → Set α} (H : ∀ i, IsPreconnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsPreconnected (⋃ n, s n) := by rw [← biUnion_univ] exact IsPreconnected.biUnion_of_reflTransGen (fun i _ => H i) fun i _ j _ => by simpa [mem_univ] using K i j theorem IsConnected.iUnion_of_reflTransGen {ι : Type*} [Nonempty ι] {s : ι → Set α} (H : ∀ i, IsConnected (s i)) (K : ∀ i j, ReflTransGen (fun i j : ι => (s i ∩ s j).Nonempty) i j) : IsConnected (⋃ n, s n) := ⟨nonempty_iUnion.2 <| Nonempty.elim ‹_› fun i : ι => ⟨i, (H _).nonempty⟩, IsPreconnected.iUnion_of_reflTransGen (fun i => (H i).isPreconnected) K⟩ section SuccOrder open Order variable [LinearOrder β] [SuccOrder β] [IsSuccArchimedean β] /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.iUnion_of_chain {s : β → Set α} (H : ∀ n, IsPreconnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n, s n) := IsPreconnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of connected sets indexed by a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is connected. -/ theorem IsConnected.iUnion_of_chain [Nonempty β] {s : β → Set α} (H : ∀ n, IsConnected (s n)) (K : ∀ n, (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n, s n) := IsConnected.iUnion_of_reflTransGen H fun _ _ => reflTransGen_of_succ _ (fun i _ => K i) fun i _ => by rw [inter_comm] exact K i /-- The iUnion of preconnected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsPreconnected.biUnion_of_chain {s : β → Set α} {t : Set β} (ht : OrdConnected t) (H : ∀ n ∈ t, IsPreconnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsPreconnected (⋃ n ∈ t, s n) := by have h1 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → k ∈ t := fun hi hj hk => ht.out hi hj (Ico_subset_Icc_self hk) have h2 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → succ k ∈ t := fun hi hj hk => ht.out hi hj ⟨hk.1.trans <| le_succ _, succ_le_of_lt hk.2⟩ have h3 : ∀ {i j k : β}, i ∈ t → j ∈ t → k ∈ Ico i j → (s k ∩ s (succ k)).Nonempty := fun hi hj hk => K _ (h1 hi hj hk) (h2 hi hj hk) refine IsPreconnected.biUnion_of_reflTransGen H fun i hi j hj => ?_ exact reflTransGen_of_succ _ (fun k hk => ⟨h3 hi hj hk, h1 hi hj hk⟩) fun k hk => ⟨by rw [inter_comm]; exact h3 hj hi hk, h2 hj hi hk⟩ /-- The iUnion of connected sets indexed by a subset of a type with an archimedean successor (like `ℕ` or `ℤ`) such that any two neighboring sets meet is preconnected. -/ theorem IsConnected.biUnion_of_chain {s : β → Set α} {t : Set β} (hnt : t.Nonempty) (ht : OrdConnected t) (H : ∀ n ∈ t, IsConnected (s n)) (K : ∀ n : β, n ∈ t → succ n ∈ t → (s n ∩ s (succ n)).Nonempty) : IsConnected (⋃ n ∈ t, s n) := ⟨nonempty_biUnion.2 <| ⟨hnt.some, hnt.some_mem, (H _ hnt.some_mem).nonempty⟩, IsPreconnected.biUnion_of_chain ht (fun i hi => (H i hi).isPreconnected) K⟩ end SuccOrder /-- Theorem of bark and tree: if a set is within a preconnected set and its closure, then it is preconnected as well. See also `IsConnected.subset_closure`. -/ protected theorem IsPreconnected.subset_closure {s : Set α} {t : Set α} (H : IsPreconnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsPreconnected t := fun u v hu hv htuv ⟨_y, hyt, hyu⟩ ⟨_z, hzt, hzv⟩ => let ⟨p, hpu, hps⟩ := mem_closure_iff.1 (Ktcs hyt) u hu hyu let ⟨q, hqv, hqs⟩ := mem_closure_iff.1 (Ktcs hzt) v hv hzv let ⟨r, hrs, hruv⟩ := H u v hu hv (Subset.trans Kst htuv) ⟨p, hps, hpu⟩ ⟨q, hqs, hqv⟩ ⟨r, Kst hrs, hruv⟩ /-- Theorem of bark and tree: if a set is within a connected set and its closure, then it is connected as well. See also `IsPreconnected.subset_closure`. -/ protected theorem IsConnected.subset_closure {s : Set α} {t : Set α} (H : IsConnected s) (Kst : s ⊆ t) (Ktcs : t ⊆ closure s) : IsConnected t := ⟨Nonempty.mono Kst H.left, IsPreconnected.subset_closure H.right Kst Ktcs⟩ /-- The closure of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.closure {s : Set α} (H : IsPreconnected s) : IsPreconnected (closure s) := IsPreconnected.subset_closure H subset_closure Subset.rfl /-- The closure of a connected set is connected as well. -/ protected theorem IsConnected.closure {s : Set α} (H : IsConnected s) : IsConnected (closure s) := IsConnected.subset_closure H subset_closure <| Subset.rfl /-- The image of a preconnected set is preconnected as well. -/ protected theorem IsPreconnected.image [TopologicalSpace β] {s : Set α} (H : IsPreconnected s) (f : α → β) (hf : ContinuousOn f s) : IsPreconnected (f '' s) := by -- Unfold/destruct definitions in hypotheses rintro u v hu hv huv ⟨_, ⟨x, xs, rfl⟩, xu⟩ ⟨_, ⟨y, ys, rfl⟩, yv⟩ rcases continuousOn_iff'.1 hf u hu with ⟨u', hu', u'_eq⟩ rcases continuousOn_iff'.1 hf v hv with ⟨v', hv', v'_eq⟩ -- Reformulate `huv : f '' s ⊆ u ∪ v` in terms of `u'` and `v'` replace huv : s ⊆ u' ∪ v' := by rw [image_subset_iff, preimage_union] at huv replace huv := subset_inter huv Subset.rfl rw [union_inter_distrib_right, u'_eq, v'_eq, ← union_inter_distrib_right] at huv exact (subset_inter_iff.1 huv).1 -- Now `s ⊆ u' ∪ v'`, so we can apply `‹IsPreconnected s›` obtain ⟨z, hz⟩ : (s ∩ (u' ∩ v')).Nonempty := by refine H u' v' hu' hv' huv ⟨x, ?_⟩ ⟨y, ?_⟩ <;> rw [inter_comm] exacts [u'_eq ▸ ⟨xu, xs⟩, v'_eq ▸ ⟨yv, ys⟩] rw [← inter_self s, inter_assoc, inter_left_comm s u', ← inter_assoc, inter_comm s, inter_comm s, ← u'_eq, ← v'_eq] at hz exact ⟨f z, ⟨z, hz.1.2, rfl⟩, hz.1.1, hz.2.1⟩ /-- The image of a connected set is connected as well. -/ protected theorem IsConnected.image [TopologicalSpace β] {s : Set α} (H : IsConnected s) (f : α → β) (hf : ContinuousOn f s) : IsConnected (f '' s) := ⟨image_nonempty.mpr H.nonempty, H.isPreconnected.image f hf⟩ theorem isPreconnected_closed_iff {s : Set α} : IsPreconnected s ↔ ∀ t t', IsClosed t → IsClosed t' → s ⊆ t ∪ t' → (s ∩ t).Nonempty → (s ∩ t').Nonempty → (s ∩ (t ∩ t')).Nonempty := ⟨by rintro h t t' ht ht' htt' ⟨x, xs, xt⟩ ⟨y, ys, yt'⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xt' : x ∉ t' := (h' xs).resolve_left (absurd xt) have yt : y ∉ t := (h' ys).resolve_right (absurd yt') have := h _ _ ht.isOpen_compl ht'.isOpen_compl h' ⟨y, ys, yt⟩ ⟨x, xs, xt'⟩ rw [← compl_union] at this exact this.ne_empty htt'.disjoint_compl_right.inter_eq, by rintro h u v hu hv huv ⟨x, xs, xu⟩ ⟨y, ys, yv⟩ rw [← not_disjoint_iff_nonempty_inter, ← subset_compl_iff_disjoint_right, compl_inter] intro h' have xv : x ∉ v := (h' xs).elim (absurd xu) id have yu : y ∉ u := (h' ys).elim id (absurd yv) have := h _ _ hu.isClosed_compl hv.isClosed_compl h' ⟨y, ys, yu⟩ ⟨x, xs, xv⟩ rw [← compl_union] at this exact this.ne_empty huv.disjoint_compl_right.inter_eq⟩ theorem Topology.IsInducing.isPreconnected_image [TopologicalSpace β] {s : Set α} {f : α → β} (hf : IsInducing f) : IsPreconnected (f '' s) ↔ IsPreconnected s := by refine ⟨fun h => ?_, fun h => h.image _ hf.continuous.continuousOn⟩ rintro u v hu' hv' huv ⟨x, hxs, hxu⟩ ⟨y, hys, hyv⟩ rcases hf.isOpen_iff.1 hu' with ⟨u, hu, rfl⟩ rcases hf.isOpen_iff.1 hv' with ⟨v, hv, rfl⟩ replace huv : f '' s ⊆ u ∪ v := by rwa [image_subset_iff] rcases h u v hu hv huv ⟨f x, mem_image_of_mem _ hxs, hxu⟩ ⟨f y, mem_image_of_mem _ hys, hyv⟩ with ⟨_, ⟨z, hzs, rfl⟩, hzuv⟩ exact ⟨z, hzs, hzuv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isPreconnected_image := IsInducing.isPreconnected_image /- TODO: The following lemmas about connection of preimages hold more generally for strict maps (the quotient and subspace topologies of the image agree) whose fibers are preconnected. -/ theorem IsPreconnected.preimage_of_isOpenMap [TopologicalSpace β] {f : α → β} {s : Set β} (hs : IsPreconnected s) (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsPreconnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsPreconnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsPreconnected (f ⁻¹' s) := isPreconnected_closed_iff.2 fun u v hu hv hsuv hsu hsv => by replace hsf : f '' (f ⁻¹' s) = s := image_preimage_eq_of_subset hsf obtain ⟨_, has, ⟨a, hau, rfl⟩, hav⟩ : (s ∩ (f '' u ∩ f '' v)).Nonempty := by refine isPreconnected_closed_iff.1 hs (f '' u) (f '' v) (hf u hu) (hf v hv) ?_ ?_ ?_ · simpa only [hsf, image_union] using image_subset f hsuv · simpa only [image_preimage_inter] using hsu.image f · simpa only [image_preimage_inter] using hsv.image f · exact ⟨a, has, hau, hinj.mem_set_image.1 hav⟩ theorem IsConnected.preimage_of_isOpenMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsOpenMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isOpenMap hinj hf hsf⟩ theorem IsConnected.preimage_of_isClosedMap [TopologicalSpace β] {s : Set β} (hs : IsConnected s) {f : α → β} (hinj : Function.Injective f) (hf : IsClosedMap f) (hsf : s ⊆ range f) : IsConnected (f ⁻¹' s) := ⟨hs.nonempty.preimage' hsf, hs.isPreconnected.preimage_of_isClosedMap hinj hf hsf⟩ theorem IsPreconnected.subset_or_subset (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hs : IsPreconnected s) : s ⊆ u ∨ s ⊆ v := by specialize hs u v hu hv hsuv obtain hsu | hsu := (s ∩ u).eq_empty_or_nonempty · exact Or.inr ((Set.disjoint_iff_inter_eq_empty.2 hsu).subset_right_of_subset_union hsuv) · replace hs := mt (hs hsu) simp_rw [Set.not_nonempty_iff_eq_empty, ← Set.disjoint_iff_inter_eq_empty, disjoint_iff_inter_eq_empty.1 huv] at hs exact Or.inl ((hs s.disjoint_empty).subset_left_of_subset_union hsuv) theorem IsPreconnected.subset_left_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsu : (s ∩ u).Nonempty) (hs : IsPreconnected s) : s ⊆ u := Disjoint.subset_left_of_subset_union hsuv (by by_contra hsv rw [not_disjoint_iff_nonempty_inter] at hsv obtain ⟨x, _, hx⟩ := hs u v hu hv hsuv hsu hsv exact Set.disjoint_iff.1 huv hx) theorem IsPreconnected.subset_right_of_subset_union (hu : IsOpen u) (hv : IsOpen v) (huv : Disjoint u v) (hsuv : s ⊆ u ∪ v) (hsv : (s ∩ v).Nonempty) (hs : IsPreconnected s) : s ⊆ v := hs.subset_left_of_subset_union hv hu huv.symm (union_comm u v ▸ hsuv) hsv /-- If a preconnected set `s` intersects an open set `u`, and limit points of `u` inside `s` are contained in `u`, then the whole set `s` is contained in `u`. -/ theorem IsPreconnected.subset_of_closure_inter_subset (hs : IsPreconnected s) (hu : IsOpen u) (h'u : (s ∩ u).Nonempty) (h : closure u ∩ s ⊆ u) : s ⊆ u := by have A : s ⊆ u ∪ (closure u)ᶜ := by intro x hx by_cases xu : x ∈ u · exact Or.inl xu · right intro h'x exact xu (h (mem_inter h'x hx)) apply hs.subset_left_of_subset_union hu isClosed_closure.isOpen_compl _ A h'u exact disjoint_compl_right.mono_right (compl_subset_compl.2 subset_closure) theorem IsPreconnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsPreconnected s) (ht : IsPreconnected t) : IsPreconnected (s ×ˢ t) := by apply isPreconnected_of_forall_pair rintro ⟨a₁, b₁⟩ ⟨ha₁, hb₁⟩ ⟨a₂, b₂⟩ ⟨ha₂, hb₂⟩ refine ⟨Prod.mk a₁ '' t ∪ flip Prod.mk b₂ '' s, ?_, .inl ⟨b₁, hb₁, rfl⟩, .inr ⟨a₂, ha₂, rfl⟩, ?_⟩ · rintro _ (⟨y, hy, rfl⟩ | ⟨x, hx, rfl⟩) exacts [⟨ha₁, hy⟩, ⟨hx, hb₂⟩] · exact (ht.image _ (by fun_prop)).union (a₁, b₂) ⟨b₂, hb₂, rfl⟩ ⟨a₁, ha₁, rfl⟩ (hs.image _ (Continuous.prodMk_left _).continuousOn) theorem IsConnected.prod [TopologicalSpace β] {s : Set α} {t : Set β} (hs : IsConnected s) (ht : IsConnected t) : IsConnected (s ×ˢ t) := ⟨hs.1.prod ht.1, hs.2.prod ht.2⟩ theorem isPreconnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} (hs : ∀ i, IsPreconnected (s i)) : IsPreconnected (pi univ s) := by rintro u v uo vo hsuv ⟨f, hfs, hfu⟩ ⟨g, hgs, hgv⟩ classical rcases exists_finset_piecewise_mem_of_mem_nhds (uo.mem_nhds hfu) g with ⟨I, hI⟩ induction I using Finset.induction_on with | empty => refine ⟨g, hgs, ⟨?_, hgv⟩⟩ simpa using hI | insert i I _ ihI => rw [Finset.piecewise_insert] at hI have := I.piecewise_mem_set_pi hfs hgs refine (hsuv this).elim ihI fun h => ?_ set S := update (I.piecewise f g) i '' s i have hsub : S ⊆ pi univ s := by refine image_subset_iff.2 fun z hz => ?_ rwa [update_preimage_univ_pi] exact fun j _ => this j trivial have hconn : IsPreconnected S := (hs i).image _ (continuous_const.update i continuous_id).continuousOn have hSu : (S ∩ u).Nonempty := ⟨_, mem_image_of_mem _ (hfs _ trivial), hI⟩ have hSv : (S ∩ v).Nonempty := ⟨_, ⟨_, this _ trivial, update_eq_self _ _⟩, h⟩ refine (hconn u v uo vo (hsub.trans hsuv) hSu hSv).mono ?_ exact inter_subset_inter_left _ hsub @[simp] theorem isConnected_univ_pi [∀ i, TopologicalSpace (π i)] {s : ∀ i, Set (π i)} : IsConnected (pi univ s) ↔ ∀ i, IsConnected (s i) := by simp only [IsConnected, ← univ_pi_nonempty_iff, forall_and, and_congr_right_iff] refine fun hne => ⟨fun hc i => ?_, isPreconnected_univ_pi⟩ rw [← eval_image_univ_pi hne] exact hc.image _ (continuous_apply _).continuousOn /-- The connected component of a point is the maximal connected set that contains this point. -/ def connectedComponent (x : α) : Set α := ⋃₀ { s : Set α | IsPreconnected s ∧ x ∈ s } open Classical in /-- Given a set `F` in a topological space `α` and a point `x : α`, the connected component of `x` in `F` is the connected component of `x` in the subtype `F` seen as a set in `α`. This definition does not make sense if `x` is not in `F` so we return the empty set in this case. -/ def connectedComponentIn (F : Set α) (x : α) : Set α := if h : x ∈ F then (↑) '' connectedComponent (⟨x, h⟩ : F) else ∅ theorem connectedComponentIn_eq_image {F : Set α} {x : α} (h : x ∈ F) : connectedComponentIn F x = (↑) '' connectedComponent (⟨x, h⟩ : F) := dif_pos h theorem connectedComponentIn_eq_empty {F : Set α} {x : α} (h : x ∉ F) : connectedComponentIn F x = ∅ := dif_neg h theorem mem_connectedComponent {x : α} : x ∈ connectedComponent x := mem_sUnion_of_mem (mem_singleton x) ⟨isPreconnected_singleton, mem_singleton x⟩ theorem mem_connectedComponentIn {x : α} {F : Set α} (hx : x ∈ F) : x ∈ connectedComponentIn F x := by simp [connectedComponentIn_eq_image hx, mem_connectedComponent, hx] theorem connectedComponent_nonempty {x : α} : (connectedComponent x).Nonempty := ⟨x, mem_connectedComponent⟩ theorem connectedComponentIn_nonempty_iff {x : α} {F : Set α} : (connectedComponentIn F x).Nonempty ↔ x ∈ F := by rw [connectedComponentIn] split_ifs <;> simp [connectedComponent_nonempty, *] theorem connectedComponentIn_subset (F : Set α) (x : α) : connectedComponentIn F x ⊆ F := by rw [connectedComponentIn] split_ifs <;> simp theorem isPreconnected_connectedComponent {x : α} : IsPreconnected (connectedComponent x) := isPreconnected_sUnion x _ (fun _ => And.right) fun _ => And.left theorem isPreconnected_connectedComponentIn {x : α} {F : Set α} : IsPreconnected (connectedComponentIn F x) := by rw [connectedComponentIn]; split_ifs · exact IsInducing.subtypeVal.isPreconnected_image.mpr isPreconnected_connectedComponent · exact isPreconnected_empty theorem isConnected_connectedComponent {x : α} : IsConnected (connectedComponent x) := ⟨⟨x, mem_connectedComponent⟩, isPreconnected_connectedComponent⟩ theorem isConnected_connectedComponentIn_iff {x : α} {F : Set α} : IsConnected (connectedComponentIn F x) ↔ x ∈ F := by simp_rw [← connectedComponentIn_nonempty_iff, IsConnected, isPreconnected_connectedComponentIn, and_true] theorem IsPreconnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsPreconnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := fun _z hz => mem_sUnion_of_mem hz ⟨H1, H2⟩ theorem IsPreconnected.subset_connectedComponentIn {x : α} {F : Set α} (hs : IsPreconnected s) (hxs : x ∈ s) (hsF : s ⊆ F) : s ⊆ connectedComponentIn F x := by have : IsPreconnected (((↑) : F → α) ⁻¹' s) := by refine IsInducing.subtypeVal.isPreconnected_image.mp ?_ rwa [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] have h2xs : (⟨x, hsF hxs⟩ : F) ∈ (↑) ⁻¹' s := by rw [mem_preimage] exact hxs have := this.subset_connectedComponent h2xs rw [connectedComponentIn_eq_image (hsF hxs)] refine Subset.trans ?_ (image_subset _ this) rw [Subtype.image_preimage_coe, inter_eq_right.mpr hsF] theorem IsConnected.subset_connectedComponent {x : α} {s : Set α} (H1 : IsConnected s) (H2 : x ∈ s) : s ⊆ connectedComponent x := H1.2.subset_connectedComponent H2 theorem IsPreconnected.connectedComponentIn {x : α} {F : Set α} (h : IsPreconnected F) (hx : x ∈ F) : connectedComponentIn F x = F := (connectedComponentIn_subset F x).antisymm (h.subset_connectedComponentIn hx subset_rfl) theorem connectedComponent_eq {x y : α} (h : y ∈ connectedComponent x) : connectedComponent x = connectedComponent y := eq_of_subset_of_subset (isConnected_connectedComponent.subset_connectedComponent h) (isConnected_connectedComponent.subset_connectedComponent (Set.mem_of_mem_of_subset mem_connectedComponent (isConnected_connectedComponent.subset_connectedComponent h))) theorem connectedComponent_eq_iff_mem {x y : α} : connectedComponent x = connectedComponent y ↔ x ∈ connectedComponent y := ⟨fun h => h ▸ mem_connectedComponent, fun h => (connectedComponent_eq h).symm⟩ theorem connectedComponentIn_eq {x y : α} {F : Set α} (h : y ∈ connectedComponentIn F x) : connectedComponentIn F x = connectedComponentIn F y := by have hx : x ∈ F := connectedComponentIn_nonempty_iff.mp ⟨y, h⟩ simp_rw [connectedComponentIn_eq_image hx] at h ⊢ obtain ⟨⟨y, hy⟩, h2y, rfl⟩ := h simp_rw [connectedComponentIn_eq_image hy, connectedComponent_eq h2y] theorem connectedComponentIn_univ (x : α) : connectedComponentIn univ x = connectedComponent x := subset_antisymm (isPreconnected_connectedComponentIn.subset_connectedComponent <| mem_connectedComponentIn trivial) (isPreconnected_connectedComponent.subset_connectedComponentIn mem_connectedComponent <| subset_univ _) theorem connectedComponent_disjoint {x y : α} (h : connectedComponent x ≠ connectedComponent y) : Disjoint (connectedComponent x) (connectedComponent y) := Set.disjoint_left.2 fun _ h1 h2 => h ((connectedComponent_eq h1).trans (connectedComponent_eq h2).symm) theorem isClosed_connectedComponent {x : α} : IsClosed (connectedComponent x) := closure_subset_iff_isClosed.1 <| isConnected_connectedComponent.closure.subset_connectedComponent <| subset_closure mem_connectedComponent theorem Continuous.image_connectedComponent_subset [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : f '' connectedComponent a ⊆ connectedComponent (f a) := (isConnected_connectedComponent.image f h.continuousOn).subset_connectedComponent ((mem_image f (connectedComponent a) (f a)).2 ⟨a, mem_connectedComponent, rfl⟩) theorem Continuous.image_connectedComponentIn_subset [TopologicalSpace β] {f : α → β} {s : Set α} {a : α} (hf : Continuous f) (hx : a ∈ s) : f '' connectedComponentIn s a ⊆ connectedComponentIn (f '' s) (f a) := (isPreconnected_connectedComponentIn.image _ hf.continuousOn).subset_connectedComponentIn (mem_image_of_mem _ <| mem_connectedComponentIn hx) (image_subset _ <| connectedComponentIn_subset _ _) theorem Continuous.mapsTo_connectedComponent [TopologicalSpace β] {f : α → β} (h : Continuous f) (a : α) : MapsTo f (connectedComponent a) (connectedComponent (f a)) := mapsTo'.2 <| h.image_connectedComponent_subset a theorem Continuous.mapsTo_connectedComponentIn [TopologicalSpace β] {f : α → β} {s : Set α} (h : Continuous f) {a : α} (hx : a ∈ s) : MapsTo f (connectedComponentIn s a) (connectedComponentIn (f '' s) (f a)) := mapsTo'.2 <| image_connectedComponentIn_subset h hx theorem irreducibleComponent_subset_connectedComponent {x : α} : irreducibleComponent x ⊆ connectedComponent x := isIrreducible_irreducibleComponent.isConnected.subset_connectedComponent mem_irreducibleComponent @[mono] theorem connectedComponentIn_mono (x : α) {F G : Set α} (h : F ⊆ G) : connectedComponentIn F x ⊆ connectedComponentIn G x := by by_cases hx : x ∈ F · rw [connectedComponentIn_eq_image hx, connectedComponentIn_eq_image (h hx), ← show ((↑) : G → α) ∘ inclusion h = (↑) from rfl, image_comp] exact image_subset _ ((continuous_inclusion h).image_connectedComponent_subset ⟨x, hx⟩) · rw [connectedComponentIn_eq_empty hx] exact Set.empty_subset _ /-- A preconnected space is one where there is no non-trivial open partition. -/ class PreconnectedSpace (α : Type u) [TopologicalSpace α] : Prop where /-- The universal set `Set.univ` in a preconnected space is a preconnected set. -/ isPreconnected_univ : IsPreconnected (univ : Set α) export PreconnectedSpace (isPreconnected_univ) /-- A connected space is a nonempty one where there is no non-trivial open partition. -/ class ConnectedSpace (α : Type u) [TopologicalSpace α] : Prop extends PreconnectedSpace α where /-- A connected space is nonempty. -/ toNonempty : Nonempty α attribute [instance 50] ConnectedSpace.toNonempty -- see Note [lower instance priority] -- see Note [lower instance priority] theorem isConnected_univ [ConnectedSpace α] : IsConnected (univ : Set α) := ⟨univ_nonempty, isPreconnected_univ⟩ lemma preconnectedSpace_iff_univ : PreconnectedSpace α ↔ IsPreconnected (univ : Set α) := ⟨fun h ↦ h.1, fun h ↦ ⟨h⟩⟩ lemma connectedSpace_iff_univ : ConnectedSpace α ↔ IsConnected (univ : Set α) := ⟨fun h ↦ ⟨univ_nonempty, h.1.1⟩, fun h ↦ ConnectedSpace.mk (toPreconnectedSpace := ⟨h.2⟩) ⟨h.1.some⟩⟩ theorem isPreconnected_range [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (h : Continuous f) : IsPreconnected (range f) := @image_univ _ _ f ▸ isPreconnected_univ.image _ h.continuousOn theorem isConnected_range [TopologicalSpace β] [ConnectedSpace α] {f : α → β} (h : Continuous f) : IsConnected (range f) := ⟨range_nonempty f, isPreconnected_range h⟩ theorem Function.Surjective.connectedSpace [ConnectedSpace α] [TopologicalSpace β] {f : α → β} (hf : Surjective f) (hf' : Continuous f) : ConnectedSpace β := by rw [connectedSpace_iff_univ, ← hf.range_eq] exact isConnected_range hf' instance Quotient.instConnectedSpace {s : Setoid α} [ConnectedSpace α] : ConnectedSpace (Quotient s) := Quotient.mk'_surjective.connectedSpace continuous_coinduced_rng theorem DenseRange.preconnectedSpace [TopologicalSpace β] [PreconnectedSpace α] {f : α → β} (hf : DenseRange f) (hc : Continuous f) : PreconnectedSpace β := ⟨hf.closure_eq ▸ (isPreconnected_range hc).closure⟩ theorem connectedSpace_iff_connectedComponent : ConnectedSpace α ↔ ∃ x : α, connectedComponent x = univ := by constructor · rintro ⟨⟨x⟩⟩ exact ⟨x, eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x)⟩ · rintro ⟨x, h⟩ haveI : PreconnectedSpace α := ⟨by rw [← h]; exact isPreconnected_connectedComponent⟩ exact ⟨⟨x⟩⟩ theorem preconnectedSpace_iff_connectedComponent : PreconnectedSpace α ↔ ∀ x : α, connectedComponent x = univ := by constructor · intro h x exact eq_univ_of_univ_subset <| isPreconnected_univ.subset_connectedComponent (mem_univ x) · intro h rcases isEmpty_or_nonempty α with hα | hα · exact ⟨by rw [univ_eq_empty_iff.mpr hα]; exact isPreconnected_empty⟩ · exact ⟨by rw [← h (Classical.choice hα)]; exact isPreconnected_connectedComponent⟩ @[simp] theorem PreconnectedSpace.connectedComponent_eq_univ {X : Type*} [TopologicalSpace X] [h : PreconnectedSpace X] (x : X) : connectedComponent x = univ := preconnectedSpace_iff_connectedComponent.mp h x instance [TopologicalSpace β] [PreconnectedSpace α] [PreconnectedSpace β] : PreconnectedSpace (α × β) := ⟨by rw [← univ_prod_univ] exact isPreconnected_univ.prod isPreconnected_univ⟩ instance [TopologicalSpace β] [ConnectedSpace α] [ConnectedSpace β] : ConnectedSpace (α × β) := ⟨inferInstance⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, PreconnectedSpace (π i)] : PreconnectedSpace (∀ i, π i) := ⟨by rw [← pi_univ univ]; exact isPreconnected_univ_pi fun i => isPreconnected_univ⟩ instance [∀ i, TopologicalSpace (π i)] [∀ i, ConnectedSpace (π i)] : ConnectedSpace (∀ i, π i) := ⟨inferInstance⟩ -- see Note [lower instance priority] instance (priority := 100) PreirreducibleSpace.preconnectedSpace (α : Type u) [TopologicalSpace α] [PreirreducibleSpace α] : PreconnectedSpace α := ⟨isPreirreducible_univ.isPreconnected⟩ -- see Note [lower instance priority] instance (priority := 100) IrreducibleSpace.connectedSpace (α : Type u) [TopologicalSpace α] [IrreducibleSpace α] : ConnectedSpace α where toNonempty := IrreducibleSpace.toNonempty theorem Subtype.preconnectedSpace {s : Set α} (h : IsPreconnected s) : PreconnectedSpace s where isPreconnected_univ := by rwa [← IsInducing.subtypeVal.isPreconnected_image, image_univ, Subtype.range_val] theorem Subtype.connectedSpace {s : Set α} (h : IsConnected s) : ConnectedSpace s where toPreconnectedSpace := Subtype.preconnectedSpace h.isPreconnected toNonempty := h.nonempty.to_subtype theorem isPreconnected_iff_preconnectedSpace {s : Set α} : IsPreconnected s ↔ PreconnectedSpace s := ⟨Subtype.preconnectedSpace, fun h => by simpa using isPreconnected_univ.image ((↑) : s → α) continuous_subtype_val.continuousOn⟩ theorem isConnected_iff_connectedSpace {s : Set α} : IsConnected s ↔ ConnectedSpace s := ⟨Subtype.connectedSpace, fun h => ⟨nonempty_subtype.mp h.2, isPreconnected_iff_preconnectedSpace.mpr h.1⟩⟩ end Preconnected
Mathlib/Topology/Connected/Basic.lean
735
742
/- Copyright (c) 2022 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Patrick Massot, Yury Kudryashov, Kevin H. Wilson, Heather Macbeth -/ import Mathlib.Order.Filter.Tendsto /-! # Product and coproduct filters In this file we define `Filter.prod f g` (notation: `f ×ˢ g`) and `Filter.coprod f g`. The product of two filters is the largest filter `l` such that `Filter.Tendsto Prod.fst l f` and `Filter.Tendsto Prod.snd l g`. ## Implementation details The product filter cannot be defined using the monad structure on filters. For example: ```lean F := do {x ← seq, y ← top, return (x, y)} G := do {y ← top, x ← seq, return (x, y)} ``` hence: ```lean s ∈ F ↔ ∃ n, [n..∞] × univ ⊆ s s ∈ G ↔ ∀ i:ℕ, ∃ n, [n..∞] × {i} ⊆ s ``` Now `⋃ i, [i..∞] × {i}` is in `G` but not in `F`. As product filter we want to have `F` as result. ## Notations * `f ×ˢ g` : `Filter.prod f g`, localized in `Filter`. -/ open Set open Filter namespace Filter variable {α β γ δ : Type*} {ι : Sort*} section Prod variable {s : Set α} {t : Set β} {f : Filter α} {g : Filter β} theorem prod_mem_prod (hs : s ∈ f) (ht : t ∈ g) : s ×ˢ t ∈ f ×ˢ g := inter_mem_inf (preimage_mem_comap hs) (preimage_mem_comap ht) theorem mem_prod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} : s ∈ f ×ˢ g ↔ ∃ t₁ ∈ f, ∃ t₂ ∈ g, t₁ ×ˢ t₂ ⊆ s := by constructor · rintro ⟨t₁, ⟨s₁, hs₁, hts₁⟩, t₂, ⟨s₂, hs₂, hts₂⟩, rfl⟩ exact ⟨s₁, hs₁, s₂, hs₂, fun p ⟨h, h'⟩ => ⟨hts₁ h, hts₂ h'⟩⟩ · rintro ⟨t₁, ht₁, t₂, ht₂, h⟩ exact mem_inf_of_inter (preimage_mem_comap ht₁) (preimage_mem_comap ht₂) h @[simp] theorem compl_diagonal_mem_prod {l₁ l₂ : Filter α} : (diagonal α)ᶜ ∈ l₁ ×ˢ l₂ ↔ Disjoint l₁ l₂ := by simp only [mem_prod_iff, Filter.disjoint_iff, prod_subset_compl_diagonal_iff_disjoint] @[simp] theorem prod_mem_prod_iff [f.NeBot] [g.NeBot] : s ×ˢ t ∈ f ×ˢ g ↔ s ∈ f ∧ t ∈ g := ⟨fun h => let ⟨_s', hs', _t', ht', H⟩ := mem_prod_iff.1 h (prod_subset_prod_iff.1 H).elim (fun ⟨hs's, ht't⟩ => ⟨mem_of_superset hs' hs's, mem_of_superset ht' ht't⟩) fun h => h.elim (fun hs'e => absurd hs'e (nonempty_of_mem hs').ne_empty) fun ht'e => absurd ht'e (nonempty_of_mem ht').ne_empty, fun h => prod_mem_prod h.1 h.2⟩ theorem mem_prod_principal {s : Set (α × β)} : s ∈ f ×ˢ 𝓟 t ↔ { a | ∀ b ∈ t, (a, b) ∈ s } ∈ f := by rw [← @exists_mem_subset_iff _ f, mem_prod_iff] refine exists_congr fun u => Iff.rfl.and ⟨?_, fun h => ⟨t, mem_principal_self t, ?_⟩⟩ · rintro ⟨v, v_in, hv⟩ a a_in b b_in exact hv (mk_mem_prod a_in <| v_in b_in) · rintro ⟨x, y⟩ ⟨hx, hy⟩ exact h hx y hy theorem mem_prod_top {s : Set (α × β)} : s ∈ f ×ˢ (⊤ : Filter β) ↔ { a | ∀ b, (a, b) ∈ s } ∈ f := by rw [← principal_univ, mem_prod_principal] simp only [mem_univ, forall_true_left] theorem eventually_prod_principal_iff {p : α × β → Prop} {s : Set β} : (∀ᶠ x : α × β in f ×ˢ 𝓟 s, p x) ↔ ∀ᶠ x : α in f, ∀ y : β, y ∈ s → p (x, y) := by rw [eventually_iff, eventually_iff, mem_prod_principal] simp only [mem_setOf_eq] theorem comap_prod (f : α → β × γ) (b : Filter β) (c : Filter γ) : comap f (b ×ˢ c) = comap (Prod.fst ∘ f) b ⊓ comap (Prod.snd ∘ f) c := by rw [prod_eq_inf, comap_inf, Filter.comap_comap, Filter.comap_comap] theorem comap_prodMap_prod (f : α → β) (g : γ → δ) (lb : Filter β) (ld : Filter δ) : comap (Prod.map f g) (lb ×ˢ ld) = comap f lb ×ˢ comap g ld := by simp [prod_eq_inf, comap_comap, Function.comp_def] theorem prod_top : f ×ˢ (⊤ : Filter β) = f.comap Prod.fst := by rw [prod_eq_inf, comap_top, inf_top_eq] theorem top_prod : (⊤ : Filter α) ×ˢ g = g.comap Prod.snd := by rw [prod_eq_inf, comap_top, top_inf_eq] theorem sup_prod (f₁ f₂ : Filter α) (g : Filter β) : (f₁ ⊔ f₂) ×ˢ g = (f₁ ×ˢ g) ⊔ (f₂ ×ˢ g) := by simp only [prod_eq_inf, comap_sup, inf_sup_right] theorem prod_sup (f : Filter α) (g₁ g₂ : Filter β) : f ×ˢ (g₁ ⊔ g₂) = (f ×ˢ g₁) ⊔ (f ×ˢ g₂) := by simp only [prod_eq_inf, comap_sup, inf_sup_left] theorem eventually_prod_iff {p : α × β → Prop} : (∀ᶠ x in f ×ˢ g, p x) ↔ ∃ pa : α → Prop, (∀ᶠ x in f, pa x) ∧ ∃ pb : β → Prop, (∀ᶠ y in g, pb y) ∧ ∀ {x}, pa x → ∀ {y}, pb y → p (x, y) := by simpa only [Set.prod_subset_iff] using @mem_prod_iff α β p f g theorem tendsto_fst : Tendsto Prod.fst (f ×ˢ g) f := tendsto_inf_left tendsto_comap theorem tendsto_snd : Tendsto Prod.snd (f ×ˢ g) g := tendsto_inf_right tendsto_comap /-- If a function tends to a product `g ×ˢ h` of filters, then its first component tends to `g`. See also `Filter.Tendsto.fst_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.fst {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↦ (m a).1) f g := tendsto_fst.comp H /-- If a function tends to a product `g ×ˢ h` of filters, then its second component tends to `h`. See also `Filter.Tendsto.snd_nhds` for the special case of converging to a point in a product of two topological spaces. -/ theorem Tendsto.snd {h : Filter γ} {m : α → β × γ} (H : Tendsto m f (g ×ˢ h)) : Tendsto (fun a ↦ (m a).2) f h := tendsto_snd.comp H theorem Tendsto.prodMk {h : Filter γ} {m₁ : α → β} {m₂ : α → γ} (h₁ : Tendsto m₁ f g) (h₂ : Tendsto m₂ f h) : Tendsto (fun x => (m₁ x, m₂ x)) f (g ×ˢ h) := tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ @[deprecated (since := "2025-03-10")] alias Tendsto.prod_mk := Tendsto.prodMk theorem tendsto_prod_swap : Tendsto (Prod.swap : α × β → β × α) (f ×ˢ g) (g ×ˢ f) := tendsto_snd.prodMk tendsto_fst theorem Eventually.prod_inl {la : Filter α} {p : α → Prop} (h : ∀ᶠ x in la, p x) (lb : Filter β) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).1 := tendsto_fst.eventually h theorem Eventually.prod_inr {lb : Filter β} {p : β → Prop} (h : ∀ᶠ x in lb, p x) (la : Filter α) : ∀ᶠ x in la ×ˢ lb, p (x : α × β).2 := tendsto_snd.eventually h theorem Eventually.prod_mk {la : Filter α} {pa : α → Prop} (ha : ∀ᶠ x in la, pa x) {lb : Filter β} {pb : β → Prop} (hb : ∀ᶠ y in lb, pb y) : ∀ᶠ p in la ×ˢ lb, pa (p : α × β).1 ∧ pb p.2 := (ha.prod_inl lb).and (hb.prod_inr la) theorem EventuallyEq.prodMap {δ} {la : Filter α} {fa ga : α → γ} (ha : fa =ᶠ[la] ga) {lb : Filter β} {fb gb : β → δ} (hb : fb =ᶠ[lb] gb) : Prod.map fa fb =ᶠ[la ×ˢ lb] Prod.map ga gb := (Eventually.prod_mk ha hb).mono fun _ h => Prod.ext h.1 h.2 @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_map := EventuallyEq.prodMap theorem EventuallyLE.prodMap {δ} [LE γ] [LE δ] {la : Filter α} {fa ga : α → γ} (ha : fa ≤ᶠ[la] ga) {lb : Filter β} {fb gb : β → δ} (hb : fb ≤ᶠ[lb] gb) : Prod.map fa fb ≤ᶠ[la ×ˢ lb] Prod.map ga gb := Eventually.prod_mk ha hb @[deprecated (since := "2025-03-10")] alias EventuallyLE.prod_map := EventuallyLE.prodMap theorem Eventually.curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∀ᶠ x in la ×ˢ lb, p x) : ∀ᶠ x in la, ∀ᶠ y in lb, p (x, y) := by rcases eventually_prod_iff.1 h with ⟨pa, ha, pb, hb, h⟩ exact ha.mono fun a ha => hb.mono fun b hb => h ha hb protected lemma Frequently.uncurry {la : Filter α} {lb : Filter β} {p : α → β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p x y) : ∃ᶠ xy in la ×ˢ lb, p xy.1 xy.2 := mt (fun h ↦ by simpa only [not_frequently] using h.curry) h lemma Frequently.of_curry {la : Filter α} {lb : Filter β} {p : α × β → Prop} (h : ∃ᶠ x in la, ∃ᶠ y in lb, p (x, y)) : ∃ᶠ xy in la ×ˢ lb, p xy := h.uncurry /-- A fact that is eventually true about all pairs `l ×ˢ l` is eventually true about all diagonal pairs `(i, i)` -/ theorem Eventually.diag_of_prod {p : α × α → Prop} (h : ∀ᶠ i in f ×ˢ f, p i) : ∀ᶠ i in f, p (i, i) := by obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h apply (ht.and hs).mono fun x hx => hst hx.1 hx.2 theorem Eventually.diag_of_prod_left {f : Filter α} {g : Filter γ} {p : (α × α) × γ → Prop} : (∀ᶠ x in (f ×ˢ f) ×ˢ g, p x) → ∀ᶠ x : α × γ in f ×ˢ g, p ((x.1, x.1), x.2) := by intro h obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.diag_of_prod.prod_mk hs).mono fun x hx => by simp only [hst hx.1 hx.2] theorem Eventually.diag_of_prod_right {f : Filter α} {g : Filter γ} {p : α × γ × γ → Prop} : (∀ᶠ x in f ×ˢ (g ×ˢ g), p x) → ∀ᶠ x : α × γ in f ×ˢ g, p (x.1, x.2, x.2) := by intro h obtain ⟨t, ht, s, hs, hst⟩ := eventually_prod_iff.1 h exact (ht.prod_mk hs.diag_of_prod).mono fun x hx => by simp only [hst hx.1 hx.2] theorem tendsto_diag : Tendsto (fun i => (i, i)) f (f ×ˢ f) := tendsto_iff_eventually.mpr fun _ hpr => hpr.diag_of_prod theorem prod_iInf_left [Nonempty ι] {f : ι → Filter α} {g : Filter β} : (⨅ i, f i) ×ˢ g = ⨅ i, f i ×ˢ g := by simp only [prod_eq_inf, comap_iInf, iInf_inf] theorem prod_iInf_right [Nonempty ι] {f : Filter α} {g : ι → Filter β} : (f ×ˢ ⨅ i, g i) = ⨅ i, f ×ˢ g i := by simp only [prod_eq_inf, comap_iInf, inf_iInf] @[mono, gcongr] theorem prod_mono {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ := inf_le_inf (comap_mono hf) (comap_mono hg) @[gcongr] theorem prod_mono_left (g : Filter β) {f₁ f₂ : Filter α} (hf : f₁ ≤ f₂) : f₁ ×ˢ g ≤ f₂ ×ˢ g := Filter.prod_mono hf rfl.le @[gcongr] theorem prod_mono_right (f : Filter α) {g₁ g₂ : Filter β} (hf : g₁ ≤ g₂) : f ×ˢ g₁ ≤ f ×ˢ g₂ := Filter.prod_mono rfl.le hf theorem prod_comap_comap_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : β₁ → α₁} {m₂ : β₂ → α₂} : comap m₁ f₁ ×ˢ comap m₂ f₂ = comap (fun p : β₁ × β₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := by simp only [prod_eq_inf, comap_comap, comap_inf, Function.comp_def] theorem prod_comm' : f ×ˢ g = comap Prod.swap (g ×ˢ f) := by simp only [prod_eq_inf, comap_comap, Function.comp_def, inf_comm, Prod.swap, comap_inf] theorem prod_comm : f ×ˢ g = map (fun p : β × α => (p.2, p.1)) (g ×ˢ f) := by rw [prod_comm', ← map_swap_eq_comap_swap] rfl theorem mem_prod_iff_left {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ f, ∀ᶠ y in g, ∀ x ∈ t, (x, y) ∈ s := by simp only [mem_prod_iff, prod_subset_iff] refine exists_congr fun _ => Iff.rfl.and <| Iff.trans ?_ exists_mem_subset_iff exact exists_congr fun _ => Iff.rfl.and forall₂_swap theorem mem_prod_iff_right {s : Set (α × β)} : s ∈ f ×ˢ g ↔ ∃ t ∈ g, ∀ᶠ x in f, ∀ y ∈ t, (x, y) ∈ s := by rw [prod_comm, mem_map, mem_prod_iff_left]; rfl @[simp] theorem map_fst_prod (f : Filter α) (g : Filter β) [NeBot g] : map Prod.fst (f ×ˢ g) = f := by ext s simp only [mem_map, mem_prod_iff_left, mem_preimage, eventually_const, ← subset_def, exists_mem_subset_iff] @[simp] theorem map_snd_prod (f : Filter α) (g : Filter β) [NeBot f] : map Prod.snd (f ×ˢ g) = g := by rw [prod_comm, map_map]; apply map_fst_prod @[simp] theorem prod_le_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ ≤ f₂ ×ˢ g₂ ↔ f₁ ≤ f₂ ∧ g₁ ≤ g₂ := ⟨fun h => ⟨map_fst_prod f₁ g₁ ▸ tendsto_fst.mono_left h, map_snd_prod f₁ g₁ ▸ tendsto_snd.mono_left h⟩, fun h => prod_mono h.1 h.2⟩ @[simp] theorem prod_inj {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} [NeBot f₁] [NeBot g₁] : f₁ ×ˢ g₁ = f₂ ×ˢ g₂ ↔ f₁ = f₂ ∧ g₁ = g₂ := by refine ⟨fun h => ?_, fun h => h.1 ▸ h.2 ▸ rfl⟩ have hle : f₁ ≤ f₂ ∧ g₁ ≤ g₂ := prod_le_prod.1 h.le haveI := neBot_of_le hle.1; haveI := neBot_of_le hle.2 exact ⟨hle.1.antisymm <| (prod_le_prod.1 h.ge).1, hle.2.antisymm <| (prod_le_prod.1 h.ge).2⟩ theorem eventually_swap_iff {p : α × β → Prop} : (∀ᶠ x : α × β in f ×ˢ g, p x) ↔ ∀ᶠ y : β × α in g ×ˢ f, p y.swap := by rw [prod_comm]; rfl theorem prod_assoc (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) = f ×ˢ (g ×ˢ h) := by simp_rw [← comap_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_symm_apply] theorem prod_assoc_symm (f : Filter α) (g : Filter β) (h : Filter γ) : map (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) = (f ×ˢ g) ×ˢ h := by simp_rw [map_equiv_symm, prod_eq_inf, comap_inf, comap_comap, inf_assoc, Function.comp_def, Equiv.prodAssoc_apply] theorem tendsto_prodAssoc {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ) ((f ×ˢ g) ×ˢ h) (f ×ˢ (g ×ˢ h)) := (prod_assoc f g h).le theorem tendsto_prodAssoc_symm {h : Filter γ} : Tendsto (Equiv.prodAssoc α β γ).symm (f ×ˢ (g ×ˢ h)) ((f ×ˢ g) ×ˢ h) := (prod_assoc_symm f g h).le /-- A useful lemma when dealing with uniformities. -/ theorem map_swap4_prod {h : Filter γ} {k : Filter δ} : map (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) = (f ×ˢ h) ×ˢ (g ×ˢ k) := by simp_rw [map_swap4_eq_comap, prod_eq_inf, comap_inf, comap_comap]; ac_rfl theorem tendsto_swap4_prod {h : Filter γ} {k : Filter δ} : Tendsto (fun p : (α × β) × γ × δ => ((p.1.1, p.2.1), (p.1.2, p.2.2))) ((f ×ˢ g) ×ˢ (h ×ˢ k)) ((f ×ˢ h) ×ˢ (g ×ˢ k)) := map_swap4_prod.le theorem prod_map_map_eq.{u, v, w, x} {α₁ : Type u} {α₂ : Type v} {β₁ : Type w} {β₂ : Type x} {f₁ : Filter α₁} {f₂ : Filter α₂} {m₁ : α₁ → β₁} {m₂ : α₂ → β₂} : map m₁ f₁ ×ˢ map m₂ f₂ = map (fun p : α₁ × α₂ => (m₁ p.1, m₂ p.2)) (f₁ ×ˢ f₂) := le_antisymm (fun s hs => let ⟨s₁, hs₁, s₂, hs₂, h⟩ := mem_prod_iff.mp hs mem_of_superset (prod_mem_prod (image_mem_map hs₁) (image_mem_map hs₂)) <| by rwa [prod_image_image_eq, image_subset_iff]) ((tendsto_map.comp tendsto_fst).prodMk (tendsto_map.comp tendsto_snd)) theorem prod_map_map_eq' {α₁ : Type*} {α₂ : Type*} {β₁ : Type*} {β₂ : Type*} (f : α₁ → α₂) (g : β₁ → β₂) (F : Filter α₁) (G : Filter β₁) : map f F ×ˢ map g G = map (Prod.map f g) (F ×ˢ G) := prod_map_map_eq theorem prod_map_left (f : α → β) (F : Filter α) (G : Filter γ) : map f F ×ˢ G = map (Prod.map f id) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem prod_map_right (f : β → γ) (F : Filter α) (G : Filter β) : F ×ˢ map f G = map (Prod.map id f) (F ×ˢ G) := by rw [← prod_map_map_eq', map_id] theorem le_prod_map_fst_snd {f : Filter (α × β)} : f ≤ map Prod.fst f ×ˢ map Prod.snd f := le_inf le_comap_map le_comap_map theorem Tendsto.prodMap {δ : Type*} {f : α → γ} {g : β → δ} {a : Filter α} {b : Filter β} {c : Filter γ} {d : Filter δ} (hf : Tendsto f a c) (hg : Tendsto g b d) : Tendsto (Prod.map f g) (a ×ˢ b) (c ×ˢ d) := by rw [Tendsto, Prod.map_def, ← prod_map_map_eq] exact Filter.prod_mono hf hg @[deprecated (since := "2025-03-10")] alias Tendsto.prod_map := Tendsto.prodMap protected theorem map_prod (m : α × β → γ) (f : Filter α) (g : Filter β) : map m (f ×ˢ g) = (f.map fun a b => m (a, b)).seq g := by simp only [Filter.ext_iff, mem_map, mem_prod_iff, mem_map_seq_iff, exists_and_left] intro s constructor · exact fun ⟨t, ht, s, hs, h⟩ => ⟨s, hs, t, ht, fun x hx y hy => @h ⟨x, y⟩ ⟨hx, hy⟩⟩ · exact fun ⟨s, hs, t, ht, h⟩ => ⟨t, ht, s, hs, fun ⟨x, y⟩ ⟨hx, hy⟩ => h x hx y hy⟩ theorem prod_eq : f ×ˢ g = (f.map Prod.mk).seq g := f.map_prod id g theorem prod_inf_prod {f₁ f₂ : Filter α} {g₁ g₂ : Filter β} : (f₁ ×ˢ g₁) ⊓ (f₂ ×ˢ g₂) = (f₁ ⊓ f₂) ×ˢ (g₁ ⊓ g₂) := by simp only [prod_eq_inf, comap_inf, inf_comm, inf_assoc, inf_left_comm] theorem inf_prod {f₁ f₂ : Filter α} : (f₁ ⊓ f₂) ×ˢ g = (f₁ ×ˢ g) ⊓ (f₂ ×ˢ g) := by rw [prod_inf_prod, inf_idem] theorem prod_inf {g₁ g₂ : Filter β} : f ×ˢ (g₁ ⊓ g₂) = (f ×ˢ g₁) ⊓ (f ×ˢ g₂) := by rw [prod_inf_prod, inf_idem] @[simp] theorem prod_principal_principal {s : Set α} {t : Set β} : 𝓟 s ×ˢ 𝓟 t = 𝓟 (s ×ˢ t) := by simp only [prod_eq_inf, comap_principal, principal_eq_iff_eq, comap_principal, inf_principal]; rfl @[simp] theorem pure_prod {a : α} {f : Filter β} : pure a ×ˢ f = map (Prod.mk a) f := by rw [prod_eq, map_pure, pure_seq_eq_map] theorem map_pure_prod (f : α → β → γ) (a : α) (B : Filter β) : map (Function.uncurry f) (pure a ×ˢ B) = map (f a) B := by rw [Filter.pure_prod]; rfl @[simp] theorem prod_pure {b : β} : f ×ˢ pure b = map (fun a => (a, b)) f := by rw [prod_eq, seq_pure, map_map]; rfl theorem prod_pure_pure {a : α} {b : β} : (pure a : Filter α) ×ˢ (pure b : Filter β) = pure (a, b) := by simp @[simp] theorem prod_eq_bot : f ×ˢ g = ⊥ ↔ f = ⊥ ∨ g = ⊥ := by simp_rw [← empty_mem_iff_bot, mem_prod_iff, subset_empty_iff, prod_eq_empty_iff, ← exists_prop, Subtype.exists', exists_or, exists_const, Subtype.exists, exists_prop, exists_eq_right] @[simp] theorem prod_bot : f ×ˢ (⊥ : Filter β) = ⊥ := prod_eq_bot.2 <| Or.inr rfl @[simp] theorem bot_prod : (⊥ : Filter α) ×ˢ g = ⊥ := prod_eq_bot.2 <| Or.inl rfl theorem prod_neBot : NeBot (f ×ˢ g) ↔ NeBot f ∧ NeBot g := by simp only [neBot_iff, Ne, prod_eq_bot, not_or] protected theorem NeBot.prod (hf : NeBot f) (hg : NeBot g) : NeBot (f ×ˢ g) := prod_neBot.2 ⟨hf, hg⟩ instance prod.instNeBot [hf : NeBot f] [hg : NeBot g] : NeBot (f ×ˢ g) := hf.prod hg @[simp] lemma disjoint_prod {f' : Filter α} {g' : Filter β} : Disjoint (f ×ˢ g) (f' ×ˢ g') ↔ Disjoint f f' ∨ Disjoint g g' := by simp only [disjoint_iff, prod_inf_prod, prod_eq_bot] /-- `p ∧ q` occurs frequently along the product of two filters iff both `p` and `q` occur frequently along the corresponding filters. -/ theorem frequently_prod_and {p : α → Prop} {q : β → Prop} : (∃ᶠ x in f ×ˢ g, p x.1 ∧ q x.2) ↔ (∃ᶠ a in f, p a) ∧ ∃ᶠ b in g, q b := by simp only [frequently_iff_neBot, ← prod_neBot, ← prod_inf_prod, prod_principal_principal] rfl theorem tendsto_prod_iff {f : α × β → γ} {x : Filter α} {y : Filter β} {z : Filter γ} : Tendsto f (x ×ˢ y) z ↔ ∀ W ∈ z, ∃ U ∈ x, ∃ V ∈ y, ∀ x y, x ∈ U → y ∈ V → f (x, y) ∈ W := by simp only [tendsto_def, mem_prod_iff, prod_sub_preimage_iff, exists_prop] theorem tendsto_prod_iff' {g' : Filter γ} {s : α → β × γ} : Tendsto s f (g ×ˢ g') ↔ Tendsto (fun n => (s n).1) f g ∧ Tendsto (fun n => (s n).2) f g' := by simp only [prod_eq_inf, tendsto_inf, tendsto_comap_iff, Function.comp_def] theorem le_prod {f : Filter (α × β)} {g : Filter α} {g' : Filter β} : (f ≤ g ×ˢ g') ↔ Tendsto Prod.fst f g ∧ Tendsto Prod.snd f g' := tendsto_prod_iff' end Prod /-! ### Coproducts of filters -/ section Coprod variable {f : Filter α} {g : Filter β} theorem coprod_eq_prod_top_sup_top_prod (f : Filter α) (g : Filter β) : Filter.coprod f g = f ×ˢ ⊤ ⊔ ⊤ ×ˢ g := by rw [prod_top, top_prod] rfl theorem mem_coprod_iff {s : Set (α × β)} {f : Filter α} {g : Filter β} :
s ∈ f.coprod g ↔ (∃ t₁ ∈ f, Prod.fst ⁻¹' t₁ ⊆ s) ∧ ∃ t₂ ∈ g, Prod.snd ⁻¹' t₂ ⊆ s := by simp [Filter.coprod]
Mathlib/Order/Filter/Prod.lean
441
443
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import Mathlib.Order.PropInstances import Mathlib.Order.GaloisConnection.Defs /-! # Heyting algebras This file defines Heyting, co-Heyting and bi-Heyting algebras. A Heyting algebra is a bounded distributive lattice with an implication operation `⇨` such that `a ≤ b ⇨ c ↔ a ⊓ b ≤ c`. It also comes with a pseudo-complement `ᶜ`, such that `aᶜ = a ⇨ ⊥`. Co-Heyting algebras are dual to Heyting algebras. They have a difference `\` and a negation `¬` such that `a \ b ≤ c ↔ a ≤ b ⊔ c` and `¬a = ⊤ \ a`. Bi-Heyting algebras are Heyting algebras that are also co-Heyting algebras. From a logic standpoint, Heyting algebras precisely model intuitionistic logic, whereas boolean algebras model classical logic. Heyting algebras are the order theoretic equivalent of cartesian-closed categories. ## Main declarations * `GeneralizedHeytingAlgebra`: Heyting algebra without a top element (nor negation). * `GeneralizedCoheytingAlgebra`: Co-Heyting algebra without a bottom element (nor complement). * `HeytingAlgebra`: Heyting algebra. * `CoheytingAlgebra`: Co-Heyting algebra. * `BiheytingAlgebra`: bi-Heyting algebra. ## References * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] ## Tags Heyting, Brouwer, algebra, implication, negation, intuitionistic -/ assert_not_exists RelIso open Function OrderDual universe u variable {ι α β : Type*} /-! ### Notation -/ section variable (α β) instance Prod.instHImp [HImp α] [HImp β] : HImp (α × β) := ⟨fun a b => (a.1 ⇨ b.1, a.2 ⇨ b.2)⟩ instance Prod.instHNot [HNot α] [HNot β] : HNot (α × β) := ⟨fun a => (¬a.1, ¬a.2)⟩ instance Prod.instSDiff [SDiff α] [SDiff β] : SDiff (α × β) := ⟨fun a b => (a.1 \ b.1, a.2 \ b.2)⟩ instance Prod.instHasCompl [HasCompl α] [HasCompl β] : HasCompl (α × β) := ⟨fun a => (a.1ᶜ, a.2ᶜ)⟩ end @[simp] theorem fst_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).1 = a.1 ⇨ b.1 := rfl @[simp] theorem snd_himp [HImp α] [HImp β] (a b : α × β) : (a ⇨ b).2 = a.2 ⇨ b.2 := rfl @[simp] theorem fst_hnot [HNot α] [HNot β] (a : α × β) : (¬a).1 = ¬a.1 := rfl @[simp] theorem snd_hnot [HNot α] [HNot β] (a : α × β) : (¬a).2 = ¬a.2 := rfl @[simp] theorem fst_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).1 = a.1 \ b.1 := rfl @[simp] theorem snd_sdiff [SDiff α] [SDiff β] (a b : α × β) : (a \ b).2 = a.2 \ b.2 := rfl @[simp] theorem fst_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.1 = a.1ᶜ := rfl @[simp] theorem snd_compl [HasCompl α] [HasCompl β] (a : α × β) : aᶜ.2 = a.2ᶜ := rfl namespace Pi variable {π : ι → Type*} instance [∀ i, HImp (π i)] : HImp (∀ i, π i) := ⟨fun a b i => a i ⇨ b i⟩ instance [∀ i, HNot (π i)] : HNot (∀ i, π i) := ⟨fun a i => ¬a i⟩ theorem himp_def [∀ i, HImp (π i)] (a b : ∀ i, π i) : a ⇨ b = fun i => a i ⇨ b i := rfl theorem hnot_def [∀ i, HNot (π i)] (a : ∀ i, π i) : ¬a = fun i => ¬a i := rfl @[simp] theorem himp_apply [∀ i, HImp (π i)] (a b : ∀ i, π i) (i : ι) : (a ⇨ b) i = a i ⇨ b i := rfl @[simp] theorem hnot_apply [∀ i, HNot (π i)] (a : ∀ i, π i) (i : ι) : (¬a) i = ¬a i := rfl end Pi /-- A generalized Heyting algebra is a lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. This generalizes `HeytingAlgebra` by not requiring a bottom element. -/ class GeneralizedHeytingAlgebra (α : Type*) extends Lattice α, OrderTop α, HImp α where /-- `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)` -/ le_himp_iff (a b c : α) : a ≤ b ⇨ c ↔ a ⊓ b ≤ c /-- A generalized co-Heyting algebra is a lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. This generalizes `CoheytingAlgebra` by not requiring a top element. -/ class GeneralizedCoheytingAlgebra (α : Type*) extends Lattice α, OrderBot α, SDiff α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- A Heyting algebra is a bounded lattice with an additional binary operation `⇨` called Heyting implication such that `(a ⇨ ·)` is right adjoint to `(a ⊓ ·)`. -/ class HeytingAlgebra (α : Type*) extends GeneralizedHeytingAlgebra α, OrderBot α, HasCompl α where /-- `aᶜ` is defined as `a ⇨ ⊥` -/ himp_bot (a : α) : a ⇨ ⊥ = aᶜ /-- A co-Heyting algebra is a bounded lattice with an additional binary difference operation `\` such that `(· \ a)` is left adjoint to `(· ⊔ a)`. -/ class CoheytingAlgebra (α : Type*) extends GeneralizedCoheytingAlgebra α, OrderTop α, HNot α where /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a /-- A bi-Heyting algebra is a Heyting algebra that is also a co-Heyting algebra. -/ class BiheytingAlgebra (α : Type*) extends HeytingAlgebra α, SDiff α, HNot α where /-- `(· \ a)` is left adjoint to `(· ⊔ a)` -/ sdiff_le_iff (a b c : α) : a \ b ≤ c ↔ a ≤ b ⊔ c /-- `⊤ \ a` is `¬a` -/ top_sdiff (a : α) : ⊤ \ a = ¬a -- See note [lower instance priority] attribute [instance 100] GeneralizedHeytingAlgebra.toOrderTop attribute [instance 100] GeneralizedCoheytingAlgebra.toOrderBot -- See note [lower instance priority] instance (priority := 100) HeytingAlgebra.toBoundedOrder [HeytingAlgebra α] : BoundedOrder α := { bot_le := ‹HeytingAlgebra α›.bot_le } -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toBoundedOrder [CoheytingAlgebra α] : BoundedOrder α := { ‹CoheytingAlgebra α› with } -- See note [lower instance priority] instance (priority := 100) BiheytingAlgebra.toCoheytingAlgebra [BiheytingAlgebra α] : CoheytingAlgebra α := { ‹BiheytingAlgebra α› with } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and Heyting implication alone. -/ abbrev HeytingAlgebra.ofHImp [DistribLattice α] [BoundedOrder α] (himp : α → α → α) (le_himp_iff : ∀ a b c, a ≤ himp b c ↔ a ⊓ b ≤ c) : HeytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with himp, compl := fun a => himp a ⊥, le_himp_iff, himp_bot := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a Heyting algebra from the lattice structure and complement operator alone. -/ abbrev HeytingAlgebra.ofCompl [DistribLattice α] [BoundedOrder α] (compl : α → α) (le_himp_iff : ∀ a b c, a ≤ compl b ⊔ c ↔ a ⊓ b ≤ c) : HeytingAlgebra α where himp := (compl · ⊔ ·) compl := compl le_himp_iff := le_himp_iff himp_bot _ := sup_bot_eq _ -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the lattice structure and the difference alone. -/ abbrev CoheytingAlgebra.ofSDiff [DistribLattice α] [BoundedOrder α] (sdiff : α → α → α) (sdiff_le_iff : ∀ a b c, sdiff a b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α := { ‹DistribLattice α›, ‹BoundedOrder α› with sdiff, hnot := fun a => sdiff ⊤ a, sdiff_le_iff, top_sdiff := fun _ => rfl } -- See note [reducible non-instances] /-- Construct a co-Heyting algebra from the difference and Heyting negation alone. -/ abbrev CoheytingAlgebra.ofHNot [DistribLattice α] [BoundedOrder α] (hnot : α → α) (sdiff_le_iff : ∀ a b c, a ⊓ hnot b ≤ c ↔ a ≤ b ⊔ c) : CoheytingAlgebra α where sdiff a b := a ⊓ hnot b hnot := hnot sdiff_le_iff := sdiff_le_iff top_sdiff _ := top_inf_eq _ /-! In this section, we'll give interpretations of these results in the Heyting algebra model of intuitionistic logic,- where `≤` can be interpreted as "validates", `⇨` as "implies", `⊓` as "and", `⊔` as "or", `⊥` as "false" and `⊤` as "true". Note that we confuse `→` and `⊢` because those are the same in this logic. See also `Prop.heytingAlgebra`. -/ section GeneralizedHeytingAlgebra variable [GeneralizedHeytingAlgebra α] {a b c d : α} /-- `p → q → r ↔ p ∧ q → r` -/ @[simp] theorem le_himp_iff : a ≤ b ⇨ c ↔ a ⊓ b ≤ c := GeneralizedHeytingAlgebra.le_himp_iff _ _ _ /-- `p → q → r ↔ q ∧ p → r` -/ theorem le_himp_iff' : a ≤ b ⇨ c ↔ b ⊓ a ≤ c := by rw [le_himp_iff, inf_comm] /-- `p → q → r ↔ q → p → r` -/ theorem le_himp_comm : a ≤ b ⇨ c ↔ b ≤ a ⇨ c := by rw [le_himp_iff, le_himp_iff'] /-- `p → q → p` -/ theorem le_himp : a ≤ b ⇨ a := le_himp_iff.2 inf_le_left /-- `p → p → q ↔ p → q` -/ theorem le_himp_iff_left : a ≤ a ⇨ b ↔ a ≤ b := by rw [le_himp_iff, inf_idem] /-- `p → p` -/ @[simp] theorem himp_self : a ⇨ a = ⊤ := top_le_iff.1 <| le_himp_iff.2 inf_le_right /-- `(p → q) ∧ p → q` -/ theorem himp_inf_le : (a ⇨ b) ⊓ a ≤ b := le_himp_iff.1 le_rfl /-- `p ∧ (p → q) → q` -/ theorem inf_himp_le : a ⊓ (a ⇨ b) ≤ b := by rw [inf_comm, ← le_himp_iff] /-- `p ∧ (p → q) ↔ p ∧ q` -/ @[simp] theorem inf_himp (a b : α) : a ⊓ (a ⇨ b) = a ⊓ b := le_antisymm (le_inf inf_le_left <| by rw [inf_comm, ← le_himp_iff]) <| inf_le_inf_left _ le_himp /-- `(p → q) ∧ p ↔ q ∧ p` -/ @[simp] theorem himp_inf_self (a b : α) : (a ⇨ b) ⊓ a = b ⊓ a := by rw [inf_comm, inf_himp, inf_comm] /-- The **deduction theorem** in the Heyting algebra model of intuitionistic logic: an implication holds iff the conclusion follows from the hypothesis. -/ @[simp] theorem himp_eq_top_iff : a ⇨ b = ⊤ ↔ a ≤ b := by rw [← top_le_iff, le_himp_iff, top_inf_eq] /-- `p → true`, `true → p ↔ p` -/ @[simp] theorem himp_top : a ⇨ ⊤ = ⊤ := himp_eq_top_iff.2 le_top @[simp] theorem top_himp : ⊤ ⇨ a = a := eq_of_forall_le_iff fun b => by rw [le_himp_iff, inf_top_eq] /-- `p → q → r ↔ p ∧ q → r` -/ theorem himp_himp (a b c : α) : a ⇨ b ⇨ c = a ⊓ b ⇨ c := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, inf_assoc] /-- `(q → r) → (p → q) → q → r` -/ theorem himp_le_himp_himp_himp : b ⇨ c ≤ (a ⇨ b) ⇨ a ⇨ c := by rw [le_himp_iff, le_himp_iff, inf_assoc, himp_inf_self, ← inf_assoc, himp_inf_self, inf_assoc] exact inf_le_left @[simp] theorem himp_inf_himp_inf_le : (b ⇨ c) ⊓ (a ⇨ b) ⊓ a ≤ c := by simpa using @himp_le_himp_himp_himp /-- `p → q → r ↔ q → p → r` -/ theorem himp_left_comm (a b c : α) : a ⇨ b ⇨ c = b ⇨ a ⇨ c := by simp_rw [himp_himp, inf_comm] @[simp] theorem himp_idem : b ⇨ b ⇨ a = b ⇨ a := by rw [himp_himp, inf_idem] theorem himp_inf_distrib (a b c : α) : a ⇨ b ⊓ c = (a ⇨ b) ⊓ (a ⇨ c) := eq_of_forall_le_iff fun d => by simp_rw [le_himp_iff, le_inf_iff, le_himp_iff] theorem sup_himp_distrib (a b c : α) : a ⊔ b ⇨ c = (a ⇨ c) ⊓ (b ⇨ c) := eq_of_forall_le_iff fun d => by rw [le_inf_iff, le_himp_comm, sup_le_iff] simp_rw [le_himp_comm] theorem himp_le_himp_left (h : a ≤ b) : c ⇨ a ≤ c ⇨ b := le_himp_iff.2 <| himp_inf_le.trans h theorem himp_le_himp_right (h : a ≤ b) : b ⇨ c ≤ a ⇨ c := le_himp_iff.2 <| (inf_le_inf_left _ h).trans himp_inf_le theorem himp_le_himp (hab : a ≤ b) (hcd : c ≤ d) : b ⇨ c ≤ a ⇨ d := (himp_le_himp_right hab).trans <| himp_le_himp_left hcd @[simp] theorem sup_himp_self_left (a b : α) : a ⊔ b ⇨ a = b ⇨ a := by rw [sup_himp_distrib, himp_self, top_inf_eq] @[simp] theorem sup_himp_self_right (a b : α) : a ⊔ b ⇨ b = a ⇨ b := by rw [sup_himp_distrib, himp_self, inf_top_eq] theorem Codisjoint.himp_eq_right (h : Codisjoint a b) : b ⇨ a = a := by conv_rhs => rw [← @top_himp _ _ a] rw [← h.eq_top, sup_himp_self_left] theorem Codisjoint.himp_eq_left (h : Codisjoint a b) : a ⇨ b = b := h.symm.himp_eq_right theorem Codisjoint.himp_inf_cancel_right (h : Codisjoint a b) : a ⇨ a ⊓ b = b := by rw [himp_inf_distrib, himp_self, top_inf_eq, h.himp_eq_left] theorem Codisjoint.himp_inf_cancel_left (h : Codisjoint a b) : b ⇨ a ⊓ b = a := by rw [himp_inf_distrib, himp_self, inf_top_eq, h.himp_eq_right] /-- See `himp_le` for a stronger version in Boolean algebras. -/ theorem Codisjoint.himp_le_of_right_le (hac : Codisjoint a c) (hba : b ≤ a) : c ⇨ b ≤ a := (himp_le_himp_left hba).trans_eq hac.himp_eq_right theorem le_himp_himp : a ≤ (a ⇨ b) ⇨ b := le_himp_iff.2 inf_himp_le @[simp] lemma himp_eq_himp_iff : b ⇨ a = a ⇨ b ↔ a = b := by simp [le_antisymm_iff] lemma himp_ne_himp_iff : b ⇨ a ≠ a ⇨ b ↔ a ≠ b := himp_eq_himp_iff.not theorem himp_triangle (a b c : α) : (a ⇨ b) ⊓ (b ⇨ c) ≤ a ⇨ c := by rw [le_himp_iff, inf_right_comm, ← le_himp_iff] exact himp_inf_le.trans le_himp_himp theorem himp_inf_himp_cancel (hba : b ≤ a) (hcb : c ≤ b) : (a ⇨ b) ⊓ (b ⇨ c) = a ⇨ c := (himp_triangle _ _ _).antisymm <| le_inf (himp_le_himp_left hcb) (himp_le_himp_right hba) theorem gc_inf_himp : GaloisConnection (a ⊓ ·) (a ⇨ ·) := fun _ _ ↦ Iff.symm le_himp_iff' -- See note [lower instance priority] instance (priority := 100) GeneralizedHeytingAlgebra.toDistribLattice : DistribLattice α := DistribLattice.ofInfSupLe fun a b c => by simp_rw [inf_comm a, ← le_himp_iff, sup_le_iff, le_himp_iff, ← sup_le_iff]; rfl instance OrderDual.instGeneralizedCoheytingAlgebra : GeneralizedCoheytingAlgebra αᵒᵈ where sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff instance Prod.instGeneralizedHeytingAlgebra [GeneralizedHeytingAlgebra β] : GeneralizedHeytingAlgebra (α × β) where le_himp_iff _ _ _ := and_congr le_himp_iff le_himp_iff instance Pi.instGeneralizedHeytingAlgebra {α : ι → Type*} [∀ i, GeneralizedHeytingAlgebra (α i)] : GeneralizedHeytingAlgebra (∀ i, α i) where le_himp_iff i := by simp [le_def] end GeneralizedHeytingAlgebra section GeneralizedCoheytingAlgebra variable [GeneralizedCoheytingAlgebra α] {a b c d : α} @[simp] theorem sdiff_le_iff : a \ b ≤ c ↔ a ≤ b ⊔ c := GeneralizedCoheytingAlgebra.sdiff_le_iff _ _ _ theorem sdiff_le_iff' : a \ b ≤ c ↔ a ≤ c ⊔ b := by rw [sdiff_le_iff, sup_comm] theorem sdiff_le_comm : a \ b ≤ c ↔ a \ c ≤ b := by rw [sdiff_le_iff, sdiff_le_iff'] theorem sdiff_le : a \ b ≤ a := sdiff_le_iff.2 le_sup_right theorem Disjoint.disjoint_sdiff_left (h : Disjoint a b) : Disjoint (a \ c) b := h.mono_left sdiff_le theorem Disjoint.disjoint_sdiff_right (h : Disjoint a b) : Disjoint a (b \ c) := h.mono_right sdiff_le theorem sdiff_le_iff_left : a \ b ≤ b ↔ a ≤ b := by rw [sdiff_le_iff, sup_idem] @[simp] theorem sdiff_self : a \ a = ⊥ := le_bot_iff.1 <| sdiff_le_iff.2 le_sup_left theorem le_sup_sdiff : a ≤ b ⊔ a \ b := sdiff_le_iff.1 le_rfl theorem le_sdiff_sup : a ≤ a \ b ⊔ b := by rw [sup_comm, ← sdiff_le_iff] theorem sup_sdiff_left : a ⊔ a \ b = a := sup_of_le_left sdiff_le theorem sup_sdiff_right : a \ b ⊔ a = a := sup_of_le_right sdiff_le theorem inf_sdiff_left : a \ b ⊓ a = a \ b := inf_of_le_left sdiff_le theorem inf_sdiff_right : a ⊓ a \ b = a \ b := inf_of_le_right sdiff_le @[simp] theorem sup_sdiff_self (a b : α) : a ⊔ b \ a = a ⊔ b := le_antisymm (sup_le_sup_left sdiff_le _) (sup_le le_sup_left le_sup_sdiff) @[simp] theorem sdiff_sup_self (a b : α) : b \ a ⊔ a = b ⊔ a := by rw [sup_comm, sup_sdiff_self, sup_comm] alias sup_sdiff_self_left := sdiff_sup_self alias sup_sdiff_self_right := sup_sdiff_self theorem sup_sdiff_eq_sup (h : c ≤ a) : a ⊔ b \ c = a ⊔ b := sup_congr_left (sdiff_le.trans le_sup_right) <| le_sup_sdiff.trans <| sup_le_sup_right h _ -- cf. `Set.union_diff_cancel'` theorem sup_sdiff_cancel' (hab : a ≤ b) (hbc : b ≤ c) : b ⊔ c \ a = c := by rw [sup_sdiff_eq_sup hab, sup_of_le_right hbc] theorem sup_sdiff_cancel_right (h : a ≤ b) : a ⊔ b \ a = b := sup_sdiff_cancel' le_rfl h theorem sdiff_sup_cancel (h : b ≤ a) : a \ b ⊔ b = a := by rw [sup_comm, sup_sdiff_cancel_right h] theorem sup_le_of_le_sdiff_left (h : b ≤ c \ a) (hac : a ≤ c) : a ⊔ b ≤ c := sup_le hac <| h.trans sdiff_le theorem sup_le_of_le_sdiff_right (h : a ≤ c \ b) (hbc : b ≤ c) : a ⊔ b ≤ c := sup_le (h.trans sdiff_le) hbc @[simp] theorem sdiff_eq_bot_iff : a \ b = ⊥ ↔ a ≤ b := by rw [← le_bot_iff, sdiff_le_iff, sup_bot_eq] @[simp] theorem sdiff_bot : a \ ⊥ = a := eq_of_forall_ge_iff fun b => by rw [sdiff_le_iff, bot_sup_eq] @[simp] theorem bot_sdiff : ⊥ \ a = ⊥ := sdiff_eq_bot_iff.2 bot_le theorem sdiff_sdiff_sdiff_le_sdiff : (a \ b) \ (a \ c) ≤ c \ b := by rw [sdiff_le_iff, sdiff_le_iff, sup_left_comm, sup_sdiff_self, sup_left_comm, sdiff_sup_self, sup_left_comm] exact le_sup_left @[simp] theorem le_sup_sdiff_sup_sdiff : a ≤ b ⊔ (a \ c ⊔ c \ b) := by simpa using @sdiff_sdiff_sdiff_le_sdiff theorem sdiff_sdiff (a b c : α) : (a \ b) \ c = a \ (b ⊔ c) := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_assoc] theorem sdiff_sdiff_left : (a \ b) \ c = a \ (b ⊔ c) := sdiff_sdiff _ _ _ theorem sdiff_right_comm (a b c : α) : (a \ b) \ c = (a \ c) \ b := by simp_rw [sdiff_sdiff, sup_comm] theorem sdiff_sdiff_comm : (a \ b) \ c = (a \ c) \ b := sdiff_right_comm _ _ _ @[simp] theorem sdiff_idem : (a \ b) \ b = a \ b := by rw [sdiff_sdiff_left, sup_idem] @[simp] theorem sdiff_sdiff_self : (a \ b) \ a = ⊥ := by rw [sdiff_sdiff_comm, sdiff_self, bot_sdiff] theorem sup_sdiff_distrib (a b c : α) : (a ⊔ b) \ c = a \ c ⊔ b \ c := eq_of_forall_ge_iff fun d => by simp_rw [sdiff_le_iff, sup_le_iff, sdiff_le_iff] theorem sdiff_inf_distrib (a b c : α) : a \ (b ⊓ c) = a \ b ⊔ a \ c := eq_of_forall_ge_iff fun d => by rw [sup_le_iff, sdiff_le_comm, le_inf_iff] simp_rw [sdiff_le_comm] theorem sup_sdiff : (a ⊔ b) \ c = a \ c ⊔ b \ c := sup_sdiff_distrib _ _ _ @[simp] theorem sup_sdiff_right_self : (a ⊔ b) \ b = a \ b := by rw [sup_sdiff, sdiff_self, sup_bot_eq] @[simp] theorem sup_sdiff_left_self : (a ⊔ b) \ a = b \ a := by rw [sup_comm, sup_sdiff_right_self] @[gcongr] theorem sdiff_le_sdiff_right (h : a ≤ b) : a \ c ≤ b \ c := sdiff_le_iff.2 <| h.trans <| le_sup_sdiff @[gcongr] theorem sdiff_le_sdiff_left (h : a ≤ b) : c \ b ≤ c \ a := sdiff_le_iff.2 <| le_sup_sdiff.trans <| sup_le_sup_right h _ @[gcongr] theorem sdiff_le_sdiff (hab : a ≤ b) (hcd : c ≤ d) : a \ d ≤ b \ c := (sdiff_le_sdiff_right hab).trans <| sdiff_le_sdiff_left hcd -- cf. `IsCompl.inf_sup` theorem sdiff_inf : a \ (b ⊓ c) = a \ b ⊔ a \ c := sdiff_inf_distrib _ _ _ @[simp] theorem sdiff_inf_self_left (a b : α) : a \ (a ⊓ b) = a \ b := by rw [sdiff_inf, sdiff_self, bot_sup_eq] @[simp] theorem sdiff_inf_self_right (a b : α) : b \ (a ⊓ b) = b \ a := by rw [sdiff_inf, sdiff_self, sup_bot_eq] theorem Disjoint.sdiff_eq_left (h : Disjoint a b) : a \ b = a := by conv_rhs => rw [← @sdiff_bot _ _ a] rw [← h.eq_bot, sdiff_inf_self_left] theorem Disjoint.sdiff_eq_right (h : Disjoint a b) : b \ a = b := h.symm.sdiff_eq_left theorem Disjoint.sup_sdiff_cancel_left (h : Disjoint a b) : (a ⊔ b) \ a = b := by rw [sup_sdiff, sdiff_self, bot_sup_eq, h.sdiff_eq_right] theorem Disjoint.sup_sdiff_cancel_right (h : Disjoint a b) : (a ⊔ b) \ b = a := by rw [sup_sdiff, sdiff_self, sup_bot_eq, h.sdiff_eq_left] /-- See `le_sdiff` for a stronger version in generalised Boolean algebras. -/ theorem Disjoint.le_sdiff_of_le_left (hac : Disjoint a c) (hab : a ≤ b) : a ≤ b \ c := hac.sdiff_eq_left.ge.trans <| sdiff_le_sdiff_right hab theorem sdiff_sdiff_le : a \ (a \ b) ≤ b := sdiff_le_iff.2 le_sdiff_sup @[simp] lemma sdiff_eq_sdiff_iff : a \ b = b \ a ↔ a = b := by simp [le_antisymm_iff] lemma sdiff_ne_sdiff_iff : a \ b ≠ b \ a ↔ a ≠ b := sdiff_eq_sdiff_iff.not theorem sdiff_triangle (a b c : α) : a \ c ≤ a \ b ⊔ b \ c := by rw [sdiff_le_iff, sup_left_comm, ← sdiff_le_iff] exact sdiff_sdiff_le.trans le_sup_sdiff theorem sdiff_sup_sdiff_cancel (hba : b ≤ a) (hcb : c ≤ b) : a \ b ⊔ b \ c = a \ c := (sdiff_triangle _ _ _).antisymm' <| sup_le (sdiff_le_sdiff_left hcb) (sdiff_le_sdiff_right hba) /-- a version of `sdiff_sup_sdiff_cancel` with more general hypotheses. -/ theorem sdiff_sup_sdiff_cancel' (hinf : a ⊓ c ≤ b) (hsup : b ≤ a ⊔ c) : a \ b ⊔ b \ c = a \ c := by refine (sdiff_triangle ..).antisymm' <| sup_le ?_ <| by simpa [sup_comm] rw [← sdiff_inf_self_left (b := c)] exact sdiff_le_sdiff_left hinf theorem sdiff_le_sdiff_of_sup_le_sup_left (h : c ⊔ a ≤ c ⊔ b) : a \ c ≤ b \ c := by rw [← sup_sdiff_left_self, ← @sup_sdiff_left_self _ _ _ b] exact sdiff_le_sdiff_right h theorem sdiff_le_sdiff_of_sup_le_sup_right (h : a ⊔ c ≤ b ⊔ c) : a \ c ≤ b \ c := by rw [← sup_sdiff_right_self, ← @sup_sdiff_right_self _ _ b] exact sdiff_le_sdiff_right h @[simp] theorem inf_sdiff_sup_left : a \ c ⊓ (a ⊔ b) = a \ c := inf_of_le_left <| sdiff_le.trans le_sup_left @[simp] theorem inf_sdiff_sup_right : a \ c ⊓ (b ⊔ a) = a \ c := inf_of_le_left <| sdiff_le.trans le_sup_right theorem gc_sdiff_sup : GaloisConnection (· \ a) (a ⊔ ·) := fun _ _ ↦ sdiff_le_iff -- See note [lower instance priority] instance (priority := 100) GeneralizedCoheytingAlgebra.toDistribLattice : DistribLattice α := { ‹GeneralizedCoheytingAlgebra α› with le_sup_inf := fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl } instance OrderDual.instGeneralizedHeytingAlgebra : GeneralizedHeytingAlgebra αᵒᵈ where himp := fun a b => toDual (ofDual b \ ofDual a) le_himp_iff := fun a b c => by rw [inf_comm]; exact sdiff_le_iff instance Prod.instGeneralizedCoheytingAlgebra [GeneralizedCoheytingAlgebra β] : GeneralizedCoheytingAlgebra (α × β) where sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff instance Pi.instGeneralizedCoheytingAlgebra {α : ι → Type*} [∀ i, GeneralizedCoheytingAlgebra (α i)] : GeneralizedCoheytingAlgebra (∀ i, α i) where sdiff_le_iff i := by simp [le_def] end GeneralizedCoheytingAlgebra section HeytingAlgebra variable [HeytingAlgebra α] {a b : α} @[simp] theorem himp_bot (a : α) : a ⇨ ⊥ = aᶜ := HeytingAlgebra.himp_bot _ @[simp] theorem bot_himp (a : α) : ⊥ ⇨ a = ⊤ := himp_eq_top_iff.2 bot_le theorem compl_sup_distrib (a b : α) : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := by simp_rw [← himp_bot, sup_himp_distrib] @[simp] theorem compl_sup : (a ⊔ b)ᶜ = aᶜ ⊓ bᶜ := compl_sup_distrib _ _ theorem compl_le_himp : aᶜ ≤ a ⇨ b := (himp_bot _).ge.trans <| himp_le_himp_left bot_le theorem compl_sup_le_himp : aᶜ ⊔ b ≤ a ⇨ b := sup_le compl_le_himp le_himp theorem sup_compl_le_himp : b ⊔ aᶜ ≤ a ⇨ b := sup_le le_himp compl_le_himp -- `p → ¬ p ↔ ¬ p` @[simp] theorem himp_compl (a : α) : a ⇨ aᶜ = aᶜ := by rw [← himp_bot, himp_himp, inf_idem] -- `p → ¬ q ↔ q → ¬ p` theorem himp_compl_comm (a b : α) : a ⇨ bᶜ = b ⇨ aᶜ := by simp_rw [← himp_bot, himp_left_comm] theorem le_compl_iff_disjoint_right : a ≤ bᶜ ↔ Disjoint a b := by rw [← himp_bot, le_himp_iff, disjoint_iff_inf_le] theorem le_compl_iff_disjoint_left : a ≤ bᶜ ↔ Disjoint b a := le_compl_iff_disjoint_right.trans disjoint_comm theorem le_compl_comm : a ≤ bᶜ ↔ b ≤ aᶜ := by rw [le_compl_iff_disjoint_right, le_compl_iff_disjoint_left] alias ⟨_, Disjoint.le_compl_right⟩ := le_compl_iff_disjoint_right alias ⟨_, Disjoint.le_compl_left⟩ := le_compl_iff_disjoint_left alias le_compl_iff_le_compl := le_compl_comm alias ⟨le_compl_of_le_compl, _⟩ := le_compl_comm theorem disjoint_compl_left : Disjoint aᶜ a := disjoint_iff_inf_le.mpr <| le_himp_iff.1 (himp_bot _).ge theorem disjoint_compl_right : Disjoint a aᶜ := disjoint_compl_left.symm theorem LE.le.disjoint_compl_left (h : b ≤ a) : Disjoint aᶜ b := _root_.disjoint_compl_left.mono_right h theorem LE.le.disjoint_compl_right (h : a ≤ b) : Disjoint a bᶜ := _root_.disjoint_compl_right.mono_left h theorem IsCompl.compl_eq (h : IsCompl a b) : aᶜ = b := h.1.le_compl_left.antisymm' <| Disjoint.le_of_codisjoint disjoint_compl_left h.2 theorem IsCompl.eq_compl (h : IsCompl a b) : a = bᶜ := h.1.le_compl_right.antisymm <| Disjoint.le_of_codisjoint disjoint_compl_left h.2.symm theorem compl_unique (h₀ : a ⊓ b = ⊥) (h₁ : a ⊔ b = ⊤) : aᶜ = b := (IsCompl.of_eq h₀ h₁).compl_eq @[simp] theorem inf_compl_self (a : α) : a ⊓ aᶜ = ⊥ := disjoint_compl_right.eq_bot @[simp] theorem compl_inf_self (a : α) : aᶜ ⊓ a = ⊥ := disjoint_compl_left.eq_bot theorem inf_compl_eq_bot : a ⊓ aᶜ = ⊥ := inf_compl_self _ theorem compl_inf_eq_bot : aᶜ ⊓ a = ⊥ := compl_inf_self _ @[simp] theorem compl_top : (⊤ : α)ᶜ = ⊥ := eq_of_forall_le_iff fun a => by rw [le_compl_iff_disjoint_right, disjoint_top, le_bot_iff] @[simp] theorem compl_bot : (⊥ : α)ᶜ = ⊤ := by rw [← himp_bot, himp_self] @[simp] theorem le_compl_self : a ≤ aᶜ ↔ a = ⊥ := by rw [le_compl_iff_disjoint_left, disjoint_self] @[simp] theorem ne_compl_self [Nontrivial α] : a ≠ aᶜ := by intro h cases le_compl_self.1 (le_of_eq h) simp at h @[simp] theorem compl_ne_self [Nontrivial α] : aᶜ ≠ a := ne_comm.1 ne_compl_self @[simp] theorem lt_compl_self [Nontrivial α] : a < aᶜ ↔ a = ⊥ := by rw [lt_iff_le_and_ne]; simp theorem le_compl_compl : a ≤ aᶜᶜ := disjoint_compl_right.le_compl_right theorem compl_anti : Antitone (compl : α → α) := fun _ _ h => le_compl_comm.1 <| h.trans le_compl_compl @[gcongr] theorem compl_le_compl (h : a ≤ b) : bᶜ ≤ aᶜ := compl_anti h @[simp] theorem compl_compl_compl (a : α) : aᶜᶜᶜ = aᶜ := (compl_anti le_compl_compl).antisymm le_compl_compl @[simp] theorem disjoint_compl_compl_left_iff : Disjoint aᶜᶜ b ↔ Disjoint a b := by simp_rw [← le_compl_iff_disjoint_left, compl_compl_compl] @[simp] theorem disjoint_compl_compl_right_iff : Disjoint a bᶜᶜ ↔ Disjoint a b := by simp_rw [← le_compl_iff_disjoint_right, compl_compl_compl] theorem compl_sup_compl_le : aᶜ ⊔ bᶜ ≤ (a ⊓ b)ᶜ := sup_le (compl_anti inf_le_left) <| compl_anti inf_le_right theorem compl_compl_inf_distrib (a b : α) : (a ⊓ b)ᶜᶜ = aᶜᶜ ⊓ bᶜᶜ := by refine ((compl_anti compl_sup_compl_le).trans (compl_sup_distrib _ _).le).antisymm ?_ rw [le_compl_iff_disjoint_right, disjoint_assoc, disjoint_compl_compl_left_iff, disjoint_left_comm, disjoint_compl_compl_left_iff, ← disjoint_assoc, inf_comm] exact disjoint_compl_right theorem compl_compl_himp_distrib (a b : α) : (a ⇨ b)ᶜᶜ = aᶜᶜ ⇨ bᶜᶜ := by apply le_antisymm · rw [le_himp_iff, ← compl_compl_inf_distrib] exact compl_anti (compl_anti himp_inf_le) · refine le_compl_comm.1 ((compl_anti compl_sup_le_himp).trans ?_) rw [compl_sup_distrib, le_compl_iff_disjoint_right, disjoint_right_comm, ← le_compl_iff_disjoint_right] exact inf_himp_le instance OrderDual.instCoheytingAlgebra : CoheytingAlgebra αᵒᵈ where hnot := toDual ∘ compl ∘ ofDual sdiff a b := toDual (ofDual b ⇨ ofDual a) sdiff_le_iff a b c := by rw [sup_comm]; exact le_himp_iff top_sdiff := @himp_bot α _ @[simp] theorem ofDual_hnot (a : αᵒᵈ) : ofDual (¬a) = (ofDual a)ᶜ := rfl @[simp] theorem toDual_compl (a : α) : toDual aᶜ = ¬toDual a := rfl instance Prod.instHeytingAlgebra [HeytingAlgebra β] : HeytingAlgebra (α × β) where himp_bot a := Prod.ext_iff.2 ⟨himp_bot a.1, himp_bot a.2⟩ instance Pi.instHeytingAlgebra {α : ι → Type*} [∀ i, HeytingAlgebra (α i)] : HeytingAlgebra (∀ i, α i) where himp_bot f := funext fun i ↦ himp_bot (f i) end HeytingAlgebra section CoheytingAlgebra variable [CoheytingAlgebra α] {a b : α} @[simp] theorem top_sdiff' (a : α) : ⊤ \ a = ¬a := CoheytingAlgebra.top_sdiff _ @[simp] theorem sdiff_top (a : α) : a \ ⊤ = ⊥ := sdiff_eq_bot_iff.2 le_top theorem hnot_inf_distrib (a b : α) : ¬(a ⊓ b) = ¬a ⊔ ¬b := by simp_rw [← top_sdiff', sdiff_inf_distrib] theorem sdiff_le_hnot : a \ b ≤ ¬b := (sdiff_le_sdiff_right le_top).trans_eq <| top_sdiff' _ theorem sdiff_le_inf_hnot : a \ b ≤ a ⊓ ¬b := le_inf sdiff_le sdiff_le_hnot -- See note [lower instance priority] instance (priority := 100) CoheytingAlgebra.toDistribLattice : DistribLattice α := { ‹CoheytingAlgebra α› with le_sup_inf := fun a b c => by simp_rw [← sdiff_le_iff, le_inf_iff, sdiff_le_iff, ← le_inf_iff]; rfl } @[simp] theorem hnot_sdiff (a : α) : ¬a \ a = ¬a := by rw [← top_sdiff', sdiff_sdiff, sup_idem] theorem hnot_sdiff_comm (a b : α) : ¬a \ b = ¬b \ a := by simp_rw [← top_sdiff', sdiff_right_comm] theorem hnot_le_iff_codisjoint_right : ¬a ≤ b ↔ Codisjoint a b := by rw [← top_sdiff', sdiff_le_iff, codisjoint_iff_le_sup] theorem hnot_le_iff_codisjoint_left : ¬a ≤ b ↔ Codisjoint b a := hnot_le_iff_codisjoint_right.trans codisjoint_comm theorem hnot_le_comm : ¬a ≤ b ↔ ¬b ≤ a := by rw [hnot_le_iff_codisjoint_right, hnot_le_iff_codisjoint_left] alias ⟨_, Codisjoint.hnot_le_right⟩ := hnot_le_iff_codisjoint_right alias ⟨_, Codisjoint.hnot_le_left⟩ := hnot_le_iff_codisjoint_left theorem codisjoint_hnot_right : Codisjoint a (¬a) := codisjoint_iff_le_sup.2 <| sdiff_le_iff.1 (top_sdiff' _).le theorem codisjoint_hnot_left : Codisjoint (¬a) a := codisjoint_hnot_right.symm theorem LE.le.codisjoint_hnot_left (h : a ≤ b) : Codisjoint (¬a) b := _root_.codisjoint_hnot_left.mono_right h theorem LE.le.codisjoint_hnot_right (h : b ≤ a) : Codisjoint a (¬b) := _root_.codisjoint_hnot_right.mono_left h theorem IsCompl.hnot_eq (h : IsCompl a b) : ¬a = b := h.2.hnot_le_right.antisymm <| Disjoint.le_of_codisjoint h.1.symm codisjoint_hnot_right theorem IsCompl.eq_hnot (h : IsCompl a b) : a = ¬b := h.2.hnot_le_left.antisymm' <| Disjoint.le_of_codisjoint h.1 codisjoint_hnot_right @[simp] theorem sup_hnot_self (a : α) : a ⊔ ¬a = ⊤ := Codisjoint.eq_top codisjoint_hnot_right @[simp] theorem hnot_sup_self (a : α) : ¬a ⊔ a = ⊤ := Codisjoint.eq_top codisjoint_hnot_left @[simp] theorem hnot_bot : ¬(⊥ : α) = ⊤ := eq_of_forall_ge_iff fun a => by rw [hnot_le_iff_codisjoint_left, codisjoint_bot, top_le_iff] @[simp] theorem hnot_top : ¬(⊤ : α) = ⊥ := by rw [← top_sdiff', sdiff_self] theorem hnot_hnot_le : ¬¬a ≤ a := codisjoint_hnot_right.hnot_le_left theorem hnot_anti : Antitone (hnot : α → α) := fun _ _ h => hnot_le_comm.1 <| hnot_hnot_le.trans h theorem hnot_le_hnot (h : a ≤ b) : ¬b ≤ ¬a := hnot_anti h @[simp] theorem hnot_hnot_hnot (a : α) : ¬¬¬a = ¬a := hnot_hnot_le.antisymm <| hnot_anti hnot_hnot_le @[simp] theorem codisjoint_hnot_hnot_left_iff : Codisjoint (¬¬a) b ↔ Codisjoint a b := by simp_rw [← hnot_le_iff_codisjoint_right, hnot_hnot_hnot] @[simp] theorem codisjoint_hnot_hnot_right_iff : Codisjoint a (¬¬b) ↔ Codisjoint a b := by simp_rw [← hnot_le_iff_codisjoint_left, hnot_hnot_hnot] theorem le_hnot_inf_hnot : ¬(a ⊔ b) ≤ ¬a ⊓ ¬b := le_inf (hnot_anti le_sup_left) <| hnot_anti le_sup_right theorem hnot_hnot_sup_distrib (a b : α) : ¬¬(a ⊔ b) = ¬¬a ⊔ ¬¬b := by refine ((hnot_inf_distrib _ _).ge.trans <| hnot_anti le_hnot_inf_hnot).antisymm' ?_ rw [hnot_le_iff_codisjoint_left, codisjoint_assoc, codisjoint_hnot_hnot_left_iff, codisjoint_left_comm, codisjoint_hnot_hnot_left_iff, ← codisjoint_assoc, sup_comm] exact codisjoint_hnot_right theorem hnot_hnot_sdiff_distrib (a b : α) : ¬¬(a \ b) = ¬¬a \ ¬¬b := by apply le_antisymm · refine hnot_le_comm.1 ((hnot_anti sdiff_le_inf_hnot).trans' ?_) rw [hnot_inf_distrib, hnot_le_iff_codisjoint_right, codisjoint_left_comm, ← hnot_le_iff_codisjoint_right] exact le_sdiff_sup · rw [sdiff_le_iff, ← hnot_hnot_sup_distrib] exact hnot_anti (hnot_anti le_sup_sdiff) instance OrderDual.instHeytingAlgebra : HeytingAlgebra αᵒᵈ where compl := toDual ∘ hnot ∘ ofDual himp a b := toDual (ofDual b \ ofDual a) le_himp_iff a b c := by rw [inf_comm]; exact sdiff_le_iff himp_bot := @top_sdiff' α _ @[simp] theorem ofDual_compl (a : αᵒᵈ) : ofDual aᶜ = ¬ofDual a := rfl @[simp] theorem ofDual_himp (a b : αᵒᵈ) : ofDual (a ⇨ b) = ofDual b \ ofDual a := rfl @[simp] theorem toDual_hnot (a : α) : toDual (¬a) = (toDual a)ᶜ := rfl @[simp] theorem toDual_sdiff (a b : α) : toDual (a \ b) = toDual b ⇨ toDual a := rfl instance Prod.instCoheytingAlgebra [CoheytingAlgebra β] : CoheytingAlgebra (α × β) where sdiff_le_iff _ _ _ := and_congr sdiff_le_iff sdiff_le_iff top_sdiff a := Prod.ext_iff.2 ⟨top_sdiff' a.1, top_sdiff' a.2⟩ instance Pi.instCoheytingAlgebra {α : ι → Type*} [∀ i, CoheytingAlgebra (α i)] : CoheytingAlgebra (∀ i, α i) where top_sdiff f := funext fun i ↦ top_sdiff' (f i) end CoheytingAlgebra section BiheytingAlgebra variable [BiheytingAlgebra α] {a : α} theorem compl_le_hnot : aᶜ ≤ ¬a := (disjoint_compl_left : Disjoint _ a).le_of_codisjoint codisjoint_hnot_right end BiheytingAlgebra /-- Propositions form a Heyting algebra with implication as Heyting implication and negation as complement. -/ instance Prop.instHeytingAlgebra : HeytingAlgebra Prop := { Prop.instDistribLattice, Prop.instBoundedOrder with himp := (· → ·), le_himp_iff := fun _ _ _ => and_imp.symm, himp_bot := fun _ => rfl } @[simp] theorem himp_iff_imp (p q : Prop) : p ⇨ q ↔ p → q := Iff.rfl @[simp] theorem compl_iff_not (p : Prop) : pᶜ ↔ ¬p := Iff.rfl -- See note [reducible non-instances] /-- A bounded linear order is a bi-Heyting algebra by setting * `a ⇨ b = ⊤` if `a ≤ b` and `a ⇨ b = b` otherwise. * `a \ b = ⊥` if `a ≤ b` and `a \ b = a` otherwise. -/ abbrev LinearOrder.toBiheytingAlgebra [LinearOrder α] [BoundedOrder α] : BiheytingAlgebra α := { LinearOrder.toLattice, ‹BoundedOrder α› with himp := fun a b => if a ≤ b then ⊤ else b, compl := fun a => if a = ⊥ then ⊤ else ⊥, le_himp_iff := fun a b c => by split_ifs with h · exact iff_of_true le_top (inf_le_of_right_le h) · rw [inf_le_iff, or_iff_left h], himp_bot := fun _ => if_congr le_bot_iff rfl rfl, sdiff := fun a b => if a ≤ b then ⊥ else a, hnot := fun a => if a = ⊤ then ⊥ else ⊤, sdiff_le_iff := fun a b c => by split_ifs with h · exact iff_of_true bot_le (le_sup_of_le_left h) · rw [le_sup_iff, or_iff_right h], top_sdiff := fun _ => if_congr top_le_iff rfl rfl } instance OrderDual.instBiheytingAlgebra [BiheytingAlgebra α] : BiheytingAlgebra αᵒᵈ where __ := instHeytingAlgebra __ := instCoheytingAlgebra instance Prod.instBiheytingAlgebra [BiheytingAlgebra α] [BiheytingAlgebra β] : BiheytingAlgebra (α × β) where __ := instHeytingAlgebra __ := instCoheytingAlgebra instance Pi.instBiheytingAlgebra {α : ι → Type*} [∀ i, BiheytingAlgebra (α i)] : BiheytingAlgebra (∀ i, α i) where __ := instHeytingAlgebra __ := instCoheytingAlgebra section lift -- See note [reducible non-instances] /-- Pullback a `GeneralizedHeytingAlgebra` along an injection. -/ protected abbrev Function.Injective.generalizedHeytingAlgebra [Max α] [Min α] [Top α] [HImp α] [GeneralizedHeytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_top : f ⊤ = ⊤) (map_himp : ∀ a b, f (a ⇨ b) = f a ⇨ f b) : GeneralizedHeytingAlgebra α := { __ := hf.lattice f map_sup map_inf __ := ‹Top α› __ := ‹HImp α› le_top := fun a => by change f _ ≤ _ rw [map_top] exact le_top, le_himp_iff := fun a b c => by change f _ ≤ _ ↔ f _ ≤ _ rw [map_himp, map_inf, le_himp_iff] } -- See note [reducible non-instances] /-- Pullback a `GeneralizedCoheytingAlgebra` along an injection. -/ protected abbrev Function.Injective.generalizedCoheytingAlgebra [Max α] [Min α] [Bot α] [SDiff α] [GeneralizedCoheytingAlgebra β] (f : α → β) (hf : Injective f) (map_sup : ∀ a b, f (a ⊔ b) = f a ⊔ f b) (map_inf : ∀ a b, f (a ⊓ b) = f a ⊓ f b) (map_bot : f ⊥ = ⊥) (map_sdiff : ∀ a b, f (a \ b) = f a \ f b) : GeneralizedCoheytingAlgebra α := { __ := hf.lattice f map_sup map_inf __ := ‹Bot α› __ := ‹SDiff α› bot_le := fun a => by change f _ ≤ _ rw [map_bot] exact bot_le, sdiff_le_iff := fun a b c => by change f _ ≤ _ ↔ f _ ≤ _ rw [map_sdiff, map_sup, sdiff_le_iff] }
-- See note [reducible non-instances]
Mathlib/Order/Heyting/Basic.lean
1,019
1,020
/- 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.Geometry.Euclidean.Altitude import Mathlib.Geometry.Euclidean.Circumcenter /-! # Monge point and orthocenter This file defines the orthocenter of a triangle, via its n-dimensional generalization, the Monge point of a simplex. ## Main definitions * `mongePoint` is the Monge point of a simplex, defined in terms of its position on the Euler line and then shown to be the point of concurrence of the Monge planes. * `mongePlane` is a Monge plane of an (n+2)-simplex, which is the (n+1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an n-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). * `orthocenter` is defined, for the case of a triangle, to be the same as its Monge point, then shown to be the point of concurrence of the altitudes. * `OrthocentricSystem` is a predicate on sets of points that says whether they are four points, one of which is the orthocenter of the other three (in which case various other properties hold, including that each is the orthocenter of the other three). ## References * <https://en.wikipedia.org/wiki/Monge_point> * <https://en.wikipedia.org/wiki/Orthocentric_system> * Małgorzata Buba-Brzozowa, [The Monge Point and the 3(n+1) Point Sphere of an n-Simplex](https://pdfs.semanticscholar.org/6f8b/0f623459c76dac2e49255737f8f0f4725d16.pdf) -/ noncomputable section open scoped RealInnerProductSpace namespace Affine namespace Simplex open Finset AffineSubspace EuclideanGeometry PointsWithCircumcenterIndex variable {V : Type*} {P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] /-- The Monge point of a simplex (in 2 or more dimensions) is a generalization of the orthocenter of a triangle. It is defined to be the intersection of the Monge planes, where a Monge plane is the (n-1)-dimensional affine subspace of the subspace spanned by the simplex that passes through the centroid of an (n-2)-dimensional face and is orthogonal to the opposite edge (in 2 dimensions, this is the same as an altitude). The circumcenter O, centroid G and Monge point M are collinear in that order on the Euler line, with OG : GM = (n-1): 2. Here, we use that ratio to define the Monge point (so resulting in a point that equals the centroid in 0 or 1 dimensions), and then show in subsequent lemmas that the point so defined lies in the Monge planes and is their unique point of intersection. -/ def mongePoint {n : ℕ} (s : Simplex ℝ P n) : P := (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter /-- The position of the Monge point in relation to the circumcenter and centroid. -/ theorem mongePoint_eq_smul_vsub_vadd_circumcenter {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint = (((n + 1 : ℕ) : ℝ) / ((n - 1 : ℕ) : ℝ)) • ((univ : Finset (Fin (n + 1))).centroid ℝ s.points -ᵥ s.circumcenter) +ᵥ s.circumcenter := rfl /-- The Monge point lies in the affine span. -/ theorem mongePoint_mem_affineSpan {n : ℕ} (s : Simplex ℝ P n) : s.mongePoint ∈ affineSpan ℝ (Set.range s.points) := smul_vsub_vadd_mem _ _ (centroid_mem_affineSpan_of_card_eq_add_one ℝ _ (card_fin (n + 1))) s.circumcenter_mem_affineSpan s.circumcenter_mem_affineSpan /-- Two simplices with the same points have the same Monge point. -/ theorem mongePoint_eq_of_range_eq {n : ℕ} {s₁ s₂ : Simplex ℝ P n} (h : Set.range s₁.points = Set.range s₂.points) : s₁.mongePoint = s₂.mongePoint := by simp_rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_of_range_eq h, circumcenter_eq_of_range_eq h] /-- The weights for the Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ def mongePointWeightsWithCircumcenter (n : ℕ) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex _ => ((n + 1 : ℕ) : ℝ)⁻¹ | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) /-- `mongePointWeightsWithCircumcenter` sums to 1. -/ @[simp] theorem sum_mongePointWeightsWithCircumcenter (n : ℕ) : ∑ i, mongePointWeightsWithCircumcenter n i = 1 := by simp_rw [sum_pointsWithCircumcenter, mongePointWeightsWithCircumcenter, sum_const, card_fin, nsmul_eq_mul] field_simp ring /-- The Monge point of an (n+2)-simplex, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_eq_affineCombination_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) : s.mongePoint = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).affineCombination ℝ s.pointsWithCircumcenter (mongePointWeightsWithCircumcenter n) := by rw [mongePoint_eq_smul_vsub_vadd_circumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, circumcenter_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, ← LinearMap.map_smul, weightedVSub_vadd_affineCombination] congr with i rw [Pi.add_apply, Pi.smul_apply, smul_eq_mul, Pi.sub_apply] -- Porting note: replaced -- have hn1 : (n + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ have hn1 : (n + 1 : ℝ) ≠ 0 := n.cast_add_one_ne_zero cases i <;> simp_rw [centroidWeightsWithCircumcenter, circumcenterWeightsWithCircumcenter, mongePointWeightsWithCircumcenter] <;> rw [add_tsub_assoc_of_le (by decide : 1 ≤ 2), (by decide : 2 - 1 = 1)] · rw [if_pos (mem_univ _), sub_zero, add_zero, card_fin] -- Porting note: replaced -- have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := mod_cast Nat.succ_ne_zero _ have hn3 : (n + 2 + 1 : ℝ) ≠ 0 := by norm_cast field_simp [hn1, hn3, mul_comm] · field_simp [hn1] ring /-- The weights for the Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. This definition is only valid when `i₁ ≠ i₂`. -/ def mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} (i₁ i₂ : Fin (n + 3)) : PointsWithCircumcenterIndex (n + 2) → ℝ | pointIndex i => if i = i₁ ∨ i = i₂ then ((n + 1 : ℕ) : ℝ)⁻¹ else 0 | circumcenterIndex => -2 / ((n + 1 : ℕ) : ℝ) /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` is the result of subtracting `centroidWeightsWithCircumcenter` from `mongePointWeightsWithCircumcenter`. -/ theorem mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ = mongePointWeightsWithCircumcenter n - centroidWeightsWithCircumcenter {i₁, i₂}ᶜ := by ext i obtain i | i := i · rw [Pi.sub_apply, mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] have hu : #{i₁, i₂}ᶜ = n + 1 := by simp [card_compl, Fintype.card_fin, h] rw [hu] by_cases hi : i = i₁ ∨ i = i₂ <;> simp [compl_eq_univ_sdiff, hi] · simp [mongePointWeightsWithCircumcenter, centroidWeightsWithCircumcenter, mongePointVSubFaceCentroidWeightsWithCircumcenter] /-- `mongePointVSubFaceCentroidWeightsWithCircumcenter` sums to 0. -/ @[simp] theorem sum_mongePointVSubFaceCentroidWeightsWithCircumcenter {n : ℕ} {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : ∑ i, mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂ i = 0 := by rw [mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] simp_rw [Pi.sub_apply, sum_sub_distrib, sum_mongePointWeightsWithCircumcenter] rw [sum_centroidWeightsWithCircumcenter, sub_self] simp [← card_pos, card_compl, h] /-- The Monge point of an (n+2)-simplex, minus the centroid of an n-dimensional face, in terms of `pointsWithCircumcenter`. -/ theorem mongePoint_vsub_face_centroid_eq_weightedVSub_of_pointsWithCircumcenter {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} (h : i₁ ≠ i₂) : s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points = (univ : Finset (PointsWithCircumcenterIndex (n + 2))).weightedVSub s.pointsWithCircumcenter (mongePointVSubFaceCentroidWeightsWithCircumcenter i₁ i₂) := by simp_rw [mongePoint_eq_affineCombination_of_pointsWithCircumcenter, centroid_eq_affineCombination_of_pointsWithCircumcenter, affineCombination_vsub, mongePointVSubFaceCentroidWeightsWithCircumcenter_eq_sub h] /-- The Monge point of an (n+2)-simplex, minus the centroid of an
n-dimensional face, is orthogonal to the difference of the two vertices not in that face. -/ theorem inner_mongePoint_vsub_face_centroid_vsub {n : ℕ} (s : Simplex ℝ P (n + 2)) {i₁ i₂ : Fin (n + 3)} : ⟪s.mongePoint -ᵥ ({i₁, i₂}ᶜ : Finset (Fin (n + 3))).centroid ℝ s.points, s.points i₁ -ᵥ s.points i₂⟫ =
Mathlib/Geometry/Euclidean/MongePoint.lean
187
192
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.MeasureTheory.Function.LpSeminorm.Basic /-! # Lp seminorm with respect to trimmed measure In this file we prove basic properties of the Lp-seminorm of a function with respect to the restriction of a measure to a sub-σ-algebra. -/ namespace MeasureTheory open Filter open scoped ENNReal variable {α E : Type*} {m m0 : MeasurableSpace α} {p : ℝ≥0∞} {q : ℝ} {μ : Measure α} [NormedAddCommGroup E] theorem eLpNorm'_trim (hm : m ≤ m0) {f : α → E} (hf : StronglyMeasurable[m] f) : eLpNorm' f q (μ.trim hm) = eLpNorm' f q μ := by simp_rw [eLpNorm'] congr 1 refine lintegral_trim hm ?_ refine @Measurable.pow_const _ _ _ _ _ _ _ m _ (@Measurable.coe_nnreal_ennreal _ m _ ?_) q apply @StronglyMeasurable.measurable exact @StronglyMeasurable.nnnorm α m _ _ _ hf theorem limsup_trim (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : Measurable[m] f) : limsup f (ae (μ.trim hm)) = limsup f (ae μ) := by simp_rw [limsup_eq]
suffices h_set_eq : { a : ℝ≥0∞ | ∀ᵐ n ∂μ.trim hm, f n ≤ a } = { a : ℝ≥0∞ | ∀ᵐ n ∂μ, f n ≤ a } by rw [h_set_eq] ext1 a suffices h_meas_eq : μ { x | ¬f x ≤ a } = μ.trim hm { x | ¬f x ≤ a } by simp_rw [Set.mem_setOf_eq, ae_iff, h_meas_eq] refine (trim_measurableSet_eq hm ?_).symm refine @MeasurableSet.compl _ _ m (@measurableSet_le ℝ≥0∞ _ _ _ _ m _ _ _ _ _ hf ?_) exact @measurable_const _ _ _ m _ theorem essSup_trim (hm : m ≤ m0) {f : α → ℝ≥0∞} (hf : Measurable[m] f) : essSup f (μ.trim hm) = essSup f μ := by
Mathlib/MeasureTheory/Function/LpSeminorm/Trim.lean
35
45
/- 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, Julian Kuelshammer -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.Group.Pointwise.Set.Finite import Mathlib.Algebra.Group.Subgroup.Finite import Mathlib.Algebra.Module.NatInt import Mathlib.Algebra.Order.Group.Action import Mathlib.Algebra.Order.Ring.Abs import Mathlib.Data.Int.ModEq import Mathlib.Dynamics.PeriodicPts.Lemmas import Mathlib.GroupTheory.Index import Mathlib.NumberTheory.Divisors import Mathlib.Order.Interval.Set.Infinite /-! # Order of an element This file defines the order of an element of a finite group. For a finite group `G` the order of `x ∈ G` is the minimal `n ≥ 1` such that `x ^ n = 1`. ## Main definitions * `IsOfFinOrder` is a predicate on an element `x` of a monoid `G` saying that `x` is of finite order. * `IsOfFinAddOrder` is the additive analogue of `IsOfFinOrder`. * `orderOf x` defines the order of an element `x` of a monoid `G`, by convention its value is `0` if `x` has infinite order. * `addOrderOf` is the additive analogue of `orderOf`. ## Tags order of an element -/ assert_not_exists Field open Function Fintype Nat Pointwise Subgroup Submonoid open scoped Finset variable {G H A α β : Type*} section Monoid variable [Monoid G] {a b x y : G} {n m : ℕ} section IsOfFinOrder -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed @[to_additive] theorem isPeriodicPt_mul_iff_pow_eq_one (x : G) : IsPeriodicPt (x * ·) n 1 ↔ x ^ n = 1 := by rw [IsPeriodicPt, IsFixedPt, mul_left_iterate]; beta_reduce; rw [mul_one] /-- `IsOfFinOrder` is a predicate on an element `x` of a monoid to be of finite order, i.e. there exists `n ≥ 1` such that `x ^ n = 1`. -/ @[to_additive "`IsOfFinAddOrder` is a predicate on an element `a` of an additive monoid to be of finite order, i.e. there exists `n ≥ 1` such that `n • a = 0`."] def IsOfFinOrder (x : G) : Prop := (1 : G) ∈ periodicPts (x * ·) theorem isOfFinAddOrder_ofMul_iff : IsOfFinAddOrder (Additive.ofMul x) ↔ IsOfFinOrder x := Iff.rfl theorem isOfFinOrder_ofAdd_iff {α : Type*} [AddMonoid α] {x : α} : IsOfFinOrder (Multiplicative.ofAdd x) ↔ IsOfFinAddOrder x := Iff.rfl @[to_additive] theorem isOfFinOrder_iff_pow_eq_one : IsOfFinOrder x ↔ ∃ n, 0 < n ∧ x ^ n = 1 := by simp [IsOfFinOrder, mem_periodicPts, isPeriodicPt_mul_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.exists_pow_eq_one, _⟩ := isOfFinOrder_iff_pow_eq_one @[to_additive] lemma isOfFinOrder_iff_zpow_eq_one {G} [DivisionMonoid G] {x : G} : IsOfFinOrder x ↔ ∃ (n : ℤ), n ≠ 0 ∧ x ^ n = 1 := by rw [isOfFinOrder_iff_pow_eq_one] refine ⟨fun ⟨n, hn, hn'⟩ ↦ ⟨n, Int.natCast_ne_zero_iff_pos.mpr hn, zpow_natCast x n ▸ hn'⟩, fun ⟨n, hn, hn'⟩ ↦ ⟨n.natAbs, Int.natAbs_pos.mpr hn, ?_⟩⟩ rcases (Int.natAbs_eq_iff (a := n)).mp rfl with h | h · rwa [h, zpow_natCast] at hn' · rwa [h, zpow_neg, inv_eq_one, zpow_natCast] at hn' /-- See also `injective_pow_iff_not_isOfFinOrder`. -/ @[to_additive "See also `injective_nsmul_iff_not_isOfFinAddOrder`."] theorem not_isOfFinOrder_of_injective_pow {x : G} (h : Injective fun n : ℕ => x ^ n) : ¬IsOfFinOrder x := by simp_rw [isOfFinOrder_iff_pow_eq_one, not_exists, not_and] intro n hn_pos hnx rw [← pow_zero x] at hnx rw [h hnx] at hn_pos exact irrefl 0 hn_pos /-- 1 is of finite order in any monoid. -/ @[to_additive (attr := simp) "0 is of finite order in any additive monoid."] theorem IsOfFinOrder.one : IsOfFinOrder (1 : G) := isOfFinOrder_iff_pow_eq_one.mpr ⟨1, Nat.one_pos, one_pow 1⟩ @[to_additive] lemma IsOfFinOrder.pow {n : ℕ} : IsOfFinOrder a → IsOfFinOrder (a ^ n) := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨m, hm, ha⟩ exact ⟨m, hm, by simp [pow_right_comm _ n, ha]⟩ @[to_additive] lemma IsOfFinOrder.of_pow {n : ℕ} (h : IsOfFinOrder (a ^ n)) (hn : n ≠ 0) : IsOfFinOrder a := by rw [isOfFinOrder_iff_pow_eq_one] at * rcases h with ⟨m, hm, ha⟩ exact ⟨n * m, mul_pos hn.bot_lt hm, by rwa [pow_mul]⟩ @[to_additive (attr := simp)] lemma isOfFinOrder_pow {n : ℕ} : IsOfFinOrder (a ^ n) ↔ IsOfFinOrder a ∨ n = 0 := by rcases Decidable.eq_or_ne n 0 with rfl | hn · simp · exact ⟨fun h ↦ .inl <| h.of_pow hn, fun h ↦ (h.resolve_right hn).pow⟩ /-- Elements of finite order are of finite order in submonoids. -/ @[to_additive "Elements of finite order are of finite order in submonoids."] theorem Submonoid.isOfFinOrder_coe {H : Submonoid G} {x : H} : IsOfFinOrder (x : G) ↔ IsOfFinOrder x := by rw [isOfFinOrder_iff_pow_eq_one, isOfFinOrder_iff_pow_eq_one] norm_cast theorem IsConj.isOfFinOrder (h : IsConj x y) : IsOfFinOrder x → IsOfFinOrder y := by simp_rw [isOfFinOrder_iff_pow_eq_one] rintro ⟨n, n_gt_0, eq'⟩ exact ⟨n, n_gt_0, by rw [← isConj_one_right, ← eq']; exact h.pow n⟩ /-- The image of an element of finite order has finite order. -/ @[to_additive "The image of an element of finite additive order has finite additive order."] theorem MonoidHom.isOfFinOrder [Monoid H] (f : G →* H) {x : G} (h : IsOfFinOrder x) : IsOfFinOrder <| f x := isOfFinOrder_iff_pow_eq_one.mpr <| by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact ⟨n, npos, by rw [← f.map_pow, hn, f.map_one]⟩ /-- If a direct product has finite order then so does each component. -/ @[to_additive "If a direct product has finite additive order then so does each component."] theorem IsOfFinOrder.apply {η : Type*} {Gs : η → Type*} [∀ i, Monoid (Gs i)] {x : ∀ i, Gs i} (h : IsOfFinOrder x) : ∀ i, IsOfFinOrder (x i) := by obtain ⟨n, npos, hn⟩ := h.exists_pow_eq_one exact fun _ => isOfFinOrder_iff_pow_eq_one.mpr ⟨n, npos, (congr_fun hn.symm _).symm⟩ /-- The submonoid generated by an element is a group if that element has finite order. -/ @[to_additive "The additive submonoid generated by an element is an additive group if that element has finite order."] noncomputable abbrev IsOfFinOrder.groupPowers (hx : IsOfFinOrder x) : Group (Submonoid.powers x) := by obtain ⟨hpos, hx⟩ := hx.exists_pow_eq_one.choose_spec exact Submonoid.groupPowers hpos hx end IsOfFinOrder /-- `orderOf x` is the order of the element `x`, i.e. the `n ≥ 1`, s.t. `x ^ n = 1` if it exists. Otherwise, i.e. if `x` is of infinite order, then `orderOf x` is `0` by convention. -/ @[to_additive "`addOrderOf a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `n • a = 0` if it exists. Otherwise, i.e. if `a` is of infinite order, then `addOrderOf a` is `0` by convention."] noncomputable def orderOf (x : G) : ℕ := minimalPeriod (x * ·) 1 @[simp] theorem addOrderOf_ofMul_eq_orderOf (x : G) : addOrderOf (Additive.ofMul x) = orderOf x := rfl @[simp] lemma orderOf_ofAdd_eq_addOrderOf {α : Type*} [AddMonoid α] (a : α) : orderOf (Multiplicative.ofAdd a) = addOrderOf a := rfl @[to_additive] protected lemma IsOfFinOrder.orderOf_pos (h : IsOfFinOrder x) : 0 < orderOf x := minimalPeriod_pos_of_mem_periodicPts h @[to_additive addOrderOf_nsmul_eq_zero] theorem pow_orderOf_eq_one (x : G) : x ^ orderOf x = 1 := by convert Eq.trans _ (isPeriodicPt_minimalPeriod (x * ·) 1) -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed in the middle of the rewrite rw [orderOf, mul_left_iterate]; beta_reduce; rw [mul_one] @[to_additive] theorem orderOf_eq_zero (h : ¬IsOfFinOrder x) : orderOf x = 0 := by rwa [orderOf, minimalPeriod, dif_neg] @[to_additive] theorem orderOf_eq_zero_iff : orderOf x = 0 ↔ ¬IsOfFinOrder x := ⟨fun h H ↦ H.orderOf_pos.ne' h, orderOf_eq_zero⟩ @[to_additive] theorem orderOf_eq_zero_iff' : orderOf x = 0 ↔ ∀ n : ℕ, 0 < n → x ^ n ≠ 1 := by simp_rw [orderOf_eq_zero_iff, isOfFinOrder_iff_pow_eq_one, not_exists, not_and] @[to_additive] theorem orderOf_eq_iff {n} (h : 0 < n) : orderOf x = n ↔ x ^ n = 1 ∧ ∀ m, m < n → 0 < m → x ^ m ≠ 1 := by simp_rw [Ne, ← isPeriodicPt_mul_iff_pow_eq_one, orderOf, minimalPeriod] split_ifs with h1 · classical rw [find_eq_iff] simp only [h, true_and] push_neg rfl · rw [iff_false_left h.ne] rintro ⟨h', -⟩ exact h1 ⟨n, h, h'⟩ /-- A group element has finite order iff its order is positive. -/ @[to_additive "A group element has finite additive order iff its order is positive."] theorem orderOf_pos_iff : 0 < orderOf x ↔ IsOfFinOrder x := by rw [iff_not_comm.mp orderOf_eq_zero_iff, pos_iff_ne_zero] @[to_additive] theorem IsOfFinOrder.mono [Monoid β] {y : β} (hx : IsOfFinOrder x) (h : orderOf y ∣ orderOf x) : IsOfFinOrder y := by rw [← orderOf_pos_iff] at hx ⊢; exact Nat.pos_of_dvd_of_pos h hx @[to_additive] theorem pow_ne_one_of_lt_orderOf (n0 : n ≠ 0) (h : n < orderOf x) : x ^ n ≠ 1 := fun j => not_isPeriodicPt_of_pos_of_lt_minimalPeriod n0 h ((isPeriodicPt_mul_iff_pow_eq_one x).mpr j) @[to_additive] theorem orderOf_le_of_pow_eq_one (hn : 0 < n) (h : x ^ n = 1) : orderOf x ≤ n := IsPeriodicPt.minimalPeriod_le hn (by rwa [isPeriodicPt_mul_iff_pow_eq_one]) @[to_additive (attr := simp)] theorem orderOf_one : orderOf (1 : G) = 1 := by rw [orderOf, ← minimalPeriod_id (x := (1 : G)), ← one_mul_eq_id] @[to_additive (attr := simp) AddMonoid.addOrderOf_eq_one_iff] theorem orderOf_eq_one_iff : orderOf x = 1 ↔ x = 1 := by rw [orderOf, minimalPeriod_eq_one_iff_isFixedPt, IsFixedPt, mul_one] @[to_additive (attr := simp) mod_addOrderOf_nsmul] lemma pow_mod_orderOf (x : G) (n : ℕ) : x ^ (n % orderOf x) = x ^ n := calc x ^ (n % orderOf x) = x ^ (n % orderOf x + orderOf x * (n / orderOf x)) := by simp [pow_add, pow_mul, pow_orderOf_eq_one] _ = x ^ n := by rw [Nat.mod_add_div] @[to_additive] theorem orderOf_dvd_of_pow_eq_one (h : x ^ n = 1) : orderOf x ∣ n := IsPeriodicPt.minimalPeriod_dvd ((isPeriodicPt_mul_iff_pow_eq_one _).mpr h) @[to_additive] theorem orderOf_dvd_iff_pow_eq_one {n : ℕ} : orderOf x ∣ n ↔ x ^ n = 1 := ⟨fun h => by rw [← pow_mod_orderOf, Nat.mod_eq_zero_of_dvd h, _root_.pow_zero], orderOf_dvd_of_pow_eq_one⟩ @[to_additive addOrderOf_smul_dvd] theorem orderOf_pow_dvd (n : ℕ) : orderOf (x ^ n) ∣ orderOf x := by rw [orderOf_dvd_iff_pow_eq_one, pow_right_comm, pow_orderOf_eq_one, one_pow] @[to_additive] lemma pow_injOn_Iio_orderOf : (Set.Iio <| orderOf x).InjOn (x ^ ·) := by simpa only [mul_left_iterate, mul_one] using iterate_injOn_Iio_minimalPeriod (f := (x * ·)) (x := 1) @[to_additive] protected lemma IsOfFinOrder.mem_powers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ Submonoid.powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' hx.orderOf_pos <| pow_mod_orderOf _ @[to_additive] protected lemma IsOfFinOrder.powers_eq_image_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : (Submonoid.powers x : Set G) = (Finset.range (orderOf x)).image (x ^ ·) := Set.ext fun _ ↦ hx.mem_powers_iff_mem_range_orderOf @[to_additive] theorem pow_eq_one_iff_modEq : x ^ n = 1 ↔ n ≡ 0 [MOD orderOf x] := by rw [modEq_zero_iff_dvd, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_map_dvd {H : Type*} [Monoid H] (ψ : G →* H) (x : G) : orderOf (ψ x) ∣ orderOf x := by apply orderOf_dvd_of_pow_eq_one rw [← map_pow, pow_orderOf_eq_one] apply map_one @[to_additive] theorem exists_pow_eq_self_of_coprime (h : n.Coprime (orderOf x)) : ∃ m : ℕ, (x ^ n) ^ m = x := by by_cases h0 : orderOf x = 0 · rw [h0, coprime_zero_right] at h exact ⟨1, by rw [h, pow_one, pow_one]⟩ by_cases h1 : orderOf x = 1 · exact ⟨0, by rw [orderOf_eq_one_iff.mp h1, one_pow, one_pow]⟩ obtain ⟨m, h⟩ := exists_mul_emod_eq_one_of_coprime h (one_lt_iff_ne_zero_and_ne_one.mpr ⟨h0, h1⟩) exact ⟨m, by rw [← pow_mul, ← pow_mod_orderOf, h, pow_one]⟩ /-- If `x^n = 1`, but `x^(n/p) ≠ 1` for all prime factors `p` of `n`, then `x` has order `n` in `G`. -/ @[to_additive addOrderOf_eq_of_nsmul_and_div_prime_nsmul "If `n * x = 0`, but `n/p * x ≠ 0` for all prime factors `p` of `n`, then `x` has order `n` in `G`."] theorem orderOf_eq_of_pow_and_pow_div_prime (hn : 0 < n) (hx : x ^ n = 1) (hd : ∀ p : ℕ, p.Prime → p ∣ n → x ^ (n / p) ≠ 1) : orderOf x = n := by -- Let `a` be `n/(orderOf x)`, and show `a = 1` obtain ⟨a, ha⟩ := exists_eq_mul_right_of_dvd (orderOf_dvd_of_pow_eq_one hx) suffices a = 1 by simp [this, ha] -- Assume `a` is not one... by_contra h have a_min_fac_dvd_p_sub_one : a.minFac ∣ n := by obtain ⟨b, hb⟩ : ∃ b : ℕ, a = b * a.minFac := exists_eq_mul_left_of_dvd a.minFac_dvd rw [hb, ← mul_assoc] at ha exact Dvd.intro_left (orderOf x * b) ha.symm -- Use the minimum prime factor of `a` as `p`. refine hd a.minFac (Nat.minFac_prime h) a_min_fac_dvd_p_sub_one ?_ rw [← orderOf_dvd_iff_pow_eq_one, Nat.dvd_div_iff_mul_dvd a_min_fac_dvd_p_sub_one, ha, mul_comm, Nat.mul_dvd_mul_iff_left (IsOfFinOrder.orderOf_pos _)] · exact Nat.minFac_dvd a · rw [isOfFinOrder_iff_pow_eq_one] exact Exists.intro n (id ⟨hn, hx⟩) @[to_additive] theorem orderOf_eq_orderOf_iff {H : Type*} [Monoid H] {y : H} : orderOf x = orderOf y ↔ ∀ n : ℕ, x ^ n = 1 ↔ y ^ n = 1 := by simp_rw [← isPeriodicPt_mul_iff_pow_eq_one, ← minimalPeriod_eq_minimalPeriod_iff, orderOf] /-- An injective homomorphism of monoids preserves orders of elements. -/ @[to_additive "An injective homomorphism of additive monoids preserves orders of elements."] theorem orderOf_injective {H : Type*} [Monoid H] (f : G →* H) (hf : Function.Injective f) (x : G) : orderOf (f x) = orderOf x := by simp_rw [orderOf_eq_orderOf_iff, ← f.map_pow, ← f.map_one, hf.eq_iff, forall_const] /-- A multiplicative equivalence preserves orders of elements. -/ @[to_additive (attr := simp) "An additive equivalence preserves orders of elements."] lemma MulEquiv.orderOf_eq {H : Type*} [Monoid H] (e : G ≃* H) (x : G) : orderOf (e x) = orderOf x := orderOf_injective e.toMonoidHom e.injective x @[to_additive] theorem Function.Injective.isOfFinOrder_iff [Monoid H] {f : G →* H} (hf : Injective f) : IsOfFinOrder (f x) ↔ IsOfFinOrder x := by rw [← orderOf_pos_iff, orderOf_injective f hf x, ← orderOf_pos_iff] @[to_additive (attr := norm_cast, simp)] theorem orderOf_submonoid {H : Submonoid G} (y : H) : orderOf (y : G) = orderOf y := orderOf_injective H.subtype Subtype.coe_injective y @[to_additive] theorem orderOf_units {y : Gˣ} : orderOf (y : G) = orderOf y := orderOf_injective (Units.coeHom G) Units.ext y /-- If the order of `x` is finite, then `x` is a unit with inverse `x ^ (orderOf x - 1)`. -/ @[to_additive (attr := simps) "If the additive order of `x` is finite, then `x` is an additive unit with inverse `(addOrderOf x - 1) • x`. "] noncomputable def IsOfFinOrder.unit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : Mˣ := ⟨x, x ^ (orderOf x - 1), by rw [← _root_.pow_succ', tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one], by rw [← _root_.pow_succ, tsub_add_cancel_of_le (by exact hx.orderOf_pos), pow_orderOf_eq_one]⟩ @[to_additive] lemma IsOfFinOrder.isUnit {M} [Monoid M] {x : M} (hx : IsOfFinOrder x) : IsUnit x := ⟨hx.unit, rfl⟩ variable (x) @[to_additive] theorem orderOf_pow' (h : n ≠ 0) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd h, mul_left_iterate] @[to_additive] lemma orderOf_pow_of_dvd {x : G} {n : ℕ} (hn : n ≠ 0) (dvd : n ∣ orderOf x) : orderOf (x ^ n) = orderOf x / n := by rw [orderOf_pow' _ hn, Nat.gcd_eq_right dvd] @[to_additive] lemma orderOf_pow_orderOf_div {x : G} {n : ℕ} (hx : orderOf x ≠ 0) (hn : n ∣ orderOf x) : orderOf (x ^ (orderOf x / n)) = n := by rw [orderOf_pow_of_dvd _ (Nat.div_dvd_of_dvd hn), Nat.div_div_self hn hx] rw [← Nat.div_mul_cancel hn] at hx; exact left_ne_zero_of_mul hx variable (n) @[to_additive] protected lemma IsOfFinOrder.orderOf_pow (h : IsOfFinOrder x) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := by unfold orderOf rw [← minimalPeriod_iterate_eq_div_gcd' h, mul_left_iterate] @[to_additive] lemma Nat.Coprime.orderOf_pow (h : (orderOf y).Coprime m) : orderOf (y ^ m) = orderOf y := by by_cases hg : IsOfFinOrder y · rw [hg.orderOf_pow y m , h.gcd_eq_one, Nat.div_one] · rw [m.coprime_zero_left.1 (orderOf_eq_zero hg ▸ h), pow_one] @[to_additive] lemma IsOfFinOrder.natCard_powers_le_orderOf (ha : IsOfFinOrder a) : Nat.card (powers a : Set G) ≤ orderOf a := by classical simpa [ha.powers_eq_image_range_orderOf, Finset.card_range, Nat.Iio_eq_range] using Finset.card_image_le (s := Finset.range (orderOf a)) @[to_additive] lemma IsOfFinOrder.finite_powers (ha : IsOfFinOrder a) : (powers a : Set G).Finite := by classical rw [ha.powers_eq_image_range_orderOf]; exact Finset.finite_toSet _ namespace Commute variable {x} @[to_additive] theorem orderOf_mul_dvd_lcm (h : Commute x y) : orderOf (x * y) ∣ Nat.lcm (orderOf x) (orderOf y) := by rw [orderOf, ← comp_mul_left] exact Function.Commute.minimalPeriod_of_comp_dvd_lcm h.function_commute_mul_left @[to_additive] theorem orderOf_dvd_lcm_mul (h : Commute x y): orderOf y ∣ Nat.lcm (orderOf x) (orderOf (x * y)) := by by_cases h0 : orderOf x = 0 · rw [h0, lcm_zero_left] apply dvd_zero conv_lhs => rw [← one_mul y, ← pow_orderOf_eq_one x, ← succ_pred_eq_of_pos (Nat.pos_of_ne_zero h0), _root_.pow_succ, mul_assoc] exact (((Commute.refl x).mul_right h).pow_left _).orderOf_mul_dvd_lcm.trans (lcm_dvd_iff.2 ⟨(orderOf_pow_dvd _).trans (dvd_lcm_left _ _), dvd_lcm_right _ _⟩) @[to_additive addOrderOf_add_dvd_mul_addOrderOf] theorem orderOf_mul_dvd_mul_orderOf (h : Commute x y): orderOf (x * y) ∣ orderOf x * orderOf y := dvd_trans h.orderOf_mul_dvd_lcm (lcm_dvd_mul _ _) @[to_additive addOrderOf_add_eq_mul_addOrderOf_of_coprime] theorem orderOf_mul_eq_mul_orderOf_of_coprime (h : Commute x y) (hco : (orderOf x).Coprime (orderOf y)) : orderOf (x * y) = orderOf x * orderOf y := by rw [orderOf, ← comp_mul_left] exact h.function_commute_mul_left.minimalPeriod_of_comp_eq_mul_of_coprime hco /-- Commuting elements of finite order are closed under multiplication. -/ @[to_additive "Commuting elements of finite additive order are closed under addition."] theorem isOfFinOrder_mul (h : Commute x y) (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := orderOf_pos_iff.mp <| pos_of_dvd_of_pos h.orderOf_mul_dvd_mul_orderOf <| mul_pos hx.orderOf_pos hy.orderOf_pos /-- If each prime factor of `orderOf x` has higher multiplicity in `orderOf y`, and `x` commutes with `y`, then `x * y` has the same order as `y`. -/ @[to_additive addOrderOf_add_eq_right_of_forall_prime_mul_dvd "If each prime factor of `addOrderOf x` has higher multiplicity in `addOrderOf y`, and `x` commutes with `y`, then `x + y` has the same order as `y`."] theorem orderOf_mul_eq_right_of_forall_prime_mul_dvd (h : Commute x y) (hy : IsOfFinOrder y) (hdvd : ∀ p : ℕ, p.Prime → p ∣ orderOf x → p * orderOf x ∣ orderOf y) : orderOf (x * y) = orderOf y := by have hoy := hy.orderOf_pos have hxy := dvd_of_forall_prime_mul_dvd hdvd apply orderOf_eq_of_pow_and_pow_div_prime hoy <;> simp only [Ne, ← orderOf_dvd_iff_pow_eq_one] · exact h.orderOf_mul_dvd_lcm.trans (lcm_dvd hxy dvd_rfl) refine fun p hp hpy hd => hp.ne_one ?_ rw [← Nat.dvd_one, ← mul_dvd_mul_iff_right hoy.ne', one_mul, ← dvd_div_iff_mul_dvd hpy] refine (orderOf_dvd_lcm_mul h).trans (lcm_dvd ((dvd_div_iff_mul_dvd hpy).2 ?_) hd) by_cases h : p ∣ orderOf x exacts [hdvd p hp h, (hp.coprime_iff_not_dvd.2 h).mul_dvd_of_dvd_of_dvd hpy hxy] end Commute section PPrime variable {x n} {p : ℕ} [hp : Fact p.Prime] @[to_additive] theorem orderOf_eq_prime_iff : orderOf x = p ↔ x ^ p = 1 ∧ x ≠ 1 := by rw [orderOf, minimalPeriod_eq_prime_iff, isPeriodicPt_mul_iff_pow_eq_one, IsFixedPt, mul_one] /-- The backward direction of `orderOf_eq_prime_iff`. -/ @[to_additive "The backward direction of `addOrderOf_eq_prime_iff`."] theorem orderOf_eq_prime (hg : x ^ p = 1) (hg1 : x ≠ 1) : orderOf x = p := orderOf_eq_prime_iff.mpr ⟨hg, hg1⟩ @[to_additive addOrderOf_eq_prime_pow] theorem orderOf_eq_prime_pow (hnot : ¬x ^ p ^ n = 1) (hfin : x ^ p ^ (n + 1) = 1) : orderOf x = p ^ (n + 1) := by apply minimalPeriod_eq_prime_pow <;> rwa [isPeriodicPt_mul_iff_pow_eq_one] @[to_additive exists_addOrderOf_eq_prime_pow_iff] theorem exists_orderOf_eq_prime_pow_iff : (∃ k : ℕ, orderOf x = p ^ k) ↔ ∃ m : ℕ, x ^ (p : ℕ) ^ m = 1 := ⟨fun ⟨k, hk⟩ => ⟨k, by rw [← hk, pow_orderOf_eq_one]⟩, fun ⟨_, hm⟩ => by obtain ⟨k, _, hk⟩ := (Nat.dvd_prime_pow hp.elim).mp (orderOf_dvd_of_pow_eq_one hm) exact ⟨k, hk⟩⟩ end PPrime /-- The equivalence between `Fin (orderOf x)` and `Submonoid.powers x`, sending `i` to `x ^ i` -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `AddSubmonoid.multiples a`, sending `i` to `i • a`"] noncomputable def finEquivPowers {x : G} (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ powers x := Equiv.ofBijective (fun n ↦ ⟨x ^ (n : ℕ), ⟨n, rfl⟩⟩) ⟨fun ⟨_, h₁⟩ ⟨_, h₂⟩ ij ↦ Fin.ext (pow_injOn_Iio_orderOf h₁ h₂ (Subtype.mk_eq_mk.1 ij)), fun ⟨_, i, rfl⟩ ↦ ⟨⟨i % orderOf x, mod_lt _ hx.orderOf_pos⟩, Subtype.eq <| pow_mod_orderOf _ _⟩⟩ @[to_additive (attr := simp)] lemma finEquivPowers_apply {x : G} (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivPowers hx n = ⟨x ^ (n : ℕ), n, rfl⟩ := rfl @[to_additive (attr := simp)] lemma finEquivPowers_symm_apply {x : G} (hx : IsOfFinOrder x) (n : ℕ) : (finEquivPowers hx).symm ⟨x ^ n, _, rfl⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [Equiv.symm_apply_eq, finEquivPowers_apply, Subtype.mk_eq_mk, ← pow_mod_orderOf, Fin.val_mk] variable {x n} (hx : IsOfFinOrder x) include hx @[to_additive] theorem IsOfFinOrder.pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [pow_add, (hx.isUnit.pow _).mul_eq_left, pow_eq_one_iff_modEq] exact ⟨fun h ↦ Nat.ModEq.add_left _ h, fun h ↦ Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive] lemma IsOfFinOrder.pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := hx.pow_eq_pow_iff_modEq end Monoid section CancelMonoid variable [LeftCancelMonoid G] {x y : G} {a : G} {m n : ℕ} @[to_additive] theorem pow_eq_pow_iff_modEq : x ^ n = x ^ m ↔ n ≡ m [MOD orderOf x] := by wlog hmn : m ≤ n generalizing m n · rw [eq_comm, ModEq.comm, this (le_of_not_le hmn)] obtain ⟨k, rfl⟩ := Nat.exists_eq_add_of_le hmn rw [← mul_one (x ^ m), pow_add, mul_left_cancel_iff, pow_eq_one_iff_modEq] exact ⟨fun h => Nat.ModEq.add_left _ h, fun h => Nat.ModEq.add_left_cancel' _ h⟩ @[to_additive (attr := simp)] lemma injective_pow_iff_not_isOfFinOrder : Injective (fun n : ℕ ↦ x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨fun h => not_isOfFinOrder_of_injective_pow h, fun h n m hnm => ?_⟩ rwa [pow_eq_pow_iff_modEq, orderOf_eq_zero_iff.mpr h, modEq_zero_iff] at hnm @[to_additive] lemma pow_inj_mod {n m : ℕ} : x ^ n = x ^ m ↔ n % orderOf x = m % orderOf x := pow_eq_pow_iff_modEq @[to_additive] theorem pow_inj_iff_of_orderOf_eq_zero (h : orderOf x = 0) {n m : ℕ} : x ^ n = x ^ m ↔ n = m := by rw [pow_eq_pow_iff_modEq, h, modEq_zero_iff] @[to_additive] theorem infinite_not_isOfFinOrder {x : G} (h : ¬IsOfFinOrder x) : { y : G | ¬IsOfFinOrder y }.Infinite := by let s := { n | 0 < n }.image fun n : ℕ => x ^ n have hs : s ⊆ { y : G | ¬IsOfFinOrder y } := by rintro - ⟨n, hn : 0 < n, rfl⟩ (contra : IsOfFinOrder (x ^ n)) apply h rw [isOfFinOrder_iff_pow_eq_one] at contra ⊢ obtain ⟨m, hm, hm'⟩ := contra exact ⟨n * m, mul_pos hn hm, by rwa [pow_mul]⟩ suffices s.Infinite by exact this.mono hs contrapose! h have : ¬Injective fun n : ℕ => x ^ n := by have := Set.not_injOn_infinite_finite_image (Set.Ioi_infinite 0) (Set.not_infinite.mp h) contrapose! this exact Set.injOn_of_injective this rwa [injective_pow_iff_not_isOfFinOrder, Classical.not_not] at this @[to_additive (attr := simp)] lemma finite_powers : (powers a : Set G).Finite ↔ IsOfFinOrder a := by refine ⟨fun h ↦ ?_, IsOfFinOrder.finite_powers⟩ obtain ⟨m, n, hmn, ha⟩ := h.exists_lt_map_eq_of_forall_mem (f := fun n : ℕ ↦ a ^ n) (fun n ↦ by simp [mem_powers_iff]) refine isOfFinOrder_iff_pow_eq_one.2 ⟨n - m, tsub_pos_iff_lt.2 hmn, ?_⟩ rw [← mul_left_cancel_iff (a := a ^ m), ← pow_add, add_tsub_cancel_of_le hmn.le, ha, mul_one] @[to_additive (attr := simp)] lemma infinite_powers : (powers a : Set G).Infinite ↔ ¬ IsOfFinOrder a := finite_powers.not /-- See also `orderOf_eq_card_powers`. -/ @[to_additive "See also `addOrder_eq_card_multiples`."] lemma Nat.card_submonoidPowers : Nat.card (powers a) = orderOf a := by classical by_cases ha : IsOfFinOrder a · exact (Nat.card_congr (finEquivPowers ha).symm).trans <| by simp · have := (infinite_powers.2 ha).to_subtype rw [orderOf_eq_zero ha, Nat.card_eq_zero_of_infinite] end CancelMonoid section Group variable [Group G] {x y : G} {i : ℤ} /-- Inverses of elements of finite order have finite order. -/ @[to_additive (attr := simp) "Inverses of elements of finite additive order have finite additive order."] theorem isOfFinOrder_inv_iff {x : G} : IsOfFinOrder x⁻¹ ↔ IsOfFinOrder x := by simp [isOfFinOrder_iff_pow_eq_one] @[to_additive] alias ⟨IsOfFinOrder.of_inv, IsOfFinOrder.inv⟩ := isOfFinOrder_inv_iff @[to_additive] theorem orderOf_dvd_iff_zpow_eq_one : (orderOf x : ℤ) ∣ i ↔ x ^ i = 1 := by rcases Int.eq_nat_or_neg i with ⟨i, rfl | rfl⟩ · rw [Int.natCast_dvd_natCast, orderOf_dvd_iff_pow_eq_one, zpow_natCast] · rw [dvd_neg, Int.natCast_dvd_natCast, zpow_neg, inv_eq_one, zpow_natCast, orderOf_dvd_iff_pow_eq_one] @[to_additive (attr := simp)] theorem orderOf_inv (x : G) : orderOf x⁻¹ = orderOf x := by simp [orderOf_eq_orderOf_iff] @[to_additive] theorem orderOf_dvd_sub_iff_zpow_eq_zpow {a b : ℤ} : (orderOf x : ℤ) ∣ a - b ↔ x ^ a = x ^ b := by rw [orderOf_dvd_iff_zpow_eq_one, zpow_sub, mul_inv_eq_one] namespace Subgroup variable {H : Subgroup G} @[to_additive (attr := norm_cast)] lemma orderOf_coe (a : H) : orderOf (a : G) = orderOf a := orderOf_injective H.subtype Subtype.coe_injective _ @[to_additive (attr := simp)] lemma orderOf_mk (a : G) (ha) : orderOf (⟨a, ha⟩ : H) = orderOf a := (orderOf_coe _).symm end Subgroup @[to_additive mod_addOrderOf_zsmul] lemma zpow_mod_orderOf (x : G) (z : ℤ) : x ^ (z % (orderOf x : ℤ)) = x ^ z := calc x ^ (z % (orderOf x : ℤ)) = x ^ (z % orderOf x + orderOf x * (z / orderOf x) : ℤ) := by simp [zpow_add, zpow_mul, pow_orderOf_eq_one] _ = x ^ z := by rw [Int.emod_add_ediv] @[to_additive (attr := simp) zsmul_smul_addOrderOf] theorem zpow_pow_orderOf : (x ^ i) ^ orderOf x = 1 := by by_cases h : IsOfFinOrder x · rw [← zpow_natCast, ← zpow_mul, mul_comm, zpow_mul, zpow_natCast, pow_orderOf_eq_one, one_zpow] · rw [orderOf_eq_zero h, _root_.pow_zero] @[to_additive] theorem IsOfFinOrder.zpow (h : IsOfFinOrder x) {i : ℤ} : IsOfFinOrder (x ^ i) := isOfFinOrder_iff_pow_eq_one.mpr ⟨orderOf x, h.orderOf_pos, zpow_pow_orderOf⟩ @[to_additive] theorem IsOfFinOrder.of_mem_zpowers (h : IsOfFinOrder x) (h' : y ∈ Subgroup.zpowers x) : IsOfFinOrder y := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h' exact h.zpow @[to_additive] theorem orderOf_dvd_of_mem_zpowers (h : y ∈ Subgroup.zpowers x) : orderOf y ∣ orderOf x := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp h rw [orderOf_dvd_iff_pow_eq_one] exact zpow_pow_orderOf theorem smul_eq_self_of_mem_zpowers {α : Type*} [MulAction G α] (hx : x ∈ Subgroup.zpowers y) {a : α} (hs : y • a = a) : x • a = a := by obtain ⟨k, rfl⟩ := Subgroup.mem_zpowers_iff.mp hx rw [← MulAction.toPerm_apply, ← MulAction.toPermHom_apply, MonoidHom.map_zpow _ y k, MulAction.toPermHom_apply] exact Function.IsFixedPt.perm_zpow (by exact hs) k -- Porting note: help elab'n with `by exact` theorem vadd_eq_self_of_mem_zmultiples {α G : Type*} [AddGroup G] [AddAction G α] {x y : G} (hx : x ∈ AddSubgroup.zmultiples y) {a : α} (hs : y +ᵥ a = a) : x +ᵥ a = a := @smul_eq_self_of_mem_zpowers (Multiplicative G) _ _ _ α _ hx a hs attribute [to_additive existing] smul_eq_self_of_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_powers_iff_mem_zpowers (hx : IsOfFinOrder x) : y ∈ powers x ↔ y ∈ zpowers x := ⟨fun ⟨n, hn⟩ ↦ ⟨n, by simp_all⟩, fun ⟨i, hi⟩ ↦ ⟨(i % orderOf x).natAbs, by dsimp only rwa [← zpow_natCast, Int.natAbs_of_nonneg <| Int.emod_nonneg _ <| Int.natCast_ne_zero_iff_pos.2 <| hx.orderOf_pos, zpow_mod_orderOf]⟩⟩ @[to_additive] lemma IsOfFinOrder.powers_eq_zpowers (hx : IsOfFinOrder x) : (powers x : Set G) = zpowers x := Set.ext fun _ ↦ hx.mem_powers_iff_mem_zpowers @[to_additive] lemma IsOfFinOrder.mem_zpowers_iff_mem_range_orderOf [DecidableEq G] (hx : IsOfFinOrder x) : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := hx.mem_powers_iff_mem_zpowers.symm.trans hx.mem_powers_iff_mem_range_orderOf /-- The equivalence between `Fin (orderOf x)` and `Subgroup.zpowers x`, sending `i` to `x ^ i`. -/ @[to_additive "The equivalence between `Fin (addOrderOf a)` and `Subgroup.zmultiples a`, sending `i` to `i • a`."] noncomputable def finEquivZPowers (hx : IsOfFinOrder x) : Fin (orderOf x) ≃ zpowers x := (finEquivPowers hx).trans <| Equiv.setCongr hx.powers_eq_zpowers @[to_additive] lemma finEquivZPowers_apply (hx : IsOfFinOrder x) {n : Fin (orderOf x)} : finEquivZPowers hx n = ⟨x ^ (n : ℕ), n, zpow_natCast x n⟩ := rfl @[to_additive] lemma finEquivZPowers_symm_apply (hx : IsOfFinOrder x) (n : ℕ) : (finEquivZPowers hx).symm ⟨x ^ n, ⟨n, by simp⟩⟩ = ⟨n % orderOf x, Nat.mod_lt _ hx.orderOf_pos⟩ := by rw [finEquivZPowers, Equiv.symm_trans_apply]; exact finEquivPowers_symm_apply _ n end Group section CommMonoid variable [CommMonoid G] {x y : G} /-- Elements of finite order are closed under multiplication. -/ @[to_additive "Elements of finite additive order are closed under addition."] theorem IsOfFinOrder.mul (hx : IsOfFinOrder x) (hy : IsOfFinOrder y) : IsOfFinOrder (x * y) := (Commute.all x y).isOfFinOrder_mul hx hy end CommMonoid section FiniteMonoid variable [Monoid G] {x : G} {n : ℕ} @[to_additive] theorem sum_card_orderOf_eq_card_pow_eq_one [Fintype G] [DecidableEq G] (hn : n ≠ 0) : ∑ m ∈ divisors n, #{x : G | orderOf x = m} = #{x : G | x ^ n = 1} := by refine (Finset.card_biUnion ?_).symm.trans ?_ · simp +contextual [Set.PairwiseDisjoint, Set.Pairwise, disjoint_iff, Finset.ext_iff] · congr; ext; simp [hn, orderOf_dvd_iff_pow_eq_one] @[to_additive] theorem orderOf_le_card_univ [Fintype G] : orderOf x ≤ Fintype.card G := Finset.le_card_of_inj_on_range (x ^ ·) (fun _ _ ↦ Finset.mem_univ _) pow_injOn_Iio_orderOf @[to_additive] theorem orderOf_le_card [Finite G] : orderOf x ≤ Nat.card G := by obtain ⟨⟩ := nonempty_fintype G simpa using orderOf_le_card_univ end FiniteMonoid section FiniteCancelMonoid variable [LeftCancelMonoid G] -- TODO: Of course everything also works for `RightCancelMonoid`. section Finite variable [Finite G] {x y : G} {n : ℕ} -- TODO: Use this to show that a finite left cancellative monoid is a group. @[to_additive] lemma isOfFinOrder_of_finite (x : G) : IsOfFinOrder x := by by_contra h; exact infinite_not_isOfFinOrder h <| Set.toFinite _ /-- This is the same as `IsOfFinOrder.orderOf_pos` but with one fewer explicit assumption since this is automatic in case of a finite cancellative monoid. -/ @[to_additive "This is the same as `IsOfFinAddOrder.addOrderOf_pos` but with one fewer explicit assumption since this is automatic in case of a finite cancellative additive monoid."] lemma orderOf_pos (x : G) : 0 < orderOf x := (isOfFinOrder_of_finite x).orderOf_pos /-- This is the same as `orderOf_pow'` and `orderOf_pow''` but with one assumption less which is automatic in the case of a finite cancellative monoid. -/ @[to_additive "This is the same as `addOrderOf_nsmul'` and `addOrderOf_nsmul` but with one assumption less which is automatic in the case of a finite cancellative additive monoid."] theorem orderOf_pow (x : G) : orderOf (x ^ n) = orderOf x / gcd (orderOf x) n := (isOfFinOrder_of_finite _).orderOf_pow .. @[to_additive] theorem mem_powers_iff_mem_range_orderOf [DecidableEq G] : y ∈ powers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := Finset.mem_range_iff_mem_finset_range_of_mod_eq' (orderOf_pos x) <| pow_mod_orderOf _ /-- The equivalence between `Submonoid.powers` of two elements `x, y` of the same order, mapping `x ^ i` to `y ^ i`. -/ @[to_additive "The equivalence between `Submonoid.multiples` of two elements `a, b` of the same additive order, mapping `i • a` to `i • b`."] noncomputable def powersEquivPowers (h : orderOf x = orderOf y) : powers x ≃ powers y := (finEquivPowers <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <| finEquivPowers <| isOfFinOrder_of_finite _ @[to_additive (attr := simp)] theorem powersEquivPowers_apply (h : orderOf x = orderOf y) (n : ℕ) : powersEquivPowers h ⟨x ^ n, n, rfl⟩ = ⟨y ^ n, n, rfl⟩ := by rw [powersEquivPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivPowers_symm_apply, ← Equiv.eq_symm_apply, finEquivPowers_symm_apply] simp [h] end Finite variable [Fintype G] {x : G} @[to_additive] lemma orderOf_eq_card_powers : orderOf x = Fintype.card (powers x : Submonoid G) := (Fintype.card_fin (orderOf x)).symm.trans <| Fintype.card_eq.2 ⟨finEquivPowers <| isOfFinOrder_of_finite _⟩ end FiniteCancelMonoid section FiniteGroup variable [Group G] {x y : G} @[to_additive] theorem zpow_eq_one_iff_modEq {n : ℤ} : x ^ n = 1 ↔ n ≡ 0 [ZMOD orderOf x] := by rw [Int.modEq_zero_iff_dvd, orderOf_dvd_iff_zpow_eq_one] @[to_additive] theorem zpow_eq_zpow_iff_modEq {m n : ℤ} : x ^ m = x ^ n ↔ m ≡ n [ZMOD orderOf x] := by rw [← mul_inv_eq_one, ← zpow_sub, zpow_eq_one_iff_modEq, Int.modEq_iff_dvd, Int.modEq_iff_dvd, zero_sub, neg_sub] @[to_additive (attr := simp)] theorem injective_zpow_iff_not_isOfFinOrder : (Injective fun n : ℤ => x ^ n) ↔ ¬IsOfFinOrder x := by refine ⟨?_, fun h n m hnm => ?_⟩ · simp_rw [isOfFinOrder_iff_pow_eq_one] rintro h ⟨n, hn, hx⟩ exact Nat.cast_ne_zero.2 hn.ne' (h <| by simpa using hx) rwa [zpow_eq_zpow_iff_modEq, orderOf_eq_zero_iff.2 h, Nat.cast_zero, Int.modEq_zero_iff] at hnm section Finite variable [Finite G] @[to_additive] theorem exists_zpow_eq_one (x : G) : ∃ (i : ℤ) (_ : i ≠ 0), x ^ (i : ℤ) = 1 := by obtain ⟨w, hw1, hw2⟩ := isOfFinOrder_of_finite x refine ⟨w, Int.natCast_ne_zero.mpr (_root_.ne_of_gt hw1), ?_⟩ rw [zpow_natCast] exact (isPeriodicPt_mul_iff_pow_eq_one _).mp hw2 @[to_additive] lemma mem_powers_iff_mem_zpowers : y ∈ powers x ↔ y ∈ zpowers x := (isOfFinOrder_of_finite _).mem_powers_iff_mem_zpowers @[to_additive] lemma powers_eq_zpowers (x : G) : (powers x : Set G) = zpowers x := (isOfFinOrder_of_finite _).powers_eq_zpowers @[to_additive] lemma mem_zpowers_iff_mem_range_orderOf [DecidableEq G] : y ∈ zpowers x ↔ y ∈ (Finset.range (orderOf x)).image (x ^ ·) := (isOfFinOrder_of_finite _).mem_zpowers_iff_mem_range_orderOf /-- The equivalence between `Subgroup.zpowers` of two elements `x, y` of the same order, mapping `x ^ i` to `y ^ i`. -/ @[to_additive "The equivalence between `Subgroup.zmultiples` of two elements `a, b` of the same additive order, mapping `i • a` to `i • b`."] noncomputable def zpowersEquivZPowers (h : orderOf x = orderOf y) : Subgroup.zpowers x ≃ Subgroup.zpowers y := (finEquivZPowers <| isOfFinOrder_of_finite _).symm.trans <| (finCongr h).trans <| finEquivZPowers <| isOfFinOrder_of_finite _ @[to_additive (attr := simp) zmultiples_equiv_zmultiples_apply] theorem zpowersEquivZPowers_apply (h : orderOf x = orderOf y) (n : ℕ) : zpowersEquivZPowers h ⟨x ^ n, n, zpow_natCast x n⟩ = ⟨y ^ n, n, zpow_natCast y n⟩ := by rw [zpowersEquivZPowers, Equiv.trans_apply, Equiv.trans_apply, finEquivZPowers_symm_apply, ← Equiv.eq_symm_apply, finEquivZPowers_symm_apply] simp [h] end Finite variable [Fintype G] {x : G} {n : ℕ} /-- See also `Nat.card_zpowers`. -/ @[to_additive "See also `Nat.card_zmultiples`."] theorem Fintype.card_zpowers : Fintype.card (zpowers x) = orderOf x := (Fintype.card_eq.2 ⟨finEquivZPowers <| isOfFinOrder_of_finite _⟩).symm.trans <| Fintype.card_fin (orderOf x) @[to_additive] theorem card_zpowers_le (a : G) {k : ℕ} (k_pos : k ≠ 0) (ha : a ^ k = 1) : Fintype.card (Subgroup.zpowers a) ≤ k := by rw [Fintype.card_zpowers] apply orderOf_le_of_pow_eq_one k_pos.bot_lt ha open QuotientGroup @[to_additive] theorem orderOf_dvd_card : orderOf x ∣ Fintype.card G := by classical have ft_prod : Fintype ((G ⧸ zpowers x) × zpowers x) := Fintype.ofEquiv G groupEquivQuotientProdSubgroup have ft_s : Fintype (zpowers x) := @Fintype.prodRight _ _ _ ft_prod _ have ft_cosets : Fintype (G ⧸ zpowers x) := @Fintype.prodLeft _ _ _ ft_prod ⟨⟨1, (zpowers x).one_mem⟩⟩ have eq₁ : Fintype.card G = @Fintype.card _ ft_cosets * @Fintype.card _ ft_s := calc Fintype.card G = @Fintype.card _ ft_prod := @Fintype.card_congr _ _ _ ft_prod groupEquivQuotientProdSubgroup _ = @Fintype.card _ (@instFintypeProd _ _ ft_cosets ft_s) := congr_arg (@Fintype.card _) <| Subsingleton.elim _ _ _ = @Fintype.card _ ft_cosets * @Fintype.card _ ft_s := @Fintype.card_prod _ _ ft_cosets ft_s have eq₂ : orderOf x = @Fintype.card _ ft_s := calc orderOf x = _ := Fintype.card_zpowers.symm _ = _ := congr_arg (@Fintype.card _) <| Subsingleton.elim _ _ exact Dvd.intro (@Fintype.card (G ⧸ Subgroup.zpowers x) ft_cosets) (by rw [eq₁, eq₂, mul_comm]) @[to_additive] theorem orderOf_dvd_natCard {G : Type*} [Group G] (x : G) : orderOf x ∣ Nat.card G := by obtain h | h := fintypeOrInfinite G · simp only [Nat.card_eq_fintype_card, orderOf_dvd_card] · simp only [card_eq_zero_of_infinite, dvd_zero] @[to_additive] nonrec lemma Subgroup.orderOf_dvd_natCard {G : Type*} [Group G] (s : Subgroup G) {x} (hx : x ∈ s) : orderOf x ∣ Nat.card s := by simpa using orderOf_dvd_natCard (⟨x, hx⟩ : s) @[to_additive] lemma Subgroup.orderOf_le_card {G : Type*} [Group G] (s : Subgroup G) (hs : (s : Set G).Finite) {x} (hx : x ∈ s) : orderOf x ≤ Nat.card s := le_of_dvd (Nat.card_pos_iff.2 <| ⟨s.coe_nonempty.to_subtype, hs.to_subtype⟩) <| s.orderOf_dvd_natCard hx @[to_additive] lemma Submonoid.orderOf_le_card {G : Type*} [Group G] (s : Submonoid G) (hs : (s : Set G).Finite) {x} (hx : x ∈ s) : orderOf x ≤ Nat.card s := by rw [← Nat.card_submonoidPowers]; exact Nat.card_mono hs <| powers_le.2 hx @[to_additive (attr := simp) card_nsmul_eq_zero'] theorem pow_card_eq_one' {G : Type*} [Group G] {x : G} : x ^ Nat.card G = 1 := orderOf_dvd_iff_pow_eq_one.mp <| orderOf_dvd_natCard _ @[to_additive (attr := simp) card_nsmul_eq_zero] theorem pow_card_eq_one : x ^ Fintype.card G = 1 := by rw [← Nat.card_eq_fintype_card, pow_card_eq_one'] @[to_additive] theorem Subgroup.pow_index_mem {G : Type*} [Group G] (H : Subgroup G) [Normal H] (g : G) : g ^ index H ∈ H := by rw [← eq_one_iff, QuotientGroup.mk_pow H, index, pow_card_eq_one'] @[to_additive (attr := simp) mod_card_nsmul] lemma pow_mod_card (a : G) (n : ℕ) : a ^ (n % card G) = a ^ n := by rw [eq_comm, ← pow_mod_orderOf, ← Nat.mod_mod_of_dvd n orderOf_dvd_card, pow_mod_orderOf] @[to_additive (attr := simp) mod_card_zsmul] theorem zpow_mod_card (a : G) (n : ℤ) : a ^ (n % Fintype.card G : ℤ) = a ^ n := by rw [eq_comm, ← zpow_mod_orderOf, ← Int.emod_emod_of_dvd n (Int.natCast_dvd_natCast.2 orderOf_dvd_card), zpow_mod_orderOf] @[to_additive (attr := simp) mod_natCard_nsmul] lemma pow_mod_natCard {G} [Group G] (a : G) (n : ℕ) : a ^ (n % Nat.card G) = a ^ n := by rw [eq_comm, ← pow_mod_orderOf, ← Nat.mod_mod_of_dvd n <| orderOf_dvd_natCard _, pow_mod_orderOf] @[to_additive (attr := simp) mod_natCard_zsmul] lemma zpow_mod_natCard {G} [Group G] (a : G) (n : ℤ) : a ^ (n % Nat.card G : ℤ) = a ^ n := by rw [eq_comm, ← zpow_mod_orderOf, ← Int.emod_emod_of_dvd n <| Int.natCast_dvd_natCast.2 <| orderOf_dvd_natCard _, zpow_mod_orderOf] /-- If `gcd(|G|,n)=1` then the `n`th power map is a bijection -/ @[to_additive (attr := simps) "If `gcd(|G|,n)=1` then the smul by `n` is a bijection"] noncomputable def powCoprime {G : Type*} [Group G] (h : (Nat.card G).Coprime n) : G ≃ G where toFun g := g ^ n invFun g := g ^ (Nat.card G).gcdB n left_inv g := by have key := congr_arg (g ^ ·) ((Nat.card G).gcd_eq_gcd_ab n) dsimp only at key rwa [zpow_add, zpow_mul, zpow_mul, zpow_natCast, zpow_natCast, zpow_natCast, h.gcd_eq_one, pow_one, pow_card_eq_one', one_zpow, one_mul, eq_comm] at key right_inv g := by have key := congr_arg (g ^ ·) ((Nat.card G).gcd_eq_gcd_ab n) dsimp only at key rwa [zpow_add, zpow_mul, zpow_mul', zpow_natCast, zpow_natCast, zpow_natCast, h.gcd_eq_one, pow_one, pow_card_eq_one', one_zpow, one_mul, eq_comm] at key @[to_additive] theorem powCoprime_one {G : Type*} [Group G] (h : (Nat.card G).Coprime n) : powCoprime h 1 = 1 := one_pow n @[to_additive] theorem powCoprime_inv {G : Type*} [Group G] (h : (Nat.card G).Coprime n) {g : G} : powCoprime h g⁻¹ = (powCoprime h g)⁻¹ := inv_pow g n @[to_additive Nat.Coprime.nsmul_right_bijective] lemma Nat.Coprime.pow_left_bijective {G} [Group G] (hn : (Nat.card G).Coprime n) : Bijective (· ^ n : G → G) := (powCoprime hn).bijective /- TODO: Generalise to `Submonoid.powers`. -/ @[to_additive] theorem image_range_orderOf [DecidableEq G] : letI : Fintype (zpowers x) := (Subgroup.zpowers x).instFintypeSubtypeMemOfDecidablePred Finset.image (fun i => x ^ i) (Finset.range (orderOf x)) = (zpowers x : Set G).toFinset := by letI : Fintype (zpowers x) := (Subgroup.zpowers x).instFintypeSubtypeMemOfDecidablePred ext x rw [Set.mem_toFinset, SetLike.mem_coe, mem_zpowers_iff_mem_range_orderOf] /- TODO: Generalise to `Finite` + `CancelMonoid`. -/ @[to_additive gcd_nsmul_card_eq_zero_iff] theorem pow_gcd_card_eq_one_iff : x ^ n = 1 ↔ x ^ gcd n (Fintype.card G) = 1 := ⟨fun h => pow_gcd_eq_one _ h <| pow_card_eq_one, fun h => by let ⟨m, hm⟩ := gcd_dvd_left n (Fintype.card G) rw [hm, pow_mul, h, one_pow]⟩ lemma smul_eq_of_le_smul {G : Type*} [Group G] [Finite G] {α : Type*} [PartialOrder α] {g : G} {a : α} [MulAction G α] [CovariantClass G α HSMul.hSMul LE.le] (h : a ≤ g • a) : g • a = a := by have key := smul_mono_right g (le_pow_smul h (Nat.card G - 1)) rw [smul_smul, ← _root_.pow_succ', Nat.sub_one_add_one_eq_of_pos Nat.card_pos, pow_card_eq_one', one_smul] at key exact le_antisymm key h lemma smul_eq_of_smul_le {G : Type*} [Group G] [Finite G] {α : Type*} [PartialOrder α] {g : G} {a : α} [MulAction G α] [CovariantClass G α HSMul.hSMul LE.le] (h : g • a ≤ a) : g • a = a := by have key := smul_mono_right g (pow_smul_le h (Nat.card G - 1)) rw [smul_smul, ← _root_.pow_succ', Nat.sub_one_add_one_eq_of_pos Nat.card_pos, pow_card_eq_one', one_smul] at key exact le_antisymm h key end FiniteGroup section PowIsSubgroup /-- A nonempty idempotent subset of a finite cancellative monoid is a submonoid -/ @[to_additive "A nonempty idempotent subset of a finite cancellative add monoid is a submonoid"] def submonoidOfIdempotent {M : Type*} [LeftCancelMonoid M] [Finite M] (S : Set M) (hS1 : S.Nonempty) (hS2 : S * S = S) : Submonoid M := have pow_mem (a : M) (ha : a ∈ S) (n : ℕ) : a ^ (n + 1) ∈ S := by induction n with | zero => rwa [zero_add, pow_one] | succ n ih => rw [← hS2, pow_succ] exact Set.mul_mem_mul ih ha { carrier := S one_mem' := by obtain ⟨a, ha⟩ := hS1 rw [← pow_orderOf_eq_one a, ← tsub_add_cancel_of_le (succ_le_of_lt (orderOf_pos a))] exact pow_mem a ha (orderOf a - 1) mul_mem' := fun ha hb => (congr_arg₂ (· ∈ ·) rfl hS2).mp (Set.mul_mem_mul ha hb) } /-- A nonempty idempotent subset of a finite group is a subgroup -/ @[to_additive "A nonempty idempotent subset of a finite add group is a subgroup"] def subgroupOfIdempotent {G : Type*} [Group G] [Finite G] (S : Set G) (hS1 : S.Nonempty) (hS2 : S * S = S) : Subgroup G := { submonoidOfIdempotent S hS1 hS2 with carrier := S inv_mem' := fun {a} ha => show a⁻¹ ∈ submonoidOfIdempotent S hS1 hS2 by rw [← one_mul a⁻¹, ← pow_one a, ← pow_orderOf_eq_one a, ← pow_sub a (orderOf_pos a)] exact pow_mem ha (orderOf a - 1) } /-- If `S` is a nonempty subset of a finite group `G`, then `S ^ |G|` is a subgroup -/ @[to_additive (attr := simps!) smulCardAddSubgroup "If `S` is a nonempty subset of a finite add group `G`, then `|G| • S` is a subgroup"] def powCardSubgroup {G : Type*} [Group G] [Fintype G] (S : Set G) (hS : S.Nonempty) : Subgroup G := have one_mem : (1 : G) ∈ S ^ Fintype.card G := by obtain ⟨a, ha⟩ := hS rw [← pow_card_eq_one] exact Set.pow_mem_pow ha subgroupOfIdempotent (S ^ Fintype.card G) ⟨1, one_mem⟩ <| by classical apply (Set.eq_of_subset_of_card_le (Set.subset_mul_left _ one_mem) (ge_of_eq _)).symm simp_rw [← pow_add, Group.card_pow_eq_card_pow_card_univ S (Fintype.card G + Fintype.card G) le_add_self] end PowIsSubgroup section LinearOrderedSemiring variable [Semiring G] [LinearOrder G] [IsStrictOrderedRing G] {a : G} protected lemma IsOfFinOrder.eq_one (ha₀ : 0 ≤ a) (ha : IsOfFinOrder a) : a = 1 := by obtain ⟨n, hn, ha⟩ := ha.exists_pow_eq_one exact (pow_eq_one_iff_of_nonneg ha₀ hn.ne').1 ha end LinearOrderedSemiring section LinearOrderedRing variable [Ring G] [LinearOrder G] [IsStrictOrderedRing G] {a x : G} protected lemma IsOfFinOrder.eq_neg_one (ha₀ : a ≤ 0) (ha : IsOfFinOrder a) : a = -1 := (sq_eq_one_iff.1 <| ha.pow.eq_one <| sq_nonneg a).resolve_left <| by rintro rfl; exact one_pos.not_le ha₀ theorem orderOf_abs_ne_one (h : |x| ≠ 1) : orderOf x = 0 := by rw [orderOf_eq_zero_iff'] intro n hn hx replace hx : |x| ^ n = 1 := by simpa only [abs_one, abs_pow] using congr_arg abs hx rcases h.lt_or_lt with h | h · exact ((pow_lt_one₀ (abs_nonneg x) h hn.ne').ne hx).elim · exact ((one_lt_pow₀ h hn.ne').ne' hx).elim theorem LinearOrderedRing.orderOf_le_two : orderOf x ≤ 2 := by rcases ne_or_eq |x| 1 with h | h · simp [orderOf_abs_ne_one h] rcases eq_or_eq_neg_of_abs_eq h with (rfl | rfl) · simp exact orderOf_le_of_pow_eq_one zero_lt_two (by simp) end LinearOrderedRing section Prod variable [Monoid α] [Monoid β] {x : α × β} {a : α} {b : β} @[to_additive] protected theorem Prod.orderOf (x : α × β) : orderOf x = (orderOf x.1).lcm (orderOf x.2) := minimalPeriod_prodMap _ _ _ @[to_additive] theorem orderOf_fst_dvd_orderOf : orderOf x.1 ∣ orderOf x := minimalPeriod_fst_dvd @[to_additive] theorem orderOf_snd_dvd_orderOf : orderOf x.2 ∣ orderOf x := minimalPeriod_snd_dvd @[to_additive] theorem IsOfFinOrder.fst {x : α × β} (hx : IsOfFinOrder x) : IsOfFinOrder x.1 := hx.mono orderOf_fst_dvd_orderOf @[to_additive] theorem IsOfFinOrder.snd {x : α × β} (hx : IsOfFinOrder x) : IsOfFinOrder x.2 := hx.mono orderOf_snd_dvd_orderOf @[to_additive IsOfFinAddOrder.prod_mk] theorem IsOfFinOrder.prod_mk : IsOfFinOrder a → IsOfFinOrder b → IsOfFinOrder (a, b) := by simpa only [← orderOf_pos_iff, Prod.orderOf] using Nat.lcm_pos @[to_additive] lemma Prod.orderOf_mk : orderOf (a, b) = Nat.lcm (orderOf a) (orderOf b) := (a, b).orderOf end Prod -- TODO: Corresponding `pi` lemmas. We cannot currently state them here because of import cycles @[simp] lemma Nat.cast_card_eq_zero (R) [AddGroupWithOne R] [Fintype R] : (Fintype.card R : R) = 0 := by rw [← nsmul_one, card_nsmul_eq_zero] section NonAssocRing variable (R : Type*) [NonAssocRing R] (p : ℕ) lemma CharP.addOrderOf_one : CharP R (addOrderOf (1 : R)) where cast_eq_zero_iff n := by rw [← Nat.smul_one_eq_cast, addOrderOf_dvd_iff_nsmul_eq_zero] variable [Fintype R] variable {R} in lemma charP_of_ne_zero (hn : card R = p) (hR : ∀ i < p, (i : R) = 0 → i = 0) : CharP R p where cast_eq_zero_iff n := by have H : (p : R) = 0 := by rw [← hn, Nat.cast_card_eq_zero] constructor · intro h rw [← Nat.mod_add_div n p, Nat.cast_add, Nat.cast_mul, H, zero_mul, add_zero] at h rw [Nat.dvd_iff_mod_eq_zero] apply hR _ (Nat.mod_lt _ _) h rw [← hn, gt_iff_lt, Fintype.card_pos_iff] exact ⟨0⟩ · rintro ⟨n, rfl⟩ rw [Nat.cast_mul, H, zero_mul] end NonAssocRing lemma charP_of_prime_pow_injective (R) [Ring R] [Fintype R] (p n : ℕ) [hp : Fact p.Prime] (hn : card R = p ^ n) (hR : ∀ i ≤ n, (p : R) ^ i = 0 → i = n) : CharP R (p ^ n) := by obtain ⟨c, hc⟩ := CharP.exists R have hcpn : c ∣ p ^ n := by rw [← CharP.cast_eq_zero_iff R c, ← hn, Nat.cast_card_eq_zero] obtain ⟨i, hi, rfl⟩ : ∃ i ≤ n, c = p ^ i := by rwa [Nat.dvd_prime_pow hp.1] at hcpn obtain rfl : i = n := hR i hi <| by rw [← Nat.cast_pow, CharP.cast_eq_zero] assumption namespace SemiconjBy @[to_additive] lemma orderOf_eq [Group G] (a : G) {x y : G} (h : SemiconjBy a x y) : orderOf x = orderOf y := by rw [orderOf_eq_orderOf_iff] intro n exact (h.pow_right n).eq_one_iff end SemiconjBy section single lemma orderOf_piMulSingle {ι : Type*} [DecidableEq ι] {M : ι → Type*} [(i : ι) → Monoid (M i)] (i : ι) (g : M i) : orderOf (Pi.mulSingle i g) = orderOf g := orderOf_injective (MonoidHom.mulSingle M i) (Pi.mulSingle_injective M i) g end single
Mathlib/GroupTheory/OrderOfElement.lean
1,343
1,349
/- Copyright (c) 2022 Alex Kontorovich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Eric Wieser -/ import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Group.Submonoid.MulOpposite /-! # Mul-opposite subgroups ## Tags subgroup, subgroups -/ variable {ι : Sort*} {G : Type*} [Group G] namespace Subgroup /-- Pull a subgroup back to an opposite subgroup along `MulOpposite.unop` -/ @[to_additive (attr := simps) "Pull an additive subgroup back to an opposite additive subgroup along `AddOpposite.unop`"] protected def op (H : Subgroup G) : Subgroup Gᵐᵒᵖ where carrier := MulOpposite.unop ⁻¹' (H : Set G) one_mem' := H.one_mem mul_mem' ha hb := H.mul_mem hb ha inv_mem' := H.inv_mem @[to_additive (attr := simp)] theorem mem_op {x : Gᵐᵒᵖ} {S : Subgroup G} : x ∈ S.op ↔ x.unop ∈ S := Iff.rfl @[to_additive (attr := simp)] lemma op_toSubmonoid (H : Subgroup G) : H.op.toSubmonoid = H.toSubmonoid.op := rfl /-- Pull an opposite subgroup back to a subgroup along `MulOpposite.op` -/ @[to_additive (attr := simps) "Pull an opposite additive subgroup back to an additive subgroup along `AddOpposite.op`"] protected def unop (H : Subgroup Gᵐᵒᵖ) : Subgroup G where carrier := MulOpposite.op ⁻¹' (H : Set Gᵐᵒᵖ) one_mem' := H.one_mem mul_mem' := fun ha hb => H.mul_mem hb ha inv_mem' := H.inv_mem @[to_additive (attr := simp)] theorem mem_unop {x : G} {S : Subgroup Gᵐᵒᵖ} : x ∈ S.unop ↔ MulOpposite.op x ∈ S := Iff.rfl @[to_additive (attr := simp)] lemma unop_toSubmonoid (H : Subgroup Gᵐᵒᵖ) : H.unop.toSubmonoid = H.toSubmonoid.unop := rfl @[to_additive (attr := simp)] theorem unop_op (S : Subgroup G) : S.op.unop = S := rfl @[to_additive (attr := simp)] theorem op_unop (S : Subgroup Gᵐᵒᵖ) : S.unop.op = S := rfl /-! ### Lattice results -/ @[to_additive] theorem op_le_iff {S₁ : Subgroup G} {S₂ : Subgroup Gᵐᵒᵖ} : S₁.op ≤ S₂ ↔ S₁ ≤ S₂.unop := MulOpposite.op_surjective.forall @[to_additive] theorem le_op_iff {S₁ : Subgroup Gᵐᵒᵖ} {S₂ : Subgroup G} : S₁ ≤ S₂.op ↔ S₁.unop ≤ S₂ := MulOpposite.op_surjective.forall @[to_additive (attr := simp)] theorem op_le_op_iff {S₁ S₂ : Subgroup G} : S₁.op ≤ S₂.op ↔ S₁ ≤ S₂ := MulOpposite.op_surjective.forall @[to_additive (attr := simp)] theorem unop_le_unop_iff {S₁ S₂ : Subgroup Gᵐᵒᵖ} : S₁.unop ≤ S₂.unop ↔ S₁ ≤ S₂ := MulOpposite.unop_surjective.forall /-- A subgroup `H` of `G` determines a subgroup `H.op` of the opposite group `Gᵐᵒᵖ`. -/ @[to_additive (attr := simps) "An additive subgroup `H` of `G` determines an additive subgroup `H.op` of the opposite additive group `Gᵃᵒᵖ`."] def opEquiv : Subgroup G ≃o Subgroup Gᵐᵒᵖ where toFun := Subgroup.op invFun := Subgroup.unop left_inv := unop_op right_inv := op_unop map_rel_iff' := op_le_op_iff @[to_additive] theorem op_injective : (@Subgroup.op G _).Injective := opEquiv.injective @[to_additive] theorem unop_injective : (@Subgroup.unop G _).Injective := opEquiv.symm.injective @[to_additive (attr := simp)] theorem op_inj {S T : Subgroup G} : S.op = T.op ↔ S = T := opEquiv.eq_iff_eq @[to_additive (attr := simp)] theorem unop_inj {S T : Subgroup Gᵐᵒᵖ} : S.unop = T.unop ↔ S = T := opEquiv.symm.eq_iff_eq /-- Bijection between a subgroup `H` and its opposite. -/ @[to_additive (attr := simps!) "Bijection between an additive subgroup `H` and its opposite."] def equivOp (H : Subgroup G) : H ≃ H.op := MulOpposite.opEquiv.subtypeEquiv fun _ => Iff.rfl @[to_additive] theorem op_normalizer (H : Subgroup G) : H.normalizer.op = H.op.normalizer := by ext x simp [mem_normalizer_iff', MulOpposite.op_surjective.forall, iff_comm] @[to_additive] theorem unop_normalizer (H : Subgroup Gᵐᵒᵖ) : H.normalizer.unop = H.unop.normalizer := by rw [← op_inj, op_unop, op_normalizer, op_unop] end Subgroup
Mathlib/Algebra/Group/Subgroup/MulOpposite.lean
157
160
/- 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, Floris van Doorn, Yury Kudryashov, Neil Strickland -/ import Mathlib.Algebra.Divisibility.Hom import Mathlib.Algebra.Group.Equiv.Basic import Mathlib.Algebra.Ring.Defs import Mathlib.Data.Nat.Basic /-! # Lemmas about divisibility in rings Note that this file is imported by basic tactics like `linarith` and so must have only minimal imports. Further results about divisibility in rings may be found in `Mathlib.Algebra.Ring.Divisibility.Lemmas` which is not subject to this import constraint. -/ variable {α β : Type*} section Semigroup variable [Semigroup α] [Semigroup β] {F : Type*} [EquivLike F α β] [MulEquivClass F α β] theorem map_dvd_iff (f : F) {a b} : f a ∣ f b ↔ a ∣ b := let f := MulEquivClass.toMulEquiv f ⟨fun h ↦ by rw [← f.left_inv a, ← f.left_inv b]; exact map_dvd f.symm h, map_dvd f⟩ theorem MulEquiv.decompositionMonoid (f : F) [DecompositionMonoid β] : DecompositionMonoid α where primal a b c h := by rw [← map_dvd_iff f, map_mul] at h obtain ⟨a₁, a₂, h⟩ := DecompositionMonoid.primal _ h refine ⟨symm f a₁, symm f a₂, ?_⟩ simp_rw [← map_dvd_iff f, ← map_mul, eq_symm_apply] iterate 2 erw [(f : α ≃* β).apply_symm_apply] exact h /-- If `G` is a `LeftCancelSemiGroup`, left multiplication by `g` yields an equivalence between `G` and the set of elements of `G` divisible by `g`. -/ protected noncomputable def Equiv.dvd {G : Type*} [LeftCancelSemigroup G] (g : G) : G ≃ {a : G // g ∣ a} where toFun := fun a ↦ ⟨g * a, ⟨a, rfl⟩⟩ invFun := fun ⟨_, h⟩ ↦ h.choose left_inv := fun _ ↦ by simp right_inv := by rintro ⟨_, ⟨_, rfl⟩⟩ simp @[simp] theorem Equiv.dvd_apply {G : Type*} [LeftCancelSemigroup G] (g a : G) : Equiv.dvd g a = g * a := rfl end Semigroup section DistribSemigroup variable [Add α] [Semigroup α] theorem dvd_add [LeftDistribClass α] {a b c : α} (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b + c := Dvd.elim h₁ fun d hd => Dvd.elim h₂ fun e he => Dvd.intro (d + e) (by simp [left_distrib, hd, he]) alias Dvd.dvd.add := dvd_add end DistribSemigroup section Semiring variable [Semiring α] {a b c : α} {m n : ℕ} lemma min_pow_dvd_add (ha : c ^ m ∣ a) (hb : c ^ n ∣ b) : c ^ min m n ∣ a + b := ((pow_dvd_pow c (m.min_le_left n)).trans ha).add ((pow_dvd_pow c (m.min_le_right n)).trans hb) end Semiring section NonUnitalCommSemiring variable [NonUnitalCommSemiring α] theorem Dvd.dvd.linear_comb {d x y : α} (hdx : d ∣ x) (hdy : d ∣ y) (a b : α) : d ∣ a * x + b * y := dvd_add (hdx.mul_left a) (hdy.mul_left b) end NonUnitalCommSemiring section Semigroup variable [Semigroup α] [HasDistribNeg α] {a b : α} /-- An element `a` of a semigroup with a distributive negation divides the negation of an element `b` iff `a` divides `b`. -/ @[simp] theorem dvd_neg : a ∣ -b ↔ a ∣ b := (Equiv.neg _).exists_congr_left.trans <| by simp only [Equiv.neg_symm, Equiv.neg_apply, mul_neg, neg_inj, Dvd.dvd] /-- The negation of an element `a` of a semigroup with a distributive negation divides another element `b` iff `a` divides `b`. -/ @[simp] theorem neg_dvd : -a ∣ b ↔ a ∣ b := (Equiv.neg _).exists_congr_left.trans <| by simp only [Equiv.neg_symm, Equiv.neg_apply, mul_neg, neg_mul, neg_neg, Dvd.dvd] alias ⟨Dvd.dvd.of_neg_left, Dvd.dvd.neg_left⟩ := neg_dvd alias ⟨Dvd.dvd.of_neg_right, Dvd.dvd.neg_right⟩ := dvd_neg end Semigroup section NonUnitalRing variable [NonUnitalRing α] {a b c : α} theorem dvd_sub (h₁ : a ∣ b) (h₂ : a ∣ c) : a ∣ b - c := by simpa only [← sub_eq_add_neg] using h₁.add h₂.neg_right alias Dvd.dvd.sub := dvd_sub /-- If an element `a` divides another element `c` in a ring, `a` divides the sum of another element `b` with `c` iff `a` divides `b`. -/ theorem dvd_add_left (h : a ∣ c) : a ∣ b + c ↔ a ∣ b := ⟨fun H => by simpa only [add_sub_cancel_right] using dvd_sub H h, fun h₂ => dvd_add h₂ h⟩ /-- If an element `a` divides another element `b` in a ring, `a` divides the sum of `b` and another element `c` iff `a` divides `c`. -/ theorem dvd_add_right (h : a ∣ b) : a ∣ b + c ↔ a ∣ c := by rw [add_comm]; exact dvd_add_left h /-- If an element `a` divides another element `c` in a ring, `a` divides the difference of another element `b` with `c` iff `a` divides `b`. -/ theorem dvd_sub_left (h : a ∣ c) : a ∣ b - c ↔ a ∣ b := by simpa only [← sub_eq_add_neg] using dvd_add_left (dvd_neg.2 h) /-- If an element `a` divides another element `b` in a ring, `a` divides the difference of `b` and another element `c` iff `a` divides `c`. -/ theorem dvd_sub_right (h : a ∣ b) : a ∣ b - c ↔ a ∣ c := by rw [sub_eq_add_neg, dvd_add_right h, dvd_neg] theorem dvd_iff_dvd_of_dvd_sub (h : a ∣ b - c) : a ∣ b ↔ a ∣ c := by rw [← sub_add_cancel b c, dvd_add_right h] theorem dvd_sub_comm : a ∣ b - c ↔ a ∣ c - b := by rw [← dvd_neg, neg_sub] end NonUnitalRing section Ring
variable [Ring α] {a b : α}
Mathlib/Algebra/Ring/Divisibility/Basic.lean
146
147
/- Copyright (c) 2023 Luke Mantle. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Luke Mantle -/ import Mathlib.Algebra.Polynomial.Derivative import Mathlib.Data.Nat.Factorial.DoubleFactorial /-! # Hermite polynomials This file defines `Polynomial.hermite n`, the `n`th probabilists' Hermite polynomial. ## Main definitions * `Polynomial.hermite n`: the `n`th probabilists' Hermite polynomial, defined recursively as a `Polynomial ℤ` ## Results * `Polynomial.hermite_succ`: the recursion `hermite (n+1) = (x - d/dx) (hermite n)` * `Polynomial.coeff_hermite_explicit`: a closed formula for (nonvanishing) coefficients in terms of binomial coefficients and double factorials. * `Polynomial.coeff_hermite_of_odd_add`: for `n`,`k` where `n+k` is odd, `(hermite n).coeff k` is zero. * `Polynomial.coeff_hermite_of_even_add`: a closed formula for `(hermite n).coeff k` when `n+k` is even, equivalent to `Polynomial.coeff_hermite_explicit`. * `Polynomial.monic_hermite`: for all `n`, `hermite n` is monic. * `Polynomial.degree_hermite`: for all `n`, `hermite n` has degree `n`. ## References * [Hermite Polynomials](https://en.wikipedia.org/wiki/Hermite_polynomials) -/ noncomputable section open Polynomial namespace Polynomial /-- the probabilists' Hermite polynomials. -/ noncomputable def hermite : ℕ → Polynomial ℤ | 0 => 1 | n + 1 => X * hermite n - derivative (hermite n) /-- The recursion `hermite (n+1) = (x - d/dx) (hermite n)` -/ @[simp] theorem hermite_succ (n : ℕ) : hermite (n + 1) = X * hermite n - derivative (hermite n) := by rw [hermite] theorem hermite_eq_iterate (n : ℕ) : hermite n = (fun p => X * p - derivative p)^[n] 1 := by induction n with
| zero => rfl | succ n ih => rw [Function.iterate_succ_apply', ← ih, hermite_succ]
Mathlib/RingTheory/Polynomial/Hermite/Basic.lean
55
56
/- 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, Yaël Dillies -/ import Mathlib.Logic.Equiv.Set import Mathlib.Order.CompleteLattice.Lemmas import Mathlib.Order.Directed import Mathlib.Order.GaloisConnection.Basic /-! # Frames, completely distributive lattices and complete Boolean algebras In this file we define and provide API for (co)frames, completely distributive lattices and complete Boolean algebras. We distinguish two different distributivity properties: 1. `inf_iSup_eq : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i` (finite `⊓` distributes over infinite `⨆`). This is required by `Frame`, `CompleteDistribLattice`, and `CompleteBooleanAlgebra` (`Coframe`, etc., require the dual property). 2. `iInf_iSup_eq : (⨅ i, ⨆ j, f i j) = ⨆ s, ⨅ i, f i (s i)` (infinite `⨅` distributes over infinite `⨆`). This stronger property is called "completely distributive", and is required by `CompletelyDistribLattice` and `CompleteAtomicBooleanAlgebra`. ## Typeclasses * `Order.Frame`: Frame: A complete lattice whose `⊓` distributes over `⨆`. * `Order.Coframe`: Coframe: A complete lattice whose `⊔` distributes over `⨅`. * `CompleteDistribLattice`: Complete distributive lattices: A complete lattice whose `⊓` and `⊔` distribute over `⨆` and `⨅` respectively. * `CompleteBooleanAlgebra`: Complete Boolean algebra: A Boolean algebra whose `⊓` and `⊔` distribute over `⨆` and `⨅` respectively. * `CompletelyDistribLattice`: Completely distributive lattices: A complete lattice whose `⨅` and `⨆` satisfy `iInf_iSup_eq`. * `CompleteBooleanAlgebra`: Complete Boolean algebra: A Boolean algebra whose `⊓` and `⊔` distribute over `⨆` and `⨅` respectively. * `CompleteAtomicBooleanAlgebra`: Complete atomic Boolean algebra: A complete Boolean algebra which is additionally completely distributive. (This implies that it's (co)atom(ist)ic.) A set of opens gives rise to a topological space precisely if it forms a frame. Such a frame is also completely distributive, but not all frames are. `Filter` is a coframe but not a completely distributive lattice. ## References * [Wikipedia, *Complete Heyting algebra*](https://en.wikipedia.org/wiki/Complete_Heyting_algebra) * [Francis Borceux, *Handbook of Categorical Algebra III*][borceux-vol3] -/ open Function Set universe u v w w' variable {α : Type u} {β : Type v} {ι : Sort w} {κ : ι → Sort w'} /-- Structure containing the minimal axioms required to check that an order is a frame. Do NOT use, except for implementing `Order.Frame` via `Order.Frame.ofMinimalAxioms`. This structure omits the `himp`, `compl` fields, which can be recovered using `Order.Frame.ofMinimalAxioms`. -/ class Order.Frame.MinimalAxioms (α : Type u) extends CompleteLattice α where inf_sSup_le_iSup_inf (a : α) (s : Set α) : a ⊓ sSup s ≤ ⨆ b ∈ s, a ⊓ b /-- Structure containing the minimal axioms required to check that an order is a coframe. Do NOT use, except for implementing `Order.Coframe` via `Order.Coframe.ofMinimalAxioms`. This structure omits the `sdiff`, `hnot` fields, which can be recovered using `Order.Coframe.ofMinimalAxioms`. -/ class Order.Coframe.MinimalAxioms (α : Type u) extends CompleteLattice α where iInf_sup_le_sup_sInf (a : α) (s : Set α) : ⨅ b ∈ s, a ⊔ b ≤ a ⊔ sInf s /-- A frame, aka complete Heyting algebra, is a complete lattice whose `⊓` distributes over `⨆`. -/ class Order.Frame (α : Type*) extends CompleteLattice α, HeytingAlgebra α where /-- `⊓` distributes over `⨆`. -/ theorem inf_sSup_eq {α : Type*} [Order.Frame α] {s : Set α} {a : α} : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b := gc_inf_himp.l_sSup /-- A coframe, aka complete Brouwer algebra or complete co-Heyting algebra, is a complete lattice whose `⊔` distributes over `⨅`. -/ class Order.Coframe (α : Type*) extends CompleteLattice α, CoheytingAlgebra α where /-- `⊔` distributes over `⨅`. -/ theorem sup_sInf_eq {α : Type*} [Order.Coframe α] {s : Set α} {a : α} : a ⊔ sInf s = ⨅ b ∈ s, a ⊔ b := gc_sdiff_sup.u_sInf open Order /-- Structure containing the minimal axioms required to check that an order is a complete distributive lattice. Do NOT use, except for implementing `CompleteDistribLattice` via `CompleteDistribLattice.ofMinimalAxioms`. This structure omits the `himp`, `compl`, `sdiff`, `hnot` fields, which can be recovered using `CompleteDistribLattice.ofMinimalAxioms`. -/ structure CompleteDistribLattice.MinimalAxioms (α : Type u) extends CompleteLattice α, toFrameMinimalAxioms : Frame.MinimalAxioms α, toCoframeMinimalAxioms : Coframe.MinimalAxioms α where -- We give those projections better name further down attribute [nolint docBlame] CompleteDistribLattice.MinimalAxioms.toFrameMinimalAxioms CompleteDistribLattice.MinimalAxioms.toCoframeMinimalAxioms /-- A complete distributive lattice is a complete lattice whose `⊔` and `⊓` respectively distribute over `⨅` and `⨆`. -/ class CompleteDistribLattice (α : Type*) extends Frame α, Coframe α, BiheytingAlgebra α /-- Structure containing the minimal axioms required to check that an order is a completely distributive. Do NOT use, except for implementing `CompletelyDistribLattice` via `CompletelyDistribLattice.ofMinimalAxioms`. This structure omits the `himp`, `compl`, `sdiff`, `hnot` fields, which can be recovered using `CompletelyDistribLattice.ofMinimalAxioms`. -/ structure CompletelyDistribLattice.MinimalAxioms (α : Type u) extends CompleteLattice α where protected iInf_iSup_eq {ι : Type u} {κ : ι → Type u} (f : ∀ a, κ a → α) : (⨅ a, ⨆ b, f a b) = ⨆ g : ∀ a, κ a, ⨅ a, f a (g a) /-- A completely distributive lattice is a complete lattice whose `⨅` and `⨆` distribute over each other. -/ class CompletelyDistribLattice (α : Type u) extends CompleteLattice α, BiheytingAlgebra α where protected iInf_iSup_eq {ι : Type u} {κ : ι → Type u} (f : ∀ a, κ a → α) : (⨅ a, ⨆ b, f a b) = ⨆ g : ∀ a, κ a, ⨅ a, f a (g a) theorem le_iInf_iSup [CompleteLattice α] {f : ∀ a, κ a → α} : (⨆ g : ∀ a, κ a, ⨅ a, f a (g a)) ≤ ⨅ a, ⨆ b, f a b := iSup_le fun _ => le_iInf fun a => le_trans (iInf_le _ a) (le_iSup _ _) lemma iSup_iInf_le [CompleteLattice α] {f : ∀ a, κ a → α} : ⨆ a, ⨅ b, f a b ≤ ⨅ g : ∀ a, κ a, ⨆ a, f a (g a) := le_iInf_iSup (α := αᵒᵈ) namespace Order.Frame.MinimalAxioms variable (minAx : MinimalAxioms α) {s : Set α} {a b : α} lemma inf_sSup_eq : a ⊓ sSup s = ⨆ b ∈ s, a ⊓ b := (minAx.inf_sSup_le_iSup_inf _ _).antisymm iSup_inf_le_inf_sSup lemma sSup_inf_eq : sSup s ⊓ b = ⨆ a ∈ s, a ⊓ b := by simpa only [inf_comm] using @inf_sSup_eq α _ s b lemma iSup_inf_eq (f : ι → α) (a : α) : (⨆ i, f i) ⊓ a = ⨆ i, f i ⊓ a := by rw [iSup, sSup_inf_eq, iSup_range] lemma inf_iSup_eq (a : α) (f : ι → α) : (a ⊓ ⨆ i, f i) = ⨆ i, a ⊓ f i := by simpa only [inf_comm] using minAx.iSup_inf_eq f a lemma inf_iSup₂_eq {f : ∀ i, κ i → α} (a : α) : (a ⊓ ⨆ i, ⨆ j, f i j) = ⨆ i, ⨆ j, a ⊓ f i j := by simp only [inf_iSup_eq] /-- The `Order.Frame.MinimalAxioms` element corresponding to a frame. -/ def of [Frame α] : MinimalAxioms α where __ := ‹Frame α› inf_sSup_le_iSup_inf a s := _root_.inf_sSup_eq.le end MinimalAxioms /-- Construct a frame instance using the minimal amount of work needed. This sets `a ⇨ b := sSup {c | c ⊓ a ≤ b}` and `aᶜ := a ⇨ ⊥`. -/ -- See note [reducible non instances] abbrev ofMinimalAxioms (minAx : MinimalAxioms α) : Frame α where __ := minAx compl a := sSup {c | c ⊓ a ≤ ⊥} himp a b := sSup {c | c ⊓ a ≤ b} le_himp_iff _ b c := ⟨fun h ↦ (inf_le_inf_right _ h).trans (by simp [minAx.sSup_inf_eq]), fun h ↦ le_sSup h⟩ himp_bot _ := rfl end Order.Frame namespace Order.Coframe.MinimalAxioms variable (minAx : MinimalAxioms α) {s : Set α} {a b : α} lemma sup_sInf_eq : a ⊔ sInf s = ⨅ b ∈ s, a ⊔ b := sup_sInf_le_iInf_sup.antisymm (minAx.iInf_sup_le_sup_sInf _ _) lemma sInf_sup_eq : sInf s ⊔ b = ⨅ a ∈ s, a ⊔ b := by simpa only [sup_comm] using @sup_sInf_eq α _ s b lemma iInf_sup_eq (f : ι → α) (a : α) : (⨅ i, f i) ⊔ a = ⨅ i, f i ⊔ a := by rw [iInf, sInf_sup_eq, iInf_range] lemma sup_iInf_eq (a : α) (f : ι → α) : (a ⊔ ⨅ i, f i) = ⨅ i, a ⊔ f i := by simpa only [sup_comm] using minAx.iInf_sup_eq f a lemma sup_iInf₂_eq {f : ∀ i, κ i → α} (a : α) : (a ⊔ ⨅ i, ⨅ j, f i j) = ⨅ i, ⨅ j, a ⊔ f i j := by simp only [sup_iInf_eq] /-- The `Order.Coframe.MinimalAxioms` element corresponding to a frame. -/ def of [Coframe α] : MinimalAxioms α where __ := ‹Coframe α› iInf_sup_le_sup_sInf a s := _root_.sup_sInf_eq.ge end MinimalAxioms /-- Construct a coframe instance using the minimal amount of work needed.
This sets `a \ b := sInf {c | a ≤ b ⊔ c}` and `¬a := ⊤ \ a`. -/ -- See note [reducible non instances] abbrev ofMinimalAxioms (minAx : MinimalAxioms α) : Coframe α where
Mathlib/Order/CompleteBooleanAlgebra.lean
202
204
/- 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]
Mathlib/Algebra/QuaternionBasis.lean
84
85
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.Homology import Mathlib.CategoryTheory.Abelian.Basic /-! # Abelian categories have homology In this file, it is shown that all short complexes `S` in abelian categories have terms of type `S.HomologyData`. The strategy of the proof is to study the morphism `kernel.ι S.g ≫ cokernel.π S.f`. We show that there is a `LeftHomologyData` for `S` for which the `H` field consists of the coimage of `kernel.ι S.g ≫ cokernel.π S.f`, while there is a `RightHomologyData` for which the `H` is the image of `kernel.ι S.g ≫ cokernel.π S.f`. The fact that these left and right homology data are compatible (i.e. provide a `HomologyData`) is obtained by using the coimage-image isomorphism in abelian categories. -/ universe v u namespace CategoryTheory open Category Limits variable {C : Type u} [Category.{v} C] [Abelian C] (S : ShortComplex C) namespace ShortComplex /-- The canonical morphism `Abelian.image S.f ⟶ kernel S.g` for a short complex `S` in an abelian category. -/ noncomputable def abelianImageToKernel : Abelian.image S.f ⟶ kernel S.g := kernel.lift S.g (Abelian.image.ι S.f) (by simp only [← cancel_epi (Abelian.factorThruImage S.f), kernel.lift_ι_assoc, zero, comp_zero]) @[reassoc (attr := simp)] lemma abelianImageToKernel_comp_kernel_ι : S.abelianImageToKernel ≫ kernel.ι S.g = Abelian.image.ι S.f := kernel.lift_ι _ _ _ instance : Mono S.abelianImageToKernel := mono_of_mono_fac S.abelianImageToKernel_comp_kernel_ι @[reassoc]
lemma abelianImageToKernel_comp_kernel_ι_comp_cokernel_π : S.abelianImageToKernel ≫ kernel.ι S.g ≫ cokernel.π S.f = 0 := by simp
Mathlib/Algebra/Homology/ShortComplex/Abelian.lean
54
57
/- 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.Combinatorics.Enumerative.Composition import Mathlib.Tactic.ApplyFun /-! # Partitions A partition of a natural number `n` is a way of writing `n` as a sum of positive integers, where the order does not matter: two sums that differ only in the order of their summands are considered the same partition. This notion is closely related to that of a composition of `n`, but in a composition of `n` the order does matter. A summand of the partition is called a part. ## Main functions * `p : Partition n` is a structure, made of a multiset of integers which are all positive and add up to `n`. ## Implementation details The main motivation for this structure and its API is to show Euler's partition theorem, and related results. The representation of a partition as a multiset is very handy as multisets are very flexible and already have a well-developed API. ## TODO Link this to Young diagrams. ## Tags Partition ## References <https://en.wikipedia.org/wiki/Partition_(number_theory)> -/ assert_not_exists Field open Multiset namespace Nat /-- A partition of `n` is a multiset of positive integers summing to `n`. -/ @[ext] structure Partition (n : ℕ) where /-- positive integers summing to `n` -/ parts : Multiset ℕ /-- proof that the `parts` are positive -/ parts_pos : ∀ {i}, i ∈ parts → 0 < i /-- proof that the `parts` sum to `n` -/ parts_sum : parts.sum = n deriving DecidableEq namespace Partition @[deprecated "Partition now derives an instance of DecidableEq." (since := "2024-12-28")] instance decidableEqPartition {n : ℕ} : DecidableEq (Partition n) := fun _ _ => decidable_of_iff' _ Partition.ext_iff /-- A composition induces a partition (just convert the list to a multiset). -/ @[simps] def ofComposition (n : ℕ) (c : Composition n) : Partition n where parts := c.blocks parts_pos hi := c.blocks_pos hi parts_sum := by rw [Multiset.sum_coe, c.blocks_sum] theorem ofComposition_surj {n : ℕ} : Function.Surjective (ofComposition n) := by rintro ⟨b, hb₁, hb₂⟩ induction b using Quotient.inductionOn with | _ b => ?_ exact ⟨⟨b, hb₁, by simpa using hb₂⟩, Partition.ext rfl⟩ -- The argument `n` is kept explicit here since it is useful in tactic mode proofs to generate the -- proof obligation `l.sum = n`. /-- Given a multiset which sums to `n`, construct a partition of `n` with the same multiset, but without the zeros. -/ @[simps] def ofSums (n : ℕ) (l : Multiset ℕ) (hl : l.sum = n) : Partition n where parts := l.filter (· ≠ 0) parts_pos hi := (of_mem_filter hi).bot_lt parts_sum := by have lz : (l.filter (· = 0)).sum = 0 := by simp [sum_eq_zero_iff] rwa [← filter_add_not (· = 0) l, sum_add, lz, zero_add] at hl /-- A `Multiset ℕ` induces a partition on its sum. -/ @[simps!] def ofMultiset (l : Multiset ℕ) : Partition l.sum := ofSums _ l rfl /-- An element `s` of `Sym σ n` induces a partition given by its multiplicities. -/ def ofSym {n : ℕ} {σ : Type*} (s : Sym σ n) [DecidableEq σ] : n.Partition where parts := s.1.dedup.map s.1.count parts_pos := by simp [Multiset.count_pos] parts_sum := by show ∑ a ∈ s.1.toFinset, count a s.1 = n rw [toFinset_sum_count_eq] exact s.2 variable {n : ℕ} {σ τ : Type*} [DecidableEq σ] [DecidableEq τ] @[simp] lemma ofSym_map (e : σ ≃ τ) (s : Sym σ n) :
ofSym (s.map e) = ofSym s := by simp only [ofSym, Sym.val_eq_coe, Sym.coe_map, toFinset_val, mk.injEq]
Mathlib/Combinatorics/Enumerative/Partition.lean
108
109
/- Copyright (c) 2024 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Rémy Degenne -/ import Mathlib.Data.Set.Finite.Lattice /-! # Partitions based on membership of a sequence of sets Let `f : ℕ → Set α` be a sequence of sets. For `n : ℕ`, we can form the set of points that are in `f 0 ∪ f 1 ∪ ... ∪ f (n-1)`; then the set of points in `(f 0)ᶜ ∪ f 1 ∪ ... ∪ f (n-1)` and so on for all 2^n choices of a set or its complement. The at most 2^n sets we obtain form a partition of `univ : Set α`. We call that partition `memPartition f n` (the membership partition of `f`). For `n = 0` we set `memPartition f 0 = {univ}`. The partition `memPartition f (n + 1)` is finer than `memPartition f n`. ## Main definitions * `memPartition f n`: the membership partition of the first `n` sets in `f`. * `memPartitionSet`: `memPartitionSet f n x` is the set in the partition `memPartition f n` to which `x` belongs. ## Main statements * `disjoint_memPartition`: the sets in `memPartition f n` are disjoint * `sUnion_memPartition`: the union of the sets in `memPartition f n` is `univ` * `finite_memPartition`: `memPartition f n` is finite -/ open Set variable {α : Type*} /-- `memPartition f n` is the partition containing at most `2^(n+1)` sets, where each set contains the points that for all `i` belong to one of `f i` or its complement. -/ def memPartition (f : ℕ → Set α) : ℕ → Set (Set α) | 0 => {univ} | n + 1 => {s | ∃ u ∈ memPartition f n, s = u ∩ f n ∨ s = u \ f n} @[simp] lemma memPartition_zero (f : ℕ → Set α) : memPartition f 0 = {univ} := rfl lemma memPartition_succ (f : ℕ → Set α) (n : ℕ) : memPartition f (n + 1) = {s | ∃ u ∈ memPartition f n, s = u ∩ f n ∨ s = u \ f n} := rfl lemma disjoint_memPartition (f : ℕ → Set α) (n : ℕ) {u v : Set α} (hu : u ∈ memPartition f n) (hv : v ∈ memPartition f n) (huv : u ≠ v) : Disjoint u v := by revert u v induction n with | zero => intro u v hu hv huv simp only [memPartition_zero, mem_insert_iff, mem_singleton_iff] at hu hv rw [hu, hv] at huv exact absurd rfl huv | succ n ih => intro u v hu hv huv rw [memPartition_succ] at hu hv obtain ⟨u', hu', hu'_eq⟩ := hu obtain ⟨v', hv', hv'_eq⟩ := hv rcases hu'_eq with rfl | rfl <;> rcases hv'_eq with rfl | rfl · refine Disjoint.mono inter_subset_left inter_subset_left (ih hu' hv' ?_) exact fun huv' ↦ huv (huv' ▸ rfl) · exact Disjoint.mono_left inter_subset_right Set.disjoint_sdiff_right · exact Disjoint.mono_right inter_subset_right Set.disjoint_sdiff_left · refine Disjoint.mono diff_subset diff_subset (ih hu' hv' ?_) exact fun huv' ↦ huv (huv' ▸ rfl) @[simp] lemma sUnion_memPartition (f : ℕ → Set α) (n : ℕ) : ⋃₀ memPartition f n = univ := by induction n with | zero => simp | succ n ih => rw [memPartition_succ] ext x have : x ∈ ⋃₀ memPartition f n := by simp [ih] simp only [mem_sUnion, mem_iUnion, mem_insert_iff, mem_singleton_iff, exists_prop, mem_univ, iff_true] at this ⊢ obtain ⟨t, ht, hxt⟩ := this by_cases hxf : x ∈ f n · exact ⟨t ∩ f n, ⟨t, ht, Or.inl rfl⟩, hxt, hxf⟩ · exact ⟨t \ f n, ⟨t, ht, Or.inr rfl⟩, hxt, hxf⟩ lemma finite_memPartition (f : ℕ → Set α) (n : ℕ) : Set.Finite (memPartition f n) := by induction n with | zero => simp | succ n ih => rw [memPartition_succ] have : Finite (memPartition f n) := Set.finite_coe_iff.mp ih rw [← Set.finite_coe_iff] simp_rw [setOf_exists, ← exists_prop, setOf_exists, setOf_or] refine Finite.Set.finite_biUnion (memPartition f n) _ (fun u _ ↦ ?_) rw [Set.finite_coe_iff] simp instance instFinite_memPartition (f : ℕ → Set α) (n : ℕ) : Finite (memPartition f n) := Set.finite_coe_iff.mp (finite_memPartition _ _) noncomputable instance instFintype_memPartition (f : ℕ → Set α) (n : ℕ) : Fintype (memPartition f n) := (finite_memPartition f n).fintype open Classical in /-- The set in `memPartition f n` to which `a : α` belongs. -/ def memPartitionSet (f : ℕ → Set α) : ℕ → α → Set α | 0 => fun _ ↦ univ | n + 1 => fun a ↦ if a ∈ f n then memPartitionSet f n a ∩ f n else memPartitionSet f n a \ f n @[simp] lemma memPartitionSet_zero (f : ℕ → Set α) (a : α) : memPartitionSet f 0 a = univ := by simp [memPartitionSet] lemma memPartitionSet_succ (f : ℕ → Set α) (n : ℕ) (a : α) [Decidable (a ∈ f n)] : memPartitionSet f (n + 1) a = if a ∈ f n then memPartitionSet f n a ∩ f n else memPartitionSet f n a \ f n := by simp [memPartitionSet] lemma memPartitionSet_mem (f : ℕ → Set α) (n : ℕ) (a : α) : memPartitionSet f n a ∈ memPartition f n := by induction n with | zero => simp [memPartitionSet] | succ n ih => classical rw [memPartitionSet_succ, memPartition_succ] refine ⟨memPartitionSet f n a, ?_⟩ split_ifs <;> simp [ih] lemma mem_memPartitionSet (f : ℕ → Set α) (n : ℕ) (a : α) : a ∈ memPartitionSet f n a := by
induction n with | zero => simp [memPartitionSet] | succ n ih => classical rw [memPartitionSet_succ] split_ifs with h <;> exact ⟨ih, h⟩
Mathlib/Data/Set/MemPartition.lean
133
139
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.Algebra.Polynomial.FieldDivision import Mathlib.Algebra.Polynomial.Lifts import Mathlib.Data.List.Prime import Mathlib.RingTheory.Polynomial.Tower /-! # Split polynomials A polynomial `f : K[X]` splits over a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have degree `1`. ## Main definitions * `Polynomial.Splits i f`: A predicate on a homomorphism `i : K →+* L` from a commutative ring to a field and a polynomial `f` saying that `f.map i` is zero or all of its irreducible factors over `L` have degree `1`. -/ noncomputable section open Polynomial universe u v w variable {R : Type*} {F : Type u} {K : Type v} {L : Type w} namespace Polynomial section Splits section CommRing variable [CommRing K] [Field L] [Field F] variable (i : K →+* L) /-- A polynomial `Splits` iff it is zero or all of its irreducible factors have `degree` 1. -/ def Splits (f : K[X]) : Prop := f.map i = 0 ∨ ∀ {g : L[X]}, Irreducible g → g ∣ f.map i → degree g = 1 @[simp] theorem splits_zero : Splits i (0 : K[X]) := Or.inl (Polynomial.map_zero i) theorem splits_of_map_eq_C {f : K[X]} {a : L} (h : f.map i = C a) : Splits i f := letI := Classical.decEq L if ha : a = 0 then Or.inl (h.trans (ha.symm ▸ C_0)) else Or.inr fun hg ⟨p, hp⟩ => absurd hg.1 <| Classical.not_not.2 <| isUnit_iff_degree_eq_zero.2 <| by have := congr_arg degree hp rw [h, degree_C ha, degree_mul, @eq_comm (WithBot ℕ) 0, Nat.WithBot.add_eq_zero_iff] at this exact this.1 @[simp] theorem splits_C (a : K) : Splits i (C a) := splits_of_map_eq_C i (map_C i) theorem splits_of_map_degree_eq_one {f : K[X]} (hf : degree (f.map i) = 1) : Splits i f := Or.inr fun hg ⟨p, hp⟩ => by have := congr_arg degree hp simp [Nat.WithBot.add_eq_one_iff, hf, @eq_comm (WithBot ℕ) 1, mt isUnit_iff_degree_eq_zero.2 hg.1] at this tauto theorem splits_of_degree_le_one {f : K[X]} (hf : degree f ≤ 1) : Splits i f := if hif : degree (f.map i) ≤ 0 then splits_of_map_eq_C i (degree_le_zero_iff.mp hif) else by push_neg at hif rw [← Order.succ_le_iff, ← WithBot.coe_zero, WithBot.orderSucc_coe, Nat.succ_eq_succ] at hif exact splits_of_map_degree_eq_one i ((degree_map_le.trans hf).antisymm hif) theorem splits_of_degree_eq_one {f : K[X]} (hf : degree f = 1) : Splits i f := splits_of_degree_le_one i hf.le theorem splits_of_natDegree_le_one {f : K[X]} (hf : natDegree f ≤ 1) : Splits i f := splits_of_degree_le_one i (degree_le_of_natDegree_le hf) theorem splits_of_natDegree_eq_one {f : K[X]} (hf : natDegree f = 1) : Splits i f := splits_of_natDegree_le_one i (le_of_eq hf) theorem splits_mul {f g : K[X]} (hf : Splits i f) (hg : Splits i g) : Splits i (f * g) := letI := Classical.decEq L if h : (f * g).map i = 0 then Or.inl h else Or.inr @fun p hp hpf => ((irreducible_iff_prime.1 hp).2.2 _ _ (show p ∣ map i f * map i g by convert hpf; rw [Polynomial.map_mul])).elim (hf.resolve_left (fun hf => by simp [hf] at h) hp) (hg.resolve_left (fun hg => by simp [hg] at h) hp) theorem splits_of_splits_mul' {f g : K[X]} (hfg : (f * g).map i ≠ 0) (h : Splits i (f * g)) : Splits i f ∧ Splits i g := ⟨Or.inr @fun g hgi hg => Or.resolve_left h hfg hgi (by rw [Polynomial.map_mul]; exact hg.trans (dvd_mul_right _ _)), Or.inr @fun g hgi hg => Or.resolve_left h hfg hgi (by rw [Polynomial.map_mul]; exact hg.trans (dvd_mul_left _ _))⟩ theorem splits_map_iff (j : L →+* F) {f : K[X]} : Splits j (f.map i) ↔ Splits (j.comp i) f := by simp [Splits, Polynomial.map_map] theorem splits_one : Splits i 1 := splits_C i 1 theorem splits_of_isUnit [IsDomain K] {u : K[X]} (hu : IsUnit u) : u.Splits i := (isUnit_iff.mp hu).choose_spec.2 ▸ splits_C _ _ theorem splits_X_sub_C {x : K} : (X - C x).Splits i := splits_of_degree_le_one _ <| degree_X_sub_C_le _ theorem splits_X : X.Splits i := splits_of_degree_le_one _ degree_X_le theorem splits_prod {ι : Type u} {s : ι → K[X]} {t : Finset ι} : (∀ j ∈ t, (s j).Splits i) → (∏ x ∈ t, s x).Splits i := by classical refine Finset.induction_on t (fun _ => splits_one i) fun a t hat ih ht => ?_ rw [Finset.forall_mem_insert] at ht; rw [Finset.prod_insert hat] exact splits_mul i ht.1 (ih ht.2) theorem splits_pow {f : K[X]} (hf : f.Splits i) (n : ℕ) : (f ^ n).Splits i := by rw [← Finset.card_range n, ← Finset.prod_const] exact splits_prod i fun j _ => hf theorem splits_X_pow (n : ℕ) : (X ^ n).Splits i := splits_pow i (splits_X i) n theorem splits_id_iff_splits {f : K[X]} : (f.map i).Splits (RingHom.id L) ↔ f.Splits i := by rw [splits_map_iff, RingHom.id_comp] variable {i} theorem Splits.comp_of_map_degree_le_one {f : K[X]} {p : K[X]} (hd : (p.map i).degree ≤ 1) (h : f.Splits i) : (f.comp p).Splits i := by by_cases hzero : map i (f.comp p) = 0 · exact Or.inl hzero cases h with | inl h0 => exact Or.inl <| map_comp i _ _ ▸ h0.symm ▸ zero_comp | inr h => right intro g irr dvd rw [map_comp] at dvd hzero cases lt_or_eq_of_le hd with | inl hd => rw [eq_C_of_degree_le_zero (Nat.WithBot.lt_one_iff_le_zero.mp hd), comp_C] at dvd hzero refine False.elim (irr.1 (isUnit_of_dvd_unit dvd ?_)) simpa using hzero | inr hd => let _ := invertibleOfNonzero (leadingCoeff_ne_zero.mpr (ne_zero_of_degree_gt (n := ⊥) (by rw [hd]; decide))) rw [eq_X_add_C_of_degree_eq_one hd, dvd_comp_C_mul_X_add_C_iff _ _] at dvd have := h (irr.map (algEquivCMulXAddC _ _).symm) dvd rw [degree_eq_natDegree irr.ne_zero]
rwa [algEquivCMulXAddC_symm_apply, ← comp_eq_aeval, degree_eq_natDegree (fun h => WithBot.bot_ne_one (h ▸ this)),
Mathlib/Algebra/Polynomial/Splits.lean
164
165
/- Copyright (c) 2017 Johannes Hölzl. 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.Algebra.GroupWithZero.Divisibility import Mathlib.Data.Nat.SuccPred import Mathlib.Order.SuccPred.InitialSeg import Mathlib.SetTheory.Ordinal.Basic /-! # Ordinal arithmetic Ordinals have an addition (corresponding to disjoint union) that turns them into an additive monoid, and a multiplication (corresponding to the lexicographic order on the product) that turns them into a monoid. One can also define correspondingly a subtraction, a division, a successor function, a power function and a logarithm function. We also define limit ordinals and prove the basic induction principle on ordinals separating successor ordinals and limit ordinals, in `limitRecOn`. ## Main definitions and results * `o₁ + o₂` is the order on the disjoint union of `o₁` and `o₂` obtained by declaring that every element of `o₁` is smaller than every element of `o₂`. * `o₁ - o₂` is the unique ordinal `o` such that `o₂ + o = o₁`, when `o₂ ≤ o₁`. * `o₁ * o₂` is the lexicographic order on `o₂ × o₁`. * `o₁ / o₂` is the ordinal `o` such that `o₁ = o₂ * o + o'` with `o' < o₂`. We also define the divisibility predicate, and a modulo operation. * `Order.succ o = o + 1` is the successor of `o`. * `pred o` if the predecessor of `o`. If `o` is not a successor, we set `pred o = o`. We discuss the properties of casts of natural numbers of and of `ω` with respect to these operations. Some properties of the operations are also used to discuss general tools on ordinals: * `IsLimit o`: an ordinal is a limit ordinal if it is neither `0` nor a successor. * `limitRecOn` is the main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. * `IsNormal`: a function `f : Ordinal → Ordinal` satisfies `IsNormal` if it is strictly increasing and order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. Various other basic arithmetic results are given in `Principal.lean` instead. -/ assert_not_exists Field Module noncomputable section open Function Cardinal Set Equiv Order open scoped Ordinal universe u v w namespace Ordinal variable {α β γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} /-! ### Further properties of addition on ordinals -/ @[simp] theorem lift_add (a b : Ordinal.{v}) : lift.{u} (a + b) = lift.{u} a + lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.sumLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ @[simp] theorem lift_succ (a : Ordinal.{v}) : lift.{u} (succ a) = succ (lift.{u} a) := by rw [← add_one_eq_succ, lift_add, lift_one] rfl instance instAddLeftReflectLE : AddLeftReflectLE Ordinal.{u} where elim c a b := by refine inductionOn₃ a b c fun α r _ β s _ γ t _ ⟨f⟩ ↦ ?_ have H₁ a : f (Sum.inl a) = Sum.inl a := by simpa using ((InitialSeg.leAdd t r).trans f).eq (InitialSeg.leAdd t s) a have H₂ a : ∃ b, f (Sum.inr a) = Sum.inr b := by generalize hx : f (Sum.inr a) = x obtain x | x := x · rw [← H₁, f.inj] at hx contradiction · exact ⟨x, rfl⟩ choose g hg using H₂ refine (RelEmbedding.ofMonotone g fun _ _ h ↦ ?_).ordinal_type_le rwa [← @Sum.lex_inr_inr _ t _ s, ← hg, ← hg, f.map_rel_iff, Sum.lex_inr_inr] instance : IsLeftCancelAdd Ordinal where add_left_cancel a b c h := by simpa only [le_antisymm_iff, add_le_add_iff_left] using h @[deprecated add_left_cancel_iff (since := "2024-12-11")] protected theorem add_left_cancel (a) {b c : Ordinal} : a + b = a + c ↔ b = c := add_left_cancel_iff private theorem add_lt_add_iff_left' (a) {b c : Ordinal} : a + b < a + c ↔ b < c := by rw [← not_le, ← not_le, add_le_add_iff_left] instance instAddLeftStrictMono : AddLeftStrictMono Ordinal.{u} := ⟨fun a _b _c ↦ (add_lt_add_iff_left' a).2⟩ instance instAddLeftReflectLT : AddLeftReflectLT Ordinal.{u} := ⟨fun a _b _c ↦ (add_lt_add_iff_left' a).1⟩ instance instAddRightReflectLT : AddRightReflectLT Ordinal.{u} := ⟨fun _a _b _c ↦ lt_imp_lt_of_le_imp_le fun h => add_le_add_right h _⟩ theorem add_le_add_iff_right {a b : Ordinal} : ∀ n : ℕ, a + n ≤ b + n ↔ a ≤ b | 0 => by simp | n + 1 => by simp only [natCast_succ, add_succ, add_succ, succ_le_succ_iff, add_le_add_iff_right] theorem add_right_cancel {a b : Ordinal} (n : ℕ) : a + n = b + n ↔ a = b := by simp only [le_antisymm_iff, add_le_add_iff_right] theorem add_eq_zero_iff {a b : Ordinal} : a + b = 0 ↔ a = 0 ∧ b = 0 := inductionOn₂ a b fun α r _ β s _ => by simp_rw [← type_sum_lex, type_eq_zero_iff_isEmpty] exact isEmpty_sum theorem left_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : a = 0 := (add_eq_zero_iff.1 h).1 theorem right_eq_zero_of_add_eq_zero {a b : Ordinal} (h : a + b = 0) : b = 0 := (add_eq_zero_iff.1 h).2 /-! ### The predecessor of an ordinal -/ open Classical in /-- The ordinal predecessor of `o` is `o'` if `o = succ o'`, and `o` otherwise. -/ def pred (o : Ordinal) : Ordinal := if h : ∃ a, o = succ a then Classical.choose h else o @[simp] theorem pred_succ (o) : pred (succ o) = o := by have h : ∃ a, succ o = succ a := ⟨_, rfl⟩ simpa only [pred, dif_pos h] using (succ_injective <| Classical.choose_spec h).symm theorem pred_le_self (o) : pred o ≤ o := by classical exact if h : ∃ a, o = succ a then by let ⟨a, e⟩ := h rw [e, pred_succ]; exact le_succ a else by rw [pred, dif_neg h] theorem pred_eq_iff_not_succ {o} : pred o = o ↔ ¬∃ a, o = succ a := ⟨fun e ⟨a, e'⟩ => by rw [e', pred_succ] at e; exact (lt_succ a).ne e, fun h => dif_neg h⟩ theorem pred_eq_iff_not_succ' {o} : pred o = o ↔ ∀ a, o ≠ succ a := by simpa using pred_eq_iff_not_succ theorem pred_lt_iff_is_succ {o} : pred o < o ↔ ∃ a, o = succ a := Iff.trans (by simp only [le_antisymm_iff, pred_le_self, true_and, not_le]) (iff_not_comm.1 pred_eq_iff_not_succ).symm @[simp] theorem pred_zero : pred 0 = 0 := pred_eq_iff_not_succ'.2 fun a => (succ_ne_zero a).symm theorem succ_pred_iff_is_succ {o} : succ (pred o) = o ↔ ∃ a, o = succ a := ⟨fun e => ⟨_, e.symm⟩, fun ⟨a, e⟩ => by simp only [e, pred_succ]⟩ theorem succ_lt_of_not_succ {o b : Ordinal} (h : ¬∃ a, o = succ a) : succ b < o ↔ b < o := ⟨(lt_succ b).trans, fun l => lt_of_le_of_ne (succ_le_of_lt l) fun e => h ⟨_, e.symm⟩⟩ theorem lt_pred {a b} : a < pred b ↔ succ a < b := by classical exact if h : ∃ a, b = succ a then by let ⟨c, e⟩ := h rw [e, pred_succ, succ_lt_succ_iff] else by simp only [pred, dif_neg h, succ_lt_of_not_succ h] theorem pred_le {a b} : pred a ≤ b ↔ a ≤ succ b := le_iff_le_iff_lt_iff_lt.2 lt_pred @[simp] theorem lift_is_succ {o : Ordinal.{v}} : (∃ a, lift.{u} o = succ a) ↔ ∃ a, o = succ a := ⟨fun ⟨a, h⟩ => let ⟨b, e⟩ := mem_range_lift_of_le <| show a ≤ lift.{u} o from le_of_lt <| h.symm ▸ lt_succ a ⟨b, (lift_inj.{u,v}).1 <| by rw [h, ← e, lift_succ]⟩, fun ⟨a, h⟩ => ⟨lift.{u} a, by simp only [h, lift_succ]⟩⟩ @[simp] theorem lift_pred (o : Ordinal.{v}) : lift.{u} (pred o) = pred (lift.{u} o) := by classical exact if h : ∃ a, o = succ a then by obtain ⟨a, e⟩ := h; simp only [e, pred_succ, lift_succ] else by rw [pred_eq_iff_not_succ.2 h, pred_eq_iff_not_succ.2 (mt lift_is_succ.1 h)] /-! ### Limit ordinals -/ /-- A limit ordinal is an ordinal which is not zero and not a successor. TODO: deprecate this in favor of `Order.IsSuccLimit`. -/ def IsLimit (o : Ordinal) : Prop := IsSuccLimit o theorem isLimit_iff {o} : IsLimit o ↔ o ≠ 0 ∧ IsSuccPrelimit o := by simp [IsLimit, IsSuccLimit] theorem IsLimit.isSuccPrelimit {o} (h : IsLimit o) : IsSuccPrelimit o := IsSuccLimit.isSuccPrelimit h theorem IsLimit.succ_lt {o a : Ordinal} (h : IsLimit o) : a < o → succ a < o := IsSuccLimit.succ_lt h theorem isSuccPrelimit_zero : IsSuccPrelimit (0 : Ordinal) := isSuccPrelimit_bot theorem not_zero_isLimit : ¬IsLimit 0 := not_isSuccLimit_bot theorem not_succ_isLimit (o) : ¬IsLimit (succ o) := not_isSuccLimit_succ o theorem not_succ_of_isLimit {o} (h : IsLimit o) : ¬∃ a, o = succ a | ⟨a, e⟩ => not_succ_isLimit a (e ▸ h) theorem succ_lt_of_isLimit {o a : Ordinal} (h : IsLimit o) : succ a < o ↔ a < o := IsSuccLimit.succ_lt_iff h theorem le_succ_of_isLimit {o} (h : IsLimit o) {a} : o ≤ succ a ↔ o ≤ a := le_iff_le_iff_lt_iff_lt.2 <| succ_lt_of_isLimit h theorem limit_le {o} (h : IsLimit o) {a} : o ≤ a ↔ ∀ x < o, x ≤ a := ⟨fun h _x l => l.le.trans h, fun H => (le_succ_of_isLimit h).1 <| le_of_not_lt fun hn => not_lt_of_le (H _ hn) (lt_succ a)⟩ theorem lt_limit {o} (h : IsLimit o) {a} : a < o ↔ ∃ x < o, a < x := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@limit_le _ h a) @[simp] theorem lift_isLimit (o : Ordinal.{v}) : IsLimit (lift.{u,v} o) ↔ IsLimit o := liftInitialSeg.isSuccLimit_apply_iff theorem IsLimit.pos {o : Ordinal} (h : IsLimit o) : 0 < o := IsSuccLimit.bot_lt h theorem IsLimit.ne_zero {o : Ordinal} (h : IsLimit o) : o ≠ 0 := h.pos.ne' theorem IsLimit.one_lt {o : Ordinal} (h : IsLimit o) : 1 < o := by simpa only [succ_zero] using h.succ_lt h.pos theorem IsLimit.nat_lt {o : Ordinal} (h : IsLimit o) : ∀ n : ℕ, (n : Ordinal) < o | 0 => h.pos | n + 1 => h.succ_lt (IsLimit.nat_lt h n) theorem zero_or_succ_or_limit (o : Ordinal) : o = 0 ∨ (∃ a, o = succ a) ∨ IsLimit o := by simpa [eq_comm] using isMin_or_mem_range_succ_or_isSuccLimit o theorem isLimit_of_not_succ_of_ne_zero {o : Ordinal} (h : ¬∃ a, o = succ a) (h' : o ≠ 0) : IsLimit o := ((zero_or_succ_or_limit o).resolve_left h').resolve_left h -- TODO: this is an iff with `IsSuccPrelimit` theorem IsLimit.sSup_Iio {o : Ordinal} (h : IsLimit o) : sSup (Iio o) = o := by apply (csSup_le' (fun a ha ↦ le_of_lt ha)).antisymm apply le_of_forall_lt intro a ha exact (lt_succ a).trans_le (le_csSup bddAbove_Iio (h.succ_lt ha)) theorem IsLimit.iSup_Iio {o : Ordinal} (h : IsLimit o) : ⨆ a : Iio o, a.1 = o := by rw [← sSup_eq_iSup', h.sSup_Iio] /-- Main induction principle of ordinals: if one can prove a property by induction at successor ordinals and at limit ordinals, then it holds for all ordinals. -/ @[elab_as_elim] def limitRecOn {motive : Ordinal → Sort*} (o : Ordinal) (zero : motive 0) (succ : ∀ o, motive o → motive (succ o)) (isLimit : ∀ o, IsLimit o → (∀ o' < o, motive o') → motive o) : motive o := by refine SuccOrder.limitRecOn o (fun a ha ↦ ?_) (fun a _ ↦ succ a) isLimit convert zero simpa using ha @[simp] theorem limitRecOn_zero {motive} (H₁ H₂ H₃) : @limitRecOn motive 0 H₁ H₂ H₃ = H₁ := SuccOrder.limitRecOn_isMin _ _ _ isMin_bot @[simp] theorem limitRecOn_succ {motive} (o H₁ H₂ H₃) : @limitRecOn motive (succ o) H₁ H₂ H₃ = H₂ o (@limitRecOn motive o H₁ H₂ H₃) := SuccOrder.limitRecOn_succ .. @[simp] theorem limitRecOn_limit {motive} (o H₁ H₂ H₃ h) : @limitRecOn motive o H₁ H₂ H₃ = H₃ o h fun x _h => @limitRecOn motive x H₁ H₂ H₃ := SuccOrder.limitRecOn_of_isSuccLimit .. /-- Bounded recursion on ordinals. Similar to `limitRecOn`, with the assumption `o < l` added to all cases. The final term's domain is the ordinals below `l`. -/ @[elab_as_elim] def boundedLimitRecOn {l : Ordinal} (lLim : l.IsLimit) {motive : Iio l → Sort*} (o : Iio l) (zero : motive ⟨0, lLim.pos⟩) (succ : (o : Iio l) → motive o → motive ⟨succ o, lLim.succ_lt o.2⟩) (isLimit : (o : Iio l) → IsLimit o → (Π o' < o, motive o') → motive o) : motive o := limitRecOn (motive := fun p ↦ (h : p < l) → motive ⟨p, h⟩) o.1 (fun _ ↦ zero) (fun o ih h ↦ succ ⟨o, _⟩ <| ih <| (lt_succ o).trans h) (fun _o ho ih _ ↦ isLimit _ ho fun _o' h ↦ ih _ h _) o.2 @[simp] theorem boundedLimitRec_zero {l} (lLim : l.IsLimit) {motive} (H₁ H₂ H₃) : @boundedLimitRecOn l lLim motive ⟨0, lLim.pos⟩ H₁ H₂ H₃ = H₁ := by rw [boundedLimitRecOn, limitRecOn_zero] @[simp] theorem boundedLimitRec_succ {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃) : @boundedLimitRecOn l lLim motive ⟨succ o.1, lLim.succ_lt o.2⟩ H₁ H₂ H₃ = H₂ o (@boundedLimitRecOn l lLim motive o H₁ H₂ H₃) := by rw [boundedLimitRecOn, limitRecOn_succ] rfl theorem boundedLimitRec_limit {l} (lLim : l.IsLimit) {motive} (o H₁ H₂ H₃ oLim) : @boundedLimitRecOn l lLim motive o H₁ H₂ H₃ = H₃ o oLim (fun x _ ↦ @boundedLimitRecOn l lLim motive x H₁ H₂ H₃) := by rw [boundedLimitRecOn, limitRecOn_limit] rfl instance orderTopToTypeSucc (o : Ordinal) : OrderTop (succ o).toType := @OrderTop.mk _ _ (Top.mk _) le_enum_succ theorem enum_succ_eq_top {o : Ordinal} : enum (α := (succ o).toType) (· < ·) ⟨o, type_toType _ ▸ lt_succ o⟩ = ⊤ := rfl theorem has_succ_of_type_succ_lt {α} {r : α → α → Prop} [wo : IsWellOrder α r] (h : ∀ a < type r, succ a < type r) (x : α) : ∃ y, r x y := by use enum r ⟨succ (typein r x), h _ (typein_lt_type r x)⟩ convert enum_lt_enum.mpr _ · rw [enum_typein] · rw [Subtype.mk_lt_mk, lt_succ_iff] theorem toType_noMax_of_succ_lt {o : Ordinal} (ho : ∀ a < o, succ a < o) : NoMaxOrder o.toType := ⟨has_succ_of_type_succ_lt (type_toType _ ▸ ho)⟩ theorem bounded_singleton {r : α → α → Prop} [IsWellOrder α r] (hr : (type r).IsLimit) (x) : Bounded r {x} := by refine ⟨enum r ⟨succ (typein r x), hr.succ_lt (typein_lt_type r x)⟩, ?_⟩ intro b hb rw [mem_singleton_iff.1 hb] nth_rw 1 [← enum_typein r x] rw [@enum_lt_enum _ r, Subtype.mk_lt_mk] apply lt_succ @[simp] theorem typein_ordinal (o : Ordinal.{u}) : @typein Ordinal (· < ·) _ o = Ordinal.lift.{u + 1} o := by refine Quotient.inductionOn o ?_ rintro ⟨α, r, wo⟩; apply Quotient.sound constructor; refine ((RelIso.preimage Equiv.ulift r).trans (enum r).symm).symm theorem mk_Iio_ordinal (o : Ordinal.{u}) : #(Iio o) = Cardinal.lift.{u + 1} o.card := by rw [lift_card, ← typein_ordinal] rfl /-! ### Normal ordinal functions -/ /-- A normal ordinal function is a strictly increasing function which is order-continuous, i.e., the image `f o` of a limit ordinal `o` is the sup of `f a` for `a < o`. -/ def IsNormal (f : Ordinal → Ordinal) : Prop := (∀ o, f o < f (succ o)) ∧ ∀ o, IsLimit o → ∀ a, f o ≤ a ↔ ∀ b < o, f b ≤ a theorem IsNormal.limit_le {f} (H : IsNormal f) : ∀ {o}, IsLimit o → ∀ {a}, f o ≤ a ↔ ∀ b < o, f b ≤ a := @H.2 theorem IsNormal.limit_lt {f} (H : IsNormal f) {o} (h : IsLimit o) {a} : a < f o ↔ ∃ b < o, a < f b := not_iff_not.1 <| by simpa only [exists_prop, not_exists, not_and, not_lt] using H.2 _ h a theorem IsNormal.strictMono {f} (H : IsNormal f) : StrictMono f := fun a b => limitRecOn b (Not.elim (not_lt_of_le <| Ordinal.zero_le _)) (fun _b IH h => (lt_or_eq_of_le (le_of_lt_succ h)).elim (fun h => (IH h).trans (H.1 _)) fun e => e ▸ H.1 _) fun _b l _IH h => lt_of_lt_of_le (H.1 a) ((H.2 _ l _).1 le_rfl _ (l.succ_lt h)) theorem IsNormal.monotone {f} (H : IsNormal f) : Monotone f := H.strictMono.monotone theorem isNormal_iff_strictMono_limit (f : Ordinal → Ordinal) : IsNormal f ↔ StrictMono f ∧ ∀ o, IsLimit o → ∀ a, (∀ b < o, f b ≤ a) → f o ≤ a := ⟨fun hf => ⟨hf.strictMono, fun a ha c => (hf.2 a ha c).2⟩, fun ⟨hs, hl⟩ => ⟨fun a => hs (lt_succ a), fun a ha c => ⟨fun hac _b hba => ((hs hba).trans_le hac).le, hl a ha c⟩⟩⟩ theorem IsNormal.lt_iff {f} (H : IsNormal f) {a b} : f a < f b ↔ a < b := StrictMono.lt_iff_lt <| H.strictMono theorem IsNormal.le_iff {f} (H : IsNormal f) {a b} : f a ≤ f b ↔ a ≤ b := le_iff_le_iff_lt_iff_lt.2 H.lt_iff theorem IsNormal.inj {f} (H : IsNormal f) {a b} : f a = f b ↔ a = b := by simp only [le_antisymm_iff, H.le_iff] theorem IsNormal.id_le {f} (H : IsNormal f) : id ≤ f := H.strictMono.id_le theorem IsNormal.le_apply {f} (H : IsNormal f) {a} : a ≤ f a := H.strictMono.le_apply theorem IsNormal.le_iff_eq {f} (H : IsNormal f) {a} : f a ≤ a ↔ f a = a := H.le_apply.le_iff_eq theorem IsNormal.le_set {f o} (H : IsNormal f) (p : Set Ordinal) (p0 : p.Nonempty) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f a ≤ o := ⟨fun h _ pa => (H.le_iff.2 ((H₂ _).1 le_rfl _ pa)).trans h, fun h => by induction b using limitRecOn with | zero => obtain ⟨x, px⟩ := p0 have := Ordinal.le_zero.1 ((H₂ _).1 (Ordinal.zero_le _) _ px) rw [this] at px exact h _ px | succ S _ => rcases not_forall₂.1 (mt (H₂ S).2 <| (lt_succ S).not_le) with ⟨a, h₁, h₂⟩ exact (H.le_iff.2 <| succ_le_of_lt <| not_le.1 h₂).trans (h _ h₁) | isLimit S L _ => refine (H.2 _ L _).2 fun a h' => ?_ rcases not_forall₂.1 (mt (H₂ a).2 h'.not_le) with ⟨b, h₁, h₂⟩ exact (H.le_iff.2 <| (not_le.1 h₂).le).trans (h _ h₁)⟩ theorem IsNormal.le_set' {f o} (H : IsNormal f) (p : Set α) (p0 : p.Nonempty) (g : α → Ordinal) (b) (H₂ : ∀ o, b ≤ o ↔ ∀ a ∈ p, g a ≤ o) : f b ≤ o ↔ ∀ a ∈ p, f (g a) ≤ o := by simpa [H₂] using H.le_set (g '' p) (p0.image g) b theorem IsNormal.refl : IsNormal id := ⟨lt_succ, fun _o l _a => Ordinal.limit_le l⟩ theorem IsNormal.trans {f g} (H₁ : IsNormal f) (H₂ : IsNormal g) : IsNormal (f ∘ g) := ⟨fun _x => H₁.lt_iff.2 (H₂.1 _), fun o l _a => H₁.le_set' (· < o) ⟨0, l.pos⟩ g _ fun _c => H₂.2 _ l _⟩ theorem IsNormal.isLimit {f} (H : IsNormal f) {o} (ho : IsLimit o) : IsLimit (f o) := by rw [isLimit_iff, isSuccPrelimit_iff_succ_lt] use (H.lt_iff.2 ho.pos).ne_bot intro a ha obtain ⟨b, hb, hab⟩ := (H.limit_lt ho).1 ha rw [← succ_le_iff] at hab apply hab.trans_lt rwa [H.lt_iff] theorem add_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a + b ≤ c ↔ ∀ b' < b, a + b' ≤ c := ⟨fun h _ l => (add_le_add_left l.le _).trans h, fun H => le_of_not_lt <| by -- Porting note: `induction` tactics are required because of the parser bug. induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => intro l suffices ∀ x : β, Sum.Lex r s (Sum.inr x) (enum _ ⟨_, l⟩) by -- Porting note: `revert` & `intro` is required because `cases'` doesn't replace -- `enum _ _ l` in `this`. revert this; rcases enum _ ⟨_, l⟩ with x | x <;> intro this · cases this (enum s ⟨0, h.pos⟩) · exact irrefl _ (this _) intro x rw [← typein_lt_typein (Sum.Lex r s), typein_enum] have := H _ (h.succ_lt (typein_lt_type s x)) rw [add_succ, succ_le_iff] at this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨a | b, h⟩ · exact Sum.inl a · exact Sum.inr ⟨b, by cases h; assumption⟩ · rcases a with ⟨a | a, h₁⟩ <;> rcases b with ⟨b | b, h₂⟩ <;> cases h₁ <;> cases h₂ <;> rintro ⟨⟩ <;> constructor <;> assumption⟩ theorem isNormal_add_right (a : Ordinal) : IsNormal (a + ·) := ⟨fun b => (add_lt_add_iff_left a).2 (lt_succ b), fun _b l _c => add_le_of_limit l⟩ theorem isLimit_add (a) {b} : IsLimit b → IsLimit (a + b) := (isNormal_add_right a).isLimit alias IsLimit.add := isLimit_add /-! ### Subtraction on ordinals -/ /-- The set in the definition of subtraction is nonempty. -/ private theorem sub_nonempty {a b : Ordinal} : { o | a ≤ b + o }.Nonempty := ⟨a, le_add_left _ _⟩ /-- `a - b` is the unique ordinal satisfying `b + (a - b) = a` when `b ≤ a`. -/ instance sub : Sub Ordinal := ⟨fun a b => sInf { o | a ≤ b + o }⟩ theorem le_add_sub (a b : Ordinal) : a ≤ b + (a - b) := csInf_mem sub_nonempty theorem sub_le {a b c : Ordinal} : a - b ≤ c ↔ a ≤ b + c := ⟨fun h => (le_add_sub a b).trans (add_le_add_left h _), fun h => csInf_le' h⟩ theorem lt_sub {a b c : Ordinal} : a < b - c ↔ c + a < b := lt_iff_lt_of_le_iff_le sub_le theorem add_sub_cancel (a b : Ordinal) : a + b - a = b := le_antisymm (sub_le.2 <| le_rfl) ((add_le_add_iff_left a).1 <| le_add_sub _ _) theorem sub_eq_of_add_eq {a b c : Ordinal} (h : a + b = c) : c - a = b := h ▸ add_sub_cancel _ _ theorem sub_le_self (a b : Ordinal) : a - b ≤ a := sub_le.2 <| le_add_left _ _ protected theorem add_sub_cancel_of_le {a b : Ordinal} (h : b ≤ a) : b + (a - b) = a := (le_add_sub a b).antisymm' (by rcases zero_or_succ_or_limit (a - b) with (e | ⟨c, e⟩ | l) · simp only [e, add_zero, h] · rw [e, add_succ, succ_le_iff, ← lt_sub, e] exact lt_succ c · exact (add_le_of_limit l).2 fun c l => (lt_sub.1 l).le) theorem le_sub_of_le {a b c : Ordinal} (h : b ≤ a) : c ≤ a - b ↔ b + c ≤ a := by rw [← add_le_add_iff_left b, Ordinal.add_sub_cancel_of_le h] theorem sub_lt_of_le {a b c : Ordinal} (h : b ≤ a) : a - b < c ↔ a < b + c := lt_iff_lt_of_le_iff_le (le_sub_of_le h) instance existsAddOfLE : ExistsAddOfLE Ordinal := ⟨fun h => ⟨_, (Ordinal.add_sub_cancel_of_le h).symm⟩⟩ @[simp] theorem sub_zero (a : Ordinal) : a - 0 = a := by simpa only [zero_add] using add_sub_cancel 0 a @[simp] theorem zero_sub (a : Ordinal) : 0 - a = 0 := by rw [← Ordinal.le_zero]; apply sub_le_self @[simp] theorem sub_self (a : Ordinal) : a - a = 0 := by simpa only [add_zero] using add_sub_cancel a 0 protected theorem sub_eq_zero_iff_le {a b : Ordinal} : a - b = 0 ↔ a ≤ b := ⟨fun h => by simpa only [h, add_zero] using le_add_sub a b, fun h => by rwa [← Ordinal.le_zero, sub_le, add_zero]⟩ protected theorem sub_ne_zero_iff_lt {a b : Ordinal} : a - b ≠ 0 ↔ b < a := by simpa using Ordinal.sub_eq_zero_iff_le.not theorem sub_sub (a b c : Ordinal) : a - b - c = a - (b + c) := eq_of_forall_ge_iff fun d => by rw [sub_le, sub_le, sub_le, add_assoc] @[simp] theorem add_sub_add_cancel (a b c : Ordinal) : a + b - (a + c) = b - c := by rw [← sub_sub, add_sub_cancel] theorem le_sub_of_add_le {a b c : Ordinal} (h : b + c ≤ a) : c ≤ a - b := by rw [← add_le_add_iff_left b] exact h.trans (le_add_sub a b) theorem sub_lt_of_lt_add {a b c : Ordinal} (h : a < b + c) (hc : 0 < c) : a - b < c := by obtain hab | hba := lt_or_le a b · rwa [Ordinal.sub_eq_zero_iff_le.2 hab.le] · rwa [sub_lt_of_le hba] theorem lt_add_iff {a b c : Ordinal} (hc : c ≠ 0) : a < b + c ↔ ∃ d < c, a ≤ b + d := by use fun h ↦ ⟨_, sub_lt_of_lt_add h hc.bot_lt, le_add_sub a b⟩ rintro ⟨d, hd, ha⟩ exact ha.trans_lt (add_lt_add_left hd b) theorem add_le_iff {a b c : Ordinal} (hb : b ≠ 0) : a + b ≤ c ↔ ∀ d < b, a + d < c := by simpa using (lt_add_iff hb).not @[deprecated add_le_iff (since := "2024-12-08")] theorem add_le_of_forall_add_lt {a b c : Ordinal} (hb : 0 < b) (h : ∀ d < b, a + d < c) : a + b ≤ c := (add_le_iff hb.ne').2 h theorem isLimit_sub {a b} (ha : IsLimit a) (h : b < a) : IsLimit (a - b) := by rw [isLimit_iff, Ordinal.sub_ne_zero_iff_lt, isSuccPrelimit_iff_succ_lt] refine ⟨h, fun c hc ↦ ?_⟩ rw [lt_sub] at hc ⊢ rw [add_succ] exact ha.succ_lt hc /-! ### Multiplication of ordinals -/ /-- The multiplication of ordinals `o₁` and `o₂` is the (well founded) lexicographic order on `o₂ × o₁`. -/ instance monoid : Monoid Ordinal.{u} where mul a b := Quotient.liftOn₂ a b (fun ⟨α, r, _⟩ ⟨β, s, _⟩ => ⟦⟨β × α, Prod.Lex s r, inferInstance⟩⟧ : WellOrder → WellOrder → Ordinal) fun ⟨_, _, _⟩ _ _ _ ⟨f⟩ ⟨g⟩ => Quot.sound ⟨RelIso.prodLexCongr g f⟩ one := 1 mul_assoc a b c := Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Eq.symm <| Quotient.sound ⟨⟨prodAssoc _ _ _, @fun a b => by rcases a with ⟨⟨a₁, a₂⟩, a₃⟩ rcases b with ⟨⟨b₁, b₂⟩, b₃⟩ simp [Prod.lex_def, and_or_left, or_assoc, and_assoc]⟩⟩ mul_one a := inductionOn a fun α r _ => Quotient.sound ⟨⟨punitProd _, @fun a b => by rcases a with ⟨⟨⟨⟩⟩, a⟩; rcases b with ⟨⟨⟨⟩⟩, b⟩ simp only [Prod.lex_def, EmptyRelation, false_or] simp only [eq_self_iff_true, true_and] rfl⟩⟩ one_mul a := inductionOn a fun α r _ => Quotient.sound ⟨⟨prodPUnit _, @fun a b => by rcases a with ⟨a, ⟨⟨⟩⟩⟩; rcases b with ⟨b, ⟨⟨⟩⟩⟩ simp only [Prod.lex_def, EmptyRelation, and_false, or_false] rfl⟩⟩ @[simp] theorem type_prod_lex {α β : Type u} (r : α → α → Prop) (s : β → β → Prop) [IsWellOrder α r] [IsWellOrder β s] : type (Prod.Lex s r) = type r * type s := rfl private theorem mul_eq_zero' {a b : Ordinal} : a * b = 0 ↔ a = 0 ∨ b = 0 := inductionOn a fun α _ _ => inductionOn b fun β _ _ => by simp_rw [← type_prod_lex, type_eq_zero_iff_isEmpty] rw [or_comm] exact isEmpty_prod instance monoidWithZero : MonoidWithZero Ordinal := { Ordinal.monoid with zero := 0 mul_zero := fun _a => mul_eq_zero'.2 <| Or.inr rfl zero_mul := fun _a => mul_eq_zero'.2 <| Or.inl rfl } instance noZeroDivisors : NoZeroDivisors Ordinal := ⟨fun {_ _} => mul_eq_zero'.1⟩ @[simp] theorem lift_mul (a b : Ordinal.{v}) : lift.{u} (a * b) = lift.{u} a * lift.{u} b := Quotient.inductionOn₂ a b fun ⟨_α, _r, _⟩ ⟨_β, _s, _⟩ => Quotient.sound ⟨(RelIso.preimage Equiv.ulift _).trans (RelIso.prodLexCongr (RelIso.preimage Equiv.ulift _) (RelIso.preimage Equiv.ulift _)).symm⟩ @[simp] theorem card_mul (a b) : card (a * b) = card a * card b := Quotient.inductionOn₂ a b fun ⟨α, _r, _⟩ ⟨β, _s, _⟩ => mul_comm #β #α instance leftDistribClass : LeftDistribClass Ordinal.{u} := ⟨fun a b c => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ => Quotient.sound ⟨⟨sumProdDistrib _ _ _, by rintro ⟨a₁ | a₁, a₂⟩ ⟨b₁ | b₁, b₂⟩ <;> simp only [Prod.lex_def, Sum.lex_inl_inl, Sum.Lex.sep, Sum.lex_inr_inl, Sum.lex_inr_inr, sumProdDistrib_apply_left, sumProdDistrib_apply_right, reduceCtorEq] <;> -- Porting note: `Sum.inr.inj_iff` is required. simp only [Sum.inl.inj_iff, Sum.inr.inj_iff, true_or, false_and, false_or]⟩⟩⟩ theorem mul_succ (a b : Ordinal) : a * succ b = a * b + a := mul_add_one a b instance mulLeftMono : MulLeftMono Ordinal.{u} := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : α × γ => (f a.1, a.2)) fun a b h => ?_).ordinal_type_le obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h · exact Prod.Lex.left _ _ (f.toRelEmbedding.map_rel_iff.2 h') · exact Prod.Lex.right _ h'⟩ instance mulRightMono : MulRightMono Ordinal.{u} := ⟨fun c a b => Quotient.inductionOn₃ a b c fun ⟨α, r, _⟩ ⟨β, s, _⟩ ⟨γ, t, _⟩ ⟨f⟩ => by refine (RelEmbedding.ofMonotone (fun a : γ × α => (a.1, f a.2)) fun a b h => ?_).ordinal_type_le obtain ⟨-, -, h'⟩ | ⟨-, h'⟩ := h · exact Prod.Lex.left _ _ h' · exact Prod.Lex.right _ (f.toRelEmbedding.map_rel_iff.2 h')⟩ theorem le_mul_left (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ a * b := by convert mul_le_mul_left' (one_le_iff_pos.2 hb) a rw [mul_one a] theorem le_mul_right (a : Ordinal) {b : Ordinal} (hb : 0 < b) : a ≤ b * a := by convert mul_le_mul_right' (one_le_iff_pos.2 hb) a rw [one_mul a] private theorem mul_le_of_limit_aux {α β r s} [IsWellOrder α r] [IsWellOrder β s] {c} (h : IsLimit (type s)) (H : ∀ b' < type s, type r * b' ≤ c) (l : c < type r * type s) : False := by suffices ∀ a b, Prod.Lex s r (b, a) (enum _ ⟨_, l⟩) by obtain ⟨b, a⟩ := enum _ ⟨_, l⟩ exact irrefl _ (this _ _) intro a b rw [← typein_lt_typein (Prod.Lex s r), typein_enum] have := H _ (h.succ_lt (typein_lt_type s b)) rw [mul_succ] at this have := ((add_lt_add_iff_left _).2 (typein_lt_type _ a)).trans_le this refine (RelEmbedding.ofMonotone (fun a => ?_) fun a b => ?_).ordinal_type_le.trans_lt this · rcases a with ⟨⟨b', a'⟩, h⟩ by_cases e : b = b' · refine Sum.inr ⟨a', ?_⟩ subst e obtain ⟨-, -, h⟩ | ⟨-, h⟩ := h · exact (irrefl _ h).elim · exact h · refine Sum.inl (⟨b', ?_⟩, a') obtain ⟨-, -, h⟩ | ⟨e, h⟩ := h · exact h · exact (e rfl).elim · rcases a with ⟨⟨b₁, a₁⟩, h₁⟩ rcases b with ⟨⟨b₂, a₂⟩, h₂⟩ intro h by_cases e₁ : b = b₁ <;> by_cases e₂ : b = b₂ · substs b₁ b₂ simpa only [subrel_val, Prod.lex_def, @irrefl _ s _ b, true_and, false_or, eq_self_iff_true, dif_pos, Sum.lex_inr_inr] using h · subst b₁ simp only [subrel_val, Prod.lex_def, e₂, Prod.lex_def, dif_pos, subrel_val, eq_self_iff_true, or_false, dif_neg, not_false_iff, Sum.lex_inr_inl, false_and] at h ⊢ obtain ⟨-, -, h₂_h⟩ | e₂ := h₂ <;> [exact asymm h h₂_h; exact e₂ rfl] · simp [e₂, dif_neg e₁, show b₂ ≠ b₁ from e₂ ▸ e₁] · simpa only [dif_neg e₁, dif_neg e₂, Prod.lex_def, subrel_val, Subtype.mk_eq_mk, Sum.lex_inl_inl] using h theorem mul_le_of_limit {a b c : Ordinal} (h : IsLimit b) : a * b ≤ c ↔ ∀ b' < b, a * b' ≤ c := ⟨fun h _ l => (mul_le_mul_left' l.le _).trans h, fun H => -- Porting note: `induction` tactics are required because of the parser bug. le_of_not_lt <| by induction a using inductionOn with | H α r => induction b using inductionOn with | H β s => exact mul_le_of_limit_aux h H⟩ theorem isNormal_mul_right {a : Ordinal} (h : 0 < a) : IsNormal (a * ·) := -- Porting note (https://github.com/leanprover-community/mathlib4/issues/12129): additional beta reduction needed ⟨fun b => by beta_reduce rw [mul_succ] simpa only [add_zero] using (add_lt_add_iff_left (a * b)).2 h, fun _ l _ => mul_le_of_limit l⟩ theorem lt_mul_of_limit {a b c : Ordinal} (h : IsLimit c) : a < b * c ↔ ∃ c' < c, a < b * c' := by -- Porting note: `bex_def` is required. simpa only [not_forall₂, not_le, bex_def] using not_congr (@mul_le_of_limit b c a h) theorem mul_lt_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b < a * c ↔ b < c := (isNormal_mul_right a0).lt_iff theorem mul_le_mul_iff_left {a b c : Ordinal} (a0 : 0 < a) : a * b ≤ a * c ↔ b ≤ c := (isNormal_mul_right a0).le_iff theorem mul_lt_mul_of_pos_left {a b c : Ordinal} (h : a < b) (c0 : 0 < c) : c * a < c * b := (mul_lt_mul_iff_left c0).2 h theorem mul_pos {a b : Ordinal} (h₁ : 0 < a) (h₂ : 0 < b) : 0 < a * b := by simpa only [mul_zero] using mul_lt_mul_of_pos_left h₂ h₁ theorem mul_ne_zero {a b : Ordinal} : a ≠ 0 → b ≠ 0 → a * b ≠ 0 := by simpa only [Ordinal.pos_iff_ne_zero] using mul_pos theorem le_of_mul_le_mul_left {a b c : Ordinal} (h : c * a ≤ c * b) (h0 : 0 < c) : a ≤ b := le_imp_le_of_lt_imp_lt (fun h' => mul_lt_mul_of_pos_left h' h0) h theorem mul_right_inj {a b c : Ordinal} (a0 : 0 < a) : a * b = a * c ↔ b = c := (isNormal_mul_right a0).inj theorem isLimit_mul {a b : Ordinal} (a0 : 0 < a) : IsLimit b → IsLimit (a * b) := (isNormal_mul_right a0).isLimit theorem isLimit_mul_left {a b : Ordinal} (l : IsLimit a) (b0 : 0 < b) : IsLimit (a * b) := by rcases zero_or_succ_or_limit b with (rfl | ⟨b, rfl⟩ | lb) · exact b0.false.elim · rw [mul_succ] exact isLimit_add _ l · exact isLimit_mul l.pos lb theorem smul_eq_mul : ∀ (n : ℕ) (a : Ordinal), n • a = a * n | 0, a => by rw [zero_nsmul, Nat.cast_zero, mul_zero] | n + 1, a => by rw [succ_nsmul, Nat.cast_add, mul_add, Nat.cast_one, mul_one, smul_eq_mul n] private theorem add_mul_limit_aux {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) (IH : ∀ c' < c, (a + b) * succ c' = a * succ c' + b) : (a + b) * c = a * c := le_antisymm ((mul_le_of_limit l).2 fun c' h => by apply (mul_le_mul_left' (le_succ c') _).trans rw [IH _ h] apply (add_le_add_left _ _).trans · rw [← mul_succ] exact mul_le_mul_left' (succ_le_of_lt <| l.succ_lt h) _ · rw [← ba] exact le_add_right _ _) (mul_le_mul_right' (le_add_right _ _) _) theorem add_mul_succ {a b : Ordinal} (c) (ba : b + a = a) : (a + b) * succ c = a * succ c + b := by induction c using limitRecOn with | zero => simp only [succ_zero, mul_one] | succ c IH => rw [mul_succ, IH, ← add_assoc, add_assoc _ b, ba, ← mul_succ] | isLimit c l IH => rw [mul_succ, add_mul_limit_aux ba l IH, mul_succ, add_assoc] theorem add_mul_limit {a b c : Ordinal} (ba : b + a = a) (l : IsLimit c) : (a + b) * c = a * c := add_mul_limit_aux ba l fun c' _ => add_mul_succ c' ba /-! ### Division on ordinals -/ /-- The set in the definition of division is nonempty. -/ private theorem div_nonempty {a b : Ordinal} (h : b ≠ 0) : { o | a < b * succ o }.Nonempty := ⟨a, (succ_le_iff (a := a) (b := b * succ a)).1 <| by simpa only [succ_zero, one_mul] using mul_le_mul_right' (succ_le_of_lt (Ordinal.pos_iff_ne_zero.2 h)) (succ a)⟩ /-- `a / b` is the unique ordinal `o` satisfying `a = b * o + o'` with `o' < b`. -/ instance div : Div Ordinal := ⟨fun a b => if b = 0 then 0 else sInf { o | a < b * succ o }⟩ @[simp] theorem div_zero (a : Ordinal) : a / 0 = 0 := dif_pos rfl private theorem div_def (a) {b : Ordinal} (h : b ≠ 0) : a / b = sInf { o | a < b * succ o } := dif_neg h theorem lt_mul_succ_div (a) {b : Ordinal} (h : b ≠ 0) : a < b * succ (a / b) := by rw [div_def a h]; exact csInf_mem (div_nonempty h) theorem lt_mul_div_add (a) {b : Ordinal} (h : b ≠ 0) : a < b * (a / b) + b := by simpa only [mul_succ] using lt_mul_succ_div a h theorem div_le {a b c : Ordinal} (b0 : b ≠ 0) : a / b ≤ c ↔ a < b * succ c := ⟨fun h => (lt_mul_succ_div a b0).trans_le (mul_le_mul_left' (succ_le_succ_iff.2 h) _), fun h => by rw [div_def a b0]; exact csInf_le' h⟩ theorem lt_div {a b c : Ordinal} (h : c ≠ 0) : a < b / c ↔ c * succ a ≤ b := by rw [← not_le, div_le h, not_lt] theorem div_pos {b c : Ordinal} (h : c ≠ 0) : 0 < b / c ↔ c ≤ b := by simp [lt_div h] theorem le_div {a b c : Ordinal} (c0 : c ≠ 0) : a ≤ b / c ↔ c * a ≤ b := by induction a using limitRecOn with | zero => simp only [mul_zero, Ordinal.zero_le] | succ _ _ => rw [succ_le_iff, lt_div c0] | isLimit _ h₁ h₂ => revert h₁ h₂ simp +contextual only [mul_le_of_limit, limit_le, forall_true_iff] theorem div_lt {a b c : Ordinal} (b0 : b ≠ 0) : a / b < c ↔ a < b * c := lt_iff_lt_of_le_iff_le <| le_div b0 theorem div_le_of_le_mul {a b c : Ordinal} (h : a ≤ b * c) : a / b ≤ c := if b0 : b = 0 then by simp only [b0, div_zero, Ordinal.zero_le] else (div_le b0).2 <| h.trans_lt <| mul_lt_mul_of_pos_left (lt_succ c) (Ordinal.pos_iff_ne_zero.2 b0) theorem mul_lt_of_lt_div {a b c : Ordinal} : a < b / c → c * a < b := lt_imp_lt_of_le_imp_le div_le_of_le_mul @[simp] theorem zero_div (a : Ordinal) : 0 / a = 0 := Ordinal.le_zero.1 <| div_le_of_le_mul <| Ordinal.zero_le _ theorem mul_div_le (a b : Ordinal) : b * (a / b) ≤ a := if b0 : b = 0 then by simp only [b0, zero_mul, Ordinal.zero_le] else (le_div b0).1 le_rfl theorem div_le_left {a b : Ordinal} (h : a ≤ b) (c : Ordinal) : a / c ≤ b / c := by obtain rfl | hc := eq_or_ne c 0 · rw [div_zero, div_zero] · rw [le_div hc] exact (mul_div_le a c).trans h theorem mul_add_div (a) {b : Ordinal} (b0 : b ≠ 0) (c) : (b * a + c) / b = a + c / b := by apply le_antisymm · apply (div_le b0).2 rw [mul_succ, mul_add, add_assoc, add_lt_add_iff_left] apply lt_mul_div_add _ b0 · rw [le_div b0, mul_add, add_le_add_iff_left] apply mul_div_le theorem div_eq_zero_of_lt {a b : Ordinal} (h : a < b) : a / b = 0 := by rw [← Ordinal.le_zero, div_le <| Ordinal.pos_iff_ne_zero.1 <| (Ordinal.zero_le _).trans_lt h] simpa only [succ_zero, mul_one] using h @[simp] theorem mul_div_cancel (a) {b : Ordinal} (b0 : b ≠ 0) : b * a / b = a := by simpa only [add_zero, zero_div] using mul_add_div a b0 0 theorem mul_add_div_mul {a c : Ordinal} (hc : c < a) (b d : Ordinal) : (a * b + c) / (a * d) = b / d := by have ha : a ≠ 0 := ((Ordinal.zero_le c).trans_lt hc).ne' obtain rfl | hd := eq_or_ne d 0 · rw [mul_zero, div_zero, div_zero] · have H := mul_ne_zero ha hd apply le_antisymm · rw [← lt_succ_iff, div_lt H, mul_assoc] · apply (add_lt_add_left hc _).trans_le rw [← mul_succ] apply mul_le_mul_left' rw [succ_le_iff] exact lt_mul_succ_div b hd · rw [le_div H, mul_assoc] exact (mul_le_mul_left' (mul_div_le b d) a).trans (le_add_right _ c) theorem mul_div_mul_cancel {a : Ordinal} (ha : a ≠ 0) (b c) : a * b / (a * c) = b / c := by convert mul_add_div_mul (Ordinal.pos_iff_ne_zero.2 ha) b c using 1 rw [add_zero] @[simp] theorem div_one (a : Ordinal) : a / 1 = a := by simpa only [one_mul] using mul_div_cancel a Ordinal.one_ne_zero @[simp] theorem div_self {a : Ordinal} (h : a ≠ 0) : a / a = 1 := by simpa only [mul_one] using mul_div_cancel 1 h theorem mul_sub (a b c : Ordinal) : a * (b - c) = a * b - a * c := if a0 : a = 0 then by simp only [a0, zero_mul, sub_self] else eq_of_forall_ge_iff fun d => by rw [sub_le, ← le_div a0, sub_le, ← le_div a0, mul_add_div _ a0] theorem isLimit_add_iff {a b} : IsLimit (a + b) ↔ IsLimit b ∨ b = 0 ∧ IsLimit a := by constructor <;> intro h · by_cases h' : b = 0 · rw [h', add_zero] at h right exact ⟨h', h⟩ left rw [← add_sub_cancel a b] apply isLimit_sub h suffices a + 0 < a + b by simpa only [add_zero] using this rwa [add_lt_add_iff_left, Ordinal.pos_iff_ne_zero] rcases h with (h | ⟨rfl, h⟩) · exact isLimit_add a h · simpa only [add_zero] theorem dvd_add_iff : ∀ {a b c : Ordinal}, a ∣ b → (a ∣ b + c ↔ a ∣ c) | a, _, c, ⟨b, rfl⟩ => ⟨fun ⟨d, e⟩ => ⟨d - b, by rw [mul_sub, ← e, add_sub_cancel]⟩, fun ⟨d, e⟩ => by rw [e, ← mul_add] apply dvd_mul_right⟩ theorem div_mul_cancel : ∀ {a b : Ordinal}, a ≠ 0 → a ∣ b → a * (b / a) = b | a, _, a0, ⟨b, rfl⟩ => by rw [mul_div_cancel _ a0] theorem le_of_dvd : ∀ {a b : Ordinal}, b ≠ 0 → a ∣ b → a ≤ b -- Porting note: `⟨b, rfl⟩ => by` → `⟨b, e⟩ => by subst e` | a, _, b0, ⟨b, e⟩ => by subst e -- Porting note: `Ne` is required. simpa only [mul_one] using mul_le_mul_left' (one_le_iff_ne_zero.2 fun h : b = 0 => by simp only [h, mul_zero, Ne, not_true_eq_false] at b0) a theorem dvd_antisymm {a b : Ordinal} (h₁ : a ∣ b) (h₂ : b ∣ a) : a = b := if a0 : a = 0 then by subst a; exact (eq_zero_of_zero_dvd h₁).symm else if b0 : b = 0 then by subst b; exact eq_zero_of_zero_dvd h₂ else (le_of_dvd b0 h₁).antisymm (le_of_dvd a0 h₂) instance isAntisymm : IsAntisymm Ordinal (· ∣ ·) := ⟨@dvd_antisymm⟩ /-- `a % b` is the unique ordinal `o'` satisfying `a = b * o + o'` with `o' < b`. -/ instance mod : Mod Ordinal := ⟨fun a b => a - b * (a / b)⟩ theorem mod_def (a b : Ordinal) : a % b = a - b * (a / b) := rfl theorem mod_le (a b : Ordinal) : a % b ≤ a := sub_le_self a _ @[simp] theorem mod_zero (a : Ordinal) : a % 0 = a := by simp only [mod_def, div_zero, zero_mul, sub_zero] theorem mod_eq_of_lt {a b : Ordinal} (h : a < b) : a % b = a := by simp only [mod_def, div_eq_zero_of_lt h, mul_zero, sub_zero] @[simp] theorem zero_mod (b : Ordinal) : 0 % b = 0 := by simp only [mod_def, zero_div, mul_zero, sub_self] theorem div_add_mod (a b : Ordinal) : b * (a / b) + a % b = a := Ordinal.add_sub_cancel_of_le <| mul_div_le _ _ theorem mod_lt (a) {b : Ordinal} (h : b ≠ 0) : a % b < b := (add_lt_add_iff_left (b * (a / b))).1 <| by rw [div_add_mod]; exact lt_mul_div_add a h @[simp] theorem mod_self (a : Ordinal) : a % a = 0 := if a0 : a = 0 then by simp only [a0, zero_mod] else by simp only [mod_def, div_self a0, mul_one, sub_self] @[simp] theorem mod_one (a : Ordinal) : a % 1 = 0 := by simp only [mod_def, div_one, one_mul, sub_self] theorem dvd_of_mod_eq_zero {a b : Ordinal} (H : a % b = 0) : b ∣ a := ⟨a / b, by simpa [H] using (div_add_mod a b).symm⟩ theorem mod_eq_zero_of_dvd {a b : Ordinal} (H : b ∣ a) : a % b = 0 := by rcases H with ⟨c, rfl⟩ rcases eq_or_ne b 0 with (rfl | hb) · simp · simp [mod_def, hb] theorem dvd_iff_mod_eq_zero {a b : Ordinal} : b ∣ a ↔ a % b = 0 := ⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩ @[simp] theorem mul_add_mod_self (x y z : Ordinal) : (x * y + z) % x = z % x := by rcases eq_or_ne x 0 with rfl | hx · simp · rwa [mod_def, mul_add_div, mul_add, ← sub_sub, add_sub_cancel, mod_def] @[simp] theorem mul_mod (x y : Ordinal) : x * y % x = 0 := by simpa using mul_add_mod_self x y 0 theorem mul_add_mod_mul {w x : Ordinal} (hw : w < x) (y z : Ordinal) : (x * y + w) % (x * z) = x * (y % z) + w := by rw [mod_def, mul_add_div_mul hw] apply sub_eq_of_add_eq rw [← add_assoc, mul_assoc, ← mul_add, div_add_mod] theorem mul_mod_mul (x y z : Ordinal) : (x * y) % (x * z) = x * (y % z) := by obtain rfl | hx := Ordinal.eq_zero_or_pos x · simp · convert mul_add_mod_mul hx y z using 1 <;> rw [add_zero] theorem mod_mod_of_dvd (a : Ordinal) {b c : Ordinal} (h : c ∣ b) : a % b % c = a % c := by nth_rw 2 [← div_add_mod a b] rcases h with ⟨d, rfl⟩ rw [mul_assoc, mul_add_mod_self] @[simp] theorem mod_mod (a b : Ordinal) : a % b % b = a % b := mod_mod_of_dvd a dvd_rfl /-! ### Casting naturals into ordinals, compatibility with operations -/ instance instCharZero : CharZero Ordinal := by refine ⟨fun a b h ↦ ?_⟩ rwa [← Cardinal.ord_nat, ← Cardinal.ord_nat, Cardinal.ord_inj, Nat.cast_inj] at h @[simp] theorem one_add_natCast (m : ℕ) : 1 + (m : Ordinal) = succ m := by rw [← Nat.cast_one, ← Nat.cast_add, add_comm] rfl @[simp] theorem one_add_ofNat (m : ℕ) [m.AtLeastTwo] : 1 + (ofNat(m) : Ordinal) = Order.succ (OfNat.ofNat m : Ordinal) := one_add_natCast m @[simp, norm_cast] theorem natCast_mul (m : ℕ) : ∀ n : ℕ, ((m * n : ℕ) : Ordinal) = m * n | 0 => by simp | n + 1 => by rw [Nat.mul_succ, Nat.cast_add, natCast_mul m n, Nat.cast_succ, mul_add_one] @[simp, norm_cast] theorem natCast_sub (m n : ℕ) : ((m - n : ℕ) : Ordinal) = m - n := by rcases le_total m n with h | h · rw [tsub_eq_zero_iff_le.2 h, Ordinal.sub_eq_zero_iff_le.2 (Nat.cast_le.2 h), Nat.cast_zero] · rw [← add_left_cancel_iff (a := ↑n), ← Nat.cast_add, add_tsub_cancel_of_le h, Ordinal.add_sub_cancel_of_le (Nat.cast_le.2 h)] @[simp, norm_cast] theorem natCast_div (m n : ℕ) : ((m / n : ℕ) : Ordinal) = m / n := by rcases eq_or_ne n 0 with (rfl | hn) · simp · have hn' : (n : Ordinal) ≠ 0 := Nat.cast_ne_zero.2 hn apply le_antisymm · rw [le_div hn', ← natCast_mul, Nat.cast_le, mul_comm] apply Nat.div_mul_le_self · rw [div_le hn', ← add_one_eq_succ, ← Nat.cast_succ, ← natCast_mul, Nat.cast_lt, mul_comm, ← Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero hn)] apply Nat.lt_succ_self @[simp, norm_cast] theorem natCast_mod (m n : ℕ) : ((m % n : ℕ) : Ordinal) = m % n := by rw [← add_left_cancel_iff, div_add_mod, ← natCast_div, ← natCast_mul, ← Nat.cast_add, Nat.div_add_mod] @[simp] theorem lift_natCast : ∀ n : ℕ, lift.{u, v} n = n | 0 => by simp | n + 1 => by simp [lift_natCast n] @[simp] theorem lift_ofNat (n : ℕ) [n.AtLeastTwo] : lift.{u, v} ofNat(n) = OfNat.ofNat n := lift_natCast n theorem lt_omega0 {o : Ordinal} : o < ω ↔ ∃ n : ℕ, o = n := by simp_rw [← Cardinal.ord_aleph0, Cardinal.lt_ord, lt_aleph0, card_eq_nat] theorem nat_lt_omega0 (n : ℕ) : ↑n < ω := lt_omega0.2 ⟨_, rfl⟩ theorem eq_nat_or_omega0_le (o : Ordinal) : (∃ n : ℕ, o = n) ∨ ω ≤ o := by obtain ho | ho := lt_or_le o ω · exact Or.inl <| lt_omega0.1 ho · exact Or.inr ho theorem omega0_pos : 0 < ω := nat_lt_omega0 0 theorem omega0_ne_zero : ω ≠ 0 := omega0_pos.ne' theorem one_lt_omega0 : 1 < ω := by simpa only [Nat.cast_one] using nat_lt_omega0 1 theorem isLimit_omega0 : IsLimit ω := by rw [isLimit_iff, isSuccPrelimit_iff_succ_lt] refine ⟨omega0_ne_zero, fun o h => ?_⟩ obtain ⟨n, rfl⟩ := lt_omega0.1 h exact nat_lt_omega0 (n + 1) theorem omega0_le {o : Ordinal} : ω ≤ o ↔ ∀ n : ℕ, ↑n ≤ o := ⟨fun h n => (nat_lt_omega0 _).le.trans h, fun H => le_of_forall_lt fun a h => by let ⟨n, e⟩ := lt_omega0.1 h rw [e, ← succ_le_iff]; exact H (n + 1)⟩ theorem nat_lt_limit {o} (h : IsLimit o) : ∀ n : ℕ, ↑n < o | 0 => h.pos | n + 1 => h.succ_lt (nat_lt_limit h n) theorem omega0_le_of_isLimit {o} (h : IsLimit o) : ω ≤ o := omega0_le.2 fun n => le_of_lt <| nat_lt_limit h n theorem natCast_add_omega0 (n : ℕ) : n + ω = ω := by refine le_antisymm (le_of_forall_lt fun a ha ↦ ?_) (le_add_left _ _) obtain ⟨b, hb', hb⟩ := (lt_add_iff omega0_ne_zero).1 ha obtain ⟨m, rfl⟩ := lt_omega0.1 hb' apply hb.trans_lt exact_mod_cast nat_lt_omega0 (n + m) theorem one_add_omega0 : 1 + ω = ω := mod_cast natCast_add_omega0 1 theorem add_omega0 {a : Ordinal} (h : a < ω) : a + ω = ω := by obtain ⟨n, rfl⟩ := lt_omega0.1 h exact natCast_add_omega0 n @[simp] theorem natCast_add_of_omega0_le {o} (h : ω ≤ o) (n : ℕ) : n + o = o := by rw [← Ordinal.add_sub_cancel_of_le h, ← add_assoc, natCast_add_omega0] @[simp] theorem one_add_of_omega0_le {o} (h : ω ≤ o) : 1 + o = o := mod_cast natCast_add_of_omega0_le h 1 open Ordinal theorem isLimit_iff_omega0_dvd {a : Ordinal} : IsLimit a ↔ a ≠ 0 ∧ ω ∣ a := by refine ⟨fun l => ⟨l.ne_zero, ⟨a / ω, le_antisymm ?_ (mul_div_le _ _)⟩⟩, fun h => ?_⟩ · refine (limit_le l).2 fun x hx => le_of_lt ?_ rw [← div_lt omega0_ne_zero, ← succ_le_iff, le_div omega0_ne_zero, mul_succ, add_le_of_limit isLimit_omega0] intro b hb rcases lt_omega0.1 hb with ⟨n, rfl⟩ exact (add_le_add_right (mul_div_le _ _) _).trans (lt_sub.1 <| nat_lt_limit (isLimit_sub l hx) _).le · rcases h with ⟨a0, b, rfl⟩ refine isLimit_mul_left isLimit_omega0 (Ordinal.pos_iff_ne_zero.2 <| mt ?_ a0) intro e simp only [e, mul_zero] @[simp] theorem natCast_mod_omega0 (n : ℕ) : n % ω = n := mod_eq_of_lt (nat_lt_omega0 n) end Ordinal namespace Cardinal open Ordinal @[simp] theorem add_one_of_aleph0_le {c} (h : ℵ₀ ≤ c) : c + 1 = c := by rw [add_comm, ← card_ord c, ← card_one, ← card_add, one_add_of_omega0_le] rwa [← ord_aleph0, ord_le_ord] theorem isLimit_ord {c} (co : ℵ₀ ≤ c) : (ord c).IsLimit := by rw [isLimit_iff, isSuccPrelimit_iff_succ_lt] refine ⟨fun h => aleph0_ne_zero ?_, fun a => lt_imp_lt_of_le_imp_le fun h => ?_⟩ · rw [← Ordinal.le_zero, ord_le] at h simpa only [card_zero, nonpos_iff_eq_zero] using co.trans h · rw [ord_le] at h ⊢ rwa [← @add_one_of_aleph0_le (card a), ← card_succ] rw [← ord_le, ← le_succ_of_isLimit, ord_le] · exact co.trans h · rw [ord_aleph0] exact Ordinal.isLimit_omega0 theorem noMaxOrder {c} (h : ℵ₀ ≤ c) : NoMaxOrder c.ord.toType := toType_noMax_of_succ_lt fun _ ↦ (isLimit_ord h).succ_lt end Cardinal
Mathlib/SetTheory/Ordinal/Arithmetic.lean
2,566
2,567
/- Copyright (c) 2021 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.Algebra.Lie.Ideal /-! # Ideal operations for Lie algebras Given a Lie module `M` over a Lie algebra `L`, there is a natural action of the Lie ideals of `L` on the Lie submodules of `M`. In the special case that `M = L` with the adjoint action, this provides a pairing of Lie ideals which is especially important. For example, it can be used to define solvability / nilpotency of a Lie algebra via the derived / lower-central series. ## Main definitions * `LieSubmodule.hasBracket` * `LieSubmodule.lieIdeal_oper_eq_linear_span` * `LieIdeal.map_bracket_le` * `LieIdeal.comap_bracket_le` ## Notation Given a Lie module `M` over a Lie algebra `L`, together with a Lie submodule `N ⊆ M` and a Lie ideal `I ⊆ L`, we introduce the notation `⁅I, N⁆` for the Lie submodule of `M` corresponding to the action defined in this file. ## Tags lie algebra, ideal operation -/ universe u v w w₁ w₂ namespace LieSubmodule variable {R : Type u} {L : Type v} {M : Type w} {M₂ : Type w₁} variable [CommRing R] [LieRing L] variable [AddCommGroup M] [Module R M] [LieRingModule L M] variable [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] variable (N N' : LieSubmodule R L M) (N₂ : LieSubmodule R L M₂) variable (f : M →ₗ⁅R,L⁆ M₂) section LieIdealOperations theorem map_comap_le : map f (comap f N₂) ≤ N₂ := (N₂ : Set M₂).image_preimage_subset f theorem map_comap_eq (hf : N₂ ≤ f.range) : map f (comap f N₂) = N₂ := by rw [SetLike.ext'_iff] exact Set.image_preimage_eq_of_subset hf theorem le_comap_map : N ≤ comap f (map f N) := (N : Set M).subset_preimage_image f theorem comap_map_eq (hf : f.ker = ⊥) : comap f (map f N) = N := by rw [SetLike.ext'_iff] exact (N : Set M).preimage_image_eq (f.ker_eq_bot.mp hf) @[simp] theorem map_comap_incl : map N.incl (comap N.incl N') = N ⊓ N' := by rw [← toSubmodule_inj] exact (N : Submodule R M).map_comap_subtype N' variable [LieAlgebra R L] [LieModule R L M₂] (I J : LieIdeal R L) /-- Given a Lie module `M` over a Lie algebra `L`, the set of Lie ideals of `L` acts on the set of submodules of `M`. -/ instance hasBracket : Bracket (LieIdeal R L) (LieSubmodule R L M) := ⟨fun I N => lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) }⟩ theorem lieIdeal_oper_eq_span : ⁅I, N⁆ = lieSpan R L { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } := rfl /-- See also `LieSubmodule.lieIdeal_oper_eq_linear_span'` and `LieSubmodule.lieIdeal_oper_eq_tensor_map_range`. -/ theorem lieIdeal_oper_eq_linear_span [LieModule R L M] : (↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } := by apply le_antisymm · let s := { ⁅(x : L), (n : M)⁆ | (x : I) (n : N) } have aux : ∀ (y : L), ∀ m' ∈ Submodule.span R s, ⁅y, m'⁆ ∈ Submodule.span R s := by intro y m' hm' refine Submodule.span_induction (R := R) (M := M) (s := s) (p := fun m' _ ↦ ⁅y, m'⁆ ∈ Submodule.span R s) ?_ ?_ ?_ ?_ hm' · rintro m'' ⟨x, n, hm''⟩; rw [← hm'', leibniz_lie] refine Submodule.add_mem _ ?_ ?_ <;> apply Submodule.subset_span · use ⟨⁅y, ↑x⁆, I.lie_mem x.property⟩, n · use x, ⟨⁅y, ↑n⁆, N.lie_mem n.property⟩ · simp only [lie_zero, Submodule.zero_mem] · intro m₁ m₂ _ _ hm₁ hm₂; rw [lie_add]; exact Submodule.add_mem _ hm₁ hm₂ · intro t m'' _ hm''; rw [lie_smul]; exact Submodule.smul_mem _ t hm'' change _ ≤ ({ Submodule.span R s with lie_mem := fun hm' => aux _ _ hm' } : LieSubmodule R L M) rw [lieIdeal_oper_eq_span, lieSpan_le] exact Submodule.subset_span · rw [lieIdeal_oper_eq_span]; apply submodule_span_le_lieSpan theorem lieIdeal_oper_eq_linear_span' [LieModule R L M] : (↑⁅I, N⁆ : Submodule R M) = Submodule.span R { ⁅x, n⁆ | (x ∈ I) (n ∈ N) } := by rw [lieIdeal_oper_eq_linear_span] congr ext m constructor · rintro ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩ exact ⟨x, hx, n, hn, rfl⟩ · rintro ⟨x, hx, n, hn, rfl⟩ exact ⟨⟨x, hx⟩, ⟨n, hn⟩, rfl⟩ theorem lie_le_iff : ⁅I, N⁆ ≤ N' ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅x, m⁆ ∈ N' := by rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_le] refine ⟨fun h x hx m hm => h ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩ rintro h _ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩ exact h x hx m hm variable {N I} in theorem lie_coe_mem_lie (x : I) (m : N) : ⁅(x : L), (m : M)⁆ ∈ ⁅I, N⁆ := by rw [lieIdeal_oper_eq_span]; apply subset_lieSpan; use x, m variable {N I} in theorem lie_mem_lie {x : L} {m : M} (hx : x ∈ I) (hm : m ∈ N) : ⁅x, m⁆ ∈ ⁅I, N⁆ := lie_coe_mem_lie ⟨x, hx⟩ ⟨m, hm⟩ theorem lie_comm : ⁅I, J⁆ = ⁅J, I⁆ := by suffices ∀ I J : LieIdeal R L, ⁅I, J⁆ ≤ ⁅J, I⁆ by exact le_antisymm (this I J) (this J I) clear! I J; intro I J rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro x ⟨y, z, h⟩; rw [← h] rw [← lie_skew, ← lie_neg, ← LieSubmodule.coe_neg] apply lie_coe_mem_lie theorem lie_le_right : ⁅I, N⁆ ≤ N := by rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨x, n, hn⟩; rw [← hn] exact N.lie_mem n.property theorem lie_le_left : ⁅I, J⁆ ≤ I := by rw [lie_comm]; exact lie_le_right I J theorem lie_le_inf : ⁅I, J⁆ ≤ I ⊓ J := by rw [le_inf_iff]; exact ⟨lie_le_left I J, lie_le_right J I⟩ @[simp] theorem lie_bot : ⁅I, (⊥ : LieSubmodule R L M)⁆ = ⊥ := by rw [eq_bot_iff]; apply lie_le_right @[simp] theorem bot_lie : ⁅(⊥ : LieIdeal R L), N⁆ = ⊥ := by suffices ⁅(⊥ : LieIdeal R L), N⁆ ≤ ⊥ by exact le_bot_iff.mp this rw [lieIdeal_oper_eq_span, lieSpan_le]; rintro m ⟨⟨x, hx⟩, n, hn⟩; rw [← hn] change x ∈ (⊥ : LieIdeal R L) at hx; rw [mem_bot] at hx; simp [hx] theorem lie_eq_bot_iff : ⁅I, N⁆ = ⊥ ↔ ∀ x ∈ I, ∀ m ∈ N, ⁅(x : L), m⁆ = 0 := by rw [lieIdeal_oper_eq_span, LieSubmodule.lieSpan_eq_bot_iff] refine ⟨fun h x hx m hm => h ⁅x, m⁆ ⟨⟨x, hx⟩, ⟨m, hm⟩, rfl⟩, ?_⟩ rintro h - ⟨⟨x, hx⟩, ⟨⟨n, hn⟩, rfl⟩⟩ exact h x hx n hn variable {I J N N'} in theorem mono_lie (h₁ : I ≤ J) (h₂ : N ≤ N') : ⁅I, N⁆ ≤ ⁅J, N'⁆ := by intro m h rw [lieIdeal_oper_eq_span, mem_lieSpan] at h; rw [lieIdeal_oper_eq_span, mem_lieSpan] intro N hN; apply h; rintro m' ⟨⟨x, hx⟩, ⟨n, hn⟩, hm⟩; rw [← hm]; apply hN use ⟨x, h₁ hx⟩, ⟨n, h₂ hn⟩ variable {I J} in theorem mono_lie_left (h : I ≤ J) : ⁅I, N⁆ ≤ ⁅J, N⁆ := mono_lie h (le_refl N) variable {N N'} in theorem mono_lie_right (h : N ≤ N') : ⁅I, N⁆ ≤ ⁅I, N'⁆ := mono_lie (le_refl I) h @[simp] theorem lie_sup : ⁅I, N ⊔ N'⁆ = ⁅I, N⁆ ⊔ ⁅I, N'⁆ := by have h : ⁅I, N⁆ ⊔ ⁅I, N'⁆ ≤ ⁅I, N ⊔ N'⁆ := by rw [sup_le_iff]; constructor <;> apply mono_lie_right <;> [exact le_sup_left; exact le_sup_right] suffices ⁅I, N ⊔ N'⁆ ≤ ⁅I, N⁆ ⊔ ⁅I, N'⁆ by exact le_antisymm this h rw [lieIdeal_oper_eq_span, lieSpan_le] rintro m ⟨x, ⟨n, hn⟩, h⟩ simp only [SetLike.mem_coe] rw [LieSubmodule.mem_sup] at hn ⊢ rcases hn with ⟨n₁, hn₁, n₂, hn₂, hn'⟩ use ⁅(x : L), (⟨n₁, hn₁⟩ : N)⁆; constructor; · apply lie_coe_mem_lie use ⁅(x : L), (⟨n₂, hn₂⟩ : N')⁆; constructor; · apply lie_coe_mem_lie simp [← h, ← hn'] @[simp] theorem sup_lie : ⁅I ⊔ J, N⁆ = ⁅I, N⁆ ⊔ ⁅J, N⁆ := by have h : ⁅I, N⁆ ⊔ ⁅J, N⁆ ≤ ⁅I ⊔ J, N⁆ := by rw [sup_le_iff]; constructor <;> apply mono_lie_left <;> [exact le_sup_left; exact le_sup_right]
suffices ⁅I ⊔ J, N⁆ ≤ ⁅I, N⁆ ⊔ ⁅J, N⁆ by exact le_antisymm this h rw [lieIdeal_oper_eq_span, lieSpan_le] rintro m ⟨⟨x, hx⟩, n, h⟩
Mathlib/Algebra/Lie/IdealOperations.lean
190
192
/- Copyright (c) 2021 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.MeasureTheory.Group.Measure import Mathlib.MeasureTheory.Measure.Prod /-! # Measure theory in the product of groups In this file we show properties about measure theory in products of measurable groups and properties of iterated integrals in measurable groups. These lemmas show the uniqueness of left invariant measures on measurable groups, up to scaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos. The idea of the proof is to use the translation invariance of measures to prove `μ(t) = c * μ(s)` for two sets `s` and `t`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be the characteristic functions of `s` and `t`. Assume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)` preserves the measure `μ × ν`, which means that ``` ∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ ``` If we apply this to `h x y := e x * f y⁻¹ / ν ((fun h ↦ h * y⁻¹) ⁻¹' s)`, we can rewrite the RHS to `μ(t)`, and the LHS to `c * μ(s)`, where `c = c(ν)` does not depend on `μ`. Applying this to `μ` and to `ν` gives `μ (t) / μ (s) = ν (t) / ν (s)`, which is the uniqueness up to scalar multiplication. The proof in [Halmos] seems to contain an omission in §60 Th. A, see `MeasureTheory.measure_lintegral_div_measure`. Note that this theory only applies in measurable groups, i.e., when multiplication and inversion are measurable. This is not the case in general in locally compact groups, or even in compact groups, when the topology is not second-countable. For arguments along the same line, but using continuous functions instead of measurable sets and working in the general locally compact setting, see the file `Mathlib/MeasureTheory/Measure/Haar/Unique.lean`. -/ noncomputable section open Set hiding prod_eq open Function MeasureTheory open Filter hiding map open scoped ENNReal Pointwise MeasureTheory variable (G : Type*) [MeasurableSpace G] variable [Group G] [MeasurableMul₂ G] variable (μ ν : Measure G) [SFinite ν] [SFinite μ] {s : Set G} /-- The map `(x, y) ↦ (x, xy)` as a `MeasurableEquiv`. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a `MeasurableEquiv`."] protected def MeasurableEquiv.shearMulRight [MeasurableInv G] : G × G ≃ᵐ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with measurable_toFun := measurable_fst.prodMk measurable_mul measurable_invFun := measurable_fst.prodMk <| measurable_fst.inv.mul measurable_snd } /-- The map `(x, y) ↦ (x, y / x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, yx)` -/ @[to_additive "The map `(x, y) ↦ (x, y - x)` as a `MeasurableEquiv` with as inverse `(x, y) ↦ (x, y + x)`."] protected def MeasurableEquiv.shearDivRight [MeasurableInv G] : G × G ≃ᵐ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.divRight with measurable_toFun := measurable_fst.prodMk <| measurable_snd.div measurable_fst measurable_invFun := measurable_fst.prodMk <| measurable_snd.mul measurable_fst } variable {G} namespace MeasureTheory open Measure section LeftInvariant /-- The multiplicative shear mapping `(x, y) ↦ (x, xy)` preserves the measure `μ × ν`. This condition is part of the definition of a measurable group in [Halmos, §59]. There, the map in this lemma is called `S`. -/ @[to_additive measurePreserving_prod_add " The shear mapping `(x, y) ↦ (x, x + y)` preserves the measure `μ × ν`. "] theorem measurePreserving_prod_mul [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.1, z.1 * z.2)) (μ.prod ν) (μ.prod ν) := (MeasurePreserving.id μ).skew_product measurable_mul <| Filter.Eventually.of_forall <| map_mul_left_eq_self ν /-- The map `(x, y) ↦ (y, yx)` sends the measure `μ × ν` to `ν × μ`. This is the map `SR` in [Halmos, §59]. `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_prod_add_swap " The map `(x, y) ↦ (y, y + x)` sends the measure `μ × ν` to `ν × μ`. "] theorem measurePreserving_prod_mul_swap [IsMulLeftInvariant μ] : MeasurePreserving (fun z : G × G => (z.2, z.2 * z.1)) (μ.prod ν) (ν.prod μ) := (measurePreserving_prod_mul ν μ).comp measurePreserving_swap @[to_additive] theorem measurable_measure_mul_right (hs : MeasurableSet s) : Measurable fun x => μ ((fun y => y * x) ⁻¹' s) := by suffices Measurable fun y => μ ((fun x => (x, y)) ⁻¹' ((fun z : G × G => ((1 : G), z.1 * z.2)) ⁻¹' univ ×ˢ s)) by convert this using 1; ext1 x; congr 1 with y : 1; simp apply measurable_measure_prodMk_right apply measurable_const.prodMk measurable_mul (MeasurableSet.univ.prod hs) infer_instance variable [MeasurableInv G] /-- The map `(x, y) ↦ (x, x⁻¹y)` is measure-preserving. This is the function `S⁻¹` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)`. -/ @[to_additive measurePreserving_prod_neg_add "The map `(x, y) ↦ (x, - x + y)` is measure-preserving."] theorem measurePreserving_prod_inv_mul [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.1, z.1⁻¹ * z.2)) (μ.prod ν) (μ.prod ν) := (measurePreserving_prod_mul μ ν).symm <| MeasurableEquiv.shearMulRight G variable [IsMulLeftInvariant μ] /-- The map `(x, y) ↦ (y, y⁻¹x)` sends `μ × ν` to `ν × μ`. This is the function `S⁻¹R` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_prod_neg_add_swap "The map `(x, y) ↦ (y, - y + x)` sends `μ × ν` to `ν × μ`."] theorem measurePreserving_prod_inv_mul_swap : MeasurePreserving (fun z : G × G => (z.2, z.2⁻¹ * z.1)) (μ.prod ν) (ν.prod μ) := (measurePreserving_prod_inv_mul ν μ).comp measurePreserving_swap /-- The map `(x, y) ↦ (yx, x⁻¹)` is measure-preserving. This is the function `S⁻¹RSR` in [Halmos, §59], where `S` is the map `(x, y) ↦ (x, xy)` and `R` is `Prod.swap`. -/ @[to_additive measurePreserving_add_prod_neg "The map `(x, y) ↦ (y + x, - x)` is measure-preserving."] theorem measurePreserving_mul_prod_inv [IsMulLeftInvariant ν] : MeasurePreserving (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod ν) (μ.prod ν) := by convert (measurePreserving_prod_inv_mul_swap ν μ).comp (measurePreserving_prod_mul_swap μ ν) using 1 ext1 ⟨x, y⟩ simp_rw [Function.comp_apply, mul_inv_rev, inv_mul_cancel_right] @[to_additive] theorem quasiMeasurePreserving_inv : QuasiMeasurePreserving (Inv.inv : G → G) μ μ := by refine ⟨measurable_inv, AbsolutelyContinuous.mk fun s hsm hμs => ?_⟩ rw [map_apply measurable_inv hsm, inv_preimage] have hf : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) := (measurable_snd.mul measurable_fst).prodMk measurable_fst.inv suffices map (fun z : G × G => (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (s⁻¹ ×ˢ s⁻¹) = 0 by simpa only [(measurePreserving_mul_prod_inv μ μ).map_eq, prod_prod, mul_eq_zero (M₀ := ℝ≥0∞), or_self_iff] using this have hsm' : MeasurableSet (s⁻¹ ×ˢ s⁻¹) := hsm.inv.prod hsm.inv simp_rw [map_apply hf hsm', prod_apply_symm (μ := μ) (ν := μ) (hf hsm'), preimage_preimage, mk_preimage_prod, inv_preimage, inv_inv, measure_mono_null inter_subset_right hμs, lintegral_zero] @[to_additive (attr := simp)] theorem measure_inv_null : μ s⁻¹ = 0 ↔ μ s = 0 := by refine ⟨fun hs => ?_, (quasiMeasurePreserving_inv μ).preimage_null⟩ rw [← inv_inv s] exact (quasiMeasurePreserving_inv μ).preimage_null hs @[to_additive (attr := simp)] theorem inv_ae : (ae μ)⁻¹ = ae μ := by refine le_antisymm (quasiMeasurePreserving_inv μ).tendsto_ae ?_ nth_rewrite 1 [← inv_inv (ae μ)] exact Filter.map_mono (quasiMeasurePreserving_inv μ).tendsto_ae @[to_additive (attr := simp)] theorem eventuallyConst_inv_set_ae : EventuallyConst (s⁻¹ : Set G) (ae μ) ↔ EventuallyConst s (ae μ) := by rw [← inv_preimage, eventuallyConst_preimage, Filter.map_inv, inv_ae] @[to_additive] theorem inv_absolutelyContinuous : μ.inv ≪ μ := (quasiMeasurePreserving_inv μ).absolutelyContinuous @[to_additive] theorem absolutelyContinuous_inv : μ ≪ μ.inv := by refine AbsolutelyContinuous.mk fun s _ => ?_ simp_rw [inv_apply μ s, measure_inv_null, imp_self] @[to_additive] theorem lintegral_lintegral_mul_inv [IsMulLeftInvariant ν] (f : G → G → ℝ≥0∞) (hf : AEMeasurable (uncurry f) (μ.prod ν)) : (∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ) = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ := by have h : Measurable fun z : G × G => (z.2 * z.1, z.1⁻¹) := (measurable_snd.mul measurable_fst).prodMk measurable_fst.inv have h2f : AEMeasurable (uncurry fun x y => f (y * x) x⁻¹) (μ.prod ν) := hf.comp_quasiMeasurePreserving (measurePreserving_mul_prod_inv μ ν).quasiMeasurePreserving simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf] conv_rhs => rw [← (measurePreserving_mul_prod_inv μ ν).map_eq] symm exact lintegral_map' (hf.mono' (measurePreserving_mul_prod_inv μ ν).map_eq.absolutelyContinuous) h.aemeasurable @[to_additive] theorem measure_mul_right_null (y : G) : μ ((fun x => x * y) ⁻¹' s) = 0 ↔ μ s = 0 := calc μ ((fun x => x * y) ⁻¹' s) = 0 ↔ μ ((fun x => y⁻¹ * x) ⁻¹' s⁻¹)⁻¹ = 0 := by simp_rw [← inv_preimage, preimage_preimage, mul_inv_rev, inv_inv] _ ↔ μ s = 0 := by simp only [measure_inv_null μ, measure_preimage_mul] @[to_additive] theorem measure_mul_right_ne_zero (h2s : μ s ≠ 0) (y : G) : μ ((fun x => x * y) ⁻¹' s) ≠ 0 := (not_congr (measure_mul_right_null μ y)).mpr h2s @[to_additive] theorem absolutelyContinuous_map_mul_right (g : G) : μ ≪ map (· * g) μ := by refine AbsolutelyContinuous.mk fun s hs => ?_ rw [map_apply (measurable_mul_const g) hs, measure_mul_right_null]; exact id @[to_additive] theorem absolutelyContinuous_map_div_left (g : G) : μ ≪ map (fun h => g / h) μ := by simp_rw [div_eq_mul_inv] have := map_map (μ := μ) (measurable_const_mul g) measurable_inv simp only [Function.comp_def] at this rw [← this] conv_lhs => rw [← map_mul_left_eq_self μ g] exact (absolutelyContinuous_inv μ).map (measurable_const_mul g) /-- This is the computation performed in the proof of [Halmos, §60 Th. A]. -/ @[to_additive "This is the computation performed in the proof of [Halmos, §60 Th. A]."] theorem measure_mul_lintegral_eq [IsMulLeftInvariant ν] (sm : MeasurableSet s) (f : G → ℝ≥0∞) (hf : Measurable f) : (μ s * ∫⁻ y, f y ∂ν) = ∫⁻ x, ν ((fun z => z * x) ⁻¹' s) * f x⁻¹ ∂μ := by rw [← setLIntegral_one, ← lintegral_indicator sm, ← lintegral_lintegral_mul (measurable_const.indicator sm).aemeasurable hf.aemeasurable, ← lintegral_lintegral_mul_inv μ ν] swap · exact (((measurable_const.indicator sm).comp measurable_fst).mul (hf.comp measurable_snd)).aemeasurable have ms : ∀ x : G, Measurable fun y => ((fun z => z * x) ⁻¹' s).indicator (fun _ => (1 : ℝ≥0∞)) y := fun x => measurable_const.indicator (measurable_mul_const _ sm) have : ∀ x y, s.indicator (fun _ : G => (1 : ℝ≥0∞)) (y * x) = ((fun z => z * x) ⁻¹' s).indicator (fun b : G => 1) y := by intro x y; symm; convert indicator_comp_right (M := ℝ≥0∞) fun y => y * x using 2; ext1; rfl simp_rw [this, lintegral_mul_const _ (ms _), lintegral_indicator (measurable_mul_const _ sm), setLIntegral_one] /-- Any two nonzero left-invariant measures are absolutely continuous w.r.t. each other. -/ @[to_additive " Any two nonzero left-invariant measures are absolutely continuous w.r.t. each other. "] theorem absolutelyContinuous_of_isMulLeftInvariant [IsMulLeftInvariant ν] (hν : ν ≠ 0) : μ ≪ ν := by refine AbsolutelyContinuous.mk fun s sm hνs => ?_ have h1 := measure_mul_lintegral_eq μ ν sm 1 measurable_one simp_rw [Pi.one_apply, lintegral_one, mul_one, (measure_mul_right_null ν _).mpr hνs, lintegral_zero, mul_eq_zero (M₀ := ℝ≥0∞), measure_univ_eq_zero.not.mpr hν, or_false] at h1 exact h1 section SigmaFinite variable (μ' ν' : Measure G) [SigmaFinite μ'] [SigmaFinite ν'] [IsMulLeftInvariant μ'] [IsMulLeftInvariant ν'] @[to_additive] theorem ae_measure_preimage_mul_right_lt_top (hμs : μ' s ≠ ∞) : ∀ᵐ x ∂μ', ν' ((· * x) ⁻¹' s) < ∞ := by wlog sm : MeasurableSet s generalizing s · filter_upwards [this ((measure_toMeasurable _).trans_ne hμs) (measurableSet_toMeasurable ..)] with x hx using lt_of_le_of_lt (by gcongr; apply subset_toMeasurable) hx refine ae_of_forall_measure_lt_top_ae_restrict' ν'.inv _ ?_ intro A hA _ h3A simp only [ν'.inv_apply] at h3A apply ae_lt_top (measurable_measure_mul_right ν' sm) have h1 := measure_mul_lintegral_eq μ' ν' sm (A⁻¹.indicator 1) (measurable_one.indicator hA.inv) rw [lintegral_indicator hA.inv] at h1 simp_rw [Pi.one_apply, setLIntegral_one, ← image_inv_eq_inv, indicator_image inv_injective, image_inv_eq_inv, ← indicator_mul_right _ fun x => ν' ((· * x) ⁻¹' s), Function.comp, Pi.one_apply, mul_one] at h1 rw [← lintegral_indicator hA, ← h1] exact ENNReal.mul_ne_top hμs h3A.ne @[to_additive] theorem ae_measure_preimage_mul_right_lt_top_of_ne_zero (h2s : ν' s ≠ 0) (h3s : ν' s ≠ ∞) : ∀ᵐ x ∂μ', ν' ((fun y => y * x) ⁻¹' s) < ∞ := by refine (ae_measure_preimage_mul_right_lt_top ν' ν' h3s).filter_mono ?_ refine (absolutelyContinuous_of_isMulLeftInvariant μ' ν' ?_).ae_le refine mt ?_ h2s intro hν rw [hν, Measure.coe_zero, Pi.zero_apply] /-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A]. Note that if `f` is the characteristic function of a measurable set `t` this states that `μ t = c * μ s` for a constant `c` that does not depend on `μ`. Note: There is a gap in the last step of the proof in [Halmos]. In the last line, the equality `g(x⁻¹)ν(sx⁻¹) = f(x)` holds if we can prove that `0 < ν(sx⁻¹) < ∞`. The first inequality follows from §59, Th. D, but the second inequality is not justified. We prove this inequality for almost all `x` in `MeasureTheory.ae_measure_preimage_mul_right_lt_top_of_ne_zero`. -/ @[to_additive "A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A]. Note that if `f` is the characteristic function of a measurable set `t` this states that `μ t = c * μ s` for a constant `c` that does not depend on `μ`.
Note: There is a gap in the last step of the proof in [Halmos]. In the last line, the equality `g(-x) + ν(s - x) = f(x)` holds if we can prove that `0 < ν(s - x) < ∞`. The first inequality follows from §59, Th. D, but the second inequality is not justified. We prove this inequality for almost all `x` in `MeasureTheory.ae_measure_preimage_add_right_lt_top_of_ne_zero`."] theorem measure_lintegral_div_measure (sm : MeasurableSet s) (h2s : ν' s ≠ 0) (h3s : ν' s ≠ ∞) (f : G → ℝ≥0∞) (hf : Measurable f) : (μ' s * ∫⁻ y, f y⁻¹ / ν' ((· * y⁻¹) ⁻¹' s) ∂ν') = ∫⁻ x, f x ∂μ' := by
Mathlib/MeasureTheory/Group/Prod.lean
296
303
/- Copyright (c) 2017 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.WSeq.Basic import Mathlib.Data.WSeq.Defs import Mathlib.Data.WSeq.Productive import Mathlib.Data.WSeq.Relation deprecated_module (since := "2025-04-13")
Mathlib/Data/Seq/WSeq.lean
1,111
1,112
/- Copyright (c) 2021 Yakov Pechersky. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yakov Pechersky -/ import Mathlib.Algebra.Order.Monoid.Canonical.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.OrderDual import Mathlib.Algebra.BigOperators.Group.List.Basic /-! # Big operators on a list in ordered groups This file contains the results concerning the interaction of list big operators with ordered groups/monoids. -/ variable {ι α M N : Type*} namespace List section Monoid variable [Monoid M] @[to_additive sum_le_sum] lemma Forall₂.prod_le_prod' [Preorder M] [MulRightMono M] [MulLeftMono M] {l₁ l₂ : List M} (h : Forall₂ (· ≤ ·) l₁ l₂) : l₁.prod ≤ l₂.prod := by induction h with | nil => rfl | cons hab ih ih' => simpa only [prod_cons] using mul_le_mul' hab ih' /-- If `l₁` is a sublist of `l₂` and all elements of `l₂` are greater than or equal to one, then `l₁.prod ≤ l₂.prod`. One can prove a stronger version assuming `∀ a ∈ l₂.diff l₁, 1 ≤ a` instead of `∀ a ∈ l₂, 1 ≤ a` but this lemma is not yet in `mathlib`. -/ @[to_additive sum_le_sum "If `l₁` is a sublist of `l₂` and all elements of `l₂` are nonnegative, then `l₁.sum ≤ l₂.sum`. One can prove a stronger version assuming `∀ a ∈ l₂.diff l₁, 0 ≤ a` instead of `∀ a ∈ l₂, 0 ≤ a` but this lemma is not yet in `mathlib`."] lemma Sublist.prod_le_prod' [Preorder M] [MulRightMono M] [MulLeftMono M] {l₁ l₂ : List M} (h : l₁ <+ l₂) (h₁ : ∀ a ∈ l₂, (1 : M) ≤ a) : l₁.prod ≤ l₂.prod := by induction h with | slnil => rfl | cons a _ ih' => simp only [prod_cons, forall_mem_cons] at h₁ ⊢ exact (ih' h₁.2).trans (le_mul_of_one_le_left' h₁.1) | cons₂ a _ ih' => simp only [prod_cons, forall_mem_cons] at h₁ ⊢ exact mul_le_mul_left' (ih' h₁.2) _ @[to_additive sum_le_sum] lemma SublistForall₂.prod_le_prod' [Preorder M] [MulRightMono M] [MulLeftMono M] {l₁ l₂ : List M} (h : SublistForall₂ (· ≤ ·) l₁ l₂) (h₁ : ∀ a ∈ l₂, (1 : M) ≤ a) : l₁.prod ≤ l₂.prod := let ⟨_, hall, hsub⟩ := sublistForall₂_iff.1 h hall.prod_le_prod'.trans <| hsub.prod_le_prod' h₁ @[to_additive sum_le_sum] lemma prod_le_prod' [Preorder M] [MulRightMono M] [MulLeftMono M] {l : List ι} {f g : ι → M} (h : ∀ i ∈ l, f i ≤ g i) : (l.map f).prod ≤ (l.map g).prod := Forall₂.prod_le_prod' <| by simpa @[to_additive sum_lt_sum] lemma prod_lt_prod' [Preorder M] [MulLeftStrictMono M] [MulLeftMono M] [MulRightStrictMono M] [MulRightMono M] {l : List ι} (f g : ι → M) (h₁ : ∀ i ∈ l, f i ≤ g i) (h₂ : ∃ i ∈ l, f i < g i) : (l.map f).prod < (l.map g).prod := by induction' l with i l ihl · rcases h₂ with ⟨_, ⟨⟩, _⟩ simp only [forall_mem_cons, map_cons, prod_cons] at h₁ ⊢ simp only [mem_cons, exists_eq_or_imp] at h₂ cases h₂ · exact mul_lt_mul_of_lt_of_le ‹_› (prod_le_prod' h₁.2) · exact mul_lt_mul_of_le_of_lt h₁.1 <| ihl h₁.2 ‹_› @[to_additive] lemma prod_lt_prod_of_ne_nil [Preorder M] [MulLeftStrictMono M] [MulLeftMono M] [MulRightStrictMono M] [MulRightMono M] {l : List ι} (hl : l ≠ []) (f g : ι → M) (hlt : ∀ i ∈ l, f i < g i) : (l.map f).prod < (l.map g).prod := (prod_lt_prod' f g fun i hi => (hlt i hi).le) <| (exists_mem_of_ne_nil l hl).imp fun i hi => ⟨hi, hlt i hi⟩ @[to_additive sum_le_card_nsmul] lemma prod_le_pow_card [Preorder M] [MulRightMono M] [MulLeftMono M] (l : List M) (n : M) (h : ∀ x ∈ l, x ≤ n) : l.prod ≤ n ^ l.length := by simpa only [map_id', map_const', prod_replicate] using prod_le_prod' h @[to_additive card_nsmul_le_sum] lemma pow_card_le_prod [Preorder M] [MulRightMono M] [MulLeftMono M] (l : List M) (n : M) (h : ∀ x ∈ l, n ≤ x) : n ^ l.length ≤ l.prod := @prod_le_pow_card Mᵒᵈ _ _ _ _ l n h @[to_additive exists_lt_of_sum_lt] lemma exists_lt_of_prod_lt' [LinearOrder M] [MulRightMono M] [MulLeftMono M] {l : List ι} (f g : ι → M) (h : (l.map f).prod < (l.map g).prod) : ∃ i ∈ l, f i < g i := by contrapose! h exact prod_le_prod' h @[to_additive exists_le_of_sum_le] lemma exists_le_of_prod_le' [LinearOrder M] [MulLeftStrictMono M] [MulLeftMono M] [MulRightStrictMono M] [MulRightMono M] {l : List ι} (hl : l ≠ []) (f g : ι → M) (h : (l.map f).prod ≤ (l.map g).prod) : ∃ x ∈ l, f x ≤ g x := by contrapose! h exact prod_lt_prod_of_ne_nil hl _ _ h @[to_additive sum_nonneg] lemma one_le_prod_of_one_le [Preorder M] [MulLeftMono M] {l : List M} (hl₁ : ∀ x ∈ l, (1 : M) ≤ x) : 1 ≤ l.prod := by -- We don't use `pow_card_le_prod` to avoid assumption -- [covariant_class M M (function.swap (*)) (≤)] induction' l with hd tl ih · rfl rw [prod_cons] exact one_le_mul (hl₁ hd mem_cons_self) (ih fun x h => hl₁ x (mem_cons_of_mem hd h))
@[to_additive] lemma max_prod_le (l : List α) (f g : α → M) [LinearOrder M] [MulLeftMono M] [MulRightMono M] : max (l.map f).prod (l.map g).prod ≤ (l.map fun i ↦ max (f i) (g i)).prod := by rw [max_le_iff] constructor <;> apply List.prod_le_prod' <;> intros · apply le_max_left
Mathlib/Algebra/Order/BigOperators/Group/List.lean
122
128
/- Copyright (c) 2022 Riccardo Brasca. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Riccardo Brasca -/ import Mathlib.NumberTheory.Cyclotomic.Discriminant import Mathlib.RingTheory.Polynomial.Eisenstein.IsIntegral import Mathlib.RingTheory.Ideal.Norm.AbsNorm import Mathlib.RingTheory.Prime /-! # Ring of integers of `p ^ n`-th cyclotomic fields We gather results about cyclotomic extensions of `ℚ`. In particular, we compute the ring of integers of a `p ^ n`-th cyclotomic extension of `ℚ`. ## Main results * `IsCyclotomicExtension.Rat.isIntegralClosure_adjoin_singleton_of_prime_pow`: if `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. * `IsCyclotomicExtension.Rat.cyclotomicRing_isIntegralClosure_of_prime_pow`: the integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. * `IsCyclotomicExtension.Rat.absdiscr_prime_pow` and related results: the absolute discriminant of cyclotomic fields. -/ universe u open Algebra IsCyclotomicExtension Polynomial NumberField open scoped Cyclotomic Nat variable {p : ℕ+} {k : ℕ} {K : Type u} [Field K] {ζ : K} [hp : Fact (p : ℕ).Prime] namespace IsCyclotomicExtension.Rat variable [CharZero K] /-- The discriminant of the power basis given by `ζ - 1`. -/ theorem discr_prime_pow_ne_two' [IsCyclotomicExtension {p ^ (k + 1)} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ (k + 1))) (hk : p ^ (k + 1) ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ (k + 1) : ℕ).totient / 2) * p ^ ((p : ℕ) ^ k * ((p - 1) * (k + 1) - 1)) := by rw [← discr_prime_pow_ne_two hζ (cyclotomic.irreducible_rat (p ^ (k + 1)).pos) hk] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm theorem discr_odd_prime' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) (hodd : p ≠ 2) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ (((p : ℕ) - 1) / 2) * p ^ ((p : ℕ) - 2) := by rw [← discr_odd_prime hζ (cyclotomic.irreducible_rat hp.out.pos) hodd] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm /-- The discriminant of the power basis given by `ζ - 1`. Beware that in the cases `p ^ k = 1` and `p ^ k = 2` the formula uses `1 / 2 = 0` and `0 - 1 = 0`. It is useful only to have a uniform result. See also `IsCyclotomicExtension.Rat.discr_prime_pow_eq_unit_mul_pow'`. -/ theorem discr_prime_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : discr ℚ (hζ.subOnePowerBasis ℚ).basis = (-1) ^ ((p ^ k : ℕ).totient / 2) * p ^ ((p : ℕ) ^ (k - 1) * ((p - 1) * k - 1)) := by rw [← discr_prime_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos)] exact hζ.discr_zeta_eq_discr_zeta_sub_one.symm /-- If `p` is a prime and `IsCyclotomicExtension {p ^ k} K L`, then there are `u : ℤˣ` and `n : ℕ` such that the discriminant of the power basis given by `ζ - 1` is `u * p ^ n`. Often this is enough and less cumbersome to use than `IsCyclotomicExtension.Rat.discr_prime_pow'`. -/ theorem discr_prime_pow_eq_unit_mul_pow' [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : ∃ (u : ℤˣ) (n : ℕ), discr ℚ (hζ.subOnePowerBasis ℚ).basis = u * p ^ n := by rw [hζ.discr_zeta_eq_discr_zeta_sub_one.symm] exact discr_prime_pow_eq_unit_mul_pow hζ (cyclotomic.irreducible_rat (p ^ k).pos) /-- If `K` is a `p ^ k`-th cyclotomic extension of `ℚ`, then `(adjoin ℤ {ζ})` is the integral closure of `ℤ` in `K`. -/ theorem isIntegralClosure_adjoin_singleton_of_prime_pow [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : IsIntegralClosure (adjoin ℤ ({ζ} : Set K)) ℤ K := by refine ⟨Subtype.val_injective, @fun x => ⟨fun h => ⟨⟨x, ?_⟩, rfl⟩, ?_⟩⟩ swap · rintro ⟨y, rfl⟩ exact IsIntegral.algebraMap ((le_integralClosure_iff_isIntegral.1 (adjoin_le_integralClosure (hζ.isIntegral (p ^ k).pos))).isIntegral _) let B := hζ.subOnePowerBasis ℚ have hint : IsIntegral ℤ B.gen := (hζ.isIntegral (p ^ k).pos).sub isIntegral_one -- Porting note: the following `letI` was not needed because the locale `cyclotomic` set it -- as instances. letI := IsCyclotomicExtension.finiteDimensional {p ^ k} ℚ K have H := discr_mul_isIntegral_mem_adjoin ℚ hint h obtain ⟨u, n, hun⟩ := discr_prime_pow_eq_unit_mul_pow' hζ rw [hun] at H replace H := Subalgebra.smul_mem _ H u.inv rw [← smul_assoc, ← smul_mul_assoc, Units.inv_eq_val_inv, zsmul_eq_mul, ← Int.cast_mul, Units.inv_mul, Int.cast_one, one_mul, smul_def, map_pow] at H cases k · haveI : IsCyclotomicExtension {1} ℚ K := by simpa using hcycl have : x ∈ (⊥ : Subalgebra ℚ K) := by rw [singleton_one ℚ K] exact mem_top obtain ⟨y, rfl⟩ := mem_bot.1 this replace h := (isIntegral_algebraMap_iff (algebraMap ℚ K).injective).1 h obtain ⟨z, hz⟩ := IsIntegrallyClosed.isIntegral_iff.1 h rw [← hz, ← IsScalarTower.algebraMap_apply] exact Subalgebra.algebraMap_mem _ _ · have hmin : (minpoly ℤ B.gen).IsEisensteinAt (Submodule.span ℤ {((p : ℕ) : ℤ)}) := by have h₁ := minpoly.isIntegrallyClosed_eq_field_fractions' ℚ hint have h₂ := hζ.minpoly_sub_one_eq_cyclotomic_comp (cyclotomic.irreducible_rat (p ^ _).pos) rw [IsPrimitiveRoot.subOnePowerBasis_gen] at h₁ rw [h₁, ← map_cyclotomic_int, show Int.castRingHom ℚ = algebraMap ℤ ℚ by rfl, show X + 1 = map (algebraMap ℤ ℚ) (X + 1) by simp, ← map_comp] at h₂ rw [IsPrimitiveRoot.subOnePowerBasis_gen, map_injective (algebraMap ℤ ℚ) (algebraMap ℤ ℚ).injective_int h₂] exact cyclotomic_prime_pow_comp_X_add_one_isEisensteinAt p _ refine adjoin_le ?_ (mem_adjoin_of_smul_prime_pow_smul_of_minpoly_isEisensteinAt (n := n) (Nat.prime_iff_prime_int.1 hp.out) hint h (by simpa using H) hmin) simp only [Set.singleton_subset_iff, SetLike.mem_coe] exact Subalgebra.sub_mem _ (self_mem_adjoin_singleton ℤ _) (Subalgebra.one_mem _) theorem isIntegralClosure_adjoin_singleton_of_prime [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ ↑p) : IsIntegralClosure (adjoin ℤ ({ζ} : Set K)) ℤ K := by rw [← pow_one p] at hζ hcycl exact isIntegralClosure_adjoin_singleton_of_prime_pow hζ /-- The integral closure of `ℤ` inside `CyclotomicField (p ^ k) ℚ` is `CyclotomicRing (p ^ k) ℤ ℚ`. -/ theorem cyclotomicRing_isIntegralClosure_of_prime_pow : IsIntegralClosure (CyclotomicRing (p ^ k) ℤ ℚ) ℤ (CyclotomicField (p ^ k) ℚ) := by have hζ := zeta_spec (p ^ k) ℚ (CyclotomicField (p ^ k) ℚ) refine ⟨IsFractionRing.injective _ _, @fun x => ⟨fun h => ⟨⟨x, ?_⟩, rfl⟩, ?_⟩⟩ · obtain ⟨y, rfl⟩ := (isIntegralClosure_adjoin_singleton_of_prime_pow hζ).isIntegral_iff.1 h refine adjoin_mono ?_ y.2 simp only [PNat.pow_coe, Set.singleton_subset_iff, Set.mem_setOf_eq] exact hζ.pow_eq_one · rintro ⟨y, rfl⟩ exact IsIntegral.algebraMap ((IsCyclotomicExtension.integral {p ^ k} ℤ _).isIntegral _) theorem cyclotomicRing_isIntegralClosure_of_prime : IsIntegralClosure (CyclotomicRing p ℤ ℚ) ℤ (CyclotomicField p ℚ) := by rw [← pow_one p] exact cyclotomicRing_isIntegralClosure_of_prime_pow end IsCyclotomicExtension.Rat section PowerBasis open IsCyclotomicExtension.Rat namespace IsPrimitiveRoot section CharZero variable [CharZero K] /-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p ^ k`-th root of unity and `K` is a `p ^ k`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : adjoin ℤ ({ζ} : Set K) ≃ₐ[ℤ] 𝓞 K := let _ := isIntegralClosure_adjoin_singleton_of_prime_pow hζ IsIntegralClosure.equiv ℤ (adjoin ℤ ({ζ} : Set K)) K (𝓞 K) /-- The ring of integers of a `p ^ k`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance IsCyclotomicExtension.ringOfIntegers [IsCyclotomicExtension {p ^ k} ℚ K] : IsCyclotomicExtension {p ^ k} ℤ (𝓞 K) := let _ := (zeta_spec (p ^ k) ℚ K).adjoin_isCyclotomicExtension ℤ IsCyclotomicExtension.equiv _ ℤ _ (zeta_spec (p ^ k) ℚ K).adjoinEquivRingOfIntegers /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis ℤ (𝓞 K) := (Algebra.adjoin.powerBasis' (hζ.isIntegral (p ^ k).pos)).map hζ.adjoinEquivRingOfIntegers /-- Abbreviation to see a primitive root of unity as a member of the ring of integers. -/ abbrev toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : 𝓞 K := ⟨ζ, hζ.isIntegral k.pos⟩ end CharZero lemma coe_toInteger {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : hζ.toInteger.1 = ζ := rfl /-- `𝓞 K ⧸ Ideal.span {ζ - 1}` is finite. -/ lemma finite_quotient_toInteger_sub_one [NumberField K] {k : ℕ+} (hk : 1 < k) (hζ : IsPrimitiveRoot ζ k) : Finite (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) := by refine Ideal.finiteQuotientOfFreeOfNeBot _ (fun h ↦ ?_) simp only [Ideal.span_singleton_eq_bot, sub_eq_zero, ← Subtype.coe_inj] at h exact hζ.ne_one hk (RingOfIntegers.ext_iff.1 h) /-- We have that `𝓞 K ⧸ Ideal.span {ζ - 1}` has cardinality equal to the norm of `ζ - 1`. See the results below to compute this norm in various cases. -/ lemma card_quotient_toInteger_sub_one [NumberField K] {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : Nat.card (𝓞 K ⧸ Ideal.span {hζ.toInteger - 1}) = (Algebra.norm ℤ (hζ.toInteger - 1)).natAbs := by rw [← Submodule.cardQuot_apply, ← Ideal.absNorm_apply, Ideal.absNorm_span_singleton] lemma toInteger_isPrimitiveRoot {k : ℕ+} (hζ : IsPrimitiveRoot ζ k) : IsPrimitiveRoot hζ.toInteger k := IsPrimitiveRoot.of_map_of_injective (by exact hζ) RingOfIntegers.coe_injective variable [CharZero K] @[simp] theorem integralPowerBasis_gen [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.gen = hζ.toInteger := Subtype.ext <| show algebraMap _ K hζ.integralPowerBasis.gen = _ by rw [integralPowerBasis, PowerBasis.map_gen, adjoin.powerBasis'_gen] simp only [adjoinEquivRingOfIntegers_apply, IsIntegralClosure.algebraMap_lift] rfl #adaptation_note /-- https://github.com/leanprover/lean4/pull/5338 We name `hcycl` so it can be used as a named argument, but since https://github.com/leanprover/lean4/pull/5338, this is considered unused, so we need to disable the linter. -/ set_option linter.unusedVariables false in @[simp] theorem integralPowerBasis_dim [hcycl : IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.integralPowerBasis.dim = φ (p ^ k) := by simp [integralPowerBasis, ← cyclotomic_eq_minpoly hζ, natDegree_cyclotomic] /-- The algebra isomorphism `adjoin ℤ {ζ} ≃ₐ[ℤ] (𝓞 K)`, where `ζ` is a primitive `p`-th root of unity and `K` is a `p`-th cyclotomic extension of `ℚ`. -/ @[simps!] noncomputable def _root_.IsPrimitiveRoot.adjoinEquivRingOfIntegers' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : adjoin ℤ ({ζ} : Set K) ≃ₐ[ℤ] 𝓞 K := have : IsCyclotomicExtension {p ^ 1} ℚ K := by convert hcycl; rw [pow_one] adjoinEquivRingOfIntegers (p := p) (k := 1) (ζ := ζ) (by rwa [pow_one]) /-- The ring of integers of a `p`-th cyclotomic extension of `ℚ` is a cyclotomic extension. -/ instance _root_.IsCyclotomicExtension.ring_of_integers' [IsCyclotomicExtension {p} ℚ K] : IsCyclotomicExtension {p} ℤ (𝓞 K) := let _ := (zeta_spec p ℚ K).adjoin_isCyclotomicExtension ℤ IsCyclotomicExtension.equiv _ ℤ _ (zeta_spec p ℚ K).adjoinEquivRingOfIntegers' /-- The integral `PowerBasis` of `𝓞 K` given by a primitive root of unity, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def integralPowerBasis' [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis ℤ (𝓞 K) := have : IsCyclotomicExtension {p ^ 1} ℚ K := by convert hcycl; rw [pow_one] integralPowerBasis (p := p) (k := 1) (ζ := ζ) (by rwa [pow_one]) @[simp] theorem integralPowerBasis'_gen [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.gen = hζ.toInteger := integralPowerBasis_gen (hcycl := by rwa [pow_one]) (by rwa [pow_one]) @[simp] theorem power_basis_int'_dim [hcycl : IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.integralPowerBasis'.dim = φ p := by rw [integralPowerBasis', integralPowerBasis_dim (hcycl := by rwa [pow_one]) (by rwa [pow_one]), pow_one] /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p ^ k` cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : PowerBasis ℤ (𝓞 K) := PowerBasis.ofGenMemAdjoin' hζ.integralPowerBasis (RingOfIntegers.isIntegral _) (by simp only [integralPowerBasis_gen, toInteger] convert Subalgebra.add_mem _ (self_mem_adjoin_singleton ℤ (⟨ζ - 1, _⟩ : 𝓞 K)) (Subalgebra.one_mem _) · simp · exact Subalgebra.sub_mem _ (hζ.isIntegral (by simp)) (Subalgebra.one_mem _)) @[simp] theorem subOneIntegralPowerBasis_gen [IsCyclotomicExtension {p ^ k} ℚ K] (hζ : IsPrimitiveRoot ζ ↑(p ^ k)) : hζ.subOneIntegralPowerBasis.gen = ⟨ζ - 1, Subalgebra.sub_mem _ (hζ.isIntegral (p ^ k).pos) (Subalgebra.one_mem _)⟩ := by simp [subOneIntegralPowerBasis] /-- The integral `PowerBasis` of `𝓞 K` given by `ζ - 1`, where `K` is a `p`-th cyclotomic extension of `ℚ`. -/ noncomputable def subOneIntegralPowerBasis' [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : PowerBasis ℤ (𝓞 K) := have : IsCyclotomicExtension {p ^ 1} ℚ K := by rwa [pow_one] subOneIntegralPowerBasis (p := p) (k := 1) (ζ := ζ) (by rwa [pow_one])
@[simp, nolint unusedHavesSuffices] theorem subOneIntegralPowerBasis'_gen [IsCyclotomicExtension {p} ℚ K] (hζ : IsPrimitiveRoot ζ p) : hζ.subOneIntegralPowerBasis'.gen = hζ.toInteger - 1 := -- The `unusedHavesSuffices` linter incorrectly thinks this `have` is unnecessary.
Mathlib/NumberTheory/Cyclotomic/Rat.lean
280
284
/- Copyright (c) 2023 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes -/ import Mathlib.GroupTheory.CoprodI import Mathlib.GroupTheory.Coprod.Basic import Mathlib.GroupTheory.Complement /-! ## Pushouts of Monoids and Groups This file defines wide pushouts of monoids and groups and proves some properties of the amalgamated product of groups (i.e. the special case where all the maps in the diagram are injective). ## Main definitions - `Monoid.PushoutI`: the pushout of a diagram of monoids indexed by a type `ι` - `Monoid.PushoutI.base`: the map from the amalgamating monoid to the pushout - `Monoid.PushoutI.of`: the map from each Monoid in the family to the pushout - `Monoid.PushoutI.lift`: the universal property used to define homomorphisms out of the pushout. - `Monoid.PushoutI.NormalWord`: a normal form for words in the pushout - `Monoid.PushoutI.of_injective`: if all the maps in the diagram are injective in a pushout of groups then so is `of` - `Monoid.PushoutI.Reduced.eq_empty_of_mem_range`: For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base monoid. ## References * The normal form theorem follows these [notes](https://webspace.maths.qmul.ac.uk/i.m.chiswell/ggt/lecture_notes/lecture2.pdf) from Queen Mary University ## Tags amalgamated product, pushout, group -/ namespace Monoid open CoprodI Subgroup Coprod Function List variable {ι : Type*} {G : ι → Type*} {H : Type*} {K : Type*} [Monoid K] /-- The relation we quotient by to form the pushout -/ def PushoutI.con [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Con (Coprod (CoprodI G) H) := conGen (fun x y : Coprod (CoprodI G) H => ∃ i x', x = inl (of (φ i x')) ∧ y = inr x') /-- The indexed pushout of monoids, which is the pushout in the category of monoids, or the category of groups. -/ def PushoutI [∀ i, Monoid (G i)] [Monoid H] (φ : ∀ i, H →* G i) : Type _ := (PushoutI.con φ).Quotient namespace PushoutI section Monoid variable [∀ i, Monoid (G i)] [Monoid H] {φ : ∀ i, H →* G i} protected instance mul : Mul (PushoutI φ) := by delta PushoutI; infer_instance protected instance one : One (PushoutI φ) := by delta PushoutI; infer_instance instance monoid : Monoid (PushoutI φ) := { Con.monoid _ with toMul := PushoutI.mul toOne := PushoutI.one } /-- The map from each indexing group into the pushout -/ def of (i : ι) : G i →* PushoutI φ := (Con.mk' _).comp <| inl.comp CoprodI.of variable (φ) in /-- The map from the base monoid into the pushout -/ def base : H →* PushoutI φ := (Con.mk' _).comp inr theorem of_comp_eq_base (i : ι) : (of i).comp (φ i) = (base φ) := by ext x apply (Con.eq _).2 refine ConGen.Rel.of _ _ ?_ simp only [MonoidHom.comp_apply, Set.mem_iUnion, Set.mem_range] exact ⟨_, _, rfl, rfl⟩ variable (φ) in theorem of_apply_eq_base (i : ι) (x : H) : of i (φ i x) = base φ x := by rw [← MonoidHom.comp_apply, of_comp_eq_base] /-- Define a homomorphism out of the pushout of monoids be defining it on each object in the diagram -/ def lift (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) : PushoutI φ →* K := Con.lift _ (Coprod.lift (CoprodI.lift f) k) <| by apply Con.conGen_le fun x y => ?_ rintro ⟨i, x', rfl, rfl⟩ simp only [DFunLike.ext_iff, MonoidHom.coe_comp, comp_apply] at hf simp [hf] @[simp] theorem lift_of (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) {i : ι} (g : G i) : (lift f k hf) (of i g : PushoutI φ) = f i g := by delta PushoutI lift of simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inl, CoprodI.lift_of] @[simp] theorem lift_base (f : ∀ i, G i →* K) (k : H →* K) (hf : ∀ i, (f i).comp (φ i) = k) (g : H) : (lift f k hf) (base φ g : PushoutI φ) = k g := by delta PushoutI lift base simp only [MonoidHom.coe_comp, Con.coe_mk', comp_apply, Con.lift_coe, lift_apply_inr] -- `ext` attribute should be lower priority then `hom_ext_nonempty` @[ext 1199] theorem hom_ext {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) (hbase : f.comp (base φ) = g.comp (base φ)) : f = g := (MonoidHom.cancel_right Con.mk'_surjective).mp <| Coprod.hom_ext (CoprodI.ext_hom _ _ h) hbase @[ext high] theorem hom_ext_nonempty [hn : Nonempty ι] {f g : PushoutI φ →* K} (h : ∀ i, f.comp (of i : G i →* _) = g.comp (of i : G i →* _)) : f = g := hom_ext h <| by cases hn with | intro i => ext rw [← of_comp_eq_base i, ← MonoidHom.comp_assoc, h, MonoidHom.comp_assoc] /-- The equivalence that is part of the universal property of the pushout. A hom out of the pushout is just a morphism out of all groups in the pushout that satisfies a commutativity condition. -/ @[simps] def homEquiv : (PushoutI φ →* K) ≃ { f : (Π i, G i →* K) × (H →* K) // ∀ i, (f.1 i).comp (φ i) = f.2 } := { toFun := fun f => ⟨(fun i => f.comp (of i), f.comp (base φ)), fun i => by rw [MonoidHom.comp_assoc, of_comp_eq_base]⟩ invFun := fun f => lift f.1.1 f.1.2 f.2, left_inv := fun _ => hom_ext (by simp [DFunLike.ext_iff]) (by simp [DFunLike.ext_iff]) right_inv := fun ⟨⟨_, _⟩, _⟩ => by simp [DFunLike.ext_iff, funext_iff] } /-- The map from the coproduct into the pushout -/ def ofCoprodI : CoprodI G →* PushoutI φ := CoprodI.lift of @[simp] theorem ofCoprodI_of (i : ι) (g : G i) : (ofCoprodI (CoprodI.of g) : PushoutI φ) = of i g := by simp [ofCoprodI] theorem induction_on {motive : PushoutI φ → Prop} (x : PushoutI φ) (of : ∀ (i : ι) (g : G i), motive (of i g)) (base : ∀ h, motive (base φ h)) (mul : ∀ x y, motive x → motive y → motive (x * y)) : motive x := by delta PushoutI PushoutI.of PushoutI.base at * induction x using Con.induction_on with | H x => induction x using Coprod.induction_on with | inl g => induction g using CoprodI.induction_on with | of i g => exact of i g | mul x y ihx ihy => rw [map_mul] exact mul _ _ ihx ihy | one => simpa using base 1 | inr h => exact base h | mul x y ihx ihy => exact mul _ _ ihx ihy end Monoid variable [∀ i, Group (G i)] [Group H] {φ : ∀ i, H →* G i} instance : Group (PushoutI φ) := { Con.group (PushoutI.con φ) with toMonoid := PushoutI.monoid } namespace NormalWord /- In this section we show that there is a normal form for words in the amalgamated product. To have a normal form, we need to pick canonical choice of element of each right coset of the base group. The choice of element in the base group itself is `1`. Given a choice of element of each right coset, given by the type `Transversal φ` we can find a normal form. The normal form for an element is an element of the base group, multiplied by a word in the coproduct, where each letter in the word is the canonical choice of element of its coset. We then show that all groups in the diagram act faithfully on the normal form. This implies that the maps into the coproduct are injective. We demonstrate the action is faithful using the equivalence `equivPair`. We show that `G i` acts faithfully on `Pair d i` and that `Pair d i` is isomorphic to `NormalWord d`. Here, `d` is a `Transversal`. A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. We then show that the equivalence between `NormalWord` and `PushoutI`, between the set of normal words and the elements of the amalgamated product. The key to this is the theorem `prod_smul_empty`, which says that going from `NormalWord` to `PushoutI` and back is the identity. This is proven by induction on the word using `consRecOn`. -/ variable (φ) /-- The data we need to pick a normal form for words in the pushout. We need to pick a canonical element of each coset. We also need all the maps in the diagram to be injective -/ structure Transversal : Type _ where /-- All maps in the diagram are injective -/ injective : ∀ i, Injective (φ i) /-- The underlying set, containing exactly one element of each coset of the base group -/ set : ∀ i, Set (G i) /-- The chosen element of the base group itself is the identity -/ one_mem : ∀ i, 1 ∈ set i /-- We have exactly one element of each coset of the base group -/ compl : ∀ i, IsComplement (φ i).range (set i) theorem transversal_nonempty (hφ : ∀ i, Injective (φ i)) : Nonempty (Transversal φ) := by choose t ht using fun i => (φ i).range.exists_isComplement_right 1 apply Nonempty.intro exact { injective := hφ set := t one_mem := fun i => (ht i).2 compl := fun i => (ht i).1 } variable {φ} /-- The normal form for words in the pushout. Every element of the pushout is the product of an element of the base group and a word made up of letters each of which is in the transversal. -/ structure _root_.Monoid.PushoutI.NormalWord (d : Transversal φ) extends CoprodI.Word G where /-- Every `NormalWord` is the product of an element of the base group and a word made up of letters each of which is in the transversal. `head` is that element of the base group. -/ head : H /-- All letter in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ toList → g ∈ d.set i /-- A `Pair d i` is a word in the coproduct, `Coprod G`, the `tail`, and an element of the group `G i`, the `head`. The first letter of the `tail` must not be an element of `G i`. Note that the `head` may be `1` Every letter in the `tail` must be in the transversal given by `d`. Similar to `Monoid.CoprodI.Pair` except every letter must be in the transversal (not including the head letter). -/ structure Pair (d : Transversal φ) (i : ι) extends CoprodI.Word.Pair G i where /-- All letters in the word are in the transversal. -/ normalized : ∀ i g, ⟨i, g⟩ ∈ tail.toList → g ∈ d.set i variable {d : Transversal φ} /-- The empty normalized word, representing the identity element of the group. -/ @[simps!] def empty : NormalWord d := ⟨CoprodI.Word.empty, 1, fun i g => by simp [CoprodI.Word.empty]⟩ instance : Inhabited (NormalWord d) := ⟨NormalWord.empty⟩ instance (i : ι) : Inhabited (Pair d i) := ⟨{ (empty : NormalWord d) with head := 1, tail := _, fstIdx_ne := fun h => by cases h }⟩ @[ext] theorem ext {w₁ w₂ : NormalWord d} (hhead : w₁.head = w₂.head) (hlist : w₁.toList = w₂.toList) : w₁ = w₂ := by rcases w₁ with ⟨⟨_, _, _⟩, _, _⟩ rcases w₂ with ⟨⟨_, _, _⟩, _, _⟩ simp_all open Subgroup.IsComplement instance baseAction : MulAction H (NormalWord d) := { smul := fun h w => { w with head := h * w.head }, one_smul := by simp [instHSMul] mul_smul := by simp [instHSMul, mul_assoc] } theorem base_smul_def' (h : H) (w : NormalWord d) : h • w = { w with head := h * w.head } := rfl /-- Take the product of a normal word as an element of the `PushoutI`. We show that this is bijective, in `NormalWord.equiv`. -/ def prod (w : NormalWord d) : PushoutI φ := base φ w.head * ofCoprodI (w.toWord).prod @[simp] theorem prod_base_smul (h : H) (w : NormalWord d) : (h • w).prod = base φ h * w.prod := by simp only [base_smul_def', prod, map_mul, mul_assoc] @[simp] theorem prod_empty : (empty : NormalWord d).prod = 1 := by simp [prod, empty] /-- A constructor that multiplies a `NormalWord` by an element, with condition to make sure the underlying list does get longer. -/ @[simps!] noncomputable def cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : NormalWord d := letI n := (d.compl i).equiv (g * (φ i w.head)) letI w' := Word.cons (n.2 : G i) w.toWord hmw (mt (coe_equiv_snd_eq_one_iff_mem _ (d.one_mem _)).1 (mt (mul_mem_cancel_right (by simp)).1 hgr)) { toWord := w' head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by simp only [w', Word.cons, mem_cons, Sigma.mk.inj_iff] at hg rcases hg with ⟨rfl, hg | hg⟩ · simp · exact w.normalized _ _ (by assumption) } @[simp] theorem prod_cons {i} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : (cons g w hmw hgr).prod = of i g * w.prod := by simp [prod, cons, ← of_apply_eq_base φ i, equiv_fst_eq_mul_inv, mul_assoc] variable [DecidableEq ι] [∀ i, DecidableEq (G i)] /-- Given a word in `CoprodI`, if every letter is in the transversal and when we multiply by an element of the base group it still has this property, then the element of the base group we multiplied by was one. -/ theorem eq_one_of_smul_normalized (w : CoprodI.Word G) {i : ι} (h : H) (hw : ∀ i g, ⟨i, g⟩ ∈ w.toList → g ∈ d.set i) (hφw : ∀ j g, ⟨j, g⟩ ∈ (CoprodI.of (φ i h) • w).toList → g ∈ d.set j) : h = 1 := by simp only [← (d.compl _).equiv_snd_eq_self_iff_mem (one_mem _)] at hw hφw have hhead : ((d.compl i).equiv (Word.equivPair i w).head).2 = (Word.equivPair i w).head := by rw [Word.equivPair_head] split_ifs with h · rcases h with ⟨_, rfl⟩ exact hw _ _ (List.head_mem _) · rw [equiv_one (d.compl i) (one_mem _) (d.one_mem _)] by_contra hh1 have := hφw i (φ i h * (Word.equivPair i w).head) ?_ · apply hh1 rw [equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩, hhead] at this simpa [((injective_iff_map_eq_one' _).1 (d.injective i))] using this · simp only [Word.mem_smul_iff, not_true, false_and, ne_eq, Option.mem_def, mul_right_inj, exists_eq_right', mul_eq_left, exists_prop, true_and, false_or] constructor · intro h apply_fun (d.compl i).equiv at h simp only [Prod.ext_iff, equiv_one (d.compl i) (one_mem _) (d.one_mem _), equiv_mul_left_of_mem (d.compl i) ⟨_, rfl⟩ , hhead, Subtype.ext_iff, Prod.ext_iff, Subgroup.coe_mul] at h rcases h with ⟨h₁, h₂⟩ rw [h₂, equiv_one (d.compl i) (one_mem _) (d.one_mem _)] at h₁ erw [mul_one] at h₁ simp only [((injective_iff_map_eq_one' _).1 (d.injective i))] at h₁ contradiction · rw [Word.equivPair_head] dsimp split_ifs with hep · rcases hep with ⟨hnil, rfl⟩ rw [head?_eq_head hnil] simp_all · push_neg at hep by_cases hw : w.toList = [] · simp [hw, Word.fstIdx] · simp [head?_eq_head hw, Word.fstIdx, hep hw] theorem ext_smul {w₁ w₂ : NormalWord d} (i : ι) (h : CoprodI.of (φ i w₁.head) • w₁.toWord = CoprodI.of (φ i w₂.head) • w₂.toWord) : w₁ = w₂ := by rcases w₁ with ⟨w₁, h₁, hw₁⟩ rcases w₂ with ⟨w₂, h₂, hw₂⟩ dsimp at * rw [smul_eq_iff_eq_inv_smul, ← mul_smul] at h subst h simp only [← map_inv, ← map_mul] at hw₁ have : h₁⁻¹ * h₂ = 1 := eq_one_of_smul_normalized w₂ (h₁⁻¹ * h₂) hw₂ hw₁ rw [inv_mul_eq_one] at this; subst this simp /-- Given a pair `(head, tail)`, we can form a word by prepending `head` to `tail`, but putting head into normal form first, by making sure it is expressed as an element of the base group multiplied by an element of the transversal. -/ noncomputable def rcons (i : ι) (p : Pair d i) : NormalWord d := letI n := (d.compl i).equiv p.head let w := (Word.equivPair i).symm { p.toPair with head := n.2 } { toWord := w head := (MonoidHom.ofInjective (d.injective i)).symm n.1 normalized := fun i g hg => by dsimp [w] at hg rw [Word.equivPair_symm, Word.mem_rcons_iff] at hg rcases hg with hg | ⟨_, rfl, rfl⟩ · exact p.normalized _ _ hg · simp } theorem rcons_injective {i : ι} : Function.Injective (rcons (d := d) i) := by rintro ⟨⟨head₁, tail₁⟩, _⟩ ⟨⟨head₂, tail₂⟩, _⟩ simp only [rcons, NormalWord.mk.injEq, EmbeddingLike.apply_eq_iff_eq, Word.Pair.mk.injEq, Pair.mk.injEq, and_imp] intro h₁ h₂ h₃ subst h₂ rw [← equiv_fst_mul_equiv_snd (d.compl i) head₁, ← equiv_fst_mul_equiv_snd (d.compl i) head₂, h₁, h₃] simp /-- The equivalence between `NormalWord`s and pairs. We can turn a `NormalWord` into a pair by taking the head of the `List` if it is in `G i` and multiplying it by the element of the base group. -/ noncomputable def equivPair (i) : NormalWord d ≃ Pair d i := letI toFun : NormalWord d → Pair d i := fun w => letI p := Word.equivPair i (CoprodI.of (φ i w.head) • w.toWord) { toPair := p normalized := fun j g hg => by dsimp only [p] at hg rw [Word.of_smul_def, ← Word.equivPair_symm, Equiv.apply_symm_apply] at hg dsimp at hg exact w.normalized _ _ (Word.mem_of_mem_equivPair_tail _ hg) } haveI leftInv : Function.LeftInverse (rcons i) toFun := fun w => ext_smul i <| by simp only [toFun, rcons, Word.equivPair_symm, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul] { toFun := toFun invFun := rcons i left_inv := leftInv right_inv := fun _ => rcons_injective (leftInv _) } noncomputable instance summandAction (i : ι) : MulAction (G i) (NormalWord d) := { smul := fun g w => (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } one_smul := fun _ => by dsimp [instHSMul] rw [one_mul] exact (equivPair i).symm_apply_apply _ mul_smul := fun _ _ _ => by dsimp [instHSMul] simp [mul_assoc, Equiv.apply_symm_apply, Function.End.mul_def] } theorem summand_smul_def' {i : ι} (g : G i) (w : NormalWord d) : g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := rfl noncomputable instance mulAction : MulAction (PushoutI φ) (NormalWord d) := MulAction.ofEndHom <| lift (fun _ => MulAction.toEndHom) MulAction.toEndHom <| by intro i simp only [MulAction.toEndHom, DFunLike.ext_iff, MonoidHom.coe_comp, MonoidHom.coe_mk, OneHom.coe_mk, comp_apply] intro h funext w apply NormalWord.ext_smul i simp only [summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, equiv_fst_eq_mul_inv, map_mul, map_inv, mul_smul, inv_smul_smul, smul_inv_smul, base_smul_def', MonoidHom.apply_ofInjective_symm] theorem base_smul_def (h : H) (w : NormalWord d) : base φ h • w = { w with head := h * w.head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_base] rfl theorem summand_smul_def {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = (equivPair i).symm { equivPair i w with head := g * (equivPair i w).head } := by dsimp [NormalWord.mulAction, instHSMul, SMul.smul] rw [lift_of] rfl theorem of_smul_eq_smul {i : ι} (g : G i) (w : NormalWord d) : of (φ := φ) i g • w = g • w := by rw [summand_smul_def, summand_smul_def'] theorem base_smul_eq_smul (h : H) (w : NormalWord d) : base φ h • w = h • w := by rw [base_smul_def, base_smul_def'] /-- Induction principle for `NormalWord`, that corresponds closely to inducting on the underlying list. -/ @[elab_as_elim] noncomputable def consRecOn {motive : NormalWord d → Sort _} (w : NormalWord d) (empty : motive empty) (cons : ∀ (i : ι) (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (_hgn : g ∈ d.set i) (hgr : g ∉ (φ i).range) (_hw1 : w.head = 1), motive w → motive (cons g w hmw hgr)) (base : ∀ (h : H) (w : NormalWord d), w.head = 1 → motive w → motive (base φ h • w)) : motive w := by rcases w with ⟨w, head, h3⟩ convert base head ⟨w, 1, h3⟩ rfl ?_ · simp [base_smul_def] · induction w using Word.consRecOn with | empty => exact empty | cons i g w h1 hg1 ih => convert cons i g ⟨w, 1, fun _ _ h => h3 _ _ (List.mem_cons_of_mem _ h)⟩ h1 (h3 _ _ List.mem_cons_self) ?_ rfl (ih ?_) · ext simp only [Word.cons, Option.mem_def, NormalWord.cons, map_one, mul_one, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ List.mem_cons_self)] · apply d.injective i simp only [NormalWord.cons, equiv_fst_eq_mul_inv, MonoidHom.apply_ofInjective_symm, map_one, mul_one, mul_inv_cancel, (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ List.mem_cons_self)] · rwa [← SetLike.mem_coe, ← coe_equiv_snd_eq_one_iff_mem (d.compl i) (d.one_mem _), (equiv_snd_eq_self_iff_mem (d.compl i) (one_mem _)).2 (h3 _ _ List.mem_cons_self)] theorem cons_eq_smul {i : ι} (g : G i) (w : NormalWord d) (hmw : w.fstIdx ≠ some i) (hgr : g ∉ (φ i).range) : cons g w hmw hgr = of (φ := φ) i g • w := by apply ext_smul i simp only [cons, ne_eq, Word.cons_eq_smul, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, mul_smul, inv_smul_smul, summand_smul_def, equivPair, rcons, Word.equivPair_symm, Word.rcons_eq_smul, Equiv.coe_fn_mk, Word.equivPair_tail_eq_inv_smul, Equiv.coe_fn_symm_mk, smul_inv_smul] @[simp] theorem prod_summand_smul {i : ι} (g : G i) (w : NormalWord d) : (g • w).prod = of i g * w.prod := by simp only [prod, summand_smul_def', equivPair, rcons, Word.equivPair_symm, Equiv.coe_fn_mk, Equiv.coe_fn_symm_mk, Word.equivPair_smul_same, Word.equivPair_tail_eq_inv_smul, Word.rcons_eq_smul, ← of_apply_eq_base φ i, MonoidHom.apply_ofInjective_symm, equiv_fst_eq_mul_inv, mul_assoc, map_mul, map_inv, Word.prod_smul, ofCoprodI_of, inv_mul_cancel_left, mul_inv_cancel_left] @[simp] theorem prod_smul (g : PushoutI φ) (w : NormalWord d) : (g • w).prod = g * w.prod := by induction g using PushoutI.induction_on generalizing w with | of i g => rw [of_smul_eq_smul, prod_summand_smul] | base h => rw [base_smul_eq_smul, prod_base_smul] | mul x y ihx ihy => rw [mul_smul, ihx, ihy, mul_assoc] theorem prod_smul_empty (w : NormalWord d) : w.prod • empty = w := by induction w using consRecOn with | empty => simp | cons i g w _ _ _ _ ih => rw [prod_cons, mul_smul, ih, cons_eq_smul] | base h w _ ih => rw [prod_smul, mul_smul, ih] /-- The equivalence between normal forms and elements of the pushout -/ noncomputable def equiv : PushoutI φ ≃ NormalWord d := { toFun := fun g => g • .empty invFun := fun w => w.prod left_inv := fun g => by simp only [prod_smul, prod_empty, mul_one] right_inv := fun w => prod_smul_empty w } theorem prod_injective {ι : Type*} {G : ι → Type*} [(i : ι) → Group (G i)] {φ : (i : ι) → H →* G i} {d : Transversal φ} : Function.Injective (prod : NormalWord d → PushoutI φ) := by letI := Classical.decEq ι letI := fun i => Classical.decEq (G i) classical exact equiv.symm.injective instance : FaithfulSMul (PushoutI φ) (NormalWord d) := ⟨fun h => by simpa using congr_arg prod (h empty)⟩ instance (i : ι) : FaithfulSMul (G i) (NormalWord d) := ⟨by simp [summand_smul_def']⟩ instance : FaithfulSMul H (NormalWord d) := ⟨by simp [base_smul_def']⟩ end NormalWord open NormalWord /-- All maps into the `PushoutI`, or amalgamated product of groups are injective, provided all maps in the diagram are injective. See also `base_injective` -/ theorem of_injective (hφ : ∀ i, Function.Injective (φ i)) (i : ι) : Function.Injective (of (φ := φ) i) := by rcases transversal_nonempty φ hφ with ⟨d⟩ let _ := Classical.decEq ι let _ := fun i => Classical.decEq (G i) refine Function.Injective.of_comp (f := ((· • ·) : PushoutI φ → NormalWord d → NormalWord d)) ?_ intros _ _ h exact eq_of_smul_eq_smul (fun w : NormalWord d => by simp_all [funext_iff, of_smul_eq_smul]) theorem base_injective (hφ : ∀ i, Function.Injective (φ i)) : Function.Injective (base φ) := by rcases transversal_nonempty φ hφ with ⟨d⟩ let _ := Classical.decEq ι let _ := fun i => Classical.decEq (G i) refine Function.Injective.of_comp (f := ((· • ·) : PushoutI φ → NormalWord d → NormalWord d)) ?_ intros _ _ h exact eq_of_smul_eq_smul (fun w : NormalWord d => by simp_all [funext_iff, base_smul_eq_smul]) section Reduced open NormalWord variable (φ) in /-- A word in `CoprodI` is reduced if none of its letters are in the base group. -/ def Reduced (w : Word G) : Prop := ∀ g, g ∈ w.toList → g.2 ∉ (φ g.1).range theorem Reduced.exists_normalWord_prod_eq (d : Transversal φ) {w : Word G} (hw : Reduced φ w) : ∃ w' : NormalWord d, w'.prod = ofCoprodI w.prod ∧ w'.toList.map Sigma.fst = w.toList.map Sigma.fst := by classical induction w using Word.consRecOn with | empty => exact ⟨empty, by simp, rfl⟩ | cons i g w hIdx hg1 ih => rcases ih (fun _ hg => hw _ (List.mem_cons_of_mem _ hg)) with ⟨w', hw'prod, hw'map⟩ refine ⟨cons g w' ?_ ?_, ?_⟩ · rwa [Word.fstIdx, ← List.head?_map, hw'map, List.head?_map] · exact hw _ List.mem_cons_self · simp [hw'prod, hw'map] /-- For any word `w` in the coproduct, if `w` is reduced (i.e none its letters are in the image of the base monoid), and nonempty, then `w` itself is not in the image of the base group. -/ theorem Reduced.eq_empty_of_mem_range (hφ : ∀ i, Injective (φ i)) {w : Word G} (hw : Reduced φ w) (h : ofCoprodI w.prod ∈ (base φ).range) : w = .empty := by rcases transversal_nonempty φ hφ with ⟨d⟩ rcases hw.exists_normalWord_prod_eq d with ⟨w', hw'prod, hw'map⟩ rcases h with ⟨h, heq⟩ have : (NormalWord.prod (d := d) ⟨.empty, h, by simp⟩) = base φ h := by simp [NormalWord.prod] rw [← hw'prod, ← this] at heq suffices w'.toWord = .empty by simp [this, @eq_comm _ []] at hw'map ext simp [hw'map] rw [← prod_injective heq] end Reduced /-- The intersection of the images of the maps from any two distinct groups in the diagram into the amalgamated product is the image of the map from the base group in the diagram. -/ theorem inf_of_range_eq_base_range (hφ : ∀ i, Injective (φ i)) {i j : ι} (hij : i ≠ j) : (of i).range ⊓ (of j).range = (base φ).range := le_antisymm (by intro x ⟨⟨g₁, hg₁⟩, ⟨g₂, hg₂⟩⟩ by_contra hx
have hx1 : x ≠ 1 := by rintro rfl; simp_all only [ne_eq, one_mem, not_true_eq_false] have hg₁1 : g₁ ≠ 1 := ne_of_apply_ne (of (φ := φ) i) (by simp_all) have hg₂1 : g₂ ≠ 1 := ne_of_apply_ne (of (φ := φ) j) (by simp_all) have hg₁r : g₁ ∉ (φ i).range := by rintro ⟨y, rfl⟩ subst hg₁ exact hx (of_apply_eq_base φ i y ▸ MonoidHom.mem_range.2 ⟨y, rfl⟩) have hg₂r : g₂ ∉ (φ j).range := by rintro ⟨y, rfl⟩ subst hg₂ exact hx (of_apply_eq_base φ j y ▸ MonoidHom.mem_range.2 ⟨y, rfl⟩) let w : Word G := ⟨[⟨_, g₁⟩, ⟨_, g₂⁻¹⟩], by simp_all, by simp_all⟩ have hw : Reduced φ w := by simp only [w, not_exists, ne_eq, Reduced, List.find?, List.mem_cons, List.mem_singleton, forall_eq_or_imp, not_false_eq_true, forall_const, forall_eq, true_and, hg₁r, hg₂r, List.mem_nil_iff, false_imp_iff, imp_true_iff, and_true, inv_mem_iff] have := hw.eq_empty_of_mem_range hφ (by simp only [w, Word.prod, List.map_cons, List.prod_cons, List.prod_nil, List.map_nil, map_mul, ofCoprodI_of, hg₁, hg₂, map_inv, map_one, mul_one, mul_inv_cancel, one_mem]) simp [w, Word.empty] at this) (le_inf (by rw [← of_comp_eq_base i] rintro _ ⟨h, rfl⟩ exact MonoidHom.mem_range.2 ⟨φ i h, rfl⟩) (by rw [← of_comp_eq_base j] rintro _ ⟨h, rfl⟩ exact MonoidHom.mem_range.2 ⟨φ j h, rfl⟩)) end PushoutI end Monoid
Mathlib/GroupTheory/PushoutI.lean
662
697
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Sébastien Gouëzel -/ import Mathlib.Analysis.Normed.Field.Basic import Mathlib.Topology.MetricSpace.Cauchy /-! # Completeness in terms of `Cauchy` filters vs `isCauSeq` sequences In this file we apply `Metric.complete_of_cauchySeq_tendsto` to prove that a `NormedRing` is complete in terms of `Cauchy` filter if and only if it is complete in terms of `CauSeq` Cauchy sequences. -/ universe u v open Set Filter Topology variable {β : Type v} theorem CauSeq.tendsto_limit [NormedRing β] [hn : IsAbsoluteValue (norm : β → ℝ)] (f : CauSeq β norm) [CauSeq.IsComplete β norm] : Tendsto f atTop (𝓝 f.lim) := tendsto_nhds.mpr (by intro s os lfs suffices ∃ a : ℕ, ∀ b : ℕ, b ≥ a → f b ∈ s by simpa using this rcases Metric.isOpen_iff.1 os _ lfs with ⟨ε, ⟨hε, hεs⟩⟩ obtain ⟨N, hN⟩ := Setoid.symm (CauSeq.equiv_lim f) _ hε exists N intro b hb apply hεs dsimp [Metric.ball] rw [dist_comm, dist_eq_norm] solve_by_elim) variable [NormedField β] /- This section shows that if we have a uniform space generated by an absolute value, topological completeness and Cauchy sequence completeness coincide. The problem is that there isn't a good notion of "uniform space generated by an absolute value", so right now this is specific to norm. Furthermore, norm only instantiates IsAbsoluteValue on NormedDivisionRing. This needs to be fixed, since it prevents showing that ℤ_[hp] is complete. -/ open Metric theorem CauchySeq.isCauSeq {f : ℕ → β} (hf : CauchySeq f) : IsCauSeq norm f := by obtain ⟨hf1, hf2⟩ := cauchy_iff.1 hf intro ε hε rcases hf2 { x | dist x.1 x.2 < ε } (dist_mem_uniformity hε) with ⟨t, ⟨ht, htsub⟩⟩ simp only [mem_map, mem_atTop_sets, mem_preimage] at ht; obtain ⟨N, hN⟩ := ht exists N intro j hj rw [← dist_eq_norm] apply @htsub (f j, f N) apply Set.mk_mem_prod <;> solve_by_elim [le_refl] theorem CauSeq.cauchySeq (f : CauSeq β norm) : CauchySeq f := by refine cauchy_iff.2 ⟨by infer_instance, fun s hs => ?_⟩ rcases mem_uniformity_dist.1 hs with ⟨ε, ⟨hε, hεs⟩⟩ obtain ⟨N, hN⟩ := CauSeq.cauchy₂ f hε exists { n | n ≥ N }.image f simp only [exists_prop, mem_atTop_sets, mem_map, mem_image, mem_setOf_eq] constructor
· exists N intro b hb exists b · rintro ⟨a, b⟩ ⟨⟨a', ⟨ha'1, ha'2⟩⟩, ⟨b', ⟨hb'1, hb'2⟩⟩⟩ dsimp at ha'1 ha'2 hb'1 hb'2 rw [← ha'2, ← hb'2] apply hεs rw [dist_eq_norm] apply hN <;> assumption /-- In a normed field, `CauSeq` coincides with the usual notion of Cauchy sequences. -/ theorem isCauSeq_iff_cauchySeq {α : Type u} [NormedField α] {u : ℕ → α} : IsCauSeq norm u ↔ CauchySeq u := ⟨fun h => CauSeq.cauchySeq ⟨u, h⟩, fun h => h.isCauSeq⟩ -- see Note [lower instance priority]
Mathlib/Topology/MetricSpace/CauSeqFilter.lean
67
82
/- 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.VecNotation import Mathlib.Logic.Small.Basic import Mathlib.SetTheory.ZFC.PSet /-! # A model of ZFC In this file, we model Zermelo-Fraenkel set theory (+ choice) using Lean's underlying type theory, building on the pre-sets defined in `Mathlib.SetTheory.ZFC.PSet`. The theory of classes is developed in `Mathlib.SetTheory.ZFC.Class`. ## Main definitions * `ZFSet`: ZFC set. Defined as `PSet` quotiented by `PSet.Equiv`, the extensional equivalence. * `ZFSet.choice`: Axiom of choice. Proved from Lean's axiom of choice. * `ZFSet.omega`: The von Neumann ordinal `ω` as a `Set`. * `Classical.allZFSetDefinable`: All functions are classically definable. * `ZFSet.IsFunc` : Predicate that a ZFC set is a subset of `x × y` that can be considered as a ZFC function `x → y`. That is, each member of `x` is related by the ZFC set to exactly one member of `y`. * `ZFSet.funs`: ZFC set of ZFC functions `x → y`. * `ZFSet.Hereditarily p x`: Predicate that every set in the transitive closure of `x` has property `p`. ## Notes To avoid confusion between the Lean `Set` and the ZFC `Set`, docstrings in this file refer to them respectively as "`Set`" and "ZFC set". -/ universe u /-- The ZFC universe of sets consists of the type of pre-sets, quotiented by extensional equivalence. -/ @[pp_with_univ] def ZFSet : Type (u + 1) := Quotient PSet.setoid.{u} namespace ZFSet /-- Turns a pre-set into a ZFC set. -/ def mk : PSet → ZFSet := Quotient.mk'' @[simp] theorem mk_eq (x : PSet) : @Eq ZFSet ⟦x⟧ (mk x) := rfl @[simp] theorem mk_out : ∀ x : ZFSet, mk x.out = x := Quotient.out_eq /-- A set function is "definable" if it is the image of some n-ary `PSet` function. This isn't exactly definability, but is useful as a sufficient condition for functions that have a computable image. -/ class Definable (n) (f : (Fin n → ZFSet.{u}) → ZFSet.{u}) where /-- Turns a definable function into an n-ary `PSet` function. -/ out : (Fin n → PSet.{u}) → PSet.{u} /-- A set function `f` is the image of `Definable.out f`. -/ mk_out xs : mk (out xs) = f (mk <| xs ·) := by simp attribute [simp] Definable.mk_out /-- An abbrev of `ZFSet.Definable` for unary functions. -/ abbrev Definable₁ (f : ZFSet.{u} → ZFSet.{u}) := Definable 1 (fun s ↦ f (s 0)) /-- A simpler constructor for `ZFSet.Definable₁`. -/ abbrev Definable₁.mk {f : ZFSet.{u} → ZFSet.{u}} (out : PSet.{u} → PSet.{u}) (mk_out : ∀ x, ⟦out x⟧ = f ⟦x⟧) : Definable₁ f where out xs := out (xs 0) mk_out xs := mk_out (xs 0) /-- Turns a unary definable function into a unary `PSet` function. -/ abbrev Definable₁.out (f : ZFSet.{u} → ZFSet.{u}) [Definable₁ f] : PSet.{u} → PSet.{u} := fun x ↦ Definable.out (fun s ↦ f (s 0)) ![x] lemma Definable₁.mk_out {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x : PSet} : .mk (out f x) = f (.mk x) := Definable.mk_out ![x] /-- An abbrev of `ZFSet.Definable` for binary functions. -/ abbrev Definable₂ (f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}) := Definable 2 (fun s ↦ f (s 0) (s 1)) /-- A simpler constructor for `ZFSet.Definable₂`. -/ abbrev Definable₂.mk {f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}} (out : PSet.{u} → PSet.{u} → PSet.{u}) (mk_out : ∀ x y, ⟦out x y⟧ = f ⟦x⟧ ⟦y⟧) : Definable₂ f where out xs := out (xs 0) (xs 1) mk_out xs := mk_out (xs 0) (xs 1) /-- Turns a binary definable function into a binary `PSet` function. -/ abbrev Definable₂.out (f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}) [Definable₂ f] : PSet.{u} → PSet.{u} → PSet.{u} := fun x y ↦ Definable.out (fun s ↦ f (s 0) (s 1)) ![x, y] lemma Definable₂.mk_out {f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}} [Definable₂ f] {x y : PSet} : .mk (out f x y) = f (.mk x) (.mk y) := Definable.mk_out ![x, y] instance (f) [Definable₁ f] (n g) [Definable n g] : Definable n (fun s ↦ f (g s)) where out xs := Definable₁.out f (Definable.out g xs) instance (f) [Definable₂ f] (n g₁ g₂) [Definable n g₁] [Definable n g₂] : Definable n (fun s ↦ f (g₁ s) (g₂ s)) where out xs := Definable₂.out f (Definable.out g₁ xs) (Definable.out g₂ xs) instance (n) (i) : Definable n (fun s ↦ s i) where out s := s i lemma Definable.out_equiv {n} (f : (Fin n → ZFSet.{u}) → ZFSet.{u}) [Definable n f] {xs ys : Fin n → PSet} (h : ∀ i, xs i ≈ ys i) : out f xs ≈ out f ys := by rw [← Quotient.eq_iff_equiv, mk_eq, mk_eq, mk_out, mk_out] exact congrArg _ (funext fun i ↦ Quotient.sound (h i)) lemma Definable₁.out_equiv (f : ZFSet.{u} → ZFSet.{u}) [Definable₁ f] {x y : PSet} (h : x ≈ y) : out f x ≈ out f y := Definable.out_equiv _ (by simp [h]) lemma Definable₂.out_equiv (f : ZFSet.{u} → ZFSet.{u} → ZFSet.{u}) [Definable₂ f] {x₁ y₁ x₂ y₂ : PSet} (h₁ : x₁ ≈ y₁) (h₂ : x₂ ≈ y₂) : out f x₁ x₂ ≈ out f y₁ y₂ := Definable.out_equiv _ (by simp [Fin.forall_fin_succ, h₁, h₂]) end ZFSet namespace Classical open PSet ZFSet /-- All functions are classically definable. -/ noncomputable def allZFSetDefinable {n} (F : (Fin n → ZFSet.{u}) → ZFSet.{u}) : Definable n F where out xs := (F (mk <| xs ·)).out end Classical namespace ZFSet open PSet theorem eq {x y : PSet} : mk x = mk y ↔ Equiv x y := Quotient.eq theorem sound {x y : PSet} (h : PSet.Equiv x y) : mk x = mk y := Quotient.sound h theorem exact {x y : PSet} : mk x = mk y → PSet.Equiv x y := Quotient.exact /-- The membership relation for ZFC sets is inherited from the membership relation for pre-sets. -/ protected def Mem : ZFSet → ZFSet → Prop := Quotient.lift₂ (· ∈ ·) fun _ _ _ _ hx hy => propext ((Mem.congr_left hx).trans (Mem.congr_right hy)) instance : Membership ZFSet ZFSet where mem t s := ZFSet.Mem s t @[simp] theorem mk_mem_iff {x y : PSet} : mk x ∈ mk y ↔ x ∈ y := Iff.rfl /-- Convert a ZFC set into a `Set` of ZFC sets -/ def toSet (u : ZFSet.{u}) : Set ZFSet.{u} := { x | x ∈ u } @[simp] theorem mem_toSet (a u : ZFSet.{u}) : a ∈ u.toSet ↔ a ∈ u := Iff.rfl instance small_toSet (x : ZFSet.{u}) : Small.{u} x.toSet := Quotient.inductionOn x fun a => by let f : a.Type → (mk a).toSet := fun i => ⟨mk <| a.Func i, func_mem a i⟩ suffices Function.Surjective f by exact small_of_surjective this rintro ⟨y, hb⟩ induction y using Quotient.inductionOn obtain ⟨i, h⟩ := hb exact ⟨i, Subtype.coe_injective (Quotient.sound h.symm)⟩ /-- A nonempty set is one that contains some element. -/ protected def Nonempty (u : ZFSet) : Prop := u.toSet.Nonempty theorem nonempty_def (u : ZFSet) : u.Nonempty ↔ ∃ x, x ∈ u := Iff.rfl theorem nonempty_of_mem {x u : ZFSet} (h : x ∈ u) : u.Nonempty := ⟨x, h⟩ @[simp] theorem nonempty_toSet_iff {u : ZFSet} : u.toSet.Nonempty ↔ u.Nonempty := Iff.rfl /-- `x ⊆ y` as ZFC sets means that all members of `x` are members of `y`. -/ protected def Subset (x y : ZFSet.{u}) := ∀ ⦃z⦄, z ∈ x → z ∈ y instance hasSubset : HasSubset ZFSet := ⟨ZFSet.Subset⟩ theorem subset_def {x y : ZFSet.{u}} : x ⊆ y ↔ ∀ ⦃z⦄, z ∈ x → z ∈ y := Iff.rfl instance : IsRefl ZFSet (· ⊆ ·) := ⟨fun _ _ => id⟩ instance : IsTrans ZFSet (· ⊆ ·) := ⟨fun _ _ _ hxy hyz _ ha => hyz (hxy ha)⟩ @[simp] theorem subset_iff : ∀ {x y : PSet}, mk x ⊆ mk y ↔ x ⊆ y | ⟨_, A⟩, ⟨_, _⟩ => ⟨fun h a => @h ⟦A a⟧ (Mem.mk A a), fun h z => Quotient.inductionOn z fun _ ⟨a, za⟩ => let ⟨b, ab⟩ := h a ⟨b, za.trans ab⟩⟩ @[simp] theorem toSet_subset_iff {x y : ZFSet} : x.toSet ⊆ y.toSet ↔ x ⊆ y := by simp [subset_def, Set.subset_def] @[ext] theorem ext {x y : ZFSet.{u}} : (∀ z : ZFSet.{u}, z ∈ x ↔ z ∈ y) → x = y := Quotient.inductionOn₂ x y fun _ _ h => Quotient.sound (Mem.ext fun w => h ⟦w⟧) theorem toSet_injective : Function.Injective toSet := fun _ _ h => ext <| Set.ext_iff.1 h @[simp] theorem toSet_inj {x y : ZFSet} : x.toSet = y.toSet ↔ x = y := toSet_injective.eq_iff instance : IsAntisymm ZFSet (· ⊆ ·) := ⟨fun _ _ hab hba => ext fun c => ⟨@hab c, @hba c⟩⟩ /-- The empty ZFC set -/ protected def empty : ZFSet := mk ∅ instance : EmptyCollection ZFSet := ⟨ZFSet.empty⟩ instance : Inhabited ZFSet := ⟨∅⟩ @[simp] theorem not_mem_empty (x) : x ∉ (∅ : ZFSet.{u}) := Quotient.inductionOn x PSet.not_mem_empty @[simp] theorem toSet_empty : toSet ∅ = ∅ := by simp [toSet] @[simp] theorem empty_subset (x : ZFSet.{u}) : (∅ : ZFSet) ⊆ x := Quotient.inductionOn x fun y => subset_iff.2 <| PSet.empty_subset y @[simp] theorem not_nonempty_empty : ¬ZFSet.Nonempty ∅ := by simp [ZFSet.Nonempty] @[simp] theorem nonempty_mk_iff {x : PSet} : (mk x).Nonempty ↔ x.Nonempty := by refine ⟨?_, fun ⟨a, h⟩ => ⟨mk a, h⟩⟩ rintro ⟨a, h⟩ induction a using Quotient.inductionOn exact ⟨_, h⟩ theorem eq_empty (x : ZFSet.{u}) : x = ∅ ↔ ∀ y : ZFSet.{u}, y ∉ x := by simp [ZFSet.ext_iff] theorem eq_empty_or_nonempty (u : ZFSet) : u = ∅ ∨ u.Nonempty := by rw [eq_empty, ← not_exists] apply em' /-- `Insert x y` is the set `{x} ∪ y` -/ protected def Insert : ZFSet → ZFSet → ZFSet := Quotient.map₂ PSet.insert fun _ _ uv ⟨_, _⟩ ⟨_, _⟩ ⟨αβ, βα⟩ => ⟨fun o => match o with | some a => let ⟨b, hb⟩ := αβ a ⟨some b, hb⟩ | none => ⟨none, uv⟩, fun o => match o with | some b => let ⟨a, ha⟩ := βα b ⟨some a, ha⟩ | none => ⟨none, uv⟩⟩ instance : Insert ZFSet ZFSet := ⟨ZFSet.Insert⟩ instance : Singleton ZFSet ZFSet := ⟨fun x => insert x ∅⟩ instance : LawfulSingleton ZFSet ZFSet := ⟨fun _ => rfl⟩ @[simp] theorem mem_insert_iff {x y z : ZFSet.{u}} : x ∈ insert y z ↔ x = y ∨ x ∈ z := Quotient.inductionOn₃ x y z fun _ _ _ => PSet.mem_insert_iff.trans (or_congr_left eq.symm) theorem mem_insert (x y : ZFSet) : x ∈ insert x y := mem_insert_iff.2 <| Or.inl rfl theorem mem_insert_of_mem {y z : ZFSet} (x) (h : z ∈ y) : z ∈ insert x y := mem_insert_iff.2 <| Or.inr h @[simp] theorem toSet_insert (x y : ZFSet) : (insert x y).toSet = insert x y.toSet := by ext simp @[simp] theorem mem_singleton {x y : ZFSet.{u}} : x ∈ @singleton ZFSet.{u} ZFSet.{u} _ y ↔ x = y := Quotient.inductionOn₂ x y fun _ _ => PSet.mem_singleton.trans eq.symm @[simp] theorem toSet_singleton (x : ZFSet) : ({x} : ZFSet).toSet = {x} := by ext simp theorem insert_nonempty (u v : ZFSet) : (insert u v).Nonempty := ⟨u, mem_insert u v⟩ theorem singleton_nonempty (u : ZFSet) : ZFSet.Nonempty {u} := insert_nonempty u ∅ theorem mem_pair {x y z : ZFSet.{u}} : x ∈ ({y, z} : ZFSet) ↔ x = y ∨ x = z := by simp @[simp] theorem pair_eq_singleton (x : ZFSet) : {x, x} = ({x} : ZFSet) := by ext simp @[simp] theorem pair_eq_singleton_iff {x y z : ZFSet} : ({x, y} : ZFSet) = {z} ↔ x = z ∧ y = z := by refine ⟨fun h ↦ ?_, ?_⟩ · rw [← mem_singleton, ← mem_singleton] simp [← h] · rintro ⟨rfl, rfl⟩ exact pair_eq_singleton y @[simp] theorem singleton_eq_pair_iff {x y z : ZFSet} : ({x} : ZFSet) = {y, z} ↔ x = y ∧ x = z := by rw [eq_comm, pair_eq_singleton_iff] simp_rw [eq_comm] /-- `omega` is the first infinite von Neumann ordinal -/ def omega : ZFSet := mk PSet.omega @[simp] theorem omega_zero : ∅ ∈ omega := ⟨⟨0⟩, Equiv.rfl⟩ @[simp] theorem omega_succ {n} : n ∈ omega.{u} → insert n n ∈ omega.{u} := Quotient.inductionOn n fun x ⟨⟨n⟩, h⟩ => ⟨⟨n + 1⟩, ZFSet.exact <| show insert (mk x) (mk x) = insert (mk <| ofNat n) (mk <| ofNat n) by rw [ZFSet.sound h] rfl⟩ /-- `{x ∈ a | p x}` is the set of elements in `a` satisfying `p` -/ protected def sep (p : ZFSet → Prop) : ZFSet → ZFSet := Quotient.map (PSet.sep fun y => p (mk y)) fun ⟨α, A⟩ ⟨β, B⟩ ⟨αβ, βα⟩ => ⟨fun ⟨a, pa⟩ => let ⟨b, hb⟩ := αβ a ⟨⟨b, by simpa only [mk_func, ← ZFSet.sound hb]⟩, hb⟩, fun ⟨b, pb⟩ => let ⟨a, ha⟩ := βα b ⟨⟨a, by simpa only [mk_func, ZFSet.sound ha]⟩, ha⟩⟩ -- Porting note: the { x | p x } notation appears to be disabled in Lean 4. instance : Sep ZFSet ZFSet := ⟨ZFSet.sep⟩ @[simp] theorem mem_sep {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} : y ∈ ZFSet.sep p x ↔ y ∈ x ∧ p y := Quotient.inductionOn₂ x y fun _ _ => PSet.mem_sep (p := p ∘ mk) fun _ _ h => (Quotient.sound h).subst @[simp] theorem sep_empty (p : ZFSet → Prop) : (∅ : ZFSet).sep p = ∅ := (eq_empty _).mpr fun _ h ↦ not_mem_empty _ (mem_sep.mp h).1 @[simp] theorem toSet_sep (a : ZFSet) (p : ZFSet → Prop) : (ZFSet.sep p a).toSet = { x ∈ a.toSet | p x } := by ext simp /-- The powerset operation, the collection of subsets of a ZFC set -/ def powerset : ZFSet → ZFSet := Quotient.map PSet.powerset fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ => ⟨fun p => ⟨{ b | ∃ a, p a ∧ Equiv (A a) (B b) }, fun ⟨a, pa⟩ => let ⟨b, ab⟩ := αβ a ⟨⟨b, a, pa, ab⟩, ab⟩, fun ⟨_, a, pa, ab⟩ => ⟨⟨a, pa⟩, ab⟩⟩, fun q => ⟨{ a | ∃ b, q b ∧ Equiv (A a) (B b) }, fun ⟨_, b, qb, ab⟩ => ⟨⟨b, qb⟩, ab⟩, fun ⟨b, qb⟩ => let ⟨a, ab⟩ := βα b ⟨⟨a, b, qb, ab⟩, ab⟩⟩⟩ @[simp] theorem mem_powerset {x y : ZFSet.{u}} : y ∈ powerset x ↔ y ⊆ x := Quotient.inductionOn₂ x y fun _ _ => PSet.mem_powerset.trans subset_iff.symm theorem sUnion_lem {α β : Type u} (A : α → PSet) (B : β → PSet) (αβ : ∀ a, ∃ b, Equiv (A a) (B b)) : ∀ a, ∃ b, Equiv ((sUnion ⟨α, A⟩).Func a) ((sUnion ⟨β, B⟩).Func b) | ⟨a, c⟩ => by let ⟨b, hb⟩ := αβ a induction' ea : A a with γ Γ induction' eb : B b with δ Δ rw [ea, eb] at hb obtain ⟨γδ, δγ⟩ := hb let c : (A a).Type := c let ⟨d, hd⟩ := γδ (by rwa [ea] at c) use ⟨b, Eq.ndrec d (Eq.symm eb)⟩ change PSet.Equiv ((A a).Func c) ((B b).Func (Eq.ndrec d eb.symm)) match A a, B b, ea, eb, c, d, hd with | _, _, rfl, rfl, _, _, hd => exact hd /-- The union operator, the collection of elements of elements of a ZFC set -/ def sUnion : ZFSet → ZFSet := Quotient.map PSet.sUnion fun ⟨_, A⟩ ⟨_, B⟩ ⟨αβ, βα⟩ => ⟨sUnion_lem A B αβ, fun a => Exists.elim (sUnion_lem B A (fun b => Exists.elim (βα b) fun c hc => ⟨c, PSet.Equiv.symm hc⟩) a) fun b hb => ⟨b, PSet.Equiv.symm hb⟩⟩ @[inherit_doc] prefix:110 "⋃₀ " => ZFSet.sUnion /-- The intersection operator, the collection of elements in all of the elements of a ZFC set. We define `⋂₀ ∅ = ∅`. -/ def sInter (x : ZFSet) : ZFSet := (⋃₀ x).sep (fun y => ∀ z ∈ x, y ∈ z) @[inherit_doc] prefix:110 "⋂₀ " => ZFSet.sInter @[simp] theorem mem_sUnion {x y : ZFSet.{u}} : y ∈ ⋃₀ x ↔ ∃ z ∈ x, y ∈ z := Quotient.inductionOn₂ x y fun _ _ => PSet.mem_sUnion.trans ⟨fun ⟨z, h⟩ => ⟨⟦z⟧, h⟩, fun ⟨z, h⟩ => Quotient.inductionOn z (fun z h => ⟨z, h⟩) h⟩ theorem mem_sInter {x y : ZFSet} (h : x.Nonempty) : y ∈ ⋂₀ x ↔ ∀ z ∈ x, y ∈ z := by unfold sInter simp only [and_iff_right_iff_imp, mem_sep] intro mem apply mem_sUnion.mpr replace ⟨s, h⟩ := h exact ⟨_, h, mem _ h⟩ @[simp] theorem sUnion_empty : ⋃₀ (∅ : ZFSet.{u}) = ∅ := by ext simp @[simp] theorem sInter_empty : ⋂₀ (∅ : ZFSet) = ∅ := by simp [sInter] theorem mem_of_mem_sInter {x y z : ZFSet} (hy : y ∈ ⋂₀ x) (hz : z ∈ x) : y ∈ z := by rcases eq_empty_or_nonempty x with (rfl | hx) · exact (not_mem_empty z hz).elim · exact (mem_sInter hx).1 hy z hz theorem mem_sUnion_of_mem {x y z : ZFSet} (hy : y ∈ z) (hz : z ∈ x) : y ∈ ⋃₀ x := mem_sUnion.2 ⟨z, hz, hy⟩ theorem not_mem_sInter_of_not_mem {x y z : ZFSet} (hy : ¬y ∈ z) (hz : z ∈ x) : ¬y ∈ ⋂₀ x := fun hx => hy <| mem_of_mem_sInter hx hz @[simp] theorem sUnion_singleton {x : ZFSet.{u}} : ⋃₀ ({x} : ZFSet) = x := ext fun y => by simp_rw [mem_sUnion, mem_singleton, exists_eq_left] @[simp] theorem sInter_singleton {x : ZFSet.{u}} : ⋂₀ ({x} : ZFSet) = x := ext fun y => by simp_rw [mem_sInter (singleton_nonempty x), mem_singleton, forall_eq] @[simp] theorem toSet_sUnion (x : ZFSet.{u}) : (⋃₀ x).toSet = ⋃₀ (toSet '' x.toSet) := by ext simp theorem toSet_sInter {x : ZFSet.{u}} (h : x.Nonempty) : (⋂₀ x).toSet = ⋂₀ (toSet '' x.toSet) := by ext simp [mem_sInter h] theorem singleton_injective : Function.Injective (@singleton ZFSet ZFSet _) := fun x y H => by let this := congr_arg sUnion H rwa [sUnion_singleton, sUnion_singleton] at this @[simp] theorem singleton_inj {x y : ZFSet} : ({x} : ZFSet) = {y} ↔ x = y := singleton_injective.eq_iff /-- The binary union operation -/ protected def union (x y : ZFSet.{u}) : ZFSet.{u} := ⋃₀ {x, y} /-- The binary intersection operation -/ protected def inter (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => z ∈ y) x -- { z ∈ x | z ∈ y } /-- The set difference operation -/ protected def diff (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (fun z => z ∉ y) x -- { z ∈ x | z ∉ y } instance : Union ZFSet := ⟨ZFSet.union⟩ instance : Inter ZFSet := ⟨ZFSet.inter⟩ instance : SDiff ZFSet := ⟨ZFSet.diff⟩ @[simp] theorem toSet_union (x y : ZFSet.{u}) : (x ∪ y).toSet = x.toSet ∪ y.toSet := by change (⋃₀ {x, y}).toSet = _ simp @[simp] theorem toSet_inter (x y : ZFSet.{u}) : (x ∩ y).toSet = x.toSet ∩ y.toSet := by change (ZFSet.sep (fun z => z ∈ y) x).toSet = _ ext simp @[simp] theorem toSet_sdiff (x y : ZFSet.{u}) : (x \ y).toSet = x.toSet \ y.toSet := by change (ZFSet.sep (fun z => z ∉ y) x).toSet = _ ext simp @[simp] theorem mem_union {x y z : ZFSet.{u}} : z ∈ x ∪ y ↔ z ∈ x ∨ z ∈ y := by rw [← mem_toSet] simp @[simp] theorem mem_inter {x y z : ZFSet.{u}} : z ∈ x ∩ y ↔ z ∈ x ∧ z ∈ y := @mem_sep (fun z : ZFSet.{u} => z ∈ y) x z @[simp] theorem mem_diff {x y z : ZFSet.{u}} : z ∈ x \ y ↔ z ∈ x ∧ z ∉ y := @mem_sep (fun z : ZFSet.{u} => z ∉ y) x z @[simp] theorem sUnion_pair {x y : ZFSet.{u}} : ⋃₀ ({x, y} : ZFSet.{u}) = x ∪ y := rfl theorem mem_wf : @WellFounded ZFSet (· ∈ ·) := (wellFounded_lift₂_iff (H := fun a b c d hx hy => propext ((@Mem.congr_left a c hx).trans (@Mem.congr_right b d hy _)))).mpr PSet.mem_wf /-- Induction on the `∈` relation. -/ @[elab_as_elim] theorem inductionOn {p : ZFSet → Prop} (x) (h : ∀ x, (∀ y ∈ x, p y) → p x) : p x := mem_wf.induction x h instance : IsWellFounded ZFSet (· ∈ ·) := ⟨mem_wf⟩ instance : WellFoundedRelation ZFSet := ⟨_, mem_wf⟩ theorem mem_asymm {x y : ZFSet} : x ∈ y → y ∉ x := asymm_of (· ∈ ·) theorem mem_irrefl (x : ZFSet) : x ∉ x := irrefl_of (· ∈ ·) x theorem not_subset_of_mem {x y : ZFSet} (h : x ∈ y) : ¬ y ⊆ x := fun h' ↦ mem_irrefl _ (h' h) theorem not_mem_of_subset {x y : ZFSet} (h : x ⊆ y) : y ∉ x := imp_not_comm.2 not_subset_of_mem h theorem regularity (x : ZFSet.{u}) (h : x ≠ ∅) : ∃ y ∈ x, x ∩ y = ∅ := by_contradiction fun ne => h <| (eq_empty x).2 fun y => @inductionOn (fun z => z ∉ x) y fun z IH zx => ne ⟨z, zx, (eq_empty _).2 fun w wxz => let ⟨wx, wz⟩ := mem_inter.1 wxz IH w wz wx⟩ /-- The image of a (definable) ZFC set function -/ def image (f : ZFSet → ZFSet) [Definable₁ f] : ZFSet → ZFSet := let r := Definable₁.out f Quotient.map (PSet.image r) fun _ _ e => Mem.ext fun _ => (mem_image (fun _ _ ↦ Definable₁.out_equiv _)).trans <| Iff.trans ⟨fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).1 h1, h2⟩, fun ⟨w, h1, h2⟩ => ⟨w, (Mem.congr_right e).2 h1, h2⟩⟩ <| (mem_image (fun _ _ ↦ Definable₁.out_equiv _)).symm theorem image.mk (f : ZFSet.{u} → ZFSet.{u}) [Definable₁ f] (x) {y} : y ∈ x → f y ∈ image f x := Quotient.inductionOn₂ x y fun ⟨_, _⟩ _ ⟨a, ya⟩ => by simp only [mk_eq, ← Definable₁.mk_out (f := f)] exact ⟨a, Definable₁.out_equiv f ya⟩ @[simp] theorem mem_image {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x y : ZFSet.{u}} : y ∈ image f x ↔ ∃ z ∈ x, f z = y := Quotient.inductionOn₂ x y fun ⟨_, A⟩ _ => ⟨fun ⟨a, ya⟩ => ⟨⟦A a⟧, Mem.mk A a, ((Quotient.sound ya).trans Definable₁.mk_out).symm⟩, fun ⟨_, hz, e⟩ => e ▸ image.mk _ _ hz⟩ @[simp] theorem toSet_image (f : ZFSet → ZFSet) [Definable₁ f] (x : ZFSet) : (image f x).toSet = f '' x.toSet := by ext simp /-- The range of a type-indexed family of sets. -/ noncomputable def range {α} [Small.{u} α] (f : α → ZFSet.{u}) : ZFSet.{u} := ⟦⟨_, Quotient.out ∘ f ∘ (equivShrink α).symm⟩⟧ @[simp] theorem mem_range {α} [Small.{u} α] {f : α → ZFSet.{u}} {x : ZFSet.{u}} : x ∈ range f ↔ x ∈ Set.range f := Quotient.inductionOn x fun y => by constructor · rintro ⟨z, hz⟩ exact ⟨(equivShrink α).symm z, Quotient.eq_mk_iff_out.2 hz.symm⟩ · rintro ⟨z, hz⟩ use equivShrink α z simpa [hz] using PSet.Equiv.symm (Quotient.mk_out y) @[simp] theorem toSet_range {α} [Small.{u} α] (f : α → ZFSet.{u}) : (range f).toSet = Set.range f := by ext simp /-- Kuratowski ordered pair -/ def pair (x y : ZFSet.{u}) : ZFSet.{u} := {{x}, {x, y}} @[simp] theorem toSet_pair (x y : ZFSet.{u}) : (pair x y).toSet = {{x}, {x, y}} := by simp [pair] /-- A subset of pairs `{(a, b) ∈ x × y | p a b}` -/ def pairSep (p : ZFSet.{u} → ZFSet.{u} → Prop) (x y : ZFSet.{u}) : ZFSet.{u} := (powerset (powerset (x ∪ y))).sep fun z => ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b @[simp] theorem mem_pairSep {p} {x y z : ZFSet.{u}} : z ∈ pairSep p x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b ∧ p a b := by refine mem_sep.trans ⟨And.right, fun e => ⟨?_, e⟩⟩ rcases e with ⟨a, ax, b, bY, rfl, pab⟩ simp only [mem_powerset, subset_def, mem_union, pair, mem_pair] rintro u (rfl | rfl) v <;> simp only [mem_singleton, mem_pair] · rintro rfl exact Or.inl ax · rintro (rfl | rfl) <;> [left; right] <;> assumption theorem pair_injective : Function.Injective2 pair := by intro x x' y y' H simp_rw [ZFSet.ext_iff, pair, mem_pair] at H obtain rfl : x = x' := And.left <| by simpa [or_and_left] using (H {x}).1 (Or.inl rfl) have he : y = x → y = y' := by rintro rfl simpa [eq_comm] using H {y, y'} have hx := H {x, y} simp_rw [pair_eq_singleton_iff, true_and, or_true, true_iff] at hx refine ⟨rfl, hx.elim he fun hy ↦ Or.elim ?_ he id⟩ simpa using ZFSet.ext_iff.1 hy y @[simp] theorem pair_inj {x y x' y' : ZFSet} : pair x y = pair x' y' ↔ x = x' ∧ y = y' := pair_injective.eq_iff /-- The cartesian product, `{(a, b) | a ∈ x, b ∈ y}` -/ def prod : ZFSet.{u} → ZFSet.{u} → ZFSet.{u} := pairSep fun _ _ => True @[simp] theorem mem_prod {x y z : ZFSet.{u}} : z ∈ prod x y ↔ ∃ a ∈ x, ∃ b ∈ y, z = pair a b := by simp [prod] theorem pair_mem_prod {x y a b : ZFSet.{u}} : pair a b ∈ prod x y ↔ a ∈ x ∧ b ∈ y := by simp /-- `isFunc x y f` is the assertion that `f` is a subset of `x × y` which relates to each element of `x` a unique element of `y`, so that we can consider `f` as a ZFC function `x → y`. -/ def IsFunc (x y f : ZFSet.{u}) : Prop := f ⊆ prod x y ∧ ∀ z : ZFSet.{u}, z ∈ x → ∃! w, pair z w ∈ f /-- `funs x y` is `y ^ x`, the set of all set functions `x → y` -/ def funs (x y : ZFSet.{u}) : ZFSet.{u} := ZFSet.sep (IsFunc x y) (powerset (prod x y)) @[simp] theorem mem_funs {x y f : ZFSet.{u}} : f ∈ funs x y ↔ IsFunc x y f := by simp [funs, IsFunc] instance : Definable₁ ({·}) := .mk ({·}) (fun _ ↦ rfl) instance : Definable₂ insert := .mk insert (fun _ _ ↦ rfl) instance : Definable₂ pair := by unfold pair; infer_instance /-- Graph of a function: `map f x` is the ZFC function which maps `a ∈ x` to `f a` -/ def map (f : ZFSet → ZFSet) [Definable₁ f] : ZFSet → ZFSet := image fun y => pair y (f y) @[simp] theorem mem_map {f : ZFSet → ZFSet} [Definable₁ f] {x y : ZFSet} : y ∈ map f x ↔ ∃ z ∈ x, pair z (f z) = y := mem_image theorem map_unique {f : ZFSet.{u} → ZFSet.{u}} [Definable₁ f] {x z : ZFSet.{u}} (zx : z ∈ x) : ∃! w, pair z w ∈ map f x := ⟨f z, image.mk _ _ zx, fun y yx => by let ⟨w, _, we⟩ := mem_image.1 yx let ⟨wz, fy⟩ := pair_injective we rw [← fy, wz]⟩ @[simp] theorem map_isFunc {f : ZFSet → ZFSet} [Definable₁ f] {x y : ZFSet} : IsFunc x y (map f x) ↔ ∀ z ∈ x, f z ∈ y := ⟨fun ⟨ss, h⟩ z zx => let ⟨_, t1, t2⟩ := h z zx (t2 (f z) (image.mk _ _ zx)).symm ▸ (pair_mem_prod.1 (ss t1)).right, fun h => ⟨fun _ yx => let ⟨z, zx, ze⟩ := mem_image.1 yx ze ▸ pair_mem_prod.2 ⟨zx, h z zx⟩, fun _ => map_unique⟩⟩ /-- Given a predicate `p` on ZFC sets. `Hereditarily p x` means that `x` has property `p` and the members of `x` are all `Hereditarily p`. -/ def Hereditarily (p : ZFSet → Prop) (x : ZFSet) : Prop := p x ∧ ∀ y ∈ x, Hereditarily p y termination_by x section Hereditarily variable {p : ZFSet.{u} → Prop} {x y : ZFSet.{u}} theorem hereditarily_iff : Hereditarily p x ↔ p x ∧ ∀ y ∈ x, Hereditarily p y := by rw [← Hereditarily] alias ⟨Hereditarily.def, _⟩ := hereditarily_iff theorem Hereditarily.self (h : x.Hereditarily p) : p x := h.def.1 theorem Hereditarily.mem (h : x.Hereditarily p) (hy : y ∈ x) : y.Hereditarily p := h.def.2 _ hy theorem Hereditarily.empty : Hereditarily p x → p ∅ := by apply @ZFSet.inductionOn _ x intro y IH h rcases ZFSet.eq_empty_or_nonempty y with (rfl | ⟨a, ha⟩) · exact h.self · exact IH a ha (h.mem ha) end Hereditarily end ZFSet
Mathlib/SetTheory/ZFC/Basic.lean
1,067
1,069
/- 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.CharP.Lemmas import Mathlib.GroupTheory.OrderOfElement /-! # Lemmas about rings of characteristic two This file contains results about `CharP R 2`, in the `CharTwo` namespace. The lemmas in this file with a `_sq` suffix are just special cases of the `_pow_char` lemmas elsewhere, with a shorter name for ease of discovery, and no need for a `[Fact (Prime 2)]` argument. -/ assert_not_exists Algebra LinearMap variable {R ι : Type*} namespace CharTwo section AddMonoidWithOne variable [AddMonoidWithOne R] theorem two_eq_zero [CharP R 2] : (2 : R) = 0 := by rw [← Nat.cast_two, CharP.cast_eq_zero] /-- The only hypotheses required to build a `CharP R 2` instance are `1 ≠ 0` and `2 = 0`. -/ theorem of_one_ne_zero_of_two_eq_zero (h₁ : (1 : R) ≠ 0) (h₂ : (2 : R) = 0) : CharP R 2 where cast_eq_zero_iff n := by obtain hn | hn := Nat.even_or_odd n · simp_rw [hn.two_dvd, iff_true] exact natCast_eq_zero_of_even_of_two_eq_zero hn h₂ · simp_rw [hn.not_two_dvd_nat, iff_false] rwa [natCast_eq_one_of_odd_of_two_eq_zero hn h₂] end AddMonoidWithOne section Semiring variable [Semiring R] [CharP R 2] @[scoped simp] theorem add_self_eq_zero (x : R) : x + x = 0 := by rw [← two_smul R x, two_eq_zero, zero_smul] @[scoped simp] protected theorem two_nsmul (x : R) : 2 • x = 0 := by rw [two_smul, add_self_eq_zero] end Semiring section Ring variable [Ring R] [CharP R 2] @[scoped simp] theorem neg_eq (x : R) : -x = x := by rw [neg_eq_iff_add_eq_zero, add_self_eq_zero] theorem neg_eq' : Neg.neg = (id : R → R) := funext neg_eq @[scoped simp] theorem sub_eq_add (x y : R) : x - y = x + y := by rw [sub_eq_add_neg, neg_eq] @[deprecated sub_eq_add (since := "2024-10-24")] theorem sub_eq_add' : HSub.hSub = (· + · : R → R → R) := funext₂ sub_eq_add theorem add_eq_iff_eq_add {a b c : R} : a + b = c ↔ a = c + b := by rw [← sub_eq_iff_eq_add, sub_eq_add] theorem eq_add_iff_add_eq {a b c : R} : a = b + c ↔ a + c = b := by rw [← eq_sub_iff_add_eq, sub_eq_add] @[scoped simp] protected theorem two_zsmul (x : R) : (2 : ℤ) • x = 0 := by rw [two_zsmul, add_self_eq_zero] end Ring section CommSemiring variable [CommSemiring R] [CharP R 2] theorem add_sq (x y : R) : (x + y) ^ 2 = x ^ 2 + y ^ 2 := add_pow_char _ _ _ theorem add_mul_self (x y : R) : (x + y) * (x + y) = x * x + y * y := by rw [← pow_two, ← pow_two, ← pow_two, add_sq] theorem list_sum_sq (l : List R) : l.sum ^ 2 = (l.map (· ^ 2)).sum := list_sum_pow_char _ _ theorem list_sum_mul_self (l : List R) : l.sum * l.sum = (List.map (fun x => x * x) l).sum := by simp_rw [← pow_two, list_sum_sq] theorem multiset_sum_sq (l : Multiset R) : l.sum ^ 2 = (l.map (· ^ 2)).sum := multiset_sum_pow_char _ _ theorem multiset_sum_mul_self (l : Multiset R) : l.sum * l.sum = (Multiset.map (fun x => x * x) l).sum := by simp_rw [← pow_two, multiset_sum_sq] theorem sum_sq (s : Finset ι) (f : ι → R) : (∑ i ∈ s, f i) ^ 2 = ∑ i ∈ s, f i ^ 2 := sum_pow_char _ _ _ theorem sum_mul_self (s : Finset ι) (f : ι → R) : ((∑ i ∈ s, f i) * ∑ i ∈ s, f i) = ∑ i ∈ s, f i * f i := by simp_rw [← pow_two, sum_sq] end CommSemiring end CharTwo
section ringChar
Mathlib/Algebra/CharP/Two.lean
115
116
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Michael Stoll -/ import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic /-! # Legendre symbol This file contains results about Legendre symbols. We define the Legendre symbol $\Bigl(\frac{a}{p}\Bigr)$ as `legendreSym p a`. Note the order of arguments! The advantage of this form is that then `legendreSym p` is a multiplicative map. The Legendre symbol is used to define the Jacobi symbol, `jacobiSym a b`, for integers `a` and (odd) natural numbers `b`, which extends the Legendre symbol. ## Main results We also prove the supplementary laws that give conditions for when `-1` is a square modulo a prime `p`: `legendreSym.at_neg_one` and `ZMod.exists_sq_eq_neg_one_iff` for `-1`. See `NumberTheory.LegendreSymbol.QuadraticReciprocity` for the conditions when `2` and `-2` are squares: `legendreSym.at_two` and `ZMod.exists_sq_eq_two_iff` for `2`, `legendreSym.at_neg_two` and `ZMod.exists_sq_eq_neg_two_iff` for `-2`. ## Tags quadratic residue, quadratic nonresidue, Legendre symbol -/ open Nat section Euler namespace ZMod variable (p : ℕ) [Fact p.Prime] /-- Euler's Criterion: A unit `x` of `ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/ theorem euler_criterion_units (x : (ZMod p)ˣ) : (∃ y : (ZMod p)ˣ, y ^ 2 = x) ↔ x ^ (p / 2) = 1 := by by_cases hc : p = 2 · subst hc simp only [eq_iff_true_of_subsingleton, exists_const] · have h₀ := FiniteField.unit_isSquare_iff (by rwa [ringChar_zmod_n]) x have hs : (∃ y : (ZMod p)ˣ, y ^ 2 = x) ↔ IsSquare x := by rw [isSquare_iff_exists_sq x] simp_rw [eq_comm] rw [hs] rwa [card p] at h₀ /-- Euler's Criterion: a nonzero `a : ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/ theorem euler_criterion {a : ZMod p} (ha : a ≠ 0) : IsSquare (a : ZMod p) ↔ a ^ (p / 2) = 1 := by apply (iff_congr _ (by simp [Units.ext_iff])).mp (euler_criterion_units p (Units.mk0 a ha)) simp only [Units.ext_iff, sq, Units.val_mk0, Units.val_mul] constructor · rintro ⟨y, hy⟩; exact ⟨y, hy.symm⟩ · rintro ⟨y, rfl⟩ have hy : y ≠ 0 := by rintro rfl simp [zero_pow, mul_zero, ne_eq, not_true] at ha refine ⟨Units.mk0 y hy, ?_⟩; simp /-- If `a : ZMod p` is nonzero, then `a^(p/2)` is either `1` or `-1`. -/ theorem pow_div_two_eq_neg_one_or_one {a : ZMod p} (ha : a ≠ 0) : a ^ (p / 2) = 1 ∨ a ^ (p / 2) = -1 := by rcases Prime.eq_two_or_odd (@Fact.out p.Prime _) with hp2 | hp_odd · subst p; revert a ha; intro a; fin_cases a · tauto · simp rw [← mul_self_eq_one_iff, ← pow_add, ← two_mul, two_mul_odd_div_two hp_odd] exact pow_card_sub_one_eq_one ha end ZMod end Euler section Legendre /-! ### Definition of the Legendre symbol and basic properties -/ open ZMod variable (p : ℕ) [Fact p.Prime] /-- The Legendre symbol of `a : ℤ` and a prime `p`, `legendreSym p a`, is an integer defined as * `0` if `a` is `0` modulo `p`; * `1` if `a` is a nonzero square modulo `p` * `-1` otherwise. Note the order of the arguments! The advantage of the order chosen here is that `legendreSym p` is a multiplicative function `ℤ → ℤ`. -/ def legendreSym (a : ℤ) : ℤ := quadraticChar (ZMod p) a namespace legendreSym /-- We have the congruence `legendreSym p a ≡ a ^ (p / 2) mod p`. -/ theorem eq_pow (a : ℤ) : (legendreSym p a : ZMod p) = (a : ZMod p) ^ (p / 2) := by rcases eq_or_ne (ringChar (ZMod p)) 2 with hc | hc · by_cases ha : (a : ZMod p) = 0 · rw [legendreSym, ha, quadraticChar_zero, zero_pow (Nat.div_pos (@Fact.out p.Prime).two_le (succ_pos 1)).ne'] norm_cast · have := (ringChar_zmod_n p).symm.trans hc -- p = 2 subst p rw [legendreSym, quadraticChar_eq_one_of_char_two hc ha] revert ha push_cast generalize (a : ZMod 2) = b; fin_cases b · tauto · simp · convert quadraticChar_eq_pow_of_char_ne_two' hc (a : ZMod p) exact (card p).symm /-- If `p ∤ a`, then `legendreSym p a` is `1` or `-1`. -/ theorem eq_one_or_neg_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p a = 1 ∨ legendreSym p a = -1 := quadraticChar_dichotomy ha theorem eq_neg_one_iff_not_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p a = -1 ↔ ¬legendreSym p a = 1 := quadraticChar_eq_neg_one_iff_not_one ha /-- The Legendre symbol of `p` and `a` is zero iff `p ∣ a`. -/ theorem eq_zero_iff (a : ℤ) : legendreSym p a = 0 ↔ (a : ZMod p) = 0 := quadraticChar_eq_zero_iff @[simp] theorem at_zero : legendreSym p 0 = 0 := by rw [legendreSym, Int.cast_zero, MulChar.map_zero] @[simp] theorem at_one : legendreSym p 1 = 1 := by rw [legendreSym, Int.cast_one, MulChar.map_one] /-- The Legendre symbol is multiplicative in `a` for `p` fixed. -/ protected theorem mul (a b : ℤ) : legendreSym p (a * b) = legendreSym p a * legendreSym p b := by simp [legendreSym, Int.cast_mul, map_mul, quadraticCharFun_mul] /-- The Legendre symbol is a homomorphism of monoids with zero. -/ @[simps] def hom : ℤ →*₀ ℤ where toFun := legendreSym p map_zero' := at_zero p map_one' := at_one p map_mul' := legendreSym.mul p /-- The square of the symbol is 1 if `p ∤ a`. -/ theorem sq_one {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p a ^ 2 = 1 := quadraticChar_sq_one ha /-- The Legendre symbol of `a^2` at `p` is 1 if `p ∤ a`. -/ theorem sq_one' {a : ℤ} (ha : (a : ZMod p) ≠ 0) : legendreSym p (a ^ 2) = 1 := by dsimp only [legendreSym] rw [Int.cast_pow] exact quadraticChar_sq_one' ha /-- The Legendre symbol depends only on `a` mod `p`. -/ protected theorem mod (a : ℤ) : legendreSym p a = legendreSym p (a % p) := by simp only [legendreSym, intCast_mod] /-- When `p ∤ a`, then `legendreSym p a = 1` iff `a` is a square mod `p`. -/ theorem eq_one_iff {a : ℤ} (ha0 : (a : ZMod p) ≠ 0) : legendreSym p a = 1 ↔ IsSquare (a : ZMod p) := quadraticChar_one_iff_isSquare ha0 theorem eq_one_iff' {a : ℕ} (ha0 : (a : ZMod p) ≠ 0) : legendreSym p a = 1 ↔ IsSquare (a : ZMod p) := by rw [eq_one_iff] · norm_cast · exact mod_cast ha0 /-- `legendreSym p a = -1` iff `a` is a nonsquare mod `p`. -/ theorem eq_neg_one_iff {a : ℤ} : legendreSym p a = -1 ↔ ¬IsSquare (a : ZMod p) := quadraticChar_neg_one_iff_not_isSquare theorem eq_neg_one_iff' {a : ℕ} : legendreSym p a = -1 ↔ ¬IsSquare (a : ZMod p) := by rw [eq_neg_one_iff]; norm_cast /-- The number of square roots of `a` modulo `p` is determined by the Legendre symbol. -/ theorem card_sqrts (hp : p ≠ 2) (a : ℤ) : ↑{x : ZMod p | x ^ 2 = a}.toFinset.card = legendreSym p a + 1 := quadraticChar_card_sqrts ((ringChar_zmod_n p).substr hp) a end legendreSym end Legendre section QuadraticForm /-! ### Applications to binary quadratic forms -/ namespace legendreSym /-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `ℤ/pℤ` of the equation `x^2 - a*y^2 = 0` with `y ≠ 0`. -/ theorem eq_one_of_sq_sub_mul_sq_eq_zero {p : ℕ} [Fact p.Prime] {a : ℤ} (ha : (a : ZMod p) ≠ 0) {x y : ZMod p} (hy : y ≠ 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by apply_fun (· * y⁻¹ ^ 2) at hxy simp only [zero_mul] at hxy rw [(by ring : (x ^ 2 - ↑a * y ^ 2) * y⁻¹ ^ 2 = (x * y⁻¹) ^ 2 - a * (y * y⁻¹) ^ 2), mul_inv_cancel₀ hy, one_pow, mul_one, sub_eq_zero, pow_two] at hxy exact (eq_one_iff p ha).mpr ⟨x * y⁻¹, hxy.symm⟩ /-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `ℤ/pℤ` of the equation `x^2 - a*y^2 = 0` with `x ≠ 0`. -/ theorem eq_one_of_sq_sub_mul_sq_eq_zero' {p : ℕ} [Fact p.Prime] {a : ℤ} (ha : (a : ZMod p) ≠ 0) {x y : ZMod p} (hx : x ≠ 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by haveI hy : y ≠ 0 := by rintro rfl rw [zero_pow two_ne_zero, mul_zero, sub_zero, sq_eq_zero_iff] at hxy exact hx hxy exact eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy /-- If `legendreSym p a = -1`, then the only solution of `x^2 - a*y^2 = 0` in `ℤ/pℤ` is the trivial one. -/ theorem eq_zero_mod_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : legendreSym p a = -1) {x y : ZMod p} (hxy : x ^ 2 - a * y ^ 2 = 0) : x = 0 ∧ y = 0 := by have ha : (a : ZMod p) ≠ 0 := by intro hf rw [(eq_zero_iff p a).mpr hf] at h simp at h by_contra hf rcases imp_iff_or_not.mp (not_and'.mp hf) with hx | hy · rw [eq_one_of_sq_sub_mul_sq_eq_zero' ha hx hxy, CharZero.eq_neg_self_iff] at h exact one_ne_zero h · rw [eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy, CharZero.eq_neg_self_iff] at h exact one_ne_zero h /-- If `legendreSym p a = -1` and `p` divides `x^2 - a*y^2`, then `p` must divide `x` and `y`. -/ theorem prime_dvd_of_eq_neg_one {p : ℕ} [Fact p.Prime] {a : ℤ} (h : legendreSym p a = -1) {x y : ℤ} (hxy : (p : ℤ) ∣ x ^ 2 - a * y ^ 2) : ↑p ∣ x ∧ ↑p ∣ y := by simp_rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] at hxy ⊢ push_cast at hxy exact eq_zero_mod_of_eq_neg_one h hxy end legendreSym end QuadraticForm
section Values /-! ### The value of the Legendre symbol at `-1` See `jacobiSym.at_neg_one` for the corresponding statement for the Jacobi symbol. -/ variable {p : ℕ} [Fact p.Prime] open ZMod
Mathlib/NumberTheory/LegendreSymbol/Basic.lean
254
265
/- 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 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 refine (p.toOuterMeasure_apply s).symm ▸ ⟨fun h a hap => ?_, fun h => ?_⟩ · refine by_contra fun hs => ne_of_lt ?_ (h.trans p.tsum_coe.symm) have hs' : s.indicator p a = 0 := Set.indicator_apply_eq_zero.2 fun hs' => False.elim <| hs hs' have hsa : s.indicator p a < p a := hs'.symm ▸ (p.apply_pos_iff a).2 hap exact ENNReal.tsum_lt_tsum (p.tsum_coe_indicator_ne_top s) (fun x => Set.indicator_apply_le fun _ => le_rfl) hsa · classical suffices ∀ (x) (_ : x ∉ s), p x = 0 from _root_.trans (tsum_congr fun a => (Set.indicator_apply s p a).trans (ite_eq_left_iff.2 <| symm ∘ this a)) p.tsum_coe exact fun a ha => (p.apply_eq_zero_iff a).2 <| Set.not_mem_subset h ha @[simp] theorem toOuterMeasure_apply_inter_support : p.toOuterMeasure (s ∩ p.support) = p.toOuterMeasure s := by simp only [toOuterMeasure_apply, PMF.support, Set.indicator_inter_support] /-- Slightly stronger than `OuterMeasure.mono` having an intersection with `p.support`. -/ theorem toOuterMeasure_mono {s t : Set α} (h : s ∩ p.support ⊆ t) : p.toOuterMeasure s ≤ p.toOuterMeasure t := le_trans (le_of_eq (toOuterMeasure_apply_inter_support p s).symm) (p.toOuterMeasure.mono h) theorem toOuterMeasure_apply_eq_of_inter_support_eq {s t : Set α} (h : s ∩ p.support = t ∩ p.support) : p.toOuterMeasure s = p.toOuterMeasure t := le_antisymm (p.toOuterMeasure_mono (h.symm ▸ Set.inter_subset_left)) (p.toOuterMeasure_mono (h ▸ Set.inter_subset_left)) @[simp] theorem toOuterMeasure_apply_fintype [Fintype α] : p.toOuterMeasure s = ∑ x, s.indicator p x := (p.toOuterMeasure_apply s).trans (tsum_eq_sum fun x h => absurd (Finset.mem_univ x) h) end OuterMeasure section Measure open MeasureTheory /-- Since every set is Carathéodory-measurable under `PMF.toOuterMeasure`, we can further extend this `OuterMeasure` to a `Measure` on `α`. -/ def toMeasure [MeasurableSpace α] (p : PMF α) : Measure α := p.toOuterMeasure.toMeasure ((toOuterMeasure_caratheodory p).symm ▸ le_top) variable [MeasurableSpace α] (p : PMF α) (s : Set α) theorem toOuterMeasure_apply_le_toMeasure_apply : p.toOuterMeasure s ≤ p.toMeasure s := le_toMeasure_apply p.toOuterMeasure _ s theorem toMeasure_apply_eq_toOuterMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = p.toOuterMeasure s := toMeasure_apply p.toOuterMeasure _ hs theorem toMeasure_apply (hs : MeasurableSet s) : p.toMeasure s = ∑' x, s.indicator p x := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs).trans (p.toOuterMeasure_apply s) theorem toMeasure_apply_singleton (a : α) (h : MeasurableSet ({a} : Set α)) : p.toMeasure {a} = p a := by simp [toMeasure_apply_eq_toOuterMeasure_apply _ _ h, toOuterMeasure_apply_singleton] theorem toMeasure_apply_eq_zero_iff (hs : MeasurableSet s) : p.toMeasure s = 0 ↔ Disjoint p.support s := by rw [toMeasure_apply_eq_toOuterMeasure_apply p s hs, toOuterMeasure_apply_eq_zero_iff] theorem toMeasure_apply_eq_one_iff (hs : MeasurableSet s) : p.toMeasure s = 1 ↔ p.support ⊆ s := (p.toMeasure_apply_eq_toOuterMeasure_apply s hs).symm ▸ p.toOuterMeasure_apply_eq_one_iff s @[simp] theorem toMeasure_apply_inter_support (hs : MeasurableSet s) (hp : MeasurableSet p.support) : p.toMeasure (s ∩ p.support) = p.toMeasure s := by simp [p.toMeasure_apply_eq_toOuterMeasure_apply s hs, p.toMeasure_apply_eq_toOuterMeasure_apply _ (hs.inter hp)] @[simp] theorem restrict_toMeasure_support [MeasurableSingletonClass α] (p : PMF α) : Measure.restrict (toMeasure p) (support p) = toMeasure p := by ext s hs apply (MeasureTheory.Measure.restrict_apply hs).trans apply toMeasure_apply_inter_support p s hs p.support_countable.measurableSet theorem toMeasure_mono {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : s ∩ p.support ⊆ t) : p.toMeasure s ≤ p.toMeasure t := by simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using toOuterMeasure_mono p h theorem toMeasure_apply_eq_of_inter_support_eq {s t : Set α} (hs : MeasurableSet s) (ht : MeasurableSet t) (h : s ∩ p.support = t ∩ p.support) : p.toMeasure s = p.toMeasure t := by simpa only [p.toMeasure_apply_eq_toOuterMeasure_apply, hs, ht] using toOuterMeasure_apply_eq_of_inter_support_eq p h section MeasurableSingletonClass variable [MeasurableSingletonClass α] theorem toMeasure_injective : (toMeasure : PMF α → Measure α).Injective := by intro p q h ext x rw [← p.toMeasure_apply_singleton x <| measurableSet_singleton x, ← q.toMeasure_apply_singleton x <| measurableSet_singleton x, h] @[simp]
theorem toMeasure_inj {p q : PMF α} : p.toMeasure = q.toMeasure ↔ p = q := toMeasure_injective.eq_iff
Mathlib/Probability/ProbabilityMassFunction/Basic.lean
269
271
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Bhavik Mehta -/ import Mathlib.CategoryTheory.Comma.Over.Basic import Mathlib.CategoryTheory.Discrete.Basic import Mathlib.CategoryTheory.EpiMono import Mathlib.CategoryTheory.Limits.Shapes.Terminal /-! # Binary (co)products We define a category `WalkingPair`, which is the index category for a binary (co)product diagram. A convenience method `pair X Y` constructs the functor from the walking pair, hitting the given objects. We define `prod X Y` and `coprod X Y` as limits and colimits of such functors. Typeclasses `HasBinaryProducts` and `HasBinaryCoproducts` assert the existence of (co)limits shaped as walking pairs. We include lemmas for simplifying equations involving projections and coprojections, and define braiding and associating isomorphisms, and the product comparison morphism. ## References * [Stacks: Products of pairs](https://stacks.math.columbia.edu/tag/001R) * [Stacks: coproducts of pairs](https://stacks.math.columbia.edu/tag/04AN) -/ universe v v₁ u u₁ u₂ open CategoryTheory namespace CategoryTheory.Limits /-- The type of objects for the diagram indexing a binary (co)product. -/ inductive WalkingPair : Type | left | right deriving DecidableEq, Inhabited open WalkingPair /-- The equivalence swapping left and right. -/ def WalkingPair.swap : WalkingPair ≃ WalkingPair where toFun | left => right | right => left invFun | left => right | right => left left_inv j := by cases j <;> rfl right_inv j := by cases j <;> rfl @[simp] theorem WalkingPair.swap_apply_left : WalkingPair.swap left = right := rfl @[simp] theorem WalkingPair.swap_apply_right : WalkingPair.swap right = left := rfl @[simp] theorem WalkingPair.swap_symm_apply_tt : WalkingPair.swap.symm left = right := rfl @[simp] theorem WalkingPair.swap_symm_apply_ff : WalkingPair.swap.symm right = left := rfl /-- An equivalence from `WalkingPair` to `Bool`, sometimes useful when reindexing limits. -/ def WalkingPair.equivBool : WalkingPair ≃ Bool where toFun | left => true | right => false -- to match equiv.sum_equiv_sigma_bool invFun b := Bool.recOn b right left left_inv j := by cases j <;> rfl right_inv b := by cases b <;> rfl @[simp] theorem WalkingPair.equivBool_apply_left : WalkingPair.equivBool left = true := rfl @[simp] theorem WalkingPair.equivBool_apply_right : WalkingPair.equivBool right = false := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_true : WalkingPair.equivBool.symm true = left := rfl @[simp] theorem WalkingPair.equivBool_symm_apply_false : WalkingPair.equivBool.symm false = right := rfl variable {C : Type u} /-- The function on the walking pair, sending the two points to `X` and `Y`. -/ def pairFunction (X Y : C) : WalkingPair → C := fun j => WalkingPair.casesOn j X Y @[simp] theorem pairFunction_left (X Y : C) : pairFunction X Y left = X := rfl @[simp] theorem pairFunction_right (X Y : C) : pairFunction X Y right = Y := rfl variable [Category.{v} C] /-- The diagram on the walking pair, sending the two points to `X` and `Y`. -/ def pair (X Y : C) : Discrete WalkingPair ⥤ C := Discrete.functor fun j => WalkingPair.casesOn j X Y @[simp] theorem pair_obj_left (X Y : C) : (pair X Y).obj ⟨left⟩ = X := rfl @[simp] theorem pair_obj_right (X Y : C) : (pair X Y).obj ⟨right⟩ = Y := rfl section variable {F G : Discrete WalkingPair ⥤ C} (f : F.obj ⟨left⟩ ⟶ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ⟶ G.obj ⟨right⟩) attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases /-- The natural transformation between two functors out of the walking pair, specified by its components. -/ def mapPair : F ⟶ G where app | ⟨left⟩ => f | ⟨right⟩ => g naturality := fun ⟨X⟩ ⟨Y⟩ ⟨⟨u⟩⟩ => by aesop_cat @[simp] theorem mapPair_left : (mapPair f g).app ⟨left⟩ = f := rfl @[simp] theorem mapPair_right : (mapPair f g).app ⟨right⟩ = g := rfl /-- The natural isomorphism between two functors out of the walking pair, specified by its components. -/ @[simps!] def mapPairIso (f : F.obj ⟨left⟩ ≅ G.obj ⟨left⟩) (g : F.obj ⟨right⟩ ≅ G.obj ⟨right⟩) : F ≅ G := NatIso.ofComponents (fun j ↦ match j with | ⟨left⟩ => f | ⟨right⟩ => g) (fun ⟨⟨u⟩⟩ => by aesop_cat) end /-- Every functor out of the walking pair is naturally isomorphic (actually, equal) to a `pair` -/ @[simps!] def diagramIsoPair (F : Discrete WalkingPair ⥤ C) : F ≅ pair (F.obj ⟨WalkingPair.left⟩) (F.obj ⟨WalkingPair.right⟩) := mapPairIso (Iso.refl _) (Iso.refl _) section variable {D : Type u₁} [Category.{v₁} D] /-- The natural isomorphism between `pair X Y ⋙ F` and `pair (F.obj X) (F.obj Y)`. -/ def pairComp (X Y : C) (F : C ⥤ D) : pair X Y ⋙ F ≅ pair (F.obj X) (F.obj Y) := diagramIsoPair _ end /-- A binary fan is just a cone on a diagram indexing a product. -/ abbrev BinaryFan (X Y : C) := Cone (pair X Y) /-- The first projection of a binary fan. -/ abbrev BinaryFan.fst {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.left⟩ /-- The second projection of a binary fan. -/ abbrev BinaryFan.snd {X Y : C} (s : BinaryFan X Y) := s.π.app ⟨WalkingPair.right⟩ @[simp] theorem BinaryFan.π_app_left {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.left⟩ = s.fst := rfl @[simp] theorem BinaryFan.π_app_right {X Y : C} (s : BinaryFan X Y) : s.π.app ⟨WalkingPair.right⟩ = s.snd := rfl /-- Constructs an isomorphism of `BinaryFan`s out of an isomorphism of the tips that commutes with the projections. -/ def BinaryFan.ext {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt) (h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : c ≅ c' := Cones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption) @[simp] lemma BinaryFan.ext_hom_hom {A B : C} {c c' : BinaryFan A B} (e : c.pt ≅ c'.pt) (h₁ : c.fst = e.hom ≫ c'.fst) (h₂ : c.snd = e.hom ≫ c'.snd) : (ext e h₁ h₂).hom.hom = e.hom := rfl /-- A convenient way to show that a binary fan is a limit. -/ def BinaryFan.IsLimit.mk {X Y : C} (s : BinaryFan X Y) (lift : ∀ {T : C} (_ : T ⟶ X) (_ : T ⟶ Y), T ⟶ s.pt) (hl₁ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.fst = f) (hl₂ : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y), lift f g ≫ s.snd = g) (uniq : ∀ {T : C} (f : T ⟶ X) (g : T ⟶ Y) (m : T ⟶ s.pt) (_ : m ≫ s.fst = f) (_ : m ≫ s.snd = g), m = lift f g) : IsLimit s := Limits.IsLimit.mk (fun t => lift (BinaryFan.fst t) (BinaryFan.snd t)) (by rintro t (rfl | rfl) · exact hl₁ _ _ · exact hl₂ _ _) fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryFan.IsLimit.hom_ext {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) {f g : W ⟶ s.pt} (h₁ : f ≫ s.fst = g ≫ s.fst) (h₂ : f ≫ s.snd = g ≫ s.snd) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ /-- A binary cofan is just a cocone on a diagram indexing a coproduct. -/ abbrev BinaryCofan (X Y : C) := Cocone (pair X Y) /-- The first inclusion of a binary cofan. -/ abbrev BinaryCofan.inl {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.left⟩ /-- The second inclusion of a binary cofan. -/ abbrev BinaryCofan.inr {X Y : C} (s : BinaryCofan X Y) := s.ι.app ⟨WalkingPair.right⟩ /-- Constructs an isomorphism of `BinaryCofan`s out of an isomorphism of the tips that commutes with the injections. -/ def BinaryCofan.ext {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt) (h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : c ≅ c' := Cocones.ext e (fun j => by rcases j with ⟨⟨⟩⟩ <;> assumption) @[simp] lemma BinaryCofan.ext_hom_hom {A B : C} {c c' : BinaryCofan A B} (e : c.pt ≅ c'.pt) (h₁ : c.inl ≫ e.hom = c'.inl) (h₂ : c.inr ≫ e.hom = c'.inr) : (ext e h₁ h₂).hom.hom = e.hom := rfl @[simp] theorem BinaryCofan.ι_app_left {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.left⟩ = s.inl := rfl @[simp] theorem BinaryCofan.ι_app_right {X Y : C} (s : BinaryCofan X Y) : s.ι.app ⟨WalkingPair.right⟩ = s.inr := rfl /-- A convenient way to show that a binary cofan is a colimit. -/ def BinaryCofan.IsColimit.mk {X Y : C} (s : BinaryCofan X Y) (desc : ∀ {T : C} (_ : X ⟶ T) (_ : Y ⟶ T), s.pt ⟶ T) (hd₁ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inl ≫ desc f g = f) (hd₂ : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T), s.inr ≫ desc f g = g) (uniq : ∀ {T : C} (f : X ⟶ T) (g : Y ⟶ T) (m : s.pt ⟶ T) (_ : s.inl ≫ m = f) (_ : s.inr ≫ m = g), m = desc f g) : IsColimit s := Limits.IsColimit.mk (fun t => desc (BinaryCofan.inl t) (BinaryCofan.inr t)) (by rintro t (rfl | rfl) · exact hd₁ _ _ · exact hd₂ _ _) fun _ _ h => uniq _ _ _ (h ⟨WalkingPair.left⟩) (h ⟨WalkingPair.right⟩) theorem BinaryCofan.IsColimit.hom_ext {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) {f g : s.pt ⟶ W} (h₁ : s.inl ≫ f = s.inl ≫ g) (h₂ : s.inr ≫ f = s.inr ≫ g) : f = g := h.hom_ext fun j => Discrete.recOn j fun j => WalkingPair.casesOn j h₁ h₂ variable {X Y : C} section 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 /-- A binary fan with vertex `P` consists of the two projections `π₁ : P ⟶ X` and `π₂ : P ⟶ Y`. -/ @[simps pt] def BinaryFan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : BinaryFan X Y where pt := P π := { app := fun | { as := j } => match j with | left => π₁ | right => π₂ } /-- A binary cofan with vertex `P` consists of the two inclusions `ι₁ : X ⟶ P` and `ι₂ : Y ⟶ P`. -/ @[simps pt] def BinaryCofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : BinaryCofan X Y where pt := P ι := { app := fun | { as := j } => match j with | left => ι₁ | right => ι₂ } end @[simp] theorem BinaryFan.mk_fst {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).fst = π₁ := rfl @[simp] theorem BinaryFan.mk_snd {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : (BinaryFan.mk π₁ π₂).snd = π₂ := rfl @[simp] theorem BinaryCofan.mk_inl {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inl = ι₁ := rfl @[simp] theorem BinaryCofan.mk_inr {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : (BinaryCofan.mk ι₁ ι₂).inr = ι₂ := rfl /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryFanMk {X Y : C} (c : BinaryFan X Y) : c ≅ BinaryFan.mk c.fst c.snd := Cones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp /-- Every `BinaryFan` is isomorphic to an application of `BinaryFan.mk`. -/ def isoBinaryCofanMk {X Y : C} (c : BinaryCofan X Y) : c ≅ BinaryCofan.mk c.inl c.inr := Cocones.ext (Iso.refl _) fun ⟨l⟩ => by cases l; repeat simp /-- This is a more convenient formulation to show that a `BinaryFan` constructed using `BinaryFan.mk` is a limit cone. -/ def BinaryFan.isLimitMk {W : C} {fst : W ⟶ X} {snd : W ⟶ Y} (lift : ∀ s : BinaryFan X Y, s.pt ⟶ W) (fac_left : ∀ s : BinaryFan X Y, lift s ≫ fst = s.fst) (fac_right : ∀ s : BinaryFan X Y, lift s ≫ snd = s.snd) (uniq : ∀ (s : BinaryFan X Y) (m : s.pt ⟶ W) (_ : m ≫ fst = s.fst) (_ : m ≫ snd = s.snd), m = lift s) : IsLimit (BinaryFan.mk fst snd) := { lift := lift fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- This is a more convenient formulation to show that a `BinaryCofan` constructed using `BinaryCofan.mk` is a colimit cocone. -/ def BinaryCofan.isColimitMk {W : C} {inl : X ⟶ W} {inr : Y ⟶ W} (desc : ∀ s : BinaryCofan X Y, W ⟶ s.pt) (fac_left : ∀ s : BinaryCofan X Y, inl ≫ desc s = s.inl) (fac_right : ∀ s : BinaryCofan X Y, inr ≫ desc s = s.inr) (uniq : ∀ (s : BinaryCofan X Y) (m : W ⟶ s.pt) (_ : inl ≫ m = s.inl) (_ : inr ≫ m = s.inr), m = desc s) : IsColimit (BinaryCofan.mk inl inr) := { desc := desc fac := fun s j => by rcases j with ⟨⟨⟩⟩ exacts [fac_left s, fac_right s] uniq := fun s m w => uniq s m (w ⟨WalkingPair.left⟩) (w ⟨WalkingPair.right⟩) } /-- If `s` is a limit binary fan over `X` and `Y`, then every pair of morphisms `f : W ⟶ X` and `g : W ⟶ Y` induces a morphism `l : W ⟶ s.pt` satisfying `l ≫ s.fst = f` and `l ≫ s.snd = g`. -/ @[simps] def BinaryFan.IsLimit.lift' {W X Y : C} {s : BinaryFan X Y} (h : IsLimit s) (f : W ⟶ X) (g : W ⟶ Y) : { l : W ⟶ s.pt // l ≫ s.fst = f ∧ l ≫ s.snd = g } := ⟨h.lift <| BinaryFan.mk f g, h.fac _ _, h.fac _ _⟩ /-- If `s` is a colimit binary cofan over `X` and `Y`,, then every pair of morphisms `f : X ⟶ W` and `g : Y ⟶ W` induces a morphism `l : s.pt ⟶ W` satisfying `s.inl ≫ l = f` and `s.inr ≫ l = g`. -/ @[simps] def BinaryCofan.IsColimit.desc' {W X Y : C} {s : BinaryCofan X Y} (h : IsColimit s) (f : X ⟶ W) (g : Y ⟶ W) : { l : s.pt ⟶ W // s.inl ≫ l = f ∧ s.inr ≫ l = g } := ⟨h.desc <| BinaryCofan.mk f g, h.fac _ _, h.fac _ _⟩ /-- Binary products are symmetric. -/ def BinaryFan.isLimitFlip {X Y : C} {c : BinaryFan X Y} (hc : IsLimit c) : IsLimit (BinaryFan.mk c.snd c.fst) := BinaryFan.isLimitMk (fun s => hc.lift (BinaryFan.mk s.snd s.fst)) (fun _ => hc.fac _ _) (fun _ => hc.fac _ _) fun s _ e₁ e₂ => BinaryFan.IsLimit.hom_ext hc (e₂.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.left⟩).symm) (e₁.trans (hc.fac (BinaryFan.mk s.snd s.fst) ⟨WalkingPair.right⟩).symm) theorem BinaryFan.isLimit_iff_isIso_fst {X Y : C} (h : IsTerminal Y) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.fst := by constructor · rintro ⟨H⟩ obtain ⟨l, hl, -⟩ := BinaryFan.IsLimit.lift' H (𝟙 X) (h.from X) exact ⟨⟨l, BinaryFan.IsLimit.hom_ext H (by simpa [hl, -Category.comp_id] using Category.comp_id _) (h.hom_ext _ _), hl⟩⟩ · intro exact ⟨BinaryFan.IsLimit.mk _ (fun f _ => f ≫ inv c.fst) (fun _ _ => by simp) (fun _ _ => h.hom_ext _ _) fun _ _ _ e _ => by simp [← e]⟩ theorem BinaryFan.isLimit_iff_isIso_snd {X Y : C} (h : IsTerminal X) (c : BinaryFan X Y) : Nonempty (IsLimit c) ↔ IsIso c.snd := by refine Iff.trans ?_ (BinaryFan.isLimit_iff_isIso_fst h (BinaryFan.mk c.snd c.fst)) exact ⟨fun h => ⟨BinaryFan.isLimitFlip h.some⟩, fun h => ⟨(BinaryFan.isLimitFlip h.some).ofIsoLimit (isoBinaryFanMk c).symm⟩⟩ /-- If `X' ≅ X`, then `X × Y` also is the product of `X'` and `Y`. -/ noncomputable def BinaryFan.isLimitCompLeftIso {X Y X' : C} (c : BinaryFan X Y) (f : X ⟶ X')
[IsIso f] (h : IsLimit c) : IsLimit (BinaryFan.mk (c.fst ≫ f) c.snd) := by fapply BinaryFan.isLimitMk · exact fun s => h.lift (BinaryFan.mk (s.fst ≫ inv f) s.snd) · intro s -- Porting note: simp timed out here simp only [Category.comp_id,BinaryFan.π_app_left,IsIso.inv_hom_id, BinaryFan.mk_fst,IsLimit.fac_assoc,eq_self_iff_true,Category.assoc] · intro s -- Porting note: simp timed out here simp only [BinaryFan.π_app_right,BinaryFan.mk_snd,eq_self_iff_true,IsLimit.fac] · intro s m e₁ e₂ -- Porting note: simpa timed out here also apply BinaryFan.IsLimit.hom_ext h · simpa only [BinaryFan.π_app_left,BinaryFan.mk_fst,Category.assoc,IsLimit.fac,IsIso.eq_comp_inv] · simpa only [BinaryFan.π_app_right,BinaryFan.mk_snd,IsLimit.fac]
Mathlib/CategoryTheory/Limits/Shapes/BinaryProducts.lean
407
420
/- 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, Mario Carneiro -/ import Mathlib.Algebra.GroupWithZero.Divisibility import Mathlib.Algebra.Ring.Rat import Mathlib.Algebra.Ring.Int.Parity import Mathlib.Data.PNat.Defs /-! # Further lemmas for the Rational Numbers -/ namespace Rat theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a := by rcases e : a /. b with ⟨n, d, h, c⟩ rw [Rat.mk'_eq_divInt, divInt_eq_iff b0 (mod_cast h)] at e refine Int.natAbs_dvd.1 <| Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.dvd_of_dvd_mul_right ?_ have := congr_arg Int.natAbs e simp only [Int.natAbs_mul, Int.natAbs_natCast] at this; simp [this] theorem den_dvd (a b : ℤ) : ((a /. b).den : ℤ) ∣ b := by by_cases b0 : b = 0; · simp [b0] rcases e : a /. b with ⟨n, d, h, c⟩ rw [mk'_eq_divInt, divInt_eq_iff b0 (ne_of_gt (Int.natCast_pos.2 (Nat.pos_of_ne_zero h)))] at e refine Int.dvd_natAbs.1 <| Int.natCast_dvd_natCast.2 <| c.symm.dvd_of_dvd_mul_left ?_ rw [← Int.natAbs_mul, ← Int.natCast_dvd_natCast, Int.dvd_natAbs, ← e]; simp theorem num_den_mk {q : ℚ} {n d : ℤ} (hd : d ≠ 0) (qdf : q = n /. d) : ∃ c : ℤ, n = c * q.num ∧ d = c * q.den := by obtain rfl | hn := eq_or_ne n 0 · simp [qdf] have : q.num * d = n * ↑q.den := by refine (divInt_eq_iff ?_ hd).mp ?_ · exact Int.natCast_ne_zero.mpr (Rat.den_nz _)
· rwa [num_divInt_den] have hqdn : q.num ∣ n := by rw [qdf] exact Rat.num_dvd _ hd refine ⟨n / q.num, ?_, ?_⟩ · rw [Int.ediv_mul_cancel hqdn] · refine Int.eq_mul_div_of_mul_eq_mul_of_dvd_left ?_ hqdn this rw [qdf] exact Rat.num_ne_zero.2 ((divInt_ne_zero hd).mpr hn) theorem num_mk (n d : ℤ) : (n /. d).num = d.sign * n / n.gcd d := by have (m : ℕ) : Int.natAbs (m + 1) = m + 1 := by rw [← Nat.cast_one, ← Nat.cast_add, Int.natAbs_cast] rcases d with ((_ | _) | _) <;> rw [← Int.tdiv_eq_ediv_of_dvd] <;> simp [divInt, mkRat, Rat.normalize, Nat.succPNat, Int.sign, Int.gcd,
Mathlib/Data/Rat/Lemmas.lean
41
56
/- Copyright (c) 2023 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.CategoryTheory.Shift.Basic /-! # Functors which commute with shifts Let `C` and `D` be two categories equipped with shifts by an additive monoid `A`. In this file, we define the notion of functor `F : C ⥤ D` which "commutes" with these shifts. The associated type class is `[F.CommShift A]`. The data consists of commutation isomorphisms `F.commShiftIso a : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` for all `a : A` which satisfy a compatibility with the addition and the zero. After this was formalised in Lean, it was found that this definition is exactly the definition which appears in Jean-Louis Verdier's thesis (I 1.2.3/1.2.4), although the language is different. (In Verdier's thesis, the shift is not given by a monoidal functor `Discrete A ⥤ C ⥤ C`, but by a fibred category `C ⥤ BA`, where `BA` is the category with one object, the endomorphisms of which identify to `A`. The choice of a cleavage for this fibered category gives the individual shift functors.) ## References * [Jean-Louis Verdier, *Des catégories dérivées des catégories abéliennes*][verdier1996] -/ namespace CategoryTheory open Category namespace Functor variable {C D E : Type*} [Category C] [Category D] [Category E] (F : C ⥤ D) (G : D ⥤ E) (A B : Type*) [AddMonoid A] [AddCommMonoid B] [HasShift C A] [HasShift D A] [HasShift E A] [HasShift C B] [HasShift D B] namespace CommShift /-- For any functor `F : C ⥤ D`, this is the obvious isomorphism `shiftFunctor C (0 : A) ⋙ F ≅ F ⋙ shiftFunctor D (0 : A)` deduced from the isomorphisms `shiftFunctorZero` on both categories `C` and `D`. -/ @[simps!] noncomputable def isoZero : shiftFunctor C (0 : A) ⋙ F ≅ F ⋙ shiftFunctor D (0 : A) := isoWhiskerRight (shiftFunctorZero C A) F ≪≫ F.leftUnitor ≪≫ F.rightUnitor.symm ≪≫ isoWhiskerLeft F (shiftFunctorZero D A).symm /-- For any functor `F : C ⥤ D` and any `a` in `A` such that `a = 0`, this is the obvious isomorphism `shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a` deduced from the isomorphisms `shiftFunctorZero'` on both categories `C` and `D`. -/ @[simps!] noncomputable def isoZero' (a : A) (ha : a = 0) : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a := isoWhiskerRight (shiftFunctorZero' C a ha) F ≪≫ F.leftUnitor ≪≫ F.rightUnitor.symm ≪≫ isoWhiskerLeft F (shiftFunctorZero' D a ha).symm @[simp] lemma isoZero'_eq_isoZero : isoZero' F A 0 rfl = isoZero F A := by ext; simp [isoZero', shiftFunctorZero'] variable {F A} /-- If a functor `F : C ⥤ D` is equipped with "commutation isomorphisms" with the shifts by `a` and `b`, then there is a commutation isomorphism with the shift by `c` when `a + b = c`. -/ @[simps!] noncomputable def isoAdd' {a b c : A} (h : a + b = c) (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) : shiftFunctor C c ⋙ F ≅ F ⋙ shiftFunctor D c := isoWhiskerRight (shiftFunctorAdd' C _ _ _ h) F ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ e₂ ≪≫ (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight e₁ _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (shiftFunctorAdd' D _ _ _ h).symm /-- If a functor `F : C ⥤ D` is equipped with "commutation isomorphisms" with the shifts by `a` and `b`, then there is a commutation isomorphism with the shift by `a + b`. -/ noncomputable def isoAdd {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) : shiftFunctor C (a + b) ⋙ F ≅ F ⋙ shiftFunctor D (a + b) := CommShift.isoAdd' rfl e₁ e₂ @[simp] lemma isoAdd_hom_app {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) (X : C) : (CommShift.isoAdd e₁ e₂).hom.app X = F.map ((shiftFunctorAdd C a b).hom.app X) ≫ e₂.hom.app ((shiftFunctor C a).obj X) ≫ (shiftFunctor D b).map (e₁.hom.app X) ≫ (shiftFunctorAdd D a b).inv.app (F.obj X) := by simp only [isoAdd, isoAdd'_hom_app, shiftFunctorAdd'_eq_shiftFunctorAdd] @[simp] lemma isoAdd_inv_app {a b : A} (e₁ : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a) (e₂ : shiftFunctor C b ⋙ F ≅ F ⋙ shiftFunctor D b) (X : C) : (CommShift.isoAdd e₁ e₂).inv.app X = (shiftFunctorAdd D a b).hom.app (F.obj X) ≫ (shiftFunctor D b).map (e₁.inv.app X) ≫ e₂.inv.app ((shiftFunctor C a).obj X) ≫ F.map ((shiftFunctorAdd C a b).inv.app X) := by simp only [isoAdd, isoAdd'_inv_app, shiftFunctorAdd'_eq_shiftFunctorAdd] end CommShift /-- A functor `F` commutes with the shift by a monoid `A` if it is equipped with commutation isomorphisms with the shifts by all `a : A`, and these isomorphisms satisfy coherence properties with respect to `0 : A` and the addition in `A`. -/ class CommShift where /-- The commutation isomorphisms for all `a`-shifts this functor is equipped with -/ iso (a : A) : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a zero : iso 0 = CommShift.isoZero F A := by aesop_cat add (a b : A) : iso (a + b) = CommShift.isoAdd (iso a) (iso b) := by aesop_cat variable {A} section variable [F.CommShift A] /-- If a functor `F` commutes with the shift by `A` (i.e. `[F.CommShift A]`), then `F.commShiftIso a` is the given isomorphism `shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a`. -/ def commShiftIso (a : A) : shiftFunctor C a ⋙ F ≅ F ⋙ shiftFunctor D a := CommShift.iso a -- Note: The following two lemmas are introduced in order to have more proofs work `by simp`. -- Indeed, `simp only [(F.commShiftIso a).hom.naturality f]` would almost never work because -- of the compositions of functors which appear in both the source and target of -- `F.commShiftIso a`. Otherwise, we would be forced to use `erw [NatTrans.naturality]`. @[reassoc (attr := simp)] lemma commShiftIso_hom_naturality {X Y : C} (f : X ⟶ Y) (a : A) : F.map (f⟦a⟧') ≫ (F.commShiftIso a).hom.app Y = (F.commShiftIso a).hom.app X ≫ (F.map f)⟦a⟧' := (F.commShiftIso a).hom.naturality f @[reassoc (attr := simp)] lemma commShiftIso_inv_naturality {X Y : C} (f : X ⟶ Y) (a : A) : (F.map f)⟦a⟧' ≫ (F.commShiftIso a).inv.app Y = (F.commShiftIso a).inv.app X ≫ F.map (f⟦a⟧') := (F.commShiftIso a).inv.naturality f variable (A) lemma commShiftIso_zero : F.commShiftIso (0 : A) = CommShift.isoZero F A := CommShift.zero set_option linter.docPrime false in lemma commShiftIso_zero' (a : A) (h : a = 0) : F.commShiftIso a = CommShift.isoZero' F A a h := by subst h; rw [CommShift.isoZero'_eq_isoZero, commShiftIso_zero] variable {A} lemma commShiftIso_add (a b : A) : F.commShiftIso (a + b) = CommShift.isoAdd (F.commShiftIso a) (F.commShiftIso b) := CommShift.add a b lemma commShiftIso_add' {a b c : A} (h : a + b = c) : F.commShiftIso c = CommShift.isoAdd' h (F.commShiftIso a) (F.commShiftIso b) := by subst h simp only [commShiftIso_add, CommShift.isoAdd] end namespace CommShift variable (C) in instance id : CommShift (𝟭 C) A where iso := fun _ => rightUnitor _ ≪≫ (leftUnitor _).symm instance comp [F.CommShift A] [G.CommShift A] : (F ⋙ G).CommShift A where iso a := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (F.commShiftIso a) _ ≪≫ Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (G.commShiftIso a) ≪≫ (Functor.associator _ _ _).symm zero := by ext X dsimp simp only [id_comp, comp_id, commShiftIso_zero, isoZero_hom_app, ← Functor.map_comp_assoc, assoc, Iso.inv_hom_id_app, id_obj, comp_map, comp_obj] add := fun a b => by ext X dsimp simp only [commShiftIso_add, isoAdd_hom_app] dsimp simp only [comp_id, id_comp, assoc, ← Functor.map_comp_assoc, Iso.inv_hom_id_app, comp_obj] simp only [map_comp, assoc, commShiftIso_hom_naturality_assoc] end CommShift @[simp] lemma commShiftIso_id_hom_app (a : A) (X : C) : (commShiftIso (𝟭 C) a).hom.app X = 𝟙 _ := comp_id _ @[simp] lemma commShiftIso_id_inv_app (a : A) (X : C) : (commShiftIso (𝟭 C) a).inv.app X = 𝟙 _ := comp_id _ lemma commShiftIso_comp_hom_app [F.CommShift A] [G.CommShift A] (a : A) (X : C) : (commShiftIso (F ⋙ G) a).hom.app X = G.map ((commShiftIso F a).hom.app X) ≫ (commShiftIso G a).hom.app (F.obj X) := by simp [commShiftIso, CommShift.iso] lemma commShiftIso_comp_inv_app [F.CommShift A] [G.CommShift A] (a : A) (X : C) : (commShiftIso (F ⋙ G) a).inv.app X = (commShiftIso G a).inv.app (F.obj X) ≫ G.map ((commShiftIso F a).inv.app X) := by simp [commShiftIso, CommShift.iso] variable {B} lemma map_shiftFunctorComm_hom_app [F.CommShift B] (X : C) (a b : B) : F.map ((shiftFunctorComm C a b).hom.app X) = (F.commShiftIso b).hom.app (X⟦a⟧) ≫ ((F.commShiftIso a).hom.app X)⟦b⟧' ≫ (shiftFunctorComm D a b).hom.app (F.obj X) ≫ ((F.commShiftIso b).inv.app X)⟦a⟧' ≫ (F.commShiftIso a).inv.app (X⟦b⟧) := by have eq := NatTrans.congr_app (congr_arg Iso.hom (F.commShiftIso_add a b)) X simp only [comp_obj, CommShift.isoAdd_hom_app, ← cancel_epi (F.map ((shiftFunctorAdd C a b).inv.app X)), Category.assoc, ← F.map_comp_assoc, Iso.inv_hom_id_app, F.map_id, Category.id_comp, F.map_comp] at eq simp only [shiftFunctorComm_eq D a b _ rfl] dsimp simp only [Functor.map_comp, shiftFunctorAdd'_eq_shiftFunctorAdd, Category.assoc, ← reassoc_of% eq, shiftFunctorComm_eq C a b _ rfl] dsimp rw [Functor.map_comp] simp only [NatTrans.congr_app (congr_arg Iso.hom (F.commShiftIso_add' (add_comm b a))) X, CommShift.isoAdd'_hom_app, Category.assoc, Iso.inv_hom_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, Category.id_comp, comp_obj, Category.comp_id] @[simp, reassoc] lemma map_shiftFunctorCompIsoId_hom_app [F.CommShift A] (X : C) (a b : A) (h : a + b = 0) : F.map ((shiftFunctorCompIsoId C a b h).hom.app X) = (F.commShiftIso b).hom.app (X⟦a⟧) ≫ ((F.commShiftIso a).hom.app X)⟦b⟧' ≫ (shiftFunctorCompIsoId D a b h).hom.app (F.obj X) := by dsimp [shiftFunctorCompIsoId] have eq := NatTrans.congr_app (congr_arg Iso.hom (F.commShiftIso_add' h)) X simp only [commShiftIso_zero, comp_obj, CommShift.isoZero_hom_app, CommShift.isoAdd'_hom_app] at eq rw [← cancel_epi (F.map ((shiftFunctorAdd' C a b 0 h).hom.app X)), ← reassoc_of% eq, F.map_comp] simp only [Iso.inv_hom_id_app, id_obj, Category.comp_id, ← F.map_comp_assoc, Iso.hom_inv_id_app, F.map_id, Category.id_comp] @[simp, reassoc] lemma map_shiftFunctorCompIsoId_inv_app [F.CommShift A] (X : C) (a b : A) (h : a + b = 0) : F.map ((shiftFunctorCompIsoId C a b h).inv.app X) = (shiftFunctorCompIsoId D a b h).inv.app (F.obj X) ≫ ((F.commShiftIso a).inv.app X)⟦b⟧' ≫ (F.commShiftIso b).inv.app (X⟦a⟧) := by rw [← cancel_epi (F.map ((shiftFunctorCompIsoId C a b h).hom.app X)), ← F.map_comp, Iso.hom_inv_id_app, F.map_id, map_shiftFunctorCompIsoId_hom_app] simp only [comp_obj, id_obj, Category.assoc, Iso.hom_inv_id_app_assoc, ← Functor.map_comp_assoc, Iso.hom_inv_id_app, Functor.map_id, Category.id_comp] end Functor namespace NatTrans variable {C D E J : Type*} [Category C] [Category D] [Category E] [Category J] {F₁ F₂ F₃ : C ⥤ D} (τ : F₁ ⟶ F₂) (τ' : F₂ ⟶ F₃) (e : F₁ ≅ F₂) (G G' : D ⥤ E) (τ'' : G ⟶ G') (H : E ⥤ J) (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] [HasShift E A] [HasShift J A] [F₁.CommShift A] [F₂.CommShift A] [F₃.CommShift A] [G.CommShift A] [G'.CommShift A] [H.CommShift A] /-- If `τ : F₁ ⟶ F₂` is a natural transformation between two functors which commute with a shift by an additive monoid `A`, this typeclass asserts a compatibility of `τ` with these shifts. -/ class CommShift : Prop where shift_comm (a : A) : (F₁.commShiftIso a).hom ≫ whiskerRight τ _ = whiskerLeft _ τ ≫ (F₂.commShiftIso a).hom := by aesop_cat section variable {A} [NatTrans.CommShift τ A] @[reassoc] lemma shift_comm (a : A) : (F₁.commShiftIso a).hom ≫ whiskerRight τ _ = whiskerLeft _ τ ≫ (F₂.commShiftIso a).hom := by apply CommShift.shift_comm @[reassoc] lemma shift_app_comm (a : A) (X : C) : (F₁.commShiftIso a).hom.app X ≫ (τ.app X)⟦a⟧' = τ.app (X⟦a⟧) ≫ (F₂.commShiftIso a).hom.app X := congr_app (shift_comm τ a) X @[reassoc] lemma shift_app (a : A) (X : C) : (τ.app X)⟦a⟧' = (F₁.commShiftIso a).inv.app X ≫ τ.app (X⟦a⟧) ≫ (F₂.commShiftIso a).hom.app X := by rw [← shift_app_comm, Iso.inv_hom_id_app_assoc] @[reassoc] lemma app_shift (a : A) (X : C) : τ.app (X⟦a⟧) = (F₁.commShiftIso a).hom.app X ≫ (τ.app X)⟦a⟧' ≫ (F₂.commShiftIso a).inv.app X := by simp [shift_app_comm_assoc τ a X] @[deprecated (since := "2024-12-31")] alias CommShift.comm' := shift_comm @[deprecated (since := "2024-12-31")] alias CommShift.comm := shift_comm @[deprecated (since := "2024-12-31")] alias CommShift.comm_app := shift_app_comm @[deprecated (since := "2024-12-31")] alias CommShift.shift_app := shift_app @[deprecated (since := "2024-12-31")] alias CommShift.app_shift := app_shift end namespace CommShift instance of_iso_inv [NatTrans.CommShift e.hom A] : NatTrans.CommShift e.inv A := ⟨fun a => by ext X dsimp rw [← cancel_epi (e.hom.app (X⟦a⟧)), e.hom_inv_id_app_assoc, ← shift_app_comm_assoc, ← Functor.map_comp, e.hom_inv_id_app, Functor.map_id, Category.comp_id]⟩ lemma of_isIso [IsIso τ] [NatTrans.CommShift τ A] : NatTrans.CommShift (inv τ) A := by haveI : NatTrans.CommShift (asIso τ).hom A := by assumption change NatTrans.CommShift (asIso τ).inv A infer_instance variable (F₁) in instance id : NatTrans.CommShift (𝟙 F₁) A where attribute [local simp] Functor.commShiftIso_comp_hom_app shift_app_comm shift_app_comm_assoc instance comp [NatTrans.CommShift τ A] [NatTrans.CommShift τ' A] : NatTrans.CommShift (τ ≫ τ') A where instance whiskerRight [NatTrans.CommShift τ A] : NatTrans.CommShift (whiskerRight τ G) A := ⟨fun a => by ext X simp only [whiskerRight_twice, Functor.associator_hom_app, Functor.associator_inv_app, id_comp, comp_id, comp_app, whiskerRight_app, Functor.comp_map, whiskerLeft_app, Functor.commShiftIso_comp_hom_app, Category.assoc, ← Functor.commShiftIso_hom_naturality, ← G.map_comp_assoc, shift_app_comm]⟩ instance whiskerLeft [NatTrans.CommShift τ'' A] : NatTrans.CommShift (whiskerLeft F₁ τ'') A where instance associator : CommShift (Functor.associator F₁ G H).hom A where instance leftUnitor : CommShift F₁.leftUnitor.hom A where instance rightUnitor : CommShift F₁.rightUnitor.hom A where end CommShift end NatTrans namespace Functor namespace CommShift variable {C D E : Type*} [Category C] [Category D] {F : C ⥤ D} {G : C ⥤ D} (e : F ≅ G) (A : Type*) [AddMonoid A] [HasShift C A] [HasShift D A] [F.CommShift A] /-- If `e : F ≅ G` is an isomorphism of functors and if `F` commutes with the shift, then `G` also commutes with the shift. -/ def ofIso : G.CommShift A where iso a := isoWhiskerLeft _ e.symm ≪≫ F.commShiftIso a ≪≫ isoWhiskerRight e _ zero := by ext X
simp only [comp_obj, F.commShiftIso_zero A, Iso.trans_hom, isoWhiskerLeft_hom, Iso.symm_hom, isoWhiskerRight_hom, NatTrans.comp_app, whiskerLeft_app, isoZero_hom_app, whiskerRight_app, assoc] erw [← e.inv.naturality_assoc, ← NatTrans.naturality, e.inv_hom_id_app_assoc] add a b := by ext X
Mathlib/CategoryTheory/Shift/CommShift.lean
368
374
/- Copyright (c) 2023 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import Mathlib.LinearAlgebra.FreeModule.Finite.Basic import Mathlib.LinearAlgebra.FreeModule.PID import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.LinearAlgebra.Trace /-! # Linear maps between direct sums This file contains results about linear maps which respect direct sum decompositions of their domain and codomain. -/ open Set DirectSum namespace LinearMap variable {ι R M : Type*} [CommRing R] [AddCommGroup M] [Module R M] {N : ι → Submodule R M} section IsInternal variable [DecidableEq ι] /-- If a linear map `f : M₁ → M₂` respects direct sum decompositions of `M₁` and `M₂`, then it has a block diagonal matrix with respect to bases compatible with the direct sum decompositions. -/ lemma toMatrix_directSum_collectedBasis_eq_blockDiagonal' {R M₁ M₂ : Type*} [CommSemiring R] [AddCommMonoid M₁] [Module R M₁] {N₁ : ι → Submodule R M₁} (h₁ : IsInternal N₁) [AddCommMonoid M₂] [Module R M₂] {N₂ : ι → Submodule R M₂} (h₂ : IsInternal N₂) {κ₁ κ₂ : ι → Type*} [∀ i, Fintype (κ₁ i)] [∀ i, Finite (κ₂ i)] [∀ i, DecidableEq (κ₁ i)] [Fintype ι] (b₁ : (i : ι) → Basis (κ₁ i) R (N₁ i)) (b₂ : (i : ι) → Basis (κ₂ i) R (N₂ i)) {f : M₁ →ₗ[R] M₂} (hf : ∀ i, MapsTo f (N₁ i) (N₂ i)) : toMatrix (h₁.collectedBasis b₁) (h₂.collectedBasis b₂) f = Matrix.blockDiagonal' fun i ↦ toMatrix (b₁ i) (b₂ i) (f.restrict (hf i)) := by ext ⟨i, _⟩ ⟨j, _⟩ simp only [toMatrix_apply, Matrix.blockDiagonal'_apply] rcases eq_or_ne i j with rfl | hij · simp [h₂.collectedBasis_repr_of_mem _ (hf _ (Subtype.mem _)), restrict_apply] · simp [hij, h₂.collectedBasis_repr_of_mem_ne _ hij.symm (hf _ (Subtype.mem _))] lemma diag_toMatrix_directSum_collectedBasis_eq_zero_of_mapsTo_ne {κ : ι → Type*} [∀ i, Fintype (κ i)] [∀ i, DecidableEq (κ i)] {s : Finset ι} (h : IsInternal fun i : s ↦ N i) (b : (i : s) → Basis (κ i) R (N i)) (σ : ι → ι) (hσ : ∀ i, σ i ≠ i) {f : Module.End R M} (hf : ∀ i, MapsTo f (N i) (N <| σ i)) (hN : ∀ i, i ∉ s → N i = ⊥) : Matrix.diag (toMatrix (h.collectedBasis b) (h.collectedBasis b) f) = 0 := by ext ⟨i, k⟩ simp only [Matrix.diag_apply, Pi.zero_apply, toMatrix_apply, IsInternal.collectedBasis_coe] by_cases hi : σ i ∈ s · let j : s := ⟨σ i, hi⟩ replace hσ : j ≠ i := fun hij ↦ hσ i <| Subtype.ext_iff.mp hij exact h.collectedBasis_repr_of_mem_ne b hσ <| hf _ <| Subtype.mem (b i k) · suffices f (b i k) = 0 by simp [this] simpa [hN _ hi] using hf i <| Subtype.mem (b i k) variable [∀ i, Module.Finite R (N i)] [∀ i, Module.Free R (N i)]
/-- The trace of an endomorphism of a direct sum is the sum of the traces on each component. See also `LinearMap.trace_restrict_eq_sum_trace_restrict`. -/ lemma trace_eq_sum_trace_restrict (h : IsInternal N) [Fintype ι] {f : M →ₗ[R] M} (hf : ∀ i, MapsTo f (N i) (N i)) : trace R M f = ∑ i, trace R (N i) (f.restrict (hf i)) := by let b : (i : ι) → Basis _ R (N i) := fun i ↦ Module.Free.chooseBasis R (N i) simp_rw [trace_eq_matrix_trace R (h.collectedBasis b), toMatrix_directSum_collectedBasis_eq_blockDiagonal' h h b b hf, Matrix.trace_blockDiagonal', ← trace_eq_matrix_trace]
Mathlib/Algebra/DirectSum/LinearMap.lean
62
71
/- 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.Topology.MetricSpace.HausdorffDistance /-! # Topological study of spaces `Π (n : ℕ), E n` When `E n` are topological spaces, the space `Π (n : ℕ), E n` is naturally a topological space (with the product topology). When `E n` are uniform spaces, it also inherits a uniform structure. However, it does not inherit a canonical metric space structure of the `E n`. Nevertheless, one can put a noncanonical metric space structure (or rather, several of them). This is done in this file. ## Main definitions and results One can define a combinatorial distance on `Π (n : ℕ), E n`, as follows: * `PiNat.cylinder x n` is the set of points `y` with `x i = y i` for `i < n`. * `PiNat.firstDiff x y` is the first index at which `x i ≠ y i`. * `PiNat.dist x y` is equal to `(1/2) ^ (firstDiff x y)`. It defines a distance on `Π (n : ℕ), E n`, compatible with the topology when the `E n` have the discrete topology. * `PiNat.metricSpace`: the metric space structure, given by this distance. Not registered as an instance. This space is a complete metric space. * `PiNat.metricSpaceOfDiscreteUniformity`: the same metric space structure, but adjusting the uniformity defeqness when the `E n` already have the discrete uniformity. Not registered as an instance * `PiNat.metricSpaceNatNat`: the particular case of `ℕ → ℕ`, not registered as an instance. These results are used to construct continuous functions on `Π n, E n`: * `PiNat.exists_retraction_of_isClosed`: given a nonempty closed subset `s` of `Π (n : ℕ), E n`, there exists a retraction onto `s`, i.e., a continuous map from the whole space to `s` restricting to the identity on `s`. * `exists_nat_nat_continuous_surjective_of_completeSpace`: given any nonempty complete metric space with second-countable topology, there exists a continuous surjection from `ℕ → ℕ` onto this space. One can also put distances on `Π (i : ι), E i` when the spaces `E i` are metric spaces (not discrete in general), and `ι` is countable. * `PiCountable.dist` is the distance on `Π i, E i` given by `dist x y = ∑' i, min (1/2)^(encode i) (dist (x i) (y i))`. * `PiCountable.metricSpace` is the corresponding metric space structure, adjusted so that the uniformity is definitionally the product uniformity. Not registered as an instance. -/ noncomputable section open Topology TopologicalSpace Set Metric Filter Function attribute [local simp] pow_le_pow_iff_right₀ one_lt_two inv_le_inv₀ zero_le_two zero_lt_two variable {E : ℕ → Type*} namespace PiNat /-! ### The firstDiff function -/ open Classical in /-- In a product space `Π n, E n`, then `firstDiff x y` is the first index at which `x` and `y` differ. If `x = y`, then by convention we set `firstDiff x x = 0`. -/ irreducible_def firstDiff (x y : ∀ n, E n) : ℕ := if h : x ≠ y then Nat.find (ne_iff.1 h) else 0 theorem apply_firstDiff_ne {x y : ∀ n, E n} (h : x ≠ y) : x (firstDiff x y) ≠ y (firstDiff x y) := by rw [firstDiff_def, dif_pos h] classical exact Nat.find_spec (ne_iff.1 h) theorem apply_eq_of_lt_firstDiff {x y : ∀ n, E n} {n : ℕ} (hn : n < firstDiff x y) : x n = y n := by rw [firstDiff_def] at hn split_ifs at hn with h · convert Nat.find_min (ne_iff.1 h) hn simp · exact (not_lt_zero' hn).elim theorem firstDiff_comm (x y : ∀ n, E n) : firstDiff x y = firstDiff y x := by classical simp only [firstDiff_def, ne_comm] theorem min_firstDiff_le (x y z : ∀ n, E n) (h : x ≠ z) : min (firstDiff x y) (firstDiff y z) ≤ firstDiff x z := by by_contra! H rw [lt_min_iff] at H refine apply_firstDiff_ne h ?_ calc x (firstDiff x z) = y (firstDiff x z) := apply_eq_of_lt_firstDiff H.1 _ = z (firstDiff x z) := apply_eq_of_lt_firstDiff H.2 /-! ### Cylinders -/ /-- In a product space `Π n, E n`, the cylinder set of length `n` around `x`, denoted `cylinder x n`, is the set of sequences `y` that coincide with `x` on the first `n` symbols, i.e., such that `y i = x i` for all `i < n`. -/ def cylinder (x : ∀ n, E n) (n : ℕ) : Set (∀ n, E n) := { y | ∀ i, i < n → y i = x i } theorem cylinder_eq_pi (x : ∀ n, E n) (n : ℕ) : cylinder x n = Set.pi (Finset.range n : Set ℕ) fun i : ℕ => {x i} := by ext y simp [cylinder] @[simp] theorem cylinder_zero (x : ∀ n, E n) : cylinder x 0 = univ := by simp [cylinder_eq_pi] theorem cylinder_anti (x : ∀ n, E n) {m n : ℕ} (h : m ≤ n) : cylinder x n ⊆ cylinder x m := fun _y hy i hi => hy i (hi.trans_le h) @[simp] theorem mem_cylinder_iff {x y : ∀ n, E n} {n : ℕ} : y ∈ cylinder x n ↔ ∀ i < n, y i = x i := Iff.rfl theorem self_mem_cylinder (x : ∀ n, E n) (n : ℕ) : x ∈ cylinder x n := by simp
Mathlib/Topology/MetricSpace/PiNat.lean
119
119
/- 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
Mathlib/Data/Set/Card.lean
479
480
/- 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 theorem sZMod_eq_s (p' : ℕ) (i : ℕ) : sZMod (p' + 2) i = (s i : ZMod (2 ^ (p' + 2) - 1)) := by induction i with | zero => dsimp [s, sZMod]; norm_num | succ i ih => push_cast [s, sZMod, ih]; rfl -- These next two don't make good `norm_cast` lemmas. theorem Int.natCast_pow_pred (b p : ℕ) (w : 0 < b) : ((b ^ p - 1 : ℕ) : ℤ) = (b : ℤ) ^ p - 1 := by have : 1 ≤ b ^ p := Nat.one_le_pow p b w norm_cast theorem Int.coe_nat_two_pow_pred (p : ℕ) : ((2 ^ p - 1 : ℕ) : ℤ) = (2 ^ p - 1 : ℤ) := Int.natCast_pow_pred 2 p (by decide) theorem sZMod_eq_sMod (p : ℕ) (i : ℕ) : sZMod p i = (sMod p i : ZMod (2 ^ p - 1)) := by induction i <;> push_cast [← Int.coe_nat_two_pow_pred p, sMod, sZMod, *] <;> rfl /-- The Lucas-Lehmer residue is `s p (p-2)` in `ZMod (2^p - 1)`. -/ def lucasLehmerResidue (p : ℕ) : ZMod (2 ^ p - 1) := sZMod p (p - 2) theorem residue_eq_zero_iff_sMod_eq_zero (p : ℕ) (w : 1 < p) : lucasLehmerResidue p = 0 ↔ sMod p (p - 2) = 0 := by dsimp [lucasLehmerResidue] rw [sZMod_eq_sMod p] constructor · -- We want to use that fact that `0 ≤ s_mod p (p-2) < 2^p - 1` -- and `lucas_lehmer_residue p = 0 → 2^p - 1 ∣ s_mod p (p-2)`. intro h simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says simp only [ZMod.intCast_zmod_eq_zero_iff_dvd, ofNat_pos, pow_pos, cast_pred, cast_pow, cast_ofNat] at h apply Int.eq_zero_of_dvd_of_nonneg_of_lt _ _ h <;> clear h · exact sMod_nonneg _ (by positivity) _ · exact sMod_lt _ (by positivity) _ · intro h rw [h] simp /-- **Lucas-Lehmer Test**: a Mersenne number `2^p-1` is prime if and only if the Lucas-Lehmer residue `s p (p-2) % (2^p - 1)` is zero. -/ def LucasLehmerTest (p : ℕ) : Prop := lucasLehmerResidue p = 0 /-- `q` is defined as the minimum factor of `mersenne p`, bundled as an `ℕ+`. -/ def q (p : ℕ) : ℕ+ := ⟨Nat.minFac (mersenne p), Nat.minFac_pos (mersenne p)⟩ -- It would be nice to define this as (ℤ/qℤ)[x] / (x^2 - 3), -- obtaining the ring structure for free, -- but that seems to be more trouble than it's worth; -- if it were easy to make the definition, -- cardinality calculations would be somewhat more involved, too. /-- We construct the ring `X q` as ℤ/qℤ + √3 ℤ/qℤ. -/ def X (q : ℕ+) : Type := ZMod q × ZMod q namespace X variable {q : ℕ+} instance : Inhabited (X q) := inferInstanceAs (Inhabited (ZMod q × ZMod q)) instance : Fintype (X q) := inferInstanceAs (Fintype (ZMod q × ZMod q)) instance : DecidableEq (X q) := inferInstanceAs (DecidableEq (ZMod q × ZMod q)) instance : AddCommGroup (X q) := inferInstanceAs (AddCommGroup (ZMod q × ZMod q)) @[ext] theorem ext {x y : X q} (h₁ : x.1 = y.1) (h₂ : x.2 = y.2) : x = y := by cases x; cases y; congr @[simp] theorem zero_fst : (0 : X q).1 = 0 := rfl @[simp] theorem zero_snd : (0 : X q).2 = 0 := rfl @[simp] theorem add_fst (x y : X q) : (x + y).1 = x.1 + y.1 := rfl @[simp] theorem add_snd (x y : X q) : (x + y).2 = x.2 + y.2 := rfl @[simp] theorem neg_fst (x : X q) : (-x).1 = -x.1 := rfl @[simp] theorem neg_snd (x : X q) : (-x).2 = -x.2 := rfl instance : Mul (X q) where mul x y := (x.1 * y.1 + 3 * x.2 * y.2, x.1 * y.2 + x.2 * y.1) @[simp] theorem mul_fst (x y : X q) : (x * y).1 = x.1 * y.1 + 3 * x.2 * y.2 := rfl @[simp] theorem mul_snd (x y : X q) : (x * y).2 = x.1 * y.2 + x.2 * y.1 := rfl instance : One (X q) where one := ⟨1, 0⟩ @[simp] theorem one_fst : (1 : X q).1 = 1 := rfl @[simp] theorem one_snd : (1 : X q).2 = 0 := rfl instance : Monoid (X q) := { inferInstanceAs (Mul (X q)), inferInstanceAs (One (X q)) with mul_assoc := fun x y z => by ext <;> dsimp <;> ring one_mul := fun x => by ext <;> simp mul_one := fun x => by ext <;> simp } instance : NatCast (X q) where natCast := fun n => ⟨n, 0⟩ @[simp] theorem fst_natCast (n : ℕ) : (n : X q).fst = (n : ZMod q) := rfl @[simp] theorem snd_natCast (n : ℕ) : (n : X q).snd = (0 : ZMod q) := rfl @[simp] theorem ofNat_fst (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : X q).fst = OfNat.ofNat n := rfl @[simp] theorem ofNat_snd (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : X q).snd = 0 := rfl instance : AddGroupWithOne (X q) := { inferInstanceAs (Monoid (X q)), inferInstanceAs (AddCommGroup (X q)), inferInstanceAs (NatCast (X q)) with natCast_zero := by ext <;> simp natCast_succ := fun _ ↦ by ext <;> simp intCast := fun n => ⟨n, 0⟩ intCast_ofNat := fun n => by ext <;> simp intCast_negSucc := fun n => by ext <;> simp } theorem left_distrib (x y z : X q) : x * (y + z) = x * y + x * z := by ext <;> dsimp <;> ring theorem right_distrib (x y z : X q) : (x + y) * z = x * z + y * z := by ext <;> dsimp <;> ring instance : Ring (X q) := { inferInstanceAs (AddGroupWithOne (X q)), inferInstanceAs (AddCommGroup (X q)), inferInstanceAs (Monoid (X q)) with left_distrib := left_distrib right_distrib := right_distrib mul_zero := fun _ ↦ by ext <;> simp zero_mul := fun _ ↦ by ext <;> simp } instance : CommRing (X q) := { inferInstanceAs (Ring (X q)) with mul_comm := fun _ _ ↦ by ext <;> dsimp <;> ring } instance [Fact (1 < (q : ℕ))] : Nontrivial (X q) := ⟨⟨0, 1, ne_of_apply_ne Prod.fst zero_ne_one⟩⟩ @[simp] theorem fst_intCast (n : ℤ) : (n : X q).fst = (n : ZMod q) := rfl @[simp] theorem snd_intCast (n : ℤ) : (n : X q).snd = (0 : ZMod q) := rfl @[norm_cast] theorem coe_mul (n m : ℤ) : ((n * m : ℤ) : X q) = (n : X q) * (m : X q) := by ext <;> simp @[norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ) : X q) = (n : X q) := by ext <;> simp /-- The cardinality of `X` is `q^2`. -/ theorem card_eq : Fintype.card (X q) = q ^ 2 := by dsimp [X] rw [Fintype.card_prod, ZMod.card q, sq] /-- There are strictly fewer than `q^2` units, since `0` is not a unit. -/ nonrec theorem card_units_lt (w : 1 < q) : Fintype.card (X q)ˣ < q ^ 2 := by have : Fact (1 < (q : ℕ)) := ⟨w⟩ convert card_units_lt (X q) rw [card_eq] /-- We define `ω = 2 + √3`. -/ def ω : X q := (2, 1) /-- We define `ωb = 2 - √3`, which is the inverse of `ω`. -/ def ωb : X q := (2, -1) theorem ω_mul_ωb (q : ℕ+) : (ω : X q) * ωb = 1 := by dsimp [ω, ωb] ext <;> simp; ring theorem ωb_mul_ω (q : ℕ+) : (ωb : X q) * ω = 1 := by rw [mul_comm, ω_mul_ωb] /-- A closed form for the recurrence relation. -/ theorem closed_form (i : ℕ) : (s i : X q) = (ω : X q) ^ 2 ^ i + (ωb : X q) ^ 2 ^ i := by induction i with | zero => dsimp [s, ω, ωb] ext <;> norm_num | succ i ih => calc (s (i + 1) : X q) = (s i ^ 2 - 2 : ℤ) := rfl _ = (s i : X q) ^ 2 - 2 := by push_cast; rfl _ = (ω ^ 2 ^ i + ωb ^ 2 ^ i) ^ 2 - 2 := by rw [ih] _ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 + 2 * (ωb ^ 2 ^ i * ω ^ 2 ^ i) - 2 := by ring _ = (ω ^ 2 ^ i) ^ 2 + (ωb ^ 2 ^ i) ^ 2 := by rw [← mul_pow ωb ω, ωb_mul_ω, one_pow, mul_one, add_sub_cancel_right] _ = ω ^ 2 ^ (i + 1) + ωb ^ 2 ^ (i + 1) := by rw [← pow_mul, ← pow_mul, _root_.pow_succ] end X open X /-! Here and below, we introduce `p' = p - 2`, in order to avoid using subtraction in `ℕ`. -/ /-- If `1 < p`, then `q p`, the smallest prime factor of `mersenne p`, is more than 2. -/ theorem two_lt_q (p' : ℕ) : 2 < q (p' + 2) := by refine (minFac_prime (one_lt_mersenne.2 ?_).ne').two_le.lt_of_ne' ?_ · exact le_add_left _ _ · rw [Ne, minFac_eq_two_iff, mersenne, Nat.pow_succ'] exact Nat.two_not_dvd_two_mul_sub_one Nat.one_le_two_pow theorem ω_pow_formula (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : ∃ k : ℤ, (ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = k * mersenne (p' + 2) * (ω : X (q (p' + 2))) ^ 2 ^ p' - 1 := by dsimp [lucasLehmerResidue] at h rw [sZMod_eq_s p'] at h simp? [ZMod.intCast_zmod_eq_zero_iff_dvd] at h says simp only [add_tsub_cancel_right, ZMod.intCast_zmod_eq_zero_iff_dvd, ofNat_pos, pow_pos, cast_pred, cast_pow, cast_ofNat] at h obtain ⟨k, h⟩ := h use k replace h := congr_arg (fun n : ℤ => (n : X (q (p' + 2)))) h -- coercion from ℤ to X q dsimp at h rw [closed_form] at h replace h := congr_arg (fun x => ω ^ 2 ^ p' * x) h dsimp at h have t : 2 ^ p' + 2 ^ p' = 2 ^ (p' + 1) := by ring rw [mul_add, ← pow_add ω, t, ← mul_pow ω ωb (2 ^ p'), ω_mul_ωb, one_pow] at h rw [mul_comm, coe_mul] at h rw [mul_comm _ (k : X (q (p' + 2)))] at h replace h := eq_sub_of_add_eq h have : 1 ≤ 2 ^ (p' + 2) := Nat.one_le_pow _ _ (by decide) exact mod_cast h /-- `q` is the minimum factor of `mersenne p`, so `M p = 0` in `X q`. -/ theorem mersenne_coe_X (p : ℕ) : (mersenne p : X (q p)) = 0 := by ext <;> simp [mersenne, q, ZMod.natCast_zmod_eq_zero_iff_dvd, -pow_pos] apply Nat.minFac_dvd theorem ω_pow_eq_neg_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : (ω : X (q (p' + 2))) ^ 2 ^ (p' + 1) = -1 := by obtain ⟨k, w⟩ := ω_pow_formula p' h rw [mersenne_coe_X] at w simpa using w theorem ω_pow_eq_one (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : (ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = 1 := calc (ω : X (q (p' + 2))) ^ 2 ^ (p' + 2) = (ω ^ 2 ^ (p' + 1)) ^ 2 := by rw [← pow_mul, ← Nat.pow_succ] _ = (-1) ^ 2 := by rw [ω_pow_eq_neg_one p' h] _ = 1 := by simp /-- `ω` as an element of the group of units. -/ def ωUnit (p : ℕ) : Units (X (q p)) where val := ω inv := ωb val_inv := ω_mul_ωb _ inv_val := ωb_mul_ω _ @[simp] theorem ωUnit_coe (p : ℕ) : (ωUnit p : X (q p)) = ω := rfl /-- The order of `ω` in the unit group is exactly `2^p`. -/ theorem order_ω (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : orderOf (ωUnit (p' + 2)) = 2 ^ (p' + 2) := by apply Nat.eq_prime_pow_of_dvd_least_prime_pow -- the order of ω divides 2^p · exact Nat.prime_two · intro o have ω_pow := orderOf_dvd_iff_pow_eq_one.1 o replace ω_pow := congr_arg (Units.coeHom (X (q (p' + 2))) : Units (X (q (p' + 2))) → X (q (p' + 2))) ω_pow simp? at ω_pow says simp only [Units.coeHom_apply, Units.val_pow_eq_pow_val, ωUnit_coe, Units.val_one] at ω_pow have h : (1 : ZMod (q (p' + 2))) = -1 := congr_arg Prod.fst (ω_pow.symm.trans (ω_pow_eq_neg_one p' h)) haveI : Fact (2 < (q (p' + 2) : ℕ)) := ⟨two_lt_q _⟩ apply ZMod.neg_one_ne_one h.symm · apply orderOf_dvd_iff_pow_eq_one.2 apply Units.ext push_cast exact ω_pow_eq_one p' h theorem order_ineq (p' : ℕ) (h : lucasLehmerResidue (p' + 2) = 0) : 2 ^ (p' + 2) < (q (p' + 2) : ℕ) ^ 2 := calc 2 ^ (p' + 2) = orderOf (ωUnit (p' + 2)) := (order_ω p' h).symm _ ≤ Fintype.card (X (q (p' + 2)))ˣ := orderOf_le_card_univ _ < (q (p' + 2) : ℕ) ^ 2 := card_units_lt (Nat.lt_of_succ_lt (two_lt_q _)) end LucasLehmer export LucasLehmer (LucasLehmerTest lucasLehmerResidue) open LucasLehmer theorem lucas_lehmer_sufficiency (p : ℕ) (w : 1 < p) : LucasLehmerTest p → (mersenne p).Prime := by let p' := p - 2 have z : p = p' + 2 := (tsub_eq_iff_eq_add_of_le w.nat_succ_le).mp rfl have w : 1 < p' + 2 := Nat.lt_of_sub_eq_succ rfl contrapose intro a t rw [z] at a rw [z] at t have h₁ := order_ineq p' t have h₂ := Nat.minFac_sq_le_self (mersenne_pos.2 (Nat.lt_of_succ_lt w)) a have h := lt_of_lt_of_le h₁ h₂ exact not_lt_of_ge (Nat.sub_le _ _) h namespace LucasLehmer /-! ### `norm_num` extension Next we define a `norm_num` extension that calculates `LucasLehmerTest p` for `1 < p`. It makes use of a version of `sMod` that is specifically written to be reducible by the Lean 4 kernel, which has the capability of efficiently reducing natural number expressions. With this reduction in hand, it's a simple matter of applying the lemma `LucasLehmer.residue_eq_zero_iff_sMod_eq_zero`. See [Archive/Examples/MersennePrimes.lean] for certifications of all Mersenne primes up through `mersenne 4423`. -/ namespace norm_num_ext open Qq Lean Elab.Tactic Mathlib.Meta.NormNum /-- Version of `sMod` that is `ℕ`-valued. One should have `q = 2 ^ p - 1`. This can be reduced by the kernel. -/ def sModNat (q : ℕ) : ℕ → ℕ | 0 => 4 % q | i + 1 => (sModNat q i ^ 2 + (q - 2)) % q theorem sModNat_eq_sMod (p k : ℕ) (hp : 2 ≤ p) : (sModNat (2 ^ p - 1) k : ℤ) = sMod p k := by have h1 := calc 4 = 2 ^ 2 := by norm_num _ ≤ 2 ^ p := Nat.pow_le_pow_right (by norm_num) hp have h2 : 1 ≤ 2 ^ p := by omega induction k with | zero => rw [sModNat, sMod, Int.natCast_emod] simp [h2] | succ k ih => rw [sModNat, sMod, ← ih] have h3 : 2 ≤ 2 ^ p - 1 := by zify [h2] calc (2 : Int) ≤ 4 - 1 := by norm_num _ ≤ 2 ^ p - 1 := by zify at h1; exact Int.sub_le_sub_right h1 _ zify [h2, h3] rw [← add_sub_assoc, sub_eq_add_neg, add_assoc, add_comm _ (-2), ← add_assoc, Int.add_emod_right, ← sub_eq_add_neg] /-- Tail-recursive version of `sModNat`. -/ def sModNatTR (q : ℕ) (k : Nat) : ℕ := go k (4 % q) where /-- Helper function for `sMod''`. -/ go : ℕ → ℕ → ℕ | 0, acc => acc | n + 1, acc => go n ((acc ^ 2 + (q - 2)) % q) /-- Generalization of `sModNat` with arbitrary base case, useful for proving `sModNatTR` and `sModNat` agree. -/ def sModNat_aux (b : ℕ) (q : ℕ) : ℕ → ℕ | 0 => b | i + 1 => (sModNat_aux b q i ^ 2 + (q - 2)) % q theorem sModNat_aux_eq (q k : ℕ) : sModNat_aux (4 % q) q k = sModNat q k := by induction k with | zero => rfl | succ k ih => rw [sModNat_aux, ih, sModNat, ← ih] theorem sModNatTR_eq_sModNat (q : ℕ) (i : ℕ) : sModNatTR q i = sModNat q i := by rw [sModNatTR, helper, sModNat_aux_eq] where helper b q k : sModNatTR.go q k b = sModNat_aux b q k := by induction k generalizing b with | zero => rfl | succ k ih => rw [sModNatTR.go, ih, sModNat_aux] clear ih induction k with | zero => rfl | succ k ih => rw [sModNat_aux, ih, sModNat_aux] lemma testTrueHelper (p : ℕ) (hp : Nat.blt 1 p = true) (h : sModNatTR (2 ^ p - 1) (p - 2) = 0) : LucasLehmerTest p := by rw [Nat.blt_eq] at hp rw [LucasLehmerTest, LucasLehmer.residue_eq_zero_iff_sMod_eq_zero p hp, ← sModNat_eq_sMod p _ hp, ← sModNatTR_eq_sModNat, h] rfl lemma testFalseHelper (p : ℕ) (hp : Nat.blt 1 p = true) (h : Nat.ble 1 (sModNatTR (2 ^ p - 1) (p - 2))) : ¬ LucasLehmerTest p := by rw [Nat.blt_eq] at hp rw [Nat.ble_eq, Nat.succ_le, Nat.pos_iff_ne_zero] at h rw [LucasLehmerTest, LucasLehmer.residue_eq_zero_iff_sMod_eq_zero p hp, ← sModNat_eq_sMod p _ hp, ← sModNatTR_eq_sModNat] simpa using h theorem isNat_lucasLehmerTest : {p np : ℕ} → IsNat p np → LucasLehmerTest np → LucasLehmerTest p | _, _, ⟨rfl⟩, h => h theorem isNat_not_lucasLehmerTest : {p np : ℕ} → IsNat p np → ¬ LucasLehmerTest np → ¬ LucasLehmerTest p | _, _, ⟨rfl⟩, h => h /-- Calculate `LucasLehmer.LucasLehmerTest p` for `2 ≤ p` by using kernel reduction for the `sMod'` function. -/ @[norm_num LucasLehmer.LucasLehmerTest (_ : ℕ)] def evalLucasLehmerTest : NormNumExt where eval {_ _} e := do let .app _ (p : Q(ℕ)) ← Meta.whnfR e | failure let ⟨ep, hp⟩ ← deriveNat p _ let np := ep.natLit! unless 1 < np do failure haveI' h1ltp : Nat.blt 1 $ep =Q true := ⟨⟩ if sModNatTR (2 ^ np - 1) (np - 2) = 0 then haveI' hs : sModNatTR (2 ^ $ep - 1) ($ep - 2) =Q 0 := ⟨⟩ have pf : Q(LucasLehmerTest $ep) := q(testTrueHelper $ep $h1ltp $hs) have pf' : Q(LucasLehmerTest $p) := q(isNat_lucasLehmerTest $hp $pf) return .isTrue pf' else haveI' hs : Nat.ble 1 (sModNatTR (2 ^ $ep - 1) ($ep - 2)) =Q true := ⟨⟩ have pf : Q(¬ LucasLehmerTest $ep) := q(testFalseHelper $ep $h1ltp $hs) have pf' : Q(¬ LucasLehmerTest $p) := q(isNat_not_lucasLehmerTest $hp $pf) return .isFalse pf' end norm_num_ext end LucasLehmer /-! This implementation works successfully to prove `(2^4423 - 1).Prime`, and all the Mersenne primes up to this point appear in [Archive/Examples/MersennePrimes.lean]. These can be calculated nearly instantly, and `(2^9689 - 1).Prime` only fails due to deep recursion. (Note by kmill: the following notes were for the Lean 3 version. They seem like they could still be useful, so I'm leaving them here.) There's still low hanging fruit available to do faster computations based on the formula ``` n ≡ (n % 2^p) + (n / 2^p) [MOD 2^p - 1] ``` and the fact that `% 2^p` and `/ 2^p` can be very efficient on the binary representation. Someone should do this, too! -/ theorem modEq_mersenne (n k : ℕ) : k ≡ k / 2 ^ n + k % 2 ^ n [MOD 2 ^ n - 1] := -- See https://leanprover.zulipchat.com/#narrow/stream/113489-new-members/topic/help.20finding.20a.20lemma/near/177698446 calc k = 2 ^ n * (k / 2 ^ n) + k % 2 ^ n := (Nat.div_add_mod k (2 ^ n)).symm _ ≡ 1 * (k / 2 ^ n) + k % 2 ^ n [MOD 2 ^ n - 1] := ((Nat.modEq_sub <| Nat.succ_le_of_lt <| pow_pos zero_lt_two _).mul_right _).add_right _ _ = k / 2 ^ n + k % 2 ^ n := by rw [one_mul] -- It's hard to know what the limiting factor for large Mersenne primes would be. -- In the purely computational world, I think it's the squaring operation in `s`.
Mathlib/NumberTheory/LucasLehmer.lean
683
689
/- 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.Hom import Mathlib.RingTheory.Congruence.Basic import Mathlib.RingTheory.Ideal.Quotient.Defs import Mathlib.RingTheory.Ideal.Span /-! # Quotients of semirings In this file, we directly define the quotient of a semiring by any relation, by building a bigger relation that represents the ideal generated by that relation. We prove the universal properties of the quotient, and recommend avoiding relying on the actual definition, which is made irreducible for this purpose. Since everything runs in parallel for quotients of `R`-algebras, we do that case at the same time. -/ assert_not_exists Star.star universe uR uS uT uA u₄ variable {R : Type uR} [Semiring R] variable {S : Type uS} [CommSemiring S] variable {T : Type uT} variable {A : Type uA} [Semiring A] [Algebra S A] namespace RingCon instance (c : RingCon A) : Algebra S c.Quotient where smul := (· • ·) algebraMap := c.mk'.comp (algebraMap S A) commutes' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.commutes _ _ smul_def' _ := Quotient.ind' fun _ ↦ congr_arg Quotient.mk'' <| Algebra.smul_def _ _ @[simp, norm_cast] theorem coe_algebraMap (c : RingCon A) (s : S) : (algebraMap S A s : c.Quotient) = algebraMap S _ s := rfl end RingCon namespace RingQuot /-- Given an arbitrary relation `r` on a ring, we strengthen it to a relation `Rel r`, such that the equivalence relation generated by `Rel r` has `x ~ y` if and only if `x - y` is in the ideal generated by elements `a - b` such that `r a b`. -/ inductive Rel (r : R → R → Prop) : R → R → Prop | of ⦃x y : R⦄ (h : r x y) : Rel r x y | add_left ⦃a b c⦄ : Rel r a b → Rel r (a + c) (b + c) | mul_left ⦃a b c⦄ : Rel r a b → Rel r (a * c) (b * c) | mul_right ⦃a b c⦄ : Rel r b c → Rel r (a * b) (a * c) theorem Rel.add_right {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a + b) (a + c) := by rw [add_comm a b, add_comm a c] exact Rel.add_left h theorem Rel.neg {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b : R⦄ (h : Rel r a b) : Rel r (-a) (-b) := by simp only [neg_eq_neg_one_mul a, neg_eq_neg_one_mul b, Rel.mul_right h] theorem Rel.sub_left {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r a b) : Rel r (a - c) (b - c) := by simp only [sub_eq_add_neg, h.add_left] theorem Rel.sub_right {R : Type uR} [Ring R] {r : R → R → Prop} ⦃a b c : R⦄ (h : Rel r b c) : Rel r (a - b) (a - c) := by simp only [sub_eq_add_neg, h.neg.add_right] theorem Rel.smul {r : A → A → Prop} (k : S) ⦃a b : A⦄ (h : Rel r a b) : Rel r (k • a) (k • b) := by simp only [Algebra.smul_def, Rel.mul_right h] /-- `EqvGen (RingQuot.Rel r)` is a ring congruence. -/ def ringCon (r : R → R → Prop) : RingCon R where r := Relation.EqvGen (Rel r) iseqv := Relation.EqvGen.is_equivalence _ add' {a b c d} hab hcd := by induction hab generalizing c d with | rel _ _ hab => refine (Relation.EqvGen.rel _ _ hab.add_left).trans _ _ _ ?_ induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.add_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | refl => induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.add_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | symm x y _ hxy => exact (hxy hcd.symm).symm | trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| Relation.EqvGen.refl _) mul' {a b c d} hab hcd := by induction hab generalizing c d with | rel _ _ hab => refine (Relation.EqvGen.rel _ _ hab.mul_left).trans _ _ _ ?_ induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.mul_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | refl => induction hcd with | rel _ _ hcd => exact Relation.EqvGen.rel _ _ hcd.mul_right | refl => exact Relation.EqvGen.refl _ | symm _ _ _ h => exact h.symm _ _ | trans _ _ _ _ _ h h' => exact h.trans _ _ _ h' | symm x y _ hxy => exact (hxy hcd.symm).symm | trans x y z _ _ h h' => exact (h hcd).trans _ _ _ (h' <| Relation.EqvGen.refl _) theorem eqvGen_rel_eq (r : R → R → Prop) : Relation.EqvGen (Rel r) = RingConGen.Rel r := by ext x₁ x₂ constructor · intro h induction h with | rel _ _ h => induction h with | of => exact RingConGen.Rel.of _ _ ‹_› | add_left _ h => exact h.add (RingConGen.Rel.refl _) | mul_left _ h => exact h.mul (RingConGen.Rel.refl _) | mul_right _ h => exact (RingConGen.Rel.refl _).mul h | refl => exact RingConGen.Rel.refl _ | symm => exact RingConGen.Rel.symm ‹_› | trans => exact RingConGen.Rel.trans ‹_› ‹_› · intro h induction h with | of => exact Relation.EqvGen.rel _ _ (Rel.of ‹_›) | refl => exact (RingQuot.ringCon r).refl _ | symm => exact (RingQuot.ringCon r).symm ‹_› | trans => exact (RingQuot.ringCon r).trans ‹_› ‹_› | add => exact (RingQuot.ringCon r).add ‹_› ‹_› | mul => exact (RingQuot.ringCon r).mul ‹_› ‹_› end RingQuot /-- The quotient of a ring by an arbitrary relation. -/ structure RingQuot (r : R → R → Prop) where toQuot : Quot (RingQuot.Rel r) namespace RingQuot variable (r : R → R → Prop) -- can't be irreducible, causes diamonds in ℕ-algebras private def natCast (n : ℕ) : RingQuot r := ⟨Quot.mk _ n⟩ private irreducible_def zero : RingQuot r := ⟨Quot.mk _ 0⟩ private irreducible_def one : RingQuot r := ⟨Quot.mk _ 1⟩ private irreducible_def add : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· + ·) Rel.add_right Rel.add_left a b⟩ private irreducible_def mul : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ (· * ·) Rel.mul_right Rel.mul_left a b⟩ private irreducible_def neg {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (fun a ↦ -a) Rel.neg a⟩ private irreducible_def sub {R : Type uR} [Ring R] (r : R → R → Prop) : RingQuot r → RingQuot r → RingQuot r | ⟨a⟩, ⟨b⟩ => ⟨Quot.map₂ Sub.sub Rel.sub_right Rel.sub_left a b⟩ private irreducible_def npow (n : ℕ) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.lift (fun a ↦ Quot.mk (RingQuot.Rel r) (a ^ n)) (fun a b (h : Rel r a b) ↦ by -- note we can't define a `Rel.pow` as `Rel` isn't reflexive so `Rel r 1 1` isn't true dsimp only induction n with | zero => rw [pow_zero, pow_zero] | succ n ih => simpa only [pow_succ, mul_def, Quot.map₂_mk, mk.injEq] using congr_arg₂ (fun x y ↦ mul r ⟨x⟩ ⟨y⟩) ih (Quot.sound h)) a⟩ -- note: this cannot be irreducible, as otherwise diamonds don't commute. private def smul [Algebra S R] (n : S) : RingQuot r → RingQuot r | ⟨a⟩ => ⟨Quot.map (fun a ↦ n • a) (Rel.smul n) a⟩ instance : NatCast (RingQuot r) := ⟨natCast r⟩ instance : Zero (RingQuot r) := ⟨zero r⟩ instance : One (RingQuot r) := ⟨one r⟩ instance : Add (RingQuot r) := ⟨add r⟩ instance : Mul (RingQuot r) := ⟨mul r⟩ instance : NatPow (RingQuot r) := ⟨fun x n ↦ npow r n x⟩ instance {R : Type uR} [Ring R] (r : R → R → Prop) : Neg (RingQuot r) := ⟨neg r⟩ instance {R : Type uR} [Ring R] (r : R → R → Prop) : Sub (RingQuot r) := ⟨sub r⟩ instance [Algebra S R] : SMul S (RingQuot r) := ⟨smul r⟩ theorem zero_quot : (⟨Quot.mk _ 0⟩ : RingQuot r) = 0 := show _ = zero r by rw [zero_def] theorem one_quot : (⟨Quot.mk _ 1⟩ : RingQuot r) = 1 := show _ = one r by rw [one_def] theorem add_quot {a b} : (⟨Quot.mk _ a⟩ + ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a + b)⟩ := by show add r _ _ = _ rw [add_def] rfl theorem mul_quot {a b} : (⟨Quot.mk _ a⟩ * ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a * b)⟩ := by show mul r _ _ = _ rw [mul_def] rfl theorem pow_quot {a} {n : ℕ} : (⟨Quot.mk _ a⟩ ^ n : RingQuot r) = ⟨Quot.mk _ (a ^ n)⟩ := by show npow r _ _ = _ rw [npow_def] theorem neg_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a} : (-⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (-a)⟩ := by show neg r _ = _ rw [neg_def] rfl theorem sub_quot {R : Type uR} [Ring R] (r : R → R → Prop) {a b} : (⟨Quot.mk _ a⟩ - ⟨Quot.mk _ b⟩ : RingQuot r) = ⟨Quot.mk _ (a - b)⟩ := by show sub r _ _ = _ rw [sub_def] rfl theorem smul_quot [Algebra S R] {n : S} {a : R} : (n • ⟨Quot.mk _ a⟩ : RingQuot r) = ⟨Quot.mk _ (n • a)⟩ := by show smul r _ _ = _ rw [smul] rfl instance instIsScalarTower [CommSemiring T] [SMul S T] [Algebra S R] [Algebra T R]
[IsScalarTower S T R] : IsScalarTower S T (RingQuot r) := ⟨fun s t ⟨a⟩ => Quot.inductionOn a fun a' => by simp only [RingQuot.smul_quot, smul_assoc]⟩
Mathlib/Algebra/RingQuot.lean
250
252
/- 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.Analysis.Calculus.FDeriv.Add import Mathlib.Analysis.Calculus.FDeriv.Equiv import Mathlib.Analysis.Calculus.FDeriv.Prod import Mathlib.Analysis.Calculus.Monotone import Mathlib.Topology.EMetricSpace.BoundedVariation /-! # Almost everywhere differentiability of functions with locally bounded variation In this file we show that a bounded variation function is differentiable almost everywhere. This implies that Lipschitz functions from the real line into finite-dimensional vector space are also differentiable almost everywhere. ## Main definitions and results * `LocallyBoundedVariationOn.ae_differentiableWithinAt` shows that a bounded variation function into a finite dimensional real vector space is differentiable almost everywhere. * `LipschitzOnWith.ae_differentiableWithinAt` is the same result for Lipschitz functions. We also give several variations around these results. -/ open scoped NNReal ENNReal Topology open Set MeasureTheory Filter variable {α : Type*} [LinearOrder α] {E : Type*} [PseudoEMetricSpace E] /-! ## -/ variable {V : Type*} [NormedAddCommGroup V] [NormedSpace ℝ V] [FiniteDimensional ℝ V] namespace LocallyBoundedVariationOn /-- A bounded variation function into `ℝ` is differentiable almost everywhere. Superseded by `ae_differentiableWithinAt_of_mem`. -/ theorem ae_differentiableWithinAt_of_mem_real {f : ℝ → ℝ} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by obtain ⟨p, q, hp, hq, rfl⟩ : ∃ p q, MonotoneOn p s ∧ MonotoneOn q s ∧ f = p - q := h.exists_monotoneOn_sub_monotoneOn filter_upwards [hp.ae_differentiableWithinAt_of_mem, hq.ae_differentiableWithinAt_of_mem] with x hxp hxq xs exact (hxp xs).sub (hxq xs) /-- A bounded variation function into a finite dimensional product vector space is differentiable almost everywhere. Superseded by `ae_differentiableWithinAt_of_mem`. -/ theorem ae_differentiableWithinAt_of_mem_pi {ι : Type*} [Fintype ι] {f : ℝ → ι → ℝ} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by have A : ∀ i : ι, LipschitzWith 1 fun x : ι → ℝ => x i := fun i => LipschitzWith.eval i have : ∀ i : ι, ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ (fun x : ℝ => f x i) s x := fun i ↦ by apply ae_differentiableWithinAt_of_mem_real exact LipschitzWith.comp_locallyBoundedVariationOn (A i) h filter_upwards [ae_all_iff.2 this] with x hx xs exact differentiableWithinAt_pi.2 fun i => hx i xs /-- A real function into a finite dimensional real vector space with bounded variation on a set is differentiable almost everywhere in this set. -/ theorem ae_differentiableWithinAt_of_mem {f : ℝ → V} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := by let A := (Basis.ofVectorSpace ℝ V).equivFun.toContinuousLinearEquiv suffices H : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ (A ∘ f) s x by filter_upwards [H] with x hx xs have : f = (A.symm ∘ A) ∘ f := by simp only [ContinuousLinearEquiv.symm_comp_self, Function.id_comp] rw [this] exact A.symm.differentiableAt.comp_differentiableWithinAt x (hx xs) apply ae_differentiableWithinAt_of_mem_pi exact A.lipschitz.comp_locallyBoundedVariationOn h /-- A real function into a finite dimensional real vector space with bounded variation on a set is differentiable almost everywhere in this set. -/ theorem ae_differentiableWithinAt {f : ℝ → V} {s : Set ℝ} (h : LocallyBoundedVariationOn f s) (hs : MeasurableSet s) : ∀ᵐ x ∂volume.restrict s, DifferentiableWithinAt ℝ f s x := by rw [ae_restrict_iff' hs] exact h.ae_differentiableWithinAt_of_mem /-- A real function into a finite dimensional real vector space with bounded variation is differentiable almost everywhere. -/ theorem ae_differentiableAt {f : ℝ → V} (h : LocallyBoundedVariationOn f univ) : ∀ᵐ x, DifferentiableAt ℝ f x := by filter_upwards [h.ae_differentiableWithinAt_of_mem] with x hx rw [differentiableWithinAt_univ] at hx exact hx (mem_univ _) end LocallyBoundedVariationOn /-- A real function into a finite dimensional real vector space which is Lipschitz on a set is differentiable almost everywhere in this set. For the general Rademacher theorem assuming that the source space is finite dimensional, see `LipschitzOnWith.ae_differentiableWithinAt_of_mem`. -/ theorem LipschitzOnWith.ae_differentiableWithinAt_of_mem_real {C : ℝ≥0} {f : ℝ → V} {s : Set ℝ} (h : LipschitzOnWith C f s) : ∀ᵐ x, x ∈ s → DifferentiableWithinAt ℝ f s x := h.locallyBoundedVariationOn.ae_differentiableWithinAt_of_mem /-- A real function into a finite dimensional real vector space which is Lipschitz on a set is differentiable almost everywhere in this set. For the general Rademacher theorem assuming that the source space is finite dimensional, see `LipschitzOnWith.ae_differentiableWithinAt`. -/ theorem LipschitzOnWith.ae_differentiableWithinAt_real {C : ℝ≥0} {f : ℝ → V} {s : Set ℝ} (h : LipschitzOnWith C f s) (hs : MeasurableSet s) : ∀ᵐ x ∂volume.restrict s, DifferentiableWithinAt ℝ f s x := h.locallyBoundedVariationOn.ae_differentiableWithinAt hs /-- A real Lipschitz function into a finite dimensional real vector space is differentiable almost everywhere. For the general Rademacher theorem assuming that the source space is finite dimensional, see `LipschitzWith.ae_differentiableAt`. -/ theorem LipschitzWith.ae_differentiableAt_real {C : ℝ≥0} {f : ℝ → V} (h : LipschitzWith C f) : ∀ᵐ x, DifferentiableAt ℝ f x := (h.locallyBoundedVariationOn univ).ae_differentiableAt
Mathlib/Analysis/BoundedVariation.lean
216
222
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.MeasureTheory.Measure.AEMeasurable /-! # Typeclasses for measurability of operations In this file we define classes `MeasurableMul` etc and prove dot-style lemmas (`Measurable.mul`, `AEMeasurable.mul` etc). For binary operations we define two typeclasses: - `MeasurableMul` says that both left and right multiplication are measurable; - `MeasurableMul₂` says that `fun p : α × α => p.1 * p.2` is measurable, and similarly for other binary operations. The reason for introducing these classes is that in case of topological space `α` equipped with the Borel `σ`-algebra, instances for `MeasurableMul₂` etc require `α` to have a second countable topology. We define separate classes for `MeasurableDiv`/`MeasurableSub` because on some types (e.g., `ℕ`, `ℝ≥0∞`) division and/or subtraction are not defined as `a * b⁻¹` / `a + (-b)`. For instances relating, e.g., `ContinuousMul` to `MeasurableMul` see file `MeasureTheory.BorelSpace`. ## Implementation notes For the heuristics of `@[to_additive]` it is important that the type with a multiplication (or another multiplicative operations) is the first (implicit) argument of all declarations. ## Tags measurable function, arithmetic operator ## TODO * Uniformize the treatment of `pow` and `smul`. * Use `@[to_additive]` to send `MeasurablePow` to `MeasurableSMul₂`. * This might require changing the definition (swapping the arguments in the function that is in the conclusion of `MeasurableSMul`.) -/ open MeasureTheory open scoped Pointwise universe u v variable {α : Type*} /-! ### Binary operations: `(· + ·)`, `(· * ·)`, `(· - ·)`, `(· / ·)` -/ /-- We say that a type has `MeasurableAdd` if `(· + c)` and `(· + c)` are measurable functions. For a typeclass assuming measurability of `uncurry (· + ·)` see `MeasurableAdd₂`. -/ class MeasurableAdd (M : Type*) [MeasurableSpace M] [Add M] : Prop where measurable_const_add : ∀ c : M, Measurable (c + ·) measurable_add_const : ∀ c : M, Measurable (· + c) export MeasurableAdd (measurable_const_add measurable_add_const) /-- We say that a type has `MeasurableAdd₂` if `uncurry (· + ·)` is a measurable functions. For a typeclass assuming measurability of `(c + ·)` and `(· + c)` see `MeasurableAdd`. -/ class MeasurableAdd₂ (M : Type*) [MeasurableSpace M] [Add M] : Prop where measurable_add : Measurable fun p : M × M => p.1 + p.2 export MeasurableAdd₂ (measurable_add) /-- We say that a type has `MeasurableMul` if `(c * ·)` and `(· * c)` are measurable functions. For a typeclass assuming measurability of `uncurry (*)` see `MeasurableMul₂`. -/ @[to_additive] class MeasurableMul (M : Type*) [MeasurableSpace M] [Mul M] : Prop where measurable_const_mul : ∀ c : M, Measurable (c * ·) measurable_mul_const : ∀ c : M, Measurable (· * c) export MeasurableMul (measurable_const_mul measurable_mul_const) /-- We say that a type has `MeasurableMul₂` if `uncurry (· * ·)` is a measurable functions. For a typeclass assuming measurability of `(c * ·)` and `(· * c)` see `MeasurableMul`. -/ @[to_additive MeasurableAdd₂] class MeasurableMul₂ (M : Type*) [MeasurableSpace M] [Mul M] : Prop where measurable_mul : Measurable fun p : M × M => p.1 * p.2 export MeasurableMul₂ (measurable_mul) section Mul variable {M α β : Type*} [MeasurableSpace M] [Mul M] {m : MeasurableSpace α} {mβ : MeasurableSpace β} {f g : α → M} {μ : Measure α} @[to_additive (attr := fun_prop, measurability)] theorem Measurable.const_mul [MeasurableMul M] (hf : Measurable f) (c : M) : Measurable fun x => c * f x := (measurable_const_mul c).comp hf @[to_additive (attr := fun_prop, measurability)] theorem AEMeasurable.const_mul [MeasurableMul M] (hf : AEMeasurable f μ) (c : M) : AEMeasurable (fun x => c * f x) μ := (MeasurableMul.measurable_const_mul c).comp_aemeasurable hf @[to_additive (attr := fun_prop, measurability)] theorem Measurable.mul_const [MeasurableMul M] (hf : Measurable f) (c : M) : Measurable fun x => f x * c := (measurable_mul_const c).comp hf @[to_additive (attr := fun_prop, measurability)] theorem AEMeasurable.mul_const [MeasurableMul M] (hf : AEMeasurable f μ) (c : M) : AEMeasurable (fun x => f x * c) μ := (measurable_mul_const c).comp_aemeasurable hf @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.mul [MeasurableMul₂ M] (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a * g a := measurable_mul.comp (hf.prodMk hg) /-- Compositional version of `Measurable.mul` for use by `fun_prop`. -/ @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable])) "Compositional version of `Measurable.add` for use by `fun_prop`."] lemma Measurable.mul' [MeasurableMul₂ M] {f g : α → β → M} {h : α → β} (hf : Measurable ↿f) (hg : Measurable ↿g) (hh : Measurable h) : Measurable fun a ↦ (f a * g a) (h a) := by simp; fun_prop @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.mul' [MeasurableMul₂ M] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (f * g) μ := measurable_mul.comp_aemeasurable (hf.prodMk hg) @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.mul [MeasurableMul₂ M] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => f a * g a) μ := measurable_mul.comp_aemeasurable (hf.prodMk hg) @[to_additive] instance (priority := 100) MeasurableMul₂.toMeasurableMul [MeasurableMul₂ M] : MeasurableMul M := ⟨fun _ => measurable_const.mul measurable_id, fun _ => measurable_id.mul measurable_const⟩ @[to_additive] instance Pi.measurableMul {ι : Type*} {α : ι → Type*} [∀ i, Mul (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableMul (α i)] : MeasurableMul (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_mul _, fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).mul_const _⟩ @[to_additive Pi.measurableAdd₂] instance Pi.measurableMul₂ {ι : Type*} {α : ι → Type*} [∀ i, Mul (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableMul₂ (α i)] : MeasurableMul₂ (∀ i, α i) := ⟨measurable_pi_iff.mpr fun _ => measurable_fst.eval.mul measurable_snd.eval⟩ end Mul /-- A version of `measurable_div_const` that assumes `MeasurableMul` instead of `MeasurableDiv`. This can be nice to avoid unnecessary type-class assumptions. -/ @[to_additive "A version of `measurable_sub_const` that assumes `MeasurableAdd` instead of `MeasurableSub`. This can be nice to avoid unnecessary type-class assumptions."] theorem measurable_div_const' {G : Type*} [DivInvMonoid G] [MeasurableSpace G] [MeasurableMul G] (g : G) : Measurable fun h => h / g := by simp_rw [div_eq_mul_inv, measurable_mul_const] /-- This class assumes that the map `β × γ → β` given by `(x, y) ↦ x ^ y` is measurable. -/ class MeasurablePow (β γ : Type*) [MeasurableSpace β] [MeasurableSpace γ] [Pow β γ] : Prop where measurable_pow : Measurable fun p : β × γ => p.1 ^ p.2 export MeasurablePow (measurable_pow) /-- `Monoid.Pow` is measurable. -/ instance Monoid.measurablePow (M : Type*) [Monoid M] [MeasurableSpace M] [MeasurableMul₂ M] : MeasurablePow M ℕ := ⟨measurable_from_prod_countable fun n => by induction' n with n ih · simp only [pow_zero, ← Pi.one_def, measurable_one] · simp only [pow_succ] exact ih.mul measurable_id⟩ section Pow variable {β γ α : Type*} [MeasurableSpace β] [MeasurableSpace γ] [Pow β γ] [MeasurablePow β γ] {m : MeasurableSpace α} {μ : Measure α} {f : α → β} {g : α → γ} @[aesop safe 20 apply (rule_sets := [Measurable]), fun_prop] theorem Measurable.pow (hf : Measurable f) (hg : Measurable g) : Measurable fun x => f x ^ g x := measurable_pow.comp (hf.prodMk hg) @[aesop safe 20 apply (rule_sets := [Measurable]), fun_prop] theorem AEMeasurable.pow (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun x => f x ^ g x) μ := measurable_pow.comp_aemeasurable (hf.prodMk hg) @[fun_prop, measurability] theorem Measurable.pow_const (hf : Measurable f) (c : γ) : Measurable fun x => f x ^ c := hf.pow measurable_const @[fun_prop, measurability] theorem AEMeasurable.pow_const (hf : AEMeasurable f μ) (c : γ) : AEMeasurable (fun x => f x ^ c) μ := hf.pow aemeasurable_const @[fun_prop, measurability] theorem Measurable.const_pow (hg : Measurable g) (c : β) : Measurable fun x => c ^ g x := measurable_const.pow hg @[fun_prop, measurability] theorem AEMeasurable.const_pow (hg : AEMeasurable g μ) (c : β) : AEMeasurable (fun x => c ^ g x) μ := aemeasurable_const.pow hg end Pow /-- We say that a type has `MeasurableSub` if `(c - ·)` and `(· - c)` are measurable functions. For a typeclass assuming measurability of `uncurry (-)` see `MeasurableSub₂`. -/ class MeasurableSub (G : Type*) [MeasurableSpace G] [Sub G] : Prop where measurable_const_sub : ∀ c : G, Measurable (c - ·) measurable_sub_const : ∀ c : G, Measurable (· - c) export MeasurableSub (measurable_const_sub measurable_sub_const) /-- We say that a type has `MeasurableSub₂` if `uncurry (· - ·)` is a measurable functions. For a typeclass assuming measurability of `(c - ·)` and `(· - c)` see `MeasurableSub`. -/ class MeasurableSub₂ (G : Type*) [MeasurableSpace G] [Sub G] : Prop where measurable_sub : Measurable fun p : G × G => p.1 - p.2 export MeasurableSub₂ (measurable_sub) /-- We say that a type has `MeasurableDiv` if `(c / ·)` and `(· / c)` are measurable functions. For a typeclass assuming measurability of `uncurry (· / ·)` see `MeasurableDiv₂`. -/ @[to_additive] class MeasurableDiv (G₀ : Type*) [MeasurableSpace G₀] [Div G₀] : Prop where measurable_const_div : ∀ c : G₀, Measurable (c / ·) measurable_div_const : ∀ c : G₀, Measurable (· / c) export MeasurableDiv (measurable_const_div measurable_div_const) /-- We say that a type has `MeasurableDiv₂` if `uncurry (· / ·)` is a measurable functions. For a typeclass assuming measurability of `(c / ·)` and `(· / c)` see `MeasurableDiv`. -/ @[to_additive MeasurableSub₂] class MeasurableDiv₂ (G₀ : Type*) [MeasurableSpace G₀] [Div G₀] : Prop where measurable_div : Measurable fun p : G₀ × G₀ => p.1 / p.2 export MeasurableDiv₂ (measurable_div) section Div variable {G α β : Type*} [MeasurableSpace G] [Div G] {m : MeasurableSpace α} {mβ : MeasurableSpace β} {f g : α → G} {μ : Measure α} @[to_additive (attr := fun_prop, measurability)] theorem Measurable.const_div [MeasurableDiv G] (hf : Measurable f) (c : G) : Measurable fun x => c / f x := (MeasurableDiv.measurable_const_div c).comp hf @[to_additive (attr := fun_prop, measurability)] theorem AEMeasurable.const_div [MeasurableDiv G] (hf : AEMeasurable f μ) (c : G) : AEMeasurable (fun x => c / f x) μ := (MeasurableDiv.measurable_const_div c).comp_aemeasurable hf @[to_additive (attr := fun_prop, measurability)] theorem Measurable.div_const [MeasurableDiv G] (hf : Measurable f) (c : G) : Measurable fun x => f x / c := (MeasurableDiv.measurable_div_const c).comp hf @[to_additive (attr := fun_prop, measurability)] theorem AEMeasurable.div_const [MeasurableDiv G] (hf : AEMeasurable f μ) (c : G) : AEMeasurable (fun x => f x / c) μ := (MeasurableDiv.measurable_div_const c).comp_aemeasurable hf @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] theorem Measurable.div [MeasurableDiv₂ G] (hf : Measurable f) (hg : Measurable g) : Measurable fun a => f a / g a := measurable_div.comp (hf.prodMk hg) @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] lemma Measurable.div' [MeasurableDiv₂ G] {f g : α → β → G} {h : α → β} (hf : Measurable ↿f) (hg : Measurable ↿g) (hh : Measurable h) : Measurable fun a ↦ (f a / g a) (h a) := by simp; fun_prop @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.div' [MeasurableDiv₂ G] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (f / g) μ := measurable_div.comp_aemeasurable (hf.prodMk hg) @[to_additive (attr := fun_prop, aesop safe 20 apply (rule_sets := [Measurable]))] theorem AEMeasurable.div [MeasurableDiv₂ G] (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : AEMeasurable (fun a => f a / g a) μ := measurable_div.comp_aemeasurable (hf.prodMk hg) @[to_additive] instance (priority := 100) MeasurableDiv₂.toMeasurableDiv [MeasurableDiv₂ G] : MeasurableDiv G := ⟨fun _ => measurable_const.div measurable_id, fun _ => measurable_id.div measurable_const⟩ @[to_additive] instance Pi.measurableDiv {ι : Type*} {α : ι → Type*} [∀ i, Div (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableDiv (α i)] : MeasurableDiv (∀ i, α i) := ⟨fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).const_div _, fun _ => measurable_pi_iff.mpr fun i => (measurable_pi_apply i).div_const _⟩ @[to_additive Pi.measurableSub₂] instance Pi.measurableDiv₂ {ι : Type*} {α : ι → Type*} [∀ i, Div (α i)] [∀ i, MeasurableSpace (α i)] [∀ i, MeasurableDiv₂ (α i)] : MeasurableDiv₂ (∀ i, α i) := ⟨measurable_pi_iff.mpr fun _ => measurable_fst.eval.div measurable_snd.eval⟩ @[measurability] theorem measurableSet_eq_fun {m : MeasurableSpace α} {E} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] {f g : α → E} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { x | f x = g x } := by suffices h_set_eq : { x : α | f x = g x } = { x | (f - g) x = (0 : E) } by rw [h_set_eq] exact (hf.sub hg) measurableSet_eq ext simp_rw [Set.mem_setOf_eq, Pi.sub_apply, sub_eq_zero] @[measurability] lemma measurableSet_eq_fun' {β : Type*} [AddCommMonoid β] [PartialOrder β] [CanonicallyOrderedAdd β] [Sub β] [OrderedSub β] {_ : MeasurableSpace β} [MeasurableSub₂ β] [MeasurableSingletonClass β] {f g : α → β} (hf : Measurable f) (hg : Measurable g) : MeasurableSet {x | f x = g x} := by have : {a | f a = g a} = {a | (f - g) a = 0} ∩ {a | (g - f) a = 0} := by ext simp only [Set.mem_setOf_eq, Pi.sub_apply, tsub_eq_zero_iff_le, Set.mem_inter_iff] exact ⟨fun h ↦ ⟨h.le, h.symm.le⟩, fun h ↦ le_antisymm h.1 h.2⟩ rw [this] exact ((hf.sub hg) (measurableSet_singleton 0)).inter ((hg.sub hf) (measurableSet_singleton 0)) theorem nullMeasurableSet_eq_fun {E} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] {f g : α → E} (hf : AEMeasurable f μ) (hg : AEMeasurable g μ) : NullMeasurableSet { x | f x = g x } μ := by apply (measurableSet_eq_fun hf.measurable_mk hg.measurable_mk).nullMeasurableSet.congr filter_upwards [hf.ae_eq_mk, hg.ae_eq_mk] with x hfx hgx change (hf.mk f x = hg.mk g x) = (f x = g x) simp only [hfx, hgx] theorem measurableSet_eq_fun_of_countable {m : MeasurableSpace α} {E} [MeasurableSpace E] [MeasurableSingletonClass E] [Countable E] {f g : α → E} (hf : Measurable f) (hg : Measurable g) : MeasurableSet { x | f x = g x } := by have : { x | f x = g x } = ⋃ j, { x | f x = j } ∩ { x | g x = j } := by ext1 x simp only [Set.mem_setOf_eq, Set.mem_iUnion, Set.mem_inter_iff, exists_eq_right'] rw [this] refine MeasurableSet.iUnion fun j => MeasurableSet.inter ?_ ?_ · exact hf (measurableSet_singleton j) · exact hg (measurableSet_singleton j) theorem ae_eq_trim_of_measurable {α E} {m m0 : MeasurableSpace α} {μ : Measure α} [MeasurableSpace E] [AddGroup E] [MeasurableSingletonClass E] [MeasurableSub₂ E] (hm : m ≤ m0) {f g : α → E} (hf : Measurable[m] f) (hg : Measurable[m] g) (hfg : f =ᵐ[μ] g) : f =ᵐ[μ.trim hm] g := by rwa [Filter.EventuallyEq, ae_iff, trim_measurableSet_eq hm _] exact @MeasurableSet.compl α _ m (@measurableSet_eq_fun α m E _ _ _ _ _ _ hf hg) end Div /-- We say that a type has `MeasurableNeg` if `x ↦ -x` is a measurable function. -/ class MeasurableNeg (G : Type*) [Neg G] [MeasurableSpace G] : Prop where measurable_neg : Measurable (Neg.neg : G → G) /-- We say that a type has `MeasurableInv` if `x ↦ x⁻¹` is a measurable function. -/ @[to_additive] class MeasurableInv (G : Type*) [Inv G] [MeasurableSpace G] : Prop where measurable_inv : Measurable (Inv.inv : G → G) export MeasurableInv (measurable_inv) export MeasurableNeg (measurable_neg) @[to_additive] instance (priority := 100) measurableDiv_of_mul_inv (G : Type*) [MeasurableSpace G] [DivInvMonoid G] [MeasurableMul G] [MeasurableInv G] : MeasurableDiv G where measurable_const_div c := by convert measurable_inv.const_mul c using 1 ext1 apply div_eq_mul_inv measurable_div_const c := by convert measurable_id.mul_const c⁻¹ using 1 ext1 apply div_eq_mul_inv section Inv variable {G α : Type*} [Inv G] [MeasurableSpace G] [MeasurableInv G] {m : MeasurableSpace α} {f : α → G} {μ : Measure α} @[to_additive (attr := fun_prop, measurability)] theorem Measurable.inv (hf : Measurable f) : Measurable fun x => (f x)⁻¹ := measurable_inv.comp hf @[to_additive (attr := fun_prop, measurability)] theorem AEMeasurable.inv (hf : AEMeasurable f μ) : AEMeasurable (fun x => (f x)⁻¹) μ := measurable_inv.comp_aemeasurable hf @[to_additive (attr := simp)] theorem measurable_inv_iff {G : Type*} [InvolutiveInv G] [MeasurableSpace G] [MeasurableInv G] {f : α → G} : (Measurable fun x => (f x)⁻¹) ↔ Measurable f := ⟨fun h => by simpa only [inv_inv] using h.inv, fun h => h.inv⟩ @[to_additive (attr := simp)] theorem aemeasurable_inv_iff {G : Type*} [InvolutiveInv G] [MeasurableSpace G] [MeasurableInv G]
{f : α → G} : AEMeasurable (fun x => (f x)⁻¹) μ ↔ AEMeasurable f μ := ⟨fun h => by simpa only [inv_inv] using h.inv, fun h => h.inv⟩ @[deprecated (since := "2025-04-09")] alias measurable_inv_iff₀ := measurable_inv_iff @[deprecated (since := "2025-04-09")]
Mathlib/MeasureTheory/Group/Arithmetic.lean
398
404
/- Copyright (c) 2024 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.FieldTheory.KummerExtension /-! # More results on primitive roots of unity (We put these in a separate file because of the `KummerExtension` import.) Assume that `μ` is a primitive `n`th root of unity in an integral domain `R`. Then $$ \prod_{k=1}^{n-1} (1 - \mu^k) = n \,; $$ see `IsPrimitiveRoot.prod_one_sub_pow_eq_order` and its variant `IsPrimitiveRoot.prod_pow_sub_one_eq_order` in terms of `∏ (μ^k - 1)`. We use this to deduce that `n` is divisible by `(μ - 1)^k` in `ℤ[μ] ⊆ R` when `k < n`. -/ variable {R : Type*} [CommRing R] [IsDomain R] namespace IsPrimitiveRoot open Finset Polynomial /-- If `μ` is a primitive `n`th root of unity in `R`, then `∏(1≤k<n) (1-μ^k) = n`.
(Stated with `n+1` in place of `n` to avoid the condition `n ≠ 0`.) -/ lemma prod_one_sub_pow_eq_order {n : ℕ} {μ : R} (hμ : IsPrimitiveRoot μ (n + 1)) : ∏ k ∈ range n, (1 - μ ^ (k + 1)) = n + 1 := by have := X_pow_sub_C_eq_prod hμ n.zero_lt_succ (one_pow (n + 1)) rw [C_1, ← mul_geom_sum, prod_range_succ', pow_zero, mul_one, mul_comm, eq_comm] at this replace this := mul_right_cancel₀ (Polynomial.X_sub_C_ne_zero 1) this apply_fun Polynomial.eval 1 at this simpa only [mul_one, map_pow, eval_prod, eval_sub, eval_X, eval_pow, eval_C, eval_geom_sum, one_pow, sum_const, card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] using this
Mathlib/RingTheory/RootsOfUnity/Lemmas.lean
28
37
/- Copyright (c) 2020 Jean Lo, Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jean Lo, Yury Kudryashov -/ import Mathlib.Algebra.GroupWithZero.Action.Pointwise.Set import Mathlib.Algebra.Ring.Action.Pointwise.Set import Mathlib.Topology.Bornology.Basic /-! # Absorption of sets Let `M` act on `α`, let `A` and `B` be sets in `α`. We say that `A` *absorbs* `B` if for sufficiently large `a : M`, we have `B ⊆ a • A`. Formally, "for sufficiently large `a : M`" means "for all but a bounded set of `a`". Traditionally, this definition is formulated for the action of a (semi)normed ring on a module over that ring. We formulate it in a more general settings for two reasons: - this way we don't have to depend on metric spaces, normed rings etc; - some proofs look nicer with this definition than with something like `∃ r : ℝ, ∀ a : R, r ≤ ‖a‖ → B ⊆ a • A`. If `M` is a `GroupWithZero` (e.g., a division ring), the sets absorbing a given set form a filter, see `Filter.absorbing`. ## Implementation notes For now, all theorems assume that we deal with (a generalization of) a module over a division ring. Some lemmas have multiplicative versions for `MulDistribMulAction`s. They can be added later when someone needs them. ## Keywords absorbs, absorbent -/ assert_not_exists Real open Set Bornology Filter open scoped Pointwise section Defs variable (M : Type*) {α : Type*} [Bornology M] [SMul M α] /-- A set `s` absorbs another set `t` if `t` is contained in all scalings of `s` by all but a bounded set of elements. -/ def Absorbs (s t : Set α) : Prop := ∀ᶠ a in cobounded M, t ⊆ a • s /-- A set is *absorbent* if it absorbs every singleton. -/ def Absorbent (s : Set α) : Prop := ∀ x, Absorbs M s {x} end Defs namespace Absorbs section SMul variable {M α : Type*} [Bornology M] [SMul M α] {s s₁ s₂ t t₁ t₂ : Set α} {S T : Set (Set α)} protected lemma empty : Absorbs M s ∅ := by simp [Absorbs] protected lemma eventually (h : Absorbs M s t) : ∀ᶠ a in cobounded M, t ⊆ a • s := h @[simp] lemma of_boundedSpace [BoundedSpace M] : Absorbs M s t := by simp [Absorbs] lemma mono_left (h : Absorbs M s₁ t) (hs : s₁ ⊆ s₂) : Absorbs M s₂ t := h.mono fun _a ha ↦ ha.trans <| smul_set_mono hs lemma mono_right (h : Absorbs M s t₁) (ht : t₂ ⊆ t₁) : Absorbs M s t₂ := h.mono fun _ ↦ ht.trans lemma mono (h : Absorbs M s₁ t₁) (hs : s₁ ⊆ s₂) (ht : t₂ ⊆ t₁) : Absorbs M s₂ t₂ := (h.mono_left hs).mono_right ht @[simp] lemma _root_.absorbs_union : Absorbs M s (t₁ ∪ t₂) ↔ Absorbs M s t₁ ∧ Absorbs M s t₂ := by simp [Absorbs] protected lemma union (h₁ : Absorbs M s t₁) (h₂ : Absorbs M s t₂) : Absorbs M s (t₁ ∪ t₂) := absorbs_union.2 ⟨h₁, h₂⟩ lemma _root_.Set.Finite.absorbs_sUnion {T : Set (Set α)} (hT : T.Finite) : Absorbs M s (⋃₀ T) ↔ ∀ t ∈ T, Absorbs M s t := by simp [Absorbs, hT] protected lemma sUnion (hT : T.Finite) (hs : ∀ t ∈ T, Absorbs M s t) : Absorbs M s (⋃₀ T) := hT.absorbs_sUnion.2 hs @[simp] lemma _root_.absorbs_iUnion {ι : Sort*} [Finite ι] {t : ι → Set α} : Absorbs M s (⋃ i, t i) ↔ ∀ i, Absorbs M s (t i) := (finite_range t).absorbs_sUnion.trans forall_mem_range protected alias ⟨_, iUnion⟩ := absorbs_iUnion lemma _root_.Set.Finite.absorbs_biUnion {ι : Type*} {t : ι → Set α} {I : Set ι} (hI : I.Finite) : Absorbs M s (⋃ i ∈ I, t i) ↔ ∀ i ∈ I, Absorbs M s (t i) := by simp [Absorbs, hI] protected alias ⟨_, biUnion⟩ := Set.Finite.absorbs_biUnion @[simp] lemma _root_.absorbs_biUnion_finset {ι : Type*} {t : ι → Set α} {I : Finset ι} : Absorbs M s (⋃ i ∈ I, t i) ↔ ∀ i ∈ I, Absorbs M s (t i) := I.finite_toSet.absorbs_biUnion protected alias ⟨_, biUnion_finset⟩ := absorbs_biUnion_finset end SMul section AddZero variable {M E : Type*} [Bornology M] {s₁ s₂ t₁ t₂ : Set E} protected lemma add [AddZeroClass E] [DistribSMul M E] (h₁ : Absorbs M s₁ t₁) (h₂ : Absorbs M s₂ t₂) : Absorbs M (s₁ + s₂) (t₁ + t₂) := h₂.mp <| h₁.eventually.mono fun x hx₁ hx₂ ↦ by rw [smul_add]; exact add_subset_add hx₁ hx₂ protected lemma zero [Zero E] [SMulZeroClass M E] {s : Set E} (hs : 0 ∈ s) : Absorbs M s 0 := Eventually.of_forall fun _ ↦ zero_subset.2 <| zero_mem_smul_set hs end AddZero end Absorbs section GroupWithZero variable {G₀ α : Type*} [GroupWithZero G₀] [Bornology G₀] [MulAction G₀ α] {s t u : Set α} {S : Set (Set α)} @[simp]
protected lemma Absorbs.univ : Absorbs G₀ univ s := (eventually_ne_cobounded 0).mono fun a ha ↦ by rw [smul_set_univ₀ ha]; apply subset_univ
Mathlib/Topology/Bornology/Absorbs.lean
139
141
/- Copyright (c) 2021 Alex Kontorovich and Heather Macbeth and Marc Masdeu. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alex Kontorovich, Heather Macbeth, Marc Masdeu -/ import Mathlib.Analysis.Complex.Basic import Mathlib.Data.Fintype.Parity import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Defs /-! # The upper half plane and its automorphisms This file defines `UpperHalfPlane` to be the upper half plane in `ℂ`. We furthermore equip it with the structure of a `GLPos 2 ℝ` action by fractional linear transformations. We define the notation `ℍ` for the upper half plane available in the locale `UpperHalfPlane` so as not to conflict with the quaternions. -/ noncomputable section open Matrix Matrix.SpecialLinearGroup open scoped MatrixGroups /-- The open upper half plane, denoted as `ℍ` within the `UpperHalfPlane` namespace -/ def UpperHalfPlane := { point : ℂ // 0 < point.im } @[inherit_doc] scoped[UpperHalfPlane] notation "ℍ" => UpperHalfPlane open UpperHalfPlane namespace UpperHalfPlane /-- The coercion first into an element of `GL(2, ℝ)⁺`, then `GL(2, ℝ)` and finally a 2 × 2 matrix. This notation is scoped in namespace `UpperHalfPlane`. -/ scoped notation:1024 "↑ₘ" A:1024 => (((A : GL(2, ℝ)⁺) : GL (Fin 2) ℝ) : Matrix (Fin 2) (Fin 2) _) instance instCoeFun : CoeFun GL(2, ℝ)⁺ fun _ => Fin 2 → Fin 2 → ℝ where coe A := ↑ₘA /-- The coercion into an element of `GL(2, R)` and finally a 2 × 2 matrix over `R`. This is similar to `↑ₘ`, but without positivity requirements, and allows the user to specify the ring `R`, which can be useful to help Lean elaborate correctly. This notation is scoped in namespace `UpperHalfPlane`. -/ scoped notation:1024 "↑ₘ[" R "]" A:1024 => ((A : GL (Fin 2) R) : Matrix (Fin 2) (Fin 2) R) /-- Canonical embedding of the upper half-plane into `ℂ`. -/ @[coe] protected def coe (z : ℍ) : ℂ := z.1 instance : CoeOut ℍ ℂ := ⟨UpperHalfPlane.coe⟩ instance : Inhabited ℍ := ⟨⟨Complex.I, by simp⟩⟩ @[ext] theorem ext {a b : ℍ} (h : (a : ℂ) = b) : a = b := Subtype.eq h @[simp, norm_cast] theorem ext_iff' {a b : ℍ} : (a : ℂ) = b ↔ a = b := UpperHalfPlane.ext_iff.symm instance canLift : CanLift ℂ ℍ ((↑) : ℍ → ℂ) fun z => 0 < z.im := Subtype.canLift fun (z : ℂ) => 0 < z.im /-- Imaginary part -/ def im (z : ℍ) := (z : ℂ).im /-- Real part -/ def re (z : ℍ) := (z : ℂ).re /-- Extensionality lemma in terms of `UpperHalfPlane.re` and `UpperHalfPlane.im`. -/ theorem ext' {a b : ℍ} (hre : a.re = b.re) (him : a.im = b.im) : a = b := ext <| Complex.ext hre him /-- Constructor for `UpperHalfPlane`. It is useful if `⟨z, h⟩` makes Lean use a wrong typeclass instance. -/ def mk (z : ℂ) (h : 0 < z.im) : ℍ := ⟨z, h⟩ @[simp] theorem coe_im (z : ℍ) : (z : ℂ).im = z.im := rfl @[simp] theorem coe_re (z : ℍ) : (z : ℂ).re = z.re := rfl @[simp] theorem mk_re (z : ℂ) (h : 0 < z.im) : (mk z h).re = z.re := rfl @[simp] theorem mk_im (z : ℂ) (h : 0 < z.im) : (mk z h).im = z.im := rfl @[simp] theorem coe_mk (z : ℂ) (h : 0 < z.im) : (mk z h : ℂ) = z := rfl @[simp] lemma coe_mk_subtype {z : ℂ} (hz : 0 < z.im) : UpperHalfPlane.coe ⟨z, hz⟩ = z := by rfl @[simp] theorem mk_coe (z : ℍ) (h : 0 < (z : ℂ).im := z.2) : mk z h = z := rfl theorem re_add_im (z : ℍ) : (z.re + z.im * Complex.I : ℂ) = z := Complex.re_add_im z theorem im_pos (z : ℍ) : 0 < z.im := z.2 theorem im_ne_zero (z : ℍ) : z.im ≠ 0 := z.im_pos.ne' theorem ne_zero (z : ℍ) : (z : ℂ) ≠ 0 := mt (congr_arg Complex.im) z.im_ne_zero /-- Define I := √-1 as an element on the upper half plane. -/ def I : ℍ := ⟨Complex.I, by simp⟩ @[simp] lemma I_im : I.im = 1 := rfl @[simp] lemma I_re : I.re = 0 := rfl @[simp, norm_cast] lemma coe_I : I = Complex.I := rfl end UpperHalfPlane namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: `UpperHalfPlane.im`. -/ @[positivity UpperHalfPlane.im _] def evalUpperHalfPlaneIm : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(UpperHalfPlane.im $a) => assertInstancesCommute pure (.positive q(@UpperHalfPlane.im_pos $a)) | _, _, _ => throwError "not UpperHalfPlane.im" /-- Extension for the `positivity` tactic: `UpperHalfPlane.coe`. -/ @[positivity UpperHalfPlane.coe _] def evalUpperHalfPlaneCoe : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℂ), ~q(UpperHalfPlane.coe $a) => assertInstancesCommute pure (.nonzero q(@UpperHalfPlane.ne_zero $a)) | _, _, _ => throwError "not UpperHalfPlane.coe" end Mathlib.Meta.Positivity namespace UpperHalfPlane theorem normSq_pos (z : ℍ) : 0 < Complex.normSq (z : ℂ) := by rw [Complex.normSq_pos]; exact z.ne_zero theorem normSq_ne_zero (z : ℍ) : Complex.normSq (z : ℂ) ≠ 0 := (normSq_pos z).ne' theorem im_inv_neg_coe_pos (z : ℍ) : 0 < (-z : ℂ)⁻¹.im := by simpa [neg_div] using div_pos z.property (normSq_pos z) lemma ne_nat (z : ℍ) : ∀ n : ℕ, z.1 ≠ n := by intro n have h1 := z.2 aesop lemma ne_int (z : ℍ) : ∀ n : ℤ, z.1 ≠ n := by intro n have h1 := z.2 aesop /-- Numerator of the formula for a fractional linear transformation -/ def num (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := g 0 0 * z + g 0 1 /-- Denominator of the formula for a fractional linear transformation -/ def denom (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := g 1 0 * z + g 1 1 theorem linear_ne_zero (cd : Fin 2 → ℝ) (z : ℍ) (h : cd ≠ 0) : (cd 0 : ℂ) * z + cd 1 ≠ 0 := by contrapose! h have : cd 0 = 0 := by -- we will need this twice apply_fun Complex.im at h simpa only [z.im_ne_zero, Complex.add_im, add_zero, coe_im, zero_mul, or_false, Complex.ofReal_im, Complex.zero_im, Complex.mul_im, mul_eq_zero] using h simp only [this, zero_mul, Complex.ofReal_zero, zero_add, Complex.ofReal_eq_zero] at h ext i fin_cases i <;> assumption theorem denom_ne_zero (g : GL(2, ℝ)⁺) (z : ℍ) : denom g z ≠ 0 := by intro H have DET := (mem_glpos _).1 g.prop simp only [GeneralLinearGroup.val_det_apply] at DET obtain hg | hz : g 1 0 = 0 ∨ z.im = 0 := by simpa [num, denom] using congr_arg Complex.im H · simp only [hg, Complex.ofReal_zero, denom, zero_mul, zero_add, Complex.ofReal_eq_zero] at H simp only [Matrix.det_fin_two g.1.1, H, hg, mul_zero, sub_zero, lt_self_iff_false] at DET · exact z.prop.ne' hz theorem normSq_denom_pos (g : GL(2, ℝ)⁺) (z : ℍ) : 0 < Complex.normSq (denom g z) := Complex.normSq_pos.mpr (denom_ne_zero g z) theorem normSq_denom_ne_zero (g : GL(2, ℝ)⁺) (z : ℍ) : Complex.normSq (denom g z) ≠ 0 := ne_of_gt (normSq_denom_pos g z) /-- Fractional linear transformation, also known as the Moebius transformation -/ def smulAux' (g : GL(2, ℝ)⁺) (z : ℍ) : ℂ := num g z / denom g z theorem smulAux'_im (g : GL(2, ℝ)⁺) (z : ℍ) : (smulAux' g z).im = det ↑ₘg * z.im / Complex.normSq (denom g z) := by simp only [smulAux', num, denom, Complex.div_im, Complex.add_im, Complex.mul_im, Complex.ofReal_re, coe_im, Complex.ofReal_im, coe_re, zero_mul, add_zero, Complex.add_re, Complex.mul_re, sub_zero, ← sub_div, g.1.1.det_fin_two] ring /-- Fractional linear transformation, also known as the Moebius transformation -/ def smulAux (g : GL(2, ℝ)⁺) (z : ℍ) : ℍ := mk (smulAux' g z) <| by rw [smulAux'_im] convert mul_pos ((mem_glpos _).1 g.prop) (div_pos z.im_pos (Complex.normSq_pos.mpr (denom_ne_zero g z))) using 1 simp only [GeneralLinearGroup.val_det_apply] ring theorem denom_cocycle (x y : GL(2, ℝ)⁺) (z : ℍ) : denom (x * y) z = denom x (smulAux y z) * denom y z := by change _ = (_ * (_ / _) + _) * _ field_simp [denom_ne_zero] simp only [denom, Subgroup.coe_mul, Fin.isValue, Units.val_mul, mul_apply, Fin.sum_univ_succ, Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, Fin.succ_zero_eq_one, Complex.ofReal_add, Complex.ofReal_mul, num] ring theorem mul_smul' (x y : GL(2, ℝ)⁺) (z : ℍ) : smulAux (x * y) z = smulAux x (smulAux y z) := by ext1 change _ / _ = (_ * (_ / _) + _) / _ rw [denom_cocycle] field_simp [denom_ne_zero] simp only [num, Subgroup.coe_mul, Fin.isValue, Units.val_mul, mul_apply, Fin.sum_univ_succ, Finset.univ_unique, Fin.default_eq_zero, Finset.sum_singleton, Fin.succ_zero_eq_one, Complex.ofReal_add, Complex.ofReal_mul, denom] ring /-- The action of `GLPos 2 ℝ` on the upper half-plane by fractional linear transformations. -/ instance : MulAction GL(2, ℝ)⁺ ℍ where smul := smulAux one_smul z := by ext1 change _ / _ = _ simp [num, denom] mul_smul := mul_smul' instance SLAction {R : Type*} [CommRing R] [Algebra R ℝ] : MulAction SL(2, R) ℍ := MulAction.compHom ℍ <| SpecialLinearGroup.toGLPos.comp <| map (algebraMap R ℝ) -- Porting note: in the statement, we used to have coercions `↑· : ℝ` -- rather than `algebraMap R ℝ ·`. theorem specialLinearGroup_apply {R : Type*} [CommRing R] [Algebra R ℝ] (g : SL(2, R)) (z : ℍ) : g • z = mk (((algebraMap R ℝ (g 0 0) : ℂ) * z + (algebraMap R ℝ (g 0 1) : ℂ)) / ((algebraMap R ℝ (g 1 0) : ℂ) * z + (algebraMap R ℝ (g 1 1) : ℂ))) (g • z).property := rfl variable (g : GL(2, ℝ)⁺) (z : ℍ) @[simp] theorem coe_smul : ↑(g • z) = num g z / denom g z := rfl @[simp] theorem re_smul : (g • z).re = (num g z / denom g z).re := rfl theorem im_smul : (g • z).im = (num g z / denom g z).im := rfl theorem im_smul_eq_div_normSq : (g • z).im = det ↑ₘg * z.im / Complex.normSq (denom g z) := smulAux'_im g z theorem c_mul_im_sq_le_normSq_denom : (g 1 0 * z.im) ^ 2 ≤ Complex.normSq (denom g z) := by set c := g 1 0 set d := g 1 1 calc (c * z.im) ^ 2 ≤ (c * z.im) ^ 2 + (c * z.re + d) ^ 2 := by nlinarith _ = Complex.normSq (denom g z) := by dsimp [c, d, denom, Complex.normSq]; ring @[simp] theorem neg_smul : -g • z = g • z := by ext1 change _ / _ = _ / _ field_simp [denom_ne_zero] simp only [num, denom, Complex.ofReal_neg, neg_mul, GLPos.coe_neg_GL, Units.val_neg, neg_apply] ring_nf lemma denom_one : denom 1 z = 1 := by simp [denom] section PosRealAction instance posRealAction : MulAction { x : ℝ // 0 < x } ℍ where smul x z := mk ((x : ℝ) • (z : ℂ)) <| by simpa using mul_pos x.2 z.2 one_smul _ := Subtype.ext <| one_smul _ _ mul_smul x y z := Subtype.ext <| mul_smul (x : ℝ) y (z : ℂ) variable (x : { x : ℝ // 0 < x }) (z : ℍ) @[simp] theorem coe_pos_real_smul : ↑(x • z) = (x : ℝ) • (z : ℂ) := rfl @[simp] theorem pos_real_im : (x • z).im = x * z.im := Complex.smul_im _ _ @[simp] theorem pos_real_re : (x • z).re = x * z.re := Complex.smul_re _ _ end PosRealAction section RealAddAction instance : AddAction ℝ ℍ where vadd x z := mk (x + z) <| by simpa using z.im_pos zero_vadd _ := Subtype.ext <| by simp [HVAdd.hVAdd] add_vadd x y z := Subtype.ext <| by simp [HVAdd.hVAdd, add_assoc] variable (x : ℝ) (z : ℍ) @[simp] theorem coe_vadd : ↑(x +ᵥ z) = (x + z : ℂ) := rfl @[simp] theorem vadd_re : (x +ᵥ z).re = x + z.re := rfl @[simp] theorem vadd_im : (x +ᵥ z).im = z.im := zero_add _ end RealAddAction /- these next few lemmas are *not* flagged `@simp` because of the constructors on the RHS; instead we use the versions with coercions to `ℂ` as simp lemmas instead. -/ theorem modular_S_smul (z : ℍ) : ModularGroup.S • z = mk (-z : ℂ)⁻¹ z.im_inv_neg_coe_pos := by rw [specialLinearGroup_apply]; simp [ModularGroup.S, neg_div, inv_neg, toGL] theorem modular_T_zpow_smul (z : ℍ) (n : ℤ) : ModularGroup.T ^ n • z = (n : ℝ) +ᵥ z := by rw [UpperHalfPlane.ext_iff, coe_vadd, add_comm, specialLinearGroup_apply, coe_mk] simp [toGL, ModularGroup.coe_T_zpow, of_apply, cons_val_zero, algebraMap.coe_one, Complex.ofReal_one, one_mul, cons_val_one, head_cons, algebraMap.coe_zero, zero_mul, zero_add, div_one] theorem modular_T_smul (z : ℍ) : ModularGroup.T • z = (1 : ℝ) +ᵥ z := by simpa only [Int.cast_one] using modular_T_zpow_smul z 1 theorem exists_SL2_smul_eq_of_apply_zero_one_eq_zero (g : SL(2, ℝ)) (hc : g 1 0 = 0) : ∃ (u : { x : ℝ // 0 < x }) (v : ℝ), (g • · : ℍ → ℍ) = (v +ᵥ ·) ∘ (u • ·) := by obtain ⟨a, b, ha, rfl⟩ := g.fin_two_exists_eq_mk_of_apply_zero_one_eq_zero hc refine ⟨⟨_, mul_self_pos.mpr ha⟩, b * a, ?_⟩ ext1 ⟨z, hz⟩; ext1 suffices ↑a * z * a + b * a = b * a + a * a * z by simpa [toGL, specialLinearGroup_apply, add_mul] ring theorem exists_SL2_smul_eq_of_apply_zero_one_ne_zero (g : SL(2, ℝ)) (hc : g 1 0 ≠ 0) : ∃ (u : { x : ℝ // 0 < x }) (v w : ℝ), (g • · : ℍ → ℍ) = (w +ᵥ ·) ∘ (ModularGroup.S • · : ℍ → ℍ) ∘ (v +ᵥ · : ℍ → ℍ) ∘ (u • · : ℍ → ℍ) := by have h_denom := denom_ne_zero g induction g using Matrix.SpecialLinearGroup.fin_two_induction with | _ a b c d h => ?_ replace hc : c ≠ 0 := by simpa using hc refine ⟨⟨_, mul_self_pos.mpr hc⟩, c * d, a / c, ?_⟩ ext1 ⟨z, hz⟩; ext1 suffices (↑a * z + b) / (↑c * z + d) = a / c - (c * d + ↑c * ↑c * z)⁻¹ by simpa only [modular_S_smul, inv_neg, Function.comp_apply, coe_vadd, Complex.ofReal_mul, coe_pos_real_smul, Complex.real_smul, Complex.ofReal_div, coe_mk] replace hc : (c : ℂ) ≠ 0 := by norm_cast replace h_denom : ↑c * z + d ≠ 0 := by simpa using h_denom ⟨z, hz⟩ have h_aux : (c : ℂ) * d + ↑c * ↑c * z ≠ 0 := by rw [mul_assoc, ← mul_add, add_comm] exact mul_ne_zero hc h_denom replace h : (a * d - b * c : ℂ) = (1 : ℂ) := by norm_cast field_simp linear_combination (-(z * (c : ℂ) ^ 2) - c * d) * h end UpperHalfPlane namespace ModularGroup -- results specific to `SL(2, ℤ)` section ModularScalarTowers /-- Canonical embedding of `SL(2, ℤ)` into `GL(2, ℝ)⁺`. -/ @[coe] def coe (g : SL(2, ℤ)) : GL(2, ℝ)⁺ := ((g : SL(2, ℝ)) : GL(2, ℝ)⁺) @[deprecated (since := "2024-11-19")] noncomputable alias coe' := coe instance : Coe SL(2, ℤ) GL(2, ℝ)⁺ := ⟨coe⟩ @[simp] theorem coe_apply_complex {g : SL(2, ℤ)} {i j : Fin 2} : (Units.val <| Subtype.val <| coe g) i j = (Subtype.val g i j : ℂ) := rfl @[deprecated (since := "2024-11-19")] alias coe'_apply_complex := coe_apply_complex @[simp] theorem det_coe {g : SL(2, ℤ)} : det (Units.val <| Subtype.val <| coe g) = 1 := by simp only [SpecialLinearGroup.coe_GLPos_coe_GL_coe_matrix, SpecialLinearGroup.det_coe, coe] @[deprecated (since := "2024-11-19")] alias det_coe' := det_coe lemma coe_one : coe 1 = 1 := by simp only [coe, map_one] instance SLOnGLPos : SMul SL(2, ℤ) GL(2, ℝ)⁺ := ⟨fun s g => s * g⟩ theorem SLOnGLPos_smul_apply (s : SL(2, ℤ)) (g : GL(2, ℝ)⁺) (z : ℍ) : (s • g) • z = ((s : GL(2, ℝ)⁺) * g) • z := rfl instance SL_to_GL_tower : IsScalarTower SL(2, ℤ) GL(2, ℝ)⁺ ℍ where smul_assoc s g z := by simp only [SLOnGLPos_smul_apply] apply mul_smul' end ModularScalarTowers section SLModularAction
variable (g : SL(2, ℤ)) (z : ℍ) @[simp]
Mathlib/Analysis/Complex/UpperHalfPlane/Basic.lean
451
453
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Mario Carneiro, Johan Commelin -/ import Mathlib.NumberTheory.Padics.PadicNumbers import Mathlib.RingTheory.DiscreteValuationRing.Basic /-! # p-adic integers This file defines the `p`-adic integers `ℤ_[p]` as the subtype of `ℚ_[p]` with norm `≤ 1`. We show that `ℤ_[p]` * is complete, * is nonarchimedean, * is a normed ring, * is a local ring, and * is a discrete valuation ring. The relation between `ℤ_[p]` and `ZMod p` is established in another file. ## Important definitions * `PadicInt` : the type of `p`-adic integers ## Notation We introduce the notation `ℤ_[p]` for the `p`-adic integers. ## Implementation notes Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically by taking `[Fact p.Prime]` as a type class argument. Coercions into `ℤ_[p]` are set up to work with the `norm_cast` tactic. ## References * [F. Q. Gouvêa, *p-adic numbers*][gouvea1997] * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/P-adic_number> ## Tags p-adic, p adic, padic, p-adic integer -/ open Padic Metric IsLocalRing noncomputable section variable (p : ℕ) [hp : Fact p.Prime] /-- The `p`-adic integers `ℤ_[p]` are the `p`-adic numbers with norm `≤ 1`. -/ def PadicInt : Type := {x : ℚ_[p] // ‖x‖ ≤ 1} /-- The ring of `p`-adic integers. -/ notation "ℤ_[" p "]" => PadicInt p namespace PadicInt variable {p} {x y : ℤ_[p]} /-! ### Ring structure and coercion to `ℚ_[p]` -/ instance : Coe ℤ_[p] ℚ_[p] := ⟨Subtype.val⟩ theorem ext {x y : ℤ_[p]} : (x : ℚ_[p]) = y → x = y := Subtype.ext variable (p) /-- The `p`-adic integers as a subring of `ℚ_[p]`. -/ def subring : Subring ℚ_[p] where carrier := { x : ℚ_[p] | ‖x‖ ≤ 1 } zero_mem' := by norm_num one_mem' := by norm_num add_mem' hx hy := (padicNormE.nonarchimedean _ _).trans <| max_le_iff.2 ⟨hx, hy⟩ mul_mem' hx hy := (padicNormE.mul _ _).trans_le <| mul_le_one₀ hx (norm_nonneg _) hy neg_mem' hx := (norm_neg _).trans_le hx @[simp] theorem mem_subring_iff {x : ℚ_[p]} : x ∈ subring p ↔ ‖x‖ ≤ 1 := Iff.rfl variable {p} instance instCommRing : CommRing ℤ_[p] := inferInstanceAs <| CommRing (subring p) instance : Inhabited ℤ_[p] := ⟨0⟩ @[simp] theorem mk_zero {h} : (⟨0, h⟩ : ℤ_[p]) = (0 : ℤ_[p]) := rfl @[simp, norm_cast] theorem coe_add (z1 z2 : ℤ_[p]) : ((z1 + z2 : ℤ_[p]) : ℚ_[p]) = z1 + z2 := rfl @[simp, norm_cast] theorem coe_mul (z1 z2 : ℤ_[p]) : ((z1 * z2 : ℤ_[p]) : ℚ_[p]) = z1 * z2 := rfl @[simp, norm_cast] theorem coe_neg (z1 : ℤ_[p]) : ((-z1 : ℤ_[p]) : ℚ_[p]) = -z1 := rfl @[simp, norm_cast] theorem coe_sub (z1 z2 : ℤ_[p]) : ((z1 - z2 : ℤ_[p]) : ℚ_[p]) = z1 - z2 := rfl @[simp, norm_cast] theorem coe_one : ((1 : ℤ_[p]) : ℚ_[p]) = 1 := rfl @[simp, norm_cast] theorem coe_zero : ((0 : ℤ_[p]) : ℚ_[p]) = 0 := rfl @[simp] lemma coe_eq_zero : (x : ℚ_[p]) = 0 ↔ x = 0 := by rw [← coe_zero, Subtype.coe_inj] lemma coe_ne_zero : (x : ℚ_[p]) ≠ 0 ↔ x ≠ 0 := coe_eq_zero.not @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℤ_[p]) : ℚ_[p]) = n := rfl @[simp, norm_cast] theorem coe_intCast (z : ℤ) : ((z : ℤ_[p]) : ℚ_[p]) = z := rfl /-- The coercion from `ℤ_[p]` to `ℚ_[p]` as a ring homomorphism. -/ def Coe.ringHom : ℤ_[p] →+* ℚ_[p] := (subring p).subtype @[simp, norm_cast] theorem coe_pow (x : ℤ_[p]) (n : ℕ) : (↑(x ^ n) : ℚ_[p]) = (↑x : ℚ_[p]) ^ n := rfl theorem mk_coe (k : ℤ_[p]) : (⟨k, k.2⟩ : ℤ_[p]) = k := by simp /-- The inverse of a `p`-adic integer with norm equal to `1` is also a `p`-adic integer. Otherwise, the inverse is defined to be `0`. -/ def inv : ℤ_[p] → ℤ_[p] | ⟨k, _⟩ => if h : ‖k‖ = 1 then ⟨k⁻¹, by simp [h]⟩ else 0 instance : CharZero ℤ_[p] where cast_injective m n h := Nat.cast_injective (R := ℚ_[p]) (by rw [Subtype.ext_iff] at h; norm_cast at h) @[norm_cast] theorem intCast_eq (z1 z2 : ℤ) : (z1 : ℤ_[p]) = z2 ↔ z1 = z2 := by simp /-- A sequence of integers that is Cauchy with respect to the `p`-adic norm converges to a `p`-adic integer. -/ def ofIntSeq (seq : ℕ → ℤ) (h : IsCauSeq (padicNorm p) fun n => seq n) : ℤ_[p] := ⟨⟦⟨_, h⟩⟧, show ↑(PadicSeq.norm _) ≤ (1 : ℝ) by rw [PadicSeq.norm] split_ifs with hne <;> norm_cast apply padicNorm.of_int⟩ /-! ### Instances We now show that `ℤ_[p]` is a * complete metric space * normed ring * integral domain -/ variable (p) instance : MetricSpace ℤ_[p] := Subtype.metricSpace instance : IsUltrametricDist ℤ_[p] := IsUltrametricDist.subtype _ instance completeSpace : CompleteSpace ℤ_[p] := have : IsClosed { x : ℚ_[p] | ‖x‖ ≤ 1 } := isClosed_le continuous_norm continuous_const this.completeSpace_coe instance : Norm ℤ_[p] := ⟨fun z => ‖(z : ℚ_[p])‖⟩ variable {p} in theorem norm_def {z : ℤ_[p]} : ‖z‖ = ‖(z : ℚ_[p])‖ := rfl instance : NormedCommRing ℤ_[p] where __ := instCommRing dist_eq := fun ⟨_, _⟩ ⟨_, _⟩ ↦ rfl norm_mul_le := by simp [norm_def] instance : NormOneClass ℤ_[p] := ⟨norm_def.trans norm_one⟩ instance : NormMulClass ℤ_[p] := ⟨fun x y ↦ by simp [norm_def]⟩ instance : IsDomain ℤ_[p] := NoZeroDivisors.to_isDomain _ variable {p} /-! ### Norm -/ theorem norm_le_one (z : ℤ_[p]) : ‖z‖ ≤ 1 := z.2 theorem nonarchimedean (q r : ℤ_[p]) : ‖q + r‖ ≤ max ‖q‖ ‖r‖ := padicNormE.nonarchimedean _ _ theorem norm_add_eq_max_of_ne {q r : ℤ_[p]} : ‖q‖ ≠ ‖r‖ → ‖q + r‖ = max ‖q‖ ‖r‖ := padicNormE.add_eq_max_of_ne theorem norm_eq_of_norm_add_lt_right {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z2‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_right) h theorem norm_eq_of_norm_add_lt_left {z1 z2 : ℤ_[p]} (h : ‖z1 + z2‖ < ‖z1‖) : ‖z1‖ = ‖z2‖ := by_contra fun hne => not_lt_of_ge (by rw [norm_add_eq_max_of_ne hne]; apply le_max_left) h @[simp] theorem padic_norm_e_of_padicInt (z : ℤ_[p]) : ‖(z : ℚ_[p])‖ = ‖z‖ := by simp [norm_def] theorem norm_intCast_eq_padic_norm (z : ℤ) : ‖(z : ℤ_[p])‖ = ‖(z : ℚ_[p])‖ := by simp [norm_def] @[simp] theorem norm_eq_padic_norm {q : ℚ_[p]} (hq : ‖q‖ ≤ 1) : @norm ℤ_[p] _ ⟨q, hq⟩ = ‖q‖ := rfl @[simp] theorem norm_p : ‖(p : ℤ_[p])‖ = (p : ℝ)⁻¹ := padicNormE.norm_p theorem norm_p_pow (n : ℕ) : ‖(p : ℤ_[p]) ^ n‖ = (p : ℝ) ^ (-n : ℤ) := by simp private def cauSeq_to_rat_cauSeq (f : CauSeq ℤ_[p] norm) : CauSeq ℚ_[p] fun a => ‖a‖ := ⟨fun n => f n, fun _ hε => by simpa [norm, norm_def] using f.cauchy hε⟩ variable (p) instance complete : CauSeq.IsComplete ℤ_[p] norm := ⟨fun f => have hqn : ‖CauSeq.lim (cauSeq_to_rat_cauSeq f)‖ ≤ 1 := padicNormE_lim_le zero_lt_one fun _ => norm_le_one _ ⟨⟨_, hqn⟩, fun ε => by simpa [norm, norm_def] using CauSeq.equiv_lim (cauSeq_to_rat_cauSeq f) ε⟩⟩ theorem exists_pow_neg_lt {ε : ℝ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℝ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := exists_nat_gt ε⁻¹ use k rw [← inv_lt_inv₀ hε (zpow_pos _ _)] · rw [zpow_neg, inv_inv, zpow_natCast] apply lt_of_lt_of_le hk norm_cast apply le_of_lt convert Nat.lt_pow_self _ using 1 exact hp.1.one_lt · exact mod_cast hp.1.pos theorem exists_pow_neg_lt_rat {ε : ℚ} (hε : 0 < ε) : ∃ k : ℕ, (p : ℚ) ^ (-(k : ℤ)) < ε := by obtain ⟨k, hk⟩ := @exists_pow_neg_lt p _ ε (mod_cast hε) use k rw [show (p : ℝ) = (p : ℚ) by simp] at hk exact mod_cast hk variable {p} theorem norm_int_lt_one_iff_dvd (k : ℤ) : ‖(k : ℤ_[p])‖ < 1 ↔ (p : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ < 1 ↔ ↑p ∣ k by rwa [norm_intCast_eq_padic_norm] padicNormE.norm_int_lt_one_iff_dvd k theorem norm_int_le_pow_iff_dvd {k : ℤ} {n : ℕ} : ‖(k : ℤ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k := suffices ‖(k : ℚ_[p])‖ ≤ (p : ℝ) ^ (-n : ℤ) ↔ (p ^ n : ℤ) ∣ k by simpa [norm_intCast_eq_padic_norm] padicNormE.norm_int_le_pow_iff_dvd _ _ /-! ### Valuation on `ℤ_[p]` -/ lemma valuation_coe_nonneg : 0 ≤ (x : ℚ_[p]).valuation := by obtain rfl | hx := eq_or_ne x 0 · simp have := x.2 rwa [Padic.norm_eq_zpow_neg_valuation <| coe_ne_zero.2 hx, zpow_le_one_iff_right₀, neg_nonpos] at this exact mod_cast hp.out.one_lt /-- `PadicInt.valuation` lifts the `p`-adic valuation on `ℚ` to `ℤ_[p]`. -/ def valuation (x : ℤ_[p]) : ℕ := (x : ℚ_[p]).valuation.toNat @[simp, norm_cast] lemma valuation_coe (x : ℤ_[p]) : (x : ℚ_[p]).valuation = x.valuation := by simp [valuation, valuation_coe_nonneg]
@[simp] lemma valuation_zero : valuation (0 : ℤ_[p]) = 0 := by simp [valuation] @[simp] lemma valuation_one : valuation (1 : ℤ_[p]) = 0 := by simp [valuation] @[simp] lemma valuation_p : valuation (p : ℤ_[p]) = 1 := by simp [valuation] lemma le_valuation_add (hxy : x + y ≠ 0) : min x.valuation y.valuation ≤ (x + y).valuation := by
Mathlib/NumberTheory/Padics/PadicIntegers.lean
276
281
/- Copyright (c) 2023 Amelia Livingston. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Amelia Livingston, Joël Riou -/ import Mathlib.Algebra.Homology.ShortComplex.ModuleCat import Mathlib.RepresentationTheory.GroupCohomology.Basic import Mathlib.RepresentationTheory.Invariants /-! # The low-degree cohomology of a `k`-linear `G`-representation Let `k` be a commutative ring and `G` a group. This file gives simple expressions for the group cohomology of a `k`-linear `G`-representation `A` in degrees 0, 1 and 2. In `RepresentationTheory.GroupCohomology.Basic`, we define the `n`th group cohomology of `A` to be the cohomology of a complex `inhomogeneousCochains A`, whose objects are `(Fin n → G) → A`; this is unnecessarily unwieldy in low degree. Moreover, cohomology of a complex is defined as an abstract cokernel, whereas the definitions here are explicit quotients of cocycles by coboundaries. We also show that when the representation on `A` is trivial, `H¹(G, A) ≃ Hom(G, A)`. Given an additive or multiplicative abelian group `A` with an appropriate scalar action of `G`, we provide support for turning a function `f : G → A` satisfying the 1-cocycle identity into an element of the `oneCocycles` of the representation on `A` (or `Additive A`) corresponding to the scalar action. We also do this for 1-coboundaries, 2-cocycles and 2-coboundaries. The multiplicative case, starting with the section `IsMulCocycle`, just mirrors the additive case; unfortunately `@[to_additive]` can't deal with scalar actions. The file also contains an identification between the definitions in `RepresentationTheory.GroupCohomology.Basic`, `groupCohomology.cocycles A n` and `groupCohomology A n`, and the `nCocycles` and `Hn A` in this file, for `n = 0, 1, 2`. ## Main definitions * `groupCohomology.H0 A`: the invariants `Aᴳ` of the `G`-representation on `A`. * `groupCohomology.H1 A`: 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). * `groupCohomology.H2 A`: 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). * `groupCohomology.H1LequivOfIsTrivial`: the isomorphism `H¹(G, A) ≃ Hom(G, A)` when the representation on `A` is trivial. * `groupCohomology.isoHn` for `n = 0, 1, 2`: an isomorphism `groupCohomology A n ≅ groupCohomology.Hn A`. ## TODO * The relationship between `H2` and group extensions * The inflation-restriction exact sequence * Nonabelian group cohomology -/ universe v u noncomputable section open CategoryTheory Limits Representation variable {k G : Type u} [CommRing k] [Group G] (A : Rep k G) namespace groupCohomology section Cochains /-- The 0th object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `A` as a `k`-module. -/ def zeroCochainsLequiv : (inhomogeneousCochains A).X 0 ≃ₗ[k] A := LinearEquiv.funUnique (Fin 0 → G) k A /-- The 1st object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G, A)` as a `k`-module. -/ def oneCochainsLequiv : (inhomogeneousCochains A).X 1 ≃ₗ[k] G → A := LinearEquiv.funCongrLeft k A (Equiv.funUnique (Fin 1) G).symm /-- The 2nd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G², A)` as a `k`-module. -/ def twoCochainsLequiv : (inhomogeneousCochains A).X 2 ≃ₗ[k] G × G → A := LinearEquiv.funCongrLeft k A <| (piFinTwoEquiv fun _ => G).symm /-- The 3rd object in the complex of inhomogeneous cochains of `A : Rep k G` is isomorphic to `Fun(G³, A)` as a `k`-module. -/ def threeCochainsLequiv : (inhomogeneousCochains A).X 3 ≃ₗ[k] G × G × G → A := LinearEquiv.funCongrLeft k A <| ((Fin.consEquiv _).symm.trans ((Equiv.refl G).prodCongr (piFinTwoEquiv fun _ => G))).symm end Cochains section Differentials /-- The 0th differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `A → Fun(G, A)`. It sends `(a, g) ↦ ρ_A(g)(a) - a.` -/ @[simps] def dZero : A →ₗ[k] G → A where toFun m g := A.ρ g m - m map_add' x y := funext fun g => by simp only [map_add, add_sub_add_comm]; rfl map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_sub] theorem dZero_ker_eq_invariants : LinearMap.ker (dZero A) = invariants A.ρ := by ext x simp only [LinearMap.mem_ker, mem_invariants, ← @sub_eq_zero _ _ _ x, funext_iff] rfl @[simp] theorem dZero_eq_zero [A.IsTrivial] : dZero A = 0 := by ext simp only [dZero_apply, isTrivial_apply, sub_self, LinearMap.zero_apply, Pi.zero_apply] lemma dZero_comp_subtype : dZero A ∘ₗ A.ρ.invariants.subtype = 0 := by ext ⟨x, hx⟩ g replace hx := hx g rw [← sub_eq_zero] at hx exact hx /-- The 1st differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G, A) → Fun(G × G, A)`. It sends `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ @[simps] def dOne : (G → A) →ₗ[k] G × G → A where toFun f g := A.ρ g.1 (f g.2) - f (g.1 * g.2) + f g.1 map_add' x y := funext fun g => by dsimp; rw [map_add, add_add_add_comm, add_sub_add_comm] map_smul' r x := funext fun g => by dsimp; rw [map_smul, smul_add, smul_sub] /-- The 2nd differential in the complex of inhomogeneous cochains of `A : Rep k G`, as a `k`-linear map `Fun(G × G, A) → Fun(G × G × G, A)`. It sends `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ @[simps] def dTwo : (G × G → A) →ₗ[k] G × G × G → A where toFun f g := A.ρ g.1 (f (g.2.1, g.2.2)) - f (g.1 * g.2.1, g.2.2) + f (g.1, g.2.1 * g.2.2) - f (g.1, g.2.1) map_add' x y := funext fun g => by dsimp rw [map_add, add_sub_add_comm (A.ρ _ _), add_sub_assoc, add_sub_add_comm, add_add_add_comm, add_sub_assoc, add_sub_assoc] map_smul' r x := funext fun g => by dsimp; simp only [map_smul, smul_add, smul_sub] /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dZero` gives a simpler expression for the 0th differential: that is, the following square commutes: ``` C⁰(G, A) ---d⁰---> C¹(G, A) | | | | | | v v A ---- dZero ---> Fun(G, A) ``` where the vertical arrows are `zeroCochainsLequiv` and `oneCochainsLequiv` respectively. -/ theorem dZero_comp_eq : dZero A ∘ₗ (zeroCochainsLequiv A) = oneCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 0 1).hom := by ext x y show A.ρ y (x default) - x default = _ + ({0} : Finset _).sum _ simp_rw [Fin.val_eq_zero, zero_add, pow_one, neg_smul, one_smul, Finset.sum_singleton, sub_eq_add_neg] rcongr i <;> exact Fin.elim0 i /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dOne` gives a simpler expression for the 1st differential: that is, the following square commutes: ``` C¹(G, A) ---d¹-----> C²(G, A) | | | | | | v v Fun(G, A) -dOne-> Fun(G × G, A) ``` where the vertical arrows are `oneCochainsLequiv` and `twoCochainsLequiv` respectively. -/ theorem dOne_comp_eq : dOne A ∘ₗ oneCochainsLequiv A = twoCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 1 2).hom := by ext x y show A.ρ y.1 (x _) - x _ + x _ = _ + _ rw [Fin.sum_univ_two] simp only [Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Nat.one_add, neg_one_sq, sub_eq_add_neg, add_assoc] rcongr i <;> rw [Subsingleton.elim i 0] <;> rfl /-- Let `C(G, A)` denote the complex of inhomogeneous cochains of `A : Rep k G`. This lemma says `dTwo` gives a simpler expression for the 2nd differential: that is, the following square commutes: ``` C²(G, A) -------d²-----> C³(G, A) | | | | | | v v Fun(G × G, A) --dTwo--> Fun(G × G × G, A) ``` where the vertical arrows are `twoCochainsLequiv` and `threeCochainsLequiv` respectively. -/ theorem dTwo_comp_eq : dTwo A ∘ₗ twoCochainsLequiv A = threeCochainsLequiv A ∘ₗ ((inhomogeneousCochains A).d 2 3).hom := by ext x y show A.ρ y.1 (x _) - x _ + x _ - x _ = _ + _ dsimp rw [Fin.sum_univ_three] simp only [sub_eq_add_neg, add_assoc, Fin.val_zero, zero_add, pow_one, neg_smul, one_smul, Fin.val_one, Fin.val_two, pow_succ' (-1 : k) 2, neg_sq, Nat.one_add, one_pow, mul_one] rcongr i <;> fin_cases i <;> rfl theorem dOne_comp_dZero : dOne A ∘ₗ dZero A = 0 := by ext x g simp only [LinearMap.coe_comp, Function.comp_apply, dOne_apply A, dZero_apply A, map_sub, map_mul, Module.End.mul_apply, sub_sub_sub_cancel_left, sub_add_sub_cancel, sub_self] rfl theorem dTwo_comp_dOne : dTwo A ∘ₗ dOne A = 0 := by show (ModuleCat.ofHom (dOne A) ≫ ModuleCat.ofHom (dTwo A)).hom = _ have h1 := congr_arg ModuleCat.ofHom (dOne_comp_eq A) have h2 := congr_arg ModuleCat.ofHom (dTwo_comp_eq A) simp only [ModuleCat.ofHom_comp, ModuleCat.ofHom_comp, ← LinearEquiv.toModuleIso_hom] at h1 h2 simp only [(Iso.eq_inv_comp _).2 h2, (Iso.eq_inv_comp _).2 h1, ModuleCat.ofHom_hom, ModuleCat.hom_ofHom, Category.assoc, Iso.hom_inv_id_assoc, HomologicalComplex.d_comp_d_assoc, zero_comp, comp_zero, ModuleCat.hom_zero] open ShortComplex /-- The (exact) short complex `A.ρ.invariants ⟶ A ⟶ (G → A)`. -/ def shortComplexH0 : ShortComplex (ModuleCat k) := moduleCatMk _ _ (dZero_comp_subtype A) /-- The short complex `A --dZero--> Fun(G, A) --dOne--> Fun(G × G, A)`. -/ def shortComplexH1 : ShortComplex (ModuleCat k) := moduleCatMk (dZero A) (dOne A) (dOne_comp_dZero A) /-- The short complex `Fun(G, A) --dOne--> Fun(G × G, A) --dTwo--> Fun(G × G × G, A)`. -/ def shortComplexH2 : ShortComplex (ModuleCat k) := moduleCatMk (dOne A) (dTwo A) (dTwo_comp_dOne A) end Differentials section Cocycles /-- The 1-cocycles `Z¹(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def oneCocycles : Submodule k (G → A) := LinearMap.ker (dOne A) /-- The 2-cocycles `Z²(G, A)` of `A : Rep k G`, defined as the kernel of the map `Fun(G × G, A) → Fun(G × G × G, A)` sending `(f, (g₁, g₂, g₃)) ↦ ρ_A(g₁)(f(g₂, g₃)) - f(g₁g₂, g₃) + f(g₁, g₂g₃) - f(g₁, g₂).` -/ def twoCocycles : Submodule k (G × G → A) := LinearMap.ker (dTwo A) variable {A} instance : FunLike (oneCocycles A) G A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem oneCocycles.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : oneCocycles A) : G → A) = f := rfl @[simp] theorem oneCocycles.val_eq_coe (f : oneCocycles A) : f.1 = f := rfl @[ext] theorem oneCocycles_ext {f₁ f₂ : oneCocycles A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ := DFunLike.ext f₁ f₂ h theorem mem_oneCocycles_def (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, A.ρ g (f h) - f (g * h) + f g = 0 := LinearMap.mem_ker.trans <| by rw [funext_iff] simp only [dOne_apply, Pi.zero_apply, Prod.forall] theorem mem_oneCocycles_iff (f : G → A) : f ∈ oneCocycles A ↔ ∀ g h : G, f (g * h) = A.ρ g (f h) + f g := by simp_rw [mem_oneCocycles_def, sub_add_eq_add_sub, sub_eq_zero, eq_comm] @[simp] theorem oneCocycles_map_one (f : oneCocycles A) : f 1 = 0 := by have := (mem_oneCocycles_def f).1 f.2 1 1 simpa only [map_one, Module.End.one_apply, mul_one, sub_self, zero_add] using this @[simp] theorem oneCocycles_map_inv (f : oneCocycles A) (g : G) : A.ρ g (f g⁻¹) = - f g := by rw [← add_eq_zero_iff_eq_neg, ← oneCocycles_map_one f, ← mul_inv_cancel g, (mem_oneCocycles_iff f).1 f.2 g g⁻¹] theorem dZero_apply_mem_oneCocycles (x : A) : dZero A x ∈ oneCocycles A := congr($(dOne_comp_dZero A) x) theorem oneCocycles_map_mul_of_isTrivial [A.IsTrivial] (f : oneCocycles A) (g h : G) : f (g * h) = f g + f h := by rw [(mem_oneCocycles_iff f).1 f.2, isTrivial_apply A.ρ g (f h), add_comm] theorem mem_oneCocycles_of_addMonoidHom [A.IsTrivial] (f : Additive G →+ A) : f ∘ Additive.ofMul ∈ oneCocycles A := (mem_oneCocycles_iff _).2 fun g h => by simp only [Function.comp_apply, ofMul_mul, map_add, oneCocycles_map_mul_of_isTrivial, isTrivial_apply A.ρ g (f (Additive.ofMul h)), add_comm (f (Additive.ofMul g))] variable (A) in /-- When `A : Rep k G` is a trivial representation of `G`, `Z¹(G, A)` is isomorphic to the group homs `G → A`. -/ @[simps] def oneCocyclesLequivOfIsTrivial [hA : A.IsTrivial] : oneCocycles A ≃ₗ[k] Additive G →+ A where toFun f := { toFun := f ∘ Additive.toMul map_zero' := oneCocycles_map_one f map_add' := oneCocycles_map_mul_of_isTrivial f } map_add' _ _ := rfl map_smul' _ _ := rfl invFun f := { val := f property := mem_oneCocycles_of_addMonoidHom f } left_inv f := by ext; rfl right_inv f := by ext; rfl instance : FunLike (twoCocycles A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem twoCocycles.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : twoCocycles A) : G × G → A) = f := rfl @[simp] theorem twoCocycles.val_eq_coe (f : twoCocycles A) : f.1 = f := rfl @[ext] theorem twoCocycles_ext {f₁ f₂ : twoCocycles A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ := DFunLike.ext f₁ f₂ (Prod.forall.mpr h) theorem mem_twoCocycles_def (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, A.ρ g (f (h, j)) - f (g * h, j) + f (g, h * j) - f (g, h) = 0 := LinearMap.mem_ker.trans <| by rw [funext_iff] simp only [dTwo_apply, Prod.mk.eta, Pi.zero_apply, Prod.forall] theorem mem_twoCocycles_iff (f : G × G → A) : f ∈ twoCocycles A ↔ ∀ g h j : G, f (g * h, j) + f (g, h) = A.ρ g (f (h, j)) + f (g, h * j) := by simp_rw [mem_twoCocycles_def, sub_eq_zero, sub_add_eq_add_sub, sub_eq_iff_eq_add, eq_comm, add_comm (f (_ * _, _))] theorem twoCocycles_map_one_fst (f : twoCocycles A) (g : G) : f (1, g) = f (1, 1) := by have := ((mem_twoCocycles_iff f).1 f.2 1 1 g).symm simpa only [map_one, Module.End.one_apply, one_mul, add_right_inj, this] theorem twoCocycles_map_one_snd (f : twoCocycles A) (g : G) : f (g, 1) = A.ρ g (f (1, 1)) := by have := (mem_twoCocycles_iff f).1 f.2 g 1 1 simpa only [mul_one, add_left_inj, this] lemma twoCocycles_ρ_map_inv_sub_map_inv (f : twoCocycles A) (g : G) : A.ρ g (f (g⁻¹, g)) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by have := (mem_twoCocycles_iff f).1 f.2 g g⁻¹ g simp only [mul_inv_cancel, inv_mul_cancel, twoCocycles_map_one_fst _ g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm theorem dOne_apply_mem_twoCocycles (x : G → A) : dOne A x ∈ twoCocycles A := congr($(dTwo_comp_dOne A) x) end Cocycles section Coboundaries /-- The 1-coboundaries `B¹(G, A)` of `A : Rep k G`, defined as the image of the map `A → Fun(G, A)` sending `(a, g) ↦ ρ_A(g)(a) - a.` -/ def oneCoboundaries : Submodule k (G → A) := LinearMap.range (dZero A) /-- The 2-coboundaries `B²(G, A)` of `A : Rep k G`, defined as the image of the map `Fun(G, A) → Fun(G × G, A)` sending `(f, (g₁, g₂)) ↦ ρ_A(g₁)(f(g₂)) - f(g₁g₂) + f(g₁).` -/ def twoCoboundaries : Submodule k (G × G → A) := LinearMap.range (dOne A) variable {A} instance : FunLike (oneCoboundaries A) G A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem oneCoboundaries.coe_mk (f : G → A) (hf) : ((⟨f, hf⟩ : oneCoboundaries A) : G → A) = f := rfl @[simp] theorem oneCoboundaries.val_eq_coe (f : oneCoboundaries A) : f.1 = f := rfl @[ext] theorem oneCoboundaries_ext {f₁ f₂ : oneCoboundaries A} (h : ∀ g : G, f₁ g = f₂ g) : f₁ = f₂ := DFunLike.ext f₁ f₂ h variable (A) in lemma oneCoboundaries_le_oneCocycles : oneCoboundaries A ≤ oneCocycles A := by rintro _ ⟨x, rfl⟩ exact dZero_apply_mem_oneCocycles x variable (A) in /-- Natural inclusion `B¹(G, A) →ₗ[k] Z¹(G, A)`. -/ abbrev oneCoboundariesToOneCocycles : oneCoboundaries A →ₗ[k] oneCocycles A := Submodule.inclusion (oneCoboundaries_le_oneCocycles A) @[simp] lemma oneCoboundariesToOneCocycles_apply (x : oneCoboundaries A) : oneCoboundariesToOneCocycles A x = x.1 := rfl theorem oneCoboundaries_eq_bot_of_isTrivial (A : Rep k G) [A.IsTrivial] : oneCoboundaries A = ⊥ := by simp_rw [oneCoboundaries, dZero_eq_zero] exact LinearMap.range_eq_bot.2 rfl instance : FunLike (twoCoboundaries A) (G × G) A := ⟨Subtype.val, Subtype.val_injective⟩ @[simp] theorem twoCoboundaries.coe_mk (f : G × G → A) (hf) : ((⟨f, hf⟩ : twoCoboundaries A) : G × G → A) = f := rfl @[simp] theorem twoCoboundaries.val_eq_coe (f : twoCoboundaries A) : f.1 = f := rfl @[ext] theorem twoCoboundaries_ext {f₁ f₂ : twoCoboundaries A} (h : ∀ g h : G, f₁ (g, h) = f₂ (g, h)) : f₁ = f₂ := DFunLike.ext f₁ f₂ (Prod.forall.mpr h) variable (A) in lemma twoCoboundaries_le_twoCocycles : twoCoboundaries A ≤ twoCocycles A := by rintro _ ⟨x, rfl⟩ exact dOne_apply_mem_twoCocycles x variable (A) in /-- Natural inclusion `B²(G, A) →ₗ[k] Z²(G, A)`. -/ abbrev twoCoboundariesToTwoCocycles : twoCoboundaries A →ₗ[k] twoCocycles A := Submodule.inclusion (twoCoboundaries_le_twoCocycles A) @[simp] lemma twoCoboundariesToTwoCocycles_apply (x : twoCoboundaries A) : twoCoboundariesToTwoCocycles A x = x.1 := rfl end Coboundaries section IsCocycle section variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A] /-- A function `f : G → A` satisfies the 1-cocycle condition if `f(gh) = g • f(h) + f(g)` for all `g, h : G`. -/ def IsOneCocycle (f : G → A) : Prop := ∀ g h : G, f (g * h) = g • f h + f g /-- A function `f : G × G → A` satisfies the 2-cocycle condition if `f(gh, j) + f(g, h) = g • f(h, j) + f(g, hj)` for all `g, h : G`. -/ def IsTwoCocycle (f : G × G → A) : Prop := ∀ g h j : G, f (g * h, j) + f (g, h) = g • (f (h, j)) + f (g, h * j) end section variable {G A : Type*} [Monoid G] [AddCommGroup A] [MulAction G A] theorem map_one_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) : f 1 = 0 := by simpa only [mul_one, one_smul, left_eq_add] using hf 1 1 theorem map_one_fst_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : f (1, g) = f (1, 1) := by simpa only [one_smul, one_mul, mul_one, add_right_inj] using (hf 1 1 g).symm theorem map_one_snd_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : f (g, 1) = g • f (1, 1) := by simpa only [mul_one, add_left_inj] using hf g 1 1 end section variable {G A : Type*} [Group G] [AddCommGroup A] [MulAction G A] @[scoped simp] theorem map_inv_of_isOneCocycle {f : G → A} (hf : IsOneCocycle f) (g : G) : g • f g⁻¹ = - f g := by rw [← add_eq_zero_iff_eq_neg, ← map_one_of_isOneCocycle hf, ← mul_inv_cancel g, hf g g⁻¹] theorem smul_map_inv_sub_map_inv_of_isTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) (g : G) : g • f (g⁻¹, g) - f (g, g⁻¹) = f (1, 1) - f (g, 1) := by have := hf g g⁻¹ g simp only [mul_inv_cancel, inv_mul_cancel, map_one_fst_of_isTwoCocycle hf g] at this exact sub_eq_sub_iff_add_eq_add.2 this.symm end end IsCocycle section IsCoboundary variable {G A : Type*} [Mul G] [AddCommGroup A] [SMul G A] /-- A function `f : G → A` satisfies the 1-coboundary condition if there's `x : A` such that `g • x - x = f(g)` for all `g : G`. -/ def IsOneCoboundary (f : G → A) : Prop := ∃ x : A, ∀ g : G, g • x - x = f g /-- A function `f : G × G → A` satisfies the 2-coboundary condition if there's `x : G → A` such that `g • x(h) - x(gh) + x(g) = f(g, h)` for all `g, h : G`. -/ def IsTwoCoboundary (f : G × G → A) : Prop := ∃ x : G → A, ∀ g h : G, g • x h - x (g * h) + x g = f (g, h) end IsCoboundary section ofDistribMulAction variable {k G A : Type u} [CommRing k] [Group G] [AddCommGroup A] [Module k A] [DistribMulAction G A] [SMulCommClass G k A] /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G → A` satisfying the 1-cocycle condition, produces a 1-cocycle for the representation on `A` induced by the `DistribMulAction`. -/ @[simps] def oneCocyclesOfIsOneCocycle {f : G → A} (hf : IsOneCocycle f) : oneCocycles (Rep.ofDistribMulAction k G A) := ⟨f, (mem_oneCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩ theorem isOneCocycle_of_mem_oneCocycles (f : G → A) (hf : f ∈ oneCocycles (Rep.ofDistribMulAction k G A)) : IsOneCocycle f := fun _ _ => (mem_oneCocycles_iff (A := Rep.ofDistribMulAction k G A) f).1 hf _ _ /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G → A` satisfying the 1-coboundary condition, produces a 1-coboundary for the representation on `A` induced by the `DistribMulAction`. -/ @[simps] def oneCoboundariesOfIsOneCoboundary {f : G → A} (hf : IsOneCoboundary f) : oneCoboundaries (Rep.ofDistribMulAction k G A) := ⟨f, hf.choose, funext hf.choose_spec⟩ theorem isOneCoboundary_of_mem_oneCoboundaries (f : G → A) (hf : f ∈ oneCoboundaries (Rep.ofDistribMulAction k G A)) : IsOneCoboundary f := by rcases hf with ⟨a, rfl⟩ exact ⟨a, fun _ => rfl⟩ /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G × G → A` satisfying the 2-cocycle condition, produces a 2-cocycle for the representation on `A` induced by the `DistribMulAction`. -/ @[simps] def twoCocyclesOfIsTwoCocycle {f : G × G → A} (hf : IsTwoCocycle f) : twoCocycles (Rep.ofDistribMulAction k G A) := ⟨f, (mem_twoCocycles_iff (A := Rep.ofDistribMulAction k G A) f).2 hf⟩ theorem isTwoCocycle_of_mem_twoCocycles (f : G × G → A) (hf : f ∈ twoCocycles (Rep.ofDistribMulAction k G A)) : IsTwoCocycle f := (mem_twoCocycles_iff (A := Rep.ofDistribMulAction k G A) f).1 hf /-- Given a `k`-module `A` with a compatible `DistribMulAction` of `G`, and a function `f : G × G → A` satisfying the 2-coboundary condition, produces a 2-coboundary for the representation on `A` induced by the `DistribMulAction`. -/ @[simps] def twoCoboundariesOfIsTwoCoboundary {f : G × G → A} (hf : IsTwoCoboundary f) : twoCoboundaries (Rep.ofDistribMulAction k G A) := ⟨f, hf.choose,funext fun g ↦ hf.choose_spec g.1 g.2⟩ theorem isTwoCoboundary_of_mem_twoCoboundaries (f : G × G → A) (hf : f ∈ twoCoboundaries (Rep.ofDistribMulAction k G A)) : IsTwoCoboundary f := by rcases hf with ⟨a, rfl⟩ exact ⟨a, fun _ _ => rfl⟩ end ofDistribMulAction /-! The next few sections, until the section `Cohomology`, are a multiplicative copy of the previous few sections beginning with `IsCocycle`. Unfortunately `@[to_additive]` doesn't work with scalar actions. -/ section IsMulCocycle section variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M] /-- A function `f : G → M` satisfies the multiplicative 1-cocycle condition if `f(gh) = g • f(h) * f(g)` for all `g, h : G`. -/ def IsMulOneCocycle (f : G → M) : Prop := ∀ g h : G, f (g * h) = g • f h * f g /-- A function `f : G × G → M` satisfies the multiplicative 2-cocycle condition if `f(gh, j) * f(g, h) = g • f(h, j) * f(g, hj)` for all `g, h : G`. -/ def IsMulTwoCocycle (f : G × G → M) : Prop := ∀ g h j : G, f (g * h, j) * f (g, h) = g • (f (h, j)) * f (g, h * j) end section variable {G M : Type*} [Monoid G] [CommGroup M] [MulAction G M] theorem map_one_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) : f 1 = 1 := by simpa only [mul_one, one_smul, left_eq_mul] using hf 1 1 theorem map_one_fst_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) : f (1, g) = f (1, 1) := by simpa only [one_smul, one_mul, mul_one, mul_right_inj] using (hf 1 1 g).symm theorem map_one_snd_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) : f (g, 1) = g • f (1, 1) := by simpa only [mul_one, mul_left_inj] using hf g 1 1 end section variable {G M : Type*} [Group G] [CommGroup M] [MulAction G M] @[scoped simp] theorem map_inv_of_isMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) (g : G) : g • f g⁻¹ = (f g)⁻¹ := by rw [← mul_eq_one_iff_eq_inv, ← map_one_of_isMulOneCocycle hf, ← mul_inv_cancel g, hf g g⁻¹] theorem smul_map_inv_div_map_inv_of_isMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) (g : G) : g • f (g⁻¹, g) / f (g, g⁻¹) = f (1, 1) / f (g, 1) := by have := hf g g⁻¹ g simp only [mul_inv_cancel, inv_mul_cancel, map_one_fst_of_isMulTwoCocycle hf g] at this exact div_eq_div_iff_mul_eq_mul.2 this.symm end end IsMulCocycle section IsMulCoboundary variable {G M : Type*} [Mul G] [CommGroup M] [SMul G M] /-- A function `f : G → M` satisfies the multiplicative 1-coboundary condition if there's `x : M` such that `g • x / x = f(g)` for all `g : G`. -/ def IsMulOneCoboundary (f : G → M) : Prop := ∃ x : M, ∀ g : G, g • x / x = f g /-- A function `f : G × G → M` satisfies the 2-coboundary condition if there's `x : G → M` such that `g • x(h) / x(gh) * x(g) = f(g, h)` for all `g, h : G`. -/ def IsMulTwoCoboundary (f : G × G → M) : Prop := ∃ x : G → M, ∀ g h : G, g • x h / x (g * h) * x g = f (g, h) end IsMulCoboundary section ofMulDistribMulAction variable {G M : Type} [Group G] [CommGroup M] [MulDistribMulAction G M] /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G → M` satisfying the multiplicative 1-cocycle condition, produces a 1-cocycle for the representation on `Additive M` induced by the `MulDistribMulAction`. -/ @[simps] def oneCocyclesOfIsMulOneCocycle {f : G → M} (hf : IsMulOneCocycle f) : oneCocycles (Rep.ofMulDistribMulAction G M) := ⟨Additive.ofMul ∘ f, (mem_oneCocycles_iff (A := Rep.ofMulDistribMulAction G M) f).2 hf⟩ theorem isMulOneCocycle_of_mem_oneCocycles (f : G → M) (hf : f ∈ oneCocycles (Rep.ofMulDistribMulAction G M)) : IsMulOneCocycle (Additive.toMul ∘ f) := (mem_oneCocycles_iff (A := Rep.ofMulDistribMulAction G M) f).1 hf /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G → M` satisfying the multiplicative 1-coboundary condition, produces a 1-coboundary for the representation on `Additive M` induced by the `MulDistribMulAction`. -/ @[simps] def oneCoboundariesOfIsMulOneCoboundary {f : G → M} (hf : IsMulOneCoboundary f) : oneCoboundaries (Rep.ofMulDistribMulAction G M) := ⟨f, hf.choose, funext hf.choose_spec⟩ theorem isMulOneCoboundary_of_mem_oneCoboundaries (f : G → M) (hf : f ∈ oneCoboundaries (Rep.ofMulDistribMulAction G M)) : IsMulOneCoboundary (M := M) (Additive.ofMul ∘ f) := by rcases hf with ⟨x, rfl⟩ exact ⟨x, fun _ => rfl⟩ /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G × G → M` satisfying the multiplicative 2-cocycle condition, produces a 2-cocycle for the representation on `Additive M` induced by the `MulDistribMulAction`. -/ @[simps] def twoCocyclesOfIsMulTwoCocycle {f : G × G → M} (hf : IsMulTwoCocycle f) : twoCocycles (Rep.ofMulDistribMulAction G M) := ⟨Additive.ofMul ∘ f, (mem_twoCocycles_iff (A := Rep.ofMulDistribMulAction G M) f).2 hf⟩ theorem isMulTwoCocycle_of_mem_twoCocycles (f : G × G → M) (hf : f ∈ twoCocycles (Rep.ofMulDistribMulAction G M)) : IsMulTwoCocycle (Additive.toMul ∘ f) := (mem_twoCocycles_iff (A := Rep.ofMulDistribMulAction G M) f).1 hf /-- Given an abelian group `M` with a `MulDistribMulAction` of `G`, and a function `f : G × G → M` satisfying the multiplicative 2-coboundary condition, produces a 2-coboundary for the representation on `M` induced by the `MulDistribMulAction`. -/ def twoCoboundariesOfIsMulTwoCoboundary {f : G × G → M} (hf : IsMulTwoCoboundary f) : twoCoboundaries (Rep.ofMulDistribMulAction G M) := ⟨f, hf.choose, funext fun g ↦ hf.choose_spec g.1 g.2⟩ theorem isMulTwoCoboundary_of_mem_twoCoboundaries (f : G × G → M) (hf : f ∈ twoCoboundaries (Rep.ofMulDistribMulAction G M)) : IsMulTwoCoboundary (M := M) (Additive.toMul ∘ f) := by rcases hf with ⟨x, rfl⟩ exact ⟨x, fun _ _ => rfl⟩ end ofMulDistribMulAction section Cohomology /-- We define the 0th group cohomology of a `k`-linear `G`-representation `A`, `H⁰(G, A)`, to be the invariants of the representation, `Aᴳ`. -/ abbrev H0 := ModuleCat.of k A.ρ.invariants /-- We define the 1st group cohomology of a `k`-linear `G`-representation `A`, `H¹(G, A)`, to be 1-cocycles (i.e. `Z¹(G, A) := Ker(d¹ : Fun(G, A) → Fun(G², A)`) modulo 1-coboundaries (i.e. `B¹(G, A) := Im(d⁰: A → Fun(G, A))`). -/ abbrev H1 := (shortComplexH1 A).moduleCatHomology /-- The quotient map `Z¹(G, A) → H¹(G, A).` -/ abbrev H1π : ModuleCat.of k (oneCocycles A) ⟶ H1 A := (shortComplexH1 A).moduleCatHomologyπ variable {A} in lemma H1π_eq_zero_iff (x : oneCocycles A) : H1π A x = 0 ↔ ⇑x ∈ oneCoboundaries A := by show (LinearMap.range ((dZero A).codRestrict (oneCocycles A) _)).mkQ _ = 0 ↔ _ simp [LinearMap.range_codRestrict, oneCoboundaries] /-- We define the 2nd group cohomology of a `k`-linear `G`-representation `A`, `H²(G, A)`, to be 2-cocycles (i.e. `Z²(G, A) := Ker(d² : Fun(G², A) → Fun(G³, A)`) modulo 2-coboundaries (i.e. `B²(G, A) := Im(d¹: Fun(G, A) → Fun(G², A))`). -/ abbrev H2 := (shortComplexH2 A).moduleCatHomology /-- The quotient map `Z²(G, A) → H²(G, A).` -/ abbrev H2π : ModuleCat.of k (twoCocycles A) ⟶ H2 A := (shortComplexH2 A).moduleCatHomologyπ variable {A} in lemma H2π_eq_zero_iff (x : twoCocycles A) : H2π A x = 0 ↔ ⇑x ∈ twoCoboundaries A := by show (LinearMap.range ((dOne A).codRestrict (twoCocycles A) _)).mkQ _ = 0 ↔ _ simp [LinearMap.range_codRestrict, twoCoboundaries] end Cohomology section H0 /-- When the representation on `A` is trivial, then `H⁰(G, A)` is all of `A.` -/ def H0LequivOfIsTrivial [A.IsTrivial] : H0 A ≃ₗ[k] A := LinearEquiv.ofTop _ (invariants_eq_top A.ρ) @[simp] theorem H0LequivOfIsTrivial_eq_subtype [A.IsTrivial] : H0LequivOfIsTrivial A = A.ρ.invariants.subtype := rfl theorem H0LequivOfIsTrivial_apply [A.IsTrivial] (x : H0 A) : H0LequivOfIsTrivial A x = x := rfl
@[simp] theorem H0LequivOfIsTrivial_symm_apply [A.IsTrivial] (x : A) : (H0LequivOfIsTrivial A).symm x = x := rfl
Mathlib/RepresentationTheory/GroupCohomology/LowDegree.lean
742
744
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Algebra.BigOperators.Option import Mathlib.Analysis.BoxIntegral.Box.Basic import Mathlib.Data.Set.Pairwise.Lattice /-! # Partitions of rectangular boxes in `ℝⁿ` In this file we define (pre)partitions of rectangular boxes in `ℝⁿ`. A partition of a box `I` in `ℝⁿ` (see `BoxIntegral.Prepartition` and `BoxIntegral.Prepartition.IsPartition`) is a finite set of pairwise disjoint boxes such that their union is exactly `I`. We use `boxes : Finset (Box ι)` to store the set of boxes. Many lemmas about box integrals deal with pairwise disjoint collections of subboxes, so we define a structure `BoxIntegral.Prepartition (I : BoxIntegral.Box ι)` that stores a collection of boxes such that * each box `J ∈ boxes` is a subbox of `I`; * the boxes are pairwise disjoint as sets in `ℝⁿ`. Then we define a predicate `BoxIntegral.Prepartition.IsPartition`; `π.IsPartition` means that the boxes of `π` actually cover the whole `I`. We also define some operations on prepartitions: * `BoxIntegral.Prepartition.biUnion`: split each box of a partition into smaller boxes; * `BoxIntegral.Prepartition.restrict`: restrict a partition to a smaller box. We also define a `SemilatticeInf` structure on `BoxIntegral.Prepartition I` for all `I : BoxIntegral.Box ι`. ## Tags rectangular box, partition -/ open Set Finset Function open scoped NNReal noncomputable section namespace BoxIntegral variable {ι : Type*} /-- A prepartition of `I : BoxIntegral.Box ι` is a finite set of pairwise disjoint subboxes of `I`. -/ structure Prepartition (I : Box ι) where /-- The underlying set of boxes -/ boxes : Finset (Box ι) /-- Each box is a sub-box of `I` -/ le_of_mem' : ∀ J ∈ boxes, J ≤ I /-- The boxes in a prepartition are pairwise disjoint. -/ pairwiseDisjoint : Set.Pairwise (↑boxes) (Disjoint on ((↑) : Box ι → Set (ι → ℝ))) namespace Prepartition variable {I J J₁ J₂ : Box ι} (π : Prepartition I) {π₁ π₂ : Prepartition I} {x : ι → ℝ} instance : Membership (Box ι) (Prepartition I) := ⟨fun π J => J ∈ π.boxes⟩ @[simp] theorem mem_boxes : J ∈ π.boxes ↔ J ∈ π := Iff.rfl @[simp] theorem mem_mk {s h₁ h₂} : J ∈ (mk s h₁ h₂ : Prepartition I) ↔ J ∈ s := Iff.rfl theorem disjoint_coe_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (h : J₁ ≠ J₂) : Disjoint (J₁ : Set (ι → ℝ)) J₂ := π.pairwiseDisjoint h₁ h₂ h theorem eq_of_mem_of_mem (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hx₁ : x ∈ J₁) (hx₂ : x ∈ J₂) : J₁ = J₂ := by_contra fun H => (π.disjoint_coe_of_mem h₁ h₂ H).le_bot ⟨hx₁, hx₂⟩ theorem eq_of_le_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle₁ : J ≤ J₁) (hle₂ : J ≤ J₂) : J₁ = J₂ := π.eq_of_mem_of_mem h₁ h₂ (hle₁ J.upper_mem) (hle₂ J.upper_mem) theorem eq_of_le (h₁ : J₁ ∈ π) (h₂ : J₂ ∈ π) (hle : J₁ ≤ J₂) : J₁ = J₂ := π.eq_of_le_of_le h₁ h₂ le_rfl hle theorem le_of_mem (hJ : J ∈ π) : J ≤ I := π.le_of_mem' J hJ theorem lower_le_lower (hJ : J ∈ π) : I.lower ≤ J.lower := Box.antitone_lower (π.le_of_mem hJ) theorem upper_le_upper (hJ : J ∈ π) : J.upper ≤ I.upper := Box.monotone_upper (π.le_of_mem hJ) theorem injective_boxes : Function.Injective (boxes : Prepartition I → Finset (Box ι)) := by rintro ⟨s₁, h₁, h₁'⟩ ⟨s₂, h₂, h₂'⟩ (rfl : s₁ = s₂) rfl @[ext] theorem ext (h : ∀ J, J ∈ π₁ ↔ J ∈ π₂) : π₁ = π₂ := injective_boxes <| Finset.ext h /-- The singleton prepartition `{J}`, `J ≤ I`. -/ @[simps] def single (I J : Box ι) (h : J ≤ I) : Prepartition I := ⟨{J}, by simpa, by simp⟩ @[simp] theorem mem_single {J'} (h : J ≤ I) : J' ∈ single I J h ↔ J' = J := mem_singleton /-- We say that `π ≤ π'` if each box of `π` is a subbox of some box of `π'`. -/ instance : LE (Prepartition I) := ⟨fun π π' => ∀ ⦃I⦄, I ∈ π → ∃ I' ∈ π', I ≤ I'⟩ instance partialOrder : PartialOrder (Prepartition I) where le := (· ≤ ·) le_refl _ I hI := ⟨I, hI, le_rfl⟩ le_trans _ _ _ h₁₂ h₂₃ _ hI₁ := let ⟨_, hI₂, hI₁₂⟩ := h₁₂ hI₁ let ⟨I₃, hI₃, hI₂₃⟩ := h₂₃ hI₂ ⟨I₃, hI₃, hI₁₂.trans hI₂₃⟩ le_antisymm := by suffices ∀ {π₁ π₂ : Prepartition I}, π₁ ≤ π₂ → π₂ ≤ π₁ → π₁.boxes ⊆ π₂.boxes from fun π₁ π₂ h₁ h₂ => injective_boxes (Subset.antisymm (this h₁ h₂) (this h₂ h₁)) intro π₁ π₂ h₁ h₂ J hJ rcases h₁ hJ with ⟨J', hJ', hle⟩; rcases h₂ hJ' with ⟨J'', hJ'', hle'⟩ obtain rfl : J = J'' := π₁.eq_of_le hJ hJ'' (hle.trans hle') obtain rfl : J' = J := le_antisymm ‹_› ‹_› assumption instance : OrderTop (Prepartition I) where top := single I I le_rfl le_top π _ hJ := ⟨I, by simp, π.le_of_mem hJ⟩ instance : OrderBot (Prepartition I) where bot := ⟨∅, fun _ hJ => (Finset.not_mem_empty _ hJ).elim, fun _ hJ => (Set.not_mem_empty _ <| Finset.coe_empty ▸ hJ).elim⟩ bot_le _ _ hJ := (Finset.not_mem_empty _ hJ).elim instance : Inhabited (Prepartition I) := ⟨⊤⟩ theorem le_def : π₁ ≤ π₂ ↔ ∀ J ∈ π₁, ∃ J' ∈ π₂, J ≤ J' := Iff.rfl @[simp] theorem mem_top : J ∈ (⊤ : Prepartition I) ↔ J = I := mem_singleton @[simp] theorem top_boxes : (⊤ : Prepartition I).boxes = {I} := rfl @[simp] theorem not_mem_bot : J ∉ (⊥ : Prepartition I) := Finset.not_mem_empty _ @[simp] theorem bot_boxes : (⊥ : Prepartition I).boxes = ∅ := rfl /-- An auxiliary lemma used to prove that the same point can't belong to more than `2 ^ Fintype.card ι` closed boxes of a prepartition. -/ theorem injOn_setOf_mem_Icc_setOf_lower_eq (x : ι → ℝ) : InjOn (fun J : Box ι => { i | J.lower i = x i }) { J | J ∈ π ∧ x ∈ Box.Icc J } := by rintro J₁ ⟨h₁, hx₁⟩ J₂ ⟨h₂, hx₂⟩ (H : { i | J₁.lower i = x i } = { i | J₂.lower i = x i }) suffices ∀ i, (Ioc (J₁.lower i) (J₁.upper i) ∩ Ioc (J₂.lower i) (J₂.upper i)).Nonempty by choose y hy₁ hy₂ using this exact π.eq_of_mem_of_mem h₁ h₂ hy₁ hy₂ intro i simp only [Set.ext_iff, mem_setOf] at H rcases (hx₁.1 i).eq_or_lt with hi₁ | hi₁ · have hi₂ : J₂.lower i = x i := (H _).1 hi₁ have H₁ : x i < J₁.upper i := by simpa only [hi₁] using J₁.lower_lt_upper i have H₂ : x i < J₂.upper i := by simpa only [hi₂] using J₂.lower_lt_upper i rw [Set.Ioc_inter_Ioc, hi₁, hi₂, sup_idem, Set.nonempty_Ioc] exact lt_min H₁ H₂ · have hi₂ : J₂.lower i < x i := (hx₂.1 i).lt_of_ne (mt (H _).2 hi₁.ne) exact ⟨x i, ⟨hi₁, hx₁.2 i⟩, ⟨hi₂, hx₂.2 i⟩⟩ open scoped Classical in /-- The set of boxes of a prepartition that contain `x` in their closures has cardinality at most `2 ^ Fintype.card ι`. -/ theorem card_filter_mem_Icc_le [Fintype ι] (x : ι → ℝ) : #{J ∈ π.boxes | x ∈ Box.Icc J} ≤ 2 ^ Fintype.card ι := by rw [← Fintype.card_set] refine Finset.card_le_card_of_injOn (fun J : Box ι => { i | J.lower i = x i }) (fun _ _ => Finset.mem_univ _) ?_ simpa using π.injOn_setOf_mem_Icc_setOf_lower_eq x /-- Given a prepartition `π : BoxIntegral.Prepartition I`, `π.iUnion` is the part of `I` covered by the boxes of `π`. -/ protected def iUnion : Set (ι → ℝ) := ⋃ J ∈ π, ↑J theorem iUnion_def : π.iUnion = ⋃ J ∈ π, ↑J := rfl theorem iUnion_def' : π.iUnion = ⋃ J ∈ π.boxes, ↑J := rfl -- Porting note: Previous proof was `:= Set.mem_iUnion₂` @[simp] theorem mem_iUnion : x ∈ π.iUnion ↔ ∃ J ∈ π, x ∈ J := by convert Set.mem_iUnion₂ rw [Box.mem_coe, exists_prop] @[simp] theorem iUnion_single (h : J ≤ I) : (single I J h).iUnion = J := by simp [iUnion_def] @[simp] theorem iUnion_top : (⊤ : Prepartition I).iUnion = I := by simp [Prepartition.iUnion] @[simp] theorem iUnion_eq_empty : π₁.iUnion = ∅ ↔ π₁ = ⊥ := by simp [← injective_boxes.eq_iff, Finset.ext_iff, Prepartition.iUnion, imp_false] @[simp] theorem iUnion_bot : (⊥ : Prepartition I).iUnion = ∅ := iUnion_eq_empty.2 rfl theorem subset_iUnion (h : J ∈ π) : ↑J ⊆ π.iUnion := subset_biUnion_of_mem h theorem iUnion_subset : π.iUnion ⊆ I := iUnion₂_subset π.le_of_mem' @[mono] theorem iUnion_mono (h : π₁ ≤ π₂) : π₁.iUnion ⊆ π₂.iUnion := fun _ hx => let ⟨_, hJ₁, hx⟩ := π₁.mem_iUnion.1 hx let ⟨J₂, hJ₂, hle⟩ := h hJ₁
π₂.mem_iUnion.2 ⟨J₂, hJ₂, hle hx⟩ theorem disjoint_boxes_of_disjoint_iUnion (h : Disjoint π₁.iUnion π₂.iUnion) :
Mathlib/Analysis/BoxIntegral/Partition/Basic.lean
226
228
/- Copyright (c) 2020 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anatole Dedecker, Sébastien Gouëzel, Yury Kudryashov, Dylan MacKenzie, Patrick Massot -/ import Mathlib.Algebra.BigOperators.Module import Mathlib.Algebra.Order.Field.Power import Mathlib.Algebra.Polynomial.Monic import Mathlib.Analysis.Asymptotics.Lemmas import Mathlib.Analysis.Normed.Ring.InfiniteSum import Mathlib.Analysis.Normed.Module.Basic import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.Data.List.TFAE import Mathlib.Data.Nat.Choose.Bounds import Mathlib.Order.Filter.AtTopBot.ModEq import Mathlib.RingTheory.Polynomial.Pochhammer import Mathlib.Tactic.NoncommRing /-! # A collection of specific limit computations This file contains important specific limit computations in (semi-)normed groups/rings/spaces, as well as such computations in `ℝ` when the natural proof passes through a fact about normed spaces. -/ noncomputable section open Set Function Filter Finset Metric Asymptotics Topology Nat NNReal ENNReal variable {α : Type*} /-! ### Powers -/ theorem isLittleO_pow_pow_of_lt_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ < r₂) : (fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n := have H : 0 < r₂ := h₁.trans_lt h₂ (isLittleO_of_tendsto fun _ hn ↦ False.elim <| H.ne' <| pow_eq_zero hn) <| (tendsto_pow_atTop_nhds_zero_of_lt_one (div_nonneg h₁ (h₁.trans h₂.le)) ((div_lt_one H).2 h₂)).congr fun _ ↦ div_pow _ _ _ theorem isBigO_pow_pow_of_le_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ ≤ r₂) : (fun n : ℕ ↦ r₁ ^ n) =O[atTop] fun n ↦ r₂ ^ n := h₂.eq_or_lt.elim (fun h ↦ h ▸ isBigO_refl _ _) fun h ↦ (isLittleO_pow_pow_of_lt_left h₁ h).isBigO theorem isLittleO_pow_pow_of_abs_lt_left {r₁ r₂ : ℝ} (h : |r₁| < |r₂|) : (fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n := by refine (IsLittleO.of_norm_left ?_).of_norm_right exact (isLittleO_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs r₂) open List in /-- Various statements equivalent to the fact that `f n` grows exponentially slower than `R ^ n`. * 0: $f n = o(a ^ n)$ for some $-R < a < R$; * 1: $f n = o(a ^ n)$ for some $0 < a < R$; * 2: $f n = O(a ^ n)$ for some $-R < a < R$; * 3: $f n = O(a ^ n)$ for some $0 < a < R$; * 4: there exist `a < R` and `C` such that one of `C` and `R` is positive and $|f n| ≤ Ca^n$ for all `n`; * 5: there exists `0 < a < R` and a positive `C` such that $|f n| ≤ Ca^n$ for all `n`; * 6: there exists `a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`; * 7: there exists `0 < a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`. NB: For backwards compatibility, if you add more items to the list, please append them at the end of the list. -/ theorem TFAE_exists_lt_isLittleO_pow (f : ℕ → ℝ) (R : ℝ) : TFAE [∃ a ∈ Ioo (-R) R, f =o[atTop] (a ^ ·), ∃ a ∈ Ioo 0 R, f =o[atTop] (a ^ ·), ∃ a ∈ Ioo (-R) R, f =O[atTop] (a ^ ·), ∃ a ∈ Ioo 0 R, f =O[atTop] (a ^ ·), ∃ a < R, ∃ C : ℝ, (0 < C ∨ 0 < R) ∧ ∀ n, |f n| ≤ C * a ^ n, ∃ a ∈ Ioo 0 R, ∃ C > 0, ∀ n, |f n| ≤ C * a ^ n, ∃ a < R, ∀ᶠ n in atTop, |f n| ≤ a ^ n, ∃ a ∈ Ioo 0 R, ∀ᶠ n in atTop, |f n| ≤ a ^ n] := by have A : Ico 0 R ⊆ Ioo (-R) R := fun x hx ↦ ⟨(neg_lt_zero.2 (hx.1.trans_lt hx.2)).trans_le hx.1, hx.2⟩ have B : Ioo 0 R ⊆ Ioo (-R) R := Subset.trans Ioo_subset_Ico_self A -- First we prove that 1-4 are equivalent using 2 → 3 → 4, 1 → 3, and 2 → 1 tfae_have 1 → 3 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩ tfae_have 2 → 1 := fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩ tfae_have 3 → 2 | ⟨a, ha, H⟩ => by rcases exists_between (abs_lt.2 ha) with ⟨b, hab, hbR⟩ exact ⟨b, ⟨(abs_nonneg a).trans_lt hab, hbR⟩, H.trans_isLittleO (isLittleO_pow_pow_of_abs_lt_left (hab.trans_le (le_abs_self b)))⟩ tfae_have 2 → 4 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩ tfae_have 4 → 3 := fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩ -- Add 5 and 6 using 4 → 6 → 5 → 3 tfae_have 4 → 6 | ⟨a, ha, H⟩ => by rcases bound_of_isBigO_nat_atTop H with ⟨C, hC₀, hC⟩ refine ⟨a, ha, C, hC₀, fun n ↦ ?_⟩ simpa only [Real.norm_eq_abs, abs_pow, abs_of_nonneg ha.1.le] using hC (pow_ne_zero n ha.1.ne') tfae_have 6 → 5 := fun ⟨a, ha, C, H₀, H⟩ ↦ ⟨a, ha.2, C, Or.inl H₀, H⟩ tfae_have 5 → 3 | ⟨a, ha, C, h₀, H⟩ => by rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ (abs_nonneg _).trans (H n) with (rfl | ⟨hC₀, ha₀⟩) · obtain rfl : f = 0 := by ext n simpa using H n simp only [lt_irrefl, false_or] at h₀ exact ⟨0, ⟨neg_lt_zero.2 h₀, h₀⟩, isBigO_zero _ _⟩ exact ⟨a, A ⟨ha₀, ha⟩, isBigO_of_le' _ fun n ↦ (H n).trans <| mul_le_mul_of_nonneg_left (le_abs_self _) hC₀.le⟩ -- Add 7 and 8 using 2 → 8 → 7 → 3 tfae_have 2 → 8 | ⟨a, ha, H⟩ => by refine ⟨a, ha, (H.def zero_lt_one).mono fun n hn ↦ ?_⟩ rwa [Real.norm_eq_abs, Real.norm_eq_abs, one_mul, abs_pow, abs_of_pos ha.1] at hn tfae_have 8 → 7 := fun ⟨a, ha, H⟩ ↦ ⟨a, ha.2, H⟩ tfae_have 7 → 3 | ⟨a, ha, H⟩ => by refine ⟨a, A ⟨?_, ha⟩, .of_norm_eventuallyLE H⟩ exact nonneg_of_eventually_pow_nonneg (H.mono fun n ↦ (abs_nonneg _).trans) tfae_finish /-- For any natural `k` and a real `r > 1` we have `n ^ k = o(r ^ n)` as `n → ∞`. -/ theorem isLittleO_pow_const_const_pow_of_one_lt {R : Type*} [NormedRing R] (k : ℕ) {r : ℝ} (hr : 1 < r) : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ r ^ n := by have : Tendsto (fun x : ℝ ↦ x ^ k) (𝓝[>] 1) (𝓝 1) := ((continuous_id.pow k).tendsto' (1 : ℝ) 1 (one_pow _)).mono_left inf_le_left obtain ⟨r' : ℝ, hr' : r' ^ k < r, h1 : 1 < r'⟩ := ((this.eventually (gt_mem_nhds hr)).and self_mem_nhdsWithin).exists have h0 : 0 ≤ r' := zero_le_one.trans h1.le suffices (fun n ↦ (n : R) ^ k : ℕ → R) =O[atTop] fun n : ℕ ↦ (r' ^ k) ^ n from this.trans_isLittleO (isLittleO_pow_pow_of_lt_left (pow_nonneg h0 _) hr') conv in (r' ^ _) ^ _ => rw [← pow_mul, mul_comm, pow_mul] suffices ∀ n : ℕ, ‖(n : R)‖ ≤ (r' - 1)⁻¹ * ‖(1 : R)‖ * ‖r' ^ n‖ from (isBigO_of_le' _ this).pow _ intro n rw [mul_right_comm] refine n.norm_cast_le.trans (mul_le_mul_of_nonneg_right ?_ (norm_nonneg _)) simpa [_root_.div_eq_inv_mul, Real.norm_eq_abs, abs_of_nonneg h0] using n.cast_le_pow_div_sub h1 /-- For a real `r > 1` we have `n = o(r ^ n)` as `n → ∞`. -/ theorem isLittleO_coe_const_pow_of_one_lt {R : Type*} [NormedRing R] {r : ℝ} (hr : 1 < r) : ((↑) : ℕ → R) =o[atTop] fun n ↦ r ^ n := by simpa only [pow_one] using @isLittleO_pow_const_const_pow_of_one_lt R _ 1 _ hr /-- If `‖r₁‖ < r₂`, then for any natural `k` we have `n ^ k r₁ ^ n = o (r₂ ^ n)` as `n → ∞`. -/ theorem isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt {R : Type*} [NormedRing R] (k : ℕ) {r₁ : R} {r₂ : ℝ} (h : ‖r₁‖ < r₂) : (fun n ↦ (n : R) ^ k * r₁ ^ n : ℕ → R) =o[atTop] fun n ↦ r₂ ^ n := by by_cases h0 : r₁ = 0 · refine (isLittleO_zero _ _).congr' (mem_atTop_sets.2 <| ⟨1, fun n hn ↦ ?_⟩) EventuallyEq.rfl simp [zero_pow (one_le_iff_ne_zero.1 hn), h0] rw [← Ne, ← norm_pos_iff] at h0 have A : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ (r₂ / ‖r₁‖) ^ n := isLittleO_pow_const_const_pow_of_one_lt k ((one_lt_div h0).2 h) suffices (fun n ↦ r₁ ^ n) =O[atTop] fun n ↦ ‖r₁‖ ^ n by simpa [div_mul_cancel₀ _ (pow_pos h0 _).ne', div_pow] using A.mul_isBigO this exact .of_norm_eventuallyLE <| eventually_norm_pow_le r₁ theorem tendsto_pow_const_div_const_pow_of_one_lt (k : ℕ) {r : ℝ} (hr : 1 < r) : Tendsto (fun n ↦ (n : ℝ) ^ k / r ^ n : ℕ → ℝ) atTop (𝓝 0) := (isLittleO_pow_const_const_pow_of_one_lt k hr).tendsto_div_nhds_zero /-- If `|r| < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`. -/ theorem tendsto_pow_const_mul_const_pow_of_abs_lt_one (k : ℕ) {r : ℝ} (hr : |r| < 1) : Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by by_cases h0 : r = 0 · exact tendsto_const_nhds.congr' (mem_atTop_sets.2 ⟨1, fun n hn ↦ by simp [zero_lt_one.trans_le hn |>.ne', h0]⟩) have hr' : 1 < |r|⁻¹ := (one_lt_inv₀ (abs_pos.2 h0)).2 hr rw [tendsto_zero_iff_norm_tendsto_zero] simpa [div_eq_mul_inv] using tendsto_pow_const_div_const_pow_of_one_lt k hr' /-- For `k ≠ 0` and a constant `r` the function `r / n ^ k` tends to zero. -/ lemma tendsto_const_div_pow (r : ℝ) (k : ℕ) (hk : k ≠ 0) : Tendsto (fun n : ℕ => r / n ^ k) atTop (𝓝 0) := by simpa using Filter.Tendsto.const_div_atTop (tendsto_natCast_atTop_atTop (R := ℝ).comp (tendsto_pow_atTop hk) ) r /-- If `0 ≤ r < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`. This is a specialized version of `tendsto_pow_const_mul_const_pow_of_abs_lt_one`, singled out for ease of application. -/ theorem tendsto_pow_const_mul_const_pow_of_lt_one (k : ℕ) {r : ℝ} (hr : 0 ≤ r) (h'r : r < 1) : Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : ℕ → ℝ) atTop (𝓝 0) := tendsto_pow_const_mul_const_pow_of_abs_lt_one k (abs_lt.2 ⟨neg_one_lt_zero.trans_le hr, h'r⟩) /-- If `|r| < 1`, then `n * r ^ n` tends to zero. -/ theorem tendsto_self_mul_const_pow_of_abs_lt_one {r : ℝ} (hr : |r| < 1) : Tendsto (fun n ↦ n * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_abs_lt_one 1 hr /-- If `0 ≤ r < 1`, then `n * r ^ n` tends to zero. This is a specialized version of `tendsto_self_mul_const_pow_of_abs_lt_one`, singled out for ease of application. -/ theorem tendsto_self_mul_const_pow_of_lt_one {r : ℝ} (hr : 0 ≤ r) (h'r : r < 1) : Tendsto (fun n ↦ n * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_lt_one 1 hr h'r /-- In a normed ring, the powers of an element x with `‖x‖ < 1` tend to zero. -/ theorem tendsto_pow_atTop_nhds_zero_of_norm_lt_one {R : Type*} [SeminormedRing R] {x : R} (h : ‖x‖ < 1) : Tendsto (fun n : ℕ ↦ x ^ n) atTop (𝓝 0) := by
apply squeeze_zero_norm' (eventually_norm_pow_le x) exact tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg _) h theorem tendsto_pow_atTop_nhds_zero_of_abs_lt_one {r : ℝ} (h : |r| < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := tendsto_pow_atTop_nhds_zero_of_norm_lt_one h lemma tendsto_pow_atTop_nhds_zero_iff_norm_lt_one {R : Type*} [SeminormedRing R] [NormMulClass R] {x : R} : Tendsto (fun n : ℕ ↦ x ^ n) atTop (𝓝 0) ↔ ‖x‖ < 1 := by -- this proof is slightly fiddly since `‖x ^ n‖ = ‖x‖ ^ n` might not hold for `n = 0` refine ⟨?_, tendsto_pow_atTop_nhds_zero_of_norm_lt_one⟩ rw [← abs_of_nonneg (norm_nonneg _), ← tendsto_pow_atTop_nhds_zero_iff, tendsto_zero_iff_norm_tendsto_zero] apply Tendsto.congr' filter_upwards [eventually_ge_atTop 1] with n hn induction n, hn using Nat.le_induction with
Mathlib/Analysis/SpecificLimits/Normed.lean
193
208
/- Copyright (c) 2021 Jakob von Raumer. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jakob von Raumer -/ import Mathlib.Tactic.CategoryTheory.Monoidal.Basic import Mathlib.CategoryTheory.Closed.Monoidal import Mathlib.Tactic.ApplyFun /-! # Rigid (autonomous) monoidal categories This file defines rigid (autonomous) monoidal categories and the necessary theory about exact pairings and duals. ## Main definitions * `ExactPairing` of two objects of a monoidal category * Type classes `HasLeftDual` and `HasRightDual` that capture that a pairing exists * The `rightAdjointMate f` as a morphism `fᘁ : Yᘁ ⟶ Xᘁ` for a morphism `f : X ⟶ Y` * The classes of `RightRigidCategory`, `LeftRigidCategory` and `RigidCategory` ## Main statements * `comp_rightAdjointMate`: The adjoint mates of the composition is the composition of adjoint mates. ## Notations * `η_` and `ε_` denote the coevaluation and evaluation morphism of an exact pairing. * `Xᘁ` and `ᘁX` denote the right and left dual of an object, as well as the adjoint mate of a morphism. ## Future work * Show that `X ⊗ Y` and `Yᘁ ⊗ Xᘁ` form an exact pairing. * Show that the left adjoint mate of the right adjoint mate of a morphism is the morphism itself. * Simplify constructions in the case where a symmetry or braiding is present. * Show that `ᘁ` gives an equivalence of categories `C ≅ (Cᵒᵖ)ᴹᵒᵖ`. * Define pivotal categories (rigid categories equipped with a natural isomorphism `ᘁᘁ ≅ 𝟙 C`). ## Notes Although we construct the adjunction `tensorLeft Y ⊣ tensorLeft X` from `ExactPairing X Y`, this is not a bijective correspondence. I think the correct statement is that `tensorLeft Y` and `tensorLeft X` are module endofunctors of `C` as a right `C` module category, and `ExactPairing X Y` is in bijection with adjunctions compatible with this right `C` action. ## References * <https://ncatlab.org/nlab/show/rigid+monoidal+category> ## Tags rigid category, monoidal category -/ open CategoryTheory MonoidalCategory universe v v₁ v₂ v₃ u u₁ u₂ u₃ noncomputable section namespace CategoryTheory variable {C : Type u₁} [Category.{v₁} C] [MonoidalCategory C] /-- An exact pairing is a pair of objects `X Y : C` which admit a coevaluation and evaluation morphism which fulfill two triangle equalities. -/ class ExactPairing (X Y : C) where /-- Coevaluation of an exact pairing. Do not use directly. Use `ExactPairing.coevaluation` instead. -/ coevaluation' : 𝟙_ C ⟶ X ⊗ Y /-- Evaluation of an exact pairing. Do not use directly. Use `ExactPairing.evaluation` instead. -/ evaluation' : Y ⊗ X ⟶ 𝟙_ C coevaluation_evaluation' : Y ◁ coevaluation' ≫ (α_ _ _ _).inv ≫ evaluation' ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := by aesop_cat evaluation_coevaluation' : coevaluation' ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ evaluation' = (λ_ X).hom ≫ (ρ_ X).inv := by aesop_cat namespace ExactPairing -- Porting note: as there is no mechanism equivalent to `[]` in Lean 3 to make -- arguments for class fields explicit, -- we now repeat all the fields without primes. -- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Making.20variable.20in.20class.20field.20explicit variable (X Y : C) variable [ExactPairing X Y] /-- Coevaluation of an exact pairing. -/ def coevaluation : 𝟙_ C ⟶ X ⊗ Y := @coevaluation' _ _ _ X Y _ /-- Evaluation of an exact pairing. -/ def evaluation : Y ⊗ X ⟶ 𝟙_ C := @evaluation' _ _ _ X Y _ @[inherit_doc] notation "η_" => ExactPairing.coevaluation @[inherit_doc] notation "ε_" => ExactPairing.evaluation lemma coevaluation_evaluation : Y ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ ε_ X _ ▷ Y = (ρ_ Y).hom ≫ (λ_ Y).inv := coevaluation_evaluation' lemma evaluation_coevaluation : η_ _ _ ▷ X ≫ (α_ _ _ _).hom ≫ X ◁ ε_ _ Y = (λ_ X).hom ≫ (ρ_ X).inv := evaluation_coevaluation' lemma coevaluation_evaluation'' : Y ◁ η_ X Y ⊗≫ ε_ X Y ▷ Y = ⊗𝟙.hom := by convert coevaluation_evaluation X Y <;> simp [monoidalComp] lemma evaluation_coevaluation'' : η_ X Y ▷ X ⊗≫ X ◁ ε_ X Y = ⊗𝟙.hom := by convert evaluation_coevaluation X Y <;> simp [monoidalComp] end ExactPairing attribute [reassoc (attr := simp)] ExactPairing.coevaluation_evaluation attribute [reassoc (attr := simp)] ExactPairing.evaluation_coevaluation instance exactPairingUnit : ExactPairing (𝟙_ C) (𝟙_ C) where coevaluation' := (ρ_ _).inv evaluation' := (ρ_ _).hom coevaluation_evaluation' := by monoidal_coherence evaluation_coevaluation' := by monoidal_coherence /-- A class of objects which have a right dual. -/ class HasRightDual (X : C) where /-- The right dual of the object `X`. -/ rightDual : C [exact : ExactPairing X rightDual] /-- A class of objects which have a left dual. -/ class HasLeftDual (Y : C) where /-- The left dual of the object `X`. -/ leftDual : C [exact : ExactPairing leftDual Y] attribute [instance] HasRightDual.exact attribute [instance] HasLeftDual.exact open ExactPairing HasRightDual HasLeftDual MonoidalCategory #adaptation_note /-- https://github.com/leanprover/lean4/pull/4596 The overlapping notation for `leftDual` and `leftAdjointMate` become more problematic in after https://github.com/leanprover/lean4/pull/4596, and we sometimes have to disambiguate with e.g. `(ᘁX : C)` where previously just `ᘁX` was enough. -/ @[inherit_doc] prefix:1024 "ᘁ" => leftDual @[inherit_doc] postfix:1024 "ᘁ" => rightDual instance hasRightDualUnit : HasRightDual (𝟙_ C) where rightDual := 𝟙_ C instance hasLeftDualUnit : HasLeftDual (𝟙_ C) where leftDual := 𝟙_ C instance hasRightDualLeftDual {X : C} [HasLeftDual X] : HasRightDual ᘁX where rightDual := X instance hasLeftDualRightDual {X : C} [HasRightDual X] : HasLeftDual Xᘁ where leftDual := X @[simp] theorem leftDual_rightDual {X : C} [HasRightDual X] : ᘁXᘁ = X := rfl @[simp] theorem rightDual_leftDual {X : C} [HasLeftDual X] : (ᘁX)ᘁ = X := rfl /-- The right adjoint mate `fᘁ : Xᘁ ⟶ Yᘁ` of a morphism `f : X ⟶ Y`. -/ def rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : Yᘁ ⟶ Xᘁ := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ _ ◁ f ▷ _ ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom /-- The left adjoint mate `ᘁf : ᘁY ⟶ ᘁX` of a morphism `f : X ⟶ Y`. -/ def leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : ᘁY ⟶ ᘁX := (λ_ _).inv ≫ η_ (ᘁX) X ▷ _ ≫ (_ ◁ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom @[inherit_doc] notation f "ᘁ" => rightAdjointMate f @[inherit_doc] notation "ᘁ" f => leftAdjointMate f @[simp] theorem rightAdjointMate_id {X : C} [HasRightDual X] : (𝟙 X)ᘁ = 𝟙 (Xᘁ) := by simp [rightAdjointMate] @[simp] theorem leftAdjointMate_id {X : C} [HasLeftDual X] : (ᘁ(𝟙 X)) = 𝟙 (ᘁX) := by simp [leftAdjointMate] theorem rightAdjointMate_comp {X Y Z : C} [HasRightDual X] [HasRightDual Y] {f : X ⟶ Y} {g : Xᘁ ⟶ Z} : fᘁ ≫ g = (ρ_ (Yᘁ)).inv ≫ _ ◁ η_ X (Xᘁ) ≫ _ ◁ (f ⊗ g) ≫ (α_ (Yᘁ) Y Z).inv ≫ ε_ Y (Yᘁ) ▷ _ ≫ (λ_ Z).hom := calc _ = 𝟙 _ ⊗≫ (Yᘁ : C) ◁ η_ X Xᘁ ≫ Yᘁ ◁ f ▷ Xᘁ ⊗≫ (ε_ Y Yᘁ ▷ Xᘁ ≫ 𝟙_ C ◁ g) ⊗≫ 𝟙 _ := by dsimp only [rightAdjointMate]; monoidal _ = _ := by rw [← whisker_exchange, tensorHom_def]; monoidal theorem leftAdjointMate_comp {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] {f : X ⟶ Y} {g : (ᘁX) ⟶ Z} : (ᘁf) ≫ g = (λ_ _).inv ≫ η_ (ᘁX : C) X ▷ _ ≫ (g ⊗ f) ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom := calc _ = 𝟙 _ ⊗≫ η_ (ᘁX : C) X ▷ (ᘁY) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ⊗≫ ((ᘁX) ◁ ε_ (ᘁY) Y ≫ g ▷ 𝟙_ C) ⊗≫ 𝟙 _ := by dsimp only [leftAdjointMate]; monoidal _ = _ := by rw [whisker_exchange, tensorHom_def']; monoidal /-- The composition of right adjoint mates is the adjoint mate of the composition. -/ @[reassoc] theorem comp_rightAdjointMate {X Y Z : C} [HasRightDual X] [HasRightDual Y] [HasRightDual Z] {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g)ᘁ = gᘁ ≫ fᘁ := by rw [rightAdjointMate_comp] simp only [rightAdjointMate, comp_whiskerRight] simp only [← Category.assoc]; congr 3; simp only [Category.assoc] simp only [← MonoidalCategory.whiskerLeft_comp]; congr 2 symm calc _ = 𝟙 _ ⊗≫ (η_ Y Yᘁ ▷ 𝟙_ C ≫ (Y ⊗ Yᘁ) ◁ η_ X Xᘁ) ⊗≫ Y ◁ Yᘁ ◁ f ▷ Xᘁ ⊗≫ Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by rw [tensorHom_def']; monoidal _ = η_ X Xᘁ ⊗≫ (η_ Y Yᘁ ▷ (X ⊗ Xᘁ) ≫ (Y ⊗ Yᘁ) ◁ f ▷ Xᘁ) ⊗≫ Y ◁ ε_ Y Yᘁ ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; monoidal _ = η_ X Xᘁ ⊗≫ f ▷ Xᘁ ⊗≫ (η_ Y Yᘁ ▷ Y ⊗≫ Y ◁ ε_ Y Yᘁ) ▷ Xᘁ ⊗≫ g ▷ Xᘁ ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; monoidal _ = η_ X Xᘁ ≫ f ▷ Xᘁ ≫ g ▷ Xᘁ := by rw [evaluation_coevaluation'']; monoidal /-- The composition of left adjoint mates is the adjoint mate of the composition. -/ @[reassoc] theorem comp_leftAdjointMate {X Y Z : C} [HasLeftDual X] [HasLeftDual Y] [HasLeftDual Z] {f : X ⟶ Y} {g : Y ⟶ Z} : (ᘁf ≫ g) = (ᘁg) ≫ ᘁf := by rw [leftAdjointMate_comp] simp only [leftAdjointMate, MonoidalCategory.whiskerLeft_comp] simp only [← Category.assoc]; congr 3; simp only [Category.assoc] simp only [← comp_whiskerRight]; congr 2 symm calc _ = 𝟙 _ ⊗≫ ((𝟙_ C) ◁ η_ (ᘁY) Y ≫ η_ (ᘁX) X ▷ ((ᘁY) ⊗ Y)) ⊗≫ (ᘁX) ◁ f ▷ (ᘁY) ▷ Y ⊗≫ (ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by rw [tensorHom_def]; monoidal _ = η_ (ᘁX) X ⊗≫ (((ᘁX) ⊗ X) ◁ η_ (ᘁY) Y ≫ ((ᘁX) ◁ f) ▷ ((ᘁY) ⊗ Y)) ⊗≫ (ᘁX) ◁ ε_ (ᘁY) Y ▷ Y ⊗≫ (ᘁX) ◁ g := by rw [whisker_exchange]; monoidal _ = η_ (ᘁX) X ⊗≫ ((ᘁX) ◁ f) ⊗≫ (ᘁX) ◁ (Y ◁ η_ (ᘁY) Y ⊗≫ ε_ (ᘁY) Y ▷ Y) ⊗≫ (ᘁX) ◁ g := by rw [whisker_exchange]; monoidal _ = η_ (ᘁX) X ≫ (ᘁX) ◁ f ≫ (ᘁX) ◁ g := by rw [coevaluation_evaluation'']; monoidal /-- Given an exact pairing on `Y Y'`, we get a bijection on hom-sets `(Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z)` by "pulling the string on the left" up or down. This gives the adjunction `tensorLeftAdjunction Y Y' : tensorLeft Y' ⊣ tensorLeft Y`. This adjunction is often referred to as "Frobenius reciprocity" in the fusion categories / planar algebras / subfactors literature. -/ def tensorLeftHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (Y' ⊗ X ⟶ Z) ≃ (X ⟶ Y ⊗ Z) where toFun f := (λ_ _).inv ≫ η_ _ _ ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ f invFun f := Y' ◁ f ≫ (α_ _ _ _).inv ≫ ε_ _ _ ▷ _ ≫ (λ_ _).hom left_inv f := by calc _ = 𝟙 _ ⊗≫ Y' ◁ η_ Y Y' ▷ X ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by monoidal _ = 𝟙 _ ⊗≫ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ▷ X ⊗≫ f := by rw [whisker_exchange]; monoidal _ = f := by rw [coevaluation_evaluation'']; monoidal right_inv f := by calc _ = 𝟙 _ ⊗≫ (η_ Y Y' ▷ X ≫ (Y ⊗ Y') ◁ f) ⊗≫ Y ◁ ε_ Y Y' ▷ Z ⊗≫ 𝟙 _ := by monoidal _ = f ⊗≫ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ▷ Z ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; monoidal _ = f := by rw [evaluation_coevaluation'']; monoidal /-- Given an exact pairing on `Y Y'`, we get a bijection on hom-sets `(X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y')` by "pulling the string on the right" up or down. -/ def tensorRightHomEquiv (X Y Y' Z : C) [ExactPairing Y Y'] : (X ⊗ Y ⟶ Z) ≃ (X ⟶ Z ⊗ Y') where toFun f := (ρ_ _).inv ≫ _ ◁ η_ _ _ ≫ (α_ _ _ _).inv ≫ f ▷ _ invFun f := f ▷ _ ≫ (α_ _ _ _).hom ≫ _ ◁ ε_ _ _ ≫ (ρ_ _).hom left_inv f := by calc _ = 𝟙 _ ⊗≫ X ◁ η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by monoidal _ = 𝟙 _ ⊗≫ X ◁ (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by rw [← whisker_exchange]; monoidal _ = f := by rw [evaluation_coevaluation'']; monoidal right_inv f := by calc _ = 𝟙 _ ⊗≫ (X ◁ η_ Y Y' ≫ f ▷ (Y ⊗ Y')) ⊗≫ Z ◁ ε_ Y Y' ▷ Y' ⊗≫ 𝟙 _ := by monoidal _ = f ⊗≫ Z ◁ (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ 𝟙 _ := by rw [whisker_exchange]; monoidal _ = f := by rw [coevaluation_evaluation'']; monoidal theorem tensorLeftHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : Y' ⊗ X ⟶ Z) (g : Z ⟶ Z') : (tensorLeftHomEquiv X Y Y' Z') (f ≫ g) = (tensorLeftHomEquiv X Y Y' Z) f ≫ Y ◁ g := by simp [tensorLeftHomEquiv] theorem tensorLeftHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X') (g : X' ⟶ Y ⊗ Z) : (tensorLeftHomEquiv X Y Y' Z).symm (f ≫ g) = _ ◁ f ≫ (tensorLeftHomEquiv X' Y Y' Z).symm g := by simp [tensorLeftHomEquiv] theorem tensorRightHomEquiv_naturality {X Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⊗ Y ⟶ Z) (g : Z ⟶ Z') : (tensorRightHomEquiv X Y Y' Z') (f ≫ g) = (tensorRightHomEquiv X Y Y' Z) f ≫ g ▷ Y' := by simp [tensorRightHomEquiv] theorem tensorRightHomEquiv_symm_naturality {X X' Y Y' Z : C} [ExactPairing Y Y'] (f : X ⟶ X') (g : X' ⟶ Z ⊗ Y') : (tensorRightHomEquiv X Y Y' Z).symm (f ≫ g) = f ▷ Y ≫ (tensorRightHomEquiv X' Y Y' Z).symm g := by simp [tensorRightHomEquiv] /-- If `Y Y'` have an exact pairing, then the functor `tensorLeft Y'` is left adjoint to `tensorLeft Y`. -/ def tensorLeftAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorLeft Y' ⊣ tensorLeft Y := Adjunction.mkOfHomEquiv { homEquiv := fun X Z => tensorLeftHomEquiv X Y Y' Z homEquiv_naturality_left_symm := fun f g => tensorLeftHomEquiv_symm_naturality f g homEquiv_naturality_right := fun f g => tensorLeftHomEquiv_naturality f g } /-- If `Y Y'` have an exact pairing, then the functor `tensor_right Y` is left adjoint to `tensor_right Y'`. -/ def tensorRightAdjunction (Y Y' : C) [ExactPairing Y Y'] : tensorRight Y ⊣ tensorRight Y' := Adjunction.mkOfHomEquiv { homEquiv := fun X Z => tensorRightHomEquiv X Y Y' Z homEquiv_naturality_left_symm := fun f g => tensorRightHomEquiv_symm_naturality f g homEquiv_naturality_right := fun f g => tensorRightHomEquiv_naturality f g } /-- If `Y` has a left dual `ᘁY`, then it is a closed object, with the internal hom functor `Y ⟶[C] -` given by left tensoring by `ᘁY`. This has to be a definition rather than an instance to avoid diamonds, for example between `category_theory.monoidal_closed.functor_closed` and `CategoryTheory.Monoidal.functorHasLeftDual`. Moreover, in concrete applications there is often a more useful definition of the internal hom object than `ᘁY ⊗ X`, in which case the closed structure shouldn't come from `has_left_dual` (e.g. in the category `FinVect k`, it is more convenient to define the internal hom as `Y →ₗ[k] X` rather than `ᘁY ⊗ X` even though these are naturally isomorphic). -/ def closedOfHasLeftDual (Y : C) [HasLeftDual Y] : Closed Y where rightAdj := tensorLeft (ᘁY) adj := tensorLeftAdjunction (ᘁY) Y /-- `tensorLeftHomEquiv` commutes with tensoring on the right -/ theorem tensorLeftHomEquiv_tensor {X X' Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⟶ Y ⊗ Z) (g : X' ⟶ Z') : (tensorLeftHomEquiv (X ⊗ X') Y Y' (Z ⊗ Z')).symm ((f ⊗ g) ≫ (α_ _ _ _).hom) = (α_ _ _ _).inv ≫ ((tensorLeftHomEquiv X Y Y' Z).symm f ⊗ g) := by simp [tensorLeftHomEquiv, tensorHom_def'] /-- `tensorRightHomEquiv` commutes with tensoring on the left -/ theorem tensorRightHomEquiv_tensor {X X' Y Y' Z Z' : C} [ExactPairing Y Y'] (f : X ⟶ Z ⊗ Y') (g : X' ⟶ Z') : (tensorRightHomEquiv (X' ⊗ X) Y Y' (Z' ⊗ Z)).symm ((g ⊗ f) ≫ (α_ _ _ _).inv) = (α_ _ _ _).hom ≫ (g ⊗ (tensorRightHomEquiv X Y Y' Z).symm f) := by simp [tensorRightHomEquiv, tensorHom_def] @[simp] theorem tensorLeftHomEquiv_symm_coevaluation_comp_whiskerLeft {Y Y' Z : C} [ExactPairing Y Y'] (f : Y' ⟶ Z) : (tensorLeftHomEquiv _ _ _ _).symm (η_ _ _ ≫ Y ◁ f) = (ρ_ _).hom ≫ f := by calc _ = Y' ◁ η_ Y Y' ⊗≫ ((Y' ⊗ Y) ◁ f ≫ ε_ Y Y' ▷ Z) ⊗≫ 𝟙 _ := by dsimp [tensorLeftHomEquiv]; monoidal _ = (Y' ◁ η_ Y Y' ⊗≫ ε_ Y Y' ▷ Y') ⊗≫ f := by rw [whisker_exchange]; monoidal _ = _ := by rw [coevaluation_evaluation'']; monoidal @[simp] theorem tensorLeftHomEquiv_symm_coevaluation_comp_whiskerRight {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : (tensorLeftHomEquiv _ _ _ _).symm (η_ _ _ ≫ f ▷ (Xᘁ)) = (ρ_ _).hom ≫ fᘁ := by dsimp [tensorLeftHomEquiv, rightAdjointMate] simp @[simp] theorem tensorRightHomEquiv_symm_coevaluation_comp_whiskerLeft {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : (tensorRightHomEquiv _ (ᘁY) _ _).symm (η_ (ᘁX : C) X ≫ (ᘁX : C) ◁ f) = (λ_ _).hom ≫ ᘁf := by dsimp [tensorRightHomEquiv, leftAdjointMate] simp @[simp] theorem tensorRightHomEquiv_symm_coevaluation_comp_whiskerRight {Y Y' Z : C} [ExactPairing Y Y'] (f : Y ⟶ Z) : (tensorRightHomEquiv _ Y _ _).symm (η_ Y Y' ≫ f ▷ Y') = (λ_ _).hom ≫ f := calc _ = η_ Y Y' ▷ Y ⊗≫ (f ▷ (Y' ⊗ Y) ≫ Z ◁ ε_ Y Y') ⊗≫ 𝟙 _ := by dsimp [tensorRightHomEquiv]; monoidal _ = (η_ Y Y' ▷ Y ⊗≫ Y ◁ ε_ Y Y') ⊗≫ f := by rw [← whisker_exchange]; monoidal _ = _ := by rw [evaluation_coevaluation'']; monoidal @[simp] theorem tensorLeftHomEquiv_whiskerLeft_comp_evaluation {Y Z : C} [HasLeftDual Z] (f : Y ⟶ ᘁZ) : (tensorLeftHomEquiv _ _ _ _) (Z ◁ f ≫ ε_ _ _) = f ≫ (ρ_ _).inv := calc _ = 𝟙 _ ⊗≫ (η_ (ᘁZ : C) Z ▷ Y ≫ ((ᘁZ) ⊗ Z) ◁ f) ⊗≫ (ᘁZ) ◁ ε_ (ᘁZ) Z := by dsimp [tensorLeftHomEquiv]; monoidal _ = f ⊗≫ (η_ (ᘁZ) Z ▷ (ᘁZ) ⊗≫ (ᘁZ) ◁ ε_ (ᘁZ) Z) := by rw [← whisker_exchange]; monoidal _ = _ := by rw [evaluation_coevaluation'']; monoidal @[simp] theorem tensorLeftHomEquiv_whiskerRight_comp_evaluation {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : (tensorLeftHomEquiv _ _ _ _) (f ▷ _ ≫ ε_ _ _) = (ᘁf) ≫ (ρ_ _).inv := by dsimp [tensorLeftHomEquiv, leftAdjointMate] simp @[simp] theorem tensorRightHomEquiv_whiskerLeft_comp_evaluation {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : (tensorRightHomEquiv _ _ _ _) ((Yᘁ : C) ◁ f ≫ ε_ _ _) = fᘁ ≫ (λ_ _).inv := by dsimp [tensorRightHomEquiv, rightAdjointMate] simp @[simp] theorem tensorRightHomEquiv_whiskerRight_comp_evaluation {X Y : C} [HasRightDual X] (f : Y ⟶ Xᘁ) : (tensorRightHomEquiv _ _ _ _) (f ▷ X ≫ ε_ X (Xᘁ)) = f ≫ (λ_ _).inv := calc _ = 𝟙 _ ⊗≫ (Y ◁ η_ X Xᘁ ≫ f ▷ (X ⊗ Xᘁ)) ⊗≫ ε_ X Xᘁ ▷ Xᘁ := by dsimp [tensorRightHomEquiv]; monoidal _ = f ⊗≫ (Xᘁ ◁ η_ X Xᘁ ⊗≫ ε_ X Xᘁ ▷ Xᘁ) := by rw [whisker_exchange]; monoidal _ = _ := by rw [coevaluation_evaluation'']; monoidal -- Next four lemmas passing `fᘁ` or `ᘁf` through (co)evaluations. @[reassoc] theorem coevaluation_comp_rightAdjointMate {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : η_ Y (Yᘁ) ≫ _ ◁ (fᘁ) = η_ _ _ ≫ f ▷ _ := by apply_fun (tensorLeftHomEquiv _ Y (Yᘁ) _).symm simp @[reassoc] theorem leftAdjointMate_comp_evaluation {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : X ◁ (ᘁf) ≫ ε_ _ _ = f ▷ _ ≫ ε_ _ _ := by apply_fun tensorLeftHomEquiv _ (ᘁX) X _ simp @[reassoc] theorem coevaluation_comp_leftAdjointMate {X Y : C} [HasLeftDual X] [HasLeftDual Y] (f : X ⟶ Y) : η_ (ᘁY) Y ≫ (ᘁf) ▷ Y = η_ (ᘁX) X ≫ (ᘁX) ◁ f := by apply_fun (tensorRightHomEquiv _ (ᘁY) Y _).symm simp @[reassoc] theorem rightAdjointMate_comp_evaluation {X Y : C} [HasRightDual X] [HasRightDual Y] (f : X ⟶ Y) : (fᘁ ▷ X) ≫ ε_ X (Xᘁ) = ((Yᘁ) ◁ f) ≫ ε_ Y (Yᘁ) := by apply_fun tensorRightHomEquiv _ X (Xᘁ) _ simp /-- Transport an exact pairing across an isomorphism in the first argument. -/ def exactPairingCongrLeft {X X' Y : C} [ExactPairing X' Y] (i : X ≅ X') : ExactPairing X Y where evaluation' := Y ◁ i.hom ≫ ε_ _ _ coevaluation' := η_ _ _ ≫ i.inv ▷ Y evaluation_coevaluation' := calc _ = η_ X' Y ▷ X ⊗≫ (i.inv ▷ (Y ⊗ X) ≫ X ◁ (Y ◁ i.hom)) ⊗≫ X ◁ ε_ X' Y := by monoidal _ = 𝟙 _ ⊗≫ (η_ X' Y ▷ X ≫ (X' ⊗ Y) ◁ i.hom) ⊗≫ (i.inv ▷ (Y ⊗ X') ≫ X ◁ ε_ X' Y) ⊗≫ 𝟙 _ := by rw [← whisker_exchange]; monoidal _ = 𝟙 _ ⊗≫ i.hom ⊗≫ (η_ X' Y ▷ X' ⊗≫ X' ◁ ε_ X' Y) ⊗≫ i.inv ⊗≫ 𝟙 _ := by rw [← whisker_exchange, ← whisker_exchange]; monoidal _ = 𝟙 _ ⊗≫ (i.hom ≫ i.inv) ⊗≫ 𝟙 _ := by rw [evaluation_coevaluation'']; monoidal _ = (λ_ X).hom ≫ (ρ_ X).inv := by rw [Iso.hom_inv_id] monoidal coevaluation_evaluation' := by calc _ = Y ◁ η_ X' Y ≫ Y ◁ (i.inv ≫ i.hom) ▷ Y ⊗≫ ε_ X' Y ▷ Y := by monoidal _ = Y ◁ η_ X' Y ⊗≫ ε_ X' Y ▷ Y := by rw [Iso.inv_hom_id]; monoidal _ = _ := by
rw [coevaluation_evaluation''] monoidal /-- Transport an exact pairing across an isomorphism in the second argument. -/
Mathlib/CategoryTheory/Monoidal/Rigid/Basic.lean
503
506
/- Copyright (c) 2022 Yaël Dillies, Sara Rousta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Sara Rousta -/ import Mathlib.Logic.Equiv.Set import Mathlib.Order.Interval.Set.OrderEmbedding import Mathlib.Order.SetNotation /-! # Properties of unbundled upper/lower sets This file proves results on `IsUpperSet` and `IsLowerSet`, including their interactions with set operations, images, preimages and order duals, and properties that reflect stronger assumptions on the underlying order (such as `PartialOrder` and `LinearOrder`). ## TODO * Lattice structure on antichains. * Order equivalence between upper/lower sets and antichains. -/ open OrderDual Set variable {α β : Type*} {ι : Sort*} {κ : ι → Sort*} attribute [aesop norm unfold] IsUpperSet IsLowerSet section LE variable [LE α] {s t : Set α} {a : α} theorem isUpperSet_empty : IsUpperSet (∅ : Set α) := fun _ _ _ => id theorem isLowerSet_empty : IsLowerSet (∅ : Set α) := fun _ _ _ => id theorem isUpperSet_univ : IsUpperSet (univ : Set α) := fun _ _ _ => id theorem isLowerSet_univ : IsLowerSet (univ : Set α) := fun _ _ _ => id theorem IsUpperSet.compl (hs : IsUpperSet s) : IsLowerSet sᶜ := fun _a _b h hb ha => hb <| hs h ha theorem IsLowerSet.compl (hs : IsLowerSet s) : IsUpperSet sᶜ := fun _a _b h hb ha => hb <| hs h ha @[simp] theorem isUpperSet_compl : IsUpperSet sᶜ ↔ IsLowerSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsLowerSet.compl⟩ @[simp] theorem isLowerSet_compl : IsLowerSet sᶜ ↔ IsUpperSet s := ⟨fun h => by convert h.compl rw [compl_compl], IsUpperSet.compl⟩ theorem IsUpperSet.union (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) theorem IsLowerSet.union (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∪ t) := fun _ _ h => Or.imp (hs h) (ht h) theorem IsUpperSet.inter (hs : IsUpperSet s) (ht : IsUpperSet t) : IsUpperSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) theorem IsLowerSet.inter (hs : IsLowerSet s) (ht : IsLowerSet t) : IsLowerSet (s ∩ t) := fun _ _ h => And.imp (hs h) (ht h) theorem isUpperSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ theorem isLowerSet_sUnion {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋃₀ S) := fun _ _ h => Exists.imp fun _ hs => ⟨hs.1, hf _ hs.1 h hs.2⟩ theorem isUpperSet_iUnion {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋃ i, f i) := isUpperSet_sUnion <| forall_mem_range.2 hf theorem isLowerSet_iUnion {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋃ i, f i) := isLowerSet_sUnion <| forall_mem_range.2 hf theorem isUpperSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋃ (i) (j), f i j) := isUpperSet_iUnion fun i => isUpperSet_iUnion <| hf i theorem isLowerSet_iUnion₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋃ (i) (j), f i j) := isLowerSet_iUnion fun i => isLowerSet_iUnion <| hf i theorem isUpperSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsUpperSet s) : IsUpperSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h theorem isLowerSet_sInter {S : Set (Set α)} (hf : ∀ s ∈ S, IsLowerSet s) : IsLowerSet (⋂₀ S) := fun _ _ h => forall₂_imp fun s hs => hf s hs h theorem isUpperSet_iInter {f : ι → Set α} (hf : ∀ i, IsUpperSet (f i)) : IsUpperSet (⋂ i, f i) := isUpperSet_sInter <| forall_mem_range.2 hf theorem isLowerSet_iInter {f : ι → Set α} (hf : ∀ i, IsLowerSet (f i)) : IsLowerSet (⋂ i, f i) := isLowerSet_sInter <| forall_mem_range.2 hf theorem isUpperSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsUpperSet (f i j)) : IsUpperSet (⋂ (i) (j), f i j) := isUpperSet_iInter fun i => isUpperSet_iInter <| hf i theorem isLowerSet_iInter₂ {f : ∀ i, κ i → Set α} (hf : ∀ i j, IsLowerSet (f i j)) : IsLowerSet (⋂ (i) (j), f i j) := isLowerSet_iInter fun i => isLowerSet_iInter <| hf i @[simp] theorem isLowerSet_preimage_ofDual_iff : IsLowerSet (ofDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem isUpperSet_preimage_ofDual_iff : IsUpperSet (ofDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl @[simp] theorem isLowerSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsLowerSet (toDual ⁻¹' s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem isUpperSet_preimage_toDual_iff {s : Set αᵒᵈ} : IsUpperSet (toDual ⁻¹' s) ↔ IsLowerSet s := Iff.rfl alias ⟨_, IsUpperSet.toDual⟩ := isLowerSet_preimage_ofDual_iff alias ⟨_, IsLowerSet.toDual⟩ := isUpperSet_preimage_ofDual_iff alias ⟨_, IsUpperSet.ofDual⟩ := isLowerSet_preimage_toDual_iff alias ⟨_, IsLowerSet.ofDual⟩ := isUpperSet_preimage_toDual_iff lemma IsUpperSet.isLowerSet_preimage_coe (hs : IsUpperSet s) : IsLowerSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t := by aesop lemma IsLowerSet.isUpperSet_preimage_coe (hs : IsLowerSet s) : IsUpperSet ((↑) ⁻¹' t : Set s) ↔ ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t := by aesop lemma IsUpperSet.sdiff (hs : IsUpperSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, b ≤ c → b ∈ t) : IsUpperSet (s \ t) := fun _b _c hbc hb ↦ ⟨hs hbc hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hbc⟩ lemma IsLowerSet.sdiff (hs : IsLowerSet s) (ht : ∀ b ∈ s, ∀ c ∈ t, c ≤ b → b ∈ t) : IsLowerSet (s \ t) := fun _b _c hcb hb ↦ ⟨hs hcb hb.1, fun hc ↦ hb.2 <| ht _ hb.1 _ hc hcb⟩ lemma IsUpperSet.sdiff_of_isLowerSet (hs : IsUpperSet s) (ht : IsLowerSet t) : IsUpperSet (s \ t) := hs.sdiff <| by aesop lemma IsLowerSet.sdiff_of_isUpperSet (hs : IsLowerSet s) (ht : IsUpperSet t) : IsLowerSet (s \ t) := hs.sdiff <| by aesop lemma IsUpperSet.erase (hs : IsUpperSet s) (has : ∀ b ∈ s, b ≤ a → b = a) : IsUpperSet (s \ {a}) := hs.sdiff <| by simpa using has lemma IsLowerSet.erase (hs : IsLowerSet s) (has : ∀ b ∈ s, a ≤ b → b = a) : IsLowerSet (s \ {a}) := hs.sdiff <| by simpa using has end LE section Preorder variable [Preorder α] [Preorder β] {s : Set α} {p : α → Prop} (a : α) theorem isUpperSet_Ici : IsUpperSet (Ici a) := fun _ _ => ge_trans theorem isLowerSet_Iic : IsLowerSet (Iic a) := fun _ _ => le_trans theorem isUpperSet_Ioi : IsUpperSet (Ioi a) := fun _ _ => flip lt_of_lt_of_le theorem isLowerSet_Iio : IsLowerSet (Iio a) := fun _ _ => lt_of_le_of_lt theorem isUpperSet_iff_Ici_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ici a ⊆ s := by simp [IsUpperSet, subset_def, @forall_swap (_ ∈ s)] theorem isLowerSet_iff_Iic_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iic a ⊆ s := by simp [IsLowerSet, subset_def, @forall_swap (_ ∈ s)] alias ⟨IsUpperSet.Ici_subset, _⟩ := isUpperSet_iff_Ici_subset alias ⟨IsLowerSet.Iic_subset, _⟩ := isLowerSet_iff_Iic_subset theorem IsUpperSet.Ioi_subset (h : IsUpperSet s) ⦃a⦄ (ha : a ∈ s) : Ioi a ⊆ s := Ioi_subset_Ici_self.trans <| h.Ici_subset ha theorem IsLowerSet.Iio_subset (h : IsLowerSet s) ⦃a⦄ (ha : a ∈ s) : Iio a ⊆ s := h.toDual.Ioi_subset ha theorem IsUpperSet.ordConnected (h : IsUpperSet s) : s.OrdConnected := ⟨fun _ ha _ _ => Icc_subset_Ici_self.trans <| h.Ici_subset ha⟩ theorem IsLowerSet.ordConnected (h : IsLowerSet s) : s.OrdConnected := ⟨fun _ _ _ hb => Icc_subset_Iic_self.trans <| h.Iic_subset hb⟩ theorem IsUpperSet.preimage (hs : IsUpperSet s) {f : β → α} (hf : Monotone f) : IsUpperSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h theorem IsLowerSet.preimage (hs : IsLowerSet s) {f : β → α} (hf : Monotone f) : IsLowerSet (f ⁻¹' s : Set β) := fun _ _ h => hs <| hf h theorem IsUpperSet.image (hs : IsUpperSet s) (f : α ≃o β) : IsUpperSet (f '' s : Set β) := by change IsUpperSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone theorem IsLowerSet.image (hs : IsLowerSet s) (f : α ≃o β) : IsLowerSet (f '' s : Set β) := by change IsLowerSet ((f : α ≃ β) '' s) rw [Set.image_equiv_eq_preimage_symm] exact hs.preimage f.symm.monotone theorem OrderEmbedding.image_Ici (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ici a = Ici (e a) := by rw [← e.preimage_Ici, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ici_subset (mem_range_self _)] theorem OrderEmbedding.image_Iic (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iic a = Iic (e a) := e.dual.image_Ici he a theorem OrderEmbedding.image_Ioi (e : α ↪o β) (he : IsUpperSet (range e)) (a : α) : e '' Ioi a = Ioi (e a) := by rw [← e.preimage_Ioi, image_preimage_eq_inter_range, inter_eq_left.2 <| he.Ioi_subset (mem_range_self _)] theorem OrderEmbedding.image_Iio (e : α ↪o β) (he : IsLowerSet (range e)) (a : α) : e '' Iio a = Iio (e a) := e.dual.image_Ioi he a @[simp] theorem Set.monotone_mem : Monotone (· ∈ s) ↔ IsUpperSet s := Iff.rfl @[simp] theorem Set.antitone_mem : Antitone (· ∈ s) ↔ IsLowerSet s := forall_swap @[simp] theorem isUpperSet_setOf : IsUpperSet { a | p a } ↔ Monotone p := Iff.rfl @[simp] theorem isLowerSet_setOf : IsLowerSet { a | p a } ↔ Antitone p := forall_swap lemma IsUpperSet.upperBounds_subset (hs : IsUpperSet s) : s.Nonempty → upperBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha lemma IsLowerSet.lowerBounds_subset (hs : IsLowerSet s) : s.Nonempty → lowerBounds s ⊆ s := fun ⟨_a, ha⟩ _b hb ↦ hs (hb ha) ha section OrderTop variable [OrderTop α] theorem IsLowerSet.top_mem (hs : IsLowerSet s) : ⊤ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs le_top h, fun h => h.symm ▸ mem_univ _⟩ theorem IsUpperSet.top_mem (hs : IsUpperSet s) : ⊤ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs le_top ha⟩ theorem IsUpperSet.not_top_mem (hs : IsUpperSet s) : ⊤ ∉ s ↔ s = ∅ := hs.top_mem.not.trans not_nonempty_iff_eq_empty end OrderTop section OrderBot variable [OrderBot α] theorem IsUpperSet.bot_mem (hs : IsUpperSet s) : ⊥ ∈ s ↔ s = univ := ⟨fun h => eq_univ_of_forall fun _ => hs bot_le h, fun h => h.symm ▸ mem_univ _⟩ theorem IsLowerSet.bot_mem (hs : IsLowerSet s) : ⊥ ∈ s ↔ s.Nonempty := ⟨fun h => ⟨_, h⟩, fun ⟨_a, ha⟩ => hs bot_le ha⟩ theorem IsLowerSet.not_bot_mem (hs : IsLowerSet s) : ⊥ ∉ s ↔ s = ∅ := hs.bot_mem.not.trans not_nonempty_iff_eq_empty end OrderBot section NoMaxOrder variable [NoMaxOrder α] theorem IsUpperSet.not_bddAbove (hs : IsUpperSet s) : s.Nonempty → ¬BddAbove s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_gt b exact hc.not_le (hb <| hs ((hb ha).trans hc.le) ha) theorem not_bddAbove_Ici : ¬BddAbove (Ici a) := (isUpperSet_Ici _).not_bddAbove nonempty_Ici theorem not_bddAbove_Ioi : ¬BddAbove (Ioi a) := (isUpperSet_Ioi _).not_bddAbove nonempty_Ioi end NoMaxOrder section NoMinOrder variable [NoMinOrder α] theorem IsLowerSet.not_bddBelow (hs : IsLowerSet s) : s.Nonempty → ¬BddBelow s := by rintro ⟨a, ha⟩ ⟨b, hb⟩ obtain ⟨c, hc⟩ := exists_lt b exact hc.not_le (hb <| hs (hc.le.trans <| hb ha) ha) theorem not_bddBelow_Iic : ¬BddBelow (Iic a) := (isLowerSet_Iic _).not_bddBelow nonempty_Iic theorem not_bddBelow_Iio : ¬BddBelow (Iio a) := (isLowerSet_Iio _).not_bddBelow nonempty_Iio end NoMinOrder end Preorder section PartialOrder variable [PartialOrder α] {s : Set α} theorem isUpperSet_iff_forall_lt : IsUpperSet s ↔ ∀ ⦃a b : α⦄, a < b → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] theorem isLowerSet_iff_forall_lt : IsLowerSet s ↔ ∀ ⦃a b : α⦄, b < a → a ∈ s → b ∈ s := forall_congr' fun a => by simp [le_iff_eq_or_lt, or_imp, forall_and] theorem isUpperSet_iff_Ioi_subset : IsUpperSet s ↔ ∀ ⦃a⦄, a ∈ s → Ioi a ⊆ s := by simp [isUpperSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] theorem isLowerSet_iff_Iio_subset : IsLowerSet s ↔ ∀ ⦃a⦄, a ∈ s → Iio a ⊆ s := by simp [isLowerSet_iff_forall_lt, subset_def, @forall_swap (_ ∈ s)] end PartialOrder section LinearOrder variable [LinearOrder α] {s t : Set α} theorem IsUpperSet.total (hs : IsUpperSet s) (ht : IsUpperSet t) : s ⊆ t ∨ t ⊆ s := by by_contra! h simp_rw [Set.not_subset] at h obtain ⟨⟨a, has, hat⟩, b, hbt, hbs⟩ := h obtain hab | hba := le_total a b · exact hbs (hs hab has) · exact hat (ht hba hbt) theorem IsLowerSet.total (hs : IsLowerSet s) (ht : IsLowerSet t) : s ⊆ t ∨ t ⊆ s := hs.toDual.total ht.toDual end LinearOrder
Mathlib/Order/UpperLower/Basic.lean
627
627
/- Copyright (c) 2019 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Yaël Dillies -/ import Mathlib.Data.List.Iterate import Mathlib.GroupTheory.Perm.Cycle.Basic import Mathlib.GroupTheory.NoncommPiCoprod import Mathlib.Tactic.Group /-! # Cycle factors of a permutation Let `β` be a `Fintype` and `f : Equiv.Perm β`. * `Equiv.Perm.cycleOf`: `f.cycleOf x` is the cycle of `f` that `x` belongs to. * `Equiv.Perm.cycleFactors`: `f.cycleFactors` is a list of disjoint cyclic permutations that multiply to `f`. -/ open Equiv Function Finset variable {ι α β : Type*} namespace Equiv.Perm /-! ### `cycleOf` -/ section CycleOf variable {f g : Perm α} {x y : α} /-- `f.cycleOf x` is the cycle of the permutation `f` to which `x` belongs. -/ def cycleOf (f : Perm α) [DecidableRel f.SameCycle] (x : α) : Perm α := ofSubtype (subtypePerm f fun _ => sameCycle_apply_right.symm : Perm { y // SameCycle f x y }) theorem cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (x y : α) : cycleOf f x y = if SameCycle f x y then f y else y := by dsimp only [cycleOf] split_ifs with h · apply ofSubtype_apply_of_mem exact h · apply ofSubtype_apply_of_not_mem exact h theorem cycleOf_inv (f : Perm α) [DecidableRel f.SameCycle] (x : α) : (cycleOf f x)⁻¹ = cycleOf f⁻¹ x := Equiv.ext fun y => by rw [inv_eq_iff_eq, cycleOf_apply, cycleOf_apply] split_ifs <;> simp_all [sameCycle_inv, sameCycle_inv_apply_right] @[simp] theorem cycleOf_pow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : ∀ n : ℕ, (cycleOf f x ^ n) x = (f ^ n) x := by intro n induction n with | zero => rfl | succ n hn => rw [pow_succ', mul_apply, cycleOf_apply, hn, if_pos, pow_succ', mul_apply] exact ⟨n, rfl⟩ @[simp] theorem cycleOf_zpow_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : ∀ n : ℤ, (cycleOf f x ^ n) x = (f ^ n) x := by intro z cases z with | ofNat z => exact cycleOf_pow_apply_self f x z | negSucc z => rw [zpow_negSucc, ← inv_pow, cycleOf_inv, zpow_negSucc, ← inv_pow, cycleOf_pow_apply_self] theorem SameCycle.cycleOf_apply [DecidableRel f.SameCycle] : SameCycle f x y → cycleOf f x y = f y := ofSubtype_apply_of_mem _ theorem cycleOf_apply_of_not_sameCycle [DecidableRel f.SameCycle] : ¬SameCycle f x y → cycleOf f x y = y := ofSubtype_apply_of_not_mem _ theorem SameCycle.cycleOf_eq [DecidableRel f.SameCycle] (h : SameCycle f x y) : cycleOf f x = cycleOf f y := by ext z rw [Equiv.Perm.cycleOf_apply] split_ifs with hz · exact (h.symm.trans hz).cycleOf_apply.symm · exact (cycleOf_apply_of_not_sameCycle (mt h.trans hz)).symm @[simp] theorem cycleOf_apply_apply_zpow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℤ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by rw [SameCycle.cycleOf_apply] · rw [add_comm, zpow_add, zpow_one, mul_apply] · exact ⟨k, rfl⟩ @[simp] theorem cycleOf_apply_apply_pow_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) (k : ℕ) : cycleOf f x ((f ^ k) x) = (f ^ (k + 1) : Perm α) x := by convert cycleOf_apply_apply_zpow_self f x k using 1 @[simp] theorem cycleOf_apply_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x (f x) = f (f x) := by convert cycleOf_apply_apply_pow_self f x 1 using 1 @[simp] theorem cycleOf_apply_self (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f x x = f x := SameCycle.rfl.cycleOf_apply theorem IsCycle.cycleOf_eq [DecidableRel f.SameCycle] (hf : IsCycle f) (hx : f x ≠ x) : cycleOf f x = f := Equiv.ext fun y => if h : SameCycle f x y then by rw [h.cycleOf_apply] else by rw [cycleOf_apply_of_not_sameCycle h, Classical.not_not.1 (mt ((isCycle_iff_sameCycle hx).1 hf).2 h)] @[simp] theorem cycleOf_eq_one_iff (f : Perm α) [DecidableRel f.SameCycle] : cycleOf f x = 1 ↔ f x = x := by simp_rw [Perm.ext_iff, cycleOf_apply, one_apply] refine ⟨fun h => (if_pos (SameCycle.refl f x)).symm.trans (h x), fun h y => ?_⟩ by_cases hy : f y = y · rw [hy, ite_self] · exact if_neg (mt SameCycle.apply_eq_self_iff (by tauto)) @[simp] theorem cycleOf_self_apply (f : Perm α) [DecidableRel f.SameCycle] (x : α) : cycleOf f (f x) = cycleOf f x := (sameCycle_apply_right.2 SameCycle.rfl).symm.cycleOf_eq @[simp] theorem cycleOf_self_apply_pow (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.pow_left.cycleOf_eq @[simp] theorem cycleOf_self_apply_zpow (f : Perm α) [DecidableRel f.SameCycle] (n : ℤ) (x : α) : cycleOf f ((f ^ n) x) = cycleOf f x := SameCycle.rfl.zpow_left.cycleOf_eq protected theorem IsCycle.cycleOf [DecidableRel f.SameCycle] [DecidableEq α] (hf : IsCycle f) : cycleOf f x = if f x = x then 1 else f := by by_cases hx : f x = x · rwa [if_pos hx, cycleOf_eq_one_iff] · rwa [if_neg hx, hf.cycleOf_eq] theorem cycleOf_one [DecidableRel (1 : Perm α).SameCycle] (x : α) : cycleOf 1 x = 1 := (cycleOf_eq_one_iff 1).mpr rfl theorem isCycle_cycleOf (f : Perm α) [DecidableRel f.SameCycle] (hx : f x ≠ x) : IsCycle (cycleOf f x) := have : cycleOf f x x ≠ x := by rwa [SameCycle.rfl.cycleOf_apply] (isCycle_iff_sameCycle this).2 @fun y => ⟨fun h => mt h.apply_eq_self_iff.2 this, fun h => if hxy : SameCycle f x y then let ⟨i, hi⟩ := hxy ⟨i, by rw [cycleOf_zpow_apply_self, hi]⟩ else by
rw [cycleOf_apply_of_not_sameCycle hxy] at h exact (h rfl).elim⟩ theorem pow_mod_orderOf_cycleOf_apply (f : Perm α) [DecidableRel f.SameCycle] (n : ℕ) (x : α) : (f ^ (n % orderOf (cycleOf f x))) x = (f ^ n) x := by
Mathlib/GroupTheory/Perm/Cycle/Factors.lean
160
164
/- Copyright (c) 2020 Markus Himmel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Markus Himmel, Adam Topaz, Johan Commelin, Jakob von Raumer -/ import Mathlib.Algebra.Homology.ImageToKernel import Mathlib.Algebra.Homology.ShortComplex.Exact import Mathlib.CategoryTheory.Abelian.Opposite import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels import Mathlib.CategoryTheory.Adjunction.Limits import Mathlib.Tactic.TFAE /-! # Exact sequences in abelian categories In an abelian category, we get several interesting results related to exactness which are not true in more general settings. ## Main results * A short complex `S` is exact iff `imageSubobject S.f = kernelSubobject S.g`. * If `(f, g)` is exact, then `image.ι f` has the universal property of the kernel of `g`. * `f` is a monomorphism iff `kernel.ι f = 0` iff `Exact 0 f`, and `f` is an epimorphism iff `cokernel.π = 0` iff `Exact f 0`. * A faithful functor between abelian categories that preserves zero morphisms reflects exact sequences. * `X ⟶ Y ⟶ Z ⟶ 0` is exact if and only if the second map is a cokernel of the first, and `0 ⟶ X ⟶ Y ⟶ Z` is exact if and only if the first map is a kernel of the second. * A functor `F` such that for all `S`, we have `S.Exact → (S.map F).Exact` preserves both finite limits and colimits. -/ universe v₁ v₂ u₁ u₂ noncomputable section open CategoryTheory Limits Preadditive variable {C : Type u₁} [Category.{v₁} C] [Abelian C] namespace CategoryTheory namespace ShortComplex variable (S : ShortComplex C) attribute [local instance] hasEqualizers_of_hasKernels theorem exact_iff_epi_imageToKernel' : S.Exact ↔ Epi (imageToKernel' S.f S.g S.zero) := by rw [S.exact_iff_epi_kernel_lift] have : factorThruImage S.f ≫ imageToKernel' S.f S.g S.zero = kernel.lift S.g S.f S.zero := by simp only [← cancel_mono (kernel.ι _), kernel.lift_ι, imageToKernel', Category.assoc, image.fac] constructor · intro exact epi_of_epi_fac this · intro rw [← this] apply epi_comp theorem exact_iff_epi_imageToKernel : S.Exact ↔ Epi (imageToKernel S.f S.g S.zero) := by rw [S.exact_iff_epi_imageToKernel'] apply (MorphismProperty.epimorphisms C).arrow_mk_iso_iff exact Arrow.isoMk (imageSubobjectIso S.f).symm (kernelSubobjectIso S.g).symm theorem exact_iff_isIso_imageToKernel : S.Exact ↔ IsIso (imageToKernel S.f S.g S.zero) := by rw [S.exact_iff_epi_imageToKernel] constructor · intro apply isIso_of_mono_of_epi · intro infer_instance /-- In an abelian category, a short complex `S` is exact iff `imageSubobject S.f = kernelSubobject S.g`. -/ theorem exact_iff_image_eq_kernel : S.Exact ↔ imageSubobject S.f = kernelSubobject S.g := by rw [exact_iff_isIso_imageToKernel] constructor · intro exact Subobject.eq_of_comm (asIso (imageToKernel _ _ S.zero)) (by simp) · intro h exact ⟨Subobject.ofLE _ _ h.ge, by ext; simp, by ext; simp⟩ theorem exact_iff_of_forks {cg : KernelFork S.g} (hg : IsLimit cg) {cf : CokernelCofork S.f} (hf : IsColimit cf) : S.Exact ↔ cg.ι ≫ cf.π = 0 := by rw [exact_iff_kernel_ι_comp_cokernel_π_zero] let e₁ := IsLimit.conePointUniqueUpToIso (kernelIsKernel S.g) hg let e₂ := IsColimit.coconePointUniqueUpToIso (cokernelIsCokernel S.f) hf have : cg.ι ≫ cf.π = e₁.inv ≫ kernel.ι S.g ≫ cokernel.π S.f ≫ e₂.hom := by have eq₁ := IsLimit.conePointUniqueUpToIso_inv_comp (kernelIsKernel S.g) hg (.zero) have eq₂ := IsColimit.comp_coconePointUniqueUpToIso_hom (cokernelIsCokernel S.f) hf (.one) dsimp at eq₁ eq₂ rw [← eq₁, ← eq₂, Category.assoc] rw [this, IsIso.comp_left_eq_zero e₁.inv, ← Category.assoc, IsIso.comp_right_eq_zero _ e₂.hom] variable {S} /-- If `(f, g)` is exact, then `Abelian.image.ι S.f` is a kernel of `S.g`. -/ def Exact.isLimitImage (h : S.Exact) : IsLimit (KernelFork.ofι (Abelian.image.ι S.f) (Abelian.image_ι_comp_eq_zero S.zero) : KernelFork S.g) := by rw [exact_iff_kernel_ι_comp_cokernel_π_zero] at h exact KernelFork.IsLimit.ofι _ _ (fun u hu ↦ kernel.lift (cokernel.π S.f) u (by rw [← kernel.lift_ι S.g u hu, Category.assoc, h, comp_zero])) (by simp) (fun _ _ _ hm => by rw [← cancel_mono (Abelian.image.ι S.f), hm, kernel.lift_ι]) /-- If `(f, g)` is exact, then `image.ι f` is a kernel of `g`. -/ def Exact.isLimitImage' (h : S.Exact) : IsLimit (KernelFork.ofι (Limits.image.ι S.f) (image_ι_comp_eq_zero S.zero) : KernelFork S.g) := IsKernel.isoKernel _ _ h.isLimitImage (Abelian.imageIsoImage S.f).symm <| IsImage.lift_fac _ _ /-- If `(f, g)` is exact, then `Abelian.coimage.π g` is a cokernel of `f`. -/ def Exact.isColimitCoimage (h : S.Exact) : IsColimit (CokernelCofork.ofπ (Abelian.coimage.π S.g) (Abelian.comp_coimage_π_eq_zero S.zero) : CokernelCofork S.f) := by rw [exact_iff_kernel_ι_comp_cokernel_π_zero] at h refine CokernelCofork.IsColimit.ofπ _ _ (fun u hu => cokernel.desc (kernel.ι S.g) u (by rw [← cokernel.π_desc S.f u hu, ← Category.assoc, h, zero_comp])) (by simp) ?_ intros _ _ _ _ hm ext rw [hm, cokernel.π_desc] /-- If `(f, g)` is exact, then `factorThruImage g` is a cokernel of `f`. -/ def Exact.isColimitImage (h : S.Exact) : IsColimit (CokernelCofork.ofπ (Limits.factorThruImage S.g) (comp_factorThruImage_eq_zero S.zero)) := IsCokernel.cokernelIso _ _ h.isColimitCoimage (Abelian.coimageIsoImage' S.g) <| (cancel_mono (Limits.image.ι S.g)).1 <| by simp theorem exact_kernel {X Y : C} (f : X ⟶ Y) : (ShortComplex.mk (kernel.ι f) f (by simp)).Exact := exact_of_f_is_kernel _ (kernelIsKernel f) theorem exact_cokernel {X Y : C} (f : X ⟶ Y) : (ShortComplex.mk f (cokernel.π f) (by simp)).Exact := exact_of_g_is_cokernel _ (cokernelIsCokernel f) variable (S) theorem exact_iff_exact_image_ι : S.Exact ↔ (ShortComplex.mk (Abelian.image.ι S.f) S.g (Abelian.image_ι_comp_eq_zero S.zero)).Exact := ShortComplex.exact_iff_of_epi_of_isIso_of_mono { τ₁ := Abelian.factorThruImage S.f τ₂ := 𝟙 _ τ₃ := 𝟙 _ } theorem exact_iff_exact_coimage_π : S.Exact ↔ (ShortComplex.mk S.f (Abelian.coimage.π S.g) (Abelian.comp_coimage_π_eq_zero S.zero)).Exact := by symm exact ShortComplex.exact_iff_of_epi_of_isIso_of_mono { τ₁ := 𝟙 _ τ₂ := 𝟙 _ τ₃ := Abelian.factorThruCoimage S.g } end ShortComplex section open List in theorem Abelian.tfae_mono {X Y : C} (f : X ⟶ Y) (Z : C) : TFAE [Mono f, kernel.ι f = 0, (ShortComplex.mk (0 : Z ⟶ X) f zero_comp).Exact] := by tfae_have 2 → 1 := mono_of_kernel_ι_eq_zero _ tfae_have 1 → 2 | _ => by rw [← cancel_mono f, kernel.condition, zero_comp] tfae_have 3 ↔ 1 := ShortComplex.exact_iff_mono _ (by simp) tfae_finish open List in theorem Abelian.tfae_epi {X Y : C} (f : X ⟶ Y) (Z : C) : TFAE [Epi f, cokernel.π f = 0, (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).Exact] := by tfae_have 2 → 1 := epi_of_cokernel_π_eq_zero _ tfae_have 1 → 2 | _ => by rw [← cancel_epi f, cokernel.condition, comp_zero] tfae_have 3 ↔ 1 := ShortComplex.exact_iff_epi _ (by simp) tfae_finish end namespace Functor section variable {D : Type u₂} [Category.{v₂} D] [Abelian D] variable (F : C ⥤ D) [PreservesZeroMorphisms F] lemma reflects_exact_of_faithful [F.Faithful] (S : ShortComplex C) (hS : (S.map F).Exact) : S.Exact := by rw [ShortComplex.exact_iff_kernel_ι_comp_cokernel_π_zero] at hS ⊢ dsimp at hS apply F.zero_of_map_zero obtain ⟨k, hk⟩ := kernel.lift' (F.map S.g) (F.map (kernel.ι S.g)) (by simp only [← F.map_comp, kernel.condition, CategoryTheory.Functor.map_zero]) obtain ⟨l, hl⟩ := cokernel.desc' (F.map S.f) (F.map (cokernel.π S.f)) (by simp only [← F.map_comp, cokernel.condition, CategoryTheory.Functor.map_zero]) rw [F.map_comp, ← hl, ← hk, Category.assoc, reassoc_of% hS, zero_comp, comp_zero] end end Functor namespace Functor open Limits Abelian variable {A : Type u₁} {B : Type u₂} [Category.{v₁} A] [Category.{v₂} B] variable [Abelian A] [Abelian B] variable (L : A ⥤ B) section variable [L.PreservesZeroMorphisms] variable (hL : ∀ (S : ShortComplex A), S.Exact → (S.map L).Exact) include hL open ZeroObject /-- A functor which preserves exactness preserves monomorphisms. -/ theorem preservesMonomorphisms_of_map_exact : L.PreservesMonomorphisms where preserves f hf := by apply ((Abelian.tfae_mono (L.map f) (L.obj 0)).out 2 0).mp refine ShortComplex.exact_of_iso ?_ (hL _ (((tfae_mono f 0).out 0 2).mp hf)) exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _) /-- A functor which preserves exactness preserves epimorphisms. -/ theorem preservesEpimorphisms_of_map_exact : L.PreservesEpimorphisms where preserves f hf := by apply ((Abelian.tfae_epi (L.map f) (L.obj 0)).out 2 0).mp refine ShortComplex.exact_of_iso ?_ (hL _ (((tfae_epi f 0).out 0 2).mp hf)) exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _) /-- A functor which preserves the exactness of short complexes preserves homology. -/ lemma preservesHomology_of_map_exact : L.PreservesHomology where preservesCokernels X Y f := by have := preservesEpimorphisms_of_map_exact _ hL apply preservesColimit_of_preserves_colimit_cocone (cokernelIsCokernel f) apply (CokernelCofork.isColimitMapCoconeEquiv _ L).2 have : Epi ((ShortComplex.mk _ _ (cokernel.condition f)).map L).g := by dsimp infer_instance exact (hL (ShortComplex.mk _ _ (cokernel.condition f))
(ShortComplex.exact_of_g_is_cokernel _ (cokernelIsCokernel f))).gIsCokernel preservesKernels X Y f := by have := preservesMonomorphisms_of_map_exact _ hL apply preservesLimit_of_preserves_limit_cone (kernelIsKernel f) apply (KernelFork.isLimitMapConeEquiv _ L).2 have : Mono ((ShortComplex.mk _ _ (kernel.condition f)).map L).f := by dsimp infer_instance exact (hL (ShortComplex.mk _ _ (kernel.condition f))
Mathlib/CategoryTheory/Abelian/Exact.lean
253
261
/- 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, Yury Kudryashov -/ import Mathlib.Order.Filter.Tendsto import Mathlib.Data.Set.Accumulate import Mathlib.Topology.Bornology.Basic import Mathlib.Topology.ContinuousOn import Mathlib.Topology.Ultrafilter import Mathlib.Topology.Defs.Ultrafilter /-! # Compact sets and compact spaces ## Main results * `isCompact_univ_pi`: **Tychonov's theorem** - an arbitrary product of compact sets is compact. -/ open Set Filter Topology TopologicalSpace Function universe u v variable {X : Type u} {Y : Type v} {ι : Type*} variable [TopologicalSpace X] [TopologicalSpace Y] {s t : Set X} {f : X → Y} -- compact sets section Compact lemma IsCompact.exists_clusterPt (hs : IsCompact s) {f : Filter X} [NeBot f] (hf : f ≤ 𝓟 s) : ∃ x ∈ s, ClusterPt x f := hs hf lemma IsCompact.exists_mapClusterPt {ι : Type*} (hs : IsCompact s) {f : Filter ι} [NeBot f] {u : ι → X} (hf : Filter.map u f ≤ 𝓟 s) : ∃ x ∈ s, MapClusterPt x f u := hs hf lemma IsCompact.exists_clusterPt_of_frequently {l : Filter X} (hs : IsCompact s) (hl : ∃ᶠ x in l, x ∈ s) : ∃ a ∈ s, ClusterPt a l := let ⟨a, has, ha⟩ := @hs _ (frequently_mem_iff_neBot.mp hl) inf_le_right ⟨a, has, ha.mono inf_le_left⟩ lemma IsCompact.exists_mapClusterPt_of_frequently {l : Filter ι} {f : ι → X} (hs : IsCompact s) (hf : ∃ᶠ x in l, f x ∈ s) : ∃ a ∈ s, MapClusterPt a l f := hs.exists_clusterPt_of_frequently hf /-- The complement to a compact set belongs to a filter `f` if it belongs to each filter `𝓝 x ⊓ f`, `x ∈ s`. -/ theorem IsCompact.compl_mem_sets (hs : IsCompact s) {f : Filter X} (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 _ hf inf_le_right /-- The complement to a compact set belongs to a filter `f` if each `x ∈ s` has a neighborhood `t` within `s` such that `tᶜ` belongs to `f`. -/ theorem IsCompact.compl_mem_sets_of_nhdsWithin (hs : IsCompact s) {f : Filter X} (hf : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, tᶜ ∈ f) : sᶜ ∈ f := by refine hs.compl_mem_sets fun x hx => ?_ rcases hf x hx with ⟨t, ht, hst⟩ replace ht := mem_inf_principal.1 ht apply mem_inf_of_inter ht hst rintro x ⟨h₁, h₂⟩ hs exact h₂ (h₁ hs) /-- If `p : Set X → Prop` is stable under restriction and union, and each point `x` of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/ @[elab_as_elim] theorem IsCompact.induction_on (hs : IsCompact s) {p : Set X → Prop} (he : p ∅) (hmono : ∀ ⦃s t⦄, s ⊆ t → p t → p s) (hunion : ∀ ⦃s t⦄, p s → p t → p (s ∪ t)) (hnhds : ∀ x ∈ s, ∃ t ∈ 𝓝[s] x, p t) : p s := by let f : Filter X := comk p he (fun _t ht _s hsub ↦ hmono hsub ht) (fun _s hs _t ht ↦ hunion hs ht) have : sᶜ ∈ f := hs.compl_mem_sets_of_nhdsWithin (by simpa [f] using hnhds) rwa [← compl_compl s] /-- The intersection of a compact set and a closed set is a compact set. -/ theorem IsCompact.inter_right (hs : IsCompact s) (ht : IsClosed t) : IsCompact (s ∩ t) := by intro f hnf hstf obtain ⟨x, hsx, hx⟩ : ∃ x ∈ s, ClusterPt x f := hs (le_trans hstf (le_principal_iff.2 inter_subset_left)) have : x ∈ t := ht.mem_of_nhdsWithin_neBot <| hx.mono <| le_trans hstf (le_principal_iff.2 inter_subset_right) exact ⟨x, ⟨hsx, this⟩, hx⟩ /-- The intersection of a closed set and a compact set is a compact set. -/ theorem IsCompact.inter_left (ht : IsCompact t) (hs : IsClosed s) : IsCompact (s ∩ t) := inter_comm t s ▸ ht.inter_right hs /-- The set difference of a compact set and an open set is a compact set. -/ theorem IsCompact.diff (hs : IsCompact s) (ht : IsOpen t) : IsCompact (s \ t) := hs.inter_right (isClosed_compl_iff.mpr ht) /-- A closed subset of a compact set is a compact set. -/ theorem IsCompact.of_isClosed_subset (hs : IsCompact s) (ht : IsClosed t) (h : t ⊆ s) : IsCompact t := inter_eq_self_of_subset_right h ▸ hs.inter_right ht theorem IsCompact.image_of_continuousOn {f : X → Y} (hs : IsCompact s) (hf : ContinuousOn f s) : IsCompact (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 theorem IsCompact.image {f : X → Y} (hs : IsCompact s) (hf : Continuous f) : IsCompact (f '' s) := hs.image_of_continuousOn hf.continuousOn theorem IsCompact.adherence_nhdset {f : Filter X} (hs : IsCompact s) (hf₂ : f ≤ 𝓟 s) (ht₁ : IsOpen t) (ht₂ : ∀ x ∈ s, ClusterPt x f → x ∈ t) : t ∈ f := Classical.by_cases mem_of_eq_bot fun (this : f ⊓ 𝓟 tᶜ ≠ ⊥) => let ⟨x, hx, (hfx : ClusterPt x <| f ⊓ 𝓟 tᶜ)⟩ := @hs _ ⟨this⟩ <| inf_le_of_left_le hf₂ have : x ∈ t := ht₂ x hx hfx.of_inf_left have : tᶜ ∩ t ∈ 𝓝[tᶜ] x := inter_mem_nhdsWithin _ (IsOpen.mem_nhds ht₁ 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 theorem isCompact_iff_ultrafilter_le_nhds : IsCompact s ↔ ∀ f : Ultrafilter X, ↑f ≤ 𝓟 s → ∃ x ∈ s, ↑f ≤ 𝓝 x := by refine (forall_neBot_le_iff ?_).trans ?_ · rintro f g hle ⟨x, hxs, hxf⟩ exact ⟨x, hxs, hxf.mono hle⟩ · simp only [Ultrafilter.clusterPt_iff] alias ⟨IsCompact.ultrafilter_le_nhds, _⟩ := isCompact_iff_ultrafilter_le_nhds theorem isCompact_iff_ultrafilter_le_nhds' : IsCompact s ↔ ∀ f : Ultrafilter X, s ∈ f → ∃ x ∈ s, ↑f ≤ 𝓝 x := by simp only [isCompact_iff_ultrafilter_le_nhds, le_principal_iff, Ultrafilter.mem_coe] alias ⟨IsCompact.ultrafilter_le_nhds', _⟩ := isCompact_iff_ultrafilter_le_nhds' /-- If a compact set belongs to a filter and this filter has a unique cluster point `y` in this set, then the filter is less than or equal to `𝓝 y`. -/ lemma IsCompact.le_nhds_of_unique_clusterPt (hs : IsCompact s) {l : Filter X} {y : X} (hmem : s ∈ l) (h : ∀ x ∈ s, ClusterPt x l → x = y) : l ≤ 𝓝 y := by refine le_iff_ultrafilter.2 fun f hf ↦ ?_ rcases hs.ultrafilter_le_nhds' f (hf hmem) with ⟨x, hxs, hx⟩ convert ← hx exact h x hxs (.mono (.of_le_nhds hx) hf) /-- If values of `f : Y → X` belong to a compact set `s` eventually along a filter `l` and `y` is a unique `MapClusterPt` for `f` along `l` in `s`, then `f` tends to `𝓝 y` along `l`. -/ lemma IsCompact.tendsto_nhds_of_unique_mapClusterPt {Y} {l : Filter Y} {y : X} {f : Y → X} (hs : IsCompact s) (hmem : ∀ᶠ x in l, f x ∈ s) (h : ∀ x ∈ s, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := hs.le_nhds_of_unique_clusterPt (mem_map.2 hmem) h /-- For every open directed cover of a compact set, there exists a single element of the cover which itself includes the set. -/ theorem IsCompact.elim_directed_cover {ι : Type v} [hι : Nonempty ι] (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) (hdU : Directed (· ⊆ ·) U) : ∃ i, s ⊆ U i := hι.elim fun i₀ => IsCompact.induction_on hs ⟨i₀, empty_subset _⟩ (fun _ _ hs ⟨i, hi⟩ => ⟨i, hs.trans hi⟩) (fun _ _ ⟨i, hi⟩ ⟨j, hj⟩ => let ⟨k, hki, hkj⟩ := hdU i j ⟨k, union_subset (Subset.trans hi hki) (Subset.trans hj hkj)⟩) fun _x hx => let ⟨i, hi⟩ := mem_iUnion.1 (hsU hx) ⟨U i, mem_nhdsWithin_of_mem_nhds (IsOpen.mem_nhds (hUo i) hi), i, Subset.refl _⟩ /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover {ι : Type v} (hs : IsCompact s) (U : ι → Set X) (hUo : ∀ i, IsOpen (U i)) (hsU : s ⊆ ⋃ i, U i) : ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := hs.elim_directed_cover _ (fun _ => isOpen_biUnion fun i _ => hUo i) (iUnion_eq_iUnion_finset U ▸ hsU) (directed_of_isDirected_le fun _ _ h => biUnion_subset_biUnion_left h) lemma IsCompact.elim_nhds_subcover_nhdsSet' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x hx, U x hx ∈ 𝓝 x) : ∃ t : Finset s, (⋃ x ∈ t, U x.1 x.2) ∈ 𝓝ˢ s := by rcases hs.elim_finite_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 _ _⟩ with ⟨t, hst⟩ refine ⟨t, mem_nhdsSet_iff_forall.2 fun x hx ↦ ?_⟩ rcases mem_iUnion₂.1 (hst hx) with ⟨y, hyt, hy⟩ refine mem_of_superset ?_ (subset_biUnion_of_mem hyt) exact mem_interior_iff_mem_nhds.1 hy lemma IsCompact.elim_nhds_subcover_nhdsSet (hs : IsCompact s) {U : X → Set X} (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ (⋃ x ∈ t, U x) ∈ 𝓝ˢ s := by let ⟨t, ht⟩ := hs.elim_nhds_subcover_nhdsSet' (fun x _ => U x) hU classical exact ⟨t.image (↑), fun x hx => let ⟨y, _, hyx⟩ := Finset.mem_image.1 hx hyx ▸ y.2, by rwa [Finset.set_biUnion_finset_image]⟩ theorem IsCompact.elim_nhds_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x ‹x ∈ s› ∈ 𝓝 x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U (x : s) x.2 := (hs.elim_nhds_subcover_nhdsSet' U hU).imp fun _ ↦ subset_of_mem_nhdsSet theorem IsCompact.elim_nhds_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝 x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := (hs.elim_nhds_subcover_nhdsSet hU).imp fun _ h ↦ h.imp_right subset_of_mem_nhdsSet theorem IsCompact.elim_nhdsWithin_subcover' (hs : IsCompact s) (U : ∀ x ∈ s, Set X) (hU : ∀ x (hx : x ∈ s), U x hx ∈ 𝓝[s] x) : ∃ t : Finset s, s ⊆ ⋃ x ∈ t, U x x.2 := by choose V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx) refine (hs.elim_nhds_subcover' V V_nhds).imp fun t ht => subset_trans ?_ (iUnion₂_mono fun x _ => hV x x.2) simpa [← iUnion_inter, ← iUnion_coe_set] theorem IsCompact.elim_nhdsWithin_subcover (hs : IsCompact s) (U : X → Set X) (hU : ∀ x ∈ s, U x ∈ 𝓝[s] x) : ∃ t : Finset X, (∀ x ∈ t, x ∈ s) ∧ s ⊆ ⋃ x ∈ t, U x := by choose! V V_nhds hV using fun x hx => mem_nhdsWithin_iff_exists_mem_nhds_inter.1 (hU x hx) refine (hs.elim_nhds_subcover V V_nhds).imp fun t ⟨t_sub_s, ht⟩ => ⟨t_sub_s, subset_trans ?_ (iUnion₂_mono fun x hx => hV x (t_sub_s x hx))⟩ simpa [← iUnion_inter] /-- The neighborhood filter of a compact set is disjoint with a filter `l` if and only if the neighborhood filter of each point of this set is disjoint with `l`. -/ theorem IsCompact.disjoint_nhdsSet_left {l : Filter X} (hs : IsCompact 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, 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₂, biInter_finset_mem] exact fun x hx => hUl x (hts x hx) /-- A filter `l` is disjoint with the neighborhood filter of a compact set if and only if it is disjoint with the neighborhood filter of each point of this set. -/ theorem IsCompact.disjoint_nhdsSet_right {l : Filter X} (hs : IsCompact s) : Disjoint l (𝓝ˢ s) ↔ ∀ x ∈ s, Disjoint l (𝓝 x) := by simpa only [disjoint_comm] using hs.disjoint_nhdsSet_left -- TODO: reformulate using `Disjoint` /-- For every directed family of closed sets whose intersection avoids a compact set, there exists a single element of the family which itself avoids this compact set. -/ theorem IsCompact.elim_directed_family_closed {ι : Type v} [Nonempty ι] (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) (hdt : Directed (· ⊇ ·) t) : ∃ i : ι, s ∩ t i = ∅ := let ⟨t, ht⟩ := hs.elim_directed_cover (compl ∘ t) (fun i => (htc i).isOpen_compl) (by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using hst) (hdt.mono_comp _ fun _ _ => compl_subset_compl.mpr) ⟨t, by simpa only [subset_def, not_forall, eq_empty_iff_forall_not_mem, mem_iUnion, exists_prop, mem_inter_iff, not_and, mem_iInter, mem_compl_iff] using ht⟩ -- TODO: reformulate using `Disjoint` /-- For every family of closed sets whose intersection avoids a compact set, there exists a finite subfamily whose intersection avoids this compact set. -/ theorem IsCompact.elim_finite_subfamily_closed {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : (s ∩ ⋂ i, t i) = ∅) : ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := hs.elim_directed_family_closed _ (fun _ ↦ isClosed_biInter fun _ _ ↦ htc _) (by rwa [← iInter_eq_iInter_finset]) (directed_of_isDirected_le fun _ _ h ↦ biInter_subset_biInter_left h) /-- To show that a compact set intersects the intersection of a family of closed sets, it is sufficient to show that it intersects every finite subfamily. -/ theorem IsCompact.inter_iInter_nonempty {ι : Type v} (hs : IsCompact s) (t : ι → Set X) (htc : ∀ i, IsClosed (t i)) (hst : ∀ u : Finset ι, (s ∩ ⋂ i ∈ u, t i).Nonempty) : (s ∩ ⋂ i, t i).Nonempty := by contrapose! hst exact hs.elim_finite_subfamily_closed t htc hst /-- Cantor's intersection theorem for `iInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed {ι : Type v} [hι : Nonempty ι] (t : ι → Set X) (htd : Directed (· ⊇ ·) t) (htn : ∀ i, (t i).Nonempty) (htc : ∀ i, IsCompact (t i)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := by let i₀ := hι.some suffices (t i₀ ∩ ⋂ i, t i).Nonempty by rwa [inter_eq_right.mpr (iInter_subset _ i₀)] at this simp only [nonempty_iff_ne_empty] at htn ⊢ apply mt ((htc i₀).elim_directed_family_closed t htcl) push_neg simp only [← nonempty_iff_ne_empty] at htn ⊢ refine ⟨htd, fun i => ?_⟩ rcases htd i₀ i with ⟨j, hji₀, hji⟩ exact (htn j).mono (subset_inter hji₀ hji) /-- Cantor's intersection theorem for `sInter`: the intersection of a directed family of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_sInter_of_directed_nonempty_isCompact_isClosed {S : Set (Set X)} [hS : Nonempty S] (hSd : DirectedOn (· ⊇ ·) S) (hSn : ∀ U ∈ S, U.Nonempty) (hSc : ∀ U ∈ S, IsCompact U) (hScl : ∀ U ∈ S, IsClosed U) : (⋂₀ S).Nonempty := by rw [sInter_eq_iInter] exact IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (DirectedOn.directed_val hSd) (fun i ↦ hSn i i.2) (fun i ↦ hSc i i.2) (fun i ↦ hScl i i.2) /-- Cantor's intersection theorem for sequences indexed by `ℕ`: the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/ theorem IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed (t : ℕ → Set X) (htd : ∀ i, t (i + 1) ⊆ t i) (htn : ∀ i, (t i).Nonempty) (ht0 : IsCompact (t 0)) (htcl : ∀ i, IsClosed (t i)) : (⋂ i, t i).Nonempty := have tmono : Antitone t := antitone_nat_of_succ_le htd have htd : Directed (· ⊇ ·) t := tmono.directed_ge have : ∀ i, t i ⊆ t 0 := fun i => tmono <| Nat.zero_le i have htc : ∀ i, IsCompact (t i) := fun i => ht0.of_isClosed_subset (htcl i) (this i) IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed t htd htn htc htcl /-- For every open cover of a compact set, there exists a finite subcover. -/ theorem IsCompact.elim_finite_subcover_image {b : Set ι} {c : ι → Set X} (hs : IsCompact s) (hc₁ : ∀ i ∈ b, IsOpen (c i)) (hc₂ : s ⊆ ⋃ i ∈ b, c i) : ∃ b', b' ⊆ b ∧ Set.Finite b' ∧ s ⊆ ⋃ i ∈ b', c i := by simp only [Subtype.forall', biUnion_eq_iUnion] at hc₁ hc₂ rcases hs.elim_finite_subcover (fun i => c i : b → Set X) hc₁ hc₂ with ⟨d, hd⟩ refine ⟨Subtype.val '' d.toSet, ?_, d.finite_toSet.image _, ?_⟩ · simp · rwa [biUnion_image] /-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_of_finite_subcover (h : ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i) : IsCompact 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 U hU hUf using h refine ⟨s, U, fun x => (hU x).2, fun x hx => mem_iUnion.2 ⟨⟨x, hx⟩, (hU _).1⟩, fun t ht => ?_⟩ refine compl_not_mem (le_principal_iff.1 hfs) ?_ refine mem_of_superset ((biInter_finset_mem t).2 fun x _ => hUf x) ?_ rw [subset_compl_comm, compl_iInter₂] simpa only [compl_compl] -- TODO: reformulate using `Disjoint` /-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅) : IsCompact s := isCompact_of_finite_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 compact if and only if for every open cover of `s`, there exists a finite subcover. -/ theorem isCompact_iff_finite_subcover : IsCompact s ↔ ∀ {ι : Type u} (U : ι → Set X), (∀ i, IsOpen (U i)) → (s ⊆ ⋃ i, U i) → ∃ t : Finset ι, s ⊆ ⋃ i ∈ t, U i := ⟨fun hs => hs.elim_finite_subcover, isCompact_of_finite_subcover⟩ /-- A set `s` is compact if and only if for every family of closed sets whose intersection avoids `s`, there exists a finite subfamily whose intersection avoids `s`. -/ theorem isCompact_iff_finite_subfamily_closed : IsCompact s ↔ ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → (s ∩ ⋂ i, t i) = ∅ → ∃ u : Finset ι, (s ∩ ⋂ i ∈ u, t i) = ∅ := ⟨fun hs => hs.elim_finite_subfamily_closed, isCompact_of_finite_subfamily_closed⟩ /-- If `s : Set (X × Y)` belongs to `𝓝 x ×ˢ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ×ˢ l`, i.e., there exist an open `U ⊇ K` and `t ∈ l` such that `U ×ˢ t ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_prod_of_forall {K : Set X} {Y} {l : Filter Y} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ×ˢ l) : s ∈ (𝓝ˢ K) ×ˢ l := by refine hK.induction_on (by simp) (fun t t' ht hs ↦ ?_) (fun t t' ht ht' ↦ ?_) fun x hx ↦ ?_ · exact prod_mono (nhdsSet_mono ht) le_rfl hs · simp [sup_prod, *] · rcases ((nhds_basis_opens _).prod l.basis_sets).mem_iff.1 (hs x hx) with ⟨⟨u, v⟩, ⟨⟨hx, huo⟩, hv⟩, hs⟩ refine ⟨u, nhdsWithin_le_nhds (huo.mem_nhds hx), mem_of_superset ?_ hs⟩ exact prod_mem_prod (huo.mem_nhdsSet.2 Subset.rfl) hv theorem IsCompact.nhdsSet_prod_eq_biSup {K : Set X} (hK : IsCompact K) {Y} (l : Filter Y) : (𝓝ˢ K) ×ˢ l = ⨆ x ∈ K, 𝓝 x ×ˢ l := le_antisymm (fun s hs ↦ hK.mem_nhdsSet_prod_of_forall <| by simpa using hs) (iSup₂_le fun _ hx ↦ prod_mono (nhds_le_nhdsSet hx) le_rfl) theorem IsCompact.prod_nhdsSet_eq_biSup {K : Set Y} (hK : IsCompact K) {X} (l : Filter X) : l ×ˢ (𝓝ˢ K) = ⨆ y ∈ K, l ×ˢ 𝓝 y := by simp only [prod_comm (f := l), hK.nhdsSet_prod_eq_biSup, map_iSup] /-- If `s : Set (X × Y)` belongs to `l ×ˢ 𝓝 y` for all `y` from a compact set `K`, then it belongs to `l ×ˢ (𝓝ˢ K)`, i.e., there exist `t ∈ l` and an open `U ⊇ K` such that `t ×ˢ U ⊆ s`. -/ theorem IsCompact.mem_prod_nhdsSet_of_forall {K : Set Y} {X} {l : Filter X} {s : Set (X × Y)} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ×ˢ 𝓝 y) : s ∈ l ×ˢ 𝓝ˢ K := (hK.prod_nhdsSet_eq_biSup l).symm ▸ by simpa using hs -- TODO: Is there a way to prove directly the `inf` version and then deduce the `Prod` one ? -- That would seem a bit more natural. theorem IsCompact.nhdsSet_inf_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : (𝓝ˢ K) ⊓ l = ⨆ x ∈ K, 𝓝 x ⊓ l := by have : ∀ f : Filter X, f ⊓ l = comap (fun x ↦ (x, x)) (f ×ˢ l) := fun f ↦ by simpa only [comap_prod] using congrArg₂ (· ⊓ ·) comap_id.symm comap_id.symm simp_rw [this, ← comap_iSup, hK.nhdsSet_prod_eq_biSup] theorem IsCompact.inf_nhdsSet_eq_biSup {K : Set X} (hK : IsCompact K) (l : Filter X) : l ⊓ (𝓝ˢ K) = ⨆ x ∈ K, l ⊓ 𝓝 x := by simp only [inf_comm l, hK.nhdsSet_inf_eq_biSup] /-- If `s : Set X` belongs to `𝓝 x ⊓ l` for all `x` from a compact set `K`, then it belongs to `(𝓝ˢ K) ⊓ l`, i.e., there exist an open `U ⊇ K` and `T ∈ l` such that `U ∩ T ⊆ s`. -/ theorem IsCompact.mem_nhdsSet_inf_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ x ∈ K, s ∈ 𝓝 x ⊓ l) : s ∈ (𝓝ˢ K) ⊓ l := (hK.nhdsSet_inf_eq_biSup l).symm ▸ by simpa using hs /-- If `s : Set S` belongs to `l ⊓ 𝓝 x` for all `x` from a compact set `K`, then it belongs to `l ⊓ (𝓝ˢ K)`, i.e., there exist `T ∈ l` and an open `U ⊇ K` such that `T ∩ U ⊆ s`. -/ theorem IsCompact.mem_inf_nhdsSet_of_forall {K : Set X} {l : Filter X} {s : Set X} (hK : IsCompact K) (hs : ∀ y ∈ K, s ∈ l ⊓ 𝓝 y) : s ∈ l ⊓ 𝓝ˢ K := (hK.inf_nhdsSet_eq_biSup l).symm ▸ by simpa using hs /-- To show that `∀ y ∈ K, P x y` holds for `x` close enough to `x₀` when `K` is compact, it is sufficient to show that for all `y₀ ∈ K` there `P x y` holds for `(x, y)` close enough to `(x₀, y₀)`. Provided for backwards compatibility, see `IsCompact.mem_prod_nhdsSet_of_forall` for a stronger statement. -/ theorem IsCompact.eventually_forall_of_forall_eventually {x₀ : X} {K : Set Y} (hK : IsCompact K) {P : X → Y → Prop} (hP : ∀ y ∈ K, ∀ᶠ z : X × Y in 𝓝 (x₀, y), P z.1 z.2) : ∀ᶠ x in 𝓝 x₀, ∀ y ∈ K, P x y := by simp only [nhds_prod_eq, ← eventually_iSup, ← hK.prod_nhdsSet_eq_biSup] at hP exact hP.curry.mono fun _ h ↦ h.self_of_nhdsSet theorem isCompact_empty : IsCompact (∅ : Set X) := fun _f hnf hsf => Not.elim hnf.ne <| empty_mem_iff_bot.1 <| le_principal_iff.1 hsf theorem isCompact_singleton {x : X} : IsCompact ({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.isCompact (hs : s.Subsingleton) : IsCompact s := Subsingleton.induction_on hs isCompact_empty fun _ => isCompact_singleton theorem Set.Finite.isCompact_biUnion {s : Set ι} {f : ι → Set X} (hs : s.Finite) (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := isCompact_iff_ultrafilter_le_nhds'.2 fun l hl => by rw [Ultrafilter.finite_biUnion_mem_iff hs] at hl rcases hl with ⟨i, his, hi⟩ rcases (hf i his).ultrafilter_le_nhds _ (le_principal_iff.2 hi) with ⟨x, hxi, hlx⟩ exact ⟨x, mem_iUnion₂.2 ⟨i, his, hxi⟩, hlx⟩ theorem Finset.isCompact_biUnion (s : Finset ι) {f : ι → Set X} (hf : ∀ i ∈ s, IsCompact (f i)) : IsCompact (⋃ i ∈ s, f i) := s.finite_toSet.isCompact_biUnion hf theorem isCompact_accumulate {K : ℕ → Set X} (hK : ∀ n, IsCompact (K n)) (n : ℕ) : IsCompact (Accumulate K n) := (finite_le_nat n).isCompact_biUnion fun k _ => hK k theorem Set.Finite.isCompact_sUnion {S : Set (Set X)} (hf : S.Finite) (hc : ∀ s ∈ S, IsCompact s) : IsCompact (⋃₀ S) := by rw [sUnion_eq_biUnion]; exact hf.isCompact_biUnion hc theorem isCompact_iUnion {ι : Sort*} {f : ι → Set X} [Finite ι] (h : ∀ i, IsCompact (f i)) : IsCompact (⋃ i, f i) := (finite_range f).isCompact_sUnion <| forall_mem_range.2 h @[simp] theorem Set.Finite.isCompact (hs : s.Finite) : IsCompact s := biUnion_of_singleton s ▸ hs.isCompact_biUnion fun _ _ => isCompact_singleton theorem IsCompact.finite_of_discrete [DiscreteTopology X] (hs : IsCompact s) : s.Finite := 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, _, hst⟩ simp only [← t.set_biUnion_coe, biUnion_of_singleton] at hst exact t.finite_toSet.subset hst theorem isCompact_iff_finite [DiscreteTopology X] : IsCompact s ↔ s.Finite := ⟨fun h => h.finite_of_discrete, fun h => h.isCompact⟩ theorem IsCompact.union (hs : IsCompact s) (ht : IsCompact t) : IsCompact (s ∪ t) := by rw [union_eq_iUnion]; exact isCompact_iUnion fun b => by cases b <;> assumption protected theorem IsCompact.insert (hs : IsCompact s) (a) : IsCompact (insert a s) := isCompact_singleton.union hs -- TODO: reformulate using `𝓝ˢ` /-- If `V : ι → Set X` is a decreasing family of closed compact sets then any neighborhood of `⋂ i, V i` contains some `V i`. We assume each `V i` is compact *and* closed because `X` is not assumed to be Hausdorff. See `exists_subset_nhd_of_compact` for version assuming this. -/ theorem exists_subset_nhds_of_isCompact' [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_cpct : ∀ i, IsCompact (V i)) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := by obtain ⟨W, hsubW, W_op, hWU⟩ := exists_open_set_nhds hU suffices ∃ i, V i ⊆ W from this.imp fun i hi => hi.trans hWU by_contra! H replace H : ∀ i, (V i ∩ Wᶜ).Nonempty := fun i => Set.inter_compl_nonempty_iff.mpr (H i) have : (⋂ i, V i ∩ Wᶜ).Nonempty := by refine IsCompact.nonempty_iInter_of_directed_nonempty_isCompact_isClosed _ (fun i j => ?_) H (fun i => (hV_cpct i).inter_right W_op.isClosed_compl) fun i => (hV_closed i).inter W_op.isClosed_compl rcases hV i j with ⟨k, hki, hkj⟩ refine ⟨k, ⟨fun x => ?_, fun x => ?_⟩⟩ <;> simp only [and_imp, mem_inter_iff, mem_compl_iff] <;> tauto have : ¬⋂ i : ι, V i ⊆ W := by simpa [← iInter_inter, inter_compl_nonempty_iff] contradiction namespace Filter theorem hasBasis_cocompact : (cocompact X).HasBasis IsCompact compl := hasBasis_biInf_principal' (fun s hs t ht => ⟨s ∪ t, hs.union ht, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩) ⟨∅, isCompact_empty⟩ theorem mem_cocompact : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ tᶜ ⊆ s := hasBasis_cocompact.mem_iff theorem mem_cocompact' : s ∈ cocompact X ↔ ∃ t, IsCompact t ∧ sᶜ ⊆ t := mem_cocompact.trans <| exists_congr fun _ => and_congr_right fun _ => compl_subset_comm theorem _root_.IsCompact.compl_mem_cocompact (hs : IsCompact s) : sᶜ ∈ Filter.cocompact X := hasBasis_cocompact.mem_of_mem hs theorem cocompact_le_cofinite : cocompact X ≤ cofinite := fun s hs => compl_compl s ▸ hs.isCompact.compl_mem_cocompact theorem cocompact_eq_cofinite (X : Type*) [TopologicalSpace X] [DiscreteTopology X] : cocompact X = cofinite := by simp only [cocompact, hasBasis_cofinite.eq_biInf, isCompact_iff_finite] /-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/ theorem disjoint_cocompact_left (f : Filter X) : Disjoint (Filter.cocompact X) f ↔ ∃ K ∈ f, IsCompact K := by simp_rw [hasBasis_cocompact.disjoint_iff_left, compl_compl] tauto /-- A filter is disjoint from the cocompact filter if and only if it contains a compact set. -/ theorem disjoint_cocompact_right (f : Filter X) : Disjoint f (Filter.cocompact X) ↔ ∃ K ∈ f, IsCompact K := by simp_rw [hasBasis_cocompact.disjoint_iff_right, compl_compl] tauto theorem Tendsto.isCompact_insert_range_of_cocompact {f : X → Y} {y} (hf : Tendsto f (cocompact X) (𝓝 y)) (hfc : Continuous f) : IsCompact (insert y (range f)) := by intro l hne hle by_cases hy : ClusterPt y l · exact ⟨y, Or.inl rfl, hy⟩ simp only [clusterPt_iff_nonempty, not_forall, ← not_disjoint_iff_nonempty_inter, not_not] at hy rcases hy with ⟨s, hsy, t, htl, hd⟩ rcases mem_cocompact.1 (hf hsy) with ⟨K, hKc, hKs⟩ have : f '' K ∈ l := by filter_upwards [htl, le_principal_iff.1 hle] with y hyt hyf rcases hyf with (rfl | ⟨x, rfl⟩) exacts [(hd.le_bot ⟨mem_of_mem_nhds hsy, hyt⟩).elim, mem_image_of_mem _ (not_not.1 fun hxK => hd.le_bot ⟨hKs hxK, hyt⟩)] rcases hKc.image hfc (le_principal_iff.2 this) with ⟨y, hy, hyl⟩ exact ⟨y, Or.inr <| image_subset_range _ _ hy, hyl⟩ theorem Tendsto.isCompact_insert_range_of_cofinite {f : ι → X} {x} (hf : Tendsto f cofinite (𝓝 x)) : IsCompact (insert x (range f)) := by letI : TopologicalSpace ι := ⊥; haveI h : DiscreteTopology ι := ⟨rfl⟩ rw [← cocompact_eq_cofinite ι] at hf exact hf.isCompact_insert_range_of_cocompact continuous_of_discreteTopology theorem Tendsto.isCompact_insert_range {f : ℕ → X} {x} (hf : Tendsto f atTop (𝓝 x)) : IsCompact (insert x (range f)) := Filter.Tendsto.isCompact_insert_range_of_cofinite <| Nat.cofinite_eq_atTop.symm ▸ hf theorem hasBasis_coclosedCompact : (Filter.coclosedCompact X).HasBasis (fun s => IsClosed s ∧ IsCompact s) compl := by simp only [Filter.coclosedCompact, iInf_and'] refine hasBasis_biInf_principal' ?_ ⟨∅, isClosed_empty, isCompact_empty⟩ rintro s ⟨hs₁, hs₂⟩ t ⟨ht₁, ht₂⟩ exact ⟨s ∪ t, ⟨⟨hs₁.union ht₁, hs₂.union ht₂⟩, compl_subset_compl.2 subset_union_left, compl_subset_compl.2 subset_union_right⟩⟩ /-- A set belongs to `coclosedCompact` if and only if the closure of its complement is compact. -/ theorem mem_coclosedCompact_iff : s ∈ coclosedCompact X ↔ IsCompact (closure sᶜ) := by refine hasBasis_coclosedCompact.mem_iff.trans ⟨?_, fun h ↦ ?_⟩ · rintro ⟨t, ⟨htcl, htco⟩, hst⟩ exact htco.of_isClosed_subset isClosed_closure <| closure_minimal (compl_subset_comm.2 hst) htcl · exact ⟨closure sᶜ, ⟨isClosed_closure, h⟩, compl_subset_comm.2 subset_closure⟩ /-- Complement of a set belongs to `coclosedCompact` if and only if its closure is compact. -/ theorem compl_mem_coclosedCompact : sᶜ ∈ coclosedCompact X ↔ IsCompact (closure s) := by rw [mem_coclosedCompact_iff, compl_compl] theorem cocompact_le_coclosedCompact : cocompact X ≤ coclosedCompact X := iInf_mono fun _ => le_iInf fun _ => le_rfl end Filter theorem IsCompact.compl_mem_coclosedCompact_of_isClosed (hs : IsCompact s) (hs' : IsClosed s) : sᶜ ∈ Filter.coclosedCompact X := hasBasis_coclosedCompact.mem_of_mem ⟨hs', hs⟩ namespace Bornology variable (X) in /-- Sets that are contained in a compact set form a bornology. Its `cobounded` filter is `Filter.cocompact`. See also `Bornology.relativelyCompact` the bornology of sets with compact closure. -/ def inCompact : Bornology X where cobounded' := Filter.cocompact X le_cofinite' := Filter.cocompact_le_cofinite theorem inCompact.isBounded_iff : @IsBounded _ (inCompact X) s ↔ ∃ t, IsCompact t ∧ s ⊆ t := by change sᶜ ∈ Filter.cocompact X ↔ _ rw [Filter.mem_cocompact] simp end Bornology /-- If `s` and `t` are compact sets, then the set neighborhoods filter of `s ×ˢ t` is the product of set neighborhoods filters for `s` and `t`. For general sets, only the `≤` inequality holds, see `nhdsSet_prod_le`. -/ theorem IsCompact.nhdsSet_prod_eq {t : Set Y} (hs : IsCompact s) (ht : IsCompact t) : 𝓝ˢ (s ×ˢ t) = 𝓝ˢ s ×ˢ 𝓝ˢ t := by simp_rw [hs.nhdsSet_prod_eq_biSup, ht.prod_nhdsSet_eq_biSup, nhdsSet, sSup_image, biSup_prod, nhds_prod_eq] theorem nhdsSet_prod_le_of_disjoint_cocompact {f : Filter Y} (hs : IsCompact s) (hf : Disjoint f (Filter.cocompact Y)) : 𝓝ˢ s ×ˢ f ≤ 𝓝ˢ (s ×ˢ Set.univ) := by obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf calc 𝓝ˢ s ×ˢ f _ ≤ 𝓝ˢ s ×ˢ 𝓟 K := Filter.prod_mono_right _ (Filter.le_principal_iff.mpr hKf) _ ≤ 𝓝ˢ s ×ˢ 𝓝ˢ K := Filter.prod_mono_right _ principal_le_nhdsSet _ = 𝓝ˢ (s ×ˢ K) := (hs.nhdsSet_prod_eq hK).symm _ ≤ 𝓝ˢ (s ×ˢ Set.univ) := nhdsSet_mono (prod_mono_right le_top) theorem prod_nhdsSet_le_of_disjoint_cocompact {t : Set Y} {f : Filter X} (ht : IsCompact t) (hf : Disjoint f (Filter.cocompact X)) : f ×ˢ 𝓝ˢ t ≤ 𝓝ˢ (Set.univ ×ˢ t) := by obtain ⟨K, hKf, hK⟩ := (disjoint_cocompact_right f).mp hf calc f ×ˢ 𝓝ˢ t _ ≤ (𝓟 K) ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ (Filter.le_principal_iff.mpr hKf) _ ≤ 𝓝ˢ K ×ˢ 𝓝ˢ t := Filter.prod_mono_left _ principal_le_nhdsSet _ = 𝓝ˢ (K ×ˢ t) := (hK.nhdsSet_prod_eq ht).symm _ ≤ 𝓝ˢ (Set.univ ×ˢ t) := nhdsSet_mono (prod_mono_left le_top) theorem nhds_prod_le_of_disjoint_cocompact {f : Filter Y} (x : X) (hf : Disjoint f (Filter.cocompact Y)) : 𝓝 x ×ˢ f ≤ 𝓝ˢ ({x} ×ˢ Set.univ) := by simpa using nhdsSet_prod_le_of_disjoint_cocompact isCompact_singleton hf theorem prod_nhds_le_of_disjoint_cocompact {f : Filter X} (y : Y) (hf : Disjoint f (Filter.cocompact X)) : f ×ˢ 𝓝 y ≤ 𝓝ˢ (Set.univ ×ˢ {y}) := by simpa using prod_nhdsSet_le_of_disjoint_cocompact isCompact_singleton hf /-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`. See also `IsCompact.nhdsSet_prod_eq`. -/ theorem generalized_tube_lemma (hs : IsCompact s) {t : Set Y} (ht : IsCompact t) {n : Set (X × Y)} (hn : IsOpen n) (hp : s ×ˢ t ⊆ n) : ∃ (u : Set X) (v : Set Y), IsOpen u ∧ IsOpen v ∧ s ⊆ u ∧ t ⊆ v ∧ u ×ˢ v ⊆ n := by rw [← hn.mem_nhdsSet, hs.nhdsSet_prod_eq ht, ((hasBasis_nhdsSet _).prod (hasBasis_nhdsSet _)).mem_iff] at hp rcases hp with ⟨⟨u, v⟩, ⟨⟨huo, hsu⟩, hvo, htv⟩, hn⟩ exact ⟨u, v, huo, hvo, hsu, htv, hn⟩ -- see Note [lower instance priority] instance (priority := 10) Subsingleton.compactSpace [Subsingleton X] : CompactSpace X := ⟨subsingleton_univ.isCompact⟩ theorem isCompact_univ_iff : IsCompact (univ : Set X) ↔ CompactSpace X := ⟨fun h => ⟨h⟩, fun h => h.1⟩ theorem isCompact_univ [h : CompactSpace X] : IsCompact (univ : Set X) := h.isCompact_univ theorem exists_clusterPt_of_compactSpace [CompactSpace X] (f : Filter X) [NeBot f] : ∃ x, ClusterPt x f := by simpa using isCompact_univ (show f ≤ 𝓟 univ by simp) nonrec theorem Ultrafilter.le_nhds_lim [CompactSpace X] (F : Ultrafilter X) : ↑F ≤ 𝓝 F.lim := by rcases isCompact_univ.ultrafilter_le_nhds F (by simp) with ⟨x, -, h⟩ exact le_nhds_lim ⟨x, h⟩ theorem CompactSpace.elim_nhds_subcover [CompactSpace X] (U : X → Set X) (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Finset X, ⋃ x ∈ t, U x = ⊤ := by obtain ⟨t, -, s⟩ := IsCompact.elim_nhds_subcover isCompact_univ U fun x _ => hU x exact ⟨t, top_unique s⟩ theorem compactSpace_of_finite_subfamily_closed (h : ∀ {ι : Type u} (t : ι → Set X), (∀ i, IsClosed (t i)) → ⋂ i, t i = ∅ → ∃ u : Finset ι, ⋂ i ∈ u, t i = ∅) : CompactSpace X where isCompact_univ := isCompact_of_finite_subfamily_closed fun t => by simpa using h t theorem IsClosed.isCompact [CompactSpace X] (h : IsClosed s) : IsCompact s := isCompact_univ.of_isClosed_subset h (subset_univ _) /-- If a filter has a unique cluster point `y` in a compact topological space, then the filter is less than or equal to `𝓝 y`. -/ lemma le_nhds_of_unique_clusterPt [CompactSpace X] {l : Filter X} {y : X} (h : ∀ x, ClusterPt x l → x = y) : l ≤ 𝓝 y := isCompact_univ.le_nhds_of_unique_clusterPt univ_mem fun x _ ↦ h x /-- If `y` is a unique `MapClusterPt` for `f` along `l` and the codomain of `f` is a compact space, then `f` tends to `𝓝 y` along `l`. -/ lemma tendsto_nhds_of_unique_mapClusterPt [CompactSpace X] {Y} {l : Filter Y} {y : X} {f : Y → X} (h : ∀ x, MapClusterPt x l f → x = y) : Tendsto f l (𝓝 y) := le_nhds_of_unique_clusterPt h lemma noncompact_univ (X : Type*) [TopologicalSpace X] [NoncompactSpace X] : ¬IsCompact (univ : Set X) := NoncompactSpace.noncompact_univ theorem IsCompact.ne_univ [NoncompactSpace X] (hs : IsCompact s) : s ≠ univ := fun h => noncompact_univ X (h ▸ hs) instance [NoncompactSpace X] : NeBot (Filter.cocompact X) := by refine Filter.hasBasis_cocompact.neBot_iff.2 fun hs => ?_ contrapose hs; rw [not_nonempty_iff_eq_empty, compl_empty_iff] at hs rw [hs]; exact noncompact_univ X @[simp] theorem Filter.cocompact_eq_bot [CompactSpace X] : Filter.cocompact X = ⊥ := Filter.hasBasis_cocompact.eq_bot_iff.mpr ⟨Set.univ, isCompact_univ, Set.compl_univ⟩ instance [NoncompactSpace X] : NeBot (Filter.coclosedCompact X) := neBot_of_le Filter.cocompact_le_coclosedCompact theorem noncompactSpace_of_neBot (_ : NeBot (Filter.cocompact X)) : NoncompactSpace X := ⟨fun h' => (Filter.nonempty_of_mem h'.compl_mem_cocompact).ne_empty compl_univ⟩ theorem Filter.cocompact_neBot_iff : NeBot (Filter.cocompact X) ↔ NoncompactSpace X := ⟨noncompactSpace_of_neBot, fun _ => inferInstance⟩ theorem not_compactSpace_iff : ¬CompactSpace X ↔ NoncompactSpace X := ⟨fun h₁ => ⟨fun h₂ => h₁ ⟨h₂⟩⟩, fun ⟨h₁⟩ ⟨h₂⟩ => h₁ h₂⟩ instance : NoncompactSpace ℤ := noncompactSpace_of_neBot <| by simp only [Filter.cocompact_eq_cofinite, Filter.cofinite_neBot] -- Note: We can't make this into an instance because it loops with `Finite.compactSpace`. /-- A compact discrete space is finite. -/ theorem finite_of_compact_of_discrete [CompactSpace X] [DiscreteTopology X] : Finite X := Finite.of_finite_univ <| isCompact_univ.finite_of_discrete lemma Set.Infinite.exists_accPt_cofinite_inf_principal_of_subset_isCompact {K : Set X} (hs : s.Infinite) (hK : IsCompact K) (hsub : s ⊆ K) : ∃ x ∈ K, AccPt x (cofinite ⊓ 𝓟 s) := (@hK _ hs.cofinite_inf_principal_neBot (inf_le_right.trans <| principal_mono.2 hsub)).imp fun x hx ↦ by rwa [accPt_iff_clusterPt, inf_comm, inf_right_comm, (finite_singleton _).cofinite_inf_principal_compl] lemma Set.Infinite.exists_accPt_of_subset_isCompact {K : Set X} (hs : s.Infinite) (hK : IsCompact K) (hsub : s ⊆ K) : ∃ x ∈ K, AccPt x (𝓟 s) := let ⟨x, hxK, hx⟩ := hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact hK hsub ⟨x, hxK, hx.mono inf_le_right⟩ lemma Set.Infinite.exists_accPt_cofinite_inf_principal [CompactSpace X] (hs : s.Infinite) : ∃ x, AccPt x (cofinite ⊓ 𝓟 s) := by simpa only [mem_univ, true_and] using hs.exists_accPt_cofinite_inf_principal_of_subset_isCompact isCompact_univ s.subset_univ lemma Set.Infinite.exists_accPt_principal [CompactSpace X] (hs : s.Infinite) : ∃ x, AccPt x (𝓟 s) := hs.exists_accPt_cofinite_inf_principal.imp fun _x hx ↦ hx.mono inf_le_right theorem exists_nhds_ne_neBot (X : Type*) [TopologicalSpace X] [CompactSpace X] [Infinite X] : ∃ z : X, (𝓝[≠] z).NeBot := by simpa [AccPt] using (@infinite_univ X _).exists_accPt_principal theorem finite_cover_nhds_interior [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Finset X, ⋃ x ∈ t, interior (U x) = univ := let ⟨t, ht⟩ := isCompact_univ.elim_finite_subcover (fun x => interior (U x)) (fun _ => isOpen_interior) fun x _ => mem_iUnion.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩ ⟨t, univ_subset_iff.1 ht⟩ theorem finite_cover_nhds [CompactSpace X] {U : X → Set X} (hU : ∀ x, U x ∈ 𝓝 x) : ∃ t : Finset X, ⋃ x ∈ t, U x = univ := let ⟨t, ht⟩ := finite_cover_nhds_interior hU ⟨t, univ_subset_iff.1 <| ht.symm.subset.trans <| iUnion₂_mono fun _ _ => interior_subset⟩ /-- The comap of the cocompact filter on `Y` by a continuous function `f : X → Y` is less than or equal to the cocompact filter on `X`. This is a reformulation of the fact that images of compact sets are compact. -/ theorem Filter.comap_cocompact_le {f : X → Y} (hf : Continuous f) : (Filter.cocompact Y).comap f ≤ Filter.cocompact X := by rw [(Filter.hasBasis_cocompact.comap f).le_basis_iff Filter.hasBasis_cocompact] intro t ht refine ⟨f '' t, ht.image hf, ?_⟩ simpa using t.subset_preimage_image f /-- If a filter is disjoint from the cocompact filter, so is its image under any continuous function. -/ theorem disjoint_map_cocompact {g : X → Y} {f : Filter X} (hg : Continuous g) (hf : Disjoint f (Filter.cocompact X)) : Disjoint (map g f) (Filter.cocompact Y) := by rw [← Filter.disjoint_comap_iff_map, disjoint_iff_inf_le] calc f ⊓ (comap g (cocompact Y)) _ ≤ f ⊓ Filter.cocompact X := inf_le_inf_left f (Filter.comap_cocompact_le hg) _ = ⊥ := disjoint_iff.mp hf theorem isCompact_range [CompactSpace X] {f : X → Y} (hf : Continuous f) : IsCompact (range f) := by rw [← image_univ]; exact isCompact_univ.image hf theorem isCompact_diagonal [CompactSpace X] : IsCompact (diagonal X) := @range_diag X ▸ isCompact_range (continuous_id.prodMk continuous_id) /-- If `X` is a compact topological space, then `Prod.snd : X × Y → Y` is a closed map. -/ theorem isClosedMap_snd_of_compactSpace [CompactSpace X] : IsClosedMap (Prod.snd : X × Y → Y) := fun s hs => by rw [← isOpen_compl_iff, isOpen_iff_mem_nhds] intro y hy have : univ ×ˢ {y} ⊆ sᶜ := by exact fun (x, y') ⟨_, rfl⟩ hs => hy ⟨(x, y'), hs, rfl⟩ rcases generalized_tube_lemma isCompact_univ isCompact_singleton hs.isOpen_compl this with ⟨U, V, -, hVo, hU, hV, hs⟩ refine mem_nhds_iff.2 ⟨V, ?_, hVo, hV rfl⟩ rintro _ hzV ⟨z, hzs, rfl⟩ exact hs ⟨hU trivial, hzV⟩ hzs /-- If `Y` is a compact topological space, then `Prod.fst : X × Y → X` is a closed map. -/ theorem isClosedMap_fst_of_compactSpace [CompactSpace Y] : IsClosedMap (Prod.fst : X × Y → X) := isClosedMap_snd_of_compactSpace.comp isClosedMap_swap theorem exists_subset_nhds_of_compactSpace [CompactSpace X] [Nonempty ι] {V : ι → Set X} (hV : Directed (· ⊇ ·) V) (hV_closed : ∀ i, IsClosed (V i)) {U : Set X} (hU : ∀ x ∈ ⋂ i, V i, U ∈ 𝓝 x) : ∃ i, V i ⊆ U := exists_subset_nhds_of_isCompact' hV (fun i => (hV_closed i).isCompact) hV_closed hU /-- If `f : X → Y` is an inducing map, the image `f '' s` of a set `s` is compact if and only if `s` is compact. -/ theorem Topology.IsInducing.isCompact_iff {f : X → Y} (hf : IsInducing f) : IsCompact s ↔ IsCompact (f '' s) := by refine ⟨fun hs => hs.image hf.continuous, fun hs F F_ne_bot F_le => ?_⟩ obtain ⟨_, ⟨x, x_in : x ∈ s, rfl⟩, hx : ClusterPt (f x) (map f F)⟩ := hs ((map_mono F_le).trans_eq map_principal) exact ⟨x, x_in, hf.mapClusterPt_iff.1 hx⟩ @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_iff := IsInducing.isCompact_iff /-- If `f : X → Y` is an embedding, the image `f '' s` of a set `s` is compact if and only if `s` is compact. -/ theorem Topology.IsEmbedding.isCompact_iff {f : X → Y} (hf : IsEmbedding f) : IsCompact s ↔ IsCompact (f '' s) := hf.isInducing.isCompact_iff @[deprecated (since := "2024-10-26")] alias Embedding.isCompact_iff := IsEmbedding.isCompact_iff /-- The preimage of a compact set under an inducing map is a compact set. -/ theorem Topology.IsInducing.isCompact_preimage (hf : IsInducing f) (hf' : IsClosed (range f)) {K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) := by replace hK := hK.inter_right hf' rwa [hf.isCompact_iff, image_preimage_eq_inter_range] @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_preimage := IsInducing.isCompact_preimage lemma Topology.IsInducing.isCompact_preimage_iff {f : X → Y} (hf : IsInducing f) {K : Set Y} (Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) ↔ IsCompact K := by rw [hf.isCompact_iff, image_preimage_eq_of_subset Kf] @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_preimage_iff := IsInducing.isCompact_preimage_iff /-- The preimage of a compact set in the image of an inducing map is compact. -/ lemma Topology.IsInducing.isCompact_preimage' (hf : IsInducing f) {K : Set Y} (hK : IsCompact K) (Kf : K ⊆ range f) : IsCompact (f ⁻¹' K) := (hf.isCompact_preimage_iff Kf).2 hK @[deprecated (since := "2024-10-28")] alias Inducing.isCompact_preimage' := IsInducing.isCompact_preimage' /-- The preimage of a compact set under a closed embedding is a compact set. -/ theorem Topology.IsClosedEmbedding.isCompact_preimage (hf : IsClosedEmbedding f) {K : Set Y} (hK : IsCompact K) : IsCompact (f ⁻¹' K) := hf.isInducing.isCompact_preimage (hf.isClosed_range) hK /-- A closed embedding is proper, ie, inverse images of compact sets are contained in compacts. Moreover, the preimage of a compact set is compact, see `IsClosedEmbedding.isCompact_preimage`. -/ theorem Topology.IsClosedEmbedding.tendsto_cocompact (hf : IsClosedEmbedding f) : Tendsto f (Filter.cocompact X) (Filter.cocompact Y) := Filter.hasBasis_cocompact.tendsto_right_iff.mpr fun _K hK => (hf.isCompact_preimage hK).compl_mem_cocompact /-- Sets of subtype are compact iff the image under a coercion is. -/ theorem Subtype.isCompact_iff {p : X → Prop} {s : Set { x // p x }} : IsCompact s ↔ IsCompact ((↑) '' s : Set X) := IsEmbedding.subtypeVal.isCompact_iff theorem isCompact_iff_isCompact_univ : IsCompact s ↔ IsCompact (univ : Set s) := by rw [Subtype.isCompact_iff, image_univ, Subtype.range_coe] theorem isCompact_iff_compactSpace : IsCompact s ↔ CompactSpace s := isCompact_iff_isCompact_univ.trans isCompact_univ_iff theorem IsCompact.finite (hs : IsCompact s) (hs' : DiscreteTopology s) : s.Finite := finite_coe_iff.mp (@finite_of_compact_of_discrete _ _ (isCompact_iff_compactSpace.mp hs) hs') theorem exists_nhds_ne_inf_principal_neBot (hs : IsCompact s) (hs' : s.Infinite) : ∃ z ∈ s, (𝓝[≠] z ⊓ 𝓟 s).NeBot := hs'.exists_accPt_of_subset_isCompact hs Subset.rfl protected theorem Topology.IsClosedEmbedding.noncompactSpace [NoncompactSpace X] {f : X → Y} (hf : IsClosedEmbedding f) : NoncompactSpace Y := noncompactSpace_of_neBot hf.tendsto_cocompact.neBot
protected theorem Topology.IsClosedEmbedding.compactSpace [h : CompactSpace Y] {f : X → Y} (hf : IsClosedEmbedding f) : CompactSpace X := ⟨by rw [hf.isInducing.isCompact_iff, image_univ]; exact hf.isClosed_range.isCompact⟩
Mathlib/Topology/Compactness/Compact.lean
909
911
/- 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.Trigonometric.Basic import Mathlib.Topology.Order.ProjIcc /-! # Inverse trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function. (This is delayed as it is easier to set up after developing complex trigonometric functions.) Basic inequalities on trigonometric functions. -/ noncomputable section open Topology Filter Set Filter Real namespace Real variable {x y : ℝ} /-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`. It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/ @[pp_nodot] noncomputable def arcsin : ℝ → ℝ := Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) := Subtype.coe_prop _ @[simp] theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by rw [arcsin, range_comp Subtype.val] simp [Icc] theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 := (arcsin_mem_Icc x).2 theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x := (arcsin_mem_Icc x).1 theorem arcsin_projIcc (x : ℝ) : arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend, Function.comp_apply] theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩) theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x := sin_arcsin' ⟨hx₁, hx₂⟩ theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x := injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)] theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x := arcsin_sin' ⟨hx₁, hx₂⟩ theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) := (Subtype.strictMono_coe _).comp_strictMonoOn <| sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _ @[gcongr] theorem arcsin_lt_arcsin {x y : ℝ} (hx : -1 ≤ x) (hlt : x < y) (hy : y ≤ 1) : arcsin x < arcsin y := strictMonoOn_arcsin ⟨hx, hlt.le.trans hy⟩ ⟨hx.trans hlt.le, hy⟩ hlt theorem monotone_arcsin : Monotone arcsin := (Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _ @[gcongr] theorem arcsin_le_arcsin {x y : ℝ} (h : x ≤ y) : arcsin x ≤ arcsin y := monotone_arcsin h theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) := strictMonoOn_arcsin.injOn theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) : arcsin x = arcsin y ↔ x = y := injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ @[continuity, fun_prop] theorem continuous_arcsin : Continuous arcsin := continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend' @[fun_prop] theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x := continuous_arcsin.continuousAt theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin y = x := by subst y exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x)) @[simp] theorem arcsin_zero : arcsin 0 = 0 := arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩ @[simp] theorem arcsin_one : arcsin 1 = π / 2 := arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one] theorem arcsin_neg_one : arcsin (-1) = -(π / 2) := arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <| left_mem_Icc.2 (neg_le_self pi_div_two_pos.le) theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one] @[simp] theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by rcases le_total x (-1) with hx₁ | hx₁ · rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)] rcases le_total 1 x with hx₂ | hx₂ · rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)] refine arcsin_eq_of_sin_eq ?_ ?_ · rw [sin_neg, sin_arcsin hx₁ hx₂] · exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩ theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy] theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) : arcsin x ≤ y ↔ x ≤ sin y := by rcases le_total x (-1) with hx₁ | hx₁ · simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)] rcases lt_or_le 1 x with hx₂ | hx₂ · simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂] exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy) theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) : x ≤ arcsin y ↔ sin x ≤ y := by rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩, sin_neg, neg_le_neg_iff] theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le
theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) : arcsin x < y ↔ x < sin y := not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) : x < arcsin y ↔ sin x < y :=
Mathlib/Analysis/SpecialFunctions/Trigonometric/Inverse.lean
153
159
/- Copyright (c) 2020 Adam Topaz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Adam Topaz, Bhavik Mehta, Dagur Asgeirsson -/ import Mathlib.CategoryTheory.Monad.Limits import Mathlib.Topology.StoneCech import Mathlib.Topology.UrysohnsLemma import Mathlib.Topology.Category.CompHausLike.Basic import Mathlib.Topology.Category.TopCat.Limits.Basic /-! # The category of Compact Hausdorff Spaces We construct the category of compact Hausdorff spaces. The type of compact Hausdorff spaces is denoted `CompHaus`, and it is endowed with a category instance making it a full subcategory of `TopCat`. The fully faithful functor `CompHaus ⥤ TopCat` is denoted `compHausToTop`. **Note:** The file `Mathlib/Topology/Category/Compactum.lean` provides the equivalence between `Compactum`, which is defined as the category of algebras for the ultrafilter monad, and `CompHaus`. `CompactumToCompHaus` is the functor from `Compactum` to `CompHaus` which is proven to be an equivalence of categories in `CompactumToCompHaus.isEquivalence`. See `Mathlib/Topology/Category/Compactum.lean` for a more detailed discussion where these definitions are introduced. ## Implementation The category `CompHaus` is defined using the structure `CompHausLike`. See the file `CompHausLike.Basic` for more information. -/ universe v u open CategoryTheory CompHausLike /-- The category of compact Hausdorff spaces. -/ abbrev CompHaus := CompHausLike (fun _ ↦ True) namespace CompHaus instance : Inhabited CompHaus := ⟨{ toTop := TopCat.of PEmpty, prop := trivial}⟩ instance : CoeSort CompHaus Type* := ⟨fun X => X.toTop⟩ instance {X : CompHaus} : CompactSpace X := X.is_compact instance {X : CompHaus} : T2Space X := X.is_hausdorff variable (X : Type*) [TopologicalSpace X] [CompactSpace X] [T2Space X] instance : HasProp (fun _ ↦ True) X := ⟨trivial⟩ /-- A constructor for objects of the category `CompHaus`, taking a type, and bundling the compact Hausdorff topology found by typeclass inference. -/ abbrev of : CompHaus := CompHausLike.of _ X end CompHaus /-- The fully faithful embedding of `CompHaus` in `TopCat`. -/ abbrev compHausToTop : CompHaus.{u} ⥤ TopCat.{u} := CompHausLike.compHausLikeToTop _ /-- (Implementation) The object part of the compactification functor from topological spaces to compact Hausdorff spaces. -/ @[simps!] def stoneCechObj (X : TopCat) : CompHaus := CompHaus.of (StoneCech X) /-- (Implementation) The bijection of homsets to establish the reflective adjunction of compact Hausdorff spaces in topological spaces. -/ noncomputable def stoneCechEquivalence (X : TopCat.{u}) (Y : CompHaus.{u}) : (stoneCechObj X ⟶ Y) ≃ (X ⟶ compHausToTop.obj Y) where toFun f := TopCat.ofHom { toFun := f ∘ stoneCechUnit continuous_toFun := f.hom.2.comp (@continuous_stoneCechUnit X _) } invFun f := CompHausLike.ofHom _ { toFun := stoneCechExtend f.hom.2 continuous_toFun := continuous_stoneCechExtend f.hom.2 } left_inv := by rintro ⟨f : StoneCech X ⟶ Y, hf : Continuous f⟩ ext x refine congr_fun ?_ x apply Continuous.ext_on denseRange_stoneCechUnit (continuous_stoneCechExtend _) hf · rintro _ ⟨y, rfl⟩ apply congr_fun (stoneCechExtend_extends (hf.comp _)) y apply continuous_stoneCechUnit right_inv := by rintro ⟨f : (X : Type _) ⟶ Y, hf : Continuous f⟩ ext exact congr_fun (stoneCechExtend_extends hf) _ /-- The Stone-Cech compactification functor from topological spaces to compact Hausdorff spaces, left adjoint to the inclusion functor. -/ noncomputable def topToCompHaus : TopCat.{u} ⥤ CompHaus.{u} := Adjunction.leftAdjointOfEquiv stoneCechEquivalence.{u} fun _ _ _ _ _ => rfl theorem topToCompHaus_obj (X : TopCat) : ↥(topToCompHaus.obj X) = StoneCech X := rfl /-- The category of compact Hausdorff spaces is reflective in the category of topological spaces. -/ noncomputable instance compHausToTop.reflective : Reflective compHausToTop where L := topToCompHaus adj := Adjunction.adjunctionOfEquivLeft _ _ noncomputable instance compHausToTop.createsLimits : CreatesLimits compHausToTop := monadicCreatesLimits _ instance CompHaus.hasLimits : Limits.HasLimits CompHaus := hasLimits_of_hasLimits_createsLimits compHausToTop instance CompHaus.hasColimits : Limits.HasColimits CompHaus := hasColimits_of_reflective compHausToTop namespace CompHaus /-- An explicit limit cone for a functor `F : J ⥤ CompHaus`, defined in terms of `TopCat.limitCone`. -/ def limitCone {J : Type v} [SmallCategory J] (F : J ⥤ CompHaus.{max v u}) : Limits.Cone F := letI FF : J ⥤ TopCat := F ⋙ compHausToTop { pt := { toTop := (TopCat.limitCone FF).pt is_compact := by show CompactSpace { u : ∀ j, F.obj j | ∀ {i j : J} (f : i ⟶ j), (F.map f) (u i) = u j } rw [← isCompact_iff_compactSpace] apply IsClosed.isCompact have : { u : ∀ j, F.obj j | ∀ {i j : J} (f : i ⟶ j), F.map f (u i) = u j } = ⋂ (i : J) (j : J) (f : i ⟶ j), { u | F.map f (u i) = u j } := by ext1 simp only [Set.mem_iInter, Set.mem_setOf_eq] rw [this] apply isClosed_iInter intro i apply isClosed_iInter intro j apply isClosed_iInter intro f apply isClosed_eq · exact ((F.map f).hom.continuous).comp (continuous_apply i) · exact continuous_apply j is_hausdorff := show T2Space { u : ∀ j, F.obj j | ∀ {i j : J} (f : i ⟶ j), (F.map f) (u i) = u j } from inferInstance prop := trivial } π := { app := fun j => (TopCat.limitCone FF).π.app j naturality := by intro _ _ f ext ⟨x, hx⟩ simp only [CategoryTheory.comp_apply, Functor.const_obj_map, CategoryTheory.id_apply] exact (hx f).symm } } /-- The limit cone `CompHaus.limitCone F` is indeed a limit cone. -/ def limitConeIsLimit {J : Type v} [SmallCategory J] (F : J ⥤ CompHaus.{max v u}) : Limits.IsLimit.{v} (limitCone.{v,u} F) := letI FF : J ⥤ TopCat := F ⋙ compHausToTop { lift := fun S => (TopCat.limitConeIsLimit FF).lift (compHausToTop.mapCone S) fac := fun S => (TopCat.limitConeIsLimit FF).fac (compHausToTop.mapCone S) uniq := fun S => (TopCat.limitConeIsLimit FF).uniq (compHausToTop.mapCone S) } theorem epi_iff_surjective {X Y : CompHaus.{u}} (f : X ⟶ Y) : Epi f ↔ Function.Surjective f := by constructor · dsimp [Function.Surjective] contrapose! rintro ⟨y, hy⟩ hf let C := Set.range f have hC : IsClosed C := (isCompact_range f.hom.continuous).isClosed let D := ({y} : Set Y) have hD : IsClosed D := isClosed_singleton have hCD : Disjoint C D := by rw [Set.disjoint_singleton_right] rintro ⟨y', hy'⟩ exact hy y' hy' obtain ⟨φ, hφ0, hφ1, hφ01⟩ := exists_continuous_zero_one_of_isClosed hC hD hCD haveI : CompactSpace (ULift.{u} <| Set.Icc (0 : ℝ) 1) := Homeomorph.ulift.symm.compactSpace haveI : T2Space (ULift.{u} <| Set.Icc (0 : ℝ) 1) := Homeomorph.ulift.symm.t2Space let Z := of (ULift.{u} <| Set.Icc (0 : ℝ) 1) let g : Y ⟶ Z := ofHom _ ⟨fun y' => ⟨⟨φ y', hφ01 y'⟩⟩, continuous_uliftUp.comp (φ.continuous.subtype_mk fun y' => hφ01 y')⟩ let h : Y ⟶ Z := ofHom _ ⟨fun _ => ⟨⟨0, Set.left_mem_Icc.mpr zero_le_one⟩⟩, continuous_const⟩ have H : h = g := by rw [← cancel_epi f] ext x : 4 simp [g, h, Z, hφ0 (Set.mem_range_self x)] apply_fun fun e => (e y).down.1 at H dsimp [g, h, Z] at H simp only [hφ1 (Set.mem_singleton y), Pi.one_apply] at H exact zero_ne_one H · rw [← CategoryTheory.epi_iff_surjective] apply (forget CompHaus).epi_of_epi_map end CompHaus /-- Every `CompHausLike` admits a functor to `CompHaus`. -/ abbrev compHausLikeToCompHaus (P : TopCat → Prop) : CompHausLike P ⥤ CompHaus := CompHausLike.toCompHausLike (by simp only [implies_true])
Mathlib/Topology/Category/CompHaus/Basic.lean
380
392