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 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.CharP.Defs import Mathlib.Algebra.Polynomial.AlgebraMap import Mathlib.Algebra.Polynomial.Basic import Mathlib.RingTheory.MvPowerSeries.Basic import Mathlib.Tactic.MoveAdd import Mathlib.Algebra.MvPolynomial.Equiv import Mathlib.RingTheory.Ideal.Basic /-! # Formal power series (in one variable) This file defines (univariate) formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. Formal power series in one variable are defined from multivariate power series as `PowerSeries R := MvPowerSeries Unit R`. The file sets up the (semi)ring structure on univariate power series. We provide the natural inclusion from polynomials to formal power series. Additional results can be found in: * `Mathlib.RingTheory.PowerSeries.Trunc`, truncation of power series; * `Mathlib.RingTheory.PowerSeries.Inverse`, about inverses of power series, and the fact that power series over a local ring form a local ring; * `Mathlib.RingTheory.PowerSeries.Order`, the order of a power series at 0, and application to the fact that power series over an integral domain form an integral domain. ## Implementation notes Because of its definition, `PowerSeries R := MvPowerSeries Unit R`. a lot of proofs and properties from the multivariate case can be ported to the single variable case. However, it means that formal power series are indexed by `Unit →₀ ℕ`, which is of course canonically isomorphic to `ℕ`. We then build some glue to treat formal power series as if they were indexed by `ℕ`. Occasionally this leads to proofs that are uglier than expected. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Formal power series over a coefficient type `R` -/ abbrev PowerSeries (R : Type*) := MvPowerSeries Unit R namespace PowerSeries open Finsupp (single) variable {R : Type*} section -- Porting note: not available in Lean 4 -- local reducible PowerSeries /-- `R⟦X⟧` is notation for `PowerSeries R`, the semiring of formal power series in one variable over a semiring `R`. -/ scoped notation:9000 R "⟦X⟧" => PowerSeries R instance [Inhabited R] : Inhabited R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Zero R] : Zero R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddMonoid R] : AddMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddGroup R] : AddGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommMonoid R] : AddCommMonoid R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [AddCommGroup R] : AddCommGroup R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Semiring R] : Semiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommSemiring R] : CommSemiring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Ring R] : Ring R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [CommRing R] : CommRing R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance [Nontrivial R] : Nontrivial R⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S A⟦X⟧ := Pi.isScalarTower instance {A} [Semiring A] [CommSemiring R] [Algebra R A] : Algebra R A⟦X⟧ := by dsimp only [PowerSeries] infer_instance end section Semiring variable (R) [Semiring R] /-- The `n`th coefficient of a formal power series. -/ def coeff (n : ℕ) : R⟦X⟧ →ₗ[R] R := MvPowerSeries.coeff R (single () n) /-- The `n`th monomial with coefficient `a` as formal power series. -/ def monomial (n : ℕ) : R →ₗ[R] R⟦X⟧ := MvPowerSeries.monomial R (single () n) variable {R} theorem coeff_def {s : Unit →₀ ℕ} {n : ℕ} (h : s () = n) : coeff R n = MvPowerSeries.coeff R s := by rw [coeff, ← h, ← Finsupp.unique_single s] /-- Two formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ : R⟦X⟧} (h : ∀ n, coeff R n φ = coeff R n ψ) : φ = ψ := MvPowerSeries.ext fun n => by rw [← coeff_def] · apply h rfl @[simp] theorem forall_coeff_eq_zero (φ : R⟦X⟧) : (∀ n, coeff R n φ = 0) ↔ φ = 0 := ⟨fun h => ext h, fun h => by simp [h]⟩ /-- Two formal power series are equal if all their coefficients are equal. -/ add_decl_doc PowerSeries.ext_iff instance [Subsingleton R] : Subsingleton R⟦X⟧ := by simp only [subsingleton_iff, PowerSeries.ext_iff] subsingleton /-- Constructor for formal power series. -/ def mk {R} (f : ℕ → R) : R⟦X⟧ := fun s => f (s ()) @[simp] theorem coeff_mk (n : ℕ) (f : ℕ → R) : coeff R n (mk f) = f n := congr_arg f Finsupp.single_eq_same theorem coeff_monomial (m n : ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := calc coeff R m (monomial R n a) = _ := MvPowerSeries.coeff_monomial _ _ _ _ = if m = n then a else 0 := by simp only [Finsupp.unique_single_eq_iff] theorem monomial_eq_mk (n : ℕ) (a : R) : monomial R n a = mk fun m => if m = n then a else 0 := ext fun m => by rw [coeff_monomial, coeff_mk] @[simp] theorem coeff_monomial_same (n : ℕ) (a : R) : coeff R n (monomial R n a) = a := MvPowerSeries.coeff_monomial_same _ _ @[simp] theorem coeff_comp_monomial (n : ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n variable (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : R⟦X⟧ →+* R := MvPowerSeries.constantCoeff Unit R /-- The constant formal power series. -/ def C : R →+* R⟦X⟧ := MvPowerSeries.C Unit R @[simp] lemma algebraMap_eq {R : Type*} [CommSemiring R] : algebraMap R R⟦X⟧ = C R := rfl variable {R} /-- The variable of the formal power series ring. -/ def X : R⟦X⟧ := MvPowerSeries.X () theorem commute_X (φ : R⟦X⟧) : Commute φ X := MvPowerSeries.commute_X _ _ theorem X_mul {φ : R⟦X⟧} : X * φ = φ * X := MvPowerSeries.X_mul theorem commute_X_pow (φ : R⟦X⟧) (n : ℕ) : Commute φ (X ^ n) := MvPowerSeries.commute_X_pow _ _ _ theorem X_pow_mul {φ : R⟦X⟧} {n : ℕ} : X ^ n * φ = φ * X ^ n := MvPowerSeries.X_pow_mul @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R 0) = constantCoeff R := by rw [coeff, Finsupp.single_zero] rfl theorem coeff_zero_eq_constantCoeff_apply (φ : R⟦X⟧) : coeff R 0 φ = constantCoeff R φ := by rw [coeff_zero_eq_constantCoeff] @[simp] theorem monomial_zero_eq_C : ⇑(monomial R 0) = C R := by -- This used to be `rw`, but we need `rw; rfl` after https://github.com/leanprover/lean4/pull/2644 rw [monomial, Finsupp.single_zero, MvPowerSeries.monomial_zero_eq_C] rfl theorem monomial_zero_eq_C_apply (a : R) : monomial R 0 a = C R a := by simp theorem coeff_C (n : ℕ) (a : R) : coeff R n (C R a : R⟦X⟧) = if n = 0 then a else 0 := by rw [← monomial_zero_eq_C_apply, coeff_monomial] @[simp] theorem coeff_zero_C (a : R) : coeff R 0 (C R a) = a := by rw [coeff_C, if_pos rfl] theorem coeff_ne_zero_C {a : R} {n : ℕ} (h : n ≠ 0) : coeff R n (C R a) = 0 := by rw [coeff_C, if_neg h] @[simp] theorem coeff_succ_C {a : R} {n : ℕ} : coeff R (n + 1) (C R a) = 0 := coeff_ne_zero_C n.succ_ne_zero theorem C_injective : Function.Injective (C R) := by intro a b H simp_rw [PowerSeries.ext_iff] at H simpa only [coeff_zero_C] using H 0 protected theorem subsingleton_iff : Subsingleton R⟦X⟧ ↔ Subsingleton R := by refine ⟨fun h ↦ ?_, fun _ ↦ inferInstance⟩ rw [subsingleton_iff] at h ⊢ exact fun a b ↦ C_injective (h (C R a) (C R b)) theorem X_eq : (X : R⟦X⟧) = monomial R 1 1 := rfl theorem coeff_X (n : ℕ) : coeff R n (X : R⟦X⟧) = if n = 1 then 1 else 0 := by
rw [X_eq, coeff_monomial] @[simp] theorem coeff_zero_X : coeff R 0 (X : R⟦X⟧) = 0 := by
Mathlib/RingTheory/PowerSeries/Basic.lean
267
270
/- Copyright (c) 2021 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.Extreme import Mathlib.Analysis.Convex.Function import Mathlib.Topology.Algebra.Module.LinearMap import Mathlib.Topology.Order.OrderClosed /-! # Exposed sets This file defines exposed sets and exposed points for sets in a real vector space. An exposed subset of `A` is a subset of `A` that is the set of all maximal points of a functional (a continuous linear map `E → 𝕜`) over `A`. By convention, `∅` is an exposed subset of all sets. This allows for better functoriality of the definition (the intersection of two exposed subsets is exposed, faces of a polytope form a bounded lattice). This is an analytic notion of "being on the side of". It is stronger than being extreme (see `IsExposed.isExtreme`), but weaker (for exposed points) than being a vertex. An exposed set of `A` is sometimes called a "face of `A`", but we decided to reserve this terminology to the more specific notion of a face of a polytope (sometimes hopefully soon out on mathlib!). ## Main declarations * `IsExposed 𝕜 A B`: States that `B` is an exposed set of `A` (in the literature, `A` is often implicit). * `IsExposed.isExtreme`: An exposed set is also extreme. ## References See chapter 8 of [Barry Simon, *Convexity*][simon2011] ## TODO Prove lemmas relating exposed sets and points to the intrinsic frontier. -/ open Affine Set section PreorderSemiring variable (𝕜 : Type*) {E : Type*} [TopologicalSpace 𝕜] [Semiring 𝕜] [Preorder 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] {A B : Set E} /-- A set `B` is exposed with respect to `A` iff it maximizes some functional over `A` (and contains all points maximizing it). Written `IsExposed 𝕜 A B`. -/ def IsExposed (A B : Set E) : Prop := B.Nonempty → ∃ l : E →L[𝕜] 𝕜, B = { x ∈ A | ∀ y ∈ A, l y ≤ l x } end PreorderSemiring section OrderedRing variable {𝕜 : Type*} {E : Type*} [TopologicalSpace 𝕜] [Ring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] [TopologicalSpace E] [Module 𝕜 E] {l : E →L[𝕜] 𝕜} {A B C : Set E} {x : E} /-- A useful way to build exposed sets from intersecting `A` with half-spaces (modelled by an inequality with a functional). -/ def ContinuousLinearMap.toExposed (l : E →L[𝕜] 𝕜) (A : Set E) : Set E := { x ∈ A | ∀ y ∈ A, l y ≤ l x } theorem ContinuousLinearMap.toExposed.isExposed : IsExposed 𝕜 A (l.toExposed A) := fun _ => ⟨l, rfl⟩ theorem isExposed_empty : IsExposed 𝕜 A ∅ := fun ⟨_, hx⟩ => by exfalso exact hx namespace IsExposed protected theorem subset (hAB : IsExposed 𝕜 A B) : B ⊆ A := by rintro x hx obtain ⟨_, rfl⟩ := hAB ⟨x, hx⟩ exact hx.1 @[refl] protected theorem refl (A : Set E) : IsExposed 𝕜 A A := fun ⟨_, _⟩ => ⟨0, Subset.antisymm (fun _ hx => ⟨hx, fun _ _ => le_refl 0⟩) fun _ hx => hx.1⟩ protected theorem antisymm (hB : IsExposed 𝕜 A B) (hA : IsExposed 𝕜 B A) : A = B := hA.subset.antisymm hB.subset /-! `IsExposed` is *not* transitive: Consider a (topologically) open cube with vertices `A₀₀₀, ..., A₁₁₁` and add to it the triangle `A₀₀₀A₀₀₁A₀₁₀`. Then `A₀₀₁A₀₁₀` is an exposed subset of `A₀₀₀A₀₀₁A₀₁₀` which is an exposed subset of the cube, but `A₀₀₁A₀₁₀` is not itself an exposed subset of the cube. -/ protected theorem mono (hC : IsExposed 𝕜 A C) (hBA : B ⊆ A) (hCB : C ⊆ B) : IsExposed 𝕜 B C := by rintro ⟨w, hw⟩ obtain ⟨l, rfl⟩ := hC ⟨w, hw⟩ exact ⟨l, Subset.antisymm (fun x hx => ⟨hCB hx, fun y hy => hx.2 y (hBA hy)⟩) fun x hx => ⟨hBA hx.1, fun y hy => (hw.2 y hy).trans (hx.2 w (hCB hw))⟩⟩ /-- If `B` is a nonempty exposed subset of `A`, then `B` is the intersection of `A` with some closed half-space. The converse is *not* true. It would require that the corresponding open half-space doesn't intersect `A`. -/ theorem eq_inter_halfSpace' {A B : Set E} (hAB : IsExposed 𝕜 A B) (hB : B.Nonempty) : ∃ l : E →L[𝕜] 𝕜, ∃ a, B = { x ∈ A | a ≤ l x } := by obtain ⟨l, rfl⟩ := hAB hB obtain ⟨w, hw⟩ := hB exact ⟨l, l w, Subset.antisymm (fun x hx => ⟨hx.1, hx.2 w hw.1⟩) fun x hx => ⟨hx.1, fun y hy => (hw.2 y hy).trans hx.2⟩⟩ @[deprecated (since := "2024-11-12")] alias eq_inter_halfspace' := eq_inter_halfSpace' /-- For nontrivial `𝕜`, if `B` is an exposed subset of `A`, then `B` is the intersection of `A` with some closed half-space. The converse is *not* true. It would require that the corresponding open half-space doesn't intersect `A`. -/ theorem eq_inter_halfSpace [IsOrderedRing 𝕜] [Nontrivial 𝕜] {A B : Set E} (hAB : IsExposed 𝕜 A B) : ∃ l : E →L[𝕜] 𝕜, ∃ a, B = { x ∈ A | a ≤ l x } := by obtain rfl | hB := B.eq_empty_or_nonempty · refine ⟨0, 1, ?_⟩ rw [eq_comm, eq_empty_iff_forall_not_mem] rintro x ⟨-, h⟩ rw [ContinuousLinearMap.zero_apply] at h have : ¬(1 : 𝕜) ≤ 0 := not_le_of_lt zero_lt_one contradiction exact hAB.eq_inter_halfSpace' hB @[deprecated (since := "2024-11-12")] alias eq_inter_halfspace := eq_inter_halfSpace protected theorem inter [IsOrderedRing 𝕜] [ContinuousAdd 𝕜] {A B C : Set E} (hB : IsExposed 𝕜 A B) (hC : IsExposed 𝕜 A C) : IsExposed 𝕜 A (B ∩ C) := by rintro ⟨w, hwB, hwC⟩ obtain ⟨l₁, rfl⟩ := hB ⟨w, hwB⟩ obtain ⟨l₂, rfl⟩ := hC ⟨w, hwC⟩ refine ⟨l₁ + l₂, Subset.antisymm ?_ ?_⟩ · rintro x ⟨⟨hxA, hxB⟩, ⟨-, hxC⟩⟩ exact ⟨hxA, fun z hz => add_le_add (hxB z hz) (hxC z hz)⟩ rintro x ⟨hxA, hx⟩ refine ⟨⟨hxA, fun y hy => ?_⟩, hxA, fun y hy => ?_⟩ · exact (add_le_add_iff_right (l₂ x)).1 ((add_le_add (hwB.2 y hy) (hwC.2 x hxA)).trans (hx w hwB.1)) · exact (add_le_add_iff_left (l₁ x)).1 (le_trans (add_le_add (hwB.2 x hxA) (hwC.2 y hy)) (hx w hwB.1)) theorem sInter [IsOrderedRing 𝕜] [ContinuousAdd 𝕜] {F : Finset (Set E)} (hF : F.Nonempty) (hAF : ∀ B ∈ F, IsExposed 𝕜 A B) : IsExposed 𝕜 A (⋂₀ F) := by classical induction F using Finset.induction with | empty => exfalso; exact Finset.not_nonempty_empty hF | insert C F _ hF' => rw [Finset.coe_insert, sInter_insert] obtain rfl | hFnemp := F.eq_empty_or_nonempty · rw [Finset.coe_empty, sInter_empty, inter_univ] exact hAF C (Finset.mem_singleton_self C) · exact (hAF C (Finset.mem_insert_self C F)).inter (hF' hFnemp fun B hB => hAF B (Finset.mem_insert_of_mem hB)) theorem inter_left (hC : IsExposed 𝕜 A C) (hCB : C ⊆ B) : IsExposed 𝕜 (A ∩ B) C := by rintro ⟨w, hw⟩ obtain ⟨l, rfl⟩ := hC ⟨w, hw⟩ exact ⟨l, Subset.antisymm (fun x hx => ⟨⟨hx.1, hCB hx⟩, fun y hy => hx.2 y hy.1⟩) fun x ⟨⟨hxC, _⟩, hx⟩ => ⟨hxC, fun y hy => (hw.2 y hy).trans (hx w ⟨hC.subset hw, hCB hw⟩)⟩⟩ theorem inter_right (hC : IsExposed 𝕜 B C) (hCA : C ⊆ A) : IsExposed 𝕜 (A ∩ B) C := by rw [inter_comm] exact hC.inter_left hCA protected theorem isClosed [OrderClosedTopology 𝕜] {A B : Set E} (hAB : IsExposed 𝕜 A B) (hA : IsClosed A) : IsClosed B := by obtain rfl | hB := B.eq_empty_or_nonempty · simp obtain ⟨l, a, rfl⟩ := hAB.eq_inter_halfSpace' hB exact hA.isClosed_le continuousOn_const l.continuous.continuousOn protected theorem isCompact [OrderClosedTopology 𝕜] [T2Space E] {A B : Set E} (hAB : IsExposed 𝕜 A B) (hA : IsCompact A) : IsCompact B :=
hA.of_isClosed_subset (hAB.isClosed hA.isClosed) hAB.subset end IsExposed variable (𝕜) in
Mathlib/Analysis/Convex/Exposed.lean
169
173
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Batteries.Tactic.Congr import Mathlib.Data.Option.Basic import Mathlib.Data.Prod.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Data.Set.SymmDiff import Mathlib.Data.Set.Inclusion /-! # Images and preimages of sets ## Main definitions * `preimage f t : Set α` : the preimage f⁻¹(t) (written `f ⁻¹' t` in Lean) of a subset of β. * `range f : Set β` : the image of `univ` under `f`. Also works for `{p : Prop} (f : p → α)` (unlike `image`) ## Notation * `f ⁻¹' t` for `Set.preimage f t` * `f '' s` for `Set.image f s` ## Tags set, sets, image, preimage, pre-image, range -/ assert_not_exists WithTop OrderIso universe u v open Function Set namespace Set variable {α β γ : Type*} {ι : Sort*} /-! ### Inverse image -/ section Preimage variable {f : α → β} {g : β → γ} @[simp] theorem preimage_empty : f ⁻¹' ∅ = ∅ := rfl theorem preimage_congr {f g : α → β} {s : Set β} (h : ∀ x : α, f x = g x) : f ⁻¹' s = g ⁻¹' s := by congr with x simp [h] @[gcongr] theorem preimage_mono {s t : Set β} (h : s ⊆ t) : f ⁻¹' s ⊆ f ⁻¹' t := fun _ hx => h hx @[simp, mfld_simps] theorem preimage_univ : f ⁻¹' univ = univ := rfl theorem subset_preimage_univ {s : Set α} : s ⊆ f ⁻¹' univ := subset_univ _ @[simp, mfld_simps] theorem preimage_inter {s t : Set β} : f ⁻¹' (s ∩ t) = f ⁻¹' s ∩ f ⁻¹' t := rfl @[simp] theorem preimage_union {s t : Set β} : f ⁻¹' (s ∪ t) = f ⁻¹' s ∪ f ⁻¹' t := rfl @[simp] theorem preimage_compl {s : Set β} : f ⁻¹' sᶜ = (f ⁻¹' s)ᶜ := rfl @[simp] theorem preimage_diff (f : α → β) (s t : Set β) : f ⁻¹' (s \ t) = f ⁻¹' s \ f ⁻¹' t := rfl open scoped symmDiff in @[simp] lemma preimage_symmDiff {f : α → β} (s t : Set β) : f ⁻¹' (s ∆ t) = (f ⁻¹' s) ∆ (f ⁻¹' t) := rfl @[simp] theorem preimage_ite (f : α → β) (s t₁ t₂ : Set β) : f ⁻¹' s.ite t₁ t₂ = (f ⁻¹' s).ite (f ⁻¹' t₁) (f ⁻¹' t₂) := rfl @[simp] theorem preimage_setOf_eq {p : α → Prop} {f : β → α} : f ⁻¹' { a | p a } = { a | p (f a) } := rfl @[simp] theorem preimage_id_eq : preimage (id : α → α) = id := rfl @[mfld_simps] theorem preimage_id {s : Set α} : id ⁻¹' s = s := rfl @[simp, mfld_simps] theorem preimage_id' {s : Set α} : (fun x => x) ⁻¹' s = s := rfl @[simp] theorem preimage_const_of_mem {b : β} {s : Set β} (h : b ∈ s) : (fun _ : α => b) ⁻¹' s = univ := eq_univ_of_forall fun _ => h @[simp] theorem preimage_const_of_not_mem {b : β} {s : Set β} (h : b ∉ s) : (fun _ : α => b) ⁻¹' s = ∅ := eq_empty_of_subset_empty fun _ hx => h hx theorem preimage_const (b : β) (s : Set β) [Decidable (b ∈ s)] : (fun _ : α => b) ⁻¹' s = if b ∈ s then univ else ∅ := by split_ifs with hb exacts [preimage_const_of_mem hb, preimage_const_of_not_mem hb] /-- If preimage of each singleton under `f : α → β` is either empty or the whole type, then `f` is a constant. -/ lemma exists_eq_const_of_preimage_singleton [Nonempty β] {f : α → β} (hf : ∀ b : β, f ⁻¹' {b} = ∅ ∨ f ⁻¹' {b} = univ) : ∃ b, f = const α b := by rcases em (∃ b, f ⁻¹' {b} = univ) with ⟨b, hb⟩ | hf' · exact ⟨b, funext fun x ↦ eq_univ_iff_forall.1 hb x⟩ · have : ∀ x b, f x ≠ b := fun x b ↦ eq_empty_iff_forall_not_mem.1 ((hf b).resolve_right fun h ↦ hf' ⟨b, h⟩) x exact ⟨Classical.arbitrary β, funext fun x ↦ absurd rfl (this x _)⟩ theorem preimage_comp {s : Set γ} : g ∘ f ⁻¹' s = f ⁻¹' (g ⁻¹' s) := rfl theorem preimage_comp_eq : preimage (g ∘ f) = preimage f ∘ preimage g := rfl theorem preimage_iterate_eq {f : α → α} {n : ℕ} : Set.preimage f^[n] = (Set.preimage f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ, iterate_succ', preimage_comp_eq, ih] theorem preimage_preimage {g : β → γ} {f : α → β} {s : Set γ} : f ⁻¹' (g ⁻¹' s) = (fun x => g (f x)) ⁻¹' s := preimage_comp.symm theorem eq_preimage_subtype_val_iff {p : α → Prop} {s : Set (Subtype p)} {t : Set α} : s = Subtype.val ⁻¹' t ↔ ∀ (x) (h : p x), (⟨x, h⟩ : Subtype p) ∈ s ↔ x ∈ t := ⟨fun s_eq x h => by rw [s_eq] simp, fun h => ext fun ⟨x, hx⟩ => by simp [h]⟩ theorem nonempty_of_nonempty_preimage {s : Set β} {f : α → β} (hf : (f ⁻¹' s).Nonempty) : s.Nonempty := let ⟨x, hx⟩ := hf ⟨f x, hx⟩ @[simp] theorem preimage_singleton_true (p : α → Prop) : p ⁻¹' {True} = {a | p a} := by ext; simp @[simp] theorem preimage_singleton_false (p : α → Prop) : p ⁻¹' {False} = {a | ¬p a} := by ext; simp theorem preimage_subtype_coe_eq_compl {s u v : Set α} (hsuv : s ⊆ u ∪ v) (H : s ∩ (u ∩ v) = ∅) : ((↑) : s → α) ⁻¹' u = ((↑) ⁻¹' v)ᶜ := by ext ⟨x, x_in_s⟩ constructor · intro x_in_u x_in_v exact eq_empty_iff_forall_not_mem.mp H x ⟨x_in_s, ⟨x_in_u, x_in_v⟩⟩ · intro hx exact Or.elim (hsuv x_in_s) id fun hx' => hx.elim hx' lemma preimage_subset {s t} (hs : s ⊆ f '' t) (hf : Set.InjOn f (f ⁻¹' s)) : f ⁻¹' s ⊆ t := by rintro a ha obtain ⟨b, hb, hba⟩ := hs ha rwa [hf ha _ hba.symm] simpa [hba] end Preimage /-! ### Image of a set under a function -/ section Image variable {f : α → β} {s t : Set α} theorem image_eta (f : α → β) : f '' s = (fun x => f x) '' s := rfl theorem _root_.Function.Injective.mem_set_image {f : α → β} (hf : Injective f) {s : Set α} {a : α} : f a ∈ f '' s ↔ a ∈ s := ⟨fun ⟨_, hb, Eq⟩ => hf Eq ▸ hb, mem_image_of_mem f⟩ lemma preimage_subset_of_surjOn {t : Set β} (hf : Injective f) (h : SurjOn f s t) : f ⁻¹' t ⊆ s := fun _ hx ↦ hf.mem_set_image.1 <| h hx theorem forall_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∀ y ∈ f '' s, p y) ↔ ∀ ⦃x⦄, x ∈ s → p (f x) := by simp theorem exists_mem_image {f : α → β} {s : Set α} {p : β → Prop} : (∃ y ∈ f '' s, p y) ↔ ∃ x ∈ s, p (f x) := by simp @[congr] theorem image_congr {f g : α → β} {s : Set α} (h : ∀ a ∈ s, f a = g a) : f '' s = g '' s := by aesop /-- A common special case of `image_congr` -/ theorem image_congr' {f g : α → β} {s : Set α} (h : ∀ x : α, f x = g x) : f '' s = g '' s := image_congr fun x _ => h x @[gcongr] lemma image_mono (h : s ⊆ t) : f '' s ⊆ f '' t := by rintro - ⟨a, ha, rfl⟩; exact mem_image_of_mem f (h ha) theorem image_comp (f : β → γ) (g : α → β) (a : Set α) : f ∘ g '' a = f '' (g '' a) := by aesop theorem image_comp_eq {g : β → γ} : image (g ∘ f) = image g ∘ image f := by ext; simp /-- A variant of `image_comp`, useful for rewriting -/ theorem image_image (g : β → γ) (f : α → β) (s : Set α) : g '' (f '' s) = (fun x => g (f x)) '' s := (image_comp g f s).symm theorem image_comm {β'} {f : β → γ} {g : α → β} {f' : α → β'} {g' : β' → γ} (h_comm : ∀ a, f (g a) = g' (f' a)) : (s.image g).image f = (s.image f').image g' := by simp_rw [image_image, h_comm] theorem _root_.Function.Semiconj.set_image {f : α → β} {ga : α → α} {gb : β → β} (h : Function.Semiconj f ga gb) : Function.Semiconj (image f) (image ga) (image gb) := fun _ => image_comm h theorem _root_.Function.Commute.set_image {f g : α → α} (h : Function.Commute f g) : Function.Commute (image f) (image g) := Function.Semiconj.set_image h /-- Image is monotone with respect to `⊆`. See `Set.monotone_image` for the statement in terms of `≤`. -/ @[gcongr] theorem image_subset {a b : Set α} (f : α → β) (h : a ⊆ b) : f '' a ⊆ f '' b := by simp only [subset_def, mem_image] exact fun x => fun ⟨w, h1, h2⟩ => ⟨w, h h1, h2⟩ /-- `Set.image` is monotone. See `Set.image_subset` for the statement in terms of `⊆`. -/ lemma monotone_image {f : α → β} : Monotone (image f) := fun _ _ => image_subset _ theorem image_union (f : α → β) (s t : Set α) : f '' (s ∪ t) = f '' s ∪ f '' t := ext fun x => ⟨by rintro ⟨a, h | h, rfl⟩ <;> [left; right] <;> exact ⟨_, h, rfl⟩, by rintro (⟨a, h, rfl⟩ | ⟨a, h, rfl⟩) <;> refine ⟨_, ?_, rfl⟩ · exact mem_union_left t h · exact mem_union_right s h⟩ @[simp] theorem image_empty (f : α → β) : f '' ∅ = ∅ := by ext simp theorem image_inter_subset (f : α → β) (s t : Set α) : f '' (s ∩ t) ⊆ f '' s ∩ f '' t := subset_inter (image_subset _ inter_subset_left) (image_subset _ inter_subset_right) theorem image_inter_on {f : α → β} {s t : Set α} (h : ∀ x ∈ t, ∀ y ∈ s, f x = f y → x = y) : f '' (s ∩ t) = f '' s ∩ f '' t := (image_inter_subset _ _ _).antisymm fun b ⟨⟨a₁, ha₁, h₁⟩, ⟨a₂, ha₂, h₂⟩⟩ ↦ have : a₂ = a₁ := h _ ha₂ _ ha₁ (by simp [*]) ⟨a₁, ⟨ha₁, this ▸ ha₂⟩, h₁⟩ theorem image_inter {f : α → β} {s t : Set α} (H : Injective f) : f '' (s ∩ t) = f '' s ∩ f '' t := image_inter_on fun _ _ _ _ h => H h theorem image_univ_of_surjective {ι : Type*} {f : ι → β} (H : Surjective f) : f '' univ = univ := eq_univ_of_forall <| by simpa [image] @[simp] theorem image_singleton {f : α → β} {a : α} : f '' {a} = {f a} := by ext simp [image, eq_comm] @[simp] theorem Nonempty.image_const {s : Set α} (hs : s.Nonempty) (a : β) : (fun _ => a) '' s = {a} := ext fun _ => ⟨fun ⟨_, _, h⟩ => h ▸ mem_singleton _, fun h => (eq_of_mem_singleton h).symm ▸ hs.imp fun _ hy => ⟨hy, rfl⟩⟩ @[simp, mfld_simps] theorem image_eq_empty {α β} {f : α → β} {s : Set α} : f '' s = ∅ ↔ s = ∅ := by simp only [eq_empty_iff_forall_not_mem] exact ⟨fun H a ha => H _ ⟨_, ha, rfl⟩, fun H b ⟨_, ha, _⟩ => H _ ha⟩ theorem preimage_compl_eq_image_compl [BooleanAlgebra α] (S : Set α) : HasCompl.compl ⁻¹' S = HasCompl.compl '' S := Set.ext fun x => ⟨fun h => ⟨xᶜ, h, compl_compl x⟩, fun h => Exists.elim h fun _ hy => (compl_eq_comm.mp hy.2).symm.subst hy.1⟩ theorem mem_compl_image [BooleanAlgebra α] (t : α) (S : Set α) : t ∈ HasCompl.compl '' S ↔ tᶜ ∈ S := by simp [← preimage_compl_eq_image_compl] @[simp] theorem image_id_eq : image (id : α → α) = id := by ext; simp /-- A variant of `image_id` -/ @[simp] theorem image_id' (s : Set α) : (fun x => x) '' s = s := by ext simp theorem image_id (s : Set α) : id '' s = s := by simp lemma image_iterate_eq {f : α → α} {n : ℕ} : image (f^[n]) = (image f)^[n] := by induction n with | zero => simp | succ n ih => rw [iterate_succ', iterate_succ', ← ih, image_comp_eq] theorem compl_compl_image [BooleanAlgebra α] (S : Set α) : HasCompl.compl '' (HasCompl.compl '' S) = S := by rw [← image_comp, compl_comp_compl, image_id] theorem image_insert_eq {f : α → β} {a : α} {s : Set α} : f '' insert a s = insert (f a) (f '' s) := by ext simp [and_or_left, exists_or, eq_comm, or_comm, and_comm] theorem image_pair (f : α → β) (a b : α) : f '' {a, b} = {f a, f b} := by simp only [image_insert_eq, image_singleton] theorem image_subset_preimage_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set α) : f '' s ⊆ g ⁻¹' s := fun _ ⟨a, h, e⟩ => e ▸ ((I a).symm ▸ h : g (f a) ∈ s) theorem preimage_subset_image_of_inverse {f : α → β} {g : β → α} (I : LeftInverse g f) (s : Set β) : f ⁻¹' s ⊆ g '' s := fun b h => ⟨f b, h, I b⟩ theorem range_inter_ssubset_iff_preimage_ssubset {f : α → β} {S S' : Set β} : range f ∩ S ⊂ range f ∩ S' ↔ f ⁻¹' S ⊂ f ⁻¹' S' := by simp only [Set.ssubset_iff_exists] apply and_congr ?_ (by aesop) constructor all_goals intro r x hx simp_all only [subset_inter_iff, inter_subset_left, true_and, mem_preimage, mem_inter_iff, mem_range, true_and] aesop theorem image_eq_preimage_of_inverse {f : α → β} {g : β → α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : image f = preimage g := funext fun s => Subset.antisymm (image_subset_preimage_of_inverse h₁ s) (preimage_subset_image_of_inverse h₂ s) theorem mem_image_iff_of_inverse {f : α → β} {g : β → α} {b : β} {s : Set α} (h₁ : LeftInverse g f) (h₂ : RightInverse g f) : b ∈ f '' s ↔ g b ∈ s := by rw [image_eq_preimage_of_inverse h₁ h₂]; rfl theorem image_compl_subset {f : α → β} {s : Set α} (H : Injective f) : f '' sᶜ ⊆ (f '' s)ᶜ := Disjoint.subset_compl_left <| by simp [disjoint_iff_inf_le, ← image_inter H] theorem subset_image_compl {f : α → β} {s : Set α} (H : Surjective f) : (f '' s)ᶜ ⊆ f '' sᶜ := compl_subset_iff_union.2 <| by rw [← image_union] simp [image_univ_of_surjective H] theorem image_compl_eq {f : α → β} {s : Set α} (H : Bijective f) : f '' sᶜ = (f '' s)ᶜ := Subset.antisymm (image_compl_subset H.1) (subset_image_compl H.2) theorem subset_image_diff (f : α → β) (s t : Set α) : f '' s \ f '' t ⊆ f '' (s \ t) := by rw [diff_subset_iff, ← image_union, union_diff_self] exact image_subset f subset_union_right open scoped symmDiff in theorem subset_image_symmDiff : (f '' s) ∆ (f '' t) ⊆ f '' s ∆ t := (union_subset_union (subset_image_diff _ _ _) <| subset_image_diff _ _ _).trans (superset_of_eq (image_union _ _ _)) theorem image_diff {f : α → β} (hf : Injective f) (s t : Set α) : f '' (s \ t) = f '' s \ f '' t := Subset.antisymm (Subset.trans (image_inter_subset _ _ _) <| inter_subset_inter_right _ <| image_compl_subset hf) (subset_image_diff f s t) open scoped symmDiff in theorem image_symmDiff (hf : Injective f) (s t : Set α) : f '' s ∆ t = (f '' s) ∆ (f '' t) := by simp_rw [Set.symmDiff_def, image_union, image_diff hf] theorem Nonempty.image (f : α → β) {s : Set α} : s.Nonempty → (f '' s).Nonempty | ⟨x, hx⟩ => ⟨f x, mem_image_of_mem f hx⟩ theorem Nonempty.of_image {f : α → β} {s : Set α} : (f '' s).Nonempty → s.Nonempty | ⟨_, x, hx, _⟩ => ⟨x, hx⟩ @[simp] theorem image_nonempty {f : α → β} {s : Set α} : (f '' s).Nonempty ↔ s.Nonempty := ⟨Nonempty.of_image, fun h => h.image f⟩ theorem Nonempty.preimage {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : Surjective f) : (f ⁻¹' s).Nonempty := let ⟨y, hy⟩ := hs let ⟨x, hx⟩ := hf y ⟨x, mem_preimage.2 <| hx.symm ▸ hy⟩ instance (f : α → β) (s : Set α) [Nonempty s] : Nonempty (f '' s) := (Set.Nonempty.image f .of_subtype).to_subtype /-- image and preimage are a Galois connection -/ @[simp] theorem image_subset_iff {s : Set α} {t : Set β} {f : α → β} : f '' s ⊆ t ↔ s ⊆ f ⁻¹' t := forall_mem_image theorem image_preimage_subset (f : α → β) (s : Set β) : f '' (f ⁻¹' s) ⊆ s := image_subset_iff.2 Subset.rfl theorem subset_preimage_image (f : α → β) (s : Set α) : s ⊆ f ⁻¹' (f '' s) := fun _ => mem_image_of_mem f theorem preimage_image_univ {f : α → β} : f ⁻¹' (f '' univ) = univ := Subset.antisymm (fun _ _ => trivial) (subset_preimage_image f univ) @[simp] theorem preimage_image_eq {f : α → β} (s : Set α) (h : Injective f) : f ⁻¹' (f '' s) = s := Subset.antisymm (fun _ ⟨_, hy, e⟩ => h e ▸ hy) (subset_preimage_image f s) @[simp] theorem image_preimage_eq {f : α → β} (s : Set β) (h : Surjective f) : f '' (f ⁻¹' s) = s := Subset.antisymm (image_preimage_subset f s) fun x hx => let ⟨y, e⟩ := h x ⟨y, (e.symm ▸ hx : f y ∈ s), e⟩ @[simp] theorem Nonempty.subset_preimage_const {s : Set α} (hs : Set.Nonempty s) (t : Set β) (a : β) : s ⊆ (fun _ => a) ⁻¹' t ↔ a ∈ t := by rw [← image_subset_iff, hs.image_const, singleton_subset_iff] -- Note defeq abuse identifying `preimage` with function composition in the following two proofs. @[simp] theorem preimage_injective : Injective (preimage f) ↔ Surjective f := injective_comp_right_iff_surjective @[simp] theorem preimage_surjective : Surjective (preimage f) ↔ Injective f := surjective_comp_right_iff_injective @[simp] theorem preimage_eq_preimage {f : β → α} (hf : Surjective f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := (preimage_injective.mpr hf).eq_iff theorem image_inter_preimage (f : α → β) (s : Set α) (t : Set β) : f '' (s ∩ f ⁻¹' t) = f '' s ∩ t := by apply Subset.antisymm · calc f '' (s ∩ f ⁻¹' t) ⊆ f '' s ∩ f '' (f ⁻¹' t) := image_inter_subset _ _ _ _ ⊆ f '' s ∩ t := inter_subset_inter_right _ (image_preimage_subset f t) · rintro _ ⟨⟨x, h', rfl⟩, h⟩ exact ⟨x, ⟨h', h⟩, rfl⟩ theorem image_preimage_inter (f : α → β) (s : Set α) (t : Set β) : f '' (f ⁻¹' t ∩ s) = t ∩ f '' s := by simp only [inter_comm, image_inter_preimage] @[simp] theorem image_inter_nonempty_iff {f : α → β} {s : Set α} {t : Set β} : (f '' s ∩ t).Nonempty ↔ (s ∩ f ⁻¹' t).Nonempty := by rw [← image_inter_preimage, image_nonempty] theorem image_diff_preimage {f : α → β} {s : Set α} {t : Set β} : f '' (s \ f ⁻¹' t) = f '' s \ t := by simp_rw [diff_eq, ← preimage_compl, image_inter_preimage] theorem compl_image : image (compl : Set α → Set α) = preimage compl := image_eq_preimage_of_inverse compl_compl compl_compl theorem compl_image_set_of {p : Set α → Prop} : compl '' { s | p s } = { s | p sᶜ } := congr_fun compl_image p theorem inter_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∩ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∩ t) := fun _ h => ⟨mem_image_of_mem _ h.left, h.right⟩ theorem union_preimage_subset (s : Set α) (t : Set β) (f : α → β) : s ∪ f ⁻¹' t ⊆ f ⁻¹' (f '' s ∪ t) := fun _ h => Or.elim h (fun l => Or.inl <| mem_image_of_mem _ l) fun r => Or.inr r theorem subset_image_union (f : α → β) (s : Set α) (t : Set β) : f '' (s ∪ f ⁻¹' t) ⊆ f '' s ∪ t := image_subset_iff.2 (union_preimage_subset _ _ _) theorem preimage_subset_iff {A : Set α} {B : Set β} {f : α → β} : f ⁻¹' B ⊆ A ↔ ∀ a : α, f a ∈ B → a ∈ A := Iff.rfl theorem image_eq_image {f : α → β} (hf : Injective f) : f '' s = f '' t ↔ s = t := Iff.symm <| (Iff.intro fun eq => eq ▸ rfl) fun eq => by rw [← preimage_image_eq s hf, ← preimage_image_eq t hf, eq] theorem subset_image_iff {t : Set β} : t ⊆ f '' s ↔ ∃ u, u ⊆ s ∧ f '' u = t := by refine ⟨fun h ↦ ⟨f ⁻¹' t ∩ s, inter_subset_right, ?_⟩, fun ⟨u, hu, hu'⟩ ↦ hu'.symm ▸ image_mono hu⟩ rwa [image_preimage_inter, inter_eq_left] @[simp] lemma exists_subset_image_iff {p : Set β → Prop} : (∃ t ⊆ f '' s, p t) ↔ ∃ t ⊆ s, p (f '' t) := by simp [subset_image_iff] @[simp] lemma forall_subset_image_iff {p : Set β → Prop} : (∀ t ⊆ f '' s, p t) ↔ ∀ t ⊆ s, p (f '' t) := by simp [subset_image_iff] theorem image_subset_image_iff {f : α → β} (hf : Injective f) : f '' s ⊆ f '' t ↔ s ⊆ t := by refine Iff.symm <| (Iff.intro (image_subset f)) fun h => ?_ rw [← preimage_image_eq s hf, ← preimage_image_eq t hf] exact preimage_mono h theorem prod_quotient_preimage_eq_image [s : Setoid α] (g : Quotient s → β) {h : α → β} (Hh : h = g ∘ Quotient.mk'') (r : Set (β × β)) : { x : Quotient s × Quotient s | (g x.1, g x.2) ∈ r } = (fun a : α × α => (⟦a.1⟧, ⟦a.2⟧)) '' ((fun a : α × α => (h a.1, h a.2)) ⁻¹' r) := Hh.symm ▸ Set.ext fun ⟨a₁, a₂⟩ => ⟨Quot.induction_on₂ a₁ a₂ fun a₁ a₂ h => ⟨(a₁, a₂), h, rfl⟩, fun ⟨⟨b₁, b₂⟩, h₁, h₂⟩ => show (g a₁, g a₂) ∈ r from have h₃ : ⟦b₁⟧ = a₁ ∧ ⟦b₂⟧ = a₂ := Prod.ext_iff.1 h₂ h₃.1 ▸ h₃.2 ▸ h₁⟩ theorem exists_image_iff (f : α → β) (x : Set α) (P : β → Prop) : (∃ a : f '' x, P a) ↔ ∃ a : x, P (f a) := ⟨fun ⟨a, h⟩ => ⟨⟨_, a.prop.choose_spec.1⟩, a.prop.choose_spec.2.symm ▸ h⟩, fun ⟨a, h⟩ => ⟨⟨_, _, a.prop, rfl⟩, h⟩⟩ theorem imageFactorization_eq {f : α → β} {s : Set α} : Subtype.val ∘ imageFactorization f s = f ∘ Subtype.val := funext fun _ => rfl theorem surjective_onto_image {f : α → β} {s : Set α} : Surjective (imageFactorization f s) := fun ⟨_, ⟨a, ha, rfl⟩⟩ => ⟨⟨a, ha⟩, rfl⟩ /-- If the only elements outside `s` are those left fixed by `σ`, then mapping by `σ` has no effect. -/ theorem image_perm {s : Set α} {σ : Equiv.Perm α} (hs : { a : α | σ a ≠ a } ⊆ s) : σ '' s = s := by ext i obtain hi | hi := eq_or_ne (σ i) i · refine ⟨?_, fun h => ⟨i, h, hi⟩⟩ rintro ⟨j, hj, h⟩ rwa [σ.injective (hi.trans h.symm)] · refine iff_of_true ⟨σ.symm i, hs fun h => hi ?_, σ.apply_symm_apply _⟩ (hs hi) convert congr_arg σ h <;> exact (σ.apply_symm_apply _).symm end Image /-! ### Lemmas about the powerset and image. -/ /-- The powerset of `{a} ∪ s` is `𝒫 s` together with `{a} ∪ t` for each `t ∈ 𝒫 s`. -/ theorem powerset_insert (s : Set α) (a : α) : 𝒫 insert a s = 𝒫 s ∪ insert a '' 𝒫 s := by ext t simp_rw [mem_union, mem_image, mem_powerset_iff] constructor · intro h by_cases hs : a ∈ t · right refine ⟨t \ {a}, ?_, ?_⟩ · rw [diff_singleton_subset_iff] assumption · rw [insert_diff_singleton, insert_eq_of_mem hs] · left exact (subset_insert_iff_of_not_mem hs).mp h · rintro (h | ⟨s', h₁, rfl⟩) · exact subset_trans h (subset_insert a s) · exact insert_subset_insert h₁ /-! ### Lemmas about range of a function. -/ section Range variable {f : ι → α} {s t : Set α} theorem forall_mem_range {p : α → Prop} : (∀ a ∈ range f, p a) ↔ ∀ i, p (f i) := by simp theorem forall_subtype_range_iff {p : range f → Prop} : (∀ a : range f, p a) ↔ ∀ i, p ⟨f i, mem_range_self _⟩ := ⟨fun H _ => H _, fun H ⟨y, i, hi⟩ => by subst hi apply H⟩ theorem exists_range_iff {p : α → Prop} : (∃ a ∈ range f, p a) ↔ ∃ i, p (f i) := by simp theorem exists_subtype_range_iff {p : range f → Prop} : (∃ a : range f, p a) ↔ ∃ i, p ⟨f i, mem_range_self _⟩ := ⟨fun ⟨⟨a, i, hi⟩, ha⟩ => by subst a exact ⟨i, ha⟩, fun ⟨_, hi⟩ => ⟨_, hi⟩⟩ theorem range_eq_univ : range f = univ ↔ Surjective f := eq_univ_iff_forall @[deprecated (since := "2024-11-11")] alias range_iff_surjective := range_eq_univ alias ⟨_, _root_.Function.Surjective.range_eq⟩ := range_eq_univ @[simp] theorem subset_range_of_surjective {f : α → β} (h : Surjective f) (s : Set β) : s ⊆ range f := Surjective.range_eq h ▸ subset_univ s @[simp] theorem image_univ {f : α → β} : f '' univ = range f := by ext simp [image, range] lemma image_compl_eq_range_diff_image {f : α → β} (hf : Injective f) (s : Set α) : f '' sᶜ = range f \ f '' s := by rw [← image_univ, ← image_diff hf, compl_eq_univ_diff] /-- Alias of `Set.image_compl_eq_range_sdiff_image`. -/ lemma range_diff_image {f : α → β} (hf : Injective f) (s : Set α) : range f \ f '' s = f '' sᶜ := by rw [image_compl_eq_range_diff_image hf] @[simp] theorem preimage_eq_univ_iff {f : α → β} {s} : f ⁻¹' s = univ ↔ range f ⊆ s := by rw [← univ_subset_iff, ← image_subset_iff, image_univ] theorem image_subset_range (f : α → β) (s) : f '' s ⊆ range f := by rw [← image_univ]; exact image_subset _ (subset_univ _) theorem mem_range_of_mem_image (f : α → β) (s) {x : β} (h : x ∈ f '' s) : x ∈ range f := image_subset_range f s h theorem _root_.Nat.mem_range_succ (i : ℕ) : i ∈ range Nat.succ ↔ 0 < i := ⟨by rintro ⟨n, rfl⟩ exact Nat.succ_pos n, fun h => ⟨_, Nat.succ_pred_eq_of_pos h⟩⟩ theorem Nonempty.preimage' {s : Set β} (hs : s.Nonempty) {f : α → β} (hf : s ⊆ range f) : (f ⁻¹' s).Nonempty := let ⟨_, hy⟩ := hs let ⟨x, hx⟩ := hf hy ⟨x, Set.mem_preimage.2 <| hx.symm ▸ hy⟩ theorem range_comp (g : α → β) (f : ι → α) : range (g ∘ f) = g '' range f := by aesop /-- Variant of `range_comp` using a lambda instead of function composition. -/ theorem range_comp' (g : α → β) (f : ι → α) : range (fun x => g (f x)) = g '' range f := range_comp g f theorem range_subset_iff : range f ⊆ s ↔ ∀ y, f y ∈ s := forall_mem_range theorem range_subset_range_iff_exists_comp {f : α → γ} {g : β → γ} : range f ⊆ range g ↔ ∃ h : α → β, f = g ∘ h := by simp only [range_subset_iff, mem_range, Classical.skolem, funext_iff, (· ∘ ·), eq_comm] theorem range_eq_iff (f : α → β) (s : Set β) : range f = s ↔ (∀ a, f a ∈ s) ∧ ∀ b ∈ s, ∃ a, f a = b := by rw [← range_subset_iff] exact le_antisymm_iff theorem range_comp_subset_range (f : α → β) (g : β → γ) : range (g ∘ f) ⊆ range g := by rw [range_comp]; apply image_subset_range theorem range_nonempty_iff_nonempty : (range f).Nonempty ↔ Nonempty ι := ⟨fun ⟨_, x, _⟩ => ⟨x⟩, fun ⟨x⟩ => ⟨f x, mem_range_self x⟩⟩ theorem range_nonempty [h : Nonempty ι] (f : ι → α) : (range f).Nonempty := range_nonempty_iff_nonempty.2 h @[simp] theorem range_eq_empty_iff {f : ι → α} : range f = ∅ ↔ IsEmpty ι := by rw [← not_nonempty_iff, ← range_nonempty_iff_nonempty, not_nonempty_iff_eq_empty] theorem range_eq_empty [IsEmpty ι] (f : ι → α) : range f = ∅ := range_eq_empty_iff.2 ‹_› instance instNonemptyRange [Nonempty ι] (f : ι → α) : Nonempty (range f) := (range_nonempty f).to_subtype @[simp] theorem image_union_image_compl_eq_range (f : α → β) : f '' s ∪ f '' sᶜ = range f := by rw [← image_union, ← image_univ, ← union_compl_self] theorem insert_image_compl_eq_range (f : α → β) (x : α) : insert (f x) (f '' {x}ᶜ) = range f := by rw [← image_insert_eq, insert_eq, union_compl_self, image_univ] theorem image_preimage_eq_range_inter {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = range f ∩ t := ext fun x => ⟨fun ⟨_, hx, HEq⟩ => HEq ▸ ⟨mem_range_self _, hx⟩, fun ⟨⟨y, h_eq⟩, hx⟩ => h_eq ▸ mem_image_of_mem f <| show y ∈ f ⁻¹' t by rw [preimage, mem_setOf, h_eq]; exact hx⟩ theorem image_preimage_eq_inter_range {f : α → β} {t : Set β} : f '' (f ⁻¹' t) = t ∩ range f := by rw [image_preimage_eq_range_inter, inter_comm] theorem image_preimage_eq_of_subset {f : α → β} {s : Set β} (hs : s ⊆ range f) : f '' (f ⁻¹' s) = s := by rw [image_preimage_eq_range_inter, inter_eq_self_of_subset_right hs] theorem image_preimage_eq_iff {f : α → β} {s : Set β} : f '' (f ⁻¹' s) = s ↔ s ⊆ range f := ⟨by intro h rw [← h] apply image_subset_range, image_preimage_eq_of_subset⟩ theorem subset_range_iff_exists_image_eq {f : α → β} {s : Set β} : s ⊆ range f ↔ ∃ t, f '' t = s := ⟨fun h => ⟨_, image_preimage_eq_iff.2 h⟩, fun ⟨_, ht⟩ => ht ▸ image_subset_range _ _⟩ theorem range_image (f : α → β) : range (image f) = 𝒫 range f := ext fun _ => subset_range_iff_exists_image_eq.symm @[simp] theorem exists_subset_range_and_iff {f : α → β} {p : Set β → Prop} : (∃ s, s ⊆ range f ∧ p s) ↔ ∃ s, p (f '' s) := by rw [← exists_range_iff, range_image]; rfl @[simp] theorem forall_subset_range_iff {f : α → β} {p : Set β → Prop} : (∀ s, s ⊆ range f → p s) ↔ ∀ s, p (f '' s) := by rw [← forall_mem_range, range_image]; simp only [mem_powerset_iff] @[simp] theorem preimage_subset_preimage_iff {s t : Set α} {f : β → α} (hs : s ⊆ range f) : f ⁻¹' s ⊆ f ⁻¹' t ↔ s ⊆ t := by constructor · intro h x hx rcases hs hx with ⟨y, rfl⟩ exact h hx intro h x; apply h theorem preimage_eq_preimage' {s t : Set α} {f : β → α} (hs : s ⊆ range f) (ht : t ⊆ range f) : f ⁻¹' s = f ⁻¹' t ↔ s = t := by constructor · intro h apply Subset.antisymm · rw [← preimage_subset_preimage_iff hs, h] · rw [← preimage_subset_preimage_iff ht, h] rintro rfl; rfl -- Not `@[simp]` since `simp` can prove this. theorem preimage_inter_range {f : α → β} {s : Set β} : f ⁻¹' (s ∩ range f) = f ⁻¹' s := Set.ext fun x => and_iff_left ⟨x, rfl⟩ -- Not `@[simp]` since `simp` can prove this. theorem preimage_range_inter {f : α → β} {s : Set β} : f ⁻¹' (range f ∩ s) = f ⁻¹' s := by rw [inter_comm, preimage_inter_range] theorem preimage_image_preimage {f : α → β} {s : Set β} : f ⁻¹' (f '' (f ⁻¹' s)) = f ⁻¹' s := by rw [image_preimage_eq_range_inter, preimage_range_inter] @[simp, mfld_simps] theorem range_id : range (@id α) = univ := range_eq_univ.2 surjective_id @[simp, mfld_simps] theorem range_id' : (range fun x : α => x) = univ := range_id @[simp] theorem _root_.Prod.range_fst [Nonempty β] : range (Prod.fst : α × β → α) = univ := Prod.fst_surjective.range_eq @[simp] theorem _root_.Prod.range_snd [Nonempty α] : range (Prod.snd : α × β → β) = univ := Prod.snd_surjective.range_eq @[simp] theorem range_eval {α : ι → Sort _} [∀ i, Nonempty (α i)] (i : ι) : range (eval i : (∀ i, α i) → α i) = univ := (surjective_eval i).range_eq theorem range_inl : range (@Sum.inl α β) = {x | Sum.isLeft x} := by ext (_|_) <;> simp theorem range_inr : range (@Sum.inr α β) = {x | Sum.isRight x} := by ext (_|_) <;> simp theorem isCompl_range_inl_range_inr : IsCompl (range <| @Sum.inl α β) (range Sum.inr) := IsCompl.of_le (by rintro y ⟨⟨x₁, rfl⟩, ⟨x₂, h⟩⟩ exact Sum.noConfusion h) (by rintro (x | y) - <;> [left; right] <;> exact mem_range_self _) @[simp] theorem range_inl_union_range_inr : range (Sum.inl : α → α ⊕ β) ∪ range Sum.inr = univ := isCompl_range_inl_range_inr.sup_eq_top @[simp] theorem range_inl_inter_range_inr : range (Sum.inl : α → α ⊕ β) ∩ range Sum.inr = ∅ := isCompl_range_inl_range_inr.inf_eq_bot @[simp] theorem range_inr_union_range_inl : range (Sum.inr : β → α ⊕ β) ∪ range Sum.inl = univ := isCompl_range_inl_range_inr.symm.sup_eq_top @[simp] theorem range_inr_inter_range_inl : range (Sum.inr : β → α ⊕ β) ∩ range Sum.inl = ∅ := isCompl_range_inl_range_inr.symm.inf_eq_bot @[simp] theorem preimage_inl_image_inr (s : Set β) : Sum.inl ⁻¹' (@Sum.inr α β '' s) = ∅ := by ext simp @[simp] theorem preimage_inr_image_inl (s : Set α) : Sum.inr ⁻¹' (@Sum.inl α β '' s) = ∅ := by ext simp @[simp] theorem preimage_inl_range_inr : Sum.inl ⁻¹' range (Sum.inr : β → α ⊕ β) = ∅ := by rw [← image_univ, preimage_inl_image_inr] @[simp] theorem preimage_inr_range_inl : Sum.inr ⁻¹' range (Sum.inl : α → α ⊕ β) = ∅ := by rw [← image_univ, preimage_inr_image_inl] @[simp]
theorem compl_range_inl : (range (Sum.inl : α → α ⊕ β))ᶜ = range (Sum.inr : β → α ⊕ β) := IsCompl.compl_eq isCompl_range_inl_range_inr
Mathlib/Data/Set/Image.lean
811
813
/- Copyright (c) 2019 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Subalgebra.Prod import Mathlib.Algebra.Algebra.Subalgebra.Tower import Mathlib.LinearAlgebra.Basis.Basic import Mathlib.LinearAlgebra.Prod /-! # Adjoining elements to form subalgebras This file contains basic results on `Algebra.adjoin`. ## Tags adjoin, algebra -/ assert_not_exists Polynomial universe uR uS uA uB open Pointwise open Submodule Subsemiring variable {R : Type uR} {S : Type uS} {A : Type uA} {B : Type uB} namespace Algebra section Semiring variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] variable [Algebra R S] [Algebra R A] [Algebra S A] [Algebra R B] [IsScalarTower R S A] variable {s t : Set A} variable (R A) variable {A} (s) theorem adjoin_prod_le (s : Set A) (t : Set B) : adjoin R (s ×ˢ t) ≤ (adjoin R s).prod (adjoin R t) := adjoin_le <| Set.prod_mono subset_adjoin subset_adjoin theorem adjoin_inl_union_inr_eq_prod (s) (t) : adjoin R (LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1})) = (adjoin R s).prod (adjoin R t) := by apply le_antisymm · simp only [adjoin_le_iff, Set.insert_subset_iff, Subalgebra.zero_mem, Subalgebra.one_mem, subset_adjoin,-- the rest comes from `squeeze_simp` Set.union_subset_iff, LinearMap.coe_inl, Set.mk_preimage_prod_right, Set.image_subset_iff, SetLike.mem_coe, Set.mk_preimage_prod_left, LinearMap.coe_inr, and_self_iff, Set.union_singleton, Subalgebra.coe_prod] · rintro ⟨a, b⟩ ⟨ha, hb⟩ let P := adjoin R (LinearMap.inl R A B '' (s ∪ {1}) ∪ LinearMap.inr R A B '' (t ∪ {1})) have Ha : (a, (0 : B)) ∈ adjoin R (LinearMap.inl R A B '' (s ∪ {1})) := mem_adjoin_of_map_mul R LinearMap.inl_map_mul ha have Hb : ((0 : A), b) ∈ adjoin R (LinearMap.inr R A B '' (t ∪ {1})) := mem_adjoin_of_map_mul R LinearMap.inr_map_mul hb replace Ha : (a, (0 : B)) ∈ P := adjoin_mono Set.subset_union_left Ha replace Hb : ((0 : A), b) ∈ P := adjoin_mono Set.subset_union_right Hb simpa [P] using Subalgebra.add_mem _ Ha Hb variable (A) in theorem adjoin_algebraMap (s : Set S) : adjoin R (algebraMap S A '' s) = (adjoin R s).map (IsScalarTower.toAlgHom R S A) := adjoin_image R (IsScalarTower.toAlgHom R S A) s theorem adjoin_algebraMap_image_union_eq_adjoin_adjoin (s : Set S) (t : Set A) : adjoin R (algebraMap S A '' s ∪ t) = (adjoin (adjoin R s) t).restrictScalars R := le_antisymm (closure_mono <| Set.union_subset (Set.range_subset_iff.2 fun r => Or.inl ⟨algebraMap R (adjoin R s) r, (IsScalarTower.algebraMap_apply _ _ _ _).symm⟩) (Set.union_subset_union_left _ fun _ ⟨_x, hx, hxs⟩ => hxs ▸ ⟨⟨_, subset_adjoin hx⟩, rfl⟩)) (closure_le.2 <| Set.union_subset (Set.range_subset_iff.2 fun x => adjoin_mono Set.subset_union_left <| Algebra.adjoin_algebraMap R A s ▸ ⟨x, x.prop, rfl⟩) (Set.Subset.trans Set.subset_union_right subset_adjoin)) theorem adjoin_adjoin_of_tower (s : Set A) : adjoin S (adjoin R s : Set A) = adjoin S s := by apply le_antisymm (adjoin_le _) · exact adjoin_mono subset_adjoin · change adjoin R s ≤ (adjoin S s).restrictScalars R refine adjoin_le ?_ -- Porting note: unclear why this was broken have : (Subalgebra.restrictScalars R (adjoin S s) : Set A) = adjoin S s := rfl rw [this] exact subset_adjoin theorem Subalgebra.restrictScalars_adjoin {s : Set A} : (adjoin S s).restrictScalars R = (IsScalarTower.toAlgHom R S A).range ⊔ adjoin R s := by refine le_antisymm (fun _ hx ↦ adjoin_induction (fun x hx ↦ le_sup_right (α := Subalgebra R A) (subset_adjoin hx)) (fun x ↦ le_sup_left (α := Subalgebra R A) ⟨x, rfl⟩)
(fun _ _ _ _ ↦ add_mem) (fun _ _ _ _ ↦ mul_mem) <| (Subalgebra.mem_restrictScalars _).mp hx) (sup_le ?_ <| adjoin_le subset_adjoin) rintro _ ⟨x, rfl⟩; exact algebraMap_mem (adjoin S s) x @[simp] theorem adjoin_top {A} [Semiring A] [Algebra S A] (t : Set A) : adjoin (⊤ : Subalgebra R S) t = (adjoin S t).restrictScalars (⊤ : Subalgebra R S) := let equivTop : Subalgebra (⊤ : Subalgebra R S) A ≃o Subalgebra S A := { toFun := fun s => { s with algebraMap_mem' := fun r => s.algebraMap_mem ⟨r, trivial⟩ } invFun := fun s => s.restrictScalars _ left_inv := fun _ => SetLike.coe_injective rfl right_inv := fun _ => SetLike.coe_injective rfl map_rel_iff' := @fun _ _ => Iff.rfl } le_antisymm (adjoin_le <| show t ⊆ adjoin S t from subset_adjoin)
Mathlib/RingTheory/Adjoin/Basic.lean
99
113
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Johannes Hölzl, Kim Morrison, Jens Wagemaker -/ import Mathlib.Algebra.MonoidAlgebra.Degree import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Polynomial.Basic import Mathlib.Data.Nat.Cast.WithTop import Mathlib.Data.Nat.SuccPred import Mathlib.Order.SuccPred.WithBot /-! # Degree of univariate polynomials ## Main definitions * `Polynomial.degree`: the degree of a polynomial, where `0` has degree `⊥` * `Polynomial.natDegree`: the degree of a polynomial, where `0` has degree `0` * `Polynomial.leadingCoeff`: the leading coefficient of a polynomial * `Polynomial.Monic`: a polynomial is monic if its leading coefficient is 0 * `Polynomial.nextCoeff`: the next coefficient after the leading coefficient ## Main results * `Polynomial.degree_eq_natDegree`: the degree and natDegree coincide for nonzero polynomials -/ noncomputable section open Finsupp Finset open Polynomial namespace Polynomial universe u v variable {R : Type u} {S : Type v} {a b c d : R} {n m : ℕ} section Semiring variable [Semiring R] {p q r : R[X]} /-- `degree p` is the degree of the polynomial `p`, i.e. the largest `X`-exponent in `p`. `degree p = some n` when `p ≠ 0` and `n` is the highest power of `X` that appears in `p`, otherwise `degree 0 = ⊥`. -/ def degree (p : R[X]) : WithBot ℕ := p.support.max /-- `natDegree p` forces `degree p` to ℕ, by defining `natDegree 0 = 0`. -/ def natDegree (p : R[X]) : ℕ := (degree p).unbotD 0 /-- `leadingCoeff p` gives the coefficient of the highest power of `X` in `p`. -/ def leadingCoeff (p : R[X]) : R := coeff p (natDegree p) /-- a polynomial is `Monic` if its leading coefficient is 1 -/ def Monic (p : R[X]) := leadingCoeff p = (1 : R) theorem Monic.def : Monic p ↔ leadingCoeff p = 1 := Iff.rfl instance Monic.decidable [DecidableEq R] : Decidable (Monic p) := by unfold Monic; infer_instance @[simp] theorem Monic.leadingCoeff {p : R[X]} (hp : p.Monic) : leadingCoeff p = 1 := hp theorem Monic.coeff_natDegree {p : R[X]} (hp : p.Monic) : p.coeff p.natDegree = 1 := hp @[simp] theorem degree_zero : degree (0 : R[X]) = ⊥ := rfl @[simp] theorem natDegree_zero : natDegree (0 : R[X]) = 0 := rfl @[simp] theorem coeff_natDegree : coeff p (natDegree p) = leadingCoeff p := rfl @[simp] theorem degree_eq_bot : degree p = ⊥ ↔ p = 0 := ⟨fun h => support_eq_empty.1 (Finset.max_eq_bot.1 h), fun h => h.symm ▸ rfl⟩ theorem degree_ne_bot : degree p ≠ ⊥ ↔ p ≠ 0 := degree_eq_bot.not theorem degree_eq_natDegree (hp : p ≠ 0) : degree p = (natDegree p : WithBot ℕ) := by let ⟨n, hn⟩ := not_forall.1 (mt Option.eq_none_iff_forall_not_mem.2 (mt degree_eq_bot.1 hp)) have hn : degree p = some n := Classical.not_not.1 hn rw [natDegree, hn]; rfl theorem degree_eq_iff_natDegree_eq {p : R[X]} {n : ℕ} (hp : p ≠ 0) : p.degree = n ↔ p.natDegree = n := by rw [degree_eq_natDegree hp]; exact WithBot.coe_eq_coe theorem degree_eq_iff_natDegree_eq_of_pos {p : R[X]} {n : ℕ} (hn : 0 < n) : p.degree = n ↔ p.natDegree = n := by obtain rfl|h := eq_or_ne p 0 · simp [hn.ne] · exact degree_eq_iff_natDegree_eq h theorem natDegree_eq_of_degree_eq_some {p : R[X]} {n : ℕ} (h : degree p = n) : natDegree p = n := by rw [natDegree, h, Nat.cast_withBot, WithBot.unbotD_coe] theorem degree_ne_of_natDegree_ne {n : ℕ} : p.natDegree ≠ n → degree p ≠ n := mt natDegree_eq_of_degree_eq_some @[simp] theorem degree_le_natDegree : degree p ≤ natDegree p := WithBot.giUnbotDBot.gc.le_u_l _ theorem natDegree_eq_of_degree_eq [Semiring S] {q : S[X]} (h : degree p = degree q) : natDegree p = natDegree q := by unfold natDegree; rw [h] theorem le_degree_of_ne_zero (h : coeff p n ≠ 0) : (n : WithBot ℕ) ≤ degree p := by rw [Nat.cast_withBot] exact Finset.le_sup (mem_support_iff.2 h) theorem degree_mono [Semiring S] {f : R[X]} {g : S[X]} (h : f.support ⊆ g.support) : f.degree ≤ g.degree := Finset.sup_mono h theorem degree_le_degree (h : coeff q (natDegree p) ≠ 0) : degree p ≤ degree q := by by_cases hp : p = 0 · rw [hp, degree_zero] exact bot_le · rw [degree_eq_natDegree hp] exact le_degree_of_ne_zero h theorem natDegree_le_iff_degree_le {n : ℕ} : natDegree p ≤ n ↔ degree p ≤ n := WithBot.unbotD_le_iff (fun _ ↦ bot_le) theorem natDegree_lt_iff_degree_lt (hp : p ≠ 0) : p.natDegree < n ↔ p.degree < ↑n := WithBot.unbotD_lt_iff (absurd · (degree_eq_bot.not.mpr hp)) alias ⟨degree_le_of_natDegree_le, natDegree_le_of_degree_le⟩ := natDegree_le_iff_degree_le theorem natDegree_le_natDegree [Semiring S] {q : S[X]} (hpq : p.degree ≤ q.degree) : p.natDegree ≤ q.natDegree := WithBot.giUnbotDBot.gc.monotone_l hpq @[simp] theorem degree_C (ha : a ≠ 0) : degree (C a) = (0 : WithBot ℕ) := by rw [degree, ← monomial_zero_left, support_monomial 0 ha, max_eq_sup_coe, sup_singleton, WithBot.coe_zero] theorem degree_C_le : degree (C a) ≤ 0 := by by_cases h : a = 0 · rw [h, C_0] exact bot_le · rw [degree_C h] theorem degree_C_lt : degree (C a) < 1 := degree_C_le.trans_lt <| WithBot.coe_lt_coe.mpr zero_lt_one theorem degree_one_le : degree (1 : R[X]) ≤ (0 : WithBot ℕ) := by rw [← C_1]; exact degree_C_le @[simp] theorem natDegree_C (a : R) : natDegree (C a) = 0 := by by_cases ha : a = 0 · have : C a = 0 := by rw [ha, C_0] rw [natDegree, degree_eq_bot.2 this, WithBot.unbotD_bot] · rw [natDegree, degree_C ha, WithBot.unbotD_zero] @[simp] theorem natDegree_one : natDegree (1 : R[X]) = 0 := natDegree_C 1 @[simp] theorem natDegree_natCast (n : ℕ) : natDegree (n : R[X]) = 0 := by simp only [← C_eq_natCast, natDegree_C] @[simp] theorem natDegree_ofNat (n : ℕ) [Nat.AtLeastTwo n] : natDegree (ofNat(n) : R[X]) = 0 := natDegree_natCast _ theorem degree_natCast_le (n : ℕ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[simp] theorem degree_monomial (n : ℕ) (ha : a ≠ 0) : degree (monomial n a) = n := by rw [degree, support_monomial n ha, max_singleton, Nat.cast_withBot] @[simp] theorem degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) : degree (C a * X ^ n) = n := by rw [C_mul_X_pow_eq_monomial, degree_monomial n ha] theorem degree_C_mul_X (ha : a ≠ 0) : degree (C a * X) = 1 := by simpa only [pow_one] using degree_C_mul_X_pow 1 ha theorem degree_monomial_le (n : ℕ) (a : R) : degree (monomial n a) ≤ n := letI := Classical.decEq R if h : a = 0 then by rw [h, (monomial n).map_zero, degree_zero]; exact bot_le else le_of_eq (degree_monomial n h) theorem degree_C_mul_X_pow_le (n : ℕ) (a : R) : degree (C a * X ^ n) ≤ n := by rw [C_mul_X_pow_eq_monomial] apply degree_monomial_le theorem degree_C_mul_X_le (a : R) : degree (C a * X) ≤ 1 := by simpa only [pow_one] using degree_C_mul_X_pow_le 1 a @[simp] theorem natDegree_C_mul_X_pow (n : ℕ) (a : R) (ha : a ≠ 0) : natDegree (C a * X ^ n) = n := natDegree_eq_of_degree_eq_some (degree_C_mul_X_pow n ha) @[simp] theorem natDegree_C_mul_X (a : R) (ha : a ≠ 0) : natDegree (C a * X) = 1 := by simpa only [pow_one] using natDegree_C_mul_X_pow 1 a ha @[simp] theorem natDegree_monomial [DecidableEq R] (i : ℕ) (r : R) : natDegree (monomial i r) = if r = 0 then 0 else i := by split_ifs with hr · simp [hr] · rw [← C_mul_X_pow_eq_monomial, natDegree_C_mul_X_pow i r hr] theorem natDegree_monomial_le (a : R) {m : ℕ} : (monomial m a).natDegree ≤ m := by classical rw [Polynomial.natDegree_monomial] split_ifs exacts [Nat.zero_le _, le_rfl] theorem natDegree_monomial_eq (i : ℕ) {r : R} (r0 : r ≠ 0) : (monomial i r).natDegree = i := letI := Classical.decEq R Eq.trans (natDegree_monomial _ _) (if_neg r0) theorem coeff_ne_zero_of_eq_degree (hn : degree p = n) : coeff p n ≠ 0 := fun h => mem_support_iff.mp (mem_of_max hn) h theorem degree_X_pow_le (n : ℕ) : degree (X ^ n : R[X]) ≤ n := by simpa only [C_1, one_mul] using degree_C_mul_X_pow_le n (1 : R) theorem degree_X_le : degree (X : R[X]) ≤ 1 := degree_monomial_le _ _ theorem natDegree_X_le : (X : R[X]).natDegree ≤ 1 := natDegree_le_of_degree_le degree_X_le theorem withBotSucc_degree_eq_natDegree_add_one (h : p ≠ 0) : p.degree.succ = p.natDegree + 1 := by rw [degree_eq_natDegree h] exact WithBot.succ_coe p.natDegree end Semiring section NonzeroSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} @[simp] theorem degree_one : degree (1 : R[X]) = (0 : WithBot ℕ) := degree_C one_ne_zero @[simp] theorem degree_X : degree (X : R[X]) = 1 := degree_monomial _ one_ne_zero @[simp] theorem natDegree_X : (X : R[X]).natDegree = 1 := natDegree_eq_of_degree_eq_some degree_X end NonzeroSemiring section Ring variable [Ring R] @[simp] theorem degree_neg (p : R[X]) : degree (-p) = degree p := by unfold degree; rw [support_neg] theorem degree_neg_le_of_le {a : WithBot ℕ} {p : R[X]} (hp : degree p ≤ a) : degree (-p) ≤ a := p.degree_neg.le.trans hp @[simp] theorem natDegree_neg (p : R[X]) : natDegree (-p) = natDegree p := by simp [natDegree] theorem natDegree_neg_le_of_le {p : R[X]} (hp : natDegree p ≤ m) : natDegree (-p) ≤ m := (natDegree_neg p).le.trans hp @[simp] theorem natDegree_intCast (n : ℤ) : natDegree (n : R[X]) = 0 := by rw [← C_eq_intCast, natDegree_C] theorem degree_intCast_le (n : ℤ) : degree (n : R[X]) ≤ 0 := degree_le_of_natDegree_le (by simp) @[simp] theorem leadingCoeff_neg (p : R[X]) : (-p).leadingCoeff = -p.leadingCoeff := by rw [leadingCoeff, leadingCoeff, natDegree_neg, coeff_neg] end Ring section Semiring variable [Semiring R] {p : R[X]} /-- The second-highest coefficient, or 0 for constants -/ def nextCoeff (p : R[X]) : R := if p.natDegree = 0 then 0 else p.coeff (p.natDegree - 1) lemma nextCoeff_eq_zero : p.nextCoeff = 0 ↔ p.natDegree = 0 ∨ 0 < p.natDegree ∧ p.coeff (p.natDegree - 1) = 0 := by simp [nextCoeff, or_iff_not_imp_left, pos_iff_ne_zero]; aesop lemma nextCoeff_ne_zero : p.nextCoeff ≠ 0 ↔ p.natDegree ≠ 0 ∧ p.coeff (p.natDegree - 1) ≠ 0 := by simp [nextCoeff] @[simp] theorem nextCoeff_C_eq_zero (c : R) : nextCoeff (C c) = 0 := by rw [nextCoeff] simp theorem nextCoeff_of_natDegree_pos (hp : 0 < p.natDegree) : nextCoeff p = p.coeff (p.natDegree - 1) := by rw [nextCoeff, if_neg] contrapose! hp simpa variable {p q : R[X]} {ι : Type*} theorem degree_add_le (p q : R[X]) : degree (p + q) ≤ max (degree p) (degree q) := by simpa only [degree, ← support_toFinsupp, toFinsupp_add] using AddMonoidAlgebra.sup_support_add_le _ _ _ theorem degree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : degree p ≤ n) (hq : degree q ≤ n) : degree (p + q) ≤ n := (degree_add_le p q).trans <| max_le hp hq theorem degree_add_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p + q) ≤ max a b := (p.degree_add_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_add_le (p q : R[X]) : natDegree (p + q) ≤ max (natDegree p) (natDegree q) := by rcases le_max_iff.1 (degree_add_le p q) with h | h <;> simp [natDegree_le_natDegree h] theorem natDegree_add_le_of_degree_le {p q : R[X]} {n : ℕ} (hp : natDegree p ≤ n) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ n := (natDegree_add_le p q).trans <| max_le hp hq theorem natDegree_add_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p + q) ≤ max m n := (p.natDegree_add_le q).trans <| max_le_max ‹_› ‹_› @[simp] theorem leadingCoeff_zero : leadingCoeff (0 : R[X]) = 0 := rfl @[simp] theorem leadingCoeff_eq_zero : leadingCoeff p = 0 ↔ p = 0 := ⟨fun h => Classical.by_contradiction fun hp => mt mem_support_iff.1 (Classical.not_not.2 h) (mem_of_max (degree_eq_natDegree hp)), fun h => h.symm ▸ leadingCoeff_zero⟩ theorem leadingCoeff_ne_zero : leadingCoeff p ≠ 0 ↔ p ≠ 0 := by rw [Ne, leadingCoeff_eq_zero] theorem leadingCoeff_eq_zero_iff_deg_eq_bot : leadingCoeff p = 0 ↔ degree p = ⊥ := by rw [leadingCoeff_eq_zero, degree_eq_bot] theorem natDegree_C_mul_X_pow_le (a : R) (n : ℕ) : natDegree (C a * X ^ n) ≤ n := natDegree_le_iff_degree_le.2 <| degree_C_mul_X_pow_le _ _ theorem degree_erase_le (p : R[X]) (n : ℕ) : degree (p.erase n) ≤ degree p := by rcases p with ⟨p⟩ simp only [erase_def, degree, coeff, support] apply sup_mono rw [Finsupp.support_erase] apply Finset.erase_subset theorem degree_erase_lt (hp : p ≠ 0) : degree (p.erase (natDegree p)) < degree p := by apply lt_of_le_of_ne (degree_erase_le _ _) rw [degree_eq_natDegree hp, degree, support_erase] exact fun h => not_mem_erase _ _ (mem_of_max h) theorem degree_update_le (p : R[X]) (n : ℕ) (a : R) : degree (p.update n a) ≤ max (degree p) n := by classical rw [degree, support_update] split_ifs · exact (Finset.max_mono (erase_subset _ _)).trans (le_max_left _ _) · rw [max_insert, max_comm] exact le_rfl theorem degree_sum_le (s : Finset ι) (f : ι → R[X]) : degree (∑ i ∈ s, f i) ≤ s.sup fun b => degree (f b) := Finset.cons_induction_on s (by simp only [sum_empty, sup_empty, degree_zero, le_refl]) fun a s has ih => calc degree (∑ i ∈ cons a s has, f i) ≤ max (degree (f a)) (degree (∑ i ∈ s, f i)) := by rw [Finset.sum_cons]; exact degree_add_le _ _ _ ≤ _ := by rw [sup_cons]; exact max_le_max le_rfl ih theorem degree_mul_le (p q : R[X]) : degree (p * q) ≤ degree p + degree q := by simpa only [degree, ← support_toFinsupp, toFinsupp_mul] using AddMonoidAlgebra.sup_support_mul_le (WithBot.coe_add _ _).le _ _ theorem degree_mul_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p * q) ≤ a + b := (p.degree_mul_le _).trans <| add_le_add ‹_› ‹_› theorem degree_pow_le (p : R[X]) : ∀ n : ℕ, degree (p ^ n) ≤ n • degree p | 0 => by rw [pow_zero, zero_nsmul]; exact degree_one_le | n + 1 => calc degree (p ^ (n + 1)) ≤ degree (p ^ n) + degree p := by rw [pow_succ]; exact degree_mul_le _ _ _ ≤ _ := by rw [succ_nsmul]; exact add_le_add_right (degree_pow_le _ _) _ theorem degree_pow_le_of_le {a : WithBot ℕ} (b : ℕ) (hp : degree p ≤ a) : degree (p ^ b) ≤ b * a := by induction b with | zero => simp [degree_one_le] | succ n hn => rw [Nat.cast_succ, add_mul, one_mul, pow_succ] exact degree_mul_le_of_le hn hp @[simp] theorem leadingCoeff_monomial (a : R) (n : ℕ) : leadingCoeff (monomial n a) = a := by classical by_cases ha : a = 0 · simp only [ha, (monomial n).map_zero, leadingCoeff_zero] · rw [leadingCoeff, natDegree_monomial, if_neg ha, coeff_monomial] simp theorem leadingCoeff_C_mul_X_pow (a : R) (n : ℕ) : leadingCoeff (C a * X ^ n) = a := by rw [C_mul_X_pow_eq_monomial, leadingCoeff_monomial] theorem leadingCoeff_C_mul_X (a : R) : leadingCoeff (C a * X) = a := by simpa only [pow_one] using leadingCoeff_C_mul_X_pow a 1 @[simp] theorem leadingCoeff_C (a : R) : leadingCoeff (C a) = a := leadingCoeff_monomial a 0 theorem leadingCoeff_X_pow (n : ℕ) : leadingCoeff ((X : R[X]) ^ n) = 1 := by simpa only [C_1, one_mul] using leadingCoeff_C_mul_X_pow (1 : R) n theorem leadingCoeff_X : leadingCoeff (X : R[X]) = 1 := by simpa only [pow_one] using @leadingCoeff_X_pow R _ 1 @[simp] theorem monic_X_pow (n : ℕ) : Monic (X ^ n : R[X]) := leadingCoeff_X_pow n @[simp] theorem monic_X : Monic (X : R[X]) := leadingCoeff_X theorem leadingCoeff_one : leadingCoeff (1 : R[X]) = 1 := leadingCoeff_C 1 @[simp] theorem monic_one : Monic (1 : R[X]) := leadingCoeff_C _ theorem Monic.ne_zero {R : Type*} [Semiring R] [Nontrivial R] {p : R[X]} (hp : p.Monic) : p ≠ 0 := by rintro rfl simp [Monic] at hp theorem Monic.ne_zero_of_ne (h : (0 : R) ≠ 1) {p : R[X]} (hp : p.Monic) : p ≠ 0 := by nontriviality R exact hp.ne_zero theorem Monic.ne_zero_of_polynomial_ne {r} (hp : Monic p) (hne : q ≠ r) : p ≠ 0 := haveI := Nontrivial.of_polynomial_ne hne hp.ne_zero theorem natDegree_mul_le {p q : R[X]} : natDegree (p * q) ≤ natDegree p + natDegree q := by apply natDegree_le_of_degree_le apply le_trans (degree_mul_le p q) rw [Nat.cast_add] apply add_le_add <;> apply degree_le_natDegree theorem natDegree_mul_le_of_le (hp : natDegree p ≤ m) (hg : natDegree q ≤ n) : natDegree (p * q) ≤ m + n := natDegree_mul_le.trans <| add_le_add ‹_› ‹_› theorem natDegree_pow_le {p : R[X]} {n : ℕ} : (p ^ n).natDegree ≤ n * p.natDegree := by induction n with | zero => simp | succ i hi => rw [pow_succ, Nat.succ_mul] apply le_trans natDegree_mul_le (add_le_add_right hi _) theorem natDegree_pow_le_of_le (n : ℕ) (hp : natDegree p ≤ m) : natDegree (p ^ n) ≤ n * m := natDegree_pow_le.trans (Nat.mul_le_mul le_rfl ‹_›) theorem natDegree_eq_zero_iff_degree_le_zero : p.natDegree = 0 ↔ p.degree ≤ 0 := by rw [← nonpos_iff_eq_zero, natDegree_le_iff_degree_le, Nat.cast_zero] theorem degree_zero_le : degree (0 : R[X]) ≤ 0 := natDegree_eq_zero_iff_degree_le_zero.mp rfl theorem degree_le_iff_coeff_zero (f : R[X]) (n : WithBot ℕ) : degree f ≤ n ↔ ∀ m : ℕ, n < m → coeff f m = 0 := by simp only [degree, Finset.max, Finset.sup_le_iff, mem_support_iff, Ne, ← not_le, not_imp_comm, Nat.cast_withBot] theorem degree_lt_iff_coeff_zero (f : R[X]) (n : ℕ) : degree f < n ↔ ∀ m : ℕ, n ≤ m → coeff f m = 0 := by simp only [degree, Finset.sup_lt_iff (WithBot.bot_lt_coe n), mem_support_iff, WithBot.coe_lt_coe, ← @not_le ℕ, max_eq_sup_coe, Nat.cast_withBot, Ne, not_imp_not] theorem natDegree_pos_iff_degree_pos : 0 < natDegree p ↔ 0 < degree p := lt_iff_lt_of_le_iff_le natDegree_le_iff_degree_le end Semiring section NontrivialSemiring variable [Semiring R] [Nontrivial R] {p q : R[X]} (n : ℕ) @[simp] theorem degree_X_pow : degree ((X : R[X]) ^ n) = n := by rw [X_pow_eq_monomial, degree_monomial _ (one_ne_zero' R)] @[simp] theorem natDegree_X_pow : natDegree ((X : R[X]) ^ n) = n := natDegree_eq_of_degree_eq_some (degree_X_pow n) end NontrivialSemiring section Ring variable [Ring R] {p q : R[X]} theorem degree_sub_le (p q : R[X]) : degree (p - q) ≤ max (degree p) (degree q) := by simpa only [degree_neg q] using degree_add_le p (-q) theorem degree_sub_le_of_le {a b : WithBot ℕ} (hp : degree p ≤ a) (hq : degree q ≤ b) : degree (p - q) ≤ max a b := (p.degree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem natDegree_sub_le (p q : R[X]) : natDegree (p - q) ≤ max (natDegree p) (natDegree q) := by simpa only [← natDegree_neg q] using natDegree_add_le p (-q) theorem natDegree_sub_le_of_le (hp : natDegree p ≤ m) (hq : natDegree q ≤ n) : natDegree (p - q) ≤ max m n := (p.natDegree_sub_le q).trans <| max_le_max ‹_› ‹_› theorem degree_sub_lt (hd : degree p = degree q) (hp0 : p ≠ 0) (hlc : leadingCoeff p = leadingCoeff q) : degree (p - q) < degree p := have hp : monomial (natDegree p) (leadingCoeff p) + p.erase (natDegree p) = p := monomial_add_erase _ _ have hq : monomial (natDegree q) (leadingCoeff q) + q.erase (natDegree q) = q := monomial_add_erase _ _ have hd' : natDegree p = natDegree q := by unfold natDegree; rw [hd] have hq0 : q ≠ 0 := mt degree_eq_bot.2 (hd ▸ mt degree_eq_bot.1 hp0) calc degree (p - q) = degree (erase (natDegree q) p + -erase (natDegree q) q) := by conv => lhs rw [← hp, ← hq, hlc, hd', add_sub_add_left_eq_sub, sub_eq_add_neg] _ ≤ max (degree (erase (natDegree q) p)) (degree (erase (natDegree q) q)) := (degree_neg (erase (natDegree q) q) ▸ degree_add_le _ _) _ < degree p := max_lt_iff.2 ⟨hd' ▸ degree_erase_lt hp0, hd.symm ▸ degree_erase_lt hq0⟩ theorem degree_X_sub_C_le (r : R) : (X - C r).degree ≤ 1 := (degree_sub_le _ _).trans (max_le degree_X_le (degree_C_le.trans zero_le_one)) theorem natDegree_X_sub_C_le (r : R) : (X - C r).natDegree ≤ 1 := natDegree_le_iff_degree_le.2 <| degree_X_sub_C_le r end Ring end Polynomial
Mathlib/Algebra/Polynomial/Degree/Definitions.lean
669
670
/- 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.Finset.Card import Mathlib.Data.Finset.Lattice.Union import Mathlib.Data.Multiset.Powerset import Mathlib.Data.Set.Pairwise.Lattice /-! # The powerset of a finset -/ namespace Finset open Function Multiset variable {α : Type*} {s t : Finset α} /-! ### powerset -/ section Powerset /-- When `s` is a finset, `s.powerset` is the finset of all subsets of `s` (seen as finsets). -/ def powerset (s : Finset α) : Finset (Finset α) := ⟨(s.1.powerset.pmap Finset.mk) fun _t h => nodup_of_le (mem_powerset.1 h) s.nodup, s.nodup.powerset.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩ @[simp] theorem mem_powerset {s t : Finset α} : s ∈ powerset t ↔ s ⊆ t := by cases s simp [powerset, mem_mk, mem_pmap, mk.injEq, mem_powerset, exists_prop, exists_eq_right, ← val_le_iff] @[simp, norm_cast] theorem coe_powerset (s : Finset α) : (s.powerset : Set (Finset α)) = ((↑) : Finset α → Set α) ⁻¹' (s : Set α).powerset := by ext simp theorem empty_mem_powerset (s : Finset α) : ∅ ∈ powerset s := by simp theorem mem_powerset_self (s : Finset α) : s ∈ powerset s := by simp @[aesop safe apply (rule_sets := [finsetNonempty])] theorem powerset_nonempty (s : Finset α) : s.powerset.Nonempty := ⟨∅, empty_mem_powerset _⟩ @[simp] theorem powerset_mono {s t : Finset α} : powerset s ⊆ powerset t ↔ s ⊆ t := ⟨fun h => mem_powerset.1 <| h <| mem_powerset_self _, fun st _u h => mem_powerset.2 <| Subset.trans (mem_powerset.1 h) st⟩ theorem powerset_injective : Injective (powerset : Finset α → Finset (Finset α)) := (injective_of_le_imp_le _) powerset_mono.1 @[simp] theorem powerset_inj : powerset s = powerset t ↔ s = t := powerset_injective.eq_iff @[simp] theorem powerset_empty : (∅ : Finset α).powerset = {∅} := rfl @[simp] theorem powerset_eq_singleton_empty : s.powerset = {∅} ↔ s = ∅ := by rw [← powerset_empty, powerset_inj] /-- **Number of Subsets of a Set** -/ @[simp] theorem card_powerset (s : Finset α) : card (powerset s) = 2 ^ card s := (card_pmap _ _ _).trans (Multiset.card_powerset s.1) theorem not_mem_of_mem_powerset_of_not_mem {s t : Finset α} {a : α} (ht : t ∈ s.powerset) (h : a ∉ s) : a ∉ t := by apply mt _ h apply mem_powerset.1 ht theorem powerset_insert [DecidableEq α] (s : Finset α) (a : α) : powerset (insert a s) = s.powerset ∪ s.powerset.image (insert a) := by ext t simp only [exists_prop, mem_powerset, mem_image, mem_union, subset_insert_iff] by_cases h : a ∈ t · constructor · exact fun H => Or.inr ⟨_, H, insert_erase h⟩ · intro H rcases H with H | H · exact Subset.trans (erase_subset a t) H · rcases H with ⟨u, hu⟩ rw [← hu.2] exact Subset.trans (erase_insert_subset a u) hu.1 · have : ¬∃ u : Finset α, u ⊆ s ∧ insert a u = t := by simp [Ne.symm (ne_insert_of_not_mem _ _ h)] simp [Finset.erase_eq_of_not_mem h, this] lemma pairwiseDisjoint_pair_insert [DecidableEq α] {a : α} (ha : a ∉ s) : (s.powerset : Set (Finset α)).PairwiseDisjoint fun t ↦ ({t, insert a t} : Set (Finset α)) := by simp_rw [Set.pairwiseDisjoint_iff, mem_coe, mem_powerset] rintro i hi j hj simp only [Set.Nonempty, Set.mem_inter_iff, Set.mem_insert_iff, Set.mem_singleton_iff, exists_eq_or_imp, exists_eq_left, or_imp, imp_self, true_and] refine ⟨?_, ?_, insert_erase_invOn.2.injOn (not_mem_mono hi ha) (not_mem_mono hj ha)⟩ <;> rintro rfl <;> cases Finset.not_mem_mono ‹_› ha (Finset.mem_insert_self _ _) /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/ instance decidableExistsOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop} [∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∃ (t : _) (h : t ⊆ s), p t h) := decidable_of_iff (∃ (t : _) (hs : t ∈ s.powerset), p t (mem_powerset.1 hs)) ⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_powerset.2 hs, hp⟩⟩ /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/ instance decidableForallOfDecidableSubsets {s : Finset α} {p : ∀ t ⊆ s, Prop} [∀ (t) (h : t ⊆ s), Decidable (p t h)] : Decidable (∀ (t) (h : t ⊆ s), p t h) := decidable_of_iff (∀ (t) (h : t ∈ s.powerset), p t (mem_powerset.1 h)) ⟨fun h t hs => h t (mem_powerset.2 hs), fun h _ _ => h _ _⟩ /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for any subset. -/ instance decidableExistsOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop} [∀ t, Decidable (p t)] : Decidable (∃ t ⊆ s, p t) := decidable_of_iff (∃ (t : _) (_h : t ⊆ s), p t) <| by simp /-- For predicate `p` decidable on subsets, it is decidable whether `p` holds for every subset. -/ instance decidableForallOfDecidableSubsets' {s : Finset α} {p : Finset α → Prop} [∀ t, Decidable (p t)] : Decidable (∀ t ⊆ s, p t) := decidable_of_iff (∀ (t : _) (_h : t ⊆ s), p t) <| by simp end Powerset section SSubsets variable [DecidableEq α] /-- For `s` a finset, `s.ssubsets` is the finset comprising strict subsets of `s`. -/ def ssubsets (s : Finset α) : Finset (Finset α) := erase (powerset s) s @[simp] theorem mem_ssubsets {s t : Finset α} : t ∈ s.ssubsets ↔ t ⊂ s := by rw [ssubsets, mem_erase, mem_powerset, ssubset_iff_subset_ne, and_comm] theorem empty_mem_ssubsets {s : Finset α} (h : s.Nonempty) : ∅ ∈ s.ssubsets := by rw [mem_ssubsets, ssubset_iff_subset_ne] exact ⟨empty_subset s, h.ne_empty.symm⟩ /-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for any ssubset. -/ def decidableExistsOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop} [∀ t h, Decidable (p t h)] : Decidable (∃ t h, p t h) := decidable_of_iff (∃ (t : _) (hs : t ∈ s.ssubsets), p t (mem_ssubsets.1 hs)) ⟨fun ⟨t, _, hp⟩ => ⟨t, _, hp⟩, fun ⟨t, hs, hp⟩ => ⟨t, mem_ssubsets.2 hs, hp⟩⟩ /-- For predicate `p` decidable on ssubsets, it is decidable whether `p` holds for every ssubset. -/ def decidableForallOfDecidableSSubsets {s : Finset α} {p : ∀ t ⊂ s, Prop} [∀ t h, Decidable (p t h)] : Decidable (∀ t h, p t h) := decidable_of_iff (∀ (t) (h : t ∈ s.ssubsets), p t (mem_ssubsets.1 h)) ⟨fun h t hs => h t (mem_ssubsets.2 hs), fun h _ _ => h _ _⟩ /-- A version of `Finset.decidableExistsOfDecidableSSubsets` with a non-dependent `p`. Typeclass inference cannot find `hu` here, so this is not an instance. -/ def decidableExistsOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop} (hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∃ (t : _) (_h : t ⊂ s), p t) := @Finset.decidableExistsOfDecidableSSubsets _ _ _ _ hu /-- A version of `Finset.decidableForallOfDecidableSSubsets` with a non-dependent `p`. Typeclass inference cannot find `hu` here, so this is not an instance. -/ def decidableForallOfDecidableSSubsets' {s : Finset α} {p : Finset α → Prop} (hu : ∀ t ⊂ s, Decidable (p t)) : Decidable (∀ t ⊂ s, p t) := @Finset.decidableForallOfDecidableSSubsets _ _ _ _ hu end SSubsets section powersetCard variable {n} {s t : Finset α} /-- Given an integer `n` and a finset `s`, then `powersetCard n s` is the finset of subsets of `s` of cardinality `n`. -/ def powersetCard (n : ℕ) (s : Finset α) : Finset (Finset α) := ⟨((s.1.powersetCard n).pmap Finset.mk) fun _t h => nodup_of_le (mem_powersetCard.1 h).1 s.2, s.2.powersetCard.pmap fun _a _ha _b _hb => congr_arg Finset.val⟩ @[simp] lemma mem_powersetCard : s ∈ powersetCard n t ↔ s ⊆ t ∧ card s = n := by cases s; simp [powersetCard, val_le_iff.symm] @[simp] theorem powersetCard_mono {n} {s t : Finset α} (h : s ⊆ t) : powersetCard n s ⊆ powersetCard n t := fun _u h' => mem_powersetCard.2 <| And.imp (fun h₂ => Subset.trans h₂ h) id (mem_powersetCard.1 h') /-- **Formula for the Number of Combinations** -/ @[simp] theorem card_powersetCard (n : ℕ) (s : Finset α) : card (powersetCard n s) = Nat.choose (card s) n := (card_pmap _ _ _).trans (Multiset.card_powersetCard n s.1) @[simp] theorem powersetCard_zero (s : Finset α) : s.powersetCard 0 = {∅} := by ext; rw [mem_powersetCard, mem_singleton, card_eq_zero] refine ⟨fun h => h.2, fun h => by rw [h] exact ⟨empty_subset s, rfl⟩⟩ lemma powersetCard_empty_subsingleton (n : ℕ) : (powersetCard n (∅ : Finset α) : Set <| Finset α).Subsingleton := by simp [Set.Subsingleton, subset_empty] @[simp] theorem map_val_val_powersetCard (s : Finset α) (i : ℕ) : (s.powersetCard i).val.map Finset.val = s.1.powersetCard i := by simp [Finset.powersetCard, map_pmap, pmap_eq_map, map_id'] theorem powersetCard_one (s : Finset α) : s.powersetCard 1 = s.map ⟨_, Finset.singleton_injective⟩ := eq_of_veq <| Multiset.map_injective val_injective <| by simp [Multiset.powersetCard_one] @[simp] lemma powersetCard_eq_empty : powersetCard n s = ∅ ↔ s.card < n := by refine ⟨?_, fun h ↦ card_eq_zero.1 <| by rw [card_powersetCard, Nat.choose_eq_zero_of_lt h]⟩ contrapose! exact fun h ↦ nonempty_iff_ne_empty.1 <| (exists_subset_card_eq h).imp <| by simp @[simp] lemma powersetCard_card_add (s : Finset α) (hn : 0 < n) : s.powersetCard (s.card + n) = ∅ := by simpa theorem powersetCard_eq_filter {n} {s : Finset α} : powersetCard n s = (powerset s).filter fun x => x.card = n := by ext simp [mem_powersetCard] theorem powersetCard_succ_insert [DecidableEq α] {x : α} {s : Finset α} (h : x ∉ s) (n : ℕ) : powersetCard n.succ (insert x s) = powersetCard n.succ s ∪ (powersetCard n s).image (insert x) := by rw [powersetCard_eq_filter, powerset_insert, filter_union, ← powersetCard_eq_filter] congr rw [powersetCard_eq_filter, filter_image] congr 1 ext t simp only [mem_powerset, mem_filter, Function.comp_apply, and_congr_right_iff] intro ht have : x ∉ t := fun H => h (ht H) simp [card_insert_of_not_mem this, Nat.succ_inj] @[simp] lemma powersetCard_nonempty : (powersetCard n s).Nonempty ↔ n ≤ s.card := by aesop (add simp [Finset.Nonempty, exists_subset_card_eq, card_le_card]) @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, powersetCard_nonempty_of_le⟩ := powersetCard_nonempty @[simp] theorem powersetCard_self (s : Finset α) : powersetCard s.card s = {s} := by ext rw [mem_powersetCard, mem_singleton] constructor · exact fun ⟨hs, hc⟩ => eq_of_subset_of_card_le hs hc.ge · rintro rfl simp theorem pairwise_disjoint_powersetCard (s : Finset α) : Pairwise fun i j => Disjoint (s.powersetCard i) (s.powersetCard j) := fun _i _j hij => Finset.disjoint_left.mpr fun _x hi hj => hij <| (mem_powersetCard.mp hi).2.symm.trans (mem_powersetCard.mp hj).2 theorem powerset_card_disjiUnion (s : Finset α) : Finset.powerset s = (range (s.card + 1)).disjiUnion (fun i => powersetCard i s) (s.pairwise_disjoint_powersetCard.set_pairwise _) := by refine ext fun a => ⟨fun ha => ?_, fun ha => ?_⟩ · rw [mem_disjiUnion] exact ⟨a.card, mem_range.mpr (Nat.lt_succ_of_le (card_le_card (mem_powerset.mp ha))),
mem_powersetCard.mpr ⟨mem_powerset.mp ha, rfl⟩⟩ · rcases mem_disjiUnion.mp ha with ⟨i, _hi, ha⟩ exact mem_powerset.mpr (mem_powersetCard.mp ha).1
Mathlib/Data/Finset/Powerset.lean
274
276
/- Copyright (c) 2016 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro, Johannes Hölzl, Damiano Testa, Yuyang Zhao -/ import Mathlib.Algebra.Order.Monoid.Unbundled.Defs import Mathlib.Data.Ordering.Basic import Mathlib.Order.MinMax import Mathlib.Tactic.Contrapose import Mathlib.Tactic.Use /-! # Ordered monoids This file develops the basics of ordered monoids. ## Implementation details Unfortunately, the number of `'` appended to lemmas in this file may differ between the multiplicative and the additive version of a lemma. The reason is that we did not want to change existing names in the library. ## Remark Almost no monoid is actually present in this file: most assumptions have been generalized to `Mul` or `MulOneClass`. -/ -- TODO: If possible, uniformize lemma names, taking special care of `'`, -- after the `ordered`-refactor is done. open Function section Nat instance Nat.instMulLeftMono : MulLeftMono ℕ where elim := fun _ _ _ h => mul_le_mul_left _ h end Nat section Int instance Int.instAddLeftMono : AddLeftMono ℤ where elim := fun _ _ _ h => Int.add_le_add_left h _ end Int variable {α β : Type*} section Mul variable [Mul α] section LE variable [LE α] /- The prime on this lemma is present only on the multiplicative version. The unprimed version is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/ @[to_additive (attr := gcongr) add_le_add_left] theorem mul_le_mul_left' [MulLeftMono α] {b c : α} (bc : b ≤ c) (a : α) : a * b ≤ a * c := CovariantClass.elim _ bc @[to_additive le_of_add_le_add_left] theorem le_of_mul_le_mul_left' [MulLeftReflectLE α] {a b c : α} (bc : a * b ≤ a * c) : b ≤ c := ContravariantClass.elim _ bc /- The prime on this lemma is present only on the multiplicative version. The unprimed version is taken by the analogous lemma for semiring, with an extra non-negativity assumption. -/ @[to_additive (attr := gcongr) add_le_add_right] theorem mul_le_mul_right' [i : MulRightMono α] {b c : α} (bc : b ≤ c) (a : α) : b * a ≤ c * a := i.elim a bc @[to_additive le_of_add_le_add_right] theorem le_of_mul_le_mul_right' [i : MulRightReflectLE α] {a b c : α} (bc : b * a ≤ c * a) : b ≤ c := i.elim a bc @[to_additive (attr := simp)] theorem mul_le_mul_iff_left [MulLeftMono α] [MulLeftReflectLE α] (a : α) {b c : α} : a * b ≤ a * c ↔ b ≤ c := rel_iff_cov α α (· * ·) (· ≤ ·) a @[to_additive (attr := simp)] theorem mul_le_mul_iff_right [MulRightMono α] [MulRightReflectLE α] (a : α) {b c : α} : b * a ≤ c * a ↔ b ≤ c := rel_iff_cov α α (swap (· * ·)) (· ≤ ·) a end LE section LT variable [LT α] @[to_additive (attr := simp)] theorem mul_lt_mul_iff_left [MulLeftStrictMono α] [MulLeftReflectLT α] (a : α) {b c : α} : a * b < a * c ↔ b < c := rel_iff_cov α α (· * ·) (· < ·) a @[to_additive (attr := simp)] theorem mul_lt_mul_iff_right [MulRightStrictMono α] [MulRightReflectLT α] (a : α) {b c : α} : b * a < c * a ↔ b < c := rel_iff_cov α α (swap (· * ·)) (· < ·) a @[to_additive (attr := gcongr) add_lt_add_left] theorem mul_lt_mul_left' [MulLeftStrictMono α] {b c : α} (bc : b < c) (a : α) : a * b < a * c := CovariantClass.elim _ bc @[to_additive lt_of_add_lt_add_left] theorem lt_of_mul_lt_mul_left' [MulLeftReflectLT α] {a b c : α} (bc : a * b < a * c) : b < c := ContravariantClass.elim _ bc @[to_additive (attr := gcongr) add_lt_add_right] theorem mul_lt_mul_right' [i : MulRightStrictMono α] {b c : α} (bc : b < c) (a : α) : b * a < c * a := i.elim a bc @[to_additive lt_of_add_lt_add_right] theorem lt_of_mul_lt_mul_right' [i : MulRightReflectLT α] {a b c : α} (bc : b * a < c * a) : b < c := i.elim a bc end LT section Preorder variable [Preorder α] @[to_additive] lemma mul_left_mono [MulLeftMono α] {a : α} : Monotone (a * ·) := fun _ _ h ↦ mul_le_mul_left' h _ @[to_additive] lemma mul_right_mono [MulRightMono α] {a : α} : Monotone (· * a) := fun _ _ h ↦ mul_le_mul_right' h _ @[to_additive] lemma mul_left_strictMono [MulLeftStrictMono α] {a : α} : StrictMono (a * ·) := fun _ _ h ↦ mul_lt_mul_left' h _ @[to_additive] lemma mul_right_strictMono [MulRightStrictMono α] {a : α} : StrictMono (· * a) := fun _ _ h ↦ mul_lt_mul_right' h _ @[to_additive (attr := gcongr)] theorem mul_lt_mul_of_lt_of_lt [MulLeftStrictMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := calc a * c < a * d := mul_lt_mul_left' h₂ a _ < b * d := mul_lt_mul_right' h₁ d alias add_lt_add := add_lt_add_of_lt_of_lt @[to_additive] theorem mul_lt_mul_of_le_of_lt [MulLeftStrictMono α] [MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c < d) : a * c < b * d := (mul_le_mul_right' h₁ _).trans_lt (mul_lt_mul_left' h₂ b) @[to_additive] theorem mul_lt_mul_of_lt_of_le [MulLeftMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c ≤ d) : a * c < b * d := (mul_le_mul_left' h₂ _).trans_lt (mul_lt_mul_right' h₁ d) /-- Only assumes left strict covariance. -/ @[to_additive "Only assumes left strict covariance"] theorem Left.mul_lt_mul [MulLeftStrictMono α] [MulRightMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := mul_lt_mul_of_le_of_lt h₁.le h₂ /-- Only assumes right strict covariance. -/ @[to_additive "Only assumes right strict covariance"] theorem Right.mul_lt_mul [MulLeftMono α] [MulRightStrictMono α] {a b c d : α} (h₁ : a < b) (h₂ : c < d) : a * c < b * d := mul_lt_mul_of_lt_of_le h₁ h₂.le @[to_additive (attr := gcongr) add_le_add] theorem mul_le_mul' [MulLeftMono α] [MulRightMono α] {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) : a * c ≤ b * d := (mul_le_mul_left' h₂ _).trans (mul_le_mul_right' h₁ d) @[to_additive] theorem mul_le_mul_three [MulLeftMono α] [MulRightMono α] {a b c d e f : α} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) : a * b * c ≤ d * e * f := mul_le_mul' (mul_le_mul' h₁ h₂) h₃ @[to_additive] theorem mul_lt_of_mul_lt_left [MulLeftMono α] {a b c d : α} (h : a * b < c) (hle : d ≤ b) : a * d < c := (mul_le_mul_left' hle a).trans_lt h @[to_additive] theorem mul_le_of_mul_le_left [MulLeftMono α] {a b c d : α} (h : a * b ≤ c) (hle : d ≤ b) : a * d ≤ c := @act_rel_of_rel_of_act_rel _ _ _ (· ≤ ·) _ _ a _ _ _ hle h @[to_additive] theorem mul_lt_of_mul_lt_right [MulRightMono α] {a b c d : α} (h : a * b < c) (hle : d ≤ a) : d * b < c := (mul_le_mul_right' hle b).trans_lt h @[to_additive] theorem mul_le_of_mul_le_right [MulRightMono α] {a b c d : α} (h : a * b ≤ c) (hle : d ≤ a) : d * b ≤ c := (mul_le_mul_right' hle b).trans h @[to_additive] theorem lt_mul_of_lt_mul_left [MulLeftMono α] {a b c d : α} (h : a < b * c) (hle : c ≤ d) : a < b * d := h.trans_le (mul_le_mul_left' hle b) @[to_additive] theorem le_mul_of_le_mul_left [MulLeftMono α] {a b c d : α} (h : a ≤ b * c) (hle : c ≤ d) : a ≤ b * d := @rel_act_of_rel_of_rel_act _ _ _ (· ≤ ·) _ _ b _ _ _ hle h @[to_additive] theorem lt_mul_of_lt_mul_right [MulRightMono α] {a b c d : α} (h : a < b * c) (hle : b ≤ d) : a < d * c := h.trans_le (mul_le_mul_right' hle c) @[to_additive] theorem le_mul_of_le_mul_right [MulRightMono α] {a b c d : α} (h : a ≤ b * c) (hle : b ≤ d) : a ≤ d * c := h.trans (mul_le_mul_right' hle c) end Preorder section PartialOrder variable [PartialOrder α] @[to_additive] theorem mul_left_cancel'' [MulLeftReflectLE α] {a b c : α} (h : a * b = a * c) : b = c := (le_of_mul_le_mul_left' h.le).antisymm (le_of_mul_le_mul_left' h.ge) @[to_additive] theorem mul_right_cancel'' [MulRightReflectLE α] {a b c : α} (h : a * b = c * b) : a = c := (le_of_mul_le_mul_right' h.le).antisymm (le_of_mul_le_mul_right' h.ge) @[to_additive] lemma mul_le_mul_iff_of_ge [MulLeftStrictMono α] [MulRightStrictMono α] {a₁ a₂ b₁ b₂ : α} (ha : a₁ ≤ a₂) (hb : b₁ ≤ b₂) : a₂ * b₂ ≤ a₁ * b₁ ↔ a₁ = a₂ ∧ b₁ = b₂ := by haveI := mulLeftMono_of_mulLeftStrictMono α haveI := mulRightMono_of_mulRightStrictMono α refine ⟨fun h ↦ ?_, by rintro ⟨rfl, rfl⟩; rfl⟩ simp only [eq_iff_le_not_lt, ha, hb, true_and] refine ⟨fun ha ↦ h.not_lt ?_, fun hb ↦ h.not_lt ?_⟩ exacts [mul_lt_mul_of_lt_of_le ha hb, mul_lt_mul_of_le_of_lt ha hb] @[to_additive] theorem mul_eq_mul_iff_eq_and_eq [MulLeftStrictMono α] [MulRightStrictMono α] {a b c d : α} (hac : a ≤ c) (hbd : b ≤ d) : a * b = c * d ↔ a = c ∧ b = d := by haveI := mulLeftMono_of_mulLeftStrictMono α haveI := mulRightMono_of_mulRightStrictMono α rw [le_antisymm_iff, eq_true (mul_le_mul' hac hbd), true_and, mul_le_mul_iff_of_ge hac hbd] @[to_additive] lemma mul_left_inj_of_comparable [MulRightStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) : c * a = b * a ↔ c = b := by refine ⟨fun h' => ?_, (· ▸ rfl)⟩ contrapose h' obtain h | h := h · exact mul_lt_mul_right' (h.lt_of_ne' h') a |>.ne' · exact mul_lt_mul_right' (h.lt_of_ne h') a |>.ne @[to_additive] lemma mul_right_inj_of_comparable [MulLeftStrictMono α] {a b c : α} (h : b ≤ c ∨ c ≤ b) : a * c = a * b ↔ c = b := by refine ⟨fun h' => ?_, (· ▸ rfl)⟩ contrapose h' obtain h | h := h · exact mul_lt_mul_left' (h.lt_of_ne' h') a |>.ne' · exact mul_lt_mul_left' (h.lt_of_ne h') a |>.ne end PartialOrder section LinearOrder variable [LinearOrder α] {a b c d : α} @[to_additive] theorem trichotomy_of_mul_eq_mul [MulLeftStrictMono α] [MulRightStrictMono α] (h : a * b = c * d) : (a = c ∧ b = d) ∨ a < c ∨ b < d := by obtain hac | rfl | hca := lt_trichotomy a c · right; left; exact hac · left; simpa using mul_right_inj_of_comparable (LinearOrder.le_total d b)|>.1 h · obtain hbd | rfl | hdb := lt_trichotomy b d · right; right; exact hbd · exact False.elim <| ne_of_lt (mul_lt_mul_right' hca b) h.symm · exact False.elim <| ne_of_lt (mul_lt_mul_of_lt_of_lt hca hdb) h.symm @[to_additive] lemma mul_max [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : a * max b c = max (a * b) (a * c) := mul_left_mono.map_max @[to_additive] lemma max_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) : max a b * c = max (a * c) (b * c) := mul_right_mono.map_max @[to_additive] lemma mul_min [CovariantClass α α (· * ·) (· ≤ ·)] (a b c : α) : a * min b c = min (a * b) (a * c) := mul_left_mono.map_min @[to_additive] lemma min_mul [CovariantClass α α (swap (· * ·)) (· ≤ ·)] (a b c : α) : min a b * c = min (a * c) (b * c) := mul_right_mono.map_min @[to_additive] lemma min_lt_max_of_mul_lt_mul [MulLeftMono α] [MulRightMono α] (h : a * b < c * d) : min a b < max c d := by simp_rw [min_lt_iff, lt_max_iff]; contrapose! h; exact mul_le_mul' h.1.1 h.2.2 @[to_additive] lemma Left.min_le_max_of_mul_le_mul [MulLeftStrictMono α] [MulRightMono α] (h : a * b ≤ c * d) : min a b ≤ max c d := by simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_le_of_lt h.1.1.le h.2.2 @[to_additive] lemma Right.min_le_max_of_mul_le_mul [MulLeftMono α] [MulRightStrictMono α] (h : a * b ≤ c * d) : min a b ≤ max c d := by simp_rw [min_le_iff, le_max_iff]; contrapose! h; exact mul_lt_mul_of_lt_of_le h.1.1 h.2.2.le @[to_additive] lemma min_le_max_of_mul_le_mul [MulLeftStrictMono α] [MulRightStrictMono α] (h : a * b ≤ c * d) : min a b ≤ max c d := haveI := mulRightMono_of_mulRightStrictMono α Left.min_le_max_of_mul_le_mul h /-- Not an instance, to avoid loops with `IsLeftCancelMul.mulLeftStrictMono_of_mulLeftMono`. -/ @[to_additive] theorem MulLeftStrictMono.toIsLeftCancelMul [MulLeftStrictMono α] : IsLeftCancelMul α where mul_left_cancel _ _ _ h := mul_left_strictMono.injective h /-- Not an instance, to avoid loops with `IsRightCancelMul.mulRightStrictMono_of_mulRightMono`. -/ @[to_additive] theorem MulRightStrictMono.toIsRightCancelMul [MulRightStrictMono α] : IsRightCancelMul α where mul_right_cancel _ _ _ h := mul_right_strictMono.injective h end LinearOrder section LinearOrder variable [LinearOrder α] [MulLeftMono α] [MulRightMono α] {a b c d : α} @[to_additive max_add_add_le_max_add_max] theorem max_mul_mul_le_max_mul_max' : max (a * b) (c * d) ≤ max a c * max b d := max_le (mul_le_mul' (le_max_left _ _) <| le_max_left _ _) <| mul_le_mul' (le_max_right _ _) <| le_max_right _ _ @[to_additive min_add_min_le_min_add_add] theorem min_mul_min_le_min_mul_mul' : min a c * min b d ≤ min (a * b) (c * d) := le_min (mul_le_mul' (min_le_left _ _) <| min_le_left _ _) <| mul_le_mul' (min_le_right _ _) <| min_le_right _ _ end LinearOrder end Mul -- using one section MulOneClass variable [MulOneClass α] section LE variable [LE α] @[to_additive le_add_of_nonneg_right] theorem le_mul_of_one_le_right' [MulLeftMono α] {a b : α} (h : 1 ≤ b) : a ≤ a * b := calc a = a * 1 := (mul_one a).symm _ ≤ a * b := mul_le_mul_left' h a @[to_additive add_le_of_nonpos_right] theorem mul_le_of_le_one_right' [MulLeftMono α] {a b : α} (h : b ≤ 1) : a * b ≤ a := calc a * b ≤ a * 1 := mul_le_mul_left' h a _ = a := mul_one a @[to_additive le_add_of_nonneg_left] theorem le_mul_of_one_le_left' [MulRightMono α] {a b : α} (h : 1 ≤ b) : a ≤ b * a := calc a = 1 * a := (one_mul a).symm _ ≤ b * a := mul_le_mul_right' h a @[to_additive add_le_of_nonpos_left] theorem mul_le_of_le_one_left' [MulRightMono α] {a b : α} (h : b ≤ 1) : b * a ≤ a := calc b * a ≤ 1 * a := mul_le_mul_right' h a _ = a := one_mul a @[to_additive] theorem one_le_of_le_mul_right [MulLeftReflectLE α] {a b : α} (h : a ≤ a * b) : 1 ≤ b := le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one] @[to_additive] theorem le_one_of_mul_le_right [MulLeftReflectLE α] {a b : α} (h : a * b ≤ a) : b ≤ 1 := le_of_mul_le_mul_left' (a := a) <| by simpa only [mul_one] @[to_additive] theorem one_le_of_le_mul_left [MulRightReflectLE α] {a b : α} (h : b ≤ a * b) : 1 ≤ a := le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul] @[to_additive] theorem le_one_of_mul_le_left [MulRightReflectLE α] {a b : α} (h : a * b ≤ b) :
a ≤ 1 := le_of_mul_le_mul_right' (a := b) <| by simpa only [one_mul] @[to_additive (attr := simp) le_add_iff_nonneg_right]
Mathlib/Algebra/Order/Monoid/Unbundled/Basic.lean
450
453
/- Copyright (c) 2018 Patrick Massot. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Patrick Massot, Johannes Hölzl, Yaël Dillies -/ import Mathlib.Analysis.Normed.Group.Seminorm import Mathlib.Data.NNReal.Basic import Mathlib.Topology.Algebra.Support import Mathlib.Topology.MetricSpace.Basic import Mathlib.Topology.Order.Real /-! # Normed (semi)groups In this file we define 10 classes: * `Norm`, `NNNorm`: auxiliary classes endowing a type `α` with a function `norm : α → ℝ` (notation: `‖x‖`) and `nnnorm : α → ℝ≥0` (notation: `‖x‖₊`), respectively; * `Seminormed...Group`: A seminormed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible pseudometric space structure: `∀ x y, dist x y = ‖x / y‖` or `∀ x y, dist x y = ‖x - y‖`, depending on the group operation. * `Normed...Group`: A normed (additive) (commutative) group is an (additive) (commutative) group with a norm and a compatible metric space structure. We also prove basic properties of (semi)normed groups and provide some instances. ## Notes The current convention `dist x y = ‖x - y‖` means that the distance is invariant under right addition, but actions in mathlib are usually from the left. This means we might want to change it to `dist x y = ‖-x + y‖`. The normed group hierarchy would lend itself well to a mixin design (that is, having `SeminormedGroup` and `SeminormedAddGroup` not extend `Group` and `AddGroup`), but we choose not to for performance concerns. ## Tags normed group -/ variable {𝓕 α ι κ E F G : Type*} open Filter Function Metric Bornology open ENNReal Filter NNReal Uniformity Pointwise Topology /-- Auxiliary class, endowing a type `E` with a function `norm : E → ℝ` with notation `‖x‖`. This class is designed to be extended in more interesting classes specifying the properties of the norm. -/ @[notation_class] class Norm (E : Type*) where /-- the `ℝ`-valued norm function. -/ norm : E → ℝ /-- Auxiliary class, endowing a type `α` with a function `nnnorm : α → ℝ≥0` with notation `‖x‖₊`. -/ @[notation_class] class NNNorm (E : Type*) where /-- the `ℝ≥0`-valued norm function. -/ nnnorm : E → ℝ≥0 /-- Auxiliary class, endowing a type `α` with a function `enorm : α → ℝ≥0∞` with notation `‖x‖ₑ`. -/ @[notation_class] class ENorm (E : Type*) where /-- the `ℝ≥0∞`-valued norm function. -/ enorm : E → ℝ≥0∞ export Norm (norm) export NNNorm (nnnorm) export ENorm (enorm) @[inherit_doc] notation "‖" e "‖" => norm e @[inherit_doc] notation "‖" e "‖₊" => nnnorm e @[inherit_doc] notation "‖" e "‖ₑ" => enorm e section ENorm variable {E : Type*} [NNNorm E] {x : E} {r : ℝ≥0} instance NNNorm.toENorm : ENorm E where enorm := (‖·‖₊ : E → ℝ≥0∞) lemma enorm_eq_nnnorm (x : E) : ‖x‖ₑ = ‖x‖₊ := rfl @[simp] lemma toNNReal_enorm (x : E) : ‖x‖ₑ.toNNReal = ‖x‖₊ := rfl @[simp, norm_cast] lemma coe_le_enorm : r ≤ ‖x‖ₑ ↔ r ≤ ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_le_coe : ‖x‖ₑ ≤ r ↔ ‖x‖₊ ≤ r := by simp [enorm] @[simp, norm_cast] lemma coe_lt_enorm : r < ‖x‖ₑ ↔ r < ‖x‖₊ := by simp [enorm] @[simp, norm_cast] lemma enorm_lt_coe : ‖x‖ₑ < r ↔ ‖x‖₊ < r := by simp [enorm] @[simp] lemma enorm_ne_top : ‖x‖ₑ ≠ ∞ := by simp [enorm] @[simp] lemma enorm_lt_top : ‖x‖ₑ < ∞ := by simp [enorm] end ENorm /-- A type `E` equipped with a continuous map `‖·‖ₑ : E → ℝ≥0∞` NB. We do not demand that the topology is somehow defined by the enorm: for ℝ≥0∞ (the motivating example behind this definition), this is not true. -/ class ContinuousENorm (E : Type*) [TopologicalSpace E] extends ENorm E where continuous_enorm : Continuous enorm /-- An enormed monoid is an additive monoid endowed with a continuous enorm. -/ class ENormedAddMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, AddMonoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 0 protected enorm_add_le : ∀ x y : E, ‖x + y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ /-- An enormed monoid is a monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedMonoid (E : Type*) [TopologicalSpace E] extends ContinuousENorm E, Monoid E where enorm_eq_zero : ∀ x : E, ‖x‖ₑ = 0 ↔ x = 1 enorm_mul_le : ∀ x y : E, ‖x * y‖ₑ ≤ ‖x‖ₑ + ‖y‖ₑ /-- An enormed commutative monoid is an additive commutative monoid endowed with a continuous enorm. We don't have `ENormedAddCommMonoid` extend `EMetricSpace`, since the canonical instance `ℝ≥0∞` is not an `EMetricSpace`. This is because `ℝ≥0∞` carries the order topology, which is distinct from the topology coming from `edist`. -/ class ENormedAddCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedAddMonoid E, AddCommMonoid E where /-- An enormed commutative monoid is a commutative monoid endowed with a continuous enorm. -/ @[to_additive] class ENormedCommMonoid (E : Type*) [TopologicalSpace E] extends ENormedMonoid E, CommMonoid E where /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddGroup (E : Type*) extends Norm E, AddGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedGroup (E : Type*) extends Norm E, Group E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddGroup (E : Type*) extends Norm E, AddGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedGroup (E : Type*) extends Norm E, Group E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A seminormed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a pseudometric space structure. -/ class SeminormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A seminormed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a pseudometric space structure. -/ @[to_additive] class SeminormedCommGroup (E : Type*) extends Norm E, CommGroup E, PseudoMetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop /-- A normed group is an additive group endowed with a norm for which `dist x y = ‖x - y‖` defines a metric space structure. -/ class NormedAddCommGroup (E : Type*) extends Norm E, AddCommGroup E, MetricSpace E where dist := fun x y => ‖x - y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x - y‖ := by aesop /-- A normed group is a group endowed with a norm for which `dist x y = ‖x / y‖` defines a metric space structure. -/ @[to_additive] class NormedCommGroup (E : Type*) extends Norm E, CommGroup E, MetricSpace E where dist := fun x y => ‖x / y‖ /-- The distance function is induced by the norm. -/ dist_eq : ∀ x y, dist x y = ‖x / y‖ := by aesop -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedGroup.toSeminormedGroup [NormedGroup E] : SeminormedGroup E := { ‹NormedGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toSeminormedCommGroup [NormedCommGroup E] : SeminormedCommGroup E := { ‹NormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedCommGroup.toSeminormedGroup [SeminormedCommGroup E] : SeminormedGroup E := { ‹SeminormedCommGroup E› with } -- See note [lower instance priority] @[to_additive] instance (priority := 100) NormedCommGroup.toNormedGroup [NormedCommGroup E] : NormedGroup E := { ‹NormedCommGroup E› with } -- See note [reducible non-instances] /-- Construct a `NormedGroup` from a `SeminormedGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedGroup` instance as a special case of a more general `SeminormedGroup` instance. -/ @[to_additive "Construct a `NormedAddGroup` from a `SeminormedAddGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddGroup` instance as a special case of a more general `SeminormedAddGroup` instance."] abbrev NormedGroup.ofSeparation [SeminormedGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedGroup E where dist_eq := ‹SeminormedGroup E›.dist_eq toMetricSpace := { eq_of_dist_eq_zero := fun hxy => div_eq_one.1 <| h _ <| (‹SeminormedGroup E›.dist_eq _ _).symm.trans hxy } -- See note [reducible non-instances] /-- Construct a `NormedCommGroup` from a `SeminormedCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 1`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedCommGroup` instance as a special case of a more general `SeminormedCommGroup` instance. -/ @[to_additive "Construct a `NormedAddCommGroup` from a `SeminormedAddCommGroup` satisfying `∀ x, ‖x‖ = 0 → x = 0`. This avoids having to go back to the `(Pseudo)MetricSpace` level when declaring a `NormedAddCommGroup` instance as a special case of a more general `SeminormedAddCommGroup` instance."] abbrev NormedCommGroup.ofSeparation [SeminormedCommGroup E] (h : ∀ x : E, ‖x‖ = 0 → x = 1) : NormedCommGroup E := { ‹SeminormedCommGroup E›, NormedGroup.ofSeparation h with } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant distance. -/ @[to_additive "Construct a seminormed group from a translation-invariant distance."] abbrev SeminormedGroup.ofMulDist [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedGroup.ofMulDist' [Norm E] [Group E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedGroup E where dist_eq x y := by rw [h₁]; apply le_antisymm · simpa only [div_mul_cancel, one_mul] using h₂ (x / y) 1 y · simpa only [div_eq_mul_inv, ← mul_inv_cancel y] using h₂ _ _ _ -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a seminormed group from a translation-invariant pseudodistance."] abbrev SeminormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [PseudoMetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : SeminormedCommGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant distance. -/ @[to_additive "Construct a normed group from a translation-invariant distance."] abbrev NormedGroup.ofMulDist [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedGroup E := { SeminormedGroup.ofMulDist h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedGroup.ofMulDist' [Norm E] [Group E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedGroup E := { SeminormedGroup.ofMulDist' h₁ h₂ with eq_of_dist_eq_zero := eq_of_dist_eq_zero } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist x y ≤ dist (x * z) (y * z)) : NormedCommGroup E := { NormedGroup.ofMulDist h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a multiplication-invariant pseudodistance. -/ @[to_additive "Construct a normed group from a translation-invariant pseudodistance."] abbrev NormedCommGroup.ofMulDist' [Norm E] [CommGroup E] [MetricSpace E] (h₁ : ∀ x : E, ‖x‖ = dist x 1) (h₂ : ∀ x y z : E, dist (x * z) (y * z) ≤ dist x y) : NormedCommGroup E := { NormedGroup.ofMulDist' h₁ h₂ with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedGroup [Group E] (f : GroupSeminorm E) : SeminormedGroup E where dist x y := f (x / y) norm := f dist_eq _ _ := rfl dist_self x := by simp only [div_self', map_one_eq_zero] dist_triangle := le_map_div_add_map_div f dist_comm := map_div_rev f -- See note [reducible non-instances] /-- Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a seminormed group from a seminorm, i.e., registering the pseudodistance and the pseudometric space structure from the seminorm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupSeminorm.toSeminormedCommGroup [CommGroup E] (f : GroupSeminorm E) : SeminormedCommGroup E := { f.toSeminormedGroup with mul_comm := mul_comm } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedGroup [Group E] (f : GroupNorm E) : NormedGroup E := { f.toGroupSeminorm.toSeminormedGroup with eq_of_dist_eq_zero := fun h => div_eq_one.1 <| eq_one_of_map_eq_zero f h } -- See note [reducible non-instances] /-- Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`). -/ @[to_additive "Construct a normed group from a norm, i.e., registering the distance and the metric space structure from the norm properties. Note that in most cases this instance creates bad definitional equalities (e.g., it does not take into account a possibly existing `UniformSpace` instance on `E`)."] abbrev GroupNorm.toNormedCommGroup [CommGroup E] (f : GroupNorm E) : NormedCommGroup E := { f.toNormedGroup with mul_comm := mul_comm } section SeminormedGroup variable [SeminormedGroup E] [SeminormedGroup F] [SeminormedGroup G] {s : Set E} {a a₁ a₂ b c : E} {r r₁ r₂ : ℝ} @[to_additive] theorem dist_eq_norm_div (a b : E) : dist a b = ‖a / b‖ := SeminormedGroup.dist_eq _ _ @[to_additive] theorem dist_eq_norm_div' (a b : E) : dist a b = ‖b / a‖ := by rw [dist_comm, dist_eq_norm_div] alias dist_eq_norm := dist_eq_norm_sub alias dist_eq_norm' := dist_eq_norm_sub' @[to_additive of_forall_le_norm] lemma DiscreteTopology.of_forall_le_norm' (hpos : 0 < r) (hr : ∀ x : E, x ≠ 1 → r ≤ ‖x‖) : DiscreteTopology E := .of_forall_le_dist hpos fun x y hne ↦ by simp only [dist_eq_norm_div] exact hr _ (div_ne_one.2 hne) @[to_additive (attr := simp)] theorem dist_one_right (a : E) : dist a 1 = ‖a‖ := by rw [dist_eq_norm_div, div_one] @[to_additive] theorem inseparable_one_iff_norm {a : E} : Inseparable a 1 ↔ ‖a‖ = 0 := by rw [Metric.inseparable_iff, dist_one_right] @[to_additive] lemma dist_one_left (a : E) : dist 1 a = ‖a‖ := by rw [dist_comm, dist_one_right] @[to_additive (attr := simp)] lemma dist_one : dist (1 : E) = norm := funext dist_one_left @[to_additive] theorem norm_div_rev (a b : E) : ‖a / b‖ = ‖b / a‖ := by simpa only [dist_eq_norm_div] using dist_comm a b @[to_additive (attr := simp) norm_neg] theorem norm_inv' (a : E) : ‖a⁻¹‖ = ‖a‖ := by simpa using norm_div_rev 1 a @[to_additive (attr := simp) norm_abs_zsmul] theorem norm_zpow_abs (a : E) (n : ℤ) : ‖a ^ |n|‖ = ‖a ^ n‖ := by rcases le_total 0 n with hn | hn <;> simp [hn, abs_of_nonneg, abs_of_nonpos] @[to_additive (attr := simp) norm_natAbs_smul] theorem norm_pow_natAbs (a : E) (n : ℤ) : ‖a ^ n.natAbs‖ = ‖a ^ n‖ := by rw [← zpow_natCast, ← Int.abs_eq_natAbs, norm_zpow_abs] @[to_additive norm_isUnit_zsmul] theorem norm_zpow_isUnit (a : E) {n : ℤ} (hn : IsUnit n) : ‖a ^ n‖ = ‖a‖ := by rw [← norm_pow_natAbs, Int.isUnit_iff_natAbs_eq.mp hn, pow_one] @[simp] theorem norm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℤˣ) (a : E) : ‖n • a‖ = ‖a‖ := norm_isUnit_zsmul a n.isUnit open scoped symmDiff in @[to_additive] theorem dist_mulIndicator (s t : Set α) (f : α → E) (x : α) : dist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖ := by rw [dist_eq_norm_div, Set.apply_mulIndicator_symmDiff norm_inv'] /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le "**Triangle inequality** for the norm."] theorem norm_mul_le' (a b : E) : ‖a * b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b⁻¹ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add_le_of_le "**Triangle inequality** for the norm."] theorem norm_mul_le_of_le' (h₁ : ‖a₁‖ ≤ r₁) (h₂ : ‖a₂‖ ≤ r₂) : ‖a₁ * a₂‖ ≤ r₁ + r₂ := (norm_mul_le' a₁ a₂).trans <| add_le_add h₁ h₂ /-- **Triangle inequality** for the norm. -/ @[to_additive norm_add₃_le "**Triangle inequality** for the norm."] lemma norm_mul₃_le' : ‖a * b * c‖ ≤ ‖a‖ + ‖b‖ + ‖c‖ := norm_mul_le_of_le' (norm_mul_le' _ _) le_rfl @[to_additive] lemma norm_div_le_norm_div_add_norm_div (a b c : E) : ‖a / c‖ ≤ ‖a / b‖ + ‖b / c‖ := by simpa only [dist_eq_norm_div] using dist_triangle a b c @[to_additive (attr := simp) norm_nonneg] theorem norm_nonneg' (a : E) : 0 ≤ ‖a‖ := by rw [← dist_one_right] exact dist_nonneg attribute [bound] norm_nonneg @[to_additive (attr := simp) abs_norm] theorem abs_norm' (z : E) : |‖z‖| = ‖z‖ := abs_of_nonneg <| norm_nonneg' _ @[to_additive (attr := simp) norm_zero] theorem norm_one' : ‖(1 : E)‖ = 0 := by rw [← dist_one_right, dist_self] @[to_additive] theorem ne_one_of_norm_ne_zero : ‖a‖ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact norm_one' @[to_additive (attr := nontriviality) norm_of_subsingleton] theorem norm_of_subsingleton' [Subsingleton E] (a : E) : ‖a‖ = 0 := by rw [Subsingleton.elim a 1, norm_one'] @[to_additive zero_lt_one_add_norm_sq] theorem zero_lt_one_add_norm_sq' (x : E) : 0 < 1 + ‖x‖ ^ 2 := by positivity @[to_additive] theorem norm_div_le (a b : E) : ‖a / b‖ ≤ ‖a‖ + ‖b‖ := by simpa [dist_eq_norm_div] using dist_triangle a 1 b attribute [bound] norm_sub_le @[to_additive] theorem norm_div_le_of_le {r₁ r₂ : ℝ} (H₁ : ‖a₁‖ ≤ r₁) (H₂ : ‖a₂‖ ≤ r₂) : ‖a₁ / a₂‖ ≤ r₁ + r₂ := (norm_div_le a₁ a₂).trans <| add_le_add H₁ H₂ @[to_additive dist_le_norm_add_norm] theorem dist_le_norm_add_norm' (a b : E) : dist a b ≤ ‖a‖ + ‖b‖ := by rw [dist_eq_norm_div] apply norm_div_le @[to_additive abs_norm_sub_norm_le] theorem abs_norm_sub_norm_le' (a b : E) : |‖a‖ - ‖b‖| ≤ ‖a / b‖ := by simpa [dist_eq_norm_div] using abs_dist_sub_le a b 1 @[to_additive norm_sub_norm_le] theorem norm_sub_norm_le' (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a / b‖ := (le_abs_self _).trans (abs_norm_sub_norm_le' a b) @[to_additive (attr := bound)] theorem norm_sub_le_norm_mul (a b : E) : ‖a‖ - ‖b‖ ≤ ‖a * b‖ := by simpa using norm_mul_le' (a * b) (b⁻¹) @[to_additive dist_norm_norm_le] theorem dist_norm_norm_le' (a b : E) : dist ‖a‖ ‖b‖ ≤ ‖a / b‖ := abs_norm_sub_norm_le' a b @[to_additive] theorem norm_le_norm_add_norm_div' (u v : E) : ‖u‖ ≤ ‖v‖ + ‖u / v‖ := by rw [add_comm] refine (norm_mul_le' _ _).trans_eq' ?_ rw [div_mul_cancel] @[to_additive] theorem norm_le_norm_add_norm_div (u v : E) : ‖v‖ ≤ ‖u‖ + ‖u / v‖ := by rw [norm_div_rev] exact norm_le_norm_add_norm_div' v u alias norm_le_insert' := norm_le_norm_add_norm_sub' alias norm_le_insert := norm_le_norm_add_norm_sub @[to_additive] theorem norm_le_mul_norm_add (u v : E) : ‖u‖ ≤ ‖u * v‖ + ‖v‖ := calc ‖u‖ = ‖u * v / v‖ := by rw [mul_div_cancel_right] _ ≤ ‖u * v‖ + ‖v‖ := norm_div_le _ _ /-- An analogue of `norm_le_mul_norm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `norm_le_add_norm_add` for the addition from the left."] theorem norm_le_mul_norm_add' (u v : E) : ‖v‖ ≤ ‖u * v‖ + ‖u‖ := calc ‖v‖ = ‖u⁻¹ * (u * v)‖ := by rw [← mul_assoc, inv_mul_cancel, one_mul] _ ≤ ‖u⁻¹‖ + ‖u * v‖ := norm_mul_le' u⁻¹ (u * v) _ = ‖u * v‖ + ‖u‖ := by rw [norm_inv', add_comm] @[to_additive] lemma norm_mul_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x * y‖ = ‖y‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_mul_le' x y · simpa [h] using norm_le_mul_norm_add' x y @[to_additive] lemma norm_mul_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x * y‖ = ‖x‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_mul_le' x y · simpa [h] using norm_le_mul_norm_add x y @[to_additive] lemma norm_div_eq_norm_right {x : E} (y : E) (h : ‖x‖ = 0) : ‖x / y‖ = ‖y‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_div_le x y · simpa [h, norm_div_rev x y] using norm_sub_norm_le' y x @[to_additive] lemma norm_div_eq_norm_left (x : E) {y : E} (h : ‖y‖ = 0) : ‖x / y‖ = ‖x‖ := by apply le_antisymm ?_ ?_ · simpa [h] using norm_div_le x y · simpa [h] using norm_sub_norm_le' x y @[to_additive ball_eq] theorem ball_eq' (y : E) (ε : ℝ) : ball y ε = { x | ‖x / y‖ < ε } := Set.ext fun a => by simp [dist_eq_norm_div] @[to_additive] theorem ball_one_eq (r : ℝ) : ball (1 : E) r = { x | ‖x‖ < r } := Set.ext fun a => by simp @[to_additive mem_ball_iff_norm] theorem mem_ball_iff_norm'' : b ∈ ball a r ↔ ‖b / a‖ < r := by rw [mem_ball, dist_eq_norm_div] @[to_additive mem_ball_iff_norm'] theorem mem_ball_iff_norm''' : b ∈ ball a r ↔ ‖a / b‖ < r := by rw [mem_ball', dist_eq_norm_div] @[to_additive] theorem mem_ball_one_iff : a ∈ ball (1 : E) r ↔ ‖a‖ < r := by rw [mem_ball, dist_one_right] @[to_additive mem_closedBall_iff_norm] theorem mem_closedBall_iff_norm'' : b ∈ closedBall a r ↔ ‖b / a‖ ≤ r := by rw [mem_closedBall, dist_eq_norm_div] @[to_additive] theorem mem_closedBall_one_iff : a ∈ closedBall (1 : E) r ↔ ‖a‖ ≤ r := by rw [mem_closedBall, dist_one_right] @[to_additive mem_closedBall_iff_norm'] theorem mem_closedBall_iff_norm''' : b ∈ closedBall a r ↔ ‖a / b‖ ≤ r := by rw [mem_closedBall', dist_eq_norm_div] @[to_additive norm_le_of_mem_closedBall] theorem norm_le_of_mem_closedBall' (h : b ∈ closedBall a r) : ‖b‖ ≤ ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans <| add_le_add_left (by rwa [← dist_eq_norm_div]) _ @[to_additive norm_le_norm_add_const_of_dist_le] theorem norm_le_norm_add_const_of_dist_le' : dist a b ≤ r → ‖a‖ ≤ ‖b‖ + r := norm_le_of_mem_closedBall' @[to_additive norm_lt_of_mem_ball] theorem norm_lt_of_mem_ball' (h : b ∈ ball a r) : ‖b‖ < ‖a‖ + r := (norm_le_norm_add_norm_div' _ _).trans_lt <| add_lt_add_left (by rwa [← dist_eq_norm_div]) _ @[to_additive] theorem norm_div_sub_norm_div_le_norm_div (u v w : E) : ‖u / w‖ - ‖v / w‖ ≤ ‖u / v‖ := by simpa only [div_div_div_cancel_right] using norm_sub_norm_le' (u / w) (v / w) @[to_additive (attr := simp 1001) mem_sphere_iff_norm] -- Porting note: increase priority so the left-hand side doesn't reduce theorem mem_sphere_iff_norm' : b ∈ sphere a r ↔ ‖b / a‖ = r := by simp [dist_eq_norm_div] @[to_additive] -- `simp` can prove this theorem mem_sphere_one_iff_norm : a ∈ sphere (1 : E) r ↔ ‖a‖ = r := by simp [dist_eq_norm_div] @[to_additive (attr := simp) norm_eq_of_mem_sphere] theorem norm_eq_of_mem_sphere' (x : sphere (1 : E) r) : ‖(x : E)‖ = r := mem_sphere_one_iff_norm.mp x.2 @[to_additive] theorem ne_one_of_mem_sphere (hr : r ≠ 0) (x : sphere (1 : E) r) : (x : E) ≠ 1 := ne_one_of_norm_ne_zero <| by rwa [norm_eq_of_mem_sphere' x] @[to_additive ne_zero_of_mem_unit_sphere] theorem ne_one_of_mem_unit_sphere (x : sphere (1 : E) 1) : (x : E) ≠ 1 := ne_one_of_mem_sphere one_ne_zero _ variable (E) /-- The norm of a seminormed group as a group seminorm. -/ @[to_additive "The norm of a seminormed group as an additive group seminorm."] def normGroupSeminorm : GroupSeminorm E := ⟨norm, norm_one', norm_mul_le', norm_inv'⟩ @[to_additive (attr := simp)] theorem coe_normGroupSeminorm : ⇑(normGroupSeminorm E) = norm := rfl variable {E} @[to_additive] theorem NormedCommGroup.tendsto_nhds_one {f : α → E} {l : Filter α} : Tendsto f l (𝓝 1) ↔ ∀ ε > 0, ∀ᶠ x in l, ‖f x‖ < ε := Metric.tendsto_nhds.trans <| by simp only [dist_one_right] @[to_additive] theorem NormedCommGroup.tendsto_nhds_nhds {f : E → F} {x : E} {y : F} : Tendsto f (𝓝 x) (𝓝 y) ↔ ∀ ε > 0, ∃ δ > 0, ∀ x', ‖x' / x‖ < δ → ‖f x' / y‖ < ε := by simp_rw [Metric.tendsto_nhds_nhds, dist_eq_norm_div] @[to_additive] theorem NormedCommGroup.nhds_basis_norm_lt (x : E) : (𝓝 x).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y / x‖ < ε } := by simp_rw [← ball_eq'] exact Metric.nhds_basis_ball @[to_additive] theorem NormedCommGroup.nhds_one_basis_norm_lt : (𝓝 (1 : E)).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { y | ‖y‖ < ε } := by convert NormedCommGroup.nhds_basis_norm_lt (1 : E) simp @[to_additive] theorem NormedCommGroup.uniformity_basis_dist : (𝓤 E).HasBasis (fun ε : ℝ => 0 < ε) fun ε => { p : E × E | ‖p.fst / p.snd‖ < ε } := by convert Metric.uniformity_basis_dist (α := E) using 1 simp [dist_eq_norm_div] open Finset variable [FunLike 𝓕 E F] section NNNorm -- See note [lower instance priority] @[to_additive] instance (priority := 100) SeminormedGroup.toNNNorm : NNNorm E := ⟨fun a => ⟨‖a‖, norm_nonneg' a⟩⟩ @[to_additive (attr := simp, norm_cast) coe_nnnorm] theorem coe_nnnorm' (a : E) : (‖a‖₊ : ℝ) = ‖a‖ := rfl @[to_additive (attr := simp) coe_comp_nnnorm] theorem coe_comp_nnnorm' : (toReal : ℝ≥0 → ℝ) ∘ (nnnorm : E → ℝ≥0) = norm := rfl @[to_additive (attr := simp) norm_toNNReal] theorem norm_toNNReal' : ‖a‖.toNNReal = ‖a‖₊ := @Real.toNNReal_coe ‖a‖₊ @[to_additive (attr := simp) toReal_enorm] lemma toReal_enorm' (x : E) : ‖x‖ₑ.toReal = ‖x‖ := by simp [enorm] @[to_additive (attr := simp) ofReal_norm] lemma ofReal_norm' (x : E) : .ofReal ‖x‖ = ‖x‖ₑ := by simp [enorm, ENNReal.ofReal, Real.toNNReal, nnnorm] @[to_additive enorm_eq_iff_norm_eq] theorem enorm'_eq_iff_norm_eq {x : E} {y : F} : ‖x‖ₑ = ‖y‖ₑ ↔ ‖x‖ = ‖y‖ := by simp only [← ofReal_norm'] refine ⟨fun h ↦ ?_, fun h ↦ by congr⟩ exact (Real.toNNReal_eq_toNNReal_iff (norm_nonneg' _) (norm_nonneg' _)).mp (ENNReal.coe_inj.mp h) @[to_additive enorm_le_iff_norm_le] theorem enorm'_le_iff_norm_le {x : E} {y : F} : ‖x‖ₑ ≤ ‖y‖ₑ ↔ ‖x‖ ≤ ‖y‖ := by simp only [← ofReal_norm'] refine ⟨fun h ↦ ?_, fun h ↦ by gcongr⟩ rw [ENNReal.ofReal_le_ofReal_iff (norm_nonneg' _)] at h exact h @[to_additive] theorem nndist_eq_nnnorm_div (a b : E) : nndist a b = ‖a / b‖₊ := NNReal.eq <| dist_eq_norm_div _ _ alias nndist_eq_nnnorm := nndist_eq_nnnorm_sub @[to_additive (attr := simp)] theorem nndist_one_right (a : E) : nndist a 1 = ‖a‖₊ := by simp [nndist_eq_nnnorm_div] @[to_additive (attr := simp)] lemma edist_one_right (a : E) : edist a 1 = ‖a‖ₑ := by simp [edist_nndist, nndist_one_right, enorm] @[to_additive (attr := simp) nnnorm_zero] theorem nnnorm_one' : ‖(1 : E)‖₊ = 0 := NNReal.eq norm_one' @[to_additive] theorem ne_one_of_nnnorm_ne_zero {a : E} : ‖a‖₊ ≠ 0 → a ≠ 1 := mt <| by rintro rfl exact nnnorm_one' @[to_additive nnnorm_add_le] theorem nnnorm_mul_le' (a b : E) : ‖a * b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_mul_le' a b @[to_additive norm_nsmul_le] lemma norm_pow_le_mul_norm : ∀ {n : ℕ}, ‖a ^ n‖ ≤ n * ‖a‖ | 0 => by simp | n + 1 => by simpa [pow_succ, add_mul] using norm_mul_le_of_le' norm_pow_le_mul_norm le_rfl @[to_additive nnnorm_nsmul_le] lemma nnnorm_pow_le_mul_norm {n : ℕ} : ‖a ^ n‖₊ ≤ n * ‖a‖₊ := by simpa only [← NNReal.coe_le_coe, NNReal.coe_mul, NNReal.coe_natCast] using norm_pow_le_mul_norm @[to_additive (attr := simp) nnnorm_neg] theorem nnnorm_inv' (a : E) : ‖a⁻¹‖₊ = ‖a‖₊ := NNReal.eq <| norm_inv' a @[to_additive (attr := simp) nnnorm_abs_zsmul] theorem nnnorm_zpow_abs (a : E) (n : ℤ) : ‖a ^ |n|‖₊ = ‖a ^ n‖₊ := NNReal.eq <| norm_zpow_abs a n @[to_additive (attr := simp) nnnorm_natAbs_smul] theorem nnnorm_pow_natAbs (a : E) (n : ℤ) : ‖a ^ n.natAbs‖₊ = ‖a ^ n‖₊ := NNReal.eq <| norm_pow_natAbs a n @[to_additive nnnorm_isUnit_zsmul] theorem nnnorm_zpow_isUnit (a : E) {n : ℤ} (hn : IsUnit n) : ‖a ^ n‖₊ = ‖a‖₊ := NNReal.eq <| norm_zpow_isUnit a hn @[simp] theorem nnnorm_units_zsmul {E : Type*} [SeminormedAddGroup E] (n : ℤˣ) (a : E) : ‖n • a‖₊ = ‖a‖₊ := NNReal.eq <| norm_isUnit_zsmul a n.isUnit @[to_additive (attr := simp)] theorem nndist_one_left (a : E) : nndist 1 a = ‖a‖₊ := by simp [nndist_eq_nnnorm_div] @[to_additive (attr := simp)] theorem edist_one_left (a : E) : edist 1 a = ‖a‖₊ := by rw [edist_nndist, nndist_one_left] open scoped symmDiff in @[to_additive] theorem nndist_mulIndicator (s t : Set α) (f : α → E) (x : α) : nndist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := NNReal.eq <| dist_mulIndicator s t f x @[to_additive] theorem nnnorm_div_le (a b : E) : ‖a / b‖₊ ≤ ‖a‖₊ + ‖b‖₊ := NNReal.coe_le_coe.1 <| norm_div_le _ _ @[to_additive] lemma enorm_div_le : ‖a / b‖ₑ ≤ ‖a‖ₑ + ‖b‖ₑ := by simpa [enorm, ← ENNReal.coe_add] using nnnorm_div_le a b @[to_additive nndist_nnnorm_nnnorm_le] theorem nndist_nnnorm_nnnorm_le' (a b : E) : nndist ‖a‖₊ ‖b‖₊ ≤ ‖a / b‖₊ := NNReal.coe_le_coe.1 <| dist_norm_norm_le' a b @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div (a b : E) : ‖b‖₊ ≤ ‖a‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div _ _ @[to_additive] theorem nnnorm_le_nnnorm_add_nnnorm_div' (a b : E) : ‖a‖₊ ≤ ‖b‖₊ + ‖a / b‖₊ := norm_le_norm_add_norm_div' _ _ alias nnnorm_le_insert' := nnnorm_le_nnnorm_add_nnnorm_sub' alias nnnorm_le_insert := nnnorm_le_nnnorm_add_nnnorm_sub @[to_additive] theorem nnnorm_le_mul_nnnorm_add (a b : E) : ‖a‖₊ ≤ ‖a * b‖₊ + ‖b‖₊ := norm_le_mul_norm_add _ _ /-- An analogue of `nnnorm_le_mul_nnnorm_add` for the multiplication from the left. -/ @[to_additive "An analogue of `nnnorm_le_add_nnnorm_add` for the addition from the left."] theorem nnnorm_le_mul_nnnorm_add' (a b : E) : ‖b‖₊ ≤ ‖a * b‖₊ + ‖a‖₊ := norm_le_mul_norm_add' _ _ @[to_additive] lemma nnnorm_mul_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x * y‖₊ = ‖y‖₊ := NNReal.eq <| norm_mul_eq_norm_right _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_mul_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x * y‖₊ = ‖x‖₊ := NNReal.eq <| norm_mul_eq_norm_left _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_div_eq_nnnorm_right {x : E} (y : E) (h : ‖x‖₊ = 0) : ‖x / y‖₊ = ‖y‖₊ := NNReal.eq <| norm_div_eq_norm_right _ <| congr_arg NNReal.toReal h @[to_additive] lemma nnnorm_div_eq_nnnorm_left (x : E) {y : E} (h : ‖y‖₊ = 0) : ‖x / y‖₊ = ‖x‖₊ := NNReal.eq <| norm_div_eq_norm_left _ <| congr_arg NNReal.toReal h /-- The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm. -/ @[to_additive toReal_coe_nnnorm "The non negative norm seen as an `ENNReal` and then as a `Real` is equal to the norm."] theorem toReal_coe_nnnorm' (a : E) : (‖a‖₊ : ℝ≥0∞).toReal = ‖a‖ := rfl open scoped symmDiff in @[to_additive] theorem edist_mulIndicator (s t : Set α) (f : α → E) (x : α) : edist (s.mulIndicator f x) (t.mulIndicator f x) = ‖(s ∆ t).mulIndicator f x‖₊ := by rw [edist_nndist, nndist_mulIndicator] end NNNorm section ENorm @[to_additive (attr := simp) enorm_zero] lemma enorm_one' {E : Type*} [TopologicalSpace E] [ENormedMonoid E] : ‖(1 : E)‖ₑ = 0 := by rw [ENormedMonoid.enorm_eq_zero] @[to_additive exists_enorm_lt] lemma exists_enorm_lt' (E : Type*) [TopologicalSpace E] [ENormedMonoid E] [hbot : NeBot (𝓝[≠] (1 : E))] {c : ℝ≥0∞} (hc : c ≠ 0) : ∃ x ≠ (1 : E), ‖x‖ₑ < c := frequently_iff_neBot.mpr hbot |>.and_eventually (ContinuousENorm.continuous_enorm.tendsto' 1 0 (by simp) |>.eventually_lt_const hc.bot_lt) |>.exists @[to_additive (attr := simp) enorm_neg] lemma enorm_inv' (a : E) : ‖a⁻¹‖ₑ = ‖a‖ₑ := by simp [enorm] @[to_additive ofReal_norm_eq_enorm] lemma ofReal_norm_eq_enorm' (a : E) : .ofReal ‖a‖ = ‖a‖ₑ := ENNReal.ofReal_eq_coe_nnreal _ @[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm := ofReal_norm_eq_enorm @[deprecated (since := "2025-01-17")] alias ofReal_norm_eq_coe_nnnorm' := ofReal_norm_eq_enorm' instance : ENorm ℝ≥0∞ where enorm x := x @[simp] lemma enorm_eq_self (x : ℝ≥0∞) : ‖x‖ₑ = x := rfl @[to_additive] theorem edist_eq_enorm_div (a b : E) : edist a b = ‖a / b‖ₑ := by rw [edist_dist, dist_eq_norm_div, ofReal_norm_eq_enorm'] @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm_sub := edist_eq_enorm_sub @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm_div := edist_eq_enorm_div @[to_additive] theorem edist_one_eq_enorm (x : E) : edist x 1 = ‖x‖ₑ := by rw [edist_eq_enorm_div, div_one] @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm := edist_zero_eq_enorm @[deprecated (since := "2025-01-17")] alias edist_eq_coe_nnnorm' := edist_one_eq_enorm @[to_additive] theorem mem_emetric_ball_one_iff {r : ℝ≥0∞} : a ∈ EMetric.ball 1 r ↔ ‖a‖ₑ < r := by rw [EMetric.mem_ball, edist_one_eq_enorm] end ENorm section ContinuousENorm variable {E : Type*} [TopologicalSpace E] [ContinuousENorm E] @[continuity, fun_prop] lemma continuous_enorm : Continuous fun a : E ↦ ‖a‖ₑ := ContinuousENorm.continuous_enorm variable {X : Type*} [TopologicalSpace X] {f : X → E} {s : Set X} {a : X} @[fun_prop] lemma Continuous.enorm : Continuous f → Continuous (‖f ·‖ₑ) := continuous_enorm.comp lemma ContinuousAt.enorm {a : X} (h : ContinuousAt f a) : ContinuousAt (‖f ·‖ₑ) a := by fun_prop @[fun_prop] lemma ContinuousWithinAt.enorm {s : Set X} {a : X} (h : ContinuousWithinAt f s a) : ContinuousWithinAt (‖f ·‖ₑ) s a := (ContinuousENorm.continuous_enorm.continuousWithinAt).comp (t := Set.univ) h (fun _ _ ↦ by trivial) @[fun_prop] lemma ContinuousOn.enorm (h : ContinuousOn f s) : ContinuousOn (‖f ·‖ₑ) s := (ContinuousENorm.continuous_enorm.continuousOn).comp (t := Set.univ) h <| Set.mapsTo_univ _ _ end ContinuousENorm section ENormedMonoid variable {E : Type*} [TopologicalSpace E] [ENormedMonoid E] @[to_additive enorm_add_le] lemma enorm_mul_le' (a b : E) : ‖a * b‖ₑ ≤ ‖a‖ₑ + ‖b‖ₑ := ENormedMonoid.enorm_mul_le a b @[to_additive (attr := simp) enorm_eq_zero] lemma enorm_eq_zero' {a : E} : ‖a‖ₑ = 0 ↔ a = 1 := by simp [enorm, ENormedMonoid.enorm_eq_zero] @[to_additive enorm_ne_zero] lemma enorm_ne_zero' {a : E} : ‖a‖ₑ ≠ 0 ↔ a ≠ 1 := enorm_eq_zero'.ne @[to_additive (attr := simp) enorm_pos] lemma enorm_pos' {a : E} : 0 < ‖a‖ₑ ↔ a ≠ 1 := pos_iff_ne_zero.trans enorm_ne_zero' end ENormedMonoid instance : ENormedAddCommMonoid ℝ≥0∞ where continuous_enorm := continuous_id enorm_eq_zero := by simp enorm_add_le := by simp open Set in @[to_additive] lemma SeminormedGroup.disjoint_nhds (x : E) (f : Filter E) : Disjoint (𝓝 x) f ↔ ∃ δ > 0, ∀ᶠ y in f, δ ≤ ‖y / x‖ := by simp [NormedCommGroup.nhds_basis_norm_lt x |>.disjoint_iff_left, compl_setOf, eventually_iff] @[to_additive] lemma SeminormedGroup.disjoint_nhds_one (f : Filter E) : Disjoint (𝓝 1) f ↔ ∃ δ > 0, ∀ᶠ y in f, δ ≤ ‖y‖ := by simpa using disjoint_nhds 1 f end SeminormedGroup section Induced variable (E F) variable [FunLike 𝓕 E F] -- See note [reducible non-instances] /-- A group homomorphism from a `Group` to a `SeminormedGroup` induces a `SeminormedGroup` structure on the domain. -/ @[to_additive "A group homomorphism from an `AddGroup` to a `SeminormedAddGroup` induces a `SeminormedAddGroup` structure on the domain."] abbrev SeminormedGroup.induced [Group E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedGroup E := { PseudoMetricSpace.induced f toPseudoMetricSpace with norm := fun x => ‖f x‖ dist_eq := fun x y => by simp only [map_div, ← dist_eq_norm_div]; rfl } -- See note [reducible non-instances] /-- A group homomorphism from a `CommGroup` to a `SeminormedGroup` induces a `SeminormedCommGroup` structure on the domain. -/ @[to_additive "A group homomorphism from an `AddCommGroup` to a `SeminormedAddGroup` induces a `SeminormedAddCommGroup` structure on the domain."] abbrev SeminormedCommGroup.induced [CommGroup E] [SeminormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) : SeminormedCommGroup E := { SeminormedGroup.induced E F f with mul_comm := mul_comm } -- See note [reducible non-instances]. /-- An injective group homomorphism from a `Group` to a `NormedGroup` induces a `NormedGroup` structure on the domain. -/ @[to_additive "An injective group homomorphism from an `AddGroup` to a `NormedAddGroup` induces a `NormedAddGroup` structure on the domain."] abbrev NormedGroup.induced [Group E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with } -- See note [reducible non-instances]. /-- An injective group homomorphism from a `CommGroup` to a `NormedGroup` induces a `NormedCommGroup` structure on the domain. -/ @[to_additive "An injective group homomorphism from a `CommGroup` to a `NormedCommGroup` induces a `NormedCommGroup` structure on the domain."] abbrev NormedCommGroup.induced [CommGroup E] [NormedGroup F] [MonoidHomClass 𝓕 E F] (f : 𝓕) (h : Injective f) : NormedCommGroup E := { SeminormedGroup.induced E F f, MetricSpace.induced f h _ with mul_comm := mul_comm } end Induced namespace Real variable {r : ℝ} instance norm : Norm ℝ where norm r := |r| @[simp] theorem norm_eq_abs (r : ℝ) : ‖r‖ = |r| := rfl instance normedAddCommGroup : NormedAddCommGroup ℝ := ⟨fun _r _y => rfl⟩ theorem norm_of_nonneg (hr : 0 ≤ r) : ‖r‖ = r := abs_of_nonneg hr theorem norm_of_nonpos (hr : r ≤ 0) : ‖r‖ = -r := abs_of_nonpos hr theorem le_norm_self (r : ℝ) : r ≤ ‖r‖ := le_abs_self r @[simp 1100] lemma norm_natCast (n : ℕ) : ‖(n : ℝ)‖ = n := abs_of_nonneg n.cast_nonneg @[simp 1100] lemma nnnorm_natCast (n : ℕ) : ‖(n : ℝ)‖₊ = n := NNReal.eq <| norm_natCast _ @[simp 1100] lemma enorm_natCast (n : ℕ) : ‖(n : ℝ)‖ₑ = n := by simp [enorm] @[simp 1100] lemma norm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : ℝ)‖ = ofNat(n) := norm_natCast n @[simp 1100] lemma nnnorm_ofNat (n : ℕ) [n.AtLeastTwo] : ‖(ofNat(n) : ℝ)‖₊ = ofNat(n) := nnnorm_natCast n lemma norm_two : ‖(2 : ℝ)‖ = 2 := abs_of_pos zero_lt_two lemma nnnorm_two : ‖(2 : ℝ)‖₊ = 2 := NNReal.eq <| by simp @[simp 1100, norm_cast] lemma norm_nnratCast (q : ℚ≥0) : ‖(q : ℝ)‖ = q := norm_of_nonneg q.cast_nonneg @[simp 1100, norm_cast] lemma nnnorm_nnratCast (q : ℚ≥0) : ‖(q : ℝ)‖₊ = q := by simp [nnnorm, -norm_eq_abs] theorem nnnorm_of_nonneg (hr : 0 ≤ r) : ‖r‖₊ = ⟨r, hr⟩ := NNReal.eq <| norm_of_nonneg hr lemma enorm_of_nonneg (hr : 0 ≤ r) : ‖r‖ₑ = .ofReal r := by simp [enorm, nnnorm_of_nonneg hr, ENNReal.ofReal, toNNReal, hr] @[simp] lemma nnnorm_abs (r : ℝ) : ‖|r|‖₊ = ‖r‖₊ := by simp [nnnorm] @[simp] lemma enorm_abs (r : ℝ) : ‖|r|‖ₑ = ‖r‖ₑ := by simp [enorm] theorem enorm_eq_ofReal (hr : 0 ≤ r) : ‖r‖ₑ = .ofReal r := by rw [← ofReal_norm_eq_enorm, norm_of_nonneg hr] @[deprecated (since := "2025-01-17")] alias ennnorm_eq_ofReal := enorm_eq_ofReal theorem enorm_eq_ofReal_abs (r : ℝ) : ‖r‖ₑ = ENNReal.ofReal |r| := by rw [← enorm_eq_ofReal (abs_nonneg _), enorm_abs] @[deprecated (since := "2025-01-17")] alias ennnorm_eq_ofReal_abs := enorm_eq_ofReal_abs theorem toNNReal_eq_nnnorm_of_nonneg (hr : 0 ≤ r) : r.toNNReal = ‖r‖₊ := by rw [Real.toNNReal_of_nonneg hr] ext rw [coe_mk, coe_nnnorm r, Real.norm_eq_abs r, abs_of_nonneg hr] -- Porting note: this is due to the change from `Subtype.val` to `NNReal.toReal` for the coercion theorem ofReal_le_enorm (r : ℝ) : ENNReal.ofReal r ≤ ‖r‖ₑ := by rw [enorm_eq_ofReal_abs]; gcongr; exact le_abs_self _ @[deprecated (since := "2025-01-17")] alias ofReal_le_ennnorm := ofReal_le_enorm end Real namespace NNReal instance : NNNorm ℝ≥0 where nnnorm x := x @[simp] lemma nnnorm_eq_self (x : ℝ≥0) : ‖x‖₊ = x := rfl end NNReal section SeminormedCommGroup variable [SeminormedCommGroup E] [SeminormedCommGroup F] {a b : E} {r : ℝ} @[to_additive] theorem dist_inv (x y : E) : dist x⁻¹ y = dist x y⁻¹ := by simp_rw [dist_eq_norm_div, ← norm_inv' (x⁻¹ / y), inv_div, div_inv_eq_mul, mul_comm] theorem norm_multiset_sum_le {E} [SeminormedAddCommGroup E] (m : Multiset E) : ‖m.sum‖ ≤ (m.map fun x => ‖x‖).sum := m.le_sum_of_subadditive norm norm_zero norm_add_le @[to_additive existing] theorem norm_multiset_prod_le (m : Multiset E) : ‖m.prod‖ ≤ (m.map fun x => ‖x‖).sum := by rw [← Multiplicative.ofAdd_le, ofAdd_multiset_prod, Multiset.map_map] refine Multiset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y @[bound] theorem norm_sum_le {ι E} [SeminormedAddCommGroup E] (s : Finset ι) (f : ι → E) : ‖∑ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := s.le_sum_of_subadditive norm norm_zero norm_add_le f @[to_additive existing] theorem norm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ i ∈ s, f i‖ ≤ ∑ i ∈ s, ‖f i‖ := by rw [← Multiplicative.ofAdd_le, ofAdd_sum] refine Finset.le_prod_of_submultiplicative (Multiplicative.ofAdd ∘ norm) ?_ (fun x y => ?_) _ _ · simp only [comp_apply, norm_one', ofAdd_zero] · exact norm_mul_le' x y @[to_additive] theorem norm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ} (h : ∀ b ∈ s, ‖f b‖ ≤ n b) : ‖∏ b ∈ s, f b‖ ≤ ∑ b ∈ s, n b := (norm_prod_le s f).trans <| Finset.sum_le_sum h @[to_additive] theorem dist_prod_prod_le_of_le (s : Finset ι) {f a : ι → E} {d : ι → ℝ} (h : ∀ b ∈ s, dist (f b) (a b) ≤ d b) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, d b := by simp only [dist_eq_norm_div, ← Finset.prod_div_distrib] at * exact norm_prod_le_of_le s h @[to_additive] theorem dist_prod_prod_le (s : Finset ι) (f a : ι → E) : dist (∏ b ∈ s, f b) (∏ b ∈ s, a b) ≤ ∑ b ∈ s, dist (f b) (a b) := dist_prod_prod_le_of_le s fun _ _ => le_rfl @[to_additive] theorem mul_mem_ball_iff_norm : a * b ∈ ball a r ↔ ‖b‖ < r := by rw [mem_ball_iff_norm'', mul_div_cancel_left] @[to_additive] theorem mul_mem_closedBall_iff_norm : a * b ∈ closedBall a r ↔ ‖b‖ ≤ r := by rw [mem_closedBall_iff_norm'', mul_div_cancel_left] @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_ball (a b : E) (r : ℝ) : (b * ·) ⁻¹' ball a r = ball (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_ball, div_div_eq_mul_div, mul_comm] @[to_additive (attr := simp 1001)] -- Porting note: increase priority so that the left-hand side doesn't simplify theorem preimage_mul_closedBall (a b : E) (r : ℝ) : (b * ·) ⁻¹' closedBall a r = closedBall (a / b) r := by ext c simp only [dist_eq_norm_div, Set.mem_preimage, mem_closedBall, div_div_eq_mul_div, mul_comm] @[to_additive (attr := simp)] theorem preimage_mul_sphere (a b : E) (r : ℝ) : (b * ·) ⁻¹' sphere a r = sphere (a / b) r := by ext c simp only [Set.mem_preimage, mem_sphere_iff_norm', div_div_eq_mul_div, mul_comm] @[to_additive] theorem pow_mem_closedBall {n : ℕ} (h : a ∈ closedBall b r) : a ^ n ∈ closedBall (b ^ n) (n • r) := by simp only [mem_closedBall, dist_eq_norm_div, ← div_pow] at h ⊢ refine norm_pow_le_mul_norm.trans ?_ simpa only [nsmul_eq_mul] using mul_le_mul_of_nonneg_left h n.cast_nonneg @[to_additive] theorem pow_mem_ball {n : ℕ} (hn : 0 < n) (h : a ∈ ball b r) : a ^ n ∈ ball (b ^ n) (n • r) := by simp only [mem_ball, dist_eq_norm_div, ← div_pow] at h ⊢ refine lt_of_le_of_lt norm_pow_le_mul_norm ?_ replace hn : 0 < (n : ℝ) := by norm_cast rw [nsmul_eq_mul] nlinarith @[to_additive] theorem mul_mem_closedBall_mul_iff {c : E} : a * c ∈ closedBall (b * c) r ↔ a ∈ closedBall b r := by simp only [mem_closedBall, dist_eq_norm_div, mul_div_mul_right_eq_div] @[to_additive] theorem mul_mem_ball_mul_iff {c : E} : a * c ∈ ball (b * c) r ↔ a ∈ ball b r := by simp only [mem_ball, dist_eq_norm_div, mul_div_mul_right_eq_div] @[to_additive] theorem smul_closedBall'' : a • closedBall b r = closedBall (a • b) r := by ext simp [mem_closedBall, Set.mem_smul_set, dist_eq_norm_div, div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] @[to_additive] theorem smul_ball'' : a • ball b r = ball (a • b) r := by ext simp [mem_ball, Set.mem_smul_set, dist_eq_norm_div, _root_.div_eq_inv_mul, ← eq_inv_mul_iff_mul_eq, mul_assoc] @[to_additive] theorem nnnorm_multiset_prod_le (m : Multiset E) : ‖m.prod‖₊ ≤ (m.map fun x => ‖x‖₊).sum := NNReal.coe_le_coe.1 <| by push_cast rw [Multiset.map_map] exact norm_multiset_prod_le _ @[to_additive] theorem nnnorm_prod_le (s : Finset ι) (f : ι → E) : ‖∏ a ∈ s, f a‖₊ ≤ ∑ a ∈ s, ‖f a‖₊ := NNReal.coe_le_coe.1 <| by push_cast exact norm_prod_le _ _ @[to_additive] theorem nnnorm_prod_le_of_le (s : Finset ι) {f : ι → E} {n : ι → ℝ≥0} (h : ∀ b ∈ s, ‖f b‖₊ ≤ n b) : ‖∏ b ∈ s, f b‖₊ ≤ ∑ b ∈ s, n b := (norm_prod_le_of_le s h).trans_eq (NNReal.coe_sum ..).symm -- Porting note: increase priority so that the LHS doesn't simplify @[to_additive (attr := simp 1001) norm_norm] lemma norm_norm' (x : E) : ‖‖x‖‖ = ‖x‖ := Real.norm_of_nonneg (norm_nonneg' _) @[to_additive (attr := simp) nnnorm_norm] lemma nnnorm_norm' (x : E) : ‖‖x‖‖₊ = ‖x‖₊ := by simp [nnnorm] @[to_additive (attr := simp) enorm_norm] lemma enorm_norm' (x : E) : ‖‖x‖‖ₑ = ‖x‖ₑ := by simp [enorm] lemma enorm_enorm {ε : Type*} [ENorm ε] (x : ε) : ‖‖x‖ₑ‖ₑ = ‖x‖ₑ := by simp [enorm] end SeminormedCommGroup section NormedGroup variable [NormedGroup E] {a b : E} @[to_additive (attr := simp) norm_le_zero_iff] lemma norm_le_zero_iff' : ‖a‖ ≤ 0 ↔ a = 1 := by rw [← dist_one_right, dist_le_zero] @[to_additive (attr := simp) norm_pos_iff] lemma norm_pos_iff' : 0 < ‖a‖ ↔ a ≠ 1 := by rw [← not_le, norm_le_zero_iff'] @[to_additive (attr := simp) norm_eq_zero] lemma norm_eq_zero' : ‖a‖ = 0 ↔ a = 1 := (norm_nonneg' a).le_iff_eq.symm.trans norm_le_zero_iff' @[to_additive norm_ne_zero_iff] lemma norm_ne_zero_iff' : ‖a‖ ≠ 0 ↔ a ≠ 1 := norm_eq_zero'.not @[deprecated (since := "2024-11-24")] alias norm_le_zero_iff'' := norm_le_zero_iff' @[deprecated (since := "2024-11-24")] alias norm_le_zero_iff''' := norm_le_zero_iff' @[deprecated (since := "2024-11-24")] alias norm_pos_iff'' := norm_pos_iff' @[deprecated (since := "2024-11-24")] alias norm_eq_zero'' := norm_eq_zero' @[deprecated (since := "2024-11-24")] alias norm_eq_zero''' := norm_eq_zero' @[to_additive] theorem norm_div_eq_zero_iff : ‖a / b‖ = 0 ↔ a = b := by rw [norm_eq_zero', div_eq_one] @[to_additive] theorem norm_div_pos_iff : 0 < ‖a / b‖ ↔ a ≠ b := by rw [(norm_nonneg' _).lt_iff_ne, ne_comm] exact norm_div_eq_zero_iff.not @[to_additive eq_of_norm_sub_le_zero] theorem eq_of_norm_div_le_zero (h : ‖a / b‖ ≤ 0) : a = b := by rwa [← div_eq_one, ← norm_le_zero_iff'] alias ⟨eq_of_norm_div_eq_zero, _⟩ := norm_div_eq_zero_iff attribute [to_additive] eq_of_norm_div_eq_zero @[to_additive] theorem eq_one_or_norm_pos (a : E) : a = 1 ∨ 0 < ‖a‖ := by simpa [eq_comm] using (norm_nonneg' a).eq_or_lt @[to_additive] theorem eq_one_or_nnnorm_pos (a : E) : a = 1 ∨ 0 < ‖a‖₊ := eq_one_or_norm_pos a @[to_additive (attr := simp) nnnorm_eq_zero] theorem nnnorm_eq_zero' : ‖a‖₊ = 0 ↔ a = 1 := by rw [← NNReal.coe_eq_zero, coe_nnnorm', norm_eq_zero'] @[to_additive nnnorm_ne_zero_iff] theorem nnnorm_ne_zero_iff' : ‖a‖₊ ≠ 0 ↔ a ≠ 1 := nnnorm_eq_zero'.not @[to_additive (attr := simp) nnnorm_pos] lemma nnnorm_pos' : 0 < ‖a‖₊ ↔ a ≠ 1 := pos_iff_ne_zero.trans nnnorm_ne_zero_iff' variable (E) /-- The norm of a normed group as a group norm. -/ @[to_additive "The norm of a normed group as an additive group norm."] def normGroupNorm : GroupNorm E := { normGroupSeminorm _ with eq_one_of_map_eq_zero' := fun _ => norm_eq_zero'.1 } @[simp] theorem coe_normGroupNorm : ⇑(normGroupNorm E) = norm := rfl end NormedGroup section NormedAddGroup variable [NormedAddGroup E] [TopologicalSpace α] {f : α → E} /-! Some relations with `HasCompactSupport` -/ theorem hasCompactSupport_norm_iff : (HasCompactSupport fun x => ‖f x‖) ↔ HasCompactSupport f := hasCompactSupport_comp_left norm_eq_zero alias ⟨_, HasCompactSupport.norm⟩ := hasCompactSupport_norm_iff end NormedAddGroup lemma tendsto_norm_atTop_atTop : Tendsto (norm : ℝ → ℝ) atTop atTop := tendsto_abs_atTop_atTop /-! ### `positivity` extensions -/ namespace Mathlib.Meta.Positivity open Lean Meta Qq Function /-- Extension for the `positivity` tactic: multiplicative norms are always nonnegative, and positive on non-one inputs. -/ @[positivity ‖_‖] def evalMulNorm : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $E $_n $a) => let _seminormedGroup_E ← synthInstanceQ q(SeminormedGroup $E) assertInstancesCommute -- Check whether we are in a normed group and whether the context contains a `a ≠ 1` assumption let o : Option (Q(NormedGroup $E) × Q($a ≠ 1)) := ← do let .some normedGroup_E ← trySynthInstanceQ q(NormedGroup $E) | return none let some pa ← findLocalDeclWithTypeQ? q($a ≠ 1) | return none return some (normedGroup_E, pa) match o with -- If so, return a proof of `0 < ‖a‖` | some (_normedGroup_E, pa) => assertInstancesCommute return .positive q(norm_pos_iff'.2 $pa) -- Else, return a proof of `0 ≤ ‖a‖` | none => return .nonnegative q(norm_nonneg' $a) | _, _, _ => throwError "not `‖·‖`" /-- Extension for the `positivity` tactic: additive norms are always nonnegative, and positive on non-zero inputs. -/ @[positivity ‖_‖] def evalAddNorm : PositivityExt where eval {u α} _ _ e := do match u, α, e with | 0, ~q(ℝ), ~q(@Norm.norm $E $_n $a) => let _seminormedAddGroup_E ← synthInstanceQ q(SeminormedAddGroup $E) assertInstancesCommute -- Check whether we are in a normed group and whether the context contains a `a ≠ 0` assumption let o : Option (Q(NormedAddGroup $E) × Q($a ≠ 0)) := ← do let .some normedAddGroup_E ← trySynthInstanceQ q(NormedAddGroup $E) | return none let some pa ← findLocalDeclWithTypeQ? q($a ≠ 0) | return none return some (normedAddGroup_E, pa) match o with -- If so, return a proof of `0 < ‖a‖` | some (_normedAddGroup_E, pa) => assertInstancesCommute return .positive q(norm_pos_iff.2 $pa) -- Else, return a proof of `0 ≤ ‖a‖` | none => return .nonnegative q(norm_nonneg $a) | _, _, _ => throwError "not `‖·‖`" end Mathlib.Meta.Positivity
Mathlib/Analysis/Normed/Group/Basic.lean
1,549
1,549
/- Copyright (c) 2022 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.MeasureTheory.Function.StronglyMeasurable.Basic /-! # Egorov theorem This file contains the Egorov theorem which states that an almost everywhere convergent sequence on a finite measure space converges uniformly except on an arbitrarily small set. This theorem is useful for the Vitali convergence theorem as well as theorems regarding convergence in measure. ## Main results * `MeasureTheory.tendstoUniformlyOn_of_ae_tendsto`: Egorov's theorem which shows that a sequence of almost everywhere convergent functions converges uniformly except on an arbitrarily small set. -/ noncomputable section open MeasureTheory NNReal ENNReal Topology namespace MeasureTheory open Set Filter TopologicalSpace variable {α β ι : Type*} {m : MeasurableSpace α} [MetricSpace β] {μ : Measure α} namespace Egorov /-- Given a sequence of functions `f` and a function `g`, `notConvergentSeq f g n j` is the set of elements such that `f k x` and `g x` are separated by at least `1 / (n + 1)` for some `k ≥ j`. This definition is useful for Egorov's theorem. -/ def notConvergentSeq [Preorder ι] (f : ι → α → β) (g : α → β) (n : ℕ) (j : ι) : Set α := ⋃ (k) (_ : j ≤ k), { x | 1 / (n + 1 : ℝ) < dist (f k x) (g x) } variable {n : ℕ} {j : ι} {s : Set α} {ε : ℝ} {f : ι → α → β} {g : α → β} theorem mem_notConvergentSeq_iff [Preorder ι] {x : α} : x ∈ notConvergentSeq f g n j ↔ ∃ k ≥ j, 1 / (n + 1 : ℝ) < dist (f k x) (g x) := by simp_rw [notConvergentSeq, Set.mem_iUnion, exists_prop, mem_setOf] theorem notConvergentSeq_antitone [Preorder ι] : Antitone (notConvergentSeq f g n) := fun _ _ hjk => Set.iUnion₂_mono' fun l hl => ⟨l, le_trans hjk hl, Set.Subset.rfl⟩ theorem measure_inter_notConvergentSeq_eq_zero [SemilatticeSup ι] [Nonempty ι] (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) (n : ℕ) : μ (s ∩ ⋂ j, notConvergentSeq f g n j) = 0 := by simp_rw [Metric.tendsto_atTop, ae_iff] at hfg rw [← nonpos_iff_eq_zero, ← hfg] refine measure_mono fun x => ?_ simp only [Set.mem_inter_iff, Set.mem_iInter, mem_notConvergentSeq_iff] push_neg rintro ⟨hmem, hx⟩ refine ⟨hmem, 1 / (n + 1 : ℝ), Nat.one_div_pos_of_nat, fun N => ?_⟩ obtain ⟨n, hn₁, hn₂⟩ := hx N exact ⟨n, hn₁, hn₂.le⟩ theorem notConvergentSeq_measurableSet [Preorder ι] [Countable ι] (hf : ∀ n, StronglyMeasurable[m] (f n)) (hg : StronglyMeasurable g) : MeasurableSet (notConvergentSeq f g n j) := MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun _ => StronglyMeasurable.measurableSet_lt stronglyMeasurable_const <| (hf k).dist hg theorem measure_notConvergentSeq_tendsto_zero [SemilatticeSup ι] [Countable ι] (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) (n : ℕ) : Tendsto (fun j => μ (s ∩ notConvergentSeq f g n j)) atTop (𝓝 0) := by rcases isEmpty_or_nonempty ι with h | h · have : (fun j => μ (s ∩ notConvergentSeq f g n j)) = fun j => 0 := by simp only [eq_iff_true_of_subsingleton] rw [this] exact tendsto_const_nhds rw [← measure_inter_notConvergentSeq_eq_zero hfg n, Set.inter_iInter] refine tendsto_measure_iInter_atTop (fun n ↦ (hsm.inter <| notConvergentSeq_measurableSet hf hg).nullMeasurableSet) (fun k l hkl => Set.inter_subset_inter_right _ <| notConvergentSeq_antitone hkl) ⟨h.some, ne_top_of_le_ne_top hs (measure_mono Set.inter_subset_left)⟩ variable [SemilatticeSup ι] [Nonempty ι] [Countable ι] theorem exists_notConvergentSeq_lt (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) (n : ℕ) : ∃ j : ι, μ (s ∩ notConvergentSeq f g n j) ≤ ENNReal.ofReal (ε * 2⁻¹ ^ n) := by have ⟨N, hN⟩ := (ENNReal.tendsto_atTop ENNReal.zero_ne_top).1 (measure_notConvergentSeq_tendsto_zero hf hg hsm hs hfg n) (ENNReal.ofReal (ε * 2⁻¹ ^ n)) (by rw [gt_iff_lt, ENNReal.ofReal_pos] exact mul_pos hε (pow_pos (by norm_num) n)) rw [zero_add] at hN exact ⟨N, (hN N le_rfl).2⟩ /-- Given some `ε > 0`, `notConvergentSeqLTIndex` provides the index such that `notConvergentSeq` (intersected with a set of finite measure) has measure less than `ε * 2⁻¹ ^ n`. This definition is useful for Egorov's theorem. -/ def notConvergentSeqLTIndex (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) (n : ℕ) : ι := Classical.choose <| exists_notConvergentSeq_lt hε hf hg hsm hs hfg n theorem notConvergentSeqLTIndex_spec (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) (n : ℕ) : μ (s ∩ notConvergentSeq f g n (notConvergentSeqLTIndex hε hf hg hsm hs hfg n)) ≤ ENNReal.ofReal (ε * 2⁻¹ ^ n) := Classical.choose_spec <| exists_notConvergentSeq_lt hε hf hg hsm hs hfg n /-- Given some `ε > 0`, `iUnionNotConvergentSeq` is the union of `notConvergentSeq` with specific indices such that `iUnionNotConvergentSeq` has measure less equal than `ε`. This definition is useful for Egorov's theorem. -/ def iUnionNotConvergentSeq (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) : Set α := ⋃ n, s ∩ notConvergentSeq f g n (notConvergentSeqLTIndex (half_pos hε) hf hg hsm hs hfg n) theorem iUnionNotConvergentSeq_measurableSet (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) : MeasurableSet <| iUnionNotConvergentSeq hε hf hg hsm hs hfg := MeasurableSet.iUnion fun _ => hsm.inter <| notConvergentSeq_measurableSet hf hg theorem measure_iUnionNotConvergentSeq (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) : μ (iUnionNotConvergentSeq hε hf hg hsm hs hfg) ≤ ENNReal.ofReal ε := by refine le_trans (measure_iUnion_le _) (le_trans (ENNReal.tsum_le_tsum <| notConvergentSeqLTIndex_spec (half_pos hε) hf hg hsm hs hfg) ?_) simp_rw [ENNReal.ofReal_mul (half_pos hε).le] rw [ENNReal.tsum_mul_left, ← ENNReal.ofReal_tsum_of_nonneg, inv_eq_one_div, tsum_geometric_two, ← ENNReal.ofReal_mul (half_pos hε).le, div_mul_cancel₀ ε two_ne_zero] · intro n; positivity · rw [inv_eq_one_div] exact summable_geometric_two theorem iUnionNotConvergentSeq_subset (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) : iUnionNotConvergentSeq hε hf hg hsm hs hfg ⊆ s := by rw [iUnionNotConvergentSeq, ← Set.inter_iUnion] exact Set.inter_subset_left theorem tendstoUniformlyOn_diff_iUnionNotConvergentSeq (hε : 0 < ε) (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞) (hfg : ∀ᵐ x ∂μ, x ∈ s → Tendsto (fun n => f n x) atTop (𝓝 (g x))) : TendstoUniformlyOn f g atTop (s \ Egorov.iUnionNotConvergentSeq hε hf hg hsm hs hfg) := by rw [Metric.tendstoUniformlyOn_iff] intro δ hδ obtain ⟨N, hN⟩ := exists_nat_one_div_lt hδ rw [eventually_atTop] refine ⟨Egorov.notConvergentSeqLTIndex (half_pos hε) hf hg hsm hs hfg N, fun n hn x hx => ?_⟩ simp only [Set.mem_diff, Egorov.iUnionNotConvergentSeq, not_exists, Set.mem_iUnion, Set.mem_inter_iff, not_and, exists_and_left] at hx obtain ⟨hxs, hx⟩ := hx specialize hx hxs N rw [Egorov.mem_notConvergentSeq_iff] at hx push_neg at hx
rw [dist_comm] exact lt_of_le_of_lt (hx n hn) hN end Egorov variable [SemilatticeSup ι] [Nonempty ι] [Countable ι] {f : ι → α → β} {g : α → β} {s : Set α} /-- **Egorov's theorem**: If `f : ι → α → β` is a sequence of strongly measurable functions that converges to `g : α → β` almost everywhere on a measurable set `s` of finite measure, then for all `ε > 0`, there exists a subset `t ⊆ s` such that `μ t ≤ ε` and `f` converges to `g` uniformly on `s \ t`. We require the index type `ι` to be countable, and usually `ι = ℕ`. In other words, a sequence of almost everywhere convergent functions converges uniformly except on an arbitrarily small set. -/ theorem tendstoUniformlyOn_of_ae_tendsto (hf : ∀ n, StronglyMeasurable (f n)) (hg : StronglyMeasurable g) (hsm : MeasurableSet s) (hs : μ s ≠ ∞)
Mathlib/MeasureTheory/Function/Egorov.lean
168
184
/- Copyright (c) 2021 François Sunatori. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: François Sunatori -/ import Mathlib.Analysis.Complex.Circle import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup.Basic /-! # Isometries of the Complex Plane The lemma `linear_isometry_complex` states the classification of isometries in the complex plane. Specifically, isometries with rotations but without translation. The proof involves: 1. creating a linear isometry `g` with two fixed points, `g(0) = 0`, `g(1) = 1` 2. applying `linear_isometry_complex_aux` to `g` The proof of `linear_isometry_complex_aux` is separated in the following parts: 1. show that the real parts match up: `LinearIsometry.re_apply_eq_re` 2. show that I maps to either I or -I 3. every z is a linear combination of a + b * I ## References * [Isometries of the Complex Plane](http://helmut.knaust.info/mediawiki/images/b/b5/Iso.pdf) -/ noncomputable section open Complex open CharZero open ComplexConjugate local notation "|" x "|" => Complex.abs x /-- An element of the unit circle defines a `LinearIsometryEquiv` from `ℂ` to itself, by rotation. -/ def rotation : Circle →* ℂ ≃ₗᵢ[ℝ] ℂ where toFun a := { DistribMulAction.toLinearEquiv ℝ ℂ a with norm_map' x := show ‖a * x‖ = ‖x‖ by rw [norm_mul, Circle.norm_coe, one_mul] } map_one' := LinearIsometryEquiv.ext <| by simp map_mul' a b := LinearIsometryEquiv.ext <| mul_smul a b @[simp] theorem rotation_apply (a : Circle) (z : ℂ) : rotation a z = a * z := rfl @[simp] theorem rotation_symm (a : Circle) : (rotation a).symm = rotation a⁻¹ := LinearIsometryEquiv.ext fun _ => rfl @[simp] theorem rotation_trans (a b : Circle) : (rotation a).trans (rotation b) = rotation (b * a) := by ext1 simp theorem rotation_ne_conjLIE (a : Circle) : rotation a ≠ conjLIE := by intro h have h1 : rotation a 1 = conj 1 := LinearIsometryEquiv.congr_fun h 1 have hI : rotation a I = conj I := LinearIsometryEquiv.congr_fun h I rw [rotation_apply, RingHom.map_one, mul_one] at h1 rw [rotation_apply, conj_I, ← neg_one_mul, mul_left_inj' I_ne_zero, h1, eq_neg_self_iff] at hI exact one_ne_zero hI /-- Takes an element of `ℂ ≃ₗᵢ[ℝ] ℂ` and checks if it is a rotation, returns an element of the unit circle. -/ @[simps] def rotationOf (e : ℂ ≃ₗᵢ[ℝ] ℂ) : Circle := ⟨e 1 / ‖e 1‖, by simp [Submonoid.unitSphere]⟩ @[simp] theorem rotationOf_rotation (a : Circle) : rotationOf (rotation a) = a := Subtype.ext <| by simp theorem rotation_injective : Function.Injective rotation := Function.LeftInverse.injective rotationOf_rotation theorem LinearIsometry.re_apply_eq_re_of_add_conj_eq (f : ℂ →ₗᵢ[ℝ] ℂ) (h₃ : ∀ z, z + conj z = f z + conj (f z)) (z : ℂ) : (f z).re = z.re := by simpa [Complex.ext_iff, add_re, add_im, conj_re, conj_im, ← two_mul, show (2 : ℝ) ≠ 0 by simp [two_ne_zero]] using (h₃ z).symm theorem LinearIsometry.im_apply_eq_im_or_neg_of_re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h₂ : ∀ z, (f z).re = z.re) (z : ℂ) : (f z).im = z.im ∨ (f z).im = -z.im := by have h₁ := f.norm_map z simp only [norm_def] at h₁ rwa [Real.sqrt_inj (normSq_nonneg _) (normSq_nonneg _), normSq_apply (f z), normSq_apply z, h₂, add_left_cancel_iff, mul_self_eq_mul_self_iff] at h₁ theorem LinearIsometry.im_apply_eq_im {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : z + conj z = f z + conj (f z) := by have : ‖f z - 1‖ = ‖z - 1‖ := by rw [← f.norm_map (z - 1), f.map_sub, h] apply_fun fun x => x ^ 2 at this simp only [← normSq_eq_norm_sq] at this rw [← ofReal_inj, ← mul_conj, ← mul_conj] at this rw [RingHom.map_sub, RingHom.map_sub] at this simp only [sub_mul, mul_sub, one_mul, mul_one] at this rw [mul_conj, normSq_eq_norm_sq, LinearIsometry.norm_map] at this rw [mul_conj, normSq_eq_norm_sq] at this simp only [sub_sub, sub_right_inj, mul_one, ofReal_pow, RingHom.map_one] at this simp only [add_sub, sub_left_inj] at this rw [add_comm, ← this, add_comm] theorem LinearIsometry.re_apply_eq_re {f : ℂ →ₗᵢ[ℝ] ℂ} (h : f 1 = 1) (z : ℂ) : (f z).re = z.re := by apply LinearIsometry.re_apply_eq_re_of_add_conj_eq intro z apply LinearIsometry.im_apply_eq_im h theorem linear_isometry_complex_aux {f : ℂ ≃ₗᵢ[ℝ] ℂ} (h : f 1 = 1) : f = LinearIsometryEquiv.refl ℝ ℂ ∨ f = conjLIE := by have h0 : f I = I ∨ f I = -I := by simp only [Complex.ext_iff, ← and_or_left, neg_re, I_re, neg_im, neg_zero] constructor · rw [← I_re] exact @LinearIsometry.re_apply_eq_re f.toLinearIsometry h I · apply @LinearIsometry.im_apply_eq_im_or_neg_of_re_apply_eq_re f.toLinearIsometry intro z rw [@LinearIsometry.re_apply_eq_re f.toLinearIsometry h] refine h0.imp (fun h' : f I = I => ?_) fun h' : f I = -I => ?_ <;>
· apply LinearIsometryEquiv.toLinearEquiv_injective apply Complex.basisOneI.ext' intro i fin_cases i <;> simp [h, h'] theorem linear_isometry_complex (f : ℂ ≃ₗᵢ[ℝ] ℂ) : ∃ a : Circle, f = rotation a ∨ f = conjLIE.trans (rotation a) := by let a : Circle := ⟨f 1, by simp [Submonoid.unitSphere, f.norm_map]⟩ use a have : (f.trans (rotation a).symm) 1 = 1 := by simpa [a] using rotation_apply a⁻¹ (f 1) refine (linear_isometry_complex_aux this).imp (fun h₁ => ?_) fun h₂ => ?_ · simpa using eq_mul_of_inv_mul_eq h₁ · exact eq_mul_of_inv_mul_eq h₂ /-- The matrix representation of `rotation a` is equal to the conformal matrix
Mathlib/Analysis/Complex/Isometry.lean
125
139
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Manuel Candales -/ import Mathlib.Analysis.Convex.Between import Mathlib.Analysis.Normed.Group.AddTorsor import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic import Mathlib.Analysis.Normed.Affine.Isometry /-! # Angles between points This file defines unoriented angles in Euclidean affine spaces. ## Main definitions * `EuclideanGeometry.angle`, with notation `∠`, is the undirected angle determined by three points. ## TODO Prove the triangle inequality for the angle. -/ noncomputable section open Real RealInnerProductSpace namespace EuclideanGeometry open InnerProductGeometry variable {V P : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] [MetricSpace P] [NormedAddTorsor V P] {p p₀ : P} /-- The undirected angle at `p₂` between the line segments to `p₁` and `p₃`. If either of those points equals `p₂`, this is π/2. Use `open scoped EuclideanGeometry` to access the `∠ p₁ p₂ p₃` notation. -/ nonrec def angle (p₁ p₂ p₃ : P) : ℝ := angle (p₁ -ᵥ p₂ : V) (p₃ -ᵥ p₂) @[inherit_doc] scoped notation "∠" => EuclideanGeometry.angle theorem continuousAt_angle {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 let f : P × P × P → V × V := fun y => (y.1 -ᵥ y.2.1, y.2.2 -ᵥ y.2.1) have hf1 : (f x).1 ≠ 0 := by simp [f, hx12] have hf2 : (f x).2 ≠ 0 := by simp [f, hx32] exact (InnerProductGeometry.continuousAt_angle hf1 hf2).comp (by fun_prop) @[simp] theorem _root_.AffineIsometry.angle_map {V₂ P₂ : Type*} [NormedAddCommGroup V₂] [InnerProductSpace ℝ V₂] [MetricSpace P₂] [NormedAddTorsor V₂ P₂] (f : P →ᵃⁱ[ℝ] P₂) (p₁ p₂ p₃ : P) : ∠ (f p₁) (f p₂) (f p₃) = ∠ p₁ p₂ p₃ := by simp_rw [angle, ← AffineIsometry.map_vsub, LinearIsometry.angle_map] @[simp, norm_cast] theorem _root_.AffineSubspace.angle_coe {s : AffineSubspace ℝ P} (p₁ p₂ p₃ : s) : haveI : Nonempty s := ⟨p₁⟩ ∠ (p₁ : P) (p₂ : P) (p₃ : P) = ∠ p₁ p₂ p₃ := haveI : Nonempty s := ⟨p₁⟩ s.subtypeₐᵢ.angle_map p₁ p₂ p₃ /-- Angles are translation invariant -/ @[simp] theorem angle_const_vadd (v : V) (p₁ p₂ p₃ : P) : ∠ (v +ᵥ p₁) (v +ᵥ p₂) (v +ᵥ p₃) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.constVAdd ℝ P v).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_vadd_const (v₁ v₂ v₃ : V) (p : P) : ∠ (v₁ +ᵥ p) (v₂ +ᵥ p) (v₃ +ᵥ p) = ∠ v₁ v₂ v₃ := (AffineIsometryEquiv.vaddConst ℝ p).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_const_vsub (p p₁ p₂ p₃ : P) : ∠ (p -ᵥ p₁) (p -ᵥ p₂) (p -ᵥ p₃) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.constVSub ℝ p).toAffineIsometry.angle_map _ _ _ /-- Angles are translation invariant -/ @[simp] theorem angle_vsub_const (p₁ p₂ p₃ p : P) : ∠ (p₁ -ᵥ p) (p₂ -ᵥ p) (p₃ -ᵥ p) = ∠ p₁ p₂ p₃ := (AffineIsometryEquiv.vaddConst ℝ p).symm.toAffineIsometry.angle_map _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_add_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ + v) (v₂ + v) (v₃ + v) = ∠ v₁ v₂ v₃ := angle_vadd_const _ _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_const_add (v : V) (v₁ v₂ v₃ : V) : ∠ (v + v₁) (v + v₂) (v + v₃) = ∠ v₁ v₂ v₃ := angle_const_vadd _ _ _ _ /-- Angles in a vector space are translation invariant -/ @[simp] theorem angle_sub_const (v₁ v₂ v₃ : V) (v : V) : ∠ (v₁ - v) (v₂ - v) (v₃ - v) = ∠ v₁ v₂ v₃ := by simpa only [vsub_eq_sub] using angle_vsub_const v₁ v₂ v₃ v /-- Angles in a vector space are invariant to inversion -/ @[simp] theorem angle_const_sub (v : V) (v₁ v₂ v₃ : V) : ∠ (v - v₁) (v - v₂) (v - v₃) = ∠ v₁ v₂ v₃ := by simpa only [vsub_eq_sub] using angle_const_vsub v v₁ v₂ v₃ /-- Angles in a vector space are invariant to inversion -/ @[simp] theorem angle_neg (v₁ v₂ v₃ : V) : ∠ (-v₁) (-v₂) (-v₃) = ∠ v₁ v₂ v₃ := by simpa only [zero_sub] using angle_const_sub 0 v₁ v₂ v₃ /-- The angle at a point does not depend on the order of the other two points. -/ nonrec theorem angle_comm (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ = ∠ p₃ p₂ p₁ := angle_comm _ _ /-- The angle at a point is nonnegative. -/ nonrec theorem angle_nonneg (p₁ p₂ p₃ : P) : 0 ≤ ∠ p₁ p₂ p₃ := angle_nonneg _ _ /-- The angle at a point is at most π. -/ nonrec theorem angle_le_pi (p₁ p₂ p₃ : P) : ∠ p₁ p₂ p₃ ≤ π := angle_le_pi _ _ /-- The angle ∠AAB at a point is always `π / 2`. -/ @[simp] lemma angle_self_left (p₀ p : P) : ∠ p₀ p₀ p = π / 2 := by unfold angle rw [vsub_self] exact angle_zero_left _ /-- The angle ∠ABB at a point is always `π / 2`. -/ @[simp] lemma angle_self_right (p₀ p : P) : ∠ p p₀ p₀ = π / 2 := by rw [angle_comm, angle_self_left] /-- The angle ∠ABA at a point is `0`, unless `A = B`. -/ theorem angle_self_of_ne (h : p ≠ p₀) : ∠ p p₀ p = 0 := angle_self <| vsub_ne_zero.2 h /-- If the angle ∠ABC at a point is π, the angle ∠BAC is 0. -/ theorem angle_eq_zero_of_angle_eq_pi_left {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₁ p₃ = 0 := by unfold angle at h rw [angle_eq_pi_iff] at h rcases h with ⟨hp₁p₂, ⟨r, ⟨hr, hpr⟩⟩⟩ unfold angle rw [angle_eq_zero_iff] rw [← neg_vsub_eq_vsub_rev, neg_ne_zero] at hp₁p₂ use hp₁p₂, -r + 1, add_pos (neg_pos_of_neg hr) zero_lt_one rw [add_smul, ← neg_vsub_eq_vsub_rev p₁ p₂, smul_neg] simp [← hpr] /-- If the angle ∠ABC at a point is π, the angle ∠BCA is 0. -/ theorem angle_eq_zero_of_angle_eq_pi_right {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : ∠ p₂ p₃ p₁ = 0 := by rw [angle_comm] at h exact angle_eq_zero_of_angle_eq_pi_left h /-- If ∠BCD = π, then ∠ABC = ∠ABD. -/ theorem angle_eq_angle_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) : ∠ p₁ p₂ p₃ = ∠ p₁ p₂ p₄ := by unfold angle at * rcases angle_eq_pi_iff.1 h with ⟨_, ⟨r, ⟨hr, hpr⟩⟩⟩ rw [eq_comm] convert angle_smul_right_of_pos (p₁ -ᵥ p₂) (p₃ -ᵥ p₂) (add_pos (neg_pos_of_neg hr) zero_lt_one) rw [add_smul, ← neg_vsub_eq_vsub_rev p₂ p₃, smul_neg, neg_smul, ← hpr] simp /-- If ∠BCD = π, then ∠ACB + ∠ACD = π. -/ nonrec theorem angle_add_angle_eq_pi_of_angle_eq_pi (p₁ : P) {p₂ p₃ p₄ : P} (h : ∠ p₂ p₃ p₄ = π) : ∠ p₁ p₃ p₂ + ∠ p₁ p₃ p₄ = π := by unfold angle at h rw [angle_comm p₁ p₃ p₂, angle_comm p₁ p₃ p₄] unfold angle exact angle_add_angle_eq_pi_of_angle_eq_pi _ h /-- **Vertical Angles Theorem**: angles opposite each other, formed by two intersecting straight lines, are equal. -/ theorem angle_eq_angle_of_angle_eq_pi_of_angle_eq_pi {p₁ p₂ p₃ p₄ p₅ : P} (hapc : ∠ p₁ p₅ p₃ = π) (hbpd : ∠ p₂ p₅ p₄ = π) : ∠ p₁ p₅ p₂ = ∠ p₃ p₅ p₄ := by linarith [angle_add_angle_eq_pi_of_angle_eq_pi p₁ hbpd, angle_comm p₄ p₅ p₁, angle_add_angle_eq_pi_of_angle_eq_pi p₄ hapc, angle_comm p₄ p₅ p₃] /-- If ∠ABC = π then dist A B ≠ 0. -/ theorem left_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₂ ≠ 0 := by by_contra heq rw [dist_eq_zero] at heq rw [heq, angle_self_left] at h exact Real.pi_ne_zero (by linarith) /-- If ∠ABC = π then dist C B ≠ 0. -/ theorem right_dist_ne_zero_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₃ p₂ ≠ 0 := left_dist_ne_zero_of_angle_eq_pi <| (angle_comm _ _ _).trans h /-- If ∠ABC = π, then (dist A C) = (dist A B) + (dist B C). -/ theorem dist_eq_add_dist_of_angle_eq_pi {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = π) : dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_add_norm_of_angle_eq_pi h /-- If A ≠ B and C ≠ B then ∠ABC = π if and only if (dist A C) = (dist A B) + (dist B C). -/ theorem dist_eq_add_dist_iff_angle_eq_pi {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) : dist p₁ p₃ = dist p₁ p₂ + dist p₃ p₂ ↔ ∠ p₁ p₂ p₃ = π := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_add_norm_iff_angle_eq_pi (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he)) fun he => hp₃p₂ (vsub_eq_zero_iff_eq.1 he) /-- If ∠ABC = 0, then (dist A C) = abs ((dist A B) - (dist B C)). -/ theorem dist_eq_abs_sub_dist_of_angle_eq_zero {p₁ p₂ p₃ : P} (h : ∠ p₁ p₂ p₃ = 0) : dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_abs_sub_norm_of_angle_eq_zero h /-- If A ≠ B and C ≠ B then ∠ABC = 0 if and only if (dist A C) = abs ((dist A B) - (dist B C)). -/ theorem dist_eq_abs_sub_dist_iff_angle_eq_zero {p₁ p₂ p₃ : P} (hp₁p₂ : p₁ ≠ p₂) (hp₃p₂ : p₃ ≠ p₂) : dist p₁ p₃ = |dist p₁ p₂ - dist p₃ p₂| ↔ ∠ p₁ p₂ p₃ = 0 := by rw [dist_eq_norm_vsub V, dist_eq_norm_vsub V, dist_eq_norm_vsub V, ← vsub_sub_vsub_cancel_right] exact norm_sub_eq_abs_sub_norm_iff_angle_eq_zero (fun he => hp₁p₂ (vsub_eq_zero_iff_eq.1 he)) fun he => hp₃p₂ (vsub_eq_zero_iff_eq.1 he) /-- If M is the midpoint of the segment AB, then ∠AMB = π. -/ theorem angle_midpoint_eq_pi (p₁ p₂ : P) (hp₁p₂ : p₁ ≠ p₂) : ∠ p₁ (midpoint ℝ p₁ p₂) p₂ = π := by simp only [angle, left_vsub_midpoint, invOf_eq_inv, right_vsub_midpoint, inv_pos, zero_lt_two, angle_smul_right_of_pos, angle_smul_left_of_pos] rw [← neg_vsub_eq_vsub_rev p₁ p₂] apply angle_self_neg_of_nonzero simpa only [ne_eq, vsub_eq_zero_iff_eq] /-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B then ∠CMA = π / 2. -/ theorem angle_left_midpoint_eq_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₃ p₁ = dist p₃ p₂) : ∠ p₃ (midpoint ℝ p₁ p₂) p₁ = π / 2 := by let m : P := midpoint ℝ p₁ p₂ have h1 : p₃ -ᵥ p₁ = p₃ -ᵥ m - (p₁ -ᵥ m) := (vsub_sub_vsub_cancel_right p₃ p₁ m).symm have h2 : p₃ -ᵥ p₂ = p₃ -ᵥ m + (p₁ -ᵥ m) := by rw [left_vsub_midpoint, ← midpoint_vsub_right, vsub_add_vsub_cancel] rw [dist_eq_norm_vsub V p₃ p₁, dist_eq_norm_vsub V p₃ p₂, h1, h2] at h exact (norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (p₃ -ᵥ m) (p₁ -ᵥ m)).mp h.symm /-- If M is the midpoint of the segment AB and C is the same distance from A as it is from B then ∠CMB = π / 2. -/ theorem angle_right_midpoint_eq_pi_div_two_of_dist_eq {p₁ p₂ p₃ : P} (h : dist p₃ p₁ = dist p₃ p₂) : ∠ p₃ (midpoint ℝ p₁ p₂) p₂ = π / 2 := by rw [midpoint_comm p₁ p₂, angle_left_midpoint_eq_pi_div_two_of_dist_eq h.symm] /-- If the second of three points is strictly between the other two, the angle at that point is π. -/ theorem _root_.Sbtw.angle₁₂₃_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₁ p₂ p₃ = π := by rw [angle, angle_eq_pi_iff] rcases h with ⟨⟨r, ⟨hr0, hr1⟩, hp₂⟩, hp₂p₁, hp₂p₃⟩ refine ⟨vsub_ne_zero.2 hp₂p₁.symm, -(1 - r) / r, ?_⟩ have hr0' : r ≠ 0 := by rintro rfl rw [← hp₂] at hp₂p₁ simp at hp₂p₁ have hr1' : r ≠ 1 := by rintro rfl rw [← hp₂] at hp₂p₃ simp at hp₂p₃ replace hr0 := hr0.lt_of_ne hr0'.symm replace hr1 := hr1.lt_of_ne hr1' refine ⟨div_neg_of_neg_of_pos (Left.neg_neg_iff.2 (sub_pos.2 hr1)) hr0, ?_⟩ rw [← hp₂, AffineMap.lineMap_apply, vsub_vadd_eq_vsub_sub, vsub_vadd_eq_vsub_sub, vsub_self, zero_sub, smul_neg, smul_smul, div_mul_cancel₀ _ hr0', neg_smul, neg_neg, sub_eq_iff_eq_add, ← add_smul, sub_add_cancel, one_smul] /-- If the second of three points is strictly between the other two, the angle at that point (reversed) is π. -/ theorem _root_.Sbtw.angle₃₂₁_eq_pi {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₃ p₂ p₁ = π := by rw [← h.angle₁₂₃_eq_pi, angle_comm] /-- The angle between three points is π if and only if the second point is strictly between the other two. -/ theorem angle_eq_pi_iff_sbtw {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = π ↔ Sbtw ℝ p₁ p₂ p₃ := by refine ⟨?_, fun h => h.angle₁₂₃_eq_pi⟩ rw [angle, angle_eq_pi_iff] rintro ⟨hp₁p₂, r, hr, hp₃p₂⟩ refine ⟨⟨1 / (1 - r), ⟨div_nonneg zero_le_one (sub_nonneg.2 (hr.le.trans zero_le_one)), (div_le_one (sub_pos.2 (hr.trans zero_lt_one))).2 ((le_sub_self_iff 1).2 hr.le)⟩, ?_⟩, (vsub_ne_zero.1 hp₁p₂).symm, ?_⟩ · rw [← eq_vadd_iff_vsub_eq] at hp₃p₂ rw [AffineMap.lineMap_apply, hp₃p₂, vadd_vsub_assoc, ← neg_vsub_eq_vsub_rev p₂ p₁, smul_neg, ← neg_smul, smul_add, smul_smul, ← add_smul, eq_comm, eq_vadd_iff_vsub_eq] convert (one_smul ℝ (p₂ -ᵥ p₁)).symm field_simp [(sub_pos.2 (hr.trans zero_lt_one)).ne.symm] ring · rw [ne_comm, ← @vsub_ne_zero V, hp₃p₂, smul_ne_zero_iff] exact ⟨hr.ne, hp₁p₂⟩ /-- If the second of three points is weakly between the other two, and not equal to the first, the angle at the first point is zero. -/ theorem _root_.Wbtw.angle₂₁₃_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₁ : p₂ ≠ p₁) : ∠ p₂ p₁ p₃ = 0 := by rw [angle, angle_eq_zero_iff] rcases h with ⟨r, ⟨hr0, hr1⟩, rfl⟩ have hr0' : r ≠ 0 := by rintro rfl simp at hp₂p₁ replace hr0 := hr0.lt_of_ne hr0'.symm refine ⟨vsub_ne_zero.2 hp₂p₁, r⁻¹, inv_pos.2 hr0, ?_⟩ rw [AffineMap.lineMap_apply, vadd_vsub_assoc, vsub_self, add_zero, smul_smul, inv_mul_cancel₀ hr0', one_smul] /-- If the second of three points is strictly between the other two, the angle at the first point is zero. -/ theorem _root_.Sbtw.angle₂₁₃_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₂ p₁ p₃ = 0 := h.wbtw.angle₂₁₃_eq_zero_of_ne h.ne_left /-- If the second of three points is weakly between the other two, and not equal to the first, the angle at the first point (reversed) is zero. -/ theorem _root_.Wbtw.angle₃₁₂_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₁ : p₂ ≠ p₁) : ∠ p₃ p₁ p₂ = 0 := by rw [← h.angle₂₁₃_eq_zero_of_ne hp₂p₁, angle_comm] /-- If the second of three points is strictly between the other two, the angle at the first point (reversed) is zero. -/ theorem _root_.Sbtw.angle₃₁₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₃ p₁ p₂ = 0 := h.wbtw.angle₃₁₂_eq_zero_of_ne h.ne_left /-- If the second of three points is weakly between the other two, and not equal to the third, the angle at the third point is zero. -/ theorem _root_.Wbtw.angle₂₃₁_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₃ : p₂ ≠ p₃) : ∠ p₂ p₃ p₁ = 0 := h.symm.angle₂₁₃_eq_zero_of_ne hp₂p₃ /-- If the second of three points is strictly between the other two, the angle at the third point is zero. -/ theorem _root_.Sbtw.angle₂₃₁_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₂ p₃ p₁ = 0 := h.wbtw.angle₂₃₁_eq_zero_of_ne h.ne_right /-- If the second of three points is weakly between the other two, and not equal to the third, the angle at the third point (reversed) is zero. -/ theorem _root_.Wbtw.angle₁₃₂_eq_zero_of_ne {p₁ p₂ p₃ : P} (h : Wbtw ℝ p₁ p₂ p₃) (hp₂p₃ : p₂ ≠ p₃) : ∠ p₁ p₃ p₂ = 0 := h.symm.angle₃₁₂_eq_zero_of_ne hp₂p₃
/-- If the second of three points is strictly between the other two, the angle at the third point (reversed) is zero. -/ theorem _root_.Sbtw.angle₁₃₂_eq_zero {p₁ p₂ p₃ : P} (h : Sbtw ℝ p₁ p₂ p₃) : ∠ p₁ p₃ p₂ = 0 := h.wbtw.angle₁₃₂_eq_zero_of_ne h.ne_right /-- The angle between three points is zero if and only if one of the first and third points is weakly between the other two, and not equal to the second. -/ theorem angle_eq_zero_iff_ne_and_wbtw {p₁ p₂ p₃ : P} : ∠ p₁ p₂ p₃ = 0 ↔ p₁ ≠ p₂ ∧ Wbtw ℝ p₂ p₁ p₃ ∨ p₃ ≠ p₂ ∧ Wbtw ℝ p₂ p₃ p₁ := by constructor
Mathlib/Geometry/Euclidean/Angle/Unoriented/Affine.lean
334
344
/- Copyright (c) 2022 Antoine Labelle, Rémi Bottinelli. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Antoine Labelle, Rémi Bottinelli -/ import Mathlib.Combinatorics.Quiver.Cast import Mathlib.Combinatorics.Quiver.Symmetric import Mathlib.Data.Sigma.Basic import Mathlib.Data.Sum.Basic import Mathlib.Logic.Equiv.Sum import Mathlib.Tactic.Common /-! # Covering This file defines coverings of quivers as prefunctors that are bijective on the so-called stars and costars at each vertex of the domain. ## Main definitions * `Quiver.Star u` is the type of all arrows with source `u`; * `Quiver.Costar u` is the type of all arrows with target `u`; * `Prefunctor.star φ u` is the obvious function `star u → star (φ.obj u)`; * `Prefunctor.costar φ u` is the obvious function `costar u → costar (φ.obj u)`; * `Prefunctor.IsCovering φ` means that `φ.star u` and `φ.costar u` are bijections for all `u`; * `Quiver.PathStar u` is the type of all paths with source `u`; * `Prefunctor.pathStar u` is the obvious function `PathStar u → PathStar (φ.obj u)`. ## Main statements * `Prefunctor.IsCovering.pathStar_bijective` states that if `φ` is a covering, then `φ.pathStar u` is a bijection for all `u`. In other words, every path in the codomain of `φ` lifts uniquely to its domain. ## TODO Clean up the namespaces by renaming `Prefunctor` to `Quiver.Prefunctor`. ## Tags Cover, covering, quiver, path, lift -/ open Function Quiver universe u v w variable {U : Type _} [Quiver.{u + 1} U] {V : Type _} [Quiver.{v + 1} V] (φ : U ⥤q V) {W : Type _} [Quiver.{w + 1} W] (ψ : V ⥤q W) /-- The `Quiver.Star` at a vertex is the collection of arrows whose source is the vertex. The type `Quiver.Star u` is defined to be `Σ (v : U), (u ⟶ v)`. -/ abbrev Quiver.Star (u : U) := Σ v : U, u ⟶ v /-- Constructor for `Quiver.Star`. Defined to be `Sigma.mk`. -/ protected abbrev Quiver.Star.mk {u v : U} (f : u ⟶ v) : Quiver.Star u := ⟨_, f⟩ /-- The `Quiver.Costar` at a vertex is the collection of arrows whose target is the vertex. The type `Quiver.Costar v` is defined to be `Σ (u : U), (u ⟶ v)`. -/ abbrev Quiver.Costar (v : U) := Σ u : U, u ⟶ v /-- Constructor for `Quiver.Costar`. Defined to be `Sigma.mk`. -/ protected abbrev Quiver.Costar.mk {u v : U} (f : u ⟶ v) : Quiver.Costar v := ⟨_, f⟩ /-- A prefunctor induces a map of `Quiver.Star` at every vertex. -/ @[simps] def Prefunctor.star (u : U) : Quiver.Star u → Quiver.Star (φ.obj u) := fun F => Quiver.Star.mk (φ.map F.2) /-- A prefunctor induces a map of `Quiver.Costar` at every vertex. -/ @[simps] def Prefunctor.costar (u : U) : Quiver.Costar u → Quiver.Costar (φ.obj u) := fun F => Quiver.Costar.mk (φ.map F.2) @[simp] theorem Prefunctor.star_apply {u v : U} (e : u ⟶ v) : φ.star u (Quiver.Star.mk e) = Quiver.Star.mk (φ.map e) := rfl @[simp] theorem Prefunctor.costar_apply {u v : U} (e : u ⟶ v) : φ.costar v (Quiver.Costar.mk e) = Quiver.Costar.mk (φ.map e) := rfl theorem Prefunctor.star_comp (u : U) : (φ ⋙q ψ).star u = ψ.star (φ.obj u) ∘ φ.star u := rfl theorem Prefunctor.costar_comp (u : U) : (φ ⋙q ψ).costar u = ψ.costar (φ.obj u) ∘ φ.costar u := rfl /-- A prefunctor is a covering of quivers if it defines bijections on all stars and costars. -/ protected structure Prefunctor.IsCovering : Prop where star_bijective : ∀ u, Bijective (φ.star u) costar_bijective : ∀ u, Bijective (φ.costar u) @[simp] theorem Prefunctor.IsCovering.map_injective (hφ : φ.IsCovering) {u v : U} : Injective fun f : u ⟶ v => φ.map f := by rintro f g he have : φ.star u (Quiver.Star.mk f) = φ.star u (Quiver.Star.mk g) := by simpa using he simpa using (hφ.star_bijective u).left this theorem Prefunctor.IsCovering.comp (hφ : φ.IsCovering) (hψ : ψ.IsCovering) : (φ ⋙q ψ).IsCovering := ⟨fun _ => (hψ.star_bijective _).comp (hφ.star_bijective _), fun _ => (hψ.costar_bijective _).comp (hφ.costar_bijective _)⟩ theorem Prefunctor.IsCovering.of_comp_right (hψ : ψ.IsCovering) (hφψ : (φ ⋙q ψ).IsCovering) : φ.IsCovering := ⟨fun _ => (Bijective.of_comp_iff' (hψ.star_bijective _) _).mp (hφψ.star_bijective _), fun _ => (Bijective.of_comp_iff' (hψ.costar_bijective _) _).mp (hφψ.costar_bijective _)⟩ theorem Prefunctor.IsCovering.of_comp_left (hφ : φ.IsCovering) (hφψ : (φ ⋙q ψ).IsCovering) (φsur : Surjective φ.obj) : ψ.IsCovering := by refine ⟨fun v => ?_, fun v => ?_⟩ <;> obtain ⟨u, rfl⟩ := φsur v exacts [(Bijective.of_comp_iff _ (hφ.star_bijective u)).mp (hφψ.star_bijective u), (Bijective.of_comp_iff _ (hφ.costar_bijective u)).mp (hφψ.costar_bijective u)] /-- The star of the symmetrification of a quiver at a vertex `u` is equivalent to the sum of the star and the costar at `u` in the original quiver. -/ def Quiver.symmetrifyStar (u : U) : Quiver.Star (Symmetrify.of.obj u) ≃ Quiver.Star u ⊕ Quiver.Costar u := Equiv.sigmaSumDistrib _ _ /-- The costar of the symmetrification of a quiver at a vertex `u` is equivalent to the sum of the costar and the star at `u` in the original quiver. -/ def Quiver.symmetrifyCostar (u : U) : Quiver.Costar (Symmetrify.of.obj u) ≃ Quiver.Costar u ⊕ Quiver.Star u := Equiv.sigmaSumDistrib _ _ theorem Prefunctor.symmetrifyStar (u : U) : φ.symmetrify.star u = (Quiver.symmetrifyStar _).symm ∘ Sum.map (φ.star u) (φ.costar u) ∘ Quiver.symmetrifyStar u := by rw [Equiv.eq_symm_comp (e := Quiver.symmetrifyStar (φ.obj u))] ext ⟨v, f | g⟩ <;> -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [Quiver.symmetrifyStar]` simp only [Quiver.symmetrifyStar, Function.comp_apply] <;> erw [Equiv.sigmaSumDistrib_apply, Equiv.sigmaSumDistrib_apply] <;> simp protected theorem Prefunctor.symmetrifyCostar (u : U) : φ.symmetrify.costar u = (Quiver.symmetrifyCostar _).symm ∘ Sum.map (φ.costar u) (φ.star u) ∘ Quiver.symmetrifyCostar u := by rw [Equiv.eq_symm_comp (e := Quiver.symmetrifyCostar (φ.obj u))] ext ⟨v, f | g⟩ <;> -- Porting note (https://github.com/leanprover-community/mathlib4/issues/10745): was `simp [Quiver.symmetrifyCostar]` simp only [Quiver.symmetrifyCostar, Function.comp_apply] <;> erw [Equiv.sigmaSumDistrib_apply, Equiv.sigmaSumDistrib_apply] <;> simp protected theorem Prefunctor.IsCovering.symmetrify (hφ : φ.IsCovering) : φ.symmetrify.IsCovering := by refine ⟨fun u => ?_, fun u => ?_⟩ <;> simp [φ.symmetrifyStar, φ.symmetrifyCostar, hφ.star_bijective u, hφ.costar_bijective u] /-- The path star at a vertex `u` is the type of all paths starting at `u`. The type `Quiver.PathStar u` is defined to be `Σ v : U, Path u v`. -/ abbrev Quiver.PathStar (u : U) := Σ v : U, Path u v /-- Constructor for `Quiver.PathStar`. Defined to be `Sigma.mk`. -/ protected abbrev Quiver.PathStar.mk {u v : U} (p : Path u v) : Quiver.PathStar u := ⟨_, p⟩ /-- A prefunctor induces a map of path stars. -/ def Prefunctor.pathStar (u : U) : Quiver.PathStar u → Quiver.PathStar (φ.obj u) := fun p => Quiver.PathStar.mk (φ.mapPath p.2) @[simp] theorem Prefunctor.pathStar_apply {u v : U} (p : Path u v) : φ.pathStar u (Quiver.PathStar.mk p) = Quiver.PathStar.mk (φ.mapPath p) := rfl theorem Prefunctor.pathStar_injective (hφ : ∀ u, Injective (φ.star u)) (u : U) : Injective (φ.pathStar u) := by dsimp +unfoldPartialApp [Prefunctor.pathStar, Quiver.PathStar.mk] rintro ⟨v₁, p₁⟩ induction p₁ with | nil => rintro ⟨y₂, p₂⟩ rcases p₂ with - | ⟨p₂, e₂⟩ · intro; rfl -- Porting note: goal not present in lean3. · intro h -- Porting note: added `Sigma.mk.inj_iff` simp only [mapPath_cons, Sigma.mk.inj_iff] at h exfalso obtain ⟨h, h'⟩ := h rw [← Path.eq_cast_iff_heq rfl h.symm, Path.cast_cons] at h' exact (Path.nil_ne_cons _ _) h' | cons p₁ e₁ ih => rename_i x₁ y₁ rintro ⟨y₂, p₂⟩ rcases p₂ with - | ⟨p₂, e₂⟩ · intro h simp only [mapPath_cons, Sigma.mk.inj_iff] at h exfalso obtain ⟨h, h'⟩ := h rw [← Path.cast_eq_iff_heq rfl h, Path.cast_cons] at h' exact (Path.cons_ne_nil _ _) h' · rename_i x₂ intro h simp only [mapPath_cons, Sigma.mk.inj_iff] at h obtain ⟨hφy, h'⟩ := h rw [← Path.cast_eq_iff_heq rfl hφy, Path.cast_cons, Path.cast_rfl_rfl] at h' have hφx := Path.obj_eq_of_cons_eq_cons h' have hφp := Path.heq_of_cons_eq_cons h' have hφe := HEq.trans (Hom.cast_heq rfl hφy _).symm (Path.hom_heq_of_cons_eq_cons h') have h_path_star : φ.pathStar u ⟨x₁, p₁⟩ = φ.pathStar u ⟨x₂, p₂⟩ := by simp only [Prefunctor.pathStar_apply, Sigma.mk.inj_iff]; exact ⟨hφx, hφp⟩ cases ih h_path_star have h_star : φ.star x₁ ⟨y₁, e₁⟩ = φ.star x₁ ⟨y₂, e₂⟩ := by simp only [Prefunctor.star_apply, Sigma.mk.inj_iff]; exact ⟨hφy, hφe⟩ cases hφ x₁ h_star rfl theorem Prefunctor.pathStar_surjective (hφ : ∀ u, Surjective (φ.star u)) (u : U) : Surjective (φ.pathStar u) := by dsimp +unfoldPartialApp [Prefunctor.pathStar, Quiver.PathStar.mk] rintro ⟨v, p⟩ induction p with | nil => use ⟨u, Path.nil⟩ simp only [Prefunctor.mapPath_nil, eq_self_iff_true, heq_iff_eq, and_self_iff] | cons p' ev ih => obtain ⟨⟨u', q'⟩, h⟩ := ih simp only at h obtain ⟨rfl, rfl⟩ := h obtain ⟨⟨u'', eu⟩, k⟩ := hφ u' ⟨_, ev⟩ simp only [star_apply, Sigma.mk.inj_iff] at k -- Porting note: was `obtain ⟨rfl, rfl⟩ := k` obtain ⟨rfl, k⟩ := k simp only [heq_eq_eq] at k subst k use ⟨_, q'.cons eu⟩ simp only [Prefunctor.mapPath_cons, eq_self_iff_true, heq_iff_eq, and_self_iff] theorem Prefunctor.pathStar_bijective (hφ : ∀ u, Bijective (φ.star u)) (u : U) : Bijective (φ.pathStar u) := ⟨φ.pathStar_injective (fun u => (hφ u).1) _, φ.pathStar_surjective (fun u => (hφ u).2) _⟩
namespace Prefunctor.IsCovering variable {φ} protected theorem pathStar_bijective (hφ : φ.IsCovering) (u : U) : Bijective (φ.pathStar u) := φ.pathStar_bijective hφ.1 u end Prefunctor.IsCovering section HasInvolutiveReverse variable [HasInvolutiveReverse U] [HasInvolutiveReverse V] /-- In a quiver with involutive inverses, the star and costar at every vertex are equivalent. This map is induced by `Quiver.reverse`. -/ @[simps] def Quiver.starEquivCostar (u : U) : Quiver.Star u ≃ Quiver.Costar u where
Mathlib/Combinatorics/Quiver/Covering.lean
246
263
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Aurélien Saue, Anne Baanen -/ import Mathlib.Tactic.NormNum.Inv import Mathlib.Tactic.NormNum.Pow import Mathlib.Util.AtomM /-! # `ring` tactic A tactic for solving equations in commutative (semi)rings, where the exponents can also contain variables. Based on <http://www.cs.ru.nl/~freek/courses/tt-2014/read/10.1.1.61.3041.pdf> . More precisely, expressions of the following form are supported: - constants (non-negative integers) - variables - coefficients (any rational number, embedded into the (semi)ring) - addition of expressions - multiplication of expressions (`a * b`) - scalar multiplication of expressions (`n • a`; the multiplier must have type `ℕ`) - exponentiation of expressions (the exponent must have type `ℕ`) - subtraction and negation of expressions (if the base is a full ring) The extension to exponents means that something like `2 * 2^n * b = b * 2^(n+1)` can be proved, even though it is not strictly speaking an equation in the language of commutative rings. ## Implementation notes The basic approach to prove equalities is to normalise both sides and check for equality. The normalisation is guided by building a value in the type `ExSum` at the meta level, together with a proof (at the base level) that the original value is equal to the normalised version. The outline of the file: - Define a mutual inductive family of types `ExSum`, `ExProd`, `ExBase`, which can represent expressions with `+`, `*`, `^` and rational numerals. The mutual induction ensures that associativity and distributivity are applied, by restricting which kinds of subexpressions appear as arguments to the various operators. - Represent addition, multiplication and exponentiation in the `ExSum` type, thus allowing us to map expressions to `ExSum` (the `eval` function drives this). We apply associativity and distributivity of the operators here (helped by `Ex*` types) and commutativity as well (by sorting the subterms; unfortunately not helped by anything). Any expression not of the above formats is treated as an atom (the same as a variable). There are some details we glossed over which make the plan more complicated: - The order on atoms is not initially obvious. We construct a list containing them in order of initial appearance in the expression, then use the index into the list as a key to order on. - For `pow`, the exponent must be a natural number, while the base can be any semiring `α`. We swap out operations for the base ring `α` with those for the exponent ring `ℕ` as soon as we deal with exponents. ## Caveats and future work The normalized form of an expression is the one that is useful for the tactic, but not as nice to read. To remedy this, the user-facing normalization calls `ringNFCore`. Subtraction cancels out identical terms, but division does not. That is: `a - a = 0 := by ring` solves the goal, but `a / a := 1 by ring` doesn't. Note that `0 / 0` is generally defined to be `0`, so division cancelling out is not true in general. Multiplication of powers can be simplified a little bit further: `2 ^ n * 2 ^ n = 4 ^ n := by ring` could be implemented in a similar way that `2 * a + 2 * a = 4 * a := by ring` already works. This feature wasn't needed yet, so it's not implemented yet. ## Tags ring, semiring, exponent, power -/ assert_not_exists OrderedAddCommMonoid namespace Mathlib.Tactic namespace Ring open Mathlib.Meta Qq NormNum Lean.Meta AtomM attribute [local instance] monadLiftOptionMetaM open Lean (MetaM Expr mkRawNatLit) /-- A shortcut instance for `CommSemiring ℕ` used by ring. -/ def instCommSemiringNat : CommSemiring ℕ := inferInstance /-- A typed expression of type `CommSemiring ℕ` used when we are working on ring subexpressions of type `ℕ`. -/ def sℕ : Q(CommSemiring ℕ) := q(instCommSemiringNat) mutual /-- The base `e` of a normalized exponent expression. -/ inductive ExBase : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- An atomic expression `e` with id `id`. Atomic expressions are those which `ring` cannot parse any further. For instance, `a + (a % b)` has `a` and `(a % b)` as atoms. The `ring1` tactic does not normalize the subexpressions in atoms, but `ring_nf` does. Atoms in fact represent equivalence classes of expressions, modulo definitional equality. The field `index : ℕ` should be a unique number for each class, while `value : expr` contains a representative of this class. The function `resolve_atom` determines the appropriate atom for a given expression. -/ | atom {sα} {e} (id : ℕ) : ExBase sα e /-- A sum of monomials. -/ | sum {sα} {e} (_ : ExSum sα e) : ExBase sα e /-- A monomial, which is a product of powers of `ExBase` expressions, terminated by a (nonzero) constant coefficient. -/ inductive ExProd : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- A coefficient `value`, which must not be `0`. `e` is a raw rat cast. If `value` is not an integer, then `hyp` should be a proof of `(value.den : α) ≠ 0`. -/ | const {sα} {e} (value : ℚ) (hyp : Option Expr := none) : ExProd sα e /-- A product `x ^ e * b` is a monomial if `b` is a monomial. Here `x` is an `ExBase` and `e` is an `ExProd` representing a monomial expression in `ℕ` (it is a monomial instead of a polynomial because we eagerly normalize `x ^ (a + b) = x ^ a * x ^ b`.) -/ | mul {u : Lean.Level} {α : Q(Type u)} {sα} {x : Q($α)} {e : Q(ℕ)} {b : Q($α)} : ExBase sα x → ExProd sℕ e → ExProd sα b → ExProd sα q($x ^ $e * $b) /-- A polynomial expression, which is a sum of monomials. -/ inductive ExSum : ∀ {u : Lean.Level} {α : Q(Type u)}, Q(CommSemiring $α) → (e : Q($α)) → Type /-- Zero is a polynomial. `e` is the expression `0`. -/ | zero {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} : ExSum sα q(0 : $α) /-- A sum `a + b` is a polynomial if `a` is a monomial and `b` is another polynomial. -/ | add {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExSum sα b → ExSum sα q($a + $b) end mutual -- partial only to speed up compilation /-- Equality test for expressions. This is not a `BEq` instance because it is heterogeneous. -/ partial def ExBase.eq {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExBase sα a → ExBase sα b → Bool | .atom i, .atom j => i == j | .sum a, .sum b => a.eq b | _, _ => false @[inherit_doc ExBase.eq] partial def ExProd.eq {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExProd sα b → Bool | .const i _, .const j _ => i == j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => a₁.eq b₁ && a₂.eq b₂ && a₃.eq b₃ | _, _ => false @[inherit_doc ExBase.eq] partial def ExSum.eq {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExSum sα a → ExSum sα b → Bool | .zero, .zero => true | .add a₁ a₂, .add b₁ b₂ => a₁.eq b₁ && a₂.eq b₂ | _, _ => false end mutual -- partial only to speed up compilation /-- A total order on normalized expressions. This is not an `Ord` instance because it is heterogeneous. -/ partial def ExBase.cmp {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExBase sα a → ExBase sα b → Ordering | .atom i, .atom j => compare i j | .sum a, .sum b => a.cmp b | .atom .., .sum .. => .lt | .sum .., .atom .. => .gt @[inherit_doc ExBase.cmp] partial def ExProd.cmp {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExProd sα a → ExProd sα b → Ordering | .const i _, .const j _ => compare i j | .mul a₁ a₂ a₃, .mul b₁ b₂ b₃ => (a₁.cmp b₁).then (a₂.cmp b₂) |>.then (a₃.cmp b₃) | .const _ _, .mul .. => .lt | .mul .., .const _ _ => .gt @[inherit_doc ExBase.cmp] partial def ExSum.cmp {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a b : Q($α)} : ExSum sα a → ExSum sα b → Ordering | .zero, .zero => .eq | .add a₁ a₂, .add b₁ b₂ => (a₁.cmp b₁).then (a₂.cmp b₂) | .zero, .add .. => .lt | .add .., .zero => .gt end variable {u : Lean.Level} {α : Q(Type u)} {sα : Q(CommSemiring $α)} instance : Inhabited (Σ e, (ExBase sα) e) := ⟨default, .atom 0⟩ instance : Inhabited (Σ e, (ExSum sα) e) := ⟨_, .zero⟩ instance : Inhabited (Σ e, (ExProd sα) e) := ⟨default, .const 0 none⟩ mutual /-- Converts `ExBase sα` to `ExBase sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExBase.cast {v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} : ExBase sα a → Σ a, ExBase sβ a | .atom i => ⟨a, .atom i⟩ | .sum a => let ⟨_, vb⟩ := a.cast; ⟨_, .sum vb⟩ /-- Converts `ExProd sα` to `ExProd sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExProd.cast {v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} : ExProd sα a → Σ a, ExProd sβ a | .const i h => ⟨a, .const i h⟩ | .mul a₁ a₂ a₃ => ⟨_, .mul a₁.cast.2 a₂ a₃.cast.2⟩ /-- Converts `ExSum sα` to `ExSum sβ`, assuming `sα` and `sβ` are defeq. -/ partial def ExSum.cast {v : Lean.Level} {β : Q(Type v)} {sβ : Q(CommSemiring $β)} {a : Q($α)} : ExSum sα a → Σ a, ExSum sβ a | .zero => ⟨_, .zero⟩ | .add a₁ a₂ => ⟨_, .add a₁.cast.2 a₂.cast.2⟩ end variable {u : Lean.Level} /-- The result of evaluating an (unnormalized) expression `e` into the type family `E` (one of `ExSum`, `ExProd`, `ExBase`) is a (normalized) element `e'` and a representation `E e'` for it, and a proof of `e = e'`. -/ structure Result {α : Q(Type u)} (E : Q($α) → Type) (e : Q($α)) where /-- The normalized result. -/ expr : Q($α) /-- The data associated to the normalization. -/ val : E expr /-- A proof that the original expression is equal to the normalized result. -/ proof : Q($e = $expr) instance {α : Q(Type u)} {E : Q($α) → Type} {e : Q($α)} [Inhabited (Σ e, E e)] : Inhabited (Result E e) := let ⟨e', v⟩ : Σ e, E e := default; ⟨e', v, default⟩ variable {α : Q(Type u)} (sα : Q(CommSemiring $α)) {R : Type*} [CommSemiring R] /-- Constructs the expression corresponding to `.const n`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNat (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q(($lit).rawCast : $α), .const n none⟩ /-- Constructs the expression corresponding to `.const (-n)`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkNegNat (_ : Q(Ring $α)) (n : ℕ) : (e : Q($α)) × ExProd sα e := let lit : Q(ℕ) := mkRawNatLit n ⟨q((Int.negOfNat $lit).rawCast : $α), .const (-n) none⟩ /-- Constructs the expression corresponding to `.const q h` for `q = n / d` and `h` a proof that `(d : α) ≠ 0`. (The `.const` constructor does not check that the expression is correct.) -/ def ExProd.mkRat (_ : Q(DivisionRing $α)) (q : ℚ) (n : Q(ℤ)) (d : Q(ℕ)) (h : Expr) : (e : Q($α)) × ExProd sα e := ⟨q(Rat.rawCast $n $d : $α), .const q h⟩ section /-- Embed an exponent (an `ExBase, ExProd` pair) as an `ExProd` by multiplying by 1. -/ def ExBase.toProd {α : Q(Type u)} {sα : Q(CommSemiring $α)} {a : Q($α)} {b : Q(ℕ)} (va : ExBase sα a) (vb : ExProd sℕ b) : ExProd sα q($a ^ $b * (nat_lit 1).rawCast) := .mul va vb (.const 1 none) /-- Embed `ExProd` in `ExSum` by adding 0. -/ def ExProd.toSum {sα : Q(CommSemiring $α)} {e : Q($α)} (v : ExProd sα e) : ExSum sα q($e + 0) := .add v .zero /-- Get the leading coefficient of an `ExProd`. -/ def ExProd.coeff {sα : Q(CommSemiring $α)} {e : Q($α)} : ExProd sα e → ℚ | .const q _ => q | .mul _ _ v => v.coeff end /-- Two monomials are said to "overlap" if they differ by a constant factor, in which case the constants just add. When this happens, the constant may be either zero (if the monomials cancel) or nonzero (if they add up); the zero case is handled specially. -/ inductive Overlap (e : Q($α)) where /-- The expression `e` (the sum of monomials) is equal to `0`. -/ | zero (_ : Q(IsNat $e (nat_lit 0))) /-- The expression `e` (the sum of monomials) is equal to another monomial (with nonzero leading coefficient). -/ | nonzero (_ : Result (ExProd sα) e) variable {a a' a₁ a₂ a₃ b b' b₁ b₂ b₃ c c₁ c₂ : R} theorem add_overlap_pf (x : R) (e) (pq_pf : a + b = c) : x ^ e * a + x ^ e * b = x ^ e * c := by subst_vars; simp [mul_add] theorem add_overlap_pf_zero (x : R) (e) : IsNat (a + b) (nat_lit 0) → IsNat (x ^ e * a + x ^ e * b) (nat_lit 0) | ⟨h⟩ => ⟨by simp [h, ← mul_add]⟩ -- TODO: decide if this is a good idea globally in -- https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.60MonadLift.20Option.20.28OptionT.20m.29.60/near/469097834 private local instance {m} [Pure m] : MonadLift Option (OptionT m) where monadLift f := .mk <| pure f /-- Given monomials `va, vb`, attempts to add them together to get another monomial. If the monomials are not compatible, returns `none`. For example, `xy + 2xy = 3xy` is a `.nonzero` overlap, while `xy + xz` returns `none` and `xy + -xy = 0` is a `.zero` overlap. -/ def evalAddOverlap {a b : Q($α)} (va : ExProd sα a) (vb : ExProd sα b) : OptionT Lean.Core.CoreM (Overlap sα q($a + $b)) := do Lean.Core.checkSystem decl_name%.toString match va, vb with | .const za ha, .const zb hb => do let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let res ← NormNum.evalAdd.core q($a + $b) q(HAdd.hAdd) a b ra rb match res with | .isNat _ (.lit (.natVal 0)) p => pure <| .zero p | rc => let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq pure <| .nonzero ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .mul vb₁ vb₂ vb₃ => do guard (va₁.eq vb₁ && va₂.eq vb₂) match ← evalAddOverlap va₃ vb₃ with | .zero p => pure <| .zero (q(add_overlap_pf_zero $a₁ $a₂ $p) : Expr) | .nonzero ⟨_, vc, p⟩ => pure <| .nonzero ⟨_, .mul va₁ va₂ vc, (q(add_overlap_pf $a₁ $a₂ $p) : Expr)⟩ | _, _ => OptionT.fail theorem add_pf_zero_add (b : R) : 0 + b = b := by simp theorem add_pf_add_zero (a : R) : a + 0 = a := by simp theorem add_pf_add_overlap (_ : a₁ + b₁ = c₁) (_ : a₂ + b₂ = c₂) : (a₁ + a₂ : R) + (b₁ + b₂) = c₁ + c₂ := by subst_vars; simp [add_assoc, add_left_comm] theorem add_pf_add_overlap_zero (h : IsNat (a₁ + b₁) (nat_lit 0)) (h₄ : a₂ + b₂ = c) : (a₁ + a₂ : R) + (b₁ + b₂) = c := by subst_vars; rw [add_add_add_comm, h.1, Nat.cast_zero, add_pf_zero_add] theorem add_pf_add_lt (a₁ : R) (_ : a₂ + b = c) : (a₁ + a₂) + b = a₁ + c := by simp [*, add_assoc] theorem add_pf_add_gt (b₁ : R) (_ : a + b₂ = c) : a + (b₁ + b₂) = b₁ + c := by subst_vars; simp [add_left_comm] /-- Adds two polynomials `va, vb` together to get a normalized result polynomial. * `0 + b = b` * `a + 0 = a` * `a * x + a * y = a * (x + y)` (for `x`, `y` coefficients; uses `evalAddOverlap`) * `(a₁ + a₂) + (b₁ + b₂) = a₁ + (a₂ + (b₁ + b₂))` (if `a₁.lt b₁`) * `(a₁ + a₂) + (b₁ + b₂) = b₁ + ((a₁ + a₂) + b₂)` (if not `a₁.lt b₁`) -/ partial def evalAdd {a b : Q($α)} (va : ExSum sα a) (vb : ExSum sα b) : Lean.Core.CoreM <| Result (ExSum sα) q($a + $b) := do Lean.Core.checkSystem decl_name%.toString match va, vb with | .zero, vb => return ⟨b, vb, q(add_pf_zero_add $b)⟩ | va, .zero => return ⟨a, va, q(add_pf_add_zero $a)⟩ | .add (a := a₁) (b := _a₂) va₁ va₂, .add (a := b₁) (b := _b₂) vb₁ vb₂ => match ← (evalAddOverlap sα va₁ vb₁).run with | some (.nonzero ⟨_, vc₁, pc₁⟩) => let ⟨_, vc₂, pc₂⟩ ← evalAdd va₂ vb₂ return ⟨_, .add vc₁ vc₂, q(add_pf_add_overlap $pc₁ $pc₂)⟩ | some (.zero pc₁) => let ⟨c₂, vc₂, pc₂⟩ ← evalAdd va₂ vb₂ return ⟨c₂, vc₂, q(add_pf_add_overlap_zero $pc₁ $pc₂)⟩ | none => if let .lt := va₁.cmp vb₁ then let ⟨_c, vc, (pc : Q($_a₂ + ($b₁ + $_b₂) = $_c))⟩ ← evalAdd va₂ vb return ⟨_, .add va₁ vc, q(add_pf_add_lt $a₁ $pc)⟩ else let ⟨_c, vc, (pc : Q($a₁ + $_a₂ + $_b₂ = $_c))⟩ ← evalAdd va vb₂ return ⟨_, .add vb₁ vc, q(add_pf_add_gt $b₁ $pc)⟩ theorem one_mul (a : R) : (nat_lit 1).rawCast * a = a := by simp [Nat.rawCast] theorem mul_one (a : R) : a * (nat_lit 1).rawCast = a := by simp [Nat.rawCast] theorem mul_pf_left (a₁ : R) (a₂) (_ : a₃ * b = c) : (a₁ ^ a₂ * a₃ : R) * b = a₁ ^ a₂ * c := by subst_vars; rw [mul_assoc] theorem mul_pf_right (b₁ : R) (b₂) (_ : a * b₃ = c) : a * (b₁ ^ b₂ * b₃) = b₁ ^ b₂ * c := by subst_vars; rw [mul_left_comm] theorem mul_pp_pf_overlap {ea eb e : ℕ} (x : R) (_ : ea + eb = e) (_ : a₂ * b₂ = c) : (x ^ ea * a₂ : R) * (x ^ eb * b₂) = x ^ e * c := by subst_vars; simp [pow_add, mul_mul_mul_comm] /-- Multiplies two monomials `va, vb` together to get a normalized result monomial. * `x * y = (x * y)` (for `x`, `y` coefficients) * `x * (b₁ * b₂) = b₁ * (b₂ * x)` (for `x` coefficient) * `(a₁ * a₂) * y = a₁ * (a₂ * y)` (for `y` coefficient) * `(x ^ ea * a₂) * (x ^ eb * b₂) = x ^ (ea + eb) * (a₂ * b₂)` (if `ea` and `eb` are identical except coefficient) * `(a₁ * a₂) * (b₁ * b₂) = a₁ * (a₂ * (b₁ * b₂))` (if `a₁.lt b₁`) * `(a₁ * a₂) * (b₁ * b₂) = b₁ * ((a₁ * a₂) * b₂)` (if not `a₁.lt b₁`) -/ partial def evalMulProd {a b : Q($α)} (va : ExProd sα a) (vb : ExProd sα b) : Lean.Core.CoreM <| Result (ExProd sα) q($a * $b) := do Lean.Core.checkSystem decl_name%.toString match va, vb with | .const za ha, .const zb hb => if za = 1 then return ⟨b, .const zb hb, (q(one_mul $b) : Expr)⟩ else if zb = 1 then return ⟨a, .const za ha, (q(mul_one $a) : Expr)⟩ else let ra := Result.ofRawRat za a ha; let rb := Result.ofRawRat zb b hb let rc := (NormNum.evalMul.core q($a * $b) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) ra rb).get! let ⟨zc, hc⟩ := rc.toRatNZ.get! let ⟨c, pc⟩ := rc.toRawEq return ⟨c, .const zc hc, pc⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃, .const _ _ => let ⟨_, vc, pc⟩ ← evalMulProd va₃ vb return ⟨_, .mul va₁ va₂ vc, (q(mul_pf_left $a₁ $a₂ $pc) : Expr)⟩ | .const _ _, .mul (x := b₁) (e := b₂) vb₁ vb₂ vb₃ => let ⟨_, vc, pc⟩ ← evalMulProd va vb₃ return ⟨_, .mul vb₁ vb₂ vc, (q(mul_pf_right $b₁ $b₂ $pc) : Expr)⟩ | .mul (x := xa) (e := ea) vxa vea va₂, .mul (x := xb) (e := eb) vxb veb vb₂ => do if vxa.eq vxb then if let some (.nonzero ⟨_, ve, pe⟩) ← (evalAddOverlap sℕ vea veb).run then let ⟨_, vc, pc⟩ ← evalMulProd va₂ vb₂ return ⟨_, .mul vxa ve vc, (q(mul_pp_pf_overlap $xa $pe $pc) : Expr)⟩ if let .lt := (vxa.cmp vxb).then (vea.cmp veb) then let ⟨_, vc, pc⟩ ← evalMulProd va₂ vb return ⟨_, .mul vxa vea vc, (q(mul_pf_left $xa $ea $pc) : Expr)⟩ else let ⟨_, vc, pc⟩ ← evalMulProd va vb₂ return ⟨_, .mul vxb veb vc, (q(mul_pf_right $xb $eb $pc) : Expr)⟩ theorem mul_zero (a : R) : a * 0 = 0 := by simp theorem mul_add {d : R} (_ : (a : R) * b₁ = c₁) (_ : a * b₂ = c₂) (_ : c₁ + 0 + c₂ = d) : a * (b₁ + b₂) = d := by subst_vars; simp [_root_.mul_add] /-- Multiplies a monomial `va` to a polynomial `vb` to get a normalized result polynomial. * `a * 0 = 0` * `a * (b₁ + b₂) = (a * b₁) + (a * b₂)` -/ def evalMul₁ {a b : Q($α)} (va : ExProd sα a) (vb : ExSum sα b) : Lean.Core.CoreM <| Result (ExSum sα) q($a * $b) := do match vb with | .zero => return ⟨_, .zero, q(mul_zero $a)⟩ | .add vb₁ vb₂ => let ⟨_, vc₁, pc₁⟩ ← evalMulProd sα va vb₁ let ⟨_, vc₂, pc₂⟩ ← evalMul₁ va vb₂ let ⟨_, vd, pd⟩ ← evalAdd sα vc₁.toSum vc₂ return ⟨_, vd, q(mul_add $pc₁ $pc₂ $pd)⟩ theorem zero_mul (b : R) : 0 * b = 0 := by simp theorem add_mul {d : R} (_ : (a₁ : R) * b = c₁) (_ : a₂ * b = c₂) (_ : c₁ + c₂ = d) : (a₁ + a₂) * b = d := by subst_vars; simp [_root_.add_mul] /-- Multiplies two polynomials `va, vb` together to get a normalized result polynomial. * `0 * b = 0` * `(a₁ + a₂) * b = (a₁ * b) + (a₂ * b)` -/ def evalMul {a b : Q($α)} (va : ExSum sα a) (vb : ExSum sα b) : Lean.Core.CoreM <| Result (ExSum sα) q($a * $b) := do match va with | .zero => return ⟨_, .zero, q(zero_mul $b)⟩ | .add va₁ va₂ => let ⟨_, vc₁, pc₁⟩ ← evalMul₁ sα va₁ vb let ⟨_, vc₂, pc₂⟩ ← evalMul va₂ vb let ⟨_, vd, pd⟩ ← evalAdd sα vc₁ vc₂ return ⟨_, vd, q(add_mul $pc₁ $pc₂ $pd)⟩ theorem natCast_nat (n) : ((Nat.rawCast n : ℕ) : R) = Nat.rawCast n := by simp theorem natCast_mul {a₁ a₃ : ℕ} (a₂) (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₃ : ℕ) : R) = b₃) : ((a₁ ^ a₂ * a₃ : ℕ) : R) = b₁ ^ a₂ * b₃ := by subst_vars; simp theorem natCast_zero : ((0 : ℕ) : R) = 0 := Nat.cast_zero theorem natCast_add {a₁ a₂ : ℕ} (_ : ((a₁ : ℕ) : R) = b₁) (_ : ((a₂ : ℕ) : R) = b₂) : ((a₁ + a₂ : ℕ) : R) = b₁ + b₂ := by subst_vars; simp mutual /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * An atom `e` causes `↑e` to be allocated as a new atom. * A sum delegates to `ExSum.evalNatCast`. -/ partial def ExBase.evalNatCast {a : Q(ℕ)} (va : ExBase sℕ a) : AtomM (Result (ExBase sα) q($a)) := match va with | .atom _ => do let (i, ⟨b', _⟩) ← addAtomQ q($a) pure ⟨b', ExBase.atom i, q(Eq.refl $b')⟩ | .sum va => do let ⟨_, vc, p⟩ ← va.evalNatCast pure ⟨_, .sum vc, p⟩ /-- Applies `Nat.cast` to a nat monomial to produce a monomial in `α`. * `↑c = c` if `c` is a numeric literal * `↑(a ^ n * b) = ↑a ^ n * ↑b` -/ partial def ExProd.evalNatCast {a : Q(ℕ)} (va : ExProd sℕ a) : AtomM (Result (ExProd sα) q($a)) := match va with | .const c hc => have n : Q(ℕ) := a.appArg! pure ⟨q(Nat.rawCast $n), .const c hc, (q(natCast_nat (R := $α) $n) : Expr)⟩ | .mul (e := a₂) va₁ va₂ va₃ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₃, pb₃⟩ ← va₃.evalNatCast pure ⟨_, .mul vb₁ va₂ vb₃, q(natCast_mul $a₂ $pb₁ $pb₃)⟩ /-- Applies `Nat.cast` to a nat polynomial to produce a polynomial in `α`. * `↑0 = 0` * `↑(a + b) = ↑a + ↑b` -/ partial def ExSum.evalNatCast {a : Q(ℕ)} (va : ExSum sℕ a) : AtomM (Result (ExSum sα) q($a)) := match va with | .zero => pure ⟨_, .zero, q(natCast_zero (R := $α))⟩ | .add va₁ va₂ => do let ⟨_, vb₁, pb₁⟩ ← va₁.evalNatCast let ⟨_, vb₂, pb₂⟩ ← va₂.evalNatCast pure ⟨_, .add vb₁ vb₂, q(natCast_add $pb₁ $pb₂)⟩ end theorem smul_nat {a b c : ℕ} (_ : (a * b : ℕ) = c) : a • b = c := by subst_vars; simp theorem smul_eq_cast {a : ℕ} (_ : ((a : ℕ) : R) = a') (_ : a' * b = c) : a • b = c := by subst_vars; simp /-- Constructs the scalar multiplication `n • a`, where both `n : ℕ` and `a : α` are normalized polynomial expressions. * `a • b = a * b` if `α = ℕ` * `a • b = ↑a * b` otherwise -/ def evalNSMul {a : Q(ℕ)} {b : Q($α)} (va : ExSum sℕ a) (vb : ExSum sα b) : AtomM (Result (ExSum sα) q($a • $b)) := do if ← isDefEq sα sℕ then let ⟨_, va'⟩ := va.cast have _b : Q(ℕ) := b let ⟨(_c : Q(ℕ)), vc, (pc : Q($a * $_b = $_c))⟩ ← evalMul sα va' vb pure ⟨_, vc, (q(smul_nat $pc) : Expr)⟩ else let ⟨_, va', pa'⟩ ← va.evalNatCast sα let ⟨_, vc, pc⟩ ← evalMul sα va' vb pure ⟨_, vc, (q(smul_eq_cast $pa' $pc) : Expr)⟩ theorem neg_one_mul {R} [Ring R] {a b : R} (_ : (Int.negOfNat (nat_lit 1)).rawCast * a = b) : -a = b := by subst_vars; simp [Int.negOfNat] theorem neg_mul {R} [Ring R] (a₁ : R) (a₂) {a₃ b : R} (_ : -a₃ = b) : -(a₁ ^ a₂ * a₃) = a₁ ^ a₂ * b := by subst_vars; simp /-- Negates a monomial `va` to get another monomial. * `-c = (-c)` (for `c` coefficient) * `-(a₁ * a₂) = a₁ * -a₂` -/ def evalNegProd {a : Q($α)} (rα : Q(Ring $α)) (va : ExProd sα a) : Lean.Core.CoreM <| Result (ExProd sα) q(-$a) := do Lean.Core.checkSystem decl_name%.toString match va with | .const za ha => let lit : Q(ℕ) := mkRawNatLit 1 let ⟨m1, _⟩ := ExProd.mkNegNat sα rα 1 let rm := Result.isNegNat rα lit (q(IsInt.of_raw $α (.negOfNat $lit)) : Expr) let ra := Result.ofRawRat za a ha let rb := (NormNum.evalMul.core q($m1 * $a) q(HMul.hMul) _ _ q(CommSemiring.toSemiring) rm ra).get! let ⟨zb, hb⟩ := rb.toRatNZ.get! let ⟨b, (pb : Q((Int.negOfNat (nat_lit 1)).rawCast * $a = $b))⟩ := rb.toRawEq return ⟨b, .const zb hb, (q(neg_one_mul (R := $α) $pb) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨_, vb, pb⟩ ← evalNegProd rα va₃ return ⟨_, .mul va₁ va₂ vb, (q(neg_mul $a₁ $a₂ $pb) : Expr)⟩ theorem neg_zero {R} [Ring R] : -(0 : R) = 0 := by simp theorem neg_add {R} [Ring R] {a₁ a₂ b₁ b₂ : R} (_ : -a₁ = b₁) (_ : -a₂ = b₂) : -(a₁ + a₂) = b₁ + b₂ := by subst_vars; simp [add_comm] /-- Negates a polynomial `va` to get another polynomial. * `-0 = 0` (for `c` coefficient) * `-(a₁ + a₂) = -a₁ + -a₂` -/ def evalNeg {a : Q($α)} (rα : Q(Ring $α)) (va : ExSum sα a) : Lean.Core.CoreM <| Result (ExSum sα) q(-$a) := do match va with | .zero => return ⟨_, .zero, (q(neg_zero (R := $α)) : Expr)⟩ | .add va₁ va₂ => let ⟨_, vb₁, pb₁⟩ ← evalNegProd sα rα va₁ let ⟨_, vb₂, pb₂⟩ ← evalNeg rα va₂ return ⟨_, .add vb₁ vb₂, (q(neg_add $pb₁ $pb₂) : Expr)⟩ theorem sub_pf {R} [Ring R] {a b c d : R} (_ : -b = c) (_ : a + c = d) : a - b = d := by subst_vars; simp [sub_eq_add_neg] /-- Subtracts two polynomials `va, vb` to get a normalized result polynomial. * `a - b = a + -b` -/ def evalSub {α : Q(Type u)} (sα : Q(CommSemiring $α)) {a b : Q($α)} (rα : Q(Ring $α)) (va : ExSum sα a) (vb : ExSum sα b) : Lean.Core.CoreM <| Result (ExSum sα) q($a - $b) := do let ⟨_c, vc, pc⟩ ← evalNeg sα rα vb let ⟨d, vd, (pd : Q($a + $_c = $d))⟩ ← evalAdd sα va vc return ⟨d, vd, (q(sub_pf $pc $pd) : Expr)⟩ theorem pow_prod_atom (a : R) (b) : a ^ b = (a + 0) ^ b * (nat_lit 1).rawCast := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. (This has a slightly different normalization than `evalPowAtom` because the input types are different.) * `x ^ e = (x + 0) ^ e * 1` -/ def evalPowProdAtom {a : Q($α)} {b : Q(ℕ)} (va : ExProd sα a) (vb : ExProd sℕ b) : Result (ExProd sα) q($a ^ $b) := ⟨_, (ExBase.sum va.toSum).toProd vb, q(pow_prod_atom $a $b)⟩ theorem pow_atom (a : R) (b) : a ^ b = a ^ b * (nat_lit 1).rawCast + 0 := by simp /-- The fallback case for exponentiating polynomials is to use `ExBase.toProd` to just build an exponent expression. * `x ^ e = x ^ e * 1 + 0` -/ def evalPowAtom {a : Q($α)} {b : Q(ℕ)} (va : ExBase sα a) (vb : ExProd sℕ b) : Result (ExSum sα) q($a ^ $b) := ⟨_, (va.toProd vb).toSum, q(pow_atom $a $b)⟩ theorem const_pos (n : ℕ) (h : Nat.ble 1 n = true) : 0 < (n.rawCast : ℕ) := Nat.le_of_ble_eq_true h theorem mul_exp_pos {a₁ a₂ : ℕ} (n) (h₁ : 0 < a₁) (h₂ : 0 < a₂) : 0 < a₁ ^ n * a₂ := Nat.mul_pos (Nat.pow_pos h₁) h₂ theorem add_pos_left {a₁ : ℕ} (a₂) (h : 0 < a₁) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_right ..) theorem add_pos_right {a₂ : ℕ} (a₁) (h : 0 < a₂) : 0 < a₁ + a₂ := Nat.lt_of_lt_of_le h (Nat.le_add_left ..) mutual /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * Atoms are not (necessarily) positive * Sums defer to `ExSum.evalPos` -/ partial def ExBase.evalPos {a : Q(ℕ)} (va : ExBase sℕ a) : Option Q(0 < $a) := match va with | .atom _ => none | .sum va => va.evalPos /-- Attempts to prove that a monomial expression in `ℕ` is positive. * `0 < c` (where `c` is a numeral) is true by the normalization invariant (`c` is not zero) * `0 < x ^ e * b` if `0 < x` and `0 < b` -/ partial def ExProd.evalPos {a : Q(ℕ)} (va : ExProd sℕ a) : Option Q(0 < $a) := match va with | .const _ _ => -- it must be positive because it is a nonzero nat literal have lit : Q(ℕ) := a.appArg! haveI : $a =Q Nat.rawCast $lit := ⟨⟩ haveI p : Nat.ble 1 $lit =Q true := ⟨⟩ some q(const_pos $lit $p) | .mul (e := ea₁) vxa₁ _ va₂ => do let pa₁ ← vxa₁.evalPos let pa₂ ← va₂.evalPos some q(mul_exp_pos $ea₁ $pa₁ $pa₂) /-- Attempts to prove that a polynomial expression in `ℕ` is positive. * `0 < 0` fails * `0 < a + b` if `0 < a` or `0 < b` -/ partial def ExSum.evalPos {a : Q(ℕ)} (va : ExSum sℕ a) : Option Q(0 < $a) := match va with | .zero => none | .add (a := a₁) (b := a₂) va₁ va₂ => do match va₁.evalPos with | some p => some q(add_pos_left $a₂ $p) | none => let p ← va₂.evalPos; some q(add_pos_right $a₁ $p) end theorem pow_one (a : R) : a ^ nat_lit 1 = a := by simp theorem pow_bit0 {k : ℕ} (_ : (a : R) ^ k = b) (_ : b * b = c) : a ^ (Nat.mul (nat_lit 2) k) = c := by subst_vars; simp [Nat.succ_mul, pow_add] theorem pow_bit1 {k : ℕ} {d : R} (_ : (a : R) ^ k = b) (_ : b * b = c) (_ : c * a = d) : a ^ (Nat.add (Nat.mul (nat_lit 2) k) (nat_lit 1)) = d := by subst_vars; simp [Nat.succ_mul, pow_add] /-- The main case of exponentiation of ring expressions is when `va` is a polynomial and `n` is a nonzero literal expression, like `(x + y)^5`. In this case we work out the polynomial completely into a sum of monomials. * `x ^ 1 = x` * `x ^ (2*n) = x ^ n * x ^ n` * `x ^ (2*n+1) = x ^ n * x ^ n * x` -/ partial def evalPowNat {a : Q($α)} (va : ExSum sα a) (n : Q(ℕ)) : Lean.Core.CoreM <| Result (ExSum sα) q($a ^ $n) := do let nn := n.natLit! if nn = 1 then return ⟨_, va, (q(pow_one $a) : Expr)⟩ else let nm := nn >>> 1 have m : Q(ℕ) := mkRawNatLit nm if nn &&& 1 = 0 then let ⟨_, vb, pb⟩ ← evalPowNat va m let ⟨_, vc, pc⟩ ← evalMul sα vb vb return ⟨_, vc, (q(pow_bit0 $pb $pc) : Expr)⟩ else let ⟨_, vb, pb⟩ ← evalPowNat va m let ⟨_, vc, pc⟩ ← evalMul sα vb vb let ⟨_, vd, pd⟩ ← evalMul sα vc va return ⟨_, vd, (q(pow_bit1 $pb $pc $pd) : Expr)⟩ theorem one_pow (b : ℕ) : ((nat_lit 1).rawCast : R) ^ b = (nat_lit 1).rawCast := by simp theorem mul_pow {ea₁ b c₁ : ℕ} {xa₁ : R} (_ : ea₁ * b = c₁) (_ : a₂ ^ b = c₂) : (xa₁ ^ ea₁ * a₂ : R) ^ b = xa₁ ^ c₁ * c₂ := by subst_vars; simp [_root_.mul_pow, pow_mul] /-- There are several special cases when exponentiating monomials: * `1 ^ n = 1` * `x ^ y = (x ^ y)` when `x` and `y` are constants * `(a * b) ^ e = a ^ e * b ^ e` In all other cases we use `evalPowProdAtom`. -/ def evalPowProd {a : Q($α)} {b : Q(ℕ)} (va : ExProd sα a) (vb : ExProd sℕ b) : Lean.Core.CoreM <| Result (ExProd sα) q($a ^ $b) := do Lean.Core.checkSystem decl_name%.toString let res : OptionT Lean.Core.CoreM (Result (ExProd sα) q($a ^ $b)) := do match va, vb with | .const 1, _ => return ⟨_, va, (q(one_pow (R := $α) $b) : Expr)⟩ | .const za ha, .const zb hb => assert! 0 ≤ zb let ra := Result.ofRawRat za a ha have lit : Q(ℕ) := b.appArg! let rb := (q(IsNat.of_raw ℕ $lit) : Expr) let rc ← NormNum.evalPow.core q($a ^ $b) q(HPow.hPow) q($a) q($b) lit rb q(CommSemiring.toSemiring) ra let ⟨zc, hc⟩ ← rc.toRatNZ let ⟨c, pc⟩ := rc.toRawEq return ⟨c, .const zc hc, pc⟩ | .mul vxa₁ vea₁ va₂, vb => let ⟨_, vc₁, pc₁⟩ ← evalMulProd sℕ vea₁ vb let ⟨_, vc₂, pc₂⟩ ← evalPowProd va₂ vb return ⟨_, .mul vxa₁ vc₁ vc₂, q(mul_pow $pc₁ $pc₂)⟩ | _, _ => OptionT.fail return (← res.run).getD (evalPowProdAtom sα va vb) /-- The result of `extractCoeff` is a numeral and a proof that the original expression factors by this numeral. -/ structure ExtractCoeff (e : Q(ℕ)) where /-- A raw natural number literal. -/ k : Q(ℕ) /-- The result of extracting the coefficient is a monic monomial. -/ e' : Q(ℕ) /-- `e'` is a monomial. -/ ve' : ExProd sℕ e' /-- The proof that `e` splits into the coefficient `k` and the monic monomial `e'`. -/ p : Q($e = $e' * $k) theorem coeff_one (k : ℕ) : k.rawCast = (nat_lit 1).rawCast * k := by simp theorem coeff_mul {a₃ c₂ k : ℕ} (a₁ a₂ : ℕ) (_ : a₃ = c₂ * k) : a₁ ^ a₂ * a₃ = (a₁ ^ a₂ * c₂) * k := by subst_vars; rw [mul_assoc] /-- Given a monomial expression `va`, splits off the leading coefficient `k` and the remainder `e'`, stored in the `ExtractCoeff` structure. * `c = 1 * c` (if `c` is a constant) * `a * b = (a * b') * k` if `b = b' * k` -/ def extractCoeff {a : Q(ℕ)} (va : ExProd sℕ a) : ExtractCoeff a := match va with | .const _ _ => have k : Q(ℕ) := a.appArg! ⟨k, q((nat_lit 1).rawCast), .const 1, (q(coeff_one $k) : Expr)⟩ | .mul (x := a₁) (e := a₂) va₁ va₂ va₃ => let ⟨k, _, vc, pc⟩ := extractCoeff va₃ ⟨k, _, .mul va₁ va₂ vc, q(coeff_mul $a₁ $a₂ $pc)⟩ theorem pow_one_cast (a : R) : a ^ (nat_lit 1).rawCast = a := by simp theorem zero_pow {b : ℕ} (_ : 0 < b) : (0 : R) ^ b = 0 := match b with | b+1 => by simp [pow_succ] theorem single_pow {b : ℕ} (_ : (a : R) ^ b = c) : (a + 0) ^ b = c + 0 := by simp [*] theorem pow_nat {b c k : ℕ} {d e : R} (_ : b = c * k) (_ : a ^ c = d) (_ : d ^ k = e) : (a : R) ^ b = e := by subst_vars; simp [pow_mul] /-- Exponentiates a polynomial `va` by a monomial `vb`, including several special cases. * `a ^ 1 = a` * `0 ^ e = 0` if `0 < e` * `(a + 0) ^ b = a ^ b` computed using `evalPowProd`
* `a ^ b = (a ^ b') ^ k` if `b = b' * k` and `k > 1`
Mathlib/Tactic/Ring/Basic.lean
844
845
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subgroup.Ker /-! # Basic results on subgroups We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid homomorphisms. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ assert_not_exists OrderedAddCommMonoid Multiset Ring open Function open scoped Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff end SubgroupClass namespace Subgroup variable (H K : Subgroup G) @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff variable {k : Set G} open Set variable {N : Type*} [Group N] {P : Type*} [Group P] /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl open scoped Relator in @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ @[to_additive (attr := simp) bot_prod_bot] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff @[to_additive closure_prod] theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) : closure (s ×ˢ t) = (closure s).prod (closure t) := le_antisymm (closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩) (prod_le_iff.2 ⟨ map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩, map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩) /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI)
variable [∀ i, Group (f i)]
Mathlib/Algebra/Group/Subgroup/Basic.lean
178
179
/- 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.Abelian import Mathlib.Algebra.Lie.BaseChange import Mathlib.Algebra.Lie.IdealOperations import Mathlib.Order.Hom.Basic import Mathlib.RingTheory.Flat.FaithfullyFlat.Basic /-! # Solvable Lie algebras Like groups, Lie algebras admit a natural concept of solvability. We define this here via the derived series and prove some related results. We also define the radical of a Lie algebra and prove that it is solvable when the Lie algebra is Noetherian. ## Main definitions * `LieAlgebra.derivedSeriesOfIdeal` * `LieAlgebra.derivedSeries` * `LieAlgebra.IsSolvable` * `LieAlgebra.isSolvableAdd` * `LieAlgebra.radical` * `LieAlgebra.radicalIsSolvable` * `LieAlgebra.derivedLengthOfIdeal` * `LieAlgebra.derivedLength` * `LieAlgebra.derivedAbelianOfIdeal` ## Tags lie algebra, derived series, derived length, solvable, radical -/ universe u v w w₁ w₂ variable (R : Type u) (L : Type v) (M : Type w) {L' : Type w₁} variable [CommRing R] [LieRing L] [LieAlgebra R L] [LieRing L'] [LieAlgebra R L'] variable (I J : LieIdeal R L) {f : L' →ₗ⁅R⁆ L} namespace LieAlgebra /-- A generalisation of the derived series of a Lie algebra, whose zeroth term is a specified ideal. It can be more convenient to work with this generalisation when considering the derived series of an ideal since it provides a type-theoretic expression of the fact that the terms of the ideal's derived series are also ideals of the enclosing algebra. See also `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_comap` and `LieIdeal.derivedSeries_eq_derivedSeriesOfIdeal_map` below. -/ def derivedSeriesOfIdeal (k : ℕ) : LieIdeal R L → LieIdeal R L := (fun I => ⁅I, I⁆)^[k] @[simp] theorem derivedSeriesOfIdeal_zero : derivedSeriesOfIdeal R L 0 I = I := rfl @[simp] theorem derivedSeriesOfIdeal_succ (k : ℕ) : derivedSeriesOfIdeal R L (k + 1) I = ⁅derivedSeriesOfIdeal R L k I, derivedSeriesOfIdeal R L k I⁆ := Function.iterate_succ_apply' (fun I => ⁅I, I⁆) k I /-- The derived series of Lie ideals of a Lie algebra. -/ abbrev derivedSeries (k : ℕ) : LieIdeal R L := derivedSeriesOfIdeal R L k ⊤ theorem derivedSeries_def (k : ℕ) : derivedSeries R L k = derivedSeriesOfIdeal R L k ⊤ := rfl variable {R L} local notation "D" => derivedSeriesOfIdeal R L theorem derivedSeriesOfIdeal_add (k l : ℕ) : D (k + l) I = D k (D l I) := by induction k with | zero => rw [Nat.zero_add, derivedSeriesOfIdeal_zero] | succ k ih => rw [Nat.succ_add k l, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ, ih] @[gcongr, mono] theorem derivedSeriesOfIdeal_le {I J : LieIdeal R L} {k l : ℕ} (h₁ : I ≤ J) (h₂ : l ≤ k) : D k I ≤ D l J := by revert l; induction' k with k ih <;> intro l h₂ · rw [le_zero_iff] at h₂; rw [h₂, derivedSeriesOfIdeal_zero]; exact h₁ · have h : l = k.succ ∨ l ≤ k := by rwa [le_iff_eq_or_lt, Nat.lt_succ_iff] at h₂ rcases h with h | h
· rw [h, derivedSeriesOfIdeal_succ, derivedSeriesOfIdeal_succ] exact LieSubmodule.mono_lie (ih (le_refl k)) (ih (le_refl k)) · rw [derivedSeriesOfIdeal_succ]; exact le_trans (LieSubmodule.lie_le_left _ _) (ih h) theorem derivedSeriesOfIdeal_succ_le (k : ℕ) : D (k + 1) I ≤ D k I := derivedSeriesOfIdeal_le (le_refl I) k.le_succ theorem derivedSeriesOfIdeal_le_self (k : ℕ) : D k I ≤ I := derivedSeriesOfIdeal_le (le_refl I) (zero_le k)
Mathlib/Algebra/Lie/Solvable.lean
89
97
/- Copyright (c) 2023 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.Group.Action.Pointwise.Finset import Mathlib.GroupTheory.QuotientGroup.Defs import Mathlib.Order.ConditionallyCompleteLattice.Basic /-! # Stabilizer of a set under a pointwise action This file characterises the stabilizer of a set/finset under the pointwise action of a group. -/ open Function MulOpposite Set open scoped Pointwise namespace MulAction variable {G H α : Type*} /-! ### Stabilizer of a set -/ section Set section Group variable [Group G] [Group H] [MulAction G α] {a : G} {s t : Set α} @[to_additive (attr := simp)] lemma stabilizer_empty : stabilizer G (∅ : Set α) = ⊤ := Subgroup.coe_eq_univ.1 <| eq_univ_of_forall fun _a ↦ smul_set_empty @[to_additive (attr := simp)] lemma stabilizer_univ : stabilizer G (Set.univ : Set α) = ⊤ := by ext simp @[to_additive (attr := simp)] lemma stabilizer_singleton (b : α) : stabilizer G ({b} : Set α) = stabilizer G b := by ext; simp @[to_additive] lemma mem_stabilizer_set {s : Set α} : a ∈ stabilizer G s ↔ ∀ b, a • b ∈ s ↔ b ∈ s := by refine mem_stabilizer_iff.trans ⟨fun h b ↦ ?_, fun h ↦ ?_⟩ · rw [← (smul_mem_smul_set_iff : a • b ∈ _ ↔ _), h] simp_rw [Set.ext_iff, mem_smul_set_iff_inv_smul_mem] exact ((MulAction.toPerm a).forall_congr' <| by simp [Iff.comm]).1 h @[to_additive] lemma map_stabilizer_le (f : G →* H) (s : Set G) : (stabilizer G s).map f ≤ stabilizer H (f '' s) := by rintro a simp only [Subgroup.mem_map, mem_stabilizer_iff, exists_prop, forall_exists_index, and_imp] rintro a ha rfl rw [← image_smul_distrib, ha] @[to_additive (attr := simp)] lemma stabilizer_mul_self (s : Set G) : (stabilizer G s : Set G) * s = s := by ext refine ⟨?_, fun h ↦ ⟨_, (stabilizer G s).one_mem, _, h, one_mul _⟩⟩ rintro ⟨a, ha, b, hb, rfl⟩ rw [← mem_stabilizer_iff.1 ha] exact smul_mem_smul_set hb @[to_additive] lemma stabilizer_inf_stabilizer_le_stabilizer_apply₂ {f : Set α → Set α → Set α} (hf : ∀ a : G, a • f s t = f (a • s) (a • t)) : stabilizer G s ⊓ stabilizer G t ≤ stabilizer G (f s t) := by aesop (add simp [SetLike.le_def]) @[to_additive] lemma stabilizer_inf_stabilizer_le_stabilizer_union : stabilizer G s ⊓ stabilizer G t ≤ stabilizer G (s ∪ t) := stabilizer_inf_stabilizer_le_stabilizer_apply₂ fun _ ↦ smul_set_union @[to_additive] lemma stabilizer_inf_stabilizer_le_stabilizer_inter : stabilizer G s ⊓ stabilizer G t ≤ stabilizer G (s ∩ t) := stabilizer_inf_stabilizer_le_stabilizer_apply₂ fun _ ↦ smul_set_inter @[to_additive] lemma stabilizer_inf_stabilizer_le_stabilizer_sdiff : stabilizer G s ⊓ stabilizer G t ≤ stabilizer G (s \ t) := stabilizer_inf_stabilizer_le_stabilizer_apply₂ fun _ ↦ smul_set_sdiff @[to_additive] lemma stabilizer_union_eq_left (hdisj : Disjoint s t) (hstab : stabilizer G s ≤ stabilizer G t) (hstab_union : stabilizer G (s ∪ t) ≤ stabilizer G t) : stabilizer G (s ∪ t) = stabilizer G s := by refine le_antisymm ?_ ?_ · calc stabilizer G (s ∪ t) ≤ stabilizer G (s ∪ t) ⊓ stabilizer G t := by simpa _ ≤ stabilizer G ((s ∪ t) \ t) := stabilizer_inf_stabilizer_le_stabilizer_sdiff _ = stabilizer G s := by rw [union_diff_cancel_right]; simpa [← disjoint_iff_inter_eq_empty] · calc stabilizer G s ≤ stabilizer G s ⊓ stabilizer G t := by simpa _ ≤ stabilizer G (s ∪ t) := stabilizer_inf_stabilizer_le_stabilizer_union @[to_additive] lemma stabilizer_union_eq_right (hdisj : Disjoint s t) (hstab : stabilizer G t ≤ stabilizer G s) (hstab_union : stabilizer G (s ∪ t) ≤ stabilizer G s) : stabilizer G (s ∪ t) = stabilizer G t := by rw [union_comm, stabilizer_union_eq_left hdisj.symm hstab (union_comm .. ▸ hstab_union)] variable {s : Set G} open scoped RightActions in @[to_additive] lemma op_smul_set_stabilizer_subset (ha : a ∈ s) : (stabilizer G s : Set G) <• a ⊆ s := smul_set_subset_iff.2 fun b hb ↦ by rw [← hb]; exact smul_mem_smul_set ha @[to_additive] lemma stabilizer_subset_div_right (ha : a ∈ s) : ↑(stabilizer G s) ⊆ s / {a} := fun b hb ↦ ⟨_, by rwa [← smul_eq_mul, mem_stabilizer_set.1 hb], _, mem_singleton _, mul_div_cancel_right _ _⟩ @[to_additive] lemma stabilizer_finite (hs₀ : s.Nonempty) (hs : s.Finite) : (stabilizer G s : Set G).Finite := by obtain ⟨a, ha⟩ := hs₀ exact (hs.div <| finite_singleton _).subset <| stabilizer_subset_div_right ha end Group section CommGroup variable [CommGroup G] {s t : Set G} {a : G} @[to_additive]
lemma smul_set_stabilizer_subset (ha : a ∈ s) : a • (stabilizer G s : Set G) ⊆ s := by simpa using op_smul_set_stabilizer_subset ha end CommGroup
Mathlib/Algebra/Pointwise/Stabilizer.lean
126
129
/- 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 clear t_ih_l' t_ih_r' have t_l_h := Valid'.erase_aux x h.left obtain ⟨t_l_valid, t_l_size⟩ := t_l_h rw [size_balanceR t_l_valid.bal h.right.bal t_l_valid.sz h.right.sz (Or.inl (Exists.intro t_l.size (And.intro t_l_size h.bal.1)))] rw [t_ih_l, h.sz.1] have h_pos_t_l_size := pos_size_of_mem h.left.sz h_mem revert h_pos_t_l_size; rcases t_l.size with - | t_l_size <;> intro h_pos_t_l_size · cases h_pos_t_l_size · simp [Nat.add_right_comm] · rw [(Valid'.glue h.left h.right h.bal.1).2, h.sz.1]; rfl · have t_ih_r := t_ih_r' h_mem clear t_ih_l' t_ih_r' have t_r_h := Valid'.erase_aux x h.right obtain ⟨t_r_valid, t_r_size⟩ := t_r_h rw [size_balanceL h.left.bal t_r_valid.bal h.left.sz t_r_valid.sz (Or.inr (Exists.intro t_r.size (And.intro t_r_size h.bal.1)))] rw [t_ih_r, h.sz.1] have h_pos_t_r_size := pos_size_of_mem h.right.sz h_mem revert h_pos_t_r_size; rcases t_r.size with - | t_r_size <;> intro h_pos_t_r_size · cases h_pos_t_r_size · simp [Nat.add_assoc] end Valid end Ordnode /-- An `Ordset α` is a finite set of values, represented as a tree. The operations on this type maintain that the tree is balanced and correctly stores subtree sizes at each level. The correctness property of the tree is baked into the type, so all operations on this type are correct by construction. -/ def Ordset (α : Type*) [Preorder α] := { t : Ordnode α // t.Valid } namespace Ordset open Ordnode variable [Preorder α] /-- O(1). The empty set. -/ nonrec def nil : Ordset α := ⟨nil, ⟨⟩, ⟨⟩, ⟨⟩⟩ /-- O(1). Get the size of the set. -/ def size (s : Ordset α) : ℕ := s.1.size /-- O(1). Construct a singleton set containing value `a`. -/ protected def singleton (a : α) : Ordset α := ⟨singleton a, valid_singleton⟩ instance instEmptyCollection : EmptyCollection (Ordset α) := ⟨nil⟩ instance instInhabited : Inhabited (Ordset α) := ⟨nil⟩ instance instSingleton : Singleton α (Ordset α) := ⟨Ordset.singleton⟩ /-- O(1). Is the set empty? -/ def Empty (s : Ordset α) : Prop := s = ∅ theorem empty_iff {s : Ordset α} : s = ∅ ↔ s.1.empty := ⟨fun h => by cases h; exact rfl, fun h => by cases s with | mk s_val _ => cases s_val <;> [rfl; cases h]⟩ instance Empty.instDecidablePred : DecidablePred (@Empty α _) := fun _ => decidable_of_iff' _ empty_iff /-- O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, this replaces it. -/ protected def insert [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) : Ordset α := ⟨Ordnode.insert x s.1, insert.valid _ s.2⟩ instance instInsert [IsTotal α (· ≤ ·)] [DecidableLE α] : Insert α (Ordset α) := ⟨Ordset.insert⟩ /-- O(log n). Insert an element into the set, preserving balance and the BST property. If an equivalent element is already in the set, the set is returned as is. -/ nonrec def insert' [IsTotal α (· ≤ ·)] [DecidableLE α] (x : α) (s : Ordset α) : Ordset α := ⟨insert' x s.1, insert'.valid _ s.2⟩ section variable [DecidableLE α] /-- O(log n). Does the set contain the element `x`? That is, is there an element that is equivalent to `x` in the order? -/ def mem (x : α) (s : Ordset α) : Bool := x ∈ s.val /-- O(log n). Retrieve an element in the set that is equivalent to `x` in the order, if it exists. -/ def find (x : α) (s : Ordset α) : Option α := Ordnode.find x s.val instance instMembership : Membership α (Ordset α) := ⟨fun s x => mem x s⟩ instance mem.decidable (x : α) (s : Ordset α) : Decidable (x ∈ s) := instDecidableEqBool _ _ theorem pos_size_of_mem {x : α} {t : Ordset α} (h_mem : x ∈ t) : 0 < size t := by simp? [Membership.mem, mem] at h_mem says simp only [Membership.mem, mem, Bool.decide_eq_true] at h_mem apply Ordnode.pos_size_of_mem t.property.sz h_mem end /-- O(log n). Remove an element from the set equivalent to `x`. Does nothing if there is no such element. -/ def erase [DecidableLE α] (x : α) (s : Ordset α) : Ordset α := ⟨Ordnode.erase x s.val, Ordnode.erase.valid x s.property⟩ /-- O(n). Map a function across a tree, without changing the structure. -/ def map {β} [Preorder β] (f : α → β) (f_strict_mono : StrictMono f) (s : Ordset α) : Ordset β := ⟨Ordnode.map f s.val, Ordnode.map.valid f_strict_mono s.property⟩ end Ordset
Mathlib/Data/Ordmap/Ordset.lean
922
924
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis -/ import Mathlib.Algebra.Polynomial.Identities import Mathlib.Analysis.SpecificLimits.Basic import Mathlib.NumberTheory.Padics.PadicIntegers import Mathlib.Topology.Algebra.Polynomial import Mathlib.Topology.MetricSpace.CauSeqFilter /-! # Hensel's lemma on ℤ_p This file proves Hensel's lemma on ℤ_p, roughly following Keith Conrad's writeup: <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf> Hensel's lemma gives a simple condition for the existence of a root of a polynomial. The proof and motivation are described in the paper [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]. ## References * <http://www.math.uconn.edu/~kconrad/blurbs/gradnumthy/hensel.pdf> * [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019] * <https://en.wikipedia.org/wiki/Hensel%27s_lemma> ## Tags p-adic, p adic, padic, p-adic integer -/ noncomputable section open Topology -- We begin with some general lemmas that are used below in the computation. theorem padic_polynomial_dist {p : ℕ} [Fact p.Prime] (F : Polynomial ℤ_[p]) (x y : ℤ_[p]) : ‖F.eval x - F.eval y‖ ≤ ‖x - y‖ := let ⟨z, hz⟩ := F.evalSubFactor x y calc ‖F.eval x - F.eval y‖ = ‖z‖ * ‖x - y‖ := by simp [hz] _ ≤ 1 * ‖x - y‖ := by gcongr; apply PadicInt.norm_le_one _ = ‖x - y‖ := by simp open Filter Metric private theorem comp_tendsto_lim {p : ℕ} [Fact p.Prime] {F : Polynomial ℤ_[p]} (ncs : CauSeq ℤ_[p] norm) : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 (F.eval ncs.lim)) := Filter.Tendsto.comp (@Polynomial.continuousAt _ _ _ _ F _) ncs.tendsto_limit section variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]} {a : ℤ_[p]} (ncs_der_val : ∀ n, ‖F.derivative.eval (ncs n)‖ = ‖F.derivative.eval a‖) private theorem ncs_tendsto_lim : Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval ncs.lim‖) := Tendsto.comp (continuous_iff_continuousAt.1 continuous_norm _) (comp_tendsto_lim _) include ncs_der_val private theorem ncs_tendsto_const : Tendsto (fun i => ‖F.derivative.eval (ncs i)‖) atTop (𝓝 ‖F.derivative.eval a‖) := by convert @tendsto_const_nhds ℝ _ ℕ _ _; rw [ncs_der_val] private theorem norm_deriv_eq : ‖F.derivative.eval ncs.lim‖ = ‖F.derivative.eval a‖ := tendsto_nhds_unique ncs_tendsto_lim (ncs_tendsto_const ncs_der_val) end section variable {p : ℕ} [Fact p.Prime] {ncs : CauSeq ℤ_[p] norm} {F : Polynomial ℤ_[p]} (hnorm : Tendsto (fun i => ‖F.eval (ncs i)‖) atTop (𝓝 0)) include hnorm private theorem tendsto_zero_of_norm_tendsto_zero : Tendsto (fun i => F.eval (ncs i)) atTop (𝓝 0) := tendsto_iff_norm_sub_tendsto_zero.2 (by simpa using hnorm) theorem limit_zero_of_norm_tendsto_zero : F.eval ncs.lim = 0 := tendsto_nhds_unique (comp_tendsto_lim _) (tendsto_zero_of_norm_tendsto_zero hnorm) end section Hensel open Nat variable (p : ℕ) [Fact p.Prime] (F : Polynomial ℤ_[p]) (a : ℤ_[p]) /-- `T` is an auxiliary value that is used to control the behavior of the polynomial `F`. -/ private def T_gen : ℝ := ‖F.eval a / ((F.derivative.eval a ^ 2 : ℤ_[p]) : ℚ_[p])‖ local notation "T" => @T_gen p _ F a variable {p F a} private theorem T_def : T = ‖F.eval a‖ / ‖F.derivative.eval a‖ ^ 2 := by simp [T_gen, ← PadicInt.norm_def] private theorem T_nonneg : 0 ≤ T := norm_nonneg _ private theorem T_pow_nonneg (n : ℕ) : 0 ≤ T ^ n := pow_nonneg T_nonneg _ variable (hnorm : ‖F.eval a‖ < ‖F.derivative.eval a‖ ^ 2) include hnorm private theorem deriv_sq_norm_pos : 0 < ‖F.derivative.eval a‖ ^ 2 := lt_of_le_of_lt (norm_nonneg _) hnorm private theorem deriv_sq_norm_ne_zero : ‖F.derivative.eval a‖ ^ 2 ≠ 0 := ne_of_gt (deriv_sq_norm_pos hnorm) private theorem deriv_norm_ne_zero : ‖F.derivative.eval a‖ ≠ 0 := fun h => deriv_sq_norm_ne_zero hnorm (by simp [*, sq]) private theorem deriv_norm_pos : 0 < ‖F.derivative.eval a‖ := lt_of_le_of_ne (norm_nonneg _) (Ne.symm (deriv_norm_ne_zero hnorm)) private theorem deriv_ne_zero : F.derivative.eval a ≠ 0 := mt norm_eq_zero.2 (deriv_norm_ne_zero hnorm) private theorem T_lt_one : T < 1 := by have h := (div_lt_one (deriv_sq_norm_pos hnorm)).2 hnorm rw [T_def]; exact h private theorem T_pow {n : ℕ} (hn : n ≠ 0) : T ^ n < 1 := pow_lt_one₀ T_nonneg (T_lt_one hnorm) hn private theorem T_pow' (n : ℕ) : T ^ 2 ^ n < 1 := T_pow hnorm (pow_ne_zero _ two_ne_zero) /-- We will construct a sequence of elements of ℤ_p satisfying successive values of `ih`. -/ private def ih_gen (n : ℕ) (z : ℤ_[p]) : Prop := ‖F.derivative.eval z‖ = ‖F.derivative.eval a‖ ∧ ‖F.eval z‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n local notation "ih" => @ih_gen p _ F a private theorem ih_0 : ih 0 a := ⟨rfl, by simp [T_def, mul_div_cancel₀ _ (ne_of_gt (deriv_sq_norm_pos hnorm))]⟩ private theorem calc_norm_le_one {n : ℕ} {z : ℤ_[p]} (hz : ih n z) : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1 := calc ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ = ‖(↑(F.eval z) : ℚ_[p])‖ / ‖(↑(F.derivative.eval z) : ℚ_[p])‖ := norm_div _ _ _ = ‖F.eval z‖ / ‖F.derivative.eval a‖ := by simp [hz.1] _ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := by gcongr apply hz.2 _ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _ _ ≤ 1 := mul_le_one₀ (PadicInt.norm_le_one _) (T_pow_nonneg _) (le_of_lt (T_pow' hnorm _)) private theorem calc_deriv_dist {z z' z1 : ℤ_[p]} (hz' : z' = z - z1) (hz1 : ‖z1‖ = ‖F.eval z‖ / ‖F.derivative.eval a‖) {n} (hz : ih n z) : ‖F.derivative.eval z' - F.derivative.eval z‖ < ‖F.derivative.eval a‖ := calc ‖F.derivative.eval z' - F.derivative.eval z‖ ≤ ‖z' - z‖ := padic_polynomial_dist _ _ _ _ = ‖z1‖ := by simp only [sub_eq_add_neg, add_assoc, hz', add_add_neg_cancel'_right, norm_neg] _ = ‖F.eval z‖ / ‖F.derivative.eval a‖ := hz1 _ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := by gcongr apply hz.2 _ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _ _ < ‖F.derivative.eval a‖ := (mul_lt_iff_lt_one_right (deriv_norm_pos hnorm)).2 (T_pow' hnorm _) private def calc_eval_z' {z z' z1 : ℤ_[p]} (hz' : z' = z - z1) {n} (hz : ih n z) (h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1) (hzeq : z1 = ⟨_, h1⟩) : { q : ℤ_[p] // F.eval z' = q * z1 ^ 2 } := by have hdzne : F.derivative.eval z ≠ 0 := mt norm_eq_zero.2 (by rw [hz.1]; apply deriv_norm_ne_zero; assumption) have hdzne' : (↑(F.derivative.eval z) : ℚ_[p]) ≠ 0 := fun h => hdzne (Subtype.ext_iff_val.2 h) obtain ⟨q, hq⟩ := F.binomExpansion z (-z1) have : ‖(↑(F.derivative.eval z) * (↑(F.eval z) / ↑(F.derivative.eval z)) : ℚ_[p])‖ ≤ 1 := by rw [padicNormE.mul] exact mul_le_one₀ (PadicInt.norm_le_one _) (norm_nonneg _) h1 have : F.derivative.eval z * -z1 = -F.eval z := by calc F.derivative.eval z * -z1 = F.derivative.eval z * -⟨↑(F.eval z) / ↑(F.derivative.eval z), h1⟩ := by rw [hzeq] _ = -(F.derivative.eval z * ⟨↑(F.eval z) / ↑(F.derivative.eval z), h1⟩) := mul_neg _ _ _ = -⟨F.derivative.eval z * (F.eval z / (F.derivative.eval z : ℤ_[p]) : ℚ_[p]), this⟩ := (Subtype.ext <| by simp only [PadicInt.coe_neg, PadicInt.coe_mul, Subtype.coe_mk]) _ = -F.eval z := by simp only [mul_div_cancel₀ _ hdzne', Subtype.coe_eta] exact ⟨q, by simpa only [sub_eq_add_neg, this, hz', add_neg_cancel, neg_sq, zero_add] using hq⟩ private def calc_eval_z'_norm {z z' z1 : ℤ_[p]} {n} (hz : ih n z) {q} (heq : F.eval z' = q * z1 ^ 2) (h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1) (hzeq : z1 = ⟨_, h1⟩) : ‖F.eval z'‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ (n + 1) := by calc ‖F.eval z'‖ = ‖q‖ * ‖z1‖ ^ 2 := by simp [heq] _ ≤ 1 * ‖z1‖ ^ 2 := by gcongr; apply PadicInt.norm_le_one _ = ‖F.eval z‖ ^ 2 / ‖F.derivative.eval a‖ ^ 2 := by simp [hzeq, hz.1, div_pow] _ ≤ (‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n) ^ 2 / ‖F.derivative.eval a‖ ^ 2 := by gcongr exact hz.2 _ = (‖F.derivative.eval a‖ ^ 2) ^ 2 * (T ^ 2 ^ n) ^ 2 / ‖F.derivative.eval a‖ ^ 2 := by simp only [mul_pow] _ = ‖F.derivative.eval a‖ ^ 2 * (T ^ 2 ^ n) ^ 2 := div_sq_cancel _ _ _ = ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ (n + 1) := by rw [← pow_mul, pow_succ 2] /-- Given `z : ℤ_[p]` satisfying `ih n z`, construct `z' : ℤ_[p]` satisfying `ih (n+1) z'`. We need the hypothesis `ih n z`, since otherwise `z'` is not necessarily an integer. -/ private def ih_n {n : ℕ} {z : ℤ_[p]} (hz : ih n z) : { z' : ℤ_[p] // ih (n + 1) z' } := have h1 : ‖(↑(F.eval z) : ℚ_[p]) / ↑(F.derivative.eval z)‖ ≤ 1 := calc_norm_le_one hnorm hz let z1 : ℤ_[p] := ⟨_, h1⟩ let z' : ℤ_[p] := z - z1 ⟨z', have hdist : ‖F.derivative.eval z' - F.derivative.eval z‖ < ‖F.derivative.eval a‖ := calc_deriv_dist hnorm rfl (by simp [z1, hz.1]) hz have hfeq : ‖F.derivative.eval z'‖ = ‖F.derivative.eval a‖ := by rw [sub_eq_add_neg, ← hz.1, ← norm_neg (F.derivative.eval z)] at hdist have := PadicInt.norm_eq_of_norm_add_lt_right hdist rwa [norm_neg, hz.1] at this let ⟨_, heq⟩ := calc_eval_z' hnorm rfl hz h1 rfl have hnle : ‖F.eval z'‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ (n + 1) := calc_eval_z'_norm hz heq h1 rfl ⟨hfeq, hnle⟩⟩ private def newton_seq_aux : ∀ n : ℕ, { z : ℤ_[p] // ih n z } | 0 => ⟨a, ih_0 hnorm⟩ | k + 1 => ih_n hnorm (newton_seq_aux k).2 private def newton_seq_gen (n : ℕ) : ℤ_[p] := (newton_seq_aux hnorm n).1 local notation "newton_seq" => newton_seq_gen hnorm private theorem newton_seq_deriv_norm (n : ℕ) : ‖F.derivative.eval (newton_seq n)‖ = ‖F.derivative.eval a‖ := (newton_seq_aux hnorm n).2.1 private theorem newton_seq_norm_le (n : ℕ) : ‖F.eval (newton_seq n)‖ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n := (newton_seq_aux hnorm n).2.2 private theorem newton_seq_norm_eq (n : ℕ) : ‖newton_seq (n + 1) - newton_seq n‖ = ‖F.eval (newton_seq n)‖ / ‖F.derivative.eval (newton_seq n)‖ := by rw [newton_seq_gen, newton_seq_gen, newton_seq_aux, ih_n] simp [sub_eq_add_neg, add_comm] private theorem newton_seq_succ_dist (n : ℕ) : ‖newton_seq (n + 1) - newton_seq n‖ ≤ ‖F.derivative.eval a‖ * T ^ 2 ^ n := calc ‖newton_seq (n + 1) - newton_seq n‖ = ‖F.eval (newton_seq n)‖ / ‖F.derivative.eval (newton_seq n)‖ := newton_seq_norm_eq hnorm _ _ = ‖F.eval (newton_seq n)‖ / ‖F.derivative.eval a‖ := by rw [newton_seq_deriv_norm] _ ≤ ‖F.derivative.eval a‖ ^ 2 * T ^ 2 ^ n / ‖F.derivative.eval a‖ := ((div_le_div_iff_of_pos_right (deriv_norm_pos hnorm)).2 (newton_seq_norm_le hnorm _)) _ = ‖F.derivative.eval a‖ * T ^ 2 ^ n := div_sq_cancel _ _ private theorem newton_seq_dist_aux (n : ℕ) :
∀ k : ℕ, ‖newton_seq (n + k) - newton_seq n‖ ≤ ‖F.derivative.eval a‖ * T ^ 2 ^ n | 0 => by simp [T_pow_nonneg, mul_nonneg] | k + 1 => have : 2 ^ n ≤ 2 ^ (n + k) := by apply pow_right_mono₀ · norm_num · apply Nat.le_add_right calc ‖newton_seq (n + (k + 1)) - newton_seq n‖ = ‖newton_seq (n + k + 1) - newton_seq n‖ := by rw [add_assoc]
Mathlib/NumberTheory/Padics/Hensel.lean
264
273
/- 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]
Mathlib/Analysis/SpecialFunctions/Pow/Complex.lean
80
82
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) : (⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ · exact mk_toType o · exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) : (a ^ b).card ≤ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ · simpa using one_lt_omega0.le.trans ha · intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add · rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha · rwa [aleph0_le_card] · intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) · simpa using hb.pos.ne' · refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ · exact Cardinal.bddAbove_of_small _ · simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) : (a ^ b).card ≤ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] · exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b · rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le · exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) · exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a hb · exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a (omega0_pos.trans_le hb) · exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o · rw [omega_zero] exact principal_opow_omega0 · intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊢ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· ^ ·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· + ·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· * ·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
225
228
/- 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.Algebra.Group.Units.Equiv import Mathlib.CategoryTheory.Endomorphism import Mathlib.CategoryTheory.HomCongr /-! # Conjugate morphisms by isomorphisms An isomorphism `α : X ≅ Y` defines - a monoid isomorphism `CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`; - a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by `α.conjAut f = α.symm ≪≫ f ≪≫ α` using `CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)` and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)` which are defined in `CategoryTheory.HomCongr`. -/ universe v u namespace CategoryTheory namespace Iso variable {C : Type u} [Category.{v} C] variable {X Y : C} (α : X ≅ Y) /-- An isomorphism between two objects defines a monoid isomorphism between their monoid of endomorphisms. -/ def conj : End X ≃* End Y := { homCongr α α with map_mul' := fun f g => homCongr_comp α α α g f } theorem conj_apply (f : End X) : α.conj f = α.inv ≫ f ≫ α.hom := rfl @[simp] theorem conj_comp (f g : End X) : α.conj (f ≫ g) = α.conj f ≫ α.conj g := map_mul α.conj g f @[simp] theorem conj_id : α.conj (𝟙 X) = 𝟙 Y := map_one α.conj @[simp] theorem refl_conj (f : End X) : (Iso.refl X).conj f = f := by rw [conj_apply, Iso.refl_inv, Iso.refl_hom, Category.id_comp, Category.comp_id] @[simp]
theorem trans_conj {Z : C} (β : Y ≅ Z) (f : End X) : (α ≪≫ β).conj f = β.conj (α.conj f) := homCongr_trans α α β β f
Mathlib/CategoryTheory/Conj.lean
55
56
/- Copyright (c) 2024 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Group import Mathlib.NumberTheory.EllipticDivisibilitySequence /-! # Division polynomials of Weierstrass curves This file defines certain polynomials associated to division polynomials of Weierstrass curves. These are defined in terms of the auxiliary sequences for normalised elliptic divisibility sequences (EDS) as defined in `Mathlib.NumberTheory.EllipticDivisibilitySequence`. ## Mathematical background Let `W` be a Weierstrass curve over a commutative ring `R`. The sequence of `n`-division polynomials `ψₙ ∈ R[X, Y]` of `W` is the normalised EDS with initial values * `ψ₀ := 0`, * `ψ₁ := 1`, * `ψ₂ := 2Y + a₁X + a₃`, * `ψ₃ := 3X⁴ + b₂X³ + 3b₄X² + 3b₆X + b₈`, and * `ψ₄ := ψ₂ ⬝ (2X⁶ + b₂X⁵ + 5b₄X⁴ + 10b₆X³ + 10b₈X² + (b₂b₈ - b₄b₆)X + (b₄b₈ - b₆²))`. Furthermore, define the associated sequences `φₙ, ωₙ ∈ R[X, Y]` by * `φₙ := Xψₙ² - ψₙ₊₁ ⬝ ψₙ₋₁`, and * `ωₙ := (ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)) / 2`. Note that `ωₙ` is always well-defined as a polynomial in `R[X, Y]`. As a start, it can be shown by induction that `ψₙ` always divides `ψ₂ₙ` in `R[X, Y]`, so that `ψ₂ₙ / ψₙ` is always well-defined as a polynomial, while division by `2` is well-defined when `R` has characteristic different from `2`. In general, it can be shown that `2` always divides the polynomial `ψ₂ₙ / ψₙ - ψₙ ⬝ (a₁φₙ + a₃ψₙ²)` in the characteristic `0` universal ring `𝓡[X, Y] := ℤ[A₁, A₂, A₃, A₄, A₆][X, Y]` of `W`, where the `Aᵢ` are indeterminates. Then `ωₙ` can be equivalently defined as the image of this division under the associated universal morphism `𝓡[X, Y] → R[X, Y]` mapping `Aᵢ` to `aᵢ`. Now, in the coordinate ring `R[W]`, note that `ψ₂²` is congruent to the polynomial `Ψ₂Sq := 4X³ + b₂X² + 2b₄X + b₆ ∈ R[X]`. As such, the recurrences of a normalised EDS show that `ψₙ / ψ₂` are congruent to certain polynomials in `R[W]`. In particular, define `preΨₙ ∈ R[X]` as the auxiliary sequence for a normalised EDS with extra parameter `Ψ₂Sq²` and initial values * `preΨ₀ := 0`, * `preΨ₁ := 1`, * `preΨ₂ := 1`, * `preΨ₃ := ψ₃`, and * `preΨ₄ := ψ₄ / ψ₂`. The corresponding normalised EDS `Ψₙ ∈ R[X, Y]` is then given by * `Ψₙ := preΨₙ ⬝ ψ₂` if `n` is even, and * `Ψₙ := preΨₙ` if `n` is odd. Furthermore, define the associated sequences `ΨSqₙ, Φₙ ∈ R[X]` by * `ΨSqₙ := preΨₙ² ⬝ Ψ₂Sq` if `n` is even, * `ΨSqₙ := preΨₙ²` if `n` is odd, * `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁` if `n` is even, and * `Φₙ := XΨSqₙ - preΨₙ₊₁ ⬝ preΨₙ₋₁ ⬝ Ψ₂Sq` if `n` is odd. With these definitions, `ψₙ ∈ R[X, Y]` and `φₙ ∈ R[X, Y]` are congruent in `R[W]` to `Ψₙ ∈ R[X, Y]` and `Φₙ ∈ R[X]` respectively, which are defined in terms of `Ψ₂Sq ∈ R[X]` and `preΨₙ ∈ R[X]`. ## Main definitions * `WeierstrassCurve.preΨ`: the univariate polynomials `preΨₙ`. * `WeierstrassCurve.ΨSq`: the univariate polynomials `ΨSqₙ`. * `WeierstrassCurve.Ψ`: the bivariate polynomials `Ψₙ`. * `WeierstrassCurve.Φ`: the univariate polynomials `Φₙ`. * `WeierstrassCurve.ψ`: the bivariate `n`-division polynomials `ψₙ`. * `WeierstrassCurve.φ`: the bivariate polynomials `φₙ`. * TODO: the bivariate polynomials `ωₙ`. ## Implementation notes Analogously to `Mathlib.NumberTheory.EllipticDivisibilitySequence`, the bivariate polynomials `Ψₙ` are defined in terms of the univariate polynomials `preΨₙ`. This is done partially to avoid ring division, but more crucially to allow the definition of `ΨSqₙ` and `Φₙ` as univariate polynomials without needing to work under the coordinate ring, and to allow the computation of their leading terms without ambiguity. Furthermore, evaluating these polynomials at a rational point on `W` recovers their original definition up to linear combinations of the Weierstrass equation of `W`, hence also avoiding the need to work in the coordinate ring. TODO: implementation notes for the definition of `ωₙ`. ## References [J Silverman, *The Arithmetic of Elliptic Curves*][silverman2009] ## Tags elliptic curve, division polynomial, torsion point -/ open Polynomial open scoped Polynomial.Bivariate local macro "C_simp" : tactic => `(tactic| simp only [map_ofNat, C_0, C_1, C_neg, C_add, C_sub, C_mul, C_pow]) local macro "map_simp" : tactic => `(tactic| simp only [map_ofNat, map_neg, map_add, map_sub, map_mul, map_pow, map_div₀, Polynomial.map_ofNat, Polynomial.map_one, map_C, map_X, Polynomial.map_neg, Polynomial.map_add, Polynomial.map_sub, Polynomial.map_mul, Polynomial.map_pow, Polynomial.map_div, coe_mapRingHom, apply_ite <| mapRingHom _, WeierstrassCurve.map]) universe r s u v namespace WeierstrassCurve variable {R : Type r} {S : Type s} [CommRing R] [CommRing S] (W : WeierstrassCurve R) section Ψ₂Sq /-! ### The univariate polynomial `Ψ₂Sq` -/ /-- The `2`-division polynomial `ψ₂ = Ψ₂`. -/ noncomputable def ψ₂ : R[X][Y] := W.toAffine.polynomialY /-- The univariate polynomial `Ψ₂Sq` congruent to `ψ₂²`. -/ noncomputable def Ψ₂Sq : R[X] := C 4 * X ^ 3 + C W.b₂ * X ^ 2 + C (2 * W.b₄) * X + C W.b₆ lemma C_Ψ₂Sq : C W.Ψ₂Sq = W.ψ₂ ^ 2 - 4 * W.toAffine.polynomial := by rw [Ψ₂Sq, ψ₂, b₂, b₄, b₆, Affine.polynomialY, Affine.polynomial] C_simp ring1 lemma ψ₂_sq : W.ψ₂ ^ 2 = C W.Ψ₂Sq + 4 * W.toAffine.polynomial := by rw [C_Ψ₂Sq, sub_add_cancel] lemma Affine.CoordinateRing.mk_ψ₂_sq : mk W W.ψ₂ ^ 2 = mk W (C W.Ψ₂Sq) := by rw [C_Ψ₂Sq, map_sub, map_mul, AdjoinRoot.mk_self, mul_zero, sub_zero, map_pow] -- TODO: remove `twoTorsionPolynomial` in favour of `Ψ₂Sq` lemma Ψ₂Sq_eq : W.Ψ₂Sq = W.twoTorsionPolynomial.toPoly := rfl end Ψ₂Sq section preΨ' /-! ### The univariate polynomials `preΨₙ` for `n ∈ ℕ` -/ /-- The `3`-division polynomial `ψ₃ = Ψ₃`. -/ noncomputable def Ψ₃ : R[X] := 3 * X ^ 4 + C W.b₂ * X ^ 3 + 3 * C W.b₄ * X ^ 2 + 3 * C W.b₆ * X + C W.b₈ /-- The univariate polynomial `preΨ₄`, which is auxiliary to the 4-division polynomial `ψ₄ = Ψ₄ = preΨ₄ψ₂`. -/ noncomputable def preΨ₄ : R[X] := 2 * X ^ 6 + C W.b₂ * X ^ 5 + 5 * C W.b₄ * X ^ 4 + 10 * C W.b₆ * X ^ 3 + 10 * C W.b₈ * X ^ 2 + C (W.b₂ * W.b₈ - W.b₄ * W.b₆) * X + C (W.b₄ * W.b₈ - W.b₆ ^ 2) /-- The univariate polynomials `preΨₙ` for `n ∈ ℕ`, which are auxiliary to the bivariate polynomials `Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/ noncomputable def preΨ' (n : ℕ) : R[X] := preNormEDS' (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n @[simp] lemma preΨ'_zero : W.preΨ' 0 = 0 := preNormEDS'_zero .. @[simp] lemma preΨ'_one : W.preΨ' 1 = 1 := preNormEDS'_one .. @[simp] lemma preΨ'_two : W.preΨ' 2 = 1 := preNormEDS'_two .. @[simp] lemma preΨ'_three : W.preΨ' 3 = W.Ψ₃ := preNormEDS'_three .. @[simp] lemma preΨ'_four : W.preΨ' 4 = W.preΨ₄ := preNormEDS'_four .. lemma preΨ'_even (m : ℕ) : W.preΨ' (2 * (m + 3)) = W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) - W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2 := preNormEDS'_even .. lemma preΨ'_odd (m : ℕ) : W.preΨ' (2 * (m + 2) + 1) = W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS'_odd .. end preΨ' section preΨ /-! ### The univariate polynomials `preΨₙ` for `n ∈ ℤ` -/ /-- The univariate polynomials `preΨₙ` for `n ∈ ℤ`, which are auxiliary to the bivariate polynomials `Ψₙ` congruent to the bivariate `n`-division polynomials `ψₙ`. -/ noncomputable def preΨ (n : ℤ) : R[X] := preNormEDS (W.Ψ₂Sq ^ 2) W.Ψ₃ W.preΨ₄ n @[simp] lemma preΨ_ofNat (n : ℕ) : W.preΨ n = W.preΨ' n := preNormEDS_ofNat .. @[simp] lemma preΨ_zero : W.preΨ 0 = 0 := preNormEDS_zero .. @[simp] lemma preΨ_one : W.preΨ 1 = 1 := preNormEDS_one .. @[simp] lemma preΨ_two : W.preΨ 2 = 1 := preNormEDS_two .. @[simp] lemma preΨ_three : W.preΨ 3 = W.Ψ₃ := preNormEDS_three .. @[simp] lemma preΨ_four : W.preΨ 4 = W.preΨ₄ := preNormEDS_four .. lemma preΨ_even_ofNat (m : ℕ) : W.preΨ (2 * (m + 3)) = W.preΨ (m + 2) ^ 2 * W.preΨ (m + 3) * W.preΨ (m + 5) - W.preΨ (m + 1) * W.preΨ (m + 3) * W.preΨ (m + 4) ^ 2 := preNormEDS_even_ofNat .. lemma preΨ_odd_ofNat (m : ℕ) : W.preΨ (2 * (m + 2) + 1) = W.preΨ (m + 4) * W.preΨ (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m + 1) * W.preΨ (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS_odd_ofNat .. @[simp] lemma preΨ_neg (n : ℤ) : W.preΨ (-n) = -W.preΨ n := preNormEDS_neg .. lemma preΨ_even (m : ℤ) : W.preΨ (2 * m) = W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) - W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2 := preNormEDS_even .. lemma preΨ_odd (m : ℤ) : W.preΨ (2 * m + 1) = W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2) := preNormEDS_odd .. end preΨ section ΨSq /-! ### The univariate polynomials `ΨSqₙ` -/ /-- The univariate polynomials `ΨSqₙ` congruent to `ψₙ²`. -/ noncomputable def ΨSq (n : ℤ) : R[X] := W.preΨ n ^ 2 * if Even n then W.Ψ₂Sq else 1 @[simp] lemma ΨSq_ofNat (n : ℕ) : W.ΨSq n = W.preΨ' n ^ 2 * if Even n then W.Ψ₂Sq else 1 := by simp only [ΨSq, preΨ_ofNat, Int.even_coe_nat] @[simp] lemma ΨSq_zero : W.ΨSq 0 = 0 := by rw [← Nat.cast_zero, ΨSq_ofNat, preΨ'_zero, zero_pow two_ne_zero, zero_mul] @[simp] lemma ΨSq_one : W.ΨSq 1 = 1 := by rw [← Nat.cast_one, ΨSq_ofNat, preΨ'_one, one_pow, one_mul, if_neg Nat.not_even_one] @[simp] lemma ΨSq_two : W.ΨSq 2 = W.Ψ₂Sq := by rw [← Nat.cast_two, ΨSq_ofNat, preΨ'_two, one_pow, one_mul, if_pos even_two] @[simp] lemma ΨSq_three : W.ΨSq 3 = W.Ψ₃ ^ 2 := by rw [← Nat.cast_three, ΨSq_ofNat, preΨ'_three, if_neg <| by decide, mul_one] @[simp] lemma ΨSq_four : W.ΨSq 4 = W.preΨ₄ ^ 2 * W.Ψ₂Sq := by rw [← Nat.cast_four, ΨSq_ofNat, preΨ'_four, if_pos <| by decide] lemma ΨSq_even_ofNat (m : ℕ) : W.ΨSq (2 * (m + 3)) = (W.preΨ' (m + 2) ^ 2 * W.preΨ' (m + 3) * W.preΨ' (m + 5) - W.preΨ' (m + 1) * W.preΨ' (m + 3) * W.preΨ' (m + 4) ^ 2) ^ 2 * W.Ψ₂Sq := by rw_mod_cast [ΨSq_ofNat, preΨ'_even, if_pos <| even_two_mul _] lemma ΨSq_odd_ofNat (m : ℕ) : W.ΨSq (2 * (m + 2) + 1) = (W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by rw_mod_cast [ΨSq_ofNat, preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, mul_one] @[simp] lemma ΨSq_neg (n : ℤ) : W.ΨSq (-n) = W.ΨSq n := by simp only [ΨSq, preΨ_neg, neg_sq, even_neg] lemma ΨSq_even (m : ℤ) : W.ΨSq (2 * m) = (W.preΨ (m - 1) ^ 2 * W.preΨ m * W.preΨ (m + 2) - W.preΨ (m - 2) * W.preΨ m * W.preΨ (m + 1) ^ 2) ^ 2 * W.Ψ₂Sq := by rw [ΨSq, preΨ_even, if_pos <| even_two_mul _] lemma ΨSq_odd (m : ℤ) : W.ΨSq (2 * m + 1) = (W.preΨ (m + 2) * W.preΨ m ^ 3 * (if Even m then W.Ψ₂Sq ^ 2 else 1) - W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3 * (if Even m then 1 else W.Ψ₂Sq ^ 2)) ^ 2 := by rw [ΨSq, preΨ_odd, if_neg m.not_even_two_mul_add_one, mul_one] end ΨSq section Ψ /-! ### The bivariate polynomials `Ψₙ` -/ /-- The bivariate polynomials `Ψₙ` congruent to the `n`-division polynomials `ψₙ`. -/ protected noncomputable def Ψ (n : ℤ) : R[X][Y] := C (W.preΨ n) * if Even n then W.ψ₂ else 1 open WeierstrassCurve (Ψ) @[simp] lemma Ψ_ofNat (n : ℕ) : W.Ψ n = C (W.preΨ' n) * if Even n then W.ψ₂ else 1 := by simp only [Ψ, preΨ_ofNat, Int.even_coe_nat] @[simp] lemma Ψ_zero : W.Ψ 0 = 0 := by rw [← Nat.cast_zero, Ψ_ofNat, preΨ'_zero, C_0, zero_mul] @[simp] lemma Ψ_one : W.Ψ 1 = 1 := by rw [← Nat.cast_one, Ψ_ofNat, preΨ'_one, C_1, if_neg Nat.not_even_one, mul_one] @[simp] lemma Ψ_two : W.Ψ 2 = W.ψ₂ := by rw [← Nat.cast_two, Ψ_ofNat, preΨ'_two, C_1, one_mul, if_pos even_two] @[simp] lemma Ψ_three : W.Ψ 3 = C W.Ψ₃ := by rw [← Nat.cast_three, Ψ_ofNat, preΨ'_three, if_neg <| by decide, mul_one] @[simp] lemma Ψ_four : W.Ψ 4 = C W.preΨ₄ * W.ψ₂ := by rw [← Nat.cast_four, Ψ_ofNat, preΨ'_four, if_pos <| by decide] lemma Ψ_even_ofNat (m : ℕ) : W.Ψ (2 * (m + 3)) * W.ψ₂ = W.Ψ (m + 2) ^ 2 * W.Ψ (m + 3) * W.Ψ (m + 5) - W.Ψ (m + 1) * W.Ψ (m + 3) * W.Ψ (m + 4) ^ 2 := by repeat rw_mod_cast [Ψ_ofNat] simp_rw [preΨ'_even, if_pos <| even_two_mul _, Nat.even_add_one, ite_not] split_ifs <;> C_simp <;> ring1 lemma Ψ_odd_ofNat (m : ℕ) : W.Ψ (2 * (m + 2) + 1) = W.Ψ (m + 4) * W.Ψ (m + 2) ^ 3 - W.Ψ (m + 1) * W.Ψ (m + 3) ^ 3 + W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) * C (if Even m then W.preΨ' (m + 4) * W.preΨ' (m + 2) ^ 3 else -W.preΨ' (m + 1) * W.preΨ' (m + 3) ^ 3) := by repeat rw_mod_cast [Ψ_ofNat] simp_rw [preΨ'_odd, if_neg (m + 2).not_even_two_mul_add_one, Nat.even_add_one, ite_not] split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1 @[simp] lemma Ψ_neg (n : ℤ) : W.Ψ (-n) = -W.Ψ n := by simp only [Ψ, preΨ_neg, C_neg, neg_mul (α := R[X][Y]), even_neg] lemma Ψ_even (m : ℤ) : W.Ψ (2 * m) * W.ψ₂ = W.Ψ (m - 1) ^ 2 * W.Ψ m * W.Ψ (m + 2) - W.Ψ (m - 2) * W.Ψ m * W.Ψ (m + 1) ^ 2 := by repeat rw [Ψ] simp_rw [preΨ_even, if_pos <| even_two_mul _, Int.even_add_one, show m + 2 = m + 1 + 1 by ring1, Int.even_add_one, show m - 2 = m - 1 - 1 by ring1, Int.even_sub_one, ite_not] split_ifs <;> C_simp <;> ring1 lemma Ψ_odd (m : ℤ) : W.Ψ (2 * m + 1) = W.Ψ (m + 2) * W.Ψ m ^ 3 - W.Ψ (m - 1) * W.Ψ (m + 1) ^ 3 + W.toAffine.polynomial * (16 * W.toAffine.polynomial - 8 * W.ψ₂ ^ 2) * C (if Even m then W.preΨ (m + 2) * W.preΨ m ^ 3 else -W.preΨ (m - 1) * W.preΨ (m + 1) ^ 3) := by repeat rw [Ψ] simp_rw [preΨ_odd, if_neg m.not_even_two_mul_add_one, show m + 2 = m + 1 + 1 by ring1, Int.even_add_one, Int.even_sub_one, ite_not] split_ifs <;> C_simp <;> rw [C_Ψ₂Sq] <;> ring1 lemma Affine.CoordinateRing.mk_Ψ_sq (n : ℤ) : mk W (W.Ψ n) ^ 2 = mk W (C <| W.ΨSq n) := by simp only [Ψ, ΨSq, map_one, map_mul, map_pow, one_pow, mul_pow, ite_pow, apply_ite C, apply_ite <| mk W, mk_ψ₂_sq] end Ψ section Φ /-! ### The univariate polynomials `Φₙ` -/ /-- The univariate polynomials `Φₙ` congruent to `φₙ`. -/ protected noncomputable def Φ (n : ℤ) : R[X] := X * W.ΨSq n - W.preΨ (n + 1) * W.preΨ (n - 1) * if Even n then 1 else W.Ψ₂Sq open WeierstrassCurve (Φ) @[simp] lemma Φ_ofNat (n : ℕ) : W.Φ (n + 1) = X * W.preΨ' (n + 1) ^ 2 * (if Even n then 1 else W.Ψ₂Sq) - W.preΨ' (n + 2) * W.preΨ' n * (if Even n then W.Ψ₂Sq else 1) := by rw [Φ, ← Nat.cast_one, ← Nat.cast_add, ΨSq_ofNat, ← mul_assoc, ← Nat.cast_add, preΨ_ofNat, Nat.cast_add, add_sub_cancel_right, preΨ_ofNat, ← Nat.cast_add] simp only [Nat.even_add_one, Int.even_add_one, Int.even_coe_nat, ite_not] @[simp] lemma Φ_zero : W.Φ 0 = 1 := by rw [Φ, ΨSq_zero, mul_zero, zero_sub, zero_add, preΨ_one, one_mul, zero_sub, preΨ_neg, preΨ_one, neg_one_mul, neg_neg, if_pos Even.zero] @[simp] lemma Φ_one : W.Φ 1 = X := by rw [show 1 = ((0 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_one, one_pow, mul_one, if_pos Even.zero, mul_one, preΨ'_zero, mul_zero, zero_mul, sub_zero] @[simp] lemma Φ_two : W.Φ 2 = X ^ 4 - C W.b₄ * X ^ 2 - C (2 * W.b₆) * X - C W.b₈ := by rw [show 2 = ((1 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_two, if_neg Nat.not_even_one, Ψ₂Sq, preΨ'_three, preΨ'_one, if_neg Nat.not_even_one, Ψ₃] C_simp ring1 @[simp] lemma Φ_three : W.Φ 3 = X * W.Ψ₃ ^ 2 - W.preΨ₄ * W.Ψ₂Sq := by rw [show 3 = ((2 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_three, if_pos <| by decide, mul_one, preΨ'_four, preΨ'_two, mul_one, if_pos even_two] @[simp] lemma Φ_four : W.Φ 4 = X * W.preΨ₄ ^ 2 * W.Ψ₂Sq - W.Ψ₃ * (W.preΨ₄ * W.Ψ₂Sq ^ 2 - W.Ψ₃ ^ 3) := by rw [show 4 = ((3 : ℕ) + 1 : ℤ) by rfl, Φ_ofNat, preΨ'_four, if_neg <| by decide, show 3 + 2 = 2 * 2 + 1 by rfl, preΨ'_odd, preΨ'_four, preΨ'_two, if_pos Even.zero, preΨ'_one, preΨ'_three, if_pos Even.zero, if_neg <| by decide] ring1 @[simp] lemma Φ_neg (n : ℤ) : W.Φ (-n) = W.Φ n := by simp only [Φ, ΨSq_neg, neg_add_eq_sub, ← neg_sub n, preΨ_neg, ← neg_add', preΨ_neg, neg_mul_neg, mul_comm <| W.preΨ <| n - 1, even_neg] end Φ section ψ /-! ### The bivariate polynomials `ψₙ` -/ /-- The bivariate `n`-division polynomials `ψₙ`. -/ protected noncomputable def ψ (n : ℤ) : R[X][Y] := normEDS W.ψ₂ (C W.Ψ₃) (C W.preΨ₄) n open WeierstrassCurve (Ψ ψ) @[simp] lemma ψ_zero : W.ψ 0 = 0 := normEDS_zero .. @[simp] lemma ψ_one : W.ψ 1 = 1 := normEDS_one .. @[simp] lemma ψ_two : W.ψ 2 = W.ψ₂ := normEDS_two .. @[simp] lemma ψ_three : W.ψ 3 = C W.Ψ₃ :=
normEDS_three .. @[simp]
Mathlib/AlgebraicGeometry/EllipticCurve/DivisionPolynomial/Basic.lean
461
463
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.GCDMonoid.Basic import Mathlib.Algebra.Order.Group.Multiset import Mathlib.Data.Multiset.FinsetOps import Mathlib.Data.Multiset.Fold /-! # GCD and LCM operations on multisets ## Main definitions - `Multiset.gcd` - the greatest common denominator of a `Multiset` of elements of a `GCDMonoid` - `Multiset.lcm` - the least common multiple of a `Multiset` of elements of a `GCDMonoid` ## Implementation notes TODO: simplify with a tactic and `Data.Multiset.Lattice` ## Tags multiset, gcd -/ namespace Multiset variable {α : Type*} [CancelCommMonoidWithZero α] [NormalizedGCDMonoid α] /-! ### LCM -/ section lcm /-- Least common multiple of a multiset -/ def lcm (s : Multiset α) : α := s.fold GCDMonoid.lcm 1 @[simp] theorem lcm_zero : (0 : Multiset α).lcm = 1 := fold_zero _ _ @[simp] theorem lcm_cons (a : α) (s : Multiset α) : (a ::ₘ s).lcm = GCDMonoid.lcm a s.lcm := fold_cons_left _ _ _ _ @[simp] theorem lcm_singleton {a : α} : ({a} : Multiset α).lcm = normalize a := (fold_singleton _ _ _).trans <| lcm_one_right _ @[simp] theorem lcm_add (s₁ s₂ : Multiset α) : (s₁ + s₂).lcm = GCDMonoid.lcm s₁.lcm s₂.lcm := Eq.trans (by simp [lcm]) (fold_add _ _ _ _ _) theorem lcm_dvd {s : Multiset α} {a : α} : s.lcm ∣ a ↔ ∀ b ∈ s, b ∣ a := Multiset.induction_on s (by simp) (by simp +contextual [or_imp, forall_and, lcm_dvd_iff]) theorem dvd_lcm {s : Multiset α} {a : α} (h : a ∈ s) : a ∣ s.lcm := lcm_dvd.1 dvd_rfl _ h theorem lcm_mono {s₁ s₂ : Multiset α} (h : s₁ ⊆ s₂) : s₁.lcm ∣ s₂.lcm := lcm_dvd.2 fun _ hb ↦ dvd_lcm (h hb) @[simp] theorem normalize_lcm (s : Multiset α) : normalize s.lcm = s.lcm := Multiset.induction_on s (by simp) fun a s _ ↦ by simp @[simp] nonrec theorem lcm_eq_zero_iff [Nontrivial α] (s : Multiset α) : s.lcm = 0 ↔ (0 : α) ∈ s := by induction s using Multiset.induction_on with | empty => simp only [lcm_zero, one_ne_zero, not_mem_zero] | cons a s ihs => simp only [mem_cons, lcm_cons, lcm_eq_zero_iff, ihs, @eq_comm _ a] variable [DecidableEq α] @[simp] theorem lcm_dedup (s : Multiset α) : (dedup s).lcm = s.lcm :=
Multiset.induction_on s (by simp) fun a s IH ↦ by by_cases h : a ∈ s <;> simp [IH, h]
Mathlib/Algebra/GCDMonoid/Multiset.lean
81
82
/- 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.Data.Fintype.List import Mathlib.Data.Fintype.OfMap /-! # Cycles of a list Lists have an equivalence relation of whether they are rotational permutations of one another. This relation is defined as `IsRotated`. Based on this, we define the quotient of lists by the rotation relation, called `Cycle`. We also define a representation of concrete cycles, available when viewing them in a goal state or via `#eval`, when over representable types. For example, the cycle `(2 1 4 3)` will be shown as `c[2, 1, 4, 3]`. Two equal cycles may be printed differently if their internal representation is different. -/ assert_not_exists MonoidWithZero namespace List variable {α : Type*} [DecidableEq α] /-- Return the `z` such that `x :: z :: _` appears in `xs`, or `default` if there is no such `z`. -/ def nextOr : ∀ (_ : List α) (_ _ : α), α | [], _, default => default | [_], _, default => default -- Handles the not-found and the wraparound case | y :: z :: xs, x, default => if x = y then z else nextOr (z :: xs) x default @[simp] theorem nextOr_nil (x d : α) : nextOr [] x d = d := rfl @[simp] theorem nextOr_singleton (x y d : α) : nextOr [y] x d = d := rfl @[simp] theorem nextOr_self_cons_cons (xs : List α) (x y d : α) : nextOr (x :: y :: xs) x d = y := if_pos rfl theorem nextOr_cons_of_ne (xs : List α) (y x d : α) (h : x ≠ y) : nextOr (y :: xs) x d = nextOr xs x d := by rcases xs with - | ⟨z, zs⟩ · rfl · exact if_neg h /-- `nextOr` does not depend on the default value, if the next value appears. -/ theorem nextOr_eq_nextOr_of_mem_of_ne (xs : List α) (x d d' : α) (x_mem : x ∈ xs) (x_ne : x ≠ xs.getLast (ne_nil_of_mem x_mem)) : nextOr xs x d = nextOr xs x d' := by induction' xs with y ys IH · cases x_mem rcases ys with - | ⟨z, zs⟩ · simp at x_mem x_ne contradiction by_cases h : x = y · rw [h, nextOr_self_cons_cons, nextOr_self_cons_cons] · rw [nextOr, nextOr, IH] · simpa [h] using x_mem · simpa using x_ne theorem mem_of_nextOr_ne {xs : List α} {x d : α} (h : nextOr xs x d ≠ d) : x ∈ xs := by induction' xs with y ys IH · simp at h rcases ys with - | ⟨z, zs⟩ · simp at h · by_cases hx : x = y · simp [hx] · rw [nextOr_cons_of_ne _ _ _ _ hx] at h simpa [hx] using IH h theorem nextOr_concat {xs : List α} {x : α} (d : α) (h : x ∉ xs) : nextOr (xs ++ [x]) x d = d := by induction' xs with z zs IH · simp · obtain ⟨hz, hzs⟩ := not_or.mp (mt mem_cons.2 h) rw [cons_append, nextOr_cons_of_ne _ _ _ _ hz, IH hzs] theorem nextOr_mem {xs : List α} {x d : α} (hd : d ∈ xs) : nextOr xs x d ∈ xs := by revert hd suffices ∀ xs' : List α, (∀ x ∈ xs, x ∈ xs') → d ∈ xs' → nextOr xs x d ∈ xs' by exact this xs fun _ => id intro xs' hxs' hd induction' xs with y ys ih · exact hd rcases ys with - | ⟨z, zs⟩ · exact hd rw [nextOr] split_ifs with h · exact hxs' _ (mem_cons_of_mem _ mem_cons_self) · exact ih fun _ h => hxs' _ (mem_cons_of_mem _ h) /-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the next element of `l`. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates. For example: * `next [1, 2, 3] 2 _ = 3` * `next [1, 2, 3] 3 _ = 1` * `next [1, 2, 3, 2, 4] 2 _ = 3` * `next [1, 2, 3, 2] 2 _ = 3` * `next [1, 1, 2, 3, 2] 1 _ = 1` -/ def next (l : List α) (x : α) (h : x ∈ l) : α := nextOr l x (l.get ⟨0, length_pos_of_mem h⟩) /-- Given an element `x : α` of `l : List α` such that `x ∈ l`, get the previous element of `l`. This works from head to tail, (including a check for last element) so it will match on first hit, ignoring later duplicates. * `prev [1, 2, 3] 2 _ = 1` * `prev [1, 2, 3] 1 _ = 3` * `prev [1, 2, 3, 2, 4] 2 _ = 1` * `prev [1, 2, 3, 4, 2] 2 _ = 1` * `prev [1, 1, 2] 1 _ = 2` -/ def prev : ∀ l : List α, ∀ x ∈ l, α | [], _, h => by simp at h | [y], _, _ => y | y :: z :: xs, x, h => if hx : x = y then getLast (z :: xs) (cons_ne_nil _ _) else if x = z then y else prev (z :: xs) x (by simpa [hx] using h) variable (l : List α) (x : α) @[simp] theorem next_singleton (x y : α) (h : x ∈ [y]) : next [y] x h = y := rfl @[simp] theorem prev_singleton (x y : α) (h : x ∈ [y]) : prev [y] x h = y := rfl theorem next_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) : next (y :: z :: l) x h = z := by rw [next, nextOr, if_pos hx] @[simp] theorem next_cons_cons_eq (z : α) (h : x ∈ x :: z :: l) : next (x :: z :: l) x h = z := next_cons_cons_eq' l x x z h rfl theorem next_ne_head_ne_getLast (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y) (hx : x ≠ getLast (y :: l) (cons_ne_nil _ _)) : next (y :: l) x h = next l x (by simpa [hy] using h) := by rw [next, next, nextOr_cons_of_ne _ _ _ _ hy, nextOr_eq_nextOr_of_mem_of_ne] · rwa [getLast_cons] at hx exact ne_nil_of_mem (by assumption) · rwa [getLast_cons] at hx theorem next_cons_concat (y : α) (hy : x ≠ y) (hx : x ∉ l) (h : x ∈ y :: l ++ [x] := mem_append_right _ (mem_singleton_self x)) : next (y :: l ++ [x]) x h = y := by rw [next, nextOr_concat] · rfl · simp [hy, hx] theorem next_getLast_cons (h : x ∈ l) (y : α) (h : x ∈ y :: l) (hy : x ≠ y) (hx : x = getLast (y :: l) (cons_ne_nil _ _)) (hl : Nodup l) : next (y :: l) x h = y := by rw [next, get, ← dropLast_append_getLast (cons_ne_nil y l), hx, nextOr_concat] subst hx intro H obtain ⟨_ | k, hk, hk'⟩ := getElem_of_mem H · rw [← Option.some_inj] at hk' rw [← getElem?_eq_getElem, dropLast_eq_take, getElem?_take_of_lt, getElem?_cons_zero, Option.some_inj] at hk' · exact hy (Eq.symm hk') rw [length_cons] exact length_pos_of_mem (by assumption) suffices k + 1 = l.length by simp [this] at hk rcases l with - | ⟨hd, tl⟩ · simp at hk · rw [nodup_iff_injective_get] at hl rw [length, Nat.succ_inj] refine Fin.val_eq_of_eq <| @hl ⟨k, Nat.lt_of_succ_lt <| by simpa using hk⟩ ⟨tl.length, by simp⟩ ?_ rw [← Option.some_inj] at hk' rw [← getElem?_eq_getElem, dropLast_eq_take, getElem?_take_of_lt, getElem?_cons_succ, getElem?_eq_getElem, Option.some_inj] at hk' · rw [get_eq_getElem, hk'] simp only [getLast_eq_getElem, length_cons, Nat.succ_eq_add_one, Nat.succ_sub_succ_eq_sub, Nat.sub_zero, get_eq_getElem, getElem_cons_succ] simpa using hk theorem prev_getLast_cons' (y : α) (hxy : x ∈ y :: l) (hx : x = y) : prev (y :: l) x hxy = getLast (y :: l) (cons_ne_nil _ _) := by cases l <;> simp [prev, hx] @[simp] theorem prev_getLast_cons (h : x ∈ x :: l) : prev (x :: l) x h = getLast (x :: l) (cons_ne_nil _ _) := prev_getLast_cons' l x x h rfl theorem prev_cons_cons_eq' (y z : α) (h : x ∈ y :: z :: l) (hx : x = y) : prev (y :: z :: l) x h = getLast (z :: l) (cons_ne_nil _ _) := by rw [prev, dif_pos hx] theorem prev_cons_cons_eq (z : α) (h : x ∈ x :: z :: l) : prev (x :: z :: l) x h = getLast (z :: l) (cons_ne_nil _ _) := prev_cons_cons_eq' l x x z h rfl theorem prev_cons_cons_of_ne' (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz : x = z) : prev (y :: z :: l) x h = y := by cases l · simp [prev, hy, hz] · rw [prev, dif_neg hy, if_pos hz] theorem prev_cons_cons_of_ne (y : α) (h : x ∈ y :: x :: l) (hy : x ≠ y) : prev (y :: x :: l) x h = y := prev_cons_cons_of_ne' _ _ _ _ _ hy rfl theorem prev_ne_cons_cons (y z : α) (h : x ∈ y :: z :: l) (hy : x ≠ y) (hz : x ≠ z) : prev (y :: z :: l) x h = prev (z :: l) x (by simpa [hy] using h) := by cases l · simp [hy, hz] at h · rw [prev, dif_neg hy, if_neg hz] theorem next_mem (h : x ∈ l) : l.next x h ∈ l := nextOr_mem (get_mem _ _) theorem prev_mem (h : x ∈ l) : l.prev x h ∈ l := by rcases l with - | ⟨hd, tl⟩ · simp at h induction' tl with hd' tl hl generalizing hd · simp · by_cases hx : x = hd · simp only [hx, prev_cons_cons_eq] exact mem_cons_of_mem _ (getLast_mem _) · rw [prev, dif_neg hx] split_ifs with hm · exact mem_cons_self · exact mem_cons_of_mem _ (hl _ _) theorem next_getElem (l : List α) (h : Nodup l) (i : Nat) (hi : i < l.length) : next l l[i] (get_mem _ _) = (l[(i + 1) % l.length]'(Nat.mod_lt _ (i.zero_le.trans_lt hi))) := match l, h, i, hi with | [], _, i, hi => by simp at hi | [_], _, _, _ => by simp | x::y::l, _h, 0, h0 => by have h₁ : (x :: y :: l)[0] = x := by simp rw [next_cons_cons_eq' _ _ _ _ _ h₁] simp | x::y::l, hn, i+1, hi => by have hx' : (x :: y :: l)[i+1] ≠ x := by intro H suffices (i + 1 : ℕ) = 0 by simpa rw [nodup_iff_injective_get] at hn refine Fin.val_eq_of_eq (@hn ⟨i + 1, hi⟩ ⟨0, by simp⟩ ?_) simpa using H have hi' : i ≤ l.length := Nat.le_of_lt_succ (Nat.succ_lt_succ_iff.1 hi) rcases hi'.eq_or_lt with (hi' | hi') · subst hi' rw [next_getLast_cons] · simp [hi', get] · rw [getElem_cons_succ]; exact get_mem _ _ · exact hx' · simp [getLast_eq_getElem] · exact hn.of_cons · rw [next_ne_head_ne_getLast _ _ _ _ _ hx'] · simp only [getElem_cons_succ] rw [next_getElem (y::l), ← getElem_cons_succ (a := x)] · congr dsimp rw [Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 hi'), Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 (Nat.succ_lt_succ_iff.2 hi'))] · simp [Nat.mod_eq_of_lt (Nat.succ_lt_succ_iff.2 hi'), hi'] · exact hn.of_cons · rw [getLast_eq_getElem] intro h have := nodup_iff_injective_get.1 hn h simp at this; simp [this] at hi' · rw [getElem_cons_succ]; exact get_mem _ _ @[deprecated (since := "2025-02-015")] alias next_get := next_getElem -- Unused variable linter incorrectly reports that `h` is unused here. set_option linter.unusedVariables false in theorem prev_getElem (l : List α) (h : Nodup l) (i : Nat) (hi : i < l.length) : prev l l[i] (get_mem _ _) = (l[(i + (l.length - 1)) % l.length]'(Nat.mod_lt _ (by omega))) := match l with | [] => by simp at hi | x::l => by induction l generalizing i x with | nil => simp | cons y l hl => rcases i with (_ | _ | i) · simp [getLast_eq_getElem] · simp only [mem_cons, nodup_cons] at h push_neg at h simp only [zero_add, getElem_cons_succ, getElem_cons_zero, List.prev_cons_cons_of_ne _ _ _ _ h.left.left.symm, length, add_comm, Nat.add_sub_cancel_left, Nat.mod_self] · rw [prev_ne_cons_cons] · convert hl i.succ y h.of_cons (Nat.le_of_succ_le_succ hi) using 1 have : ∀ k hk, (y :: l)[k] = (x :: y :: l)[k + 1]'(Nat.succ_lt_succ hk) := by simp rw [this] congr simp only [Nat.add_succ_sub_one, add_zero, length] simp only [length, Nat.succ_lt_succ_iff] at hi set k := l.length rw [Nat.succ_add, ← Nat.add_succ, Nat.add_mod_right, Nat.succ_add, ← Nat.add_succ _ k, Nat.add_mod_right, Nat.mod_eq_of_lt, Nat.mod_eq_of_lt] · exact Nat.lt_succ_of_lt hi · exact Nat.succ_lt_succ (Nat.lt_succ_of_lt hi) · intro H suffices i.succ.succ = 0 by simpa suffices Fin.mk _ hi = ⟨0, by omega⟩ by rwa [Fin.mk.inj_iff] at this rw [nodup_iff_injective_get] at h apply h; rw [← H]; simp · intro H suffices i.succ.succ = 1 by simpa suffices Fin.mk _ hi = ⟨1, by omega⟩ by rwa [Fin.mk.inj_iff] at this rw [nodup_iff_injective_get] at h apply h; rw [← H]; simp @[deprecated (since := "2025-02-15")] alias prev_get := prev_getElem theorem pmap_next_eq_rotate_one (h : Nodup l) : (l.pmap l.next fun _ h => h) = l.rotate 1 := by apply List.ext_getElem · simp · intros rw [getElem_pmap, getElem_rotate, next_getElem _ h] theorem pmap_prev_eq_rotate_length_sub_one (h : Nodup l) : (l.pmap l.prev fun _ h => h) = l.rotate (l.length - 1) := by apply List.ext_getElem · simp · intro n hn hn' rw [getElem_rotate, getElem_pmap, prev_getElem _ h] theorem prev_next (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : prev l (next l x hx) (next_mem _ _ _) = x := by obtain ⟨n, hn, rfl⟩ := getElem_of_mem hx simp only [next_getElem, prev_getElem, h, Nat.mod_add_mod] rcases l with - | ⟨hd, tl⟩ · simp at hn · have : (n + 1 + length tl) % (length tl + 1) = n := by rw [length_cons] at hn rw [add_assoc, add_comm 1, Nat.add_mod_right, Nat.mod_eq_of_lt hn] simp only [length_cons, Nat.succ_sub_succ_eq_sub, Nat.sub_zero, Nat.succ_eq_add_one, this] theorem next_prev (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : next l (prev l x hx) (prev_mem _ _ _) = x := by obtain ⟨n, hn, rfl⟩ := getElem_of_mem hx simp only [next_getElem, prev_getElem, h, Nat.mod_add_mod] rcases l with - | ⟨hd, tl⟩ · simp at hn · have : (n + length tl + 1) % (length tl + 1) = n := by rw [length_cons] at hn rw [add_assoc, Nat.add_mod_right, Nat.mod_eq_of_lt hn] simp [this] theorem prev_reverse_eq_next (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : prev l.reverse x (mem_reverse.mpr hx) = next l x hx := by obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx have lpos : 0 < l.length := k.zero_le.trans_lt hk have key : l.length - 1 - k < l.length := by omega rw [← getElem_pmap l.next (fun _ h => h) (by simpa using hk)] simp_rw [getElem_eq_getElem_reverse (l := l), pmap_next_eq_rotate_one _ h] rw [← getElem_pmap l.reverse.prev fun _ h => h] · simp_rw [pmap_prev_eq_rotate_length_sub_one _ (nodup_reverse.mpr h), rotate_reverse, length_reverse, Nat.mod_eq_of_lt (Nat.sub_lt lpos Nat.succ_pos'), Nat.sub_sub_self (Nat.succ_le_of_lt lpos)] rw [getElem_eq_getElem_reverse] · simp [Nat.sub_sub_self (Nat.le_sub_one_of_lt hk)] · simpa theorem next_reverse_eq_prev (l : List α) (h : Nodup l) (x : α) (hx : x ∈ l) : next l.reverse x (mem_reverse.mpr hx) = prev l x hx := by convert (prev_reverse_eq_next l.reverse (nodup_reverse.mpr h) x (mem_reverse.mpr hx)).symm exact (reverse_reverse l).symm theorem isRotated_next_eq {l l' : List α} (h : l ~r l') (hn : Nodup l) {x : α} (hx : x ∈ l) : l.next x hx = l'.next x (h.mem_iff.mp hx) := by obtain ⟨k, hk, rfl⟩ := getElem_of_mem hx obtain ⟨n, rfl⟩ := id h rw [next_getElem _ hn] simp_rw [getElem_eq_getElem_rotate _ n k] rw [next_getElem _ (h.nodup_iff.mp hn), getElem_eq_getElem_rotate _ n] simp [add_assoc] theorem isRotated_prev_eq {l l' : List α} (h : l ~r l') (hn : Nodup l) {x : α} (hx : x ∈ l) : l.prev x hx = l'.prev x (h.mem_iff.mp hx) := by rw [← next_reverse_eq_prev _ hn, ← next_reverse_eq_prev _ (h.nodup_iff.mp hn)] exact isRotated_next_eq h.reverse (nodup_reverse.mpr hn) _ end List open List /-- `Cycle α` is the quotient of `List α` by cyclic permutation. Duplicates are allowed. -/ def Cycle (α : Type*) : Type _ := Quotient (IsRotated.setoid α) namespace Cycle variable {α : Type*} /-- The coercion from `List α` to `Cycle α` -/ @[coe] def ofList : List α → Cycle α := Quot.mk _ instance : Coe (List α) (Cycle α) := ⟨ofList⟩ @[simp] theorem coe_eq_coe {l₁ l₂ : List α} : (l₁ : Cycle α) = (l₂ : Cycle α) ↔ l₁ ~r l₂ := @Quotient.eq _ (IsRotated.setoid _) _ _
@[simp] theorem mk_eq_coe (l : List α) : Quot.mk _ l = (l : Cycle α) := rfl
Mathlib/Data/List/Cycle.lean
417
420
/- Copyright (c) 2018 Kenny Lau. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kenny Lau -/ import Mathlib.Algebra.Algebra.Operations import Mathlib.Algebra.Module.BigOperators import Mathlib.Data.Fintype.Lattice import Mathlib.RingTheory.Coprime.Lemmas import Mathlib.RingTheory.Ideal.Basic import Mathlib.RingTheory.NonUnitalSubsemiring.Basic /-! # More operations on modules and ideals -/ assert_not_exists Basis -- See `RingTheory.Ideal.Basis` Submodule.hasQuotient -- See `RingTheory.Ideal.Quotient.Operations` universe u v w x open Pointwise namespace Submodule lemma coe_span_smul {R' M' : Type*} [CommSemiring R'] [AddCommMonoid M'] [Module R' M'] (s : Set R') (N : Submodule R' M') : (Ideal.span s : Set R') • N = s • N := set_smul_eq_of_le _ _ _ (by rintro r n hr hn induction hr using Submodule.span_induction with | mem _ h => exact mem_set_smul_of_mem_mem h hn | zero => rw [zero_smul]; exact Submodule.zero_mem _ | add _ _ _ _ ihr ihs => rw [add_smul]; exact Submodule.add_mem _ ihr ihs | smul _ _ hr => rw [mem_span_set] at hr obtain ⟨c, hc, rfl⟩ := hr rw [Finsupp.sum, Finset.smul_sum, Finset.sum_smul] refine Submodule.sum_mem _ fun i hi => ?_ rw [← mul_smul, smul_eq_mul, mul_comm, mul_smul] exact mem_set_smul_of_mem_mem (hc hi) <| Submodule.smul_mem _ _ hn) <| set_smul_mono_left _ Submodule.subset_span lemma span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) : (span ℤ {a}).toAddSubgroup = AddSubgroup.zmultiples a := by ext i simp [Ideal.mem_span_singleton', AddSubgroup.mem_zmultiples_iff] @[simp] lemma _root_.Ideal.span_singleton_toAddSubgroup_eq_zmultiples (a : ℤ) : (Ideal.span {a}).toAddSubgroup = AddSubgroup.zmultiples a := Submodule.span_singleton_toAddSubgroup_eq_zmultiples _ variable {R : Type u} {M : Type v} {M' F G : Type*} section Semiring variable [Semiring R] [AddCommMonoid M] [Module R M] /-- This duplicates the global `smul_eq_mul`, but doesn't have to unfold anywhere near as much to apply. -/ protected theorem _root_.Ideal.smul_eq_mul (I J : Ideal R) : I • J = I * J := rfl variable {I J : Ideal R} {N : Submodule R M} theorem smul_le_right : I • N ≤ N := smul_le.2 fun r _ _ ↦ N.smul_mem r theorem map_le_smul_top (I : Ideal R) (f : R →ₗ[R] M) : Submodule.map f I ≤ I • (⊤ : Submodule R M) := by rintro _ ⟨y, hy, rfl⟩ rw [← mul_one y, ← smul_eq_mul, f.map_smul] exact smul_mem_smul hy mem_top variable (I J N) @[simp] theorem top_smul : (⊤ : Ideal R) • N = N := le_antisymm smul_le_right fun r hri => one_smul R r ▸ smul_mem_smul mem_top hri protected theorem mul_smul : (I * J) • N = I • J • N := Submodule.smul_assoc _ _ _ theorem mem_of_span_top_of_smul_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, (r : R) • x ∈ M') : x ∈ M' := by suffices LinearMap.range (LinearMap.toSpanSingleton R M x) ≤ M' by rw [← LinearMap.toSpanSingleton_one R M x] exact this (LinearMap.mem_range_self _ 1) rw [LinearMap.range_eq_map, ← hs, map_le_iff_le_comap, Ideal.span, span_le] exact fun r hr ↦ H ⟨r, hr⟩ variable {M' : Type w} [AddCommMonoid M'] [Module R M'] @[simp] theorem map_smul'' (f : M →ₗ[R] M') : (I • N).map f = I • N.map f := le_antisymm (map_le_iff_le_comap.2 <| smul_le.2 fun r hr n hn => show f (r • n) ∈ I • N.map f from (f.map_smul r n).symm ▸ smul_mem_smul hr (mem_map_of_mem hn)) <| smul_le.2 fun r hr _ hn => let ⟨p, hp, hfp⟩ := mem_map.1 hn hfp ▸ f.map_smul r p ▸ mem_map_of_mem (smul_mem_smul hr hp) theorem mem_smul_top_iff (N : Submodule R M) (x : N) : x ∈ I • (⊤ : Submodule R N) ↔ (x : M) ∈ I • N := by have : Submodule.map N.subtype (I • ⊤) = I • N := by rw [Submodule.map_smul'', Submodule.map_top, Submodule.range_subtype] simp [← this, -map_smul''] @[simp] theorem smul_comap_le_comap_smul (f : M →ₗ[R] M') (S : Submodule R M') (I : Ideal R) : I • S.comap f ≤ (I • S).comap f := by refine Submodule.smul_le.mpr fun r hr x hx => ?_ rw [Submodule.mem_comap] at hx ⊢ rw [f.map_smul] exact Submodule.smul_mem_smul hr hx end Semiring section CommSemiring variable [CommSemiring R] [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M'] open Pointwise theorem mem_smul_span_singleton {I : Ideal R} {m : M} {x : M} : x ∈ I • span R ({m} : Set M) ↔ ∃ y ∈ I, y • m = x := ⟨fun hx => smul_induction_on hx (fun r hri _ hnm => let ⟨s, hs⟩ := mem_span_singleton.1 hnm ⟨r * s, I.mul_mem_right _ hri, hs ▸ mul_smul r s m⟩) fun m1 m2 ⟨y1, hyi1, hy1⟩ ⟨y2, hyi2, hy2⟩ => ⟨y1 + y2, I.add_mem hyi1 hyi2, by rw [add_smul, hy1, hy2]⟩, fun ⟨_, hyi, hy⟩ => hy ▸ smul_mem_smul hyi (subset_span <| Set.mem_singleton m)⟩ variable {I J : Ideal R} {N P : Submodule R M} variable (S : Set R) (T : Set M) theorem smul_eq_map₂ : I • N = Submodule.map₂ (LinearMap.lsmul R M) I N := le_antisymm (smul_le.mpr fun _m hm _n ↦ Submodule.apply_mem_map₂ _ hm) (map₂_le.mpr fun _m hm _n ↦ smul_mem_smul hm) theorem span_smul_span : Ideal.span S • span R T = span R (⋃ (s ∈ S) (t ∈ T), {s • t}) := by rw [smul_eq_map₂] exact (map₂_span_span _ _ _ _).trans <| congr_arg _ <| Set.image2_eq_iUnion _ _ _ theorem ideal_span_singleton_smul (r : R) (N : Submodule R M) : (Ideal.span {r} : Ideal R) • N = r • N := by have : span R (⋃ (t : M) (_ : t ∈ N), {r • t}) = r • N := by convert span_eq (r • N) exact (Set.image_eq_iUnion _ (N : Set M)).symm conv_lhs => rw [← span_eq N, span_smul_span] simpa /-- Given `s`, a generating set of `R`, to check that an `x : M` falls in a submodule `M'` of `x`, we only need to show that `r ^ n • x ∈ M'` for some `n` for each `r : s`. -/ theorem mem_of_span_eq_top_of_smul_pow_mem (M' : Submodule R M) (s : Set R) (hs : Ideal.span s = ⊤) (x : M) (H : ∀ r : s, ∃ n : ℕ, ((r : R) ^ n : R) • x ∈ M') : x ∈ M' := by choose f hf using H apply M'.mem_of_span_top_of_smul_mem _ (Ideal.span_range_pow_eq_top s hs f) rintro ⟨_, r, hr, rfl⟩ exact hf r open Pointwise in @[simp] theorem map_pointwise_smul (r : R) (N : Submodule R M) (f : M →ₗ[R] M') : (r • N).map f = r • N.map f := by simp_rw [← ideal_span_singleton_smul, map_smul''] theorem mem_smul_span {s : Set M} {x : M} : x ∈ I • Submodule.span R s ↔ x ∈ Submodule.span R (⋃ (a ∈ I) (b ∈ s), ({a • b} : Set M)) := by rw [← I.span_eq, Submodule.span_smul_span, I.span_eq] simp variable (I) /-- If `x` is an `I`-multiple of the submodule spanned by `f '' s`, then we can write `x` as an `I`-linear combination of the elements of `f '' s`. -/ theorem mem_ideal_smul_span_iff_exists_sum {ι : Type*} (f : ι → M) (x : M) : x ∈ I • span R (Set.range f) ↔ ∃ (a : ι →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by constructor; swap · rintro ⟨a, ha, rfl⟩ exact Submodule.sum_mem _ fun c _ => smul_mem_smul (ha c) <| subset_span <| Set.mem_range_self _ refine fun hx => span_induction ?_ ?_ ?_ ?_ (mem_smul_span.mp hx) · simp only [Set.mem_iUnion, Set.mem_range, Set.mem_singleton_iff] rintro x ⟨y, hy, x, ⟨i, rfl⟩, rfl⟩ refine ⟨Finsupp.single i y, fun j => ?_, ?_⟩ · letI := Classical.decEq ι rw [Finsupp.single_apply] split_ifs · assumption · exact I.zero_mem refine @Finsupp.sum_single_index ι R M _ _ i _ (fun i y => y • f i) ?_ simp · exact ⟨0, fun _ => I.zero_mem, Finsupp.sum_zero_index⟩ · rintro x y - - ⟨ax, hax, rfl⟩ ⟨ay, hay, rfl⟩ refine ⟨ax + ay, fun i => I.add_mem (hax i) (hay i), Finsupp.sum_add_index' ?_ ?_⟩ <;> intros <;> simp only [zero_smul, add_smul] · rintro c x - ⟨a, ha, rfl⟩ refine ⟨c • a, fun i => I.mul_mem_left c (ha i), ?_⟩ rw [Finsupp.sum_smul_index, Finsupp.smul_sum] <;> intros <;> simp only [zero_smul, mul_smul] theorem mem_ideal_smul_span_iff_exists_sum' {ι : Type*} (s : Set ι) (f : ι → M) (x : M) : x ∈ I • span R (f '' s) ↔ ∃ (a : s →₀ R) (_ : ∀ i, a i ∈ I), (a.sum fun i c => c • f i) = x := by rw [← Submodule.mem_ideal_smul_span_iff_exists_sum, ← Set.image_eq_range] end CommSemiring end Submodule namespace Ideal section Add variable {R : Type u} [Semiring R] @[simp] theorem add_eq_sup {I J : Ideal R} : I + J = I ⊔ J := rfl @[simp] theorem zero_eq_bot : (0 : Ideal R) = ⊥ := rfl @[simp] theorem sum_eq_sup {ι : Type*} (s : Finset ι) (f : ι → Ideal R) : s.sum f = s.sup f := rfl end Add section Semiring variable {R : Type u} [Semiring R] {I J K L : Ideal R} @[simp] theorem one_eq_top : (1 : Ideal R) = ⊤ := by rw [Submodule.one_eq_span, ← Ideal.span, Ideal.span_singleton_one] theorem add_eq_one_iff : I + J = 1 ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [one_eq_top, eq_top_iff_one, add_eq_sup, Submodule.mem_sup] theorem mul_mem_mul {r s} (hr : r ∈ I) (hs : s ∈ J) : r * s ∈ I * J := Submodule.smul_mem_smul hr hs theorem pow_mem_pow {x : R} (hx : x ∈ I) (n : ℕ) : x ^ n ∈ I ^ n := Submodule.pow_mem_pow _ hx _ theorem mul_le : I * J ≤ K ↔ ∀ r ∈ I, ∀ s ∈ J, r * s ∈ K := Submodule.smul_le theorem mul_le_left : I * J ≤ J := mul_le.2 fun _ _ _ => J.mul_mem_left _ @[simp] theorem sup_mul_left_self : I ⊔ J * I = I := sup_eq_left.2 mul_le_left @[simp] theorem mul_left_self_sup : J * I ⊔ I = I := sup_eq_right.2 mul_le_left theorem mul_le_right [I.IsTwoSided] : I * J ≤ I := mul_le.2 fun _ hr _ _ ↦ I.mul_mem_right _ hr @[simp] theorem sup_mul_right_self [I.IsTwoSided] : I ⊔ I * J = I := sup_eq_left.2 mul_le_right @[simp] theorem mul_right_self_sup [I.IsTwoSided] : I * J ⊔ I = I := sup_eq_right.2 mul_le_right protected theorem mul_assoc : I * J * K = I * (J * K) := Submodule.smul_assoc I J K variable (I) theorem mul_bot : I * ⊥ = ⊥ := by simp theorem bot_mul : ⊥ * I = ⊥ := by simp @[simp] theorem top_mul : ⊤ * I = I := Submodule.top_smul I variable {I} theorem mul_mono (hik : I ≤ K) (hjl : J ≤ L) : I * J ≤ K * L := Submodule.smul_mono hik hjl theorem mul_mono_left (h : I ≤ J) : I * K ≤ J * K := Submodule.smul_mono_left h theorem mul_mono_right (h : J ≤ K) : I * J ≤ I * K := smul_mono_right I h variable (I J K) theorem mul_sup : I * (J ⊔ K) = I * J ⊔ I * K := Submodule.smul_sup I J K theorem sup_mul : (I ⊔ J) * K = I * K ⊔ J * K := Submodule.sup_smul I J K variable {I J K} theorem pow_le_pow_right {m n : ℕ} (h : m ≤ n) : I ^ n ≤ I ^ m := by obtain _ | m := m · rw [Submodule.pow_zero, one_eq_top]; exact le_top obtain ⟨n, rfl⟩ := Nat.exists_eq_add_of_le h rw [add_comm, Submodule.pow_add _ m.add_one_ne_zero] exact mul_le_left theorem pow_le_self {n : ℕ} (hn : n ≠ 0) : I ^ n ≤ I := calc I ^ n ≤ I ^ 1 := pow_le_pow_right (Nat.pos_of_ne_zero hn) _ = I := Submodule.pow_one _ theorem pow_right_mono (e : I ≤ J) (n : ℕ) : I ^ n ≤ J ^ n := by induction' n with _ hn · rw [Submodule.pow_zero, Submodule.pow_zero] · rw [Submodule.pow_succ, Submodule.pow_succ] exact Ideal.mul_mono hn e namespace IsTwoSided instance (priority := low) [J.IsTwoSided] : (I * J).IsTwoSided := ⟨fun b ha ↦ Submodule.mul_induction_on ha (fun i hi j hj ↦ by rw [mul_assoc]; exact mul_mem_mul hi (mul_mem_right _ _ hj)) fun x y hx hy ↦ by rw [right_distrib]; exact add_mem hx hy⟩ variable [I.IsTwoSided] (m n : ℕ) instance (priority := low) : (I ^ n).IsTwoSided := n.rec (by rw [Submodule.pow_zero, one_eq_top]; infer_instance) (fun _ _ ↦ by rw [Submodule.pow_succ]; infer_instance) protected theorem mul_one : I * 1 = I := mul_le_right.antisymm fun i hi ↦ mul_one i ▸ mul_mem_mul hi (one_eq_top (R := R) ▸ Submodule.mem_top) protected theorem pow_add : I ^ (m + n) = I ^ m * I ^ n := by obtain rfl | h := eq_or_ne n 0 · rw [add_zero, Submodule.pow_zero, IsTwoSided.mul_one] · exact Submodule.pow_add _ h protected theorem pow_succ : I ^ (n + 1) = I * I ^ n := by rw [add_comm, IsTwoSided.pow_add, Submodule.pow_one] end IsTwoSided @[simp] theorem mul_eq_bot [NoZeroDivisors R] : I * J = ⊥ ↔ I = ⊥ ∨ J = ⊥ := ⟨fun hij => or_iff_not_imp_left.mpr fun I_ne_bot => J.eq_bot_iff.mpr fun j hj => let ⟨i, hi, ne0⟩ := I.ne_bot_iff.mp I_ne_bot Or.resolve_left (mul_eq_zero.mp ((I * J).eq_bot_iff.mp hij _ (mul_mem_mul hi hj))) ne0, fun h => by obtain rfl | rfl := h; exacts [bot_mul _, mul_bot _]⟩ instance [NoZeroDivisors R] : NoZeroDivisors (Ideal R) where eq_zero_or_eq_zero_of_mul_eq_zero := mul_eq_bot.1 instance {S A : Type*} [Semiring S] [SMul R S] [AddCommMonoid A] [Module R A] [Module S A] [IsScalarTower R S A] [NoZeroSMulDivisors R A] {I : Submodule S A} : NoZeroSMulDivisors R I := Submodule.noZeroSMulDivisors (Submodule.restrictScalars R I) theorem pow_eq_zero_of_mem {I : Ideal R} {n m : ℕ} (hnI : I ^ n = 0) (hmn : n ≤ m) {x : R} (hx : x ∈ I) : x ^ m = 0 := by simpa [hnI] using pow_le_pow_right hmn <| pow_mem_pow hx m end Semiring section MulAndRadical variable {R : Type u} {ι : Type*} [CommSemiring R] variable {I J K L : Ideal R} theorem mul_mem_mul_rev {r s} (hr : r ∈ I) (hs : s ∈ J) : s * r ∈ I * J := mul_comm r s ▸ mul_mem_mul hr hs theorem prod_mem_prod {ι : Type*} {s : Finset ι} {I : ι → Ideal R} {x : ι → R} : (∀ i ∈ s, x i ∈ I i) → (∏ i ∈ s, x i) ∈ ∏ i ∈ s, I i := by classical refine Finset.induction_on s ?_ ?_ · intro rw [Finset.prod_empty, Finset.prod_empty, one_eq_top] exact Submodule.mem_top · intro a s ha IH h rw [Finset.prod_insert ha, Finset.prod_insert ha] exact mul_mem_mul (h a <| Finset.mem_insert_self a s) (IH fun i hi => h i <| Finset.mem_insert_of_mem hi) lemma sup_pow_add_le_pow_sup_pow {n m : ℕ} : (I ⊔ J) ^ (n + m) ≤ I ^ n ⊔ J ^ m := by rw [← Ideal.add_eq_sup, ← Ideal.add_eq_sup, add_pow, Ideal.sum_eq_sup] apply Finset.sup_le intros i hi by_cases hn : n ≤ i · exact (Ideal.mul_le_right.trans (Ideal.mul_le_right.trans ((Ideal.pow_le_pow_right hn).trans le_sup_left))) · refine (Ideal.mul_le_right.trans (Ideal.mul_le_left.trans ((Ideal.pow_le_pow_right ?_).trans le_sup_right))) omega variable (I J K) protected theorem mul_comm : I * J = J * I := le_antisymm (mul_le.2 fun _ hrI _ hsJ => mul_mem_mul_rev hsJ hrI) (mul_le.2 fun _ hrJ _ hsI => mul_mem_mul_rev hsI hrJ) theorem span_mul_span (S T : Set R) : span S * span T = span (⋃ (s ∈ S) (t ∈ T), {s * t}) := Submodule.span_smul_span S T variable {I J K} theorem span_mul_span' (S T : Set R) : span S * span T = span (S * T) := by unfold span rw [Submodule.span_mul_span] theorem span_singleton_mul_span_singleton (r s : R) : span {r} * span {s} = (span {r * s} : Ideal R) := by unfold span rw [Submodule.span_mul_span, Set.singleton_mul_singleton] theorem span_singleton_pow (s : R) (n : ℕ) : span {s} ^ n = (span {s ^ n} : Ideal R) := by induction' n with n ih; · simp [Set.singleton_one] simp only [pow_succ, ih, span_singleton_mul_span_singleton] theorem mem_mul_span_singleton {x y : R} {I : Ideal R} : x ∈ I * span {y} ↔ ∃ z ∈ I, z * y = x := Submodule.mem_smul_span_singleton theorem mem_span_singleton_mul {x y : R} {I : Ideal R} : x ∈ span {y} * I ↔ ∃ z ∈ I, y * z = x := by simp only [mul_comm, mem_mul_span_singleton] theorem le_span_singleton_mul_iff {x : R} {I J : Ideal R} : I ≤ span {x} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI := show (∀ {zI} (_ : zI ∈ I), zI ∈ span {x} * J) ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI by simp only [mem_span_singleton_mul] theorem span_singleton_mul_le_iff {x : R} {I J : Ideal R} : span {x} * I ≤ J ↔ ∀ z ∈ I, x * z ∈ J := by simp only [mul_le, mem_span_singleton_mul, mem_span_singleton] constructor · intro h zI hzI exact h x (dvd_refl x) zI hzI · rintro h _ ⟨z, rfl⟩ zI hzI rw [mul_comm x z, mul_assoc] exact J.mul_mem_left _ (h zI hzI) theorem span_singleton_mul_le_span_singleton_mul {x y : R} {I J : Ideal R} : span {x} * I ≤ span {y} * J ↔ ∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ := by simp only [span_singleton_mul_le_iff, mem_span_singleton_mul, eq_comm] theorem span_singleton_mul_right_mono [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I ≤ span {x} * J ↔ I ≤ J := by simp_rw [span_singleton_mul_le_span_singleton_mul, mul_right_inj' hx, exists_eq_right', SetLike.le_def] theorem span_singleton_mul_left_mono [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} ≤ J * span {x} ↔ I ≤ J := by simpa only [mul_comm I, mul_comm J] using span_singleton_mul_right_mono hx theorem span_singleton_mul_right_inj [IsDomain R] {x : R} (hx : x ≠ 0) : span {x} * I = span {x} * J ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_right_mono hx] theorem span_singleton_mul_left_inj [IsDomain R] {x : R} (hx : x ≠ 0) : I * span {x} = J * span {x} ↔ I = J := by simp only [le_antisymm_iff, span_singleton_mul_left_mono hx] theorem span_singleton_mul_right_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective ((span {x} : Ideal R) * ·) := fun _ _ => (span_singleton_mul_right_inj hx).mp theorem span_singleton_mul_left_injective [IsDomain R] {x : R} (hx : x ≠ 0) : Function.Injective fun I : Ideal R => I * span {x} := fun _ _ => (span_singleton_mul_left_inj hx).mp theorem eq_span_singleton_mul {x : R} (I J : Ideal R) : I = span {x} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zJ = zI) ∧ ∀ z ∈ J, x * z ∈ I := by simp only [le_antisymm_iff, le_span_singleton_mul_iff, span_singleton_mul_le_iff] theorem span_singleton_mul_eq_span_singleton_mul {x y : R} (I J : Ideal R) : span {x} * I = span {y} * J ↔ (∀ zI ∈ I, ∃ zJ ∈ J, x * zI = y * zJ) ∧ ∀ zJ ∈ J, ∃ zI ∈ I, x * zI = y * zJ := by simp only [le_antisymm_iff, span_singleton_mul_le_span_singleton_mul, eq_comm] theorem prod_span {ι : Type*} (s : Finset ι) (I : ι → Set R) : (∏ i ∈ s, Ideal.span (I i)) = Ideal.span (∏ i ∈ s, I i) := Submodule.prod_span s I theorem prod_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) : (∏ i ∈ s, Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := Submodule.prod_span_singleton s I @[simp] theorem multiset_prod_span_singleton (m : Multiset R) : (m.map fun x => Ideal.span {x}).prod = Ideal.span ({Multiset.prod m} : Set R) := Multiset.induction_on m (by simp) fun a m ih => by simp only [Multiset.map_cons, Multiset.prod_cons, ih, ← Ideal.span_singleton_mul_span_singleton] open scoped Function in -- required for scoped `on` notation theorem finset_inf_span_singleton {ι : Type*} (s : Finset ι) (I : ι → R) (hI : Set.Pairwise (↑s) (IsCoprime on I)) : (s.inf fun i => Ideal.span ({I i} : Set R)) = Ideal.span {∏ i ∈ s, I i} := by ext x simp only [Submodule.mem_finset_inf, Ideal.mem_span_singleton] exact ⟨Finset.prod_dvd_of_coprime hI, fun h i hi => (Finset.dvd_prod_of_mem _ hi).trans h⟩ theorem iInf_span_singleton {ι : Type*} [Fintype ι] {I : ι → R} (hI : ∀ (i j) (_ : i ≠ j), IsCoprime (I i) (I j)) : ⨅ i, span ({I i} : Set R) = span {∏ i, I i} := by rw [← Finset.inf_univ_eq_iInf, finset_inf_span_singleton] rwa [Finset.coe_univ, Set.pairwise_univ] theorem iInf_span_singleton_natCast {R : Type*} [CommRing R] {ι : Type*} [Fintype ι] {I : ι → ℕ} (hI : Pairwise fun i j => (I i).Coprime (I j)) : ⨅ (i : ι), span {(I i : R)} = span {((∏ i : ι, I i : ℕ) : R)} := by rw [iInf_span_singleton, Nat.cast_prod] exact fun i j h ↦ (hI h).cast theorem sup_eq_top_iff_isCoprime {R : Type*} [CommSemiring R] (x y : R) : span ({x} : Set R) ⊔ span {y} = ⊤ ↔ IsCoprime x y := by rw [eq_top_iff_one, Submodule.mem_sup] constructor · rintro ⟨u, hu, v, hv, h1⟩ rw [mem_span_singleton'] at hu hv rw [← hu.choose_spec, ← hv.choose_spec] at h1 exact ⟨_, _, h1⟩ · exact fun ⟨u, v, h1⟩ => ⟨_, mem_span_singleton'.mpr ⟨_, rfl⟩, _, mem_span_singleton'.mpr ⟨_, rfl⟩, h1⟩ theorem mul_le_inf : I * J ≤ I ⊓ J := mul_le.2 fun r hri s hsj => ⟨I.mul_mem_right s hri, J.mul_mem_left r hsj⟩ theorem multiset_prod_le_inf {s : Multiset (Ideal R)} : s.prod ≤ s.inf := by classical refine s.induction_on ?_ ?_ · rw [Multiset.inf_zero] exact le_top intro a s ih rw [Multiset.prod_cons, Multiset.inf_cons] exact le_trans mul_le_inf (inf_le_inf le_rfl ih) theorem prod_le_inf {s : Finset ι} {f : ι → Ideal R} : s.prod f ≤ s.inf f := multiset_prod_le_inf theorem mul_eq_inf_of_coprime (h : I ⊔ J = ⊤) : I * J = I ⊓ J := le_antisymm mul_le_inf fun r ⟨hri, hrj⟩ => let ⟨s, hsi, t, htj, hst⟩ := Submodule.mem_sup.1 ((eq_top_iff_one _).1 h) mul_one r ▸ hst ▸ (mul_add r s t).symm ▸ Ideal.add_mem (I * J) (mul_mem_mul_rev hsi hrj) (mul_mem_mul hri htj) theorem sup_mul_eq_of_coprime_left (h : I ⊔ J = ⊤) : I ⊔ J * K = I ⊔ K := le_antisymm (sup_le_sup_left mul_le_left _) fun i hi => by rw [eq_top_iff_one] at h; rw [Submodule.mem_sup] at h hi ⊢ obtain ⟨i1, hi1, j, hj, h⟩ := h; obtain ⟨i', hi', k, hk, hi⟩ := hi refine ⟨_, add_mem hi' (mul_mem_right k _ hi1), _, mul_mem_mul hj hk, ?_⟩ rw [add_assoc, ← add_mul, h, one_mul, hi] theorem sup_mul_eq_of_coprime_right (h : I ⊔ K = ⊤) : I ⊔ J * K = I ⊔ J := by rw [mul_comm] exact sup_mul_eq_of_coprime_left h theorem mul_sup_eq_of_coprime_left (h : I ⊔ J = ⊤) : I * K ⊔ J = K ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_left h, sup_comm] theorem mul_sup_eq_of_coprime_right (h : K ⊔ J = ⊤) : I * K ⊔ J = I ⊔ J := by rw [sup_comm] at h rw [sup_comm, sup_mul_eq_of_coprime_right h, sup_comm] theorem sup_prod_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ∏ i ∈ s, J i) = ⊤ := Finset.prod_induction _ (fun J => I ⊔ J = ⊤) (fun _ _ hJ hK => (sup_mul_eq_of_coprime_left hJ).trans hK) (by simp_rw [one_eq_top, sup_top_eq]) h theorem sup_multiset_prod_eq_top {s : Multiset (Ideal R)} (h : ∀ p ∈ s, I ⊔ p = ⊤) : I ⊔ Multiset.prod s = ⊤ := Multiset.prod_induction (I ⊔ · = ⊤) s (fun _ _ hp hq ↦ (sup_mul_eq_of_coprime_left hp).trans hq) (by simp only [one_eq_top, ge_iff_le, top_le_iff, le_top, sup_of_le_right]) h theorem sup_iInf_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → I ⊔ J i = ⊤) : (I ⊔ ⨅ i ∈ s, J i) = ⊤ := eq_top_iff.mpr <| le_of_eq_of_le (sup_prod_eq_top h).symm <| sup_le_sup_left (le_of_le_of_eq prod_le_inf <| Finset.inf_eq_iInf _ _) _ theorem prod_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (∏ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_prod_eq_top]; intro i hi; rw [sup_comm, h i hi] theorem iInf_sup_eq_top {s : Finset ι} {J : ι → Ideal R} (h : ∀ i, i ∈ s → J i ⊔ I = ⊤) : (⨅ i ∈ s, J i) ⊔ I = ⊤ := by rw [sup_comm, sup_iInf_eq_top]; intro i hi; rw [sup_comm, h i hi] theorem sup_pow_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ⊔ J ^ n = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact sup_prod_eq_top fun _ _ => h theorem pow_sup_eq_top {n : ℕ} (h : I ⊔ J = ⊤) : I ^ n ⊔ J = ⊤ := by rw [← Finset.card_range n, ← Finset.prod_const] exact prod_sup_eq_top fun _ _ => h theorem pow_sup_pow_eq_top {m n : ℕ} (h : I ⊔ J = ⊤) : I ^ m ⊔ J ^ n = ⊤ := sup_pow_eq_top (pow_sup_eq_top h) variable (I) in @[simp] theorem mul_top : I * ⊤ = I := Ideal.mul_comm ⊤ I ▸ Submodule.top_smul I /-- A product of ideals in an integral domain is zero if and only if one of the terms is zero. -/ @[simp] lemma multiset_prod_eq_bot {R : Type*} [CommSemiring R] [IsDomain R] {s : Multiset (Ideal R)} : s.prod = ⊥ ↔ ⊥ ∈ s := Multiset.prod_eq_zero_iff theorem span_pair_mul_span_pair (w x y z : R) : (span {w, x} : Ideal R) * span {y, z} = span {w * y, w * z, x * y, x * z} := by simp_rw [span_insert, sup_mul, mul_sup, span_singleton_mul_span_singleton, sup_assoc] theorem isCoprime_iff_codisjoint : IsCoprime I J ↔ Codisjoint I J := by rw [IsCoprime, codisjoint_iff] constructor · rintro ⟨x, y, hxy⟩ rw [eq_top_iff_one] apply (show x * I + y * J ≤ I ⊔ J from sup_le (mul_le_left.trans le_sup_left) (mul_le_left.trans le_sup_right)) rw [hxy] simp only [one_eq_top, Submodule.mem_top] · intro h refine ⟨1, 1, ?_⟩ simpa only [one_eq_top, top_mul, Submodule.add_eq_sup] theorem isCoprime_of_isMaximal [I.IsMaximal] [J.IsMaximal] (ne : I ≠ J) : IsCoprime I J := by rw [isCoprime_iff_codisjoint, isMaximal_def] at * exact IsCoatom.codisjoint_of_ne ‹_› ‹_› ne theorem isCoprime_iff_add : IsCoprime I J ↔ I + J = 1 := by rw [isCoprime_iff_codisjoint, codisjoint_iff, add_eq_sup, one_eq_top] theorem isCoprime_iff_exists : IsCoprime I J ↔ ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := by rw [← add_eq_one_iff, isCoprime_iff_add] theorem isCoprime_iff_sup_eq : IsCoprime I J ↔ I ⊔ J = ⊤ := by rw [isCoprime_iff_codisjoint, codisjoint_iff] open List in theorem isCoprime_tfae : TFAE [IsCoprime I J, Codisjoint I J, I + J = 1, ∃ i ∈ I, ∃ j ∈ J, i + j = 1, I ⊔ J = ⊤] := by rw [← isCoprime_iff_codisjoint, ← isCoprime_iff_add, ← isCoprime_iff_exists, ← isCoprime_iff_sup_eq] simp theorem _root_.IsCoprime.codisjoint (h : IsCoprime I J) : Codisjoint I J := isCoprime_iff_codisjoint.mp h theorem _root_.IsCoprime.add_eq (h : IsCoprime I J) : I + J = 1 := isCoprime_iff_add.mp h theorem _root_.IsCoprime.exists (h : IsCoprime I J) : ∃ i ∈ I, ∃ j ∈ J, i + j = 1 := isCoprime_iff_exists.mp h theorem _root_.IsCoprime.sup_eq (h : IsCoprime I J) : I ⊔ J = ⊤ := isCoprime_iff_sup_eq.mp h theorem inf_eq_mul_of_isCoprime (coprime : IsCoprime I J) : I ⊓ J = I * J := (Ideal.mul_eq_inf_of_coprime coprime.sup_eq).symm theorem isCoprime_span_singleton_iff (x y : R) : IsCoprime (span <| singleton x) (span <| singleton y) ↔ IsCoprime x y := by simp_rw [isCoprime_iff_codisjoint, codisjoint_iff, eq_top_iff_one, mem_span_singleton_sup, mem_span_singleton] constructor · rintro ⟨a, _, ⟨b, rfl⟩, e⟩; exact ⟨a, b, mul_comm b y ▸ e⟩ · rintro ⟨a, b, e⟩; exact ⟨a, _, ⟨b, rfl⟩, mul_comm y b ▸ e⟩ theorem isCoprime_biInf {J : ι → Ideal R} {s : Finset ι} (hf : ∀ j ∈ s, IsCoprime I (J j)) : IsCoprime I (⨅ j ∈ s, J j) := by classical simp_rw [isCoprime_iff_add] at * induction s using Finset.induction with | empty => simp | insert i s _ hs => rw [Finset.iInf_insert, inf_comm, one_eq_top, eq_top_iff, ← one_eq_top] set K := ⨅ j ∈ s, J j calc 1 = I + K := (hs fun j hj ↦ hf j (Finset.mem_insert_of_mem hj)).symm _ = I + K*(I + J i) := by rw [hf i (Finset.mem_insert_self i s), mul_one] _ = (1+K)*I + K*J i := by ring _ ≤ I + K ⊓ J i := add_le_add mul_le_left mul_le_inf /-- The radical of an ideal `I` consists of the elements `r` such that `r ^ n ∈ I` for some `n`. -/ def radical (I : Ideal R) : Ideal R where carrier := { r | ∃ n : ℕ, r ^ n ∈ I } zero_mem' := ⟨1, (pow_one (0 : R)).symm ▸ I.zero_mem⟩ add_mem' := fun {_ _} ⟨m, hxmi⟩ ⟨n, hyni⟩ => ⟨m + n - 1, add_pow_add_pred_mem_of_pow_mem I hxmi hyni⟩ smul_mem' {r s} := fun ⟨n, h⟩ ↦ ⟨n, (mul_pow r s n).symm ▸ I.mul_mem_left (r ^ n) h⟩ theorem mem_radical_iff {r : R} : r ∈ I.radical ↔ ∃ n : ℕ, r ^ n ∈ I := Iff.rfl /-- An ideal is radical if it contains its radical. -/ def IsRadical (I : Ideal R) : Prop := I.radical ≤ I theorem le_radical : I ≤ radical I := fun r hri => ⟨1, (pow_one r).symm ▸ hri⟩ /-- An ideal is radical iff it is equal to its radical. -/ theorem radical_eq_iff : I.radical = I ↔ I.IsRadical := by rw [le_antisymm_iff, and_iff_left le_radical, IsRadical] alias ⟨_, IsRadical.radical⟩ := radical_eq_iff theorem isRadical_iff_pow_one_lt (k : ℕ) (hk : 1 < k) : I.IsRadical ↔ ∀ r, r ^ k ∈ I → r ∈ I := ⟨fun h _r hr ↦ h ⟨k, hr⟩, fun h x ⟨n, hx⟩ ↦
k.pow_imp_self_of_one_lt hk _ (fun _ _ ↦ .inr ∘ I.smul_mem _) h n x hx⟩ variable (R) in
Mathlib/RingTheory/Ideal/Operations.lean
723
725
/- Copyright (c) 2024 Violeta Hernández Palacios. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Violeta Hernández Palacios -/ import Mathlib.SetTheory.Cardinal.Arithmetic import Mathlib.SetTheory.Ordinal.Principal /-! # Ordinal arithmetic with cardinals This file collects results about the cardinality of different ordinal operations. -/ universe u v open Cardinal Ordinal Set /-! ### Cardinal operations with ordinal indices -/ namespace Cardinal /-- Bounds the cardinal of an ordinal-indexed union of sets. -/ lemma mk_iUnion_Ordinal_lift_le_of_le {β : Type v} {o : Ordinal.{u}} {c : Cardinal.{v}} (ho : lift.{v} o.card ≤ lift.{u} c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by simp_rw [← mem_Iio, biUnion_eq_iUnion, iUnion, iSup, ← o.enumIsoToType.symm.surjective.range_comp] rw [← lift_le.{u}] apply ((mk_iUnion_le_lift _).trans _).trans_eq (mul_eq_self (aleph0_le_lift.2 hc)) rw [mk_toType] refine mul_le_mul' ho (ciSup_le' ?_) intro i simpa using hA _ (o.enumIsoToType.symm i).2 lemma mk_iUnion_Ordinal_le_of_le {β : Type*} {o : Ordinal} {c : Cardinal} (ho : o.card ≤ c) (hc : ℵ₀ ≤ c) (A : Ordinal → Set β) (hA : ∀ j < o, #(A j) ≤ c) : #(⋃ j < o, A j) ≤ c := by apply mk_iUnion_Ordinal_lift_le_of_le _ hc A hA rwa [Cardinal.lift_le] end Cardinal @[deprecated mk_iUnion_Ordinal_le_of_le (since := "2024-11-02")] alias Ordinal.Cardinal.mk_iUnion_Ordinal_le_of_le := mk_iUnion_Ordinal_le_of_le /-! ### Cardinality of ordinals -/ namespace Ordinal theorem lift_card_iSup_le_sum_card {ι : Type u} [Small.{v} ι] (f : ι → Ordinal.{v}) : Cardinal.lift.{u} (⨆ i, f i).card ≤ Cardinal.sum fun i ↦ (f i).card := by simp_rw [← mk_toType] rw [← mk_sigma, ← Cardinal.lift_id'.{v} #(Σ _, _), ← Cardinal.lift_umax.{v, u}] apply lift_mk_le_lift_mk_of_surjective (f := enumIsoToType _ ∘ (⟨(enumIsoToType _).symm ·.2, (mem_Iio.mp ((enumIsoToType _).symm _).2).trans_le (Ordinal.le_iSup _ _)⟩)) rw [EquivLike.comp_surjective] rintro ⟨x, hx⟩ obtain ⟨i, hi⟩ := Ordinal.lt_iSup_iff.mp hx exact ⟨⟨i, enumIsoToType _ ⟨x, hi⟩⟩, by simp⟩ theorem card_iSup_le_sum_card {ι : Type u} (f : ι → Ordinal.{max u v}) : (⨆ i, f i).card ≤ Cardinal.sum (fun i ↦ (f i).card) := by have := lift_card_iSup_le_sum_card f rwa [Cardinal.lift_id'] at this theorem card_iSup_Iio_le_sum_card {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.sum fun i ↦ (f ((enumIsoToType o).symm i)).card := by apply le_of_eq_of_le (congr_arg _ _).symm (card_iSup_le_sum_card _) simpa using (enumIsoToType o).symm.iSup_comp (g := fun x ↦ f x) theorem card_iSup_Iio_le_card_mul_iSup {o : Ordinal.{u}} (f : Iio o → Ordinal.{max u v}) : (⨆ a : Iio o, f a).card ≤ Cardinal.lift.{v} o.card * ⨆ a : Iio o, (f a).card := by apply (card_iSup_Iio_le_sum_card f).trans convert ← sum_le_iSup_lift _ · exact mk_toType o · exact (enumIsoToType o).symm.iSup_comp (g := fun x ↦ (f x).card) theorem card_opow_le_of_omega0_le_left {a : Ordinal} (ha : ω ≤ a) (b : Ordinal) : (a ^ b).card ≤ max a.card b.card := by refine limitRecOn b ?_ ?_ ?_ · simpa using one_lt_omega0.le.trans ha · intro b IH rw [opow_succ, card_mul, card_succ, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply (max_le_max_left _ IH).trans rw [← max_assoc, max_self] exact max_le_max_left _ le_self_add · rw [ne_eq, card_eq_zero, opow_eq_zero] rintro ⟨rfl, -⟩ cases omega0_pos.not_le ha · rwa [aleph0_le_card] · intro b hb IH rw [(isNormal_opow (one_lt_omega0.trans_le ha)).apply_of_isLimit hb] apply (card_iSup_Iio_le_card_mul_iSup _).trans rw [Cardinal.lift_id, Cardinal.mul_eq_max_of_aleph0_le_right, max_comm] · apply max_le _ (le_max_right _ _) apply ciSup_le' intro c exact (IH c.1 c.2).trans (max_le_max_left _ (card_le_card c.2.le)) · simpa using hb.pos.ne' · refine le_ciSup_of_le ?_ ⟨1, one_lt_omega0.trans_le <| omega0_le_of_isLimit hb⟩ ?_ · exact Cardinal.bddAbove_of_small _ · simpa theorem card_opow_le_of_omega0_le_right (a : Ordinal) {b : Ordinal} (hb : ω ≤ b) : (a ^ b).card ≤ max a.card b.card := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · apply (card_le_card <| opow_le_opow_left b (nat_lt_omega0 n).le).trans apply (card_opow_le_of_omega0_le_left le_rfl _).trans simp [hb] · exact card_opow_le_of_omega0_le_left ha b theorem card_opow_le (a b : Ordinal) : (a ^ b).card ≤ max ℵ₀ (max a.card b.card) := by obtain ⟨n, rfl⟩ | ha := eq_nat_or_omega0_le a · obtain ⟨m, rfl⟩ | hb := eq_nat_or_omega0_le b · rw [← natCast_opow, card_nat] exact le_max_of_le_left (nat_lt_aleph0 _).le · exact (card_opow_le_of_omega0_le_right _ hb).trans (le_max_right _ _) · exact (card_opow_le_of_omega0_le_left ha _).trans (le_max_right _ _) theorem card_opow_eq_of_omega0_le_left {a b : Ordinal} (ha : ω ≤ a) (hb : 0 < b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_left ha b).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a hb · exact right_le_opow b (one_lt_omega0.trans_le ha) theorem card_opow_eq_of_omega0_le_right {a b : Ordinal} (ha : 1 < a) (hb : ω ≤ b) : (a ^ b).card = max a.card b.card := by apply (card_opow_le_of_omega0_le_right a hb).antisymm (max_le _ _) <;> apply card_le_card · exact left_le_opow a (omega0_pos.trans_le hb) · exact right_le_opow b ha theorem card_omega0_opow {a : Ordinal} (h : a ≠ 0) : card (ω ^ a) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_left le_rfl h.bot_lt, card_omega0] theorem card_opow_omega0 {a : Ordinal} (h : 1 < a) : card (a ^ ω) = max ℵ₀ a.card := by rw [card_opow_eq_of_omega0_le_right h le_rfl, card_omega0, max_comm] theorem principal_opow_omega (o : Ordinal) : Principal (· ^ ·) (ω_ o) := by obtain rfl | ho := Ordinal.eq_zero_or_pos o · rw [omega_zero] exact principal_opow_omega0 · intro a b ha hb rw [lt_omega_iff_card_lt] at ha hb ⊢ apply (card_opow_le a b).trans_lt (max_lt _ (max_lt ha hb)) rwa [← aleph_zero, aleph_lt_aleph] theorem IsInitial.principal_opow {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· ^ ·) o := by obtain ⟨a, rfl⟩ := mem_range_omega_iff.2 ⟨ho, h⟩ exact principal_opow_omega a theorem principal_opow_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· ^ ·) c.ord := by apply (isInitial_ord c).principal_opow rwa [omega0_le_ord] /-! ### Initial ordinals are principal -/ theorem principal_add_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· + ·) c.ord := by intro a b ha hb rw [lt_ord, card_add] at * exact add_lt_of_lt hc ha hb theorem IsInitial.principal_add {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· + ·) o := by rw [← h.ord_card] apply principal_add_ord rwa [aleph0_le_card] theorem principal_add_omega (o : Ordinal) : Principal (· + ·) (ω_ o) := (isInitial_omega o).principal_add (omega0_le_omega o) theorem principal_mul_ord {c : Cardinal} (hc : ℵ₀ ≤ c) : Principal (· * ·) c.ord := by intro a b ha hb rw [lt_ord, card_mul] at * exact mul_lt_of_lt hc ha hb theorem IsInitial.principal_mul {o : Ordinal} (h : IsInitial o) (ho : ω ≤ o) : Principal (· * ·) o := by rw [← h.ord_card] apply principal_mul_ord rwa [aleph0_le_card] theorem principal_mul_omega (o : Ordinal) : Principal (· * ·) (ω_ o) := (isInitial_omega o).principal_mul (omega0_le_omega o) @[deprecated principal_add_omega (since := "2024-11-08")] theorem _root_.Cardinal.principal_add_aleph (o : Ordinal) : Principal (· + ·) (ℵ_ o).ord := principal_add_ord <| aleph0_le_aleph o end Ordinal
Mathlib/SetTheory/Cardinal/Ordinal.lean
327
332
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Comap import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono, gcongr] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν @[gcongr] theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) : μ.restrict s ≤ ν.restrict s := restrict_mono subset_rfl h @[gcongr] theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) : μ.restrict s ≤ μ.restrict t := restrict_mono h le_rfl theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply]
theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)]
Mathlib/MeasureTheory/Measure/Restrict.lean
110
113
/- Copyright (c) 2019 Kim Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kim Morrison, Jakob von Raumer -/ import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts import Mathlib.CategoryTheory.Limits.Shapes.Kernels /-! # Biproducts and binary biproducts We introduce the notion of (finite) biproducts. Binary biproducts are defined in `CategoryTheory.Limits.Shapes.BinaryBiproducts`. These are slightly unusual relative to the other shapes in the library, as they are simultaneously limits and colimits. (Zero objects are similar; they are "biterminal".) For results about biproducts in preadditive categories see `CategoryTheory.Preadditive.Biproducts`. For biproducts indexed by a `Fintype J`, a `bicone` consists of a cone point `X` and morphisms `π j : X ⟶ F j` and `ι j : F j ⟶ X` for each `j`, such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. ## Notation As `⊕` is already taken for the sum of types, we introduce the notation `X ⊞ Y` for a binary biproduct. We introduce `⨁ f` for the indexed biproduct. ## Implementation notes Prior to https://github.com/leanprover-community/mathlib3/pull/14046, `HasFiniteBiproducts` required a `DecidableEq` instance on the indexing type. As this had no pay-off (everything about limits is non-constructive in mathlib), and occasional cost (constructing decidability instances appropriate for constructions involving the indexing type), we made everything classical. -/ noncomputable section universe w w' v u open CategoryTheory Functor namespace CategoryTheory.Limits variable {J : Type w} universe uC' uC uD' uD variable {C : Type uC} [Category.{uC'} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] open scoped Classical in /-- A `c : Bicone F` is: * an object `c.pt` and * morphisms `π j : pt ⟶ F j` and `ι j : F j ⟶ pt` for each `j`, * such that `ι j ≫ π j'` is the identity when `j = j'` and zero otherwise. -/ structure Bicone (F : J → C) where pt : C π : ∀ j, pt ⟶ F j ι : ∀ j, F j ⟶ pt ι_π : ∀ j j', ι j ≫ π j' = if h : j = j' then eqToHom (congrArg F h) else 0 := by aesop attribute [inherit_doc Bicone] Bicone.pt Bicone.π Bicone.ι Bicone.ι_π @[reassoc (attr := simp)] theorem bicone_ι_π_self {F : J → C} (B : Bicone F) (j : J) : B.ι j ≫ B.π j = 𝟙 (F j) := by simpa using B.ι_π j j @[reassoc (attr := simp)] theorem bicone_ι_π_ne {F : J → C} (B : Bicone F) {j j' : J} (h : j ≠ j') : B.ι j ≫ B.π j' = 0 := by simpa [h] using B.ι_π j j' variable {F : J → C} /-- A bicone morphism between two bicones for the same diagram is a morphism of the bicone points which commutes with the cone and cocone legs. -/ structure BiconeMorphism {F : J → C} (A B : Bicone F) where /-- A morphism between the two vertex objects of the bicones -/ hom : A.pt ⟶ B.pt /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wπ : ∀ j : J, hom ≫ B.π j = A.π j := by aesop_cat /-- The triangle consisting of the two natural transformations and `hom` commutes -/ wι : ∀ j : J, A.ι j ≫ hom = B.ι j := by aesop_cat attribute [reassoc (attr := simp)] BiconeMorphism.wι BiconeMorphism.wπ /-- The category of bicones on a given diagram. -/ @[simps] instance Bicone.category : Category (Bicone F) where Hom A B := BiconeMorphism A B comp f g := { hom := f.hom ≫ g.hom } id B := { hom := 𝟙 B.pt } -- Porting note: if we do not have `simps` automatically generate the lemma for simplifying -- the `hom` field of a category, we need to write the `ext` lemma in terms of the categorical -- morphism, rather than the underlying structure. @[ext] theorem BiconeMorphism.ext {c c' : Bicone F} (f g : c ⟶ c') (w : f.hom = g.hom) : f = g := by cases f cases g congr namespace Bicones /-- To give an isomorphism between cocones, it suffices to give an isomorphism between their vertices which commutes with the cocone maps. -/ @[aesop apply safe (rule_sets := [CategoryTheory]), simps] def ext {c c' : Bicone F} (φ : c.pt ≅ c'.pt) (wι : ∀ j, c.ι j ≫ φ.hom = c'.ι j := by aesop_cat) (wπ : ∀ j, φ.hom ≫ c'.π j = c.π j := by aesop_cat) : c ≅ c' where hom := { hom := φ.hom } inv := { hom := φ.inv wι := fun j => φ.comp_inv_eq.mpr (wι j).symm wπ := fun j => φ.inv_comp_eq.mpr (wπ j).symm } variable (F) in /-- A functor `G : C ⥤ D` sends bicones over `F` to bicones over `G.obj ∘ F` functorially. -/ @[simps] def functoriality (G : C ⥤ D) [Functor.PreservesZeroMorphisms G] : Bicone F ⥤ Bicone (G.obj ∘ F) where obj A := { pt := G.obj A.pt π := fun j => G.map (A.π j) ι := fun j => G.map (A.ι j) ι_π := fun i j => (Functor.map_comp _ _ _).symm.trans <| by rw [A.ι_π] aesop_cat } map f := { hom := G.map f.hom wπ := fun j => by simp [-BiconeMorphism.wπ, ← f.wπ j] wι := fun j => by simp [-BiconeMorphism.wι, ← f.wι j] } variable (G : C ⥤ D) instance functoriality_full [G.PreservesZeroMorphisms] [G.Full] [G.Faithful] : (functoriality F G).Full where map_surjective t := ⟨{ hom := G.preimage t.hom wι := fun j => G.map_injective (by simpa using t.wι j) wπ := fun j => G.map_injective (by simpa using t.wπ j) }, by aesop_cat⟩ instance functoriality_faithful [G.PreservesZeroMorphisms] [G.Faithful] : (functoriality F G).Faithful where map_injective {_X} {_Y} f g h := BiconeMorphism.ext f g <| G.map_injective <| congr_arg BiconeMorphism.hom h end Bicones namespace Bicone attribute [local aesop safe tactic (rule_sets := [CategoryTheory])] CategoryTheory.Discrete.discreteCases -- Porting note: would it be okay to use this more generally? attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Eq /-- Extract the cone from a bicone. -/ def toConeFunctor : Bicone F ⥤ Cone (Discrete.functor F) where obj B := { pt := B.pt, π := { app := fun j => B.π j.as } } map {_ _} F := { hom := F.hom, w := fun _ => F.wπ _ } /-- A shorthand for `toConeFunctor.obj` -/ abbrev toCone (B : Bicone F) : Cone (Discrete.functor F) := toConeFunctor.obj B -- TODO Consider changing this API to `toFan (B : Bicone F) : Fan F`. @[simp] theorem toCone_pt (B : Bicone F) : B.toCone.pt = B.pt := rfl @[simp] theorem toCone_π_app (B : Bicone F) (j : Discrete J) : B.toCone.π.app j = B.π j.as := rfl theorem toCone_π_app_mk (B : Bicone F) (j : J) : B.toCone.π.app ⟨j⟩ = B.π j := rfl @[simp] theorem toCone_proj (B : Bicone F) (j : J) : Fan.proj B.toCone j = B.π j := rfl /-- Extract the cocone from a bicone. -/ def toCoconeFunctor : Bicone F ⥤ Cocone (Discrete.functor F) where obj B := { pt := B.pt, ι := { app := fun j => B.ι j.as } } map {_ _} F := { hom := F.hom, w := fun _ => F.wι _ } /-- A shorthand for `toCoconeFunctor.obj` -/ abbrev toCocone (B : Bicone F) : Cocone (Discrete.functor F) := toCoconeFunctor.obj B @[simp] theorem toCocone_pt (B : Bicone F) : B.toCocone.pt = B.pt := rfl @[simp] theorem toCocone_ι_app (B : Bicone F) (j : Discrete J) : B.toCocone.ι.app j = B.ι j.as := rfl @[simp] theorem toCocone_inj (B : Bicone F) (j : J) : Cofan.inj B.toCocone j = B.ι j := rfl theorem toCocone_ι_app_mk (B : Bicone F) (j : J) : B.toCocone.ι.app ⟨j⟩ = B.ι j := rfl open scoped Classical in /-- We can turn any limit cone over a discrete collection of objects into a bicone. -/ @[simps] def ofLimitCone {f : J → C} {t : Cone (Discrete.functor f)} (ht : IsLimit t) : Bicone f where pt := t.pt π j := t.π.app ⟨j⟩ ι j := ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) ι_π j j' := by simp open scoped Classical in theorem ι_of_isLimit {f : J → C} {t : Bicone f} (ht : IsLimit t.toCone) (j : J) : t.ι j = ht.lift (Fan.mk _ fun j' => if h : j = j' then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] open scoped Classical in /-- We can turn any colimit cocone over a discrete collection of objects into a bicone. -/ @[simps] def ofColimitCocone {f : J → C} {t : Cocone (Discrete.functor f)} (ht : IsColimit t) : Bicone f where pt := t.pt π j := ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) ι j := t.ι.app ⟨j⟩ ι_π j j' := by simp open scoped Classical in theorem π_of_isColimit {f : J → C} {t : Bicone f} (ht : IsColimit t.toCocone) (j : J) : t.π j = ht.desc (Cofan.mk _ fun j' => if h : j' = j then eqToHom (congr_arg f h) else 0) := ht.hom_ext fun j' => by rw [ht.fac] simp [t.ι_π] /-- Structure witnessing that a bicone is both a limit cone and a colimit cocone. -/ structure IsBilimit {F : J → C} (B : Bicone F) where isLimit : IsLimit B.toCone isColimit : IsColimit B.toCocone attribute [inherit_doc IsBilimit] IsBilimit.isLimit IsBilimit.isColimit attribute [simp] IsBilimit.mk.injEq attribute [local ext] Bicone.IsBilimit instance subsingleton_isBilimit {f : J → C} {c : Bicone f} : Subsingleton c.IsBilimit := ⟨fun _ _ => Bicone.IsBilimit.ext (Subsingleton.elim _ _) (Subsingleton.elim _ _)⟩ section Whisker variable {K : Type w'} /-- Whisker a bicone with an equivalence between the indexing types. -/ @[simps] def whisker {f : J → C} (c : Bicone f) (g : K ≃ J) : Bicone (f ∘ g) where pt := c.pt π k := c.π (g k) ι k := c.ι (g k) ι_π k k' := by simp only [c.ι_π] split_ifs with h h' h' <;> simp [Equiv.apply_eq_iff_eq g] at h h' <;> tauto /-- Taking the cone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cone and postcomposing with a suitable isomorphism. -/ def whiskerToCone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCone ≅ (Cones.postcompose (Discrete.functorComp f g).inv).obj (c.toCone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cones.ext (Iso.refl _) (by simp) /-- Taking the cocone of a whiskered bicone results in a cone isomorphic to one gained by whiskering the cocone and precomposing with a suitable isomorphism. -/ def whiskerToCocone {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).toCocone ≅ (Cocones.precompose (Discrete.functorComp f g).hom).obj (c.toCocone.whisker (Discrete.functor (Discrete.mk ∘ g))) := Cocones.ext (Iso.refl _) (by simp) /-- Whiskering a bicone with an equivalence between types preserves being a bilimit bicone. -/ noncomputable def whiskerIsBilimitIff {f : J → C} (c : Bicone f) (g : K ≃ J) : (c.whisker g).IsBilimit ≃ c.IsBilimit := by refine equivOfSubsingletonOfSubsingleton (fun hc => ⟨?_, ?_⟩) fun hc => ⟨?_, ?_⟩ · let this := IsLimit.ofIsoLimit hc.isLimit (Bicone.whiskerToCone c g) let this := (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _) this exact IsLimit.ofWhiskerEquivalence (Discrete.equivalence g) this · let this := IsColimit.ofIsoColimit hc.isColimit (Bicone.whiskerToCocone c g) let this := (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _) this exact IsColimit.ofWhiskerEquivalence (Discrete.equivalence g) this · apply IsLimit.ofIsoLimit _ (Bicone.whiskerToCone c g).symm apply (IsLimit.postcomposeHomEquiv (Discrete.functorComp f g).symm _).symm _ exact IsLimit.whiskerEquivalence hc.isLimit (Discrete.equivalence g) · apply IsColimit.ofIsoColimit _ (Bicone.whiskerToCocone c g).symm apply (IsColimit.precomposeHomEquiv (Discrete.functorComp f g) _).symm _ exact IsColimit.whiskerEquivalence hc.isColimit (Discrete.equivalence g) end Whisker end Bicone /-- A bicone over `F : J → C`, which is both a limit cone and a colimit cocone. -/ structure LimitBicone (F : J → C) where bicone : Bicone F isBilimit : bicone.IsBilimit attribute [inherit_doc LimitBicone] LimitBicone.bicone LimitBicone.isBilimit /-- `HasBiproduct F` expresses the mere existence of a bicone which is simultaneously a limit and a colimit of the diagram `F`. -/ class HasBiproduct (F : J → C) : Prop where mk' :: exists_biproduct : Nonempty (LimitBicone F) attribute [inherit_doc HasBiproduct] HasBiproduct.exists_biproduct theorem HasBiproduct.mk {F : J → C} (d : LimitBicone F) : HasBiproduct F := ⟨Nonempty.intro d⟩ /-- Use the axiom of choice to extract explicit `BiproductData F` from `HasBiproduct F`. -/ def getBiproductData (F : J → C) [HasBiproduct F] : LimitBicone F := Classical.choice HasBiproduct.exists_biproduct /-- A bicone for `F` which is both a limit cone and a colimit cocone. -/ def biproduct.bicone (F : J → C) [HasBiproduct F] : Bicone F := (getBiproductData F).bicone /-- `biproduct.bicone F` is a bilimit bicone. -/ def biproduct.isBilimit (F : J → C) [HasBiproduct F] : (biproduct.bicone F).IsBilimit := (getBiproductData F).isBilimit /-- `biproduct.bicone F` is a limit cone. -/ def biproduct.isLimit (F : J → C) [HasBiproduct F] : IsLimit (biproduct.bicone F).toCone := (getBiproductData F).isBilimit.isLimit /-- `biproduct.bicone F` is a colimit cocone. -/ def biproduct.isColimit (F : J → C) [HasBiproduct F] : IsColimit (biproduct.bicone F).toCocone := (getBiproductData F).isBilimit.isColimit instance (priority := 100) hasProduct_of_hasBiproduct [HasBiproduct F] : HasProduct F := HasLimit.mk { cone := (biproduct.bicone F).toCone isLimit := biproduct.isLimit F } instance (priority := 100) hasCoproduct_of_hasBiproduct [HasBiproduct F] : HasCoproduct F := HasColimit.mk { cocone := (biproduct.bicone F).toCocone isColimit := biproduct.isColimit F } variable (J C) /-- `C` has biproducts of shape `J` if we have a limit and a colimit, with the same cone points, of every function `F : J → C`. -/ class HasBiproductsOfShape : Prop where has_biproduct : ∀ F : J → C, HasBiproduct F attribute [instance 100] HasBiproductsOfShape.has_biproduct /-- `HasFiniteBiproducts C` represents a choice of biproduct for every family of objects in `C` indexed by a finite type. -/ class HasFiniteBiproducts : Prop where out : ∀ n, HasBiproductsOfShape (Fin n) C attribute [inherit_doc HasFiniteBiproducts] HasFiniteBiproducts.out variable {J} theorem hasBiproductsOfShape_of_equiv {K : Type w'} [HasBiproductsOfShape K C] (e : J ≃ K) : HasBiproductsOfShape J C := ⟨fun F => let ⟨⟨h⟩⟩ := HasBiproductsOfShape.has_biproduct (F ∘ e.symm) let ⟨c, hc⟩ := h HasBiproduct.mk <| by simpa only [Function.comp_def, e.symm_apply_apply] using LimitBicone.mk (c.whisker e) ((c.whiskerIsBilimitIff _).2 hc)⟩ instance (priority := 100) hasBiproductsOfShape_finite [HasFiniteBiproducts C] [Finite J] : HasBiproductsOfShape J C := by rcases Finite.exists_equiv_fin J with ⟨n, ⟨e⟩⟩ haveI : HasBiproductsOfShape (Fin n) C := HasFiniteBiproducts.out n exact hasBiproductsOfShape_of_equiv C e instance (priority := 100) hasFiniteProducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteProducts C where out _ := ⟨fun _ => hasLimit_of_iso Discrete.natIsoFunctor.symm⟩ instance (priority := 100) hasFiniteCoproducts_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasFiniteCoproducts C where out _ := ⟨fun _ => hasColimit_of_iso Discrete.natIsoFunctor⟩ instance (priority := 100) hasProductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] : HasProductsOfShape J C where has_limit _ := hasLimit_of_iso Discrete.natIsoFunctor.symm instance (priority := 100) hasCoproductsOfShape_of_hasBiproductsOfShape [HasBiproductsOfShape J C] : HasCoproductsOfShape J C where has_colimit _ := hasColimit_of_iso Discrete.natIsoFunctor variable {C} /-- The isomorphism between the specified limit and the specified colimit for a functor with a bilimit. -/ def biproductIso (F : J → C) [HasBiproduct F] : Limits.piObj F ≅ Limits.sigmaObj F := (IsLimit.conePointUniqueUpToIso (limit.isLimit _) (biproduct.isLimit F)).trans <| IsColimit.coconePointUniqueUpToIso (biproduct.isColimit F) (colimit.isColimit _) variable {J : Type w} {K : Type*} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] /-- `biproduct f` computes the biproduct of a family of elements `f`. (It is defined as an abbreviation for `limit (Discrete.functor f)`, so for most facts about `biproduct f`, you will just use general facts about limits and colimits.) -/ abbrev biproduct (f : J → C) [HasBiproduct f] : C := (biproduct.bicone f).pt @[inherit_doc biproduct] notation "⨁ " f:20 => biproduct f /-- The projection onto a summand of a biproduct. -/ abbrev biproduct.π (f : J → C) [HasBiproduct f] (b : J) : ⨁ f ⟶ f b := (biproduct.bicone f).π b @[simp] theorem biproduct.bicone_π (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).π b = biproduct.π f b := rfl /-- The inclusion into a summand of a biproduct. -/ abbrev biproduct.ι (f : J → C) [HasBiproduct f] (b : J) : f b ⟶ ⨁ f := (biproduct.bicone f).ι b @[simp] theorem biproduct.bicone_ι (f : J → C) [HasBiproduct f] (b : J) : (biproduct.bicone f).ι b = biproduct.ι f b := rfl /-- Note that as this lemma has an `if` in the statement, we include a `DecidableEq` argument. This means you may not be able to `simp` using this lemma unless you `open scoped Classical`. -/ @[reassoc] theorem biproduct.ι_π [DecidableEq J] (f : J → C) [HasBiproduct f] (j j' : J) : biproduct.ι f j ≫ biproduct.π f j' = if h : j = j' then eqToHom (congr_arg f h) else 0 := by convert (biproduct.bicone f).ι_π j j' @[reassoc] -- Porting note: both versions proven by simp theorem biproduct.ι_π_self (f : J → C) [HasBiproduct f] (j : J) : biproduct.ι f j ≫ biproduct.π f j = 𝟙 _ := by simp [biproduct.ι_π] @[reassoc (attr := simp)] theorem biproduct.ι_π_ne (f : J → C) [HasBiproduct f] {j j' : J} (h : j ≠ j') : biproduct.ι f j ≫ biproduct.π f j' = 0 := by simp [biproduct.ι_π, h] -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.eqToHom_comp_ι (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : eqToHom (by simp [w]) ≫ biproduct.ι f j' = biproduct.ι f j := by cases w simp -- The `simpNF` linter incorrectly identifies these as simp lemmas that could never apply. -- It seems the side condition `w` is not applied by `simpNF`. -- https://github.com/leanprover-community/mathlib4/issues/5049 -- They are used by `simp` in `biproduct.whiskerEquiv` below. @[reassoc (attr := simp, nolint simpNF)] theorem biproduct.π_comp_eqToHom (f : J → C) [HasBiproduct f] {j j' : J} (w : j = j') : biproduct.π f j ≫ eqToHom (by simp [w]) = biproduct.π f j' := by cases w simp /-- Given a collection of maps into the summands, we obtain a map into the biproduct. -/ abbrev biproduct.lift {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) : P ⟶ ⨁ f := (biproduct.isLimit f).lift (Fan.mk P p) /-- Given a collection of maps out of the summands, we obtain a map out of the biproduct. -/ abbrev biproduct.desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) : ⨁ f ⟶ P := (biproduct.isColimit f).desc (Cofan.mk P p) @[reassoc (attr := simp)] theorem biproduct.lift_π {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, P ⟶ f b) (j : J) : biproduct.lift p ≫ biproduct.π f j = p j := (biproduct.isLimit f).fac _ ⟨j⟩ @[reassoc (attr := simp)] theorem biproduct.ι_desc {f : J → C} [HasBiproduct f] {P : C} (p : ∀ b, f b ⟶ P) (j : J) : biproduct.ι f j ≫ biproduct.desc p = p j := (biproduct.isColimit f).fac _ ⟨j⟩ /-- Given a collection of maps between corresponding summands of a pair of biproducts indexed by the same type, we obtain a map between the biproducts. -/ abbrev biproduct.map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsLimit.map (biproduct.bicone f).toCone (biproduct.isLimit g) (Discrete.natTrans (fun j => p j.as)) /-- An alternative to `biproduct.map` constructed via colimits. This construction only exists in order to show it is equal to `biproduct.map`. -/ abbrev biproduct.map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : ⨁ f ⟶ ⨁ g := IsColimit.map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) -- We put this at slightly higher priority than `biproduct.hom_ext'`, -- to get the matrix indices in the "right" order. @[ext 1001] theorem biproduct.hom_ext {f : J → C} [HasBiproduct f] {Z : C} (g h : Z ⟶ ⨁ f) (w : ∀ j, g ≫ biproduct.π f j = h ≫ biproduct.π f j) : g = h := (biproduct.isLimit f).hom_ext fun j => w j.as @[ext] theorem biproduct.hom_ext' {f : J → C} [HasBiproduct f] {Z : C} (g h : ⨁ f ⟶ Z) (w : ∀ j, biproduct.ι f j ≫ g = biproduct.ι f j ≫ h) : g = h := (biproduct.isColimit f).hom_ext fun j => w j.as /-- The canonical isomorphism between the chosen biproduct and the chosen product. -/ def biproduct.isoProduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∏ᶜ f := IsLimit.conePointUniqueUpToIso (biproduct.isLimit f) (limit.isLimit _) @[simp] theorem biproduct.isoProduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).hom = Pi.lift (biproduct.π f) := limit.hom_ext fun j => by simp [biproduct.isoProduct] @[simp] theorem biproduct.isoProduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoProduct f).inv = biproduct.lift (Pi.π f) := biproduct.hom_ext _ _ fun j => by simp [Iso.inv_comp_eq] /-- The canonical isomorphism between the chosen biproduct and the chosen coproduct. -/ def biproduct.isoCoproduct (f : J → C) [HasBiproduct f] : ⨁ f ≅ ∐ f := IsColimit.coconePointUniqueUpToIso (biproduct.isColimit f) (colimit.isColimit _) @[simp] theorem biproduct.isoCoproduct_inv {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).inv = Sigma.desc (biproduct.ι f) := colimit.hom_ext fun j => by simp [biproduct.isoCoproduct] @[simp] theorem biproduct.isoCoproduct_hom {f : J → C} [HasBiproduct f] : (biproduct.isoCoproduct f).hom = biproduct.desc (Sigma.ι f) := biproduct.hom_ext' _ _ fun j => by simp [← Iso.eq_comp_inv] /-- If a category has biproducts of a shape `J`, its `colim` and `lim` functor on diagrams over `J` are isomorphic. -/ @[simps!] def HasBiproductsOfShape.colimIsoLim [HasBiproductsOfShape J C] : colim (J := Discrete J) (C := C) ≅ lim := NatIso.ofComponents (fun F => (Sigma.isoColimit F).symm ≪≫ (biproduct.isoCoproduct _).symm ≪≫ biproduct.isoProduct _ ≪≫ Pi.isoLimit F) fun η => colimit.hom_ext fun ⟨i⟩ => limit.hom_ext fun ⟨j⟩ => by classical by_cases h : i = j <;> simp_all [h, Sigma.isoColimit, Pi.isoLimit, biproduct.ι_π, biproduct.ι_π_assoc] theorem biproduct.map_eq_map' {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ⟶ g b) : biproduct.map p = biproduct.map' p := by classical ext dsimp simp only [Discrete.natTrans_app, Limits.IsColimit.ι_map_assoc, Limits.IsLimit.map_π, Category.assoc, ← Bicone.toCone_π_app_mk, ← biproduct.bicone_π, ← Bicone.toCocone_ι_app_mk, ← biproduct.bicone_ι] dsimp rw [biproduct.ι_π_assoc, biproduct.ι_π] split_ifs with h · subst h; simp · simp @[reassoc (attr := simp)] theorem biproduct.map_π {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.map p ≫ biproduct.π g j = biproduct.π f j ≫ p j := Limits.IsLimit.map_π _ _ _ (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.ι_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) (j : J) : biproduct.ι f j ≫ biproduct.map p = p j ≫ biproduct.ι g j := by rw [biproduct.map_eq_map'] apply Limits.IsColimit.ι_map (biproduct.isColimit f) (biproduct.bicone g).toCocone (Discrete.natTrans fun j => p j.as) (Discrete.mk j) @[reassoc (attr := simp)] theorem biproduct.map_desc {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) {P : C} (k : ∀ j, g j ⟶ P) : biproduct.map p ≫ biproduct.desc k = biproduct.desc fun j => p j ≫ k j := by ext; simp @[reassoc (attr := simp)] theorem biproduct.lift_map {f g : J → C} [HasBiproduct f] [HasBiproduct g] {P : C} (k : ∀ j, P ⟶ f j) (p : ∀ j, f j ⟶ g j) : biproduct.lift k ≫ biproduct.map p = biproduct.lift fun j => k j ≫ p j := by ext; simp /-- Given a collection of isomorphisms between corresponding summands of a pair of biproducts indexed by the same type, we obtain an isomorphism between the biproducts. -/ @[simps] def biproduct.mapIso {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ b, f b ≅ g b) : ⨁ f ≅ ⨁ g where hom := biproduct.map fun b => (p b).hom inv := biproduct.map fun b => (p b).inv instance biproduct.map_epi {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Epi (p j)] : Epi (biproduct.map p) := by classical have : biproduct.map p = (biproduct.isoCoproduct _).hom ≫ Sigma.map p ≫ (biproduct.isoCoproduct _).inv := by ext simp only [map_π, isoCoproduct_hom, isoCoproduct_inv, Category.assoc, ι_desc_assoc, ι_colimMap_assoc, Discrete.functor_obj_eq_as, Discrete.natTrans_app, colimit.ι_desc_assoc, Cofan.mk_pt, Cofan.mk_ι_app, ι_π, ι_π_assoc] split all_goals simp_all rw [this] infer_instance instance Pi.map_epi {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Epi (p j)] : Epi (Pi.map p) := by rw [show Pi.map p = (biproduct.isoProduct _).inv ≫ biproduct.map p ≫ (biproduct.isoProduct _).hom by aesop] infer_instance instance biproduct.map_mono {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Mono (p j)] : Mono (biproduct.map p) := by rw [show biproduct.map p = (biproduct.isoProduct _).hom ≫ Pi.map p ≫ (biproduct.isoProduct _).inv by aesop] infer_instance instance Sigma.map_mono {f g : J → C} [HasBiproduct f] [HasBiproduct g] (p : ∀ j, f j ⟶ g j) [∀ j, Mono (p j)] : Mono (Sigma.map p) := by rw [show Sigma.map p = (biproduct.isoCoproduct _).inv ≫ biproduct.map p ≫ (biproduct.isoCoproduct _).hom by aesop] infer_instance /-- Two biproducts which differ by an equivalence in the indexing type, and up to isomorphism in the factors, are isomorphic. Unfortunately there are two natural ways to define each direction of this isomorphism (because it is true for both products and coproducts separately). We give the alternative definitions as lemmas below. -/ @[simps] def biproduct.whiskerEquiv {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : ⨁ f ≅ ⨁ g where hom := biproduct.desc fun j => (w j).inv ≫ biproduct.ι g (e j) inv := biproduct.desc fun k => eqToHom (by simp) ≫ (w (e.symm k)).hom ≫ biproduct.ι f _ lemma biproduct.whiskerEquiv_hom_eq_lift {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).hom = biproduct.lift fun k => biproduct.π f (e.symm k) ≫ (w _).inv ≫ eqToHom (by simp) := by simp only [whiskerEquiv_hom] ext k j by_cases h : k = e j · subst h simp · simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] · simp · rintro rfl simp at h · exact Ne.symm h lemma biproduct.whiskerEquiv_inv_eq_lift {f : J → C} {g : K → C} (e : J ≃ K) (w : ∀ j, g (e j) ≅ f j) [HasBiproduct f] [HasBiproduct g] : (biproduct.whiskerEquiv e w).inv = biproduct.lift fun j => biproduct.π g (e j) ≫ (w j).hom := by simp only [whiskerEquiv_inv] ext j k by_cases h : k = e j · subst h simp only [ι_desc_assoc, ← eqToHom_iso_hom_naturality_assoc w (e.symm_apply_apply j).symm, Equiv.symm_apply_apply, eqToHom_comp_ι, Category.assoc, bicone_ι_π_self, Category.comp_id, lift_π, bicone_ι_π_self_assoc] · simp only [ι_desc_assoc, Category.assoc, ne_eq, lift_π] rw [biproduct.ι_π_ne, biproduct.ι_π_ne_assoc] · simp · exact h · rintro rfl simp at h attribute [local simp] Sigma.forall in instance {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : HasBiproduct fun p : Σ i, f i => g p.1 p.2 where exists_biproduct := Nonempty.intro { bicone := { pt := ⨁ fun i => ⨁ g i ι := fun X => biproduct.ι (g X.1) X.2 ≫ biproduct.ι (fun i => ⨁ g i) X.1 π := fun X => biproduct.π (fun i => ⨁ g i) X.1 ≫ biproduct.π (g X.1) X.2 ι_π := fun ⟨j, x⟩ ⟨j', y⟩ => by split_ifs with h · obtain ⟨rfl, rfl⟩ := h simp · simp only [Sigma.mk.inj_iff, not_and] at h by_cases w : j = j' · cases w simp only [heq_eq_eq, forall_true_left] at h simp [biproduct.ι_π_ne _ h] · simp [biproduct.ι_π_ne_assoc _ w] } isBilimit := { isLimit := mkFanLimit _ (fun s => biproduct.lift fun b => biproduct.lift fun c => s.proj ⟨b, c⟩) isColimit := mkCofanColimit _ (fun s => biproduct.desc fun b => biproduct.desc fun c => s.inj ⟨b, c⟩) } } /-- An iterated biproduct is a biproduct over a sigma type. -/ @[simps] def biproductBiproductIso {ι} (f : ι → Type*) (g : (i : ι) → (f i) → C) [∀ i, HasBiproduct (g i)] [HasBiproduct fun i => ⨁ g i] : (⨁ fun i => ⨁ g i) ≅ (⨁ fun p : Σ i, f i => g p.1 p.2) where hom := biproduct.lift fun ⟨i, x⟩ => biproduct.π _ i ≫ biproduct.π _ x inv := biproduct.lift fun i => biproduct.lift fun x => biproduct.π _ (⟨i, x⟩ : Σ i, f i) section πKernel section variable (f : J → C) [HasBiproduct f] variable (p : J → Prop) [HasBiproduct (Subtype.restrict p f)] /-- The canonical morphism from the biproduct over a restricted index type to the biproduct of the full index type. -/ def biproduct.fromSubtype : ⨁ Subtype.restrict p f ⟶ ⨁ f := biproduct.desc fun j => biproduct.ι _ j.val /-- The canonical morphism from a biproduct to the biproduct over a restriction of its index type. -/ def biproduct.toSubtype : ⨁ f ⟶ ⨁ Subtype.restrict p f := biproduct.lift fun _ => biproduct.π _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_π [DecidablePred p] (j : J) : biproduct.fromSubtype f p ≫ biproduct.π f j = if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := by classical ext i; dsimp rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π] by_cases h : p j · rw [dif_pos h, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] · rw [dif_neg h, dif_neg (show (i : J) ≠ j from fun h₂ => h (h₂ ▸ i.2)), comp_zero] theorem biproduct.fromSubtype_eq_lift [DecidablePred p] : biproduct.fromSubtype f p = biproduct.lift fun j => if h : p j then biproduct.π (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext _ _ (by simp) @[reassoc] -- Porting note: both version solved using simp theorem biproduct.fromSubtype_π_subtype (j : Subtype p) : biproduct.fromSubtype f p ≫ biproduct.π f j = biproduct.π (Subtype.restrict p f) j := by classical ext rw [biproduct.fromSubtype, biproduct.ι_desc_assoc, biproduct.ι_π, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] @[reassoc (attr := simp)] theorem biproduct.toSubtype_π (j : Subtype p) : biproduct.toSubtype f p ≫ biproduct.π (Subtype.restrict p f) j = biproduct.π f j := biproduct.lift_π _ _ @[reassoc (attr := simp)] theorem biproduct.ι_toSubtype [DecidablePred p] (j : J) : biproduct.ι f j ≫ biproduct.toSubtype f p = if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := by classical ext i rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π] by_cases h : p j · rw [dif_pos h, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] · rw [dif_neg h, dif_neg (show j ≠ i from fun h₂ => h (h₂.symm ▸ i.2)), zero_comp] theorem biproduct.toSubtype_eq_desc [DecidablePred p] : biproduct.toSubtype f p = biproduct.desc fun j => if h : p j then biproduct.ι (Subtype.restrict p f) ⟨j, h⟩ else 0 := biproduct.hom_ext' _ _ (by simp) @[reassoc] theorem biproduct.ι_toSubtype_subtype (j : Subtype p) : biproduct.ι f j ≫ biproduct.toSubtype f p = biproduct.ι (Subtype.restrict p f) j := by classical ext rw [biproduct.toSubtype, Category.assoc, biproduct.lift_π, biproduct.ι_π, biproduct.ι_π] split_ifs with h₁ h₂ h₂ exacts [rfl, False.elim (h₂ (Subtype.ext h₁)), False.elim (h₁ (congr_arg Subtype.val h₂)), rfl] @[reassoc (attr := simp)] theorem biproduct.ι_fromSubtype (j : Subtype p) : biproduct.ι (Subtype.restrict p f) j ≫ biproduct.fromSubtype f p = biproduct.ι f j := biproduct.ι_desc _ _ @[reassoc (attr := simp)] theorem biproduct.fromSubtype_toSubtype : biproduct.fromSubtype f p ≫ biproduct.toSubtype f p = 𝟙 (⨁ Subtype.restrict p f) := by refine biproduct.hom_ext _ _ fun j => ?_ rw [Category.assoc, biproduct.toSubtype_π, biproduct.fromSubtype_π_subtype, Category.id_comp] @[reassoc (attr := simp)] theorem biproduct.toSubtype_fromSubtype [DecidablePred p] : biproduct.toSubtype f p ≫ biproduct.fromSubtype f p = biproduct.map fun j => if p j then 𝟙 (f j) else 0 := by ext1 i by_cases h : p i · simp [h] · simp [h] end section variable (f : J → C) (i : J) [HasBiproduct f] [HasBiproduct (Subtype.restrict (fun j => j ≠ i) f)] open scoped Classical in /-- The kernel of `biproduct.π f i` is the inclusion from the biproduct which omits `i` from the index set `J` into the biproduct over `J`. -/ def biproduct.isLimitFromSubtype : IsLimit (KernelFork.ofι (biproduct.fromSubtype f fun j => j ≠ i) (by simp) : KernelFork (biproduct.π f i)) := Fork.IsLimit.mk' _ fun s => ⟨s.ι ≫ biproduct.toSubtype _ _, by apply biproduct.hom_ext; intro j rw [KernelFork.ι_ofι, Category.assoc, Category.assoc, biproduct.toSubtype_fromSubtype_assoc, biproduct.map_π] rcases Classical.em (i = j) with (rfl | h) · rw [if_neg (Classical.not_not.2 rfl), comp_zero, comp_zero, KernelFork.condition] · rw [if_pos (Ne.symm h), Category.comp_id], by intro m hm rw [← hm, KernelFork.ι_ofι, Category.assoc, biproduct.fromSubtype_toSubtype] exact (Category.comp_id _).symm⟩ instance : HasKernel (biproduct.π f i) := HasLimit.mk ⟨_, biproduct.isLimitFromSubtype f i⟩ /-- The kernel of `biproduct.π f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/ @[simps!] def kernelBiproductπIso : kernel (biproduct.π f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f := limit.isoLimitCone ⟨_, biproduct.isLimitFromSubtype f i⟩ open scoped Classical in /-- The cokernel of `biproduct.ι f i` is the projection from the biproduct over the index set `J` onto the biproduct omitting `i`. -/ def biproduct.isColimitToSubtype : IsColimit (CokernelCofork.ofπ (biproduct.toSubtype f fun j => j ≠ i) (by simp) : CokernelCofork (biproduct.ι f i)) := Cofork.IsColimit.mk' _ fun s => ⟨biproduct.fromSubtype _ _ ≫ s.π, by apply biproduct.hom_ext'; intro j rw [CokernelCofork.π_ofπ, biproduct.toSubtype_fromSubtype_assoc, biproduct.ι_map_assoc] rcases Classical.em (i = j) with (rfl | h) · rw [if_neg (Classical.not_not.2 rfl), zero_comp, CokernelCofork.condition] · rw [if_pos (Ne.symm h), Category.id_comp], by intro m hm rw [← hm, CokernelCofork.π_ofπ, ← Category.assoc, biproduct.fromSubtype_toSubtype] exact (Category.id_comp _).symm⟩ instance : HasCokernel (biproduct.ι f i) := HasColimit.mk ⟨_, biproduct.isColimitToSubtype f i⟩ /-- The cokernel of `biproduct.ι f i` is `⨁ Subtype.restrict {i}ᶜ f`. -/ @[simps!] def cokernelBiproductιIso : cokernel (biproduct.ι f i) ≅ ⨁ Subtype.restrict (fun j => j ≠ i) f := colimit.isoColimitCocone ⟨_, biproduct.isColimitToSubtype f i⟩ end section -- Per https://github.com/leanprover-community/mathlib3/pull/15067, we only allow indexing in `Type 0` here. variable {K : Type} [Finite K] [HasFiniteBiproducts C] (f : K → C) /-- The limit cone exhibiting `⨁ Subtype.restrict pᶜ f` as the kernel of `biproduct.toSubtype f p` -/ @[simps] def kernelForkBiproductToSubtype (p : Set K) : LimitCone (parallelPair (biproduct.toSubtype f p) 0) where cone := KernelFork.ofι (biproduct.fromSubtype f pᶜ) (by classical ext j k simp only [Category.assoc, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] rw [dif_neg k.2] simp only [zero_comp]) isLimit := KernelFork.IsLimit.ofι _ _ (fun {_} g _ => g ≫ biproduct.toSubtype f pᶜ) (by classical intro W' g' w ext j simp only [Category.assoc, biproduct.toSubtype_fromSubtype, Pi.compl_apply, biproduct.map_π] split_ifs with h · simp · replace w := w =≫ biproduct.π _ ⟨j, not_not.mp h⟩ simpa using w.symm) (by aesop_cat) instance (p : Set K) : HasKernel (biproduct.toSubtype f p) := HasLimit.mk (kernelForkBiproductToSubtype f p) /-- The kernel of `biproduct.toSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/ @[simps!] def kernelBiproductToSubtypeIso (p : Set K) : kernel (biproduct.toSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f := limit.isoLimitCone (kernelForkBiproductToSubtype f p) /-- The colimit cocone exhibiting `⨁ Subtype.restrict pᶜ f` as the cokernel of `biproduct.fromSubtype f p` -/ @[simps] def cokernelCoforkBiproductFromSubtype (p : Set K) : ColimitCocone (parallelPair (biproduct.fromSubtype f p) 0) where cocone := CokernelCofork.ofπ (biproduct.toSubtype f pᶜ) (by classical ext j k simp only [Category.assoc, Pi.compl_apply, biproduct.ι_fromSubtype_assoc, biproduct.ι_toSubtype_assoc, comp_zero, zero_comp] rw [dif_neg] · simp only [zero_comp] · exact not_not.mpr k.2) isColimit := CokernelCofork.IsColimit.ofπ _ _ (fun {_} g _ => biproduct.fromSubtype f pᶜ ≫ g) (by classical intro W g' w ext j simp only [biproduct.toSubtype_fromSubtype_assoc, Pi.compl_apply, biproduct.ι_map_assoc] split_ifs with h · simp · replace w := biproduct.ι _ (⟨j, not_not.mp h⟩ : p) ≫= w simpa using w.symm) (by aesop_cat) instance (p : Set K) : HasCokernel (biproduct.fromSubtype f p) := HasColimit.mk (cokernelCoforkBiproductFromSubtype f p) /-- The cokernel of `biproduct.fromSubtype f p` is `⨁ Subtype.restrict pᶜ f`. -/ @[simps!] def cokernelBiproductFromSubtypeIso (p : Set K) : cokernel (biproduct.fromSubtype f p) ≅ ⨁ Subtype.restrict pᶜ f := colimit.isoColimitCocone (cokernelCoforkBiproductFromSubtype f p) end end πKernel section FiniteBiproducts variable {J : Type} [Finite J] {K : Type} [Finite K] {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasFiniteBiproducts C] {f : J → C} {g : K → C} /-- Convert a (dependently typed) matrix to a morphism of biproducts. -/ def biproduct.matrix (m : ∀ j k, f j ⟶ g k) : ⨁ f ⟶ ⨁ g := biproduct.desc fun j => biproduct.lift fun k => m j k @[reassoc (attr := simp)] theorem biproduct.matrix_π (m : ∀ j k, f j ⟶ g k) (k : K) : biproduct.matrix m ≫ biproduct.π g k = biproduct.desc fun j => m j k := by ext simp [biproduct.matrix] @[reassoc (attr := simp)] theorem biproduct.ι_matrix (m : ∀ j k, f j ⟶ g k) (j : J) : biproduct.ι f j ≫ biproduct.matrix m = biproduct.lift fun k => m j k := by ext simp [biproduct.matrix] /-- Extract the matrix components from a morphism of biproducts. -/ def biproduct.components (m : ⨁ f ⟶ ⨁ g) (j : J) (k : K) : f j ⟶ g k := biproduct.ι f j ≫ m ≫ biproduct.π g k @[simp] theorem biproduct.matrix_components (m : ∀ j k, f j ⟶ g k) (j : J) (k : K) : biproduct.components (biproduct.matrix m) j k = m j k := by simp [biproduct.components] @[simp] theorem biproduct.components_matrix (m : ⨁ f ⟶ ⨁ g) : (biproduct.matrix fun j k => biproduct.components m j k) = m := by ext simp [biproduct.components] /-- Morphisms between direct sums are matrices. -/ @[simps] def biproduct.matrixEquiv : (⨁ f ⟶ ⨁ g) ≃ ∀ j k, f j ⟶ g k where toFun := biproduct.components invFun := biproduct.matrix left_inv := biproduct.components_matrix right_inv m := by ext apply biproduct.matrix_components end FiniteBiproducts variable {J : Type w} variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] variable {D : Type uD} [Category.{uD'} D] [HasZeroMorphisms D] instance biproduct.ι_mono (f : J → C) [HasBiproduct f] (b : J) : IsSplitMono (biproduct.ι f b) := by classical exact IsSplitMono.mk' { retraction := biproduct.desc <| Pi.single b (𝟙 (f b)) } instance biproduct.π_epi (f : J → C) [HasBiproduct f] (b : J) : IsSplitEpi (biproduct.π f b) := by classical exact IsSplitEpi.mk' { section_ := biproduct.lift <| Pi.single b (𝟙 (f b)) } /-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/ theorem biproduct.conePointUniqueUpToIso_hom (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).hom = biproduct.lift b.π := rfl /-- Auxiliary lemma for `biproduct.uniqueUpToIso`. -/ theorem biproduct.conePointUniqueUpToIso_inv (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : (hb.isLimit.conePointUniqueUpToIso (biproduct.isLimit _)).inv = biproduct.desc b.ι := by classical refine biproduct.hom_ext' _ _ fun j => hb.isLimit.hom_ext fun j' => ?_ rw [Category.assoc, IsLimit.conePointUniqueUpToIso_inv_comp, Bicone.toCone_π_app, biproduct.bicone_π, biproduct.ι_desc, biproduct.ι_π, b.toCone_π_app, b.ι_π] /-- Biproducts are unique up to isomorphism. This already follows because bilimits are limits, but in the case of biproducts we can give an isomorphism with particularly nice definitional properties, namely that `biproduct.lift b.π` and `biproduct.desc b.ι` are inverses of each other. -/ @[simps] def biproduct.uniqueUpToIso (f : J → C) [HasBiproduct f] {b : Bicone f} (hb : b.IsBilimit) : b.pt ≅ ⨁ f where hom := biproduct.lift b.π inv := biproduct.desc b.ι hom_inv_id := by rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.hom_inv_id] inv_hom_id := by rw [← biproduct.conePointUniqueUpToIso_hom f hb, ← biproduct.conePointUniqueUpToIso_inv f hb, Iso.inv_hom_id] variable (C) -- see Note [lower instance priority] /-- A category with finite biproducts has a zero object. -/ instance (priority := 100) hasZeroObject_of_hasFiniteBiproducts [HasFiniteBiproducts C] : HasZeroObject C := by refine ⟨⟨biproduct Empty.elim, fun X => ⟨⟨⟨0⟩, ?_⟩⟩, fun X => ⟨⟨⟨0⟩, ?_⟩⟩⟩⟩ · intro a; apply biproduct.hom_ext'; simp · intro a; apply biproduct.hom_ext; simp section variable {C}
attribute [local simp] eq_iff_true_of_subsingleton in /-- The limit bicone for the biproduct over an index type with exactly one term. -/ @[simps]
Mathlib/CategoryTheory/Limits/Shapes/Biproducts.lean
1,041
1,044
/- 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, Johan Commelin, Mario Carneiro -/ import Mathlib.Data.Finsupp.Lex import Mathlib.Algebra.MvPolynomial.Degrees /-! # Variables of polynomials This file establishes many results about the variable sets of a multivariate polynomial. The *variable set* of a polynomial $P \in R[X]$ is a `Finset` containing each $x \in X$ that appears in a monomial in $P$. ## Main declarations * `MvPolynomial.vars p` : the finset of variables occurring in `p`. For example if `p = x⁴y+yz` then `vars p = {x, y, z}` ## Notation As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v w variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} section Vars /-! ### `vars` -/ /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : MvPolynomial σ R) : Finset σ := letI := Classical.decEq σ p.degrees.toFinset theorem vars_def [DecidableEq σ] (p : MvPolynomial σ R) : p.vars = p.degrees.toFinset := by rw [vars] convert rfl @[simp] theorem vars_0 : (0 : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_zero, Multiset.toFinset_zero] @[simp] theorem vars_monomial (h : r ≠ 0) : (monomial s r).vars = s.support := by classical rw [vars_def, degrees_monomial_eq _ _ h, Finsupp.toFinset_toMultiset] @[simp] theorem vars_C : (C r : MvPolynomial σ R).vars = ∅ := by classical rw [vars_def, degrees_C, Multiset.toFinset_zero] @[simp] theorem vars_X [Nontrivial R] : (X n : MvPolynomial σ R).vars = {n} := by rw [X, vars_monomial (one_ne_zero' R), Finsupp.support_single_ne_zero _ (one_ne_zero' ℕ)] theorem mem_vars (i : σ) : i ∈ p.vars ↔ ∃ d ∈ p.support, i ∈ d.support := by classical simp only [vars_def, Multiset.mem_toFinset, mem_degrees, mem_support_iff, exists_prop] theorem mem_support_not_mem_vars_zero {f : MvPolynomial σ R} {x : σ →₀ ℕ} (H : x ∈ f.support) {v : σ} (h : v ∉ vars f) : x v = 0 := by contrapose! h exact (mem_vars v).mpr ⟨x, H, Finsupp.mem_support_iff.mpr h⟩ theorem vars_add_subset [DecidableEq σ] (p q : MvPolynomial σ R) : (p + q).vars ⊆ p.vars ∪ q.vars := by intro x hx simp only [vars_def, Finset.mem_union, Multiset.mem_toFinset] at hx ⊢ simpa using Multiset.mem_of_le degrees_add_le hx theorem vars_add_of_disjoint [DecidableEq σ] (h : Disjoint p.vars q.vars) : (p + q).vars = p.vars ∪ q.vars := by refine (vars_add_subset p q).antisymm fun x hx => ?_ simp only [vars_def, Multiset.disjoint_toFinset] at h hx ⊢ rwa [degrees_add_of_disjoint h, Multiset.toFinset_union] section Mul theorem vars_mul [DecidableEq σ] (φ ψ : MvPolynomial σ R) : (φ * ψ).vars ⊆ φ.vars ∪ ψ.vars := by simp_rw [vars_def, ← Multiset.toFinset_add, Multiset.toFinset_subset] exact Multiset.subset_of_le degrees_mul_le @[simp] theorem vars_one : (1 : MvPolynomial σ R).vars = ∅ := vars_C theorem vars_pow (φ : MvPolynomial σ R) (n : ℕ) : (φ ^ n).vars ⊆ φ.vars := by classical induction n with | zero => simp | succ n ih => rw [pow_succ'] apply Finset.Subset.trans (vars_mul _ _) exact Finset.union_subset (Finset.Subset.refl _) ih /-- The variables of the product of a family of polynomials are a subset of the union of the sets of variables of each polynomial. -/ theorem vars_prod {ι : Type*} [DecidableEq σ] {s : Finset ι} (f : ι → MvPolynomial σ R) : (∏ i ∈ s, f i).vars ⊆ s.biUnion fun i => (f i).vars := by classical induction s using Finset.induction_on with | empty => simp | insert _ _ hs hsub => simp only [hs, Finset.biUnion_insert, Finset.prod_insert, not_false_iff] apply Finset.Subset.trans (vars_mul _ _) exact Finset.union_subset_union (Finset.Subset.refl _) hsub section IsDomain variable {A : Type*} [CommRing A] [NoZeroDivisors A] theorem vars_C_mul (a : A) (ha : a ≠ 0) (φ : MvPolynomial σ A) : (C a * φ : MvPolynomial σ A).vars = φ.vars := by ext1 i simp only [mem_vars, exists_prop, mem_support_iff] apply exists_congr intro d apply and_congr _ Iff.rfl rw [coeff_C_mul, mul_ne_zero_iff, eq_true ha, true_and] end IsDomain end Mul section Sum variable {ι : Type*} (t : Finset ι) (φ : ι → MvPolynomial σ R) theorem vars_sum_subset [DecidableEq σ] : (∑ i ∈ t, φ i).vars ⊆ Finset.biUnion t fun i => (φ i).vars := by classical induction t using Finset.induction_on with | empty => simp | insert _ _ has hsum => rw [Finset.biUnion_insert, Finset.sum_insert has] refine Finset.Subset.trans (vars_add_subset _ _) (Finset.union_subset_union (Finset.Subset.refl _) ?_) assumption theorem vars_sum_of_disjoint [DecidableEq σ] (h : Pairwise <| (Disjoint on fun i => (φ i).vars)) : (∑ i ∈ t, φ i).vars = Finset.biUnion t fun i => (φ i).vars := by classical induction t using Finset.induction_on with | empty => simp | insert _ _ has hsum => rw [Finset.biUnion_insert, Finset.sum_insert has, vars_add_of_disjoint, hsum] unfold Pairwise onFun at h rw [hsum] simp only [Finset.disjoint_iff_ne] at h ⊢ intro v hv v2 hv2 rw [Finset.mem_biUnion] at hv2 rcases hv2 with ⟨i, his, hi⟩ refine h ?_ _ hv _ hi rintro rfl contradiction end Sum section Map variable [CommSemiring S] (f : R →+* S) variable (p) theorem vars_map : (map f p).vars ⊆ p.vars := by classical simp [vars_def, Multiset.subset_of_le degrees_map_le] variable {f} theorem vars_map_of_injective (hf : Injective f) : (map f p).vars = p.vars := by simp [vars, degrees_map_of_injective _ hf] theorem vars_monomial_single (i : σ) {e : ℕ} {r : R} (he : e ≠ 0) (hr : r ≠ 0) : (monomial (Finsupp.single i e) r).vars = {i} := by rw [vars_monomial hr, Finsupp.support_single_ne_zero _ he] theorem vars_eq_support_biUnion_support [DecidableEq σ] : p.vars = p.support.biUnion Finsupp.support := by ext i rw [mem_vars, Finset.mem_biUnion] end Map end Vars section EvalVars /-! ### `vars` and `eval` -/ variable [CommSemiring S] theorem eval₂Hom_eq_constantCoeff_of_vars (f : R →+* S) {g : σ → S} {p : MvPolynomial σ R}
(hp : ∀ i ∈ p.vars, g i = 0) : eval₂Hom f g p = f (constantCoeff p) := by conv_lhs => rw [p.as_sum] simp only [map_sum, eval₂Hom_monomial]
Mathlib/Algebra/MvPolynomial/Variables.lean
226
228
/- Copyright (c) 2019 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Analysis.Analytic.Within import Mathlib.Analysis.Calculus.FDeriv.Analytic import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries /-! # Higher differentiability A function is `C^1` on a domain if it is differentiable there, and its derivative is continuous. By induction, it is `C^n` if it is `C^{n-1}` and its (n-1)-th derivative is `C^1` there or, equivalently, if it is `C^1` and its derivative is `C^{n-1}`. It is `C^∞` if it is `C^n` for all n. Finally, it is `C^ω` if it is analytic (as well as all its derivative, which is automatic if the space is complete). We formalize these notions with predicates `ContDiffWithinAt`, `ContDiffAt`, `ContDiffOn` and `ContDiff` saying that the function is `C^n` within a set at a point, at a point, on a set and on the whole space respectively. To avoid the issue of choice when choosing a derivative in sets where the derivative is not necessarily unique, `ContDiffOn` is not defined directly in terms of the regularity of the specific choice `iteratedFDerivWithin 𝕜 n f s` inside `s`, but in terms of the existence of a nice sequence of derivatives, expressed with a predicate `HasFTaylorSeriesUpToOn` defined in the file `FTaylorSeries`. We prove basic properties of these notions. ## Main definitions and results Let `f : E → F` be a map between normed vector spaces over a nontrivially normed field `𝕜`. * `ContDiff 𝕜 n f`: expresses that `f` is `C^n`, i.e., it admits a Taylor series up to rank `n`. * `ContDiffOn 𝕜 n f s`: expresses that `f` is `C^n` in `s`. * `ContDiffAt 𝕜 n f x`: expresses that `f` is `C^n` around `x`. * `ContDiffWithinAt 𝕜 n f s x`: expresses that `f` is `C^n` around `x` within the set `s`. In sets of unique differentiability, `ContDiffOn 𝕜 n f s` can be expressed in terms of the properties of `iteratedFDerivWithin 𝕜 m f s` for `m ≤ n`. In the whole space, `ContDiff 𝕜 n f` can be expressed in terms of the properties of `iteratedFDeriv 𝕜 m f` for `m ≤ n`. ## Implementation notes The definitions in this file are designed to work on any field `𝕜`. They are sometimes slightly more complicated than the naive definitions one would guess from the intuition over the real or complex numbers, but they are designed to circumvent the lack of gluing properties and partitions of unity in general. In the usual situations, they coincide with the usual definitions. ### Definition of `C^n` functions in domains One could define `C^n` functions in a domain `s` by fixing an arbitrary choice of derivatives (this is what we do with `iteratedFDerivWithin`) and requiring that all these derivatives up to `n` are continuous. If the derivative is not unique, this could lead to strange behavior like two `C^n` functions `f` and `g` on `s` whose sum is not `C^n`. A better definition is thus to say that a function is `C^n` inside `s` if it admits a sequence of derivatives up to `n` inside `s`. This definition still has the problem that a function which is locally `C^n` would not need to be `C^n`, as different choices of sequences of derivatives around different points might possibly not be glued together to give a globally defined sequence of derivatives. (Note that this issue can not happen over reals, thanks to partition of unity, but the behavior over a general field is not so clear, and we want a definition for general fields). Also, there are locality problems for the order parameter: one could image a function which, for each `n`, has a nice sequence of derivatives up to order `n`, but they do not coincide for varying `n` and can therefore not be glued to give rise to an infinite sequence of derivatives. This would give a function which is `C^n` for all `n`, but not `C^∞`. We solve this issue by putting locality conditions in space and order in our definition of `ContDiffWithinAt` and `ContDiffOn`. The resulting definition is slightly more complicated to work with (in fact not so much), but it gives rise to completely satisfactory theorems. For instance, with this definition, a real function which is `C^m` (but not better) on `(-1/m, 1/m)` for each natural `m` is by definition `C^∞` at `0`. There is another issue with the definition of `ContDiffWithinAt 𝕜 n f s x`. We can require the existence and good behavior of derivatives up to order `n` on a neighborhood of `x` within `s`. However, this does not imply continuity or differentiability within `s` of the function at `x` when `x` does not belong to `s`. Therefore, we require such existence and good behavior on a neighborhood of `x` within `s ∪ {x}` (which appears as `insert x s` in this file). ## Notations We use the notation `E [×n]→L[𝕜] F` for the space of continuous multilinear maps on `E^n` with values in `F`. This is the space in which the `n`-th derivative of a function from `E` to `F` lives. In this file, we denote `(⊤ : ℕ∞) : WithTop ℕ∞` with `∞`, and `⊤ : WithTop ℕ∞` with `ω`. To avoid ambiguities with the two tops, the theorems name use either `infty` or `omega`. These notations are scoped in `ContDiff`. ## Tags derivative, differentiability, higher derivative, `C^n`, multilinear, Taylor series, formal series -/ noncomputable section open Set Fin Filter Function open scoped NNReal Topology ContDiff universe u uE uF uG uX variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] {E : Type uE} [NormedAddCommGroup E] [NormedSpace 𝕜 E] {F : Type uF} [NormedAddCommGroup F] [NormedSpace 𝕜 F] {G : Type uG} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {X : Type uX} [NormedAddCommGroup X] [NormedSpace 𝕜 X] {s s₁ t u : Set E} {f f₁ : E → F} {g : F → G} {x x₀ : E} {c : F} {m n : WithTop ℕ∞} {p : E → FormalMultilinearSeries 𝕜 E F} /-! ### Smooth functions within a set around a point -/ variable (𝕜) in /-- A function is continuously differentiable up to order `n` within a set `s` at a point `x` if it admits continuous derivatives up to order `n` in a neighborhood of `x` in `s ∪ {x}`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). For `n = ω`, we require the function to be analytic within `s` at `x`. The precise definition we give (all the derivatives should be analytic) is more involved to work around issues when the space is not complete, but it is equivalent when the space is complete. For instance, a real function which is `C^m` on `(-1/m, 1/m)` for each natural `m`, but not better, is `C^∞` at `0` within `univ`. -/ def ContDiffWithinAt (n : WithTop ℕ∞) (f : E → F) (s : Set E) (x : E) : Prop := match n with | ω => ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn ω f p u ∧ ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u | (n : ℕ∞) => ∀ m : ℕ, m ≤ n → ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn m f p u lemma HasFTaylorSeriesUpToOn.analyticOn (hf : HasFTaylorSeriesUpToOn ω f p s) (h : AnalyticOn 𝕜 (fun x ↦ p x 0) s) : AnalyticOn 𝕜 f s := by have : AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryFin0 𝕜 E F) (p x 0)) s := (LinearIsometryEquiv.analyticOnNhd _ _ ).comp_analyticOn h (Set.mapsTo_univ _ _) exact this.congr (fun y hy ↦ (hf.zero_eq _ hy).symm) lemma ContDiffWithinAt.analyticOn (h : ContDiffWithinAt 𝕜 ω f s x) : ∃ u ∈ 𝓝[insert x s] x, AnalyticOn 𝕜 f u := by obtain ⟨u, hu, p, hp, h'p⟩ := h exact ⟨u, hu, hp.analyticOn (h'p 0)⟩ lemma ContDiffWithinAt.analyticWithinAt (h : ContDiffWithinAt 𝕜 ω f s x) : AnalyticWithinAt 𝕜 f s x := by obtain ⟨u, hu, hf⟩ := h.analyticOn have xu : x ∈ u := mem_of_mem_nhdsWithin (by simp) hu exact (hf x xu).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) theorem contDiffWithinAt_omega_iff_analyticWithinAt [CompleteSpace F] : ContDiffWithinAt 𝕜 ω f s x ↔ AnalyticWithinAt 𝕜 f s x := by refine ⟨fun h ↦ h.analyticWithinAt, fun h ↦ ?_⟩ obtain ⟨u, hu, p, hp, h'p⟩ := h.exists_hasFTaylorSeriesUpToOn ω exact ⟨u, hu, p, hp.of_le le_top, fun i ↦ h'p i⟩ theorem contDiffWithinAt_nat {n : ℕ} : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u := ⟨fun H => H n le_rfl, fun ⟨u, hu, p, hp⟩ _m hm => ⟨u, hu, p, hp.of_le (mod_cast hm)⟩⟩ /-- When `n` is either a natural number or `ω`, one can characterize the property of being `C^n` as the existence of a neighborhood on which there is a Taylor series up to order `n`, requiring in addition that its terms are analytic in the `ω` case. -/ lemma contDiffWithinAt_iff_of_ne_infty (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ∃ p : E → FormalMultilinearSeries 𝕜 E F, HasFTaylorSeriesUpToOn n f p u ∧ (n = ω → ∀ i, AnalyticOn 𝕜 (fun x ↦ p x i) u) := by match n with | ω => simp [ContDiffWithinAt] | ∞ => simp at hn | (n : ℕ) => simp [contDiffWithinAt_nat] theorem ContDiffWithinAt.of_le (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m ≤ n) : ContDiffWithinAt 𝕜 m f s x := by match n with | ω => match m with | ω => exact h | (m : ℕ∞) => intro k _ obtain ⟨u, hu, p, hp, -⟩ := h exact ⟨u, hu, p, hp.of_le le_top⟩ | (n : ℕ∞) => match m with | ω => simp at hmn | (m : ℕ∞) => exact fun k hk ↦ h k (le_trans hk (mod_cast hmn)) /-- In a complete space, a function which is analytic within a set at a point is also `C^ω` there. Note that the same statement for `AnalyticOn` does not require completeness, see `AnalyticOn.contDiffOn`. -/ theorem AnalyticWithinAt.contDiffWithinAt [CompleteSpace F] (h : AnalyticWithinAt 𝕜 f s x) : ContDiffWithinAt 𝕜 n f s x := (contDiffWithinAt_omega_iff_analyticWithinAt.2 h).of_le le_top theorem contDiffWithinAt_iff_forall_nat_le {n : ℕ∞} : ContDiffWithinAt 𝕜 n f s x ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffWithinAt 𝕜 m f s x := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H m hm => H m hm _ le_rfl⟩ theorem contDiffWithinAt_infty : ContDiffWithinAt 𝕜 ∞ f s x ↔ ∀ n : ℕ, ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_iff_forall_nat_le.trans <| by simp only [forall_prop_of_true, le_top] @[deprecated (since := "2024-11-25")] alias contDiffWithinAt_top := contDiffWithinAt_infty theorem ContDiffWithinAt.continuousWithinAt (h : ContDiffWithinAt 𝕜 n f s x) : ContinuousWithinAt f s x := by have := h.of_le (zero_le _) simp only [ContDiffWithinAt, nonpos_iff_eq_zero, Nat.cast_eq_zero, mem_pure, forall_eq, CharP.cast_eq_zero] at this rcases this with ⟨u, hu, p, H⟩ rw [mem_nhdsWithin_insert] at hu exact (H.continuousOn.continuousWithinAt hu.1).mono_of_mem_nhdsWithin hu.2 theorem ContDiffWithinAt.congr_of_eventuallyEq (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨{x ∈ u | f₁ x = f x}, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right, fun i ↦ (H' i).mono (sep_subset _ _)⟩ | (n : ℕ∞) => intro m hm let ⟨u, hu, p, H⟩ := h m hm exact ⟨{ x ∈ u | f₁ x = f x }, Filter.inter_mem hu (mem_nhdsWithin_insert.2 ⟨hx, h₁⟩), p, (H.mono (sep_subset _ _)).congr fun _ ↦ And.right⟩ theorem Filter.EventuallyEq.congr_contDiffWithinAt (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq h₁.symm hx.symm, fun H ↦ H.congr_of_eventuallyEq h₁ hx⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (nhdsWithin_mono x (subset_insert x s) h₁) (mem_of_mem_nhdsWithin (mem_insert x s) h₁ :) theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_insert (h₁ : f₁ =ᶠ[𝓝[insert x s] x] f) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_insert h₁.symm, fun H ↦ H.congr_of_eventuallyEq_insert h₁⟩ theorem ContDiffWithinAt.congr_of_eventuallyEq_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq h₁ <| h₁.self_of_nhdsWithin hx theorem Filter.EventuallyEq.congr_contDiffWithinAt_of_mem (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : x ∈ s): ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun H ↦ H.congr_of_eventuallyEq_of_mem h₁.symm hx, fun H ↦ H.congr_of_eventuallyEq_of_mem h₁ hx⟩ theorem ContDiffWithinAt.congr (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr_of_eventuallyEq (Filter.eventuallyEq_of_mem self_mem_nhdsWithin h₁) hx theorem contDiffWithinAt_congr (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := ⟨fun h' ↦ h'.congr (fun x hx ↦ (h₁ x hx).symm) hx.symm, fun h' ↦ h'.congr h₁ hx⟩ theorem ContDiffWithinAt.congr_of_mem (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr h₁ (h₁ _ hx) theorem contDiffWithinAt_congr_of_mem (h₁ : ∀ y ∈ s, f₁ y = f y) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr h₁ (h₁ x hx) theorem ContDiffWithinAt.congr_of_insert (h : ContDiffWithinAt 𝕜 n f s x) (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x := h.congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem contDiffWithinAt_congr_of_insert (h₁ : ∀ y ∈ insert x s, f₁ y = f y) : ContDiffWithinAt 𝕜 n f₁ s x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr (fun y hy ↦ h₁ y (mem_insert_of_mem _ hy)) (h₁ x (mem_insert _ _)) theorem ContDiffWithinAt.mono_of_mem_nhdsWithin (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s ∈ 𝓝[t] x) : ContDiffWithinAt 𝕜 n f t x := by match n with | ω => obtain ⟨u, hu, p, H, H'⟩ := h exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H, H'⟩ | (n : ℕ∞) => intro m hm rcases h m hm with ⟨u, hu, p, H⟩ exact ⟨u, nhdsWithin_le_of_mem (insert_mem_nhdsWithin_insert hst) hu, p, H⟩ @[deprecated (since := "2024-10-30")] alias ContDiffWithinAt.mono_of_mem := ContDiffWithinAt.mono_of_mem_nhdsWithin theorem ContDiffWithinAt.mono (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : t ⊆ s) : ContDiffWithinAt 𝕜 n f t x := h.mono_of_mem_nhdsWithin <| Filter.mem_of_superset self_mem_nhdsWithin hst theorem ContDiffWithinAt.congr_mono (h : ContDiffWithinAt 𝕜 n f s x) (h' : EqOn f₁ f s₁) (h₁ : s₁ ⊆ s) (hx : f₁ x = f x) : ContDiffWithinAt 𝕜 n f₁ s₁ x := (h.mono h₁).congr h' hx theorem ContDiffWithinAt.congr_set (h : ContDiffWithinAt 𝕜 n f s x) {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f t x := by rw [← nhdsWithin_eq_iff_eventuallyEq] at hst apply h.mono_of_mem_nhdsWithin <| hst ▸ self_mem_nhdsWithin @[deprecated (since := "2024-10-23")] alias ContDiffWithinAt.congr_nhds := ContDiffWithinAt.congr_set theorem contDiffWithinAt_congr_set {t : Set E} (hst : s =ᶠ[𝓝 x] t) : ContDiffWithinAt 𝕜 n f s x ↔ ContDiffWithinAt 𝕜 n f t x := ⟨fun h => h.congr_set hst, fun h => h.congr_set hst.symm⟩ @[deprecated (since := "2024-10-23")] alias contDiffWithinAt_congr_nhds := contDiffWithinAt_congr_set theorem contDiffWithinAt_inter' (h : t ∈ 𝓝[s] x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_congr_set (mem_nhdsWithin_iff_eventuallyEq.1 h).symm theorem contDiffWithinAt_inter (h : t ∈ 𝓝 x) : ContDiffWithinAt 𝕜 n f (s ∩ t) x ↔ ContDiffWithinAt 𝕜 n f s x := contDiffWithinAt_inter' (mem_nhdsWithin_of_mem_nhds h) theorem contDiffWithinAt_insert_self : ContDiffWithinAt 𝕜 n f (insert x s) x ↔ ContDiffWithinAt 𝕜 n f s x := by match n with | ω => simp [ContDiffWithinAt] | (n : ℕ∞) => simp_rw [ContDiffWithinAt, insert_idem] theorem contDiffWithinAt_insert {y : E} : ContDiffWithinAt 𝕜 n f (insert y s) x ↔ ContDiffWithinAt 𝕜 n f s x := by rcases eq_or_ne x y with (rfl | hx) · exact contDiffWithinAt_insert_self refine ⟨fun h ↦ h.mono (subset_insert _ _), fun h ↦ ?_⟩ apply h.mono_of_mem_nhdsWithin simp [nhdsWithin_insert_of_ne hx, self_mem_nhdsWithin] alias ⟨ContDiffWithinAt.of_insert, ContDiffWithinAt.insert'⟩ := contDiffWithinAt_insert protected theorem ContDiffWithinAt.insert (h : ContDiffWithinAt 𝕜 n f s x) : ContDiffWithinAt 𝕜 n f (insert x s) x := h.insert' theorem contDiffWithinAt_diff_singleton {y : E} : ContDiffWithinAt 𝕜 n f (s \ {y}) x ↔ ContDiffWithinAt 𝕜 n f s x := by rw [← contDiffWithinAt_insert, insert_diff_singleton, contDiffWithinAt_insert] /-- If a function is `C^n` within a set at a point, with `n ≥ 1`, then it is differentiable within this set at this point. -/ theorem ContDiffWithinAt.differentiableWithinAt' (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f (insert x s) x := by rcases contDiffWithinAt_nat.1 (h.of_le hn) with ⟨u, hu, p, H⟩ rcases mem_nhdsWithin.1 hu with ⟨t, t_open, xt, tu⟩ rw [inter_comm] at tu exact (differentiableWithinAt_inter (IsOpen.mem_nhds t_open xt)).1 <| ((H.mono tu).differentiableOn le_rfl) x ⟨mem_insert x s, xt⟩ theorem ContDiffWithinAt.differentiableWithinAt (h : ContDiffWithinAt 𝕜 n f s x) (hn : 1 ≤ n) : DifferentiableWithinAt 𝕜 f s x := (h.differentiableWithinAt' hn).mono (subset_insert x s) /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n` (and moreover the function is analytic when `n = ω`). -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffWithinAt 𝕜 n f' u x := by have h'n : n + 1 ≠ ∞ := by simpa using hn constructor · intro h rcases (contDiffWithinAt_iff_of_ne_infty h'n).1 h with ⟨u, hu, p, Hp, H'p⟩ refine ⟨u, hu, ?_, fun y => (continuousMultilinearCurryFin1 𝕜 E F) (p y 1), fun y hy => Hp.hasFDerivWithinAt le_add_self hy, ?_⟩ · rintro rfl exact Hp.analyticOn (H'p rfl 0) apply (contDiffWithinAt_iff_of_ne_infty hn).2 refine ⟨u, ?_, fun y : E => (p y).shift, ?_⟩ · convert @self_mem_nhdsWithin _ _ x u have : x ∈ insert x s := by simp exact insert_eq_of_mem (mem_of_mem_nhdsWithin this hu) · rw [hasFTaylorSeriesUpToOn_succ_iff_right] at Hp refine ⟨Hp.2.2, ?_⟩ rintro rfl i change AnalyticOn 𝕜 (fun x ↦ (continuousMultilinearCurryRightEquiv' 𝕜 i E F) (p x (i + 1))) u apply (LinearIsometryEquiv.analyticOnNhd _ _).comp_analyticOn ?_ (Set.mapsTo_univ _ _) exact H'p rfl _ · rintro ⟨u, hu, hf, f', f'_eq_deriv, Hf'⟩ rw [contDiffWithinAt_iff_of_ne_infty h'n] rcases (contDiffWithinAt_iff_of_ne_infty hn).1 Hf' with ⟨v, hv, p', Hp', p'_an⟩ refine ⟨v ∩ u, ?_, fun x => (p' x).unshift (f x), ?_, ?_⟩ · apply Filter.inter_mem _ hu apply nhdsWithin_le_of_mem hu exact nhdsWithin_mono _ (subset_insert x u) hv · rw [hasFTaylorSeriesUpToOn_succ_iff_right] refine ⟨fun y _ => rfl, fun y hy => ?_, ?_⟩ · change HasFDerivWithinAt (fun z => (continuousMultilinearCurryFin0 𝕜 E F).symm (f z)) (FormalMultilinearSeries.unshift (p' y) (f y) 1).curryLeft (v ∩ u) y rw [← Function.comp_def _ f, LinearIsometryEquiv.comp_hasFDerivWithinAt_iff'] convert (f'_eq_deriv y hy.2).mono inter_subset_right rw [← Hp'.zero_eq y hy.1] ext z change ((p' y 0) (init (@cons 0 (fun _ => E) z 0))) (@cons 0 (fun _ => E) z 0 (last 0)) = ((p' y 0) 0) z congr norm_num [eq_iff_true_of_subsingleton] · convert (Hp'.mono inter_subset_left).congr fun x hx => Hp'.zero_eq x hx.1 using 1 · ext x y change p' x 0 (init (@snoc 0 (fun _ : Fin 1 => E) 0 y)) y = p' x 0 0 y rw [init_snoc] · ext x k v y change p' x k (init (@snoc k (fun _ : Fin k.succ => E) v y)) (@snoc k (fun _ : Fin k.succ => E) v y (last k)) = p' x k v y rw [snoc_last, init_snoc] · intro h i simp only [WithTop.add_eq_top, WithTop.one_ne_top, or_false] at h match i with | 0 => simp only [FormalMultilinearSeries.unshift] apply AnalyticOnNhd.comp_analyticOn _ ((hf h).mono inter_subset_right) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ | i + 1 => simp only [FormalMultilinearSeries.unshift, Nat.succ_eq_add_one] apply AnalyticOnNhd.comp_analyticOn _ ((p'_an h i).mono inter_subset_left) (Set.mapsTo_univ _ _) exact LinearIsometryEquiv.analyticOnNhd _ _ /-- A version of `contDiffWithinAt_succ_iff_hasFDerivWithinAt` where all derivatives are taken within the same set. -/ theorem contDiffWithinAt_succ_iff_hasFDerivWithinAt' (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 (n + 1) f s x ↔ ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) s x) ∧ ContDiffWithinAt 𝕜 n f' s x := by refine ⟨fun hf => ?_, ?_⟩ · obtain ⟨u, hu, f_an, f', huf', hf'⟩ := (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).mp hf obtain ⟨w, hw, hxw, hwu⟩ := mem_nhdsWithin.mp hu rw [inter_comm] at hwu refine ⟨insert x s ∩ w, inter_mem_nhdsWithin _ (hw.mem_nhds hxw), inter_subset_left, ?_, f', fun y hy => ?_, ?_⟩ · intro h apply (f_an h).mono hwu · refine ((huf' y <| hwu hy).mono hwu).mono_of_mem_nhdsWithin ?_ refine mem_of_superset ?_ (inter_subset_inter_left _ (subset_insert _ _)) exact inter_mem_nhdsWithin _ (hw.mem_nhds hy.2) · exact hf'.mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert _ _) hu) · rw [← contDiffWithinAt_insert, contDiffWithinAt_succ_iff_hasFDerivWithinAt hn, insert_eq_of_mem (mem_insert _ _)] rintro ⟨u, hu, hus, f_an, f', huf', hf'⟩ exact ⟨u, hu, f_an, f', fun y hy => (huf' y hy).insert'.mono hus, hf'.insert.mono hus⟩ /-! ### Smooth functions within a set -/ variable (𝕜) in /-- A function is continuously differentiable up to `n` on `s` if, for any point `x` in `s`, it admits continuous derivatives up to order `n` on a neighborhood of `x` in `s`. For `n = ∞`, we only require that this holds up to any finite order (where the neighborhood may depend on the finite order we consider). -/ def ContDiffOn (n : WithTop ℕ∞) (f : E → F) (s : Set E) : Prop := ∀ x ∈ s, ContDiffWithinAt 𝕜 n f s x theorem HasFTaylorSeriesUpToOn.contDiffOn {n : ℕ∞} {f' : E → FormalMultilinearSeries 𝕜 E F} (hf : HasFTaylorSeriesUpToOn n f f' s) : ContDiffOn 𝕜 n f s := by intro x hx m hm use s simp only [Set.insert_eq_of_mem hx, self_mem_nhdsWithin, true_and] exact ⟨f', hf.of_le (mod_cast hm)⟩ theorem ContDiffOn.contDiffWithinAt (h : ContDiffOn 𝕜 n f s) (hx : x ∈ s) : ContDiffWithinAt 𝕜 n f s x := h x hx theorem ContDiffOn.of_le (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) : ContDiffOn 𝕜 m f s := fun x hx => (h x hx).of_le hmn theorem ContDiffWithinAt.contDiffOn' (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 m f (insert x s ∩ u) := by rcases eq_or_ne n ω with rfl | hn · obtain ⟨t, ht, p, hp, h'p⟩ := h rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut refine ⟨u, huo, hxu, ?_⟩ suffices ContDiffOn 𝕜 ω f (insert x s ∩ u) from this.of_le le_top intro y hy refine ⟨insert x s ∩ u, ?_, p, hp.mono hut, fun i ↦ (h'p i).mono hut⟩ simp only [insert_eq_of_mem, hy, self_mem_nhdsWithin] · match m with | ω => simp [hn] at hm | ∞ => exact (hn (h' rfl)).elim | (m : ℕ) => rcases contDiffWithinAt_nat.1 (h.of_le hm) with ⟨t, ht, p, hp⟩ rcases mem_nhdsWithin.1 ht with ⟨u, huo, hxu, hut⟩ rw [inter_comm] at hut exact ⟨u, huo, hxu, (hp.mono hut).contDiffOn⟩ theorem ContDiffWithinAt.contDiffOn (hm : m ≤ n) (h' : m = ∞ → n = ω) (h : ContDiffWithinAt 𝕜 n f s x) : ∃ u ∈ 𝓝[insert x s] x, u ⊆ insert x s ∧ ContDiffOn 𝕜 m f u := by obtain ⟨_u, uo, xu, h⟩ := h.contDiffOn' hm h' exact ⟨_, inter_mem_nhdsWithin _ (uo.mem_nhds xu), inter_subset_left, h⟩ theorem ContDiffOn.analyticOn (h : ContDiffOn 𝕜 ω f s) : AnalyticOn 𝕜 f s := fun x hx ↦ (h x hx).analyticWithinAt /-- A function is `C^n` within a set at a point, for `n : ℕ`, if and only if it is `C^n` on a neighborhood of this point. -/ theorem contDiffWithinAt_iff_contDiffOn_nhds (hn : n ≠ ∞) : ContDiffWithinAt 𝕜 n f s x ↔ ∃ u ∈ 𝓝[insert x s] x, ContDiffOn 𝕜 n f u := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, h'u⟩ exact ⟨u, hu, h'u.2⟩ · rcases h with ⟨u, u_mem, hu⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert x s) u_mem exact (hu x this).mono_of_mem_nhdsWithin (nhdsWithin_mono _ (subset_insert x s) u_mem) protected theorem ContDiffWithinAt.eventually (h : ContDiffWithinAt 𝕜 n f s x) (hn : n ≠ ∞) : ∀ᶠ y in 𝓝[insert x s] x, ContDiffWithinAt 𝕜 n f s y := by rcases h.contDiffOn le_rfl (by simp [hn]) with ⟨u, hu, _, hd⟩ have : ∀ᶠ y : E in 𝓝[insert x s] x, u ∈ 𝓝[insert x s] y ∧ y ∈ u := (eventually_eventually_nhdsWithin.2 hu).and hu refine this.mono fun y hy => (hd y hy.2).mono_of_mem_nhdsWithin ?_ exact nhdsWithin_mono y (subset_insert _ _) hy.1 theorem ContDiffOn.of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 n f s := h.of_le le_self_add theorem ContDiffOn.one_of_succ (h : ContDiffOn 𝕜 (n + 1) f s) : ContDiffOn 𝕜 1 f s := h.of_le le_add_self theorem contDiffOn_iff_forall_nat_le {n : ℕ∞} : ContDiffOn 𝕜 n f s ↔ ∀ m : ℕ, ↑m ≤ n → ContDiffOn 𝕜 m f s := ⟨fun H _ hm => H.of_le (mod_cast hm), fun H x hx m hm => H m hm x hx m le_rfl⟩ theorem contDiffOn_infty : ContDiffOn 𝕜 ∞ f s ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := contDiffOn_iff_forall_nat_le.trans <| by simp only [le_top, forall_prop_of_true] @[deprecated (since := "2024-11-27")] alias contDiffOn_top := contDiffOn_infty @[deprecated (since := "2024-11-27")] alias contDiffOn_infty_iff_contDiffOn_omega := contDiffOn_infty theorem contDiffOn_all_iff_nat : (∀ (n : ℕ∞), ContDiffOn 𝕜 n f s) ↔ ∀ n : ℕ, ContDiffOn 𝕜 n f s := by refine ⟨fun H n => H n, ?_⟩ rintro H (_ | n) exacts [contDiffOn_infty.2 H, H n] theorem ContDiffOn.continuousOn (h : ContDiffOn 𝕜 n f s) : ContinuousOn f s := fun x hx => (h x hx).continuousWithinAt theorem ContDiffOn.congr (h : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s := fun x hx => (h x hx).congr h₁ (h₁ x hx) theorem contDiffOn_congr (h₁ : ∀ x ∈ s, f₁ x = f x) : ContDiffOn 𝕜 n f₁ s ↔ ContDiffOn 𝕜 n f s := ⟨fun H => H.congr fun x hx => (h₁ x hx).symm, fun H => H.congr h₁⟩ theorem ContDiffOn.mono (h : ContDiffOn 𝕜 n f s) {t : Set E} (hst : t ⊆ s) : ContDiffOn 𝕜 n f t := fun x hx => (h x (hst hx)).mono hst theorem ContDiffOn.congr_mono (hf : ContDiffOn 𝕜 n f s) (h₁ : ∀ x ∈ s₁, f₁ x = f x) (hs : s₁ ⊆ s) : ContDiffOn 𝕜 n f₁ s₁ := (hf.mono hs).congr h₁ /-- If a function is `C^n` on a set with `n ≥ 1`, then it is differentiable there. -/ theorem ContDiffOn.differentiableOn (h : ContDiffOn 𝕜 n f s) (hn : 1 ≤ n) : DifferentiableOn 𝕜 f s := fun x hx => (h x hx).differentiableWithinAt hn /-- If a function is `C^n` around each point in a set, then it is `C^n` on the set. -/ theorem contDiffOn_of_locally_contDiffOn (h : ∀ x ∈ s, ∃ u, IsOpen u ∧ x ∈ u ∧ ContDiffOn 𝕜 n f (s ∩ u)) : ContDiffOn 𝕜 n f s := by intro x xs rcases h x xs with ⟨u, u_open, xu, hu⟩ apply (contDiffWithinAt_inter _).1 (hu x ⟨xs, xu⟩) exact IsOpen.mem_nhds u_open xu /-- A function is `C^(n + 1)` on a domain iff locally, it has a derivative which is `C^n`. -/ theorem contDiffOn_succ_iff_hasFDerivWithinAt (hn : n ≠ ∞) : ContDiffOn 𝕜 (n + 1) f s ↔ ∀ x ∈ s, ∃ u ∈ 𝓝[insert x s] x, (n = ω → AnalyticOn 𝕜 f u) ∧ ∃ f' : E → E →L[𝕜] F, (∀ x ∈ u, HasFDerivWithinAt f (f' x) u x) ∧ ContDiffOn 𝕜 n f' u := by constructor · intro h x hx rcases (contDiffWithinAt_succ_iff_hasFDerivWithinAt hn).1 (h x hx) with ⟨u, hu, f_an, f', hf', Hf'⟩ rcases Hf'.contDiffOn le_rfl (by simp [hn]) with ⟨v, vu, v'u, hv⟩ rw [insert_eq_of_mem hx] at hu ⊢ have xu : x ∈ u := mem_of_mem_nhdsWithin hx hu rw [insert_eq_of_mem xu] at vu v'u exact ⟨v, nhdsWithin_le_of_mem hu vu, fun h ↦ (f_an h).mono v'u, f', fun y hy ↦ (hf' y (v'u hy)).mono v'u, hv⟩ · intro h x hx rw [contDiffWithinAt_succ_iff_hasFDerivWithinAt hn] rcases h x hx with ⟨u, u_nhbd, f_an, f', hu, hf'⟩ have : x ∈ u := mem_of_mem_nhdsWithin (mem_insert _ _) u_nhbd exact ⟨u, u_nhbd, f_an, f', hu, hf' x this⟩ /-! ### Iterated derivative within a set -/ @[simp] theorem contDiffOn_zero : ContDiffOn 𝕜 0 f s ↔ ContinuousOn f s := by refine ⟨fun H => H.continuousOn, fun H => fun x hx m hm ↦ ?_⟩ have : (m : WithTop ℕ∞) = 0 := le_antisymm (mod_cast hm) bot_le rw [this] refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ rw [hasFTaylorSeriesUpToOn_zero_iff] exact ⟨by rwa [insert_eq_of_mem hx], fun x _ => by simp [ftaylorSeriesWithin]⟩ theorem contDiffWithinAt_zero (hx : x ∈ s) : ContDiffWithinAt 𝕜 0 f s x ↔ ∃ u ∈ 𝓝[s] x, ContinuousOn f (s ∩ u) := by constructor · intro h obtain ⟨u, H, p, hp⟩ := h 0 le_rfl refine ⟨u, ?_, ?_⟩ · simpa [hx] using H · simp only [Nat.cast_zero, hasFTaylorSeriesUpToOn_zero_iff] at hp exact hp.1.mono inter_subset_right · rintro ⟨u, H, hu⟩ rw [← contDiffWithinAt_inter' H] have h' : x ∈ s ∩ u := ⟨hx, mem_of_mem_nhdsWithin hx H⟩ exact (contDiffOn_zero.mpr hu).contDiffWithinAt h' /-- When a function is `C^n` in a set `s` of unique differentiability, it admits `ftaylorSeriesWithin 𝕜 f s` as a Taylor series up to order `n` in `s`. -/ protected theorem ContDiffOn.ftaylorSeriesWithin (h : ContDiffOn 𝕜 n f s) (hs : UniqueDiffOn 𝕜 s) : HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin 𝕜 f s) s := by constructor · intro x _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro m hm x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hm rcases (h x hx).of_le this _ le_rfl with ⟨u, hu, p, Hp⟩ rw [insert_eq_of_mem hx] at hu rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [inter_comm] at ho have : p x m.succ = ftaylorSeriesWithin 𝕜 f s x m.succ := by change p x m.succ = iteratedFDerivWithin 𝕜 m.succ f s x rw [← iteratedFDerivWithin_inter_open o_open xo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hx, xo⟩ rw [← this, ← hasFDerivWithinAt_inter (IsOpen.mem_nhds o_open xo)] have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn (mod_cast Nat.le_succ m) (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).fderivWithin m (mod_cast lt_add_one m) x ⟨hx, xo⟩).congr (fun y hy => (A y hy).symm) (A x ⟨hx, xo⟩).symm · intro m hm apply continuousOn_of_locally_continuousOn intro x hx rcases (h x hx).of_le hm _ le_rfl with ⟨u, hu, p, Hp⟩ rcases mem_nhdsWithin.1 hu with ⟨o, o_open, xo, ho⟩ rw [insert_eq_of_mem hx] at ho rw [inter_comm] at ho refine ⟨o, o_open, xo, ?_⟩ have A : ∀ y ∈ s ∩ o, p y m = ftaylorSeriesWithin 𝕜 f s y m := by rintro y ⟨hy, yo⟩ change p y m = iteratedFDerivWithin 𝕜 m f s y rw [← iteratedFDerivWithin_inter_open o_open yo] exact (Hp.mono ho).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl (hs.inter o_open) ⟨hy, yo⟩ exact ((Hp.mono ho).cont m le_rfl).congr fun y hy => (A y hy).symm theorem iteratedFDerivWithin_subset {n : ℕ} (st : s ⊆ t) (hs : UniqueDiffOn 𝕜 s) (ht : UniqueDiffOn 𝕜 t) (h : ContDiffOn 𝕜 n f t) (hx : x ∈ s) : iteratedFDerivWithin 𝕜 n f s x = iteratedFDerivWithin 𝕜 n f t x := (((h.ftaylorSeriesWithin ht).mono st).eq_iteratedFDerivWithin_of_uniqueDiffOn le_rfl hs hx).symm theorem ContDiffWithinAt.eventually_hasFTaylorSeriesUpToOn {f : E → F} {s : Set E} {a : E} (h : ContDiffWithinAt 𝕜 n f s a) (hs : UniqueDiffOn 𝕜 s) (ha : a ∈ s) {m : ℕ} (hm : m ≤ n) : ∀ᶠ t in (𝓝[s] a).smallSets, HasFTaylorSeriesUpToOn m f (ftaylorSeriesWithin 𝕜 f s) t := by rcases h.contDiffOn' hm (by simp) with ⟨U, hUo, haU, hfU⟩ have : ∀ᶠ t in (𝓝[s] a).smallSets, t ⊆ s ∩ U := by rw [eventually_smallSets_subset] exact inter_mem_nhdsWithin _ <| hUo.mem_nhds haU refine this.mono fun t ht ↦ .mono ?_ ht rw [insert_eq_of_mem ha] at hfU refine (hfU.ftaylorSeriesWithin (hs.inter hUo)).congr_series fun k hk x hx ↦ ?_ exact iteratedFDerivWithin_inter_open hUo hx.2 /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOn.contDiffOn_of_completeSpace`. -/ theorem AnalyticOn.contDiffOn (h : AnalyticOn 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top rcases h.exists_hasFTaylorSeriesUpToOn hs with ⟨p, hp⟩ intro x hx refine ⟨s, ?_, p, hp⟩ rw [insert_eq_of_mem hx] exact self_mem_nhdsWithin /-- On a set with unique differentiability, an analytic function is automatically `C^ω`, as its successive derivatives are also analytic. This does not require completeness of the space. See also `AnalyticOnNhd.contDiffOn_of_completeSpace`. -/ theorem AnalyticOnNhd.contDiffOn (h : AnalyticOnNhd 𝕜 f s) (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn hs /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOn.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOn 𝕜 f s) : ContDiffOn 𝕜 n f s := fun x hx ↦ (h x hx).contDiffWithinAt /-- An analytic function is automatically `C^ω` in a complete space -/ theorem AnalyticOnNhd.contDiffOn_of_completeSpace [CompleteSpace F] (h : AnalyticOnNhd 𝕜 f s) : ContDiffOn 𝕜 n f s := h.analyticOn.contDiffOn_of_completeSpace theorem contDiffOn_of_continuousOn_differentiableOn {n : ℕ∞} (Hcont : ∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) (Hdiff : ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s) : ContDiffOn 𝕜 n f s := by intro x hx m hm rw [insert_eq_of_mem hx] refine ⟨s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_⟩ constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k hk y hy convert (Hdiff k (lt_of_lt_of_le (mod_cast hk) (mod_cast hm)) y hy).hasFDerivWithinAt · intro k hk exact Hcont k (le_trans (mod_cast hk) (mod_cast hm)) theorem contDiffOn_of_differentiableOn {n : ℕ∞} (h : ∀ m : ℕ, m ≤ n → DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := contDiffOn_of_continuousOn_differentiableOn (fun m hm => (h m hm).continuousOn) fun m hm => h m (le_of_lt hm) theorem contDiffOn_of_analyticOn_iteratedFDerivWithin (h : ∀ m, AnalyticOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s) : ContDiffOn 𝕜 n f s := by suffices ContDiffOn 𝕜 ω f s from this.of_le le_top intro x hx refine ⟨insert x s, self_mem_nhdsWithin, ftaylorSeriesWithin 𝕜 f s, ?_, ?_⟩ · rw [insert_eq_of_mem hx] constructor · intro y _ simp only [ftaylorSeriesWithin, ContinuousMultilinearMap.curry0_apply, iteratedFDerivWithin_zero_apply] · intro k _ y hy exact ((h k).differentiableOn y hy).hasFDerivWithinAt · intro k _ exact (h k).continuousOn · intro i rw [insert_eq_of_mem hx] exact h i theorem contDiffOn_omega_iff_analyticOn (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 ω f s ↔ AnalyticOn 𝕜 f s := ⟨fun h m ↦ h.analyticOn m, fun h ↦ h.contDiffOn hs⟩ theorem ContDiffOn.continuousOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m ≤ n) (hs : UniqueDiffOn 𝕜 s) : ContinuousOn (iteratedFDerivWithin 𝕜 m f s) s := ((h.of_le hmn).ftaylorSeriesWithin hs).cont m le_rfl theorem ContDiffOn.differentiableOn_iteratedFDerivWithin {m : ℕ} (h : ContDiffOn 𝕜 n f s) (hmn : m < n) (hs : UniqueDiffOn 𝕜 s) : DifferentiableOn 𝕜 (iteratedFDerivWithin 𝕜 m f s) s := by intro x hx have : (m + 1 : ℕ) ≤ n := ENat.add_one_natCast_le_withTop_of_lt hmn apply (((h.of_le this).ftaylorSeriesWithin hs).fderivWithin m ?_ x hx).differentiableWithinAt exact_mod_cast lt_add_one m theorem ContDiffWithinAt.differentiableWithinAt_iteratedFDerivWithin {m : ℕ} (h : ContDiffWithinAt 𝕜 n f s x) (hmn : m < n) (hs : UniqueDiffOn 𝕜 (insert x s)) : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f s) s x := by have : (m + 1 : WithTop ℕ∞) ≠ ∞ := Ne.symm (ne_of_beq_false rfl) rcases h.contDiffOn' (ENat.add_one_natCast_le_withTop_of_lt hmn) (by simp [this]) with ⟨u, uo, xu, hu⟩ set t := insert x s ∩ u have A : t =ᶠ[𝓝[≠] x] s := by simp only [set_eventuallyEq_iff_inf_principal, ← nhdsWithin_inter'] rw [← inter_assoc, nhdsWithin_inter_of_mem', ← diff_eq_compl_inter, insert_diff_of_mem, diff_eq_compl_inter] exacts [rfl, mem_nhdsWithin_of_mem_nhds (uo.mem_nhds xu)] have B : iteratedFDerivWithin 𝕜 m f s =ᶠ[𝓝 x] iteratedFDerivWithin 𝕜 m f t := iteratedFDerivWithin_eventually_congr_set' _ A.symm _ have C : DifferentiableWithinAt 𝕜 (iteratedFDerivWithin 𝕜 m f t) t x := hu.differentiableOn_iteratedFDerivWithin (Nat.cast_lt.2 m.lt_succ_self) (hs.inter uo) x ⟨mem_insert _ _, xu⟩ rw [differentiableWithinAt_congr_set' _ A] at C exact C.congr_of_eventuallyEq (B.filter_mono inf_le_left) B.self_of_nhds theorem contDiffOn_iff_continuousOn_differentiableOn {n : ℕ∞} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧ ∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := ⟨fun h => ⟨fun _m hm => h.continuousOn_iteratedFDerivWithin (mod_cast hm) hs, fun _m hm => h.differentiableOn_iteratedFDerivWithin (mod_cast hm) hs⟩, fun h => contDiffOn_of_continuousOn_differentiableOn h.1 h.2⟩ theorem contDiffOn_nat_iff_continuousOn_differentiableOn {n : ℕ} (hs : UniqueDiffOn 𝕜 s) : ContDiffOn 𝕜 n f s ↔ (∀ m : ℕ, m ≤ n → ContinuousOn (fun x => iteratedFDerivWithin 𝕜 m f s x) s) ∧
∀ m : ℕ, m < n → DifferentiableOn 𝕜 (fun x => iteratedFDerivWithin 𝕜 m f s x) s := by rw [← WithTop.coe_natCast, contDiffOn_iff_continuousOn_differentiableOn hs] simp
Mathlib/Analysis/Calculus/ContDiff/Defs.lean
801
803
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.Group.Basic import Mathlib.Data.Set.Function import Mathlib.Order.Interval.Set.Basic import Mathlib.Algebra.Order.Monoid.Defs import Mathlib.Algebra.Order.Monoid.Unbundled.ExistsOfLE /-! # Images of intervals under `(+ d)` The lemmas in this file state that addition maps intervals bijectively. The typeclass `ExistsAddOfLE` is defined specifically to make them work when combined with `OrderedCancelAddCommMonoid`; the lemmas below therefore apply to all `OrderedAddCommGroup`, but also to `ℕ` and `ℝ≥0`, which are not groups. -/ namespace Set variable {M : Type*} [AddCommMonoid M] [PartialOrder M] [IsOrderedCancelAddMonoid M] [ExistsAddOfLE M] (a b c d : M) theorem Ici_add_bij : BijOn (· + d) (Ici a) (Ici (a + d)) := by refine ⟨fun x h => add_le_add_right (mem_Ici.mp h) _, (add_left_injective d).injOn, fun _ h => ?_⟩ obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ici.mp h) rw [mem_Ici, add_right_comm, add_le_add_iff_right] at h exact ⟨a + c, h, by rw [add_right_comm]⟩ theorem Ioi_add_bij : BijOn (· + d) (Ioi a) (Ioi (a + d)) := by refine ⟨fun x h => add_lt_add_right (mem_Ioi.mp h) _, fun _ _ _ _ h => add_right_cancel h, fun _ h => ?_⟩ obtain ⟨c, rfl⟩ := exists_add_of_le (mem_Ioi.mp h).le rw [mem_Ioi, add_right_comm, add_lt_add_iff_right] at h exact ⟨a + c, h, by rw [add_right_comm]⟩ theorem Icc_add_bij : BijOn (· + d) (Icc a b) (Icc (a + d) (b + d)) := by rw [← Ici_inter_Iic, ← Ici_inter_Iic] exact (Ici_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx => le_of_add_le_add_right hx.2 theorem Ioo_add_bij : BijOn (· + d) (Ioo a b) (Ioo (a + d) (b + d)) := by rw [← Ioi_inter_Iio, ← Ioi_inter_Iio] exact (Ioi_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx => lt_of_add_lt_add_right hx.2 theorem Ioc_add_bij : BijOn (· + d) (Ioc a b) (Ioc (a + d) (b + d)) := by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic] exact (Ioi_add_bij a d).inter_mapsTo (fun x hx => add_le_add_right hx _) fun x hx => le_of_add_le_add_right hx.2 theorem Ico_add_bij : BijOn (· + d) (Ico a b) (Ico (a + d) (b + d)) := by rw [← Ici_inter_Iio, ← Ici_inter_Iio] exact (Ici_add_bij a d).inter_mapsTo (fun x hx => add_lt_add_right hx _) fun x hx => lt_of_add_lt_add_right hx.2 /-! ### Images under `x ↦ x + a` -/ @[simp] theorem image_add_const_Ici : (fun x => x + a) '' Ici b = Ici (b + a) := (Ici_add_bij _ _).image_eq @[simp] theorem image_add_const_Ioi : (fun x => x + a) '' Ioi b = Ioi (b + a) := (Ioi_add_bij _ _).image_eq @[simp] theorem image_add_const_Icc : (fun x => x + a) '' Icc b c = Icc (b + a) (c + a) := (Icc_add_bij _ _ _).image_eq @[simp] theorem image_add_const_Ico : (fun x => x + a) '' Ico b c = Ico (b + a) (c + a) := (Ico_add_bij _ _ _).image_eq @[simp] theorem image_add_const_Ioc : (fun x => x + a) '' Ioc b c = Ioc (b + a) (c + a) := (Ioc_add_bij _ _ _).image_eq @[simp] theorem image_add_const_Ioo : (fun x => x + a) '' Ioo b c = Ioo (b + a) (c + a) := (Ioo_add_bij _ _ _).image_eq /-! ### Images under `x ↦ a + x` -/ @[simp] theorem image_const_add_Ici : (fun x => a + x) '' Ici b = Ici (a + b) := by simp only [add_comm a, image_add_const_Ici] @[simp] theorem image_const_add_Ioi : (fun x => a + x) '' Ioi b = Ioi (a + b) := by simp only [add_comm a, image_add_const_Ioi] @[simp] theorem image_const_add_Icc : (fun x => a + x) '' Icc b c = Icc (a + b) (a + c) := by simp only [add_comm a, image_add_const_Icc] @[simp] theorem image_const_add_Ico : (fun x => a + x) '' Ico b c = Ico (a + b) (a + c) := by simp only [add_comm a, image_add_const_Ico] @[simp] theorem image_const_add_Ioc : (fun x => a + x) '' Ioc b c = Ioc (a + b) (a + c) := by simp only [add_comm a, image_add_const_Ioc] @[simp] theorem image_const_add_Ioo : (fun x => a + x) '' Ioo b c = Ioo (a + b) (a + c) := by simp only [add_comm a, image_add_const_Ioo] end Set
Mathlib/Algebra/Order/Interval/Set/Monoid.lean
138
139
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Data.Finset.Pi import Mathlib.Data.Fintype.Basic import Mathlib.Data.Set.Finite.Basic /-! # Fintype instances for pi types -/ assert_not_exists OrderedRing MonoidWithZero open Finset Function variable {α β : Type*} namespace Fintype variable [DecidableEq α] [Fintype α] {γ δ : α → Type*} {s : ∀ a, Finset (γ a)} /-- Given for all `a : α` a finset `t a` of `δ a`, then one can define the finset `Fintype.piFinset t` of all functions taking values in `t a` for all `a`. This is the analogue of `Finset.pi` where the base finset is `univ` (but formally they are not the same, as there is an additional condition `i ∈ Finset.univ` in the `Finset.pi` definition). -/ def piFinset (t : ∀ a, Finset (δ a)) : Finset (∀ a, δ a) := (Finset.univ.pi t).map ⟨fun f a => f a (mem_univ a), fun _ _ => by simp +contextual [funext_iff]⟩ @[simp] theorem mem_piFinset {t : ∀ a, Finset (δ a)} {f : ∀ a, δ a} : f ∈ piFinset t ↔ ∀ a, f a ∈ t a := by constructor · simp only [piFinset, mem_map, and_imp, forall_prop_of_true, exists_prop, mem_univ, exists_imp, mem_pi] rintro g hg hgf a rw [← hgf] exact hg a · simp only [piFinset, mem_map, forall_prop_of_true, exists_prop, mem_univ, mem_pi] exact fun hf => ⟨fun a _ => f a, hf, rfl⟩ @[simp] theorem coe_piFinset (t : ∀ a, Finset (δ a)) : (piFinset t : Set (∀ a, δ a)) = Set.pi Set.univ fun a => t a := Set.ext fun x => by rw [Set.mem_univ_pi] exact Fintype.mem_piFinset theorem piFinset_subset (t₁ t₂ : ∀ a, Finset (δ a)) (h : ∀ a, t₁ a ⊆ t₂ a) : piFinset t₁ ⊆ piFinset t₂ := fun _ hg => mem_piFinset.2 fun a => h a <| mem_piFinset.1 hg a @[simp] theorem piFinset_eq_empty : piFinset s = ∅ ↔ ∃ i, s i = ∅ := by simp [piFinset] @[simp] theorem piFinset_empty [Nonempty α] : piFinset (fun _ => ∅ : ∀ i, Finset (δ i)) = ∅ := by simp @[simp] lemma piFinset_nonempty : (piFinset s).Nonempty ↔ ∀ a, (s a).Nonempty := by simp [piFinset] @[aesop safe apply (rule_sets := [finsetNonempty])] alias ⟨_, Aesop.piFinset_nonempty_of_forall_nonempty⟩ := piFinset_nonempty lemma _root_.Finset.Nonempty.piFinset_const {ι : Type*} [Fintype ι] [DecidableEq ι] {s : Finset β}
(hs : s.Nonempty) : (piFinset fun _ : ι ↦ s).Nonempty := piFinset_nonempty.2 fun _ ↦ hs @[simp]
Mathlib/Data/Fintype/Pi.lean
66
68
/- 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.Algebra.Group.Subgroup.Pointwise import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Order.Filter.Bases.Finite import Mathlib.Topology.Algebra.Group.Defs import Mathlib.Topology.Algebra.Monoid import Mathlib.Topology.Homeomorph.Lemmas /-! # Topological groups This file defines the following typeclasses: * `IsTopologicalGroup`, `IsTopologicalAddGroup`: multiplicative and additive topological groups, i.e., groups with continuous `(*)` and `(⁻¹)` / `(+)` and `(-)`; * `ContinuousSub G` means that `G` has a continuous subtraction operation. There is an instance deducing `ContinuousSub` from `IsTopologicalGroup` but we use a separate typeclass because, e.g., `ℕ` and `ℝ≥0` have continuous subtraction but are not additive groups. We also define `Homeomorph` versions of several `Equiv`s: `Homeomorph.mulLeft`, `Homeomorph.mulRight`, `Homeomorph.inv`, and prove a few facts about neighbourhood filters in groups. ## Tags topological space, group, topological group -/ open Set Filter TopologicalSpace Function Topology MulOpposite Pointwise universe u v w x variable {G : Type w} {H : Type x} {α : Type u} {β : Type v} section ContinuousMulGroup /-! ### Groups with continuous multiplication In this section we prove a few statements about groups with continuous `(*)`. -/ variable [TopologicalSpace G] [Group G] [ContinuousMul G] /-- Multiplication from the left in a topological group as a homeomorphism. -/ @[to_additive "Addition from the left in a topological additive group as a homeomorphism."] protected def Homeomorph.mulLeft (a : G) : G ≃ₜ G := { Equiv.mulLeft a with continuous_toFun := continuous_const.mul continuous_id continuous_invFun := continuous_const.mul continuous_id } @[to_additive (attr := simp)] theorem Homeomorph.coe_mulLeft (a : G) : ⇑(Homeomorph.mulLeft a) = (a * ·) := rfl @[to_additive] theorem Homeomorph.mulLeft_symm (a : G) : (Homeomorph.mulLeft a).symm = Homeomorph.mulLeft a⁻¹ := by ext rfl @[to_additive] lemma isOpenMap_mul_left (a : G) : IsOpenMap (a * ·) := (Homeomorph.mulLeft a).isOpenMap @[to_additive IsOpen.left_addCoset] theorem IsOpen.leftCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (x • U) := isOpenMap_mul_left x _ h @[to_additive] lemma isClosedMap_mul_left (a : G) : IsClosedMap (a * ·) := (Homeomorph.mulLeft a).isClosedMap @[to_additive IsClosed.left_addCoset] theorem IsClosed.leftCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (x • U) := isClosedMap_mul_left x _ h /-- Multiplication from the right in a topological group as a homeomorphism. -/ @[to_additive "Addition from the right in a topological additive group as a homeomorphism."] protected def Homeomorph.mulRight (a : G) : G ≃ₜ G := { Equiv.mulRight a with continuous_toFun := continuous_id.mul continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive (attr := simp)] lemma Homeomorph.coe_mulRight (a : G) : ⇑(Homeomorph.mulRight a) = (· * a) := rfl @[to_additive] theorem Homeomorph.mulRight_symm (a : G) : (Homeomorph.mulRight a).symm = Homeomorph.mulRight a⁻¹ := by ext rfl @[to_additive] theorem isOpenMap_mul_right (a : G) : IsOpenMap (· * a) := (Homeomorph.mulRight a).isOpenMap @[to_additive IsOpen.right_addCoset] theorem IsOpen.rightCoset {U : Set G} (h : IsOpen U) (x : G) : IsOpen (op x • U) := isOpenMap_mul_right x _ h @[to_additive] theorem isClosedMap_mul_right (a : G) : IsClosedMap (· * a) := (Homeomorph.mulRight a).isClosedMap @[to_additive IsClosed.right_addCoset] theorem IsClosed.rightCoset {U : Set G} (h : IsClosed U) (x : G) : IsClosed (op x • U) := isClosedMap_mul_right x _ h @[to_additive] theorem discreteTopology_of_isOpen_singleton_one (h : IsOpen ({1} : Set G)) : DiscreteTopology G := by rw [← singletons_open_iff_discrete] intro g suffices {g} = (g⁻¹ * ·) ⁻¹' {1} by rw [this] exact (continuous_mul_left g⁻¹).isOpen_preimage _ h simp only [mul_one, Set.preimage_mul_left_singleton, eq_self_iff_true, inv_inv, Set.singleton_eq_singleton_iff] @[to_additive] theorem discreteTopology_iff_isOpen_singleton_one : DiscreteTopology G ↔ IsOpen ({1} : Set G) := ⟨fun h => forall_open_iff_discrete.mpr h {1}, discreteTopology_of_isOpen_singleton_one⟩ end ContinuousMulGroup /-! ### `ContinuousInv` and `ContinuousNeg` -/ section ContinuousInv variable [TopologicalSpace G] [Inv G] [ContinuousInv G] @[to_additive] theorem ContinuousInv.induced {α : Type*} {β : Type*} {F : Type*} [FunLike F α β] [Group α] [DivisionMonoid β] [MonoidHomClass F α β] [tβ : TopologicalSpace β] [ContinuousInv β] (f : F) : @ContinuousInv α (tβ.induced f) _ := by let _tα := tβ.induced f refine ⟨continuous_induced_rng.2 ?_⟩ simp only [Function.comp_def, map_inv] fun_prop @[to_additive] protected theorem Specializes.inv {x y : G} (h : x ⤳ y) : (x⁻¹) ⤳ (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Inseparable.inv {x y : G} (h : Inseparable x y) : Inseparable (x⁻¹) (y⁻¹) := h.map continuous_inv @[to_additive] protected theorem Specializes.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : x ⤳ y) : ∀ m : ℤ, (x ^ m) ⤳ (y ^ m) | .ofNat n => by simpa using h.pow n | .negSucc n => by simpa using (h.pow (n + 1)).inv @[to_additive] protected theorem Inseparable.zpow {G : Type*} [DivInvMonoid G] [TopologicalSpace G] [ContinuousMul G] [ContinuousInv G] {x y : G} (h : Inseparable x y) (m : ℤ) : Inseparable (x ^ m) (y ^ m) := (h.specializes.zpow m).antisymm (h.specializes'.zpow m) @[to_additive] instance : ContinuousInv (ULift G) := ⟨continuous_uliftUp.comp (continuous_inv.comp continuous_uliftDown)⟩ @[to_additive] theorem continuousOn_inv {s : Set G} : ContinuousOn Inv.inv s := continuous_inv.continuousOn @[to_additive] theorem continuousWithinAt_inv {s : Set G} {x : G} : ContinuousWithinAt Inv.inv s x := continuous_inv.continuousWithinAt @[to_additive] theorem continuousAt_inv {x : G} : ContinuousAt Inv.inv x := continuous_inv.continuousAt @[to_additive] theorem tendsto_inv (a : G) : Tendsto Inv.inv (𝓝 a) (𝓝 a⁻¹) := continuousAt_inv variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive] instance OrderDual.instContinuousInv : ContinuousInv Gᵒᵈ := ‹ContinuousInv G› @[to_additive] instance Prod.continuousInv [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousInv (G × H) := ⟨continuous_inv.fst'.prodMk continuous_inv.snd'⟩ variable {ι : Type*} @[to_additive] instance Pi.continuousInv {C : ι → Type*} [∀ i, TopologicalSpace (C i)] [∀ i, Inv (C i)] [∀ i, ContinuousInv (C i)] : ContinuousInv (∀ i, C i) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv /-- A version of `Pi.continuousInv` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousInv` for non-dependent functions. -/ @[to_additive "A version of `Pi.continuousNeg` for non-dependent functions. It is needed because sometimes Lean fails to use `Pi.continuousNeg` for non-dependent functions."] instance Pi.has_continuous_inv' : ContinuousInv (ι → G) := Pi.continuousInv @[to_additive] instance (priority := 100) continuousInv_of_discreteTopology [TopologicalSpace H] [Inv H] [DiscreteTopology H] : ContinuousInv H := ⟨continuous_of_discreteTopology⟩ section PointwiseLimits variable (G₁ G₂ : Type*) [TopologicalSpace G₂] [T2Space G₂] @[to_additive] theorem isClosed_setOf_map_inv [Inv G₁] [Inv G₂] [ContinuousInv G₂] : IsClosed { f : G₁ → G₂ | ∀ x, f x⁻¹ = (f x)⁻¹ } := by simp only [setOf_forall] exact isClosed_iInter fun i => isClosed_eq (continuous_apply _) (continuous_apply _).inv end PointwiseLimits instance [TopologicalSpace H] [Inv H] [ContinuousInv H] : ContinuousNeg (Additive H) where continuous_neg := @continuous_inv H _ _ _ instance [TopologicalSpace H] [Neg H] [ContinuousNeg H] : ContinuousInv (Multiplicative H) where continuous_inv := @continuous_neg H _ _ _ end ContinuousInv section ContinuousInvolutiveInv variable [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] {s : Set G} @[to_additive] theorem IsCompact.inv (hs : IsCompact s) : IsCompact s⁻¹ := by rw [← image_inv_eq_inv] exact hs.image continuous_inv variable (G) /-- Inversion in a topological group as a homeomorphism. -/ @[to_additive "Negation in a topological group as a homeomorphism."] protected def Homeomorph.inv (G : Type*) [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : G ≃ₜ G := { Equiv.inv G with continuous_toFun := continuous_inv continuous_invFun := continuous_inv } @[to_additive (attr := simp)] lemma Homeomorph.coe_inv {G : Type*} [TopologicalSpace G] [InvolutiveInv G] [ContinuousInv G] : ⇑(Homeomorph.inv G) = Inv.inv := rfl @[to_additive] theorem nhds_inv (a : G) : 𝓝 a⁻¹ = (𝓝 a)⁻¹ := ((Homeomorph.inv G).map_nhds_eq a).symm @[to_additive] theorem isOpenMap_inv : IsOpenMap (Inv.inv : G → G) := (Homeomorph.inv _).isOpenMap @[to_additive] theorem isClosedMap_inv : IsClosedMap (Inv.inv : G → G) := (Homeomorph.inv _).isClosedMap variable {G} @[to_additive] theorem IsOpen.inv (hs : IsOpen s) : IsOpen s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem IsClosed.inv (hs : IsClosed s) : IsClosed s⁻¹ := hs.preimage continuous_inv @[to_additive] theorem inv_closure : ∀ s : Set G, (closure s)⁻¹ = closure s⁻¹ := (Homeomorph.inv G).preimage_closure variable [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} @[to_additive (attr := simp)] lemma continuous_inv_iff : Continuous f⁻¹ ↔ Continuous f := (Homeomorph.inv G).comp_continuous_iff @[to_additive (attr := simp)] lemma continuousAt_inv_iff : ContinuousAt f⁻¹ x ↔ ContinuousAt f x := (Homeomorph.inv G).comp_continuousAt_iff _ _ @[to_additive (attr := simp)] lemma continuousOn_inv_iff : ContinuousOn f⁻¹ s ↔ ContinuousOn f s := (Homeomorph.inv G).comp_continuousOn_iff _ _ @[to_additive] alias ⟨Continuous.of_inv, _⟩ := continuous_inv_iff @[to_additive] alias ⟨ContinuousAt.of_inv, _⟩ := continuousAt_inv_iff @[to_additive] alias ⟨ContinuousOn.of_inv, _⟩ := continuousOn_inv_iff end ContinuousInvolutiveInv section LatticeOps variable {ι' : Sort*} [Inv G] @[to_additive] theorem continuousInv_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @ContinuousInv G t _) : @ContinuousInv G (sInf ts) _ := letI := sInf ts { continuous_inv := continuous_sInf_rng.2 fun t ht => continuous_sInf_dom ht (@ContinuousInv.continuous_inv G t _ (h t ht)) } @[to_additive] theorem continuousInv_iInf {ts' : ι' → TopologicalSpace G} (h' : ∀ i, @ContinuousInv G (ts' i) _) : @ContinuousInv G (⨅ i, ts' i) _ := by rw [← sInf_range] exact continuousInv_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem continuousInv_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @ContinuousInv G t₁ _) (h₂ : @ContinuousInv G t₂ _) : @ContinuousInv G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine continuousInv_iInf fun b => ?_ cases b <;> assumption end LatticeOps @[to_additive] theorem Topology.IsInducing.continuousInv {G H : Type*} [Inv G] [Inv H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv H] {f : G → H} (hf : IsInducing f) (hf_inv : ∀ x, f x⁻¹ = (f x)⁻¹) : ContinuousInv G := ⟨hf.continuous_iff.2 <| by simpa only [Function.comp_def, hf_inv] using hf.continuous.inv⟩ @[deprecated (since := "2024-10-28")] alias Inducing.continuousInv := IsInducing.continuousInv section IsTopologicalGroup /-! ### Topological groups A topological group is a group in which the multiplication and inversion operations are continuous. Topological additive groups are defined in the same way. Equivalently, we can require that the division operation `x y ↦ x * y⁻¹` (resp., subtraction) is continuous. -/ section Conj instance ConjAct.units_continuousConstSMul {M} [Monoid M] [TopologicalSpace M] [ContinuousMul M] : ContinuousConstSMul (ConjAct Mˣ) M := ⟨fun _ => (continuous_const.mul continuous_id).mul continuous_const⟩ variable [TopologicalSpace G] [Inv G] [Mul G] [ContinuousMul G] /-- Conjugation is jointly continuous on `G × G` when both `mul` and `inv` are continuous. -/ @[to_additive continuous_addConj_prod "Conjugation is jointly continuous on `G × G` when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj_prod [ContinuousInv G] : Continuous fun g : G × G => g.fst * g.snd * g.fst⁻¹ := continuous_mul.mul (continuous_inv.comp continuous_fst) @[deprecated (since := "2025-03-11")] alias IsTopologicalAddGroup.continuous_conj_sum := IsTopologicalAddGroup.continuous_addConj_prod /-- Conjugation by a fixed element is continuous when `mul` is continuous. -/ @[to_additive (attr := continuity) "Conjugation by a fixed element is continuous when `add` is continuous."] theorem IsTopologicalGroup.continuous_conj (g : G) : Continuous fun h : G => g * h * g⁻¹ := (continuous_mul_right g⁻¹).comp (continuous_mul_left g) /-- Conjugation acting on fixed element of the group is continuous when both `mul` and `inv` are continuous. -/ @[to_additive (attr := continuity) "Conjugation acting on fixed element of the additive group is continuous when both `add` and `neg` are continuous."] theorem IsTopologicalGroup.continuous_conj' [ContinuousInv G] (h : G) : Continuous fun g : G => g * h * g⁻¹ := (continuous_mul_right h).mul continuous_inv end Conj variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] [TopologicalSpace α] {f : α → G} {s : Set α} {x : α} instance : IsTopologicalGroup (ULift G) where section ZPow @[to_additive (attr := continuity, fun_prop)] theorem continuous_zpow : ∀ z : ℤ, Continuous fun a : G => a ^ z | Int.ofNat n => by simpa using continuous_pow n | Int.negSucc n => by simpa using (continuous_pow (n + 1)).inv instance AddGroup.continuousConstSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousConstSMul ℤ A := ⟨continuous_zsmul⟩ instance AddGroup.continuousSMul_int {A} [AddGroup A] [TopologicalSpace A] [IsTopologicalAddGroup A] : ContinuousSMul ℤ A := ⟨continuous_prod_of_discrete_left.mpr continuous_zsmul⟩ @[to_additive (attr := continuity, fun_prop)] theorem Continuous.zpow {f : α → G} (h : Continuous f) (z : ℤ) : Continuous fun b => f b ^ z := (continuous_zpow z).comp h @[to_additive] theorem continuousOn_zpow {s : Set G} (z : ℤ) : ContinuousOn (fun x => x ^ z) s := (continuous_zpow z).continuousOn @[to_additive] theorem continuousAt_zpow (x : G) (z : ℤ) : ContinuousAt (fun x => x ^ z) x := (continuous_zpow z).continuousAt @[to_additive] theorem Filter.Tendsto.zpow {α} {l : Filter α} {f : α → G} {x : G} (hf : Tendsto f l (𝓝 x)) (z : ℤ) : Tendsto (fun x => f x ^ z) l (𝓝 (x ^ z)) := (continuousAt_zpow _ _).tendsto.comp hf @[to_additive] theorem ContinuousWithinAt.zpow {f : α → G} {x : α} {s : Set α} (hf : ContinuousWithinAt f s x) (z : ℤ) : ContinuousWithinAt (fun x => f x ^ z) s x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousAt.zpow {f : α → G} {x : α} (hf : ContinuousAt f x) (z : ℤ) : ContinuousAt (fun x => f x ^ z) x := Filter.Tendsto.zpow hf z @[to_additive (attr := fun_prop)] theorem ContinuousOn.zpow {f : α → G} {s : Set α} (hf : ContinuousOn f s) (z : ℤ) : ContinuousOn (fun x => f x ^ z) s := fun x hx => (hf x hx).zpow z end ZPow section OrderedCommGroup variable [TopologicalSpace H] [CommGroup H] [PartialOrder H] [IsOrderedMonoid H] [ContinuousInv H] @[to_additive] theorem tendsto_inv_nhdsGT {a : H} : Tendsto Inv.inv (𝓝[>] a) (𝓝[<] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi := tendsto_neg_nhdsGT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi := tendsto_inv_nhdsGT @[to_additive] theorem tendsto_inv_nhdsLT {a : H} : Tendsto Inv.inv (𝓝[<] a) (𝓝[>] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio := tendsto_neg_nhdsLT @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio := tendsto_inv_nhdsLT @[to_additive] theorem tendsto_inv_nhdsGT_inv {a : H} : Tendsto Inv.inv (𝓝[>] a⁻¹) (𝓝[<] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ioi_neg := tendsto_neg_nhdsGT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ioi_inv := tendsto_inv_nhdsGT_inv @[to_additive] theorem tendsto_inv_nhdsLT_inv {a : H} : Tendsto Inv.inv (𝓝[<] a⁻¹) (𝓝[>] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLT (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iio_neg := tendsto_neg_nhdsLT_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iio_inv := tendsto_inv_nhdsLT_inv @[to_additive] theorem tendsto_inv_nhdsGE {a : H} : Tendsto Inv.inv (𝓝[≥] a) (𝓝[≤] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici := tendsto_neg_nhdsGE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici := tendsto_inv_nhdsGE @[to_additive] theorem tendsto_inv_nhdsLE {a : H} : Tendsto Inv.inv (𝓝[≤] a) (𝓝[≥] a⁻¹) := (continuous_inv.tendsto a).inf <| by simp [tendsto_principal_principal] @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic := tendsto_neg_nhdsLE @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic := tendsto_inv_nhdsLE @[to_additive] theorem tendsto_inv_nhdsGE_inv {a : H} : Tendsto Inv.inv (𝓝[≥] a⁻¹) (𝓝[≤] a) := by simpa only [inv_inv] using tendsto_inv_nhdsGE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Ici_neg := tendsto_neg_nhdsGE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Ici_inv := tendsto_inv_nhdsGE_inv @[to_additive] theorem tendsto_inv_nhdsLE_inv {a : H} : Tendsto Inv.inv (𝓝[≤] a⁻¹) (𝓝[≥] a) := by simpa only [inv_inv] using tendsto_inv_nhdsLE (a := a⁻¹) @[deprecated (since := "2024-12-22")] alias tendsto_neg_nhdsWithin_Iic_neg := tendsto_neg_nhdsLE_neg @[to_additive existing, deprecated (since := "2024-12-22")] alias tendsto_inv_nhdsWithin_Iic_inv := tendsto_inv_nhdsLE_inv end OrderedCommGroup @[to_additive] instance Prod.instIsTopologicalGroup [TopologicalSpace H] [Group H] [IsTopologicalGroup H] : IsTopologicalGroup (G × H) where continuous_inv := continuous_inv.prodMap continuous_inv @[to_additive] instance OrderDual.instIsTopologicalGroup : IsTopologicalGroup Gᵒᵈ where @[to_additive] instance Pi.topologicalGroup {C : β → Type*} [∀ b, TopologicalSpace (C b)] [∀ b, Group (C b)] [∀ b, IsTopologicalGroup (C b)] : IsTopologicalGroup (∀ b, C b) where continuous_inv := continuous_pi fun i => (continuous_apply i).inv open MulOpposite @[to_additive] instance [Inv α] [ContinuousInv α] : ContinuousInv αᵐᵒᵖ := opHomeomorph.symm.isInducing.continuousInv unop_inv /-- If multiplication is continuous in `α`, then it also is in `αᵐᵒᵖ`. -/ @[to_additive "If addition is continuous in `α`, then it also is in `αᵃᵒᵖ`."] instance [Group α] [IsTopologicalGroup α] : IsTopologicalGroup αᵐᵒᵖ where variable (G) @[to_additive] theorem nhds_one_symm : comap Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).comap_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem nhds_one_symm' : map Inv.inv (𝓝 (1 : G)) = 𝓝 (1 : G) := ((Homeomorph.inv G).map_nhds_eq _).trans (congr_arg nhds inv_one) @[to_additive] theorem inv_mem_nhds_one {S : Set G} (hS : S ∈ (𝓝 1 : Filter G)) : S⁻¹ ∈ 𝓝 (1 : G) := by rwa [← nhds_one_symm'] at hS /-- The map `(x, y) ↦ (x, x * y)` as a homeomorphism. This is a shear mapping. -/ @[to_additive "The map `(x, y) ↦ (x, x + y)` as a homeomorphism. This is a shear mapping."] protected def Homeomorph.shearMulRight : G × G ≃ₜ G × G := { Equiv.prodShear (Equiv.refl _) Equiv.mulLeft with continuous_toFun := by dsimp; fun_prop continuous_invFun := by dsimp; fun_prop } @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_coe : ⇑(Homeomorph.shearMulRight G) = fun z : G × G => (z.1, z.1 * z.2) := rfl @[to_additive (attr := simp)] theorem Homeomorph.shearMulRight_symm_coe : ⇑(Homeomorph.shearMulRight G).symm = fun z : G × G => (z.1, z.1⁻¹ * z.2) := rfl variable {G} @[to_additive] protected theorem Topology.IsInducing.topologicalGroup {F : Type*} [Group H] [TopologicalSpace H] [FunLike F H G] [MonoidHomClass F H G] (f : F) (hf : IsInducing f) : IsTopologicalGroup H := { toContinuousMul := hf.continuousMul _ toContinuousInv := hf.continuousInv (map_inv f) } @[deprecated (since := "2024-10-28")] alias Inducing.topologicalGroup := IsInducing.topologicalGroup @[to_additive] theorem topologicalGroup_induced {F : Type*} [Group H] [FunLike F H G] [MonoidHomClass F H G] (f : F) : @IsTopologicalGroup H (induced f ‹_›) _ := letI := induced f ‹_› IsInducing.topologicalGroup f ⟨rfl⟩ namespace Subgroup @[to_additive] instance (S : Subgroup G) : IsTopologicalGroup S := IsInducing.subtypeVal.topologicalGroup S.subtype end Subgroup /-- The (topological-space) closure of a subgroup of a topological group is itself a subgroup. -/ @[to_additive "The (topological-space) closure of an additive subgroup of an additive topological group is itself an additive subgroup."] def Subgroup.topologicalClosure (s : Subgroup G) : Subgroup G := { s.toSubmonoid.topologicalClosure with carrier := _root_.closure (s : Set G) inv_mem' := fun {g} hg => by simpa only [← Set.mem_inv, inv_closure, inv_coe_set] using hg } @[to_additive (attr := simp)] theorem Subgroup.topologicalClosure_coe {s : Subgroup G} : (s.topologicalClosure : Set G) = _root_.closure s := rfl @[to_additive] theorem Subgroup.le_topologicalClosure (s : Subgroup G) : s ≤ s.topologicalClosure := _root_.subset_closure @[to_additive] theorem Subgroup.isClosed_topologicalClosure (s : Subgroup G) : IsClosed (s.topologicalClosure : Set G) := isClosed_closure @[to_additive] theorem Subgroup.topologicalClosure_minimal (s : Subgroup G) {t : Subgroup G} (h : s ≤ t) (ht : IsClosed (t : Set G)) : s.topologicalClosure ≤ t := closure_minimal h ht @[to_additive] theorem DenseRange.topologicalClosure_map_subgroup [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {f : G →* H} (hf : Continuous f) (hf' : DenseRange f) {s : Subgroup G} (hs : s.topologicalClosure = ⊤) : (s.map f).topologicalClosure = ⊤ := by rw [SetLike.ext'_iff] at hs ⊢ simp only [Subgroup.topologicalClosure_coe, Subgroup.coe_top, ← dense_iff_closure_eq] at hs ⊢ exact hf'.dense_image hf hs /-- The topological closure of a normal subgroup is normal. -/ @[to_additive "The topological closure of a normal additive subgroup is normal."] theorem Subgroup.is_normal_topologicalClosure {G : Type*} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] (N : Subgroup G) [N.Normal] : (Subgroup.topologicalClosure N).Normal where conj_mem n hn g := by apply map_mem_closure (IsTopologicalGroup.continuous_conj g) hn exact fun m hm => Subgroup.Normal.conj_mem inferInstance m hm g @[to_additive] theorem mul_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] {g h : G} (hg : g ∈ connectedComponent (1 : G)) (hh : h ∈ connectedComponent (1 : G)) : g * h ∈ connectedComponent (1 : G) := by rw [connectedComponent_eq hg] have hmul : g ∈ connectedComponent (g * h) := by apply Continuous.image_connectedComponent_subset (continuous_mul_left g) rw [← connectedComponent_eq hh] exact ⟨(1 : G), mem_connectedComponent, by simp only [mul_one]⟩ simpa [← connectedComponent_eq hmul] using mem_connectedComponent @[to_additive] theorem inv_mem_connectedComponent_one {G : Type*} [TopologicalSpace G] [DivisionMonoid G] [ContinuousInv G] {g : G} (hg : g ∈ connectedComponent (1 : G)) : g⁻¹ ∈ connectedComponent (1 : G) := by rw [← inv_one] exact Continuous.image_connectedComponent_subset continuous_inv _ ((Set.mem_image _ _ _).mp ⟨g, hg, rfl⟩) /-- The connected component of 1 is a subgroup of `G`. -/ @[to_additive "The connected component of 0 is a subgroup of `G`."] def Subgroup.connectedComponentOfOne (G : Type*) [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : Subgroup G where carrier := connectedComponent (1 : G) one_mem' := mem_connectedComponent mul_mem' hg hh := mul_mem_connectedComponent_one hg hh inv_mem' hg := inv_mem_connectedComponent_one hg /-- If a subgroup of a topological group is commutative, then so is its topological closure. See note [reducible non-instances]. -/ @[to_additive "If a subgroup of an additive topological group is commutative, then so is its topological closure. See note [reducible non-instances]."] abbrev Subgroup.commGroupTopologicalClosure [T2Space G] (s : Subgroup G) (hs : ∀ x y : s, x * y = y * x) : CommGroup s.topologicalClosure := { s.topologicalClosure.toGroup, s.toSubmonoid.commMonoidTopologicalClosure hs with } variable (G) in @[to_additive] lemma Subgroup.coe_topologicalClosure_bot : ((⊥ : Subgroup G).topologicalClosure : Set G) = _root_.closure ({1} : Set G) := by simp @[to_additive exists_nhds_half_neg] theorem exists_nhds_split_inv {s : Set G} (hs : s ∈ 𝓝 (1 : G)) : ∃ V ∈ 𝓝 (1 : G), ∀ v ∈ V, ∀ w ∈ V, v / w ∈ s := by have : (fun p : G × G => p.1 * p.2⁻¹) ⁻¹' s ∈ 𝓝 ((1, 1) : G × G) := continuousAt_fst.mul continuousAt_snd.inv (by simpa) simpa only [div_eq_mul_inv, nhds_prod_eq, mem_prod_self_iff, prod_subset_iff, mem_preimage] using this @[to_additive] theorem nhds_translation_mul_inv (x : G) : comap (· * x⁻¹) (𝓝 1) = 𝓝 x := ((Homeomorph.mulRight x⁻¹).comap_nhds_eq 1).trans <| show 𝓝 (1 * x⁻¹⁻¹) = 𝓝 x by simp @[to_additive (attr := simp)] theorem map_mul_left_nhds (x y : G) : map (x * ·) (𝓝 y) = 𝓝 (x * y) := (Homeomorph.mulLeft x).map_nhds_eq y @[to_additive] theorem map_mul_left_nhds_one (x : G) : map (x * ·) (𝓝 1) = 𝓝 x := by simp @[to_additive (attr := simp)] theorem map_mul_right_nhds (x y : G) : map (· * x) (𝓝 y) = 𝓝 (y * x) := (Homeomorph.mulRight x).map_nhds_eq y @[to_additive] theorem map_mul_right_nhds_one (x : G) : map (· * x) (𝓝 1) = 𝓝 x := by simp @[to_additive] theorem Filter.HasBasis.nhds_of_one {ι : Sort*} {p : ι → Prop} {s : ι → Set G} (hb : HasBasis (𝓝 1 : Filter G) p s) (x : G) : HasBasis (𝓝 x) p fun i => { y | y / x ∈ s i } := by rw [← nhds_translation_mul_inv] simp_rw [div_eq_mul_inv] exact hb.comap _ @[to_additive] theorem mem_closure_iff_nhds_one {x : G} {s : Set G} : x ∈ closure s ↔ ∀ U ∈ (𝓝 1 : Filter G), ∃ y ∈ s, y / x ∈ U := by rw [mem_closure_iff_nhds_basis ((𝓝 1 : Filter G).basis_sets.nhds_of_one x)] simp_rw [Set.mem_setOf, id] /-- A monoid homomorphism (a bundled morphism of a type that implements `MonoidHomClass`) from a topological group to a topological monoid is continuous provided that it is continuous at one. See also `uniformContinuous_of_continuousAt_one`. -/ @[to_additive "An additive monoid homomorphism (a bundled morphism of a type that implements `AddMonoidHomClass`) from an additive topological group to an additive topological monoid is continuous provided that it is continuous at zero. See also `uniformContinuous_of_continuousAt_zero`."] theorem continuous_of_continuousAt_one {M hom : Type*} [MulOneClass M] [TopologicalSpace M] [ContinuousMul M] [FunLike hom G M] [MonoidHomClass hom G M] (f : hom) (hf : ContinuousAt f 1) : Continuous f := continuous_iff_continuousAt.2 fun x => by simpa only [ContinuousAt, ← map_mul_left_nhds_one x, tendsto_map'_iff, Function.comp_def, map_mul, map_one, mul_one] using hf.tendsto.const_mul (f x) @[to_additive continuous_of_continuousAt_zero₂] theorem continuous_of_continuousAt_one₂ {H M : Type*} [CommMonoid M] [TopologicalSpace M] [ContinuousMul M] [Group H] [TopologicalSpace H] [IsTopologicalGroup H] (f : G →* H →* M) (hf : ContinuousAt (fun x : G × H ↦ f x.1 x.2) (1, 1)) (hl : ∀ x, ContinuousAt (f x) 1) (hr : ∀ y, ContinuousAt (f · y) 1) : Continuous (fun x : G × H ↦ f x.1 x.2) := continuous_iff_continuousAt.2 fun (x, y) => by simp only [ContinuousAt, nhds_prod_eq, ← map_mul_left_nhds_one x, ← map_mul_left_nhds_one y, prod_map_map_eq, tendsto_map'_iff, Function.comp_def, map_mul, MonoidHom.mul_apply] at * refine ((tendsto_const_nhds.mul ((hr y).comp tendsto_fst)).mul (((hl x).comp tendsto_snd).mul hf)).mono_right (le_of_eq ?_) simp only [map_one, mul_one, MonoidHom.one_apply] @[to_additive] lemma IsTopologicalGroup.isInducing_iff_nhds_one {H : Type*} [Group H] [TopologicalSpace H] [IsTopologicalGroup H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : Topology.IsInducing f ↔ 𝓝 (1 : G) = (𝓝 (1 : H)).comap f := by rw [Topology.isInducing_iff_nhds] refine ⟨(map_one f ▸ · 1), fun hf x ↦ ?_⟩ rw [← nhds_translation_mul_inv, ← nhds_translation_mul_inv (f x), Filter.comap_comap, hf, Filter.comap_comap] congr 1 ext; simp @[to_additive] lemma TopologicalGroup.isOpenMap_iff_nhds_one {H : Type*} [Monoid H] [TopologicalSpace H] [ContinuousConstSMul H H] {F : Type*} [FunLike F G H] [MonoidHomClass F G H] {f : F} : IsOpenMap f ↔ 𝓝 1 ≤ .map f (𝓝 1) := by refine ⟨fun H ↦ map_one f ▸ H.nhds_le 1, fun h ↦ IsOpenMap.of_nhds_le fun x ↦ ?_⟩ have : Filter.map (f x * ·) (𝓝 1) = 𝓝 (f x) := by simpa [-Homeomorph.map_nhds_eq, Units.smul_def] using (Homeomorph.smul ((toUnits x).map (MonoidHomClass.toMonoidHom f))).map_nhds_eq (1 : H) rw [← map_mul_left_nhds_one x, Filter.map_map, Function.comp_def, ← this] refine (Filter.map_mono h).trans ?_ simp [Function.comp_def] -- TODO: unify with `QuotientGroup.isOpenQuotientMap_mk` /-- Let `A` and `B` be topological groups, and let `φ : A → B` be a continuous surjective group homomorphism. Assume furthermore that `φ` is a quotient map (i.e., `V ⊆ B` is open iff `φ⁻¹ V` is open). Then `φ` is an open quotient map, and in particular an open map. -/ @[to_additive "Let `A` and `B` be topological additive groups, and let `φ : A → B` be a continuous surjective additive group homomorphism. Assume furthermore that `φ` is a quotient map (i.e., `V ⊆ B` is open iff `φ⁻¹ V` is open). Then `φ` is an open quotient map, and in particular an open map."] lemma MonoidHom.isOpenQuotientMap_of_isQuotientMap {A : Type*} [Group A] [TopologicalSpace A] [ContinuousMul A] {B : Type*} [Group B] [TopologicalSpace B] {F : Type*} [FunLike F A B] [MonoidHomClass F A B] {φ : F} (hφ : IsQuotientMap φ) : IsOpenQuotientMap φ where surjective := hφ.surjective continuous := hφ.continuous isOpenMap := by -- We need to check that if `U ⊆ A` is open then `φ⁻¹ (φ U)` is open. intro U hU rw [← hφ.isOpen_preimage] -- It suffices to show that `φ⁻¹ (φ U) = ⋃ (U * k⁻¹)` as `k` runs through the kernel of `φ`, -- as `U * k⁻¹` is open because `x ↦ x * k` is continuous. -- Remark: here is where we use that we have groups not monoids (you cannot avoid -- using both `k` and `k⁻¹` at this point). suffices ⇑φ ⁻¹' (⇑φ '' U) = ⋃ k ∈ ker (φ : A →* B), (fun x ↦ x * k) ⁻¹' U by exact this ▸ isOpen_biUnion (fun k _ ↦ Continuous.isOpen_preimage (by fun_prop) _ hU) ext x -- But this is an elementary calculation. constructor · rintro ⟨y, hyU, hyx⟩ apply Set.mem_iUnion_of_mem (x⁻¹ * y) simp_all · rintro ⟨_, ⟨k, rfl⟩, _, ⟨(hk : φ k = 1), rfl⟩, hx⟩ use x * k, hx rw [map_mul, hk, mul_one] @[to_additive] theorem IsTopologicalGroup.ext {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) (h : @nhds G t 1 = @nhds G t' 1) : t = t' := TopologicalSpace.ext_nhds fun x ↦ by rw [← @nhds_translation_mul_inv G t _ _ x, ← @nhds_translation_mul_inv G t' _ _ x, ← h] @[to_additive] theorem IsTopologicalGroup.ext_iff {G : Type*} [Group G] {t t' : TopologicalSpace G} (tg : @IsTopologicalGroup G t _) (tg' : @IsTopologicalGroup G t' _) : t = t' ↔ @nhds G t 1 = @nhds G t' 1 := ⟨fun h => h ▸ rfl, tg.ext tg'⟩ @[to_additive] theorem ContinuousInv.of_nhds_one {G : Type*} [Group G] [TopologicalSpace G] (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x : G => x₀ * x) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (fun x : G => x₀ * x * x₀⁻¹) (𝓝 1) (𝓝 1)) : ContinuousInv G := by refine ⟨continuous_iff_continuousAt.2 fun x₀ => ?_⟩ have : Tendsto (fun x => x₀⁻¹ * (x₀ * x⁻¹ * x₀⁻¹)) (𝓝 1) (map (x₀⁻¹ * ·) (𝓝 1)) := (tendsto_map.comp <| hconj x₀).comp hinv simpa only [ContinuousAt, hleft x₀, hleft x₀⁻¹, tendsto_map'_iff, Function.comp_def, mul_assoc, mul_inv_rev, inv_mul_cancel_left] using this @[to_additive] theorem IsTopologicalGroup.of_nhds_one' {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x₀ * x) (𝓝 1)) (hright : ∀ x₀ : G, 𝓝 x₀ = map (fun x => x * x₀) (𝓝 1)) : IsTopologicalGroup G := { toContinuousMul := ContinuousMul.of_nhds_one hmul hleft hright toContinuousInv := ContinuousInv.of_nhds_one hinv hleft fun x₀ => le_of_eq (by rw [show (fun x => x₀ * x * x₀⁻¹) = (fun x => x * x₀⁻¹) ∘ fun x => x₀ * x from rfl, ← map_map, ← hleft, hright, map_map] simp [(· ∘ ·)]) } @[to_additive] theorem IsTopologicalGroup.of_nhds_one {G : Type u} [Group G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) (hconj : ∀ x₀ : G, Tendsto (x₀ * · * x₀⁻¹) (𝓝 1) (𝓝 1)) : IsTopologicalGroup G := by refine IsTopologicalGroup.of_nhds_one' hmul hinv hleft fun x₀ => ?_ replace hconj : ∀ x₀ : G, map (x₀ * · * x₀⁻¹) (𝓝 1) = 𝓝 1 := fun x₀ => map_eq_of_inverse (x₀⁻¹ * · * x₀⁻¹⁻¹) (by ext; simp [mul_assoc]) (hconj _) (hconj _) rw [← hconj x₀] simpa [Function.comp_def] using hleft _ @[to_additive] theorem IsTopologicalGroup.of_comm_of_nhds_one {G : Type u} [CommGroup G] [TopologicalSpace G] (hmul : Tendsto (uncurry ((· * ·) : G → G → G)) (𝓝 1 ×ˢ 𝓝 1) (𝓝 1)) (hinv : Tendsto (fun x : G => x⁻¹) (𝓝 1) (𝓝 1)) (hleft : ∀ x₀ : G, 𝓝 x₀ = map (x₀ * ·) (𝓝 1)) : IsTopologicalGroup G := IsTopologicalGroup.of_nhds_one hmul hinv hleft (by simpa using tendsto_id) variable (G) in /-- Any first countable topological group has an antitone neighborhood basis `u : ℕ → Set G` for which `(u (n + 1)) ^ 2 ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientGroup.completeSpace` -/ @[to_additive "Any first countable topological additive group has an antitone neighborhood basis `u : ℕ → set G` for which `u (n + 1) + u (n + 1) ⊆ u n`. The existence of such a neighborhood basis is a key tool for `QuotientAddGroup.completeSpace`"] theorem IsTopologicalGroup.exists_antitone_basis_nhds_one [FirstCountableTopology G] : ∃ u : ℕ → Set G, (𝓝 1).HasAntitoneBasis u ∧ ∀ n, u (n + 1) * u (n + 1) ⊆ u n := by rcases (𝓝 (1 : G)).exists_antitone_basis with ⟨u, hu, u_anti⟩ have := ((hu.prod_nhds hu).tendsto_iff hu).mp (by simpa only [mul_one] using continuous_mul.tendsto ((1, 1) : G × G)) simp only [and_self_iff, mem_prod, and_imp, Prod.forall, exists_true_left, Prod.exists, forall_true_left] at this have event_mul : ∀ n : ℕ, ∀ᶠ m in atTop, u m * u m ⊆ u n := by intro n rcases this n with ⟨j, k, -, h⟩ refine atTop_basis.eventually_iff.mpr ⟨max j k, True.intro, fun m hm => ?_⟩ rintro - ⟨a, ha, b, hb, rfl⟩ exact h a b (u_anti ((le_max_left _ _).trans hm) ha) (u_anti ((le_max_right _ _).trans hm) hb) obtain ⟨φ, -, hφ, φ_anti_basis⟩ := HasAntitoneBasis.subbasis_with_rel ⟨hu, u_anti⟩ event_mul exact ⟨u ∘ φ, φ_anti_basis, fun n => hφ n.lt_succ_self⟩ end IsTopologicalGroup section ContinuousDiv variable [TopologicalSpace G] [Div G] [ContinuousDiv G] @[to_additive const_sub] theorem Filter.Tendsto.const_div' (b : G) {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) : Tendsto (fun k : α => b / f k) l (𝓝 (b / c)) := tendsto_const_nhds.div' h @[to_additive] lemma Filter.tendsto_const_div_iff {G : Type*} [CommGroup G] [TopologicalSpace G] [ContinuousDiv G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (fun k : α ↦ b / f k) l (𝓝 (b / c)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, Filter.Tendsto.const_div' b⟩ convert h.const_div' b with k <;> rw [div_div_cancel] @[to_additive sub_const] theorem Filter.Tendsto.div_const' {c : G} {f : α → G} {l : Filter α} (h : Tendsto f l (𝓝 c)) (b : G) : Tendsto (f · / b) l (𝓝 (c / b)) := h.div' tendsto_const_nhds lemma Filter.tendsto_div_const_iff {G : Type*} [CommGroupWithZero G] [TopologicalSpace G] [ContinuousDiv G] {b : G} (hb : b ≠ 0) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · / b) l (𝓝 (c / b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.div_const' h b⟩ convert h.div_const' b⁻¹ with k <;> rw [div_div, mul_inv_cancel₀ hb, div_one] lemma Filter.tendsto_sub_const_iff {G : Type*} [AddCommGroup G] [TopologicalSpace G] [ContinuousSub G] (b : G) {c : G} {f : α → G} {l : Filter α} : Tendsto (f · - b) l (𝓝 (c - b)) ↔ Tendsto f l (𝓝 c) := by refine ⟨fun h ↦ ?_, fun h ↦ Filter.Tendsto.sub_const h b⟩ convert h.sub_const (-b) with k <;> rw [sub_sub, ← sub_eq_add_neg, sub_self, sub_zero] variable [TopologicalSpace α] {f g : α → G} {s : Set α} {x : α} @[to_additive (attr := continuity) continuous_sub_left] lemma continuous_div_left' (a : G) : Continuous (a / ·) := continuous_const.div' continuous_id @[to_additive (attr := continuity) continuous_sub_right] lemma continuous_div_right' (a : G) : Continuous (· / a) := continuous_id.div' continuous_const end ContinuousDiv section DivInvTopologicalGroup variable [Group G] [TopologicalSpace G] [IsTopologicalGroup G] /-- A version of `Homeomorph.mulLeft a b⁻¹` that is defeq to `a / b`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addLeft a (-b)` that is defeq to `a - b`."] def Homeomorph.divLeft (x : G) : G ≃ₜ G := { Equiv.divLeft x with continuous_toFun := continuous_const.div' continuous_id continuous_invFun := continuous_inv.mul continuous_const } @[to_additive] theorem isOpenMap_div_left (a : G) : IsOpenMap (a / ·) := (Homeomorph.divLeft _).isOpenMap @[to_additive] theorem isClosedMap_div_left (a : G) : IsClosedMap (a / ·) := (Homeomorph.divLeft _).isClosedMap /-- A version of `Homeomorph.mulRight a⁻¹ b` that is defeq to `b / a`. -/ @[to_additive (attr := simps! +simpRhs) "A version of `Homeomorph.addRight (-a) b` that is defeq to `b - a`. "] def Homeomorph.divRight (x : G) : G ≃ₜ G := { Equiv.divRight x with continuous_toFun := continuous_id.div' continuous_const continuous_invFun := continuous_id.mul continuous_const } @[to_additive] lemma isOpenMap_div_right (a : G) : IsOpenMap (· / a) := (Homeomorph.divRight a).isOpenMap @[to_additive] lemma isClosedMap_div_right (a : G) : IsClosedMap (· / a) := (Homeomorph.divRight a).isClosedMap @[to_additive] theorem tendsto_div_nhds_one_iff {α : Type*} {l : Filter α} {x : G} {u : α → G} : Tendsto (u · / x) l (𝓝 1) ↔ Tendsto u l (𝓝 x) := haveI A : Tendsto (fun _ : α => x) l (𝓝 x) := tendsto_const_nhds ⟨fun h => by simpa using h.mul A, fun h => by simpa using h.div' A⟩ @[to_additive] theorem nhds_translation_div (x : G) : comap (· / x) (𝓝 1) = 𝓝 x := by simpa only [div_eq_mul_inv] using nhds_translation_mul_inv x end DivInvTopologicalGroup section FilterMul section variable (G) [TopologicalSpace G] [Group G] [ContinuousMul G] @[to_additive] theorem IsTopologicalGroup.t1Space (h : @IsClosed G _ {1}) : T1Space G := ⟨fun x => by simpa using isClosedMap_mul_right x _ h⟩ end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] variable (S : Subgroup G) [Subgroup.Normal S] [IsClosed (S : Set G)] /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the left, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`."] theorem Subgroup.properlyDiscontinuousSMul_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S G := { finite_disjoint_inter_image := by intro K L hK hL have H : Set.Finite _ := hS ((hL.prod hK).image continuous_div').compl_mem_cocompact rw [preimage_compl, compl_compl] at H convert H ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.smul_inter_ne_empty_iff' } /-- A subgroup `S` of a topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousSMul_of_t2Space` to show that the quotient group `G ⧸ S` is Hausdorff. -/ @[to_additive "A subgroup `S` of an additive topological group `G` acts on `G` properly discontinuously on the right, if it is discrete in the sense that `S ∩ K` is finite for all compact `K`. (See also `DiscreteTopology`.) If `G` is Hausdorff, this can be combined with `t2Space_of_properlyDiscontinuousVAdd_of_t2Space` to show that the quotient group `G ⧸ S` is Hausdorff."] theorem Subgroup.properlyDiscontinuousSMul_opposite_of_tendsto_cofinite (S : Subgroup G) (hS : Tendsto S.subtype cofinite (cocompact G)) : ProperlyDiscontinuousSMul S.op G := { finite_disjoint_inter_image := by intro K L hK hL have : Continuous fun p : G × G => (p.1⁻¹, p.2) := continuous_inv.prodMap continuous_id have H : Set.Finite _ := hS ((hK.prod hL).image (continuous_mul.comp this)).compl_mem_cocompact simp only [preimage_compl, compl_compl, coe_subtype, comp_apply] at H apply Finite.of_preimage _ (equivOp S).surjective convert H using 1 ext x simp only [image_smul, mem_setOf_eq, coe_subtype, mem_preimage, mem_image, Prod.exists] exact Set.op_smul_inter_ne_empty_iff } end section /-! Some results about an open set containing the product of two sets in a topological group. -/ variable [TopologicalSpace G] [MulOneClass G] [ContinuousMul G] /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `K * V ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `K + V ⊆ U`."] theorem compact_open_separated_mul_right {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), K * V ⊆ U := by refine hK.induction_on ?_ ?_ ?_ ?_ · exact ⟨univ, by simp⟩ · rintro s t hst ⟨V, hV, hV'⟩ exact ⟨V, hV, (mul_subset_mul_right hst).trans hV'⟩ · rintro s t ⟨V, V_in, hV'⟩ ⟨W, W_in, hW'⟩ use V ∩ W, inter_mem V_in W_in rw [union_mul] exact union_subset ((mul_subset_mul_left V.inter_subset_left).trans hV') ((mul_subset_mul_left V.inter_subset_right).trans hW') · intro x hx have := tendsto_mul (show U ∈ 𝓝 (x * 1) by simpa using hU.mem_nhds (hKU hx)) rw [nhds_prod_eq, mem_map, mem_prod_iff] at this rcases this with ⟨t, ht, s, hs, h⟩ rw [← image_subset_iff, image_mul_prod] at h exact ⟨t, mem_nhdsWithin_of_mem_nhds ht, s, hs, h⟩ open MulOpposite /-- Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `1` such that `V * K ⊆ U`. -/ @[to_additive "Given a compact set `K` inside an open set `U`, there is an open neighborhood `V` of `0` such that `V + K ⊆ U`."] theorem compact_open_separated_mul_left {K U : Set G} (hK : IsCompact K) (hU : IsOpen U) (hKU : K ⊆ U) : ∃ V ∈ 𝓝 (1 : G), V * K ⊆ U := by rcases compact_open_separated_mul_right (hK.image continuous_op) (opHomeomorph.isOpenMap U hU) (image_subset op hKU) with ⟨V, hV : V ∈ 𝓝 (op (1 : G)), hV' : op '' K * V ⊆ op '' U⟩ refine ⟨op ⁻¹' V, continuous_op.continuousAt hV, ?_⟩ rwa [← image_preimage_eq V op_surjective, ← image_op_mul, image_subset_iff, preimage_image_eq _ op_injective] at hV' end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] /-- A compact set is covered by finitely many left multiplicative translates of a set with non-empty interior. -/ @[to_additive "A compact set is covered by finitely many left additive translates of a set with non-empty interior."] theorem compact_covered_by_mul_left_translates {K V : Set G} (hK : IsCompact K) (hV : (interior V).Nonempty) : ∃ t : Finset G, K ⊆ ⋃ g ∈ t, (g * ·) ⁻¹' V := by obtain ⟨t, ht⟩ : ∃ t : Finset G, K ⊆ ⋃ x ∈ t, interior ((x * ·) ⁻¹' V) := by refine hK.elim_finite_subcover (fun x => interior <| (x * ·) ⁻¹' V) (fun x => isOpen_interior) ?_ obtain ⟨g₀, hg₀⟩ := hV refine fun g _ => mem_iUnion.2 ⟨g₀ * g⁻¹, ?_⟩ refine preimage_interior_subset_interior_preimage (continuous_const.mul continuous_id) ?_ rwa [mem_preimage, Function.id_def, inv_mul_cancel_right] exact ⟨t, Subset.trans ht <| iUnion₂_mono fun g _ => interior_subset⟩ /-- Every weakly locally compact separable topological group is σ-compact. Note: this is not true if we drop the topological group hypothesis. -/ @[to_additive SeparableWeaklyLocallyCompactAddGroup.sigmaCompactSpace "Every weakly locally compact separable topological additive group is σ-compact. Note: this is not true if we drop the topological group hypothesis."] instance (priority := 100) SeparableWeaklyLocallyCompactGroup.sigmaCompactSpace [SeparableSpace G] [WeaklyLocallyCompactSpace G] : SigmaCompactSpace G := by obtain ⟨L, hLc, hL1⟩ := exists_compact_mem_nhds (1 : G) refine ⟨⟨fun n => (fun x => x * denseSeq G n) ⁻¹' L, ?_, ?_⟩⟩ · intro n exact (Homeomorph.mulRight _).isCompact_preimage.mpr hLc · refine iUnion_eq_univ_iff.2 fun x => ?_ obtain ⟨_, ⟨n, rfl⟩, hn⟩ : (range (denseSeq G) ∩ (fun y => x * y) ⁻¹' L).Nonempty := by rw [← (Homeomorph.mulLeft x).apply_symm_apply 1] at hL1 exact (denseRange_denseSeq G).inter_nhds_nonempty ((Homeomorph.mulLeft x).continuous.continuousAt <| hL1) exact ⟨n, hn⟩ /-- Given two compact sets in a noncompact topological group, there is a translate of the second one that is disjoint from the first one. -/ @[to_additive "Given two compact sets in a noncompact additive topological group, there is a translate of the second one that is disjoint from the first one."] theorem exists_disjoint_smul_of_isCompact [NoncompactSpace G] {K L : Set G} (hK : IsCompact K) (hL : IsCompact L) : ∃ g : G, Disjoint K (g • L) := by have A : ¬K * L⁻¹ = univ := (hK.mul hL.inv).ne_univ obtain ⟨g, hg⟩ : ∃ g, g ∉ K * L⁻¹ := by contrapose! A exact eq_univ_iff_forall.2 A refine ⟨g, ?_⟩ refine disjoint_left.2 fun a ha h'a => hg ?_ rcases h'a with ⟨b, bL, rfl⟩ refine ⟨g * b, ha, b⁻¹, by simpa only [Set.mem_inv, inv_inv] using bL, ?_⟩ simp only [smul_eq_mul, mul_inv_cancel_right] end section variable [TopologicalSpace G] [Group G] [IsTopologicalGroup G] @[to_additive] theorem nhds_mul (x y : G) : 𝓝 (x * y) = 𝓝 x * 𝓝 y := calc 𝓝 (x * y) = map (x * ·) (map (· * y) (𝓝 1 * 𝓝 1)) := by simp _ = map₂ (fun a b => x * (a * b * y)) (𝓝 1) (𝓝 1) := by rw [← map₂_mul, map_map₂, map_map₂] _ = map₂ (fun a b => x * a * (b * y)) (𝓝 1) (𝓝 1) := by simp only [mul_assoc] _ = 𝓝 x * 𝓝 y := by rw [← map_mul_left_nhds_one x, ← map_mul_right_nhds_one y, ← map₂_mul, map₂_map_left, map₂_map_right] /-- On a topological group, `𝓝 : G → Filter G` can be promoted to a `MulHom`. -/ @[to_additive (attr := simps) "On an additive topological group, `𝓝 : G → Filter G` can be promoted to an `AddHom`."] def nhdsMulHom : G →ₙ* Filter G where toFun := 𝓝 map_mul' _ _ := nhds_mul _ _ end end FilterMul instance {G} [TopologicalSpace G] [Group G] [IsTopologicalGroup G] : IsTopologicalAddGroup (Additive G) where continuous_neg := @continuous_inv G _ _ _ instance {G} [TopologicalSpace G] [AddGroup G] [IsTopologicalAddGroup G] : IsTopologicalGroup (Multiplicative G) where continuous_inv := @continuous_neg G _ _ _ /-- If `G` is a group with topological `⁻¹`, then it is homeomorphic to its units. -/ @[to_additive "If `G` is an additive group with topological negation, then it is homeomorphic to its additive units."] def toUnits_homeomorph [Group G] [TopologicalSpace G] [ContinuousInv G] : G ≃ₜ Gˣ where toEquiv := toUnits.toEquiv continuous_toFun := Units.continuous_iff.2 ⟨continuous_id, continuous_inv⟩ continuous_invFun := Units.continuous_val @[to_additive] theorem Units.isEmbedding_val [Group G] [TopologicalSpace G] [ContinuousInv G] : IsEmbedding (val : Gˣ → G) := toUnits_homeomorph.symm.isEmbedding @[deprecated (since := "2024-10-26")] alias Units.embedding_val := Units.isEmbedding_val lemma Continuous.of_coeHom_comp [Group G] [Monoid H] [TopologicalSpace G] [TopologicalSpace H] [ContinuousInv G] {f : G →* Hˣ} (hf : Continuous ((Units.coeHom H).comp f)) : Continuous f := by apply continuous_induced_rng.mpr ?_ refine continuous_prodMk.mpr ⟨hf, ?_⟩ simp_rw [← map_inv] exact MulOpposite.continuous_op.comp (hf.comp continuous_inv) namespace Units open MulOpposite (continuous_op continuous_unop) variable [Monoid α] [TopologicalSpace α] [Monoid β] [TopologicalSpace β] @[to_additive] instance [ContinuousMul α] : IsTopologicalGroup αˣ where continuous_inv := Units.continuous_iff.2 <| ⟨continuous_coe_inv, continuous_val⟩ /-- The topological group isomorphism between the units of a product of two monoids, and the product of the units of each monoid. -/ @[to_additive prodAddUnits "The topological group isomorphism between the additive units of a product of two additive monoids, and the product of the additive units of each additive monoid."] def _root_.Homeomorph.prodUnits : (α × β)ˣ ≃ₜ αˣ × βˣ where continuous_toFun := (continuous_fst.units_map (MonoidHom.fst α β)).prodMk (continuous_snd.units_map (MonoidHom.snd α β)) continuous_invFun := Units.continuous_iff.2 ⟨continuous_val.fst'.prodMk continuous_val.snd', continuous_coe_inv.fst'.prodMk continuous_coe_inv.snd'⟩ toEquiv := MulEquiv.prodUnits.toEquiv @[deprecated (since := "2025-02-21")] alias Homeomorph.sumAddUnits := Homeomorph.prodAddUnits @[deprecated (since := "2025-02-21")] protected alias Homeomorph.prodUnits := Homeomorph.prodUnits end Units section LatticeOps variable {ι : Sort*} [Group G] @[to_additive] theorem topologicalGroup_sInf {ts : Set (TopologicalSpace G)} (h : ∀ t ∈ ts, @IsTopologicalGroup G t _) : @IsTopologicalGroup G (sInf ts) _ := letI := sInf ts { toContinuousInv := @continuousInv_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousInv G t _ <| h t ht toContinuousMul := @continuousMul_sInf _ _ _ fun t ht => @IsTopologicalGroup.toContinuousMul G t _ <| h t ht } @[to_additive] theorem topologicalGroup_iInf {ts' : ι → TopologicalSpace G} (h' : ∀ i, @IsTopologicalGroup G (ts' i) _) : @IsTopologicalGroup G (⨅ i, ts' i) _ := by rw [← sInf_range] exact topologicalGroup_sInf (Set.forall_mem_range.mpr h') @[to_additive] theorem topologicalGroup_inf {t₁ t₂ : TopologicalSpace G} (h₁ : @IsTopologicalGroup G t₁ _) (h₂ : @IsTopologicalGroup G t₂ _) : @IsTopologicalGroup G (t₁ ⊓ t₂) _ := by rw [inf_eq_iInf] refine topologicalGroup_iInf fun b => ?_ cases b <;> assumption end LatticeOps
Mathlib/Topology/Algebra/Group/Basic.lean
1,880
1,890
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.Measure.Comap import Mathlib.MeasureTheory.Measure.QuasiMeasurePreserving /-! # Restricting a measure to a subset or a subtype Given a measure `μ` on a type `α` and a subset `s` of `α`, we define a measure `μ.restrict s` as the restriction of `μ` to `s` (still as a measure on `α`). We investigate how this notion interacts with usual operations on measures (sum, pushforward, pullback), and on sets (inclusion, union, Union). We also study the relationship between the restriction of a measure to a subtype (given by the pullback under `Subtype.val`) and the restriction to a set as above. -/ open scoped ENNReal NNReal Topology open Set MeasureTheory Measure Filter MeasurableSpace ENNReal Function variable {R α β δ γ ι : Type*} namespace MeasureTheory variable {m0 : MeasurableSpace α} [MeasurableSpace β] [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-! ### Restricting a measure -/ /-- Restrict a measure `μ` to a set `s` as an `ℝ≥0∞`-linear map. -/ noncomputable def restrictₗ {m0 : MeasurableSpace α} (s : Set α) : Measure α →ₗ[ℝ≥0∞] Measure α := liftLinear (OuterMeasure.restrict s) fun μ s' hs' t => by suffices μ (s ∩ t) = μ (s ∩ t ∩ s') + μ ((s ∩ t) \ s') by simpa [← Set.inter_assoc, Set.inter_comm _ s, ← inter_diff_assoc] exact le_toOuterMeasure_caratheodory _ _ hs' _ /-- Restrict a measure `μ` to a set `s`. -/ noncomputable def restrict {_m0 : MeasurableSpace α} (μ : Measure α) (s : Set α) : Measure α := restrictₗ s μ @[simp] theorem restrictₗ_apply {_m0 : MeasurableSpace α} (s : Set α) (μ : Measure α) : restrictₗ s μ = μ.restrict s := rfl /-- This lemma shows that `restrict` and `toOuterMeasure` commute. Note that the LHS has a restrict on measures and the RHS has a restrict on outer measures. -/ theorem restrict_toOuterMeasure_eq_toOuterMeasure_restrict (h : MeasurableSet s) : (μ.restrict s).toOuterMeasure = OuterMeasure.restrict s μ.toOuterMeasure := by simp_rw [restrict, restrictₗ, liftLinear, LinearMap.coe_mk, AddHom.coe_mk, toMeasure_toOuterMeasure, OuterMeasure.restrict_trim h, μ.trimmed] theorem restrict_apply₀ (ht : NullMeasurableSet t (μ.restrict s)) : μ.restrict s t = μ (t ∩ s) := by rw [← restrictₗ_apply, restrictₗ, liftLinear_apply₀ _ ht, OuterMeasure.restrict_apply, coe_toOuterMeasure] /-- If `t` is a measurable set, then the measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. An alternate version requiring that `s` be measurable instead of `t` exists as `Measure.restrict_apply'`. -/ @[simp] theorem restrict_apply (ht : MeasurableSet t) : μ.restrict s t = μ (t ∩ s) := restrict_apply₀ ht.nullMeasurableSet /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ theorem restrict_mono' {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ ⦃μ ν : Measure α⦄ (hs : s ≤ᵐ[μ] s') (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ (t ∩ s') := (measure_mono_ae <| hs.mono fun _x hx ⟨hxt, hxs⟩ => ⟨hxt, hx hxs⟩) _ ≤ ν (t ∩ s') := le_iff'.1 hμν (t ∩ s') _ = ν.restrict s' t := (restrict_apply ht).symm /-- Restriction of a measure to a subset is monotone both in set and in measure. -/ @[mono, gcongr] theorem restrict_mono {_m0 : MeasurableSpace α} ⦃s s' : Set α⦄ (hs : s ⊆ s') ⦃μ ν : Measure α⦄ (hμν : μ ≤ ν) : μ.restrict s ≤ ν.restrict s' := restrict_mono' (ae_of_all _ hs) hμν @[gcongr] theorem restrict_mono_measure {_ : MeasurableSpace α} {μ ν : Measure α} (h : μ ≤ ν) (s : Set α) : μ.restrict s ≤ ν.restrict s := restrict_mono subset_rfl h @[gcongr] theorem restrict_mono_set {_ : MeasurableSpace α} (μ : Measure α) {s t : Set α} (h : s ⊆ t) : μ.restrict s ≤ μ.restrict t := restrict_mono h le_rfl theorem restrict_mono_ae (h : s ≤ᵐ[μ] t) : μ.restrict s ≤ μ.restrict t := restrict_mono' h (le_refl μ) theorem restrict_congr_set (h : s =ᵐ[μ] t) : μ.restrict s = μ.restrict t := le_antisymm (restrict_mono_ae h.le) (restrict_mono_ae h.symm.le) /-- If `s` is a measurable set, then the outer measure of `t` with respect to the restriction of the measure to `s` equals the outer measure of `t ∩ s`. This is an alternate version of `Measure.restrict_apply`, requiring that `s` is measurable instead of `t`. -/ @[simp] theorem restrict_apply' (hs : MeasurableSet s) : μ.restrict s t = μ (t ∩ s) := by rw [← toOuterMeasure_apply, Measure.restrict_toOuterMeasure_eq_toOuterMeasure_restrict hs, OuterMeasure.restrict_apply s t _, toOuterMeasure_apply] theorem restrict_apply₀' (hs : NullMeasurableSet s μ) : μ.restrict s t = μ (t ∩ s) := by rw [← restrict_congr_set hs.toMeasurable_ae_eq, restrict_apply' (measurableSet_toMeasurable _ _), measure_congr ((ae_eq_refl t).inter hs.toMeasurable_ae_eq)] theorem restrict_le_self : μ.restrict s ≤ μ := Measure.le_iff.2 fun t ht => calc μ.restrict s t = μ (t ∩ s) := restrict_apply ht _ ≤ μ t := measure_mono inter_subset_left variable (μ) theorem restrict_eq_self (h : s ⊆ t) : μ.restrict t s = μ s := (le_iff'.1 restrict_le_self s).antisymm <| calc μ s ≤ μ (toMeasurable (μ.restrict t) s ∩ t) := measure_mono (subset_inter (subset_toMeasurable _ _) h) _ = μ.restrict t s := by rw [← restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] @[simp] theorem restrict_apply_self (s : Set α) : (μ.restrict s) s = μ s := restrict_eq_self μ Subset.rfl variable {μ} theorem restrict_apply_univ (s : Set α) : μ.restrict s univ = μ s := by rw [restrict_apply MeasurableSet.univ, Set.univ_inter] theorem le_restrict_apply (s t : Set α) : μ (t ∩ s) ≤ μ.restrict s t := calc μ (t ∩ s) = μ.restrict s (t ∩ s) := (restrict_eq_self μ inter_subset_right).symm _ ≤ μ.restrict s t := measure_mono inter_subset_left theorem restrict_apply_le (s t : Set α) : μ.restrict s t ≤ μ t := Measure.le_iff'.1 restrict_le_self _ theorem restrict_apply_superset (h : s ⊆ t) : μ.restrict s t = μ s := ((measure_mono (subset_univ _)).trans_eq <| restrict_apply_univ _).antisymm ((restrict_apply_self μ s).symm.trans_le <| measure_mono h) @[simp] theorem restrict_add {_m0 : MeasurableSpace α} (μ ν : Measure α) (s : Set α) : (μ + ν).restrict s = μ.restrict s + ν.restrict s := (restrictₗ s).map_add μ ν @[simp] theorem restrict_zero {_m0 : MeasurableSpace α} (s : Set α) : (0 : Measure α).restrict s = 0 := (restrictₗ s).map_zero @[simp] theorem restrict_smul {_m0 : MeasurableSpace α} {R : Type*} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) (μ : Measure α) (s : Set α) : (c • μ).restrict s = c • μ.restrict s := by simpa only [smul_one_smul] using (restrictₗ s).map_smul (c • 1) μ theorem restrict_restrict₀ (hs : NullMeasurableSet s (μ.restrict t)) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [Set.inter_assoc, restrict_apply hu, restrict_apply₀ (hu.nullMeasurableSet.inter hs)] @[simp] theorem restrict_restrict (hs : MeasurableSet s) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀ hs.nullMeasurableSet theorem restrict_restrict_of_subset (h : s ⊆ t) : (μ.restrict t).restrict s = μ.restrict s := by ext1 u hu rw [restrict_apply hu, restrict_apply hu, restrict_eq_self] exact inter_subset_right.trans h theorem restrict_restrict₀' (ht : NullMeasurableSet t μ) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := ext fun u hu => by simp only [restrict_apply hu, restrict_apply₀' ht, inter_assoc] theorem restrict_restrict' (ht : MeasurableSet t) : (μ.restrict t).restrict s = μ.restrict (s ∩ t) := restrict_restrict₀' ht.nullMeasurableSet theorem restrict_comm (hs : MeasurableSet s) : (μ.restrict t).restrict s = (μ.restrict s).restrict t := by rw [restrict_restrict hs, restrict_restrict' hs, inter_comm] theorem restrict_apply_eq_zero (ht : MeasurableSet t) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply ht] theorem measure_inter_eq_zero_of_restrict (h : μ.restrict s t = 0) : μ (t ∩ s) = 0 := nonpos_iff_eq_zero.1 (h ▸ le_restrict_apply _ _) theorem restrict_apply_eq_zero' (hs : MeasurableSet s) : μ.restrict s t = 0 ↔ μ (t ∩ s) = 0 := by rw [restrict_apply' hs] @[simp] theorem restrict_eq_zero : μ.restrict s = 0 ↔ μ s = 0 := by rw [← measure_univ_eq_zero, restrict_apply_univ] /-- If `μ s ≠ 0`, then `μ.restrict s ≠ 0`, in terms of `NeZero` instances. -/ instance restrict.neZero [NeZero (μ s)] : NeZero (μ.restrict s) := ⟨mt restrict_eq_zero.mp <| NeZero.ne _⟩ theorem restrict_zero_set {s : Set α} (h : μ s = 0) : μ.restrict s = 0 := restrict_eq_zero.2 h @[simp] theorem restrict_empty : μ.restrict ∅ = 0 := restrict_zero_set measure_empty @[simp] theorem restrict_univ : μ.restrict univ = μ := ext fun s hs => by simp [hs] theorem restrict_inter_add_diff₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := by ext1 u hu simp only [add_apply, restrict_apply hu, ← inter_assoc, diff_eq] exact measure_inter_add_diff₀ (u ∩ s) ht theorem restrict_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∩ t) + μ.restrict (s \ t) = μ.restrict s := restrict_inter_add_diff₀ s ht.nullMeasurableSet theorem restrict_union_add_inter₀ (s : Set α) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by rw [← restrict_inter_add_diff₀ (s ∪ t) ht, union_inter_cancel_right, union_diff_right, ← restrict_inter_add_diff₀ s ht, add_comm, ← add_assoc, add_right_comm] theorem restrict_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := restrict_union_add_inter₀ s ht.nullMeasurableSet theorem restrict_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ.restrict (s ∪ t) + μ.restrict (s ∩ t) = μ.restrict s + μ.restrict t := by simpa only [union_comm, inter_comm, add_comm] using restrict_union_add_inter t hs theorem restrict_union₀ (h : AEDisjoint μ s t) (ht : NullMeasurableSet t μ) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by simp [← restrict_union_add_inter₀ s ht, restrict_zero_set h] theorem restrict_union (h : Disjoint s t) (ht : MeasurableSet t) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := restrict_union₀ h.aedisjoint ht.nullMeasurableSet theorem restrict_union' (h : Disjoint s t) (hs : MeasurableSet s) : μ.restrict (s ∪ t) = μ.restrict s + μ.restrict t := by rw [union_comm, restrict_union h.symm hs, add_comm] @[simp] theorem restrict_add_restrict_compl (hs : MeasurableSet s) : μ.restrict s + μ.restrict sᶜ = μ := by rw [← restrict_union (@disjoint_compl_right (Set α) _ _) hs.compl, union_compl_self, restrict_univ] @[simp] theorem restrict_compl_add_restrict (hs : MeasurableSet s) : μ.restrict sᶜ + μ.restrict s = μ := by rw [add_comm, restrict_add_restrict_compl hs] theorem restrict_union_le (s s' : Set α) : μ.restrict (s ∪ s') ≤ μ.restrict s + μ.restrict s' := le_iff.2 fun t ht ↦ by simpa [ht, inter_union_distrib_left] using measure_union_le (t ∩ s) (t ∩ s') theorem restrict_iUnion_apply_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := by simp only [restrict_apply, ht, inter_iUnion] exact measure_iUnion₀ (hd.mono fun i j h => h.mono inter_subset_right inter_subset_right) fun i => ht.nullMeasurableSet.inter (hm i) theorem restrict_iUnion_apply [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ∑' i, μ.restrict (s i) t := restrict_iUnion_apply_ae hd.aedisjoint (fun i => (hm i).nullMeasurableSet) ht theorem restrict_iUnion_apply_eq_iSup [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) {t : Set α} (ht : MeasurableSet t) : μ.restrict (⋃ i, s i) t = ⨆ i, μ.restrict (s i) t := by simp only [restrict_apply ht, inter_iUnion] rw [Directed.measure_iUnion] exacts [hd.mono_comp _ fun s₁ s₂ => inter_subset_inter_right _] /-- The restriction of the pushforward measure is the pushforward of the restriction. For a version assuming only `AEMeasurable`, see `restrict_map_of_aemeasurable`. -/ theorem restrict_map {f : α → β} (hf : Measurable f) {s : Set β} (hs : MeasurableSet s) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f := ext fun t ht => by simp [*, hf ht] theorem restrict_toMeasurable (h : μ s ≠ ∞) : μ.restrict (toMeasurable μ s) = μ.restrict s := ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, inter_comm, measure_toMeasurable_inter ht h, inter_comm] theorem restrict_eq_self_of_ae_mem {_m0 : MeasurableSpace α} ⦃s : Set α⦄ ⦃μ : Measure α⦄ (hs : ∀ᵐ x ∂μ, x ∈ s) : μ.restrict s = μ := calc μ.restrict s = μ.restrict univ := restrict_congr_set (eventuallyEq_univ.mpr hs) _ = μ := restrict_univ theorem restrict_congr_meas (hs : MeasurableSet s) : μ.restrict s = ν.restrict s ↔ ∀ t ⊆ s, MeasurableSet t → μ t = ν t := ⟨fun H t hts ht => by rw [← inter_eq_self_of_subset_left hts, ← restrict_apply ht, H, restrict_apply ht], fun H => ext fun t ht => by rw [restrict_apply ht, restrict_apply ht, H _ inter_subset_right (ht.inter hs)]⟩ theorem restrict_congr_mono (hs : s ⊆ t) (h : μ.restrict t = ν.restrict t) : μ.restrict s = ν.restrict s := by rw [← restrict_restrict_of_subset hs, h, restrict_restrict_of_subset hs] /-- If two measures agree on all measurable subsets of `s` and `t`, then they agree on all measurable subsets of `s ∪ t`. -/ theorem restrict_union_congr : μ.restrict (s ∪ t) = ν.restrict (s ∪ t) ↔ μ.restrict s = ν.restrict s ∧ μ.restrict t = ν.restrict t := by refine ⟨fun h ↦ ⟨restrict_congr_mono subset_union_left h, restrict_congr_mono subset_union_right h⟩, ?_⟩ rintro ⟨hs, ht⟩ ext1 u hu simp only [restrict_apply hu, inter_union_distrib_left] rcases exists_measurable_superset₂ μ ν (u ∩ s) with ⟨US, hsub, hm, hμ, hν⟩ calc μ (u ∩ s ∪ u ∩ t) = μ (US ∪ u ∩ t) := measure_union_congr_of_subset hsub hμ.le Subset.rfl le_rfl _ = μ US + μ ((u ∩ t) \ US) := (measure_add_diff hm.nullMeasurableSet _).symm _ = restrict μ s u + restrict μ t (u \ US) := by simp only [restrict_apply, hu, hu.diff hm, hμ, ← inter_comm t, inter_diff_assoc] _ = restrict ν s u + restrict ν t (u \ US) := by rw [hs, ht] _ = ν US + ν ((u ∩ t) \ US) := by simp only [restrict_apply, hu, hu.diff hm, hν, ← inter_comm t, inter_diff_assoc] _ = ν (US ∪ u ∩ t) := measure_add_diff hm.nullMeasurableSet _ _ = ν (u ∩ s ∪ u ∩ t) := .symm <| measure_union_congr_of_subset hsub hν.le Subset.rfl le_rfl theorem restrict_finset_biUnion_congr {s : Finset ι} {t : ι → Set α} : μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔ ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by classical induction' s using Finset.induction_on with i s _ hs; · simp simp only [forall_eq_or_imp, iUnion_iUnion_eq_or_left, Finset.mem_insert] rw [restrict_union_congr, ← hs] theorem restrict_iUnion_congr [Countable ι] {s : ι → Set α} : μ.restrict (⋃ i, s i) = ν.restrict (⋃ i, s i) ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by refine ⟨fun h i => restrict_congr_mono (subset_iUnion _ _) h, fun h => ?_⟩ ext1 t ht have D : Directed (· ⊆ ·) fun t : Finset ι => ⋃ i ∈ t, s i := Monotone.directed_le fun t₁ t₂ ht => biUnion_subset_biUnion_left ht rw [iUnion_eq_iUnion_finset] simp only [restrict_iUnion_apply_eq_iSup D ht, restrict_finset_biUnion_congr.2 fun i _ => h i] theorem restrict_biUnion_congr {s : Set ι} {t : ι → Set α} (hc : s.Countable) : μ.restrict (⋃ i ∈ s, t i) = ν.restrict (⋃ i ∈ s, t i) ↔ ∀ i ∈ s, μ.restrict (t i) = ν.restrict (t i) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, SetCoe.forall', restrict_iUnion_congr] theorem restrict_sUnion_congr {S : Set (Set α)} (hc : S.Countable) : μ.restrict (⋃₀ S) = ν.restrict (⋃₀ S) ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := by rw [sUnion_eq_biUnion, restrict_biUnion_congr hc] /-- This lemma shows that `Inf` and `restrict` commute for measures. -/ theorem restrict_sInf_eq_sInf_restrict {m0 : MeasurableSpace α} {m : Set (Measure α)} (hm : m.Nonempty) (ht : MeasurableSet t) : (sInf m).restrict t = sInf ((fun μ : Measure α => μ.restrict t) '' m) := by ext1 s hs simp_rw [sInf_apply hs, restrict_apply hs, sInf_apply (MeasurableSet.inter hs ht), Set.image_image, restrict_toOuterMeasure_eq_toOuterMeasure_restrict ht, ← Set.image_image _ toOuterMeasure, ← OuterMeasure.restrict_sInf_eq_sInf_restrict _ (hm.image _), OuterMeasure.restrict_apply] theorem exists_mem_of_measure_ne_zero_of_ae (hs : μ s ≠ 0) {p : α → Prop} (hp : ∀ᵐ x ∂μ.restrict s, p x) : ∃ x, x ∈ s ∧ p x := by rw [← μ.restrict_apply_self, ← frequently_ae_mem_iff] at hs exact (hs.and_eventually hp).exists /-- If a quasi measure preserving map `f` maps a set `s` to a set `t`, then it is quasi measure preserving with respect to the restrictions of the measures. -/ theorem QuasiMeasurePreserving.restrict {ν : Measure β} {f : α → β} (hf : QuasiMeasurePreserving f μ ν) {t : Set β} (hmaps : MapsTo f s t) : QuasiMeasurePreserving f (μ.restrict s) (ν.restrict t) where measurable := hf.measurable absolutelyContinuous := by refine AbsolutelyContinuous.mk fun u hum ↦ ?_ suffices ν (u ∩ t) = 0 → μ (f ⁻¹' u ∩ s) = 0 by simpa [hum, hf.measurable, hf.measurable hum] refine fun hu ↦ measure_mono_null ?_ (hf.preimage_null hu) rw [preimage_inter] gcongr assumption /-! ### Extensionality results -/ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `Union`). -/ theorem ext_iff_of_iUnion_eq_univ [Countable ι] {s : ι → Set α} (hs : ⋃ i, s i = univ) : μ = ν ↔ ∀ i, μ.restrict (s i) = ν.restrict (s i) := by rw [← restrict_iUnion_congr, hs, restrict_univ, restrict_univ] alias ⟨_, ext_of_iUnion_eq_univ⟩ := ext_iff_of_iUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `biUnion`). -/ theorem ext_iff_of_biUnion_eq_univ {S : Set ι} {s : ι → Set α} (hc : S.Countable) (hs : ⋃ i ∈ S, s i = univ) : μ = ν ↔ ∀ i ∈ S, μ.restrict (s i) = ν.restrict (s i) := by rw [← restrict_biUnion_congr hc, hs, restrict_univ, restrict_univ] alias ⟨_, ext_of_biUnion_eq_univ⟩ := ext_iff_of_biUnion_eq_univ /-- Two measures are equal if they have equal restrictions on a spanning collection of sets (formulated using `sUnion`). -/ theorem ext_iff_of_sUnion_eq_univ {S : Set (Set α)} (hc : S.Countable) (hs : ⋃₀ S = univ) : μ = ν ↔ ∀ s ∈ S, μ.restrict s = ν.restrict s := ext_iff_of_biUnion_eq_univ hc <| by rwa [← sUnion_eq_biUnion] alias ⟨_, ext_of_sUnion_eq_univ⟩ := ext_iff_of_sUnion_eq_univ theorem ext_of_generateFrom_of_cover {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S) (hc : T.Countable) (h_inter : IsPiSystem S) (hU : ⋃₀ T = univ) (htop : ∀ t ∈ T, μ t ≠ ∞) (ST_eq : ∀ t ∈ T, ∀ s ∈ S, μ (s ∩ t) = ν (s ∩ t)) (T_eq : ∀ t ∈ T, μ t = ν t) : μ = ν := by refine ext_of_sUnion_eq_univ hc hU fun t ht => ?_ ext1 u hu simp only [restrict_apply hu] induction u, hu using induction_on_inter h_gen h_inter with | empty => simp only [Set.empty_inter, measure_empty] | basic u hu => exact ST_eq _ ht _ hu | compl u hu ihu => have := T_eq t ht rw [Set.inter_comm] at ihu ⊢ rwa [← measure_inter_add_diff t hu, ← measure_inter_add_diff t hu, ← ihu, ENNReal.add_right_inj] at this exact ne_top_of_le_ne_top (htop t ht) (measure_mono Set.inter_subset_left) | iUnion f hfd hfm ihf => simp only [← restrict_apply (hfm _), ← restrict_apply (MeasurableSet.iUnion hfm)] at ihf ⊢ simp only [measure_iUnion hfd hfm, ihf] /-- Two measures are equal if they are equal on the π-system generating the σ-algebra, and they are both finite on an increasing spanning sequence of sets in the π-system. This lemma is formulated using `sUnion`. -/ theorem ext_of_generateFrom_of_cover_subset {S T : Set (Set α)} (h_gen : ‹_› = generateFrom S) (h_inter : IsPiSystem S) (h_sub : T ⊆ S) (hc : T.Countable) (hU : ⋃₀ T = univ) (htop : ∀ s ∈ T, μ s ≠ ∞) (h_eq : ∀ s ∈ S, μ s = ν s) : μ = ν := by refine ext_of_generateFrom_of_cover h_gen hc h_inter hU htop ?_ fun t ht => h_eq t (h_sub ht) intro t ht s hs; rcases (s ∩ t).eq_empty_or_nonempty with H | H · simp only [H, measure_empty] · exact h_eq _ (h_inter _ hs _ (h_sub ht) H) /-- Two measures are equal if they are equal on the π-system generating the σ-algebra, and they are both finite on an increasing spanning sequence of sets in the π-system. This lemma is formulated using `iUnion`. `FiniteSpanningSetsIn.ext` is a reformulation of this lemma. -/ theorem ext_of_generateFrom_of_iUnion (C : Set (Set α)) (B : ℕ → Set α) (hA : ‹_› = generateFrom C) (hC : IsPiSystem C) (h1B : ⋃ i, B i = univ) (h2B : ∀ i, B i ∈ C) (hμB : ∀ i, μ (B i) ≠ ∞) (h_eq : ∀ s ∈ C, μ s = ν s) : μ = ν := by refine ext_of_generateFrom_of_cover_subset hA hC ?_ (countable_range B) h1B ?_ h_eq · rintro _ ⟨i, rfl⟩ apply h2B · rintro _ ⟨i, rfl⟩ apply hμB @[simp] theorem restrict_sum (μ : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : (sum μ).restrict s = sum fun i => (μ i).restrict s := ext fun t ht => by simp only [sum_apply, restrict_apply, ht, ht.inter hs] @[simp] theorem restrict_sum_of_countable [Countable ι] (μ : ι → Measure α) (s : Set α) : (sum μ).restrict s = sum fun i => (μ i).restrict s := by ext t ht simp_rw [sum_apply _ ht, restrict_apply ht, sum_apply_of_countable] lemma AbsolutelyContinuous.restrict (h : μ ≪ ν) (s : Set α) : μ.restrict s ≪ ν.restrict s := by refine Measure.AbsolutelyContinuous.mk (fun t ht htν ↦ ?_) rw [restrict_apply ht] at htν ⊢ exact h htν theorem restrict_iUnion_ae [Countable ι] {s : ι → Set α} (hd : Pairwise (AEDisjoint μ on s)) (hm : ∀ i, NullMeasurableSet (s i) μ) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) := ext fun t ht => by simp only [sum_apply _ ht, restrict_iUnion_apply_ae hd hm ht] theorem restrict_iUnion [Countable ι] {s : ι → Set α} (hd : Pairwise (Disjoint on s)) (hm : ∀ i, MeasurableSet (s i)) : μ.restrict (⋃ i, s i) = sum fun i => μ.restrict (s i) := restrict_iUnion_ae hd.aedisjoint fun i => (hm i).nullMeasurableSet theorem restrict_iUnion_le [Countable ι] {s : ι → Set α} : μ.restrict (⋃ i, s i) ≤ sum fun i => μ.restrict (s i) := le_iff.2 fun t ht ↦ by simpa [ht, inter_iUnion] using measure_iUnion_le (t ∩ s ·) end Measure @[simp] theorem ae_restrict_iUnion_eq [Countable ι] (s : ι → Set α) : ae (μ.restrict (⋃ i, s i)) = ⨆ i, ae (μ.restrict (s i)) := le_antisymm ((ae_sum_eq fun i => μ.restrict (s i)) ▸ ae_mono restrict_iUnion_le) <| iSup_le fun i => ae_mono <| restrict_mono (subset_iUnion s i) le_rfl @[simp] theorem ae_restrict_union_eq (s t : Set α) : ae (μ.restrict (s ∪ t)) = ae (μ.restrict s) ⊔ ae (μ.restrict t) := by simp [union_eq_iUnion, iSup_bool_eq] theorem ae_restrict_biUnion_eq (s : ι → Set α) {t : Set ι} (ht : t.Countable) : ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := by haveI := ht.to_subtype rw [biUnion_eq_iUnion, ae_restrict_iUnion_eq, ← iSup_subtype''] theorem ae_restrict_biUnion_finset_eq (s : ι → Set α) (t : Finset ι) : ae (μ.restrict (⋃ i ∈ t, s i)) = ⨆ i ∈ t, ae (μ.restrict (s i)) := ae_restrict_biUnion_eq s t.countable_toSet theorem ae_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i, s i), p x) ↔ ∀ i, ∀ᵐ x ∂μ.restrict (s i), p x := by simp theorem ae_restrict_union_iff (s t : Set α) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (s ∪ t), p x) ↔ (∀ᵐ x ∂μ.restrict s, p x) ∧ ∀ᵐ x ∂μ.restrict t, p x := by simp theorem ae_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by simp_rw [Filter.Eventually, ae_restrict_biUnion_eq s ht, mem_iSup] @[simp] theorem ae_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (p : α → Prop) : (∀ᵐ x ∂μ.restrict (⋃ i ∈ t, s i), p x) ↔ ∀ i ∈ t, ∀ᵐ x ∂μ.restrict (s i), p x := by simp_rw [Filter.Eventually, ae_restrict_biUnion_finset_eq s, mem_iSup] theorem ae_eq_restrict_iUnion_iff [Countable ι] (s : ι → Set α) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i, s i)] g ↔ ∀ i, f =ᵐ[μ.restrict (s i)] g := by simp_rw [EventuallyEq, ae_restrict_iUnion_eq, eventually_iSup] theorem ae_eq_restrict_biUnion_iff (s : ι → Set α) {t : Set ι} (ht : t.Countable) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := by simp_rw [ae_restrict_biUnion_eq s ht, EventuallyEq, eventually_iSup] theorem ae_eq_restrict_biUnion_finset_iff (s : ι → Set α) (t : Finset ι) (f g : α → δ) : f =ᵐ[μ.restrict (⋃ i ∈ t, s i)] g ↔ ∀ i ∈ t, f =ᵐ[μ.restrict (s i)] g := ae_eq_restrict_biUnion_iff s t.countable_toSet f g open scoped Interval in theorem ae_restrict_uIoc_eq [LinearOrder α] (a b : α) : ae (μ.restrict (Ι a b)) = ae (μ.restrict (Ioc a b)) ⊔ ae (μ.restrict (Ioc b a)) := by simp only [uIoc_eq_union, ae_restrict_union_eq] open scoped Interval in /-- See also `MeasureTheory.ae_uIoc_iff`. -/ theorem ae_restrict_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ.restrict (Ι a b), P x) ↔ (∀ᵐ x ∂μ.restrict (Ioc a b), P x) ∧ ∀ᵐ x ∂μ.restrict (Ioc b a), P x := by rw [ae_restrict_uIoc_eq, eventually_sup] theorem ae_restrict_iff₀ {p : α → Prop} (hp : NullMeasurableSet { x | p x } (μ.restrict s)) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by simp only [ae_iff, ← compl_setOf, Measure.restrict_apply₀ hp.compl] rw [iff_iff_eq]; congr with x; simp [and_comm] theorem ae_restrict_iff {p : α → Prop} (hp : MeasurableSet { x | p x }) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := ae_restrict_iff₀ hp.nullMeasurableSet theorem ae_imp_of_ae_restrict {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ.restrict s, p x) : ∀ᵐ x ∂μ, x ∈ s → p x := by simp only [ae_iff] at h ⊢ simpa [setOf_and, inter_comm] using measure_inter_eq_zero_of_restrict h theorem ae_restrict_iff'₀ {p : α → Prop} (hs : NullMeasurableSet s μ) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := by simp only [ae_iff, ← compl_setOf, restrict_apply₀' hs] rw [iff_iff_eq]; congr with x; simp [and_comm] theorem ae_restrict_iff' {p : α → Prop} (hs : MeasurableSet s) : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ, x ∈ s → p x := ae_restrict_iff'₀ hs.nullMeasurableSet theorem _root_.Filter.EventuallyEq.restrict {f g : α → δ} {s : Set α} (hfg : f =ᵐ[μ] g) : f =ᵐ[μ.restrict s] g := by -- note that we cannot use `ae_restrict_iff` since we do not require measurability refine hfg.filter_mono ?_ rw [Measure.ae_le_iff_absolutelyContinuous] exact Measure.absolutelyContinuous_of_le Measure.restrict_le_self theorem ae_restrict_mem₀ (hs : NullMeasurableSet s μ) : ∀ᵐ x ∂μ.restrict s, x ∈ s := (ae_restrict_iff'₀ hs).2 (Filter.Eventually.of_forall fun _ => id) theorem ae_restrict_mem (hs : MeasurableSet s) : ∀ᵐ x ∂μ.restrict s, x ∈ s := ae_restrict_mem₀ hs.nullMeasurableSet theorem ae_restrict_of_forall_mem {μ : Measure α} {s : Set α} (hs : MeasurableSet s) {p : α → Prop} (h : ∀ x ∈ s, p x) : ∀ᵐ (x : α) ∂μ.restrict s, p x := (ae_restrict_mem hs).mono h theorem ae_restrict_of_ae {s : Set α} {p : α → Prop} (h : ∀ᵐ x ∂μ, p x) : ∀ᵐ x ∂μ.restrict s, p x := h.filter_mono (ae_mono Measure.restrict_le_self) theorem ae_restrict_of_ae_restrict_of_subset {s t : Set α} {p : α → Prop} (hst : s ⊆ t) (h : ∀ᵐ x ∂μ.restrict t, p x) : ∀ᵐ x ∂μ.restrict s, p x := h.filter_mono (ae_mono <| Measure.restrict_mono hst (le_refl μ)) theorem ae_of_ae_restrict_of_ae_restrict_compl (t : Set α) {p : α → Prop} (ht : ∀ᵐ x ∂μ.restrict t, p x) (htc : ∀ᵐ x ∂μ.restrict tᶜ, p x) : ∀ᵐ x ∂μ, p x := nonpos_iff_eq_zero.1 <| calc μ { x | ¬p x } ≤ μ ({ x | ¬p x } ∩ t) + μ ({ x | ¬p x } ∩ tᶜ) := measure_le_inter_add_diff _ _ _ _ ≤ μ.restrict t { x | ¬p x } + μ.restrict tᶜ { x | ¬p x } := add_le_add (le_restrict_apply _ _) (le_restrict_apply _ _) _ = 0 := by rw [ae_iff.1 ht, ae_iff.1 htc, zero_add] theorem mem_map_restrict_ae_iff {β} {s : Set α} {t : Set β} {f : α → β} (hs : MeasurableSet s) : t ∈ Filter.map f (ae (μ.restrict s)) ↔ μ ((f ⁻¹' t)ᶜ ∩ s) = 0 := by rw [mem_map, mem_ae_iff, Measure.restrict_apply' hs] theorem ae_add_measure_iff {p : α → Prop} {ν} : (∀ᵐ x ∂μ + ν, p x) ↔ (∀ᵐ x ∂μ, p x) ∧ ∀ᵐ x ∂ν, p x := add_eq_zero theorem ae_eq_comp' {ν : Measure β} {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ) (h : g =ᵐ[ν] g') (h2 : μ.map f ≪ ν) : g ∘ f =ᵐ[μ] g' ∘ f := (tendsto_ae_map hf).mono_right h2.ae_le h theorem Measure.QuasiMeasurePreserving.ae_eq_comp {ν : Measure β} {f : α → β} {g g' : β → δ} (hf : QuasiMeasurePreserving f μ ν) (h : g =ᵐ[ν] g') : g ∘ f =ᵐ[μ] g' ∘ f := ae_eq_comp' hf.aemeasurable h hf.absolutelyContinuous theorem ae_eq_comp {f : α → β} {g g' : β → δ} (hf : AEMeasurable f μ) (h : g =ᵐ[μ.map f] g') : g ∘ f =ᵐ[μ] g' ∘ f := ae_eq_comp' hf h AbsolutelyContinuous.rfl @[to_additive] theorem div_ae_eq_one {β} [Group β] (f g : α → β) : f / g =ᵐ[μ] 1 ↔ f =ᵐ[μ] g := by refine ⟨fun h ↦ h.mono fun x hx ↦ ?_, fun h ↦ h.mono fun x hx ↦ ?_⟩ · rwa [Pi.div_apply, Pi.one_apply, div_eq_one] at hx · rwa [Pi.div_apply, Pi.one_apply, div_eq_one] @[to_additive sub_nonneg_ae] lemma one_le_div_ae {β : Type*} [Group β] [LE β] [MulRightMono β] (f g : α → β) : 1 ≤ᵐ[μ] g / f ↔ f ≤ᵐ[μ] g := by refine ⟨fun h ↦ h.mono fun a ha ↦ ?_, fun h ↦ h.mono fun a ha ↦ ?_⟩ · rwa [Pi.one_apply, Pi.div_apply, one_le_div'] at ha · rwa [Pi.one_apply, Pi.div_apply, one_le_div'] theorem le_ae_restrict : ae μ ⊓ 𝓟 s ≤ ae (μ.restrict s) := fun _s hs => eventually_inf_principal.2 (ae_imp_of_ae_restrict hs) @[simp] theorem ae_restrict_eq (hs : MeasurableSet s) : ae (μ.restrict s) = ae μ ⊓ 𝓟 s := by ext t simp only [mem_inf_principal, mem_ae_iff, restrict_apply_eq_zero' hs, compl_setOf, Classical.not_imp, fun a => and_comm (a := a ∈ s) (b := ¬a ∈ t)] rfl lemma ae_restrict_le : ae (μ.restrict s) ≤ ae μ := ae_mono restrict_le_self theorem ae_restrict_eq_bot {s} : ae (μ.restrict s) = ⊥ ↔ μ s = 0 := ae_eq_bot.trans restrict_eq_zero theorem ae_restrict_neBot {s} : (ae <| μ.restrict s).NeBot ↔ μ s ≠ 0 := neBot_iff.trans ae_restrict_eq_bot.not theorem self_mem_ae_restrict {s} (hs : MeasurableSet s) : s ∈ ae (μ.restrict s) := by simp only [ae_restrict_eq hs, exists_prop, mem_principal, mem_inf_iff] exact ⟨_, univ_mem, s, Subset.rfl, (univ_inter s).symm⟩ /-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one is almost everywhere true on the other -/ theorem ae_restrict_of_ae_eq_of_ae_restrict {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} : (∀ᵐ x ∂μ.restrict s, p x) → ∀ᵐ x ∂μ.restrict t, p x := by simp [Measure.restrict_congr_set hst] /-- If two measurable sets are ae_eq then any proposition that is almost everywhere true on one is almost everywhere true on the other -/ theorem ae_restrict_congr_set {s t} (hst : s =ᵐ[μ] t) {p : α → Prop} : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ x ∂μ.restrict t, p x := ⟨ae_restrict_of_ae_eq_of_ae_restrict hst, ae_restrict_of_ae_eq_of_ae_restrict hst.symm⟩ lemma NullMeasurable.measure_preimage_eq_measure_restrict_preimage_of_ae_compl_eq_const {β : Type*} [MeasurableSpace β] {b : β} {f : α → β} {s : Set α} (f_mble : NullMeasurable f (μ.restrict s)) (hs : f =ᵐ[Measure.restrict μ sᶜ] (fun _ ↦ b)) {t : Set β} (t_mble : MeasurableSet t) (ht : b ∉ t) : μ (f ⁻¹' t) = μ.restrict s (f ⁻¹' t) := by rw [Measure.restrict_apply₀ (f_mble t_mble)] rw [EventuallyEq, ae_iff, Measure.restrict_apply₀] at hs · apply le_antisymm _ (measure_mono inter_subset_left) apply (measure_mono (Eq.symm (inter_union_compl (f ⁻¹' t) s)).le).trans apply (measure_union_le _ _).trans have obs : μ ((f ⁻¹' t) ∩ sᶜ) = 0 := by apply le_antisymm _ (zero_le _) rw [← hs] apply measure_mono (inter_subset_inter_left _ _) intro x hx hfx simp only [mem_preimage, mem_setOf_eq] at hx hfx exact ht (hfx ▸ hx) simp only [obs, add_zero, le_refl] · exact NullMeasurableSet.of_null hs namespace Measure section Subtype /-! ### Subtype of a measure space -/ section ComapAnyMeasure theorem MeasurableSet.nullMeasurableSet_subtype_coe {t : Set s} (hs : NullMeasurableSet s μ) (ht : MeasurableSet t) : NullMeasurableSet ((↑) '' t) μ := by rw [Subtype.instMeasurableSpace, comap_eq_generateFrom] at ht induction t, ht using generateFrom_induction with | hC t' ht' => obtain ⟨s', hs', rfl⟩ := ht' rw [Subtype.image_preimage_coe] exact hs.inter (hs'.nullMeasurableSet) | empty => simp only [image_empty, nullMeasurableSet_empty] | compl t' _ ht' => simp only [← range_diff_image Subtype.coe_injective, Subtype.range_coe_subtype, setOf_mem_eq] exact hs.diff ht' | iUnion f _ hf => dsimp only [] rw [image_iUnion] exact .iUnion hf theorem NullMeasurableSet.subtype_coe {t : Set s} (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t (μ.comap Subtype.val)) : NullMeasurableSet (((↑) : s → α) '' t) μ := NullMeasurableSet.image _ μ Subtype.coe_injective (fun _ => MeasurableSet.nullMeasurableSet_subtype_coe hs) ht theorem measure_subtype_coe_le_comap (hs : NullMeasurableSet s μ) (t : Set s) : μ (((↑) : s → α) '' t) ≤ μ.comap Subtype.val t := le_comap_apply _ _ Subtype.coe_injective (fun _ => MeasurableSet.nullMeasurableSet_subtype_coe hs) _ theorem measure_subtype_coe_eq_zero_of_comap_eq_zero (hs : NullMeasurableSet s μ) {t : Set s} (ht : μ.comap Subtype.val t = 0) : μ (((↑) : s → α) '' t) = 0 := eq_bot_iff.mpr <| (measure_subtype_coe_le_comap hs t).trans ht.le end ComapAnyMeasure section MeasureSpace variable {u : Set δ} [MeasureSpace δ] {p : δ → Prop} /-- In a measure space, one can restrict the measure to a subtype to get a new measure space. Not registered as an instance, as there are other natural choices such as the normalized restriction for a probability measure, or the subspace measure when restricting to a vector subspace. Enable locally if needed with `attribute [local instance] Measure.Subtype.measureSpace`. -/ noncomputable def Subtype.measureSpace : MeasureSpace (Subtype p) where volume := Measure.comap Subtype.val volume attribute [local instance] Subtype.measureSpace theorem Subtype.volume_def : (volume : Measure u) = volume.comap Subtype.val := rfl theorem Subtype.volume_univ (hu : NullMeasurableSet u) : volume (univ : Set u) = volume u := by rw [Subtype.volume_def, comap_apply₀ _ _ _ _ MeasurableSet.univ.nullMeasurableSet] · congr simp only [image_univ, Subtype.range_coe_subtype, setOf_mem_eq] · exact Subtype.coe_injective · exact fun t => MeasurableSet.nullMeasurableSet_subtype_coe hu theorem volume_subtype_coe_le_volume (hu : NullMeasurableSet u) (t : Set u) : volume (((↑) : u → δ) '' t) ≤ volume t := measure_subtype_coe_le_comap hu t theorem volume_subtype_coe_eq_zero_of_volume_eq_zero (hu : NullMeasurableSet u) {t : Set u} (ht : volume t = 0) : volume (((↑) : u → δ) '' t) = 0 := measure_subtype_coe_eq_zero_of_comap_eq_zero hu ht end MeasureSpace end Subtype end Measure end MeasureTheory open MeasureTheory Measure namespace MeasurableEmbedding variable {m0 : MeasurableSpace α} {m1 : MeasurableSpace β} {f : α → β} section variable (hf : MeasurableEmbedding f) include hf theorem map_comap (μ : Measure β) : (comap f μ).map f = μ.restrict (range f) := by ext1 t ht rw [hf.map_apply, comap_apply f hf.injective hf.measurableSet_image' _ (hf.measurable ht), image_preimage_eq_inter_range, Measure.restrict_apply ht] theorem comap_apply (μ : Measure β) (s : Set α) : comap f μ s = μ (f '' s) := calc comap f μ s = comap f μ (f ⁻¹' (f '' s)) := by rw [hf.injective.preimage_image] _ = (comap f μ).map f (f '' s) := (hf.map_apply _ _).symm _ = μ (f '' s) := by rw [hf.map_comap, restrict_apply' hf.measurableSet_range, inter_eq_self_of_subset_left (image_subset_range _ _)] theorem comap_map (μ : Measure α) : (map f μ).comap f = μ := by ext t _ rw [hf.comap_apply, hf.map_apply, preimage_image_eq _ hf.injective] theorem ae_map_iff {p : β → Prop} {μ : Measure α} : (∀ᵐ x ∂μ.map f, p x) ↔ ∀ᵐ x ∂μ, p (f x) := by simp only [ae_iff, hf.map_apply, preimage_setOf_eq] theorem restrict_map (μ : Measure α) (s : Set β) : (μ.map f).restrict s = (μ.restrict <| f ⁻¹' s).map f := Measure.ext fun t ht => by simp [hf.map_apply, ht, hf.measurable ht] protected theorem comap_preimage (μ : Measure β) (s : Set β) : μ.comap f (f ⁻¹' s) = μ (s ∩ range f) := by rw [← hf.map_apply, hf.map_comap, restrict_apply' hf.measurableSet_range] lemma comap_restrict (μ : Measure β) (s : Set β) : (μ.restrict s).comap f = (μ.comap f).restrict (f ⁻¹' s) := by ext t ht rw [Measure.restrict_apply ht, comap_apply hf, comap_apply hf, Measure.restrict_apply (hf.measurableSet_image.2 ht), image_inter_preimage] lemma restrict_comap (μ : Measure β) (s : Set α) : (μ.comap f).restrict s = (μ.restrict (f '' s)).comap f := by rw [comap_restrict hf, preimage_image_eq _ hf.injective] end theorem _root_.MeasurableEquiv.restrict_map (e : α ≃ᵐ β) (μ : Measure α) (s : Set β) : (μ.map e).restrict s = (μ.restrict <| e ⁻¹' s).map e := e.measurableEmbedding.restrict_map _ _ end MeasurableEmbedding section Subtype theorem comap_subtype_coe_apply {_m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s) (μ : Measure α) (t : Set s) : comap (↑) μ t = μ ((↑) '' t) := (MeasurableEmbedding.subtype_coe hs).comap_apply _ _ theorem map_comap_subtype_coe {m0 : MeasurableSpace α} {s : Set α} (hs : MeasurableSet s) (μ : Measure α) : (comap (↑) μ).map ((↑) : s → α) = μ.restrict s := by rw [(MeasurableEmbedding.subtype_coe hs).map_comap, Subtype.range_coe] theorem ae_restrict_iff_subtype {m0 : MeasurableSpace α} {μ : Measure α} {s : Set α} (hs : MeasurableSet s) {p : α → Prop} : (∀ᵐ x ∂μ.restrict s, p x) ↔ ∀ᵐ (x : s) ∂comap ((↑) : s → α) μ, p x := by rw [← map_comap_subtype_coe hs, (MeasurableEmbedding.subtype_coe hs).ae_map_iff] variable [MeasureSpace α] {s t : Set α} /-! ### Volume on `s : Set α` Note the instance is provided earlier as `Subtype.measureSpace`. -/ attribute [local instance] Subtype.measureSpace theorem volume_set_coe_def (s : Set α) : (volume : Measure s) = comap ((↑) : s → α) volume := rfl theorem MeasurableSet.map_coe_volume {s : Set α} (hs : MeasurableSet s) : volume.map ((↑) : s → α) = restrict volume s := by rw [volume_set_coe_def, (MeasurableEmbedding.subtype_coe hs).map_comap volume, Subtype.range_coe] theorem volume_image_subtype_coe {s : Set α} (hs : MeasurableSet s) (t : Set s) : volume ((↑) '' t : Set α) = volume t := (comap_subtype_coe_apply hs volume t).symm @[simp] theorem volume_preimage_coe (hs : NullMeasurableSet s) (ht : MeasurableSet t) : volume (((↑) : s → α) ⁻¹' t) = volume (t ∩ s) := by rw [volume_set_coe_def, comap_apply₀ _ _ Subtype.coe_injective (fun h => MeasurableSet.nullMeasurableSet_subtype_coe hs) (measurable_subtype_coe ht).nullMeasurableSet, image_preimage_eq_inter_range, Subtype.range_coe] end Subtype section Piecewise variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f g : α → β} theorem piecewise_ae_eq_restrict [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : piecewise s f g =ᵐ[μ.restrict s] f := by rw [ae_restrict_eq hs] exact (piecewise_eqOn s f g).eventuallyEq.filter_mono inf_le_right theorem piecewise_ae_eq_restrict_compl [DecidablePred (· ∈ s)] (hs : MeasurableSet s) : piecewise s f g =ᵐ[μ.restrict sᶜ] g := by rw [ae_restrict_eq hs.compl] exact (piecewise_eqOn_compl s f g).eventuallyEq.filter_mono inf_le_right theorem piecewise_ae_eq_of_ae_eq_set [DecidablePred (· ∈ s)] [DecidablePred (· ∈ t)] (hst : s =ᵐ[μ] t) : s.piecewise f g =ᵐ[μ] t.piecewise f g := hst.mem_iff.mono fun x hx => by simp [piecewise, hx] end Piecewise section IndicatorFunction variable [MeasurableSpace α] {μ : Measure α} {s t : Set α} {f : α → β} theorem mem_map_indicator_ae_iff_mem_map_restrict_ae_of_zero_mem [Zero β] {t : Set β} (ht : (0 : β) ∈ t) (hs : MeasurableSet s) : t ∈ Filter.map (s.indicator f) (ae μ) ↔ t ∈ Filter.map f (ae <| μ.restrict s) := by classical
simp_rw [mem_map, mem_ae_iff] rw [Measure.restrict_apply' hs, Set.indicator_preimage, Set.ite] simp_rw [Set.compl_union, Set.compl_inter]
Mathlib/MeasureTheory/Measure/Restrict.lean
908
910
/- Copyright (c) 2021 Anne Baanen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Anne Baanen -/ import Mathlib.FieldTheory.RatFunc.Defs import Mathlib.RingTheory.EuclideanDomain import Mathlib.RingTheory.Localization.FractionRing import Mathlib.RingTheory.Polynomial.Content /-! # The field structure of rational functions ## Main definitions Working with rational functions as polynomials: - `RatFunc.instField` provides a field structure You can use `IsFractionRing` API to treat `RatFunc` as the field of fractions of polynomials: * `algebraMap K[X] (RatFunc K)` maps polynomials to rational functions * `IsFractionRing.algEquiv` maps other fields of fractions of `K[X]` to `RatFunc K`, in particular: * `FractionRing.algEquiv K[X] (RatFunc K)` maps the generic field of fraction construction to `RatFunc K`. Combine this with `AlgEquiv.restrictScalars` to change the `FractionRing K[X] ≃ₐ[K[X]] RatFunc K` to `FractionRing K[X] ≃ₐ[K] RatFunc K`. Working with rational functions as fractions: - `RatFunc.num` and `RatFunc.denom` give the numerator and denominator. These values are chosen to be coprime and such that `RatFunc.denom` is monic. Lifting homomorphisms of polynomials to other types, by mapping and dividing, as long as the homomorphism retains the non-zero-divisor property: - `RatFunc.liftMonoidWithZeroHom` lifts a `K[X] →*₀ G₀` to a `RatFunc K →*₀ G₀`, where `[CommRing K] [CommGroupWithZero G₀]` - `RatFunc.liftRingHom` lifts a `K[X] →+* L` to a `RatFunc K →+* L`, where `[CommRing K] [Field L]` - `RatFunc.liftAlgHom` lifts a `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L`, where `[CommRing K] [Field L] [CommSemiring S] [Algebra S K[X]] [Algebra S L]` This is satisfied by injective homs. We also have lifting homomorphisms of polynomials to other polynomials, with the same condition on retaining the non-zero-divisor property across the map: - `RatFunc.map` lifts `K[X] →* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapRingHom` lifts `K[X] →+* R[X]` when `[CommRing K] [CommRing R]` - `RatFunc.mapAlgHom` lifts `K[X] →ₐ[S] R[X]` when `[CommRing K] [IsDomain K] [CommRing R] [IsDomain R]` -/ universe u v noncomputable section open scoped nonZeroDivisors Polynomial variable {K : Type u} namespace RatFunc section Field variable [CommRing K] /-- The zero rational function. -/ protected irreducible_def zero : RatFunc K := ⟨0⟩ instance : Zero (RatFunc K) := ⟨RatFunc.zero⟩ theorem ofFractionRing_zero : (ofFractionRing 0 : RatFunc K) = 0 := zero_def.symm /-- Addition of rational functions. -/ protected irreducible_def add : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p + q⟩ instance : Add (RatFunc K) := ⟨RatFunc.add⟩ theorem ofFractionRing_add (p q : FractionRing K[X]) : ofFractionRing (p + q) = ofFractionRing p + ofFractionRing q := (add_def _ _).symm /-- Subtraction of rational functions. -/ protected irreducible_def sub : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p - q⟩ instance : Sub (RatFunc K) := ⟨RatFunc.sub⟩ theorem ofFractionRing_sub (p q : FractionRing K[X]) : ofFractionRing (p - q) = ofFractionRing p - ofFractionRing q := (sub_def _ _).symm /-- Additive inverse of a rational function. -/ protected irreducible_def neg : RatFunc K → RatFunc K | ⟨p⟩ => ⟨-p⟩ instance : Neg (RatFunc K) := ⟨RatFunc.neg⟩ theorem ofFractionRing_neg (p : FractionRing K[X]) : ofFractionRing (-p) = -ofFractionRing p := (neg_def _).symm /-- The multiplicative unit of rational functions. -/ protected irreducible_def one : RatFunc K := ⟨1⟩ instance : One (RatFunc K) := ⟨RatFunc.one⟩ theorem ofFractionRing_one : (ofFractionRing 1 : RatFunc K) = 1 := one_def.symm /-- Multiplication of rational functions. -/ protected irreducible_def mul : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p * q⟩ instance : Mul (RatFunc K) := ⟨RatFunc.mul⟩ theorem ofFractionRing_mul (p q : FractionRing K[X]) : ofFractionRing (p * q) = ofFractionRing p * ofFractionRing q := (mul_def _ _).symm section IsDomain variable [IsDomain K] /-- Division of rational functions. -/ protected irreducible_def div : RatFunc K → RatFunc K → RatFunc K | ⟨p⟩, ⟨q⟩ => ⟨p / q⟩ instance : Div (RatFunc K) := ⟨RatFunc.div⟩ theorem ofFractionRing_div (p q : FractionRing K[X]) : ofFractionRing (p / q) = ofFractionRing p / ofFractionRing q := (div_def _ _).symm /-- Multiplicative inverse of a rational function. -/ protected irreducible_def inv : RatFunc K → RatFunc K | ⟨p⟩ => ⟨p⁻¹⟩ instance : Inv (RatFunc K) := ⟨RatFunc.inv⟩ theorem ofFractionRing_inv (p : FractionRing K[X]) : ofFractionRing p⁻¹ = (ofFractionRing p)⁻¹ := (inv_def _).symm -- Auxiliary lemma for the `Field` instance theorem mul_inv_cancel : ∀ {p : RatFunc K}, p ≠ 0 → p * p⁻¹ = 1 | ⟨p⟩, h => by have : p ≠ 0 := fun hp => h <| by rw [hp, ofFractionRing_zero] simpa only [← ofFractionRing_inv, ← ofFractionRing_mul, ← ofFractionRing_one, ofFractionRing.injEq] using mul_inv_cancel₀ this end IsDomain section SMul variable {R : Type*} /-- Scalar multiplication of rational functions. -/ protected irreducible_def smul [SMul R (FractionRing K[X])] : R → RatFunc K → RatFunc K | r, ⟨p⟩ => ⟨r • p⟩ instance [SMul R (FractionRing K[X])] : SMul R (RatFunc K) := ⟨RatFunc.smul⟩ theorem ofFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : FractionRing K[X]) : ofFractionRing (c • p) = c • ofFractionRing p := (smul_def _ _).symm theorem toFractionRing_smul [SMul R (FractionRing K[X])] (c : R) (p : RatFunc K) : toFractionRing (c • p) = c • toFractionRing p := by cases p rw [← ofFractionRing_smul] theorem smul_eq_C_smul (x : RatFunc K) (r : K) : r • x = Polynomial.C r • x := by obtain ⟨x⟩ := x induction x using Localization.induction_on rw [← ofFractionRing_smul, ← ofFractionRing_smul, Localization.smul_mk, Localization.smul_mk, smul_eq_mul, Polynomial.smul_eq_C_mul] section IsDomain variable [IsDomain K] variable [Monoid R] [DistribMulAction R K[X]] variable [IsScalarTower R K[X] K[X]] theorem mk_smul (c : R) (p q : K[X]) : RatFunc.mk (c • p) q = c • RatFunc.mk p q := by letI : SMulZeroClass R (FractionRing K[X]) := inferInstance by_cases hq : q = 0 · rw [hq, mk_zero, mk_zero, ← ofFractionRing_smul, smul_zero] · rw [mk_eq_localization_mk _ hq, mk_eq_localization_mk _ hq, ← Localization.smul_mk, ← ofFractionRing_smul] instance : IsScalarTower R K[X] (RatFunc K) := ⟨fun c p q => q.induction_on' fun q r _ => by rw [← mk_smul, smul_assoc, mk_smul, mk_smul]⟩ end IsDomain end SMul variable (K) instance [Subsingleton K] : Subsingleton (RatFunc K) := toFractionRing_injective.subsingleton instance : Inhabited (RatFunc K) := ⟨0⟩ instance instNontrivial [Nontrivial K] : Nontrivial (RatFunc K) := ofFractionRing_injective.nontrivial /-- `RatFunc K` is isomorphic to the field of fractions of `K[X]`, as rings. This is an auxiliary definition; `simp`-normal form is `IsLocalization.algEquiv`. -/ @[simps apply] def toFractionRingRingEquiv : RatFunc K ≃+* FractionRing K[X] where toFun := toFractionRing invFun := ofFractionRing left_inv := fun ⟨_⟩ => rfl right_inv _ := rfl map_add' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_add] map_mul' := fun ⟨_⟩ ⟨_⟩ => by simp [← ofFractionRing_mul] end Field section TacticInterlude /-- Solve equations for `RatFunc K` by working in `FractionRing K[X]`. -/ macro "frac_tac" : tactic => `(tactic| · repeat (rintro (⟨⟩ : RatFunc _)) try simp only [← ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_sub, ← ofFractionRing_neg, ← ofFractionRing_one, ← ofFractionRing_mul, ← ofFractionRing_div, ← ofFractionRing_inv, add_assoc, zero_add, add_zero, mul_assoc, mul_zero, mul_one, mul_add, inv_zero, add_comm, add_left_comm, mul_comm, mul_left_comm, sub_eq_add_neg, div_eq_mul_inv, add_mul, zero_mul, one_mul, neg_mul, mul_neg, add_neg_cancel]) /-- Solve equations for `RatFunc K` by applying `RatFunc.induction_on`. -/ macro "smul_tac" : tactic => `(tactic| repeat (first | rintro (⟨⟩ : RatFunc _) | intro) <;> simp_rw [← ofFractionRing_smul] <;> simp only [add_comm, mul_comm, zero_smul, succ_nsmul, zsmul_eq_mul, mul_add, mul_one, mul_zero, neg_add, mul_neg, Int.cast_zero, Int.cast_add, Int.cast_one, Int.cast_negSucc, Int.cast_natCast, Nat.cast_succ, Localization.mk_zero, Localization.add_mk_self, Localization.neg_mk, ofFractionRing_zero, ← ofFractionRing_add, ← ofFractionRing_neg]) end TacticInterlude section CommRing variable (K) [CommRing K] /-- `RatFunc K` is a commutative monoid. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instCommMonoid : CommMonoid (RatFunc K) where mul := (· * ·) mul_assoc := by frac_tac mul_comm := by frac_tac one := 1 one_mul := by frac_tac mul_one := by frac_tac npow := npowRec /-- `RatFunc K` is an additive commutative group. This is an intermediate step on the way to the full instance `RatFunc.instCommRing`. -/ def instAddCommGroup : AddCommGroup (RatFunc K) where add := (· + ·) add_assoc := by frac_tac add_comm := by frac_tac zero := 0 zero_add := by frac_tac add_zero := by frac_tac neg := Neg.neg neg_add_cancel := by frac_tac sub := Sub.sub sub_eq_add_neg := by frac_tac nsmul := (· • ·) nsmul_zero := by smul_tac nsmul_succ _ := by smul_tac zsmul := (· • ·) zsmul_zero' := by smul_tac zsmul_succ' _ := by smul_tac zsmul_neg' _ := by smul_tac instance instCommRing : CommRing (RatFunc K) := { instCommMonoid K, instAddCommGroup K with zero := 0 sub := Sub.sub zero_mul := by frac_tac mul_zero := by frac_tac left_distrib := by frac_tac right_distrib := by frac_tac one := 1 nsmul := (· • ·) zsmul := (· • ·) npow := npowRec } variable {K} section LiftHom open RatFunc variable {G₀ L R S F : Type*} [CommGroupWithZero G₀] [Field L] [CommRing R] [CommRing S] variable [FunLike F R[X] S[X]] open scoped Classical in /-- Lift a monoid homomorphism that maps polynomials `φ : R[X] →* S[X]` to a `RatFunc R →* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def map [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →* RatFunc S where toFun f := RatFunc.liftOn f (fun n d => if h : φ d ∈ S[X]⁰ then ofFractionRing (Localization.mk (φ n) ⟨φ d, h⟩) else 0) fun {p q p' q'} hq hq' h => by simp only [Submonoid.mem_comap.mp (hφ hq), Submonoid.mem_comap.mp (hφ hq'), dif_pos, ofFractionRing.injEq, Localization.mk_eq_mk_iff] refine Localization.r_of_eq ?_ simpa only [map_mul] using congr_arg φ h map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, OneMemClass.one_mem, dite_true, ofFractionRing.injEq, Localization.mk_one, Localization.mk_eq_monoidOf_mk', Submonoid.LocalizationMap.mk'_self] map_mul' x y := by obtain ⟨x⟩ := x; obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' have hq : φ q ∈ S[X]⁰ := hφ q.prop have hq' : φ q' ∈ S[X]⁰ := hφ q'.prop have hqq' : φ ↑(q * q') ∈ S[X]⁰ := by simpa using Submonoid.mul_mem _ hq hq' simp_rw [← ofFractionRing_mul, Localization.mk_mul, liftOn_ofFractionRing_mk, dif_pos hq, dif_pos hq', dif_pos hqq', ← ofFractionRing_mul, Submonoid.coe_mul, map_mul, Localization.mk_mul, Submonoid.mk_mul_mk] theorem map_apply_ofFractionRing_mk [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (n : R[X]) (d : R[X]⁰) : map φ hφ (ofFractionRing (Localization.mk n d)) = ofFractionRing (Localization.mk (φ n) ⟨φ d, hφ d.prop⟩) := by simp only [map, MonoidHom.coe_mk, OneHom.coe_mk, liftOn_ofFractionRing_mk, Submonoid.mem_comap.mp (hφ d.2), ↓reduceDIte] theorem map_injective [MonoidHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) (hf : Function.Injective φ) : Function.Injective (map φ hφ) := by rintro ⟨x⟩ ⟨y⟩ h induction x using Localization.induction_on induction y using Localization.induction_on simpa only [map_apply_ofFractionRing_mk, ofFractionRing_injective.eq_iff, Localization.mk_eq_mk_iff, Localization.r_iff_exists, mul_cancel_left_coe_nonZeroDivisors, exists_const, ← map_mul, hf.eq_iff] using h /-- Lift a ring homomorphism that maps polynomials `φ : R[X] →+* S[X]` to a `RatFunc R →+* RatFunc S`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapRingHom [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : RatFunc R →+* RatFunc S := { map φ hφ with map_zero' := by simp_rw [MonoidHom.toFun_eq_coe, ← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), ← Localization.mk_zero (1 : S[X]⁰), map_apply_ofFractionRing_mk, map_zero, Localization.mk_eq_mk', IsLocalization.mk'_zero] map_add' := by rintro ⟨x⟩ ⟨y⟩ induction x using Localization.induction_on induction y using Localization.induction_on · simp only [← ofFractionRing_add, Localization.add_mk, map_add, map_mul, MonoidHom.toFun_eq_coe, map_apply_ofFractionRing_mk, Submonoid.coe_mul, -- We have to specify `S[X]⁰` to `mk_mul_mk`, otherwise it will try to rewrite -- the wrong occurrence. Submonoid.mk_mul_mk S[X]⁰] } theorem coe_mapRingHom_eq_coe_map [RingHomClass F R[X] S[X]] (φ : F) (hφ : R[X]⁰ ≤ S[X]⁰.comap φ) : (mapRingHom φ hφ : RatFunc R → RatFunc S) = map φ hφ := rfl -- TODO: Generalize to `FunLike` classes, /-- Lift a monoid with zero homomorphism `R[X] →*₀ G₀` to a `RatFunc R →*₀ G₀` on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def liftMonoidWithZeroHom (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) : RatFunc R →*₀ G₀ where toFun f := RatFunc.liftOn f (fun p q => φ p / φ q) fun {p q p' q'} hq hq' h => by cases subsingleton_or_nontrivial R · rw [Subsingleton.elim p q, Subsingleton.elim p' q, Subsingleton.elim q' q] rw [div_eq_div_iff, ← map_mul, mul_comm p, h, map_mul, mul_comm] <;> exact nonZeroDivisors.ne_zero (hφ ‹_›) map_one' := by simp_rw [← ofFractionRing_one, ← Localization.mk_one, liftOn_ofFractionRing_mk, OneMemClass.coe_one, map_one, div_one] map_mul' x y := by obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with p q induction' y using Localization.induction_on with p' q' rw [← ofFractionRing_mul, Localization.mk_mul] simp only [liftOn_ofFractionRing_mk, div_mul_div_comm, map_mul, Submonoid.coe_mul] map_zero' := by simp_rw [← ofFractionRing_zero, ← Localization.mk_zero (1 : R[X]⁰), liftOn_ofFractionRing_mk, map_zero, zero_div] theorem liftMonoidWithZeroHom_apply_ofFractionRing_mk (φ : R[X] →*₀ G₀) (hφ : R[X]⁰ ≤ G₀⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftMonoidWithZeroHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftOn_ofFractionRing_mk _ _ _ _ theorem liftMonoidWithZeroHom_injective [Nontrivial R] (φ : R[X] →*₀ G₀) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ G₀⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftMonoidWithZeroHom φ hφ') := by rintro ⟨x⟩ ⟨y⟩ induction' x using Localization.induction_on with a induction' y using Localization.induction_on with a' simp_rw [liftMonoidWithZeroHom_apply_ofFractionRing_mk] intro h congr 1 refine Localization.mk_eq_mk_iff.mpr (Localization.r_of_eq (M := R[X]) ?_) have := mul_eq_mul_of_div_eq_div _ _ ?_ ?_ h · rwa [← map_mul, ← map_mul, hφ.eq_iff, mul_comm, mul_comm a'.fst] at this all_goals exact map_ne_zero_of_mem_nonZeroDivisors _ hφ (SetLike.coe_mem _) /-- Lift an injective ring homomorphism `R[X] →+* L` to a `RatFunc R →+* L` by mapping both the numerator and denominator and quotienting them. -/ def liftRingHom (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) : RatFunc R →+* L := { liftMonoidWithZeroHom φ.toMonoidWithZeroHom hφ with map_add' := fun x y => by simp only [ZeroHom.toFun_eq_coe, MonoidWithZeroHom.toZeroHom_coe] cases subsingleton_or_nontrivial R · rw [Subsingleton.elim (x + y) y, Subsingleton.elim x 0, map_zero, zero_add] obtain ⟨x⟩ := x obtain ⟨y⟩ := y induction' x using Localization.induction_on with pq induction' y using Localization.induction_on with p'q' obtain ⟨p, q⟩ := pq obtain ⟨p', q'⟩ := p'q' rw [← ofFractionRing_add, Localization.add_mk] simp only [RingHom.toMonoidWithZeroHom_eq_coe, liftMonoidWithZeroHom_apply_ofFractionRing_mk] rw [div_add_div, div_eq_div_iff] · rw [mul_comm _ p, mul_comm _ p', mul_comm _ (φ p'), add_comm] simp only [map_add, map_mul, Submonoid.coe_mul] all_goals try simp only [← map_mul, ← Submonoid.coe_mul] exact nonZeroDivisors.ne_zero (hφ (SetLike.coe_mem _)) } theorem liftRingHom_apply_ofFractionRing_mk (φ : R[X] →+* L) (hφ : R[X]⁰ ≤ L⁰.comap φ) (n : R[X]) (d : R[X]⁰) : liftRingHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftRingHom_injective [Nontrivial R] (φ : R[X] →+* L) (hφ : Function.Injective φ) (hφ' : R[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftRingHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ end LiftHom variable (K) @[stacks 09FK] instance instField [IsDomain K] : Field (RatFunc K) where inv_zero := by frac_tac div := (· / ·) div_eq_mul_inv := by frac_tac mul_inv_cancel _ := mul_inv_cancel zpow := zpowRec nnqsmul := _ nnqsmul_def := fun _ _ => rfl qsmul := _ qsmul_def := fun _ _ => rfl section IsFractionRing /-! ### `RatFunc` as field of fractions of `Polynomial` -/ section IsDomain variable [IsDomain K] instance (R : Type*) [CommSemiring R] [Algebra R K[X]] : Algebra R (RatFunc K) where algebraMap := { toFun x := RatFunc.mk (algebraMap _ _ x) 1 map_add' x y := by simp only [mk_one', RingHom.map_add, ofFractionRing_add] map_mul' x y := by simp only [mk_one', RingHom.map_mul, ofFractionRing_mul] map_one' := by simp only [mk_one', RingHom.map_one, ofFractionRing_one] map_zero' := by simp only [mk_one', RingHom.map_zero, ofFractionRing_zero] } smul := (· • ·) smul_def' c x := by induction' x using RatFunc.induction_on' with p q hq rw [RingHom.coe_mk, MonoidHom.coe_mk, OneHom.coe_mk, mk_one', ← mk_smul, mk_def_of_ne (c • p) hq, mk_def_of_ne p hq, ← ofFractionRing_mul, IsLocalization.mul_mk'_eq_mk'_of_mul, Algebra.smul_def] commutes' _ _ := mul_comm _ _ variable {K} /-- The coercion from polynomials to rational functions, implemented as the algebra map from a domain to its field of fractions -/ @[coe] def coePolynomial (P : Polynomial K) : RatFunc K := algebraMap _ _ P instance : Coe (Polynomial K) (RatFunc K) := ⟨coePolynomial⟩ theorem mk_one (x : K[X]) : RatFunc.mk x 1 = algebraMap _ _ x := rfl theorem ofFractionRing_algebraMap (x : K[X]) : ofFractionRing (algebraMap _ (FractionRing K[X]) x) = algebraMap _ _ x := by rw [← mk_one, mk_one'] @[simp] theorem mk_eq_div (p q : K[X]) : RatFunc.mk p q = algebraMap _ _ p / algebraMap _ _ q := by simp only [mk_eq_div', ofFractionRing_div, ofFractionRing_algebraMap] @[simp] theorem div_smul {R} [Monoid R] [DistribMulAction R K[X]] [IsScalarTower R K[X] K[X]] (c : R) (p q : K[X]) : algebraMap _ (RatFunc K) (c • p) / algebraMap _ _ q = c • (algebraMap _ _ p / algebraMap _ _ q) := by rw [← mk_eq_div, mk_smul, mk_eq_div] theorem algebraMap_apply {R : Type*} [CommSemiring R] [Algebra R K[X]] (x : R) : algebraMap R (RatFunc K) x = algebraMap _ _ (algebraMap R K[X] x) / algebraMap K[X] _ 1 := by rw [← mk_eq_div] rfl theorem map_apply_div_ne_zero {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) (hq : q ≠ 0) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by have hq' : φ q ≠ 0 := nonZeroDivisors.ne_zero (hφ (mem_nonZeroDivisors_iff_ne_zero.mpr hq)) simp only [← mk_eq_div, mk_eq_localization_mk _ hq, map_apply_ofFractionRing_mk, mk_eq_localization_mk _ hq'] @[simp] theorem map_apply_div {R F : Type*} [CommRing R] [IsDomain R] [FunLike F K[X] R[X]] [MonoidWithZeroHomClass F K[X] R[X]] (φ : F) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) (p q : K[X]) : map φ hφ (algebraMap _ _ p / algebraMap _ _ q) = algebraMap _ _ (φ p) / algebraMap _ _ (φ q) := by rcases eq_or_ne q 0 with (rfl | hq) · have : (0 : RatFunc K) = algebraMap K[X] _ 0 / algebraMap K[X] _ 1 := by simp rw [map_zero, map_zero, map_zero, div_zero, div_zero, this, map_apply_div_ne_zero, map_one, map_one, div_one, map_zero, map_zero] exact one_ne_zero exact map_apply_div_ne_zero _ _ _ _ hq theorem liftMonoidWithZeroHom_apply_div {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := by rcases eq_or_ne q 0 with (rfl | hq) · simp only [div_zero, map_zero] simp only [← mk_eq_div, mk_eq_localization_mk _ hq, liftMonoidWithZeroHom_apply_ofFractionRing_mk] @[simp] theorem liftMonoidWithZeroHom_apply_div' {L : Type*} [CommGroupWithZero L] (φ : MonoidWithZeroHom K[X] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftMonoidWithZeroHom φ hφ (algebraMap _ _ p) / liftMonoidWithZeroHom φ hφ (algebraMap _ _ q) = φ p / φ q := by rw [← map_div₀, liftMonoidWithZeroHom_apply_div] theorem liftRingHom_apply_div {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ @[simp] theorem liftRingHom_apply_div' {L : Type*} [Field L] (φ : K[X] →+* L) (hφ : K[X]⁰ ≤ L⁰.comap φ) (p q : K[X]) : liftRingHom φ hφ (algebraMap _ _ p) / liftRingHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ variable (K) theorem ofFractionRing_comp_algebraMap : ofFractionRing ∘ algebraMap K[X] (FractionRing K[X]) = algebraMap _ _ := funext ofFractionRing_algebraMap theorem algebraMap_injective : Function.Injective (algebraMap K[X] (RatFunc K)) := by rw [← ofFractionRing_comp_algebraMap] exact ofFractionRing_injective.comp (IsFractionRing.injective _ _) variable {K} section LiftAlgHom variable {L R S : Type*} [Field L] [CommRing R] [IsDomain R] [CommSemiring S] [Algebra S K[X]] [Algebra S L] [Algebra S R[X]] (φ : K[X] →ₐ[S] L) (hφ : K[X]⁰ ≤ L⁰.comap φ) /-- Lift an algebra homomorphism that maps polynomials `φ : K[X] →ₐ[S] R[X]` to a `RatFunc K →ₐ[S] RatFunc R`, on the condition that `φ` maps non zero divisors to non zero divisors, by mapping both the numerator and denominator and quotienting them. -/ def mapAlgHom (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : RatFunc K →ₐ[S] RatFunc R := { mapRingHom φ hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, coe_mapRingHom_eq_coe_map, algebraMap_apply r, map_apply_div, map_one, AlgHom.commutes] } theorem coe_mapAlgHom_eq_coe_map (φ : K[X] →ₐ[S] R[X]) (hφ : K[X]⁰ ≤ R[X]⁰.comap φ) : (mapAlgHom φ hφ : RatFunc K → RatFunc R) = map φ hφ := rfl /-- Lift an injective algebra homomorphism `K[X] →ₐ[S] L` to a `RatFunc K →ₐ[S] L` by mapping both the numerator and denominator and quotienting them. -/ def liftAlgHom : RatFunc K →ₐ[S] L := { liftRingHom φ.toRingHom hφ with commutes' := fun r => by simp_rw [RingHom.toFun_eq_coe, AlgHom.toRingHom_eq_coe, algebraMap_apply r, liftRingHom_apply_div, AlgHom.coe_toRingHom, map_one, div_one, AlgHom.commutes] } theorem liftAlgHom_apply_ofFractionRing_mk (n : K[X]) (d : K[X]⁰) : liftAlgHom φ hφ (ofFractionRing (Localization.mk n d)) = φ n / φ d := liftMonoidWithZeroHom_apply_ofFractionRing_mk _ hφ _ _ theorem liftAlgHom_injective (φ : K[X] →ₐ[S] L) (hφ : Function.Injective φ) (hφ' : K[X]⁰ ≤ L⁰.comap φ := nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _ hφ) : Function.Injective (liftAlgHom φ hφ') := liftMonoidWithZeroHom_injective _ hφ @[simp] theorem liftAlgHom_apply_div' (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p) / liftAlgHom φ hφ (algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div' _ hφ _ _ theorem liftAlgHom_apply_div (p q : K[X]) : liftAlgHom φ hφ (algebraMap _ _ p / algebraMap _ _ q) = φ p / φ q := liftMonoidWithZeroHom_apply_div _ hφ _ _ end LiftAlgHom variable (K) /-- `RatFunc K` is the field of fractions of the polynomials over `K`. -/ instance : IsFractionRing K[X] (RatFunc K) where map_units' y := by rw [← ofFractionRing_algebraMap] exact (toFractionRingRingEquiv K).symm.toRingHom.isUnit_map (IsLocalization.map_units _ y) exists_of_eq {x y} := by rw [← ofFractionRing_algebraMap, ← ofFractionRing_algebraMap] exact fun h ↦ IsLocalization.exists_of_eq ((toFractionRingRingEquiv K).symm.injective h) surj' := by rintro ⟨z⟩ convert IsLocalization.surj K[X]⁰ z simp only [← ofFractionRing_algebraMap, Function.comp_apply, ← ofFractionRing_mul, ofFractionRing.injEq] variable {K} theorem algebraMap_ne_zero {x : K[X]} (hx : x ≠ 0) : algebraMap K[X] (RatFunc K) x ≠ 0 := by simpa @[simp] theorem liftOn_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H' : ∀ {p q p' q'} (_hq : q ≠ 0) (_hq' : q' ≠ 0), q' * p = q * p' → f p q = f p' q') (H : ∀ {p q p' q'} (_hq : q ∈ K[X]⁰) (_hq' : q' ∈ K[X]⁰), q' * p = q * p' → f p q = f p' q' := fun {_ _ _ _} hq hq' h => H' (nonZeroDivisors.ne_zero hq) (nonZeroDivisors.ne_zero hq') h) : (RatFunc.liftOn (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [← mk_eq_div, liftOn_mk _ _ f f0 @H'] @[simp] theorem liftOn'_div {P : Sort v} (p q : K[X]) (f : K[X] → K[X] → P) (f0 : ∀ p, f p 0 = f 0 1) (H) : (RatFunc.liftOn' (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) f @H = f p q := by rw [RatFunc.liftOn', liftOn_div _ _ _ f0] apply liftOn_condition_of_liftOn'_condition H /-- Induction principle for `RatFunc K`: if `f p q : P (p / q)` for all `p q : K[X]`, then `P` holds on all elements of `RatFunc K`. See also `induction_on'`, which is a recursion principle defined in terms of `RatFunc.mk`. -/ protected theorem induction_on {P : RatFunc K → Prop} (x : RatFunc K) (f : ∀ (p q : K[X]) (_ : q ≠ 0), P (algebraMap _ (RatFunc K) p / algebraMap _ _ q)) : P x := x.induction_on' fun p q hq => by simpa using f p q hq theorem ofFractionRing_mk' (x : K[X]) (y : K[X]⁰) : ofFractionRing (IsLocalization.mk' _ x y) = IsLocalization.mk' (RatFunc K) x y := by rw [IsFractionRing.mk'_eq_div, IsFractionRing.mk'_eq_div, ← mk_eq_div', ← mk_eq_div] theorem mk_eq_mk' (f : Polynomial K) {g : Polynomial K} (hg : g ≠ 0) : RatFunc.mk f g = IsLocalization.mk' (RatFunc K) f ⟨g, mem_nonZeroDivisors_iff_ne_zero.2 hg⟩ := by simp only [mk_eq_div, IsFractionRing.mk'_eq_div] @[simp] theorem ofFractionRing_eq : (ofFractionRing : FractionRing K[X] → RatFunc K) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun x => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRing_eq : (toFractionRing : RatFunc K → FractionRing K[X]) = IsLocalization.algEquiv K[X]⁰ _ _ := funext fun ⟨x⟩ => Localization.induction_on x fun x => by simp only [Localization.mk_eq_mk'_apply, ofFractionRing_mk', IsLocalization.algEquiv_apply, IsLocalization.map_mk', RingHom.id_apply] @[simp] theorem toFractionRingRingEquiv_symm_eq : (toFractionRingRingEquiv K).symm = (IsLocalization.algEquiv K[X]⁰ _ _).toRingEquiv := by ext x simp [toFractionRingRingEquiv, ofFractionRing_eq, AlgEquiv.coe_ringEquiv'] end IsDomain end IsFractionRing end CommRing section NumDenom /-! ### Numerator and denominator -/ open GCDMonoid Polynomial variable [Field K] open scoped Classical in /-- `RatFunc.numDenom` are numerator and denominator of a rational function over a field, normalized such that the denominator is monic. -/ def numDenom (x : RatFunc K) : K[X] × K[X] := x.liftOn' (fun p q => if q = 0 then ⟨0, 1⟩ else let r := gcd p q ⟨Polynomial.C (q / r).leadingCoeff⁻¹ * (p / r), Polynomial.C (q / r).leadingCoeff⁻¹ * (q / r)⟩) (by intros p q a hq ha dsimp rw [if_neg hq, if_neg (mul_ne_zero ha hq)] have ha' : a.leadingCoeff ≠ 0 := Polynomial.leadingCoeff_ne_zero.mpr ha have hainv : a.leadingCoeff⁻¹ ≠ 0 := inv_ne_zero ha' simp only [Prod.ext_iff, gcd_mul_left, normalize_apply a, Polynomial.coe_normUnit, mul_assoc, CommGroupWithZero.coe_normUnit _ ha'] have hdeg : (gcd p q).degree ≤ q.degree := degree_gcd_le_right _ hq have hdeg' : (Polynomial.C a.leadingCoeff⁻¹ * gcd p q).degree ≤ q.degree := by rw [Polynomial.degree_mul, Polynomial.degree_C hainv, zero_add] exact hdeg have hdivp : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ p := (C_mul_dvd hainv).mpr (gcd_dvd_left p q) have hdivq : Polynomial.C a.leadingCoeff⁻¹ * gcd p q ∣ q := (C_mul_dvd hainv).mpr (gcd_dvd_right p q) rw [EuclideanDomain.mul_div_mul_cancel ha hdivp, EuclideanDomain.mul_div_mul_cancel ha hdivq, leadingCoeff_div hdeg, leadingCoeff_div hdeg', Polynomial.leadingCoeff_mul, Polynomial.leadingCoeff_C, div_C_mul, div_C_mul, ← mul_assoc, ← Polynomial.C_mul, ← mul_assoc, ← Polynomial.C_mul] constructor <;> congr <;> rw [inv_div, mul_comm, mul_div_assoc, ← mul_assoc, inv_inv, mul_inv_cancel₀ ha', one_mul, inv_div]) open scoped Classical in @[simp] theorem numDenom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : numDenom (algebraMap _ _ p / algebraMap _ _ q) = (Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q), Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q)) := by rw [numDenom, liftOn'_div, if_neg hq] intro p rw [if_pos rfl, if_neg (one_ne_zero' K[X])] simp /-- `RatFunc.num` is the numerator of a rational function, normalized such that the denominator is monic. -/ def num (x : RatFunc K) : K[X] := x.numDenom.1 open scoped Classical in private theorem num_div' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by rw [num, numDenom_div _ hq] @[simp] theorem num_zero : num (0 : RatFunc K) = 0 := by convert num_div' (0 : K[X]) one_ne_zero <;> simp open scoped Classical in @[simp] theorem num_div (p q : K[X]) : num (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) := by by_cases hq : q = 0 · simp [hq] · exact num_div' p hq @[simp] theorem num_one : num (1 : RatFunc K) = 1 := by convert num_div (1 : K[X]) 1 <;> simp @[simp] theorem num_algebraMap (p : K[X]) : num (algebraMap _ _ p) = p := by convert num_div p 1 <;> simp theorem num_div_dvd (p : K[X]) {q : K[X]} (hq : q ≠ 0) : num (algebraMap _ _ p / algebraMap _ _ q) ∣ p := by classical rw [num_div _ q, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_left p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq open scoped Classical in /-- A version of `num_div_dvd` with the LHS in simp normal form -/ @[simp] theorem num_div_dvd' (p : K[X]) {q : K[X]} (hq : q ≠ 0) : C (q / gcd p q).leadingCoeff⁻¹ * (p / gcd p q) ∣ p := by simpa using num_div_dvd p hq /-- `RatFunc.denom` is the denominator of a rational function, normalized such that it is monic. -/ def denom (x : RatFunc K) : K[X] := x.numDenom.2 open scoped Classical in @[simp] theorem denom_div (p : K[X]) {q : K[X]} (hq : q ≠ 0) : denom (algebraMap _ _ p / algebraMap _ _ q) = Polynomial.C (q / gcd p q).leadingCoeff⁻¹ * (q / gcd p q) := by rw [denom, numDenom_div _ hq] theorem monic_denom (x : RatFunc K) : (denom x).Monic := by classical induction x using RatFunc.induction_on with | f p q hq => rw [denom_div p hq, mul_comm] exact Polynomial.monic_mul_leadingCoeff_inv (right_div_gcd_ne_zero hq) theorem denom_ne_zero (x : RatFunc K) : denom x ≠ 0 := (monic_denom x).ne_zero @[simp] theorem denom_zero : denom (0 : RatFunc K) = 1 := by convert denom_div (0 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_one : denom (1 : RatFunc K) = 1 := by convert denom_div (1 : K[X]) one_ne_zero <;> simp @[simp] theorem denom_algebraMap (p : K[X]) : denom (algebraMap _ (RatFunc K) p) = 1 := by convert denom_div p one_ne_zero <;> simp @[simp] theorem denom_div_dvd (p q : K[X]) : denom (algebraMap _ _ p / algebraMap _ _ q) ∣ q := by classical by_cases hq : q = 0 · simp [hq] rw [denom_div _ hq, C_mul_dvd] · exact EuclideanDomain.div_dvd_of_dvd (gcd_dvd_right p q) · simpa only [Ne, inv_eq_zero, Polynomial.leadingCoeff_eq_zero] using right_div_gcd_ne_zero hq @[simp] theorem num_div_denom (x : RatFunc K) : algebraMap _ _ (num x) / algebraMap _ _ (denom x) = x := by classical induction' x using RatFunc.induction_on with p q hq have q_div_ne_zero : q / gcd p q ≠ 0 := right_div_gcd_ne_zero hq rw [num_div p q, denom_div p hq, RingHom.map_mul, RingHom.map_mul, mul_div_mul_left, div_eq_div_iff, ← RingHom.map_mul, ← RingHom.map_mul, mul_comm _ q, ← EuclideanDomain.mul_div_assoc, ← EuclideanDomain.mul_div_assoc, mul_comm] · apply gcd_dvd_right · apply gcd_dvd_left · exact algebraMap_ne_zero q_div_ne_zero · exact algebraMap_ne_zero hq · refine algebraMap_ne_zero (mt Polynomial.C_eq_zero.mp ?_) exact inv_ne_zero (Polynomial.leadingCoeff_ne_zero.mpr q_div_ne_zero) theorem isCoprime_num_denom (x : RatFunc K) : IsCoprime x.num x.denom := by classical induction' x using RatFunc.induction_on with p q hq rw [num_div, denom_div _ hq] exact (isCoprime_mul_unit_left ((leadingCoeff_ne_zero.2 <| right_div_gcd_ne_zero hq).isUnit.inv.map C) _ _).2 (isCoprime_div_gcd_div_gcd hq) @[simp] theorem num_eq_zero_iff {x : RatFunc K} : num x = 0 ↔ x = 0 := ⟨fun h => by rw [← num_div_denom x, h, RingHom.map_zero, zero_div], fun h => h.symm ▸ num_zero⟩ theorem num_ne_zero {x : RatFunc K} (hx : x ≠ 0) : num x ≠ 0 := mt num_eq_zero_iff.mp hx theorem num_mul_eq_mul_denom_iff {x : RatFunc K} {p q : K[X]} (hq : q ≠ 0) : x.num * q = p * x.denom ↔ x = algebraMap _ _ p / algebraMap _ _ q := by rw [← (algebraMap_injective K).eq_iff, eq_div_iff (algebraMap_ne_zero hq)] conv_rhs => rw [← num_div_denom x] rw [RingHom.map_mul, RingHom.map_mul, div_eq_mul_inv, mul_assoc, mul_comm (Inv.inv _), ← mul_assoc, ← div_eq_mul_inv, div_eq_iff] exact algebraMap_ne_zero (denom_ne_zero x) theorem num_denom_add (x y : RatFunc K) : (x + y).num * (x.denom * y.denom) = (x.num * y.denom + x.denom * y.num) * (x + y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y] rw [div_add_div, RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) theorem num_denom_neg (x : RatFunc K) : (-x).num * x.denom = -x.num * (-x).denom := by rw [num_mul_eq_mul_denom_iff (denom_ne_zero x), map_neg, neg_div, num_div_denom] theorem num_denom_mul (x y : RatFunc K) : (x * y).num * (x.denom * y.denom) = x.num * y.num * (x * y).denom := (num_mul_eq_mul_denom_iff (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))).mpr <| by conv_lhs => rw [← num_div_denom x, ← num_div_denom y, div_mul_div_comm, ← RingHom.map_mul, ← RingHom.map_mul] theorem num_dvd {x : RatFunc K} {p : K[X]} (hp : p ≠ 0) : num x ∣ p ↔ ∃ q : K[X], q ≠ 0 ∧ x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨q, rfl⟩ obtain ⟨_hx, hq⟩ := mul_ne_zero_iff.mp hp use denom x * q rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] · exact ⟨mul_ne_zero (denom_ne_zero x) hq, rfl⟩ · exact algebraMap_ne_zero hq · rintro ⟨q, hq, rfl⟩ exact num_div_dvd p hq theorem denom_dvd {x : RatFunc K} {q : K[X]} (hq : q ≠ 0) : denom x ∣ q ↔ ∃ p : K[X], x = algebraMap _ _ p / algebraMap _ _ q := by constructor · rintro ⟨p, rfl⟩ obtain ⟨_hx, hp⟩ := mul_ne_zero_iff.mp hq use num x * p rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, div_self, mul_one, num_div_denom] exact algebraMap_ne_zero hp · rintro ⟨p, rfl⟩ exact denom_div_dvd p q theorem num_mul_dvd (x y : RatFunc K) : num (x * y) ∣ num x * num y := by by_cases hx : x = 0 · simp [hx] by_cases hy : y = 0 · simp [hy] rw [num_dvd (mul_ne_zero (num_ne_zero hx) (num_ne_zero hy))] refine ⟨x.denom * y.denom, mul_ne_zero (denom_ne_zero x) (denom_ne_zero y), ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] theorem denom_mul_dvd (x y : RatFunc K) : denom (x * y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_mul, ← div_mul_div_comm, num_div_denom, num_div_denom] theorem denom_add_dvd (x y : RatFunc K) : denom (x + y) ∣ denom x * denom y := by rw [denom_dvd (mul_ne_zero (denom_ne_zero x) (denom_ne_zero y))] refine ⟨x.num * y.denom + x.denom * y.num, ?_⟩ rw [RingHom.map_mul, RingHom.map_add, RingHom.map_mul, RingHom.map_mul, ← div_add_div, num_div_denom, num_div_denom] · exact algebraMap_ne_zero (denom_ne_zero x) · exact algebraMap_ne_zero (denom_ne_zero y) theorem map_denom_ne_zero {L F : Type*} [Zero L] [FunLike F K[X] L] [ZeroHomClass F K[X] L] (φ : F) (hφ : Function.Injective φ) (f : RatFunc K) : φ f.denom ≠ 0 := fun H =>
(denom_ne_zero f) ((map_eq_zero_iff φ hφ).mp H)
Mathlib/FieldTheory/RatFunc/Basic.lean
974
975
/- 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.Field.Basic import Mathlib.Algebra.Field.Rat import Mathlib.Algebra.Group.Commute.Basic import Mathlib.Algebra.GroupWithZero.Units.Lemmas import Mathlib.Data.Int.Cast.Lemmas import Mathlib.Data.Rat.Lemmas import Mathlib.Order.Nat /-! # Casts for Rational Numbers ## Summary We define the canonical injection from ℚ into an arbitrary division ring and prove various casting lemmas showing the well-behavedness of this injection. ## Tags rat, rationals, field, ℚ, numerator, denominator, num, denom, cast, coercion, casting -/ assert_not_exists MulAction OrderedAddCommMonoid variable {F ι α β : Type*} namespace NNRat variable [DivisionSemiring α] {q r : ℚ≥0} @[simp, norm_cast] lemma cast_natCast (n : ℕ) : ((n : ℚ≥0) : α) = n := by simp [cast_def] @[simp, norm_cast] lemma cast_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℚ≥0) = (ofNat(n) : α) := cast_natCast _ @[simp, norm_cast] lemma cast_zero : ((0 : ℚ≥0) : α) = 0 := (cast_natCast _).trans Nat.cast_zero @[simp, norm_cast] lemma cast_one : ((1 : ℚ≥0) : α) = 1 := (cast_natCast _).trans Nat.cast_one lemma cast_commute (q : ℚ≥0) (a : α) : Commute (↑q) a := by simpa only [cast_def] using (q.num.cast_commute a).div_left (q.den.cast_commute a) lemma commute_cast (a : α) (q : ℚ≥0) : Commute a q := (cast_commute ..).symm lemma cast_comm (q : ℚ≥0) (a : α) : q * a = a * q := cast_commute _ _ @[norm_cast] lemma cast_divNat_of_ne_zero (a : ℕ) {b : ℕ} (hb : (b : α) ≠ 0) : divNat a b = (a / b : α) := by rcases e : divNat a b with ⟨⟨n, d, h, c⟩, hn⟩ rw [← Rat.num_nonneg] at hn lift n to ℕ using hn have hd : (d : α) ≠ 0 := by refine fun hd ↦ hb ?_ have : Rat.divInt a b = _ := congr_arg NNRat.cast e obtain ⟨k, rfl⟩ : d ∣ b := by simpa [Int.natCast_dvd_natCast, this] using Rat.den_dvd a b simp [*] have hb' : b ≠ 0 := by rintro rfl; exact hb Nat.cast_zero have hd' : d ≠ 0 := by rintro rfl; exact hd Nat.cast_zero simp_rw [Rat.mk'_eq_divInt, mk_divInt, divNat_inj hb' hd'] at e rw [cast_def] dsimp rw [Commute.div_eq_div_iff _ hd hb] · norm_cast rw [e] exact b.commute_cast _ @[norm_cast] lemma cast_add_of_ne_zero (hq : (q.den : α) ≠ 0) (hr : (r.den : α) ≠ 0) : ↑(q + r) = (q + r : α) := by rw [add_def, cast_divNat_of_ne_zero, cast_def, cast_def, mul_comm _ q.den, (Nat.commute_cast _ _).div_add_div (Nat.commute_cast _ _) hq hr] · push_cast rfl · push_cast exact mul_ne_zero hq hr @[norm_cast] lemma cast_mul_of_ne_zero (hq : (q.den : α) ≠ 0) (hr : (r.den : α) ≠ 0) : ↑(q * r) = (q * r : α) := by rw [mul_def, cast_divNat_of_ne_zero, cast_def, cast_def, (Nat.commute_cast _ _).div_mul_div_comm (Nat.commute_cast _ _)] · push_cast rfl · push_cast exact mul_ne_zero hq hr @[norm_cast] lemma cast_inv_of_ne_zero (hq : (q.num : α) ≠ 0) : (q⁻¹ : ℚ≥0) = (q⁻¹ : α) := by rw [inv_def, cast_divNat_of_ne_zero _ hq, cast_def, inv_div] @[norm_cast] lemma cast_div_of_ne_zero (hq : (q.den : α) ≠ 0) (hr : (r.num : α) ≠ 0) : ↑(q / r) = (q / r : α) := by rw [div_def, cast_divNat_of_ne_zero, cast_def, cast_def, div_eq_mul_inv (_ / _), inv_div, (Nat.commute_cast _ _).div_mul_div_comm (Nat.commute_cast _ _)] · push_cast rfl · push_cast exact mul_ne_zero hq hr end NNRat namespace Rat variable [DivisionRing α] {p q : ℚ} @[simp, norm_cast] theorem cast_intCast (n : ℤ) : ((n : ℚ) : α) = n := (cast_def _).trans <| show (n / (1 : ℕ) : α) = n by rw [Nat.cast_one, div_one] @[simp, norm_cast] theorem cast_natCast (n : ℕ) : ((n : ℚ) : α) = n := by rw [← Int.cast_natCast, cast_intCast, Int.cast_natCast] @[simp, norm_cast] lemma cast_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℚ) : α) = (ofNat(n) : α) := by simp [cast_def] @[simp, norm_cast] theorem cast_zero : ((0 : ℚ) : α) = 0 := (cast_intCast _).trans Int.cast_zero @[simp, norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1 := (cast_intCast _).trans Int.cast_one theorem cast_commute (r : ℚ) (a : α) : Commute (↑r) a := by simpa only [cast_def] using (r.1.cast_commute a).div_left (r.2.cast_commute a) theorem cast_comm (r : ℚ) (a : α) : (r : α) * a = a * r := (cast_commute r a).eq theorem commute_cast (a : α) (r : ℚ) : Commute a r := (r.cast_commute a).symm @[norm_cast] lemma cast_divInt_of_ne_zero (a : ℤ) {b : ℤ} (b0 : (b : α) ≠ 0) : (a /. b : α) = a / b := by have b0' : b ≠ 0 := by refine mt ?_ b0 simp +contextual rcases e : a /. b with ⟨n, d, h, c⟩ have d0 : (d : α) ≠ 0 := by intro d0 have dd := den_dvd a b rcases show (d : ℤ) ∣ b by rwa [e] at dd with ⟨k, ke⟩ have : (b : α) = (d : α) * (k : α) := by rw [ke, Int.cast_mul, Int.cast_natCast] rw [d0, zero_mul] at this contradiction rw [mk'_eq_divInt] at e have := congr_arg ((↑) : ℤ → α) ((divInt_eq_iff b0' <| ne_of_gt <| Int.natCast_pos.2 h.bot_lt).1 e) rw [Int.cast_mul, Int.cast_mul, Int.cast_natCast] at this rw [eq_comm, cast_def, div_eq_mul_inv, eq_div_iff_mul_eq d0, mul_assoc, (d.commute_cast _).eq, ← mul_assoc, this, mul_assoc, mul_inv_cancel₀ b0, mul_one] @[norm_cast] lemma cast_mkRat_of_ne_zero (a : ℤ) {b : ℕ} (hb : (b : α) ≠ 0) : (mkRat a b : α) = a / b := by rw [Rat.mkRat_eq_divInt, cast_divInt_of_ne_zero, Int.cast_natCast]; rwa [Int.cast_natCast] @[norm_cast] lemma cast_add_of_ne_zero {q r : ℚ} (hq : (q.den : α) ≠ 0) (hr : (r.den : α) ≠ 0) : (q + r : ℚ) = (q + r : α) := by rw [add_def', cast_mkRat_of_ne_zero, cast_def, cast_def, mul_comm r.num, (Nat.cast_commute _ _).div_add_div (Nat.commute_cast _ _) hq hr] · push_cast rfl · push_cast exact mul_ne_zero hq hr @[simp, norm_cast] lemma cast_neg (q : ℚ) : ↑(-q) = (-q : α) := by simp [cast_def, neg_div] @[norm_cast] lemma cast_sub_of_ne_zero (hp : (p.den : α) ≠ 0) (hq : (q.den : α) ≠ 0) : ↑(p - q) = (p - q : α) := by simp [sub_eq_add_neg, cast_add_of_ne_zero, hp, hq] @[norm_cast] lemma cast_mul_of_ne_zero (hp : (p.den : α) ≠ 0) (hq : (q.den : α) ≠ 0) : ↑(p * q) = (p * q : α) := by rw [mul_eq_mkRat, cast_mkRat_of_ne_zero, cast_def, cast_def, (Nat.commute_cast _ _).div_mul_div_comm (Int.commute_cast _ _)] · push_cast rfl · push_cast exact mul_ne_zero hp hq @[norm_cast] lemma cast_inv_of_ne_zero (hq : (q.num : α) ≠ 0) : ↑(q⁻¹) = (q⁻¹ : α) := by rw [inv_def', cast_divInt_of_ne_zero _ hq, cast_def, inv_div, Int.cast_natCast] @[norm_cast] lemma cast_div_of_ne_zero (hp : (p.den : α) ≠ 0) (hq : (q.num : α) ≠ 0) : ↑(p / q) = (p / q : α) := by rw [div_def', cast_divInt_of_ne_zero, cast_def, cast_def, div_eq_mul_inv (_ / _), inv_div, (Int.commute_cast _ _).div_mul_div_comm (Nat.commute_cast _ _)] · push_cast rfl · push_cast exact mul_ne_zero hp hq end Rat open Rat variable [FunLike F α β] @[simp] lemma map_nnratCast [DivisionSemiring α] [DivisionSemiring β] [RingHomClass F α β] (f : F) (q : ℚ≥0) : f q = q := by simp_rw [NNRat.cast_def, map_div₀, map_natCast] @[simp] lemma eq_nnratCast [DivisionSemiring α] [FunLike F ℚ≥0 α] [RingHomClass F ℚ≥0 α] (f : F) (q : ℚ≥0) : f q = q := by rw [← map_nnratCast f, NNRat.cast_id] @[simp] theorem map_ratCast [DivisionRing α] [DivisionRing β] [RingHomClass F α β] (f : F) (q : ℚ) : f q = q := by rw [cast_def, map_div₀, map_intCast, map_natCast, cast_def] @[simp] lemma eq_ratCast [DivisionRing α] [FunLike F ℚ α] [RingHomClass F ℚ α] (f : F) (q : ℚ) : f q = q := by rw [← map_ratCast f, Rat.cast_id] namespace MonoidWithZeroHomClass variable {M₀ : Type*} [MonoidWithZero M₀] section NNRat variable [FunLike F ℚ≥0 M₀] [MonoidWithZeroHomClass F ℚ≥0 M₀] {f g : F} /-- If monoid with zero homs `f` and `g` from `ℚ≥0` agree on the naturals then they are equal. -/ lemma ext_nnrat' (h : ∀ n : ℕ, f n = g n) : f = g := (DFunLike.ext f g) fun r => by rw [← r.num_div_den, div_eq_mul_inv, map_mul, map_mul, h, eq_on_inv₀ f g]
apply h /-- If monoid with zero homs `f` and `g` from `ℚ≥0` agree on the naturals then they are equal.
Mathlib/Data/Rat/Cast/Defs.lean
231
233
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Mathlib.Logic.Basic import Mathlib.Logic.Function.Defs import Mathlib.Order.Defs.LinearOrder /-! # Booleans This file proves various trivial lemmas about booleans and their relation to decidable propositions. ## Tags bool, boolean, Bool, De Morgan -/ namespace Bool section /-! This section contains lemmas about booleans which were present in core Lean 3. The remainder of this file contains lemmas about booleans from mathlib 3. -/ theorem true_eq_false_eq_False : ¬true = false := by decide theorem false_eq_true_eq_False : ¬false = true := by decide theorem eq_false_eq_not_eq_true (b : Bool) : (¬b = true) = (b = false) := by simp theorem eq_true_eq_not_eq_false (b : Bool) : (¬b = false) = (b = true) := by simp theorem eq_false_of_not_eq_true {b : Bool} : ¬b = true → b = false := Eq.mp (eq_false_eq_not_eq_true b) theorem eq_true_of_not_eq_false {b : Bool} : ¬b = false → b = true := Eq.mp (eq_true_eq_not_eq_false b) theorem and_eq_true_eq_eq_true_and_eq_true (a b : Bool) : ((a && b) = true) = (a = true ∧ b = true) := by simp theorem or_eq_true_eq_eq_true_or_eq_true (a b : Bool) : ((a || b) = true) = (a = true ∨ b = true) := by simp theorem not_eq_true_eq_eq_false (a : Bool) : (not a = true) = (a = false) := by cases a <;> simp #adaptation_note /-- nightly-2024-03-05 this is no longer a simp lemma, as the LHS simplifies. -/ theorem and_eq_false_eq_eq_false_or_eq_false (a b : Bool) : ((a && b) = false) = (a = false ∨ b = false) := by cases a <;> cases b <;> simp theorem or_eq_false_eq_eq_false_and_eq_false (a b : Bool) : ((a || b) = false) = (a = false ∧ b = false) := by cases a <;> cases b <;> simp theorem not_eq_false_eq_eq_true (a : Bool) : (not a = false) = (a = true) := by cases a <;> simp theorem coe_false : ↑false = False := by simp theorem coe_true : ↑true = True := by simp theorem coe_sort_false : (false : Prop) = False := by simp theorem coe_sort_true : (true : Prop) = True := by simp theorem decide_iff (p : Prop) [d : Decidable p] : decide p = true ↔ p := by simp theorem decide_true {p : Prop} [Decidable p] : p → decide p := (decide_iff p).2 theorem of_decide_true {p : Prop} [Decidable p] : decide p → p := (decide_iff p).1 theorem bool_iff_false {b : Bool} : ¬b ↔ b = false := by cases b <;> decide theorem bool_eq_false {b : Bool} : ¬b → b = false := bool_iff_false.1 theorem decide_false_iff (p : Prop) {_ : Decidable p} : decide p = false ↔ ¬p := bool_iff_false.symm.trans (not_congr (decide_iff _)) theorem decide_false {p : Prop} [Decidable p] : ¬p → decide p = false := (decide_false_iff p).2 theorem of_decide_false {p : Prop} [Decidable p] : decide p = false → ¬p := (decide_false_iff p).1 theorem decide_congr {p q : Prop} [Decidable p] [Decidable q] (h : p ↔ q) : decide p = decide q := decide_eq_decide.mpr h theorem coe_xor_iff (a b : Bool) : xor a b ↔ Xor' (a = true) (b = true) := by cases a <;> cases b <;> decide end theorem dichotomy (b : Bool) : b = false ∨ b = true := by cases b <;> simp theorem not_ne_id : not ≠ id := fun h ↦ false_ne_true <| congrFun h true theorem or_inl {a b : Bool} (H : a) : a || b := by simp [H] theorem or_inr {a b : Bool} (H : b) : a || b := by cases a <;> simp [H] theorem and_elim_left : ∀ {a b : Bool}, a && b → a := by decide theorem and_intro : ∀ {a b : Bool}, a → b → a && b := by decide theorem and_elim_right : ∀ {a b : Bool}, a && b → b := by decide lemma eq_not_iff : ∀ {a b : Bool}, a = !b ↔ a ≠ b := by decide lemma not_eq_iff : ∀ {a b : Bool}, !a = b ↔ a ≠ b := by decide theorem ne_not {a b : Bool} : a ≠ !b ↔ a = b := not_eq_not lemma not_ne_self : ∀ b : Bool, (!b) ≠ b := by decide lemma self_ne_not : ∀ b : Bool, b ≠ !b := by decide lemma eq_or_eq_not : ∀ a b, a = b ∨ a = !b := by decide -- TODO naming issue: these two `not` are different. theorem not_iff_not : ∀ {b : Bool}, !b ↔ ¬b := by simp theorem eq_true_of_not_eq_false' {a : Bool} : !a = false → a = true := by cases a <;> decide theorem eq_false_of_not_eq_true' {a : Bool} : !a = true → a = false := by cases a <;> decide theorem bne_eq_xor : bne = xor := by funext a b; revert a b; decide attribute [simp] xor_assoc theorem xor_iff_ne : ∀ {x y : Bool}, xor x y = true ↔ x ≠ y := by decide /-! ### De Morgan's laws for booleans -/ instance linearOrder : LinearOrder Bool where le_refl := by decide le_trans := by decide le_antisymm := by decide le_total := by decide toDecidableLE := inferInstance toDecidableEq := inferInstance toDecidableLT := inferInstance lt_iff_le_not_le := by decide max_def := by decide min_def := by decide theorem lt_iff : ∀ {x y : Bool}, x < y ↔ x = false ∧ y = true := by decide @[simp] theorem false_lt_true : false < true := lt_iff.2 ⟨rfl, rfl⟩ theorem le_iff_imp : ∀ {x y : Bool}, x ≤ y ↔ x → y := by decide theorem and_le_left : ∀ x y : Bool, (x && y) ≤ x := by decide theorem and_le_right : ∀ x y : Bool, (x && y) ≤ y := by decide theorem le_and : ∀ {x y z : Bool}, x ≤ y → x ≤ z → x ≤ (y && z) := by decide theorem left_le_or : ∀ x y : Bool, x ≤ (x || y) := by decide theorem right_le_or : ∀ x y : Bool, y ≤ (x || y) := by decide theorem or_le : ∀ {x y z}, x ≤ z → y ≤ z → (x || y) ≤ z := by decide /-- convert a `ℕ` to a `Bool`, `0 -> false`, everything else -> `true` -/ def ofNat (n : Nat) : Bool := decide (n ≠ 0) @[simp] lemma toNat_beq_zero (b : Bool) : (b.toNat == 0) = !b := by cases b <;> rfl @[simp] lemma toNat_bne_zero (b : Bool) : (b.toNat != 0) = b := by simp [bne] @[simp] lemma toNat_beq_one (b : Bool) : (b.toNat == 1) = b := by cases b <;> rfl @[simp] lemma toNat_bne_one (b : Bool) : (b.toNat != 1) = !b := by simp [bne] theorem ofNat_le_ofNat {n m : Nat} (h : n ≤ m) : ofNat n ≤ ofNat m := by simp only [ofNat, ne_eq, _root_.decide_not] cases Nat.decEq n 0 with | isTrue hn => rw [_root_.decide_eq_true hn]; exact Bool.false_le _ | isFalse hn => cases Nat.decEq m 0 with | isFalse hm => rw [_root_.decide_eq_false hm]; exact Bool.le_true _ | isTrue hm => subst hm; have h := Nat.le_antisymm h (Nat.zero_le n); contradiction theorem toNat_le_toNat {b₀ b₁ : Bool} (h : b₀ ≤ b₁) : toNat b₀ ≤ toNat b₁ := by cases b₀ <;> cases b₁ <;> simp_all +decide theorem ofNat_toNat (b : Bool) : ofNat (toNat b) = b := by cases b <;> rfl @[simp] theorem injective_iff {α : Sort*} {f : Bool → α} : Function.Injective f ↔ f false ≠ f true := ⟨fun Hinj Heq ↦ false_ne_true (Hinj Heq), fun H x y hxy ↦ by cases x <;> cases y · rfl · exact (H hxy).elim · exact (H hxy.symm).elim · rfl⟩ /-- **Kaminski's Equation** -/ theorem apply_apply_apply (f : Bool → Bool) (x : Bool) : f (f (f x)) = f x := by cases x <;> cases h₁ : f true <;> cases h₂ : f false <;> simp only [h₁, h₂] /-- `xor3 x y c` is `((x XOR y) XOR c)`. -/ protected def xor3 (x y c : Bool) := xor (xor x y) c /-- `carry x y c` is `x && y || x && c || y && c`. -/ protected def carry (x y c : Bool) := x && y || x && c || y && c end Bool
Mathlib/Data/Bool/Basic.lean
251
258
/- Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro -/ import Mathlib.Algebra.Group.Nat.Defs import Mathlib.Algebra.Group.Basic import Mathlib.Data.Nat.Bits /-! Lemmas about `size`. -/ namespace Nat /-! ### `shiftLeft` and `shiftRight` -/ section theorem shiftLeft_eq_mul_pow (m) : ∀ n, m <<< n = m * 2 ^ n := shiftLeft_eq _ theorem shiftLeft'_tt_eq_mul_pow (m) : ∀ n, shiftLeft' true m n + 1 = (m + 1) * 2 ^ n | 0 => by simp [shiftLeft', pow_zero, Nat.one_mul] | k + 1 => by rw [shiftLeft', bit_val, Bool.toNat_true, add_assoc, ← Nat.mul_add_one, shiftLeft'_tt_eq_mul_pow m k, mul_left_comm, mul_comm 2, pow_succ] end theorem shiftLeft'_ne_zero_left (b) {m} (h : m ≠ 0) (n) : shiftLeft' b m n ≠ 0 := by induction n <;> simp [bit_ne_zero, shiftLeft', *] theorem shiftLeft'_tt_ne_zero (m) : ∀ {n}, (n ≠ 0) → shiftLeft' true m n ≠ 0 | 0, h => absurd rfl h | succ _, _ => by dsimp [shiftLeft', bit]; omega /-! ### `size` -/ @[simp] theorem size_zero : size 0 = 0 := by simp [size] @[simp] theorem size_bit {b n} (h : bit b n ≠ 0) : size (bit b n) = succ (size n) := by unfold size conv => lhs rw [binaryRec] simp [h] section
@[simp]
Mathlib/Data/Nat/Size.lean
51
51
/- Copyright (c) 2019 Gabriel Ebner. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner, Anatole Dedecker, Yury Kudryashov -/ import Mathlib.Analysis.Calculus.Deriv.Basic import Mathlib.Analysis.Calculus.FDeriv.Mul import Mathlib.Analysis.Calculus.FDeriv.Add /-! # Derivative of `f x * g x` In this file we prove formulas for `(f x * g x)'` and `(f x • g x)'`. For a more detailed overview of one-dimensional derivatives in mathlib, see the module docstring of `Analysis/Calculus/Deriv/Basic`. ## Keywords derivative, multiplication -/ universe u v w noncomputable section open scoped Topology Filter ENNReal open Filter Asymptotics Set open ContinuousLinearMap (smulRight smulRight_one_eq_iff) variable {𝕜 : Type u} [NontriviallyNormedField 𝕜] variable {F : Type v} [NormedAddCommGroup F] [NormedSpace 𝕜 F] variable {E : Type w} [NormedAddCommGroup E] [NormedSpace 𝕜 E] variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] variable {f : 𝕜 → F} variable {f' : F} variable {x : 𝕜} variable {s : Set 𝕜} variable {L : Filter 𝕜} /-! ### Derivative of bilinear maps -/ namespace ContinuousLinearMap variable {B : E →L[𝕜] F →L[𝕜] G} {u : 𝕜 → E} {v : 𝕜 → F} {u' : E} {v' : F} theorem hasDerivWithinAt_of_bilinear (hu : HasDerivWithinAt u u' s x) (hv : HasDerivWithinAt v v' s x) : HasDerivWithinAt (fun x ↦ B (u x) (v x)) (B (u x) v' + B u' (v x)) s x := by simpa using (B.hasFDerivWithinAt_of_bilinear hu.hasFDerivWithinAt hv.hasFDerivWithinAt).hasDerivWithinAt theorem hasDerivAt_of_bilinear (hu : HasDerivAt u u' x) (hv : HasDerivAt v v' x) : HasDerivAt (fun x ↦ B (u x) (v x)) (B (u x) v' + B u' (v x)) x := by simpa using (B.hasFDerivAt_of_bilinear hu.hasFDerivAt hv.hasFDerivAt).hasDerivAt theorem hasStrictDerivAt_of_bilinear (hu : HasStrictDerivAt u u' x) (hv : HasStrictDerivAt v v' x) : HasStrictDerivAt (fun x ↦ B (u x) (v x)) (B (u x) v' + B u' (v x)) x := by simpa using (B.hasStrictFDerivAt_of_bilinear hu.hasStrictFDerivAt hv.hasStrictFDerivAt).hasStrictDerivAt theorem derivWithin_of_bilinear (hu : DifferentiableWithinAt 𝕜 u s x) (hv : DifferentiableWithinAt 𝕜 v s x) : derivWithin (fun y => B (u y) (v y)) s x = B (u x) (derivWithin v s x) + B (derivWithin u s x) (v x) := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (B.hasDerivWithinAt_of_bilinear hu.hasDerivWithinAt hv.hasDerivWithinAt).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem deriv_of_bilinear (hu : DifferentiableAt 𝕜 u x) (hv : DifferentiableAt 𝕜 v x) : deriv (fun y => B (u y) (v y)) x = B (u x) (deriv v x) + B (deriv u x) (v x) := (B.hasDerivAt_of_bilinear hu.hasDerivAt hv.hasDerivAt).deriv end ContinuousLinearMap section SMul /-! ### Derivative of the multiplication of a scalar function and a vector function -/ variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] [NormedSpace 𝕜' F] [IsScalarTower 𝕜 𝕜' F] {c : 𝕜 → 𝕜'} {c' : 𝕜'} theorem HasDerivWithinAt.smul (hc : HasDerivWithinAt c c' s x) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun y => c y • f y) (c x • f' + c' • f x) s x := by simpa using (HasFDerivWithinAt.smul hc hf).hasDerivWithinAt theorem HasDerivAt.smul (hc : HasDerivAt c c' x) (hf : HasDerivAt f f' x) : HasDerivAt (fun y => c y • f y) (c x • f' + c' • f x) x := by rw [← hasDerivWithinAt_univ] at * exact hc.smul hf nonrec theorem HasStrictDerivAt.smul (hc : HasStrictDerivAt c c' x) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y => c y • f y) (c x • f' + c' • f x) x := by simpa using (hc.smul hf).hasStrictDerivAt theorem derivWithin_smul (hc : DifferentiableWithinAt 𝕜 c s x) (hf : DifferentiableWithinAt 𝕜 f s x) : derivWithin (fun y => c y • f y) s x = c x • derivWithin f s x + derivWithin c s x • f x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.smul hf.hasDerivWithinAt).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem deriv_smul (hc : DifferentiableAt 𝕜 c x) (hf : DifferentiableAt 𝕜 f x) : deriv (fun y => c y • f y) x = c x • deriv f x + deriv c x • f x := (hc.hasDerivAt.smul hf.hasDerivAt).deriv theorem HasStrictDerivAt.smul_const (hc : HasStrictDerivAt c c' x) (f : F) : HasStrictDerivAt (fun y => c y • f) (c' • f) x := by have := hc.smul (hasStrictDerivAt_const x f) rwa [smul_zero, zero_add] at this theorem HasDerivWithinAt.smul_const (hc : HasDerivWithinAt c c' s x) (f : F) : HasDerivWithinAt (fun y => c y • f) (c' • f) s x := by have := hc.smul (hasDerivWithinAt_const x s f) rwa [smul_zero, zero_add] at this theorem HasDerivAt.smul_const (hc : HasDerivAt c c' x) (f : F) : HasDerivAt (fun y => c y • f) (c' • f) x := by rw [← hasDerivWithinAt_univ] at * exact hc.smul_const f theorem derivWithin_smul_const (hc : DifferentiableWithinAt 𝕜 c s x) (f : F) : derivWithin (fun y => c y • f) s x = derivWithin c s x • f := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.smul_const f).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem deriv_smul_const (hc : DifferentiableAt 𝕜 c x) (f : F) : deriv (fun y => c y • f) x = deriv c x • f := (hc.hasDerivAt.smul_const f).deriv end SMul section ConstSMul variable {R : Type*} [Semiring R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] nonrec theorem HasStrictDerivAt.const_smul (c : R) (hf : HasStrictDerivAt f f' x) : HasStrictDerivAt (fun y => c • f y) (c • f') x := by simpa using (hf.const_smul c).hasStrictDerivAt nonrec theorem HasDerivAtFilter.const_smul (c : R) (hf : HasDerivAtFilter f f' x L) : HasDerivAtFilter (fun y => c • f y) (c • f') x L := by simpa using (hf.const_smul c).hasDerivAtFilter nonrec theorem HasDerivWithinAt.const_smul (c : R) (hf : HasDerivWithinAt f f' s x) : HasDerivWithinAt (fun y => c • f y) (c • f') s x := hf.const_smul c nonrec theorem HasDerivAt.const_smul (c : R) (hf : HasDerivAt f f' x) : HasDerivAt (fun y => c • f y) (c • f') x := hf.const_smul c theorem derivWithin_const_smul (c : R) (hf : DifferentiableWithinAt 𝕜 f s x) : derivWithin (fun y => c • f y) s x = c • derivWithin f s x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hf.hasDerivWithinAt.const_smul c).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem deriv_const_smul (c : R) (hf : DifferentiableAt 𝕜 f x) : deriv (fun y => c • f y) x = c • deriv f x := (hf.hasDerivAt.const_smul c).deriv /-- A variant of `deriv_const_smul` without differentiability assumption when the scalar multiplication is by field elements. -/ lemma deriv_const_smul' {f : 𝕜 → F} {x : 𝕜} {R : Type*} [Field R] [Module R F] [SMulCommClass 𝕜 R F] [ContinuousConstSMul R F] (c : R) : deriv (fun y ↦ c • f y) x = c • deriv f x := by by_cases hf : DifferentiableAt 𝕜 f x · exact deriv_const_smul c hf · rcases eq_or_ne c 0 with rfl | hc · simp only [zero_smul, deriv_const'] · have H : ¬DifferentiableAt 𝕜 (fun y ↦ c • f y) x := by contrapose! hf conv => enter [2, y]; rw [← inv_smul_smul₀ hc (f y)] exact DifferentiableAt.const_smul hf c⁻¹ rw [deriv_zero_of_not_differentiableAt hf, deriv_zero_of_not_differentiableAt H, smul_zero] end ConstSMul section Mul /-! ### Derivative of the multiplication of two functions -/ variable {𝕜' 𝔸 : Type*} [NormedField 𝕜'] [NormedRing 𝔸] [NormedAlgebra 𝕜 𝕜'] [NormedAlgebra 𝕜 𝔸] {c d : 𝕜 → 𝔸} {c' d' : 𝔸} {u v : 𝕜 → 𝕜'} theorem HasDerivWithinAt.mul (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) : HasDerivWithinAt (fun y => c y * d y) (c' * d x + c x * d') s x := by have := (HasFDerivWithinAt.mul' hc hd).hasDerivWithinAt rwa [ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivAt.mul (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) : HasDerivAt (fun y => c y * d y) (c' * d x + c x * d') x := by rw [← hasDerivWithinAt_univ] at * exact hc.mul hd theorem HasStrictDerivAt.mul (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) : HasStrictDerivAt (fun y => c y * d y) (c' * d x + c x * d') x := by have := (HasStrictFDerivAt.mul' hc hd).hasStrictDerivAt rwa [ContinuousLinearMap.add_apply, ContinuousLinearMap.smul_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.smulRight_apply, ContinuousLinearMap.one_apply, one_smul, one_smul, add_comm] at this theorem derivWithin_mul (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : derivWithin (fun y => c y * d y) s x = derivWithin c s x * d x + c x * derivWithin d s x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.mul hd.hasDerivWithinAt).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] @[simp] theorem deriv_mul (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : deriv (fun y => c y * d y) x = deriv c x * d x + c x * deriv d x := (hc.hasDerivAt.mul hd.hasDerivAt).deriv theorem HasDerivWithinAt.mul_const (hc : HasDerivWithinAt c c' s x) (d : 𝔸) : HasDerivWithinAt (fun y => c y * d) (c' * d) s x := by convert hc.mul (hasDerivWithinAt_const x s d) using 1 rw [mul_zero, add_zero] theorem HasDerivAt.mul_const (hc : HasDerivAt c c' x) (d : 𝔸) : HasDerivAt (fun y => c y * d) (c' * d) x := by rw [← hasDerivWithinAt_univ] at * exact hc.mul_const d theorem hasDerivAt_mul_const (c : 𝕜) : HasDerivAt (fun x => x * c) c x := by simpa only [one_mul] using (hasDerivAt_id' x).mul_const c theorem HasStrictDerivAt.mul_const (hc : HasStrictDerivAt c c' x) (d : 𝔸) : HasStrictDerivAt (fun y => c y * d) (c' * d) x := by convert hc.mul (hasStrictDerivAt_const x d) using 1 rw [mul_zero, add_zero] theorem derivWithin_mul_const (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝔸) : derivWithin (fun y => c y * d) s x = derivWithin c s x * d := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.mul_const d).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] lemma derivWithin_mul_const_field (u : 𝕜') : derivWithin (fun y => v y * u) s x = derivWithin v s x * u := by by_cases hv : DifferentiableWithinAt 𝕜 v s x · rw [derivWithin_mul_const hv u] by_cases hu : u = 0 · simp [hu] rw [derivWithin_zero_of_not_differentiableWithinAt hv, zero_mul, derivWithin_zero_of_not_differentiableWithinAt] have : v = fun x ↦ (v x * u) * u⁻¹ := by ext; simp [hu] exact fun h_diff ↦ hv <| this ▸ h_diff.mul_const _ theorem deriv_mul_const (hc : DifferentiableAt 𝕜 c x) (d : 𝔸) : deriv (fun y => c y * d) x = deriv c x * d := (hc.hasDerivAt.mul_const d).deriv theorem deriv_mul_const_field (v : 𝕜') : deriv (fun y => u y * v) x = deriv u x * v := by by_cases hu : DifferentiableAt 𝕜 u x · exact deriv_mul_const hu v · rw [deriv_zero_of_not_differentiableAt hu, zero_mul] rcases eq_or_ne v 0 with (rfl | hd) · simp only [mul_zero, deriv_const] · refine deriv_zero_of_not_differentiableAt (mt (fun H => ?_) hu) simpa only [mul_inv_cancel_right₀ hd] using H.mul_const v⁻¹ @[simp] theorem deriv_mul_const_field' (v : 𝕜') : (deriv fun x => u x * v) = fun x => deriv u x * v := funext fun _ => deriv_mul_const_field v theorem HasDerivWithinAt.const_mul (c : 𝔸) (hd : HasDerivWithinAt d d' s x) : HasDerivWithinAt (fun y => c * d y) (c * d') s x := by convert (hasDerivWithinAt_const x s c).mul hd using 1 rw [zero_mul, zero_add] theorem HasDerivAt.const_mul (c : 𝔸) (hd : HasDerivAt d d' x) : HasDerivAt (fun y => c * d y) (c * d') x := by rw [← hasDerivWithinAt_univ] at * exact hd.const_mul c theorem HasStrictDerivAt.const_mul (c : 𝔸) (hd : HasStrictDerivAt d d' x) : HasStrictDerivAt (fun y => c * d y) (c * d') x := by convert (hasStrictDerivAt_const _ _).mul hd using 1 rw [zero_mul, zero_add] theorem derivWithin_const_mul (c : 𝔸) (hd : DifferentiableWithinAt 𝕜 d s x) : derivWithin (fun y => c * d y) s x = c * derivWithin d s x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hd.hasDerivWithinAt.const_mul c).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] lemma derivWithin_const_mul_field (u : 𝕜') : derivWithin (fun y => u * v y) s x = u * derivWithin v s x := by simp_rw [mul_comm u] exact derivWithin_mul_const_field u theorem deriv_const_mul (c : 𝔸) (hd : DifferentiableAt 𝕜 d x) : deriv (fun y => c * d y) x = c * deriv d x := (hd.hasDerivAt.const_mul c).deriv theorem deriv_const_mul_field (u : 𝕜') : deriv (fun y => u * v y) x = u * deriv v x := by simp only [mul_comm u, deriv_mul_const_field] @[simp] theorem deriv_const_mul_field' (u : 𝕜') : (deriv fun x => u * v x) = fun x => u * deriv v x := funext fun _ => deriv_const_mul_field u end Mul section Prod section HasDeriv variable {ι : Type*} [DecidableEq ι] {𝔸' : Type*} [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸'] {u : Finset ι} {f : ι → 𝕜 → 𝔸'} {f' : ι → 𝔸'} theorem HasDerivAt.finset_prod (hf : ∀ i ∈ u, HasDerivAt (f i) (f' i) x) : HasDerivAt (∏ i ∈ u, f i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • f' i) x := by simpa [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply] using (HasFDerivAt.finset_prod (fun i hi ↦ (hf i hi).hasFDerivAt)).hasDerivAt theorem HasDerivWithinAt.finset_prod (hf : ∀ i ∈ u, HasDerivWithinAt (f i) (f' i) s x) : HasDerivWithinAt (∏ i ∈ u, f i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • f' i) s x := by simpa [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply] using (HasFDerivWithinAt.finset_prod (fun i hi ↦ (hf i hi).hasFDerivWithinAt)).hasDerivWithinAt theorem HasStrictDerivAt.finset_prod (hf : ∀ i ∈ u, HasStrictDerivAt (f i) (f' i) x) : HasStrictDerivAt (∏ i ∈ u, f i ·) (∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • f' i) x := by simpa [ContinuousLinearMap.sum_apply, ContinuousLinearMap.smul_apply] using (HasStrictFDerivAt.finset_prod (fun i hi ↦ (hf i hi).hasStrictFDerivAt)).hasStrictDerivAt theorem deriv_finset_prod (hf : ∀ i ∈ u, DifferentiableAt 𝕜 (f i) x) : deriv (∏ i ∈ u, f i ·) x = ∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • deriv (f i) x := (HasDerivAt.finset_prod fun i hi ↦ (hf i hi).hasDerivAt).deriv theorem derivWithin_finset_prod (hf : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (f i) s x) : derivWithin (∏ i ∈ u, f i ·) s x = ∑ i ∈ u, (∏ j ∈ u.erase i, f j x) • derivWithin (f i) s x := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (HasDerivWithinAt.finset_prod fun i hi ↦ (hf i hi).hasDerivWithinAt).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] end HasDeriv variable {ι : Type*} {𝔸' : Type*} [NormedCommRing 𝔸'] [NormedAlgebra 𝕜 𝔸'] {u : Finset ι} {f : ι → 𝕜 → 𝔸'} @[fun_prop] theorem DifferentiableAt.finset_prod (hd : ∀ i ∈ u, DifferentiableAt 𝕜 (f i) x) : DifferentiableAt 𝕜 (∏ i ∈ u, f i ·) x := by classical exact (HasDerivAt.finset_prod (fun i hi ↦ DifferentiableAt.hasDerivAt (hd i hi))).differentiableAt @[fun_prop] theorem DifferentiableWithinAt.finset_prod (hd : ∀ i ∈ u, DifferentiableWithinAt 𝕜 (f i) s x) : DifferentiableWithinAt 𝕜 (∏ i ∈ u, f i ·) s x := by classical exact (HasDerivWithinAt.finset_prod (fun i hi ↦ DifferentiableWithinAt.hasDerivWithinAt (hd i hi))).differentiableWithinAt @[fun_prop] theorem DifferentiableOn.finset_prod (hd : ∀ i ∈ u, DifferentiableOn 𝕜 (f i) s) : DifferentiableOn 𝕜 (∏ i ∈ u, f i ·) s := fun x hx ↦ .finset_prod (fun i hi ↦ hd i hi x hx) @[fun_prop] theorem Differentiable.finset_prod (hd : ∀ i ∈ u, Differentiable 𝕜 (f i)) : Differentiable 𝕜 (∏ i ∈ u, f i ·) := fun x ↦ .finset_prod (fun i hi ↦ hd i hi x) end Prod section Div variable {𝕜' : Type*} [NontriviallyNormedField 𝕜'] [NormedAlgebra 𝕜 𝕜'] {c : 𝕜 → 𝕜'} {c' : 𝕜'} theorem HasDerivAt.div_const (hc : HasDerivAt c c' x) (d : 𝕜') : HasDerivAt (fun x => c x / d) (c' / d) x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ theorem HasDerivWithinAt.div_const (hc : HasDerivWithinAt c c' s x) (d : 𝕜') : HasDerivWithinAt (fun x => c x / d) (c' / d) s x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ theorem HasStrictDerivAt.div_const (hc : HasStrictDerivAt c c' x) (d : 𝕜') : HasStrictDerivAt (fun x => c x / d) (c' / d) x := by simpa only [div_eq_mul_inv] using hc.mul_const d⁻¹ @[fun_prop] theorem DifferentiableWithinAt.div_const (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝕜') : DifferentiableWithinAt 𝕜 (fun x => c x / d) s x := (hc.hasDerivWithinAt.div_const _).differentiableWithinAt @[simp, fun_prop] theorem DifferentiableAt.div_const (hc : DifferentiableAt 𝕜 c x) (d : 𝕜') : DifferentiableAt 𝕜 (fun x => c x / d) x := (hc.hasDerivAt.div_const _).differentiableAt @[fun_prop] theorem DifferentiableOn.div_const (hc : DifferentiableOn 𝕜 c s) (d : 𝕜') : DifferentiableOn 𝕜 (fun x => c x / d) s := fun x hx => (hc x hx).div_const d @[simp, fun_prop] theorem Differentiable.div_const (hc : Differentiable 𝕜 c) (d : 𝕜') : Differentiable 𝕜 fun x => c x / d := fun x => (hc x).div_const d theorem derivWithin_div_const (hc : DifferentiableWithinAt 𝕜 c s x) (d : 𝕜') : derivWithin (fun x => c x / d) s x = derivWithin c s x / d := by simp [div_eq_inv_mul, derivWithin_const_mul, hc] @[simp] theorem deriv_div_const (d : 𝕜') : deriv (fun x => c x / d) x = deriv c x / d := by simp only [div_eq_mul_inv, deriv_mul_const_field] end Div section CLMCompApply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ open ContinuousLinearMap variable {G : Type*} [NormedAddCommGroup G] [NormedSpace 𝕜 G] {c : 𝕜 → F →L[𝕜] G} {c' : F →L[𝕜] G} {d : 𝕜 → E →L[𝕜] F} {d' : E →L[𝕜] F} {u : 𝕜 → F} {u' : F} theorem HasStrictDerivAt.clm_comp (hc : HasStrictDerivAt c c' x) (hd : HasStrictDerivAt d d' x) : HasStrictDerivAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x := by have := (hc.hasStrictFDerivAt.clm_comp hd.hasStrictFDerivAt).hasStrictDerivAt rwa [add_apply, comp_apply, comp_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivWithinAt.clm_comp (hc : HasDerivWithinAt c c' s x) (hd : HasDerivWithinAt d d' s x) : HasDerivWithinAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') s x := by have := (hc.hasFDerivWithinAt.clm_comp hd.hasFDerivWithinAt).hasDerivWithinAt rwa [add_apply, comp_apply, comp_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivAt.clm_comp (hc : HasDerivAt c c' x) (hd : HasDerivAt d d' x) : HasDerivAt (fun y => (c y).comp (d y)) (c'.comp (d x) + (c x).comp d') x := by rw [← hasDerivWithinAt_univ] at * exact hc.clm_comp hd theorem derivWithin_clm_comp (hc : DifferentiableWithinAt 𝕜 c s x) (hd : DifferentiableWithinAt 𝕜 d s x) : derivWithin (fun y => (c y).comp (d y)) s x = (derivWithin c s x).comp (d x) + (c x).comp (derivWithin d s x) := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.clm_comp hd.hasDerivWithinAt).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem deriv_clm_comp (hc : DifferentiableAt 𝕜 c x) (hd : DifferentiableAt 𝕜 d x) : deriv (fun y => (c y).comp (d y)) x = (deriv c x).comp (d x) + (c x).comp (deriv d x) := (hc.hasDerivAt.clm_comp hd.hasDerivAt).deriv theorem HasStrictDerivAt.clm_apply (hc : HasStrictDerivAt c c' x) (hu : HasStrictDerivAt u u' x) : HasStrictDerivAt (fun y => (c y) (u y)) (c' (u x) + c x u') x := by have := (hc.hasStrictFDerivAt.clm_apply hu.hasStrictFDerivAt).hasStrictDerivAt rwa [add_apply, comp_apply, flip_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivWithinAt.clm_apply (hc : HasDerivWithinAt c c' s x) (hu : HasDerivWithinAt u u' s x) : HasDerivWithinAt (fun y => (c y) (u y)) (c' (u x) + c x u') s x := by have := (hc.hasFDerivWithinAt.clm_apply hu.hasFDerivWithinAt).hasDerivWithinAt rwa [add_apply, comp_apply, flip_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem HasDerivAt.clm_apply (hc : HasDerivAt c c' x) (hu : HasDerivAt u u' x) : HasDerivAt (fun y => (c y) (u y)) (c' (u x) + c x u') x := by have := (hc.hasFDerivAt.clm_apply hu.hasFDerivAt).hasDerivAt rwa [add_apply, comp_apply, flip_apply, smulRight_apply, smulRight_apply, one_apply, one_smul, one_smul, add_comm] at this theorem derivWithin_clm_apply (hc : DifferentiableWithinAt 𝕜 c s x) (hu : DifferentiableWithinAt 𝕜 u s x) : derivWithin (fun y => (c y) (u y)) s x = derivWithin c s x (u x) + c x (derivWithin u s x) := by by_cases hsx : UniqueDiffWithinAt 𝕜 s x · exact (hc.hasDerivWithinAt.clm_apply hu.hasDerivWithinAt).derivWithin hsx · simp [derivWithin_zero_of_not_uniqueDiffWithinAt hsx] theorem deriv_clm_apply (hc : DifferentiableAt 𝕜 c x) (hu : DifferentiableAt 𝕜 u x) : deriv (fun y => (c y) (u y)) x = deriv c x (u x) + c x (deriv u x) := (hc.hasDerivAt.clm_apply hu.hasDerivAt).deriv
end CLMCompApply
Mathlib/Analysis/Calculus/Deriv/Mul.lean
495
499
/- 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
Mathlib/SetTheory/Cardinal/Basic.lean
929
932
/- Copyright (c) 2022 Michael Blyth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Blyth -/ import Mathlib.LinearAlgebra.Projectivization.Basic /-! # Subspaces of Projective Space In this file we define subspaces of a projective space, and show that the subspaces of a projective space form a complete lattice under inclusion. ## Implementation Details A subspace of a projective space ℙ K V is defined to be a structure consisting of a subset of ℙ K V such that if two nonzero vectors in V determine points in ℙ K V which are in the subset, and the sum of the two vectors is nonzero, then the point determined by the sum of the two vectors is also in the subset. ## Results - There is a Galois insertion between the subsets of points of a projective space and the subspaces of the projective space, which is given by taking the span of the set of points. - The subspaces of a projective space form a complete lattice under inclusion. # Future Work - Show that there is a one-to-one order-preserving correspondence between subspaces of a projective space and the submodules of the underlying vector space. -/ variable (K V : Type*) [Field K] [AddCommGroup V] [Module K V] namespace Projectivization open scoped LinearAlgebra.Projectivization /-- A subspace of a projective space is a structure consisting of a set of points such that: If two nonzero vectors determine points which are in the set, and the sum of the two vectors is nonzero, then the point determined by the sum is also in the set. -/ @[ext] structure Subspace where /-- The set of points. -/ carrier : Set (ℙ K V) /-- The addition rule. -/ mem_add' (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : mk K v hv ∈ carrier → mk K w hw ∈ carrier → mk K (v + w) hvw ∈ carrier namespace Subspace variable {K V} instance : SetLike (Subspace K V) (ℙ K V) where coe := carrier coe_injective' A B := by cases A cases B simp @[simp] theorem mem_carrier_iff (A : Subspace K V) (x : ℙ K V) : x ∈ A.carrier ↔ x ∈ A := Iff.refl _ theorem mem_add (T : Subspace K V) (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : Projectivization.mk K v hv ∈ T → Projectivization.mk K w hw ∈ T → Projectivization.mk K (v + w) hvw ∈ T := T.mem_add' v w hv hw hvw /-- The span of a set of points in a projective space is defined inductively to be the set of points which contains the original set, and contains all points determined by the (nonzero) sum of two nonzero vectors, each of which determine points in the span. -/ inductive spanCarrier (S : Set (ℙ K V)) : Set (ℙ K V) | of (x : ℙ K V) (hx : x ∈ S) : spanCarrier S x | mem_add (v w : V) (hv : v ≠ 0) (hw : w ≠ 0) (hvw : v + w ≠ 0) : spanCarrier S (Projectivization.mk K v hv) → spanCarrier S (Projectivization.mk K w hw) → spanCarrier S (Projectivization.mk K (v + w) hvw) /-- The span of a set of points in projective space is a subspace. -/ def span (S : Set (ℙ K V)) : Subspace K V where carrier := spanCarrier S mem_add' v w hv hw hvw := spanCarrier.mem_add v w hv hw hvw /-- The span of a set of points contains the set of points. -/ theorem subset_span (S : Set (ℙ K V)) : S ⊆ span S := fun _x hx => spanCarrier.of _ hx /-- The span of a set of points is a Galois insertion between sets of points of a projective space and subspaces of the projective space. -/ def gi : GaloisInsertion (span : Set (ℙ K V) → Subspace K V) SetLike.coe where choice S _hS := span S gc A B := ⟨fun h => le_trans (subset_span _) h, by intro h x hx induction hx with | of => apply h; assumption | mem_add => apply B.mem_add; assumption'⟩ le_l_u _ := subset_span _ choice_eq _ _ := rfl /-- The span of a subspace is the subspace. -/ @[simp] theorem span_coe (W : Subspace K V) : span ↑W = W := GaloisInsertion.l_u_eq gi W /-- The infimum of two subspaces exists. -/ instance instInf : Min (Subspace K V) := ⟨fun A B => ⟨A ⊓ B, fun _v _w hv hw _hvw h1 h2 => ⟨A.mem_add _ _ hv hw _ h1.1 h2.1, B.mem_add _ _ hv hw _ h1.2 h2.2⟩⟩⟩ /-- Infimums of arbitrary collections of subspaces exist. -/ instance instInfSet : InfSet (Subspace K V) := ⟨fun A => ⟨sInf (SetLike.coe '' A), fun v w hv hw hvw h1 h2 t => by rintro ⟨s, hs, rfl⟩ exact s.mem_add v w hv hw _ (h1 s ⟨s, hs, rfl⟩) (h2 s ⟨s, hs, rfl⟩)⟩⟩ /-- The subspaces of a projective space form a complete lattice. -/ instance : CompleteLattice (Subspace K V) := { __ := completeLatticeOfInf (Subspace K V) (by refine fun s => ⟨fun a ha x hx => hx _ ⟨a, ha, rfl⟩, fun a ha x hx E => ?_⟩ rintro ⟨E, hE, rfl⟩ exact ha hE hx) inf_le_left := fun A B _ hx => (@inf_le_left _ _ A B) hx inf_le_right := fun A B _ hx => (@inf_le_right _ _ A B) hx le_inf := fun _ _ _ h1 h2 _ hx => (le_inf h1 h2) hx } instance subspaceInhabited : Inhabited (Subspace K V) where default := ⊤ /-- The span of the empty set is the bottom of the lattice of subspaces. -/ @[simp] theorem span_empty : span (∅ : Set (ℙ K V)) = ⊥ := gi.gc.l_bot /-- The span of the entire projective space is the top of the lattice of subspaces. -/ @[simp] theorem span_univ : span (Set.univ : Set (ℙ K V)) = ⊤ := by rw [eq_top_iff, SetLike.le_def] intro x _hx exact subset_span _ (Set.mem_univ x) /-- The span of a set of points is contained in a subspace if and only if the set of points is contained in the subspace. -/ theorem span_le_subspace_iff {S : Set (ℙ K V)} {W : Subspace K V} : span S ≤ W ↔ S ⊆ W := gi.gc S W /-- If a set of points is a subset of another set of points, then its span will be contained in the span of that set. -/ @[mono] theorem monotone_span : Monotone (span : Set (ℙ K V) → Subspace K V) := gi.gc.monotone_l @[gcongr] lemma span_le_span {s t : Set (ℙ K V)} (hst : s ⊆ t) : span s ≤ span t := monotone_span hst theorem subset_span_trans {S T U : Set (ℙ K V)} (hST : S ⊆ span T) (hTU : T ⊆ span U) : S ⊆ span U := gi.gc.le_u_l_trans hST hTU /-- The supremum of two subspaces is equal to the span of their union. -/ theorem span_union (S T : Set (ℙ K V)) : span (S ∪ T) = span S ⊔ span T := (@gi K V _ _ _).gc.l_sup /-- The supremum of a collection of subspaces is equal to the span of the union of the collection. -/ theorem span_iUnion {ι} (s : ι → Set (ℙ K V)) : span (⋃ i, s i) = ⨆ i, span (s i) := (@gi K V _ _ _).gc.l_iSup /-- The supremum of a subspace and the span of a set of points is equal to the span of the union of the subspace and the set of points. -/ theorem sup_span {S : Set (ℙ K V)} {W : Subspace K V} : W ⊔ span S = span (W ∪ S) := by rw [span_union, span_coe] theorem span_sup {S : Set (ℙ K V)} {W : Subspace K V} : span S ⊔ W = span (S ∪ W) := by rw [span_union, span_coe] /-- A point in a projective space is contained in the span of a set of points if and only if the point is contained in all subspaces of the projective space which contain the set of points. -/ theorem mem_span {S : Set (ℙ K V)} (u : ℙ K V) : u ∈ span S ↔ ∀ W : Subspace K V, S ⊆ W → u ∈ W := by simp_rw [← span_le_subspace_iff] exact ⟨fun hu W hW => hW hu, fun W => W (span S) (le_refl _)⟩ /-- The span of a set of points in a projective space is equal to the infimum of the collection of subspaces which contain the set. -/ theorem span_eq_sInf {S : Set (ℙ K V)} : span S = sInf { W : Subspace K V| S ⊆ W } := by ext x simp_rw [mem_carrier_iff, mem_span x] refine ⟨fun hx => ?_, fun hx W hW => ?_⟩ · rintro W ⟨T, hT, rfl⟩ exact hx T hT · exact (@sInf_le _ _ { W : Subspace K V | S ⊆ ↑W } W hW) hx /-- If a set of points in projective space is contained in a subspace, and that subspace is contained in the span of the set of points, then the span of the set of points is equal to
the subspace. -/ theorem span_eq_of_le {S : Set (ℙ K V)} {W : Subspace K V} (hS : S ⊆ W) (hW : W ≤ span S) :
Mathlib/LinearAlgebra/Projectivization/Subspace.lean
196
197
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers -/ import Mathlib.Algebra.ModEq import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.Algebra.Ring.Periodic import Mathlib.Data.Int.SuccPred import Mathlib.Order.Circular /-! # Reducing to an interval modulo its length This file defines operations that reduce a number (in an `Archimedean` `LinearOrderedAddCommGroup`) to a number in a given interval, modulo the length of that interval. ## Main definitions * `toIcoDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. * `toIcoMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ico a (a + p)`. * `toIocDiv hp a b` (where `hp : 0 < p`): The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. * `toIocMod hp a b` (where `hp : 0 < p`): Reduce `b` to the interval `Ioc a (a + p)`. -/ assert_not_exists TwoSidedIdeal noncomputable section section LinearOrderedAddCommGroup variable {α : Type*} [AddCommGroup α] [LinearOrder α] [IsOrderedAddMonoid α] [hα : Archimedean α] {p : α} (hp : 0 < p) {a b c : α} {n : ℤ} section include hp /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ico a (a + p)`. -/ def toIcoDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ico hp b a).choose theorem sub_toIcoDiv_zsmul_mem_Ico (a b : α) : b - toIcoDiv hp a b • p ∈ Set.Ico a (a + p) := (existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.1 theorem toIcoDiv_eq_of_sub_zsmul_mem_Ico (h : b - n • p ∈ Set.Ico a (a + p)) : toIcoDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ico hp b a).choose_spec.2 _ h).symm /-- The unique integer such that this multiple of `p`, subtracted from `b`, is in `Ioc a (a + p)`. -/ def toIocDiv (a b : α) : ℤ := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose theorem sub_toIocDiv_zsmul_mem_Ioc (a b : α) : b - toIocDiv hp a b • p ∈ Set.Ioc a (a + p) := (existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.1 theorem toIocDiv_eq_of_sub_zsmul_mem_Ioc (h : b - n • p ∈ Set.Ioc a (a + p)) : toIocDiv hp a b = n := ((existsUnique_sub_zsmul_mem_Ioc hp b a).choose_spec.2 _ h).symm /-- Reduce `b` to the interval `Ico a (a + p)`. -/ def toIcoMod (a b : α) : α := b - toIcoDiv hp a b • p /-- Reduce `b` to the interval `Ioc a (a + p)`. -/ def toIocMod (a b : α) : α := b - toIocDiv hp a b • p theorem toIcoMod_mem_Ico (a b : α) : toIcoMod hp a b ∈ Set.Ico a (a + p) := sub_toIcoDiv_zsmul_mem_Ico hp a b theorem toIcoMod_mem_Ico' (b : α) : toIcoMod hp 0 b ∈ Set.Ico 0 p := by convert toIcoMod_mem_Ico hp 0 b exact (zero_add p).symm theorem toIocMod_mem_Ioc (a b : α) : toIocMod hp a b ∈ Set.Ioc a (a + p) := sub_toIocDiv_zsmul_mem_Ioc hp a b theorem left_le_toIcoMod (a b : α) : a ≤ toIcoMod hp a b := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).1 theorem left_lt_toIocMod (a b : α) : a < toIocMod hp a b := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).1 theorem toIcoMod_lt_right (a b : α) : toIcoMod hp a b < a + p := (Set.mem_Ico.1 (toIcoMod_mem_Ico hp a b)).2 theorem toIocMod_le_right (a b : α) : toIocMod hp a b ≤ a + p := (Set.mem_Ioc.1 (toIocMod_mem_Ioc hp a b)).2 @[simp] theorem self_sub_toIcoDiv_zsmul (a b : α) : b - toIcoDiv hp a b • p = toIcoMod hp a b := rfl @[simp] theorem self_sub_toIocDiv_zsmul (a b : α) : b - toIocDiv hp a b • p = toIocMod hp a b := rfl @[simp] theorem toIcoDiv_zsmul_sub_self (a b : α) : toIcoDiv hp a b • p - b = -toIcoMod hp a b := by rw [toIcoMod, neg_sub] @[simp] theorem toIocDiv_zsmul_sub_self (a b : α) : toIocDiv hp a b • p - b = -toIocMod hp a b := by rw [toIocMod, neg_sub] @[simp] theorem toIcoMod_sub_self (a b : α) : toIcoMod hp a b - b = -toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel_left, neg_smul] @[simp] theorem toIocMod_sub_self (a b : α) : toIocMod hp a b - b = -toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel_left, neg_smul] @[simp] theorem self_sub_toIcoMod (a b : α) : b - toIcoMod hp a b = toIcoDiv hp a b • p := by rw [toIcoMod, sub_sub_cancel] @[simp] theorem self_sub_toIocMod (a b : α) : b - toIocMod hp a b = toIocDiv hp a b • p := by rw [toIocMod, sub_sub_cancel] @[simp] theorem toIcoMod_add_toIcoDiv_zsmul (a b : α) : toIcoMod hp a b + toIcoDiv hp a b • p = b := by rw [toIcoMod, sub_add_cancel] @[simp] theorem toIocMod_add_toIocDiv_zsmul (a b : α) : toIocMod hp a b + toIocDiv hp a b • p = b := by rw [toIocMod, sub_add_cancel] @[simp] theorem toIcoDiv_zsmul_sub_toIcoMod (a b : α) : toIcoDiv hp a b • p + toIcoMod hp a b = b := by rw [add_comm, toIcoMod_add_toIcoDiv_zsmul] @[simp] theorem toIocDiv_zsmul_sub_toIocMod (a b : α) : toIocDiv hp a b • p + toIocMod hp a b = b := by rw [add_comm, toIocMod_add_toIocDiv_zsmul] theorem toIcoMod_eq_iff : toIcoMod hp a b = c ↔ c ∈ Set.Ico a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIcoMod_mem_Ico hp a b, toIcoDiv hp a b, h ▸ (toIcoMod_add_toIcoDiv_zsmul _ _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIcoDiv_eq_of_sub_zsmul_mem_Ico hp hc, toIcoMod] theorem toIocMod_eq_iff : toIocMod hp a b = c ↔ c ∈ Set.Ioc a (a + p) ∧ ∃ z : ℤ, b = c + z • p := by refine ⟨fun h => ⟨h ▸ toIocMod_mem_Ioc hp a b, toIocDiv hp a b, h ▸ (toIocMod_add_toIocDiv_zsmul hp _ _).symm⟩, ?_⟩ simp_rw [← @sub_eq_iff_eq_add] rintro ⟨hc, n, rfl⟩ rw [← toIocDiv_eq_of_sub_zsmul_mem_Ioc hp hc, toIocMod] @[simp] theorem toIcoDiv_apply_left (a : α) : toIcoDiv hp a a = 0 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] @[simp] theorem toIocDiv_apply_left (a : α) : toIocDiv hp a a = -1 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] @[simp] theorem toIcoMod_apply_left (a : α) : toIcoMod hp a a = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIocMod_apply_left (a : α) : toIocMod hp a a = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, -1, by simp⟩ theorem toIcoDiv_apply_right (a : α) : toIcoDiv hp a (a + p) = 1 := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simp [hp] theorem toIocDiv_apply_right (a : α) : toIocDiv hp a (a + p) = 0 := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simp [hp] theorem toIcoMod_apply_right (a : α) : toIcoMod hp a (a + p) = a := by rw [toIcoMod_eq_iff hp, Set.left_mem_Ico] exact ⟨lt_add_of_pos_right _ hp, 1, by simp⟩ theorem toIocMod_apply_right (a : α) : toIocMod hp a (a + p) = a + p := by rw [toIocMod_eq_iff hp, Set.right_mem_Ioc] exact ⟨lt_add_of_pos_right _ hp, 0, by simp⟩ @[simp] theorem toIcoDiv_add_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b + m • p) = toIcoDiv hp a b + m := toIcoDiv_eq_of_sub_zsmul_mem_Ico hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIcoDiv_add_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a + m • p) b = toIcoDiv hp a b - m := by refine toIcoDiv_eq_of_sub_zsmul_mem_Ico _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIcoDiv_zsmul_mem_Ico hp a b @[simp] theorem toIocDiv_add_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b + m • p) = toIocDiv hp a b + m := toIocDiv_eq_of_sub_zsmul_mem_Ioc hp <| by simpa only [add_smul, add_sub_add_right_eq_sub] using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIocDiv_add_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a + m • p) b = toIocDiv hp a b - m := by refine toIocDiv_eq_of_sub_zsmul_mem_Ioc _ ?_ rw [sub_smul, ← sub_add, add_right_comm] simpa using sub_toIocDiv_zsmul_mem_Ioc hp a b @[simp] theorem toIcoDiv_zsmul_add (a b : α) (m : ℤ) : toIcoDiv hp a (m • p + b) = m + toIcoDiv hp a b := by rw [add_comm, toIcoDiv_add_zsmul, add_comm] /-! Note we omit `toIcoDiv_zsmul_add'` as `-m + toIcoDiv hp a b` is not very convenient. -/ @[simp] theorem toIocDiv_zsmul_add (a b : α) (m : ℤ) : toIocDiv hp a (m • p + b) = m + toIocDiv hp a b := by rw [add_comm, toIocDiv_add_zsmul, add_comm] /-! Note we omit `toIocDiv_zsmul_add'` as `-m + toIocDiv hp a b` is not very convenient. -/ @[simp] theorem toIcoDiv_sub_zsmul (a b : α) (m : ℤ) : toIcoDiv hp a (b - m • p) = toIcoDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIcoDiv_sub_zsmul' (a b : α) (m : ℤ) : toIcoDiv hp (a - m • p) b = toIcoDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIcoDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIocDiv_sub_zsmul (a b : α) (m : ℤ) : toIocDiv hp a (b - m • p) = toIocDiv hp a b - m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul, sub_eq_add_neg] @[simp] theorem toIocDiv_sub_zsmul' (a b : α) (m : ℤ) : toIocDiv hp (a - m • p) b = toIocDiv hp a b + m := by rw [sub_eq_add_neg, ← neg_smul, toIocDiv_add_zsmul', sub_neg_eq_add] @[simp] theorem toIcoDiv_add_right (a b : α) : toIcoDiv hp a (b + p) = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul hp a b 1 @[simp] theorem toIcoDiv_add_right' (a b : α) : toIcoDiv hp (a + p) b = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_add_zsmul' hp a b 1 @[simp] theorem toIocDiv_add_right (a b : α) : toIocDiv hp a (b + p) = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul hp a b 1 @[simp] theorem toIocDiv_add_right' (a b : α) : toIocDiv hp (a + p) b = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_add_zsmul' hp a b 1 @[simp] theorem toIcoDiv_add_left (a b : α) : toIcoDiv hp a (p + b) = toIcoDiv hp a b + 1 := by rw [add_comm, toIcoDiv_add_right] @[simp] theorem toIcoDiv_add_left' (a b : α) : toIcoDiv hp (p + a) b = toIcoDiv hp a b - 1 := by rw [add_comm, toIcoDiv_add_right'] @[simp] theorem toIocDiv_add_left (a b : α) : toIocDiv hp a (p + b) = toIocDiv hp a b + 1 := by rw [add_comm, toIocDiv_add_right] @[simp] theorem toIocDiv_add_left' (a b : α) : toIocDiv hp (p + a) b = toIocDiv hp a b - 1 := by rw [add_comm, toIocDiv_add_right'] @[simp] theorem toIcoDiv_sub (a b : α) : toIcoDiv hp a (b - p) = toIcoDiv hp a b - 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul hp a b 1 @[simp] theorem toIcoDiv_sub' (a b : α) : toIcoDiv hp (a - p) b = toIcoDiv hp a b + 1 := by simpa only [one_zsmul] using toIcoDiv_sub_zsmul' hp a b 1 @[simp] theorem toIocDiv_sub (a b : α) : toIocDiv hp a (b - p) = toIocDiv hp a b - 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul hp a b 1 @[simp] theorem toIocDiv_sub' (a b : α) : toIocDiv hp (a - p) b = toIocDiv hp a b + 1 := by simpa only [one_zsmul] using toIocDiv_sub_zsmul' hp a b 1 theorem toIcoDiv_sub_eq_toIcoDiv_add (a b c : α) : toIcoDiv hp a (b - c) = toIcoDiv hp (a + c) b := by apply toIcoDiv_eq_of_sub_zsmul_mem_Ico rw [← sub_right_comm, Set.sub_mem_Ico_iff_left, add_right_comm] exact sub_toIcoDiv_zsmul_mem_Ico hp (a + c) b theorem toIocDiv_sub_eq_toIocDiv_add (a b c : α) : toIocDiv hp a (b - c) = toIocDiv hp (a + c) b := by apply toIocDiv_eq_of_sub_zsmul_mem_Ioc rw [← sub_right_comm, Set.sub_mem_Ioc_iff_left, add_right_comm] exact sub_toIocDiv_zsmul_mem_Ioc hp (a + c) b theorem toIcoDiv_sub_eq_toIcoDiv_add' (a b c : α) : toIcoDiv hp (a - c) b = toIcoDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIcoDiv_sub_eq_toIcoDiv_add, sub_eq_add_neg] theorem toIocDiv_sub_eq_toIocDiv_add' (a b c : α) : toIocDiv hp (a - c) b = toIocDiv hp a (b + c) := by rw [← sub_neg_eq_add, toIocDiv_sub_eq_toIocDiv_add, sub_eq_add_neg] theorem toIcoDiv_neg (a b : α) : toIcoDiv hp a (-b) = -(toIocDiv hp (-a) b + 1) := by suffices toIcoDiv hp a (-b) = -toIocDiv hp (-(a + p)) b by rwa [neg_add, ← sub_eq_add_neg, toIocDiv_sub_eq_toIocDiv_add', toIocDiv_add_right] at this rw [← neg_eq_iff_eq_neg, eq_comm] apply toIocDiv_eq_of_sub_zsmul_mem_Ioc obtain ⟨hc, ho⟩ := sub_toIcoDiv_zsmul_mem_Ico hp a (-b) rw [← neg_lt_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at ho rw [← neg_le_neg_iff, neg_sub' (-b), neg_neg, ← neg_smul] at hc refine ⟨ho, hc.trans_eq ?_⟩ rw [neg_add, neg_add_cancel_right] theorem toIcoDiv_neg' (a b : α) : toIcoDiv hp (-a) b = -(toIocDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIcoDiv_neg hp (-a) (-b) theorem toIocDiv_neg (a b : α) : toIocDiv hp a (-b) = -(toIcoDiv hp (-a) b + 1) := by rw [← neg_neg b, toIcoDiv_neg, neg_neg, neg_neg, neg_add', neg_neg, add_sub_cancel_right] theorem toIocDiv_neg' (a b : α) : toIocDiv hp (-a) b = -(toIcoDiv hp a (-b) + 1) := by simpa only [neg_neg] using toIocDiv_neg hp (-a) (-b) @[simp] theorem toIcoMod_add_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b + m • p) = toIcoMod hp a b := by rw [toIcoMod, toIcoDiv_add_zsmul, toIcoMod, add_smul] abel @[simp] theorem toIcoMod_add_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a + m • p) b = toIcoMod hp a b + m • p := by simp only [toIcoMod, toIcoDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIocMod_add_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b + m • p) = toIocMod hp a b := by rw [toIocMod, toIocDiv_add_zsmul, toIocMod, add_smul] abel @[simp] theorem toIocMod_add_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a + m • p) b = toIocMod hp a b + m • p := by simp only [toIocMod, toIocDiv_add_zsmul', sub_smul, sub_add] @[simp] theorem toIcoMod_zsmul_add (a b : α) (m : ℤ) : toIcoMod hp a (m • p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_zsmul_add' (a b : α) (m : ℤ) : toIcoMod hp (m • p + a) b = m • p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_zsmul', add_comm] @[simp] theorem toIocMod_zsmul_add (a b : α) (m : ℤ) : toIocMod hp a (m • p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul] @[simp] theorem toIocMod_zsmul_add' (a b : α) (m : ℤ) : toIocMod hp (m • p + a) b = m • p + toIocMod hp a b := by rw [add_comm, toIocMod_add_zsmul', add_comm] @[simp] theorem toIcoMod_sub_zsmul (a b : α) (m : ℤ) : toIcoMod hp a (b - m • p) = toIcoMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul] @[simp] theorem toIcoMod_sub_zsmul' (a b : α) (m : ℤ) : toIcoMod hp (a - m • p) b = toIcoMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIcoMod_add_zsmul'] @[simp] theorem toIocMod_sub_zsmul (a b : α) (m : ℤ) : toIocMod hp a (b - m • p) = toIocMod hp a b := by rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul] @[simp] theorem toIocMod_sub_zsmul' (a b : α) (m : ℤ) : toIocMod hp (a - m • p) b = toIocMod hp a b - m • p := by simp_rw [sub_eq_add_neg, ← neg_smul, toIocMod_add_zsmul'] @[simp] theorem toIcoMod_add_right (a b : α) : toIcoMod hp a (b + p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_add_zsmul hp a b 1 @[simp] theorem toIcoMod_add_right' (a b : α) : toIcoMod hp (a + p) b = toIcoMod hp a b + p := by simpa only [one_zsmul] using toIcoMod_add_zsmul' hp a b 1 @[simp] theorem toIocMod_add_right (a b : α) : toIocMod hp a (b + p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_add_zsmul hp a b 1 @[simp] theorem toIocMod_add_right' (a b : α) : toIocMod hp (a + p) b = toIocMod hp a b + p := by simpa only [one_zsmul] using toIocMod_add_zsmul' hp a b 1 @[simp] theorem toIcoMod_add_left (a b : α) : toIcoMod hp a (p + b) = toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right] @[simp] theorem toIcoMod_add_left' (a b : α) : toIcoMod hp (p + a) b = p + toIcoMod hp a b := by rw [add_comm, toIcoMod_add_right', add_comm] @[simp] theorem toIocMod_add_left (a b : α) : toIocMod hp a (p + b) = toIocMod hp a b := by rw [add_comm, toIocMod_add_right] @[simp] theorem toIocMod_add_left' (a b : α) : toIocMod hp (p + a) b = p + toIocMod hp a b := by rw [add_comm, toIocMod_add_right', add_comm] @[simp] theorem toIcoMod_sub (a b : α) : toIcoMod hp a (b - p) = toIcoMod hp a b := by simpa only [one_zsmul] using toIcoMod_sub_zsmul hp a b 1 @[simp] theorem toIcoMod_sub' (a b : α) : toIcoMod hp (a - p) b = toIcoMod hp a b - p := by simpa only [one_zsmul] using toIcoMod_sub_zsmul' hp a b 1 @[simp] theorem toIocMod_sub (a b : α) : toIocMod hp a (b - p) = toIocMod hp a b := by simpa only [one_zsmul] using toIocMod_sub_zsmul hp a b 1 @[simp] theorem toIocMod_sub' (a b : α) : toIocMod hp (a - p) b = toIocMod hp a b - p := by simpa only [one_zsmul] using toIocMod_sub_zsmul' hp a b 1 theorem toIcoMod_sub_eq_sub (a b c : α) : toIcoMod hp a (b - c) = toIcoMod hp (a + c) b - c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add, sub_right_comm] theorem toIocMod_sub_eq_sub (a b c : α) : toIocMod hp a (b - c) = toIocMod hp (a + c) b - c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add, sub_right_comm] theorem toIcoMod_add_right_eq_add (a b c : α) : toIcoMod hp a (b + c) = toIcoMod hp (a - c) b + c := by simp_rw [toIcoMod, toIcoDiv_sub_eq_toIcoDiv_add', sub_add_eq_add_sub] theorem toIocMod_add_right_eq_add (a b c : α) : toIocMod hp a (b + c) = toIocMod hp (a - c) b + c := by simp_rw [toIocMod, toIocDiv_sub_eq_toIocDiv_add', sub_add_eq_add_sub] theorem toIcoMod_neg (a b : α) : toIcoMod hp a (-b) = p - toIocMod hp (-a) b := by simp_rw [toIcoMod, toIocMod, toIcoDiv_neg, neg_smul, add_smul] abel theorem toIcoMod_neg' (a b : α) : toIcoMod hp (-a) b = p - toIocMod hp a (-b) := by simpa only [neg_neg] using toIcoMod_neg hp (-a) (-b) theorem toIocMod_neg (a b : α) : toIocMod hp a (-b) = p - toIcoMod hp (-a) b := by simp_rw [toIocMod, toIcoMod, toIocDiv_neg, neg_smul, add_smul] abel theorem toIocMod_neg' (a b : α) : toIocMod hp (-a) b = p - toIcoMod hp a (-b) := by simpa only [neg_neg] using toIocMod_neg hp (-a) (-b) theorem toIcoMod_eq_toIcoMod : toIcoMod hp a b = toIcoMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIcoDiv hp a c - toIcoDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, ← toIcoMod_add_toIcoDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIcoMod_zsmul_add] theorem toIocMod_eq_toIocMod : toIocMod hp a b = toIocMod hp a c ↔ ∃ n : ℤ, c - b = n • p := by refine ⟨fun h => ⟨toIocDiv hp a c - toIocDiv hp a b, ?_⟩, fun h => ?_⟩ · conv_lhs => rw [← toIocMod_add_toIocDiv_zsmul hp a b, ← toIocMod_add_toIocDiv_zsmul hp a c] rw [h, sub_smul] abel · rcases h with ⟨z, hz⟩ rw [sub_eq_iff_eq_add] at hz rw [hz, toIocMod_zsmul_add] /-! ### Links between the `Ico` and `Ioc` variants applied to the same element -/ section IcoIoc namespace AddCommGroup theorem modEq_iff_toIcoMod_eq_left : a ≡ b [PMOD p] ↔ toIcoMod hp a b = a := modEq_iff_eq_add_zsmul.trans ⟨by rintro ⟨n, rfl⟩ rw [toIcoMod_add_zsmul, toIcoMod_apply_left], fun h => ⟨toIcoDiv hp a b, eq_add_of_sub_eq h⟩⟩ theorem modEq_iff_toIocMod_eq_right : a ≡ b [PMOD p] ↔ toIocMod hp a b = a + p := by refine modEq_iff_eq_add_zsmul.trans ⟨?_, fun h => ⟨toIocDiv hp a b + 1, ?_⟩⟩ · rintro ⟨z, rfl⟩ rw [toIocMod_add_zsmul, toIocMod_apply_left] · rwa [add_one_zsmul, add_left_comm, ← sub_eq_iff_eq_add'] alias ⟨ModEq.toIcoMod_eq_left, _⟩ := modEq_iff_toIcoMod_eq_left alias ⟨ModEq.toIcoMod_eq_right, _⟩ := modEq_iff_toIocMod_eq_right variable (a b) open List in theorem tfae_modEq : TFAE [a ≡ b [PMOD p], ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p), toIcoMod hp a b ≠ toIocMod hp a b, toIcoMod hp a b + p = toIocMod hp a b] := by rw [modEq_iff_toIcoMod_eq_left hp] tfae_have 3 → 2 := by rw [← not_exists, not_imp_not] exact fun ⟨i, hi⟩ => ((toIcoMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ico_self hi, i, (sub_add_cancel b _).symm⟩).trans ((toIocMod_eq_iff hp).2 ⟨Set.Ioo_subset_Ioc_self hi, i, (sub_add_cancel b _).symm⟩).symm tfae_have 4 → 3 | h => by rw [← h, Ne, eq_comm, add_eq_left] exact hp.ne' tfae_have 1 → 4 | h => by rw [h, eq_comm, toIocMod_eq_iff, Set.right_mem_Ioc] refine ⟨lt_add_of_pos_right a hp, toIcoDiv hp a b - 1, ?_⟩ rw [sub_one_zsmul, add_add_add_comm, add_neg_cancel, add_zero] conv_lhs => rw [← toIcoMod_add_toIcoDiv_zsmul hp a b, h] tfae_have 2 → 1 := by rw [← not_exists, not_imp_comm] have h' := toIcoMod_mem_Ico hp a b exact fun h => ⟨_, h'.1.lt_of_ne' h, h'.2⟩ tfae_finish variable {a b} theorem modEq_iff_not_forall_mem_Ioo_mod : a ≡ b [PMOD p] ↔ ∀ z : ℤ, b - z • p ∉ Set.Ioo a (a + p) := (tfae_modEq hp a b).out 0 1 theorem modEq_iff_toIcoMod_ne_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b ≠ toIocMod hp a b := (tfae_modEq hp a b).out 0 2 theorem modEq_iff_toIcoMod_add_period_eq_toIocMod : a ≡ b [PMOD p] ↔ toIcoMod hp a b + p = toIocMod hp a b := (tfae_modEq hp a b).out 0 3 theorem not_modEq_iff_toIcoMod_eq_toIocMod : ¬a ≡ b [PMOD p] ↔ toIcoMod hp a b = toIocMod hp a b := (modEq_iff_toIcoMod_ne_toIocMod _).not_left theorem not_modEq_iff_toIcoDiv_eq_toIocDiv : ¬a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b := by rw [not_modEq_iff_toIcoMod_eq_toIocMod hp, toIcoMod, toIocMod, sub_right_inj, zsmul_left_inj hp] theorem modEq_iff_toIcoDiv_eq_toIocDiv_add_one : a ≡ b [PMOD p] ↔ toIcoDiv hp a b = toIocDiv hp a b + 1 := by rw [modEq_iff_toIcoMod_add_period_eq_toIocMod hp, toIcoMod, toIocMod, ← eq_sub_iff_add_eq, sub_sub, sub_right_inj, ← add_one_zsmul, zsmul_left_inj hp] end AddCommGroup open AddCommGroup /-- If `a` and `b` fall within the same cycle WRT `c`, then they are congruent modulo `p`. -/ @[simp] theorem toIcoMod_inj {c : α} : toIcoMod hp c a = toIcoMod hp c b ↔ a ≡ b [PMOD p] := by simp_rw [toIcoMod_eq_toIcoMod, modEq_iff_eq_add_zsmul, sub_eq_iff_eq_add'] alias ⟨_, AddCommGroup.ModEq.toIcoMod_eq_toIcoMod⟩ := toIcoMod_inj theorem Ico_eq_locus_Ioc_eq_iUnion_Ioo : { b | toIcoMod hp a b = toIocMod hp a b } = ⋃ z : ℤ, Set.Ioo (a + z • p) (a + p + z • p) := by ext1 simp_rw [Set.mem_setOf, Set.mem_iUnion, ← Set.sub_mem_Ioo_iff_left, ← not_modEq_iff_toIcoMod_eq_toIocMod, modEq_iff_not_forall_mem_Ioo_mod hp, not_forall, Classical.not_not] theorem toIocDiv_wcovBy_toIcoDiv (a b : α) : toIocDiv hp a b ⩿ toIcoDiv hp a b := by suffices toIocDiv hp a b = toIcoDiv hp a b ∨ toIocDiv hp a b + 1 = toIcoDiv hp a b by rwa [wcovBy_iff_eq_or_covBy, ← Order.succ_eq_iff_covBy] rw [eq_comm, ← not_modEq_iff_toIcoDiv_eq_toIocDiv, eq_comm, ← modEq_iff_toIcoDiv_eq_toIocDiv_add_one] exact em' _ theorem toIcoMod_le_toIocMod (a b : α) : toIcoMod hp a b ≤ toIocMod hp a b := by rw [toIcoMod, toIocMod, sub_le_sub_iff_left] exact zsmul_left_mono hp.le (toIocDiv_wcovBy_toIcoDiv _ _ _).le theorem toIocMod_le_toIcoMod_add (a b : α) : toIocMod hp a b ≤ toIcoMod hp a b + p := by rw [toIcoMod, toIocMod, sub_add, sub_le_sub_iff_left, sub_le_iff_le_add, ← add_one_zsmul, (zsmul_left_strictMono hp).le_iff_le] apply (toIocDiv_wcovBy_toIcoDiv _ _ _).le_succ end IcoIoc open AddCommGroup
theorem toIcoMod_eq_self : toIcoMod hp a b = b ↔ b ∈ Set.Ico a (a + p) := by rw [toIcoMod_eq_iff, and_iff_left] exact ⟨0, by simp⟩ theorem toIocMod_eq_self : toIocMod hp a b = b ↔ b ∈ Set.Ioc a (a + p) := by
Mathlib/Algebra/Order/ToIntervalMod.lean
604
608
/- Copyright (c) 2023 Andrew Yang, Patrick Lutz. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Andrew Yang -/ import Mathlib.RingTheory.RootsOfUnity.PrimitiveRoots import Mathlib.FieldTheory.Galois.Basic import Mathlib.FieldTheory.KummerPolynomial import Mathlib.LinearAlgebra.Eigenspace.Minpoly import Mathlib.RingTheory.Norm.Basic /-! # Kummer Extensions ## Main result - `isCyclic_tfae`: Suppose `L/K` is a finite extension of dimension `n`, and `K` contains all `n`-th roots of unity. Then `L/K` is cyclic iff `L` is a splitting field of some irreducible polynomial of the form `Xⁿ - a : K[X]` iff `L = K[α]` for some `αⁿ ∈ K`. - `autEquivRootsOfUnity`: Given an instance `IsSplittingField K L (X ^ n - C a)` (perhaps via `isSplittingField_X_pow_sub_C_of_root_adjoin_eq_top`), then the galois group is isomorphic to `rootsOfUnity n K`, by sending `σ ↦ σ α / α` for `α ^ n = a`, and the inverse is given by `μ ↦ (α ↦ μ • α)`. - `autEquivZmod`: Furthermore, given an explicit choice `ζ` of a primitive `n`-th root of unity, the galois group is then isomorphic to `Multiplicative (ZMod n)` whose inverse is given by `i ↦ (α ↦ ζⁱ • α)`. ## Other results Criteria for `X ^ n - C a` to be irreducible is given: - `X_pow_sub_C_irreducible_iff_of_prime_pow`: For `n = p ^ k` an odd prime power, `X ^ n - C a` is irreducible iff `a` is not a `p`-power. - `X_pow_sub_C_irreducible_iff_forall_prime_of_odd`: For `n` odd, `X ^ n - C a` is irreducible iff `a` is not a `p`-power for all prime `p ∣ n`. - `X_pow_sub_C_irreducible_iff_of_odd`: For `n` odd, `X ^ n - C a` is irreducible iff `a` is not a `d`-power for `d ∣ n` and `d ≠ 1`. TODO: criteria for even `n`. See [serge_lang_algebra] VI,§9. TODO: relate Kummer extensions of degree 2 with the class `Algebra.IsQuadraticExtension`. -/ universe u variable {K : Type u} [Field K] open Polynomial IntermediateField AdjoinRoot section Splits theorem X_pow_sub_C_splits_of_isPrimitiveRoot {n : ℕ} {ζ : K} (hζ : IsPrimitiveRoot ζ n) {α a : K} (e : α ^ n = a) : (X ^ n - C a).Splits (RingHom.id _) := by cases n.eq_zero_or_pos with | inl hn => rw [hn, pow_zero, ← C.map_one, ← map_sub] exact splits_C _ _ | inr hn => rw [splits_iff_card_roots, ← nthRoots, hζ.card_nthRoots, natDegree_X_pow_sub_C, if_pos ⟨α, e⟩] -- make this private, as we only use it to prove a strictly more general version private theorem X_pow_sub_C_eq_prod' {n : ℕ} {ζ : K} (hζ : IsPrimitiveRoot ζ n) {α a : K} (hn : 0 < n) (e : α ^ n = a) : (X ^ n - C a) = ∏ i ∈ Finset.range n, (X - C (ζ ^ i * α)) := by rw [eq_prod_roots_of_monic_of_splits_id (monic_X_pow_sub_C _ (Nat.pos_iff_ne_zero.mp hn)) (X_pow_sub_C_splits_of_isPrimitiveRoot hζ e), ← nthRoots, hζ.nthRoots_eq e, Multiset.map_map] rfl lemma X_pow_sub_C_eq_prod {R : Type*} [CommRing R] [IsDomain R] {n : ℕ} {ζ : R} (hζ : IsPrimitiveRoot ζ n) {α a : R} (hn : 0 < n) (e : α ^ n = a) : (X ^ n - C a) = ∏ i ∈ Finset.range n, (X - C (ζ ^ i * α)) := by let K := FractionRing R let i := algebraMap R K have h := FaithfulSMul.algebraMap_injective R K apply_fun Polynomial.map i using map_injective i h simpa only [Polynomial.map_sub, Polynomial.map_pow, map_X, map_C, map_mul, map_pow, Polynomial.map_prod, Polynomial.map_mul] using X_pow_sub_C_eq_prod' (hζ.map_of_injective h) hn <| map_pow i α n ▸ congrArg i e end Splits section Irreducible theorem X_pow_mul_sub_C_irreducible {n m : ℕ} {a : K} (hm : Irreducible (X ^ m - C a)) (hn : ∀ (E : Type u) [Field E] [Algebra K E] (x : E) (_ : minpoly K x = X ^ m - C a), Irreducible (X ^ n - C (AdjoinSimple.gen K x))) : Irreducible (X ^ (n * m) - C a) := by have hm' : m ≠ 0 := by rintro rfl rw [pow_zero, ← C.map_one, ← map_sub] at hm exact not_irreducible_C _ hm simpa [pow_mul] using irreducible_comp (monic_X_pow_sub_C a hm') (monic_X_pow n) hm (by simpa only [Polynomial.map_pow, map_X] using hn) -- TODO: generalize to even `n` theorem X_pow_sub_C_irreducible_of_odd {n : ℕ} (hn : Odd n) {a : K} (ha : ∀ p : ℕ, p.Prime → p ∣ n → ∀ b : K, b ^ p ≠ a) : Irreducible (X ^ n - C a) := by induction n using induction_on_primes generalizing K a with | h₀ => simp [← Nat.not_even_iff_odd] at hn | h₁ => simpa using irreducible_X_sub_C a | h p n hp IH => rw [mul_comm] apply X_pow_mul_sub_C_irreducible (X_pow_sub_C_irreducible_of_prime hp (ha p hp (dvd_mul_right _ _))) intro E _ _ x hx have : IsIntegral K x := not_not.mp fun h ↦ by simpa only [degree_zero, degree_X_pow_sub_C hp.pos, WithBot.natCast_ne_bot] using congr_arg degree (hx.symm.trans (dif_neg h)) apply IH (Nat.odd_mul.mp hn).2 intros q hq hqn b hb apply ha q hq (dvd_mul_of_dvd_right hqn p) (Algebra.norm _ b) rw [← map_pow, hb, ← adjoin.powerBasis_gen this, Algebra.PowerBasis.norm_gen_eq_coeff_zero_minpoly] simp [minpoly_gen, hx, hp.ne_zero.symm, (Nat.odd_mul.mp hn).1.neg_pow] theorem X_pow_sub_C_irreducible_iff_forall_prime_of_odd {n : ℕ} (hn : Odd n) {a : K} : Irreducible (X ^ n - C a) ↔ (∀ p : ℕ, p.Prime → p ∣ n → ∀ b : K, b ^ p ≠ a) := ⟨fun e _ hp hpn ↦ pow_ne_of_irreducible_X_pow_sub_C e hpn hp.ne_one, X_pow_sub_C_irreducible_of_odd hn⟩ theorem X_pow_sub_C_irreducible_iff_of_odd {n : ℕ} (hn : Odd n) {a : K} : Irreducible (X ^ n - C a) ↔ (∀ d, d ∣ n → d ≠ 1 → ∀ b : K, b ^ d ≠ a) := ⟨fun e _ ↦ pow_ne_of_irreducible_X_pow_sub_C e, fun H ↦ X_pow_sub_C_irreducible_of_odd hn fun p hp hpn ↦ (H p hpn hp.ne_one)⟩ -- TODO: generalize to `p = 2` theorem X_pow_sub_C_irreducible_of_prime_pow {p : ℕ} (hp : p.Prime) (hp' : p ≠ 2) (n : ℕ) {a : K} (ha : ∀ b : K, b ^ p ≠ a) : Irreducible (X ^ (p ^ n) - C a) := by apply X_pow_sub_C_irreducible_of_odd (hp.odd_of_ne_two hp').pow intros q hq hq' simpa [(Nat.prime_dvd_prime_iff_eq hq hp).mp (hq.dvd_of_dvd_pow hq')] using ha theorem X_pow_sub_C_irreducible_iff_of_prime_pow {p : ℕ} (hp : p.Prime) (hp' : p ≠ 2) {n} (hn : n ≠ 0) {a : K} : Irreducible (X ^ p ^ n - C a) ↔ ∀ b, b ^ p ≠ a := ⟨(pow_ne_of_irreducible_X_pow_sub_C · (dvd_pow dvd_rfl hn) hp.ne_one), X_pow_sub_C_irreducible_of_prime_pow hp hp' n⟩ end Irreducible /-! ### Galois Group of `K[n√a]` We first develop the theory for a specific `K[n√a] := AdjoinRoot (X ^ n - C a)`. The main result is the description of the galois group: `autAdjoinRootXPowSubCEquiv`. -/ variable {n : ℕ} (hζ : (primitiveRoots n K).Nonempty) variable (a : K) (H : Irreducible (X ^ n - C a)) set_option quotPrecheck false in scoped[KummerExtension] notation3 "K[" n "√" a "]" => AdjoinRoot (Polynomial.X ^ n - Polynomial.C a) attribute [nolint docBlame] KummerExtension.«termK[_√_]» open scoped KummerExtension section AdjoinRoot include hζ H in /-- Also see `Polynomial.separable_X_pow_sub_C_unit` -/ theorem Polynomial.separable_X_pow_sub_C_of_irreducible : (X ^ n - C a).Separable := by letI := Fact.mk H letI : Algebra K K[n√a] := inferInstance have hn := Nat.pos_iff_ne_zero.mpr (ne_zero_of_irreducible_X_pow_sub_C H) by_cases hn' : n = 1 · rw [hn', pow_one]; exact separable_X_sub_C have ⟨ζ, hζ⟩ := hζ rw [mem_primitiveRoots (Nat.pos_of_ne_zero <| ne_zero_of_irreducible_X_pow_sub_C H)] at hζ rw [← separable_map (algebraMap K K[n√a]), Polynomial.map_sub, Polynomial.map_pow, map_C, map_X, AdjoinRoot.algebraMap_eq, X_pow_sub_C_eq_prod (hζ.map_of_injective (algebraMap K _).injective) hn (root_X_pow_sub_C_pow n a), separable_prod_X_sub_C_iff'] #adaptation_note /-- https://github.com/leanprover/lean4/pull/5376 we need to provide this helper instance. -/ have : MonoidHomClass (K →+* K[n√a]) K K[n√a] := inferInstance exact (hζ.map_of_injective (algebraMap K K[n√a]).injective).injOn_pow_mul (root_X_pow_sub_C_ne_zero (lt_of_le_of_ne (show 1 ≤ n from hn) (Ne.symm hn')) _) variable (n) /-- The natural embedding of the roots of unity of `K` into `Gal(K[ⁿ√a]/K)`, by sending `η ↦ (ⁿ√a ↦ η • ⁿ√a)`. Also see `autAdjoinRootXPowSubC` for the `AlgEquiv` version. -/ noncomputable def autAdjoinRootXPowSubCHom : rootsOfUnity n K →* (K[n√a] →ₐ[K] K[n√a]) where toFun := fun η ↦ liftHom (X ^ n - C a) (((η : Kˣ) : K) • (root _) : K[n√a]) <| by have := (mem_rootsOfUnity' _ _).mp η.prop rw [map_sub, map_pow, aeval_C, aeval_X, Algebra.smul_def, mul_pow, root_X_pow_sub_C_pow, AdjoinRoot.algebraMap_eq, ← map_pow, this, map_one, one_mul, sub_self] map_one' := algHom_ext <| by simp map_mul' := fun ε η ↦ algHom_ext <| by simp [mul_smul, smul_comm ((ε : Kˣ) : K)] /-- The natural embedding of the roots of unity of `K` into `Gal(K[ⁿ√a]/K)`, by sending `η ↦ (ⁿ√a ↦ η • ⁿ√a)`. This is an isomorphism when `K` contains a primitive root of unity. See `autAdjoinRootXPowSubCEquiv`. -/ noncomputable def autAdjoinRootXPowSubC : rootsOfUnity n K →* (K[n√a] ≃ₐ[K] K[n√a]) := (AlgEquiv.algHomUnitsEquiv _ _).toMonoidHom.comp (autAdjoinRootXPowSubCHom n a).toHomUnits variable {n} lemma autAdjoinRootXPowSubC_root (η) : autAdjoinRootXPowSubC n a η (root _) = ((η : Kˣ) : K) • root _ := by dsimp [autAdjoinRootXPowSubC, autAdjoinRootXPowSubCHom, AlgEquiv.algHomUnitsEquiv] apply liftHom_root variable {a} /-- The inverse function of `autAdjoinRootXPowSubC` if `K` has all roots of unity. See `autAdjoinRootXPowSubCEquiv`. -/ noncomputable def AdjoinRootXPowSubCEquivToRootsOfUnity [NeZero n] (σ : K[n√a] ≃ₐ[K] K[n√a]) : rootsOfUnity n K := letI := Fact.mk H letI : IsDomain K[n√a] := inferInstance letI := Classical.decEq K (rootsOfUnityEquivOfPrimitiveRoots (n := n) (algebraMap K K[n√a]).injective hζ).symm (rootsOfUnity.mkOfPowEq (if a = 0 then 1 else σ (root _) / root _) (by -- The if is needed in case `n = 1` and `a = 0` and `K[n√a] = K`. split · exact one_pow _ rw [div_pow, ← map_pow]
simp only [root_X_pow_sub_C_pow, ← AdjoinRoot.algebraMap_eq, AlgEquiv.commutes] rw [div_self] rwa [Ne, map_eq_zero_iff _ (algebraMap K _).injective])) /-- The equivalence between the roots of unity of `K` and `Gal(K[ⁿ√a]/K)`. -/ noncomputable
Mathlib/FieldTheory/KummerExtension.lean
230
235
/- Copyright (c) 2023 Michael Stoll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Stoll -/ import Mathlib.Analysis.Normed.Ring.InfiniteSum import Mathlib.Analysis.SpecificLimits.Normed import Mathlib.NumberTheory.ArithmeticFunction import Mathlib.NumberTheory.SmoothNumbers /-! # Euler Products The main result in this file is `EulerProduct.eulerProduct_hasProd`, which says that if `f : ℕ → R` is norm-summable, where `R` is a complete normed commutative ring and `f` is multiplicative on coprime arguments with `f 0 = 0`, then `∏' p : Primes, ∑' e : ℕ, f (p^e)` converges to `∑' n, f n`. `ArithmeticFunction.IsMultiplicative.eulerProduct_hasProd` is a version for multiplicative arithmetic functions in the sense of `ArithmeticFunction.IsMultiplicative`. There is also a version `EulerProduct.eulerProduct_completely_multiplicative_hasProd`, which states that `∏' p : Primes, (1 - f p)⁻¹` converges to `∑' n, f n` when `f` is completely multiplicative with values in a complete normed field `F` (implemented as `f : ℕ →*₀ F`). There are variants stating the equality of the infinite product and the infinite sum (`EulerProduct.eulerProduct_tprod`, `ArithmeticFunction.IsMultiplicative.eulerProduct_tprod`, `EulerProduct.eulerProduct_completely_multiplicative_tprod`) and also variants stating the convergence of the sequence of partial products over primes `< n` (`EulerProduct.eulerProduct`, `ArithmeticFunction.IsMultiplicative.eulerProduct`, `EulerProduct.eulerProduct_completely_multiplicative`.) An intermediate step is `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum` (and its variant `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_geometric`), which relates the finite product over primes `p ∈ s` to the sum of `f n` over `s`-factored `n`, for `s : Finset ℕ`. ## Tags Euler product, multiplicative function -/ /-- If `f` is multiplicative and summable, then its values at natural numbers `> 1` have norm strictly less than `1`. -/ lemma Summable.norm_lt_one {F : Type*} [NormedDivisionRing F] [CompleteSpace F] {f : ℕ →* F} (hsum : Summable f) {p : ℕ} (hp : 1 < p) : ‖f p‖ < 1 := by refine summable_geometric_iff_norm_lt_one.mp ?_ simp_rw [← map_pow] exact hsum.comp_injective <| Nat.pow_right_injective hp open scoped Topology open Nat Finset section General /-! ### General Euler Products In this section we consider multiplicative (on coprime arguments) functions `f : ℕ → R`, where `R` is a complete normed commutative ring. The main result is `EulerProduct.eulerProduct`. -/ variable {R : Type*} [NormedCommRing R] {f : ℕ → R} -- local instance to speed up typeclass search @[local instance] private lemma instT0Space : T0Space R := MetricSpace.instT0Space variable [CompleteSpace R] namespace EulerProduct variable (hf₁ : f 1 = 1) (hmul : ∀ {m n}, Nat.Coprime m n → f (m * n) = f m * f n) include hf₁ hmul in /-- We relate a finite product over primes in `s` to an infinite sum over `s`-factored numbers. -/ lemma summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum (hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (s : Finset ℕ) : Summable (fun m : factoredNumbers s ↦ ‖f m‖) ∧ HasSum (fun m : factoredNumbers s ↦ f m) (∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n)) := by induction s using Finset.induction with | empty => rw [factoredNumbers_empty] simp only [not_mem_empty, IsEmpty.forall_iff, forall_const, filter_true_of_mem, prod_empty] exact ⟨(Set.finite_singleton 1).summable (‖f ·‖), hf₁ ▸ hasSum_singleton 1 f⟩ | insert p s hp ih => rw [filter_insert] split_ifs with hpp · constructor · simp only [← (equivProdNatFactoredNumbers hpp hp).summable_iff, Function.comp_def, equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp] refine Summable.of_nonneg_of_le (fun _ ↦ norm_nonneg _) (fun _ ↦ norm_mul_le ..) ?_ apply Summable.mul_of_nonneg (hsum hpp) ih.1 <;> exact fun n ↦ norm_nonneg _ · have hp' : p ∉ {p ∈ s | p.Prime} := mt (mem_of_mem_filter p) hp rw [prod_insert hp', ← (equivProdNatFactoredNumbers hpp hp).hasSum_iff, Function.comp_def] conv => enter [1, x] rw [equivProdNatFactoredNumbers_apply', factoredNumbers.map_prime_pow_mul hmul hpp hp] have : T3Space R := instT3Space -- speeds up the following apply (hsum hpp).of_norm.hasSum.mul ih.2 -- `exact summable_mul_of_summable_norm (hsum hpp) ih.1` gives a time-out apply summable_mul_of_summable_norm (hsum hpp) ih.1 · rwa [factoredNumbers_insert s hpp] include hf₁ hmul in /-- A version of `EulerProduct.summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum` in terms of the value of the series. -/ lemma prod_filter_prime_tsum_eq_tsum_factoredNumbers (hsum : Summable (‖f ·‖)) (s : Finset ℕ) : ∏ p ∈ s with p.Prime, ∑' n : ℕ, f (p ^ n) = ∑' m : factoredNumbers s, f m := (summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul (fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm /-- The following statement says that summing over `s`-factored numbers such that `s` contains `primesBelow N` for large enough `N` gets us arbitrarily close to the sum over all natural numbers (assuming `f` is summable and `f 0 = 0`; the latter since `0` is not `s`-factored). -/ lemma norm_tsum_factoredNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ} (εpos : 0 < ε) : ∃ N : ℕ, ∀ s : Finset ℕ, primesBelow N ≤ s → ‖(∑' m : ℕ, f m) - ∑' m : factoredNumbers s, f m‖ < ε := by obtain ⟨N, hN⟩ := summable_iff_nat_tsum_vanishing.mp hsum (Metric.ball 0 ε) <| Metric.ball_mem_nhds 0 εpos simp_rw [mem_ball_zero_iff] at hN refine ⟨N, fun s hs ↦ ?_⟩ have := hN _ <| factoredNumbers_compl hs rwa [← hsum.tsum_subtype_add_tsum_subtype_compl (factoredNumbers s), add_sub_cancel_left, tsum_eq_tsum_diff_singleton (factoredNumbers s)ᶜ hf₀] -- Versions of the three lemmas above for `smoothNumbers N` include hf₁ hmul in /-- We relate a finite product over primes to an infinite sum over smooth numbers. -/ lemma summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum (hsum : ∀ {p : ℕ}, p.Prime → Summable (fun n : ℕ ↦ ‖f (p ^ n)‖)) (N : ℕ) : Summable (fun m : N.smoothNumbers ↦ ‖f m‖) ∧ HasSum (fun m : N.smoothNumbers ↦ f m) (∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n)) := by rw [smoothNumbers_eq_factoredNumbers, primesBelow] exact summable_and_hasSum_factoredNumbers_prod_filter_prime_tsum hf₁ hmul hsum _ include hf₁ hmul in /-- A version of `EulerProduct.summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum` in terms of the value of the series. -/ lemma prod_primesBelow_tsum_eq_tsum_smoothNumbers (hsum : Summable (‖f ·‖)) (N : ℕ) : ∏ p ∈ N.primesBelow, ∑' n : ℕ, f (p ^ n) = ∑' m : N.smoothNumbers, f m := (summable_and_hasSum_smoothNumbers_prod_primesBelow_tsum hf₁ hmul (fun hp ↦ hsum.comp_injective <| Nat.pow_right_injective hp.one_lt) _).2.tsum_eq.symm /-- The following statement says that summing over `N`-smooth numbers for large enough `N` gets us arbitrarily close to the sum over all natural numbers (assuming `f` is norm-summable and `f 0 = 0`; the latter since `0` is not smooth). -/ lemma norm_tsum_smoothNumbers_sub_tsum_lt (hsum : Summable f) (hf₀ : f 0 = 0) {ε : ℝ} (εpos : 0 < ε) : ∃ N₀ : ℕ, ∀ N ≥ N₀, ‖(∑' m : ℕ, f m) - ∑' m : N.smoothNumbers, f m‖ < ε := by conv => enter [1, N₀, N]; rw [smoothNumbers_eq_factoredNumbers] obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum hf₀ εpos refine ⟨N₀, fun N hN ↦ hN₀ (range N) fun p hp ↦ ?_⟩ exact mem_range.mpr <| (lt_of_mem_primesBelow hp).trans_le hN include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated using `HasProd`. -/ theorem eulerProduct_hasProd (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by let F : ℕ → R := fun n ↦ ∑' e, f (n ^ e) change HasProd (F ∘ Subtype.val) _ rw [hasProd_subtype_iff_mulIndicator, show Set.mulIndicator (fun p : ℕ ↦ Irreducible p) = {p | Nat.Prime p}.mulIndicator from rfl, HasProd, Metric.tendsto_atTop] intro ε hε obtain ⟨N₀, hN₀⟩ := norm_tsum_factoredNumbers_sub_tsum_lt hsum.of_norm hf₀ hε refine ⟨range N₀, fun s hs ↦ ?_⟩ have : ∏ p ∈ s, {p | Nat.Prime p}.mulIndicator F p = ∏ p ∈ s with p.Prime, F p := prod_mulIndicator_eq_prod_filter s (fun _ ↦ F) _ id rw [this, dist_eq_norm, prod_filter_prime_tsum_eq_tsum_factoredNumbers hf₁ hmul hsum, norm_sub_rev] exact hN₀ s fun p hp ↦ hs <| mem_range.mpr <| lt_of_mem_primesBelow hp include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` i multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : ℕ, if p.Prime then ∑' e, f (p ^ e) else 1 = ∑' n, f n`. This version is stated using `HasProd` and `Set.mulIndicator`. -/ theorem eulerProduct_hasProd_mulIndicator (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : HasProd (Set.mulIndicator {p | Nat.Prime p} fun p ↦ ∑' e, f (p ^ e)) (∑' n, f n) := by rw [← hasProd_subtype_iff_mulIndicator] exact eulerProduct_hasProd hf₁ hmul hsum hf₀ open Filter in include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : {p : ℕ | p.Prime}, ∑' e, f (p ^ e) = ∑' n, f n`. This is a version using convergence of finite partial products. -/ theorem eulerProduct (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, ∑' e, f (p ^ e)) atTop (𝓝 (∑' n, f n)) := by have := (eulerProduct_hasProd_mulIndicator hf₁ hmul hsum hf₀).tendsto_prod_nat let F : ℕ → R := fun p ↦ ∑' (e : ℕ), f (p ^ e) have H (n : ℕ) : ∏ i ∈ range n, Set.mulIndicator {p | Nat.Prime p} F i = ∏ p ∈ primesBelow n, ∑' (e : ℕ), f (p ^ e) := prod_mulIndicator_eq_prod_filter (range n) (fun _ ↦ F) (fun _ ↦ {p | Nat.Prime p}) id simpa only [F, H] include hf₁ hmul in /-- The *Euler Product* for multiplicative (on coprime arguments) functions. If `f : ℕ → R`, where `R` is a complete normed commutative ring, `f 0 = 0`, `f 1 = 1`, `f` is multiplicative on coprime arguments, and `‖f ·‖` is summable, then `∏' p : {p : ℕ | p.Prime}, ∑' e, f (p ^ e) = ∑' n, f n`. -/ theorem eulerProduct_tprod (hsum : Summable (‖f ·‖)) (hf₀ : f 0 = 0) : ∏' p : Primes, ∑' e, f (p ^ e) = ∑' n, f n := (eulerProduct_hasProd hf₁ hmul hsum hf₀).tprod_eq end EulerProduct /-! ### Versions for arithmetic functions -/ namespace ArithmeticFunction open EulerProduct /-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a complete normed commutative ring `R`: if `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated in terms of `HasProd`. -/ nonrec theorem IsMultiplicative.eulerProduct_hasProd {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) : HasProd (fun p : Primes ↦ ∑' e, f (p ^ e)) (∑' n, f n) := eulerProduct_hasProd hf.1 hf.2 hsum f.map_zero open Filter in /-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a complete normed commutative ring `R`: if `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. This version is stated in the form of convergence of finite partial products. -/ nonrec theorem IsMultiplicative.eulerProduct {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) : Tendsto (fun n : ℕ ↦ ∏ p ∈ primesBelow n, ∑' e, f (p ^ e)) atTop (𝓝 (∑' n, f n)) := eulerProduct hf.1 hf.2 hsum f.map_zero /-- The *Euler Product* for a multiplicative arithmetic function `f` with values in a complete normed commutative ring `R`: if `‖f ·‖` is summable, then `∏' p : Nat.Primes, ∑' e, f (p ^ e) = ∑' n, f n`. -/ nonrec theorem IsMultiplicative.eulerProduct_tprod {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (hsum : Summable (‖f ·‖)) : ∏' p : Primes, ∑' e, f (p ^ e) = ∑' n, f n := eulerProduct_tprod hf.1 hf.2 hsum f.map_zero end ArithmeticFunction end General section CompletelyMultiplicative
/-! ### Euler Products for completely multiplicative functions We now assume that `f` is completely multiplicative and has values in a complete normed field `F`. Then we can use the formula for geometric series to simplify the statement. This leads to `EulerProduct.eulerProduct_completely_multiplicative_hasProd` and variants. -/
Mathlib/NumberTheory/EulerProduct/Basic.lean
268
275
/- Copyright (c) 2022 Moritz Doll. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Moritz Doll -/ import Mathlib.Analysis.Calculus.ContDiff.Bounds import Mathlib.Analysis.Calculus.IteratedDeriv.Defs import Mathlib.Analysis.Calculus.LineDeriv.Basic import Mathlib.Analysis.LocallyConvex.WithSeminorms import Mathlib.Analysis.Normed.Group.ZeroAtInfty import Mathlib.Analysis.SpecialFunctions.Pow.Real import Mathlib.Analysis.SpecialFunctions.JapaneseBracket import Mathlib.Topology.Algebra.UniformFilterBasis import Mathlib.Tactic.MoveAdd /-! # Schwartz space This file defines the Schwartz space. Usually, the Schwartz space is defined as the set of smooth functions $f : ℝ^n → ℂ$ such that there exists $C_{αβ} > 0$ with $$|x^α ∂^β f(x)| < C_{αβ}$$ for all $x ∈ ℝ^n$ and for all multiindices $α, β$. In mathlib, we use a slightly different approach and define the Schwartz space as all smooth functions `f : E → F`, where `E` and `F` are real normed vector spaces such that for all natural numbers `k` and `n` we have uniform bounds `‖x‖^k * ‖iteratedFDeriv ℝ n f x‖ < C`. This approach completely avoids using partial derivatives as well as polynomials. We construct the topology on the Schwartz space by a family of seminorms, which are the best constants in the above estimates. The abstract theory of topological vector spaces developed in `SeminormFamily.moduleFilterBasis` and `WithSeminorms.toLocallyConvexSpace` turns the Schwartz space into a locally convex topological vector space. ## Main definitions * `SchwartzMap`: The Schwartz space is the space of smooth functions such that all derivatives decay faster than any power of `‖x‖`. * `SchwartzMap.seminorm`: The family of seminorms as described above * `SchwartzMap.compCLM`: Composition with a function on the right as a continuous linear map `𝓢(E, F) →L[𝕜] 𝓢(D, F)`, provided that the function is temperate and grows polynomially near infinity * `SchwartzMap.fderivCLM`: The differential as a continuous linear map `𝓢(E, F) →L[𝕜] 𝓢(E, E →L[ℝ] F)` * `SchwartzMap.derivCLM`: The one-dimensional derivative as a continuous linear map `𝓢(ℝ, F) →L[𝕜] 𝓢(ℝ, F)` * `SchwartzMap.integralCLM`: Integration as a continuous linear map `𝓢(ℝ, F) →L[ℝ] F` ## Main statements * `SchwartzMap.instIsUniformAddGroup` and `SchwartzMap.instLocallyConvexSpace`: The Schwartz space is a locally convex topological vector space. * `SchwartzMap.one_add_le_sup_seminorm_apply`: For a Schwartz function `f` there is a uniform bound on `(1 + ‖x‖) ^ k * ‖iteratedFDeriv ℝ n f x‖`. ## Implementation details The implementation of the seminorms is taken almost literally from `ContinuousLinearMap.opNorm`. ## Notation * `𝓢(E, F)`: The Schwartz space `SchwartzMap E F` localized in `SchwartzSpace` ## Tags Schwartz space, tempered distributions -/ noncomputable section open scoped Nat NNReal ContDiff variable {𝕜 𝕜' D E F G V : Type*} variable [NormedAddCommGroup E] [NormedSpace ℝ E] variable [NormedAddCommGroup F] [NormedSpace ℝ F] variable (E F) /-- A function is a Schwartz function if it is smooth and all derivatives decay faster than any power of `‖x‖`. -/ structure SchwartzMap where toFun : E → F smooth' : ContDiff ℝ ∞ toFun decay' : ∀ k n : ℕ, ∃ C : ℝ, ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n toFun x‖ ≤ C /-- A function is a Schwartz function if it is smooth and all derivatives decay faster than any power of `‖x‖`. -/ scoped[SchwartzMap] notation "𝓢(" E ", " F ")" => SchwartzMap E F variable {E F} namespace SchwartzMap instance instFunLike : FunLike 𝓢(E, F) E F where coe f := f.toFun coe_injective' f g h := by cases f; cases g; congr /-- All derivatives of a Schwartz function are rapidly decaying. -/ theorem decay (f : 𝓢(E, F)) (k n : ℕ) : ∃ C : ℝ, 0 < C ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ C := by rcases f.decay' k n with ⟨C, hC⟩ exact ⟨max C 1, by positivity, fun x => (hC x).trans (le_max_left _ _)⟩ /-- Every Schwartz function is smooth. -/ theorem smooth (f : 𝓢(E, F)) (n : ℕ∞) : ContDiff ℝ n f := f.smooth'.of_le (mod_cast le_top) /-- Every Schwartz function is continuous. -/ @[continuity] protected theorem continuous (f : 𝓢(E, F)) : Continuous f := (f.smooth 0).continuous instance instContinuousMapClass : ContinuousMapClass 𝓢(E, F) E F where map_continuous := SchwartzMap.continuous /-- Every Schwartz function is differentiable. -/ protected theorem differentiable (f : 𝓢(E, F)) : Differentiable ℝ f := (f.smooth 1).differentiable rfl.le /-- Every Schwartz function is differentiable at any point. -/ protected theorem differentiableAt (f : 𝓢(E, F)) {x : E} : DifferentiableAt ℝ f x := f.differentiable.differentiableAt @[ext] theorem ext {f g : 𝓢(E, F)} (h : ∀ x, (f : E → F) x = g x) : f = g := DFunLike.ext f g h section IsBigO open Asymptotics Filter variable (f : 𝓢(E, F)) /-- Auxiliary lemma, used in proving the more general result `isBigO_cocompact_rpow`. -/ theorem isBigO_cocompact_zpow_neg_nat (k : ℕ) : f =O[cocompact E] fun x => ‖x‖ ^ (-k : ℤ) := by obtain ⟨d, _, hd'⟩ := f.decay k 0 simp only [norm_iteratedFDeriv_zero] at hd' simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith] refine ⟨d, Filter.Eventually.filter_mono Filter.cocompact_le_cofinite ?_⟩ refine (Filter.eventually_cofinite_ne 0).mono fun x hx => ?_ rw [Real.norm_of_nonneg (zpow_nonneg (norm_nonneg _) _), zpow_neg, ← div_eq_mul_inv, le_div_iff₀'] exacts [hd' x, zpow_pos (norm_pos_iff.mpr hx) _] theorem isBigO_cocompact_rpow [ProperSpace E] (s : ℝ) : f =O[cocompact E] fun x => ‖x‖ ^ s := by let k := ⌈-s⌉₊ have hk : -(k : ℝ) ≤ s := neg_le.mp (Nat.le_ceil (-s)) refine (isBigO_cocompact_zpow_neg_nat f k).trans ?_ suffices (fun x : ℝ => x ^ (-k : ℤ)) =O[atTop] fun x : ℝ => x ^ s from this.comp_tendsto tendsto_norm_cocompact_atTop simp_rw [Asymptotics.IsBigO, Asymptotics.IsBigOWith] refine ⟨1, (Filter.eventually_ge_atTop 1).mono fun x hx => ?_⟩ rw [one_mul, Real.norm_of_nonneg (Real.rpow_nonneg (zero_le_one.trans hx) _), Real.norm_of_nonneg (zpow_nonneg (zero_le_one.trans hx) _), ← Real.rpow_intCast, Int.cast_neg, Int.cast_natCast] exact Real.rpow_le_rpow_of_exponent_le hx hk theorem isBigO_cocompact_zpow [ProperSpace E] (k : ℤ) : f =O[cocompact E] fun x => ‖x‖ ^ k := by simpa only [Real.rpow_intCast] using isBigO_cocompact_rpow f k end IsBigO section Aux theorem bounds_nonempty (k n : ℕ) (f : 𝓢(E, F)) : ∃ c : ℝ, c ∈ { c : ℝ | 0 ≤ c ∧ ∀ x : E, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } := let ⟨M, hMp, hMb⟩ := f.decay k n ⟨M, le_of_lt hMp, hMb⟩ theorem bounds_bddBelow (k n : ℕ) (f : 𝓢(E, F)) : BddBelow { c | 0 ≤ c ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } := ⟨0, fun _ ⟨hn, _⟩ => hn⟩ theorem decay_add_le_aux (k n : ℕ) (f g : 𝓢(E, F)) (x : E) : ‖x‖ ^ k * ‖iteratedFDeriv ℝ n ((f : E → F) + (g : E → F)) x‖ ≤ ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ + ‖x‖ ^ k * ‖iteratedFDeriv ℝ n g x‖ := by rw [← mul_add] refine mul_le_mul_of_nonneg_left ?_ (by positivity) rw [iteratedFDeriv_add_apply (f.smooth _).contDiffAt (g.smooth _).contDiffAt] exact norm_add_le _ _ theorem decay_neg_aux (k n : ℕ) (f : 𝓢(E, F)) (x : E) : ‖x‖ ^ k * ‖iteratedFDeriv ℝ n (-f : E → F) x‖ = ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ := by rw [iteratedFDeriv_neg_apply, norm_neg] variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] theorem decay_smul_aux (k n : ℕ) (f : 𝓢(E, F)) (c : 𝕜) (x : E) : ‖x‖ ^ k * ‖iteratedFDeriv ℝ n (c • (f : E → F)) x‖ = ‖c‖ * ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ := by rw [mul_comm ‖c‖, mul_assoc, iteratedFDeriv_const_smul_apply (f.smooth _).contDiffAt, norm_smul c (iteratedFDeriv ℝ n (⇑f) x)] end Aux section SeminormAux /-- Helper definition for the seminorms of the Schwartz space. -/ protected def seminormAux (k n : ℕ) (f : 𝓢(E, F)) : ℝ := sInf { c | 0 ≤ c ∧ ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ c } theorem seminormAux_nonneg (k n : ℕ) (f : 𝓢(E, F)) : 0 ≤ f.seminormAux k n := le_csInf (bounds_nonempty k n f) fun _ ⟨hx, _⟩ => hx theorem le_seminormAux (k n : ℕ) (f : 𝓢(E, F)) (x : E) : ‖x‖ ^ k * ‖iteratedFDeriv ℝ n (⇑f) x‖ ≤ f.seminormAux k n := le_csInf (bounds_nonempty k n f) fun _ ⟨_, h⟩ => h x /-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/ theorem seminormAux_le_bound (k n : ℕ) (f : 𝓢(E, F)) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ M) : f.seminormAux k n ≤ M := csInf_le (bounds_bddBelow k n f) ⟨hMp, hM⟩ end SeminormAux /-! ### Algebraic properties -/ section SMul variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] [NormedField 𝕜'] [NormedSpace 𝕜' F] [SMulCommClass ℝ 𝕜' F] instance instSMul : SMul 𝕜 𝓢(E, F) := ⟨fun c f => { toFun := c • (f : E → F) smooth' := (f.smooth _).const_smul c decay' := fun k n => by refine ⟨f.seminormAux k n * (‖c‖ + 1), fun x => ?_⟩ have hc : 0 ≤ ‖c‖ := by positivity refine le_trans ?_ ((mul_le_mul_of_nonneg_right (f.le_seminormAux k n x) hc).trans ?_) · apply Eq.le rw [mul_comm _ ‖c‖, ← mul_assoc] exact decay_smul_aux k n f c x · apply mul_le_mul_of_nonneg_left _ (f.seminormAux_nonneg k n) linarith }⟩ @[simp] theorem smul_apply {f : 𝓢(E, F)} {c : 𝕜} {x : E} : (c • f) x = c • f x := rfl instance instIsScalarTower [SMul 𝕜 𝕜'] [IsScalarTower 𝕜 𝕜' F] : IsScalarTower 𝕜 𝕜' 𝓢(E, F) := ⟨fun a b f => ext fun x => smul_assoc a b (f x)⟩ instance instSMulCommClass [SMulCommClass 𝕜 𝕜' F] : SMulCommClass 𝕜 𝕜' 𝓢(E, F) := ⟨fun a b f => ext fun x => smul_comm a b (f x)⟩ theorem seminormAux_smul_le (k n : ℕ) (c : 𝕜) (f : 𝓢(E, F)) : (c • f).seminormAux k n ≤ ‖c‖ * f.seminormAux k n := by refine (c • f).seminormAux_le_bound k n (mul_nonneg (norm_nonneg _) (seminormAux_nonneg _ _ _)) fun x => (decay_smul_aux k n f c x).le.trans ?_ rw [mul_assoc] exact mul_le_mul_of_nonneg_left (f.le_seminormAux k n x) (norm_nonneg _) instance instNSMul : SMul ℕ 𝓢(E, F) := ⟨fun c f => { toFun := c • (f : E → F) smooth' := (f.smooth _).const_smul c decay' := by simpa [← Nat.cast_smul_eq_nsmul ℝ] using ((c : ℝ) • f).decay' }⟩ instance instZSMul : SMul ℤ 𝓢(E, F) := ⟨fun c f => { toFun := c • (f : E → F) smooth' := (f.smooth _).const_smul c decay' := by simpa [← Int.cast_smul_eq_zsmul ℝ] using ((c : ℝ) • f).decay' }⟩ end SMul section Zero instance instZero : Zero 𝓢(E, F) := ⟨{ toFun := fun _ => 0 smooth' := contDiff_const decay' := fun _ _ => ⟨1, fun _ => by simp⟩ }⟩ instance instInhabited : Inhabited 𝓢(E, F) := ⟨0⟩ theorem coe_zero : DFunLike.coe (0 : 𝓢(E, F)) = (0 : E → F) := rfl @[simp] theorem coeFn_zero : ⇑(0 : 𝓢(E, F)) = (0 : E → F) := rfl @[simp] theorem zero_apply {x : E} : (0 : 𝓢(E, F)) x = 0 := rfl theorem seminormAux_zero (k n : ℕ) : (0 : 𝓢(E, F)).seminormAux k n = 0 := le_antisymm (seminormAux_le_bound k n _ rfl.le fun _ => by simp [Pi.zero_def]) (seminormAux_nonneg _ _ _) end Zero section Neg instance instNeg : Neg 𝓢(E, F) := ⟨fun f => ⟨-f, (f.smooth _).neg, fun k n => ⟨f.seminormAux k n, fun x => (decay_neg_aux k n f x).le.trans (f.le_seminormAux k n x)⟩⟩⟩ end Neg section Add instance instAdd : Add 𝓢(E, F) := ⟨fun f g => ⟨f + g, (f.smooth _).add (g.smooth _), fun k n => ⟨f.seminormAux k n + g.seminormAux k n, fun x => (decay_add_le_aux k n f g x).trans (add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x))⟩⟩⟩ @[simp] theorem add_apply {f g : 𝓢(E, F)} {x : E} : (f + g) x = f x + g x := rfl theorem seminormAux_add_le (k n : ℕ) (f g : 𝓢(E, F)) : (f + g).seminormAux k n ≤ f.seminormAux k n + g.seminormAux k n := (f + g).seminormAux_le_bound k n (add_nonneg (seminormAux_nonneg _ _ _) (seminormAux_nonneg _ _ _)) fun x => (decay_add_le_aux k n f g x).trans <| add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x) end Add section Sub instance instSub : Sub 𝓢(E, F) := ⟨fun f g => ⟨f - g, (f.smooth _).sub (g.smooth _), by intro k n refine ⟨f.seminormAux k n + g.seminormAux k n, fun x => ?_⟩ refine le_trans ?_ (add_le_add (f.le_seminormAux k n x) (g.le_seminormAux k n x)) rw [sub_eq_add_neg] rw [← decay_neg_aux k n g x] convert decay_add_le_aux k n f (-g) x⟩⟩ -- exact fails with deterministic timeout @[simp] theorem sub_apply {f g : 𝓢(E, F)} {x : E} : (f - g) x = f x - g x := rfl end Sub section AddCommGroup instance instAddCommGroup : AddCommGroup 𝓢(E, F) := DFunLike.coe_injective.addCommGroup _ rfl (fun _ _ => rfl) (fun _ => rfl) (fun _ _ => rfl) (fun _ _ => rfl) fun _ _ => rfl variable (E F) /-- Coercion as an additive homomorphism. -/ def coeHom : 𝓢(E, F) →+ E → F where toFun f := f map_zero' := coe_zero map_add' _ _ := rfl variable {E F} theorem coe_coeHom : (coeHom E F : 𝓢(E, F) → E → F) = DFunLike.coe := rfl theorem coeHom_injective : Function.Injective (coeHom E F) := by rw [coe_coeHom] exact DFunLike.coe_injective end AddCommGroup section Module variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] instance instModule : Module 𝕜 𝓢(E, F) := coeHom_injective.module 𝕜 (coeHom E F) fun _ _ => rfl end Module section Seminorms /-! ### Seminorms on Schwartz space -/ variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] variable (𝕜) /-- The seminorms of the Schwartz space given by the best constants in the definition of `𝓢(E, F)`. -/ protected def seminorm (k n : ℕ) : Seminorm 𝕜 𝓢(E, F) := Seminorm.ofSMulLE (SchwartzMap.seminormAux k n) (seminormAux_zero k n) (seminormAux_add_le k n) (seminormAux_smul_le k n) /-- If one controls the seminorm for every `x`, then one controls the seminorm. -/ theorem seminorm_le_bound (k n : ℕ) (f : 𝓢(E, F)) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ M) : SchwartzMap.seminorm 𝕜 k n f ≤ M := f.seminormAux_le_bound k n hMp hM /-- If one controls the seminorm for every `x`, then one controls the seminorm. Variant for functions `𝓢(ℝ, F)`. -/ theorem seminorm_le_bound' (k n : ℕ) (f : 𝓢(ℝ, F)) {M : ℝ} (hMp : 0 ≤ M) (hM : ∀ x, |x| ^ k * ‖iteratedDeriv n f x‖ ≤ M) : SchwartzMap.seminorm 𝕜 k n f ≤ M := by refine seminorm_le_bound 𝕜 k n f hMp ?_ simpa only [Real.norm_eq_abs, norm_iteratedFDeriv_eq_norm_iteratedDeriv] /-- The seminorm controls the Schwartz estimate for any fixed `x`. -/ theorem le_seminorm (k n : ℕ) (f : 𝓢(E, F)) (x : E) : ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ SchwartzMap.seminorm 𝕜 k n f := f.le_seminormAux k n x /-- The seminorm controls the Schwartz estimate for any fixed `x`. Variant for functions `𝓢(ℝ, F)`. -/ theorem le_seminorm' (k n : ℕ) (f : 𝓢(ℝ, F)) (x : ℝ) : |x| ^ k * ‖iteratedDeriv n f x‖ ≤ SchwartzMap.seminorm 𝕜 k n f := by have := le_seminorm 𝕜 k n f x rwa [← Real.norm_eq_abs, ← norm_iteratedFDeriv_eq_norm_iteratedDeriv] theorem norm_iteratedFDeriv_le_seminorm (f : 𝓢(E, F)) (n : ℕ) (x₀ : E) : ‖iteratedFDeriv ℝ n f x₀‖ ≤ (SchwartzMap.seminorm 𝕜 0 n) f := by have := SchwartzMap.le_seminorm 𝕜 0 n f x₀ rwa [pow_zero, one_mul] at this theorem norm_pow_mul_le_seminorm (f : 𝓢(E, F)) (k : ℕ) (x₀ : E) : ‖x₀‖ ^ k * ‖f x₀‖ ≤ (SchwartzMap.seminorm 𝕜 k 0) f := by have := SchwartzMap.le_seminorm 𝕜 k 0 f x₀ rwa [norm_iteratedFDeriv_zero] at this theorem norm_le_seminorm (f : 𝓢(E, F)) (x₀ : E) : ‖f x₀‖ ≤ (SchwartzMap.seminorm 𝕜 0 0) f := by have := norm_pow_mul_le_seminorm 𝕜 f 0 x₀ rwa [pow_zero, one_mul] at this variable (E F) /-- The family of Schwartz seminorms. -/ def _root_.schwartzSeminormFamily : SeminormFamily 𝕜 𝓢(E, F) (ℕ × ℕ) := fun m => SchwartzMap.seminorm 𝕜 m.1 m.2 @[simp] theorem schwartzSeminormFamily_apply (n k : ℕ) : schwartzSeminormFamily 𝕜 E F (n, k) = SchwartzMap.seminorm 𝕜 n k := rfl @[simp] theorem schwartzSeminormFamily_apply_zero : schwartzSeminormFamily 𝕜 E F 0 = SchwartzMap.seminorm 𝕜 0 0 := rfl variable {𝕜 E F} /-- A more convenient version of `le_sup_seminorm_apply`. The set `Finset.Iic m` is the set of all pairs `(k', n')` with `k' ≤ m.1` and `n' ≤ m.2`. Note that the constant is far from optimal. -/ theorem one_add_le_sup_seminorm_apply {m : ℕ × ℕ} {k n : ℕ} (hk : k ≤ m.1) (hn : n ≤ m.2) (f : 𝓢(E, F)) (x : E) : (1 + ‖x‖) ^ k * ‖iteratedFDeriv ℝ n f x‖ ≤ 2 ^ m.1 * (Finset.Iic m).sup (fun m => SchwartzMap.seminorm 𝕜 m.1 m.2) f := by rw [add_comm, add_pow] simp only [one_pow, mul_one, Finset.sum_congr, Finset.sum_mul] norm_cast rw [← Nat.sum_range_choose m.1] push_cast rw [Finset.sum_mul] have hk' : Finset.range (k + 1) ⊆ Finset.range (m.1 + 1) := by rwa [Finset.range_subset, add_le_add_iff_right] refine le_trans (Finset.sum_le_sum_of_subset_of_nonneg hk' fun _ _ _ => by positivity) ?_ gcongr ∑ _i ∈ Finset.range (m.1 + 1), ?_ with i hi move_mul [(Nat.choose k i : ℝ), (Nat.choose m.1 i : ℝ)] gcongr · apply (le_seminorm 𝕜 i n f x).trans apply Seminorm.le_def.1 exact Finset.le_sup_of_le (Finset.mem_Iic.2 <| Prod.mk_le_mk.2 ⟨Finset.mem_range_succ_iff.mp hi, hn⟩) le_rfl · exact mod_cast Nat.choose_le_choose i hk end Seminorms section Topology /-! ### The topology on the Schwartz space -/ variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] variable (𝕜 E F) instance instTopologicalSpace : TopologicalSpace 𝓢(E, F) := (schwartzSeminormFamily ℝ E F).moduleFilterBasis.topology' theorem _root_.schwartz_withSeminorms : WithSeminorms (schwartzSeminormFamily 𝕜 E F) := by have A : WithSeminorms (schwartzSeminormFamily ℝ E F) := ⟨rfl⟩ rw [SeminormFamily.withSeminorms_iff_nhds_eq_iInf] at A ⊢ rw [A] rfl variable {𝕜 E F} instance instContinuousSMul : ContinuousSMul 𝕜 𝓢(E, F) := by rw [(schwartz_withSeminorms 𝕜 E F).withSeminorms_eq] exact (schwartzSeminormFamily 𝕜 E F).moduleFilterBasis.continuousSMul instance instIsTopologicalAddGroup : IsTopologicalAddGroup 𝓢(E, F) := (schwartzSeminormFamily ℝ E F).addGroupFilterBasis.isTopologicalAddGroup instance instUniformSpace : UniformSpace 𝓢(E, F) := (schwartzSeminormFamily ℝ E F).addGroupFilterBasis.uniformSpace instance instIsUniformAddGroup : IsUniformAddGroup 𝓢(E, F) := (schwartzSeminormFamily ℝ E F).addGroupFilterBasis.isUniformAddGroup @[deprecated (since := "2025-03-31")] alias instUniformAddGroup := SchwartzMap.instIsUniformAddGroup instance instLocallyConvexSpace : LocallyConvexSpace ℝ 𝓢(E, F) := (schwartz_withSeminorms ℝ E F).toLocallyConvexSpace instance instFirstCountableTopology : FirstCountableTopology 𝓢(E, F) := (schwartz_withSeminorms ℝ E F).firstCountableTopology end Topology section TemperateGrowth /-! ### Functions of temperate growth -/ /-- A function is called of temperate growth if it is smooth and all iterated derivatives are polynomially bounded. -/ def _root_.Function.HasTemperateGrowth (f : E → F) : Prop := ContDiff ℝ ∞ f ∧ ∀ n : ℕ, ∃ (k : ℕ) (C : ℝ), ∀ x, ‖iteratedFDeriv ℝ n f x‖ ≤ C * (1 + ‖x‖) ^ k theorem _root_.Function.HasTemperateGrowth.norm_iteratedFDeriv_le_uniform_aux {f : E → F} (hf_temperate : f.HasTemperateGrowth) (n : ℕ) : ∃ (k : ℕ) (C : ℝ), 0 ≤ C ∧ ∀ N ≤ n, ∀ x : E, ‖iteratedFDeriv ℝ N f x‖ ≤ C * (1 + ‖x‖) ^ k := by choose k C f using hf_temperate.2 use (Finset.range (n + 1)).sup k let C' := max (0 : ℝ) ((Finset.range (n + 1)).sup' (by simp) C) have hC' : 0 ≤ C' := by simp only [C', le_refl, Finset.le_sup'_iff, true_or, le_max_iff] use C', hC' intro N hN x rw [← Finset.mem_range_succ_iff] at hN refine le_trans (f N x) (mul_le_mul ?_ ?_ (by positivity) hC') · simp only [C', Finset.le_sup'_iff, le_max_iff] right exact ⟨N, hN, rfl.le⟩ gcongr · simp exact Finset.le_sup hN lemma _root_.Function.HasTemperateGrowth.of_fderiv {f : E → F} (h'f : Function.HasTemperateGrowth (fderiv ℝ f)) (hf : Differentiable ℝ f) {k : ℕ} {C : ℝ} (h : ∀ x, ‖f x‖ ≤ C * (1 + ‖x‖) ^ k) : Function.HasTemperateGrowth f := by refine ⟨contDiff_succ_iff_fderiv.2 ⟨hf, by simp, h'f.1⟩ , fun n ↦ ?_⟩ rcases n with rfl|m · exact ⟨k, C, fun x ↦ by simpa using h x⟩ · rcases h'f.2 m with ⟨k', C', h'⟩ refine ⟨k', C', ?_⟩ simpa [iteratedFDeriv_succ_eq_comp_right] using h' lemma _root_.Function.HasTemperateGrowth.zero : Function.HasTemperateGrowth (fun _ : E ↦ (0 : F)) := by refine ⟨contDiff_const, fun n ↦ ⟨0, 0, fun x ↦ ?_⟩⟩ simp only [iteratedFDeriv_zero_fun, Pi.zero_apply, norm_zero, forall_const] positivity lemma _root_.Function.HasTemperateGrowth.const (c : F) : Function.HasTemperateGrowth (fun _ : E ↦ c) := .of_fderiv (by simpa using .zero) (differentiable_const c) (k := 0) (C := ‖c‖) (fun x ↦ by simp) lemma _root_.ContinuousLinearMap.hasTemperateGrowth (f : E →L[ℝ] F) : Function.HasTemperateGrowth f := by apply Function.HasTemperateGrowth.of_fderiv ?_ f.differentiable (k := 1) (C := ‖f‖) (fun x ↦ ?_) · have : fderiv ℝ f = fun _ ↦ f := by ext1 v; simp only [ContinuousLinearMap.fderiv] simpa [this] using .const _ · exact (f.le_opNorm x).trans (by simp [mul_add]) variable [NormedAddCommGroup D] [MeasurableSpace D] open MeasureTheory Module open scoped ENNReal /-- A measure `μ` has temperate growth if there is an `n : ℕ` such that `(1 + ‖x‖) ^ (- n)` is `μ`-integrable. -/ class _root_.MeasureTheory.Measure.HasTemperateGrowth (μ : Measure D) : Prop where exists_integrable : ∃ (n : ℕ), Integrable (fun x ↦ (1 + ‖x‖) ^ (- (n : ℝ))) μ open Classical in /-- An integer exponent `l` such that `(1 + ‖x‖) ^ (-l)` is integrable if `μ` has temperate growth. -/ def _root_.MeasureTheory.Measure.integrablePower (μ : Measure D) : ℕ := if h : μ.HasTemperateGrowth then h.exists_integrable.choose else 0 lemma integrable_pow_neg_integrablePower (μ : Measure D) [h : μ.HasTemperateGrowth] : Integrable (fun x ↦ (1 + ‖x‖) ^ (- (μ.integrablePower : ℝ))) μ := by simpa [Measure.integrablePower, h] using h.exists_integrable.choose_spec instance _root_.MeasureTheory.Measure.IsFiniteMeasure.instHasTemperateGrowth {μ : Measure D} [h : IsFiniteMeasure μ] : μ.HasTemperateGrowth := ⟨⟨0, by simp⟩⟩ variable [NormedSpace ℝ D] [FiniteDimensional ℝ D] [BorelSpace D] in instance _root_.MeasureTheory.Measure.IsAddHaarMeasure.instHasTemperateGrowth {μ : Measure D} [h : μ.IsAddHaarMeasure] : μ.HasTemperateGrowth := ⟨⟨finrank ℝ D + 1, by apply integrable_one_add_norm; norm_num⟩⟩ /-- Pointwise inequality to control `x ^ k * f` in terms of `1 / (1 + x) ^ l` if one controls both `f` (with a bound `C₁`) and `x ^ (k + l) * f` (with a bound `C₂`). This will be used to check integrability of `x ^ k * f x` when `f` is a Schwartz function, and to control explicitly its integral in terms of suitable seminorms of `f`. -/ lemma pow_mul_le_of_le_of_pow_mul_le {C₁ C₂ : ℝ} {k l : ℕ} {x f : ℝ} (hx : 0 ≤ x) (hf : 0 ≤ f) (h₁ : f ≤ C₁) (h₂ : x ^ (k + l) * f ≤ C₂) : x ^ k * f ≤ 2 ^ l * (C₁ + C₂) * (1 + x) ^ (- (l : ℝ)) := by have : 0 ≤ C₂ := le_trans (by positivity) h₂ have : 2 ^ l * (C₁ + C₂) * (1 + x) ^ (- (l : ℝ)) = ((1 + x) / 2) ^ (-(l : ℝ)) * (C₁ + C₂) := by rw [Real.div_rpow (by linarith) zero_le_two] simp [div_eq_inv_mul, ← Real.rpow_neg_one, ← Real.rpow_mul] ring rw [this] rcases le_total x 1 with h'x|h'x · gcongr · apply (pow_le_one₀ hx h'x).trans apply Real.one_le_rpow_of_pos_of_le_one_of_nonpos · linarith · linarith · simp · linarith · calc x ^ k * f = x ^ (-(l : ℝ)) * (x ^ (k + l) * f) := by rw [← Real.rpow_natCast, ← Real.rpow_natCast, ← mul_assoc, ← Real.rpow_add (by linarith)] simp _ ≤ ((1 + x) / 2) ^ (-(l : ℝ)) * (C₁ + C₂) := by apply mul_le_mul _ _ (by positivity) (by positivity) · exact Real.rpow_le_rpow_of_nonpos (by linarith) (by linarith) (by simp) · exact h₂.trans (by linarith) variable [BorelSpace D] [SecondCountableTopology D] in /-- Given a function such that `f` and `x ^ (k + l) * f` are bounded for a suitable `l`, then `x ^ k * f` is integrable. The bounds are not relevant for the integrability conclusion, but they are relevant for bounding the integral in `integral_pow_mul_le_of_le_of_pow_mul_le`. We formulate the two lemmas with the same set of assumptions for ease of applications. -/ -- We redeclare `E` here to avoid the `NormedSpace ℝ E` typeclass available throughout this file. lemma integrable_of_le_of_pow_mul_le {E : Type*} [NormedAddCommGroup E] {μ : Measure D} [μ.HasTemperateGrowth] {f : D → E} {C₁ C₂ : ℝ} {k : ℕ} (hf : ∀ x, ‖f x‖ ≤ C₁) (h'f : ∀ x, ‖x‖ ^ (k + μ.integrablePower) * ‖f x‖ ≤ C₂) (h''f : AEStronglyMeasurable f μ) : Integrable (fun x ↦ ‖x‖ ^ k * ‖f x‖) μ := by apply ((integrable_pow_neg_integrablePower μ).const_mul (2 ^ μ.integrablePower * (C₁ + C₂))).mono' · exact AEStronglyMeasurable.mul (aestronglyMeasurable_id.norm.pow _) h''f.norm · filter_upwards with v simp only [norm_mul, norm_pow, norm_norm] apply pow_mul_le_of_le_of_pow_mul_le (norm_nonneg _) (norm_nonneg _) (hf v) (h'f v) /-- Given a function such that `f` and `x ^ (k + l) * f` are bounded for a suitable `l`, then one can bound explicitly the integral of `x ^ k * f`. -/ -- We redeclare `E` here to avoid the `NormedSpace ℝ E` typeclass available throughout this file. lemma integral_pow_mul_le_of_le_of_pow_mul_le {E : Type*} [NormedAddCommGroup E] {μ : Measure D} [μ.HasTemperateGrowth] {f : D → E} {C₁ C₂ : ℝ} {k : ℕ} (hf : ∀ x, ‖f x‖ ≤ C₁) (h'f : ∀ x, ‖x‖ ^ (k + μ.integrablePower) * ‖f x‖ ≤ C₂) : ∫ x, ‖x‖ ^ k * ‖f x‖ ∂μ ≤ 2 ^ μ.integrablePower * (∫ x, (1 + ‖x‖) ^ (- (μ.integrablePower : ℝ)) ∂μ) * (C₁ + C₂) := by rw [← integral_const_mul, ← integral_mul_const] apply integral_mono_of_nonneg · filter_upwards with v using by positivity · exact ((integrable_pow_neg_integrablePower μ).const_mul _).mul_const _ filter_upwards with v exact (pow_mul_le_of_le_of_pow_mul_le (norm_nonneg _) (norm_nonneg _) (hf v) (h'f v)).trans (le_of_eq (by ring)) /-- For any `HasTemperateGrowth` measure and `p`, there exists an integer power `k` such that `(1 + ‖x‖) ^ (-k)` is in `L^p`. -/ theorem _root_.MeasureTheory.Measure.HasTemperateGrowth.exists_eLpNorm_lt_top (p : ℝ≥0∞) {μ : Measure D} (hμ : μ.HasTemperateGrowth) : ∃ k : ℕ, eLpNorm (fun x ↦ (1 + ‖x‖) ^ (-k : ℝ)) p μ < ⊤ := by cases p with | top => exact ⟨0, eLpNormEssSup_lt_top_of_ae_bound (C := 1) (by simp)⟩ | coe p => cases eq_or_ne (p : ℝ≥0∞) 0 with | inl hp => exact ⟨0, by simp [hp]⟩ | inr hp => have h_one_add (x : D) : 0 < 1 + ‖x‖ := lt_add_of_pos_of_le zero_lt_one (norm_nonneg x) have hp_pos : 0 < (p : ℝ) := by simpa [zero_lt_iff] using hp rcases hμ.exists_integrable with ⟨l, hl⟩ let k := ⌈(l / p : ℝ)⌉₊ have hlk : l ≤ k * (p : ℝ) := by simpa [div_le_iff₀ hp_pos] using Nat.le_ceil (l / p : ℝ) use k suffices HasFiniteIntegral (fun x ↦ ((1 + ‖x‖) ^ (-(k * p) : ℝ))) μ by rw [hasFiniteIntegral_iff_enorm] at this rw [eLpNorm_lt_top_iff_lintegral_rpow_enorm_lt_top hp ENNReal.coe_ne_top] simp only [ENNReal.coe_toReal] refine Eq.subst (motive := (∫⁻ x, · x ∂μ < ⊤)) (funext fun x ↦ ?_) this rw [← neg_mul, Real.rpow_mul (h_one_add x).le] exact Real.enorm_rpow_of_nonneg (Real.rpow_nonneg (h_one_add x).le _) NNReal.zero_le_coe refine hl.hasFiniteIntegral.mono' (ae_of_all μ fun x ↦ ?_) rw [Real.norm_of_nonneg (Real.rpow_nonneg (h_one_add x).le _)] gcongr simp end TemperateGrowth section CLM /-! ### Construction of continuous linear maps between Schwartz spaces -/ variable [NormedField 𝕜] [NormedField 𝕜'] variable [NormedAddCommGroup D] [NormedSpace ℝ D] variable [NormedSpace 𝕜 E] [SMulCommClass ℝ 𝕜 E] variable [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedSpace 𝕜' G] [SMulCommClass ℝ 𝕜' G] variable {σ : 𝕜 →+* 𝕜'} /-- Create a semilinear map between Schwartz spaces. Note: This is a helper definition for `mkCLM`. -/ def mkLM (A : (D → E) → F → G) (hadd : ∀ (f g : 𝓢(D, E)) (x), A (f + g) x = A f x + A g x) (hsmul : ∀ (a : 𝕜) (f : 𝓢(D, E)) (x), A (a • f) x = σ a • A f x) (hsmooth : ∀ f : 𝓢(D, E), ContDiff ℝ ∞ (A f)) (hbound : ∀ n : ℕ × ℕ, ∃ (s : Finset (ℕ × ℕ)) (C : ℝ), 0 ≤ C ∧ ∀ (f : 𝓢(D, E)) (x : F), ‖x‖ ^ n.fst * ‖iteratedFDeriv ℝ n.snd (A f) x‖ ≤ C * s.sup (schwartzSeminormFamily 𝕜 D E) f) : 𝓢(D, E) →ₛₗ[σ] 𝓢(F, G) where toFun f := { toFun := A f smooth' := hsmooth f decay' := by intro k n rcases hbound ⟨k, n⟩ with ⟨s, C, _, h⟩ exact ⟨C * (s.sup (schwartzSeminormFamily 𝕜 D E)) f, h f⟩ } map_add' f g := ext (hadd f g) map_smul' a f := ext (hsmul a f) /-- Create a continuous semilinear map between Schwartz spaces. For an example of using this definition, see `fderivCLM`. -/ def mkCLM [RingHomIsometric σ] (A : (D → E) → F → G) (hadd : ∀ (f g : 𝓢(D, E)) (x), A (f + g) x = A f x + A g x) (hsmul : ∀ (a : 𝕜) (f : 𝓢(D, E)) (x), A (a • f) x = σ a • A f x) (hsmooth : ∀ f : 𝓢(D, E), ContDiff ℝ ∞ (A f)) (hbound : ∀ n : ℕ × ℕ, ∃ (s : Finset (ℕ × ℕ)) (C : ℝ), 0 ≤ C ∧ ∀ (f : 𝓢(D, E)) (x : F), ‖x‖ ^ n.fst * ‖iteratedFDeriv ℝ n.snd (A f) x‖ ≤ C * s.sup (schwartzSeminormFamily 𝕜 D E) f) : 𝓢(D, E) →SL[σ] 𝓢(F, G) where cont := by change Continuous (mkLM A hadd hsmul hsmooth hbound : 𝓢(D, E) →ₛₗ[σ] 𝓢(F, G)) refine Seminorm.continuous_from_bounded (schwartz_withSeminorms 𝕜 D E) (schwartz_withSeminorms 𝕜' F G) _ fun n => ?_ rcases hbound n with ⟨s, C, hC, h⟩ refine ⟨s, ⟨C, hC⟩, fun f => ?_⟩ exact (mkLM A hadd hsmul hsmooth hbound f).seminorm_le_bound 𝕜' n.1 n.2 (by positivity) (h f) toLinearMap := mkLM A hadd hsmul hsmooth hbound /-- Define a continuous semilinear map from Schwartz space to a normed space. -/ def mkCLMtoNormedSpace [RingHomIsometric σ] (A : 𝓢(D, E) → G) (hadd : ∀ (f g : 𝓢(D, E)), A (f + g) = A f + A g) (hsmul : ∀ (a : 𝕜) (f : 𝓢(D, E)), A (a • f) = σ a • A f) (hbound : ∃ (s : Finset (ℕ × ℕ)) (C : ℝ), 0 ≤ C ∧ ∀ (f : 𝓢(D, E)), ‖A f‖ ≤ C * s.sup (schwartzSeminormFamily 𝕜 D E) f) : 𝓢(D, E) →SL[σ] G := letI f : 𝓢(D, E) →ₛₗ[σ] G := { toFun := (A ·) map_add' := hadd map_smul' := hsmul } { toLinearMap := f cont := by change Continuous (LinearMap.mk _ _) apply Seminorm.cont_withSeminorms_normedSpace G (schwartz_withSeminorms 𝕜 D E) rcases hbound with ⟨s, C, hC, h⟩ exact ⟨s, ⟨C, hC⟩, h⟩ } end CLM section EvalCLM variable [NormedField 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] /-- The map applying a vector to Hom-valued Schwartz function as a continuous linear map. -/ protected def evalCLM (m : E) : 𝓢(E, E →L[ℝ] F) →L[𝕜] 𝓢(E, F) := mkCLM (fun f x => f x m) (fun _ _ _ => rfl) (fun _ _ _ => rfl) (fun f => ContDiff.clm_apply f.2 contDiff_const) <| by rintro ⟨k, n⟩ use {(k, n)}, ‖m‖, norm_nonneg _ intro f x simp only [Finset.sup_singleton, schwartzSeminormFamily_apply] calc ‖x‖ ^ k * ‖iteratedFDeriv ℝ n (f · m) x‖ ≤ ‖x‖ ^ k * (‖m‖ * ‖iteratedFDeriv ℝ n f x‖) := by gcongr exact norm_iteratedFDeriv_clm_apply_const (f.smooth _).contDiffAt le_rfl _ ≤ ‖m‖ * SchwartzMap.seminorm 𝕜 k n f := by move_mul [‖m‖] gcongr apply le_seminorm end EvalCLM section Multiplication variable [NontriviallyNormedField 𝕜] [NormedAlgebra ℝ 𝕜] [NormedAddCommGroup D] [NormedSpace ℝ D] [NormedAddCommGroup G] [NormedSpace ℝ G] [NormedSpace 𝕜 E] [NormedSpace 𝕜 F] [NormedSpace 𝕜 G] /-- The map `f ↦ (x ↦ B (f x) (g x))` as a continuous `𝕜`-linear map on Schwartz space, where `B` is a continuous `𝕜`-linear map and `g` is a function of temperate growth. -/ def bilinLeftCLM (B : E →L[𝕜] F →L[𝕜] G) {g : D → F} (hg : g.HasTemperateGrowth) : 𝓢(D, E) →L[𝕜] 𝓢(D, G) := by refine mkCLM (fun f x => B (f x) (g x)) (fun _ _ _ => by simp only [map_add, add_left_inj, Pi.add_apply, eq_self_iff_true, ContinuousLinearMap.add_apply]) (fun _ _ _ => by simp only [smul_apply, map_smul, ContinuousLinearMap.coe_smul', Pi.smul_apply, RingHom.id_apply]) (fun f => (B.bilinearRestrictScalars ℝ).isBoundedBilinearMap.contDiff.comp (f.smooth'.prodMk hg.1)) ?_ rintro ⟨k, n⟩ rcases hg.norm_iteratedFDeriv_le_uniform_aux n with ⟨l, C, hC, hgrowth⟩ use Finset.Iic (l + k, n), ‖B‖ * ((n : ℝ) + (1 : ℝ)) * n.choose (n / 2) * (C * 2 ^ (l + k)), by positivity intro f x have hxk : 0 ≤ ‖x‖ ^ k := by positivity simp_rw [← ContinuousLinearMap.bilinearRestrictScalars_apply_apply ℝ B] have hnorm_mul := ContinuousLinearMap.norm_iteratedFDeriv_le_of_bilinear (B.bilinearRestrictScalars ℝ) f.smooth' hg.1 x (n := n) (mod_cast le_top) refine le_trans (mul_le_mul_of_nonneg_left hnorm_mul hxk) ?_ rw [ContinuousLinearMap.norm_bilinearRestrictScalars] move_mul [← ‖B‖] simp_rw [mul_assoc ‖B‖] gcongr _ * ?_ rw [Finset.mul_sum] have : (∑ _x ∈ Finset.range (n + 1), (1 : ℝ)) = n + 1 := by simp simp_rw [mul_assoc ((n : ℝ) + 1)] rw [← this, Finset.sum_mul] refine Finset.sum_le_sum fun i hi => ?_ simp only [one_mul] move_mul [(Nat.choose n i : ℝ), (Nat.choose n (n / 2) : ℝ)] gcongr ?_ * ?_ swap · norm_cast exact i.choose_le_middle n specialize hgrowth (n - i) (by simp only [tsub_le_self]) x refine le_trans (mul_le_mul_of_nonneg_left hgrowth (by positivity)) ?_ move_mul [C] gcongr ?_ * C rw [Finset.mem_range_succ_iff] at hi change i ≤ (l + k, n).snd at hi refine le_trans ?_ (one_add_le_sup_seminorm_apply le_rfl hi f x) rw [pow_add] move_mul [(1 + ‖x‖) ^ l] gcongr simp end Multiplication section Comp variable (𝕜) variable [RCLike 𝕜] variable [NormedAddCommGroup D] [NormedSpace ℝ D] variable [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] /-- Composition with a function on the right is a continuous linear map on Schwartz space provided that the function is temperate and growths polynomially near infinity. -/ def compCLM {g : D → E} (hg : g.HasTemperateGrowth) (hg_upper : ∃ (k : ℕ) (C : ℝ), ∀ x, ‖x‖ ≤ C * (1 + ‖g x‖) ^ k) : 𝓢(E, F) →L[𝕜] 𝓢(D, F) := by refine mkCLM (fun f x => f (g x)) (fun _ _ _ => by simp only [add_left_inj, Pi.add_apply, eq_self_iff_true]) (fun _ _ _ => rfl) (fun f => f.smooth'.comp hg.1) ?_ rintro ⟨k, n⟩ rcases hg.norm_iteratedFDeriv_le_uniform_aux n with ⟨l, C, hC, hgrowth⟩ rcases hg_upper with ⟨kg, Cg, hg_upper'⟩ have hCg : 1 ≤ 1 + Cg := by refine le_add_of_nonneg_right ?_ specialize hg_upper' 0 rw [norm_zero] at hg_upper' exact nonneg_of_mul_nonneg_left hg_upper' (by positivity) let k' := kg * (k + l * n) use Finset.Iic (k', n), (1 + Cg) ^ (k + l * n) * ((C + 1) ^ n * n ! * 2 ^ k'), by positivity intro f x let seminorm_f := ((Finset.Iic (k', n)).sup (schwartzSeminormFamily 𝕜 _ _)) f have hg_upper'' : (1 + ‖x‖) ^ (k + l * n) ≤ (1 + Cg) ^ (k + l * n) * (1 + ‖g x‖) ^ k' := by rw [pow_mul, ← mul_pow] gcongr rw [add_mul] refine add_le_add ?_ (hg_upper' x) nth_rw 1 [← one_mul (1 : ℝ)] gcongr apply one_le_pow₀ simp only [le_add_iff_nonneg_right, norm_nonneg] have hbound : ∀ i, i ≤ n → ‖iteratedFDeriv ℝ i f (g x)‖ ≤ 2 ^ k' * seminorm_f / (1 + ‖g x‖) ^ k' := by intro i hi have hpos : 0 < (1 + ‖g x‖) ^ k' := by positivity rw [le_div_iff₀' hpos] change i ≤ (k', n).snd at hi exact one_add_le_sup_seminorm_apply le_rfl hi _ _ have hgrowth' : ∀ N : ℕ, 1 ≤ N → N ≤ n → ‖iteratedFDeriv ℝ N g x‖ ≤ ((C + 1) * (1 + ‖x‖) ^ l) ^ N := by intro N hN₁ hN₂ refine (hgrowth N hN₂ x).trans ?_ rw [mul_pow] have hN₁' := (lt_of_lt_of_le zero_lt_one hN₁).ne' gcongr · exact le_trans (by simp [hC]) (le_self_pow₀ (by simp [hC]) hN₁') · refine le_self_pow₀ (one_le_pow₀ ?_) hN₁' simp only [le_add_iff_nonneg_right, norm_nonneg] have := norm_iteratedFDeriv_comp_le f.smooth' hg.1 (mod_cast le_top) x hbound hgrowth' have hxk : ‖x‖ ^ k ≤ (1 + ‖x‖) ^ k := pow_le_pow_left₀ (norm_nonneg _) (by simp only [zero_le_one, le_add_iff_nonneg_left]) _ refine le_trans (mul_le_mul hxk this (by positivity) (by positivity)) ?_ have rearrange : (1 + ‖x‖) ^ k * (n ! * (2 ^ k' * seminorm_f / (1 + ‖g x‖) ^ k') * ((C + 1) * (1 + ‖x‖) ^ l) ^ n) = (1 + ‖x‖) ^ (k + l * n) / (1 + ‖g x‖) ^ k' * ((C + 1) ^ n * n ! * 2 ^ k' * seminorm_f) := by rw [mul_pow, pow_add, ← pow_mul] ring rw [rearrange] have hgxk' : 0 < (1 + ‖g x‖) ^ k' := by positivity rw [← div_le_iff₀ hgxk'] at hg_upper'' have hpos : (0 : ℝ) ≤ (C + 1) ^ n * n ! * 2 ^ k' * seminorm_f := by have : 0 ≤ seminorm_f := apply_nonneg _ _ positivity refine le_trans (mul_le_mul_of_nonneg_right hg_upper'' hpos) ?_ rw [← mul_assoc] @[simp] lemma compCLM_apply {g : D → E} (hg : g.HasTemperateGrowth) (hg_upper : ∃ (k : ℕ) (C : ℝ), ∀ x, ‖x‖ ≤ C * (1 + ‖g x‖) ^ k) (f : 𝓢(E, F)) : compCLM 𝕜 hg hg_upper f = f ∘ g := rfl /-- Composition with a function on the right is a continuous linear map on Schwartz space provided that the function is temperate and antilipschitz. -/ def compCLMOfAntilipschitz {K : ℝ≥0} {g : D → E} (hg : g.HasTemperateGrowth) (h'g : AntilipschitzWith K g) : 𝓢(E, F) →L[𝕜] 𝓢(D, F) := by refine compCLM 𝕜 hg ⟨1, K * max 1 ‖g 0‖, fun x ↦ ?_⟩ calc ‖x‖ ≤ K * ‖g x - g 0‖ := by rw [← dist_zero_right, ← dist_eq_norm] apply h'g.le_mul_dist _ ≤ K * (‖g x‖ + ‖g 0‖) := by gcongr exact norm_sub_le _ _ _ ≤ K * (‖g x‖ + max 1 ‖g 0‖) := by gcongr exact le_max_right _ _ _ ≤ (K * max 1 ‖g 0‖ : ℝ) * (1 + ‖g x‖) ^ 1 := by simp only [mul_add, add_comm (K * ‖g x‖), pow_one, mul_one, add_le_add_iff_left] gcongr exact le_mul_of_one_le_right (by positivity) (le_max_left _ _) @[simp] lemma compCLMOfAntilipschitz_apply {K : ℝ≥0} {g : D → E} (hg : g.HasTemperateGrowth) (h'g : AntilipschitzWith K g) (f : 𝓢(E, F)) : compCLMOfAntilipschitz 𝕜 hg h'g f = f ∘ g := rfl /-- Composition with a continuous linear equiv on the right is a continuous linear map on Schwartz space. -/ def compCLMOfContinuousLinearEquiv (g : D ≃L[ℝ] E) : 𝓢(E, F) →L[𝕜] 𝓢(D, F) := compCLMOfAntilipschitz 𝕜 (g.toContinuousLinearMap.hasTemperateGrowth) g.antilipschitz @[simp] lemma compCLMOfContinuousLinearEquiv_apply (g : D ≃L[ℝ] E) (f : 𝓢(E, F)) : compCLMOfContinuousLinearEquiv 𝕜 g f = f ∘ g := rfl end Comp section Derivatives /-! ### Derivatives of Schwartz functions -/ variable (𝕜) variable [RCLike 𝕜] [NormedSpace 𝕜 F] [SMulCommClass ℝ 𝕜 F] /-- The Fréchet derivative on Schwartz space as a continuous `𝕜`-linear map. -/ def fderivCLM : 𝓢(E, F) →L[𝕜] 𝓢(E, E →L[ℝ] F) := mkCLM (fderiv ℝ) (fun f g _ => fderiv_add f.differentiableAt g.differentiableAt) (fun a f _ => fderiv_const_smul f.differentiableAt a) (fun f => (contDiff_succ_iff_fderiv.mp f.smooth').2.2) fun ⟨k, n⟩ => ⟨{⟨k, n + 1⟩}, 1, zero_le_one, fun f x => by simpa only [schwartzSeminormFamily_apply, Seminorm.comp_apply, Finset.sup_singleton, one_smul, norm_iteratedFDeriv_fderiv, one_mul] using f.le_seminorm 𝕜 k (n + 1) x⟩ @[simp] theorem fderivCLM_apply (f : 𝓢(E, F)) (x : E) : fderivCLM 𝕜 f x = fderiv ℝ f x := rfl /-- The 1-dimensional derivative on Schwartz space as a continuous `𝕜`-linear map. -/ def derivCLM : 𝓢(ℝ, F) →L[𝕜] 𝓢(ℝ, F) := mkCLM deriv (fun f g _ => deriv_add f.differentiableAt g.differentiableAt) (fun a f _ => deriv_const_smul a f.differentiableAt) (fun f => (contDiff_succ_iff_deriv.mp f.smooth').2.2) fun ⟨k, n⟩ => ⟨{⟨k, n + 1⟩}, 1, zero_le_one, fun f x => by simpa only [Real.norm_eq_abs, Finset.sup_singleton, schwartzSeminormFamily_apply, one_mul, norm_iteratedFDeriv_eq_norm_iteratedDeriv, ← iteratedDeriv_succ'] using f.le_seminorm' 𝕜 k (n + 1) x⟩ @[simp] theorem derivCLM_apply (f : 𝓢(ℝ, F)) (x : ℝ) : derivCLM 𝕜 f x = deriv f x := rfl /-- The partial derivative (or directional derivative) in the direction `m : E` as a continuous linear map on Schwartz space. -/ def pderivCLM (m : E) : 𝓢(E, F) →L[𝕜] 𝓢(E, F) := (SchwartzMap.evalCLM m).comp (fderivCLM 𝕜) @[simp] theorem pderivCLM_apply (m : E) (f : 𝓢(E, F)) (x : E) : pderivCLM 𝕜 m f x = fderiv ℝ f x m := rfl theorem pderivCLM_eq_lineDeriv (m : E) (f : 𝓢(E, F)) (x : E) : pderivCLM 𝕜 m f x = lineDeriv ℝ f x m := by simp only [pderivCLM_apply, f.differentiableAt.lineDeriv_eq_fderiv] /-- The iterated partial derivative (or directional derivative) as a continuous linear map on Schwartz space. -/ def iteratedPDeriv {n : ℕ} : (Fin n → E) → 𝓢(E, F) →L[𝕜] 𝓢(E, F) := Nat.recOn n (fun _ => ContinuousLinearMap.id 𝕜 _) fun _ rec x => (pderivCLM 𝕜 (x 0)).comp (rec (Fin.tail x)) @[simp] theorem iteratedPDeriv_zero (m : Fin 0 → E) (f : 𝓢(E, F)) : iteratedPDeriv 𝕜 m f = f := rfl @[simp] theorem iteratedPDeriv_one (m : Fin 1 → E) (f : 𝓢(E, F)) : iteratedPDeriv 𝕜 m f = pderivCLM 𝕜 (m 0) f := rfl theorem iteratedPDeriv_succ_left {n : ℕ} (m : Fin (n + 1) → E) (f : 𝓢(E, F)) : iteratedPDeriv 𝕜 m f = pderivCLM 𝕜 (m 0) (iteratedPDeriv 𝕜 (Fin.tail m) f) := rfl theorem iteratedPDeriv_succ_right {n : ℕ} (m : Fin (n + 1) → E) (f : 𝓢(E, F)) : iteratedPDeriv 𝕜 m f = iteratedPDeriv 𝕜 (Fin.init m) (pderivCLM 𝕜 (m (Fin.last n)) f) := by induction n with | zero => rw [iteratedPDeriv_zero, iteratedPDeriv_one] rfl -- The proof is `∂^{n + 2} = ∂ ∂^{n + 1} = ∂ ∂^n ∂ = ∂^{n+1} ∂` | succ n IH => have hmzero : Fin.init m 0 = m 0 := by simp only [Fin.init_def, Fin.castSucc_zero] have hmtail : Fin.tail m (Fin.last n) = m (Fin.last n.succ) := by simp only [Fin.tail_def, Fin.succ_last] calc _ = pderivCLM 𝕜 (m 0) (iteratedPDeriv 𝕜 _ f) := iteratedPDeriv_succ_left _ _ _ _ = pderivCLM 𝕜 (m 0) ((iteratedPDeriv 𝕜 _) ((pderivCLM 𝕜 _) f)) := by congr 1 exact IH _ _ = _ := by simp only [hmtail, iteratedPDeriv_succ_left, hmzero, Fin.tail_init_eq_init_tail] theorem iteratedPDeriv_eq_iteratedFDeriv {n : ℕ} {m : Fin n → E} {f : 𝓢(E, F)} {x : E} : iteratedPDeriv 𝕜 m f x = iteratedFDeriv ℝ n f x m := by induction n generalizing x with | zero => simp | succ n ih => simp only [iteratedPDeriv_succ_left, iteratedFDeriv_succ_apply_left] rw [← fderiv_continuousMultilinear_apply_const_apply] · simp [← ih] · exact f.smooth'.differentiable_iteratedFDeriv (mod_cast ENat.coe_lt_top n) x end Derivatives section Integration /-! ### Integration -/ open Real Complex Filter MeasureTheory MeasureTheory.Measure Module variable [RCLike 𝕜] variable [NormedAddCommGroup D] [NormedSpace ℝ D] variable [NormedAddCommGroup V] [NormedSpace ℝ V] [NormedSpace 𝕜 V] variable [MeasurableSpace D] variable {μ : Measure D} [hμ : HasTemperateGrowth μ] attribute [local instance 101] secondCountableTopologyEither_of_left variable (𝕜 μ) in lemma integral_pow_mul_iteratedFDeriv_le (f : 𝓢(D, V)) (k n : ℕ) : ∫ x, ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖ ∂μ ≤ 2 ^ μ.integrablePower * (∫ x, (1 + ‖x‖) ^ (- (μ.integrablePower : ℝ)) ∂μ) * (SchwartzMap.seminorm 𝕜 0 n f + SchwartzMap.seminorm 𝕜 (k + μ.integrablePower) n f) := integral_pow_mul_le_of_le_of_pow_mul_le (norm_iteratedFDeriv_le_seminorm ℝ _ _) (le_seminorm ℝ _ _ _) variable [BorelSpace D] [SecondCountableTopology D] variable (μ) in lemma integrable_pow_mul_iteratedFDeriv (f : 𝓢(D, V)) (k n : ℕ) : Integrable (fun x ↦ ‖x‖ ^ k * ‖iteratedFDeriv ℝ n f x‖) μ := integrable_of_le_of_pow_mul_le (norm_iteratedFDeriv_le_seminorm ℝ _ _) (le_seminorm ℝ _ _ _) ((f.smooth ⊤).continuous_iteratedFDeriv (mod_cast le_top)).aestronglyMeasurable
variable (μ) in lemma integrable_pow_mul (f : 𝓢(D, V)) (k : ℕ) : Integrable (fun x ↦ ‖x‖ ^ k * ‖f x‖) μ := by convert integrable_pow_mul_iteratedFDeriv μ f k 0 with x simp lemma integrable (f : 𝓢(D, V)) : Integrable f μ := (f.integrable_pow_mul μ 0).mono f.continuous.aestronglyMeasurable (Eventually.of_forall (fun _ ↦ by simp)) variable (𝕜 μ) in /-- The integral as a continuous linear map from Schwartz space to the codomain. -/ def integralCLM : 𝓢(D, V) →L[𝕜] V := by refine mkCLMtoNormedSpace (∫ x, · x ∂μ) (fun f g ↦ integral_add f.integrable g.integrable) (integral_smul · ·) ?_ rcases hμ.exists_integrable with ⟨n, h⟩
Mathlib/Analysis/Distribution/SchwartzSpace.lean
1,098
1,113
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Logic.Encodable.Lattice import Mathlib.Order.Filter.AtTopBot.Finset import Mathlib.Topology.Algebra.InfiniteSum.Group /-! # Infinite sums and products over `ℕ` and `ℤ` This file contains lemmas about `HasSum`, `Summable`, `tsum`, `HasProd`, `Multipliable`, and `tprod` applied to the important special cases where the domain is `ℕ` or `ℤ`. For instance, we prove the formula `∑ i ∈ range k, f i + ∑' i, f (i + k) = ∑' i, f i`, ∈ `sum_add_tsum_nat_add`, as well as several results relating sums and products on `ℕ` to sums and products on `ℤ`. -/ noncomputable section open Filter Finset Function Encodable open scoped Topology variable {M : Type*} [CommMonoid M] [TopologicalSpace M] {m m' : M} variable {G : Type*} [CommGroup G] {g g' : G} -- don't declare `[IsTopologicalAddGroup G]`, here as some results require -- `[IsUniformAddGroup G]` instead /-! ## Sums over `ℕ` -/ section Nat section Monoid /-- If `f : ℕ → M` has product `m`, then the partial products `∏ i ∈ range n, f i` converge to `m`. -/ @[to_additive "If `f : ℕ → M` has sum `m`, then the partial sums `∑ i ∈ range n, f i` converge to `m`."] theorem HasProd.tendsto_prod_nat {f : ℕ → M} (h : HasProd f m) : Tendsto (fun n ↦ ∏ i ∈ range n, f i) atTop (𝓝 m) := h.comp tendsto_finset_range /-- If `f : ℕ → M` is multipliable, then the partial products `∏ i ∈ range n, f i` converge to `∏' i, f i`. -/ @[to_additive "If `f : ℕ → M` is summable, then the partial sums `∑ i ∈ range n, f i` converge to `∑' i, f i`."] theorem Multipliable.tendsto_prod_tprod_nat {f : ℕ → M} (h : Multipliable f) : Tendsto (fun n ↦ ∏ i ∈ range n, f i) atTop (𝓝 (∏' i, f i)) := h.hasProd.tendsto_prod_nat @[deprecated (since := "2025-02-02")] alias HasProd.Multipliable.tendsto_prod_tprod_nat := Multipliable.tendsto_prod_tprod_nat @[deprecated (since := "2025-02-02")] alias HasSum.Multipliable.tendsto_sum_tsum_nat := Summable.tendsto_sum_tsum_nat namespace HasProd section ContinuousMul variable [ContinuousMul M] @[to_additive] theorem prod_range_mul {f : ℕ → M} {k : ℕ} (h : HasProd (fun n ↦ f (n + k)) m) : HasProd f ((∏ i ∈ range k, f i) * m) := by refine ((range k).hasProd f).mul_compl ?_ rwa [← (notMemRangeEquiv k).symm.hasProd_iff] @[to_additive] theorem zero_mul {f : ℕ → M} (h : HasProd (fun n ↦ f (n + 1)) m) : HasProd f (f 0 * m) := by simpa only [prod_range_one] using h.prod_range_mul @[to_additive] theorem even_mul_odd {f : ℕ → M} (he : HasProd (fun k ↦ f (2 * k)) m) (ho : HasProd (fun k ↦ f (2 * k + 1)) m') : HasProd f (m * m') := by have := mul_right_injective₀ (two_ne_zero' ℕ) replace ho := ((add_left_injective 1).comp this).hasProd_range_iff.2 ho refine (this.hasProd_range_iff.2 he).mul_isCompl ?_ ho simpa [Function.comp_def] using Nat.isCompl_even_odd end ContinuousMul
end HasProd namespace Multipliable
Mathlib/Topology/Algebra/InfiniteSum/NatInt.lean
88
92
/- Copyright (c) 2021 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.Convex.Between import Mathlib.MeasureTheory.Constructions.BorelSpace.Basic import Mathlib.MeasureTheory.Measure.Lebesgue.Basic import Mathlib.Topology.MetricSpace.Holder import Mathlib.Topology.MetricSpace.MetricSeparated /-! # Hausdorff measure and metric (outer) measures In this file we define the `d`-dimensional Hausdorff measure on an (extended) metric space `X` and the Hausdorff dimension of a set in an (extended) metric space. Let `μ d δ` be the maximal outer measure such that `μ d δ s ≤ (EMetric.diam s) ^ d` for every set of diameter less than `δ`. Then the Hausdorff measure `μH[d] s` of `s` is defined as `⨆ δ > 0, μ d δ s`. By Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, this is a Borel measure on `X`. The value of `μH[d]`, `d > 0`, on a set `s` (measurable or not) is given by ``` μH[d] s = ⨆ (r : ℝ≥0∞) (hr : 0 < r), ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, EMetric.diam (t n) ^ d ``` For every set `s` for any `d < d'` we have either `μH[d] s = ∞` or `μH[d'] s = 0`, see `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`. In `Mathlib.Topology.MetricSpace.HausdorffDimension` we use this fact to define the Hausdorff dimension `dimH` of a set in an (extended) metric space. We also define two generalizations of the Hausdorff measure. In one generalization (see `MeasureTheory.Measure.mkMetric`) we take any function `m (diam s)` instead of `(diam s) ^ d`. In an even more general definition (see `MeasureTheory.Measure.mkMetric'`) we use any function of `m : Set X → ℝ≥0∞`. Some authors start with a partial function `m` defined only on some sets `s : Set X` (e.g., only on balls or only on measurable sets). This is equivalent to our definition applied to `MeasureTheory.extend m`. We also define a predicate `MeasureTheory.OuterMeasure.IsMetric` which says that an outer measure is additive on metric separated pairs of sets: `μ (s ∪ t) = μ s + μ t` provided that `⨅ (x ∈ s) (y ∈ t), edist x y ≠ 0`. This is the property required for the Caratheodory theorem `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`, so we prove this theorem for any metric outer measure, then prove that outer measures constructed using `mkMetric'` are metric outer measures. ## Main definitions * `MeasureTheory.OuterMeasure.IsMetric`: an outer measure `μ` is called *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s` and `t`. A metric outer measure in a Borel extended metric space is guaranteed to satisfy the Caratheodory condition, see `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`. * `MeasureTheory.OuterMeasure.mkMetric'` and its particular case `MeasureTheory.OuterMeasure.mkMetric`: a construction of an outer measure that is guaranteed to be metric. Both constructions are generalizations of the Hausdorff measure. The same measures interpreted as Borel measures are called `MeasureTheory.Measure.mkMetric'` and `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure` a.k.a. `μH[d]`: the `d`-dimensional Hausdorff measure. There are many definitions of the Hausdorff measure that differ from each other by a multiplicative constant. We put `μH[d] s = ⨆ r > 0, ⨅ (t : ℕ → Set X) (hts : s ⊆ ⋃ n, t n) (ht : ∀ n, EMetric.diam (t n) ≤ r), ∑' n, ⨆ (ht : ¬Set.Subsingleton (t n)), (EMetric.diam (t n)) ^ d`, see `MeasureTheory.Measure.hausdorffMeasure_apply`. In the most interesting case `0 < d` one can omit the `⨆ (ht : ¬Set.Subsingleton (t n))` part. ## Main statements ### Basic properties * `MeasureTheory.OuterMeasure.IsMetric.borel_le_caratheodory`: if `μ` is a metric outer measure on an extended metric space `X` (that is, it is additive on pairs of metric separated sets), then every Borel set is Caratheodory measurable (hence, `μ` defines an actual `MeasureTheory.Measure`). See also `MeasureTheory.Measure.mkMetric`. * `MeasureTheory.Measure.hausdorffMeasure_mono`: `μH[d] s` is an antitone function of `d`. * `MeasureTheory.Measure.hausdorffMeasure_zero_or_top`: if `d₁ < d₂`, then for any `s`, either `μH[d₂] s = 0` or `μH[d₁] s = ∞`. Together with the previous lemma, this means that `μH[d] s` is equal to infinity on some ray `(-∞, D)` and is equal to zero on `(D, +∞)`, where `D` is a possibly infinite number called the *Hausdorff dimension* of `s`; `μH[D] s` can be zero, infinity, or anything in between. * `MeasureTheory.Measure.noAtoms_hausdorff`: Hausdorff measure has no atoms. ### Hausdorff measure in `ℝⁿ` * `MeasureTheory.hausdorffMeasure_pi_real`: for a nonempty `ι`, `μH[card ι]` on `ι → ℝ` equals Lebesgue measure. ## Notations We use the following notation localized in `MeasureTheory`. - `μH[d]` : `MeasureTheory.Measure.hausdorffMeasure d` ## Implementation notes There are a few similar constructions called the `d`-dimensional Hausdorff measure. E.g., some sources only allow coverings by balls and use `r ^ d` instead of `(diam s) ^ d`. While these construction lead to different Hausdorff measures, they lead to the same notion of the Hausdorff dimension. ## References * [Herbert Federer, Geometric Measure Theory, Chapter 2.10][Federer1996] ## Tags Hausdorff measure, measure, metric measure -/ open scoped NNReal ENNReal Topology open EMetric Set Function Filter Encodable Module TopologicalSpace noncomputable section variable {ι X Y : Type*} [EMetricSpace X] [EMetricSpace Y] namespace MeasureTheory namespace OuterMeasure /-! ### Metric outer measures In this section we define metric outer measures and prove Caratheodory theorem: a metric outer measure has the Caratheodory property. -/ /-- We say that an outer measure `μ` in an (e)metric space is *metric* if `μ (s ∪ t) = μ s + μ t` for any two metric separated sets `s`, `t`. -/ def IsMetric (μ : OuterMeasure X) : Prop := ∀ s t : Set X, Metric.AreSeparated s t → μ (s ∪ t) = μ s + μ t namespace IsMetric variable {μ : OuterMeasure X} /-- A metric outer measure is additive on a finite set of pairwise metric separated sets. -/ theorem finset_iUnion_of_pairwise_separated (hm : IsMetric μ) {I : Finset ι} {s : ι → Set X} (hI : ∀ i ∈ I, ∀ j ∈ I, i ≠ j → Metric.AreSeparated (s i) (s j)) : μ (⋃ i ∈ I, s i) = ∑ i ∈ I, μ (s i) := by classical induction I using Finset.induction_on with | empty => simp | insert i I hiI ihI => simp only [Finset.mem_insert] at hI rw [Finset.set_biUnion_insert, hm, ihI, Finset.sum_insert hiI] exacts [fun i hi j hj hij => hI i (Or.inr hi) j (Or.inr hj) hij, Metric.AreSeparated.finset_iUnion_right fun j hj => hI i (Or.inl rfl) j (Or.inr hj) (ne_of_mem_of_not_mem hj hiI).symm] /-- Caratheodory theorem. If `m` is a metric outer measure, then every Borel measurable set `t` is Caratheodory measurable: for any (not necessarily measurable) set `s` we have `μ (s ∩ t) + μ (s \ t) = μ s`. -/ theorem borel_le_caratheodory (hm : IsMetric μ) : borel X ≤ μ.caratheodory := by rw [borel_eq_generateFrom_isClosed] refine MeasurableSpace.generateFrom_le fun t ht => μ.isCaratheodory_iff_le.2 fun s => ?_ set S : ℕ → Set X := fun n => {x ∈ s | (↑n)⁻¹ ≤ infEdist x t} have Ssep (n) : Metric.AreSeparated (S n) t := ⟨n⁻¹, ENNReal.inv_ne_zero.2 (ENNReal.natCast_ne_top _), fun x hx y hy ↦ hx.2.trans <| infEdist_le_edist_of_mem hy⟩ have Ssep' : ∀ n, Metric.AreSeparated (S n) (s ∩ t) := fun n => (Ssep n).mono Subset.rfl inter_subset_right have S_sub : ∀ n, S n ⊆ s \ t := fun n => subset_inter inter_subset_left (Ssep n).subset_compl_right have hSs : ∀ n, μ (s ∩ t) + μ (S n) ≤ μ s := fun n => calc μ (s ∩ t) + μ (S n) = μ (s ∩ t ∪ S n) := Eq.symm <| hm _ _ <| (Ssep' n).symm _ ≤ μ (s ∩ t ∪ s \ t) := μ.mono <| union_subset_union_right _ <| S_sub n _ = μ s := by rw [inter_union_diff] have iUnion_S : ⋃ n, S n = s \ t := by refine Subset.antisymm (iUnion_subset S_sub) ?_ rintro x ⟨hxs, hxt⟩ rw [mem_iff_infEdist_zero_of_closed ht] at hxt rcases ENNReal.exists_inv_nat_lt hxt with ⟨n, hn⟩ exact mem_iUnion.2 ⟨n, hxs, hn.le⟩ /- Now we have `∀ n, μ (s ∩ t) + μ (S n) ≤ μ s` and we need to prove `μ (s ∩ t) + μ (⋃ n, S n) ≤ μ s`. We can't pass to the limit because `μ` is only an outer measure. -/ by_cases htop : μ (s \ t) = ∞ · rw [htop, add_top, ← htop] exact μ.mono diff_subset suffices μ (⋃ n, S n) ≤ ⨆ n, μ (S n) by calc μ (s ∩ t) + μ (s \ t) = μ (s ∩ t) + μ (⋃ n, S n) := by rw [iUnion_S] _ ≤ μ (s ∩ t) + ⨆ n, μ (S n) := by gcongr _ = ⨆ n, μ (s ∩ t) + μ (S n) := ENNReal.add_iSup .. _ ≤ μ s := iSup_le hSs /- It suffices to show that `∑' k, μ (S (k + 1) \ S k) ≠ ∞`. Indeed, if we have this, then for all `N` we have `μ (⋃ n, S n) ≤ μ (S N) + ∑' k, m (S (N + k + 1) \ S (N + k))` and the second term tends to zero, see `OuterMeasure.iUnion_nat_of_monotone_of_tsum_ne_top` for details. -/ have : ∀ n, S n ⊆ S (n + 1) := fun n x hx => ⟨hx.1, le_trans (ENNReal.inv_le_inv.2 <| Nat.cast_le.2 n.le_succ) hx.2⟩ refine (μ.iUnion_nat_of_monotone_of_tsum_ne_top this ?_).le; clear this /- While the sets `S (k + 1) \ S k` are not pairwise metric separated, the sets in each subsequence `S (2 * k + 1) \ S (2 * k)` and `S (2 * k + 2) \ S (2 * k)` are metric separated, so `m` is additive on each of those sequences. -/ rw [← tsum_even_add_odd ENNReal.summable ENNReal.summable, ENNReal.add_ne_top] suffices ∀ a, (∑' k : ℕ, μ (S (2 * k + 1 + a) \ S (2 * k + a))) ≠ ∞ from ⟨by simpa using this 0, by simpa using this 1⟩ refine fun r => ne_top_of_le_ne_top htop ?_ rw [← iUnion_S, ENNReal.tsum_eq_iSup_nat, iSup_le_iff] intro n rw [← hm.finset_iUnion_of_pairwise_separated] · exact μ.mono (iUnion_subset fun i => iUnion_subset fun _ x hx => mem_iUnion.2 ⟨_, hx.1⟩) suffices ∀ i j, i < j → Metric.AreSeparated (S (2 * i + 1 + r)) (s \ S (2 * j + r)) from fun i _ j _ hij => hij.lt_or_lt.elim (fun h => (this i j h).mono inter_subset_left fun x hx => by exact ⟨hx.1.1, hx.2⟩) fun h => (this j i h).symm.mono (fun x hx => by exact ⟨hx.1.1, hx.2⟩) inter_subset_left intro i j hj have A : ((↑(2 * j + r))⁻¹ : ℝ≥0∞) < (↑(2 * i + 1 + r))⁻¹ := by rw [ENNReal.inv_lt_inv, Nat.cast_lt]; omega refine ⟨(↑(2 * i + 1 + r))⁻¹ - (↑(2 * j + r))⁻¹, by simpa [tsub_eq_zero_iff_le] using A, fun x hx y hy => ?_⟩ have : infEdist y t < (↑(2 * j + r))⁻¹ := not_le.1 fun hle => hy.2 ⟨hy.1, hle⟩ rcases infEdist_lt_iff.mp this with ⟨z, hzt, hyz⟩ have hxz : (↑(2 * i + 1 + r))⁻¹ ≤ edist x z := le_infEdist.1 hx.2 _ hzt apply ENNReal.le_of_add_le_add_right hyz.ne_top refine le_trans ?_ (edist_triangle _ _ _) refine (add_le_add le_rfl hyz.le).trans (Eq.trans_le ?_ hxz) rw [tsub_add_cancel_of_le A.le] theorem le_caratheodory [MeasurableSpace X] [BorelSpace X] (hm : IsMetric μ) : ‹MeasurableSpace X› ≤ μ.caratheodory := by rw [BorelSpace.measurable_eq (α := X)] exact hm.borel_le_caratheodory end IsMetric /-! ### Constructors of metric outer measures In this section we provide constructors `MeasureTheory.OuterMeasure.mkMetric'` and `MeasureTheory.OuterMeasure.mkMetric` and prove that these outer measures are metric outer measures. We also prove basic lemmas about `map`/`comap` of these measures. -/ /-- Auxiliary definition for `OuterMeasure.mkMetric'`: given a function on sets `m : Set X → ℝ≥0∞`, returns the maximal outer measure `μ` such that `μ s ≤ m s` for any set `s` of diameter at most `r`. -/ def mkMetric'.pre (m : Set X → ℝ≥0∞) (r : ℝ≥0∞) : OuterMeasure X := boundedBy <| extend fun s (_ : diam s ≤ r) => m s /-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `mkMetric'.pre m r` over `r > 0`. Equivalently, it is the limit of `mkMetric'.pre m r` as `r` tends to zero from the right. -/ def mkMetric' (m : Set X → ℝ≥0∞) : OuterMeasure X := ⨆ r > 0, mkMetric'.pre m r /-- Given a function `m : ℝ≥0∞ → ℝ≥0∞` and `r > 0`, let `μ r` be the maximal outer measure such that `μ s ≤ m (EMetric.diam s)` whenever `EMetric.diam s < r`. Then `mkMetric m = ⨆ r > 0, μ r`. -/ def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X := mkMetric' fun s => m (diam s) namespace mkMetric' variable {m : Set X → ℝ≥0∞} {r : ℝ≥0∞} {μ : OuterMeasure X} {s : Set X} theorem le_pre : μ ≤ pre m r ↔ ∀ s : Set X, diam s ≤ r → μ s ≤ m s := by simp only [pre, le_boundedBy, extend, le_iInf_iff] theorem pre_le (hs : diam s ≤ r) : pre m r s ≤ m s := (boundedBy_le _).trans <| iInf_le _ hs theorem mono_pre (m : Set X → ℝ≥0∞) {r r' : ℝ≥0∞} (h : r ≤ r') : pre m r' ≤ pre m r := le_pre.2 fun _ hs => pre_le (hs.trans h) theorem mono_pre_nat (m : Set X → ℝ≥0∞) : Monotone fun k : ℕ => pre m k⁻¹ := fun k l h => le_pre.2 fun _ hs => pre_le (hs.trans <| by simpa) theorem tendsto_pre (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun r => pre m r s) (𝓝[>] 0) (𝓝 <| mkMetric' m s) := by rw [← map_coe_Ioi_atBot, tendsto_map'_iff] simp only [mkMetric', OuterMeasure.iSup_apply, iSup_subtype'] exact tendsto_atBot_iSup fun r r' hr => mono_pre _ hr _ theorem tendsto_pre_nat (m : Set X → ℝ≥0∞) (s : Set X) : Tendsto (fun n : ℕ => pre m n⁻¹ s) atTop (𝓝 <| mkMetric' m s) := by refine (tendsto_pre m s).comp (tendsto_inf.2 ⟨ENNReal.tendsto_inv_nat_nhds_zero, ?_⟩) refine tendsto_principal.2 (Eventually.of_forall fun n => ?_) simp theorem eq_iSup_nat (m : Set X → ℝ≥0∞) : mkMetric' m = ⨆ n : ℕ, mkMetric'.pre m n⁻¹ := by ext1 s rw [iSup_apply] refine tendsto_nhds_unique (mkMetric'.tendsto_pre_nat m s) (tendsto_atTop_iSup fun k l hkl => mkMetric'.mono_pre_nat m hkl s) /-- `MeasureTheory.OuterMeasure.mkMetric'.pre m r` is a trimmed measure provided that `m (closure s) = m s` for any set `s`. -/ theorem trim_pre [MeasurableSpace X] [OpensMeasurableSpace X] (m : Set X → ℝ≥0∞) (hcl : ∀ s, m (closure s) = m s) (r : ℝ≥0∞) : (pre m r).trim = pre m r := by refine le_antisymm (le_pre.2 fun s hs => ?_) (le_trim _) rw [trim_eq_iInf] refine iInf_le_of_le (closure s) <| iInf_le_of_le subset_closure <| iInf_le_of_le measurableSet_closure ((pre_le ?_).trans_eq (hcl _)) rwa [diam_closure] end mkMetric' /-- An outer measure constructed using `OuterMeasure.mkMetric'` is a metric outer measure. -/ theorem mkMetric'_isMetric (m : Set X → ℝ≥0∞) : (mkMetric' m).IsMetric := by rintro s t ⟨r, r0, hr⟩ refine tendsto_nhds_unique_of_eventuallyEq (mkMetric'.tendsto_pre _ _) ((mkMetric'.tendsto_pre _ _).add (mkMetric'.tendsto_pre _ _)) ?_ rw [← pos_iff_ne_zero] at r0 filter_upwards [Ioo_mem_nhdsGT r0] rintro ε ⟨_, εr⟩ refine boundedBy_union_of_top_of_nonempty_inter ?_ rintro u ⟨x, hxs, hxu⟩ ⟨y, hyt, hyu⟩ have : ε < diam u := εr.trans_le ((hr x hxs y hyt).trans <| edist_le_diam_of_mem hxu hyu) exact iInf_eq_top.2 fun h => (this.not_le h).elim /-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/ theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0) (hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : OuterMeasure X) ≤ c • mkMetric m₂ := by classical rcases (mem_nhdsGE_iff_exists_Ico_subset' zero_lt_one).1 hle with ⟨r, hr0, hr⟩ refine fun s => le_of_tendsto_of_tendsto (mkMetric'.tendsto_pre _ s) (ENNReal.Tendsto.const_mul (mkMetric'.tendsto_pre _ s) (Or.inr hc)) (mem_of_superset (Ioo_mem_nhdsGT hr0) fun r' hr' => ?_) simp only [mem_setOf_eq, mkMetric'.pre, RingHom.id_apply] rw [← smul_eq_mul, ← smul_apply, smul_boundedBy hc] refine le_boundedBy.2 (fun t => (boundedBy_le _).trans ?_) _ simp only [smul_eq_mul, Pi.smul_apply, extend, iInf_eq_if] split_ifs with ht · apply hr exact ⟨zero_le _, ht.trans_lt hr'.2⟩ · simp [h0] @[simp] theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : OuterMeasure X) = ⊤ := by simp_rw [mkMetric, mkMetric', mkMetric'.pre, extend_top, boundedBy_top, eq_top_iff] rw [le_iSup_iff] intro b hb simpa using hb ⊤ /-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/ theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) : (mkMetric m₁ : OuterMeasure X) ≤ mkMetric m₂ := by convert @mkMetric_mono_smul X _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] theorem isometry_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : comap f (mkMetric m) = mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, comap_iSup] refine surjective_id.iSup_congr id fun ε => surjective_id.iSup_congr id fun hε => ?_ rw [comap_boundedBy _ (H.imp _ id)] · congr with s : 1 apply extend_congr · simp [hf.ediam_image] · intros; simp [hf.injective.subsingleton_image_iff, hf.ediam_image] · intro h_mono s t hst simp only [extend, le_iInf_iff] intro ht apply le_trans _ (h_mono (diam_mono hst)) simp only [(diam_mono hst).trans ht, le_refl, ciInf_pos] theorem mkMetric_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0∞} (hc : c ≠ ∞) (hc' : c ≠ 0) : (mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by simp only [mkMetric, mkMetric', mkMetric'.pre, inducedOuterMeasure, ENNReal.smul_iSup] simp_rw [smul_iSup, smul_boundedBy hc, smul_extend _ hc', Pi.smul_apply] theorem mkMetric_nnreal_smul (m : ℝ≥0∞ → ℝ≥0∞) {c : ℝ≥0} (hc : c ≠ 0) : (mkMetric (c • m) : OuterMeasure X) = c • mkMetric m := by rw [ENNReal.smul_def, ENNReal.smul_def, mkMetric_smul m ENNReal.coe_ne_top (ENNReal.coe_ne_zero.mpr hc)] theorem isometry_map_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) {f : X → Y} (hf : Isometry f) (H : Monotone m ∨ Surjective f) : map f (mkMetric m) = restrict (range f) (mkMetric m) := by rw [← isometry_comap_mkMetric _ hf H, map_comap] theorem isometryEquiv_comap_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (f : X ≃ᵢ Y) : comap f (mkMetric m) = mkMetric m := isometry_comap_mkMetric _ f.isometry (Or.inr f.surjective) theorem isometryEquiv_map_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (f : X ≃ᵢ Y) : map f (mkMetric m) = mkMetric m := by rw [← isometryEquiv_comap_mkMetric _ f, map_comap_of_surjective f.surjective] theorem trim_mkMetric [MeasurableSpace X] [BorelSpace X] (m : ℝ≥0∞ → ℝ≥0∞) : (mkMetric m : OuterMeasure X).trim = mkMetric m := by simp only [mkMetric, mkMetric'.eq_iSup_nat, trim_iSup] congr 1 with n : 1 refine mkMetric'.trim_pre _ (fun s => ?_) _ simp theorem le_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (μ : OuterMeasure X) (r : ℝ≥0∞) (h0 : 0 < r) (hr : ∀ s, diam s ≤ r → μ s ≤ m (diam s)) : μ ≤ mkMetric m := le_iSup₂_of_le r h0 <| mkMetric'.le_pre.2 fun _ hs => hr _ hs end OuterMeasure /-! ### Metric measures In this section we use `MeasureTheory.OuterMeasure.toMeasure` and theorems about `MeasureTheory.OuterMeasure.mkMetric'`/`MeasureTheory.OuterMeasure.mkMetric` to define `MeasureTheory.Measure.mkMetric'`/`MeasureTheory.Measure.mkMetric`. We also restate some lemmas about metric outer measures for metric measures. -/ namespace Measure variable [MeasurableSpace X] [BorelSpace X] /-- Given a function `m : Set X → ℝ≥0∞`, `mkMetric' m` is the supremum of `μ r` over `r > 0`, where `μ r` is the maximal outer measure `μ` such that `μ s ≤ m s` for all `s`. While each `μ r` is an *outer* measure, the supremum is a measure. -/ def mkMetric' (m : Set X → ℝ≥0∞) : Measure X := (OuterMeasure.mkMetric' m).toMeasure (OuterMeasure.mkMetric'_isMetric _).le_caratheodory /-- Given a function `m : ℝ≥0∞ → ℝ≥0∞`, `mkMetric m` is the supremum of `μ r` over `r > 0`, where `μ r` is the maximal outer measure `μ` such that `μ s ≤ m s` for all sets `s` that contain at least two points. While each `mkMetric'.pre` is an *outer* measure, the supremum is a measure. -/ def mkMetric (m : ℝ≥0∞ → ℝ≥0∞) : Measure X := (OuterMeasure.mkMetric m).toMeasure (OuterMeasure.mkMetric'_isMetric _).le_caratheodory @[simp] theorem mkMetric'_toOuterMeasure (m : Set X → ℝ≥0∞) : (mkMetric' m).toOuterMeasure = (OuterMeasure.mkMetric' m).trim := rfl @[simp] theorem mkMetric_toOuterMeasure (m : ℝ≥0∞ → ℝ≥0∞) : (mkMetric m : Measure X).toOuterMeasure = OuterMeasure.mkMetric m := OuterMeasure.trim_mkMetric m end Measure theorem OuterMeasure.coe_mkMetric [MeasurableSpace X] [BorelSpace X] (m : ℝ≥0∞ → ℝ≥0∞) : ⇑(OuterMeasure.mkMetric m : OuterMeasure X) = Measure.mkMetric m := by rw [← Measure.mkMetric_toOuterMeasure, Measure.coe_toOuterMeasure] namespace Measure variable [MeasurableSpace X] [BorelSpace X] /-- If `c ∉ {0, ∞}` and `m₁ d ≤ c * m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ c • mkMetric m₂ hm₂`. -/ theorem mkMetric_mono_smul {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (h0 : c ≠ 0) (hle : m₁ ≤ᶠ[𝓝[≥] 0] c • m₂) : (mkMetric m₁ : Measure X) ≤ c • mkMetric m₂ := fun s ↦ by rw [← OuterMeasure.coe_mkMetric, coe_smul, ← OuterMeasure.coe_mkMetric] exact OuterMeasure.mkMetric_mono_smul hc h0 hle s @[simp] theorem mkMetric_top : (mkMetric (fun _ => ∞ : ℝ≥0∞ → ℝ≥0∞) : Measure X) = ⊤ := by apply toOuterMeasure_injective rw [mkMetric_toOuterMeasure, OuterMeasure.mkMetric_top, toOuterMeasure_top] /-- If `m₁ d ≤ m₂ d` for `d < ε` for some `ε > 0` (we use `≤ᶠ[𝓝[≥] 0]` to state this), then `mkMetric m₁ hm₁ ≤ mkMetric m₂ hm₂`. -/ theorem mkMetric_mono {m₁ m₂ : ℝ≥0∞ → ℝ≥0∞} (hle : m₁ ≤ᶠ[𝓝[≥] 0] m₂) : (mkMetric m₁ : Measure X) ≤ mkMetric m₂ := by convert @mkMetric_mono_smul X _ _ _ _ m₂ _ ENNReal.one_ne_top one_ne_zero _ <;> simp [*] /-- A formula for `MeasureTheory.Measure.mkMetric`. -/ theorem mkMetric_apply (m : ℝ≥0∞ → ℝ≥0∞) (s : Set X) : mkMetric m s = ⨆ (r : ℝ≥0∞) (_ : 0 < r), ⨅ (t : ℕ → Set X) (_ : s ⊆ iUnion t) (_ : ∀ n, diam (t n) ≤ r), ∑' n, ⨆ _ : (t n).Nonempty, m (diam (t n)) := by classical -- We mostly unfold the definitions but we need to switch the order of `∑'` and `⨅` simp only [← OuterMeasure.coe_mkMetric, OuterMeasure.mkMetric, OuterMeasure.mkMetric', OuterMeasure.iSup_apply, OuterMeasure.mkMetric'.pre, OuterMeasure.boundedBy_apply, extend] refine surjective_id.iSup_congr id fun r => iSup_congr_Prop Iff.rfl fun _ => surjective_id.iInf_congr _ fun t => iInf_congr_Prop Iff.rfl fun ht => ?_ dsimp by_cases htr : ∀ n, diam (t n) ≤ r · rw [iInf_eq_if, if_pos htr] congr 1 with n : 1 simp only [iInf_eq_if, htr n, id, if_true, iSup_and'] · rw [iInf_eq_if, if_neg htr] push_neg at htr; rcases htr with ⟨n, hn⟩ refine ENNReal.tsum_eq_top_of_eq_top ⟨n, ?_⟩ rw [iSup_eq_if, if_pos, iInf_eq_if, if_neg] · exact hn.not_le rcases diam_pos_iff.1 ((zero_le r).trans_lt hn) with ⟨x, hx, -⟩ exact ⟨x, hx⟩ theorem le_mkMetric (m : ℝ≥0∞ → ℝ≥0∞) (μ : Measure X) (ε : ℝ≥0∞) (h₀ : 0 < ε) (h : ∀ s : Set X, diam s ≤ ε → μ s ≤ m (diam s)) : μ ≤ mkMetric m := by rw [← toOuterMeasure_le, mkMetric_toOuterMeasure] exact OuterMeasure.le_mkMetric m μ.toOuterMeasure ε h₀ h /-- To bound the Hausdorff measure (or, more generally, for a measure defined using `MeasureTheory.Measure.mkMetric`) of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of countable types. -/ theorem mkMetric_le_liminf_tsum {β : Type*} {ι : β → Type*} [∀ n, Countable (ι n)] (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) (m : ℝ≥0∞ → ℝ≥0∞) : mkMetric m s ≤ liminf (fun n => ∑' i, m (diam (t n i))) l := by haveI : ∀ n, Encodable (ι n) := fun n => Encodable.ofCountable _ simp only [mkMetric_apply] refine iSup₂_le fun ε hε => ?_ refine le_of_forall_gt_imp_ge_of_dense fun c hc => ?_ rcases ((frequently_lt_of_liminf_lt (by isBoundedDefault) hc).and_eventually ((hr.eventually (gt_mem_nhds hε)).and (ht.and hst))).exists with ⟨n, hn, hrn, htn, hstn⟩ set u : ℕ → Set X := fun j => ⋃ b ∈ decode₂ (ι n) j, t n b refine iInf₂_le_of_le u (by rwa [iUnion_decode₂]) ?_ refine iInf_le_of_le (fun j => ?_) ?_ · rw [EMetric.diam_iUnion_mem_option] exact iSup₂_le fun _ _ => (htn _).trans hrn.le · calc (∑' j : ℕ, ⨆ _ : (u j).Nonempty, m (diam (u j))) = _ := tsum_iUnion_decode₂ (fun t : Set X => ⨆ _ : t.Nonempty, m (diam t)) (by simp) _ _ ≤ ∑' i : ι n, m (diam (t n i)) := ENNReal.tsum_le_tsum fun b => iSup_le fun _ => le_rfl _ ≤ c := hn.le /-- To bound the Hausdorff measure (or, more generally, for a measure defined using `MeasureTheory.Measure.mkMetric`) of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of finite types. -/ theorem mkMetric_le_liminf_sum {β : Type*} {ι : β → Type*} [hι : ∀ n, Fintype (ι n)] (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) (m : ℝ≥0∞ → ℝ≥0∞) : mkMetric m s ≤ liminf (fun n => ∑ i, m (diam (t n i))) l := by simpa only [tsum_fintype] using mkMetric_le_liminf_tsum s r hr t ht hst m /-! ### Hausdorff measure and Hausdorff dimension -/ /-- Hausdorff measure on an (e)metric space. -/ def hausdorffMeasure (d : ℝ) : Measure X := mkMetric fun r => r ^ d @[inherit_doc] scoped[MeasureTheory] notation "μH[" d "]" => MeasureTheory.Measure.hausdorffMeasure d theorem le_hausdorffMeasure (d : ℝ) (μ : Measure X) (ε : ℝ≥0∞) (h₀ : 0 < ε) (h : ∀ s : Set X, diam s ≤ ε → μ s ≤ diam s ^ d) : μ ≤ μH[d] := le_mkMetric _ μ ε h₀ h /-- A formula for `μH[d] s`. -/ theorem hausdorffMeasure_apply (d : ℝ) (s : Set X) : μH[d] s = ⨆ (r : ℝ≥0∞) (_ : 0 < r), ⨅ (t : ℕ → Set X) (_ : s ⊆ ⋃ n, t n) (_ : ∀ n, diam (t n) ≤ r), ∑' n, ⨆ _ : (t n).Nonempty, diam (t n) ^ d := mkMetric_apply _ _ /-- To bound the Hausdorff measure of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of countable types. -/ theorem hausdorffMeasure_le_liminf_tsum {β : Type*} {ι : β → Type*} [∀ n, Countable (ι n)] (d : ℝ) (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) : μH[d] s ≤ liminf (fun n => ∑' i, diam (t n i) ^ d) l := mkMetric_le_liminf_tsum s r hr t ht hst _ /-- To bound the Hausdorff measure of a set, one may use coverings with maximum diameter tending to `0`, indexed by any sequence of finite types. -/ theorem hausdorffMeasure_le_liminf_sum {β : Type*} {ι : β → Type*} [∀ n, Fintype (ι n)] (d : ℝ) (s : Set X) {l : Filter β} (r : β → ℝ≥0∞) (hr : Tendsto r l (𝓝 0)) (t : ∀ n : β, ι n → Set X) (ht : ∀ᶠ n in l, ∀ i, diam (t n i) ≤ r n) (hst : ∀ᶠ n in l, s ⊆ ⋃ i, t n i) : μH[d] s ≤ liminf (fun n => ∑ i, diam (t n i) ^ d) l := mkMetric_le_liminf_sum s r hr t ht hst _ /-- If `d₁ < d₂`, then for any set `s` we have either `μH[d₂] s = 0`, or `μH[d₁] s = ∞`. -/ theorem hausdorffMeasure_zero_or_top {d₁ d₂ : ℝ} (h : d₁ < d₂) (s : Set X) : μH[d₂] s = 0 ∨ μH[d₁] s = ∞ := by by_contra! H suffices ∀ c : ℝ≥0, c ≠ 0 → μH[d₂] s ≤ c * μH[d₁] s by rcases ENNReal.exists_nnreal_pos_mul_lt H.2 H.1 with ⟨c, hc0, hc⟩ exact hc.not_le (this c (pos_iff_ne_zero.1 hc0)) intro c hc refine le_iff'.1 (mkMetric_mono_smul ENNReal.coe_ne_top (mod_cast hc) ?_) s have : 0 < ((c : ℝ≥0∞) ^ (d₂ - d₁)⁻¹) := by rw [← ENNReal.coe_rpow_of_ne_zero hc, pos_iff_ne_zero, Ne, ENNReal.coe_eq_zero, NNReal.rpow_eq_zero_iff] exact mt And.left hc filter_upwards [Ico_mem_nhdsGE this] rintro r ⟨hr₀, hrc⟩ lift r to ℝ≥0 using ne_top_of_lt hrc rw [Pi.smul_apply, smul_eq_mul, ← ENNReal.div_le_iff_le_mul (Or.inr ENNReal.coe_ne_top) (Or.inr <| mt ENNReal.coe_eq_zero.1 hc)] rcases eq_or_ne r 0 with (rfl | hr₀) · rcases lt_or_le 0 d₂ with (h₂ | h₂) · simp only [h₂, ENNReal.zero_rpow_of_pos, zero_le, ENNReal.zero_div, ENNReal.coe_zero] · simp only [h.trans_le h₂, ENNReal.div_top, zero_le, ENNReal.zero_rpow_of_neg, ENNReal.coe_zero] · have : (r : ℝ≥0∞) ≠ 0 := by simpa only [ENNReal.coe_eq_zero, Ne] using hr₀ rw [← ENNReal.rpow_sub _ _ this ENNReal.coe_ne_top] refine (ENNReal.rpow_lt_rpow hrc (sub_pos.2 h)).le.trans ?_ rw [← ENNReal.rpow_mul, inv_mul_cancel₀ (sub_pos.2 h).ne', ENNReal.rpow_one] /-- Hausdorff measure `μH[d] s` is monotone in `d`. -/ theorem hausdorffMeasure_mono {d₁ d₂ : ℝ} (h : d₁ ≤ d₂) (s : Set X) : μH[d₂] s ≤ μH[d₁] s := by rcases h.eq_or_lt with (rfl | h); · exact le_rfl rcases hausdorffMeasure_zero_or_top h s with hs | hs · rw [hs]; exact zero_le _ · rw [hs]; exact le_top variable (X) in theorem noAtoms_hausdorff {d : ℝ} (hd : 0 < d) : NoAtoms (hausdorffMeasure d : Measure X) := by refine ⟨fun x => ?_⟩ rw [← nonpos_iff_eq_zero, hausdorffMeasure_apply] refine iSup₂_le fun ε _ => iInf₂_le_of_le (fun _ => {x}) ?_ <| iInf_le_of_le (fun _ => ?_) ?_ · exact subset_iUnion (fun _ => {x} : ℕ → Set X) 0 · simp only [EMetric.diam_singleton, zero_le] · simp [hd] @[simp] theorem hausdorffMeasure_zero_singleton (x : X) : μH[0] ({x} : Set X) = 1 := by apply le_antisymm · let r : ℕ → ℝ≥0∞ := fun _ => 0 let t : ℕ → Unit → Set X := fun _ _ => {x} have ht : ∀ᶠ n in atTop, ∀ i, diam (t n i) ≤ r n := by simp only [t, r, imp_true_iff, eq_self_iff_true, diam_singleton, eventually_atTop, nonpos_iff_eq_zero, exists_const] simpa [t, liminf_const] using hausdorffMeasure_le_liminf_sum 0 {x} r tendsto_const_nhds t ht · rw [hausdorffMeasure_apply] suffices (1 : ℝ≥0∞) ≤ ⨅ (t : ℕ → Set X) (_ : {x} ⊆ ⋃ n, t n) (_ : ∀ n, diam (t n) ≤ 1), ∑' n, ⨆ _ : (t n).Nonempty, diam (t n) ^ (0 : ℝ) by apply le_trans this _ convert le_iSup₂ (α := ℝ≥0∞) (1 : ℝ≥0∞) zero_lt_one rfl simp only [ENNReal.rpow_zero, le_iInf_iff] intro t hst _ rcases mem_iUnion.1 (hst (mem_singleton x)) with ⟨m, hm⟩ have A : (t m).Nonempty := ⟨x, hm⟩ calc (1 : ℝ≥0∞) = ⨆ h : (t m).Nonempty, 1 := by simp only [A, ciSup_pos] _ ≤ ∑' n, ⨆ h : (t n).Nonempty, 1 := ENNReal.le_tsum _ theorem one_le_hausdorffMeasure_zero_of_nonempty {s : Set X} (h : s.Nonempty) : 1 ≤ μH[0] s := by rcases h with ⟨x, hx⟩ calc (1 : ℝ≥0∞) = μH[0] ({x} : Set X) := (hausdorffMeasure_zero_singleton x).symm _ ≤ μH[0] s := measure_mono (singleton_subset_iff.2 hx) theorem hausdorffMeasure_le_one_of_subsingleton {s : Set X} (hs : s.Subsingleton) {d : ℝ} (hd : 0 ≤ d) : μH[d] s ≤ 1 := by rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) · simp only [measure_empty, zero_le] · rw [(subsingleton_iff_singleton hx).1 hs] rcases eq_or_lt_of_le hd with (rfl | dpos) · simp only [le_refl, hausdorffMeasure_zero_singleton] · haveI := noAtoms_hausdorff X dpos simp only [zero_le, measure_singleton] end Measure end MeasureTheory /-! ### Hausdorff measure, Hausdorff dimension, and Hölder or Lipschitz continuous maps -/ open scoped MeasureTheory open MeasureTheory MeasureTheory.Measure variable [MeasurableSpace X] [BorelSpace X] [MeasurableSpace Y] [BorelSpace Y] namespace HolderOnWith variable {C r : ℝ≥0} {f : X → Y} {s : Set X} /-- If `f : X → Y` is Hölder continuous on `s` with a positive exponent `r`, then `μH[d] (f '' s) ≤ C ^ d * μH[r * d] s`. -/ theorem hausdorffMeasure_image_le (h : HolderOnWith C r f s) (hr : 0 < r) {d : ℝ} (hd : 0 ≤ d) : μH[d] (f '' s) ≤ (C : ℝ≥0∞) ^ d * μH[r * d] s := by -- We start with the trivial case `C = 0` rcases (zero_le C).eq_or_lt with (rfl | hC0) · rcases eq_empty_or_nonempty s with (rfl | ⟨x, hx⟩) · simp only [measure_empty, nonpos_iff_eq_zero, mul_zero, image_empty] have : f '' s = {f x} := have : (f '' s).Subsingleton := by simpa [diam_eq_zero_iff] using h.ediam_image_le (subsingleton_iff_singleton (mem_image_of_mem f hx)).1 this rw [this] rcases eq_or_lt_of_le hd with (rfl | h'd) · simp only [ENNReal.rpow_zero, one_mul, mul_zero] rw [hausdorffMeasure_zero_singleton] exact one_le_hausdorffMeasure_zero_of_nonempty ⟨x, hx⟩ · haveI := noAtoms_hausdorff Y h'd simp only [zero_le, measure_singleton] -- Now assume `C ≠ 0` · have hCd0 : (C : ℝ≥0∞) ^ d ≠ 0 := by simp [hC0.ne'] have hCd : (C : ℝ≥0∞) ^ d ≠ ∞ := by simp [hd] simp only [hausdorffMeasure_apply, ENNReal.mul_iSup, ENNReal.mul_iInf_of_ne hCd0 hCd, ← ENNReal.tsum_mul_left] refine iSup_le fun R => iSup_le fun hR => ?_ have : Tendsto (fun d : ℝ≥0∞ => (C : ℝ≥0∞) * d ^ (r : ℝ)) (𝓝 0) (𝓝 0) := ENNReal.tendsto_const_mul_rpow_nhds_zero_of_pos ENNReal.coe_ne_top hr rcases ENNReal.nhds_zero_basis_Iic.eventually_iff.1 (this.eventually (gt_mem_nhds hR)) with ⟨δ, δ0, H⟩ refine le_iSup₂_of_le δ δ0 <| iInf₂_mono' fun t hst ↦ ⟨fun n => f '' (t n ∩ s), ?_, iInf_mono' fun htδ ↦ ⟨fun n => (h.ediam_image_inter_le (t n)).trans (H (htδ n)).le, ?_⟩⟩ · rw [← image_iUnion, ← iUnion_inter] exact image_subset _ (subset_inter hst Subset.rfl) · refine ENNReal.tsum_le_tsum fun n => ?_ simp only [iSup_le_iff, image_nonempty] intro hft simp only [Nonempty.mono ((t n).inter_subset_left) hft, ciSup_pos] rw [ENNReal.rpow_mul, ← ENNReal.mul_rpow_of_nonneg _ _ hd] exact ENNReal.rpow_le_rpow (h.ediam_image_inter_le _) hd end HolderOnWith namespace LipschitzOnWith variable {K : ℝ≥0} {f : X → Y} {s : Set X} /-- If `f : X → Y` is `K`-Lipschitz on `s`, then `μH[d] (f '' s) ≤ K ^ d * μH[d] s`. -/ theorem hausdorffMeasure_image_le (h : LipschitzOnWith K f s) {d : ℝ} (hd : 0 ≤ d) : μH[d] (f '' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := by simpa only [NNReal.coe_one, one_mul] using h.holderOnWith.hausdorffMeasure_image_le zero_lt_one hd end LipschitzOnWith namespace LipschitzWith variable {K : ℝ≥0} {f : X → Y} /-- If `f` is a `K`-Lipschitz map, then it increases the Hausdorff `d`-measures of sets at most by the factor of `K ^ d`. -/ theorem hausdorffMeasure_image_le (h : LipschitzWith K f) {d : ℝ} (hd : 0 ≤ d) (s : Set X) : μH[d] (f '' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := h.lipschitzOnWith.hausdorffMeasure_image_le hd end LipschitzWith open scoped Pointwise theorem MeasureTheory.Measure.hausdorffMeasure_smul₀ {𝕜 E : Type*} [NormedAddCommGroup E] [NormedField 𝕜] [NormedSpace 𝕜 E] [MeasurableSpace E] [BorelSpace E] {d : ℝ} (hd : 0 ≤ d) {r : 𝕜} (hr : r ≠ 0) (s : Set E) : μH[d] (r • s) = ‖r‖₊ ^ d • μH[d] s := by have {r : 𝕜} (s : Set E) : μH[d] (r • s) ≤ ‖r‖₊ ^ d • μH[d] s := by simpa [ENNReal.coe_rpow_of_nonneg, hd] using (lipschitzWith_smul r).hausdorffMeasure_image_le hd s refine le_antisymm (this s) ?_ rw [← le_inv_smul_iff_of_pos] · dsimp rw [← NNReal.inv_rpow, ← nnnorm_inv] · refine Eq.trans_le ?_ (this (r • s)) rw [inv_smul_smul₀ hr] · simp [pos_iff_ne_zero, hr] /-! ### Antilipschitz maps do not decrease Hausdorff measures and dimension -/ namespace AntilipschitzWith variable {f : X → Y} {K : ℝ≥0} {d : ℝ} theorem hausdorffMeasure_preimage_le (hf : AntilipschitzWith K f) (hd : 0 ≤ d) (s : Set Y) : μH[d] (f ⁻¹' s) ≤ (K : ℝ≥0∞) ^ d * μH[d] s := by rcases eq_or_ne K 0 with (rfl | h0) · rcases eq_empty_or_nonempty (f ⁻¹' s) with (hs | ⟨x, hx⟩) · simp only [hs, measure_empty, zero_le] have : f ⁻¹' s = {x} := by haveI : Subsingleton X := hf.subsingleton have : (f ⁻¹' s).Subsingleton := subsingleton_univ.anti (subset_univ _) exact (subsingleton_iff_singleton hx).1 this rw [this] rcases eq_or_lt_of_le hd with (rfl | h'd) · simp only [ENNReal.rpow_zero, one_mul, mul_zero] rw [hausdorffMeasure_zero_singleton] exact one_le_hausdorffMeasure_zero_of_nonempty ⟨f x, hx⟩ · haveI := noAtoms_hausdorff X h'd simp only [zero_le, measure_singleton] have hKd0 : (K : ℝ≥0∞) ^ d ≠ 0 := by simp [h0] have hKd : (K : ℝ≥0∞) ^ d ≠ ∞ := by simp [hd] simp only [hausdorffMeasure_apply, ENNReal.mul_iSup, ENNReal.mul_iInf_of_ne hKd0 hKd, ← ENNReal.tsum_mul_left] refine iSup₂_le fun ε ε0 => ?_ refine le_iSup₂_of_le (ε / K) (by simp [ε0.ne']) ?_ refine le_iInf₂ fun t hst => le_iInf fun htε => ?_ replace hst : f ⁻¹' s ⊆ _ := preimage_mono hst; rw [preimage_iUnion] at hst refine iInf₂_le_of_le _ hst (iInf_le_of_le (fun n => ?_) ?_) · exact (hf.ediam_preimage_le _).trans (ENNReal.mul_le_of_le_div' <| htε n) · refine ENNReal.tsum_le_tsum fun n => iSup_le_iff.2 fun hft => ?_ simp only [nonempty_of_nonempty_preimage hft, ciSup_pos] rw [← ENNReal.mul_rpow_of_nonneg _ _ hd] exact ENNReal.rpow_le_rpow (hf.ediam_preimage_le _) hd theorem le_hausdorffMeasure_image (hf : AntilipschitzWith K f) (hd : 0 ≤ d) (s : Set X) : μH[d] s ≤ (K : ℝ≥0∞) ^ d * μH[d] (f '' s) := calc μH[d] s ≤ μH[d] (f ⁻¹' (f '' s)) := measure_mono (subset_preimage_image _ _) _ ≤ (K : ℝ≥0∞) ^ d * μH[d] (f '' s) := hf.hausdorffMeasure_preimage_le hd (f '' s) end AntilipschitzWith /-! ### Isometries preserve the Hausdorff measure and Hausdorff dimension -/ namespace Isometry variable {f : X → Y} {d : ℝ} theorem hausdorffMeasure_image (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) (s : Set X) : μH[d] (f '' s) = μH[d] s := by simp only [hausdorffMeasure, ← OuterMeasure.coe_mkMetric, ← OuterMeasure.comap_apply] rw [OuterMeasure.isometry_comap_mkMetric _ hf (hd.imp_left _)] exact ENNReal.monotone_rpow_of_nonneg theorem hausdorffMeasure_preimage (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) (s : Set Y) : μH[d] (f ⁻¹' s) = μH[d] (s ∩ range f) := by rw [← hf.hausdorffMeasure_image hd, image_preimage_eq_inter_range] theorem map_hausdorffMeasure (hf : Isometry f) (hd : 0 ≤ d ∨ Surjective f) : Measure.map f μH[d] = μH[d].restrict (range f) := by ext1 s hs rw [map_apply hf.continuous.measurable hs, Measure.restrict_apply hs, hf.hausdorffMeasure_preimage hd] end Isometry namespace IsometryEquiv @[simp] theorem hausdorffMeasure_image (e : X ≃ᵢ Y) (d : ℝ) (s : Set X) : μH[d] (e '' s) = μH[d] s := e.isometry.hausdorffMeasure_image (Or.inr e.surjective) s @[simp] theorem hausdorffMeasure_preimage (e : X ≃ᵢ Y) (d : ℝ) (s : Set Y) : μH[d] (e ⁻¹' s) = μH[d] s := by rw [← e.image_symm, e.symm.hausdorffMeasure_image] @[simp] theorem map_hausdorffMeasure (e : X ≃ᵢ Y) (d : ℝ) : Measure.map e μH[d] = μH[d] := by rw [e.isometry.map_hausdorffMeasure (Or.inr e.surjective), e.surjective.range_eq, restrict_univ] theorem measurePreserving_hausdorffMeasure (e : X ≃ᵢ Y) (d : ℝ) : MeasurePreserving e μH[d] μH[d] := ⟨e.continuous.measurable, map_hausdorffMeasure _ _⟩ end IsometryEquiv namespace MeasureTheory @[to_additive] theorem hausdorffMeasure_smul {α : Type*} [SMul α X] [IsIsometricSMul α X] {d : ℝ} (c : α) (h : 0 ≤ d ∨ Surjective (c • · : X → X)) (s : Set X) : μH[d] (c • s) = μH[d] s := (isometry_smul X c).hausdorffMeasure_image h _ @[to_additive] instance {d : ℝ} [Group X] [IsIsometricSMul X X] : IsMulLeftInvariant (μH[d] : Measure X) where map_mul_left_eq_self x := (IsometryEquiv.constSMul x).map_hausdorffMeasure _ @[to_additive] instance {d : ℝ} [Group X] [IsIsometricSMul Xᵐᵒᵖ X] : IsMulRightInvariant (μH[d] : Measure X) where map_mul_right_eq_self x := (IsometryEquiv.constSMul (MulOpposite.op x)).map_hausdorffMeasure _ /-! ### Hausdorff measure and Lebesgue measure -/ /-- In the space `ι → ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/ @[simp] theorem hausdorffMeasure_pi_real {ι : Type*} [Fintype ι] : (μH[Fintype.card ι] : Measure (ι → ℝ)) = volume := by classical -- it suffices to check that the two measures coincide on products of rational intervals refine (pi_eq_generateFrom (fun _ => Real.borel_eq_generateFrom_Ioo_rat.symm) (fun _ => Real.isPiSystem_Ioo_rat) (fun _ => Real.finiteSpanningSetsInIooRat _) ?_).symm simp only [mem_iUnion, mem_singleton_iff] -- fix such a product `s` of rational intervals, of the form `Π (a i, b i)`. intro s hs choose a b H using hs obtain rfl : s = fun i => Ioo (α := ℝ) (a i) (b i) := funext fun i => (H i).2 replace H := fun i => (H i).1 apply le_antisymm _ -- first check that `volume s ≤ μH s` · have Hle : volume ≤ (μH[Fintype.card ι] : Measure (ι → ℝ)) := by refine le_hausdorffMeasure _ _ ∞ ENNReal.coe_lt_top fun s _ => ?_ rw [ENNReal.rpow_natCast] exact Real.volume_pi_le_diam_pow s rw [← volume_pi_pi fun i => Ioo (a i : ℝ) (b i)] exact Measure.le_iff'.1 Hle _ /- For the other inequality `μH s ≤ volume s`, we use a covering of `s` by sets of small diameter `1/n`, namely cubes with left-most point of the form `a i + f i / n` with `f i` ranging between `0` and `⌈(b i - a i) * n⌉`. Their number is asymptotic to `n^d * Π (b i - a i)`. -/ have I : ∀ i, 0 ≤ (b i : ℝ) - a i := fun i => by simpa only [sub_nonneg, Rat.cast_le] using (H i).le let γ := fun n : ℕ => ∀ i : ι, Fin ⌈((b i : ℝ) - a i) * n⌉₊ let t : ∀ n : ℕ, γ n → Set (ι → ℝ) := fun n f => Set.pi univ fun i => Icc (a i + f i / n) (a i + (f i + 1) / n) have A : Tendsto (fun n : ℕ => 1 / (n : ℝ≥0∞)) atTop (𝓝 0) := by simp only [one_div, ENNReal.tendsto_inv_nat_nhds_zero] have B : ∀ᶠ n in atTop, ∀ i : γ n, diam (t n i) ≤ 1 / n := by refine eventually_atTop.2 ⟨1, fun n hn => ?_⟩ intro f refine diam_pi_le_of_le fun b => ?_ simp only [Real.ediam_Icc, add_div, ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr hn), le_refl, add_sub_add_left_eq_sub, add_sub_cancel_left, ENNReal.ofReal_one, ENNReal.ofReal_natCast] have C : ∀ᶠ n in atTop, (Set.pi univ fun i : ι => Ioo (a i : ℝ) (b i)) ⊆ ⋃ i : γ n, t n i := by refine eventually_atTop.2 ⟨1, fun n hn => ?_⟩ have npos : (0 : ℝ) < n := Nat.cast_pos.2 hn intro x hx simp only [mem_Ioo, mem_univ_pi] at hx simp only [t, mem_iUnion, mem_Ioo, mem_univ_pi] let f : γ n := fun i => ⟨⌊(x i - a i) * n⌋₊, by apply Nat.floor_lt_ceil_of_lt_of_pos · refine (mul_lt_mul_right npos).2 ?_ simp only [(hx i).right, sub_lt_sub_iff_right] · refine mul_pos ?_ npos simpa only [Rat.cast_lt, sub_pos] using H i⟩ refine ⟨f, fun i => ⟨?_, ?_⟩⟩ · calc (a i : ℝ) + ⌊(x i - a i) * n⌋₊ / n ≤ (a i : ℝ) + (x i - a i) * n / n := by gcongr exact Nat.floor_le (mul_nonneg (sub_nonneg.2 (hx i).1.le) npos.le) _ = x i := by field_simp [npos.ne'] · calc x i = (a i : ℝ) + (x i - a i) * n / n := by field_simp [npos.ne'] _ ≤ (a i : ℝ) + (⌊(x i - a i) * n⌋₊ + 1) / n := by gcongr exact (Nat.lt_floor_add_one _).le calc μH[Fintype.card ι] (Set.pi univ fun i : ι => Ioo (a i : ℝ) (b i)) ≤ liminf (fun n : ℕ => ∑ i : γ n, diam (t n i) ^ ((Fintype.card ι) : ℝ)) atTop := hausdorffMeasure_le_liminf_sum _ (Set.pi univ fun i => Ioo (a i : ℝ) (b i)) (fun n : ℕ => 1 / (n : ℝ≥0∞)) A t B C _ ≤ liminf (fun n : ℕ => ∑ i : γ n, (1 / (n : ℝ≥0∞)) ^ Fintype.card ι) atTop := by refine liminf_le_liminf ?_ ?_ · filter_upwards [B] with _ hn apply Finset.sum_le_sum fun i _ => _ simp only [ENNReal.rpow_natCast]
intros i _ exact pow_le_pow_left' (hn i) _ · isBoundedDefault _ = liminf (fun n : ℕ => ∏ i : ι, (⌈((b i : ℝ) - a i) * n⌉₊ : ℝ≥0∞) / n) atTop := by simp only [γ, Finset.card_univ, Nat.cast_prod, one_mul, Fintype.card_fin, Finset.sum_const, nsmul_eq_mul, Fintype.card_pi, div_eq_mul_inv, Finset.prod_mul_distrib, Finset.prod_const] _ = ∏ i : ι, volume (Ioo (a i : ℝ) (b i)) := by simp only [Real.volume_Ioo] apply Tendsto.liminf_eq refine ENNReal.tendsto_finset_prod_of_ne_top _ (fun i _ => ?_) fun i _ => ?_ · apply Tendsto.congr' _ ((ENNReal.continuous_ofReal.tendsto _).comp ((tendsto_nat_ceil_mul_div_atTop (I i)).comp tendsto_natCast_atTop_atTop)) apply eventually_atTop.2 ⟨1, fun n hn => _⟩ intros n hn simp only [ENNReal.ofReal_div_of_pos (Nat.cast_pos.mpr hn), comp_apply, ENNReal.ofReal_natCast] · simp only [ENNReal.ofReal_ne_top, Ne, not_false_iff] instance isAddHaarMeasure_hausdorffMeasure {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] : IsAddHaarMeasure (G := E) μH[finrank ℝ E] where lt_top_of_isCompact K hK := by set e : E ≃L[ℝ] Fin (finrank ℝ E) → ℝ := ContinuousLinearEquiv.ofFinrankEq (by simp) suffices μH[finrank ℝ E] (e '' K) < ⊤ by rw [← e.symm_image_image K] apply lt_of_le_of_lt <| e.symm.lipschitz.hausdorffMeasure_image_le (by simp) (e '' K) rw [ENNReal.rpow_natCast] exact ENNReal.mul_lt_top (ENNReal.pow_lt_top ENNReal.coe_lt_top) this conv_lhs => congr; congr; rw [← Fintype.card_fin (finrank ℝ E)] rw [hausdorffMeasure_pi_real] exact (hK.image e.continuous).measure_lt_top open_pos U hU hU' := by set e : E ≃L[ℝ] Fin (finrank ℝ E) → ℝ := ContinuousLinearEquiv.ofFinrankEq (by simp) suffices 0 < μH[finrank ℝ E] (e '' U) from (ENNReal.mul_pos_iff.mp (lt_of_lt_of_le this <| e.lipschitz.hausdorffMeasure_image_le (by simp) _)).2.ne' conv_rhs => congr; congr; rw [← Fintype.card_fin (finrank ℝ E)] rw [hausdorffMeasure_pi_real] apply (e.isOpenMap U hU).measure_pos (μ := volume) simpa variable (ι X) theorem hausdorffMeasure_measurePreserving_funUnique [Unique ι] [SecondCountableTopology X] (d : ℝ) : MeasurePreserving (MeasurableEquiv.funUnique ι X) μH[d] μH[d] := (IsometryEquiv.funUnique ι X).measurePreserving_hausdorffMeasure _ theorem hausdorffMeasure_measurePreserving_piFinTwo (α : Fin 2 → Type*) [∀ i, MeasurableSpace (α i)] [∀ i, EMetricSpace (α i)] [∀ i, BorelSpace (α i)] [∀ i, SecondCountableTopology (α i)] (d : ℝ) : MeasurePreserving (MeasurableEquiv.piFinTwo α) μH[d] μH[d] := (IsometryEquiv.piFinTwo α).measurePreserving_hausdorffMeasure _ /-- In the space `ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/ @[simp] theorem hausdorffMeasure_real : (μH[1] : Measure ℝ) = volume := by rw [← (volume_preserving_funUnique Unit ℝ).map_eq, ← (hausdorffMeasure_measurePreserving_funUnique Unit ℝ 1).map_eq, ← hausdorffMeasure_pi_real, Fintype.card_unit, Nat.cast_one] /-- In the space `ℝ × ℝ`, the Hausdorff measure coincides exactly with the Lebesgue measure. -/ @[simp] theorem hausdorffMeasure_prod_real : (μH[2] : Measure (ℝ × ℝ)) = volume := by rw [← (volume_preserving_piFinTwo fun _ => ℝ).map_eq, ← (hausdorffMeasure_measurePreserving_piFinTwo (fun _ => ℝ) _).map_eq, ← hausdorffMeasure_pi_real, Fintype.card_fin, Nat.cast_two] /-! ### Geometric results in affine spaces -/ section Geometric variable {𝕜 E P : Type*} theorem hausdorffMeasure_smul_right_image [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] (v : E) (s : Set ℝ) : μH[1] ((fun r => r • v) '' s) = ‖v‖₊ • μH[1] s := by obtain rfl | hv := eq_or_ne v 0 · haveI := noAtoms_hausdorff E one_pos obtain rfl | hs := s.eq_empty_or_nonempty · simp simp [hs] have hn : ‖v‖ ≠ 0 := norm_ne_zero_iff.mpr hv -- break lineMap into pieces suffices μH[1] ((‖v‖ • ·) '' (LinearMap.toSpanSingleton ℝ E (‖v‖⁻¹ • v) '' s)) = ‖v‖₊ • μH[1] s by
Mathlib/MeasureTheory/Measure/Hausdorff.lean
938
1,026
/- 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.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. Denoted `π`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : π / 2 ≤ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≤ π := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) theorem pi_le_four : π ≤ 4 := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≤ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi @[bound] theorem pi_nonneg : 0 ≤ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟨π, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : ℤ) : |cos (k * π)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≤ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : 0 ≤ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨fun h => ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨_, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hx₂ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 π) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] · refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num · exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : ∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) : ∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) @[simp] theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow₀ one_lt_two n.succ_ne_zero have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A have C : 0 < π / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : ℕ) : sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] · congr
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
672
674
/- Copyright (c) 2021 Rémy Degenne. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Zhouhang Zhou, Yury Kudryashov -/ import Mathlib.MeasureTheory.Function.L1Space.Integrable import Mathlib.MeasureTheory.Function.LpSpace.Indicator /-! # Functions integrable on a set and at a filter We define `IntegrableOn f s μ := Integrable f (μ.restrict s)` and prove theorems like `integrableOn_union : IntegrableOn f (s ∪ t) μ ↔ IntegrableOn f s μ ∧ IntegrableOn f t μ`. Next we define a predicate `IntegrableAtFilter (f : α → E) (l : Filter α) (μ : Measure α)` saying that `f` is integrable at some set `s ∈ l` and prove that a measurable function is integrable at `l` with respect to `μ` provided that `f` is bounded above at `l ⊓ ae μ` and `μ` is finite at `l`. -/ noncomputable section open Set Filter TopologicalSpace MeasureTheory Function open scoped Topology Interval Filter ENNReal MeasureTheory variable {α β ε E F : Type*} [MeasurableSpace α] [ENorm ε] [TopologicalSpace ε] section variable [TopologicalSpace β] {l l' : Filter α} {f g : α → β} {μ ν : Measure α} /-- A function `f` is strongly measurable at a filter `l` w.r.t. a measure `μ` if it is ae strongly measurable w.r.t. `μ.restrict s` for some `s ∈ l`. -/ def StronglyMeasurableAtFilter (f : α → β) (l : Filter α) (μ : Measure α := by volume_tac) := ∃ s ∈ l, AEStronglyMeasurable f (μ.restrict s) @[simp] theorem stronglyMeasurableAt_bot {f : α → β} : StronglyMeasurableAtFilter f ⊥ μ := ⟨∅, mem_bot, by simp⟩ protected theorem StronglyMeasurableAtFilter.eventually (h : StronglyMeasurableAtFilter f l μ) : ∀ᶠ s in l.smallSets, AEStronglyMeasurable f (μ.restrict s) := (eventually_smallSets' fun _ _ => AEStronglyMeasurable.mono_set).2 h protected theorem StronglyMeasurableAtFilter.filter_mono (h : StronglyMeasurableAtFilter f l μ) (h' : l' ≤ l) : StronglyMeasurableAtFilter f l' μ := let ⟨s, hsl, hs⟩ := h ⟨s, h' hsl, hs⟩ protected theorem MeasureTheory.AEStronglyMeasurable.stronglyMeasurableAtFilter (h : AEStronglyMeasurable f μ) : StronglyMeasurableAtFilter f l μ := ⟨univ, univ_mem, by rwa [Measure.restrict_univ]⟩ theorem AEStronglyMeasurable.stronglyMeasurableAtFilter_of_mem {s} (h : AEStronglyMeasurable f (μ.restrict s)) (hl : s ∈ l) : StronglyMeasurableAtFilter f l μ := ⟨s, hl, h⟩ @[deprecated (since := "2025-02-12")] alias AeStronglyMeasurable.stronglyMeasurableAtFilter_of_mem := AEStronglyMeasurable.stronglyMeasurableAtFilter_of_mem protected theorem MeasureTheory.StronglyMeasurable.stronglyMeasurableAtFilter (h : StronglyMeasurable f) : StronglyMeasurableAtFilter f l μ := h.aestronglyMeasurable.stronglyMeasurableAtFilter end namespace MeasureTheory section NormedAddCommGroup theorem hasFiniteIntegral_restrict_of_bounded [NormedAddCommGroup E] {f : α → E} {s : Set α} {μ : Measure α} {C} (hs : μ s < ∞) (hf : ∀ᵐ x ∂μ.restrict s, ‖f x‖ ≤ C) : HasFiniteIntegral f (μ.restrict s) := haveI : IsFiniteMeasure (μ.restrict s) := ⟨by rwa [Measure.restrict_apply_univ]⟩ hasFiniteIntegral_of_bounded hf variable [NormedAddCommGroup E] {f g : α → E} {s t : Set α} {μ ν : Measure α} /-- A function is `IntegrableOn` a set `s` if it is almost everywhere strongly measurable on `s` and if the integral of its pointwise norm over `s` is less than infinity. -/ def IntegrableOn (f : α → ε) (s : Set α) (μ : Measure α := by volume_tac) : Prop := Integrable f (μ.restrict s) theorem IntegrableOn.integrable (h : IntegrableOn f s μ) : Integrable f (μ.restrict s) := h @[simp] theorem integrableOn_empty : IntegrableOn f ∅ μ := by simp [IntegrableOn, integrable_zero_measure] @[simp] theorem integrableOn_univ : IntegrableOn f univ μ ↔ Integrable f μ := by rw [IntegrableOn, Measure.restrict_univ] theorem integrableOn_zero : IntegrableOn (fun _ => (0 : E)) s μ := integrable_zero _ _ _ @[simp] theorem integrableOn_const {C : E} : IntegrableOn (fun _ => C) s μ ↔ C = 0 ∨ μ s < ∞ := integrable_const_iff.trans <| by rw [isFiniteMeasure_restrict, lt_top_iff_ne_top] theorem IntegrableOn.mono (h : IntegrableOn f t ν) (hs : s ⊆ t) (hμ : μ ≤ ν) : IntegrableOn f s μ := h.mono_measure <| Measure.restrict_mono hs hμ theorem IntegrableOn.mono_set (h : IntegrableOn f t μ) (hst : s ⊆ t) : IntegrableOn f s μ := h.mono hst le_rfl theorem IntegrableOn.mono_measure (h : IntegrableOn f s ν) (hμ : μ ≤ ν) : IntegrableOn f s μ := h.mono (Subset.refl _) hμ theorem IntegrableOn.mono_set_ae (h : IntegrableOn f t μ) (hst : s ≤ᵐ[μ] t) : IntegrableOn f s μ := h.integrable.mono_measure <| Measure.restrict_mono_ae hst theorem IntegrableOn.congr_set_ae (h : IntegrableOn f t μ) (hst : s =ᵐ[μ] t) : IntegrableOn f s μ := h.mono_set_ae hst.le theorem IntegrableOn.congr_fun_ae (h : IntegrableOn f s μ) (hst : f =ᵐ[μ.restrict s] g) : IntegrableOn g s μ := Integrable.congr h hst theorem integrableOn_congr_fun_ae (hst : f =ᵐ[μ.restrict s] g) : IntegrableOn f s μ ↔ IntegrableOn g s μ := ⟨fun h => h.congr_fun_ae hst, fun h => h.congr_fun_ae hst.symm⟩ theorem IntegrableOn.congr_fun (h : IntegrableOn f s μ) (hst : EqOn f g s) (hs : MeasurableSet s) : IntegrableOn g s μ := h.congr_fun_ae ((ae_restrict_iff' hs).2 (Eventually.of_forall hst)) theorem integrableOn_congr_fun (hst : EqOn f g s) (hs : MeasurableSet s) : IntegrableOn f s μ ↔ IntegrableOn g s μ := ⟨fun h => h.congr_fun hst hs, fun h => h.congr_fun hst.symm hs⟩ theorem Integrable.integrableOn (h : Integrable f μ) : IntegrableOn f s μ := h.restrict theorem IntegrableOn.restrict (h : IntegrableOn f s μ) : IntegrableOn f s (μ.restrict t) := by dsimp only [IntegrableOn] at h ⊢ exact h.mono_measure <| Measure.restrict_mono_measure Measure.restrict_le_self _ theorem IntegrableOn.inter_of_restrict (h : IntegrableOn f s (μ.restrict t)) : IntegrableOn f (s ∩ t) μ := by have := h.mono_set (inter_subset_left (t := t)) rwa [IntegrableOn, μ.restrict_restrict_of_subset inter_subset_right] at this lemma Integrable.piecewise [DecidablePred (· ∈ s)] (hs : MeasurableSet s) (hf : IntegrableOn f s μ) (hg : IntegrableOn g sᶜ μ) : Integrable (s.piecewise f g) μ := by rw [IntegrableOn] at hf hg rw [← memLp_one_iff_integrable] at hf hg ⊢ exact MemLp.piecewise hs hf hg theorem IntegrableOn.left_of_union (h : IntegrableOn f (s ∪ t) μ) : IntegrableOn f s μ := h.mono_set subset_union_left theorem IntegrableOn.right_of_union (h : IntegrableOn f (s ∪ t) μ) : IntegrableOn f t μ := h.mono_set subset_union_right theorem IntegrableOn.union (hs : IntegrableOn f s μ) (ht : IntegrableOn f t μ) : IntegrableOn f (s ∪ t) μ := (hs.add_measure ht).mono_measure <| Measure.restrict_union_le _ _ @[simp] theorem integrableOn_union : IntegrableOn f (s ∪ t) μ ↔ IntegrableOn f s μ ∧ IntegrableOn f t μ := ⟨fun h => ⟨h.left_of_union, h.right_of_union⟩, fun h => h.1.union h.2⟩ @[simp] theorem integrableOn_singleton_iff {x : α} [MeasurableSingletonClass α] : IntegrableOn f {x} μ ↔ f x = 0 ∨ μ {x} < ∞ := by have : f =ᵐ[μ.restrict {x}] fun _ => f x := by filter_upwards [ae_restrict_mem (measurableSet_singleton x)] with _ ha simp only [mem_singleton_iff.1 ha] rw [IntegrableOn, integrable_congr this, integrable_const_iff, isFiniteMeasure_restrict, lt_top_iff_ne_top] @[simp] theorem integrableOn_finite_biUnion {s : Set β} (hs : s.Finite) {t : β → Set α} : IntegrableOn f (⋃ i ∈ s, t i) μ ↔ ∀ i ∈ s, IntegrableOn f (t i) μ := by induction s, hs using Set.Finite.induction_on with | empty => simp | insert _ _ hf => simp [hf, or_imp, forall_and] @[simp] theorem integrableOn_finset_iUnion {s : Finset β} {t : β → Set α} : IntegrableOn f (⋃ i ∈ s, t i) μ ↔ ∀ i ∈ s, IntegrableOn f (t i) μ := integrableOn_finite_biUnion s.finite_toSet @[simp] theorem integrableOn_finite_iUnion [Finite β] {t : β → Set α} : IntegrableOn f (⋃ i, t i) μ ↔ ∀ i, IntegrableOn f (t i) μ := by cases nonempty_fintype β simpa using @integrableOn_finset_iUnion _ _ _ _ _ f μ Finset.univ t lemma IntegrableOn.finset [MeasurableSingletonClass α] {μ : Measure α} [IsFiniteMeasure μ] {s : Finset α} {f : α → E} : IntegrableOn f s μ := by rw [← s.toSet.biUnion_of_singleton] simp [integrableOn_finset_iUnion, measure_lt_top] lemma IntegrableOn.of_finite [MeasurableSingletonClass α] {μ : Measure α} [IsFiniteMeasure μ] {s : Set α} (hs : s.Finite) {f : α → E} : IntegrableOn f s μ := by simpa using IntegrableOn.finset (s := hs.toFinset) theorem IntegrableOn.add_measure (hμ : IntegrableOn f s μ) (hν : IntegrableOn f s ν) : IntegrableOn f s (μ + ν) := by delta IntegrableOn; rw [Measure.restrict_add]; exact hμ.integrable.add_measure hν @[simp] theorem integrableOn_add_measure : IntegrableOn f s (μ + ν) ↔ IntegrableOn f s μ ∧ IntegrableOn f s ν := ⟨fun h => ⟨h.mono_measure (Measure.le_add_right le_rfl), h.mono_measure (Measure.le_add_left le_rfl)⟩, fun h => h.1.add_measure h.2⟩ theorem _root_.MeasurableEmbedding.integrableOn_map_iff [MeasurableSpace β] {e : α → β} (he : MeasurableEmbedding e) {f : β → E} {μ : Measure α} {s : Set β} : IntegrableOn f s (μ.map e) ↔ IntegrableOn (f ∘ e) (e ⁻¹' s) μ := by simp_rw [IntegrableOn, he.restrict_map, he.integrable_map_iff] theorem _root_.MeasurableEmbedding.integrableOn_iff_comap [MeasurableSpace β] {e : α → β} (he : MeasurableEmbedding e) {f : β → E} {μ : Measure β} {s : Set β} (hs : s ⊆ range e) : IntegrableOn f s μ ↔ IntegrableOn (f ∘ e) (e ⁻¹' s) (μ.comap e) := by simp_rw [← he.integrableOn_map_iff, he.map_comap, IntegrableOn, Measure.restrict_restrict_of_subset hs] theorem _root_.MeasurableEmbedding.integrableOn_range_iff_comap [MeasurableSpace β] {e : α → β} (he : MeasurableEmbedding e) {f : β → E} {μ : Measure β} : IntegrableOn f (range e) μ ↔ Integrable (f ∘ e) (μ.comap e) := by rw [he.integrableOn_iff_comap .rfl, preimage_range, integrableOn_univ] theorem integrableOn_iff_comap_subtypeVal (hs : MeasurableSet s) : IntegrableOn f s μ ↔ Integrable (f ∘ (↑) : s → E) (μ.comap (↑)) := by rw [← (MeasurableEmbedding.subtype_coe hs).integrableOn_range_iff_comap, Subtype.range_val] theorem integrableOn_map_equiv [MeasurableSpace β] (e : α ≃ᵐ β) {f : β → E} {μ : Measure α} {s : Set β} : IntegrableOn f s (μ.map e) ↔ IntegrableOn (f ∘ e) (e ⁻¹' s) μ := by simp only [IntegrableOn, e.restrict_map, integrable_map_equiv e] theorem MeasurePreserving.integrableOn_comp_preimage [MeasurableSpace β] {e : α → β} {ν} (h₁ : MeasurePreserving e μ ν) (h₂ : MeasurableEmbedding e) {f : β → E} {s : Set β} : IntegrableOn (f ∘ e) (e ⁻¹' s) μ ↔ IntegrableOn f s ν := (h₁.restrict_preimage_emb h₂ s).integrable_comp_emb h₂ theorem MeasurePreserving.integrableOn_image [MeasurableSpace β] {e : α → β} {ν} (h₁ : MeasurePreserving e μ ν) (h₂ : MeasurableEmbedding e) {f : β → E} {s : Set α} : IntegrableOn f (e '' s) ν ↔ IntegrableOn (f ∘ e) s μ := ((h₁.restrict_image_emb h₂ s).integrable_comp_emb h₂).symm theorem integrable_indicator_iff (hs : MeasurableSet s) : Integrable (indicator s f) μ ↔ IntegrableOn f s μ := by simp_rw [IntegrableOn, Integrable, hasFiniteIntegral_iff_enorm, enorm_indicator_eq_indicator_enorm, lintegral_indicator hs, aestronglyMeasurable_indicator_iff hs] theorem IntegrableOn.integrable_indicator (h : IntegrableOn f s μ) (hs : MeasurableSet s) : Integrable (indicator s f) μ := (integrable_indicator_iff hs).2 h @[fun_prop] theorem Integrable.indicator (h : Integrable f μ) (hs : MeasurableSet s) : Integrable (indicator s f) μ := h.integrableOn.integrable_indicator hs theorem IntegrableOn.indicator (h : IntegrableOn f s μ) (ht : MeasurableSet t) : IntegrableOn (indicator t f) s μ := Integrable.indicator h ht theorem integrable_indicatorConstLp {E} [NormedAddCommGroup E] {p : ℝ≥0∞} {s : Set α} (hs : MeasurableSet s) (hμs : μ s ≠ ∞) (c : E) : Integrable (indicatorConstLp p hs hμs c) μ := by rw [integrable_congr indicatorConstLp_coeFn, integrable_indicator_iff hs, IntegrableOn, integrable_const_iff, isFiniteMeasure_restrict] exact .inr hμs /-- If a function is integrable on a set `s` and nonzero there, then the measurable hull of `s` is well behaved: the restriction of the measure to `toMeasurable μ s` coincides with its restriction to `s`. -/ theorem IntegrableOn.restrict_toMeasurable (hf : IntegrableOn f s μ) (h's : ∀ x ∈ s, f x ≠ 0) : μ.restrict (toMeasurable μ s) = μ.restrict s := by rcases exists_seq_strictAnti_tendsto (0 : ℝ) with ⟨u, _, u_pos, u_lim⟩ let v n := toMeasurable (μ.restrict s) { x | u n ≤ ‖f x‖ } have A : ∀ n, μ (s ∩ v n) ≠ ∞ := by intro n rw [inter_comm, ← Measure.restrict_apply (measurableSet_toMeasurable _ _), measure_toMeasurable] exact (hf.measure_norm_ge_lt_top (u_pos n)).ne apply Measure.restrict_toMeasurable_of_cover _ A intro x hx have : 0 < ‖f x‖ := by simp only [h's x hx, norm_pos_iff, Ne, not_false_iff] obtain ⟨n, hn⟩ : ∃ n, u n < ‖f x‖ := ((tendsto_order.1 u_lim).2 _ this).exists exact mem_iUnion.2 ⟨n, subset_toMeasurable _ _ hn.le⟩ /-- If a function is integrable on a set `s`, and vanishes on `t \ s`, then it is integrable on `t` if `t` is null-measurable. -/ theorem IntegrableOn.of_ae_diff_eq_zero (hf : IntegrableOn f s μ) (ht : NullMeasurableSet t μ) (h't : ∀ᵐ x ∂μ, x ∈ t \ s → f x = 0) : IntegrableOn f t μ := by let u := { x ∈ s | f x ≠ 0 } have hu : IntegrableOn f u μ := hf.mono_set fun x hx => hx.1 let v := toMeasurable μ u have A : IntegrableOn f v μ := by rw [IntegrableOn, hu.restrict_toMeasurable] · exact hu · intro x hx; exact hx.2 have B : IntegrableOn f (t \ v) μ := by apply integrableOn_zero.congr filter_upwards [ae_restrict_of_ae h't, ae_restrict_mem₀ (ht.diff (measurableSet_toMeasurable μ u).nullMeasurableSet)] with x hxt hx by_cases h'x : x ∈ s · by_contra H exact hx.2 (subset_toMeasurable μ u ⟨h'x, Ne.symm H⟩) · exact (hxt ⟨hx.1, h'x⟩).symm apply (A.union B).mono_set _ rw [union_diff_self] exact subset_union_right /-- If a function is integrable on a set `s`, and vanishes on `t \ s`, then it is integrable on `t` if `t` is measurable. -/ theorem IntegrableOn.of_forall_diff_eq_zero (hf : IntegrableOn f s μ) (ht : MeasurableSet t) (h't : ∀ x ∈ t \ s, f x = 0) : IntegrableOn f t μ := hf.of_ae_diff_eq_zero ht.nullMeasurableSet (Eventually.of_forall h't) /-- If a function is integrable on a set `s` and vanishes almost everywhere on its complement, then it is integrable. -/ theorem IntegrableOn.integrable_of_ae_not_mem_eq_zero (hf : IntegrableOn f s μ) (h't : ∀ᵐ x ∂μ, x ∉ s → f x = 0) : Integrable f μ := by rw [← integrableOn_univ] apply hf.of_ae_diff_eq_zero nullMeasurableSet_univ filter_upwards [h't] with x hx h'x using hx h'x.2 /-- If a function is integrable on a set `s` and vanishes everywhere on its complement, then it is integrable. -/ theorem IntegrableOn.integrable_of_forall_not_mem_eq_zero (hf : IntegrableOn f s μ) (h't : ∀ x, x ∉ s → f x = 0) : Integrable f μ := hf.integrable_of_ae_not_mem_eq_zero (Eventually.of_forall fun x hx => h't x hx) theorem integrableOn_iff_integrable_of_support_subset (h1s : support f ⊆ s) : IntegrableOn f s μ ↔ Integrable f μ := by refine ⟨fun h => ?_, fun h => h.integrableOn⟩ refine h.integrable_of_forall_not_mem_eq_zero fun x hx => ?_ contrapose! hx exact h1s (mem_support.2 hx) theorem integrableOn_Lp_of_measure_ne_top {E} [NormedAddCommGroup E] {p : ℝ≥0∞} {s : Set α} (f : Lp E p μ) (hp : 1 ≤ p) (hμs : μ s ≠ ∞) : IntegrableOn f s μ := by refine memLp_one_iff_integrable.mp ?_ have hμ_restrict_univ : (μ.restrict s) Set.univ < ∞ := by simpa only [Set.univ_inter, MeasurableSet.univ, Measure.restrict_apply, lt_top_iff_ne_top] haveI hμ_finite : IsFiniteMeasure (μ.restrict s) := ⟨hμ_restrict_univ⟩ exact ((Lp.memLp _).restrict s).mono_exponent hp theorem Integrable.lintegral_lt_top {f : α → ℝ} (hf : Integrable f μ) : (∫⁻ x, ENNReal.ofReal (f x) ∂μ) < ∞ := calc (∫⁻ x, ENNReal.ofReal (f x) ∂μ) ≤ ∫⁻ x, ↑‖f x‖₊ ∂μ := lintegral_ofReal_le_lintegral_enorm f _ < ∞ := hf.2 theorem IntegrableOn.setLIntegral_lt_top {f : α → ℝ} {s : Set α} (hf : IntegrableOn f s μ) : (∫⁻ x in s, ENNReal.ofReal (f x) ∂μ) < ∞ := Integrable.lintegral_lt_top hf /-- We say that a function `f` is *integrable at filter* `l` if it is integrable on some set `s ∈ l`. Equivalently, it is eventually integrable on `s` in `l.smallSets`. -/ def IntegrableAtFilter (f : α → ε) (l : Filter α) (μ : Measure α := by volume_tac) := ∃ s ∈ l, IntegrableOn f s μ variable {l l' : Filter α} theorem _root_.MeasurableEmbedding.integrableAtFilter_map_iff [MeasurableSpace β] {e : α → β} (he : MeasurableEmbedding e) {f : β → E} : IntegrableAtFilter f (l.map e) (μ.map e) ↔ IntegrableAtFilter (f ∘ e) l μ := by simp_rw [IntegrableAtFilter, he.integrableOn_map_iff] constructor <;> rintro ⟨s, hs⟩ · exact ⟨_, hs⟩ · exact ⟨e '' s, by rwa [mem_map, he.injective.preimage_image]⟩ theorem _root_.MeasurableEmbedding.integrableAtFilter_iff_comap [MeasurableSpace β] {e : α → β} (he : MeasurableEmbedding e) {f : β → E} {μ : Measure β} : IntegrableAtFilter f (l.map e) μ ↔ IntegrableAtFilter (f ∘ e) l (μ.comap e) := by simp_rw [← he.integrableAtFilter_map_iff, IntegrableAtFilter, he.map_comap] constructor <;> rintro ⟨s, hs, int⟩ · exact ⟨s, hs, int.mono_measure <| μ.restrict_le_self⟩ · exact ⟨_, inter_mem hs range_mem_map, int.inter_of_restrict⟩ theorem Integrable.integrableAtFilter (h : Integrable f μ) (l : Filter α) : IntegrableAtFilter f l μ := ⟨univ, Filter.univ_mem, integrableOn_univ.2 h⟩ protected theorem IntegrableAtFilter.eventually (h : IntegrableAtFilter f l μ) : ∀ᶠ s in l.smallSets, IntegrableOn f s μ := Iff.mpr (eventually_smallSets' fun _s _t hst ht => ht.mono_set hst) h theorem integrableAtFilter_atBot_iff [Preorder α] [IsDirected α fun (x1 x2 : α) => x1 ≥ x2] [Nonempty α] : IntegrableAtFilter f atBot μ ↔ ∃ a, IntegrableOn f (Iic a) μ := by refine ⟨fun ⟨s, hs, hi⟩ ↦ ?_, fun ⟨a, ha⟩ ↦ ⟨Iic a, Iic_mem_atBot a, ha⟩⟩ obtain ⟨t, ht⟩ := mem_atBot_sets.mp hs exact ⟨t, hi.mono_set fun _ hx ↦ ht _ hx⟩ theorem integrableAtFilter_atTop_iff [Preorder α] [IsDirected α fun (x1 x2 : α) => x1 ≤ x2] [Nonempty α] : IntegrableAtFilter f atTop μ ↔ ∃ a, IntegrableOn f (Ici a) μ := integrableAtFilter_atBot_iff (α := αᵒᵈ) protected theorem IntegrableAtFilter.add {f g : α → E} (hf : IntegrableAtFilter f l μ) (hg : IntegrableAtFilter g l μ) : IntegrableAtFilter (f + g) l μ := by rcases hf with ⟨s, sl, hs⟩ rcases hg with ⟨t, tl, ht⟩ refine ⟨s ∩ t, inter_mem sl tl, ?_⟩ exact (hs.mono_set inter_subset_left).add (ht.mono_set inter_subset_right) protected theorem IntegrableAtFilter.neg {f : α → E} (hf : IntegrableAtFilter f l μ) : IntegrableAtFilter (-f) l μ := by rcases hf with ⟨s, sl, hs⟩ exact ⟨s, sl, hs.neg⟩ protected theorem IntegrableAtFilter.sub {f g : α → E} (hf : IntegrableAtFilter f l μ) (hg : IntegrableAtFilter g l μ) : IntegrableAtFilter (f - g) l μ := by rw [sub_eq_add_neg] exact hf.add hg.neg protected theorem IntegrableAtFilter.smul {𝕜 : Type*} [NormedAddCommGroup 𝕜] [SMulZeroClass 𝕜 E] [IsBoundedSMul 𝕜 E] {f : α → E} (hf : IntegrableAtFilter f l μ) (c : 𝕜) : IntegrableAtFilter (c • f) l μ := by rcases hf with ⟨s, sl, hs⟩ exact ⟨s, sl, hs.smul c⟩ protected theorem IntegrableAtFilter.norm (hf : IntegrableAtFilter f l μ) : IntegrableAtFilter (fun x => ‖f x‖) l μ := Exists.casesOn hf fun s hs ↦ ⟨s, hs.1, hs.2.norm⟩ theorem IntegrableAtFilter.filter_mono (hl : l ≤ l') (hl' : IntegrableAtFilter f l' μ) : IntegrableAtFilter f l μ := let ⟨s, hs, hsf⟩ := hl' ⟨s, hl hs, hsf⟩ theorem IntegrableAtFilter.inf_of_left (hl : IntegrableAtFilter f l μ) : IntegrableAtFilter f (l ⊓ l') μ := hl.filter_mono inf_le_left theorem IntegrableAtFilter.inf_of_right (hl : IntegrableAtFilter f l μ) : IntegrableAtFilter f (l' ⊓ l) μ := hl.filter_mono inf_le_right @[simp] theorem IntegrableAtFilter.inf_ae_iff {l : Filter α} : IntegrableAtFilter f (l ⊓ ae μ) μ ↔ IntegrableAtFilter f l μ := by refine ⟨?_, fun h ↦ h.filter_mono inf_le_left⟩ rintro ⟨s, ⟨t, ht, u, hu, rfl⟩, hf⟩ refine ⟨t, ht, hf.congr_set_ae <| eventuallyEq_set.2 ?_⟩ filter_upwards [hu] with x hx using (and_iff_left hx).symm alias ⟨IntegrableAtFilter.of_inf_ae, _⟩ := IntegrableAtFilter.inf_ae_iff @[simp] theorem integrableAtFilter_top : IntegrableAtFilter f ⊤ μ ↔ Integrable f μ := by refine ⟨fun h ↦ ?_, fun h ↦ h.integrableAtFilter ⊤⟩ obtain ⟨s, hsf, hs⟩ := h exact (integrableOn_iff_integrable_of_support_subset fun _ _ ↦ hsf _).mp hs theorem IntegrableAtFilter.sup_iff {l l' : Filter α} : IntegrableAtFilter f (l ⊔ l') μ ↔ IntegrableAtFilter f l μ ∧ IntegrableAtFilter f l' μ := by constructor · exact fun h => ⟨h.filter_mono le_sup_left, h.filter_mono le_sup_right⟩ · exact fun ⟨⟨s, hsl, hs⟩, ⟨t, htl, ht⟩⟩ ↦ ⟨s ∪ t, union_mem_sup hsl htl, hs.union ht⟩ /-- If `μ` is a measure finite at filter `l` and `f` is a function such that its norm is bounded above at `l`, then `f` is integrable at `l`. -/ theorem Measure.FiniteAtFilter.integrableAtFilter {l : Filter α} [IsMeasurablyGenerated l] (hfm : StronglyMeasurableAtFilter f l μ) (hμ : μ.FiniteAtFilter l) (hf : l.IsBoundedUnder (· ≤ ·) (norm ∘ f)) : IntegrableAtFilter f l μ := by obtain ⟨C, hC⟩ : ∃ C, ∀ᶠ s in l.smallSets, ∀ x ∈ s, ‖f x‖ ≤ C := hf.imp fun C hC => eventually_smallSets.2 ⟨_, hC, fun t => id⟩ rcases (hfm.eventually.and (hμ.eventually.and hC)).exists_measurable_mem_of_smallSets with ⟨s, hsl, hsm, hfm, hμ, hC⟩ refine ⟨s, hsl, ⟨hfm, hasFiniteIntegral_restrict_of_bounded hμ (C := C) ?_⟩⟩ rw [ae_restrict_eq hsm, eventually_inf_principal] exact Eventually.of_forall hC theorem Measure.FiniteAtFilter.integrableAtFilter_of_tendsto_ae {l : Filter α} [IsMeasurablyGenerated l] (hfm : StronglyMeasurableAtFilter f l μ) (hμ : μ.FiniteAtFilter l) {b} (hf : Tendsto f (l ⊓ ae μ) (𝓝 b)) : IntegrableAtFilter f l μ := (hμ.inf_of_left.integrableAtFilter (hfm.filter_mono inf_le_left) hf.norm.isBoundedUnder_le).of_inf_ae alias _root_.Filter.Tendsto.integrableAtFilter_ae := Measure.FiniteAtFilter.integrableAtFilter_of_tendsto_ae theorem Measure.FiniteAtFilter.integrableAtFilter_of_tendsto {l : Filter α} [IsMeasurablyGenerated l] (hfm : StronglyMeasurableAtFilter f l μ) (hμ : μ.FiniteAtFilter l) {b} (hf : Tendsto f l (𝓝 b)) : IntegrableAtFilter f l μ := hμ.integrableAtFilter hfm hf.norm.isBoundedUnder_le alias _root_.Filter.Tendsto.integrableAtFilter := Measure.FiniteAtFilter.integrableAtFilter_of_tendsto lemma Measure.integrableOn_of_bounded (s_finite : μ s ≠ ∞) (f_mble : AEStronglyMeasurable f μ) {M : ℝ} (f_bdd : ∀ᵐ a ∂(μ.restrict s), ‖f a‖ ≤ M) : IntegrableOn f s μ := ⟨f_mble.restrict, hasFiniteIntegral_restrict_of_bounded (C := M) s_finite.lt_top f_bdd⟩ theorem integrable_add_of_disjoint {f g : α → E} (h : Disjoint (support f) (support g))
(hf : StronglyMeasurable f) (hg : StronglyMeasurable g) : Integrable (f + g) μ ↔ Integrable f μ ∧ Integrable g μ := by refine ⟨fun hfg => ⟨?_, ?_⟩, fun h => h.1.add h.2⟩ · rw [← indicator_add_eq_left h]; exact hfg.indicator hf.measurableSet_support · rw [← indicator_add_eq_right h]; exact hfg.indicator hg.measurableSet_support /-- If a function converges along a filter to a limit `a`, is integrable along this filter, and all elements of the filter have infinite measure, then the limit has to vanish. -/ lemma IntegrableAtFilter.eq_zero_of_tendsto (h : IntegrableAtFilter f l μ) (h' : ∀ s ∈ l, μ s = ∞) {a : E}
Mathlib/MeasureTheory/Integral/IntegrableOn.lean
503
512
/- 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,257
2,272
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Algebra.CharP.Reduced import Mathlib.Algebra.Field.ZMod import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.ValMinAbs import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix import Mathlib.FieldTheory.Finiteness import Mathlib.FieldTheory.Perfect import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * #(univ.image fun x => eval x p) := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = #(p - C a).roots.toFinset := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_cancel]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g))) <| calc 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * #(univ.image fun x : R => eval x f) + natDegree (-g) * #(univ.image fun x : R => eval x (-g)) := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) := by rw [card_union_of_disjoint hd] simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp +contextual [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) : ∑ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G ↪ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x simp only [h_unchanged, mulLeftEmbedding_apply, Subgroup.coe_mul, Units.val_mul, ← mul_sum, a_mul_emb] at h_sum_map -- thus one of (a - 1) or ∑ G, x is zero have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] : ∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by by_cases G_bot : G = ⊥ · subst G_bot simp only [univ_unique, sum_singleton, ↓reduceIte, Units.val_eq_one, OneMemClass.coe_eq_one] rw [Set.default_coe_singleton] rfl · simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by rw [← Nat.card_eq_fintype_card] at k_lt_card_G nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k) = (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by funext x simp only [Function.comp_apply, Subgroup.coe_mul, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : Kˣ) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K]
theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one]
Mathlib/FieldTheory/Finite/Basic.lean
215
222
/- 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.Order.Hom.CompleteLattice import Mathlib.Topology.Compactness.Bases import Mathlib.Topology.ContinuousMap.Basic import Mathlib.Order.CompactlyGenerated.Basic import Mathlib.Order.Copy /-! # Open sets ## Summary We define the subtype of open sets in a topological space. ## Main Definitions ### Bundled open sets - `TopologicalSpace.Opens α` is the type of open subsets of a topological space `α`. - `TopologicalSpace.Opens.IsBasis` is a predicate saying that a set of `Opens`s form a topological basis. - `TopologicalSpace.Opens.comap`: preimage of an open set under a continuous map as a `FrameHom`. - `Homeomorph.opensCongr`: order-preserving equivalence between open sets in the domain and the codomain of a homeomorphism. ### Bundled open neighborhoods - `TopologicalSpace.OpenNhdsOf x` is the type of open subsets of a topological space `α` containing `x : α`. - `TopologicalSpace.OpenNhdsOf.comap f x U` is the preimage of open neighborhood `U` of `f x` under `f : C(α, β)`. ## Main results We define order structures on both `Opens α` (`CompleteLattice`, `Frame`) and `OpenNhdsOf x` (`OrderTop`, `DistribLattice`). ## TODO - Rename `TopologicalSpace.Opens` to `Open`? - Port the `auto_cases` tactic version (as a plugin if the ported `auto_cases` will allow plugins). -/ open Filter Function Order Set open Topology variable {ι α β γ : Type*} [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ] namespace TopologicalSpace variable (α) in /-- The type of open subsets of a topological space. -/ structure Opens where /-- The underlying set of a bundled `TopologicalSpace.Opens` object. -/ carrier : Set α /-- The `TopologicalSpace.Opens.carrier _` is an open set. -/ is_open' : IsOpen carrier namespace Opens instance : SetLike (Opens α) α where coe := Opens.carrier coe_injective' := fun ⟨_, _⟩ ⟨_, _⟩ _ => by congr instance : CanLift (Set α) (Opens α) (↑) IsOpen := ⟨fun s h => ⟨⟨s, h⟩, rfl⟩⟩ instance instSecondCountableOpens [SecondCountableTopology α] (U : Opens α) : SecondCountableTopology U := inferInstanceAs (SecondCountableTopology U.1) theorem «forall» {p : Opens α → Prop} : (∀ U, p U) ↔ ∀ (U : Set α) (hU : IsOpen U), p ⟨U, hU⟩ := ⟨fun h _ _ => h _, fun h _ => h _ _⟩ @[simp] theorem carrier_eq_coe (U : Opens α) : U.1 = ↑U := rfl /-- the coercion `Opens α → Set α` applied to a pair is the same as taking the first component -/ @[simp] theorem coe_mk {U : Set α} {hU : IsOpen U} : ↑(⟨U, hU⟩ : Opens α) = U := rfl @[simp] theorem mem_mk {x : α} {U : Set α} {h : IsOpen U} : x ∈ mk U h ↔ x ∈ U := Iff.rfl protected theorem nonempty_coeSort {U : Opens α} : Nonempty U ↔ (U : Set α).Nonempty := Set.nonempty_coe_sort -- TODO: should this theorem be proved for a `SetLike`? protected theorem nonempty_coe {U : Opens α} : (U : Set α).Nonempty ↔ ∃ x, x ∈ U := Iff.rfl @[ext] -- TODO: replace with `∀ x, x ∈ U ↔ x ∈ V`? theorem ext {U V : Opens α} (h : (U : Set α) = V) : U = V := SetLike.coe_injective h theorem coe_inj {U V : Opens α} : (U : Set α) = V ↔ U = V := SetLike.ext'_iff.symm /-- A version of `Set.inclusion` not requiring definitional abuse -/ abbrev inclusion {U V : Opens α} (h : U ≤ V) : U → V := Set.inclusion h protected theorem isOpen (U : Opens α) : IsOpen (U : Set α) := U.is_open' @[simp] theorem mk_coe (U : Opens α) : mk (↑U) U.isOpen = U := rfl /-- See Note [custom simps projection]. -/ def Simps.coe (U : Opens α) : Set α := U initialize_simps_projections Opens (carrier → coe, as_prefix coe) /-- The interior of a set, as an element of `Opens`. -/ @[simps] protected def interior (s : Set α) : Opens α := ⟨interior s, isOpen_interior⟩ @[simp] theorem mem_interior {s : Set α} {x : α} : x ∈ Opens.interior s ↔ x ∈ _root_.interior s := .rfl theorem gc : GaloisConnection ((↑) : Opens α → Set α) Opens.interior := fun U _ => ⟨fun h => interior_maximal h U.isOpen, fun h => le_trans h interior_subset⟩ /-- The galois coinsertion between sets and opens. -/ def gi : GaloisCoinsertion (↑) (@Opens.interior α _) where choice s hs := ⟨s, interior_eq_iff_isOpen.mp <| le_antisymm interior_subset hs⟩ gc := gc u_l_le _ := interior_subset choice_eq _s hs := le_antisymm hs interior_subset instance : CompleteLattice (Opens α) := CompleteLattice.copy (GaloisCoinsertion.liftCompleteLattice gi) -- le (fun U V => (U : Set α) ⊆ V) rfl -- top ⟨univ, isOpen_univ⟩ (ext interior_univ.symm) -- bot ⟨∅, isOpen_empty⟩ rfl -- sup (fun U V => ⟨↑U ∪ ↑V, U.2.union V.2⟩) rfl -- inf (fun U V => ⟨↑U ∩ ↑V, U.2.inter V.2⟩) (funext₂ fun U V => ext (U.2.inter V.2).interior_eq.symm) -- sSup (fun S => ⟨⋃ s ∈ S, ↑s, isOpen_biUnion fun s _ => s.2⟩) (funext fun _ => ext sSup_image.symm) -- sInf _ rfl @[simp] theorem mk_inf_mk {U V : Set α} {hU : IsOpen U} {hV : IsOpen V} : (⟨U, hU⟩ ⊓ ⟨V, hV⟩ : Opens α) = ⟨U ⊓ V, IsOpen.inter hU hV⟩ := rfl @[simp, norm_cast] theorem coe_inf (s t : Opens α) : (↑(s ⊓ t) : Set α) = ↑s ∩ ↑t := rfl @[simp] lemma mem_inf {s t : Opens α} {x : α} : x ∈ s ⊓ t ↔ x ∈ s ∧ x ∈ t := Iff.rfl @[simp, norm_cast] theorem coe_sup (s t : Opens α) : (↑(s ⊔ t) : Set α) = ↑s ∪ ↑t := rfl @[simp, norm_cast] theorem coe_bot : ((⊥ : Opens α) : Set α) = ∅ := rfl @[simp] lemma mem_bot {x : α} : x ∈ (⊥ : Opens α) ↔ False := Iff.rfl @[simp] theorem mk_empty : (⟨∅, isOpen_empty⟩ : Opens α) = ⊥ := rfl @[simp, norm_cast] theorem coe_eq_empty {U : Opens α} : (U : Set α) = ∅ ↔ U = ⊥ := SetLike.coe_injective.eq_iff' rfl @[simp] lemma mem_top (x : α) : x ∈ (⊤ : Opens α) := trivial @[simp, norm_cast] theorem coe_top : ((⊤ : Opens α) : Set α) = Set.univ := rfl @[simp] theorem mk_univ : (⟨univ, isOpen_univ⟩ : Opens α) = ⊤ := rfl @[simp, norm_cast] theorem coe_eq_univ {U : Opens α} : (U : Set α) = univ ↔ U = ⊤ := SetLike.coe_injective.eq_iff' rfl @[simp, norm_cast] theorem coe_sSup {S : Set (Opens α)} : (↑(sSup S) : Set α) = ⋃ i ∈ S, ↑i := rfl @[simp, norm_cast] theorem coe_finset_sup (f : ι → Opens α) (s : Finset ι) : (↑(s.sup f) : Set α) = s.sup ((↑) ∘ f) := map_finset_sup (⟨⟨(↑), coe_sup⟩, coe_bot⟩ : SupBotHom (Opens α) (Set α)) _ _ @[simp, norm_cast] theorem coe_finset_inf (f : ι → Opens α) (s : Finset ι) : (↑(s.inf f) : Set α) = s.inf ((↑) ∘ f) := map_finset_inf (⟨⟨(↑), coe_inf⟩, coe_top⟩ : InfTopHom (Opens α) (Set α)) _ _ instance : Inhabited (Opens α) := ⟨⊥⟩ instance [IsEmpty α] : Unique (Opens α) where uniq _ := ext <| Subsingleton.elim _ _ instance [Nonempty α] : Nontrivial (Opens α) where exists_pair_ne := ⟨⊥, ⊤, mt coe_inj.2 empty_ne_univ⟩ @[simp, norm_cast] theorem coe_iSup {ι} (s : ι → Opens α) : ((⨆ i, s i : Opens α) : Set α) = ⋃ i, s i := by simp [iSup] theorem iSup_def {ι} (s : ι → Opens α) : ⨆ i, s i = ⟨⋃ i, s i, isOpen_iUnion fun i => (s i).2⟩ := ext <| coe_iSup s @[simp] theorem iSup_mk {ι} (s : ι → Set α) (h : ∀ i, IsOpen (s i)) : (⨆ i, ⟨s i, h i⟩ : Opens α) = ⟨⋃ i, s i, isOpen_iUnion h⟩ := iSup_def _ @[simp] theorem mem_iSup {ι} {x : α} {s : ι → Opens α} : x ∈ iSup s ↔ ∃ i, x ∈ s i := by rw [← SetLike.mem_coe] simp @[simp] theorem mem_sSup {Us : Set (Opens α)} {x : α} : x ∈ sSup Us ↔ ∃ u ∈ Us, x ∈ u := by simp_rw [sSup_eq_iSup, mem_iSup, exists_prop] /-- Open sets in a topological space form a frame. -/ def frameMinimalAxioms : Frame.MinimalAxioms (Opens α) where inf_sSup_le_iSup_inf a s := (ext <| by simp only [coe_inf, coe_iSup, coe_sSup, Set.inter_iUnion₂]).le instance instFrame : Frame (Opens α) := .ofMinimalAxioms frameMinimalAxioms theorem isOpenEmbedding' (U : Opens α) : IsOpenEmbedding (Subtype.val : U → α) := U.isOpen.isOpenEmbedding_subtypeVal theorem isOpenEmbedding_of_le {U V : Opens α} (i : U ≤ V) : IsOpenEmbedding (Set.inclusion <| SetLike.coe_subset_coe.2 i) where toIsEmbedding := .inclusion i isOpen_range := by rw [Set.range_inclusion i] exact U.isOpen.preimage continuous_subtype_val theorem not_nonempty_iff_eq_bot (U : Opens α) : ¬Set.Nonempty (U : Set α) ↔ U = ⊥ := by rw [← coe_inj, coe_bot, ← Set.not_nonempty_iff_eq_empty] theorem ne_bot_iff_nonempty (U : Opens α) : U ≠ ⊥ ↔ Set.Nonempty (U : Set α) := by rw [Ne, ← not_nonempty_iff_eq_bot, not_not] /-- An open set in the indiscrete topology is either empty or the whole space. -/ theorem eq_bot_or_top {α} [t : TopologicalSpace α] (h : t = ⊤) (U : Opens α) : U = ⊥ ∨ U = ⊤ := by subst h; letI : TopologicalSpace α := ⊤ rw [← coe_eq_empty, ← coe_eq_univ, ← isOpen_top_iff]
exact U.2 instance [Nonempty α] [Subsingleton α] : IsSimpleOrder (Opens α) where eq_bot_or_eq_top := eq_bot_or_top <| Subsingleton.elim _ _ /-- A set of `opens α` is a basis if the set of corresponding sets is a topological basis. -/
Mathlib/Topology/Sets/Opens.lean
264
269
/- Copyright (c) 2019 Abhimanyu Pallavi Sudhir. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Abhimanyu Pallavi Sudhir -/ import Mathlib.Order.Filter.FilterProduct import Mathlib.Analysis.SpecificLimits.Basic /-! # Construction of the hyperreal numbers as an ultraproduct of real sequences. -/ open Filter Germ Topology /-- Hyperreal numbers on the ultrafilter extending the cofinite filter -/ def Hyperreal : Type := Germ (hyperfilter ℕ : Filter ℕ) ℝ deriving Inhabited namespace Hyperreal @[inherit_doc] notation "ℝ*" => Hyperreal noncomputable instance : Field ℝ* := inferInstanceAs (Field (Germ _ _)) noncomputable instance : LinearOrder ℝ* := inferInstanceAs (LinearOrder (Germ _ _)) instance : IsStrictOrderedRing ℝ* := inferInstanceAs (IsStrictOrderedRing (Germ _ _)) /-- Natural embedding `ℝ → ℝ*`. -/ @[coe] def ofReal : ℝ → ℝ* := const noncomputable instance : CoeTC ℝ ℝ* := ⟨ofReal⟩ @[simp, norm_cast] theorem coe_eq_coe {x y : ℝ} : (x : ℝ*) = y ↔ x = y := Germ.const_inj theorem coe_ne_coe {x y : ℝ} : (x : ℝ*) ≠ y ↔ x ≠ y := coe_eq_coe.not @[simp, norm_cast] theorem coe_eq_zero {x : ℝ} : (x : ℝ*) = 0 ↔ x = 0 := coe_eq_coe @[simp, norm_cast] theorem coe_eq_one {x : ℝ} : (x : ℝ*) = 1 ↔ x = 1 := coe_eq_coe @[norm_cast] theorem coe_ne_zero {x : ℝ} : (x : ℝ*) ≠ 0 ↔ x ≠ 0 := coe_ne_coe @[norm_cast] theorem coe_ne_one {x : ℝ} : (x : ℝ*) ≠ 1 ↔ x ≠ 1 := coe_ne_coe @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ) = (1 : ℝ*) := rfl @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ) = (0 : ℝ*) := rfl @[simp, norm_cast] theorem coe_inv (x : ℝ) : ↑x⁻¹ = (x⁻¹ : ℝ*) := rfl @[simp, norm_cast] theorem coe_neg (x : ℝ) : ↑(-x) = (-x : ℝ*) := rfl @[simp, norm_cast] theorem coe_add (x y : ℝ) : ↑(x + y) = (x + y : ℝ*) := rfl @[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℝ) : ℝ*) = OfNat.ofNat n := rfl @[simp, norm_cast] theorem coe_mul (x y : ℝ) : ↑(x * y) = (x * y : ℝ*) := rfl @[simp, norm_cast] theorem coe_div (x y : ℝ) : ↑(x / y) = (x / y : ℝ*) := rfl @[simp, norm_cast] theorem coe_sub (x y : ℝ) : ↑(x - y) = (x - y : ℝ*) := rfl @[simp, norm_cast] theorem coe_le_coe {x y : ℝ} : (x : ℝ*) ≤ y ↔ x ≤ y := Germ.const_le_iff @[simp, norm_cast] theorem coe_lt_coe {x y : ℝ} : (x : ℝ*) < y ↔ x < y := Germ.const_lt_iff @[simp, norm_cast] theorem coe_nonneg {x : ℝ} : 0 ≤ (x : ℝ*) ↔ 0 ≤ x := coe_le_coe @[simp, norm_cast] theorem coe_pos {x : ℝ} : 0 < (x : ℝ*) ↔ 0 < x := coe_lt_coe @[simp, norm_cast] theorem coe_abs (x : ℝ) : ((|x| : ℝ) : ℝ*) = |↑x| := const_abs x @[simp, norm_cast] theorem coe_max (x y : ℝ) : ((max x y : ℝ) : ℝ*) = max ↑x ↑y := Germ.const_max _ _ @[simp, norm_cast] theorem coe_min (x y : ℝ) : ((min x y : ℝ) : ℝ*) = min ↑x ↑y := Germ.const_min _ _ /-- Construct a hyperreal number from a sequence of real numbers. -/ def ofSeq (f : ℕ → ℝ) : ℝ* := (↑f : Germ (hyperfilter ℕ : Filter ℕ) ℝ) theorem ofSeq_surjective : Function.Surjective ofSeq := Quot.exists_rep theorem ofSeq_lt_ofSeq {f g : ℕ → ℝ} : ofSeq f < ofSeq g ↔ ∀ᶠ n in hyperfilter ℕ, f n < g n := Germ.coe_lt /-- A sample infinitesimal hyperreal -/ noncomputable def epsilon : ℝ* := ofSeq fun n => n⁻¹ /-- A sample infinite hyperreal -/ noncomputable def omega : ℝ* := ofSeq Nat.cast @[inherit_doc] scoped notation "ε" => Hyperreal.epsilon @[inherit_doc] scoped notation "ω" => Hyperreal.omega @[simp] theorem inv_omega : ω⁻¹ = ε := rfl @[simp] theorem inv_epsilon : ε⁻¹ = ω := @inv_inv _ _ ω theorem omega_pos : 0 < ω := Germ.coe_pos.2 <| Nat.hyperfilter_le_atTop <| (eventually_gt_atTop 0).mono fun _ ↦ Nat.cast_pos.2 theorem epsilon_pos : 0 < ε := inv_pos_of_pos omega_pos theorem epsilon_ne_zero : ε ≠ 0 := epsilon_pos.ne' theorem omega_ne_zero : ω ≠ 0 := omega_pos.ne' theorem epsilon_mul_omega : ε * ω = 1 := @inv_mul_cancel₀ _ _ ω omega_ne_zero theorem lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) : ∀ {r : ℝ}, 0 < r → ofSeq f < (r : ℝ*) := fun hr ↦ ofSeq_lt_ofSeq.2 <| (hf.eventually <| gt_mem_nhds hr).filter_mono Nat.hyperfilter_le_atTop theorem neg_lt_of_tendsto_zero_of_pos {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) : ∀ {r : ℝ}, 0 < r → (-r : ℝ*) < ofSeq f := fun hr => have hg := hf.neg neg_lt_of_neg_lt (by rw [neg_zero] at hg; exact lt_of_tendsto_zero_of_pos hg hr) theorem gt_of_tendsto_zero_of_neg {f : ℕ → ℝ} (hf : Tendsto f atTop (𝓝 0)) : ∀ {r : ℝ}, r < 0 → (r : ℝ*) < ofSeq f := fun {r} hr => by rw [← neg_neg r, coe_neg]; exact neg_lt_of_tendsto_zero_of_pos hf (neg_pos.mpr hr) theorem epsilon_lt_pos (x : ℝ) : 0 < x → ε < x := lt_of_tendsto_zero_of_pos tendsto_inverse_atTop_nhds_zero_nat /-- Standard part predicate -/ def IsSt (x : ℝ*) (r : ℝ) := ∀ δ : ℝ, 0 < δ → (r - δ : ℝ*) < x ∧ x < r + δ open scoped Classical in /-- Standard part function: like a "round" to ℝ instead of ℤ -/ noncomputable def st : ℝ* → ℝ := fun x => if h : ∃ r, IsSt x r then Classical.choose h else 0 /-- A hyperreal number is infinitesimal if its standard part is 0 -/ def Infinitesimal (x : ℝ*) := IsSt x 0 /-- A hyperreal number is positive infinite if it is larger than all real numbers -/ def InfinitePos (x : ℝ*) := ∀ r : ℝ, ↑r < x /-- A hyperreal number is negative infinite if it is smaller than all real numbers -/ def InfiniteNeg (x : ℝ*) := ∀ r : ℝ, x < r /-- A hyperreal number is infinite if it is infinite positive or infinite negative -/ def Infinite (x : ℝ*) := InfinitePos x ∨ InfiniteNeg x /-! ### Some facts about `st` -/ theorem isSt_ofSeq_iff_tendsto {f : ℕ → ℝ} {r : ℝ} : IsSt (ofSeq f) r ↔ Tendsto f (hyperfilter ℕ) (𝓝 r) := Iff.trans (forall₂_congr fun _ _ ↦ (ofSeq_lt_ofSeq.and ofSeq_lt_ofSeq).trans eventually_and.symm) (nhds_basis_Ioo_pos _).tendsto_right_iff.symm theorem isSt_iff_tendsto {x : ℝ*} {r : ℝ} : IsSt x r ↔ x.Tendsto (𝓝 r) := by rcases ofSeq_surjective x with ⟨f, rfl⟩ exact isSt_ofSeq_iff_tendsto theorem isSt_of_tendsto {f : ℕ → ℝ} {r : ℝ} (hf : Tendsto f atTop (𝓝 r)) : IsSt (ofSeq f) r := isSt_ofSeq_iff_tendsto.2 <| hf.mono_left Nat.hyperfilter_le_atTop protected theorem IsSt.lt {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) (hrs : r < s) : x < y := by rcases ofSeq_surjective x with ⟨f, rfl⟩ rcases ofSeq_surjective y with ⟨g, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hxr hys exact ofSeq_lt_ofSeq.2 <| hxr.eventually_lt hys hrs theorem IsSt.unique {x : ℝ*} {r s : ℝ} (hr : IsSt x r) (hs : IsSt x s) : r = s := by rcases ofSeq_surjective x with ⟨f, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hr hs exact tendsto_nhds_unique hr hs theorem IsSt.st_eq {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : st x = r := by have h : ∃ r, IsSt x r := ⟨r, hxr⟩ rw [st, dif_pos h] exact (Classical.choose_spec h).unique hxr theorem IsSt.not_infinite {x : ℝ*} {r : ℝ} (h : IsSt x r) : ¬Infinite x := fun hi ↦ hi.elim (fun hp ↦ lt_asymm (h 1 one_pos).2 (hp (r + 1))) fun hn ↦ lt_asymm (h 1 one_pos).1 (hn (r - 1)) theorem not_infinite_of_exists_st {x : ℝ*} : (∃ r : ℝ, IsSt x r) → ¬Infinite x := fun ⟨_r, hr⟩ => hr.not_infinite theorem Infinite.st_eq {x : ℝ*} (hi : Infinite x) : st x = 0 := dif_neg fun ⟨_r, hr⟩ ↦ hr.not_infinite hi theorem isSt_sSup {x : ℝ*} (hni : ¬Infinite x) : IsSt x (sSup { y : ℝ | (y : ℝ*) < x }) := let S : Set ℝ := { y : ℝ | (y : ℝ*) < x } let R : ℝ := sSup S let ⟨r₁, hr₁⟩ := not_forall.mp (not_or.mp hni).2 let ⟨r₂, hr₂⟩ := not_forall.mp (not_or.mp hni).1 have HR₁ : S.Nonempty := ⟨r₁ - 1, lt_of_lt_of_le (coe_lt_coe.2 <| sub_one_lt _) (not_lt.mp hr₁)⟩ have HR₂ : BddAbove S := ⟨r₂, fun _y hy => le_of_lt (coe_lt_coe.1 (lt_of_lt_of_le hy (not_lt.mp hr₂)))⟩ fun δ hδ => ⟨lt_of_not_le fun c => have hc : ∀ y ∈ S, y ≤ R - δ := fun _y hy => coe_le_coe.1 <| le_of_lt <| lt_of_lt_of_le hy c not_lt_of_le (csSup_le HR₁ hc) <| sub_lt_self R hδ, lt_of_not_le fun c => have hc : ↑(R + δ / 2) < x := lt_of_lt_of_le (add_lt_add_left (coe_lt_coe.2 (half_lt_self hδ)) R) c not_lt_of_le (le_csSup HR₂ hc) <| (lt_add_iff_pos_right _).mpr <| half_pos hδ⟩ theorem exists_st_of_not_infinite {x : ℝ*} (hni : ¬Infinite x) : ∃ r : ℝ, IsSt x r := ⟨sSup { y : ℝ | (y : ℝ*) < x }, isSt_sSup hni⟩ theorem st_eq_sSup {x : ℝ*} : st x = sSup { y : ℝ | (y : ℝ*) < x } := by rcases _root_.em (Infinite x) with (hx|hx) · rw [hx.st_eq] cases hx with | inl hx => convert Real.sSup_univ.symm exact Set.eq_univ_of_forall hx | inr hx => convert Real.sSup_empty.symm exact Set.eq_empty_of_forall_not_mem fun y hy ↦ hy.out.not_lt (hx _) · exact (isSt_sSup hx).st_eq theorem exists_st_iff_not_infinite {x : ℝ*} : (∃ r : ℝ, IsSt x r) ↔ ¬Infinite x := ⟨not_infinite_of_exists_st, exists_st_of_not_infinite⟩ theorem infinite_iff_not_exists_st {x : ℝ*} : Infinite x ↔ ¬∃ r : ℝ, IsSt x r := iff_not_comm.mp exists_st_iff_not_infinite theorem IsSt.isSt_st {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : IsSt x (st x) := by rwa [hxr.st_eq] theorem isSt_st_of_exists_st {x : ℝ*} (hx : ∃ r : ℝ, IsSt x r) : IsSt x (st x) := let ⟨_r, hr⟩ := hx; hr.isSt_st theorem isSt_st' {x : ℝ*} (hx : ¬Infinite x) : IsSt x (st x) := (isSt_sSup hx).isSt_st theorem isSt_st {x : ℝ*} (hx : st x ≠ 0) : IsSt x (st x) := isSt_st' <| mt Infinite.st_eq hx theorem isSt_refl_real (r : ℝ) : IsSt r r := isSt_ofSeq_iff_tendsto.2 tendsto_const_nhds theorem st_id_real (r : ℝ) : st r = r := (isSt_refl_real r).st_eq theorem eq_of_isSt_real {r s : ℝ} : IsSt r s → r = s := (isSt_refl_real r).unique theorem isSt_real_iff_eq {r s : ℝ} : IsSt r s ↔ r = s := ⟨eq_of_isSt_real, fun hrs => hrs ▸ isSt_refl_real r⟩ theorem isSt_symm_real {r s : ℝ} : IsSt r s ↔ IsSt s r := by rw [isSt_real_iff_eq, isSt_real_iff_eq, eq_comm] theorem isSt_trans_real {r s t : ℝ} : IsSt r s → IsSt s t → IsSt r t := by rw [isSt_real_iff_eq, isSt_real_iff_eq, isSt_real_iff_eq]; exact Eq.trans theorem isSt_inj_real {r₁ r₂ s : ℝ} (h1 : IsSt r₁ s) (h2 : IsSt r₂ s) : r₁ = r₂ := Eq.trans (eq_of_isSt_real h1) (eq_of_isSt_real h2).symm theorem isSt_iff_abs_sub_lt_delta {x : ℝ*} {r : ℝ} : IsSt x r ↔ ∀ δ : ℝ, 0 < δ → |x - ↑r| < δ := by simp only [abs_sub_lt_iff, sub_lt_iff_lt_add, IsSt, and_comm, add_comm] theorem IsSt.map {x : ℝ*} {r : ℝ} (hxr : IsSt x r) {f : ℝ → ℝ} (hf : ContinuousAt f r) : IsSt (x.map f) (f r) := by rcases ofSeq_surjective x with ⟨g, rfl⟩ exact isSt_ofSeq_iff_tendsto.2 <| hf.tendsto.comp (isSt_ofSeq_iff_tendsto.1 hxr) theorem IsSt.map₂ {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) {f : ℝ → ℝ → ℝ} (hf : ContinuousAt (Function.uncurry f) (r, s)) : IsSt (x.map₂ f y) (f r s) := by rcases ofSeq_surjective x with ⟨x, rfl⟩ rcases ofSeq_surjective y with ⟨y, rfl⟩ rw [isSt_ofSeq_iff_tendsto] at hxr hys exact isSt_ofSeq_iff_tendsto.2 <| hf.tendsto.comp (hxr.prodMk_nhds hys) theorem IsSt.add {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x + y) (r + s) := hxr.map₂ hys continuous_add.continuousAt theorem IsSt.neg {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : IsSt (-x) (-r) := hxr.map continuous_neg.continuousAt theorem IsSt.sub {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x - y) (r - s) := hxr.map₂ hys continuous_sub.continuousAt theorem IsSt.le {x y : ℝ*} {r s : ℝ} (hrx : IsSt x r) (hsy : IsSt y s) (hxy : x ≤ y) : r ≤ s := not_lt.1 fun h ↦ hxy.not_lt <| hsy.lt hrx h theorem st_le_of_le {x y : ℝ*} (hix : ¬Infinite x) (hiy : ¬Infinite y) : x ≤ y → st x ≤ st y := (isSt_st' hix).le (isSt_st' hiy) theorem lt_of_st_lt {x y : ℝ*} (hix : ¬Infinite x) (hiy : ¬Infinite y) : st x < st y → x < y := (isSt_st' hix).lt (isSt_st' hiy) /-! ### Basic lemmas about infinite -/ theorem infinitePos_def {x : ℝ*} : InfinitePos x ↔ ∀ r : ℝ, ↑r < x := Iff.rfl theorem infiniteNeg_def {x : ℝ*} : InfiniteNeg x ↔ ∀ r : ℝ, x < r := Iff.rfl theorem InfinitePos.pos {x : ℝ*} (hip : InfinitePos x) : 0 < x := hip 0 theorem InfiniteNeg.lt_zero {x : ℝ*} : InfiniteNeg x → x < 0 := fun hin => hin 0 theorem Infinite.ne_zero {x : ℝ*} (hI : Infinite x) : x ≠ 0 := hI.elim (fun hip => hip.pos.ne') fun hin => hin.lt_zero.ne theorem not_infinite_zero : ¬Infinite 0 := fun hI => hI.ne_zero rfl theorem InfiniteNeg.not_infinitePos {x : ℝ*} : InfiniteNeg x → ¬InfinitePos x := fun hn hp => (hn 0).not_lt (hp 0) theorem InfinitePos.not_infiniteNeg {x : ℝ*} (hp : InfinitePos x) : ¬InfiniteNeg x := fun hn ↦ hn.not_infinitePos hp theorem InfinitePos.neg {x : ℝ*} : InfinitePos x → InfiniteNeg (-x) := fun hp r => neg_lt.mp (hp (-r)) theorem InfiniteNeg.neg {x : ℝ*} : InfiniteNeg x → InfinitePos (-x) := fun hp r => lt_neg.mp (hp (-r)) @[simp] theorem infiniteNeg_neg {x : ℝ*} : InfiniteNeg (-x) ↔ InfinitePos x := ⟨fun hin => neg_neg x ▸ hin.neg, InfinitePos.neg⟩ @[simp] theorem infinitePos_neg {x : ℝ*} : InfinitePos (-x) ↔ InfiniteNeg x := ⟨fun hin => neg_neg x ▸ hin.neg, InfiniteNeg.neg⟩ @[simp] theorem infinite_neg {x : ℝ*} : Infinite (-x) ↔ Infinite x := or_comm.trans <| infiniteNeg_neg.or infinitePos_neg nonrec theorem Infinitesimal.not_infinite {x : ℝ*} (h : Infinitesimal x) : ¬Infinite x := h.not_infinite theorem Infinite.not_infinitesimal {x : ℝ*} (h : Infinite x) : ¬Infinitesimal x := fun h' ↦ h'.not_infinite h theorem InfinitePos.not_infinitesimal {x : ℝ*} (h : InfinitePos x) : ¬Infinitesimal x := Infinite.not_infinitesimal (Or.inl h) theorem InfiniteNeg.not_infinitesimal {x : ℝ*} (h : InfiniteNeg x) : ¬Infinitesimal x := Infinite.not_infinitesimal (Or.inr h) theorem infinitePos_iff_infinite_and_pos {x : ℝ*} : InfinitePos x ↔ Infinite x ∧ 0 < x := ⟨fun hip => ⟨Or.inl hip, hip 0⟩, fun ⟨hi, hp⟩ => hi.casesOn id fun hin => False.elim (not_lt_of_lt hp (hin 0))⟩ theorem infiniteNeg_iff_infinite_and_neg {x : ℝ*} : InfiniteNeg x ↔ Infinite x ∧ x < 0 := ⟨fun hip => ⟨Or.inr hip, hip 0⟩, fun ⟨hi, hp⟩ => hi.casesOn (fun hin => False.elim (not_lt_of_lt hp (hin 0))) fun hip => hip⟩ theorem infinitePos_iff_infinite_of_nonneg {x : ℝ*} (hp : 0 ≤ x) : InfinitePos x ↔ Infinite x := .symm <| or_iff_left fun h ↦ h.lt_zero.not_le hp theorem infinitePos_iff_infinite_of_pos {x : ℝ*} (hp : 0 < x) : InfinitePos x ↔ Infinite x := infinitePos_iff_infinite_of_nonneg hp.le theorem infiniteNeg_iff_infinite_of_neg {x : ℝ*} (hn : x < 0) : InfiniteNeg x ↔ Infinite x := .symm <| or_iff_right fun h ↦ h.pos.not_lt hn theorem infinitePos_abs_iff_infinite_abs {x : ℝ*} : InfinitePos |x| ↔ Infinite |x| := infinitePos_iff_infinite_of_nonneg (abs_nonneg _) @[simp] theorem infinite_abs_iff {x : ℝ*} : Infinite |x| ↔ Infinite x := by cases le_total 0 x <;> simp [*, abs_of_nonneg, abs_of_nonpos, infinite_neg] @[simp] theorem infinitePos_abs_iff_infinite {x : ℝ*} : InfinitePos |x| ↔ Infinite x := infinitePos_abs_iff_infinite_abs.trans infinite_abs_iff theorem infinite_iff_abs_lt_abs {x : ℝ*} : Infinite x ↔ ∀ r : ℝ, (|r| : ℝ*) < |x| := infinitePos_abs_iff_infinite.symm.trans ⟨fun hI r => coe_abs r ▸ hI |r|, fun hR r => (le_abs_self _).trans_lt (hR r)⟩ theorem infinitePos_add_not_infiniteNeg {x y : ℝ*} : InfinitePos x → ¬InfiniteNeg y → InfinitePos (x + y) := by intro hip hnin r obtain ⟨r₂, hr₂⟩ := not_forall.mp hnin convert add_lt_add_of_lt_of_le (hip (r + -r₂)) (not_lt.mp hr₂) using 1 simp theorem not_infiniteNeg_add_infinitePos {x y : ℝ*} : ¬InfiniteNeg x → InfinitePos y → InfinitePos (x + y) := fun hx hy => add_comm y x ▸ infinitePos_add_not_infiniteNeg hy hx theorem infiniteNeg_add_not_infinitePos {x y : ℝ*} : InfiniteNeg x → ¬InfinitePos y → InfiniteNeg (x + y) := by rw [← infinitePos_neg, ← infinitePos_neg, ← @infiniteNeg_neg y, neg_add] exact infinitePos_add_not_infiniteNeg theorem not_infinitePos_add_infiniteNeg {x y : ℝ*} : ¬InfinitePos x → InfiniteNeg y → InfiniteNeg (x + y) := fun hx hy => add_comm y x ▸ infiniteNeg_add_not_infinitePos hy hx theorem infinitePos_add_infinitePos {x y : ℝ*} : InfinitePos x → InfinitePos y → InfinitePos (x + y) := fun hx hy => infinitePos_add_not_infiniteNeg hx hy.not_infiniteNeg theorem infiniteNeg_add_infiniteNeg {x y : ℝ*} : InfiniteNeg x → InfiniteNeg y → InfiniteNeg (x + y) := fun hx hy => infiniteNeg_add_not_infinitePos hx hy.not_infinitePos theorem infinitePos_add_not_infinite {x y : ℝ*} : InfinitePos x → ¬Infinite y → InfinitePos (x + y) := fun hx hy => infinitePos_add_not_infiniteNeg hx (not_or.mp hy).2 theorem infiniteNeg_add_not_infinite {x y : ℝ*} : InfiniteNeg x → ¬Infinite y → InfiniteNeg (x + y) := fun hx hy => infiniteNeg_add_not_infinitePos hx (not_or.mp hy).1 theorem infinitePos_of_tendsto_top {f : ℕ → ℝ} (hf : Tendsto f atTop atTop) : InfinitePos (ofSeq f) := fun r => have hf' := tendsto_atTop_atTop.mp hf let ⟨i, hi⟩ := hf' (r + 1) have hi' : ∀ a : ℕ, f a < r + 1 → a < i := fun a => lt_imp_lt_of_le_imp_le (hi a) have hS : { a : ℕ | r < f a }ᶜ ⊆ { a : ℕ | a ≤ i } := by simp only [Set.compl_setOf, not_lt] exact fun a har => le_of_lt (hi' a (lt_of_le_of_lt har (lt_add_one _))) Germ.coe_lt.2 <| mem_hyperfilter_of_finite_compl <| (Set.finite_le_nat _).subset hS theorem infiniteNeg_of_tendsto_bot {f : ℕ → ℝ} (hf : Tendsto f atTop atBot) : InfiniteNeg (ofSeq f) := fun r => have hf' := tendsto_atTop_atBot.mp hf let ⟨i, hi⟩ := hf' (r - 1) have hi' : ∀ a : ℕ, r - 1 < f a → a < i := fun a => lt_imp_lt_of_le_imp_le (hi a) have hS : { a : ℕ | f a < r }ᶜ ⊆ { a : ℕ | a ≤ i } := by simp only [Set.compl_setOf, not_lt] exact fun a har => le_of_lt (hi' a (lt_of_lt_of_le (sub_one_lt _) har)) Germ.coe_lt.2 <| mem_hyperfilter_of_finite_compl <| (Set.finite_le_nat _).subset hS theorem not_infinite_neg {x : ℝ*} : ¬Infinite x → ¬Infinite (-x) := mt infinite_neg.mp theorem not_infinite_add {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : ¬Infinite (x + y) := have ⟨r, hr⟩ := exists_st_of_not_infinite hx have ⟨s, hs⟩ := exists_st_of_not_infinite hy not_infinite_of_exists_st <| ⟨r + s, hr.add hs⟩ theorem not_infinite_iff_exist_lt_gt {x : ℝ*} : ¬Infinite x ↔ ∃ r s : ℝ, (r : ℝ*) < x ∧ x < s := ⟨fun hni ↦ let ⟨r, hr⟩ := exists_st_of_not_infinite hni; ⟨r - 1, r + 1, hr 1 one_pos⟩, fun ⟨r, s, hr, hs⟩ hi ↦ hi.elim (fun hp ↦ (hp s).not_lt hs) (fun hn ↦ (hn r).not_lt hr)⟩ theorem not_infinite_real (r : ℝ) : ¬Infinite r := by rw [not_infinite_iff_exist_lt_gt] exact ⟨r - 1, r + 1, coe_lt_coe.2 <| sub_one_lt r, coe_lt_coe.2 <| lt_add_one r⟩ theorem Infinite.ne_real {x : ℝ*} : Infinite x → ∀ r : ℝ, x ≠ r := fun hi r hr => not_infinite_real r <| @Eq.subst _ Infinite _ _ hr hi /-! ### Facts about `st` that require some infinite machinery -/ theorem IsSt.mul {x y : ℝ*} {r s : ℝ} (hxr : IsSt x r) (hys : IsSt y s) : IsSt (x * y) (r * s) := hxr.map₂ hys continuous_mul.continuousAt --AN INFINITE LEMMA THAT REQUIRES SOME MORE ST MACHINERY theorem not_infinite_mul {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : ¬Infinite (x * y) := have ⟨_r, hr⟩ := exists_st_of_not_infinite hx have ⟨_s, hs⟩ := exists_st_of_not_infinite hy (hr.mul hs).not_infinite --- theorem st_add {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : st (x + y) = st x + st y := (isSt_st' (not_infinite_add hx hy)).unique ((isSt_st' hx).add (isSt_st' hy)) theorem st_neg (x : ℝ*) : st (-x) = -st x := by classical by_cases h : Infinite x · rw [h.st_eq, (infinite_neg.2 h).st_eq, neg_zero] · exact (isSt_st' (not_infinite_neg h)).unique (isSt_st' h).neg theorem st_mul {x y : ℝ*} (hx : ¬Infinite x) (hy : ¬Infinite y) : st (x * y) = st x * st y := have hx' := isSt_st' hx have hy' := isSt_st' hy have hxy := isSt_st' (not_infinite_mul hx hy) hxy.unique (hx'.mul hy') /-! ### Basic lemmas about infinitesimal -/ theorem infinitesimal_def {x : ℝ*} : Infinitesimal x ↔ ∀ r : ℝ, 0 < r → -(r : ℝ*) < x ∧ x < r := by simp [Infinitesimal, IsSt] theorem lt_of_pos_of_infinitesimal {x : ℝ*} : Infinitesimal x → ∀ r : ℝ, 0 < r → x < r := fun hi r hr => ((infinitesimal_def.mp hi) r hr).2 theorem lt_neg_of_pos_of_infinitesimal {x : ℝ*} : Infinitesimal x → ∀ r : ℝ, 0 < r → -↑r < x := fun hi r hr => ((infinitesimal_def.mp hi) r hr).1 theorem gt_of_neg_of_infinitesimal {x : ℝ*} (hi : Infinitesimal x) (r : ℝ) (hr : r < 0) : ↑r < x := neg_neg r ▸ (infinitesimal_def.1 hi (-r) (neg_pos.2 hr)).1 theorem abs_lt_real_iff_infinitesimal {x : ℝ*} : Infinitesimal x ↔ ∀ r : ℝ, r ≠ 0 → |x| < |↑r| := ⟨fun hi r hr ↦ abs_lt.mpr (coe_abs r ▸ infinitesimal_def.mp hi |r| (abs_pos.2 hr)), fun hR ↦ infinitesimal_def.mpr fun r hr => abs_lt.mp <| (abs_of_pos <| coe_pos.2 hr) ▸ hR r <| hr.ne'⟩ theorem infinitesimal_zero : Infinitesimal 0 := isSt_refl_real 0 theorem Infinitesimal.eq_zero {r : ℝ} : Infinitesimal r → r = 0 := eq_of_isSt_real @[simp] theorem infinitesimal_real_iff {r : ℝ} : Infinitesimal r ↔ r = 0 := isSt_real_iff_eq nonrec theorem Infinitesimal.add {x y : ℝ*} (hx : Infinitesimal x) (hy : Infinitesimal y) : Infinitesimal (x + y) := by simpa only [add_zero] using hx.add hy nonrec theorem Infinitesimal.neg {x : ℝ*} (hx : Infinitesimal x) : Infinitesimal (-x) := by simpa only [neg_zero] using hx.neg @[simp] theorem infinitesimal_neg {x : ℝ*} : Infinitesimal (-x) ↔ Infinitesimal x := ⟨fun h => neg_neg x ▸ h.neg, Infinitesimal.neg⟩ nonrec theorem Infinitesimal.mul {x y : ℝ*} (hx : Infinitesimal x) (hy : Infinitesimal y) : Infinitesimal (x * y) := by simpa only [mul_zero] using hx.mul hy theorem infinitesimal_of_tendsto_zero {f : ℕ → ℝ} (h : Tendsto f atTop (𝓝 0)) : Infinitesimal (ofSeq f) := isSt_of_tendsto h theorem infinitesimal_epsilon : Infinitesimal ε := infinitesimal_of_tendsto_zero tendsto_inverse_atTop_nhds_zero_nat theorem not_real_of_infinitesimal_ne_zero (x : ℝ*) : Infinitesimal x → x ≠ 0 → ∀ r : ℝ, x ≠ r := fun hi hx r hr => hx <| hr.trans <| coe_eq_zero.2 <| IsSt.unique (hr.symm ▸ isSt_refl_real r : IsSt x r) hi theorem IsSt.infinitesimal_sub {x : ℝ*} {r : ℝ} (hxr : IsSt x r) : Infinitesimal (x - ↑r) := by simpa only [sub_self] using hxr.sub (isSt_refl_real r) theorem infinitesimal_sub_st {x : ℝ*} (hx : ¬Infinite x) : Infinitesimal (x - ↑(st x)) := (isSt_st' hx).infinitesimal_sub theorem infinitePos_iff_infinitesimal_inv_pos {x : ℝ*} : InfinitePos x ↔ Infinitesimal x⁻¹ ∧ 0 < x⁻¹ := ⟨fun hip => ⟨infinitesimal_def.mpr fun r hr => ⟨lt_trans (coe_lt_coe.2 (neg_neg_of_pos hr)) (inv_pos.2 (hip 0)), inv_lt_of_inv_lt₀ (coe_lt_coe.2 hr) (by convert hip r⁻¹)⟩, inv_pos.2 <| hip 0⟩, fun ⟨hi, hp⟩ r => @_root_.by_cases (r = 0) (↑r < x) (fun h => Eq.substr h (inv_pos.mp hp)) fun h => lt_of_le_of_lt (coe_le_coe.2 (le_abs_self r)) ((inv_lt_inv₀ (inv_pos.mp hp) (coe_lt_coe.2 (abs_pos.2 h))).mp ((infinitesimal_def.mp hi) |r|⁻¹ (inv_pos.2 (abs_pos.2 h))).2)⟩ theorem infiniteNeg_iff_infinitesimal_inv_neg {x : ℝ*} : InfiniteNeg x ↔ Infinitesimal x⁻¹ ∧ x⁻¹ < 0 := by rw [← infinitePos_neg, infinitePos_iff_infinitesimal_inv_pos, inv_neg, neg_pos, infinitesimal_neg] theorem infinitesimal_inv_of_infinite {x : ℝ*} : Infinite x → Infinitesimal x⁻¹ := fun hi => Or.casesOn hi (fun hip => (infinitePos_iff_infinitesimal_inv_pos.mp hip).1) fun hin => (infiniteNeg_iff_infinitesimal_inv_neg.mp hin).1 theorem infinite_of_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) (hi : Infinitesimal x⁻¹) : Infinite x := by rcases lt_or_gt_of_ne h0 with hn | hp · exact Or.inr (infiniteNeg_iff_infinitesimal_inv_neg.mpr ⟨hi, inv_lt_zero.mpr hn⟩) · exact Or.inl (infinitePos_iff_infinitesimal_inv_pos.mpr ⟨hi, inv_pos.mpr hp⟩) theorem infinite_iff_infinitesimal_inv {x : ℝ*} (h0 : x ≠ 0) : Infinite x ↔ Infinitesimal x⁻¹ := ⟨infinitesimal_inv_of_infinite, infinite_of_infinitesimal_inv h0⟩ theorem infinitesimal_pos_iff_infinitePos_inv {x : ℝ*} : InfinitePos x⁻¹ ↔ Infinitesimal x ∧ 0 < x := infinitePos_iff_infinitesimal_inv_pos.trans <| by rw [inv_inv] theorem infinitesimal_neg_iff_infiniteNeg_inv {x : ℝ*} : InfiniteNeg x⁻¹ ↔ Infinitesimal x ∧ x < 0 := infiniteNeg_iff_infinitesimal_inv_neg.trans <| by rw [inv_inv] theorem infinitesimal_iff_infinite_inv {x : ℝ*} (h : x ≠ 0) : Infinitesimal x ↔ Infinite x⁻¹ := Iff.trans (by rw [inv_inv]) (infinite_iff_infinitesimal_inv (inv_ne_zero h)).symm /-! ### `Hyperreal.st` stuff that requires infinitesimal machinery -/ theorem IsSt.inv {x : ℝ*} {r : ℝ} (hi : ¬Infinitesimal x) (hr : IsSt x r) : IsSt x⁻¹ r⁻¹ := hr.map <| continuousAt_inv₀ <| by rintro rfl; exact hi hr theorem st_inv (x : ℝ*) : st x⁻¹ = (st x)⁻¹ := by by_cases h0 : x = 0 · rw [h0, inv_zero, ← coe_zero, st_id_real, inv_zero] by_cases h1 : Infinitesimal x · rw [((infinitesimal_iff_infinite_inv h0).mp h1).st_eq, h1.st_eq, inv_zero] by_cases h2 : Infinite x · rw [(infinitesimal_inv_of_infinite h2).st_eq, h2.st_eq, inv_zero] exact ((isSt_st' h2).inv h1).st_eq /-! ### Infinite stuff that requires infinitesimal machinery -/ theorem infinitePos_omega : InfinitePos ω := infinitePos_iff_infinitesimal_inv_pos.mpr ⟨infinitesimal_epsilon, epsilon_pos⟩ theorem infinite_omega : Infinite ω := (infinite_iff_infinitesimal_inv omega_ne_zero).mpr infinitesimal_epsilon theorem infinitePos_mul_of_infinitePos_not_infinitesimal_pos {x y : ℝ*} : InfinitePos x → ¬Infinitesimal y → 0 < y → InfinitePos (x * y) := fun hx hy₁ hy₂ r => by have hy₁' := not_forall.mp (mt infinitesimal_def.2 hy₁) let ⟨r₁, hy₁''⟩ := hy₁' have hyr : 0 < r₁ ∧ ↑r₁ ≤ y := by rwa [Classical.not_imp, ← abs_lt, not_lt, abs_of_pos hy₂] at hy₁'' rw [← div_mul_cancel₀ r (ne_of_gt hyr.1), coe_mul] exact mul_lt_mul (hx (r / r₁)) hyr.2 (coe_lt_coe.2 hyr.1) (le_of_lt (hx 0)) theorem infinitePos_mul_of_not_infinitesimal_pos_infinitePos {x y : ℝ*} : ¬Infinitesimal x → 0 < x → InfinitePos y → InfinitePos (x * y) := fun hx hp hy => mul_comm y x ▸ infinitePos_mul_of_infinitePos_not_infinitesimal_pos hy hx hp theorem infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg {x y : ℝ*} : InfiniteNeg x → ¬Infinitesimal y → y < 0 → InfinitePos (x * y) := by rw [← infinitePos_neg, ← neg_pos, ← neg_mul_neg, ← infinitesimal_neg] exact infinitePos_mul_of_infinitePos_not_infinitesimal_pos theorem infinitePos_mul_of_not_infinitesimal_neg_infiniteNeg {x y : ℝ*} : ¬Infinitesimal x → x < 0 → InfiniteNeg y → InfinitePos (x * y) := fun hx hp hy => mul_comm y x ▸ infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg hy hx hp theorem infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg {x y : ℝ*} : InfinitePos x → ¬Infinitesimal y → y < 0 → InfiniteNeg (x * y) := by rw [← infinitePos_neg, ← neg_pos, neg_mul_eq_mul_neg, ← infinitesimal_neg] exact infinitePos_mul_of_infinitePos_not_infinitesimal_pos theorem infiniteNeg_mul_of_not_infinitesimal_neg_infinitePos {x y : ℝ*} : ¬Infinitesimal x → x < 0 → InfinitePos y → InfiniteNeg (x * y) := fun hx hp hy => mul_comm y x ▸ infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg hy hx hp theorem infiniteNeg_mul_of_infiniteNeg_not_infinitesimal_pos {x y : ℝ*} : InfiniteNeg x → ¬Infinitesimal y → 0 < y → InfiniteNeg (x * y) := by rw [← infinitePos_neg, ← infinitePos_neg, neg_mul_eq_neg_mul] exact infinitePos_mul_of_infinitePos_not_infinitesimal_pos theorem infiniteNeg_mul_of_not_infinitesimal_pos_infiniteNeg {x y : ℝ*} : ¬Infinitesimal x → 0 < x → InfiniteNeg y → InfiniteNeg (x * y) := fun hx hp hy => by rw [mul_comm]; exact infiniteNeg_mul_of_infiniteNeg_not_infinitesimal_pos hy hx hp theorem infinitePos_mul_infinitePos {x y : ℝ*} : InfinitePos x → InfinitePos y → InfinitePos (x * y) := fun hx hy => infinitePos_mul_of_infinitePos_not_infinitesimal_pos hx hy.not_infinitesimal (hy 0) theorem infiniteNeg_mul_infiniteNeg {x y : ℝ*} : InfiniteNeg x → InfiniteNeg y → InfinitePos (x * y) := fun hx hy => infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg hx hy.not_infinitesimal (hy 0) theorem infinitePos_mul_infiniteNeg {x y : ℝ*} : InfinitePos x → InfiniteNeg y → InfiniteNeg (x * y) := fun hx hy => infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg hx hy.not_infinitesimal (hy 0) theorem infiniteNeg_mul_infinitePos {x y : ℝ*} : InfiniteNeg x → InfinitePos y → InfiniteNeg (x * y) := fun hx hy => infiniteNeg_mul_of_infiniteNeg_not_infinitesimal_pos hx hy.not_infinitesimal (hy 0) theorem infinite_mul_of_infinite_not_infinitesimal {x y : ℝ*} : Infinite x → ¬Infinitesimal y → Infinite (x * y) := fun hx hy => have h0 : y < 0 ∨ 0 < y := lt_or_gt_of_ne fun H0 => hy (Eq.substr H0 (isSt_refl_real 0)) hx.elim (h0.elim (fun H0 Hx => Or.inr (infiniteNeg_mul_of_infinitePos_not_infinitesimal_neg Hx hy H0)) fun H0 Hx => Or.inl (infinitePos_mul_of_infinitePos_not_infinitesimal_pos Hx hy H0)) (h0.elim (fun H0 Hx => Or.inl (infinitePos_mul_of_infiniteNeg_not_infinitesimal_neg Hx hy H0)) fun H0 Hx => Or.inr (infiniteNeg_mul_of_infiniteNeg_not_infinitesimal_pos Hx hy H0)) theorem infinite_mul_of_not_infinitesimal_infinite {x y : ℝ*} : ¬Infinitesimal x → Infinite y → Infinite (x * y) := fun hx hy => by rw [mul_comm]; exact infinite_mul_of_infinite_not_infinitesimal hy hx theorem Infinite.mul {x y : ℝ*} : Infinite x → Infinite y → Infinite (x * y) := fun hx hy => infinite_mul_of_infinite_not_infinitesimal hx hy.not_infinitesimal end Hyperreal /- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: restore `positivity` plugin namespace Tactic open Positivity private theorem hyperreal_coe_ne_zero {r : ℝ} : r ≠ 0 → (r : ℝ*) ≠ 0 := Hyperreal.coe_ne_zero.2 private theorem hyperreal_coe_nonneg {r : ℝ} : 0 ≤ r → 0 ≤ (r : ℝ*) := Hyperreal.coe_nonneg.2
private theorem hyperreal_coe_pos {r : ℝ} : 0 < r → 0 < (r : ℝ*) := Hyperreal.coe_pos.2
Mathlib/Data/Real/Hyperreal.lean
750
752
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov, Moritz Doll -/ import Mathlib.LinearAlgebra.Prod /-! # Partially defined linear maps A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. We define a `SemilatticeInf` with `OrderBot` instance on this, and define three operations: * `mkSpanSingleton` defines a partial linear map defined on the span of a singleton. * `sup` takes two partial linear maps `f`, `g` that agree on the intersection of their domains, and returns the unique partial linear map on `f.domain ⊔ g.domain` that extends both `f` and `g`. * `sSup` takes a `DirectedOn (· ≤ ·)` set of partial linear maps, and returns the unique partial linear map on the `sSup` of their domains that extends all these maps. Moreover, we define * `LinearPMap.graph` is the graph of the partial linear map viewed as a submodule of `E × F`. Partially defined maps are currently used in `Mathlib` to prove Hahn-Banach theorem and its variations. Namely, `LinearPMap.sSup` implies that every chain of `LinearPMap`s is bounded above. They are also the basis for the theory of unbounded operators. -/ universe u v w /-- A `LinearPMap R E F` or `E →ₗ.[R] F` is a linear map from a submodule of `E` to `F`. -/ structure LinearPMap (R : Type u) [Ring R] (E : Type v) [AddCommGroup E] [Module R E] (F : Type w) [AddCommGroup F] [Module R F] where domain : Submodule R E toFun : domain →ₗ[R] F @[inherit_doc] notation:25 E " →ₗ.[" R:25 "] " F:0 => LinearPMap R E F variable {R : Type*} [Ring R] {E : Type*} [AddCommGroup E] [Module R E] {F : Type*} [AddCommGroup F] [Module R F] {G : Type*} [AddCommGroup G] [Module R G] namespace LinearPMap open Submodule @[coe] def toFun' (f : E →ₗ.[R] F) : f.domain → F := f.toFun instance : CoeFun (E →ₗ.[R] F) fun f : E →ₗ.[R] F => f.domain → F := ⟨toFun'⟩ @[simp] theorem toFun_eq_coe (f : E →ₗ.[R] F) (x : f.domain) : f.toFun x = f x := rfl @[ext (iff := false)] theorem ext {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩) : f = g := by rcases f with ⟨f_dom, f⟩ rcases g with ⟨g_dom, g⟩ obtain rfl : f_dom = g_dom := h congr apply LinearMap.ext intro x apply h' /-- A dependent version of `ext`. -/ theorem dExt {f g : E →ₗ.[R] F} (h : f.domain = g.domain) (h' : ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y) : f = g := ext h fun _ _ _ ↦ h' rfl @[simp] theorem map_zero (f : E →ₗ.[R] F) : f 0 = 0 := f.toFun.map_zero theorem ext_iff {f g : E →ₗ.[R] F} : f = g ↔ f.domain = g.domain ∧ ∀ ⦃x : E⦄ ⦃hf : x ∈ f.domain⦄ ⦃hg : x ∈ g.domain⦄, f ⟨x, hf⟩ = g ⟨x, hg⟩ := ⟨by rintro rfl; simp, fun ⟨deq, feq⟩ ↦ ext deq feq⟩ theorem dExt_iff {f g : E →ₗ.[R] F} : f = g ↔ ∃ _domain_eq : f.domain = g.domain, ∀ ⦃x : f.domain⦄ ⦃y : g.domain⦄ (_h : (x : E) = y), f x = g y := ⟨fun EQ => EQ ▸ ⟨rfl, fun x y h => by congr exact mod_cast h⟩, fun ⟨deq, feq⟩ => dExt deq feq⟩ theorem ext' {s : Submodule R E} {f g : s →ₗ[R] F} (h : f = g) : mk s f = mk s g := h ▸ rfl theorem map_add (f : E →ₗ.[R] F) (x y : f.domain) : f (x + y) = f x + f y := f.toFun.map_add x y theorem map_neg (f : E →ₗ.[R] F) (x : f.domain) : f (-x) = -f x := f.toFun.map_neg x theorem map_sub (f : E →ₗ.[R] F) (x y : f.domain) : f (x - y) = f x - f y := f.toFun.map_sub x y theorem map_smul (f : E →ₗ.[R] F) (c : R) (x : f.domain) : f (c • x) = c • f x := f.toFun.map_smul c x @[simp] theorem mk_apply (p : Submodule R E) (f : p →ₗ[R] F) (x : p) : mk p f x = f x := rfl /-- The unique `LinearPMap` on `R ∙ x` that sends `x` to `y`. This version works for modules over rings, and requires a proof of `∀ c, c • x = 0 → c • y = 0`. -/ noncomputable def mkSpanSingleton' (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : E →ₗ.[R] F where domain := R ∙ x toFun := have H : ∀ c₁ c₂ : R, c₁ • x = c₂ • x → c₁ • y = c₂ • y := by intro c₁ c₂ h rw [← sub_eq_zero, ← sub_smul] at h ⊢ exact H _ h { toFun z := Classical.choose (mem_span_singleton.1 z.prop) • y map_add' y z := by rw [← add_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [add_smul, sub_smul, this, ← coe_add] map_smul' c z := by rw [smul_smul, H] have (w : R ∙ x) := Classical.choose_spec (mem_span_singleton.1 w.prop) simp only [mul_smul, this] apply coe_smul } @[simp] theorem domain_mkSpanSingleton (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) : (mkSpanSingleton' x y H).domain = R ∙ x := rfl @[simp] theorem mkSpanSingleton'_apply (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (c : R) (h) : mkSpanSingleton' x y H ⟨c • x, h⟩ = c • y := by dsimp [mkSpanSingleton'] rw [← sub_eq_zero, ← sub_smul] apply H simp only [sub_smul, one_smul, sub_eq_zero] apply Classical.choose_spec (mem_span_singleton.1 h) @[simp] theorem mkSpanSingleton'_apply_self (x : E) (y : F) (H : ∀ c : R, c • x = 0 → c • y = 0) (h) : mkSpanSingleton' x y H ⟨x, h⟩ = y := by
conv_rhs => rw [← one_smul R y] rw [← mkSpanSingleton'_apply x y H 1 ?_] · congr rw [one_smul] · rwa [one_smul] /-- The unique `LinearPMap` on `span R {x}` that sends a non-zero vector `x` to `y`.
Mathlib/LinearAlgebra/LinearPMap.lean
152
158
/- 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 -/ import Mathlib.Logic.Relator import Mathlib.Tactic.Use import Mathlib.Tactic.MkIffOfInductiveProp import Mathlib.Tactic.SimpRw import Mathlib.Logic.Basic import Mathlib.Order.Defs.Unbundled /-! # Relation closures This file defines the reflexive, transitive, reflexive transitive and equivalence closures of relations and proves some basic results on them. Note that this is about unbundled relations, that is terms of types of the form `α → β → Prop`. For the bundled version, see `Rel`. ## Definitions * `Relation.ReflGen`: Reflexive closure. `ReflGen r` relates everything `r` related, plus for all `a` it relates `a` with itself. So `ReflGen r a b ↔ r a b ∨ a = b`. * `Relation.TransGen`: Transitive closure. `TransGen r` relates everything `r` related transitively. So `TransGen r a b ↔ ∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b`. * `Relation.ReflTransGen`: Reflexive transitive closure. `ReflTransGen r` relates everything `r` related transitively, plus for all `a` it relates `a` with itself. So `ReflTransGen r a b ↔ (∃ x₀ ... xₙ, r a x₀ ∧ r x₀ x₁ ∧ ... ∧ r xₙ b) ∨ a = b`. It is the same as the reflexive closure of the transitive closure, or the transitive closure of the reflexive closure. In terms of rewriting systems, this means that `a` can be rewritten to `b` in a number of rewrites. * `Relation.EqvGen`: Equivalence closure. `EqvGen r` relates everything `ReflTransGen r` relates, plus for all related pairs it relates them in the opposite order. * `Relation.Comp`: Relation composition. We provide notation `∘r`. For `r : α → β → Prop` and `s : β → γ → Prop`, `r ∘r s`relates `a : α` and `c : γ` iff there exists `b : β` that's related to both. * `Relation.Map`: Image of a relation under a pair of maps. For `r : α → β → Prop`, `f : α → γ`, `g : β → δ`, `Map r f g` is the relation `γ → δ → Prop` relating `f a` and `g b` for all `a`, `b` related by `r`. * `Relation.Join`: Join of a relation. For `r : α → α → Prop`, `Join r a b ↔ ∃ c, r a c ∧ r b c`. In terms of rewriting systems, this means that `a` and `b` can be rewritten to the same term. -/ open Function variable {α β γ δ ε ζ : Type*} section NeImp variable {r : α → α → Prop} theorem IsRefl.reflexive [IsRefl α r] : Reflexive r := fun x ↦ IsRefl.refl x /-- To show a reflexive relation `r : α → α → Prop` holds over `x y : α`, it suffices to show it holds when `x ≠ y`. -/ theorem Reflexive.rel_of_ne_imp (h : Reflexive r) {x y : α} (hr : x ≠ y → r x y) : r x y := by by_cases hxy : x = y · exact hxy ▸ h x · exact hr hxy /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. -/ theorem Reflexive.ne_imp_iff (h : Reflexive r) {x y : α} : x ≠ y → r x y ↔ r x y := ⟨h.rel_of_ne_imp, fun hr _ ↦ hr⟩ /-- If a reflexive relation `r : α → α → Prop` holds over `x y : α`, then it holds whether or not `x ≠ y`. Unlike `Reflexive.ne_imp_iff`, this uses `[IsRefl α r]`. -/ theorem reflexive_ne_imp_iff [IsRefl α r] {x y : α} : x ≠ y → r x y ↔ r x y := IsRefl.reflexive.ne_imp_iff protected theorem Symmetric.iff (H : Symmetric r) (x y : α) : r x y ↔ r y x := ⟨fun h ↦ H h, fun h ↦ H h⟩ theorem Symmetric.flip_eq (h : Symmetric r) : flip r = r := funext₂ fun _ _ ↦ propext <| h.iff _ _ theorem Symmetric.swap_eq : Symmetric r → swap r = r := Symmetric.flip_eq theorem flip_eq_iff : flip r = r ↔ Symmetric r := ⟨fun h _ _ ↦ (congr_fun₂ h _ _).mp, Symmetric.flip_eq⟩ theorem swap_eq_iff : swap r = r ↔ Symmetric r := flip_eq_iff end NeImp section Comap variable {r : β → β → Prop} theorem Reflexive.comap (h : Reflexive r) (f : α → β) : Reflexive (r on f) := fun a ↦ h (f a) theorem Symmetric.comap (h : Symmetric r) (f : α → β) : Symmetric (r on f) := fun _ _ hab ↦ h hab theorem Transitive.comap (h : Transitive r) (f : α → β) : Transitive (r on f) := fun _ _ _ hab hbc ↦ h hab hbc theorem Equivalence.comap (h : Equivalence r) (f : α → β) : Equivalence (r on f) := ⟨fun a ↦ h.refl (f a), h.symm, h.trans⟩ end Comap namespace Relation section Comp variable {r : α → β → Prop} {p : β → γ → Prop} {q : γ → δ → Prop} /-- The composition of two relations, yielding a new relation. The result relates a term of `α` and a term of `γ` if there is an intermediate term of `β` related to both. -/ def Comp (r : α → β → Prop) (p : β → γ → Prop) (a : α) (c : γ) : Prop := ∃ b, r a b ∧ p b c @[inherit_doc] local infixr:80 " ∘r " => Relation.Comp @[simp] theorem comp_eq_fun (f : γ → β) : r ∘r (· = f ·) = (r · <| f ·) := by ext x y simp [Comp] @[simp] theorem comp_eq : r ∘r (· = ·) = r := comp_eq_fun .. @[simp] theorem fun_eq_comp (f : γ → α) : (f · = ·) ∘r r = (r <| f ·) := by ext x y simp [Comp] @[simp] theorem eq_comp : (· = ·) ∘r r = r := fun_eq_comp .. @[simp] theorem iff_comp {r : Prop → α → Prop} : (· ↔ ·) ∘r r = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, eq_comp] @[simp] theorem comp_iff {r : α → Prop → Prop} : r ∘r (· ↔ ·) = r := by have : (· ↔ ·) = (· = ·) := by funext a b; exact iff_eq_eq rw [this, comp_eq] theorem comp_assoc : (r ∘r p) ∘r q = r ∘r p ∘r q := by funext a d apply propext constructor · exact fun ⟨c, ⟨b, hab, hbc⟩, hcd⟩ ↦ ⟨b, hab, c, hbc, hcd⟩ · exact fun ⟨b, hab, c, hbc, hcd⟩ ↦ ⟨c, ⟨b, hab, hbc⟩, hcd⟩ theorem flip_comp : flip (r ∘r p) = flip p ∘r flip r := by funext c a apply propext constructor · exact fun ⟨b, hab, hbc⟩ ↦ ⟨b, hbc, hab⟩ · exact fun ⟨b, hbc, hab⟩ ↦ ⟨b, hab, hbc⟩ end Comp section Fibration variable (rα : α → α → Prop) (rβ : β → β → Prop) (f : α → β) /-- A function `f : α → β` is a fibration between the relation `rα` and `rβ` if for all `a : α` and `b : β`, whenever `b : β` and `f a` are related by `rβ`, `b` is the image of some `a' : α` under `f`, and `a'` and `a` are related by `rα`. -/ def Fibration := ∀ ⦃a b⦄, rβ b (f a) → ∃ a', rα a' a ∧ f a' = b variable {rα rβ} /-- If `f : α → β` is a fibration between relations `rα` and `rβ`, and `a : α` is accessible under `rα`, then `f a` is accessible under `rβ`. -/ theorem _root_.Acc.of_fibration (fib : Fibration rα rβ f) {a} (ha : Acc rα a) : Acc rβ (f a) := by induction ha with | intro a _ ih => ?_ refine Acc.intro (f a) fun b hr ↦ ?_ obtain ⟨a', hr', rfl⟩ := fib hr exact ih a' hr' theorem _root_.Acc.of_downward_closed (dc : ∀ {a b}, rβ b (f a) → ∃ c, f c = b) (a : α) (ha : Acc (InvImage rβ f) a) : Acc rβ (f a) := ha.of_fibration f fun a _ h ↦ let ⟨a', he⟩ := dc h ⟨a', by simp_all [InvImage], he⟩ end Fibration section Map variable {r : α → β → Prop} {f : α → γ} {g : β → δ} {c : γ} {d : δ} /-- The map of a relation `r` through a pair of functions pushes the relation to the codomains of the functions. The resulting relation is defined by having pairs of terms related if they have preimages related by `r`. -/ protected def Map (r : α → β → Prop) (f : α → γ) (g : β → δ) : γ → δ → Prop := fun c d ↦ ∃ a b, r a b ∧ f a = c ∧ g b = d lemma map_apply : Relation.Map r f g c d ↔ ∃ a b, r a b ∧ f a = c ∧ g b = d := Iff.rfl @[simp] lemma map_map (r : α → β → Prop) (f₁ : α → γ) (g₁ : β → δ) (f₂ : γ → ε) (g₂ : δ → ζ) : Relation.Map (Relation.Map r f₁ g₁) f₂ g₂ = Relation.Map r (f₂ ∘ f₁) (g₂ ∘ g₁) := by ext a b simp_rw [Relation.Map, Function.comp_apply, ← exists_and_right, @exists_comm γ, @exists_comm δ] refine exists₂_congr fun a b ↦ ⟨?_, fun h ↦ ⟨_, _, ⟨⟨h.1, rfl, rfl⟩, h.2⟩⟩⟩ rintro ⟨_, _, ⟨hab, rfl, rfl⟩, h⟩ exact ⟨hab, h⟩ @[simp] lemma map_apply_apply (hf : Injective f) (hg : Injective g) (r : α → β → Prop) (a : α) (b : β) : Relation.Map r f g (f a) (g b) ↔ r a b := by simp [Relation.Map, hf.eq_iff, hg.eq_iff] @[simp] lemma map_id_id (r : α → β → Prop) : Relation.Map r id id = r := by ext; simp [Relation.Map] instance [Decidable (∃ a b, r a b ∧ f a = c ∧ g b = d)] : Decidable (Relation.Map r f g c d) := ‹Decidable _› lemma map_reflexive {r : α → α → Prop} (hr : Reflexive r) {f : α → β} (hf : f.Surjective) : Reflexive (Relation.Map r f f) := by intro x obtain ⟨y, rfl⟩ := hf x exact ⟨y, y, hr y, rfl, rfl⟩ lemma map_symmetric {r : α → α → Prop} (hr : Symmetric r) (f : α → β) : Symmetric (Relation.Map r f f) := by rintro _ _ ⟨x, y, hxy, rfl, rfl⟩; exact ⟨_, _, hr hxy, rfl, rfl⟩ lemma map_transitive {r : α → α → Prop} (hr : Transitive r) {f : α → β} (hf : ∀ x y, f x = f y → r x y) : Transitive (Relation.Map r f f) := by rintro _ _ _ ⟨x, y, hxy, rfl, rfl⟩ ⟨y', z, hyz, hy, rfl⟩ exact ⟨x, z, hr hxy <| hr (hf _ _ hy.symm) hyz, rfl, rfl⟩ lemma map_equivalence {r : α → α → Prop} (hr : Equivalence r) (f : α → β) (hf : f.Surjective) (hf_ker : ∀ x y, f x = f y → r x y) : Equivalence (Relation.Map r f f) where refl := map_reflexive hr.reflexive hf symm := @(map_symmetric hr.symmetric _) trans := @(map_transitive hr.transitive hf_ker) -- TODO: state this using `≤`, after adjusting imports. lemma map_mono {r s : α → β → Prop} {f : α → γ} {g : β → δ} (h : ∀ x y, r x y → s x y) : ∀ x y, Relation.Map r f g x y → Relation.Map s f g x y := fun _ _ ⟨x, y, hxy, hx, hy⟩ => ⟨x, y, h _ _ hxy, hx, hy⟩ end Map variable {r : α → α → Prop} {a b c : α} /-- `ReflTransGen r`: reflexive transitive closure of `r` -/ @[mk_iff ReflTransGen.cases_tail_iff] inductive ReflTransGen (r : α → α → Prop) (a : α) : α → Prop | refl : ReflTransGen r a a | tail {b c} : ReflTransGen r a b → r b c → ReflTransGen r a c attribute [refl] ReflTransGen.refl /-- `ReflGen r`: reflexive closure of `r` -/ @[mk_iff] inductive ReflGen (r : α → α → Prop) (a : α) : α → Prop | refl : ReflGen r a a | single {b} : r a b → ReflGen r a b variable (r) in /-- `EqvGen r`: equivalence closure of `r`. -/ @[mk_iff] inductive EqvGen : α → α → Prop | rel x y : r x y → EqvGen x y | refl x : EqvGen x x | symm x y : EqvGen x y → EqvGen y x | trans x y z : EqvGen x y → EqvGen y z → EqvGen x z attribute [mk_iff] TransGen attribute [refl] ReflGen.refl namespace ReflGen theorem to_reflTransGen : ∀ {a b}, ReflGen r a b → ReflTransGen r a b | a, _, refl => by rfl | _, _, single h => ReflTransGen.tail ReflTransGen.refl h theorem mono {p : α → α → Prop} (hp : ∀ a b, r a b → p a b) : ∀ {a b}, ReflGen r a b → ReflGen p a b | a, _, ReflGen.refl => by rfl | a, b, single h => single (hp a b h) instance : IsRefl α (ReflGen r) := ⟨@refl α r⟩ end ReflGen namespace ReflTransGen @[trans] theorem trans (hab : ReflTransGen r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by induction hbc with | refl => assumption | tail _ hcd hac => exact hac.tail hcd theorem single (hab : r a b) : ReflTransGen r a b := refl.tail hab theorem head (hab : r a b) (hbc : ReflTransGen r b c) : ReflTransGen r a c := by induction hbc with | refl => exact refl.tail hab | tail _ hcd hac => exact hac.tail hcd theorem symmetric (h : Symmetric r) : Symmetric (ReflTransGen r) := by intro x y h induction h with | refl => rfl | tail _ b c => apply Relation.ReflTransGen.head (h b) c theorem cases_tail : ReflTransGen r a b → b = a ∨ ∃ c, ReflTransGen r a c ∧ r c b := (cases_tail_iff r a b).1 @[elab_as_elim] theorem head_induction_on {P : ∀ a : α, ReflTransGen r a b → Prop} {a : α} (h : ReflTransGen r a b) (refl : P b refl) (head : ∀ {a c} (h' : r a c) (h : ReflTransGen r c b), P c h → P a (h.head h')) : P a h := by induction h with | refl => exact refl | @tail b c _ hbc ih => apply ih · exact head hbc _ refl · exact fun h1 h2 ↦ head h1 (h2.tail hbc) @[elab_as_elim] theorem trans_induction_on {P : ∀ {a b : α}, ReflTransGen r a b → Prop} {a b : α} (h : ReflTransGen r a b) (ih₁ : ∀ a, @P a a refl) (ih₂ : ∀ {a b} (h : r a b), P (single h)) (ih₃ : ∀ {a b c} (h₁ : ReflTransGen r a b) (h₂ : ReflTransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) : P h := by induction h with | refl => exact ih₁ a | tail hab hbc ih => exact ih₃ hab (single hbc) ih (ih₂ hbc) theorem cases_head (h : ReflTransGen r a b) : a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by induction h using Relation.ReflTransGen.head_induction_on · left rfl · right exact ⟨_, by assumption, by assumption⟩ theorem cases_head_iff : ReflTransGen r a b ↔ a = b ∨ ∃ c, r a c ∧ ReflTransGen r c b := by use cases_head rintro (rfl | ⟨c, hac, hcb⟩) · rfl · exact head hac hcb theorem total_of_right_unique (U : Relator.RightUnique r) (ab : ReflTransGen r a b) (ac : ReflTransGen r a c) : ReflTransGen r b c ∨ ReflTransGen r c b := by induction ab with | refl => exact Or.inl ac | tail _ bd IH => rcases IH with (IH | IH) · rcases cases_head IH with (rfl | ⟨e, be, ec⟩) · exact Or.inr (single bd) · cases U bd be exact Or.inl ec · exact Or.inr (IH.tail bd) end ReflTransGen namespace TransGen theorem to_reflTransGen {a b} (h : TransGen r a b) : ReflTransGen r a b := by induction h with | single h => exact ReflTransGen.single h | tail _ bc ab => exact ReflTransGen.tail ab bc theorem trans_left (hab : TransGen r a b) (hbc : ReflTransGen r b c) : TransGen r a c := by induction hbc with | refl => assumption | tail _ hcd hac => exact hac.tail hcd instance : Trans (TransGen r) (ReflTransGen r) (TransGen r) := ⟨trans_left⟩ attribute [trans] trans instance : Trans (TransGen r) (TransGen r) (TransGen r) := ⟨trans⟩ theorem head' (hab : r a b) (hbc : ReflTransGen r b c) : TransGen r a c := trans_left (single hab) hbc theorem tail' (hab : ReflTransGen r a b) (hbc : r b c) : TransGen r a c := by induction hab generalizing c with | refl => exact single hbc | tail _ hdb IH => exact tail (IH hdb) hbc theorem head (hab : r a b) (hbc : TransGen r b c) : TransGen r a c := head' hab hbc.to_reflTransGen @[elab_as_elim] theorem head_induction_on {P : ∀ a : α, TransGen r a b → Prop} {a : α} (h : TransGen r a b) (base : ∀ {a} (h : r a b), P a (single h)) (ih : ∀ {a c} (h' : r a c) (h : TransGen r c b), P c h → P a (h.head h')) : P a h := by induction h with | single h => exact base h | @tail b c _ hbc h_ih => apply h_ih · exact fun h ↦ ih h (single hbc) (base hbc) · exact fun hab hbc ↦ ih hab _ @[elab_as_elim] theorem trans_induction_on {P : ∀ {a b : α}, TransGen r a b → Prop} {a b : α} (h : TransGen r a b) (base : ∀ {a b} (h : r a b), P (single h)) (ih : ∀ {a b c} (h₁ : TransGen r a b) (h₂ : TransGen r b c), P h₁ → P h₂ → P (h₁.trans h₂)) : P h := by induction h with | single h => exact base h | tail hab hbc h_ih => exact ih hab (single hbc) h_ih (base hbc) theorem trans_right (hab : ReflTransGen r a b) (hbc : TransGen r b c) : TransGen r a c := by induction hbc with | single hbc => exact tail' hab hbc | tail _ hcd hac => exact hac.tail hcd instance : Trans (ReflTransGen r) (TransGen r) (TransGen r) := ⟨trans_right⟩ theorem tail'_iff : TransGen r a c ↔ ∃ b, ReflTransGen r a b ∧ r b c := by refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ tail' hab hbc⟩ cases h with | single hac => exact ⟨_, by rfl, hac⟩ | tail hab hbc => exact ⟨_, hab.to_reflTransGen, hbc⟩ theorem head'_iff : TransGen r a c ↔ ∃ b, r a b ∧ ReflTransGen r b c := by refine ⟨fun h ↦ ?_, fun ⟨b, hab, hbc⟩ ↦ head' hab hbc⟩ induction h with | single hac => exact ⟨_, hac, by rfl⟩ | tail _ hbc IH => rcases IH with ⟨d, had, hdb⟩ exact ⟨_, had, hdb.tail hbc⟩ end TransGen section reflGen lemma reflGen_eq_self (hr : Reflexive r) : ReflGen r = r := by ext x y simpa only [reflGen_iff, or_iff_right_iff_imp] using fun h ↦ h ▸ hr y lemma reflexive_reflGen : Reflexive (ReflGen r) := fun _ ↦ .refl lemma reflGen_minimal {r' : α → α → Prop} (hr' : Reflexive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflGen r x y) : r' x y := by simpa [reflGen_eq_self hr'] using ReflGen.mono h hxy end reflGen section TransGen theorem transGen_eq_self (trans : Transitive r) : TransGen r = r := funext fun a ↦ funext fun b ↦ propext <| ⟨fun h ↦ by induction h with | single hc => exact hc | tail _ hcd hac => exact trans hac hcd, TransGen.single⟩ theorem transitive_transGen : Transitive (TransGen r) := fun _ _ _ ↦ TransGen.trans instance : IsTrans α (TransGen r) := ⟨@TransGen.trans α r⟩ theorem transGen_idem : TransGen (TransGen r) = TransGen r := transGen_eq_self transitive_transGen theorem TransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b)) (hab : TransGen r a b) : TransGen p (f a) (f b) := by induction hab with | single hac => exact TransGen.single (h a _ hac) | tail _ hcd hac => exact TransGen.tail hac (h _ _ hcd) theorem TransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → TransGen p (f a) (f b)) (hab : TransGen r a b) : TransGen p (f a) (f b) := by simpa [transGen_idem] using hab.lift f h theorem TransGen.closed {p : α → α → Prop} : (∀ a b, r a b → TransGen p a b) → TransGen r a b → TransGen p a b := TransGen.lift' id lemma TransGen.closed' {P : α → Prop} (dc : ∀ {a b}, r a b → P b → P a) {a b : α} (h : TransGen r a b) : P b → P a := h.head_induction_on dc fun hr _ hi ↦ dc hr ∘ hi theorem TransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) → TransGen r a b → TransGen p a b := TransGen.lift id lemma transGen_minimal {r' : α → α → Prop} (hr' : Transitive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : TransGen r x y) : r' x y := by simpa [transGen_eq_self hr'] using TransGen.mono h hxy theorem TransGen.swap (h : TransGen r b a) : TransGen (swap r) a b := by induction h with | single h => exact TransGen.single h | tail _ hbc ih => exact ih.head hbc theorem transGen_swap : TransGen (swap r) a b ↔ TransGen r b a := ⟨TransGen.swap, TransGen.swap⟩ end TransGen section ReflTransGen open ReflTransGen theorem reflTransGen_iff_eq (h : ∀ b, ¬r a b) : ReflTransGen r a b ↔ b = a := by rw [cases_head_iff]; simp [h, eq_comm] theorem reflTransGen_iff_eq_or_transGen : ReflTransGen r a b ↔ b = a ∨ TransGen r a b := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · cases h with | refl => exact Or.inl rfl | tail hac hcb => exact Or.inr (TransGen.tail' hac hcb) · rcases h with (rfl | h) · rfl · exact h.to_reflTransGen theorem ReflTransGen.lift {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := ReflTransGen.trans_induction_on hab (fun _ ↦ refl) (ReflTransGen.single ∘ h _ _) fun _ _ ↦ trans theorem ReflTransGen.mono {p : α → α → Prop} : (∀ a b, r a b → p a b) → ReflTransGen r a b → ReflTransGen p a b := ReflTransGen.lift id theorem reflTransGen_eq_self (refl : Reflexive r) (trans : Transitive r) : ReflTransGen r = r := funext fun a ↦ funext fun b ↦ propext <| ⟨fun h ↦ by induction h with | refl => apply refl | tail _ h₂ IH => exact trans IH h₂, single⟩ lemma reflTransGen_minimal {r' : α → α → Prop} (hr₁ : Reflexive r') (hr₂ : Transitive r') (h : ∀ x y, r x y → r' x y) {x y : α} (hxy : ReflTransGen r x y) : r' x y := by simpa [reflTransGen_eq_self hr₁ hr₂] using ReflTransGen.mono h hxy theorem reflexive_reflTransGen : Reflexive (ReflTransGen r) := fun _ ↦ refl theorem transitive_reflTransGen : Transitive (ReflTransGen r) := fun _ _ _ ↦ trans instance : IsRefl α (ReflTransGen r) := ⟨@ReflTransGen.refl α r⟩ instance : IsTrans α (ReflTransGen r) := ⟨@ReflTransGen.trans α r⟩ theorem reflTransGen_idem : ReflTransGen (ReflTransGen r) = ReflTransGen r := reflTransGen_eq_self reflexive_reflTransGen transitive_reflTransGen theorem ReflTransGen.lift' {p : β → β → Prop} {a b : α} (f : α → β) (h : ∀ a b, r a b → ReflTransGen p (f a) (f b)) (hab : ReflTransGen r a b) : ReflTransGen p (f a) (f b) := by simpa [reflTransGen_idem] using hab.lift f h theorem reflTransGen_closed {p : α → α → Prop} : (∀ a b, r a b → ReflTransGen p a b) → ReflTransGen r a b → ReflTransGen p a b := ReflTransGen.lift' id theorem ReflTransGen.swap (h : ReflTransGen r b a) : ReflTransGen (swap r) a b := by induction h with | refl => rfl | tail _ hbc ih => exact ih.head hbc theorem reflTransGen_swap : ReflTransGen (swap r) a b ↔ ReflTransGen r b a := ⟨ReflTransGen.swap, ReflTransGen.swap⟩ @[simp] lemma reflGen_transGen : ReflGen (TransGen r) = ReflTransGen r := by ext x y simp_rw [reflTransGen_iff_eq_or_transGen, reflGen_iff] @[simp] lemma transGen_reflGen : TransGen (ReflGen r) = ReflTransGen r := by ext x y refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · simpa [reflTransGen_idem] using TransGen.to_reflTransGen <| TransGen.mono (fun _ _ ↦ ReflGen.to_reflTransGen) h · obtain (rfl | h) := reflTransGen_iff_eq_or_transGen.mp h · exact .single .refl · exact TransGen.mono (fun _ _ ↦ .single) h @[simp] lemma reflTransGen_reflGen : ReflTransGen (ReflGen r) = ReflTransGen r := by simp only [← transGen_reflGen, reflGen_eq_self reflexive_reflGen] @[simp] lemma reflTransGen_transGen : ReflTransGen (TransGen r) = ReflTransGen r := by simp only [← reflGen_transGen, transGen_idem] lemma reflTransGen_eq_transGen (hr : Reflexive r) : ReflTransGen r = TransGen r := by rw [← transGen_reflGen, reflGen_eq_self hr] lemma reflTransGen_eq_reflGen (hr : Transitive r) : ReflTransGen r = ReflGen r := by rw [← reflGen_transGen, transGen_eq_self hr] end ReflTransGen namespace EqvGen variable (r) theorem is_equivalence : Equivalence (@EqvGen α r) := Equivalence.mk EqvGen.refl (EqvGen.symm _ _) (EqvGen.trans _ _ _) /-- `EqvGen.setoid r` is the setoid generated by a relation `r`. The motivation for this definition is that `Quot r` behaves like `Quotient (EqvGen.setoid r)`, see for example `Quot.eqvGen_exact` and `Quot.eqvGen_sound`. -/ def setoid : Setoid α := Setoid.mk _ (EqvGen.is_equivalence r) theorem mono {r p : α → α → Prop} (hrp : ∀ a b, r a b → p a b) (h : EqvGen r a b) : EqvGen p a b := by induction h with | rel a b h => exact EqvGen.rel _ _ (hrp _ _ h) | refl => exact EqvGen.refl _ | symm a b _ ih => exact EqvGen.symm _ _ ih | trans a b c _ _ hab hbc => exact EqvGen.trans _ _ _ hab hbc end EqvGen /-- The join of a relation on a single type is a new relation for which
pairs of terms are related if there is a third term they are both related to. For example, if `r` is a relation representing rewrites in a term rewriting system, then *confluence* is the property that if
Mathlib/Logic/Relation.lean
632
634
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Countable.Basic import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Set.Subsingleton import Mathlib.Logic.Equiv.List /-! # Countable sets In this file we define `Set.Countable s` as `Countable s` and prove basic properties of this definition. Note that this definition does not provide a computable encoding. For a noncomputable conversion to `Encodable s`, use `Set.Countable.nonempty_encodable`. ## Keywords sets, countable set -/ assert_not_exists Monoid Multiset.sort noncomputable section open Function Set Encodable universe u v w x variable {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} namespace Set /-- A set `s` is countable if the corresponding subtype is countable, i.e., there exists an injective map `f : s → ℕ`. Note that this is an abbreviation, so `hs : Set.Countable s` in the proof context is the same as an instance `Countable s`. For a constructive version, see `Encodable`. -/ protected def Countable (s : Set α) : Prop := Countable s @[simp] theorem countable_coe_iff {s : Set α} : Countable s ↔ s.Countable := .rfl /-- Prove `Set.Countable` from a `Countable` instance on the subtype. -/ theorem to_countable (s : Set α) [Countable s] : s.Countable := ‹_› /-- Restate `Set.Countable` as a `Countable` instance. -/ alias ⟨_root_.Countable.to_set, Countable.to_subtype⟩ := countable_coe_iff protected theorem countable_iff_exists_injective {s : Set α} : s.Countable ↔ ∃ f : s → ℕ, Injective f := countable_iff_exists_injective s /-- A set `s : Set α` is countable if and only if there exists a function `α → ℕ` injective on `s`. -/ theorem countable_iff_exists_injOn {s : Set α} : s.Countable ↔ ∃ f : α → ℕ, InjOn f s := Set.countable_iff_exists_injective.trans exists_injOn_iff_injective.symm theorem countable_iff_nonempty_encodable {s : Set α} : s.Countable ↔ Nonempty (Encodable s) := Encodable.nonempty_encodable.symm alias ⟨Countable.nonempty_encodable, _⟩ := countable_iff_nonempty_encodable /-- Convert `Set.Countable s` to `Encodable s` (noncomputable). -/ protected def Countable.toEncodable {s : Set α} (hs : s.Countable) : Encodable s := Classical.choice hs.nonempty_encodable section Enumerate /-- Noncomputably enumerate elements in a set. The `default` value is used to extend the domain to all of `ℕ`. -/ def enumerateCountable {s : Set α} (h : s.Countable) (default : α) : ℕ → α := fun n => match @Encodable.decode s h.toEncodable n with | some y => y | none => default theorem subset_range_enumerate {s : Set α} (h : s.Countable) (default : α) : s ⊆ range (enumerateCountable h default) := fun x hx => ⟨@Encodable.encode s h.toEncodable ⟨x, hx⟩, by letI := h.toEncodable simp [enumerateCountable, Encodable.encodek]⟩ lemma range_enumerateCountable_subset {s : Set α} (h : s.Countable) (default : α) : range (enumerateCountable h default) ⊆ insert default s := by refine range_subset_iff.mpr (fun n ↦ ?_) rw [enumerateCountable] match @decode s (Countable.toEncodable h) n with | none => exact mem_insert _ _ | some val => simp lemma range_enumerateCountable_of_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s) : range (enumerateCountable h default) = s := subset_antisymm ((range_enumerateCountable_subset h _).trans_eq (insert_eq_of_mem h_mem)) (subset_range_enumerate h default) lemma enumerateCountable_mem {s : Set α} (h : s.Countable) {default : α} (h_mem : default ∈ s) (n : ℕ) : enumerateCountable h default n ∈ s := by convert mem_range_self n exact (range_enumerateCountable_of_mem h h_mem).symm end Enumerate theorem Countable.mono {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) (hs : s₂.Countable) : s₁.Countable := have := hs.to_subtype; (inclusion_injective h).countable theorem countable_range [Countable ι] (f : ι → β) : (range f).Countable := surjective_onto_range.countable.to_set theorem countable_iff_exists_subset_range [Nonempty α] {s : Set α} : s.Countable ↔ ∃ f : ℕ → α, s ⊆ range f := ⟨fun h => by inhabit α exact ⟨enumerateCountable h default, subset_range_enumerate _ _⟩, fun ⟨f, hsf⟩ => (countable_range f).mono hsf⟩ /-- A non-empty set is countable iff there exists a surjection from the natural numbers onto the subtype induced by the set. -/ protected theorem countable_iff_exists_surjective {s : Set α} (hs : s.Nonempty) : s.Countable ↔ ∃ f : ℕ → s, Surjective f := @countable_iff_exists_surjective s hs.to_subtype alias ⟨Countable.exists_surjective, _⟩ := Set.countable_iff_exists_surjective theorem countable_univ_iff : (univ : Set α).Countable ↔ Countable α := countable_coe_iff.symm.trans (Equiv.Set.univ _).countable_iff theorem countable_univ [Countable α] : (univ : Set α).Countable := to_countable univ theorem not_countable_univ_iff : ¬ (univ : Set α).Countable ↔ Uncountable α := by rw [countable_univ_iff, not_countable_iff] theorem not_countable_univ [Uncountable α] : ¬ (univ : Set α).Countable := not_countable_univ_iff.2 ‹_› /-- If `s : Set α` is a nonempty countable set, then there exists a map `f : ℕ → α` such that `s = range f`. -/ theorem Countable.exists_eq_range {s : Set α} (hc : s.Countable) (hs : s.Nonempty) : ∃ f : ℕ → α, s = range f := by rcases hc.exists_surjective hs with ⟨f, hf⟩ refine ⟨(↑) ∘ f, ?_⟩ rw [hf.range_comp, Subtype.range_coe] @[simp] theorem countable_empty : (∅ : Set α).Countable := to_countable _ @[simp] theorem countable_singleton (a : α) : ({a} : Set α).Countable := to_countable _ theorem Countable.image {s : Set α} (hs : s.Countable) (f : α → β) : (f '' s).Countable := by rw [image_eq_range] have := hs.to_subtype apply countable_range theorem MapsTo.countable_of_injOn {s : Set α} {t : Set β} {f : α → β} (hf : MapsTo f s t) (hf' : InjOn f s) (ht : t.Countable) : s.Countable := have := ht.to_subtype have : Injective (hf.restrict f s t) := (injOn_iff_injective.1 hf').codRestrict _ this.countable theorem Countable.preimage_of_injOn {s : Set β} (hs : s.Countable) {f : α → β} (hf : InjOn f (f ⁻¹' s)) : (f ⁻¹' s).Countable := (mapsTo_preimage f s).countable_of_injOn hf hs protected theorem Countable.preimage {s : Set β} (hs : s.Countable) {f : α → β} (hf : Injective f) : (f ⁻¹' s).Countable := hs.preimage_of_injOn hf.injOn theorem exists_seq_iSup_eq_top_iff_countable [CompleteLattice α] {p : α → Prop} (h : ∃ x, p x) : (∃ s : ℕ → α, (∀ n, p (s n)) ∧ ⨆ n, s n = ⊤) ↔ ∃ S : Set α, S.Countable ∧ (∀ s ∈ S, p s) ∧ sSup S = ⊤ := by constructor · rintro ⟨s, hps, hs⟩ refine ⟨range s, countable_range s, forall_mem_range.2 hps, ?_⟩ rwa [sSup_range] · rintro ⟨S, hSc, hps, hS⟩ rcases eq_empty_or_nonempty S with (rfl | hne) · rw [sSup_empty] at hS haveI := subsingleton_of_bot_eq_top hS rcases h with ⟨x, hx⟩ exact ⟨fun _ => x, fun _ => hx, Subsingleton.elim _ _⟩ · rcases (Set.countable_iff_exists_surjective hne).1 hSc with ⟨s, hs⟩ refine ⟨fun n => s n, fun n => hps _ (s n).coe_prop, ?_⟩ rwa [hs.iSup_comp, ← sSup_eq_iSup'] theorem exists_seq_cover_iff_countable {p : Set α → Prop} (h : ∃ s, p s) : (∃ s : ℕ → Set α, (∀ n, p (s n)) ∧ ⋃ n, s n = univ) ↔ ∃ S : Set (Set α), S.Countable ∧ (∀ s ∈ S, p s) ∧ ⋃₀ S = univ := exists_seq_iSup_eq_top_iff_countable h theorem countable_of_injective_of_countable_image {s : Set α} {f : α → β} (hf : InjOn f s) (hs : (f '' s).Countable) : s.Countable := (mapsTo_image _ _).countable_of_injOn hf hs theorem countable_iUnion {t : ι → Set α} [Countable ι] (ht : ∀ i, (t i).Countable) : (⋃ i, t i).Countable := by have := fun i ↦ (ht i).to_subtype rw [iUnion_eq_range_psigma] apply countable_range @[simp] theorem countable_iUnion_iff [Countable ι] {t : ι → Set α} : (⋃ i, t i).Countable ↔ ∀ i, (t i).Countable := ⟨fun h _ => h.mono <| subset_iUnion _ _, countable_iUnion⟩ theorem Countable.biUnion_iff {s : Set α} {t : ∀ a ∈ s, Set β} (hs : s.Countable) : (⋃ a ∈ s, t a ‹_›).Countable ↔ ∀ a (ha : a ∈ s), (t a ha).Countable := by have := hs.to_subtype rw [biUnion_eq_iUnion, countable_iUnion_iff, SetCoe.forall'] theorem Countable.sUnion_iff {s : Set (Set α)} (hs : s.Countable) : (⋃₀ s).Countable ↔ ∀ a ∈ s, a.Countable := by rw [sUnion_eq_biUnion, hs.biUnion_iff] alias ⟨_, Countable.biUnion⟩ := Countable.biUnion_iff alias ⟨_, Countable.sUnion⟩ := Countable.sUnion_iff @[simp] theorem countable_union {s t : Set α} : (s ∪ t).Countable ↔ s.Countable ∧ t.Countable := by simp [union_eq_iUnion, and_comm] theorem Countable.union {s t : Set α} (hs : s.Countable) (ht : t.Countable) : (s ∪ t).Countable := countable_union.2 ⟨hs, ht⟩ theorem Countable.of_diff {s t : Set α} (h : (s \ t).Countable) (ht : t.Countable) : s.Countable := (h.union ht).mono (subset_diff_union _ _) @[simp] theorem countable_insert {s : Set α} {a : α} : (insert a s).Countable ↔ s.Countable := by simp only [insert_eq, countable_union, countable_singleton, true_and] protected theorem Countable.insert {s : Set α} (a : α) (h : s.Countable) : (insert a s).Countable := countable_insert.2 h theorem Finite.countable {s : Set α} (hs : s.Finite) : s.Countable := have := hs.to_subtype; s.to_countable @[nontriviality] theorem Countable.of_subsingleton [Subsingleton α] (s : Set α) : s.Countable := (Finite.of_subsingleton s).countable theorem Subsingleton.countable {s : Set α} (hs : s.Subsingleton) : s.Countable := hs.finite.countable theorem countable_isTop (α : Type*) [PartialOrder α] : { x : α | IsTop x }.Countable := (finite_isTop α).countable theorem countable_isBot (α : Type*) [PartialOrder α] : { x : α | IsBot x }.Countable := (finite_isBot α).countable /-- The set of finite subsets of a countable set is countable. -/ theorem countable_setOf_finite_subset {s : Set α} (hs : s.Countable) : { t | Set.Finite t ∧ t ⊆ s }.Countable := by have := hs.to_subtype refine (countable_range fun t : Finset s => Subtype.val '' (t : Set s)).mono ?_ rintro t ⟨ht, hts⟩ lift t to Set s using hts lift t to Finset s using ht.of_finite_image Subtype.val_injective.injOn exact mem_range_self _ /-- The set of finite sets in a countable type is countable. -/ theorem Countable.setOf_finite [Countable α] : {s : Set α | s.Finite}.Countable := by simpa using countable_setOf_finite_subset countable_univ theorem countable_univ_pi {π : α → Type*} [Finite α] {s : ∀ a, Set (π a)} (hs : ∀ a, (s a).Countable) : (pi univ s).Countable := have := fun a ↦ (hs a).to_subtype; .of_equiv _ (Equiv.Set.univPi s).symm theorem countable_pi {π : α → Type*} [Finite α] {s : ∀ a, Set (π a)} (hs : ∀ a, (s a).Countable) : { f : ∀ a, π a | ∀ a, f a ∈ s a }.Countable := by simpa only [← mem_univ_pi] using countable_univ_pi hs protected theorem Countable.prod {s : Set α} {t : Set β} (hs : s.Countable) (ht : t.Countable) : Set.Countable (s ×ˢ t) := have := hs.to_subtype; have := ht.to_subtype; .of_equiv _ <| (Equiv.Set.prod _ _).symm theorem Countable.image2 {s : Set α} {t : Set β} (hs : s.Countable) (ht : t.Countable) (f : α → β → γ) : (image2 f s t).Countable := by rw [← image_prod] exact (hs.prod ht).image _ /-- If a family of disjoint sets is included in a countable set, then only countably many of them are nonempty. -/ theorem countable_setOf_nonempty_of_disjoint {f : β → Set α} (hf : Pairwise (Disjoint on f)) {s : Set α} (h'f : ∀ t, f t ⊆ s) (hs : s.Countable) : Set.Countable {t | (f t).Nonempty} := by rw [← Set.countable_coe_iff] at hs ⊢ have : ∀ t : {t // (f t).Nonempty}, ∃ x : s, x.1 ∈ f t := by rintro ⟨t, ⟨x, hx⟩⟩ exact ⟨⟨x, (h'f t hx)⟩, hx⟩ choose F hF using this have A : Injective F := by rintro ⟨t, ht⟩ ⟨t', ht'⟩ htt' have A : (f t ∩ f t').Nonempty := by refine ⟨F ⟨t, ht⟩, hF ⟨t, _⟩, ?_⟩ rw [htt'] exact hF ⟨t', _⟩ simp only [Subtype.mk.injEq] by_contra H exact not_disjoint_iff_nonempty_inter.2 A (hf H) exact Injective.countable A end Set theorem Finset.countable_toSet (s : Finset α) : Set.Countable (↑s : Set α) := s.finite_toSet.countable
Mathlib/Data/Set/Countable.lean
319
322
/- Copyright (c) 2022 Felix Weilacher. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Felix Weilacher -/ import Mathlib.Topology.Separation.Regular /-! # Perfect Sets In this file we define perfect subsets of a topological space, and prove some basic properties, including a version of the Cantor-Bendixson Theorem. ## Main Definitions * `Perfect C`: A set `C` is perfect, meaning it is closed and every point of it is an accumulation point of itself. * `PerfectSpace X`: A topological space `X` is perfect if its universe is a perfect set. ## Main Statements * `Perfect.splitting`: A perfect nonempty set contains two disjoint perfect nonempty subsets. The main inductive step in the construction of an embedding from the Cantor space to a perfect nonempty complete metric space. * `exists_countable_union_perfect_of_isClosed`: One version of the **Cantor-Bendixson Theorem**: A closed set in a second countable space can be written as the union of a countable set and a perfect set. ## Implementation Notes We do not require perfect sets to be nonempty. We define a nonstandard predicate, `Preperfect`, which drops the closed-ness requirement from the definition of perfect. In T1 spaces, this is equivalent to having a perfect closure, see `preperfect_iff_perfect_closure`. ## See also `Mathlib.Topology.MetricSpace.Perfect`, for properties of perfect sets in metric spaces, namely Polish spaces. ## References * [kechris1995] (Chapters 6-7) ## Tags accumulation point, perfect set, cantor-bendixson. -/ open Topology Filter Set TopologicalSpace section Basic variable {α : Type*} [TopologicalSpace α] {C : Set α} /-- If `x` is an accumulation point of a set `C` and `U` is a neighborhood of `x`, then `x` is an accumulation point of `U ∩ C`. -/ theorem AccPt.nhds_inter {x : α} {U : Set α} (h_acc : AccPt x (𝓟 C)) (hU : U ∈ 𝓝 x) : AccPt x (𝓟 (U ∩ C)) := by have : 𝓝[≠] x ≤ 𝓟 U := by rw [le_principal_iff] exact mem_nhdsWithin_of_mem_nhds hU rw [AccPt, ← inf_principal, ← inf_assoc, inf_of_le_left this] exact h_acc /-- A set `C` is preperfect if all of its points are accumulation points of itself. If `C` is nonempty and `α` is a T1 space, this is equivalent to the closure of `C` being perfect. See `preperfect_iff_perfect_closure`. -/ def Preperfect (C : Set α) : Prop := ∀ x ∈ C, AccPt x (𝓟 C) /-- A set `C` is called perfect if it is closed and all of its points are accumulation points of itself. Note that we do not require `C` to be nonempty. -/ @[mk_iff perfect_def] structure Perfect (C : Set α) : Prop where closed : IsClosed C acc : Preperfect C theorem preperfect_iff_nhds : Preperfect C ↔ ∀ x ∈ C, ∀ U ∈ 𝓝 x, ∃ y ∈ U ∩ C, y ≠ x := by simp only [Preperfect, accPt_iff_nhds] section PerfectSpace variable (α) /-- A topological space `X` is said to be perfect if its universe is a perfect set. Equivalently, this means that `𝓝[≠] x ≠ ⊥` for every point `x : X`. -/ @[mk_iff perfectSpace_def] class PerfectSpace : Prop where univ_preperfect : Preperfect (Set.univ : Set α) theorem PerfectSpace.univ_perfect [PerfectSpace α] : Perfect (Set.univ : Set α) := ⟨isClosed_univ, PerfectSpace.univ_preperfect⟩ end PerfectSpace section Preperfect /-- The intersection of a preperfect set and an open set is preperfect. -/ theorem Preperfect.open_inter {U : Set α} (hC : Preperfect C) (hU : IsOpen U) : Preperfect (U ∩ C) := by rintro x ⟨xU, xC⟩ apply (hC _ xC).nhds_inter exact hU.mem_nhds xU /-- The closure of a preperfect set is perfect. For a converse, see `preperfect_iff_perfect_closure`. -/ theorem Preperfect.perfect_closure (hC : Preperfect C) : Perfect (closure C) := by constructor; · exact isClosed_closure intro x hx by_cases h : x ∈ C <;> apply AccPt.mono _ (principal_mono.mpr subset_closure) · exact hC _ h have : {x}ᶜ ∩ C = C := by simp [h] rw [AccPt, nhdsWithin, inf_assoc, inf_principal, this] rw [closure_eq_cluster_pts] at hx exact hx /-- In a T1 space, being preperfect is equivalent to having perfect closure. -/ theorem preperfect_iff_perfect_closure [T1Space α] : Preperfect C ↔ Perfect (closure C) := by constructor <;> intro h · exact h.perfect_closure intro x xC have H : AccPt x (𝓟 (closure C)) := h.acc _ (subset_closure xC) rw [accPt_iff_frequently] at * have : ∀ y, y ≠ x ∧ y ∈ closure C → ∃ᶠ z in 𝓝 y, z ≠ x ∧ z ∈ C := by rintro y ⟨hyx, yC⟩ simp only [← mem_compl_singleton_iff, and_comm, ← frequently_nhdsWithin_iff, hyx.nhdsWithin_compl_singleton, ← mem_closure_iff_frequently] exact yC rw [← frequently_frequently_nhds] exact H.mono this theorem Perfect.closure_nhds_inter {U : Set α} (hC : Perfect C) (x : α) (xC : x ∈ C) (xU : x ∈ U) (Uop : IsOpen U) : Perfect (closure (U ∩ C)) ∧ (closure (U ∩ C)).Nonempty := by constructor · apply Preperfect.perfect_closure exact hC.acc.open_inter Uop apply Nonempty.closure exact ⟨x, ⟨xU, xC⟩⟩ /-- Given a perfect nonempty set in a T2.5 space, we can find two disjoint perfect subsets. This is the main inductive step in the proof of the Cantor-Bendixson Theorem. -/ theorem Perfect.splitting [T25Space α] (hC : Perfect C) (hnonempty : C.Nonempty) : ∃ C₀ C₁ : Set α, (Perfect C₀ ∧ C₀.Nonempty ∧ C₀ ⊆ C) ∧ (Perfect C₁ ∧ C₁.Nonempty ∧ C₁ ⊆ C) ∧ Disjoint C₀ C₁ := by obtain ⟨y, yC⟩ := hnonempty obtain ⟨x, xC, hxy⟩ : ∃ x ∈ C, x ≠ y := by have := hC.acc _ yC rw [accPt_iff_nhds] at this rcases this univ univ_mem with ⟨x, xC, hxy⟩ exact ⟨x, xC.2, hxy⟩ obtain ⟨U, xU, Uop, V, yV, Vop, hUV⟩ := exists_open_nhds_disjoint_closure hxy use closure (U ∩ C), closure (V ∩ C) constructor <;> rw [← and_assoc] · refine ⟨hC.closure_nhds_inter x xC xU Uop, ?_⟩ rw [hC.closed.closure_subset_iff] exact inter_subset_right constructor · refine ⟨hC.closure_nhds_inter y yC yV Vop, ?_⟩ rw [hC.closed.closure_subset_iff] exact inter_subset_right apply Disjoint.mono _ _ hUV <;> apply closure_mono <;> exact inter_subset_left lemma IsPreconnected.preperfect_of_nontrivial [T1Space α] {U : Set α} (hu : U.Nontrivial) (h : IsPreconnected U) : Preperfect U := by intro x hx rw [isPreconnected_closed_iff] at h specialize h {x} (closure (U \ {x})) isClosed_singleton isClosed_closure ?_ ?_ ?_ · trans {x} ∪ (U \ {x}) · simp apply Set.union_subset_union_right exact subset_closure · exact Set.inter_singleton_nonempty.mpr hx · obtain ⟨y, hy⟩ := Set.Nontrivial.exists_ne hu x use y simp only [Set.mem_inter_iff, hy, true_and] apply subset_closure simp [hy] · apply Set.Nonempty.right at h rw [Set.singleton_inter_nonempty, mem_closure_iff_clusterPt, ← accPt_principal_iff_clusterPt] at h exact h end Preperfect section Kernel /-- The **Cantor-Bendixson Theorem**: Any closed subset of a second countable space can be written as the union of a countable set and a perfect set. -/ theorem exists_countable_union_perfect_of_isClosed [SecondCountableTopology α] (hclosed : IsClosed C) : ∃ V D : Set α, V.Countable ∧ Perfect D ∧ C = V ∪ D := by obtain ⟨b, bct, _, bbasis⟩ := TopologicalSpace.exists_countable_basis α let v := { U ∈ b | (U ∩ C).Countable } let V := ⋃ U ∈ v, U let D := C \ V have Vct : (V ∩ C).Countable := by simp only [V, iUnion_inter, mem_sep_iff] apply Countable.biUnion · exact Countable.mono inter_subset_left bct · exact inter_subset_right refine ⟨V ∩ C, D, Vct, ⟨?_, ?_⟩, ?_⟩ · refine hclosed.sdiff (isOpen_biUnion fun _ ↦ ?_) exact fun ⟨Ub, _⟩ ↦ IsTopologicalBasis.isOpen bbasis Ub · rw [preperfect_iff_nhds] intro x xD E xE have : ¬(E ∩ D).Countable := by intro h obtain ⟨U, hUb, xU, hU⟩ : ∃ U ∈ b, x ∈ U ∧ U ⊆ E := (IsTopologicalBasis.mem_nhds_iff bbasis).mp xE have hU_cnt : (U ∩ C).Countable := by apply @Countable.mono _ _ (E ∩ D ∪ V ∩ C) · rintro y ⟨yU, yC⟩ by_cases h : y ∈ V · exact mem_union_right _ (mem_inter h yC) · exact mem_union_left _ (mem_inter (hU yU) ⟨yC, h⟩) exact Countable.union h Vct have : U ∈ v := ⟨hUb, hU_cnt⟩ apply xD.2 exact mem_biUnion this xU by_contra! h exact absurd (Countable.mono h (Set.countable_singleton _)) this · rw [inter_comm, inter_union_diff] /-- Any uncountable closed set in a second countable space contains a nonempty perfect subset. -/ theorem exists_perfect_nonempty_of_isClosed_of_not_countable [SecondCountableTopology α] (hclosed : IsClosed C) (hunc : ¬C.Countable) : ∃ D : Set α, Perfect D ∧ D.Nonempty ∧ D ⊆ C := by rcases exists_countable_union_perfect_of_isClosed hclosed with ⟨V, D, Vct, Dperf, VD⟩ refine ⟨D, ⟨Dperf, ?_⟩⟩ constructor · rw [nonempty_iff_ne_empty] by_contra h rw [h, union_empty] at VD rw [VD] at hunc contradiction rw [VD] exact subset_union_right
end Kernel
Mathlib/Topology/Perfect.lean
244
245
/- 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.Algebra.Ring.Pointwise.Set import Mathlib.Order.Filter.AtTopBot.CompleteLattice import Mathlib.Order.Filter.AtTopBot.Group import Mathlib.Topology.Order.Basic /-! # Neighborhoods to the left and to the right on an `OrderTopology` We've seen some properties of left and right neighborhood of a point in an `OrderClosedTopology`. In an `OrderTopology`, such neighborhoods can be characterized as the sets containing suitable intervals to the right or to the left of `a`. We give now these characterizations. -/ open Set Filter TopologicalSpace Topology Function open OrderDual (toDual ofDual) variable {α β γ : Type*} section LinearOrder variable [TopologicalSpace α] [LinearOrder α] section OrderTopology variable [OrderTopology α] open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `(a, +∞)`; 1. `s` is a neighborhood of `a` within `(a, b]`; 2. `s` is a neighborhood of `a` within `(a, b)`; 3. `s` includes `(a, u)` for some `u ∈ (a, b]`; 4. `s` includes `(a, u)` for some `u > a`. -/ theorem TFAE_mem_nhdsGT {a b : α} (hab : a < b) (s : Set α) : TFAE [s ∈ 𝓝[>] a, s ∈ 𝓝[Ioc a b] a, s ∈ 𝓝[Ioo a b] a, ∃ u ∈ Ioc a b, Ioo a u ⊆ s, ∃ u ∈ Ioi a, Ioo a u ⊆ s] := by tfae_have 1 ↔ 2 := by rw [nhdsWithin_Ioc_eq_nhdsGT hab] tfae_have 1 ↔ 3 := by rw [nhdsWithin_Ioo_eq_nhdsGT hab] tfae_have 4 → 5 := fun ⟨u, umem, hu⟩ => ⟨u, umem.1, hu⟩ tfae_have 5 → 1 | ⟨u, hau, hu⟩ => mem_of_superset (Ioo_mem_nhdsGT hau) hu tfae_have 1 → 4 | h => by rcases mem_nhdsWithin_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩ rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩ exact ⟨u, au, fun x hx => hv ⟨hu ⟨le_of_lt hx.1, hx.2⟩, hx.1⟩⟩ tfae_finish @[deprecated (since := "2024-12-22")] alias TFAE_mem_nhdsWithin_Ioi := TFAE_mem_nhdsGT theorem mem_nhdsGT_iff_exists_mem_Ioc_Ioo_subset {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioc a u', Ioo a u ⊆ s := (TFAE_mem_nhdsGT hu' s).out 0 3 @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ioi_iff_exists_mem_Ioc_Ioo_subset := mem_nhdsGT_iff_exists_mem_Ioc_Ioo_subset /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u < u'`, provided `a` is not a top element. -/ theorem mem_nhdsGT_iff_exists_Ioo_subset' {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioi a, Ioo a u ⊆ s := (TFAE_mem_nhdsGT hu' s).out 0 4 @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ioi_iff_exists_Ioo_subset' := mem_nhdsGT_iff_exists_Ioo_subset' theorem nhdsGT_basis_of_exists_gt {a : α} (h : ∃ b, a < b) : (𝓝[>] a).HasBasis (a < ·) (Ioo a) := let ⟨_, h⟩ := h ⟨fun _ => mem_nhdsGT_iff_exists_Ioo_subset' h⟩ @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioi_basis' := nhdsGT_basis_of_exists_gt lemma nhdsGT_basis [NoMaxOrder α] (a : α) : (𝓝[>] a).HasBasis (a < ·) (Ioo a) := nhdsGT_basis_of_exists_gt <| exists_gt a @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioi_basis := nhdsGT_basis theorem nhdsGT_eq_bot_iff {a : α} : 𝓝[>] a = ⊥ ↔ IsTop a ∨ ∃ b, a ⋖ b := by by_cases ha : IsTop a · simp [ha, ha.isMax.Ioi_eq] · simp only [ha, false_or] rw [isTop_iff_isMax, not_isMax_iff] at ha simp only [(nhdsGT_basis_of_exists_gt ha).eq_bot_iff, covBy_iff_Ioo_eq] @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ioi_eq_bot_iff := nhdsGT_eq_bot_iff /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u`. -/ theorem mem_nhdsGT_iff_exists_Ioo_subset [NoMaxOrder α] {a : α} {s : Set α} : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioi a, Ioo a u ⊆ s := let ⟨_u', hu'⟩ := exists_gt a mem_nhdsGT_iff_exists_Ioo_subset' hu' @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ioi_iff_exists_Ioo_subset := mem_nhdsGT_iff_exists_Ioo_subset /-- The set of points which are isolated on the right is countable when the space is second-countable. -/ theorem countable_setOf_isolated_right [SecondCountableTopology α] : { x : α | 𝓝[>] x = ⊥ }.Countable := by simp only [nhdsGT_eq_bot_iff, setOf_or] exact (subsingleton_isTop α).countable.union countable_setOf_covBy_right /-- The set of points which are isolated on the left is countable when the space is second-countable. -/ theorem countable_setOf_isolated_left [SecondCountableTopology α] : { x : α | 𝓝[<] x = ⊥ }.Countable := countable_setOf_isolated_right (α := αᵒᵈ) /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u]` with `a < u`. -/ theorem mem_nhdsGT_iff_exists_Ioc_subset [NoMaxOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[>] a ↔ ∃ u ∈ Ioi a, Ioc a u ⊆ s := by rw [mem_nhdsGT_iff_exists_Ioo_subset] constructor · rintro ⟨u, au, as⟩ rcases exists_between au with ⟨v, hv⟩ exact ⟨v, hv.1, fun x hx => as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ · rintro ⟨u, au, as⟩ exact ⟨u, au, Subset.trans Ioo_subset_Ioc_self as⟩ @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ioi_iff_exists_Ioc_subset := mem_nhdsGT_iff_exists_Ioc_subset open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b)` 1. `s` is a neighborhood of `b` within `[a, b)` 2. `s` is a neighborhood of `b` within `(a, b)` 3. `s` includes `(l, b)` for some `l ∈ [a, b)` 4. `s` includes `(l, b)` for some `l < b` -/ theorem TFAE_mem_nhdsLT {a b : α} (h : a < b) (s : Set α) : TFAE [s ∈ 𝓝[<] b,-- 0 : `s` is a neighborhood of `b` within `(-∞, b)` s ∈ 𝓝[Ico a b] b,-- 1 : `s` is a neighborhood of `b` within `[a, b)` s ∈ 𝓝[Ioo a b] b,-- 2 : `s` is a neighborhood of `b` within `(a, b)` ∃ l ∈ Ico a b, Ioo l b ⊆ s,-- 3 : `s` includes `(l, b)` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioo l b ⊆ s] := by-- 4 : `s` includes `(l, b)` for some `l < b` simpa using TFAE_mem_nhdsGT h.dual (ofDual ⁻¹' s) @[deprecated (since := "2024-12-22")] alias TFAE_mem_nhdsWithin_Iio := TFAE_mem_nhdsLT theorem mem_nhdsLT_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[<] a ↔ ∃ l ∈ Ico l' a, Ioo l a ⊆ s := (TFAE_mem_nhdsLT hl' s).out 0 3 @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iio_iff_exists_mem_Ico_Ioo_subset := mem_nhdsLT_iff_exists_mem_Ico_Ioo_subset /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`, provided `a` is not a bottom element. -/ theorem mem_nhdsLT_iff_exists_Ioo_subset' {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[<] a ↔ ∃ l ∈ Iio a, Ioo l a ⊆ s := (TFAE_mem_nhdsLT hl' s).out 0 4 @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iio_iff_exists_Ioo_subset' := mem_nhdsLT_iff_exists_Ioo_subset' /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`. -/ theorem mem_nhdsLT_iff_exists_Ioo_subset [NoMinOrder α] {a : α} {s : Set α} : s ∈ 𝓝[<] a ↔ ∃ l ∈ Iio a, Ioo l a ⊆ s := let ⟨_, h⟩ := exists_lt a mem_nhdsLT_iff_exists_Ioo_subset' h @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iio_iff_exists_Ioo_subset := mem_nhdsLT_iff_exists_Ioo_subset /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `[l, a)` with `l < a`. -/ theorem mem_nhdsLT_iff_exists_Ico_subset [NoMinOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[<] a ↔ ∃ l ∈ Iio a, Ico l a ⊆ s := by have : ofDual ⁻¹' s ∈ 𝓝[>] toDual a ↔ _ := mem_nhdsGT_iff_exists_Ioc_subset simpa using this @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iio_iff_exists_Ico_subset := mem_nhdsLT_iff_exists_Ico_subset theorem nhdsLT_basis_of_exists_lt {a : α} (h : ∃ b, b < a) : (𝓝[<] a).HasBasis (· < a) (Ioo · a) := let ⟨_, h⟩ := h ⟨fun _ => mem_nhdsLT_iff_exists_Ioo_subset' h⟩ @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iio_basis' := nhdsLT_basis_of_exists_lt theorem nhdsLT_basis [NoMinOrder α] (a : α) : (𝓝[<] a).HasBasis (· < a) (Ioo · a) := nhdsLT_basis_of_exists_lt <| exists_lt a @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iio_basis := nhdsLT_basis theorem nhdsLT_eq_bot_iff {a : α} : 𝓝[<] a = ⊥ ↔ IsBot a ∨ ∃ b, b ⋖ a := by convert (config := { preTransparency := .default }) nhdsGT_eq_bot_iff (a := OrderDual.toDual a) using 4 exact ofDual_covBy_ofDual_iff @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iio_eq_bot_iff := nhdsLT_eq_bot_iff open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `[a, +∞)`; 1. `s` is a neighborhood of `a` within `[a, b]`; 2. `s` is a neighborhood of `a` within `[a, b)`; 3. `s` includes `[a, u)` for some `u ∈ (a, b]`; 4. `s` includes `[a, u)` for some `u > a`. -/ theorem TFAE_mem_nhdsGE {a b : α} (hab : a < b) (s : Set α) : TFAE [s ∈ 𝓝[≥] a, s ∈ 𝓝[Icc a b] a, s ∈ 𝓝[Ico a b] a, ∃ u ∈ Ioc a b, Ico a u ⊆ s, ∃ u ∈ Ioi a , Ico a u ⊆ s] := by tfae_have 1 ↔ 2 := by rw [nhdsWithin_Icc_eq_nhdsGE hab] tfae_have 1 ↔ 3 := by rw [nhdsWithin_Ico_eq_nhdsGE hab] tfae_have 1 ↔ 5 := (nhdsGE_basis_of_exists_gt ⟨b, hab⟩).mem_iff tfae_have 4 → 5 := fun ⟨u, umem, hu⟩ => ⟨u, umem.1, hu⟩ tfae_have 5 → 4 | ⟨u, hua, hus⟩ => ⟨min u b, ⟨lt_min hua hab, min_le_right _ _⟩, (Ico_subset_Ico_right <| min_le_left _ _).trans hus⟩ tfae_finish @[deprecated (since := "2024-12-22")] alias TFAE_mem_nhdsWithin_Ici := TFAE_mem_nhdsGE theorem mem_nhdsGE_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[≥] a ↔ ∃ u ∈ Ioc a u', Ico a u ⊆ s := (TFAE_mem_nhdsGE hu' s).out 0 3 (by norm_num) (by norm_num) @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ici_iff_exists_mem_Ioc_Ico_subset := mem_nhdsGE_iff_exists_mem_Ioc_Ico_subset /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u < u'`, provided `a` is not a top element. -/ theorem mem_nhdsGE_iff_exists_Ico_subset' {a u' : α} {s : Set α} (hu' : a < u') : s ∈ 𝓝[≥] a ↔ ∃ u ∈ Ioi a, Ico a u ⊆ s := (TFAE_mem_nhdsGE hu' s).out 0 4 (by norm_num) (by norm_num) @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ici_iff_exists_Ico_subset' := mem_nhdsGE_iff_exists_Ico_subset' /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u`. -/ theorem mem_nhdsGE_iff_exists_Ico_subset [NoMaxOrder α] {a : α} {s : Set α} : s ∈ 𝓝[≥] a ↔ ∃ u ∈ Ioi a, Ico a u ⊆ s := let ⟨_, hu'⟩ := exists_gt a mem_nhdsGE_iff_exists_Ico_subset' hu' @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ici_iff_exists_Ico_subset := mem_nhdsGE_iff_exists_Ico_subset theorem nhdsGE_basis_Ico [NoMaxOrder α] (a : α) : (𝓝[≥] a).HasBasis (fun u => a < u) (Ico a) := ⟨fun _ => mem_nhdsGE_iff_exists_Ico_subset⟩ @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis_Ico := nhdsGE_basis_Ico /-- The filter of right neighborhoods has a basis of closed intervals. -/ theorem nhdsGE_basis_Icc [NoMaxOrder α] [DenselyOrdered α] {a : α} : (𝓝[≥] a).HasBasis (a < ·) (Icc a) := (nhdsGE_basis _).to_hasBasis (fun _u hu ↦ (exists_between hu).imp fun _v hv ↦ hv.imp_right Icc_subset_Ico_right) fun u hu ↦ ⟨u, hu, Ico_subset_Icc_self⟩ @[deprecated (since := "2024-12-22")] alias nhdsWithin_Ici_basis_Icc := nhdsGE_basis_Icc /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ theorem mem_nhdsGE_iff_exists_Icc_subset [NoMaxOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[≥] a ↔ ∃ u, a < u ∧ Icc a u ⊆ s := nhdsGE_basis_Icc.mem_iff @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Ici_iff_exists_Icc_subset := mem_nhdsGE_iff_exists_Icc_subset open List in /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b]` 1. `s` is a neighborhood of `b` within `[a, b]` 2. `s` is a neighborhood of `b` within `(a, b]` 3. `s` includes `(l, b]` for some `l ∈ [a, b)` 4. `s` includes `(l, b]` for some `l < b` -/ theorem TFAE_mem_nhdsLE {a b : α} (h : a < b) (s : Set α) : TFAE [s ∈ 𝓝[≤] b,-- 0 : `s` is a neighborhood of `b` within `(-∞, b]` s ∈ 𝓝[Icc a b] b,-- 1 : `s` is a neighborhood of `b` within `[a, b]` s ∈ 𝓝[Ioc a b] b,-- 2 : `s` is a neighborhood of `b` within `(a, b]` ∃ l ∈ Ico a b, Ioc l b ⊆ s,-- 3 : `s` includes `(l, b]` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioc l b ⊆ s] := by-- 4 : `s` includes `(l, b]` for some `l < b` simpa using TFAE_mem_nhdsGE h.dual (ofDual ⁻¹' s) @[deprecated (since := "2024-12-22")] alias TFAE_mem_nhdsWithin_Iic := TFAE_mem_nhdsLE theorem mem_nhdsLE_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[≤] a ↔ ∃ l ∈ Ico l' a, Ioc l a ⊆ s := (TFAE_mem_nhdsLE hl' s).out 0 3 (by norm_num) (by norm_num) @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iic_iff_exists_mem_Ico_Ioc_subset := mem_nhdsLE_iff_exists_mem_Ico_Ioc_subset /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`, provided `a` is not a bottom element. -/ theorem mem_nhdsLE_iff_exists_Ioc_subset' {a l' : α} {s : Set α} (hl' : l' < a) : s ∈ 𝓝[≤] a ↔ ∃ l ∈ Iio a, Ioc l a ⊆ s := (TFAE_mem_nhdsLE hl' s).out 0 4 (by norm_num) (by norm_num) @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iic_iff_exists_Ioc_subset' := mem_nhdsLE_iff_exists_Ioc_subset' /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`. -/ theorem mem_nhdsLE_iff_exists_Ioc_subset [NoMinOrder α] {a : α} {s : Set α} : s ∈ 𝓝[≤] a ↔ ∃ l ∈ Iio a, Ioc l a ⊆ s := let ⟨_, hl'⟩ := exists_lt a mem_nhdsLE_iff_exists_Ioc_subset' hl' @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iic_iff_exists_Ioc_subset := mem_nhdsLE_iff_exists_Ioc_subset /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ theorem mem_nhdsLE_iff_exists_Icc_subset [NoMinOrder α] [DenselyOrdered α] {a : α} {s : Set α} : s ∈ 𝓝[≤] a ↔ ∃ l, l < a ∧ Icc l a ⊆ s := calc s ∈ 𝓝[≤] a ↔ ofDual ⁻¹' s ∈ 𝓝[≥] (toDual a) := Iff.rfl _ ↔ ∃ u : α, toDual a < toDual u ∧ Icc (toDual a) (toDual u) ⊆ ofDual ⁻¹' s := mem_nhdsGE_iff_exists_Icc_subset _ ↔ ∃ l, l < a ∧ Icc l a ⊆ s := by simp @[deprecated (since := "2024-12-22")] alias mem_nhdsWithin_Iic_iff_exists_Icc_subset := mem_nhdsLE_iff_exists_Icc_subset /-- The filter of left neighborhoods has a basis of closed intervals. -/ theorem nhdsLE_basis_Icc [NoMinOrder α] [DenselyOrdered α] {a : α} : (𝓝[≤] a).HasBasis (· < a) (Icc · a) := ⟨fun _ ↦ mem_nhdsLE_iff_exists_Icc_subset⟩ @[deprecated (since := "2024-12-22")] alias nhdsWithin_Iic_basis_Icc := nhdsLE_basis_Icc
end OrderTopology end LinearOrder
Mathlib/Topology/Order/LeftRightNhds.lean
362
365
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import Mathlib.Data.Bool.Basic import Mathlib.Order.Monotone.Basic import Mathlib.Order.ULift import Mathlib.Tactic.GCongr.CoreAttrs /-! # (Semi-)lattices Semilattices are partially ordered sets with join (least upper bound, or `sup`) or meet (greatest lower bound, or `inf`) operations. Lattices are posets that are both join-semilattices and meet-semilattices. Distributive lattices are lattices which satisfy any of four equivalent distributivity properties, of `sup` over `inf`, on the left or on the right. ## Main declarations * `SemilatticeSup`: a type class for join semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeSup` via proofs that `⊔` is commutative, associative and idempotent. * `SemilatticeInf`: a type class for meet semilattices * `SemilatticeSup.mk'`: an alternative constructor for `SemilatticeInf` via proofs that `⊓` is commutative, associative and idempotent. * `Lattice`: a type class for lattices * `Lattice.mk'`: an alternative constructor for `Lattice` via proofs that `⊔` and `⊓` are commutative, associative and satisfy a pair of "absorption laws". * `DistribLattice`: a type class for distributive lattices. ## Notations * `a ⊔ b`: the supremum or join of `a` and `b` * `a ⊓ b`: the infimum or meet of `a` and `b` ## TODO * (Semi-)lattice homomorphisms * Alternative constructors for distributive lattices from the other distributive properties ## Tags semilattice, lattice -/ /-- See if the term is `a ⊂ b` and the goal is `a ⊆ b`. -/ @[gcongr_forward] def exactSubsetOfSSubset : Mathlib.Tactic.GCongr.ForwardExt where eval h goal := do goal.assignIfDefEq (← Lean.Meta.mkAppM ``subset_of_ssubset #[h]) universe u v w variable {α : Type u} {β : Type v} /-! ### Join-semilattices -/ -- TODO: automatic construction of dual definitions / theorems /-- A `SemilatticeSup` is a join-semilattice, that is, a partial order with a join (a.k.a. lub / least upper bound, sup / supremum) operation `⊔` which is the least element larger than both factors. -/ class SemilatticeSup (α : Type u) extends PartialOrder α where /-- The binary supremum, used to derive `Max α` -/ sup : α → α → α /-- The supremum is an upper bound on the first argument -/ protected le_sup_left : ∀ a b : α, a ≤ sup a b /-- The supremum is an upper bound on the second argument -/ protected le_sup_right : ∀ a b : α, b ≤ sup a b /-- The supremum is the *least* upper bound -/ protected sup_le : ∀ a b c : α, a ≤ c → b ≤ c → sup a b ≤ c instance SemilatticeSup.toMax [SemilatticeSup α] : Max α where max a b := SemilatticeSup.sup a b /-- A type with a commutative, associative and idempotent binary `sup` operation has the structure of a join-semilattice. The partial order is defined so that `a ≤ b` unfolds to `a ⊔ b = b`; cf. `sup_eq_right`. -/ def SemilatticeSup.mk' {α : Type*} [Max α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) : SemilatticeSup α where sup := (· ⊔ ·) le a b := a ⊔ b = b le_refl := sup_idem le_trans a b c hab hbc := by rw [← hbc, ← sup_assoc, hab] le_antisymm a b hab hba := by rwa [← hba, sup_comm] le_sup_left a b := by rw [← sup_assoc, sup_idem] le_sup_right a b := by rw [sup_comm, sup_assoc, sup_idem] sup_le a b c hac hbc := by rwa [sup_assoc, hbc] section SemilatticeSup variable [SemilatticeSup α] {a b c d : α} @[simp] theorem le_sup_left : a ≤ a ⊔ b := SemilatticeSup.le_sup_left a b @[simp] theorem le_sup_right : b ≤ a ⊔ b := SemilatticeSup.le_sup_right a b theorem le_sup_of_le_left (h : c ≤ a) : c ≤ a ⊔ b := le_trans h le_sup_left theorem le_sup_of_le_right (h : c ≤ b) : c ≤ a ⊔ b := le_trans h le_sup_right theorem lt_sup_of_lt_left (h : c < a) : c < a ⊔ b := h.trans_le le_sup_left theorem lt_sup_of_lt_right (h : c < b) : c < a ⊔ b := h.trans_le le_sup_right theorem sup_le : a ≤ c → b ≤ c → a ⊔ b ≤ c := SemilatticeSup.sup_le a b c @[simp] theorem sup_le_iff : a ⊔ b ≤ c ↔ a ≤ c ∧ b ≤ c := ⟨fun h : a ⊔ b ≤ c => ⟨le_trans le_sup_left h, le_trans le_sup_right h⟩, fun ⟨h₁, h₂⟩ => sup_le h₁ h₂⟩ @[simp] theorem sup_eq_left : a ⊔ b = a ↔ b ≤ a := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem sup_eq_right : a ⊔ b = b ↔ a ≤ b := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem left_eq_sup : a = a ⊔ b ↔ b ≤ a := eq_comm.trans sup_eq_left @[simp] theorem right_eq_sup : b = a ⊔ b ↔ a ≤ b := eq_comm.trans sup_eq_right alias ⟨_, sup_of_le_left⟩ := sup_eq_left alias ⟨le_of_sup_eq, sup_of_le_right⟩ := sup_eq_right attribute [simp] sup_of_le_left sup_of_le_right @[simp] theorem left_lt_sup : a < a ⊔ b ↔ ¬b ≤ a := le_sup_left.lt_iff_ne.trans <| not_congr left_eq_sup @[simp] theorem right_lt_sup : b < a ⊔ b ↔ ¬a ≤ b := le_sup_right.lt_iff_ne.trans <| not_congr right_eq_sup theorem left_or_right_lt_sup (h : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := h.not_le_or_not_le.symm.imp left_lt_sup.2 right_lt_sup.2 theorem le_iff_exists_sup : a ≤ b ↔ ∃ c, b = a ⊔ c := by constructor · intro h exact ⟨b, (sup_eq_right.mpr h).symm⟩ · rintro ⟨c, rfl : _ = _ ⊔ _⟩ exact le_sup_left @[gcongr] theorem sup_le_sup (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊔ c ≤ b ⊔ d := sup_le (le_sup_of_le_left h₁) (le_sup_of_le_right h₂) @[gcongr] theorem sup_le_sup_left (h₁ : a ≤ b) (c) : c ⊔ a ≤ c ⊔ b := sup_le_sup le_rfl h₁ @[gcongr] theorem sup_le_sup_right (h₁ : a ≤ b) (c) : a ⊔ c ≤ b ⊔ c := sup_le_sup h₁ le_rfl theorem sup_idem (a : α) : a ⊔ a = a := by simp instance : Std.IdempotentOp (α := α) (· ⊔ ·) := ⟨sup_idem⟩ theorem sup_comm (a b : α) : a ⊔ b = b ⊔ a := by apply le_antisymm <;> simp instance : Std.Commutative (α := α) (· ⊔ ·) := ⟨sup_comm⟩ theorem sup_assoc (a b c : α) : a ⊔ b ⊔ c = a ⊔ (b ⊔ c) := eq_of_forall_ge_iff fun x => by simp only [sup_le_iff]; rw [and_assoc] instance : Std.Associative (α := α) (· ⊔ ·) := ⟨sup_assoc⟩ theorem sup_left_right_swap (a b c : α) : a ⊔ b ⊔ c = c ⊔ b ⊔ a := by rw [sup_comm, sup_comm a, sup_assoc] theorem sup_left_idem (a b : α) : a ⊔ (a ⊔ b) = a ⊔ b := by simp theorem sup_right_idem (a b : α) : a ⊔ b ⊔ b = a ⊔ b := by simp theorem sup_left_comm (a b c : α) : a ⊔ (b ⊔ c) = b ⊔ (a ⊔ c) := by rw [← sup_assoc, ← sup_assoc, @sup_comm α _ a] theorem sup_right_comm (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ b := by rw [sup_assoc, sup_assoc, sup_comm b] theorem sup_sup_sup_comm (a b c d : α) : a ⊔ b ⊔ (c ⊔ d) = a ⊔ c ⊔ (b ⊔ d) := by rw [sup_assoc, sup_left_comm b, ← sup_assoc] theorem sup_sup_distrib_left (a b c : α) : a ⊔ (b ⊔ c) = a ⊔ b ⊔ (a ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] theorem sup_sup_distrib_right (a b c : α) : a ⊔ b ⊔ c = a ⊔ c ⊔ (b ⊔ c) := by rw [sup_sup_sup_comm, sup_idem] theorem sup_congr_left (hb : b ≤ a ⊔ c) (hc : c ≤ a ⊔ b) : a ⊔ b = a ⊔ c := (sup_le le_sup_left hb).antisymm <| sup_le le_sup_left hc theorem sup_congr_right (ha : a ≤ b ⊔ c) (hb : b ≤ a ⊔ c) : a ⊔ c = b ⊔ c := (sup_le ha le_sup_right).antisymm <| sup_le hb le_sup_right theorem sup_eq_sup_iff_left : a ⊔ b = a ⊔ c ↔ b ≤ a ⊔ c ∧ c ≤ a ⊔ b := ⟨fun h => ⟨h ▸ le_sup_right, h.symm ▸ le_sup_right⟩, fun h => sup_congr_left h.1 h.2⟩ theorem sup_eq_sup_iff_right : a ⊔ c = b ⊔ c ↔ a ≤ b ⊔ c ∧ b ≤ a ⊔ c := ⟨fun h => ⟨h ▸ le_sup_left, h.symm ▸ le_sup_left⟩, fun h => sup_congr_right h.1 h.2⟩ theorem Ne.lt_sup_or_lt_sup (hab : a ≠ b) : a < a ⊔ b ∨ b < a ⊔ b := hab.symm.not_le_or_not_le.imp left_lt_sup.2 right_lt_sup.2 /-- If `f` is monotone, `g` is antitone, and `f ≤ g`, then for all `a`, `b` we have `f a ≤ g b`. -/ theorem Monotone.forall_le_of_antitone {β : Type*} [Preorder β] {f g : α → β} (hf : Monotone f) (hg : Antitone g) (h : f ≤ g) (m n : α) : f m ≤ g n := calc f m ≤ f (m ⊔ n) := hf le_sup_left _ ≤ g (m ⊔ n) := h _ _ ≤ g n := hg le_sup_right theorem SemilatticeSup.ext_sup {α} {A B : SemilatticeSup α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) (x y : α) : (haveI := A; x ⊔ y) = x ⊔ y := eq_of_forall_ge_iff fun c => by simp only [sup_le_iff]; rw [← H, @sup_le_iff α A, H, H] theorem SemilatticeSup.ext {α} {A B : SemilatticeSup α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by cases A cases B cases PartialOrder.ext H congr ext; apply SemilatticeSup.ext_sup H theorem ite_le_sup (s s' : α) (P : Prop) [Decidable P] : ite P s s' ≤ s ⊔ s' := if h : P then (if_pos h).trans_le le_sup_left else (if_neg h).trans_le le_sup_right end SemilatticeSup /-! ### Meet-semilattices -/ /-- A `SemilatticeInf` is a meet-semilattice, that is, a partial order with a meet (a.k.a. glb / greatest lower bound, inf / infimum) operation `⊓` which is the greatest element smaller than both factors. -/ class SemilatticeInf (α : Type u) extends PartialOrder α where /-- The binary infimum, used to derive `Min α` -/ inf : α → α → α /-- The infimum is a lower bound on the first argument -/ protected inf_le_left : ∀ a b : α, inf a b ≤ a /-- The infimum is a lower bound on the second argument -/ protected inf_le_right : ∀ a b : α, inf a b ≤ b /-- The infimum is the *greatest* lower bound -/ protected le_inf : ∀ a b c : α, a ≤ b → a ≤ c → a ≤ inf b c instance SemilatticeInf.toMin [SemilatticeInf α] : Min α where min a b := SemilatticeInf.inf a b instance OrderDual.instSemilatticeSup (α) [SemilatticeInf α] : SemilatticeSup αᵒᵈ where sup := @SemilatticeInf.inf α _ le_sup_left := @SemilatticeInf.inf_le_left α _ le_sup_right := @SemilatticeInf.inf_le_right α _ sup_le := fun _ _ _ hca hcb => @SemilatticeInf.le_inf α _ _ _ _ hca hcb instance OrderDual.instSemilatticeInf (α) [SemilatticeSup α] : SemilatticeInf αᵒᵈ where inf := @SemilatticeSup.sup α _ inf_le_left := @le_sup_left α _ inf_le_right := @le_sup_right α _ le_inf := fun _ _ _ hca hcb => @sup_le α _ _ _ _ hca hcb theorem SemilatticeSup.dual_dual (α : Type*) [H : SemilatticeSup α] : OrderDual.instSemilatticeSup αᵒᵈ = H := SemilatticeSup.ext fun _ _ => Iff.rfl section SemilatticeInf variable [SemilatticeInf α] {a b c d : α} @[simp] theorem inf_le_left : a ⊓ b ≤ a := SemilatticeInf.inf_le_left a b @[simp] theorem inf_le_right : a ⊓ b ≤ b := SemilatticeInf.inf_le_right a b theorem le_inf : a ≤ b → a ≤ c → a ≤ b ⊓ c := SemilatticeInf.le_inf a b c theorem inf_le_of_left_le (h : a ≤ c) : a ⊓ b ≤ c := le_trans inf_le_left h theorem inf_le_of_right_le (h : b ≤ c) : a ⊓ b ≤ c := le_trans inf_le_right h theorem inf_lt_of_left_lt (h : a < c) : a ⊓ b < c := lt_of_le_of_lt inf_le_left h theorem inf_lt_of_right_lt (h : b < c) : a ⊓ b < c := lt_of_le_of_lt inf_le_right h @[simp] theorem le_inf_iff : a ≤ b ⊓ c ↔ a ≤ b ∧ a ≤ c := @sup_le_iff αᵒᵈ _ _ _ _ @[simp] theorem inf_eq_left : a ⊓ b = a ↔ a ≤ b := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem inf_eq_right : a ⊓ b = b ↔ b ≤ a := le_antisymm_iff.trans <| by simp [le_rfl] @[simp] theorem left_eq_inf : a = a ⊓ b ↔ a ≤ b := eq_comm.trans inf_eq_left @[simp] theorem right_eq_inf : b = a ⊓ b ↔ b ≤ a := eq_comm.trans inf_eq_right alias ⟨le_of_inf_eq, inf_of_le_left⟩ := inf_eq_left alias ⟨_, inf_of_le_right⟩ := inf_eq_right attribute [simp] inf_of_le_left inf_of_le_right @[simp] theorem inf_lt_left : a ⊓ b < a ↔ ¬a ≤ b := @left_lt_sup αᵒᵈ _ _ _ @[simp] theorem inf_lt_right : a ⊓ b < b ↔ ¬b ≤ a := @right_lt_sup αᵒᵈ _ _ _ theorem inf_lt_left_or_right (h : a ≠ b) : a ⊓ b < a ∨ a ⊓ b < b := @left_or_right_lt_sup αᵒᵈ _ _ _ h @[gcongr] theorem inf_le_inf (h₁ : a ≤ b) (h₂ : c ≤ d) : a ⊓ c ≤ b ⊓ d := @sup_le_sup αᵒᵈ _ _ _ _ _ h₁ h₂ @[gcongr] theorem inf_le_inf_right (a : α) {b c : α} (h : b ≤ c) : b ⊓ a ≤ c ⊓ a := inf_le_inf h le_rfl @[gcongr] theorem inf_le_inf_left (a : α) {b c : α} (h : b ≤ c) : a ⊓ b ≤ a ⊓ c := inf_le_inf le_rfl h theorem inf_idem (a : α) : a ⊓ a = a := by simp instance : Std.IdempotentOp (α := α) (· ⊓ ·) := ⟨inf_idem⟩ theorem inf_comm (a b : α) : a ⊓ b = b ⊓ a := @sup_comm αᵒᵈ _ _ _ instance : Std.Commutative (α := α) (· ⊓ ·) := ⟨inf_comm⟩ theorem inf_assoc (a b c : α) : a ⊓ b ⊓ c = a ⊓ (b ⊓ c) := @sup_assoc αᵒᵈ _ _ _ _ instance : Std.Associative (α := α) (· ⊓ ·) := ⟨inf_assoc⟩ theorem inf_left_right_swap (a b c : α) : a ⊓ b ⊓ c = c ⊓ b ⊓ a := @sup_left_right_swap αᵒᵈ _ _ _ _ theorem inf_left_idem (a b : α) : a ⊓ (a ⊓ b) = a ⊓ b := by simp theorem inf_right_idem (a b : α) : a ⊓ b ⊓ b = a ⊓ b := by simp theorem inf_left_comm (a b c : α) : a ⊓ (b ⊓ c) = b ⊓ (a ⊓ c) := @sup_left_comm αᵒᵈ _ a b c theorem inf_right_comm (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ b := @sup_right_comm αᵒᵈ _ a b c theorem inf_inf_inf_comm (a b c d : α) : a ⊓ b ⊓ (c ⊓ d) = a ⊓ c ⊓ (b ⊓ d) := @sup_sup_sup_comm αᵒᵈ _ _ _ _ _ theorem inf_inf_distrib_left (a b c : α) : a ⊓ (b ⊓ c) = a ⊓ b ⊓ (a ⊓ c) := @sup_sup_distrib_left αᵒᵈ _ _ _ _ theorem inf_inf_distrib_right (a b c : α) : a ⊓ b ⊓ c = a ⊓ c ⊓ (b ⊓ c) := @sup_sup_distrib_right αᵒᵈ _ _ _ _ theorem inf_congr_left (hb : a ⊓ c ≤ b) (hc : a ⊓ b ≤ c) : a ⊓ b = a ⊓ c := @sup_congr_left αᵒᵈ _ _ _ _ hb hc theorem inf_congr_right (h1 : b ⊓ c ≤ a) (h2 : a ⊓ c ≤ b) : a ⊓ c = b ⊓ c := @sup_congr_right αᵒᵈ _ _ _ _ h1 h2 theorem inf_eq_inf_iff_left : a ⊓ b = a ⊓ c ↔ a ⊓ c ≤ b ∧ a ⊓ b ≤ c := @sup_eq_sup_iff_left αᵒᵈ _ _ _ _ theorem inf_eq_inf_iff_right : a ⊓ c = b ⊓ c ↔ b ⊓ c ≤ a ∧ a ⊓ c ≤ b := @sup_eq_sup_iff_right αᵒᵈ _ _ _ _ theorem Ne.inf_lt_or_inf_lt : a ≠ b → a ⊓ b < a ∨ a ⊓ b < b := @Ne.lt_sup_or_lt_sup αᵒᵈ _ _ _ theorem SemilatticeInf.ext_inf {α} {A B : SemilatticeInf α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) (x y : α) : (haveI := A; x ⊓ y) = x ⊓ y := eq_of_forall_le_iff fun c => by simp only [le_inf_iff]; rw [← H, @le_inf_iff α A, H, H] theorem SemilatticeInf.ext {α} {A B : SemilatticeInf α} (H : ∀ x y : α, (haveI := A; x ≤ y) ↔ x ≤ y) : A = B := by cases A cases B cases PartialOrder.ext H congr ext; apply SemilatticeInf.ext_inf H theorem SemilatticeInf.dual_dual (α : Type*) [H : SemilatticeInf α] : OrderDual.instSemilatticeInf αᵒᵈ = H := SemilatticeInf.ext fun _ _ => Iff.rfl theorem inf_le_ite (s s' : α) (P : Prop) [Decidable P] : s ⊓ s' ≤ ite P s s' := @ite_le_sup αᵒᵈ _ _ _ _ _ end SemilatticeInf /-- A type with a commutative, associative and idempotent binary `inf` operation has the structure of a meet-semilattice. The partial order is defined so that `a ≤ b` unfolds to `b ⊓ a = a`; cf. `inf_eq_right`. -/ def SemilatticeInf.mk' {α : Type*} [Min α] (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a) (inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a) : SemilatticeInf α := by haveI : SemilatticeSup αᵒᵈ := SemilatticeSup.mk' inf_comm inf_assoc inf_idem haveI i := OrderDual.instSemilatticeInf αᵒᵈ exact i /-! ### Lattices -/ /-- A lattice is a join-semilattice which is also a meet-semilattice. -/ class Lattice (α : Type u) extends SemilatticeSup α, SemilatticeInf α instance OrderDual.instLattice (α) [Lattice α] : Lattice αᵒᵈ where /-- The partial orders from `SemilatticeSup_mk'` and `SemilatticeInf_mk'` agree if `sup` and `inf` satisfy the lattice absorption laws `sup_inf_self` (`a ⊔ a ⊓ b = a`) and `inf_sup_self` (`a ⊓ (a ⊔ b) = a`). -/ theorem semilatticeSup_mk'_partialOrder_eq_semilatticeInf_mk'_partialOrder {α : Type*} [Max α] [Min α] (sup_comm : ∀ a b : α, a ⊔ b = b ⊔ a) (sup_assoc : ∀ a b c : α, a ⊔ b ⊔ c = a ⊔ (b ⊔ c)) (sup_idem : ∀ a : α, a ⊔ a = a) (inf_comm : ∀ a b : α, a ⊓ b = b ⊓ a)
(inf_assoc : ∀ a b c : α, a ⊓ b ⊓ c = a ⊓ (b ⊓ c)) (inf_idem : ∀ a : α, a ⊓ a = a)
Mathlib/Order/Lattice.lean
475
475
/- Copyright (c) 2021 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Eric Wieser -/ import Mathlib.LinearAlgebra.Determinant import Mathlib.LinearAlgebra.Dual.Lemmas import Mathlib.LinearAlgebra.FiniteDimensional.Lemmas import Mathlib.LinearAlgebra.Matrix.Diagonal import Mathlib.LinearAlgebra.Matrix.DotProduct import Mathlib.LinearAlgebra.Matrix.Dual /-! # Rank of matrices The rank of a matrix `A` is defined to be the rank of range of the linear map corresponding to `A`. This definition does not depend on the choice of basis, see `Matrix.rank_eq_finrank_range_toLin`. ## Main declarations * `Matrix.rank`: the rank of a matrix * `Matrix.cRank`: the rank of a matrix as a cardinal * `Matrix.eRank`: the rank of a matrix as a term in `ℕ∞`. -/ open Matrix namespace Matrix open Module Cardinal Set Submodule universe ul um um₀ un un₀ uo uR variable {l : Type ul} {m : Type um} {m₀ : Type um₀} {n : Type un} {n₀ : Type un₀} {o : Type uo} variable {R : Type uR} section Infinite variable [Semiring R] /-- The rank of a matrix, defined as the dimension of its column space, as a cardinal. -/ noncomputable def cRank (A : Matrix m n R) : Cardinal := Module.rank R <| span R <| range Aᵀ lemma cRank_toNat_eq_finrank (A : Matrix m n R) : A.cRank.toNat = Module.finrank R (span R (range A.col)) := rfl lemma lift_cRank_submatrix_le (A : Matrix m n R) (r : m₀ → m) (c : n₀ → n) : lift.{um} (A.submatrix r c).cRank ≤ lift.{um₀} A.cRank := by have h : ((A.submatrix r id).submatrix id c).cRank ≤ (A.submatrix r id).cRank := Submodule.rank_mono <| span_mono <| by rintro _ ⟨x, rfl⟩; exact ⟨c x, rfl⟩ refine (Cardinal.lift_monotone h).trans ?_ let f : (m → R) →ₗ[R] (m₀ → R) := LinearMap.funLeft R R r have h_eq : Submodule.map f (span R (range Aᵀ)) = span R (range (A.submatrix r id)ᵀ) := by rw [LinearMap.map_span, ← image_univ, image_image, transpose_submatrix] aesop rw [cRank, ← h_eq] have hwin := lift_rank_map_le f (span R (range Aᵀ)) simp_rw [← lift_umax] at hwin ⊢ exact hwin /-- A special case of `lift_cRank_submatrix_le` for when `m₀` and `m` are in the same universe. -/ lemma cRank_submatrix_le {m m₀ : Type um} (A : Matrix m n R) (r : m₀ → m) (c : n₀ → n) : (A.submatrix r c).cRank ≤ A.cRank := by simpa using lift_cRank_submatrix_le A r c lemma cRank_le_card_height [StrongRankCondition R] [Fintype m] (A : Matrix m n R) : A.cRank ≤ Fintype.card m := (Submodule.rank_le (span R (range Aᵀ))).trans <| by rw [rank_fun'] lemma cRank_le_card_width [StrongRankCondition R] [Fintype n] (A : Matrix m n R) : A.cRank ≤ Fintype.card n := (rank_span_le ..).trans <| by simpa using Cardinal.mk_range_le_lift (f := Aᵀ) /-- The rank of a matrix, defined as the dimension of its column space, as a term in `ℕ∞`. -/ noncomputable def eRank (A : Matrix m n R) : ℕ∞ := A.cRank.toENat
lemma eRank_toNat_eq_finrank (A : Matrix m n R) : A.eRank.toNat = Module.finrank R (span R (range A.col)) := toNat_toENat .. lemma eRank_submatrix_le (A : Matrix m n R) (r : m₀ → m) (c : n₀ → n) :
Mathlib/Data/Matrix/Rank.lean
77
81
/- Copyright (c) 2020 Johan Commelin, Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Robert Y. Lewis -/ import Mathlib.Algebra.Field.ZMod import Mathlib.NumberTheory.Padics.PadicIntegers import Mathlib.RingTheory.LocalRing.ResidueField.Defs import Mathlib.RingTheory.ZMod /-! # Relating `ℤ_[p]` to `ZMod (p ^ n)`, aka `ℤ/p^nℤ`. In this file we establish connections between the `p`-adic integers `ℤ_[p]` and the integers modulo powers of `p`, `ℤ/p^nℤ`, implemented as `ZMod (p^n)`. ## Main declarations We show that `ℤ_[p]` has a ring homomorphism to `ℤ/p^nℤ` for each `n`. The case for `n = 1` is handled separately, since it is used in the general construction and we may want to use it without the `^1` getting in the way. * `PadicInt.toZMod`: ring homomorphism to `ℤ/pℤ`, implemented as `ZMod p`. * `PadicInt.toZModPow`: ring homomorphism to `ℤ/p^nℤ`, implemented as `ZMod (p^n)`. * `PadicInt.ker_toZMod` / `PadicInt.ker_toZModPow`: the kernels of these maps are the ideals generated by `p^n` * `PadicInt.residueField` shows that the residue field of `ℤ_[p]` is isomorhic to ``ℤ/pℤ`. We also establish the universal property of `ℤ_[p]` as a projective limit. Given a family of compatible ring homomorphisms `f_k : R → ℤ/p^nℤ`, there is a unique limit `R → ℤ_[p]` * `PadicInt.lift`: the limit function * `PadicInt.lift_spec` / `PadicInt.lift_unique`: the universal property ## Implementation notes The constructions of the ring homomorphisms go through an auxiliary constructor `PadicInt.toZModHom`, which removes some boilerplate code. -/ noncomputable section open Nat IsLocalRing Padic namespace PadicInt variable {p : ℕ} [hp_prime : Fact p.Prime] section RingHoms /-! ### Ring homomorphisms to `ZMod p` and `ZMod (p ^ n)` -/ variable (p) (r : ℚ) /-- `modPart p r` is an integer that satisfies `‖(r - modPart p r : ℚ_[p])‖ < 1` when `‖(r : ℚ_[p])‖ ≤ 1`, see `PadicInt.norm_sub_modPart`. It is the unique non-negative integer that is `< p` with this property. (Note that this definition assumes `r : ℚ`. See `PadicInt.zmodRepr` for a version that takes values in `ℕ` and works for arbitrary `x : ℤ_[p]`.) -/ def modPart : ℤ := r.num * gcdA r.den p % p variable {p} theorem modPart_lt_p : modPart p r < p := by convert Int.emod_lt_abs _ _ · simp · exact mod_cast hp_prime.1.ne_zero theorem modPart_nonneg : 0 ≤ modPart p r := Int.emod_nonneg _ <| mod_cast hp_prime.1.ne_zero theorem isUnit_den (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : IsUnit (r.den : ℤ_[p]) := by rw [isUnit_iff] apply le_antisymm (r.den : ℤ_[p]).2 rw [← not_lt, coe_natCast] intro norm_denom_lt have hr : ‖(r * r.den : ℚ_[p])‖ = ‖(r.num : ℚ_[p])‖ := by congr rw_mod_cast [@Rat.mul_den_eq_num r] rw [padicNormE.mul] at hr have key : ‖(r.num : ℚ_[p])‖ < 1 := by calc _ = _ := hr.symm _ < 1 * 1 := mul_lt_mul' h norm_denom_lt (norm_nonneg _) zero_lt_one _ = 1 := mul_one 1 have : ↑p ∣ r.num ∧ (p : ℤ) ∣ r.den := by simp only [← norm_int_lt_one_iff_dvd, ← padic_norm_e_of_padicInt] exact ⟨key, norm_denom_lt⟩ apply hp_prime.1.not_dvd_one rwa [← r.reduced.gcd_eq_one, Nat.dvd_gcd_iff, ← Int.natCast_dvd, ← Int.natCast_dvd_natCast] theorem norm_sub_modPart_aux (r : ℚ) (h : ‖(r : ℚ_[p])‖ ≤ 1) : ↑p ∣ r.num - r.num * r.den.gcdA p % p * ↑r.den := by rw [← ZMod.intCast_zmod_eq_zero_iff_dvd] simp only [Int.cast_natCast, ZMod.natCast_mod, Int.cast_mul, Int.cast_sub] have := congr_arg (fun x => x % p : ℤ → ZMod p) (gcd_eq_gcd_ab r.den p) simp only [Int.cast_natCast, CharP.cast_eq_zero, EuclideanDomain.mod_zero, Int.cast_add, Int.cast_mul, zero_mul, add_zero] at this push_cast rw [mul_right_comm, mul_assoc, ← this] suffices rdcp : r.den.Coprime p by rw [rdcp.gcd_eq_one] simp only [mul_one, cast_one, sub_self] apply Coprime.symm apply (coprime_or_dvd_of_prime hp_prime.1 _).resolve_right rw [← Int.natCast_dvd_natCast, ← norm_int_lt_one_iff_dvd, not_lt] apply ge_of_eq rw [← isUnit_iff] exact isUnit_den r h theorem norm_sub_modPart (h : ‖(r : ℚ_[p])‖ ≤ 1) : ‖(⟨r, h⟩ - modPart p r : ℤ_[p])‖ < 1 := by let n := modPart p r rw [norm_lt_one_iff_dvd, ← (isUnit_den r h).dvd_mul_right] suffices ↑p ∣ r.num - n * r.den by convert (Int.castRingHom ℤ_[p]).map_dvd this
simp only [n, sub_mul, Int.cast_natCast, eq_intCast, Int.cast_mul, sub_left_inj, Int.cast_sub] apply Subtype.coe_injective simp only [coe_mul, Subtype.coe_mk, coe_natCast] rw_mod_cast [@Rat.mul_den_eq_num r] rfl exact norm_sub_modPart_aux r h theorem exists_mem_range_of_norm_rat_le_one (h : ‖(r : ℚ_[p])‖ ≤ 1) : ∃ n : ℤ, 0 ≤ n ∧ n < p ∧ ‖(⟨r, h⟩ - n : ℤ_[p])‖ < 1 := ⟨modPart p r, modPart_nonneg _, modPart_lt_p _, norm_sub_modPart _ h⟩
Mathlib/NumberTheory/Padics/RingHoms.lean
124
134
/- Copyright (c) 2015 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Jeremy Avigad -/ import Mathlib.Data.Finset.Basic import Mathlib.Data.Finset.Image /-! # Cardinality of a finite set This defines the cardinality of a `Finset` and provides induction principles for finsets. ## Main declarations * `Finset.card`: `#s : ℕ` returns the cardinality of `s : Finset α`. ### Induction principles * `Finset.strongInduction`: Strong induction * `Finset.strongInductionOn` * `Finset.strongDownwardInduction` * `Finset.strongDownwardInductionOn` * `Finset.case_strong_induction_on` * `Finset.Nonempty.strong_induction` -/ assert_not_exists Monoid open Function Multiset Nat variable {α β R : Type*} namespace Finset variable {s t : Finset α} {a b : α} /-- `s.card` is the number of elements of `s`, aka its cardinality. The notation `#s` can be accessed in the `Finset` locale. -/ def card (s : Finset α) : ℕ := Multiset.card s.1 @[inherit_doc] scoped prefix:arg "#" => Finset.card theorem card_def (s : Finset α) : #s = Multiset.card s.1 := rfl @[simp] lemma card_val (s : Finset α) : Multiset.card s.1 = #s := rfl @[simp] theorem card_mk {m nodup} : #(⟨m, nodup⟩ : Finset α) = Multiset.card m := rfl @[simp] theorem card_empty : #(∅ : Finset α) = 0 := rfl @[gcongr] theorem card_le_card : s ⊆ t → #s ≤ #t := Multiset.card_le_card ∘ val_le_iff.mpr @[mono] theorem card_mono : Monotone (@card α) := by apply card_le_card @[simp] lemma card_eq_zero : #s = 0 ↔ s = ∅ := Multiset.card_eq_zero.trans val_eq_zero lemma card_ne_zero : #s ≠ 0 ↔ s.Nonempty := card_eq_zero.ne.trans nonempty_iff_ne_empty.symm @[simp] lemma card_pos : 0 < #s ↔ s.Nonempty := Nat.pos_iff_ne_zero.trans card_ne_zero @[simp] lemma one_le_card : 1 ≤ #s ↔ s.Nonempty := card_pos alias ⟨_, Nonempty.card_pos⟩ := card_pos alias ⟨_, Nonempty.card_ne_zero⟩ := card_ne_zero theorem card_ne_zero_of_mem (h : a ∈ s) : #s ≠ 0 := (not_congr card_eq_zero).2 <| ne_empty_of_mem h @[simp] theorem card_singleton (a : α) : #{a} = 1 := Multiset.card_singleton _ theorem card_singleton_inter [DecidableEq α] : #({a} ∩ s) ≤ 1 := by obtain h | h := Finset.decidableMem a s · simp [Finset.singleton_inter_of_not_mem h] · simp [Finset.singleton_inter_of_mem h] @[simp] theorem card_cons (h : a ∉ s) : #(s.cons a h) = #s + 1 := Multiset.card_cons _ _ section InsertErase variable [DecidableEq α] @[simp] theorem card_insert_of_not_mem (h : a ∉ s) : #(insert a s) = #s + 1 := by rw [← cons_eq_insert _ _ h, card_cons] theorem card_insert_of_mem (h : a ∈ s) : #(insert a s) = #s := by rw [insert_eq_of_mem h] theorem card_insert_le (a : α) (s : Finset α) : #(insert a s) ≤ #s + 1 := by by_cases h : a ∈ s · rw [insert_eq_of_mem h] exact Nat.le_succ _ · rw [card_insert_of_not_mem h] section variable {a b c d e f : α} theorem card_le_two : #{a, b} ≤ 2 := card_insert_le _ _ theorem card_le_three : #{a, b, c} ≤ 3 := (card_insert_le _ _).trans (Nat.succ_le_succ card_le_two) theorem card_le_four : #{a, b, c, d} ≤ 4 := (card_insert_le _ _).trans (Nat.succ_le_succ card_le_three) theorem card_le_five : #{a, b, c, d, e} ≤ 5 := (card_insert_le _ _).trans (Nat.succ_le_succ card_le_four) theorem card_le_six : #{a, b, c, d, e, f} ≤ 6 := (card_insert_le _ _).trans (Nat.succ_le_succ card_le_five) end /-- If `a ∈ s` is known, see also `Finset.card_insert_of_mem` and `Finset.card_insert_of_not_mem`. -/ theorem card_insert_eq_ite : #(insert a s) = if a ∈ s then #s else #s + 1 := by by_cases h : a ∈ s · rw [card_insert_of_mem h, if_pos h] · rw [card_insert_of_not_mem h, if_neg h] @[simp] theorem card_pair_eq_one_or_two : #{a, b} = 1 ∨ #{a, b} = 2 := by simp [card_insert_eq_ite] tauto @[simp] theorem card_pair (h : a ≠ b) : #{a, b} = 2 := by rw [card_insert_of_not_mem (not_mem_singleton.2 h), card_singleton] /-- $\#(s \setminus \{a\}) = \#s - 1$ if $a \in s$. -/ @[simp] theorem card_erase_of_mem : a ∈ s → #(s.erase a) = #s - 1 := Multiset.card_erase_of_mem @[simp] theorem card_erase_add_one : a ∈ s → #(s.erase a) + 1 = #s := Multiset.card_erase_add_one theorem card_erase_lt_of_mem : a ∈ s → #(s.erase a) < #s := Multiset.card_erase_lt_of_mem theorem card_erase_le : #(s.erase a) ≤ #s := Multiset.card_erase_le theorem pred_card_le_card_erase : #s - 1 ≤ #(s.erase a) := by by_cases h : a ∈ s · exact (card_erase_of_mem h).ge · rw [erase_eq_of_not_mem h] exact Nat.sub_le _ _ /-- If `a ∈ s` is known, see also `Finset.card_erase_of_mem` and `Finset.erase_eq_of_not_mem`. -/ theorem card_erase_eq_ite : #(s.erase a) = if a ∈ s then #s - 1 else #s := Multiset.card_erase_eq_ite end InsertErase @[simp] theorem card_range (n : ℕ) : #(range n) = n := Multiset.card_range n @[simp] theorem card_attach : #s.attach = #s := Multiset.card_attach end Finset open scoped Finset section ToMLListultiset variable [DecidableEq α] (m : Multiset α) (l : List α) theorem Multiset.card_toFinset : #m.toFinset = Multiset.card m.dedup := rfl theorem Multiset.toFinset_card_le : #m.toFinset ≤ Multiset.card m := card_le_card <| dedup_le _ theorem Multiset.toFinset_card_of_nodup {m : Multiset α} (h : m.Nodup) : #m.toFinset = Multiset.card m := congr_arg card <| Multiset.dedup_eq_self.mpr h theorem Multiset.dedup_card_eq_card_iff_nodup {m : Multiset α} : card m.dedup = card m ↔ m.Nodup := .trans ⟨fun h ↦ eq_of_le_of_card_le (dedup_le m) h.ge, congr_arg _⟩ dedup_eq_self theorem Multiset.toFinset_card_eq_card_iff_nodup {m : Multiset α} : #m.toFinset = card m ↔ m.Nodup := dedup_card_eq_card_iff_nodup theorem List.card_toFinset : #l.toFinset = l.dedup.length := rfl theorem List.toFinset_card_le : #l.toFinset ≤ l.length := Multiset.toFinset_card_le ⟦l⟧ theorem List.toFinset_card_of_nodup {l : List α} (h : l.Nodup) : #l.toFinset = l.length := Multiset.toFinset_card_of_nodup h end ToMLListultiset namespace Finset variable {s t u : Finset α} {f : α → β} {n : ℕ} @[simp] theorem length_toList (s : Finset α) : s.toList.length = #s := by rw [toList, ← Multiset.coe_card, Multiset.coe_toList, card_def] theorem card_image_le [DecidableEq β] : #(s.image f) ≤ #s := by simpa only [card_map] using (s.1.map f).toFinset_card_le theorem card_image_of_injOn [DecidableEq β] (H : Set.InjOn f s) : #(s.image f) = #s := by simp only [card, image_val_of_injOn H, card_map] theorem injOn_of_card_image_eq [DecidableEq β] (H : #(s.image f) = #s) : Set.InjOn f s := by rw [card_def, card_def, image, toFinset] at H dsimp only at H have : (s.1.map f).dedup = s.1.map f := by refine Multiset.eq_of_le_of_card_le (Multiset.dedup_le _) ?_ simp only [H, Multiset.card_map, le_rfl] rw [Multiset.dedup_eq_self] at this exact inj_on_of_nodup_map this theorem card_image_iff [DecidableEq β] : #(s.image f) = #s ↔ Set.InjOn f s := ⟨injOn_of_card_image_eq, card_image_of_injOn⟩ theorem card_image_of_injective [DecidableEq β] (s : Finset α) (H : Injective f) : #(s.image f) = #s := card_image_of_injOn fun _ _ _ _ h => H h theorem fiber_card_ne_zero_iff_mem_image (s : Finset α) (f : α → β) [DecidableEq β] (y : β) : #(s.filter fun x ↦ f x = y) ≠ 0 ↔ y ∈ s.image f := by rw [← Nat.pos_iff_ne_zero, card_pos, fiber_nonempty_iff_mem_image] lemma card_filter_le_iff (s : Finset α) (P : α → Prop) [DecidablePred P] (n : ℕ) : #(s.filter P) ≤ n ↔ ∀ s' ⊆ s, n < #s' → ∃ a ∈ s', ¬ P a := (s.1.card_filter_le_iff P n).trans ⟨fun H s' hs' h ↦ H s'.1 (by aesop) h, fun H s' hs' h ↦ H ⟨s', nodup_of_le hs' s.2⟩ (fun _ hx ↦ Multiset.subset_of_le hs' hx) h⟩ @[simp] theorem card_map (f : α ↪ β) : #(s.map f) = #s := Multiset.card_map _ _ @[simp] theorem card_subtype (p : α → Prop) [DecidablePred p] (s : Finset α) : #(s.subtype p) = #(s.filter p) := by simp [Finset.subtype] theorem card_filter_le (s : Finset α) (p : α → Prop) [DecidablePred p] : #(s.filter p) ≤ #s := card_le_card <| filter_subset _ _ theorem eq_of_subset_of_card_le {s t : Finset α} (h : s ⊆ t) (h₂ : #t ≤ #s) : s = t := eq_of_veq <| Multiset.eq_of_le_of_card_le (val_le_iff.mpr h) h₂ theorem eq_iff_card_le_of_subset (hst : s ⊆ t) : #t ≤ #s ↔ s = t := ⟨eq_of_subset_of_card_le hst, (ge_of_eq <| congr_arg _ ·)⟩ theorem eq_of_superset_of_card_ge (hst : s ⊆ t) (hts : #t ≤ #s) : t = s := (eq_of_subset_of_card_le hst hts).symm theorem eq_iff_card_ge_of_superset (hst : s ⊆ t) : #t ≤ #s ↔ t = s := (eq_iff_card_le_of_subset hst).trans eq_comm theorem subset_iff_eq_of_card_le (h : #t ≤ #s) : s ⊆ t ↔ s = t := ⟨fun hst => eq_of_subset_of_card_le hst h, Eq.subset'⟩ theorem map_eq_of_subset {f : α ↪ α} (hs : s.map f ⊆ s) : s.map f = s := eq_of_subset_of_card_le hs (card_map _).ge theorem card_filter_eq_iff {p : α → Prop} [DecidablePred p] : #(s.filter p) = #s ↔ ∀ x ∈ s, p x := by rw [(card_filter_le s p).eq_iff_not_lt, not_lt, eq_iff_card_le_of_subset (filter_subset p s), filter_eq_self] alias ⟨filter_card_eq, _⟩ := card_filter_eq_iff theorem card_filter_eq_zero_iff {p : α → Prop} [DecidablePred p] : #(s.filter p) = 0 ↔ ∀ x ∈ s, ¬ p x := by rw [card_eq_zero, filter_eq_empty_iff] nonrec lemma card_lt_card (h : s ⊂ t) : #s < #t := card_lt_card <| val_lt_iff.2 h lemma card_strictMono : StrictMono (card : Finset α → ℕ) := fun _ _ ↦ card_lt_card theorem card_eq_of_bijective (f : ∀ i, i < n → α) (hf : ∀ a ∈ s, ∃ i, ∃ h : i < n, f i h = a) (hf' : ∀ i (h : i < n), f i h ∈ s) (f_inj : ∀ i j (hi : i < n) (hj : j < n), f i hi = f j hj → i = j) : #s = n := by classical have : s = (range n).attach.image fun i => f i.1 (mem_range.1 i.2) := by ext a suffices _ : a ∈ s ↔ ∃ (i : _) (hi : i ∈ range n), f i (mem_range.1 hi) = a by simpa only [mem_image, mem_attach, true_and, Subtype.exists] constructor · intro ha; obtain ⟨i, hi, rfl⟩ := hf a ha; use i, mem_range.2 hi · rintro ⟨i, hi, rfl⟩; apply hf' calc #s = #((range n).attach.image fun i => f i.1 (mem_range.1 i.2)) := by rw [this] _ = #(range n).attach := ?_ _ = #(range n) := card_attach _ = n := card_range n apply card_image_of_injective intro ⟨i, hi⟩ ⟨j, hj⟩ eq exact Subtype.eq <| f_inj i j (mem_range.1 hi) (mem_range.1 hj) eq section bij variable {t : Finset β} /-- Reorder a finset. The difference with `Finset.card_bij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.card_nbij` is that the bijection is allowed to use membership of the domain, rather than being a non-dependent function. -/ lemma card_bij (i : ∀ a ∈ s, β) (hi : ∀ a ha, i a ha ∈ t) (i_inj : ∀ a₁ ha₁ a₂ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, ∃ a ha, i a ha = b) : #s = #t := by classical calc #s = #s.attach := card_attach.symm _ = #(s.attach.image fun a ↦ i a.1 a.2) := Eq.symm ?_ _ = #t := ?_ · apply card_image_of_injective intro ⟨_, _⟩ ⟨_, _⟩ h simpa using i_inj _ _ _ _ h · congr 1 ext b constructor <;> intro h · obtain ⟨_, _, rfl⟩ := mem_image.1 h; apply hi · obtain ⟨a, ha, rfl⟩ := i_surj b h; exact mem_image.2 ⟨⟨a, ha⟩, by simp⟩ /-- Reorder a finset. The difference with `Finset.card_bij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.card_nbij'` is that the bijection and its inverse are allowed to use membership of the domains, rather than being non-dependent functions. -/ lemma card_bij' (i : ∀ a ∈ s, β) (j : ∀ a ∈ t, α) (hi : ∀ a ha, i a ha ∈ t) (hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a) (right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) : #s = #t := by refine card_bij i hi (fun a1 h1 a2 h2 eq ↦ ?_) (fun b hb ↦ ⟨_, hj b hb, right_inv b hb⟩) rw [← left_inv a1 h1, ← left_inv a2 h2] simp only [eq] /-- Reorder a finset. The difference with `Finset.card_nbij'` is that the bijection is specified as a surjective injection, rather than by an inverse function. The difference with `Finset.card_bij` is that the bijection is a non-dependent function, rather than being allowed to use membership of the domain. -/ lemma card_nbij (i : α → β) (hi : ∀ a ∈ s, i a ∈ t) (i_inj : (s : Set α).InjOn i) (i_surj : (s : Set α).SurjOn i t) : #s = #t := card_bij (fun a _ ↦ i a) hi i_inj (by simpa using i_surj) /-- Reorder a finset. The difference with `Finset.card_nbij` is that the bijection is specified with an inverse, rather than as a surjective injection. The difference with `Finset.card_bij'` is that the bijection and its inverse are non-dependent functions, rather than being allowed to use membership of the domains. The difference with `Finset.card_equiv` is that bijectivity is only required to hold on the domains, rather than on the entire types. -/ lemma card_nbij' (i : α → β) (j : β → α) (hi : ∀ a ∈ s, i a ∈ t) (hj : ∀ a ∈ t, j a ∈ s) (left_inv : ∀ a ∈ s, j (i a) = a) (right_inv : ∀ a ∈ t, i (j a) = a) : #s = #t := card_bij' (fun a _ ↦ i a) (fun b _ ↦ j b) hi hj left_inv right_inv /-- Specialization of `Finset.card_nbij'` that automatically fills in most arguments. See `Fintype.card_equiv` for the version where `s` and `t` are `univ`. -/ lemma card_equiv (e : α ≃ β) (hst : ∀ i, i ∈ s ↔ e i ∈ t) : #s = #t := by refine card_nbij' e e.symm ?_ ?_ ?_ ?_ <;> simp [hst] /-- Specialization of `Finset.card_nbij` that automatically fills in most arguments. See `Fintype.card_bijective` for the version where `s` and `t` are `univ`. -/ lemma card_bijective (e : α → β) (he : e.Bijective) (hst : ∀ i, i ∈ s ↔ e i ∈ t) : #s = #t := card_equiv (.ofBijective e he) hst
lemma card_le_card_of_injOn (f : α → β) (hf : ∀ a ∈ s, f a ∈ t) (f_inj : (s : Set α).InjOn f) : #s ≤ #t := by classical calc #s = #(s.image f) := (card_image_of_injOn f_inj).symm _ ≤ #t := card_le_card <| image_subset_iff.2 hf lemma card_le_card_of_injective {f : s → t} (hf : f.Injective) : #s ≤ #t := by rcases s.eq_empty_or_nonempty with rfl | ⟨a₀, ha₀⟩ · simp · classical let f' : α → β := fun a => f (if ha : a ∈ s then ⟨a, ha⟩ else ⟨a₀, ha₀⟩) apply card_le_card_of_injOn f'
Mathlib/Data/Finset/Card.lean
394
406
/- 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.Algebra.Field.NegOnePow import Mathlib.Algebra.Field.Periodic import Mathlib.Algebra.QuadraticDiscriminant import Mathlib.Analysis.SpecialFunctions.Exp /-! # Trigonometric functions ## Main definitions This file contains the definition of `π`. See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions. See also `Analysis.SpecialFunctions.Complex.Arg` and `Analysis.SpecialFunctions.Complex.Log` for the complex argument function and the complex logarithm. ## Main statements Many basic inequalities on the real trigonometric functions are established. The continuity of the usual trigonometric functions is proved. Several facts about the real trigonometric functions have the proofs deferred to `Analysis.SpecialFunctions.Trigonometric.Complex`, as they are most easily proved by appealing to the corresponding fact for complex trigonometric functions. See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas in terms of Chebyshev polynomials. ## Tags sin, cos, tan, angle -/ noncomputable section open Topology Filter Set namespace Complex @[continuity, fun_prop] theorem continuous_sin : Continuous sin := by change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2 fun_prop @[fun_prop] theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := by change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2 fun_prop @[fun_prop] theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := by change Continuous fun z => (exp z - exp (-z)) / 2 fun_prop @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := by change Continuous fun z => (exp z + exp (-z)) / 2 fun_prop end Complex namespace Real variable {x y z : ℝ} @[continuity, fun_prop] theorem continuous_sin : Continuous sin := Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_sin {s} : ContinuousOn sin s := continuous_sin.continuousOn @[continuity, fun_prop] theorem continuous_cos : Continuous cos := Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal) @[fun_prop] theorem continuousOn_cos {s} : ContinuousOn cos s := continuous_cos.continuousOn @[continuity, fun_prop] theorem continuous_sinh : Continuous sinh := Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal) @[continuity, fun_prop] theorem continuous_cosh : Continuous cosh := Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal) end Real namespace Real theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 := intermediate_value_Icc' (by norm_num) continuousOn_cos ⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩ /-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. Denoted `π`, once the `Real` namespace is opened. -/ protected noncomputable def pi : ℝ := 2 * Classical.choose exists_cos_eq_zero @[inherit_doc] scoped notation "π" => Real.pi @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).2 theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.1 theorem pi_div_two_le_two : π / 2 ≤ 2 := by rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)] exact (Classical.choose_spec exists_cos_eq_zero).1.2 theorem two_le_pi : (2 : ℝ) ≤ π := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two) theorem pi_le_four : π ≤ 4 := (div_le_div_iff_of_pos_right (show (0 : ℝ) < 2 by norm_num)).1 (calc π / 2 ≤ 2 := pi_div_two_le_two _ = 4 / 2 := by norm_num) @[bound] theorem pi_pos : 0 < π := lt_of_lt_of_le (by norm_num) two_le_pi @[bound] theorem pi_nonneg : 0 ≤ π := pi_pos.le theorem pi_ne_zero : π ≠ 0 := pi_pos.ne' theorem pi_div_two_pos : 0 < π / 2 := half_pos pi_pos theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos] end Real namespace Mathlib.Meta.Positivity open Lean.Meta Qq /-- Extension for the `positivity` tactic: `π` is always positive. -/ @[positivity Real.pi] def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(Real.pi) => assertInstancesCommute pure (.positive q(Real.pi_pos)) | _, _, _ => throwError "not Real.pi" end Mathlib.Meta.Positivity namespace NNReal open Real open Real NNReal /-- `π` considered as a nonnegative real. -/ noncomputable def pi : ℝ≥0 := ⟨π, Real.pi_pos.le⟩ @[simp] theorem coe_real_pi : (pi : ℝ) = π := rfl theorem pi_pos : 0 < pi := mod_cast Real.pi_pos theorem pi_ne_zero : pi ≠ 0 := pi_pos.ne' end NNReal namespace Real @[simp] theorem sin_pi : sin π = 0 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two] norm_num @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul @[simp] theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x := sin_antiperiodic x @[simp] theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x := sin_periodic x @[simp] theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x @[simp] theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x @[simp] theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' @[simp] theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' @[simp] theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n @[simp] theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x @[simp] theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x @[simp] theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n @[simp] theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n @[simp] theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n @[simp] theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x := sin_antiperiodic.add_nat_mul_eq n theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x := n.cast_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x := sin_antiperiodic.sub_nat_mul_eq n theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg, Int.cast_negOnePow] using sin_antiperiodic.int_mul_sub_eq n theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul @[simp] theorem abs_cos_int_mul_pi (k : ℤ) : |cos (k * π)| = 1 := by simp [abs_cos_eq_sqrt_one_sub_sin_sq] @[simp] theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x := cos_antiperiodic x @[simp] theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x := cos_periodic x @[simp] theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x @[simp] theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x @[simp] theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' @[simp] theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' @[simp] theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero @[simp] theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero @[simp] theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x @[simp] theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x @[simp] theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_nat_mul_eq n @[simp] theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n @[simp] theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.nat_mul_sub_eq n @[simp] theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x := cos_neg x ▸ cos_periodic.int_mul_sub_eq n theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x := cos_antiperiodic.add_nat_mul_eq n theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x := cos_antiperiodic.sub_nat_mul_eq n theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x := n.cast_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x := cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x := if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2 else have : (2 : ℝ) + 2 = 4 := by norm_num have : π - x ≤ 2 := sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _)) sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x := sin_pos_of_pos_of_lt_pi hx.1 hx.2 theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by rw [← closure_Ioo pi_ne_zero.symm] at hx exact closure_lt_subset_le continuous_const continuous_sin (closure_mono (fun y => sin_pos_of_mem_Ioo) hx) theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x := sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩ theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 := neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx) theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 := neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx) @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2) this.resolve_right fun h => show ¬(0 : ℝ) < -1 by norm_num <| h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos) theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add] theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add] theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add] theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add] theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add] theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by rw [← cos_neg, neg_sub, cos_sub_pi_div_two] theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x := sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x := sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩ theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : 0 ≤ cos x := cos_nonneg_of_mem_Icc ⟨hl, hu⟩ theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) : cos x < 0 := neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩ theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) : cos x ≤ 0 := neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩ theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) : sin x = √(1 - cos x ^ 2) := by rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)] theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) : cos x = √(1 - sin x ^ 2) := by rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)] lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves] lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div] lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) : sin (x / 2) = sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonneg] apply sin_nonneg_of_nonneg_of_le_pi <;> linarith lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) : sin (x / 2) = -sqrt ((1 - cos x) / 2) := by rw [← abs_sin_half, abs_of_nonpos, neg_neg] apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 := ⟨fun h => by contrapose! h cases h.lt_or_lt with | inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne | inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne', fun h => by simp [h]⟩ theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x := ⟨fun h => ⟨⌊x / π⌋, le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos)) (sub_nonpos.1 <| le_of_not_gt fun h₃ => (sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne (by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩, fun ⟨_, hn⟩ => hn ▸ sin_int_mul_pi _⟩ theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by rw [← not_exists, not_iff_not, sin_eq_zero_iff] theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x := ⟨fun h => let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h)) ⟨n / 2, (Int.emod_two_eq_zero_or_one n).elim (fun hn0 => by rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul, Int.ediv_mul_cancel (Int.dvd_iff_emod_eq_zero.2 hn0)]) fun hn1 => by rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm, mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn rw [← hn, cos_int_mul_two_pi_add_pi] at h exact absurd h (by norm_num)⟩, fun ⟨_, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩ theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) : cos x = 1 ↔ x = 0 := ⟨fun h => by rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩ rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂ rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁ norm_cast at hx₁ hx₂ obtain rfl : n = 0 := le_antisymm (by omega) (by omega) simp, fun h => by simp [h]⟩ theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : sin x < sin y := by rw [← sub_pos, sin_sub_sin] have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith positivity theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy => sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) : cos y < cos x := by rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub] apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2) (hxy : x < y) : cos y < cos x := cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy => cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) : cos y ≤ cos x := (strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2) (hxy : x ≤ y) : sin x ≤ sin y := (strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) := strictMonoOn_sin.injOn theorem injOn_cos : InjOn cos (Icc 0 π) := strictAntiOn_cos.injOn theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by simpa only [sin_neg, sin_pi_div_two] using intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_sin x, sin_le_one x⟩ theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 := ⟨neg_one_le_cos x, cos_le_one x⟩ theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := ⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩ theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) := ⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩ @[simp] theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range @[simp] theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) := Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range theorem range_cos_infinite : (range Real.cos).Infinite := by rw [Real.range_cos] exact Icc_infinite (by norm_num) theorem range_sin_infinite : (range Real.sin).Infinite := by rw [Real.range_sin] exact Icc_infinite (by norm_num) section CosDivSq variable (x : ℝ) /-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots, starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2` -/ @[simp] noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ | 0 => x | n + 1 => √(2 + sqrtTwoAddSeries x n) theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n | 0 => le_refl 0 | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n | 0 => h | _ + 1 => sqrt_nonneg _ theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2 | 0 => by norm_num | n + 1 => by refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt'] · refine (sqrtTwoAddSeries_lt_two n).trans_le ?_ norm_num · exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n) theorem sqrtTwoAddSeries_succ (x : ℝ) : ∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n | 0 => rfl | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries] theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) : ∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n | 0 => h | n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries] exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _) @[simp] theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2 | 0 => by simp | n + 1 => by have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow₀ one_lt_two n.succ_ne_zero have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A have C : 0 < π / 2 ^ (n + 1) := by positivity rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries, add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;> linarith [sqrtTwoAddSeries_nonneg le_rfl n] theorem sin_sq_pi_over_two_pow (n : ℕ) : sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by rw [sin_sq, cos_pi_over_two_pow] theorem sin_sq_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub] · congr · norm_num · norm_num · exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _) @[simp] theorem sin_pi_over_two_pow_succ (n : ℕ) : sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_eq_sq, mul_pow, sin_sq_pi_over_two_pow_succ, sub_mul] · congr <;> norm_num · rw [sub_nonneg] exact (sqrtTwoAddSeries_lt_two _).le refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two · positivity · exact div_le_self pi_pos.le <| one_le_pow₀ one_le_two @[simp] theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by trans cos (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by trans sin (π / 2 ^ 2) · congr norm_num · simp @[simp] theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by trans cos (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by trans sin (π / 2 ^ 3) · congr norm_num · simp @[simp] theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by trans cos (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by trans sin (π / 2 ^ 4) · congr norm_num · simp @[simp] theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by trans cos (π / 2 ^ 5) · congr norm_num · simp @[simp] theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by trans sin (π / 2 ^ 5) · congr norm_num · simp -- This section is also a convenient location for other explicit values of `sin` and `cos`. /-- The cosine of `π / 3` is `1 / 2`. -/ @[simp] theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by have : cos (3 * (π / 3)) = cos π := by congr 1 ring linarith [cos_pi, cos_three_mul (π / 3)] rcases mul_eq_zero.mp h₁ with h | h · linarith [pow_eq_zero h] · have : cos π < cos (π / 3) := by refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos] linarith [cos_pi] /-- The cosine of `π / 6` is `√3 / 2`. -/ @[simp] theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div, ← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos] /-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num /-- The sine of `π / 6` is `1 / 2`. -/ @[simp] theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_three] congr ring /-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the result for cosine itself). -/ theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six] congr ring /-- The sine of `π / 3` is `√3 / 2`. -/ @[simp] theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by rw [← cos_pi_div_two_sub, ← cos_pi_div_six] congr ring theorem quadratic_root_cos_pi_div_five : letI c := cos (π / 5) 4 * c ^ 2 - 2 * c - 1 = 0 := by set θ := π / 5 with hθ set c := cos θ set s := sin θ suffices 2 * c = 4 * c ^ 2 - 1 by simp [this] have hs : s ≠ 0 := by rw [ne_eq, sin_eq_zero_iff, hθ] push_neg intro n hn replace hn : n * 5 = 1 := by field_simp [mul_comm _ π, mul_assoc] at hn; norm_cast at hn omega suffices s * (2 * c) = s * (4 * c ^ 2 - 1) from mul_left_cancel₀ hs this calc s * (2 * c) = 2 * s * c := by rw [← mul_assoc, mul_comm 2] _ = sin (2 * θ) := by rw [sin_two_mul] _ = sin (π - 2 * θ) := by rw [sin_pi_sub] _ = sin (2 * θ + θ) := by congr; field_simp [hθ]; linarith _ = sin (2 * θ) * c + cos (2 * θ) * s := sin_add (2 * θ) θ _ = 2 * s * c * c + cos (2 * θ) * s := by rw [sin_two_mul] _ = 2 * s * c * c + (2 * c ^ 2 - 1) * s := by rw [cos_two_mul] _ = s * (2 * c * c) + s * (2 * c ^ 2 - 1) := by linarith _ = s * (4 * c ^ 2 - 1) := by linarith open Polynomial in theorem Polynomial.isRoot_cos_pi_div_five : (4 • X ^ 2 - 2 • X - C 1 : ℝ[X]).IsRoot (cos (π / 5)) := by simpa using quadratic_root_cos_pi_div_five /-- The cosine of `π / 5` is `(1 + √5) / 4`. -/ @[simp] theorem cos_pi_div_five : cos (π / 5) = (1 + √5) / 4 := by set c := cos (π / 5) have : 4 * (c * c) + (-2) * c + (-1) = 0 := by rw [← sq, neg_mul, ← sub_eq_add_neg, ← sub_eq_add_neg] exact quadratic_root_cos_pi_div_five have hd : discrim 4 (-2) (-1) = (2 * √5) * (2 * √5) := by norm_num [discrim, mul_mul_mul_comm] rcases (quadratic_eq_zero_iff (by norm_num) hd c).mp this with h | h · field_simp [h]; linarith · absurd (show 0 ≤ c from cos_nonneg_of_mem_Icc <| by constructor <;> linarith [pi_pos.le]) rw [not_le, h] exact div_neg_of_neg_of_pos (by norm_num [lt_sqrt]) (by positivity) end CosDivSq /-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/ def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 := (strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq @[simp] theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x := rfl theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ := rfl @[simp] theorem tan_pi_div_four : tan (π / 4) = 1 := by rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four] have h : √2 / 2 > 0 := by positivity exact div_self (ne_of_gt h) @[simp] theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos] @[simp] theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six] ring @[simp] theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three] ring theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by rw [tan_eq_sin_div_cos] exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩) theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x := match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with | Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp) | Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos] | Or.inr hx0, _ => by simp [hx0.symm] theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 := neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos])) theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) : tan x ≤ 0 := neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith)) theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(π / 2)) (π / 2)) := by rintro x hx y hy hlt rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, div_lt_div_iff₀ (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub] exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2] theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := strictMonoOn_tan ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩ hxy theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2) (hxy : x < y) : tan x < tan y := tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hy₂ hxy theorem injOn_tan : InjOn tan (Ioo (-(π / 2)) (π / 2)) := strictMonoOn_tan.injOn theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) (hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y := injOn_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy theorem tan_periodic : Function.Periodic tan π := by simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic @[simp] theorem tan_pi : tan π = 0 := by rw [tan_periodic.eq, tan_zero] theorem tan_add_pi (x : ℝ) : tan (x + π) = tan x := tan_periodic x theorem tan_sub_pi (x : ℝ) : tan (x - π) = tan x := tan_periodic.sub_eq x theorem tan_pi_sub (x : ℝ) : tan (π - x) = -tan x := tan_neg x ▸ tan_periodic.sub_eq' theorem tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ := by rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub] theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.nat_mul_eq n theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 := tan_zero ▸ tan_periodic.int_mul_eq n theorem tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x := tan_periodic.nat_mul n x theorem tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x := tan_periodic.int_mul n x theorem tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x := tan_periodic.sub_nat_mul_eq n theorem tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x := tan_periodic.sub_int_mul_eq n theorem tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.nat_mul_sub_eq n theorem tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x := tan_neg x ▸ tan_periodic.int_mul_sub_eq n theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (π / 2)) (𝓝 1) := by convert continuous_sin.continuousWithinAt.tendsto simp theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (π / 2)) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsLT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (π / 2)) atTop := by convert tendsto_cos_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_pos zero_lt_one tendsto_sin_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(π / 2))) (𝓝 (-1)) := by convert continuous_sin.continuousWithinAt.tendsto using 2 simp theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(π / 2))) (𝓝[>] 0) := by apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within · convert continuous_cos.continuousWithinAt.tendsto simp · filter_upwards [Ioo_mem_nhdsGT (neg_lt_self pi_div_two_pos)] with x hx exact cos_pos_of_mem_Ioo hx theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(π / 2))) atBot := by convert tendsto_cos_neg_pi_div_two.inv_tendsto_nhdsGT_zero.atTop_mul_neg (by norm_num) tendsto_sin_neg_pi_div_two using 1 simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos] end Real namespace Complex open Real theorem sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self] exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩ @[simp] theorem cos_pi_div_two : cos (π / 2) = 0 := calc cos (π / 2) = Real.cos (π / 2) := by rw [ofReal_cos]; simp _ = 0 := by simp @[simp] theorem sin_pi_div_two : sin (π / 2) = 1 := calc sin (π / 2) = Real.sin (π / 2) := by rw [ofReal_sin]; simp _ = 1 := by simp @[simp] theorem sin_pi : sin π = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp @[simp] theorem cos_pi : cos π = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp @[simp] theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add] @[simp] theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add] theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add] theorem sin_periodic : Function.Periodic sin (2 * π) := sin_antiperiodic.periodic_two_mul theorem sin_add_pi (x : ℂ) : sin (x + π) = -sin x := sin_antiperiodic x theorem sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x := sin_periodic x theorem sin_sub_pi (x : ℂ) : sin (x - π) = -sin x := sin_antiperiodic.sub_eq x theorem sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x := sin_periodic.sub_eq x theorem sin_pi_sub (x : ℂ) : sin (π - x) = sin x := neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq' theorem sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x := sin_neg x ▸ sin_periodic.sub_eq' theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 := sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 := sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n theorem sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x := sin_periodic.nat_mul n x theorem sin_add_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x + n * (2 * π)) = sin x := sin_periodic.int_mul n x theorem sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_nat_mul_eq n theorem sin_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x - n * (2 * π)) = sin x := sin_periodic.sub_int_mul_eq n theorem sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.nat_mul_sub_eq n theorem sin_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x := sin_neg x ▸ sin_periodic.int_mul_sub_eq n theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add] theorem cos_periodic : Function.Periodic cos (2 * π) := cos_antiperiodic.periodic_two_mul theorem cos_add_pi (x : ℂ) : cos (x + π) = -cos x := cos_antiperiodic x theorem cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x := cos_periodic x theorem cos_sub_pi (x : ℂ) : cos (x - π) = -cos x := cos_antiperiodic.sub_eq x theorem cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x := cos_periodic.sub_eq x theorem cos_pi_sub (x : ℂ) : cos (π - x) = -cos x := cos_neg x ▸ cos_antiperiodic.sub_eq' theorem cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x := cos_neg x ▸ cos_periodic.sub_eq' theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 := (cos_periodic.nat_mul_eq n).trans cos_zero theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 := (cos_periodic.int_mul_eq n).trans cos_zero theorem cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x := cos_periodic.nat_mul n x theorem cos_add_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x + n * (2 * π)) = cos x := cos_periodic.int_mul n x theorem cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n theorem cos_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x - n * (2 * π)) = cos x := cos_periodic.sub_int_mul_eq n theorem cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
Mathlib/Analysis/SpecialFunctions/Trigonometric/Basic.lean
1,098
1,103
/- Copyright (c) 2022 Joël Riou. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joël Riou -/ import Mathlib.AlgebraicTopology.DoldKan.Projections import Mathlib.CategoryTheory.Idempotents.FunctorCategories import Mathlib.CategoryTheory.Idempotents.FunctorExtension /-! # Construction of the projection `PInfty` for the Dold-Kan correspondence In this file, we construct the projection `PInfty : K[X] ⟶ K[X]` by passing to the limit the projections `P q` defined in `Projections.lean`. This projection is a critical tool in this formalisation of the Dold-Kan correspondence, because in the case of abelian categories, `PInfty` corresponds to the projection on the normalized Moore subcomplex, with kernel the degenerate subcomplex. (See `Equivalence.lean` for the general strategy of proof of the Dold-Kan equivalence.) -/ open CategoryTheory CategoryTheory.Category CategoryTheory.Preadditive CategoryTheory.SimplicialObject CategoryTheory.Idempotents Opposite Simplicial DoldKan namespace AlgebraicTopology namespace DoldKan variable {C : Type*} [Category C] [Preadditive C] {X : SimplicialObject C} theorem P_is_eventually_constant {q n : ℕ} (hqn : n ≤ q) : ((P (q + 1)).f n : X _⦋n⦌ ⟶ _) = (P q).f n := by cases n with | zero => simp only [P_f_0_eq] | succ n => simp only [P_succ, comp_add, comp_id, HomologicalComplex.add_f_apply, HomologicalComplex.comp_f, add_eq_left] exact (HigherFacesVanish.of_P q n).comp_Hσ_eq_zero (Nat.succ_le_iff.mp hqn) theorem Q_is_eventually_constant {q n : ℕ} (hqn : n ≤ q) : ((Q (q + 1)).f n : X _⦋n⦌ ⟶ _) = (Q q).f n := by simp only [Q, HomologicalComplex.sub_f_apply, P_is_eventually_constant hqn] /-- The endomorphism `PInfty : K[X] ⟶ K[X]` obtained from the `P q` by passing to the limit. -/ noncomputable def PInfty : K[X] ⟶ K[X] := ChainComplex.ofHom _ _ _ _ _ _ (fun n => ((P n).f n : X _⦋n⦌ ⟶ _)) fun n => by simpa only [← P_is_eventually_constant (show n ≤ n by rfl), AlternatingFaceMapComplex.obj_d_eq] using (P (n + 1) : K[X] ⟶ _).comm (n + 1) n /-- The endomorphism `QInfty : K[X] ⟶ K[X]` obtained from the `Q q` by passing to the limit. -/ noncomputable def QInfty : K[X] ⟶ K[X] := 𝟙 _ - PInfty @[simp] theorem PInfty_f_0 : (PInfty.f 0 : X _⦋0⦌ ⟶ X _⦋0⦌) = 𝟙 _ := rfl theorem PInfty_f (n : ℕ) : (PInfty.f n : X _⦋n⦌ ⟶ X _⦋n⦌) = (P n).f n := rfl @[simp] theorem QInfty_f_0 : (QInfty.f 0 : X _⦋0⦌ ⟶ X _⦋0⦌) = 0 := by dsimp [QInfty] simp only [sub_self] theorem QInfty_f (n : ℕ) : (QInfty.f n : X _⦋n⦌ ⟶ X _⦋n⦌) = (Q n).f n := rfl @[reassoc (attr := simp)] theorem PInfty_f_naturality (n : ℕ) {X Y : SimplicialObject C} (f : X ⟶ Y) : f.app (op ⦋n⦌) ≫ PInfty.f n = PInfty.f n ≫ f.app (op ⦋n⦌) := P_f_naturality n n f @[reassoc (attr := simp)] theorem QInfty_f_naturality (n : ℕ) {X Y : SimplicialObject C} (f : X ⟶ Y) : f.app (op ⦋n⦌) ≫ QInfty.f n = QInfty.f n ≫ f.app (op ⦋n⦌) := Q_f_naturality n n f @[reassoc (attr := simp)] theorem PInfty_f_idem (n : ℕ) : (PInfty.f n : X _⦋n⦌ ⟶ _) ≫ PInfty.f n = PInfty.f n := by simp only [PInfty_f, P_f_idem] @[reassoc (attr := simp)] theorem PInfty_idem : (PInfty : K[X] ⟶ _) ≫ PInfty = PInfty := by ext n exact PInfty_f_idem n @[reassoc (attr := simp)] theorem QInfty_f_idem (n : ℕ) : (QInfty.f n : X _⦋n⦌ ⟶ _) ≫ QInfty.f n = QInfty.f n := Q_f_idem _ _ @[reassoc (attr := simp)] theorem QInfty_idem : (QInfty : K[X] ⟶ _) ≫ QInfty = QInfty := by ext n exact QInfty_f_idem n @[reassoc (attr := simp)] theorem PInfty_f_comp_QInfty_f (n : ℕ) : (PInfty.f n : X _⦋n⦌ ⟶ _) ≫ QInfty.f n = 0 := by dsimp only [QInfty] simp only [HomologicalComplex.sub_f_apply, HomologicalComplex.id_f, comp_sub, comp_id, PInfty_f_idem, sub_self] @[reassoc (attr := simp)] theorem PInfty_comp_QInfty : (PInfty : K[X] ⟶ _) ≫ QInfty = 0 := by ext n apply PInfty_f_comp_QInfty_f
@[reassoc (attr := simp)] theorem QInfty_f_comp_PInfty_f (n : ℕ) : (QInfty.f n : X _⦋n⦌ ⟶ _) ≫ PInfty.f n = 0 := by
Mathlib/AlgebraicTopology/DoldKan/PInfty.lean
110
112
/- Copyright (c) 2020 Kexing Ying. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Kexing Ying -/ import Mathlib.Algebra.Group.Conj import Mathlib.Algebra.Group.Pi.Lemmas import Mathlib.Algebra.Group.Subgroup.Ker /-! # Basic results on subgroups We prove basic results on the definitions of subgroups. The bundled subgroups use bundled monoid homomorphisms. Special thanks goes to Amelia Livingston and Yury Kudryashov for their help and inspiration. ## Main definitions Notation used here: - `G N` are `Group`s - `A` is an `AddGroup` - `H K` are `Subgroup`s of `G` or `AddSubgroup`s of `A` - `x` is an element of type `G` or type `A` - `f g : N →* G` are group homomorphisms - `s k` are sets of elements of type `G` Definitions in the file: * `Subgroup.prod H K` : the product of subgroups `H`, `K` of groups `G`, `N` respectively, `H × K` is a subgroup of `G × N` ## Implementation notes Subgroup inclusion is denoted `≤` rather than `⊆`, although `∈` is defined as membership of a subgroup's underlying set. ## Tags subgroup, subgroups -/ assert_not_exists OrderedAddCommMonoid Multiset Ring open Function open scoped Int variable {G G' G'' : Type*} [Group G] [Group G'] [Group G''] variable {A : Type*} [AddGroup A] section SubgroupClass variable {M S : Type*} [DivInvMonoid M] [SetLike S M] [hSM : SubgroupClass S M] {H K : S} variable [SetLike S G] [SubgroupClass S G] @[to_additive] theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := inv_div b a ▸ inv_mem_iff end SubgroupClass namespace Subgroup variable (H K : Subgroup G) @[to_additive] protected theorem div_mem_comm_iff {a b : G} : a / b ∈ H ↔ b / a ∈ H := div_mem_comm_iff variable {k : Set G} open Set variable {N : Type*} [Group N] {P : Type*} [Group P] /-- Given `Subgroup`s `H`, `K` of groups `G`, `N` respectively, `H × K` as a subgroup of `G × N`. -/ @[to_additive prod "Given `AddSubgroup`s `H`, `K` of `AddGroup`s `A`, `B` respectively, `H × K` as an `AddSubgroup` of `A × B`."] def prod (H : Subgroup G) (K : Subgroup N) : Subgroup (G × N) := { Submonoid.prod H.toSubmonoid K.toSubmonoid with inv_mem' := fun hx => ⟨H.inv_mem' hx.1, K.inv_mem' hx.2⟩ } @[to_additive coe_prod] theorem coe_prod (H : Subgroup G) (K : Subgroup N) : (H.prod K : Set (G × N)) = (H : Set G) ×ˢ (K : Set N) := rfl @[to_additive mem_prod] theorem mem_prod {H : Subgroup G} {K : Subgroup N} {p : G × N} : p ∈ H.prod K ↔ p.1 ∈ H ∧ p.2 ∈ K := Iff.rfl open scoped Relator in @[to_additive prod_mono] theorem prod_mono : ((· ≤ ·) ⇒ (· ≤ ·) ⇒ (· ≤ ·)) (@prod G _ N _) (@prod G _ N _) := fun _s _s' hs _t _t' ht => Set.prod_mono hs ht @[to_additive prod_mono_right] theorem prod_mono_right (K : Subgroup G) : Monotone fun t : Subgroup N => K.prod t := prod_mono (le_refl K) @[to_additive prod_mono_left] theorem prod_mono_left (H : Subgroup N) : Monotone fun K : Subgroup G => K.prod H := fun _ _ hs => prod_mono hs (le_refl H) @[to_additive prod_top] theorem prod_top (K : Subgroup G) : K.prod (⊤ : Subgroup N) = K.comap (MonoidHom.fst G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_fst] @[to_additive top_prod] theorem top_prod (H : Subgroup N) : (⊤ : Subgroup G).prod H = H.comap (MonoidHom.snd G N) := ext fun x => by simp [mem_prod, MonoidHom.coe_snd] @[to_additive (attr := simp) top_prod_top] theorem top_prod_top : (⊤ : Subgroup G).prod (⊤ : Subgroup N) = ⊤ := (top_prod _).trans <| comap_top _ @[to_additive (attr := simp) bot_prod_bot] theorem bot_prod_bot : (⊥ : Subgroup G).prod (⊥ : Subgroup N) = ⊥ := SetLike.coe_injective <| by simp [coe_prod] @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.bot_sum_bot := AddSubgroup.bot_prod_bot @[to_additive le_prod_iff] theorem le_prod_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : J ≤ H.prod K ↔ map (MonoidHom.fst G N) J ≤ H ∧ map (MonoidHom.snd G N) J ≤ K := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.le_prod_iff @[to_additive prod_le_iff] theorem prod_le_iff {H : Subgroup G} {K : Subgroup N} {J : Subgroup (G × N)} : H.prod K ≤ J ↔ map (MonoidHom.inl G N) H ≤ J ∧ map (MonoidHom.inr G N) K ≤ J := by simpa only [← Subgroup.toSubmonoid_le] using Submonoid.prod_le_iff @[to_additive (attr := simp) prod_eq_bot_iff] theorem prod_eq_bot_iff {H : Subgroup G} {K : Subgroup N} : H.prod K = ⊥ ↔ H = ⊥ ∧ K = ⊥ := by simpa only [← Subgroup.toSubmonoid_inj] using Submonoid.prod_eq_bot_iff @[to_additive closure_prod] theorem closure_prod {s : Set G} {t : Set N} (hs : 1 ∈ s) (ht : 1 ∈ t) : closure (s ×ˢ t) = (closure s).prod (closure t) := le_antisymm (closure_le _ |>.2 <| Set.prod_subset_prod_iff.2 <| .inl ⟨subset_closure, subset_closure⟩) (prod_le_iff.2 ⟨ map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _x hx => subset_closure ⟨hx, ht⟩, map_le_iff_le_comap.2 <| closure_le _ |>.2 fun _y hy => subset_closure ⟨hs, hy⟩⟩) /-- Product of subgroups is isomorphic to their product as groups. -/ @[to_additive prodEquiv "Product of additive subgroups is isomorphic to their product as additive groups"] def prodEquiv (H : Subgroup G) (K : Subgroup N) : H.prod K ≃* H × K := { Equiv.Set.prod (H : Set G) (K : Set N) with map_mul' := fun _ _ => rfl } section Pi variable {η : Type*} {f : η → Type*} -- defined here and not in Algebra.Group.Submonoid.Operations to have access to Algebra.Group.Pi /-- A version of `Set.pi` for submonoids. Given an index set `I` and a family of submodules `s : Π i, Submonoid f i`, `pi I s` is the submonoid of dependent functions `f : Π i, f i` such that `f i` belongs to `Pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubmonoid`s. Given an index set `I` and a family of submodules `s : Π i, AddSubmonoid f i`, `pi I s` is the `AddSubmonoid` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def _root_.Submonoid.pi [∀ i, MulOneClass (f i)] (I : Set η) (s : ∀ i, Submonoid (f i)) : Submonoid (∀ i, f i) where carrier := I.pi fun i => (s i).carrier one_mem' i _ := (s i).one_mem mul_mem' hp hq i hI := (s i).mul_mem (hp i hI) (hq i hI) variable [∀ i, Group (f i)] /-- A version of `Set.pi` for subgroups. Given an index set `I` and a family of submodules `s : Π i, Subgroup f i`, `pi I s` is the subgroup of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`. -/ @[to_additive "A version of `Set.pi` for `AddSubgroup`s. Given an index set `I` and a family of submodules `s : Π i, AddSubgroup f i`, `pi I s` is the `AddSubgroup` of dependent functions `f : Π i, f i` such that `f i` belongs to `pi I s` whenever `i ∈ I`."] def pi (I : Set η) (H : ∀ i, Subgroup (f i)) : Subgroup (∀ i, f i) := { Submonoid.pi I fun i => (H i).toSubmonoid with inv_mem' := fun hp i hI => (H i).inv_mem (hp i hI) } @[to_additive] theorem coe_pi (I : Set η) (H : ∀ i, Subgroup (f i)) : (pi I H : Set (∀ i, f i)) = Set.pi I fun i => (H i : Set (f i)) := rfl @[to_additive] theorem mem_pi (I : Set η) {H : ∀ i, Subgroup (f i)} {p : ∀ i, f i} : p ∈ pi I H ↔ ∀ i : η, i ∈ I → p i ∈ H i := Iff.rfl @[to_additive] theorem pi_top (I : Set η) : (pi I fun i => (⊤ : Subgroup (f i))) = ⊤ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_empty (H : ∀ i, Subgroup (f i)) : pi ∅ H = ⊤ := ext fun x => by simp [mem_pi] @[to_additive] theorem pi_bot : (pi Set.univ fun i => (⊥ : Subgroup (f i))) = ⊥ := (eq_bot_iff_forall _).mpr fun p hp => by simp only [mem_pi, mem_bot] at * ext j exact hp j trivial @[to_additive] theorem le_pi_iff {I : Set η} {H : ∀ i, Subgroup (f i)} {J : Subgroup (∀ i, f i)} : J ≤ pi I H ↔ ∀ i : η, i ∈ I → map (Pi.evalMonoidHom f i) J ≤ H i := by constructor · intro h i hi rintro _ ⟨x, hx, rfl⟩ exact (h hx) _ hi · intro h x hx i hi exact h i hi ⟨_, hx, rfl⟩ @[to_additive (attr := simp)] theorem mulSingle_mem_pi [DecidableEq η] {I : Set η} {H : ∀ i, Subgroup (f i)} (i : η) (x : f i) : Pi.mulSingle i x ∈ pi I H ↔ i ∈ I → x ∈ H i := by constructor · intro h hi simpa using h i hi · intro h j hj by_cases heq : j = i · subst heq simpa using h hj · simp [heq, one_mem] @[to_additive] theorem pi_eq_bot_iff (H : ∀ i, Subgroup (f i)) : pi Set.univ H = ⊥ ↔ ∀ i, H i = ⊥ := by classical simp only [eq_bot_iff_forall] constructor · intro h i x hx have : MonoidHom.mulSingle f i x = 1 := h (MonoidHom.mulSingle f i x) ((mulSingle_mem_pi i x).mpr fun _ => hx) simpa using congr_fun this i · exact fun h x hx => funext fun i => h _ _ (hx i trivial) end Pi end Subgroup namespace Subgroup variable {H K : Subgroup G} variable (H) /-- A subgroup is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (MulAut.conj b)) a).mpr ha⟩ end Subgroup namespace AddSubgroup variable (H : AddSubgroup A) /-- An `AddSubgroup` is characteristic if it is fixed by all automorphisms. Several equivalent conditions are provided by lemmas of the form `Characteristic.iff...` -/ structure Characteristic : Prop where /-- `H` is fixed by all automorphisms -/ fixed : ∀ ϕ : A ≃+ A, H.comap ϕ.toAddMonoidHom = H attribute [to_additive] Subgroup.Characteristic attribute [class] Characteristic instance (priority := 100) normal_of_characteristic [h : H.Characteristic] : H.Normal := ⟨fun a ha b => (SetLike.ext_iff.mp (h.fixed (AddAut.conj b)) a).mpr ha⟩ end AddSubgroup namespace Subgroup variable {H K : Subgroup G} @[to_additive] theorem characteristic_iff_comap_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom = H := ⟨Characteristic.fixed, Characteristic.mk⟩ @[to_additive] theorem characteristic_iff_comap_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.comap ϕ.toMonoidHom ≤ H := characteristic_iff_comap_eq.trans ⟨fun h ϕ => le_of_eq (h ϕ), fun h ϕ => le_antisymm (h ϕ) fun g hg => h ϕ.symm ((congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mpr hg)⟩ @[to_additive] theorem characteristic_iff_le_comap : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.comap ϕ.toMonoidHom := characteristic_iff_comap_eq.trans ⟨fun h ϕ => ge_of_eq (h ϕ), fun h ϕ => le_antisymm (fun g hg => (congr_arg (· ∈ H) (ϕ.symm_apply_apply g)).mp (h ϕ.symm hg)) (h ϕ)⟩ @[to_additive] theorem characteristic_iff_map_eq : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom = H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_eq.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] theorem characteristic_iff_map_le : H.Characteristic ↔ ∀ ϕ : G ≃* G, H.map ϕ.toMonoidHom ≤ H := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_comap_le.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] theorem characteristic_iff_le_map : H.Characteristic ↔ ∀ ϕ : G ≃* G, H ≤ H.map ϕ.toMonoidHom := by simp_rw [map_equiv_eq_comap_symm'] exact characteristic_iff_le_comap.trans ⟨fun h ϕ => h ϕ.symm, fun h ϕ => h ϕ.symm⟩ @[to_additive] instance botCharacteristic : Characteristic (⊥ : Subgroup G) := characteristic_iff_le_map.mpr fun _ϕ => bot_le @[to_additive] instance topCharacteristic : Characteristic (⊤ : Subgroup G) := characteristic_iff_map_le.mpr fun _ϕ => le_top variable (H) section Normalizer variable {H} @[to_additive] theorem normalizer_eq_top_iff : H.normalizer = ⊤ ↔ H.Normal := eq_top_iff.trans ⟨fun h => ⟨fun a ha b => (h (mem_top b) a).mp ha⟩, fun h a _ha b => ⟨fun hb => h.conj_mem b hb a, fun hb => by rwa [h.mem_comm_iff, inv_mul_cancel_left] at hb⟩⟩ variable (H) in @[to_additive] theorem normalizer_eq_top [h : H.Normal] : H.normalizer = ⊤ := normalizer_eq_top_iff.mpr h variable {N : Type*} [Group N] /-- The preimage of the normalizer is contained in the normalizer of the preimage. -/ @[to_additive "The preimage of the normalizer is contained in the normalizer of the preimage."] theorem le_normalizer_comap (f : N →* G) : H.normalizer.comap f ≤ (H.comap f).normalizer := fun x => by simp only [mem_normalizer_iff, mem_comap] intro h n simp [h (f n)] /-- The image of the normalizer is contained in the normalizer of the image. -/ @[to_additive "The image of the normalizer is contained in the normalizer of the image."] theorem le_normalizer_map (f : G →* N) : H.normalizer.map f ≤ (H.map f).normalizer := fun _ => by simp only [and_imp, exists_prop, mem_map, exists_imp, mem_normalizer_iff] rintro x hx rfl n constructor · rintro ⟨y, hy, rfl⟩ use x * y * x⁻¹, (hx y).1 hy simp · rintro ⟨y, hyH, hy⟩ use x⁻¹ * y * x rw [hx] simp [hy, hyH, mul_assoc] @[to_additive] theorem comap_normalizer_eq_of_le_range {f : N →* G} (h : H ≤ f.range) : comap f H.normalizer = (comap f H).normalizer := by apply le_antisymm (le_normalizer_comap f) rw [← map_le_iff_le_comap] apply (le_normalizer_map f).trans rw [map_comap_eq_self h] @[to_additive] theorem subgroupOf_normalizer_eq {H N : Subgroup G} (h : H ≤ N) : H.normalizer.subgroupOf N = (H.subgroupOf N).normalizer := comap_normalizer_eq_of_le_range (h.trans_eq N.range_subtype.symm) @[to_additive] theorem normal_subgroupOf_iff_le_normalizer (h : H ≤ K) : (H.subgroupOf K).Normal ↔ K ≤ H.normalizer := by rw [← subgroupOf_eq_top, subgroupOf_normalizer_eq h, normalizer_eq_top_iff] @[to_additive] theorem normal_subgroupOf_iff_le_normalizer_inf : (H.subgroupOf K).Normal ↔ K ≤ (H ⊓ K).normalizer := inf_subgroupOf_right H K ▸ normal_subgroupOf_iff_le_normalizer inf_le_right @[to_additive] instance (priority := 100) normal_in_normalizer : (H.subgroupOf H.normalizer).Normal := (normal_subgroupOf_iff_le_normalizer H.le_normalizer).mpr le_rfl @[to_additive] theorem le_normalizer_of_normal_subgroupOf [hK : (H.subgroupOf K).Normal] (HK : H ≤ K) : K ≤ H.normalizer := (normal_subgroupOf_iff_le_normalizer HK).mp hK @[to_additive] theorem subset_normalizer_of_normal {S : Set G} [hH : H.Normal] : S ⊆ H.normalizer := (@normalizer_eq_top _ _ H hH) ▸ le_top @[to_additive] theorem le_normalizer_of_normal [H.Normal] : K ≤ H.normalizer := subset_normalizer_of_normal @[to_additive] theorem inf_normalizer_le_normalizer_inf : H.normalizer ⊓ K.normalizer ≤ (H ⊓ K).normalizer := fun _ h g ↦ and_congr (h.1 g) (h.2 g) variable (G) in /-- Every proper subgroup `H` of `G` is a proper normal subgroup of the normalizer of `H` in `G`. -/ def _root_.NormalizerCondition := ∀ H : Subgroup G, H < ⊤ → H < normalizer H /-- Alternative phrasing of the normalizer condition: Only the full group is self-normalizing. This may be easier to work with, as it avoids inequalities and negations. -/ theorem _root_.normalizerCondition_iff_only_full_group_self_normalizing : NormalizerCondition G ↔ ∀ H : Subgroup G, H.normalizer = H → H = ⊤ := by apply forall_congr'; intro H simp only [lt_iff_le_and_ne, le_normalizer, le_top, Ne] tauto variable (H) end Normalizer end Subgroup namespace Group variable {s : Set G} /-- Given a set `s`, `conjugatesOfSet s` is the set of all conjugates of the elements of `s`. -/ def conjugatesOfSet (s : Set G) : Set G := ⋃ a ∈ s, conjugatesOf a theorem mem_conjugatesOfSet_iff {x : G} : x ∈ conjugatesOfSet s ↔ ∃ a ∈ s, IsConj a x := by rw [conjugatesOfSet, Set.mem_iUnion₂] simp only [conjugatesOf, isConj_iff, Set.mem_setOf_eq, exists_prop] theorem subset_conjugatesOfSet : s ⊆ conjugatesOfSet s := fun (x : G) (h : x ∈ s) => mem_conjugatesOfSet_iff.2 ⟨x, h, IsConj.refl _⟩ theorem conjugatesOfSet_mono {s t : Set G} (h : s ⊆ t) : conjugatesOfSet s ⊆ conjugatesOfSet t := Set.biUnion_subset_biUnion_left h theorem conjugates_subset_normal {N : Subgroup G} [tn : N.Normal] {a : G} (h : a ∈ N) : conjugatesOf a ⊆ N := by rintro a hc obtain ⟨c, rfl⟩ := isConj_iff.1 hc exact tn.conj_mem a h c theorem conjugatesOfSet_subset {s : Set G} {N : Subgroup G} [N.Normal] (h : s ⊆ N) : conjugatesOfSet s ⊆ N := Set.iUnion₂_subset fun _x H => conjugates_subset_normal (h H) /-- The set of conjugates of `s` is closed under conjugation. -/ theorem conj_mem_conjugatesOfSet {x c : G} : x ∈ conjugatesOfSet s → c * x * c⁻¹ ∈ conjugatesOfSet s := fun H => by rcases mem_conjugatesOfSet_iff.1 H with ⟨a, h₁, h₂⟩ exact mem_conjugatesOfSet_iff.2 ⟨a, h₁, h₂.trans (isConj_iff.2 ⟨c, rfl⟩)⟩ end Group namespace Subgroup open Group variable {s : Set G} /-- The normal closure of a set `s` is the subgroup closure of all the conjugates of elements of `s`. It is the smallest normal subgroup containing `s`. -/ def normalClosure (s : Set G) : Subgroup G := closure (conjugatesOfSet s) theorem conjugatesOfSet_subset_normalClosure : conjugatesOfSet s ⊆ normalClosure s := subset_closure theorem subset_normalClosure : s ⊆ normalClosure s := Set.Subset.trans subset_conjugatesOfSet conjugatesOfSet_subset_normalClosure theorem le_normalClosure {H : Subgroup G} : H ≤ normalClosure ↑H := fun _ h => subset_normalClosure h /-- The normal closure of `s` is a normal subgroup. -/ instance normalClosure_normal : (normalClosure s).Normal := ⟨fun n h g => by refine Subgroup.closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) h · exact conjugatesOfSet_subset_normalClosure (conj_mem_conjugatesOfSet hx) · simpa using (normalClosure s).one_mem · rw [← conj_mul] exact mul_mem ihx ihy · rw [← conj_inv] exact inv_mem ihx⟩ /-- The normal closure of `s` is the smallest normal subgroup containing `s`. -/ theorem normalClosure_le_normal {N : Subgroup G} [N.Normal] (h : s ⊆ N) : normalClosure s ≤ N := by intro a w refine closure_induction (fun x hx => ?_) ?_ (fun x y _ _ ihx ihy => ?_) (fun x _ ihx => ?_) w · exact conjugatesOfSet_subset h hx · exact one_mem _ · exact mul_mem ihx ihy · exact inv_mem ihx theorem normalClosure_subset_iff {N : Subgroup G} [N.Normal] : s ⊆ N ↔ normalClosure s ≤ N := ⟨normalClosure_le_normal, Set.Subset.trans subset_normalClosure⟩ @[gcongr] theorem normalClosure_mono {s t : Set G} (h : s ⊆ t) : normalClosure s ≤ normalClosure t := normalClosure_le_normal (Set.Subset.trans h subset_normalClosure) theorem normalClosure_eq_iInf : normalClosure s = ⨅ (N : Subgroup G) (_ : Normal N) (_ : s ⊆ N), N := le_antisymm (le_iInf fun _ => le_iInf fun _ => le_iInf normalClosure_le_normal) (iInf_le_of_le (normalClosure s) (iInf_le_of_le (by infer_instance) (iInf_le_of_le subset_normalClosure le_rfl))) @[simp] theorem normalClosure_eq_self (H : Subgroup G) [H.Normal] : normalClosure ↑H = H := le_antisymm (normalClosure_le_normal rfl.subset) le_normalClosure theorem normalClosure_idempotent : normalClosure ↑(normalClosure s) = normalClosure s := normalClosure_eq_self _ theorem closure_le_normalClosure {s : Set G} : closure s ≤ normalClosure s := by simp only [subset_normalClosure, closure_le] @[simp] theorem normalClosure_closure_eq_normalClosure {s : Set G} : normalClosure ↑(closure s) = normalClosure s := le_antisymm (normalClosure_le_normal closure_le_normalClosure) (normalClosure_mono subset_closure) /-- The normal core of a subgroup `H` is the largest normal subgroup of `G` contained in `H`, as shown by `Subgroup.normalCore_eq_iSup`. -/ def normalCore (H : Subgroup G) : Subgroup G where carrier := { a : G | ∀ b : G, b * a * b⁻¹ ∈ H } one_mem' a := by rw [mul_one, mul_inv_cancel]; exact H.one_mem inv_mem' {_} h b := (congr_arg (· ∈ H) conj_inv).mp (H.inv_mem (h b)) mul_mem' {_ _} ha hb c := (congr_arg (· ∈ H) conj_mul).mp (H.mul_mem (ha c) (hb c)) theorem normalCore_le (H : Subgroup G) : H.normalCore ≤ H := fun a h => by rw [← mul_one a, ← inv_one, ← one_mul a] exact h 1 instance normalCore_normal (H : Subgroup G) : H.normalCore.Normal := ⟨fun a h b c => by rw [mul_assoc, mul_assoc, ← mul_inv_rev, ← mul_assoc, ← mul_assoc]; exact h (c * b)⟩ theorem normal_le_normalCore {H : Subgroup G} {N : Subgroup G} [hN : N.Normal] : N ≤ H.normalCore ↔ N ≤ H := ⟨ge_trans H.normalCore_le, fun h_le n hn g => h_le (hN.conj_mem n hn g)⟩ theorem normalCore_mono {H K : Subgroup G} (h : H ≤ K) : H.normalCore ≤ K.normalCore := normal_le_normalCore.mpr (H.normalCore_le.trans h) theorem normalCore_eq_iSup (H : Subgroup G) : H.normalCore = ⨆ (N : Subgroup G) (_ : Normal N) (_ : N ≤ H), N := le_antisymm (le_iSup_of_le H.normalCore (le_iSup_of_le H.normalCore_normal (le_iSup_of_le H.normalCore_le le_rfl))) (iSup_le fun _ => iSup_le fun _ => iSup_le normal_le_normalCore.mpr) @[simp] theorem normalCore_eq_self (H : Subgroup G) [H.Normal] : H.normalCore = H := le_antisymm H.normalCore_le (normal_le_normalCore.mpr le_rfl) theorem normalCore_idempotent (H : Subgroup G) : H.normalCore.normalCore = H.normalCore := H.normalCore.normalCore_eq_self end Subgroup namespace MonoidHom variable {N : Type*} {P : Type*} [Group N] [Group P] (K : Subgroup G) open Subgroup section Ker variable {M : Type*} [MulOneClass M] @[to_additive prodMap_comap_prod] theorem prodMap_comap_prod {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') (S : Subgroup N) (S' : Subgroup N') : (S.prod S').comap (prodMap f g) = (S.comap f).prod (S'.comap g) := SetLike.coe_injective <| Set.preimage_prod_map_prod f g _ _ @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.sumMap_comap_sum := AddMonoidHom.prodMap_comap_prod @[to_additive ker_prodMap] theorem ker_prodMap {G' : Type*} {N' : Type*} [Group G'] [Group N'] (f : G →* N) (g : G' →* N') : (prodMap f g).ker = f.ker.prod g.ker := by rw [← comap_bot, ← comap_bot, ← comap_bot, ← prodMap_comap_prod, bot_prod_bot] @[deprecated (since := "2025-03-11")] alias _root_.AddMonoidHom.ker_sumMap := AddMonoidHom.ker_prodMap @[to_additive (attr := simp)] lemma ker_fst : ker (fst G G') = .prod ⊥ ⊤ := SetLike.ext fun _ => (iff_of_eq (and_true _)).symm @[to_additive (attr := simp)] lemma ker_snd : ker (snd G G') = .prod ⊤ ⊥ := SetLike.ext fun _ => (iff_of_eq (true_and _)).symm end Ker end MonoidHom namespace Subgroup variable {N : Type*} [Group N] (H : Subgroup G) @[to_additive] theorem Normal.map {H : Subgroup G} (h : H.Normal) (f : G →* N) (hf : Function.Surjective f) : (H.map f).Normal := by rw [← normalizer_eq_top_iff, ← top_le_iff, ← f.range_eq_top_of_surjective hf, f.range_eq_map, ← H.normalizer_eq_top] exact le_normalizer_map _ end Subgroup namespace Subgroup open MonoidHom variable {N : Type*} [Group N] (f : G →* N) /-- The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function. -/ @[to_additive "The preimage of the normalizer is equal to the normalizer of the preimage of a surjective function."] theorem comap_normalizer_eq_of_surjective (H : Subgroup G) {f : N →* G} (hf : Function.Surjective f) : H.normalizer.comap f = (H.comap f).normalizer := comap_normalizer_eq_of_le_range fun x _ ↦ hf x @[deprecated (since := "2025-03-13")] alias comap_normalizer_eq_of_injective_of_le_range := comap_normalizer_eq_of_le_range @[deprecated (since := "2025-03-13")] alias _root_.AddSubgroup.comap_normalizer_eq_of_injective_of_le_range := AddSubgroup.comap_normalizer_eq_of_le_range /-- The image of the normalizer is equal to the normalizer of the image of an isomorphism. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of an isomorphism."] theorem map_equiv_normalizer_eq (H : Subgroup G) (f : G ≃* N) : H.normalizer.map f.toMonoidHom = (H.map f.toMonoidHom).normalizer := by ext x simp only [mem_normalizer_iff, mem_map_equiv] rw [f.toEquiv.forall_congr] intro simp /-- The image of the normalizer is equal to the normalizer of the image of a bijective function. -/ @[to_additive "The image of the normalizer is equal to the normalizer of the image of a bijective function."] theorem map_normalizer_eq_of_bijective (H : Subgroup G) {f : G →* N} (hf : Function.Bijective f) : H.normalizer.map f = (H.map f).normalizer := map_equiv_normalizer_eq H (MulEquiv.ofBijective f hf) end Subgroup namespace MonoidHom variable {G₁ G₂ G₃ : Type*} [Group G₁] [Group G₂] [Group G₃] variable (f : G₁ →* G₂) (f_inv : G₂ → G₁) /-- Auxiliary definition used to define `liftOfRightInverse` -/ @[to_additive "Auxiliary definition used to define `liftOfRightInverse`"] def liftOfRightInverseAux (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) : G₂ →* G₃ where toFun b := g (f_inv b) map_one' := hg (hf 1) map_mul' := by intro x y rw [← g.map_mul, ← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one, f.map_mul] simp only [hf _] @[to_additive (attr := simp)] theorem liftOfRightInverseAux_comp_apply (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (x : G₁) : (f.liftOfRightInverseAux f_inv hf g hg) (f x) = g x := by dsimp [liftOfRightInverseAux] rw [← mul_inv_eq_one, ← g.map_inv, ← g.map_mul, ← g.mem_ker] apply hg rw [f.mem_ker, f.map_mul, f.map_inv, mul_inv_eq_one] simp only [hf _] /-- `liftOfRightInverse f hf g hg` is the unique group homomorphism `φ` * such that `φ.comp f = g` (`MonoidHom.liftOfRightInverse_comp`), * where `f : G₁ →+* G₂` has a RightInverse `f_inv` (`hf`), * and `g : G₂ →+* G₃` satisfies `hg : f.ker ≤ g.ker`. See `MonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \ f | \ g | \ v \⌟ G₂----> G₃ ∃!φ ``` -/ @[to_additive "`liftOfRightInverse f f_inv hf g hg` is the unique additive group homomorphism `φ` * such that `φ.comp f = g` (`AddMonoidHom.liftOfRightInverse_comp`), * where `f : G₁ →+ G₂` has a RightInverse `f_inv` (`hf`), * and `g : G₂ →+ G₃` satisfies `hg : f.ker ≤ g.ker`. See `AddMonoidHom.eq_liftOfRightInverse` for the uniqueness lemma. ``` G₁. | \\ f | \\ g | \\ v \\⌟ G₂----> G₃ ∃!φ ```"] def liftOfRightInverse (hf : Function.RightInverse f_inv f) : { g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) where toFun g := f.liftOfRightInverseAux f_inv hf g.1 g.2 invFun φ := ⟨φ.comp f, fun x hx ↦ mem_ker.mpr <| by simp [mem_ker.mp hx]⟩ left_inv g := by ext simp only [comp_apply, liftOfRightInverseAux_comp_apply, Subtype.coe_mk] right_inv φ := by ext b simp [liftOfRightInverseAux, hf b] /-- A non-computable version of `MonoidHom.liftOfRightInverse` for when no computable right inverse is available, that uses `Function.surjInv`. -/ @[to_additive (attr := simp) "A non-computable version of `AddMonoidHom.liftOfRightInverse` for when no computable right inverse is available."] noncomputable abbrev liftOfSurjective (hf : Function.Surjective f) : { g : G₁ →* G₃ // f.ker ≤ g.ker } ≃ (G₂ →* G₃) := f.liftOfRightInverse (Function.surjInv hf) (Function.rightInverse_surjInv hf) @[to_additive (attr := simp)] theorem liftOfRightInverse_comp_apply (hf : Function.RightInverse f_inv f) (g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) (x : G₁) : (f.liftOfRightInverse f_inv hf g) (f x) = g.1 x := f.liftOfRightInverseAux_comp_apply f_inv hf g.1 g.2 x @[to_additive (attr := simp)] theorem liftOfRightInverse_comp (hf : Function.RightInverse f_inv f) (g : { g : G₁ →* G₃ // f.ker ≤ g.ker }) : (f.liftOfRightInverse f_inv hf g).comp f = g := MonoidHom.ext <| f.liftOfRightInverse_comp_apply f_inv hf g @[to_additive] theorem eq_liftOfRightInverse (hf : Function.RightInverse f_inv f) (g : G₁ →* G₃) (hg : f.ker ≤ g.ker) (h : G₂ →* G₃) (hh : h.comp f = g) : h = f.liftOfRightInverse f_inv hf ⟨g, hg⟩ := by simp_rw [← hh] exact ((f.liftOfRightInverse f_inv hf).apply_symm_apply _).symm end MonoidHom variable {N : Type*} [Group N] namespace Subgroup -- Here `H.Normal` is an explicit argument so we can use dot notation with `comap`. @[to_additive] theorem Normal.comap {H : Subgroup N} (hH : H.Normal) (f : G →* N) : (H.comap f).Normal := ⟨fun _ => by simp +contextual [Subgroup.mem_comap, hH.conj_mem]⟩ @[to_additive] instance (priority := 100) normal_comap {H : Subgroup N} [nH : H.Normal] (f : G →* N) : (H.comap f).Normal := nH.comap _ -- Here `H.Normal` is an explicit argument so we can use dot notation with `subgroupOf`. @[to_additive] theorem Normal.subgroupOf {H : Subgroup G} (hH : H.Normal) (K : Subgroup G) : (H.subgroupOf K).Normal := hH.comap _ @[to_additive] instance (priority := 100) normal_subgroupOf {H N : Subgroup G} [N.Normal] : (N.subgroupOf H).Normal := Subgroup.normal_comap _ theorem map_normalClosure (s : Set G) (f : G →* N) (hf : Surjective f) : (normalClosure s).map f = normalClosure (f '' s) := by have : Normal (map f (normalClosure s)) := Normal.map inferInstance f hf apply le_antisymm · simp [map_le_iff_le_comap, normalClosure_le_normal, coe_comap, ← Set.image_subset_iff, subset_normalClosure] · exact normalClosure_le_normal (Set.image_subset f subset_normalClosure) theorem comap_normalClosure (s : Set N) (f : G ≃* N) : normalClosure (f ⁻¹' s) = (normalClosure s).comap f := by have := Set.preimage_equiv_eq_image_symm s f.toEquiv simp_all [comap_equiv_eq_map_symm, map_normalClosure s (f.symm : N →* G) f.symm.surjective] lemma Normal.of_map_injective {G H : Type*} [Group G] [Group H] {φ : G →* H} (hφ : Function.Injective φ) {L : Subgroup G} (n : (L.map φ).Normal) : L.Normal := L.comap_map_eq_self_of_injective hφ ▸ n.comap φ theorem Normal.of_map_subtype {K : Subgroup G} {L : Subgroup K} (n : (Subgroup.map K.subtype L).Normal) : L.Normal := n.of_map_injective K.subtype_injective end Subgroup namespace Subgroup section SubgroupNormal @[to_additive] theorem normal_subgroupOf_iff {H K : Subgroup G} (hHK : H ≤ K) : (H.subgroupOf K).Normal ↔ ∀ h k, h ∈ H → k ∈ K → k * h * k⁻¹ ∈ H := ⟨fun hN h k hH hK => hN.conj_mem ⟨h, hHK hH⟩ hH ⟨k, hK⟩, fun hN => { conj_mem := fun h hm k => hN h.1 k.1 hm k.2 }⟩ @[to_additive prod_addSubgroupOf_prod_normal] instance prod_subgroupOf_prod_normal {H₁ K₁ : Subgroup G} {H₂ K₂ : Subgroup N} [h₁ : (H₁.subgroupOf K₁).Normal] [h₂ : (H₂.subgroupOf K₂).Normal] : ((H₁.prod H₂).subgroupOf (K₁.prod K₂)).Normal where conj_mem n hgHK g := ⟨h₁.conj_mem ⟨(n : G × N).fst, (mem_prod.mp n.2).1⟩ hgHK.1 ⟨(g : G × N).fst, (mem_prod.mp g.2).1⟩, h₂.conj_mem ⟨(n : G × N).snd, (mem_prod.mp n.2).2⟩ hgHK.2 ⟨(g : G × N).snd, (mem_prod.mp g.2).2⟩⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_addSubgroupOf_sum_normal := AddSubgroup.prod_addSubgroupOf_prod_normal @[to_additive prod_normal] instance prod_normal (H : Subgroup G) (K : Subgroup N) [hH : H.Normal] [hK : K.Normal] : (H.prod K).Normal where conj_mem n hg g := ⟨hH.conj_mem n.fst (Subgroup.mem_prod.mp hg).1 g.fst, hK.conj_mem n.snd (Subgroup.mem_prod.mp hg).2 g.snd⟩ @[deprecated (since := "2025-03-11")] alias _root_.AddSubgroup.sum_normal := AddSubgroup.prod_normal @[to_additive] theorem inf_subgroupOf_inf_normal_of_right (A B' B : Subgroup G) [hN : (B'.subgroupOf B).Normal] : ((A ⊓ B').subgroupOf (A ⊓ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf A.le_normalizer hN) (inf_normalizer_le_normalizer_inf) @[to_additive] theorem inf_subgroupOf_inf_normal_of_left {A' A : Subgroup G} (B : Subgroup G) [hN : (A'.subgroupOf A).Normal] : ((A' ⊓ B).subgroupOf (A ⊓ B)).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] at hN ⊢ rw [inf_inf_inf_comm, inf_idem] exact le_trans (inf_le_inf hN B.le_normalizer) (inf_normalizer_le_normalizer_inf) @[to_additive] instance normal_inf_normal (H K : Subgroup G) [hH : H.Normal] [hK : K.Normal] : (H ⊓ K).Normal := ⟨fun n hmem g => ⟨hH.conj_mem n hmem.1 g, hK.conj_mem n hmem.2 g⟩⟩ @[to_additive] theorem normal_iInf_normal {ι : Type*} {a : ι → Subgroup G} (norm : ∀ i : ι, (a i).Normal) : (iInf a).Normal := by constructor intro g g_in_iInf h rw [Subgroup.mem_iInf] at g_in_iInf ⊢ intro i exact (norm i).conj_mem g (g_in_iInf i) h @[to_additive] theorem SubgroupNormal.mem_comm {H K : Subgroup G} (hK : H ≤ K) [hN : (H.subgroupOf K).Normal] {a b : G} (hb : b ∈ K) (h : a * b ∈ H) : b * a ∈ H := by have := (normal_subgroupOf_iff hK).mp hN (a * b) b h hb rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one] at this /-- Elements of disjoint, normal subgroups commute. -/ @[to_additive "Elements of disjoint, normal subgroups commute."] theorem commute_of_normal_of_disjoint (H₁ H₂ : Subgroup G) (hH₁ : H₁.Normal) (hH₂ : H₂.Normal) (hdis : Disjoint H₁ H₂) (x y : G) (hx : x ∈ H₁) (hy : y ∈ H₂) : Commute x y := by suffices x * y * x⁻¹ * y⁻¹ = 1 by show x * y = y * x · rw [mul_assoc, mul_eq_one_iff_eq_inv] at this simpa apply hdis.le_bot constructor · suffices x * (y * x⁻¹ * y⁻¹) ∈ H₁ by simpa [mul_assoc] exact H₁.mul_mem hx (hH₁.conj_mem _ (H₁.inv_mem hx) _) · show x * y * x⁻¹ * y⁻¹ ∈ H₂ apply H₂.mul_mem _ (H₂.inv_mem hy) apply hH₂.conj_mem _ hy @[to_additive] theorem normal_subgroupOf_of_le_normalizer {H N : Subgroup G} (hLE : H ≤ N.normalizer) : (N.subgroupOf H).Normal := by rw [normal_subgroupOf_iff_le_normalizer_inf] exact (le_inf hLE H.le_normalizer).trans inf_normalizer_le_normalizer_inf @[to_additive] theorem normal_subgroupOf_sup_of_le_normalizer {H N : Subgroup G} (hLE : H ≤ N.normalizer) : (N.subgroupOf (H ⊔ N)).Normal := by rw [normal_subgroupOf_iff_le_normalizer le_sup_right] exact sup_le hLE le_normalizer end SubgroupNormal end Subgroup namespace IsConj open Subgroup theorem normalClosure_eq_top_of {N : Subgroup G} [hn : N.Normal] {g g' : G} {hg : g ∈ N} {hg' : g' ∈ N} (hc : IsConj g g') (ht : normalClosure ({⟨g, hg⟩} : Set N) = ⊤) : normalClosure ({⟨g', hg'⟩} : Set N) = ⊤ := by obtain ⟨c, rfl⟩ := isConj_iff.1 hc have h : ∀ x : N, (MulAut.conj c) x ∈ N := by rintro ⟨x, hx⟩ exact hn.conj_mem _ hx c have hs : Function.Surjective (((MulAut.conj c).toMonoidHom.restrict N).codRestrict _ h) := by rintro ⟨x, hx⟩ refine ⟨⟨c⁻¹ * x * c, ?_⟩, ?_⟩ · have h := hn.conj_mem _ hx c⁻¹ rwa [inv_inv] at h simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, Subtype.mk_eq_mk, ← mul_assoc, mul_inv_cancel, one_mul] rw [mul_assoc, mul_inv_cancel, mul_one] rw [eq_top_iff, ← MonoidHom.range_eq_top.2 hs, MonoidHom.range_eq_map] refine le_trans (map_mono (eq_top_iff.1 ht)) (map_le_iff_le_comap.2 (normalClosure_le_normal ?_)) rw [Set.singleton_subset_iff, SetLike.mem_coe] simp only [MonoidHom.codRestrict_apply, MulEquiv.coe_toMonoidHom, MulAut.conj_apply, coe_mk, MonoidHom.restrict_apply, mem_comap] exact subset_normalClosure (Set.mem_singleton _) end IsConj namespace ConjClasses /-- The conjugacy classes that are not trivial. -/ def noncenter (G : Type*) [Monoid G] : Set (ConjClasses G) := {x | x.carrier.Nontrivial} @[simp] lemma mem_noncenter {G} [Monoid G] (g : ConjClasses G) : g ∈ noncenter G ↔ g.carrier.Nontrivial := Iff.rfl end ConjClasses /-- Suppose `G` acts on `M` and `I` is a subgroup of `M`. The inertia subgroup of `I` is the subgroup of `G` whose action is trivial mod `I`. -/ def AddSubgroup.inertia {M : Type*} [AddGroup M] (I : AddSubgroup M) (G : Type*) [Group G] [MulAction G M] : Subgroup G where carrier := { σ | ∀ x, σ • x - x ∈ I } mul_mem' {a b} ha hb x := by simpa [mul_smul] using add_mem (ha (b • x)) (hb x) one_mem' := by simp [zero_mem] inv_mem' {a} ha x := by simpa using sub_mem_comm_iff.mp (ha (a⁻¹ • x)) @[simp] lemma AddSubgroup.mem_inertia {M : Type*} [AddGroup M] {I : AddSubgroup M} {G : Type*} [Group G] [MulAction G M] {σ : G} : σ ∈ I.inertia G ↔ ∀ x, σ • x - x ∈ I := .rfl
Mathlib/Algebra/Group/Subgroup/Basic.lean
1,763
1,764
/- Copyright (c) 2021 Martin Zinkevich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Martin Zinkevich, Vincent Beffara -/ import Mathlib.MeasureTheory.Integral.Bochner.Set import Mathlib.Probability.Independence.Basic /-! # Integration in Probability Theory Integration results for independent random variables. Specifically, for two independent random variables X and Y over the extended non-negative reals, `E[X * Y] = E[X] * E[Y]`, and similar results. ## Implementation notes Many lemmas in this file take two arguments of the same typeclass. It is worth remembering that lean will always pick the later typeclass in this situation, and does not care whether the arguments are `[]`, `{}`, or `()`. All of these use the `MeasurableSpace` `M2` to define `μ`: ```lean example {M1 : MeasurableSpace Ω} [M2 : MeasurableSpace Ω] {μ : Measure Ω} : sorry := sorry example [M1 : MeasurableSpace Ω] {M2 : MeasurableSpace Ω} {μ : Measure Ω} : sorry := sorry ``` -/ noncomputable section open Set MeasureTheory open scoped ENNReal MeasureTheory variable {Ω : Type*} {mΩ : MeasurableSpace Ω} {μ : Measure Ω} {f g : Ω → ℝ≥0∞} {X Y : Ω → ℝ} namespace ProbabilityTheory /-- If a random variable `f` in `ℝ≥0∞` is independent of an event `T`, then if you restrict the random variable to `T`, then `E[f * indicator T c 0]=E[f] * E[indicator T c 0]`. It is useful for `lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace`. -/ theorem lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator {Mf mΩ : MeasurableSpace Ω} {μ : Measure Ω} (hMf : Mf ≤ mΩ) (c : ℝ≥0∞) {T : Set Ω} (h_meas_T : MeasurableSet T) (h_ind : IndepSets {s | MeasurableSet[Mf] s} {T} μ) (h_meas_f : Measurable[Mf] f) : (∫⁻ ω, f ω * T.indicator (fun _ => c) ω ∂μ) = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, T.indicator (fun _ => c) ω ∂μ := by revert f have h_mul_indicator : ∀ g, Measurable g → Measurable fun a => g a * T.indicator (fun _ => c) a := fun g h_mg => h_mg.mul (measurable_const.indicator h_meas_T) apply @Measurable.ennreal_induction _ Mf · intro c' s' h_meas_s' simp_rw [← inter_indicator_mul] rw [lintegral_indicator (MeasurableSet.inter (hMf _ h_meas_s') h_meas_T), lintegral_indicator (hMf _ h_meas_s'), lintegral_indicator h_meas_T] simp only [measurable_const, lintegral_const, univ_inter, lintegral_const_mul, MeasurableSet.univ, Measure.restrict_apply] rw [IndepSets_iff] at h_ind rw [mul_mul_mul_comm, h_ind s' T h_meas_s' (Set.mem_singleton _)] · intro f' g _ h_meas_f' _ h_ind_f' h_ind_g have h_measM_f' : Measurable f' := h_meas_f'.mono hMf le_rfl simp_rw [Pi.add_apply, right_distrib] rw [lintegral_add_left (h_mul_indicator _ h_measM_f'), lintegral_add_left h_measM_f', right_distrib, h_ind_f', h_ind_g] · intro f h_meas_f h_mono_f h_ind_f have h_measM_f : ∀ n, Measurable (f n) := fun n => (h_meas_f n).mono hMf le_rfl simp_rw [ENNReal.iSup_mul] rw [lintegral_iSup h_measM_f h_mono_f, lintegral_iSup, ENNReal.iSup_mul] · simp_rw [← h_ind_f] · exact fun n => h_mul_indicator _ (h_measM_f n) · exact fun m n h_le a => mul_le_mul_right' (h_mono_f h_le a) _ /-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`, then `E[f * g] = E[f] * E[g]`. However, instead of directly using the independence of the random variables, it uses the independence of measurable spaces for the domains of `f` and `g`. This is similar to the sigma-algebra approach to independence. See `lintegral_mul_eq_lintegral_mul_lintegral_of_indepFun` for a more common variant of the product of independent variables. -/ theorem lintegral_mul_eq_lintegral_mul_lintegral_of_independent_measurableSpace {Mf Mg mΩ : MeasurableSpace Ω} {μ : Measure Ω} (hMf : Mf ≤ mΩ) (hMg : Mg ≤ mΩ) (h_ind : Indep Mf Mg μ) (h_meas_f : Measurable[Mf] f) (h_meas_g : Measurable[Mg] g) :
∫⁻ ω, f ω * g ω ∂μ = (∫⁻ ω, f ω ∂μ) * ∫⁻ ω, g ω ∂μ := by revert g have h_measM_f : Measurable f := h_meas_f.mono hMf le_rfl apply @Measurable.ennreal_induction _ Mg · intro c s h_s apply lintegral_mul_indicator_eq_lintegral_mul_lintegral_indicator hMf _ (hMg _ h_s) _ h_meas_f apply indepSets_of_indepSets_of_le_right h_ind rwa [singleton_subset_iff] · intro f' g _ h_measMg_f' _ h_ind_f' h_ind_g' have h_measM_f' : Measurable f' := h_measMg_f'.mono hMg le_rfl simp_rw [Pi.add_apply, left_distrib] rw [lintegral_add_left h_measM_f', lintegral_add_left (h_measM_f.mul h_measM_f'), left_distrib, h_ind_f', h_ind_g'] · intro f' h_meas_f' h_mono_f' h_ind_f' have h_measM_f' : ∀ n, Measurable (f' n) := fun n => (h_meas_f' n).mono hMg le_rfl simp_rw [ENNReal.mul_iSup] rw [lintegral_iSup, lintegral_iSup h_measM_f' h_mono_f', ENNReal.mul_iSup] · simp_rw [← h_ind_f'] · exact fun n => h_measM_f.mul (h_measM_f' n) · exact fun n m (h_le : n ≤ m) a => mul_le_mul_left' (h_mono_f' h_le a) _ /-- If `f` and `g` are independent random variables with values in `ℝ≥0∞`, then `E[f * g] = E[f] * E[g]`. -/
Mathlib/Probability/Integration.lean
82
104
/- Copyright (c) 2021 Thomas Browning. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Thomas Browning -/ import Mathlib.GroupTheory.Index /-! # Complements In this file we define the complement of a subgroup. ## Main definitions - `Subgroup.IsComplement S T` where `S` and `T` are subsets of `G` states that every `g : G` can be written uniquely as a product `s * t` for `s ∈ S`, `t ∈ T`. - `H.LeftTransversal` where `H` is a subgroup of `G` is the type of all left-complements of `H`, i.e. the set of all `S : Set G` that contain exactly one element of each left coset of `H`. - `H.RightTransversal` where `H` is a subgroup of `G` is the set of all right-complements of `H`, i.e. the set of all `T : Set G` that contain exactly one element of each right coset of `H`. ## Main results - `isComplement'_of_coprime` : Subgroups of coprime order are complements. -/ open Function Set open scoped Pointwise namespace Subgroup variable {G : Type*} [Group G] (H K : Subgroup G) (S T : Set G) /-- `S` and `T` are complements if `(*) : S × T → G` is a bijection. This notion generalizes left transversals, right transversals, and complementary subgroups. -/ @[to_additive "`S` and `T` are complements if `(+) : S × T → G` is a bijection"] def IsComplement : Prop := Function.Bijective fun x : S × T => x.1.1 * x.2.1 /-- `H` and `K` are complements if `(*) : H × K → G` is a bijection -/ @[to_additive "`H` and `K` are complements if `(+) : H × K → G` is a bijection"] abbrev IsComplement' := IsComplement (H : Set G) (K : Set G) /-- The set of left-complements of `T : Set G` -/ @[to_additive (attr := deprecated IsComplement (since := "2024-12-18")) "The set of left-complements of `T : Set G`"] def leftTransversals : Set (Set G) := { S : Set G | IsComplement S T } /-- The set of right-complements of `S : Set G` -/ @[to_additive (attr := deprecated IsComplement (since := "2024-12-18")) "The set of right-complements of `S : Set G`"] def rightTransversals : Set (Set G) := { T : Set G | IsComplement S T } variable {H K S T} @[to_additive] theorem isComplement'_def : IsComplement' H K ↔ IsComplement (H : Set G) (K : Set G) := Iff.rfl @[to_additive] theorem isComplement_iff_existsUnique : IsComplement S T ↔ ∀ g : G, ∃! x : S × T, x.1.1 * x.2.1 = g := Function.bijective_iff_existsUnique _ @[to_additive] theorem IsComplement.existsUnique (h : IsComplement S T) (g : G) : ∃! x : S × T, x.1.1 * x.2.1 = g := isComplement_iff_existsUnique.mp h g @[to_additive] theorem IsComplement'.symm (h : IsComplement' H K) : IsComplement' K H := by let ϕ : H × K ≃ K × H := Equiv.mk (fun x => ⟨x.2⁻¹, x.1⁻¹⟩) (fun x => ⟨x.2⁻¹, x.1⁻¹⟩) (fun x => Prod.ext (inv_inv _) (inv_inv _)) fun x => Prod.ext (inv_inv _) (inv_inv _) let ψ : G ≃ G := Equiv.mk (fun g : G => g⁻¹) (fun g : G => g⁻¹) inv_inv inv_inv suffices hf : (ψ ∘ fun x : H × K => x.1.1 * x.2.1) = (fun x : K × H => x.1.1 * x.2.1) ∘ ϕ by rw [isComplement'_def, IsComplement, ← Equiv.bijective_comp ϕ] apply (congr_arg Function.Bijective hf).mp -- Porting note: This was a `rw` in mathlib3 rwa [ψ.comp_bijective] exact funext fun x => mul_inv_rev _ _ @[to_additive] theorem isComplement'_comm : IsComplement' H K ↔ IsComplement' K H := ⟨IsComplement'.symm, IsComplement'.symm⟩ @[to_additive] theorem isComplement_univ_singleton {g : G} : IsComplement (univ : Set G) {g} := ⟨fun ⟨_, _, rfl⟩ ⟨_, _, rfl⟩ h => Prod.ext (Subtype.ext (mul_right_cancel h)) rfl, fun x => ⟨⟨⟨x * g⁻¹, ⟨⟩⟩, g, rfl⟩, inv_mul_cancel_right x g⟩⟩ @[to_additive] theorem isComplement_singleton_univ {g : G} : IsComplement ({g} : Set G) univ := ⟨fun ⟨⟨_, rfl⟩, _⟩ ⟨⟨_, rfl⟩, _⟩ h => Prod.ext rfl (Subtype.ext (mul_left_cancel h)), fun x => ⟨⟨⟨g, rfl⟩, g⁻¹ * x, ⟨⟩⟩, mul_inv_cancel_left g x⟩⟩ @[to_additive] theorem isComplement_singleton_left {g : G} : IsComplement {g} S ↔ S = univ := by refine ⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => (congr_arg _ h).mpr isComplement_singleton_univ⟩ obtain ⟨⟨⟨z, rfl : z = g⟩, y, _⟩, hy⟩ := h.2 (g * x) rwa [← mul_left_cancel hy] @[to_additive] theorem isComplement_singleton_right {g : G} : IsComplement S {g} ↔ S = univ := by refine ⟨fun h => top_le_iff.mp fun x _ => ?_, fun h => h ▸ isComplement_univ_singleton⟩ obtain ⟨y, hy⟩ := h.2 (x * g) conv_rhs at hy => rw [← show y.2.1 = g from y.2.2] rw [← mul_right_cancel hy] exact y.1.2 @[to_additive] theorem isComplement_univ_left : IsComplement univ S ↔ ∃ g : G, S = {g} := by refine ⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩ · obtain ⟨a, _⟩ := h.2 1 exact ⟨a.2.1, a.2.2⟩ · have : (⟨⟨_, mem_top a⁻¹⟩, ⟨a, ha⟩⟩ : (⊤ : Set G) × S) = ⟨⟨_, mem_top b⁻¹⟩, ⟨b, hb⟩⟩ := h.1 ((inv_mul_cancel a).trans (inv_mul_cancel b).symm) exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).2 · rintro ⟨g, rfl⟩ exact isComplement_univ_singleton @[to_additive] theorem isComplement_univ_right : IsComplement S univ ↔ ∃ g : G, S = {g} := by refine ⟨fun h => Set.exists_eq_singleton_iff_nonempty_subsingleton.mpr ⟨?_, fun a ha b hb => ?_⟩, ?_⟩ · obtain ⟨a, _⟩ := h.2 1 exact ⟨a.1.1, a.1.2⟩ · have : (⟨⟨a, ha⟩, ⟨_, mem_top a⁻¹⟩⟩ : S × (⊤ : Set G)) = ⟨⟨b, hb⟩, ⟨_, mem_top b⁻¹⟩⟩ := h.1 ((mul_inv_cancel a).trans (mul_inv_cancel b).symm) exact Subtype.ext_iff.mp (Prod.ext_iff.mp this).1 · rintro ⟨g, rfl⟩ exact isComplement_singleton_univ @[to_additive] lemma IsComplement.mul_eq (h : IsComplement S T) : S * T = univ := eq_univ_of_forall fun x ↦ by simpa [mem_mul] using (h.existsUnique x).exists @[to_additive (attr := simp)] lemma not_isComplement_empty_left : ¬ IsComplement ∅ T := fun h ↦ by simpa [eq_comm (a := ∅)] using h.mul_eq @[to_additive (attr := simp)] lemma not_isComplement_empty_right : ¬ IsComplement S ∅ := fun h ↦ by simpa [eq_comm (a := ∅)] using h.mul_eq @[to_additive] lemma IsComplement.nonempty_left (hst : IsComplement S T) : S.Nonempty := by contrapose! hst; simp [hst] @[to_additive] lemma IsComplement.nonempty_right (hst : IsComplement S T) : T.Nonempty := by contrapose! hst; simp [hst] @[to_additive] lemma IsComplement.pairwiseDisjoint_smul (hst : IsComplement S T) : S.PairwiseDisjoint (· • T) := fun a ha b hb hab ↦ disjoint_iff_forall_ne.2 <| by rintro _ ⟨c, hc, rfl⟩ _ ⟨d, hd, rfl⟩ exact hst.1.ne (a₁ := (⟨a, ha⟩, ⟨c, hc⟩)) (a₂:= (⟨b, hb⟩, ⟨d, hd⟩)) (by simp [hab]) @[to_additive AddSubgroup.IsComplement.card_mul_card] lemma IsComplement.card_mul_card (h : IsComplement S T) : Nat.card S * Nat.card T = Nat.card G := (Nat.card_prod _ _).symm.trans <| Nat.card_congr <| Equiv.ofBijective _ h @[to_additive] theorem isComplement'_top_bot : IsComplement' (⊤ : Subgroup G) ⊥ := isComplement_univ_singleton @[to_additive] theorem isComplement'_bot_top : IsComplement' (⊥ : Subgroup G) ⊤ := isComplement_singleton_univ @[to_additive (attr := simp)] theorem isComplement'_bot_left : IsComplement' ⊥ H ↔ H = ⊤ := isComplement_singleton_left.trans coe_eq_univ @[to_additive (attr := simp)] theorem isComplement'_bot_right : IsComplement' H ⊥ ↔ H = ⊤ := isComplement_singleton_right.trans coe_eq_univ @[to_additive (attr := simp)] theorem isComplement'_top_left : IsComplement' ⊤ H ↔ H = ⊥ := isComplement_univ_left.trans coe_eq_singleton @[to_additive (attr := simp)] theorem isComplement'_top_right : IsComplement' H ⊤ ↔ H = ⊥ := isComplement_univ_right.trans coe_eq_singleton @[to_additive] lemma isComplement_iff_existsUnique_inv_mul_mem : IsComplement S T ↔ ∀ g, ∃! s : S, (s : G)⁻¹ * g ∈ T := by convert isComplement_iff_existsUnique with g constructor <;> rintro ⟨x, hx, hx'⟩ · exact ⟨(x, ⟨_, hx⟩), by simp, by aesop⟩ · exact ⟨x.1, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (y, ⟨_, hy⟩)).1⟩ set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_iff_existsUnique_inv_mul_mem (since := "2024-12-18"))] theorem mem_leftTransversals_iff_existsUnique_inv_mul_mem : S ∈ leftTransversals T ↔ ∀ g : G, ∃! s : S, (s : G)⁻¹ * g ∈ T := by rw [leftTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique] refine ⟨fun h g => ?_, fun h g => ?_⟩ · obtain ⟨x, h1, h2⟩ := h g exact ⟨x.1, (congr_arg (· ∈ T) (eq_inv_mul_of_mul_eq h1)).mp x.2.2, fun y hy => (Prod.ext_iff.mp (h2 ⟨y, (↑y)⁻¹ * g, hy⟩ (mul_inv_cancel_left ↑y g))).1⟩ · obtain ⟨x, h1, h2⟩ := h g refine ⟨⟨x, (↑x)⁻¹ * g, h1⟩, mul_inv_cancel_left (↑x) g, fun y hy => ?_⟩ have hf := h2 y.1 ((congr_arg (· ∈ T) (eq_inv_mul_of_mul_eq hy)).mp y.2.2) exact Prod.ext hf (Subtype.ext (eq_inv_mul_of_mul_eq (hf ▸ hy))) @[to_additive] lemma isComplement_iff_existsUnique_mul_inv_mem : IsComplement S T ↔ ∀ g, ∃! t : T, g * (t : G)⁻¹ ∈ S := by convert isComplement_iff_existsUnique with g constructor <;> rintro ⟨x, hx, hx'⟩ · exact ⟨(⟨_, hx⟩, x), by simp, by aesop⟩ · exact ⟨x.2, by simp [← hx], fun y hy ↦ (Prod.ext_iff.1 <| by simpa using hx' (⟨_, hy⟩, y)).2⟩ set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_iff_existsUnique_mul_inv_mem (since := "2024-12-18"))] theorem mem_rightTransversals_iff_existsUnique_mul_inv_mem : S ∈ rightTransversals T ↔ ∀ g : G, ∃! s : S, g * (s : G)⁻¹ ∈ T := by rw [rightTransversals, Set.mem_setOf_eq, isComplement_iff_existsUnique] refine ⟨fun h g => ?_, fun h g => ?_⟩ · obtain ⟨x, h1, h2⟩ := h g exact ⟨x.2, (congr_arg (· ∈ T) (eq_mul_inv_of_mul_eq h1)).mp x.1.2, fun y hy => (Prod.ext_iff.mp (h2 ⟨⟨g * (↑y)⁻¹, hy⟩, y⟩ (inv_mul_cancel_right g y))).2⟩ · obtain ⟨x, h1, h2⟩ := h g refine ⟨⟨⟨g * (↑x)⁻¹, h1⟩, x⟩, inv_mul_cancel_right g x, fun y hy => ?_⟩ have hf := h2 y.2 ((congr_arg (· ∈ T) (eq_mul_inv_of_mul_eq hy)).mp y.1.2) exact Prod.ext (Subtype.ext (eq_mul_inv_of_mul_eq (hf ▸ hy))) hf @[to_additive] lemma isComplement_subgroup_right_iff_existsUnique_quotientGroupMk : IsComplement S H ↔ ∀ q : G ⧸ H, ∃! s : S, QuotientGroup.mk s.1 = q := by simp_rw [isComplement_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ← QuotientGroup.eq, QuotientGroup.forall_mk] set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_right_iff_existsUnique_quotientGroupMk (since := "2024-12-18"))] theorem mem_leftTransversals_iff_existsUnique_quotient_mk''_eq : S ∈ leftTransversals (H : Set G) ↔ ∀ q : Quotient (QuotientGroup.leftRel H), ∃! s : S, Quotient.mk'' s.1 = q := by simp_rw [mem_leftTransversals_iff_existsUnique_inv_mul_mem, SetLike.mem_coe, ← QuotientGroup.eq] exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩ set_option linter.docPrime false in @[to_additive] lemma isComplement_subgroup_left_iff_existsUnique_quotientMk'' : IsComplement H T ↔ ∀ q : Quotient (QuotientGroup.rightRel H), ∃! t : T, Quotient.mk'' t.1 = q := by simp_rw [isComplement_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, ← QuotientGroup.rightRel_apply, ← Quotient.eq'', Quotient.forall] set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_left_iff_existsUnique_quotientMk'' (since := "2024-12-18"))] theorem mem_rightTransversals_iff_existsUnique_quotient_mk''_eq : S ∈ rightTransversals (H : Set G) ↔ ∀ q : Quotient (QuotientGroup.rightRel H), ∃! s : S, Quotient.mk'' s.1 = q := by simp_rw [mem_rightTransversals_iff_existsUnique_mul_inv_mem, SetLike.mem_coe, ← QuotientGroup.rightRel_apply, ← Quotient.eq''] exact ⟨fun h q => Quotient.inductionOn' q h, fun h g => h (Quotient.mk'' g)⟩ @[to_additive] lemma isComplement_subgroup_right_iff_bijective : IsComplement S H ↔ Bijective (S.restrict (QuotientGroup.mk : G → G ⧸ H)) := isComplement_subgroup_right_iff_existsUnique_quotientGroupMk.trans (bijective_iff_existsUnique (S.restrict QuotientGroup.mk)).symm set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_right_iff_bijective (since := "2024-12-18"))] theorem mem_leftTransversals_iff_bijective : S ∈ leftTransversals (H : Set G) ↔ Function.Bijective (S.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.leftRel H))) := mem_leftTransversals_iff_existsUnique_quotient_mk''_eq.trans (Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm @[to_additive] lemma isComplement_subgroup_left_iff_bijective : IsComplement H T ↔ Bijective (T.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.rightRel H))) := isComplement_subgroup_left_iff_existsUnique_quotientMk''.trans (bijective_iff_existsUnique (T.restrict Quotient.mk'')).symm set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_subgroup_left_iff_bijective (since := "2024-12-18"))] theorem mem_rightTransversals_iff_bijective : S ∈ rightTransversals (H : Set G) ↔ Function.Bijective (S.restrict (Quotient.mk'' : G → Quotient (QuotientGroup.rightRel H))) := mem_rightTransversals_iff_existsUnique_quotient_mk''_eq.trans (Function.bijective_iff_existsUnique (S.restrict Quotient.mk'')).symm @[to_additive] lemma IsComplement.card_left (h : IsComplement S H) : Nat.card S = H.index := Nat.card_congr <| .ofBijective _ <| isComplement_subgroup_right_iff_bijective.mp h set_option linter.deprecated false in @[to_additive (attr := deprecated IsComplement.card_left (since := "2024-12-18"))] theorem card_left_transversal (h : S ∈ leftTransversals (H : Set G)) : Nat.card S = H.index := Nat.card_congr <| Equiv.ofBijective _ <| mem_leftTransversals_iff_bijective.mp h @[to_additive] lemma IsComplement.card_right (h : IsComplement H T) : Nat.card T = H.index := Nat.card_congr <| (Equiv.ofBijective _ <| isComplement_subgroup_left_iff_bijective.mp h).trans <| QuotientGroup.quotientRightRelEquivQuotientLeftRel H set_option linter.deprecated false in @[to_additive (attr := deprecated IsComplement.card_right (since := "2024-12-18"))] theorem card_right_transversal (h : S ∈ rightTransversals (H : Set G)) : Nat.card S = H.index := Nat.card_congr <| (Equiv.ofBijective _ <| mem_rightTransversals_iff_bijective.mp h).trans <| QuotientGroup.quotientRightRelEquivQuotientLeftRel H @[to_additive] lemma isComplement_range_left {f : G ⧸ H → G} (hf : ∀ q, ↑(f q) = q) : IsComplement (range f) H := by rw [isComplement_subgroup_right_iff_bijective] refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩ rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂) set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_range_left (since := "2024-12-18"))] theorem range_mem_leftTransversals {f : G ⧸ H → G} (hf : ∀ q, ↑(f q) = q) : Set.range f ∈ leftTransversals (H : Set G) := mem_leftTransversals_iff_bijective.mpr ⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂), fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩ @[to_additive] lemma isComplement_range_right {f : Quotient (QuotientGroup.rightRel H) → G} (hf : ∀ q, Quotient.mk'' (f q) = q) : IsComplement H (range f) := by rw [isComplement_subgroup_left_iff_bijective] refine ⟨?_, fun q ↦ ⟨⟨f q, q, rfl⟩, hf q⟩⟩ rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂) set_option linter.deprecated false in @[to_additive (attr := deprecated isComplement_range_right (since := "2024-12-18"))] theorem range_mem_rightTransversals {f : Quotient (QuotientGroup.rightRel H) → G} (hf : ∀ q, Quotient.mk'' (f q) = q) : Set.range f ∈ rightTransversals (H : Set G) := mem_rightTransversals_iff_bijective.mpr ⟨by rintro ⟨-, q₁, rfl⟩ ⟨-, q₂, rfl⟩ h exact Subtype.ext <| congr_arg f <| ((hf q₁).symm.trans h).trans (hf q₂), fun q => ⟨⟨f q, q, rfl⟩, hf q⟩⟩ @[to_additive] lemma exists_isComplement_left (H : Subgroup G) (g : G) : ∃ S, IsComplement S H ∧ g ∈ S := by classical refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_left fun q ↦ ?_, QuotientGroup.mk g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g · exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) · refine Function.update_of_ne ?_ g Quotient.out ▸ q.out_eq' exact hq set_option linter.deprecated false in @[to_additive (attr := deprecated exists_isComplement_left (since := "2024-12-18"))] lemma exists_left_transversal (H : Subgroup G) (g : G) : ∃ S ∈ leftTransversals (H : Set G), g ∈ S := by classical refine ⟨Set.range (Function.update Quotient.out _ g), range_mem_leftTransversals fun q => ?_, Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g · exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) · refine (Function.update_of_ne ?_ g Quotient.out) ▸ q.out_eq' exact hq @[to_additive] lemma exists_isComplement_right (H : Subgroup G) (g : G) : ∃ T, IsComplement H T ∧ g ∈ T := by classical refine ⟨Set.range (Function.update Quotient.out _ g), isComplement_range_right fun q ↦ ?_, Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g · exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) · refine Function.update_of_ne ?_ g Quotient.out ▸ q.out_eq' exact hq set_option linter.deprecated false in @[to_additive (attr := deprecated exists_isComplement_right (since := "2024-12-18"))] lemma exists_right_transversal (H : Subgroup G) (g : G) : ∃ S ∈ rightTransversals (H : Set G), g ∈ S := by classical refine ⟨Set.range (Function.update Quotient.out _ g), range_mem_rightTransversals fun q => ?_, Quotient.mk'' g, Function.update_self (Quotient.mk'' g) g Quotient.out⟩ by_cases hq : q = Quotient.mk'' g · exact hq.symm ▸ congr_arg _ (Function.update_self (Quotient.mk'' g) g Quotient.out) · exact Eq.trans (congr_arg _ (Function.update_of_ne hq g Quotient.out)) q.out_eq' /-- Given two subgroups `H' ⊆ H`, there exists a left transversal to `H'` inside `H`. -/ @[to_additive "Given two subgroups `H' ⊆ H`, there exists a transversal to `H'` inside `H`"] lemma exists_left_transversal_of_le {H' H : Subgroup G} (h : H' ≤ H) : ∃ S : Set G, S * H' = H ∧ Nat.card S * Nat.card H' = Nat.card H := by let H'' : Subgroup H := H'.comap H.subtype have : H' = H''.map H.subtype := by simp [H'', h] rw [this] obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_left 1 refine ⟨H.subtype '' S, ?_, ?_⟩ · have : H.subtype '' (S * H'') = H.subtype '' S * H''.map H.subtype := image_mul H.subtype rw [← this, cmem.mul_eq] simp [Set.ext_iff] · rw [← cmem.card_mul_card] refine congr_arg₂ (· * ·) ?_ ?_ <;> exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm /-- Given two subgroups `H' ⊆ H`, there exists a right transversal to `H'` inside `H`. -/ @[to_additive "Given two subgroups `H' ⊆ H`, there exists a transversal to `H'` inside `H`"] lemma exists_right_transversal_of_le {H' H : Subgroup G} (h : H' ≤ H) : ∃ S : Set G, H' * S = H ∧ Nat.card H' * Nat.card S = Nat.card H := by let H'' : Subgroup H := H'.comap H.subtype have : H' = H''.map H.subtype := by simp [H'', h] rw [this] obtain ⟨S, cmem, -⟩ := H''.exists_isComplement_right 1 refine ⟨H.subtype '' S, ?_, ?_⟩ · have : H.subtype '' (H'' * S) = H''.map H.subtype * H.subtype '' S := image_mul H.subtype rw [← this, cmem.mul_eq] simp [Set.ext_iff] · have : Nat.card H'' * Nat.card S = Nat.card H := cmem.card_mul_card rw [← this] refine congr_arg₂ (· * ·) ?_ ?_ <;> exact Nat.card_congr (Equiv.Set.image _ _ <| subtype_injective H).symm namespace IsComplement /-- The equivalence `G ≃ S × T`, such that the inverse is `(*) : S × T → G` -/ noncomputable def equiv {S T : Set G} (hST : IsComplement S T) : G ≃ S × T := (Equiv.ofBijective (fun x : S × T => x.1.1 * x.2.1) hST).symm variable (hST : IsComplement S T) (hHT : IsComplement H T) (hSK : IsComplement S K) @[simp] theorem equiv_symm_apply (x : S × T) : (hST.equiv.symm x : G) = x.1.1 * x.2.1 := rfl @[simp] theorem equiv_fst_mul_equiv_snd (g : G) : ↑(hST.equiv g).fst * (hST.equiv g).snd = g := (Equiv.ofBijective (fun x : S × T => x.1.1 * x.2.1) hST).right_inv g theorem equiv_fst_eq_mul_inv (g : G) : ↑(hST.equiv g).fst = g * ((hST.equiv g).snd : G)⁻¹ := eq_mul_inv_of_mul_eq (hST.equiv_fst_mul_equiv_snd g) theorem equiv_snd_eq_inv_mul (g : G) : ↑(hST.equiv g).snd = ((hST.equiv g).fst : G)⁻¹ * g := eq_inv_mul_of_mul_eq (hST.equiv_fst_mul_equiv_snd g) theorem equiv_fst_eq_iff_leftCosetEquivalence {g₁ g₂ : G} : (hSK.equiv g₁).fst = (hSK.equiv g₂).fst ↔ LeftCosetEquivalence K g₁ g₂ := by rw [LeftCosetEquivalence, leftCoset_eq_iff] constructor · intro h rw [← hSK.equiv_fst_mul_equiv_snd g₂, ← hSK.equiv_fst_mul_equiv_snd g₁, ← h, mul_inv_rev, ← mul_assoc, inv_mul_cancel_right, ← coe_inv, ← coe_mul] exact Subtype.property _ · intro h apply (isComplement_iff_existsUnique_inv_mul_mem.1 hSK g₁).unique · -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_fst_eq_mul_inv]; simp · rw [SetLike.mem_coe, ← mul_mem_cancel_right h] -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_fst_eq_mul_inv]; simp [equiv_fst_eq_mul_inv, ← mul_assoc] theorem equiv_snd_eq_iff_rightCosetEquivalence {g₁ g₂ : G} : (hHT.equiv g₁).snd = (hHT.equiv g₂).snd ↔ RightCosetEquivalence H g₁ g₂ := by rw [RightCosetEquivalence, rightCoset_eq_iff] constructor · intro h rw [← hHT.equiv_fst_mul_equiv_snd g₂, ← hHT.equiv_fst_mul_equiv_snd g₁, ← h, mul_inv_rev, mul_assoc, mul_inv_cancel_left, ← coe_inv, ← coe_mul] exact Subtype.property _ · intro h apply (isComplement_iff_existsUnique_mul_inv_mem.1 hHT g₁).unique · -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_snd_eq_inv_mul]; simp · rw [SetLike.mem_coe, ← mul_mem_cancel_left h] -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [equiv_snd_eq_inv_mul, mul_assoc]; simp theorem leftCosetEquivalence_equiv_fst (g : G) : LeftCosetEquivalence K g ((hSK.equiv g).fst : G) := by -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644
rw [equiv_fst_eq_mul_inv]; simp [LeftCosetEquivalence, leftCoset_eq_iff] theorem rightCosetEquivalence_equiv_snd (g : G) : RightCosetEquivalence H g ((hHT.equiv g).snd : G) := by -- This used to be `simp [...]` before https://github.com/leanprover/lean4/pull/2644 rw [RightCosetEquivalence, rightCoset_eq_iff, equiv_snd_eq_inv_mul]; simp theorem equiv_fst_eq_self_of_mem_of_one_mem {g : G} (h1 : 1 ∈ T) (hg : g ∈ S) :
Mathlib/GroupTheory/Complement.lean
496
503
/- Copyright (c) 2014 Parikshit Khanna. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro -/ import Batteries.Data.List.Perm import Mathlib.Tactic.Common /-! # Counting in lists This file proves basic properties of `List.countP` and `List.count`, which count the number of elements of a list satisfying a predicate and equal to a given element respectively. -/ assert_not_exists Monoid Set.range open Nat variable {α β : Type*} namespace List @[simp] theorem countP_lt_length_iff {l : List α} {p : α → Bool} : l.countP p < l.length ↔ ∃ a ∈ l, p a = false := by simp [Nat.lt_iff_le_and_ne, countP_le_length] variable [DecidableEq α] {l l₁ l₂ : List α} @[simp] theorem count_lt_length_iff {a : α} : l.count a < l.length ↔ ∃ b ∈ l, b ≠ a := by simp [count] lemma countP_erase (p : α → Bool) (l : List α) (a : α) : countP p (l.erase a) = countP p l - if a ∈ l ∧ p a then 1 else 0 := by rw [countP_eq_length_filter, countP_eq_length_filter, ← erase_filter, length_erase] aesop lemma count_diff (a : α) (l₁ : List α) : ∀ l₂, count a (l₁.diff l₂) = count a l₁ - count a l₂ | [] => rfl | b :: l₂ => by simp only [diff_cons, count_diff, count_erase, beq_iff_eq, Nat.sub_right_comm, count_cons, Nat.sub_add_eq] lemma countP_diff (hl : l₂ <+~ l₁) (p : α → Bool) : countP p (l₁.diff l₂) = countP p l₁ - countP p l₂ := by refine (Nat.sub_eq_of_eq_add ?_).symm rw [← countP_append] exact ((subperm_append_diff_self_of_count_le <| subperm_ext_iff.1 hl).symm.trans perm_append_comm).countP_eq _ @[simp] theorem count_map_of_injective [DecidableEq β] (l : List α) (f : α → β) (hf : Function.Injective f) (x : α) : count (f x) (map f l) = count x l := by simp only [count, countP_map] unfold Function.comp simp only [hf.beq_eq] end List
Mathlib/Data/List/Count.lean
71
72
/- Copyright (c) 2018 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Data.Set.Lattice import Mathlib.Order.ConditionallyCompleteLattice.Defs /-! # Theory of conditionally complete lattices A conditionally complete lattice is a lattice in which every non-empty bounded subset `s` has a least upper bound and a greatest lower bound, denoted below by `sSup s` and `sInf s`. Typical examples are `ℝ`, `ℕ`, and `ℤ` with their usual orders. The theory is very comparable to the theory of complete lattices, except that suitable boundedness and nonemptiness assumptions have to be added to most statements. We express these using the `BddAbove` and `BddBelow` predicates, which we use to prove most useful properties of `sSup` and `sInf` in conditionally complete lattices. To differentiate the statements between complete lattices and conditionally complete lattices, we prefix `sInf` and `sSup` in the statements by `c`, giving `csInf` and `csSup`. For instance, `sInf_le` is a statement in complete lattices ensuring `sInf s ≤ x`, while `csInf_le` is the same statement in conditionally complete lattices with an additional assumption that `s` is bounded below. -/ -- Guard against import creep assert_not_exists Multiset open Function OrderDual Set variable {α β γ : Type*} {ι : Sort*} section /-! Extension of `sSup` and `sInf` from a preorder `α` to `WithTop α` and `WithBot α` -/ variable [Preorder α] open Classical in noncomputable instance WithTop.instSupSet [SupSet α] : SupSet (WithTop α) := ⟨fun S => if ⊤ ∈ S then ⊤ else if BddAbove ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α) then ↑(sSup ((fun (a : α) ↦ (a : WithTop α)) ⁻¹' S : Set α)) else ⊤⟩ open Classical in noncomputable instance WithTop.instInfSet [InfSet α] : InfSet (WithTop α) := ⟨fun S => if S ⊆ {⊤} ∨ ¬BddBelow S then ⊤ else ↑(sInf ((fun (a : α) ↦ ↑a) ⁻¹' S : Set α))⟩ noncomputable instance WithBot.instSupSet [SupSet α] : SupSet (WithBot α) := ⟨(WithTop.instInfSet (α := αᵒᵈ)).sInf⟩ noncomputable instance WithBot.instInfSet [InfSet α] : InfSet (WithBot α) := ⟨(WithTop.instSupSet (α := αᵒᵈ)).sSup⟩ theorem WithTop.sSup_eq [SupSet α] {s : Set (WithTop α)} (hs : ⊤ ∉ s) (hs' : BddAbove ((↑) ⁻¹' s : Set α)) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) := (if_neg hs).trans <| if_pos hs' theorem WithTop.sInf_eq [InfSet α] {s : Set (WithTop α)} (hs : ¬s ⊆ {⊤}) (h's : BddBelow s) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) := if_neg <| by simp [hs, h's] theorem WithBot.sInf_eq [InfSet α] {s : Set (WithBot α)} (hs : ⊥ ∉ s) (hs' : BddBelow ((↑) ⁻¹' s : Set α)) : sInf s = ↑(sInf ((↑) ⁻¹' s) : α) := (if_neg hs).trans <| if_pos hs' theorem WithBot.sSup_eq [SupSet α] {s : Set (WithBot α)} (hs : ¬s ⊆ {⊥}) (h's : BddAbove s) : sSup s = ↑(sSup ((↑) ⁻¹' s) : α) := WithTop.sInf_eq (α := αᵒᵈ) hs h's @[simp] theorem WithTop.sInf_empty [InfSet α] : sInf (∅ : Set (WithTop α)) = ⊤ := if_pos <| by simp theorem WithTop.coe_sInf' [InfSet α] {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) : ↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by classical obtain ⟨x, hx⟩ := hs change _ = ite _ _ _ split_ifs with h · rcases h with h1 | h2 · cases h1 (mem_image_of_mem _ hx) · exact (h2 (Monotone.map_bddBelow coe_mono h's)).elim · rw [preimage_image_eq] exact Option.some_injective _ theorem WithTop.coe_sSup' [SupSet α] {s : Set α} (hs : BddAbove s) : ↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithTop α) := by classical change _ = ite _ _ _ rw [if_neg, preimage_image_eq, if_pos hs] · exact Option.some_injective _ · rintro ⟨x, _, ⟨⟩⟩ @[simp] theorem WithBot.sSup_empty [SupSet α] : sSup (∅ : Set (WithBot α)) = ⊥ := WithTop.sInf_empty (α := αᵒᵈ) @[norm_cast] theorem WithBot.coe_sSup' [SupSet α] {s : Set α} (hs : s.Nonempty) (h's : BddAbove s) : ↑(sSup s) = (sSup ((fun (a : α) ↦ ↑a) '' s) : WithBot α) := WithTop.coe_sInf' (α := αᵒᵈ) hs h's @[norm_cast] theorem WithBot.coe_sInf' [InfSet α] {s : Set α} (hs : BddBelow s) : ↑(sInf s) = (sInf ((fun (a : α) ↦ ↑a) '' s) : WithBot α) := WithTop.coe_sSup' (α := αᵒᵈ) hs end instance ConditionallyCompleteLinearOrder.toLinearOrder [ConditionallyCompleteLinearOrder α] : LinearOrder α := { ‹ConditionallyCompleteLinearOrder α› with min_def := fun a b ↦ by by_cases hab : a = b · simp [hab] · rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂) · simp [h₁] · simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] max_def := fun a b ↦ by by_cases hab : a = b · simp [hab] · rcases ConditionallyCompleteLinearOrder.le_total a b with (h₁ | h₂) · simp [h₁] · simp [show ¬(a ≤ b) from fun h => hab (le_antisymm h h₂), h₂] } -- see Note [lower instance priority] attribute [instance 100] ConditionallyCompleteLinearOrderBot.toOrderBot -- see Note [lower instance priority] /-- A complete lattice is a conditionally complete lattice, as there are no restrictions on the properties of sInf and sSup in a complete lattice. -/ instance (priority := 100) CompleteLattice.toConditionallyCompleteLattice [CompleteLattice α] : ConditionallyCompleteLattice α := { ‹CompleteLattice α› with le_csSup := by intros; apply le_sSup; assumption csSup_le := by intros; apply sSup_le; assumption csInf_le := by intros; apply sInf_le; assumption le_csInf := by intros; apply le_sInf; assumption } -- see Note [lower instance priority] instance (priority := 100) CompleteLinearOrder.toConditionallyCompleteLinearOrderBot {α : Type*} [h : CompleteLinearOrder α] : ConditionallyCompleteLinearOrderBot α := { CompleteLattice.toConditionallyCompleteLattice, h with csSup_empty := sSup_empty csSup_of_not_bddAbove := fun s H ↦ (H (OrderTop.bddAbove s)).elim csInf_of_not_bddBelow := fun s H ↦ (H (OrderBot.bddBelow s)).elim } namespace OrderDual instance instConditionallyCompleteLattice (α : Type*) [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice αᵒᵈ := { OrderDual.instInf α, OrderDual.instSup α, OrderDual.instLattice α with le_csSup := ConditionallyCompleteLattice.csInf_le (α := α) csSup_le := ConditionallyCompleteLattice.le_csInf (α := α) le_csInf := ConditionallyCompleteLattice.csSup_le (α := α) csInf_le := ConditionallyCompleteLattice.le_csSup (α := α) } instance (α : Type*) [ConditionallyCompleteLinearOrder α] : ConditionallyCompleteLinearOrder αᵒᵈ := { OrderDual.instConditionallyCompleteLattice α, OrderDual.instLinearOrder α with csSup_of_not_bddAbove := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow (α := α) csInf_of_not_bddBelow := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove (α := α) } end OrderDual section ConditionallyCompleteLattice variable [ConditionallyCompleteLattice α] {s t : Set α} {a b : α} theorem le_csSup (h₁ : BddAbove s) (h₂ : a ∈ s) : a ≤ sSup s := ConditionallyCompleteLattice.le_csSup s a h₁ h₂ theorem csSup_le (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, b ≤ a) : sSup s ≤ a := ConditionallyCompleteLattice.csSup_le s a h₁ h₂ theorem csInf_le (h₁ : BddBelow s) (h₂ : a ∈ s) : sInf s ≤ a := ConditionallyCompleteLattice.csInf_le s a h₁ h₂ theorem le_csInf (h₁ : s.Nonempty) (h₂ : ∀ b ∈ s, a ≤ b) : a ≤ sInf s := ConditionallyCompleteLattice.le_csInf s a h₁ h₂ theorem le_csSup_of_le (hs : BddAbove s) (hb : b ∈ s) (h : a ≤ b) : a ≤ sSup s := le_trans h (le_csSup hs hb) theorem csInf_le_of_le (hs : BddBelow s) (hb : b ∈ s) (h : b ≤ a) : sInf s ≤ a := le_trans (csInf_le hs hb) h theorem csSup_le_csSup (ht : BddAbove t) (hs : s.Nonempty) (h : s ⊆ t) : sSup s ≤ sSup t := csSup_le hs fun _ ha => le_csSup ht (h ha) theorem csInf_le_csInf (ht : BddBelow t) (hs : s.Nonempty) (h : s ⊆ t) : sInf t ≤ sInf s := le_csInf hs fun _ ha => csInf_le ht (h ha) theorem le_csSup_iff (h : BddAbove s) (hs : s.Nonempty) : a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b := ⟨fun h _ hb => le_trans h (csSup_le hs hb), fun hb => hb _ fun _ => le_csSup h⟩ theorem csInf_le_iff (h : BddBelow s) (hs : s.Nonempty) : sInf s ≤ a ↔ ∀ b ∈ lowerBounds s, b ≤ a := ⟨fun h _ hb => le_trans (le_csInf hs hb) h, fun hb => hb _ fun _ => csInf_le h⟩ theorem isLUB_csSup (ne : s.Nonempty) (H : BddAbove s) : IsLUB s (sSup s) := ⟨fun _ => le_csSup H, fun _ => csSup_le ne⟩ theorem isGLB_csInf (ne : s.Nonempty) (H : BddBelow s) : IsGLB s (sInf s) := ⟨fun _ => csInf_le H, fun _ => le_csInf ne⟩ theorem IsLUB.csSup_eq (H : IsLUB s a) (ne : s.Nonempty) : sSup s = a := (isLUB_csSup ne ⟨a, H.1⟩).unique H /-- A greatest element of a set is the supremum of this set. -/ theorem IsGreatest.csSup_eq (H : IsGreatest s a) : sSup s = a := H.isLUB.csSup_eq H.nonempty theorem IsGreatest.csSup_mem (H : IsGreatest s a) : sSup s ∈ s := H.csSup_eq.symm ▸ H.1 theorem IsGLB.csInf_eq (H : IsGLB s a) (ne : s.Nonempty) : sInf s = a := (isGLB_csInf ne ⟨a, H.1⟩).unique H /-- A least element of a set is the infimum of this set. -/ theorem IsLeast.csInf_eq (H : IsLeast s a) : sInf s = a := H.isGLB.csInf_eq H.nonempty theorem IsLeast.csInf_mem (H : IsLeast s a) : sInf s ∈ s := H.csInf_eq.symm ▸ H.1 theorem subset_Icc_csInf_csSup (hb : BddBelow s) (ha : BddAbove s) : s ⊆ Icc (sInf s) (sSup s) := fun _ hx => ⟨csInf_le hb hx, le_csSup ha hx⟩ theorem csSup_le_iff (hb : BddAbove s) (hs : s.Nonempty) : sSup s ≤ a ↔ ∀ b ∈ s, b ≤ a := isLUB_le_iff (isLUB_csSup hs hb) theorem le_csInf_iff (hb : BddBelow s) (hs : s.Nonempty) : a ≤ sInf s ↔ ∀ b ∈ s, a ≤ b := le_isGLB_iff (isGLB_csInf hs hb) theorem csSup_lowerBounds_eq_csInf {s : Set α} (h : BddBelow s) (hs : s.Nonempty) : sSup (lowerBounds s) = sInf s := (isLUB_csSup h <| hs.mono fun _ hx _ hy => hy hx).unique (isGLB_csInf hs h).isLUB theorem csInf_upperBounds_eq_csSup {s : Set α} (h : BddAbove s) (hs : s.Nonempty) : sInf (upperBounds s) = sSup s := (isGLB_csInf h <| hs.mono fun _ hx _ hy => hy hx).unique (isLUB_csSup hs h).isGLB theorem csSup_lowerBounds_range [Nonempty β] {f : β → α} (hf : BddBelow (range f)) : sSup (lowerBounds (range f)) = ⨅ i, f i := csSup_lowerBounds_eq_csInf hf <| range_nonempty _ theorem csInf_upperBounds_range [Nonempty β] {f : β → α} (hf : BddAbove (range f)) : sInf (upperBounds (range f)) = ⨆ i, f i := csInf_upperBounds_eq_csSup hf <| range_nonempty _ theorem not_mem_of_lt_csInf {x : α} {s : Set α} (h : x < sInf s) (hs : BddBelow s) : x ∉ s := fun hx => lt_irrefl _ (h.trans_le (csInf_le hs hx)) theorem not_mem_of_csSup_lt {x : α} {s : Set α} (h : sSup s < x) (hs : BddAbove s) : x ∉ s := not_mem_of_lt_csInf (α := αᵒᵈ) h hs /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that `b` is larger than all elements of `s`, and that this is not the case of any `w<b`. See `sSup_eq_of_forall_le_of_forall_lt_exists_gt` for a version in complete lattices. -/ theorem csSup_eq_of_forall_le_of_forall_lt_exists_gt (hs : s.Nonempty) (H : ∀ a ∈ s, a ≤ b) (H' : ∀ w, w < b → ∃ a ∈ s, w < a) : sSup s = b := (eq_of_le_of_not_lt (csSup_le hs H)) fun hb => let ⟨_, ha, ha'⟩ := H' _ hb lt_irrefl _ <| ha'.trans_le <| le_csSup ⟨b, H⟩ ha /-- Introduction rule to prove that `b` is the infimum of `s`: it suffices to check that `b` is smaller than all elements of `s`, and that this is not the case of any `w>b`. See `sInf_eq_of_forall_ge_of_forall_gt_exists_lt` for a version in complete lattices. -/ theorem csInf_eq_of_forall_ge_of_forall_gt_exists_lt : s.Nonempty → (∀ a ∈ s, b ≤ a) → (∀ w, b < w → ∃ a ∈ s, a < w) → sInf s = b := csSup_eq_of_forall_le_of_forall_lt_exists_gt (α := αᵒᵈ) /-- `b < sSup s` when there is an element `a` in `s` with `b < a`, when `s` is bounded above. This is essentially an iff, except that the assumptions for the two implications are slightly different (one needs boundedness above for one direction, nonemptiness and linear order for the other one), so we formulate separately the two implications, contrary to the `CompleteLattice` case. -/ theorem lt_csSup_of_lt (hs : BddAbove s) (ha : a ∈ s) (h : b < a) : b < sSup s := lt_of_lt_of_le h (le_csSup hs ha) /-- `sInf s < b` when there is an element `a` in `s` with `a < b`, when `s` is bounded below. This is essentially an iff, except that the assumptions for the two implications are slightly different (one needs boundedness below for one direction, nonemptiness and linear order for the other one), so we formulate separately the two implications, contrary to the `CompleteLattice` case. -/ theorem csInf_lt_of_lt : BddBelow s → a ∈ s → a < b → sInf s < b := lt_csSup_of_lt (α := αᵒᵈ) /-- If all elements of a nonempty set `s` are less than or equal to all elements of a nonempty set `t`, then there exists an element between these sets. -/ theorem exists_between_of_forall_le (sne : s.Nonempty) (tne : t.Nonempty) (hst : ∀ x ∈ s, ∀ y ∈ t, x ≤ y) : (upperBounds s ∩ lowerBounds t).Nonempty := ⟨sInf t, fun x hx => le_csInf tne <| hst x hx, fun _ hy => csInf_le (sne.mono hst) hy⟩ /-- The supremum of a singleton is the element of the singleton -/ @[simp] theorem csSup_singleton (a : α) : sSup {a} = a := isGreatest_singleton.csSup_eq /-- The infimum of a singleton is the element of the singleton -/ @[simp] theorem csInf_singleton (a : α) : sInf {a} = a := isLeast_singleton.csInf_eq theorem csSup_pair (a b : α) : sSup {a, b} = a ⊔ b := (@isLUB_pair _ _ a b).csSup_eq (insert_nonempty _ _) theorem csInf_pair (a b : α) : sInf {a, b} = a ⊓ b := (@isGLB_pair _ _ a b).csInf_eq (insert_nonempty _ _) /-- If a set is bounded below and above, and nonempty, its infimum is less than or equal to its supremum. -/ theorem csInf_le_csSup (hb : BddBelow s) (ha : BddAbove s) (ne : s.Nonempty) : sInf s ≤ sSup s := isGLB_le_isLUB (isGLB_csInf ne hb) (isLUB_csSup ne ha) ne /-- The `sSup` of a union of two sets is the max of the suprema of each subset, under the assumptions that all sets are bounded above and nonempty. -/ theorem csSup_union (hs : BddAbove s) (sne : s.Nonempty) (ht : BddAbove t) (tne : t.Nonempty) : sSup (s ∪ t) = sSup s ⊔ sSup t := ((isLUB_csSup sne hs).union (isLUB_csSup tne ht)).csSup_eq sne.inl /-- The `sInf` of a union of two sets is the min of the infima of each subset, under the assumptions that all sets are bounded below and nonempty. -/ theorem csInf_union (hs : BddBelow s) (sne : s.Nonempty) (ht : BddBelow t) (tne : t.Nonempty) : sInf (s ∪ t) = sInf s ⊓ sInf t := csSup_union (α := αᵒᵈ) hs sne ht tne /-- The supremum of an intersection of two sets is bounded by the minimum of the suprema of each set, if all sets are bounded above and nonempty. -/ theorem csSup_inter_le (hs : BddAbove s) (ht : BddAbove t) (hst : (s ∩ t).Nonempty) : sSup (s ∩ t) ≤ sSup s ⊓ sSup t := (csSup_le hst) fun _ hx => le_inf (le_csSup hs hx.1) (le_csSup ht hx.2) /-- The infimum of an intersection of two sets is bounded below by the maximum of the infima of each set, if all sets are bounded below and nonempty. -/ theorem le_csInf_inter : BddBelow s → BddBelow t → (s ∩ t).Nonempty → sInf s ⊔ sInf t ≤ sInf (s ∩ t) := csSup_inter_le (α := αᵒᵈ) /-- The supremum of `insert a s` is the maximum of `a` and the supremum of `s`, if `s` is nonempty and bounded above. -/ @[simp] theorem csSup_insert (hs : BddAbove s) (sne : s.Nonempty) : sSup (insert a s) = a ⊔ sSup s := ((isLUB_csSup sne hs).insert a).csSup_eq (insert_nonempty a s) /-- The infimum of `insert a s` is the minimum of `a` and the infimum of `s`, if `s` is nonempty and bounded below. -/ @[simp] theorem csInf_insert (hs : BddBelow s) (sne : s.Nonempty) : sInf (insert a s) = a ⊓ sInf s := csSup_insert (α := αᵒᵈ) hs sne @[simp] theorem csInf_Icc (h : a ≤ b) : sInf (Icc a b) = a := (isGLB_Icc h).csInf_eq (nonempty_Icc.2 h) @[simp] theorem csInf_Ici : sInf (Ici a) = a := isLeast_Ici.csInf_eq @[simp] theorem csInf_Ico (h : a < b) : sInf (Ico a b) = a := (isGLB_Ico h).csInf_eq (nonempty_Ico.2 h) @[simp] theorem csInf_Ioc [DenselyOrdered α] (h : a < b) : sInf (Ioc a b) = a := (isGLB_Ioc h).csInf_eq (nonempty_Ioc.2 h) @[simp] theorem csInf_Ioi [NoMaxOrder α] [DenselyOrdered α] : sInf (Ioi a) = a := csInf_eq_of_forall_ge_of_forall_gt_exists_lt nonempty_Ioi (fun _ => le_of_lt) fun w hw => by simpa using exists_between hw @[simp] theorem csInf_Ioo [DenselyOrdered α] (h : a < b) : sInf (Ioo a b) = a := (isGLB_Ioo h).csInf_eq (nonempty_Ioo.2 h) @[simp] theorem csSup_Icc (h : a ≤ b) : sSup (Icc a b) = b := (isLUB_Icc h).csSup_eq (nonempty_Icc.2 h) @[simp] theorem csSup_Ico [DenselyOrdered α] (h : a < b) : sSup (Ico a b) = b := (isLUB_Ico h).csSup_eq (nonempty_Ico.2 h) @[simp] theorem csSup_Iic : sSup (Iic a) = a := isGreatest_Iic.csSup_eq @[simp] theorem csSup_Iio [NoMinOrder α] [DenselyOrdered α] : sSup (Iio a) = a := csSup_eq_of_forall_le_of_forall_lt_exists_gt nonempty_Iio (fun _ => le_of_lt) fun w hw => by simpa [and_comm] using exists_between hw @[simp] theorem csSup_Ioc (h : a < b) : sSup (Ioc a b) = b := (isLUB_Ioc h).csSup_eq (nonempty_Ioc.2 h) @[simp] theorem csSup_Ioo [DenselyOrdered α] (h : a < b) : sSup (Ioo a b) = b := (isLUB_Ioo h).csSup_eq (nonempty_Ioo.2 h) /-- Introduction rule to prove that `b` is the supremum of `s`: it suffices to check that 1) `b` is an upper bound 2) every other upper bound `b'` satisfies `b ≤ b'`. -/ theorem csSup_eq_of_is_forall_le_of_forall_le_imp_ge (hs : s.Nonempty) (h_is_ub : ∀ a ∈ s, a ≤ b) (h_b_le_ub : ∀ ub, (∀ a ∈ s, a ≤ ub) → b ≤ ub) : sSup s = b := (csSup_le hs h_is_ub).antisymm ((h_b_le_ub _) fun _ => le_csSup ⟨b, h_is_ub⟩) lemma sup_eq_top_of_top_mem [OrderTop α] (h : ⊤ ∈ s) : sSup s = ⊤ := top_unique <| le_csSup (OrderTop.bddAbove s) h lemma inf_eq_bot_of_bot_mem [OrderBot α] (h : ⊥ ∈ s) : sInf s = ⊥ := bot_unique <| csInf_le (OrderBot.bddBelow s) h end ConditionallyCompleteLattice instance Pi.conditionallyCompleteLattice {ι : Type*} {α : ι → Type*} [∀ i, ConditionallyCompleteLattice (α i)] : ConditionallyCompleteLattice (∀ i, α i) := { Pi.instLattice, Pi.supSet, Pi.infSet with le_csSup := fun _ f ⟨g, hg⟩ hf i => le_csSup ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩ csSup_le := fun s _ hs hf i => (csSup_le (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ => hb ▸ hf hg i csInf_le := fun _ f ⟨g, hg⟩ hf i => csInf_le ⟨g i, Set.forall_mem_range.2 fun ⟨_, hf'⟩ => hg hf' i⟩ ⟨⟨f, hf⟩, rfl⟩ le_csInf := fun s _ hs hf i => (le_csInf (by haveI := hs.to_subtype; apply range_nonempty)) fun _ ⟨⟨_, hg⟩, hb⟩ => hb ▸ hf hg i } section ConditionallyCompleteLinearOrder variable [ConditionallyCompleteLinearOrder α] {f : ι → α} {s : Set α} {a b : α} /-- When `b < sSup s`, there is an element `a` in `s` with `b < a`, if `s` is nonempty and the order is a linear order. -/ theorem exists_lt_of_lt_csSup (hs : s.Nonempty) (hb : b < sSup s) : ∃ a ∈ s, b < a := by contrapose! hb exact csSup_le hs hb /-- When `sInf s < b`, there is an element `a` in `s` with `a < b`, if `s` is nonempty and the order is a linear order. -/ theorem exists_lt_of_csInf_lt (hs : s.Nonempty) (hb : sInf s < b) : ∃ a ∈ s, a < b := exists_lt_of_lt_csSup (α := αᵒᵈ) hs hb theorem lt_csSup_iff (hb : BddAbove s) (hs : s.Nonempty) : a < sSup s ↔ ∃ b ∈ s, a < b := lt_isLUB_iff <| isLUB_csSup hs hb theorem csInf_lt_iff (hb : BddBelow s) (hs : s.Nonempty) : sInf s < a ↔ ∃ b ∈ s, b < a := isGLB_lt_iff <| isGLB_csInf hs hb @[simp] lemma csSup_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup ∅ := ConditionallyCompleteLinearOrder.csSup_of_not_bddAbove s hs @[simp] lemma ciSup_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup ∅ := csSup_of_not_bddAbove hf lemma csSup_eq_univ_of_not_bddAbove (hs : ¬BddAbove s) : sSup s = sSup univ := by rw [csSup_of_not_bddAbove hs, csSup_of_not_bddAbove (s := univ)] contrapose! hs exact hs.mono (subset_univ _) lemma ciSup_eq_univ_of_not_bddAbove (hf : ¬BddAbove (range f)) : ⨆ i, f i = sSup univ := csSup_eq_univ_of_not_bddAbove hf @[simp] lemma csInf_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf ∅ := ConditionallyCompleteLinearOrder.csInf_of_not_bddBelow s hs @[simp] lemma ciInf_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf ∅ := csInf_of_not_bddBelow hf lemma csInf_eq_univ_of_not_bddBelow (hs : ¬BddBelow s) : sInf s = sInf univ := csSup_eq_univ_of_not_bddAbove (α := αᵒᵈ) hs lemma ciInf_eq_univ_of_not_bddBelow (hf : ¬BddBelow (range f)) : ⨅ i, f i = sInf univ := csInf_eq_univ_of_not_bddBelow hf /-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then `s` and `t` have the same supremum. This holds even when the sets may be empty or unbounded. -/ theorem csSup_eq_csSup_of_forall_exists_le {s t : Set α} (hs : ∀ x ∈ s, ∃ y ∈ t, x ≤ y) (ht : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) : sSup s = sSup t := by rcases eq_empty_or_nonempty s with rfl|s_ne · have : t = ∅ := eq_empty_of_forall_not_mem (fun y yt ↦ by simpa using ht y yt) rw [this] rcases eq_empty_or_nonempty t with rfl|t_ne · have : s = ∅ := eq_empty_of_forall_not_mem (fun x xs ↦ by simpa using hs x xs) rw [this] by_cases B : BddAbove s ∨ BddAbove t · have Bs : BddAbove s := by rcases B with hB|⟨b, hb⟩ · exact hB · refine ⟨b, fun x hx ↦ ?_⟩ rcases hs x hx with ⟨y, hy, hxy⟩ exact hxy.trans (hb hy) have Bt : BddAbove t := by rcases B with ⟨b, hb⟩|hB · refine ⟨b, fun y hy ↦ ?_⟩ rcases ht y hy with ⟨x, hx, hyx⟩ exact hyx.trans (hb hx) · exact hB apply le_antisymm · apply csSup_le s_ne (fun x hx ↦ ?_) rcases hs x hx with ⟨y, yt, hxy⟩ exact hxy.trans (le_csSup Bt yt) · apply csSup_le t_ne (fun y hy ↦ ?_) rcases ht y hy with ⟨x, xs, hyx⟩ exact hyx.trans (le_csSup Bs xs) · simp [csSup_of_not_bddAbove, (not_or.1 B).1, (not_or.1 B).2] /-- When every element of a set `s` is bounded by an element of a set `t`, and conversely, then `s` and `t` have the same infimum. This holds even when the sets may be empty or unbounded. -/ theorem csInf_eq_csInf_of_forall_exists_le {s t : Set α} (hs : ∀ x ∈ s, ∃ y ∈ t, y ≤ x) (ht : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) : sInf s = sInf t := csSup_eq_csSup_of_forall_exists_le (α := αᵒᵈ) hs ht lemma sSup_iUnion_Iic (f : ι → α) : sSup (⋃ (i : ι), Iic (f i)) = ⨆ i, f i := by apply csSup_eq_csSup_of_forall_exists_le · rintro x ⟨-, ⟨i, rfl⟩, hi⟩ exact ⟨f i, mem_range_self _, hi⟩ · rintro x ⟨i, rfl⟩ exact ⟨f i, mem_iUnion_of_mem i le_rfl, le_rfl⟩ lemma sInf_iUnion_Ici (f : ι → α) : sInf (⋃ (i : ι), Ici (f i)) = ⨅ i, f i := sSup_iUnion_Iic (α := αᵒᵈ) f theorem csInf_eq_bot_of_bot_mem [OrderBot α] {s : Set α} (hs : ⊥ ∈ s) : sInf s = ⊥ := eq_bot_iff.2 <| csInf_le (OrderBot.bddBelow s) hs theorem csSup_eq_top_of_top_mem [OrderTop α] {s : Set α} (hs : ⊤ ∈ s) : sSup s = ⊤ := csInf_eq_bot_of_bot_mem (α := αᵒᵈ) hs open Function variable [WellFoundedLT α] theorem sInf_eq_argmin_on (hs : s.Nonempty) : sInf s = argminOn id s hs := IsLeast.csInf_eq ⟨argminOn_mem _ _ _, fun _ ha => argminOn_le id _ ha⟩ theorem isLeast_csInf (hs : s.Nonempty) : IsLeast s (sInf s) := by rw [sInf_eq_argmin_on hs] exact ⟨argminOn_mem _ _ _, fun a ha => argminOn_le id _ ha⟩ theorem le_csInf_iff' (hs : s.Nonempty) : b ≤ sInf s ↔ b ∈ lowerBounds s := le_isGLB_iff (isLeast_csInf hs).isGLB theorem csInf_mem (hs : s.Nonempty) : sInf s ∈ s := (isLeast_csInf hs).1 theorem MonotoneOn.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β} (hf : MonotoneOn f s) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) := (hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm theorem Monotone.map_csInf {β : Type*} [ConditionallyCompleteLattice β] {f : α → β} (hf : Monotone f) (hs : s.Nonempty) : f (sInf s) = sInf (f '' s) := (hf.map_isLeast (isLeast_csInf hs)).csInf_eq.symm end ConditionallyCompleteLinearOrder /-! ### Lemmas about a conditionally complete linear order with bottom element In this case we have `Sup ∅ = ⊥`, so we can drop some `Nonempty`/`Set.Nonempty` assumptions. -/ section ConditionallyCompleteLinearOrderBot @[simp] theorem csInf_univ [ConditionallyCompleteLattice α] [OrderBot α] : sInf (univ : Set α) = ⊥ := isLeast_univ.csInf_eq variable [ConditionallyCompleteLinearOrderBot α] {s : Set α} {a : α} @[simp] theorem csSup_empty : (sSup ∅ : α) = ⊥ := ConditionallyCompleteLinearOrderBot.csSup_empty theorem isLUB_csSup' {s : Set α} (hs : BddAbove s) : IsLUB s (sSup s) := by rcases eq_empty_or_nonempty s with (rfl | hne) · simp only [csSup_empty, isLUB_empty] · exact isLUB_csSup hne hs /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `csSup_le_iff`. -/ theorem csSup_le_iff' {s : Set α} (hs : BddAbove s) {a : α} : sSup s ≤ a ↔ ∀ x ∈ s, x ≤ a := isLUB_le_iff (isLUB_csSup' hs) theorem csSup_le' {s : Set α} {a : α} (h : a ∈ upperBounds s) : sSup s ≤ a := (csSup_le_iff' ⟨a, h⟩).2 h /-- In conditionally complete orders with a bottom element, the nonempty condition can be omitted from `lt_csSup_iff`. -/ theorem lt_csSup_iff' (hb : BddAbove s) : a < sSup s ↔ ∃ b ∈ s, a < b := by simpa only [not_le, not_forall₂, exists_prop] using (csSup_le_iff' hb).not theorem le_csSup_iff' {s : Set α} {a : α} (h : BddAbove s) : a ≤ sSup s ↔ ∀ b, b ∈ upperBounds s → a ≤ b := ⟨fun h _ hb => le_trans h (csSup_le' hb), fun hb => hb _ fun _ => le_csSup h⟩ theorem le_csInf_iff'' {s : Set α} {a : α} (ne : s.Nonempty) : a ≤ sInf s ↔ ∀ b : α, b ∈ s → a ≤ b := le_csInf_iff (OrderBot.bddBelow _) ne theorem csInf_le' (h : a ∈ s) : sInf s ≤ a := csInf_le (OrderBot.bddBelow _) h theorem exists_lt_of_lt_csSup' {s : Set α} {a : α} (h : a < sSup s) : ∃ b ∈ s, a < b := by contrapose! h exact csSup_le' h theorem not_mem_of_lt_csInf' {x : α} {s : Set α} (h : x < sInf s) : x ∉ s := not_mem_of_lt_csInf h (OrderBot.bddBelow s) theorem csInf_le_csInf' {s t : Set α} (h₁ : t.Nonempty) (h₂ : t ⊆ s) : sInf s ≤ sInf t := csInf_le_csInf (OrderBot.bddBelow s) h₁ h₂ theorem csSup_le_csSup' {s t : Set α} (h₁ : BddAbove t) (h₂ : s ⊆ t) : sSup s ≤ sSup t := by rcases eq_empty_or_nonempty s with rfl | h · rw [csSup_empty] exact bot_le · exact csSup_le_csSup h₁ h h₂ end ConditionallyCompleteLinearOrderBot namespace WithTop variable [ConditionallyCompleteLinearOrderBot α] /-- The `sSup` of a non-empty set is its least upper bound for a conditionally complete lattice with a top. -/ theorem isLUB_sSup' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)} (hs : s.Nonempty) : IsLUB s (sSup s) := by classical constructor · show ite _ _ _ ∈ _ split_ifs with h₁ h₂ · intro _ _ exact le_top · rintro (⟨⟩ | a) ha · contradiction apply coe_le_coe.2 exact le_csSup h₂ ha · intro _ _ exact le_top · show ite _ _ _ ∈ _ split_ifs with h₁ h₂ · rintro (⟨⟩ | a) ha · exact le_rfl · exact False.elim (not_top_le_coe a (ha h₁)) · rintro (⟨⟩ | b) hb · exact le_top refine coe_le_coe.2 (csSup_le ?_ ?_) · rcases hs with ⟨⟨⟩ | b, hb⟩ · exact absurd hb h₁ · exact ⟨b, hb⟩ · intro a ha exact coe_le_coe.1 (hb ha) · rintro (⟨⟩ | b) hb · exact le_rfl · exfalso apply h₂ use b intro a ha exact coe_le_coe.1 (hb ha) theorem isLUB_sSup (s : Set (WithTop α)) : IsLUB s (sSup s) := by rcases s.eq_empty_or_nonempty with rfl | hs · simp [sSup] · exact isLUB_sSup' hs /-- The `sInf` of a bounded-below set is its greatest lower bound for a conditionally complete lattice with a top. -/ theorem isGLB_sInf' {β : Type*} [ConditionallyCompleteLattice β] {s : Set (WithTop β)} (hs : BddBelow s) : IsGLB s (sInf s) := by classical constructor · show ite _ _ _ ∈ _ simp only [hs, not_true_eq_false, or_false] split_ifs with h · intro a ha exact top_le_iff.2 (Set.mem_singleton_iff.1 (h ha)) · rintro (⟨⟩ | a) ha · exact le_top refine coe_le_coe.2 (csInf_le ?_ ha) rcases hs with ⟨⟨⟩ | b, hb⟩ · exfalso apply h intro c hc rw [mem_singleton_iff, ← top_le_iff] exact hb hc use b intro c hc exact coe_le_coe.1 (hb hc) · show ite _ _ _ ∈ _ simp only [hs, not_true_eq_false, or_false] split_ifs with h · intro _ _ exact le_top · rintro (⟨⟩ | a) ha · exfalso apply h intro b hb exact Set.mem_singleton_iff.2 (top_le_iff.1 (ha hb)) · refine coe_le_coe.2 (le_csInf ?_ ?_) · classical contrapose! h rintro (⟨⟩ | a) ha · exact mem_singleton ⊤ · exact (not_nonempty_iff_eq_empty.2 h ⟨a, ha⟩).elim · intro b hb rw [← coe_le_coe] exact ha hb theorem isGLB_sInf (s : Set (WithTop α)) : IsGLB s (sInf s) := by by_cases hs : BddBelow s · exact isGLB_sInf' hs · exfalso apply hs use ⊥ intro _ _ exact bot_le noncomputable instance : CompleteLinearOrder (WithTop α) where __ := linearOrder __ := LinearOrder.toBiheytingAlgebra le_sSup s := (isLUB_sSup s).1 sSup_le s := (isLUB_sSup s).2 le_sInf s := (isGLB_sInf s).2 sInf_le s := (isGLB_sInf s).1 /-- A version of `WithTop.coe_sSup'` with a more convenient but less general statement. -/ @[norm_cast] theorem coe_sSup {s : Set α} (hb : BddAbove s) : ↑(sSup s) = (⨆ a ∈ s, ↑a : WithTop α) := by rw [coe_sSup' hb, sSup_image] /-- A version of `WithTop.coe_sInf'` with a more convenient but less general statement. -/ @[norm_cast] theorem coe_sInf {s : Set α} (hs : s.Nonempty) (h's : BddBelow s) : ↑(sInf s) = (⨅ a ∈ s, ↑a : WithTop α) := by rw [coe_sInf' hs h's, sInf_image] end WithTop namespace Monotone variable [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} (h_mono : Monotone f) include h_mono /-! A monotone function into a conditionally complete lattice preserves the ordering properties of `sSup` and `sInf`. -/ theorem le_csSup_image {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddAbove s) : f c ≤ sSup (f '' s) := le_csSup (map_bddAbove h_mono h_bdd) (mem_image_of_mem f hcs) theorem csSup_image_le {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ upperBounds s) : sSup (f '' s) ≤ f B := csSup_le (Nonempty.image f hs) (h_mono.mem_upperBounds_image hB) -- Porting note: in mathlib3 `f'` is not needed theorem csInf_image_le {s : Set α} {c : α} (hcs : c ∈ s) (h_bdd : BddBelow s) : sInf (f '' s) ≤ f c := by let f' : αᵒᵈ → βᵒᵈ := f exact le_csSup_image (α := αᵒᵈ) (β := βᵒᵈ) (show Monotone f' from fun x y hxy => h_mono hxy) hcs h_bdd -- Porting note: in mathlib3 `f'` is not needed theorem le_csInf_image {s : Set α} (hs : s.Nonempty) {B : α} (hB : B ∈ lowerBounds s) : f B ≤ sInf (f '' s) := by let f' : αᵒᵈ → βᵒᵈ := f exact csSup_image_le (α := αᵒᵈ) (β := βᵒᵈ) (show Monotone f' from fun x y hxy => h_mono hxy) hs hB end Monotone lemma MonotoneOn.csInf_eq_of_subset_of_forall_exists_le [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {s t : Set α} (ht : BddBelow (f '' t)) (hf : MonotoneOn f t) (hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, x ≤ y) : sInf (f '' s) = sInf (f '' t) := by obtain rfl | hs := Set.eq_empty_or_nonempty s · obtain rfl : t = ∅ := by simpa [Set.eq_empty_iff_forall_not_mem] using h rfl apply le_antisymm _ (csInf_le_csInf ht (hs.image _) (image_subset _ hst)) refine le_csInf ((hs.mono hst).image f) ?_ simp only [mem_image, forall_exists_index, and_imp, forall_apply_eq_imp_iff₂] intro a ha obtain ⟨x, hxs, hxa⟩ := h a ha exact csInf_le_of_le (ht.mono (image_subset _ hst)) ⟨x, hxs, rfl⟩ (hf (hst hxs) ha hxa) lemma MonotoneOn.csSup_eq_of_subset_of_forall_exists_le [Preorder α] [ConditionallyCompleteLattice β] {f : α → β} {s t : Set α} (ht : BddAbove (f '' t)) (hf : MonotoneOn f t) (hst : s ⊆ t) (h : ∀ y ∈ t, ∃ x ∈ s, y ≤ x) : sSup (f '' s) = sSup (f '' t) := MonotoneOn.csInf_eq_of_subset_of_forall_exists_le (α := αᵒᵈ) (β := βᵒᵈ) ht hf.dual hst h /-! ### Supremum/infimum of `Set.image2` A collection of lemmas showing what happens to the suprema/infima of `s` and `t` when mapped under a binary function whose partial evaluations are lower/upper adjoints of Galois connections. -/ section variable [ConditionallyCompleteLattice α] [ConditionallyCompleteLattice β] [ConditionallyCompleteLattice γ] {s : Set α} {t : Set β} variable {l u : α → β → γ} {l₁ u₁ : β → γ → α} {l₂ u₂ : α → γ → β} theorem csSup_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) (hs₀ : s.Nonempty) (hs₁ : BddAbove s) (ht₀ : t.Nonempty) (ht₁ : BddAbove t) : sSup (image2 l s t) = l (sSup s) (sSup t) := by refine eq_of_forall_ge_iff fun c => ?_ rw [csSup_le_iff (hs₁.image2 (fun _ => (h₁ _).monotone_l) (fun _ => (h₂ _).monotone_l) ht₁) (hs₀.image2 ht₀), forall_mem_image2, forall₂_swap, (h₂ _).le_iff_le, csSup_le_iff ht₁ ht₀] simp_rw [← (h₂ _).le_iff_le, (h₁ _).le_iff_le, csSup_le_iff hs₁ hs₀] theorem csSup_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (swap l b) (u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sSup s) (sInf t) := csSup_image2_eq_csSup_csSup (β := βᵒᵈ) h₁ h₂ theorem csSup_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a) (u₂ a)) : s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sSup (image2 l s t) = l (sInf s) (sSup t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) h₁ h₂ theorem csSup_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (swap l b ∘ ofDual) (toDual ∘ u₁ b)) (h₂ : ∀ a, GaloisConnection (l a ∘ ofDual) (toDual ∘ u₂ a)) : s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sSup (image2 l s t) = l (sInf s) (sInf t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csInf_csInf (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : s.Nonempty → BddBelow s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sInf s) (sInf t) := csSup_image2_eq_csSup_csSup (α := αᵒᵈ) (β := βᵒᵈ) (γ := γᵒᵈ) (u₁ := l₁) (u₂ := l₂) (fun _ => (h₁ _).dual) fun _ => (h₂ _).dual theorem csInf_image2_eq_csInf_csSup (h₁ : ∀ b, GaloisConnection (l₁ b) (swap u b)) (h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) : s.Nonempty → BddBelow s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sInf s) (sSup t) := csInf_image2_eq_csInf_csInf (β := βᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csSup_csInf (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual)) (h₂ : ∀ a, GaloisConnection (l₂ a) (u a)) : s.Nonempty → BddAbove s → t.Nonempty → BddBelow t → sInf (image2 u s t) = u (sSup s) (sInf t) := csInf_image2_eq_csInf_csInf (α := αᵒᵈ) h₁ h₂ theorem csInf_image2_eq_csSup_csSup (h₁ : ∀ b, GaloisConnection (toDual ∘ l₁ b) (swap u b ∘ ofDual)) (h₂ : ∀ a, GaloisConnection (toDual ∘ l₂ a) (u a ∘ ofDual)) : s.Nonempty → BddAbove s → t.Nonempty → BddAbove t → sInf (image2 u s t) = u (sSup s) (sSup t) := csInf_image2_eq_csInf_csInf (α := αᵒᵈ) (β := βᵒᵈ) h₁ h₂ end section WithTopBot /-! ### Complete lattice structure on `WithTop (WithBot α)` If `α` is a `ConditionallyCompleteLattice`, then we show that `WithTop α` and `WithBot α` also inherit the structure of conditionally complete lattices. Furthermore, we show that `WithTop (WithBot α)` and `WithBot (WithTop α)` naturally inherit the structure of a complete lattice. Note that for `α` a conditionally complete lattice, `sSup` and `sInf` both return junk values for sets which are empty or unbounded. The extension of `sSup` to `WithTop α` fixes the unboundedness problem and the extension to `WithBot α` fixes the problem with the empty set. This result can be used to show that the extended reals `[-∞, ∞]` are a complete linear order. -/ /-- Adding a top element to a conditionally complete lattice gives a conditionally complete lattice -/ noncomputable instance WithTop.conditionallyCompleteLattice {α : Type*} [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithTop α) := { lattice, instSupSet, instInfSet with le_csSup := fun _ a _ haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS csSup_le := fun _ _ hS haS => (WithTop.isLUB_sSup' hS).2 haS csInf_le := fun _ _ hS haS => (WithTop.isGLB_sInf' hS).1 haS le_csInf := fun _ a _ haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS } /-- Adding a bottom element to a conditionally complete lattice gives a conditionally complete lattice -/ noncomputable instance WithBot.conditionallyCompleteLattice {α : Type*} [ConditionallyCompleteLattice α] : ConditionallyCompleteLattice (WithBot α) := { WithBot.lattice with le_csSup := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csInf_le csSup_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csInf csInf_le := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).le_csSup le_csInf := (WithTop.conditionallyCompleteLattice (α := αᵒᵈ)).csSup_le } open Classical in noncomputable instance WithTop.WithBot.completeLattice {α : Type*} [ConditionallyCompleteLattice α] : CompleteLattice (WithTop (WithBot α)) := { instInfSet, instSupSet, boundedOrder, lattice with le_sSup := fun _ a haS => (WithTop.isLUB_sSup' ⟨a, haS⟩).1 haS sSup_le := fun S a ha => by rcases S.eq_empty_or_nonempty with h | h · show ite _ _ _ ≤ a simp [h] · exact (WithTop.isLUB_sSup' h).2 ha sInf_le := fun S a haS => show ite _ _ _ ≤ a by simp only [OrderBot.bddBelow, not_true_eq_false, or_false] split_ifs with h₁ · cases a · exact le_rfl cases h₁ haS · cases a · exact le_top · apply WithTop.coe_le_coe.2 refine csInf_le ?_ haS use ⊥ intro b _ exact bot_le le_sInf := fun _ a haS => (WithTop.isGLB_sInf' ⟨a, haS⟩).2 haS } noncomputable instance WithTop.WithBot.completeLinearOrder {α : Type*} [ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithTop (WithBot α)) := -- FIXME: Spread notation doesn't work { completeLattice, linearOrder, LinearOrder.toBiheytingAlgebra with } noncomputable instance WithBot.WithTop.completeLattice {α : Type*} [ConditionallyCompleteLattice α] : CompleteLattice (WithBot (WithTop α)) := { instInfSet, instSupSet, instBoundedOrder, lattice with le_sSup := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sInf_le sSup_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sInf sInf_le := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).le_sSup le_sInf := (WithTop.WithBot.completeLattice (α := αᵒᵈ)).sSup_le } noncomputable instance WithBot.WithTop.completeLinearOrder {α : Type*} [ConditionallyCompleteLinearOrder α] : CompleteLinearOrder (WithBot (WithTop α)) := { completeLattice, linearOrder, LinearOrder.toBiheytingAlgebra with } end WithTopBot
Mathlib/Order/ConditionallyCompleteLattice/Basic.lean
1,085
1,090
/- 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, Johan Commelin, Mario Carneiro -/ import Mathlib.Algebra.MonoidAlgebra.Degree import Mathlib.Algebra.MvPolynomial.Rename /-! # Degrees of polynomials This file establishes many results about the degree of a multivariate polynomial. The *degree set* of a polynomial $P \in R[X]$ is a `Multiset` containing, for each $x$ in the variable set, $n$ copies of $x$, where $n$ is the maximum number of copies of $x$ appearing in a monomial of $P$. ## Main declarations * `MvPolynomial.degrees p` : the multiset of variables representing the union of the multisets corresponding to each non-zero monomial in `p`. For example if `7 ≠ 0` in `R` and `p = x²y+7y³` then `degrees p = {x, x, y, y, y}` * `MvPolynomial.degreeOf n p : ℕ` : the total degree of `p` with respect to the variable `n`. For example if `p = x⁴y+yz` then `degreeOf y p = 1`. * `MvPolynomial.totalDegree p : ℕ` : the max of the sizes of the multisets `s` whose monomials `X^s` occur in `p`. For example if `p = x⁴y+yz` then `totalDegree p = 5`. ## Notation As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R : Type*` `[CommSemiring R]` (the coefficients) + `s : σ →₀ ℕ`, a function from `σ` to `ℕ` which is zero away from a finite set. This will give rise to a monomial in `MvPolynomial σ R` which mathematicians might call `X^s` + `r : R` + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `p : MvPolynomial σ R` -/ noncomputable section open Set Function Finsupp AddMonoidAlgebra universe u v w variable {R : Type u} {S : Type v} namespace MvPolynomial variable {σ τ : Type*} {r : R} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} section CommSemiring variable [CommSemiring R] {p q : MvPolynomial σ R} section Degrees /-! ### `degrees` -/ /-- The maximal degrees of each variable in a multi-variable polynomial, expressed as a multiset. (For example, `degrees (x^2 * y + y^3)` would be `{x, x, y, y, y}`.) -/ def degrees (p : MvPolynomial σ R) : Multiset σ := letI := Classical.decEq σ p.support.sup fun s : σ →₀ ℕ => toMultiset s theorem degrees_def [DecidableEq σ] (p : MvPolynomial σ R) : p.degrees = p.support.sup fun s : σ →₀ ℕ => Finsupp.toMultiset s := by rw [degrees]; convert rfl theorem degrees_monomial (s : σ →₀ ℕ) (a : R) : degrees (monomial s a) ≤ toMultiset s := by classical refine (supDegree_single s a).trans_le ?_ split_ifs exacts [bot_le, le_rfl] theorem degrees_monomial_eq (s : σ →₀ ℕ) (a : R) (ha : a ≠ 0) : degrees (monomial s a) = toMultiset s := by classical exact (supDegree_single s a).trans (if_neg ha) theorem degrees_C (a : R) : degrees (C a : MvPolynomial σ R) = 0 := Multiset.le_zero.1 <| degrees_monomial _ _ theorem degrees_X' (n : σ) : degrees (X n : MvPolynomial σ R) ≤ {n} := le_trans (degrees_monomial _ _) <| le_of_eq <| toMultiset_single _ _ @[simp] theorem degrees_X [Nontrivial R] (n : σ) : degrees (X n : MvPolynomial σ R) = {n} := (degrees_monomial_eq _ (1 : R) one_ne_zero).trans (toMultiset_single _ _) @[simp] theorem degrees_zero : degrees (0 : MvPolynomial σ R) = 0 := by rw [← C_0] exact degrees_C 0 @[simp] theorem degrees_one : degrees (1 : MvPolynomial σ R) = 0 := degrees_C 1 theorem degrees_add_le [DecidableEq σ] {p q : MvPolynomial σ R} : (p + q).degrees ≤ p.degrees ⊔ q.degrees := by simp_rw [degrees_def]; exact supDegree_add_le theorem degrees_sum_le {ι : Type*} [DecidableEq σ] (s : Finset ι) (f : ι → MvPolynomial σ R) : (∑ i ∈ s, f i).degrees ≤ s.sup fun i => (f i).degrees := by simp_rw [degrees_def]; exact supDegree_sum_le theorem degrees_mul_le {p q : MvPolynomial σ R} : (p * q).degrees ≤ p.degrees + q.degrees := by classical simp_rw [degrees_def] exact supDegree_mul_le (map_add _) theorem degrees_prod_le {ι : Type*} {s : Finset ι} {f : ι → MvPolynomial σ R} : (∏ i ∈ s, f i).degrees ≤ ∑ i ∈ s, (f i).degrees := by classical exact supDegree_prod_le (map_zero _) (map_add _) theorem degrees_pow_le {p : MvPolynomial σ R} {n : ℕ} : (p ^ n).degrees ≤ n • p.degrees := by simpa using degrees_prod_le (s := .range n) (f := fun _ ↦ p) @[deprecated (since := "2024-12-28")] alias degrees_add := degrees_add_le @[deprecated (since := "2024-12-28")] alias degrees_sum := degrees_sum_le @[deprecated (since := "2024-12-28")] alias degrees_mul := degrees_mul_le @[deprecated (since := "2024-12-28")] alias degrees_prod := degrees_prod_le @[deprecated (since := "2024-12-28")] alias degrees_pow := degrees_pow_le theorem mem_degrees {p : MvPolynomial σ R} {i : σ} : i ∈ p.degrees ↔ ∃ d, p.coeff d ≠ 0 ∧ i ∈ d.support := by classical simp only [degrees_def, Multiset.mem_sup, ← mem_support_iff, Finsupp.mem_toMultiset, exists_prop] theorem le_degrees_add_left (h : Disjoint p.degrees q.degrees) : p.degrees ≤ (p + q).degrees := by classical apply Finset.sup_le intro d hd rw [Multiset.disjoint_iff_ne] at h
obtain rfl | h0 := eq_or_ne d 0 · rw [toMultiset_zero]; apply Multiset.zero_le
Mathlib/Algebra/MvPolynomial/Degrees.lean
149
150
/- Copyright (c) 2014 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Leonardo de Moura -/ import Mathlib.Data.Set.Operations import Mathlib.Order.Basic import Mathlib.Order.BooleanAlgebra import Mathlib.Tactic.Tauto import Mathlib.Tactic.ByContra import Mathlib.Util.Delaborators import Mathlib.Tactic.Lift /-! # Basic properties of sets Sets in Lean are homogeneous; all their elements have the same type. Sets whose elements have type `X` are thus defined as `Set X := X → Prop`. Note that this function need not be decidable. The definition is in the module `Mathlib.Data.Set.Defs`. This file provides some basic definitions related to sets and functions not present in the definitions file, as well as extra lemmas for functions defined in the definitions file and `Mathlib.Data.Set.Operations` (empty set, univ, union, intersection, insert, singleton, set-theoretic difference, complement, and powerset). Note that a set is a term, not a type. There is a coercion from `Set α` to `Type*` sending `s` to the corresponding subtype `↥s`. See also the file `SetTheory/ZFC.lean`, which contains an encoding of ZFC set theory in Lean. ## Main definitions Notation used here: - `f : α → β` is a function, - `s : Set α` and `s₁ s₂ : Set α` are subsets of `α` - `t : Set β` is a subset of `β`. Definitions in the file: * `Nonempty s : Prop` : the predicate `s ≠ ∅`. Note that this is the preferred way to express the fact that `s` has an element (see the Implementation Notes). * `inclusion s₁ s₂ : ↥s₁ → ↥s₂` : the map `↥s₁ → ↥s₂` induced by an inclusion `s₁ ⊆ s₂`. ## Notation * `sᶜ` for the complement of `s` ## Implementation notes * `s.Nonempty` is to be preferred to `s ≠ ∅` or `∃ x, x ∈ s`. It has the advantage that the `s.Nonempty` dot notation can be used. * For `s : Set α`, do not use `Subtype s`. Instead use `↥s` or `(s : Type*)` or `s`. ## Tags set, sets, subset, subsets, union, intersection, insert, singleton, complement, powerset -/ assert_not_exists RelIso /-! ### Set coercion to a type -/ open Function universe u v namespace Set variable {α : Type u} {s t : Set α} instance instBooleanAlgebra : BooleanAlgebra (Set α) := { (inferInstance : BooleanAlgebra (α → Prop)) with sup := (· ∪ ·), le := (· ≤ ·), lt := fun s t => s ⊆ t ∧ ¬t ⊆ s, inf := (· ∩ ·), bot := ∅, compl := (·ᶜ), top := univ, sdiff := (· \ ·) } instance : HasSSubset (Set α) := ⟨(· < ·)⟩ @[simp] theorem top_eq_univ : (⊤ : Set α) = univ := rfl @[simp] theorem bot_eq_empty : (⊥ : Set α) = ∅ := rfl @[simp] theorem sup_eq_union : ((· ⊔ ·) : Set α → Set α → Set α) = (· ∪ ·) := rfl @[simp] theorem inf_eq_inter : ((· ⊓ ·) : Set α → Set α → Set α) = (· ∩ ·) := rfl @[simp] theorem le_eq_subset : ((· ≤ ·) : Set α → Set α → Prop) = (· ⊆ ·) := rfl @[simp] theorem lt_eq_ssubset : ((· < ·) : Set α → Set α → Prop) = (· ⊂ ·) := rfl theorem le_iff_subset : s ≤ t ↔ s ⊆ t := Iff.rfl theorem lt_iff_ssubset : s < t ↔ s ⊂ t := Iff.rfl alias ⟨_root_.LE.le.subset, _root_.HasSubset.Subset.le⟩ := le_iff_subset alias ⟨_root_.LT.lt.ssubset, _root_.HasSSubset.SSubset.lt⟩ := lt_iff_ssubset instance PiSetCoe.canLift (ι : Type u) (α : ι → Type v) [∀ i, Nonempty (α i)] (s : Set ι) : CanLift (∀ i : s, α i) (∀ i, α i) (fun f i => f i) fun _ => True := PiSubtype.canLift ι α s instance PiSetCoe.canLift' (ι : Type u) (α : Type v) [Nonempty α] (s : Set ι) : CanLift (s → α) (ι → α) (fun f i => f i) fun _ => True := PiSetCoe.canLift ι (fun _ => α) s end Set section SetCoe variable {α : Type u} instance (s : Set α) : CoeTC s α := ⟨fun x => x.1⟩ theorem Set.coe_eq_subtype (s : Set α) : ↥s = { x // x ∈ s } := rfl @[simp] theorem Set.coe_setOf (p : α → Prop) : ↥{ x | p x } = { x // p x } := rfl theorem SetCoe.forall {s : Set α} {p : s → Prop} : (∀ x : s, p x) ↔ ∀ (x) (h : x ∈ s), p ⟨x, h⟩ := Subtype.forall theorem SetCoe.exists {s : Set α} {p : s → Prop} : (∃ x : s, p x) ↔ ∃ (x : _) (h : x ∈ s), p ⟨x, h⟩ := Subtype.exists theorem SetCoe.exists' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∃ (x : _) (h : x ∈ s), p x h) ↔ ∃ x : s, p x.1 x.2 := (@SetCoe.exists _ _ fun x => p x.1 x.2).symm theorem SetCoe.forall' {s : Set α} {p : ∀ x, x ∈ s → Prop} : (∀ (x) (h : x ∈ s), p x h) ↔ ∀ x : s, p x.1 x.2 := (@SetCoe.forall _ _ fun x => p x.1 x.2).symm @[simp] theorem set_coe_cast : ∀ {s t : Set α} (H' : s = t) (H : ↥s = ↥t) (x : s), cast H x = ⟨x.1, H' ▸ x.2⟩ | _, _, rfl, _, _ => rfl theorem SetCoe.ext {s : Set α} {a b : s} : (a : α) = b → a = b := Subtype.eq theorem SetCoe.ext_iff {s : Set α} {a b : s} : (↑a : α) = ↑b ↔ a = b := Iff.intro SetCoe.ext fun h => h ▸ rfl end SetCoe /-- See also `Subtype.prop` -/ theorem Subtype.mem {α : Type*} {s : Set α} (p : s) : (p : α) ∈ s := p.prop /-- Duplicate of `Eq.subset'`, which currently has elaboration problems. -/ theorem Eq.subset {α} {s t : Set α} : s = t → s ⊆ t := fun h₁ _ h₂ => by rw [← h₁]; exact h₂ namespace Set variable {α : Type u} {β : Type v} {a b : α} {s s₁ s₂ t t₁ t₂ u : Set α} instance : Inhabited (Set α) := ⟨∅⟩ @[trans] theorem mem_of_mem_of_subset {x : α} {s t : Set α} (hx : x ∈ s) (h : s ⊆ t) : x ∈ t := h hx theorem forall_in_swap {p : α → β → Prop} : (∀ a ∈ s, ∀ (b), p a b) ↔ ∀ (b), ∀ a ∈ s, p a b := by tauto theorem setOf_injective : Function.Injective (@setOf α) := injective_id theorem setOf_inj {p q : α → Prop} : { x | p x } = { x | q x } ↔ p = q := Iff.rfl /-! ### Lemmas about `mem` and `setOf` -/ theorem mem_setOf {a : α} {p : α → Prop} : a ∈ { x | p x } ↔ p a := Iff.rfl /-- This lemma is intended for use with `rw` where a membership predicate is needed, hence the explicit argument and the equality in the reverse direction from normal. See also `Set.mem_setOf_eq` for the reverse direction applied to an argument. -/ theorem eq_mem_setOf (p : α → Prop) : p = (· ∈ {a | p a}) := rfl /-- If `h : a ∈ {x | p x}` then `h.out : p x`. These are definitionally equal, but this can nevertheless be useful for various reasons, e.g. to apply further projection notation or in an argument to `simp`. -/ theorem _root_.Membership.mem.out {p : α → Prop} {a : α} (h : a ∈ { x | p x }) : p a := h theorem nmem_setOf_iff {a : α} {p : α → Prop} : a ∉ { x | p x } ↔ ¬p a := Iff.rfl @[simp] theorem setOf_mem_eq {s : Set α} : { x | x ∈ s } = s := rfl theorem setOf_set {s : Set α} : setOf s = s := rfl theorem setOf_app_iff {p : α → Prop} {x : α} : { x | p x } x ↔ p x := Iff.rfl theorem mem_def {a : α} {s : Set α} : a ∈ s ↔ s a := Iff.rfl theorem setOf_bijective : Bijective (setOf : (α → Prop) → Set α) := bijective_id theorem subset_setOf {p : α → Prop} {s : Set α} : s ⊆ setOf p ↔ ∀ x, x ∈ s → p x := Iff.rfl theorem setOf_subset {p : α → Prop} {s : Set α} : setOf p ⊆ s ↔ ∀ x, p x → x ∈ s := Iff.rfl @[simp] theorem setOf_subset_setOf {p q : α → Prop} : { a | p a } ⊆ { a | q a } ↔ ∀ a, p a → q a := Iff.rfl theorem setOf_and {p q : α → Prop} : { a | p a ∧ q a } = { a | p a } ∩ { a | q a } := rfl theorem setOf_or {p q : α → Prop} : { a | p a ∨ q a } = { a | p a } ∪ { a | q a } := rfl /-! ### Subset and strict subset relations -/ instance : IsRefl (Set α) (· ⊆ ·) := show IsRefl (Set α) (· ≤ ·) by infer_instance instance : IsTrans (Set α) (· ⊆ ·) := show IsTrans (Set α) (· ≤ ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊆ ·) := show Trans (· ≤ ·) (· ≤ ·) (· ≤ ·) by infer_instance instance : IsAntisymm (Set α) (· ⊆ ·) := show IsAntisymm (Set α) (· ≤ ·) by infer_instance instance : IsIrrefl (Set α) (· ⊂ ·) := show IsIrrefl (Set α) (· < ·) by infer_instance instance : IsTrans (Set α) (· ⊂ ·) := show IsTrans (Set α) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· < ·) (· < ·) (· < ·) by infer_instance instance : Trans ((· ⊂ ·) : Set α → Set α → Prop) (· ⊆ ·) (· ⊂ ·) := show Trans (· < ·) (· ≤ ·) (· < ·) by infer_instance instance : Trans ((· ⊆ ·) : Set α → Set α → Prop) (· ⊂ ·) (· ⊂ ·) := show Trans (· ≤ ·) (· < ·) (· < ·) by infer_instance instance : IsAsymm (Set α) (· ⊂ ·) := show IsAsymm (Set α) (· < ·) by infer_instance instance : IsNonstrictStrictOrder (Set α) (· ⊆ ·) (· ⊂ ·) := ⟨fun _ _ => Iff.rfl⟩ -- TODO(Jeremy): write a tactic to unfold specific instances of generic notation? theorem subset_def : (s ⊆ t) = ∀ x, x ∈ s → x ∈ t := rfl theorem ssubset_def : (s ⊂ t) = (s ⊆ t ∧ ¬t ⊆ s) := rfl @[refl] theorem Subset.refl (a : Set α) : a ⊆ a := fun _ => id theorem Subset.rfl {s : Set α} : s ⊆ s := Subset.refl s @[trans] theorem Subset.trans {a b c : Set α} (ab : a ⊆ b) (bc : b ⊆ c) : a ⊆ c := fun _ h => bc <| ab h @[trans] theorem mem_of_eq_of_mem {x y : α} {s : Set α} (hx : x = y) (h : y ∈ s) : x ∈ s := hx.symm ▸ h theorem Subset.antisymm {a b : Set α} (h₁ : a ⊆ b) (h₂ : b ⊆ a) : a = b := Set.ext fun _ => ⟨@h₁ _, @h₂ _⟩ theorem Subset.antisymm_iff {a b : Set α} : a = b ↔ a ⊆ b ∧ b ⊆ a := ⟨fun e => ⟨e.subset, e.symm.subset⟩, fun ⟨h₁, h₂⟩ => Subset.antisymm h₁ h₂⟩ -- an alternative name theorem eq_of_subset_of_subset {a b : Set α} : a ⊆ b → b ⊆ a → a = b := Subset.antisymm theorem mem_of_subset_of_mem {s₁ s₂ : Set α} {a : α} (h : s₁ ⊆ s₂) : a ∈ s₁ → a ∈ s₂ := @h _ theorem not_mem_subset (h : s ⊆ t) : a ∉ t → a ∉ s := mt <| mem_of_subset_of_mem h theorem not_subset : ¬s ⊆ t ↔ ∃ a ∈ s, a ∉ t := by simp only [subset_def, not_forall, exists_prop] theorem not_top_subset : ¬⊤ ⊆ s ↔ ∃ a, a ∉ s := by simp [not_subset] lemma eq_of_forall_subset_iff (h : ∀ u, s ⊆ u ↔ t ⊆ u) : s = t := eq_of_forall_ge_iff h /-! ### Definition of strict subsets `s ⊂ t` and basic properties. -/ protected theorem eq_or_ssubset_of_subset (h : s ⊆ t) : s = t ∨ s ⊂ t := eq_or_lt_of_le h theorem exists_of_ssubset {s t : Set α} (h : s ⊂ t) : ∃ x ∈ t, x ∉ s := not_subset.1 h.2 protected theorem ssubset_iff_subset_ne {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ s ≠ t := @lt_iff_le_and_ne (Set α) _ s t theorem ssubset_iff_of_subset {s t : Set α} (h : s ⊆ t) : s ⊂ t ↔ ∃ x ∈ t, x ∉ s := ⟨exists_of_ssubset, fun ⟨_, hxt, hxs⟩ => ⟨h, fun h => hxs <| h hxt⟩⟩ theorem ssubset_iff_exists {s t : Set α} : s ⊂ t ↔ s ⊆ t ∧ ∃ x ∈ t, x ∉ s := ⟨fun h ↦ ⟨h.le, Set.exists_of_ssubset h⟩, fun ⟨h1, h2⟩ ↦ (Set.ssubset_iff_of_subset h1).mpr h2⟩ protected theorem ssubset_of_ssubset_of_subset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊂ s₂) (hs₂s₃ : s₂ ⊆ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂.1 hs₂s₃, fun hs₃s₁ => hs₁s₂.2 (Subset.trans hs₂s₃ hs₃s₁)⟩ protected theorem ssubset_of_subset_of_ssubset {s₁ s₂ s₃ : Set α} (hs₁s₂ : s₁ ⊆ s₂) (hs₂s₃ : s₂ ⊂ s₃) : s₁ ⊂ s₃ := ⟨Subset.trans hs₁s₂ hs₂s₃.1, fun hs₃s₁ => hs₂s₃.2 (Subset.trans hs₃s₁ hs₁s₂)⟩ theorem not_mem_empty (x : α) : ¬x ∈ (∅ : Set α) := id theorem not_not_mem : ¬a ∉ s ↔ a ∈ s := not_not /-! ### Non-empty sets -/ theorem nonempty_coe_sort {s : Set α} : Nonempty ↥s ↔ s.Nonempty := nonempty_subtype alias ⟨_, Nonempty.coe_sort⟩ := nonempty_coe_sort theorem nonempty_def : s.Nonempty ↔ ∃ x, x ∈ s := Iff.rfl theorem nonempty_of_mem {x} (h : x ∈ s) : s.Nonempty := ⟨x, h⟩ theorem Nonempty.not_subset_empty : s.Nonempty → ¬s ⊆ ∅ | ⟨_, hx⟩, hs => hs hx /-- Extract a witness from `s.Nonempty`. This function might be used instead of case analysis on the argument. Note that it makes a proof depend on the `Classical.choice` axiom. -/ protected noncomputable def Nonempty.some (h : s.Nonempty) : α := Classical.choose h protected theorem Nonempty.some_mem (h : s.Nonempty) : h.some ∈ s := Classical.choose_spec h theorem Nonempty.mono (ht : s ⊆ t) (hs : s.Nonempty) : t.Nonempty := hs.imp ht theorem nonempty_of_not_subset (h : ¬s ⊆ t) : (s \ t).Nonempty := let ⟨x, xs, xt⟩ := not_subset.1 h ⟨x, xs, xt⟩ theorem nonempty_of_ssubset (ht : s ⊂ t) : (t \ s).Nonempty := nonempty_of_not_subset ht.2 theorem Nonempty.of_diff (h : (s \ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left theorem nonempty_of_ssubset' (ht : s ⊂ t) : t.Nonempty := (nonempty_of_ssubset ht).of_diff theorem Nonempty.inl (hs : s.Nonempty) : (s ∪ t).Nonempty := hs.imp fun _ => Or.inl theorem Nonempty.inr (ht : t.Nonempty) : (s ∪ t).Nonempty := ht.imp fun _ => Or.inr @[simp] theorem union_nonempty : (s ∪ t).Nonempty ↔ s.Nonempty ∨ t.Nonempty := exists_or theorem Nonempty.left (h : (s ∩ t).Nonempty) : s.Nonempty := h.imp fun _ => And.left theorem Nonempty.right (h : (s ∩ t).Nonempty) : t.Nonempty := h.imp fun _ => And.right theorem inter_nonempty : (s ∩ t).Nonempty ↔ ∃ x, x ∈ s ∧ x ∈ t := Iff.rfl theorem inter_nonempty_iff_exists_left : (s ∩ t).Nonempty ↔ ∃ x ∈ s, x ∈ t := by simp_rw [inter_nonempty] theorem inter_nonempty_iff_exists_right : (s ∩ t).Nonempty ↔ ∃ x ∈ t, x ∈ s := by simp_rw [inter_nonempty, and_comm] theorem nonempty_iff_univ_nonempty : Nonempty α ↔ (univ : Set α).Nonempty := ⟨fun ⟨x⟩ => ⟨x, trivial⟩, fun ⟨x, _⟩ => ⟨x⟩⟩ @[simp] theorem univ_nonempty : ∀ [Nonempty α], (univ : Set α).Nonempty | ⟨x⟩ => ⟨x, trivial⟩ theorem Nonempty.to_subtype : s.Nonempty → Nonempty (↥s) := nonempty_subtype.2 theorem Nonempty.to_type : s.Nonempty → Nonempty α := fun ⟨x, _⟩ => ⟨x⟩ instance univ.nonempty [Nonempty α] : Nonempty (↥(Set.univ : Set α)) := Set.univ_nonempty.to_subtype -- Redeclare for refined keys -- `Nonempty (@Subtype _ (@Membership.mem _ (Set _) _ (@Top.top (Set _) _)))` instance instNonemptyTop [Nonempty α] : Nonempty (⊤ : Set α) := inferInstanceAs (Nonempty (univ : Set α)) theorem Nonempty.of_subtype [Nonempty (↥s)] : s.Nonempty := nonempty_subtype.mp ‹_› @[deprecated (since := "2024-11-23")] alias nonempty_of_nonempty_subtype := Nonempty.of_subtype /-! ### Lemmas about the empty set -/ theorem empty_def : (∅ : Set α) = { _x : α | False } := rfl @[simp] theorem mem_empty_iff_false (x : α) : x ∈ (∅ : Set α) ↔ False := Iff.rfl @[simp] theorem setOf_false : { _a : α | False } = ∅ := rfl @[simp] theorem setOf_bot : { _x : α | ⊥ } = ∅ := rfl @[simp] theorem empty_subset (s : Set α) : ∅ ⊆ s := nofun @[simp] theorem subset_empty_iff {s : Set α} : s ⊆ ∅ ↔ s = ∅ := (Subset.antisymm_iff.trans <| and_iff_left (empty_subset _)).symm theorem eq_empty_iff_forall_not_mem {s : Set α} : s = ∅ ↔ ∀ x, x ∉ s := subset_empty_iff.symm theorem eq_empty_of_forall_not_mem (h : ∀ x, x ∉ s) : s = ∅ := subset_empty_iff.1 h theorem eq_empty_of_subset_empty {s : Set α} : s ⊆ ∅ → s = ∅ := subset_empty_iff.1 theorem eq_empty_of_isEmpty [IsEmpty α] (s : Set α) : s = ∅ := eq_empty_of_subset_empty fun x _ => isEmptyElim x /-- There is exactly one set of a type that is empty. -/ instance uniqueEmpty [IsEmpty α] : Unique (Set α) where default := ∅ uniq := eq_empty_of_isEmpty /-- See also `Set.nonempty_iff_ne_empty`. -/ theorem not_nonempty_iff_eq_empty {s : Set α} : ¬s.Nonempty ↔ s = ∅ := by simp only [Set.Nonempty, not_exists, eq_empty_iff_forall_not_mem] /-- See also `Set.not_nonempty_iff_eq_empty`. -/ theorem nonempty_iff_ne_empty : s.Nonempty ↔ s ≠ ∅ := not_nonempty_iff_eq_empty.not_right /-- See also `nonempty_iff_ne_empty'`. -/ theorem not_nonempty_iff_eq_empty' : ¬Nonempty s ↔ s = ∅ := by rw [nonempty_subtype, not_exists, eq_empty_iff_forall_not_mem] /-- See also `not_nonempty_iff_eq_empty'`. -/ theorem nonempty_iff_ne_empty' : Nonempty s ↔ s ≠ ∅ := not_nonempty_iff_eq_empty'.not_right alias ⟨Nonempty.ne_empty, _⟩ := nonempty_iff_ne_empty @[simp] theorem not_nonempty_empty : ¬(∅ : Set α).Nonempty := fun ⟨_, hx⟩ => hx @[simp] theorem isEmpty_coe_sort {s : Set α} : IsEmpty (↥s) ↔ s = ∅ := not_iff_not.1 <| by simpa using nonempty_iff_ne_empty theorem eq_empty_or_nonempty (s : Set α) : s = ∅ ∨ s.Nonempty := or_iff_not_imp_left.2 nonempty_iff_ne_empty.2 theorem subset_eq_empty {s t : Set α} (h : t ⊆ s) (e : s = ∅) : t = ∅ := subset_empty_iff.1 <| e ▸ h theorem forall_mem_empty {p : α → Prop} : (∀ x ∈ (∅ : Set α), p x) ↔ True := iff_true_intro fun _ => False.elim instance (α : Type u) : IsEmpty.{u + 1} (↥(∅ : Set α)) := ⟨fun x => x.2⟩ @[simp] theorem empty_ssubset : ∅ ⊂ s ↔ s.Nonempty := (@bot_lt_iff_ne_bot (Set α) _ _ _).trans nonempty_iff_ne_empty.symm alias ⟨_, Nonempty.empty_ssubset⟩ := empty_ssubset /-! ### Universal set. In Lean `@univ α` (or `univ : Set α`) is the set that contains all elements of type `α`. Mathematically it is the same as `α` but it has a different type. -/ @[simp] theorem setOf_true : { _x : α | True } = univ := rfl @[simp] theorem setOf_top : { _x : α | ⊤ } = univ := rfl @[simp] theorem univ_eq_empty_iff : (univ : Set α) = ∅ ↔ IsEmpty α := eq_empty_iff_forall_not_mem.trans ⟨fun H => ⟨fun x => H x trivial⟩, fun H x _ => @IsEmpty.false α H x⟩ theorem empty_ne_univ [Nonempty α] : (∅ : Set α) ≠ univ := fun e => not_isEmpty_of_nonempty α <| univ_eq_empty_iff.1 e.symm @[simp] theorem subset_univ (s : Set α) : s ⊆ univ := fun _ _ => trivial @[simp] theorem univ_subset_iff {s : Set α} : univ ⊆ s ↔ s = univ := @top_le_iff _ _ _ s alias ⟨eq_univ_of_univ_subset, _⟩ := univ_subset_iff theorem eq_univ_iff_forall {s : Set α} : s = univ ↔ ∀ x, x ∈ s := univ_subset_iff.symm.trans <| forall_congr' fun _ => imp_iff_right trivial theorem eq_univ_of_forall {s : Set α} : (∀ x, x ∈ s) → s = univ := eq_univ_iff_forall.2 theorem Nonempty.eq_univ [Subsingleton α] : s.Nonempty → s = univ := by rintro ⟨x, hx⟩ exact eq_univ_of_forall fun y => by rwa [Subsingleton.elim y x] theorem eq_univ_of_subset {s t : Set α} (h : s ⊆ t) (hs : s = univ) : t = univ := eq_univ_of_univ_subset <| (hs ▸ h : univ ⊆ t) theorem exists_mem_of_nonempty (α) : ∀ [Nonempty α], ∃ x : α, x ∈ (univ : Set α) | ⟨x⟩ => ⟨x, trivial⟩ theorem ne_univ_iff_exists_not_mem {α : Type*} (s : Set α) : s ≠ univ ↔ ∃ a, a ∉ s := by rw [← not_forall, ← eq_univ_iff_forall] theorem not_subset_iff_exists_mem_not_mem {α : Type*} {s t : Set α} : ¬s ⊆ t ↔ ∃ x, x ∈ s ∧ x ∉ t := by simp [subset_def] theorem univ_unique [Unique α] : @Set.univ α = {default} := Set.ext fun x => iff_of_true trivial <| Subsingleton.elim x default theorem ssubset_univ_iff : s ⊂ univ ↔ s ≠ univ := lt_top_iff_ne_top instance nontrivial_of_nonempty [Nonempty α] : Nontrivial (Set α) := ⟨⟨∅, univ, empty_ne_univ⟩⟩ /-! ### Lemmas about union -/ theorem union_def {s₁ s₂ : Set α} : s₁ ∪ s₂ = { a | a ∈ s₁ ∨ a ∈ s₂ } := rfl theorem mem_union_left {x : α} {a : Set α} (b : Set α) : x ∈ a → x ∈ a ∪ b := Or.inl theorem mem_union_right {x : α} {b : Set α} (a : Set α) : x ∈ b → x ∈ a ∪ b := Or.inr theorem mem_or_mem_of_mem_union {x : α} {a b : Set α} (H : x ∈ a ∪ b) : x ∈ a ∨ x ∈ b := H theorem MemUnion.elim {x : α} {a b : Set α} {P : Prop} (H₁ : x ∈ a ∪ b) (H₂ : x ∈ a → P) (H₃ : x ∈ b → P) : P := Or.elim H₁ H₂ H₃ @[simp] theorem mem_union (x : α) (a b : Set α) : x ∈ a ∪ b ↔ x ∈ a ∨ x ∈ b := Iff.rfl @[simp] theorem union_self (a : Set α) : a ∪ a = a := ext fun _ => or_self_iff @[simp] theorem union_empty (a : Set α) : a ∪ ∅ = a := ext fun _ => iff_of_eq (or_false _) @[simp] theorem empty_union (a : Set α) : ∅ ∪ a = a := ext fun _ => iff_of_eq (false_or _) theorem union_comm (a b : Set α) : a ∪ b = b ∪ a := ext fun _ => or_comm theorem union_assoc (a b c : Set α) : a ∪ b ∪ c = a ∪ (b ∪ c) := ext fun _ => or_assoc instance union_isAssoc : Std.Associative (α := Set α) (· ∪ ·) := ⟨union_assoc⟩ instance union_isComm : Std.Commutative (α := Set α) (· ∪ ·) := ⟨union_comm⟩ theorem union_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ (s₂ ∪ s₃) = s₂ ∪ (s₁ ∪ s₃) := ext fun _ => or_left_comm theorem union_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∪ s₂ ∪ s₃ = s₁ ∪ s₃ ∪ s₂ := ext fun _ => or_right_comm @[simp] theorem union_eq_left {s t : Set α} : s ∪ t = s ↔ t ⊆ s := sup_eq_left @[simp] theorem union_eq_right {s t : Set α} : s ∪ t = t ↔ s ⊆ t := sup_eq_right theorem union_eq_self_of_subset_left {s t : Set α} (h : s ⊆ t) : s ∪ t = t := union_eq_right.mpr h theorem union_eq_self_of_subset_right {s t : Set α} (h : t ⊆ s) : s ∪ t = s := union_eq_left.mpr h @[simp] theorem subset_union_left {s t : Set α} : s ⊆ s ∪ t := fun _ => Or.inl @[simp] theorem subset_union_right {s t : Set α} : t ⊆ s ∪ t := fun _ => Or.inr theorem union_subset {s t r : Set α} (sr : s ⊆ r) (tr : t ⊆ r) : s ∪ t ⊆ r := fun _ => Or.rec (@sr _) (@tr _) @[simp] theorem union_subset_iff {s t u : Set α} : s ∪ t ⊆ u ↔ s ⊆ u ∧ t ⊆ u := (forall_congr' fun _ => or_imp).trans forall_and @[gcongr] theorem union_subset_union {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ s₂) (h₂ : t₁ ⊆ t₂) : s₁ ∪ t₁ ⊆ s₂ ∪ t₂ := fun _ => Or.imp (@h₁ _) (@h₂ _) @[gcongr] theorem union_subset_union_left {s₁ s₂ : Set α} (t) (h : s₁ ⊆ s₂) : s₁ ∪ t ⊆ s₂ ∪ t := union_subset_union h Subset.rfl @[gcongr] theorem union_subset_union_right (s) {t₁ t₂ : Set α} (h : t₁ ⊆ t₂) : s ∪ t₁ ⊆ s ∪ t₂ := union_subset_union Subset.rfl h theorem subset_union_of_subset_left {s t : Set α} (h : s ⊆ t) (u : Set α) : s ⊆ t ∪ u := h.trans subset_union_left theorem subset_union_of_subset_right {s u : Set α} (h : s ⊆ u) (t : Set α) : s ⊆ t ∪ u := h.trans subset_union_right theorem union_congr_left (ht : t ⊆ s ∪ u) (hu : u ⊆ s ∪ t) : s ∪ t = s ∪ u := sup_congr_left ht hu theorem union_congr_right (hs : s ⊆ t ∪ u) (ht : t ⊆ s ∪ u) : s ∪ u = t ∪ u := sup_congr_right hs ht theorem union_eq_union_iff_left : s ∪ t = s ∪ u ↔ t ⊆ s ∪ u ∧ u ⊆ s ∪ t := sup_eq_sup_iff_left theorem union_eq_union_iff_right : s ∪ u = t ∪ u ↔ s ⊆ t ∪ u ∧ t ⊆ s ∪ u := sup_eq_sup_iff_right @[simp] theorem union_empty_iff {s t : Set α} : s ∪ t = ∅ ↔ s = ∅ ∧ t = ∅ := by simp only [← subset_empty_iff] exact union_subset_iff @[simp] theorem union_univ (s : Set α) : s ∪ univ = univ := sup_top_eq _ @[simp] theorem univ_union (s : Set α) : univ ∪ s = univ := top_sup_eq _ @[simp] theorem ssubset_union_left_iff : s ⊂ s ∪ t ↔ ¬ t ⊆ s := left_lt_sup @[simp] theorem ssubset_union_right_iff : t ⊂ s ∪ t ↔ ¬ s ⊆ t := right_lt_sup /-! ### Lemmas about intersection -/ theorem inter_def {s₁ s₂ : Set α} : s₁ ∩ s₂ = { a | a ∈ s₁ ∧ a ∈ s₂ } := rfl @[simp, mfld_simps] theorem mem_inter_iff (x : α) (a b : Set α) : x ∈ a ∩ b ↔ x ∈ a ∧ x ∈ b := Iff.rfl theorem mem_inter {x : α} {a b : Set α} (ha : x ∈ a) (hb : x ∈ b) : x ∈ a ∩ b := ⟨ha, hb⟩ theorem mem_of_mem_inter_left {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ a := h.left theorem mem_of_mem_inter_right {x : α} {a b : Set α} (h : x ∈ a ∩ b) : x ∈ b := h.right @[simp] theorem inter_self (a : Set α) : a ∩ a = a := ext fun _ => and_self_iff @[simp] theorem inter_empty (a : Set α) : a ∩ ∅ = ∅ := ext fun _ => iff_of_eq (and_false _) @[simp] theorem empty_inter (a : Set α) : ∅ ∩ a = ∅ := ext fun _ => iff_of_eq (false_and _) theorem inter_comm (a b : Set α) : a ∩ b = b ∩ a := ext fun _ => and_comm theorem inter_assoc (a b c : Set α) : a ∩ b ∩ c = a ∩ (b ∩ c) := ext fun _ => and_assoc instance inter_isAssoc : Std.Associative (α := Set α) (· ∩ ·) := ⟨inter_assoc⟩ instance inter_isComm : Std.Commutative (α := Set α) (· ∩ ·) := ⟨inter_comm⟩ theorem inter_left_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ (s₂ ∩ s₃) = s₂ ∩ (s₁ ∩ s₃) := ext fun _ => and_left_comm theorem inter_right_comm (s₁ s₂ s₃ : Set α) : s₁ ∩ s₂ ∩ s₃ = s₁ ∩ s₃ ∩ s₂ := ext fun _ => and_right_comm @[simp, mfld_simps] theorem inter_subset_left {s t : Set α} : s ∩ t ⊆ s := fun _ => And.left @[simp] theorem inter_subset_right {s t : Set α} : s ∩ t ⊆ t := fun _ => And.right theorem subset_inter {s t r : Set α} (rs : r ⊆ s) (rt : r ⊆ t) : r ⊆ s ∩ t := fun _ h => ⟨rs h, rt h⟩ @[simp] theorem subset_inter_iff {s t r : Set α} : r ⊆ s ∩ t ↔ r ⊆ s ∧ r ⊆ t := (forall_congr' fun _ => imp_and).trans forall_and @[simp] lemma inter_eq_left : s ∩ t = s ↔ s ⊆ t := inf_eq_left @[simp] lemma inter_eq_right : s ∩ t = t ↔ t ⊆ s := inf_eq_right @[simp] lemma left_eq_inter : s = s ∩ t ↔ s ⊆ t := left_eq_inf @[simp] lemma right_eq_inter : t = s ∩ t ↔ t ⊆ s := right_eq_inf theorem inter_eq_self_of_subset_left {s t : Set α} : s ⊆ t → s ∩ t = s := inter_eq_left.mpr theorem inter_eq_self_of_subset_right {s t : Set α} : t ⊆ s → s ∩ t = t := inter_eq_right.mpr theorem inter_congr_left (ht : s ∩ u ⊆ t) (hu : s ∩ t ⊆ u) : s ∩ t = s ∩ u := inf_congr_left ht hu theorem inter_congr_right (hs : t ∩ u ⊆ s) (ht : s ∩ u ⊆ t) : s ∩ u = t ∩ u := inf_congr_right hs ht theorem inter_eq_inter_iff_left : s ∩ t = s ∩ u ↔ s ∩ u ⊆ t ∧ s ∩ t ⊆ u := inf_eq_inf_iff_left theorem inter_eq_inter_iff_right : s ∩ u = t ∩ u ↔ t ∩ u ⊆ s ∧ s ∩ u ⊆ t := inf_eq_inf_iff_right @[simp, mfld_simps] theorem inter_univ (a : Set α) : a ∩ univ = a := inf_top_eq _ @[simp, mfld_simps] theorem univ_inter (a : Set α) : univ ∩ a = a := top_inf_eq _ @[gcongr] theorem inter_subset_inter {s₁ s₂ t₁ t₂ : Set α} (h₁ : s₁ ⊆ t₁) (h₂ : s₂ ⊆ t₂) : s₁ ∩ s₂ ⊆ t₁ ∩ t₂ := fun _ => And.imp (@h₁ _) (@h₂ _) @[gcongr] theorem inter_subset_inter_left {s t : Set α} (u : Set α) (H : s ⊆ t) : s ∩ u ⊆ t ∩ u := inter_subset_inter H Subset.rfl @[gcongr] theorem inter_subset_inter_right {s t : Set α} (u : Set α) (H : s ⊆ t) : u ∩ s ⊆ u ∩ t := inter_subset_inter Subset.rfl H theorem union_inter_cancel_left {s t : Set α} : (s ∪ t) ∩ s = s := inter_eq_self_of_subset_right subset_union_left theorem union_inter_cancel_right {s t : Set α} : (s ∪ t) ∩ t = t := inter_eq_self_of_subset_right subset_union_right theorem inter_setOf_eq_sep (s : Set α) (p : α → Prop) : s ∩ {a | p a} = {a ∈ s | p a} := rfl theorem setOf_inter_eq_sep (p : α → Prop) (s : Set α) : {a | p a} ∩ s = {a ∈ s | p a} := inter_comm _ _ @[simp] theorem inter_ssubset_right_iff : s ∩ t ⊂ t ↔ ¬ t ⊆ s := inf_lt_right @[simp] theorem inter_ssubset_left_iff : s ∩ t ⊂ s ↔ ¬ s ⊆ t := inf_lt_left /-! ### Distributivity laws -/ theorem inter_union_distrib_left (s t u : Set α) : s ∩ (t ∪ u) = s ∩ t ∪ s ∩ u := inf_sup_left _ _ _ theorem union_inter_distrib_right (s t u : Set α) : (s ∪ t) ∩ u = s ∩ u ∪ t ∩ u := inf_sup_right _ _ _ theorem union_inter_distrib_left (s t u : Set α) : s ∪ t ∩ u = (s ∪ t) ∩ (s ∪ u) := sup_inf_left _ _ _ theorem inter_union_distrib_right (s t u : Set α) : s ∩ t ∪ u = (s ∪ u) ∩ (t ∪ u) := sup_inf_right _ _ _ theorem union_union_distrib_left (s t u : Set α) : s ∪ (t ∪ u) = s ∪ t ∪ (s ∪ u) := sup_sup_distrib_left _ _ _ theorem union_union_distrib_right (s t u : Set α) : s ∪ t ∪ u = s ∪ u ∪ (t ∪ u) := sup_sup_distrib_right _ _ _ theorem inter_inter_distrib_left (s t u : Set α) : s ∩ (t ∩ u) = s ∩ t ∩ (s ∩ u) := inf_inf_distrib_left _ _ _ theorem inter_inter_distrib_right (s t u : Set α) : s ∩ t ∩ u = s ∩ u ∩ (t ∩ u) := inf_inf_distrib_right _ _ _ theorem union_union_union_comm (s t u v : Set α) : s ∪ t ∪ (u ∪ v) = s ∪ u ∪ (t ∪ v) := sup_sup_sup_comm _ _ _ _ theorem inter_inter_inter_comm (s t u v : Set α) : s ∩ t ∩ (u ∩ v) = s ∩ u ∩ (t ∩ v) := inf_inf_inf_comm _ _ _ _ /-! ### Lemmas about sets defined as `{x ∈ s | p x}`. -/ section Sep variable {p q : α → Prop} {x : α} theorem mem_sep (xs : x ∈ s) (px : p x) : x ∈ { x ∈ s | p x } := ⟨xs, px⟩ @[simp] theorem sep_mem_eq : { x ∈ s | x ∈ t } = s ∩ t := rfl @[simp] theorem mem_sep_iff : x ∈ { x ∈ s | p x } ↔ x ∈ s ∧ p x := Iff.rfl theorem sep_ext_iff : { x ∈ s | p x } = { x ∈ s | q x } ↔ ∀ x ∈ s, p x ↔ q x := by simp_rw [Set.ext_iff, mem_sep_iff, and_congr_right_iff] theorem sep_eq_of_subset (h : s ⊆ t) : { x ∈ t | x ∈ s } = s := inter_eq_self_of_subset_right h @[simp] theorem sep_subset (s : Set α) (p : α → Prop) : { x ∈ s | p x } ⊆ s := fun _ => And.left @[simp] theorem sep_eq_self_iff_mem_true : { x ∈ s | p x } = s ↔ ∀ x ∈ s, p x := by simp_rw [Set.ext_iff, mem_sep_iff, and_iff_left_iff_imp] @[simp] theorem sep_eq_empty_iff_mem_false : { x ∈ s | p x } = ∅ ↔ ∀ x ∈ s, ¬p x := by simp_rw [Set.ext_iff, mem_sep_iff, mem_empty_iff_false, iff_false, not_and] theorem sep_true : { x ∈ s | True } = s := inter_univ s theorem sep_false : { x ∈ s | False } = ∅ := inter_empty s theorem sep_empty (p : α → Prop) : { x ∈ (∅ : Set α) | p x } = ∅ := empty_inter {x | p x} theorem sep_univ : { x ∈ (univ : Set α) | p x } = { x | p x } := univ_inter {x | p x} @[simp] theorem sep_union : { x | (x ∈ s ∨ x ∈ t) ∧ p x } = { x ∈ s | p x } ∪ { x ∈ t | p x } := union_inter_distrib_right { x | x ∈ s } { x | x ∈ t } p @[simp] theorem sep_inter : { x | (x ∈ s ∧ x ∈ t) ∧ p x } = { x ∈ s | p x } ∩ { x ∈ t | p x } := inter_inter_distrib_right s t {x | p x} @[simp] theorem sep_and : { x ∈ s | p x ∧ q x } = { x ∈ s | p x } ∩ { x ∈ s | q x } := inter_inter_distrib_left s {x | p x} {x | q x} @[simp] theorem sep_or : { x ∈ s | p x ∨ q x } = { x ∈ s | p x } ∪ { x ∈ s | q x } := inter_union_distrib_left s p q @[simp] theorem sep_setOf : { x ∈ { y | p y } | q x } = { x | p x ∧ q x } := rfl end Sep /-- See also `Set.sdiff_inter_right_comm`. -/ lemma inter_diff_assoc (a b c : Set α) : (a ∩ b) \ c = a ∩ (b \ c) := inf_sdiff_assoc .. /-- See also `Set.inter_diff_assoc`. -/ lemma sdiff_inter_right_comm (s t u : Set α) : s \ t ∩ u = (s ∩ u) \ t := sdiff_inf_right_comm .. lemma inter_sdiff_left_comm (s t u : Set α) : s ∩ (t \ u) = t ∩ (s \ u) := inf_sdiff_left_comm .. theorem diff_union_diff_cancel (hts : t ⊆ s) (hut : u ⊆ t) : s \ t ∪ t \ u = s \ u := sdiff_sup_sdiff_cancel hts hut /-- A version of `diff_union_diff_cancel` with more general hypotheses. -/ theorem diff_union_diff_cancel' (hi : s ∩ u ⊆ t) (hu : t ⊆ s ∪ u) : (s \ t) ∪ (t \ u) = s \ u := sdiff_sup_sdiff_cancel' hi hu theorem diff_diff_eq_sdiff_union (h : u ⊆ s) : s \ (t \ u) = s \ t ∪ u := sdiff_sdiff_eq_sdiff_sup h theorem inter_diff_distrib_left (s t u : Set α) : s ∩ (t \ u) = (s ∩ t) \ (s ∩ u) := inf_sdiff_distrib_left _ _ _ theorem inter_diff_distrib_right (s t u : Set α) : (s \ t) ∩ u = (s ∩ u) \ (t ∩ u) := inf_sdiff_distrib_right _ _ _ theorem diff_inter_distrib_right (s t r : Set α) : (t ∩ r) \ s = (t \ s) ∩ (r \ s) := inf_sdiff /-! ### Lemmas about complement -/ theorem compl_def (s : Set α) : sᶜ = { x | x ∉ s } := rfl theorem mem_compl {s : Set α} {x : α} (h : x ∉ s) : x ∈ sᶜ := h theorem compl_setOf {α} (p : α → Prop) : { a | p a }ᶜ = { a | ¬p a } := rfl theorem not_mem_of_mem_compl {s : Set α} {x : α} (h : x ∈ sᶜ) : x ∉ s := h theorem not_mem_compl_iff {x : α} : x ∉ sᶜ ↔ x ∈ s := not_not @[simp] theorem inter_compl_self (s : Set α) : s ∩ sᶜ = ∅ := inf_compl_eq_bot @[simp] theorem compl_inter_self (s : Set α) : sᶜ ∩ s = ∅ := compl_inf_eq_bot @[simp] theorem compl_empty : (∅ : Set α)ᶜ = univ := compl_bot @[simp] theorem compl_union (s t : Set α) : (s ∪ t)ᶜ = sᶜ ∩ tᶜ := compl_sup theorem compl_inter (s t : Set α) : (s ∩ t)ᶜ = sᶜ ∪ tᶜ := compl_inf @[simp] theorem compl_univ : (univ : Set α)ᶜ = ∅ := compl_top @[simp] theorem compl_empty_iff {s : Set α} : sᶜ = ∅ ↔ s = univ := compl_eq_bot @[simp] theorem compl_univ_iff {s : Set α} : sᶜ = univ ↔ s = ∅ := compl_eq_top theorem compl_ne_univ : sᶜ ≠ univ ↔ s.Nonempty := compl_univ_iff.not.trans nonempty_iff_ne_empty.symm lemma inl_compl_union_inr_compl {α β : Type*} {s : Set α} {t : Set β} : Sum.inl '' sᶜ ∪ Sum.inr '' tᶜ = (Sum.inl '' s ∪ Sum.inr '' t)ᶜ := by rw [compl_union] aesop theorem nonempty_compl : sᶜ.Nonempty ↔ s ≠ univ := (ne_univ_iff_exists_not_mem s).symm theorem union_eq_compl_compl_inter_compl (s t : Set α) : s ∪ t = (sᶜ ∩ tᶜ)ᶜ := ext fun _ => or_iff_not_and_not theorem inter_eq_compl_compl_union_compl (s t : Set α) : s ∩ t = (sᶜ ∪ tᶜ)ᶜ := ext fun _ => and_iff_not_or_not @[simp] theorem union_compl_self (s : Set α) : s ∪ sᶜ = univ := eq_univ_iff_forall.2 fun _ => em _ @[simp] theorem compl_union_self (s : Set α) : sᶜ ∪ s = univ := by rw [union_comm, union_compl_self] theorem compl_subset_comm : sᶜ ⊆ t ↔ tᶜ ⊆ s := @compl_le_iff_compl_le _ s _ _ theorem subset_compl_comm : s ⊆ tᶜ ↔ t ⊆ sᶜ := @le_compl_iff_le_compl _ _ _ t @[simp] theorem compl_subset_compl : sᶜ ⊆ tᶜ ↔ t ⊆ s := @compl_le_compl_iff_le (Set α) _ _ _ @[gcongr] theorem compl_subset_compl_of_subset (h : t ⊆ s) : sᶜ ⊆ tᶜ := compl_subset_compl.2 h theorem subset_union_compl_iff_inter_subset {s t u : Set α} : s ⊆ t ∪ uᶜ ↔ s ∩ u ⊆ t := (@isCompl_compl _ u _).le_sup_right_iff_inf_left_le theorem compl_subset_iff_union {s t : Set α} : sᶜ ⊆ t ↔ s ∪ t = univ := Iff.symm <| eq_univ_iff_forall.trans <| forall_congr' fun _ => or_iff_not_imp_left theorem inter_subset (a b c : Set α) : a ∩ b ⊆ c ↔ a ⊆ bᶜ ∪ c := forall_congr' fun _ => and_imp.trans <| imp_congr_right fun _ => imp_iff_not_or theorem inter_compl_nonempty_iff {s t : Set α} : (s ∩ tᶜ).Nonempty ↔ ¬s ⊆ t := (not_subset.trans <| exists_congr fun x => by simp [mem_compl]).symm /-! ### Lemmas about set difference -/ theorem not_mem_diff_of_mem {s t : Set α} {x : α} (hx : x ∈ t) : x ∉ s \ t := fun h => h.2 hx theorem mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∈ s := h.left theorem not_mem_of_mem_diff {s t : Set α} {x : α} (h : x ∈ s \ t) : x ∉ t := h.right theorem diff_eq_compl_inter {s t : Set α} : s \ t = tᶜ ∩ s := by rw [diff_eq, inter_comm] theorem diff_nonempty {s t : Set α} : (s \ t).Nonempty ↔ ¬s ⊆ t := inter_compl_nonempty_iff theorem diff_subset {s t : Set α} : s \ t ⊆ s := show s \ t ≤ s from sdiff_le theorem diff_subset_compl (s t : Set α) : s \ t ⊆ tᶜ := diff_eq_compl_inter ▸ inter_subset_left theorem union_diff_cancel' {s t u : Set α} (h₁ : s ⊆ t) (h₂ : t ⊆ u) : t ∪ u \ s = u := sup_sdiff_cancel' h₁ h₂ theorem union_diff_cancel {s t : Set α} (h : s ⊆ t) : s ∪ t \ s = t := sup_sdiff_cancel_right h theorem union_diff_cancel_left {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ s = t := Disjoint.sup_sdiff_cancel_left <| disjoint_iff_inf_le.2 h theorem union_diff_cancel_right {s t : Set α} (h : s ∩ t ⊆ ∅) : (s ∪ t) \ t = s := Disjoint.sup_sdiff_cancel_right <| disjoint_iff_inf_le.2 h @[simp] theorem union_diff_left {s t : Set α} : (s ∪ t) \ s = t \ s := sup_sdiff_left_self @[simp] theorem union_diff_right {s t : Set α} : (s ∪ t) \ t = s \ t := sup_sdiff_right_self theorem union_diff_distrib {s t u : Set α} : (s ∪ t) \ u = s \ u ∪ t \ u := sup_sdiff @[simp] theorem inter_diff_self (a b : Set α) : a ∩ (b \ a) = ∅ := inf_sdiff_self_right @[simp] theorem inter_union_diff (s t : Set α) : s ∩ t ∪ s \ t = s := sup_inf_sdiff s t @[simp] theorem diff_union_inter (s t : Set α) : s \ t ∪ s ∩ t = s := by rw [union_comm] exact sup_inf_sdiff _ _ @[simp] theorem inter_union_compl (s t : Set α) : s ∩ t ∪ s ∩ tᶜ = s := inter_union_diff _ _ @[gcongr] theorem diff_subset_diff {s₁ s₂ t₁ t₂ : Set α} : s₁ ⊆ s₂ → t₂ ⊆ t₁ → s₁ \ t₁ ⊆ s₂ \ t₂ := show s₁ ≤ s₂ → t₂ ≤ t₁ → s₁ \ t₁ ≤ s₂ \ t₂ from sdiff_le_sdiff @[gcongr] theorem diff_subset_diff_left {s₁ s₂ t : Set α} (h : s₁ ⊆ s₂) : s₁ \ t ⊆ s₂ \ t := sdiff_le_sdiff_right ‹s₁ ≤ s₂› @[gcongr] theorem diff_subset_diff_right {s t u : Set α} (h : t ⊆ u) : s \ u ⊆ s \ t := sdiff_le_sdiff_left ‹t ≤ u› theorem diff_subset_diff_iff_subset {r : Set α} (hs : s ⊆ r) (ht : t ⊆ r) : r \ s ⊆ r \ t ↔ t ⊆ s := sdiff_le_sdiff_iff_le hs ht theorem compl_eq_univ_diff (s : Set α) : sᶜ = univ \ s := top_sdiff.symm @[simp] theorem empty_diff (s : Set α) : (∅ \ s : Set α) = ∅ := bot_sdiff theorem diff_eq_empty {s t : Set α} : s \ t = ∅ ↔ s ⊆ t := sdiff_eq_bot_iff @[simp] theorem diff_empty {s : Set α} : s \ ∅ = s := sdiff_bot @[simp] theorem diff_univ (s : Set α) : s \ univ = ∅ := diff_eq_empty.2 (subset_univ s) theorem diff_diff {u : Set α} : (s \ t) \ u = s \ (t ∪ u) := sdiff_sdiff_left -- the following statement contains parentheses to help the reader theorem diff_diff_comm {s t u : Set α} : (s \ t) \ u = (s \ u) \ t := sdiff_sdiff_comm theorem diff_subset_iff {s t u : Set α} : s \ t ⊆ u ↔ s ⊆ t ∪ u := show s \ t ≤ u ↔ s ≤ t ∪ u from sdiff_le_iff theorem subset_diff_union (s t : Set α) : s ⊆ s \ t ∪ t := show s ≤ s \ t ∪ t from le_sdiff_sup theorem diff_union_of_subset {s t : Set α} (h : t ⊆ s) : s \ t ∪ t = s := Subset.antisymm (union_subset diff_subset h) (subset_diff_union _ _) theorem diff_subset_comm {s t u : Set α} : s \ t ⊆ u ↔ s \ u ⊆ t := show s \ t ≤ u ↔ s \ u ≤ t from sdiff_le_comm theorem diff_inter {s t u : Set α} : s \ (t ∩ u) = s \ t ∪ s \ u := sdiff_inf theorem diff_inter_diff : s \ t ∩ (s \ u) = s \ (t ∪ u) := sdiff_sup.symm theorem diff_compl : s \ tᶜ = s ∩ t := sdiff_compl theorem compl_diff : (t \ s)ᶜ = s ∪ tᶜ := Eq.trans compl_sdiff himp_eq theorem diff_diff_right {s t u : Set α} : s \ (t \ u) = s \ t ∪ s ∩ u := sdiff_sdiff_right' theorem inter_diff_right_comm : (s ∩ t) \ u = s \ u ∩ t := by rw [diff_eq, diff_eq, inter_right_comm] theorem diff_inter_right_comm : (s \ u) ∩ t = (s ∩ t) \ u := by rw [diff_eq, diff_eq, inter_right_comm] @[simp] theorem union_diff_self {s t : Set α} : s ∪ t \ s = s ∪ t := sup_sdiff_self _ _ @[simp] theorem diff_union_self {s t : Set α} : s \ t ∪ t = s ∪ t := sdiff_sup_self _ _ @[simp] theorem diff_inter_self {a b : Set α} : b \ a ∩ a = ∅ := inf_sdiff_self_left @[simp] theorem diff_inter_self_eq_diff {s t : Set α} : s \ (t ∩ s) = s \ t := sdiff_inf_self_right _ _ @[simp] theorem diff_self_inter {s t : Set α} : s \ (s ∩ t) = s \ t := sdiff_inf_self_left _ _ theorem diff_self {s : Set α} : s \ s = ∅ := sdiff_self theorem diff_diff_right_self (s t : Set α) : s \ (s \ t) = s ∩ t := sdiff_sdiff_right_self theorem diff_diff_cancel_left {s t : Set α} (h : s ⊆ t) : t \ (t \ s) = s := sdiff_sdiff_eq_self h theorem union_eq_diff_union_diff_union_inter (s t : Set α) : s ∪ t = s \ t ∪ t \ s ∪ s ∩ t := sup_eq_sdiff_sup_sdiff_sup_inf /-! ### Powerset -/ theorem mem_powerset {x s : Set α} (h : x ⊆ s) : x ∈ 𝒫 s := @h theorem subset_of_mem_powerset {x s : Set α} (h : x ∈ 𝒫 s) : x ⊆ s := @h @[simp] theorem mem_powerset_iff (x s : Set α) : x ∈ 𝒫 s ↔ x ⊆ s := Iff.rfl theorem powerset_inter (s t : Set α) : 𝒫(s ∩ t) = 𝒫 s ∩ 𝒫 t := ext fun _ => subset_inter_iff @[simp] theorem powerset_mono : 𝒫 s ⊆ 𝒫 t ↔ s ⊆ t := ⟨fun h => @h _ (fun _ h => h), fun h _ hu _ ha => h (hu ha)⟩ theorem monotone_powerset : Monotone (powerset : Set α → Set (Set α)) := fun _ _ => powerset_mono.2 @[simp] theorem powerset_nonempty : (𝒫 s).Nonempty := ⟨∅, fun _ h => empty_subset s h⟩ @[simp] theorem powerset_empty : 𝒫(∅ : Set α) = {∅} := ext fun _ => subset_empty_iff @[simp] theorem powerset_univ : 𝒫(univ : Set α) = univ := eq_univ_of_forall subset_univ /-! ### Sets defined as an if-then-else -/ @[deprecated _root_.mem_dite (since := "2025-01-30")] protected theorem mem_dite (p : Prop) [Decidable p] (s : p → Set α) (t : ¬ p → Set α) (x : α) : (x ∈ if h : p then s h else t h) ↔ (∀ h : p, x ∈ s h) ∧ ∀ h : ¬p, x ∈ t h := _root_.mem_dite theorem mem_dite_univ_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else univ) ↔ ∀ h : p, x ∈ t h := by simp [mem_dite] @[simp] theorem mem_ite_univ_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t Set.univ ↔ p → x ∈ t := mem_dite_univ_right p (fun _ => t) x theorem mem_dite_univ_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then univ else t h) ↔ ∀ h : ¬p, x ∈ t h := by split_ifs <;> simp_all @[simp] theorem mem_ite_univ_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p Set.univ t ↔ ¬p → x ∈ t := mem_dite_univ_left p (fun _ => t) x theorem mem_dite_empty_right (p : Prop) [Decidable p] (t : p → Set α) (x : α) : (x ∈ if h : p then t h else ∅) ↔ ∃ h : p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false, not_not] exact ⟨fun h => ⟨h.2, h.1 h.2⟩, fun ⟨h₁, h₂⟩ => ⟨fun _ => h₂, h₁⟩⟩ @[simp] theorem mem_ite_empty_right (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p t ∅ ↔ p ∧ x ∈ t := (mem_dite_empty_right p (fun _ => t) x).trans (by simp) theorem mem_dite_empty_left (p : Prop) [Decidable p] (t : ¬p → Set α) (x : α) : (x ∈ if h : p then ∅ else t h) ↔ ∃ h : ¬p, x ∈ t h := by simp only [mem_dite, mem_empty_iff_false, imp_false] exact ⟨fun h => ⟨h.1, h.2 h.1⟩, fun ⟨h₁, h₂⟩ => ⟨fun h => h₁ h, fun _ => h₂⟩⟩ @[simp] theorem mem_ite_empty_left (p : Prop) [Decidable p] (t : Set α) (x : α) : x ∈ ite p ∅ t ↔ ¬p ∧ x ∈ t := (mem_dite_empty_left p (fun _ => t) x).trans (by simp) /-! ### If-then-else for sets -/ /-- `ite` for sets: `Set.ite t s s' ∩ t = s ∩ t`, `Set.ite t s s' ∩ tᶜ = s' ∩ tᶜ`. Defined as `s ∩ t ∪ s' \ t`. -/ protected def ite (t s s' : Set α) : Set α := s ∩ t ∪ s' \ t @[simp] theorem ite_inter_self (t s s' : Set α) : t.ite s s' ∩ t = s ∩ t := by rw [Set.ite, union_inter_distrib_right, diff_inter_self, inter_assoc, inter_self, union_empty] @[simp] theorem ite_compl (t s s' : Set α) : tᶜ.ite s s' = t.ite s' s := by rw [Set.ite, Set.ite, diff_compl, union_comm, diff_eq] @[simp] theorem ite_inter_compl_self (t s s' : Set α) : t.ite s s' ∩ tᶜ = s' ∩ tᶜ := by rw [← ite_compl, ite_inter_self] @[simp] theorem ite_diff_self (t s s' : Set α) : t.ite s s' \ t = s' \ t := ite_inter_compl_self t s s' @[simp] theorem ite_same (t s : Set α) : t.ite s s = s := inter_union_diff _ _ @[simp] theorem ite_left (s t : Set α) : s.ite s t = s ∪ t := by simp [Set.ite] @[simp] theorem ite_right (s t : Set α) : s.ite t s = t ∩ s := by simp [Set.ite] @[simp] theorem ite_empty (s s' : Set α) : Set.ite ∅ s s' = s' := by simp [Set.ite] @[simp] theorem ite_univ (s s' : Set α) : Set.ite univ s s' = s := by simp [Set.ite] @[simp] theorem ite_empty_left (t s : Set α) : t.ite ∅ s = s \ t := by simp [Set.ite] @[simp] theorem ite_empty_right (t s : Set α) : t.ite s ∅ = s ∩ t := by simp [Set.ite] theorem ite_mono (t : Set α) {s₁ s₁' s₂ s₂' : Set α} (h : s₁ ⊆ s₂) (h' : s₁' ⊆ s₂') : t.ite s₁ s₁' ⊆ t.ite s₂ s₂' := union_subset_union (inter_subset_inter_left _ h) (inter_subset_inter_left _ h') theorem ite_subset_union (t s s' : Set α) : t.ite s s' ⊆ s ∪ s' := union_subset_union inter_subset_left diff_subset theorem inter_subset_ite (t s s' : Set α) : s ∩ s' ⊆ t.ite s s' := ite_same t (s ∩ s') ▸ ite_mono _ inter_subset_left inter_subset_right theorem ite_inter_inter (t s₁ s₂ s₁' s₂' : Set α) : t.ite (s₁ ∩ s₂) (s₁' ∩ s₂') = t.ite s₁ s₁' ∩ t.ite s₂ s₂' := by ext x simp only [Set.ite, Set.mem_inter_iff, Set.mem_diff, Set.mem_union] tauto theorem ite_inter (t s₁ s₂ s : Set α) : t.ite (s₁ ∩ s) (s₂ ∩ s) = t.ite s₁ s₂ ∩ s := by rw [ite_inter_inter, ite_same] theorem ite_inter_of_inter_eq (t : Set α) {s₁ s₂ s : Set α} (h : s₁ ∩ s = s₂ ∩ s) : t.ite s₁ s₂ ∩ s = s₁ ∩ s := by rw [← ite_inter, ← h, ite_same] theorem subset_ite {t s s' u : Set α} : u ⊆ t.ite s s' ↔ u ∩ t ⊆ s ∧ u \ t ⊆ s' := by simp only [subset_def, ← forall_and] refine forall_congr' fun x => ?_ by_cases hx : x ∈ t <;> simp [*, Set.ite] theorem ite_eq_of_subset_left (t : Set α) {s₁ s₂ : Set α} (h : s₁ ⊆ s₂) : t.ite s₁ s₂ = s₁ ∪ (s₂ \ t) := by ext x by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_right_of_imp (@h x)] theorem ite_eq_of_subset_right (t : Set α) {s₁ s₂ : Set α} (h : s₂ ⊆ s₁) : t.ite s₁ s₂ = (s₁ ∩ t) ∪ s₂ := by ext x by_cases hx : x ∈ t <;> simp [*, Set.ite, or_iff_left_of_imp (@h x)] end Set open Set namespace Function variable {α : Type*} {β : Type*} theorem Injective.nonempty_apply_iff {f : Set α → Set β} (hf : Injective f) (h2 : f ∅ = ∅) {s : Set α} : (f s).Nonempty ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, ← h2, nonempty_iff_ne_empty, hf.ne_iff] end Function namespace Subsingleton variable {α : Type*} [Subsingleton α] theorem eq_univ_of_nonempty {s : Set α} : s.Nonempty → s = univ := fun ⟨x, hx⟩ => eq_univ_of_forall fun y => Subsingleton.elim x y ▸ hx @[elab_as_elim] theorem set_cases {p : Set α → Prop} (h0 : p ∅) (h1 : p univ) (s) : p s := (s.eq_empty_or_nonempty.elim fun h => h.symm ▸ h0) fun h => (eq_univ_of_nonempty h).symm ▸ h1 theorem mem_iff_nonempty {α : Type*} [Subsingleton α] {s : Set α} {x : α} : x ∈ s ↔ s.Nonempty := ⟨fun hx => ⟨x, hx⟩, fun ⟨y, hy⟩ => Subsingleton.elim y x ▸ hy⟩ end Subsingleton /-! ### Decidability instances for sets -/ namespace Set variable {α : Type u} (s t : Set α) (a b : α) instance decidableSdiff [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s \ t) := inferInstanceAs (Decidable (a ∈ s ∧ a ∉ t)) instance decidableInter [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∩ t) := inferInstanceAs (Decidable (a ∈ s ∧ a ∈ t)) instance decidableUnion [Decidable (a ∈ s)] [Decidable (a ∈ t)] : Decidable (a ∈ s ∪ t) := inferInstanceAs (Decidable (a ∈ s ∨ a ∈ t)) instance decidableCompl [Decidable (a ∈ s)] : Decidable (a ∈ sᶜ) := inferInstanceAs (Decidable (a ∉ s)) instance decidableEmptyset : Decidable (a ∈ (∅ : Set α)) := Decidable.isFalse (by simp) instance decidableUniv : Decidable (a ∈ univ) := Decidable.isTrue (by simp) instance decidableInsert [Decidable (a = b)] [Decidable (a ∈ s)] : Decidable (a ∈ insert b s) := inferInstanceAs (Decidable (_ ∨ _)) instance decidableSetOf (p : α → Prop) [Decidable (p a)] : Decidable (a ∈ { a | p a }) := by assumption end Set variable {α : Type*} {s t u : Set α} namespace Equiv /-- Given a predicate `p : α → Prop`, produces an equivalence between `Set {a : α // p a}` and `{s : Set α // ∀ a ∈ s, p a}`. -/ protected def setSubtypeComm (p : α → Prop) : Set {a : α // p a} ≃ {s : Set α // ∀ a ∈ s, p a} where toFun s := ⟨{a | ∃ h : p a, s ⟨a, h⟩}, fun _ h ↦ h.1⟩ invFun s := {a | a.val ∈ s.val} left_inv s := by ext a; exact ⟨fun h ↦ h.2, fun h ↦ ⟨a.property, h⟩⟩ right_inv s := by ext; exact ⟨fun h ↦ h.2, fun h ↦ ⟨s.property _ h, h⟩⟩ @[simp] protected lemma setSubtypeComm_apply (p : α → Prop) (s : Set {a // p a}) : (Equiv.setSubtypeComm p) s = ⟨{a | ∃ h : p a, ⟨a, h⟩ ∈ s}, fun _ h ↦ h.1⟩ := rfl @[simp] protected lemma setSubtypeComm_symm_apply (p : α → Prop) (s : {s // ∀ a ∈ s, p a}) : (Equiv.setSubtypeComm p).symm s = {a | a.val ∈ s.val} := rfl end Equiv
Mathlib/Data/Set/Basic.lean
2,368
2,370
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Jeremy Avigad -/ import Mathlib.Data.Set.Finite.Basic import Mathlib.Data.Set.Finite.Range import Mathlib.Data.Set.Lattice import Mathlib.Topology.Defs.Filter /-! # Openness and closedness of a set This file provides lemmas relating to the predicates `IsOpen` and `IsClosed` of a set endowed with a topology. ## Implementation notes Topology in mathlib heavily uses filters (even more than in Bourbaki). See explanations in <https://leanprover-community.github.io/theories/topology.html>. ## References * [N. Bourbaki, *General Topology*][bourbaki1966] * [I. M. James, *Topologies and Uniformities*][james1999] ## Tags topological space -/ open Set Filter Topology universe u v /-- A constructor for topologies by specifying the closed sets, and showing that they satisfy the appropriate conditions. -/ def TopologicalSpace.ofClosed {X : Type u} (T : Set (Set X)) (empty_mem : ∅ ∈ T) (sInter_mem : ∀ A, A ⊆ T → ⋂₀ A ∈ T) (union_mem : ∀ A, A ∈ T → ∀ B, B ∈ T → A ∪ B ∈ T) : TopologicalSpace X where IsOpen X := Xᶜ ∈ T isOpen_univ := by simp [empty_mem] isOpen_inter s t hs ht := by simpa only [compl_inter] using union_mem sᶜ hs tᶜ ht isOpen_sUnion s hs := by simp only [Set.compl_sUnion] exact sInter_mem (compl '' s) fun z ⟨y, hy, hz⟩ => hz ▸ hs y hy section TopologicalSpace variable {X : Type u} {ι : Sort v} {α : Type*} {x : X} {s s₁ s₂ t : Set X} {p p₁ p₂ : X → Prop} lemma isOpen_mk {p h₁ h₂ h₃} : IsOpen[⟨p, h₁, h₂, h₃⟩] s ↔ p s := Iff.rfl @[ext (iff := false)] protected theorem TopologicalSpace.ext : ∀ {f g : TopologicalSpace X}, IsOpen[f] = IsOpen[g] → f = g | ⟨_, _, _, _⟩, ⟨_, _, _, _⟩, rfl => rfl protected theorem TopologicalSpace.ext_iff {t t' : TopologicalSpace X} : t = t' ↔ ∀ s, IsOpen[t] s ↔ IsOpen[t'] s := ⟨fun h _ => h ▸ Iff.rfl, fun h => by ext; exact h _⟩ theorem isOpen_fold {t : TopologicalSpace X} : t.IsOpen s = IsOpen[t] s := rfl variable [TopologicalSpace X] theorem isOpen_iUnion {f : ι → Set X} (h : ∀ i, IsOpen (f i)) : IsOpen (⋃ i, f i) := isOpen_sUnion (forall_mem_range.2 h) theorem isOpen_biUnion {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋃ i ∈ s, f i) := isOpen_iUnion fun i => isOpen_iUnion fun hi => h i hi theorem IsOpen.union (h₁ : IsOpen s₁) (h₂ : IsOpen s₂) : IsOpen (s₁ ∪ s₂) := by rw [union_eq_iUnion]; exact isOpen_iUnion (Bool.forall_bool.2 ⟨h₂, h₁⟩) lemma isOpen_iff_of_cover {f : α → Set X} (ho : ∀ i, IsOpen (f i)) (hU : (⋃ i, f i) = univ) : IsOpen s ↔ ∀ i, IsOpen (f i ∩ s) := by refine ⟨fun h i ↦ (ho i).inter h, fun h ↦ ?_⟩ rw [← s.inter_univ, inter_comm, ← hU, iUnion_inter] exact isOpen_iUnion fun i ↦ h i @[simp] theorem isOpen_empty : IsOpen (∅ : Set X) := by rw [← sUnion_empty]; exact isOpen_sUnion fun a => False.elim theorem Set.Finite.isOpen_sInter {s : Set (Set X)} (hs : s.Finite) (h : ∀ t ∈ s, IsOpen t) : IsOpen (⋂₀ s) := by induction s, hs using Set.Finite.induction_on with | empty => rw [sInter_empty]; exact isOpen_univ | insert _ _ ih => simp only [sInter_insert, forall_mem_insert] at h ⊢ exact h.1.inter (ih h.2) theorem Set.Finite.isOpen_biInter {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := sInter_image f s ▸ (hs.image _).isOpen_sInter (forall_mem_image.2 h) theorem isOpen_iInter_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsOpen (s i)) : IsOpen (⋂ i, s i) := (finite_range _).isOpen_sInter (forall_mem_range.2 h) theorem isOpen_biInter_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsOpen (f i)) : IsOpen (⋂ i ∈ s, f i) := s.finite_toSet.isOpen_biInter h @[simp] theorem isOpen_const {p : Prop} : IsOpen { _x : X | p } := by by_cases p <;> simp [*] theorem IsOpen.and : IsOpen { x | p₁ x } → IsOpen { x | p₂ x } → IsOpen { x | p₁ x ∧ p₂ x } := IsOpen.inter @[simp] theorem isOpen_compl_iff : IsOpen sᶜ ↔ IsClosed s := ⟨fun h => ⟨h⟩, fun h => h.isOpen_compl⟩ theorem TopologicalSpace.ext_iff_isClosed {X} {t₁ t₂ : TopologicalSpace X} : t₁ = t₂ ↔ ∀ s, IsClosed[t₁] s ↔ IsClosed[t₂] s := by rw [TopologicalSpace.ext_iff, compl_surjective.forall] simp only [@isOpen_compl_iff _ _ t₁, @isOpen_compl_iff _ _ t₂] alias ⟨_, TopologicalSpace.ext_isClosed⟩ := TopologicalSpace.ext_iff_isClosed theorem isClosed_const {p : Prop} : IsClosed { _x : X | p } := ⟨isOpen_const (p := ¬p)⟩ @[simp] theorem isClosed_empty : IsClosed (∅ : Set X) := isClosed_const @[simp] theorem isClosed_univ : IsClosed (univ : Set X) := isClosed_const lemma IsOpen.isLocallyClosed (hs : IsOpen s) : IsLocallyClosed s := ⟨_, _, hs, isClosed_univ, (inter_univ _).symm⟩ lemma IsClosed.isLocallyClosed (hs : IsClosed s) : IsLocallyClosed s := ⟨_, _, isOpen_univ, hs, (univ_inter _).symm⟩ theorem IsClosed.union : IsClosed s₁ → IsClosed s₂ → IsClosed (s₁ ∪ s₂) := by simpa only [← isOpen_compl_iff, compl_union] using IsOpen.inter theorem isClosed_sInter {s : Set (Set X)} : (∀ t ∈ s, IsClosed t) → IsClosed (⋂₀ s) := by simpa only [← isOpen_compl_iff, compl_sInter, sUnion_image] using isOpen_biUnion theorem isClosed_iInter {f : ι → Set X} (h : ∀ i, IsClosed (f i)) : IsClosed (⋂ i, f i) := isClosed_sInter <| forall_mem_range.2 h theorem isClosed_biInter {s : Set α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋂ i ∈ s, f i) := isClosed_iInter fun i => isClosed_iInter <| h i @[simp] theorem isClosed_compl_iff {s : Set X} : IsClosed sᶜ ↔ IsOpen s := by rw [← isOpen_compl_iff, compl_compl] alias ⟨_, IsOpen.isClosed_compl⟩ := isClosed_compl_iff theorem IsOpen.sdiff (h₁ : IsOpen s) (h₂ : IsClosed t) : IsOpen (s \ t) := IsOpen.inter h₁ h₂.isOpen_compl theorem IsClosed.inter (h₁ : IsClosed s₁) (h₂ : IsClosed s₂) : IsClosed (s₁ ∩ s₂) := by rw [← isOpen_compl_iff] at * rw [compl_inter] exact IsOpen.union h₁ h₂ theorem IsClosed.sdiff (h₁ : IsClosed s) (h₂ : IsOpen t) : IsClosed (s \ t) := IsClosed.inter h₁ (isClosed_compl_iff.mpr h₂) theorem Set.Finite.isClosed_biUnion {s : Set α} {f : α → Set X} (hs : s.Finite) (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact hs.isOpen_biInter h lemma isClosed_biUnion_finset {s : Finset α} {f : α → Set X} (h : ∀ i ∈ s, IsClosed (f i)) : IsClosed (⋃ i ∈ s, f i) := s.finite_toSet.isClosed_biUnion h theorem isClosed_iUnion_of_finite [Finite ι] {s : ι → Set X} (h : ∀ i, IsClosed (s i)) : IsClosed (⋃ i, s i) := by simp only [← isOpen_compl_iff, compl_iUnion] at * exact isOpen_iInter_of_finite h theorem isClosed_imp {p q : X → Prop} (hp : IsOpen { x | p x }) (hq : IsClosed { x | q x }) : IsClosed { x | p x → q x } := by simpa only [imp_iff_not_or] using hp.isClosed_compl.union hq theorem IsClosed.not : IsClosed { a | p a } → IsOpen { a | ¬p a } := isOpen_compl_iff.mpr /-! ### Limits of filters in topological spaces In this section we define functions that return a limit of a filter (or of a function along a filter), if it exists, and a random point otherwise. These functions are rarely used in Mathlib, most of the theorems are written using `Filter.Tendsto`. One of the reasons is that `Filter.limUnder f g = x` is not equivalent to `Filter.Tendsto g f (𝓝 x)` unless the codomain is a Hausdorff space and `g` has a limit along `f`. -/ section lim /-- If a filter `f` is majorated by some `𝓝 x`, then it is majorated by `𝓝 (Filter.lim f)`. We formulate this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for types without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify this instance with any other instance. -/ theorem le_nhds_lim {f : Filter X} (h : ∃ x, f ≤ 𝓝 x) : f ≤ 𝓝 (@lim _ _ (nonempty_of_exists h) f) := Classical.epsilon_spec h /-- If `g` tends to some `𝓝 x` along `f`, then it tends to `𝓝 (Filter.limUnder f g)`. We formulate this lemma with a `[Nonempty X]` argument of `lim` derived from `h` to make it useful for types without a `[Nonempty X]` instance. Because of the built-in proof irrelevance, Lean will unify this instance with any other instance. -/ theorem tendsto_nhds_limUnder {f : Filter α} {g : α → X} (h : ∃ x, Tendsto g f (𝓝 x)) : Tendsto g f (𝓝 (@limUnder _ _ _ (nonempty_of_exists h) f g)) := le_nhds_lim h theorem limUnder_of_not_tendsto [hX : Nonempty X] {f : Filter α} {g : α → X} (h : ¬ ∃ x, Tendsto g f (𝓝 x)) : limUnder f g = Classical.choice hX := by simp_rw [Tendsto] at h simp_rw [limUnder, lim, Classical.epsilon, Classical.strongIndefiniteDescription, dif_neg h] end lim end TopologicalSpace
Mathlib/Topology/Basic.lean
248
249
/- Copyright (c) 2020 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Joseph Myers -/ import Mathlib.Data.Complex.Exponential import Mathlib.Analysis.SpecialFunctions.Log.Deriv /-! # Bounds on specific values of the exponential -/ namespace Real open IsAbsoluteValue Finset CauSeq Complex theorem exp_one_near_10 : |exp 1 - 2244083 / 825552| ≤ 1 / 10 ^ 10 := by apply exp_approx_start iterate 13 refine exp_1_approx_succ_eq (by norm_num1; rfl) (by norm_cast) ?_ norm_num1 refine exp_approx_end' _ (by norm_num1; rfl) _ (by norm_cast) (by simp) ?_ rw [_root_.abs_one, abs_of_pos] <;> norm_num1 theorem exp_one_near_20 : |exp 1 - 363916618873 / 133877442384| ≤ 1 / 10 ^ 20 := by apply exp_approx_start iterate 21 refine exp_1_approx_succ_eq (by norm_num1; rfl) (by norm_cast) ?_
norm_num1 refine exp_approx_end' _ (by norm_num1; rfl) _ (by norm_cast) (by simp) ?_ rw [_root_.abs_one, abs_of_pos] <;> norm_num1 theorem exp_one_gt_d9 : 2.7182818283 < exp 1 := lt_of_lt_of_le (by norm_num) (sub_le_comm.1 (abs_sub_le_iff.1 exp_one_near_10).2)
Mathlib/Data/Complex/ExponentialBounds.lean
28
33
/- Copyright (c) 2022 Sébastien Gouëzel. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel -/ import Mathlib.Probability.IdentDistrib import Mathlib.Probability.Independence.Integrable import Mathlib.MeasureTheory.Integral.DominatedConvergence import Mathlib.Analysis.SpecificLimits.FloorPow import Mathlib.Analysis.PSeries import Mathlib.Analysis.Asymptotics.SpecificAsymptotics /-! # The strong law of large numbers We prove the strong law of large numbers, in `ProbabilityTheory.strong_law_ae`: If `X n` is a sequence of independent identically distributed integrable random variables, then `∑ i ∈ range n, X i / n` converges almost surely to `𝔼[X 0]`. We give here the strong version, due to Etemadi, that only requires pairwise independence. This file also contains the Lᵖ version of the strong law of large numbers provided by `ProbabilityTheory.strong_law_Lp` which shows `∑ i ∈ range n, X i / n` converges in Lᵖ to `𝔼[X 0]` provided `X n` is independent identically distributed and is Lᵖ. ## Implementation The main point is to prove the result for real-valued random variables, as the general case of Banach-space valued random variables follows from this case and approximation by simple functions. The real version is given in `ProbabilityTheory.strong_law_ae_real`. We follow the proof by Etemadi [Etemadi, *An elementary proof of the strong law of large numbers*][etemadi_strong_law], which goes as follows. It suffices to prove the result for nonnegative `X`, as one can prove the general result by splitting a general `X` into its positive part and negative part. Consider `Xₙ` a sequence of nonnegative integrable identically distributed pairwise independent random variables. Let `Yₙ` be the truncation of `Xₙ` up to `n`. We claim that * Almost surely, `Xₙ = Yₙ` for all but finitely many indices. Indeed, `∑ ℙ (Xₙ ≠ Yₙ)` is bounded by `1 + 𝔼[X]` (see `sum_prob_mem_Ioc_le` and `tsum_prob_mem_Ioi_lt_top`). * Let `c > 1`. Along the sequence `n = c ^ k`, then `(∑_{i=0}^{n-1} Yᵢ - 𝔼[Yᵢ])/n` converges almost surely to `0`. This follows from a variance control, as ``` ∑_k ℙ (|∑_{i=0}^{c^k - 1} Yᵢ - 𝔼[Yᵢ]| > c^k ε) ≤ ∑_k (c^k ε)^{-2} ∑_{i=0}^{c^k - 1} Var[Yᵢ] (by Markov inequality) ≤ ∑_i (C/i^2) Var[Yᵢ] (as ∑_{c^k > i} 1/(c^k)^2 ≤ C/i^2) ≤ ∑_i (C/i^2) 𝔼[Yᵢ^2] ≤ 2C 𝔼[X^2] (see `sum_variance_truncation_le`) ``` * As `𝔼[Yᵢ]` converges to `𝔼[X]`, it follows from the two previous items and Cesàro that, along the sequence `n = c^k`, one has `(∑_{i=0}^{n-1} Xᵢ) / n → 𝔼[X]` almost surely. * To generalize it to all indices, we use the fact that `∑_{i=0}^{n-1} Xᵢ` is nondecreasing and that, if `c` is close enough to `1`, the gap between `c^k` and `c^(k+1)` is small. -/ noncomputable section open MeasureTheory Filter Finset Asymptotics open Set (indicator) open scoped Topology MeasureTheory ProbabilityTheory ENNReal NNReal open scoped Function -- required for scoped `on` notation namespace ProbabilityTheory /-! ### Prerequisites on truncations -/ section Truncation variable {α : Type*} /-- Truncating a real-valued function to the interval `(-A, A]`. -/ def truncation (f : α → ℝ) (A : ℝ) := indicator (Set.Ioc (-A) A) id ∘ f variable {m : MeasurableSpace α} {μ : Measure α} {f : α → ℝ} theorem _root_.MeasureTheory.AEStronglyMeasurable.truncation (hf : AEStronglyMeasurable f μ) {A : ℝ} : AEStronglyMeasurable (truncation f A) μ := by apply AEStronglyMeasurable.comp_aemeasurable _ hf.aemeasurable exact (stronglyMeasurable_id.indicator measurableSet_Ioc).aestronglyMeasurable theorem abs_truncation_le_bound (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |A| := by simp only [truncation, Set.indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs with h · exact abs_le_abs h.2 (neg_le.2 h.1.le) · simp [abs_nonneg] @[simp] theorem truncation_zero (f : α → ℝ) : truncation f 0 = 0 := by simp [truncation]; rfl theorem abs_truncation_le_abs_self (f : α → ℝ) (A : ℝ) (x : α) : |truncation f A x| ≤ |f x| := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply] split_ifs · exact le_rfl · simp [abs_nonneg] theorem truncation_eq_self {f : α → ℝ} {A : ℝ} {x : α} (h : |f x| < A) : truncation f A x = f x := by simp only [truncation, indicator, Set.mem_Icc, id, Function.comp_apply, ite_eq_left_iff] intro H apply H.elim simp [(abs_lt.1 h).1, (abs_lt.1 h).2.le] theorem truncation_eq_of_nonneg {f : α → ℝ} {A : ℝ} (h : ∀ x, 0 ≤ f x) : truncation f A = indicator (Set.Ioc 0 A) id ∘ f := by ext x rcases (h x).lt_or_eq with (hx | hx) · simp only [truncation, indicator, hx, Set.mem_Ioc, id, Function.comp_apply] by_cases h'x : f x ≤ A · have : -A < f x := by linarith [h x] simp only [this, true_and] · simp only [h'x, and_false] · simp only [truncation, indicator, hx, id, Function.comp_apply, ite_self] theorem truncation_nonneg {f : α → ℝ} (A : ℝ) {x : α} (h : 0 ≤ f x) : 0 ≤ truncation f A x := Set.indicator_apply_nonneg fun _ => h theorem _root_.MeasureTheory.AEStronglyMeasurable.memLp_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} {p : ℝ≥0∞} : MemLp (truncation f A) p μ := MemLp.of_bound hf.truncation |A| (Eventually.of_forall fun _ => abs_truncation_le_bound _ _ _) theorem _root_.MeasureTheory.AEStronglyMeasurable.integrable_truncation [IsFiniteMeasure μ] (hf : AEStronglyMeasurable f μ) {A : ℝ} : Integrable (truncation f A) μ := by rw [← memLp_one_iff_integrable]; exact hf.memLp_truncation theorem moment_truncation_eq_intervalIntegral (hf : AEStronglyMeasurable f μ) {A : ℝ} (hA : 0 ≤ A) {n : ℕ} (hn : n ≠ 0) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in -A..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc (-A) A) := measurableSet_Ioc change ∫ x, (fun z => indicator (Set.Ioc (-A) A) id z ^ n) (f x) ∂μ = _ rw [← integral_map (f := fun z => _ ^ n) hf.aemeasurable, intervalIntegral.integral_of_le, ← integral_indicator M] · simp only [indicator, zero_pow hn, id, ite_pow] · linarith · exact ((measurable_id.indicator M).pow_const n).aestronglyMeasurable
theorem moment_truncation_eq_intervalIntegral_of_nonneg (hf : AEStronglyMeasurable f μ) {A : ℝ} {n : ℕ} (hn : n ≠ 0) (h'f : 0 ≤ f) : ∫ x, truncation f A x ^ n ∂μ = ∫ y in (0)..A, y ^ n ∂Measure.map f μ := by have M : MeasurableSet (Set.Ioc 0 A) := measurableSet_Ioc have M' : MeasurableSet (Set.Ioc A 0) := measurableSet_Ioc rw [truncation_eq_of_nonneg h'f] change ∫ x, (fun z => indicator (Set.Ioc 0 A) id z ^ n) (f x) ∂μ = _ rcases le_or_lt 0 A with (hA | hA)
Mathlib/Probability/StrongLaw.lean
140
148
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import Mathlib.MeasureTheory.MeasurableSpace.MeasurablyGenerated import Mathlib.MeasureTheory.Measure.NullMeasurable import Mathlib.Order.Interval.Set.Monotone /-! # Measure spaces The definition of a measure and a measure space are in `MeasureTheory.MeasureSpaceDef`, with only a few basic properties. This file provides many more properties of these objects. This separation allows the measurability tactic to import only the file `MeasureSpaceDef`, and to be available in `MeasureSpace` (through `MeasurableSpace`). Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the extended nonnegative reals that satisfies the following conditions: 1. `μ ∅ = 0`; 2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint sets is equal to the measure of the individual sets. Every measure can be canonically extended to an outer measure, so that it assigns values to all subsets, not just the measurable subsets. On the other hand, a measure that is countably additive on measurable sets can be restricted to measurable sets to obtain a measure. In this file a measure is defined to be an outer measure that is countably additive on measurable sets, with the additional assumption that the outer measure is the canonical extension of the restricted measure. Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`. Given a measure, the null sets are the sets where `μ s = 0`, where `μ` denotes the corresponding outer measure (so `s` might not be measurable). We can then define the completion of `μ` as the measure on the least `σ`-algebra that also contains all null sets, by defining the measure to be `0` on the null sets. ## Main statements * `completion` is the completion of a measure to all null measurable sets. * `Measure.ofMeasurable` and `OuterMeasure.toMeasure` are two important ways to define a measure. ## Implementation notes Given `μ : Measure α`, `μ s` is the value of the *outer measure* applied to `s`. This conveniently allows us to apply the measure to sets without proving that they are measurable. We get countable subadditivity for all sets, but only countable additivity for measurable sets. You often don't want to define a measure via its constructor. Two ways that are sometimes more convenient: * `Measure.ofMeasurable` is a way to define a measure by only giving its value on measurable sets and proving the properties (1) and (2) mentioned above. * `OuterMeasure.toMeasure` is a way of obtaining a measure from an outer measure by showing that all measurable sets in the measurable space are Carathéodory measurable. To prove that two measures are equal, there are multiple options: * `ext`: two measures are equal if they are equal on all measurable sets. * `ext_of_generateFrom_of_iUnion`: two measures are equal if they are equal on a π-system generating the measurable sets, if the π-system contains a spanning increasing sequence of sets where the measures take finite value (in particular the measures are σ-finite). This is a special case of the more general `ext_of_generateFrom_of_cover` * `ext_of_generate_finite`: two finite measures are equal if they are equal on a π-system generating the measurable sets. This is a special case of `ext_of_generateFrom_of_iUnion` using `C ∪ {univ}`, but is easier to work with. A `MeasureSpace` is a class that is a measurable space with a canonical measure. The measure is denoted `volume`. ## References * <https://en.wikipedia.org/wiki/Measure_(mathematics)> * <https://en.wikipedia.org/wiki/Complete_measure> * <https://en.wikipedia.org/wiki/Almost_everywhere> ## Tags measure, almost everywhere, measure space, completion, null set, null measurable set -/ noncomputable section open Set open Filter hiding map open Function MeasurableSpace Topology Filter ENNReal NNReal Interval MeasureTheory open scoped symmDiff variable {α β γ δ ι R R' : Type*} namespace MeasureTheory section variable {m : MeasurableSpace α} {μ μ₁ μ₂ : Measure α} {s s₁ s₂ t : Set α} instance ae_isMeasurablyGenerated : IsMeasurablyGenerated (ae μ) := ⟨fun _s hs => let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩ /-- See also `MeasureTheory.ae_restrict_uIoc_iff`. -/ theorem ae_uIoc_iff [LinearOrder α] {a b : α} {P : α → Prop} : (∀ᵐ x ∂μ, x ∈ Ι a b → P x) ↔ (∀ᵐ x ∂μ, x ∈ Ioc a b → P x) ∧ ∀ᵐ x ∂μ, x ∈ Ioc b a → P x := by simp only [uIoc_eq_union, mem_union, or_imp, eventually_and] theorem measure_union (hd : Disjoint s₁ s₂) (h : MeasurableSet s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀ h.nullMeasurableSet hd.aedisjoint theorem measure_union' (hd : Disjoint s₁ s₂) (h : MeasurableSet s₁) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := measure_union₀' h.nullMeasurableSet hd.aedisjoint theorem measure_inter_add_diff (s : Set α) (ht : MeasurableSet t) : μ (s ∩ t) + μ (s \ t) = μ s := measure_inter_add_diff₀ _ ht.nullMeasurableSet theorem measure_diff_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s \ t) + μ (s ∩ t) = μ s := (add_comm _ _).trans (measure_inter_add_diff s ht) theorem measure_diff_eq_top (hs : μ s = ∞) (ht : μ t ≠ ∞) : μ (s \ t) = ∞ := by contrapose! hs exact ((measure_mono (subset_diff_union s t)).trans_lt ((measure_union_le _ _).trans_lt (ENNReal.add_lt_top.2 ⟨hs.lt_top, ht.lt_top⟩))).ne theorem measure_union_add_inter (s : Set α) (ht : MeasurableSet t) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [← measure_inter_add_diff (s ∪ t) ht, Set.union_inter_cancel_right, union_diff_right, ← measure_inter_add_diff s ht] ac_rfl theorem measure_union_add_inter' (hs : MeasurableSet s) (t : Set α) : μ (s ∪ t) + μ (s ∩ t) = μ s + μ t := by rw [union_comm, inter_comm, measure_union_add_inter t hs, add_comm] lemma measure_symmDiff_eq (hs : NullMeasurableSet s μ) (ht : NullMeasurableSet t μ) : μ (s ∆ t) = μ (s \ t) + μ (t \ s) := by simpa only [symmDiff_def, sup_eq_union] using measure_union₀ (ht.diff hs) disjoint_sdiff_sdiff.aedisjoint lemma measure_symmDiff_le (s t u : Set α) : μ (s ∆ u) ≤ μ (s ∆ t) + μ (t ∆ u) := le_trans (μ.mono <| symmDiff_triangle s t u) (measure_union_le (s ∆ t) (t ∆ u)) theorem measure_symmDiff_eq_top (hs : μ s ≠ ∞) (ht : μ t = ∞) : μ (s ∆ t) = ∞ := measure_mono_top subset_union_right (measure_diff_eq_top ht hs) theorem measure_add_measure_compl (h : MeasurableSet s) : μ s + μ sᶜ = μ univ := measure_add_measure_compl₀ h.nullMeasurableSet theorem measure_biUnion₀ {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.Pairwise (AEDisjoint μ on f)) (h : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := by haveI := hs.toEncodable rw [biUnion_eq_iUnion] exact measure_iUnion₀ (hd.on_injective Subtype.coe_injective fun x => x.2) fun x => h x x.2 theorem measure_biUnion {s : Set β} {f : β → Set α} (hs : s.Countable) (hd : s.PairwiseDisjoint f) (h : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑' p : s, μ (f p) := measure_biUnion₀ hs hd.aedisjoint fun b hb => (h b hb).nullMeasurableSet theorem measure_sUnion₀ {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise (AEDisjoint μ)) (h : ∀ s ∈ S, NullMeasurableSet s μ) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion₀ hs hd h] theorem measure_sUnion {S : Set (Set α)} (hs : S.Countable) (hd : S.Pairwise Disjoint) (h : ∀ s ∈ S, MeasurableSet s) : μ (⋃₀ S) = ∑' s : S, μ s := by rw [sUnion_eq_biUnion, measure_biUnion hs hd h] theorem measure_biUnion_finset₀ {s : Finset ι} {f : ι → Set α} (hd : Set.Pairwise (↑s) (AEDisjoint μ on f)) (hm : ∀ b ∈ s, NullMeasurableSet (f b) μ) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := by rw [← Finset.sum_attach, Finset.attach_eq_univ, ← tsum_fintype] exact measure_biUnion₀ s.countable_toSet hd hm theorem measure_biUnion_finset {s : Finset ι} {f : ι → Set α} (hd : PairwiseDisjoint (↑s) f) (hm : ∀ b ∈ s, MeasurableSet (f b)) : μ (⋃ b ∈ s, f b) = ∑ p ∈ s, μ (f p) := measure_biUnion_finset₀ hd.aedisjoint fun b hb => (hm b hb).nullMeasurableSet /-- The measure of an a.e. disjoint union (even uncountable) of null-measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint₀ {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, NullMeasurableSet (As i) μ) (As_disj : Pairwise (AEDisjoint μ on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := by rw [ENNReal.tsum_eq_iSup_sum, iSup_le_iff] intro s simp only [← measure_biUnion_finset₀ (fun _i _hi _j _hj hij => As_disj hij) fun i _ => As_mble i] gcongr exact iUnion_subset fun _ ↦ Subset.rfl /-- The measure of a disjoint union (even uncountable) of measurable sets is at least the sum of the measures of the sets. -/ theorem tsum_meas_le_meas_iUnion_of_disjoint {ι : Type*} {_ : MeasurableSpace α} (μ : Measure α) {As : ι → Set α} (As_mble : ∀ i : ι, MeasurableSet (As i)) (As_disj : Pairwise (Disjoint on As)) : (∑' i, μ (As i)) ≤ μ (⋃ i, As i) := tsum_meas_le_meas_iUnion_of_disjoint₀ μ (fun i ↦ (As_mble i).nullMeasurableSet) (fun _ _ h ↦ Disjoint.aedisjoint (As_disj h)) /-- If `s` is a countable set, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem tsum_measure_preimage_singleton {s : Set β} (hs : s.Countable) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑' b : s, μ (f ⁻¹' {↑b})) = μ (f ⁻¹' s) := by rw [← Set.biUnion_preimage_singleton, measure_biUnion hs (pairwiseDisjoint_fiber f s) hf] lemma measure_preimage_eq_zero_iff_of_countable {s : Set β} {f : α → β} (hs : s.Countable) : μ (f ⁻¹' s) = 0 ↔ ∀ x ∈ s, μ (f ⁻¹' {x}) = 0 := by rw [← biUnion_preimage_singleton, measure_biUnion_null_iff hs] /-- If `s` is a `Finset`, then the measure of its preimage can be found as the sum of measures of the fibers `f ⁻¹' {y}`. -/ theorem sum_measure_preimage_singleton (s : Finset β) {f : α → β} (hf : ∀ y ∈ s, MeasurableSet (f ⁻¹' {y})) : (∑ b ∈ s, μ (f ⁻¹' {b})) = μ (f ⁻¹' ↑s) := by simp only [← measure_biUnion_finset (pairwiseDisjoint_fiber f s) hf, Finset.set_biUnion_preimage_singleton] @[simp] lemma sum_measure_singleton {s : Finset α} [MeasurableSingletonClass α] : ∑ x ∈ s, μ {x} = μ s := by trans ∑ x ∈ s, μ (id ⁻¹' {x}) · simp rw [sum_measure_preimage_singleton] · simp · simp theorem measure_diff_null' (h : μ (s₁ ∩ s₂) = 0) : μ (s₁ \ s₂) = μ s₁ := measure_congr <| diff_ae_eq_self.2 h theorem measure_add_diff (hs : NullMeasurableSet s μ) (t : Set α) : μ s + μ (t \ s) = μ (s ∪ t) := by rw [← measure_union₀' hs disjoint_sdiff_right.aedisjoint, union_diff_self] theorem measure_diff' (s : Set α) (hm : NullMeasurableSet t μ) (h_fin : μ t ≠ ∞) : μ (s \ t) = μ (s ∪ t) - μ t := ENNReal.eq_sub_of_add_eq h_fin <| by rw [add_comm, measure_add_diff hm, union_comm] theorem measure_diff (h : s₂ ⊆ s₁) (h₂ : NullMeasurableSet s₂ μ) (h_fin : μ s₂ ≠ ∞) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := by rw [measure_diff' _ h₂ h_fin, union_eq_self_of_subset_right h] theorem le_measure_diff : μ s₁ - μ s₂ ≤ μ (s₁ \ s₂) := tsub_le_iff_left.2 <| (measure_le_inter_add_diff μ s₁ s₂).trans <| by gcongr; apply inter_subset_right /-- If the measure of the symmetric difference of two sets is finite, then one has infinite measure if and only if the other one does. -/ theorem measure_eq_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s = ∞ ↔ μ t = ∞ := by suffices h : ∀ u v, μ (u ∆ v) ≠ ∞ → μ u = ∞ → μ v = ∞ from ⟨h s t hμst, h t s (symmDiff_comm s t ▸ hμst)⟩ intro u v hμuv hμu by_contra! hμv apply hμuv rw [Set.symmDiff_def, eq_top_iff] calc ∞ = μ u - μ v := by rw [ENNReal.sub_eq_top_iff.2 ⟨hμu, hμv⟩] _ ≤ μ (u \ v) := le_measure_diff _ ≤ μ (u \ v ∪ v \ u) := measure_mono subset_union_left /-- If the measure of the symmetric difference of two sets is finite, then one has finite measure if and only if the other one does. -/ theorem measure_ne_top_iff_of_symmDiff (hμst : μ (s ∆ t) ≠ ∞) : μ s ≠ ∞ ↔ μ t ≠ ∞ := (measure_eq_top_iff_of_symmDiff hμst).ne theorem measure_diff_lt_of_lt_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} (h : μ t < μ s + ε) : μ (t \ s) < ε := by rw [measure_diff hst hs hs']; rw [add_comm] at h exact ENNReal.sub_lt_of_lt_add (measure_mono hst) h theorem measure_diff_le_iff_le_add (hs : NullMeasurableSet s μ) (hst : s ⊆ t) (hs' : μ s ≠ ∞) {ε : ℝ≥0∞} : μ (t \ s) ≤ ε ↔ μ t ≤ μ s + ε := by rw [measure_diff hst hs hs', tsub_le_iff_left] theorem measure_eq_measure_of_null_diff {s t : Set α} (hst : s ⊆ t) (h_nulldiff : μ (t \ s) = 0) : μ s = μ t := measure_congr <| EventuallyLE.antisymm (HasSubset.Subset.eventuallyLE hst) (ae_le_set.mpr h_nulldiff) theorem measure_eq_measure_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ ∧ μ s₂ = μ s₃ := by have le12 : μ s₁ ≤ μ s₂ := measure_mono h12 have le23 : μ s₂ ≤ μ s₃ := measure_mono h23 have key : μ s₃ ≤ μ s₁ := calc μ s₃ = μ (s₃ \ s₁ ∪ s₁) := by rw [diff_union_of_subset (h12.trans h23)] _ ≤ μ (s₃ \ s₁) + μ s₁ := measure_union_le _ _ _ = μ s₁ := by simp only [h_nulldiff, zero_add] exact ⟨le12.antisymm (le23.trans key), le23.antisymm (key.trans le12)⟩ theorem measure_eq_measure_smaller_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₁ = μ s₂ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).1 theorem measure_eq_measure_larger_of_between_null_diff {s₁ s₂ s₃ : Set α} (h12 : s₁ ⊆ s₂) (h23 : s₂ ⊆ s₃) (h_nulldiff : μ (s₃ \ s₁) = 0) : μ s₂ = μ s₃ := (measure_eq_measure_of_between_null_diff h12 h23 h_nulldiff).2 lemma measure_compl₀ (h : NullMeasurableSet s μ) (hs : μ s ≠ ∞) : μ sᶜ = μ Set.univ - μ s := by rw [← measure_add_measure_compl₀ h, ENNReal.add_sub_cancel_left hs] theorem measure_compl (h₁ : MeasurableSet s) (h_fin : μ s ≠ ∞) : μ sᶜ = μ univ - μ s := measure_compl₀ h₁.nullMeasurableSet h_fin lemma measure_inter_conull' (ht : μ (s \ t) = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null']; rwa [← diff_eq] lemma measure_inter_conull (ht : μ tᶜ = 0) : μ (s ∩ t) = μ s := by rw [← diff_compl, measure_diff_null ht] @[simp] theorem union_ae_eq_left_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] s ↔ t ≤ᵐ[μ] s := by rw [ae_le_set] refine ⟨fun h => by simpa only [union_diff_left] using (ae_eq_set.mp h).1, fun h => eventuallyLE_antisymm_iff.mpr ⟨by rwa [ae_le_set, union_diff_left], HasSubset.Subset.eventuallyLE subset_union_left⟩⟩ @[simp] theorem union_ae_eq_right_iff_ae_subset : (s ∪ t : Set α) =ᵐ[μ] t ↔ s ≤ᵐ[μ] t := by rw [union_comm, union_ae_eq_left_iff_ae_subset] theorem ae_eq_of_ae_subset_of_measure_ge (h₁ : s ≤ᵐ[μ] t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := by refine eventuallyLE_antisymm_iff.mpr ⟨h₁, ae_le_set.mpr ?_⟩ replace h₂ : μ t = μ s := h₂.antisymm (measure_mono_ae h₁) replace ht : μ s ≠ ∞ := h₂ ▸ ht rw [measure_diff' t hsm ht, measure_congr (union_ae_eq_left_iff_ae_subset.mpr h₁), h₂, tsub_self] /-- If `s ⊆ t`, `μ t ≤ μ s`, `μ t ≠ ∞`, and `s` is measurable, then `s =ᵐ[μ] t`. -/ theorem ae_eq_of_subset_of_measure_ge (h₁ : s ⊆ t) (h₂ : μ t ≤ μ s) (hsm : NullMeasurableSet s μ) (ht : μ t ≠ ∞) : s =ᵐ[μ] t := ae_eq_of_ae_subset_of_measure_ge (HasSubset.Subset.eventuallyLE h₁) h₂ hsm ht theorem measure_iUnion_congr_of_subset {ι : Sort*} [Countable ι] {s : ι → Set α} {t : ι → Set α} (hsub : ∀ i, s i ⊆ t i) (h_le : ∀ i, μ (t i) ≤ μ (s i)) : μ (⋃ i, s i) = μ (⋃ i, t i) := by refine le_antisymm (by gcongr; apply hsub) ?_ rcases Classical.em (∃ i, μ (t i) = ∞) with (⟨i, hi⟩ | htop) · calc μ (⋃ i, t i) ≤ ∞ := le_top _ ≤ μ (s i) := hi ▸ h_le i _ ≤ μ (⋃ i, s i) := measure_mono <| subset_iUnion _ _ push_neg at htop set M := toMeasurable μ have H : ∀ b, (M (t b) ∩ M (⋃ b, s b) : Set α) =ᵐ[μ] M (t b) := by refine fun b => ae_eq_of_subset_of_measure_ge inter_subset_left ?_ ?_ ?_ · calc μ (M (t b)) = μ (t b) := measure_toMeasurable _ _ ≤ μ (s b) := h_le b _ ≤ μ (M (t b) ∩ M (⋃ b, s b)) := measure_mono <| subset_inter ((hsub b).trans <| subset_toMeasurable _ _) ((subset_iUnion _ _).trans <| subset_toMeasurable _ _) · measurability · rw [measure_toMeasurable] exact htop b calc μ (⋃ b, t b) ≤ μ (⋃ b, M (t b)) := measure_mono (iUnion_mono fun b => subset_toMeasurable _ _) _ = μ (⋃ b, M (t b) ∩ M (⋃ b, s b)) := measure_congr (EventuallyEq.countable_iUnion H).symm _ ≤ μ (M (⋃ b, s b)) := measure_mono (iUnion_subset fun b => inter_subset_right) _ = μ (⋃ b, s b) := measure_toMeasurable _ theorem measure_union_congr_of_subset {t₁ t₂ : Set α} (hs : s₁ ⊆ s₂) (hsμ : μ s₂ ≤ μ s₁) (ht : t₁ ⊆ t₂) (htμ : μ t₂ ≤ μ t₁) : μ (s₁ ∪ t₁) = μ (s₂ ∪ t₂) := by rw [union_eq_iUnion, union_eq_iUnion] exact measure_iUnion_congr_of_subset (Bool.forall_bool.2 ⟨ht, hs⟩) (Bool.forall_bool.2 ⟨htμ, hsμ⟩) @[simp] theorem measure_iUnion_toMeasurable {ι : Sort*} [Countable ι] (s : ι → Set α) : μ (⋃ i, toMeasurable μ (s i)) = μ (⋃ i, s i) := Eq.symm <| measure_iUnion_congr_of_subset (fun _i => subset_toMeasurable _ _) fun _i ↦ (measure_toMeasurable _).le theorem measure_biUnion_toMeasurable {I : Set β} (hc : I.Countable) (s : β → Set α) : μ (⋃ b ∈ I, toMeasurable μ (s b)) = μ (⋃ b ∈ I, s b) := by haveI := hc.toEncodable simp only [biUnion_eq_iUnion, measure_iUnion_toMeasurable] @[simp] theorem measure_toMeasurable_union : μ (toMeasurable μ s ∪ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset (subset_toMeasurable _ _) (measure_toMeasurable _).le Subset.rfl le_rfl @[simp] theorem measure_union_toMeasurable : μ (s ∪ toMeasurable μ t) = μ (s ∪ t) := Eq.symm <| measure_union_congr_of_subset Subset.rfl le_rfl (subset_toMeasurable _ _) (measure_toMeasurable _).le theorem sum_measure_le_measure_univ {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : Set.Pairwise s (AEDisjoint μ on t)) : (∑ i ∈ s, μ (t i)) ≤ μ (univ : Set α) := by rw [← measure_biUnion_finset₀ H h] exact measure_mono (subset_univ _) theorem tsum_measure_le_measure_univ {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (H : Pairwise (AEDisjoint μ on s)) : ∑' i, μ (s i) ≤ μ (univ : Set α) := by rw [ENNReal.tsum_eq_iSup_sum] exact iSup_le fun s => sum_measure_le_measure_univ (fun i _hi => hs i) fun i _hi j _hj hij => H hij /-- Pigeonhole principle for measure spaces: if `∑' i, μ (s i) > μ univ`, then one of the intersections `s i ∩ s j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_tsum_measure {m : MeasurableSpace α} (μ : Measure α) {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (H : μ (univ : Set α) < ∑' i, μ (s i)) : ∃ i j, i ≠ j ∧ (s i ∩ s j).Nonempty := by contrapose! H apply tsum_measure_le_measure_univ hs intro i j hij exact (disjoint_iff_inter_eq_empty.mpr (H i j hij)).aedisjoint /-- Pigeonhole principle for measure spaces: if `s` is a `Finset` and `∑ i ∈ s, μ (t i) > μ univ`, then one of the intersections `t i ∩ t j` is not empty. -/ theorem exists_nonempty_inter_of_measure_univ_lt_sum_measure {m : MeasurableSpace α} (μ : Measure α) {s : Finset ι} {t : ι → Set α} (h : ∀ i ∈ s, NullMeasurableSet (t i) μ) (H : μ (univ : Set α) < ∑ i ∈ s, μ (t i)) : ∃ i ∈ s, ∃ j ∈ s, ∃ _h : i ≠ j, (t i ∩ t j).Nonempty := by contrapose! H apply sum_measure_le_measure_univ h intro i hi j hj hij exact (disjoint_iff_inter_eq_empty.mpr (H i hi j hj hij)).aedisjoint /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `t` is measurable. -/ theorem nonempty_inter_of_measure_lt_add {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (ht : MeasurableSet t) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [← Set.not_disjoint_iff_nonempty_inter] contrapose! h calc μ s + μ t = μ (s ∪ t) := (measure_union h ht).symm _ ≤ μ u := measure_mono (union_subset h's h't) /-- If two sets `s` and `t` are included in a set `u`, and `μ s + μ t > μ u`, then `s` intersects `t`. Version assuming that `s` is measurable. -/ theorem nonempty_inter_of_measure_lt_add' {m : MeasurableSpace α} (μ : Measure α) {s t u : Set α} (hs : MeasurableSet s) (h's : s ⊆ u) (h't : t ⊆ u) (h : μ u < μ s + μ t) : (s ∩ t).Nonempty := by rw [add_comm] at h rw [inter_comm] exact nonempty_inter_of_measure_lt_add μ hs h't h's h /-- Continuity from below: the measure of the union of a directed sequence of (not necessarily measurable) sets is the supremum of the measures. -/ theorem _root_.Directed.measure_iUnion [Countable ι] {s : ι → Set α} (hd : Directed (· ⊆ ·) s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by -- WLOG, `ι = ℕ` rcases Countable.exists_injective_nat ι with ⟨e, he⟩ generalize ht : Function.extend e s ⊥ = t replace hd : Directed (· ⊆ ·) t := ht ▸ hd.extend_bot he suffices μ (⋃ n, t n) = ⨆ n, μ (t n) by simp only [← ht, Function.apply_extend μ, ← iSup_eq_iUnion, iSup_extend_bot he, Function.comp_def, Pi.bot_apply, bot_eq_empty, measure_empty] at this exact this.trans (iSup_extend_bot he _) clear! ι -- The `≥` inequality is trivial refine le_antisymm ?_ (iSup_le fun i ↦ measure_mono <| subset_iUnion _ _) -- Choose `T n ⊇ t n` of the same measure, put `Td n = disjointed T` set T : ℕ → Set α := fun n => toMeasurable μ (t n) set Td : ℕ → Set α := disjointed T have hm : ∀ n, MeasurableSet (Td n) := .disjointed fun n ↦ measurableSet_toMeasurable _ _ calc μ (⋃ n, t n) = μ (⋃ n, Td n) := by rw [iUnion_disjointed, measure_iUnion_toMeasurable] _ ≤ ∑' n, μ (Td n) := measure_iUnion_le _ _ = ⨆ I : Finset ℕ, ∑ n ∈ I, μ (Td n) := ENNReal.tsum_eq_iSup_sum _ ≤ ⨆ n, μ (t n) := iSup_le fun I => by rcases hd.finset_le I with ⟨N, hN⟩ calc (∑ n ∈ I, μ (Td n)) = μ (⋃ n ∈ I, Td n) := (measure_biUnion_finset ((disjoint_disjointed T).set_pairwise I) fun n _ => hm n).symm _ ≤ μ (⋃ n ∈ I, T n) := measure_mono (iUnion₂_mono fun n _hn => disjointed_subset _ _) _ = μ (⋃ n ∈ I, t n) := measure_biUnion_toMeasurable I.countable_toSet _ _ ≤ μ (t N) := measure_mono (iUnion₂_subset hN) _ ≤ ⨆ n, μ (t n) := le_iSup (μ ∘ t) N /-- Continuity from below: the measure of the union of a monotone family of sets is equal to the supremum of their measures. The theorem assumes that the `atTop` filter on the index set is countably generated, so it works for a family indexed by a countable type, as well as `ℝ`. -/ theorem _root_.Monotone.measure_iUnion [Preorder ι] [IsDirected ι (· ≤ ·)] [(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := by cases isEmpty_or_nonempty ι with | inl _ => simp | inr _ => rcases exists_seq_monotone_tendsto_atTop_atTop ι with ⟨x, hxm, hx⟩ rw [← hs.iUnion_comp_tendsto_atTop hx, ← Monotone.iSup_comp_tendsto_atTop _ hx] exacts [(hs.comp hxm).directed_le.measure_iUnion, fun _ _ h ↦ measure_mono (hs h)] theorem _root_.Antitone.measure_iUnion [Preorder ι] [IsDirected ι (· ≥ ·)] [(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) : μ (⋃ i, s i) = ⨆ i, μ (s i) := hs.dual_left.measure_iUnion /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the supremum of the measures of the partial unions. -/ theorem measure_iUnion_eq_iSup_accumulate [Preorder ι] [IsDirected ι (· ≤ ·)] [(atTop : Filter ι).IsCountablyGenerated] {f : ι → Set α} : μ (⋃ i, f i) = ⨆ i, μ (Accumulate f i) := by rw [← iUnion_accumulate] exact monotone_accumulate.measure_iUnion theorem measure_biUnion_eq_iSup {s : ι → Set α} {t : Set ι} (ht : t.Countable) (hd : DirectedOn ((· ⊆ ·) on s) t) : μ (⋃ i ∈ t, s i) = ⨆ i ∈ t, μ (s i) := by haveI := ht.to_subtype rw [biUnion_eq_iUnion, hd.directed_val.measure_iUnion, ← iSup_subtype''] /-- **Continuity from above**: the measure of the intersection of a directed downwards countable family of measurable sets is the infimum of the measures. -/ theorem _root_.Directed.measure_iInter [Countable ι] {s : ι → Set α} (h : ∀ i, NullMeasurableSet (s i) μ) (hd : Directed (· ⊇ ·) s) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by rcases hfin with ⟨k, hk⟩ have : ∀ t ⊆ s k, μ t ≠ ∞ := fun t ht => ne_top_of_le_ne_top hk (measure_mono ht) rw [← ENNReal.sub_sub_cancel hk (iInf_le (fun i => μ (s i)) k), ENNReal.sub_iInf, ← ENNReal.sub_sub_cancel hk (measure_mono (iInter_subset _ k)), ← measure_diff (iInter_subset _ k) (.iInter h) (this _ (iInter_subset _ k)), diff_iInter, Directed.measure_iUnion] · congr 1 refine le_antisymm (iSup_mono' fun i => ?_) (iSup_mono fun i => le_measure_diff) rcases hd i k with ⟨j, hji, hjk⟩ use j rw [← measure_diff hjk (h _) (this _ hjk)] gcongr · exact hd.mono_comp _ fun _ _ => diff_subset_diff_right /-- **Continuity from above**: the measure of the intersection of a monotone family of measurable sets indexed by a type with countably generated `atBot` filter is equal to the infimum of the measures. -/ theorem _root_.Monotone.measure_iInter [Preorder ι] [IsDirected ι (· ≥ ·)] [(atBot : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Monotone s) (hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := by refine le_antisymm (le_iInf fun i ↦ measure_mono <| iInter_subset _ _) ?_ have := hfin.nonempty rcases exists_seq_antitone_tendsto_atTop_atBot ι with ⟨x, hxm, hx⟩ calc ⨅ i, μ (s i) ≤ ⨅ n, μ (s (x n)) := le_iInf_comp (μ ∘ s) x _ = μ (⋂ n, s (x n)) := by refine .symm <| (hs.comp_antitone hxm).directed_ge.measure_iInter (fun n ↦ hsm _) ?_ rcases hfin with ⟨k, hk⟩ rcases (hx.eventually_le_atBot k).exists with ⟨n, hn⟩ exact ⟨n, ne_top_of_le_ne_top hk <| measure_mono <| hs hn⟩ _ ≤ μ (⋂ i, s i) := by refine measure_mono <| iInter_mono' fun i ↦ ?_ rcases (hx.eventually_le_atBot i).exists with ⟨n, hn⟩ exact ⟨n, hs hn⟩ /-- **Continuity from above**: the measure of the intersection of an antitone family of measurable sets indexed by a type with countably generated `atTop` filter is equal to the infimum of the measures. -/ theorem _root_.Antitone.measure_iInter [Preorder ι] [IsDirected ι (· ≤ ·)] [(atTop : Filter ι).IsCountablyGenerated] {s : ι → Set α} (hs : Antitone s) (hsm : ∀ i, NullMeasurableSet (s i) μ) (hfin : ∃ i, μ (s i) ≠ ∞) : μ (⋂ i, s i) = ⨅ i, μ (s i) := hs.dual_left.measure_iInter hsm hfin /-- Continuity from above: the measure of the intersection of a sequence of measurable sets is the infimum of the measures of the partial intersections. -/ theorem measure_iInter_eq_iInf_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [Countable ι] [Preorder ι] [IsDirected ι (· ≤ ·)] {f : ι → Set α} (h : ∀ i, NullMeasurableSet (f i) μ) (hfin : ∃ i, μ (f i) ≠ ∞) : μ (⋂ i, f i) = ⨅ i, μ (⋂ j ≤ i, f j) := by rw [← Antitone.measure_iInter] · rw [iInter_comm] exact congrArg μ <| iInter_congr fun i ↦ (biInf_const nonempty_Ici).symm · exact fun i j h ↦ biInter_mono (Iic_subset_Iic.2 h) fun _ _ ↦ Set.Subset.rfl · exact fun i ↦ .biInter (to_countable _) fun _ _ ↦ h _ · refine hfin.imp fun k hk ↦ ne_top_of_le_ne_top hk <| measure_mono <| iInter₂_subset k ?_ rfl /-- Continuity from below: the measure of the union of an increasing sequence of (not necessarily measurable) sets is the limit of the measures. -/ theorem tendsto_measure_iUnion_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {s : ι → Set α} (hm : Monotone s) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋃ n, s n))) := by refine .of_neBot_imp fun h ↦ ?_ have := (atTop_neBot_iff.1 h).2 rw [hm.measure_iUnion] exact tendsto_atTop_iSup fun n m hnm => measure_mono <| hm hnm theorem tendsto_measure_iUnion_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)] {s : ι → Set α} (hm : Antitone s) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋃ n, s n))) := tendsto_measure_iUnion_atTop (ι := ιᵒᵈ) hm.dual_left /-- Continuity from below: the measure of the union of a sequence of (not necessarily measurable) sets is the limit of the measures of the partial unions. -/ theorem tendsto_measure_iUnion_accumulate {α ι : Type*} [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {_ : MeasurableSpace α} {μ : Measure α} {f : ι → Set α} : Tendsto (fun i ↦ μ (Accumulate f i)) atTop (𝓝 (μ (⋃ i, f i))) := by refine .of_neBot_imp fun h ↦ ?_ have := (atTop_neBot_iff.1 h).2 rw [measure_iUnion_eq_iSup_accumulate] exact tendsto_atTop_iSup fun i j hij ↦ by gcongr /-- Continuity from above: the measure of the intersection of a decreasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter_atTop [Preorder ι] [IsCountablyGenerated (atTop : Filter ι)] {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Antitone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atTop (𝓝 (μ (⋂ n, s n))) := by refine .of_neBot_imp fun h ↦ ?_ have := (atTop_neBot_iff.1 h).2 rw [hm.measure_iInter hs hf] exact tendsto_atTop_iInf fun n m hnm => measure_mono <| hm hnm /-- Continuity from above: the measure of the intersection of an increasing sequence of measurable sets is the limit of the measures. -/ theorem tendsto_measure_iInter_atBot [Preorder ι] [IsCountablyGenerated (atBot : Filter ι)] {s : ι → Set α} (hs : ∀ i, NullMeasurableSet (s i) μ) (hm : Monotone s) (hf : ∃ i, μ (s i) ≠ ∞) : Tendsto (μ ∘ s) atBot (𝓝 (μ (⋂ n, s n))) := tendsto_measure_iInter_atTop (ι := ιᵒᵈ) hs hm.dual_left hf /-- Continuity from above: the measure of the intersection of a sequence of measurable sets such that one has finite measure is the limit of the measures of the partial intersections. -/ theorem tendsto_measure_iInter_le {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [Countable ι] [Preorder ι] {f : ι → Set α} (hm : ∀ i, NullMeasurableSet (f i) μ) (hf : ∃ i, μ (f i) ≠ ∞) : Tendsto (fun i ↦ μ (⋂ j ≤ i, f j)) atTop (𝓝 (μ (⋂ i, f i))) := by refine .of_neBot_imp fun hne ↦ ?_ cases atTop_neBot_iff.mp hne rw [measure_iInter_eq_iInf_measure_iInter_le hm hf] exact tendsto_atTop_iInf fun i j hij ↦ measure_mono <| biInter_subset_biInter_left fun k hki ↦ le_trans hki hij /-- Some version of continuity of a measure in the empty set using the intersection along a set of sets. -/ theorem exists_measure_iInter_lt {α ι : Type*} {_ : MeasurableSpace α} {μ : Measure α} [SemilatticeSup ι] [Countable ι] {f : ι → Set α} (hm : ∀ i, NullMeasurableSet (f i) μ) {ε : ℝ≥0∞} (hε : 0 < ε) (hfin : ∃ i, μ (f i) ≠ ∞) (hfem : ⋂ n, f n = ∅) : ∃ m, μ (⋂ n ≤ m, f n) < ε := by let F m := μ (⋂ n ≤ m, f n) have hFAnti : Antitone F := fun i j hij => measure_mono (biInter_subset_biInter_left fun k hki => le_trans hki hij) suffices Filter.Tendsto F Filter.atTop (𝓝 0) by rw [@ENNReal.tendsto_atTop_zero_iff_lt_of_antitone _ (nonempty_of_exists hfin) _ _ hFAnti] at this exact this ε hε have hzero : μ (⋂ n, f n) = 0 := by simp only [hfem, measure_empty] rw [← hzero] exact tendsto_measure_iInter_le hm hfin /-- The measure of the intersection of a decreasing sequence of measurable sets indexed by a linear order with first countable topology is the limit of the measures. -/ theorem tendsto_measure_biInter_gt {ι : Type*} [LinearOrder ι] [TopologicalSpace ι] [OrderTopology ι] [DenselyOrdered ι] [FirstCountableTopology ι] {s : ι → Set α} {a : ι} (hs : ∀ r > a, NullMeasurableSet (s r) μ) (hm : ∀ i j, a < i → i ≤ j → s i ⊆ s j) (hf : ∃ r > a, μ (s r) ≠ ∞) : Tendsto (μ ∘ s) (𝓝[Ioi a] a) (𝓝 (μ (⋂ r > a, s r))) := by have : (atBot : Filter (Ioi a)).IsCountablyGenerated := by rw [← comap_coe_Ioi_nhdsGT] infer_instance simp_rw [← map_coe_Ioi_atBot, tendsto_map'_iff, ← mem_Ioi, biInter_eq_iInter] apply tendsto_measure_iInter_atBot · rwa [Subtype.forall] · exact fun i j h ↦ hm i j i.2 h · simpa only [Subtype.exists, exists_prop] theorem measure_if {x : β} {t : Set β} {s : Set α} [Decidable (x ∈ t)] : μ (if x ∈ t then s else ∅) = indicator t (fun _ => μ s) x := by split_ifs with h <;> simp [h] end section OuterMeasure variable [ms : MeasurableSpace α] {s t : Set α} /-- Obtain a measure by giving an outer measure where all sets in the σ-algebra are Carathéodory measurable. -/ def OuterMeasure.toMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : Measure α := Measure.ofMeasurable (fun s _ => m s) m.empty fun _f hf hd => m.iUnion_eq_of_caratheodory (fun i => h _ (hf i)) hd theorem le_toOuterMeasure_caratheodory (μ : Measure α) : ms ≤ μ.toOuterMeasure.caratheodory := fun _s hs _t => (measure_inter_add_diff _ hs).symm @[simp] theorem toMeasure_toOuterMeasure (m : OuterMeasure α) (h : ms ≤ m.caratheodory) : (m.toMeasure h).toOuterMeasure = m.trim := rfl @[simp] theorem toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : MeasurableSet s) : m.toMeasure h s = m s := m.trim_eq hs theorem le_toMeasure_apply (m : OuterMeasure α) (h : ms ≤ m.caratheodory) (s : Set α) : m s ≤ m.toMeasure h s := m.le_trim s theorem toMeasure_apply₀ (m : OuterMeasure α) (h : ms ≤ m.caratheodory) {s : Set α} (hs : NullMeasurableSet s (m.toMeasure h)) : m.toMeasure h s = m s := by refine le_antisymm ?_ (le_toMeasure_apply _ _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, hts, htm, heq⟩ calc m.toMeasure h s = m.toMeasure h t := measure_congr heq.symm _ = m t := toMeasure_apply m h htm _ ≤ m s := m.mono hts @[simp] theorem toOuterMeasure_toMeasure {μ : Measure α} : μ.toOuterMeasure.toMeasure (le_toOuterMeasure_caratheodory _) = μ := Measure.ext fun _s => μ.toOuterMeasure.trim_eq @[simp] theorem boundedBy_measure (μ : Measure α) : OuterMeasure.boundedBy μ = μ.toOuterMeasure := μ.toOuterMeasure.boundedBy_eq_self end OuterMeasure section variable {m0 : MeasurableSpace α} {mβ : MeasurableSpace β} [MeasurableSpace γ] variable {μ μ₁ μ₂ μ₃ ν ν' ν₁ ν₂ : Measure α} {s s' t : Set α} namespace Measure /-- If `u` is a superset of `t` with the same (finite) measure (both sets possibly non-measurable), then for any measurable set `s` one also has `μ (t ∩ s) = μ (u ∩ s)`. -/ theorem measure_inter_eq_of_measure_eq {s t u : Set α} (hs : MeasurableSet s) (h : μ t = μ u) (htu : t ⊆ u) (ht_ne_top : μ t ≠ ∞) : μ (t ∩ s) = μ (u ∩ s) := by rw [h] at ht_ne_top refine le_antisymm (by gcongr) ?_ have A : μ (u ∩ s) + μ (u \ s) ≤ μ (t ∩ s) + μ (u \ s) := calc μ (u ∩ s) + μ (u \ s) = μ u := measure_inter_add_diff _ hs _ = μ t := h.symm _ = μ (t ∩ s) + μ (t \ s) := (measure_inter_add_diff _ hs).symm _ ≤ μ (t ∩ s) + μ (u \ s) := by gcongr have B : μ (u \ s) ≠ ∞ := (lt_of_le_of_lt (measure_mono diff_subset) ht_ne_top.lt_top).ne exact ENNReal.le_of_add_le_add_right B A /-- The measurable superset `toMeasurable μ t` of `t` (which has the same measure as `t`) satisfies, for any measurable set `s`, the equality `μ (toMeasurable μ t ∩ s) = μ (u ∩ s)`. Here, we require that the measure of `t` is finite. The conclusion holds without this assumption when the measure is s-finite (for example when it is σ-finite), see `measure_toMeasurable_inter_of_sFinite`. -/ theorem measure_toMeasurable_inter {s t : Set α} (hs : MeasurableSet s) (ht : μ t ≠ ∞) : μ (toMeasurable μ t ∩ s) = μ (t ∩ s) := (measure_inter_eq_of_measure_eq hs (measure_toMeasurable t).symm (subset_toMeasurable μ t) ht).symm /-! ### The `ℝ≥0∞`-module of measures -/ instance instZero {_ : MeasurableSpace α} : Zero (Measure α) := ⟨{ toOuterMeasure := 0 m_iUnion := fun _f _hf _hd => tsum_zero.symm trim_le := OuterMeasure.trim_zero.le }⟩ @[simp] theorem zero_toOuterMeasure {_m : MeasurableSpace α} : (0 : Measure α).toOuterMeasure = 0 := rfl @[simp, norm_cast] theorem coe_zero {_m : MeasurableSpace α} : ⇑(0 : Measure α) = 0 := rfl @[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_zero [ms : MeasurableSpace α] (h : ms ≤ (0 : OuterMeasure α).caratheodory) : (0 : OuterMeasure α).toMeasure h = 0 := by ext s hs simp [hs] @[simp] lemma _root_.MeasureTheory.OuterMeasure.toMeasure_eq_zero {ms : MeasurableSpace α} {μ : OuterMeasure α} (h : ms ≤ μ.caratheodory) : μ.toMeasure h = 0 ↔ μ = 0 where mp hμ := by ext s; exact le_bot_iff.1 <| (le_toMeasure_apply _ _ _).trans_eq congr($hμ s) mpr := by rintro rfl; simp @[nontriviality] lemma apply_eq_zero_of_isEmpty [IsEmpty α] {_ : MeasurableSpace α} (μ : Measure α) (s : Set α) : μ s = 0 := by rw [eq_empty_of_isEmpty s, measure_empty] instance instSubsingleton [IsEmpty α] {m : MeasurableSpace α} : Subsingleton (Measure α) := ⟨fun μ ν => by ext1 s _; rw [apply_eq_zero_of_isEmpty, apply_eq_zero_of_isEmpty]⟩ theorem eq_zero_of_isEmpty [IsEmpty α] {_m : MeasurableSpace α} (μ : Measure α) : μ = 0 := Subsingleton.elim μ 0 instance instInhabited {_ : MeasurableSpace α} : Inhabited (Measure α) := ⟨0⟩ instance instAdd {_ : MeasurableSpace α} : Add (Measure α) := ⟨fun μ₁ μ₂ => { toOuterMeasure := μ₁.toOuterMeasure + μ₂.toOuterMeasure m_iUnion := fun s hs hd => show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑' i, (μ₁ (s i) + μ₂ (s i)) by rw [ENNReal.tsum_add, measure_iUnion hd hs, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ @[simp] theorem add_toOuterMeasure {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : (μ₁ + μ₂).toOuterMeasure = μ₁.toOuterMeasure + μ₂.toOuterMeasure := rfl @[simp, norm_cast] theorem coe_add {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) : ⇑(μ₁ + μ₂) = μ₁ + μ₂ := rfl theorem add_apply {_m : MeasurableSpace α} (μ₁ μ₂ : Measure α) (s : Set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl section SMul variable [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] variable [SMul R' ℝ≥0∞] [IsScalarTower R' ℝ≥0∞ ℝ≥0∞] instance instSMul {_ : MeasurableSpace α} : SMul R (Measure α) := ⟨fun c μ => { toOuterMeasure := c • μ.toOuterMeasure m_iUnion := fun s hs hd => by simp only [OuterMeasure.smul_apply, coe_toOuterMeasure, ENNReal.tsum_const_smul, measure_iUnion hd hs] trim_le := by rw [OuterMeasure.trim_smul, μ.trimmed] }⟩ @[simp] theorem smul_toOuterMeasure {_m : MeasurableSpace α} (c : R) (μ : Measure α) : (c • μ).toOuterMeasure = c • μ.toOuterMeasure := rfl @[simp, norm_cast] theorem coe_smul {_m : MeasurableSpace α} (c : R) (μ : Measure α) : ⇑(c • μ) = c • ⇑μ := rfl @[simp] theorem smul_apply {_m : MeasurableSpace α} (c : R) (μ : Measure α) (s : Set α) : (c • μ) s = c • μ s := rfl instance instSMulCommClass [SMulCommClass R R' ℝ≥0∞] {_ : MeasurableSpace α} : SMulCommClass R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_comm _ _ _⟩ instance instIsScalarTower [SMul R R'] [IsScalarTower R R' ℝ≥0∞] {_ : MeasurableSpace α} : IsScalarTower R R' (Measure α) := ⟨fun _ _ _ => ext fun _ _ => smul_assoc _ _ _⟩ instance instIsCentralScalar [SMul Rᵐᵒᵖ ℝ≥0∞] [IsCentralScalar R ℝ≥0∞] {_ : MeasurableSpace α} : IsCentralScalar R (Measure α) := ⟨fun _ _ => ext fun _ _ => op_smul_eq_smul _ _⟩ end SMul instance instNoZeroSMulDivisors [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] : NoZeroSMulDivisors R (Measure α) where eq_zero_or_eq_zero_of_smul_eq_zero h := by simpa [Ne, ext_iff', forall_or_left] using h instance instMulAction [Monoid R] [MulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {_ : MeasurableSpace α} : MulAction R (Measure α) := Injective.mulAction _ toOuterMeasure_injective smul_toOuterMeasure instance instAddCommMonoid {_ : MeasurableSpace α} : AddCommMonoid (Measure α) := toOuterMeasure_injective.addCommMonoid toOuterMeasure zero_toOuterMeasure add_toOuterMeasure fun _ _ => smul_toOuterMeasure _ _ /-- Coercion to function as an additive monoid homomorphism. -/ def coeAddHom {_ : MeasurableSpace α} : Measure α →+ Set α → ℝ≥0∞ where toFun := (⇑) map_zero' := coe_zero map_add' := coe_add @[simp] theorem coeAddHom_apply {_ : MeasurableSpace α} (μ : Measure α) : coeAddHom μ = ⇑μ := rfl @[simp] theorem coe_finset_sum {_m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) : ⇑(∑ i ∈ I, μ i) = ∑ i ∈ I, ⇑(μ i) := map_sum coeAddHom μ I theorem finset_sum_apply {m : MeasurableSpace α} (I : Finset ι) (μ : ι → Measure α) (s : Set α) : (∑ i ∈ I, μ i) s = ∑ i ∈ I, μ i s := by rw [coe_finset_sum, Finset.sum_apply] instance instDistribMulAction [Monoid R] [DistribMulAction R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {_ : MeasurableSpace α} : DistribMulAction R (Measure α) := Injective.distribMulAction ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure instance instModule [Semiring R] [Module R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] {_ : MeasurableSpace α} : Module R (Measure α) := Injective.module R ⟨⟨toOuterMeasure, zero_toOuterMeasure⟩, add_toOuterMeasure⟩ toOuterMeasure_injective smul_toOuterMeasure @[simp] theorem coe_nnreal_smul_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : (c • μ) s = c * μ s := rfl @[simp] theorem nnreal_smul_coe_apply {_m : MeasurableSpace α} (c : ℝ≥0) (μ : Measure α) (s : Set α) : c • μ s = c * μ s := by rfl theorem ae_smul_measure {p : α → Prop} [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (h : ∀ᵐ x ∂μ, p x) (c : R) : ∀ᵐ x ∂c • μ, p x := ae_iff.2 <| by rw [smul_apply, ae_iff.1 h, ← smul_one_smul ℝ≥0∞, smul_zero] theorem ae_smul_measure_le [SMul R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] (c : R) : ae (c • μ) ≤ ae μ := fun _ h ↦ ae_smul_measure h c section SMulWithZero variable {R : Type*} [Zero R] [SMulWithZero R ℝ≥0∞] [IsScalarTower R ℝ≥0∞ ℝ≥0∞] [NoZeroSMulDivisors R ℝ≥0∞] {c : R} {p : α → Prop} lemma ae_smul_measure_iff (hc : c ≠ 0) {μ : Measure α} : (∀ᵐ x ∂c • μ, p x) ↔ ∀ᵐ x ∂μ, p x := by simp [ae_iff, hc] @[simp] lemma ae_smul_measure_eq (hc : c ≠ 0) (μ : Measure α) : ae (c • μ) = ae μ := by ext; exact ae_smul_measure_iff hc end SMulWithZero theorem measure_eq_left_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : μ s = μ t := by refine le_antisymm (measure_mono h') ?_ have : μ t + ν t ≤ μ s + ν t := calc μ t + ν t = μ s + ν s := h''.symm _ ≤ μ s + ν t := by gcongr apply ENNReal.le_of_add_le_add_right _ this exact ne_top_of_le_ne_top h (le_add_left le_rfl) theorem measure_eq_right_of_subset_of_measure_add_eq {s t : Set α} (h : (μ + ν) t ≠ ∞) (h' : s ⊆ t) (h'' : (μ + ν) s = (μ + ν) t) : ν s = ν t := by rw [add_comm] at h'' h exact measure_eq_left_of_subset_of_measure_add_eq h h' h'' theorem measure_toMeasurable_add_inter_left {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : μ (toMeasurable (μ + ν) t ∩ s) = μ (t ∩ s) := by refine (measure_inter_eq_of_measure_eq hs ?_ (subset_toMeasurable _ _) ?_).symm · refine measure_eq_left_of_subset_of_measure_add_eq ?_ (subset_toMeasurable _ _) (measure_toMeasurable t).symm rwa [measure_toMeasurable t] · simp only [not_or, ENNReal.add_eq_top, Pi.add_apply, Ne, coe_add] at ht exact ht.1 theorem measure_toMeasurable_add_inter_right {s t : Set α} (hs : MeasurableSet s) (ht : (μ + ν) t ≠ ∞) : ν (toMeasurable (μ + ν) t ∩ s) = ν (t ∩ s) := by rw [add_comm] at ht ⊢ exact measure_toMeasurable_add_inter_left hs ht /-! ### The complete lattice of measures -/ /-- Measures are partially ordered. -/ instance instPartialOrder {_ : MeasurableSpace α} : PartialOrder (Measure α) where le m₁ m₂ := ∀ s, m₁ s ≤ m₂ s le_refl _ _ := le_rfl le_trans _ _ _ h₁ h₂ s := le_trans (h₁ s) (h₂ s) le_antisymm _ _ h₁ h₂ := ext fun s _ => le_antisymm (h₁ s) (h₂ s) theorem toOuterMeasure_le : μ₁.toOuterMeasure ≤ μ₂.toOuterMeasure ↔ μ₁ ≤ μ₂ := .rfl theorem le_iff : μ₁ ≤ μ₂ ↔ ∀ s, MeasurableSet s → μ₁ s ≤ μ₂ s := outerMeasure_le_iff theorem le_intro (h : ∀ s, MeasurableSet s → s.Nonempty → μ₁ s ≤ μ₂ s) : μ₁ ≤ μ₂ := le_iff.2 fun s hs ↦ s.eq_empty_or_nonempty.elim (by rintro rfl; simp) (h s hs) theorem le_iff' : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := .rfl theorem lt_iff : μ < ν ↔ μ ≤ ν ∧ ∃ s, MeasurableSet s ∧ μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff, not_forall, not_le, exists_prop] theorem lt_iff' : μ < ν ↔ μ ≤ ν ∧ ∃ s, μ s < ν s := lt_iff_le_not_le.trans <| and_congr Iff.rfl <| by simp only [le_iff', not_forall, not_le] instance instAddLeftMono {_ : MeasurableSpace α} : AddLeftMono (Measure α) := ⟨fun _ν _μ₁ _μ₂ hμ s => add_le_add_left (hμ s) _⟩ protected theorem le_add_left (h : μ ≤ ν) : μ ≤ ν' + ν := fun s => le_add_left (h s) protected theorem le_add_right (h : μ ≤ ν) : μ ≤ ν + ν' := fun s => le_add_right (h s) section sInf variable {m : Set (Measure α)} theorem sInf_caratheodory (s : Set α) (hs : MeasurableSet s) : MeasurableSet[(sInf (toOuterMeasure '' m)).caratheodory] s := by rw [OuterMeasure.sInf_eq_boundedBy_sInfGen] refine OuterMeasure.boundedBy_caratheodory fun t => ?_ simp only [OuterMeasure.sInfGen, le_iInf_iff, forall_mem_image, measure_eq_iInf t, coe_toOuterMeasure] intro μ hμ u htu _hu have hm : ∀ {s t}, s ⊆ t → OuterMeasure.sInfGen (toOuterMeasure '' m) s ≤ μ t := by intro s t hst rw [OuterMeasure.sInfGen_def, iInf_image] exact iInf₂_le_of_le μ hμ <| measure_mono hst rw [← measure_inter_add_diff u hs] exact add_le_add (hm <| inter_subset_inter_left _ htu) (hm <| diff_subset_diff_left htu) instance {_ : MeasurableSpace α} : InfSet (Measure α) := ⟨fun m => (sInf (toOuterMeasure '' m)).toMeasure <| sInf_caratheodory⟩ theorem sInf_apply (hs : MeasurableSet s) : sInf m s = sInf (toOuterMeasure '' m) s := toMeasure_apply _ _ hs private theorem measure_sInf_le (h : μ ∈ m) : sInf m ≤ μ := have : sInf (toOuterMeasure '' m) ≤ μ.toOuterMeasure := sInf_le (mem_image_of_mem _ h) le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s private theorem measure_le_sInf (h : ∀ μ' ∈ m, μ ≤ μ') : μ ≤ sInf m := have : μ.toOuterMeasure ≤ sInf (toOuterMeasure '' m) := le_sInf <| forall_mem_image.2 fun _ hμ ↦ toOuterMeasure_le.2 <| h _ hμ le_iff.2 fun s hs => by rw [sInf_apply hs]; exact this s instance instCompleteSemilatticeInf {_ : MeasurableSpace α} : CompleteSemilatticeInf (Measure α) := { (by infer_instance : PartialOrder (Measure α)), (by infer_instance : InfSet (Measure α)) with sInf_le := fun _s _a => measure_sInf_le le_sInf := fun _s _a => measure_le_sInf } instance instCompleteLattice {_ : MeasurableSpace α} : CompleteLattice (Measure α) := { completeLatticeOfCompleteSemilatticeInf (Measure α) with top := { toOuterMeasure := ⊤, m_iUnion := by intro f _ _ refine (measure_iUnion_le _).antisymm ?_ if hne : (⋃ i, f i).Nonempty then rw [OuterMeasure.top_apply hne] exact le_top else simp_all [Set.not_nonempty_iff_eq_empty] trim_le := le_top }, le_top := fun _ => toOuterMeasure_le.mp le_top bot := 0 bot_le := fun _a _s => bot_le } end sInf lemma inf_apply {s : Set α} (hs : MeasurableSet s) : (μ ⊓ ν) s = sInf {m | ∃ t, m = μ (t ∩ s) + ν (tᶜ ∩ s)} := by -- `(μ ⊓ ν) s` is defined as `⊓ (t : ℕ → Set α) (ht : s ⊆ ⋃ n, t n), ∑' n, μ (t n) ⊓ ν (t n)` rw [← sInf_pair, Measure.sInf_apply hs, OuterMeasure.sInf_apply (image_nonempty.2 <| insert_nonempty μ {ν})] refine le_antisymm (le_sInf fun m ⟨t, ht₁⟩ ↦ ?_) (le_iInf₂ fun t' ht' ↦ ?_) · subst ht₁ -- We first show `(μ ⊓ ν) s ≤ μ (t ∩ s) + ν (tᶜ ∩ s)` for any `t : Set α` -- For this, define the sequence `t' : ℕ → Set α` where `t' 0 = t ∩ s`, `t' 1 = tᶜ ∩ s` and -- `∅` otherwise. Then, we have by construction -- `(μ ⊓ ν) s ≤ ∑' n, μ (t' n) ⊓ ν (t' n) ≤ μ (t' 0) + ν (t' 1) = μ (t ∩ s) + ν (tᶜ ∩ s)`. set t' : ℕ → Set α := fun n ↦ if n = 0 then t ∩ s else if n = 1 then tᶜ ∩ s else ∅ with ht' refine (iInf₂_le t' fun x hx ↦ ?_).trans ?_ · by_cases hxt : x ∈ t · refine mem_iUnion.2 ⟨0, ?_⟩ simp [hx, hxt] · refine mem_iUnion.2 ⟨1, ?_⟩ simp [hx, hxt] · simp only [iInf_image, coe_toOuterMeasure, iInf_pair] rw [tsum_eq_add_tsum_ite 0, tsum_eq_add_tsum_ite 1, if_neg zero_ne_one.symm, ENNReal.summable.tsum_eq_zero_iff.2 _, add_zero] · exact add_le_add (inf_le_left.trans <| by simp [ht']) (inf_le_right.trans <| by simp [ht']) · simp only [ite_eq_left_iff] intro n hn₁ hn₀ simp only [ht', if_neg hn₀, if_neg hn₁, measure_empty, iInf_pair, le_refl, inf_of_le_left] · simp only [iInf_image, coe_toOuterMeasure, iInf_pair] -- Conversely, fixing `t' : ℕ → Set α` such that `s ⊆ ⋃ n, t' n`, we construct `t : Set α` -- for which `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n)`. -- Denoting `I := {n | μ (t' n) ≤ ν (t' n)}`, we set `t = ⋃ n ∈ I, t' n`. -- Clearly `μ (t ∩ s) ≤ ∑' n ∈ I, μ (t' n)` and `ν (tᶜ ∩ s) ≤ ∑' n ∉ I, ν (t' n)`, so -- `μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n ∈ I, μ (t' n) + ∑' n ∉ I, ν (t' n)` -- where the RHS equals `∑' n, μ (t' n) ⊓ ν (t' n)` by the choice of `I`. set t := ⋃ n ∈ {k : ℕ | μ (t' k) ≤ ν (t' k)}, t' n with ht suffices hadd : μ (t ∩ s) + ν (tᶜ ∩ s) ≤ ∑' n, μ (t' n) ⊓ ν (t' n) by exact le_trans (sInf_le ⟨t, rfl⟩) hadd have hle₁ : μ (t ∩ s) ≤ ∑' (n : {k | μ (t' k) ≤ ν (t' k)}), μ (t' n) := (measure_mono inter_subset_left).trans <| measure_biUnion_le _ (to_countable _) _ have hcap : tᶜ ∩ s ⊆ ⋃ n ∈ {k | ν (t' k) < μ (t' k)}, t' n := by simp_rw [ht, compl_iUnion] refine fun x ⟨hx₁, hx₂⟩ ↦ mem_iUnion₂.2 ?_ obtain ⟨i, hi⟩ := mem_iUnion.1 <| ht' hx₂ refine ⟨i, ?_, hi⟩ by_contra h simp only [mem_setOf_eq, not_lt] at h exact mem_iInter₂.1 hx₁ i h hi have hle₂ : ν (tᶜ ∩ s) ≤ ∑' (n : {k | ν (t' k) < μ (t' k)}), ν (t' n) := (measure_mono hcap).trans (measure_biUnion_le ν (to_countable {k | ν (t' k) < μ (t' k)}) _) refine (add_le_add hle₁ hle₂).trans ?_ have heq : {k | μ (t' k) ≤ ν (t' k)} ∪ {k | ν (t' k) < μ (t' k)} = univ := by ext k; simp [le_or_lt] conv in ∑' (n : ℕ), μ (t' n) ⊓ ν (t' n) => rw [← tsum_univ, ← heq] rw [ENNReal.summable.tsum_union_disjoint (f := fun n ↦ μ (t' n) ⊓ ν (t' n)) ?_ ENNReal.summable] · refine add_le_add (tsum_congr ?_).le (tsum_congr ?_).le · rw [Subtype.forall] intro n hn; simpa · rw [Subtype.forall] intro n hn rw [mem_setOf_eq] at hn simp [le_of_lt hn] · rw [Set.disjoint_iff] rintro k ⟨hk₁, hk₂⟩ rw [mem_setOf_eq] at hk₁ hk₂ exact False.elim <| hk₂.not_le hk₁ @[simp] theorem _root_.MeasureTheory.OuterMeasure.toMeasure_top : (⊤ : OuterMeasure α).toMeasure (by rw [OuterMeasure.top_caratheodory]; exact le_top) = (⊤ : Measure α) := toOuterMeasure_toMeasure (μ := ⊤) @[simp] theorem toOuterMeasure_top {_ : MeasurableSpace α} : (⊤ : Measure α).toOuterMeasure = (⊤ : OuterMeasure α) := rfl @[simp] theorem top_add : ⊤ + μ = ⊤ := top_unique <| Measure.le_add_right le_rfl @[simp] theorem add_top : μ + ⊤ = ⊤ := top_unique <| Measure.le_add_left le_rfl protected theorem zero_le {_m0 : MeasurableSpace α} (μ : Measure α) : 0 ≤ μ := bot_le theorem nonpos_iff_eq_zero' : μ ≤ 0 ↔ μ = 0 := μ.zero_le.le_iff_eq @[simp] theorem measure_univ_eq_zero : μ univ = 0 ↔ μ = 0 := ⟨fun h => bot_unique fun s => (h ▸ measure_mono (subset_univ s) : μ s ≤ 0), fun h => h.symm ▸ rfl⟩ theorem measure_univ_ne_zero : μ univ ≠ 0 ↔ μ ≠ 0 := measure_univ_eq_zero.not instance [NeZero μ] : NeZero (μ univ) := ⟨measure_univ_ne_zero.2 <| NeZero.ne μ⟩ @[simp] theorem measure_univ_pos : 0 < μ univ ↔ μ ≠ 0 := pos_iff_ne_zero.trans measure_univ_ne_zero lemma nonempty_of_neZero (μ : Measure α) [NeZero μ] : Nonempty α := (isEmpty_or_nonempty α).resolve_left fun h ↦ by simpa [eq_empty_of_isEmpty] using NeZero.ne (μ univ) section Sum variable {f : ι → Measure α} /-- Sum of an indexed family of measures. -/ noncomputable def sum (f : ι → Measure α) : Measure α := (OuterMeasure.sum fun i => (f i).toOuterMeasure).toMeasure <| le_trans (le_iInf fun _ => le_toOuterMeasure_caratheodory _) (OuterMeasure.le_sum_caratheodory _) theorem le_sum_apply (f : ι → Measure α) (s : Set α) : ∑' i, f i s ≤ sum f s := le_toMeasure_apply _ _ _ @[simp] theorem sum_apply (f : ι → Measure α) {s : Set α} (hs : MeasurableSet s) : sum f s = ∑' i, f i s := toMeasure_apply _ _ hs theorem sum_apply₀ (f : ι → Measure α) {s : Set α} (hs : NullMeasurableSet s (sum f)) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases hs.exists_measurable_subset_ae_eq with ⟨t, ts, t_meas, ht⟩ calc sum f s = sum f t := measure_congr ht.symm _ = ∑' i, f i t := sum_apply _ t_meas _ ≤ ∑' i, f i s := ENNReal.tsum_le_tsum fun i ↦ measure_mono ts /-! For the next theorem, the countability assumption is necessary. For a counterexample, consider an uncountable space, with a distinguished point `x₀`, and the sigma-algebra made of countable sets not containing `x₀`, and their complements. All points but `x₀` are measurable. Consider the sum of the Dirac masses at points different from `x₀`, and `s = {x₀}`. For any Dirac mass `δ_x`, we have `δ_x (x₀) = 0`, so `∑' x, δ_x (x₀) = 0`. On the other hand, the measure `sum δ_x` gives mass one to each point different from `x₀`, so it gives infinite mass to any measurable set containing `x₀` (as such a set is uncountable), and by outer regularity one gets `sum δ_x {x₀} = ∞`. -/ theorem sum_apply_of_countable [Countable ι] (f : ι → Measure α) (s : Set α) : sum f s = ∑' i, f i s := by apply le_antisymm ?_ (le_sum_apply _ _) rcases exists_measurable_superset_forall_eq f s with ⟨t, hst, htm, ht⟩ calc sum f s ≤ sum f t := measure_mono hst _ = ∑' i, f i t := sum_apply _ htm _ = ∑' i, f i s := by simp [ht] theorem le_sum (μ : ι → Measure α) (i : ι) : μ i ≤ sum μ := le_iff.2 fun s hs ↦ by simpa only [sum_apply μ hs] using ENNReal.le_tsum i @[simp] theorem sum_apply_eq_zero [Countable ι] {μ : ι → Measure α} {s : Set α} : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [sum_apply_of_countable] theorem sum_apply_eq_zero' {μ : ι → Measure α} {s : Set α} (hs : MeasurableSet s) : sum μ s = 0 ↔ ∀ i, μ i s = 0 := by simp [hs] @[simp] lemma sum_eq_zero : sum f = 0 ↔ ∀ i, f i = 0 := by simp +contextual [Measure.ext_iff, forall_swap (α := ι)] @[simp] lemma sum_zero : Measure.sum (fun (_ : ι) ↦ (0 : Measure α)) = 0 := by ext s hs simp [Measure.sum_apply _ hs] theorem sum_sum {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum (fun (p : ι × ι') ↦ μ p.1 p.2) := by ext1 s hs simp [sum_apply _ hs, ENNReal.tsum_prod'] theorem sum_comm {ι' : Type*} (μ : ι → ι' → Measure α) : (sum fun n => sum (μ n)) = sum fun m => sum fun n => μ n m := by ext1 s hs simp_rw [sum_apply _ hs] rw [ENNReal.tsum_comm] theorem ae_sum_iff [Countable ι] {μ : ι → Measure α} {p : α → Prop} : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero theorem ae_sum_iff' {μ : ι → Measure α} {p : α → Prop} (h : MeasurableSet { x | p x }) : (∀ᵐ x ∂sum μ, p x) ↔ ∀ i, ∀ᵐ x ∂μ i, p x := sum_apply_eq_zero' h.compl @[simp] theorem sum_fintype [Fintype ι] (μ : ι → Measure α) : sum μ = ∑ i, μ i := by ext1 s hs simp only [sum_apply, finset_sum_apply, hs, tsum_fintype] theorem sum_coe_finset (s : Finset ι) (μ : ι → Measure α) : (sum fun i : s => μ i) = ∑ i ∈ s, μ i := by rw [sum_fintype, Finset.sum_coe_sort s μ] @[simp] theorem ae_sum_eq [Countable ι] (μ : ι → Measure α) : ae (sum μ) = ⨆ i, ae (μ i) := Filter.ext fun _ => ae_sum_iff.trans mem_iSup.symm theorem sum_bool (f : Bool → Measure α) : sum f = f true + f false := by rw [sum_fintype, Fintype.sum_bool] theorem sum_cond (μ ν : Measure α) : (sum fun b => cond b μ ν) = μ + ν := sum_bool _ @[simp] theorem sum_of_isEmpty [IsEmpty ι] (μ : ι → Measure α) : sum μ = 0 := by rw [← measure_univ_eq_zero, sum_apply _ MeasurableSet.univ, tsum_empty] theorem sum_add_sum_compl (s : Set ι) (μ : ι → Measure α) : ((sum fun i : s => μ i) + sum fun i : ↥sᶜ => μ i) = sum μ := by ext1 t ht simp only [add_apply, sum_apply _ ht] exact ENNReal.summable.tsum_add_tsum_compl (f := fun i => μ i t) ENNReal.summable theorem sum_congr {μ ν : ℕ → Measure α} (h : ∀ n, μ n = ν n) : sum μ = sum ν := congr_arg sum (funext h) theorem sum_add_sum {ι : Type*} (μ ν : ι → Measure α) : sum μ + sum ν = sum fun n => μ n + ν n := by ext1 s hs simp only [add_apply, sum_apply _ hs, Pi.add_apply, coe_add, ENNReal.summable.tsum_add ENNReal.summable] @[simp] lemma sum_comp_equiv {ι ι' : Type*} (e : ι' ≃ ι) (m : ι → Measure α) : sum (m ∘ e) = sum m := by ext s hs simpa [hs, sum_apply] using e.tsum_eq (fun n ↦ m n s) @[simp] lemma sum_extend_zero {ι ι' : Type*} {f : ι → ι'} (hf : Injective f) (m : ι → Measure α) : sum (Function.extend f m 0) = sum m := by ext s hs simp [*, Function.apply_extend (fun μ : Measure α ↦ μ s)] end Sum /-! ### The `cofinite` filter -/ /-- The filter of sets `s` such that `sᶜ` has finite measure. -/ def cofinite {m0 : MeasurableSpace α} (μ : Measure α) : Filter α := comk (μ · < ∞) (by simp) (fun _ ht _ hs ↦ (measure_mono hs).trans_lt ht) fun s hs t ht ↦ (measure_union_le s t).trans_lt <| ENNReal.add_lt_top.2 ⟨hs, ht⟩ theorem mem_cofinite : s ∈ μ.cofinite ↔ μ sᶜ < ∞ := Iff.rfl theorem compl_mem_cofinite : sᶜ ∈ μ.cofinite ↔ μ s < ∞ := by rw [mem_cofinite, compl_compl] theorem eventually_cofinite {p : α → Prop} : (∀ᶠ x in μ.cofinite, p x) ↔ μ { x | ¬p x } < ∞ := Iff.rfl instance cofinite.instIsMeasurablyGenerated : IsMeasurablyGenerated μ.cofinite where exists_measurable_subset s hs := by refine ⟨(toMeasurable μ sᶜ)ᶜ, ?_, (measurableSet_toMeasurable _ _).compl, ?_⟩ · rwa [compl_mem_cofinite, measure_toMeasurable] · rw [compl_subset_comm] apply subset_toMeasurable end Measure open Measure open MeasureTheory protected theorem _root_.AEMeasurable.nullMeasurable {f : α → β} (h : AEMeasurable f μ) : NullMeasurable f μ := let ⟨_g, hgm, hg⟩ := h; hgm.nullMeasurable.congr hg.symm lemma _root_.AEMeasurable.nullMeasurableSet_preimage {f : α → β} {s : Set β} (hf : AEMeasurable f μ) (hs : MeasurableSet s) : NullMeasurableSet (f ⁻¹' s) μ := hf.nullMeasurable hs @[simp] theorem ae_eq_bot : ae μ = ⊥ ↔ μ = 0 := by rw [← empty_mem_iff_bot, mem_ae_iff, compl_empty, measure_univ_eq_zero] @[simp] theorem ae_neBot : (ae μ).NeBot ↔ μ ≠ 0 := neBot_iff.trans (not_congr ae_eq_bot) instance Measure.ae.neBot [NeZero μ] : (ae μ).NeBot := ae_neBot.2 <| NeZero.ne μ @[simp] theorem ae_zero {_m0 : MeasurableSpace α} : ae (0 : Measure α) = ⊥ := ae_eq_bot.2 rfl section Intervals theorem biSup_measure_Iic [Preorder α] {s : Set α} (hsc : s.Countable) (hst : ∀ x : α, ∃ y ∈ s, x ≤ y) (hdir : DirectedOn (· ≤ ·) s) : ⨆ x ∈ s, μ (Iic x) = μ univ := by rw [← measure_biUnion_eq_iSup hsc] · congr simp only [← bex_def] at hst exact iUnion₂_eq_univ_iff.2 hst · exact directedOn_iff_directed.2 (hdir.directed_val.mono_comp _ fun x y => Iic_subset_Iic.2) theorem tendsto_measure_Ico_atTop [Preorder α] [NoMaxOrder α] [(atTop : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) : Tendsto (fun x => μ (Ico a x)) atTop (𝓝 (μ (Ici a))) := by rw [← iUnion_Ico_right] exact tendsto_measure_iUnion_atTop (antitone_const.Ico monotone_id) theorem tendsto_measure_Ioc_atBot [Preorder α] [NoMinOrder α] [(atBot : Filter α).IsCountablyGenerated] (μ : Measure α) (a : α) : Tendsto (fun x => μ (Ioc x a)) atBot (𝓝 (μ (Iic a))) := by rw [← iUnion_Ioc_left] exact tendsto_measure_iUnion_atBot (monotone_id.Ioc antitone_const) theorem tendsto_measure_Iic_atTop [Preorder α] [(atTop : Filter α).IsCountablyGenerated] (μ : Measure α) : Tendsto (fun x => μ (Iic x)) atTop (𝓝 (μ univ)) := by rw [← iUnion_Iic] exact tendsto_measure_iUnion_atTop monotone_Iic theorem tendsto_measure_Ici_atBot [Preorder α] [(atBot : Filter α).IsCountablyGenerated] (μ : Measure α) : Tendsto (fun x => μ (Ici x)) atBot (𝓝 (μ univ)) := tendsto_measure_Iic_atTop (α := αᵒᵈ) μ variable [PartialOrder α] {a b : α} theorem Iio_ae_eq_Iic' (ha : μ {a} = 0) : Iio a =ᵐ[μ] Iic a := by rw [← Iic_diff_right, diff_ae_eq_self, measure_mono_null Set.inter_subset_right ha] theorem Ioi_ae_eq_Ici' (ha : μ {a} = 0) : Ioi a =ᵐ[μ] Ici a := Iio_ae_eq_Iic' (α := αᵒᵈ) ha theorem Ioo_ae_eq_Ioc' (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Ioc a b := (ae_eq_refl _).inter (Iio_ae_eq_Iic' hb) theorem Ioc_ae_eq_Icc' (ha : μ {a} = 0) : Ioc a b =ᵐ[μ] Icc a b := (Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _) theorem Ioo_ae_eq_Ico' (ha : μ {a} = 0) : Ioo a b =ᵐ[μ] Ico a b := (Ioi_ae_eq_Ici' ha).inter (ae_eq_refl _) theorem Ioo_ae_eq_Icc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ioo a b =ᵐ[μ] Icc a b := (Ioi_ae_eq_Ici' ha).inter (Iio_ae_eq_Iic' hb) theorem Ico_ae_eq_Icc' (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Icc a b := (ae_eq_refl _).inter (Iio_ae_eq_Iic' hb) theorem Ico_ae_eq_Ioc' (ha : μ {a} = 0) (hb : μ {b} = 0) : Ico a b =ᵐ[μ] Ioc a b := (Ioo_ae_eq_Ico' ha).symm.trans (Ioo_ae_eq_Ioc' hb) end Intervals end end MeasureTheory end
Mathlib/MeasureTheory/Measure/MeasureSpace.lean
1,991
1,992
/- Copyright (c) 2019 Alexander Bentkamp. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Alexander Bentkamp, François Dupuis -/ import Mathlib.Analysis.Convex.Basic import Mathlib.Order.Filter.Extr import Mathlib.Tactic.NormNum /-! # Convex and concave functions This file defines convex and concave functions in vector spaces and proves the finite Jensen inequality. The integral version can be found in `Analysis.Convex.Integral`. A function `f : E → β` is `ConvexOn` a set `s` if `s` is itself a convex set, and for any two points `x y ∈ s`, the segment joining `(x, f x)` to `(y, f y)` is above the graph of `f`. Equivalently, `ConvexOn 𝕜 f s` means that the epigraph `{p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2}` is a convex set. ## Main declarations * `ConvexOn 𝕜 s f`: The function `f` is convex on `s` with scalars `𝕜`. * `ConcaveOn 𝕜 s f`: The function `f` is concave on `s` with scalars `𝕜`. * `StrictConvexOn 𝕜 s f`: The function `f` is strictly convex on `s` with scalars `𝕜`. * `StrictConcaveOn 𝕜 s f`: The function `f` is strictly concave on `s` with scalars `𝕜`. -/ open LinearMap Set Convex Pointwise variable {𝕜 E F α β ι : Type*} section OrderedSemiring variable [Semiring 𝕜] [PartialOrder 𝕜] section AddCommMonoid variable [AddCommMonoid E] [AddCommMonoid F] section OrderedAddCommMonoid variable [AddCommMonoid α] [PartialOrder α] [AddCommMonoid β] [PartialOrder β] section SMul variable (𝕜) [SMul 𝕜 E] [SMul 𝕜 α] [SMul 𝕜 β] (s : Set E) (f : E → β) {g : β → α} /-- Convexity of functions -/ def ConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y /-- Concavity of functions -/ def ConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) /-- Strict convexity of functions -/ def StrictConvexOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y /-- Strict concavity of functions -/ def StrictConcaveOn : Prop := Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y) variable {𝕜 s f} open OrderDual (toDual ofDual) theorem ConvexOn.dual (hf : ConvexOn 𝕜 s f) : ConcaveOn 𝕜 s (toDual ∘ f) := hf theorem ConcaveOn.dual (hf : ConcaveOn 𝕜 s f) : ConvexOn 𝕜 s (toDual ∘ f) := hf theorem StrictConvexOn.dual (hf : StrictConvexOn 𝕜 s f) : StrictConcaveOn 𝕜 s (toDual ∘ f) := hf theorem StrictConcaveOn.dual (hf : StrictConcaveOn 𝕜 s f) : StrictConvexOn 𝕜 s (toDual ∘ f) := hf theorem convexOn_id {s : Set β} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ theorem concaveOn_id {s : Set β} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s _root_.id := ⟨hs, by intros rfl⟩ section congr variable {g : E → β} theorem ConvexOn.congr (hf : ConvexOn 𝕜 s f) (hfg : EqOn f g s) : ConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ theorem ConcaveOn.congr (hf : ConcaveOn 𝕜 s f) (hfg : EqOn f g s) : ConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩ theorem StrictConvexOn.congr (hf : StrictConvexOn 𝕜 s f) (hfg : EqOn f g s) : StrictConvexOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ theorem StrictConcaveOn.congr (hf : StrictConcaveOn 𝕜 s f) (hfg : EqOn f g s) : StrictConcaveOn 𝕜 s g := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => by simpa only [← hfg hx, ← hfg hy, ← hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩ end congr theorem ConvexOn.subset {t : Set E} (hf : ConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem ConcaveOn.subset {t : Set E} (hf : ConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem StrictConvexOn.subset {t : Set E} (hf : StrictConvexOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConvexOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem StrictConcaveOn.subset {t : Set E} (hf : StrictConcaveOn 𝕜 t f) (hst : s ⊆ t) (hs : Convex 𝕜 s) : StrictConcaveOn 𝕜 s f := ⟨hs, fun _ hx _ hy => hf.2 (hst hx) (hst hy)⟩ theorem ConvexOn.comp (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha hb hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) <| hf.2 hx hy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab⟩ theorem ConcaveOn.comp (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : MonotoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha hb hab) (mem_image_of_mem f <| hf.1 hx hy ha hb hab) <| hf.2 hx hy ha hb hab⟩ theorem ConvexOn.comp_concaveOn (hg : ConvexOn 𝕜 (f '' s) g) (hf : ConcaveOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' theorem ConcaveOn.comp_convexOn (hg : ConcaveOn 𝕜 (f '' s) g) (hf : ConvexOn 𝕜 s f) (hg' : AntitoneOn g (f '' s)) : ConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' theorem StrictConvexOn.comp (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg' (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab).trans <| hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab⟩ theorem StrictConcaveOn.comp (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictMonoOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hg.2 (mem_image_of_mem f hx) (mem_image_of_mem f hy) (mt (hf' hx hy) hxy) ha hb hab).trans <| hg' (hg.1 (mem_image_of_mem f hx) (mem_image_of_mem f hy) ha.le hb.le hab) (mem_image_of_mem f <| hf.1 hx hy ha.le hb.le hab) <| hf.2 hx hy hxy ha hb hab⟩ theorem StrictConvexOn.comp_strictConcaveOn (hg : StrictConvexOn 𝕜 (f '' s) g) (hf : StrictConcaveOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConvexOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' theorem StrictConcaveOn.comp_strictConvexOn (hg : StrictConcaveOn 𝕜 (f '' s) g) (hf : StrictConvexOn 𝕜 s f) (hg' : StrictAntiOn g (f '' s)) (hf' : s.InjOn f) : StrictConcaveOn 𝕜 s (g ∘ f) := hg.dual.comp hf hg' hf' end SMul section DistribMulAction variable [IsOrderedAddMonoid β] [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.add (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) ≤ a • f x + b • f y + (a • g x + b • g y) := add_le_add (hf.2 hx hy ha hb hab) (hg.2 hx hy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm] ⟩ theorem ConcaveOn.add (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f + g) := hf.dual.add hg end DistribMulAction section Module variable [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f : E → β} theorem convexOn_const (c : β) (hs : Convex 𝕜 s) : ConvexOn 𝕜 s fun _ : E => c := ⟨hs, fun _ _ _ _ _ _ _ _ hab => (Convex.combo_self hab c).ge⟩ theorem concaveOn_const (c : β) (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s fun _ => c := convexOn_const (β := βᵒᵈ) _ hs theorem ConvexOn.add_const [IsOrderedAddMonoid β] (hf : ConvexOn 𝕜 s f) (b : β) : ConvexOn 𝕜 s (f + fun _ => b) := hf.add (convexOn_const _ hf.1) theorem ConcaveOn.add_const [IsOrderedAddMonoid β] (hf : ConcaveOn 𝕜 s f) (b : β) : ConcaveOn 𝕜 s (f + fun _ => b) := hf.add (concaveOn_const _ hf.1) theorem convexOn_of_convex_epigraph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 }) : ConvexOn 𝕜 s f := ⟨fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).1, fun x hx y hy a b ha hb hab => (@h (x, f x) ⟨hx, le_rfl⟩ (y, f y) ⟨hy, le_rfl⟩ a b ha hb hab).2⟩ theorem concaveOn_of_convex_hypograph (h : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 }) : ConcaveOn 𝕜 s f := convexOn_of_convex_epigraph (β := βᵒᵈ) h end Module section OrderedSMul variable [IsOrderedAddMonoid β] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_le (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x ≤ r }) := fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha hb hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2 · exact hy.2 _ = r := Convex.combo_self hab r ⟩ theorem ConcaveOn.convex_ge (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r ≤ f x }) := hf.dual.convex_le r theorem ConvexOn.convex_epigraph (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := by rintro ⟨x, r⟩ ⟨hx, hr⟩ ⟨y, t⟩ ⟨hy, ht⟩ a b ha hb hab refine ⟨hf.1 hx hy ha hb hab, ?_⟩ calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • r + b • t := by gcongr theorem ConcaveOn.convex_hypograph (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := hf.dual.convex_epigraph theorem convexOn_iff_convex_epigraph : ConvexOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 ≤ p.2 } := ⟨ConvexOn.convex_epigraph, convexOn_of_convex_epigraph⟩ theorem concaveOn_iff_convex_hypograph : ConcaveOn 𝕜 s f ↔ Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 ≤ f p.1 } := convexOn_iff_convex_epigraph (β := βᵒᵈ) end OrderedSMul section Module variable [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β} /-- Right translation preserves convexity. -/ theorem ConvexOn.translate_right (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := ⟨hf.1.translate_preimage_right _, fun x hx y hy a b ha hb hab => calc f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab] _ ≤ a • f (c + x) + b • f (c + y) := hf.2 hx hy ha hb hab ⟩ /-- Right translation preserves concavity. -/ theorem ConcaveOn.translate_right (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := hf.dual.translate_right _ /-- Left translation preserves convexity. -/ theorem ConvexOn.translate_left (hf : ConvexOn 𝕜 s f) (c : E) : ConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm c] using hf.translate_right c /-- Left translation preserves concavity. -/ theorem ConcaveOn.translate_left (hf : ConcaveOn 𝕜 s f) (c : E) : ConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := hf.dual.translate_left _ end Module section Module variable [Module 𝕜 E] [Module 𝕜 β] theorem convexOn_iff_forall_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by refine and_congr_right' ⟨fun h x hx y hy a b ha hb hab => h hx hy ha.le hb.le hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | ha' := ha.eq_or_lt · rw [zero_add] at hab subst b simp_rw [zero_smul, zero_add, one_smul, le_rfl] obtain rfl | hb' := hb.eq_or_lt · rw [add_zero] at hab subst a simp_rw [zero_smul, add_zero, one_smul, le_rfl] exact h hx hy ha' hb' hab theorem concaveOn_iff_forall_pos {s : Set E} {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) := convexOn_iff_forall_pos (β := βᵒᵈ) theorem convexOn_iff_pairwise_pos {s : Set E} {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y := by rw [convexOn_iff_forall_pos] refine and_congr_right' ⟨fun h x hx y hy _ a b ha hb hab => h hx hy ha hb hab, fun h x hx y hy a b ha hb hab => ?_⟩ obtain rfl | hxy := eq_or_ne x y · rw [Convex.combo_self hab, Convex.combo_self hab] exact h hx hy hxy ha hb hab theorem concaveOn_iff_pairwise_pos {s : Set E} {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ s.Pairwise fun x y => ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y) := convexOn_iff_pairwise_pos (β := βᵒᵈ) /-- A linear map is convex. -/ theorem LinearMap.convexOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConvexOn 𝕜 s f := ⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩ /-- A linear map is concave. -/ theorem LinearMap.concaveOn (f : E →ₗ[𝕜] β) {s : Set E} (hs : Convex 𝕜 s) : ConcaveOn 𝕜 s f := ⟨hs, fun _ _ _ _ _ _ _ _ _ => by rw [f.map_add, f.map_smul, f.map_smul]⟩ theorem StrictConvexOn.convexOn {s : Set E} {f : E → β} (hf : StrictConvexOn 𝕜 s f) : ConvexOn 𝕜 s f := convexOn_iff_pairwise_pos.mpr ⟨hf.1, fun _ hx _ hy hxy _ _ ha hb hab => (hf.2 hx hy hxy ha hb hab).le⟩ theorem StrictConcaveOn.concaveOn {s : Set E} {f : E → β} (hf : StrictConcaveOn 𝕜 s f) : ConcaveOn 𝕜 s f := hf.dual.convexOn section OrderedSMul variable [IsOrderedAddMonoid β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem StrictConvexOn.convex_lt (hf : StrictConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := convex_iff_pairwise_pos.2 fun x hx y hy hxy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha.le hb.le hab, calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx.1 hy.1 hxy ha hb hab _ ≤ a • r + b • r := by gcongr · exact hx.2.le · exact hy.2.le _ = r := Convex.combo_self hab r ⟩ theorem StrictConcaveOn.convex_gt (hf : StrictConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r end OrderedSMul section LinearOrder variable [LinearOrder E] {s : Set E} {f : E → β} /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is convex, it suffices to verify the inequality `f (a • x + b • y) ≤ a • f x + b • f y` only for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.convexOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) ≤ a • f x + b • f y) : ConvexOn 𝕜 s f := by refine convexOn_iff_pairwise_pos.2 ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩ wlog h : x < y · rw [add_comm (a • x), add_comm (a • f x)] rw [add_comm] at hab exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h) exact hf hx hy h ha hb hab /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is concave it suffices to verify the inequality `a • f x + b • f y ≤ f (a • x + b • y)` for `x < y` and positive `a`, `b`. The main use case is `E = ℝ` however one can apply it, e.g., to `ℝ^n` with lexicographic order. -/ theorem LinearOrder.concaveOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y ≤ f (a • x + b • y)) : ConcaveOn 𝕜 s f := LinearOrder.convexOn_of_lt (β := βᵒᵈ) hs hf /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is strictly convex, it suffices to verify the inequality `f (a • x + b • y) < a • f x + b • f y` for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.strictConvexOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → f (a • x + b • y) < a • f x + b • f y) : StrictConvexOn 𝕜 s f := by refine ⟨hs, fun x hx y hy hxy a b ha hb hab => ?_⟩ wlog h : x < y · rw [add_comm (a • x), add_comm (a • f x)] rw [add_comm] at hab exact this hs hf y hy x hx hxy.symm b a hb ha hab (hxy.lt_or_lt.resolve_left h) exact hf hx hy h ha hb hab /-- For a function on a convex set in a linearly ordered space (where the order and the algebraic structures aren't necessarily compatible), in order to prove that it is strictly concave it suffices to verify the inequality `a • f x + b • f y < f (a • x + b • y)` for `x < y` and positive `a`, `b`. The main use case is `E = 𝕜` however one can apply it, e.g., to `𝕜^n` with lexicographic order. -/ theorem LinearOrder.strictConcaveOn_of_lt (hs : Convex 𝕜 s) (hf : ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x < y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → a + b = 1 → a • f x + b • f y < f (a • x + b • y)) : StrictConcaveOn 𝕜 s f := LinearOrder.strictConvexOn_of_lt (β := βᵒᵈ) hs hf end LinearOrder end Module section Module variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β] /-- If `g` is convex on `s`, so is `(f ∘ g)` on `f ⁻¹' s` for a linear `f`. -/ theorem ConvexOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConvexOn 𝕜 s f) (g : E →ₗ[𝕜] F) : ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) := ⟨hf.1.linear_preimage _, fun x hx y hy a b ha hb hab => calc f (g (a • x + b • y)) = f (a • g x + b • g y) := by rw [g.map_add, g.map_smul, g.map_smul] _ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩ /-- If `g` is concave on `s`, so is `(g ∘ f)` on `f ⁻¹' s` for a linear `f`. -/ theorem ConcaveOn.comp_linearMap {f : F → β} {s : Set F} (hf : ConcaveOn 𝕜 s f) (g : E →ₗ[𝕜] F) : ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) := hf.dual.comp_linearMap g end Module end OrderedAddCommMonoid section OrderedCancelAddCommMonoid variable [AddCommMonoid β] [PartialOrder β] [IsOrderedCancelAddMonoid β] section DistribMulAction variable [SMul 𝕜 E] [DistribMulAction 𝕜 β] {s : Set E} {f g : E → β} theorem StrictConvexOn.add_convexOn (hf : StrictConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) := add_lt_add_of_lt_of_le (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy ha.le hb.le hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩ theorem ConvexOn.add_strictConvexOn (hf : ConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := add_comm g f ▸ hg.add_convexOn hf theorem StrictConvexOn.add (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f + g) := ⟨hf.1, fun x hx y hy hxy a b ha hb hab => calc f (a • x + b • y) + g (a • x + b • y) < a • f x + b • f y + (a • g x + b • g y) := add_lt_add (hf.2 hx hy hxy ha hb hab) (hg.2 hx hy hxy ha hb hab) _ = a • (f x + g x) + b • (f y + g y) := by rw [smul_add, smul_add, add_add_add_comm]⟩ theorem StrictConcaveOn.add_concaveOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add_convexOn hg.dual theorem ConcaveOn.add_strictConcaveOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add_strictConvexOn hg.dual theorem StrictConcaveOn.add (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f + g) := hf.dual.add hg theorem StrictConvexOn.add_const {γ : Type*} {f : E → γ} [AddCommMonoid γ] [PartialOrder γ] [IsOrderedCancelAddMonoid γ] [Module 𝕜 γ] (hf : StrictConvexOn 𝕜 s f) (b : γ) : StrictConvexOn 𝕜 s (f + fun _ => b) := hf.add_convexOn (convexOn_const _ hf.1) theorem StrictConcaveOn.add_const {γ : Type*} {f : E → γ} [AddCommMonoid γ] [PartialOrder γ] [IsOrderedCancelAddMonoid γ] [Module 𝕜 γ] (hf : StrictConcaveOn 𝕜 s f) (b : γ) : StrictConcaveOn 𝕜 s (f + fun _ => b) := hf.add_concaveOn (concaveOn_const _ hf.1) end DistribMulAction section Module variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.convex_lt (hf : ConvexOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | f x < r }) := convex_iff_forall_pos.2 fun x hx y hy a b ha hb hab => ⟨hf.1 hx.1 hy.1 ha.le hb.le hab, calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx.1 hy.1 ha.le hb.le hab _ < a • r + b • r := (add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hx.2 ha) (smul_le_smul_of_nonneg_left hy.2.le hb.le)) _ = r := Convex.combo_self hab _⟩ theorem ConcaveOn.convex_gt (hf : ConcaveOn 𝕜 s f) (r : β) : Convex 𝕜 ({ x ∈ s | r < f x }) := hf.dual.convex_lt r theorem ConvexOn.openSegment_subset_strict_epigraph (hf : ConvexOn 𝕜 s f) (p q : E × β) (hp : p.1 ∈ s ∧ f p.1 < p.2) (hq : q.1 ∈ s ∧ f q.1 ≤ q.2) : openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := by rintro _ ⟨a, b, ha, hb, hab, rfl⟩ refine ⟨hf.1 hp.1 hq.1 ha.le hb.le hab, ?_⟩ calc f (a • p.1 + b • q.1) ≤ a • f p.1 + b • f q.1 := hf.2 hp.1 hq.1 ha.le hb.le hab _ < a • p.2 + b • q.2 := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left hp.2 ha) (smul_le_smul_of_nonneg_left hq.2 hb.le) theorem ConcaveOn.openSegment_subset_strict_hypograph (hf : ConcaveOn 𝕜 s f) (p q : E × β) (hp : p.1 ∈ s ∧ p.2 < f p.1) (hq : q.1 ∈ s ∧ q.2 ≤ f q.1) : openSegment 𝕜 p q ⊆ { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } := hf.dual.openSegment_subset_strict_epigraph p q hp hq theorem ConvexOn.convex_strict_epigraph [ZeroLEOneClass 𝕜] (hf : ConvexOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ f p.1 < p.2 } := convex_iff_openSegment_subset.mpr fun p hp q hq => hf.openSegment_subset_strict_epigraph p q hp ⟨hq.1, hq.2.le⟩ theorem ConcaveOn.convex_strict_hypograph [ZeroLEOneClass 𝕜] (hf : ConcaveOn 𝕜 s f) : Convex 𝕜 { p : E × β | p.1 ∈ s ∧ p.2 < f p.1 } := hf.dual.convex_strict_epigraph end Module end OrderedCancelAddCommMonoid section LinearOrderedAddCommMonoid variable [AddCommMonoid β] [LinearOrder β] [IsOrderedAddMonoid β] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} /-- The pointwise maximum of convex functions is convex. -/ theorem ConvexOn.sup (hf : ConvexOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConvexOn 𝕜 s (f ⊔ g) := by refine ⟨hf.left, fun x hx y hy a b ha hb hab => sup_le ?_ ?_⟩ · calc f (a • x + b • y) ≤ a • f x + b • f y := hf.right hx hy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left · calc g (a • x + b • y) ≤ a • g x + b • g y := hg.right hx hy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right /-- The pointwise minimum of concave functions is concave. -/ theorem ConcaveOn.inf (hf : ConcaveOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg /-- The pointwise maximum of strictly convex functions is strictly convex. -/ theorem StrictConvexOn.sup (hf : StrictConvexOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConvexOn 𝕜 s (f ⊔ g) := ⟨hf.left, fun x hx y hy hxy a b ha hb hab => max_lt (calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_left) (calc g (a • x + b • y) < a • g x + b • g y := hg.2 hx hy hxy ha hb hab _ ≤ a • (f x ⊔ g x) + b • (f y ⊔ g y) := by gcongr <;> apply le_sup_right)⟩ /-- The pointwise minimum of strictly concave functions is strictly concave. -/ theorem StrictConcaveOn.inf (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f ⊓ g) := hf.dual.sup hg /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem ConvexOn.le_on_segment' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : f (a • x + b • y) ≤ max (f x) (f y) := calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha hb hab _ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by gcongr · apply le_max_left · apply le_max_right _ = max (f x) (f y) := Convex.combo_self hab _ /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem ConcaveOn.ge_on_segment' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) : min (f x) (f y) ≤ f (a • x + b • y) := hf.dual.le_on_segment' hx hy ha hb hab /-- A convex function on a segment is upper-bounded by the max of its endpoints. -/ theorem ConvexOn.le_on_segment (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[𝕜] y]) : f z ≤ max (f x) (f y) := let ⟨_, _, ha, hb, hab, hz⟩ := hz hz ▸ hf.le_on_segment' hx hy ha hb hab /-- A concave function on a segment is lower-bounded by the min of its endpoints. -/ theorem ConcaveOn.ge_on_segment (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ [x -[𝕜] y]) : min (f x) (f y) ≤ f z := hf.dual.le_on_segment hx hy hz /-- A strictly convex function on an open segment is strictly upper-bounded by the max of its endpoints. -/ theorem StrictConvexOn.lt_on_open_segment' (hf : StrictConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : f (a • x + b • y) < max (f x) (f y) := calc f (a • x + b • y) < a • f x + b • f y := hf.2 hx hy hxy ha hb hab _ ≤ a • max (f x) (f y) + b • max (f x) (f y) := by gcongr · apply le_max_left · apply le_max_right _ = max (f x) (f y) := Convex.combo_self hab _ /-- A strictly concave function on an open segment is strictly lower-bounded by the min of its endpoints. -/ theorem StrictConcaveOn.lt_on_open_segment' (hf : StrictConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) : min (f x) (f y) < f (a • x + b • y) := hf.dual.lt_on_open_segment' hx hy hxy ha hb hab /-- A strictly convex function on an open segment is strictly upper-bounded by the max of its endpoints. -/ theorem StrictConvexOn.lt_on_openSegment (hf : StrictConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : f z < max (f x) (f y) := let ⟨_, _, ha, hb, hab, hz⟩ := hz hz ▸ hf.lt_on_open_segment' hx hy hxy ha hb hab /-- A strictly concave function on an open segment is strictly lower-bounded by the min of its endpoints. -/ theorem StrictConcaveOn.lt_on_openSegment (hf : StrictConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) (hz : z ∈ openSegment 𝕜 x y) : min (f x) (f y) < f z := hf.dual.lt_on_openSegment hx hy hxy hz end LinearOrderedAddCommMonoid section LinearOrderedCancelAddCommMonoid variable [AddCommMonoid β] [LinearOrder β] [IsOrderedCancelAddMonoid β] section OrderedSMul variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} theorem ConvexOn.le_left_of_right_le' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f y ≤ f (a • x + b • y)) : f (a • x + b • y) ≤ f x := le_of_not_lt fun h ↦ lt_irrefl (f (a • x + b • y)) <| calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb hab _ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_lt_of_le (smul_lt_smul_of_pos_left h ha) (smul_le_smul_of_nonneg_left hfy hb) _ = f (a • x + b • y) := Convex.combo_self hab _ theorem ConcaveOn.left_le_of_le_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 ≤ b) (hab : a + b = 1) (hfy : f (a • x + b • y) ≤ f y) : f x ≤ f (a • x + b • y) := hf.dual.le_left_of_right_le' hx hy ha hb hab hfy theorem ConvexOn.le_right_of_left_le' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x ≤ f (a • x + b • y)) : f (a • x + b • y) ≤ f y := by rw [add_comm] at hab hfx ⊢ exact hf.le_left_of_right_le' hy hx hb ha hab hfx theorem ConcaveOn.right_le_of_le_left' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 ≤ a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) ≤ f x) : f y ≤ f (a • x + b • y) := hf.dual.le_right_of_left_le' hx hy ha hb hab hfx theorem ConvexOn.le_left_of_right_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f y ≤ f z) : f z ≤ f x := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.le_left_of_right_le' hx hy ha hb.le hab hyz theorem ConcaveOn.left_le_of_le_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f z ≤ f y) : f x ≤ f z := hf.dual.le_left_of_right_le hx hy hz hyz theorem ConvexOn.le_right_of_left_le (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f x ≤ f z) : f z ≤ f y := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.le_right_of_left_le' hx hy ha.le hb hab hxz theorem ConcaveOn.right_le_of_le_left (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f z ≤ f x) : f y ≤ f z := hf.dual.le_right_of_left_le hx hy hz hxz end OrderedSMul section Module variable [Module 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f g : E → β} /- The following lemmas don't require `Module 𝕜 E` if you add the hypothesis `x ≠ y`. At the time of the writing, we decided the resulting lemmas wouldn't be useful. Feel free to reintroduce them. -/ theorem ConvexOn.lt_left_of_right_lt' (hf : ConvexOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f y < f (a • x + b • y)) : f (a • x + b • y) < f x := not_le.1 fun h ↦ lt_irrefl (f (a • x + b • y)) <| calc f (a • x + b • y) ≤ a • f x + b • f y := hf.2 hx hy ha.le hb.le hab _ < a • f (a • x + b • y) + b • f (a • x + b • y) := add_lt_add_of_le_of_lt (smul_le_smul_of_nonneg_left h ha.le) (smul_lt_smul_of_pos_left hfy hb) _ = f (a • x + b • y) := Convex.combo_self hab _ theorem ConcaveOn.left_lt_of_lt_right' (hf : ConcaveOn 𝕜 s f) {x y : E} (hx : x ∈ s) (hy : y ∈ s) {a b : 𝕜} (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfy : f (a • x + b • y) < f y) : f x < f (a • x + b • y) := hf.dual.lt_left_of_right_lt' hx hy ha hb hab hfy theorem ConvexOn.lt_right_of_left_lt' (hf : ConvexOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f x < f (a • x + b • y)) : f (a • x + b • y) < f y := by rw [add_comm] at hab hfx ⊢ exact hf.lt_left_of_right_lt' hy hx hb ha hab hfx theorem ConcaveOn.lt_right_of_left_lt' (hf : ConcaveOn 𝕜 s f) {x y : E} {a b : 𝕜} (hx : x ∈ s) (hy : y ∈ s) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) (hfx : f (a • x + b • y) < f x) : f y < f (a • x + b • y) := hf.dual.lt_right_of_left_lt' hx hy ha hb hab hfx theorem ConvexOn.lt_left_of_right_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f y < f z) : f z < f x := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.lt_left_of_right_lt' hx hy ha hb hab hyz theorem ConcaveOn.left_lt_of_lt_right (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hyz : f z < f y) : f x < f z := hf.dual.lt_left_of_right_lt hx hy hz hyz theorem ConvexOn.lt_right_of_left_lt (hf : ConvexOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f x < f z) : f z < f y := by obtain ⟨a, b, ha, hb, hab, rfl⟩ := hz exact hf.lt_right_of_left_lt' hx hy ha hb hab hxz theorem ConcaveOn.lt_right_of_left_lt (hf : ConcaveOn 𝕜 s f) {x y z : E} (hx : x ∈ s) (hy : y ∈ s) (hz : z ∈ openSegment 𝕜 x y) (hxz : f z < f x) : f y < f z := hf.dual.lt_right_of_left_lt hx hy hz hxz end Module end LinearOrderedCancelAddCommMonoid section OrderedAddCommGroup variable [AddCommGroup β] [PartialOrder β] [IsOrderedAddMonoid β] [SMul 𝕜 E] [Module 𝕜 β] {s : Set E} {f g : E → β} /-- A function `-f` is convex iff `f` is concave. -/ @[simp] theorem neg_convexOn_iff : ConvexOn 𝕜 s (-f) ↔ ConcaveOn 𝕜 s f := by constructor · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy a b ha hb hab => ?_⟩ simp? [neg_apply, neg_le, add_comm] at h says simp only [Pi.neg_apply, smul_neg, le_add_neg_iff_add_le, add_comm, add_neg_le_iff_le_add] at h exact h hx hy ha hb hab · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy a b ha hb hab => ?_⟩ rw [← neg_le_neg_iff] simp_rw [neg_add, Pi.neg_apply, smul_neg, neg_neg] exact h hx hy ha hb hab /-- A function `-f` is concave iff `f` is convex. -/ @[simp] theorem neg_concaveOn_iff : ConcaveOn 𝕜 s (-f) ↔ ConvexOn 𝕜 s f := by rw [← neg_convexOn_iff, neg_neg f] /-- A function `-f` is strictly convex iff `f` is strictly concave. -/ @[simp] theorem neg_strictConvexOn_iff : StrictConvexOn 𝕜 s (-f) ↔ StrictConcaveOn 𝕜 s f := by constructor · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy hxy a b ha hb hab => ?_⟩ simp only [ne_eq, Pi.neg_apply, smul_neg, lt_add_neg_iff_add_lt, add_comm, add_neg_lt_iff_lt_add] at h exact h hx hy hxy ha hb hab · rintro ⟨hconv, h⟩ refine ⟨hconv, fun x hx y hy hxy a b ha hb hab => ?_⟩ rw [← neg_lt_neg_iff] simp_rw [neg_add, Pi.neg_apply, smul_neg, neg_neg] exact h hx hy hxy ha hb hab /-- A function `-f` is strictly concave iff `f` is strictly convex. -/ @[simp] theorem neg_strictConcaveOn_iff : StrictConcaveOn 𝕜 s (-f) ↔ StrictConvexOn 𝕜 s f := by rw [← neg_strictConvexOn_iff, neg_neg f] alias ⟨_, ConcaveOn.neg⟩ := neg_convexOn_iff alias ⟨_, ConvexOn.neg⟩ := neg_concaveOn_iff alias ⟨_, StrictConcaveOn.neg⟩ := neg_strictConvexOn_iff alias ⟨_, StrictConvexOn.neg⟩ := neg_strictConcaveOn_iff theorem ConvexOn.sub (hf : ConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : ConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem ConcaveOn.sub (hf : ConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : ConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem StrictConvexOn.sub (hf : StrictConvexOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem StrictConcaveOn.sub (hf : StrictConcaveOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add hg.neg theorem ConvexOn.sub_strictConcaveOn (hf : ConvexOn 𝕜 s f) (hg : StrictConcaveOn 𝕜 s g) : StrictConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_strictConvexOn hg.neg theorem ConcaveOn.sub_strictConvexOn (hf : ConcaveOn 𝕜 s f) (hg : StrictConvexOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_strictConcaveOn hg.neg theorem StrictConvexOn.sub_concaveOn (hf : StrictConvexOn 𝕜 s f) (hg : ConcaveOn 𝕜 s g) : StrictConvexOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_convexOn hg.neg theorem StrictConcaveOn.sub_convexOn (hf : StrictConcaveOn 𝕜 s f) (hg : ConvexOn 𝕜 s g) : StrictConcaveOn 𝕜 s (f - g) := (sub_eq_add_neg f g).symm ▸ hf.add_concaveOn hg.neg end OrderedAddCommGroup end AddCommMonoid section AddCancelCommMonoid variable [AddCancelCommMonoid E] [AddCommMonoid β] [PartialOrder β] [Module 𝕜 E] [SMul 𝕜 β] {s : Set E} {f : E → β} /-- Right translation preserves strict convexity. -/ theorem StrictConvexOn.translate_right (hf : StrictConvexOn 𝕜 s f) (c : E) : StrictConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := ⟨hf.1.translate_preimage_right _, fun x hx y hy hxy a b ha hb hab => calc f (c + (a • x + b • y)) = f (a • (c + x) + b • (c + y)) := by rw [smul_add, smul_add, add_add_add_comm, Convex.combo_self hab] _ < a • f (c + x) + b • f (c + y) := hf.2 hx hy ((add_right_injective c).ne hxy) ha hb hab⟩ /-- Right translation preserves strict concavity. -/ theorem StrictConcaveOn.translate_right (hf : StrictConcaveOn 𝕜 s f) (c : E) : StrictConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => c + z) := hf.dual.translate_right _ /-- Left translation preserves strict convexity. -/ theorem StrictConvexOn.translate_left (hf : StrictConvexOn 𝕜 s f) (c : E) : StrictConvexOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm] using hf.translate_right c /-- Left translation preserves strict concavity. -/ theorem StrictConcaveOn.translate_left (hf : StrictConcaveOn 𝕜 s f) (c : E) : StrictConcaveOn 𝕜 ((fun z => c + z) ⁻¹' s) (f ∘ fun z => z + c) := by simpa only [add_comm] using hf.translate_right c end AddCancelCommMonoid end OrderedSemiring section OrderedCommSemiring variable [CommSemiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid E] section OrderedAddCommMonoid variable [AddCommMonoid β] [PartialOrder β] section Module variable [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {s : Set E} {f : E → β} theorem ConvexOn.smul {c : 𝕜} (hc : 0 ≤ c) (hf : ConvexOn 𝕜 s f) : ConvexOn 𝕜 s fun x => c • f x := ⟨hf.1, fun x hx y hy a b ha hb hab => calc c • f (a • x + b • y) ≤ c • (a • f x + b • f y) := smul_le_smul_of_nonneg_left (hf.2 hx hy ha hb hab) hc _ = a • c • f x + b • c • f y := by rw [smul_add, smul_comm c, smul_comm c]⟩ theorem ConcaveOn.smul {c : 𝕜} (hc : 0 ≤ c) (hf : ConcaveOn 𝕜 s f) : ConcaveOn 𝕜 s fun x => c • f x := hf.dual.smul hc end Module end OrderedAddCommMonoid end OrderedCommSemiring section OrderedRing variable [Field 𝕜] [LinearOrder 𝕜] [AddCommGroup E] [AddCommGroup F] section OrderedAddCommMonoid variable [AddCommMonoid β] [PartialOrder β] section Module variable [Module 𝕜 E] [Module 𝕜 F] [SMul 𝕜 β] /-- If a function is convex on `s`, it remains convex when precomposed by an affine map. -/ theorem ConvexOn.comp_affineMap {f : F → β} (g : E →ᵃ[𝕜] F) {s : Set F} (hf : ConvexOn 𝕜 s f) : ConvexOn 𝕜 (g ⁻¹' s) (f ∘ g) := ⟨hf.1.affine_preimage _, fun x hx y hy a b ha hb hab => calc (f ∘ g) (a • x + b • y) = f (g (a • x + b • y)) := rfl _ = f (a • g x + b • g y) := by rw [Convex.combo_affine_apply hab] _ ≤ a • f (g x) + b • f (g y) := hf.2 hx hy ha hb hab⟩ /-- If a function is concave on `s`, it remains concave when precomposed by an affine map. -/ theorem ConcaveOn.comp_affineMap {f : F → β} (g : E →ᵃ[𝕜] F) {s : Set F} (hf : ConcaveOn 𝕜 s f) : ConcaveOn 𝕜 (g ⁻¹' s) (f ∘ g) := hf.dual.comp_affineMap g end Module end OrderedAddCommMonoid end OrderedRing section LinearOrderedField variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [AddCommMonoid E] section OrderedAddCommMonoid variable [AddCommMonoid β] [PartialOrder β] section SMul variable [SMul 𝕜 E] [SMul 𝕜 β] {s : Set E} theorem convexOn_iff_div {f : E → β} : ConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → f ((a / (a + b)) • x + (b / (a + b)) • y) ≤ (a / (a + b)) • f x + (b / (a + b)) • f y := and_congr Iff.rfl ⟨by intro h x hx y hy a b ha hb hab apply h hx hy (div_nonneg ha hab.le) (div_nonneg hb hab.le) rw [← add_div, div_self hab.ne'], by intro h x hx y hy a b ha hb hab simpa [hab, zero_lt_one] using h hx hy ha hb⟩ theorem concaveOn_iff_div {f : E → β} : ConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → ∀ ⦃a b : 𝕜⦄, 0 ≤ a → 0 ≤ b → 0 < a + b → (a / (a + b)) • f x + (b / (a + b)) • f y ≤ f ((a / (a + b)) • x + (b / (a + b)) • y) := convexOn_iff_div (β := βᵒᵈ) theorem strictConvexOn_iff_div {f : E → β} : StrictConvexOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → f ((a / (a + b)) • x + (b / (a + b)) • y) < (a / (a + b)) • f x + (b / (a + b)) • f y := and_congr Iff.rfl ⟨by intro h x hx y hy hxy a b ha hb have hab := add_pos ha hb apply h hx hy hxy (div_pos ha hab) (div_pos hb hab) rw [← add_div, div_self hab.ne'], by intro h x hx y hy hxy a b ha hb hab simpa [hab, zero_lt_one] using h hx hy hxy ha hb⟩ theorem strictConcaveOn_iff_div {f : E → β} : StrictConcaveOn 𝕜 s f ↔ Convex 𝕜 s ∧ ∀ ⦃x⦄, x ∈ s → ∀ ⦃y⦄, y ∈ s → x ≠ y → ∀ ⦃a b : 𝕜⦄, 0 < a → 0 < b → (a / (a + b)) • f x + (b / (a + b)) • f y < f ((a / (a + b)) • x + (b / (a + b)) • y) := strictConvexOn_iff_div (β := βᵒᵈ) end SMul end OrderedAddCommMonoid end LinearOrderedField section OrderIso variable [Semiring 𝕜] [PartialOrder 𝕜] [AddCommMonoid α] [PartialOrder α] [SMul 𝕜 α] [AddCommMonoid β] [PartialOrder β] [SMul 𝕜 β] theorem OrderIso.strictConvexOn_symm (f : α ≃o β) (hf : StrictConcaveOn 𝕜 univ f) : StrictConvexOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ have hxy' : x' ≠ y' := by rw [← f.injective.ne_iff, ← hx'', ← hy'']; exact hxy simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.lt_iff_lt, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) hxy' ha hb hab theorem OrderIso.convexOn_symm (f : α ≃o β) (hf : ConcaveOn 𝕜 univ f) : ConvexOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.le_iff_le, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) ha hb hab theorem OrderIso.strictConcaveOn_symm (f : α ≃o β) (hf : StrictConvexOn 𝕜 univ f) : StrictConcaveOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ hxy a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ have hxy' : x' ≠ y' := by rw [← f.injective.ne_iff, ← hx'', ← hy'']; exact hxy simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.lt_iff_lt, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) hxy' ha hb hab theorem OrderIso.concaveOn_symm (f : α ≃o β) (hf : ConvexOn 𝕜 univ f) : ConcaveOn 𝕜 univ f.symm := by refine ⟨convex_univ, fun x _ y _ a b ha hb hab => ?_⟩ obtain ⟨x', hx''⟩ := f.surjective.exists.mp ⟨x, rfl⟩ obtain ⟨y', hy''⟩ := f.surjective.exists.mp ⟨y, rfl⟩ simp only [hx'', hy'', OrderIso.symm_apply_apply, gt_iff_lt] rw [← f.le_iff_le, OrderIso.apply_symm_apply] exact hf.2 (by simp : x' ∈ univ) (by simp : y' ∈ univ) ha hb hab end OrderIso section LinearOrderedField variable [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] section OrderedAddCommMonoid variable [AddCommMonoid β] [PartialOrder β] [IsOrderedAddMonoid β] [AddCommMonoid E] [SMul 𝕜 E] [Module 𝕜 β] [OrderedSMul 𝕜 β] {f : E → β} {s : Set E} {x y : E} /-- A strictly convex function admits at most one global minimum. -/ lemma StrictConvexOn.eq_of_isMinOn (hf : StrictConvexOn 𝕜 s f) (hfx : IsMinOn f s x) (hfy : IsMinOn f s y) (hx : x ∈ s) (hy : y ∈ s) : x = y := by by_contra hxy let z := (2 : 𝕜)⁻¹ • x + (2 : 𝕜)⁻¹ • y have hz : z ∈ s := hf.1 hx hy (by norm_num) (by norm_num) <| by norm_num refine lt_irrefl (f z) ?_ calc f z < _ := hf.2 hx hy hxy (by norm_num) (by norm_num) <| by norm_num _ ≤ (2 : 𝕜)⁻¹ • f z + (2 : 𝕜)⁻¹ • f z := by gcongr; exacts [hfx hz, hfy hz] _ = f z := by rw [← _root_.add_smul]; norm_num /-- A strictly concave function admits at most one global maximum. -/ lemma StrictConcaveOn.eq_of_isMaxOn (hf : StrictConcaveOn 𝕜 s f) (hfx : IsMaxOn f s x) (hfy : IsMaxOn f s y) (hx : x ∈ s) (hy : y ∈ s) : x = y := hf.dual.eq_of_isMinOn hfx hfy hx hy end OrderedAddCommMonoid section LinearOrderedCancelAddCommMonoid variable [AddCommMonoid β] [LinearOrder β] [IsOrderedCancelAddMonoid β] [Module 𝕜 β] [OrderedSMul 𝕜 β] {x y z : 𝕜} {s : Set 𝕜} {f : 𝕜 → β} theorem ConvexOn.le_right_of_left_le'' (hf : ConvexOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y ≤ z) (h : f x ≤ f y) : f y ≤ f z := hyz.eq_or_lt.elim (fun hyz => (congr_arg f hyz).le) fun hyz => hf.le_right_of_left_le hx hz (Ioo_subset_openSegment ⟨hxy, hyz⟩) h theorem ConvexOn.le_left_of_right_le'' (hf : ConvexOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x ≤ y) (hyz : y < z) (h : f z ≤ f y) : f y ≤ f x := hxy.eq_or_lt.elim (fun hxy => (congr_arg f hxy).ge) fun hxy => hf.le_left_of_right_le hx hz (Ioo_subset_openSegment ⟨hxy, hyz⟩) h theorem ConcaveOn.right_le_of_le_left'' (hf : ConcaveOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s)
(hxy : x < y) (hyz : y ≤ z) (h : f y ≤ f x) : f z ≤ f y := hf.dual.le_right_of_left_le'' hx hz hxy hyz h theorem ConcaveOn.left_le_of_le_right'' (hf : ConcaveOn 𝕜 s f) (hx : x ∈ s) (hz : z ∈ s) (hxy : x ≤ y) (hyz : y < z) (h : f y ≤ f z) : f x ≤ f y := hf.dual.le_left_of_right_le'' hx hz hxy hyz h end LinearOrderedCancelAddCommMonoid end LinearOrderedField
Mathlib/Analysis/Convex/Function.lean
1,098
1,106
/- Copyright (c) 2020 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.Algebra.BigOperators.Ring.Finset import Mathlib.Algebra.Module.BigOperators import Mathlib.NumberTheory.Divisors import Mathlib.Data.Nat.Squarefree import Mathlib.Data.Nat.GCD.BigOperators import Mathlib.Data.Nat.Factorization.Induction import Mathlib.Tactic.ArithMult /-! # Arithmetic Functions and Dirichlet Convolution This file defines arithmetic functions, which are functions from `ℕ` to a specified type that map 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. These arithmetic functions are endowed with a multiplication, given by Dirichlet convolution, and pointwise addition, to form the Dirichlet ring. ## Main Definitions * `ArithmeticFunction R` consists of functions `f : ℕ → R` such that `f 0 = 0`. * An arithmetic function `f` `IsMultiplicative` when `x.Coprime y → f (x * y) = f x * f y`. * The pointwise operations `pmul` and `ppow` differ from the multiplication and power instances on `ArithmeticFunction R`, which use Dirichlet multiplication. * `ζ` is the arithmetic function such that `ζ x = 1` for `0 < x`. * `σ k` is the arithmetic function such that `σ k x = ∑ y ∈ divisors x, y ^ k` for `0 < x`. * `pow k` is the arithmetic function such that `pow k x = x ^ k` for `0 < x`. * `id` is the identity arithmetic function on `ℕ`. * `ω n` is the number of distinct prime factors of `n`. * `Ω n` is the number of prime factors of `n` counted with multiplicity. * `μ` is the Möbius function (spelled `moebius` in code). ## Main Results * Several forms of Möbius inversion: * `sum_eq_iff_sum_mul_moebius_eq` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_of_nonzero` for functions to a `CommGroupWithZero` * And variants that apply when the equalities only hold on a set `S : Set ℕ` such that `m ∣ n → n ∈ S → m ∈ S`: * `sum_eq_iff_sum_mul_moebius_eq_on` for functions to a `CommRing` * `sum_eq_iff_sum_smul_moebius_eq_on` for functions to an `AddCommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on` for functions to a `CommGroup` * `prod_eq_iff_prod_pow_moebius_eq_on_of_nonzero` for functions to a `CommGroupWithZero` ## Notation All notation is localized in the namespace `ArithmeticFunction`. The arithmetic functions `ζ`, `σ`, `ω`, `Ω` and `μ` have Greek letter names. In addition, there are separate locales `ArithmeticFunction.zeta` for `ζ`, `ArithmeticFunction.sigma` for `σ`, `ArithmeticFunction.omega` for `ω`, `ArithmeticFunction.Omega` for `Ω`, and `ArithmeticFunction.Moebius` for `μ`, to allow for selective access to these notations. The arithmetic function $$n \mapsto \prod_{p \mid n} f(p)$$ is given custom notation `∏ᵖ p ∣ n, f p` when applied to `n`. ## Tags arithmetic functions, dirichlet convolution, divisors -/ open Finset open Nat variable (R : Type*) /-- An arithmetic function is a function from `ℕ` that maps 0 to 0. In the literature, they are often instead defined as functions from `ℕ+`. Multiplication on `ArithmeticFunctions` is by Dirichlet convolution. -/ def ArithmeticFunction [Zero R] := ZeroHom ℕ R instance ArithmeticFunction.zero [Zero R] : Zero (ArithmeticFunction R) := inferInstanceAs (Zero (ZeroHom ℕ R)) instance [Zero R] : Inhabited (ArithmeticFunction R) := inferInstanceAs (Inhabited (ZeroHom ℕ R)) variable {R} namespace ArithmeticFunction section Zero variable [Zero R] instance : FunLike (ArithmeticFunction R) ℕ R := inferInstanceAs (FunLike (ZeroHom ℕ R) ℕ R) @[simp] theorem toFun_eq (f : ArithmeticFunction R) : f.toFun = f := rfl @[simp] theorem coe_mk (f : ℕ → R) (hf) : @DFunLike.coe (ArithmeticFunction R) _ _ _ (ZeroHom.mk f hf) = f := rfl @[simp] theorem map_zero {f : ArithmeticFunction R} : f 0 = 0 := ZeroHom.map_zero' f theorem coe_inj {f g : ArithmeticFunction R} : (f : ℕ → R) = g ↔ f = g := DFunLike.coe_fn_eq @[simp] theorem zero_apply {x : ℕ} : (0 : ArithmeticFunction R) x = 0 := ZeroHom.zero_apply x @[ext] theorem ext ⦃f g : ArithmeticFunction R⦄ (h : ∀ x, f x = g x) : f = g := ZeroHom.ext h section One variable [One R] instance one : One (ArithmeticFunction R) := ⟨⟨fun x => ite (x = 1) 1 0, rfl⟩⟩ theorem one_apply {x : ℕ} : (1 : ArithmeticFunction R) x = ite (x = 1) 1 0 := rfl @[simp] theorem one_one : (1 : ArithmeticFunction R) 1 = 1 := rfl @[simp] theorem one_apply_ne {x : ℕ} (h : x ≠ 1) : (1 : ArithmeticFunction R) x = 0 := if_neg h end One end Zero /-- Coerce an arithmetic function with values in `ℕ` to one with values in `R`. We cannot inline this in `natCoe` because it gets unfolded too much. -/ @[coe] def natToArithmeticFunction [AddMonoidWithOne R] : (ArithmeticFunction ℕ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance natCoe [AddMonoidWithOne R] : Coe (ArithmeticFunction ℕ) (ArithmeticFunction R) := ⟨natToArithmeticFunction⟩ @[simp] theorem natCoe_nat (f : ArithmeticFunction ℕ) : natToArithmeticFunction f = f := ext fun _ => cast_id _ @[simp] theorem natCoe_apply [AddMonoidWithOne R] {f : ArithmeticFunction ℕ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl /-- Coerce an arithmetic function with values in `ℤ` to one with values in `R`. We cannot inline this in `intCoe` because it gets unfolded too much. -/ @[coe] def ofInt [AddGroupWithOne R] : (ArithmeticFunction ℤ) → (ArithmeticFunction R) := fun f => ⟨fun n => ↑(f n), by simp⟩ instance intCoe [AddGroupWithOne R] : Coe (ArithmeticFunction ℤ) (ArithmeticFunction R) := ⟨ofInt⟩ @[simp] theorem intCoe_int (f : ArithmeticFunction ℤ) : ofInt f = f := ext fun _ => Int.cast_id @[simp] theorem intCoe_apply [AddGroupWithOne R] {f : ArithmeticFunction ℤ} {x : ℕ} : (f : ArithmeticFunction R) x = f x := rfl @[simp] theorem coe_coe [AddGroupWithOne R] {f : ArithmeticFunction ℕ} : ((f : ArithmeticFunction ℤ) : ArithmeticFunction R) = (f : ArithmeticFunction R) := by ext simp @[simp] theorem natCoe_one [AddMonoidWithOne R] : ((1 : ArithmeticFunction ℕ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] @[simp] theorem intCoe_one [AddGroupWithOne R] : ((1 : ArithmeticFunction ℤ) : ArithmeticFunction R) = 1 := by ext n simp [one_apply] section AddMonoid variable [AddMonoid R] instance add : Add (ArithmeticFunction R) := ⟨fun f g => ⟨fun n => f n + g n, by simp⟩⟩ @[simp] theorem add_apply {f g : ArithmeticFunction R} {n : ℕ} : (f + g) n = f n + g n := rfl instance instAddMonoid : AddMonoid (ArithmeticFunction R) := { ArithmeticFunction.zero R, ArithmeticFunction.add with add_assoc := fun _ _ _ => ext fun _ => add_assoc _ _ _ zero_add := fun _ => ext fun _ => zero_add _ add_zero := fun _ => ext fun _ => add_zero _ nsmul := nsmulRec } end AddMonoid instance instAddMonoidWithOne [AddMonoidWithOne R] : AddMonoidWithOne (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid, ArithmeticFunction.one with natCast := fun n => ⟨fun x => if x = 1 then (n : R) else 0, by simp⟩ natCast_zero := by ext; simp natCast_succ := fun n => by ext x; by_cases h : x = 1 <;> simp [h] } instance instAddCommMonoid [AddCommMonoid R] : AddCommMonoid (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with add_comm := fun _ _ => ext fun _ => add_comm _ _ } instance [NegZeroClass R] : Neg (ArithmeticFunction R) where neg f := ⟨fun n => -f n, by simp⟩ instance [AddGroup R] : AddGroup (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoid with neg_add_cancel := fun _ => ext fun _ => neg_add_cancel _ zsmul := zsmulRec } instance [AddCommGroup R] : AddCommGroup (ArithmeticFunction R) := { show AddGroup (ArithmeticFunction R) by infer_instance with add_comm := fun _ _ ↦ add_comm _ _ } section SMul variable {M : Type*} [Zero R] [AddCommMonoid M] [SMul R M] /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance : SMul (ArithmeticFunction R) (ArithmeticFunction M) := ⟨fun f g => ⟨fun n => ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd, by simp⟩⟩ @[simp] theorem smul_apply {f : ArithmeticFunction R} {g : ArithmeticFunction M} {n : ℕ} : (f • g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst • g x.snd := rfl end SMul /-- The Dirichlet convolution of two arithmetic functions `f` and `g` is another arithmetic function such that `(f * g) n` is the sum of `f x * g y` over all `(x,y)` such that `x * y = n`. -/ instance [Semiring R] : Mul (ArithmeticFunction R) := ⟨(· • ·)⟩ @[simp] theorem mul_apply [Semiring R] {f g : ArithmeticFunction R} {n : ℕ} : (f * g) n = ∑ x ∈ divisorsAntidiagonal n, f x.fst * g x.snd := rfl theorem mul_apply_one [Semiring R] {f g : ArithmeticFunction R} : (f * g) 1 = f 1 * g 1 := by simp @[simp, norm_cast] theorem natCoe_mul [Semiring R] {f g : ArithmeticFunction ℕ} : (↑(f * g) : ArithmeticFunction R) = f * g := by ext n simp @[simp, norm_cast] theorem intCoe_mul [Ring R] {f g : ArithmeticFunction ℤ} : (↑(f * g) : ArithmeticFunction R) = ↑f * g := by ext n simp section Module variable {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] theorem mul_smul' (f g : ArithmeticFunction R) (h : ArithmeticFunction M) : (f * g) • h = f • g • h := by ext n simp only [mul_apply, smul_apply, sum_smul, mul_smul, smul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l * j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i * k, l), (i, k)⟩) <;> aesop (add simp mul_assoc) theorem one_smul' (b : ArithmeticFunction M) : (1 : ArithmeticFunction R) • b = b := by ext x rw [smul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(1, x)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro y ymem ynmem have y1ne : y.fst ≠ 1 := fun con => by simp_all [Prod.ext_iff] simp [y1ne] end Module section Semiring variable [Semiring R] instance instMonoid : Monoid (ArithmeticFunction R) := { one := One.one mul := Mul.mul one_mul := one_smul' mul_one := fun f => by ext x rw [mul_apply] by_cases x0 : x = 0 · simp [x0] have h : {(x, 1)} ⊆ divisorsAntidiagonal x := by simp [x0] rw [← sum_subset h] · simp intro ⟨y₁, y₂⟩ ymem ynmem have y2ne : y₂ ≠ 1 := by intro con simp_all simp [y2ne] mul_assoc := mul_smul' } instance instSemiring : Semiring (ArithmeticFunction R) := { ArithmeticFunction.instAddMonoidWithOne, ArithmeticFunction.instMonoid, ArithmeticFunction.instAddCommMonoid with zero_mul := fun f => by ext simp mul_zero := fun f => by ext simp left_distrib := fun a b c => by ext simp [← sum_add_distrib, mul_add] right_distrib := fun a b c => by ext simp [← sum_add_distrib, add_mul] } end Semiring instance [CommSemiring R] : CommSemiring (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with mul_comm := fun f g => by ext rw [mul_apply, ← map_swap_divisorsAntidiagonal, sum_map] simp [mul_comm] } instance [CommRing R] : CommRing (ArithmeticFunction R) := { ArithmeticFunction.instSemiring with neg_add_cancel := neg_add_cancel mul_comm := mul_comm zsmul := (· • ·) } instance {M : Type*} [Semiring R] [AddCommMonoid M] [Module R M] : Module (ArithmeticFunction R) (ArithmeticFunction M) where one_smul := one_smul' mul_smul := mul_smul' smul_add r x y := by ext simp only [sum_add_distrib, smul_add, smul_apply, add_apply] smul_zero r := by ext simp only [smul_apply, sum_const_zero, smul_zero, zero_apply] add_smul r s x := by ext simp only [add_smul, sum_add_distrib, smul_apply, add_apply] zero_smul r := by ext simp only [smul_apply, sum_const_zero, zero_smul, zero_apply] section Zeta /-- `ζ 0 = 0`, otherwise `ζ x = 1`. The Dirichlet Series is the Riemann `ζ`. -/ def zeta : ArithmeticFunction ℕ := ⟨fun x => ite (x = 0) 0 1, rfl⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "ζ" => ArithmeticFunction.zeta @[inherit_doc] scoped[ArithmeticFunction.zeta] notation "ζ" => ArithmeticFunction.zeta @[simp] theorem zeta_apply {x : ℕ} : ζ x = if x = 0 then 0 else 1 := rfl theorem zeta_apply_ne {x : ℕ} (h : x ≠ 0) : ζ x = 1 := if_neg h -- Porting note: removed `@[simp]`, LHS not in normal form theorem coe_zeta_smul_apply {M} [Semiring R] [AddCommMonoid M] [MulAction R M] {f : ArithmeticFunction M} {x : ℕ} : ((↑ζ : ArithmeticFunction R) • f) x = ∑ i ∈ divisors x, f i := by rw [smul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.snd · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (left_ne_zero_of_mul h), cast_one, one_smul] · rw [← map_div_left_divisors, sum_map, Function.Embedding.coeFn_mk] theorem coe_zeta_mul_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (↑ζ * f) x = ∑ i ∈ divisors x, f i := coe_zeta_smul_apply theorem coe_mul_zeta_apply [Semiring R] {f : ArithmeticFunction R} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by rw [mul_apply] trans ∑ i ∈ divisorsAntidiagonal x, f i.1 · refine sum_congr rfl fun i hi => ?_ rcases mem_divisorsAntidiagonal.1 hi with ⟨rfl, h⟩ rw [natCoe_apply, zeta_apply_ne (right_ne_zero_of_mul h), cast_one, mul_one] · rw [← map_div_right_divisors, sum_map, Function.Embedding.coeFn_mk] theorem zeta_mul_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (ζ * f) x = ∑ i ∈ divisors x, f i := by rw [← natCoe_nat ζ, coe_zeta_mul_apply] theorem mul_zeta_apply {f : ArithmeticFunction ℕ} {x : ℕ} : (f * ζ) x = ∑ i ∈ divisors x, f i := by rw [← natCoe_nat ζ, coe_mul_zeta_apply] end Zeta open ArithmeticFunction section Pmul /-- This is the pointwise product of `ArithmeticFunction`s. -/ def pmul [MulZeroClass R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun x => f x * g x, by simp⟩ @[simp] theorem pmul_apply [MulZeroClass R] {f g : ArithmeticFunction R} {x : ℕ} : f.pmul g x = f x * g x := rfl theorem pmul_comm [CommMonoidWithZero R] (f g : ArithmeticFunction R) : f.pmul g = g.pmul f := by ext simp [mul_comm] lemma pmul_assoc [SemigroupWithZero R] (f₁ f₂ f₃ : ArithmeticFunction R) : pmul (pmul f₁ f₂) f₃ = pmul f₁ (pmul f₂ f₃) := by ext simp only [pmul_apply, mul_assoc] section NonAssocSemiring variable [NonAssocSemiring R] @[simp] theorem pmul_zeta (f : ArithmeticFunction R) : f.pmul ↑ζ = f := by ext x cases x <;> simp [Nat.succ_ne_zero] @[simp] theorem zeta_pmul (f : ArithmeticFunction R) : (ζ : ArithmeticFunction R).pmul f = f := by ext x cases x <;> simp [Nat.succ_ne_zero] end NonAssocSemiring variable [Semiring R] /-- This is the pointwise power of `ArithmeticFunction`s. -/ def ppow (f : ArithmeticFunction R) (k : ℕ) : ArithmeticFunction R := if h0 : k = 0 then ζ else ⟨fun x ↦ f x ^ k, by simp_rw [map_zero, zero_pow h0]⟩ @[simp] theorem ppow_zero {f : ArithmeticFunction R} : f.ppow 0 = ζ := by rw [ppow, dif_pos rfl] @[simp] theorem ppow_apply {f : ArithmeticFunction R} {k x : ℕ} (kpos : 0 < k) : f.ppow k x = f x ^ k := by rw [ppow, dif_neg (Nat.ne_of_gt kpos), coe_mk] theorem ppow_succ' {f : ArithmeticFunction R} {k : ℕ} : f.ppow (k + 1) = f.pmul (f.ppow k) := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ'] induction k <;> simp theorem ppow_succ {f : ArithmeticFunction R} {k : ℕ} {kpos : 0 < k} : f.ppow (k + 1) = (f.ppow k).pmul f := by ext x rw [ppow_apply (Nat.succ_pos k), _root_.pow_succ] induction k <;> simp end Pmul section Pdiv /-- This is the pointwise division of `ArithmeticFunction`s. -/ def pdiv [GroupWithZero R] (f g : ArithmeticFunction R) : ArithmeticFunction R := ⟨fun n => f n / g n, by simp only [map_zero, ne_eq, not_true, div_zero]⟩ @[simp] theorem pdiv_apply [GroupWithZero R] (f g : ArithmeticFunction R) (n : ℕ) : pdiv f g n = f n / g n := rfl /-- This result only holds for `DivisionSemiring`s instead of `GroupWithZero`s because zeta takes values in ℕ, and hence the coercion requires an `AddMonoidWithOne`. TODO: Generalise zeta -/ @[simp] theorem pdiv_zeta [DivisionSemiring R] (f : ArithmeticFunction R) : pdiv f zeta = f := by ext n cases n <;> simp [succ_ne_zero] end Pdiv section ProdPrimeFactors /-- The map $n \mapsto \prod_{p \mid n} f(p)$ as an arithmetic function -/ def prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : ArithmeticFunction R where toFun d := if d = 0 then 0 else ∏ p ∈ d.primeFactors, f p map_zero' := if_pos rfl open Batteries.ExtendedBinder /-- `∏ᵖ p ∣ n, f p` is custom notation for `prodPrimeFactors f n` -/ scoped syntax (name := bigproddvd) "∏ᵖ " extBinder " ∣ " term ", " term:67 : term scoped macro_rules (kind := bigproddvd) | `(∏ᵖ $x:ident ∣ $n, $r) => `(prodPrimeFactors (fun $x ↦ $r) $n) @[simp] theorem prodPrimeFactors_apply [CommMonoidWithZero R] {f : ℕ → R} {n : ℕ} (hn : n ≠ 0) : ∏ᵖ p ∣ n, f p = ∏ p ∈ n.primeFactors, f p := if_neg hn end ProdPrimeFactors /-- Multiplicative functions -/ def IsMultiplicative [MonoidWithZero R] (f : ArithmeticFunction R) : Prop := f 1 = 1 ∧ ∀ {m n : ℕ}, m.Coprime n → f (m * n) = f m * f n namespace IsMultiplicative section MonoidWithZero variable [MonoidWithZero R] @[simp, arith_mult] theorem map_one {f : ArithmeticFunction R} (h : f.IsMultiplicative) : f 1 = 1 := h.1 @[simp] theorem map_mul_of_coprime {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {m n : ℕ} (h : m.Coprime n) : f (m * n) = f m * f n := hf.2 h end MonoidWithZero open scoped Function in -- required for scoped `on` notation theorem map_prod {ι : Type*} [CommMonoidWithZero R] (g : ι → ℕ) {f : ArithmeticFunction R} (hf : f.IsMultiplicative) (s : Finset ι) (hs : (s : Set ι).Pairwise (Coprime on g)) : f (∏ i ∈ s, g i) = ∏ i ∈ s, f (g i) := by classical induction s using Finset.induction_on with | empty => simp [hf] | insert _ _ has ih => rw [coe_insert, Set.pairwise_insert_of_symmetric (Coprime.symmetric.comap g)] at hs rw [prod_insert has, prod_insert has, hf.map_mul_of_coprime, ih hs.1] exact .prod_right fun i hi => hs.2 _ hi (hi.ne_of_not_mem has).symm theorem map_prod_of_prime [CommMonoidWithZero R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (t : Finset ℕ) (ht : ∀ p ∈ t, p.Prime) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod _ h_mult t fun x hx y hy hxy => (coprime_primes (ht x hx) (ht y hy)).mpr hxy theorem map_prod_of_subset_primeFactors [CommMonoidWithZero R] {f : ArithmeticFunction R} (h_mult : ArithmeticFunction.IsMultiplicative f) (l : ℕ) (t : Finset ℕ) (ht : t ⊆ l.primeFactors) : f (∏ a ∈ t, a) = ∏ a ∈ t, f a := map_prod_of_prime h_mult t fun _ a => prime_of_mem_primeFactors (ht a) theorem map_div_of_coprime [GroupWithZero R] {f : ArithmeticFunction R} (hf : IsMultiplicative f) {l d : ℕ} (hdl : d ∣ l) (hl : (l / d).Coprime d) (hd : f d ≠ 0) : f (l / d) = f l / f d := by apply (div_eq_of_eq_mul hd ..).symm rw [← hf.right hl, Nat.div_mul_cancel hdl] @[arith_mult] theorem natCast {f : ArithmeticFunction ℕ} [Semiring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ @[arith_mult] theorem intCast {f : ArithmeticFunction ℤ} [Ring R] (h : f.IsMultiplicative) : IsMultiplicative (f : ArithmeticFunction R) := ⟨by simp [h], fun {m n} cop => by simp [h.2 cop]⟩ @[arith_mult] theorem mul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f * g) := by refine ⟨by simp [hf.1, hg.1], ?_⟩ simp only [mul_apply] intro m n cop rw [sum_mul_sum, ← sum_product'] symm apply sum_nbij fun ((i, j), k, l) ↦ (i * k, j * l) · rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ h simp only [mem_divisorsAntidiagonal, Ne, mem_product] at h rcases h with ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ simp only [mem_divisorsAntidiagonal, Nat.mul_eq_zero, Ne] constructor · ring rw [Nat.mul_eq_zero] at * apply not_or_intro ha hb · simp only [Set.InjOn, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Prod.mk_inj] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ ⟨⟨c1, c2⟩, ⟨d1, d2⟩⟩ hcd h simp only [Prod.mk_inj] at h ext <;> dsimp only · trans Nat.gcd (a1 * a2) (a1 * b1) · rw [Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.1, Nat.gcd_mul_left, cop.coprime_mul_left.coprime_mul_right_right.gcd_eq_one, mul_one] · trans Nat.gcd (a1 * a2) (a2 * b2) · rw [mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.1.1, h.2, mul_comm, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a1 * b1) · rw [mul_comm, Nat.gcd_mul_right, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.1, mul_comm c1 d1, Nat.gcd_mul_left, cop.coprime_mul_right.coprime_mul_left_right.symm.gcd_eq_one, mul_one] · trans Nat.gcd (b1 * b2) (a2 * b2) · rw [Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · rw [← hcd.1.1, ← hcd.2.1] at cop rw [← hcd.2.1, h.2, Nat.gcd_mul_right, cop.coprime_mul_left.coprime_mul_right_right.symm.gcd_eq_one, one_mul] · simp only [Set.SurjOn, Set.subset_def, mem_coe, mem_divisorsAntidiagonal, Ne, mem_product, Set.mem_image, exists_prop, Prod.mk_inj] rintro ⟨b1, b2⟩ h dsimp at h use ((b1.gcd m, b2.gcd m), (b1.gcd n, b2.gcd n)) rw [← cop.gcd_mul _, ← cop.gcd_mul _, ← h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop h.1, Nat.gcd_mul_gcd_of_coprime_of_mul_eq_mul cop.symm _] · rw [Nat.mul_eq_zero, not_or] at h simp [h.2.1, h.2.2] rw [mul_comm n m, h.1] · simp only [mem_divisorsAntidiagonal, Ne, mem_product] rintro ⟨⟨a1, a2⟩, ⟨b1, b2⟩⟩ ⟨⟨rfl, ha⟩, ⟨rfl, hb⟩⟩ dsimp only rw [hf.map_mul_of_coprime cop.coprime_mul_right.coprime_mul_right_right, hg.map_mul_of_coprime cop.coprime_mul_left.coprime_mul_left_right] ring @[arith_mult] theorem pmul [CommSemiring R] {f g : ArithmeticFunction R} (hf : f.IsMultiplicative) (hg : g.IsMultiplicative) : IsMultiplicative (f.pmul g) := ⟨by simp [hf, hg], fun {m n} cop => by simp only [pmul_apply, hf.map_mul_of_coprime cop, hg.map_mul_of_coprime cop] ring⟩ @[arith_mult] theorem pdiv [CommGroupWithZero R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) : IsMultiplicative (pdiv f g) := ⟨by simp [hf, hg], fun {m n} cop => by simp only [pdiv_apply, map_mul_of_coprime hf cop, map_mul_of_coprime hg cop, div_eq_mul_inv, mul_inv] apply mul_mul_mul_comm ⟩ /-- For any multiplicative function `f` and any `n > 0`, we can evaluate `f n` by evaluating `f` at `p ^ k` over the factorization of `n` -/ theorem multiplicative_factorization [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) {n : ℕ} (hn : n ≠ 0) : f n = n.factorization.prod fun p k => f (p ^ k) := Nat.multiplicative_factorization f (fun _ _ => hf.2) hf.1 hn /-- A recapitulation of the definition of multiplicative that is simpler for proofs -/ theorem iff_ne_zero [MonoidWithZero R] {f : ArithmeticFunction R} : IsMultiplicative f ↔ f 1 = 1 ∧ ∀ {m n : ℕ}, m ≠ 0 → n ≠ 0 → m.Coprime n → f (m * n) = f m * f n := by refine and_congr_right' (forall₂_congr fun m n => ⟨fun h _ _ => h, fun h hmn => ?_⟩) rcases eq_or_ne m 0 with (rfl | hm) · simp rcases eq_or_ne n 0 with (rfl | hn) · simp exact h hm hn hmn /-- Two multiplicative functions `f` and `g` are equal if and only if they agree on prime powers -/ theorem eq_iff_eq_on_prime_powers [CommMonoidWithZero R] (f : ArithmeticFunction R) (hf : f.IsMultiplicative) (g : ArithmeticFunction R) (hg : g.IsMultiplicative) : f = g ↔ ∀ p i : ℕ, Nat.Prime p → f (p ^ i) = g (p ^ i) := by constructor · intro h p i _ rw [h] intro h ext n by_cases hn : n = 0 · rw [hn, ArithmeticFunction.map_zero, ArithmeticFunction.map_zero] rw [multiplicative_factorization f hf hn, multiplicative_factorization g hg hn] exact Finset.prod_congr rfl fun p hp ↦ h p _ (Nat.prime_of_mem_primeFactors hp) @[arith_mult] theorem prodPrimeFactors [CommMonoidWithZero R] (f : ℕ → R) : IsMultiplicative (prodPrimeFactors f) := by rw [iff_ne_zero] simp only [ne_eq, one_ne_zero, not_false_eq_true, prodPrimeFactors_apply, primeFactors_one, prod_empty, true_and] intro x y hx hy hxy have hxy₀ : x * y ≠ 0 := mul_ne_zero hx hy rw [prodPrimeFactors_apply hxy₀, prodPrimeFactors_apply hx, prodPrimeFactors_apply hy, Nat.primeFactors_mul hx hy, ← Finset.prod_union hxy.disjoint_primeFactors] theorem prodPrimeFactors_add_of_squarefree [CommSemiring R] {f g : ArithmeticFunction R} (hf : IsMultiplicative f) (hg : IsMultiplicative g) {n : ℕ} (hn : Squarefree n) : ∏ᵖ p ∣ n, (f + g) p = (f * g) n := by rw [prodPrimeFactors_apply hn.ne_zero] simp_rw [add_apply (f := f) (g := g)] rw [Finset.prod_add, mul_apply, sum_divisorsAntidiagonal (f · * g ·), ← divisors_filter_squarefree_of_squarefree hn, sum_divisors_filter_squarefree hn.ne_zero, factors_eq] apply Finset.sum_congr rfl intro t ht rw [t.prod_val, Function.id_def, ← prod_primeFactors_sdiff_of_squarefree hn (Finset.mem_powerset.mp ht), hf.map_prod_of_subset_primeFactors n t (Finset.mem_powerset.mp ht), ← hg.map_prod_of_subset_primeFactors n (_ \ t) Finset.sdiff_subset] theorem lcm_apply_mul_gcd_apply [CommMonoidWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} : f (x.lcm y) * f (x.gcd y) = f x * f y := by by_cases hx : x = 0 · simp only [hx, f.map_zero, zero_mul, Nat.lcm_zero_left, Nat.gcd_zero_left] by_cases hy : y = 0 · simp only [hy, f.map_zero, mul_zero, Nat.lcm_zero_right, Nat.gcd_zero_right, zero_mul] have hgcd_ne_zero : x.gcd y ≠ 0 := gcd_ne_zero_left hx have hlcm_ne_zero : x.lcm y ≠ 0 := lcm_ne_zero hx hy have hfi_zero : ∀ {i}, f (i ^ 0) = 1 := by intro i; rw [Nat.pow_zero, hf.1] iterate 4 rw [hf.multiplicative_factorization f (by assumption), Finsupp.prod_of_support_subset _ _ _ (fun _ _ => hfi_zero) (s := (x.primeFactors ∪ y.primeFactors))] · rw [← Finset.prod_mul_distrib, ← Finset.prod_mul_distrib] apply Finset.prod_congr rfl intro p _ rcases Nat.le_or_le (x.factorization p) (y.factorization p) with h | h <;> simp only [factorization_lcm hx hy, Finsupp.sup_apply, h, sup_of_le_right, sup_of_le_left, inf_of_le_right, Nat.factorization_gcd hx hy, Finsupp.inf_apply, inf_of_le_left, mul_comm] · apply Finset.subset_union_right · apply Finset.subset_union_left · rw [factorization_gcd hx hy, Finsupp.support_inf] apply Finset.inter_subset_union · simp [factorization_lcm hx hy] theorem map_gcd [CommGroupWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} (hf_lcm : f (x.lcm y) ≠ 0) : f (x.gcd y) = f x * f y / f (x.lcm y) := by rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_left₀ _ hf_lcm] theorem map_lcm [CommGroupWithZero R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {x y : ℕ} (hf_gcd : f (x.gcd y) ≠ 0) : f (x.lcm y) = f x * f y / f (x.gcd y) := by rw [← hf.lcm_apply_mul_gcd_apply, mul_div_cancel_right₀ _ hf_gcd] theorem eq_zero_of_squarefree_of_dvd_eq_zero [MonoidWithZero R] {f : ArithmeticFunction R} (hf : IsMultiplicative f) {m n : ℕ} (hn : Squarefree n) (hmn : m ∣ n) (h_zero : f m = 0) : f n = 0 := by rcases hmn with ⟨k, rfl⟩ simp only [MulZeroClass.zero_mul, eq_self_iff_true, hf.map_mul_of_coprime (coprime_of_squarefree_mul hn), h_zero] end IsMultiplicative section SpecialFunctions /-- The identity on `ℕ` as an `ArithmeticFunction`. -/ def id : ArithmeticFunction ℕ := ⟨_root_.id, rfl⟩ @[simp] theorem id_apply {x : ℕ} : id x = x := rfl /-- `pow k n = n ^ k`, except `pow 0 0 = 0`. -/ def pow (k : ℕ) : ArithmeticFunction ℕ := id.ppow k @[simp] theorem pow_apply {k n : ℕ} : pow k n = if k = 0 ∧ n = 0 then 0 else n ^ k := by cases k <;> simp [pow] theorem pow_zero_eq_zeta : pow 0 = ζ := by ext n simp /-- `σ k n` is the sum of the `k`th powers of the divisors of `n` -/ def sigma (k : ℕ) : ArithmeticFunction ℕ := ⟨fun n => ∑ d ∈ divisors n, d ^ k, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "σ" => ArithmeticFunction.sigma @[inherit_doc] scoped[ArithmeticFunction.sigma] notation "σ" => ArithmeticFunction.sigma theorem sigma_apply {k n : ℕ} : σ k n = ∑ d ∈ divisors n, d ^ k := rfl theorem sigma_apply_prime_pow {k p i : ℕ} (hp : p.Prime) : σ k (p ^ i) = ∑ j ∈ .range (i + 1), p ^ (j * k) := by simp [sigma_apply, divisors_prime_pow hp, Nat.pow_mul] theorem sigma_one_apply (n : ℕ) : σ 1 n = ∑ d ∈ divisors n, d := by simp [sigma_apply] theorem sigma_one_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 1 (p ^ i) = ∑ k ∈ .range (i + 1), p ^ k := by simp [sigma_apply_prime_pow hp] theorem sigma_zero_apply (n : ℕ) : σ 0 n = #n.divisors := by simp [sigma_apply] theorem sigma_zero_apply_prime_pow {p i : ℕ} (hp : p.Prime) : σ 0 (p ^ i) = i + 1 := by simp [sigma_apply_prime_pow hp] theorem zeta_mul_pow_eq_sigma {k : ℕ} : ζ * pow k = σ k := by ext rw [sigma, zeta_mul_apply] apply sum_congr rfl intro x hx rw [pow_apply, if_neg (not_and_of_not_right _ _)] contrapose! hx simp [hx] @[arith_mult] theorem isMultiplicative_one [MonoidWithZero R] : IsMultiplicative (1 : ArithmeticFunction R) := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by intro m n hm _hn hmn rcases eq_or_ne m 1 with (rfl | hm') · simp rw [one_apply_ne, one_apply_ne hm', zero_mul] rw [Ne, mul_eq_one, not_and_or] exact Or.inl hm'⟩ @[arith_mult] theorem isMultiplicative_zeta : IsMultiplicative ζ := IsMultiplicative.iff_ne_zero.2 ⟨by simp, by simp +contextual⟩ @[arith_mult] theorem isMultiplicative_id : IsMultiplicative ArithmeticFunction.id := ⟨rfl, fun {_ _} _ => rfl⟩ @[arith_mult] theorem IsMultiplicative.ppow [CommSemiring R] {f : ArithmeticFunction R} (hf : f.IsMultiplicative) {k : ℕ} : IsMultiplicative (f.ppow k) := by induction k with | zero => exact isMultiplicative_zeta.natCast | succ k hi => rw [ppow_succ']; apply hf.pmul hi @[arith_mult] theorem isMultiplicative_pow {k : ℕ} : IsMultiplicative (pow k) := isMultiplicative_id.ppow @[arith_mult] theorem isMultiplicative_sigma {k : ℕ} : IsMultiplicative (σ k) := by rw [← zeta_mul_pow_eq_sigma] apply isMultiplicative_zeta.mul isMultiplicative_pow /-- `Ω n` is the number of prime factors of `n`. -/ def cardFactors : ArithmeticFunction ℕ := ⟨fun n => n.primeFactorsList.length, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "Ω" => ArithmeticFunction.cardFactors @[inherit_doc] scoped[ArithmeticFunction.Omega] notation "Ω" => ArithmeticFunction.cardFactors theorem cardFactors_apply {n : ℕ} : Ω n = n.primeFactorsList.length := rfl lemma cardFactors_zero : Ω 0 = 0 := by simp @[simp] theorem cardFactors_one : Ω 1 = 0 := by simp [cardFactors_apply] @[simp] theorem cardFactors_eq_one_iff_prime {n : ℕ} : Ω n = 1 ↔ n.Prime := by refine ⟨fun h => ?_, fun h => List.length_eq_one_iff.2 ⟨n, primeFactorsList_prime h⟩⟩ cases n with | zero => simp at h | succ n => rcases List.length_eq_one_iff.1 h with ⟨x, hx⟩ rw [← prod_primeFactorsList n.add_one_ne_zero, hx, List.prod_singleton] apply prime_of_mem_primeFactorsList rw [hx, List.mem_singleton] theorem cardFactors_mul {m n : ℕ} (m0 : m ≠ 0) (n0 : n ≠ 0) : Ω (m * n) = Ω m + Ω n := by rw [cardFactors_apply, cardFactors_apply, cardFactors_apply, ← Multiset.coe_card, ← factors_eq, UniqueFactorizationMonoid.normalizedFactors_mul m0 n0, factors_eq, factors_eq, Multiset.card_add, Multiset.coe_card, Multiset.coe_card] theorem cardFactors_multiset_prod {s : Multiset ℕ} (h0 : s.prod ≠ 0) : Ω s.prod = (Multiset.map Ω s).sum := by induction s using Multiset.induction_on with | empty => simp | cons ih => simp_all [cardFactors_mul, not_or] @[simp] theorem cardFactors_apply_prime {p : ℕ} (hp : p.Prime) : Ω p = 1 := cardFactors_eq_one_iff_prime.2 hp @[simp] theorem cardFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) : Ω (p ^ k) = k := by rw [cardFactors_apply, hp.primeFactorsList_pow, List.length_replicate] /-- `ω n` is the number of distinct prime factors of `n`. -/ def cardDistinctFactors : ArithmeticFunction ℕ := ⟨fun n => n.primeFactorsList.dedup.length, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "ω" => ArithmeticFunction.cardDistinctFactors @[inherit_doc] scoped[ArithmeticFunction.omega] notation "ω" => ArithmeticFunction.cardDistinctFactors theorem cardDistinctFactors_zero : ω 0 = 0 := by simp @[simp] theorem cardDistinctFactors_one : ω 1 = 0 := by simp [cardDistinctFactors] theorem cardDistinctFactors_apply {n : ℕ} : ω n = n.primeFactorsList.dedup.length := rfl theorem cardDistinctFactors_eq_cardFactors_iff_squarefree {n : ℕ} (h0 : n ≠ 0) : ω n = Ω n ↔ Squarefree n := by rw [squarefree_iff_nodup_primeFactorsList h0, cardDistinctFactors_apply] constructor <;> intro h · rw [← n.primeFactorsList.dedup_sublist.eq_of_length h] apply List.nodup_dedup · simp [h.dedup, cardFactors] @[simp] theorem cardDistinctFactors_apply_prime_pow {p k : ℕ} (hp : p.Prime) (hk : k ≠ 0) : ω (p ^ k) = 1 := by rw [cardDistinctFactors_apply, hp.primeFactorsList_pow, List.replicate_dedup hk, List.length_singleton] @[simp] theorem cardDistinctFactors_apply_prime {p : ℕ} (hp : p.Prime) : ω p = 1 := by rw [← pow_one p, cardDistinctFactors_apply_prime_pow hp one_ne_zero] /-- `μ` is the Möbius function. If `n` is squarefree with an even number of distinct prime factors, `μ n = 1`. If `n` is squarefree with an odd number of distinct prime factors, `μ n = -1`. If `n` is not squarefree, `μ n = 0`. -/ def moebius : ArithmeticFunction ℤ := ⟨fun n => if Squarefree n then (-1) ^ cardFactors n else 0, by simp⟩ @[inherit_doc] scoped[ArithmeticFunction] notation "μ" => ArithmeticFunction.moebius @[inherit_doc] scoped[ArithmeticFunction.Moebius] notation "μ" => ArithmeticFunction.moebius @[simp] theorem moebius_apply_of_squarefree {n : ℕ} (h : Squarefree n) : μ n = (-1) ^ cardFactors n := if_pos h @[simp] theorem moebius_eq_zero_of_not_squarefree {n : ℕ} (h : ¬Squarefree n) : μ n = 0 := if_neg h theorem moebius_apply_one : μ 1 = 1 := by simp theorem moebius_ne_zero_iff_squarefree {n : ℕ} : μ n ≠ 0 ↔ Squarefree n := by constructor <;> intro h · contrapose! h simp [h] · simp [h, pow_ne_zero] theorem moebius_eq_or (n : ℕ) : μ n = 0 ∨ μ n = 1 ∨ μ n = -1 := by simp only [moebius, coe_mk] split_ifs
· right exact neg_one_pow_eq_or .. · left rfl
Mathlib/NumberTheory/ArithmeticFunction.lean
981
984
/- Copyright (c) 2023 Peter Nelson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Peter Nelson -/ import Mathlib.SetTheory.Cardinal.Finite import Mathlib.Data.Set.Finite.Powerset /-! # Noncomputable Set Cardinality We define the cardinality of set `s` as a term `Set.encard s : ℕ∞` and a term `Set.ncard s : ℕ`. The latter takes the junk value of zero if `s` is infinite. Both functions are noncomputable, and are defined in terms of `ENat.card` (which takes a type as its argument); this file can be seen as an API for the same function in the special case where the type is a coercion of a `Set`, allowing for smoother interactions with the `Set` API. `Set.encard` never takes junk values, so is more mathematically natural than `Set.ncard`, even though it takes values in a less convenient type. It is probably the right choice in settings where one is concerned with the cardinalities of sets that may or may not be infinite. `Set.ncard` has a nicer codomain, but when using it, `Set.Finite` hypotheses are normally needed to make sure its values are meaningful. More generally, `Set.ncard` is intended to be used over the obvious alternative `Finset.card` when finiteness is 'propositional' rather than 'structural'. When working with sets that are finite by virtue of their definition, then `Finset.card` probably makes more sense. One setting where `Set.ncard` works nicely is in a type `α` with `[Finite α]`, where every set is automatically finite. In this setting, we use default arguments and a simple tactic so that finiteness goals are discharged automatically in `Set.ncard` theorems. ## Main Definitions * `Set.encard s` is the cardinality of the set `s` as an extended natural number, with value `⊤` if `s` is infinite. * `Set.ncard s` is the cardinality of the set `s` as a natural number, provided `s` is Finite. If `s` is Infinite, then `Set.ncard s = 0`. * `toFinite_tac` is a tactic that tries to synthesize a `Set.Finite s` argument with `Set.toFinite`. This will work for `s : Set α` where there is a `Finite α` instance. ## Implementation Notes The theorems in this file are very similar to those in `Data.Finset.Card`, but with `Set` operations instead of `Finset`. We first prove all the theorems for `Set.encard`, and then derive most of the `Set.ncard` results as a consequence. Things are done this way to avoid reliance on the `Finset` API for theorems about infinite sets, and to allow for a refactor that removes or modifies `Set.ncard` in the future. Nearly all the theorems for `Set.ncard` require finiteness of one or more of their arguments. We provide this assumption with a default argument of the form `(hs : s.Finite := by toFinite_tac)`, where `toFinite_tac` will find an `s.Finite` term in the cases where `s` is a set in a `Finite` type. Often, where there are two set arguments `s` and `t`, the finiteness of one follows from the other in the context of the theorem, in which case we only include the ones that are needed, and derive the other inside the proof. A few of the theorems, such as `ncard_union_le` do not require finiteness arguments; they are true by coincidence due to junk values. -/ namespace Set variable {α β : Type*} {s t : Set α} /-- The cardinality of a set as a term in `ℕ∞` -/ noncomputable def encard (s : Set α) : ℕ∞ := ENat.card s @[simp] theorem encard_univ_coe (s : Set α) : encard (univ : Set s) = encard s := by rw [encard, encard, ENat.card_congr (Equiv.Set.univ ↑s)] theorem encard_univ (α : Type*) : encard (univ : Set α) = ENat.card α := by rw [encard, ENat.card_congr (Equiv.Set.univ α)] theorem Finite.encard_eq_coe_toFinset_card (h : s.Finite) : s.encard = h.toFinset.card := by have := h.fintype rw [encard, ENat.card_eq_coe_fintype_card, toFinite_toFinset, toFinset_card] theorem encard_eq_coe_toFinset_card (s : Set α) [Fintype s] : encard s = s.toFinset.card := by have h := toFinite s rw [h.encard_eq_coe_toFinset_card, toFinite_toFinset] @[simp] theorem toENat_cardinalMk (s : Set α) : (Cardinal.mk s).toENat = s.encard := rfl theorem toENat_cardinalMk_subtype (P : α → Prop) : (Cardinal.mk {x // P x}).toENat = {x | P x}.encard := rfl @[simp] theorem coe_fintypeCard (s : Set α) [Fintype s] : Fintype.card s = s.encard := by simp [encard_eq_coe_toFinset_card] @[simp, norm_cast] theorem encard_coe_eq_coe_finsetCard (s : Finset α) : encard (s : Set α) = s.card := by rw [Finite.encard_eq_coe_toFinset_card (Finset.finite_toSet s)]; simp @[simp] theorem Infinite.encard_eq {s : Set α} (h : s.Infinite) : s.encard = ⊤ := by have := h.to_subtype rw [encard, ENat.card_eq_top_of_infinite] @[simp] theorem encard_eq_zero : s.encard = 0 ↔ s = ∅ := by rw [encard, ENat.card_eq_zero_iff_empty, isEmpty_subtype, eq_empty_iff_forall_not_mem] @[simp] theorem encard_empty : (∅ : Set α).encard = 0 := by rw [encard_eq_zero] theorem nonempty_of_encard_ne_zero (h : s.encard ≠ 0) : s.Nonempty := by rwa [nonempty_iff_ne_empty, Ne, ← encard_eq_zero] theorem encard_ne_zero : s.encard ≠ 0 ↔ s.Nonempty := by rw [ne_eq, encard_eq_zero, nonempty_iff_ne_empty] @[simp] theorem encard_pos : 0 < s.encard ↔ s.Nonempty := by rw [pos_iff_ne_zero, encard_ne_zero] protected alias ⟨_, Nonempty.encard_pos⟩ := encard_pos @[simp] theorem encard_singleton (e : α) : ({e} : Set α).encard = 1 := by rw [encard, ENat.card_eq_coe_fintype_card, Fintype.card_ofSubsingleton, Nat.cast_one] theorem encard_union_eq (h : Disjoint s t) : (s ∪ t).encard = s.encard + t.encard := by classical simp [encard, ENat.card_congr (Equiv.Set.union h)] theorem encard_insert_of_not_mem {a : α} (has : a ∉ s) : (insert a s).encard = s.encard + 1 := by rw [← union_singleton, encard_union_eq (by simpa), encard_singleton] theorem Finite.encard_lt_top (h : s.Finite) : s.encard < ⊤ := by induction s, h using Set.Finite.induction_on with | empty => simp | insert hat _ ht' => rw [encard_insert_of_not_mem hat] exact lt_tsub_iff_right.1 ht' theorem Finite.encard_eq_coe (h : s.Finite) : s.encard = ENat.toNat s.encard := (ENat.coe_toNat h.encard_lt_top.ne).symm theorem Finite.exists_encard_eq_coe (h : s.Finite) : ∃ (n : ℕ), s.encard = n := ⟨_, h.encard_eq_coe⟩ @[simp] theorem encard_lt_top_iff : s.encard < ⊤ ↔ s.Finite := ⟨fun h ↦ by_contra fun h' ↦ h.ne (Infinite.encard_eq h'), Finite.encard_lt_top⟩ @[simp] theorem encard_eq_top_iff : s.encard = ⊤ ↔ s.Infinite := by rw [← not_iff_not, ← Ne, ← lt_top_iff_ne_top, encard_lt_top_iff, not_infinite] alias ⟨_, encard_eq_top⟩ := encard_eq_top_iff theorem encard_ne_top_iff : s.encard ≠ ⊤ ↔ s.Finite := by simp theorem finite_of_encard_le_coe {k : ℕ} (h : s.encard ≤ k) : s.Finite := by rw [← encard_lt_top_iff]; exact h.trans_lt (WithTop.coe_lt_top _) theorem finite_of_encard_eq_coe {k : ℕ} (h : s.encard = k) : s.Finite := finite_of_encard_le_coe h.le theorem encard_le_coe_iff {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ ∃ (n₀ : ℕ), s.encard = n₀ ∧ n₀ ≤ k := ⟨fun h ↦ ⟨finite_of_encard_le_coe h, by rwa [ENat.le_coe_iff] at h⟩, fun ⟨_,⟨n₀,hs, hle⟩⟩ ↦ by rwa [hs, Nat.cast_le]⟩ @[simp] theorem encard_prod : (s ×ˢ t).encard = s.encard * t.encard := by simp [Set.encard, ENat.card_congr (Equiv.Set.prod ..)] section Lattice theorem encard_le_encard (h : s ⊆ t) : s.encard ≤ t.encard := by rw [← union_diff_cancel h, encard_union_eq disjoint_sdiff_right]; exact le_self_add @[deprecated (since := "2025-01-05")] alias encard_le_card := encard_le_encard theorem encard_mono {α : Type*} : Monotone (encard : Set α → ℕ∞) := fun _ _ ↦ encard_le_encard theorem encard_diff_add_encard_of_subset (h : s ⊆ t) : (t \ s).encard + s.encard = t.encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self, union_eq_self_of_subset_right h] @[simp] theorem one_le_encard_iff_nonempty : 1 ≤ s.encard ↔ s.Nonempty := by rw [nonempty_iff_ne_empty, Ne, ← encard_eq_zero, ENat.one_le_iff_ne_zero] theorem encard_diff_add_encard_inter (s t : Set α) : (s \ t).encard + (s ∩ t).encard = s.encard := by rw [← encard_union_eq (disjoint_of_subset_right inter_subset_right disjoint_sdiff_left), diff_union_inter] theorem encard_union_add_encard_inter (s t : Set α) : (s ∪ t).encard + (s ∩ t).encard = s.encard + t.encard := by rw [← diff_union_self, encard_union_eq disjoint_sdiff_left, add_right_comm, encard_diff_add_encard_inter] theorem encard_eq_encard_iff_encard_diff_eq_encard_diff (h : (s ∩ t).Finite) : s.encard = t.encard ↔ (s \ t).encard = (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_right_inj h.encard_lt_top.ne] theorem encard_le_encard_iff_encard_diff_le_encard_diff (h : (s ∩ t).Finite) : s.encard ≤ t.encard ↔ (s \ t).encard ≤ (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_le_add_iff_right h.encard_lt_top.ne] theorem encard_lt_encard_iff_encard_diff_lt_encard_diff (h : (s ∩ t).Finite) : s.encard < t.encard ↔ (s \ t).encard < (t \ s).encard := by rw [← encard_diff_add_encard_inter s t, ← encard_diff_add_encard_inter t s, inter_comm t s, WithTop.add_lt_add_iff_right h.encard_lt_top.ne] theorem encard_union_le (s t : Set α) : (s ∪ t).encard ≤ s.encard + t.encard := by rw [← encard_union_add_encard_inter]; exact le_self_add theorem finite_iff_finite_of_encard_eq_encard (h : s.encard = t.encard) : s.Finite ↔ t.Finite := by rw [← encard_lt_top_iff, ← encard_lt_top_iff, h] theorem infinite_iff_infinite_of_encard_eq_encard (h : s.encard = t.encard) : s.Infinite ↔ t.Infinite := by rw [← encard_eq_top_iff, h, encard_eq_top_iff] theorem Finite.finite_of_encard_le {s : Set α} {t : Set β} (hs : s.Finite) (h : t.encard ≤ s.encard) : t.Finite := encard_lt_top_iff.1 (h.trans_lt hs.encard_lt_top) lemma Finite.eq_of_subset_of_encard_le' (ht : t.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := by rw [← zero_add (a := encard s), ← encard_diff_add_encard_of_subset hst] at hts have hdiff := WithTop.le_of_add_le_add_right (ht.subset hst).encard_lt_top.ne hts rw [nonpos_iff_eq_zero, encard_eq_zero, diff_eq_empty] at hdiff exact hst.antisymm hdiff theorem Finite.eq_of_subset_of_encard_le (hs : s.Finite) (hst : s ⊆ t) (hts : t.encard ≤ s.encard) : s = t := (hs.finite_of_encard_le hts).eq_of_subset_of_encard_le' hst hts theorem Finite.encard_lt_encard (hs : s.Finite) (h : s ⊂ t) : s.encard < t.encard := (encard_mono h.subset).lt_of_ne fun he ↦ h.ne (hs.eq_of_subset_of_encard_le h.subset he.symm.le) theorem encard_strictMono [Finite α] : StrictMono (encard : Set α → ℕ∞) := fun _ _ h ↦ (toFinite _).encard_lt_encard h theorem encard_diff_add_encard (s t : Set α) : (s \ t).encard + t.encard = (s ∪ t).encard := by rw [← encard_union_eq disjoint_sdiff_left, diff_union_self] theorem encard_le_encard_diff_add_encard (s t : Set α) : s.encard ≤ (s \ t).encard + t.encard := (encard_mono subset_union_left).trans_eq (encard_diff_add_encard _ _).symm theorem tsub_encard_le_encard_diff (s t : Set α) : s.encard - t.encard ≤ (s \ t).encard := by rw [tsub_le_iff_left, add_comm]; apply encard_le_encard_diff_add_encard theorem encard_add_encard_compl (s : Set α) : s.encard + sᶜ.encard = (univ : Set α).encard := by rw [← encard_union_eq disjoint_compl_right, union_compl_self] end Lattice section InsertErase variable {a b : α} theorem encard_insert_le (s : Set α) (x : α) : (insert x s).encard ≤ s.encard + 1 := by rw [← union_singleton, ← encard_singleton x]; apply encard_union_le theorem encard_singleton_inter (s : Set α) (x : α) : ({x} ∩ s).encard ≤ 1 := by rw [← encard_singleton x]; exact encard_le_encard inter_subset_left theorem encard_diff_singleton_add_one (h : a ∈ s) : (s \ {a}).encard + 1 = s.encard := by rw [← encard_insert_of_not_mem (fun h ↦ h.2 rfl), insert_diff_singleton, insert_eq_of_mem h] theorem encard_diff_singleton_of_mem (h : a ∈ s) : (s \ {a}).encard = s.encard - 1 := by rw [← encard_diff_singleton_add_one h, ← WithTop.add_right_inj WithTop.one_ne_top, tsub_add_cancel_of_le (self_le_add_left _ _)] theorem encard_tsub_one_le_encard_diff_singleton (s : Set α) (x : α) : s.encard - 1 ≤ (s \ {x}).encard := by rw [← encard_singleton x]; apply tsub_encard_le_encard_diff theorem encard_exchange (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).encard = s.encard := by rw [encard_insert_of_not_mem, encard_diff_singleton_add_one hb] simp_all only [not_true, mem_diff, mem_singleton_iff, false_and, not_false_eq_true] theorem encard_exchange' (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).encard = s.encard := by rw [← insert_diff_singleton_comm (by rintro rfl; exact ha hb), encard_exchange ha hb] theorem encard_eq_add_one_iff {k : ℕ∞} : s.encard = k + 1 ↔ (∃ a t, ¬a ∈ t ∧ insert a t = s ∧ t.encard = k) := by refine ⟨fun h ↦ ?_, ?_⟩ · obtain ⟨a, ha⟩ := nonempty_of_encard_ne_zero (s := s) (by simp [h]) refine ⟨a, s \ {a}, fun h ↦ h.2 rfl, by rwa [insert_diff_singleton, insert_eq_of_mem], ?_⟩ rw [← WithTop.add_right_inj WithTop.one_ne_top, ← h, encard_diff_singleton_add_one ha] rintro ⟨a, t, h, rfl, rfl⟩ rw [encard_insert_of_not_mem h] /-- Every set is either empty, infinite, or can have its `encard` reduced by a removal. Intended for well-founded induction on the value of `encard`. -/ theorem eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt (s : Set α) : s = ∅ ∨ s.encard = ⊤ ∨ ∃ a ∈ s, (s \ {a}).encard < s.encard := by refine s.eq_empty_or_nonempty.elim Or.inl (Or.inr ∘ fun ⟨a,ha⟩ ↦ (s.finite_or_infinite.elim (fun hfin ↦ Or.inr ⟨a, ha, ?_⟩) (Or.inl ∘ Infinite.encard_eq))) rw [← encard_diff_singleton_add_one ha]; nth_rw 1 [← add_zero (encard _)] exact WithTop.add_lt_add_left hfin.diff.encard_lt_top.ne zero_lt_one end InsertErase section SmallSets theorem encard_pair {x y : α} (hne : x ≠ y) : ({x, y} : Set α).encard = 2 := by rw [encard_insert_of_not_mem (by simpa), ← one_add_one_eq_two, WithTop.add_right_inj WithTop.one_ne_top, encard_singleton] theorem encard_eq_one : s.encard = 1 ↔ ∃ x, s = {x} := by refine ⟨fun h ↦ ?_, fun ⟨x, hx⟩ ↦ by rw [hx, encard_singleton]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) exact ⟨x, ((finite_singleton x).eq_of_subset_of_encard_le (by simpa) (by simp [h])).symm⟩ theorem encard_le_one_iff_eq : s.encard ≤ 1 ↔ s = ∅ ∨ ∃ x, s = {x} := by rw [le_iff_lt_or_eq, lt_iff_not_le, ENat.one_le_iff_ne_zero, not_not, encard_eq_zero, encard_eq_one] theorem encard_le_one_iff : s.encard ≤ 1 ↔ ∀ a b, a ∈ s → b ∈ s → a = b := by rw [encard_le_one_iff_eq, or_iff_not_imp_left, ← Ne, ← nonempty_iff_ne_empty] refine ⟨fun h a b has hbs ↦ ?_, fun h ⟨x, hx⟩ ↦ ⟨x, ((singleton_subset_iff.2 hx).antisymm' (fun y hy ↦ h _ _ hy hx))⟩⟩ obtain ⟨x, rfl⟩ := h ⟨_, has⟩ rw [(has : a = x), (hbs : b = x)] theorem encard_le_one_iff_subsingleton : s.encard ≤ 1 ↔ s.Subsingleton := by rw [encard_le_one_iff, Set.Subsingleton] tauto theorem one_lt_encard_iff_nontrivial : 1 < s.encard ↔ s.Nontrivial := by rw [← not_iff_not, not_lt, Set.not_nontrivial_iff, ← encard_le_one_iff_subsingleton] theorem one_lt_encard_iff : 1 < s.encard ↔ ∃ a b, a ∈ s ∧ b ∈ s ∧ a ≠ b := by rw [← not_iff_not, not_exists, not_lt, encard_le_one_iff]; aesop theorem exists_ne_of_one_lt_encard (h : 1 < s.encard) (a : α) : ∃ b ∈ s, b ≠ a := by by_contra! h' obtain ⟨b, b', hb, hb', hne⟩ := one_lt_encard_iff.1 h apply hne rw [h' b hb, h' b' hb'] theorem encard_eq_two : s.encard = 2 ↔ ∃ x y, x ≠ y ∧ s = {x, y} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, hne, hs⟩ ↦ by rw [hs, encard_pair hne]⟩ obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), ← one_add_one_eq_two, WithTop.add_right_inj (WithTop.one_ne_top), encard_eq_one] at h obtain ⟨y, h⟩ := h refine ⟨x, y, by rintro rfl; exact (h.symm.subset rfl).2 rfl, ?_⟩ rw [← h, insert_diff_singleton, insert_eq_of_mem hx] theorem encard_eq_three {α : Type u_1} {s : Set α} : encard s = 3 ↔ ∃ x y z, x ≠ y ∧ x ≠ z ∧ y ≠ z ∧ s = {x, y, z} := by refine ⟨fun h ↦ ?_, fun ⟨x, y, z, hxy, hyz, hxz, hs⟩ ↦ ?_⟩ · obtain ⟨x, hx⟩ := nonempty_of_encard_ne_zero (s := s) (by rw [h]; simp) rw [← insert_eq_of_mem hx, ← insert_diff_singleton, encard_insert_of_not_mem (fun h ↦ h.2 rfl), (by exact rfl : (3 : ℕ∞) = 2 + 1), WithTop.add_right_inj WithTop.one_ne_top, encard_eq_two] at h obtain ⟨y, z, hne, hs⟩ := h refine ⟨x, y, z, ?_, ?_, hne, ?_⟩ · rintro rfl; exact (hs.symm.subset (Or.inl rfl)).2 rfl · rintro rfl; exact (hs.symm.subset (Or.inr rfl)).2 rfl rw [← hs, insert_diff_singleton, insert_eq_of_mem hx] rw [hs, encard_insert_of_not_mem, encard_insert_of_not_mem, encard_singleton] <;> aesop theorem Nat.encard_range (k : ℕ) : {i | i < k}.encard = k := by convert encard_coe_eq_coe_finsetCard (Finset.range k) using 1 · rw [Finset.coe_range, Iio_def] rw [Finset.card_range] end SmallSets theorem Finite.eq_insert_of_subset_of_encard_eq_succ (hs : s.Finite) (h : s ⊆ t) (hst : t.encard = s.encard + 1) : ∃ a, t = insert a s := by rw [← encard_diff_add_encard_of_subset h, add_comm, WithTop.add_left_inj hs.encard_lt_top.ne, encard_eq_one] at hst obtain ⟨x, hx⟩ := hst; use x; rw [← diff_union_of_subset h, hx, singleton_union] theorem exists_subset_encard_eq {k : ℕ∞} (hk : k ≤ s.encard) : ∃ t, t ⊆ s ∧ t.encard = k := by revert hk refine ENat.nat_induction k (fun _ ↦ ⟨∅, empty_subset _, by simp⟩) (fun n IH hle ↦ ?_) ?_ · obtain ⟨t₀, ht₀s, ht₀⟩ := IH (le_trans (by simp) hle) simp only [Nat.cast_succ] at * have hne : t₀ ≠ s := by rintro rfl; rw [ht₀, ← Nat.cast_one, ← Nat.cast_add, Nat.cast_le] at hle; simp at hle obtain ⟨x, hx⟩ := exists_of_ssubset (ht₀s.ssubset_of_ne hne) exact ⟨insert x t₀, insert_subset hx.1 ht₀s, by rw [encard_insert_of_not_mem hx.2, ht₀]⟩ simp only [top_le_iff, encard_eq_top_iff] exact fun _ hi ↦ ⟨s, Subset.rfl, hi⟩ theorem exists_superset_subset_encard_eq {k : ℕ∞} (hst : s ⊆ t) (hsk : s.encard ≤ k) (hkt : k ≤ t.encard) : ∃ r, s ⊆ r ∧ r ⊆ t ∧ r.encard = k := by obtain (hs | hs) := eq_or_ne s.encard ⊤ · rw [hs, top_le_iff] at hsk; subst hsk; exact ⟨s, Subset.rfl, hst, hs⟩ obtain ⟨k, rfl⟩ := exists_add_of_le hsk obtain ⟨k', hk'⟩ := exists_add_of_le hkt have hk : k ≤ encard (t \ s) := by rw [← encard_diff_add_encard_of_subset hst, add_comm] at hkt exact WithTop.le_of_add_le_add_right hs hkt obtain ⟨r', hr', rfl⟩ := exists_subset_encard_eq hk refine ⟨s ∪ r', subset_union_left, union_subset hst (hr'.trans diff_subset), ?_⟩ rw [encard_union_eq (disjoint_of_subset_right hr' disjoint_sdiff_right)] section Function variable {s : Set α} {t : Set β} {f : α → β} theorem InjOn.encard_image (h : InjOn f s) : (f '' s).encard = s.encard := by rw [encard, ENat.card_image_of_injOn h, encard] theorem encard_congr (e : s ≃ t) : s.encard = t.encard := by rw [← encard_univ_coe, ← encard_univ_coe t, encard_univ, encard_univ, ENat.card_congr e] theorem _root_.Function.Injective.encard_image (hf : f.Injective) (s : Set α) : (f '' s).encard = s.encard := hf.injOn.encard_image theorem _root_.Function.Embedding.encard_le (e : s ↪ t) : s.encard ≤ t.encard := by rw [← encard_univ_coe, ← e.injective.encard_image, ← Subtype.coe_injective.encard_image] exact encard_mono (by simp) theorem encard_image_le (f : α → β) (s : Set α) : (f '' s).encard ≤ s.encard := by obtain (h | h) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] apply encard_le_encard exact f.invFunOn_image_image_subset s theorem Finite.injOn_of_encard_image_eq (hs : s.Finite) (h : (f '' s).encard = s.encard) : InjOn f s := by obtain (h' | hne) := isEmpty_or_nonempty α · rw [s.eq_empty_of_isEmpty]; simp rw [← (f.invFunOn_injOn_image s).encard_image] at h rw [injOn_iff_invFunOn_image_image_eq_self] exact hs.eq_of_subset_of_encard_le' (f.invFunOn_image_image_subset s) h.symm.le theorem encard_preimage_of_injective_subset_range (hf : f.Injective) (ht : t ⊆ range f) : (f ⁻¹' t).encard = t.encard := by rw [← hf.encard_image, image_preimage_eq_inter_range, inter_eq_self_of_subset_left ht] lemma encard_preimage_of_bijective (hf : f.Bijective) (t : Set β) : (f ⁻¹' t).encard = t.encard := encard_preimage_of_injective_subset_range hf.injective (by simp [hf.surjective.range_eq]) theorem encard_le_encard_of_injOn (hf : MapsTo f s t) (f_inj : InjOn f s) : s.encard ≤ t.encard := by rw [← f_inj.encard_image]; apply encard_le_encard; rintro _ ⟨x, hx, rfl⟩; exact hf hx theorem Finite.exists_injOn_of_encard_le [Nonempty β] {s : Set α} {t : Set β} (hs : s.Finite) (hle : s.encard ≤ t.encard) : ∃ (f : α → β), s ⊆ f ⁻¹' t ∧ InjOn f s := by classical obtain (rfl | h | ⟨a, has, -⟩) := s.eq_empty_or_encard_eq_top_or_encard_diff_singleton_lt · simp · exact (encard_ne_top_iff.mpr hs h).elim obtain ⟨b, hbt⟩ := encard_pos.1 ((encard_pos.2 ⟨_, has⟩).trans_le hle) have hle' : (s \ {a}).encard ≤ (t \ {b}).encard := by rwa [← WithTop.add_le_add_iff_right WithTop.one_ne_top, encard_diff_singleton_add_one has, encard_diff_singleton_add_one hbt] obtain ⟨f₀, hf₀s, hinj⟩ := exists_injOn_of_encard_le hs.diff hle' simp only [preimage_diff, subset_def, mem_diff, mem_singleton_iff, mem_preimage, and_imp] at hf₀s use Function.update f₀ a b rw [← insert_eq_of_mem has, ← insert_diff_singleton, injOn_insert (fun h ↦ h.2 rfl)] simp only [mem_diff, mem_singleton_iff, not_true, and_false, insert_diff_singleton, subset_def, mem_insert_iff, mem_preimage, ne_eq, Function.update_apply, forall_eq_or_imp, ite_true, and_imp, mem_image, ite_eq_left_iff, not_exists, not_and, not_forall, exists_prop, and_iff_right hbt] refine ⟨?_, ?_, fun x hxs hxa ↦ ⟨hxa, (hf₀s x hxs hxa).2⟩⟩ · rintro x hx; split_ifs with h · assumption · exact (hf₀s x hx h).1 exact InjOn.congr hinj (fun x ⟨_, hxa⟩ ↦ by rwa [Function.update_of_ne]) termination_by encard s theorem Finite.exists_bijOn_of_encard_eq [Nonempty β] (hs : s.Finite) (h : s.encard = t.encard) : ∃ (f : α → β), BijOn f s t := by obtain ⟨f, hf, hinj⟩ := hs.exists_injOn_of_encard_le h.le; use f convert hinj.bijOn_image rw [(hs.image f).eq_of_subset_of_encard_le (image_subset_iff.mpr hf) (h.symm.trans hinj.encard_image.symm).le] end Function section ncard open Nat /-- A tactic (for use in default params) that applies `Set.toFinite` to synthesize a `Set.Finite` term. -/ syntax "toFinite_tac" : tactic macro_rules | `(tactic| toFinite_tac) => `(tactic| apply Set.toFinite) /-- A tactic useful for transferring proofs for `encard` to their corresponding `card` statements -/ syntax "to_encard_tac" : tactic macro_rules | `(tactic| to_encard_tac) => `(tactic| simp only [← Nat.cast_le (α := ℕ∞), ← Nat.cast_inj (R := ℕ∞), Nat.cast_add, Nat.cast_one]) /-- The cardinality of `s : Set α` . Has the junk value `0` if `s` is infinite -/ noncomputable def ncard (s : Set α) : ℕ := ENat.toNat s.encard theorem ncard_def (s : Set α) : s.ncard = ENat.toNat s.encard := rfl theorem Finite.cast_ncard_eq (hs : s.Finite) : s.ncard = s.encard := by rwa [ncard, ENat.coe_toNat_eq_self, ne_eq, encard_eq_top_iff, Set.Infinite, not_not] lemma ncard_le_encard (s : Set α) : s.ncard ≤ s.encard := ENat.coe_toNat_le_self _ theorem Nat.card_coe_set_eq (s : Set α) : Nat.card s = s.ncard := by obtain (h | h) := s.finite_or_infinite · have := h.fintype rw [ncard, h.encard_eq_coe_toFinset_card, Nat.card_eq_fintype_card, toFinite_toFinset, toFinset_card, ENat.toNat_coe] have := infinite_coe_iff.2 h rw [ncard, h.encard_eq, Nat.card_eq_zero_of_infinite, ENat.toNat_top] theorem ncard_eq_toFinset_card (s : Set α) (hs : s.Finite := by toFinite_tac) : s.ncard = hs.toFinset.card := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_fintype_card _ hs.fintype, @Finite.card_toFinset _ _ hs.fintype hs] theorem ncard_eq_toFinset_card' (s : Set α) [Fintype s] : s.ncard = s.toFinset.card := by simp [← Nat.card_coe_set_eq, Nat.card_eq_fintype_card] lemma cast_ncard {s : Set α} (hs : s.Finite) : (s.ncard : Cardinal) = Cardinal.mk s := @Nat.cast_card _ hs theorem encard_le_coe_iff_finite_ncard_le {k : ℕ} : s.encard ≤ k ↔ s.Finite ∧ s.ncard ≤ k := by rw [encard_le_coe_iff, and_congr_right_iff] exact fun hfin ↦ ⟨fun ⟨n₀, hn₀, hle⟩ ↦ by rwa [ncard_def, hn₀, ENat.toNat_coe], fun h ↦ ⟨s.ncard, by rw [hfin.cast_ncard_eq], h⟩⟩ theorem Infinite.ncard (hs : s.Infinite) : s.ncard = 0 := by rw [← Nat.card_coe_set_eq, @Nat.card_eq_zero_of_infinite _ hs.to_subtype] @[gcongr] theorem ncard_le_ncard (hst : s ⊆ t) (ht : t.Finite := by toFinite_tac) : s.ncard ≤ t.ncard := by rw [← Nat.cast_le (α := ℕ∞), ht.cast_ncard_eq, (ht.subset hst).cast_ncard_eq] exact encard_mono hst theorem ncard_mono [Finite α] : @Monotone (Set α) _ _ _ ncard := fun _ _ ↦ ncard_le_ncard @[simp] theorem ncard_eq_zero (hs : s.Finite := by toFinite_tac) : s.ncard = 0 ↔ s = ∅ := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, Nat.cast_zero, encard_eq_zero] @[simp, norm_cast] theorem ncard_coe_Finset (s : Finset α) : (s : Set α).ncard = s.card := by rw [ncard_eq_toFinset_card _, Finset.finite_toSet_toFinset] theorem ncard_univ (α : Type*) : (univ : Set α).ncard = Nat.card α := by rcases finite_or_infinite α with h | h · have hft := Fintype.ofFinite α rw [ncard_eq_toFinset_card, Finite.toFinset_univ, Finset.card_univ, Nat.card_eq_fintype_card] rw [Nat.card_eq_zero_of_infinite, Infinite.ncard] exact infinite_univ @[simp] theorem ncard_empty (α : Type*) : (∅ : Set α).ncard = 0 := by rw [ncard_eq_zero] theorem ncard_pos (hs : s.Finite := by toFinite_tac) : 0 < s.ncard ↔ s.Nonempty := by rw [pos_iff_ne_zero, Ne, ncard_eq_zero hs, nonempty_iff_ne_empty] protected alias ⟨_, Nonempty.ncard_pos⟩ := ncard_pos theorem ncard_ne_zero_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : s.ncard ≠ 0 := ((ncard_pos hs).mpr ⟨a, h⟩).ne.symm theorem finite_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Finite := s.finite_or_infinite.elim id fun h ↦ (hs h.ncard).elim theorem finite_of_ncard_pos (hs : 0 < s.ncard) : s.Finite := finite_of_ncard_ne_zero hs.ne.symm theorem nonempty_of_ncard_ne_zero (hs : s.ncard ≠ 0) : s.Nonempty := by rw [nonempty_iff_ne_empty]; rintro rfl; simp at hs @[simp] theorem ncard_singleton (a : α) : ({a} : Set α).ncard = 1 := by simp [ncard] theorem ncard_singleton_inter (a : α) (s : Set α) : ({a} ∩ s).ncard ≤ 1 := by rw [← Nat.cast_le (α := ℕ∞), (toFinite _).cast_ncard_eq, Nat.cast_one] apply encard_singleton_inter @[simp] theorem ncard_prod : (s ×ˢ t).ncard = s.ncard * t.ncard := by simp [ncard, ENat.toNat_mul] @[simp] theorem ncard_powerset (s : Set α) (hs : s.Finite := by toFinite_tac) : (𝒫 s).ncard = 2 ^ s.ncard := by have h := Cardinal.mk_powerset s rw [← cast_ncard hs.powerset, ← cast_ncard hs] at h norm_cast at h section InsertErase @[simp] theorem ncard_insert_of_not_mem {a : α} (h : a ∉ s) (hs : s.Finite := by toFinite_tac) : (insert a s).ncard = s.ncard + 1 := by rw [← Nat.cast_inj (R := ℕ∞), (hs.insert a).cast_ncard_eq, Nat.cast_add, Nat.cast_one, hs.cast_ncard_eq, encard_insert_of_not_mem h] theorem ncard_insert_of_mem {a : α} (h : a ∈ s) : ncard (insert a s) = s.ncard := by rw [insert_eq_of_mem h] theorem ncard_insert_le (a : α) (s : Set α) : (insert a s).ncard ≤ s.ncard + 1 := by obtain hs | hs := s.finite_or_infinite · to_encard_tac; rw [hs.cast_ncard_eq, (hs.insert _).cast_ncard_eq]; apply encard_insert_le rw [(hs.mono (subset_insert a s)).ncard] exact Nat.zero_le _ theorem ncard_insert_eq_ite {a : α} [Decidable (a ∈ s)] (hs : s.Finite := by toFinite_tac) : ncard (insert a s) = if a ∈ s then s.ncard else s.ncard + 1 := by by_cases h : a ∈ s · rw [ncard_insert_of_mem h, if_pos h] · rw [ncard_insert_of_not_mem h hs, if_neg h] theorem ncard_le_ncard_insert (a : α) (s : Set α) : s.ncard ≤ (insert a s).ncard := by classical refine s.finite_or_infinite.elim (fun h ↦ ?_) (fun h ↦ by (rw [h.ncard]; exact Nat.zero_le _)) rw [ncard_insert_eq_ite h]; split_ifs <;> simp @[simp] theorem ncard_pair {a b : α} (h : a ≠ b) : ({a, b} : Set α).ncard = 2 := by rw [ncard_insert_of_not_mem, ncard_singleton]; simpa @[simp] theorem ncard_diff_singleton_add_one {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard + 1 = s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, hs.diff.cast_ncard_eq, encard_diff_singleton_add_one h] @[simp] theorem ncard_diff_singleton_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard = s.ncard - 1 := eq_tsub_of_add_eq (ncard_diff_singleton_add_one h hs) theorem ncard_diff_singleton_lt_of_mem {a : α} (h : a ∈ s) (hs : s.Finite := by toFinite_tac) : (s \ {a}).ncard < s.ncard := by rw [← ncard_diff_singleton_add_one h hs]; apply lt_add_one theorem ncard_diff_singleton_le (s : Set α) (a : α) : (s \ {a}).ncard ≤ s.ncard := by obtain hs | hs := s.finite_or_infinite · apply ncard_le_ncard diff_subset hs convert zero_le (α := ℕ) _ exact (hs.diff (by simp : Set.Finite {a})).ncard theorem pred_ncard_le_ncard_diff_singleton (s : Set α) (a : α) : s.ncard - 1 ≤ (s \ {a}).ncard := by rcases s.finite_or_infinite with hs | hs · by_cases h : a ∈ s · rw [ncard_diff_singleton_of_mem h hs] rw [diff_singleton_eq_self h] apply Nat.pred_le convert Nat.zero_le _ rw [hs.ncard] theorem ncard_exchange {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a (s \ {b})).ncard = s.ncard := congr_arg ENat.toNat <| encard_exchange ha hb theorem ncard_exchange' {a b : α} (ha : a ∉ s) (hb : b ∈ s) : (insert a s \ {b}).ncard = s.ncard := by rw [← ncard_exchange ha hb, ← singleton_union, ← singleton_union, union_diff_distrib, @diff_singleton_eq_self _ b {a} fun h ↦ ha (by rwa [← mem_singleton_iff.mp h])] lemma odd_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) : Odd (insert a s).ncard ↔ Even s.ncard := by rw [ncard_insert_of_not_mem ha hs, Nat.odd_add] simp only [Nat.odd_add, ← Nat.not_even_iff_odd, Nat.not_even_one, iff_false, Decidable.not_not] lemma even_card_insert_iff {a : α} (ha : a ∉ s) (hs : s.Finite := by toFinite_tac) : Even (insert a s).ncard ↔ Odd s.ncard := by rw [ncard_insert_of_not_mem ha hs, Nat.even_add_one, Nat.not_even_iff_odd] end InsertErase variable {f : α → β} theorem ncard_image_le (hs : s.Finite := by toFinite_tac) : (f '' s).ncard ≤ s.ncard := by to_encard_tac; rw [hs.cast_ncard_eq, (hs.image _).cast_ncard_eq]; apply encard_image_le theorem ncard_image_of_injOn (H : Set.InjOn f s) : (f '' s).ncard = s.ncard := congr_arg ENat.toNat <| H.encard_image
theorem injOn_of_ncard_image_eq (h : (f '' s).ncard = s.ncard) (hs : s.Finite := by toFinite_tac) : Set.InjOn f s := by rw [← Nat.cast_inj (R := ℕ∞), hs.cast_ncard_eq, (hs.image _).cast_ncard_eq] at h exact hs.injOn_of_encard_image_eq h theorem ncard_image_iff (hs : s.Finite := by toFinite_tac) :
Mathlib/Data/Set/Card.lean
681
686
/- Copyright (c) 2021 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import Mathlib.SetTheory.Cardinal.ENat /-! # Projection from cardinal numbers to natural numbers In this file we define `Cardinal.toNat` to be the natural projection `Cardinal → ℕ`, sending all infinite cardinals to zero. We also prove basic lemmas about this definition. -/ assert_not_exists Field universe u v open Function Set namespace Cardinal variable {α : Type u} {c d : Cardinal.{u}} /-- This function sends finite cardinals to the corresponding natural, and infinite cardinals to 0. -/ noncomputable def toNat : Cardinal →*₀ ℕ := ENat.toNatHom.comp toENat @[simp] lemma toNat_toENat (a : Cardinal) : ENat.toNat (toENat a) = toNat a := rfl @[simp] theorem toNat_ofENat (n : ℕ∞) : toNat n = ENat.toNat n := congr_arg ENat.toNat <| toENat_ofENat n @[simp, norm_cast] theorem toNat_natCast (n : ℕ) : toNat n = n := toNat_ofENat n @[simp] lemma toNat_eq_zero : toNat c = 0 ↔ c = 0 ∨ ℵ₀ ≤ c := by rw [← toNat_toENat, ENat.toNat_eq_zero, toENat_eq_zero, toENat_eq_top] lemma toNat_ne_zero : toNat c ≠ 0 ↔ c ≠ 0 ∧ c < ℵ₀ := by simp [not_or] @[simp] lemma toNat_pos : 0 < toNat c ↔ c ≠ 0 ∧ c < ℵ₀ := pos_iff_ne_zero.trans toNat_ne_zero theorem cast_toNat_of_lt_aleph0 {c : Cardinal} (h : c < ℵ₀) : ↑(toNat c) = c := by lift c to ℕ using h rw [toNat_natCast] theorem toNat_apply_of_lt_aleph0 {c : Cardinal.{u}} (h : c < ℵ₀) : toNat c = Classical.choose (lt_aleph0.1 h) := Nat.cast_injective (R := Cardinal.{u}) <| by rw [cast_toNat_of_lt_aleph0 h, ← Classical.choose_spec (lt_aleph0.1 h)] theorem toNat_apply_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : toNat c = 0 := by simp [h] theorem cast_toNat_of_aleph0_le {c : Cardinal} (h : ℵ₀ ≤ c) : ↑(toNat c) = (0 : Cardinal) := by rw [toNat_apply_of_aleph0_le h, Nat.cast_zero] theorem cast_toNat_eq_iff_lt_aleph0 {c : Cardinal} : (toNat c) = c ↔ c < ℵ₀ := by constructor · intro h; by_contra h'; rw [not_lt] at h' rw [toNat_apply_of_aleph0_le h'] at h; rw [← h] at h' absurd h'; rw [not_le]; exact nat_lt_aleph0 0 · exact fun h ↦ (Cardinal.cast_toNat_of_lt_aleph0 h) theorem toNat_strictMonoOn : StrictMonoOn toNat (Iio ℵ₀) := by simp only [← range_natCast, StrictMonoOn, forall_mem_range, toNat_natCast, Nat.cast_lt] exact fun _ _ ↦ id theorem toNat_monotoneOn : MonotoneOn toNat (Iio ℵ₀) := toNat_strictMonoOn.monotoneOn theorem toNat_injOn : InjOn toNat (Iio ℵ₀) := toNat_strictMonoOn.injOn /-- Two finite cardinals are equal iff they are equal their `Cardinal.toNat` projections are equal. -/ theorem toNat_inj_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat c = toNat d ↔ c = d := toNat_injOn.eq_iff hc hd @[deprecated (since := "2024-12-29")] alias toNat_eq_iff_eq_of_lt_aleph0 := toNat_inj_of_lt_aleph0 theorem toNat_le_iff_le_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat c ≤ toNat d ↔ c ≤ d := toNat_strictMonoOn.le_iff_le hc hd theorem toNat_lt_iff_lt_of_lt_aleph0 (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat c < toNat d ↔ c < d := toNat_strictMonoOn.lt_iff_lt hc hd @[gcongr] theorem toNat_le_toNat (hcd : c ≤ d) (hd : d < ℵ₀) : toNat c ≤ toNat d := toNat_monotoneOn (hcd.trans_lt hd) hd hcd theorem toNat_lt_toNat (hcd : c < d) (hd : d < ℵ₀) : toNat c < toNat d := toNat_strictMonoOn (hcd.trans hd) hd hcd @[simp] theorem toNat_ofNat (n : ℕ) [n.AtLeastTwo] : Cardinal.toNat ofNat(n) = OfNat.ofNat n := toNat_natCast n /-- `toNat` has a right-inverse: coercion. -/ theorem toNat_rightInverse : Function.RightInverse ((↑) : ℕ → Cardinal) toNat := toNat_natCast theorem toNat_surjective : Surjective toNat := toNat_rightInverse.surjective @[simp] theorem mk_toNat_of_infinite [h : Infinite α] : toNat #α = 0 := by simp @[simp] theorem aleph0_toNat : toNat ℵ₀ = 0 := toNat_apply_of_aleph0_le le_rfl theorem mk_toNat_eq_card [Fintype α] : toNat #α = Fintype.card α := by simp @[simp] theorem zero_toNat : toNat 0 = 0 := map_zero _ theorem one_toNat : toNat 1 = 1 := map_one _ theorem toNat_eq_iff {n : ℕ} (hn : n ≠ 0) : toNat c = n ↔ c = n := by rw [← toNat_toENat, ENat.toNat_eq_iff hn, toENat_eq_nat] /-- A version of `toNat_eq_iff` for literals -/ theorem toNat_eq_ofNat {n : ℕ} [Nat.AtLeastTwo n] : toNat c = OfNat.ofNat n ↔ c = OfNat.ofNat n := toNat_eq_iff <| OfNat.ofNat_ne_zero n @[simp] theorem toNat_eq_one : toNat c = 1 ↔ c = 1 := by rw [toNat_eq_iff one_ne_zero, Nat.cast_one] theorem toNat_eq_one_iff_unique : toNat #α = 1 ↔ Subsingleton α ∧ Nonempty α := toNat_eq_one.trans eq_one_iff_unique @[simp] theorem toNat_lift (c : Cardinal.{v}) : toNat (lift.{u, v} c) = toNat c := by simp only [← toNat_toENat, toENat_lift] theorem toNat_congr {β : Type v} (e : α ≃ β) : toNat #α = toNat #β := by -- Porting note: Inserted universe hint below rw [← toNat_lift, (lift_mk_eq.{_,_,v}).mpr ⟨e⟩, toNat_lift] theorem toNat_mul (x y : Cardinal) : toNat (x * y) = toNat x * toNat y := map_mul toNat x y @[simp] theorem toNat_add (hc : c < ℵ₀) (hd : d < ℵ₀) : toNat (c + d) = toNat c + toNat d := by lift c to ℕ using hc lift d to ℕ using hd norm_cast @[simp] theorem toNat_lift_add_lift {a : Cardinal.{u}} {b : Cardinal.{v}} (ha : a < ℵ₀) (hb : b < ℵ₀) : toNat (lift.{v} a + lift.{u} b) = toNat a + toNat b := by simp [*] end Cardinal
Mathlib/SetTheory/Cardinal/ToNat.lean
168
170
/- Copyright (c) 2021 Frédéric Dupuis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Frédéric Dupuis -/ import Mathlib.Algebra.Group.Subgroup.Defs import Mathlib.Algebra.Module.Defs import Mathlib.Algebra.Star.Pi import Mathlib.Algebra.Star.Rat /-! # Self-adjoint, skew-adjoint and normal elements of a star additive group This file defines `selfAdjoint R` (resp. `skewAdjoint R`), where `R` is a star additive group, as the additive subgroup containing the elements that satisfy `star x = x` (resp. `star x = -x`). This includes, for instance, (skew-)Hermitian operators on Hilbert spaces. We also define `IsStarNormal R`, a `Prop` that states that an element `x` satisfies `star x * x = x * star x`. ## Implementation notes * When `R` is a `StarModule R₂ R`, then `selfAdjoint R` has a natural `Module (selfAdjoint R₂) (selfAdjoint R)` structure. However, doing this literally would be undesirable since in the main case of interest (`R₂ = ℂ`) we want `Module ℝ (selfAdjoint R)` and not `Module (selfAdjoint ℂ) (selfAdjoint R)`. We solve this issue by adding the typeclass `[TrivialStar R₃]`, of which `ℝ` is an instance (registered in `Data/Real/Basic`), and then add a `[Module R₃ (selfAdjoint R)]` instance whenever we have `[Module R₃ R] [TrivialStar R₃]`. (Another approach would have been to define `[StarInvariantScalars R₃ R]` to express the fact that `star (x • v) = x • star v`, but this typeclass would have the disadvantage of taking two type arguments.) ## TODO * Define `IsSkewAdjoint` to match `IsSelfAdjoint`. * Define `fun z x => z * x * star z` (i.e. conjugation by `z`) as a monoid action of `R` on `R` (similar to the existing `ConjAct` for groups), and then state the fact that `selfAdjoint R` is invariant under it. -/ open Function variable {R A : Type*} /-- An element is self-adjoint if it is equal to its star. -/ def IsSelfAdjoint [Star R] (x : R) : Prop := star x = x /-- An element of a star monoid is normal if it commutes with its adjoint. -/ @[mk_iff] class IsStarNormal [Mul R] [Star R] (x : R) : Prop where /-- A normal element of a star monoid commutes with its adjoint. -/ star_comm_self : Commute (star x) x export IsStarNormal (star_comm_self) theorem star_comm_self' [Mul R] [Star R] (x : R) [IsStarNormal x] : star x * x = x * star x := IsStarNormal.star_comm_self namespace IsSelfAdjoint -- named to match `Commute.allₓ` /-- All elements are self-adjoint when `star` is trivial. -/ theorem all [Star R] [TrivialStar R] (r : R) : IsSelfAdjoint r := star_trivial _ theorem star_eq [Star R] {x : R} (hx : IsSelfAdjoint x) : star x = x := hx theorem _root_.isSelfAdjoint_iff [Star R] {x : R} : IsSelfAdjoint x ↔ star x = x := Iff.rfl @[simp] theorem star_iff [InvolutiveStar R] {x : R} : IsSelfAdjoint (star x) ↔ IsSelfAdjoint x := by simpa only [IsSelfAdjoint, star_star] using eq_comm @[simp] theorem star_mul_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (star x * x) := by simp only [IsSelfAdjoint, star_mul, star_star] @[simp] theorem mul_star_self [Mul R] [StarMul R] (x : R) : IsSelfAdjoint (x * star x) := by simpa only [star_star] using star_mul_self (star x) /-- Self-adjoint elements commute if and only if their product is self-adjoint. -/ lemma commute_iff {R : Type*} [Mul R] [StarMul R] {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : Commute x y ↔ IsSelfAdjoint (x * y) := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [isSelfAdjoint_iff, star_mul, hx.star_eq, hy.star_eq, h.eq] · simpa only [star_mul, hx.star_eq, hy.star_eq] using h.symm /-- Functions in a `StarHomClass` preserve self-adjoint elements. -/ @[aesop 10% apply] theorem map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] {x : R} (hx : IsSelfAdjoint x) (f : F) : IsSelfAdjoint (f x) := show star (f x) = f x from map_star f x ▸ congr_arg f hx /- note: this lemma is *not* marked as `simp` so that Lean doesn't look for a `[TrivialStar R]` instance every time it sees `⊢ IsSelfAdjoint (f x)`, which will likely occur relatively often. -/ theorem _root_.isSelfAdjoint_map {F R S : Type*} [Star R] [Star S] [FunLike F R S] [StarHomClass F R S] [TrivialStar R] (f : F) (x : R) : IsSelfAdjoint (f x) := (IsSelfAdjoint.all x).map f section AddMonoid variable [AddMonoid R] [StarAddMonoid R] variable (R) in @[simp] protected theorem zero : IsSelfAdjoint (0 : R) := star_zero R @[aesop 90% apply] theorem add {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x + y) := by simp only [isSelfAdjoint_iff, star_add, hx.star_eq, hy.star_eq] end AddMonoid section AddGroup variable [AddGroup R] [StarAddMonoid R] @[aesop safe apply] theorem neg {x : R} (hx : IsSelfAdjoint x) : IsSelfAdjoint (-x) := by simp only [isSelfAdjoint_iff, star_neg, hx.star_eq] @[aesop 90% apply] theorem sub {x y : R} (hx : IsSelfAdjoint x) (hy : IsSelfAdjoint y) : IsSelfAdjoint (x - y) := by simp only [isSelfAdjoint_iff, star_sub, hx.star_eq, hy.star_eq] end AddGroup section AddCommMonoid variable [AddCommMonoid R] [StarAddMonoid R] @[simp] theorem add_star_self (x : R) : IsSelfAdjoint (x + star x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] @[simp] theorem star_add_self (x : R) : IsSelfAdjoint (star x + x) := by simp only [isSelfAdjoint_iff, add_comm, star_add, star_star] end AddCommMonoid
section Semigroup
Mathlib/Algebra/Star/SelfAdjoint.lean
145
146
/- Copyright (c) 2024 Theodore Hwa. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Kim Morrison, Violeta Hernández Palacios, Junyan Xu, Theodore Hwa -/ import Mathlib.Logic.Hydra import Mathlib.SetTheory.Surreal.Basic /-! ### Surreal multiplication In this file, we show that multiplication of surreal numbers is well-defined, and thus the surreal numbers form a linear ordered commutative ring. An inductive argument proves the following three main theorems: * P1: being numeric is closed under multiplication, * P2: multiplying a numeric pregame by equivalent numeric pregames results in equivalent pregames, * P3: the product of two positive numeric pregames is positive (`mul_pos`). This is Theorem 8 in [Conway2001], or Theorem 3.8 in [SchleicherStoll]. P1 allows us to define multiplication as an operation on numeric pregames, P2 says that this is well-defined as an operation on the quotient by `PGame.Equiv`, namely the surreal numbers, and P3 is an axiom that needs to be satisfied for the surreals to be a `OrderedRing`. We follow the proof in [SchleicherStoll], except that we use the well-foundedness of the hydra relation `CutExpand` on `Multiset PGame` instead of the argument based on a depth function in the paper. In the argument, P3 is stated with four variables `x₁`, `x₂`, `y₁`, `y₂` satisfying `x₁ < x₂` and `y₁ < y₂`, and says that `x₁ * y₂ + x₂ * x₁ < x₁ * y₁ + x₂ * y₂`, which is equivalent to `0 < x₂ - x₁ → 0 < y₂ - y₁ → 0 < (x₂ - x₁) * (y₂ - y₁)`, i.e. `@mul_pos PGame _ (x₂ - x₁) (y₂ - y₁)`. It has to be stated in this form and not in terms of `mul_pos` because we need to show P1, P2 and (a specialized form of) P3 simultaneously, and for example `P1 x y` will be deduced from P3 with variables taking values simpler than `x` or `y` (among other induction hypotheses), but if you subtract two pregames simpler than `x` or `y`, the result may no longer be simpler. The specialized version of P3 is called P4, which takes only three arguments `x₁`, `x₂`, `y` and requires that `y₂ = y` or `-y` and that `y₁` is a left option of `y₂`. After P1, P2 and P4 are shown, a further inductive argument (this time using the `GameAdd` relation) proves P3 in full. Implementation strategy of the inductive argument: we * extract specialized versions (`IH1`, `IH2`, `IH3`, `IH4` and `IH24`) of the induction hypothesis that are easier to apply (taking `IsOption` arguments directly), and * show they are invariant under certain symmetries (permutation and negation of arguments) and that the induction hypothesis indeed implies the specialized versions. * utilize the symmetries to minimize calculation. The whole proof features a clear separation into lemmas of different roles: * verification of symmetry properties of P and IH (`P3_comm`, `ih1_neg_left`, etc.), * calculations that connect P1, P2, P3, and inequalities between the product of two surreals and its options (`mulOption_lt_iff_P1`, etc.), * specializations of the induction hypothesis (`numeric_option_mul`, `ih1`, `ih1_swap`, `ih₁₂`, `ih4`, etc.), * application of specialized induction hypothesis (`P1_of_ih`, `mul_right_le_of_equiv`, `P3_of_lt`, etc.). ## References * [Conway, *On numbers and games*][Conway2001] * [Schleicher, Stoll, *An introduction to Conway's games and numbers*][SchleicherStoll] -/ universe u open SetTheory Game PGame WellFounded namespace Surreal.Multiplication /-- The nontrivial part of P1 in [SchleicherStoll] says that the left options of `x * y` are less than the right options, and this is the general form of these statements. -/ def P1 (x₁ x₂ x₃ y₁ y₂ y₃ : PGame) := ⟦x₁ * y₁⟧ + ⟦x₂ * y₂⟧ - ⟦x₁ * y₂⟧ < ⟦x₃ * y₁⟧ + ⟦x₂ * y₃⟧ - (⟦x₃ * y₃⟧ : Game) /-- The proposition P2, without numericity assumptions. -/ def P2 (x₁ x₂ y : PGame) := x₁ ≈ x₂ → ⟦x₁ * y⟧ = (⟦x₂ * y⟧ : Game) /-- The proposition P3, without the `x₁ < x₂` and `y₁ < y₂` assumptions. -/ def P3 (x₁ x₂ y₁ y₂ : PGame) := ⟦x₁ * y₂⟧ + ⟦x₂ * y₁⟧ < ⟦x₁ * y₁⟧ + (⟦x₂ * y₂⟧ : Game) /-- The proposition P4, without numericity assumptions. In the references, the second part of the conjunction is stated as `∀ j, P3 x₁ x₂ y (y.moveRight j)`, which is equivalent to our statement by `P3_comm` and `P3_neg`. We choose to state everything in terms of left options for uniform treatment. -/ def P4 (x₁ x₂ y : PGame) := x₁ < x₂ → (∀ i, P3 x₁ x₂ (y.moveLeft i) y) ∧ ∀ j, P3 x₁ x₂ ((-y).moveLeft j) (-y) /-- The conjunction of P2 and P4. -/ def P24 (x₁ x₂ y : PGame) : Prop := P2 x₁ x₂ y ∧ P4 x₁ x₂ y variable {x x₁ x₂ x₃ x' y y₁ y₂ y₃ y' : PGame.{u}} /-! #### Symmetry properties of P1, P2, P3, and P4 -/ lemma P3_comm : P3 x₁ x₂ y₁ y₂ ↔ P3 y₁ y₂ x₁ x₂ := by rw [P3, P3, add_comm] congr! 2 <;> rw [quot_mul_comm] lemma P3.trans (h₁ : P3 x₁ x₂ y₁ y₂) (h₂ : P3 x₂ x₃ y₁ y₂) : P3 x₁ x₃ y₁ y₂ := by rw [P3] at h₁ h₂ rw [P3, ← add_lt_add_iff_left (⟦x₂ * y₁⟧ + ⟦x₂ * y₂⟧)] convert add_lt_add h₁ h₂ using 1 <;> abel lemma P3_neg : P3 x₁ x₂ y₁ y₂ ↔ P3 (-x₂) (-x₁) y₁ y₂ := by simp_rw [P3, quot_neg_mul] rw [← _root_.neg_lt_neg_iff] abel_nf lemma P2_neg_left : P2 x₁ x₂ y ↔ P2 (-x₂) (-x₁) y := by rw [P2, P2] constructor · rw [quot_neg_mul, quot_neg_mul, eq_comm, neg_inj, neg_equiv_neg_iff, PGame.equiv_comm] exact (· ·) · rw [PGame.equiv_comm, neg_equiv_neg_iff, quot_neg_mul, quot_neg_mul, neg_inj, eq_comm] exact (· ·) lemma P2_neg_right : P2 x₁ x₂ y ↔ P2 x₁ x₂ (-y) := by rw [P2, P2, quot_mul_neg, quot_mul_neg, neg_inj] lemma P4_neg_left : P4 x₁ x₂ y ↔ P4 (-x₂) (-x₁) y := by simp_rw [P4, PGame.neg_lt_neg_iff, moveLeft_neg, ← P3_neg] lemma P4_neg_right : P4 x₁ x₂ y ↔ P4 x₁ x₂ (-y) := by rw [P4, P4, neg_neg, and_comm] lemma P24_neg_left : P24 x₁ x₂ y ↔ P24 (-x₂) (-x₁) y := by rw [P24, P24, P2_neg_left, P4_neg_left] lemma P24_neg_right : P24 x₁ x₂ y ↔ P24 x₁ x₂ (-y) := by rw [P24, P24, P2_neg_right, P4_neg_right] /-! #### Explicit calculations necessary for the main proof -/ lemma mulOption_lt_iff_P1 {i j k l} : (⟦mulOption x y i k⟧ : Game) < -⟦mulOption x (-y) j l⟧ ↔ P1 (x.moveLeft i) x (x.moveLeft j) y (y.moveLeft k) (-(-y).moveLeft l) := by dsimp only [P1, mulOption, quot_sub, quot_add] simp_rw [neg_sub', neg_add, quot_mul_neg, neg_neg] lemma mulOption_lt_mul_iff_P3 {i j} : ⟦mulOption x y i j⟧ < (⟦x * y⟧ : Game) ↔ P3 (x.moveLeft i) x (y.moveLeft j) y := by dsimp only [mulOption, quot_sub, quot_add] exact sub_lt_iff_lt_add' lemma P1_of_eq (he : x₁ ≈ x₃) (h₁ : P2 x₁ x₃ y₁) (h₃ : P2 x₁ x₃ y₃) (h3 : P3 x₁ x₂ y₂ y₃) : P1 x₁ x₂ x₃ y₁ y₂ y₃ := by rw [P1, ← h₁ he, ← h₃ he, sub_lt_sub_iff] convert add_lt_add_left h3 ⟦x₁ * y₁⟧ using 1 <;> abel lemma P1_of_lt (h₁ : P3 x₃ x₂ y₂ y₃) (h₂ : P3 x₁ x₃ y₂ y₁) : P1 x₁ x₂ x₃ y₁ y₂ y₃ := by rw [P1, sub_lt_sub_iff, ← add_lt_add_iff_left ⟦x₃ * y₂⟧] convert add_lt_add h₁ h₂ using 1 <;> abel /-- The type of lists of arguments for P1, P2, and P4. -/ inductive Args : Type (u + 1) | P1 (x y : PGame.{u}) : Args | P24 (x₁ x₂ y : PGame.{u}) : Args /-- The multiset associated to a list of arguments. -/ def Args.toMultiset : Args → Multiset PGame | (Args.P1 x y) => {x, y} | (Args.P24 x₁ x₂ y) => {x₁, x₂, y} /-- A list of arguments is numeric if all the arguments are. -/ def Args.Numeric (a : Args) := ∀ x ∈ a.toMultiset, SetTheory.PGame.Numeric x lemma Args.numeric_P1 {x y} : (Args.P1 x y).Numeric ↔ x.Numeric ∧ y.Numeric := by simp [Args.Numeric, Args.toMultiset] lemma Args.numeric_P24 {x₁ x₂ y} : (Args.P24 x₁ x₂ y).Numeric ↔ x₁.Numeric ∧ x₂.Numeric ∧ y.Numeric := by simp [Args.Numeric, Args.toMultiset] open Relation /-- The relation specifying when a list of (pregame) arguments is considered simpler than another: `ArgsRel a₁ a₂` is true if `a₁`, considered as a multiset, can be obtained from `a₂` by repeatedly removing a pregame from `a₂` and adding back one or two options of the pregame. -/ def ArgsRel := InvImage (TransGen <| CutExpand IsOption) Args.toMultiset /-- `ArgsRel` is well-founded. -/ theorem argsRel_wf : WellFounded ArgsRel := InvImage.wf _ wf_isOption.cutExpand.transGen /-- The statement that we will show by induction using the well-founded relation `ArgsRel`. -/ def P124 : Args → Prop | (Args.P1 x y) => Numeric (x * y) | (Args.P24 x₁ x₂ y) => P24 x₁ x₂ y /-- The property that all arguments are numeric is leftward-closed under `ArgsRel`. -/ lemma ArgsRel.numeric_closed {a' a} : ArgsRel a' a → a.Numeric → a'.Numeric := TransGen.closed' <| @cutExpand_closed _ IsOption ⟨wf_isOption.isIrrefl.1⟩ _ Numeric.isOption /-- A specialized induction hypothesis used to prove P1. -/ def IH1 (x y : PGame) : Prop := ∀ ⦃x₁ x₂ y'⦄, IsOption x₁ x → IsOption x₂ x → (y' = y ∨ IsOption y' y) → P24 x₁ x₂ y' /-! #### Symmetry properties of `IH1` -/
lemma ih1_neg_left : IH1 x y → IH1 (-x) y := fun h x₁ x₂ y' h₁ h₂ hy ↦ by rw [isOption_neg] at h₁ h₂ exact P24_neg_left.2 (h h₂ h₁ hy)
Mathlib/SetTheory/Surreal/Multiplication.lean
197
200
/- Copyright (c) 2022 Joseph Myers. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Joseph Myers, Heather Macbeth -/ import Mathlib.Analysis.SpecialFunctions.Complex.Circle import Mathlib.Geometry.Euclidean.Angle.Oriented.Basic /-! # Rotations by oriented angles. This file defines rotations by oriented angles in real inner product spaces. ## Main definitions * `Orientation.rotation` is the rotation by an oriented angle with respect to an orientation. -/ noncomputable section open Module Complex open scoped Real RealInnerProductSpace ComplexConjugate namespace Orientation attribute [local instance] Complex.finrank_real_complex_fact variable {V V' : Type*} variable [NormedAddCommGroup V] [NormedAddCommGroup V'] variable [InnerProductSpace ℝ V] [InnerProductSpace ℝ V'] variable [Fact (finrank ℝ V = 2)] [Fact (finrank ℝ V' = 2)] (o : Orientation ℝ V (Fin 2)) local notation "J" => o.rightAngleRotation /-- Auxiliary construction to build a rotation by the oriented angle `θ`. -/ def rotationAux (θ : Real.Angle) : V →ₗᵢ[ℝ] V := LinearMap.isometryOfInner (Real.Angle.cos θ • LinearMap.id + Real.Angle.sin θ • (LinearIsometryEquiv.toLinearEquiv J).toLinearMap) (by intro x y simp only [RCLike.conj_to_real, id, LinearMap.smul_apply, LinearMap.add_apply, LinearMap.id_coe, LinearEquiv.coe_coe, LinearIsometryEquiv.coe_toLinearEquiv, Orientation.areaForm_rightAngleRotation_left, Orientation.inner_rightAngleRotation_left, Orientation.inner_rightAngleRotation_right, inner_add_left, inner_smul_left, inner_add_right, inner_smul_right] linear_combination inner (𝕜 := ℝ) x y * θ.cos_sq_add_sin_sq) @[simp] theorem rotationAux_apply (θ : Real.Angle) (x : V) : o.rotationAux θ x = Real.Angle.cos θ • x + Real.Angle.sin θ • J x := rfl /-- A rotation by the oriented angle `θ`. -/ def rotation (θ : Real.Angle) : V ≃ₗᵢ[ℝ] V := LinearIsometryEquiv.ofLinearIsometry (o.rotationAux θ) (Real.Angle.cos θ • LinearMap.id - Real.Angle.sin θ • (LinearIsometryEquiv.toLinearEquiv J).toLinearMap) (by ext x convert congr_arg (fun t : ℝ => t • x) θ.cos_sq_add_sin_sq using 1 · simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply, Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv, map_smul, map_sub, LinearMap.coe_comp, LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply] module · simp) (by ext x convert congr_arg (fun t : ℝ => t • x) θ.cos_sq_add_sin_sq using 1 · simp only [o.rightAngleRotation_rightAngleRotation, o.rotationAux_apply, Function.comp_apply, id, LinearEquiv.coe_coe, LinearIsometry.coe_toLinearMap, LinearIsometryEquiv.coe_toLinearEquiv, map_add, map_smul, LinearMap.coe_comp, LinearMap.id_coe, LinearMap.smul_apply, LinearMap.sub_apply] module · simp) theorem rotation_apply (θ : Real.Angle) (x : V) : o.rotation θ x = Real.Angle.cos θ • x + Real.Angle.sin θ • J x := rfl theorem rotation_symm_apply (θ : Real.Angle) (x : V) : (o.rotation θ).symm x = Real.Angle.cos θ • x - Real.Angle.sin θ • J x := rfl theorem rotation_eq_matrix_toLin (θ : Real.Angle) {x : V} (hx : x ≠ 0) : (o.rotation θ).toLinearMap = Matrix.toLin (o.basisRightAngleRotation x hx) (o.basisRightAngleRotation x hx) !![θ.cos, -θ.sin; θ.sin, θ.cos] := by apply (o.basisRightAngleRotation x hx).ext intro i fin_cases i · rw [Matrix.toLin_self] simp [rotation_apply, Fin.sum_univ_succ] · rw [Matrix.toLin_self] simp [rotation_apply, Fin.sum_univ_succ, add_comm] /-- The determinant of `rotation` (as a linear map) is equal to `1`. -/ @[simp] theorem det_rotation (θ : Real.Angle) : LinearMap.det (o.rotation θ).toLinearMap = 1 := by haveI : Nontrivial V := nontrivial_of_finrank_eq_succ (@Fact.out (finrank ℝ V = 2) _) obtain ⟨x, hx⟩ : ∃ x, x ≠ (0 : V) := exists_ne (0 : V) rw [o.rotation_eq_matrix_toLin θ hx] simpa [sq] using θ.cos_sq_add_sin_sq /-- The determinant of `rotation` (as a linear equiv) is equal to `1`. -/ @[simp] theorem linearEquiv_det_rotation (θ : Real.Angle) : LinearEquiv.det (o.rotation θ).toLinearEquiv = 1 := Units.ext <| by -- Porting note: Lean can't see through `LinearEquiv.coe_det` and needed the rewrite -- in mathlib3 this was just `units.ext <| o.det_rotation θ` simpa only [LinearEquiv.coe_det, Units.val_one] using o.det_rotation θ /-- The inverse of `rotation` is rotation by the negation of the angle. -/ @[simp] theorem rotation_symm (θ : Real.Angle) : (o.rotation θ).symm = o.rotation (-θ) := by ext; simp [o.rotation_apply, o.rotation_symm_apply, sub_eq_add_neg] /-- Rotation by 0 is the identity. -/ @[simp] theorem rotation_zero : o.rotation 0 = LinearIsometryEquiv.refl ℝ V := by ext; simp [rotation] /-- Rotation by π is negation. -/ @[simp] theorem rotation_pi : o.rotation π = LinearIsometryEquiv.neg ℝ := by ext x simp [rotation] /-- Rotation by π is negation. -/ theorem rotation_pi_apply (x : V) : o.rotation π x = -x := by simp /-- Rotation by π / 2 is the "right-angle-rotation" map `J`. -/ theorem rotation_pi_div_two : o.rotation (π / 2 : ℝ) = J := by ext x simp [rotation] /-- Rotating twice is equivalent to rotating by the sum of the angles. -/ @[simp] theorem rotation_rotation (θ₁ θ₂ : Real.Angle) (x : V) : o.rotation θ₁ (o.rotation θ₂ x) = o.rotation (θ₁ + θ₂) x := by simp only [o.rotation_apply, Real.Angle.cos_add, Real.Angle.sin_add, LinearIsometryEquiv.map_add, LinearIsometryEquiv.trans_apply, map_smul, rightAngleRotation_rightAngleRotation] module /-- Rotating twice is equivalent to rotating by the sum of the angles. -/ @[simp] theorem rotation_trans (θ₁ θ₂ : Real.Angle) : (o.rotation θ₁).trans (o.rotation θ₂) = o.rotation (θ₂ + θ₁) := LinearIsometryEquiv.ext fun _ => by rw [← rotation_rotation, LinearIsometryEquiv.trans_apply]
/-- Rotating the first of two vectors by `θ` scales their Kahler form by `cos θ - sin θ * I`. -/ @[simp] theorem kahler_rotation_left (x y : V) (θ : Real.Angle) :
Mathlib/Geometry/Euclidean/Angle/Oriented/Rotation.lean
155
157
/- Copyright (c) 2022 David Kurniadi Angdinata. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Kurniadi Angdinata -/ import Mathlib.Algebra.Polynomial.Splits import Mathlib.Tactic.IntervalCases /-! # Cubics and discriminants This file defines cubic polynomials over a semiring and their discriminants over a splitting field. ## Main definitions * `Cubic`: the structure representing a cubic polynomial. * `Cubic.disc`: the discriminant of a cubic polynomial. ## Main statements * `Cubic.disc_ne_zero_iff_roots_nodup`: the cubic discriminant is not equal to zero if and only if the cubic has no duplicate roots. ## References * https://en.wikipedia.org/wiki/Cubic_equation * https://en.wikipedia.org/wiki/Discriminant ## Tags cubic, discriminant, polynomial, root -/ noncomputable section /-- The structure representing a cubic polynomial. -/ @[ext] structure Cubic (R : Type*) where /-- The degree-3 coefficient -/ a : R /-- The degree-2 coefficient -/ b : R /-- The degree-1 coefficient -/ c : R /-- The degree-0 coefficient -/ d : R namespace Cubic open Polynomial variable {R S F K : Type*} instance [Inhabited R] : Inhabited (Cubic R) := ⟨⟨default, default, default, default⟩⟩ instance [Zero R] : Zero (Cubic R) := ⟨⟨0, 0, 0, 0⟩⟩ section Basic variable {P Q : Cubic R} {a b c d a' b' c' d' : R} [Semiring R] /-- Convert a cubic polynomial to a polynomial. -/ def toPoly (P : Cubic R) : R[X] := C P.a * X ^ 3 + C P.b * X ^ 2 + C P.c * X + C P.d theorem C_mul_prod_X_sub_C_eq [CommRing S] {w x y z : S} : C w * (X - C x) * (X - C y) * (X - C z) = toPoly ⟨w, w * -(x + y + z), w * (x * y + x * z + y * z), w * -(x * y * z)⟩ := by simp only [toPoly, C_neg, C_add, C_mul] ring1 theorem prod_X_sub_C_eq [CommRing S] {x y z : S} : (X - C x) * (X - C y) * (X - C z) = toPoly ⟨1, -(x + y + z), x * y + x * z + y * z, -(x * y * z)⟩ := by rw [← one_mul <| X - C x, ← C_1, C_mul_prod_X_sub_C_eq, one_mul, one_mul, one_mul] /-! ### Coefficients -/ section Coeff private theorem coeffs : (∀ n > 3, P.toPoly.coeff n = 0) ∧ P.toPoly.coeff 3 = P.a ∧ P.toPoly.coeff 2 = P.b ∧ P.toPoly.coeff 1 = P.c ∧ P.toPoly.coeff 0 = P.d := by simp only [toPoly, coeff_add, coeff_C, coeff_C_mul_X, coeff_C_mul_X_pow] norm_num intro n hn repeat' rw [if_neg] any_goals omega repeat' rw [zero_add] @[simp] theorem coeff_eq_zero {n : ℕ} (hn : 3 < n) : P.toPoly.coeff n = 0 := coeffs.1 n hn @[simp] theorem coeff_eq_a : P.toPoly.coeff 3 = P.a := coeffs.2.1 @[simp] theorem coeff_eq_b : P.toPoly.coeff 2 = P.b := coeffs.2.2.1 @[simp] theorem coeff_eq_c : P.toPoly.coeff 1 = P.c := coeffs.2.2.2.1 @[simp] theorem coeff_eq_d : P.toPoly.coeff 0 = P.d := coeffs.2.2.2.2 theorem a_of_eq (h : P.toPoly = Q.toPoly) : P.a = Q.a := by rw [← coeff_eq_a, h, coeff_eq_a] theorem b_of_eq (h : P.toPoly = Q.toPoly) : P.b = Q.b := by rw [← coeff_eq_b, h, coeff_eq_b] theorem c_of_eq (h : P.toPoly = Q.toPoly) : P.c = Q.c := by rw [← coeff_eq_c, h, coeff_eq_c] theorem d_of_eq (h : P.toPoly = Q.toPoly) : P.d = Q.d := by rw [← coeff_eq_d, h, coeff_eq_d] theorem toPoly_injective (P Q : Cubic R) : P.toPoly = Q.toPoly ↔ P = Q := ⟨fun h ↦ Cubic.ext (a_of_eq h) (b_of_eq h) (c_of_eq h) (d_of_eq h), congr_arg toPoly⟩ theorem of_a_eq_zero (ha : P.a = 0) : P.toPoly = C P.b * X ^ 2 + C P.c * X + C P.d := by rw [toPoly, ha, C_0, zero_mul, zero_add] theorem of_a_eq_zero' : toPoly ⟨0, b, c, d⟩ = C b * X ^ 2 + C c * X + C d := of_a_eq_zero rfl theorem of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly = C P.c * X + C P.d := by rw [of_a_eq_zero ha, hb, C_0, zero_mul, zero_add] theorem of_b_eq_zero' : toPoly ⟨0, 0, c, d⟩ = C c * X + C d := of_b_eq_zero rfl rfl theorem of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly = C P.d := by rw [of_b_eq_zero ha hb, hc, C_0, zero_mul, zero_add] theorem of_c_eq_zero' : toPoly ⟨0, 0, 0, d⟩ = C d := of_c_eq_zero rfl rfl rfl theorem of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly = 0 := by rw [of_c_eq_zero ha hb hc, hd, C_0] theorem of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly = 0 := of_d_eq_zero rfl rfl rfl rfl theorem zero : (0 : Cubic R).toPoly = 0 := of_d_eq_zero' theorem toPoly_eq_zero_iff (P : Cubic R) : P.toPoly = 0 ↔ P = 0 := by rw [← zero, toPoly_injective] private theorem ne_zero (h0 : P.a ≠ 0 ∨ P.b ≠ 0 ∨ P.c ≠ 0 ∨ P.d ≠ 0) : P.toPoly ≠ 0 := by contrapose! h0 rw [(toPoly_eq_zero_iff P).mp h0] exact ⟨rfl, rfl, rfl, rfl⟩ theorem ne_zero_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp ne_zero).1 ha theorem ne_zero_of_b_ne_zero (hb : P.b ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp (or_imp.mp ne_zero).2).1 hb theorem ne_zero_of_c_ne_zero (hc : P.c ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).1 hc theorem ne_zero_of_d_ne_zero (hd : P.d ≠ 0) : P.toPoly ≠ 0 := (or_imp.mp (or_imp.mp (or_imp.mp ne_zero).2).2).2 hd @[simp] theorem leadingCoeff_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.leadingCoeff = P.a := leadingCoeff_cubic ha @[simp] theorem leadingCoeff_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).leadingCoeff = a := leadingCoeff_of_a_ne_zero ha @[simp] theorem leadingCoeff_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.leadingCoeff = P.b := by rw [of_a_eq_zero ha, leadingCoeff_quadratic hb] @[simp] theorem leadingCoeff_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).leadingCoeff = b := leadingCoeff_of_b_ne_zero rfl hb @[simp] theorem leadingCoeff_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.leadingCoeff = P.c := by rw [of_b_eq_zero ha hb, leadingCoeff_linear hc] @[simp] theorem leadingCoeff_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).leadingCoeff = c := leadingCoeff_of_c_ne_zero rfl rfl hc @[simp] theorem leadingCoeff_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.leadingCoeff = P.d := by rw [of_c_eq_zero ha hb hc, leadingCoeff_C] theorem leadingCoeff_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).leadingCoeff = d := leadingCoeff_of_c_eq_zero rfl rfl rfl theorem monic_of_a_eq_one (ha : P.a = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_a_ne_zero (ha ▸ one_ne_zero), ha] theorem monic_of_a_eq_one' : (toPoly ⟨1, b, c, d⟩).Monic := monic_of_a_eq_one rfl theorem monic_of_b_eq_one (ha : P.a = 0) (hb : P.b = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_b_ne_zero ha (hb ▸ one_ne_zero), hb] theorem monic_of_b_eq_one' : (toPoly ⟨0, 1, c, d⟩).Monic := monic_of_b_eq_one rfl rfl theorem monic_of_c_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 1) : P.toPoly.Monic := by nontriviality R rw [Monic, leadingCoeff_of_c_ne_zero ha hb (hc ▸ one_ne_zero), hc] theorem monic_of_c_eq_one' : (toPoly ⟨0, 0, 1, d⟩).Monic := monic_of_c_eq_one rfl rfl rfl theorem monic_of_d_eq_one (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 1) : P.toPoly.Monic := by rw [Monic, leadingCoeff_of_c_eq_zero ha hb hc, hd] theorem monic_of_d_eq_one' : (toPoly ⟨0, 0, 0, 1⟩).Monic := monic_of_d_eq_one rfl rfl rfl rfl end Coeff /-! ### Degrees -/ section Degree /-- The equivalence between cubic polynomials and polynomials of degree at most three. -/ @[simps] def equiv : Cubic R ≃ { p : R[X] // p.degree ≤ 3 } where toFun P := ⟨P.toPoly, degree_cubic_le⟩ invFun f := ⟨coeff f 3, coeff f 2, coeff f 1, coeff f 0⟩ left_inv P := by ext <;> simp only [Subtype.coe_mk, coeffs] right_inv f := by ext n obtain hn | hn := le_or_lt n 3 · interval_cases n <;> simp only [Nat.succ_eq_add_one] <;> ring_nf <;> try simp only [coeffs] · rw [coeff_eq_zero hn, (degree_le_iff_coeff_zero (f : R[X]) 3).mp f.2] simpa using hn @[simp] theorem degree_of_a_ne_zero (ha : P.a ≠ 0) : P.toPoly.degree = 3 := degree_cubic ha @[simp] theorem degree_of_a_ne_zero' (ha : a ≠ 0) : (toPoly ⟨a, b, c, d⟩).degree = 3 := degree_of_a_ne_zero ha theorem degree_of_a_eq_zero (ha : P.a = 0) : P.toPoly.degree ≤ 2 := by simpa only [of_a_eq_zero ha] using degree_quadratic_le theorem degree_of_a_eq_zero' : (toPoly ⟨0, b, c, d⟩).degree ≤ 2 := degree_of_a_eq_zero rfl @[simp] theorem degree_of_b_ne_zero (ha : P.a = 0) (hb : P.b ≠ 0) : P.toPoly.degree = 2 := by rw [of_a_eq_zero ha, degree_quadratic hb] @[simp] theorem degree_of_b_ne_zero' (hb : b ≠ 0) : (toPoly ⟨0, b, c, d⟩).degree = 2 := degree_of_b_ne_zero rfl hb theorem degree_of_b_eq_zero (ha : P.a = 0) (hb : P.b = 0) : P.toPoly.degree ≤ 1 := by simpa only [of_b_eq_zero ha hb] using degree_linear_le theorem degree_of_b_eq_zero' : (toPoly ⟨0, 0, c, d⟩).degree ≤ 1 := degree_of_b_eq_zero rfl rfl @[simp] theorem degree_of_c_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c ≠ 0) : P.toPoly.degree = 1 := by rw [of_b_eq_zero ha hb, degree_linear hc] @[simp] theorem degree_of_c_ne_zero' (hc : c ≠ 0) : (toPoly ⟨0, 0, c, d⟩).degree = 1 := degree_of_c_ne_zero rfl rfl hc theorem degree_of_c_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) : P.toPoly.degree ≤ 0 := by simpa only [of_c_eq_zero ha hb hc] using degree_C_le theorem degree_of_c_eq_zero' : (toPoly ⟨0, 0, 0, d⟩).degree ≤ 0 := degree_of_c_eq_zero rfl rfl rfl @[simp] theorem degree_of_d_ne_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d ≠ 0) : P.toPoly.degree = 0 := by rw [of_c_eq_zero ha hb hc, degree_C hd] @[simp] theorem degree_of_d_ne_zero' (hd : d ≠ 0) : (toPoly ⟨0, 0, 0, d⟩).degree = 0 := degree_of_d_ne_zero rfl rfl rfl hd @[simp] theorem degree_of_d_eq_zero (ha : P.a = 0) (hb : P.b = 0) (hc : P.c = 0) (hd : P.d = 0) : P.toPoly.degree = ⊥ := by rw [of_d_eq_zero ha hb hc hd, degree_zero]
theorem degree_of_d_eq_zero' : (⟨0, 0, 0, 0⟩ : Cubic R).toPoly.degree = ⊥ := degree_of_d_eq_zero rfl rfl rfl rfl
Mathlib/Algebra/CubicDiscriminant.lean
310
311
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Sébastien Gouëzel, Johannes Hölzl, Yury Kudryashov, Patrick Massot -/ import Mathlib.Algebra.GeomSum import Mathlib.Order.Filter.AtTopBot.Archimedean import Mathlib.Order.Iterate import Mathlib.Topology.Algebra.Algebra import Mathlib.Topology.Algebra.InfiniteSum.Real import Mathlib.Topology.Instances.EReal.Lemmas /-! # A collection of specific limit computations This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains important specific limit computations in metric spaces, in ordered rings/fields, and in specific instances of these such as `ℝ`, `ℝ≥0` and `ℝ≥0∞`. -/ assert_not_exists Basis NormedSpace noncomputable section open Set Function Filter Finset Metric Topology Nat uniformity NNReal ENNReal variable {α : Type*} {β : Type*} {ι : Type*} theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) := tendsto_const_div_atTop_nhds_zero_nat 1 theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by rw [← NNReal.tendsto_coe] exact _root_.tendsto_inverse_atTop_nhds_zero_nat theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ℝ≥0) : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C ≠ ⊥) (h' : C ≠ ⊤) : Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by have : (fun n : ℕ ↦ C / n) = fun n : ℕ ↦ ((C.toReal / n : ℝ) : EReal) := by ext n nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n] rw [this, ← coe_zero, tendsto_coe] exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal theorem tendsto_one_div_add_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1 / ((n : ℝ) + 1)) atTop (𝓝 0) := suffices Tendsto (fun n : ℕ ↦ 1 / (↑(n + 1) : ℝ)) atTop (𝓝 0) by simpa (tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1) theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ≥0 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ≥0 𝕜] : Tendsto (algebraMap ℝ≥0 𝕜 ∘ fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by convert (continuous_algebraMap ℝ≥0 𝕜).continuousAt.tendsto.comp tendsto_inverse_atTop_nhds_zero_nat rw [map_zero] theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ 𝕜] : Tendsto (algebraMap ℝ 𝕜 ∘ fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) := NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat 𝕜 /-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division algebra over `ℝ`, e.g., `ℂ`). TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this statement simultaneously on `ℚ`, `ℝ` and `ℂ`. -/ theorem tendsto_natCast_div_add_atTop {𝕜 : Type*} [DivisionRing 𝕜] [TopologicalSpace 𝕜] [CharZero 𝕜] [Algebra ℝ 𝕜] [ContinuousSMul ℝ 𝕜] [IsTopologicalDivisionRing 𝕜] (x : 𝕜) : Tendsto (fun n : ℕ ↦ (n : 𝕜) / (n + x)) atTop (𝓝 1) := by convert Tendsto.congr' ((eventually_ne_atTop 0).mp (Eventually.of_forall fun n hn ↦ _)) _ · exact fun n : ℕ ↦ 1 / (1 + x / n) · field_simp [Nat.cast_ne_zero.mpr hn] · have : 𝓝 (1 : 𝕜) = 𝓝 (1 / (1 + x * (0 : 𝕜))) := by rw [mul_zero, add_zero, div_one] rw [this] refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp) simp_rw [div_eq_mul_inv] refine tendsto_const_nhds.mul ?_ have := ((continuous_algebraMap ℝ 𝕜).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat rw [map_zero, Filter.tendsto_atTop'] at this refine Iff.mpr tendsto_atTop' ?_ intros simp_all only [comp_apply, map_inv₀, map_natCast] /-- For any positive `m : ℕ`, `((n % m : ℕ) : ℝ) / (n : ℝ)` tends to `0` as `n` tends to `∞`. -/ theorem tendsto_mod_div_atTop_nhds_zero_nat {m : ℕ} (hm : 0 < m) : Tendsto (fun n : ℕ => ((n % m : ℕ) : ℝ) / (n : ℝ)) atTop (𝓝 0) := by have h0 : ∀ᶠ n : ℕ in atTop, 0 ≤ (fun n : ℕ => ((n % m : ℕ) : ℝ)) n := by aesop exact tendsto_bdd_div_atTop_nhds_zero h0 (.of_forall (fun n ↦ cast_le.mpr (mod_lt n hm).le)) tendsto_natCast_atTop_atTop theorem Filter.EventuallyEq.div_mul_cancel {α G : Type*} [GroupWithZero G] {f g : α → G} {l : Filter α} (hg : Tendsto g l (𝓟 {0}ᶜ)) : (fun x ↦ f x / g x * g x) =ᶠ[l] fun x ↦ f x := by filter_upwards [hg.le_comap <| preimage_mem_comap (m := g) (mem_principal_self {0}ᶜ)] with x hx aesop /-- If `g` tends to `∞`, then eventually for all `x` we have `(f x / g x) * g x = f x`. -/ theorem Filter.EventuallyEq.div_mul_cancel_atTop {α K : Type*} [Semifield K] [LinearOrder K] [IsStrictOrderedRing K] {f g : α → K} {l : Filter α} (hg : Tendsto g l atTop) : (fun x ↦ f x / g x * g x) =ᶠ[l] fun x ↦ f x := div_mul_cancel <| hg.mono_right <| le_principal_iff.mpr <| mem_of_superset (Ioi_mem_atTop 0) <| by simp /-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive constant, then `f` tends to `∞`. -/ theorem Tendsto.num {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] {f g : α → K} {l : Filter α} (hg : Tendsto g l atTop) {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto f l atTop := (hlim.pos_mul_atTop ha hg).congr' (EventuallyEq.div_mul_cancel_atTop hg) /-- If when `x` tends to `∞`, `g` tends to `∞` and `f x / g x` tends to a positive constant, then `f` tends to `∞`. -/ theorem Tendsto.den {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] [ContinuousInv K] {f g : α → K} {l : Filter α} (hf : Tendsto f l atTop) {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto g l atTop := have hlim' : Tendsto (fun x => g x / f x) l (𝓝 a⁻¹) := by simp_rw [← inv_div (f _)] exact Filter.Tendsto.inv (f := fun x => f x / g x) hlim (hlim'.pos_mul_atTop (inv_pos_of_pos ha) hf).congr' (.div_mul_cancel_atTop hf) /-- If when `x` tends to `∞`, `f x / g x` tends to a positive constant, then `f` tends to `∞` if and only if `g` tends to `∞`. -/ theorem Tendsto.num_atTop_iff_den_atTop {α K : Type*} [Field K] [LinearOrder K] [IsStrictOrderedRing K] [TopologicalSpace K] [OrderTopology K] [ContinuousInv K] {f g : α → K} {l : Filter α} {a : K} (ha : 0 < a) (hlim : Tendsto (fun x => f x / g x) l (𝓝 a)) : Tendsto f l atTop ↔ Tendsto g l atTop := ⟨fun hf ↦ Tendsto.den hf ha hlim, fun hg ↦ Tendsto.num hg ha hlim⟩ /-! ### Powers -/ theorem tendsto_add_one_pow_atTop_atTop_of_pos [Semiring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] {r : α} (h : 0 < r) : Tendsto (fun n : ℕ ↦ (r + 1) ^ n) atTop atTop := tendsto_atTop_atTop_of_monotone' (pow_right_mono₀ <| le_add_of_nonneg_left h.le) <| not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h theorem tendsto_pow_atTop_atTop_of_one_lt [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [Archimedean α] {r : α} (h : 1 < r) : Tendsto (fun n : ℕ ↦ r ^ n) atTop atTop := sub_add_cancel r 1 ▸ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h) theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : ℕ} (h : 1 < m) : Tendsto (fun n : ℕ ↦ m ^ n) atTop atTop := tsub_add_cancel_of_le (le_of_lt h) ▸ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h) theorem tendsto_pow_atTop_nhds_zero_of_lt_one {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 ≤ r) (h₂ : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := h₁.eq_or_lt.elim (fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by simp [_root_.pow_succ, ← hr, tendsto_const_nhds]) (fun hr ↦ have := (one_lt_inv₀ hr).2 h₂ |> tendsto_pow_atTop_atTop_of_one_lt (tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp) @[simp] theorem tendsto_pow_atTop_nhds_zero_iff {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by rw [tendsto_zero_iff_abs_tendsto_zero] refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩ · by_cases hr : 1 = |r| · replace h : Tendsto (fun n : ℕ ↦ |r|^n) atTop (𝓝 0) := by simpa only [← abs_pow, h] simp only [hr.symm, one_pow] at h exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds · apply @not_tendsto_nhds_of_tendsto_atTop 𝕜 ℕ _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _ · refine (pow_right_strictMono₀ <| lt_of_le_of_ne (le_of_not_lt hr_le) hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_) obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr)) exact ⟨n, le_of_lt hn⟩ · simpa only [← abs_pow] · simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {𝕜 : Type*} [Field 𝕜] [LinearOrder 𝕜] [IsStrictOrderedRing 𝕜] [Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 < r) (h₂ : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝[>] 0) := tendsto_inf.2 ⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le h₂, tendsto_principal.2 <| Eventually.of_forall fun _ ↦ pow_pos h₁ _⟩ theorem uniformity_basis_dist_pow_of_lt_one {α : Type*} [PseudoMetricSpace α] {r : ℝ} (h₀ : 0 < r) (h₁ : r < 1) : (uniformity α).HasBasis (fun _ : ℕ ↦ True) fun k ↦ { p : α × α | dist p.1 p.2 < r ^ k } := Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos h₀ _) fun _ ε0 ↦ (exists_pow_lt_of_lt_one ε0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩ theorem geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n) (h : ∀ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h · simp · simp [_root_.pow_succ', mul_assoc, le_refl] theorem geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) : c ^ n * u 0 ≤ u n := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;> simp [_root_.pow_succ', mul_assoc, le_refl] theorem lt_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n) (h : ∀ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _ · simp · simp [_root_.pow_succ', mul_assoc, le_refl] theorem le_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, u (k + 1) ≤ c * u k) : u n ≤ c ^ n * u 0 := by apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;> simp [_root_.pow_succ', mul_assoc, le_refl] /-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`, then it goes to +∞. -/ theorem tendsto_atTop_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c) (hu : ∀ n, c * v n ≤ v (n + 1)) : Tendsto v atTop atTop := (tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <| (tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const h₀ theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0} (hr : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := NNReal.tendsto_coe.1 <| by simp only [NNReal.coe_pow, NNReal.coe_zero, _root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr] @[simp] protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0} : Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := ⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0∞} (hr : r < 1) : Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := by rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ rw [← ENNReal.coe_zero] norm_cast at * apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0∞} : Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := by refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩ lift r to NNReal · refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr ▸ h)) exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩ rw [← coe_zero] at h norm_cast at h ⊢ exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h @[simp] protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ℝ≥0∞} : Tendsto (fun n ↦ r^n) atTop (𝓝 ∞) ↔ 1 < r := by refine ⟨?_, ?_⟩ · contrapose! intro r_le_one h_tends specialize h_tends (Ioi_mem_nhds one_lt_top) simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends obtain ⟨n, hn⟩ := h_tends exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_one₀ (zero_le _) r_le_one · intro r_gt_one have obs := @Tendsto.inv ℝ≥0∞ ℕ _ _ _ (fun n ↦ (r⁻¹)^n) atTop 0 simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs simpa [← ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one lemma ENNReal.eq_zero_of_le_mul_pow {x r : ℝ≥0∞} {ε : ℝ≥0} (hr : r < 1) (h : ∀ n : ℕ, x ≤ ε * r ^ n) : x = 0 := by rw [← nonpos_iff_eq_zero] refine ge_of_tendsto' (f := fun (n : ℕ) ↦ ε * r ^ n) (x := atTop) ?_ h rw [← mul_zero (M₀ := ℝ≥0∞) (a := ε)] exact Tendsto.const_mul (tendsto_pow_atTop_nhds_zero_of_lt_one hr) (Or.inr coe_ne_top) /-! ### Geometric series -/ section Geometric theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ := have : r ≠ 1 := ne_of_lt h₂ have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) := ((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds (hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv] theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : Summable fun n : ℕ ↦ r ^ n := ⟨_, hasSum_geometric_of_lt_one h₁ h₂⟩ theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := (hasSum_geometric_of_lt_one h₁ h₂).tsum_eq theorem hasSum_geometric_two : HasSum (fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n) 2 := by convert hasSum_geometric_of_lt_one _ _ <;> norm_num theorem summable_geometric_two : Summable fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n := ⟨_, hasSum_geometric_two⟩ theorem summable_geometric_two_encode {ι : Type*} [Encodable ι] : Summable fun i : ι ↦ (1 / 2 : ℝ) ^ Encodable.encode i := summable_geometric_two.comp_injective Encodable.encode_injective theorem tsum_geometric_two : (∑' n : ℕ, ((1 : ℝ) / 2) ^ n) = 2 := hasSum_geometric_two.tsum_eq theorem sum_geometric_two_le (n : ℕ) : (∑ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≤ 2 := by have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i := by intro i apply pow_nonneg norm_num convert summable_geometric_two.sum_le_tsum (range n) (fun i _ ↦ this i) exact tsum_geometric_two.symm theorem tsum_geometric_inv_two : (∑' n : ℕ, (2 : ℝ)⁻¹ ^ n) = 2 := (inv_eq_one_div (2 : ℝ)).symm ▸ tsum_geometric_two /-- The sum of `2⁻¹ ^ i` for `n ≤ i` equals `2 * 2⁻¹ ^ n`. -/ theorem tsum_geometric_inv_two_ge (n : ℕ) : (∑' i, ite (n ≤ i) ((2 : ℝ)⁻¹ ^ i) 0) = 2 * 2⁻¹ ^ n := by have A : Summable fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0 := by simpa only [← piecewise_eq_indicator, one_div] using summable_geometric_two.indicator {i | n ≤ i} have B : ((Finset.range n).sum fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0) = 0 := Finset.sum_eq_zero fun i hi ↦ ite_eq_right_iff.2 fun h ↦ (lt_irrefl _ ((Finset.mem_range.1 hi).trans_le h)).elim simp only [← Summable.sum_add_tsum_nat_add n A, B, if_true, zero_add, zero_le', le_add_iff_nonneg_left, pow_add, _root_.tsum_mul_right, tsum_geometric_inv_two] theorem hasSum_geometric_two' (a : ℝ) : HasSum (fun n : ℕ ↦ a / 2 / 2 ^ n) a := by convert HasSum.mul_left (a / 2) (hasSum_geometric_of_lt_one (le_of_lt one_half_pos) one_half_lt_one) using 1 · funext n simp only [one_div, inv_pow] rfl · norm_num theorem summable_geometric_two' (a : ℝ) : Summable fun n : ℕ ↦ a / 2 / 2 ^ n := ⟨a, hasSum_geometric_two' a⟩ theorem tsum_geometric_two' (a : ℝ) : ∑' n : ℕ, a / 2 / 2 ^ n = a := (hasSum_geometric_two' a).tsum_eq /-- **Sum of a Geometric Series** -/ theorem NNReal.hasSum_geometric {r : ℝ≥0} (hr : r < 1) : HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ := by apply NNReal.hasSum_coe.1 push_cast rw [NNReal.coe_sub (le_of_lt hr)] exact hasSum_geometric_of_lt_one r.coe_nonneg hr theorem NNReal.summable_geometric {r : ℝ≥0} (hr : r < 1) : Summable fun n : ℕ ↦ r ^ n := ⟨_, NNReal.hasSum_geometric hr⟩ theorem tsum_geometric_nnreal {r : ℝ≥0} (hr : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := (NNReal.hasSum_geometric hr).tsum_eq /-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number, and for `1 ≤ r` the RHS equals `∞`. -/ @[simp] theorem ENNReal.tsum_geometric (r : ℝ≥0∞) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := by rcases lt_or_le r 1 with hr | hr · rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩ norm_cast at * convert ENNReal.tsum_coe_eq (NNReal.hasSum_geometric hr) rw [ENNReal.coe_inv <| ne_of_gt <| tsub_pos_iff_lt.2 hr, coe_sub, coe_one] · rw [tsub_eq_zero_iff_le.mpr hr, ENNReal.inv_zero, ENNReal.tsum_eq_iSup_nat, iSup_eq_top] refine fun a ha ↦ (ENNReal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp fun n hn ↦ lt_of_lt_of_le hn ?_ calc (n : ℝ≥0∞) = ∑ i ∈ range n, 1 := by rw [sum_const, nsmul_one, card_range] _ ≤ ∑ i ∈ range n, r ^ i := by gcongr; apply one_le_pow₀ hr theorem ENNReal.tsum_geometric_add_one (r : ℝ≥0∞) : ∑' n : ℕ, r ^ (n + 1) = r * (1 - r)⁻¹ := by simp only [_root_.pow_succ', ENNReal.tsum_mul_left, ENNReal.tsum_geometric] end Geometric /-! ### Sequences with geometrically decaying distance in metric spaces In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance between two consecutive terms decays geometrically. We show that such sequences are Cauchy sequences, and bound their distances to the limit. We also discuss series with geometrically decaying terms. -/ section EdistLeGeometric variable [PseudoEMetricSpace α] (r C : ℝ≥0∞) (hr : r < 1) (hC : C ≠ ⊤) {f : ℕ → α} (hu : ∀ n, edist (f n) (f (n + 1)) ≤ C * r ^ n) include hr hC hu in /-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C ≠ ∞`, `r < 1`, then `f` is a Cauchy sequence. -/
theorem cauchySeq_of_edist_le_geometric : CauchySeq f := by refine cauchySeq_of_edist_le_of_tsum_ne_top _ hu ?_ rw [ENNReal.tsum_mul_left, ENNReal.tsum_geometric] refine ENNReal.mul_ne_top hC (ENNReal.inv_ne_top.2 ?_)
Mathlib/Analysis/SpecificLimits/Basic.lean
410
413
/- 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.Algebra.Category.ModuleCat.Sheaf.ChangeOfRings import Mathlib.CategoryTheory.Sites.LocallySurjective /-! # The associated sheaf of a presheaf of modules In this file, given a presheaf of modules `M₀` over a presheaf of rings `R₀`, we construct the associated sheaf of `M₀`. More precisely, if `R` is a sheaf of rings and `α : R₀ ⟶ R.val` is locally bijective, and `A` is the sheafification of the underlying presheaf of abelian groups of `M₀`, i.e. we have a locally bijective map `φ : M₀.presheaf ⟶ A.val`, then we endow `A` with the structure of a sheaf of modules over `R`: this is `PresheafOfModules.sheafify α φ`. In many applications, the morphism `α` shall be the identity, but this more general construction allows the sheafification of both the presheaf of rings and the presheaf of modules. -/ universe w v v₁ u₁ u open CategoryTheory variable {C : Type u₁} [Category.{v₁} C] {J : GrothendieckTopology C} namespace CategoryTheory namespace Presieve.FamilyOfElements section smul variable {R : Cᵒᵖ ⥤ RingCat.{u}} {M : PresheafOfModules.{v} R} {X : C} {P : Presieve X} (r : FamilyOfElements (R ⋙ forget _) P) (m : FamilyOfElements (M.presheaf ⋙ forget _) P) /-- The scalar multiplication of family of elements of a presheaf of modules `M` over `R` by a family of elements of `R`. -/ def smul : FamilyOfElements (M.presheaf ⋙ forget _) P := fun Y f hf => HSMul.hSMul (α := R.obj (Opposite.op Y)) (β := M.obj (Opposite.op Y)) (r f hf) (m f hf) end smul section variable {R₀ R : Cᵒᵖ ⥤ RingCat.{u}} (α : R₀ ⟶ R) [Presheaf.IsLocallyInjective J α] {M₀ : PresheafOfModules.{v} R₀} {A : Cᵒᵖ ⥤ AddCommGrp.{v}} (φ : M₀.presheaf ⟶ A) [Presheaf.IsLocallyInjective J φ] (hA : Presheaf.IsSeparated J A) {X : C} (r : R.obj (Opposite.op X)) (m : A.obj (Opposite.op X)) {P : Presieve X} (r₀ : FamilyOfElements (R₀ ⋙ forget _) P) (m₀ : FamilyOfElements (M₀.presheaf ⋙ forget _) P) include hA lemma _root_.PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective {Y : C} (r₀ r₀' : R₀.obj (Opposite.op Y)) (m₀ m₀' : M₀.obj (Opposite.op Y)) (hr₀ : α.app _ r₀ = α.app _ r₀') (hm₀ : φ.app _ m₀ = φ.app _ m₀') : φ.app _ (r₀ • m₀) = φ.app _ (r₀' • m₀') := by apply hA _ (Presheaf.equalizerSieve r₀ r₀' ⊓ Presheaf.equalizerSieve (F := M₀.presheaf) m₀ m₀') · apply J.intersection_covering · exact Presheaf.equalizerSieve_mem J α _ _ hr₀ · exact Presheaf.equalizerSieve_mem J φ _ _ hm₀ · intro Z g hg rw [← NatTrans.naturality_apply (D := Ab), ← NatTrans.naturality_apply (D := Ab)] erw [M₀.map_smul, M₀.map_smul, hg.1, hg.2] rfl lemma isCompatible_map_smul_aux {Y Z : C} (f : Y ⟶ X) (g : Z ⟶ Y) (r₀ : R₀.obj (Opposite.op Y)) (r₀' : R₀.obj (Opposite.op Z)) (m₀ : M₀.obj (Opposite.op Y)) (m₀' : M₀.obj (Opposite.op Z)) (hr₀ : α.app _ r₀ = R.map f.op r) (hr₀' : α.app _ r₀' = R.map (f.op ≫ g.op) r) (hm₀ : φ.app _ m₀ = A.map f.op m) (hm₀' : φ.app _ m₀' = A.map (f.op ≫ g.op) m) : φ.app _ (M₀.map g.op (r₀ • m₀)) = φ.app _ (r₀' • m₀') := by rw [← PresheafOfModules.Sheafify.app_eq_of_isLocallyInjective α φ hA (R₀.map g.op r₀) r₀' (M₀.map g.op m₀) m₀', M₀.map_smul] · rw [hr₀', R.map_comp, RingCat.comp_apply, ← hr₀, ← RingCat.comp_apply, NatTrans.naturality, RingCat.comp_apply] · rw [hm₀', A.map_comp, AddCommGrp.coe_comp, Function.comp_apply, ← hm₀] erw [NatTrans.naturality_apply φ] variable (hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r) (hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m) include hr₀ hm₀ in lemma isCompatible_map_smul : ((r₀.smul m₀).map (whiskerRight φ (forget _))).Compatible := by intro Y₁ Y₂ Z g₁ g₂ f₁ f₂ h₁ h₂ fac let a₁ := r₀ f₁ h₁ let b₁ := m₀ f₁ h₁ let a₂ := r₀ f₂ h₂ let b₂ := m₀ f₂ h₂ let a₀ := R₀.map g₁.op a₁ let b₀ := M₀.map g₁.op b₁ have ha₁ : (α.app (Opposite.op Y₁)) a₁ = (R.map f₁.op) r := (hr₀ f₁ h₁).symm have ha₂ : (α.app (Opposite.op Y₂)) a₂ = (R.map f₂.op) r := (hr₀ f₂ h₂).symm have hb₁ : (φ.app (Opposite.op Y₁)) b₁ = (A.map f₁.op) m := (hm₀ f₁ h₁).symm have hb₂ : (φ.app (Opposite.op Y₂)) b₂ = (A.map f₂.op) m := (hm₀ f₂ h₂).symm have ha₀ : (α.app (Opposite.op Z)) a₀ = (R.map (f₁.op ≫ g₁.op)) r := by dsimp [a₀] rw [← RingCat.comp_apply, NatTrans.naturality, RingCat.comp_apply, ha₁, Functor.map_comp, RingCat.comp_apply] have hb₀ : (φ.app (Opposite.op Z)) b₀ = (A.map (f₁.op ≫ g₁.op)) m := by dsimp [b₀] erw [NatTrans.naturality_apply φ, hb₁, Functor.map_comp, ConcreteCategory.comp_apply] have ha₀' : (α.app (Opposite.op Z)) a₀ = (R.map (f₂.op ≫ g₂.op)) r := by rw [ha₀, ← op_comp, fac, op_comp] have hb₀' : (φ.app (Opposite.op Z)) b₀ = (A.map (f₂.op ≫ g₂.op)) m := by rw [hb₀, ← op_comp, fac, op_comp] dsimp erw [← NatTrans.naturality_apply φ, ← NatTrans.naturality_apply φ] exact (isCompatible_map_smul_aux α φ hA r m f₁ g₁ a₁ a₀ b₁ b₀ ha₁ ha₀ hb₁ hb₀).trans (isCompatible_map_smul_aux α φ hA r m f₂ g₂ a₂ a₀ b₂ b₀ ha₂ ha₀' hb₂ hb₀').symm end end Presieve.FamilyOfElements end CategoryTheory variable {R₀ : Cᵒᵖ ⥤ RingCat.{u}} {R : Sheaf J RingCat.{u}} (α : R₀ ⟶ R.val) [Presheaf.IsLocallyInjective J α] [Presheaf.IsLocallySurjective J α] namespace PresheafOfModules variable {M₀ : PresheafOfModules.{v} R₀} {A : Sheaf J AddCommGrp.{v}} (φ : M₀.presheaf ⟶ A.val) [Presheaf.IsLocallyInjective J φ] [Presheaf.IsLocallySurjective J φ] namespace Sheafify variable {X Y : Cᵒᵖ} (π : X ⟶ Y) (r r' : R.val.obj X) (m m' : A.val.obj X) /-- Assuming `α : R₀ ⟶ R.val` is the sheafification map of a presheaf of rings `R₀` and `φ : M₀.presheaf ⟶ A.val` is the sheafification map of the underlying sheaf of abelian groups of a presheaf of modules `M₀` over `R₀`, then given `r : R.val.obj X` and `m : A.val.obj X`, this structure contains the data of `x : A.val.obj X` along with the property which makes `x` a good candidate for the definition of the scalar multiplication `r • m`. -/ structure SMulCandidate where /-- The candidate for the scalar product `r • m`. -/ x : A.val.obj X h ⦃Y : Cᵒᵖ⦄ (f : X ⟶ Y) (r₀ : R₀.obj Y) (hr₀ : α.app Y r₀ = R.val.map f r) (m₀ : M₀.obj Y) (hm₀ : φ.app Y m₀ = A.val.map f m) : A.val.map f x = φ.app Y (r₀ • m₀) /-- Constructor for `SMulCandidate`. -/ def SMulCandidate.mk' (S : Sieve X.unop) (hS : S ∈ J X.unop) (r₀ : Presieve.FamilyOfElements (R₀ ⋙ forget _) S.arrows) (m₀ : Presieve.FamilyOfElements (M₀.presheaf ⋙ forget _) S.arrows) (hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r) (hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m) (a : A.val.obj X) (ha : ((r₀.smul m₀).map (whiskerRight φ (forget _))).IsAmalgamation a) : SMulCandidate α φ r m where x := a h Y f a₀ ha₀ b₀ hb₀ := by apply A.isSeparated _ _ (J.pullback_stable f.unop hS) rintro Z g hg dsimp at hg rw [← ConcreteCategory.comp_apply, ← A.val.map_comp, ← NatTrans.naturality_apply (D := Ab)] erw [M₀.map_smul] -- Mismatch between `M₀.map` and `M₀.presheaf.map` refine (ha _ hg).trans (app_eq_of_isLocallyInjective α φ A.isSeparated _ _ _ _ ?_ ?_) · rw [← RingCat.comp_apply, NatTrans.naturality, RingCat.comp_apply, ha₀] apply (hr₀ _ hg).symm.trans simp · erw [NatTrans.naturality_apply φ, hb₀] apply (hm₀ _ hg).symm.trans dsimp rw [Functor.map_comp] rfl instance : Nonempty (SMulCandidate α φ r m) := ⟨by let S := (Presheaf.imageSieve α r ⊓ Presheaf.imageSieve φ m) have hS : S ∈ J _ := by apply J.intersection_covering all_goals apply Presheaf.imageSieve_mem have h₁ : S ≤ Presheaf.imageSieve α r := fun _ _ h => h.1 have h₂ : S ≤ Presheaf.imageSieve φ m := fun _ _ h => h.2 let r₀ := (Presieve.FamilyOfElements.localPreimage (whiskerRight α (forget _)) r).restrict h₁ let m₀ := (Presieve.FamilyOfElements.localPreimage (whiskerRight φ (forget _)) m).restrict h₂ have hr₀ : (r₀.map (whiskerRight α (forget _))).IsAmalgamation r := by rw [Presieve.FamilyOfElements.restrict_map] apply Presieve.isAmalgamation_restrict apply Presieve.FamilyOfElements.isAmalgamation_map_localPreimage have hm₀ : (m₀.map (whiskerRight φ (forget _))).IsAmalgamation m := by rw [Presieve.FamilyOfElements.restrict_map] apply Presieve.isAmalgamation_restrict apply Presieve.FamilyOfElements.isAmalgamation_map_localPreimage exact SMulCandidate.mk' α φ r m S hS r₀ m₀ hr₀ hm₀ _ (Presieve.IsSheafFor.isAmalgamation (((sheafCompose J (forget _)).obj A).2.isSheafFor S hS) (Presieve.FamilyOfElements.isCompatible_map_smul α φ A.isSeparated r m r₀ m₀ hr₀ hm₀))⟩ instance : Subsingleton (SMulCandidate α φ r m) where allEq := by rintro ⟨x₁, h₁⟩ ⟨x₂, h₂⟩ simp only [SMulCandidate.mk.injEq] let S := (Presheaf.imageSieve α r ⊓ Presheaf.imageSieve φ m) have hS : S ∈ J _ := by apply J.intersection_covering all_goals apply Presheaf.imageSieve_mem apply A.isSeparated _ _ hS intro Y f ⟨⟨r₀, hr₀⟩, ⟨m₀, hm₀⟩⟩ rw [h₁ f.op r₀ hr₀ m₀ hm₀, h₂ f.op r₀ hr₀ m₀ hm₀] noncomputable instance : Unique (SMulCandidate α φ r m) := uniqueOfSubsingleton (Nonempty.some inferInstance) /-- The (unique) element in `SMulCandidate α φ r m`. -/ noncomputable def smulCandidate : SMulCandidate α φ r m := default /-- The scalar multiplication on the sheafification of a presheaf of modules. -/ noncomputable def smul : A.val.obj X := (smulCandidate α φ r m).x lemma map_smul_eq {Y : Cᵒᵖ} (f : X ⟶ Y) (r₀ : R₀.obj Y) (hr₀ : α.app Y r₀ = R.val.map f r) (m₀ : M₀.obj Y) (hm₀ : φ.app Y m₀ = A.val.map f m) : A.val.map f (smul α φ r m) = φ.app Y (r₀ • m₀) :=
(smulCandidate α φ r m).h f r₀ hr₀ m₀ hm₀ protected lemma one_smul : smul α φ 1 m = m := by apply A.isSeparated _ _ (Presheaf.imageSieve_mem J φ m) rintro Y f ⟨m₀, hm₀⟩ rw [← hm₀, map_smul_eq α φ 1 m f.op 1 (by simp) m₀ hm₀, one_smul]
Mathlib/Algebra/Category/ModuleCat/Presheaf/Sheafify.lean
219
224
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Logic.Encodable.Pi import Mathlib.Logic.Function.Iterate /-! # The primitive recursive functions The primitive recursive functions are the least collection of functions `ℕ → ℕ` which are closed under projections (using the `pair` pairing function), composition, zero, successor, and primitive recursion (i.e. `Nat.rec` where the motive is `C n := ℕ`). We can extend this definition to a large class of basic types by using canonical encodings of types as natural numbers (Gödel numbering), which we implement through the type class `Encodable`. (More precisely, we need that the composition of encode with decode yields a primitive recursive function, so we have the `Primcodable` type class for this.) In the above, the pairing function is primitive recursive by definition. This deviates from the textbook definition of primitive recursive functions, which instead work with *`n`-ary* functions. We formalize the textbook definition in `Nat.Primrec'`. `Nat.Primrec'.prim_iff` then proves it is equivalent to our chosen formulation. For more discussionn of this and other design choices in this formalization, see [carneiro2019]. ## Main definitions - `Nat.Primrec f`: `f` is primitive recursive, for functions `f : ℕ → ℕ` - `Primrec f`: `f` is primitive recursive, for functions between `Primcodable` types - `Primcodable α`: well-behaved encoding of `α` into `ℕ`, i.e. one such that roundtripping through the encoding functions adds no computational power ## References * [Mario Carneiro, *Formalizing computability theory via partial recursive functions*][carneiro2019] -/ open List (Vector) open Denumerable Encodable Function namespace Nat /-- Calls the given function on a pair of entries `n`, encoded via the pairing function. -/ @[simp, reducible] def unpaired {α} (f : ℕ → ℕ → α) (n : ℕ) : α := f n.unpair.1 n.unpair.2 /-- The primitive recursive functions `ℕ → ℕ`. -/ protected inductive Primrec : (ℕ → ℕ) → Prop | zero : Nat.Primrec fun _ => 0 | protected succ : Nat.Primrec succ | left : Nat.Primrec fun n => n.unpair.1 | right : Nat.Primrec fun n => n.unpair.2 | pair {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => pair (f n) (g n) | comp {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec fun n => f (g n) | prec {f g} : Nat.Primrec f → Nat.Primrec g → Nat.Primrec (unpaired fun z n => n.rec (f z) fun y IH => g <| pair z <| pair y IH) namespace Primrec theorem of_eq {f g : ℕ → ℕ} (hf : Nat.Primrec f) (H : ∀ n, f n = g n) : Nat.Primrec g := (funext H : f = g) ▸ hf theorem const : ∀ n : ℕ, Nat.Primrec fun _ => n | 0 => zero | n + 1 => Primrec.succ.comp (const n) protected theorem id : Nat.Primrec id := (left.pair right).of_eq fun n => by simp theorem prec1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec fun n => n.rec m fun y IH => f <| Nat.pair y IH := ((prec (const m) (hf.comp right)).comp (zero.pair Primrec.id)).of_eq fun n => by simp theorem casesOn1 {f} (m : ℕ) (hf : Nat.Primrec f) : Nat.Primrec (Nat.casesOn · m f) := (prec1 m (hf.comp left)).of_eq <| by simp -- Porting note: `Nat.Primrec.casesOn` is already declared as a recursor. theorem casesOn' {f g} (hf : Nat.Primrec f) (hg : Nat.Primrec g) : Nat.Primrec (unpaired fun z n => n.casesOn (f z) fun y => g <| Nat.pair z y) := (prec hf (hg.comp (pair left (left.comp right)))).of_eq fun n => by simp protected theorem swap : Nat.Primrec (unpaired (swap Nat.pair)) := (pair right left).of_eq fun n => by simp theorem swap' {f} (hf : Nat.Primrec (unpaired f)) : Nat.Primrec (unpaired (swap f)) := (hf.comp .swap).of_eq fun n => by simp theorem pred : Nat.Primrec pred := (casesOn1 0 Primrec.id).of_eq fun n => by cases n <;> simp [*] theorem add : Nat.Primrec (unpaired (· + ·)) := (prec .id ((Primrec.succ.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.add_assoc] theorem sub : Nat.Primrec (unpaired (· - ·)) := (prec .id ((pred.comp right).comp right)).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.sub_add_eq] theorem mul : Nat.Primrec (unpaired (· * ·)) := (prec zero (add.comp (pair left (right.comp right)))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, mul_succ, add_comm _ (unpair p).fst] theorem pow : Nat.Primrec (unpaired (· ^ ·)) := (prec (const 1) (mul.comp (pair (right.comp right) left))).of_eq fun p => by simp; induction p.unpair.2 <;> simp [*, Nat.pow_succ] end Primrec end Nat /-- A `Primcodable` type is, essentially, an `Encodable` type for which the encode/decode functions are primitive recursive. However, such a definition is circular. Instead, we ask that the composition of `decode : ℕ → Option α` with `encode : Option α → ℕ` is primitive recursive. Said composition is the identity function, restricted to the image of `encode`. Thus, in a way, the added requirement ensures that no predicates can be smuggled in through a cunning choice of the subset of `ℕ` into which the type is encoded. -/ class Primcodable (α : Type*) extends Encodable α where -- Porting note: was `prim [] `. -- This means that `prim` does not take the type explicitly in Lean 4 prim : Nat.Primrec fun n => Encodable.encode (decode n) namespace Primcodable open Nat.Primrec instance (priority := 10) ofDenumerable (α) [Denumerable α] : Primcodable α := ⟨Nat.Primrec.succ.of_eq <| by simp⟩ /-- Builds a `Primcodable` instance from an equivalence to a `Primcodable` type. -/ def ofEquiv (α) {β} [Primcodable α] (e : β ≃ α) : Primcodable β := { __ := Encodable.ofEquiv α e prim := (@Primcodable.prim α _).of_eq fun n => by rw [decode_ofEquiv] cases (@decode α _ n) <;> simp [encode_ofEquiv] } instance empty : Primcodable Empty := ⟨zero⟩ instance unit : Primcodable PUnit := ⟨(casesOn1 1 zero).of_eq fun n => by cases n <;> simp⟩ instance option {α : Type*} [h : Primcodable α] : Primcodable (Option α) := ⟨(casesOn1 1 ((casesOn1 0 (.comp .succ .succ)).comp (@Primcodable.prim α _))).of_eq fun n => by cases n with | zero => rfl | succ n => rw [decode_option_succ] cases H : @decode α _ n <;> simp [H]⟩ instance bool : Primcodable Bool := ⟨(casesOn1 1 (casesOn1 2 zero)).of_eq fun n => match n with | 0 => rfl | 1 => rfl | (n + 2) => by rw [decode_ge_two] <;> simp⟩ end Primcodable /-- `Primrec f` means `f` is primitive recursive (after encoding its input and output as natural numbers). -/ def Primrec {α β} [Primcodable α] [Primcodable β] (f : α → β) : Prop := Nat.Primrec fun n => encode ((@decode α _ n).map f) namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec protected theorem encode : Primrec (@encode α _) := (@Primcodable.prim α _).of_eq fun n => by cases @decode α _ n <;> rfl protected theorem decode : Primrec (@decode α _) := Nat.Primrec.succ.comp (@Primcodable.prim α _) theorem dom_denumerable {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Nat.Primrec fun n => encode (f (ofNat α n)) := ⟨fun h => (pred.comp h).of_eq fun n => by simp, fun h => (Nat.Primrec.succ.comp h).of_eq fun n => by simp⟩ theorem nat_iff {f : ℕ → ℕ} : Primrec f ↔ Nat.Primrec f := dom_denumerable theorem encdec : Primrec fun n => encode (@decode α _ n) := nat_iff.2 Primcodable.prim theorem option_some : Primrec (@some α) := ((casesOn1 0 (Nat.Primrec.succ.comp .succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp theorem of_eq {f g : α → σ} (hf : Primrec f) (H : ∀ n, f n = g n) : Primrec g := (funext H : f = g) ▸ hf theorem const (x : σ) : Primrec fun _ : α => x := ((casesOn1 0 (.const (encode x).succ)).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> rfl protected theorem id : Primrec (@id α) := (@Primcodable.prim α).of_eq <| by simp theorem comp {f : β → σ} {g : α → β} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => f (g a) := ((casesOn1 0 (.comp hf (pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] theorem succ : Primrec Nat.succ := nat_iff.2 Nat.Primrec.succ theorem pred : Primrec Nat.pred := nat_iff.2 Nat.Primrec.pred theorem encode_iff {f : α → σ} : (Primrec fun a => encode (f a)) ↔ Primrec f := ⟨fun h => Nat.Primrec.of_eq h fun n => by cases @decode α _ n <;> rfl, Primrec.encode.comp⟩ theorem ofNat_iff {α β} [Denumerable α] [Primcodable β] {f : α → β} : Primrec f ↔ Primrec fun n => f (ofNat α n) := dom_denumerable.trans <| nat_iff.symm.trans encode_iff protected theorem ofNat (α) [Denumerable α] : Primrec (ofNat α) := ofNat_iff.1 Primrec.id theorem option_some_iff {f : α → σ} : (Primrec fun a => some (f a)) ↔ Primrec f := ⟨fun h => encode_iff.1 <| pred.comp <| encode_iff.2 h, option_some.comp⟩ theorem of_equiv {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e := letI : Primcodable β := Primcodable.ofEquiv α e encode_iff.1 Primrec.encode theorem of_equiv_symm {β} {e : β ≃ α} : haveI := Primcodable.ofEquiv α e Primrec e.symm := letI := Primcodable.ofEquiv α e encode_iff.1 (show Primrec fun a => encode (e (e.symm a)) by simp [Primrec.encode]) theorem of_equiv_iff {β} (e : β ≃ α) {f : σ → β} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv_symm.comp h).of_eq fun a => by simp, of_equiv.comp⟩ theorem of_equiv_symm_iff {β} (e : β ≃ α) {f : σ → α} : haveI := Primcodable.ofEquiv α e (Primrec fun a => e.symm (f a)) ↔ Primrec f := letI := Primcodable.ofEquiv α e ⟨fun h => (of_equiv.comp h).of_eq fun a => by simp, of_equiv_symm.comp⟩ end Primrec namespace Primcodable open Nat.Primrec instance prod {α β} [Primcodable α] [Primcodable β] : Primcodable (α × β) := ⟨((casesOn' zero ((casesOn' zero .succ).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1; · simp cases @decode β _ n.unpair.2 <;> simp⟩ end Primcodable namespace Primrec variable {α : Type*} [Primcodable α] open Nat.Primrec theorem fst {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.fst α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp left)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp theorem snd {α β} [Primcodable α] [Primcodable β] : Primrec (@Prod.snd α β) := ((casesOn' zero ((casesOn' zero (Nat.Primrec.succ.comp right)).comp (pair right ((@Primcodable.prim β).comp left)))).comp (pair right ((@Primcodable.prim α).comp left))).of_eq fun n => by simp only [Nat.unpaired, Nat.unpair_pair, decode_prod_val] cases @decode α _ n.unpair.1 <;> simp cases @decode β _ n.unpair.2 <;> simp theorem pair {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {f : α → β} {g : α → γ} (hf : Primrec f) (hg : Primrec g) : Primrec fun a => (f a, g a) := ((casesOn1 0 (Nat.Primrec.succ.comp <| .pair (Nat.Primrec.pred.comp hf) (Nat.Primrec.pred.comp hg))).comp (@Primcodable.prim α _)).of_eq fun n => by cases @decode α _ n <;> simp [encodek] theorem unpair : Primrec Nat.unpair := (pair (nat_iff.2 .left) (nat_iff.2 .right)).of_eq fun n => by simp theorem list_getElem?₁ : ∀ l : List α, Primrec (l[·]? : ℕ → Option α) | [] => dom_denumerable.2 zero | a :: l => dom_denumerable.2 <| (casesOn1 (encode a).succ <| dom_denumerable.1 <| list_getElem?₁ l).of_eq fun n => by cases n <;> simp @[deprecated (since := "2025-02-14")] alias list_get?₁ := list_getElem?₁ end Primrec /-- `Primrec₂ f` means `f` is a binary primitive recursive function. This is technically unnecessary since we can always curry all the arguments together, but there are enough natural two-arg functions that it is convenient to express this directly. -/ def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) := Primrec fun p : α × β => f p.1 p.2 /-- `PrimrecPred p` means `p : α → Prop` is a (decidable) primitive recursive predicate, which is to say that `decide ∘ p : α → Bool` is primitive recursive. -/ def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] := Primrec fun a => decide (p a) /-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable) primitive recursive relation, which is to say that `decide ∘ p : α → β → Bool` is primitive recursive. -/ def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop) [∀ a b, Decidable (s a b)] := Primrec₂ fun a b => decide (s a b) namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem mk {f : α → β → σ} (hf : Primrec fun p : α × β => f p.1 p.2) : Primrec₂ f := hf theorem of_eq {f g : α → β → σ} (hg : Primrec₂ f) (H : ∀ a b, f a b = g a b) : Primrec₂ g := (by funext a b; apply H : f = g) ▸ hg theorem const (x : σ) : Primrec₂ fun (_ : α) (_ : β) => x := Primrec.const _ protected theorem pair : Primrec₂ (@Prod.mk α β) := Primrec.pair .fst .snd theorem left : Primrec₂ fun (a : α) (_ : β) => a := .fst theorem right : Primrec₂ fun (_ : α) (b : β) => b := .snd theorem natPair : Primrec₂ Nat.pair := by simp [Primrec₂, Primrec]; constructor theorem unpaired {f : ℕ → ℕ → α} : Primrec (Nat.unpaired f) ↔ Primrec₂ f := ⟨fun h => by simpa using h.comp natPair, fun h => h.comp Primrec.unpair⟩ theorem unpaired' {f : ℕ → ℕ → ℕ} : Nat.Primrec (Nat.unpaired f) ↔ Primrec₂ f := Primrec.nat_iff.symm.trans unpaired theorem encode_iff {f : α → β → σ} : (Primrec₂ fun a b => encode (f a b)) ↔ Primrec₂ f := Primrec.encode_iff theorem option_some_iff {f : α → β → σ} : (Primrec₂ fun a b => some (f a b)) ↔ Primrec₂ f := Primrec.option_some_iff theorem ofNat_iff {α β σ} [Denumerable α] [Denumerable β] [Primcodable σ] {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => f (ofNat α m) (ofNat β n) := (Primrec.ofNat_iff.trans <| by simp).trans unpaired theorem uncurry {f : α → β → σ} : Primrec (Function.uncurry f) ↔ Primrec₂ f := by rw [show Function.uncurry f = fun p : α × β => f p.1 p.2 from funext fun ⟨a, b⟩ => rfl]; rfl theorem curry {f : α × β → σ} : Primrec₂ (Function.curry f) ↔ Primrec f := by rw [← uncurry, Function.uncurry_curry] end Primrec₂ section Comp variable {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable γ] [Primcodable δ] [Primcodable σ] theorem Primrec.comp₂ {f : γ → σ} {g : α → β → γ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a b => f (g a b) := hf.comp hg theorem Primrec₂.comp {f : β → γ → σ} {g : α → β} {h : α → γ} (hf : Primrec₂ f) (hg : Primrec g) (hh : Primrec h) : Primrec fun a => f (g a) (h a) := Primrec.comp hf (hg.pair hh) theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α → β → δ} (hf : Primrec₂ f) (hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) := hf.comp hg hh theorem PrimrecPred.comp {p : β → Prop} [DecidablePred p] {f : α → β} : PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) := Primrec.comp theorem PrimrecRel.comp {R : β → γ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} : PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) := Primrec₂.comp theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ} {g : α → β → δ} : PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) := PrimrecRel.comp end Comp theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q := Primrec.of_eq hp fun a => Bool.decide_congr (H a) theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop} [∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r) (H : ∀ a b, r a b ↔ s a b) : PrimrecRel s := Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b) namespace Primrec₂ variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] open Nat.Primrec theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) := h.comp₂ Primrec₂.right Primrec₂.left theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec (.unpaired fun m n => encode <| (@decode α _ m).bind fun a => (@decode β _ n).map (f a)) := by have : ∀ (a : Option α) (b : Option β), Option.map (fun p : α × β => f p.1 p.2) (Option.bind a fun a : α => Option.map (Prod.mk a) b) = Option.bind a fun a => Option.map (f a) b := fun a b => by cases a <;> cases b <;> rfl simp [Primrec₂, Primrec, this] theorem nat_iff' {f : α → β → σ} : Primrec₂ f ↔ Primrec₂ fun m n : ℕ => (@decode α _ m).bind fun a => Option.map (f a) (@decode β _ n) := nat_iff.trans <| unpaired'.trans encode_iff end Primrec₂ namespace Primrec variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) := hf.of_eq fun _ => rfl theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) := Primrec₂.nat_iff.2 <| ((Nat.Primrec.casesOn' .zero <| (Nat.Primrec.prec hf <| .comp hg <| Nat.Primrec.left.pair <| (Nat.Primrec.left.comp .right).pair <| Nat.Primrec.pred.comp <| Nat.Primrec.right.comp .right).comp <| Nat.Primrec.right.pair <| Nat.Primrec.right.comp Nat.Primrec.left).comp <| Nat.Primrec.id.pair <| (@Primcodable.prim α).comp Nat.Primrec.left).of_eq fun n => by simp only [Nat.unpaired, id_eq, Nat.unpair_pair, decode_prod_val, decode_nat, Option.some_bind, Option.map_map, Option.map_some'] rcases @decode α _ n.unpair.1 with - | a; · rfl simp only [Nat.pred_eq_sub_one, encode_some, Nat.succ_eq_add_one, encodek, Option.map_some', Option.some_bind, Option.map_map] induction' n.unpair.2 with m <;> simp [encodek] simp [*, encodek] theorem nat_rec' {f : α → ℕ} {g : α → β} {h : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (f a).rec (motive := fun _ => β) (g a) fun n IH => h a (n, IH) := (nat_rec hg hh).comp .id hf theorem nat_rec₁ {f : ℕ → α → α} (a : α) (hf : Primrec₂ f) : Primrec (Nat.rec a f) := nat_rec' .id (const a) <| comp₂ hf Primrec₂.right theorem nat_casesOn' {f : α → β} {g : α → ℕ → β} (hf : Primrec f) (hg : Primrec₂ g) : Primrec₂ fun a (n : ℕ) => (n.casesOn (f a) (g a) : β) := nat_rec hf <| hg.comp₂ Primrec₂.left <| comp₂ fst Primrec₂.right theorem nat_casesOn {f : α → ℕ} {g : α → β} {h : α → ℕ → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => ((f a).casesOn (g a) (h a) : β) := (nat_casesOn' hg hh).comp .id hf theorem nat_casesOn₁ {f : ℕ → α} (a : α) (hf : Primrec f) : Primrec (fun (n : ℕ) => (n.casesOn a f : α)) := nat_casesOn .id (const a) (comp₂ hf .right) theorem nat_iterate {f : α → ℕ} {g : α → β} {h : α → β → β} (hf : Primrec f) (hg : Primrec g) (hh : Primrec₂ h) : Primrec fun a => (h a)^[f a] (g a) := (nat_rec' hf hg (hh.comp₂ Primrec₂.left <| snd.comp₂ Primrec₂.right)).of_eq fun a => by induction f a <;> simp [*, -Function.iterate_succ, Function.iterate_succ'] theorem option_casesOn {o : α → Option β} {f : α → σ} {g : α → β → σ} (ho : Primrec o) (hf : Primrec f) (hg : Primrec₂ g) : @Primrec _ σ _ _ fun a => Option.casesOn (o a) (f a) (g a) := encode_iff.1 <| (nat_casesOn (encode_iff.2 ho) (encode_iff.2 hf) <| pred.comp₂ <| Primrec₂.encode_iff.2 <| (Primrec₂.nat_iff'.1 hg).comp₂ ((@Primrec.encode α _).comp fst).to₂ Primrec₂.right).of_eq fun a => by rcases o a with - | b <;> simp [encodek] theorem option_bind {f : α → Option β} {g : α → β → Option σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).bind (g a) := (option_casesOn hf (const none) hg).of_eq fun a => by cases f a <;> rfl theorem option_bind₁ {f : α → Option σ} (hf : Primrec f) : Primrec fun o => Option.bind o f := option_bind .id (hf.comp snd).to₂ theorem option_map {f : α → Option β} {g : α → β → σ} (hf : Primrec f) (hg : Primrec₂ g) : Primrec fun a => (f a).map (g a) := (option_bind hf (option_some.comp₂ hg)).of_eq fun x => by cases f x <;> rfl theorem option_map₁ {f : α → σ} (hf : Primrec f) : Primrec (Option.map f) := option_map .id (hf.comp snd).to₂ theorem option_iget [Inhabited α] : Primrec (@Option.iget α _) := (option_casesOn .id (const <| @default α _) .right).of_eq fun o => by cases o <;> rfl theorem option_isSome : Primrec (@Option.isSome α) := (option_casesOn .id (const false) (const true).to₂).of_eq fun o => by cases o <;> rfl theorem option_getD : Primrec₂ (@Option.getD α) := Primrec.of_eq (option_casesOn Primrec₂.left Primrec₂.right .right) fun ⟨o, a⟩ => by cases o <;> rfl theorem bind_decode_iff {f : α → β → Option σ} : (Primrec₂ fun a n => (@decode β _ n).bind (f a)) ↔ Primrec₂ f := ⟨fun h => by simpa [encodek] using h.comp fst ((@Primrec.encode β _).comp snd), fun h => option_bind (Primrec.decode.comp snd) <| h.comp (fst.comp fst) snd⟩ theorem map_decode_iff {f : α → β → σ} : (Primrec₂ fun a n => (@decode β _ n).map (f a)) ↔ Primrec₂ f := by simp only [Option.map_eq_bind] exact bind_decode_iff.trans Primrec₂.option_some_iff theorem nat_add : Primrec₂ ((· + ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.add theorem nat_sub : Primrec₂ ((· - ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.sub theorem nat_mul : Primrec₂ ((· * ·) : ℕ → ℕ → ℕ) := Primrec₂.unpaired'.1 Nat.Primrec.mul theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => bif (c a) then (f a) else (g a) := (nat_casesOn (encode_iff.2 hc) hg (hf.comp fst).to₂).of_eq fun a => by cases c a <;> rfl theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c) (hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by simpa [Bool.cond_decide] using cond hc hf hg theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) := (nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by dsimp [swap] rcases e : p.1 - p.2 with - | n · simp [Nat.sub_eq_zero_iff_le.1 e] · simp [not_le.2 (Nat.lt_of_sub_eq_succ e)] theorem nat_min : Primrec₂ (@min ℕ _) := ite nat_le fst snd theorem nat_max : Primrec₂ (@max ℕ _) := ite (nat_le.comp fst snd) snd fst theorem dom_bool (f : Bool → α) : Primrec f := (cond .id (const (f true)) (const (f false))).of_eq fun b => by cases b <;> rfl theorem dom_bool₂ (f : Bool → Bool → α) : Primrec₂ f := (cond fst ((dom_bool (f true)).comp snd) ((dom_bool (f false)).comp snd)).of_eq fun ⟨a, b⟩ => by cases a <;> rfl protected theorem not : Primrec not := dom_bool _ protected theorem and : Primrec₂ and := dom_bool₂ _ protected theorem or : Primrec₂ or := dom_bool₂ _ theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : PrimrecPred fun a => ¬p a := (Primrec.not.comp hp).of_eq fun n => by simp theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a := (Primrec.and.comp hp hq).of_eq fun n => by simp theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q] (hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a := (Primrec.or.comp hp hq).of_eq fun n => by simp protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) := have : PrimrecRel fun a b : ℕ => a = b := (PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff] (this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq fun _ _ => encode_injective.eq_iff protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) := (nat_le.comp snd fst).not.of_eq fun p => by simp theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β} (hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) := ite (hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none) theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Option α) := (option_casesOn fst snd (fst.comp fst).to₂).of_eq fun ⟨o₁, o₂⟩ => by cases o₁ <;> cases o₂ <;> rfl protected theorem decode₂ : Primrec (decode₂ α) := option_bind .decode <| option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) : ∀ l : List β, Primrec fun a => l.findIdx (p a) | [] => const 0 | a :: l => (cond (hp.comp .id (const a)) (const 0) (succ.comp (list_findIdx₁ hp l))).of_eq fun n => by simp [List.findIdx_cons] theorem list_idxOf₁ [DecidableEq α] (l : List α) : Primrec fun a => l.idxOf a := list_findIdx₁ (.swap .beq) l @[deprecated (since := "2025-01-30")] alias list_indexOf₁ := list_idxOf₁ theorem dom_fintype [Finite α] (f : α → σ) : Primrec f := let ⟨l, _, m⟩ := Finite.exists_univ_list α option_some_iff.1 <| by haveI := decidableEqOfEncodable α refine ((list_getElem?₁ (l.map f)).comp (list_idxOf₁ l)).of_eq fun a => ?_ rw [List.getElem?_map, List.getElem?_idxOf (m a), Option.map_some'] -- Porting note: These are new lemmas -- I added it because it actually simplified the proofs -- and because I couldn't understand the original proof /-- A function is `PrimrecBounded` if its size is bounded by a primitive recursive function -/ def PrimrecBounded (f : α → β) : Prop := ∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)] (hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) := (nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2) hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp)) (snd |> fst.comp |> succ.comp) (snd.comp snd))).of_eq fun x => by induction f x <;> simp [Nat.findGreatest, *] /-- To show a function `f : α → ℕ` is primitive recursive, it is enough to show that the function is bounded by a primitive recursive function and that its graph is primitive recursive -/ theorem of_graph {f : α → ℕ} (h₁ : PrimrecBounded f) (h₂ : PrimrecRel fun a b => f a = b) : Primrec f := by rcases h₁ with ⟨g, pg, hg : ∀ x, f x ≤ g x⟩ refine (nat_findGreatest pg h₂).of_eq fun n => ?_ exact (Nat.findGreatest_spec (P := fun b => f n = b) (hg n) rfl).symm -- We show that division is primitive recursive by showing that the graph is theorem nat_div : Primrec₂ ((· / ·) : ℕ → ℕ → ℕ) := by refine of_graph ⟨_, fst, fun p => Nat.div_le_self _ _⟩ ?_ have : PrimrecRel fun (a : ℕ × ℕ) (b : ℕ) => (a.2 = 0 ∧ b = 0) ∨ (0 < a.2 ∧ b * a.2 ≤ a.1 ∧ a.1 < (b + 1) * a.2) := PrimrecPred.or (.and (const 0 |> Primrec.eq.comp (fst |> snd.comp)) (const 0 |> Primrec.eq.comp snd)) (.and (nat_lt.comp (const 0) (fst |> snd.comp)) <| .and (nat_le.comp (nat_mul.comp snd (fst |> snd.comp)) (fst |> fst.comp)) (nat_lt.comp (fst.comp fst) (nat_mul.comp (Primrec.succ.comp snd) (snd.comp fst)))) refine this.of_eq ?_ rintro ⟨a, k⟩ q if H : k = 0 then simp [H, eq_comm] else have : q * k ≤ a ∧ a < (q + 1) * k ↔ q = a / k := by rw [le_antisymm_iff, ← (@Nat.lt_succ _ q), Nat.le_div_iff_mul_le (Nat.pos_of_ne_zero H), Nat.div_lt_iff_lt_mul (Nat.pos_of_ne_zero H)] simpa [H, zero_lt_iff, eq_comm (b := q)] theorem nat_mod : Primrec₂ ((· % ·) : ℕ → ℕ → ℕ) := (nat_sub.comp fst (nat_mul.comp snd nat_div)).to₂.of_eq fun m n => by apply Nat.sub_eq_of_eq_add simp [add_comm (m % n), Nat.div_add_mod] theorem nat_bodd : Primrec Nat.bodd := (Primrec.beq.comp (nat_mod.comp .id (const 2)) (const 1)).of_eq fun n => by cases H : n.bodd <;> simp [Nat.mod_two_of_bodd, H] theorem nat_div2 : Primrec Nat.div2 := (nat_div.comp .id (const 2)).of_eq fun n => n.div2_val.symm theorem nat_double : Primrec (fun n : ℕ => 2 * n) := nat_mul.comp (const _) Primrec.id theorem nat_double_succ : Primrec (fun n : ℕ => 2 * n + 1) := nat_double |> Primrec.succ.comp end Primrec section variable {α : Type*} {β : Type*} {σ : Type*} variable [Primcodable α] [Primcodable β] [Primcodable σ] variable (H : Nat.Primrec fun n => Encodable.encode (@decode (List β) _ n)) open Primrec private def prim : Primcodable (List β) := ⟨H⟩ private theorem list_casesOn' {f : α → List β} {g : α → σ} {h : α → β × List β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : @Primrec _ σ _ _ fun a => List.casesOn (f a) (g a) fun b l => h a (b, l) := letI := prim H have : @Primrec _ (Option σ) _ _ fun a => (@decode (Option (β × List β)) _ (encode (f a))).map fun o => Option.casesOn o (g a) (h a) := ((@map_decode_iff _ (Option (β × List β)) _ _ _ _ _).2 <| to₂ <| option_casesOn snd (hg.comp fst) (hh.comp₂ (fst.comp₂ Primrec₂.left) Primrec₂.right)).comp .id (encode_iff.2 hf) option_some_iff.1 <| this.of_eq fun a => by rcases f a with - | ⟨b, l⟩ <;> simp [encodek] private theorem list_foldl' {f : α → List β} {g : α → σ} {h : α → σ × β → σ} (hf : haveI := prim H; Primrec f) (hg : Primrec g) (hh : haveI := prim H; Primrec₂ h) : Primrec fun a => (f a).foldl (fun s b => h a (s, b)) (g a) := by letI := prim H let G (a : α) (IH : σ × List β) : σ × List β := List.casesOn IH.2 IH fun b l => (h a (IH.1, b), l) have hG : Primrec₂ G := list_casesOn' H (snd.comp snd) snd <| to₂ <| pair (hh.comp (fst.comp fst) <| pair ((fst.comp snd).comp fst) (fst.comp snd)) (snd.comp snd) let F := fun (a : α) (n : ℕ) => (G a)^[n] (g a, f a) have hF : Primrec fun a => (F a (encode (f a))).1 := (fst.comp <| nat_iterate (encode_iff.2 hf) (pair hg hf) <| hG) suffices ∀ a n, F a n = (((f a).take n).foldl (fun s b => h a (s, b)) (g a), (f a).drop n) by refine hF.of_eq fun a => ?_ rw [this, List.take_of_length_le (length_le_encode _)] introv dsimp only [F] generalize f a = l generalize g a = x induction n generalizing l x with | zero => rfl | succ n IH => simp only [iterate_succ, comp_apply] rcases l with - | ⟨b, l⟩ <;> simp [G, IH] private theorem list_cons' : (haveI := prim H; Primrec₂ (@List.cons β)) := letI := prim H encode_iff.1 (succ.comp <| Primrec₂.natPair.comp (encode_iff.2 fst) (encode_iff.2 snd)) private theorem list_reverse' : haveI := prim H Primrec (@List.reverse β) := letI := prim H (list_foldl' H .id (const []) <| to₂ <| ((list_cons' H).comp snd fst).comp snd).of_eq (suffices ∀ l r, List.foldl (fun (s : List β) (b : β) => b :: s) r l = List.reverseAux l r from fun l => this l [] fun l => by induction l <;> simp [*, List.reverseAux]) end namespace Primcodable variable {α : Type*} {β : Type*} variable [Primcodable α] [Primcodable β] open Primrec instance sum : Primcodable (α ⊕ β) := ⟨Primrec.nat_iff.1 <| (encode_iff.2 (cond nat_bodd (((@Primrec.decode β _).comp nat_div2).option_map <| to₂ <| nat_double_succ.comp (Primrec.encode.comp snd))
(((@Primrec.decode α _).comp nat_div2).option_map <| to₂ <| nat_double.comp (Primrec.encode.comp snd)))).of_eq fun n => show _ = encode (decodeSum n) by simp only [decodeSum, Nat.boddDiv2_eq] cases Nat.bodd n <;> simp [decodeSum]
Mathlib/Computability/Primrec.lean
797
802
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import Mathlib.Analysis.SpecialFunctions.ExpDeriv /-! # Grönwall's inequality The main technical result of this file is the Grönwall-like inequality `norm_le_gronwallBound_of_norm_deriv_right_le`. It states that if `f : ℝ → E` satisfies `‖f a‖ ≤ δ` and `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then for all `x ∈ [a, b]` we have `‖f x‖ ≤ δ * exp (K * x) + (ε / K) * (exp (K * x) - 1)`. Then we use this inequality to prove some estimates on the possible rate of growth of the distance between two approximate or exact solutions of an ordinary differential equation. The proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*, Sec. 4.5][HubbardWest-ode], where `norm_le_gronwallBound_of_norm_deriv_right_le` is called “Fundamental Inequality”. ## TODO - Once we have FTC, prove an inequality for a function satisfying `‖f' x‖ ≤ K x * ‖f x‖ + ε`, or more generally `liminf_{y→x+0} (f y - f x)/(y - x) ≤ K x * f x + ε` with any sign of `K x` and `f x`. -/ open Metric Set Asymptotics Filter Real open scoped Topology NNReal variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] /-! ### Technical lemmas about `gronwallBound` -/ /-- Upper bound used in several Grönwall-like inequalities. -/ noncomputable def gronwallBound (δ K ε x : ℝ) : ℝ := if K = 0 then δ + ε * x else δ * exp (K * x) + ε / K * (exp (K * x) - 1) theorem gronwallBound_K0 (δ ε : ℝ) : gronwallBound δ 0 ε = fun x => δ + ε * x := funext fun _ => if_pos rfl theorem gronwallBound_of_K_ne_0 {δ K ε : ℝ} (hK : K ≠ 0) : gronwallBound δ K ε = fun x => δ * exp (K * x) + ε / K * (exp (K * x) - 1) := funext fun _ => if_neg hK theorem hasDerivAt_gronwallBound (δ K ε x : ℝ) : HasDerivAt (gronwallBound δ K ε) (K * gronwallBound δ K ε x + ε) x := by by_cases hK : K = 0 · subst K simp only [gronwallBound_K0, zero_mul, zero_add] convert ((hasDerivAt_id x).const_mul ε).const_add δ rw [mul_one] · simp only [gronwallBound_of_K_ne_0 hK] convert (((hasDerivAt_id x).const_mul K).exp.const_mul δ).add ((((hasDerivAt_id x).const_mul K).exp.sub_const 1).const_mul (ε / K)) using 1 simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel₀ _ hK] ring theorem hasDerivAt_gronwallBound_shift (δ K ε x a : ℝ) : HasDerivAt (fun y => gronwallBound δ K ε (y - a)) (K * gronwallBound δ K ε (x - a) + ε) x := by convert (hasDerivAt_gronwallBound δ K ε _).comp x ((hasDerivAt_id x).sub_const a) using 1 rw [id, mul_one] theorem gronwallBound_x0 (δ K ε : ℝ) : gronwallBound δ K ε 0 = δ := by by_cases hK : K = 0 · simp only [gronwallBound, if_pos hK, mul_zero, add_zero] · simp only [gronwallBound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] theorem gronwallBound_ε0 (δ K x : ℝ) : gronwallBound δ K 0 x = δ * exp (K * x) := by by_cases hK : K = 0 · simp only [gronwallBound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] · simp only [gronwallBound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] theorem gronwallBound_ε0_δ0 (K x : ℝ) : gronwallBound 0 K 0 x = 0 := by simp only [gronwallBound_ε0, zero_mul] theorem gronwallBound_continuous_ε (δ K x : ℝ) : Continuous fun ε => gronwallBound δ K ε x := by by_cases hK : K = 0 · simp only [gronwallBound_K0, hK] exact continuous_const.add (continuous_id.mul continuous_const) · simp only [gronwallBound_of_K_ne_0 hK] exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) /-! ### Inequality and corollaries -/ /-- A Grönwall-like inequality: if `f : ℝ → ℝ` is continuous on `[a, b]` and satisfies the inequalities `f a ≤ δ` and `∀ x ∈ [a, b), liminf_{z→x+0} (f z - f x)/(z - x) ≤ K * (f x) + ε`, then `f x` is bounded by `gronwallBound δ K ε (x - a)` on `[a, b]`. See also `norm_le_gronwallBound_of_norm_deriv_right_le` for a version bounding `‖f x‖`, `f : ℝ → E`. -/ theorem le_gronwallBound_of_liminf_deriv_right_le {f f' : ℝ → ℝ} {δ K ε : ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, (z - x)⁻¹ * (f z - f x) < r) (ha : f a ≤ δ) (bound : ∀ x ∈ Ico a b, f' x ≤ K * f x + ε) : ∀ x ∈ Icc a b, f x ≤ gronwallBound δ K ε (x - a) := by have H : ∀ x ∈ Icc a b, ∀ ε' ∈ Ioi ε, f x ≤ gronwallBound δ K ε' (x - a) := by intro x hx ε' hε' apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf' · rwa [sub_self, gronwallBound_x0] · exact fun x => hasDerivAt_gronwallBound_shift δ K ε' x a · intro x hx hfB rw [← hfB] apply lt_of_le_of_lt (bound x hx) exact add_lt_add_left (mem_Ioi.1 hε') _ · exact hx intro x hx change f x ≤ (fun ε' => gronwallBound δ K ε' (x - a)) ε convert continuousWithinAt_const.closure_le _ _ (H x hx) · simp only [closure_Ioi, left_mem_Ici] exact (gronwallBound_continuous_ε δ K (x - a)).continuousWithinAt /-- A Grönwall-like inequality: if `f : ℝ → E` is continuous on `[a, b]`, has right derivative `f' x` at every point `x ∈ [a, b)`, and satisfies the inequalities `‖f a‖ ≤ δ`, `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then `‖f x‖` is bounded by `gronwallBound δ K ε (x - a)` on `[a, b]`. -/ theorem norm_le_gronwallBound_of_norm_deriv_right_le {f f' : ℝ → E} {δ K ε : ℝ} {a b : ℝ} (hf : ContinuousOn f (Icc a b)) (hf' : ∀ x ∈ Ico a b, HasDerivWithinAt f (f' x) (Ici x) x) (ha : ‖f a‖ ≤ δ) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ K * ‖f x‖ + ε) : ∀ x ∈ Icc a b, ‖f x‖ ≤ gronwallBound δ K ε (x - a) := le_gronwallBound_of_liminf_deriv_right_le (continuous_norm.comp_continuousOn hf) (fun x hx _r hr => (hf' x hx).liminf_right_slope_norm_le hr) ha bound variable {v : ℝ → E → E} {s : ℝ → Set E} {K : ℝ≥0} {f g f' g' : ℝ → E} {a b t₀ : ℝ} {εf εg δ : ℝ} /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_approx_trajectories_ODE_of_mem (hv : ∀ t ∈ Ico a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (f' t) (Ici t) t) (f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (g' t) (Ici t) t) (g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwallBound δ K (εf + εg) (t - a) := by simp only [dist_eq_norm] at ha ⊢ have h_deriv : ∀ t ∈ Ico a b, HasDerivWithinAt (fun t => f t - g t) (f' t - g' t) (Ici t) t := fun t ht => (hf' t ht).sub (hg' t ht) apply norm_le_gronwallBound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha intro t ht have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)) have hv := (hv t ht).dist_le_mul _ (hfs t ht) _ (hgs t ht) rw [← dist_eq_norm, ← dist_eq_norm] refine this.trans ((add_le_add (add_le_add (f_bound t ht) (g_bound t ht)) hv).trans ?_) rw [add_comm] /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_approx_trajectories_ODE (hv : ∀ t, LipschitzWith K (v t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (f' t) (Ici t) t) (f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (g' t) (Ici t) t) (g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwallBound δ K (εf + εg) (t - a) := have hfs : ∀ t ∈ Ico a b, f t ∈ @univ E := fun _ _ => trivial dist_le_of_approx_trajectories_ODE_of_mem (fun t _ => (hv t).lipschitzOnWith) hf hf' f_bound hfs hg hg' g_bound (fun _ _ => trivial) ha /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_trajectories_ODE_of_mem (hv : ∀ t ∈ Ico a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) := by have f_bound : ∀ t ∈ Ico a b, dist (v t (f t)) (v t (f t)) ≤ 0 := by intros; rw [dist_self] have g_bound : ∀ t ∈ Ico a b, dist (v t (g t)) (v t (g t)) ≤ 0 := by intros; rw [dist_self] intro t ht have := dist_le_of_approx_trajectories_ODE_of_mem hv hf hf' f_bound hfs hg hg' g_bound hgs ha t ht rwa [zero_add, gronwallBound_ε0] at this /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_trajectories_ODE (hv : ∀ t, LipschitzWith K (v t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) := have hfs : ∀ t ∈ Ico a b, f t ∈ @univ E := fun _ _ => trivial dist_le_of_trajectories_ODE_of_mem (fun t _ => (hv t).lipschitzOnWith) hf hf' hfs hg hg' (fun _ _ => trivial) ha /-- There exists only one solution of an ODE \(\dot x=v(t, x)\) in a set `s ⊆ ℝ × E` with a given initial value provided that the RHS is Lipschitz continuous in `x` within `s`, and we consider only solutions included in `s`. This version shows uniqueness in a closed interval `Icc a b`, where `a` is the initial time. -/ theorem ODE_solution_unique_of_mem_Icc_right (hv : ∀ t ∈ Ico a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : f a = g a) : EqOn f g (Icc a b) := fun t ht ↦ by have := dist_le_of_trajectories_ODE_of_mem hv hf hf' hfs hg hg' hgs (dist_le_zero.2 ha) t ht rwa [zero_mul, dist_le_zero] at this /-- A time-reversed version of `ODE_solution_unique_of_mem_Icc_right`. Uniqueness is shown in a closed interval `Icc a b`, where `b` is the "initial" time. -/ theorem ODE_solution_unique_of_mem_Icc_left (hv : ∀ t ∈ Ioc a b, LipschitzOnWith K (v t) (s t)) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ioc a b, HasDerivWithinAt f (v t (f t)) (Iic t) t) (hfs : ∀ t ∈ Ioc a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ioc a b, HasDerivWithinAt g (v t (g t)) (Iic t) t) (hgs : ∀ t ∈ Ioc a b, g t ∈ s t) (hb : f b = g b) : EqOn f g (Icc a b) := by have hv' : ∀ t ∈ Ico (-b) (-a), LipschitzOnWith K (Neg.neg ∘ (v (-t))) (s (-t)) := by intro t ht replace ht : -t ∈ Ioc a b := by simp at ht ⊢ constructor <;> linarith rw [← one_mul K] exact LipschitzWith.id.neg.comp_lipschitzOnWith (hv _ ht) have hmt1 : MapsTo Neg.neg (Icc (-b) (-a)) (Icc a b) := fun _ ht ↦ ⟨le_neg.mp ht.2, neg_le.mp ht.1⟩ have hmt2 : MapsTo Neg.neg (Ico (-b) (-a)) (Ioc a b) := fun _ ht ↦ ⟨lt_neg.mp ht.2, neg_le.mp ht.1⟩ have hmt3 (t : ℝ) : MapsTo Neg.neg (Ici t) (Iic (-t)) := fun _ ht' ↦ mem_Iic.mpr <| neg_le_neg ht' suffices EqOn (f ∘ Neg.neg) (g ∘ Neg.neg) (Icc (-b) (-a)) by rw [eqOn_comp_right_iff] at this convert this simp apply ODE_solution_unique_of_mem_Icc_right hv' (hf.comp continuousOn_neg hmt1) _ (fun _ ht ↦ hfs _ (hmt2 ht)) (hg.comp continuousOn_neg hmt1) _ (fun _ ht ↦ hgs _ (hmt2 ht)) (by simp [hb]) · intros t ht convert HasFDerivWithinAt.comp_hasDerivWithinAt t (hf' (-t) (hmt2 ht)) (hasDerivAt_neg t).hasDerivWithinAt (hmt3 t) simp · intros t ht convert HasFDerivWithinAt.comp_hasDerivWithinAt t (hg' (-t) (hmt2 ht)) (hasDerivAt_neg t).hasDerivWithinAt (hmt3 t) simp /-- A version of `ODE_solution_unique_of_mem_Icc_right` for uniqueness in a closed interval whose interior contains the initial time. -/ theorem ODE_solution_unique_of_mem_Icc (hv : ∀ t ∈ Ioo a b, LipschitzOnWith K (v t) (s t)) (ht : t₀ ∈ Ioo a b) (hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ioo a b, HasDerivAt f (v t (f t)) t) (hfs : ∀ t ∈ Ioo a b, f t ∈ s t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ioo a b, HasDerivAt g (v t (g t)) t) (hgs : ∀ t ∈ Ioo a b, g t ∈ s t) (heq : f t₀ = g t₀) : EqOn f g (Icc a b) := by rw [← Icc_union_Icc_eq_Icc (le_of_lt ht.1) (le_of_lt ht.2)] apply EqOn.union · have hss : Ioc a t₀ ⊆ Ioo a b := Ioc_subset_Ioo_right ht.2 exact ODE_solution_unique_of_mem_Icc_left (fun t ht ↦ hv t (hss ht)) (hf.mono <| Icc_subset_Icc_right <| le_of_lt ht.2) (fun _ ht' ↦ (hf' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hfs _ (hss ht'))) (hg.mono <| Icc_subset_Icc_right <| le_of_lt ht.2) (fun _ ht' ↦ (hg' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hgs _ (hss ht'))) heq · have hss : Ico t₀ b ⊆ Ioo a b := Ico_subset_Ioo_left ht.1 exact ODE_solution_unique_of_mem_Icc_right (fun t ht ↦ hv t (hss ht)) (hf.mono <| Icc_subset_Icc_left <| le_of_lt ht.1) (fun _ ht' ↦ (hf' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hfs _ (hss ht'))) (hg.mono <| Icc_subset_Icc_left <| le_of_lt ht.1) (fun _ ht' ↦ (hg' _ (hss ht')).hasDerivWithinAt) (fun _ ht' ↦ (hgs _ (hss ht'))) heq /-- A version of `ODE_solution_unique_of_mem_Icc` for uniqueness in an open interval. -/ theorem ODE_solution_unique_of_mem_Ioo (hv : ∀ t ∈ Ioo a b, LipschitzOnWith K (v t) (s t)) (ht : t₀ ∈ Ioo a b) (hf : ∀ t ∈ Ioo a b, HasDerivAt f (v t (f t)) t ∧ f t ∈ s t) (hg : ∀ t ∈ Ioo a b, HasDerivAt g (v t (g t)) t ∧ g t ∈ s t) (heq : f t₀ = g t₀) : EqOn f g (Ioo a b) := by intros t' ht' rcases lt_or_le t' t₀ with (h | h) · have hss : Icc t' t₀ ⊆ Ioo a b := fun _ ht'' ↦ ⟨lt_of_lt_of_le ht'.1 ht''.1, lt_of_le_of_lt ht''.2 ht.2⟩ exact ODE_solution_unique_of_mem_Icc_left (fun t'' ht'' ↦ hv t'' ((Ioc_subset_Icc_self.trans hss) ht'')) (HasDerivAt.continuousOn fun _ ht'' ↦ (hf _ <| hss ht'').1) (fun _ ht'' ↦ (hf _ <| hss <| Ioc_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hf _ <| hss <| Ioc_subset_Icc_self ht'').2) (HasDerivAt.continuousOn fun _ ht'' ↦ (hg _ <| hss ht'').1) (fun _ ht'' ↦ (hg _ <| hss <| Ioc_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hg _ <| hss <| Ioc_subset_Icc_self ht'').2) heq ⟨le_rfl, le_of_lt h⟩ · have hss : Icc t₀ t' ⊆ Ioo a b := fun _ ht'' ↦ ⟨lt_of_lt_of_le ht.1 ht''.1, lt_of_le_of_lt ht''.2 ht'.2⟩ exact ODE_solution_unique_of_mem_Icc_right (fun t'' ht'' ↦ hv t'' ((Ico_subset_Icc_self.trans hss) ht'')) (HasDerivAt.continuousOn fun _ ht'' ↦ (hf _ <| hss ht'').1) (fun _ ht'' ↦ (hf _ <| hss <| Ico_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hf _ <| hss <| Ico_subset_Icc_self ht'').2) (HasDerivAt.continuousOn fun _ ht'' ↦ (hg _ <| hss ht'').1) (fun _ ht'' ↦ (hg _ <| hss <| Ico_subset_Icc_self ht'').1.hasDerivWithinAt) (fun _ ht'' ↦ (hg _ <| hss <| Ico_subset_Icc_self ht'').2) heq ⟨h, le_rfl⟩ /-- Local unqueness of ODE solutions. -/ theorem ODE_solution_unique_of_eventually (hv : ∀ᶠ t in 𝓝 t₀, LipschitzOnWith K (v t) (s t)) (hf : ∀ᶠ t in 𝓝 t₀, HasDerivAt f (v t (f t)) t ∧ f t ∈ s t) (hg : ∀ᶠ t in 𝓝 t₀, HasDerivAt g (v t (g t)) t ∧ g t ∈ s t) (heq : f t₀ = g t₀) : f =ᶠ[𝓝 t₀] g := by obtain ⟨ε, hε, h⟩ := eventually_nhds_iff_ball.mp (hv.and (hf.and hg)) rw [Filter.eventuallyEq_iff_exists_mem] refine ⟨ball t₀ ε, ball_mem_nhds _ hε, ?_⟩ simp_rw [Real.ball_eq_Ioo] at * apply ODE_solution_unique_of_mem_Ioo (fun _ ht ↦ (h _ ht).1) (Real.ball_eq_Ioo t₀ ε ▸ mem_ball_self hε) (fun _ ht ↦ (h _ ht).2.1) (fun _ ht ↦ (h _ ht).2.2) heq /-- There exists only one solution of an ODE \(\dot x=v(t, x)\) with a given initial value provided that the RHS is Lipschitz continuous in `x`. -/ theorem ODE_solution_unique (hv : ∀ t, LipschitzWith K (v t))
(hf : ContinuousOn f (Icc a b)) (hf' : ∀ t ∈ Ico a b, HasDerivWithinAt f (v t (f t)) (Ici t) t) (hg : ContinuousOn g (Icc a b)) (hg' : ∀ t ∈ Ico a b, HasDerivWithinAt g (v t (g t)) (Ici t) t) (ha : f a = g a) : EqOn f g (Icc a b) := have hfs : ∀ t ∈ Ico a b, f t ∈ univ := fun _ _ => trivial ODE_solution_unique_of_mem_Icc_right (fun t _ => (hv t).lipschitzOnWith) hf hf' hfs hg hg' (fun _ _ => trivial) ha
Mathlib/Analysis/ODE/Gronwall.lean
355
364
/- Copyright (c) 2022 David Loeffler. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: David Loeffler, Yaël Dillies, Bhavik Mehta -/ import Mathlib.Analysis.Convex.SpecificFunctions.Deriv import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv /-! # Polynomial bounds for trigonometric functions ## Main statements This file contains upper and lower bounds for real trigonometric functions in terms of polynomials. See `Trigonometric.Basic` for more elementary inequalities, establishing the ranges of these functions, and their monotonicity in suitable intervals. Here we prove the following: * `sin_lt`: for `x > 0` we have `sin x < x`. * `sin_gt_sub_cube`: For `0 < x ≤ 1` we have `x - x ^ 3 / 4 < sin x`. * `lt_tan`: for `0 < x < π/2` we have `x < tan x`. * `cos_le_one_div_sqrt_sq_add_one` and `cos_lt_one_div_sqrt_sq_add_one`: for `-3 * π / 2 ≤ x ≤ 3 * π / 2`, we have `cos x ≤ 1 / sqrt (x ^ 2 + 1)`, with strict inequality if `x ≠ 0`. (This bound is not quite optimal, but not far off) ## Tags sin, cos, tan, angle -/ open Set namespace Real variable {x : ℝ} /-- For 0 < x, we have sin x < x. -/ theorem sin_lt (h : 0 < x) : sin x < x := by rcases lt_or_le 1 x with h' | h' · exact (sin_le_one x).trans_lt h' have hx : |x| = x := abs_of_nonneg h.le have := le_of_abs_le (sin_bound <| show |x| ≤ 1 by rwa [hx]) rw [sub_le_iff_le_add', hx] at this apply this.trans_lt rw [sub_add, sub_lt_self_iff, sub_pos, div_eq_mul_inv (x ^ 3)] refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3) apply pow_le_pow_of_le_one h.le h' norm_num lemma sin_le (hx : 0 ≤ x) : sin x ≤ x := by obtain rfl | hx := hx.eq_or_lt · simp · exact (sin_lt hx).le lemma lt_sin (hx : x < 0) : x < sin x := by simpa using sin_lt <| neg_pos.2 hx lemma le_sin (hx : x ≤ 0) : x ≤ sin x := by simpa using sin_le <| neg_nonneg.2 hx theorem lt_sin_mul {x : ℝ} (hx : 0 < x) (hx' : x < 1) : x < sin (π / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ pi_div_two_pos.ne (sub_pos.2 hx') hx theorem le_sin_mul {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ 1) : x ≤ sin (π / 2 * x) := by simpa [mul_comm x] using strictConcaveOn_sin_Icc.concaveOn.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ (sub_nonneg.2 hx') hx theorem mul_lt_sin {x : ℝ} (hx : 0 < x) (hx' : x < π / 2) : 2 / π * x < sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @lt_sin_mul ((π / 2)⁻¹ * x) (mul_pos (inv_pos.2 pi_div_two_pos) hx) (by rwa [← div_eq_inv_mul, div_lt_one pi_div_two_pos]) /-- One half of **Jordan's inequality**. In the range `[0, π / 2]`, we have a linear lower bound on `sin`. The other half is given by `Real.sin_le`. -/ theorem mul_le_sin {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ π / 2) : 2 / π * x ≤ sin x := by rw [← inv_div] simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @le_sin_mul ((π / 2)⁻¹ * x) (mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx) (by rwa [← div_eq_inv_mul, div_le_one pi_div_two_pos])
/-- Half of **Jordan's inequality** for negative values. -/ lemma sin_le_mul (hx : -(π / 2) ≤ x) (hx₀ : x ≤ 0) : sin x ≤ 2 / π * x := by
Mathlib/Analysis/SpecialFunctions/Trigonometric/Bounds.lean
83
85
/- 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, Simon Hudon, Mario Carneiro -/ import Aesop import Mathlib.Algebra.Group.Defs import Mathlib.Data.Nat.Init import Mathlib.Data.Int.Init import Mathlib.Logic.Function.Iterate import Mathlib.Tactic.SimpRw import Mathlib.Tactic.SplitIfs /-! # Basic lemmas about semigroups, monoids, and groups This file lists various basic lemmas about semigroups, monoids, and groups. Most proofs are one-liners from the corresponding axioms. For the definitions of semigroups, monoids and groups, see `Algebra/Group/Defs.lean`. -/ assert_not_exists MonoidWithZero DenselyOrdered open Function variable {α β G M : Type*} section ite variable [Pow α β] @[to_additive (attr := simp) dite_smul] lemma pow_dite (p : Prop) [Decidable p] (a : α) (b : p → β) (c : ¬ p → β) : a ^ (if h : p then b h else c h) = if h : p then a ^ b h else a ^ c h := by split_ifs <;> rfl @[to_additive (attr := simp) smul_dite] lemma dite_pow (p : Prop) [Decidable p] (a : p → α) (b : ¬ p → α) (c : β) : (if h : p then a h else b h) ^ c = if h : p then a h ^ c else b h ^ c := by split_ifs <;> rfl @[to_additive (attr := simp) ite_smul] lemma pow_ite (p : Prop) [Decidable p] (a : α) (b c : β) : a ^ (if p then b else c) = if p then a ^ b else a ^ c := pow_dite _ _ _ _ @[to_additive (attr := simp) smul_ite] lemma ite_pow (p : Prop) [Decidable p] (a b : α) (c : β) : (if p then a else b) ^ c = if p then a ^ c else b ^ c := dite_pow _ _ _ _ set_option linter.existingAttributeWarning false in attribute [to_additive (attr := simp)] dite_smul smul_dite ite_smul smul_ite end ite section Semigroup variable [Semigroup α] @[to_additive] instance Semigroup.to_isAssociative : Std.Associative (α := α) (· * ·) := ⟨mul_assoc⟩ /-- Composing two multiplications on the left by `y` then `x` is equal to a multiplication on the left by `x * y`. -/ @[to_additive (attr := simp) "Composing two additions on the left by `y` then `x` is equal to an addition on the left by `x + y`."] theorem comp_mul_left (x y : α) : (x * ·) ∘ (y * ·) = (x * y * ·) := by ext z simp [mul_assoc] /-- Composing two multiplications on the right by `y` and `x` is equal to a multiplication on the right by `y * x`. -/ @[to_additive (attr := simp) "Composing two additions on the right by `y` and `x` is equal to an addition on the right by `y + x`."] theorem comp_mul_right (x y : α) : (· * x) ∘ (· * y) = (· * (y * x)) := by ext z simp [mul_assoc] end Semigroup @[to_additive] instance CommMagma.to_isCommutative [CommMagma G] : Std.Commutative (α := G) (· * ·) := ⟨mul_comm⟩ section MulOneClass variable [MulOneClass M] @[to_additive] theorem ite_mul_one {P : Prop} [Decidable P] {a b : M} : ite P (a * b) 1 = ite P a 1 * ite P b 1 := by by_cases h : P <;> simp [h] @[to_additive] theorem ite_one_mul {P : Prop} [Decidable P] {a b : M} : ite P 1 (a * b) = ite P 1 a * ite P 1 b := by by_cases h : P <;> simp [h] @[to_additive] theorem eq_one_iff_eq_one_of_mul_eq_one {a b : M} (h : a * b = 1) : a = 1 ↔ b = 1 := by constructor <;> (rintro rfl; simpa using h) @[to_additive] theorem one_mul_eq_id : ((1 : M) * ·) = id := funext one_mul @[to_additive] theorem mul_one_eq_id : (· * (1 : M)) = id := funext mul_one end MulOneClass section CommSemigroup variable [CommSemigroup G] @[to_additive] theorem mul_left_comm (a b c : G) : a * (b * c) = b * (a * c) := by rw [← mul_assoc, mul_comm a, mul_assoc] @[to_additive] theorem mul_right_comm (a b c : G) : a * b * c = a * c * b := by rw [mul_assoc, mul_comm b, mul_assoc] @[to_additive] theorem mul_mul_mul_comm (a b c d : G) : a * b * (c * d) = a * c * (b * d) := by simp only [mul_left_comm, mul_assoc] @[to_additive] theorem mul_rotate (a b c : G) : a * b * c = b * c * a := by simp only [mul_left_comm, mul_comm] @[to_additive] theorem mul_rotate' (a b c : G) : a * (b * c) = b * (c * a) := by simp only [mul_left_comm, mul_comm] end CommSemigroup attribute [local simp] mul_assoc sub_eq_add_neg section Monoid variable [Monoid M] {a b : M} {m n : ℕ} @[to_additive boole_nsmul] lemma pow_boole (P : Prop) [Decidable P] (a : M) : (a ^ if P then 1 else 0) = if P then a else 1 := by simp only [pow_ite, pow_one, pow_zero] @[to_additive nsmul_add_sub_nsmul] lemma pow_mul_pow_sub (a : M) (h : m ≤ n) : a ^ m * a ^ (n - m) = a ^ n := by rw [← pow_add, Nat.add_comm, Nat.sub_add_cancel h] @[to_additive sub_nsmul_nsmul_add] lemma pow_sub_mul_pow (a : M) (h : m ≤ n) : a ^ (n - m) * a ^ m = a ^ n := by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_one_nsmul_add] lemma mul_pow_sub_one (hn : n ≠ 0) (a : M) : a * a ^ (n - 1) = a ^ n := by rw [← pow_succ', Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] @[to_additive add_sub_one_nsmul] lemma pow_sub_one_mul (hn : n ≠ 0) (a : M) : a ^ (n - 1) * a = a ^ n := by rw [← pow_succ, Nat.sub_add_cancel <| Nat.one_le_iff_ne_zero.2 hn] /-- If `x ^ n = 1`, then `x ^ m` is the same as `x ^ (m % n)` -/ @[to_additive nsmul_eq_mod_nsmul "If `n • x = 0`, then `m • x` is the same as `(m % n) • x`"] lemma pow_eq_pow_mod (m : ℕ) (ha : a ^ n = 1) : a ^ m = a ^ (m % n) := by calc a ^ m = a ^ (m % n + n * (m / n)) := by rw [Nat.mod_add_div] _ = a ^ (m % n) := by simp [pow_add, pow_mul, ha] @[to_additive] lemma pow_mul_pow_eq_one : ∀ n, a * b = 1 → a ^ n * b ^ n = 1 | 0, _ => by simp | n + 1, h => calc a ^ n.succ * b ^ n.succ = a ^ n * a * (b * b ^ n) := by rw [pow_succ, pow_succ'] _ = a ^ n * (a * b) * b ^ n := by simp only [mul_assoc] _ = 1 := by simp [h, pow_mul_pow_eq_one] @[to_additive (attr := simp)] lemma mul_left_iterate (a : M) : ∀ n : ℕ, (a * ·)^[n] = (a ^ n * ·) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ, mul_left_iterate] @[to_additive (attr := simp)] lemma mul_right_iterate (a : M) : ∀ n : ℕ, (· * a)^[n] = (· * a ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_succ', mul_right_iterate] @[to_additive] lemma mul_left_iterate_apply_one (a : M) : (a * ·)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive] lemma mul_right_iterate_apply_one (a : M) : (· * a)^[n] 1 = a ^ n := by simp [mul_right_iterate] @[to_additive (attr := simp)] lemma pow_iterate (k : ℕ) : ∀ n : ℕ, (fun x : M ↦ x ^ k)^[n] = (· ^ k ^ n) | 0 => by ext; simp | n + 1 => by ext; simp [pow_iterate, Nat.pow_succ', pow_mul] end Monoid section CommMonoid variable [CommMonoid M] {x y z : M} @[to_additive] theorem inv_unique (hy : x * y = 1) (hz : x * z = 1) : y = z := left_inv_eq_right_inv (Trans.trans (mul_comm _ _) hy) hz @[to_additive nsmul_add] lemma mul_pow (a b : M) : ∀ n, (a * b) ^ n = a ^ n * b ^ n | 0 => by rw [pow_zero, pow_zero, pow_zero, one_mul] | n + 1 => by rw [pow_succ', pow_succ', pow_succ', mul_pow, mul_mul_mul_comm] end CommMonoid section LeftCancelMonoid variable [Monoid M] [IsLeftCancelMul M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_left : a * b = a ↔ b = 1 := calc a * b = a ↔ a * b = a * 1 := by rw [mul_one] _ ↔ b = 1 := mul_left_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_right_eq_self := mul_eq_left @[deprecated (since := "2025-03-05")] alias add_right_eq_self := add_eq_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_eq_self @[to_additive (attr := simp)] theorem left_eq_mul : a = a * b ↔ b = 1 := eq_comm.trans mul_eq_left @[deprecated (since := "2025-03-05")] alias self_eq_mul_right := left_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_right := left_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_right @[to_additive] theorem mul_ne_left : a * b ≠ a ↔ b ≠ 1 := mul_eq_left.not @[deprecated (since := "2025-03-05")] alias mul_right_ne_self := mul_ne_left @[deprecated (since := "2025-03-05")] alias add_right_ne_self := add_ne_left set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_right_ne_self @[to_additive] theorem left_ne_mul : a ≠ a * b ↔ b ≠ 1 := left_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_right := left_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_right := left_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_right end LeftCancelMonoid section RightCancelMonoid variable [RightCancelMonoid M] {a b : M} @[to_additive (attr := simp)] theorem mul_eq_right : a * b = b ↔ a = 1 := calc a * b = b ↔ a * b = 1 * b := by rw [one_mul] _ ↔ a = 1 := mul_right_cancel_iff @[deprecated (since := "2025-03-05")] alias mul_left_eq_self := mul_eq_right @[deprecated (since := "2025-03-05")] alias add_left_eq_self := add_eq_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_eq_self @[to_additive (attr := simp)] theorem right_eq_mul : b = a * b ↔ a = 1 := eq_comm.trans mul_eq_right @[deprecated (since := "2025-03-05")] alias self_eq_mul_left := right_eq_mul @[deprecated (since := "2025-03-05")] alias self_eq_add_left := right_eq_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_eq_mul_left @[to_additive] theorem mul_ne_right : a * b ≠ b ↔ a ≠ 1 := mul_eq_right.not @[deprecated (since := "2025-03-05")] alias mul_left_ne_self := mul_ne_right @[deprecated (since := "2025-03-05")] alias add_left_ne_self := add_ne_right set_option linter.existingAttributeWarning false in attribute [to_additive existing] mul_left_ne_self @[to_additive] theorem right_ne_mul : b ≠ a * b ↔ a ≠ 1 := right_eq_mul.not @[deprecated (since := "2025-03-05")] alias self_ne_mul_left := right_ne_mul @[deprecated (since := "2025-03-05")] alias self_ne_add_left := right_ne_add set_option linter.existingAttributeWarning false in attribute [to_additive existing] self_ne_mul_left end RightCancelMonoid section CancelCommMonoid variable [CancelCommMonoid α] {a b c d : α} @[to_additive] lemma eq_iff_eq_of_mul_eq_mul (h : a * b = c * d) : a = c ↔ b = d := by aesop @[to_additive] lemma ne_iff_ne_of_mul_eq_mul (h : a * b = c * d) : a ≠ c ↔ b ≠ d := by aesop end CancelCommMonoid section InvolutiveInv variable [InvolutiveInv G] {a b : G} @[to_additive (attr := simp)] theorem inv_involutive : Function.Involutive (Inv.inv : G → G) := inv_inv @[to_additive (attr := simp)] theorem inv_surjective : Function.Surjective (Inv.inv : G → G) := inv_involutive.surjective @[to_additive] theorem inv_injective : Function.Injective (Inv.inv : G → G) := inv_involutive.injective @[to_additive (attr := simp)] theorem inv_inj : a⁻¹ = b⁻¹ ↔ a = b := inv_injective.eq_iff @[to_additive] theorem inv_eq_iff_eq_inv : a⁻¹ = b ↔ a = b⁻¹ := ⟨fun h => h ▸ (inv_inv a).symm, fun h => h.symm ▸ inv_inv b⟩ variable (G) @[to_additive] theorem inv_comp_inv : Inv.inv ∘ Inv.inv = @id G := inv_involutive.comp_self @[to_additive] theorem leftInverse_inv : LeftInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv @[to_additive] theorem rightInverse_inv : RightInverse (fun a : G ↦ a⁻¹) fun a ↦ a⁻¹ := inv_inv end InvolutiveInv section DivInvMonoid variable [DivInvMonoid G] @[to_additive] theorem mul_one_div (x y : G) : x * (1 / y) = x / y := by rw [div_eq_mul_inv, one_mul, div_eq_mul_inv] @[to_additive, field_simps] -- The attributes are out of order on purpose theorem mul_div_assoc' (a b c : G) : a * (b / c) = a * b / c := (mul_div_assoc _ _ _).symm @[to_additive] theorem mul_div (a b c : G) : a * (b / c) = a * b / c := by simp only [mul_assoc, div_eq_mul_inv] @[to_additive] theorem div_eq_mul_one_div (a b : G) : a / b = a * (1 / b) := by rw [div_eq_mul_inv, one_div] end DivInvMonoid section DivInvOneMonoid variable [DivInvOneMonoid G] @[to_additive (attr := simp)] theorem div_one (a : G) : a / 1 = a := by simp [div_eq_mul_inv] @[to_additive] theorem one_div_one : (1 : G) / 1 = 1 := div_one _ end DivInvOneMonoid section DivisionMonoid variable [DivisionMonoid α] {a b c d : α} attribute [local simp] mul_assoc div_eq_mul_inv @[to_additive] theorem eq_inv_of_mul_eq_one_right (h : a * b = 1) : b = a⁻¹ := (inv_eq_of_mul_eq_one_right h).symm @[to_additive] theorem eq_one_div_of_mul_eq_one_left (h : b * a = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_left h, one_div] @[to_additive] theorem eq_one_div_of_mul_eq_one_right (h : a * b = 1) : b = 1 / a := by rw [eq_inv_of_mul_eq_one_right h, one_div] @[to_additive] theorem eq_of_div_eq_one (h : a / b = 1) : a = b := inv_injective <| inv_eq_of_mul_eq_one_right <| by rwa [← div_eq_mul_inv] @[to_additive] lemma eq_of_inv_mul_eq_one (h : a⁻¹ * b = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] lemma eq_of_mul_inv_eq_one (h : a * b⁻¹ = 1) : a = b := by simpa using eq_inv_of_mul_eq_one_left h @[to_additive] theorem div_ne_one_of_ne : a ≠ b → a / b ≠ 1 := mt eq_of_div_eq_one variable (a b c) @[to_additive] theorem one_div_mul_one_div_rev : 1 / a * (1 / b) = 1 / (b * a) := by simp @[to_additive] theorem inv_div_left : a⁻¹ / b = (b * a)⁻¹ := by simp @[to_additive (attr := simp)] theorem inv_div : (a / b)⁻¹ = b / a := by simp @[to_additive] theorem one_div_div : 1 / (a / b) = b / a := by simp @[to_additive] theorem one_div_one_div : 1 / (1 / a) = a := by simp @[to_additive] theorem div_eq_div_iff_comm : a / b = c / d ↔ b / a = d / c := inv_inj.symm.trans <| by simp only [inv_div] @[to_additive] instance (priority := 100) DivisionMonoid.toDivInvOneMonoid : DivInvOneMonoid α := { DivisionMonoid.toDivInvMonoid with inv_one := by simpa only [one_div, inv_inv] using (inv_div (1 : α) 1).symm } @[to_additive (attr := simp)] lemma inv_pow (a : α) : ∀ n : ℕ, a⁻¹ ^ n = (a ^ n)⁻¹ | 0 => by rw [pow_zero, pow_zero, inv_one] | n + 1 => by rw [pow_succ', pow_succ, inv_pow _ n, mul_inv_rev] -- the attributes are intentionally out of order. `smul_zero` proves `zsmul_zero`. @[to_additive zsmul_zero, simp] lemma one_zpow : ∀ n : ℤ, (1 : α) ^ n = 1 | (n : ℕ) => by rw [zpow_natCast, one_pow] | .negSucc n => by rw [zpow_negSucc, one_pow, inv_one] @[to_additive (attr := simp) neg_zsmul] lemma zpow_neg (a : α) : ∀ n : ℤ, a ^ (-n) = (a ^ n)⁻¹ | (_ + 1 : ℕ) => DivInvMonoid.zpow_neg' _ _ | 0 => by simp | Int.negSucc n => by rw [zpow_negSucc, inv_inv, ← zpow_natCast] rfl @[to_additive neg_one_zsmul_add] lemma mul_zpow_neg_one (a b : α) : (a * b) ^ (-1 : ℤ) = b ^ (-1 : ℤ) * a ^ (-1 : ℤ) := by simp only [zpow_neg, zpow_one, mul_inv_rev] @[to_additive zsmul_neg] lemma inv_zpow (a : α) : ∀ n : ℤ, a⁻¹ ^ n = (a ^ n)⁻¹ | (n : ℕ) => by rw [zpow_natCast, zpow_natCast, inv_pow] | .negSucc n => by rw [zpow_negSucc, zpow_negSucc, inv_pow] @[to_additive (attr := simp) zsmul_neg'] lemma inv_zpow' (a : α) (n : ℤ) : a⁻¹ ^ n = a ^ (-n) := by rw [inv_zpow, zpow_neg] @[to_additive nsmul_zero_sub] lemma one_div_pow (a : α) (n : ℕ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_pow] @[to_additive zsmul_zero_sub] lemma one_div_zpow (a : α) (n : ℤ) : (1 / a) ^ n = 1 / a ^ n := by simp only [one_div, inv_zpow] variable {a b c} @[to_additive (attr := simp)] theorem inv_eq_one : a⁻¹ = 1 ↔ a = 1 := inv_injective.eq_iff' inv_one @[to_additive (attr := simp)] theorem one_eq_inv : 1 = a⁻¹ ↔ a = 1 := eq_comm.trans inv_eq_one @[to_additive] theorem inv_ne_one : a⁻¹ ≠ 1 ↔ a ≠ 1 := inv_eq_one.not @[to_additive] theorem eq_of_one_div_eq_one_div (h : 1 / a = 1 / b) : a = b := by rw [← one_div_one_div a, h, one_div_one_div] -- Note that `mul_zsmul` and `zpow_mul` have the primes swapped -- when additivised since their argument order, -- and therefore the more "natural" choice of lemma, is reversed. @[to_additive mul_zsmul'] lemma zpow_mul (a : α) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n | (m : ℕ), (n : ℕ) => by rw [zpow_natCast, zpow_natCast, ← pow_mul, ← zpow_natCast] rfl | (m : ℕ), .negSucc n => by rw [zpow_natCast, zpow_negSucc, ← pow_mul, Int.ofNat_mul_negSucc, zpow_neg, inv_inj, ← zpow_natCast] | .negSucc m, (n : ℕ) => by rw [zpow_natCast, zpow_negSucc, ← inv_pow, ← pow_mul, Int.negSucc_mul_ofNat, zpow_neg, inv_pow, inv_inj, ← zpow_natCast] | .negSucc m, .negSucc n => by rw [zpow_negSucc, zpow_negSucc, Int.negSucc_mul_negSucc, inv_pow, inv_inv, ← pow_mul, ← zpow_natCast] rfl @[to_additive mul_zsmul] lemma zpow_mul' (a : α) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m := by rw [Int.mul_comm, zpow_mul] @[to_additive] theorem zpow_comm (a : α) (m n : ℤ) : (a ^ m) ^ n = (a ^ n) ^ m := by rw [← zpow_mul, zpow_mul'] variable (a b c) @[to_additive, field_simps] -- The attributes are out of order on purpose theorem div_div_eq_mul_div : a / (b / c) = a * c / b := by simp @[to_additive (attr := simp)] theorem div_inv_eq_mul : a / b⁻¹ = a * b := by simp @[to_additive] theorem div_mul_eq_div_div_swap : a / (b * c) = a / c / b := by simp only [mul_assoc, mul_inv_rev, div_eq_mul_inv] end DivisionMonoid section DivisionCommMonoid variable [DivisionCommMonoid α] (a b c d : α) attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive neg_add] theorem mul_inv : (a * b)⁻¹ = a⁻¹ * b⁻¹ := by simp @[to_additive] theorem inv_div' : (a / b)⁻¹ = a⁻¹ / b⁻¹ := by simp @[to_additive] theorem div_eq_inv_mul : a / b = b⁻¹ * a := by simp @[to_additive] theorem inv_mul_eq_div : a⁻¹ * b = b / a := by simp @[to_additive] lemma inv_div_comm (a b : α) : a⁻¹ / b = b⁻¹ / a := by simp @[to_additive] theorem inv_mul' : (a * b)⁻¹ = a⁻¹ / b := by simp @[to_additive] theorem inv_div_inv : a⁻¹ / b⁻¹ = b / a := by simp @[to_additive] theorem inv_inv_div_inv : (a⁻¹ / b⁻¹)⁻¹ = a / b := by simp @[to_additive] theorem one_div_mul_one_div : 1 / a * (1 / b) = 1 / (a * b) := by simp @[to_additive] theorem div_right_comm : a / b / c = a / c / b := by simp @[to_additive, field_simps] theorem div_div : a / b / c = a / (b * c) := by simp @[to_additive] theorem div_mul : a / b * c = a / (b / c) := by simp @[to_additive] theorem mul_div_left_comm : a * (b / c) = b * (a / c) := by simp @[to_additive] theorem mul_div_right_comm : a * b / c = a / c * b := by simp @[to_additive] theorem div_mul_eq_div_div : a / (b * c) = a / b / c := by simp @[to_additive, field_simps] theorem div_mul_eq_mul_div : a / b * c = a * c / b := by simp @[to_additive] theorem one_div_mul_eq_div : 1 / a * b = b / a := by simp @[to_additive] theorem mul_comm_div : a / b * c = a * (c / b) := by simp @[to_additive] theorem div_mul_comm : a / b * c = c / b * a := by simp @[to_additive] theorem div_mul_eq_div_mul_one_div : a / (b * c) = a / b * (1 / c) := by simp @[to_additive] theorem div_div_div_eq : a / b / (c / d) = a * d / (b * c) := by simp @[to_additive] theorem div_div_div_comm : a / b / (c / d) = a / c / (b / d) := by simp @[to_additive] theorem div_mul_div_comm : a / b * (c / d) = a * c / (b * d) := by simp @[to_additive] theorem mul_div_mul_comm : a * b / (c * d) = a / c * (b / d) := by simp @[to_additive zsmul_add] lemma mul_zpow : ∀ n : ℤ, (a * b) ^ n = a ^ n * b ^ n | (n : ℕ) => by simp_rw [zpow_natCast, mul_pow] | .negSucc n => by simp_rw [zpow_negSucc, ← inv_pow, mul_inv, mul_pow] @[to_additive nsmul_sub] lemma div_pow (a b : α) (n : ℕ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_pow, inv_pow] @[to_additive zsmul_sub] lemma div_zpow (a b : α) (n : ℤ) : (a / b) ^ n = a ^ n / b ^ n := by simp only [div_eq_mul_inv, mul_zpow, inv_zpow] attribute [field_simps] div_pow div_zpow end DivisionCommMonoid section Group variable [Group G] {a b c d : G} {n : ℤ} @[to_additive (attr := simp)] theorem div_eq_inv_self : a / b = b⁻¹ ↔ a = 1 := by rw [div_eq_mul_inv, mul_eq_right] @[to_additive] theorem mul_left_surjective (a : G) : Surjective (a * ·) := fun x ↦ ⟨a⁻¹ * x, mul_inv_cancel_left a x⟩ @[to_additive] theorem mul_right_surjective (a : G) : Function.Surjective fun x ↦ x * a := fun x ↦ ⟨x * a⁻¹, inv_mul_cancel_right x a⟩ @[to_additive] theorem eq_mul_inv_of_mul_eq (h : a * c = b) : a = b * c⁻¹ := by simp [h.symm] @[to_additive] theorem eq_inv_mul_of_mul_eq (h : b * a = c) : a = b⁻¹ * c := by simp [h.symm] @[to_additive] theorem inv_mul_eq_of_eq_mul (h : b = a * c) : a⁻¹ * b = c := by simp [h] @[to_additive] theorem mul_inv_eq_of_eq_mul (h : a = c * b) : a * b⁻¹ = c := by simp [h] @[to_additive] theorem eq_mul_of_mul_inv_eq (h : a * c⁻¹ = b) : a = b * c := by simp [h.symm] @[to_additive] theorem eq_mul_of_inv_mul_eq (h : b⁻¹ * a = c) : a = b * c := by simp [h.symm, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_inv_mul (h : b = a⁻¹ * c) : a * b = c := by rw [h, mul_inv_cancel_left] @[to_additive] theorem mul_eq_of_eq_mul_inv (h : a = c * b⁻¹) : a * b = c := by simp [h] @[to_additive] theorem mul_eq_one_iff_eq_inv : a * b = 1 ↔ a = b⁻¹ := ⟨eq_inv_of_mul_eq_one_left, fun h ↦ by rw [h, inv_mul_cancel]⟩ @[to_additive] theorem mul_eq_one_iff_inv_eq : a * b = 1 ↔ a⁻¹ = b := by rw [mul_eq_one_iff_eq_inv, inv_eq_iff_eq_inv] /-- Variant of `mul_eq_one_iff_eq_inv` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_eq_inv' : a * b = 1 ↔ b = a⁻¹ := by rw [mul_eq_one_iff_inv_eq, eq_comm] /-- Variant of `mul_eq_one_iff_inv_eq` with swapped equality. -/ @[to_additive] theorem mul_eq_one_iff_inv_eq' : a * b = 1 ↔ b⁻¹ = a := by rw [mul_eq_one_iff_eq_inv, eq_comm] @[to_additive] theorem eq_inv_iff_mul_eq_one : a = b⁻¹ ↔ a * b = 1 := mul_eq_one_iff_eq_inv.symm @[to_additive] theorem inv_eq_iff_mul_eq_one : a⁻¹ = b ↔ a * b = 1 := mul_eq_one_iff_inv_eq.symm @[to_additive] theorem eq_mul_inv_iff_mul_eq : a = b * c⁻¹ ↔ a * c = b := ⟨fun h ↦ by rw [h, inv_mul_cancel_right], fun h ↦ by rw [← h, mul_inv_cancel_right]⟩ @[to_additive] theorem eq_inv_mul_iff_mul_eq : a = b⁻¹ * c ↔ b * a = c := ⟨fun h ↦ by rw [h, mul_inv_cancel_left], fun h ↦ by rw [← h, inv_mul_cancel_left]⟩ @[to_additive] theorem inv_mul_eq_iff_eq_mul : a⁻¹ * b = c ↔ b = a * c := ⟨fun h ↦ by rw [← h, mul_inv_cancel_left], fun h ↦ by rw [h, inv_mul_cancel_left]⟩ @[to_additive] theorem mul_inv_eq_iff_eq_mul : a * b⁻¹ = c ↔ a = c * b := ⟨fun h ↦ by rw [← h, inv_mul_cancel_right], fun h ↦ by rw [h, mul_inv_cancel_right]⟩ @[to_additive] theorem mul_inv_eq_one : a * b⁻¹ = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inv] @[to_additive] theorem inv_mul_eq_one : a⁻¹ * b = 1 ↔ a = b := by rw [mul_eq_one_iff_eq_inv, inv_inj] @[to_additive (attr := simp)] theorem conj_eq_one_iff : a * b * a⁻¹ = 1 ↔ b = 1 := by rw [mul_inv_eq_one, mul_eq_left] @[to_additive] theorem div_left_injective : Function.Injective fun a ↦ a / b := by -- FIXME this could be by `simpa`, but it fails. This is probably a bug in `simpa`. simp only [div_eq_mul_inv] exact fun a a' h ↦ mul_left_injective b⁻¹ h @[to_additive] theorem div_right_injective : Function.Injective fun a ↦ b / a := by -- FIXME see above simp only [div_eq_mul_inv] exact fun a a' h ↦ inv_injective (mul_right_injective b h) @[to_additive (attr := simp)] lemma div_mul_cancel_right (a b : G) : a / (b * a) = b⁻¹ := by rw [← inv_div, mul_div_cancel_right] @[to_additive (attr := simp)] theorem mul_div_mul_right_eq_div (a b c : G) : a * c / (b * c) = a / b := by rw [div_mul_eq_div_div_swap]; simp only [mul_left_inj, eq_self_iff_true, mul_div_cancel_right] @[to_additive eq_sub_of_add_eq] theorem eq_div_of_mul_eq' (h : a * c = b) : a = b / c := by simp [← h] @[to_additive sub_eq_of_eq_add] theorem div_eq_of_eq_mul'' (h : a = c * b) : a / b = c := by simp [h] @[to_additive] theorem eq_mul_of_div_eq (h : a / c = b) : a = b * c := by simp [← h] @[to_additive] theorem mul_eq_of_eq_div (h : a = c / b) : a * b = c := by simp [h] @[to_additive (attr := simp)] theorem div_right_inj : a / b = a / c ↔ b = c := div_right_injective.eq_iff @[to_additive (attr := simp)] theorem div_left_inj : b / a = c / a ↔ b = c := by rw [div_eq_mul_inv, div_eq_mul_inv] exact mul_left_inj _ @[to_additive (attr := simp)] theorem div_mul_div_cancel (a b c : G) : a / b * (b / c) = a / c := by rw [← mul_div_assoc, div_mul_cancel] @[to_additive (attr := simp)] theorem div_div_div_cancel_right (a b c : G) : a / c / (b / c) = a / b := by rw [← inv_div c b, div_inv_eq_mul, div_mul_div_cancel] @[to_additive] theorem div_eq_one : a / b = 1 ↔ a = b := ⟨eq_of_div_eq_one, fun h ↦ by rw [h, div_self']⟩ alias ⟨_, div_eq_one_of_eq⟩ := div_eq_one alias ⟨_, sub_eq_zero_of_eq⟩ := sub_eq_zero @[to_additive] theorem div_ne_one : a / b ≠ 1 ↔ a ≠ b := not_congr div_eq_one @[to_additive (attr := simp)] theorem div_eq_self : a / b = a ↔ b = 1 := by rw [div_eq_mul_inv, mul_eq_left, inv_eq_one] @[to_additive eq_sub_iff_add_eq] theorem eq_div_iff_mul_eq' : a = b / c ↔ a * c = b := by rw [div_eq_mul_inv, eq_mul_inv_iff_mul_eq] @[to_additive] theorem div_eq_iff_eq_mul : a / b = c ↔ a = c * b := by rw [div_eq_mul_inv, mul_inv_eq_iff_eq_mul] @[to_additive] theorem eq_iff_eq_of_div_eq_div (H : a / b = c / d) : a = b ↔ c = d := by rw [← div_eq_one, H, div_eq_one] @[to_additive] theorem leftInverse_div_mul_left (c : G) : Function.LeftInverse (fun x ↦ x / c) fun x ↦ x * c := fun x ↦ mul_div_cancel_right x c @[to_additive] theorem leftInverse_mul_left_div (c : G) : Function.LeftInverse (fun x ↦ x * c) fun x ↦ x / c := fun x ↦ div_mul_cancel x c @[to_additive] theorem leftInverse_mul_right_inv_mul (c : G) : Function.LeftInverse (fun x ↦ c * x) fun x ↦ c⁻¹ * x := fun x ↦ mul_inv_cancel_left c x @[to_additive] theorem leftInverse_inv_mul_mul_right (c : G) : Function.LeftInverse (fun x ↦ c⁻¹ * x) fun x ↦ c * x := fun x ↦ inv_mul_cancel_left c x @[to_additive (attr := simp) natAbs_nsmul_eq_zero] lemma pow_natAbs_eq_one : a ^ n.natAbs = 1 ↔ a ^ n = 1 := by cases n <;> simp @[to_additive sub_nsmul] lemma pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := eq_mul_inv_of_mul_eq <| by rw [← pow_add, Nat.sub_add_cancel h] @[to_additive sub_nsmul_neg] theorem inv_pow_sub (a : G) {m n : ℕ} (h : n ≤ m) : a⁻¹ ^ (m - n) = (a ^ m)⁻¹ * a ^ n := by rw [pow_sub a⁻¹ h, inv_pow, inv_pow, inv_inv] @[to_additive add_one_zsmul] lemma zpow_add_one (a : G) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a | (n : ℕ) => by simp only [← Int.natCast_succ, zpow_natCast, pow_succ] | -1 => by simp [Int.add_left_neg] | .negSucc (n + 1) => by rw [zpow_negSucc, pow_succ', mul_inv_rev, inv_mul_cancel_right] rw [Int.negSucc_eq, Int.neg_add, Int.neg_add_cancel_right] exact zpow_negSucc _ _ @[to_additive sub_one_zsmul] lemma zpow_sub_one (a : G) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ := calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ := (mul_inv_cancel_right _ _).symm _ = a ^ n * a⁻¹ := by rw [← zpow_add_one, Int.sub_add_cancel] @[to_additive add_zsmul] lemma zpow_add (a : G) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n := by induction n with | hz => simp | hp n ihn => simp only [← Int.add_assoc, zpow_add_one, ihn, mul_assoc] | hn n ihn => rw [zpow_sub_one, ← mul_assoc, ← ihn, ← zpow_sub_one, Int.add_sub_assoc] @[to_additive one_add_zsmul] lemma zpow_one_add (a : G) (n : ℤ) : a ^ (1 + n) = a * a ^ n := by rw [zpow_add, zpow_one] @[to_additive add_zsmul_self] lemma mul_self_zpow (a : G) (n : ℤ) : a * a ^ n = a ^ (n + 1) := by rw [Int.add_comm, zpow_add, zpow_one] @[to_additive add_self_zsmul] lemma mul_zpow_self (a : G) (n : ℤ) : a ^ n * a = a ^ (n + 1) := (zpow_add_one ..).symm @[to_additive sub_zsmul] lemma zpow_sub (a : G) (m n : ℤ) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ := by rw [Int.sub_eq_add_neg, zpow_add, zpow_neg] @[to_additive natCast_sub_natCast_zsmul] lemma zpow_natCast_sub_natCast (a : G) (m n : ℕ) : a ^ (m - n : ℤ) = a ^ m / a ^ n := by simpa [div_eq_mul_inv] using zpow_sub a m n @[to_additive natCast_sub_one_zsmul] lemma zpow_natCast_sub_one (a : G) (n : ℕ) : a ^ (n - 1 : ℤ) = a ^ n / a := by simpa [div_eq_mul_inv] using zpow_sub a n 1 @[to_additive one_sub_natCast_zsmul] lemma zpow_one_sub_natCast (a : G) (n : ℕ) : a ^ (1 - n : ℤ) = a / a ^ n := by simpa [div_eq_mul_inv] using zpow_sub a 1 n @[to_additive] lemma zpow_mul_comm (a : G) (m n : ℤ) : a ^ m * a ^ n = a ^ n * a ^ m := by rw [← zpow_add, Int.add_comm, zpow_add] theorem zpow_eq_zpow_emod {x : G} (m : ℤ) {n : ℤ} (h : x ^ n = 1) : x ^ m = x ^ (m % n) := calc x ^ m = x ^ (m % n + n * (m / n)) := by rw [Int.emod_add_ediv] _ = x ^ (m % n) := by simp [zpow_add, zpow_mul, h] theorem zpow_eq_zpow_emod' {x : G} (m : ℤ) {n : ℕ} (h : x ^ n = 1) : x ^ m = x ^ (m % (n : ℤ)) := zpow_eq_zpow_emod m (by simpa) @[to_additive (attr := simp)] lemma zpow_iterate (k : ℤ) : ∀ n : ℕ, (fun x : G ↦ x ^ k)^[n] = (· ^ k ^ n) | 0 => by ext; simp [Int.pow_zero] | n + 1 => by ext; simp [zpow_iterate, Int.pow_succ', zpow_mul] /-- To show a property of all powers of `g` it suffices to show it is closed under multiplication by `g` and `g⁻¹` on the left. For subgroups generated by more than one element, see `Subgroup.closure_induction_left`. -/ @[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under addition by `g` and `-g` on the left. For additive subgroups generated by more than one element, see `AddSubgroup.closure_induction_left`."] lemma zpow_induction_left {g : G} {P : G → Prop} (h_one : P (1 : G)) (h_mul : ∀ a, P a → P (g * a)) (h_inv : ∀ a, P a → P (g⁻¹ * a)) (n : ℤ) : P (g ^ n) := by induction n with | hz => rwa [zpow_zero] | hp n ih => rw [Int.add_comm, zpow_add, zpow_one] exact h_mul _ ih | hn n ih => rw [Int.sub_eq_add_neg, Int.add_comm, zpow_add, zpow_neg_one] exact h_inv _ ih /-- To show a property of all powers of `g` it suffices to show it is closed under multiplication by `g` and `g⁻¹` on the right. For subgroups generated by more than one element, see `Subgroup.closure_induction_right`. -/ @[to_additive "To show a property of all multiples of `g` it suffices to show it is closed under addition by `g` and `-g` on the right. For additive subgroups generated by more than one element, see `AddSubgroup.closure_induction_right`."] lemma zpow_induction_right {g : G} {P : G → Prop} (h_one : P (1 : G)) (h_mul : ∀ a, P a → P (a * g)) (h_inv : ∀ a, P a → P (a * g⁻¹)) (n : ℤ) : P (g ^ n) := by induction n with | hz => rwa [zpow_zero] | hp n ih => rw [zpow_add_one] exact h_mul _ ih | hn n ih => rw [zpow_sub_one] exact h_inv _ ih end Group section CommGroup variable [CommGroup G] {a b c d : G} attribute [local simp] mul_assoc mul_comm mul_left_comm div_eq_mul_inv @[to_additive] theorem div_eq_of_eq_mul' {a b c : G} (h : a = b * c) : a / b = c := by rw [h, div_eq_mul_inv, mul_comm, inv_mul_cancel_left] @[to_additive (attr := simp)] theorem mul_div_mul_left_eq_div (a b c : G) : c * a / (c * b) = a / b := by rw [div_eq_mul_inv, mul_inv_rev, mul_comm b⁻¹ c⁻¹, mul_comm c a, mul_assoc, ← mul_assoc c, mul_inv_cancel, one_mul, div_eq_mul_inv] @[to_additive eq_sub_of_add_eq'] theorem eq_div_of_mul_eq'' (h : c * a = b) : a = b / c := by simp [h.symm] @[to_additive] theorem eq_mul_of_div_eq' (h : a / b = c) : a = b * c := by simp [h.symm] @[to_additive] theorem mul_eq_of_eq_div' (h : b = c / a) : a * b = c := by rw [h, div_eq_mul_inv, mul_comm c, mul_inv_cancel_left] @[to_additive sub_sub_self] theorem div_div_self' (a b : G) : a / (a / b) = b := by simp @[to_additive] theorem div_eq_div_mul_div (a b c : G) : a / b = c / b * (a / c) := by simp [mul_left_comm c] @[to_additive (attr := simp)] theorem div_div_cancel (a b : G) : a / (a / b) = b := div_div_self' a b @[to_additive (attr := simp)] theorem div_div_cancel_left (a b : G) : a / b / a = b⁻¹ := by simp @[to_additive eq_sub_iff_add_eq'] theorem eq_div_iff_mul_eq'' : a = b / c ↔ c * a = b := by rw [eq_div_iff_mul_eq', mul_comm] @[to_additive] theorem div_eq_iff_eq_mul' : a / b = c ↔ a = b * c := by rw [div_eq_iff_eq_mul, mul_comm] @[to_additive (attr := simp)] theorem mul_div_cancel_left (a b : G) : a * b / a = b := by rw [div_eq_inv_mul, inv_mul_cancel_left] @[to_additive (attr := simp)] theorem mul_div_cancel (a b : G) : a * (b / a) = b := by rw [← mul_div_assoc, mul_div_cancel_left] @[to_additive (attr := simp)] theorem div_mul_cancel_left (a b : G) : a / (a * b) = b⁻¹ := by rw [← inv_div, mul_div_cancel_left] -- This lemma is in the `simp` set under the name `mul_inv_cancel_comm_assoc`, -- along with the additive version `add_neg_cancel_comm_assoc`, -- defined in `Algebra.Group.Commute` @[to_additive] theorem mul_mul_inv_cancel'_right (a b : G) : a * (b * a⁻¹) = b := by rw [← div_eq_mul_inv, mul_div_cancel a b] @[to_additive (attr := simp)] theorem mul_mul_div_cancel (a b c : G) : a * c * (b / c) = a * b := by rw [mul_assoc, mul_div_cancel] @[to_additive (attr := simp)] theorem div_mul_mul_cancel (a b c : G) : a / c * (b * c) = a * b := by rw [mul_left_comm, div_mul_cancel, mul_comm] @[to_additive (attr := simp)] theorem div_mul_div_cancel' (a b c : G) : a / b * (c / a) = c / b := by rw [mul_comm]; apply div_mul_div_cancel @[to_additive (attr := simp)] theorem mul_div_div_cancel (a b c : G) : a * b / (a / c) = b * c := by rw [← div_mul, mul_div_cancel_left] @[to_additive (attr := simp)] theorem div_div_div_cancel_left (a b c : G) : c / a / (c / b) = b / a := by rw [← inv_div b c, div_inv_eq_mul, mul_comm, div_mul_div_cancel] @[to_additive] theorem div_eq_div_iff_mul_eq_mul : a / b = c / d ↔ a * d = c * b := by rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, eq_comm, div_eq_iff_eq_mul'] simp only [mul_comm, eq_comm] @[to_additive] theorem div_eq_div_iff_div_eq_div : a / b = c / d ↔ a / c = b / d := by rw [div_eq_iff_eq_mul, div_mul_eq_mul_div, div_eq_iff_eq_mul', mul_div_assoc] end CommGroup section multiplicative variable [Monoid β] (p r : α → α → Prop) [IsTotal α r] (f : α → α → β) @[to_additive additive_of_symmetric_of_isTotal] lemma multiplicative_of_symmetric_of_isTotal (hsymm : Symmetric p) (hf_swap : ∀ {a b}, p a b → f a b * f b a = 1) (hmul : ∀ {a b c}, r a b → r b c → p a b → p b c → p a c → f a c = f a b * f b c) {a b c : α} (pab : p a b) (pbc : p b c) (pac : p a c) : f a c = f a b * f b c := by have hmul' : ∀ {b c}, r b c → p a b → p b c → p a c → f a c = f a b * f b c := by intros b c rbc pab pbc pac obtain rab | rba := total_of r a b · exact hmul rab rbc pab pbc pac rw [← one_mul (f a c), ← hf_swap pab, mul_assoc] obtain rac | rca := total_of r a c · rw [hmul rba rac (hsymm pab) pac pbc] · rw [hmul rbc rca pbc (hsymm pac) (hsymm pab), mul_assoc, hf_swap (hsymm pac), mul_one] obtain rbc | rcb := total_of r b c · exact hmul' rbc pab pbc pac · rw [hmul' rcb pac (hsymm pbc) pab, mul_assoc, hf_swap (hsymm pbc), mul_one] /-- If a binary function from a type equipped with a total relation `r` to a monoid is anti-symmetric (i.e. satisfies `f a b * f b a = 1`), in order to show it is multiplicative (i.e. satisfies `f a c = f a b * f b c`), we may assume `r a b` and `r b c` are satisfied. We allow restricting to a subset specified by a predicate `p`. -/ @[to_additive additive_of_isTotal "If a binary function from a type equipped with a total relation `r` to an additive monoid is anti-symmetric (i.e. satisfies `f a b + f b a = 0`), in order to show it is additive (i.e. satisfies `f a c = f a b + f b c`), we may assume `r a b` and `r b c` are satisfied. We allow restricting to a subset specified by a predicate `p`."] theorem multiplicative_of_isTotal (p : α → Prop) (hswap : ∀ {a b}, p a → p b → f a b * f b a = 1) (hmul : ∀ {a b c}, r a b → r b c → p a → p b → p c → f a c = f a b * f b c) {a b c : α} (pa : p a) (pb : p b) (pc : p c) : f a c = f a b * f b c := by apply multiplicative_of_symmetric_of_isTotal (fun a b => p a ∧ p b) r f fun _ _ => And.symm · simp_rw [and_imp]; exact @hswap · exact fun rab rbc pab _pbc pac => hmul rab rbc pab.1 pab.2 pac.2 exacts [⟨pa, pb⟩, ⟨pb, pc⟩, ⟨pa, pc⟩] end multiplicative /-- An auxiliary lemma that can be used to prove `⇑(f ^ n) = ⇑f^[n]`. -/ @[to_additive] lemma hom_coe_pow {F : Type*} [Monoid F] (c : F → M → M) (h1 : c 1 = id) (hmul : ∀ f g, c (f * g) = c f ∘ c g) (f : F) : ∀ n, c (f ^ n) = (c f)^[n] | 0 => by rw [pow_zero, h1] rfl | n + 1 => by rw [pow_succ, iterate_succ, hmul, hom_coe_pow c h1 hmul f n]
Mathlib/Algebra/Group/Basic.lean
1,193
1,195
/- Copyright (c) 2022 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import Mathlib.Algebra.Order.Ring.Nat import Mathlib.Order.Nat import Mathlib.Data.Nat.Prime.Basic /-! # Prime powers This file deals with prime powers: numbers which are positive integer powers of a single prime. -/ assert_not_exists Nat.divisors variable {R : Type*} [CommMonoidWithZero R] (n p : R) (k : ℕ) /-- `n` is a prime power if there is a prime `p` and a positive natural `k` such that `n` can be written as `p^k`. -/ def IsPrimePow : Prop := ∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n theorem isPrimePow_def : IsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ 0 < k ∧ p ^ k = n := Iff.rfl /-- An equivalent definition for prime powers: `n` is a prime power iff there is a prime `p` and a natural `k` such that `n` can be written as `p^(k+1)`. -/ theorem isPrimePow_iff_pow_succ : IsPrimePow n ↔ ∃ (p : R) (k : ℕ), Prime p ∧ p ^ (k + 1) = n := (isPrimePow_def _).trans ⟨fun ⟨p, k, hp, hk, hn⟩ => ⟨p, k - 1, hp, by rwa [Nat.sub_add_cancel hk]⟩, fun ⟨_, _, hp, hn⟩ => ⟨_, _, hp, Nat.succ_pos', hn⟩⟩ theorem not_isPrimePow_zero [NoZeroDivisors R] : ¬IsPrimePow (0 : R) := by simp only [isPrimePow_def, not_exists, not_and', and_imp] intro x n _hn hx rw [pow_eq_zero hx] simp theorem IsPrimePow.not_unit {n : R} (h : IsPrimePow n) : ¬IsUnit n := let ⟨_p, _k, hp, hk, hn⟩ := h hn ▸ (isUnit_pow_iff hk.ne').not.mpr hp.not_unit theorem IsUnit.not_isPrimePow {n : R} (h : IsUnit n) : ¬IsPrimePow n := fun h' => h'.not_unit h theorem not_isPrimePow_one : ¬IsPrimePow (1 : R) := isUnit_one.not_isPrimePow theorem Prime.isPrimePow {p : R} (hp : Prime p) : IsPrimePow p := ⟨p, 1, hp, zero_lt_one, by simp⟩ theorem IsPrimePow.pow {n : R} (hn : IsPrimePow n) {k : ℕ} (hk : k ≠ 0) : IsPrimePow (n ^ k) := let ⟨p, k', hp, hk', hn⟩ := hn ⟨p, k * k', hp, mul_pos hk.bot_lt hk', by rw [pow_mul', hn]⟩ theorem IsPrimePow.ne_zero [NoZeroDivisors R] {n : R} (h : IsPrimePow n) : n ≠ 0 := fun t => not_isPrimePow_zero (t ▸ h) theorem IsPrimePow.ne_one {n : R} (h : IsPrimePow n) : n ≠ 1 := fun t => not_isPrimePow_one (t ▸ h) section Nat theorem isPrimePow_nat_iff (n : ℕ) : IsPrimePow n ↔ ∃ p k : ℕ, Nat.Prime p ∧ 0 < k ∧ p ^ k = n := by simp only [isPrimePow_def, Nat.prime_iff] theorem Nat.Prime.isPrimePow {p : ℕ} (hp : p.Prime) : IsPrimePow p := _root_.Prime.isPrimePow (prime_iff.mp hp) theorem isPrimePow_nat_iff_bounded (n : ℕ) : IsPrimePow n ↔ ∃ p : ℕ, p ≤ n ∧ ∃ k : ℕ, k ≤ n ∧ p.Prime ∧ 0 < k ∧ p ^ k = n := by rw [isPrimePow_nat_iff] refine Iff.symm ⟨fun ⟨p, _, k, _, hp, hk, hn⟩ => ⟨p, k, hp, hk, hn⟩, ?_⟩ rintro ⟨p, k, hp, hk, rfl⟩ refine ⟨p, ?_, k, (Nat.lt_pow_self hp.one_lt).le, hp, hk, rfl⟩
conv => { lhs; rw [← (pow_one p)] } exact Nat.pow_le_pow_right hp.one_lt.le hk
Mathlib/Algebra/IsPrimePow.lean
76
77
/- 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 /-! ### Relation “eventually equal” -/ section EventuallyEq variable {l : Filter α} {f g : α → β} theorem EventuallyEq.eventually (h : f =ᶠ[l] g) : ∀ᶠ x in l, f x = g x := h @[simp] lemma eventuallyEq_top : f =ᶠ[⊤] g ↔ f = g := by simp [EventuallyEq, funext_iff] theorem EventuallyEq.rw {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (p : α → β → Prop) (hf : ∀ᶠ x in l, p x (f x)) : ∀ᶠ x in l, p x (g x) := hf.congr <| h.mono fun _ hx => hx ▸ Iff.rfl theorem eventuallyEq_set {s t : Set α} {l : Filter α} : s =ᶠ[l] t ↔ ∀ᶠ x in l, x ∈ s ↔ x ∈ t := eventually_congr <| Eventually.of_forall fun _ ↦ eq_iff_iff alias ⟨EventuallyEq.mem_iff, Eventually.set_eq⟩ := eventuallyEq_set @[simp] theorem eventuallyEq_univ {s : Set α} {l : Filter α} : s =ᶠ[l] univ ↔ s ∈ l := by simp [eventuallyEq_set] theorem EventuallyEq.exists_mem {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) : ∃ s ∈ l, EqOn f g s := Eventually.exists_mem h theorem eventuallyEq_of_mem {l : Filter α} {f g : α → β} {s : Set α} (hs : s ∈ l) (h : EqOn f g s) : f =ᶠ[l] g := eventually_of_mem hs h theorem eventuallyEq_iff_exists_mem {l : Filter α} {f g : α → β} : f =ᶠ[l] g ↔ ∃ s ∈ l, EqOn f g s := eventually_iff_exists_mem theorem EventuallyEq.filter_mono {l l' : Filter α} {f g : α → β} (h₁ : f =ᶠ[l] g) (h₂ : l' ≤ l) : f =ᶠ[l'] g := h₂ h₁ @[refl, simp] theorem EventuallyEq.refl (l : Filter α) (f : α → β) : f =ᶠ[l] f := Eventually.of_forall fun _ => rfl protected theorem EventuallyEq.rfl {l : Filter α} {f : α → β} : f =ᶠ[l] f := EventuallyEq.refl l f theorem EventuallyEq.of_eq {l : Filter α} {f g : α → β} (h : f = g) : f =ᶠ[l] g := h ▸ .rfl alias _root_.Eq.eventuallyEq := EventuallyEq.of_eq @[symm] theorem EventuallyEq.symm {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) : g =ᶠ[l] f := H.mono fun _ => Eq.symm lemma eventuallyEq_comm {f g : α → β} {l : Filter α} : f =ᶠ[l] g ↔ g =ᶠ[l] f := ⟨.symm, .symm⟩ @[trans] theorem EventuallyEq.trans {l : Filter α} {f g h : α → β} (H₁ : f =ᶠ[l] g) (H₂ : g =ᶠ[l] h) : f =ᶠ[l] h := H₂.rw (fun x y => f x = y) H₁ theorem EventuallyEq.congr_left {l : Filter α} {f g h : α → β} (H : f =ᶠ[l] g) : f =ᶠ[l] h ↔ g =ᶠ[l] h := ⟨H.symm.trans, H.trans⟩ theorem EventuallyEq.congr_right {l : Filter α} {f g h : α → β} (H : g =ᶠ[l] h) : f =ᶠ[l] g ↔ f =ᶠ[l] h := ⟨(·.trans H), (·.trans H.symm)⟩ instance {l : Filter α} : Trans ((· =ᶠ[l] ·) : (α → β) → (α → β) → Prop) (· =ᶠ[l] ·) (· =ᶠ[l] ·) where trans := EventuallyEq.trans theorem EventuallyEq.prodMk {l} {f f' : α → β} (hf : f =ᶠ[l] f') {g g' : α → γ} (hg : g =ᶠ[l] g') : (fun x => (f x, g x)) =ᶠ[l] fun x => (f' x, g' x) := hf.mp <| hg.mono <| by intros simp only [*] @[deprecated (since := "2025-03-10")] alias EventuallyEq.prod_mk := EventuallyEq.prodMk -- See `EventuallyEq.comp_tendsto` further below for a similar statement w.r.t. -- composition on the right. theorem EventuallyEq.fun_comp {f g : α → β} {l : Filter α} (H : f =ᶠ[l] g) (h : β → γ) : h ∘ f =ᶠ[l] h ∘ g := H.mono fun _ hx => congr_arg h hx theorem EventuallyEq.comp₂ {δ} {f f' : α → β} {g g' : α → γ} {l} (Hf : f =ᶠ[l] f') (h : β → γ → δ) (Hg : g =ᶠ[l] g') : (fun x => h (f x) (g x)) =ᶠ[l] fun x => h (f' x) (g' x) := (Hf.prodMk Hg).fun_comp (uncurry h) @[to_additive] theorem EventuallyEq.mul [Mul β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x * f' x) =ᶠ[l] fun x => g x * g' x := h.comp₂ (· * ·) h' @[to_additive const_smul] theorem EventuallyEq.pow_const {γ} [Pow β γ] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) (c : γ) : (fun x => f x ^ c) =ᶠ[l] fun x => g x ^ c := h.fun_comp (· ^ c) @[to_additive] theorem EventuallyEq.inv [Inv β] {f g : α → β} {l : Filter α} (h : f =ᶠ[l] g) : (fun x => (f x)⁻¹) =ᶠ[l] fun x => (g x)⁻¹ := h.fun_comp Inv.inv @[to_additive] theorem EventuallyEq.div [Div β] {f f' g g' : α → β} {l : Filter α} (h : f =ᶠ[l] g) (h' : f' =ᶠ[l] g') : (fun x => f x / f' x) =ᶠ[l] fun x => g x / g' x := h.comp₂ (· / ·) h' attribute [to_additive] EventuallyEq.const_smul @[to_additive] theorem EventuallyEq.smul {𝕜} [SMul 𝕜 β] {l : Filter α} {f f' : α → 𝕜} {g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x • g x) =ᶠ[l] fun x => f' x • g' x := hf.comp₂ (· • ·) hg theorem EventuallyEq.sup [Max β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊔ g x) =ᶠ[l] fun x => f' x ⊔ g' x := hf.comp₂ (· ⊔ ·) hg theorem EventuallyEq.inf [Min β] {l : Filter α} {f f' g g' : α → β} (hf : f =ᶠ[l] f') (hg : g =ᶠ[l] g') : (fun x => f x ⊓ g x) =ᶠ[l] fun x => f' x ⊓ g' x := hf.comp₂ (· ⊓ ·) hg theorem EventuallyEq.preimage {l : Filter α} {f g : α → β} (h : f =ᶠ[l] g) (s : Set β) : f ⁻¹' s =ᶠ[l] g ⁻¹' s := h.fun_comp s theorem EventuallyEq.inter {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∩ s' : Set α) =ᶠ[l] (t ∩ t' : Set α) := h.comp₂ (· ∧ ·) h' theorem EventuallyEq.union {s t s' t' : Set α} {l : Filter α} (h : s =ᶠ[l] t) (h' : s' =ᶠ[l] t') : (s ∪ s' : Set α) =ᶠ[l] (t ∪ t' : Set α) := h.comp₂ (· ∨ ·) h' theorem EventuallyEq.compl {s t : Set α} {l : Filter α} (h : s =ᶠ[l] t) :
(sᶜ : Set α) =ᶠ[l] (tᶜ : Set α) := h.fun_comp Not
Mathlib/Order/Filter/Basic.lean
996
997
/- 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, Johannes Hölzl, Mario Carneiro -/ import Mathlib.Logic.Pairwise import Mathlib.Data.Set.BooleanAlgebra /-! # The set lattice This file is a collection of results on the complete atomic boolean algebra structure of `Set α`. Notation for the complete lattice operations can be found in `Mathlib.Order.SetNotation`. ## Main declarations * `Set.sInter_eq_biInter`, `Set.sUnion_eq_biInter`: Shows that `⋂₀ s = ⋂ x ∈ s, x` and `⋃₀ s = ⋃ x ∈ s, x`. * `Set.completeAtomicBooleanAlgebra`: `Set α` is a `CompleteAtomicBooleanAlgebra` with `≤ = ⊆`, `< = ⊂`, `⊓ = ∩`, `⊔ = ∪`, `⨅ = ⋂`, `⨆ = ⋃` and `\` as the set difference. See `Set.instBooleanAlgebra`. * `Set.unionEqSigmaOfDisjoint`: Equivalence between `⋃ i, t i` and `Σ i, t i`, where `t` is an indexed family of disjoint sets. ## Naming convention In lemma names, * `⋃ i, s i` is called `iUnion` * `⋂ i, s i` is called `iInter` * `⋃ i j, s i j` is called `iUnion₂`. This is an `iUnion` inside an `iUnion`. * `⋂ i j, s i j` is called `iInter₂`. This is an `iInter` inside an `iInter`. * `⋃ i ∈ s, t i` is called `biUnion` for "bounded `iUnion`". This is the special case of `iUnion₂` where `j : i ∈ s`. * `⋂ i ∈ s, t i` is called `biInter` for "bounded `iInter`". This is the special case of `iInter₂` where `j : i ∈ s`. ## Notation * `⋃`: `Set.iUnion` * `⋂`: `Set.iInter` * `⋃₀`: `Set.sUnion` * `⋂₀`: `Set.sInter` -/ open Function Set universe u variable {α β γ δ : Type*} {ι ι' ι₂ : Sort*} {κ κ₁ κ₂ : ι → Sort*} {κ' : ι' → Sort*} namespace Set /-! ### Complete lattice and complete Boolean algebra instances -/ theorem mem_iUnion₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋃ (i) (j), s i j) ↔ ∃ i j, x ∈ s i j := by simp_rw [mem_iUnion] theorem mem_iInter₂ {x : γ} {s : ∀ i, κ i → Set γ} : (x ∈ ⋂ (i) (j), s i j) ↔ ∀ i j, x ∈ s i j := by simp_rw [mem_iInter] theorem mem_iUnion_of_mem {s : ι → Set α} {a : α} (i : ι) (ha : a ∈ s i) : a ∈ ⋃ i, s i := mem_iUnion.2 ⟨i, ha⟩ theorem mem_iUnion₂_of_mem {s : ∀ i, κ i → Set α} {a : α} {i : ι} (j : κ i) (ha : a ∈ s i j) : a ∈ ⋃ (i) (j), s i j := mem_iUnion₂.2 ⟨i, j, ha⟩ theorem mem_iInter_of_mem {s : ι → Set α} {a : α} (h : ∀ i, a ∈ s i) : a ∈ ⋂ i, s i := mem_iInter.2 h theorem mem_iInter₂_of_mem {s : ∀ i, κ i → Set α} {a : α} (h : ∀ i j, a ∈ s i j) : a ∈ ⋂ (i) (j), s i j := mem_iInter₂.2 h /-! ### Union and intersection over an indexed family of sets -/ @[congr] theorem iUnion_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iUnion f₁ = iUnion f₂ := iSup_congr_Prop pq f @[congr] theorem iInter_congr_Prop {p q : Prop} {f₁ : p → Set α} {f₂ : q → Set α} (pq : p ↔ q) (f : ∀ x, f₁ (pq.mpr x) = f₂ x) : iInter f₁ = iInter f₂ := iInf_congr_Prop pq f theorem iUnion_plift_up (f : PLift ι → Set α) : ⋃ i, f (PLift.up i) = ⋃ i, f i := iSup_plift_up _ theorem iUnion_plift_down (f : ι → Set α) : ⋃ i, f (PLift.down i) = ⋃ i, f i := iSup_plift_down _ theorem iInter_plift_up (f : PLift ι → Set α) : ⋂ i, f (PLift.up i) = ⋂ i, f i := iInf_plift_up _ theorem iInter_plift_down (f : ι → Set α) : ⋂ i, f (PLift.down i) = ⋂ i, f i := iInf_plift_down _ theorem iUnion_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋃ _ : p, s = if p then s else ∅ := iSup_eq_if _ theorem iUnion_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋃ h : p, s h = if h : p then s h else ∅ := iSup_eq_dif _ theorem iInter_eq_if {p : Prop} [Decidable p] (s : Set α) : ⋂ _ : p, s = if p then s else univ := iInf_eq_if _ theorem iInf_eq_dif {p : Prop} [Decidable p] (s : p → Set α) : ⋂ h : p, s h = if h : p then s h else univ := _root_.iInf_eq_dif _ theorem exists_set_mem_of_union_eq_top {ι : Type*} (t : Set ι) (s : ι → Set β) (w : ⋃ i ∈ t, s i = ⊤) (x : β) : ∃ i ∈ t, x ∈ s i := by have p : x ∈ ⊤ := Set.mem_univ x rw [← w, Set.mem_iUnion] at p simpa using p theorem nonempty_of_union_eq_top_of_nonempty {ι : Type*} (t : Set ι) (s : ι → Set α) (H : Nonempty α) (w : ⋃ i ∈ t, s i = ⊤) : t.Nonempty := by obtain ⟨x, m, -⟩ := exists_set_mem_of_union_eq_top t s w H.some exact ⟨x, m⟩ theorem nonempty_of_nonempty_iUnion {s : ι → Set α} (h_Union : (⋃ i, s i).Nonempty) : Nonempty ι := by obtain ⟨x, hx⟩ := h_Union exact ⟨Classical.choose <| mem_iUnion.mp hx⟩ theorem nonempty_of_nonempty_iUnion_eq_univ {s : ι → Set α} [Nonempty α] (h_Union : ⋃ i, s i = univ) : Nonempty ι := nonempty_of_nonempty_iUnion (s := s) (by simpa only [h_Union] using univ_nonempty) theorem setOf_exists (p : ι → β → Prop) : { x | ∃ i, p i x } = ⋃ i, { x | p i x } := ext fun _ => mem_iUnion.symm theorem setOf_forall (p : ι → β → Prop) : { x | ∀ i, p i x } = ⋂ i, { x | p i x } := ext fun _ => mem_iInter.symm theorem iUnion_subset {s : ι → Set α} {t : Set α} (h : ∀ i, s i ⊆ t) : ⋃ i, s i ⊆ t := iSup_le h theorem iUnion₂_subset {s : ∀ i, κ i → Set α} {t : Set α} (h : ∀ i j, s i j ⊆ t) : ⋃ (i) (j), s i j ⊆ t := iUnion_subset fun x => iUnion_subset (h x) theorem subset_iInter {t : Set β} {s : ι → Set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := le_iInf h theorem subset_iInter₂ {s : Set α} {t : ∀ i, κ i → Set α} (h : ∀ i j, s ⊆ t i j) : s ⊆ ⋂ (i) (j), t i j := subset_iInter fun x => subset_iInter <| h x @[simp] theorem iUnion_subset_iff {s : ι → Set α} {t : Set α} : ⋃ i, s i ⊆ t ↔ ∀ i, s i ⊆ t := ⟨fun h _ => Subset.trans (le_iSup s _) h, iUnion_subset⟩ theorem iUnion₂_subset_iff {s : ∀ i, κ i → Set α} {t : Set α} : ⋃ (i) (j), s i j ⊆ t ↔ ∀ i j, s i j ⊆ t := by simp_rw [iUnion_subset_iff] @[simp] theorem subset_iInter_iff {s : Set α} {t : ι → Set α} : (s ⊆ ⋂ i, t i) ↔ ∀ i, s ⊆ t i := le_iInf_iff theorem subset_iInter₂_iff {s : Set α} {t : ∀ i, κ i → Set α} : (s ⊆ ⋂ (i) (j), t i j) ↔ ∀ i j, s ⊆ t i j := by simp_rw [subset_iInter_iff] theorem subset_iUnion : ∀ (s : ι → Set β) (i : ι), s i ⊆ ⋃ i, s i := le_iSup theorem iInter_subset : ∀ (s : ι → Set β) (i : ι), ⋂ i, s i ⊆ s i := iInf_le lemma iInter_subset_iUnion [Nonempty ι] {s : ι → Set α} : ⋂ i, s i ⊆ ⋃ i, s i := iInf_le_iSup theorem subset_iUnion₂ {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : s i j ⊆ ⋃ (i') (j'), s i' j' := le_iSup₂ i j theorem iInter₂_subset {s : ∀ i, κ i → Set α} (i : ι) (j : κ i) : ⋂ (i) (j), s i j ⊆ s i j := iInf₂_le i j /-- This rather trivial consequence of `subset_iUnion`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem subset_iUnion_of_subset {s : Set α} {t : ι → Set α} (i : ι) (h : s ⊆ t i) : s ⊆ ⋃ i, t i := le_iSup_of_le i h /-- This rather trivial consequence of `iInter_subset`is convenient with `apply`, and has `i` explicit for this purpose. -/ theorem iInter_subset_of_subset {s : ι → Set α} {t : Set α} (i : ι) (h : s i ⊆ t) : ⋂ i, s i ⊆ t := iInf_le_of_le i h /-- This rather trivial consequence of `subset_iUnion₂` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem subset_iUnion₂_of_subset {s : Set α} {t : ∀ i, κ i → Set α} (i : ι) (j : κ i) (h : s ⊆ t i j) : s ⊆ ⋃ (i) (j), t i j := le_iSup₂_of_le i j h /-- This rather trivial consequence of `iInter₂_subset` is convenient with `apply`, and has `i` and `j` explicit for this purpose. -/ theorem iInter₂_subset_of_subset {s : ∀ i, κ i → Set α} {t : Set α} (i : ι) (j : κ i) (h : s i j ⊆ t) : ⋂ (i) (j), s i j ⊆ t := iInf₂_le_of_le i j h theorem iUnion_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono h @[gcongr] theorem iUnion_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iUnion s ⊆ iUnion t := iSup_mono h theorem iUnion₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋃ (i) (j), s i j ⊆ ⋃ (i) (j), t i j := iSup₂_mono h theorem iInter_mono {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : ⋂ i, s i ⊆ ⋂ i, t i := iInf_mono h @[gcongr] theorem iInter_mono'' {s t : ι → Set α} (h : ∀ i, s i ⊆ t i) : iInter s ⊆ iInter t := iInf_mono h theorem iInter₂_mono {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j ⊆ t i j) : ⋂ (i) (j), s i j ⊆ ⋂ (i) (j), t i j := iInf₂_mono h theorem iUnion_mono' {s : ι → Set α} {t : ι₂ → Set α} (h : ∀ i, ∃ j, s i ⊆ t j) : ⋃ i, s i ⊆ ⋃ i, t i := iSup_mono' h theorem iUnion₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i j, ∃ i' j', s i j ⊆ t i' j') : ⋃ (i) (j), s i j ⊆ ⋃ (i') (j'), t i' j' := iSup₂_mono' h theorem iInter_mono' {s : ι → Set α} {t : ι' → Set α} (h : ∀ j, ∃ i, s i ⊆ t j) : ⋂ i, s i ⊆ ⋂ j, t j := Set.subset_iInter fun j => let ⟨i, hi⟩ := h j iInter_subset_of_subset i hi theorem iInter₂_mono' {s : ∀ i, κ i → Set α} {t : ∀ i', κ' i' → Set α} (h : ∀ i' j', ∃ i j, s i j ⊆ t i' j') : ⋂ (i) (j), s i j ⊆ ⋂ (i') (j'), t i' j' := subset_iInter₂_iff.2 fun i' j' => let ⟨_, _, hst⟩ := h i' j' (iInter₂_subset _ _).trans hst theorem iUnion₂_subset_iUnion (κ : ι → Sort*) (s : ι → Set α) : ⋃ (i) (_ : κ i), s i ⊆ ⋃ i, s i := iUnion_mono fun _ => iUnion_subset fun _ => Subset.rfl theorem iInter_subset_iInter₂ (κ : ι → Sort*) (s : ι → Set α) : ⋂ i, s i ⊆ ⋂ (i) (_ : κ i), s i := iInter_mono fun _ => subset_iInter fun _ => Subset.rfl theorem iUnion_setOf (P : ι → α → Prop) : ⋃ i, { x : α | P i x } = { x : α | ∃ i, P i x } := by ext exact mem_iUnion theorem iInter_setOf (P : ι → α → Prop) : ⋂ i, { x : α | P i x } = { x : α | ∀ i, P i x } := by ext exact mem_iInter theorem iUnion_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋃ x, f x = ⋃ y, g y := h1.iSup_congr h h2 theorem iInter_congr_of_surjective {f : ι → Set α} {g : ι₂ → Set α} (h : ι → ι₂) (h1 : Surjective h) (h2 : ∀ x, g (h x) = f x) : ⋂ x, f x = ⋂ y, g y := h1.iInf_congr h h2 lemma iUnion_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋃ i, s i = ⋃ i, t i := iSup_congr h lemma iInter_congr {s t : ι → Set α} (h : ∀ i, s i = t i) : ⋂ i, s i = ⋂ i, t i := iInf_congr h lemma iUnion₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋃ (i) (j), s i j = ⋃ (i) (j), t i j := iUnion_congr fun i => iUnion_congr <| h i lemma iInter₂_congr {s t : ∀ i, κ i → Set α} (h : ∀ i j, s i j = t i j) : ⋂ (i) (j), s i j = ⋂ (i) (j), t i j := iInter_congr fun i => iInter_congr <| h i section Nonempty variable [Nonempty ι] {f : ι → Set α} {s : Set α} lemma iUnion_const (s : Set β) : ⋃ _ : ι, s = s := iSup_const lemma iInter_const (s : Set β) : ⋂ _ : ι, s = s := iInf_const lemma iUnion_eq_const (hf : ∀ i, f i = s) : ⋃ i, f i = s := (iUnion_congr hf).trans <| iUnion_const _ lemma iInter_eq_const (hf : ∀ i, f i = s) : ⋂ i, f i = s := (iInter_congr hf).trans <| iInter_const _ end Nonempty @[simp] theorem compl_iUnion (s : ι → Set β) : (⋃ i, s i)ᶜ = ⋂ i, (s i)ᶜ := compl_iSup theorem compl_iUnion₂ (s : ∀ i, κ i → Set α) : (⋃ (i) (j), s i j)ᶜ = ⋂ (i) (j), (s i j)ᶜ := by simp_rw [compl_iUnion] @[simp] theorem compl_iInter (s : ι → Set β) : (⋂ i, s i)ᶜ = ⋃ i, (s i)ᶜ := compl_iInf theorem compl_iInter₂ (s : ∀ i, κ i → Set α) : (⋂ (i) (j), s i j)ᶜ = ⋃ (i) (j), (s i j)ᶜ := by simp_rw [compl_iInter] -- classical -- complete_boolean_algebra theorem iUnion_eq_compl_iInter_compl (s : ι → Set β) : ⋃ i, s i = (⋂ i, (s i)ᶜ)ᶜ := by simp only [compl_iInter, compl_compl] -- classical -- complete_boolean_algebra theorem iInter_eq_compl_iUnion_compl (s : ι → Set β) : ⋂ i, s i = (⋃ i, (s i)ᶜ)ᶜ := by simp only [compl_iUnion, compl_compl] theorem inter_iUnion (s : Set β) (t : ι → Set β) : (s ∩ ⋃ i, t i) = ⋃ i, s ∩ t i := inf_iSup_eq _ _ theorem iUnion_inter (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := iSup_inf_eq _ _ theorem iUnion_union_distrib (s : ι → Set β) (t : ι → Set β) : ⋃ i, s i ∪ t i = (⋃ i, s i) ∪ ⋃ i, t i := iSup_sup_eq theorem iInter_inter_distrib (s : ι → Set β) (t : ι → Set β) : ⋂ i, s i ∩ t i = (⋂ i, s i) ∩ ⋂ i, t i := iInf_inf_eq theorem union_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∪ ⋃ i, t i) = ⋃ i, s ∪ t i := sup_iSup theorem iUnion_union [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := iSup_sup theorem inter_iInter [Nonempty ι] (s : Set β) (t : ι → Set β) : (s ∩ ⋂ i, t i) = ⋂ i, s ∩ t i := inf_iInf theorem iInter_inter [Nonempty ι] (s : Set β) (t : ι → Set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := iInf_inf theorem insert_iUnion [Nonempty ι] (x : β) (t : ι → Set β) : insert x (⋃ i, t i) = ⋃ i, insert x (t i) := by simp_rw [← union_singleton, iUnion_union] -- classical theorem union_iInter (s : Set β) (t : ι → Set β) : (s ∪ ⋂ i, t i) = ⋂ i, s ∪ t i := sup_iInf_eq _ _ theorem iInter_union (s : ι → Set β) (t : Set β) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ theorem insert_iInter (x : β) (t : ι → Set β) : insert x (⋂ i, t i) = ⋂ i, insert x (t i) := by simp_rw [← union_singleton, iInter_union] theorem iUnion_diff (s : Set β) (t : ι → Set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := iUnion_inter _ _ theorem diff_iUnion [Nonempty ι] (s : Set β) (t : ι → Set β) : (s \ ⋃ i, t i) = ⋂ i, s \ t i := by rw [diff_eq, compl_iUnion, inter_iInter]; rfl theorem diff_iInter (s : Set β) (t : ι → Set β) : (s \ ⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_iInter, inter_iUnion]; rfl theorem iUnion_inter_subset {ι α} {s t : ι → Set α} : ⋃ i, s i ∩ t i ⊆ (⋃ i, s i) ∩ ⋃ i, t i := le_iSup_inf_iSup s t theorem iUnion_inter_of_monotone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_monotone hs ht theorem iUnion_inter_of_antitone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋃ i, s i ∩ t i = (⋃ i, s i) ∩ ⋃ i, t i := iSup_inf_of_antitone hs ht theorem iInter_union_of_monotone {ι α} [Preorder ι] [IsDirected ι (swap (· ≤ ·))] {s t : ι → Set α} (hs : Monotone s) (ht : Monotone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_monotone hs ht theorem iInter_union_of_antitone {ι α} [Preorder ι] [IsDirected ι (· ≤ ·)] {s t : ι → Set α} (hs : Antitone s) (ht : Antitone t) : ⋂ i, s i ∪ t i = (⋂ i, s i) ∪ ⋂ i, t i := iInf_sup_of_antitone hs ht /-- An equality version of this lemma is `iUnion_iInter_of_monotone` in `Data.Set.Finite`. -/ theorem iUnion_iInter_subset {s : ι → ι' → Set α} : (⋃ j, ⋂ i, s i j) ⊆ ⋂ i, ⋃ j, s i j := iSup_iInf_le_iInf_iSup (flip s) theorem iUnion_option {ι} (s : Option ι → Set α) : ⋃ o, s o = s none ∪ ⋃ i, s (some i) := iSup_option s theorem iInter_option {ι} (s : Option ι → Set α) : ⋂ o, s o = s none ∩ ⋂ i, s (some i) := iInf_option s section variable (p : ι → Prop) [DecidablePred p] theorem iUnion_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋃ i, (if h : p i then f i h else g i h) = (⋃ (i) (h : p i), f i h) ∪ ⋃ (i) (h : ¬p i), g i h := iSup_dite _ _ _ theorem iUnion_ite (f g : ι → Set α) : ⋃ i, (if p i then f i else g i) = (⋃ (i) (_ : p i), f i) ∪ ⋃ (i) (_ : ¬p i), g i := iUnion_dite _ _ _ theorem iInter_dite (f : ∀ i, p i → Set α) (g : ∀ i, ¬p i → Set α) : ⋂ i, (if h : p i then f i h else g i h) = (⋂ (i) (h : p i), f i h) ∩ ⋂ (i) (h : ¬p i), g i h := iInf_dite _ _ _ theorem iInter_ite (f g : ι → Set α) : ⋂ i, (if p i then f i else g i) = (⋂ (i) (_ : p i), f i) ∩ ⋂ (i) (_ : ¬p i), g i := iInter_dite _ _ _ end /-! ### Unions and intersections indexed by `Prop` -/ theorem iInter_false {s : False → Set α} : iInter s = univ := iInf_false theorem iUnion_false {s : False → Set α} : iUnion s = ∅ := iSup_false @[simp] theorem iInter_true {s : True → Set α} : iInter s = s trivial := iInf_true @[simp] theorem iUnion_true {s : True → Set α} : iUnion s = s trivial := iSup_true @[simp] theorem iInter_exists {p : ι → Prop} {f : Exists p → Set α} : ⋂ x, f x = ⋂ (i) (h : p i), f ⟨i, h⟩ := iInf_exists @[simp] theorem iUnion_exists {p : ι → Prop} {f : Exists p → Set α} : ⋃ x, f x = ⋃ (i) (h : p i), f ⟨i, h⟩ := iSup_exists @[simp] theorem iUnion_empty : (⋃ _ : ι, ∅ : Set α) = ∅ := iSup_bot @[simp] theorem iInter_univ : (⋂ _ : ι, univ : Set α) = univ := iInf_top section variable {s : ι → Set α} @[simp] theorem iUnion_eq_empty : ⋃ i, s i = ∅ ↔ ∀ i, s i = ∅ := iSup_eq_bot @[simp] theorem iInter_eq_univ : ⋂ i, s i = univ ↔ ∀ i, s i = univ := iInf_eq_top @[simp] theorem nonempty_iUnion : (⋃ i, s i).Nonempty ↔ ∃ i, (s i).Nonempty := by simp [nonempty_iff_ne_empty] theorem nonempty_biUnion {t : Set α} {s : α → Set β} : (⋃ i ∈ t, s i).Nonempty ↔ ∃ i ∈ t, (s i).Nonempty := by simp theorem iUnion_nonempty_index (s : Set α) (t : s.Nonempty → Set β) : ⋃ h, t h = ⋃ x ∈ s, t ⟨x, ‹_›⟩ := iSup_exists end @[simp] theorem iInter_iInter_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋂ (x) (h : x = b), s x h = s b rfl := iInf_iInf_eq_left @[simp] theorem iInter_iInter_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋂ (x) (h : b = x), s x h = s b rfl := iInf_iInf_eq_right @[simp] theorem iUnion_iUnion_eq_left {b : β} {s : ∀ x : β, x = b → Set α} : ⋃ (x) (h : x = b), s x h = s b rfl := iSup_iSup_eq_left @[simp] theorem iUnion_iUnion_eq_right {b : β} {s : ∀ x : β, b = x → Set α} : ⋃ (x) (h : b = x), s x h = s b rfl := iSup_iSup_eq_right theorem iInter_or {p q : Prop} (s : p ∨ q → Set α) : ⋂ h, s h = (⋂ h : p, s (Or.inl h)) ∩ ⋂ h : q, s (Or.inr h) := iInf_or theorem iUnion_or {p q : Prop} (s : p ∨ q → Set α) : ⋃ h, s h = (⋃ i, s (Or.inl i)) ∪ ⋃ j, s (Or.inr j) := iSup_or theorem iUnion_and {p q : Prop} (s : p ∧ q → Set α) : ⋃ h, s h = ⋃ (hp) (hq), s ⟨hp, hq⟩ := iSup_and theorem iInter_and {p q : Prop} (s : p ∧ q → Set α) : ⋂ h, s h = ⋂ (hp) (hq), s ⟨hp, hq⟩ := iInf_and theorem iUnion_comm (s : ι → ι' → Set α) : ⋃ (i) (i'), s i i' = ⋃ (i') (i), s i i' := iSup_comm theorem iInter_comm (s : ι → ι' → Set α) : ⋂ (i) (i'), s i i' = ⋂ (i') (i), s i i' := iInf_comm theorem iUnion_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_sigma theorem iUnion_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋃ i, ⋃ a, s i a = ⋃ ia : Sigma γ, s ia.1 ia.2 := iSup_sigma' _ theorem iInter_sigma {γ : α → Type*} (s : Sigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ := iInf_sigma theorem iInter_sigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋂ i, ⋂ a, s i a = ⋂ ia : Sigma γ, s ia.1 ia.2 := iInf_sigma' _ theorem iUnion₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋃ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋃ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iSup₂_comm _ theorem iInter₂_comm (s : ∀ i₁, κ₁ i₁ → ∀ i₂, κ₂ i₂ → Set α) : ⋂ (i₁) (j₁) (i₂) (j₂), s i₁ j₁ i₂ j₂ = ⋂ (i₂) (j₂) (i₁) (j₁), s i₁ j₁ i₂ j₂ := iInf₂_comm _ @[simp] theorem biUnion_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋃ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iUnion_and, @iUnion_comm _ ι'] @[simp] theorem biUnion_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋃ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋃ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iUnion_and, @iUnion_comm _ ι] @[simp] theorem biInter_and (p : ι → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p x ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p x ∧ q x y), s x y h = ⋂ (x : ι) (hx : p x) (y : ι') (hy : q x y), s x y ⟨hx, hy⟩ := by simp only [iInter_and, @iInter_comm _ ι'] @[simp] theorem biInter_and' (p : ι' → Prop) (q : ι → ι' → Prop) (s : ∀ x y, p y ∧ q x y → Set α) : ⋂ (x : ι) (y : ι') (h : p y ∧ q x y), s x y h = ⋂ (y : ι') (hy : p y) (x : ι) (hx : q x y), s x y ⟨hy, hx⟩ := by simp only [iInter_and, @iInter_comm _ ι] @[simp] theorem iUnion_iUnion_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋃ (x) (h), s x h = s b (Or.inl rfl) ∪ ⋃ (x) (h : p x), s x (Or.inr h) := by simp only [iUnion_or, iUnion_union_distrib, iUnion_iUnion_eq_left] @[simp] theorem iInter_iInter_eq_or_left {b : β} {p : β → Prop} {s : ∀ x : β, x = b ∨ p x → Set α} : ⋂ (x) (h), s x h = s b (Or.inl rfl) ∩ ⋂ (x) (h : p x), s x (Or.inr h) := by simp only [iInter_or, iInter_inter_distrib, iInter_iInter_eq_left] lemma iUnion_sum {s : α ⊕ β → Set γ} : ⋃ x, s x = (⋃ x, s (.inl x)) ∪ ⋃ x, s (.inr x) := iSup_sum lemma iInter_sum {s : α ⊕ β → Set γ} : ⋂ x, s x = (⋂ x, s (.inl x)) ∩ ⋂ x, s (.inr x) := iInf_sum theorem iUnion_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋃ ia, s ia = ⋃ i, ⋃ a, s ⟨i, a⟩ := iSup_psigma _ /-- A reversed version of `iUnion_psigma` with a curried map. -/ theorem iUnion_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋃ i, ⋃ a, s i a = ⋃ ia : PSigma γ, s ia.1 ia.2 := iSup_psigma' _ theorem iInter_psigma {γ : α → Type*} (s : PSigma γ → Set β) : ⋂ ia, s ia = ⋂ i, ⋂ a, s ⟨i, a⟩ := iInf_psigma _ /-- A reversed version of `iInter_psigma` with a curried map. -/ theorem iInter_psigma' {γ : α → Type*} (s : ∀ i, γ i → Set β) : ⋂ i, ⋂ a, s i a = ⋂ ia : PSigma γ, s ia.1 ia.2 := iInf_psigma' _ /-! ### Bounded unions and intersections -/ /-- A specialization of `mem_iUnion₂`. -/ theorem mem_biUnion {s : Set α} {t : α → Set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := mem_iUnion₂_of_mem xs ytx /-- A specialization of `mem_iInter₂`. -/ theorem mem_biInter {s : Set α} {t : α → Set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) : y ∈ ⋂ x ∈ s, t x := mem_iInter₂_of_mem h /-- A specialization of `subset_iUnion₂`. -/ theorem subset_biUnion_of_mem {s : Set α} {u : α → Set β} {x : α} (xs : x ∈ s) : u x ⊆ ⋃ x ∈ s, u x := subset_iUnion₂ (s := fun i _ => u i) x xs /-- A specialization of `iInter₂_subset`. -/ theorem biInter_subset_of_mem {s : Set α} {t : α → Set β} {x : α} (xs : x ∈ s) : ⋂ x ∈ s, t x ⊆ t x := iInter₂_subset x xs lemma biInter_subset_biUnion {s : Set α} (hs : s.Nonempty) {t : α → Set β} : ⋂ x ∈ s, t x ⊆ ⋃ x ∈ s, t x := biInf_le_biSup hs theorem biUnion_subset_biUnion_left {s s' : Set α} {t : α → Set β} (h : s ⊆ s') : ⋃ x ∈ s, t x ⊆ ⋃ x ∈ s', t x := iUnion₂_subset fun _ hx => subset_biUnion_of_mem <| h hx theorem biInter_subset_biInter_left {s s' : Set α} {t : α → Set β} (h : s' ⊆ s) : ⋂ x ∈ s, t x ⊆ ⋂ x ∈ s', t x := subset_iInter₂ fun _ hx => biInter_subset_of_mem <| h hx theorem biUnion_mono {s s' : Set α} {t t' : α → Set β} (hs : s' ⊆ s) (h : ∀ x ∈ s, t x ⊆ t' x) : ⋃ x ∈ s', t x ⊆ ⋃ x ∈ s, t' x := (biUnion_subset_biUnion_left hs).trans <| iUnion₂_mono h theorem biInter_mono {s s' : Set α} {t t' : α → Set β} (hs : s ⊆ s') (h : ∀ x ∈ s, t x ⊆ t' x) : ⋂ x ∈ s', t x ⊆ ⋂ x ∈ s, t' x := (biInter_subset_biInter_left hs).trans <| iInter₂_mono h theorem biUnion_eq_iUnion (s : Set α) (t : ∀ x ∈ s, Set β) : ⋃ x ∈ s, t x ‹_› = ⋃ x : s, t x x.2 := iSup_subtype' theorem biInter_eq_iInter (s : Set α) (t : ∀ x ∈ s, Set β) : ⋂ x ∈ s, t x ‹_› = ⋂ x : s, t x x.2 := iInf_subtype' @[simp] lemma biUnion_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋃ a ∈ s, t = t := biSup_const hs @[simp] lemma biInter_const {s : Set α} (hs : s.Nonempty) (t : Set β) : ⋂ a ∈ s, t = t := biInf_const hs theorem iUnion_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋃ x : { x // p x }, s x = ⋃ (x) (hx : p x), s ⟨x, hx⟩ := iSup_subtype theorem iInter_subtype (p : α → Prop) (s : { x // p x } → Set β) : ⋂ x : { x // p x }, s x = ⋂ (x) (hx : p x), s ⟨x, hx⟩ := iInf_subtype theorem biInter_empty (u : α → Set β) : ⋂ x ∈ (∅ : Set α), u x = univ := iInf_emptyset theorem biInter_univ (u : α → Set β) : ⋂ x ∈ @univ α, u x = ⋂ x, u x := iInf_univ @[simp] theorem biUnion_self (s : Set α) : ⋃ x ∈ s, s = s := Subset.antisymm (iUnion₂_subset fun _ _ => Subset.refl s) fun _ hx => mem_biUnion hx hx @[simp] theorem iUnion_nonempty_self (s : Set α) : ⋃ _ : s.Nonempty, s = s := by rw [iUnion_nonempty_index, biUnion_self] theorem biInter_singleton (a : α) (s : α → Set β) : ⋂ x ∈ ({a} : Set α), s x = s a := iInf_singleton theorem biInter_union (s t : Set α) (u : α → Set β) : ⋂ x ∈ s ∪ t, u x = (⋂ x ∈ s, u x) ∩ ⋂ x ∈ t, u x := iInf_union theorem biInter_insert (a : α) (s : Set α) (t : α → Set β) : ⋂ x ∈ insert a s, t x = t a ∩ ⋂ x ∈ s, t x := by simp theorem biInter_pair (a b : α) (s : α → Set β) : ⋂ x ∈ ({a, b} : Set α), s x = s a ∩ s b := by rw [biInter_insert, biInter_singleton] theorem biInter_inter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, f i ∩ t = (⋂ i ∈ s, f i) ∩ t := by haveI : Nonempty s := hs.to_subtype simp [biInter_eq_iInter, ← iInter_inter] theorem inter_biInter {ι α : Type*} {s : Set ι} (hs : s.Nonempty) (f : ι → Set α) (t : Set α) : ⋂ i ∈ s, t ∩ f i = t ∩ ⋂ i ∈ s, f i := by rw [inter_comm, ← biInter_inter hs] simp [inter_comm] theorem biUnion_empty (s : α → Set β) : ⋃ x ∈ (∅ : Set α), s x = ∅ := iSup_emptyset theorem biUnion_univ (s : α → Set β) : ⋃ x ∈ @univ α, s x = ⋃ x, s x := iSup_univ theorem biUnion_singleton (a : α) (s : α → Set β) : ⋃ x ∈ ({a} : Set α), s x = s a := iSup_singleton @[simp] theorem biUnion_of_singleton (s : Set α) : ⋃ x ∈ s, {x} = s := ext <| by simp theorem biUnion_union (s t : Set α) (u : α → Set β) : ⋃ x ∈ s ∪ t, u x = (⋃ x ∈ s, u x) ∪ ⋃ x ∈ t, u x := iSup_union @[simp] theorem iUnion_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋃ i, f i = ⋃ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iUnion_subtype _ _ @[simp] theorem iInter_coe_set {α β : Type*} (s : Set α) (f : s → Set β) : ⋂ i, f i = ⋂ i ∈ s, f ⟨i, ‹i ∈ s›⟩ := iInter_subtype _ _ theorem biUnion_insert (a : α) (s : Set α) (t : α → Set β) : ⋃ x ∈ insert a s, t x = t a ∪ ⋃ x ∈ s, t x := by simp theorem biUnion_pair (a b : α) (s : α → Set β) : ⋃ x ∈ ({a, b} : Set α), s x = s a ∪ s b := by simp theorem inter_iUnion₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∩ ⋃ (i) (j), t i j) = ⋃ (i) (j), s ∩ t i j := by simp only [inter_iUnion] theorem iUnion₂_inter (s : ∀ i, κ i → Set α) (t : Set α) : (⋃ (i) (j), s i j) ∩ t = ⋃ (i) (j), s i j ∩ t := by simp_rw [iUnion_inter] theorem union_iInter₂ (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_iInter] theorem iInter₂_union (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [iInter_union] theorem mem_sUnion_of_mem {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀ S := ⟨t, ht, hx⟩ -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : α} {t : Set α} {S : Set (Set α)} (hx : x ∉ ⋃₀ S) (ht : t ∈ S) : x ∉ t := fun h => hx ⟨t, ht, h⟩ theorem sInter_subset_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := sInf_le tS theorem subset_sUnion_of_mem {S : Set (Set α)} {t : Set α} (tS : t ∈ S) : t ⊆ ⋃₀ S := le_sSup tS theorem subset_sUnion_of_subset {s : Set α} (t : Set (Set α)) (u : Set α) (h₁ : s ⊆ u) (h₂ : u ∈ t) : s ⊆ ⋃₀ t := Subset.trans h₁ (subset_sUnion_of_mem h₂) theorem sUnion_subset {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t' ⊆ t) : ⋃₀ S ⊆ t := sSup_le h @[simp] theorem sUnion_subset_iff {s : Set (Set α)} {t : Set α} : ⋃₀ s ⊆ t ↔ ∀ t' ∈ s, t' ⊆ t := sSup_le_iff /-- `sUnion` is monotone under taking a subset of each set. -/ lemma sUnion_mono_subsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, t ⊆ f t) : ⋃₀ s ⊆ ⋃₀ (f '' s) := fun _ ⟨t, htx, hxt⟩ ↦ ⟨f t, mem_image_of_mem f htx, hf t hxt⟩ /-- `sUnion` is monotone under taking a superset of each set. -/ lemma sUnion_mono_supsets {s : Set (Set α)} {f : Set α → Set α} (hf : ∀ t : Set α, f t ⊆ t) : ⋃₀ (f '' s) ⊆ ⋃₀ s := -- If t ∈ f '' s is arbitrary; t = f u for some u : Set α. fun _ ⟨_, ⟨u, hus, hut⟩, hxt⟩ ↦ ⟨u, hus, (hut ▸ hf u) hxt⟩ theorem subset_sInter {S : Set (Set α)} {t : Set α} (h : ∀ t' ∈ S, t ⊆ t') : t ⊆ ⋂₀ S := le_sInf h @[simp] theorem subset_sInter_iff {S : Set (Set α)} {t : Set α} : t ⊆ ⋂₀ S ↔ ∀ t' ∈ S, t ⊆ t' := le_sInf_iff @[gcongr] theorem sUnion_subset_sUnion {S T : Set (Set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T := sUnion_subset fun _ hs => subset_sUnion_of_mem (h hs) @[gcongr] theorem sInter_subset_sInter {S T : Set (Set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter fun _ hs => sInter_subset_of_mem (h hs) @[simp] theorem sUnion_empty : ⋃₀ ∅ = (∅ : Set α) := sSup_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : Set α) := sInf_empty @[simp] theorem sUnion_singleton (s : Set α) : ⋃₀ {s} = s := sSup_singleton @[simp] theorem sInter_singleton (s : Set α) : ⋂₀ {s} = s := sInf_singleton @[simp] theorem sUnion_eq_empty {S : Set (Set α)} : ⋃₀ S = ∅ ↔ ∀ s ∈ S, s = ∅ := sSup_eq_bot @[simp] theorem sInter_eq_univ {S : Set (Set α)} : ⋂₀ S = univ ↔ ∀ s ∈ S, s = univ := sInf_eq_top theorem subset_powerset_iff {s : Set (Set α)} {t : Set α} : s ⊆ 𝒫 t ↔ ⋃₀ s ⊆ t := sUnion_subset_iff.symm /-- `⋃₀` and `𝒫` form a Galois connection. -/ theorem sUnion_powerset_gc : GaloisConnection (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gc_sSup_Iic /-- `⋃₀` and `𝒫` form a Galois insertion. -/ def sUnionPowersetGI : GaloisInsertion (⋃₀ · : Set (Set α) → Set α) (𝒫 · : Set α → Set (Set α)) := gi_sSup_Iic @[deprecated (since := "2024-12-07")] alias sUnion_powerset_gi := sUnionPowersetGI /-- If all sets in a collection are either `∅` or `Set.univ`, then so is their union. -/ theorem sUnion_mem_empty_univ {S : Set (Set α)} (h : S ⊆ {∅, univ}) : ⋃₀ S ∈ ({∅, univ} : Set (Set α)) := by simp only [mem_insert_iff, mem_singleton_iff, or_iff_not_imp_left, sUnion_eq_empty, not_forall] rintro ⟨s, hs, hne⟩ obtain rfl : s = univ := (h hs).resolve_left hne exact univ_subset_iff.1 <| subset_sUnion_of_mem hs @[simp] theorem nonempty_sUnion {S : Set (Set α)} : (⋃₀ S).Nonempty ↔ ∃ s ∈ S, Set.Nonempty s := by simp [nonempty_iff_ne_empty] theorem Nonempty.of_sUnion {s : Set (Set α)} (h : (⋃₀ s).Nonempty) : s.Nonempty := let ⟨s, hs, _⟩ := nonempty_sUnion.1 h ⟨s, hs⟩ theorem Nonempty.of_sUnion_eq_univ [Nonempty α] {s : Set (Set α)} (h : ⋃₀ s = univ) : s.Nonempty := Nonempty.of_sUnion <| h.symm ▸ univ_nonempty theorem sUnion_union (S T : Set (Set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T := sSup_union theorem sInter_union (S T : Set (Set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := sInf_union @[simp] theorem sUnion_insert (s : Set α) (T : Set (Set α)) : ⋃₀ insert s T = s ∪ ⋃₀ T := sSup_insert @[simp] theorem sInter_insert (s : Set α) (T : Set (Set α)) : ⋂₀ insert s T = s ∩ ⋂₀ T := sInf_insert @[simp] theorem sUnion_diff_singleton_empty (s : Set (Set α)) : ⋃₀ (s \ {∅}) = ⋃₀ s := sSup_diff_singleton_bot s @[simp] theorem sInter_diff_singleton_univ (s : Set (Set α)) : ⋂₀ (s \ {univ}) = ⋂₀ s := sInf_diff_singleton_top s theorem sUnion_pair (s t : Set α) : ⋃₀ {s, t} = s ∪ t := sSup_pair theorem sInter_pair (s t : Set α) : ⋂₀ {s, t} = s ∩ t := sInf_pair @[simp] theorem sUnion_image (f : α → Set β) (s : Set α) : ⋃₀ (f '' s) = ⋃ a ∈ s, f a := sSup_image @[simp] theorem sInter_image (f : α → Set β) (s : Set α) : ⋂₀ (f '' s) = ⋂ a ∈ s, f a := sInf_image @[simp] lemma sUnion_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) : ⋃₀ (image2 f s t) = ⋃ (a ∈ s) (b ∈ t), f a b := sSup_image2 @[simp] lemma sInter_image2 (f : α → β → Set γ) (s : Set α) (t : Set β) : ⋂₀ (image2 f s t) = ⋂ (a ∈ s) (b ∈ t), f a b := sInf_image2 @[simp] theorem sUnion_range (f : ι → Set β) : ⋃₀ range f = ⋃ x, f x := rfl @[simp] theorem sInter_range (f : ι → Set β) : ⋂₀ range f = ⋂ x, f x := rfl theorem iUnion_eq_univ_iff {f : ι → Set α} : ⋃ i, f i = univ ↔ ∀ x, ∃ i, x ∈ f i := by simp only [eq_univ_iff_forall, mem_iUnion] theorem iUnion₂_eq_univ_iff {s : ∀ i, κ i → Set α} : ⋃ (i) (j), s i j = univ ↔ ∀ a, ∃ i j, a ∈ s i j := by simp only [iUnion_eq_univ_iff, mem_iUnion] theorem sUnion_eq_univ_iff {c : Set (Set α)} : ⋃₀ c = univ ↔ ∀ a, ∃ b ∈ c, a ∈ b := by simp only [eq_univ_iff_forall, mem_sUnion] -- classical theorem iInter_eq_empty_iff {f : ι → Set α} : ⋂ i, f i = ∅ ↔ ∀ x, ∃ i, x ∉ f i := by simp [Set.eq_empty_iff_forall_not_mem] -- classical theorem iInter₂_eq_empty_iff {s : ∀ i, κ i → Set α} : ⋂ (i) (j), s i j = ∅ ↔ ∀ a, ∃ i j, a ∉ s i j := by simp only [eq_empty_iff_forall_not_mem, mem_iInter, not_forall] -- classical theorem sInter_eq_empty_iff {c : Set (Set α)} : ⋂₀ c = ∅ ↔ ∀ a, ∃ b ∈ c, a ∉ b := by simp [Set.eq_empty_iff_forall_not_mem] -- classical @[simp] theorem nonempty_iInter {f : ι → Set α} : (⋂ i, f i).Nonempty ↔ ∃ x, ∀ i, x ∈ f i := by simp [nonempty_iff_ne_empty, iInter_eq_empty_iff] -- classical theorem nonempty_iInter₂ {s : ∀ i, κ i → Set α} : (⋂ (i) (j), s i j).Nonempty ↔ ∃ a, ∀ i j, a ∈ s i j := by simp -- classical @[simp] theorem nonempty_sInter {c : Set (Set α)} : (⋂₀ c).Nonempty ↔ ∃ a, ∀ b ∈ c, a ∈ b := by simp [nonempty_iff_ne_empty, sInter_eq_empty_iff] -- classical theorem compl_sUnion (S : Set (Set α)) : (⋃₀ S)ᶜ = ⋂₀ (compl '' S) := ext fun x => by simp -- classical theorem sUnion_eq_compl_sInter_compl (S : Set (Set α)) : ⋃₀ S = (⋂₀ (compl '' S))ᶜ := by rw [← compl_compl (⋃₀ S), compl_sUnion] -- classical theorem compl_sInter (S : Set (Set α)) : (⋂₀ S)ᶜ = ⋃₀ (compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] -- classical theorem sInter_eq_compl_sUnion_compl (S : Set (Set α)) : ⋂₀ S = (⋃₀ (compl '' S))ᶜ := by rw [← compl_compl (⋂₀ S), compl_sInter] theorem inter_empty_of_inter_sUnion_empty {s t : Set α} {S : Set (Set α)} (hs : t ∈ S) (h : s ∩ ⋃₀ S = ∅) : s ∩ t = ∅ := eq_empty_of_subset_empty <| by rw [← h]; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) theorem range_sigma_eq_iUnion_range {γ : α → Type*} (f : Sigma γ → β) : range f = ⋃ a, range fun b => f ⟨a, b⟩ := Set.ext <| by simp theorem iUnion_eq_range_sigma (s : α → Set β) : ⋃ i, s i = range fun a : Σi, s i => a.2 := by simp [Set.ext_iff] theorem iUnion_eq_range_psigma (s : ι → Set β) : ⋃ i, s i = range fun a : Σ'i, s i => a.2 := by simp [Set.ext_iff] theorem iUnion_image_preimage_sigma_mk_eq_self {ι : Type*} {σ : ι → Type*} (s : Set (Sigma σ)) : ⋃ i, Sigma.mk i '' (Sigma.mk i ⁻¹' s) = s := by ext x simp only [mem_iUnion, mem_image, mem_preimage] constructor · rintro ⟨i, a, h, rfl⟩ exact h · intro h obtain ⟨i, a⟩ := x exact ⟨i, a, h, rfl⟩ theorem Sigma.univ (X : α → Type*) : (Set.univ : Set (Σa, X a)) = ⋃ a, range (Sigma.mk a) := Set.ext fun x => iff_of_true trivial ⟨range (Sigma.mk x.1), Set.mem_range_self _, x.2, Sigma.eta x⟩ alias sUnion_mono := sUnion_subset_sUnion alias sInter_mono := sInter_subset_sInter theorem iUnion_subset_iUnion_const {s : Set α} (h : ι → ι₂) : ⋃ _ : ι, s ⊆ ⋃ _ : ι₂, s := iSup_const_mono (α := Set α) h @[simp] theorem iUnion_singleton_eq_range (f : α → β) : ⋃ x : α, {f x} = range f := by ext x simp [@eq_comm _ x] theorem iUnion_insert_eq_range_union_iUnion {ι : Type*} (x : ι → β) (t : ι → Set β) : ⋃ i, insert (x i) (t i) = range x ∪ ⋃ i, t i := by simp_rw [← union_singleton, iUnion_union_distrib, union_comm, iUnion_singleton_eq_range] theorem iUnion_of_singleton (α : Type*) : (⋃ x, {x} : Set α) = univ := by simp [Set.ext_iff] theorem iUnion_of_singleton_coe (s : Set α) : ⋃ i : s, ({(i : α)} : Set α) = s := by simp theorem sUnion_eq_biUnion {s : Set (Set α)} : ⋃₀ s = ⋃ (i : Set α) (_ : i ∈ s), i := by rw [← sUnion_image, image_id'] theorem sInter_eq_biInter {s : Set (Set α)} : ⋂₀ s = ⋂ (i : Set α) (_ : i ∈ s), i := by rw [← sInter_image, image_id'] theorem sUnion_eq_iUnion {s : Set (Set α)} : ⋃₀ s = ⋃ i : s, i := by simp only [← sUnion_range, Subtype.range_coe] theorem sInter_eq_iInter {s : Set (Set α)} : ⋂₀ s = ⋂ i : s, i := by simp only [← sInter_range, Subtype.range_coe] @[simp] theorem iUnion_of_empty [IsEmpty ι] (s : ι → Set α) : ⋃ i, s i = ∅ := iSup_of_empty _ @[simp] theorem iInter_of_empty [IsEmpty ι] (s : ι → Set α) : ⋂ i, s i = univ := iInf_of_empty _ theorem union_eq_iUnion {s₁ s₂ : Set α} : s₁ ∪ s₂ = ⋃ b : Bool, cond b s₁ s₂ := sup_eq_iSup s₁ s₂ theorem inter_eq_iInter {s₁ s₂ : Set α} : s₁ ∩ s₂ = ⋂ b : Bool, cond b s₁ s₂ := inf_eq_iInf s₁ s₂ theorem sInter_union_sInter {S T : Set (Set α)} : ⋂₀ S ∪ ⋂₀ T = ⋂ p ∈ S ×ˢ T, (p : Set α × Set α).1 ∪ p.2 := sInf_sup_sInf theorem sUnion_inter_sUnion {s t : Set (Set α)} : ⋃₀ s ∩ ⋃₀ t = ⋃ p ∈ s ×ˢ t, (p : Set α × Set α).1 ∩ p.2 := sSup_inf_sSup theorem biUnion_iUnion (s : ι → Set α) (t : α → Set β) : ⋃ x ∈ ⋃ i, s i, t x = ⋃ (i) (x ∈ s i), t x := by simp [@iUnion_comm _ ι] theorem biInter_iUnion (s : ι → Set α) (t : α → Set β) : ⋂ x ∈ ⋃ i, s i, t x = ⋂ (i) (x ∈ s i), t x := by simp [@iInter_comm _ ι] theorem sUnion_iUnion (s : ι → Set (Set α)) : ⋃₀ ⋃ i, s i = ⋃ i, ⋃₀ s i := by simp only [sUnion_eq_biUnion, biUnion_iUnion] theorem sInter_iUnion (s : ι → Set (Set α)) : ⋂₀ ⋃ i, s i = ⋂ i, ⋂₀ s i := by simp only [sInter_eq_biInter, biInter_iUnion] theorem iUnion_range_eq_sUnion {α β : Type*} (C : Set (Set α)) {f : ∀ s : C, β → (s : Type _)} (hf : ∀ s : C, Surjective (f s)) : ⋃ y : β, range (fun s : C => (f s y).val) = ⋃₀ C := by ext x; constructor · rintro ⟨s, ⟨y, rfl⟩, ⟨s, hs⟩, rfl⟩ refine ⟨_, hs, ?_⟩ exact (f ⟨s, hs⟩ y).2 · rintro ⟨s, hs, hx⟩ obtain ⟨y, hy⟩ := hf ⟨s, hs⟩ ⟨x, hx⟩ refine ⟨_, ⟨y, rfl⟩, ⟨s, hs⟩, ?_⟩ exact congr_arg Subtype.val hy theorem iUnion_range_eq_iUnion (C : ι → Set α) {f : ∀ x : ι, β → C x} (hf : ∀ x : ι, Surjective (f x)) : ⋃ y : β, range (fun x : ι => (f x y).val) = ⋃ x, C x := by ext x; rw [mem_iUnion, mem_iUnion]; constructor · rintro ⟨y, i, rfl⟩ exact ⟨i, (f i y).2⟩ · rintro ⟨i, hx⟩ obtain ⟨y, hy⟩ := hf i ⟨x, hx⟩ exact ⟨y, i, congr_arg Subtype.val hy⟩ theorem union_distrib_iInter_left (s : ι → Set α) (t : Set α) : (t ∪ ⋂ i, s i) = ⋂ i, t ∪ s i := sup_iInf_eq _ _ theorem union_distrib_iInter₂_left (s : Set α) (t : ∀ i, κ i → Set α) : (s ∪ ⋂ (i) (j), t i j) = ⋂ (i) (j), s ∪ t i j := by simp_rw [union_distrib_iInter_left] theorem union_distrib_iInter_right (s : ι → Set α) (t : Set α) : (⋂ i, s i) ∪ t = ⋂ i, s i ∪ t := iInf_sup_eq _ _ theorem union_distrib_iInter₂_right (s : ∀ i, κ i → Set α) (t : Set α) : (⋂ (i) (j), s i j) ∪ t = ⋂ (i) (j), s i j ∪ t := by simp_rw [union_distrib_iInter_right] lemma biUnion_lt_eq_iUnion [LT α] [NoMaxOrder α] {s : α → Set β} : ⋃ (n) (m < n), s m = ⋃ n, s n := biSup_lt_eq_iSup lemma biUnion_le_eq_iUnion [Preorder α] {s : α → Set β} : ⋃ (n) (m ≤ n), s m = ⋃ n, s n := biSup_le_eq_iSup lemma biInter_lt_eq_iInter [LT α] [NoMaxOrder α] {s : α → Set β} : ⋂ (n) (m < n), s m = ⋂ (n), s n := biInf_lt_eq_iInf lemma biInter_le_eq_iInter [Preorder α] {s : α → Set β} : ⋂ (n) (m ≤ n), s m = ⋂ (n), s n := biInf_le_eq_iInf lemma biUnion_gt_eq_iUnion [LT α] [NoMinOrder α] {s : α → Set β} : ⋃ (n) (m > n), s m = ⋃ n, s n := biSup_gt_eq_iSup lemma biUnion_ge_eq_iUnion [Preorder α] {s : α → Set β} : ⋃ (n) (m ≥ n), s m = ⋃ n, s n := biSup_ge_eq_iSup lemma biInter_gt_eq_iInf [LT α] [NoMinOrder α] {s : α → Set β} : ⋂ (n) (m > n), s m = ⋂ n, s n := biInf_gt_eq_iInf lemma biInter_ge_eq_iInf [Preorder α] {s : α → Set β} : ⋂ (n) (m ≥ n), s m = ⋂ n, s n := biInf_ge_eq_iInf section le variable {ι : Type*} [PartialOrder ι] (s : ι → Set α) (i : ι) theorem biUnion_le : (⋃ j ≤ i, s j) = (⋃ j < i, s j) ∪ s i := biSup_le_eq_sup s i theorem biInter_le : (⋂ j ≤ i, s j) = (⋂ j < i, s j) ∩ s i := biInf_le_eq_inf s i theorem biUnion_ge : (⋃ j ≥ i, s j) = s i ∪ ⋃ j > i, s j := biSup_ge_eq_sup s i theorem biInter_ge : (⋂ j ≥ i, s j) = s i ∩ ⋂ j > i, s j := biInf_ge_eq_inf s i end le section Pi variable {π : α → Type*} theorem pi_def (i : Set α) (s : ∀ a, Set (π a)) : pi i s = ⋂ a ∈ i, eval a ⁻¹' s a := by ext simp theorem univ_pi_eq_iInter (t : ∀ i, Set (π i)) : pi univ t = ⋂ i, eval i ⁻¹' t i := by simp only [pi_def, iInter_true, mem_univ] theorem pi_diff_pi_subset (i : Set α) (s t : ∀ a, Set (π a)) : pi i s \ pi i t ⊆ ⋃ a ∈ i, eval a ⁻¹' (s a \ t a) := by refine diff_subset_comm.2 fun x hx a ha => ?_ simp only [mem_diff, mem_pi, mem_iUnion, not_exists, mem_preimage, not_and, not_not, eval_apply] at hx exact hx.2 _ ha (hx.1 _ ha) theorem iUnion_univ_pi {ι : α → Type*} (t : (a : α) → ι a → Set (π a)) : ⋃ x : (a : α) → ι a, pi univ (fun a => t a (x a)) = pi univ fun a => ⋃ j : ι a, t a j := by ext simp [Classical.skolem] end Pi section Directed theorem directedOn_iUnion {r} {f : ι → Set α} (hd : Directed (· ⊆ ·) f) (h : ∀ x, DirectedOn r (f x)) : DirectedOn r (⋃ x, f x) := by simp only [DirectedOn, exists_prop, mem_iUnion, exists_imp] exact fun a₁ b₁ fb₁ a₂ b₂ fb₂ => let ⟨z, zb₁, zb₂⟩ := hd b₁ b₂ let ⟨x, xf, xa₁, xa₂⟩ := h z a₁ (zb₁ fb₁) a₂ (zb₂ fb₂) ⟨x, ⟨z, xf⟩, xa₁, xa₂⟩ theorem directedOn_sUnion {r} {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S) (h : ∀ x ∈ S, DirectedOn r x) : DirectedOn r (⋃₀ S) := by rw [sUnion_eq_iUnion] exact directedOn_iUnion (directedOn_iff_directed.mp hd) (fun i ↦ h i.1 i.2) theorem pairwise_iUnion₂ {S : Set (Set α)} (hd : DirectedOn (· ⊆ ·) S) (r : α → α → Prop) (h : ∀ s ∈ S, s.Pairwise r) : (⋃ s ∈ S, s).Pairwise r := by simp only [Set.Pairwise, Set.mem_iUnion, exists_prop, forall_exists_index, and_imp] intro x S hS hx y T hT hy hne obtain ⟨U, hU, hSU, hTU⟩ := hd S hS T hT exact h U hU (hSU hx) (hTU hy) hne end Directed end Set namespace Function namespace Surjective theorem iUnion_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋃ x, g (f x) = ⋃ y, g y := hf.iSup_comp g theorem iInter_comp {f : ι → ι₂} (hf : Surjective f) (g : ι₂ → Set α) : ⋂ x, g (f x) = ⋂ y, g y := hf.iInf_comp g end Surjective end Function /-! ### Disjoint sets -/ section Disjoint variable {s t : Set α} namespace Set @[simp] theorem disjoint_iUnion_left {ι : Sort*} {s : ι → Set α} : Disjoint (⋃ i, s i) t ↔ ∀ i, Disjoint (s i) t := iSup_disjoint_iff @[simp] theorem disjoint_iUnion_right {ι : Sort*} {s : ι → Set α} : Disjoint t (⋃ i, s i) ↔ ∀ i, Disjoint t (s i) := disjoint_iSup_iff theorem disjoint_iUnion₂_left {s : ∀ i, κ i → Set α} {t : Set α} : Disjoint (⋃ (i) (j), s i j) t ↔ ∀ i j, Disjoint (s i j) t := iSup₂_disjoint_iff theorem disjoint_iUnion₂_right {s : Set α} {t : ∀ i, κ i → Set α} : Disjoint s (⋃ (i) (j), t i j) ↔ ∀ i j, Disjoint s (t i j) := disjoint_iSup₂_iff @[simp] theorem disjoint_sUnion_left {S : Set (Set α)} {t : Set α} : Disjoint (⋃₀ S) t ↔ ∀ s ∈ S, Disjoint s t := sSup_disjoint_iff @[simp] theorem disjoint_sUnion_right {s : Set α} {S : Set (Set α)} : Disjoint s (⋃₀ S) ↔ ∀ t ∈ S, Disjoint s t := disjoint_sSup_iff lemma biUnion_compl_eq_of_pairwise_disjoint_of_iUnion_eq_univ {ι : Type*} {Es : ι → Set α} (Es_union : ⋃ i, Es i = univ) (Es_disj : Pairwise fun i j ↦ Disjoint (Es i) (Es j)) (I : Set ι) : (⋃ i ∈ I, Es i)ᶜ = ⋃ i ∈ Iᶜ, Es i := by ext x obtain ⟨i, hix⟩ : ∃ i, x ∈ Es i := by simp [← mem_iUnion, Es_union] have obs : ∀ (J : Set ι), x ∈ ⋃ j ∈ J, Es j ↔ i ∈ J := by refine fun J ↦ ⟨?_, fun i_in_J ↦ by simpa only [mem_iUnion, exists_prop] using ⟨i, i_in_J, hix⟩⟩ intro x_in_U simp only [mem_iUnion, exists_prop] at x_in_U obtain ⟨j, j_in_J, hjx⟩ := x_in_U rwa [show i = j by by_contra i_ne_j; exact Disjoint.ne_of_mem (Es_disj i_ne_j) hix hjx rfl] have obs' : ∀ (J : Set ι), x ∈ (⋃ j ∈ J, Es j)ᶜ ↔ i ∉ J := fun J ↦ by simpa only [mem_compl_iff, not_iff_not] using obs J rw [obs, obs', mem_compl_iff] end Set end Disjoint /-! ### Intervals -/ namespace Set lemma nonempty_iInter_Iic_iff [Preorder α] {f : ι → α} : (⋂ i, Iic (f i)).Nonempty ↔ BddBelow (range f) := by have : (⋂ (i : ι), Iic (f i)) = lowerBounds (range f) := by ext c; simp [lowerBounds] simp [this, BddBelow] lemma nonempty_iInter_Ici_iff [Preorder α] {f : ι → α} : (⋂ i, Ici (f i)).Nonempty ↔ BddAbove (range f) := nonempty_iInter_Iic_iff (α := αᵒᵈ) variable [CompleteLattice α] theorem Ici_iSup (f : ι → α) : Ici (⨆ i, f i) = ⋂ i, Ici (f i) :=
ext fun _ => by simp only [mem_Ici, iSup_le_iff, mem_iInter]
Mathlib/Data/Set/Lattice.lean
1,264
1,265
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Johannes Hölzl -/ import Mathlib.MeasureTheory.Integral.Lebesgue.Basic import Mathlib.MeasureTheory.Integral.Lebesgue.Countable import Mathlib.MeasureTheory.Integral.Lebesgue.MeasurePreserving import Mathlib.MeasureTheory.Integral.Lebesgue.Norm deprecated_module (since := "2025-04-13")
Mathlib/MeasureTheory/Integral/Lebesgue.lean
1,949
1,960
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Data.ENNReal.Basic /-! # Maps between real and extended non-negative real numbers This file focuses on the functions `ENNReal.toReal : ℝ≥0∞ → ℝ` and `ENNReal.ofReal : ℝ → ℝ≥0∞` which were defined in `Data.ENNReal.Basic`. It collects all the basic results of the interactions between these functions and the algebraic and lattice operations, although a few may appear in earlier files. This file provides a `positivity` extension for `ENNReal.ofReal`. # Main theorems - `trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal`: often used for `WithLp` and `lp` - `dichotomy (p : ℝ≥0∞) [Fact (1 ≤ p)] : p = ∞ ∨ 1 ≤ p.toReal`: often used for `WithLp` and `lp` - `toNNReal_iInf` through `toReal_sSup`: these declarations allow for easy conversions between indexed or set infima and suprema in `ℝ`, `ℝ≥0` and `ℝ≥0∞`. This is especially useful because `ℝ≥0∞` is a complete lattice. -/ assert_not_exists Finset open Set NNReal ENNReal namespace ENNReal section Real variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} theorem toReal_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a + b).toReal = a.toReal + b.toReal := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb rfl theorem toReal_add_le : (a + b).toReal ≤ a.toReal + b.toReal := if ha : a = ∞ then by simp only [ha, top_add, toReal_top, zero_add, toReal_nonneg] else if hb : b = ∞ then by simp only [hb, add_top, toReal_top, add_zero, toReal_nonneg] else le_of_eq (toReal_add ha hb) theorem ofReal_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal (p + q) = ENNReal.ofReal p + ENNReal.ofReal q := by rw [ENNReal.ofReal, ENNReal.ofReal, ENNReal.ofReal, ← coe_add, coe_inj, Real.toNNReal_add hp hq] theorem ofReal_add_le {p q : ℝ} : ENNReal.ofReal (p + q) ≤ ENNReal.ofReal p + ENNReal.ofReal q := coe_le_coe.2 Real.toNNReal_add_le @[simp] theorem toReal_le_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal ≤ b.toReal ↔ a ≤ b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast @[gcongr] theorem toReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toReal ≤ b.toReal := (toReal_le_toReal (ne_top_of_le_ne_top hb h) hb).2 h theorem toReal_mono' (h : a ≤ b) (ht : b = ∞ → a = ∞) : a.toReal ≤ b.toReal := by rcases eq_or_ne a ∞ with rfl | ha · exact toReal_nonneg · exact toReal_mono (mt ht ha) h @[simp] theorem toReal_lt_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal < b.toReal ↔ a < b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb norm_cast @[gcongr] theorem toReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toReal < b.toReal := (toReal_lt_toReal h.ne_top hb).2 h @[gcongr] theorem toNNReal_mono (hb : b ≠ ∞) (h : a ≤ b) : a.toNNReal ≤ b.toNNReal := toReal_mono hb h theorem le_toNNReal_of_coe_le (h : p ≤ a) (ha : a ≠ ∞) : p ≤ a.toNNReal := @toNNReal_coe p ▸ toNNReal_mono ha h @[simp] theorem toNNReal_le_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal ≤ b.toNNReal ↔ a ≤ b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_le_coe], toNNReal_mono hb⟩ @[gcongr] theorem toNNReal_strict_mono (hb : b ≠ ∞) (h : a < b) : a.toNNReal < b.toNNReal := by simpa [← ENNReal.coe_lt_coe, hb, h.ne_top] @[simp] theorem toNNReal_lt_toNNReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toNNReal < b.toNNReal ↔ a < b := ⟨fun h => by rwa [← coe_toNNReal ha, ← coe_toNNReal hb, coe_lt_coe], toNNReal_strict_mono hb⟩ theorem toNNReal_lt_of_lt_coe (h : a < p) : a.toNNReal < p := @toNNReal_coe p ▸ toNNReal_strict_mono coe_ne_top h theorem toReal_max (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (max a b) = max (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, max_eq_right]) fun h => by simp only [h, ENNReal.toReal_mono hr h, max_eq_left] theorem toReal_min {a b : ℝ≥0∞} (hr : a ≠ ∞) (hp : b ≠ ∞) : ENNReal.toReal (min a b) = min (ENNReal.toReal a) (ENNReal.toReal b) := (le_total a b).elim (fun h => by simp only [h, ENNReal.toReal_mono hp h, min_eq_left]) fun h => by simp only [h, ENNReal.toReal_mono hr h, min_eq_right] theorem toReal_sup {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊔ b).toReal = a.toReal ⊔ b.toReal := toReal_max theorem toReal_inf {a b : ℝ≥0∞} : a ≠ ∞ → b ≠ ∞ → (a ⊓ b).toReal = a.toReal ⊓ b.toReal := toReal_min theorem toNNReal_pos_iff : 0 < a.toNNReal ↔ 0 < a ∧ a < ∞ := by induction a <;> simp theorem toNNReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toNNReal := toNNReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ theorem toReal_pos_iff : 0 < a.toReal ↔ 0 < a ∧ a < ∞ := NNReal.coe_pos.trans toNNReal_pos_iff theorem toReal_pos {a : ℝ≥0∞} (ha₀ : a ≠ 0) (ha_top : a ≠ ∞) : 0 < a.toReal := toReal_pos_iff.mpr ⟨bot_lt_iff_ne_bot.mpr ha₀, lt_top_iff_ne_top.mpr ha_top⟩ @[gcongr, bound] theorem ofReal_le_ofReal {p q : ℝ} (h : p ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q := by simp [ENNReal.ofReal, Real.toNNReal_le_toNNReal h] theorem ofReal_le_of_le_toReal {a : ℝ} {b : ℝ≥0∞} (h : a ≤ ENNReal.toReal b) : ENNReal.ofReal a ≤ b := (ofReal_le_ofReal h).trans ofReal_toReal_le @[simp] theorem ofReal_le_ofReal_iff {p q : ℝ} (h : 0 ≤ q) : ENNReal.ofReal p ≤ ENNReal.ofReal q ↔ p ≤ q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_le_coe, Real.toNNReal_le_toNNReal_iff h] lemma ofReal_le_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p ≤ .ofReal q ↔ p ≤ q ∨ p ≤ 0 := coe_le_coe.trans Real.toNNReal_le_toNNReal_iff' lemma ofReal_lt_ofReal_iff' {p q : ℝ} : ENNReal.ofReal p < .ofReal q ↔ p < q ∧ 0 < q := coe_lt_coe.trans Real.toNNReal_lt_toNNReal_iff' @[simp] theorem ofReal_eq_ofReal_iff {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ENNReal.ofReal p = ENNReal.ofReal q ↔ p = q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_inj, Real.toNNReal_eq_toNNReal_iff hp hq] @[simp] theorem ofReal_lt_ofReal_iff {p q : ℝ} (h : 0 < q) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff h] theorem ofReal_lt_ofReal_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) : ENNReal.ofReal p < ENNReal.ofReal q ↔ p < q := by rw [ENNReal.ofReal, ENNReal.ofReal, coe_lt_coe, Real.toNNReal_lt_toNNReal_iff_of_nonneg hp] @[simp] theorem ofReal_pos {p : ℝ} : 0 < ENNReal.ofReal p ↔ 0 < p := by simp [ENNReal.ofReal] @[bound] private alias ⟨_, Bound.ofReal_pos_of_pos⟩ := ofReal_pos @[simp] theorem ofReal_eq_zero {p : ℝ} : ENNReal.ofReal p = 0 ↔ p ≤ 0 := by simp [ENNReal.ofReal] theorem ofReal_ne_zero_iff {r : ℝ} : ENNReal.ofReal r ≠ 0 ↔ 0 < r := by rw [← zero_lt_iff, ENNReal.ofReal_pos] @[simp] theorem zero_eq_ofReal {p : ℝ} : 0 = ENNReal.ofReal p ↔ p ≤ 0 := eq_comm.trans ofReal_eq_zero alias ⟨_, ofReal_of_nonpos⟩ := ofReal_eq_zero @[simp] lemma ofReal_lt_natCast {p : ℝ} {n : ℕ} (hn : n ≠ 0) : ENNReal.ofReal p < n ↔ p < n := by exact mod_cast ofReal_lt_ofReal_iff (Nat.cast_pos.2 hn.bot_lt) @[simp] lemma ofReal_lt_one {p : ℝ} : ENNReal.ofReal p < 1 ↔ p < 1 := by exact mod_cast ofReal_lt_natCast one_ne_zero @[simp] lemma ofReal_lt_ofNat {p : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal p < ofNat(n) ↔ p < OfNat.ofNat n := ofReal_lt_natCast (NeZero.ne n) @[simp] lemma natCast_le_ofReal {n : ℕ} {p : ℝ} (hn : n ≠ 0) : n ≤ ENNReal.ofReal p ↔ n ≤ p := by simp only [← not_lt, ofReal_lt_natCast hn] @[simp] lemma one_le_ofReal {p : ℝ} : 1 ≤ ENNReal.ofReal p ↔ 1 ≤ p := by exact mod_cast natCast_le_ofReal one_ne_zero @[simp] lemma ofNat_le_ofReal {n : ℕ} [n.AtLeastTwo] {p : ℝ} : ofNat(n) ≤ ENNReal.ofReal p ↔ OfNat.ofNat n ≤ p := natCast_le_ofReal (NeZero.ne n) @[simp, norm_cast] lemma ofReal_le_natCast {r : ℝ} {n : ℕ} : ENNReal.ofReal r ≤ n ↔ r ≤ n := coe_le_coe.trans Real.toNNReal_le_natCast @[simp] lemma ofReal_le_one {r : ℝ} : ENNReal.ofReal r ≤ 1 ↔ r ≤ 1 := coe_le_coe.trans Real.toNNReal_le_one @[simp] lemma ofReal_le_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal r ≤ ofNat(n) ↔ r ≤ OfNat.ofNat n := ofReal_le_natCast @[simp] lemma natCast_lt_ofReal {n : ℕ} {r : ℝ} : n < ENNReal.ofReal r ↔ n < r := coe_lt_coe.trans Real.natCast_lt_toNNReal @[simp] lemma one_lt_ofReal {r : ℝ} : 1 < ENNReal.ofReal r ↔ 1 < r := coe_lt_coe.trans Real.one_lt_toNNReal @[simp] lemma ofNat_lt_ofReal {n : ℕ} [n.AtLeastTwo] {r : ℝ} : ofNat(n) < ENNReal.ofReal r ↔ OfNat.ofNat n < r := natCast_lt_ofReal @[simp] lemma ofReal_eq_natCast {r : ℝ} {n : ℕ} (h : n ≠ 0) : ENNReal.ofReal r = n ↔ r = n := ENNReal.coe_inj.trans <| Real.toNNReal_eq_natCast h @[simp] lemma ofReal_eq_one {r : ℝ} : ENNReal.ofReal r = 1 ↔ r = 1 := ENNReal.coe_inj.trans Real.toNNReal_eq_one @[simp] lemma ofReal_eq_ofNat {r : ℝ} {n : ℕ} [n.AtLeastTwo] : ENNReal.ofReal r = ofNat(n) ↔ r = OfNat.ofNat n := ofReal_eq_natCast (NeZero.ne n) theorem ofReal_le_iff_le_toReal {a : ℝ} {b : ℝ≥0∞} (hb : b ≠ ∞) : ENNReal.ofReal a ≤ b ↔ a ≤ ENNReal.toReal b := by lift b to ℝ≥0 using hb simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_le_iff_le_coe theorem ofReal_lt_iff_lt_toReal {a : ℝ} {b : ℝ≥0∞} (ha : 0 ≤ a) (hb : b ≠ ∞) : ENNReal.ofReal a < b ↔ a < ENNReal.toReal b := by lift b to ℝ≥0 using hb simpa [ENNReal.ofReal, ENNReal.toReal] using Real.toNNReal_lt_iff_lt_coe ha theorem ofReal_lt_coe_iff {a : ℝ} {b : ℝ≥0} (ha : 0 ≤ a) : ENNReal.ofReal a < b ↔ a < b := (ofReal_lt_iff_lt_toReal ha coe_ne_top).trans <| by rw [coe_toReal] theorem le_ofReal_iff_toReal_le {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) (hb : 0 ≤ b) : a ≤ ENNReal.ofReal b ↔ ENNReal.toReal a ≤ b := by lift a to ℝ≥0 using ha simpa [ENNReal.ofReal, ENNReal.toReal] using Real.le_toNNReal_iff_coe_le hb theorem toReal_le_of_le_ofReal {a : ℝ≥0∞} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ENNReal.ofReal b) : ENNReal.toReal a ≤ b := have ha : a ≠ ∞ := ne_top_of_le_ne_top ofReal_ne_top h (le_ofReal_iff_toReal_le ha hb).1 h theorem lt_ofReal_iff_toReal_lt {a : ℝ≥0∞} {b : ℝ} (ha : a ≠ ∞) : a < ENNReal.ofReal b ↔ ENNReal.toReal a < b := by lift a to ℝ≥0 using ha simpa [ENNReal.ofReal, ENNReal.toReal] using Real.lt_toNNReal_iff_coe_lt theorem toReal_lt_of_lt_ofReal {b : ℝ} (h : a < ENNReal.ofReal b) : ENNReal.toReal a < b := (lt_ofReal_iff_toReal_lt h.ne_top).1 h theorem ofReal_mul {p q : ℝ} (hp : 0 ≤ p) : ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by simp only [ENNReal.ofReal, ← coe_mul, Real.toNNReal_mul hp] theorem ofReal_mul' {p q : ℝ} (hq : 0 ≤ q) : ENNReal.ofReal (p * q) = ENNReal.ofReal p * ENNReal.ofReal q := by rw [mul_comm, ofReal_mul hq, mul_comm] theorem ofReal_pow {p : ℝ} (hp : 0 ≤ p) (n : ℕ) : ENNReal.ofReal (p ^ n) = ENNReal.ofReal p ^ n := by rw [ofReal_eq_coe_nnreal hp, ← coe_pow, ← ofReal_coe_nnreal, NNReal.coe_pow, NNReal.coe_mk] theorem ofReal_nsmul {x : ℝ} {n : ℕ} : ENNReal.ofReal (n • x) = n • ENNReal.ofReal x := by simp only [nsmul_eq_mul, ← ofReal_natCast n, ← ofReal_mul n.cast_nonneg] @[simp] theorem toNNReal_mul {a b : ℝ≥0∞} : (a * b).toNNReal = a.toNNReal * b.toNNReal := WithTop.untopD_zero_mul a b theorem toNNReal_mul_top (a : ℝ≥0∞) : ENNReal.toNNReal (a * ∞) = 0 := by simp theorem toNNReal_top_mul (a : ℝ≥0∞) : ENNReal.toNNReal (∞ * a) = 0 := by simp /-- `ENNReal.toNNReal` as a `MonoidHom`. -/ def toNNRealHom : ℝ≥0∞ →*₀ ℝ≥0 where toFun := ENNReal.toNNReal map_one' := toNNReal_coe _ map_mul' _ _ := toNNReal_mul map_zero' := toNNReal_zero @[simp] theorem toNNReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toNNReal = a.toNNReal ^ n := toNNRealHom.map_pow a n /-- `ENNReal.toReal` as a `MonoidHom`. -/ def toRealHom : ℝ≥0∞ →*₀ ℝ := (NNReal.toRealHom : ℝ≥0 →*₀ ℝ).comp toNNRealHom @[simp] theorem toReal_mul : (a * b).toReal = a.toReal * b.toReal := toRealHom.map_mul a b theorem toReal_nsmul (a : ℝ≥0∞) (n : ℕ) : (n • a).toReal = n • a.toReal := by simp @[simp] theorem toReal_pow (a : ℝ≥0∞) (n : ℕ) : (a ^ n).toReal = a.toReal ^ n := toRealHom.map_pow a n theorem toReal_ofReal_mul (c : ℝ) (a : ℝ≥0∞) (h : 0 ≤ c) : ENNReal.toReal (ENNReal.ofReal c * a) = c * ENNReal.toReal a := by rw [ENNReal.toReal_mul, ENNReal.toReal_ofReal h] theorem toReal_mul_top (a : ℝ≥0∞) : ENNReal.toReal (a * ∞) = 0 := by rw [toReal_mul, toReal_top, mul_zero] theorem toReal_top_mul (a : ℝ≥0∞) : ENNReal.toReal (∞ * a) = 0 := by rw [mul_comm] exact toReal_mul_top _ theorem toReal_eq_toReal (ha : a ≠ ∞) (hb : b ≠ ∞) : a.toReal = b.toReal ↔ a = b := by lift a to ℝ≥0 using ha lift b to ℝ≥0 using hb simp only [coe_inj, NNReal.coe_inj, coe_toReal] protected theorem trichotomy (p : ℝ≥0∞) : p = 0 ∨ p = ∞ ∨ 0 < p.toReal := by simpa only [or_iff_not_imp_left] using toReal_pos protected theorem trichotomy₂ {p q : ℝ≥0∞} (hpq : p ≤ q) : p = 0 ∧ q = 0 ∨ p = 0 ∧ q = ∞ ∨ p = 0 ∧ 0 < q.toReal ∨ p = ∞ ∧ q = ∞ ∨ 0 < p.toReal ∧ q = ∞ ∨ 0 < p.toReal ∧ 0 < q.toReal ∧ p.toReal ≤ q.toReal := by rcases eq_or_lt_of_le (bot_le : 0 ≤ p) with ((rfl : 0 = p) | (hp : 0 < p)) · simpa using q.trichotomy rcases eq_or_lt_of_le (le_top : q ≤ ∞) with (rfl | hq)
· simpa using p.trichotomy repeat' right have hq' : 0 < q := lt_of_lt_of_le hp hpq
Mathlib/Data/ENNReal/Real.lean
353
355
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury Kudryashov -/ import Mathlib.Algebra.Order.Ring.WithTop import Mathlib.Algebra.Order.Sub.WithTop import Mathlib.Data.NNReal.Defs import Mathlib.Order.Interval.Set.WithBotTop /-! # Extended non-negative reals We define `ENNReal = ℝ≥0∞ := WithTop ℝ≥0` to be the type of extended nonnegative real numbers, i.e., the interval `[0, +∞]`. This type is used as the codomain of a `MeasureTheory.Measure`, and of the extended distance `edist` in an `EMetricSpace`. In this file we set up many of the instances on `ℝ≥0∞`, and provide relationships between `ℝ≥0∞` and `ℝ≥0`, and between `ℝ≥0∞` and `ℝ`. In particular, we provide a coercion from `ℝ≥0` to `ℝ≥0∞` as well as functions `ENNReal.toNNReal`, `ENNReal.ofReal` and `ENNReal.toReal`, all of which take the value zero wherever they cannot be the identity. Also included is the relationship between `ℝ≥0∞` and `ℕ`. The interaction of these functions, especially `ENNReal.ofReal` and `ENNReal.toReal`, with the algebraic and lattice structure can be found in `Data.ENNReal.Real`. This file proves many of the order properties of `ℝ≥0∞`, with the exception of the ways those relate to the algebraic structure, which are included in `Data.ENNReal.Operations`. This file also defines inversion and division: this includes `Inv` and `Div` instances on `ℝ≥0∞` making it into a `DivInvOneMonoid`. As a consequence of being a `DivInvOneMonoid`, `ℝ≥0∞` inherits a power operation with integer exponent: this and other properties is shown in `Data.ENNReal.Inv`. ## Main definitions * `ℝ≥0∞`: the extended nonnegative real numbers `[0, ∞]`; defined as `WithTop ℝ≥0`; it is equipped with the following structures: - coercion from `ℝ≥0` defined in the natural way; - the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`; - `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`; - `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a * ∞ = ∞ * a = ∞` for `a ≠ 0`; - `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have `↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only subtraction; The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn `ℝ≥0∞` into a canonically ordered commutative semiring of characteristic zero. - `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for `p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`. - `a / b` is defined as `a * b⁻¹`. This inversion and division include `Inv` and `Div` instances on `ℝ≥0∞`, making it into a `DivInvOneMonoid`. Further properties of these are shown in `Data.ENNReal.Inv`. * Coercions to/from other types: - coercion `ℝ≥0 → ℝ≥0∞` is defined as `Coe`, so one can use `(p : ℝ≥0)` in a context that expects `a : ℝ≥0∞`, and Lean will apply `coe` automatically; - `ENNReal.toNNReal` sends `↑p` to `p` and `∞` to `0`; - `ENNReal.toReal := coe ∘ ENNReal.toNNReal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`; - `ENNReal.ofReal := coe ∘ Real.toNNReal` sends `x : ℝ` to `↑⟨max x 0, _⟩` - `ENNReal.neTopEquivNNReal` is an equivalence between `{a : ℝ≥0∞ // a ≠ 0}` and `ℝ≥0`. ## Implementation notes We define a `CanLift ℝ≥0∞ ℝ≥0` instance, so one of the ways to prove theorems about an `ℝ≥0∞` number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha` in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the context, or if we have `(f : α → ℝ≥0∞) (hf : ∀ x, f x ≠ ∞)`. ## Notations * `ℝ≥0∞`: the type of the extended nonnegative real numbers; * `ℝ≥0`: the type of nonnegative real numbers `[0, ∞)`; defined in `Data.Real.NNReal`; * `∞`: a localized notation in `ENNReal` for `⊤ : ℝ≥0∞`. -/ assert_not_exists Finset open Function Set NNReal variable {α : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ def ENNReal := WithTop ℝ≥0 deriving Zero, Top, AddCommMonoidWithOne, SemilatticeSup, DistribLattice, Nontrivial @[inherit_doc] scoped[ENNReal] notation "ℝ≥0∞" => ENNReal /-- Notation for infinity as an `ENNReal` number. -/ scoped[ENNReal] notation "∞" => (⊤ : ENNReal) namespace ENNReal instance : OrderBot ℝ≥0∞ := inferInstanceAs (OrderBot (WithTop ℝ≥0)) instance : OrderTop ℝ≥0∞ := inferInstanceAs (OrderTop (WithTop ℝ≥0)) instance : BoundedOrder ℝ≥0∞ := inferInstanceAs (BoundedOrder (WithTop ℝ≥0)) instance : CharZero ℝ≥0∞ := inferInstanceAs (CharZero (WithTop ℝ≥0)) instance : Min ℝ≥0∞ := SemilatticeInf.toMin instance : Max ℝ≥0∞ := SemilatticeSup.toMax noncomputable instance : CommSemiring ℝ≥0∞ := inferInstanceAs (CommSemiring (WithTop ℝ≥0)) instance : PartialOrder ℝ≥0∞ := inferInstanceAs (PartialOrder (WithTop ℝ≥0)) instance : IsOrderedRing ℝ≥0∞ := inferInstanceAs (IsOrderedRing (WithTop ℝ≥0)) instance : CanonicallyOrderedAdd ℝ≥0∞ := inferInstanceAs (CanonicallyOrderedAdd (WithTop ℝ≥0)) instance : NoZeroDivisors ℝ≥0∞ := inferInstanceAs (NoZeroDivisors (WithTop ℝ≥0)) noncomputable instance : CompleteLinearOrder ℝ≥0∞ := inferInstanceAs (CompleteLinearOrder (WithTop ℝ≥0)) instance : DenselyOrdered ℝ≥0∞ := inferInstanceAs (DenselyOrdered (WithTop ℝ≥0)) instance : AddCommMonoid ℝ≥0∞ := inferInstanceAs (AddCommMonoid (WithTop ℝ≥0)) noncomputable instance : LinearOrder ℝ≥0∞ := inferInstanceAs (LinearOrder (WithTop ℝ≥0)) instance : IsOrderedAddMonoid ℝ≥0∞ := inferInstanceAs (IsOrderedAddMonoid (WithTop ℝ≥0)) instance instSub : Sub ℝ≥0∞ := inferInstanceAs (Sub (WithTop ℝ≥0)) instance : OrderedSub ℝ≥0∞ := inferInstanceAs (OrderedSub (WithTop ℝ≥0)) noncomputable instance : LinearOrderedAddCommMonoidWithTop ℝ≥0∞ := inferInstanceAs (LinearOrderedAddCommMonoidWithTop (WithTop ℝ≥0)) -- RFC: redefine using pattern matching? noncomputable instance : Inv ℝ≥0∞ := ⟨fun a => sInf { b | 1 ≤ a * b }⟩ noncomputable instance : DivInvMonoid ℝ≥0∞ where variable {a b c d : ℝ≥0∞} {r p q : ℝ≥0} -- TODO: add a `WithTop` instance and use it here noncomputable instance : LinearOrderedCommMonoidWithZero ℝ≥0∞ := { inferInstanceAs (LinearOrderedAddCommMonoidWithTop ℝ≥0∞), inferInstanceAs (CommSemiring ℝ≥0∞) with bot_le _ := bot_le mul_le_mul_left := fun _ _ => mul_le_mul_left' zero_le_one := zero_le 1 } instance : Unique (AddUnits ℝ≥0∞) where default := 0 uniq a := AddUnits.ext <| le_zero_iff.1 <| by rw [← a.add_neg]; exact le_self_add instance : Inhabited ℝ≥0∞ := ⟨0⟩ /-- Coercion from `ℝ≥0` to `ℝ≥0∞`. -/ @[coe, match_pattern] def ofNNReal : ℝ≥0 → ℝ≥0∞ := WithTop.some instance : Coe ℝ≥0 ℝ≥0∞ := ⟨ofNNReal⟩ /-- A version of `WithTop.recTopCoe` that uses `ENNReal.ofNNReal`. -/ @[elab_as_elim, induction_eliminator, cases_eliminator] def recTopCoe {C : ℝ≥0∞ → Sort*} (top : C ∞) (coe : ∀ x : ℝ≥0, C x) (x : ℝ≥0∞) : C x := WithTop.recTopCoe top coe x instance canLift : CanLift ℝ≥0∞ ℝ≥0 ofNNReal (· ≠ ∞) := WithTop.canLift @[simp] theorem none_eq_top : (none : ℝ≥0∞) = ∞ := rfl @[simp] theorem some_eq_coe (a : ℝ≥0) : (Option.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl @[simp] theorem some_eq_coe' (a : ℝ≥0) : (WithTop.some a : ℝ≥0∞) = (↑a : ℝ≥0∞) := rfl lemma coe_injective : Injective ((↑) : ℝ≥0 → ℝ≥0∞) := WithTop.coe_injective @[simp, norm_cast] lemma coe_inj : (p : ℝ≥0∞) = q ↔ p = q := coe_injective.eq_iff lemma coe_ne_coe : (p : ℝ≥0∞) ≠ q ↔ p ≠ q := coe_inj.not theorem range_coe' : range ofNNReal = Iio ∞ := WithTop.range_coe theorem range_coe : range ofNNReal = {∞}ᶜ := (isCompl_range_some_none ℝ≥0).symm.compl_eq.symm instance : NNRatCast ℝ≥0∞ where nnratCast r := ofNNReal r @[norm_cast] theorem coe_nnratCast (q : ℚ≥0) : ↑(q : ℝ≥0) = (q : ℝ≥0∞) := rfl /-- `toNNReal x` returns `x` if it is real, otherwise 0. -/ protected def toNNReal : ℝ≥0∞ → ℝ≥0 := WithTop.untopD 0 /-- `toReal x` returns `x` if it is real, `0` otherwise. -/ protected def toReal (a : ℝ≥0∞) : Real := a.toNNReal /-- `ofReal x` returns `x` if it is nonnegative, `0` otherwise. -/ protected def ofReal (r : Real) : ℝ≥0∞ := r.toNNReal @[simp, norm_cast] lemma toNNReal_coe (r : ℝ≥0) : (r : ℝ≥0∞).toNNReal = r := rfl @[simp] theorem coe_toNNReal : ∀ {a : ℝ≥0∞}, a ≠ ∞ → ↑a.toNNReal = a | ofNNReal _, _ => rfl | ⊤, h => (h rfl).elim @[simp] theorem coe_comp_toNNReal_comp {ι : Type*} {f : ι → ℝ≥0∞} (hf : ∀ x, f x ≠ ∞) : (fun (x : ℝ≥0) => (x : ℝ≥0∞)) ∘ ENNReal.toNNReal ∘ f = f := by ext x simp [coe_toNNReal (hf x)] @[simp] theorem ofReal_toReal {a : ℝ≥0∞} (h : a ≠ ∞) : ENNReal.ofReal a.toReal = a := by simp [ENNReal.toReal, ENNReal.ofReal, h] @[simp] theorem toReal_ofReal {r : ℝ} (h : 0 ≤ r) : (ENNReal.ofReal r).toReal = r := max_eq_left h theorem toReal_ofReal' {r : ℝ} : (ENNReal.ofReal r).toReal = max r 0 := rfl theorem coe_toNNReal_le_self : ∀ {a : ℝ≥0∞}, ↑a.toNNReal ≤ a | ofNNReal r => by rw [toNNReal_coe] | ⊤ => le_top theorem coe_nnreal_eq (r : ℝ≥0) : (r : ℝ≥0∞) = ENNReal.ofReal r := by rw [ENNReal.ofReal, Real.toNNReal_coe] theorem ofReal_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) : ENNReal.ofReal x = ofNNReal ⟨x, h⟩ := (coe_nnreal_eq ⟨x, h⟩).symm theorem ofNNReal_toNNReal (x : ℝ) : (Real.toNNReal x : ℝ≥0∞) = ENNReal.ofReal x := rfl @[simp] theorem ofReal_coe_nnreal : ENNReal.ofReal p = p := (coe_nnreal_eq p).symm @[simp, norm_cast] theorem coe_zero : ↑(0 : ℝ≥0) = (0 : ℝ≥0∞) := rfl @[simp, norm_cast] theorem coe_one : ↑(1 : ℝ≥0) = (1 : ℝ≥0∞) := rfl @[simp] theorem toReal_nonneg {a : ℝ≥0∞} : 0 ≤ a.toReal := a.toNNReal.2 @[norm_cast] theorem coe_toNNReal_eq_toReal (z : ℝ≥0∞) : (z.toNNReal : ℝ) = z.toReal := rfl @[simp] theorem toNNReal_toReal_eq (z : ℝ≥0∞) : z.toReal.toNNReal = z.toNNReal := by ext; simp [coe_toNNReal_eq_toReal] @[simp] theorem toNNReal_top : ∞.toNNReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias top_toNNReal := toNNReal_top @[simp] theorem toReal_top : ∞.toReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias top_toReal := toReal_top @[simp] theorem toReal_one : (1 : ℝ≥0∞).toReal = 1 := rfl @[deprecated (since := "2025-03-20")] alias one_toReal := toReal_one @[simp] theorem toNNReal_one : (1 : ℝ≥0∞).toNNReal = 1 := rfl @[deprecated (since := "2025-03-20")] alias one_toNNReal := toNNReal_one @[simp] theorem coe_toReal (r : ℝ≥0) : (r : ℝ≥0∞).toReal = r := rfl @[simp] theorem toNNReal_zero : (0 : ℝ≥0∞).toNNReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias zero_toNNReal := toNNReal_zero @[simp] theorem toReal_zero : (0 : ℝ≥0∞).toReal = 0 := rfl @[deprecated (since := "2025-03-20")] alias zero_toReal := toReal_zero @[simp] theorem ofReal_zero : ENNReal.ofReal (0 : ℝ) = 0 := by simp [ENNReal.ofReal] @[simp] theorem ofReal_one : ENNReal.ofReal (1 : ℝ) = (1 : ℝ≥0∞) := by simp [ENNReal.ofReal] theorem ofReal_toReal_le {a : ℝ≥0∞} : ENNReal.ofReal a.toReal ≤ a := if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (ofReal_toReal ha) theorem forall_ennreal {p : ℝ≥0∞ → Prop} : (∀ a, p a) ↔ (∀ r : ℝ≥0, p r) ∧ p ∞ := Option.forall.trans and_comm theorem forall_ne_top {p : ℝ≥0∞ → Prop} : (∀ a, a ≠ ∞ → p a) ↔ ∀ r : ℝ≥0, p r := Option.forall_ne_none theorem exists_ne_top {p : ℝ≥0∞ → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r := Option.exists_ne_none theorem toNNReal_eq_zero_iff (x : ℝ≥0∞) : x.toNNReal = 0 ↔ x = 0 ∨ x = ∞ := WithTop.untopD_eq_self_iff theorem toReal_eq_zero_iff (x : ℝ≥0∞) : x.toReal = 0 ↔ x = 0 ∨ x = ∞ := by simp [ENNReal.toReal, toNNReal_eq_zero_iff] theorem toNNReal_ne_zero : a.toNNReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toNNReal_eq_zero_iff.not.trans not_or theorem toReal_ne_zero : a.toReal ≠ 0 ↔ a ≠ 0 ∧ a ≠ ∞ := a.toReal_eq_zero_iff.not.trans not_or theorem toNNReal_eq_one_iff (x : ℝ≥0∞) : x.toNNReal = 1 ↔ x = 1 := WithTop.untopD_eq_iff.trans <| by simp theorem toReal_eq_one_iff (x : ℝ≥0∞) : x.toReal = 1 ↔ x = 1 := by rw [ENNReal.toReal, NNReal.coe_eq_one, ENNReal.toNNReal_eq_one_iff] theorem toNNReal_ne_one : a.toNNReal ≠ 1 ↔ a ≠ 1 := a.toNNReal_eq_one_iff.not theorem toReal_ne_one : a.toReal ≠ 1 ↔ a ≠ 1 := a.toReal_eq_one_iff.not @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem coe_ne_top : (r : ℝ≥0∞) ≠ ∞ := WithTop.coe_ne_top @[simp] theorem top_ne_coe : ∞ ≠ (r : ℝ≥0∞) := WithTop.top_ne_coe @[simp] theorem coe_lt_top : (r : ℝ≥0∞) < ∞ := WithTop.coe_lt_top r @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem ofReal_ne_top {r : ℝ} : ENNReal.ofReal r ≠ ∞ := coe_ne_top @[simp] theorem ofReal_lt_top {r : ℝ} : ENNReal.ofReal r < ∞ := coe_lt_top @[simp] theorem top_ne_ofReal {r : ℝ} : ∞ ≠ ENNReal.ofReal r := top_ne_coe @[simp] theorem ofReal_toReal_eq_iff : ENNReal.ofReal a.toReal = a ↔ a ≠ ⊤ := ⟨fun h => by rw [← h] exact ofReal_ne_top, ofReal_toReal⟩ @[simp] theorem toReal_ofReal_eq_iff {a : ℝ} : (ENNReal.ofReal a).toReal = a ↔ 0 ≤ a := ⟨fun h => by rw [← h] exact toReal_nonneg, toReal_ofReal⟩ @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem zero_ne_top : 0 ≠ ∞ := coe_ne_top @[simp] theorem top_ne_zero : ∞ ≠ 0 := top_ne_coe @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem one_ne_top : 1 ≠ ∞ := coe_ne_top @[simp] theorem top_ne_one : ∞ ≠ 1 := top_ne_coe @[simp] theorem zero_lt_top : 0 < ∞ := coe_lt_top @[simp, norm_cast] theorem coe_le_coe : (↑r : ℝ≥0∞) ≤ ↑q ↔ r ≤ q := WithTop.coe_le_coe @[simp, norm_cast] theorem coe_lt_coe : (↑r : ℝ≥0∞) < ↑q ↔ r < q := WithTop.coe_lt_coe -- Needed until `@[gcongr]` accepts iff statements alias ⟨_, coe_le_coe_of_le⟩ := coe_le_coe attribute [gcongr] ENNReal.coe_le_coe_of_le -- Needed until `@[gcongr]` accepts iff statements alias ⟨_, coe_lt_coe_of_lt⟩ := coe_lt_coe attribute [gcongr] ENNReal.coe_lt_coe_of_lt theorem coe_mono : Monotone ofNNReal := fun _ _ => coe_le_coe.2 theorem coe_strictMono : StrictMono ofNNReal := fun _ _ => coe_lt_coe.2 @[simp, norm_cast] theorem coe_eq_zero : (↑r : ℝ≥0∞) = 0 ↔ r = 0 := coe_inj @[simp, norm_cast] theorem zero_eq_coe : 0 = (↑r : ℝ≥0∞) ↔ 0 = r := coe_inj @[simp, norm_cast] theorem coe_eq_one : (↑r : ℝ≥0∞) = 1 ↔ r = 1 := coe_inj @[simp, norm_cast] theorem one_eq_coe : 1 = (↑r : ℝ≥0∞) ↔ 1 = r := coe_inj @[simp, norm_cast] theorem coe_pos : 0 < (r : ℝ≥0∞) ↔ 0 < r := coe_lt_coe theorem coe_ne_zero : (r : ℝ≥0∞) ≠ 0 ↔ r ≠ 0 := coe_eq_zero.not lemma coe_ne_one : (r : ℝ≥0∞) ≠ 1 ↔ r ≠ 1 := coe_eq_one.not @[simp, norm_cast] lemma coe_add (x y : ℝ≥0) : (↑(x + y) : ℝ≥0∞) = x + y := rfl @[simp, norm_cast] lemma coe_mul (x y : ℝ≥0) : (↑(x * y) : ℝ≥0∞) = x * y := rfl @[norm_cast] lemma coe_nsmul (n : ℕ) (x : ℝ≥0) : (↑(n • x) : ℝ≥0∞) = n • x := rfl @[simp, norm_cast] lemma coe_pow (x : ℝ≥0) (n : ℕ) : (↑(x ^ n) : ℝ≥0∞) = x ^ n := rfl @[simp, norm_cast] theorem coe_ofNat (n : ℕ) [n.AtLeastTwo] : ((ofNat(n) : ℝ≥0) : ℝ≥0∞) = ofNat(n) := rfl -- TODO: add lemmas about `OfNat.ofNat` and `<`/`≤` theorem coe_two : ((2 : ℝ≥0) : ℝ≥0∞) = 2 := rfl theorem toNNReal_eq_toNNReal_iff (x y : ℝ≥0∞) : x.toNNReal = y.toNNReal ↔ x = y ∨ x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0 := WithTop.untopD_eq_untopD_iff theorem toReal_eq_toReal_iff (x y : ℝ≥0∞) : x.toReal = y.toReal ↔ x = y ∨ x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0 := by simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff] theorem toNNReal_eq_toNNReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) : x.toNNReal = y.toNNReal ↔ x = y := by simp only [ENNReal.toNNReal_eq_toNNReal_iff x y, hx, hy, and_false, false_and, or_false] theorem toReal_eq_toReal_iff' {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) : x.toReal = y.toReal ↔ x = y := by simp only [ENNReal.toReal, NNReal.coe_inj, toNNReal_eq_toNNReal_iff' hx hy] theorem one_lt_two : (1 : ℝ≥0∞) < 2 := Nat.one_lt_ofNat /-- `(1 : ℝ≥0∞) ≤ 1`, recorded as a `Fact` for use with `Lp` spaces. -/ instance _root_.fact_one_le_one_ennreal : Fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩ /-- `(1 : ℝ≥0∞) ≤ 2`, recorded as a `Fact` for use with `Lp` spaces. -/ instance _root_.fact_one_le_two_ennreal : Fact ((1 : ℝ≥0∞) ≤ 2) := ⟨one_le_two⟩ /-- `(1 : ℝ≥0∞) ≤ ∞`, recorded as a `Fact` for use with `Lp` spaces. -/ instance _root_.fact_one_le_top_ennreal : Fact ((1 : ℝ≥0∞) ≤ ∞) := ⟨le_top⟩ /-- The set of numbers in `ℝ≥0∞` that are not equal to `∞` is equivalent to `ℝ≥0`. -/ def neTopEquivNNReal : { a | a ≠ ∞ } ≃ ℝ≥0 where toFun x := ENNReal.toNNReal x invFun x := ⟨x, coe_ne_top⟩ left_inv := fun x => Subtype.eq <| coe_toNNReal x.2 right_inv := toNNReal_coe theorem cinfi_ne_top [InfSet α] (f : ℝ≥0∞ → α) : ⨅ x : { x // x ≠ ∞ }, f x = ⨅ x : ℝ≥0, f x := Eq.symm <| neTopEquivNNReal.symm.surjective.iInf_congr _ fun _ => rfl theorem iInf_ne_top [CompleteLattice α] (f : ℝ≥0∞ → α) : ⨅ (x) (_ : x ≠ ∞), f x = ⨅ x : ℝ≥0, f x := by rw [iInf_subtype', cinfi_ne_top] theorem csupr_ne_top [SupSet α] (f : ℝ≥0∞ → α) : ⨆ x : { x // x ≠ ∞ }, f x = ⨆ x : ℝ≥0, f x := @cinfi_ne_top αᵒᵈ _ _ theorem iSup_ne_top [CompleteLattice α] (f : ℝ≥0∞ → α) : ⨆ (x) (_ : x ≠ ∞), f x = ⨆ x : ℝ≥0, f x := @iInf_ne_top αᵒᵈ _ _ theorem iInf_ennreal {α : Type*} [CompleteLattice α] {f : ℝ≥0∞ → α} : ⨅ n, f n = (⨅ n : ℝ≥0, f n) ⊓ f ∞ := (iInf_option f).trans (inf_comm _ _) theorem iSup_ennreal {α : Type*} [CompleteLattice α] {f : ℝ≥0∞ → α} : ⨆ n, f n = (⨆ n : ℝ≥0, f n) ⊔ f ∞ := @iInf_ennreal αᵒᵈ _ _ /-- Coercion `ℝ≥0 → ℝ≥0∞` as a `RingHom`. -/ def ofNNRealHom : ℝ≥0 →+* ℝ≥0∞ where toFun := some map_one' := coe_one map_mul' _ _ := coe_mul _ _ map_zero' := coe_zero map_add' _ _ := coe_add _ _ @[simp] theorem coe_ofNNRealHom : ⇑ofNNRealHom = some := rfl section Order theorem bot_eq_zero : (⊥ : ℝ≥0∞) = 0 := rfl -- `coe_lt_top` moved up theorem not_top_le_coe : ¬∞ ≤ ↑r := WithTop.not_top_le_coe r @[simp, norm_cast] theorem one_le_coe_iff : (1 : ℝ≥0∞) ≤ ↑r ↔ 1 ≤ r := coe_le_coe @[simp, norm_cast] theorem coe_le_one_iff : ↑r ≤ (1 : ℝ≥0∞) ↔ r ≤ 1 := coe_le_coe @[simp, norm_cast] theorem coe_lt_one_iff : (↑p : ℝ≥0∞) < 1 ↔ p < 1 := coe_lt_coe @[simp, norm_cast] theorem one_lt_coe_iff : 1 < (↑p : ℝ≥0∞) ↔ 1 < p := coe_lt_coe @[simp, norm_cast] theorem coe_natCast (n : ℕ) : ((n : ℝ≥0) : ℝ≥0∞) = n := rfl @[simp, norm_cast] lemma ofReal_natCast (n : ℕ) : ENNReal.ofReal n = n := by simp [ENNReal.ofReal] @[simp] theorem ofReal_ofNat (n : ℕ) [n.AtLeastTwo] : ENNReal.ofReal ofNat(n) = ofNat(n) := ofReal_natCast n @[simp, aesop (rule_sets := [finiteness]) safe apply] theorem natCast_ne_top (n : ℕ) : (n : ℝ≥0∞) ≠ ∞ := WithTop.natCast_ne_top n @[simp] theorem natCast_lt_top (n : ℕ) : (n : ℝ≥0∞) < ∞ := WithTop.natCast_lt_top n @[simp, aesop (rule_sets := [finiteness]) safe apply] lemma ofNat_ne_top {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) ≠ ∞ := natCast_ne_top n @[simp] lemma ofNat_lt_top {n : ℕ} [Nat.AtLeastTwo n] : ofNat(n) < ∞ := natCast_lt_top n @[simp] theorem top_ne_natCast (n : ℕ) : ∞ ≠ n := WithTop.top_ne_natCast n @[simp] theorem top_ne_ofNat {n : ℕ} [n.AtLeastTwo] : ∞ ≠ ofNat(n) := ofNat_ne_top.symm @[deprecated ofNat_ne_top (since := "2025-01-21")] lemma two_ne_top : (2 : ℝ≥0∞) ≠ ∞ := coe_ne_top @[deprecated ofNat_lt_top (since := "2025-01-21")] lemma two_lt_top : (2 : ℝ≥0∞) < ∞ := coe_lt_top @[simp] theorem one_lt_top : 1 < ∞ := coe_lt_top @[simp, norm_cast] theorem toNNReal_natCast (n : ℕ) : (n : ℝ≥0∞).toNNReal = n := by rw [← ENNReal.coe_natCast n, ENNReal.toNNReal_coe] @[deprecated (since := "2025-02-19")] alias toNNReal_nat := toNNReal_natCast theorem toNNReal_ofNat (n : ℕ) [n.AtLeastTwo] : ENNReal.toNNReal ofNat(n) = ofNat(n) := toNNReal_natCast n @[simp, norm_cast] theorem toReal_natCast (n : ℕ) : (n : ℝ≥0∞).toReal = n := by rw [← ENNReal.ofReal_natCast n, ENNReal.toReal_ofReal (Nat.cast_nonneg _)] @[deprecated (since := "2025-02-19")] alias toReal_nat := toReal_natCast @[simp] theorem toReal_ofNat (n : ℕ) [n.AtLeastTwo] : ENNReal.toReal ofNat(n) = ofNat(n) := toReal_natCast n lemma toNNReal_natCast_eq_toNNReal (n : ℕ) : (n : ℝ≥0∞).toNNReal = (n : ℝ).toNNReal := by rw [Real.toNNReal_of_nonneg (by positivity), ENNReal.toNNReal_natCast, mk_natCast] theorem le_coe_iff : a ≤ ↑r ↔ ∃ p : ℝ≥0, a = p ∧ p ≤ r := WithTop.le_coe_iff theorem coe_le_iff : ↑r ≤ a ↔ ∀ p : ℝ≥0, a = p → r ≤ p := WithTop.coe_le_iff theorem lt_iff_exists_coe : a < b ↔ ∃ p : ℝ≥0, a = p ∧ ↑p < b := WithTop.lt_iff_exists_coe theorem toReal_le_coe_of_le_coe {a : ℝ≥0∞} {b : ℝ≥0} (h : a ≤ b) : a.toReal ≤ b := by lift a to ℝ≥0 using ne_top_of_le_ne_top coe_ne_top h simpa using h @[simp] theorem max_eq_zero_iff : max a b = 0 ↔ a = 0 ∧ b = 0 := max_eq_bot theorem max_zero_left : max 0 a = a := max_eq_right (zero_le a) theorem max_zero_right : max a 0 = a := max_eq_left (zero_le a) theorem lt_iff_exists_rat_btwn : a < b ↔ ∃ q : ℚ, 0 ≤ q ∧ a < Real.toNNReal q ∧ (Real.toNNReal q : ℝ≥0∞) < b := ⟨fun h => by rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩ rcases exists_between h with ⟨c, pc, cb⟩ rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩ rcases (NNReal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩ exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩, fun ⟨_, _, qa, qb⟩ => lt_trans qa qb⟩ theorem lt_iff_exists_real_btwn : a < b ↔ ∃ r : ℝ, 0 ≤ r ∧ a < ENNReal.ofReal r ∧ (ENNReal.ofReal r : ℝ≥0∞) < b := ⟨fun h => let ⟨q, q0, aq, qb⟩ := ENNReal.lt_iff_exists_rat_btwn.1 h ⟨q, Rat.cast_nonneg.2 q0, aq, qb⟩, fun ⟨_, _, qa, qb⟩ => lt_trans qa qb⟩ theorem lt_iff_exists_nnreal_btwn : a < b ↔ ∃ r : ℝ≥0, a < r ∧ (r : ℝ≥0∞) < b := WithTop.lt_iff_exists_coe_btwn theorem lt_iff_exists_add_pos_lt : a < b ↔ ∃ r : ℝ≥0, 0 < r ∧ a + r < b := by refine ⟨fun hab => ?_, fun ⟨r, _, hr⟩ => lt_of_le_of_lt le_self_add hr⟩ rcases lt_iff_exists_nnreal_btwn.1 hab with ⟨c, ac, cb⟩ lift a to ℝ≥0 using ac.ne_top rw [coe_lt_coe] at ac refine ⟨c - a, tsub_pos_iff_lt.2 ac, ?_⟩ rwa [← coe_add, add_tsub_cancel_of_le ac.le] theorem le_of_forall_pos_le_add (h : ∀ ε : ℝ≥0, 0 < ε → b < ∞ → a ≤ b + ε) : a ≤ b := by contrapose! h rcases lt_iff_exists_add_pos_lt.1 h with ⟨r, hr0, hr⟩ exact ⟨r, hr0, h.trans_le le_top, hr⟩ theorem natCast_lt_coe {n : ℕ} : n < (r : ℝ≥0∞) ↔ n < r := ENNReal.coe_natCast n ▸ coe_lt_coe theorem coe_lt_natCast {n : ℕ} : (r : ℝ≥0∞) < n ↔ r < n := ENNReal.coe_natCast n ▸ coe_lt_coe protected theorem exists_nat_gt {r : ℝ≥0∞} (h : r ≠ ∞) : ∃ n : ℕ, r < n := by lift r to ℝ≥0 using h rcases exists_nat_gt r with ⟨n, hn⟩ exact ⟨n, coe_lt_natCast.2 hn⟩ @[simp] theorem iUnion_Iio_coe_nat : ⋃ n : ℕ, Iio (n : ℝ≥0∞) = {∞}ᶜ := by ext x rw [mem_iUnion] exact ⟨fun ⟨n, hn⟩ => ne_top_of_lt hn, ENNReal.exists_nat_gt⟩ @[simp] theorem iUnion_Iic_coe_nat : ⋃ n : ℕ, Iic (n : ℝ≥0∞) = {∞}ᶜ := Subset.antisymm (iUnion_subset fun n _x hx => ne_top_of_le_ne_top (natCast_ne_top n) hx) <| iUnion_Iio_coe_nat ▸ iUnion_mono fun _ => Iio_subset_Iic_self @[simp] theorem iUnion_Ioc_coe_nat : ⋃ n : ℕ, Ioc a n = Ioi a \ {∞} := by simp only [← Ioi_inter_Iic, ← inter_iUnion, iUnion_Iic_coe_nat, diff_eq] @[simp] theorem iUnion_Ioo_coe_nat : ⋃ n : ℕ, Ioo a n = Ioi a \ {∞} := by simp only [← Ioi_inter_Iio, ← inter_iUnion, iUnion_Iio_coe_nat, diff_eq] @[simp] theorem iUnion_Icc_coe_nat : ⋃ n : ℕ, Icc a n = Ici a \ {∞} := by simp only [← Ici_inter_Iic, ← inter_iUnion, iUnion_Iic_coe_nat, diff_eq] @[simp] theorem iUnion_Ico_coe_nat : ⋃ n : ℕ, Ico a n = Ici a \ {∞} := by simp only [← Ici_inter_Iio, ← inter_iUnion, iUnion_Iio_coe_nat, diff_eq] @[simp] theorem iInter_Ici_coe_nat : ⋂ n : ℕ, Ici (n : ℝ≥0∞) = {∞} := by simp only [← compl_Iio, ← compl_iUnion, iUnion_Iio_coe_nat, compl_compl] @[simp] theorem iInter_Ioi_coe_nat : ⋂ n : ℕ, Ioi (n : ℝ≥0∞) = {∞} := by simp only [← compl_Iic, ← compl_iUnion, iUnion_Iic_coe_nat, compl_compl] @[simp, norm_cast] theorem coe_min (r p : ℝ≥0) : ((min r p : ℝ≥0) : ℝ≥0∞) = min (r : ℝ≥0∞) p := rfl @[simp, norm_cast] theorem coe_max (r p : ℝ≥0) : ((max r p : ℝ≥0) : ℝ≥0∞) = max (r : ℝ≥0∞) p := rfl theorem le_of_top_imp_top_of_toNNReal_le {a b : ℝ≥0∞} (h : a = ⊤ → b = ⊤) (h_nnreal : a ≠ ⊤ → b ≠ ⊤ → a.toNNReal ≤ b.toNNReal) : a ≤ b := by by_contra! hlt lift b to ℝ≥0 using hlt.ne_top lift a to ℝ≥0 using mt h coe_ne_top refine hlt.not_le ?_ simpa using h_nnreal @[simp] theorem abs_toReal {x : ℝ≥0∞} : |x.toReal| = x.toReal := by cases x <;> simp end Order section CompleteLattice variable {ι : Sort*} {f : ι → ℝ≥0} theorem coe_sSup {s : Set ℝ≥0} : BddAbove s → (↑(sSup s) : ℝ≥0∞) = ⨆ a ∈ s, ↑a := WithTop.coe_sSup theorem coe_sInf {s : Set ℝ≥0} (hs : s.Nonempty) : (↑(sInf s) : ℝ≥0∞) = ⨅ a ∈ s, ↑a := WithTop.coe_sInf hs (OrderBot.bddBelow s) theorem coe_iSup {ι : Sort*} {f : ι → ℝ≥0} (hf : BddAbove (range f)) : (↑(iSup f) : ℝ≥0∞) = ⨆ a, ↑(f a) := WithTop.coe_iSup _ hf @[norm_cast] theorem coe_iInf {ι : Sort*} [Nonempty ι] (f : ι → ℝ≥0) : (↑(iInf f) : ℝ≥0∞) = ⨅ a, ↑(f a) := WithTop.coe_iInf (OrderBot.bddBelow _) theorem coe_mem_upperBounds {s : Set ℝ≥0} : ↑r ∈ upperBounds (ofNNReal '' s) ↔ r ∈ upperBounds s := by simp +contextual [upperBounds, forall_mem_image, -mem_image, *] lemma iSup_coe_eq_top : ⨆ i, (f i : ℝ≥0∞) = ⊤ ↔ ¬ BddAbove (range f) := WithTop.iSup_coe_eq_top lemma iSup_coe_lt_top : ⨆ i, (f i : ℝ≥0∞) < ⊤ ↔ BddAbove (range f) := WithTop.iSup_coe_lt_top lemma iInf_coe_eq_top : ⨅ i, (f i : ℝ≥0∞) = ⊤ ↔ IsEmpty ι := WithTop.iInf_coe_eq_top lemma iInf_coe_lt_top : ⨅ i, (f i : ℝ≥0∞) < ⊤ ↔ Nonempty ι := WithTop.iInf_coe_lt_top end CompleteLattice section Bit -- TODO: add lemmas about `OfNat.ofNat` end Bit end ENNReal open ENNReal namespace Set namespace OrdConnected variable {s : Set ℝ} {t : Set ℝ≥0} {u : Set ℝ≥0∞} theorem preimage_coe_nnreal_ennreal (h : u.OrdConnected) : ((↑) ⁻¹' u : Set ℝ≥0).OrdConnected := h.preimage_mono ENNReal.coe_mono -- TODO: generalize to `WithTop` theorem image_coe_nnreal_ennreal (h : t.OrdConnected) : ((↑) '' t : Set ℝ≥0∞).OrdConnected := by refine ⟨forall_mem_image.2 fun x hx => forall_mem_image.2 fun y hy z hz => ?_⟩ rcases ENNReal.le_coe_iff.1 hz.2 with ⟨z, rfl, -⟩ exact mem_image_of_mem _ (h.out hx hy ⟨ENNReal.coe_le_coe.1 hz.1, ENNReal.coe_le_coe.1 hz.2⟩) theorem preimage_ennreal_ofReal (h : u.OrdConnected) : (ENNReal.ofReal ⁻¹' u).OrdConnected := h.preimage_coe_nnreal_ennreal.preimage_real_toNNReal theorem image_ennreal_ofReal (h : s.OrdConnected) : (ENNReal.ofReal '' s).OrdConnected := by simpa only [image_image] using h.image_real_toNNReal.image_coe_nnreal_ennreal end OrdConnected end Set /-- While not very useful, this instance uses the same representation as `Real.instRepr`. -/ unsafe instance : Repr ℝ≥0∞ where reprPrec | (r : ℝ≥0), p => Repr.addAppParen f!"ENNReal.ofReal ({repr r.val})" p | ∞, _ => "∞" namespace Mathlib.Meta.Positivity open Lean Meta Qq /-- Extension for the `positivity` tactic: `ENNReal.toReal`. -/ @[positivity ENNReal.toReal _] def evalENNRealtoReal : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ), ~q(ENNReal.toReal $a) => assertInstancesCommute pure (.nonnegative q(ENNReal.toReal_nonneg)) | _, _, _ => throwError "not ENNReal.toReal" /-- Extension for the `positivity` tactic: `ENNReal.ofNNReal`. -/ @[positivity ENNReal.ofNNReal _] def evalENNRealOfNNReal : PositivityExt where eval {u α} _zα _pα e := do match u, α, e with | 0, ~q(ℝ≥0∞), ~q(ENNReal.ofNNReal $a) => let ra ← core q(inferInstance) q(inferInstance) a assertInstancesCommute match ra with | .positive pa => pure <| .positive q(ENNReal.coe_pos.mpr $pa) | _ => pure .none | _, _, _ => throwError "not ENNReal.ofNNReal" end Mathlib.Meta.Positivity
Mathlib/Data/ENNReal/Basic.lean
832
833
/- 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.Data.Sum.Order import Mathlib.Order.RelIso.Set import Mathlib.Order.UpperLower.Basic import Mathlib.Order.WellFounded /-! # Initial and principal segments This file defines initial and principal segment embeddings. Though these definitions make sense for arbitrary relations, they're intended for use with well orders. An initial segment is simply a lower set, i.e. if `x` belongs to the range, then any `y < x` also belongs to the range. A principal segment is a set of the form `Set.Iio x` for some `x`. An initial segment embedding `r ≼i s` is an order embedding `r ↪ s` such that its range is an initial segment. Likewise, a principal segment embedding `r ≺i s` has a principal segment for a range. ## Main definitions * `InitialSeg r s`: Type of initial segment embeddings of `r` into `s` , denoted by `r ≼i s`. * `PrincipalSeg r s`: Type of principal segment embeddings of `r` into `s` , denoted by `r ≺i s`. The lemmas `Ordinal.type_le_iff` and `Ordinal.type_lt_iff` tell us that `≼i` corresponds to the `≤` relation on ordinals, while `≺i` corresponds to the `<` relation. This prompts us to think of `PrincipalSeg` as a "strict" version of `InitialSeg`. ## Notations These notations belong to the `InitialSeg` locale. * `r ≼i s`: the type of initial segment embeddings of `r` into `s`. * `r ≺i s`: the type of principal segment embeddings of `r` into `s`. * `α ≤i β` is an abbreviation for `(· < ·) ≼i (· < ·)`. * `α <i β` is an abbreviation for `(· < ·) ≺i (· < ·)`. -/ /-! ### Initial segment embeddings -/ variable {α : Type*} {β : Type*} {γ : Type*} {r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop} open Function /-- If `r` is a relation on `α` and `s` in a relation on `β`, then `f : r ≼i s` is an order embedding whose `Set.range` is a lower set. That is, whenever `b < f a` in `β` then `b` is in the range of `f`. -/ structure InitialSeg {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends r ↪r s where /-- The order embedding is an initial segment -/ mem_range_of_rel' : ∀ a b, s b (toRelEmbedding a) → b ∈ Set.range toRelEmbedding @[inherit_doc] scoped[InitialSeg] infixl:25 " ≼i " => InitialSeg /-- An `InitialSeg` between the `<` relations of two types. -/ notation:25 α:24 " ≤i " β:25 => @InitialSeg α β (· < ·) (· < ·) namespace InitialSeg instance : Coe (r ≼i s) (r ↪r s) := ⟨InitialSeg.toRelEmbedding⟩ instance : FunLike (r ≼i s) α β where coe f := f.toFun coe_injective' := by rintro ⟨f, hf⟩ ⟨g, hg⟩ h congr with x exact congr_fun h x instance : EmbeddingLike (r ≼i s) α β where injective' f := f.inj' instance : RelHomClass (r ≼i s) r s where map_rel f := f.map_rel_iff.2 /-- An initial segment embedding between the `<` relations of two partial orders is an order embedding. -/ def toOrderEmbedding [PartialOrder α] [PartialOrder β] (f : α ≤i β) : α ↪o β := f.orderEmbeddingOfLTEmbedding @[simp] theorem toOrderEmbedding_apply [PartialOrder α] [PartialOrder β] (f : α ≤i β) (x : α) : f.toOrderEmbedding x = f x := rfl @[simp] theorem coe_toOrderEmbedding [PartialOrder α] [PartialOrder β] (f : α ≤i β) : (f.toOrderEmbedding : α → β) = f := rfl instance [PartialOrder α] [PartialOrder β] : OrderHomClass (α ≤i β) α β where map_rel f := f.toOrderEmbedding.map_rel_iff.2 @[ext] lemma ext {f g : r ≼i s} (h : ∀ x, f x = g x) : f = g := DFunLike.ext f g h @[simp] theorem coe_coe_fn (f : r ≼i s) : ((f : r ↪r s) : α → β) = f := rfl theorem mem_range_of_rel (f : r ≼i s) {a : α} {b : β} : s b (f a) → b ∈ Set.range f := f.mem_range_of_rel' _ _ theorem map_rel_iff {a b : α} (f : r ≼i s) : s (f a) (f b) ↔ r a b := f.map_rel_iff' theorem inj (f : r ≼i s) {a b : α} : f a = f b ↔ a = b := f.toRelEmbedding.inj theorem exists_eq_iff_rel (f : r ≼i s) {a : α} {b : β} : s b (f a) ↔ ∃ a', f a' = b ∧ r a' a := ⟨fun h => by rcases f.mem_range_of_rel h with ⟨a', rfl⟩ exact ⟨a', rfl, f.map_rel_iff.1 h⟩, fun ⟨_, e, h⟩ => e ▸ f.map_rel_iff.2 h⟩ /-- A relation isomorphism is an initial segment embedding -/ @[simps!] def _root_.RelIso.toInitialSeg (f : r ≃r s) : r ≼i s := ⟨f, by simp⟩ @[deprecated (since := "2024-10-22")] alias ofIso := RelIso.toInitialSeg /-- The identity function shows that `≼i` is reflexive -/ @[refl] protected def refl (r : α → α → Prop) : r ≼i r := (RelIso.refl r).toInitialSeg instance (r : α → α → Prop) : Inhabited (r ≼i r) := ⟨InitialSeg.refl r⟩ /-- Composition of functions shows that `≼i` is transitive -/ @[trans] protected def trans (f : r ≼i s) (g : s ≼i t) : r ≼i t := ⟨f.1.trans g.1, fun a c h => by simp only [RelEmbedding.coe_trans, coe_coe_fn, comp_apply] at h ⊢ rcases g.2 _ _ h with ⟨b, rfl⟩; have h := g.map_rel_iff.1 h rcases f.2 _ _ h with ⟨a', rfl⟩; exact ⟨a', rfl⟩⟩ @[simp] theorem refl_apply (x : α) : InitialSeg.refl r x = x := rfl @[simp] theorem trans_apply (f : r ≼i s) (g : s ≼i t) (a : α) : (f.trans g) a = g (f a) := rfl instance subsingleton_of_trichotomous_of_irrefl [IsTrichotomous β s] [IsIrrefl β s] [IsWellFounded α r] : Subsingleton (r ≼i s) where allEq f g := by ext a refine IsWellFounded.induction r a fun b IH => extensional_of_trichotomous_of_irrefl s fun x => ?_ rw [f.exists_eq_iff_rel, g.exists_eq_iff_rel] exact exists_congr fun x => and_congr_left fun hx => IH _ hx ▸ Iff.rfl /-- Given a well order `s`, there is at most one initial segment embedding of `r` into `s`. -/ instance [IsWellOrder β s] : Subsingleton (r ≼i s) := ⟨fun a => have := a.isWellFounded; Subsingleton.elim a⟩ protected theorem eq [IsWellOrder β s] (f g : r ≼i s) (a) : f a = g a := by rw [Subsingleton.elim f g] theorem eq_relIso [IsWellOrder β s] (f : r ≼i s) (g : r ≃r s) (a : α) : g a = f a := InitialSeg.eq g.toInitialSeg f a
private theorem antisymm_aux [IsWellOrder α r] (f : r ≼i s) (g : s ≼i r) : LeftInverse g f := (f.trans g).eq (InitialSeg.refl _) /-- If we have order embeddings between `α` and `β` whose ranges are initial segments, and `β` is a well order, then `α` and `β` are order-isomorphic. -/ def antisymm [IsWellOrder β s] (f : r ≼i s) (g : s ≼i r) : r ≃r s := have := f.toRelEmbedding.isWellOrder ⟨⟨f, g, antisymm_aux f g, antisymm_aux g f⟩, f.map_rel_iff'⟩ @[simp] theorem antisymm_toFun [IsWellOrder β s] (f : r ≼i s) (g : s ≼i r) : (antisymm f g : α → β) = f := rfl
Mathlib/Order/InitialSeg.lean
172
183
/- 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.Solvable import Mathlib.Algebra.Lie.Quotient import Mathlib.Algebra.Lie.Normalizer import Mathlib.Algebra.Order.Archimedean.Basic import Mathlib.LinearAlgebra.Eigenspace.Basic import Mathlib.RingTheory.Artinian.Module import Mathlib.RingTheory.Nilpotent.Lemmas /-! # Nilpotent Lie algebras Like groups, Lie algebras admit a natural concept of nilpotency. More generally, any Lie module carries a natural concept of nilpotency. We define these here via the lower central series. ## Main definitions * `LieModule.lowerCentralSeries` * `LieModule.IsNilpotent` * `LieModule.maxNilpotentSubmodule` * `LieAlgebra.maxNilpotentIdeal` ## Tags lie algebra, lower central series, nilpotent, max nilpotent ideal -/ universe u v w w₁ w₂ section NilpotentModules variable {R : Type u} {L : Type v} {M : Type w} variable [CommRing R] [LieRing L] [LieAlgebra R L] [AddCommGroup M] [Module R M] variable [LieRingModule L M] variable (k : ℕ) (N : LieSubmodule R L M) namespace LieSubmodule /-- A generalisation of the lower central series. The zeroth term is a specified Lie submodule of a Lie module. In the case when we specify the top ideal `⊤` of the Lie algebra, regarded as a Lie module over itself, we get the usual lower central series of a Lie algebra. It can be more convenient to work with this generalisation when considering the lower central series of a Lie submodule, regarded as a Lie module in its own right, since it provides a type-theoretic expression of the fact that the terms of the Lie submodule's lower central series are also Lie submodules of the enclosing Lie module. See also `LieSubmodule.lowerCentralSeries_eq_lcs_comap` and `LieSubmodule.lowerCentralSeries_map_eq_lcs` below, as well as `LieSubmodule.ucs`. -/ def lcs : LieSubmodule R L M → LieSubmodule R L M := (fun N => ⁅(⊤ : LieIdeal R L), N⁆)^[k] @[simp] theorem lcs_zero (N : LieSubmodule R L M) : N.lcs 0 = N := rfl @[simp] theorem lcs_succ : N.lcs (k + 1) = ⁅(⊤ : LieIdeal R L), N.lcs k⁆ := Function.iterate_succ_apply' (fun N' => ⁅⊤, N'⁆) k N @[simp] lemma lcs_sup {N₁ N₂ : LieSubmodule R L M} {k : ℕ} : (N₁ ⊔ N₂).lcs k = N₁.lcs k ⊔ N₂.lcs k := by induction k with | zero => simp | succ k ih => simp only [LieSubmodule.lcs_succ, ih, LieSubmodule.lie_sup] end LieSubmodule namespace LieModule variable (R L M) /-- The lower central series of Lie submodules of a Lie module. -/ def lowerCentralSeries : LieSubmodule R L M := (⊤ : LieSubmodule R L M).lcs k @[simp] theorem lowerCentralSeries_zero : lowerCentralSeries R L M 0 = ⊤ := rfl @[simp] theorem lowerCentralSeries_succ : lowerCentralSeries R L M (k + 1) = ⁅(⊤ : LieIdeal R L), lowerCentralSeries R L M k⁆ := (⊤ : LieSubmodule R L M).lcs_succ k private theorem coe_lowerCentralSeries_eq_int_aux (R₁ R₂ L M : Type*) [CommRing R₁] [CommRing R₂] [AddCommGroup M] [LieRing L] [LieAlgebra R₁ L] [LieAlgebra R₂ L] [Module R₁ M] [Module R₂ M] [LieRingModule L M] [LieModule R₁ L M] (k : ℕ) : let I := lowerCentralSeries R₂ L M k; let S : Set M := {⁅a, b⁆ | (a : L) (b ∈ I)} (Submodule.span R₁ S : Set M) ≤ (Submodule.span R₂ S : Set M) := by intro I S x hx simp only [SetLike.mem_coe] at hx ⊢ induction hx using Submodule.closure_induction with | zero => exact Submodule.zero_mem _ | add y z hy₁ hz₁ hy₂ hz₂ => exact Submodule.add_mem _ hy₂ hz₂ | smul_mem c y hy => obtain ⟨a, b, hb, rfl⟩ := hy rw [← smul_lie] exact Submodule.subset_span ⟨c • a, b, hb, rfl⟩ theorem coe_lowerCentralSeries_eq_int [LieModule R L M] (k : ℕ) : (lowerCentralSeries R L M k : Set M) = (lowerCentralSeries ℤ L M k : Set M) := by rw [← LieSubmodule.coe_toSubmodule, ← LieSubmodule.coe_toSubmodule] induction k with | zero => rfl | succ k ih => rw [lowerCentralSeries_succ, lowerCentralSeries_succ] rw [LieSubmodule.lieIdeal_oper_eq_linear_span', LieSubmodule.lieIdeal_oper_eq_linear_span'] rw [Set.ext_iff] at ih simp only [SetLike.mem_coe, LieSubmodule.mem_toSubmodule] at ih simp only [LieSubmodule.mem_top, ih, true_and] apply le_antisymm · exact coe_lowerCentralSeries_eq_int_aux _ _ L M k · simp only [← ih] exact coe_lowerCentralSeries_eq_int_aux _ _ L M k end LieModule namespace LieSubmodule open LieModule theorem lcs_le_self : N.lcs k ≤ N := by induction k with | zero => simp | succ k ih => simp only [lcs_succ] exact (LieSubmodule.mono_lie_right ⊤ ih).trans (N.lie_le_right ⊤) variable [LieModule R L M] theorem lowerCentralSeries_eq_lcs_comap : lowerCentralSeries R L N k = (N.lcs k).comap N.incl := by induction k with | zero => simp | succ k ih => simp only [lcs_succ, lowerCentralSeries_succ] at ih ⊢ have : N.lcs k ≤ N.incl.range := by rw [N.range_incl] apply lcs_le_self rw [ih, LieSubmodule.comap_bracket_eq _ N.incl _ N.ker_incl this] theorem lowerCentralSeries_map_eq_lcs : (lowerCentralSeries R L N k).map N.incl = N.lcs k := by rw [lowerCentralSeries_eq_lcs_comap, LieSubmodule.map_comap_incl, inf_eq_right] apply lcs_le_self theorem lowerCentralSeries_eq_bot_iff_lcs_eq_bot: lowerCentralSeries R L N k = ⊥ ↔ lcs k N = ⊥ := by refine ⟨fun h ↦ ?_, fun h ↦ ?_⟩ · rw [← N.lowerCentralSeries_map_eq_lcs, ← LieModuleHom.le_ker_iff_map] simpa · rw [N.lowerCentralSeries_eq_lcs_comap, comap_incl_eq_bot] simp [h] end LieSubmodule namespace LieModule variable {M₂ : Type w₁} [AddCommGroup M₂] [Module R M₂] [LieRingModule L M₂] [LieModule R L M₂] variable (R L M) theorem antitone_lowerCentralSeries : Antitone <| lowerCentralSeries R L M := by intro l k induction k generalizing l with | zero => exact fun h ↦ (Nat.le_zero.mp h).symm ▸ le_rfl | succ k ih => intro h rcases Nat.of_le_succ h with (hk | hk) · rw [lowerCentralSeries_succ] exact (LieSubmodule.mono_lie_right ⊤ (ih hk)).trans (LieSubmodule.lie_le_right _ _) · exact hk.symm ▸ le_rfl theorem eventually_iInf_lowerCentralSeries_eq [IsArtinian R M] : ∀ᶠ l in Filter.atTop, ⨅ k, lowerCentralSeries R L M k = lowerCentralSeries R L M l := by have h_wf : WellFoundedGT (LieSubmodule R L M)ᵒᵈ := LieSubmodule.wellFoundedLT_of_isArtinian R L M obtain ⟨n, hn : ∀ m, n ≤ m → lowerCentralSeries R L M n = lowerCentralSeries R L M m⟩ := h_wf.monotone_chain_condition ⟨_, antitone_lowerCentralSeries R L M⟩ refine Filter.eventually_atTop.mpr ⟨n, fun l hl ↦ le_antisymm (iInf_le _ _) (le_iInf fun m ↦ ?_)⟩ rcases le_or_lt l m with h | h · rw [← hn _ hl, ← hn _ (hl.trans h)] · exact antitone_lowerCentralSeries R L M (le_of_lt h) theorem trivial_iff_lower_central_eq_bot : IsTrivial L M ↔ lowerCentralSeries R L M 1 = ⊥ := by constructor <;> intro h · simp · rw [LieSubmodule.eq_bot_iff] at h; apply IsTrivial.mk; intro x m; apply h apply LieSubmodule.subset_lieSpan simp only [LieSubmodule.top_coe, Subtype.exists, LieSubmodule.mem_top, exists_prop, true_and, Set.mem_setOf] exact ⟨x, m, rfl⟩ section variable [LieModule R L M] theorem iterate_toEnd_mem_lowerCentralSeries (x : L) (m : M) (k : ℕ) : (toEnd R L M x)^[k] m ∈ lowerCentralSeries R L M k := by induction k with | zero => simp only [Function.iterate_zero, lowerCentralSeries_zero, LieSubmodule.mem_top] | succ k ih => simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', toEnd_apply_apply] exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ih theorem iterate_toEnd_mem_lowerCentralSeries₂ (x y : L) (m : M) (k : ℕ) : (toEnd R L M x ∘ₗ toEnd R L M y)^[k] m ∈ lowerCentralSeries R L M (2 * k) := by induction k with | zero => simp | succ k ih => have hk : 2 * k.succ = (2 * k + 1) + 1 := rfl simp only [lowerCentralSeries_succ, Function.comp_apply, Function.iterate_succ', hk, toEnd_apply_apply, LinearMap.coe_comp, toEnd_apply_apply] refine LieSubmodule.lie_mem_lie (LieSubmodule.mem_top x) ?_ exact LieSubmodule.lie_mem_lie (LieSubmodule.mem_top y) ih variable {R L M} theorem map_lowerCentralSeries_le (f : M →ₗ⁅R,L⁆ M₂) : (lowerCentralSeries R L M k).map f ≤ lowerCentralSeries R L M₂ k := by induction k with | zero => simp only [lowerCentralSeries_zero, le_top] | succ k ih => simp only [LieModule.lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] exact LieSubmodule.mono_lie_right ⊤ ih lemma map_lowerCentralSeries_eq {f : M →ₗ⁅R,L⁆ M₂} (hf : Function.Surjective f) : (lowerCentralSeries R L M k).map f = lowerCentralSeries R L M₂ k := by apply le_antisymm (map_lowerCentralSeries_le k f) induction k with | zero => rwa [lowerCentralSeries_zero, lowerCentralSeries_zero, top_le_iff, f.map_top, f.range_eq_top] | succ => simp only [lowerCentralSeries_succ, LieSubmodule.map_bracket_eq] apply LieSubmodule.mono_lie_right assumption end open LieAlgebra theorem derivedSeries_le_lowerCentralSeries (k : ℕ) : derivedSeries R L k ≤ lowerCentralSeries R L L k := by induction k with | zero => rw [derivedSeries_def, derivedSeriesOfIdeal_zero, lowerCentralSeries_zero] | succ k h => have h' : derivedSeries R L k ≤ ⊤ := by simp only [le_top] rw [derivedSeries_def, derivedSeriesOfIdeal_succ, lowerCentralSeries_succ] exact LieSubmodule.mono_lie h' h /-- A Lie module is nilpotent if its lower central series reaches 0 (in a finite number of steps). -/ @[mk_iff isNilpotent_iff_int] class IsNilpotent : Prop where mk_int :: nilpotent_int : ∃ k, lowerCentralSeries ℤ L M k = ⊥ section variable [LieModule R L M] /-- See also `LieModule.isNilpotent_iff_exists_ucs_eq_top`. -/ lemma isNilpotent_iff : IsNilpotent L M ↔ ∃ k, lowerCentralSeries R L M k = ⊥ := by simp [isNilpotent_iff_int, SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] lemma IsNilpotent.nilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := (isNilpotent_iff R L M).mp ‹_› variable {R L} in lemma IsNilpotent.mk {k : ℕ} (h : lowerCentralSeries R L M k = ⊥) : IsNilpotent L M := (isNilpotent_iff R L M).mpr ⟨k, h⟩ @[deprecated IsNilpotent.nilpotent (since := "2025-01-07")] theorem exists_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ∃ k, lowerCentralSeries R L M k = ⊥ := IsNilpotent.nilpotent R L M @[simp] lemma iInf_lowerCentralSeries_eq_bot_of_isNilpotent [IsNilpotent L M] : ⨅ k, lowerCentralSeries R L M k = ⊥ := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M rw [eq_bot_iff, ← hk] exact iInf_le _ _ end section variable {R L M} variable [LieModule R L M] theorem _root_.LieSubmodule.isNilpotent_iff_exists_lcs_eq_bot (N : LieSubmodule R L M) : LieModule.IsNilpotent L N ↔ ∃ k, N.lcs k = ⊥ := by rw [isNilpotent_iff R L N] refine exists_congr fun k => ?_ rw [N.lowerCentralSeries_eq_lcs_comap k, LieSubmodule.comap_incl_eq_bot, inf_eq_right.mpr (N.lcs_le_self k)] variable (R L M) instance (priority := 100) trivialIsNilpotent [IsTrivial L M] : IsNilpotent L M := ⟨by use 1; simp⟩ instance instIsNilpotentSup (M₁ M₂ : LieSubmodule R L M) [IsNilpotent L M₁] [IsNilpotent L M₂] : IsNilpotent L (M₁ ⊔ M₂ : LieSubmodule R L M) := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent R L M₁ obtain ⟨l, hl⟩ := IsNilpotent.nilpotent R L M₂ let lcs_eq_bot {m n} (N : LieSubmodule R L M) (le : m ≤ n) (hn : lowerCentralSeries R L N m = ⊥) : lowerCentralSeries R L N n = ⊥ := by simpa [hn] using antitone_lowerCentralSeries R L N le have h₁ : lowerCentralSeries R L M₁ (k ⊔ l) = ⊥ := lcs_eq_bot M₁ (Nat.le_max_left k l) hk have h₂ : lowerCentralSeries R L M₂ (k ⊔ l) = ⊥ := lcs_eq_bot M₂ (Nat.le_max_right k l) hl refine (isNilpotent_iff R L (M₁ + M₂)).mpr ⟨k ⊔ l, ?_⟩ simp [LieSubmodule.add_eq_sup, (M₁ ⊔ M₂).lowerCentralSeries_eq_lcs_comap, LieSubmodule.lcs_sup, (M₁.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₁, (M₂.lowerCentralSeries_eq_bot_iff_lcs_eq_bot (k ⊔ l)).1 h₂, LieSubmodule.comap_incl_eq_bot] theorem exists_forall_pow_toEnd_eq_zero [IsNilpotent L M] : ∃ k : ℕ, ∀ x : L, toEnd R L M x ^ k = 0 := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M use k intro x; ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← @LieSubmodule.mem_bot R L M, ← hM] exact iterate_toEnd_mem_lowerCentralSeries R L M x m k theorem isNilpotent_toEnd_of_isNilpotent [IsNilpotent L M] (x : L) : _root_.IsNilpotent (toEnd R L M x) := by change ∃ k, toEnd R L M x ^ k = 0 have := exists_forall_pow_toEnd_eq_zero R L M tauto theorem isNilpotent_toEnd_of_isNilpotent₂ [IsNilpotent L M] (x y : L) : _root_.IsNilpotent (toEnd R L M x ∘ₗ toEnd R L M y) := by obtain ⟨k, hM⟩ := IsNilpotent.nilpotent R L M replace hM : lowerCentralSeries R L M (2 * k) = ⊥ := by rw [eq_bot_iff, ← hM]; exact antitone_lowerCentralSeries R L M (by omega) use k ext m rw [Module.End.pow_apply, LinearMap.zero_apply, ← LieSubmodule.mem_bot (R := R) (L := L), ← hM] exact iterate_toEnd_mem_lowerCentralSeries₂ R L M x y m k @[simp] lemma maxGenEigenSpace_toEnd_eq_top [IsNilpotent L M] (x : L) : ((toEnd R L M x).maxGenEigenspace 0) = ⊤ := by ext m simp only [Module.End.mem_maxGenEigenspace, zero_smul, sub_zero, Submodule.mem_top, iff_true] obtain ⟨k, hk⟩ := exists_forall_pow_toEnd_eq_zero R L M exact ⟨k, by simp [hk x]⟩ /-- If the quotient of a Lie module `M` by a Lie submodule on which the Lie algebra acts trivially is nilpotent then `M` is nilpotent. This is essentially the Lie module equivalent of the fact that a central extension of nilpotent Lie algebras is nilpotent. See `LieAlgebra.nilpotent_of_nilpotent_quotient` below for the corresponding result for Lie algebras. -/ theorem nilpotentOfNilpotentQuotient {N : LieSubmodule R L M} (h₁ : N ≤ maxTrivSubmodule R L M) (h₂ : IsNilpotent L (M ⧸ N)) : IsNilpotent L M := by rw [isNilpotent_iff R L] at h₂ ⊢ obtain ⟨k, hk⟩ := h₂ use k + 1 simp only [lowerCentralSeries_succ] suffices lowerCentralSeries R L M k ≤ N by replace this := LieSubmodule.mono_lie_right ⊤ (le_trans this h₁) rwa [ideal_oper_maxTrivSubmodule_eq_bot, le_bot_iff] at this rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, ← le_bot_iff, ← hk] exact map_lowerCentralSeries_le k (LieSubmodule.Quotient.mk' N) theorem isNilpotent_quotient_iff : IsNilpotent L (M ⧸ N) ↔ ∃ k, lowerCentralSeries R L M k ≤ N := by rw [isNilpotent_iff R L] refine exists_congr fun k ↦ ?_ rw [← LieSubmodule.Quotient.map_mk'_eq_bot_le, map_lowerCentralSeries_eq k (LieSubmodule.Quotient.surjective_mk' N)] theorem iInf_lcs_le_of_isNilpotent_quot (h : IsNilpotent L (M ⧸ N)) : ⨅ k, lowerCentralSeries R L M k ≤ N := by obtain ⟨k, hk⟩ := (isNilpotent_quotient_iff R L M N).mp h exact iInf_le_of_le k hk end /-- Given a nilpotent Lie module `M` with lower central series `M = C₀ ≥ C₁ ≥ ⋯ ≥ Cₖ = ⊥`, this is the natural number `k` (the number of inclusions). For a non-nilpotent module, we use the junk value 0. -/ noncomputable def nilpotencyLength : ℕ := sInf {k | lowerCentralSeries ℤ L M k = ⊥} @[simp] theorem nilpotencyLength_eq_zero_iff [IsNilpotent L M] : nilpotencyLength L M = 0 ↔ Subsingleton M := by let s := {k | lowerCentralSeries ℤ L M k = ⊥} have hs : s.Nonempty := by obtain ⟨k, hk⟩ := IsNilpotent.nilpotent ℤ L M exact ⟨k, hk⟩ change sInf s = 0 ↔ _ rw [← LieSubmodule.subsingleton_iff ℤ L M, ← subsingleton_iff_bot_eq_top, ← lowerCentralSeries_zero, @eq_comm (LieSubmodule ℤ L M)] refine ⟨fun h => h ▸ Nat.sInf_mem hs, fun h => ?_⟩ rw [Nat.sInf_eq_zero]
exact Or.inl h section variable [LieModule R L M] theorem nilpotencyLength_eq_succ_iff (k : ℕ) : nilpotencyLength L M = k + 1 ↔ lowerCentralSeries R L M (k + 1) = ⊥ ∧ lowerCentralSeries R L M k ≠ ⊥ := by have aux (k : ℕ) : lowerCentralSeries R L M k = ⊥ ↔ lowerCentralSeries ℤ L M k = ⊥ := by simp [SetLike.ext'_iff, coe_lowerCentralSeries_eq_int R L M] let s := {k | lowerCentralSeries ℤ L M k = ⊥} rw [aux, ne_eq, aux] change sInf s = k + 1 ↔ k + 1 ∈ s ∧ k ∉ s have hs : ∀ k₁ k₂, k₁ ≤ k₂ → k₁ ∈ s → k₂ ∈ s := by rintro k₁ k₂ h₁₂ (h₁ : lowerCentralSeries ℤ L M k₁ = ⊥) exact eq_bot_iff.mpr (h₁ ▸ antitone_lowerCentralSeries ℤ L M h₁₂)
Mathlib/Algebra/Lie/Nilpotent.lean
406
422
/- Copyright (c) 2019 Johan Commelin. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin, Kenny Lau -/ import Mathlib.Algebra.Order.Antidiag.Finsupp import Mathlib.Data.Finsupp.Weight import Mathlib.Tactic.Linarith import Mathlib.LinearAlgebra.Pi import Mathlib.Algebra.MvPolynomial.Eval /-! # Formal (multivariate) power series This file defines multivariate formal power series and develops the basic properties of these objects. A formal power series is to a polynomial like an infinite sum is to a finite sum. We provide the natural inclusion from multivariate polynomials to multivariate formal power series. ## Main definitions - `MvPowerSeries.C`: constant power series - `MvPowerSeries.X`: the indeterminates - `MvPowerSeries.coeff`, `MvPowerSeries.constantCoeff`: the coefficients of a `MvPowerSeries`, its constant coefficient - `MvPowerSeries.monomial`: the monomials - `MvPowerSeries.coeff_mul`: computes the coefficients of the product of two `MvPowerSeries` - `MvPowerSeries.coeff_prod` : computes the coefficients of products of `MvPowerSeries` - `MvPowerSeries.coeff_pow` : computes the coefficients of powers of a `MvPowerSeries` - `MvPowerSeries.coeff_eq_zero_of_constantCoeff_nilpotent`: if the constant coefficient of a `MvPowerSeries` is nilpotent, then some coefficients of its powers are automatically zero - `MvPowerSeries.map`: apply a `RingHom` to the coefficients of a `MvPowerSeries` (as a `RingHom) - `MvPowerSeries.X_pow_dvd_iff`, `MvPowerSeries.X_dvd_iff`: equivalent conditions for (a power of) an indeterminate to divide a `MvPowerSeries` - `MvPolynomial.toMvPowerSeries`: the canonical coercion from `MvPolynomial` to `MvPowerSeries` ## Note This file sets up the (semi)ring structure on multivariate power series: additional results are in: * `Mathlib.RingTheory.MvPowerSeries.Inverse` : invertibility, formal power series over a local ring form a local ring; * `Mathlib.RingTheory.MvPowerSeries.Trunc`: truncation of power series. In `Mathlib.RingTheory.PowerSeries.Basic`, formal power series in one variable will be obtained as a particular case, defined by `PowerSeries R := MvPowerSeries Unit R`. See that file for a specific description. ## Implementation notes In this file we define multivariate formal power series with variables indexed by `σ` and coefficients in `R` as `MvPowerSeries σ R := (σ →₀ ℕ) → R`. Unfortunately there is not yet enough API to show that they are the completion of the ring of multivariate polynomials. However, we provide most of the infrastructure that is needed to do this. Once I-adic completion (topological or algebraic) is available it should not be hard to fill in the details. -/ noncomputable section open Finset (antidiagonal mem_antidiagonal) /-- Multivariate formal power series, where `σ` is the index set of the variables and `R` is the coefficient ring. -/ def MvPowerSeries (σ : Type*) (R : Type*) := (σ →₀ ℕ) → R namespace MvPowerSeries open Finsupp variable {σ R : Type*} instance [Inhabited R] : Inhabited (MvPowerSeries σ R) := ⟨fun _ => default⟩ instance [Zero R] : Zero (MvPowerSeries σ R) := Pi.instZero instance [AddMonoid R] : AddMonoid (MvPowerSeries σ R) := Pi.addMonoid instance [AddGroup R] : AddGroup (MvPowerSeries σ R) := Pi.addGroup instance [AddCommMonoid R] : AddCommMonoid (MvPowerSeries σ R) := Pi.addCommMonoid instance [AddCommGroup R] : AddCommGroup (MvPowerSeries σ R) := Pi.addCommGroup instance [Nontrivial R] : Nontrivial (MvPowerSeries σ R) := Function.nontrivial instance {A} [Semiring R] [AddCommMonoid A] [Module R A] : Module R (MvPowerSeries σ A) := Pi.module _ _ _ instance {A S} [Semiring R] [Semiring S] [AddCommMonoid A] [Module R A] [Module S A] [SMul R S] [IsScalarTower R S A] : IsScalarTower R S (MvPowerSeries σ A) := Pi.isScalarTower section Semiring variable (R) [Semiring R] /-- The `n`th monomial as multivariate formal power series: it is defined as the `R`-linear map from `R` to the semi-ring of multivariate formal power series associating to each `a` the map sending `n : σ →₀ ℕ` to the value `a` and sending all other `x : σ →₀ ℕ` different from `n` to `0`. -/ def monomial (n : σ →₀ ℕ) : R →ₗ[R] MvPowerSeries σ R := letI := Classical.decEq σ LinearMap.single R (fun _ ↦ R) n /-- The `n`th coefficient of a multivariate formal power series. -/ def coeff (n : σ →₀ ℕ) : MvPowerSeries σ R →ₗ[R] R := LinearMap.proj n theorem coeff_apply (f : MvPowerSeries σ R) (d : σ →₀ ℕ) : coeff R d f = f d := rfl variable {R} /-- Two multivariate formal power series are equal if all their coefficients are equal. -/ @[ext] theorem ext {φ ψ} (h : ∀ n : σ →₀ ℕ, coeff R n φ = coeff R n ψ) : φ = ψ := funext h /-- Two multivariate formal power series are equal if and only if all their coefficients are equal. -/ add_decl_doc MvPowerSeries.ext_iff theorem monomial_def [DecidableEq σ] (n : σ →₀ ℕ) : (monomial R n) = LinearMap.single R (fun _ ↦ R) n := by rw [monomial] -- unify the `Decidable` arguments convert rfl theorem coeff_monomial [DecidableEq σ] (m n : σ →₀ ℕ) (a : R) : coeff R m (monomial R n a) = if m = n then a else 0 := by dsimp only [coeff, MvPowerSeries] rw [monomial_def, LinearMap.proj_apply (i := m), LinearMap.single_apply, Pi.single_apply] @[simp] theorem coeff_monomial_same (n : σ →₀ ℕ) (a : R) : coeff R n (monomial R n a) = a := by classical rw [monomial_def] exact Pi.single_eq_same _ _ theorem coeff_monomial_ne {m n : σ →₀ ℕ} (h : m ≠ n) (a : R) : coeff R m (monomial R n a) = 0 := by classical rw [monomial_def] exact Pi.single_eq_of_ne h _ theorem eq_of_coeff_monomial_ne_zero {m n : σ →₀ ℕ} {a : R} (h : coeff R m (monomial R n a) ≠ 0) : m = n := by_contra fun h' => h <| coeff_monomial_ne h' a @[simp] theorem coeff_comp_monomial (n : σ →₀ ℕ) : (coeff R n).comp (monomial R n) = LinearMap.id := LinearMap.ext <| coeff_monomial_same n @[simp] theorem coeff_zero (n : σ →₀ ℕ) : coeff R n (0 : MvPowerSeries σ R) = 0 := rfl theorem eq_zero_iff_forall_coeff_zero {f : MvPowerSeries σ R} : f = 0 ↔ (∀ d : σ →₀ ℕ, coeff R d f = 0) := MvPowerSeries.ext_iff theorem ne_zero_iff_exists_coeff_ne_zero (f : MvPowerSeries σ R) : f ≠ 0 ↔ (∃ d : σ →₀ ℕ, coeff R d f ≠ 0) := by simp only [MvPowerSeries.ext_iff, ne_eq, coeff_zero, not_forall] variable (m n : σ →₀ ℕ) (φ ψ : MvPowerSeries σ R) instance : One (MvPowerSeries σ R) := ⟨monomial R (0 : σ →₀ ℕ) 1⟩ theorem coeff_one [DecidableEq σ] : coeff R n (1 : MvPowerSeries σ R) = if n = 0 then 1 else 0 := coeff_monomial _ _ _ theorem coeff_zero_one : coeff R (0 : σ →₀ ℕ) 1 = 1 := coeff_monomial_same 0 1 theorem monomial_zero_one : monomial R (0 : σ →₀ ℕ) 1 = 1 := rfl instance : AddMonoidWithOne (MvPowerSeries σ R) := { show AddMonoid (MvPowerSeries σ R) by infer_instance with natCast := fun n => monomial R 0 n natCast_zero := by simp [Nat.cast] natCast_succ := by simp [Nat.cast, monomial_zero_one] one := 1 } instance : Mul (MvPowerSeries σ R) := letI := Classical.decEq σ ⟨fun φ ψ n => ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ⟩ theorem coeff_mul [DecidableEq σ] : coeff R n (φ * ψ) = ∑ p ∈ antidiagonal n, coeff R p.1 φ * coeff R p.2 ψ := by refine Finset.sum_congr ?_ fun _ _ => rfl rw [Subsingleton.elim (Classical.decEq σ) ‹DecidableEq σ›] protected theorem zero_mul : (0 : MvPowerSeries σ R) * φ = 0 := ext fun n => by classical simp [coeff_mul] protected theorem mul_zero : φ * 0 = 0 := ext fun n => by classical simp [coeff_mul] theorem coeff_monomial_mul (a : R) : coeff R m (monomial R n a * φ) = if n ≤ m then a * coeff R (m - n) φ else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 (monomial R n a) * coeff R p.2 φ ≠ 0 → p.1 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (left_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_fst_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] theorem coeff_mul_monomial (a : R) : coeff R m (φ * monomial R n a) = if n ≤ m then coeff R (m - n) φ * a else 0 := by classical have : ∀ p ∈ antidiagonal m, coeff R (p : (σ →₀ ℕ) × (σ →₀ ℕ)).1 φ * coeff R p.2 (monomial R n a) ≠ 0 → p.2 = n := fun p _ hp => eq_of_coeff_monomial_ne_zero (right_ne_zero_of_mul hp) rw [coeff_mul, ← Finset.sum_filter_of_ne this, Finset.filter_snd_eq_antidiagonal _ n, Finset.sum_ite_index] simp only [Finset.sum_singleton, coeff_monomial_same, Finset.sum_empty] theorem coeff_add_monomial_mul (a : R) : coeff R (m + n) (monomial R m a * φ) = a * coeff R n φ := by rw [coeff_monomial_mul, if_pos, add_tsub_cancel_left] exact le_add_right le_rfl theorem coeff_add_mul_monomial (a : R) : coeff R (m + n) (φ * monomial R n a) = coeff R m φ * a := by rw [coeff_mul_monomial, if_pos, add_tsub_cancel_right] exact le_add_left le_rfl @[simp] theorem commute_monomial {a : R} {n} : Commute φ (monomial R n a) ↔ ∀ m, Commute (coeff R m φ) a := by rw [commute_iff_eq, MvPowerSeries.ext_iff] refine ⟨fun h m => ?_, fun h m => ?_⟩ · have := h (m + n) rwa [coeff_add_mul_monomial, add_comm, coeff_add_monomial_mul] at this · rw [coeff_mul_monomial, coeff_monomial_mul] split_ifs <;> [apply h; rfl] protected theorem one_mul : (1 : MvPowerSeries σ R) * φ = φ := ext fun n => by simpa using coeff_add_monomial_mul 0 n φ 1 protected theorem mul_one : φ * 1 = φ := ext fun n => by simpa using coeff_add_mul_monomial n 0 φ 1 protected theorem mul_add (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * (φ₂ + φ₃) = φ₁ * φ₂ + φ₁ * φ₃ := ext fun n => by classical simp only [coeff_mul, mul_add, Finset.sum_add_distrib, LinearMap.map_add] protected theorem add_mul (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : (φ₁ + φ₂) * φ₃ = φ₁ * φ₃ + φ₂ * φ₃ := ext fun n => by classical simp only [coeff_mul, add_mul, Finset.sum_add_distrib, LinearMap.map_add] protected theorem mul_assoc (φ₁ φ₂ φ₃ : MvPowerSeries σ R) : φ₁ * φ₂ * φ₃ = φ₁ * (φ₂ * φ₃) := by ext1 n classical simp only [coeff_mul, Finset.sum_mul, Finset.mul_sum, Finset.sum_sigma'] apply Finset.sum_nbij' (fun ⟨⟨_i, j⟩, ⟨k, l⟩⟩ ↦ ⟨(k, l + j), (l, j)⟩) (fun ⟨⟨i, _j⟩, ⟨k, l⟩⟩ ↦ ⟨(i + k, l), (i, k)⟩) <;> aesop (add simp [add_assoc, mul_assoc]) instance : Semiring (MvPowerSeries σ R) := { inferInstanceAs (AddMonoidWithOne (MvPowerSeries σ R)), inferInstanceAs (Mul (MvPowerSeries σ R)), inferInstanceAs (AddCommMonoid (MvPowerSeries σ R)) with mul_one := MvPowerSeries.mul_one one_mul := MvPowerSeries.one_mul mul_assoc := MvPowerSeries.mul_assoc mul_zero := MvPowerSeries.mul_zero zero_mul := MvPowerSeries.zero_mul left_distrib := MvPowerSeries.mul_add right_distrib := MvPowerSeries.add_mul } end Semiring instance [CommSemiring R] : CommSemiring (MvPowerSeries σ R) := { show Semiring (MvPowerSeries σ R) by infer_instance with mul_comm := fun φ ψ => ext fun n => by classical simpa only [coeff_mul, mul_comm] using sum_antidiagonal_swap n fun a b => coeff R a φ * coeff R b ψ } instance [Ring R] : Ring (MvPowerSeries σ R) := { inferInstanceAs (Semiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } instance [CommRing R] : CommRing (MvPowerSeries σ R) := { inferInstanceAs (CommSemiring (MvPowerSeries σ R)), inferInstanceAs (AddCommGroup (MvPowerSeries σ R)) with } section Semiring variable [Semiring R] theorem monomial_mul_monomial (m n : σ →₀ ℕ) (a b : R) : monomial R m a * monomial R n b = monomial R (m + n) (a * b) := by classical ext k simp only [coeff_mul_monomial, coeff_monomial] split_ifs with h₁ h₂ h₃ h₃ h₂ <;> try rfl · rw [← h₂, tsub_add_cancel_of_le h₁] at h₃ exact (h₃ rfl).elim · rw [h₃, add_tsub_cancel_right] at h₂ exact (h₂ rfl).elim · exact zero_mul b · rw [h₂] at h₁ exact (h₁ <| le_add_left le_rfl).elim variable (σ) (R) /-- The constant multivariate formal power series. -/ def C : R →+* MvPowerSeries σ R := { monomial R (0 : σ →₀ ℕ) with map_one' := rfl map_mul' := fun a b => (monomial_mul_monomial 0 0 a b).symm map_zero' := (monomial R 0).map_zero } variable {σ} {R} @[simp] theorem monomial_zero_eq_C : ⇑(monomial R (0 : σ →₀ ℕ)) = C σ R := rfl theorem monomial_zero_eq_C_apply (a : R) : monomial R (0 : σ →₀ ℕ) a = C σ R a := rfl theorem coeff_C [DecidableEq σ] (n : σ →₀ ℕ) (a : R) : coeff R n (C σ R a) = if n = 0 then a else 0 := coeff_monomial _ _ _ theorem coeff_zero_C (a : R) : coeff R (0 : σ →₀ ℕ) (C σ R a) = a := coeff_monomial_same 0 a /-- The variables of the multivariate formal power series ring. -/ def X (s : σ) : MvPowerSeries σ R := monomial R (single s 1) 1 theorem coeff_X [DecidableEq σ] (n : σ →₀ ℕ) (s : σ) : coeff R n (X s : MvPowerSeries σ R) = if n = single s 1 then 1 else 0 := coeff_monomial _ _ _ theorem coeff_index_single_X [DecidableEq σ] (s t : σ) : coeff R (single t 1) (X s : MvPowerSeries σ R) = if t = s then 1 else 0 := by simp only [coeff_X, single_left_inj (one_ne_zero : (1 : ℕ) ≠ 0)] @[simp] theorem coeff_index_single_self_X (s : σ) : coeff R (single s 1) (X s : MvPowerSeries σ R) = 1 := coeff_monomial_same _ _ theorem coeff_zero_X (s : σ) : coeff R (0 : σ →₀ ℕ) (X s : MvPowerSeries σ R) = 0 := by classical rw [coeff_X, if_neg] intro h exact one_ne_zero (single_eq_zero.mp h.symm) theorem commute_X (φ : MvPowerSeries σ R) (s : σ) : Commute φ (X s) := φ.commute_monomial.mpr fun _m => Commute.one_right _ theorem X_mul {φ : MvPowerSeries σ R} {s : σ} : X s * φ = φ * X s := φ.commute_X s |>.symm.eq theorem commute_X_pow (φ : MvPowerSeries σ R) (s : σ) (n : ℕ) : Commute φ (X s ^ n) := φ.commute_X s |>.pow_right _ theorem X_pow_mul {φ : MvPowerSeries σ R} {s : σ} {n : ℕ} : X s ^ n * φ = φ * X s ^ n := φ.commute_X_pow s n |>.symm.eq theorem X_def (s : σ) : X s = monomial R (single s 1) 1 := rfl theorem X_pow_eq (s : σ) (n : ℕ) : (X s : MvPowerSeries σ R) ^ n = monomial R (single s n) 1 := by induction n with | zero => simp | succ n ih => rw [pow_succ, ih, Finsupp.single_add, X, monomial_mul_monomial, one_mul] theorem coeff_X_pow [DecidableEq σ] (m : σ →₀ ℕ) (s : σ) (n : ℕ) : coeff R m ((X s : MvPowerSeries σ R) ^ n) = if m = single s n then 1 else 0 := by rw [X_pow_eq s n, coeff_monomial] @[simp] theorem coeff_mul_C (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (φ * C σ R a) = coeff R n φ * a := by simpa using coeff_add_mul_monomial n 0 φ a @[simp] theorem coeff_C_mul (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) (a : R) : coeff R n (C σ R a * φ) = a * coeff R n φ := by simpa using coeff_add_monomial_mul 0 n φ a theorem coeff_zero_mul_X (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (φ * X s) = 0 := by have : ¬single s 1 ≤ 0 := fun h => by simpa using h s simp only [X, coeff_mul_monomial, if_neg this] theorem coeff_zero_X_mul (φ : MvPowerSeries σ R) (s : σ) : coeff R (0 : σ →₀ ℕ) (X s * φ) = 0 := by rw [← (φ.commute_X s).eq, coeff_zero_mul_X] variable (σ) (R) /-- The constant coefficient of a formal power series. -/ def constantCoeff : MvPowerSeries σ R →+* R := { coeff R (0 : σ →₀ ℕ) with toFun := coeff R (0 : σ →₀ ℕ) map_one' := coeff_zero_one map_mul' := fun φ ψ => by classical simp [coeff_mul, support_single_ne_zero] map_zero' := LinearMap.map_zero _ } variable {σ} {R} @[simp] theorem coeff_zero_eq_constantCoeff : ⇑(coeff R (0 : σ →₀ ℕ)) = constantCoeff σ R := rfl theorem coeff_zero_eq_constantCoeff_apply (φ : MvPowerSeries σ R) : coeff R (0 : σ →₀ ℕ) φ = constantCoeff σ R φ := rfl @[simp] theorem constantCoeff_C (a : R) : constantCoeff σ R (C σ R a) = a := rfl @[simp] theorem constantCoeff_comp_C : (constantCoeff σ R).comp (C σ R) = RingHom.id R := rfl @[simp] theorem constantCoeff_zero : constantCoeff σ R 0 = 0 := rfl @[simp] theorem constantCoeff_one : constantCoeff σ R 1 = 1 := rfl @[simp] theorem constantCoeff_X (s : σ) : constantCoeff σ R (X s) = 0 := coeff_zero_X s @[simp] theorem constantCoeff_smul {S : Type*} [Semiring S] [Module R S] (φ : MvPowerSeries σ S) (a : R) : constantCoeff σ S (a • φ) = a • constantCoeff σ S φ := rfl /-- If a multivariate formal power series is invertible, then so is its constant coefficient. -/ theorem isUnit_constantCoeff (φ : MvPowerSeries σ R) (h : IsUnit φ) : IsUnit (constantCoeff σ R φ) := h.map _ @[simp] theorem coeff_smul (f : MvPowerSeries σ R) (n) (a : R) : coeff _ n (a • f) = a * coeff _ n f := rfl theorem smul_eq_C_mul (f : MvPowerSeries σ R) (a : R) : a • f = C σ R a * f := by ext simp theorem X_inj [Nontrivial R] {s t : σ} : (X s : MvPowerSeries σ R) = X t ↔ s = t := ⟨by classical intro h replace h := congr_arg (coeff R (single s 1)) h rw [coeff_X, if_pos rfl, coeff_X] at h split_ifs at h with H · rw [Finsupp.single_eq_single_iff] at H rcases H with H | H · exact H.1 · exfalso exact one_ne_zero H.1 · exfalso exact one_ne_zero h, congr_arg X⟩ end Semiring section Map variable {S T : Type*} [Semiring R] [Semiring S] [Semiring T] variable (f : R →+* S) (g : S →+* T) variable (σ) in /-- The map between multivariate formal power series induced by a map on the coefficients. -/ def map : MvPowerSeries σ R →+* MvPowerSeries σ S where toFun φ n := f <| coeff R n φ map_zero' := ext fun _n => f.map_zero map_one' := ext fun n => show f ((coeff R n) 1) = (coeff S n) 1 by classical rw [coeff_one, coeff_one] split_ifs with h · simp only [ite_true, map_one, h] · simp only [ite_false, map_zero, h] map_add' φ ψ := ext fun n => show f ((coeff R n) (φ + ψ)) = f ((coeff R n) φ) + f ((coeff R n) ψ) by simp map_mul' φ ψ := ext fun n => show f _ = _ by classical rw [coeff_mul, map_sum, coeff_mul] apply Finset.sum_congr rfl rintro ⟨i, j⟩ _; rw [f.map_mul]; rfl @[simp] theorem map_id : map σ (RingHom.id R) = RingHom.id _ := rfl theorem map_comp : map σ (g.comp f) = (map σ g).comp (map σ f) := rfl @[simp] theorem coeff_map (n : σ →₀ ℕ) (φ : MvPowerSeries σ R) : coeff S n (map σ f φ) = f (coeff R n φ) := rfl @[simp] theorem constantCoeff_map (φ : MvPowerSeries σ R) : constantCoeff σ S (map σ f φ) = f (constantCoeff σ R φ) := rfl @[simp] theorem map_monomial (n : σ →₀ ℕ) (a : R) : map σ f (monomial R n a) = monomial S n (f a) := by classical ext m simp [coeff_monomial, apply_ite f] @[simp] theorem map_C (a : R) : map σ f (C σ R a) = C σ S (f a) := map_monomial _ _ _ @[simp] theorem map_X (s : σ) : map σ f (X s) = X s := by simp [MvPowerSeries.X] end Map @[simp] theorem map_eq_zero {S : Type*} [DivisionSemiring R] [Semiring S] [Nontrivial S] (φ : MvPowerSeries σ R) (f : R →+* S) : φ.map σ f = 0 ↔ φ = 0 := by simp only [MvPowerSeries.ext_iff] congr! with n simp section Semiring variable [Semiring R] theorem X_pow_dvd_iff {s : σ} {n : ℕ} {φ : MvPowerSeries σ R} : (X s : MvPowerSeries σ R) ^ n ∣ φ ↔ ∀ m : σ →₀ ℕ, m s < n → coeff R m φ = 0 := by classical constructor · rintro ⟨φ, rfl⟩ m h rw [coeff_mul, Finset.sum_eq_zero] rintro ⟨i, j⟩ hij rw [coeff_X_pow, if_neg, zero_mul] contrapose! h dsimp at h subst i rw [mem_antidiagonal] at hij rw [← hij, Finsupp.add_apply, Finsupp.single_eq_same] exact Nat.le_add_right n _ · intro h refine ⟨fun m => coeff R (m + single s n) φ, ?_⟩ ext m by_cases H : m - single s n + single s n = m
· rw [coeff_mul, Finset.sum_eq_single (single s n, m - single s n)] · rw [coeff_X_pow, if_pos rfl, one_mul] simpa using congr_arg (fun m : σ →₀ ℕ => coeff R m φ) H.symm · rintro ⟨i, j⟩ hij hne
Mathlib/RingTheory/MvPowerSeries/Basic.lean
590
593
/- 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 -/ import Mathlib.Data.Finset.BooleanAlgebra import Mathlib.Data.Set.Piecewise import Mathlib.Order.Interval.Set.Basic /-! # Functions defined piecewise on a finset This file defines `Finset.piecewise`: Given two functions `f`, `g`, `s.piecewise f g` is a function which is equal to `f` on `s` and `g` on the complement. ## TODO Should we deduplicate this from `Set.piecewise`? -/ open Function namespace Finset variable {ι : Type*} {π : ι → Sort*} (s : Finset ι) (f g : ∀ i, π i) /-- `s.piecewise f g` is the function equal to `f` on the finset `s`, and to `g` on its complement. -/ def piecewise [∀ j, Decidable (j ∈ s)] : ∀ i, π i := fun i ↦ if i ∈ s then f i else g i lemma piecewise_insert_self [DecidableEq ι] {j : ι} [∀ i, Decidable (i ∈ insert j s)] : (insert j s).piecewise f g j = f j := by simp [piecewise] @[simp] lemma piecewise_empty [∀ i : ι, Decidable (i ∈ (∅ : Finset ι))] : piecewise ∅ f g = g := by ext i simp [piecewise] variable [∀ j, Decidable (j ∈ s)] -- TODO: fix this in norm_cast @[norm_cast move] lemma piecewise_coe [∀ j, Decidable (j ∈ (s : Set ι))] : (s : Set ι).piecewise f g = s.piecewise f g := by ext congr @[simp] lemma piecewise_eq_of_mem {i : ι} (hi : i ∈ s) : s.piecewise f g i = f i := by simp [piecewise, hi] @[simp] lemma piecewise_eq_of_not_mem {i : ι} (hi : i ∉ s) : s.piecewise f g i = g i := by simp [piecewise, hi] lemma piecewise_congr {f f' g g' : ∀ i, π i} (hf : ∀ i ∈ s, f i = f' i) (hg : ∀ i ∉ s, g i = g' i) : s.piecewise f g = s.piecewise f' g' := funext fun i => if_ctx_congr Iff.rfl (hf i) (hg i) @[simp] lemma piecewise_insert_of_ne [DecidableEq ι] {i j : ι} [∀ i, Decidable (i ∈ insert j s)] (h : i ≠ j) : (insert j s).piecewise f g i = s.piecewise f g i := by simp [piecewise, h] lemma piecewise_insert [DecidableEq ι] (j : ι) [∀ i, Decidable (i ∈ insert j s)] : (insert j s).piecewise f g = update (s.piecewise f g) j (f j) := by classical simp only [← piecewise_coe, coe_insert, ← Set.piecewise_insert]
ext congr simp
Mathlib/Data/Finset/Piecewise.lean
66
68
/- Copyright (c) 2018 Chris Hughes. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Chris Hughes, Joey van Langen, Casper Putz -/ import Mathlib.Algebra.CharP.Algebra import Mathlib.Algebra.CharP.Reduced import Mathlib.Algebra.Field.ZMod import Mathlib.Data.Nat.Prime.Int import Mathlib.Data.ZMod.ValMinAbs import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix import Mathlib.FieldTheory.Finiteness import Mathlib.FieldTheory.Perfect import Mathlib.FieldTheory.Separable import Mathlib.RingTheory.IntegralDomain /-! # Finite fields This file contains basic results about finite fields. Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. See `RingTheory.IntegralDomain` for the fact that the unit group of a finite field is a cyclic group, as well as the fact that every finite integral domain is a field (`Fintype.fieldOfDomain`). ## Main results 1. `Fintype.card_units`: The unit group of a finite field has cardinality `q - 1`. 2. `sum_pow_units`: The sum of `x^i`, where `x` ranges over the units of `K`, is - `q-1` if `q-1 ∣ i` - `0` otherwise 3. `FiniteField.card`: The cardinality `q` is a power of the characteristic of `K`. See `FiniteField.card'` for a variant. ## Notation Throughout most of this file, `K` denotes a finite field and `q` is notation for the cardinality of `K`. ## Implementation notes While `Fintype Kˣ` can be inferred from `Fintype K` in the presence of `DecidableEq K`, in this file we take the `Fintype Kˣ` argument directly to reduce the chance of typeclass diamonds, as `Fintype` carries data. -/ variable {K : Type*} {R : Type*} local notation "q" => Fintype.card K open Finset open scoped Polynomial namespace FiniteField section Polynomial variable [CommRing R] [IsDomain R] open Polynomial /-- The cardinality of a field is at most `n` times the cardinality of the image of a degree `n` polynomial -/ theorem card_image_polynomial_eval [DecidableEq R] [Fintype R] {p : R[X]} (hp : 0 < p.degree) : Fintype.card R ≤ natDegree p * #(univ.image fun x => eval x p) := Finset.card_le_mul_card_image _ _ (fun a _ => calc _ = #(p - C a).roots.toFinset := congr_arg card (by simp [Finset.ext_iff, ← mem_roots_sub_C hp]) _ ≤ Multiset.card (p - C a).roots := Multiset.toFinset_card_le _ _ ≤ _ := card_roots_sub_C' hp) /-- If `f` and `g` are quadratic polynomials, then the `f.eval a + g.eval b = 0` has a solution. -/ theorem exists_root_sum_quadratic [Fintype R] {f g : R[X]} (hf2 : degree f = 2) (hg2 : degree g = 2) (hR : Fintype.card R % 2 = 1) : ∃ a b, f.eval a + g.eval b = 0 := letI := Classical.decEq R suffices ¬Disjoint (univ.image fun x : R => eval x f) (univ.image fun x : R => eval x (-g)) by simp only [disjoint_left, mem_image] at this push_neg at this rcases this with ⟨x, ⟨a, _, ha⟩, ⟨b, _, hb⟩⟩ exact ⟨a, b, by rw [ha, ← hb, eval_neg, neg_add_cancel]⟩ fun hd : Disjoint _ _ => lt_irrefl (2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g))) <| calc 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) ≤ 2 * Fintype.card R := Nat.mul_le_mul_left _ (Finset.card_le_univ _) _ = Fintype.card R + Fintype.card R := two_mul _ _ < natDegree f * #(univ.image fun x : R => eval x f) + natDegree (-g) * #(univ.image fun x : R => eval x (-g)) := (add_lt_add_of_lt_of_le (lt_of_le_of_ne (card_image_polynomial_eval (by rw [hf2]; decide)) (mt (congr_arg (· % 2)) (by simp [natDegree_eq_of_degree_eq_some hf2, hR]))) (card_image_polynomial_eval (by rw [degree_neg, hg2]; decide))) _ = 2 * #((univ.image fun x : R => eval x f) ∪ univ.image fun x : R => eval x (-g)) := by rw [card_union_of_disjoint hd] simp [natDegree_eq_of_degree_eq_some hf2, natDegree_eq_of_degree_eq_some hg2, mul_add] end Polynomial theorem prod_univ_units_id_eq_neg_one [CommRing K] [IsDomain K] [Fintype Kˣ] : ∏ x : Kˣ, x = (-1 : Kˣ) := by classical have : (∏ x ∈ (@univ Kˣ _).erase (-1), x) = 1 := prod_involution (fun x _ => x⁻¹) (by simp) (fun a => by simp +contextual [Units.inv_eq_self_iff]) (fun a => by simp [@inv_eq_iff_eq_inv _ _ a]) (by simp) rw [← insert_erase (mem_univ (-1 : Kˣ)), prod_insert (not_mem_erase _ _), this, mul_one] theorem card_cast_subgroup_card_ne_zero [Ring K] [NoZeroDivisors K] [Nontrivial K] (G : Subgroup Kˣ) [Fintype G] : (Fintype.card G : K) ≠ 0 := by let n := Fintype.card G intro nzero have ⟨p, char_p⟩ := CharP.exists K have hd : p ∣ n := (CharP.cast_eq_zero_iff K p n).mp nzero cases CharP.char_is_prime_or_zero K p with | inr pzero => exact (Fintype.card_pos).ne' <| Nat.eq_zero_of_zero_dvd <| pzero ▸ hd | inl pprime => have fact_pprime := Fact.mk pprime -- G has an element x of order p by Cauchy's theorem have ⟨x, hx⟩ := exists_prime_orderOf_dvd_card p hd -- F has an element u (= ↑↑x) of order p let u := ((x : Kˣ) : K) have hu : orderOf u = p := by rwa [orderOf_units, Subgroup.orderOf_coe] -- u ^ p = 1 implies (u - 1) ^ p = 0 and hence u = 1 ... have h : u = 1 := by rw [← sub_left_inj, sub_self 1] apply pow_eq_zero (n := p) rw [sub_pow_char_of_commute, one_pow, ← hu, pow_orderOf_eq_one, sub_self] exact Commute.one_right u -- ... meaning x didn't have order p after all, contradiction apply pprime.one_lt.ne rw [← hu, h, orderOf_one] /-- The sum of a nontrivial subgroup of the units of a field is zero. -/ theorem sum_subgroup_units_eq_zero [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] (hg : G ≠ ⊥) : ∑ x : G, (x.val : K) = 0 := by rw [Subgroup.ne_bot_iff_exists_ne_one] at hg rcases hg with ⟨a, ha⟩ -- The action of a on G as an embedding let a_mul_emb : G ↪ G := mulLeftEmbedding a -- ... and leaves G unchanged have h_unchanged : Finset.univ.map a_mul_emb = Finset.univ := by simp -- Therefore the sum of x over a G is the sum of a x over G have h_sum_map := Finset.univ.sum_map a_mul_emb fun x => ((x : Kˣ) : K) -- ... and the former is the sum of x over G. -- By algebraic manipulation, we have Σ G, x = ∑ G, a x = a ∑ G, x simp only [h_unchanged, mulLeftEmbedding_apply, Subgroup.coe_mul, Units.val_mul, ← mul_sum, a_mul_emb] at h_sum_map -- thus one of (a - 1) or ∑ G, x is zero have hzero : (((a : Kˣ) : K) - 1) = 0 ∨ ∑ x : ↥G, ((x : Kˣ) : K) = 0 := by rw [← mul_eq_zero, sub_mul, ← h_sum_map, one_mul, sub_self] apply Or.resolve_left hzero contrapose! ha ext rwa [← sub_eq_zero] /-- The sum of a subgroup of the units of a field is 1 if the subgroup is trivial and 1 otherwise -/ @[simp] theorem sum_subgroup_units [Ring K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] [Decidable (G = ⊥)] : ∑ x : G, (x.val : K) = if G = ⊥ then 1 else 0 := by by_cases G_bot : G = ⊥ · subst G_bot simp only [univ_unique, sum_singleton, ↓reduceIte, Units.val_eq_one, OneMemClass.coe_eq_one] rw [Set.default_coe_singleton] rfl · simp only [G_bot, ite_false] exact sum_subgroup_units_eq_zero G_bot @[simp] theorem sum_subgroup_pow_eq_zero [CommRing K] [NoZeroDivisors K] {G : Subgroup Kˣ} [Fintype G] {k : ℕ} (k_pos : k ≠ 0) (k_lt_card_G : k < Fintype.card G) : ∑ x : G, ((x : Kˣ) : K) ^ k = 0 := by rw [← Nat.card_eq_fintype_card] at k_lt_card_G nontriviality K have := NoZeroDivisors.to_isDomain K rcases (exists_pow_ne_one_of_isCyclic k_pos k_lt_card_G) with ⟨a, ha⟩ rw [Finset.sum_eq_multiset_sum] have h_multiset_map : Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k) = Finset.univ.val.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) := by simp_rw [← mul_pow] have as_comp : (fun x : ↥G => (((x : Kˣ) : K) * ((a : Kˣ) : K)) ^ k) = (fun x : ↥G => ((x : Kˣ) : K) ^ k) ∘ fun x : ↥G => x * a := by funext x simp only [Function.comp_apply, Subgroup.coe_mul, Units.val_mul] rw [as_comp, ← Multiset.map_map] congr rw [eq_comm] exact Multiset.map_univ_val_equiv (Equiv.mulRight a) have h_multiset_map_sum : (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k) Finset.univ.val).sum = (Multiset.map (fun x : G => ((x : Kˣ) : K) ^ k * ((a : Kˣ) : K) ^ k) Finset.univ.val).sum := by rw [h_multiset_map] rw [Multiset.sum_map_mul_right] at h_multiset_map_sum have hzero : (((a : Kˣ) : K) ^ k - 1 : K) * (Multiset.map (fun i : G => (i.val : K) ^ k) Finset.univ.val).sum = 0 := by rw [sub_mul, mul_comm, ← h_multiset_map_sum, one_mul, sub_self] rw [mul_eq_zero] at hzero refine hzero.resolve_left fun h => ha ?_ ext rw [← sub_eq_zero] simp_rw [SubmonoidClass.coe_pow, Units.val_pow_eq_pow_val, OneMemClass.coe_one, Units.val_one, h] section variable [GroupWithZero K] [Fintype K] theorem pow_card_sub_one_eq_one (a : K) (ha : a ≠ 0) : a ^ (q - 1) = 1 := by calc a ^ (Fintype.card K - 1) = (Units.mk0 a ha ^ (Fintype.card K - 1) : Kˣ).1 := by rw [Units.val_pow_eq_pow_val, Units.val_mk0] _ = 1 := by classical rw [← Fintype.card_units, pow_card_eq_one] rfl theorem pow_card (a : K) : a ^ q = a := by by_cases h : a = 0; · rw [h]; apply zero_pow Fintype.card_ne_zero rw [← Nat.succ_pred_eq_of_pos Fintype.card_pos, pow_succ, Nat.pred_eq_sub_one, pow_card_sub_one_eq_one a h, one_mul] theorem pow_card_pow (n : ℕ) (a : K) : a ^ q ^ n = a := by induction n with | zero => simp | succ n ih => simp [pow_succ, pow_mul, ih, pow_card] end variable (K) [Field K] [Fintype K] /-- The cardinality `q` is a power of the characteristic of `K`. -/ @[stacks 09HY "first part"] theorem card (p : ℕ) [CharP K p] : ∃ n : ℕ+, Nat.Prime p ∧ q = p ^ (n : ℕ) := by haveI hp : Fact p.Prime := ⟨CharP.char_is_prime K p⟩ letI : Module (ZMod p) K := { (ZMod.castHom dvd_rfl K : ZMod p →+* _).toModule with } obtain ⟨n, h⟩ := VectorSpace.card_fintype (ZMod p) K rw [ZMod.card] at h refine ⟨⟨n, ?_⟩, hp.1, h⟩ apply Or.resolve_left (Nat.eq_zero_or_pos n) rintro rfl rw [pow_zero] at h have : (0 : K) = 1 := by apply Fintype.card_le_one_iff.mp (le_of_eq h) exact absurd this zero_ne_one -- this statement doesn't use `q` because we want `K` to be an explicit parameter theorem card' : ∃ (p : ℕ), CharP K p ∧ ∃ (n : ℕ+), Nat.Prime p ∧ Fintype.card K = p ^ (n : ℕ) := let ⟨p, hc⟩ := CharP.exists K ⟨p, hc, @FiniteField.card K _ _ p hc⟩ lemma isPrimePow_card : IsPrimePow (Fintype.card K) := by obtain ⟨p, _, n, hp, hn⟩ := card' K exact ⟨p, n, Nat.prime_iff.mp hp, n.prop, hn.symm⟩ theorem cast_card_eq_zero : (q : K) = 0 := by simp theorem forall_pow_eq_one_iff (i : ℕ) : (∀ x : Kˣ, x ^ i = 1) ↔ q - 1 ∣ i := by classical obtain ⟨x, hx⟩ := IsCyclic.exists_generator (α := Kˣ) rw [← Nat.card_eq_fintype_card, ← Nat.card_units, ← orderOf_eq_card_of_forall_mem_zpowers hx, orderOf_dvd_iff_pow_eq_one] constructor · intro h; apply h · intro h y simp_rw [← mem_powers_iff_mem_zpowers] at hx rcases hx y with ⟨j, rfl⟩ rw [← pow_mul, mul_comm, pow_mul, h, one_pow] /-- The sum of `x ^ i` as `x` ranges over the units of a finite field of cardinality `q` is equal to `0` unless `(q - 1) ∣ i`, in which case the sum is `q - 1`. -/ theorem sum_pow_units [DecidableEq K] (i : ℕ) : (∑ x : Kˣ, (x ^ i : K)) = if q - 1 ∣ i then -1 else 0 := by let φ : Kˣ →* K := { toFun := fun x => x ^ i map_one' := by simp map_mul' := by intros; simp [mul_pow] } have : Decidable (φ = 1) := by classical infer_instance calc (∑ x : Kˣ, φ x) = if φ = 1 then Fintype.card Kˣ else 0 := sum_hom_units φ _ = if q - 1 ∣ i then -1 else 0 := by suffices q - 1 ∣ i ↔ φ = 1 by simp only [this] split_ifs; swap · exact Nat.cast_zero · rw [Fintype.card_units, Nat.cast_sub, cast_card_eq_zero, Nat.cast_one, zero_sub] show 1 ≤ q; exact Fintype.card_pos_iff.mpr ⟨0⟩ rw [← forall_pow_eq_one_iff, DFunLike.ext_iff] apply forall_congr'; intro x; simp [φ, Units.ext_iff] /-- The sum of `x ^ i` as `x` ranges over a finite field of cardinality `q` is equal to `0` if `i < q - 1`. -/ theorem sum_pow_lt_card_sub_one (i : ℕ) (h : i < q - 1) : ∑ x : K, x ^ i = 0 := by by_cases hi : i = 0 · simp only [hi, nsmul_one, sum_const, pow_zero, card_univ, cast_card_eq_zero] classical have hiq : ¬q - 1 ∣ i := by contrapose! h; exact Nat.le_of_dvd (Nat.pos_of_ne_zero hi) h let φ : Kˣ ↪ K := ⟨fun x ↦ x, Units.ext⟩ have : univ.map φ = univ \ {0} := by ext x simpa only [mem_map, mem_univ, Function.Embedding.coeFn_mk, true_and, mem_sdiff, mem_singleton, φ] using isUnit_iff_ne_zero calc ∑ x : K, x ^ i = ∑ x ∈ univ \ {(0 : K)}, x ^ i := by rw [← sum_sdiff ({0} : Finset K).subset_univ, sum_singleton, zero_pow hi, add_zero] _ = ∑ x : Kˣ, (x ^ i : K) := by simp [φ, ← this, univ.sum_map φ] _ = 0 := by rw [sum_pow_units K i, if_neg]; exact hiq section frobenius variable (R) [CommRing R] [Algebra K R] /-- If `R` is an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is given by raising every element of `R` to its `#K`-th power. -/ @[simps!] def frobeniusAlgHom : R →ₐ[K] R where __ := powMonoidHom q map_zero' := zero_pow Fintype.card_pos.ne' map_add' _ _ := by obtain ⟨p, _, _, hp, card_eq⟩ := card' K nontriviality R have : CharP R p := charP_of_injective_algebraMap' K R p have : ExpChar R p := .prime hp simp only [OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, powMonoidHom_apply, card_eq] exact add_pow_expChar_pow .. commutes' _ := by simp [← RingHom.map_pow, pow_card] theorem coe_frobeniusAlgHom : ⇑(frobeniusAlgHom K R) = (· ^ q) := rfl /-- If `R` is a perfect ring and an algebra over a finite field `K`, the Frobenius `K`-algebra endomorphism of `R` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquiv (p : ℕ) [ExpChar R p] [PerfectRing R p] : R ≃ₐ[K] R := .ofBijective (frobeniusAlgHom K R) <| by obtain ⟨p', _, n, hp, card_eq⟩ := card' K rw [coe_frobeniusAlgHom, card_eq] have : ExpChar K p' := ExpChar.prime hp nontriviality R have := ExpChar.eq ‹_› (expChar_of_injective_algebraMap (algebraMap K R).injective p') subst this apply bijective_iterateFrobenius variable (L : Type*) [Field L] [Algebra K L] /-- If `L/K` is an algebraic extension of a finite field, the Frobenius `K`-algebra endomorphism of `L` is an automorphism. -/ @[simps!] noncomputable def frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : L ≃ₐ[K] L := (Algebra.IsAlgebraic.algEquivEquivAlgHom K L).symm (frobeniusAlgHom K L) theorem coe_frobeniusAlgEquivOfAlgebraic [Algebra.IsAlgebraic K L] : ⇑(frobeniusAlgEquivOfAlgebraic K L) = (· ^ q) := rfl variable [Finite L] open Polynomial in theorem orderOf_frobeniusAlgHom : orderOf (frobeniusAlgHom K L) = Module.finrank K L := (orderOf_eq_iff Module.finrank_pos).mpr <| by have := Fintype.ofFinite L refine ⟨DFunLike.ext _ _ fun x ↦ ?_, fun m lt pos eq ↦ ?_⟩ · simp_rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← Module.card_eq_pow_finrank, pow_card] have := card_le_degree_of_subset_roots (R := L) (p := X ^ q ^ m - X) (Z := univ) fun x _ ↦ by simp_rw [mem_roots', IsRoot, eval_sub, eval_pow, eval_X] have := DFunLike.congr_fun eq x rw [AlgHom.coe_pow, coe_frobeniusAlgHom, pow_iterate, AlgHom.one_apply, ← sub_eq_zero] at this refine ⟨fun h ↦ ?_, this⟩ simpa [if_neg (Nat.one_lt_pow pos.ne' Fintype.one_lt_card).ne] using congr_arg (coeff · 1) h refine this.not_lt (((natDegree_sub_le ..).trans_eq ?_).trans_lt <| (Nat.pow_lt_pow_right Fintype.one_lt_card lt).trans_eq Module.card_eq_pow_finrank.symm) simp [Nat.one_le_pow _ _ Fintype.card_pos] theorem orderOf_frobeniusAlgEquivOfAlgebraic : orderOf (frobeniusAlgEquivOfAlgebraic K L) = Module.finrank K L := by simpa [orderOf_eq_iff Module.finrank_pos, DFunLike.ext_iff] using orderOf_frobeniusAlgHom K L theorem bijective_frobeniusAlgHom_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgHom K L ^ n.1 := let e := (finCongr <| orderOf_frobeniusAlgHom K L).symm.trans <| finEquivPowers (orderOf_pos_iff.mp <| orderOf_frobeniusAlgHom K L ▸ Module.finrank_pos) (Subtype.val_injective.comp e.injective).bijective_of_nat_card_le ((card_algHom_le_finrank K L L).trans_eq <| by simp) theorem bijective_frobeniusAlgEquivOfAlgebraic_pow : Function.Bijective fun n : Fin (Module.finrank K L) ↦ frobeniusAlgEquivOfAlgebraic K L ^ n.1 := ((Algebra.IsAlgebraic.algEquivEquivAlgHom K L).bijective.of_comp_iff' _).mp <| by simpa only [Function.comp_def, map_pow] using bijective_frobeniusAlgHom_pow K L instance (K L) [Finite L] [Field K] [Field L] [Algebra K L] : IsCyclic (L ≃ₐ[K] L) where exists_zpow_surjective := have := Finite.of_injective _ (algebraMap K L).injective have := Fintype.ofFinite K ⟨frobeniusAlgEquivOfAlgebraic K L, fun f ↦ have ⟨n, hn⟩ := (bijective_frobeniusAlgEquivOfAlgebraic_pow K L).2 f; ⟨n, hn⟩⟩ end frobenius open Polynomial section variable [Fintype K] (K' : Type*) [Field K'] {p n : ℕ} theorem X_pow_card_sub_X_natDegree_eq (hp : 1 < p) : (X ^ p - X : K'[X]).natDegree = p := by have h1 : (X : K'[X]).degree < (X ^ p : K'[X]).degree := by rw [degree_X_pow, degree_X] exact mod_cast hp rw [natDegree_eq_of_degree_eq (degree_sub_eq_left_of_degree_lt h1), natDegree_X_pow] theorem X_pow_card_pow_sub_X_natDegree_eq (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]).natDegree = p ^ n := X_pow_card_sub_X_natDegree_eq K' <| Nat.one_lt_pow hn hp theorem X_pow_card_sub_X_ne_zero (hp : 1 < p) : (X ^ p - X : K'[X]) ≠ 0 := ne_zero_of_natDegree_gt <| calc 1 < _ := hp _ = _ := (X_pow_card_sub_X_natDegree_eq K' hp).symm theorem X_pow_card_pow_sub_X_ne_zero (hn : n ≠ 0) (hp : 1 < p) : (X ^ p ^ n - X : K'[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K' <| Nat.one_lt_pow hn hp end theorem roots_X_pow_card_sub_X : roots (X ^ q - X : K[X]) = Finset.univ.val := by classical have aux : (X ^ q - X : K[X]) ≠ 0 := X_pow_card_sub_X_ne_zero K Fintype.one_lt_card have : (roots (X ^ q - X : K[X])).toFinset = Finset.univ := by rw [eq_univ_iff_forall] intro x rw [Multiset.mem_toFinset, mem_roots aux, IsRoot.def, eval_sub, eval_pow, eval_X, sub_eq_zero, pow_card] rw [← this, Multiset.toFinset_val, eq_comm, Multiset.dedup_eq_self] apply nodup_roots rw [separable_def] convert isCoprime_one_right.neg_right (R := K[X]) using 1 rw [derivative_sub, derivative_X, derivative_X_pow, Nat.cast_card_eq_zero K, C_0, zero_mul, zero_sub] variable {K} theorem frobenius_pow {p : ℕ} [Fact p.Prime] [CharP K p] {n : ℕ} (hcard : q = p ^ n) : frobenius K p ^ n = 1 := by ext x; conv_rhs => rw [RingHom.one_def, RingHom.id_apply, ← pow_card x, hcard] clear hcard induction n with | zero => simp | succ n hn => rw [pow_succ', pow_succ, pow_mul, RingHom.mul_def, RingHom.comp_apply, frobenius_def, hn] open Polynomial theorem expand_card (f : K[X]) : expand K q f = f ^ q := by obtain ⟨p, hp⟩ := CharP.exists K letI := hp rcases FiniteField.card K p with ⟨⟨n, npos⟩, ⟨hp, hn⟩⟩ haveI : Fact p.Prime := ⟨hp⟩ dsimp at hn rw [hn, ← map_expand_pow_char, frobenius_pow hn, RingHom.one_def, map_id] end FiniteField namespace ZMod open FiniteField Polynomial theorem sq_add_sq (p : ℕ) [hp : Fact p.Prime] (x : ZMod p) : ∃ a b : ZMod p, a ^ 2 + b ^ 2 = x := by rcases hp.1.eq_two_or_odd with hp2 | hp_odd · subst p change Fin 2 at x fin_cases x · use 0; simp · use 0, 1; simp let f : (ZMod p)[X] := X ^ 2 let g : (ZMod p)[X] := X ^ 2 - C x obtain ⟨a, b, hab⟩ : ∃ a b, f.eval a + g.eval b = 0 := @exists_root_sum_quadratic _ _ _ _ f g (degree_X_pow 2) (degree_X_pow_sub_C (by decide) _) (by rw [ZMod.card, hp_odd]) refine ⟨a, b, ?_⟩ rw [← sub_eq_zero] simpa only [f, g, eval_C, eval_X, eval_pow, eval_sub, ← add_sub_assoc] using hab end ZMod /-- If `p` is a prime natural number and `x` is an integer number, then there exist natural numbers `a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [ZMOD p]`. This is a version of `ZMod.sq_add_sq` with estimates on `a` and `b`. -/ theorem Nat.sq_add_sq_zmodEq (p : ℕ) [Fact p.Prime] (x : ℤ) : ∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ (a : ℤ) ^ 2 + (b : ℤ) ^ 2 ≡ x [ZMOD p] := by rcases ZMod.sq_add_sq p x with ⟨a, b, hx⟩ refine ⟨a.valMinAbs.natAbs, b.valMinAbs.natAbs, ZMod.natAbs_valMinAbs_le _, ZMod.natAbs_valMinAbs_le _, ?_⟩ rw [← a.coe_valMinAbs, ← b.coe_valMinAbs] at hx push_cast rw [sq_abs, sq_abs, ← ZMod.intCast_eq_intCast_iff] exact mod_cast hx /-- If `p` is a prime natural number and `x` is a natural number, then there exist natural numbers `a ≤ p / 2` and `b ≤ p / 2` such that `a ^ 2 + b ^ 2 ≡ x [MOD p]`. This is a version of `ZMod.sq_add_sq` with estimates on `a` and `b`. -/ theorem Nat.sq_add_sq_modEq (p : ℕ) [Fact p.Prime] (x : ℕ) :
∃ a b : ℕ, a ≤ p / 2 ∧ b ≤ p / 2 ∧ a ^ 2 + b ^ 2 ≡ x [MOD p] := by simpa only [← Int.natCast_modEq_iff] using Nat.sq_add_sq_zmodEq p x namespace CharP
Mathlib/FieldTheory/Finite/Basic.lean
506
509